Anti-unification
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;[note 1] it cannot be empty, since a trivial generalization exists in any case. For first-order syntactical anti-unification, Gordon Plotkin[1][2] 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.[note 2] 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 [math]\displaystyle{ \equiv }[/math] on [math]\displaystyle{ T }[/math], indicating which terms are considered equal. For higher-order anti-unification, usually [math]\displaystyle{ t \equiv u }[/math] if [math]\displaystyle{ t }[/math] and [math]\displaystyle{ u }[/math] are alpha equivalent. For first-order E-anti-unification, [math]\displaystyle{ \equiv }[/math] reflects the background knowledge about certain function symbols; for example, if [math]\displaystyle{ \oplus }[/math] is considered commutative, [math]\displaystyle{ t \equiv u }[/math] if [math]\displaystyle{ u }[/math] results from [math]\displaystyle{ t }[/math] by swapping the arguments of [math]\displaystyle{ \oplus }[/math] at some (possibly all) occurrences.[note 3] If there is no background knowledge at all, then only literally, or syntactically, identical terms are considered equal.
First-order term
Given a set [math]\displaystyle{ V }[/math] of variable symbols, a set [math]\displaystyle{ C }[/math] of constant symbols and sets [math]\displaystyle{ F_n }[/math] of [math]\displaystyle{ n }[/math]-ary function symbols, also called operator symbols, for each natural number [math]\displaystyle{ n \geq 1 }[/math], the set of (unsorted first-order) terms [math]\displaystyle{ T }[/math] is recursively defined to be the smallest set with the following properties:[3]
- 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 [math]\displaystyle{ f(t_1,\ldots,t_n) }[/math] 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
Substitution
A substitution is a mapping [math]\displaystyle{ \sigma: V \longrightarrow T }[/math] from variables to terms; the notation [math]\displaystyle{ \{x_1 \mapsto t_1, \ldots, x_k \mapsto t_k \} }[/math] refers to a substitution mapping each variable [math]\displaystyle{ x_i }[/math] to the term [math]\displaystyle{ t_i }[/math], for [math]\displaystyle{ i=1,\ldots,k }[/math], and every other variable to itself. Applying that substitution to a term t is written in postfix notation as [math]\displaystyle{ t \{x_1 \mapsto t_1, \ldots, x_k \mapsto t_k \} }[/math]; it means to (simultaneously) replace every occurrence of each variable [math]\displaystyle{ x_i }[/math] in the term t by [math]\displaystyle{ t_i }[/math]. The result tσ of applying a substitution σ to a term t is called an instance of that term t. As a first-order example, applying the substitution [math]\displaystyle{ \{x \mapsto h(a,y), z \mapsto b\} }[/math] to the term
f( x , a, g( z ), y) yields f( h(a,y) , a, g( b ), y) .
Generalization, specialization
If a term [math]\displaystyle{ t }[/math] has an instance equivalent to a term [math]\displaystyle{ u }[/math], that is, if [math]\displaystyle{ t \sigma \equiv u }[/math] for some substitution [math]\displaystyle{ \sigma }[/math], then [math]\displaystyle{ t }[/math] is called more general than [math]\displaystyle{ u }[/math], and [math]\displaystyle{ u }[/math] is called more special than, or subsumed by, [math]\displaystyle{ t }[/math]. For example, [math]\displaystyle{ x \oplus a }[/math] is more general than [math]\displaystyle{ a \oplus b }[/math] if [math]\displaystyle{ \oplus }[/math] is commutative, since then [math]\displaystyle{ (x \oplus a)\{x \mapsto b\} = b \oplus a \equiv a \oplus b }[/math].
If [math]\displaystyle{ \equiv }[/math] 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, [math]\displaystyle{ f(x_1,a,g(z_1),y_1) }[/math] is a variant of [math]\displaystyle{ f(x_2,a,g(z_2),y_2) }[/math], since [math]\displaystyle{ 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) }[/math] and [math]\displaystyle{ 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) }[/math]. However, [math]\displaystyle{ f(x_1,a,g(z_1),y_1) }[/math] is not a variant of [math]\displaystyle{ f(x_2,a,g(x_2),x_2) }[/math], since no substitution can transform the latter term into the former one, although [math]\displaystyle{ \{x_1 \mapsto x_2, z_1 \mapsto x_2, y_1 \mapsto x_2 \} }[/math] achieves the reverse direction. The latter term is hence properly more special than the former one.
A substitution [math]\displaystyle{ \sigma }[/math] is more special than, or subsumed by, a substitution [math]\displaystyle{ \tau }[/math] if [math]\displaystyle{ x \sigma }[/math] is more special than [math]\displaystyle{ x \tau }[/math] for each variable [math]\displaystyle{ x }[/math]. For example, [math]\displaystyle{ \{ x \mapsto f(u), y \mapsto f(f(u)) \} }[/math] is more special than [math]\displaystyle{ \{ x \mapsto z, y \mapsto f(z) \} }[/math], since [math]\displaystyle{ f(u) }[/math] and [math]\displaystyle{ f(f(u)) }[/math] is more special than [math]\displaystyle{ z }[/math] and [math]\displaystyle{ f(z) }[/math], respectively.
Anti-unification problem, generalization set
An anti-unification problem is a pair [math]\displaystyle{ \langle t_1, t_2 \rangle }[/math] of terms. A term [math]\displaystyle{ t }[/math] is a common generalization, or anti-unifier, of [math]\displaystyle{ t_1 }[/math] and [math]\displaystyle{ t_2 }[/math] if [math]\displaystyle{ t \sigma_1 \equiv t_1 }[/math] and [math]\displaystyle{ t \sigma_2 \equiv t_2 }[/math] for some substitutions [math]\displaystyle{ \sigma_1, \sigma_2 }[/math]. For a given anti-unification problem, a set [math]\displaystyle{ S }[/math] of anti-unifiers is called complete if each generalization subsumes some term [math]\displaystyle{ t \in S }[/math]; the set [math]\displaystyle{ S }[/math] 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 [math]\displaystyle{ T }[/math] being the set of first-order terms (over some given set [math]\displaystyle{ V }[/math] of variables, [math]\displaystyle{ C }[/math] of constants and [math]\displaystyle{ F_n }[/math] of [math]\displaystyle{ n }[/math]-ary function symbols) and on [math]\displaystyle{ \equiv }[/math] being syntactic equality. In this framework, each anti-unification problem [math]\displaystyle{ \langle t_1, t_2 \rangle }[/math] has a complete, and obviously minimal, singleton solution set [math]\displaystyle{ \{t\} }[/math]. Its member [math]\displaystyle{ t }[/math] is called the least general generalization (lgg) of the problem, it has an instance syntactically equal to [math]\displaystyle{ t_1 }[/math] and another one syntactically equal to [math]\displaystyle{ t_2 }[/math]. Any common generalization of [math]\displaystyle{ t_1 }[/math] and [math]\displaystyle{ t_2 }[/math] subsumes [math]\displaystyle{ t }[/math]. The lgg is unique up to variants: if [math]\displaystyle{ S_1 }[/math] and [math]\displaystyle{ S_2 }[/math] are both complete and minimal solution sets of the same syntactical anti-unification problem, then [math]\displaystyle{ S_1 = \{ s_1\} }[/math] and [math]\displaystyle{ S_2 = \{ s_2 \} }[/math] for some terms [math]\displaystyle{ s_1 }[/math] and [math]\displaystyle{ s_2 }[/math], that are renamings of each other.
Plotkin[1][2] has given an algorithm to compute the lgg of two given terms. It presupposes an injective mapping [math]\displaystyle{ \phi: T \times T \longrightarrow V }[/math], that is, a mapping assigning each pair [math]\displaystyle{ s,t }[/math] of terms an own variable [math]\displaystyle{ \phi(s,t) }[/math], such that no two pairs share the same variable. [note 4] The algorithm consists of two rules:
[math]\displaystyle{ f(s_1,\dots,s_n) \sqcup f(t_1,\ldots,t_n) }[/math] [math]\displaystyle{ \rightsquigarrow }[/math] [math]\displaystyle{ f( s_1 \sqcup t_1, \ldots, s_n \sqcup t_n ) }[/math] [math]\displaystyle{ s \sqcup t }[/math] [math]\displaystyle{ \rightsquigarrow }[/math] [math]\displaystyle{ \phi(s,t) }[/math] if previous rule not applicable
For example, [math]\displaystyle{ (0*0) \sqcup (4*4) \rightsquigarrow (0 \sqcup 4)*(0 \sqcup 4) \rightsquigarrow \phi(0,4) * \phi(0,4) \rightsquigarrow x*x }[/math]; 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
- Jacobsen, Erik (Jun 1991), Unification and Anti-Unification, Technical Report, http://erikjacobsen.com/pdf/unification.pdf
- Østvold, Bjarte M. (Apr 2004), A Functional Reconstruction of Anti-Unification, NR Note, DART/04/04, Norwegian Computing Center, https://projects.nr.no/en/nrpublication?query=/file/nr-notat-dart-04-04.pdf
- Boytcheva, Svetla; Markov, Zdravko (2002). "Proc. FLAIRS-02". AAAI. pp. 322–326.
- Kutsia, Temur; Levy, Jordi; Villaret, Mateu (2014). "Anti-Unification for Unranked Terms and Hedges". Journal of Automated Reasoning 52 (2): 155–190. doi:10.1007/s10817-013-9285-6. https://link.springer.com/content/pdf/10.1007%2Fs10817-013-9285-6.pdf. Software.
Equational theories
- One associative and commutative operation: Pottier, Loic (Feb 1989), Algorithms des completion et generalisation en logic du premier ordre, https://www.theses.fr/1989NICE4261; Pottier, Loic (1989), Generalisation de termes en theorie equationelle – Cas associatif-commutatif, INRIA Report, 1056, INRIA
- Commutative theories: Baader, Franz (1991). "Unification, Weak Unification, Upper Bound, Lower Bound, and Generalization Problems". 488. Springer. pp. 86–91. doi:10.1007/3-540-53904-2_88. https://link.springer.com/chapter/10.1007/3-540-53904-2_88.
- Free monoids: Biere, A. (1993), Normalisierung, Unifikation und Antiunifikation in Freien Monoiden, Univ. Karlsruhe, Germany, http://fmv.jku.at/papers/Biere-Diploma-Thesis-1993.pdf
- Regular congruence classes: Heinz, Birgit (Dec 1995), Anti-Unifikation modulo Gleichungstheorie und deren Anwendung zur Lemmagenerierung, GMD Berichte, 261, TU Berlin, ISBN 978-3-486-23873-0; Burghardt, Jochen (2005). "E-Generalization Using Grammars". Artificial Intelligence 165 (1): 1–35. doi:10.1016/j.artint.2005.01.008.
- A-, C-, AC-, ACU-theories with ordered sorts: Alpuente, Maria; Escobar, Santiago; Espert, Javier; Meseguer, Jose (2014). "A modular order-sorted equational generalization algorithm". Information and Computation 235: 98–136. doi:10.1016/j.ic.2014.01.006.
- Purely idempotent theories: Cerna, David; Kutsia, Temur (2020). "Idempotent Anti-Unification". ACM Transactions on Computational Logic 21 (2): 1–32. doi:10.1145/3359060. https://dl.acm.org/doi/10.1145/3359060.
First-order sorted anti-unification
- Taxonomic sorts: Frisch, Alan M.; Page, David (1990). "Generalisation with Taxonomic Information". AAAI: 755–761.; Frisch, Alan M.; Page Jr., C. David (1991). "Generalizing Atoms in Constraint Logic". https://books.google.com/books?id=1wwZAQAAIAAJ&dq=%22Generalizing+Atoms+in+Constraint+Logic%22&pg=PA429.; Frisch, A.M.; Page, C.D. (1995). "Building Theories into Instantiation". in Mellish, C.S.. Morgan Kaufmann. pp. 1210–1216.
- Feature terms: Plaza, E. (1995). "Cases as Terms: A Feature Term Approach to the Structured Representation of Cases". 1010. Springer. pp. 265–276.
- Idestam-Almquist, Peter (Jun 1993). "Generalization under Implication by Recursive Anti-Unification". Morgan Kaufmann. pp. 151–158. https://books.google.com/books?id=TrqjBQAAQBAJ&dq=%22Generalization+under+Implication+by+Recursive+Anti-Unification%22&pg=PA151.
- Fischer, Cornelia (May 1994), PAntUDE – An Anti-Unification Algorithm for Expressing Refined Generalizations, Research Report, TM-94-04, DFKI, https://publikationen.sulb.uni-saarland.de/bitstream/20.500.11880/25109/1/TM_94_04.pdf
- 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
- Program analysis:
- Bulychev, Peter; Minea, Marius (2008). "Duplicate Code Detection Using Anti-Unification". Proceedings of the Spring/Summer Young Researchers' Colloquium on Software Engineering (2). https://cyberleninka.ru/article/n/14517244.;
- Bulychev, Peter E.; Kostylev, Egor V.; Zakharov, Vladimir A. (2009). "Perspectives of Systems Informatics (PSI) – 7th International Andrei Ershov Memorial Conference". in Amir Pnueli and Irina Virbitskaite and Andrei Voronkov. 5947. Springer. pp. 413–423. doi:10.1007/978-3-642-11486-1_35.
- Code factoring:
- Cottrell, Rylan (Sep 2008), Semi-automating Small-Scale Source Code Reuse via Structural Correspondence, Univ. Calgary, https://pages.cpsc.ucalgary.ca/~denzinge/papers/fse08.pdf
- Induction proving:
- Heinz, Birgit (1994), Lemma Discovery by Anti-Unification of Regular Sorts, Technical Report, 94-21, TU Berlin
- Information Extraction:
- Thomas, Bernd (1999). "Anti-Unification Based Learning of T-Wrappers for Information Extraction". AAAI Technical Report WS-99-11: 15–20. https://www.aaai.org/Papers/Workshops/1999/WS-99-11/WS99-11-003.pdf.
- Case-based reasoning:
- Armengol; Plaza, Enric (2005). "Artificial Intelligence Research and Development, Proc. 8th Int. Conf. of the ACIA, CCIA". in Beatriz López and Joaquim Meléndez and Petia Radeva and Jordi Vitrià. IOS Press. pp. 239–246.
- 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.
- Zohar Manna; Richard Waldinger (Dec 1978). A Deductive Approach to Program Synthesis (Technical Note). http://www.sri.com/sites/default/files/uploads/publications/pdf/725.pdf. Retrieved 2017-09-29. — preprint of the 1980 article
- Zohar Manna and Richard Waldinger (Jan 1980). "A Deductive Approach to Program Synthesis". ACM Transactions on Programming Languages and Systems 2: 90–121. doi:10.1145/357084.357090.
- Natural language processing:
- Amiridze, Nino; Kutsia, Temur (2018). "Anti-Unification and Natural Language Processing". Fifth Workshop on Natural Language and Computer Science, NLCS'18. EasyChair Preprints EasyChair Report No. 203. doi:10.29007/fkrh.
Higher-order anti-unification
- Calculus of constructions:
- Pfenning, Frank (Jul 1991). "Unification and Anti-Unification in the Calculus of Constructions". Springer. pp. 74–85. https://www.cs.cmu.edu/~fp/papers/lics91.pdf.
- Simply-typed lambda calculus (Input: Terms in the eta-long beta-normal form. Output: higher-order patterns):
- Baumgartner, Alexander; Kutsia, Temur; Levy, Jordi; Villaret, Mateu (Jun 2013). A Variant of Higher-Order Anti-Unification. Proc. RTA 2013. Vol. 21 of LIPIcs. Schloss Dagstuhl, 113-127. Software.
- Simply-typed lambda calculus (Input: Terms in the eta-long beta-normal form. Output: Various fragments of the simply-typed lambda calculus including patterns):
- Cerna, David; Kutsia, Temur (June 2019). "A Generic Framework for Higher-Order Generalizations". Schloss Dagstuhl - Leibniz-Zentrum für Informatik. pp. 74–85. https://drops.dagstuhl.de/opus/volltexte/2019/10517/pdf/LIPIcs-FSCD-2019-10.pdf.
- Restricted Higher-Order Substitutions:
- Wagner, Ulrich (Apr 2002), Combinatorically Restricted Higher Order Anti-Unification, TU Berlin; Schmidt, Martin (Sep 2010), Restricted Higher-Order Anti-Unification for Heuristic-Driven Theory Projection, PICS-Report, 31-2010, Univ. Osnabrück, Germany, ISSN 1610-5389, http://ikw.uni-osnabrueck.de/de/system/files/31-2010.pdf
Notes
- ↑ Complete generalization sets always exist, but it may be the case that every complete generalization set is non-minimal.
- ↑ Comon referred in 1986 to inequation-solving as "anti-unification", which nowadays has become quite unusual. Comon, Hubert (1986). "Sufficient Completeness, Term Rewriting Systems and 'Anti-Unification'". 230. Springer. pp. 128–140.
- ↑ E.g. [math]\displaystyle{ a \oplus (b \oplus f(x)) \equiv a \oplus (f(x) \oplus b) \equiv (b \oplus f(x)) \oplus a \equiv (f(x) \oplus b) \oplus a }[/math]
- ↑ From a theoretical viewpoint, such a mapping exists, since both [math]\displaystyle{ V }[/math] and [math]\displaystyle{ T \times T }[/math] are countably infinite sets; for practical purposes, [math]\displaystyle{ \phi }[/math] can be built up as needed, remembering assigned mappings [math]\displaystyle{ \langle s,t,\phi(s,t) \rangle }[/math] in a hash table.
References
- ↑ 1.0 1.1 Plotkin, Gordon D. (1970). Meltzer, B.; Michie, D.. eds. "A Note on Inductive Generalization". Machine Intelligence 5: 153–163.
- ↑ 2.0 2.1 Plotkin, Gordon D. (1971). Meltzer, B.; Michie, D.. eds. "A Further Note on Inductive Generalization". Machine Intelligence 6: 101–124.
- ↑ C.C. Chang; H. Jerome Keisler (1977). Model Theory. Studies in Logic and the Foundation of Mathematics. 73. North Holland.; here: Sect.1.3
Original source: https://en.wikipedia.org/wiki/Anti-unification.
Read more |