Local Termination: theory and practice

The characterisation of termination using well-founded monotone algebras has been a milestone on the way to automated termination techniques, of which we have seen an extensive development over the past years. Both the semantic characterisation and most known termination methods are concerned with global termination, uniformly of all the terms of a term rewriting system (TRS). In this paper we consider local termination, of specific sets of terms within a given TRS. The principal goal of this paper is generalising the semantic characterisation of global termination to local termination. This is made possible by admitting the well-founded monotone algebras to be partial. We also extend our approach to local relative termination. The interest in local termination naturally arises in program verification, where one is probably interested only in sensible inputs, or just wants to characterise the set of inputs for which a program terminates. Local termination will be also be of interest when dealing with a specific class of terms within a TRS that is known to be non-terminating, such as combinatory logic (CL) or a TRS encoding recursive program schemes or Turing machines. We show how some of the well-known techniques for proving global termination, such as stepwise removal of rewrite rules and semantic labelling, can be adapted to the local case. We also describe transformations reducing local to global termination problems. The resulting techniques for proving local termination have in some cases already been automated. One of our applications concerns the characterisation of the terminating S-terms in CL as regular language. Previously this language had already been found via a tedious analysis of the reduction behaviour of S-terms. These findings have now been vindicated by a fully automated and verified proof.


Introduction
An important contribution to the development of automated methods for proving termination has turned out to be the characterization of termination using well-founded monotone algebras.Both the semantic characterization and most known termination methods are concerned with global termination, uniformly of all the terms of a TRS.This is remarkable, as termination is prima facie a property of individual terms.More generally, one may consider the termination problem for an arbitrary set of terms of a TRS.We call this the local termination problem.
A typical area where termination techniques are applied is that of program verification.The termination problems naturally arising in program verification are local termination problems: the central interest is termination of a program when started on a valid input.A simple example of a program that is not globally terminating is the factorial function: This function terminates for all integers n ≥ 0. However, when started on a negative number this function is caught in an infinite recursion.(This program will be used as an illustration in Examples 3.8 and 5.3.) In logic programming (e.g.Prolog), local termination has been a central field of research over the past years.Local termination problems of Haskell programs have been considered in [PSS97] and [GSTSK06].In [PSS97], a tableau calculus is devised to show termination of sets of terms of the form f a 1 . . .a n where the a i 's are in normal form.In [GSTSK06], a transformation from Haskell programs into dependency pair problems [AG00] is given, which then in turn are solved using methods for global termination.
Surprisingly, for TRSs not much work is known about local termination.We mention the method of match-bounded string rewriting [GHW04], which can be used to prove local termination for sets of strings generated by a regular automaton.Indeed, this method can be viewed as an instance of the semantic framework we develop in this paper.
Local termination is of special interest when dealing with specific classes of terms within a TRS that is known to be non-terminating.Examples of such TRSs are combinatory logic (CL) [Cur30] and encodings of recursive program schemes or Turing machines.The wellknown halting problem for Turing machines is a local termination problem.Clearly, this holds for the blank tape halting problem which just asks for termination on the blank tape.On the first glance the uniform halting problem -asking for termination on all inputsmight seem to be global.However, this is a local termination problem as well, since Turing machines are started in a distinguished initial state and admit only one head to work on the tape.In this paper we will use CL and the halting problem for Turing machines to illustrate some of our results (Examples 3.7, 6.5, 7.9, 7.10, 9.6 and 9.7).
Outline and Contribution.In Section 3 we generalize the semantic characterization from global termination to local termination based on well-founded, monotone partial Σalgebras.This establishes a first, important step towards the development of automatable techniques for proving local termination.In Section 4 we extend this to relative termination, obtaining a characterization using extended monotone partial Σ-algebras.
For global termination it is common practice to stepwise simplify the proof obligation by removing rules.For local termination (the strictly decreasing) rules cannot simply be removed as they influence the set of reachable terms.We need to impose weak conditions on the 'removed' rules, see Section 5.
Having developed the general framework, in the remaining sections we look for fruitful instances of partial monotone algebras, suitable for automation.
In Section 6 we consider the case that the family of the set of terms for which we want to prove local termination can be described by a partial model.A variant of semantic labeling [Zan95] can then be used to transform the local termination problem into a global termination problem, and the available provers for global termination can be applied.
In Section 7 we consider TRSs with the property that strong and weak normalization coincide.In particular, this holds for orthogonal, non-erasing TRSs.In case the language of normalizing terms happens to be regular, we show how a tree automaton (partial model) can be found accepting exactly the normalizing terms.Then we label the TRS with the obtained partial model, and employ the theory developed in Section 6 to transform the local termination problem for the set of normalizing terms to global termination of the labeled TRS.We automated the search for the tree automaton as well as the labeling.
We apply this method to two well-known combinators from CL: S and δ with the rewrite rules S xyz → xz(yz) and δ xy → y(xy), respectively.Determining the language N of normalizing S-terms has been open until the year 2000 [Wal00].Using the method from Section 7 we can now automatically find the partial model for N , and we obtain a labeled system whose global termination coincides with local termination on N .Global termination of this labeled system (containing 1800 labeled rules) has been proven by TTT2 (1.0) [KSZM09] and the proof has been verified by CeTA (1.05) [TS09].
In Section 8 we demonstrate that the local termination method proposed in Section 6 can also be applied for proving global termination.To that end, we transform the global termination into local termination for the set of right-hand sides of forward closures [Der81].Then we transform the obtained system back into a global termination problem using the transformation from Section 6.We show the applicability of this method by solving an example that remained unsolved in the last termination competition [Ter08].After the transformation, the system allows for a simple termination proof using linear polynomial interpretations.
In Section 9 we combine the partial variant of the quasi-models of [Zan95] with monotone algebras to obtain partial monotone algebras.Roughly speaking, partial quasi-models are deterministic tree automata [CDG + 07] equipped with a relation ≥ on the states which guarantees that the language of the automaton is closed under rewriting.Thereby we obtain partial monotone algebras that can be applied successfully for proofs of local termination.Indeed, this method can be automated and, as a matter of fact, we have devised an implementation.
A preliminary version of this paper has appeared in [EdVW09]; our additional contribution is as follows: • For TRSs where strong and weak normalization coincide and where the language of normalizing terms N is regular, we describe an algorithm for constructing a tree automaton (a partial model) accepting exactly the language N .For example, this method is applicable for (fully automatically) determining the language of normalizing S-terms.• We show that methods for local termination can fruitfully be employed for proving global termination, classically the main focus of termination analysis for TRSs.Employing the RFC method (right-hand sides of forward closures) in combination with the transformation from local to global termination from Section 6, we give a new proof for a string rewrite system (SRS) for which no proof had been found in the termination competition so far.

