A substitution,
, is a most general unifier (mgu) of a
set of expressions
if it unifies
, and for any unifier,
, of
, there is a unifier,
, such that
.
The idea is that
is less specific than (technically, no more
specific than)
, that is, we can substitute for some of the
variables of
and get
. Note that there can be more
than one most general unifier, but such substitutions are the same
except for variable renaming.
In the above example,
is the mgu of the set of
expressions. We can see that
.
There is a simple algorithm for finding the most general unifier of a
set of expressions. First, we need to define the disagreement
set of a set of expressions. This is found by (textually) finding the
first symbol starting from the left that is not the same in every
expression and extracting the subexpressions that begin with that
symbol at that position in each expression of the set. The resulting
set of subexpressions is the disagreement set. For example, the
disagreement set for
is
.
The algorithm for finding the most general unifier for a set of
expressions
is as follows:
(the empty substitution)
while(is not a singleton) {
disagreement set of
;
if(contains a variable, say
, and a term, say
, that doesn't contain
) {
;
;
}
else
return ``Not unifiable'';
}
return;
We can prove, but won't, that this algorithm always returns the mgu, if one exists.