I have defined an "if-and-only-if" rule in a CLIPS expert system, but it requires two rules instead of one rule:
;the rules are doIfOil and doIfBlackAndFlammable
(deftemplate Object
(slot type)
(slot color)
(slot flammable)
)
(defrule doIfOil
(Object (type oil))
=>
(assert (Object (color black) (flammable yes)))
)
(defrule doIfBlackAndFlammable
(Object (color black) (flammable yes))
=>
(assert (Object (type oil)))
)
(deffacts Result
(Object
(type oil)
)
)
Would it be possible to re-write this rule in a less redundant way?
Since facts can't be duplicated, you can have the conditions of the rule check for either fact and then have the actions of the rule assert both:
Alternately, you can write a general rule (which is more complicated) that matches a fact (in a simpler representation) representing the if and only if relationship: