Backchaining Example[file backch.lsp]

The function (backchain goal rules facts) tries to prove a goal given sets of rules and facts. goal is a symbol (atom or propositional variable). facts is a list of atoms that are known to be true. rules is a list of rules of the form (concl prem1 ... premn ); each rule states that the conclusion is true if all of the premises are true. For example, a rule A &and B &rarr C would be written (c a b).

backchain works as follows: if the goal is known to be a fact, return true. Otherwise, see if some rule has the goal as conclusion and has premises that are true (using backchain).


(defun backchain (goal rules facts)
 (or (member goal facts)
     (some #'(lambda (rule) 
               (and (eq (car rule) goal)
                    (every #'(lambda (subgoal)
                              (backchain subgoal
                                   rules facts))
                           (cdr rule))))
           rules)) )


> (backchain 'e '((c a b) (e c d)) '(a b d))
T

Contents    Page-10    Prev    Next    Page+10    Index