Top Banner
Simple Termination of Context-Sensitive Rewriting Bernhard Gramlich Institut f ¨ ur Computersprachen Technische Universit¨ at Wien Favoritenstr. 9, A-1040 Wien, Austria [email protected] Salvador Lucas DSIC Universidad Polit´ ecnica de Valencia Camino de Vera s/n, 46022 Valencia, Spain [email protected] Abstract Simple termination is the (often indirect) basis of most existing au- tomatic techniques for proving termination of rule-based programs (e.g., Knuth-Bendix, polynomial, or recursive path orderings, but also DP-simple termination, etc.). An interesting framework for such programs is context-sensitive rewriting (CSR) that provides a bridge between the abstract world of general rewriting and the (more) applied setting of declarative specification and program- ming languages (e.g., OBJ*, CafeOBJ, ELAN, and Maude). In these languages, certain replacement restrictions can be specified in programs by the so-called strategy annotations. They may sig- nificantly improve the computational properties of programs, es- pecially regarding their termination behaviour. Context-sensitive rewriting techniques (in particular, the methods for proving termi- nation of CSR) have been proved useful for analyzing the properties of these programs. This entails the need to provide implementable methods for proving termination of CSR. Simplification orderings (corresponding to the notion of simple termination) which are well- known in term rewriting (and have nice properties) are, then, natu- ral candidates for such an attempt. In this paper we introduce and investigate a corresponding notion of simple termination of CSR. We prove that our notion actually provides a unifying framework for proving termination of CSR by using standard simplification or- derings via the existing (transformational) methods, and also cov- ers CSRPO, a very recent proposal that extends the recursive path ordering (RPO) (a well-known simplification ordering) to context- sensitive terms. We also introduce polynomial orderings for dealing with (simple) termination of CSR. Finally, we also give criteria for the modularity of simple termination, for the case of disjoint unions as well as for constructor-sharing rewrite systems. Work partially supported by ¨ OAD-Programm “Acciones In- tegradas 2002-2003” No. 3/2002, WTZ-B¨ uro. Work partially supported by CICYT TIC2001-2705-C03-01, Ac- ciones Integradas HU 2001-0019, HI 2000-0161, HA 2001-0059, and Generalitat Valenciana GV01-424. Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. To copy otherwise, to republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Third ACM SIGPLAN Workshop on Rule-Based Programming (RULE’02) Pitts- burgh, PA, October 5, 2002 Copyright 2002 ACM 1-58113-604-4/02/10 ...$5.00 Categories and Subject Descriptors D1.1 [Software]: Applicative (Functional) Programming; D3.1 [Programming Languages]: Formal Definitions and Theory (D.2.1, F.3.1, F.3.2, F.4.2, F.4.3); F3.1 [Theory of Computation]: Specifying and Verifying and Reasoning about Programs (D.2.1, D.2.4, D.3.1, E.1); F3.2 [Theory of Computation]: Semantics of Programming Languages (D.3.1); F4.2 [Theory of Computation]: Grammars and Other Rewriting Systems (D.3.1); I.1.3 [Computing Methodologies]: Languages and Systems—Evaluation strategies General Terms Design, Languages, Theory, Verification Keywords Context-sensitive rewriting, declarative programming, evaluation strategies, automatic proofs of termination; modular program anal- ysis and verification. 1 Introduction Well-founded orderings (i.e., orderings allowing no infinite de- creasing sequence) provide a suitable basis for proving termination in a number of programming languages and computational systems. For instance, in term rewriting systems (TRS’s) a proof of termina- tion can be achieved if we are able to find a (monotone and stable) well-founded ordering on terms (i.e., a reduction ordering) such that l r for every rule l r of the rewrite system [10, 40]. In practice, if we want to implement a tool for proving termination of a TRS R , we need to make this problem decidable. It is well-known that termination of TRSs is an undecidable problem, even for TRSs containing only one rule [7]. Hence, we can only provide effective approaches (which yield decidable termination criteria) for certain classes of systems. Simplification orderings are those monotone and stable orderings satisfying the following subterm property: for each term t , t s for every proper subterm s of t [8]. If termina- tion of a TRS R can be proved by using a simplification ordering, then we say that R is simply terminating. Although simple termi- nation is also undecidable (see [33]) it covers most usual automati- zable orderings for proving termination of rewriting (e.g., recursive path orderings (rpo [9]), Knuth-Bendix orderings (kbo [23]), and polynomial orderings (poly [26]), see [37] for a survey on simpli- fication orderings). Moreover, simple termination has interesting properties regarding modularity: in contrast to the general case, simple termination is modular for disjoint, constructor-sharing, and (some classes of) hierarchical unions of TRS’s [36].
13

Simple termination of context-sensitive rewriting

May 09, 2023

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Simple termination of context-sensitive rewriting

Simple Termination of Context-Sensitive Rewriting

Bernhard Gramlich�

Institut fur ComputersprachenTechnische Universitat Wien

Favoritenstr. 9, A-1040 Wien, Austria

[email protected]

Salvador Lucas†

DSICUniversidad Politecnica de Valencia

Camino de Vera s/n, 46022 Valencia, Spain

[email protected]

Abstract

Simple termination is the (often indirect) basis of most existing au-tomatic techniques for proving termination of rule-based programs(e.g., Knuth-Bendix, polynomial, or recursive path orderings, butalso DP-simple termination, etc.). An interesting framework forsuch programs is context-sensitive rewriting (CSR) that providesa bridge between the abstract world of general rewriting andthe(more) applied setting of declarative specification and program-ming languages (e.g.,OBJ*, CafeOBJ, ELAN, and Maude). Inthese languages, certain replacement restrictions can be specifiedin programs by the so-calledstrategy annotations. They may sig-nificantly improve the computational properties of programs, es-pecially regarding their termination behaviour. Context-sensitiverewriting techniques (in particular, the methods for proving termi-nation of CSR) have been proved useful for analyzing the propertiesof these programs. This entails the need to provide implementablemethods for proving termination of CSR.Simplification orderings(corresponding to the notion ofsimple termination) which are well-known in term rewriting (and have nice properties) are, then, natu-ral candidates for such an attempt. In this paper we introduce andinvestigate a corresponding notion of simple termination of CSR.We prove that our notion actually provides a unifying frameworkfor proving termination of CSR by using standard simplification or-derings via the existing (transformational) methods, and also cov-ers CSRPO, a very recent proposal that extends the recursivepathordering (RPO) (a well-known simplification ordering) to context-sensitive terms. We also introduce polynomial orderings for dealingwith (simple) termination of CSR. Finally, we also give criteria forthe modularity of simple termination, for the case of disjoint unionsas well as for constructor-sharing rewrite systems.�Work partially supported byOAD-Programm “Acciones In-tegradas 2002-2003” No. 3/2002, WTZ-Buro.†Work partially supported by CICYT TIC2001-2705-C03-01, Ac-ciones Integradas HU 2001-0019, HI 2000-0161, HA 2001-0059,and Generalitat Valenciana GV01-424.

Permission to make digital or hard copies of all or part of this work for personal orclassroom use is granted without fee provided that copies are not made or distributedfor profit or commercial advantage and that copies bear this notice and the full citationon the first page. To copy otherwise, to republish, to post on servers or to redistributeto lists, requires prior specific permission and/or a fee.Third ACM SIGPLAN Workshop on Rule-Based Programming (RULE’02) Pitts-burgh, PA, October 5, 2002Copyright 2002 ACM 1-58113-604-4/02/10 ...$5.00

Categories and Subject Descriptors

D1.1 [Software]: Applicative (Functional) Programming; D3.1[Programming Languages]: Formal Definitions and Theory(D.2.1, F.3.1, F.3.2, F.4.2, F.4.3); F3.1 [Theory of Computation]:Specifying and Verifying and Reasoning about Programs (D.2.1,D.2.4, D.3.1, E.1); F3.2 [Theory of Computation]: Semantics ofProgramming Languages (D.3.1); F4.2 [Theory of Computation]:Grammars and Other Rewriting Systems (D.3.1); I.1.3 [ComputingMethodologies]: Languages and Systems—Evaluation strategies

General Terms

Design, Languages, Theory, Verification

Keywords

Context-sensitive rewriting, declarative programming, evaluationstrategies, automatic proofs of termination; modular program anal-ysis and verification.

1 Introduction

Well-founded orderings (i.e., orderings allowing no infinite de-creasing sequence) provide a suitable basis for proving terminationin a number of programming languages and computational systems.For instance, in term rewriting systems (TRS’s) a proof of termina-tion can be achieved if we are able to find a (monotone and stable)well-founded ordering> on terms (i.e., areduction ordering) suchthat l > r for every rulel ! r of the rewrite system [10, 40]. Inpractice, if we want to implement a tool for proving termination ofa TRSR , we need to make this problem decidable. It is well-knownthat termination of TRSs is an undecidable problem, even forTRSscontaining only one rule [7]. Hence, we can only provide effectiveapproaches (which yield decidable termination criteria) for certainclasses of systems.Simplification orderingsare those monotoneand stable orderings> satisfying the following subterm property:for each termt, t > s for every proper subtermsof t [8]. If termina-tion of a TRSR can be proved by using a simplification ordering,then we say thatR is simply terminating. Although simple termi-nation is also undecidable (see [33]) it covers most usual automati-zable orderings for proving termination of rewriting (e.g., recursivepath orderings (rpo [9]), Knuth-Bendix orderings (kbo [23]), andpolynomial orderings (poly [26]), see [37] for a survey on simpli-fication orderings). Moreover, simple termination has interestingproperties regarding modularity: in contrast to the general case,simple termination is modular for disjoint, constructor-sharing, and(some classes of) hierarchical unions of TRS’s [36].

Page 2: Simple termination of context-sensitive rewriting

obj EXAMPLE issorts Nat LNat .op 0 : -> Nat .op s : Nat -> Nat [strat (1)] .op nil : -> LNat .op cons : Nat LNat -> LNat [strat (1)] .op from : Nat -> LNat [strat (1 0)] .op sel : Nat LNat -> Nat [strat (1 2 0)] .op first : Nat LNat -> LNat [strat (1 2 0)] .vars X Y : Nat .var Z : LNat .eq sel(s(X),cons(Y,Z)) = sel(X,Z) .eq sel(0,cons(X,Z)) = X .eq first(0,Z) = nil .eq first(s(X),cons(Y,Z)) = cons(Y,first(X,Z)) .eq from(X) = cons(X,from(s(X))) .

endo

Figure 1. Strategy annotations in OBJ

Context-sensitive rewriting (CSR [28]) is a restriction ofrewritingwhich forbids reductions on selected arguments of functions. A re-placement map µ:F ! P (N) satisfyingµ( f )�f1; : : : ;kg, for eachk-ary symbolf of the signatureF discriminates, for each symbol ofthe signature, the argument positions on which replacements are al-lowed [28]. In this way, the termination behavior of rewriting com-putations can beimproved, e.g., by pruning all the infinite rewritesequences.