Preliminaries
Term rewriting.A signature Σ is a non-empty set of symbols, each having a fixed arity, given by a map ♯ : Σ → N. Let Σ be a signature and X a set of variable symbols.The set Ter(Σ, X ) of terms over Σ and X is the smallest set satisfying: X ⊆ Ter(Σ, X ), and f (t 1 , . . ., t n ) ∈ Ter(Σ, X ) if f ∈ Σ with arity n and ∀i(1 ≤ i ≤ n) : t i ∈ Ter(Σ, X ).We use x, y, z, . . . to range over variables.The set of positions Pos(t) ⊆ N * of a term t ∈ Ter(Σ, X ) is defined as follows: A substitution σ is a map σ : X → Ter(Σ, X ).For a term t ∈ Ter(Σ, X ) we define tσ as the result of replacing each x ∈ X in t by σ(x).Formally, tσ is inductively defined by xσ = σ(x) for variables x ∈ X and otherwise A term rewriting system (TRS) R over Σ and X is a set of pairs ℓ, r ∈ Ter(Σ, X ), called rewrite rules and written as ℓ → r, for which the left-hand side ℓ is not a variable (ℓ ∈ X ), and all variables in the right-hand side r occur in ℓ as well (Var (r) ⊆ Var (ℓ)).Let R be a TRS.For terms s, t ∈ Ter(Σ, X ) we write s → R t (or briefly s → t) if there exists a rule ℓ → r ∈ R, a substitution σ and a context C ∈ Ter(Σ, The reflexive-transitive closure of → is denoted by ։.We call → the one-step rewrite relation induced by R and ։ the many-step rewrite or reduction relation.If t ։ t ′ then we call t ′ an (R)-reduct of t.
Definition 2.1.Let R be a TRS over Σ and T ⊆ Ter(Σ, X ) a set of terms.The family Fam R (T ) of T is the set of (not necessarily proper) subterms of R-reducts of terms t ∈ T (that is, the least set containing t that is closed under reduction and taking subterms).
Partial functions.For partial functions f : A 1 × . . .× A n ⇀ A and a 1 ∈ A 1 , . . ., a n ∈ A n we call f (a 1 , . . ., a n ) defined and write f (a 1 , . . ., a n )  whenever a 1 , . . ., a n is in the domain of f .Otherwise f (a 1 , . . ., a n ) is called undefined and we write f (a 1 , . . ., a n )  .We use the same terminology and notation for composite expressions involving partial functions.Between such expression we use Kleene equality: Note that an expression can only be defined if all its subexpressions are.Definition 2.2.Let A be a set and R a relation on A. We define two properties of an n-ary partial function f with respect to R.
(1) f is closed if for every a, b ∈ A we have: The functions that we consider will be typically both closed and monotone, which can be rendered briefly as: By writing something like exp 1 R exp 2 we imply that exp 1 and exp 2 are defined.
Partial Σ-algebras.We give the definition of a partial algebra: ] and a (partial) assignment of the variables, α : X ⇀ A, we can give an interpretation [[t, α]] of terms t ∈ Ter(Σ, X ), which, however, will not always be defined.So the interpretation is a partial function from terms and partial assignments to A, inductively defined by:  , then all subterms of t are defined as well.This is a consequence of the usual definition of the composition of partial functions (functional relations); 'undefined' is not an element of the domain.We say that a set of terms T is defined if all terms in T are defined:  .
Partial models.First, we generalise the models from [Zan95] to partial models.
for every rule ℓ → r ∈ R and every interpretation α : Var (ℓ) → A of the variables.
Observe that a left-hand side ℓ may be undefined while the corresponding right-hand side r is defined; the other way around is not permitted.This asymmetry is crucial, since rewriting may turn an undefined (non-terminating) term into a defined (terminating) term, but not the other way around.
Definition 2.7.Let A = A, [[ • ]] be a partial model.The language L(A) of A is: We further generalise the concept of partial models to relations: Definition 2.8.Let R be a TRS over Σ, A = A, [[•]] be a partial Σ-algebra, and ≻ ⊆ A×A a binary relation.We say that A, for all ℓ → r ∈ R and every assignment α :

Local Termination
We devise a complete characterization of local termination based on an extension of the monotone algebra approach of [EWZ08,Zan94].The central idea is the use of monotone partial algebras, that is, the operations of the algebras are allowed to be partial functions.This idea was introduced in [EGH + 09], where these algebras have been employed to obtain a complete characterization of local infinitary strong normalization.First we give the definition of local termination: Definition 3.2.A TRS R over Σ is called terminating (or strongly normalizing) on T ⊆ Ter(Σ, X ), denoted SN R (T ), if → R is terminating on T .We write SN R for termination on the set of all terms Ter(Σ, X ).
We introduce the concept of monotone partial Σ-algebras.In contrast with [EdVW09] we do not require well-foundedness of ≻.We think that it is conceptually cleaner to distinguish the two concepts.Monotone partial Σ-algebras A, [[ • ]], ≻ for which well-foundedness of ≻ holds, will be called well-founded.
equipped with a binary relation ≻⊆ A × A on A such that for every f ∈ Σ the function [[f ]] is closed and monotone with respect to ≻.
A monotone partial Σ-algebra A, Remark 3.4.One could also work with monotone, total algebras instead of partial algebras, by adding an "undefined" element ⊥ to the domain.Then defining ⊥ to be maximal, ⊥ ≻ a for every a ∈ A \ {⊥}, monotonicity of a function will automatically entail closedness.In order to get full correspondence with our framework of partial algebras, we would in this set-up only consider strict functions (that is, the value of the function is ⊥ whenever one of the arguments is ⊥).
The following theorem gives a complete characterization of local termination in terms of monotone partial algebras.
Theorem 3.5.Let R be a TRS over Σ, and T ⊆ Ter(Σ, ∅).Then SN R (T ) holds if and only if there exists a well-founded monotone partial Σ-algebra ≻ such that T is defined, and ≻ is a partial model for R.
Proof.Theorem 3.5 is proved in the same way as Theorem 4.6 (using Remark 4.2).
To keep the presentation simple, the theorem characterizes local termination for sets of ground terms T ⊆ Ter(Σ, ∅) only.Indeed, the theorem can easily be generalized to sets of open terms by, instead of just a well-founded monotone partial algebra, additionally requiring a variable assignment α.A set of terms T is then called defined if for that α we have [[t, α]]  for every t ∈ T .
Remark 3.6.In case T = Ter(Σ, ∅) is the set of all ground terms, Theorem 3.5 basically coincides with the usual theorem for proving termination using (total) well-founded monotone Σ-algebras.More precisely, the subalgebra of A containing all elements that are interpretations of ground terms (leaving out the junk) is a (total) well-founded monotone Σ-algebra proving termination of R.
Example 3.7.We consider the S combinator with the rewrite rule from combinatory logic.That is: @(@(@(S, x), y), z) → @(@(x, z), @(y, z)) in first order notation.The @(M, N ) is abbreviated by M N .The S combinator is known to be globally non-terminating.For example the term S(SS)(SS)(S(SS)(SS)) admits an infinite reduction, see further [Zac78].We have, however, local termination on certain sets of terms, for example the set of "flat" S-terms: where S 1 = S and S n+1 = @(S n , S).
We prove strong normalization on T using the well-founded monotone partial Σ-algebra for all n ∈ N and [[@]](x, y)  for all other cases.Let ≻ be the natural order on N; that is, s is neither source nor target of a ≻ step.Then well-foundedness of ≻ and monotonicity of [[@]] are obvious, and T is defined.We have [[Sxyz, α]]  only if α(x) = s and α(z) = s; then we obtain: Hence ≻ is a partial model for Sxyz → xz(yz) and we conclude termination on T .
Example 3.8.We recall the Haskell program from the introduction: We remark that the standard Haskell data type Integer allows for negative numbers.For this reason the program is not globally terminating, but only locally on non-negative integers.
The usual implementation of the factorial function as TRS makes use of Peano numerals for encoding natural numbers using a constant '0' and a unary symbol 's' for successor.Then the problem of negative numbers does not occur.
For the purpose of modeling the Haskell program as close as possible, we have chosen for a different encoding of the factorial function as TRS.For encoding negative numbers we extend Peano numerals with a unary symbol '−'.Since standard term rewriting does not allow for a priority order on rules, we need to dissolve ambiguities, that is, overlaps between the rules, by instantiating the variables; e.g. for the factorial function fac the variable n needs to be instantiated with s(n) and −(n) to match exactly the integers (in this case 0) not covered by the first rule.As the result of the translation we obtain the TRS R: This TRS is globally non-terminating due to the rewrite sequence:

