Termination of Rewriting With Strategy Annotations? Salvador Lucas DSIC, Universidad Politecnica de Valencia Camino de Vera s/n, E-46022 Valencia, Spain e.mail:
[email protected]
Abstract. We investigate termination of rewriting computations guided
by strategy annotations. We show that proofs of termination can be obtained by proving (innermost) termination of context-sensitive rewriting (CSR). Hence, we investigate how to prove innermost termination of CSR using existing methods for proving termination of CSR. Keywords: Rewriting strategies, termination.
1 Introduction Strategy annotations (e.g., lists of integers that are associated to the symbols of the signature) are used in programming languages such as OBJ2 [FGJM85], OBJ3 [GWMFJ00], CafeOBJ [FN97], and Maude [CELM96] to introduce replacement restrictions aimed at improving termination ([GWMFJ00], Section 2.4.4). Example 1. The following OBJ3 program (borrowed from [OF97]): obj EXAMPLE is sorts Sort . op 0 : -> Sort . op s : Sort -> Sort . op _::_ : Sort Sort -> Sort [strat: (1 0)] . op inf : Sort -> Sort . op nth : Sort Sort -> Sort . var X Y L : Sort . eq nth(s(X),Y::L) = nth(X,L) . eq nth(0,X::L) = X . eq inf(X) = X::inf(s(X)) . endo
speci es an explicit strategy annotation for the list constructor `::' which disables replacements on the second argument. In this way, the evaluation of the expression nth(s(0),inf(0)) always nishes and produces the term s(0), even though the `in nite list' inf(0) is a part of the expression. ?
Work partially supported by Accion Integrada Hispano-Italiana HI2000-0161, Spanish CICYT, and Conselleria de Cultura i Educacio de la Generalitat Valenciana.
Unfortunately, there is a lack of formal techniques to analyze how a particular choice of strategy annotations modi es the termination of programs. Since term rewriting systems (TRSs [BN98,DP01]) provide a suitable computational model for programs written in these programming languages, in this paper, we investigate termination of rewriting computations controlled by strategy annotations. Strategy annotations can be given dierent shapes and computational interpretations. Following Visser's recent classi cation [Vis01], we consider the following computational strategies which are associated to strategy annotations: 1. E -strategy [FGJM85,Eke98], which permits us to completely avoid the evaluation of some arguments of function symbols (in an ordered way). 2. Just-in-time (by van de Pol [Pol01]), which is designed to delay the evaluation of arguments as much as possible. We show that context-sensitive rewriting (CSR , a simple restriction of rewriting that forbids reductions on selected arguments of functions [Luc98]) provides a suitable framework for describing and analyzing computations with programs using such kind of strategy annotations. We focus on the innermost character of these computational models and show that the analysis of innermost termination of CSR provides a more accurate (even complete, for the E-strategy) characterization of termination of rewriting under strategy annotations. Termination of CSR has been studied in [GM99,Luc96,Zan97]. In these works, termination of CSR for a given TRS is demonstrated by proving termination of a transformed TRS. In this way, with CSR we can use the standard methods for proving termination of rewriting (see [Der87] for a survey). We prove that the (two) transformations of [GM99] are correct for proving the innermost termination of CSR . The transformation of [Luc96] is correct in the cases that we characterize below. Zantema's transformation [Zan97] does not provide correct proofs of innermost termination of CSR . On the other hand, we found that transformations of [GM99] (even the second one, which is complete for proving termination of CSR ) are not complete for proving innermost termination of CSR. The transformation of [Luc96] is complete under the same assumptions that make it sound for proving innermost termination of CSR. Section 2 gives some preliminaries. Section 3 introduces CSR . Sections 4 and 5 connect (innermost) termination of CSR with termination of rewriting under E- and van de Pol strategies. Section 6 investigates how to prove innermost termination of CSR . Section 7 discusses related work. Section 8 concludes.
2 Preliminaries Given a set A, P (A) denotes the set of all subsets of A. Given a binary relation R on a set A, we denote the re exive closure of R by R= , its transitive closure by R+ , and its re exive and transitive closure by R . An element a 2 A is an R-normal form, if there exists no b such that a R b; NFR is the set of R-normal forms. We say that b is an R-normal form of a, if b is an R-normal form and a R b. We say that R is terminating i there is no in nite sequence a1 R a2 R a3 .
Throughout the paper, X denotes a countable set of variables and denotes a signature, i.e., a set of function symbols ff; g; : : :g, each having a xed arity given by a mapping ar : ! N. The set of terms built from and X is T (; X ). A term is said to be linear if it has no multiple occurrences of a single variable. Terms are viewed as labelled trees in the usual way. Positions p; q; : : : are represented by chains of positive natural numbers used to address subterms of t. Given positions p; q, we denote its concatenation by p:q. Positions are ordered by the standard pre x ordering . Given a set of positions P, maximal (P) is the set of maximal positions of P w.r.t. . If p is a position, and Q is a set of positions, p:Q = fp:q j q 2 Qg. We denote the empty chain by . The set of positions of a term t is P os(t). Positions of non-variable symbols in t are denoted as P os (t), and P osX (t) are the positions of variables. The subterm at position p of t is denoted as tjp , and t[s]p is the term t with the subterm at position p replaced by s. The symbol labelling the root of t is denoted as root(t). A rewrite rule is an ordered pair (l; r), written l ! r, with l; r 2 T (; X ), l 62 X and V ar(r) V ar(l). The left-hand side (lhs) of the rule is l and the righthand side (rhs) is r. A TRS is a pair R = (; R) where R is a set of rewrite rules. L(R) denotes the set of lhs's of R. An instance (l) of a lhs l of a rule is a redex. The set of redex positions in t is P osR (t). A TRS R is left-linear if for all l 2 L(R), l is a linear term. A term t 2 T (; X ) rewrites to s (at position p), written t !p R s (or just t ! s), if tjp = (l) and s = t[(r)]p, for some rule : l ! r 2 R, p 2 P os(t) and substitution . A TRS is terminating if ! is terminating. We say that t innermost rewrites to s, written t !i s, if t !p s and p 2 maximal (P osR (t)). A TRS is innermost terminating if !i is terminating.
3 Rewriting with syntactic replacement restrictions A mapping : ! P (N) is a replacement map (or -map) if 8f 2 ; (f) f1; : : :; ar(f)g [Luc98]. The ordering v on M , the set of all -maps, is: v 0 if for all f 2 , (f) 0 (f). Thus, v 0 means that considers less positions than 0 (for reduction), i.e., is more restrictive than 0. A replacement map speci es the argument positions which can be reduced for each symbol in . Accordingly, the set of -replacing Spositions P os (t) of t 2 T (; X ) is: P os (t) = fg, if t 2 X and P os (t) = fg[ i2(root(t)) i:P os (tji ), if t 62 X . The set of positions of replacing redexes in t is P osR (t) = P osR (t) \ P os (t). In context-sensitive rewriting (CSR [Luc98]), we (only) contract replacp s and p 2 P os (t). ing redexes: t -rewrites to s, written t ,! s, if t ! R Example 2. Consider the TRS nth(0,x:y) nth(s(x),y:z)
! !
x nth(x,z)
inf(x)
!
x:inf(s(x))
with (:) = (inf) = (s) = f1g and (nth) = f1; 2g. Then, we have: nth(inf(0)) ,! nth(0:inf(s(0))) Since 1:2 62 P os (nth(0:inf(s(0)))), redex inf(s(0)) cannot be -rewritten.
The ,!-normal forms are called -normal forms. A TRS R is -terminating if ,! is terminating. With innermost CSR , #, we only contract maximal positions of replacing redexes: t # s if t !p R s and p 2 maximal (P osR (t)). We say that R is innermost -terminating if # is terminating. Strategy annotations are simple mechanisms for specifying rewriting strategies. They are associated to symbols f of the signature and mainly concern: (1) the possibility of reducing the arguments of f (indexed by 1; : : :; k, if f is a k-ary symbol), and (2) the possibility of applying the (dierent) rules de ning f (i.e., rules l ! r 2 R such that root(l) = f) to redexes rooted by symbol f. We investigate two kinds of strategy annotations.
4 Termination of rewriting under the E-strategy A positive local strategy (or E-strategy [FGJM85,Eke98,Nag99,NO01]) for a kary symbol f 2 is a sequence '(f) of integers taken from f0; 1; : : :; kg which are given in parentheses1 (see Example 1). A mapping ' that associates a local strategy '(f) to every f 2 is called a E-strategy map [NO01]. Roughly speaking, when considering a function call f(t1 ; : : :; tk ), only the arguments whose indices are present as positive integers in the local strategy for f are evaluated (following the speci ed ordering). If 0 is found, then the evaluation of f is attempted. Nagaya describes the operational semantics of term rewriting under E-strategy maps as follows [Nag99]: Let L be the set of all lists consisting of natural numbers. By Ln we denote the set of all lists of natural numbers not exceding n 2 N. We use the signature L = ffL j f 2 ^ L 2 Lar(f ) g and labelled variables XL = fxnil j x 2 Xg. An E-strategy map ' for is extended to a mapping from T (; X ) to T (L ; XL) as follows: =x2X '(t) = xf nil ('(t ); : : :; '(t )) ifif tt = f(t1 ; : : :; tk ) k '(f ) 1 The mapping erase : T (L ; XL) ! T (; X ) removes labellings from symbols. The relation !' on T (L ; XL) N+ (i.e., pairs ht; pi of labelled terms t and positions p) is [NO01,Nag99]: ht; pi !' hs; qi if and only if p 2 P os(t) and either 1. root(tjp ) = fnil , s = t and p = q:i for some i; or 2. tjp = fi:L (t1 ; : : :; tk ) with i > 0, s = t[fL (t1; : : :; tk )]p and q = p:i; or 3. tjp = f0:L (t1 ; : : :; tk ), erase(tjp) is not a redex, s = t[fL(t1 ; : : :; tk )]p , q = p; or 4. tjp = f0:L (t1 ; : : :; tk ) = (l0 ), erase(l0 ) = l, s = t[('(r))]p for some l ! r 2 R and substitution , q = p. We write e 2 L to denote that item e appears somewhere within the list L. Algebraic languages OBJ2, OBJ3, CafeOBJ, and Maude admit the speci cation of E-strategies. Symbols without an explicit local strategy are given a default 1
Apart from this, we use the standard notation of lists which is also used in [NO01]: nil is the empty list and i : L is the list whose rst element is i and whose tail is L.
one whose concrete shape depends on the considered language2. Given an Estrategy map ' for , we let ' 2 M be '(f) = fi > 0 j i 2 '(f)g for each f 2 . We drop superscript ' if no confusion arises. We have the following. Theorem 1. [Luc01] Let R be a TRS and ' be a positive E-strategy map. Let t 2 T (L ; XL), and p 2 P os (erase(t)) be s.t. root(tjp ) = fL for some sux L of '(f). If ht; pi !' hs; qi, then q 2 P os (erase(s)) and erase(t) ,!= erase(s). Semantics of OBJ programs3 under a given E-evaluation map ' is usually given by means of an evaluation function eval' : T (; X ) ! P (T (; X )) (from terms to their sets of `computed values') rather than specifying the concrete rewrite steps leading to computed values [Eke98]. Nakamura and Ogata de ne [NO01]: eval' (t) = ferase(s) 2 T (; X ) j h'(t); i !' hs; i ^ hs; i 2 NF!' g. Example 3. Consider the following TRS R [Eke98]: f(b) g(x)
! !
c h(x)
h(c) a
! !
g(f(a)) b
and ' given by '(f) = (0 1), '(g) = '(h) = (1 0), '(a) = (0), and '(b) = nil. Term t = g(f(a)) is evaluated using !' on '(t) = g(1 0)(f(0 1)(a(0)))(we underline contracted redexes in the `term' component of pairs):
; ; : ; ; : ; ; ; !' hh (0)(fnil (bnil)); 1i !' hh(0)(fnil (bnil)); i !' hhnil (fnil (bnil ));i where hhnil(fnil (bnil )); i is a !'-normal form. Then, h(f(b)) 2 eval' (t). hg
;
(1 0) (f(0 1) (a(0))) i !' hg(0) (f(0 1) (a(0))) 1i !' hg (0)(f(1)(a(0))) 1i !' hg(0)(fnil (a(0))) 1 1i !' hg (0)(fnil (bnil)) 1 1i !' hg(0)(fnil (bnil)) 1i !' hg (0)(fnil (bnil)) i !' hh(1 0) (fnil(bnil )) i
According to the previous de nition of eval' , we can say that A TRS R is '-terminating if, for all t 2 T (; X ), there is no in nite !' -rewrite sequence starting from h'(t); i. Since local strategies are nite lists, the number of !'-reduction steps that corresponds to items (1) to (3) of the de nition of !' (and that keep unchanged the erased terms) is nite. Thus, according to Theorem 1, we have the following. Theorem 2. [Luc01] Let R be a TRS and ' be a positive E-strategy map. If R is -terminating, then R is '-terminating. Theorem 2 connects termination of CSR and '-termination for positive Estrategy maps '. Termination of CSR has been studied in [GM99,Luc96,Zan97]. For instance, the (TRS which represents the) OBJ program of Example 1 can be proved (-)terminating by using Zantema's techniques (see Examples 2 and 3 of [Zan97]). However, termination of CSR only approximates '-termination. For instance, in Maude, the default local strategy associated to a k-ary symbol f , is (1 2 k 0), see [Eke98]. 3 As in [GWMFJ00], by OBJ we mean OBJ2, OBJ3, CafeOBJ, or Maude.
2
Example 4. Consider the TRS [Gra96]: f(a)
!
f(a)
a
!
b
and let '(f) = (1 0) and '(a) = (0). This TRS is '-terminating, but it is not -terminating, since we have: f(a) ,! f(a) ,! . The point here is that computations under the E-strategy are `basically' innermost. Innermost rewriting computations can be terminating even for nonterminating TRSs. This gives rise to the topic of innermost termination of rewriting which has been studied in e.g., [AG97,Gra96]. For instance, the TRS of Example 4 is nonterminating, but innermost terminating [Gra96]. Given a TRS R = (; R), we consider as the disjoint union = C ] D of symbols c 2 C , called constructors and symbols f 2 D, called de ned functions, where D = froot(l) j l ! r 2 Rg and C = ?D. We say that an E-strategy map ' is elementary if for all f 2 D, '(f) = (i1 in 0) and ij > 0 for 1 j n. Remark 1. Consecutive occurrences of zero can be simpli ed into a single one (Corollary 3.3 in [Eke98]). Since [Eke98,Nag99] discuss why in interesting cases 0 is the last index of local strategies associated to de ned symbols, the only critical requirement which is introduced with elementary strategies is that 0 occurs only at the end of the local strategy. Theorem 3. Let R = (C ] D; R) be a TRS and ' be a positive elementary Estrategy map. Let t 2 T (; X ). If h'(t); i !' hs; pi, then p 2 P os (erase(s)) and t # erase(s). Theorem 3 does not hold without requiring elementarity of '. Example 5. Consider R, ', and t as in Example 3. According to Theorem 1, the -rewriting steps associated to the evaluation of t are: g(f(a)) # g(f(b)) ,! h(f(b)) Due to redex f(b), the second -rewriting step is not innermost, Reasoning in a way similar to Theorem 1 and Theorem 2, Theorem 3 entails the following. Theorem 4. Let R = (C ] D; R) be a TRS and ' be a positive elementary E -strategy map. If R is innermost -terminating, then R is '-terminating. For nonelementary E-strategies, Theorem 4 can fail to hold. Example 6. Consider the TRS R of Example 4 and ' given by '(f) = (0 1 0), '(a) = (0), and '(b) = nil. Note that R is innermost -terminating. However, R is not '-terminating, since we have: hf(0 1 0) (a(0)); i !' hf(0 1 0)(a(0)); i !' Since -termination implies innermost -termination (but not vice versa), analyzing innermost termination of CSR provides a more accurate framework for proving termination of TRSs under positive, elementary E-strategies. In fact, we obtain a complete proof method.
Theorem 5. Let R = (C ] D; R) be a TRS and ' be a positive elementary E -strategy map. If R is '-terminating, then R is innermost -terminating. Without elementarity, '-termination may not imply innermost -termination. Example 7. Consider R and ' as in Example 3. Note that R is not innermost
-terminating: h(c)
# g(f(a)) # g(f(b)) # g(c) # h(c) #
However, R is '-terminating, since whenever (the labelled version of) the term g(f(a)) is reached the derivation stops in h(f(b)) without producing h(c) which is needed to generate the cycle (see Example 3).
5 Termination of rewriting under van de Pol's strategy annotations Let R = (; R) be a TRS. According to van de Pol [Pol01], a strategy annotation associated to a given symbol f 2 is a list &(f) whose elements can be either a number i 2 f1; : : :; ar(f)g or a rule l ! r 2 R such that root(t) = f. In principle, strategy annotations contain no duplicated items [Pol01]. Example 8. Consider the TRS [Pol01]:
: if(true,x,y) ! x
: if(x,y,y) ! y : if(false,x,y) ! y Then, a possible strategy annotation for if is &(if) = [1,, ,2,3, ]. We say that & is full regarding rules (or just r-full) if for all l ! r 2 R, l ! r 2 &(root(l)). Given a strategy annotation, van de Pol describes the rewriting strategy that it speci es. A rewriting strategy is seen as a function that given a term t yields either some rewrite of t, i.e., a pair (p; s) such that t !p s, or ? if no rewrite step has been selected. Given a term t and a strategy annotation &, rewr& indicates the (unique, if any) rewrite step that can be performed on t.
De nition 1. [Pol01] Let R = (; R) be a TRS, & be a strategy annotation, and t 2 T (; X ). Then, rewr& (t) = rewr& (t; &(root(t))), where rewr& (t; nil) = ? ; (r)) if t = (l) for some rewr& (t; (l ! r : L)) = (rewr & (t; L) otherwise (i:p; t[s] i) if rewr& (tji) = (p; s) for some p; s rewr& (t; (i : L)) = rewr& (t; L) otherwise
We write t !p & s (or just t !& s) if (p; s) = rewr& (t) 6= ?. Thus, t is a !& -normal form (or just a &-normal form) if and only if rewr& (t) = ?.
Remark 2. Van de Pol's strategy annotations include not only indices of argu-
ments of function symbols but also rules de ning function symbols. Occurrences of 0 in E-strategies can be thought of as abstractions of these items. Given a strategy annotation &, it is immediate to obtain a `corresponding' E-strategy map ' by replacing rule items l ! r in &(f) by 0, for each f 2 (and removing consecutive occurrences of 0, see Remark 1 above). Given a strategy annotation & for , we let & 2 M be & (f) = fi 2 N j i 2 &(f)g for each f 2 . We drop superscript & if no confusion arises. The following theorem establishes a very close connection between !& and ,! . Theorem 6. Let R be a TRS, & be a strategy annotation, and t; s 2 T (; X ). If t !& s, then t ,! s. We say that a TRS is &-terminating if !& is terminating. According to Theorem 6, we have the following immediate consequence. Theorem 7. Let R be a TRS and & be a strategy annotation. If R is -terminating, then R is & -terminating. Termination of !& can also be characterized as innermost -termination: A strategy annotation & is elementary for a TRS R = (C ] D; R) if there are no f 2 D; 2 R, and i 2 N such that : i : L is a sux of &(f). Theorem 8. Let R be a TRS, & be an r-full, elementary strategy annotation, and t; s 2 T (; X ). If t !& s, then t # s. Note that r-fullness is necessary in Theorem 8 to ensure that the step t !& s does not forget any inner redex due to the lack of the corresponding rule in the strategy annotations. Hence, we have the following. Theorem 9. Let R be a TRS and & be an r-full, elementary strategy annotation. If R is innermost -terminating, then R is & -terminating. In general, &-termination does not imply (innermost) -termination. Example 9. Consider the TRS R: : b ! a : b ! c(b) and & given by &(b) = [, ] and &(c) = [1]. Then, R is clearly &-terminating, but it is not (innermost) -terminating. Example 9 also shows that &-termination of a TRS does not imply '-termination for the corresponding E-strategy map (see Remark 2), since a local strategy (0) for b and (1) for c in Example 9 would lead to nonterminating computations with the E-strategy. Moreover, '-termination does not imply &-termination either. Example 10. Consider the following TRS (based on that of Example 8) : if(true,x,y) ! x
: if(x,y,y) ! a : if(false,x,y) ! y : b ! if(a,b,b)
and &(if) = [1,, ,2,3, ], &(b) = [ ]. The corresponding E-strategy map ' is '(f) = (1 0 2 3 0), '(b) = (0). Note that R is not &-terminating:
!& if(a,b,b) !& if(a,if(a,b,b),b) !& However, R is '-terminating, since we have: hb(0); i !' hif(1 0 2 3 0)(anil ,b(0),b(0)); i !+' hif(0 2 3 0)(anil ,b(0),b(0)); i !' hanil ; i b
6 Proving innermost termination of CSR Innermost termination of CSR has been related to termination of elementary local and van de Pol's strategies. How can innermost termination of CSR be proven? Since proving -termination of a TRS R is usually achieved by proving termination of a transformed TRS (e.g., [GM99,Luc96,Zan97]), the question naturally arises of whether innermost -termination is detected by these transformations. In this section, we investigate this problem. The rst correct transformation for proving termination of CSR was described in [Luc96]. The basic idea is very simple: since non--replacing arguments cannot be rewritten with CSR , it makes sense to remove them (by appropriately reducing the arity of symbols): Given a signature , the -contracted signature is obtained by renaming each f 2 as f 2 and giving it the arity ar(f ) = j(f)j. Terms from the signatures and are related by a -contracting function : T (; X ) ! T ( ; X ). This function drops the nonreplacing immediate subterms of a term t and constructs a `-contracted' term by joining the (also transformed) replacing arguments below the corresponding operator of the -contracted signature. Transformation can be used to transform TRSs. Let R = (; R) be a TRS and 2 M . The set of rules R of the -contraction R = ( ; R ) of R is R = f (l) ! (r) j l ! r 2 Rg. The following example illustrates -contraction and shows that, in general, the transformation is not correct for proving innermost -termination. Example 11. Consider the TRS f(a(b))
!
f(a(b))
a(c)
!
b
and (a) = ?, (f) = f1g. Then, R is (we use the same symbols; the arities may decrease due to removing non--replacing arguments) f(a)
!
f(a)
a
!
b
which is innermost terminating. However, R is not innermost -terminating, since we have: f(a(b)) # f(a(b)) # . However, when considering the canonical replacement map can R , which is the most restrictive replacement map (in M ) ensuring that the non-variable subterms of the left-hand sides of the rules of R are replacing, i.e., the minimum -map such that 8l 2 L(R); P os (l) P os (l) [Luc98], we have the following. Theorem 10. Let R = (; R) be a left-linear TRS and 2 M be such that can R v . If R is innermost terminating, then R is innermost -terminating.
The main problem with the contractive transformation is that it is only useful to prove -termination of -conservative TRSs. A TRS R is -conservative if R has no rule with extra variables in the right-hand side [Luc96]. An extra variable x can appear in a rule of R if all occurrences of x are non--replacing in the left-hand side l of the corresponding rule l ! r of R, but x is -replacing in r. In order to overcome this problem, given R and , Zantema [Zan97] de nes a new transformed TRS RZ which is obtained by marking the non-replacing arguments of function symbols (disregarding their positions, see [Zan97] for a detailed description of the transformation). Unfortunately, Zantema's transformation is not correct for proving innermost -termination. Example 12. Consider the TRS R: f(b,a(x))
!
f(b,a(b))
f(b,a(x)) b
! !
f(b,a(b')) b'
activate(b') activate(x)
!
mark(f(x))
Z and (a) = ?, (f) = f1; 2g (note that can R v ). Then, R is:
! !
b x
where b' and activate are new symbols. It is not dicult to see that RZ is innermost terminating. However, R is not innermost -terminating. Recently, Giesl and Middeldorp have introduced a transformation which can be used to prove termination of CSR [GM99] and that (at least from the theoretical point of view) is strictly more powerful than the contractive transformation and Zantema's transformation4. They mark the replacing positions of a term (by using a new symbol active), since these positions are the only ones where CSR may take place. Given a TRS R = (; R) and 2 M , the TRS R1 = ( [ factive; markg; R1) consists of the rules (for all l ! r 2 R and f 2 ): 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), otherwise [xi]f = xi . Concerning this transformation, we have the following result. Theorem 11. Let R = (; R) be a TRS and 2 M . If R1 is innermost terminating, then R is innermost -terminating. Giesl and Middeldorp noticed that this transformation is incomplete for proving termination of CSR , i.e., there exist TRSs R and replacement maps such that R is -terminating but R1 is not terminating (see Example 1 in [GM99]). The transformation remains incomplete for proving innermost -termination. Example 13. Consider the TRS R of Example 4. If = > , then R1 is: active(f(a))
4
mark(f(a))
!
active(f(mark(x)))
The rst statement is proved in [GM99]; the second one has been demonstrated recently [GM01].
active(a) active(x)
! !
mark(b) x
mark(a) mark(b)
! !
active(a) active(b)
R is innermost -terminating, but with R1 we have the following in nite innermost derivation:
active(f(a))
!i !i
!
mark(f(a)) i active(f(mark(a))) active(f(active(a))) i active(f(a))
!
!i
Giesl and Middeldorp also provided a correct and complete transformation to deal with termination of CSR. Basically their idea is to permit a single (contextsensitive) reduction step each time. They achieve this by using new symbols f 0 for each (non-constant) symbol f 2 and shifting a single symbol active to (non-deterministically) reach the replacing position where the redex is placed. The application of a rewrite rule changes active into mark which is propagated upwards through the term, in order to be replaced by a new symbol active that enables new reduction steps. After checking that no `strange' symbols remain uncontrolled (using a symbol proper such that proper(t) reduces to ok(t) if and only if t is a ground term of the original signature), a rule top(ok(x)) ! top(active(x)) enables a new reduction step (see [GM99] for a more detailed explanation). Given a TRS R = (; R) and 2 M , the TRS R2 = ( [ ff 0 j f 2 ^ ar(f) > 0g [ factive; mark; ok; proper; topg; R2) consists of the following rules: for all l ! r 2 R, f 2 such that k = ar(f) > 0, i 2 (f), and constants c 2 , 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)) The transformation is also correct for proving innermost termination of CSR .
Theorem 12. Let R = (; R) be a TRS and 2 M . If R is innermost terminating, then R is innermost -terminating. 2
But now the transformation is not complete for proving innermost -termination. Example 14. Consider again the TRS R in Example 4 and = > . We obtain the following R2 system: active(f(a)) active(a) active(f(x)) f'(mark(x)) proper(a)
! ! ! ! !
mark(f(a)) mark(b) f'(active(x)) mark(f(x)) ok(a)
proper(b) proper(f(x)) f(ok(x)) top(mark(x)) top(ok(x))
! ! ! ! !
ok(b) f(proper(x)) ok(f(x)) top(proper(x)) top(active(x))
In this case, we have the following in nite innermost derivation: top(active(f(a)))
!i top(mark(f(a)) !i top(proper(f(a))) !i top(ok(f(a))) !i top(active(f(a))) !i
Surprisingly, for the -contractive transformation, we have a completeness result. Theorem 13. Let R = (; R) be a left-linear TRS and 2 M be such that can R v and R is -conservative. If R is innermost -terminating, then R is innermost terminating.
Note that -conservativeness is necessary to ensure that R is a TRS. Since TRSs with extra variables cannot be innermost terminating, without this requirement, the theorem would be incorrect.
7 Related work Syntactic annotations have been used in the OBJ family of languages for many years (as local strategies). However, only recently (but quite intensively) has the formal analysis of computations with OBJ's local strategies been addressed (e.g., [Eke98,FGK01,Luc01,Nag99,NO01,OF97,Pol01]). As far as the author knows, only [FGK01,Luc01] have investigated the problem of proving termination of rewriting under positive local strategies. Termination of van de Pol's strategy annotations has not been studied before. In [FGK01], an inductive method is proposed to directly prove (ground) termination of rewriting with positive local strategies without applying any transformation. We have checked that the two examples used in [FGK01] to illustrate their technique can easily be proved terminating by using Zantema's transformation [Zan97] and an automatic tool such as Contejean and Marche's CiME 2.0 system (see http://cime.lri.fr). Moreover, we note that only proofs of termination of CSR (and Theorem 2) are necessary to deal with these examples. On the other hand, in order to be able to use their methods, it is necessary to use a dierent technique to ensure that the constant symbols are terminating (w.r.t. computations guided by the strategies). This is easy if there is no rewrite rule c ! r asociated to any constant symbol c. Note that '-termination of (a TRS containing) the TRS R: a
!
f(a)
a
!
f
with '(f) = nil, could not be proven in this way. However, '-termination of R is easily proved by using the -contractive transformation of [Luc96], since R : is clearly terminating. Nevertheless, Fissore et al.'s technique can work when our techniques do not. For instance, the TRS [GF01] f(a,g(x))
!
f(a,h(x))
h(x)
!
g(x)
terminates with the strategy '1 such that '1 (f) = (0 1 2) but it does not terminate with '2 (f) = (1 2 0) (let '1 (h) = '2 (h) = (0)). In both cases (f) = f1; 2g. Thus, we are not able to distinguish them (note that '1 is not elementary), whereas their technique seems to work [GF01].
8 Conclusions and future work We have investigated how to prove termination of rewriting under local and van de Pol's strategy annotations. We have also shown that, in general, these problems are not comparable (see Examples 9 and 10). We have shown that the analysis of (innermost) termination of CSR provides a suitable characterization of termination of rewriting under positive local and van de Pol's strategy annotations (it is even complete for local strategies, see Theorems 4 and 5). We have investigated the use of transformations that are correct to prove termination of CSR [GM99,Luc96,Zan97] as formal tools for proving innermost termination of CSR. Transformations of [GM99] are correct for proving innermost termination of CSR . The transformation of [Luc96] is correct for left-linear TRSs and replacement maps that are less restrictive than the canonical replacement map. Zantema's transformation is not correct in the general case. Concerning future work, we note that framework aimed at modelling computations under strategy annotations mucst take into account: 1. The presence of replacement restrictions on the arguments of symbols (i.e., the absence of some indices, as in Example 1). 2. The (possible) innermost character of computations (as in OBJ programs). 3. The position of the occurrences of 0 in strategy annotations (as exempli ed by Gnaedig et al.'s previous example). 4. The priority of applying some rules according to (some) strategy annotations (as in van de Pol's approach, see Example 9). 5. The presence of special classes of symbols (e.g., AC operators). 6. The presence of sorts and modules as done in OBJ. In this paper, we have (partially) covered the rst two characteristics. This has proven to be sucient for completely characterizing termination of rewriting under elementary E-strategies. By also considering other sub elds of rewriting such as priority rewriting [Pol98], AC-rewriting [DP01], etc., we would obtain a more accurate characterization of the problem in more general cases5 . Strategy annotations can also be simulated in programming languages that provide for more powerful mechanisms for de ning strategies such as ELAN [BKKMR98]. Our results also apply to ensure termination of programs written in such languages when such kinds of strategies are used. The analysis of termination of ELAN programs controlled by arbitrary strategies is also a subject for future work. Innermost termination of CSR should also be further investigated. It can be very dierent from termination of CSR . For instance, terminating TRSs are, of course, -terminating. However, the innermost terminating TRS of Example 4 is not innermost -terminating, if = ? . Thus, in contrast to -termination, in general, it is not possible to prove innermost -termination using proofs of innermost termination. On the other hand, it is well-known that innermost termination implies termination for, e.g., nonoverlapping TRSs (see [Gra96]). Since innermost termination can be easier to prove than termination (see [AG97,Gra96], 5
Termination of AC-CSR has already been studied in [FR99].
this is used for obtaining indirect proofs of termination. If this remains true for CSR, then we could obtain new methods for proving termination of CSR . Acknowledgements. I thank Jurgen Giesl, Isabelle Gnaedig, Olivier Fissore, Aart Middeldorp, and the anonymous referees for their helpful remarks. I also thank O. Fissore for sending me a copy of [FGK01].
References [AG97]
T. Arts and J. Giesl. Proving Innermost Normalisation Automatically. In H. Comon, editor, Proc. of 8th International Conference on Rewriting Techniques and Applications, RTA'97, LNCS 1232:157-171, SpringerVerlag, Berlin, 1997. [BKKMR98] P. Borovansky, C. Kirchner, H. Kirchner, P.-E. Moreau, and C. Ringeissen. An Overview of ELAN. In C. Kirchner and H. Kirchner, editors, Proc. of 2nd International Workshop on Rewriting Logic and its Applications, WRLA'98, Electronic Notes in Computer Science, 15(1998):1-16, 1998. [BN98] F. Baader and T. Nipkow. Term Rewriting and All That. Cambridge University Press, 1998. [CELM96] M. Clavel, S. Eker, P. Lincoln, and J. Meseguer. Principles of Maude. In J. Meseguer, editor, Proc. 1st International Workshop on Rewriting Logic and its Applications, Electronic Notes in Theoretical Computer Science, volume 4, 25 pages, Elsevier Sciences, 1996. [Der87] N. Dershowitz. Termination of rewriting. Journal of Symbolic Computation, 3:69-115, 1987. [DP01] N. Dershowitz and D.A. Plaisted. Rewriting. In A. Robinson and A. Voronkov, editors. Handbook of Automated Reasoning, volume 1, chapter 9, Elsevier, 2001. [Eke98] S. Eker. Term Rewriting with Operator Evaluation Strategies. In C. Kirchner and H. Kirchner, editors, Proc. of 2nd International Workshop on Rewriting Logic and its Applications, WRLA'98, Electronic Notes in Computer Science, 15(1998):1-20, 1998. [FGJM85] K. Futatsugi, J. Goguen, J.-P. Jouannaud, and J. Meseguer. Principles of OBJ2. In Conference Record of the 12th Annual ACM Symposium on Principles of Programming Languages, POPL'85, pages 52-66, ACM Press, 1985. [FGK01] O. Fissore, I. Gnaedig, and H. Kirchner. Termination of rewriting with local strategies. In M.P. Bonacina and B. Gramlich, editors, Proc. of 4th International Workshop on Strategies in Automated Deduction, STRATEGIES'01, pages 35-54, 2001. [FN97] K. Futatsugi and A. Nakagawa. An Overview of CAFE Speci cation Environment { An algebraic approach for creating, verifying, and maintaining formal speci cation over networks {. In Proc. of 1st International Conference on Formal Engineering Methods, 1997. [FR99] M.C.F. Ferreira and A.L. Ribeiro. Context-Sensitive AC-Rewriting. In P. Narendran and M. Rusinowitch, editors, Proc. of 10th International Conference on Rewriting Techniques and Applications, RTA'99, LNCS 1631:286-300, Springer-Verlag, Berlin, 1999. [GF01] I. Gnaedig and O. Fissore. Personal communication. July 2001.
[GL01]
B. Gramlich and S. Lucas (editors). 1st International Workshop on Reduction Strategies in Rewriting and Programming, WRS'01. Proceedings, volume 2359, Servicio de Publicaciones de la Universidad Politecnica de Valencia, 2001. See also: volume 57 of ENTCS, Elsevier, to appear. [GM99] J. Giesl and A. Middeldorp. Transforming Context-Sensitive Rewrite Systems. In P. Narendran and M. Rusinowitch, editors, Proc. of 10th International Conference on Rewriting Techniques and Applications, RTA'99, LNCS 1631:271-285, Springer-Verlag, Berlin, 1999. [GM01] J. Giesl and A. Middeldorp. Personal communication. May 2001. [Gra96] B. Gramlich. On Proving Termination by Innermost Termination. In H. Ganzinger, editor, Proc. of 7th International Conference on Rewriting Techniques and Applications, RTA'96, LNCS 1103:97-107, SpringerVerlag, Berlin, 1996. [GWMFJ00] J.A. Goguen, T. Winkler, J. Meseguer, K. Futatsugi, and J.-P. Jouannaud. Introducing OBJ. In J. Goguen and G. Malcolm, editors, Software Engineering with OBJ: algebraic speci cation in action, Kluwer, 2000. [Luc96] S. Lucas. Termination of context-sensitive rewriting by rewriting. In F. Meyer auf der Heide and B. Monien, editors, Proc. of 23rd. International Colloquium on Automata, Languages and Programming, ICALP'96, LNCS 1099:122-133, Springer-Verlag, Berlin, 1996. [Luc98] S. Lucas. Context-sensitive computations in functional and functional logic programs. Journal of Functional and Logic Programming, 1998(1):161, January 1998. [Luc01] S. Lucas. Termination of on-demand rewriting and termination of OBJ programs. In Proc. of 3rd International Conference on Principles and Practice of Declarative Programming, PPDP'01, pages 82-93, ACM Press, 2001. [Nag99] T. Nagaya. Reduction Strategies for Term Rewriting Systems. PhD Thesis, School of Information Science, Japan Advanced Institute of Science and Technology, March 1999. [NO01] M. Nakamura and K. Ogata. The evaluation strategy for head normal form with and without on-demand ags. In K. Futatsugi, editor, Proc. of 3rd International Workshop on Rewriting Logic and its Applications, WRLA'00, Electronic Notes in Theoretical Computer Science, volume 36, 17 pages, 2001. [OF97] K. Ogata and K. Futatsugi. Implementation of Term Rewritings with the Evaluation Strategy. In H. Glaser and P. Hartel, editors, Proc of 9th International Symposium on Programming Languages, Implementations, Logics and Programs, PLILP'97, LNCS 1292:225-239, Springer-Verlag, Berlin, 1997. [Pol98] J. van de Pol. Operational semantics of rewriting with priorities. Theoretical Computer Science, 200:289-312, 1998. [Pol01] J. van de Pol. Just-in-time: on Strategy Annotations. In [GL01], pages 39-58. [Vis01] E. Visser. A Survey of Strategies in Program Transformation Systems. In [GL01], pages 97-128. [Zan97] H. Zantema. Termination of Context-Sensitive Rewriting. In H. Comon, editor, Proc. of 8th International Conference on Rewriting Techniques and Applications, RTA'97, LNCS 1232:172-186, Springer-Verlag, Berlin, 1997.