Solving Equations Involving Sequence Variables and Sequence Functions Temur Kutsia⋆ Research Institute for Symbolic Computation, Johannes Kepler University Linz, A-4040 Linz, Austria
[email protected]
Abstract. Term equations involving individual and sequence variables, and individual and sequence function symbols are studied. Function symbols can have either fixed or flexible arity. A new unification procedure for solving such equations is presented. Decidability of unification is proved. Completeness and almost minimality of the procedure is shown.
1
Introduction
We study term equations with sequence variables and sequence function symbols. A sequence variable can be instantiated by any finite sequence of terms, including the empty sequence. A sequence function abbreviates a finite sequence of functions all having the same argument lists1 . An instance of such a function is IntegerDivision(x,y) that abbreviates the sequence Quotient(x, y), Remainder(x, y). Bringing sequence functions in the language naturally allows Skolemization over sequence variables: Let x, y be individual variables, x be a sequence variable, and p be a flexible arity predicate symbol. Then ∀x∀y∃x.p(x, y, x) Skolemizes to ∀x∀y.p(x, y, f (x, y)), where f is a binary Skolem sequence function symbol. Another example, ∀y∃x.p(y, x), where y is a sequence variable, after Skolemization introduces a flexible arity sequence function symbol g: ∀y.p(y, g(y)). Equation solving with sequence variables plays an important role in applications in automated reasoning, artificial intelligence, and programming. At the end of the paper we briefly review some of the works related to this topic. We contribute to this area by introducing a new unification procedure for solving equations in the free theory with individual and sequence variables, and individual and sequence function symbols. Function symbols can have either fixed or flexible arity. We prove that solvability of an equation is decidable in such a theory, and provide a unification procedure that enumerates an almost minimal complete set of solutions. The procedure terminates if the set is finite. This work is an extension and refinement of our previous results on unification with sequence variables [Kut02]. ⋆ 1
Supported by the Austrian Science Foundation (FWF) under Project SFB F1302. Semantically, sequence functions can be interpreted as multi-valued functions.
The paper is organized as follows: Section 2 introduces basic notions. In Section 3 decidability is proved. Section 4 is about the unification type. n Section 5 relation with order-sorted higher-order E-unification is discussed. In Section 6 unification procedure is defined and its properties are studied. In Section 7 two cases on which the procedure terminates are identified. Section 8 overviews some implementation details. Section 9 reviews some of the related work. Section 10 is Conclusion.
2
Preliminaries
We assume that the reader is familiar with the standard notions of unification theory [BS01]. We consider an alphabet consisting of the following pairwise disjoint sets of symbols: individual variables VInd , sequence variables VSeq , fixed arity individual Flex Fix , flexible arity individual function symbols FInd , fixed function symbols FInd Fix arity sequence function symbols FSeq , flexible arity sequence function symbols Flex FSeq . Each set of variables is countable. Each set of function symbols is finite or countable. Besides, the alphabet contains the parenthesis ‘(’, ‘)’ and the comma ‘,’. Fix Flex We will use the following denotations: V := VInd ∪ VSeq ; FInd := FInd ∪ FInd ; Flex Fix Fix Fix Flex Flex Flex Fix := FInd ∪ FSeq ; F := FInd ∪ FSeq ; F := FSeq := FSeq ∪ FSeq ; F FInd ∪ FSeq = F Fix ∪ F Flex . The arity of f ∈ F Fix is denoted by Arity(f ). A function symbol c ∈ F Fix is called a constant if Arity(c) = 0. Definition 1. We define the notion of term over F and V: 1. If t ∈ VInd , then t is an individual term . 2. If t ∈ VSeq , then t is a sequence term. Fix 3. If f ∈ FInd , Arity(f ) = n, n ≥ 0, and t1 , . . . , tn are individual f (t1 , . . . , tn ) is an individual term. Fix 4. If f ∈ FSeq , Arity(f ) = n, n ≥ 0, and t1 , . . . , tn are individual f (t1 , . . . , tn ) is a sequence term. Flex 5. If f ∈ FInd and t1 , . . . , tn (n ≥ 0) are (individual or sequence) f (t1 , . . . , tn ) is an individual term. Flex 6. If f ∈ FSeq and t1 , . . . , tn (n ≥ 0) are (individual or sequence) f (t1 , . . . , tn ) is a sequence term.
terms, then terms, then terms, then terms, then
A term is either an individual or a sequence term. The function symbol f is called the head of f (t1 , . . . , tn ). The head of a term t is denoted by Head(t). The set of all individual terms (resp. all sequence terms) over F and V is denoted by TInd (F, V) (resp. TSeq (F, V)) . The set of all terms over F and V is denoted by T (F, V) . Definition 2. The depth of a term t, denoted Depth(t), is defined recursively as follows: 2
– If t ∈ V, then Depth(t) = 1. – If t has a form f (s1 , . . . , sn ), where f ∈ F and n ≥ 0, then Depth(t) = max(Depth(s1 ), . . . , Depth(sn )) + 1. Definition 3. An equation over F and V is a pair hs, ti, denoted by s ≃ t, where s, t ∈ TInd (F, V). The terms s and t are called sides of the equation s ≃ t: s is the left hand side and t is the right hand side. Flex Fix Flex Example 1. Let x, y ∈ VInd , x ∈ VSeq , f ∈ FInd , g ∈ FInd , f ∈ FSeq and Fix g ∈ FSeq , Arity(g) = 2 and Arity(g) = 1.
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11.
f (x, g(x, y)) is an individual term. f (x, f (x, x, y)) is an individual term. f (x, f (x, x, y)) is a sequence term. g(f (x, x, y)) is a sequence term. f (x, g(x, y)) ≃ g(x, y) is an equation. f (x, g(x, y)) is not a term, because x occurs as an argument of g. f (x, g(x)) is not a term, because x occurs as an argument of g. f (x, g(x, y)) is not a term, because g is unary. f (x, g(x, y)) ≃ g(x, y) is not an equation, because f (x, g(x, y)) is not a term. x ≃ f (x) is not an equation, because x is not an individual term. g(x) ≃ f (x) is not an equation, because g(x) is not an individual term.
If not otherwise stated, the following symbols, with or without indices, are used as metavariables: x and y – over individual variables; x, y and z – over sequence variables; v – over (individual or sequence) variables; f , g and h – over individual function symbols; f , g and h – over sequence function symbols; a, b and c – over individual constants; a, b and c – over sequence constants; s, t, r, q – over terms. We use some other denotations as well: Let T be a term, a sequence of terms, or a set of terms. Then we denote by IVar(T ) – the set of all individual variables occurring in T , SVar(T ) – the set of all sequence variables occurring in T , Var(T ) – the set IVar(T ) ∪ SVar(T ), IFun(T ) – the set of all individual function symbols occurring in T , SFun(T ) – the set of all sequence function symbols occurring in T , Fix(T ) – the set of all fixed arity function symbols occurring in T , Flex(T ) – the set of all flexible arity function symbols occurring in T . Definition 4. A variable binding is either a pair x 7→ t where t ∈ TInd (F, V) and t 6= x, or an expression x 7→ pt1 , . . . , tn q2 where n ≥ 0, for all 1 ≤ i ≤ n we have ti ∈ T (F, V), and if n = 1 then t1 6= x. 2
To improve the readability, we write sequences that bind sequence variables between p and q.
3
Definition 5. A sequence function symbol binding is an expression of the form f 7→ pg1 , . . . , gm q, where m ≥ 1, if m = 1 then f 6= g1 , and either f , g1 , . . . , gm ∈ Flex Fix FSeq . , with Arity(f ) = Arity(g1 ) = · · · = Arity(gm ), or f , g1 , . . . , gm ∈ FSeq Definition 6. A generalized substitution, or, simply a substitution, is a finite set of variable and sequence function symbol bindings m { x1 7→ t1 , . . . , xn 7→ tn , x1 7→ ps11 , . . . , s1k1 q, . . . , xm 7→ psm 1 , . . . , skm q,
f1 7→ pg11 , . . . , gl11 q, . . . , fr 7→ pg1r , . . . , glrr q} where n, m, r ≥ 0, x1 , . . . , xn , x1 , . . . , xm are distinct variables and f1 , . . . , fr are distinct sequence function symbols. Lower case Greek letters are used to denote substitutions. The empty substitution is denoted by ε. Definition 7. The instance of a term t with respect to a substitution σ, denoted tσ, is defined recursively as follows: t, if x 7→ t ∈ σ, 1. xσ = x, otherwise. t1 , . . . , tn , if x 7→ pt1 , . . . , tn q ∈ σ, n ≥ 0, 2. xσ = x, otherwise. 3. f (t1 , . . . , tn )σ = f (t1 σ, . . . , tn σ). 4. f (t1 , . . . , tn )σ = g1 (t1 σ, . . . , tn σ), . . . , gm (t1 σ, . . . , tn σ), if f 7→ pg1 , . . . , gm q ∈ σ, f (t1 σ, . . . , tn σ), otherwise. Example 2. Let σ = {x 7→ a, y 7→ f (x), x 7→ pq, y 7→ pa, f (x), bq, g 7→ pg1 , g2 q}. Then f (x, x, g(y, g), y))σ = f (a, g1 (f (x), g1 , g2 ), g2 (f (x), g1 , g2 ), a, f (x), b). Definition 8. An application of a substitution σ on a sequence function symbol f , denoted f σ, is defined as follows: g1 , . . . , gm , if f 7→ pg1 , . . . , gm q ∈ σ, fσ = f, otherwise. Applying a substitution θ on a sequence of terms pt1 , . . . , tn q gives a sequence of terms pt1 θ, . . . , tn θq. Definition 9. Let σ be a substitution. 1. The domain of σ is the set of variables and sequence function symbols Dom(σ) = {l | lσ 6= l}.
4
2. The codomain of σ is the set of terms and sequence function symbols Cod(σ) = {lσ | l ∈ Dom(σ)}. 3. The range of σ is the set of variables Ran(σ) = Var(Cod(σ)).
Note that the codomain of a substitution is a set of terms and sequence function symbols, not a set consisting of terms, sequences of terms, sequence function symbols and sequences of sequence function symbols. For instance, Cod({x 7→ f (a), x 7→ pa, a, bq, c 7→ pc1 , c2 q}) = {f (a), a, b, c1 , c2 }. A substitution σ is called ground iff Ran(σ) = ∅. We also use the following denotations: 1. 2. 3. 4.
VDom(σ), for the set Dom(σ) ∩ V; VCod(σ), for the set {vσ | v ∈ VDom(σ)}; FDom(σ), for the set Dom(σ) ∩ F; FCod(σ) for the set {f σ | f ∈ FDom(σ)}.
Definition 10. The restriction of a substitution σ to a set of variables and sequence function symbols S, denoted σ|S , is the substitution defined by lσ|S = lσ if l ∈ S, and lσ|S = l otherwise. Definition 11. Let σ and ϑ be two substitutions: m σ = { x1 7→ t1 , . . . , xn 7→ tn , x1 7→ ps11 , . . . , s1k1 q, . . . , xm 7→ psm 1 , . . . , skm q,
f1 7→ pf11 , . . . , fl11 q, . . . , fr 7→ pf1r , . . . , flrr q}, ′
′
ϑ = { y1 7→ r1 , . . . , yn′ 7→ rn′ , y1 7→ pq11 , . . . , qk1′ 1 q, . . . , ym′ 7→ pq1m , . . . , qkm′ m′ q, g1 7→ pg11 , . . . , gl1′ q, . . . , gr′ 7→ pg1r , . . . , glr′ q}. ′
′
1
r′
Then the composition of σ and ϑ, σϑ, is the substitution obtained from the set m { x1 7→ t1 ϑ, . . . , xn 7→ tn ϑ, x1 7→ ps11 ϑ, . . . , s1k1 ϑq, . . . , xm 7→ psm 1 ϑ, . . . , skm ϑq,
f1 7→ pf11 θ, . . . , fl11 θq, . . . , fr 7→ pf1r θ, . . . , flrr θq, ′
′
y1 7→ r1 , . . . , yn′ 7→ rn′ , y1 7→ pq11 , . . . , qk1′ 1 q, . . . , ym′ 7→ pq1m , . . . , qkm′ m′ q, g1 7→ pg11 , . . . , gl1′ q, . . . , gr′ 7→ pg1r , . . . , glr′ q} ′
′
1
r′
by deleting 1. all the bindings xi 7→ ti ϑ (1 ≤ i ≤ n) for which xi = ti ϑ, 2. all the bindings xi 7→ psi1 ϑ, . . . , siki ϑq (1 ≤ i ≤ m) for which the sequence si1 ϑ, . . . , siki ϑ consists of a single term xi , 5
3. all the sequence function symbol bindings fi 7→ pf1i ϑ, . . . , flii ϑq (1 ≤ i ≤ r) such that the sequence f1i ϑ, . . . , flir ϑ consists of a single function symbol fi , 4. all the bindings yi 7→ ri (1 ≤ i ≤ n′ ) such that yi ∈ {x1 , . . . , xn }, 5. all the bindings yi 7→ pq1i , . . . , qki ′ i q (1 ≤ i ≤ m′ ) with yi ∈ {x1 , . . . , xm }, 6. all the sequence function symbol bindings gi 7→ pg1i , . . . , gli′ i q (1 ≤ i ≤ r′ ) such that gi ∈ {f1 , . . . , fr }. Example 3. Let σ and ϑ be two substitutions: σ = {x 7→ y, x 7→ py, xq, y 7→ pf (a, b), y, g(x)q, f 7→ pg, hq}. ϑ = {y 7→ x, y 7→ x, x 7→ pq, g 7→ pg1 , g2 q}. Then σϑ = {y 7→ x, y 7→ pf (a, b), x, g1 (), g2 ()q, f 7→ pg1 , g2 , hq, g 7→ pg1 , g2 q}. Proposition 1. Let t be a term, f be a sequence function symbol, and σ, ϑ and ϕ be substitutions. Then 1. (f σ)ϑ = f (σϑ). 2. (tσ)ϑ = t(σϑ). 3. (σϑ)ϕ = σ(ϑϕ). Proof. Let σ and ϑ be two substitutions: σ = { x1 7→ t1 , . . . , xn 7→ tn , m x1 7→ ps11 , . . . , s1k1 q, . . . , xm 7→ psm 1 , . . . , skm q,
f1 → 7 pf11 , . . . , fl11 q, . . . , fr 7→ pf1r , . . . , flrr q}. ϑ = { y1 → 7 r1 , . . . , yn′ 7→ rn′ , ′
′
y1 7→ pq11 , . . . , qk1′ 1 q, . . . , ym′ 7→ pq1m , . . . , qkm′ m′ q, g1 7→ pg11 , . . . , gl1′ q, . . . , gr′ 7→ pg1r , . . . , glr′ q}. ′
1
′
r′
1. We distinguish the following cases: (a) f = fi for 1 ≤ i ≤ r and {f1i , . . . , flii } ∩ Dom(ϑ) = ∅. Then (f σ)ϑ = pf1i , . . . , flii qϑ = pf1i ϑ, . . . , flii ϑq = pf1i , . . . , flii q = f (σϑ). / ∅. Assume with(b) f = fi for 1 ≤ i ≤ r and {f1i , . . . , flii } ∩ Dom(ϑ) ∈ out loss of generality that f1i = gj for some 1 ≤ j ≤ r′ . Then we have f 7→ pg1j , . . . , glj′ , f2i , . . . , flii q ∈ σϑ and (f σ)ϑ = pf1i , . . . , flii qϑ = j
pf1i ϑ, . . . , flii ϑq
=
(c) f = gj for 1 ≤ pg1j , . . . , glj′ q j
pg1j , . . . , glj′ , f2i , . . . , flii q = f (σϑ). j j ≤ r′ with gj ∈ / Dom(σ). Then
= f (σϑ).
/ Dom(σ) ∪ Dom(ϑ). Then (f σ)ϑ = f = f (σϑ). (d) f ∈ 6
(f σ)ϑ = f ϑ =
2. We use induction on depth of t. Let first t be a variable v. We distinguish the following cases: (a) v = xi for 1 ≤ i ≤ n. Then (vσ)ϑ = ti ϑ = v(σϑ). (b) v = xi for 1 ≤ i ≤ m. Then (vσ)ϑ = psi1 , . . . , siki qϑ = psi1 ϑ, . . . , siki ϑq = v(σϑ). (c) v = yj for 1 ≤ j ≤ n′ with yj ∈ / Dom(σ). Then (vσ)ϑ = vϑ = rj = v(σϑ). (d) v = yj for 1 ≤ j ≤ m′ with yj ∈ / Dom(σ). Then (vσ)ϑ = vϑ = pq1j , . . . , qkj ′ j q = v(σϑ). (e) v ∈ / Dom(σ) ∪ Dom(ϑ). Then (vσ)ϑ = v = v(σϑ). Let now t be f (s1 , . . . , sn′′ ). Then we have (tσ)ϑ = f ((s1 σ)ϑ, . . . , (sn′′ σ)ϑ) = f (s1 (σϑ), . . . , sn′′ (σϑ)) = t(σϑ). Finally, let t be f (s1 , . . . , sn′′ ). We have the following cases: (a) f = fi for 1 ≤ i ≤ r and {f1i , . . . , flii } ∩ Dom(ϑ) = ∅. Then (tσ)ϑ = pf1i (s1 σ, . . . , sn′′ σ), . . . , flii (s1 σ, . . . , sn′′ σ)qϑ = pf1i ((s1 σ)ϑ, . . . , (sn′′ σ)ϑ), . . . , flii ((s1 σ)ϑ, . . . , (sn′′ σ)ϑ)q = pf1i (s1 (σϑ), . . . , sn′′ (σϑ)), . . . , flii (s1 (σϑ), . . . , sn′′ (σϑ))q = f (s1 , . . . , sn′′ )(σϑ) = t(σϑ) (b) f = fi for 1 ≤ i ≤ r and {f1i , . . . , flii } ∩ Dom(ϑ) ∈ / ∅. Assume without loss of generality that f1i = gj for some 1 ≤ j ≤ r′ . Then we have (tσ)ϑ = pf1i (s1 σ, . . . , sn′′ σ), . . . , flii (s1 σ, . . . , sn′′ σ)qϑ = pg1j ((s1 σ)ϑ, . . . , (sn′′ σ)ϑ), . . . , glj′ ((s1 σ)ϑ, . . . , (sn′′ σ)ϑ), j
f2i ((s1 σ)ϑ, . . . , (sn′′ σ)ϑ), . . . , flii ((s1 σ)ϑ, . . . , (sn′′ σ)ϑ)q = pg1j (s1 (σϑ), . . . , sn′′ (σϑ)), . . . , glj′ (s1 (σϑ), . . . , sn′′ (σϑ)), j
f2i (s1 (σϑ), . . . , sn′′ (σϑ)), . . . , flii (s1 (σϑ), . . . , sn′′ (σϑ))q = f (s1 , . . . , sn′′ )(σϑ) = t(σϑ) / Dom(σ). Then (c) f = gj for 1 ≤ j ≤ r′ with gj ∈ (tσ)ϑ = f (s1 σ, . . . , sn′′ σ)ϑ = pg1j ((s1 σ)ϑ, . . . , (sn′′ σ)ϑ), . . . , glj′ ((s1 σ)ϑ, . . . , (sn′′ σ)ϑ)q j
=
pg1j (s1 (σϑ), . . . , sn′′ (σϑ)), . . . , glj′ (s1 (σϑ), . . . , sn′′ (σϑ))q j
= f (s1 , . . . , sn′′ )(σϑ) = t(σϑ) 7
(d) f ∈ / Dom(σ) ∪ Dom(ϑ). Then (tσ)ϑ = f ((s1 σ)ϑ, . . . , (sn′′ σ)ϑ) = f (s1 (σϑ), . . . , sn′′ (σϑ)) = f (s1 , . . . , sn′′ )(σϑ) = t(σϑ). ⊓ ⊔ Definition 12. A substitution σ is called linearizing away from a finite set of sequence function symbols Q iff the following three conditions hold: 1. Cod(σ) ∩ Q = ∅. 2. For all f , g ∈ Dom(σ) ∩ Q, if f = 6 g, then {f σ} ∩ {gσ} = ∅. 3. If f 7→ pg1 . . . , gn q ∈ σ and f ∈ Q, then for all 1 ≤ i < j ≤ n we have gi 6= gj . Intuitively, a substitution linearizing away from Q either leaves a sequence function symbol in Q “unchanged”, or “moves it away from” Q, binding it with a sequence of distinct sequence function symbols that do not occur in Q, and maps different sequence function symbols to disjoint sequences. Let E be a set of equations (called identities) over F and V. By ≃E we denote the least congruence relation on T (F, V) that is closed under substitution application and contains E. More precisely, ≃E is defined as follows: E ⊆≃E . (Reflexivity.) For all t ∈ T (F, V), t ≃E t. (Symmetry.) For all s, t ∈ T (F, V), s ≃E t implies t ≃E s. (Transitivity.) For all s, t, r ∈ T (F, V), s ≃E t and t ≃E r imply s ≃E r. (Congruence.) For all s1 , . . . , sn , t1 , . . . , tn ∈ T (F, V), if s1 ≃E t1 , . . . , sn ≃E tn , then f (s1 , . . . , sn ) ≃E f (t1 , . . . , tn ), where either f ∈ F Flex , or f ∈ F Fix and Arity(F ) = n. 6. (Substitutivity.) For all s, t ∈ T (F, V), if s ≃E t and σ is a substitution such that sσ, tσ ∈ T (F, V), then sσ ≃E tσ. 1. 2. 3. 4. 5.
Substitutivity requires that sσ and tσ must be single terms, not arbitrary sequences of terms. The set ≃E is called an equational theory defined by E. If s ≃E t, then we say that the term s is equal modulo E to the term t. In the following, we will often slightly abuse the notion of an equational theory by also calling a set E an equational theory, or E-theory. For a given set of equations E, we denote by Sig(E) the signature of E, i.e., the set IFun(E) ∪ SFun(E) of all function symbols occurring in E. Solving equations in an E-theory is called E-unification. The fact that the equation s ≃ t has to be solved in an E-theory is written as s≃?E t. Definition 13. Let E be an equational theory and F be a signature containing Sig(E). An E-unification problem over F is a finite multiset of equations Γ = 8
{s1 ≃?E t1 , . . . , sn ≃?E tn } over F and V. An E-unifier of Γ is a substitution σ such that σ is linearizing away from SFun(Γ ) and for all 1 ≤ i ≤ n, si σ ≃E ti σ. The set of all E-unifiers of Γ is denoted by UE (Γ ), and Γ is E-unifiable iff UE (Γ ) 6= ∅. Note that if Γ = {s1 ≃?E t1 , . . . , sn ≃?E tn } is a unification problem, then all s1 , . . . , sn , t1 , . . . , tn ∈ TInd (F, V). Example 4. Let E = ∅. 1. Γ = {f (g(x, y, a)) ≃?E f (g(c, b, x))}. Then {x 7→ c1 , y 7→ pc2 , bq, x 7→ a, c 7→ pc1 , c2 q} ∈ UE (Γ ). 2. Γ = {f (g(x, y, a)) ≃?E f (h(c, x))}. Then UE (Γ ) = ∅. If we did not require the E-unifiers of a unification problem to be linearizing away from the sequence function symbol set of the problem, then Γ would have E-unifiers, e.g., {x 7→ c1 , y 7→ pc2 , bq, x 7→ a, g 7→ h, c 7→ pc1 , c2 q} would be one of them. In the sequel, if not otherwise stated, E stands for an equational theory, X for a finite set of variables and Q for a finite set of sequence function symbols. Definition 14. A substitution σ is called erasing on X modulo E iff either there exist f ∈ Sig(E) and v ∈ X such that f (v)σ ≃E f (), or there exists x ∈ X such that x 7→ pq ∈ σ. We say that σ is non-erasing on X modulo E iff σ is not erasing on X modulo E. Example 5. 1. Let E = ∅ and X = {x, x}. Then any substitution that contains the variable binding x 7→ pq is erasing on X modulo E. For instance, {x 7→ a, x 7→ pq} is erasing on X modulo E. 2. Let E = {f (x, f (y), z) ≃ f (x, y, z)} and X = {x, x}. Then any substitution that contains x 7→ f (), or x 7→ pq, or a variable binding of the form x 7→ pt1 , . . . , tn q with n ≥ 1 and t1 = · · · = tn = f (), is erasing on X modulo E. For instance, the substitutions {x 7→ f ()}, {x 7→ f ()}, {x 7→ pq}, {x 7→ pf (), f (), f (), f ()q} are erasing on X modulo E. Definition 15. A substitution σ agrees with a substitution ϑ on X and Q mod,Q ulo E, denoted σ =X ϑ, iff E 1. for all x ∈ X , there exist t1 , . . . , tn , s1 , . . . , sn ∈ T (F, V), n ≥ 0, such that xσ = pt1 , . . . , tn q, xϑ = ps1 , . . . , sn q and ti ≃E si for each 1 ≤ i ≤ n; 2. for all x ∈ X , xσ ≃E xϑ; 3. for all f ∈ Q, f σ = f ϑ. Definition 16. A substitution ϕ matches a substitution σ with a substitution ϑ ,Q on X and Q modulo E, iff σϕ =X ϑ. E Example 6. Let σ = {x 7→ a}, ϑ = {x 7→ pb, cq, a 7→ pb, cq} and ϕ = {x 7→ ,Q pb, cq, a 7→ pb, cq}. Let also X = {x}, Q = {a} and E = ∅. Then σϕ =X ϑ. E 9
Definition 17. A substitution σ is more general (resp. strongly more general) X ,Q X ,Q than a substitution ϑ on X and Q modulo E, denoted σ≤ E ϑ (resp. σ E ϑ), iff there exists a substitution (resp. a substitution non-erasing on X modulo E) ,Q ϕ such that σϕ =X ϑ. E X ,Q X ,Q From Definition 17 it immediately follows that E ⊆ ≤ E .
Example 7. Let σ = {x 7→ y}, ϑ = {x 7→ pa, bq, y 7→ pa, bq}, η = {x 7→ pq, y 7→ X ,Q X ,Q X ,Q X ,Q pq}, X = {x, y}, Q = ∅, E = ∅. Then σ≤ E ϑ, σ E ϑ, σ≤ E η, σ6 E η. A substitution ϑ is an E-instance (resp. strong E-instance) of σ on X and Q iff X ,Q X ,Q X ,Q X ,Q σ≤ E ϑ (resp. σ E ϑ). The equivalence associated with ≤ E (i.e., ≤ E ∩ X ,Q X ,Q ) is denoted by = X ,Q is denoted by ≥ E E . The equivalence associated with E X ,Q X ,Q X ,Q X ,Q ). ≈ . The strict part of ≤ (resp. ) is denoted by x. Theorem 7. F -unifiability of Ψ is decidable. Proof. Let F1 = {seq} and F2 = Fix(Ψ ) be two disjoint signatures. Let E1 be a flat equational theory over F1 and VInd , and let E2 be a free equational theory over F2 and VInd . Then Ψ can be considered as an elementary unification problem in the combined theory E1 ∪ E2 . Then, by Theorem 6, we need to prove that solvability of E1 - and E2 -unification problems with linear constant restrictions is decidable. E1 -unification problems are, in fact, word equations, while E2 -unification problems are Robinson unification problems. Decidability of word equations with linear constant restrictions, and Robinson unification with linear constant restrictions was proved by [BS91]. ⊓ ⊔ 17
4
Unification Type
The unification problem {f (a, x) ≃?∅ f (x, a)} has an infinite minimal complete set of unifiers {{x 7→ pq}, {x 7→ a}, {x 7→ pa, aq}, . . .}. It implies that the syntactic sequence unification is at least infinitary. Now we show that it is not nullary. Note that by Definition 22 and Proposition 2 it is sufficient to show that every syntactic sequence unification problem has an almost minimal set of unifiers. First we define the notion of norm for terms, sequences of terms, sequences of sequence function symbols and substitutions. Definition 24. The norm of a term t, denoted ktk, is defined as follows: 1. If t ∈ VSeq , then ktk = 1. 2. If t ∈ VInd , then ktk = 2. Pn 3. If t = f (s1 , . . . , sn ), n ≥ 0, f ∈ F, then ktk = i=1 ksi k + 3.
The norm of a P sequence of terms t1 , . . . , tn , denoted kt1 , . . . , tn k, is defined as n kt1 , . . . , tn k = i=1 kti k. The norm of the empty sequence of terms is 0. The norm of a sequence of sequence function symbols f1 , . . . , fn is the length of the sequence: kf1 , . . . , fn k = n. From the definition it immediately follows that 1. ktk ≤ ktσk for any term t and a substitution σ that is non-erasing on SVar(t) modulo the free theory. 2. kf k ≤ kf σk for any sequence function symbol f and a substitution σ. Definition 25. The norm σ on X and Q, denoted by kσkX ,Q , P of a substitution P is defined as kσkX ,Q = v∈X kvσk + f ∈Q kf σk. Definition 25 implies the following proposition:
X ,Q Proposition 4. For any σ, ϑ, X and Q, if σ E ϑ, then kσkX ,Q ≤ kϑkX ,Q .
Let now VCodm (σ) be a multiset of terms {|vσ | v ∈ Dom(σ)|} , FCodm (σ) be a multiset of sequence function symbols {|f σ | f ∈ Dom(σ)|} , and Ranm (σ) be a multiset of variables occurring in VCodmult (σ). Then we define the following multiset of positive integers: M(σ) = {|n | there exists a variable v occurring n times in Ranm (σ) or there exists a sequence function symbol f occurring n times in FCodm (σ), and n > 0|} . Example 9. Let σ be { x 7→ y, y 7→ f (x, x, x), x 7→ py, xq, z 7→ py, xq, f 7→ pf1 , f2 q, g 7→ pf1 , f2 q}. Then 18
1. 2. 3. 4.
VCodm (σ) = {|y, f (x, x, x), y, x, y, x|} . FCodm (σ) = {|f1 , f2 , f1 , f2 |} . Ranm (σ) = {|y, x, x, x, x, x, y, y|} . M(σ) = {|1, 1, 4, 2, 2, 2|} .
Theorem 8. Let Γ be a syntactic unification problem, and let X = Var(Γ ) and Q = SFun(Γ ). Then every strictly decreasing chain of substitutions X ,Q σ2 ≻ X ,Q · · · σ1 ≻ ∅ ∅ in U∅ (Γ ) is finite. Proof. Assume by contradiction that there exists a strictly decreasing infinite X ,Q σ2 ≻ X ,Q · · · in U∅ (Γ ). Then for all i > 0 we have chain of substitutions σ1 ≻ ∅ ∅ kσi kX ,Q ≥ kσi+1 kX ,Q and, therefore, there must exists a k such that for all j > k we have kσj kX ,Q = kσj+1 kX ,Q . Let for all i ≥ 0 the substitution ϕi be non-erasing on X modulo the free ,Q theory such that σi+1 ϕi =X σi . Then for all j > k we have ∅ – xϕj ∈ VInd for each individual variable x ∈ Ran(σj+1 |X ). – xϕj ∈ VSeq for each sequence variable x ∈ Ran(σj+1 |X ). – f ϕj ∈ FSeq for each sequence function symbol f ∈ FCod(σj+1 |Q ). Otherwise we would have kσj kX ,Q > kσj+1 kX ,Q . Moreover, for all j > k the substitution ϕj should satisfy at least one of the following properties: 1. It binds two distinct variables from Ran(σj+1 |X ) with the same variable. 2. It binds a variable from the set Ran(σj+1 |X ) with another variable from Ran(σj+1 |X ) \ Dom(ϕj ). 3. It binds two distinct sequence function symbols from FCod(σj+1 |Q ) with the same sequence function symbol. 4. It binds a sequence function symbol from FCod(σj+1 |Q ) with another sequence function symbol from FCod(σj+1 |Q ) \ Dom(ϕj ). X ,Q Otherwise we would have σj ≈ ∅ σj+1 . Then we get that M(σj |X ∪Q ) >m M(σj+1 |X ∪Q ) for all j > k, where >m is a multiset extension of the ordering > on positive integers. Therefore, we have a strictly decreasing infinite chain of multisets:
M(σk+1 |X ∪Q ) >m M(σk+2 |X ∪Q ) >m · · · But it is a contradiction, because >m is well-founded.
⊓ ⊔
Theorem 8 implies that an almost minimal complete set of unifiers of a syntactic unification problem Γ exists: Just collect fixed representatives with respect to X ,Q ≈ of almost minimal substitutions in U (Γ ), where X = Var(Γ ) and Q = ∅
∅
SFun(Γ ). Therefore, by Proposition 2, Γ has a minimal complete set of syntactic unifiers and, hence, the syntactic sequence unification can not be nullary. It implies that the syntactic sequence unification is infinitary. 19
5
Relation with Order-Sorted Higher-Order Unification
Syntactic sequence unification can be considered as a special case of order-sorted higher-order E-unification. Here we show the corresponding encoding in the framework described in [Koh94]. We consider simply typed λ-calculus with the types i and o. The set of base sorts consists of ind, seq, seqc, o such that the type of o is o and the type of the other sorts is i. We will treat individual and sequence variables as first order variables, sequence functions as second order variables and define a context Γ such that Γ(x) = ind for all x ∈ VInd , Γ(x) = seq for all x ∈ Flex VSeq , Γ(f ) = seq → seqc for each f ∈ FSeq , and Γ(f ) = ind · · → ind} → | → ·{z n times
Fix with Arity(f ) = n. Individual function symbols are seqc for each f ∈ FSeq Flex treated as constants. We assign to each f ∈ FInd a functional sort seq → ind Fix and to each f ∈ FInd with Arity(f ) = n a functional sort ind · · → ind} → | → ·{z
n times
ind. We assume equality constants ≈s for every sort s. In addition, we have two function symbols: binary pq of the sort seq → seq → seq and a constant [] of the sort seq. Sorts are partially ordered as [ind ≤ seqc] and [seqc ≤ seq]. The equational theory is an AU-theory, asserting associativity of pq with [] as left and right unit. We consider unification problems for terms of the sort ind where terms are in βη-normal form containing no bound variables, and terms whose head is pq are flattened. For a given unification problem Γ in this theory, we are looking for unifiers that obey the following restrictions: If a unifier σ binds a second order variable f of the sort seq → seqc, then f σ = λx.pg1 (x), . . . , gm (x)q and if σ binds a second order variable f of the sort ind · · → ind} → seqc, | → ·{z n times
then f σ = λx1 . . . . xn .pg1 (x1 , . . . , xn ), . . . , gm (x1 , . . . , xn )q, where m > 1 and g1 , . . . , gm are fresh variables of the same sort as f . Hence, syntactic sequence unification can be considered as order-sorted second-order AU-unification with additional restrictions. Order-sorted higher-order syntactic unification was investigated in [Koh94], but we are not aware of any work done on order-sorted higher-order equational unification.
6
Unification Procedure
We now present inference rules for deriving solutions for unification problems. A system is either the symbol ⊥ (representing failure), or a pair hΓ ; σi, where Γ is a unification problem and σ is a substitution. The inference system U consists of the transformation rules on systems listed below. The function symbol g in the rule Partial Decomposition 2 is a new flexible arity individual function symbol. The sequence function symbols f1 and f2 in Splitting rule are new sequence function symbols of the same arity as f in the same rule. We assume that the indices n, m, k, l ≥ 0.
20
Projection (P): hΓ ; σi =⇒ hΓ ϑ; σϑi where ϑ 6= ε, Dom(ϑ) ⊆ SVar(Γ ) and Cod(ϑ) = ∅. Trivial (T): h{s ≃?∅ s} ∪ Γ ′ ; σi =⇒ hΓ ′ ; σi. Orient 1 (O1): h{s ≃?∅ x} ∪ Γ ′ ; σi =⇒ h{x ≃?∅ s} ∪ Γ ′ ; σi if s ∈ / VInd . Orient 2 (O2): h{f (s, s1 , . . . , sn ) ≃?∅ f (x, t1 , . . . , tm )} ∪ Γ ′ ; σi =⇒ h{f (x, t1 , . . . , tm ) ≃?∅ f (s, s1 , . . . , sn )} ∪ Γ ′ ; σi if t ∈ / VSeq . Solve (S): h{x ≃?∅ t} ∪ Γ ′ ; σi =⇒ hΓ ′ ϑ; σϑi if x ∈ / IVar(t) and ϑ = {x 7→ t}. Total Decomposition (TD): h{f (s1 , . . . , sn ) ≃?∅ f (t1 , . . . , tn )} ∪ Γ ′ ; σi =⇒ h{s1 ≃?∅ t1 , . . . , sn ≃?∅ tn } ∪ Γ ′ ; σi if f (s1 , . . . , sn ) 6= f (t1 , . . . , tn ), and si , ti ∈ TInd (F, V) for all 1 ≤ i ≤ n. Partial Decomposition 1 (PD1): h{f (s1 , . . . , sn ) ≃?∅ f (t1 , . . . , tm )} ∪ Γ ′ ; σi =⇒ h{s1 ≃?∅ t1 , . . . , sk−1 ≃?∅ tk−1 , f (sk , . . . , sn ) ≃?∅ f (tk , . . . , tm )} ∪ Γ ′ ; σi if f (s1 , . . . , sn ) 6= f (t1 , . . . , tm ), for some 1 < k ≤ min(n, m), sk ∈ TSeq (F, V) or tk ∈ TSeq (F, V), and si , ti ∈ TInd (F, V) for all 1 ≤ i < k. Partial Decomposition 2 (PD2): =⇒ h{f (f (r1 , . . . , rk ), s1 , . . . , sn ) ≃?∅ f (f (q1 , . . . , ql ), t1 , . . . , tm )} ∪ Γ ′ ; σi h{g(r1 , . . . , rk ) ≃?∅ g(q1 , . . . , ql ), f (s1 , . . . , sn ) ≃?∅ f (t1 , . . . , tm )} ∪ Γ ′ ; σi. if f (f (r1 , . . . , rk ), s1 , . . . , sn ) 6= f (f (q1 , . . . , ql ), t1 , . . . , tm ).
21
Sequence Variable Elimination 1 (SVE1): h{f (x, s1 , . . . , sn ) ≃?∅ f (x, t1 , . . . , tm )} ∪ Γ ′ ; σi =⇒ h{f (s1 , . . . , sn ) ≃?∅ f (t1 , . . . , tm )} ∪ Γ ′ ; σi if f (x, s1 , . . . , sn ) 6= f (x, t1 , . . . , tm ). Sequence Variable Elimination 2 (SVE2): h{f (x, s1 , . . . , sn ) ≃?∅ f (t, t1 , . . . , tm )} ∪ Γ ′ ; σi =⇒ h{f (s1 , . . . , sn )ϑ ≃?∅ f (t1 , . . . , tm )ϑ} ∪ Γ ′ ϑ; σϑi / SVar(t) and ϑ = {x 7→ t}. if x ∈ Widening 1 (W1): h{f (x, s1 , . . . , sn ) ≃?∅ f (t, t1 , . . . , tm )} ∪ Γ ′ ; σi =⇒ h{f (x, s1 ϑ, . . . , sn ϑ) ≃?∅ f (t1 ϑ, . . . , tm ϑ)} ∪ Γ ′ ϑ; σϑi if x ∈ / SVar(t) and ϑ = {x 7→ pt, xq}. Widening 2 (W2): h{f (x, s1 , . . . , sn ) ≃?∅ f (y, t1 , . . . , tm )} ∪ Γ ′ ; σi =⇒ h{f (s1 ϑ, . . . , sn ϑ) ≃?∅ f (y, t1 ϑ, . . . , tm ϑ)} ∪ Γ ′ ϑ; σϑi where ϑ = {y 7→ px, yq}. Splitting (Sp): h{f (x, s1 , . . . , sn ) ≃?∅ f (f (r1 , . . . , rk ), t1 , . . . , tm )} ∪ Γ ′ ; σi =⇒ h{f (s1 , . . . , sn )ϑ ≃?∅ f (f2 (r1 , . . . , rk ), t1 , . . . , tm )ϑ} ∪ Γ ′ ϑ; σϑi if x ∈ / SVar(f (r1 , . . . , rk )) and ϑ = {x 7→ f1 (r1 , . . . , rk )}{f 7→ pf1 , f2 q}. We call the rules above except Projection the basic transformation rules. If we want to specify which rule was used to transform a system, we may use the rule name abbreviations as subscripts, e.g., we may write hΓ1 ; σ1 i =⇒P hΓ2 ; σ2 i to indicate that the system hΓ1 ; σ1 i was transformed to the system hΓ2 ; σ2 i by Projection. We may also write hΓ1 ; σ1 i =⇒BT hΓ2 ; σ2 i to indicate that the system hΓ1 ; σ1 i was transformed to the system hΓ2 ; σ2 i by some basic transformation rule. We denote the transitive and reflexive-transitive closure of =⇒ respectively by =⇒+ and =⇒∗ . Projection rule can be applied to the same system in (finitely many) different ways. Example 10. Projection rule transforms the system h{f (x, a) ≃?∅ f (a, y)}; εi in the following three different ways: 1. h{f (x, a) ≃?∅ f (a, y)}; εi =⇒P h{f (a) ≃?∅ f (a, y)}; {x 7→ pq}i. 22
2. h{f (x, a) ≃?∅ f (a, y)}; εi =⇒P h{f (x, a) ≃?∅ f (a)}; {y 7→ pq}i. 3. h{f (x, a) ≃?∅ f (a, y)}; εi =⇒P h{f (a) ≃?∅ f (a)}; {x 7→ pq, y 7→ pq}i. Sequence Variable Elimination 2, Widening 1 and 2, and Splitting are non-deterministic basic transformation rules. Example 11. The system h{f (x, a) ≃?∅ f (a, y)}; εi can be transformed by Sequence Variable Elimination 2 and Widening 1 rules: 1. h{f (x, a) ≃?∅ f (a, y)}; εi =⇒SVE2 h{f (a) ≃?∅ f (y)}; {x 7→ a}i. 2. h{f (x, a) ≃?∅ f (a, y)}; εi =⇒W1 h{f (x, a) ≃?∅ f (y)}; {x 7→ pa, xq}i. The system h{f (x, y, a) ≃?∅ f (a, z)}; εi can be transformed by Sequence Variable Elimination 2, Widening 1 and Splitting rules: 1. h{f (x, y, a) ≃?∅ f (a, z)}; εi =⇒SVE2 h{f (y, a) ≃?∅ f (z)}; {x 7→ a}i. 2. h{f (x, y, a) ≃?∅ f (a, z)}; εi =⇒W1 h{f (x, y, a) ≃?∅ f (z)}; {x 7→ pa, xq}i. 3. h{f (x, y, a) ≃?∅ f (a, z)}; εi =⇒Sp h{f (y, a1 , a2 ) ≃?∅ f (a2 , z)}; {x 7→ a1 , a 7→ pa1 , a2 q}i. The system h{f (x, a) ≃?∅ f (z, y)}; εi can be transformed by Sequence Variable Elimination 2, Widening 1 and Widening 2 rules: 1. h{f (x, a) ≃?∅ f (z, y)}; εi =⇒SVE2 h{f (a) ≃?∅ f (y)}; {x 7→ z}i. 2. h{f (x, a) ≃?∅ f (z, y)}; εi =⇒W1 h{f (x, a) ≃?∅ f (y)}; h{x 7→ pz, xq}i. 3. h{f (x, a) ≃?∅ f (z, y)}; εi =⇒W2 h{f (a) ≃?∅ f (z, y)}; h{z 7→ px, zq}i. A derivation is a sequence of system transformations hΓ1 ; σ1 i =⇒ hΓ2 ; σ2 i =⇒ hΓ3 ; σ3 i =⇒ · · · . A derivation is said to be fair if any transformation rule which is continuously enabled is eventually applied. Any finite fair derivation S1 =⇒ S2 =⇒ · · · =⇒ Sn is maximal, i.e., no further transformation rule can be applied on the system Sn . Definition 26. A syntactic unification procedure with sequence variables and flexible arity symbols is any program that takes a system hΓ ; εi as an input and uses the transformation rules of the inference system U to generate a tree of fair derivations, called the unification tree for Γ , in the following way: 1. The root of the tree is labelled with hΓ ; εi; 2. Each branch of the tree is a fair derivation either of the form hΓ ; εi =⇒P hΓ1 ; σ1 i =⇒BT hΓ2 ; σ2 i =⇒BT · · · or of the form hΓ ; εi =⇒BT hΓ1 ; σ1 i =⇒BT hΓ2 ; σ2 i =⇒BT · · · . The nodes in the tree are systems. 23
3. If several transformation rules, or different instances of the same transformation rule are applicable to a node in the tree, they are applied concurrently. 4. The decision procedure is applied to the root and to each node generated by a non-deterministic transformation rule, to decide whether the node contains a solvable unification problem. If the unification problem ∆ in a node h∆; δi is unsolvable, then the branch is extended by h∆; δi =⇒DP ⊥. We denote the syntactic unification tree for Γ with UT ree∅ (Γ ). The leaves of the unification tree of Γ , UT ree∅ (Γ ), are labeled either with the systems of the form h∅; σi or with the system ⊥. The branches of UT ree∅ (Γ ) that end with leaves of the form h∅; σi are called successful branches, and those with the leaves ⊥ are failed branches. We denote by Sol∅ (Γ ) the solution set for Γ , i.e., the set of all substitutions σ such that h∅; σi is a leaf of UT ree∅ (Γ ). Application of a decision procedure can be a costly operation. Therefore, we give below a “lighter” version that can detect some failing cases. It can serve as a pre-filter before applying the full scale decision procedure. This version consists of the following eight rules: Individual Variable Occurrence Check (IVOC): h{x ≃?∅ t} ∪ Γ ′ ; σi =⇒ ⊥ if x 6= t and x ∈ IVar(t). Symbol Clash 1 (SC1): h{f (s1 , . . . , sn ) ≃?∅ g(t1 , . . . , tm )} ∪ Γ ′ ; σi =⇒ ⊥ if f 6= g. Symbol Clash 2 (SC2): h{f (f (r1 , . . . , rk ), s1 , . . . , sn ) ≃?∅ f (g(q1 , . . . , ql ), t1 , . . . , tm )} ∪ Γ ′ ; σi =⇒ ⊥ if f 6= g. Arity Disagreement (AD): h{f (s1 , . . . , sn ) ≃?∅ f (t1 , . . . , tm )} ∪ Γ ′ ; σi =⇒ ⊥ if for all 1 ≤ i ≤ n and for all 1 ≤ j ≤ m, si ∈ / VSeq and tj ∈ / VSeq . Empty 1 (E1): h{f () ≃?∅ f (t, t1 , . . . , tn )} ∪ Γ ′ ; σi =⇒ ⊥ Empty 2 (E2): h{f (s, s1 , . . . , sn ) ≃?∅ f ()} ∪ Γ ′ ; σi =⇒ ⊥
24
Sequence Variable Occurrence Check (SVOC): h{f (x, s1 , . . . , sn ) ≃?∅ f (t, t1 , . . . , tm )} ∪ Γ ′ ; σi =⇒ ⊥ if x 6= t and x ∈ SVar(t). Prefix Failure (PF): h{f (s, s1 , . . . , sn ) ≃?∅ f (t, t1 , . . . , tm )} ∪ Γ ′ ; σi =⇒ ⊥ if s ∈ TSeq (F, V) \ VSeq and t ∈ TInd (F, V), or s ∈ TInd (F, V) and t ∈ TSeq (F, V) \ VSeq . These rules can detect many failing cases but not all. For instance, none of them apply to the unsolvable unification problem {f (x) ≃?∅ f (c, x)}. Example 12. Let Γ = {f (x) ≃?∅ f (f (x))}. Then the unification procedure immediately terminates because the pre-filter decision procedure (SVOC rule) shows that Γ is unsolvable: h{f (x) ≃?∅ f (f (x))}; εi =⇒DP ⊥ . Thus, Sol∅ (Γ ) = ∅. Example 13. Let Γ = {f (x, x, y) ≃?∅ f (f (x), x, a, b). Then the unification procedure generates the following seven derivations: h{f (x, x, y) ≃?∅ f (f (x), x, a, b)}; εi =⇒P h{f (x) ≃?∅ f (f (), x, a, b)}; {x 7→ pq, y 7→ pq}i =⇒DP ⊥ =⇒P h{f (x, x, y) ≃?∅ f (f (x), x, a, b)}; εi h{f (x, y) ≃?∅ f (f (), x, a, b)}; {x 7→ pq}i =⇒PD1 =⇒S h{x ≃?∅ f (), f (y) ≃?∅ f (x, a, b)}; {x 7→ pq}i h{f (y) ≃?∅ f (f (), a, b)}; {x 7→ pq, x 7→ f ()}i =⇒SVE2 h{f () ≃?∅ f (a, b)}; {x 7→ pq, x 7→ f (), y 7→ f ()}i =⇒DP ⊥ =⇒P h{f (x, x, y) ≃?∅ f (f (x), x, a, b)}; εi h{f (x, y) ≃?∅ f (f (), x, a, b)}; {x 7→ pq}i =⇒PD1 =⇒S h{x ≃?∅ f (), f (y) ≃?∅ f (x, a, b)}; {x 7→ pq}i h{f (y) ≃?∅ f (f (), a, b)}; {x 7→ pq, x 7→ f ()}i =⇒W1 h{f (y) ≃?∅ f (a, b)}; {x 7→ pq, x 7→ f (), y 7→ pf (), yq}i =⇒SVE2 =⇒DP ⊥ h{f () ≃?∅ f (b)}; {x 7→ pq, x 7→ f (), y 7→ pf (), aq}i h{f (x, x, y) ≃?∅ f (f (x), x, a, b)}; εi =⇒P =⇒PD1 h{x ≃?∅ f (), f (y) ≃?∅ f (x, a, b)}; {x 7→ pq}i =⇒S h{f (y) ≃?∅ f (f (), a, b)}; {x 7→ pq, x 7→ f ()}i h{f (y) ≃?∅ f (a, b)}; {x 7→ pq, x 7→ f (), y 7→ pf (), yq}i =⇒W1 h{f (y) ≃?∅ f (b)}; {x 7→ pq, x 7→ f (), y 7→ pf (), a, yq}i =⇒SVE2 h{f () ≃?∅ f ()}; {x 7→ pq, x 7→ f (), y 7→ pf (), a, bq}i =⇒T h∅; {x 7→ pq, x 7→ f (), y 7→ pf (), a, bq}i h{f (x, x, y) ≃?∅ f (f (x), x, a, b)}; εi =⇒P h{f (x, x) ≃?∅ f (f (x), x, a, b)}; {y 7→ pq}i =⇒DP ⊥ 25
h{f (x, x, y) ≃?∅ f (f (x), x, a, b)}; εi =⇒P h{x ≃?∅ f (), f (y) ≃?∅ f (x, a, b)}; {x 7→ pq}i =⇒PD1 =⇒S h{f (y) ≃?∅ f (f (), a, b)}; {x 7→ pq, x 7→ f ()}i =⇒W1 h{f (y) ≃?∅ f (f (), a, b)}; {x 7→ pq, x 7→ f ()}i h{f (y) ≃?∅ f (a, b)}; {x 7→ pq, x 7→ f (), y 7→ pf (), yq}i =⇒W1 h{f (y) ≃?∅ f (b)}; {x 7→ pq, x 7→ f (), y 7→ pf (), a, yq}i =⇒W1 h{f (y) ≃?∅ f ()}; {x 7→ pq, x 7→ f (), y 7→ pf (), a, b, yq}i =⇒DP ⊥ h{f (x, x, y) ≃?∅ f (f (x), x, a, b)}; εi =⇒DP ⊥ Therefore, Sol∅ (Γ ) = {{x 7→ pq, x 7→ f (), y 7→ pf (), a, bq}}. Example 14. Let Γ = {f (x, x, y) ≃?∅ f (a, x, b)}. Then the unification procedure generates the following nine derivations: h{f (x, x, y) ≃?∅ f (a, x, b)}; εi =⇒P h{f (x) ≃?∅ f (a, x, b)}; {x 7→ pq, y 7→ pq}i =⇒DP ⊥ =⇒P h{f (x, x, y) ≃?∅ f (a, x, b)}; εi h{f (x, y) ≃?∅ f (a, x, b)}; {x 7→ pq}i =⇒PD1 =⇒S h{x ≃?∅ a, f (y) ≃?∅ f (x, b)}; {x 7→ pq}i h{f (y) ≃?∅ f (a, b)}; {x 7→ pq, x 7→ a}i =⇒SVE2 h{f () ≃?∅ f (b)}; {x 7→ pq, x 7→ a, y 7→ a}i =⇒DP ⊥ h{f (x, x, y) ≃?∅ f (a, x, b)}; εi =⇒P =⇒PD1 h{f (x, y) ≃?∅ f (a, x, b)}; {x 7→ pq}i =⇒S h{x ≃?∅ a, f (y) ≃?∅ f (x, b)}; {x 7→ pq}i h{f (y) ≃?∅ f (a, b)}; {x 7→ pq, x 7→ a}i =⇒W1 h{f (y) ≃?∅ f (b)}; {x 7→ pq, x 7→ a, y 7→ pa, yq}i =⇒SVE2 h{f () ≃?∅ f ()}; {x 7→ pq, x 7→ a, y 7→ pa, bq}i =⇒T h∅; {x 7→ pq, x 7→ a, y 7→ pa, bq}i =⇒P h{f (x, x, y) ≃?∅ f (a, x, b)}; εi h{f (x, y) ≃?∅ f (a, x, b)}; {x 7→ pq}i =⇒PD1 =⇒S h{x ≃?∅ a, f (y) ≃?∅ f (x, b)}; {x 7→ pq}i h{f (y) ≃?∅ f (a, b)}; {x 7→ pq, x 7→ a}i =⇒W1 h{f (y) ≃?∅ f (b)}; {x 7→ pq, x 7→ a, y 7→ pa, yq}i =⇒W1 h{f (y) ≃?∅ f ()}; {x 7→ pq, x 7→ a, y 7→ pa, b, yq}i =⇒DP ⊥ h{f (x, x, y) ≃?∅ f (a, x, b)}; εi =⇒P h{f (x, x) ≃?∅ f (a, x, b)}; {y 7→ pq}i =⇒SVE2 h{f (x) ≃?∅ f (x, b)}; {y 7→ pq, x 7→ a}i =⇒DP ⊥ h{f (x, x, y) ≃?∅ f (a, x, b)}; εi =⇒P =⇒W1 h{f (x, x) ≃?∅ f (a, x, b)}; {y 7→ pq}i h{f (x, x) ≃?∅ f (x, b)}; {y 7→ pq, x 7→ pa, xq}i =⇒SVE2 h{f (x) ≃?∅ f (b)}; {y 7→ pq, x 7→ pa, xq}i =⇒PD1 =⇒S h{x ≃?∅ b}; {y 7→ pq, x 7→ pa, xq}i h∅; {y 7→ pq, x 7→ pa, bq, x 7→ b}i 26
h{f (x, x, y) ≃?∅ f (a, x, b)}; εi =⇒P h{f (x, x) ≃?∅ f (a, x, b)}; {y 7→ pq}i =⇒W1 h{f (x, x) ≃?∅ f (x, b)}; {y 7→ pq, x 7→ pa, xq}i =⇒W1 h{f (x, x) ≃?∅ f (b)}; {y 7→ pq, x 7→ pa, x, xq}i =⇒DP ⊥ h{f (x, x, y) ≃?∅ f (a, x, b)}; εi =⇒SVE2 =⇒PD1 h{f (x, y) ≃?∅ f (x, b)}; {x 7→ a}i h{x ≃?∅ x, f (y) ≃?∅ f (b)}; {x 7→ a}i =⇒T h{f (y) ≃?∅ f (b)}; {x 7→ a, y 7→ b}i =⇒SVE2 h{f () ≃?∅ f ()}; {x 7→ a, y 7→ b}i =⇒T h∅; {x 7→ a, y 7→ b}i =⇒W1 h{f (x, x, y) ≃?∅ f (a, x, b)}; εi h{f (x, x, y) ≃?∅ f (x, b)}; {x 7→ pa, xq}i =⇒DP ⊥ Sol∅ (Γ ) = {{x 7→ pq, x 7→ a, y 7→ pa, bq}, {y 7→ pq, x 7→ pa, bq, x 7→ b}, {x 7→ a, y 7→ b}}. Example 15. Let Γ = {f (x, a) ≃?∅ f (a, x)). Then the unification procedure generates the following derivations: =⇒P h{f (x, a) ≃?∅ f (a, x)}; εi h{f (a) ≃?∅ f (a)}; {x 7→ pq}i =⇒T h∅; {x 7→ pq}i h{f (x, a) ≃?∅ f (a, x)}; εi =⇒SVE2 h{f (a) ≃?∅ f (a)}; {x 7→ a}i =⇒T h∅; {x 7→ a}i h{f (x, a) ≃?∅ f (a, x)}; εi =⇒W1 h{f (x, a) ≃?∅ f (a, x)}; {x 7→ pa, xq}i =⇒SVE2 h{f (a) ≃?∅ f (a)}; {x 7→ pa, aq}i =⇒T h∅; {x 7→ pa, aq}i ... Then Sol∅ (Γ ) is infinite: Sol∅ (Γ ) = {{x 7→ pq}, {x 7→ a}, {x 7→ pa, aq}, . . .}. 6.1
Soundness
The following lemmata will be used to show that the inference system U is sound. Lemma 1. If hΓ ; σi =⇒ h∆; σϑi, then U∅ (∆) = U∅ (Γ ϑ). Proof. The non-trivial cases concern Solve, Sequence Variable Elimination 2, Widening 1 and 2 and Splitting rules. Solve: If x ∈ / IVar(t), then xθ ≃ tθ for θ = {x 7→ t} and Γ θ = {xθ ≃?∅ ′ tθ} ∪ Γ θ and ∆ = Γ ′ θ have the same set of unifiers. Sequence Variable Elimination 2 is similar to Solve. 27
Widening 1: Let Γ = {f (x, s1 , . . . , sn ) ≃?∅ f (t, t1 , . . . , tm )} such that x ∈ / SVar(t). Then, by W1, ∆ = {f (x, s1 ϑ, . . . , sn ϑ) ≃?∅ f (t1 ϑ, . . . , tm ϑ)}, where ϑ = {x 7→ pt, xq}. Then Γ ϑ = {f (t, x, s1 ϑ, . . . , sn ϑ) ≃?∅ f (t, t1 ϑ, . . . , tm ϑ)}. Then Γ ϑ and ∆ have exactly the same set of unifiers. Widening 2 is similar to widening 1. Splitting. Let Γ = {f (x, s1 , . . . , sn ) ≃?∅ f (g(r1 , . . . , rk ), t1 , . . . , tm )} such that x ∈ / SVar(g(r1 , . . . , rk )). Then by Sp we get ∆ = {f (s1 , . . . , sn )ϑ ≃?∅ f (g2 (r1 , . . . , rk ), t1 , . . . , tm )ϑ}, where ϑ = {x 7→ g1 (r1 , . . . , rk )}{g 7→ pg1 , g2 q}. Then Γ θ and ∆ have exactly the same set of unifiers, where Γ ϑ = { f (g1 (r1 , . . . , rk ), s1 , . . . , sn )ϑ ≃?∅ f (g1 (r1 , . . . , rk ), g2 (r1 , . . . , rk ), t1 , . . . , tm )ϑ}. ⊓ ⊔ Corollary 1. If hΓ ; σi =⇒ h∅; σϑi, then ϑ ∈ U∅ (Γ ). Proof. By Lemma 1, U∅ (∅) = U∅ (Γ ϑ), which implies that any substitution is a unifier of Γ ϑ. In particular, ε ∈ U∅ (Γ ϑ) and, therefore, ϑ ∈ U∅ (Γ ). ⊓ ⊔ Lemma 2. If U∅ (Γ σ) = U∅ (∆) and U∅ (∆ϑ) = U∅ (Φ), then U∅ (Γ σϑ) = U∅ (Φ). Proof. ϕ ∈ U∅ (Γ σϑ) iff ϑϕ ∈ U∅ (Γ σ) iff ϑϕ ∈ U∅ (∆) iff ϕ ∈ U∅ (∆ϑ) iff ϕ ∈ U∅ (Φ). ⊓ ⊔ Now we prove soundness. Theorem 9 (Soundness). If hΓ ; εi =⇒+ h∅; ϑi, then ϑ ∈ U∅ (Γ ). Proof. If the derivation length is 1, then Corollary 1 implies the theorem. Assume the derivation length is greater than 1. Then the derivation has the form hΓ ; εi =⇒ h∆1 ; δ1 i =⇒ · · · =⇒ h∆n ; δ1 δ2 · · · δn i where ∆n = ∅, δ1 δ2 · · · δn = ϑ and n > 1. Applying Lemma 1 n times we get U∅ (Γ δ1 ) = U∅ (∆1 ), U∅ (∆1 δ2 ) = U∅ (∆2 ), . . . , U∅ (∆n−1 δn ) = U∅ (∆n ). After that, applying Lemma 2 n − 1 times we get U∅ (Γ δ1 · · · δn ) = U∅ (∆n ) = U∅ (∅). Therefore, ϑ = δ1 · · · δn ∈ U∅ (Γ ). ⊓ ⊔ 6.2
Completeness
Proving completeness is more involved than the soundness proof. In this section we prove completeness by showing that for any unifier ϑ of a unification problem Γ there exists a derivation from hΓ ; εi that terminates with success and the substitution in the last system of the derivation is strongly more general than ϑ. First we construct a derivation from hΓ ; εi such that every substitution in the systems of the derivation is strongly more general than ϑ. To prove termination of the derivation, we need to define a complexity measure on the systems, introduce a well-founded ordering on the measures and show that every step in the derivation strictly decreases the measure. 28
By default, we work modulo the free theory. Therefore we will not mention it explicitly below. We start with introducing notions needed later to define the complexity measure of a system. Definition 27. The length of the image of a variable v with respect to a substitution σ, denoted ILen(v, σ), is 1 if v ∈ VInd , and is the length of the sequence vσ if v ∈ VSeq . The length P of the image of X with respect to σ, denoted ILen(X , σ), is defined as v∈X ILen(v, σ). X ,Q Lemma 3. For any σ, ϑ, X and Q, if σ ∅ ϑ then ILen(X , σ) ≤ ILen(X , ϑ).
X ,Q Proof. From σ ∅ ϑ we have that there exists a substitution ϕ, non-erasing on ,Q X , such that σϕ =X ϑ. It implies ILen(SVar(X ), σ) ≤ ILen(SVar(X ), ϑ). ∅ On the other hand, ILen(IVar(X ), σ) = ILen(IVar(X ), ϑ). Therefore, we get that ILen(X , σ) ≤ ILen(X , ϑ). ⊓ ⊔
LDif (X , ϑ, σ) denotes ILen(X , ϑ) − ILen(X , σ), where LDif stands for lengths difference. It is easy to see that LDif (X , ϑ, σ) = LDif (SVar(X ), ϑ, σ). Lemma 4. Let Γ be a general syntactic unification problem, X = Var(Γ ), Q = SFun(Γ ) and ϑ ∈ U∅ (Γ ). If ϑ is non-erasing on X , then there exists a derivation of the form hΓ1 ; σ1 i =⇒BT hΓ2 ; σ2 i =⇒BT · · · =⇒BT h∅, σk i X ,Q with Γ1 = Γ and σ1 = ε such that σk ∅ ϑ.
Proof. We prove the lemma in two steps. First, we construct a derivation of the form hΓ1 ; σ1 i =⇒BT hΓ2 ; σ2 i =⇒BT · · · with Γ1 = Γ and σ1 = ε such that for X ,Q all i ≥ 1 we have σi ∅ ϑ, and then we show that the derivation terminates with success. We construct the derivation recursively. We take Γ1 = Γ , σ1 = ε and start X ,Q the derivation from hΓ1 ; σ1 i. Obviously, σ1 ∅ ϑ. Now, assume hΓn ; σn i, n ≥ 1, Γn 6= ∅ belongs to the derivation and find a X ,Q system hΓn+1 ; σn+1 i such that hΓn ; σn i =⇒BT hΓn+1 ; σn+1 i and σn+1 ∅ ϑ. X ,Q Since hΓn ; σn i belongs to the derivation, we have σn ∅ ϑ, i.e., there exists ,Q ϕ, non-erasing on X , such that σn ϕ =X ϑ. Thus, we have σn ϕ ∈ U∅ (Γ1 ) ∅ and, therefore, ϕ ∈ U∅ (Γ1 σn ). Moreover, using Lemma 2 we can show that U∅ (Γ1 σn ) = U∅ (Γn ), which implies ϕ ∈ U∅ (Γn ). Without loss of generality, pick an arbitrary equation s ≃?∅ t from Γn and represent Γn as {s ≃?∅ t} ∪ Γn′ . The pair hs, ti can have one of the following four forms: 1. A pair of identical terms; 2. A pair of distinct individual variables; 3. A pair of an individual variable and a non-variable term; 29
4. A pair of distinct non-variable terms. Consider each of these cases separately: 1. We extend the derivation with the step hΓn ; σn i =⇒T hΓn′ ; σn i. Therefore, X ,Q σn+1 = σn ∅ ϑ. 2. Let s = x and t = y. Then xϕ ≃∅ yϕ. Let ψ = {x 7→ y}. Then ψϕ = ϕ. Thus, X ,Q ,Q σn ψϕ =X ϑ, which implies σn ψ ∅ ϑ. Therefore, we can take Γn+1 = ∅ ′ Γn ψ, σn+1 = σn ψ and extend the derivation with the step hΓn ; σn i =⇒S hΓn+1 ; σn+1 i. 3. If s = x and t is a non-variable term that does not contain x, then we proceed as in the previous case, extending the derivation with Solve rule. The case when t contains x is impossible, because it leads to the contradiction ϕ ∈ U∅ (Γn ) = ∅. If t = x and s is a non-variable term, then we take Γn+1 = {x ≃?∅ s} ∪ Γn′ , σn+1 = σn and extend the derivation with the step hΓn ; σn i =⇒O1 hΓn+1 ; σn+1 i. 4. Let s = f (s1 , . . . , sk ) and t = f (t1 , . . . , tm ) be distinct non-variable terms with the same heads such that the argument lists of the terms are non-empty (The cases when the heads are different, or when the list of arguments of one term is empty, lead to the contradiction ϕ ∈ U∅ (Γn ) = ∅.). If none of the arguments of s and t is a sequence term, then k = m (otherwise we get a contradiction) and the derivation can be extended with the Total Decomposition rule, taking σn+1 = σn . If there are sequence terms among the arguments of s and t, we have the following two alternatives: (a) Neither s1 nor t1 are sequence terms. Then we take σn+1 = σn and extend the derivation with Partial Decomposition 1 rule. (b) s1 or t1 is a sequence term. Let first assume that neither s1 nor t1 is a sequence variable. Then they both must be sequence terms with the same head (otherwise we get a contradiction) and we can proceed we Partial Decomposition 2 rule taking again σn+1 = σn . If s1 and t1 are the same sequence variable, then we extend the derivation with Sequence variable Elimination 1 rule again having σn+1 = σn . Next, assume only t1 is a sequence variable. Then we perform the Orient 2 step with σn+1 = σn . Now, let s1 be a sequence variable x and t1 be a term different from s1 . We can have the following three cases: i. t1 is a sequence variable y. Then we define substitutions ψ and ρ in three different ways as follows: – ψ = {x 7→ y} and ρ = ϕ, if f (x)ϕ ≃∅ f (y)ϕ; – ψ = {x 7→ py, xq} and ρ = {x 7→ pr1 , . . . , rl q} ∪ ϕ′ , where ϕ′ = ϕ|Dom(ϕ)\{x} , if there exists a non-empty sequence of terms r1 , . . . , rl such that f (xϕ) ≃∅ f (yϕ, r1 , . . . , rl ); – ψ = {y 7→ px, yq} and ρ = {y 7→ pr1 , . . . , rl q} ∪ ϕ′ , where ϕ′ = ϕ|Dom(ϕ)\{y} , if there exists a non-empty sequence of terms r1 , . . . , rl such that f (yϕ) ≃∅ f (xϕ, r1 , . . . , rl ). 30
Since ϕ ∈ U∅ (Γn ), these three cases for ψ are the only possibilities to get Γn+1 from Γn . Thus, we can take σn+1 = σn ψ and extend the derivation either by Sequence Variable Elimination 2, Widening 1 or Widening 2 rules, depending on the cases for ψ. Since ψρ = ϕ, ,Q ,Q we have σn ψρ =X ϑ and, thus, σn+1 ρ =X ϑ. Moreover, ρ is ∅ ∅ X ,Q non-erasing on the set X , which implies that σn+1 ∅ ϑ. ii. t1 is an individual term. Then t1 does not contain x and we can proceed as in the previous case, with the only difference that now ψ can have only two alternatives instead of three. Therefore, we can extend the derivation either by Sequence Variable Elimination 2 or X ,Q Widening 1 rule ensuring σn+1 = σn ψ ∅ ϑ. iii. t1 is a sequence term f (r1 , . . . , rl ). Then we define substitutions ψ and ρ in three different ways as follows: – ψ = {x 7→ t} and ρ = ϕ, if f (x)ϕ ≃∅ f (t)ϕ; – ψ = {x 7→ pt, xq} and ρ = {x 7→ pq1 , . . . , qj q} ∪ ϕ′ , where ϕ′ = ϕ|Dom(ϕ)\{x} , if there exists a non-empty sequence of terms q1 , . . . , qj such that f (x)ϕ ≃∅ f (tϕ, q1 , . . . , qj ); – ψ = {x 7→ f1 (r1 , . . . , rl )}{f 7→ pf1 , f2 q}, ρ = ϕ|Dom(ϕ)\{f } , if for some sequence function symbols f1 and f2 , f (f (r1 , . . . , rl ))ϕ = f (f1 (r1 , . . . , rl ), f2 (r1 , . . . , rl ))ϕ and f (x)ϕ = f (f1 (r1 , . . . , rl ))ϕ. Since ϕ ∈ U∅ (Γn ), these three cases for ψ are the only possibilities to get Γn+1 from Γn . Thus, we can take σn+1 = σn ψ and get Γn+1 from Γn either by Sequence Variable Elimination 2, Widening 1 or Splitting rules, depending on the cases for ψ. Since ψρ = ϕ, we have ,Q ,Q σn ψρ =X ϑ and, thus, σn+1 ρ =X ϑ. Moreover, ρ is non-erasing ∅ ∅ X ,Q on the set X , which implies that σn+1 ϑ. ∅
Now, we have to show that the constructed derivation terminates with success. Define a complexity measure (with respect to a given substitution and a set of variables) on systems as a 7-tuple of integers, ordered by the lexicographic ordering on tuples of integers as follows: the tuple hm1 , m2 , m3 , m4 , m5 , m6 , m7 i is a complexity measure of a system h∆; σi with respect to a substitution λ and a set of variables Y, if m1 = The number of distinct variables in ∆; m2 = LDif (Y, λ, σ). m3 = The number of symbols in ∆; m4 = The number of occurrences of sequence function symbols in ∆; m5 = The number of subterms in ∆ of the form f (s1 , . . . , sn ), where s1 is not a sequence term; m6 = The number of equations in ∆ of the form t ≃?∅ x, where t is not an individual variable; m7 = The number of equations in ∆ that have the form f (s, s1 , . . . , sn ) ≃?∅ f (x, t1 , . . . , tm ), where s is not a sequence variable. First, observe that all these numbers except m2 are, indeed, natural numbers. As for m2 , depending on λ and σ, it can also be negative. But for each system 31
hΓi ; σi i in the derivation we constructed above, for the substitution ϑ and for the set X , by Lemma 3 we have LDif (X , ϑ, σi ) ≥ 0, i.e., m2 is a natural number for each hΓi ; σi i. Thus, the ordering on complexity measures of systems (with respect to ϑ and X ) in the derivation is well-founded. Now we show that each step in the derivation strictly reduces the complexity measure of the system with respect to X and ϑ. – Trivial rule does not increase m1 , does not change m2 and decreases m3 . – Total Decomposition leaves m1 and m2 unchanged and decreases m3 . – Partial Decomposition 1 leaves m1 , m2 , m3 and m4 unchanged and decreases m5 . – Partial Decomposition 2 leaves m1 , m2 and m3 unchanged and decreases m4 . – Orient 1 decreases m6 and leaves the others unchanged. – Orient 2 decreases m7 and leaves the others unchanged. – Solve decreases m1 . – Sequence Variable Elimination 1 does not increase m1 , does not change m2 and decreases m3 . – Sequence Variable Elimination 2 decreases m1 . – Widening 1 does not change m1 but decreases m2 : Let the corresponding step in the derivation be hΓi ; σi i =⇒W1 hΓi+1 ; σi+1 i where Γi = {f (x, s1 , . . . , sn ) ≃?∅ f (t, t1 , . . . , tm )} ∪ Γi′ , Γi+1 = {f (x, s1 ϕ, . . . , sn ϕ) ≃?∅ f (t1 ϕ, . . . , tm ϕ)} ∪ Γi′ ϕ and σi+1 = σi ϕ, with x ∈ / SVar(t) and ϕ = {x 7→ pt, xq}. It is clear that the step does not change the number of distinct variables in the systems. Moreover, x ∈ X , because x ∈ SVar(Γi ) and SVar(Γi ) ⊆ X (The last inclusion follows from the simple observation that no rule in the inference system U introduces a new variable.). For all y ∈ X \ {x}, ILen(y, σi+1 ) ≥ ILen(y, σi ). As for x itself, if x ∈ VDom(σi ), then x ∈ {xσi } (otherwise it would have been impossible to have x in SVar(Γi+1 )) and therefore ILen(x, σi+1 ) > ILen(x, σi ). If x ∈ / VDom(σi ), then ILen(x, σi+1 ) = 2 > 1 = ILen(x, σi ). It means that ILen(X , σi+1 ) > ILen(X , σi ), i.e., LDif (X , ϑ, σi ) > LDif (X , ϑ, σi+1 ). – Widening 2, like Widening 1, does not change m1 but decreases m2 . – Splitting decreases m1 . Thus, every step reduces the complexity of the systems in the derivation. Therefore, the derivation terminates. Let hΓk , σk i be the last system in the derivation. X ,Q Then, on the one hand, σk ∅ ϑ, on the other hand, Γk = ∅ (otherwise we could make another basic transformation step), which finishes the proof. ⊓ ⊔ Lemma 5. Let Γ be a general syntactic unification problem, X = Var(Γ ), Q = SFun(Γ ), and ϑ ∈ U∅ (Γ ). If ϑ is erasing on X , then there exists a derivation of the form hΓ0 ; σ0 i =⇒P hΓ1 ; σ1 i =⇒BT hΓ2 ; σ2 i =⇒BT · · · =⇒BT h∅; σn i with X ,Q Γ0 = Γ and σ0 = ε such that σn ∅ ϑ. Proof. Assume that x1 7→ pq, . . . , xk 7→ pq, where k > 0 and x1 , . . . , xk ∈ X , are all the bindings in ϑ that bind a sequence variable from X with the empty 32
sequence. Let σ1 = {x1 7→ pq, . . . , xk 7→ pq}, Γ1 = Γ0 σ1 , and make Projection the first step of derivation hΓ0 ; σ0 i =⇒P hΓ1 ; σ1 i. We have σ1 σ1 = σ1 . Let ϕ be ϑ|Dom(ϑ)\Dom(σ1 ) . Then ϑ = σ1 ϕ = σ1 σ1 ϕ ∈ U∅ (Γ0 ). Therefore, σ1 ϕ ∈ U∅ (Γ0 σ1 ), i.e., ϑ ∈ U∅ (Γ1 ). Moreover, ϑ is non-erasing on Var(Γ1 ). Then, by Lemma 4, there exists a derivation h∆1 ; δ1 i =⇒BT X ′ ,Q′ ϑ, h∆2 ; δ2 i =⇒BT · · · =⇒BT h∅; δn i such that ∆1 = Γ1 , δ1 = ε and δn ∅ where X ′ = Var(Γ1 ) and Q′ = SFun(Γ1 ), i.e., there exists a substitution ψ that ′ ,Q′ ϑ. Since Q′ = Q, we, in fact, have is non-erasing on X ′ such that δn ψ =X ∅ ′
,Q δn ψ =X ϑ. Moreover, since the rules in U do not introduce new variables, ∅ VDom(δn ) ⊆ X ′ and Ran(δn ) ⊆ X ′ . From the latter we can assume that ψ is non-erasing on any finite superset of X ′ , in particular, on X . From the former ,Q we have σ1 δn = σ1 ∪ δn and, finally, σ1 δn ψ =X ϑ. ∅ Note that for all i ≥ 1, if h∆i+1 ; δi+1 i is obtained from h∆i ; δi i by some rule of the system U, then h∆i+1 ; σ1 δi+1 i can be obtained from h∆i ; σ1 δi i exactly by the same rule. Thus, taking Γi = ∆i and σi = σ1 δi for all 1 < i ≤ n, we get the derivation hΓ ; εi =⇒P hΓ1 ; σ1 i =⇒BT hΓ2 ; σ2 i =⇒BT · · · =⇒BT h∅; σn i X ,Q such that σn ∅ ϑ. ⊓ ⊔ X ,Q X ,Q From Theorem 9, Lemma 4, Lemma 5 and the fact that E ⊆ ≤ E , by Definition 26 and Definition 19 we get the completeness theorem:
Theorem 10 (Completeness). Let Γ be a general syntactic unification problem. Then Sol∅ (Γ ) is a complete set of syntactic unifiers of Γ . 6.3
Almost Minimality
The set Sol∅ (Γ ), in general, is not minimal with respect to Var(Γ ) and SFun(Γ ). Just consider Γ = {f (x) ≃?∅ f (y)}, then Sol∅ (Γ ) = {{x 7→ y}, {x 7→ pq, y 7→ pq}}. However, it can be shown that Sol∅ (Γ ) is almost minimal with respect to Var(Γ ) and SFun(Γ ). In fact, we will prove a stronger statement: Sol∅ (Γ ) is almost disjoint with respect to Var(Γ ) and SFun(Γ ). First we introduce some notation. Let Γ = {s ≃?∅ t} ∪ Γ ′ be a general syntactic unification problem where the equation s ≃?∅ t is selected to perform a transformation step. We denote by Sub(Γ ) the set of substitutions {δ | h{s ≃?∅ t} ∪ Γ ′ ; εi =⇒ h∆; δi for some ∆} and by Proj(Γ ) the set of projecting substitutions {π | h{s ≃?∅ t} ∪ Γ ′ ; εi =⇒P h{sπ ≃?∅ tπ} ∪ Γ ′ π; πi}. Lemma 6. Let Γ be a general syntactic unification problem and let X = Var(Γ ) and Q = SFun(Γ ). Then Proj(Γ ) is almost disjoint with respect to X and Q. Proof. Assume by contradiction that Proj(Γ ) is not almost disjoint. Then there X ,Q exist two substitutions σ, ϑ ∈ Proj(Γ ) and a substitution ϕ such that σ ∅ ϕ X ,Q and ϑ ∅ ϕ. Since σ 6= ϑ, we assume without loss of generality that there / σ. But then x 7→ pq ∈ ϕ, and exists x ∈ X such that x 7→ pq ∈ ϑ and x 7→ pq ∈ ,Q ϕ. It contradicts therefore x 7→ pq ∈ δ for any substitution δ such that σδ =X ∅ X ,Q the fact that σ ϕ. ⊓ ⊔ ∅
33
Lemma 7. Let Γ be a general syntactic unification problem and let X = Var(Γ ) and Q = SFun(Γ ). Then Sub(Γ ) is almost disjoint with respect to X iff Sub(Γ )\ Proj(Γ ) is almost disjoint with respect to X and Q. Proof. (⇒) Since Sub(Γ ) is almost disjoint with respect to X , any subset of Sub(Γ ) is almost disjoint with respect to X . (⇐) Since, by the assumption and Lemma 6, respectively, Sub(Γ ) \ Proj(Γ ) and Proj(Γ ) are almost disjoint with respect to X and Q, what remains to show is that no σ ∈ Sub(Γ ) \ Proj(Γ ) and ϑ ∈ Proj(Γ ) can not have a common strong ∅-instance on X and Q. Assume by contradiction that there exists ϕ such X ,Q X ,Q that σ ∅ ϕ and ϑ ∅ ϕ. Then there exists x ∈ X such that x 7→ pq ∈ ϑ and x 7→ pq ∈ / σ. But then x 7→ pq ∈ ϕ, and therefore x 7→ pq ∈ δ for any X ,Q ,Q substitution δ such that σδ =X ϕ. It contradicts the fact that σ ∅ ϕ. ⊓ ⊔ ∅ Lemma 8. Let Γ be a general syntactic unification problem and let X = Var(Γ ) and Q = Var(Γ ). Then Sub(Γ ) \ Proj(Γ ) is almost disjoint with respect to X and Q. Proof. A singleton or the empty set of substitutions is trivially almost disjoint with respect to any finite sets of variables and function symbols. Therefore, we consider only the cases when Sub(Γ ) \ Proj(Γ ) can contain more than one element. It leads to assuming that the equation selected from Γ for transformation has a form {f (s, s1 , . . . , sn ) ≃?∅ f (t, t1 , . . . , tm )}, where s is a sequence variable and t is a term different from s. We can have the following cases: 1. Let s = x and t = y. Then Sub(Γ ) \ Proj(Γ ) = {σ1 , σ2 , σ3 }, where σ1 = {x 7→ y}, σ2 = {x 7→ py, xq} and σ3 = {y 7→ px, yq}. Assume by contradiction that Sub(Γ ) \ Proj(Γ ) is not almost disjoint with respect to X and Q. Then there must exist 1 ≤ i < j ≤ 3 such that σi and σj have a common ,Q strong ∅-instance, i.e., there exist ϑ and ϕ such that σi ϑ =X σj ϕ, and ϑ ∅ and ϕ are non-erasing on X . (a) Assume i = 1 and j = 2. Then we have xσ1 ϑ = yϑ, xσ2 ϕ = pyϕ, xϕq, yσ1 ϑ = yϑ, yσ2 ϕ = yϕ. It implies that xϕ should be the empty sequence, i.e., ϕ must contain the binding x 7→ pq, but this contradicts the fact that ϕ is non-erasing on X . (b) Assume i = 1 and j = 3. Then xσ1 ϑ = yϑ, xσ3 ϕ = xϕ, yσ1 ϑ = yϑ, yσ3 ϕ = pxϕ, yϕq. It implies that yϕ should be the empty sequence, i.e., ϕ must contain the binding y 7→ pq, but this contradicts the fact that ϕ is non-erasing on X . (c) Assume i = 2 and j = 3. Then xσ2 ϑ = pyϑ, xϑq, xσ3 ϕ = xϕ, yσ2 ϑ = yϑ, yσ3 ϕ = pxϕ, yϕq. It implies that yϕ and xϑ should be the empty sequences, i.e., ϕ must contain the binding y 7→ pq and ϑ must contain the binding x 7→ pq, but this contradicts the fact that ϕ and ϑ are non-erasing on X . 2. If s occurs in t, then Sub(Γ ) \ Proj(Γ ) = ∅ and is trivially almost disjoint. Otherwise, if t is not a sequence term, we can proceed similarly to the case above, having only two elements in Sub(Γ ) \ Proj(Γ ). If t is a non-variable 34
sequence term, assume that s = x and t = f (r1 , . . . , rk ), k ≥ 0. Then Sub(Γ ) \ Proj(Γ ) = {σ1 , σ2 , σ3 }, where σ1 = {x 7→ f (r1 , . . . , rk )}, σ2 = {x 7→ pf (r1 , . . . , rk ), xq} and σ3 = {x 7→ f1 (r1 , . . . , rk )}{f 7→ pf1 , f2 q}. We can show as in the case (1a) above that σ1 and σ2 can not have a common strong ∅-instance. As for σ1 and σ3 , they can not even have a common ∅instance, as well as σ2 and σ3 , because the sequence function symbol f2 can not be eliminated from σ3 . It implies that Sub(Γ ) \ Proj(Γ ) is almost disjoint with respect to X and Q. ⊓ ⊔ From Lemma 6, Lemma 7 and Lemma 8 we get the following theorem: Theorem 11. Let Γ be a general syntactic unification problem and let X = Var(Γ ) and Q = SFun(Γ ). Then Sub(Γ ) is almost disjoint with respect to X and Q. Now, we show that substitutions from Sub(Γ ) preserve almost disjointness. First, we prove the two lemmata below. Lemma 9. Let Γ be a general syntactic unification problem and let X = Var(Γ ) and Q = SFun(Γ ). Then every substitution σ ∈ Proj(Γ ) is almost-disjointness preserving on X and Q. Proof. Let ϑ1 and ϑ2 be two substitutions such that {ϑ1 , ϑ2 } is almost disjoint with respect to the set of variables ∪v∈X Var(vσ) = X \ VDom(σ) and the set of sequence function symbols ∪f ∈Q SFun(f σ) = Q. Assume by contradiction that the set {σϑ1 , σϑ2 } is not almost disjoint with respect to X and Q. Then there ,Q exist substitutions ϕ1 and ϕ2 , both non-erasing on X , such that σϑ1 ϕ1 =X ∅ X \VDom(σ),Q
σϑ2 ϕ2 . But then ϑ1 ϕ1 =∅ ϑ2 ϕ2 , which contradicts the fact that {ϑ1 , ϑ2 } is almost disjoint with respect to X \ VDom(σ) and Q. ⊓ ⊔ Lemma 10. Let Γ be a general syntactic unification problem and let X = Var(Γ ) and Q = SFun(Γ ). Then every substitution σ ∈ Sub(Γ ) \ Proj(Γ ) is almost-disjointness preserving on X and Q. Proof. Without loss of generality, pick an arbitrary equation s ≃?∅ t from Γ and represent Γ as {s ≃?∅ t} ∪ Γ ′ . The pair hs, ti can have one of the following four forms: 1. 2. 3. 4.
A A A A
pair pair pair pair
of of of of
identical terms; distinct individual variables; an individual variable and a non-variable term; distinct non-variable terms.
We consider each of these cases. 1. In this case Sub(Γ )\Proj(Γ ) contains only ε, that trivially preserves almost disjointness. 35
2. Let s = x and t = y. Then Sub(Γ ) \ Proj(Γ ) = Sub(Γ ) = {σ}, where σ = {x 7→ y}. We have ∪v∈X Var(vσ) = X \ {x} and ∪f ∈Q SFun(f σ) = Q. Let ϑ1 and ϑ2 be two substitutions such that {ϑ1 , ϑ2 } is almost disjoint with respect to X \ {x} and Q and show that {σϑ1 , σϑ2 } is almost disjoint with respect to X and Q. Assume by contradiction that it is not. Then there ,Q exist substitutions ϕ1 and ϕ2 such that σϑ1 ϕ1 =X σϑ2 ϕ2 . It implies that ∅ uσϑ1 ϕ1 ≃∅ uσϑ2 ϕ2 for all u ∈ X \ {x}. But since uσ = u for all u ∈ X \ {x}, we get uϑ1 ϕ1 ≃∅ uϑ2 ϕ2 for all u ∈ X \ {x} that contradicts the fact that {ϑ1 , ϑ2 } is almost disjoint with respect to X \ {x} and Q. 3. If t = x, then Sub(Γ ) \ Proj(Γ ) contains only {ε} that preserves almost disjointness. If s = x and x ∈ Var(t), then Sub(Γ ) = ∅ and the theorem is trivially true. Assume s = x and x ∈ / Var(t). Then Sub(Γ ) \ Proj(Γ ) = {σ}, where σ = {x 7→ t}. Moreover, ∪v∈X Var(vσ) = X \ {x} and ∪f ∈Q SFun(f σ) = Q and we can proceed as in the previous case. 4. Let s = f (s1 , . . . , sk ) and t = f (t1 , . . . , tm ) be distinct non-variable terms with the same heads such that the argument lists of the terms are non-empty (The cases when the heads are different, or when the list of arguments of one term is empty, we have Sub(Γ ) \ Proj(Γ ) = ∅ and the theorem is trivially true.). If none of the arguments of s and t is a sequence term, then k 6= m gives Sub(Γ ) \ Proj(Γ ) = ∅, and k = m gives Sub(Γ ) \ Proj(Γ ) = {ε}. In both cases the theorem is true. If there are sequence terms among the arguments of s and t, we have the following two alternatives: (a) Neither s1 nor t1 are sequence terms. Then Sub(Γ ) \ Proj(Γ ) = {ε} and the theorem is true. (b) s1 or t1 is a sequence term. Let first assume that neither s1 nor t1 is a sequence variable. If they both are sequence terms with different heads, then Sub(Γ ) \ Proj(Γ ) = ∅. If they both are sequence terms with the same head, then Sub(Γ ) \ Proj(Γ ) = {ε}. The theorem is true in either case. If s1 and t1 are the same sequence variable, or only t1 is a sequence variable, then Sub(Γ ) \ Proj(Γ ) = {ε} and the theorem is again true. Now, let s1 be a sequence variable x and t1 be a term different from s1 . Then we have the following three cases: i. t1 is a sequence variable y. Then Sub(Γ ) \ Proj(Γ ) = {σ1 , σ2 , σ3 }, where σ1 = {x 7→ y}, σ2 = {x 7→ py, xq} and σ3 = {y 7→ px, yq}. We have ∪v∈X Var(vσ1 ) = X \ {x}, ∪v∈X Var(vσ2 ) = ∪v∈X Var(vσ3 ) = X , ∪f ∈Q SFun(f σ1 ) = ∪f ∈Q SFun(f σ2 ) = ∪f ∈Q SFun(f σ3 ) = Q. We will show that each of σ1 , σ2 and σ3 preserves almost disjointness on X and Q. For σ1 we can proceed similarly to the case (2) above. 36
As for σ2 , let ϑ1 and ϑ2 be two substitutions such that {ϑ1 , ϑ2 } is almost disjoint with respect to X and Q. Assume by contradiction that {σ2 ϑ1 , σ2 ϑ2 } is not almost disjoint with respect to X and Q. Then there exist ϕ1 and ϕ2 , both non-erasing on X , such that ,Q σ2 ϑ1 ϕ1 =∅X ,Q σ2 ϑ2 ϕ2 . But then ϑ1 ϕ1 =X ϑ2 ϕ2 , that contradicts ∅ the fact that {ϑ1 , ϑ2 } is almost disjoint with respect to X and Q. The case with σ3 is similar to the case with σ2 . ii. t1 is an individual term. If x occurs in t1 , then Sub(Γ ) \ Proj(Γ ) = ∅ and the theorem is trivially true. Otherwise, we proceed as in the case above with t1 a sequence variable, having only two elements in Sub(Γ ) \ Proj(Γ ). iii. t1 is a sequence term f (r1 , . . . , rk ). If x occurs in t1 , then Sub(Γ ) \ Proj(Γ ) = ∅ and the theorem is trivially true. Otherwise Sub(Γ ) \ Proj(Γ ) = {σ1 , σ2 , σ3 }, where σ1 = {x 7→ f (r1 , . . . , rk )}, σ2 = {x 7→ pf (r1 , . . . , rk ), xq}, σ3 = {x 7→ f1 (r1 , . . . , rk ), f 7→ pf1 , f2 q}. Moreover, we have ∪v∈X Var(vσ1 ) = ∪v∈X Var(vσ3 ) = X \ {x}, ∪v∈X Var(vσ2 ) = X , ∪f ∈Q SFun(f σ1 ) = ∪f ∈Q SFun(f σ2 ) = Q, ∪f ∈Q SFun(f σ3 ) = Q ∪ {f1 , f2 } \ {f }. We will show that each of σ1 , σ2 and σ3 preserves almost disjointness on X and Q. For σ1 and σ2 we can repeat the reasoning used in the corresponding cases above where both s1 and t1 were sequence variables. As for σ3 , let ϑ1 and ϑ2 be two substitutions such that {ϑ1 , ϑ2 } is almost disjoint with respect to X \{x} and Q∪{f1 , f2 }\{f }. Assume by contradiction that {σ3 ϑ1 , σ3 ϑ2 } is not almost disjoint with respect to X and Q. Then there exist ϕ1 and ϕ2 , both non-erasing on X , ′ ,Q ,Q′ ϑ2 ϕ2 , where such that σ3 ϑ1 ϕ1 =X σ3 ϑ2 ϕ2 . But then ϑ1 ϕ1 =X ∅ ∅ X ′ = X \ {x} and Q′ = Q ∪ {f1 , f2 } \ {f }, that contradicts the fact that {ϑ1 , ϑ2 } is almost disjoint with respect to X \ {x} and Q ∪ {f1 , f2 } \ {f }. ⊓ ⊔ From Lemma 9 and Lemma 10 we get the following theorem. Theorem 12. Let Γ be a general syntactic unification problem and let X = Var(Γ ) and Q = SFun(Γ ). Then every substitution σ ∈ Sub(Γ ) is almostdisjointness preserving on X and Q. Lemma 11. Let σ1 and σ2 be two substitutions such that {σ1 , σ2 } is almost disjoint with respect to X and Q. Let ϑ1 and ϑ2 be two non-erasing substitutions on X . Then {σ1 ϑ1 , σ2 ϑ2 } is almost disjoint with respect to X and Q. 37
Proof. Assume by contradiction that {σ1 ϑ1 , σ2 ϑ2 } is not almost disjoint with respect to X and Q. Then there exist substitutions ϕ1 and ϕ2 , both non-erasing ,Q on X , such that σ1 ϑ1 ϕ1 =X σ2 ϑ2 ϕ2 , which contradicts the fact that {σ1 , σ2 } ∅ is almost disjoint with respect to X and Q. ⊓ ⊔ The next result is the almost disjointness theorem: Theorem 13 (Almost Disjointness). Let Γ be a general syntactic unification problem and let X = Var(Γ ) and Q = SFun(Γ ). Then Sol∅ (Γ ) is almost disjoint with respect to X and Q. Proof. Let σ1 , σ2 be two substitutions from Sol∅ (Γ ) and let hΓ, εi =⇒ hΓ1 , γ1 i =⇒ . . . =⇒ hΓn , γ1 γ2 · · · γn i =⇒ =⇒ h∆1 , δ1 i =⇒ . . . =⇒ h∆m , δm i =⇒ h∅, σ1 i and hΓ, εi =⇒ hΓ1 , γ1 i =⇒ . . . =⇒ hΓn , γ1 γ2 · · · γn i =⇒ =⇒ hΦ1 , ϕ1 i =⇒ . . . =⇒ hΦk , ϕk i =⇒ h∅, σ2 i be two derivations, leading respectively to h∅, σ1 i and h∅, σ2 i and having the common part hΓ, εi =⇒ hΓ1 , γ1 i =⇒ hΓ2 , γ1 γ2 i =⇒ . . . =⇒ hΓn , γ1 γ2 · · · γn i. Let γ0 = ε. First, we show that γ0 γ1 · · · γn is almost-disjointness preserving with respect to X and Q. We use induction on n. If n = 0, by Definition 21, γ0 = ε is almostdisjointness preserving with respect to X and Q. Then, assume γ0 γ1 · · · γn0 is almost-disjointness preserving with respect to X and Q for n0 > 0, and show that γ0 γ1 · · · γn0 γn0 +1 also preserves almost disjointness with respect to X and Q. Let ϑ1 , ϑ2 be two substitutions such that the set {ϑ1 , ϑ2 } is almost disjoint with respect to the set of variables ∪v∈X Var(vγ0 γ1 · · · γn0 γn0 +1 ) and the set of sequence function symbols ∪f ∈Q SFun(f γ0 γ1 · · · γn0 γn0 +1 ). We have to prove that the set {γ0 γ1 · · · γn0 γn0 +1 ϑ1 , γ0 γ1 · · · γn0 γn0 +1 ϑ2 } is almost disjoint with respect to X and Q. The substitution γn0 +1 ∈ Sub(Γn0 +1 ), therefore, by Theorem 12, γn0 +1 is almost-disjointness preserving with respect to Var(Γn0 +1 ) and SFun(Γn0 +1 ). It implies that the set {γn0 +1 ϑ1 , γn0 +1 ϑ2 } is almost disjoint with respect to the sets Var(Γn0 +1 ) and SFun(Γn0 +1 ). From the induction hypothesis and the facts Var(Γn0 +1 ) = ∪v∈X Var(vγ0 γ1 · · · γn0 ) and SFun(Γn0 +1 ) = ∪f ∈Q SFun(f γ0 γ1 · · · γn0 ), by Definition 21, we conclude that the set of substitutions {γ0 γ1 · · · γn0 γn0 +1 ϑ1 , γ0 γ1 · · · γn0 γn0 +1 ϑ2 } is almost disjoint with respect to X and Q. Thus, the substitution γ0 γ1 . . . γn is almost-disjointness preserving with respect to X and Q. Now we will show that the set {δ1 · · · δm , ϕ1 · · · ϕk } is almost disjoint with respect to Var(Γn ) and SFun(Γn ). 38
The substitutions δ1 , ϕ1 ∈ Sub(Γn ) and, by Theorem 11, the set {δ1 , ϕ1 } is almost disjoint with respect to Var(Γn ) and SFun(Γn ). The substitutions δ2 · · · δm and ϕ2 · · · ϕk are non-erasing on Var(Γn ). Therefore, by Lemma 11, the set {δ1 δ2 · · · δm , ϕ1 ϕ2 · · · ϕk } is almost disjoint with respect to Var(Γn ) and SFun(Γn ). Since we have Var(Γn ) = ∪v∈X Var(vγ0 γ1 · · · γn ) and SFun(Γn ) = ∪f ∈Q SFun(f γ0 γ1 · · · γn ), therefore, by Definition 21, we obtain that the set {γ0 γ1 · · · γn δ1 · · · δm , γ0 γ1 · · · γn ϕ1 · · · ϕk } is almost disjoint with respect to the sets X and Q. Since γ0 γ1 · · · γn δ1 · · · δm = σ1 and γ0 γ1 · · · γn ϕ1 · · · ϕk = σ2 , we obtained that {σ1 , σ2 } is almost disjoint with respect to X and Q, i.e., an arbitrary two element subset of Sol∅ (Γ ) is almost disjoint with respect to X and Q. By Definition 20, we conclude that Sol∅ (Γ ) is almost disjoint with respect to X and Q. ⊓ ⊔ Theorem 10, Theorem 13 and Proposition 3 imply the main result of this section: Theorem 14 (Main Theorem). Let Γ be a general syntactic unification problem. Then Sol∅ (Γ ) = amcu∅ (Γ ).
7
Special Cases
7.1
Sequence Variables Occur only in the Last Argument Position
The case when sequence variables occur only in the last argument positions in terms is quite interesting. It turns out that for this case unification becomes unitary, there is no need to apply the decision procedure, and we can use a modified version of the inference system U. We denote this version by U ′ . It consists of the following inference rules: Trivial, Total Decomposition, Partial Decomposition 1 and 2, Individual variable occurrence check, Symbol Clash 1 and 2, Arity Disagreement, Prefix Failure, Orient 1 and 2, and Solve. In addition, we have the inference rules Empty’ 1 and 2, Sequence Variable Occurrence Check’, Sequence Variable Deletion’ 1 and 2, and Sequence Variable Elimination’, defined as follows: Empty’ 1 (E’1): h{f () ≃?∅ f (t, t1 , . . . , tn )}; σi =⇒ ⊥ if t ∈ / VSeq . Empty’ 2 (E’2): h{f (s, s1 , . . . , sn ) ≃?∅ f ()}; σi =⇒ ⊥ if s ∈ / VSeq . Sequence Variable Occurrence Check’ (SVOC’): h{f (x) ≃?∅ f (t, t1 , . . . , tm )}; σi =⇒ ⊥ if x 6= t and x ∈ SVar(t, t1 , . . . , tm ). 39
Sequence Variable Deletion 1 (SVD1): h{f (x) ≃?∅ f ()}; σi =⇒ h∅; σϑi where ϑ = {x 7→ pq}. Sequence Variable Deletion 2 (SVD2): h{f () ≃?∅ f (x)}; σi =⇒ h∅; σϑi where ϑ = {x 7→ pq}. Sequence Variable Elimination’ (SVE’): h{f (x) ≃?∅ f (t, t1 , . . . , tm )}; σi =⇒ h∅; σϑi / SVar(t, t1 , . . . , tm ) and ϑ = {x 7→ pt, t1 , . . . , tm q}. if x ∈ Remark 3. Note that every rule in U ′ is deterministic, i.e., for each system hΓ ; σi, where Γ 6= ∅, there is only one rule in U ′ that can be applied on hΓ ; σi. No rules can be applied on ⊥ and h∅; σi. First, we show that every sequence of transformations in U ′ terminates. Lemma 12. Let Γ be a unification problem such that all sequence variables occur in the last argument positions in subterms of Γ . Then every sequence of transformations in U ′ hΓ ; εi =⇒ hΓ1 ; σ1 i =⇒ hΓ2 ; σ2 i =⇒ · · · terminates either with ⊥ or h∅; σi for some σ. Proof. For each system h∆; σi, we define a complexity measure as a tuple of natural numbers hn1 , n2 , n3 , n4 , n5 , n6 i, where n1 = The number of distinct variables in ∆; n2 = The number of symbols in ∆; n3 = The number of occurrences of sequence function symbols in ∆; n4 = The number of subterms in ∆ of the form f (s1 , . . . , sn ), where s1 is not a sequence term; n5 = The number of equations in ∆ of the form t ≃?∅ x, where t is not an individual variable; n6 = The number of equations in ∆ of the form f (s1 , . . . , sn ) ≃?∅ f (x), where n, m ≥ 0 and s is not a sequence variable. The complexity measures are ordered by the well-founded lexicographic ordering on natural numbers. Now we prove that every rule in U ′ reduces the complexity measure of systems. For the rules in U ′ that belong also to U it was shown in the proof of Lemma 4. As for the other rules, Empty’ 1 and 2 and Sequence variable occurrence check’ do not increase n1 and reduce n2 , Sequence Variable Deletion’ 1 and 2 and Sequence Variable Elimination’ reduce n1 . 40
A rule in U ′ can always be applied to a system different from ⊥ and h∅; σi for any σ. Thus the sequence of transformations terminates either with ⊥ or with h∅; σi for some σ. ⊓ ⊔ The first major result about U ′ shows that it does indeed produce a unifier. Theorem 15 (Soundness of U ′ ). Let Γ be a general syntactic sequence unification problem where sequence variables occur only in the last argument positions. Then if hΓ ; εi =⇒+ h∅; ϑi, then ϑ ∈ U∅ (Γ ). Proof. The theorem can be proved in the similar way as the soundness result for the inference system U. The counterparts of the lemmata 1 and 2, for U ′ , needed for this proof, can be established easily. ⊓ ⊔ Another major result shows that U ′ can calculate a most general unifier for a unifiable general syntactic unification problem with sequence variables in the last argument positions in subterms. Theorem 16 (Completeness of U ′ ). Let Γ be a general syntactic sequence unification problem where sequence variables occur only in the last argument positions and ϑ be a unifier of Γ . Then any maximal sequence of transformations X ,Q in U ′ hΓ ; εi =⇒ · · · must end in some system h∅; σi such that σ≤ ∅ ϑ, where X = SVar(Γ ) and Q = SFun(Γ ). Proof. By Remark 3, for each system there exists only one maximal derivation starting from the system. We first construct such a maximal derivation hΓ0 ; σ0 i =⇒ hΓ1 ; σ1 i =⇒ · · · X ,Q
with Γ0 = Γ , σ0 = ε and show that σi ≤ ∅ ϑ for all i ≥ 0. We construct the derivation recursively starting from hΓ0 ; σ0 i. Obviously, X ,Q σ0 = ε≤ ∅ ϑ. Now, assume hΓn ; σn i, n ≥ 0 belongs to the derivation and show that for X ,Q the system hΓn+1 ; σn+1 i that extends the derivation we have σn+1 ≤ ∅ ϑ. X ,Q Since hΓn ; σn i belongs to the derivation, we have σn ≤ ∅ ϑ, i.e., there exists X ,Q ϕ such that σn ϕ =∅ ϑ. Thus, we have σn ϕ ∈ U∅ (Γ0 ) and, therefore, ϕ ∈ U∅ (Γ0 σn ). Moreover, since the counterpart of Lemma 2 holds for U ′ , we can show that U∅ (Γ0 σn ) = U∅ (Γn ), which implies ϕ ∈ U∅ (Γn ). Without loss of generality, pick an arbitrary equation s ≃?∅ t from Γn and represent Γn as {s ≃?∅ t} ∪ Γn′ . The pair hs, ti can have one of the following four forms: 1. 2. 3. 4.
A A A A
pair pair pair pair
of of of of
identical terms; distinct individual variables; an individual variable and a non-variable term; distinct non-variable terms. 41
The first three cases can be proved in the same way as the corresponding cases in Lemma 4. We consider the fourth one. Let s = f (s1 , . . . , sk ) and t = f (t1 , . . . , tm ) be distinct non-variable terms with the same heads (The case when the heads are different leads to the contradiction ϕ ∈ U∅ (Γn ) = ∅.). If none of the arguments of s and t is a sequence term, then k = m (otherwise we get a contradiction) and the derivation can be extended with the Total Decomposition rule, taking σn+1 = σn . If there are sequence terms among the arguments of s and t, we have the following four alternatives: 1. If m = 0, then k = 1 and s1 = x is a sequence variable. Then x 7→ pq ∈ ϕ, because ϕ is a unifier of Γn . Let ψ = {x 7→ pq}. Then ψϕ = ϕ. Thus, X ,Q ,Q σn ψϕ =X ϑ, which implies σn ψ≤ ∅ ϑ. Then we extend the derivation ∅ with Sequence Variable Deletion 1 rule with σn+1 = σn ψ. 2. If n = 0, then m = 1 with t1 = x and we proceed as in the previous case, extending the derivation with Sequence Variable Deletion 2 rule. 3. Assume n, m > 0 and neither s1 nor t1 are sequence terms. Then we take σn+1 = σn and extend the derivation with Partial Decomposition 1 rule. 4. Assume again n, m > 0, but now let s1 or t1 be a sequence term. Let first assume that neither s1 nor t1 is a sequence variable. Then they both must be sequence terms with the same head (otherwise we get a contradiction) and we can proceed we Partial Decomposition 2 rule taking again σn+1 = σn . Next, assume only t1 is a sequence variable. Then we perform the Orient 2 step with σn+1 = σn . Now, let s1 be a sequence variable x and t1 be a term different from s1 . Note that x does not occur in t1 , . . . , tm , since otherwise we would get a contradiction. Then xϕ = pt1 ϕ, . . . , tm ϕq. Let ψ = {x 7→ pt1 , . . . , tm q}. X ,Q ,Q Then ψϕ = ϕ. Thus, σn ψϕ =X ϑ, which implies σn ψ≤ ∅ ϑ. Then we ∅ extend the derivation with Sequence Variable Elimination’ rule with σn+1 = σn ψ. Thus, every substitution in the derivation is more general than ϑ. By the construction of the derivation and Lemma 12, the derivation terminates with success and the substitution σ in the last system is more general than ϑ. ⊓ ⊔ The Completeness Theorem shows that U ′ is able to calculate a most general unifier for two unifiable terms. Unification type for this case is unitary, since any unifiable problem has an mgu. 7.2
Equations in Unification Problems Have at Least One Ground Side
In this section we show that the unification procedure terminates if equations in the unification problem have at least one ground side. 42
Theorem 17. Let Γ be a general syntactic unification problem with equations having at least one ground side. Then the unification procedure terminates on hΓ ; εi. Proof. With each system h∆; σi where ∆ contains only the equations with at least one ground side, we associate a complexity measure as a 7-tuple of natural numbers hn1 , n2 , n3 , n4 , n5 , n6 , n7 i, where: n1 = The number of distinct variables in ∆; m2 = The total number of symbols in the ground sides of equations in ∆. m3 = The number of symbols in ∆; m4 = The number of occurrences of sequence function symbols in ∆; m5 = The number of subterms in ∆ of the form f (s1 , . . . , sn ), where s1 is not a sequence term; m6 = The number of equations in ∆ of the form t ≃?∅ x, where t is not an individual variable; m7 = The number of equations in ∆ that have the form f (s, s1 , . . . , sn ) ≃?∅ f (x, t1 , . . . , tm ), where s is not a sequence variable. Measures will be compared lexicographically. Every rule in the inference system U strictly decreases the measure: Indeed, Projection, Sequence Variable Elimination 2, Solve and Splitting rules decrease n1 . Trivial rule does not increase m1 , does not change m2 and decreases m3 . Total Decomposition leaves m1 and m2 unchanged and decreases m3 . Partial Decomposition 1 leaves m1 , m2 , m3 and m4 unchanged and decreases m5 . Partial Decomposition 2 leaves m1 , m2 and m3 unchanged and decreases m4 . Orient 1 decreases m6 and leaves the others unchanged. Orient 2 decreases m7 and leaves the others unchanged. Widening 1 does not change m1 but decreases m2 . Sequence Variable Elimination 1 and Widening 2 never apply. It implies that every branch in ut(Γ ) is finite, i.e., the syntactic unification procedure terminates on Γ . ⊓ ⊔ This theorem has the following corollary: Corollary 2. General syntactic matching with sequence variables and sequence function symbols in finitary. It can be shown that if equations in a unification problem have at least one ground side, then there is no need in full-scale decision procedure. The pre-filter defined in Sect. 6 is sufficient to detect all failing cases.
8
Implementation
We implemented the unification procedure with sequence variables and sequence function symbols in Mathematica [Wol99] on the base of a rule-based programming system ρLog [MK03]. A rule in ρLog is a specification of a nondeterministic and partially defined computation. The system has primitive operators for defining elementary rules and for computing with unions, compositions, 43
reflexive-transitive closures, rewrite rules, and normal forms of rules. With these tools sequence unification procedure with bounded depth, without the decision algorithm, was implemented quite easily. Within the bounded depth, the procedure, by default, uses the depth-first search method with backtracking provided with ρLog. Options allow the user to modify the depth bound, use iterative deepening instead of depth-first method, and stop computation after obtaining a certain number of solutions. The sequence unification package comes with ρLog distribution that can be downloaded from the web: http://www.ricam.oeaw.ac.at/people/page/marin/RhoLog/
9
Related Work
Solving equations involving sequence variables is needed in various fields, like databases, programming, rewriting, artificial intelligence, or theorem proving. In this section we briefly review just some of the methods related to our work. Note that in the literature flexible arity symbols are also called “variadic”, “polyadic”, “variable arity”, “varying-arity”, or “multiple arity” symbols. Sequence variables are part of Common Logic [Gro03] (a language designed for use in the interchange of knowledge among disparate computer systems), its simplified version SCL, a “concrete” instance of Common Logic language, Knowledge Interchange Format KIF [GPH+ 98] and a simplified version of KIF, called SKIF [HM01]. In SKIF sequence variables are called row variables. Hayes and Menzel in [HM01] point out that unification with row variables is very difficult because two expressions can have infinitely many most general unifiers. They also remark that allowing row variables only in the last argument positions guarantee that unification patterns that create the difficulties with infinitely many most general unifiers cannot arise. Unification procedures for these languages are not discussed. Probably the first attempt to design and implement unification with sequence variables (without sequence functions) was made in the system MVL [Gin89]. The implementation of unification was incomplete because of restricted use of widening technique. The restriction was imposed intentionally, for the efficiency reasons. No theoretical study of the unification algorithm of MVL, to the best of our knowledge, was undertaken. Implementation of first-order logic in Isabelle [Pau90] is based on sequent calculus formulated using sequence variables (on the meta level). For example, a basic sequent is one that has a formula in common on the left and right sides. A scheme for basic sequents can be directly represented in Isabelle: ?Γ, ?P, ?Γ ′ ⊢?∆, ?P, ?∆′ where ?Γ, ?Γ ′ , ?∆, ?∆′ are sequence meta-variables and ?P is an individual metavariable. Unifying this scheme with the sequent Q(?a), Q(f (?b)) ⊢ Q(f (1)) produces two unifiers. The first one binds ?P with Q(f (1)), ?a with f (1), ?Γ ′ with Q(f (?b)), and ?Γ , ?∆ and ?∆′ with the empty sequence of formulae. The second 44
one binds ?Γ with Q(?a), ?P with Q(f (1)), ?b with 1, and ?Γ ′ , ?∆ and ?∆′ with the empty sequence of formulae. We are not aware of any formal description the sequence unification algorithm used in Isabelle implementation, but taking into account that in every unification problem no sequence meta-variable occurs more that once, we can conclude that Isabelle sequence unification is finitary. Richardson and Fuchs [RF97] describe another unification algorithm with sequence variables that they call vector variables. Vector variables come with their length attached, that makes unification finitary. Besides, applicative higherorder expressions are allowed. The algorithm was implemented but its properties have never been investigated. Extensions of logic and functional programming, integrated in the RelFun system [Bol99], permit sequence variables in the last argument positions of flexible arity symbols. Unification for such terms is unitary. RelFun allows multiplevalued functions as well. Word equations [AP90,Jaf90] and associative unification [Plo72] can be modelled by syntactic sequence unification without sequence functions using constants, sequence variables and one flexible arity function symbol. In the similar way we can imitate the unification algorithm for path logics closed under right identity and associativity [Sch98]. The Set-Var prover [BF93] of Bledsoe and Feng has a construct called vector of (Skolem) functions that resembles our sequence functions. For instance, a vector of functions denoted g(A, s), where s is a vector of variables, abbreviates a sequence of functions g1 (A, s), . . . , gm (A, s). However, in unification it is not allowed to split vectors of functions between variables: such a vector of functions either entirely unifies with a variable, or with another vector of functions. The programming language of Mathematica uses pattern matching that, among the other kinds of patterns, supports sequence variables (represented in Mathematica as identifiers with ”triple blanks”, e.g., x ) and flexible arity function symbols. The behavior of matching algorithm is explained in examples in the Mathematica book [Wol99]. Our procedure (without sequence function symbols) can imitate this behavior. For a given matching problem, the output of the procedure would be identical to the set of all possible matchers Mathematica matching algorithm computes (One can see all the Mathematica matchers using the function ReplaceList, for instance.). On the other hand, when Mathematica tries to match patterns in the left hand side of its assignments or rules to some expression, it tries first those matchers that assign the shortest sequences of arguments to the first triple blanks that appear in the pattern, and returns the first matcher it finds. We can simulate also this behavior, imposing an order of choosing successors in the Projection rule, applying Sequence Variable Elimination 2 before Widening 1, and stopping the procedure whenever the first solution appears. Widera and Beierle [WB01] extend term rewriting scheme with flexible arity function symbols and three kinds of patterns. Patterns of the form < i . . . > correspond to sequence variables in our notation, while the other two kinds of 45
patterns do not have direct counterparts in our language. Matching for terms involving these constructs is used to perform reduction. “Sequence variables” are involved in the Sequence Datalog approach to develop a finite query language for sequence databases [MB95], But these variables are treated in a different manner than sequence variables in our framework. They behave like variables of type “sequence” and unify only with terms of that type. Constraint logic programming with strings is considered in [Raj94]. The problem of infinitary string unification is solved by deferring full unification and performing partial unification at resolution step. By adapting this technique at each step a set of string equations are generated, which subsumes (possibly infinite) minimal complete sets unifiers. An algorithm for obtaining partially solved forms from any set of string equations is developed. Buchberger introduced sequence functions in Theorema [BDJ+ 00] to Skolemize quantified sequence variables. In the Theorema equational prover [Kut03] we implemented two proving methods: completion without failure [BDP89], extended with sequence variables that occur only in the last argument positions in terms (and, thus, with unary unification), and proving by simplification/rewriting, extended with sequence variables (without any restriction on their occurrence and, thus, with finitary matching). The unification procedure implemented in the prover largely follow the procedure described in this paper. Mathematica pattern matching capabilities are exploited for matching. In [Kut02] we described unification procedures for free, flat, restricted flat and orderless theories with sequence variables, but without sequence functions. The first three procedures have been implemented in ρLog.
10
Conclusion
We proved that general unification in the free theory with sequence variables and sequence functions is decidable and has the infinitary type. We developed a rule-based unification procedure and proved its soundness, completeness and almost minimality. Under certain restrictions sequence unification problems have finitely many solutions: sequence variables in the last argument positions, unification problems with at least one ground side (matching as a particular instance), all sequence variables on the top level with maximum one occurrence. It would be interested to identify more cases with finite or finitely representable solution sets.
11
Acknowledgements
I thank Prof. Bruno Buchberger and Mircea Marin for interesting discussions on the subject.
References [AP90]
H. Abdulrab and J.-P. P´ecuchet. Solving word equations. J. Symbolic Computation, 8(5):499–522, 1990.
46
[BDJ+ 00] B. Buchberger, C. Dupr´e, T. Jebelean, F. Kriftner, K. Nakagawa, D. Vasaru, and W. Windsteiger. The Theorema project: A progress report. In M. Kerber and M. Kohlhase, editors, Proc. of Calculemus’2000 Conference, pages 98–113, St. Andrews, UK, 6–7 August 2000. [BDP89] L. Bachmair, N. Dershowitz, and D. Plaisted. Completion without failure. In H. A¨ıt-Kaci and M. Nivat, editors, Resolution of Equations in Algebraic Structures, volume 2, pages 1–30. Elsevier Science, 1989. [BF93] W. W. Bledsoe and Guohui Feng. SET-VAR. J. Automated Reasoning, 11(3):293–314, 1993. [Bol99] H. Boley. A Tight, Practical Integration of Relations and Functions, volume 1712 of LNAI. Springer Verlag, 1999. [BS91] F. Baader and K. U. Schulz. General A- and AX-unification via optimized combination procedures. In H. Abdulrab and J.-P. P´ecuchet, editors, Proc. of the Second Int. Workshop on Word Equations and Related Topics, IWWERT-91, volume 677 of LNCS, pages 23–42, Rouen, France, 7–9 October 1991. Springer Verlag. [BS96] F. Baader and K. U. Schulz. Unification in the union of disjoint equational theories: Combining decision procedures. J. Symbolic Computation, 21(2):211–244, 1996. [BS01] F. Baader and W. Snyder. Unification theory. In A. Robinson and A. Voronkov, editors, Handbook of Automated Reasoning, volume I, chapter 8, pages 445–532. Elsevier Science, 2001. [Gin89] M. L. Ginsberg. User’s guide to the MVL system. Technical report, Stanford University, Stanford, California, US, 1989. [GPH+ 98] M. R. Genesereth, Ch. Petrie, T. Hinrichs, A. Hondroulis, M. Kassoff, N. Love, and W. Mohsin. Knowledge Interchange Format, draft proposed American National Standard (dpANS). Technical Report NCITS.T2/98004, 1998. http://logic.stanford.edu/kif/dpans.html. [Gro03] Common Logic Working Group. Common logic: Abstract syntax and semantics. http://cl.tamu.edu/docs/cl/1.0/cl-1.0.pdf, 2003. [HM01] P. Hayes and C. Menzel. Semantics of knowledge interchange format. http://reliant.teknowledge.com/IJCAI01/HayesMenzel-SKIF-IJCAI2001.pdf, 2001. [Jaf90] J. Jaffar. Minimal and complete word unification. J. ACM, 37(1):47–85, 1990. [Koh94] M. Kohlhase. A mechanization of sorted higher-order logic based on the resolution principle. PhD Thesis. Universit¨ at des Saarlandes. Saarbr¨ ucken, Germany, 1994. [Kut02] T. Kutsia. Solving and proving in equational theories with sequence variables and flexible arity symbols. Technical Report 02-31, RISC, Johannes Kepler University, Linz, Austria, 2002. [Kut03] T. Kutsia. Equational prover of Theorema. In R. Nieuwenhuis, editor, Proc. of the 14th Int. Conference on Rewriting Techniques and Applications, RTA’03, volume 2706 of LNCS, pages 367–379, Valencia, Spain, 9–11 June 2003. Springer Verlag. [MB95] G. Mecca and A. J. Bonner. Sequences, Datalog and transducers. In Proc. of the 14th ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems, pages 23–35, San Jose, California, US, 22–25 May 1995. [MK03] M. Marin and T. Kutsia. On the implementation of a rule-based programming system and some of its applications. In B. Konev and R. Schmidt,
47
[Pau90] [Plo72]
[Raj94]
[RF97]
[Sch98]
[WB01]
[Wol99]
editors, Proc. of the 4th Int. Workshop on the Implementation of Logics (WIL’03), pages 55–68, Almaty, Kazakhstan, 2003. L. Paulson. Isabelle: the next 700 theorem provers. In P. Odifreddi, editor, Logic and Computer Science, pages 361–386. Academic Press, 1990. G. Plotkin. Building in equational theories. In B. Meltzer and D. Michie, editors, Machine Intelligence, volume 7, pages 73–90, Edinburgh, UK, 1972. Edinburgh University Press. A. Rajasekar. Applications in constraint logic programming with strings. In A. Borning, editor, Proc. of the Second Int. Workshop on Principles and Practice of Constraint Programming, PPCP’95, volume 874 of LNCS, pages 109–122, Rosario, Orcas Island, Washington, US, 2–4 May 1994. Springer Verlag. J. Richardson and N. E. Fuchs. Development of correct transformation schemata for prolog programs. In N. E. Fuchs, editor, Proc. of the 7th Int. Workshop on Logic Program Synthesis and Transformation, LOPSTR’97, volume 1463 of LNCS, pages 263–281, Leuven, Belgium, 10–12 July 1997. Springer Verlag. R. Schmidt. E-Unification for subsystems of S4. In T. Nipkow, editor, Proc. of the 9th Int. Conference on Rewriting Techniques and Applications, RTA’98, volume 1379 of LNCS, pages 106–120, Tsukuba, Japan, 1998. Springer Verlag. M. Widera and C. Beierle. A term rewriting scheme for function symbols with variable arity. Technical Report 280, Praktische Informatik VIII, FernUniversit¨ at Hagen, Germany, 2001. S. Wolfram. The Mathematica Book. Cambridge University Press and Wolfram Research, Inc., fourth edition, 1999.
48
Index
,Q ,9 =X E X ,Q = , 10 E
Arity, 2 Cod, 5 Depth, 2 Dom, 4 FCod, 5 FDom, 5 F ix, 3 F lex, 3 Head, 2 IFun, 3 ILen, 29 IVar, 3 LDif , 29 Proj, 33 Ran, 5 SF un, 3 SVar, 3 Sig, 8 Sol∅ , 24 Sub, 33 T, 2 TInd , 2 TSeq , 2 UT ree∅ , 24 UE , 9 VCod, 5 VDom, 5 Var, 3 U, 20 U ′ , 39 X ,Q ≤ E , 10 X ,Q ≈ , 10 E
≃?E , 8 ≃E , 8 X ,Q E , 10 X