Local Relative Termination
We define local relative termination.
Definition 4.1.Let A be a set and We write SN → 1 /→ 2 for relative termination on A.
Let R, S be TRSs over Σ, and T ⊆ Ter(Σ, X ).Then the TRS R is called terminating (or strongly normalizing) relative to S on T , denoted SN R/S (T ), if → R is terminating relative to → S on T .We write SN R/S for relative termination on all terms Ter(Σ, X ).
Remark 4.2.Termination of R relative to S on T is equivalent to: no term t ∈ T that admits an infinite rewrite sequence Proof.Assume that SN ≻/ ⊒ would not hold.Then there exists an infinite (≻ ∪ ⊒)-sequence containing infinitely many ≻ steps.Using ≻ • ⊒ ⊆ ≻ we can remove all intermediate ⊒steps giving rise to an infinite ≻-sequence, contradicting well-foundedness of ≻.  .Then we have the implications: Proof.The proofs of (i) and (ii) are identical, we just prove (ii).Let s → S t, that is, we have a rule ℓ → r ∈ S, substitution σ and context  and ℓσ is a subterm of s, we also have as ⊒ is a partial model for S. Then using closedness and monotonicity of the interpretations We give a complete characterization of local relative termination in terms of extended monotone partial algebras.
Theorem 4.6.Let R and S be TRSs over Σ, and T ⊆ Ter(Σ, ∅).Then SN R/S (T ) holds if and only if there is an extended well-founded monotone partial Σ-algebra We verify that A is an extended well-founded monotone partial Σ-algebra.Suppose ≻ would not be well-founded.Then there exists t ∈ Fam R∪S (T ) admitting an infinite → R • ։ R∪S rewrite sequence, contradicting SN R/S (T ).We have ≻ • ⊒ ⊆ ≻ by definition, and consequently SN ≻/ ⊒ by Lemma 4.4.For f ∈ Σ we show that [[f ]] is closed and monotone with respect to ≻ (for ⊒ the reasoning is the same).Consider s, t ∈ A with s ≻ t.Whenever The set T is defined, since for every term s ∈ T we have [[s]]  by definition.It remains to be proved that ≻ is a partial model for R, and ⊒ a partial model for S. We only consider ≻, as the reasoning for ⊒ is the same.Let ℓ → r ∈ R and α : For the 'if'-part assume that A = A, [[•]], ≻, ⊒ fulfilling the requirements of the theorem is given.Assume that SN R/S (T ) would not hold.Then there exists t 0 ∈ T which admits an infinite → R ∪ → S rewrite sequence t 0 → t 1 → . . .containing an infinite number of → Rsteps.By Lemma 4.5 this sequence then would give rise to an infinite ≻ ∪ ⊒ sequence: Example 4.7.We consider a simple example to illustrate the method: Global relative termination SN R/S does not hold, e.g.not on f (a).However on T the rule a → b is terminating relative to the other rules.We can prove this using the extended well-founded monotone partial Σ-algebra A = {0, 1}, [[ • ]], >, ≥ .The interpretations are given by: [ See further Example 9.6 in Section 9 for a non-trivial example.

Stepwise Removal of Rules
For termination proofs it is common practice to weaken the proof obligation stepwise by removing rules.The idea is to find interpretations such that a part R ′ ⊆ R of the rules is decreasing (≻) and the remaining rules are weakly decreasing (⊒).Then for termination of R it suffices to prove termination of the rules in the complement R \ R ′ .We would also like to have this possibility for proofs of local termination.However, for local termination we cannot simply remove (and then forget about) the strictly decreasing rules, as the following example illustrates.
Example 5.1.Consider the set T = {a} in the TRS with the following rules: However, removing the strictly decreasing rule a → b is not sound, since the resulting TRS is terminating on T .
Let us briefly elaborate on the following theorem which enables us to remove rules stepwise.Assume that the goal is proving that R is terminating relative to S on T , that is, SN R/S (T ).We start with zero knowledge: SN ∅/R∪S (T ).We search for an interpretation that makes a part R ′ ⊆ R of the rules decreasing (≻) and the remaining rules in R∪S weakly decreasing (⊒).Then the rules in R ′ can only be applied finitely often: SN R ′ /((R\R ′ )∪S) (T ).But how to proceed?As we have seen above, we cannot simply forget about the rules R ′ , but need to take into account their influence on the family Fam R∪S (T ).A possible and theoretically complete solution would be to require these rules to be weakly decreasing (⊒).However, for practical applicability this requirement seems too strict as it imposes heavy restrictions on the termination order.We propose a different approach, which allows the 'removed' rules R ′ to change arbitrarily, even increase, the interpretation of the rewritten terms, as long as rewriting defined terms yields defined terms again.For this purpose we introduce a relation ❀ on A, which is a partial model for the already removed rules, and thereby guarantees that these rules preserve definedness.
Theorem 5.2.Let R, R ′ and U be TRSs over Σ, and T ⊆ Ter(Σ, ∅) a set of terms such that SN U/(R∪R ′ ) (T ) holds.Then SN (U ∪R ′ )/R (T ) holds if and only if there exists an extended well-founded monotone partial Σ-algebra ❀ is a monotone partial Σ-algebra, and (3) ≻, ⊒ and ❀ are partial models for R ′ , R and U , respectively.
Proof.Straightforward extension of the proof of Theorem 4.6.The 'only if'-part follows immediately by taking ❀ = ≻.For the 'if'-part consider an infinite reduction t 1 → t 2 → . . .with t 1 ∈ T .Then since ❀ is a partial model for U , we conclude ∀i ∈ N.
 .Moreover, as a consequence of SN U/(R∪R ′ ) (T ) we can cut off the prefix of the sequence containing the finitely many U steps.
Example 5.3.We reconsider Example 3.8, and prove termination of R on T .The usage of Theorem 5.2 allows for a simpler stepwise termination proof.In particular, for removing the rules for fac we can employ the standard interpretation mul as • and add as +.Let A = N, [[ • ]], >, ≥ where > is the natural order on N, and [[ • ]] is given by: Then > is a partial model for (ρ 1 ) and (ρ 2 ): and obviously ≥ is a partial model for the other rules.Let U 1 = {(ρ 1 ), (ρ 2 )}, and R 1 = R\U 1 .
Then by Theorem 5.2 it suffices to show SN U 1 /R 1 (T ) to conclude SN R (T ).
As second step, we remove the mul rules.
for all n, m ∈ N. Recall that the rules from U 1 have to be taken into consideration as they have an impact on the set of reachable terms (otherwise the set of terms T would consist only of normal forms).Nevertheless, the rule (ρ 2 ) from U 1 is not (weakly) decreasing, that is, ≥ is not a partial model for (ρ 2 ) with respect to the above interpretation: This is also not necessary.It suffices that U 1 is decreasing with respect to any other relation ❀ guaranteeing that all reachable terms are defined.The rules (ρ 4 ), (ρ 5 ), and (ρ 6 ) are decreasing (> is a partial model), for all α : X → N: The remaining rules in R 1 are weakly decreasing (that is, ≥ is a partial model).We define Finally, we employ the algebra Thereby > is a partial model for all rules from R 2 , and ❀ is a partial model for U 2 .Hence, we conclude SN U 2 /R 2 (T ), and thus SN R (T ).
For other applications of the theorem see Examples 9.6 and 9.7 in Section 9.

Via Models from Local to Global Termination
In this section we describe an easy transformation from local to global termination based on an adaptation of semantic labeling [Zan95].For this purpose we generalise the concept of models from [Zan95] to partial models.Whenever the language T for which we are interested in termination can be described by a partial model, that is,  }, then semantic labeling allows for a simple, complete transformation from local to global termination.Here complete means that the original system is locally terminating on T if and only if the transformed, labeled system is globally terminating.
We define a variant of semantic labeling where each symbol is labeled by the tuple of the values of its arguments.Definition 6.1.Let Σ be a signature, and let A = A, [[ • ]] be a partial Σ-algebra.For t ∈ Ter(Σ, X ) and α :  , the labeling lab A (t, α) of t with respect to α is defined as follows: In order to obtain a complete transformation we need to restrict the models to their core, that is, those elements that are interpretations of ground terms.
By construction of the core we have The restriction of a model to its core does not change its language, thus in the sequel we can without loss of generality assume that all models are core.
We have arrived at the transformation from local to global termination.The rules are labeled as known from semantic labeling with the exception that labeled rules are thrown away if the interpretation of their left-hand side is undefined.Definition 6.3.Let R be a TRS over Σ, and A = A, [[ • ]] a partial Σ-algebra.We define the labeling of R as the TRS lab A (R) over the signature lab A (Σ) by: A TRS is collapsing if it contains rules of the form ℓ → x with x ∈ X .Such collapsing rules can be eliminated by replacing them with all instances ℓσ f → xσ f for every f ∈ Σ where σ f (x) = f (x 1 , . . ., x n ) with x 1 , . . ., x n pairwise different, fresh variables.Proof.We introduce types for lab A (R) over the sorts A. For every symbol f λ ∈ lab A (Σ) with λ = a 1 , . . ., a ♯(f ) we define f λ to have input sorts a 1 , . . ., a n and output sort [[f ]](a 1 , . . ., a n ).Then [Ohl02, Proposition 5.5.24] with non-collapsingness of lab A (R) yields that lab A (R) is terminating if and only if all well-sorted terms are terminating.Since A is core there exists a well-sorted ground term for every sort in A. Thus by application of a ground substitution we can assume that all rewrite sequences contain only ground terms, and the set of well-sorted ground terms is exactly the language L(A) of the model A.
To apply Theorem 6.4 for proving local termination of R on a set of terms T we have to find a partial model A for R such that T ⊆ L(A).Then global termination of lab A (R) implies local termination of R on T .If moreover we have Fam(T ) = L(A), then the transformation is complete, that is, the converse implication holds as well.
Example 6.5.We revisit Example 3.7 on the S combinator with T = {S n | n ∈ N}.
The other labeled rules are thrown out as their left-hand side is undefined.Global termination of the transformed system can be shown by the recursive path order [Der82].

