This can be considered a continuation of the post "Nested not/and syntax question"

With the help of Ernest, the following two bugs in rule compilation have been identified.

A. Pattern (not (and ( ?var <- ...)))
The following rule is erroneously compiled.

(defrule Rule1bug
(not
    (and
        ?o <- (Object (name A))
        (Pred (obj ?o))
    )
)
=>
(printout t "OK1" crlf))

Specifically, variable ?o inside the Pred fact obtains a new name, as shown by the (ppdefrule) output, leading to wrong results:

(ppdefrule Rule1bug)
"(defrule MAIN::Rule1bug
   (initial-fact)
   (not ?o <- (and ?o <- (Object (name A)) (Pred (obj ?_021_o))))
   =>
   (printout t \"OK1\" crlf))"

One easy way to come around this bug is to add a test pattern, instead of using explicit variable matching. Eg:

(defrule Rule1fixed
(not
    (and
        ?o <- (Object (name A))
        (Pred (obj ?o2))
        (test (eq ?o ?o2))
    )
)
=>
(printout t "OK1" crlf))

B. Pattern (or (..) (and ( ?var <- ...)))
Now the compilation of the outermost (or ) and its contents is perfomed correctly, but whatever pattern is added to the lhs of the rule outside (i.e., after) the (or ..) ends up insided it somehow. Eg:

(defrule Rule2bug
(or
    (not (Object (name C)))
    (and    ?o <- (Object (name C))
        (not (Pred (obj ?o)))
    )
)
(test (eq 1 1))
=>
(printout t "OK2" crlf))

The (ppdefrule) output shows that the (test ) pattern is included in the (and ) pattern. In fact, no statement following the (or ) pattern can in practice appear outside it:

Jess> (ppdefrule Rule2bug)
"(defrule MAIN::Rule2bug
   (or
     (and
       (initial-fact)
       (not (Object (name C))))
     (and
       ?o <- (Object (name C))
       (not (and (Pred (obj ?o))
        (test (eq 1 2))))))
   =>
   (printout t \"OK2\" crlf))"

I still can't figure out a way to overcome this bug. Notice that both Rule1bug/fixed and Rule2bug express the same logical statement, therefore the fixed rule can be used as a potential solution in this case.

Theodore






--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users y...@address.com'
in the BODY of a message to majord...@sandia.gov, NOT to the list
(use your own address!) List problems? Notify owner-jess-us...@sandia.gov.
--------------------------------------------------------------------

Reply via email to