Anti-unification (computer science)

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 VT. 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 ${\displaystyle \equiv }$ on ${\displaystyle T}$, indicating which terms are considered equal. For higher-order anti-unification, usually ${\displaystyle t\equiv u}$ if ${\displaystyle t}$ and ${\displaystyle u}$ are alpha equivalent. For first-order E-anti-unification, ${\displaystyle \equiv }$ reflects the background knowledge about certain function symbols; for example, if ${\displaystyle \oplus }$ is considered commutative, ${\displaystyle t\equiv u}$ if ${\displaystyle u}$ results from ${\displaystyle t}$ by swapping the arguments of ${\displaystyle \oplus }$ 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 ${\displaystyle V}$ of variable symbols, a set ${\displaystyle C}$ of constant symbols and sets ${\displaystyle F_{n}}$ of ${\displaystyle n}$-ary function symbols, also called operator symbols, for each natural number ${\displaystyle n\geq 1}$, the set of (unsorted first-order) terms ${\displaystyle T}$ is recursively defined to be the smallest set with the following properties:[3]

• every variable symbol is a term: VT,
• every constant symbol is a term: CT,
• from every n terms t1,…,tn, and every n-ary function symbol fFn, a larger term ${\displaystyle f(t_{1},\ldots ,t_{n})}$ 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.

Substitution

A substitution is a mapping ${\displaystyle \sigma :V\longrightarrow T}$ from variables to terms; the notation ${\displaystyle \{x_{1}\mapsto t_{1},\ldots ,x_{k}\mapsto t_{k}\}}$ refers to a substitution mapping each variable ${\displaystyle x_{i}}$ to the term ${\displaystyle t_{i}}$, for ${\displaystyle i=1,\ldots ,k}$, and every other variable to itself. Applying that substitution to a term t is written in postfix notation as ${\displaystyle t\{x_{1}\mapsto t_{1},\ldots ,x_{k}\mapsto t_{k}\}}$; it means to (simultaneously) replace every occurrence of each variable ${\displaystyle x_{i}}$ in the term t by ${\displaystyle t_{i}}$. The result of applying a substitution σ to a term t is called an instance of that term t. As a first-order example, applying the substitution ${\displaystyle \{x\mapsto h(a,y),z\mapsto b\}}$ to the term

 f( x , a, g( z ), y) yields f( h(a,y) , a, g( b ), y) .

Generalization, specialization

If a term ${\displaystyle t}$ has an instance equivalent to a term ${\displaystyle u}$, that is, if ${\displaystyle t\sigma \equiv u}$ for some substitution ${\displaystyle \sigma }$, then ${\displaystyle t}$ is called more general than ${\displaystyle u}$, and ${\displaystyle u}$ is called more special than, or subsumed by, ${\displaystyle t}$. For example, ${\displaystyle x\oplus a}$ is more general than ${\displaystyle a\oplus b}$ if ${\displaystyle \oplus }$ is commutative, since then ${\displaystyle (x\oplus a)\{x\mapsto b\}=b\oplus a\equiv a\oplus b}$.

If ${\displaystyle \equiv }$ 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, ${\displaystyle f(x_{1},a,g(z_{1}),y_{1})}$ is a variant of ${\displaystyle f(x_{2},a,g(z_{2}),y_{2})}$, since ${\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})}$ and ${\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})}$. However, ${\displaystyle f(x_{1},a,g(z_{1}),y_{1})}$ is not a variant of ${\displaystyle f(x_{2},a,g(x_{2}),x_{2})}$, since no substitution can transform the latter term into the former one, although ${\displaystyle \{x_{1}\mapsto x_{2},z_{1}\mapsto x_{2},y_{1}\mapsto x_{2}\}}$ achieves the reverse direction. The latter term is hence properly more special than the former one.

A substitution ${\displaystyle \sigma }$ is more special than, or subsumed by, a substitution ${\displaystyle \tau }$ if ${\displaystyle x\sigma }$ is more special than ${\displaystyle x\tau }$ for each variable ${\displaystyle x}$. For example, ${\displaystyle \{x\mapsto f(u),y\mapsto f(f(u))\}}$ is more special than ${\displaystyle \{x\mapsto z,y\mapsto f(z)\}}$, since ${\displaystyle f(u)}$ and ${\displaystyle f(f(u))}$ is more special than ${\displaystyle z}$ and ${\displaystyle f(z)}$, respectively.

Anti-unification problem, generalization set

