atomspace icon indicating copy to clipboard operation
atomspace copied to clipboard

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

Open amebel opened this issue 9 years ago • 3 comments

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)

amebel avatar Aug 05 '16 13:08 amebel

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.

linas avatar Aug 05 '16 18:08 linas

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

linas avatar Aug 13 '16 01:08 linas

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.

amebel avatar Aug 15 '16 03:08 amebel