Examples of Unification
Home |
First order of unification |
Unification Algorithm |
Terms in Unification
- f(A) = g(B) : Fails because the heads of the terms are different
- f(A) = f(B, C) : Fails to unify because the terms have different arity
- f(g(A)) = f(B) : Unifies B with the term g(A)
- f(g(A), A) = f(B, xyz) : Unifies A with the atom xyz and B with the term g(xyz).
- A = f(A) : Infinite unification, A is unified with f(f(f(f(...)))). In proper first-order logic and many modern Prolog dialects this is forbidden (and enforced by the occurs check).
- A = abc, xyz = X, A = X : Fails to unify; effectively abc = xyz .
- It is useful to explicitly ask Prolog to (attempt) to unify two terms. Such explicit calls are made using the "=" operator.
- Example:
|?- f(A, g(X)) = f(abc, B).
A = abc, B = g(X)