(undocumented?) Restrictions on the 'not' conditional element

28 views
Skip to first unread message

Lode Hoste

unread,
Aug 4, 2011, 3:55:35 PM8/4/11
to clip...@googlegroups.com
Hi all,

I'm wondering why the 'not' conditional behaves different than
expected. For instance:

(defrule hello
(not (> (+ 1 1) 1))
=>
(printout t "123"))

is an invalid rule. It gives a syntax error at the open brackets for
the + operator.
Another parsing problem is found in the following definition:

(defrule hello
(not (= 1 1))
=>
(printout t "123"))

Note that the following examples do work:

(defrule hello
(not (> 1 1))
=>
(printout t "123"))

(defrule hello
(not (eq 1 1))
=>
(printout t "123"))


Is there a specific reason why these (arithmetic?) limitations are imposed?


Greetings,

Lode

CLIPS Support

unread,
Aug 5, 2011, 2:49:21 PM8/5/11
to CLIPSESG
You need to use the test condition element if you want to evaluate an
expression on the condition side of a rule.

(defrule hello
(test (not (> (+ 1 1) 1)))
=>
(printout t "123"))

Lode Hoste

unread,
Aug 12, 2011, 10:29:05 AM8/12/11
to clip...@googlegroups.com
Sorry, I simplified my question (way) too much.

I'm trying to compose a negation condition with fact matching and test
functions.
My invalid rule:

(deftemplate Foo (slot bar))
(deffunction complexFunction (?a ?b) FALSE)

(defrule hello
(Foo (bar ?a))
(not (Foo (bar ?b))
(test (complexFunction ?a ?b)))


=>
(printout t "123"))


The alternative (although harder to read) does work:

(defrule hello2
(Foo (bar ?a))
(not (Foo (bar ?b&:(complexFunction ?a ?b))))


=>
(printout t "123"))


Is there a reason for this limitation?

Thank you


2011/8/5 CLIPS Support <gdronl...@swbell.net>:

> --
> You received this message because you are subscribed to the Google Groups "CLIPSESG" group.
> To post to this group, send email to CLIP...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/CLIPSESG?hl=en
>
> --> IF YOU NO LONGER WANT TO RECEIVE EMAIL <--
> Visit this group at http://groups.google.com/group/CLIPSESG?hl=en
> Click on "Edit my membership" link.
> Select the "No Email" radio button.
> Click the "Save these settings" button.
>
> --> IF YOU WANT TO UNSUBSCRIBE <--
> Visit this group at http://groups.google.com/group/CLIPSESG?hl=en
> Sign in
> Click on "Edit my membership" link.
> Click the "Unsubscribe" button.
> Note: This appears to be the most reliable way to unsubscribe
>
> Alternately, send email to CLIPSESG-u...@googlegroups.com. You will receive an email which you must respond to as well to unsubscribe. Clicking the link mentioned in the unsubscribe reply does not appear to work reliably.

CLIPS Support

unread,
Aug 14, 2011, 12:49:47 PM8/14/11
to CLIPSESG
(defrule hello
(Foo (bar ?a))
(not (and (Foo (bar ?b))
(test (complexFunction ?a ?b))))
=>
(printout t "123"))

On Aug 12, 9:29 am, Lode Hoste <zill...@gmail.com> wrote:
> Sorry, I simplified my question (way) too much.
>
> I'm trying to compose a negation condition with fact matching and test
> functions.
> My invalid rule:
>
> (deftemplate Foo (slot bar))
> (deffunction complexFunction (?a ?b) FALSE)
>
> (defrule hello
>   (Foo (bar ?a))
>   (not (Foo (bar ?b))
>          (test (complexFunction ?a ?b)))
>   =>
>   (printout t "123"))
>
> The alternative (although harder to read) does work:
>
> (defrule hello2
>   (Foo (bar ?a))
>   (not (Foo (bar ?b&:(complexFunction ?a ?b))))
>   =>
>   (printout t "123"))
>
> Is there a reason for this limitation?
>
> Thank you
>
> 2011/8/5 CLIPS Support <gdronline2...@swbell.net>:
> > For more options, visit this group athttp://groups.google.com/group/CLIPSESG?hl=en
>
> > --> IF YOU NO LONGER WANT TO RECEIVE EMAIL <--
> > Visit this group athttp://groups.google.com/group/CLIPSESG?hl=en
> > Click on "Edit my membership" link.
> > Select the "No Email" radio button.
> > Click the "Save these settings" button.
>
> > --> IF YOU WANT TO UNSUBSCRIBE <--
> > Visit this group athttp://groups.google.com/group/CLIPSESG?hl=en

Lode Hoste

unread,
Mar 15, 2013, 12:55:56 PM3/15/13
to clip...@googlegroups.com
Hi,

I'm reviving this thread since I finally found some time to figure out the problematic conditions.
It seems that adding a test CE after a 'complex' not node, results in rules not getting matched:


(deftemplate Event (slot value) (slot time))

(defrule example-working
  (Event (value 1) (time ?t1))
  (Event (value 1) (time ?t2))
  (test (< ?t1 ?t2))
  (test (< ?t1 ?t2))
  (not (and (Event (value 0) (time ?tn))
            (test (< ?t1 ?tn))))
 =>
  (printout t "Works 1" crlf)
)

(defrule example-failing-1
  (Event (value 1) (time ?t1))
  (Event (value 1) (time ?t2))
  (test (< ?t1 ?t2))
  (not (and (Event (value 0) (time ?tn))
            (test (< ?t1 ?tn))))
  (test (< ?t1 ?t2))
=>
 (printout t "Fails 1" crlf)
)

(defrule example-simple-working-2
  (Event (value 1) (time ?t1))
  (Event (value 1) (time ?t2))
  (test (< ?t1 ?t2))
  (not (Event (value 0) (time ?tn)))
  (test (< ?t1 ?t2))
=>
 (printout t "Works (Simple!) 2" crlf)
)

(defrule example-failing-2
  (Event (value 1) (time ?t1))
  (Event (value 1) (time ?t2))
  (not (and (Event (value 0) (time ?tn))
            (test (< ?t1 ?tn))))
  (test (< ?t1 ?t2))
  (test (< ?t1 ?t2))
=>
 (printout t "Fails 2" crlf)
)

(defrule example-working-3
  (Event (value 1) (time ?t1))
  (not (and (Event (value 0) (time ?tn))
            (test (< ?t1 ?tn))))
  (Event (value 1) (time ?t2))
  (test (< ?t1 ?t2))
  (test (< ?t1 ?t2))
=>
 (printout t "Works 3" crlf)
)


(assert (Event (value 1) (time 0)))
(assert (Event (value 1) (time 1)))


I hope this notice will be helpful for some people.



2011/8/14 CLIPS Support <gdronl...@swbell.net>
For more options, visit this group at http://groups.google.com/group/CLIPSESG?hl=en


--> IF YOU NO LONGER WANT TO RECEIVE EMAIL <--

Click on "Edit my membership" link.
Select the "No Email" radio button.
Click the "Save these settings" button.

--> IF YOU WANT TO UNSUBSCRIBE <--
Reply all
Reply to author
Forward
0 new messages