worked example: if-then-machines
description:
if-then machines are my simplified model of neurons
they consist of several patterns that "trigger" the neuron, and then a resulting output ket
in this example we show they can implement simple logic, and a type of fuzzy logic
code:
-- if (A and B) then C
pattern |node: 1: 1> => |A> + |B>
then |node: 1: *> => |C>
-- if (A or B) then D
pattern |node: 2: 1> => |A>
pattern |node: 2: 2> => |B>
then |node: 2: *> => |D>
-- if (C and D) then E
pattern |node: 7: 1> => |C> + |D>
then |node: 7: *> => |E>
if-then |*> #=> then similar-input[pattern] words-to-list |_self>
if-then-2 |*> #=> (then similar-input[pattern])^2 words-to-list |_self>
-- if you instead want strict logic, instead of "fuzzy", use:
if-then |*> #=> drop-below[0.98] then similar-input[pattern] words-to-list |_self>
if-then-2 |*> #=> (drop-below[0.98] then similar-input[pattern])^2 words-to-list |_self>
|null> => print |>
|null> => print |if (A and B) then C>
|null> => print |if (A or B) then D>
|null> => print |if (C and D) then E>
|null> => table[input, if-then, if-then-2] (|A> + |B> + |A and B>)
-- if ((E and F) or (G and H and I) or J) then K
pattern |node: 3: 1> => |E> + |F>
then |node: 3: *> => |K1>
pattern |node: 4: 1> => |G> + |H> + |I>
then |node: 4: *> => |K2>
pattern |node: 5: 1> => |J>
then |node: 5: *> => |K3>
pattern |node: 6: 1> => |K1>
pattern |node: 6: 2> => |K2>
pattern |node: 6: 3> => |K3>
then |node: 6: *> => |K>
|null> => print |if ((E and F) or (G and H and I) or J) then K>
|null> => table[input, if-then, if-then-2] (|E> + |F> + |G> + |H> + |I> + |J> + |G and H> + |G and I> + |H and I> + |E and F> + |G, H and I>)
examples:
-- first, the fuzzy version:
sa: load if-then-machines.sw
loading sw file: sw-examples/if-then-machines.sw
if (A and B) then C
if (A or B) then D
if (C and D) then E
+---------+-----------+-----------+
| input | if-then | if-then-2 |
+---------+-----------+-----------+
| A | D, 0.50 C | 0.75 E |
| B | D, 0.50 C | 0.75 E |
| A and B | C, D | E |
+---------+-----------+-----------+
if ((E and F) or (G and H and I) or J) then K
+------------+---------+-----------+
| input | if-then | if-then-2 |
+------------+---------+-----------+
| E | 0.50 K1 | 0.50 K |
| F | 0.50 K1 | 0.50 K |
| G | 0.33 K2 | 0.33 K |
| H | 0.33 K2 | 0.33 K |
| I | 0.33 K2 | 0.33 K |
| J | K3 | K |
| G and H | 0.67 K2 | 0.67 K |
| G and I | 0.67 K2 | 0.67 K |
| H and I | 0.67 K2 | 0.67 K |
| E and F | K1 | K |
| G, H and I | K2 | K |
+------------+---------+-----------+
-- now the non-fuzzy version:
sa: load if-then-machines.sw
loading sw file: sw-examples/if-then-machines.sw
if (A and B) then C
if (A or B) then D
if (C and D) then E
+---------+---------+-----------+
| input | if-then | if-then-2 |
+---------+---------+-----------+
| A | D | |
| B | D | |
| A and B | C, D | E |
+---------+---------+-----------+
if ((E and F) or (G and H and I) or J) then K
+------------+---------+-----------+
| input | if-then | if-then-2 |
+------------+---------+-----------+
| E | | |
| F | | |
| G | | |
| H | | |
| I | | |
| J | K3 | K |
| G and H | | |
| G and I | | |
| H and I | | |
| E and F | K1 | K |
| G, H and I | K2 | K |
+------------+---------+-----------+
future:
source code:
load if-then-machines.sw
Home