The basic unification algorithm is simple. However, it must be implemented with care to ensure that the results are correct.

We begin by making sure that the two expressions have no variables in common. If there are common variables, substitute a new variable in one of the expressions. (Since variables are universally quantified, another variable can be substituted without changing the meaning.)

Imagine moving a pointer left-to-right across both expressions until
parts are encountered that are not the same in both expressions.
If one is a * variable*, and the other is a * term not containing
that variable*,

- substitute the term for the variable in both expressions,
- substitute the term for the variable in the existing substitution set [This is necessary so that the substitution set will be simultaneous.]
- add the substitution to the substitution set.