Starling and Owl
In this section we consider TRSs with the property that strong and weak normalisation coincide.In case the language of normalising terms happens to be regular, we show how a tree automaton (partial model) can be found accepting exactly the (closed) normalising terms.We automated this procedure.Then we label the TRS with the obtained partial model, and employ Theorem 6.4 to transform the local termination problem for the set of normalising terms to global termination of the labelled TRS.
Since in orthogonal, non-erasing term rewriting systems strong and weak normalisation coincide, these form a typical area where the method can be applied.In this section we illustrate this construction with two well-known examples from combinatory logic (CL) [Cur30].We use Smullyan's bird nicknames of the combinators [Smu90].
(1) The Owl, corresponding to the rewrite rule: also known as the fragment CL(S) of combinatory logic consisting of all terms solely built from application and the S-combinator.The termination problem of Smullyan's Owl has been solved in [Klo07].Here, it serves as illustrating example.
The termination problem of CL(S) is non-trivial, and its word problem is still open.In [Wal00] decidability of strong normalisation of terms in CL(S) has been shown, and we are aiming at a formal verification of the following proposition: ).The set of normalising ground S-terms is a rational language.
We now turn to the construction of the partial models.Definition 7.2.For a tree language L, its Nerode congruence ∼ L is the relation on ground terms given by t The next lemma follows easily by considering the Nerode congruence [CDG + 07].
Lemma 7.3.If a TRS R has the property that every ground term is weakly normalising if and only if it is strongly normalising, and N is the language of normalising ground terms, then • each congruence class of ∼ N is closed under R-rewriting and closed R-expansion, • the complement of N occurs as one of the ∼ N congruence classes.
Proof.Note that under the assumptions on R, for each term t ∈ N and each subterm s of a term in N we have s ∈ N .In other words, s / ∈ N implies C[s] / ∈ N .Also, for all ground terms t 1 , t 2 with t 1 → R t 2 we have t 1 ∈ N ⇐⇒ t 2 ∈ N .The claims follow.
In particular weak and strong normalisation of terms coincide for every orthogonal and non-erasing TRS; this applies for CL(S) as well as Smullyan's Owl.We note that the set of congruence classes of ∼ N can in general be infinite, even for orthogonal, non-erasing TRSs.
Example 7.4.We consider an example of an orthogonal, non-erasing TRS where the set of congruence classes of ∼ N is infinite.Let R consist of the rules: Thus, if the set of congruence classes of ∼ N is finite, then the set of normalising terms is a regular language.Assume that we are lucky and the set of congruence classes is finite.

How can we find the regular automaton accepting the set of normalising terms?
A manual analysis and construction of the automaton as in [Wal00] can be tedious and error-prone.The reference contains a hand-made tree grammar (top-down non-deterministic tree automaton A) and claims: • the S rule is locally terminating on L(A), • L(A) contains all normal forms, • A is closed under inverse application of the S rule.Starting from that grammar, we can indeed compute a bottom-up minimal deterministic tree automaton B with L(B) = L(A) (strangely, it has 39 states, and not 43, as claimed in the reference).
We propose a different, automatable approach for finding a regular automaton accepting the language of all normalising terms.The idea is to employ the definition of the Nerode congruence for 'guessing' the congruence classes.Here we use the word 'guess' in place of 'compute' since we need to check whether a term C[s] is terminating.This property is in general undecidable.We can, however, make an educated guess by choosing a large enough d and checking whether C[s] admits a rewrite sequence of length d with respect to some strategy ❀.Note that the strategy ❀ can be chosen arbitrarily since we assume that weak and strong normalisation coincide.Definition 7.6.[TeR03] A strategy ❀ for a TRS R is a relation ❀ ⊆ → R on Ter(Σ, X ) having the same normal forms as → R .A strategy ❀ is called deterministic if every term t has at most one reduct s, that is, t ❀ s.
The following algorithm searches for a partial model for the language of normalising terms.The algorithm depends on a strategy ❀ for R and parameters c, d ∈ N where c is the maximal depth of contexts C, and d is the length of ❀-reductions used to guess whether a term is normalising.
Instead of the full Nerode congruence of the set of R-normalizing terms, which might be undecidable, we use an decidable equivalence relation ∼ on terms given by s ∼ t iff for each context C[] of height ≤ c, either both C[s] and C[t] have a ❀-derivation of length at least d, or both don't.
Algorithm 7.7.Starting from the full relation ∼ 0 that relates all pairs of terms, we compute successive refinements ∼ 0 ⊃ ∼ 1 ⊃ . ... Each ∼ i is given as a finite set of representatives , where ∼ is the Nerode-like relation defined above.The ∼ i -equivalence class of non-normalizing terms is not explicitly represented.By Lemma 7.3, this is no loss of information.The full relation ∼ 0 is given by T 0 = ∅.We set T i+1 = T i ∪ {s} where s = f (s 1 , . . ., s a ), for a choice of function symbol f of arity a, and terms (s 1 , . . ., s a ) ∈ T a i , such that the ❀-derivation of s has length < d, and s ∼ t for each t ∈ T i .The algorithm stops if no such s can be found.
We remark that T 1 consists of one element, which is a term containing a nullary symbol only.Each ∼ i computed by this algorithm constitutes a partial algebra (on the carrier T i ), since each step of the algorithm defines one part of the interpretation of a function symbol.
The goal is that the output algebra is a partial model for R, exactly capturing the Nerode congruence.This may fail, for two reasons.If d is chosen too small, then a normalising term C[s] may mistakenly be considered non-normalising.If c is too small, then terms may accidentally be identified, although they behave differently when put into larger contexts.
Nevertheless, it can be shown that if the language of normalising terms is regular, then there exist appropriate parameters c and d such that the algorithm will compute the correct partial model, see Lemma 7.8.The case of having chosen c or d too small can be detected after running the algorithm as follows.Let A be the algebra computed by the algorithm.It can be effectively checked whether A is a partial model for R, and whether all undefined terms [[t]]  contain a redex with respect to R. Then it automatically follows that all undefined terms are non-normalising.Finally we can employ Theorem 6. 4

to transform the termination problem for all defined terms [[t]]
 into an equivalent global termination problem of lab A (R).If we find a termination proof for lab A (R), then the partial model A is correct and accepts exactly the language of normalising terms.
Lemma 7.8.Let R be a TRS such that every ground term is weakly normalising if and only if it is strongly normalising.If the language N of normalising terms is regular, then there exist appropriate parameters c and d such that Algorithm 7.7 computes the correct partial model accepting exactly N .
Proof.If the languages N is regular, then the set of congruence classes of ∼ N is finite.Let n = |Ter(Σ, ∅)/ ∼ N |, and let T ⊆ Ter(Σ, ∅) be the set of all ground terms of height ≤ n + 1.Then T contains at least one representative t D ∈ T for every D ∈ Ter(Σ, ∅)/ ∼ N .For every pair t D 1 , t D 2 of representatives with Let C be the set of these (finitely many) contexts.We choose for c the maximal depth of all contexts in C ∈ C, and for d the maximal length of a ❀-reduction of all normalising C[t] ∈ N with C ∈ C and t ∈ T .Then the choice of d guarantees that terms C[t] will not accidentally be identified as non-terminating, and the choice of c guarantees that all non-equivalent terms in T i will be distinguished.
We have implemented Algorithm 7.7; the Haskell source can be downloaded from: http://infinity.few.vu.nl/local/We have applied the algorithm on Smullyan's Owl and CL(S), obtaining in both cases the minimal partial algebra accepting the language of all normalising terms.Further details, including the respective partial models, are given below.
](x, y) for the Owl with x on the left and y on the top.
Examples for terms t ∈ L(A), that is, normalising terms, are δδδ . . .δ, δ(δδ . . .δ)δ . . .δ, and δ(δ(δδ)δδ)δδδ For an example of a non-normalising term take δδ(δδ).In words, the set of undefined (non-normalising) terms can be described as follows: a term is undefined if it contains two distinct occurrences of δδ.Note that the term δδδ . . .δ = (. . .((δδ)δ) . ..)δ contains only one occurrence of δδ (or @(δ, δ) in first-order notation).First, we check that A is a partial model for R: Second, we use induction on the term structure to show that every undefined term contains a redex.Let t ∈ Ter(Σ, ∅) be a term such that [[t]]  .Then by definition of [[ • ]] the term t is of the form t = @(t 1 , t 2 ) and either In the latter two cases it suffices to apply the induction hypothesis to t 1 or t 2 , respectively.Thus, let [[t 1 ]] = [[t 2 ]] = 1.We use induction on the term structure of t 1 .Again, by definition of and t = @(@(δ, t ′ 2 ), t 2 ), and hence t contains a redex.For [[t ′ 1 ]] = 1 we finish by applying the second induction hypothesis.
Example 7.10 (The set of normalising S-terms).For CL(S), Algorithm 7.7 returns the partial model , and the interpretation of @ is given in Table 2. Indeed, it can be checked that A is equivalent to the grammar given in [Wal00].
For proving that CL(S) is terminating on the language of A we have transformed the local into a global termination problem using Definition 6.3.The resulting TRS contains 1800 rules which are globally terminating, as can be shown using the DP transformation with SCC decomposition [AG00] together with simple projections and the subterm criterion [HM04].The termination proof can be found automatically, and formally verified using the current versions of CeTA (1.05) [TS09] and TTT2 (1.0) [KSZM09].

