new function process reaction

I was thinking, how can we encode reactions (eg, chemical or nuclear) into the BKO knowledge representation scheme? I eventually decided we can't really do it at the moment, but with a couple of additions, then yes we can.

The first part of this is a new function, process-reaction().
Here is the python:
# one, two and three are superpositions
def process_reaction(one,two,three):
  if intersection(two,one).count_sum() != two.count_sum():
    return one
    return intersection_fn(del_fn3,one,two).drop() + three  
Here is a simple example, making water from hydrogen and oxygen gas:
2H2 + O2 -> 2 H2O

sa: process-reaction(5|H2> + 7|O2>,2|H2> + |O2>,2|H2O>)
3|H2> + 6|O2> + 2|H2O>
I'll give a more interesting example in the next post.

The next bit is we need a way to learn superposition rules. We also have a separate motivation for this idea. That is, we need a way so that literal operators can act on superpositions, instead of just being linear. An example I like to give is:
sa: M |yes> => |yes> + -1|no>
sa: M |no> => -1|yes> + |no>
sa: matrix[M]
[ no  ] = [ 1 -1 ] [ no  ]
[ yes ]   [ -1 1 ] [ yes ]

sa: drop M (|yes> + |no>)

sa: drop M (0.8|yes> + 0.2|no>)
OK. So that works as expected/desired (a simple example of inhibition). But if we try using literal operators:
sa: clean-M |*> #=> drop M |_self>

sa: clean-M (|yes> + |no>)
|yes> + |no>

sa: clean-M (0.8|yes> + 0.2|no>)
0.8|yes> + 0.2|no>
ie, it didn't work at all! This is because literal operators are currently linear.
clean-M (|yes> + |no>)
-- expands to:
clean-M |yes> + clean-M |no>
The solution (which I have not yet implemented in code) is:
learn-a-sp-rule (*) #=> foo( |_self>)
and then when we invoke it, replace the SP on the left into |_self>.
And so we can now learn:
make-water (*) #=> process-reaction(|_self>,2|H2> + |O2>,2|H2O>)
clean-M (*) #=> drop M |_self>
Now I need to find the cleanest way to implement this. It is going to take some work in at least context.learn() and context.recall() and the parser. So yeah, quite a bit of work!

previous: new function hash
next: representing nuclear decay

updated: 19/12/2016
by Garry Morrison
email: garry -at-