views:

34

answers:

1

Hello, I want to make a program in Clips which generates all the partitions of a number. First of all I start with the number like his basic partition: (1 1 1 1 1) if it is number 5, etc.

(deftemplate partition (multislot p) )
(deffacts facts (p 1 1 1 1 1) )
(defrule adds
    (p $?a ?b ?c $?d)
    (not (p $?a (+ ?b ?c) $?d))
    (not (p (+ ?b ?c) $?a $?d))
    (not (p $?a $?d (+ ?b ?c)))
=>  (assert (p $?a (+ ?b ?c) $?d)) 
)

The problem is that although the code seems fine, it has errors on the lines with "not" - where I specify that the new partition created should not already exist in the facts. I don't know what is the problem, any idea is welcome. Thanks

A: 

In the condition part of a rule, you need to use the = operator to evaluate an expression and determine that it matches a value in the fact:

(defrule adds
   (p $?a ?b ?c $?d)

   (not (p $?a =(+ ?b ?c) $?d))

   (not (p =(+ ?b ?c) $?a $?d))

   (not (p $?a $?d =(+ ?b ?c)))

   => 

   (assert (p $?a (+ ?b ?c) $?d)))
Gary Riley