Skip to content
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

(Put (DefinedPredicate ...)) not equivalent to (Evaluation (DefinedPredicate ...)) #854

Open
amebel opened this issue Aug 5, 2016 · 3 comments

Comments

@amebel
Copy link
Contributor

amebel commented Aug 5, 2016

The dpn in question is an extension of the dpn from #852

1. Scheme and atomspace contents

(DefineLink
    (DefinedPredicateNode "check")
    (SatisfactionLink
        (VariableList
            (TypedVariableLink
                (VariableNode "$face-id")
                (TypeNode "ConceptNode"))
            (TypedVariableLink
                (VariableNode "$recog-id")
                (TypeNode "ConceptNode"))
            (TypedVariableLink
                (VariableNode "$face-id-nn")
                (TypeNode "NumberNode")))
        (AndLink
            ; If someone is visible...
            (PresentLink (EvaluationLink (PredicateNode "visible face")
                    (ListLink (VariableNode "$face-id-nn"))))
            ; but not yet acknowledged...
            (AbsentLink (EvaluationLink (PredicateNode "acked face")
                    (ListLink (VariableNode "$face-id-nn"))))
            ; and is recognizable
            (PresentLink (EvaluationLink (PredicateNode "name")
                    (ListLink
                    (VariableNode "$face-id")
                    (VariableNode "$recog-id"))))
            (Not (Identical (VariableNode "$recog-id") (ConceptNode "0")))
            ; Check the ConceptNode and NumberNode for the face-id in
            ; two EvaluationLinks are equal
            (Put
                (DefinedPredicate "is_nn_equal_cn?")
                (List
                    (VariableNode "$face-id-nn")
                    (VariableNode "$face-id")))
            )))

(Define
    (DefinedPredicate "is_nn_equal_cn?")
    (LambdaLink
        (VariableList
            (TypedVariableLink
                (VariableNode "number")
                (TypeNode "NumberNode"))
            (TypedVariableLink
                (VariableNode "concept")
                (TypeNode "ConceptNode")))
        (EvaluationLink
            (GroundedPredicate "scm: is_nn_equal_cn?")
            (ListLink
                (VariableNode "number")
                (VariableNode "concept")))))

(define-public (is_nn_equal_cn? number-node concept-node)
    (if (equal? (string->number (cog-name number-node))
            (exact->inexact (string->number (cog-name concept-node))))
        (stv 1 1)
        (stv 0 1)
    )
)


(define (make-recognized-face face-id recog-id)
    (EvaluationLink
        (PredicateNode "visible face")
        (ListLink
            (NumberNode face-id)))

    (EvaluationLink
        (PredicateNode "name")
        (ListLink
            (ConceptNode (number->string face-id))
            (ConceptNode recog-id)))
)

(define (test-1) (cog-evaluate! (DefinedPredicateNode "check")))
(define (test-2)
    (make-recognized-face 1 "foo")
    (cog-evaluate! (DefinedPredicateNode "check"))
)
(define (test-3) ; Run after running test-2 to check validity of dpn
    (cog-evaluate!
        (Satisfaction (Put
            (DefinedPredicate "is_nn_equal_cn?")
            (List
                (NumberNode 1)
                (ConceptNode "1")))))
)

2. Running the tests

scheme@(guile-user)> (test-1)
$1 = (stv 0 1)
scheme@(guile-user)> (test-2) ; this is where the issue is
$2 = (stv 0 1)
scheme@(guile-user)> (test-3)
$3 = (stv 1 1)

3. Expected results

scheme@(guile-user)> (test-2)
$2 = (stv 1 1)
@linas
Copy link
Member

linas commented Aug 5, 2016

If you change (Put (DefinedPredicate "is_nn_equal_cn?") to (Evaluation (GroundedPredicate "scm: is_nn_equal_cn?") then it will work as expected.

The pattern matcher is literally looking for a PutLink, it is NOT trying to execute it. Its as if you had written (Present (Put Later, after running test-3. such a link does exist, so the search succeeds.

You might think that (Evaluation (DefinedPredicate "is_nn_equal_cn?") might work, but it appears to trigger some bug (that I am currently not planning to investigate). If you need (Evaluation (DefinedPredicate "is_nn_equal_cn?") to work, update this bug report.

The wiki page http://wiki.opencog.org/w/PutLink#Defined_predicates suggests that this should work, but uses weasel words "behaves much like an EvaluationLink" .. .much like??? and concludes "This is perhaps confusing, and could use some work." because, for this situation, its not clear what the right thing to do is.

@amebel amebel changed the title What is wrong with (DefinedPredicateNode "check") (Put (DefinedPredicate "is_nn_equal_cn?") ...) not yet equivalent to (Evaluation (DefinedPredicate "is_nn_equal_cn?")...) Aug 8, 2016
@linas
Copy link
Member

linas commented Aug 13, 2016

Do you want to pursue this, or should this be allowed to lapse?

@linas linas changed the title (Put (DefinedPredicate "is_nn_equal_cn?") ...) not yet equivalent to (Evaluation (DefinedPredicate "is_nn_equal_cn?")...) (Put (DefinedPredicate ...)) not equivalent to (Evaluation (DefinedPredicate ...)) Aug 13, 2016
@amebel
Copy link
Contributor Author

amebel commented Aug 15, 2016

Yes, as a user it seems valid feature to be able to beta-reduce a lambda function with TV return type, and this should also simplify the imperative atomese.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants