Simple Unification Algorithm


(defun unify (u v) (unifyb u v '((t . t))))


; unify terms: subs list or NIL if failure
(defun unifyb (u v subs)         ; works if:
  (or (and (eq u v) subs)        ; identical vars
      (varunify v u subs)        ; u is a var
      (varunify u v subs)        ; v is a var
      (and (consp u) (consp v)   ; both are fns
           (eq (car u) (car v))  ;  with same name
           (unifyc (cdr u) (cdr v) subs))) ) ;args

(defun unifyc (args1 args2 subs) ; unify arg lists
  (if (null args1)             ; if args1 empty
      (if (null args2) subs)   ;    args2 must be
      (and args2 subs          ; unify first args
        (let ((newsubs (unifyb (car args1)
                               (car args2) subs)))
             (unifyc (sublis newsubs (cdr args1))
                     (sublis newsubs (cdr args2))
                     newsubs))) ))

(defun varunify (term var subs) ; unify with var
  (and var (symbolp var) (not (occurs var term))
       (cons (cons var term)
             (subst term var subs))))

Contents    Page-10    Prev    Next    Page+10    Index