Lazy Narrowing: Strong Completeness and Eager Variable Elimination Aart Middeldorp Satoshi Okui Tetsuo Ida Institute of Information Sciences and Electronics and Center for Tsukuba Advanced Research Alliance University of Tsukuba, Tsukuba 305, Japan
[email protected] Abstract
Narrowing is an important method for solving uni cation problems in equational theories that are presented by con uent term rewriting systems. Because narrowing is a rather complicated operation, several authors studied calculi in which narrowing is replaced by more simple inference rules. This paper is concerned with one such calculus. Contrary to what has been stated in the literature, we show that the calculus lacks strong completeness, so selection functions to cut down the search space are not applicable. We prove completeness of the calculus and we establish an interesting connection between its strong completeness and the completeness of basic narrowing. We also address the eager variable elimination problem. It is known that many redundant derivations can be avoided if the variable elimination rule, one of the inference rules of our calculus, is given precedence over the other inference rules. We prove the completeness of a restricted variant of eager variable elimination in the case of orthogonal term rewriting systems.
1 Introduction E -uni cation|solving equations modulo some equational theory E |is a fun-
damental technique in automated reasoning. Narrowing ([21, 4, 11]) is a general
E -uni cation procedure for equational theories that are presented by con uent
term rewriting systems. Narrowing is the computational mechanism of many functional-logic programming languages (see Hanus [7] for a recent survey on An extended abstract of this paper appeared in the Proceedings of the 20th Colloquium on Trees in Algebra and Programming, Aarhus, Lecture Notes in Computer Science 915, pp. 394{408,1995. This work is partially supported by the Grant-in-Aid for Scienti c Research (C) 06680300 and the Grant-in-Aid for Encouragement of Young Scientists 06780229 of the Ministry of Education, Science and Culture of Japan.
1
the integration of functional and logic programming). It is well-known that narrowing is complete with respect to normalizable solutions. Completeness means that for every solution to a given equation, a more general solution can be found by narrowing. If we extend narrowing to goals consisting of several equations, we obtain strong completeness. This means that we don't lose completeness when we restrict applications of the narrowing rule to a single equation in each goal. Since narrowing is not easily implemented, several authors studied calculi consisting of a small number of more elementary inference rules that simulate narrowing (e.g. [16, 8, 9, 14, 22, 6]). In this paper we are concerned with a subset (actually the specialization to con uent TRSs) of the calculus trans proposed by Holldobler [9]. We call this calculus lazy narrowing calculus (lnc for short). Because the purpose of lnc is to simulate narrowing by more elementary inference rules, it is natural to expect that lnc inherits strong completeness from narrowing, and indeed this is stated by Holldobler (Corollary 7.3.9 in [9]). We show however that lnc lacks strong completeness. An important improvement over narrowing is basic narrowing (Hullot [11]). In basic narrowing narrowing steps are never applied to (sub)terms introduced by previous narrowing substitutions, resulting in a signi cant reduction of the search space. In this paper we establish a surprising connection between lnc and basic narrowing: we show that lnc is strongly complete whenever basic narrowing is complete. The latter is known for complete (i.e., con uent and terminating) TRSs (Hullot [11]). Other sucient conditions are right-linearity and orthogonality (Middeldorp and Hamoen [17]). So lnc is strongly complete for these three classes of TRSs. We prove completeness of lnc for the general case of con uent TRSs. In the literature completeness of lnc-like calculi is proved under the additional termination assumption. Without this assumption the completeness proof is signi cantly more involved. It is known that lnc-like calculi generate many derivations which produce the same solutions (up to subsumption). Martelli [16, 14] and Holldobler [9], among others, pointed out that many of these redundant derivations can be avoided by giving the variable elimination rule, one of the inference rules of lnc-like calculi, precedence over the other inference rules. The problem whether this strategy is complete or not is called the eager variable elimination problem in [9, 22]. Martelli stated in [14] that this is easily shown in the case of terminating (and con uent) TRSs, but Snyder questions the validity of this claim in his monograph [22] on E -uni cation. We address the eager variable elimination problem for non-terminating TRSs. We prove completeness of a slightly restricted version of eager variable elimination in the case of orthogonal TRSs. To this end we simplify and extend the main result of You [23] concerning the completeness of outer narrowing for orthogonal constructor-based TRSs. The remainder of the paper is organized as follows. In a preliminary section we introduce narrowing and basic narrowing, and we state the relevant completeness results. The narrowing calculus that we are interested in|lnc|is de ned in Section 3. In that section we also show that lnc is not strongly complete. In Section 4 we establish the connection between the strong completeness of lnc and the completeness of basic narrowing. We prove the completeness of et al.
et al.
2
lnc for general con uent systems in Section 5. Section 6 is concerned with the
eager variable elimination problem. In the nal section we give suggestions for further research. The appendix contains proofs of a few technical results.
2 Preliminaries In this preliminary section we review the basic notions of term rewriting and narrowing. We refer to Dershowitz and Jouannaud [2] and Klop [12] for extensive surveys. A signature is a set F of function symbols. Associated with every f 2 F is a natural number denoting its arity. Function symbols of arity 0 are called constants. The set T (F ; V ) of terms built from a signature F and a countably in nite set of variables V with F \ V = ? is the smallest set containing V such that f (t1 ; : : : ; tn ) 2 T (F ; V ) whenever f 2 F has arity n and t1 ; : : : ; tn 2 T (F ; V ). We write c instead of c() whenever c is a constant. The set of variables occurring in a term t is denoted by V ar(t). A position is a sequence of natural numbers identifying a subterm in a term. The set P os(t) of positions in a term t is inductively de ned as follows: P os(t) = f"g if t is a variable and P os(t) = f"g [ fip j 1 6 i 6 n and p 2 P os(ti)g if t = f (t1; : : : ; tn). Here ", the root position, denotes the empty sequence. If p 2 P os(t) then tjp denotes the subterm of t at position p and t[s]p denotes the term that is obtained from t by replacing the subterm at position p by the term s. Formally, tjp = t and t[s]p = s if p = " and tjp = tijq and t[s]p = f (t1; : : : ; ti [s]q ; : : : ; tn) if p = iq and t = f (t1; : : : ; tn). The set P os(t) is partitioned into P osV (t) and P osF (t) as follows: P osV (t) = fp 2 P os(t) j tjp 2 Vg and P osF (t) = P os(t)nP osV (t). Elements of P osV (t) are called variable positions. Positions are partially ordered by the pre x order 6, i.e., p 6 q if there exists a (necessarily unique) r such that pr = q. In that case we de ne qnp as the position r. We write p < q if p 6 q and p 6= q. If neither p 6 q nor q 6 p, we write p ? q. The size jtj of a term t is the cardinality of the set P os(t). A substitution is a map from V to T (F ; V ) with the property that the set fx 2 V j (x) 6= xg is nite. This set is called the domain of and denoted by D(). We frequently identify a substitution with the set fx 7! (x) j x 2 D()g of variable bindings. The empty substitution will be denoted by . So = ? by abuse of notation. Substitutions are extended to homomorphisms from T (F ; V ) to T (F ; V ), i.e., (f (t1; : : : ; tn )) = f ((t1); : : : ; (tn )) for every n-ary function symbol f 2 F and terms t1 ; : : : ; tnS2 T (F ; V ). In the following we write t instead of (t). We denote the set x2D() V ar(x) of variables introduced by by I (). The composition 12 of two substitutions 1 and 2 is de ned by x(12 ) = (x1)2 for all x 2 V . A substitution 1 is at least as general as a substitution 2 , denoted by 1 6 2 , if there exists a substitution such that 1 = 2 . The relation 6 is called subsumption. The restriction V of a substitution to a set V ( V ) of variables is de ned as follows: V (x) = (x) if x 2 V and V (x) = x if x 2= V . A variable substitution maps variables to variables. A variable renaming is a bijective variable substitution. It is 3
well-known that the combination of 1 6 2 and 2 6 1 is equivalent to the existence of a variable renaming such that 1 = 2 . We write 1 = 2 [V ] if 1V = 2V . We write 1 6 2 [V ] if there exists a substitution such that 1 = 2 [V ]. A substitution is called idempotent if = . It is easy to show that a substitution is idempotent if and only if D() \ I () = ?. Terms s and t are uni able if there exists a substitution , a so-called uni er of s and t, such that s = t. A most general uni er has the property that 6 0 for every other uni er 0 of s and t. Most general uni ers are unique up to variable renaming. Given two uni able terms s and t, the uni cation algorithms of Robinson [20] and Martelli and Montanari [15] produce an idempotent most general uni er that satis es D() [ I () V ar(s) [ V ar(t). A rewrite rule is a directed equation l ! r that satis es l 2= V and V ar(r) V ar(l). A term rewriting system (TRS for short) is a set of rewrite rules. The rewrite relation !R associated with a TRS R is de ned as follows: s !R t if there exists a rewrite rule l ! r 2 R, a substitution , and a position p 2 P os(s) such that sjp = l and t = s[r]p. The subterm l of s is called a redex and we say that s rewrites to t by contracting redex l. Occasionally we write s !; p; l!r t or s !p; l!r t. The transitive and re exive closure of !R is denoted by !R . If s !R t we say that s rewrites to t. The transitive closure of !R is denoted by !+R . The equational theory induced by R is denoted by $R. We usually omit the subscript R. A term without redexes is called a normal form. We say that a term t has a normal form if there exists a rewrite sequence starting from t that ends in a normal form. A substitution is called normalized (normalizable ) if x is (has) a normal form for every x 2 D(). The routine proofs of the following lemmata are omitted.
Lemma 1 Let , 1, 2 be substitutions and V , V 0 sets of variables such that (V 0 nD()) [ I (V 0 ) V . If 1 6 2 [V ] then 1 6 2 [V 0 ]. Lemma 2 Let 1, 2 be substitutions and V , V 0 sets of variables such that V 0 (V nD(1 )) [I (1V ). If 12V is normalized then 2 V 0 is normalized. A TRS is terminating if it doesn't admit in nite rewrite sequences. A TRS is con uent if for all terms t1 , t2 , t3 with t1 ! t2 and t1 ! t3 there exists a term t4 such that t2 ! t4 and t3 ! t4 . Such a term t4 is called a common reduct of t2 and t3 . Con uence is equivalent to the property that t1 and t2 have a common reduct whenever t1 $ t2 . If l ! r is a rewrite rule and a variable renaming then the rewrite rule l ! r is called a variant of l ! r. A rewrite rule l ! r is left-linear (right-linear ) if l (r) does not contain multiple occurrences of the same variable. A left-linear (right-linear) TRS only contains left-linear (right-linear) rewrite rules. Let l1 ! r1 and l2 ! r2 be variants of rewrite rules of a TRS R such that they have no variables in common. Suppose l1 jp, for some p 2 P osF (l1 ), and l2 are uni able with most general uni er . The pair of terms (l1 [r2 ]p ; r1 ) is called a critical pair of R, except in the case that l1 ! r1 and l2 ! r2 are renamed versions of the same rewrite rule and p = ". A TRS without critical pairs is called non-ambiguous. An orthogonal TRS is left-linear and non-ambiguous. For orthogonal TRSs a considerable amount of 4
theory has been developed, see Klop [12] for a comprehensive survey. The most prominent fact is that orthogonal TRSs are con uent. In Section 6 we make use of the work of Huet and Levy [10] on standardization. We distinguish a nullary function symbol true and a binary function symbol , written in in x notation. A term of the form s t, where neither s nor t contains any occurrences of and true, is called an equation. The term true is also considered as an equation. The extension of a TRS R with the rewrite rule x x ! true is denoted by R+ . Let e = s t be an equation and a substitution. We say that is an (R-)solution of e and we write R ` e if s $R t. So is a solution of e if e belongs to the equational theory generated by R. If R is con uent, R ` e is equivalent to the existence of a rewrite sequence e !R true. We nd it convenient to call a solution of e normalized if the substitution V ar(e) is normalized. Narrowing is formulated as the following inference rule: if there exist a fresh1variant l ! r of a rewrite rule e in R+ , a position p 2 P osF (e), and a most general e[r]p uni er of e and l. +
jp
In the above situation we write e ; p; l!r e[r]p . This is called an nc-step (nc stands for narrowing calculus). Subscripts will be omitted when they are clear from the context or irrelevant. A ( nite) nc-derivation is a sequence
e1
1 ; p1 ; l1 !r1
en en where = 1 n?1 . An nc
n?1 ; pn?1 ; ln?1 !rn?1
of nc-steps and abbreviated to e1 derivation which ends in true is called an nc-refutation. The following completeness result is due to Hullot [11].
Theorem 3 Let R be a con uent TRS and e an equation. For every nor-
malized 2 solution of e there exists an nc-refutation e 0 6 [V ar(e)].
0 true such that
The narrowing calculus that we are interested in (lnc|to be de ned in the next section) operates on sequences of equations, the so-called goals. A substitution is a solution of a goal G = e1 ; : : : ; en , denoted by R ` G, if R ` ei for all i 2 f1; : : : ; ng. We use > as a generic notation for goals containing only equations true. So for con uent TRSs R, R ` G if and only if G !R >. The calculus nc is extended to goals as follows: if there exist a fresh variant l ! r of a rewrite G0; e; G00 rule in R+ , a position p 2 P osF (e), and a most (G0 ; e[r]p ; G00 ) general uni er of ejp and l. +
1 This means that l ! r has no variables in common with the preceding part of the computation. 2 Often completeness is stated with respect to normalizable solutions: if R ` e and V ar(e) is normalizable then there exists an nc-refutation e true such that 0 6R [V ar(e)]. Notwithstanding the fact that completeness with respect to normalized solutions implies completeness with respect to normalizable solutions but not vice-versa, to all intents and purposes normalization and normalizability are interchangeable. 0
5
Notions like nc-step, nc-derivation, and nc-refutation are de ned as in the single equation case. We use the symbol (and its derivatives) to denote nc-derivations over goals. For an nc-derivation : G G0 , denotes the corresponding rewrite sequence G ! G0 . There are three sources of non-determinism in nc: the choice of the equation e, the choice of the subterm ejp, and the choice of the rewrite rule l ! r. The last two choices are don't know non-deterministic, meaning that in general all possible choices have to be considered in order to guarantee completeness. The choice of the equation e is don't care non-deterministic, because of the strong completeness of nc. Strong completeness means completeness independent of selection functions. A selection function is mapping that assigns to every goal G dierent from > an equation e 2 G dierent from true. An example of a selection function is Sleft which always returns the leftmost equation dierent from true. We say that an nc-derivation respects a selection function S if the selected equation in every step G1 G2 of coincides with S (G1 ). Now strong completeness of nc is formulated as follows.
Theorem 4 Let R be a con uent TRS, S a selection function, and G a goal. For every normalized solution of G there exists an nc-refutation G 0 > respecting S such that 0 6 [V ar(G)]. In this paper we make frequent use of the following lifting lemma for nc.
Lemma 5 Let G be a goal and a normalized substitution. For every rewrite sequence G ! G0 there exists an nc-derivation : G 0 G00 such that 0 6 [V ] and 0 subsumes G ! G0. Here V is any nite set of variables such that V ar(G) [ D() V . The statement \0 subsumes G ! G0 " entails that the constructed ncderivation and the given rewrite sequence G ! G0 employ the same rewrite rules at the same positions in the corresponding goals. In the last part of this preliminary section we introduce basic narrowing. Hullot [11] de ned basic narrowing for the single equation case. The extension to goals presented below follows Middeldorp and Hamoen [17].
De nition 6 A position constraint for a goal G is a mapping that assigns to every equation e 2 G a subset of P osF (e). The position constraint that assigns to every e 2 G the set P osF (e) is denoted by G . De nition 7 An nc-derivation G1 ; e ; p ; l !r ? ; e ? ; p ? ; l ? !r ? Gn is based on a position constraint B1 for G1 if pi 2 Bi (ei ) for 1 6 i 6 n ? 1. Here 1
1
1
1
1
n 1
n 1
n 1 n 1
n 1
the position constraints B2 ; : : : ; Bn?1 for the goals G2 ; : : : ; Gn?1 are inductively de ned by 0 0 2 Ginfei g Bi+1 (e) = BB(i(Be ()e ); p ; r ) ifif ee0 = ei[ri ]pi i i i i 6
for all 1 6 i < n ? 1 and e = e0 i 2 Gi+1 , with B(Bi (ei ); pi ; ri ) abbreviating the set of positions Bi(ei )nfq 2 Bi (ei) j q > pig [ fpiq 2 P osF (e) j q 2 P osF (ri)g: An nc-derivation issued from a goal G is called basic if it is based on G . So in a basic derivation narrowing is never applied to a subterm introduced by a previous narrowing substitution. The following statement summarizes the known completeness results for basic narrowing. Part (1) is due to Hullot [11]. Parts (2) and (3) are due to Middeldorp and Hamoen [17].
Theorem 8 Let R be a con uent TRS and G a goal. For every normalized solution of G there exists a basic nc-refutation G 0 > such that 0 6 [V ar(G)], provided one of the following conditions is satis ed: (1) R is terminating, (2) R is orthogonal and G has an R-normal form, or (3) R is right-linear.
3 Lazy Narrowing Calculus Calculi in which the narrowing inference rule is replaced by a small number of more primitive operations are comprehensively examined by Holldobler in his thesis [9] and Snyder in his monograph [22]. The calculus that we investigate in this paper is the specialization of Holldobler's calculus trans, which is de ned for general equational systems and based on paramodulation, to (con uent) TRSs and narrowing.
De nition 9 Let R be a TRS. The lazy narrowing calculus, lnc for short, consists of the following ve inference rules: [o] outermost narrowing G0; f (s1; : : : ; sn) ' t; G00
G0; s1 l1 ; : : : ; sn ln; r t; G00 if there exists a fresh variant f (l1 ; : : : ; ln ) ! r of a rewrite rule in R,
[i] imitation
G0; f (s1; : : : ; sn) ' x; G00 0 (G ; s1 x1 ; : : : ; sn xn ; G00 )
if = fx 7! f (x1 ; : : : ; xn )g with x1 ; : : : ; xn fresh variables, [d] decomposition G0; f (s1; : : : ; sn) f (t1; : : : ; tn); G00 ;
G0; s1 t1; : : : ; sn tn; G00
[v] variable elimination
G0; s ' x; G00 (G0 ; G00 ) if x 2= V ar(s) and = fx 7! sg, 7
[t] removal of trivial equations
G0; x x; G00 : G0; G00 In the rules [o], [i], and [v], s ' t stands for s t or t s. The variable elimination rule [v] is dierent from the one of Martelli [16, 14] in that we don't keep the solved equation x ' t around. The rules [d], [v], and [t] constitute the syntactic uni cation algorithm of Martelli and Montanari [15]. Because syntactic uni cation is performed by [d], [v], and [t], the rewrite rule x x ! true is no longer used in lnc. As a consequence, we et al.
assume that the symbol true doesn't occur in lnc-goals. Contrary to usual narrowing, the outermost narrowing rule [o] generates new parameter-passing equations s1 l1 ; : : : ; sn ln besides the body equation r t. These parameter-passing equations must eventually be solved in order to obtain a refutation, but we don't require that they are solved right away. That is the reason why we call the calculus lazy. We introduce some useful notations relating to the calculus lnc. If G and G1 are the upper and lower goal in the inference rule [] ( 2 fo; i; d; v; tg), we write G )[] G1 . This is called an lnc-step. The applied rewrite rule or substitution may be supplied as subscript, that is, we will write things like G )[o]; l!r G1 and G )[i]; G1 . lnc-derivations are de ned as in the case of nc. To distinguish lnc-derivations from nc-derivations, we use the symbol (and its derivatives) for the former. An lnc-refutation is an lnc-derivation ending in the empty goal . Because the purpose of lnc is to simulate narrowing, it is natural to expect that lnc inherits strong completeness from nc. Indeed, Holldobler [9, Corollary 7.3.9] states the strong completeness of lnc for con uent TRSs with respect to normalizable solutions. However, this does not hold. Counterexample 8 10 Consider the TRS < f (x) ! g(h(x); x) R = : g(x; x) ! a b ! h(b) and the goal G = f (b) a. Con uence of R can be proved by a routine induction argument on the structure of terms and some case analysis. The (normalized) empty substitution is a solution of G because f (b) a !R g(h(b); b) a !R g(h(b); h(b)) a
!R a a
!R
+
true:
Consider the selection function Sright that selects the rightmost equation in every goal. There is essentially only one lnc-derivation issued from G respecting Sright: f (b) a )[o]; f (x)!g(h(x);x) b x; g(h(x); x) a )[o]; g(x ;x )!a b x; h(x) x1; x x1; a a )[d] b x; h(x) x1; x x1 )[v]; fx 7!xg b x; h(x) x )[i]; fx7!h(x )g b h(x2 ); h(x2 ) x2 1
1
1
)[i]; fx 7!h(x )g 2
2
3
8
This is clearly not a refutation. (The alternative binding fx 7! x1 g in the )[v] step results in a variable renaming of the above lnc-derivation.) Hence lnc is not strongly complete. This counterexample doesn't refute the completeness of lnc. The goal f (b) a can be solved, for instance, by adopting the selection function Sleft:
f (b) a )[o]; f (x)!g(h(x);x) )[v]; fx7!bg )[o]; g(x ;x )!a )[v]; fx 7!h(b)g )[o]; b!h(b) )[d] )[d] )[d] 1
1
1
b x; g(h(x); x) a g(h(b); b) a h(b) x1; b x1; a a b h(b); a a h(b) h(b); a a b b; a a aa :
In Section 5 we show that lnc is complete in the general case of con uent TRSs and normalized solutions. In the next section we present sucient conditions for the strong completeness of lnc, which turns out to be simpler than proving completeness.
4 Restoring Strong Completeness Observe that the TRS R of Counterexample 10 satis es none of the sucient conditions for the completeness of basic narrowing stated in Theorem 8. As a matter of fact, basic narrowing is not able to solve the goal f (b) a, see Middeldorp and Hamoen [17]. This suggests a surprising connection between strong completeness of lnc and completeness of basic nc. In this section we prove that lnc is strongly complete whenever basic nc is complete. The basis of our proof is the specialization of the transformation process used by Holldobler in his proof of the (strong) completeness of trans. First we formalize the intuitively clear propagation of equations along nc-derivations.
De nition 11 Let G
G1 be an nc-step and e an equation in G. If e is the selected equation in this step, then e is narrowed into the equation e[r]p in G1 . In this case we say that e[r]p is the descendant of e in G1 . Otherwise, e is simply instantiated to the equation e in G1 and we call e the descendant of e. The notion of descendant extends to nc-derivations in the obvious way. ; p; l!r
Observe that in an nc-refutation G > every equation e 2 G has exactly one descendant true in >. We now introduce six transformation steps on ncrefutations. The rst one states that non-empty nc-refutations are closed under renaming.
Lemma 12 Let be a variable renaming. For every nc-refutation : G there exists an nc-refutation (): G +? >. 1
9
+>
Proof. Let G ; e; p; l!r G1 be the rst step of and let 1 : G1 > be the remainder of . We have 1 2 = . We show the existence of an nc-step G ? ; e; p; l!r G1. First we show that ?1 1 is a most general uni er of ejp and l. We have ejp?1 1 = ejp1 = l1 = l?1 1 , so ?1 1 is a uni er of ejp and l. Let be an arbitrary uni er of ejp and l. Because is a uni er of ejp and l, and 1 is a most general uni er of these two terms, it follows that 1 6 and thus ?1 1 6 . We conclude that ?1 1 is a most general uni er of e jp and l. Write G as G0 ; e; G00 . We obtain G (G0 ; e[r]p ; G00 )?1 1 = (G0 ; e[r]p ; G00 )1 = G1 . Concatenating this nc-step with the nc-refutation 1 yields the desired nc-refutation (): G +? >. 1
1
2
1
1
Observe that Lemma 12 doesn't hold for the empty nc-refutation : > > because ?1 is only equal to if = . In the following ve lemmata denotes an nc-refutation G + > with G = G0; e; G00 such that e = s t is selected in the rst step of and V denotes a nite set of variables that includes all variables in the initial goal G of .
Lemma 13 Suppose narrowing is applied to a descendant of e in at position 1. If l ! r is the applied rewrite rule in the rst such step then there exists an nc-refutation [o] (): G0 ; s l; r t; G00 > such that 1 = [V ]. 1
Proof. Write l = f (l1 ; : : : ; ln ). The given refutation is of the form G G01; f (u1 ; : : : ; un) t0; G001 0 00 0 ; 1; l!r (G1 ; r t ; G1 )2 1
2
3
>
with 1 2 3 = . Let x be a fresh variable (so x 2= V ) and de ne the substitution 2 as the (disjoint) union of 2 and fx 7! l2 g. Because 2 is a most general uni er of f (u1 ; : : : ; un ) l and x x, can be transformed into the refutation [o]():
G0; s l; r t; G00
G01; f (u1; : : : ; un) l; r t0; G001 (G01 ; true; r t0 ; G001 )2 = (G01 ; true; r t0 ; G001 )2 >: Let 1 = 1 2 3 . We have 1 = [ fx 7! l2 3 g and because x 2= V we obtain 1 = [V ]. 1 2 3
The tedious (and boring) proof of the next transformation lemma is omitted. It is similar to the proof of Lemma 5, see e.g. [17].
Lemma 14 Let s = f (s1; : : : ; sn) and t 2 V . If root(t) = f then there exists an nc-refutation [i](): G1 > such that subsumes [i](), = [i]()1 and 1 1 = [V ]. Here 1 = ft 7! f (x1; : : : ; xn )g with x1; : : : ; xn 2= V. Lemma 15 Let s = f (s1; : : : ; sn), t = f (t1; : : : ; tn), and suppose that narrow1
ing is never applied to a descendant of e in at position 1 or 2. There exists an
10
nc-refutation [d] (): G0 ; s1 t1 ; : : : ; sn tn; G00
Proof. The given refutation must be of the form
1
> such that 1 6 [V ].
G01; s0 t0; G001 ; " (G01; true; G001 )2 > with s0 = f (s01 ; : : : ; s0n ), t0 = f (t01 ; : : : ; t0n ), and 1 2 3 = . The rst part of G
1
2
3
can be transformed into 1 :
G0; s1 t1; : : : ; sn tn; G00 G01; s01 t01; : : : ; s0n t0n; G001 : Consider the step from G01 ; s0 t0 ; G001 to (G01 ; true; G001 )2 . Let x x ! true be the employed rewrite rule, so 2 is a most general uni er of x x and s0 t0 . 1
There clearly exists a rewrite sequence (G01 ; s01 t01 ; : : : ; s0n t0n ; G001 )2 !" (G01 ; >; G001 )2 : Lifting3 results in an nc-derivation 2 : G01; s01 t01 ; : : : ; s0n t0n; G001 ; " (G01 ; >; G001 )2 such that 2 6 2 [V [ I (1 )]. We distinguish two cases. (1) Suppose G01 ; G001 = . In this case 3 = . We simply de ne [d] () = 1 ; 2 . Let 1 = 1 2 . From 2 6 2 [V [ I (1 )] we infer, using Lemma 1, that 1 6 1 2 = [V ]. (2) The case G01 ; G001 6= is more involved. First observe that 2 is a uni er of s0 and t0 . Using the fact that 2 is a most general uni er of s0 t0 and x x, it is not dicult to show that 2 6 2 [Vnfxg]. Since x 2= V [I (1 ) we have in particular 2 6 2 [V [ I (1 )]. It follows that there exists a variable renaming such that 2 = 2 [V [I (1)]. Clearly V ar(G01 ; G001 ) V [I (1). The last part of can be trivially transformed (by changing the number of occurrences of true in each goal) into 3 : (G01 ; >; G001 )2 + >. An application of Lemma 12 results in the nc-refutation (3 ): (G01 ; >; G001 )2 +? >. De ne [d]() = 1; 2 ; (3 ). Let 1 = 12 ?1 3. We have 1 = 123 = [V ]. 2
3
1
3
It should be noted that in general we don't have 1 = [V ] in Lemma 15. Consider for example the nc-refutation : a a ; xx!true true where we used the (non-idempotent) most general uni er = fx 7! a; y 7! z; z 7! yg. Decomposition results in the empty goal, so [d] (): produces the empty substitution 1 = . Clearly 1 6= [V ] if V contains y or z .
Lemma 16 Let t 2 V , t 2= V ar(s), and suppose that the rst step of takes
place at the root position. There exists an nc-refutation [v] (): (G0 ; G00 )1 > with 1 = ft 7! sg such that 1 1 6 [V ].
1
The lifting lemma for nc|Lemma 5|requires the normalization of the substitution 2 , which is not necessarily the case here. The reason for requiring normalization is to avoid rewrite sequences in which a term introduced by 2 is rewritten, because such sequences cannot be lifted. In the present situation there is no problem since we know that all steps in the rewrite sequence take place at root positions. 3
11
Proof. The given refutation is of the form
G ; "; xx!true (G0; true; G00)1 > with 1 2 = . Let 1 be the (disjoint) union of fx 7! sg and 1 . Clearly 1 is a uni er of the equations s t and x x. It is not too dicult to show that 1 is a most general uni er of these two equations. Since also 1 is a most general uni er of s t and x x, there exists a variable renaming such that 1 = 1 . If G0 ; G00 = then we let [v] () be the empty nc-refutation and thus 1 = . In this case we have 1 1 = 1 6 1 = [V ]. If G0 ; G00 = 6 , we reason as follows. From the second part of we extract the nc-refutation 1 : (G0 ; G00 )1 + > by simply dropping a single occurrence of true in every goal of . Let 1 = ?1 2. From Lemma 12 we obtain an nc-refutation (1 ): (G0 ; G00)1 + >. Because x 2= V we have 1 1 = 1 1 = 1 ?1 2 = 1 2 = [V ]. Moreover, (G1 ; G2 )1 = (G1 ; G2 )1 . Hence we can de ne [v] () = (1 ). 1
2
2
1
Lemma 17 Let t 2 V , s = t, and suppose that the rst step of takes place at the root position. There exists an nc-refutation [t] (): G0 ; G00 > such that 1 6 [V ]. 1
Proof. The proof is obtained from the previous one by letting 1 be the empty substitution .
The idea now is to repeatedly apply the above transformation steps to a given nc-refutation, connecting the initial goals of (some of) the resulting ncrefutations by lnc-steps, until we reach the empty goal. In order to guarantee termination of this process, we need a well-founded order on nc-refutations that is compatible with the transformation steps. One of the components of our well-founded order is a multiset order. A multiset over a set A is an unordered collection of elements of A in which elements may have multiple occurrences. Every (strict) partial order on A can be extended to a partial order mul on the set of nite multisets over A as follows: M mul N if there exist multisets X and Y such that ? 6= X M , N = (M ? X ) ] Y , and for every y 2 Y there exists an x 2 X such that x y. Here ] denotes multiset sum and ? denotes multiset dierence. Dershowitz and Manna [3] showed that multiset extension preserves well-foundedness.
De nition 18 The complexity jj of an nc-refutation : G
> is de ned as the triple (n; M; s) where n is the number of applications of narrowing in at non-root positions (so the number of narrowing steps that do not use the rewrite rule x x ! true), M is the multiset jMV ar(G)j, and s is the number of occurrences of symbols dierent from and true in G (which is the same as the total number of symbols in G minus the number of equations in G). Here MV ar(G) denotes the multiset of variable occurrences in G, and for any multiset M = ft1 ; : : : ; tn g of terms, M and jM j denote the multiset ft1 ; : : : ; tng and fjt1 j; : : : ; jtnjg, respectively. We de ne a (strict) partial order on nc-refutations as follows: 1 2 if j1 j lex(>; >mul; >) j2j:
12
Here lex(>; >mul; >) denotes the lexicographic product of > (the standard order on N ), >mul, and >.
Lemma 19 The partial order is a well-founded order on nc-refutations.
Proof. Both lexicographic product and multiset extension preserve well-foundedness.
Our complexity measure on nc-refutations is dierent from the one in Holldobler [9, p. 188]. Since we are concerned with one-directional term rewriting and narrowing (as opposed to bi-directional equational reasoning and paramodulation in [9]), our simpler de nition suces. The next lemma states that is compatible with the transformation steps de ned above.
Lemma 20 Let be an nc-refutation and 2 fo; i; d; v; tg. We have
[]() whenever []() is de ned.
Proof. According to the proof of Lemma 13 the number of narrowing steps at non-root positions in the nc-refutation [o] () is one less than in . Hence [o](). Next we consider [i] . By construction, and [i]() have the same number of narrowing steps at non-root positions. Let M1 and M2 be the second components of the triples jj and j[i] ()j. We claim that M1 >mul M2 . Let X be the multiset of all occurrences of the variable t in G, Y = MV ar(G) ? X , and X 0 = MV ar(G1 ) ? Y . Observe that X 0 is the multiset of all occurrences of the variables x1 ; : : : ; xn in G1 . We have M1 = jXj ] jY j and M2 = jX 0 1j ] jY 1j. We have jY j = jY 1j because y1 = y1 1 = y for all y 2 Y . Let t = f (t1 ; : : : ; tn ). We have f (x1 1 ; : : : ; xn 1 ) = t1 1 = t = f (t1 ; : : : ; tn ) and thus jx1 j < jtj for all x 2 X 0 . Therefore jXj >mul jX 0 1 j and hence M1 >mul M2. We conclude that [i](). According to the proof of Lemma 15 the number of narrowing steps at nonroot positions in [d] () is the same as in . Because the substitution produced in [d] () subsumes the substitution produced in for the initial variables, the second component of j[d] ()j doesn't exceed the second component of jj. Since the initial goal of [d] () has less symbols dierent from and true than the initial goal of (viz. two occurrences of the function symbol f ), we conclude that [d] (). From the proof of Lemma 16 we learn that and [v] () have the same number of narrowing steps at non-root positions. Let M1 and M2 be the second components of the triples jj and j[v] ()j. We claim that M1 >mul M2 . We partition MV ar(G0 ; e; G00 ) into the following three multisets: X the multiset of all variables in MV ar(G0 ; G00 ) that belong to D(1 ), Y = MV ar(G0 ; G00 ) ? X , and Z = MV ar(e). Let X 0 be the multiset of all variable occurrences in the initial goal (G0 ; G00 )1 of [v] () that are introduced by 1 , so X 0 ] Y = MV ar((G0 ; G00)1 ). We have M1 = jXj ] jY j ] jZj and M2 = jX 0 1 j ] jY 1j. Since y1 = y1 1 6 y for all y 2 Y , we have jY j >=mul jY 1 j. Using the inequality 1 1 6 [X ], it is not dicult to see that jXj >=mul jX 0 1 j. Since Z 6= ? it follows that M1 >mul M2 and therefore [v](). According to the proof of Lemma 17 the number of narrowing steps at nonroot positions in [t] () is the same in . Because the substitution produced
13
in [t] () subsumes the substitution produced in for the initial variables, the second component of j[t] ()j doesn't exceed the second component of jj. Finally, the initial goal of [t] () has less symbols dierent from and true than the initial goal of (viz. two occurrences of the same variable). Lemma 21 explains why we don't need the symmetric versions of Lemmata 13, 14, and 16.
Lemma 21 For every nc-refutation : G0; s t; G00 > there exists an ncrefutation swap (): G0 ; t s; G00 > with the same complexity. Proof. Simply swap the two sides in every descendant of s t in . This doesn't aect the complexity. The following example illustrates how the above results are used to transform nc-refutations into lnc-refutations.
Example 22 Consider the TRS R = ff (g(y)) ! yg and the nc-refutation : g(f (x)) x fx7!g(y)g g(y) g(y) true. In the variable x is bound to g(y), so the complexity of is (1; f2; 2g; 4). Transformation steps [o], [d], [v] ,
and [t] are not applicable to . Hence we try [i] . This yields the nc-refutation 1 = [i](): g(f (g(x1 ))) g(x1 ) fx 7!yg g(y) g(y) true which has complexity (1; f1; 1g; 6). Next we apply [d] . This gives the nc-refutation 2 = [d](1 ): f (g(x1 )) x1 fx 7!yg y y true with complexity (1; f1; 1g; 4). Observe that the initial goal of is transformed into the initial goal of 2 by a single )[i] -step. In 2 narrowing is applied to the initial equation at position 1. This calls for the transformation step [o], so 3 = [o] (2 ): f (g(x1 )) f (g(y)); y x1 fx 7!yg true; y y >. nc-refutation 3 has complexity (0; f1; 1; 1; 1g; 8). If we apply [d] to 3 , we obtain the nc-refutation 4 = [d](3 ): g(x1 ) g(y); y x1 fx 7!yg true; y y > with complexity (0; f1; 1; 1; 1g; 6). The initial goals of 2 and 4 are connected by an )[o]-step. In the rst step of 4 narrowing is applied at the root position of the selected equation g(x1 ) g(y), so the terms g(x1 ) and g(y) are uni able. A most general uni er is obtained by an application of )[d] followed by an application of )[v] . So rst we use [d] , yielding the nc-refutation 5 = [d] (4 ): x1 y; y x1 fx 7!yg true; y y > with complexity (0; f1; 1; 1; 1g; 4). Next we use [v] , yielding the nc-refutation 6 = [v] (5 ): y y true with complexity (0; f1; 1g; 2). The initial goals of 4 , 5 , and 6 are connected by the lnc-derivation g(x1 ) g(y); y x1 )[d] x1 y; y x1 )[v]; fx 7!yg y y. An application of [t] results in the empty nc-refutation 7 = [t] (6 ): which has complexity (0; ?; 0). Clearly y y )[t] . Concatenating the various lnc-sequences yields an lnc-refutation g(f (x)) x ) whose substitution satis es x = g(y). In Figure 1 this transformation process is summarized. 1
1
1
1
1
1
Unfortunately, the simulation of nc by lnc illustrated above doesn't always work, as shown in the following example.
14
: 2 : 4 : 5 : 6 : 7 :
g(f (x)) x +[i]; fx7!g(x )g f (g(x1 )) x1 +[o] g(x1 ) g(y); y x1 +[d] x1 y; y x1 +[v]; fx 7!yg yy +[t] 1
1
g(y) g(y)
true
yy
true
true; y
y
>
true; y
y
>
true
Figure 1: The transformation in Example 22.
Example 23 Consider the TRS 8 < f (x) ! x R = : a ! b b ! g(b)
and the nc-refutation fail: f (a) g(a) f (a) g(b) a g(b) b g(b) g(b) g(b) true: Because we apply narrowing at position 1 in the descendant f (a) g(b) of the initial equation f (a) g(a), using the rewrite rule f (x) ! x, we transform fail using [o] and [d] . This yields the nc-refutation [d] ([o] (fail )): a x; x g(a) a x; x g(b) true; a g (b) true; b g (b) true; g (b) g (b) >: Observe that the initial goals of fail and [d]([o] (fail )) are connected by an )[o]-step. Since in the refutation [d]([o](fail)) narrowing is applied at position 1 in the descendant a g(b) of the selected equation x g(a) in the initial goal a x; x g(a), we would like to use once more the transformation steps [o] and [d] . This is however impossible since the subterm of x g(a) at position 1 is a variable. The reason why fail cannot be transformed to an lnc-refutation by the transformation steps in this section is that in [d]([o] (fail )) narrowing is applied to a subterm introduced by a previous narrowing substitution. One might be tempted to think that this problem cannot occur if we restrict ourselves to normalized solutions. This is not true, however, because fail computes the empty substitution , which is clearly normalized, but [d] ([o] (fail )) computes the non-normalized solution fx 7! ag. So the transformation steps do not preserve normalization of the computed nc-solutions (restricted to the variables 15
in the initial goal). However, it turns out that basicness (cf. De nition 7) is preserved. This is one of the two key observations for the connection between strong completeness of lnc and completeness of basic nc.
Lemma 24 Let be a basic
nc-refutation and
2 fo; i; d; v; tg. The nc-
refutation [] () is basic whenever it is de ned. Proof (sketch). It is not dicult to see that narrowing is never applied to subterms introduced by previous narrowing substitutions in [o] () and [d] () whenever this is true for . Hence [o]() and [d]() are basic provided that is basic. Since [i]()1 = , [i]() inherits basicness from . Because [v]() and 1 | minus its rst step|are the same modulo renaming, the transformation [v] trivially preserves basicness. This reasoning also applies to [t].
We are now ready for the main lemma, which can be diagrammatically depicted as follows:
8 basic : G 9 1 : + 9 basic 1 : G1
1
>
>
+ 1
such that
(
1 1 6 [V ] 1
Lemma 25 For every non-empty basic nc-refutation : G + > there exist an lnc-step 1 : G ) G1 and a basic nc-refutation 1 : G1 > such that 11 6 [V ], 1, and the equation selected in the rst step of is selected 1
1
in 1 . Proof. We distinguish the following cases, depending on what happens to the selected equation e = s t in the rst step of . Let G = G0 ; e; G00 . (1) Suppose narrowing is never applied to a descendant of s t at position 1 or 2. We distinguish four further cases. (a) Suppose s; t 2= V . We may write s = f (s1 ; : : : ; sn ) and t = f (t1 ; : : : ; tn ). Let G1 = G0; s1 t1 ; : : : ; sn tn ; G00 . We have 1 : G )[d] G1. Lemma 15 yields an nc-refutation [d] (): G1 > such that 1 6 [V ]. Take 1 = . (b) Suppose t 2 V and s = t. In this case the rst step of 1 must take place at the root of e. Let G1 = G0; G00 . We have 1 : G )[t] G1 . Lemma 17 yields an nc-refutation [t] (): G1 > such that 1 6 [V ]. Take 1 = . (c) Suppose t 2 V and s 6= t. We distinguish two further cases, depending on what happens to e in the rst step of . (i) Suppose narrowing is applied to e at the root position. Let 1 = ft 7! sg and G1 = (G0; G00)1 . We have 1: G )[v]; G1. Lemma 16 yields an nc-refutation [v] (): G1 > such that 1 1 6 [V ]. (ii) Suppose narrowing is not applied to e at the root position. This implies that s 2= V . Hence we may write s = f (s1 ; : : : ; sn ). Let 1 = ft 7! f (x1; : : : ; xn )g, G1 = (G0; s1 x1; : : : ; sn xn; G00)1 , and G2 = G1 . Here x1 ; : : : ; xn are fresh variables. We have 1
1
1
1
16
1 : G )[i]; G1 . From Lemma 14 we obtain an nc-refutation 2 = [i](): G2 > such that 1 2 = [V ]. Let V2 = V [ fx1 ; : : : ; xng. Clearly V ar(G2) V2. An application of Lemma 15 to 2 results in an nc-refutation 1 = [d] (2 ): G1 > such that 1 6 2 [V2 ]. Using the inclusion (V n D(1 )) [ I (1 V ) V2 we obtain 1 1 6 1 2 = [V ] from Lemma 1. (d) In the remaining case we have t 2= V and s 2 V . This case reduces to case (1)(c) by an appeal to Lemma 21. (2) Suppose narrowing is applied to a descendant of e at position 1. Let l = f (l1; : : : ; ln ) ! r be the used rewrite rule the rst time this happens. Because is basic, s cannot be a variable, for otherwise narrowing would be applied to a subterm introduced by previous narrowing substitutions. Hence we may write s = f (s1 ; : : : ; sn ). Let G1 = G0; s1 l1 ; : : : ; sn ln; r t; G00 and G2 = G0; s l; r t; G00 . We have 1 : G )[o] G1 . From Lemma 13 we obtain an nc-refutation 2 = [o](): G2 > such that 2 = [V ]. Let V2 = V [ V ar(l). Clearly V ar(G2) V2. An application of Lemma 15 to 2 results in an ncrefutation 1 = [d](2 ): G1 > such that 1 6 2 [V2 ]. Using V V2 we obtain 1 6 [V ]. Take 1 = . (3) Suppose narrowing is applied to a descendant of e at position 2. This case reduces to the previous one by an appeal to Lemma 21. The above case analysis is summarized in Table 1. In all cases we obtain 1 from by applying one or two transformation steps [o] , [i], [d], [v] , [t] together with an additional application of swap in case (1)(d) and (3). According to Lemma 24 1 is basic. According to Lemmata 20 and 21 1 has smaller complexity than . 1
2
1
2
1
case (1)(a) (1)(b) (1)(c)(i) (1)(c)(ii) (1)(d) (2) (3)
lnc-step
)[d] )[t] )[v] )[i] )[v] or )[i] )[o] )[o]
transformation(s)
[d] [t] [v] [d] [i] [v] swap or [d] [i] swap [d] [o] [d] [o] swap
Table 1: Case analysis in the proof of Lemma 25. The other key observation for the connection between strong completeness of lnc and completeness of basic nc is the fact that for basic nc, strong completeness and completeness coincide. This is an easy consequence of the following switching lemma, whose proof can be found in the appendix. Lemma 26 Let G1 be a goal containing distinct equations e1 and e2. For every nc-derivation
G1
1 ; e1 ; p1 ; l1 !r1
G2
2 ; e2 1 ; p2 ; l2 !r2
17
G3
with p2 2 P osF (e2 ) there exists an nc-derivation
G1
H2 ; e ; p ; l !r H3 such that G3 = H3 and 1 2 = 2 1 . 2 ; e2 ; p2 ; l2 !r2
1
1 2
1
1
1
Observe that the requirement p2 2 P osF (e2 ) in Lemma 26 is always satis ed if the two steps are part of a basic narrowing derivation. Moreover, the exchange of the two steps preserves basicness. This is used in the proof below.
Lemma 27 Let S be an arbitrary selection function. For every basic ncrefutation : G > there exists a basic nc-refutation S (): G > respecting S with the same complexity.
Proof. Using the basicness of the given nc-refutation , we can transform into a basic refutation S (): G > that respects S by a nite number of applications of Lemma 26. Since the transformation in Lemma 26 preserves the number of narrowing steps at non-root positions as well as the computed substitution, it follows that the complexities of and S () are the same.
Now we can state and prove the main result of this section.
Theorem 28 Let R be an arbitrary TRS and : G > a basic nc-refutation. For every selection function S there exists an lnc-refutation : G ) respecting S such that 6 [V ar(G)].
Proof. We use well-founded induction on the complexity of the given basic nc-refutation , which is possible because of Lemma 19. In order to make the induction work we prove 6 [V ] for a nite set of variables V that includes V ar(G) instead of 6 [V ar(G)]. The base case is trivial: G must be the empty goal. For the induction step we proceed as follows. First we use Lemma 27 to transform into a basic nc-refutation S (): G + > respecting S with equal complexity. According to Lemma 25 there exist an lnc-step 1 : G ) G1 respecting S and a basic nc-refutation 1 : G1 > such that 1 1 6 [V ] and S () 1 . Let V1 = (V n D(1 )) [ I (1 V ) [ V ar(G1 ). Clearly V1 is a nite set of variables that includes V ar(G1 ). The induction hypothesis yields an lnc-refutation 0 : G1 )0 respecting S such that 0 6 1 [V1 ]. Now de ne = 10 . From 11 6 [V ], 0 6 1 [V1 ], and (V n D(1)) [ I (1V ) V1 , we infer|using Lemma 1|that 6 [V ] and thus also 6 [V ar(G)]. Concatenating the lnc-step 1 and the lnc-refutation 0 yields the desired lnc-refutation . 1
1
A related result for lazy paramodulation calculi is given by Moser [19]. He showed the completeness of his calculus TBP , a re ned version of the calculus T of Gallier and Snyder [5], by a reduction to the basic superposition calculus S of [1]. Strong completeness (of TBP ) follows because TBP satis es the so-called \switching lemma" ([13]). Since from every TBP -refutation one easily extracts a T -refutation respecting the same selection function, strong completeness of T is an immediate consequence. Combining Theorem 28 with Theorem 8 yields the following result. 18
Corollary 29 Let R be a con uent TRS, S a selection function, and G a goal. For every normalized solution of G there exists an lnc-refutation G ) respecting S such that 6 [V ar(G)], provided one of the following conditions is satis ed: (1) R is terminating, (2) R is orthogonal and G has an R-normal form, or (3) R is right-linear.
The converse of Theorem 28 does not hold, as witnessed by the con uent TRS 8 g(x; x) > < f (xa) ! ! b R = > g(a; b) ! : g(b; b) ! cf (a) from Middeldorp and Hamoen [17]. They show that the goal f (a) c cannot be solved by basic narrowing. Straightforward calculations reveal that for any selection function S there exists an lnc-refutation f (a) c ) respecting S.
5 Completeness In this section we show the completeness of lnc for con uent TRSs with respect to normalized solutions. Actually we show a stronger result: all normalized solutions are subsumed by substitutions produced by lnc-refutations that respect Sleft. Basic narrowing is of no help because of its incompleteness [17] for this general case. If we are able to de ne a class of nc-refutations respecting Sleft that (1) includes all nc-refutations respecting Sleft that produce normalized solutions, and (2) which is closed under the transformations [o] , [i] , [d] , [v] , [t] , and swap , then completeness with respect to Sleft follows along the lines of the proof of Theorem 28. We didn't succeed in de ning such a class, the main problem being the fact that an application of [o] or [d] to an nc-refutation that respects Sleft may result in an nc-refutation that doesn't respect Sleft . We found however a class of nc-refutations respecting Sleft that satis es the rst property and which is closed under [o] 1 , [i] , [d] 2 , [v] , [t] , and swap . Here 1 and 2 are transformations that preprocess nc-refutations in such a way that a subsequent application of [o] and [d] results in an nc-refutation respecting Sleft. The following de nition introduces our class of nc-refutations.
De nition 30 An nc-refutation : G > is called normal if it respects Sleft and satis es the following property: if narrowing is applied to the lefthand side (right-hand side) of a descendant of an equation s t in G then 2V ar(s ) (2V ar(t ) ) is normalized. Here 1 and 2 are de ned by writing as G = G0 ; s t; G00 >; (s t; G00 )1 >. 1
1
1
2
19
Before introducing the transformations 1 and 2 we present a switching lemma which is used in the existence proofs. For the proof of this switching lemma we refer to the appendix.
Lemma 31 Let G1 be the goal e; G0 . For every normal nc-refutation G G1 ; p ; l !r G2 ; p ; l !r G3 > with p1 = 6 " and p1 ? p2 there exists a normal nc-refutation G G1 ; p ; l !r H2 ; p ; l !r H3 > 1
1
1
1
1
1
2
2
2
2
2
2
1
1
2
2
1
2
1
2
with the same complexity such that G3 = H3 and 1 1 2 2 = 1 2 1 2 .
Lemma 32 For every normal nc-refutation : e; G
1
e1 ; G1
2 ; 1
e01 ; G1
2 ; 1
e2 ; G12
>
3
with the property that narrowing is not applied to a descendant of e at position 1 in the subderivation that produces substitution 1 , there exists a normal ncrefutation 1 ():
e02 ; G12 > with the same complexity such that 1 2 3 = 1 2 3 and narrowing is neither applied at position 1 nor in the right-hand side of a descendant of e in the subderivation that produces the substitution 1 . Proof. Let 0 be the subderivation e; G e1 ; G1 ; 1 e2 ; G1 2 of . Because respects Sleft all steps in 0 take place in a descendant of e. If there e; G
1
3
1
2
are steps in 0 such that narrowing is applied to the right-hand side of the descendant of e then there must be two consecutive steps in 0 such that the rst one applies narrowing at the right-hand side and the second one at the left-hand side. The order of these two steps can be changed by an appeal to Lemma 31, resulting in a normal nc-refutation that has the same complexity and produces the same substitution as . This process is repeated until there are no more steps before the step in which position 1 is selected that apply narrowing at the right-hand side. Termination of this process is not dicult to see. We de ne 1 () as an outcome of this (non-deterministic) transformation process.
Lemma 33 Let e = f (s1; : : : ; sn) f (t1; : : : ; tn). For every normal ncrefutation : e; G true; G1 > with the property that narrowing is never applied to a descendant of e at position 1 or 2, there exists a normal nc-refutation 2 (): e; G true; G1 > with the same complexity such that in the subderivation producing substitution 1 narrowing is applied to the subterms s1 ; : : : ; sn ; t1 ; : : : ; tn in the order s1 ; t1 ; s2 ; t2 ; : : : ; sn ; tn . Proof. By a similar transformation process as in the proof of the preceding lemma. 1
2
1
2
The next result states that the transformation steps [o] 1 , [i], [d] 2 ,
[v], [t], and swap preserve normality.
20
Lemma 34 Let be a normal nc-refutation. The nc-refutations [o](1 ()), [i](), [d](2 ()), [v](), [t](), and swap () are normal whenever they
are de ned. Proof. First we will show the normality of [o] (1 ()). From Lemma 32 it follows that 1 (), which we can write as s t; G s0 t1; G1 ; 1; l!r (r t1; G1)2 >; is normal. This nc-refutation is transformed by [o] into 2
1
3
s0 l; r t1; G1 ; xx!true true; (r t1 ; G1 )2 = true; (r t1 ; G1 )2 >: Here 2 is the substitution 2 [ fx 7! l2 g. We have to show that the condition of De nition 30 holds for every equation in the initial goal s l; r t; G of the nc-refutation [o](1 ()). Consider the equation s l. By construction [o](1 ()) doesn't contain steps in which narrowing is applied to l. Suppose s l; r t; G
1
2
3
there is a step in which narrowing is applied to the left-hand side of a descendant of s l. (This is equivalent to saying that the derivation from s l to s0 l is non-empty.) We have to show that 1 2 3 V ar(s) is normalized. Because in 1 () narrowing is applied to the left-hand side of a descendant of s t, we obtain the normalization of 1 2 3 V ar(s) from the normality of 1 (). This implies that 1 2 3 V ar(s) is normalized since 1 2 V ar(s) = 1 2 V ar(s) . By construction, the descendants of the equation r t and the equations in G are only selected in the common subrefutation (r t1 ; G1 )2 > of 1 () and [o] (1 ()). We conclude that [o] (1 ()) is normal. Next we consider [i] . Let e = s t be an arbitrary equation in the initial goal of the normal nc-refutation . We may write as G0; e; G00 >; (e; G00 )1 >: By construction, [i]() can be written as 3
1
2
(G0 ; e; G00 )1 >; (e; G00 )1 1 >: Suppose narrowing is applied to the left-hand side of a descendant of e1 in [i](). (If narrowing is applied to the right-hand side of a descendant of e1 in [i](), the desired result follows in exactly the same way.) We have to show that the substitution 2 V ar(s ) is normalized. We know that 2 V ar(s ) is normalized since narrowing is applied to the left-hand side of a descendant of e in the normal nc-refutation . Because 12 = [i]()1 2, the terms s12 and s1 1 2 are equal. Since [i]() subsumes , s1 1 is an instance of s1 and hence the normalization of 2 V ar(s ) is a consequence of the normalization of 2 V ar(s ) . Now consider [d] 2 . According to Lemma 33 the transformation 2 preserves normality. We may write 2 () as 1
2
1 1
1
1 1
1
s t; G
1
G1
2
> 21
and [d] (2 ()) as
s1 t1; : : : ; sn tn; G G1 > with s = f (s1 ; : : : ; sn ), t = f (t1 ; : : : ; tn ), and 1 2 6 1 2 [V ]. By construction [d](2 ()) respects Sleft. Suppose narrowing is applied to the left-hand side of a descendant of si ti in [d] (2 ()), for some 1 6 i 6 n. This implies that narrowing is applied to the left-hand side of a descendant of s t in 2 (). Because narrowing is applied to s t in the rst step of 2 (), it follows from the normality of 2 () that 1 2 V ar(s) is normalized. From 1 2 6 1 2 [V ] we infer the normalization of 1 2 V ar(si ) . The rst part of [d] (2 ()) can be 1
written as
2
1
s1 t1 ; : : : ; s n tn ; G
>; (si ti; : : : ; sn tn; G)1 G12 with 1 2 = 1 . The normalization of 2 2 V ar(si ) |which is what we have to show|follows from the normalization of 1 2 2 V ar(si ) by Lemma 2. Narrowing steps applied to the right-hand side of a descendant of si ti with 1 6 i 6 n in [d](2 ()) are treated similarly. The equations in G don't pose any problems since the subrefutations G1 > and G1 > of 2 () and [d] (2 ()) 2
1
2
2
dier at most a renaming. The transformations [v] and [t] are easily seen to preserve normality. Finally, swap trivially preserves normality.
Example 35 Consider again the nc-refutation fail of Example 23. This refu-
tation is easily seen to be normal. An application of [o] results in the ncrefutation [o] (fail):
f (a) f (x); x g(a)
f (a) f (x); x g(b) true; a g (b) true; b g (b) true; g (b) g (b) > which doesn't respect Sleft . If we rst apply 1 we obtain the nc-refutation 1 (fail): f (a) g(a) a g(a) a g(b) b g(b) g(b) g(b) true: An application of [o] to this normal nc-refutation yields [o] (1 (fail )): f (a) f (x); x g(a) true; a g (a) true; a g (b) true; b g (b) true; g (b) g (b) >: This nc-refutation is normal even though the produced substitution restricted to the variables in the initial goal is not normalized. 22
Now we are ready to prove the counterpart of Lemma 25 for normal ncrefutations: 8 + > > 8 normal : G < 1 1 6 [V ] such that > 1 respects Sleft 9 1 : + : 1 9 normal 1 : G1 > 1
1
Lemma 36 For every non-empty normal nc-refutation : G + > there exist an lnc-step 1 : G ) G1 respecting Sleft and a normal nc-refutation 1 : G1 > such that 1 1 6 [V ] and 1 . 1
1
Proof. The proof is very similar to that of Lemma 25. Since we refer to the proof in the next section, we nevertheless present it in full detail. We distinguish the following cases, depending on what happens to the selected equation e = s t in the rst step of . Let G = e; G0 . (1) Suppose narrowing is never applied to a descendant of e at position 1 or 2. We distinguish four further cases. (a) Suppose s; t 2= V . We may write s = f (s1 ; : : : ; sn ) and t = f (t1 ; : : : ; tn ). Let G1 = s1 t1 ; : : : ; sn tn ; G0 . We have 1 : G )[d] G1 . An application of Lemma 33 followed by Lemma 15 yields an nc-refutation [d](2 ()): G1 > such that 1 6 [V ]. Take 1 = . (b) Suppose t 2 V and s = t. In this case the rst step of 1 must take place at the root of e. Let G1 = G0 . We have 1 : G )[t] G1 . Lemma 17 yields an nc-refutation [t] (): G1 > such that 1 6 [V ]. Take 1 = . (c) Suppose t 2 V and s 6= t. We distinguish two further cases, depending on what happens to e in the rst step of . (i) Suppose narrowing is applied to e at the root position. Let 1 = ft 7! sg and G1 = G01 . We have 1: G )[v]; G1. Lemma 16 yields an nc-refutation [v] (): G1 > such that 1 1 6 [V ]. (ii) Suppose narrowing is not applied to e at the root position. This implies that s 2= V . Hence we may write s = f (s1 ; : : : ; sn ). Let 1 = ft 7! f (x1; : : : ; xn)g, G1 = (s1 x1; : : : ; sn xn; G0)1 , and G2 = G1 . Here x1 ; : : : ; xn are fresh variables. We have 1 : G )[i]; G1 . From Lemma 14 we obtain an nc-refutation 2 = [i](): G2 > such that 1 2 = [V ]. Let V2 = V [ fx1 ; : : : ; xng. Clearly V ar(G2) V2. An application of Lemma 33 to 2 followed by Lemma 15 results in an nc-refutation 1 = [d](2 (2 )): G1 > such that 1 6 2 [V2 ]. Using the inclusion (V n D(1 )) [ I (1 V ) V2 we obtain 1 1 6 1 2 = [V ] from Lemma 1. (d) In the remaining case we have t 2= V and s 2 V . This case reduces to case (1)(c) by an appeal to Lemma 21. (2) Suppose narrowing is applied to a descendant of e at position 1. Let l = f (l1; : : : ; ln ) ! r be the used rewrite rule the rst time this happens. Because is normal, s cannot be a variable. Hence we may write s = f (s1; : : : ; sn). Let G1 = s1 l1 ; : : : ; sn ln; r t; G0 and G2 = s l; r t; G0. We have 1: G )[o] G1. An application of Lemma 32 followed by 1
1
1
1
1
2
1
23
Lemma 13 yields an an nc-refutation 2 = [o](1 ()): G2 > such that 2 = [V ]. Let V2 = V [ V ar(l). Clearly V ar(G2 ) V2. An application of Lemma 33 followed by Lemma 15 to 2 results in an nc-refutation 1 = [d] (2 (2 )): G1 > such that 1 6 2 [V2 ]. Using V V2 we obtain 1 6 [V ]. Take 1 = . (3) Suppose narrowing is applied to a descendant of e at position 2. This case reduces to the previous one by an appeal to Lemma 21. The above case analysis is summarized in Table 2. In all cases we obtain 1 from by applying one or more transformations [o] 1 , [i] , [d] 2 , [v] , [t] together with an additional application of swap in case (1)(d) and (3). According to Lemma 34 1 is normal. According to Lemmata 20, 21, 32, and 33 1 has smaller complexity than . 2
1
case (1)(a) (1)(b) (1)(c)(i) (1)(c)(ii) (1)(d) (2) (3)
lnc-step
)[d] )[t] )[v] )[i] )[v] or )[i] )[o] )[o]
transformation(s)
[d] 2 [t] [v] [d] 2 [i] [v] swap or [d] 2 [i] swap [d] 2 [o] 1 [d] 2 [o] 1 swap
Table 2: Case analysis in the proof of Lemma 36. Lemma 38 below is the counterpart of Lemma 27 for normal nc-refutations. The proof is an easy consequence of the following switching lemma, whose proof can be found in the appendix.
Lemma 37 Let G1 be a goal containing distinct equations e1 and e2. For every nc-refutation G
1
G1
G1
1 ; e1 ; p1 ; l1 !r1
G2
2 ; e2 1 ; p2 ; l2 !r2
with 1 1 2 2 V ar(G) normalized there exists a nc-refutation
G3
2
>
H3 > with the same complexity such that G3 = H3 and 1 1 2 2 = 1 2 1 2 . Lemma 38 For every nc-refutation : G > that produces a normalized substitution there exists a normal nc-refutation normal(): G > with the G
1
2 ; e2 ; p2 ; l2 !r2
H2
1 ; e1 2 ; p1 ; l1 !r1
2
same complexity. Proof. Repeated applications of Lemma 37 results in an nc-refutation normal(): G > that respects Sleft with the same complexity as . Because V ar(G) is normalized, it follows that normal() is normal.
Putting all the pieces together, the following result can be proved along the lines of the proof of Theorem 28. 24
Theorem 39 For every nc-refutation : G
> with the property that V ar(G) is normalized there exists an lnc-refutation : G ) > respecting Sleft such
that 6 [V ar(G)]. Proof. Very similar to the proof of Theorem 28. The only dierence is the use of normal rather than basic nc-refutations, and Lemmata 36 and 38 instead of 25 and 27.
Corollary 40 Let R be a con uent TRS and G a goal. For every normalized solution of G there exists an lnc-refutation G ) respecting Sleft such that 6 [V ar(G)].
6 Eager Variable Elimination lnc has three sources of non-determinism: the choice of the equation in the
given goal, the choice of the inference rule, and the choice of the rewrite rule (in the case of [o]). In Section 4 we were concerned with the rst kind of nondeterminism. In this section we address the second kind of non-determinism. The non-deterministic application of the various inference rules to selected equations causes lnc to generate many redundant derivations. Consider for example the (orthogonal hence con uent) TRS a R = f (g(x))b ! ! g(b) Figure 2 shows all lnc-refutations issued from the goal f (b) a that respect the selection function Sleft . There are in nitely many such refutations. Because the
f (b) a +[o] b g(x); a a +[o] g(b) g(x); a a +[d] b x; a a )[o] g(b) x; a a )[i] b x1; a a )[o] +[v] +[v] +[v] aa aa aa +[d] +[d] +[d] Figure 2: The lnc-refutations starting from f (b) a that respect Sleft . initial goal is ground, one of them suces for completeness. At several places in the literature it is mentioned that this type of redundancy can be greatly reduced by applying the variable elimination rule [v] prior to other applicable inference rules, although to the best of our knowledge there is no supporting 25
proof of this so-called eager variable elimination problem for the general case of con uent systems. In this section we show that a restricted version of the eager variable elimination strategy is complete with respect to Sleft for orthogonal TRSs. Before we can de ne our strategy, we need to extend the concept of descendant to lnc-derivations. Descendants of non-selected equations are de ned as in De nition 11. The selected equation f (s1 ; : : : ; sn ) ' t in the outermost narrowing rule [o] has the body equation r t as only (one-step) descendant. In the imitation rule [i], all equations si xi (1 6 i 6 n) are descendants of the selected equation f (s1 ; : : : ; sn ) ' x. The selected equation f (s1 ; : : : ; sn ) ' f (t1 ; : : : ; tn ) in the decomposition rule [d] has all equations s1 t1 ; : : : ; sn tn as (onestep) descendants. Finally, the selected equations in [v] and [t] have no descendants. Observe that every equation in an lnc-derivation descends from either a parameter-passing equation or an equation in the initial goal.
De nition 41 An equation of the form x ' t, with x 2= V ar(t), is called solved.
An lnc-derivation is called eager if the variable elimination rule [v] is applied to all selected solved equations that are descendants of a parameter-passing equation in . Note that the above concept of eager lnc-derivation doesn't cover the full eager variable elimination problem due to the restriction to descendants of parameter-passing equations that we impose. Of the in nitely many lncrefutations in Figure 2 only the leftmost one is eager since all others apply the outermost narrowing rule [o] to the solved descendant b x of the parameterpassing equation b g(x) introduced in the rst )[o] -step. In this section we prove that eager lnc is complete with respect to Sleft for orthogonal TRSs (with respect to normalized solutions). The outline of our proof is as follows. (1) We de ne outside-in nc-derivations. These are the narrowing counterpart to the outside-in rewrite sequences of Huet and Levy [10]. (2) We show that the completeness of outside-in nc for orthogonal TRSs with respect to normalized solutions is an easy consequence of Huet and Levy's standardization theorem. (3) We show that the translation steps 1 , 2 , [o] , [i], [d] , [v] , [t] , and swap preserve the outside-in property. (4) We verify that the lnc-refutation obtained from an outside-in nc-refutation by means of the transformation described in the previous section is in fact eager.
De nition 42 Let R be an orthogonal TRS. An R+-rewrite sequence e1 !p ; l !r !p ? ; l ? !r ? en is called outside-in if the following condition is satis ed for all 1 6 i < n ? 1: if there exists a j with i < j < n such that " < pj < pi then pi npj 2 P osF (lj ) for 1
1
1
n 1 n 1
n 1
the least such j .
26
In an outside-in sequence every redex contraction pi contributes either directly to the nal result (if there is no j with i < j < n such that " < pj < pi ) or to the creation of a redex at a position " < pj < pi with i < j < n. (The exclusion of " in De nition 42 stems from the fact that the only applicable rewrite rule at that position is not left-linear.) The above de nition is equivalent to the one given by Huet and Levy in their seminal paper [10] on call-by-need computations in orthogonal TRSs. The following result is an immediate consequence of their standardization theorem (Theorem 3.19 in [10]).
Theorem 43 Let R be an orthogonal TRS and e an equation. For every rewrite sequence e !R true there exists an outside-in rewrite sequence e !R true. De nition 44 Let R be an orthogonal TRS. An nc-refutation : G > is called outside-in if for every equation e 2 G the rewrite sequence e ! true in is outside-in. In this case we say also that the rewrite sequence : G ! > +
+
is outside-in.
Example 45 Consider the orthogonal TRS x R = f (xa) ! ! b The nc-refutation : f (a) y; f (y) b
a y; y b true; b b > is outside-in, because the two rewrite sequences f (a) a ! a a ! true and f (a) b ! a b ! b b ! true are outside-in. The nc-refutation 0: f (a) y; f (y) b a y; f (y) b true; f (a) b true; f (b) b true; b b > is not outside-in since the rewrite sequence f (a) b ! f (b) b ! b b ! true
a y; f (y) b true; a b
isn't.
Theorem 46 Let R be an orthogonal TRS and G a goal. For every normalized solution of G there exists an outside-in nc-refutation G 0 > such that 0 6 [V ar(G)]. Proof. Let G = e1 ; : : : ; en . The rewrite sequence G !R > can be partitioned into rewrite sequences from ei to true for 1 6 i 6 n. To each of these n +
rewrite sequences we apply Theorem 43, yielding outside-in rewrite sequences from ei to true (1 6 i 6 n). Putting these n outside-in rewrite sequences together results in a outside-in rewrite sequence from G to >. Let 1 = V ar(G) . Evidently, G1 = G and 1 is normalized. An application of the lifting lemma for nc|Lemma 5|to the outside-in rewrite sequence G1 !R > results in an outside-in nc-refutation G 0 > with 0 6 1 = [V ar(G)]. +
27
The above theorem extends and simpli es the main result of You [23]: the completeness of outer narrowing for orthogonal constructor-based TRSs with respect to constructor-based solutions. One easily veri es that outer narrowing coincides with outside-in narrowing in the case of orthogonal constructor-based TRSs and that constructor-based substitutions are a special case of normalized substitutions. Hence You's completeness result (Theorem 3.13 in [23]) is a consequence of Theorem 46. Since You doesn't use the powerful standardization theorem of Huet and Levy, his completeness proof is (much) more complicated than the proof presented above, which covers a larger class of TRSs.
Lemma 47 The transformations 1, 2, [o], [i], [d], [v] , [t], swap, and normal preserve the outside-in property.
Proof. Straightforward by inspecting the various transformations.
We de ne a property P of equations in the initial goal of nc-refutations in De nition 48. In Lemma 49 we show that parameter-passing equations introduced in the transformation proof of Lemma 36 satisfy this property, provided we start from an nc-refutation that is outside-in. In Lemma 51 the property is shown to be preserved by lnc-descendants obtained during the transformation proof. Finally, in Lemma 52 it is shown that 1 in Lemma 36 consists of a )[v]-step whenever the selected (leftmost) equation in is solved and satis es the property.
De nition 48 Let : G > be an nc-refutation and e 2 G. We say that e has property P in if the following two conditions are satis ed:
(1) narrowing is not applied to the right-hand side of a descendant of e in , and (2) if narrowing is applied to the left-hand side of a descendant of e in and 1p is a narrowing position in a descendant of e such that later steps in the left-hand side of descendants of e do not take place above 1p, then 2p 2 P osF (e). A position 1p satisfying the condition in part (2) will be called critical. In the following three lemmata, 1 and 1 refer to the lnc-step and the
nc-refutation constructed in Lemma 36.
Lemma 49 Let : G + > be a normal outside-in nc-refutation. If 1 consists of an )[o]-step then every parameter-passing equation has property P in
1 . Proof. According to Table 2 we have to consider cases (2) and (3) in the proof of Lemma 36. We consider here only case (2). Consider a parameter-passing equation si li in 1 . The rst part of property P holds by construction. Suppose narrowing is applied to the left-hand side of a descendant of si li in 1 . Let 1p be a critical position. We have to show that 2p 2 P osF (si li ).
28
The nc-refutation 1 () can be written as
e; G0
1 2 ; 1ip 3 4 ; 1; l!r 5
e1; G01 e2; G01 2 e3; G01 23 e4; G01 234 >
where all narrowing steps in the subderivation e2 ; G0 1 2 e3 ; G0 1 2 3 don't take place at positions above 1ip. According to Lemma 47 1 () is outsidein. Hence, by de nition, 1ipn1 2 P osF (l) = P osF (f (l1 ; : : : ; ln )). Therefore p 2 P osF (li ) and thus 2p 2 P osF (si li ). 3
The following example shows the necessity of the outside-in property in Lemma 49.
Example 50 Consider the TRS of Example 45. We have : f (a) b f (b) b bb 1 : +[o] 1 : a x; x b b x; x b true; b b
true
>
The nc-refutation is not outside-in and the parameter-passing equation a x does not satisfy property P in 1 as position 1 is critical while 2 2= P osF (a x). Transforming into the outside-in nc-refutation 0 results in the following diagram: 0 : f (a) b +[o] 01 : 0 1 : a x; x b
ab
bb
true
true; a b
true; b b
>
The parameter-passing equation a x does have property P in 01 .
Lemma 51 Suppose : G + > is a normal nc-refutation and let e 2 G have property P . If e0 is a 1 -descendant of e then e0 has property P in 1 . Proof. First we consider the case that e 2 G is the selected equation in 1 .
Consider the case analysis in the proof of Lemma 36. In cases (1)(b), (1)(c)(i), (1)(d), and (3) there is nothing to show: either e has no 1 -descendants or the rst part of the property P doesn't hold. In case (1)(a) we have 1 = [d](2 ()). It is easy to see that equation e has property P in 2(). We have e0 = si ti for some 1 6 i 6 n. The rst part of property P clearly holds for e0 in 1 . Suppose narrowing is applied to the left-hand side of a descendant of e0 in 1 . Let 1p be a critical position. By construction of [d] , 1ip is a critical position in 2 (). Hence we obtain 2ip 2 P osF (e) from the fact that e has property P in 2 (). This implies 2p 2 P osF (e0 ). We conclude that e0 has property P in 1 . In case (1)(c)(ii) narrowing is applied to the left-hand side s of e in . This implies that there is a critical position 1p. Since the right-hand side t of e is a variable, 2p 2= P osF (e). Therefore the 29
equation e doesn't have the property P . It remains to consider case (2). We have 1 = [d] (2 (2 )) = [d] (2 ([o] (1 ()))). It is not dicult to see that e has property P in 1(). From the construction of [o] we learn that the equation r t in the initial goal G2 of 2 inherits the property P from e in . Since the rewrite sequence (r t)1 ! true in 1 1 subsumes the rewrite sequence (r t)2 ! true in 2 2 , it follows that the (unique) 1 -descendant e0 = r t of e has the property P in 1 . Next suppose that e 2 G is not selected in 1 . By comparing the rewrite sequences e ! true in and e0 1 ! true in 1 1 , one easily concludes that in all cases in the proof of Lemma 36 the (unique) 1 -descendent e0 of e inherits the property P of e.
Lemma 52 Suppose : G
+ > is a normal nc-refutation and
let the selected (leftmost) equation e have the property P . If e is solved then 1 consists of a )[v]-step. Proof. Consider the case analysis in the proof of Lemma 36. In cases (1)(a) and (1)(b) the selected equation e is not solved. In case (1)(c)(i) 1 consists indeed of a )[v] -step. In the proof of Lemma 51 we already observed that in case (1)(c)(ii) the equation e doesn't have the property P . In case (1)(d) either 1 consists of a )[v] -step or e doesn't have the property P , just as in case (1)(c). In case (2), the equation e is not solved or doesn't have property P . The latter follows as in case (1)(c)(ii). Finally, in case (3) the selected equation e doesn't have the property P because narrowing is applied to the right-hand side of a descendant of e.
Theorem 53 For every outside-in nc-refutation G > with V ar(G) normalized there exists an eager lnc-refutation G ) > respecting Sleft such that 6 [V ar(G)]. Proof. Let be the given outside-in nc-refutation G >. From Theorem 39 we obtain an lnc-refutation : G ) > respecting Sleft such that 6 [V ar(G)]. From Lemmata 49{52 we learn that the variable elimination rule [v] is applied to all selected solved descendants of parameter-passing equations in , i.e., is eager.
The combination of Theorems 46 and 53 yields the nal result of this paper.
Corollary 54 Let R be an orthogonal TRS and G a goal. For every normalized solution of G there exists an eager lnc-refutation G ) > respecting Sleft such that 6 [V ar(G)].
7 Suggestions for Further Research This paper leaves many questions unanswered. We mention some of them below. (1) We have seen that lnc lacks strong completeness. This does not mean that all selection functions result in incompleteness. We already showed that lnc is complete (for con uent TRSs and normalized solutions) with respect to Sleft . Extending this to selection functions that never select descendants 30
of a body equation before all descendants of the corresponding parameterpassing equations have been selected shouldn't be too dicult. (2) In Section 4 we have shown the strong completeness of lnc in the case of orthogonal TRSs, using the completeness of basic nc. In Section 6 we showed the completeness of eager lnc with respect to Sleft for orthogonal TRSs, using the completeness of outside-in nc. A natural question is whether these two results can be combined, i.e., is eager lnc strongly complete for orthogonal TRSs. Consider the orthogonal TRS R of Example 45 and the goal f (a) b. There are two dierent nc-refutations starting from this goal: 1 : f (a) b ab bb true and 2 : f (a) b f (b) b bb true: Refutation 1 is not basic and refutation 2 is not outside-in. Hence basic outside-in nc is not complete for orthogonal TRSs. This suggests that it is not obvious whether or not eager lnc is strongly complete for orthogonal TRSs. (3) The orthogonality assumption in our proof of the completeness of eager lnc is essential since we make use of Huet and Levy's standardization theorem. We didn't succeed in nding a non-orthogonal TRS for which eager lnc is not complete. Hence it is an open problem whether our restricted variable elimination strategy is complete for arbitrary con uent TRSs with respect to normalized solutions. A more general question is of course whether the variable elimination rule can always be eagerly applied, i.e., is the restriction to solved descendants of parameter-passing equations essential? (4) In Section 6 we addressed non-determinism between the variable elimination rule on the one hand and the outermost narrowing and imitation rules on the other hand. This is not the only non-determinism between the inference rules. For instance, there are con icts among the outermost narrowing, imitation, and decomposition rules. A question that arises here is whether it is possible to remove all non-determinism between the various inference rules. (This does not prohibit the generation of dierent solutions to a given goal, because the outermost rule is non-deterministic in itself due to the various rewrite rules that may be applied.) The very simple orthogonal constructor-based TRS ff (a) ! f (b)g together with the goal f (x) f (b) show that the restrictions for ensuring the completeness of a truly deterministic subset of lnc have to be very strong. Observe that the solution fx 7! ag can only be produced by outermost narrowing, whereas decomposition is needed for obtaining the unrelated solution fx 7! bg. Recently Middeldorp and Okui [18] showed that all non-determinism in the choice of the inference rule for descendants of parameter-passing equations can be removed for orthogonal constructor-based TRSs, whereas complete determinism in the choice of the inference rule for descendants of equations in the initial goal can be achieved for arbitrary con uent TRSs if we interpret as strict equality, meaning that we only require completeness with respect to solutions of G that have the property that s and t have the 31
same ground constructor normal form, for every equation s t 2 G. (5) The results reported in this paper should be extended to conditional TRSs. Incorporating conditional rewrite rules into lnc is easy: simply add the conditions of the rewrite rule used in the outermost narrowing rule [o] to the resulting goal. Of the three main results in this paper|Theorems 28, 39, and 53|we expect that the rst one can be lifted to conditional TRSs without much diculties, although extra variables in the right-hand sides of the conditional rewrite rules might prove to be a complication. The second result should also hold in the conditional case, but it is less clear whether the proof technique developed in Section 5 can be extended. We do not know whether Theorem 53 holds for conditional TRSs.
Acknowledgement We would like to thank Christopher Lynch and the referees for their helpful remarks.
References [1] L. Bachmair, H. Ganzinger, C. Lynch, and W. Snyder, Basic Paramodulation, Information and Computation 121 (1995) 172{192. [2] N. Dershowitz and J.-P. Jouannaud, Rewrite Systems, in: J. van Leeuwen, ed., Handbook of Theoretical Computer Science, Vol. B (North-Holland, Amsterdam, 1990) 243{320. [3] N. Dershowitz and Z. Manna, Proving Termination with Multiset Orderings, Communications of the ACM 22 (1979) 465{476. [4] M. Fay, First-Order Uni cation in Equational Theories, in: Proceedings 4th Conference on Automated Deduction, (1979) 161{167. [5] J. Gallier and W. Snyder, Complete Sets of Transformations for General E-Uni cation, Theoretical Computer Science 67 (1989) 203{260. [6] M. Hanus, Ecient Implementation of Narrowing and Rewriting, in: Proceedings International Workshop on Processing Declarative Knowledge, Lecture Notes in Arti cial Intelligence, Vol. 567 (Springer, Berlin, 1991) 344{365. [7] M. Hanus, The Integration of Functions into Logic Programming: From Theory to Practice, Journal of Logic Programming 19 & 20 (1994) 583{ 628. [8] S. Holldobler, A Uni cation Algorithm for Con uent Theories, in: Proceedings 14th International Colloquium on Automata, Languages and Programming, Lecture Notes in Computer Science, Vol. 267 (Springer, Berlin, 1987) 31{41. 32
[9] S. Holldobler, Foundations of Equational Logic Programming, Lecture Notes in Arti cial Intelligence, Vol. 353 (Springer, Berlin, 1989). [10] G. Huet and J.-J. Levy, Computations in Orthogonal Rewriting Systems, I and II, in: J.-L. Lassez and G. Plotkin, eds., Computational Logic, Essays in Honor of Alan Robinson, (The MIT Press, 1991) 396{443. [11] J.-M. Hullot, Canonical Forms and Uni cation, in: Proceedings 5th Conference on Automated Deduction, Lecture Notes in Computer Science, Vol. 87 (Springer, Berlin, 1980) 318{334. [12] J.W. Klop, Term Rewriting Systems, in: S. Abramsky, D. Gabbay and T. Maibaum, eds., Handbook of Logic in Computer Science, Vol. II (Oxford University Press, 1992) 1{112. [13] J.W. Lloyd, Foundations of Logic Programming, 2nd edition (Springer, Berlin, 1987). [14] A. Martelli, C. Moiso, and G.F. Rossi, Lazy Uni cation Algorithms for Canonical Rewrite Systems, in: H. At-Kaci and M. Nivat, eds., Resolution of Equations in Algebraic Structures, Vol. II, Rewriting Techniques, (Academic Press, 1989) 245{274. [15] A. Martelli and U. Montanari, An Ecient Uni cation Algorithm, ACM Transactions on Programming Languages and Systems 4 (1982) 258{282. [16] A. Martelli, G.F. Rossi, and C. Moiso, An Algorithm for Uni cation in Equational Theories, in: Proceedings 1986 Symposium on Logic Programming, (1986) 180{186. [17] A. Middeldorp and E. Hamoen, Completeness Results for Basic Narrowing, Applicable Algebra in Engineering, Communication and Computing 5 (1994) 213{253. [18] A. Middeldorp and S. Okui, A Deterministic Lazy Narrowing Calculus, in: Proceedings Fuji International Workshop on Functional and Logic Programming, (World Scienti c, Singapore, 1995) 104{118. [19] M. Moser, Improving Transformation Systems for General E-Uni cation, in: Proceedings 5th International Conference on Rewriting Techniques and Applications, Lecture Notes in Computer Science, Vol. 690 (Springer, Berlin, 1993) 92{105. [20] J.A. Robinson, A Machine-Oriented Logic Based on the Resolution Principle, Journal of the ACM 12 (1965) 23{41. [21] J.R. Slagle, Automatic Theorem Proving in Theories with Simpli ers, Commutativity and Associativity, Journal of the ACM 21 (1974) 622{642. [22] W. Snyder, A Proof Theory for General Uni cation, (Birkhauser, 1991). 33
[23] Y.H. You, Enumerating Outer Narrowing Derivations for Constructor Based Term Rewriting Systems, Journal of Symbolic Computation 7 (1989) 319{343.
Appendix This appendix contains proofs of Lemmata 26, 31, and 37.
Lemma 26. Let G1 be a goal containing distinct equations e1 and e2. For every nc-derivation G1 ; e ; p ; l !r G2 ; e ; p ; l !r G3 with p2 2 P osF (e2 ) there exists an nc-derivation G1 ; e ; p ; l !r H2 ; e ; p ; l !r H3 such that G3 = H3 and 1 2 = 2 1 . Proof. Let G1 = G0 ; e1 ; G00 ; e2 ; G000 . Clearly G3 = ((G0 ; e1 [r1 ]p ; G00 )1 ; e2 1 [r2 ]p ; G000 1 )2 . Since we may assume that the variables in l2 are fresh, we have D(1 ) \V ar(l2 ) = ?. Hence e2 jp 1 2 = e21jp 2 = l2 2 = l212 : So e2 jp and l2 are uni able. Let 2 be an idempotent most general uni er of these two terms. We have H2 = (G0 ; e1 ; G00 ; e2 [r2 ]p ; G000 )2 . There exists a substitution such that 2 = 1 2 . We have D(2 ) V ar(e2 jp ) [ V ar(l2 ). Because we may assume that V ar(l1 ) \V ar(e2 ) = ?, we obtain D(2 ) \V ar(l1 ) = ?. Hence e1 2jp = e1jp 2 = e1jp 12 = l1 12 = l1 2 = l1: So the terms e1 2 jp and l1 are uni able. Let be an idempotent most general uni er. We have 6 . It follows that 2 6 1 2 . Using D(2 ) \ V ar(l1 ) = ? 1
1
1
1
1
2
2
2
2
2
2
2 1
1
1 2
2
1
2
1
2
1
1
2
2
2
2
2
2
1
1
1
1
we obtain
e1 jp 2 = e1 2jp = l1 = l12 ; so 2 is a uni er of e1 jp and l1 . Because 1 is a most general uni er of these two terms, we must have 1 6 2 . Let be any substitution satisfying 1 = 2 . With help of D(1 ) \ V ar(l2 ) = ? we obtain e2 1jp = e2 jp 1 = e2 jp 2 = l2 2 = l2 1 = l2 : (In the rst equality we used the assumption p2 2 P osF (e2 ).) Hence we obtain 2 6 from the fact that 2 is a most general uni er of e2 1jp and l2 . Therefore 12 6 1 = 2 . Since we also have 2 6 12, there is a variable renaming such that 2 = 1 2. Now de ne 1 = . Since most general uni ers are closed under variable renaming, 1 is a most general uni er of e1 2 jp and l1 . So H3 = (G0 2 ; e1 2 [r1 ]p ; (G00 ; e2 [r2 ]p ; G000 )2 )1 . From 1 2 = 2 1 we infer that G3 = H3 . This proves the lemma. 1
1
1
2
2
2
2
1
1
2
34
Lemma 31. Let G1 be the goal e; G0. For every normal nc-refutation G G1 ; p ; l !r G2 ; p ; l !r G3 > with p1 = 6 and p1 ? p2 there exists a normal nc-refutation G G1 ; p ; l !r H2 ; p ; l !r H3 > 1
1
1
1
1
1
2
2
2
2
2
2
1
1
2
1
2
1
2
2
with the same complexity such that G3 = H3 and 1 1 2 2 = 1 2 1 2 . Proof. First we show that p2 2 P osF (e). Suppose to the contrary that p2 2= P osF (e). That means that p2 > q for some q 2 P osV (e). Without loss of generality we assume that q > 1. Let ejq be the variable x. The term e1 jp is a subterm of x1 . Hence e1 jp 2 is a subterm of x1 2 . Because p1 ? p2 we have e1 jp 2 = e[r1 ]p 1 jp 2 = l2 2 . So x1 2 is not a normal form. Hence x122 is also not a normal form. There exists a reduction sequence from e0 1 to e consisting of non-root reduction steps. Here e0 is the leftmost equation in G. Hence x 2 V ar(ej1 ) V ar(e0 1 j1 ). From the normality of we infer that 1 1 2 2 V ar(e0 j ) is normalized. This yields a contradiction with Lemma 2. Therefore p2 2 P osF (e). The remainder of the proof is similar to the proof of Lemma 26. We have G3 = (e[r1 ]p 1[r2 ]p ; G0 1)2. Since the variables in l2 are fresh, we have D(1)\ V ar(l2 ) = ?. Hence 2
2
1
2
2
1
1
2
ejp 12 = e1 jp 2 = l2 2 = l21 2: So 1 2 is a uni er of ejp and l2 . Hence there exists an idempotent most general uni er 2 of ejp and l2 such that 2 6 1 2 . Let be a substitution satisfying 2 = 1 2 . We obtain H2 = (e[r2 ]p ; G0 )2 . Since 2 is idempotent, D(2 ) \ V ar(l1 ) = ?. Hence e2 jp = ejp 2 = ejp 12 = l1 12 = l12 = l1; i.e., is a uni er of e2 jp and l1 . Let be an idempotent most general uni er of these two terms. We have 6 and thus 2 6 2 = 1 2 . Using D(2 ) \ V ar(l1 ) = ? we obtain ejp 2 = e2 jp = l1 = l12 : Since 1 is a most general of ejp and l1 , we have 1 6 2 , so there exists a substitution such that 1 = 2 . Using D(1 ) \ V ar(l2 ) = ? we obtain e1jp = ejp 1 = ejp 2 = l2 2 = l2 1 = l2 : Because 2 is a most general uni er of e1 jp and l2 , we must have 2 6 and hence 1 2 6 1 = 2 . So 1 2 and 2 are variants. Hence there exists a variable renaming such that 2 = 1 2 . Now de ne 1 = . Since is a most general uni er of e2 jp and l1 , and most general uni ers are closed under variable renaming, we infer that also 1 is a most general uni er of these two terms. So H3 = (e[r2 ]p 2 [r1 ]p ; G0 2 )1 . We clearly have 1 2 = 2 1 . With help of p1 ? p2 we infer that G3 = H3 . Because the number of narrowing steps 2
2
2
2
2
1
1
1
1
1
1
1
2
2
2
2
1
2
1
35
at non-root positions is the same in the two nc-refutations, it follows that they have the same complexity. It is also easy to see that normality is preserved.
Lemma 37. Let G1 be a goal containing distinct equations e1 and e2. For every nc-derivation G G1 ; e ; p ; l !r G2 ; e ; p ; l !r G3 > with 1 1 2 2 V ar(G) normalized there exists a nc-refutation G G1 ; e ; p ; l !r H2 ; e ; p ; l !r H3 > with the same complexity such that G3 = H3 and 1 1 2 2 = 1 2 1 2 . Proof. We show that p2 2 P osF (e2 ). Suppose to the contrary that p2 2= P osF (e2 ). That means that p2 > q for some q 2 P osV (e2 ). Without loss of generality we assume that q > 1. Let e2 jq be the variable x. The term e2 1 jp is a subterm of x1 . Hence e2 1 jp 2 is a subterm of x1 2 . Since e2 1 jp 2 = l2 2 , we conclude that x1 2 is not a normal form. Hence x1 2 2 is also not a normal form. There exists a reduction sequence from e1 to e2 for some equation e 2 G consisting of non-root reduction steps. Hence x 2 V ar(e2 j1 ) V ar(e1 j1 ). Now the normalization of 1 1 2 2 V ar(e j ) yields a contradiction with Lemma 2. Hence we have p2 2 P osF (e2 ). Now we apply Lemma 26 to the subderivation G1 G2 G3, resulting in a refutation of the desired shape with 1122 = 12 12. We already observed that the transformation of Lemma 26 doesn't aect the complexity. 1
1
1
1
1
1
1
2
2
2
2
2
2
1
2 1
1 2
2
1
2
1
2
2
1
2
2
2
2
2 1
36