Scholarly article on topic 'Outermost Ground Termination'

Outermost Ground Termination Academic research paper on "Computer and information sciences"

CC BY-NC-ND
0
0
Share paper
Keywords
{Rewriting / termination / outermost / strategy / "rule based languages" / induction / narrowing / "ordering constraints"}

Abstract of research paper on Computer and information sciences, author of scientific article — Olivier Fissore, Isabelle Gnaedig, Hélène Kirchner

Abstract We propose a semi-automatic inductive process to prove termination of outermost rewriting on ground term algebras. The method is based on an abstraction mechanism, schematizing normalisation of subterms, and on narrowing, schematizing reductions on ground terms. The induction ordering is not needed a priori, but is a solution of constraints set along the proof. Our method applies in particular to systems that are non-terminating for the standard strategy nor even for the lazy strategy.

Academic research paper on topic "Outermost Ground Termination"

URL: http://www.elsevier.nl/locate/entcs/volume71.html 20 pages

Outermost Ground Termination

Olivier Fissore \ Isabelle Gnaedig \ and Helene Kirchner1

LORIA-INRIA & LORIA-CNRS, 54506 Vandoeuvre-les-Nancy, BP 239 Cedex, France.

Abstract

We propose a semi-automatic inductive process to prove termination of outermost rewriting on ground term algebras. The method is based on an abstraction mechanism, schematizing normalisation of subterms, and on narrowing, schematizing reductions on ground terms. The induction ordering is not needed a priori, but is a solution of constraints set along the proof. Our method applies in particular to systems that are non-terminating for the standard strategy nor even for the lazy strategy.

Key words: Rewriting, termination, outermost, strategy, rule

based languages, induction, narrowing, ordering constraints

1 Introducing the problem

Termination of rewriting is a crucial problem in automated deduction, for equational logic, as well as in programming, for rule based languages. The property is important in itself, but it is also required to decide of properties like confluence and sufficient completeness, or to allow proofs by consistency. Most of existing methods for proving termination of term rewriting systems (TRS in short) essentially tackle the universal termination problem: they work on free term algebras and prove termination for standard rewriting (rewriting without any strategy). Many are based on syntactic or semantic noetherian orderings containing the rewriting relation induced by the TRS [15,7,20,3,8]. Other methods consist of transforming the termination problem of a TRS R into the termination problem of another TRS R, provable with techniques of the previous category. Examples are semantic labelling [25], and the dependency pair method [2].

In this paper, like in [16], we address the termination problem in the context of proof environments for rule-based programming languages, such as ASF+SDF [17], Maude [5], Cafe-OBJ [13], or ELAN [4], where a program is

1 Email: {fissore,gnaedig,Helene.Kirchner}@loria.fr

©2003 Published by Elsevier Science B. V. 188

a term rewriting system and the evaluation of a query consists of rewriting a ground expression. In such a context, one needs more specific termination proof tools than those previously cited, allowing one to prove termination under specific reduction strategies. There are still few results in this domain, although the need is important. To our knowledge, methods have only been given for the innermost strategy [1,14], the context-sensitive rewriting including particular kinds of local strategies [21], and general local strategies [10].

The outermost strategy for evaluating expressions in the context of programming is essentially used when one knows that computations can be non-terminating. The intuition suggests that rewriting a term at the highest possible position gives more chance than with another strategy to lead to an irreducible form. Indeed, outermost rewriting may succeed when innermost fails, as illustrated by the expression second(dec(1), 0), with the rewrite rules second(x,y) — y and dec(x) — dec(x — 1) on integers. Innermost rewriting fails to terminate, because it first evaluates dec(1) into dec(0), dec—1), and so on. Outermost rewriting, however, gives 0 in one rewriting step. Moreover, outermost derivations are often shorter : in our example, to reduce second(u, v), one does not need to reduce u, which can lead to infinite computations or, at least, to a useless evaluation. This advantage makes the outermost strategy an interesting strategy for rule-based languages, by allowing the interpreters to be more efficient, as well as for theorem proving, by allowing the rewriting-based proofs to be shorter.

Outermost computations are of interest in particular for functional languages like Miranda, Haskell, or Clean, where interpreters or compilers generally involve a strategy for call by name. Often, lazy evaluation is used instead: labelling operators in terms as lazy or eager, it consists in reducing the eager subterms only when their reduction allows a reduction step higher in the term [23].

However, lazy evaluation may diverge while the outermost computation terminates, which gives an additional motivation for studying outermost termination. For instance, let us consider the evaluation of the expression inf (0) with the following two rules : cons(x,cons(y, z)) — big, inf (x)—> cons(x,inf (s(x))). Evaluated in a lazy manner, inf (0) is reduced to cons(0,inf (s(0))), and then, since application of the first rule fails, the sub-expression inf(s(0)) has to be evaluated before considering the whole expression, which leads to an infinite evaluation. Evaluated in an outermost manner, inf (0) is also reduced to cons(0,inf(s(0))), but then inf (s(0)) is reduced to cons(s(0),inf(s(s(0)))), and then the whole expression is reduced to big.

Although not generally used with the rule-based evaluation process, the outermost strategy could be of interest for languages like Maude, OBJ or ELAN, for the previous efficiency reasons. A better knowledge of this strategy w.r.t. more usual ones in this context, like the innermost or local strategies, would be interesting, and could help to choose the good one when program-

ming in these languages. Studying in particular the termination problem for these different strategies, we have pointed out the fact that it is distinct for the innermost, the outermost and the lazy strategies : termination for one of these strategies does not imply termination for any other of them [12].

Lazy termination of functional languages has already been studied (see for example [24]), but to our knowledge, no termination proof tool exists for specifically proving outermost termination of rewriting. We propose here a proof method for checking termination of outermost computations, even if rewriting without strategy or with other strategies diverges.

