Unification

See also Wikipedia, Norvig's note on a bug.

unify (t1t2subst):
    if t1 is var
       if t1 in subst
           return unify(t2, lookup(t1subst), subst)
       if t2 is var ∧ t2 in subst
           return unify(t1, lookup(t2subst), subst)
       if t1 is in t2
           fail
       return subst[t1 → t2]
    if t2 is var
        return unify(t2t1subst)
    if head t1 ≠ head t2
        fail
    subst' ← unify each argument in turn
    return subst'

Last modified: Tuesday, 3 May 2016, 3:51 PM