I have constructed a (somewhat) simple test case that reproduces this behavior. Your thoughts on this are most welcome.
Speculation:
The essence seems to
be in the interaction of a pattern with an 'or' clause AND a pattern with
an (exists) clause [r2 below].
An identical rule
with (not) doesn't exhibit this behavior [r4 below]. Strange, since
(exists) is a (not ) function.
It appears that a variable
used in a fact pattern that contains an (or) function is not defined for
(exists) but is defined for (not).
This variable isn't
used in the (or) function, but is used in another slot for that same fact
pattern.
I.E. ?variable1 does not get defined in:
(<fact1> (<slot1>
?variable1) (<slot2> ?variable2&:(or <expression1>
<expression2>)) )
(exists (<fact2>
(<slot1> ?variable1))
That's my two cents worth, anyway.
Test Case:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; base case rule. fires
as expected.
(defrule r1
; establish two
variables:
(a ?x ?y)
; use variable
?type in slot 1, (or) function in slot 2
(b ?type ?d&:(or
(eq ?d ?x) (eq ?d ?y)))
; match against
?type above. ?type appears to be defined.
(c ?type)
=>
(printout t "R1
FIRES with " ?x " " ?y " " ?type " and " ?d crlf)
)
; test case: identical
to r1, but with (exists). Never fires.
(defrule r2
(a ?x ?y)
(b ?type ?d&:(or
(eq ?d ?x) (eq ?d ?y)))
; as per r1, but
with (exists)
; Now it
appears as though ?type is not defined.
(exists (c ?type))
=>
(printout t "R2
FIRES with " ?x " " ?y " " ?type " and " ?d crlf)
)
; test case r3 is the
same as r1, except for the 'OR' and it's ?y expression
; fires as expected.
(defrule r3
(a ?x ?y)
(b ?type ?d&:(eq
?d ?x))
(exists (c ?type))
=>
(printout t "R3
FIRES with " ?x " " ?y " " ?type " and " ?d crlf)
)
; test case r4. identical
to r2, but with (not) instead of (exists).
; fires as expected.
(defrule r4
(a ?x ?y)
(b ?type ?d&:(or
(eq ?d ?x) (eq ?d ?y)))
; as per r2, but
with (not)
; Now it
appears as though ?type IS defined.
(not (c ?type))
=>
(printout t "R4
FIRES with " ?x " " ?y " " ?type " and " ?d crlf)
)
(reset)
(assert (a harry moe))
(assert (a larry moe))
(assert (b fat harry))
(assert (b skinny moe))
(assert (b sidekick
george))
(assert (c fat))
(run)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Jess v 5.2
I hope all of this makes some sense, please let me know if you require further clarification.
Jack
PS
Perhaps you can try
this in 6.0 as well - I'm limited to 5.2 for a while to come.
[EMAIL PROTECTED] wrote:
I think Jack Kerkhof wrote:
> Hi all,
>
> Under what conditions could the addition of an (exists <pattern>)
> around a <pattern> cause a rule NOT to fire?None that I can think of, unless perhaps the pattern binds a variable
that is used later in the rule -- but be sure to read all the way to
the enf of this message.> I know that would imply the problem is elsewhere, but I have
> constrained all variables to only the change above. It would seem to
> me that under any circumstance two rules with the above variations
> would either not fire at all, or both fire at least once - correct?Yes, that should be the case. What does the pattern look like? Does it
define any variables?> PS Tested in 5.2
Try this in 6.0 if you can, see if the problem has been fixed.
> PPS: Ernest, the documentation section 2.8.1.7. (5.2) indicates that
> (exists) is implemented as (not (not)) when in fact it appears to be
> implemented as (not (not (unique))). I don't know if that is salient
> to this problem or 'not' ;-)It's true that the (unique) flag is set in those two nested "not"
nodes as an optimizatiion. This is the case in 5.2 but not in 6.0. You
could try commenting that line (line 1104 in jess/Jesp.java) and see
if the problem goes away -- please let me know if it does. (unique) is
a tricky beast and easy to abuse; this optimization might in fact be
one of those abuses.---------------------------------------------------------
Ernest Friedman-Hill
Distributed Systems Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
Org. 8920, MS 9012 [EMAIL PROTECTED]
PO Box 969 http://herzberg.ca.sandia.gov
Livermore, CA 94550--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------