In eager programming languages such asOBJ2 [14], OBJ3 [20],CafeOBJ [15], and Maude [6], it is possible to specify the so-called strategy annotationsfor controlling the execution of pro-grams. For instance, theOBJ3 program in Figure 1 (borrowed from[2]) specifies anexplicitstrategy annotation(1) for the list construc-tor conswhich disables replacements on the second argument (lazylists, see Appendix C.5 of [20]). If we collect asµ( f ) the posi-tive indices appearing in the strategy annotation for each symbolf in a givenOBJ program1, we can use CSR to provide a frame-work for analyzing and ensuring essential computational proper-ties such as termination, correctness and completeness (regardingthe usual semantics: head-normalization, normalization,functionalevaluation, and infinitary normalization) of programs using strat-egy annotations, see [1, 2, 29, 30, 31]. In particular, terminationof (innermost) context-sensitive rewriting has been recently relatedto termination of such languages [29, 30]. For instance, we canprove termination of theOBJ3 program in Figure 1 by using thetechniques for proving termination of CSR, see Examples 5 and 7below.

Termination of CSR and its applications has been studied in anum-ber of papers [5, 13, 16, 19, 22, 27, 32, 38, 39]. In most of thesepapers (e.g., [13, 16, 19, 27, 38, 39]) termination of CSR is stud-ied in a transformational setting, namely by transforming agivencontext-sensitive rewrite system (CSRS i.e., a pair(R ;µ) consist-ing of a TRSR and a replacement mapµ) into an ordinary TRSsuch that termination of the latter implies termination of the formeras CSRS. Unfortunately, such transformations typically use newsymbols and rules that introduce a loss of structure and intuition,due to the encoding of the context-sensitive control in the originalsystem by such new elements. They can unnecessarily complicatethe proofs of termination and make standard techniques for easingsuch proofs (e.g., modular approaches) infeasible. Only recently,some work has been devoted to thedirect analysis of terminationand related properties of CSR: regarding the definition of suitable

1As in [20], byOBJ we meanOBJ2, OBJ3, CafeOBJ, or Maude.

orderings for proving termination of CSR [5], and concerning themodularity of termination and related properties [22]. Moreover,the abstract properties of termination of CSR remain almostunex-plored (with the notable exception of Zantema’s work [39]).In-deed, all these lines of work appear to be promising and suggest tofurther investigatedirect methods for achieving simpler proofs oftermination of CSR.

In the remainder of the paper, we first introduce the necessary back-ground on CSR. Then we introduce and discuss simple terminationof CSR in Section 3. In Section 4 we show that in all cases wherethe transformational approaches yield simple termination, the orig-inal CSRS is simply terminating, too. Therefore, all existing trans-formations for proving termination of CSR can also be used forproving simple termination of CSRS’s. Then, in Section 5 we dealwith two direct approaches for proving termination of CSR. Weshow thatCSRPO-termination[5] in fact yields simple termina-tion, and we also cover simple termination proofs via polynomialorderings. Finally, some modularity results concerning simple ter-mination are presented in Section 6.2

As a motivating example for our work consider the following.

Example 1.Consider the following one-rule TRS which is con-tained in the famous example of Toyama.

f (a;b;x)! f (x;x;x)It is well known that this TRS is not simply terminating. However,by forbidding reductions on the first and second argument, i.e., bydefiningµ( f ) = f3g, we obtain a ‘simply terminating’ behavior (re-garding CSR) which can be easily proved by using a polynomialordering for CSR, see Example 10 below.

2 Preliminaries

2.1 Basics

Subsequently we will assume in general some familiarity with thebasic theory of term rewriting (cf. e.g. [3], [12]). Given a set A,P (A) denotes the set of all subsets ofA. Given a binary relationRon a setA, we denote the transitive closure byR+ and its reflexiveand transitive closure byR�. We say thatR is terminatingiff thereis no infinite sequencea1 R a2 R a3 � � �. Throughout the paper,Xdenotes a countable set of variables andF denotes a signature, i.e.,a set of function symbolsff;g; : : :g, each having a fixed arity givenby a mappingar : F ! N. The set of terms built fromF andX is T (F ;X ). A term is said to be linear if it has no multipleoccurrences of a single variable. Terms are viewed as labelled treesin the usual way. Positionsp;q; : : : are represented by chains ofpositive natural numbers used to address subterms oft. We denotethe empty chain byΛ. The set of positions of a termt is Pos(t).Positions of non-variable symbols int are denoted asPosF (t), andPosX (t) are the positions of variables. The subterm at positionp oft is denoted astjp andt[s℄p is the termt with the subterm at positionp replaced bys. The symbol labelling the root oft is denoted asroot(t).A rewrite rule is an ordered pair(l ; r), written l ! r, with l ; r 2T (F ;X ), l 62 X andV ar(r) � V ar(l). The left-hand side (lhs)of the rule isl andr is the right-hand side (rhs). A TRS is a pairR = (F ;R) whereR is a set of rewrite rules.L(R ) denotes the set

2For the sake of readability, some proofs have been moved tothe appendix.

Page 3: Simple termination of context-sensitive rewriting

of lhs’s of R . An instanceσ(l) of a lhs l of a rule is a redex. Theset of redex positions int is PosR (t). A TRSR is left-linear iffor all l 2 L(R ), l is a linear term. Given TRSsR = (F ;R) andR 0 = (F 0;R0), we letR [R 0 be the TRS(F [F 0;R[R0).A term t 2 T (F ;X ) rewrites tos (at positionp), written t

p!R s(or justt ! s), if tjp = σ(l) ands= t[σ(r)℄p, for some ruleρ : l !r 2R, p2 Pos(t) and substitutionσ. A TRS is terminating if! isterminating.

2.2 Context-Sensitive Rewriting

Given a signatureF , a mappingµ : F ! P (N) is a replacementmap(or F -map) if for all f 2 F ; µ( f ) � f1; : : : ;ar( f )g [28]. LetMF (or MR if R = (F ;R) determines the considered symbols),the set of allF -maps. For the sake of simplicity, we will applya replacement mapµ2 MF on symbolsf 2 F 0 of any signatureF 0 by assuming thatµ( f ) = ? whenever f 62 F . The inclusionordering� on P (N) extends to an orderingv on MF : µv µ0 iffor all f 2 F , µ( f ) � µ0( f ). Thus,µv µ0 means thatµ considersless positions thanµ0 (for reduction). We also say thatµ is morerestrictive thanµ0. The least upper bound (lub), t of µ;µ0 2MF aregiven by(µtµ0)( f ) = µ( f )[µ0( f ). A replacement mapµ specifiesthe argumentpositions which can be reduced for eachsymbolinF . Accordingly, the set ofµ-replacing positionsPosµ(t) of t 2T (F ;X ) is: Posµ(t) = fΛg, if t 2 X and

Posµ(t) = fΛg[ [i2µ(root(t)) i:Posµ(tji);

if t 62 X . The set of positions of replacing redexes int isPosµR(t) =

PosR (t)\Posµ(t). A context-sensitive rewrite system (CSRS) isa pair(R ;µ), whereR is a TRS andµ is a replacement map. Incontext-sensitive rewriting(CSR [28]), we (only) contractreplac-ing redexes: t µ-rewrites tos, written t ,!µ s (or just t ,! s), if

tp!R s and p2 Posµ(t). A CSRS(R ;µ) is terminating if,!µ is

terminating.

3 Simple Termination of CSR

Zantema has provided an algebraic characterization of terminationof CSR [39]. As for standard rewriting, he proves that terminationof CSR is fully captured by the so-calledµ-reduction orderings, i.e.,well-founded, stable orderings> such that, for allp 2 Posµ(C),C[s℄p >C[t℄p whenevers> t (µ-monotonicity). Then, a TRSR =(F ;R) is µ-terminating if and only if there is aµ-reduction ordering> which iscompatiblewith the rules ofR , i.e., for alll ! r 2R, l >r ([39, Proposition 1]). He also shows thatµ-reduction ordering canbe defined by means of (well-founded)µ-monotoneF -algebras. An(ordered)F -algebra, is a triple(A;FA;>), whereA is a set,FA is aset of mappingsfA : Ak ! A for each f 2 F wherek = ar( f ), and> is a (strict) ordering onA. Given f 2 F , we say thatfA : Ak ! Ais µ-monotone if for alla;b2 A such thata> b, we have that

fA(a1; : : : ;ai�1;a; : : : ;ak)> fA(a1; : : : ;ai�1;b; : : : ;ak)for all a1; : : : ;ak 2 A and i 2 µ( f ). A F -algebraA = (A;FA;>) is µ-monotone if for all f 2 FA, f is µ-monotone. AF -algebraA = (A;FA;>) is well-founded if> is well-founded. Fora given valuation mappingα : X ! A, the evaluation mapping[α℄ : T (F ;X )! A is inductively defined by[α℄(x) = α(x) if x2 Xand [α℄( f (t1; : : : ;tk)) = fA([α℄(t1); : : : ; [α℄(tk)) for x 2 X , f 2 F ,t1; : : : ;tk 2 T (F ;X ). We writet >A s if and only if [α℄(t)> [α℄(s)for all α : X ! A. Then,>A is a reduction ordering on terms for

every well-foundedµ-monotoneF -algebra(A;FA;>) ([39, Propo-sition 2]). We use these notions in the following.

Given a signatureF , we consider the TRSEmb(F ) =(F ;f f (x1; : : : ;xk)! xi j f 2 F ; i 2 f1; : : : ;ar( f )gg). A TRSR issimply terminatingif R [Emb(F ) is terminating. Regarding CSR,the most obvious extension of this notion (a CSRS(R ;µ) is simplyterminating if(R [Emb(F );µ) is terminating) is not appropriate:

Example 2.Consider the TRSR (wherea is a constant):

a! c(a)with µ(c) =?. The CSRS(R ;µ) is clearly terminating; however,(R [Emb(F );µ) (whereEmb(F ) has a single rulec(x) ! x) isnot: a ,! c(a) ,! a ,! ���.Formally, in contrast to TRS’s where termination of!R impliestermination of(!R [>st) (with >st being the proper subterm or-dering), this property does not hold for CSRS’s any more, i.e., ter-mination of ,!R in general does not imply termination of(,!R[>st).The problem is that the projections inEmb(F ) should notmake those arguments reducible which are not reducible us-ing the replacement mapµ. Therefore, we defineEmbµ(F ) =(F ;f f (x1; : : : ;xk)! xi j f 2 F ; i 2 µ( f )g) and propose the follow-ing.

DEFINITION 1. A CSRS(R ;µ) is simply terminating if (R [Embµ(F );µ) is terminating.

Obviously, ifEmbµ>(F ) = Emb(F ), then simple termination asin Definition 1 and the standard notion of simple terminationofTRS’s coincide (as one would expect). Furthermore, any simplyterminating TRSR , viewed as CSRS(R ;µ) for arbitraryµ2 MR ,is also simply terminating (sinceEmbµ(F ) is a subset ofEmb(F )for all µ). Finally, we note that ifµv µ0, thenEmbµ(F ) is includedin Embµ0(F ). Hence, simple termination of(R ;µ0) implies simpletermination of(R ;µ) in this case.

Simplification orderings are the algebraic (indeed originating)counterpart of simple termination. A simplification ordering isa monotonic, stable ordering on terms which additionally satis-fies the following ‘subterm’ property: for allt 2 T (F ;X ) andp2 Pos(t)�fΛg; t > tjp. It is well-known that simplification or-derings are well-founded (for terms over finite signatures). Thus,any simplification ordering is a reduction ordering, and hence it issuitable for (trying to) prove termination of a TRSR by just com-paring the left- and right-hand sides of its rules.

The following natural generalization of simplification orderings im-mediately arises.

DEFINITION 2. Let F be a signature and µ2 MF . A µ-monotonic, stable ordering> is a µ-simplification ordering if, forall t 2 T (F ;X ); p2 Posµ(t)�fΛg; t > tjp (µ-subterm property).

Unfortunately, in (sharp) contrast with the standard case,µ-simplification orderings are not well-founded any more (in general).

Example 3.Consider the signature consisting of the constanta andthe unary symbolc. If we chooseµ(c) =?, then the binary relation> consisting of pairsf(cn(a);cn+1(a)) j n� 0g is a µ-monotonestrict ordering and has theµ-subterm property. However, it admits

Page 4: Simple termination of context-sensitive rewriting

an infinite sequence

a> c(a)> � � �> cn(a)> � � �Nevertheless, Definition 2 characterizes the notion of simple termi-nation of Definition 1 in the following (obvious) sense.

THEOREM 1. A CSRS(R ;µ) is simply terminating if and only ifthere is a well-founded µ-simplification ordering> such that forevery rule l! r 2 R, l > r.

PROOF. If (R ;µ) is simply terminating, then the CSRS(R [Embµ(F );µ), whereR = (F ;R), is terminating and,!+ is a µ-reduction ordering which clearly satisfies theµ-subterm property(due to the presence of the corresponding rules inEmbµ(F )).Then, ,!+ is a µ-simplification ordering. Obviously, we havel ,!+ r for every rulel ! r 2R.

On the other hand, assume that> is a well-foundedµ-simplificationordering such thatl > r, for every rulel ! r 2 R. Since it is aµ-simplification ordering,f (x1; : : : ;xk) > xi for all i 2 µ( f ) and f 2F . Hence,> is a µ-reduction ordering which is compatible withR [Embµ(F ), i.e., which orients all rules from left to right. Hence,R is simplyµ-terminating.

4 Proving Simple Termination of CSR

Termination of CSRS’s(R ;µ) is usually proved by demonstratingterminationof a transformed TRSR µ

Θ obtained fromR andµ byusing a transformation3 Θ [13, 16, 17, 27, 38, 39]. A transformationΘ is

1. correct (regarding (simple) termination) if (simple) termina-tion ofR µ

Θ implies (simple) termination of(R ;µ) for all TRSR and replacement mapµ2MR .

2. complete(regarding (simple) termination) if (simple) termina-tion of (R ;µ) implies (simple) termination ofR µ

Θ for all TRSR and replacement mapµ2MR .

The simplest (and trivial) correct transformation for proving termi-nation of CSRS’s is the identity: ifR µ

ID = R is terminating, then(R ;µ) is terminating for every replacement mapµ.

Here, we are interested in proving simple termination of CSRS’s byusing existing transformations. According to this goal in mind, wereview the main (non-trivial) correct transformations forprovingtermination of CSR regarding their suitability for provingsimpletermination of CSR.

4.1 The Contractive Transformation

Let F be a signature andµ2 MF be a replacement map. With thecontractive transformation [27], the non-µ-replacing arguments ofall symbols inF areremovedand a new,µ-contractedsignatureF µ

Lis obtained (possibly reducing thearity of symbols). The functionτµ : T (F ;X )! T (F µ

L ;X ) dropsthe non-replacing immediate sub-terms of a termt 2 T (F ;X ) and constructs a ‘µ-contracted’ term byjoining the (also transformed) replacing arguments below the cor-responding operator ofF µ

L . A CSRS(R ;µ), whereR = (F ;R) isµ-contracted intoR µ

L = (F µL ;fτµ(l)! τµ(r) j l ! r 2Rg). Accord-

3Seehttp://www.dsic.upv.es/users/elp/slucas/mutermfor a tool,MU-TERM 1.0, that implements these transformations.

ing to this definition, it is not difficult to see thatR µL[Emb(F µ

L ) =(R [Embµ(F ))µL. Thus, we have the following:

THEOREM 2. Let (R ;µ) be a CSRS. IfR µL is simply terminating,

then(R ;µ) is simply terminating.

PROOF. If R µL is simply terminating, thenR µ

L[Emb(F µL ) = (R [

Embµ(F ))µL is terminating. Hence,(R [Embµ(F );µ) is terminat-ing, i.e.,(R ;µ) is simply terminating.

Example 4.Consider the following CSRS which can be used toobtain (asfirst(n,terms(1))) the first n terms of the series that ap-proximatesπ2=6 [31]:

R :

sqr(0)! 0sqr(s(x))! s(sqr(x)+dbl(x))

dbl(0)! 0dbl(s(x))! s(s(dbl(x)))

0+x! xs(x)+y! s(x+y)

f irst(0;x)! [℄f irst(s(x);y : z)! y : f irst(x;z)

terms(n)! recip(sqr(n)) : terms(s(n))with µ(:) = f1g andµ( f ) = f1; : : : ;kg for any otherk-ary symbolf . Then,

RµL :

sqr(0)! 0sqr(s(x))! s(sqr(x)+dbl(x))

dbl(0)! 0dbl(s(x))! s(s(dbl(x)))

0+x! xs(x)+y! s(x+y)

f irst(0;x)! [℄f irst(s(x); : (y))! : (y)

terms(n)! : (recip(sqr(n)))is (simply) terminating: use anrpo based on precedence4

terms�F :; recip;sqr; sqr�F dbl;+ �F s; and first�F [] :Hence,(R ;µ) is simply terminating.

The contractive transformation only works well withµ-conserva-tive TRSs, i.e., satisfying thatV arµ(r) � V arµ(l) for every rulel ! r of R [27]; otherwise, extra variables will appear in a rule ofR

µL which thus would become non-terminating. Let

CoCMR = fµ2CMR j for all l ! r in R ;V arµ(r)� V arµ(l)gThat is: CoCMR contains the replacement mapsµ 2 CMR thatmakeR µ-conservative [32].

THEOREM 3. [32] LetR be a left-linear TRS and µ2CoCMR . If(R ;µ) is terminating, thenR µL is terminating.

Hence, we can use the contractive transformation to fully charac-terize simple termination of CSR in restricted cases.

THEOREM 4. Let R = (F ;R) be a left-linear TRS and µ2CoCMR . Then,(R ;µ) is simply terminating if and only ifR µ

L issimply terminating.

4A precedence�F is a quasi-ordering (i.e., a reflexive and tran-sitive relation) on the symbols of the signatureF .

Page 5: Simple termination of context-sensitive rewriting

PROOF. The if part is Theorem 2. For the only if part, assume that(R ;µ) is simply terminating. Then,(R [Embµ(F );µ) is termi-nating and, by Theorem 3,(R [Embµ(F ))µL is terminating. Since(R [Embµ(F ))µL = R µ

L [Emb(F µL ), R µ

L [Emb(F µL ) is terminat-

ing, henceR µL is simply terminating.

4.2 Zantema’s Transformation

Zantema’s transformationmarks the non-replacing argumentsoffunction symbols (disregarding their positions within theterm)[39]. Given R = (F ;R) and µ 2 MF , R µ

Z = (F [ F 0 [factivateg;RµZ) whereRµ

Z consists of two parts. The first part resultsfrom R by replacing every function symbolf occurring in a left orright-hand side withf 0 (a fresh function symbol of the same arityas f which, then, is included inF 0) if it occurs in a non-replacingargumentof the function symbol directly above it. These new func-tion symbols are used to block further reductions at this position. Inaddition, if a variablex occurs in a non-replacing position in thelhsl of a rewrite rulel ! r, then all occurrences ofx in r are replacedby activate(x). Here,activateis a new unary function symbol whichis used to activate blocked function symbols again.

The second part ofRµZ consists of rewrite rules that are needed for

blocking and unblocking function symbols:

f (x1; : : : ;xk) ! f 0(x1; : : : ;xk)activate( f0(x1; : : : ;xk)) ! f (x1; : : : ;xk)

for every f 0 2 F 0, together with the ruleactivate(x)! x Again,we note that, since(Embµ(F ))µZ = Embµ(F )[factivate(x)! xgandEmbµ(F )� Emb(F µ

Z ), we have thatR µZ[Emb(F µ

Z ) = (R [Embµ(F ))µZ[Emb(F µ

Z ). Thus, we have:

THEOREM 5. Let (R ;µ) be a CSRS. IfR µZ is simply terminating,

then(R ;µ) is simply terminating.

Example 5.The following CSRS

R :

sel(0;x : y)! xsel(s(x);y : z)! sel(x;z)

f irst(0;x)! [℄f irst(s(x);y : z)! y : f irst(x;z)

f rom(x)! x : f rom(s(x))with µ(:) = f1g andµ( f ) = f1; : : : ;kg for any otherk-ary symbolf corresponds to theOBJ3 program in Figure 5 (we use: and []instead ofconsandnil respectively). Then,

RµZ :

sel(0;x : y)! xsel(s(x);y : z)! sel(x;activate(z))

f irst(0;x)! [℄f irst(s(x);y : z)! y : f irst 0(x;activate(z))

f rom(x)! x : f rom0(s(x))f rom(x)! f rom0(x)

activate( f rom0(x))! f rom(x)f irst(x;y)! f irst 0(x;y)

activate( f irst 0(x;y))! f irst(x;y)activate(x)! x

is simply terminating: use therpo which is based on prece-dencesel�F activate=F first �F from; :;first’; [] and from�F:; from’;s, and givessel the usual lexicographic status. Hence,(R ;µ) is simply terminating.

In [13], Ferreira and Ribeiro propose a variant of Zantema’strans-formation which has been proved strictly more powerful thanZan-

tema’s one (see [19]). Again,R µFR has two parts. The first part

results from the first part ofR µZ by marking all function sym-

bols (exceptactivate) which occur below an already marked sym-bol. Therefore, all function symbols of non-replacing subterms aremarked. The second part consists of the ruleactivate(x)! x plusthe rules:

f (x1; : : : ;xk) ! f 0(x1; : : : ;xk)activate( f0(x1; : : : ;xk)) ! f ([x1℄ f

1; : : : ; [xk℄ fk)

for every f 2 F for which f 0 appears in the first part ofR µFR, where[t℄ f

i = activate(t)if i 2 µ( f ) and [t℄ fi = t otherwise. They also in-

clude rules

activate( f(x1; : : : ;xk))! f ([x1℄ f1; : : : ; [xk℄ f

k)for k-ary symbols f where f 0 doesnot appear in the first part ofR

µFR. However, Giesl and Middeldorp have recently shown that

these rules are not necessary for obtaining a correct transformation[19]. Since we also haveR µ

FR[Emb(F µFR) = (R [Embµ(F ))µFR[

Emb(F µFR), this transformation is similar to Zantema’s one regard-

ing simple termination, i.e., we have the following:

THEOREM 6. Let (R ;µ) be a CSRS. IfR µFR is simply terminating,

then(R ;µ) is simply terminating.

4.3 Giesl and Middeldorp’s Transformations

Giesl and Middeldorp introduced a transformation that explicitlymarks the replacing positions of a term (by using a new symbolactive). Given a TRSR = (F ;R) andµ2 MF , the TRSR µ

GM =(F [factive;markg;RµGM) consists of the following rules (for all

l ! r 2R and f 2 F ):

active(l) ! mark(r)mark( f(x1; : : : ;xk)) ! active( f([x1℄ f ; : : : ; [xk℄ f ))

active(x) ! x

where[xi ℄ f = mark(xi ) if i 2 µ( f ) and[xi ℄ f = xi otherwise [16]. Wehave the following.

THEOREM 7. Let(R ;µ) be a CSRS. IfR µGM is simply terminating,

then(R ;µ) is simply terminating.

In [16], Giesl and Middeldorp suggest a slightly different presenta-tion of R µ

mGM of the previous transformation. In this presentation,symbolactiveis not used anymore. However, we have proved thatboth transformations are equivalent regarding simple termination,i.e.,R µ

GM is simply terminating if and only ifR µmGM is [32]. Thus,

Theorem 7 also holds forR µmGM.

Giesl and Middeldorp also introduced a transformationR µC which

is complete, i.e., everyµ-terminating TRS is transformed into a ter-minating TRSR µ

C [16].

Given a TRSR = (F ;R) and a replacement mapµ, the TRSR µC =(F [f f 0 j f 2F ^ar( f )> 0g[factive;mark;ok; proper; topg;Rµ

C)consists of the following rules (see [16] for a more detailedexpla-nation): for alll ! r 2R, f 2 F such thatk= ar( f )> 0, i 2 µ( f ),

Page 6: Simple termination of context-sensitive rewriting

and constantsc2 F ,

active(l) ! mark(r)active( f(x1; : : : ;xi ; : : : ;xk)) ! f 0(x1; : : : ;active(xi); : : : ;xk)f 0(x1; : : : ;mark(xi ); : : : ;xk) ! mark( f(x1; : : : ;xi ; : : : ;xk))

proper(c) ! ok(c)proper( f(x1; : : : ;xk)) ! f (proper(x1); : : : ;proper(xk))f (ok(x1); : : : ;ok(xk)) ! ok( f(x1; : : : ;xk))

top(mark(x)) ! top(proper(x))top(ok(x)) ! top(active(x))

THEOREM 8. Let (R ;µ) be a CSRS. IfR µC is simply terminating,

then(R ;µ) is simply terminating.

We conclude this section by noticing that Toyama’s CSRS of Ex-ample 1 cannot be proved to be simply terminating by using anyofthe previous transformations:

RµL : f (x)! f (x)

RµZ;R µ

FR:

f (a0;b0;x)! f (x;x;x)a! a0b! b0

activate(a0)! aactivate(b0)! bactivate(x)! x

RµGM :

active( f (a;b;x))!mark( f (x;x;x))mark( f (x;y;z))! active( f (x;y;mark(z)))

mark(a)! active(xa)mark(b)! active(b)

active(x)! x

RµC :

active( f (a;b;x))!mark( f (x;x;x))active( f (x;y;z))! f (x;y;active(z))f (x;y;mark(z))!mark( f (x;y;z))

proper( f (x;y;z))! f (proper(x); proper(y); proper(z))proper(a)! ok(a)proper(b)! ok(b)

f (ok(x);ok(y);ok(z))! ok( f (x;y;z))top(mark(x))! top(proper(x))

top(ok(x))! top(active(x))Note thatR µ

L is not even terminating;R µZ (andR µ

FR which, in thiscase coincides withR µ

Z) is not simply terminating as it contains thenon-simply terminating TRSf (a0;b0;x) ! f (x;x;x). R µ

GM is notsimply terminating:

active( f (a;b; f (a;b;b)))!R µGM

mark( f ( f (a;b;b); f (a;b;b); f (a;b;b)))!R µGM

active( f ( f (a;b;b); f (a;b;b);mark( f (a;b;b))))!+Emb(F µ

GM) active( f (a;b; f (a;b;b)))!R µGM� � �

Finally,R µC is not simply terminating either:

top(active( f (a;b; f (a;b;b))))!R µC

top(mark( f ( f (a;b;b); f (a;b;b); f (a;b;b))))!+Emb(F µ

C ) top(mark( f (a;b; f (a;b;b)))!R µC

top(proper( f (a;b; f (a;b;b)))!R µC

top(ok( f (a;b; f (a;b;b)))!R µC

top(active( f (a;b; f (a;b;b))))!R µC� � �

Therefore, these examples show that, in general, Theorems 2, 5,6, 7, and 8 cannot be used in the ‘only if’ direction. In otherwords, this means that in certain cases simple termination cannotbe proved by (the considered) transformational techniques, i.e., allof them areincompleteregarding simple termination of CSR. No-tably, the transformationC, which is complete for proving termi-nation of CSR, becomes incomplete for proving simple terminationof CSR (if we want to use simplification orderings for provingter-mination ofR µ

C). In the following section, we consider a differentclass of methods which are not based on applying transformationsto CSRS’s; in contrast, these methods are able to directly address(simple) termination of CSRS’s without transforming them.

5 Direct Approaches to SimpleTermination ofCSR

5.1 The Context-Sensitive Recursive Path Or-dering (CSRPO)

In [5], the recursive path ordering (RPO), a well-known techniquefor automatically proving (simple) termination of TRSs, has beenextended to deal with termination of CSRS’s. Thus, a naturalques-tion arises: are the CSRPO-terminating CSRS’s simply terminat-ing? In this section, we positively answer this question.

The definition of CSRPO is akin to that of RPO. First, we recallthedefinition of RPO. Given a precedence�F on the set of functionsymbols, which is the union of a well-founded ordering�F and acompatible equality=F , and a status functionstat( f ) 2 flex;mulgs.t. if f =F g thenstat( f ) = stat(g), RPO is defined recursively asfollows:

s= f (s1; : : : ;sn)�rpo t iff

1. si �rpo t, for some i = 1; : : : ;n or

2. t = g(t1; : : : ;tm) with f �F g and s�rpo ti for all i =1: : :n or

3. t = g(t1; : : : ;tm) with f =F g, stat( f )=mul andfs1; : : : ;sng ��rpoft1; : : : ;tmg or

4. t = g(t1; : : : ;tm) with f =F g, stat( f )= lex,hs1; : : : ;sni�rpolexht1; : : : ;tmi and s �rpo ti for all i 2f1; : : : ;mg.

where�rpo is the union of�rpo and syntactic equality.

The first idea that comes in mind to extend RPO to context-sensitiverewriting (CSRPO) ismarking the symbols which are in blockedpositions and consider them smaller than the active ones. Thereforeterms in blocked positions become smaller.

Example 6.Consider the rule

f rom(x)! x : f rom(s(x))together withµ(:) = f1g. In order to prove thatfrom(x) is greaterthanx:from(s(x)), we take into account the replacement restrictionµ(:) = f1g thus comparingfrom(x)andx:from(s(x))wherefrom isa marked version offrom (and we setfrom�F from).

However, marking all symbols in non-replacing positions can un-necessarily weaken the resulting ordering. Thus, in addition to theusual precedence�F on symbols, amarking map, denoted bym,which defines for every symbol and every blocked position thesetof symbols that should be marked is also used. ByF we denote

Page 7: Simple termination of context-sensitive rewriting

the set of marked symbols corresponding toF . Given a symbolf in F [F andi 2 f1; : : : ;ar( f )g, a marking mapm provides thesubset of symbols inF that should be marked, i.e.m( f ; i) � F .Marking maps are intended to markonly blocked arguments, i.e.,m( f ; i) = ? if i 2 µ( f ) (this seems reasonable and is also techni-cally necessary, see Definition 6 below). In this way, we markonlythe necessary symbols (in blocked positions).

However, if we simply apply RPO to the terms after marking thesymbols in blocked positions the resulting ordering is not stableunder substitutions. The difficult/interesting point of CSRPO isthe treatment of variables, since variables in blocked positions aresomehow smaller than variables in active positions, which is nottaken into account in RPO (see [5] for a thorough discussion of thisissue). This is achieved by appropriately marking the variables ofterms which are compared using CSRPO. Now, byX we denotethe set of labeled variables corresponding toX . The variables inXare labeled by subsets ofF , for instancexf f ;g;hg, and we will am-biguously use the variables ofX to denote variables labeled by theempty set.

When using the ordering, the marking map tells us whether we haveto mark the top symbol of a term every time we go to an argu-ment of this symbol. Thus, the marking map does not apply to thewhole term but only to the top symbol of the arguments in the recur-sive calls of the definition of CSRPO. Therefore, if we have a termf (s1; : : : ;sk), we will access the arguments usingmt(si ;m( f ; i)),which represents the result of marking the top symbol (of argu-mentssi) when required. This conditional marking of top symbolsis defined by:

mt( f (s1; : : : ;sn);W) = f (s1; : : : ;sn) if f 2Wf (s1; : : : ;sn) otherwise

mt(x;W) = xW wherex is a variable

We writes2 T (F ;X ) if s2X , ors= f (s1; : : : ;sn), with f 2F [Fandsi 2 T (F ;X ) for all i 2 f1; : : : ;ng. Note that, as said, markedsymbols can only appear at the top of a term. A ground terms is inT (F ) if it is in T (F ;X ) and contains no variable.

As remarked above, the treatment of variables is crucial in the def-inition of CSRPO. This is because we need to ensure that CSRPOis a stable ordering. In order to solve this problem, given a terms,we will provide the set of labeled variables that can be consideredsmaller than (or equal to)s without risk of losing stability undersubstitutions. Note that we label the variables with the symbolsthat should be marked in case of applying a substitution. To ensurethat some labeled variablexW is in the set of safe (wrt. stability)labeled variables of a terms, we needx to occur ins and to be surethat for any substitutionσ we have thatmt(σ(x);W) is smaller thanσ(s). Therefore, assuming thatx occurs ins, the important pointis what happens with the function symbols headingσ(s). Due tothis we analyze which function symbols are harmless as head sym-bols. In all cases, the symbols which are included in the label Wof x; additionally, all function symbols which do not appear in thelabel when we reach some occurrence ofx in s are safe. Finally,and more importantly, the symbolsg that can be proved to be safebecause the head symbol ofs (or recursively using some subtermof scontainingx) is greater than or equal tog (and in the latter casethey have multiset status), andg andg have the same marking.

DEFINITION 3. ([5]) Let s be a non-variable term inT (F ;X )and xW a labeled variable. Then xW 2 Stable(s) if and only if x2V ar(s) and f2 Sa f e(s;x) for all f 2 F nW .

The set Sa f e(s;x) for some variable x s.t. x2V ar(s) or s= xV (forsome label V ) is defined as the smallest subset ofF containing

1. if s= xV then all symbols inF nV.

2. if s= f (s1; : : : ;sn) then

(a) the union of all Sa f e(mt(si ;m( f ; i));y) with i2f1: : :ngand y2 V ar(si), and

(b) all g2F such that f=F g and stat( f )= stat(g)=mul,and(m(g; i) =m(g; i)) for all i 2 f1; : : : ;ar(g)g.

(c) all g2 F such that f�F g and(m(g; i) = m(g; i)) forall i 2 f1; : : : ;ar(g)g.

Now we can give the definition of the context-sensitive recursivepath ordering. First we give the definition of the equality relation,induced by the equality on function symbols, that we will use.

DEFINITION 4. Given two terms inT (F ;X ), we define=S asfollows:� f (s1; : : : ;sk) =S g(t1; : : : ;tk) iff f =F g and mt(si ;m( f ; i)) =S

mt(ti ;m(g; i)) for every i2 f1; : : : ;kg.� xW =S xW0 iff W =W0We can enlarge the equality relation by considering permutations ofarguments of symbols with multiset status.

DEFINITION 5 (CSRPO [5]). Let s;t 2 T (F ;X )s= f (s1; : : : ;sn)�S t with t 2 X or t = g(t1; : : : ;tm) iff

1. t = xW 2 Stable(s)2. or mt(si ;m( f ; i))�S t, for some i2 f1; : : : ;ng3. or t = g(t1; : : : ;tm) with f �F g and s�S mt(ti ;m(g; i)) for

all i 2 f1; : : : ;mg4. or t = g(t1; : : : ;tm) with f =F g, stat( f )=mul andfmt(s1;m( f ;1)); : : : ;mt(sn;m( f ;n))g��Sfmt(t1;m(g;1)); : : : ;mt(tm;m(g;m))g5. or t = g(t1; : : : ;tm), f =F g, stat( f )= lex,hmt(s1;m( f ;1)); : : : ;mt(sn;m( f ;n))i�Slexhmt(t1;m(g;1)); : : : ;mt(tm;m(g;m))i and s �S

mt(ti ;m(g; i)) for all i 2 f1; : : : ;mg.where s�S t denotes s�S t or s=S t, and��S and�Slex are re-spectively the multiset and lexicographic extension of�S wrt. =S .The precedence�F and the marking mapm have to satisfy someconditions to ensure the appropriate properties of�S for provingtermination of CSR.

DEFINITION 6. ([5]) Let �F be a precedence, µ a replacementmap andm a marking map. Then(�F ;m) is a valid marking pairif

1. m( f ; i) =? 8 f 2 F ; 8i 2 µ( f )2. f �F f 8 f 2 F3. m( f ; i)�m( f ; i) 8 f 2 F ; 8i 2 f1; : : : ;ar( f )g

Page 8: Simple termination of context-sensitive rewriting

obj EXAMPLE-TR issorts Nat LNat .ops 0 0’ : -> Nat .ops s s’ : Nat -> Nat [strat (1)] .ops nil nil’ : -> LNat .op cons : Nat LNat -> LNat [strat (1)] .op cons’ : Nat LNat -> LNat [strat (1 2)] .op fcons : Nat LNat -> LNat [strat (1 2 0)] .op from : Nat -> LNat [strat (1 0)] .ops sel sel’ : Nat LNat -> Nat [strat (1 2 0)] .ops first first’ : Nat LNat -> LNat [strat (1 2 0)] .op quote : Nat -> Nat [strat (0)] .op unquote : Nat -> Nat [strat (1 0)] .op quote’ : LNat -> LNat [strat (0)] .op unquote’ : LNat -> LNat [strat (1 0)] .vars X Y : Nat .var Z : LNat .eq sel(s(X),cons(Y,Z)) = sel(X,Z) .eq sel(0,cons(X,Z)) = X .eq first(0,Z) = nil .eq first(s(X),cons(Y,Z)) = cons(Y,first(X,Z)) .eq from(X) = cons(X,from(s(X))) .eq sel’(s(X),cons(Y,Z)) = sel’(X,Z) .eq sel’(0,cons(X,Z)) = quote(X) .eq first’(0,Z) = nil’ .eq first’(s(X),cons(Y,Z)) = cons’(quote(Y),first’(X,Z)) .eq quote(0) = 0’ .eq quote’(cons(X,Z)) = cons’(quote(X),quote’(Z)) .eq quote’(nil) = nil’ .eq quote(s(X)) = s’(quote(X)) .eq quote(sel(X,Z)) = sel’(X,Z) .eq quote’(first(X,Z)) = first’(X,Z) .eq unquote(0’) = 0 .eq unquote(s’(X)) = s(unquote(X)) .eq unquote’(nil’) = nil .eq unquote’(cons’(X,Z)) = fcons(unquote(X),unquote’(Z)) .eq fcons(X,Z) = cons(X,Z) .

endo

Figure 2. Transformed OBJ program

When valid marking maps are used, CSRPO is a reductionµ-ordering and can be used for proving termination of CSRS’s ([5]):A CSRS(R ;µ), whereR = (F ;R) is CSRPO-terminating if thereis a precedence�F onF and a valid marking mapm for F suchthat l �S r for all l ! r 2R.

Example 7.Consider the CSRS(R ;µ) of Example 5. Termina-tion of (R ;µ) can also be proved using CSRPO: use the markingm(:;2) = m(:;2) = ffromg and the precedencefirst�F from; [] ; :andsel�F from�F f:;s; fromg. We use the lexicographic statusfor first andsel and the multiset status for all other symbols (seeExample 7 of [5]).

Example 8.Using rewriting restrictions may cause that some nor-mal forms of input expressions are unreachable by restricted com-putation. For instance, the evaluation oft = first(s(0),from(0))usingthe program in Figure 1 yields5:

==========================================

obj EXAMPLE

==========================================

5We use the version 2.0 of theOBJ3 interpreter (available athttp://www.kindsoftware.com/products/opensource).

reduce in EXAMPLE : first(s(0),from(0))

rewrites: 2

result LNat: cons(0,first(0,from(s(0))))

Note thatcons(0,first(0,from(s(0))))is nota normal form. However,t !� cons(0,nil), i.e.,cons(0,nil)is a normal form oft which cannotbe obtained by using theOBJ3 interpreter.

This can be solved by using program transformation techniques.For instance, by applying the program transformation fromOBJprograms toOBJ programs of [2], we obtain the program of Figure2. In contrast to the program in Figure 1, this new program canbeused to fully evaluate expressions (see [2]). Moreover, we are alsoable to prove termination of this new program by using CSRPO[4]: use the markingm(cons;2) = m(cons;2) = m(quote’;1) =m(quote’;1) = ffromg and the precedence

sel=F sel’�F from;quotefirst=F first’ �F cons; from;nil;cons’;nil’ ;quotefrom�F f rom;cons;squote�F 0’;s’quote’�F cons’;nil’quote’�F quotefcons�F consunquote=F unquote’�F 0;s;nil; fcons

We use the lexicographic status for all symbols.

We prove that CSRPO-termination of a CSRS implies simple ter-mination of the CSRS.

THEOREM 9. Let (R ;µ) be a CSRS. If(R ;µ) is CSRPO-terminating, then it is simply terminating.

PROOF. If (R ;µ) is CSRPO-terminating, then there exists a prece-dence�F and a valid marking mapm with l �S r for everyrule l ! r of R . We only need to prove thatl �S r also holdsfor every rule l ! r in Embµ(F ). Note that, if f (x1; : : : ;xk) !xi 2 Embµ(F ), then i 2 µ( f ). Then, f (x1; : : : ;xk) �S xi if xi 2Stable( f (x1; : : : ;xk)). Note that we havexi 2 Stable( f (x1; : : : ;xk))if and only if f 2 Sa f e( f (x1; : : : ;xk);xi) for all f 2 F . Now, sincei 2 µ( f ), it follows thatm( f ; i) = ?. Hence,mt(xi ;?) = (xi)?and Sa f e((xi)?;xi) = F . Therefore, Sa f e( f (x1; : : : ;xk);xi) =F and f 2 Sa f e( f (x1; : : : ;xk);xi) for all f 2 F , which meansf (x1; : : : ;xk)�S xi .

For instance, theOBJ3 program of Figure 2 (viewed as a CSRS) issimply terminating. On the other hand, it is not difficult to see thattermination of the CSRS of Example 1 cannot be proved using theCSRPO: we would need to prove that the tupleha;b;xi containingconstant symbolsa;b is greater than the tuplehx;x;xi that only con-tains variables. According to the definition of CSRPO, this is notpossible.

To summarize what we have done so far, we can say that our no-tion of simple termination of CSR plays (almost) the same roleregarding CSR as simple termination for ordinary rewriting. Wehave proved that simply terminating TRSsR µ

Θ prove simple termi-nation of (R ;µ) for all the existing transformationsΘ. We havealso proved that CSRPO-terminating CSRS’s are simply terminat-ing. Furthermore, we have given an example of a simply terminat-ing CSRS which cannot be proved to be so by using the currentlydeveloped (automatic) techniques.

Page 9: Simple termination of context-sensitive rewriting

Next we will consider still another method of direct terminationproofs of CSRS’s.

5.2 Polynomial Orderings

A monomial ink variables overZ is a functionF :Zk!Zdefinedby F(x1; : : : ;xk) = axr1

1 � � �xrnk for some integera 6= 0 and some non-

negative integersr1; : : : ; rk. The numbera is called the coefficientof the monomial. Ifr1 = r2 = � � � = rn = 0, then the monomial iscalled a constant. A polynomial ink variables overZ is the sum offinitely many monomials ink variables overZ.

Given a signatureF andµ2 MF , let (N;FN ;>) be aF -algebrasuch that, for allf 2 F , fN 2 FN is a polynomial inar( f ) vari-ables satisfying(1) fN(x1; : : : ;xk) 2 N for all x1; : : : ;xk 2 N (well-definedness) and(2) fN is µ-monotone. Then,(N;FN ;>) is a well-foundedµ-monotone algebra and the correspondingµ-reduction or-dering is denoted>µ

poly and said to be a polynomialµ-ordering. TheF -algebraA is called apolynomial µ-interpretationfor F .

In fact, given a polynomialµ-interpretation(N;FN ;>), the corre-spondingµ-reduction ordering>µ

poly can equivalently be defined asfollows: for t;s2 T (F ;X ),

t >µpoly s , 8xi 2 N; [t℄ > [s℄

where[x℄ = x if x2 X and[ f (t1; : : : ;tk)℄ = fN([t1℄; : : : ; [tk℄) (i.e., wedo not need to make explicit the evaluation mapping anymore).

A positive aspect of polynomial orderings regarding other reduc-tion orderings is that they ease the proofs of monotonicity.In un-restricted rewriting, monotonicity of polynomial interpretations isnormally ensured by requiring that all coeficients of all polynomi-als associated to function symbols be positive (see Proposition 10in [40] or [3, Section 5.3]). Of course, we do not want to do this,as this would actually mean that we are using a reduction orderingthus making it useless for proving termination of CSR in the ‘inter-esting’ cases, i.e., when the TRS is not terminating. Even thoughthere is no simple way to ensureµ-monotonicity of polynomialµ-orderings by constraining the shape of coeficients of monomials, wecan still use the following result (where∂F=∂xi means the partialderivative of functionF w.r.t. its i-th argument).

THEOREM 10. Let F : Zk ! Z be a polynomial overZ. Then,F(x1; : : : ;xk) is monotone in its i-th argument if∂F=∂xi > 0 for allx1; : : : ;xk 2 N.

PROOF. Let x;y 2 Z be such thaty > x. Polynomials (viewed asfunctions on real numbers) are obviously differentiable inall theirarguments. Then, by the intermediate value theorem, there is a realnumberx< z< y such that the value of∂F

∂xiat(x1; : : : ;xi�1;z; : : : ;xk)

coincides with

F(x1; : : : ;xi�1;y; : : : ;xk)�F(x1; : : : ;xi�1;x; : : : ;xk)y�x

Since, by hypothesis, this is a positive number andy > x, we haveF(x1; : : : ;xi�1;y; : : : ;xk)> F(x1; : : : ;xi�1;x; : : : ;xk), hence the con-clusion.

Theorem 10 doesnotprovide a full characterization ofµ-monotony.For instance, the polynomialF(x) = 2x2�x is obviously monotone,but∂F=∂x= 4x�1 is not positive forx=0. However, our result canbe used to ensure (full) monotony (i.e.,µ>-monotony) of polynomi-als when more standard conditions (as the aforementioned ones) do

not hold. For instance, polynomialF(x) = x3�x2+x+1 containsnegative coefficients (which, as mentioned before, is not allowed inthe usual polynomial interpretations); the monotonicity of F can beensured using Theorem 10 since∂F=∂x= 3x2�2x+1 > 0 for allx2 N. We can useµ-polynomial orderings for proving terminationof CSRS’s.

Example 9.Consider the CSRS(R ;µ) of Example 1 and the poly-nomial interpretation given byfN(x;y;z) = 1+(x�y)2+z, aN = 2andbN = 1. Obviously, fN(x;y;z) 2 N for all x;y;z2 N. Note alsothat fN is µ-monotone: since∂ fN=∂z= 1> 0, this follows by The-orem 10. We have:[ f (a;b;x)℄ = 2+x > 1+x = [ f (x;x;x)℄Then,(R ;µ) is terminating.

Note that the polynomialµ-interpretation used in Example 9 isnotmonotonic in the standard case: For instancefN(1;1;0) = 1< 2=fN(0;1;0) but 1> 0, i.e., fN is not monotone in its first argument.Similarly, fN(1;1;0) = 1< 2= fN(1;0;0), i.e., fN is not monotonein its second argument either.

As for the unrestricted case, polynomialµ-orderings arewell-founded µ-simplification orderings if we additionally require thatfN(x1; : : : ;xk)> xi for all i 2 µ( f ).THEOREM 11. LetF be a signature containing at least a constantsymbol, µ2 MF and (N;FN ;>) be a polynomial µ-interpretationsuch that for all f2 F and i2 µ( f ), fN(x1; : : : ;xk) > xi for allx1; : : : ;xk 2 N Then,>µ

poly is a well-founded µ-simplification order-ing.

Now, we have the following immediate corollary.

COROLLARY 1. Let (R ;µ) be a CSRS and>µpoly be a polynomial

µ-simplification ordering. If l>µpoly r for all rule l ! r in R , then(R ;µ) is simply terminating.

Example 10.Continuing Example 9. Note thatfN in Example 9verifies fN(x;y;z) � z+ 1 > z for all x;y;z2 N. Hence,(R ;µ) issimply terminating.

6 Modularity of Simple Termination ofCSRS’s

We shall now investigate to what extent the notion of simple ter-mination of CSRS’s introduced behaves in a modular way, i.e.,whether simple termination of two given CSRS’s implies simpletermination of their union. Such a kind of modularity analysis forgeneral termination of CSRS’s has recently been initiated in [22]with promising first results. Let us recall a few notions and resultsfrom [22] that we need subsequently. For simplicity, for therest ofthe paper we assume that all considered CSRS’s are finite. Some ofthe results (but not all) do also hold for arbitrary (infinite) systems.

DEFINITION 7. We say that a propertyP of CSRS’s ismodular fordisjoint unionsif, whenever two disjoint CSRS’s have propertyP ,then their (disjoint) union also does.6

This notion of modularity can be generalized in a straightforwardway to other (more general) classes of combinations of CSRS’s.

6The reverse implication usually holds, too, but for simplicitywe don’t include it in the definition here.

Page 10: Simple termination of context-sensitive rewriting

DEFINITION 8. A rule l ! r in a CSRS(R ;µ) is non-duplicatingif for every x2V ar(l) the multiset of replacing occurrences of x inr is contained in the multiset of replacing occurrences of x in l, andduplicatingotherwise.(R ;µ) is non-duplicatingif all its rules are,andduplicating, otherwise. A rule l! r is said to becollapsing, ifr is a variable, andnon-collapsingotherwise. A CSRS iscollapsingif it has a collapsing rule, andnon-collapsing, otherwise.

Note that for CSRS’s without any replacement restrictions,collaps-ingness and non-duplication as above just yield the correspondingwell-known notions for TRS’s.

Of course, in order to sensibly combine two CSRS’s, one shouldrequire some basiccompatibilitycondition regarding the respectivereplacement restrictions.

DEFINITION 9. Two CSRS’s(R1;µ1), (R2;µ2) are said to becom-patible if they have the same replacement restrictions for sharedfunction symbols, i.e., ifR 1 = (F1;R1) andR 2 = (F2;R2), we haveµ1( f ) = µ2( f ) for every f2 F1\F2. The union(R ;µ) of two com-patible CSRS’s(R 1;µ1), (R 2;µ2) is defined componentwise, i.e.,R = (R;F ) with R= R1[R2, F = F1[F2, and µ= µ1tµ2.

Disjoint CSRS’s are trivially compatible.

THEOREM 12. ([22]) Let (R1;µ1), (R2;µ2) be two disjoint, ter-minating CSRS’s, and let(R ;µ) be their union. Then the followinghold:

(i) (R ;µ) terminates, if both(R1;µ1) and (R2;µ2) are non-collapsing.

(ii) (R ;µ) terminates, if both(R1;µ1) and (R2;µ2) are non-duplicating.

(iii) (R ;µ) terminates, if one of the systems is both non-collapsingand non-duplicating.

DEFINITION 10. A TRSR is said to beterminating under freeprojections, FP-terminating for short, if the disjoint union ofRand the TRS(fGg;fG(x;y) ! x;G(x;y) ! yg) is terminating. ACSRS(R ;µ) is said to be FP-terminating, if the disjoint union ofRand the CSRS((fGg;fG(x;y)! x;G(x;y)! yg);µ), where µ(G) =f1;2g, is terminating.

THEOREM 13. ([22]) Let (R1;µ1), (R2;µ2) be two disjoint, ter-minating CSRS’s, such that their union(R ;µ) is non-terminating.Then one of the systems is not FP-terminating, and the other systemis collapsing.

As already shown for TRS’s, this abstract and powerful structureresult has a lot of direct and indirect consequences and corollaries.To mention only a few:

DEFINITION 11. A CSRS isnon-deterministically collapsingifthere is a term that reduces to two distinct variables (in a finitenumber of context-sensitive rewrite steps).

THEOREM 14. Any non-deterministically collapsing, terminatingCSRS is FP-terminating.

THEOREM 15. ([22]) Termination is modular for non-deter-ministically collapsingdisjoint CSRS’s.

Consequently we also get the next result.

THEOREM 16. FP-termination is modular for disjoint CSRS’s.

In the case of TRS’s it is well-known that simple terminationismodular for disjoint unions ([25]). This can also be shown via theTRS version of the general Theorem 13 above (cf. [21]). In par-ticular, we note that for TRS’s we have the equivalence:(F ;R ) issimply terminating iff(F ;R [Emb(F )) is terminating. Now it isobvious that ifF contains a function symbols of arity at least 2, then(R [Emb(F );µ) is non-deterministically collapsing, and, if addi-tionally (R [Emb(F );µ) is terminating, then(R [Emb(F );µ) isFP-terminating. In fact, even for the case where the TRS(F ;R )has only functions symbols of arity 0 and 1, simple termination of(F ;R ) implies its FP-termination as can be easily shown (e.g., bya minimal counterexample proof).7

With these preparations, we are ready now to tackle modularity ofsimple termination for CSRS’s.

THEOREM 17. Let (R ;µ) with R = (F ;R) be a CSRS withjµ( f )j � 2 for at least one f2F . Then simple termination of(R ;µ)implies FP-termination of(R ;µ).PROOF. Simple termination of(R ;µ) means termination of(R [Embµ(F );µ). By assumption, there is anf 2 F with jµ( f )j �2. Thus, f (: : : ;xi ; : : : ;x j ; : : :) rewrites to bothxi and x j (usingEmbµ(F )) for i; j 2 µ( f ), i < j . But this means that(R [Embµ(F );µ) is non-deterministically collapsing, hence, by The-orem 14,(R [Embµ(F );µ) and, consequently, also(R ;µ) are FP-terminating.

By combining Theorem 17 and Theorem 13 we get now the follow-ing modularity result for simple termination.

THEOREM 18. Let (R1;µ1), (R2;µ2) with R1 = (F1;R1), R2 =(F2;R2) be two disjoint CSRS’s, and let(R ;µ) be their disjointunion (withR = (F ;R), F = F1℄F2, R= R1℄R2, µ= µ1tµ2).Moreover suppose that there exists an fi 2 Fi with jµ( fi)j � 2, fori = 1;2. Then, if(R1;µ1) and(R2;µ2) are simply terminating, then(R ;µ) is simply terminating, too.

Interestingly, for the proof of this result via Theorem 17 above,we need the technical assumption that there exists anfi 2 Fi withjµ( fi)j � 2, for i = 1;2. Currently, we do not know whether thestatement of Theorem 17 also holds without this condition. If yes,Theorem 18 would immediately generalize, too, and yield in gen-eral modularity of simple termination for CSRS’s.

But note that if this condition above is not satisfied, any proof ofthe corresponding statement in Theorem 17 cannot work as in theTRS case any more, since now we may have arbitrarily complicatedterms.

Finally, let us consider the case of (some) non-disjoint unions ofCSRS’s.

6.1 Extension to the Constructor-SharingCase

Finally, let us consider the case of (some) non-disjoint unions ofCSRS’s.

7Note that in this case the terms overF have a very simpleshape, and essentially are strings.

Page 11: Simple termination of context-sensitive rewriting

DEFINITION 12. For a CSRS(R ;µ), whereR = (F ;R), the set ofdefined (function) symbolsis D = froot(l) j l ! r 2 Rg, its set ofconstructorsisC = F nD (thusF = C ℄D). Let(R1;µ1), (R2;µ2)be CSRS’s withF1;F2; C1, C2, andD1, D2 denoting their respec-tive signatures, sets of constructors, and defined functionsymbols.Then (R1;µ1) and (R2;µ1) are said to be(at most) constructorsharingif D1\F2 = D2\F1 = ?. The set ofshared construc-tors between them isC = C1\C2. A rule l! r 2 Ri is said to be(shared) constructor liftingif root(r) 2 C , for i = 1;2. Ri is saidto be(shared) constructor liftingif it has a constructor lifting rule(i = 1;2). A rule l! r 2 Ri is said to beshared symbol liftingifroot(r) is a variable or a shared constructor.Ri is said to besharedsymbol lifting if it is collapsing or has a constructor lifting rule.Riis layer preservingif it is not shared symbol lifting.

DEFINITION 13. Let((F ;R;F );µ) be a CSRS and f2F . We saythat f is fully replacingif µ( f ) = f1; : : : ;ng where n is the arity off .

THEOREM19 ([22], EXTENDS [21, THEOREM34]).Let (R1;µ1), (R2;µ2) be two constructor sharing, compatible, ter-minating CSRS’s with all shared constructors fully replacing, suchthat their union(R ;µ) is non-terminating. Then one of the systems,is not FP-terminating and the other system is shared symbol lifting(i.e., collapsing or constructor lifting).8

PROOF. We only sketch the proof idea. Analogous to [21] one con-siders a minimal counterexample, i.e., a non-terminating derivationin the union with a minimal number of alternatinglayers. By usingsome sophisticated abstracting transfromation such a counterexam-ple can be translated into a counterexample that uses only one of thetwo systems plus a disjoint system with only two rules of the formfG(x;y) ! x;G(x;y) ! yg (that serve for “extracting relevant in-formation of the former signature by need”). Note that for this con-struction to work properly, we need the assumption that the sharedconstructors are fully replacing.

Without the above assumption the statement of the Theorem doesnot hold in general.

Example 11.Consider the CSRS’s

R1 : zeros! 0 : zeros

and

R2 :length([℄)! 0

length(x : y)! s(length(y))with µ(:) = µ(length) = µ(s) = f1g, that have a shared constructor‘:’ which is not fully replacing. Now, both CSRS’s are obviouslyterminating and also FP-terminating, but their union is notdue tothe cycle

length(zeros) ,! length(0 : zeros) ,! s(length(zeros)) :As for disjoint unions, from Theorem 19 above many results canbe derived. Especially regarding simple termination, we have thefollowing.

THEOREM 20. Let (R1;µ1), (R2;µ2) with R1 = (F1;R1), R2 =(F2;R2) be constructor-sharing CSRS’s with all shared construc-tors fully replacing, and let(R ;µ) be their union (withR =(F ;R ),

8As for TRS’s, this result holds not only for finite CSRS’s, butalso for finitely branching ones. But, in contrast to the disjointunion case, it doesn’t hold any more for infinitely branchingsys-tems, cf. [35] for a counterexample.

F = F1℄F2, µ= µ1tµ2). Moreover suppose that there exists anfi 2 Fi with jµ( fi)j � 2, for i = 1;2. Then, if(R1;µ1) and (R2;µ2)are simply terminating, then(R ;µ) is simply terminating, too.

Note that also other “symmetric” and “asymmetric” results can beeasily obtained from Theorem 19 and also from Theorem 20, anaol-ogously to the case of disjoint unions of CSRS’s (and as for TRS’s).

A simple (though somewhat artificial) application example is thefollowing variant of Example 1.

Example 12.The two CSRS’s

R1 :g(x;y)! xg(x;y)! y

f (a;b;x)! f (x;x;x)and

R2 : h(a;b)! a

with µ(h) = µ(g) = f1;2g, µ( f ) = f3g. The systems are compat-ible, constructor-sharing and all shared constructors are(trivially)fully replacing. Both are simply terminating (as it is not very dif-ficult to show; for instance, consider the polynomial interpretationof Example 9 together withgN(x;y) = x+ y+1), hence the com-bined system is also simply terminating by Theorem 20. Note thatthe union includes the full version of Toyama’s TRS (which isnon-terminating in absence of replacement restrictions), hereproved tobe simply terminating regarding CSR (for the selected replacementmap).

7 Conclusion

We have introduced a definition of simple termination of CSR andanalyzed its suitability as a unifying notion which, similar to sim-ple termination of rewriting, represents a class of orderings whichare well-suited for automatization. We have proven that allexistingtransformations for proving termination of CSR can also be used forproving simple termination of CSRS’s (this is in contrast tootherrestricted forms of termination like, e.g., innermost termination ofCSR, see [18, 22]). We have also shown thatCSRPO-terminationis actually a method for proving simple termination of CSRS’s. Wehave analyzed the use of polynomial orderings as a tool for an-alyzing (simple) termination of CSRS’s. After this analysis, ournotion of simple termination appears to be a quite natural one forthe context-sensitive setting. In contrast to the context-free casewhere simplification orderings (over finite signatures) areautomat-ically well-founded by Kruskal’s Theorem, in the context-sensitivecase termination needs to be explicitly established if suchorderingsare used for termination proofs. Some possible lines for doing sohave also been mentioned. Finally, we have also obtained somefirst modularity results concerning simple termination of CSRS’s.These results are quite encouraging and we expect that further sim-ilar results can be obtained, and also be extended to more generalcombinations of CSRS’s, e.g., to composable ([34]) and to certainhierarchical ([24], [11]) systems.

Acknowledgements

We thank the anonymous referees for their helpful remarks.

8 References

[1] M. Alpuente, S. Escobar, B. Gramlich, and S. Lucas. Improving on-demand strategy annotations. In M. Baaz and A. Voronkov, editors,

Page 12: Simple termination of context-sensitive rewriting

Proc. 9th Int. Conf. on Logic for Programming, Artificial Intelligence,and Reasoning (LPAR’02), Lecture Notes in Computer Science, Tbil-isi, Georgia, Oct. 2002. Springer-Verlag. To appear.

[2] M. Alpuente, S. Escobar, and S. Lucas. Correct and complete (pos-itive) strategy annotations for OBJ.Electronic Notes in TheoreticalComputer Science, 71, 2002.

[3] F. Baader and T. Nipkow.Term rewriting and All That. CambridgeUniversity Press, 1998.

[4] C. Borralleras. Personal communication, May 2002.

[5] C. Borralleras, S. Lucas, and A. Rubio. Recursive path orderings canbe context-sensitive. In A. Voronkov, editor,Proc. 18th InternationalConference on Automated Deduction (CADE’02), volume 2392 ofLecture Notes in Artificial Intelligence, pages 314–331, Copenhagen,Denmark, July 2002. Springer-Verlag.

[6] M. Clavel, S. Eker, P. Lincoln, and J. Meseguer. Principles of Maude.In J. Meseguer, editor,Proc. 1st International Workshop on Rewrit-ing Logic and its Applications (WRLA’96), volume 4 ofElectronicNotes in Theoretical Computer Science, Pacific Grove, California,Sept. 1996. Elsevier. 25 pages.

[7] M. Dauchet. Simulation of turing machines by a regular rewrite rule.Theoretical Computer Science, 103(2):409–420, 1992.

[8] N. Dershowitz. A note on simplification orderings.Information Pro-cessing Letters, 9(5):212–215, 1979.

[9] N. Dershowitz. Orderings for term rewriting systems.TheoreticalComputer Science, 17(3):279–301, 1982.

[10] N. Dershowitz. Termination of rewriting.Journal of Symbolic Compu-tation, 3(1):69–116, 1987. Corrigendum in: Journal of Symbol Com-putation, 4(1):409–410, 1987.

[11] N. Dershowitz. Hierarchical termination. In N. Dershowitz andN. Lindenstrauss, editors,Proc. 4th Int. Workshop on Conditional andTyped Rewriting Systems, Jerusalem, Israel (1994), volume 968 ofLecture Notes in Computer Science, pages 89–105. Springer-Verlag,1995.

[12] N. Dershowitz and D. Plaisted. Rewriting. In J. Robinson andA. Voronkov, editors,Handbook of Automated Reasoning, volume 1,chapter 9, pages 535–610. Elsevier and MIT Press, 2001.

[13] M. Ferreira and A. Ribeiro. Context-sensitive AC-rewriting. InP. Narendran and M. Rusinowitch, editors,Proc. 10th InternationalConference on Rewriting Techniques and Applications (RTA’99), vol-ume 1631 ofLecture Notes in Computer Science, pages 286–300,Trento, Italy, July 1999. Springer-Verlag.

[14] K. Futatsugi, J. Goguen, J.-P. Jouannaud, and J. Meseguer. Principlesof OBJ2. InConference Record of the 12th Annual ACM Symposiumon Principles of Programming Languages (POPL’85), pages 52–66.ACM Press, 1985.

[15] K. Futatsugi and A. Nakagawa. An overview of CAFE specifica-tion environment – an algebraic approach for creating, verifying, andmaintaining formal specifications over networks. InProc. 1st IEEE In-ternational Conference on Formal Engineering Methods (ICFEM’97),pages 170–182, Hiroshima, Japan, 1997. IEEE Computer Society.http://computer.org/proceedings/icfem/8002/8002toc.htm.

[16] J. Giesl and A. Middeldorp. Transformation techniquesfor context-sensitive rewrite systems. In P. Narendran and M. Rusinowitch, ed-itors, Proc. 10th International Conference on Rewriting Techniquesand Applications (RTA’99), volume 1631 ofLecture Notes in Com-puter Science, pages 271–287, Trento, Italy, July 1999. Springer-Verlag.

[17] J. Giesl and A. Middeldorp. Transforming context-sensitive rewritesystems. In Y. Toyama, editor,Proc. International Workshop onRewriting in Proof and Computation (RPC’01), RIEC, pages 14–33,Tohoku University, Japan, 2001.

[18] J. Giesl and A. Middeldorp. Innermost termination of context-sensitive rewriting. Aachener Informatik-Berichte (AIBs) 2002-04,

RWTH Aachen, 2002.

[19] J. Giesl and A. Middeldorp. Transformation techniquesfor context-sensitive rewrite systems. Aachener Informatik-Berichte(AIBs) 2002-02, RWTH Aachen, 2002.

[20] J. Goguen, T. Winkler, J. Meseguer, K. Futatsugi, and J.-P. Jouannaud.Introducing OBJ. In J. Goguen and G. Malcolm, editors,Software En-gineering with OBJ: algebraic specification in action. Kluwer, 2000.

[21] B. Gramlich. Generalized sufficient conditions for modular termina-tion of rewriting. Applicable Algebra in Engineering, Communicationand Computing, 5:131–158, 1994.

[22] B. Gramlich and S. Lucas. Modular termination of context-sensitiverewriting. In C. Kirchner, editor,Proc. of 4th International ACMSIGPLAN Conference on Principles and Practice of Declarative Pro-gramming, PPDP’02, Pittsburg, USA, 2002. ACM Press, New York.To appear.

[23] D. Knuth and P. Bendix. Simple word problems in universal alge-bra. In J. Leech, editor,Computational Problems in Abstract Algebra,pages 263–297. Pergamon Press, 1970.

[24] M. Krishna Rao. Modular proofs for completeness of hierarchicalterm rewriting systems.Theoretical Computer Science, 151(2):487–512, Nov. 1995.

[25] M. Kurihara and A. Ohuchi. Modularity of simple termination of termrewriting systems with shared constructors.Theoretical Computer Sci-ence, 103:273–282, 1992.

[26] D. Lankford. On proving term rewriting systems are noetherian. Tech-nical Report MTP 3, Louisiana Technical University, Ruston, 1979.

[27] S. Lucas. Termination of context-sensitive rewritingby rewriting.In F. Meyer auf der Heide and B. Monien, editors,Proc. 23rd In-ternational Colloquium on Automata, Languages and Programming(ICALP’96), volume 1099 ofLecture Notes in Computer Science,pages 122–133, Paderborn, Germany, July 1996. Springer-Verlag.

[28] S. Lucas. Context-sensitive computations in functional and func-tional logic programs.Journal of Functional and Logic Programming,1998(1):1–61, Jan. 1998. The MIT Press.

[29] S. Lucas. Termination of on-demand rewriting and termination of OBJprograms. In H. Sondergaard, editor,Proc. 3rd International ACMSIGPLAN Conference on Principles and Practice of Declarative Pro-gramming (PPDP’01), pages 82–93, Firenze, Italy, Sept. 2001. ACMPress, New York.

[30] S. Lucas. Termination of rewriting with strategy annotations. InR. Nieuwenhuis and A. Voronkov, editors,Proc. 8th Int. Conf.on Logic for Programming, Artificial Intelligence, and Reasoning(LPAR’01), volume 2250 ofLecture Notes in Computer Science, pages669–684, Havana, Cuba, Dec. 2001. Springer-Verlag.

[31] S. Lucas. Context-sensitive rewriting strategies.Information andComputation, 2002. To appear.

[32] S. Lucas. Termination of (canonical) context-sensitive rewriting. InS. Tison, editor,Proc. 13th International Conference on RewritingTechniques and Applications (RTA’02), volume 2378 ofLecture Notesin Computer Science, pages 296–310, Copenhagen, Denmark, July2002. Springer-Verlag.

[33] A. Middeldorp and B. Gramlich. Simple termination is difficult.Applicable Algebra in Engineering, Communication and Computing,6(2):115–128, 1995.

[34] E. Ohlebusch. Modular Properties of Composable Term RewritingSystems. PhD thesis, Universitat Bielefeld, 1994. Report 94-01.

[35] E. Ohlebusch. On the modularity of termination of term rewritingsystems.Theoretical Computer Science, 136:333–360, 1994.

[36] E. Ohlebusch.Advanced Topics in Term Rewriting. Springer-Verlag,Berlin, 2002.

[37] J. Steinbach. Simplification orderings: History of results.FundamentaInformaticae, 24:47–88, 1995.

Page 13: Simple termination of context-sensitive rewriting

[38] J. Steinbach and H. Xi. Freezing – termination proofs for classical,context-sensitive and innermost rewriting. Technical report, Institutfur Informatik, TU Munchen, Jan. 1998.

[39] H. Zantema. Termination of context-sensitive rewriting. In H. Comon,editor, Proc. 8th International Conference on Rewriting Techniquesand Applications (RTA’97), volume 1232 ofLecture Notes in Com-puter Science, pages 172–186, Sitges, Spain, June 1997. Springer-Verlag.

[40] H. Zantema. Termination. In TeReSe, editor,Term Rewriting Systems,chapter 6. Cambridge University Press, 2002.

Appendix

LEMMA 1. Let (R ;µ) be a CSRS whereR = (F ;R). Then,(R [Embµ(F ))µGM =R µ

GM[S , where the TRSS over the signatureF [factiveg consists of the following rules:factive( f(x1; : : : ;xk))!mark(xi ) j f 2 F ; i 2 µ( f )g:PROOF. Immediate from the definition of the transformation.

Following Giesl and Middeldorp [19], we consider the confluentand terminating TRSM containing the rules

mark( f(x1; : : : ;xk))! active( f([x1℄ f ,. . . ,[xk℄ f )

for eachf 2 Σ. Given a termt, we lett#M to be the normal form oft according to rules ofM .

LEMMA 2. [19, Lemma 1] Let(R ;µ) be a CSRS over a signatureF and t;s2 T (F ). If t ,! s, then mark(t)#M !+

RµGM

mark(s)#M .

Theorem 7 Let (R ;µ) be a CSRS. IfR µGM is simply terminating,

then(R ;µ) is simply terminating.

PROOF. If (R ;µ) is not simply terminating, then there exists aninfinite sequenceA : t1 ,! t2 ,! ��� ,! tn ,! ��� in R [Embµ(F ),whereti 2 T (F ) for i � 1. By Lemma 2, each stept ,!R [Embµ(F ) sat positionp 2 Posµ(t) induces a non-empty reduction sequencemark(t)#M !+(R [Embµ(F ))µ

GMmark(s)#M . By Lemma 1 such a se-

quence makes use of rules coming either fromR µGM or from

S = factive( f(x1; : : : ;xk))!mark(xi ) j f 2 F ; i 2 µ( f )g:Borrowing the proof of Lemma 2 (see [19]), we prove by induc-tion onp that the rewrite sequencemark(t)#M !+

RµGM[S mark(s)#M

can be simulated by using the rules inR µGM[Emb(F µ

GM), i.e., weprove thatmark(t)#M !+

RµGM[Emb(F µ

GM) mark(s)#M . If p= Λ, then

t = f (t1; : : : ;tk) = σ(l) for somel ! r in R [Embµ(F ). If l ! r isa rule f (x1; : : : ;xk)! xi 2Embµ(F ), for somei 2 µ( f ) thens= tji .By Lemma 2,

mark(t)!+M

mark(t)#M !+R

µGM[S mark(ti)#M :

Now, since F � F µGM, we only need to apply the rule

f (x1; : : : ;xk)! xi 2 Emb(F µGM) to t before initiating its normal-

ization w.r.t.M , i.e.,

mark(t)!Emb(F µGM) mark(ti) !+

Mmark(ti )#M :

If l ! r 2 R µGM, then we only need to apply Lemma 2 toR µ

GM asno embedding rule is needed.

If p = i:q, then we havet = f (t1; : : : ;ti ; : : : ;tk) and s =f (t1; : : : ;si ; : : : ;tk) with ti ,!R [Embµ(F ) si . Note that, sincep 2 Posµ(t), we have i 2 µ( f ). For 1� j � k we let t 0i =mark(tj )#M if j 2 µ( f ) and t 0j = t j if j 62 µ( f ). By the in-

duction hypothesis,t 0i =mark(ti )#M !+R

µGM[Emb(F µ

GM) mark(si)#M .

Since mark(t)#M = active( f(t 01; : : : ;t 0i ; : : : ;t 0k)) and mark(s)#M =active( f(s01; : : : ;mark(si )#M ; : : : ;s0k)) we conclude the desired inter-mediate result.

Therefore, the infinite sequenceA induces an infinite sequence

B : mark(t1)#M !+R

µGM[S mark(t2)#M !+

RµGM[S � � �

which induces an infinite sequence

B0 : mark(t1)#M !+R

µGM[Emb(F µ

GM) mark(t2)#M!+R

µGM[Emb(F µ

GM) mark(t3)#M!+R

µGM[Emb(F µ

GM) � � �thus contradicting simple termination ofR µ

GM.

LEMMA 3. Let (R ;µ) be a CSRS whereR = (F ;R). Then,(R [Embµ(F ))µC =R µ

C[factive( f(x1; : : : ;xk))!mark(xi ) j f 2F ; i 2µ( f )g.PROOF. Immediate from the definition of the transformation.

LEMMA 4. [19, Lemma 2] Let(R ;µ) be a CSRS over a signatureF and t;s2 T (F µ

C). We have proper(t)!+R

µC

ok(s) if and only t= s

and t2 T (F ).LEMMA 5. [19, Lemma 3] Let(R ;µ) be a CSRS over a signatureF and let t2 T (F ). We have t,! s if and only if active(t)!+

RµC

mark(s).

Theorem 8 Let (R ;µ) be a CSRS. IfR µC is simply terminating,

then(R ;µ) is simply terminating.

PROOF. If (R ;µ) is not simply terminating, then there exists aninfinite sequenceA : t1 ,! t2 ,! ��� ,! tn ,! ��� in R [Embµ(F ),whereti 2 T (F ) for i � 1. By Lemma 5, each stept ,!R [Embµ(F ) s

induces a non-empty reduction sequenceactive(t)!+(R [Embµ(F ))µC

mark(s). By Lemma 3 such a sequence makes use of rules fromR µC

andS = factive( f(x1; : : : ;xk)) ! mark(xi ) j f 2 F ; i 2 µ( f )g. ByLemma 4, the infinite sequenceA induces an infinite sequence

B : top(active(t1))!+R

µC[S top(mark(t2))!R µ

Ctop(proper(t2)) !R µ

Ctop(ok(t2))!R µ

Ctop(active(t2))!R µ

C[S � � �It easily follows from the proof of Lemma 5 (see [19]) that eachrewrite sequenceactive(t)!+(R [Embµ(F ))µ

Cmark(s) associated to

a given stept ,!R [Embµ(F ) s contains exactly one application ofa rule of typeactive(l)! mark(r) for some rulel ! r in R [Embµ(F ). Note that, if a ruleactive( f(x1; : : : ;xk))!mark(xi ) 2 Sapplies, then we haves= t[tjp:i ℄p androot(tjp) = f for some po-sition p 2 Pos(t). Hence, we can writetop(active(t))!Emb(F µ

C)top(active(s))by applying the rulef (x1; : : : ;xk) ! xi directly ontjp. Therefore, the infinite sequenceB can then be transformed intoan infinite sequenceB0 that only uses rules inR µ

C[Emb(F µC ). This

means thatR µC is not simply terminating, a contradiction.