The RFC Method
We show that the method proposed in Section 6 is not only useful for local termination, but can fruitfully be employed for global termination as well.In [Der81], Dershowitz reduces global termination of right-linear TRSs to local termination on the set RFC(R), called the right-hand sides of forward closures of R. The set RFC(R) ⊆ Ter(Σ, X ) is a subset of all terms, weakening the proof obligation, and often allowing for simpler termination proofs.Previously, the only automated method employing this transformation for proving global termination has been the method of match-bounded string rewriting [GHW04].In the present paper we advocate an alternative approach.
We propose a combination of the RFC-method with the transformation from Section 6.More precisely, we first reduce the global termination problem to a local termination problem on RFC(R), and then we transform this problem back into a global termination problem.We show that this method can successfully be applied to obtain proofs for global termination; see further Example 8.3 for a rewrite system that remained unsolved in the termination competition [Ter08].
A string rewriting systems (SRS) R is a TRS R where all symbols f ∈ Σ of the signature are unary.We then use words a 1 . . .a n to denote terms a n (. . .a 1 (x)).
For SRSs R the set RFC(R) can be defined as follows: ).Let R be a SRS over Σ.The right-hand sides of forward closures of R, denoted RFC(R), are defined as the smallest set F ⊆ Σ * such that: • rhs(R) ⊆ F , • if u ∈ F and u → v, then v ∈ F (rewriting), and • if uℓ 1 ∈ F and ℓ 1 ℓ 2 → r ∈ R with ℓ 1 = ε, then ur ∈ F (right extension).
We have the following well-known theorem: Theorem 8.2 ([Der81]).A string rewriting system R is terminating on Σ * if and only if R is terminating on RFC(R).
The set RFC(R) can be (over-)approximated by using the system This is the mirrored version of SRS/Waldmann07b/size-12-alpha-3-num-223 which has not been solved automatically in previous termination competitions.We present a partial Σ # -algebra A with 3 elements A = {1, 2, 3} and interpretations of function symbols: and b(2) as well as all transitions from 3 are undefined.Note: we consider the right end of the string to be the top symbol of the term.It can be checked that A is a partial model for R ∪ R # , and its language contains rhs(R)#.As a consequence we have L(A) ⊆ RFC(R)#.
Formally, for the existence of ground terms, we add a fresh constant e with interpretation [[e]] = 1.This constant does not harm the property of A being a partial model for R ∪ R # , and does not affect the termination behaviour: since SRSs are linear, R ∪ R # is terminating on rhs(R)# if and only if R ∪ R # is terminating on {a n (. . .a 1 (e)) | a 1 . . .a n ∈ rhs(R)#}.We obtain the following labelled system: termination of which is equivalent to termination of R. Indeed R A is easily seen to be terminating.E.g., Torpa [Zan05] finds the following termination proof: [A] Choose polynomial interpretation a1 c1: lambda x.x+1, rest identity remove: a1 -> remove: c2 c1 -> a2 [AC] Reverse every lhs and rhs and choose polynomial interpretation: a1 and c1: lambda x.10x, rest lambda x.x+1 remove: a2 -> remove: b1 a1 -> c1 a2 c2 b1 b1 remove: b1 -> remove: c1 c2 -> a1 Terminating since no rules remain.For automating this method, the challenge is to find a partial model such that the resulting labelled total termination problem is easier than the original one.In particular, the domain of the partial algebra must be a proper subset of the full algebra (Σ * ).In our example, the domain excludes all words containing the factor bcb.

