Hi Linas,
I'm very aware you're busy trying to get "behavior trees in OpenCog"
to work for Hanson.... However, I feel this is a subtle enough issue
that it requires more than a "knee-jerk reaction" to come to grips
with it usefully...
I also note that *none* of the solutions suggested for the near term
involve changes inside the Atomspace (though some would involve
changes in how the Atomspace is used).
Just to be sure things are clear, I will enumerate here the issues
under considerations here, and then discuss possible solutions.
**THE ISSUES**
There are two issues, separate but related:
Issue 1: VARIABLE0NODE RE-USE
Suppose we have two relations
A)
ForAllLink
VariableNode "$X"
ImplicationLink
EvaluationLink
PredicateNode "F"
VariableNode "$X"
EvaluationLink
PredicateNode "G"
VariableNode "$X"
and
B)
ForAllLink
VariableNode "$X"
ImplicationLink
EvaluationLink
PredicateNode "G"
VariableNode "$X"
EvaluationLink
PredicateNode "H"
VariableNode "$X"
...
In the current mode of usage of the Atomspace, it's the same
VariableNode $X in both cases...
Note, the Atomspace doesn't *require* this mode of usage. Instead,
we could use the Atomspace in such a way that variables which are
attached to different scoping links, have different names and Handles.
So this is not really a matter of the Atomspace code, but more of
the Atomspace usage pattern. (More on this below)
Issue 2: SCOPED-EXPRESSION REDUNDANCY
Suppose we also have in the Atomspace
C)
ForAllLink
VariableNode "$Y"
ImplicationLink
EvaluationLink
PredicateNode "F"
VariableNode "$Y"
EvaluationLink
PredicateNode "G"
VariableNode "$Y"
Then: A and C are actually the same thing. But in the current
Atomspace, they appear to be the different thing, because in one the
VariableNode is named "$X" and in the other the VariableNode is named
"$Y"
**POTENTIAL SOLUTIONS**
1)
One possible solution to the VariableNode Re-Use problem (Issue #1
above) is to simply adopt a convention not to do that.
In other words, we could simply adopt a convention that if we have two
different scoping links, then the associated VariableNodes should have
different names & Handles.
I see this as somewhat similar to the issue of Atom type signatures.
The Atomspace doesn't stop us from saying both
EvaluationLink
PredicateNode "eat"
ListLink
ConceptNode "Ben"
ConceptNode "Steak"
and
EvaluationLink
PredicateNode "eat"
ListLink
NumberNode "666"
GroundedSchemaNode "release_the_snukes.py"
TextNode "Chow Mein Kampf"
or whatever... We have talked about implementing Atom type
signatures that would prevent this sort of willy-nilly usage of
PredicateNode arguments. But for the moment, we are relying on
conventions regarding Atomspace usage patterns, and simply agreeing
not to do stuff like the above in most cases.
An agreement to not re-use the same VariableNode in different scoping
links, could be of a similar nature for the moment. Automated
enforcement of this rule could potentially be implemented later,
perhaps in the same batch of (future) code changes as enforcement of
Atom type signature checking.
If we adopted this solution, then developers would have use of a
helper function (already written and used in the R2L code) that simply
finds a VariableNode name not already used in a given Atomspace.
2)
Another possible solution to the VariableNode Re-Use Problem is not to
do anything about it --- i.e. to accept that, unlike other Node types,
we want a VariableNode with a certain name X and a certain Handle H to
have multiple different meanings and uses inside the Atomspace....
(I note this is at variance with how we use other Node types. For
instance, to handle different meanings of the word "cat", we create
different ConceptNodes named "cat_1", "cat_2", etc. We don't re-use
the same ConceptNode named "cat" to serve for all these different
senses --- even though natural language does this. But variables are
different from ordinary concepts, of course...)
In this case, the chainers have a problem --- as would any other
cognitive process needing to combine multiple different scoping links
in any way that paid attention to the Atom-structures being scoped.
The most straightforward way to work around this problem would be as follows.
Suppose a cognitive process (e.g. a chainer) takes two scoping links
L1 and L2 as arguments. Since we are assuming the same VariableNode
with the same name and Handle can be re-used for multiple meanings, it
can't simply combine the Atoms scoped by L1 and L2. Instead, what it
should do is, in general: Create new scoping links L1* and L2*. For
instance L1* is identical to L1 but with different names for the
variables. Then it should perform its cognitive processing on L1*
and L2*, deriving its conclusion (let's say L3). L3 can just be left
in the Atomspace; there's no need to change its variable names.
So e.g. inside this process
ForAllLink
VariableNode "$X"
ImplicationLink
EvaluationLink
PredicateNode "F"
VariableNode "$X"
EvaluationLink
PredicateNode "G"
VariableNode "$X"
would be replaced by
A*)
ForAllLink
VariableNode "$X_345"
ImplicationLink
EvaluationLink
PredicateNode "F"
VariableNode "$X_345"
EvaluationLink
PredicateNode "G"
VariableNode "$X_345"
Now, this is not incredibly hard to code, as you note. But it does
mean the chainer is creating copies of everything it uses, which then
need to be thrown out and garbage-collected immediately afterwards.
(Or, to save hassle, the chainer could through out the original
version with the re-used VariableNode names and keep the new version
with the unique VariableNode names. This would reduce wastage of
processor time overall, but not as much a simply avoiding the re-use
of VariableNode names in the first place.)
3)
For Issue #2, Scoped-Expression Redundancy, the simplest solution is:
-- When a new scoped expression L is created, a PM query is run to see
if the Atomspace contains any other expressions M that are equivalent
to L up to VariableNode renamings. If so, the two are merged, via an
appropriate policy.
This is straightforward in the Atomspace. It's trickier when one
thinks about backing-storage. Then the simplest solution is
-- When a new scoped expression L is created, a PM query is run
**against the backing store** to see if the Atomspace contains any
other expressions M that are equivalent to L up to VariableNode
renamings. If so, the two are merged, via an appropriate policy.
The issue with the above is that we can't currently run PM queries
against the backing store. But as previously discussed, this is not
extremely hard to implement in the sense of the simple PM queries that
would be required here (in which there would be no execution of schema
or other complexities, only matching of Atom-structures with
VariableNodes in the place of VariableNodes (heh ;p)) ...
4)
If we find that using the PM is too inefficient for solving Issue #2,
then a more advanced solution is to associate with each scoping link L
some sort of "canonical label" constituting a compact structure that
uniquely identifies the structure scoped by L. This would allow
faster search for M that are equivalent to L up to VariableNode
renaming (and could potentially deal with other kinds of equivalence
too).
But we don't need to do this, now, I just pointed it out for general
interest and future use...
...
I see that you prefer Solution #2 to the VariableNode Re-Use problem,
whereas William and Cassio and I were gravitating toward Solution
#1.... I just want to make clear that neither requires changes
inside the Atomspace, actually...
On the other hand, you haven't opined on the Scoped-Expression
Redundancy Issue .... These are two quite separate issues, though
both involve some of the same issues, right?
I also questioned, in my prior email, whether VariableNodes actually
need names, given that they are uniquely identified by Handles. But
this is more a suggestion for future architecture re-thinking, not a
suggestion for immediate changes. I note that the reason
VariableNodes have names is because me, Cassio, Senna and Thiago
fairly hastily chose to do it that way in 2001 ---- we really didn't
think through all these issues in such depth at that time. You've
already (Linas) undone a fair bit of stuff we decided at that time
when we first created the Atomspace.... VariableNodes aren't sacred
either...
-- Ben
-- Ben
>
https://groups.google.com/d/msgid/opencog/CAHrUA36ordPyAo1R%3DVrF7HATjwOYqb0FiETYmYkuE7Om4fLg5Q%40mail.gmail.com.