10.7 Exercises

Unification Algorithm

Here are the rules for computing the solved form of a conjunction of basic constraints. In the following, S and B are conjunctions of basic constraints. The algorithm is presented as a rewriting algorithm: it starts with true:B and terminates with S:true or S:false. When it terminates with S:true, S is the solved form of the input basic constraint B. When it terminates with S:false, the original B is unsatisfiable.

We say that X is bound S if S contains a basic constraint with X on the left-side of the equation. The algorith maintains the following invariant for S:B: if S contains an equation X=Y, then X does not occur in B, nor in S except in equation X=Y. We write B[X/Y] for the resulting of replacing every occurence of X in B by Y.

S : true & B  ->  S : B
S : X=X  & B  ->  S : B
S : X=Y  & B    where X and Y are distinct identifiers
      if X not bound in S
                  -> S[X/Y] & X=Y : B[X/Y]
 else if Y not bound in S
                  -> S[Y/X] & Y=X : B[Y/X]
 else X=f(X1...Xn) in S and Y=g(Y1...Ym) in S
      if f!=g or n!=m
                  -> S : false
      else        -> S[X/Y] & X=Y : (X1=Y1 & ... & Xn=Yn & B)[X/Y]
S : X=f(X1...Xn) & B
  if X=g(Z1...Zm) in S
      if f!=g or n!=m
                  -> S : false
      else        -> S : X1=Z1 & ... Xn=Zn & B
  else            -> S & X=f(X1...Xn) : B


Denys Duchier, Claire Gardent and Joachim Niehren
Version 1.3.99 (20050412)