Taro Suzuki. Aart Middeldorp. Tetsuo Ida. Institute of Information Sciences ... {taro,ami,ida}@score.is.tsukuba.ac.jp. ABSTRACT. Level-confluence is an important ...
Level-Confluence of Conditional Rewrite Systems with Extra Variables in Right-Hand Sides Taro Suzuki
Aart Middeldorp
Tetsuo Ida
Institute of Information Sciences and Electronics University of Tsukuba, Tsukuba 305, Japan {taro,ami,ida}@score.is.tsukuba.ac.jp ABSTRACT Level-confluence is an important property of conditional term rewriting systems that allow extra variables in the rewrite rules because it guarantees the completeness of narrowing for such systems. In this paper we present a syntactic condition ensuring level-confluence for orthogonal, not necessarily terminating, conditional term rewriting systems that have extra variables in the right-hand sides of the rewrite rules. To this end we generalize the parallel moves lemma. Our result bears practical significance since the class of systems that fall within its scope can be viewed as a computational model for functional logic programming languages with local definitions, such as let-expressions and where-constructs.
1.
Introduction
There is a growing interest in combining the functional and logic programming paradigms in a single language, see Hanus [12] for a recent overview of the field. The underlying computational mechanism of most of these integrated languages is (conditional) narrowing. Examples of such languages include babel [19] and k-leaf [8]. In order to ensure the desirable completeness of narrowing strategies, restrictions have to be imposed on the programs, which for the purpose of this paper are viewed as conditional term rewriting systems, written in these languages. In this paper we are concerned with the level-confluence restriction, a key property (Giovannetti and Moiso [9], Middeldorp and Hamoen [18]) for ensuring the completeness of narrowing in the presence of so-called extra variables. Very few techniques are available for establishing level-confluence of conditional systems, this in contrast to the confluence property for which several sufficient criteria are known, e.g. [2, 3, 6, 7, 11, 17, 20, 21, 22]. We only know of an early paper by Bergstra and Klop. In [3] they show that orthogonal normal conditional systems are level-confluent. (Actually they show confluence—Giovannetti and Moiso [9] remark that the proof yields level-confluence.) Bergstra and Klop restrict the use of extra variables to the conditional part of the rewrite rules. Several authors remarked that it makes good sense to lift this restriction, since it enables a more natural and efficient way of writing programs in a functional logic language. For example, the Haskell program divide 0
(y+1)
= (0, 0)
A preliminary version of this paper appeared in the Proceedings of the 6th International Conference on Rewriting Techniques and Applications, Kaiserslautern, Lecture Notes in Computer Science 914, pp. 179–193, 1995.
1
divide (x+1) (y+1) | x < y = (0, x+1) | x >= y = (q+1, r) where (q, r) = divide (x - y) (y+1) corresponds to the conditional term rewriting system div (0, S(x)) → (0, 0) div (S(x), S(y)) → (0, S(x)) ⇐ x < y = true div (S(x), S(y)) → (S(q), r) ⇐ x > y = true, div (x − y, S(y)) = (q, r) which has extra variables q and r in the right-hand side of the last rewrite rule. The criterion—orthogonality together with normality—of Bergstra and Klop [3] is no longer sufficient when extra variables are permitted in right-hand sides. For instance, the orthogonal normal system a → x ⇐ f (x) = true f (b) → true f (c) → true from [14] is not confluent, let alone level-confluent, since the term a can be rewritten to the different normal forms b and c. In this paper we present a useful syntactic condition for levelconfluence in the presence of extra variables in right-hand sides of rewrite rules. The remainder of the paper is organized as follows. In the next section we recapitulate the basics of conditional term rewriting. In Section 3 we introduce and motivate our syntactic criterion. In Section 4 we prove that our criterion indeed implies level-confluence. In the next section we extend our result to the larger class of join conditional systems. In Section 6 we relate our result to the recent work of Avenhaus and Lor´ıa-S´ aenz [2] and Hanus [13]. In the final section we discuss further extensions of our result.
2.
Preliminaries
We assume the reader is familiar with term rewriting. (See [5] and [16] for extensive surveys.) In this preliminary section we recall only some less common definitions and introduce the basic facts concerning conditional term rewriting. The set of function symbols F of a term rewriting system (TRS for short) (F, R) is partitioned into disjoint sets FD and FC as follows: a function symbol f belongs to FD if there is a rewrite rule l → r in R such that l = f (t1 , . . . , tn ) for some terms t1 , . . . , tn , otherwise f ∈ FC . Function symbols in FC are called constructors, those in FD defined symbols. A term built from constructors and variables is called a constructor term. A left-linear TRS without critical pairs is called orthogonal. The rules of a conditional TRS (CTRS for short) have the form l → r ⇐ c. Here the conditional part c is a (possibly empty) sequence s1 = t1 , . . . , sn = tn of equations. At present we only require that l is not a variable. A rewrite rule without conditions will be written as l → r. Depending on the interpretation of the equality sign in the conditions of the rewrite rules, different rewrite relations can be associated with a given CTRS. In this paper we are 2
mainly concerned with what we will call oriented CTRSs. The rewrite relation →R associated with an oriented CTRS R is obtained by interpreting the equality signs in the conditional part of a rewrite rule as reachability (→∗ ). Formally, →R is the smallest (w.r.t. inclusion) rewrite relation → with the property that lσ → rσ whenever there exist a rewrite rule l → r ⇐ c in R and a substitution σ such that sσ →∗ tσ for every equation s = t in c. The existence of →R is easily proved. For every oriented CTRS R we inductively define TRSs1 Rn (n > 0) as follows: R0 = ∅, Rn+1 = { lσ → rσ | l → r ⇐ c ∈ R and sσ →∗Rn tσ for all s = t in c }. In the sequel we write Rn ` cσ instead of sσ →∗Rn tσ for every s = t in c. Observe that Rn ⊆ Rn+1 for all n > 0. We have s →R t if and only if s →Rn t for some n > 0. The minimum such n is called the depth of s → t. The depth of a reduction s →∗R t is the minimum n such that s →∗Rn t. The depth of a ‘valley’ s ↓R t is similarly defined. We abbreviate →Rn to →n . The same applies to the derived relations of →Rn . The TRS obtained from a CTRS R by dropping the conditions in rewrite rules is called the underlying TRS of R and denoted by Ru . Concepts like left-linearity and constructor term are defined for CTRSs via the underlying TRS. Let l1 → r1 ⇐ c1 and l2 → r2 ⇐ c2 be renamed versions of rewrite rules of a CTRS R such that they have no variables in common. Suppose (l1 )|p is unifiable with l2 for some non-variable position p in l1 , say with most general unifier σ. The conditional equation l1 [r2 ]p σ = r1 σ ⇐ c1 σ, c2 σ is a conditional critical pair of R, except in the case that the two rules differ a variable renaming and p = ε. A left-linear CTRS without conditional critical pairs is called orthogonal. A normal CTRS R is an oriented CTRS satisfying the additional restriction that every right-hand side of an equation in the conditions of the rewrite rules is a ground Ru -normal form. Following [18], we classify rewrite rules l → r ⇐ c of CTRSs according to the distribution of variables among l, r, and c, as follows: type
requirement
1 2 3 4
Var(r) ∪ Var(c) ⊆ Var(l) Var(r) ⊆ Var(l) Var(r) ⊆ Var(l) ∪ Var(c) no restrictions
An n-CTRS contains only rules of type n. An extra variable x in a rewrite rule l → r ⇐ c satisfies x ∈ (Var(r) ∪ Var(c)) − Var(l). So a 1-CTRS contains no extra variables, a 2-CTRS may only contain extra variables in the conditions, and a 3-CTRS may also have extra variables in the right-hand sides provided these occur in the corresponding conditional part. Most of the literature on conditional term rewriting is concerned with 1 and 2-CTRSs. We are concerned with level-confluence of 3-CTRSs in this paper. An (oriented) CTRS R is called level-confluent if every TRS Rn (n > 0) is confluent. Level-confluence is illustrated in Figure 1. A related property is shallow-confluence. An (oriented) CTRS R is called shallow-confluent if, for all m, n > 0, s →∗m t1 and s →∗n t2 imply the existence of a term t3 such that t1 →∗n t3 and t2 →∗m t3 . A shallow-confluent CTRS is clearly level-confluent, but the reverse does not hold in general. Recently Andreas Werner [23] showed that basic conditional narrowing is complete for 1
If R contains rewrite rules that have extra variables in their right-hand sides, the TRSs Rn may violate the usual restriction Var(r) ⊆ Var(l) imposed on (unconditional) rewrite rules. This doesn’t cause us any concern.
3
· ∗
n
·
· n
∗
·
∀n ∗
n
∗
n
m
·
∗
n
∗
·
∀m,n ∗
n
m
∗
·
·
level-confluence
shallow-confluence Figure 1.
terminating and shallow-confluent 3-CTRSs, but not for all terminating and level-confluent 3CTRSs. We remark here that our syntactic condition for level-confluence actually gives shallowconfluence.
3.
Syntactic Restrictions
In the introduction we saw that 3-CTRSs are not confluent in general, even if they are orthogonal and normal. In this section we present syntactic conditions that ensure (level-)confluence. The first consideration is that we have to severely restrict the many possible terms substituted for extra variables in right-hand sides of the rules. Definition 3.1. An oriented CTRS R is called properly oriented if every rewrite rule l → r ⇐ s1 = t1 , . . . , sn = tn with Var(r) 6⊆ Var(l) in R satisfies the following property: Var(si ) ⊆ Var(l) ∪
i−1 [
Var(tj )
j=1
for all i ∈ {1, . . . , n}. A properly oriented oriented CTRS is simply called a properly oriented CTRS. Clearly every 2-CTRS is properly oriented. For 3-CTRS proper orientedness guarantees that the value of extra variables in the right-hand side is determined by the values of the variables in the left-hand side. So extra variables in a properly oriented CTRS are not really ‘extra’. The following example illustrates this point. Example 3.2. Consider f (x) → h(a, a) → R= h(a, b) → h(b, b) →
the properly oriented 3-CTRS g(x, y, z) ⇐ h(a, x) = i(y), h(a, y) = i(z) i(b) i(c) i(d)
Suppose we rewrite the term f (a) by the first rewrite rule. In this rule y and z are extra variables. The value of y is determined by the condition h(a, x) = i(y) since a is substituted for x and h(a, a) reduces to i(b). So y is bound to b. This determines the value of the extra variable z as h(a, b) reduces to i(c). Hence the term f (a) rewrites only to g(a, b, c). 4
Since we didn’t impose any restrictions on the right-hand side of the conditions so-far, properly oriented orthogonal CTRSs are in general not normal. Bergstra and Klop [3] showed that orthogonal oriented 2-CTRSs are in general not confluent. Hence it is necessary to further restrict the class of properly oriented 3-CTRSs, before we can conclude level-confluence. In order to get a better understanding of such a restriction, we first present a number of counterexamples against the level-confluence of (properly) oriented orthogonal 2-CTRSs. Counterexample 3.3. Our first counterexample is a (properly oriented) orthogonal 1-CTRS: ( a → b R= f (x) → c ⇐ x = a We can rewrite the term f (a) both to f (b) and c. These two reducts are not joinable since they are (different) normal forms. Observe that the right-hand side a of the condition x = a is not a constructor term. Counterexample 3.4. f (x, y) → R= g(x) → c →
Consider the (properly oriented) orthogonal 2-CTRS a ⇐ h(x, y) = h(z, z) f (x, g(x)) g(c)
We have c → g(c) → f (c, g(c)) → f (g(c), g(c)) → a and hence also c → g(c) →∗ g(a). It is not difficult to show that g(a) does not rewrite to a. It follows that a and g(a) do not have a common reduct. Hence R is not confluent. Note that the right-hand side h(z, z) of the condition h(x, y) = h(z, z) is not a linear term. Counterexample 3.4 is a conditional variant of the famous example of Klop [15] showing that left-linearity is essential for confluence in the absence of critical pairs. Counterexample 3.5. Next consider the (properly oriented) orthogonal 2-CTRS ( a → b R= f (x) → c ⇐ a = y, x = y and the term f (a) with the two R1 -reducts f (b) and c. These two terms have a common reduct c, but the step from f (b) to c has depth 2. So R is not level-confluent. Observe how the two right-linear equations a = y and x = y in the conditional part of the second rewrite rule simulate the non-right-linear equation h(a, x) = h(y, y). Counterexample 3.6. Finally, consider the (properly oriented) orthogonal 1-CTRS a → b R= f (x) → c ⇐ a = x This CTRS is obtained from the CTRS R of Counterexample 3.3 by simply swapping both sides of the condition. The term f (a) has the two R1 -reducts f (b) and c. These two terms are not joinable in R1 . Note that the right-hand side of the condition has a variable in common with the left-hand side of the second rewrite rule. 5
Based on the above findings, we introduce the following restriction. Definition 3.7. A CTRS R is called right-stable if every rewrite rule l → r ⇐ s1 = t1 , . . . , sn = tn in R satisfies the following conditions: (Var(l) ∪
i−1 [
Var(sj = tj ) ∪ Var(si )) ∩ Var(ti ) = ∅
j=1
and ti is either a linear constructor term or a ground Ru -normal form, for all i ∈ {1, . . . , n}.
4.
Level-Confluence
In this section we show that orthogonal properly oriented right-stable 3-CTRSs are levelconfluent. It is not difficult to see that every normal 2-CTRS is right-stable. Hence our class of CTRSs properly extends the class of orthogonal normal 2-CTRSs (IIIn systems in the terminology of [3]) of Bergstra and Klop. They showed that orthogonal normal 2-CTRSs satisfy the so-called parallel moves lemma. Hence these systems are confluent. Giovannetti and Moiso [9] observed that the confluence proof in [3] actually reveals level-confluence. Let us briefly recapitulate the result of Bergstra and Klop. Definition 4.1. Let A: s →[ p, l → r⇐c] t be a rewrite step in a CTRS R and let q ∈ Pos(s). The set q\A of descendants of q in t is defined as follows: if q < p or q k p, {q} q\A = { p·p3 ·p2 | r|p3 = l|p1 } if q = p·p1 ·p2 with p1 ∈ PosV (l), ∅ otherwise. S If Q ⊆ Pos(s) then Q\A denotes the set q∈Q q\A. The notion of descendant is extended to rewrite sequences in the obvious way. Definition 4.2. Let R be a CTRS. We write s → k n t if t can be obtained from s by contracting a set of pairwise disjoint redexes in s by Rn . We write s → k t if s → k n t for some n > 0. The minimum such n is called the depth of s → k t. The relation → k is called parallel rewriting. The parallel moves lemma for orthogonal normal 2-CTRSs can now be stated as follows. Lemma 4.3. Let R be an orthogonal normal 2-CTRS. If t → k m t1 and t → k n t2 then there exists a term t3 such that t1 → k n t3 and t2 → k m t3 . Moreover, the redexes contracted in t1 → k n t3 (t2 → k m t3 ) are the descendants in t1 (t2 ) of the redexes contracted in t → k n t2 (t → k m t1 ). Unfortunately, the parallel moves lemma does not hold for our class of 3-CTRSs, as shown in the following example. Example 4.4. Consider the properly oriented right-stable 3-CTRS f (x) → y ⇐ x = y a → b R= b → c and the term f (a). We have f (a) →1 a and f (a) →2 c. From a we can reach the normal form c, but not in a parallel step. 6
In the above example the depth of the non-parallel sequence from a to c is lower than the depth of the step from f (a) to c. This is the key to level-confluence for orthogonal properly oriented right-stable 3-CTRSs. First we introduce a new relation on terms. Definition 4.5. Let R be a CTRS. We write s ,→ k n t if there exists a set P ⊆ Pos(s) of pairwise disjoint positions such that for all p ∈ P either (1) s|p rewrites in a single root reduction step to t|p whose depth does not exceed n, or (2) there exists a rewrite sequence from s|p to t|p whose depth is less than n. Clearly ,→ k 0 is the identity relation and ,→ k 1 coincides with → k 1 . We also have ,→ k n ⊆ →∗n ⊆ ,→ k n+1 for all n > 0. The infinite union ,→ k of the relations ,→ k n (n > 0) is called extended parallel rewriting. The depth of an extended parallel rewrite step s ,→ k t is the smallest n such that s ,→ k n t. In the above example we have a ,→ k 2 c. The following result states that in case of orthogonal properly oriented right-stable 3-CTRSs extended parallel rewriting satisfies the (important) first part of the parallel moves lemma. Theorem 4.6. Let R be an orthogonal properly oriented right-stable 3-CTRS. If t ,→ k m t1 and t ,→ k n t2 then there exists a term t3 such that t1 ,→ k n t3 and t2 ,→ k m t3 . Proof. We use induction on m + n. The case m + n = 0 is trivial. Suppose the result holds for all m and n such that m + n < k for some k > 1 and consider the case m + n = k. Before we proceed, observe that the induction hypothesis implies the validity of the diagrams in Figure 2. If m = 0 then t = t1 and we can take t3 = t2 . The case n = 0 is just as simple. m0 + n0 < k, n0
·
→ k = ,→ k
n0
·
n0
·
·
·
· ∗
m0
m0
m0
∗
m0
∗
m0
∗
m0
∗ ∗
·
· n0
·
· n0
·
· n0
Figure 2. So we may assume that m, n > 0. Let P (Q) be the set of positions justifying (according to Definition 4.5) t ,→ k m t1 (t ,→ k n t2 ). Define a set U of pairwise disjoint positions as follows: U = {p ∈ P | there is no q ∈ Q with q < p} ∪ {q ∈ Q | there is no p ∈ P with p < q}. Since U dominates all positions in P ∪ Q, we have t1 = t[(t1 )|u ]u∈U and t2 = t[(t2 )|u ]u∈U . Hence for every u ∈ U we have extended parallel rewrite steps t|u ,→ k m (t1 )|u and t|u ,→ k n (t2 )|u . If for every u ∈ U we can show the existence of a term tu such that (t1 )|u ,→ k n tu and (t2 )|u ,→ k m tu , then we can take t3 = t[tu ]u∈U since t1 ,→ k n t3 and t2 ,→ k m t3 . Let u ∈ U . Without loss of generality we assume that u ∈ P . Let Pu (Qu ) be the set of positions in t|u contributing to t|u ,→ k m (t1 )|u (t|u ,→ k n (t2 )|u ). We have Pu = {ε} and Qu = {q | u·q ∈ Q} by assumption. Let mu (nu ) be the depth of the extended parallel rewrite step t|u ,→ k (t1 )|u (t|u ,→ k (t2 )|u ). We clearly have mu 6 m and nu 6 n. If mu + nu < k then we obtain a term tu such that (t1 )|u ,→ k nu tu and (t2 )|u ,→ k mu tu from the induction hypothesis. Since mu 6 m and nu 6 n this implies the desired (t1 )|u ,→ k n tu 7
and (t2 )|u ,→ k m tu . So we may assume that mu + nu = k. This implies that mu = m and nu = n. By definition the extended parallel rewrite step t|u ,→ k m (t1 )|u is either a rewrite step of depth m at root position or a rewrite sequence t|u →∗ (t1 )|u whose depth is m − 1. In the latter case we have t|u ,→ k ∗m−1 (t1 )|u . The strengthened induction hypothesis (cf. Figure 2) yields a term tu such that (t1 )|u ,→ k n tu and (t2 )|u ,→ k ∗m−1 tu . Clearly (t2 )|u ,→ k ∗m−1 tu implies (t2 )|u ,→ k m tu . So we may assume that t|u ,→ k m (t1 )|u is a rewrite step of depth m at root position. There exists a rewrite rule l → r ⇐ c and a substitution σ such that t|u = lσ, (t1 )|u = rσ, and Rm−1 ` cσ. Let c be the sequence of conditions s1 = t1 , . . . , sj = tj . For every i ∈ {0, . . . , j} let ci be the subsequence of c consisting of the first i conditions. (So c0 is the empty sequence.) We distinguish two cases. (1) Suppose Qu = {ε}. By definition the extended parallel rewrite step t|u ,→ k n (t2 )|u is either a rewrite step of depth n at root position or a rewrite sequence t|u →∗ (t2 )|u whose depth is n − 1. The latter case follows from the strengthened induction hypothesis, exactly as above. So we may assume that t|u rewrites in a single root Rn -step to (t2 )|u . By orthogonality the employed rewrite rule of R must be l → r ⇐ c. Let τ be a substitution such that t|u = lτ , (t2 )|u = rτ , and Rn−1 ` cτ . If Var(r) ⊆ Var(l) then rσ = rτ and we simply define tu = rσ. If the right-hand side r of the rewrite rule contains extra variables, we reason as follows. By induction on i ∈ {0, . . . , j} we show the existence of a substitution ρi such that (a) ρi = σ = τ [Var(l)], (b) D(ρi ) ⊆ Var(l) ∪ Var(ci ), (c) xσ ,→ k ∗n−1 xρi and xτ ,→ k ∗m−1 xρi for every variable x ∈ Var(l) ∪ Var(ci ). The substitution ρ0 = σVar(l) clearly satisfies the requirements for i = 0. Suppose i > 0 and consider the i-th condition si = ti . Because R is properly oriented we have Var(si ) ⊆ Var(l) ∪ Var(ci−1 ). Using part (c) of the induction hypothesis, we easily obtain si σ ,→ k ∗n−1 si ρi−1 and si τ ,→ k ∗m−1 si ρi−1 . Two applications of the strengthened induction hypothesis (cf. Figure 2) yields a term s0 such that ti σ ,→ k ∗n−1 s0 and ti τ ,→ k ∗m−1 s0 , see Figure 3. From the right-stability of R we learn ti is either a ground Ru -normal form or a linear si σ
si τ
m−1
m−1
n−1 ∗
∗
n−1 ∗
ti σ
∗
si ρi−1 n−1
ti τ
m−1
∗
∗ m−1
·
∗ n−1
→ k = ,→ k
∗
s0 Figure 3. constructor term. In the former case we have ti σ = s0 = ti τ and hence the substitution 8
ρi = ρi−1 satisfies the three requirements. (Note that Var(ci ) = Var(ci−1 ) in this case.) In the latter case there must be a substitution ρ such that s0 = ti ρ with D(ρ) ⊆ Var(ti ). Right-stability yields Var(ti ) ∩ (Var(l) ∪ Var(ci−1 ))) = ∅. As a consequence ρi = ρi−1 ∪ ρ is a well-defined substitution. It is easy to see that ρi satisfies the requirements (a)–(c). This concludes the induction step. Now consider the substitution ρj . Since R is a 3-CTRS we have Var(r) ⊆ Var(l) ∪ Var(cj ). Hence, using property (c), we obtain (t1 )|u = rσ ,→ k ∗n−1 rρj and (t2 )|u = rτ ,→ k ∗m−1 rρj . Since ,→ k ∗n−1 ⊆ ,→ k n and ,→ k ∗m−1 ⊆ ,→ k m , we can define tu = rρj . (2) The second case is Qu 6= {ε}. Using the orthogonality of R we obtain a substitution τ such that (t2 )|u = lτ , D(τ ) ⊆ Var(l), and xσ ,→ k n xτ for every x ∈ Var(l). In this case there is no need to distinguish Var(r) ⊆ Var(l) from Var(r) 6⊆ Var(l). By induction on i ∈ {0, . . . , j} we show the existence of a substitution ρi such that (a) (b) (c) (d)
ρi = τ [Var(l)], D(ρi ) ⊆ Var(l) ∪ Var(ci ), Rm−1 ` ci ρi , and xσ ,→ k n xρi for every variable x ∈ Var(l) ∪ Var(ci ).
If i = 0 then ρ0 = τ Var(l) satisfies the requirements. Suppose i > 0 and consider the i-th condition si = ti . From Rm−1 ` cσ we infer that si σ →∗m−1 ti σ. Hence also si σ ,→ k ∗m−1 ti σ. Let V = Var(si ) − (Var(l) ∪ Var(ci−1 )) and define the substitution ρ as the (disjoint) union of ρi−1 and σV . Using part (d) of the induction hypothesis we learn that si σ ,→ k n si ρ. The strengthened induction hypothesis (cf. Figure 2) yields a term t0 such that si ρ ,→ k ∗m−1 t0 0 and ti σ ,→ k n t . From the right-stability of R we learn that ti is either a ground Ru normal form or a linear constructor term. In the former case we have ti σ = ti = t0 and hence the substitution ρi = ρ satisfies the four requirements. In the latter case there must be a substitution ρ0 such that t0 = ti ρ0 with D(ρ0 ) ⊆ Var(ti ). Right-stability yields Var(ti )∩(Var(l)∪Var(ci−1 )∪Var(si )) = ∅. Hence ρi = ρ∪ρ0 is a well-defined substitution. It is not difficult to check that ρi satisfies the requirements (a)–(d). For instance, we have si ρi = si ρ and ti ρi = ti ρ0 , hence Rm−1 ` (si = ti )ρ0 follows from si ρ ,→ k ∗m−1 ti ρ0 . This concludes the induction step. Now consider the substitution ρj . We have lτ = lρj by property (a) and Rm−1 ` cρj by property (c). Therefore (t2 )|u = lτ →m rρj and thus (t2 )|u ,→ k m rρj . Since R is a 3-CTRS we have Var(r) ⊆ Var(l) ∪ Var(cj ). Hence, using property (d), we obtain (t1 )|u = rσ ,→ k n rρj . Thus rρj is the desired term tu . So for every u ∈ U we could define the desired term tu . This concludes the proof. The main result of this paper is an immediate consequence of the above theorem. Corollary 4.7. Orthogonal properly oriented right-stable 3-CTRSs are level-confluent.
5.
Join Systems
We extend the result of the previous section to join 3-CTRSs. The (only) difference between join and oriented CTRSs is that the equality signs in the conditions of the rewrite rules is interpreted differently: ↓ in the case of join CTRSs and →∗ in the case of oriented CTRSs. In the following we make the explicit notational convention of writing Rj (Ro ) if the CTRS R is considered as a join (oriented) CTRS.
9
For an arbitrary CTRS R, the rewrite relation associated with the oriented CTRS Ro is in general a proper subset of the one associated with the join variant Rj . Consider for example the CTRS ( a → x ⇐ c=x R= b → c We have a →Rj b because c ↓Rj b, but a →Ro b does not hold because c does not rewrite to b (in Ro ). Nevertheless a ↓Ro b holds since a →Ro c and b →Ro c. This relationship (→Rj ⊆ ↓Ro ) holds for all orthogonal properly oriented right-stable 3-CTRSs, as will be shown below. First we prove a special case. Lemma 5.1. Let R be an orthogonal properly oriented right-stable 3-CTRS. If s →Rjn t by application of a rewrite rule l → r ⇐ c with substitution σ such that s0 σ ↓Ron−1 t0 σ for every equation s0 = t0 in c then s ↓Ron t. Proof. Let c be the sequence of conditions s1 = t1 , . . . , sj = tj . For every i ∈ {1, . . . , j} let ci be the subsequence of c consisting of the first i conditions. By induction on i ∈ {0, . . . , j} we show the existence of a substitution τi such that (a) (b) (c) (d)
τi = σ [Var(l)], D(τi ) ⊆ Var(l) ∪ Var(ci ), Ron−1 ` ci τi , and xσ →∗Ro xτi for every variable x ∈ Var(l) ∪ Var(ci ). n−1
The substitution τ = σVar(l) clearly satisfies the requirements for i = 0. Suppose i > 0 and consider the i-th condition si = ti . By assumption si σ and ti σ have a common Ron−1 -reduct, say t0 . Let V = Var(si ) − (Var(l) ∪ Var(ci−1 )) and define the substitution ρ as τi−1 ∪ σV . Using part (d) of the induction hypothesis we obtain an Ron−1 -rewrite sequence from si σ to si ρ. According to Corollary 4.7 Ro is level-confluent. This implies that the Ron−1 -reducts t0 and si ρ of si σ have a common Ron−1 -reduct, say t00 . From the right-stability of R we learn that ti is either a ground Ru -normal form or a linear constructor term. In the former case we have ti σ = ti = t0 = t00 and hence the substitution τi = ρ satisfies the four requirements. In the latter case there must be a substitution ρ0 such that t00 = ti ρ0 with D(ρ0 ) ⊆ Var(ti ). Right-stability yields Var(ti ) ∩ (Var(l) ∪ Var(ci−1 )) = ∅. Hence τi = ρ ∪ ρ0 is a well-defined substitution which is easily seen to be satisfying the requirements (a)–(d). This concludes the induction step. Consider the substitution τj . We have an Ron−1 -rewrite sequence from rσ to rτj as a consequence of property (d). From properties (a) and (c) we learn that lσ = lτj →Ron−1 rτj . Therefore s ↓Ron−1 t. Lemma 5.2. Let R be an orthogonal properly oriented right-stable 3-CTRS. If s →Rjn t then s ↓Ron t. Proof. We use induction on n. If n = 0 then we have nothing to prove, so suppose n > 0. Let l → r ⇐ c be the rewrite rule and σ the substitution used in s →Rjn t. We have Rjn−1 ` cσ. Using Corollary 4.7, we obtain Ron−1 ` cσ from the induction hypothesis by a routine induction argument. Lemma 5.1 yields the desired s ↓Ron t. The main result of this section is an easy consequence of Corollary 4.7 and Lemma 5.2. Corollary 5.3. Orthogonal properly oriented right-stable join 3-CTRSs are level-confluent. 10
6.
Related Work
Bertling and Ganzinger [4] defined the class of quasi-reductive and deterministic 3-CTRSs. Deterministic CTRSs are very similar to properly oriented CTRSs, the difference being that we don’t impose the restrictions (i ∈ {1, . . . , n}) Var(si ) ⊆ Var(l) ∪
i−1 [
Var(sj = tj )
j=1
when the right-hand side r of the rewrite rule l → r ⇐ s1 = t1 , . . . , sn = tn doesn’t contain extra variables. So deterministic CTRSs are a proper subclass of properly oriented CTRS. Quasireductivity is an (undecidable) criterion guaranteeing termination. Bertling and Ganzinger showed that every quasi-reductive deterministic 3-CTRS has a decidable rewrite relation. In a recent paper Avenhaus and Lor´ıa-S´ aenz [2] provide a simple but powerful decidable condition for quasi-reductivity. Moreover, they show that every strongly deterministic and quasireductive 3-CTRS with joinable critical pairs2 is confluent. A strongly deterministic CTRS R is a deterministic one with the additional property that for every right-hand side t of the equations in the conditional parts of the rewrite rules and every normalized substitution σ, the term tσ is a normal form. Observe that both constructor terms and ground Ru -normal forms satisfy this property. Our result remains valid (with the same proof) if we relax the second condition in the definition of right-stability to the requirement that every right-hand side t of the equations in the conditional parts of the rewrite rules is a linear term with the property that tσ is a normal form whenever σ is a normalized substitution. Note though that this is no longer a decidable criterion. Every right-stable deterministic CTRS is strongly deterministic but not vice-versa, e.g., the 3-CTRS of Counterexample 3.4 is strongly deterministic but not rightstable. So the class of strongly deterministic quasi-reductive 3-CTRSs is incomparable with our class of orthogonal properly oriented right-stable 3-CTRSs. The essential difference however is that we do not impose the termination restriction. From a programming point of view, the termination assumption is quite severe. Strongly deterministic quasi-reductive 3-CTRSs with joinable critical pairs are in general not level-confluent. For instance, the 3-CTRS a → b a → c R= b → c ⇐ d=e d → e is clearly strongly deterministic. The reduction order a b c d e can be used to show quasi-reductivity. We have a →1 b and a →1 c, but the step from b to c has depth 2. Observe that R is properly oriented and right-stable. Hence we know that the system cannot be orthogonal, and indeed there is a critical pair between the first two rules. Finally, we would like to mention that the termination assumption makes the task of proving confluence easier. Very recently (and independently) Hanus [13] presented a sufficient condition for the levelconfluence of properly oriented orthogonal 3-CTRSs with strict equality. Strict equality means that a substitution σ satisfies a condition s = t of a rewrite rule only if sσ and tσ reduce to the same ground constructor term. CTRSs with strict equality can be viewed as a special case 2
Overlays obtained from a rewrite rule and (a renamed version of) itself don’t have to be considered.
11
of normal CTRSs. The proof in [13] is however insufficient since it is based on the parallel moves lemma for orthogonal normal 2-CTRSs (Bergstra and Klop [3]), which, as we have seen in Section 4, is not valid for 3-CTRSs. Our proof method can be specialized to complete Hanus’ proof. Actually, Hanus considers almost orthogonal ([1]) CTRSs. These are left-linear systems in which the non-overlapping restriction is relaxed by allowing trivial overlays. Although we only considered orthogonal CTRSs in this paper, our result immediately extends to almost orthogonal systems.
7.
Concluding Remarks
In this final section we discuss some further extensions of our sufficient condition. First of all, Dershowitz et al. [7] and Gramlich [11], among others, distinguish feasible from infeasible critical pairs. A critical pair is infeasible if the instantiated combination of the two conditional parts of the rewrite rules that induce the critical pair is unsolvable. Infeasibility is undecidable in general, but see Gonz´alez–Moreno et al. [10] for a decidable sufficient condition. Infeasible critical pairs are harmless, so orthogonality can be strengthened by allowing infeasible critical pairs. This is important in practice since it permits systems like div (0, S(x)) → (0, 0) div (S(x), S(y)) → (0, S(x)) ⇐ x < y = true div (S(x), S(y)) → (S(q), r) ⇐ x > y = true, div (x − y, S(y)) = (q, r) with disambiguating conditions. Because the condition x < y = true, x > y = true has no solutions, the critical pair between the last two rules is infeasible. The proofs in this paper remain valid if we allow infeasible critical pairs. Secondly, satisfiability of the conditional part of a rewrite rule is independent of the order of its equations. Hence we can relax proper orientedness and right-stability by allowing any permutation of the equations in the conditions to satisfy the requirements in Definitions 3.1 and 3.7. Finally, and more in spirit with the results of this paper, we consider relaxing the proper orientedness restriction. Proper orientedness requires that extra variables in the left-hand side of some equation in the conditional part of some rewrite rule occur in the preceding equations. This requirement is not necessary, however, if the extra variable under consideration does not affect the values of extra variables that occur in the right-hand side of the rewrite rule. This leads us to the following definition. Definition 7.1. In an extended properly oriented CTRS the conditional part c of every rewrite rule l → r ⇐ c with Var(r) 6⊆ Var(l) can be written as s1 = t1 , . . . , sm = tm , s01 = t01 , . . . , s0n = t0n such that the following two conditions are satisfied: Var(si ) ⊆ Var(l) ∪
i−1 [
Var(tj )
j=1
for all i ∈ {1, . . . , m}, and Var(r) ∩
Var(s0i
=
t0i )
⊆ Var(l) ∪
m [
Var(tj )
j=1
for all i ∈ {1, . . . , n}. 12
The proofs in this paper can be adapted to deal with extended properly oriented CTRSs. Hence all orthogonal extended properly oriented right-stable 3-CTRSs are level-confluent. An interesting application is the class of 3-CTRSs with strict equality and so-called local definitions. With respect to Definition 7.1 this means that t0i denotes the constant true or false and s0i the strict equation s01i ≡ s02i , for i ∈ {1, . . . , n}. Here ≡ is a function that tests whether its two arguments denote the same ground constructor term. The local definitions s1 = t1 , . . . , sm = tm support (potentially) infinite data structures. An interesting example is the following Haskell like program: filter n r [] = (-1, []) filter n r (x:xs) = (x, xs), if divide x n == (q, r) = (y, x:ys), otherwise where (y, ys) = filter n r xs The idea is that evaluating filter n r l filters out a natural number x such that x mod n = r from the list of natural numbers l. This program can handle (potentially) infinite lists. The function filter corresponds to the following orthogonal (in the sense of having only infeasible critical pairs) 3-CTRS with strict equality and local definitions: filter (n, r, nil ) → (−1, nil ) filter (n, r, x : xs) → (x, xs) ⇐ div (x, n) ≡ (q, r) = true filter (n, r, x : xs) → (y, x : ys) ⇐ filter (n, r, xs) = (y, ys), div (x, n) ≡ (q, r) = false This system is extended properly oriented and right-stable but not properly oriented due to the presence of the extra variable q in the last rewrite rule. Acknowledgements. We thank Michael Hanus for scrutinizing a previous version of the paper. Vincent van Oostrom simplified most of the counterexamples in the (LNCS version of the) paper.
References 1.
S. Antoy and A. Middeldorp, A Sequential Reduction Strategy, Proceedings of the 4th International Conference on Algebraic and Logic Programming, Madrid, Lecture Notes in Computer Science 850, pp. 168–185, 1994.
2.
J. Avenhaus and C. Lor´ıa-S´aenz, On Conditional Rewrite Systems with Extra Variables and Deterministic Logic Programs, Proceedings of the 5th International Conference on Logic Programming and Automated Reasoning, Kiev, Lecture Notes in Artificial Intelligence 822, pp 215–229, 1994.
3.
J.A. Bergstra and J.W. Klop, Conditional Rewrite Rules: Confluence and Termination, Journal of Computer and System Sciences 32(3), pp. 323–362, 1986.
4.
H. Bertling and H. Ganzinger, Completion-Time Optimization of Rewrite-Time Goal Solving, Proceedings of the 3rd International Conference on Rewriting Techniques and Applications, Chapel Hill, Lecture Notes in Computer Science 355, pp. 45–58, 1989. 13
5.
N. Dershowitz and J.-P. Jouannaud, Rewrite Systems, in: Handbook of Theoretical Computer Science, Vol. B ed. J. van Leeuwen), North-Holland, pp. 243–320, 1990.
6.
N. Dershowitz and M. Okada, A Rationale for Conditional Equational Programming, Theoretical Computer Science 75, pp. 111–138, 1990.
7.
N. Dershowitz, M. Okada, and G. Sivakumar, Confluence of Conditional Rewrite Systems, Proceedings of the 1st International Workshop on Conditional Term Rewriting Systems, Orsay, Lecture Notes in Computer Science 308, pp. 31–44, 1987.
8.
E. Giovannetti, G. Levi, C. Moiso, and C. Palamidessi, Kernel-LEAF: A Logic plus Functional Language, Journal of Computer and System Sciences 42(2), pp. 139–185, 1991.
9.
E. Giovannetti and C. Moiso, A Completeness Result for E-Unification Algorithms based on Conditional Narrowing, Proc. Workshop on Foundations of Logic and Functional Programming, Trento, Lecture Notes in Computer Science 306, pp. 157–167, 1986.
10. Juan Carlos Gonz´alez-Moreno, M.T. Hortal´a-Gonz´ alez, M. Rodr´ıguez-Artalejo, Denotational versus Declarative Semantics for Functional Programming, Proceedings of the 5th Workshop on Computer Science Logic, Berne, Lecture Notes in Computer Science 626, pp. 134–148, 1992. 11. B. Gramlich, On Termination and Confluence of Conditional Rewrite Systems, Proceedings of the 4th International Workshop on Conditional Term Rewriting Systems, Jerusalem, Lecture Notes in Computer Science, 1995. To appear. 12. M. Hanus, The Integration of Functions into Logic Programming: From Theory to Practice, Journal of Logic Programming 19 & 20, pp. 583–628, 1994. 13. M. Hanus, On Extra Variables in (Equational) Logic Programming, report MPI-I-94-246, Max-Planck-Institut f¨ ur Informatik, 1994. To appear in the Proceedings of the 12th International Conference on Logic Programming, Tokyo, MIT Press, 1995. 14. T. Ida and S. Okui, Outside-In Conditional Narrowing, IEICE Transactions on Information and Systems, E77-D(6), pp. 631–641, 1994. 15. J.W. Klop, Combinatory Reduction Systems, Ph.D. thesis, Mathematical Centre Tracts 127, Centre for Mathematics and Computer Science, Amsterdam, 1980. 16. J.W. Klop, Term Rewriting Systems, in: Handbook of Logic in Computer Science, Vol. II (eds. S. Abramsky, D. Gabbay and T. Maibaum), Oxford University Press, pp. 1–116, 1992. 17. A. Middeldorp, Completeness of Combinations of Conditional Constructor Systems, Journal of Symbolic Computation 17, pp. 3–21, 1994. 18. A. Middeldorp and E. Hamoen, Completeness Results for Basic Narrowing, Applicable Algebra in Engineering, Communication and Computing 5, pp. 213–253, 1994. 19. J.J. Moreno-Navarro and M. Rodr`ıguez-Artalejo, Logic Programming with Functions and Predicates: The Language BABEL, Journal of Logic Programming 12, pp. 191–223, 1992.
14
20. E. Ohlebusch, Modular Properties of Constructor-Sharing Conditional Term Rewriting Systems, Proceedings of the 4th International Workshop on Conditional Term Rewriting Systems, Jerusalem, Lecture Notes in Computer Science, 1995. To appear. 21. P. Padawitz, Generic Induction Proofs, Proceedings of Third International Workshop on Conditional Term Rewriting Systems, Pont–` a-Mousson, Lecture Notes in Computer Science 656, pp. 175–197, 1993. 22. Y. Toyama and M. Oyamaguchi, Church-Rosser Property and Unique Normal Form Property of Non-Duplicating Term Rewriting Systems, Proceedings of the 4th International Workshop on Conditional Term Rewriting Systems, Jerusalem, Lecture Notes in Computer Science, 1995. To appear. 23. A. Werner, personal communication, January 1995.
15