Our termination proof method for outermost rewriting on ground terms is based on an explicit induction mechanism on the termination property. The main idea is to use induction on the termination property in order to prove that any element t of a given set of terms T terminates, i.e. there is no infinite derivation chain starting from t. So this approach needs a noetherian ordering on terms used in the induction principle. Unlike classical induction proofs, where the ordering is given, we do not need to define it a priori. We only have to check its existence by ensuring satisfiability of ordering constraints incrementally set along the termination proof. Thanks to the power of induction, the generated constraints are often simple to solve.

The method is based on an abstraction mechanism, schematizing normalization of subterms, and on narrowing, schematizing reductions on ground terms. It is semi-automatic : it can stop with success, then establishing outermost termination of a given TRS ; it can stop with failure or diverge, in which case nothing can be concluded about termination. Constraints solving can be handled by the procedure itself, or can be left to the user or delegated to external automatic constraint solvers.

In section 2, the background is presented. Section 3 introduces the basic concepts of our inductive proof mechanism. Section 4 builds on these concepts to propose a proof technique for outermost termination. Proofs can be found in [12].

2 The background

We assume that the reader is familiar with the basic definitions and notations of term rewriting given for instance in [9]. T(F, X) is the set of terms built from a given finite set F of function symbols f having arity n E N, and a set X of variables denoted x,y.... T (F) is the set of ground terms (without variables). The terms composed by a symbol of arity 0 are called constants. Positions in a term are represented as sequences of integers. The empty sequence e denotes the top position. Let p and p' be two positions. The position p is said to be (a strict) prefix of p' (and p' suffix of p) iff p' = p\, where A is a non-empty sequence of integers. Given a term t, Var(t) is the set of variables of t, O(t) is the set of positions of t, inductively defined as follows: O(t) = {e} if t E X, O(t) = {e} U {i.p | 1 < i < n and p E O(U)} if t =

f (ti,...,tn). We denote Oy(t) the set of variable positions in t. The notation t\p stands for the subterm of t at position p. If p E O(t), then t[t']p denotes the term obtained from t by replacing the subterm at position p by the term t'.

A substitution is an assignment from X to T(F, X), written a = (x — t)... (y — u). It uniquely extends to an endomorphism of T(F, X). We identify a substitution a = (x — t)... (y — u) with the finite set of equations (x = t) A ... A (y = u). The result of applying a to a term t E T(F, X) is written a(t) or at. The domain of a, denoted Dom(a) is the finite subset of X such that ax = x. The range of a, denoted Ran(a), is defined by Ran(a) = (JxeDom(a) Var(ax). We have in addition Dom(a) fl Ran(a) = 0. A ground substitution or instantiation is an assignment from X to T(F). The composition of substitutions ai followed by a2 is denoted a2ai. Given two substitutions ai and a2, we write ai < a2[X] iff 39 such that a2 = 6ai[X] i.e. Wx E X, a2x = 9aix (ai is said more general than a2). Given a subset Xi of X, we write aXl for the restriction of a to the variables of Xi, i.e. the substitution such that Dom(aXl) C Xi and Wx E Dom(aXl) : aXlx = ax.

Given a set R of rewrite rules (a set of pairs of terms of T(F, X), denoted l — r, such that Var(r) C Var(l)) or term rewriting system on T(F, X), a function symbol in F is called a constructor iff it does not occur in R at the top position of the left-hand side of a rule, and is called a defined function symbol otherwise. The set of defined function symbols of F for R is denoted by Def R (R is omitted when there is no ambiguity). The rewriting relation induced by R is denoted by —R (— if there is no ambiguity on R), and defined by s — t iff there exists a substitution a and a position p in s such that s\p = al for some rule l — r of R, and t = s[ar]p. This is written s —p,l^r,a t where either p or l — r or a may be omitted; s\p is called a redex. The transitive (resp. reflexive transitive) closure of the rewriting relation induced by R is denoted by —+ (resp. —R). If t —* t' and t' cannot be rewritten anymore, then t' is called a normal form of t and denoted by t{. Remark that given t, t{ may be not unique.

An ordering y on T(F, X) is said to be noetherian iff there is no infinite decreasing chain for this ordering. It is F-stable iff for any pair of terms t,t'

of T (F, X), for any context f (......), t y t' implies f (...t...) y f (...t'...).

It has the subterm property iff for any t of T(F, X), f (...t...) y t. Observe that, for F and X finite, if y is F-stable and has the subterm property, then it is noetherian [19]. If, in addition, y is stable by substitution (for any substitution a, any pair of terms t,t' E T(F, X), t y t' implies at y at'), then it is called a simplification ordering. Let t be a term of T(F); let us recall that t terminates iff every rewriting derivation (or derivation chain) starting from t is finite.

We say that s outermost rewrites into t at position p, which is written s —<0at t iff s rewrites into t at position p and there is no prefix position p' of p such that s rewrites at position p'. Let t be a term of T(F); like for the

standard rewriting, we say that t outermost terminates iff every outermost rewriting derivation starting from t is finite. From now on, t{ denotes an outermost (rewriting) normal form of t.

Let us now recall the definition of narrowing. Let R be a TRS on T(F, X). A term t is narrowed into t', at the non-variable position p, using the rewrite rule l ^ r of R and the substitution a, iff a is a most general unifier of tlP and l, and t' = a(t[r]p). This is denoted t t' where either p, or l ^ r or

a may be omitted. It is always assumed that there is no variable in common between the rule and the term, i.e. that Var(l) fl Var(t) = 0.

The requirement of disjoint variables is easily fulfilled by an appropriate renaming of variables in the rules when narrowing is performed. Observe that for the most general unifier a used in the above definition, Dom(a) C Var(l) U Var(t) and we can choose Ran(a) f (Var(l) U Var(t)) = 0, thus introducing in the range of a only fresh variables.

3 Induction for termination

The main intuition is to observe the outermost rewriting derivation tree starting from a ground term t which is an instance of a term g(x1;... ,xm), for some defined function symbol g E Def, and variables x1,... ,xm. Proving termination on ground terms amounts to prove that all these outermost rewriting derivation trees have only finite branches.

For proving that every term t of T(F) outermost terminates, we proceed by induction on T(F) with a noetherian ordering y, assuming that for any t' such that t y t', t' outermost terminates. We first prove that a basic set of minimal elements for y outermost terminates. As we will see, it is natural to suppose termination of subterms to prove termination of the terms themselves. So the subterm property for y is required, and then the set of minimal elements for y is a subset of the set of constants of F. We then simulate the rewriting derivation trees starting from any instance of g(x1;... ,xm), for all g E Def, for proving that all branches are finite.

Each derivation tree is simulated by a proof tree starting from g(x1;..., xm), and developed by alternatively using two main concepts, namely narrowing and abstraction. More precisely, narrowing schematizes, thanks to all possible narrowing unifiers, all outermost rewriting possibilities of the ground terms in the derivations. The abstraction process simulates the normalization of subterms in the derivations, according to the outermost strategy. This abstraction step is performed on subterms that can be assumed outermost terminating by induction hypothesis.

So the proof process amounts to develop abstract trees whose nodes are composed of a current term that may have variables, and a set of ground substitutions appropriately represented by a constraint. This constraint results from the conjunction of the successive unifiers used for narrowing, from g(x1;... ,xm) to the current term. Each node schematizes a possibly empty

set of ground terms, namely all instances of the current term given by substitutions that are ground solutions of the constraint.

Obviously, the induction ordering y has to be the same along the proof : for all branches in each abstract tree with a root g(xi,..., xm),g E Def, and for all abstract trees. It is however important to point out the flexibility of the proof method that allows the combination with auxiliary termination proofs using a different technique: when the induction hypothesis cannot be applied on a term u, it is sometimes possible to prove outermost termination of every ground instance of u by another way. In the following, we will use a predicate TERMIN(u) that is true iff every ground instance of u outermost terminates.

The termination proof procedure given in this paper is described by a set of inference rules applied with a special strategy S. To prove termination of R on every term t E T(F) we proceed as follows: for each defined symbol g E 'Def, we consider a so-called reference term tref = g(xi,... ,xm) and a trivial set of constraints denoted T. Applying the rules according to the strategy S to the initial state ({g(xi,... ,xm)}, T) builds a proof tree, whose nodes are the states produced by the inference rules. Branching is obtained by the different narrowing steps for all possible rewrite rules. Different kinds of constraints occur: equality, disequality and reduction constraints during the process and ordering constraints at the end of the process.

As said before, there are three cases for the behavior of the termination proof procedure. The good case is when the strategy terminates because the rules do not apply anymore and all terminal states of all proof trees have an empty set of terms. The strategy can also stop with failure, when the rules do not apply anymore on states having non empty sets of terms. Finally, it may not terminate if there is an infinite number of applications of rules on one of the reference terms. In the last two cases, we cannot conclude anything about termination.

4 Outermost termination

Let us reconsider the previous ideas in a more detailed way. Consider the following example, that is outermost terminating, but not terminating for the standard rewriting relation, nor for the innermost strategy, nor even for the lazy evaluation strategy.

f (g(a)) — a

f (f (x)) — b g(x) — f (g(x))

Let us first prove "by hand" that R is outermost terminating on T(F) (F = {f : 1,g : 1,a : 0,b : 0}) in the following way. First, consider the constants a and b: they are obviously outermost terminating. Let us then

study the termination of the ground terms of the form f (t). If t = g(a), f (t) outermost rewrites into a, which is in normal form. Similarly, if t is of the form f (t'), f (t) rewrites into b. Otherwise, f (t) is not reducible at the top position. Using an ordering y with the subterm property as induction ordering, we get f(t) y t. So, by induction hypothesis, we assume that t outermost terminates. Now, either t is irreducible, and then, since f (t) is not reducible at the top position, f(t) is in normal form, or t normalizes into t{. Let t' be any intermediate term of the outermost reduction chain from t to t{. Either f (t') is outermost reducible at the top position into a or b, or the outermost redex is in t'. In the second case, t' is reduced into another intermediate term, on which we can apply the same reasoning. As t is supposed to be terminating, the number of intermediate terms is finite, which allows to conclude that f (t) outermost terminates. We finally study the termination of the ground terms of the form g(t). Any ground term of the form g(t) first rewrites into f (g(t)). Then, if t = a, f (g(t)) normalizes into a. If t = a, f (g(t)) outermost rewrites into f (f (g(t))) at position 1 with the third rule. Finally, the obtained term rewrites into b with the second rule, which ends the proof.

Let us show how to formalize and automate such a reasoning with narrowing and abstraction.

4.1 Induction

As said previously, we observe the outermost rewriting derivation trees starting from tref = g(xi,..., xm), for every g eF, where x 1,..., ,x mm are variables that can be instantiated by any ground term. The outermost rewriting relation is simulated by narrowing and abstracting as follows:

• First, we observe outermost rewriting from g(x1,...,xm), following the possible values of x1 ,...,xm, either on top directly or on top after reduction of subterms. Indeed, any ground instance of g(x1;..., xm) may be reducible on top directly or after outermost reductions of its subterm instances of variables x 1, .. ., x mm.

So to precisely modelize the outermost rewriting relation on ground terms, we first have to replace x1,..., xm by new and all different variables x[,..., x'm defined as follows. Given any ground instance ag(x1,..., xm) of g(x1,..., xm), the x[,..., x'm represent the first reduced form of ax1,..., axm generating an outermost reduction higher in the term (here, at the top), in any outermost rewriting chain starting from ag(x1,..., xm).

We memorize this replacement and we apply a step of outermost narrowing to g(x[, ... ,x'm) in all possible ways, to get terms v. This is the narrowing step.

• Then the idea is to apply the induction hypothesis as efficiently as possible on each resulting narrowed term v. For that we try to apply this induction hypothesis to the "smallest" (w.r.t. the size) subterms vi of v, replacing them by a variable yi, representing any of its normal forms. Indeed, when

the vi are smaller, there is more chance to satisfy the ordering constraints

tref > vi.

According to the outermost strategy, this can be done only if during their normalization, the vi do not introduce outermost redexes higher in the term v. More formally, the induction hypothesis is applied to the subterms v\pi ,...,v\Pn of the current terms v, provided at y av\Pl,..., av\Pn for every ground substitution a, for the induction ordering y and provided s = v[yi]pi ... [yn]Pn is not narrowable for the outermost narrowing relation, defined below. This implies that every ground instance of the term s outermost terminates. This is the abstracting step, which is a final step on the branches of the proof tree it applies on. If v cannot be abstracted, we attempt again a narrowing step.

• Our mechanism also includes the case where the induction hypothesis can directly be applied on the current term v, when atref y av for every ground substitution a, which ends the proof on the branch of v, since every derivation starting from v in the derivation tree of t is supposed to terminate by induction. In fact, this case is a particular case of the abstracting step.

4.2 Outermost narrowing

We first formally define the variable replacement performed before a narrowing step.

Definition 4.1 Let t E T(F, X) be a term whose variable occurrences from left to right in t are x i,..., x mm.

The reduction renaming of t consists in replacing the xi by new and all different variables x'i in t, and is denoted by the so called reduction formula

R(t) (xi ^ xl, ..., xm ^ xm)[t].

The result of the reduction renaming applied to t is denoted Ren(t).

Satisfaction of the reduction formulas is given in such a way that we simulate the outermost reduction relation by alternatively using reduction renaming and narrowing steps.

Definition 4.2 Let t E T(F, X) be a term whose variable occurrences from left to right are x i,..., ,xmm,

at positions pi,... ,pm respectively. A ground substitution 9 satisfies the reduction formula R(t) = (xi xi,..., xm xm)[t] iff there exists an outermost rewriting chain starting from 9t, such that either t[9xi]pi ... [9x'm]Pm is the first reduced form of 9t = t[9xi]pi ... [9xm]Pm on this chain having an outermost rewriting position at a non variable position of t, if this position exists, or 9xi = (9xi{),..., 9x'm = (9xm{) if there is no such position.

Before going on, a few remarks on this definition can be made. In the second case of satisfiability, t[9xi{]i... [9xm{]m is in normal form. Moreover, R(t) is always satisfiable : it is sufficient to take a ground substitu-

tion 9 such that t[9x\]pi ... [9xm]Pm has an outermost rewriting position at a non variable position of t, and then to extend its domain {x1,... ,xm} to {x-i^,..., xm, x—,..., x'm} by choosing for each i e{1, ...,m}, 9x'i = 9xi. If such a substitution does not exist, then every ground instance of t has no outermost rewriting position at a non variable position of t, and it is sufficient to take a ground substitution 9 such that 9x1 = ... = 9xm = 9x- = ... = 9x'm = u, with u any ground term in normal form.

However, there may exist several substitutions solution of such constraints. Let us consider for instance the rewrite system R = {f (a) — f (c), b — a} and the reduction formula R(f (x)) = (x x')[f(x)]. The substitution 91(x) = 91(x') = a and 92(x) = b,92(x') = a are two distinct solutions. With the substitution 92, f (a) is the first reduced form of f (b) having an outermost rewriting position at a non variable position of f (x) (here at top).

Finally, quite often, the reduction formula is reducible to a simple renaming. Let t E T(F, X) be a term whose variables are x1,... ,xm, at positions p1,...,pm respectively. Let us consider R(t) = (x1 x-,... ,xm xm)[t] and let us denote It = {i E [1..m]|t outermost rewrites at a prefix position p'i of pi}. Then R(t) is equivalent (in the sense that the same set of ground substitutions satisfies both formulas) to R(t) /\ieI x'i = xi. Indeed, for any 9 satisfying R(t), for any i E It, t[9x1]pi ... [9xi]pi... [9xm]Pm has at least one outermost rewriting position at a non variable position of t : the position pi or a prefix position of pi. Then we have 9x'i = 9xi.

To illustrate this, let us consider the system {g(x) — x,f (x,x) — x} (the right-hand sides of the rules are not important here), and the reduction formula R(f(x,g(y))) = (x x',y y')[f(x,g(y))]. Then, since f (x,g(y)) outermost rewrites at the position of g, R(f(x,g(y))) is equivalent to R'(f (x,g(y))) = (x x')[f (x,g(y))] A y = y'. Indeed, whatever the ground instance 9y, the term g(9y) outermost rewrites only at the top position, and there is no outermost reduction of 9y. Then, following Definition 4.2, 9y' = 9y. Finally, note that if It = {1,... ,m}, then R(t) is equivalent to the renaming /\™1 xi = xi, where the xi are the variable occurrences from left to right in t.

To schematize outermost rewriting on ground terms, we need to introduce a new specific narrowing relation.

Definition 4.3 A term t E T(F, X) outermost narrows into a term t' E T(F, X) at the non-variable position p, using the rule l — r E R with the most general unifier a, which is written t t' iff

(i) a(l) = a(t|p) and

(ii) t' = a(t[r]p) and

(iii) there exist no prefix position p' of p, no rule l' — r' of R and no substitution a' such that a' can unify atlp and l'.

It is always assumed that there is no variable in common between the rule

and the term, i.e. that Var(l) fl Var(t) = 0.

The third point of the above definition does not appear in the classical definition of narrowing. This special condition is needed here to define an outermost narrowing mechanism modeling the outermost rewriting relation on ground terms.

The outermost narrowing steps applying to a given term t are computed in the following way. We look at every position p of t such that t\p unifies with the left-hand side of a rule using a substitution a. The position p is an outermost narrowing position of t, according to Definition 4.3, iff there is no prefix position p' of t such that at\p> unifies with a left-hand side of rule. Then we look for every prefix position p' of p in t such that at\p> narrows with some substitutions a' and some rule l' — r', and we set a constraint to exclude these substitutions.

Let us consider the previous system {f (g(a)) — a, f (f (x)) — b,g(x) — f (g(x))}. With the standard narrowing relation used at the outermost position, f (g(xi)) only narrows into a with the first rule and the substitution a = (xi = a). With the outermost narrowing relation defined above, f (g(xi)) narrows into a with the first rule and a = (xi = a), and into f (f (g(x2))) with the third rule and the substitution a = (xi = x2 A x' = x2) satisfying the disequality x2 = a. Observe that x' comes from the renaming of variables in the rule.

As illustrated by this example, the substitutions used to narrow a term according to Definition 4.3 have in general to satisfy a set of disequalities. To make this remark precise, we need a few notations and definitions.

Let a be a substitution on T(F, X) identified with the formula /\i (xi = ti), with xi EX, ti E T(F, X), and where = is the syntactic equality. We denote by a the formula \ji(xi = ti).

Definition 4.4 A substitution a is said to satisfy a formula /\^j (xji = t^), iff for all ground instantiation a, f\i V^(aaxji = aatji).

During the proof process, we memorize the previously defined reduction re-namings of variables and the substitutions satisfying disequalities (also called constrained substitutions) used in the successive narrowing steps in a substitution constraint formula.

Definition 4.5 A substitution constraint formula (SCF for short) is a formula A^—i x'h ,...,xim x'im )[ui ]Ai(xi = ti)f\j (V kj xk3 = tk3), with

xh ,x'i ...,xim ,x'm ,xi,xkj E X ,ti,tkj E T (F, X). The empty formula is denoted T.

Then the nodes of the proof trees are composed of a current term, and a set of ground substitutions represented by a substitution constraint formula. Each node schematizes a possibly empty set of ground terms, namely all instances of the current term given by substitutions that are ground solutions of the substitution constraint formula.

Definition 4.6 A substitution constraint formula

Ai (xh x'h ,...,xim x'im )[U ]A i(xi = ti)f\j (V kj xkj = tkj) is said to

be satisfiable iff there exists at least one instantiation 9 such that ¡\i(9xi =

9td Nj (V kj 9xkj = 9tkj) and 9 satisfie^ i (xh xl1,. ..,xim xlm )[ui].

In practice, one can solve the equality and disequality part of the constraint and then check whether the solution 9 satisfies the reduction formulas. This is trivial in cases where 9 only instantiates the xi, since it can be extended by setting 9(xi) = 9(xi). Unfortunately, when 9 also instantiates the xi, we get an undecidable problem: given two ground terms t and t', can t be transformed into t' by repeated application of a given set of rewriting rules?

But fortunately, our process is sound even when inference rules are applied on nodes of the proof tree representing empty sets of terms [12]. So in the narrowing step, we do not attempt to check satisfiability of the constraints.

Nevertheless, we keep trace of the cumulated constraints along a branch of narrowing steps. If at any point, the constraints can be shown unsatisfiable, then the branch can be cut.

For the abstraction step, the satisfiability of an SCF has to be combined with the satisfiability of ordering constraints.

Definition 4.7 Let t,u1,... ,um E T(F, X) and £ an SCF. The constraint (£,t > u1,... ,um) is said to be satisfiable iff there exists an F-stable ordering y on T(F) having the subterm property such that 9t y 9ui,i E [1..m], for every ground substitution 9 satisfying £, and whose domain contains the variables of t and of the ui,i E [1..m]. Such an ordering y is said to satisfy (£, t > u-, ... ,um).

The satisfiability of (£,t > u1,...,um) is undecidable. But a sufficient condition for an ordering y to satisfy this constraint is that y is stable by substitution (the induction ordering is then a simplification ordering) and t y u1,..., um. Remark that consequently, (£,t > u-\^,..., um) may be proved satisfiable, even if £ is not.

As said before, we store in an SCF £ the reduction renamings of variables performed before the narrowing steps and the constrained substitutions used at each narrowing step, for unifying the current term u with a left-hand side of rule l, and whose domain is Var(u)UVar(l). However, since Var(u)f Var(l) = 0, we do not need to know the information related to the variables occurring in l because we are only interested by the transformations applied on u. So only the restriction of a to Var(u) and the negation of the restriction of each a' (see Definition 4.3) to Var(au), respectively denoted aVar(u) and a'Var(au), are stored in £.

4.3 Abstraction

Let us now formalize our abstracting mechanism. The abstraction of a term u relies on the concept of generalization.

Definition 4.8 A term t E T(F, X) is a generalization of u E T(F, X) iff u is an instance of t (i.e. 3a such that at = u). Given two generalizations s and t of a term u, t is said to be greater than s iff s is a generalization of t. The generalization t is called linear generalization if t is linear.

Then, abstracting a term u consists of finding the greatest linear generalization t with variables at positions pi,... ,pm such that

• the induction hypothesis applies to the u\Pi, i.e. (£,tref > u\pi,... ,u\Pm) is satisfiable,

• the generalization t = u[yi]pi ... [ym]Pm, where yi,...,ym are fresh distinct variables, is not narrowable.

The following obvious lemma allows us to conclude on termination of any ground instance of u, if u can be abstracted into a term t.

Lemma 4.9 Let u E T(F, X). Let t be a generalization of u, and {pi,... ,pm} be the set of variable positions in t. If t is not narrowable, then:

(i) in every ground instance of t,the only redex positions are suffixes of pi,i E [1. ..m],

(ii) consequently, if all ground instances of u \ pi ,...,u \ Pm outermost terminate, then every ground instance of u outermost terminates.

4.4 Inference rules

The inference rules for outermost termination, given in Table 1, work on pairs (T, £), where:

• T is a set of terms of T(F, X), containing the current term whose ground instances have to be proved outermost terminating. This is either a singleton or the empty set.

• £ is an SCF, enriched by the formulas expressing the reduction renaming of the variables of the terms to be narrowed and a new constrained substitution each time a narrowing step is performed.

The inference rules work as follows:

• The narrowing step is expressed by a rule Narrow applying on ({u}, £): the variables of u are renamed as specified in Definition 4.1. Then Ren(u) is outermost narrowed in all possible ways in one step, with all possible rewrite rules of the rewrite system R, into terms v. For any possible v, ({u}, £) is replaced by ({v}, £ A R(u) A aVar(Ren(u)) Ai a'i Var(aRen(u))) where avar(Ren(u)) Ai a'i var(aRen(u)) is the SCF defining the constrained substitution allowing outermost narrowing of Ren(u) into v.

• The abstracting step is expressed by a rule Abstract applying on ({u}, £): we look for the greatest possible generalization t of the current term u, such as required in Section 4.3. If (£,tref > u \ pi ,...,u \ Pk) is satisfiable for {pi,... ,pk} C Ov(t) and TERMIN(u\i) for i E Ov(t) \ {pi,... ,pk}

Table 1

Inference rules for outermost tref-termination

Abstract : {г0}, ££

if there is a greatest linear generalization t of u such that t is not outermost narrowable and

(£ 'tref > ulp1, ...,u lpk) is satisfiable for {p-,...,pk} C Ov(t) and TERMIN(uli) for i E Ov(t) \{p-,...,pk}

Narrow

{u}, S

{v} S A R(U) A aVar(Ren(u)) f\ Var(aRen(u))

if Ren(u)^utv where avar(Ren(u)) Ai v'iVar(aRen(u)) is the constrained

substitution allowing outermost narrowing of Ren(u) with a.

then, by induction hypothesis in the first case, and by hypothesis in the second one, all ground instances of ulpi,... ,ulPk and of the uli terminate. By Lemma 4.9, every ground instance of u outermost terminates, which ends the proof on the current derivation chain. So ({u}, £) is replaced by (0, £).

• As said before, we also can test for the current term u, whether (£, tref > u) is satisfiable or TERMIN(u). Then, as previously, by induction hypothesis or by hypothesis, every ground instance of u outermost terminates, which also ends the proof on the current derivation chain. This is a particular case of the rule Abstract, where the generalization of u is a variable y.

For establishing that TERMIN(u) is true, in some cases, the notion of usable rules, proposed in [1], can be used. Given a TRS R on T(F, X) and a term u E T(F, X), the usable rules are defined as a computable superset of the rewrite rules, that may apply to any ground instance of u, for the standard rewriting relation, until its ground normal form is reached, if it exists. Proving termination of any ground instance of u then comes down to proving termination of its usable rules, which is often much easier than orienting the whole TRS. The usable rules can be proved terminating with classical termination methods like simplification orderings - we then obtain termination of the standard rewriting relation, which implies outermost termination of u - or with our inductive method itself : we then directly prove outermost termination of u. An interesting point of this method is that the ordering used to prove termination of the usable rules, either with classical methods or inductively, is completely independent of the main induction ordering. Remark that the case where the initial TRS can be proved terminating with other well known methods (orienting rules by a simplification ordering or using dependency pairs) is taken into account with our method: the usable rules of the first term

g(xi,..., xm) of any proof tree consist of the initial whole TRS, and then the previously mentioned methods can be used to prove their termination.

Remark also that for proving termination of the constants, usable rules can also be used. The notion of usable rules, their computation and their properties are fully developed in [14].

According to the remark following Definition 4.2, the reduction formulas in £ may be reduced to simple variable renamings. In this case, £ only contains variable renamings and constrained substitutions, that can be used to show that the ordering constraint needed to apply Abstract is satisfiable (see Examples B.1 and B.4 in [12]). The following lemma can also be established. It enables to apply Abstract when the current term is either a variable, or a non narrowable term.

Lemma 4.10 Let ({U}, £i) be the ith state of any branch of the derivation tree obtained by applying the strategy S on ({tref}, T), and y an F-stable ordering having the subterm property. If every reduction formula in £i can be reduced to a formula [\- xj = xj, then we have:

Wx E Var(tj) : (£i,tT^ef > x) is satisfiable by y.

To prove outermost termination of R on every term t E T(F), for each defined symbol g E Def, we apply the rules on the initial set of terms T = {tTef = g(xi,. ..,xm)} and the trivial constraint T. These rules must be applied with the strategy S: try to apply Abstract. If Abstract does not apply, then apply Narrow. Then repeat the process until no rule applies anymore.

Let us emphasize some important points about the inference rules:

• Narrow is a non-deterministic rule that can produce several results: it is applied with all possible rewrite rules at all outermost positions.

• After Abstract, no rule applies anymore.

The three cases for the behavior of the termination proof procedure can now be described more precisely. The strategy applied to the initial state ({tref}, T) may stop with states having non empty sets of terms, it may not terminate if there is an infinite number of applications of Narrow. The good case is when the strategy terminates because the rules do not apply anymore and all states are of the form (0, £).

Let us write SUCCESS(g, y) iff the application of the inference rules on ({g(xi,..., xm)}, T), whose conditions are satisfied by y, gives a state of the form (0, £) at the end of all branches of the derivation tree. We then can state the main result.

Theorem 4.11 Let R be a TRS on T(F, X), such that the constants of F are outermost terminating. If there exists an F-stable ordering y having the subterm property, such that for each non-constant defined symbol g, SUCCESS(g, y), then every term of T(F) outermost terminates.

We now develop examples, giving the states of the proof trees. Other examples can be found in [12].

Example 4.12 Consider the previous example R = {f(g(a)) ^ a, f (f (x)) ^ b,g(x) ^ f (g(x))}, that is outermost terminating, but not terminating for the standard rewriting relation. We prove that R is outermost terminating on T(F) where F = {f : 1,g : 1,a : 0,b : 0}.

The defined symbols of F for R are f and g. Applying the rules on f (x1), we get:

((xi A x'

x'i )[f (xi)] = g(a))

(a = (xi = g(a)))

Abstract

f (xi)

E = ((xi xi)[f(xi)] A xi = f (x2)) (a = (xi = f (x2) A x' = x2))

Abstract

E = ((xi xi)[f(xi)]

A xi = g(a))

E = ((xi xi)[f(xi)] A xi = f (x2))

The variable x' comes from the renaming of x in the left-hand side of rule. For the first Abstract, a is generalized into x3, since (E, f (x1) > a) is satisfi-able by a Lexicographic Path Ordering (LPO in short) y with the precedence (ordering on F) f y? a. For the second Abstract, b is generalized into x4, since (E, f (x1) > b) is satisfiable by the previous LPO with the additional precedence f y? b. We recall that the induction ordering has to be the same for all the branches of all the derivation trees.

Applying the rules on g(x1), we get:

g(xi) S = T

Narrow

f (g(x[)) -- ((xi —* x1)[g(xi)]) (a = (x' = xi))

= ((xi A (xi -

* xi)[g(xi)] xi' )[f (g(xi))]

(a = (x'

= a) a))

f (f (g(xi)))

= ((xi —* x1)[g(xi)]

A (xi —* xi')[f (g(xi))]

A x'i' = a)

(a = (x'' = satisfies (x

Abstract

Narrow

s = ((xi —* xi)g(xi)] A (xi —* xi')[f (g(xi))]

((xi A ( x 'i A (xi' —:

-* xi)[g(xi)] »* xi')[f (g(xi))] xi'' )[f (f (g(xi')))]

A x'' = a)

(a = (x''' = g(x'/')))

Abstract

£=((x- xi)[g(x-)]

A (xi x'/)[f (g(xi))] A (x'/ x'/')[f (f (g(x'/)))]

A x'' = a)

Abstract is applied on a and b with the previous LPO with the extra precedence g yF a,b. When narrowing f (g(x-)), we first try the top position, and find a possible unification with the first rule (the left branch). One also must consider the third rule if x'{ is such that x'[ = a; thus, if x'[ = a, f (g(x'/)) is narrowed at position 1 with the third rule (second branch).

Example 4.13 Let R be the TRS cited in the introduction, built on F = {cons : 2, inf : 1, big : 0} :

cons(x,cons(y, z)) — big

inf (x) — cons(x,inf (s(x)))

Applying the inference rules on inf (x1), we get :

inf (xi) E = T

Narrow

cons(x'i ,inf(s(x'i))) E=((xi —* x')[inf (xi)]) (a = (x' = x'))

Narrow

cons(x'(, cons(s(x'''), inf(s(s(x'''))))) E = ((xi —* x')[inf (xi)] A (x' —* x'/,x' —* x'i)[cons(x'i,inf(s(x'i)))}) (a = (x'' = s(xf)))

A (x' -A (x

Narrow

E = ((xi —* x')[inf (xi)}

x'1'')[cons(x'i ,inf(s (x')))}

* /y," sy,'

rp''' _u * rr(v) rr"' „*

x i ^ x i , x i ^ x i )

[cons(x", cons(s(x),inf (s(s(x'/')))))})

(a = (x''

s(x(v)) A z'

Abstract

inf (s(s(x'ivi))))))

E = ((xi —* x')[inf (xi)} A (x' —* x'i',x'i —* x'i'')[cons(x'i, inf (s(x')))}

A (x'' — * x(iv) x''' — * x(v) x''' — * x(vi)) A (x i x i , x i ^ x i , x i ^ x i )

[cons(x'/, cons(s(x),inf (s(s(x'/')))))}) Applying the inference rules on cons (xi,x2), we get :

cons(x' ,x2) E = T

Narrow

E = ((x' —* x',x2 —* x'2)[cons(xi,x2)} A x'2 = cons(x3,x4)) (a = (x'2 = cons(x3,x4) A x' = x' A y' = x3 A z' = x4))

Abstract

E = ((x' —* x',x2 —* x')[cons(xi,x2)} A x'2 = cons(x3,x4))

5 Conclusion and perspectives

In this paper, we have proposed a method to prove outermost termination of term rewriting systems by explicit induction on the termination property. Our method works on the ground term algebra using as induction relation an F-stable ordering having the subterm property. The general proof principle relies on the simple idea that for establishing termination of a ground term t, it is enough to suppose that subterms of t are smaller than t for this ordering, and that rewriting the context leads to terminating chains. Iterating this process until obtaining a context which is not reducible anymore establishes the termination of t.

An important point to automate our proof principle is the satisfaction of the ordering constraints. On many examples, this is immediate: since the ordering constraints only express the subterm property, they are trivially satisfied by any simplification ordering, so we do not need any ordering constraint solver. Elsewhere, we can use an ordering constraint solver as CiME [6].

Up to our knowledge, our algorithm is the first automated method for proving outermost termination of non-terminating systems, and whose generality allows covering other reduction strategies.

Indeed, our process, based on narrowing and abstraction, can also be extended to other strategies. We recently have proposed inference rules for the innermost strategy [14], and for local strategies on operators [10], as they are used in OBJ3, CafeOBJ or Maude. Note that the leftmost innermost strategy can be expressed by local strategies, and, as shown in [18], the termination problem of leftmost innermost rewriting is equivalent to the termination problem of innermost rewriting. So our termination procedure for local strategies holds for proving innermost termination. On the contrary, the outermost strategy cannot be expressed by local strategies. Indeed, strategies like innermost, lazy or local strategies are intrinsically recursive in the sense that, during the evaluation, subterms have to be completely evaluated (i.e. normalized) before the whole term is reduced. This is not the case for the outermost evaluation. The termination procedure proposed in this paper is thus specific to the outermost case. With respect to innermost or local strategies, the order in which narrowing and abstraction apply is changed. Moreover, the narrowing process itself had to be adapted to suitably schematize outermost rewriting on ground terms. This led us to define and deal with specific appropriate constraints, different from those of the innermost and local strategy cases.

Since our induction principle is based on the rewriting relation itself, the extension to the associative-commutative case, as well as to the typed case seems to be easy.

We recently have implemented the algorithm proposed in this paper. This implementation is integrated in CARIBOO [11], a tool recently proposed for proving termination of rewriting under strategies, in which our inductive procedures for the innermost and local strategies are also implemented.

References

[1] T. Arts and J. Giesl. Proving innermost normalization automatically. Technical Report 96/39, Technische Hochschule Darmstadt, Germany, 1996.

[2] T. Arts and J. Giesl. Termination of term rewriting using dependency pairs. Theoretical Computer Science, 236:133-178, 2000.

[3] A. Ben Cherifa and P. Lescanne. Termination of rewriting systems by polynomial interpretations and its implementation. Science of Computer Programming, 9(2):137-160, October 1987.

[4] P. Borovansky, C. Kirchner, H. Kirchner, P.-E. Moreau, and C. Ringeissen. An overview of ELAN. In C. Kirchner and H. Kirchner, editors, Proceedings of the second International Workshop on Rewriting Logic and Applications, volume 15, http://www.elsevier.nl/locate/entcs/volume15.html, Pont-a-Mousson (France), September 1998. Electronic Notes in Theoretical Computer Science. Report LORIA 98-R-316.

[5] M. Clavel, S. Eker, P. Lincoln, and J. Meseguer. Principles of Maude. In J. Meseguer, editor, Proceedings of the 1st International Workshop on Rewriting Logic and its Applications, volume 5 of Electronic Notes in Theoretical Computer Science, Asilomar, Pacific Grove, CA, USA, September 1996. North Holland.

[6] E. Contejean, C. Marche, B. Monate, and X. Urbain. CiME version 2. Prerelease available at http://cime.lri.fr.

[7] N. Dershowitz. Orderings for term rewriting systems. Theoretical Computer Science, 17:279-301, 1982.

[8] N. Dershowitz and C. Hoot. Natural termination. Theoretical Computer Science, 142(2):179-207, 1995.

[9] N. Dershowitz and J.-P. Jouannaud. Handbook of Theoretical Computer Science, volume B, chapter 6: Rewrite Systems, pages 244-320. Elsevier Science Publishers B. V. (North-Holland), 1990. Also as: Research report 478, LRI.

[10] O. Fissore, I. Gnaedig, and H. Kirchner. Termination of rewriting with local strategies. In M. P. Bonacina and B. Gramlich, editors, Selected papers of the 4th International Workshop on Strategies in Automated Deduction, volume 58 of Electronic Notes in Theoretical Computer Science. Elsevier Science Publishers, 2001. Also available as Technical Report A01-R-177, LORIA, Nancy, France.

[11] O. Fissore, I. Gnaedig, and H. Kirchner. CARIBOO : An induction based proof tool for termination with strategies. In Proceedings of the Fourth International Conference on Principles and Practice of Declarative Programming (PPDP), Pittsburgh, USA, October 2002. ACM Press.

[12] O. Fissore, I. Gnaedig, and H. Kirchner. Outermost ground termination - Extended version. Technical report A02-R-493, LORIA, Nancy, France, December 2002.

[13] K. Futatsugi and A. Nakagawa. An overview of CAFE specification environment - an algebraic approach for creating, verifying, and maintaining formal specifications over networks. In Proceedings of the 1st IEEE Int. Conference on Formal Engineering Methods, 1997.

[14] I. Gnaedig, H. Kirchner, and O. Fissore. Induction for innermost and outermost ground termination. Technical Report A01-R-178, LORIA, Nancy, France, 2001.

[15] S. Kamin and J.-J. Levy. Attempts for generalizing the recursive path ordering. Unpublished manuscript, 1980.

[16] H. Kirchner and I. Gnaedig. Termination and normalisation under strategy - Proofs in ELAN. In Proceedigs of the Third International Workshop on Rewriting Logic and its Applications, volume 36 of Elecronic Notes In Theoretical Computer Science, Kanazawa, JAPAN, September 2000. Elsevier Science Publishers.

[17] P. Klint. A meta-environment for generating programming environments. ACM Transactions on Software Engineering and Methodology, 2:176-201, 1993.

[18] M. R. K. Krishna Rao. Some characteristics of strong normalization. Theoretical Computer Science, 239:141-164, 2000.

[19] J. B. Kruskal. Well-quasi ordering, the tree theorem and Vazsonyi's conjecture. Trans. Amer. Math. Soc., 95:210-225, 1960.

[20] D. S. Lankford. On proving term rewriting systems are noetherian. Technical report, Louisiana Tech. University, Mathematics Dept., Ruston LA, 1979.

[21] S. Lucas. Termination of rewriting with strategy annotations. In A. Voronkov and R. Nieuwenhuis, editors, Proc. of 8th International Conference on Logic for Programming, Artificial Intelligence and Reasoning, LPAR'01, volume 2250 of Lecture Notes in Artificial Intelligence, pages 669-684, La Habana, Cuba, December 2001. Springer-Verlag, Berlin.

[22] A. Middeldorp and E. Hamoen. Completeness results for basic narrowing. Applicable algebra in Engineering, Communication and Computation, 5(3&4):213-253, 1994.

[23] Q.-H. Nguyen. Compact normalisation trace via lazy rewriting. In S Lucas and B Gramlich, editors, Proc. 1st International Workshop on Reduction Strategies in Rewriting and Programming (WRS 2001), volume 57. Elsevier Science Publishers B. V. (North-Holland), May 2001. Available at http: //www.elsevier.com/locate/entcs/volume57.html.

[24] S. E. Panitz and M. Schmidt-Schauss. TEA: Automatically proving termination of programs in a non-strict higher-order functional language,. In Proceedings of Static Analysis Symposium'97, volume 1302 of Lecture Notes in Computer Science, pages 345-360. Springer-Verlag, 1997.

[25] H. Zantema. Termination of term rewriting by semantic labelling. Fundamenta Informaticae, 24:89-105, 1995.