```------------------------------------------
------------------------------------------
----- A System Matrix Implementation -----
----- using Sparse Matrix Methods,   -----
----- and Energy Flow Processing     -----
-----                                -----
----- By John Ringland               -----
----- 2004/11/21                     -----
------------------------------------------
------------------------------------------

-- this file uses sparse matrix energy flow methods
-- to implement an ergodic pure metric sysWrapped SMN framework
-- using System Transforms.
-- And uses the above methods to implement a simple NAND system.

include ergodicSysMSMN.e

---------------------------------
---------------------------------
-----  Test Model of a      -----
-----  Single NAND system   -----
---------------------------------
---------------------------------

sequence st, sm, sv, model, cUpdate
object is

function NAND(sequence in)
-- in is a pair of cData bools; either zero or one
return not (in*in)
end function

integer NAND_id
NAND_id = routine_id("NAND")

-- input selector
is = 1

st = {NAND_id}
-- constructing the Metric System Matrix element by element
sm = sparse_SM(3,3)
sm = set_SM(sm, {1,2}, is)
sm = set_SM(sm, {1,3}, is)

-- constructing the State Vector
sv = {0,1,1}

-- flagging the initial inputs for processing
cUpdate = {2,3}

-- combining all of the above into a single system model
model = {st,sm,sv,cUpdate}

puts(1,"\n\nSingle NAND System\n\n")
puts(1,"initial model a = NOT (b AND c)\n")
? model
sequence result
puts(1,"first iteration\n")
result = step_Model(model, 1)
puts(1,"State Vector:    ")
? result[model_][SV_]
puts(1,"cUpdate:         ")
? result[model_][CU_]
puts(1,"cUpdate is empty so no more iterations needed\n\n")

puts(1,"all iterations at once\n")
result = step_Model(model, 100)
puts(1,"State Vector:    ")
? result[model_][SV_]
puts(1,"cUpdate:         ")
? result[model_][CU_]

puts(1,"\nthen change c=0\n\n")
result[model_][SV_] = 0
result[model_][CU_] = {3}
puts(1,"State Vector:    ")
? result[model_][SV_]
puts(1,"cUpdate:         ")
? result[model_][CU_]
puts(1,"\nfirst iteration\n")
result = step_Model(result[model_], 1)
puts(1,"State Vector:    ")
? result[model_][SV_]
puts(1,"cUpdate:         ")
? result[model_][CU_]
puts(1,"\nsecond iteration\n")
result = step_Model(result[model_], 1)
puts(1,"State Vector:    ")
? result[model_][SV_]
puts(1,"cUpdate:         ")
? result[model_][CU_]
puts(1,"this second iteration doesn't change the state vector, it only clears the cUpdate list\n\n")

```

www.Anandavala.info