-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Evaluatable in non-logical link inside BindLink clause #132
Comments
What I see in the code of pattern matcher you cannot use MemberLink as a top link in the query, because it is not evaluatable. I guess if you add EvaluationLink around that top link it should work. For me it sounds logical, though I have not got much experience with this type system. |
We should ask @ngeiswei about this. When he simplified the format of the BindLink, I think that the top level link could be anything, in which case, its treated as a single clause. In the good old days, it had to have the format
Later on, the top could be AndLink, SequentialAndLink or ChoiceLink (and nothing else). Today, if it is not one of these three, but something else, then we could/should assume there is only one clause total to be satisfied. I guess that last part is not implemented/fully supported. A short-term work-around is to wrap the MemberLink with an AndLink. |
What I found is that doing a simpler version
doesn't generate the error. So I think there's something special with the one at the top. |
Ah, so it's not just a MemberLink thing. In fact, it happens on any non-logical link with evaluatable inside. For example, the follow also generates the error.
|
Looks like a PM bug to me (I have no more clue sorry). |
This is case 4) explained here: What we can do in your case is to introduce UniqueLink instead of (NotLink (stv 1.000000 0.000000)
(EqualLink (stv 1.000000 0.000000)
(VariableNode "$A") ; [80]
(VariableNode "$C") ; [103]
) ; [108]
) This is what @linas has suggested how to deal with elimination rules: Then there will be one less virtual atom in your first example (UniqueLink is supposed to be UnorderedLink). However what to do with ExecutionOutputLink remains open question. I think your intention is to match it without any execution. So it should be quoted somehow. Does the QuoteLink do the job? Do you have any other ideas? |
Hummm... I thought about the QuoteLink possibility, but it seems it is impossible to QuoteLink the evaluatable/virtual atom without ended up QuoteLink-ing the variables as well. Maybe the way to do it is, any evaluatable not inside a logical link should just be matched as a normal atom? |
William's last suggestion seems best: I would like to have @ngeiswei think about this, instead of saying "I don't know", because this is a general atomspace representation question, and not just a pattern-matcher question. Some link types are truth-valued (for example, the EqualLink) and it is not obvious what should happen when these are inside of non-logical links (e.g. the ListLink) For now, William's answer seems like the best answer, but its a bit confusing in general. I have thought about, and wrote some preliminary code to make the above user-configurable, via callback, but left it partly-finished, pending use-cases that really do need more complex behavior. |
Yes, it's exactly case 4. There is a check here: https://github.com/opencog/atomspace/blob/master/opencog/query/PatternMatchEngine.cc#L1117 and, since EqualLink is "evaluatable", it is evaluated, and then, the containing ListLink or MemberLink causes the error to be thrown. The "evaluatable" flag is pre-compted, at the time that the bind link is defined. We could change this so that a term is "evaluatable" if and only if it is contained in another link that expects a truth value (i.e. a logical link). If it is not contained in this way, then it is not evaluatable. The "is_evaluatable" check is based on these bits: https://github.com/opencog/atomspace/blob/master/opencog/query/Pattern.h#L108-L111 These are computed here: specifically: I had planed to do something similar for "exectuable terms" -- terms that could be executed, resulting in an atom -- but never got very far with that. |
Anyway, @ngeiswei (and I guess Ben and Matt Ikle should weigh in, too ...) do you now see what the problem is? When pattern matching, some links can be evaluated to yield a truth value; others can be executed, yielding an atom; in either case, its not obvious what to do when these are not nested in a way that "makes sense". It would be nice to have a good answer... |
It's a complex issue and I haven't digested all the PM inner workings to spot THE problem.. Personally I would have approached the pattern matching problem the other way around, assuming a pattern is a predicate ([Atom] -> TV), and give some predicate construct (let's call it BelongLink) to allow to check whether an hypergraph belongs to the atomspace. For instance the problematic pattern above (William's compact version) would have been expressed as follows: (BelongLink
(ListLink (stv 1.000000 1.000000)
(EqualLink (stv 1.000000 0.000000)
(VariableNode "$A") ; [80]
(VariableNode "$B") ; [103]
) ; [108]
(ConceptNode "URE") ; [116]
) So in the PM matcher lingo everything would be virtual if not told otherwise (BelongLink used for that). Would that fundamentally fix the issue, probably not. It seems to me generally the problem is that not enough is explicitly specified, right? I mean how do you match the following pattern (EqualLink (VariableNode "$X") (VariableNode "$Y)) ? Can you at all? Or can you match it via using SignatureLink? |
If I'm right a whole clause is either virtual or not. I mean a part cannot be virtual while another part of it wouldn't, right? So what about using a VirtualLink on top of each virtual clause? Or symmetrically using a BelongLink on top of each non virtual ones? |
Nil -- I'm not sure exactly what you mean by "virtual" here? Is it the On Mon, Jul 13, 2015 at 5:48 AM, ngeiswei [email protected] wrote:
Ben Goertzel, PhD "The reasonable man adapts himself to the world: the unreasonable one |
Couldn't it match to |
yes I would think so... On Mon, Jul 13, 2015 at 5:56 AM, William Ma [email protected]
Ben Goertzel, PhD "The reasonable man adapts himself to the world: the unreasonable one |
I just tried scheme@(guile-user) [1]> (cog-bind (BindLink (EqualLink (VariableNode "X") (VariableNode "Y")) (ListLink (VariableNode "X") (VariableNode "Y"))))
$2 = (SetLink
) so it doesn't match to anything, I think it assumes it's a virtual clause. Ben a virtual clause is a clause that is a predicate rather than a pattern, so for instance GreaterThan X Y is a virtual clause, it doesn't try to find that in the atomspace instead it uses as a constraint to filter out matches (could be used here for instance if X and Y match number nodes, etc). |
So "virtual" is almost the opposite of "quote". But QuoteLink is even stronger as is assumes the VariableNode are quoted as well (they only match themselves). |
I suggest we re-implement the pattern matcher Nil's way, everything is predicate and turn the atomspace into a LambdaLink graveyard. |
Or wrap virtual clauses into a VirtualLink... |
I have thought about this a bit now... Of course, related issues are encountered in LISP, and are dealt with there http://stackoverflow.com/questions/134887/when-to-use-quote-in-lisp where they consider examples in which you want to evaluate only parts of What LISP does is to evaluate everything by default, and then you need to Here the question is whether we treat "logical links" as evaluable or not, I'm not sure "any evaluatable not inside a logical link should just be It would seem best to make things explicit. That is, we could say -- the default for any link type except those on a certain list -- if we want to evaluate a certain instance of one of these link types, This becomes a little awkward, because we then have two types of Atoms
and when we want those of the first type to be literally matched we use So in William's example (BindLink it would just try to match the exact pattern given, i.e. to find $A, $B so that
(where the EqualLink and ListLInk are not evaluated) On the other hand, if we wanted the EqualLink to be evaluated then ListLink True ConceptNode "URE" if the pattern matcher found any $A, $B that were equal -- Ben On Sun, Jul 12, 2015 at 11:01 PM, William Ma [email protected]
Ben Goertzel, PhD "The reasonable man adapts himself to the world: the unreasonable one |
We could make everything explicit, or assume that some atoms are evaluable (or evaluatable, not sure I understand the distinction). But I'm thinking in cases the link itself is a function (like EqualLink) maybe we could benefit from introducing a special FunQuoteLink to quote only the functional part of the link. If executions were only relying on EvaluationLink or ExecutionOutputLink then you could always quote the predicate or schema, like if you'd want to match
you could write the pattern
to unambiguously tell that you don't want to execute it. But you can't do that for an EqualLink, thus a FunQuoteLink. The other option is to use UnquoteLink (or DontDoThisLink as Ben coins it), but it seems a FunQuoteLink might allows to get more compact patterns in many practical cases. |
How would FunQuoteLink handle logical links like EqualsLink etc. ? On Mon, Jul 13, 2015 at 8:58 AM, ngeiswei [email protected] wrote:
Ben Goertzel, PhD "The reasonable man adapts himself to the world: the unreasonable one |
This is probably due to historical design, but what if every link that is evaluable/executable yield only atoms? Instead of truth value yield TrueValueNode or something like that? Maybe there is something I am not aware? Having that, quoted evaluatable links would be matched without evaluation, unquoted would be matched after evaluation, replaced by the atom being a result of evaluation/execution. Just throwing the idea up, not sure how poor it is :-) |
On Mon, Jul 13, 2015 at 10:48 AM, Jacek Świergocki <[email protected]
That would not be problematic so far as I know.... To consider that when
I am not sure that we want "match after evaluation" to be the default for Almost all the time, when e.g. InheritanceLink occurs in a pattern to be So it seems that the default for logical links should be match-literally ... -- Ben |
FunQuoteLinkDefinitionQuote only the functional part of a functional link. ExampleImagine you want to match the following without executing the EqualLink, but you still want to execute its arguments, you can't use a QuoteLink (cause you want to execute the arguments), but you can use a FunQuoteLink, to quote only the Equal part:
Is that clear? |
GSN "ToBeRunAtPMTime-1" and GSN "ToBeRunAtPMTime-2" will still be executed at PM time. So it's really like writing ('equal arg1 arg2) in LISP. |
Yeah, now I get it... this seems a useful mechanism, sure... basically your I don't care what they're named, but both of these seem useful mechanisms... Still I think the default for logical links should be literal matching, so Anyway I think the matter is conceptually clear now -- we just need to add On Mon, Jul 13, 2015 at 11:01 AM, ngeiswei [email protected] wrote:
Ben Goertzel, PhD "The reasonable man adapts himself to the world: the unreasonable one |
I have one more issue. It seems to me that we need to somehow distinguish logical links from the of top of the query that connect clauses to be matched from logical links that are inside part of the clause?
The former links should be evaluated by default, because we are not searching for them, the latter should be matched literally by defaut. How can we deal with that? |
Pattern matcher searches for each clause separately. |
The OpenCog HK team has discussed this F2F with Cassio a bit earlier this The general conclusion was that, ugly as it is, introducing systematic use Of course, we could syntactically sugar this in the Scheme/python shells ben On Tue, Jul 28, 2015 at 3:31 PM, ngeiswei [email protected] wrote:
Ben Goertzel, PhD "The reasonable man adapts himself to the world: the unreasonable one |
Humm... I wasn't aware of reaching a conclusion. |
Hah .. OK, maybe only Cassio and I reached a conclusion in our own minds ;D Our conclusion was just to copy LISP, which seems to be Nil's inclination What is your current preferred option? ben On Fri, Aug 14, 2015 at 5:13 PM, William Ma [email protected]
Ben Goertzel, PhD "The reasonable man adapts himself to the world: the unreasonable one |
Does the LISP method allows you to evaluate part of the stuff inside quote? I recall Cassio mentioned UnquotedVariableNode, but what if you want to match UnquotedVariableNode literally (ie. you want to quote the UnquotedVariableNode)? I don't think the system can have "unquote" anything since it is possible to lead to conflict. The solution will have to contain only "quoting". Maybe Nil's LocalQuoteLink that only works on link would work (with QuoteLink works on everything), and no "unquote" anywhere. As I said, since the pattern are auto-generate (as oppose to someone defining it by hand), if the atom is in the AtomSpace, it will be Pattern Matched eventually. Suppose at one point we want to ground $A & $B in
without evaluating the EqualLink, then we added the following
Now that the above is in the AtomSpace, we might at some step want to ground
while matching the LocalQuoteLink as is, while grounding $A & $B, and not evaluating the EqualLink. Then do we add
what happens to the EqualLink now that the LocalQuoteLink wrapping it is not evaluated... is the EqualLink now executed?? I guess we should add
so that the outer LocalQuoteLink quote the middle one, and the inner one quote the EqualLink. Now that this atom is in the AtomSpace, how to match it as is, while grounding $A, $B, so we add
Maybe this is correct, and that's what needed. Kind of like doing |
There might be strange confusing interaction between LocalQuoteLink & QuoteLink though. Suppose again we have
which we want to match literally without grounding, we do
Now that the above is in the AtomSpace, we want to match as is, so if we do
we will ended up not evaluating the QuoteLink, and ended up making EqualLink evaluatable, and $A & $B ground-able. So maybe the solution is to only have QuoteLink (no LocalQuoteLink) but makes it only work on its top atom, so
is needed to quote the original atom. |
To be more exact about how LISP works, look at the Backquote specification http://www.gnu.org/software/emacs/manual/html_node/elisp/Backquote.html So I think the LISP backquote is like our QuoteLink, and the LISP comma I'm not sure if we have use for some analogue of the LISP splicing operator LISP also has quasiquotes, which get complificated... http://3e8.org/pub/scheme/doc/Quasiquotation%20in%20Lisp%20(Bawden).pdf -- Ben On Fri, Aug 14, 2015 at 6:16 PM, William Ma [email protected]
Ben Goertzel, PhD "The reasonable man adapts himself to the world: the unreasonable one |
Hummm.... so
but what if we actually want
does LISP allow that? |
it seems you can nest backquotes and commas http://stackoverflow.com/questions/7549550/using-two-backquotes-and-commas-common-lisp in the LISP spirit that "data is code" ... On Fri, Aug 14, 2015 at 9:21 PM, William Ma [email protected]
Ben Goertzel, PhD "The reasonable man adapts himself to the world: the unreasonable one |
When Ben talks about quote and unquote, I think he really means quasi-quote and unquote. You cannot wriggle your way out of a quote, but you can unquote your way out of a quasi-quote: Note that regular single-quote ' is quote while the back-tick ` is quasi-quote. |
So, to answer William's question:
yields
yields |
This suggests the need for three link types: QuoteLink QuasiquoteLink and UnquoteLink -- the UnquoteLink can only work inside a QuasiquoteLink; it is powerless otherwise. Whether we shall someday need a UnquoteSplicingLink is unclear. |
Linas, What you're calling a quasiquote, I used to call a "backquote", http://www.gnu.org/software/emacs/manual/html_node/elisp/Backquote.html but yeah it's the same thing... http://www.phyast.pitt.edu/~micheles/scheme/scheme8.html So I think we agree, and Cassio concurred with this approach also.... ben On Sun, Aug 16, 2015 at 9:59 AM, Linas Vepštas [email protected]
Ben Goertzel, PhD "The reasonable man adapts himself to the world: the unreasonable one |
I think only two link types are really required in our current case, though In Scheme (as you likely know), quote causes the S-expression quoted to be ftp://ftp.cs.utexas.edu/pub/garbage/cs345/schintro-v13/schintro_129.html So if one isn't concerned about optimization of quoted expressions (via So my suggestion is to just have QuoteLink and UnquoteLink, where QuoteLink I think this is what Nil was suggesting a while ago in this thread... and -- Ben On Sun, Aug 16, 2015 at 10:06 AM, Linas Vepštas [email protected]
Ben Goertzel, PhD "The reasonable man adapts himself to the world: the unreasonable one |
Guys, we've got an AbsentLink for when a pattern in not in the atomspace, let's use a PresentLink for when a pattern is in the AtomSpace. You say "it's verbose", I say "fuck that!" :-D. You can always create helper functions to workaround the verbosity, but you cannot hand to the user such a complex badly specified behavior. In its last email Linas said
I think he has a point. What isn't good to a newcomers isn't good to us. Yes most patterns will be populated with PresentLink, on the other hand the use for QuoteLink and the like will drop considerably (only when you need to match variables inside pattern, or maybe I'm missing something). |
If we wanted to use PresentLink, we would just have to wrap it around the So most patterns would not be populated with PresentLink, but would simply On Tue, Aug 18, 2015 at 6:53 PM, ngeiswei [email protected] wrote:
Ben Goertzel, PhD "The reasonable man adapts himself to the world: the unreasonable one |
The (old) idea is to have everything evaluatable by default and use PresentLink to tell to search the a pattern. So for instance to define the deduction rule one would write
letting aside the formula on the implicand. |
PresentLink is the BelongLink I introduced earlier, except the name is cooler, especially cause we've got an AbsentLink... |
I guess I still don't see why we need to make that explicit I mean when we have ImplicationLink do you want to say instead ImplicationLink ? On Tue, Aug 18, 2015 at 8:32 PM, ngeiswei [email protected] wrote:
Ben Goertzel, PhD "The reasonable man adapts himself to the world: the unreasonable one |
On Tue, Aug 18, 2015 at 7:41 AM, bgoertzel [email protected] wrote:
Sequential just means "you must evaluate in order"; pattern matching can Anyway, I like PresentLink, it solves a different bit of queasiness I'm |
There is an easy work-around for PresentLink that already exists and is implemented. Its called ChoiceLink. I just tested it, and it works as expected. An arity-N ChoiceLink is true if and only if one (or more) of its outgoing st is in the atomspace (can be grounded in the atomspace). Thus, an arity-1 ChoiceLink is identical to an arity-1 PresentLink: its true if and only if the wrapped atom is present. I defined PresentLink here: http://wiki.opencog.org/w/PresentLink and I defined it so that it requires all of its terms to be present. thus, PresentLink is like present-and, while ChoiceLink is like present-or. ChoiceLink works today! Note some additional confusion: PrsentLink resembles SatisfactionLink, in that both are either true or false; but SatisfactionLink binds its variables, while PresentLink leaves them free. I think the spec in http://wiki.opencog.org/w/PresentLink is sufficiently clear that it can be "easily" implemented. Seems like a good idea. |
+1 for n-ary PresentLink. Maybe having n-ary AbsentLink could be useful as well. In that case Also you say in the wiki page of PresentLink "Unlike SatisfactionLink, a PresentLink cannot be used with the cog-bind function. " Why is that? Also, do you intend to make PresentLink mandatory? Which involves |
I guess when PresentLink isn't used then the evaluatable per link conventions could be used... So for instance if one wants to search for the pattern |
I think this conversation has reached a conclusion; closing this as a bug report. If there are new issues, please open a new bug report. BTW, PresentLink is now partly-implemented (in a rather narrow scope) via bug #218 |
Merge opencog -> singnet
Just thought I would throw this out there. Doing
cog-bind
on the following crazinessgives me
I stumbled upon this when the BC algorithm tried to backward chain an untyped
(VariableNode "$stuff")
target (from modus ponens rule), which match to everything in the atomspace. Then since the variables inside the interior MemberLink are by current algorithmic definition "free", the MemberLink is added as a target as a "Variable Fullfillment Query", and then generate the above error when trying to ground it.The text was updated successfully, but these errors were encountered: