Unification of Higher-order Patterns modulo Simple Syntactic Equational Theories

HAL is a multi-disciplinary open access archive for the deposit and dissemination of scientific research documents, whether they are published or not. The documents may come from teaching and research institutions in France or abroad, or from public or private research centers. L’archive ouverte pluridisciplinaire HAL, est destinée au dépôt et à la diffusion de documents scientifiques de niveau recherche, publiés ou non, émanant des établissements d’enseignement et de recherche français ou étrangers, des laboratoires publics ou privés. Unification of Higher-order Patterns modulo Simple Syntactic Equational Theories Alexandre Boudet


Introduction
Unification is a crucial mechanism in logic programming and automated theorem proving.Unification modulo an equational theory E has been introduced by Plotkin [20] and has become an area of research of its own.With the emergence of higher-order logic programming and rewrite systems [17,18,16], the issue of higher-order unification is of growing interest.Higher-order unification is known to be undecidable [10,8], but Miller has shown that the unification problem is decidable for patterns, which are terms of the simply-typed lambda-calculus in which the arguments of a free variable are always distinct bound variables ‡ .Patterns allow to define higher-order functions using pattern matching, as well as interesting higher-order rewrite systems.The aim of the present work is to apply the methods initiated by Kirchner for first-order E-unification to the case of pattern E-unification.This requires to adapt the mutation rule to the case of patterns.
In practice, patterns are very similar to first-order terms because the condition that the arguments of the free variables are pairwise distinct bound variables forbids to have free variables "in the middle" of the terms.The free variables (with their restricted kind of arguments) are at the leaves of a pattern.The syntactic theories have been defined by Kirchner [13,14] as those collapse-free equational theories which admit a finite presentation such that every equational theorem can be proved by using at most one axiom at the root.This property provides us with complete (non-deterministic) top-down strategies for searching proofs or unifiers.One may guess which axiom applies at the root and then pursue the search in the subterms.
A difficulty with pattern unification is that one needs to introduce new variables.For instance, the most general unifier of λxyz F ✁ x✂ y✄ ✆☎ λxyz G ✁ z✂ x✄ , where the free variables are F and G is σ ☎ ✞✝ F ✟ ✠ , where H is a new free variable.We will see that not only the solving of such flexible-flexible equations (i.e., having a free variable at the top on both sides) require to introduce new variables.On the other hand, new variables are not needed for first-order unification.Our ultimate goal is to take advantage of the resemblance of patterns with first-order terms for lifting the methods that have been developed for two decades for first-order E-unification.In the present paper we want to present an algorithm for pattern unification modulo syntactic theories which behaves exactly as in the first-order case, hence yielding in particular a terminating algorithm whenever the first-order algorithm terminates.For this, we will introduce a preliminary non-deterministic step in which a projection such as the above substitution σ is chosen.After this step, a first goal is achieved with an algorithm which does not introduce further new variables and whose (non-failure) rules behave as in first-order unification (in a sense that will be made precise later).Then, we will adapt Kirchner's mutation rule to the case of pattern unification.The flexible-flexible equations with the same head variable on both sides (like λxy F ✁ x✂ y✄ ✌☎ λxy F ✁ y✂ x✄ ) are frozen.Such equations are always solvable (by a projection), but we do not know how to test their compatibility with the rest of the problem in general.We will give an interpretation I of pattern unification problems in terms of first-order unification problems such that if a rule applies to P yeldinq Q, the corresponding rule of the first-order algorithm will apply to I ✁ P✄ yielding I ✁ Q✄ .Finally, we will show how to handle the equations like λxy F

✁
x✂ y✄ ✍☎ λxy F ✁ y✂ x✄ in the case where all the function symbols are decomposable.

Preliminaries
We assume the reader is familiar with simply-typed lambda-calculus, and equational unification.Some background is available in e.g.[9,12] for lambda-calculus and E-unification.

Patterns and equational theories
Given a set B of base types, the set T of all types is the closure of B under the (right-associative) function space constructor ✠ .The simply-typed lambda-terms are generated from a set ✎ τ✏ T V τ of typed variables and a set ✎ τ✏ T C τ of typed constants using the following construction rules: The order of a base type is 1, and the order of an arrow type τ ✠ τ✒ is the maximum of the order of τ plus 1 and the order of τ✒ .The order of a term is the order if its type.
We shall use the following notations: λx 1 ✓ ✔✓ ✔✓ λx n s will be written λx n s, or even λx s if n is not relevant.
If in a same expression x appears several times it denotes the same sequence of variables.The curlybracketed expression ✝ x n ☛ denotes the (multi) set ✝ x 1 ✂ ✔ ✕ ✂ x n ☛ .In addition, we will use the notation The free (resp.bound) variables of a term t are denoted by The positions of a term t are words over ✝ 0✂ 1☛ , Λ is the empty word (denoting the root position) and t p is the subterm of t at position p.The notation t ✁ u✂ p stands for a term t with a subterm u at position p, t ✁ u 1 ✂ ✔ ✕ ✂ u n ✂ for a term t having subterms u 1 ✂ ✔ ✕ ✂ u n .
Unless otherwise stated, we assume that the terms are in η-long β-normal form [9], the β and η rules being respectively oriented as follows: and α is a base type.In this case, F is said to have arity n.
The η-long β-normal form of a term t is denoted by t ☎ η β .A substitution σ is a mapping from a finite set of variables to terms of the same type, written Miller [17] has defined the patterns as those terms of the simply-typed lambda-calculus in which the arguments of a free variables are (η-equivalent to) pairwise distinct bound variables.x✄ ✂ y✄ are not patterns.Patterns have useful applications in higher-order logic programming [17], pattern rewrite systems [18,16,4], or definitions of functions by cases in functional programming languages.
It is known that higher-order unification and even second-order unification are undecidable [10,8].On the contrary, patterns have decidable and unitary unification : ) Pattern unification is decidable, and there exists an algorithm that computes a most general unifier of any solvable pattern unification problem.
The equational theories we consider here are the usual first-order equational theories: given a set E of (unordered) first-order axioms built over a signature F , there is an elementary equational proof s ✆ E t if there exist an axiom l ☎ r ✑ E, a position p of s and a substitution θ such that s p ☎ lθ and t ☎ s✁ rθ✂ p .If p ☎ Λ, we call this proof a Λ-step.The equational theory ☎ E generated by E is the reflexive transitive The following is a key theorem due to Tannen.It allows us to restrict our attention to ☎ E for deciding η-β-E-equivalence of terms in η-long, β-normal form :

Unification problems
Definition 1 Unification problems are inductively defined as follows: ✡ ☞☛ (the trivial unification problem) and ✌ (the unsolvable unification problem) are unification prob- lems.
✡ An equation s ☎ t where s and t are patterns of the same type is a unification problem.✡ If P and Q are unification problems and X is a variable, then P ✍ Q, P ✎ Q and ✁ ✑✏ X ✄ P are unification problems.
Any substitution is a solution of ☛ , ✌ has no solutions and the σ is a solution of s ☎ t if sσ ☎ ηβE tσ.The solutions of P ✍ Q (resp.P ✎ Q ) are the intersection (resp.the union) of the solutions of P and Q.A substitution σ is a solution of ✁ ✑✏ X ✄ P if there exists a solution of P identical to σ except maybe on X. § We will always write such a pattern in the (η-equivalent) form λx✒ F ✓ x✔ , where the argument of the free variable F is indeed a bound variable.
As usual, we restrict our attention to the problems of the form the only disjunctions being implicitely introduced by the non-deterministic rules.Terminology In the following, free variable denotes an occurrence of a variable which is not λ-bound and bound variable an occurrence of a variable which is λ-bound.To specify the status of a free variable with respect to existential quantifications, we will explicitely write existentially quantified or not existentially quantified.In the sequel, upper-case F, G, X,... will denote free variables, a, b, f , g,... constants, and x, y, z, x 1 ,... bound variables.
Without loss of generality, we assume that the left-hand sides and right-hand sides of the equations have the same prefix of λ-bindings.This is made possible because the two terms have to be of the same type, and by using α-conversion if necessary.In other terms, we will assume that the equations are of the form λx s ☎ λx t where s and t do not have an abstraction at the top.
Rather than computing substitutions, we will compute DAG-solved forms, from which it is trivial to extract solved form which represents its own mgu.

