Formal definition
A ''unification problem'' is a finite set of equations to solve, where are in the set 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 of ''variables''. For higher-order unification, it is convenient to choose disjoint from the set ofSubstitution
A ''substitution'' is a mapping from variables to terms; the notation refers to a substitution mapping each variable to the term , for , and every other variable to itself; the must be pairwise distinct. ''Applying'' that substitution to a term is written inGeneralization, specialization
If a term has an instance equivalent to a term , that is, if for some substitution , then is called ''more general'' than , and is called ''more special'' than, or ''subsumed'' by, . For example, is more general than if ⊕ isSolution set
A substitution σ is a ''solution'' of the unification problem ''E'' if for . Such a substitution is also called a ''unifier'' of ''E''. For example, if ⊕ isSyntactic unification of first-order terms
Unification algorithms
Occurs check
An attempt to unify a variable ''x'' with a term containing ''x'' as a strict subterm ''x'' ≐ ''f''(..., ''x'', ...) would lead to an infinite term as solution for ''x'', since ''x'' would occur as a subterm of itself. In the set of (finite) first-order terms as defined above, the equation ''x'' ≐ ''f''(..., ''x'', ...) has no solution; hence the ''eliminate'' rule may only be applied if ''x'' ∉ ''vars''(''t''). Since that additional check, called ''occurs check'', slows down the algorithm, it is omitted e.g. in most Prolog systems. From a theoretical point of view, omitting the check amounts to solving equations over infinite trees, see #Unification of infinite terms below.Proof of termination
For the proof of termination of the algorithm consider a triple where is the number of variables that occur more than once in the equation set, is the number of function symbols and constants on the left hand sides of potential equations, and is the number of equations. When rule ''eliminate'' is applied, decreases, since ''x'' is eliminated from ''G'' and kept only in . Applying any other rule can never increase again. When rule ''decompose'', ''conflict'', or ''swap'' is applied, decreases, since at least the left hand side's outermost ''f'' disappears. Applying any of the remaining rules ''delete'' or ''check'' can't increase , but decreases . Hence, any rule application decreases the triple with respect to theExamples of syntactic unification of first-order terms
In the Prolog syntactical convention a symbol starting with an upper case letter is a variable name; a symbol that starts with a lowercase letter is a function symbol; the comma is used as the logical ''and'' operator. For mathematical notation, ''x,y,z'' are used as variables, ''f,g'' as function symbols, and ''a,b'' as constants.Application: unification in logic programming
The concept of unification is one of the main ideas behind=
implies first-order syntactic unification. It represents the mechanism of binding the contents of variables and can be viewed as a kind of one-time assignment.
In Prolog:
# A variable can be unified with a constant, a term, or another variable, thus effectively becoming its alias. In many modern Prolog dialects and in +
, -
, *
, /
, are not evaluated by =
. So for example 1+2 = 3
is not satisfiable because they are syntactically different. The use of integer arithmetic constraints #=
introduces a form of E-unification for which these operations are interpreted and evaluated.
Application: type inference
True : x'/code>, the compiler will use the type a -> -> /code> of the list construction function (:)
, the type Bool
of the first argument True
, and the type har/code> of the second argument x'/code>. The polymorphic type variable a
will be unified with Bool
and the second argument /code> will be unified with har/code>. a
cannot be both Bool
and Char
at the same time, therefore this expression is not correctly typed.
Like for Prolog, an algorithm for type inference can be given:
# Any type variable unifies with any type expression, and is instantiated to that expression. A specific theory might restrict this rule with an occurs check.
# Two type constants unify only if they are the same type.
# Two type constructions unify only if they are applications of the same type constructor and all of their component types recursively unify.
Application: Feature Structure Unification
Unification has been used in different research areas of computational linguistics.
Order-sorted unification
'' Order-sorted logic'' allows one to assign a ''sort'', or ''type'', to each term, and to declare a sort ''s''1 a ''subsort'' of another sort ''s''2, commonly written as ''s''1 ⊆ ''s''2. For example, when reаsoning about biological creatures, it is useful to declare a sort ''dog'' to be a subsort of a sort ''animal''. Wherever a term of some sort ''s'' is required, a term of any subsort of ''s'' may be supplied instead.
For example, assuming a function declaration ''mother'': ''animal'' → ''animal'', and a constant declaration ''lassie'': ''dog'', the term ''mother''(''lassie'') is perfectly valid and has the sort ''animal''. In order to supply the information that the mother of a dog is a dog in turn, another declaration ''mother'': ''dog'' → ''dog'' may be issued; this is called ''function overloading'', similar to overloading in programming languages
In programming language theory and type theory, polymorphism is the use of one symbol to represent multiple different types.: "Polymorphic types are types whose operations are applicable to values of more than one type."
In object-oriented progr ...
.
Walther
Walther () is a masculine given name and a surname. It is a German form of Walter, which is derived from the Old High German '' Walthari'', containing the elements ''wald'' -"power", "brightness" or "forest" and ''hari'' -"warrior".
The name was ...
gave a unification algorithm for terms in order-sorted logic, requiring for any two declared sorts ''s''1, ''s''2 their intersection ''s''1 ∩ ''s''2 to be declared, too: if ''x''1 and ''x''2 is a variable of sort ''s''1 and ''s''2, respectively, the equation ''x''1 ≐ ''x''2 has the solution , where ''x'': ''s''1 ∩ ''s''2.
After incorporating this algorithm into a clause-based automated theorem prover, he could solve a benchmark problem by translating it into order-sorted logic, thereby boiling it down an order of magnitude, as many unary predicates turned into sorts.
Smolka generalized order-sorted logic to allow for parametric polymorphism
In programming languages and type theory, parametric polymorphism allows a single piece of code to be given a "generic" type, using variables in place of actual types, and then instantiated with particular types as needed. Parametrically polymorph ...
.
In his framework, subsort declarations are propagated to complex type expressions.
As a programming example, a parametric sort ''list''(''X'') may be declared (with ''X'' being a type parameter as in a C++ template), and from a subsort declaration ''int'' ⊆ ''float'' the relation ''list''(''int'') ⊆ ''list''(''float'') is automatically inferred, meaning that each list of integers is also a list of floats.
Schmidt-Schauß generalized order-sorted logic to allow for term declarations.
As an example, assuming subsort declarations ''even'' ⊆ ''int'' and ''odd'' ⊆ ''int'', a term declaration like ∀ ''i'' : ''int''. (''i'' + ''i'') : ''even'' allows to declare a property of integer addition that could not be expressed by ordinary overloading.
Unification of infinite terms
Background on infinite trees:
*
*
*
Unification algorithm, Prolog II:
*
*
Applications:
*
E-unification
E-unification is the problem of finding solutions to a given set of equations,
taking into account some equational background knowledge ''E''.
The latter is given as a set of universal equalities.
For some particular sets ''E'', equation solving algorithms
In mathematics and computer science, an algorithm () is a finite sequence of mathematically rigorous instructions, typically used to solve a class of specific problems or to perform a computation. Algorithms are used as specifications for per ...
(a.k.a. ''E-unification algorithms'') have been devised;
for others it has been proven that no such algorithms can exist.
For example, if and are distinct constants,
the equation
In mathematics, an equation is a mathematical formula that expresses the equality of two expressions, by connecting them with the equals sign . The word ''equation'' and its cognates in other languages may have subtly different meanings; for ...
has no solution
with respect to purely syntactic unification,
where nothing is known about the operator .
However, if the is known to be commutative
In mathematics, a binary operation is commutative if changing the order of the operands does not change the result. It is a fundamental property of many binary operations, and many mathematical proofs depend on it. Perhaps most familiar as a pr ...
,
then the substitution solves the above equation,
since
:
The background knowledge ''E'' could state the commutativity of by the universal equality
" for all ".
Particular background knowledge sets E
It is said that ''unification is decidable'' for a theory, if a unification algorithm has been devised for it that terminates for ''any'' input problem.
It is said that ''unification is semi-decidable'' for a theory, if a unification algorithm has been devised for it that terminates for any ''solvable'' input problem, but may keep searching forever for solutions of an unsolvable input problem.
''Unification is decidable'' for the following theories:
*
* ,
* ,,F. Fages, ''Associative-Commutative Unification'', J. Symbolic Comput., vol.3, no.3, pp. 257–275, 1987
* ,,in the presence of equality , equalities and are equivalent, similar for and
* ,
* , (monoid)
*
* Boolean ring
In mathematics, a Boolean ring is a ring for which for all in , that is, a ring that consists of only idempotent elements. An example is the ring of integers modulo 2.
Every Boolean ring gives rise to a Boolean algebra, with ring multiplicat ...
s
* Abelian group
In mathematics, an abelian group, also called a commutative group, is a group in which the result of applying the group operation to two group elements does not depend on the order in which they are written. That is, the group operation is commu ...
s, even if the signature is expanded by arbitrary additional symbols (but not axioms)Baader and Snyder (2001), p. 486.
* K4 modal algebras
''Unification is semi-decidable'' for the following theories:
* ,
* ,,
* Commutative ring
In mathematics, a commutative ring is a Ring (mathematics), ring in which the multiplication operation is commutative. The study of commutative rings is called commutative algebra. Complementarily, noncommutative algebra is the study of ring prope ...
s
One-sided paramodulation
If there is a convergent term rewriting system ''R'' available for ''E'',
the ''one-sided paramodulation'' algorithm
can be used to enumerate all solutions of given equations.
Starting with ''G'' being the unification problem to be solved and ''S'' being the identity substitution, rules are applied nondeterministically until the empty set appears as the actual ''G'', in which case the actual ''S'' is a unifying substitution. Depending on the order the paramodulation rules are applied, on the choice of the actual equation from ''G'', and on the choice of ''R''s rules in ''mutate'', different computations paths are possible. Only some lead to a solution, while others end at a ''G'' ≠ where no further rule is applicable (e.g. ''G'' = ).
For an example, a term rewrite system ''R'' is used defining the ''append'' operator of lists built from ''cons'' and ''nil''; where ''cons''(''x'',''y'') is written in infix notation as ''x''.''y'' for brevity; e.g. ''app''(''a''.''b''.''nil'',''c''.''d''.''nil'') → ''a''.''app''(''b''.''nil'',''c''.''d''.''nil'') → ''a''.''b''.''app''(''nil'',''c''.''d''.''nil'') → ''a''.''b''.''c''.''d''.''nil'' demonstrates the concatenation of the lists ''a''.''b''.''nil'' and ''c''.''d''.''nil'', employing the rewrite rule 2,2, and 1. The equational theory ''E'' corresponding to ''R'' is the congruence closure
In mathematics, a subset of a given set is closed under an operation on the larger set if performing that operation on members of the subset always produces a member of that subset. For example, the natural numbers are closed under addition, but ...
of ''R'', both viewed as binary relations on terms.
For example, ''app''(''a''.''b''.''nil'',''c''.''d''.''nil'') ≡ ''a''.''b''.''c''.''d''.''nil'' ≡ ''app''(''a''.''b''.''c''.''d''.''nil'',''nil''). The paramodulation algorithm enumerates solutions to equations with respect to that ''E'' when fed with the example ''R''.
A successful example computation path for the unification problem is shown below. To avoid variable name clashes, rewrite rules are consistently renamed each time before their use by rule ''mutate''; ''v''2, ''v''3, ... are computer-generated variable names for this purpose. In each line, the chosen equation from ''G'' is highlighted in red. Each time the ''mutate'' rule is applied, the chosen rewrite rule (''1'' or ''2'') is indicated in parentheses. From the last line, the unifying substitution ''S'' = can be obtained. In fact,
''app''(''x'',''app''(''y'',''x'')) = ''app''(''a''.''nil'',''app''(''nil'',''a''.''nil'')) ≡ ''app''(''a''.''nil'',''a''.''nil'') ≡ ''a''.''app''(''nil'',''a''.''nil'') ≡ ''a''.''a''.''nil'' solves the given problem.
A second successful computation path, obtainable by choosing "mutate(1), mutate(2), mutate(2), mutate(1)" leads to the substitution ''S'' = ; it is not shown here. No other path leads to a success.
Narrowing
If ''R'' is a convergent term rewriting system for ''E'',
an approach alternative to the previous section consists in successive application of "narrowing steps";
this will eventually enumerate all solutions of a given equation.
A narrowing step (cf. picture) consists in
* choosing a nonvariable subterm of the current term,
* syntactically unifying it with the left hand side of a rule from ''R'', and
* replacing the instantiated rule's right hand side into the instantiated term.
Formally, if is a renamed copy of a rewrite rule from ''R'', having no variables in common with a term ''s'', and the subterm is not a variable and is unifiable with via the mgu , then can be ''narrowed'' to the term , i.e. to the term , with the subterm at ''p'' replaced by . The situation that ''s'' can be narrowed to ''t'' is commonly denoted as ''s'' ↝ ''t''.
Intuitively, a sequence of narrowing steps ''t''1 ↝ ''t''2 ↝ ... ↝ ''t''''n'' can be thought of as a sequence of rewrite steps ''t''1 → ''t''2 → ... → ''t''''n'', but with the initial term ''t''1 being further and further instantiated, as necessary to make each of the used rules applicable.
The above example paramodulation computation corresponds to the following narrowing sequence ("↓" indicating instantiation here):
The last term, ''v''2.''v''2.''nil'' can be syntactically unified with the original right hand side term ''a''.''a''.''nil''.
The ''narrowing lemma'' ensures that whenever an instance of a term ''s'' can be rewritten to a term ''t'' by a convergent term rewriting system, then ''s'' and ''t'' can be narrowed and rewritten to a term and , respectively, such that is an instance of .
Formally: whenever holds for some substitution σ, then there exist terms such that and and for some substitution τ.
Higher-order unification
Many applications require one to consider the unification of typed lambda-terms instead of first-order terms. Such unification is often called ''higher-order unification''. Higher-order unification is undecidable, and such unification problems do not have most general unifiers. For example, the unification problem , where the only variable is ''f'', has the
solutions , ,
, ,
and . A well studied branch of higher-order unification is the problem of unifying simply typed lambda terms modulo the equality determined by αβη conversions. Gérard Huet
Gérard Pierre Huet (; born 7 July 1947) is a French computer scientist, linguist and mathematician. He is senior research director at INRIA and mostly known for his major and seminal contributions to type theory, programming language theory and ...
gave a semi-decidable (pre-)unification algorithm that allows a systematic search of the space of unifiers (generalizing the unification algorithm of Martelli-Montanari with rules for terms containing higher-order variables) that seems to work sufficiently well in practice. Huet and Gilles Dowek have written articles surveying this topic.
Several subsets of higher-order unification are well-behaved, in that they are decidable and have a most-general unifier for solvable problems. One such subset is the previously described first-order terms. Higher-order pattern unification, due to Dale Miller, is another such subset. The higher-order logic programming languages λProlog
λProlog, also written lambda Prolog, is a logic programming language featuring polymorphic typing, modular programming, and higher-order programming. These extensions to Prolog are derived from the higher-order hereditary Harrop formulas used ...
and Twelf Twelf is an implementation of the logical framework LF developed by Frank Pfenning and Carsten Schürmann at Carnegie Mellon University. It is used for logic programming and for the formalization of programming language theory.
Introduction
At ...
have switched from full higher-order unification to implementing only the pattern fragment; surprisingly pattern unification is sufficient for almost all programs, if each non-pattern unification problem is suspended until a subsequent substitution puts the unification into the pattern fragment. A superset of pattern unification called functions-as-constructors unification is also well-behaved. The Zipperposition theorem prover has an algorithm integrating these well-behaved subsets into a full higher-order unification algorithm.
In computational linguistics, one of the most influential theories of elliptical construction
In linguistics, ellipsis () or an elliptical construction is the omission from a clause of one or more words that are nevertheless understood in the context of the remaining elements. There are numerous distinct types of ellipsis acknowledged in ...
is that ellipses are represented by free variables whose values are then determined using Higher-Order Unification. For instance, the semantic representation of "Jon likes Mary and Peter does too" is and the value of R (the semantic representation of the ellipsis) is determined by the equation . The process of solving such equations is called Higher-Order Unification.
Wayne Snyder gave a generalization of both higher-order unification and E-unification, i.e. an algorithm to unify lambda-terms modulo an equational theory.
See also
*Rewriting
In mathematics, computer science, and logic, rewriting covers a wide range of methods of replacing subterms of a formula with other terms. Such methods may be achieved by rewriting systems (also known as rewrite systems, rewrite engines, or reduc ...
* Admissible rule
* Explicit substitution in lambda calculus
In mathematical logic, the lambda calculus (also written as ''λ''-calculus) is a formal system for expressing computability, computation based on function Abstraction (computer science), abstraction and function application, application using var ...
*Mathematical equation solving
In mathematics, to solve an equation is to find its solutions, which are the values (numbers, functions, sets, etc.) that fulfill the condition stated by the equation, consisting generally of two expressions related by an equals sign. When s ...
* Dis-unification: solving inequations between symbolic expression
* Anti-unification: computing a least general generalization (lgg) of two terms, dual to computing a most general instance (mgu)
* Subsumption lattice, a lattice having unification as meet and anti-unification as join
*Ontology alignment
Ontology alignment, or ontology matching, is the process of determining correspondences between concepts in ontologies. A set of correspondences is also called an alignment. The phrase takes on a slightly different meaning, in computer science, c ...
(use ''unification'' with semantic equivalence {{about, semantic equivalence of metadata, the concept in mathematical logic, Logical equivalence, the concept in linguistic semantics, Semantic equivalence (linguistics)
In computer metadata, semantic equivalence is a declaration that two data elem ...
)
Notes
References
Further reading
* Franz Baader and Wayne Snyder (2001)
"Unification Theory"
In John Alan Robinson and Andrei Voronkov
Andrei Anatolievič Voronkov (born 1959) is a Professor of Formal methods in the Department of Computer Science, University of Manchester, Department of Computer Science at the University of Manchester.
Education
Voronkov was educated at Novosibir ...
, editors, ''Handbook of Automated Reasoning
The ''Handbook of Automated Reasoning'' (, 2128 pages) is a collection of survey articles on the field of automated reasoning. Published in June 2001 by MIT Press, it is edited by John Alan Robinson and Andrei Voronkov. Volume 1 describes methods ...
'', volume I, pages 447–533. Elsevier Science Publishers.
* Gilles Dowek (2001)
"Higher-order Unification and Matching"
. In ''Handbook of Automated Reasoning''.
* Franz Baader and Tobias Nipkow (1998)
''Term Rewriting and All That''
Cambridge University Press.
* Franz Baader and (1993). "Unification Theory". In ''Handbook of Logic in Artificial Intelligence and Logic Programming''.
* Jean-Pierre Jouannaud and Claude Kirchner (1991). "Solving Equations in Abstract Algebras: A Rule-Based Survey of Unification". In ''Computational Logic: Essays in Honor of Alan Robinson''.
* Nachum Dershowitz
Nachum Dershowitz () is an Israeli computer scientist, known e.g. for the Dershowitz–Manna ordering and the Path_ordering_(term_rewriting), multiset path ordering used to prove Rewriting#Termination, termination of term rewrite systems.
Educat ...
and Jean-Pierre Jouannaud, ''Rewrite Systems'', in: Jan van Leeuwen
Jan van Leeuwen (born 17 December 1946 in Waddinxveen) is a Dutch computer scientist and emeritus professor of computer science at the Department of Information and Computing Sciences at Utrecht University. (ed.), '' Handbook of Theoretical Computer Science'', volume B ''Formal Models and Semantics'', Elsevier, 1990, pp. 243–320
* Jörg H. Siekmann (1990). "Unification Theory". In Claude Kirchner (editor) ''Unification''. Academic Press.
*
* Gérard Huet
Gérard Pierre Huet (; born 7 July 1947) is a French computer scientist, linguist and mathematician. He is senior research director at INRIA and mostly known for his major and seminal contributions to type theory, programming language theory and ...
and Derek C. Oppen (1980)
"Equations and Rewrite Rules: A Survey"
Technical report. Stanford University.
* {{cite journal , last1 = Raulefs , first1 = Peter , last2 = Siekmann , first2 = Jörg , last3 = Szabó , first3 = P. , last4 = Unvericht , first4 = E. , year = 1979 , title = A short survey on the state of the art in matching and unification problems , journal = ACM SIGSAM Bulletin , volume = 13 , issue = 2 , pages = 14–20 , doi = 10.1145/1089208.1089210 , s2cid = 17033087
* Claude Kirchner and Hélène Kirchner. ''Rewriting, Solving, Proving''. In preparation.
Automated theorem proving
Logic programming
Rewriting systems
Logic in computer science
Type theory