Monotone-models for Local Termination
In Sections 3-5 we have devised a characterisation of local termination in terms of monotone partial algebras.While this gives the general method, for the purpose of obtaining automatable methods we strive for fruitful classes of these algebras.For global termination, instances of monotone algebras are well-known.This raises the natural question whether we can transform a given monotone algebra for global termination in such a way that we obtain a partial monotone algebra for local termination.
In this section we present one such approach.We combine monotone partial models with (ordinary) monotone algebras.The monotone partial models are roughly deterministic tree automata that are closed under rewriting; they describe the language of term on which we proof termination.We search for such an automaton that accepts the starting language T together with a monotone algebra such that the rewrite rules decrease on the language of the automaton.In this way monotone algebras for global termination carry over to local termination, and we obtain an automatable method that is applicable for proofs of local termination.
First we give the definition of extended µ-monotone algebras as known from global termination of context-sensitive TRSs, see [Luc98,EWZ08].A mapping µ : Σ → 2 N is called a replacement map (for Σ) if for all f ∈ Σ we have µ(f ) ⊆ {1, . . ., ♯(f )}.Let A, [[ • ]] be a Σ-algebra and µ a replacement map.For symbols f ∈ Σ we say that the interpretation [[f ]] : A ♯(f ) → A is µ-monotone with respect to ≻ if for every a, b ∈ A and i ∈ µ(f ) with a ≻ b we have: f ( . . . ≥ may contain elements a ∈ A for which [[t]] = a implies that t is a normal form.For a given partial model the set of these, which we denote by A nf (R) , can be computed (see below Definition 9.2).We can exploit this knowledge as follows: if a certain argument of a symbol f ∈ Σ is always a normal form, then its interpretation [[f ]] does not need to be monotonic for this argument position.The following definition gives an algorithm for computing the set A nf (R) .Elements that are interpretations [[ℓ, α]] of left-hand sides in R cannot belong to this set.Moreover if a ∈ A nf (R) and b = [[f ]](. . ., a, . ..) then we conclude b ∈ A nf (R) .This is formalised as follows: Definition 9.2.Let R be a TRS over the signature Σ, and for every ℓ → r ∈ R and every α : Var (ℓ) → A c , and [[f ]](a 1 , . . ., a n ) ∈ A nf (R) for every f ∈ Σ, a i ∈ A nf (R) and a 1 , . . ., a n ∈ A c .
Then by construction we obtain the following lemma: Lemma 9.3.A nf (R) consists of all a ∈ A c for which every term t ∈ Ter(Σ, ∅) with [[t]] = a is a normal form with respect to R.
As mentioned above the interpretations do not need to be monotonic in argument positions which are normal forms.We formalise this by defining a replacement map for the labelling lab A (R) of R which does not contain argument positions that are in normal form.Definition 9.4.Let R be a TRS over Σ, and A = A, [[ • ]] a partial Σ-algebra.Let the replacement map µ nf (R) be defined for every symbol f λ ∈ lab A (Σ) with λ = a 1 , . . ., a ♯(f ) as follows: As an instance of Theorem 5.2 we obtain a method for stepwise rule removal for local termination that is based on a combination of monotone partial models and extended monotone algebras.Theorem 9.5.Let R, R ′ and U be TRSs over Σ, and T ⊆ Ter(Σ, ∅) a set of terms such that SN U/R∪R ′ (T ) holds.Furthermore let Proof.We construct an extended well-founded monotone partial Σ-algebra  , and ↑ otherwise.Finally, we define the relation ❀ on C by a 1 , b 1 ❀ a 2 , b 2 ⇐⇒ a 1 ≥ a 2 .Now it is straightforward to check that all requirements of Theorem 5.2 are fulfilled, and we conclude SN (U ∪R ′ )/R (T ).
Let us briefly elaborate on the theorem.As an instance of Theorem 5.2, Theorem 9.5 is applicable for proving local termination as well as local relative termination.We start without knowledge SN ∅/R∪S (T ) and stepwise 'remove' rules, more precisely, we move rules from the right side to the left side of the slash '/'.If we reach the goal SN R/S (T ), then the proof has been successful.
The use of partial monotone partial models for R ∪ R ′ ∪ U with T ⊆ L(A) guarantees that the language we consider is closed under rewriting.The set R ′ is the set of strictly decreasing rules that we are aiming to remove.The µ nf (R∪R ′ ) -monotone lab A (Σ)-algebra B then has the task to make all labelled rules stemming from R ′ strictly decreasing (≻), and from R weakly decreasing (⊒).Then we conclude that R ′ ∪ U is terminating relative to R on T .
The second example illustrates the stepwise rule removal.
Example 9.7.We use a Turing-machine-like TRS which does the following.Starting with its head between two symbols 1, the tape containing a finite string of 1's and further blanks (0), it initially puts two boxes ✷ left and right of its head and afterwards alternately runs left and right between the boxes, each time moving them one position further, until the blanks are reached: This is implemented by the TRS R consisting of the following rules: where all symbols apart form finish (which is a constant) are unary, but have been written without parenthesis for the purpose of compactness.Note that the construction of the TRS is similar to the standard translation of Turing machines to string rewriting systems as given in [TeR03].
While the Turing machine is terminating on every input, the TRS R fails to be globally terminating.The reason is that R allows for configurations with multiple heads working at the same time on the same tape: 0✷R✷1F ✷0 → 0✷L1✷F ✷0 → 0✷L✷1R✷0 → 2 0✷R✷1F ✷0 → . . .We will prove that R is locally terminating on all terms containing arbitrary occurrences of the symbols 0, 1 and at most one occurrence of S, that is, the language given by T = {0, 1} * S {0, 1} * finish.As the first step we remove the rules 1S1 → ✷R✷ and 0✷F → finish.We do this by using a monotone model A consisting of only one element, accepting all terms.We combine this model with the lab A (Σ)-algebra B where B = N and [[1]] B (x) = [[0]] B (x) = x + 1, all other symbols are interpreted as λx.x.This makes the above two rules decreasing (≻ is a model for them).
In the second step, we use a partial model A = A, [[ • ]], ≥ where A = {0, 1}, 0 ≥ 0, 1 ≥ 1 (but not 1 ≥ 0), [[finish]] = 0 and the other interpretations are given in Table 3: As required by the theorem A is a monotone partial model for R including the two removed rules U = {1S1 → ✷R✷, 0✷F → finish} (without them T would consist of normal forms).
The three remaining rules R1 → 1R, 1F → F 1, and R✷0 → F ✷0 are even globally terminating.This corresponds to taking a model which has only one state and accepts all terms together with the corresponding termination order which proves global termination.Hence we have proven SN R (T ) by three consecutive applications of Theorem 9.5.
Finally, we give a theorem that allows us to remove rules and forget about them.We need to be sure that these rules do not influence the family, that is, the set of reachable terms.This is guaranteed if all terms in the family are normal forms with respect to these rules.
Proof.From Fam R∪R ′ ∪S (T ) ⊆ L(A) together with [[ℓ, α]]  for all ℓ → r ∈ R ′ and α it follows that the rules in R ′ are not reachable.All terms in Fam(T ) are normal forms with respect to R ′ .Hence we can ignore these rules.

Conclusion and Future Work
We have implemented some of the methods proposed in this paper.More information and the source code of the implementations can be found on the website: http://infinity.few.vu.nl/local/In particular, we have implemented the method from Section 7. The program automatically finds the minimal partial model A for the language of normalizing S-terms, and transforms the local termination problem into a global termination problem.We have formally verified the model property, and that all terms that are not in the language of A are non-terminating.Global termination of the transformed system has been proven by TTT2 (1.0) [KSZM09] and formally verified by CeTA (1.05) [TS09].Thereby we have automated one of the central contributions of [Wal00].
Methods using transformations from certain properties, like liveness properties [Kop08] or outermost termination [RZ09], to termination usually give rise to local termination problems.That is, termination is of interest only for those terms which are in the image of the transformation.For example, we noted that the transformation in [RZ09] gives rise to a language which can be described by a partial model.Then it suffices to show completeness of the transformation to local termination, and employing Theorem 6.4 we obtain a complete transformation to global termination for free.
containing precisely one occurrence of [].By C[s] we denote the term Cσ where σ([]) = s and σ(x) = x for all x ∈ X .
Definition 3.1.Let A be a set and → ⊆ A × A a binary relation on A. Then → is called terminating on B ⊆ A if no b ∈ B admits an infinite sequence b = b 1 → b 2 → . . .Note that b = b 1 ∈ B. The elements b 2 , b 3 , . . ., however, may or may not be in B.
For the current example we can choose the 'total' relation ❀ = {(n, m) | n, m ∈ N} relating all pairs of natural numbers.Then ❀ is a partial model for U 1 , and all [[f ]] for f ∈ Σ are closed and monotone with respect to ❀.

Theorem 6. 4 .
Let R be a non-collapsing TRS over Σ, and A = A, [[•]] a core partial model for R. Then R is locally terminating on L(A) if and only if lab A (R) is globally terminating.
over the signature Σ = {a, b, c, d} with d a constant.Here, terms of the from c(a n (b n (c(d)))) are non-terminating, while all terms of the form c(a n (b m (c(d)))) with n = m are terminating.Hence none of the terms b n (c(d)) for n ∈ N can be in the same congruence class of ∼ N .Corollary 7.5.If the set of congruence classes of ∼ N is finite, then the minimal complete deterministic bottom-up tree automaton for N is finite and a model for R.
where # acts as an end marker.Then RFC(R)# = (R∪R # ) * (rhs(R)#), and we can reduce the global termination problem of R to local termination of R ∪ R # on rhs(R)#.More generally we have the following observation: whenever M ⊇ rhs(R)# is closed w.r.t.R ∪ R # , then RFC(M )# ⊆ M .The closure under rewriting can be proven by giving a partial model A (M is the language of a partial Σ # -algebra A).Example 8.3.Take Σ = {a, b, c} and R = {a → ǫ, b → ǫ, cc → a, ba → cacbb}.