add_learn and stored_rules

Next, a couple of additions to the standard learn rule:
OP KET => SUPERPOSITION

First one is just a notational short-cut for something that is common.
Say you have a list of objects (say friends) and you want to append one or more on the end of that list.

Currently, you would have to do:
sa: friends |Fred> => |Mary> + |Liz>
sa: friends |Fred> => friends |Fred> + |Sam> + |Rob> + |Emma>

But I am very lazy, and like to abbreviate common constructs.
And hence, now we can do:
sa: friends |Fred> => |Mary> + |Liz>
sa: friends |Fred> +=> |Sam> + |Rob> + |Emma>
Note the "+=>" in there.

A couple of properties though:
1) it ignores elements if they are already in the list.
eg:
friends |Fred> +=> |Liz>
leaves the friends list unmodified.
2) it (currently) ignores elements even if they have a different coeff.
eg:
|shopping list> => 2|apples> + 5 |oranges>
|shopping list> +=> 7 |apples> -- this line does not affect our shopping list.
Now, I'm just saying that is how it currently works. I might change this in the future.

So all in all, add-learn "+=>" is not a super big win, but useful every now and then.
And perhaps a more appropriate name is "append learn", but too late now!

Next is stored rules. They have notation:
OP KET #=> SUPERPOSITION
and are seriously useful!

Standard "=>" is evaluated at definition time.
"#=>" is evaluated at recall time (and we call them stored_rules).
(heh, I guess a mnemonic is # looks like a barrier that stops you evaluating straight away).

I guess an example might be the best way to explain:

-- define an initial value for "a":
sa: |a> => |start value>

-- define r1 and r2:
-- set r1 to current value of a:
sa: |r1> => "" |a>
-- set r2 to invoke-time value of a:
sa: |r2> #=> "" |a>

sa: "" |r1>
|start value>

sa: "" |r2>
|start value>


-- change the value of a:
sa: |a> => |next value>

-- r1 still has original definition:
sa: "" |r1>
|start value>

-- r2 returns the current value of a:
sa: "" |r2>
|next value>

And that is about it. Just know that they are very, very useful!
More to come tomorrow, probably.

Update:
I think it would be useful to give examples to show these map to the underlying python context.learn().
So we have these examples in BKO:
friends |Fred> => |Jack>
friends |Fred> => |Jack> + |Jill>
friends |Fred> +=> |Emma> + |Liz>
siblings |person: *> #=> sisters |_self> + brothers |_self>
And they look like this in python:
-- NB: auto-casts "Jack" to ket("Jack"). Implemented because it saves typing and is neater to read.
context.learn("friends","Fred","Jack")
context.learn("friends","Fred",ket("Jack") + ket("Jill"))
-- NB: "add_learn":
context.add_learn("friends","Fred",ket("Emma") + ket("Liz"))
-- NB: stored_rule():
context.learn("siblings","person: *",stored_rule("sisters |_self> + brothers |_self>"))
Update: Just a teaser: using a big nest of stored rules you should be able to construct some large functions that are only activated at run time. I plan to give an example of this eventually!


Home
previous: train of thought
next: current weather in adelaide in sw format

updated: 19/12/2016
by Garry Morrison
email: garry -at- semantic-db.org