An anti-unification problem is a pair ${\displaystyle \langle t_{1},t_{2}\rangle }$ of terms. A term ${\displaystyle t}$ is a common generalization, or anti-unifier, of ${\displaystyle t_{1}}$ and ${\displaystyle t_{2}}$ if ${\displaystyle t\sigma _{1}\equiv t_{1}}$ and ${\displaystyle t\sigma _{2}\equiv t_{2}}$ for some substitutions ${\displaystyle \sigma _{1},\sigma _{2}}$. For a given anti-unification problem, a set ${\displaystyle S}$ of anti-unifiers is called complete if each generalization subsumes some term ${\displaystyle t\in S}$; the set ${\displaystyle S}$ 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 ${\displaystyle T}$ being the set of first-order terms (over some given set ${\displaystyle V}$ of variables, ${\displaystyle C}$ of constants and ${\displaystyle F_{n}}$ of ${\displaystyle n}$-ary function symbols) and on ${\displaystyle \equiv }$ being syntactic equality. In this framework, each anti-unification problem ${\displaystyle \langle t_{1},t_{2}\rangle }$ has a complete, and obviously minimal, singleton solution set ${\displaystyle \{t\}}$. Its member ${\displaystyle t}$ is called the least general generalization (lgg) of the problem, it has an instance syntactically equal to ${\displaystyle t_{1}}$ and another one syntactically equal to ${\displaystyle t_{2}}$. Any common generalization of ${\displaystyle t_{1}}$ and ${\displaystyle t_{2}}$ subsumes ${\displaystyle t}$. The lgg is unique up to variants: if ${\displaystyle S_{1}}$ and ${\displaystyle S_{2}}$ are both complete and minimal solution sets of the same syntactical anti-unification problem, then ${\displaystyle S_{1}=\{s_{1}\}}$ and ${\displaystyle S_{2}=\{s_{2}\}}$ for some terms ${\displaystyle s_{1}}$ and ${\displaystyle s_{2}}$, 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 ${\displaystyle \phi :T\times T\longrightarrow V}$, that is, a mapping assigning each pair ${\displaystyle s,t}$ of terms an own variable ${\displaystyle \phi (s,t)}$, such that no two pairs share the same variable. [note 4] The algorithm consists of two rules:

 ${\displaystyle f(s_{1},\dots ,s_{n})\sqcup f(t_{1},\ldots ,t_{n})}$ ${\displaystyle \rightsquigarrow }$ ${\displaystyle f(s_{1}\sqcup t_{1},\ldots ,s_{n}\sqcup t_{n})}$ ${\displaystyle s\sqcup t}$ ${\displaystyle \rightsquigarrow }$ ${\displaystyle \phi (s,t)}$ if previous rule not applicable

For example, ${\displaystyle (0*0)\sqcup (4*4)\rightsquigarrow (0\sqcup 4)*(0\sqcup 4)\rightsquigarrow \phi (0,4)*\phi (0,4)\rightsquigarrow x*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

• Jacobson, Erik (Jun 1991), Unification and Anti-Unification, Technical Report
• Østvold, Bjarte M. (Apr 2004), A Functional Reconstruction of Anti-Unification, NR Note, DART/04/04, Norwegian Computing Center
• Boytcheva, Svetla; Markov, Zdravko (2002). "An Algorithm for Inducing Least Generalization Under Relative Implication".
• Kutsia, Temur; Levy, Jordi; Villaret, Mateu (2014). "Anti-Unification for Unranked Terms and Hedges" (PDF). Journal of Automated Reasoning. Springer. 52 (2): 155–190. doi:10.1007/s10817-013-9285-6. Software.

Equational theories

• One associative and commutative operation: Pottier, Loic (Feb 1989), Algorithms des completion et generalisation en logic du premier ordre; 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". Proc. 4th Conf. on Rewriting Techniques and Applications (RTA). LNCS. 488. Springer. pp. 86–91.
• Free monoids: Biere, A. (1993), Normalisierung, Unifikation und Antiunifikation in Freien Monoiden (PDF), Univ. Karlsruhe, Germany
• Regular congruence classes: Heinz, Birgit (Dec 1995), Anti-Unifikation modulo Gleichungstheorie und deren Anwendung zur Lemmagenerierung, GMD Berichte, 261, TU Berlin, ISBN 3-486-23873-6; Burghardt, Jochen (2005). "E-Generalization Using Grammars" (PDF). Artificial Intelligence Journal. Elsevier. 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" (PDF). Information and Computation. Elsevier. 235: 98–136. doi:10.1016/j.ic.2014.01.006.

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". Proc. Conf. on Knowledge Representation.; Frisch, A.M.; Page, C.D. (1995). "Building Theories into Instantiation". In Mellish, C.S. Proc. 14th IJCAI. Morgan Kaufmann. pp. 1210–1216.
• Feature terms: Plaza, E. (1995). "Cases as Terms: A Feature Term Approach to the Structured Representation of Cases". Proc. 1st International Conference on Case-Based Reasoning (ICCBR). LNCS. 1010. Springer. pp. 265–276. ISSN 0302-9743.
• Idestam-Almquist, Peter (Jun 1993). "Generalization under Implication by Recursive Anti-Unification". Proc. 10th Conf. on Machine Learning. Morgan Kaufmann. pp. 151–158.
• Fischer, Cornelia (May 1994), PAntUDE – An Anti-Unification Algorithm for Expressing Refined Generalizations, Research Report, TM-94-04, DFKI
• 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".; Bulychev, Peter E.; Kostylev, Egor V.; Zakharov, Vladimir A. (2009). "Anti-Unification Algorithms and their Applications in Program Analysis".
• Code factoring: Cottrell, Rylan (Sep 2008), Semi-automating Small-Scale Source Code Reuse via Structural Correspondence, Univ. Calgary
• 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.
• Case-based reasoning: Armengol, Eva; Plaza, Enric (2005). "Using Symbolic Descriptions to Explain Similarity on CBR".

Anti-unification of trees and linguistic applications

• Parse trees for sentences can be subject to least general generalization to derive a maximal common sub-parse trees for language learning. There are applications in search and text classification.[4]
• Parse thickets for paragraphs as graphs can be subject to least general generalization.[5]
• Operation of generalization commutes with the operation of transition from syntactic (parse trees) to semantic (symbolic expressions) level. The latter can then be subject to conventional anti-unification.[6][7]

Notes

1. ^ Complete generalization sets always exist, but it may be the case that every complete generalization set is non-minimal.
2. ^ 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'". Proc. 8th International Conference on Automated Deduction. LNCS. 230. Springer. pp. 128–140.
3. ^ E.g. ${\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}$
4. ^ From a theoretical viewpoint, such a mapping exists, since both ${\displaystyle V}$ and ${\displaystyle T\times T}$ are countably infinite sets; for practical purposes, ${\displaystyle \phi }$ can be built up as needed, remembering assigned mappings ${\displaystyle \langle s,t,\phi (s,t)\rangle }$ in a hash table.

References

1. ^ a b Plotkin, Gordon D. (1970). Meltzer, B.; Michie, D., eds. "A Note on Inductive Generalization". Machine Intelligence. Edinburgh University Press. 5: 153–163.
2. ^ a b Plotkin, Gordon D. (1971). Meltzer, B.; Michie, D., eds. "A Further Note on Inductive Generalization". Machine Intelligence. Edinburgh University Press. 6: 101–124.
3. ^ C.C. Chang; H. Jerome Keisler (1977). A. Heyting; H.J. Keisler; A. Mostowski; A. Robinson; P. Suppes, eds. Model Theory. Studies in Logic and the Foundation of Mathematics. 73. North Holland.; here: Sect.1.3
4. ^ Boris Galitsky; Josep Lluís de la Rose; Gabor Dobrocsi (2011). "Mapping Syntactic to Semantic Generalizations of Linguistic Parse Trees". FLAIRS Conference.
5. ^ Boris Galitsky; Kuznetsov SO; Usikov DA (2013). "Parse Thicket Representation for Multi-sentence Search". Lecture Notes in Computer Science. 7735: 1072–1091. doi:10.1007/978-3-642-35786-2_12.
6. ^ Boris Galitsky; Gabor Dobrocsi; Josep Lluís de la Rosa; Sergei O. Kuznetsov (2010). "From Generalization of Syntactic Parse Trees to Conceptual Graphs". Lecture Notes in Computer Science. 6208: 185–190. doi:10.1007/978-3-642-14197-3_19.
7. ^ Boris Galitsky; de la Rosa JL; Dobrocsi G. (2012). "Inferring the semantic properties of sentences by mining syntactic parse trees". Data & Knowledge Engineering. 81-82: 21–45. doi:10.1016/j.datak.2012.07.003.