and (by η-equivalence) as F ☎ λy n s. A most general unifier of such an equation is
For the sake of readability, we will write a quasi-solved equation in the form F ☎ λy n s instead of λx k F ✁ y n ✄ ☎ λx k s in the following definition and in the rules Merge and Check* of the next section.

Definition 3 A DAG-solved form is a unification problem of the form
where for 1 ☎ i ☎ n, X i and s i have the same type, and X i ✆ ☎ X j for i ✆ ☎ j and A solved form is a unification problem of the form where for 1 ☎ i ☎ n, X i and s i have the same type, X i is not existentially quantified, and X i has exactly one occurrence.
A solved form is obtained from a DAG-solved form by applying as long as possible the rules if F has a free occurrence in P.
if F has no free occurrence in P.

Syntactic equational theories
Claude Kirchner [13] has defined the syntactic theories as those collapse-free equational theories which admit a finite presentation such that every equational proof can be performed by applying at most once an axiom at the root.Such a property provides complete top-down strategies for equational proofs or unification.At first, the unification community was not aware of the existence of many syntactic theories besides commutativity and its variants.Kirchner and Klay noticed that it is enough for a theory E to be syntactic that every equation of the form f [15].The permutative theories like commutativity, or more generally the theories presented by axioms of the form f where π is a permutation of ✁ 1✂ ✔ ✕ ✂ n✄ are syntactic, and the algoritm of figure 1 terminates for such theories.The theories of associativity, associativity-commutativity left-distributivity are syntactic, but the algorithm does not terminate in general.Arnborg and Tidén give a criterion which allows to avoid non-termination in the case of left-distributivity by detecting unsolvable problems [24].Boudet and Contejean give a criterion for pruning the search space and discarding some non-minimal solutions which ensures the termination while preserving the completeness in the case of associativity-commutativity [2].

Definition 4 An equational theory is syntactic if it possesses a finite resolvent presentation E. A set E of equations is a resolvent presentation if every E-equality proof can be performed using the axioms of E with at most one Λ-step. E f g is the set of the axioms of E of the form f
In the following, we assume that the set of first-order axioms E is a resolvent presentation.In addition, we require that E-is a simple theory, that is a theory containing no equalities of the form s ☎ E u where u is a strict subterm of s. Figure 1 gives a set of rules for first-order unification modulo simple syntactic theories.The reader is referred to e.g.[13,14,12,2] for some background on syntactic theories.

Free pattern unification revisited
In this section, we propose a modification of Miller's algorithm [17], refined by Nipkow [18] for pattern unification.We introduce a preliminary non-deterministic step in which we choose those arguments of the free variables which will effectively participate in the solution, and those that will be eliminated by a projection.After this step, we may assume that the value a free variable by a solution σ will effectively depend on each of its arguments, forbidding any further projection.The price to pay is an exponential blowup in the complexity, and the loss of minimality of the algorithm.On the other hand, the complexity of equational unification algorithms is already at least exponential for most of the theories of interest.The advantage of this approach is that the simplification rules can be modified in order to avoid introducing new variables which are needed precisely for possible projections.The resulting algorithm, after the preliminary non-deterministic step mimics closely a first-order unification algorithm.There is no need then for a new termination proof, and the algorithm will extend as in the first-order case to deal with syntactic equational theories.
In this section, the terms we consider are built over a set of typed variables and a set F C of typed free constants, that is constants which are not constrained by any equational theory.We give an example to show a crucial difference of pattern unification with first-order unification.
Example 1 Consider the equation Nipkow's algorithm transforms this equation into The first equation will be propagated in the rest of the problem.The second equation will be solvable by mapping both L 1 and G onto a new 0-ary variable.The third equation is not solvable since L 2 does not have x 3 as one of its arguments.The fourth equation has solution ✝ L 3 ✟ ✠ λxy H ✁ x✄ ✡☛ , and the last equation will be solvable or not, depending on the context s.
The above example shows that when the head of the left-hand side of an equation, is a free variable, one cannot say whether this equation is solvable even if the right-hand side does not contain the left-hand side, without traversing it all.In first-order unification, an equation of the form x ☎ s is solved if x does not occur in s.Note that even if the equation is solvable, one may need new variables to express the solution.
Figure 2 gives a non-deterministic algorithm for pattern unification.It is two-fold: in a first step, a projection is choosen nondeterministically which removes some of the bound variables under each free variable.In a second step, some rules are applied as long as possible which recall some well-known rules for first-order unification (see e.g.[12]).It has to be noticed that after the first step, no new variables are added.Our algorithm will fail when encountering an equation like that of the above example after the projection step because the sets of bound variables occurring in both sides of the equation are not the same.The values of F and G by a solution σ must depend on the same arguments and Nipkow's algorithm will return the solution

APPLY THE FOLLOWING RULE FOR EVERY FREE VARIABLE F OF P:
Our algorithm will make, (among others) the choice to keep all the arguments of F, but only the last two arguments of G.The problem obtained after the first projection step will be The third equation is then transformed into F ✒ ☎ λyz G✒ ✁ z✂ y✄ yielding a DAG solved form.It has to be noticed that no new variable is introduced in this latter transformation.
If a bad choice is made, the algorithm will fail: assume that both F and G keep all their arguments, the problem obtained after the projection step will be The above problem is obviously solvable, but we forbid ourselves any further projection after the initial step, hence no solution is computed here.
Finally, some choices may lead to solutions which are less general than the mgu.In our example this happens when the preliminary projections make F and G depend only on their last argument.The DAG solved form computed will be which is strictly less general than the mgu.

Definition 5 A constant-preserving substitution is a substitution σ such that for all F
λx k s then every variable of x k has a free occurrence in s.A projection is a substitution of the form The correctness of the failure rules is given by the following straightforward lemmas: Lemma 2 For every substitution σ, there exist a projection π and a constant-preserving substitution θ , where y and z are not the same sequence, has no constantpreserving solution.

Proposition 1 The non-deterministic algorithm of figure 2 is sound and complete for pattern unification. The irreducible problems are DAG-solved forms.
Proof: The lemma 2 shows that it is correct to first guess a projection and then restrict one's attention to constant-preserving substitutions.The lemma 3 shows that the failure rules Fail and FF☎ are complete with respect to constant-preserving substitutions.The rules Decompose, Clash and Check ✝ are already used by Nipkow.The rule FF ✆ ☎ (Coalesce) preserves the sets of solutions: , where z n is a permutation of y n and ✝ y n ☛ ✁ ✝ x k ☛ , has the same solutions as λy n F ✁ y n ✄ ✆☎ λy n G ✁ z n ✄ , and by η- equivalence, as F ☎ λy n G ✁ z n ✄ .Since ☎ ηβ is a congruence, F can be replaced by λy n G ✁ z n ✄ in the rest of the problem.The rules Trivial and Merge are correct since ☎ ηβ is an equivalence.A case analysis shows that if a problem is not in a DAG solved form, then some rule must apply.
The termination of the algorithm will follow from the termination of the first-order rules.This will be shown in section 5.

Mutation
In this section, we give a mutation rule for pattern unification modulo simple equational theories.We first introduce the notion of x k -variant.
Definition 6 An x k -variant of a first-order axiom l ☎ r is lσ ☎ rσ where σ maps every variable Y of l ☎ r onto Y ✒ ✁ y n ✄ where 1. y n is a subsequence of x k .

Y ✒ has type
The mutation rule is the following: We give an example of the use of the rule Mutate.
Example 4 Let E be the theory of left-distributivity, presented by the axiom

of (LD). The resulting problem is
Merge applies to the first two equations, yielding the problem Decompose applies to the second equation which is equivalent to x✄ is removed by Trivial, and Coalesce applies to the second.The problem to be solved is now x✂ y✂ z✄ EQE removes the useless existentially quantified variable V 2 , yielding The reader can now check that the substitution Lemma 4 Mutate preserves the sets of constant-preserving solutions.
Proof: The soundness is straightforward: a constant-preserving solution of the right-hand side of the rule is a constant-preserving solution of its left-hand side.We show the completeness: consider the equation where f and g are algebraic constants, to be solved in a syntactic theory E. By Tannen's theorem, a solution σ in η-long, β-normal form must satisfy Now, we do not need to guess an x k -variant of f ✄ for the correctness of the rule, but guessing which bound variables will occur as arguments of the variables of the axioms will allow the algorithm to fail when encountering an equation λx s

The algorithm
The algorithm of figure 2 has to be adapted in presence of an equational theory.First, the rule Clash has to be modified.Indeed, an equation may be solvable if the heads of its left-hand-side and righ-hand side are different algebraic constants, by applying Mutate (see figure 3).
The rule Decompose can be removed if one assumes that for every constant f of arity n, f More interesting is the case of the flexible-flexible equations with the same heads.It has been noticed by Qian and Wang that although such equations are always solvable by a projection, they do not have finite complete sets of AC-unifiers.
is an AC-unifier of e.On the other hand, every solution of e is an instance of some σ i .In addition Hence, AC-unification of patterns is not only infinitary, but nullary, in the sense that some problems do not have minimal complete sets of AC-unifiers [23].

APPLY THE FOLLOWING RULE FOR EVERY FREE VARIABLE F OF P:
As Qian and Wang, and as in [3], we keep these equations unaltered : the syntax of unification problems is slightly modified by distinguishing the conjunction P F of frozen equations that will never be modified by the simplification rules.The rule Freeze ignores the flexible-flexible equations with same heads and freezes them by storing them in P F .This is made necessary by the fact that even if P 0 does not contain such equations at the beginning, some may appear by applying the other rules.There are still no constantpreserving solutions of λx k F There is a proof of λx β ✄ , which is impossible since neither x i nor x j appear in the axioms of E. If a is an algebraic constant f , thet there would be a proof of ✄ which is again impossible since a simple theory admits no identities with a function symbol at the top on one side only.
It is now easy to show that our rules, after the projection step, mimic exactly those of figure 1, except for the more numerous failure cases due to the restriction to constant-preserving solutions.

Frozen equations
The algorithm that we have presented so far transforms a unification problem into a problem of the form P ✍ P F , where P is a DAG-solved form and P F is a conjunction of frozen equations of the form λx F ✁ y✄ ☎ λx F ✁ z✄ , where z is a permutation of y.There remains to check whether there exists an instance of the mgu of P that satisfies the equations of P F .The problem arises when the variable F has a "value" in P, that is, when there is an equation of the form λx F ✁ x✄ ✌☎ λx t in P. We do not have a general solution to this problem, but we propose a straightforward rule which may cause non-termination in general, and a method that will work for theories such as left-distributivity where the function symbols of the theory are decomposable.
The obvious rule for computing the solutions of P that satisfy P F is the following : Of course, we cannot guarantee the termination since the solving of the new equation λx t ☎ λx π t can yield new flexible flexible equations making it necessary to apply F-Merge again, and so on.Actually, we do conjecture that it is not decidable in general, given a theory E with decidable first-order unification, whether an equation of the form λx F

✁
x✄ ✆☎ λx F ✁ x π ✄ , where x π is a permutation of x, has a non-trivial E-solution, that is a solution which is not a solution modulo the empty theory.
Arnborg and Tidén [24] have shown that the axion of left-distributivity forms a resolvent presentation.
This implies that both ✁ and ☎ are decomposable, since there is no axiom with ✁ (or ☎ ) at the top on both sides.When all function symbols are decomposable, the only solutions to flexible-flexible equations with the same head on both sides are projections as in the non-equational case.Since we are interested in constant-preserving solutions, we can replace the Freeze rule by the following failure rule.

F-Fail
if y n is a permutation of z n other than the identity.
Theorem 3 Assume E is a simple syntactic equational theory such that every function symbol is decomposable.Assume that the algorithm given in figure 2 terminates for E in the first-order case.Then, the algorithm of figure 3, where the rule Freeze has been replaced by F-Fail terminates and implements a complete pattern E-unification algorithm.

