VIEWS: 5 PAGES: 8 POSTED ON: 12/18/2011 Public Domain
IEICE TRANS. INF. & SYST., VOL.E87–D, NO.2 FEBRUARY 2004 352 PAPER Special Section on Foundations of Computer Science Higher-Order Path Orders Based on Computability Keiichirou KUSAKARI† , Member SUMMARY Simply-typed term rewriting systems (STRSs) are an ex- map(λx.F(x), [ ]) → [ ] tension of term rewriting systems. STRSs can be naturally handle higher map(λx.F(x), X :: Xs) order functions, which are widely used in existing functional programming → F(X) :: map(λx.F(x), Xs) languages. In this paper we design recursive and lexicographic path orders, which can eﬃciently prove the termination of STRSs. Moreover we discuss In order to prove the termination of TRSs, recursive an application to the dependency pair and the argument ﬁltering methods, and lexicographic path orders are proposed [5], [11], which which are very eﬀective and eﬃcient support methods for proving termina- is based on the notion of simpliﬁcation orders. These path tion. key words: simply-typed term rewriting system, termination, path order, orders are extended to HRSs by Jouannaud and Rubio [7], computability, dependency pair, argument ﬁltering method and by Iwami and Toyama [9], [10]. We also extend path or- ders to STRSs [12]. All of these path orders are based on the 1. Introduction notion of simpliﬁcation orders. Unfortunately, these path or- ders have unnatural restrictions for type or precedence. On the other hand, in order to prove the termination Term rewriting systems (TRSs) are computation models. In of typed λ-calculus, the notion of computability was intro- TRSs, terms are reduced by using a set of directed equations, duced by Tait [18] and Girard [6]. Based on computability called rewrite rules. The most striking feature is that TRSs instead of simpliﬁcation orders, Jouannaud and Rubio [8] themselves can be regarded as functional programming lan- and Raamsdonk [14] introduced recursive path orders in guages. For example, the following TRS deﬁnes addition HRSs. on natural numbers represented by the constant 0 and the In this paper, we design new recursive and lexico- successor function S : graphic path orders in STRSs based on the notion of com- Add(x, 0) → x putability, and give an more reﬁned proof. Unlike path or- Add(x, S (y)) → S (Add(x, y)) ders in [8], [14], our path orders are reduction orders, that is, directly simulate reduction relations. This is a very ad- Unfortunately, TRSs cannot handle higher-order functions. vantage, because our path orders can combine well with the For example, the Map-function, which is one of the most dependency pair and the argument ﬁltering methods [12], typical higher-order function in functional programming which are very eﬀective and eﬃcient support methods for languages, is deﬁned as follows: proving termination. Map( f, Nil) → Nil 2. Preliminaries Map( f, Cons(x, xs)) → Cons( f (x), Map( f, xs)) We assume that the reader is familiar with notions of term This system is a legal functional program, but an illegal rewriting systems [4]. TRS: the variable f occurs at a non-leaf position in the For given binary relation >, the lexicographic extension right-hand side of the second rule. In order to handle such >lex on lists is recursively deﬁned as follows: the system above, we designed simply-typed term rewriting systems (STRSs) in which variable occurrences at non-leaf [a1 , . . . , an ] >lex [ ] if n > 0 positions are permitted [12]. [a1 , . . . , an ] >lex [a1 , . . . , am ] if a1 > a1 Nipkow also introduced higher-order rewriting systems [a1 , . . . , an ] >lex [a1 , . . . , am ] (HRSs), which are rewriting systems on algebraic λ-terms, if a1 = a1 and [a2 , . . . , an ] >lex [a2 , . . . , am ] using the λ-calculus as a meta-language [13]. Intuitively, al- A multiset on a set A is a set of elements of A in which gebraic λ-terms are simply-typed λ-terms in which occur- elements may have multiple occurrences. We use standard rences of function symbols are permitted. For example, the set notation like {a, a, b}. It will be obvious from the context Map-function in HRSs is deﬁned as follows: if we refer to a set or a multiset. For given binary relation >, multisets M and N, we deﬁne M >mul N as ∀n ∈ N − Manuscript received March 23, 2003. Manuscript revised July 6, 2003. M. ∃m ∈ M − N. m > n. Final manuscript received January 1, 2004. A signature F is a ﬁnite set of function symbols, de- † The author is with the Graduate School of Information Sci- noted by F, G, . . .. A set V is an enumerable set of vari- ence, Nagoya University, Nagoya-shi, 464–8603 Japan. able symbols, denoted by x, y, f, g, . . .. We assume that KUSAKARI: HIGHER-ORDER PATH ORDERS BASED ON COMPUTABILITY 353 F ∩ V = ∅. The set T (F , V) of terms is the smallest set of in T . A term t is said to be terminating with respect to such that a(t1 , . . . , tn ) ∈ T (F , V) whenever a ∈ F ∪ V and in T if there exists no inﬁnite decreasing sequence of ti ∈ T (F , V). In the case of n = 0, we denote a instead in T starting from t. of a(). For s ≡ a(s1 , . . . , sn ), we often write s(t1 , . . . , tm ) in- Deﬁnition 2.1: Suppose that T ⊆ T (F , V) and is a bi- stead of a(s1 , . . . , sn , t1 , . . . , tm ). Identity of terms is denoted nary relation on T . A binary relation is said to be a reduc- by ≡. We deﬁne root(a(t1 , . . . , tn )) = a. Var(t) is the set tion order in T if is monotonic, stable and well-founded of variables in t. The size |t| of a term t is the number of in T . function and variable symbols in t. A non-empty set of basic types is denoted by B. The Proposition 2.2: [12] Let R be a STRS. Then R is termi- set S of simple types is generated from B by the constructor nating iﬀ there exist T ⊆ T (F , V) and a reduction strict → as S ::= B | (S → S). A simple type (α1 → (· · · → order > in T satisfying T τ (F , V) ⊆ T and l > r for all (αn → α) · · ·)) is abbreviated to α1 → · · · → αn → α. l → r ∈ R. A type attachment τ is a function from F ∪ V to S. We We do not assume that a reduction order is a strict or- assume that for each simple type α there exists a variable x der, that is, transitive and irreﬂexive, because path orders such that τ(x) = α. A term a(t1 , . . . , tn ) has a simple type α designed in this paper are not transitive. However it is no if τ(a) = α1 → · · · → αn → α and each ti has the simple problem for proving termination, because >+ is a reduction type αi . A term t is said to be a simply-typed term if it has a strict order if > is a reduction order. Hence we obtain the simple type α. Then we denote τ(t) = α. The set of simply- following theorem from the proposition above. α typed term with simple type α is denoted by T τ (F , V), and the set of all simply-typed terms is denoted by T τ (F , V). Theorem 2.3: Let R be a STRS. Then R is terminating A substitution is a mapping from variables to terms. iﬀ there exist T ⊆ T (F , V) and a reduction order > in T A substitution over terms is deﬁned as θ(a(t1 , . . . , tn )) = satisfying T τ (F , V) ⊆ T and l > r for all l → r ∈ R. a(θ(t1 ), . . . , θ(tn )) if a ∈ F ; θ(a(t1 , . . . , tn )) = a (t1 , . . . , tk , Keep in mind that we distinguish the notions of reduc- θ(t1 ), . . . , θ(tn )) if a ∈ V with θ(a) = a (t1 , . . . , tk ). We here- tion order and reduction strict order in this paper. after assume that x and θ(x) have the same simple type for Finally, we introduce the notion of well-formed terms, each variable x. We write tθ instead of θ(t). which is mainly used throughout the paper. A context is a term which has the special symbol , called hole. We hereafter assume that is of a basic type. Deﬁnition 2.4: Suppose that B is a set of basic types, and C[t] is the term obtained from C[ ] by replacing with t. τ is a type attachment. We introduce a special basic type ∗, A rewrite rule is a pair of terms, written by l → r, such which represent any basic type. We deﬁne a function skel that root(l) ∈ F and Var(l) ⊇ Var(r). A simply-typed term as skel(α) = ∗ if α ∈ B; skel(α → β) = skel(α) → skel(β). rewriting system (STRS) is a ﬁnite set R of rules such that We deﬁne a type attachment τ0 as τ0 (α) = skel(τ(α)). The τ(l) = τ(r) ∈ B for all l → r ∈ R. A reduction relation → embedding relation on skeletons is deﬁned as follows: R in STRS R is deﬁned as s → t iﬀ s ≡ C[lθ] and t ≡ C[rθ] • ∗ ∗ • α1 → α2 α1 → α2 if αi αi (i = 1, 2) R for some rule l → r ∈ R, context C[ ] and substitution θ. For example, the Map-function is deﬁned as the following • αi α1 → α2 for i = 1, 2. STRS: A term a(t1 , . . . , tn ) is said to be well-formed with skeleton Map( f, Nil) → Nil α if τ0 (a) = α1 → · · · αn → α and for each i, there exists αi Map( f, Cons(x, xs)) → Cons( f (x), Map( f, xs)) such that ti is well-formed with αi and αi αi . We denote by T τ ,α (F , V) the set of all well-formed terms with skeleton In the system, we have the following reduction relation se- α. We also denote wftypeτ (t) = α if t ∈ T τ ,α (F , V), and quence. denote by T τ (F , V) the set of all well-formed terms. Map(S, Cons(S (0), Cons(0, Nil))) We notice that any simply-typed term is a well-formed → Cons(S (S (0)), Map(S, Cons(0, Nil))) term, that is, T τ (F , V) ⊆ T τ (F , V), but the equality R does not hold in general. For example, letting τ(0) = → Cons(S (S (0)), Cons(S (0), Map(S , Nil))) Nat, τ(Nil) = NatList and τ(Map) = (Nat → Nat) → R → Cons(S (S (0)), Cons(S (0), Nil)) NatList → NatList. Then S (Nil), Map(0, Nil) ∈ T τ (F , V), R but S (Nil), Map(0, Nil) T τ (F , V). A STRS R is terminating if there exists no inﬁnite reduc- tion sequence. We often omit the subscript R whenever no 3. Computability confusion arises. Suppose that T ⊆ T (F , V) and is a binary relation In order to prove the termination of typed λ-calculus, the on T . is said to be monotonic in T if s t ⇒ C[s] notion of computability was introduced by Tait [18] and C[t] for all s, t, C[s], C[t] ∈ T , and said to be stable in T if Girard [6]. In the following sections, we will make use of the s t ⇒ sθ tθ for all s, t, sθ, tθ ∈ T . is said to be well- notion to prove the well-foundedness of path orders. This founded in T if there exists no inﬁnite decreasing sequence approach is also used in [8], [14]. IEICE TRANS. INF. & SYST., VOL.E87–D, NO.2 FEBRUARY 2004 354 Intuitivity, the notion of computability corresponds to is not terminating. It is a contradiction with the com- termination as function. For instance, considering STRS putability of s. R = {F(0) → F(0)}. Then the term F(0) is not terminat- (3) Assume that s is not computable, that is, not terminat- ing, but the term F is terminating. We often call F non- ing. Then there exists an inﬁnite decreasing sequence terminating function. The notion of computability handles s t1 t2 · · ·. From the assumption, t1 is com- this view point, i.e., the term F is terminating but not com- putable. Since is a subject relation, wftypeτ (t1 ) = ∗. putable. Hence t1 is terminating. It is a contradiction. A notion of computability is inductively deﬁned on (4) Let α = α1 → · · · → αm → ∗. Assume that types with respect to the embedding relation as follows: t(t1 , . . . , tn ) is not computable. Then there exist com- putable well-formed terms ui for each i such that Deﬁnition 3.1: Let α = α1 → · · · → αn → ∗. A t(t1 , . . . , tn , u1 , . . . , um ) ∈ T τ ,∗ (F , V) is not terminating. well-formed term t ∈ T τ ,α (F , V) is said to be computable It is a contradiction with the computability of t. with respect to if t(t1 , . . . , tn ) is terminating with respect to for all computable terms ti (i = 1, . . . , n) such that wftypeτ (ti ) αi . 4. Recursive Path Order Deﬁnition 3.2: Let be a binary relation on well-formed terms T τ (F , V). is said to be a subject relation if s t ⇒ In the previous section we have seen that the subject and wftypeτ (s) = wftypeτ (t). has the supplement property if the supplement properties are essential in computable ap- s t ⇒ s(u) t(u) for any well-formed terms s, t and u proaches. Based on this viewpoint, we design a recursive such that s(u) and t(u) are well-formed. path order by giving the subject and the supplement proper- ties to original one [5]. Also not only approaches in [6], [18] but ones in [8], [14], four properties in the following lemma hold the key Deﬁnition 4.1 (Recursive Path Order): to computable approaches. Hence subject and supplement A precedence is a strict order on F . properties are essential in computable approaches so that For well-formed terms s ≡ a(s1 , . . . , sn ) and t ≡ clearly from the following lemma. a (t1 , . . . , tm ), we have s >rpo t if wftypeτ (s) = wftypeτ (t) and satisfying one of the following rules: Lemma 3.3: Let be a subject relation on T τ (F , V) with the supplement property. Then the following properties with (RPO1) wftypeτ (s) = ∗, a a , and for all j, either s >rpo t j respect to hold. or ∃i. si ≥rpo t j , (RPO2) a = a and {s1 , . . . , sn } >mul {t1 , . . . , tm }, or rpo (1) If there exists at least one computable well-formed (RPO3) there exists a number k such that ∃i. si ≥rpo term u with wftypeτ (u) = ∗, then any computable well- a (t1 , . . . , tk ) and ∀ j > k. ∃i j . si j ≥rpo t j , formed term is terminating. (2) If s is computable and s t then t is computable. where ≥rpo is deﬁned as >rpo ∪ ≡. (3) If wftypeτ (s) = ∗ and t is computable for any t with In the deﬁnition above, the restriction wftypeτ (s) = s t, then s is computable. wftypeτ (t) guarantees that >rpo is a subject relation, and the (4) Let t(t1 , . . . , tn ) ∈ T τ ,α (F , V). If t and each ti are com- rule (RPO3) and the restriction wftypeτ (s) = ∗ in (RPO1) putable then t(t1 , . . . , tn ) is computable. give >rpo the supplement property. Proof : Lemma 4.2: >rpo is a subject relation. (1) Let t ∈ T τ ,α (F , V) be a computable term with α = Proof : Trivial. α1 → · · · → αn → ∗. Assume that there exists an in- ﬁnite decreasing sequence t ≡ t0 t1 · · ·. Since The subject property is essential for designing >rpo . is a subject relation, wftypeτ (ti ) = α for each i. For example, letting F G, τ(F) = α → α → α and Thanks to the assumption, letting u be a computable τ(G) = (α → α) → α → α. If we omit the restriction term with wftypeτ (u) = ∗. From the deﬁnition, ∗ αi wftypeτ (s) = wftypeτ (t) whenever s >rpo t, then we ob- for each i, hence each t j (u, . . . , u) is well-formed with tain F(x, y) >rpo G(F(x), y) by (RPO1), and G(F(x), y) >rpo wftypeτ (t j (u, . . . , u)) = ∗. It follows from the supple- F(x, y) by (RPO3). ment property that t0 (u, . . . , u) t1 (u, . . . , u) · · ·. It is a contradiction with the computability of t. Lemma 4.3: >rpo has the supplement property. (2) Assume that t ∈ T τ ,α (F , V) is not computable, where Proof : Let s ≡ a(s1 , . . . , sn ) >rpo a (t1 , . . . , tm ) ≡ t, α = α1 → · · · → αn → ∗. Then there exist com- wftypeτ (s) = α → β and u ∈ T τ ,α (F , V) for some α α. putable terms ui with wftypeτ (ui ) αi (i = 1, . . . , n) We prove that s(u) >rpo t(u) by induction on the deﬁnition such that t(u1 , . . . , un ) is not terminating. Since of >rpo . According to the rule applied to s >rpo t, we distin- is a subject relation, wftypeτ (s) = α and hence guish the following cases: wftypeτ (s(u1 , . . . , un )) = ∗. From the supplement prop- erty, s(u1 , . . . , un ) t(u1 , . . . , un ). Thus s(u1 , . . . , un ) RPO1: This is not the case, because wftypeτ (s) ∗. KUSAKARI: HIGHER-ORDER PATH ORDERS BASED ON COMPUTABILITY 355 RPO2: Then {s1 , . . . , sn } >mul {t1 , . . . , tm }. Since {s1 , . . . , rpo t j is computable. sn , u} >mul {t1 , . . . , tm , u}, we have s(u) >rpo t(u) by rpo As in the case (RPO1), it suﬃces to show that any (RPO2). u is computable whenever t >rpo u. It follows from RPO3: Then there exists a number k such that ∃i. si ≥rpo the induction hypothesis, because (a, {s1 , . . . , sn }, |t|) a (t1 , . . . , tk ) and ∀ j > k. ∃i j . si j ≥rpo t j . We have also (a , {t1 , . . . , tm }, |u|). s(u) ≡ a(s1 , . . . , sn , u) >rpo a (t1 , . . . , tm , u) ≡ t(u) by RPO3: Suppose that si ≥rpo a (t1 , . . . , tk ) and si j ≥rpo t j (RPO3), because of u ≥rpo u. for all j > k. From Lemma 4.4 (2), a (t1 , . . . , tk ) and each t j ( j > k) are computable. From Lemma 4.4 (4), Thanks to the subject and the supplement properties, t ≡ a (t1 , . . . , tk , tk+1 , . . . , tm ) is computable. we can obtain the following key lemma correspond to Lemma 3.3. Lemma 4.6: >rpo is well-founded in well-formed terms T τ (F , V). Lemma 4.4: In well-formed terms, the following proper- ties with respect to >rpo hold. Proof : By Lemma 4.4 (1), any computable term is termi- (1) Any computable well-formed term is terminating. nating in well-formed terms. Hence, it suﬃces to show that (2) If s is computable and s >rpo t then t is computable. any well-formed term t is computable with respect to >rpo . (3) If wftypeτ (s) = ∗ and t is computable for any t with The proof proceeds by induction on |t|. Let t ≡ a(t1 , . . . , tm ) s >rpo t, then s is computable. and wftypeτ (t) = α1 → · · · → αn → ∗. (4) Let t(t1 , . . . , tn ) ∈ T τ (F , V). If t and each ti are com- Any ti is computable by the induction hypothesis. As- putable then t(t1 , . . . , tn ) is computable. sume that t is not computable. Then there exist com- putable terms ui such that t(u1 , . . . , un ) is a non-terminating Proof : From Lemmata 4.2 and 4.3, >rpo has the subject well-formed term. Let v be an arbitrary term such that and the supplement properties. We recall that we assume a(t1 , . . . , tm , u1 , . . . , un ) >rpo v. From Lemma 4.5, v is com- the existence of a basic-typed variable x, i.e., wftypeτ (x) = putable. Hence t(u1 , . . . , un ) is computable by Lemma 4.4 ∗. From the deﬁnition of >rpo , the variable is minimal (3). From the deﬁnition, t(u1 , . . . , un ) is terminating. It is a with respect to >rpo . Therefore this lemma follows from contradiction. Lemma 3.3. In order to prove that >rpo is a reduction order, the By using four properties above, we prove the well- monotonicity and the stability are shown only remains. foundedness of >rpo on well-formed terms by proving that These properties guarantees that >rpo can simulate the re- any well-formed term is computable. The proof is con- duction relation, i.e., s → t ⇒ s >rpo t if l >rpo r for all structed by the following two lemmata. We note that the R following lemma makes use of induction on a triple as in l → r ∈ R. [8]. Lemma 4.7: >rpo is monotonic in T τ (F , V). Lemma 4.5: Let s ≡ a(s1 , . . . , sn ) >rpo a (t1 , . . . , tm ) ≡ t Proof : Let s >rpo t. It is trivial that wftypeτ (C[s]) = such that wftypeτ (s) = ∗. If any si is computable with re- wftypeτ (C[t]) for any context C[ ]. We prove C[s] >rpo C[t] spect to >rpo , then so is t. by structural induction on C[ ]. The case of C[ ] ≡ is triv- Proof : The proof proceeds by induction on triples ial. Suppose that C[ ] ≡ a(. . . , C [ ], . . .). From the induction (a, {s1 , . . . , sn }, |t|) with respect to the order deﬁned as hypothesis, C [s] >rpo C [t]. Hence {. . . , C [s], . . .} >mul rpo the lexicographic combination of , >mul and the usual rpo {. . . , C [t], . . .}. We obtain C[s] >rpo C[t] by (RPO2). strict order over natural numbers. We notice that >mul is rpo In the proof above, we use the fact that is of a basic well-founded on multisets of computable terms, because of type. Lemma 4.4 (1). According to the rule applied to s >rpo t, we distinguish Lemma 4.8: >rpo is stable in T τ (F , V). the following cases: Proof : Let s ≡ a(s1 , . . . , sn ) >rpo a (t1 , . . . , tm ) ≡ t. It is RPO1: We ﬁrst prove that any t j is computable. In the trivial that wftypeτ (sθ) = wftypeτ (tθ) for any substitution θ. case of si ≥rpo t j , t j is computable by Lemma 4.4 We prove sθ >rpo tθ by induction on |s| + |t|. According (2). In the case of s >rpo t j , t j is computable by to the rule applied to s >rpo t, we distinguish the following the induction hypothesis, because (a, {s1 , . . . , sn }, |t|) cases: (a, {s1 , . . . , sn }, |t j |). Hence any t j is computable. From Lemma 4.2, wftypeτ (t) = wftypeτ (s) = ∗. Thanks RPO1: From the induction hypothesis, for all j either to Lemma 4.4 (3) and wftypeτ (t) = ∗, it suﬃces sθ >rpo t j θ or ∃i. si θ ≥rpo t j θ. Hence we obtain to show that any u is computable whenever t >rpo sθ >rpo tθ by (RPO1). u. It follows from the induction hypothesis, because RPO2: Let aθ = a (ui ). From the induction hypothesis, (a, {s1 , . . . , sn }, |t|) (a , {t1 , . . . , tm }, |u|). {s1 θ, . . . , sn θ} >mul {t1 θ, . . . , tm θ}. Hence {ui , s1 θ, . . . , rpo RPO2: Since {s1 , . . . , sn } >mul {t1 , . . . , tm }, for any t j there rpo sn θ} >mul {ui , t1 θ, . . . , tm θ}. Since root(sθ) = a = rpo exists si such that si ≥rpo t j . From Lemma 4.4 (2), any root(tθ), we obtain sθ >rpo tθ by (RPO2). IEICE TRANS. INF. & SYST., VOL.E87–D, NO.2 FEBRUARY 2004 356 RPO3: Suppose that ∃i. si ≥rpo a (t1 , . . . , tk ) and ∀ j > k. ∃i j . si j ≥rpo t j for some k. From 6. Dependency Pair and Argument Filtering Methods the induction hypothesis, si θ ≥rpo a (t1 , . . . , tk )θ and si j θ ≥rpo t j θ. Hence sθ ≡ a (ui , s1 θ, . . . , sn θ) >rpo The notion of dependency pairs in ﬁrst-order TRSs was in- (a (t1 , . . . , tk )θ)(tk+1 θ, . . . , tm θ) ≡ tθ by (RPO3), where troduced by Arts and Giesl [1]–[3]. The notion was ex- aθ = a (ui ). tended to higher-order systems by Sakai, Watanabe and Theorem 4.9: >rpo is a reduction order in well-formed Sakabe [15], and by Kusakari [12]. In the dependency terms T τ (F , V). pair method, weak reduction orders play an important role instead of reduction orders. To design weak reduction Proof : From Lemmata 4.6, 4.7 and 4.8. orders, Arts and Giesl introduced the argument ﬁltering Corollary 4.10: >rpo is a reduction order and >+ is a re- rpo method, which is designed by eliminating unnecessary sub- duction strict order in simply-typed terms T τ (F , V). terms [3]. After that the method was extended to STRSs by Kusakari [12]. First we introduce some results for the We notice that >rpo is not transitive. For example, let- dependency pair and the argument ﬁltering methods in ting G F, τ(F) = τ(G) = (α → α) → α → α, τ( f ) = α → STRSs [12]. α and τ(x) = α, then F(G( f ), x) >rpo G( f, x) >rpo F( f, f (x)) but F(G( f ), x) ≯rpo F( f, f (x)). Deﬁnition 6.1: The set DF(R) of deﬁned symbols in R is Note that the transitivity is unnecessary for proving ter- deﬁned as {root(l) | l → r ∈ R}. F # = {F # | F ∈ F } is mination (refer to Theorem 2.3). a set of marked symbols disjoint from F ∪ V. We deﬁne Example 4.11: Let R1 be the following STRS the root-marked term by (F(t1 , . . . , tn ))# = F # (t1 , . . . , tn ). If root(t) ∈ V then we identify t# with t. A pair u# , v# of Map( f, Nil) → Nil terms is a dependency pair of STRS R if there exists a rule Map( f, C(x, xs)) → C( f (x), Map( f, xs)) u → C[v] ∈ R such that root(v) ∈ DF(R) ∪ V, v is of a basic We deﬁne the precedence by Map C. Then type, and v itself is not a variable. We denote by DP(R) the Map( f, C(x, xs)) >rpo f (x) by (RPO3), and set of dependency pairs of R. Map( f, C(x, xs)) >rpo Map( f, xs) by (RPO2). Thus Deﬁnition 6.2: We deﬁne that a term l is said to be a pat- Map( f, C(x, xs)) >rpo C( f (x), Map( f, xs)) by (RPO1). We tern if any variable occurrences in l is at a leaf position, that have also Map( f, Nil) >rpo Nil by (RPO3). Hence R1 is ter- is, n = 0 whenever l ≡ C[x(u1 , . . . , un )] and x ∈ V. A STRS minating. R is said to be a pattern STRS if the left-hand side l for any rule l → r in R is a pattern, and a binary relation over 5. Lexicographic Path Order terms is said to be stable for pattern if l r ⇒ lθ rθ for any l and r such that l is a pattern. We also design a lexicographic path order by giving the sub- ject and the supplement properties to original one [11]. In the following, we consider pattern STRSs, because the argument ﬁltering method in [12] requires the restriction Deﬁnition 5.1 (Lexicographic Path Order): A precedence by pattern. is a strict order on F . For well-formed terms s ≡ a(s1 , . . . , sn ) and t ≡ Deﬁnition 6.3: A pair ( , >) of binary relations on a (t1 , . . . , tm ), we have s >lpo t if wftypeτ (s) = wftypeτ (t) T τ (F , V) is said to be a reduction pair for pattern STRSs and satisfying one of the following rules: if it satisﬁes the following conditions: (LPO1) wftypeτ (s) = ∗, a a , and for all j, either s >lpo t j • is monotonic and stable for pattern, or ∃i. si ≥lpo t j , • > is well-founded and stable for pattern, (LPO2) a = a , [s1 , . . . , sn ] >lex [t1 , . . . , tm ], and for all j, lpo • · > ⊆ > or > · ⊆ >, either s >lpo t j or ∃i. si ≥lpo t j , or • satisﬁes the marked condition for DF(R)† (v v# if (LPO3) there exists a number k such that ∃i. si ≥lpo root(v) ∈ DF(R) and τ(v) ∈ B). a (t1 , . . . , tk ) and ∀ j > k. ∃i j . si j ≥lpo t j , Specially, a binary relation is said to be a weak reduc- where ≥lpo is deﬁned as >lpo ∪ ≡. tion order for pattern STRSs if ( , >) is a reduction pair for Theorem 5.2: >lpo is a reduction order in well-formed pattern STRSs, where > is the strict part of . terms T τ (F , V). Proposition 6.4: [12] Let R be a pattern STRS and ( , >) We omit the proof, because all proofs are essentially be a reduction pair for pattern STRSs. If R ⊆ and similar as proofs of the recursive path order. DP(R) ⊆ > then R is terminating. Corollary 5.3: >lpo is a reduction order and >+ is a re- lpo Deﬁnition 6.5: An argument ﬁltering function is a func- duction strict order in simply-typed terms T τ (F , V). tion π such that for any F ∈ F , π(F) is a list of posi- By using >lpo , we can also prove the termination of tive integers [i1 , . . . , ik ] with i1 < · · · < ik ≤ n, where STRS R1 in Example 4.11. † This condition is slightly modiﬁed from the condition in [12]. KUSAKARI: HIGHER-ORDER PATH ORDERS BASED ON COMPUTABILITY 357 τ(F) = α1 → · · · αn → β and β ∈ B. π(F)≤n denotes the • >π are stable for DP(R), i.e., for all u, v ∈ DP(R), maximal sub-list [i1 , . . . , im ] of π(F) such that im ≤ n. We u >π v ⇒ uθ >π vθ. can naturally extend π over terms as follows: If R ⊆ and DP(R) ⊆ > then R is terminating. π(a(t1 , . . . , tn )) = a(π(t1 ), . . . , π(tn )) In this paper, we have the general assumption τ(x) = if a ∈ V τ(θ(x)) for each x, however this does not guarantee π(a(t , . . . , t )) = a(π(t ), . . . , π(t )) 1 n i1 im wftypeτπ (π(t)) = wftypeτπ (π(tθ)). if a ∈ F and π(a)≤n = [i1 , . . . , im ] Lemma 6.10: For given argument ﬁltering function π and binary relation • wftypeτπ (π(t)) = wftypeτπ (π(tθ)) if root(t) ∈ F >, we deﬁne s π t by π(s) ≥ π(t). We hereafter assume • wftypeτπ (π(t)) wftypeτπ (π(tθ)) if root(t) ∈ V that if π(F) is not deﬁned explicitly then it is intended to be [1, . . . , n], where τ(F) = α1 → · · · αn → β and β ∈ B. Proof : It is a directly consequence from deﬁnitions of wftype and π over terms. We notice that for each >∈ {>rpo , >lpo } the strict part >π of π can be directly deﬁned as s >π t ⇐⇒ π(s) > In general, wftypeτπ (π(t)) = wftypeτπ (π(tθ)) does not π(t), because > is irreﬂexive, which follows from the well- hold. For example, letting t = f (H), θ( f ) = F, τ( f ) = foundedness. τ(F) = (α → α) → α → α, τ(H) = α → α and π(F) = [1], then wftypeτπ (π(t)) = ∗ → ∗ and wftypeτπ (π(tθ)) Proposition 6.6: [12] Let > be a reduction order in = wftypeτπ (F(H)) = ∗. This problem destroys the stability, T (F , V). If > has the deletion property† and π satisﬁes because f (H) >π H but F(H) ≯π H. Hence we need a rpo rpo the marked condition for DF(R), then π is a weak reduc- suitable restriction. tion order for pattern STRSs. Lemma 6.11: Let π be an argument ﬁltering function and Unlike path orders in [12], deﬁnitions of path orders in R be a STRS satisfying the following condition: this paper dependent on type attachment. Hence we intro- (P) Let l → r ∈ R, π(l) ≡ a(π(l1 ), . . . , π(ln )) and x ∈ duce a type attachment τπ after argument ﬁltering. Var(π(l)). If τ(x) B then for each i either x ≡ li Deﬁnition 6.7: For each type attachment τ, we deﬁne τπ or x Var(π(li )). as τπ (x) = τ(x) for all x ∈ V; τπ (F) = αi1 → · · · αik → β if Then >π , π >π and π are stable for R ∪ DP(R). rpo , π(F) = [i1 , . . . , ik ] and τ(F) = α1 → · · · αn → β with β ∈ B. rpo lpo lpo α Proof : It is easily shown by induction on s that π(sθ) ≡ Lemma 6.8: If t ∈ T τ (F , V) then π(t) ∈ T τπ (F , V) for ,α π(tθ) for any s and t such that π(s) ≡ π(t). Hence it suﬃces some α α. to show the case of >π and >π . Moreover we omit the rpo lpo Proof : The proof proceeds by induction on |t|. Let t ≡ case of >π , because the proof is essentially similar as proof lpo α a(t1 , . . . , tn ) ∈ T τ (F , V), τ(a) = α1 → · · · → αn → α and of the case >π . rpo α = αn+1 → · · · → αm → β with β ∈ B. Let u, v ∈ R ∪ DP(R), s ≡ a(s1 , . . . , sn ), t ≡ a (t1 , . . . , From the induction hypothesis, for each i ≤ n, there tm ), π(s) ≡ a(π(si1 ), . . . , π(sin )) and π(t) ≡ a (π(t j1 ), . . . , ,α exists αi such that π(ti ) ∈ T τπ i (F , V) and αi αi . In the π(t jm )). Suppose that π(u) >rpo π(v) and π(s) >rpo π(t) is case of a ∈ V, it is trivial that π(t) = a(π(t1 ), . . . , π(tn )) a sub-proof of π(u) >rpo π(v). We prove π(sθ) >rpo π(tθ) by ∈ T τπ (F , V). Suppose that a ∈ F , π(a) = [i1 , . . . , il ] and ,α induction on |s| + |t|. ≤n π(a) = [i1 , . . . , ik ]. Then π(t) = a(π(ti1 ), . . . , π(tik )). Hence In the case of a, a ∈ F , thanks to Lemma 6.10, π(t) ∈ T τπ (F , V) and γ = αik+1 → · · · → αil → β. Since γ ,γ π(sθ) >rpo π(tθ) can be proved as similar to Lemma 4.8. αn+1 → · · · → αm → β = α, the claim holds. In the case of a ∈ V, π(s) ≡ a >rpo π(t) from the condition (P). It is a contradiction. Unfortunately, our recursive and lexicographic path or- Suppose that a ∈ F and a ∈ V. Then (RPO3) ders do not have the deletion property, because a(. . . , u, . . .) is only applicable to π(s) >rpo π(t). Let k be a number and a(. . . , . . .) have diﬀerent type even if both terms are such that ∃i p . π(si p ) ≥rpo a (π(ti1 ), . . . , π(tik )) and ∀ jq > well-formed. ik . ∃i jq . π(si jq ) ≥rpo π(t jq ). In the case of τ(a ) ∈ B, On the other hand, the deletion property and the restric- π(sθ) >rpo π(tθ) ≡ π(a θ) is trivially holds. Suppose tion by pattern are required only for stability. Hence, com- that τ(a ) B. From the condition (P), π(s) ≡ π(u), bining with Lemma 6.8 and Proposition 6.4, we are able to si p = a and k = 0. Hence π(si p θ) ≡ π(a θ). From reformulate Proposition 6.6. the induction hypothesis, π(si jq θ) ≥rpo π(t jq θ). Since Theorem 6.9: Let R be a STRS and > be a reduction order wftypeπτ (π(u)) = wftypeπτ (π(s)) = wftypeπτ (π(t)) = ∗, we on T τπ (F , V). Suppose that the following properties hold: have wftypeπτ (π(sθ)) = wftypeπτ (π(tθ)) = ∗ by Lemma 6.10. Therefore we obtain π(sθ) >rpo π(tθ) by (RPO3). π • has the marked condition for DF(R), i.e., v v# if † In [12], this condition is missing for Corollary 7.7, however root(v) ∈ DF(R) and τ(v) ∈ B. it is required in Theorem 6.8, on which the corollary is based. In • π are stable for R, i.e., for all l → r ∈ R, l π r ⇒ fact, the deletion property is necessary to guarantee the stability for lθ π rθ. pattern. IEICE TRANS. INF. & SYST., VOL.E87–D, NO.2 FEBRUARY 2004 358 Finally, we present an eﬀective and eﬃcient methods Add(x, 0) → x for proving termination. In general, π and π does not rpo Add(x, S (y)) → S (Add(x, y)) lpo satisfy the marked condition. Hence we need a suitable re- Sub(x, 0) → x striction for precedence. Sub(0, y) → 0 Sub(S (x), S (y)) → Sub(x, y) Theorem 6.12: Let π be an argument ﬁltering function and G(0, y) → y R be a STRS satisfying the following condition: G(S (x), y) → 0 Div(0, S (y)) → 0 (M) for any F ∈ DF(R), either F # is identiﬁed to F or Div(S (x), S (y)) F F # and π(F) ⊇ π(F # ). → G(Sub(y, x), S (Div(Sub(x, y), S (y)))) (P) Let l → r ∈ R, π(l) ≡ a(π(l1 ), . . . , π(ln )) and x ∈ Len(Nil) → 0 Var(π(l)). If τ(x) B then for each i either x ≡ li Len(C(x, xs)) → S (Len(xs)) or x Var(π(li )). Sum(Nil) → 0 π Sum(C(x, xs)) → Add(x, Sum(xs)) For each >∈ {>rpo , >lpo }, if R ⊆ and DP(R) ⊆ >π then R Map( f, Nil) → Nil is terminating. Map( f, C(x, xs)) → C( f (x), Map( f, xs)) F( f, xs) Proof : Thanks to Theorem 6.9 and Lemma 6.11, it suf- → Div(Sum(Map( f, xs)), Len(xs)) ﬁces to show that the condition (M) guarantees the marked condition for DF(R). Let v ≡ a(v1 , . . . , vn ) be a well- We suppose that B = {Nat, NatList, Bool}, The function formed term such that a ∈ DF(R) and τ(v) ∈ B. Since symbol Map has the type (Nat → Nat) → NatList → wftypeτ (v) = wftypeτ (v# ) = ∗, it follows from Lemma 6.8 NatList, and other symbols have usual types. We notice that that wftypeτπ (π(v)) = wftypeτπ (π(v# )) = ∗. Hence π(v) ≥rpo the normal form of F( f, [x1 , . . . , xn ]) by R3 correspond to f (x1 )+···+ f (xn ) π(v# ) and π(v) ≥lpo π(v# ). n . Then there exist 15 dependency pairs: Add# (x, S (y)), Add# (x, y) Example 6.13: Let τ(F) = (α → α) → α → α, τ(G) = Sub# (S (x), S (y)), Sub# (x, y) τ( f ) = α → α and τ(x) = α. We deﬁne STRS R2 as follows: Div# (S (x), S (y)), R2 = {F( f, F(G, x)) → F( f, G( f (F(G, x))))} G# (Sub(y, x), S (Div(Sub(x, y), S (y)))) Div (S (x), S (y)), Sub# (y, x) # Then there exist three dependency pairs: Div# (S (x), S (y)), Div# (Sub(x, y), S (y)) Div# (S (x), S (y)), Sub# (x, y) F # ( f, F(G, x)), F # ( f, G( f (F(G, x)))) Len# (C(x, xs)), Len# (xs) F # ( f, F(G, x)), f (F(G, x)) Sum# (C(x, xs)), Add# (x, Sum(xs)) F # ( f, F(G, x)), F # (G, x) Sum# (C(x, xs)), Sum# (xs) Map# ( f, C(x, xs)), f (x) Suppose that π(G) = [ ] and F # is identiﬁed to F. Then for Map# ( f, C(x, xs)), Map# ( f, xs) the rule F # ( f, xs), Div# (Sum(Map( f, xs)), Len(xs)) F # ( f, xs), Sum# (Map( f, xs)) π(F( f , F(G, x))) ≡ F( f, F(G, x)) F # ( f, xs), Map# ( f, xs) >rpo F( f, G) F # ( f, xs), Len# (xs) ≡ π(F( f, G( f (F(G, x))))) We suppose that H # is identiﬁed to H for all H ∈ F . We and for all dependency pairs deﬁne the argument ﬁltering function π by π(Sub) = [1], and deﬁne the precedence by Add S 0, Div G, Div π(F # ( f, F(G, x))) ≡ F # ( f, F(G, x)) S Sub, Len S , Sum Add, Map C and F D for any >rpo F # ( f, G) D ∈ {Div, Sum, Map, Len}. Then it is routine to check that ≡ π(F # ( f, G( f (F(G, x))))) π(l) ≥rpo π(r) for all l → r ∈ R3 and π(u# ) >rpo π(v# ) for all π(F # ( f, F(G, x))) ≡ F # ( f, F(G, x)) u# , v# ∈ DP(R3 ). Therefore R3 is terminating. >rpo f (F(G, x)) Note that above STRSs R2 and R3 are not simply ter- ≡ π( f (F(G, x))) minating, which is a diﬃcult class for proving termination. π(F # ( f, F(G, x))) ≡ F # ( f, F(G, x)) In fact, not only path orders in [8], [14] but also our path or- >rpo F # (G, x) ders cannot prove the termination of R2 and R3 . When we try ≡ π(F # (G, x)) to prove the termination of non-simply terminating STRSs, the argument ﬁltering method is very eﬀective. Moreover R3 Therefore R2 is terminating. cannot be proved by methods in [12], which has combined path orders with dependency and argument ﬁltering meth- Example 6.14: Let R3 be the following STRS: ods, because path orders in [12] requires Map is greatest KUSAKARI: HIGHER-ORDER PATH ORDERS BASED ON COMPUTABILITY 359 with respect to in order to orient rules for Map, however 1997. the requirement destroys orientation for the last rule. [2] T. Arts and J. Giesl, “Automatically proving termination where sim- pliﬁcation orderings fail,” TAPSOFT ’97, LNCS 1214, pp.261–272, 1997. 7. Concluding Remarks [3] T. Arts and J. Giesl, “Termination of term rewriting using depen- dency pairs,” Theor. Comput. Sci., vol.236, pp.133–178, 2000. A reader may think that the supplement property can be [4] F. Baader and T. Nipkow, Term Rewriting and All That, Cambridge given by adding the rule (s >rpo t ⇒ s(u) >rpo t(u)) to orig- University Press, 1998. inal one [5], that is, for well-formed terms s ≡ a(s1 , . . . , sn ) [5] N. Dershowitz, “Orderings for term-rewriting systems,” Theor. and t ≡ a (t1 , . . . , tm ), we deﬁne s >rpo t if wftypeτ (s) = Comput. Sci., vol.17, pp.279–301, 1982. wftypeτ (t) and satisfying one of the following rules: e ´ [6] J.-Y. Girard, Interpr´ tation fonctionnelle et elimination des coupures e e de l’arithm´ tique d’ordre sup´ rieur, Ph.D. Thesis, University of (RPO’1) a a , and for all j, either s >rpo t j or ∃i. si ≥rpo t j , Paris VII, 1972. (RPO’2) a = a and {s1 , . . . , sn } >mul {t1 , . . . , tm }, rpo [7] J.-P. Jouannaud and A. Rubio, “Rewrite orderings for higher-order (RPO’3) ∃i. si ≥rpo t, or terms in η-long β-normal form and the recursive path ordering,” Theor. Comput. Sci., vol.208, no.1/2, pp.33–58, 1998. (RPO’4) a(s1 , . . . , sn−1 ) >rpo a (t1 , . . . , tm−1 ) and sn ≥rpo [8] J.-P. Jouannaud and A. Rubio, “The higher-order recursive path or- tm . dering,” Proc. 14th IEEE Symposium on Logic in Computer Sci- We feel that the deﬁnition is correspond to ones in [8], [14]. ence, pp.402–411, IEEE Computer Society Press, 1999. [9] M. Iwami and Y. Toyama, “Simpliﬁcation ordering for higher-order However this deﬁnition is out of the framework in this pa- rewrite systems,” IPSJ Trans. Programming, vol.40, no.SIG 4 (PRO per, speciﬁcally, destroys the proof of Lemma 4.5. It is the 3), pp.1–10, 1999. reason why terms with functional type (ex. Add, Add(0)) [10] M. Iwami, Termination of Higher-Order Rewrite Systems, Ph.D. are not accepted in the framework in [14], although they Thesis, Japan Advanced Institute of Science and Technology, 1999. are accepted in STRSs. Note that terms Add and Add(0) e [11] S. Kamin and J.-J. L´ vy, Two Generalizations of the Recursive Path Ordering, University of Illinois at Urbana-Champaign, Unpublished are represented by λxy.Add(x, y) and λy.Add(0, y) in [8], manuscript, 1980. [14]. We overcome the problem by adding the restriction [12] K. Kusakari, “On proving termination of term rewriting systems wftypeτ (s) = ∗ in (RPO1). with higher-order variables,” IPSJ Trans. Programming, vol.42, Unlike path orders in [14], our path orders can com- no.SIG 7 (PRO 11), pp.35–45, July 2001. bine well with the dependency pair and the argument ﬁlter- [13] T. Nipkow, “Higher-order critical pairs,” Proc. 6th IEEE Symp. ing methods. In fact, the recursive path order in [14] guar- Logic in Computer Science, pp.342–349, IEEE Computer Society Press, 1991. antees that l >rpo d β r ⇒ ∃u. lσ ↓>rpo u β rσ ↓. So we [14] F. Raamsdonk, “On termination of higher-order rewriting,” Proc. must delicately analyze relations between the premise and 12th Int. Conf. on Rewriting Techniques and Applications, LNCS the consequence after argument ﬁltering, in order to gener- 2051 (RTA2001), pp.261–275, 2001. ate weak reduction orders by the argument ﬁltering method. [15] M. Sakai, Y. Watanabe, and T. Sakabe, “An extension of dependency We feel that it is not so easy. pair method for proving termination of higher-order rewrite sys- As a model of functional programs, the polymorphic tems,” IEICE Trans. Inf. & Syst., vol.E84-D, no.8, pp.1025–1032, Aug. 2001. types is more useful than simple types. It is easy to de- [16] M. Sakai and K. Kusakari, “On new dependency pair method for ﬁne polymorphic term rewriting systems (PTRSs) by using proving termination of higher-order rewrite systems,” The Interna- polymorphic types instead of simple types. Then we should tional Workshop on Rewriting in Proof and Computation (RPC ’01), change the deﬁnition of reduction relation. For example, pp.176–187, 2001. letting PTRS R = {I(x) → x, App( f, x) → f (x)}. In the [17] M. Sakai and K. Kusakari, “On proving termination of higher-order rewrite systems by dependency pair technique,” The First Interna- system, we have tional Workshop on Higher-Order Rewriting (HOR ’02), p.25, 2002. I( f, x) ← App(I( f ), x) → App( f, x) → f (x). [18] W.W. Tait, “Intensional interpretation of functionals of ﬁnite type,” J. Symb. Log., vol.32, pp.198–212, 1967. Hence R is not conﬂuent, which is too restrictive as model. In order to reduce I( f, x) to f (x) we need to apply the ﬁrst rule in the suﬃx context (x) which has the hole at the root position. Hence, in [12], we deﬁne the reduction relation as s → t iﬀ s ≡ C[S [lθ]] and t ≡ C[S [rθ]], where S [ ] is R a suﬃx context. Fortunately, our path orders are closed to Keiichirou Kusakari received B.E. from suﬃx contexts, that is, our path orders have the supplement Tokyo Institute of Technology in 1994, M.E. property. On the other hand, path orders in [12] does not and D.E. from Japan Advanced Institute of Sci- ence and Technology (JAIST) in 1996 and 2000. have the supplement property. Hence our path orders may From 2000 to 2003, he had been a research asso- gain an advantage over ones in [12], when we try to prove ciate of Research Institute of Electrical Commu- termination of PTRSs. nication (RIEC), Tohoku University. He is cur- rently an assistant professor of Graduate School References of Information Science, Nagoya University. His research interests include term rewriting sys- [1] T. Arts, Automatically Proving Termination and Innermost Normal- tems, program theory, and automated theorem ization of Term Rewriting Systems, Ph.D. Thesis, Univ. of Utrecht, proving. He is a member of IPSJ and JSSST.