A
unification problem is a finite set of equations to solve, where are in the set T of
terms or
expressions. Depending on which expressions or terms are allowed to occur in an equation set or unification problem, and which expressions are considered equal, several frameworks of unification are distinguished. If higher-order variables, that is, variables representing
functions, are allowed in an expression, the process is called
higher-order unification, otherwise
first-order unification. If a solution is required to make both sides of each equation literally equal, the process is called
syntactic or
free unification, otherwise
semantic or
equational unification, or
E-unification, or
unification modulo theory. If the right side of each equation is closed (no free variables), the problem is called (pattern)
matching. The left side (with variables) of each equation is called the
pattern.
Prerequisites Formally, a unification approach presupposes • An infinite set V of
variables. For higher-order unification, it is convenient to choose V disjoint from the set of
lambda-term bound variables. • A set T of
terms such that V \subseteq T. For first-order unification, T is usually the set of
first-order terms (terms built from variable and function symbols). For higher-order unification T consists of first-order terms and
lambda terms (terms containing some higher-order variables). • A mapping \text{vars}\colon T \rightarrow
\mathbb{P}(V), assigning to each term t the set \text{vars}(t) \subsetneq V of
free variables occurring in t. • A theory or
equivalence relation \equiv on T, indicating which terms are considered equal. For first-order E-unification, \equiv reflects the background knowledge about certain function symbols; for example, if \oplus is considered commutative, t\equiv u if u results from t by swapping the arguments of \oplus at some (possibly all) occurrences. In the most typical case that there is no background knowledge at all, then only literally, or syntactically, identical terms are considered equal. In this case, ≡ is called the
free theory (because it is a
free object), the
empty theory (because the set of equational
sentences, or the background knowledge, is empty), the
theory of uninterpreted functions (because unification is done on uninterpreted
terms), or the
theory of constructors (because all function symbols just build up data terms, rather than operating on them). For higher-order unification, usually t\equiv u if t and u are
alpha equivalent. As an example of how the set of terms and theory affects the set of solutions, the syntactic first-order unification problem {
y =
cons(2,
y) } has no solution over the set of
finite terms. However, it has the single solution {
y ↦
cons(2,
cons(2,
cons(2,...))) } over the set of
infinite tree terms. Similarly, the semantic first-order unification problem {
a⋅
x =
x⋅
a } has each substitution of the form {
x ↦
a⋅...⋅
a } as a solution in a
semigroup, i.e. if (⋅) is considered
associative. But the same problem, viewed in an
abelian group, where (⋅) is considered also
commutative, has any substitution at all as a solution. As an example of higher-order unification, the singleton set {
a =
y(
x) } is a syntactic second-order unification problem, since
y is a function variable. One solution is {
x ↦
a,
y ↦ (
identity function) }; another one is {
y ↦ (
constant function mapping each value to
a),
x ↦
(any value) }.
Substitution A
substitution is a mapping \sigma: V\rightarrow T from variables to terms; the notation \{x_1\mapsto t_1, ..., x_k \mapsto t_k\} refers to a substitution mapping each variable x_i to the term t_i, for i=1,...,k, and every other variable to itself; the x_i must be pairwise distinct.
Applying that substitution to a term t is written in
postfix notation as t \{x_1 \mapsto t_1, ..., x_k \mapsto t_k\}; it means to (simultaneously) replace every occurrence of each variable x_i in the term t by t_i. The result t\tau of applying a substitution \tau to a term t is called an
instance of that term t. As a first-order example, applying the substitution to the term
Generalization, specialization If a term t has an instance equivalent to a term u, that is, if t\sigma \equiv u for some substitution \sigma, then t is called
more general than u, and u is called
more special than, or
subsumed by, t. For example, x\oplus a is more general than a\oplus b if ⊕ is
commutative, since then (x\oplus a) \{x\mapsto b\} = b\oplus a\equiv a\oplus b. If ≡ is literal (syntactic) identity of terms, a term may be both more general and more special than another one only if both terms differ just in their variable names, not in their syntactic structure; such terms are called
variants, or
renamings of each other. For example, f(x_1, a, g(z_1), y_1) is a variant of f(x_2, a, g(z_2), y_2), since f(x_1, a, g(z_1), y_1) \{x_1 \mapsto x_2, y_1 \mapsto y_2, z_1 \mapsto z_2\} = f(x_2, a, g(z_2), y_2) and f(x_2, a, g(z_2), y_2) \{x_2 \mapsto x_1, y_2 \mapsto y_1, z_2 \mapsto z_1\} = f(x_1, a, g(z_1), y_1). However, f(x_1, a, g(z_1), y_1) is
not a variant of f(x_2, a, g(x_2), x_2), since no substitution can transform the latter term into the former one. The latter term is therefore properly more special than the former one. For arbitrary \equiv, a term may be both more general and more special than a structurally different term. For example, if ⊕ is
idempotent, that is, if always x \oplus x \equiv x, then the term x\oplus y is more general than z, and vice versa, although x\oplus y and z are of different structure. A substitution \sigma is
more special than, or
subsumed by, a substitution \tau if t\sigma is subsumed by t\tau for each term t. We also say that \tau is more general than \sigma. More formally, take a nonempty infinite set V of auxiliary variables such that no equation l_i \doteq r_i in the unification problem contains variables from V. Then a substitution \sigma is subsumed by another substitution \tau if there is a substitution \theta such that for all terms X\notin V, X\sigma \equiv X\tau\theta.
Solution set A substitution σ is a
solution of the unification problem
E if for i = 1, ..., n. Such a substitution is also called a
unifier of
E. For example, if ⊕ is
associative, the unification problem {
x ⊕
a ≐
a ⊕
x } has the solutions {
x ↦
a}, {
x ↦
a ⊕
a}, {
x ↦
a ⊕
a ⊕
a}, etc., while the problem {
x ⊕
a ≐
a } has no solution. For a given unification problem
E, a set
S of unifiers is called
complete if each solution substitution is subsumed by some substitution in
S. A complete substitution set always exists (e.g. the set of all solutions), but in some frameworks (such as unrestricted higher-order unification) the problem of determining whether any solution exists (i.e., whether the complete substitution set is nonempty) is undecidable. The set
S is called
minimal if none of its members subsumes another one. Depending on the framework, a complete and minimal substitution set may have zero, one, finitely many, or infinitely many members, or may not exist at all due to an infinite chain of redundant members. Thus, in general, unification algorithms compute a finite approximation of the complete set, which may or may not be minimal, although most algorithms avoid redundant unifiers when possible. gave an algorithm that reports unsolvability or computes a single unifier that by itself forms a complete and minimal substitution set, called the
most general unifier. ==Syntactic unification of first-order terms==