Conclusion
We believe that with the emergence of higher-order rewriting, higher-order logic programming and functionalalgebraic programming languages, equational pattern unification will be useful.It is certainly not a good idea to perform a non-deterministic projection step for standard pattern unification.We have used this trick because when one is interested in constant-preserving substitutions, the equations with one free variable on one side behave as in the first order case.Either they have a suitable sequence of arguments and the equation is quasi-solved, or there is no constant-preserving solution.Surprisingly, the main difficulty comes from equations like λxy F ✁ x✂ y✄ ☎ λxy F ✁ y✂ x✄ .In the empty theory, such equations cause no problem, but in the equational case, it is the only "higher-order" problem we have encountered.The problem of the existence of non-trivial solutions to such equations could be rephrased as Does there exist a first-order term with n variables which is invariant modulo E when some variables are permuted?
We believe that this problem is undecidable in general for theories with decidable unification, but we will try and provide ad-hoc solutions for some familiar theories.
The assumption that E is a simple theory is essentially technical, and could be dropped as it has been done in the first-order case for unification in combinations of equational theories.The mechanisms used for preventing or solving cycles and clashes [22,1], should be adaptable to the pattern unification context.Then, the syntactic approach could apply to larger classes of equational theories such as the shallow theories [6].

Fig. 1 :
Fig. 1: A set of rules for unification modulo simple syntactic theories

Fig. 3 :
Fig. 3: Algorithm for pattern unification modulo simple syntactic theories and ✝ z n ☛ are not the same set, hence the rule FF☎ of figure 2 is replaced by the two rules Freeze and FF☎ of figure 3. We do not go into further detail now concerning frozen equations because first, we do not know how to handle them in general, and second, they will just lead to failure when all function symbols are decomposable as, for instance in the case of one-sided distributivity (see section 6).Figure3presents our algorithm for pattern unification modulo a simple syntactic equational theory E. The fact that E is a simple theory is needed to preserve the completeness of the rules Clash and Check By contradiction.Assume that σ is a solution in η-long β-normal form, and let Fσ ☎ λv t ✁ v✂ .We have λx Fσ✁ y✄ ☎ λx λv t ✁ v✂ ✁ y✄ ✌☎ β λx t ✁ y✂with λx t ✁ y✂ in η-long β-normal form.On the other side, we have Proof: there is a proof of the above identity where all the occurrences of bound variables have been replaced by a constant a.Let t ✒ (resp.s✒ ) be t (resp.✁We have t ✒ ☎ E s✒ ✁ t✒ ✂ p with p ✆☎ Λ, which is impossible for a simple theory E.Proof: By contradiction : assume σ is a solution.If a is a bound variable x j (i ✆ ☎ j), then we would have a proof of λx x i

Example 6
Assume that ✁ is an associative-commutative function symbol and that P ✍ P F is F ☎ λxy x ✁ a ✁ y ✍ λxy F ✁ x✂ y✄ ✌☎ λxy F ✁ y✂ x✄ .Then, the mgu ✝ F ✟ ✠ λxy x ✁ a ✁ y☛ of P satisfies P F , and we are done.Assume now that P ✍ P F is F ☎ λxy H ✁ x✂ y✄ ✍ λxy F ✁

Proposition 2
We call trivial an E-solution of an equation which is also a solution modulo the empty theory.Assume that E is such that all the function symbols are decomposable.Then, the equations of the form λx F✁ x✄ ✌☎ λx F ✁ x π ✄ have no non-trivial E-solutions.By contradiction, and induction on the structure of the value Fσ of F by the alledged non-trivial solution σ in η-long β-normal form.If Fσ is of the form λx α✁ t 1 ✂ ✔ ✔ ✂ t n ✄ ,where α is a free variable or a bound variable, we have λx α✁ t 1 ✂ ✕ ✔ ✂ t n ✄ ✌☎ E λx π α ✁ t 1 ✂ ✔ ✔ ✂ t n ✄ ,hence λx t i ☎ λx π t i which is impossible by the induction hypothesis.The same holds if Fσ is of the form λx f ✁ t 1 ✂ ✔ ✕ ✂ t n ✄ , where f is a decomposable constant. Proof: