22 CHAPTER!. UNIFICATION
endif
endif
endif
One of the important points in this algorithm is the calculation of the repre
sentative of a term by means of S and the stack of equations E. Indeed, this
computation is done at each step of the reduction and is a function of the size
of the stack of equations. We must therefore try to minimize the size of this
stack. For a discussion of this problem and the comparison between different
algorithms, we refer the reader to M. Van Caneghem's thesis [Can84].
Finally, such a unification algorithm requires a special printing program to
output infinite trees [Piq84]. An interesting characteristic of this program is that
it can eliminate common subtrees, thus producing a minimal infinite tree.
1.4.2.3. Example
Let us trace this algorithm with the example that we had chosen (see section
1.3.2) in order to bring forth the deficiencies of the unification algorithm without
occur check.
Suppose we have to reduce the system T = {f(X, Y, X) = f(g(X), g(Y), Y)}
5:=0;
£:=0;
Step 1:
Let t = f(X, Y, X) and s = f(g(X), g{Y), Y)
f ι = rep(t, S U E) = t, Si= rep(s, SL)E) = S
Since t\ and s\ have the same functor and same arity,
E becomes {f{X, Y, X) = f(g{X), g(Y), Y)}
and T equals {X = g(X), Y = g(Y), X = Y)
Step 2:
Let t = X and s = g(X),
U = rep(t, SUE) = X,Si= rep(s, SUE) = g(X)
Since ti is a variable, E does not change
S becomes {X = g(X)} and T equals {Y = g(Y), X = Y)
Step 3:
Let t = Y and s = g(Y),
U = rep(t, S U E) = Y, si= rep(s, SUE) = g(Y)
Since ii is a variable, E is unchanged
S becomes {X = g(X), Y = g(Y)} and T equals [X = Y)
Step 4:
Let t = X and s = Y
ti = rep(t, SUE) = g(X), S1 = rep(s, SUE) = g(Y)