Anti-unification explained
Anti-unification is the process of constructing a generalization common to two given symbolic expressions. As in unification, several frameworks are distinguished depending on which expressions (also called terms) are allowed, and which expressions are considered equal. If variables representing functions are allowed in an expression, the process is called "higher-order anti-unification", otherwise "first-order anti-unification". If the generalization is required to have an instance literally equal to each input expression, the process is called "syntactical anti-unification", otherwise "E-anti-unification", or "anti-unification modulo theory".
An anti-unification algorithm should compute for given expressions a complete and minimal generalization set, that is, a set covering all generalizations and containing no redundant members, respectively. Depending on the framework, a complete and minimal generalization set may have one, finitely many, or possibly infinitely many members, or may not exist at all;[1] it cannot be empty, since a trivial generalization exists in any case. For first-order syntactical anti-unification, Gordon Plotkin[2] [3] gave an algorithm that computes a complete and minimal singleton generalization set containing the so-called "least general generalization" (lgg).
Anti-unification should not be confused with dis-unification. The latter means the process of solving systems of inequations, that is of finding values for the variables such that all given inequations are satisfied.[4] This task is quite different from finding generalizations.
Prerequisites
Formally, an anti-unification approach presupposes
- An infinite set V of variables. For higher-order anti-unification, it is convenient to choose V disjoint from the set of lambda-term bound variables.
- A set T of terms such that V ⊆ T. For first-order and higher-order anti-unification, T is usually the set of first-order terms (terms built from variable and function symbols) and lambda terms (terms containing some higher-order variables), respectively.
- An equivalence relation
on
, indicating which terms are considered equal. For higher-order anti-unification, usually
if
and
are alpha equivalent. For first-order E-anti-unification,
reflects the background knowledge about certain function symbols; for example, if
is considered commutative,
if
results from
by swapping the arguments of
at some (possibly all) occurrences.
[5] If there is no background knowledge at all, then only literally, or syntactically, identical terms are considered equal.
First-order term
See main article: Term (logic). Given a set
of variable symbols, a set
of constant symbols and sets
of
-ary function symbols, also called operator symbols, for each natural number
, the set of (unsorted first-order) terms
is
recursively defined to be the smallest set with the following properties:
[6] - every variable symbol is a term: V ⊆ T,
- every constant symbol is a term: C ⊆ T,
- from every n terms t1,...,tn, and every n-ary function symbol f ∈ Fn, a larger term
can be built.For example, if
x ∈
V is a variable symbol, 1 ∈
C is a constant symbol, and add ∈
F2 is a binary function symbol, then
x ∈
T, 1 ∈
T, and (hence) add(
x,1) ∈
T by the first, second, and third term building rule, respectively. The latter term is usually written as
x+1, using
Infix notation and the more common operator symbol + for convenience.
Higher-order term
See main article: Lambda calculus.
Substitution
See main article: Substitution (logic). A substitution is a mapping
from variables to terms; the notation
\{x1\mapstot1,\ldots,xk\mapstotk\}
refers to a substitution mapping each variable
to the term
, for
, and every other variable to itself. Applying that substitution to a term is written in postfix notation as
t\{x1\mapstot1,\ldots,xk\mapstotk\}
; it means to (simultaneously) replace every occurrence of each variable
in the term by
. The result of applying a substitution to a term is called an
instance of that term .As a first-order example, applying the substitution
\{x\mapstoh(a,y),z\mapstob\}
to the term
Generalization, 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
is
commutative, since then
(x ⊕ a)\{x\mapstob\}=b ⊕ a\equiva ⊕ 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,
is a variant of
, since
f(x1,a,g(z1),y1)\{x1\mapstox2,y1\mapstoy2,z1\mapstoz2\}=f(x2,a,g(z2),y2)
and
f(x2,a,g(z2),y2)\{x2\mapstox1,y2\mapstoy1,z2\mapstoz1\}=f(x1,a,g(z1),y1)
.However,
is
not a variant of
, since no substitution can transform the latter term into the former one, although
\{x1\mapstox2,z1\mapstox2,y1\mapstox2\}
achieves the reverse direction.The latter term is hence properly more special than the former one.
A substitution
is
more special than, or
subsumed by, a substitution
if
is more special than
for each variable
.For example,
\{x\mapstof(u),y\mapstof(f(u))\}
is more special than
\{x\mapstoz,y\mapstof(z)\}
, since
and
is more special than
and
, respectively.
Anti-unification problem, generalization set
An anti-unification problem is a pair
of terms.A term
is a common
generalization, or
anti-unifier, of
and
if
and
for some substitutions
.For a given anti-unification problem, a set
of anti-unifiers is called
complete if each generalization subsumes some term
; the set
is called
minimal if none of its members subsumes another one.
First-order syntactical anti-unification
The framework of first-order syntactical anti-unification is based on
being the set of
first-order terms (over some given set
of variables,
of constants and
of
-ary function symbols) and on
being
syntactic equality.In this framework, each anti-unification problem
has a complete, and obviously minimal,
singleton solution set
. Its member
is called the
least general generalization (lgg) of the problem, it has an instance syntactically equal to
and another one syntactically equal to
.Any common generalization of
and
subsumes
.The lgg is unique up to variants: if
and
are both complete and minimal solution sets of the same syntactical anti-unification problem, then
and
for some terms
and
, that are renamings of each other.
\phi:T x T\longrightarrowV
, that is, a mapping assigning each pair
of terms an own variable
, such that no two pairs share the same variable.
[7] The algorithm consists of two rules:
f(s1,...,sn)\sqcupf(t1,\ldots,tn)
|
| f(s1\sqcupt1,\ldots,sn\sqcuptn)
|
|
|
| if previous rule not applicable | |
For example,
(0*0)\sqcup(4*4)\rightsquigarrow(0\sqcup4)*(0\sqcup4)\rightsquigarrow\phi(0,4)*\phi(0,4)\rightsquigarrowx*x
; this least general generalization reflects the common property of both inputs of being square numbers.
Plotkin used his algorithm to compute the "relative least general generalization (rlgg)" of two clause sets in first-order logic, which was the basis of the Golem approach to inductive logic programming.
First-order anti-unification modulo theory
- https://aaai.org/papers/flairs-2002-064 . Svetla . Boytcheva . Zdravko . Markov . An Algorithm for Inducing Least Generalization Under Relative Implication . Proc. FLAIRS-02 . AAAI . 322 - 326 . 2002 .
- Temur. Kutsia. Jordi. Levy. Mateu. Villaret. Anti-Unification for Unranked Terms and Hedges. Journal of Automated Reasoning. 52. 2. 155–190. 2014. 10.1007/s10817-013-9285-6. free. Software.
Equational theories
- One associative and commutative operation: ;
- Commutative theories: Franz. Baader. Franz Baader. Unification, Weak Unification, Upper Bound, Lower Bound, and Generalization Problems. Proc. 4th Conf. on Rewriting Techniques and Applications (RTA). Springer. LNCS. 488. 86–91. 1991. 10.1007/3-540-53904-2_88 .
- Free monoids:
- Regular congruence classes: ; Jochen . Burghardt . E-Generalization Using Grammars . Artificial Intelligence . 165 . 1 . 1–35 . 1403.8118 . 2005 . 10.1016/j.artint.2005.01.008 . 5328240 .
- A-, C-, AC-, ACU-theories with ordered sorts: Maria. Alpuente. Santiago. Escobar. Javier. Espert. Jose. Meseguer. A modular order-sorted equational generalization algorithm. Information and Computation. 2014. 10.1016/j.ic.2014.01.006. 235. 98–136. 2142/25871. free. free.
- Purely idempotent theories: David. Cerna. Temur. Kutsia. Idempotent Anti-Unification. ACM Transactions on Computational Logic. 2020. 21. 2. 1–32 . 10.1145/3359060 . 10.1145/3359060. 207861304 .
First-order sorted anti-unification
- Taxonomic sorts: Alan M.. Frisch. David. Page. Generalisation with Taxonomic Information. AAAI. 755–761. 1990. ; Alan M.. Frisch. C. David. Page Jr.. Generalizing Atoms in Constraint Logic. Proc. Conf. on Knowledge Representation. 1991. ; A.M.. Frisch. C.D.. Page. Building Theories into Instantiation. C.S.. Mellish. Proc. 14th IJCAI. Morgan Kaufmann. 1210–1216. 1995. 10.1.1.32.1610 .
- Feature terms: E.. Plaza. Cases as Terms: A Feature Term Approach to the Structured Representation of Cases. Proc. 1st International Conference on Case-Based Reasoning (ICCBR). Springer. LNCS. 1010. 0302-9743. 265–276. 1995.
- Peter. Idestam-Almquist. Generalization under Implication by Recursive Anti-Unification. Proc. 10th Conf. on Machine Learning. Morgan Kaufmann. 151–158. Jun 1993.
- A-, C-, AC-, ACU-theories with ordered sorts: see above
Nominal anti-unification
- Baumgartner, Alexander; Kutsia, Temur; Levy, Jordi; Villaret, Mateu (Jun 2013). Nominal Anti-Unification. Proc. RTA 2015. Vol. 36 of LIPIcs. Schloss Dagstuhl, 57-73. Software.
Applications
- https://link.springer.com/chapter/10.1007/978-3-642-11486-1_35 . Peter E.. Bulychev. Egor V.. Kostylev. Vladimir A.. Zakharov . Anti-Unification Algorithms and their Applications in Program Analysis . Amir Pnueli and Irina Virbitskaite and Andrei Voronkov . Perspectives of Systems Informatics (PSI) - 7th International Andrei Ershov Memorial Conference . Springer . LNCS . 5947 . 413 - 423 . 2009 . 10.1007/978-3-642-11486-1_35. 978-3-642-11485-4.
- Code factoring:
- Case-based reasoning:
- https://www.researchgate.net/publication/221045334 . Armengol. Enric. Plaza . Using Symbolic Descriptions to Explain Similarity on . Beatriz López and Joaquim Meléndez and Petia Radeva and Jordi Vitrià . Artificial Intelligence Research and Development, Proc. 8th Int. Conf. of the ACIA, CCIA . IOS Press . 239 - 246 . 2005 .
- Program synthesis: The idea of generalizing terms with respect to an equational theory can be traced back to Manna and Waldinger (1978, 1980) who desired to apply it in program synthesis. In section "Generalization", they suggest (on p. 119 of the 1980 article) to generalize reverse(l) and reverse(tail(l))<>[''head''(''l'')] to obtain reverse(l')<>m' . This generalization is only possible if the background equation u<>[]=u is considered.
- A Deductive Approach to Program Synthesis . Zohar Manna . Richard Waldinger . Zohar Manna . Richard Waldinger . . Technical Note . 177 . Dec 1978 . 2017-09-29 . 2017-02-27 . https://web.archive.org/web/20170227140017/http://www.sri.com/sites/default/files/uploads/publications/pdf/725.pdf . dead . - preprint of the 1980 article
- Zohar Manna and Richard Waldinger . A Deductive Approach to Program Synthesis . . 2 . 90–121 . Jan 1980 . 10.1145/357084.357090 . 14770735 .
- Natural language processing:
- Nino. Amiridze. Temur. Kutsia. Anti-Unification and Natural Language Processing. Fifth Workshop on Natural Language and Computer Science, NLCS'18. EasyChair Preprints . EasyChair Report No. 203. 2018. 10.29007/fkrh . 49322739 . free.
Higher-order anti-unification
- Calculus of constructions:
- Simply-typed lambda calculus (Input: Terms in the eta-long beta-normal form. Output: higher-order patterns):
- Simply-typed lambda calculus (Input: Terms in the eta-long beta-normal form. Output: Various fragments of the simply-typed lambda calculus including patterns):
- David. Cerna. Temur. Kutsia. A Generic Framework for Higher-Order Generalizations. 4th International Conference on Formal Structures for Computation and Deduction, FSCD, June 24–30, 2019, Dortmund, Germany. Schloss Dagstuhl - Leibniz-Zentrum für Informatik. 74–85. June 2019.
- Restricted Higher-Order Substitutions:
Notes and References
- Complete generalization sets always exist, but it may be the case that every complete generalization set is non-minimal.
- Gordon D.. Plotkin. A Note on Inductive Generalization. B.. Meltzer. D.. Michie. Machine Intelligence. 5. 153–163. 1970.
- Gordon D.. Plotkin. A Further Note on Inductive Generalization. B.. Meltzer. D.. Michie. Machine Intelligence. 6. 101–124. 1971.
- Comon referred in 1986 to inequation-solving as "anti-unification", which nowadays has become quite unusual. Hubert. Comon. Sufficient Completeness, Term Rewriting Systems and 'Anti-Unification'. Proc. 8th International Conference on Automated Deduction. Springer. LNCS. 230. 128–140. 1986.
- E.g.
a ⊕ (b ⊕ f(x))\equiva ⊕ (f(x) ⊕ b)\equiv(b ⊕ f(x)) ⊕ a\equiv(f(x) ⊕ b) ⊕ a
- Book: C.C. Chang . H. Jerome Keisler . Model Theory. 1977. 73. North Holland. A. Heyting . H.J. Keisler . A. Mostowski . A. Robinson . P. Suppes . Studies in Logic and the Foundation of Mathematics.
- here: Sect.1.3
- From a theoretical viewpoint, such a mapping exists, since both
and
are countably infinite sets; for practical purposes,
can be built up as needed, remembering assigned mappings
\langles,t,\phi(s,t)\rangle
in a hash table.