Redundancy, Deduction Schemes, and Minimum-Size Bases for Association Rules

Association rules are among the most widely employed data analysis methods in the field of Data Mining. An association rule is a form of partial implication between two sets of binary variables. In the most common approach, association rules are parameterized by a lower bound on their confidence, which is the empirical conditional probability of their consequent given the antecedent, and/or by some other parameter bounds such as"support"or deviation from independence. We study here notions of redundancy among association rules from a fundamental perspective. We see each transaction in a dataset as an interpretation (or model) in the propositional logic sense, and consider existing notions of redundancy, that is, of logical entailment, among association rules, of the form"any dataset in which this first rule holds must obey also that second rule, therefore the second is redundant". We discuss several existing alternative definitions of redundancy between association rules and provide new characterizations and relationships among them. We show that the main alternatives we discuss correspond actually to just two variants, which differ in the treatment of full-confidence implications. For each of these two notions of redundancy, we provide a sound and complete deduction calculus, and we show how to construct complete bases (that is, axiomatizations) of absolutely minimum size in terms of the number of rules. We explore finally an approach to redundancy with respect to several association rules, and fully characterize its simplest case of two partial premises.


Introduction
Termination is a key aspect of program correctness, and therefore a widely studied subject in term rewriting and program verification.While termination is undecidable in general, various automated techniques have been developed for proving termination.One of the most powerful techniques is the method of dependency pairs [AG00].In [AGL06] dependency pairs for context-sensitive rewriting have been introduced, and in [AEF + 08] the dependency pair framework [GTSK04,Thi07,GL10] has been extended to context-sensitive rewriting, thereby extending the class of context-sensitive TRSs for which termination can be shown automatically.Context-sensitive rewriting [Luc98] is a restriction on term rewriting where rewriting in some fixed arguments of function symbols is disallowed.It offers a flexible paradigm to analyze properties of rewrite strategies, in particular of (lazy) evaluation strategies employed by functional programming languages.
In this paper context-sensitive rewriting is the target formalism for a transformational approach to the problem of outermost termination, that is, termination with respect to outermost rewriting.Outermost rewriting is a rewriting strategy where a redex may be contracted as long as it is not a proper subterm of another redex occurrence.The main reason for studying outermost termination is its practical relevance: lazy functional programming languages like Miranda [Tur86], Haskell [PJ03] or Clean [PvE01], are based on outermost rewriting as an evaluation strategy, and in implementations of rewrite logic such as Maude [CELM96] and CafeOBJ [FN97], outermost rewriting is an optional strategy.
To illustrate outermost rewriting, and the transformations we propose, we consider the term rewriting system R 0 consisting of the following rules: Clearly, this system is not terminating, as witnessed by the infinite rewrite sequence: However, R 0 is outermost terminating.Indeed, the third step in the rewrite sequence above is not an outermost step, since the contraction takes place inside another redex.The only (maximal) outermost rewrite sequence the term a admits is: The contribution of the present paper consists of two transformations of arbitrary TRSs into context-sensitive TRSs (henceforth also called 'µTRSs') in such a way that rewriting in the µTRS corresponds to outermost rewriting in the original TRS.As a result, advanced termination techniques for µTRSs become available for proving outermost termination.Automated termination provers for µTRSs can directly (without modification, only preprocessing) be used for proving outermost termination.One of the transformations turns out to be complete for the class of quasi-left-linear TRSs, a generalized form of left-linear TRSs, see [RZ09].In other words, termination of the resulting µTRS is equivalent to outermost termination of the original system.
The transformations are comprised of a variant of semantic labeling [Zan95].In semantic labeling the function symbols in a term are labeled by the interpretation of their arguments (or a label depending on these values) according to some given semantics.We employ semantic labeling to mark symbols at redex positions, and then obtain a µTRS by defining a replacement map that disallows rewriting inside arguments of marked symbols.
We illustrate our use of semantic labeling by means of the TRS R 0 given above.We choose an algebra with values 0 and 1, indicating the presence of the symbol f: We write f ⋆ , and say that 'f is marked', if the value of its argument is 1, and just f if the value is 0. The symbol a is a redex, and hence it is always marked, while b never is.If f is marked it corresponds to a redex position with respect to the rule f(f(x)) → b.For example the term f(f(f(a))) is labeled as f ⋆ (f ⋆ (f(a ⋆ ))).We obtain a µTRS by forbidding rewriting inside the argument of the symbol f ⋆ .Since a ⋆ is a constant, there is nothing to be forbidden.Hence for correctly labeled terms, rewriting inside redex occurrences is disallowed, and this corresponds to the strategy of outermost rewriting.
In order to rewrite labeled terms we have to label the rules of a TRS.Simply labeling both sides of a rule does not always work.For example, when we label the rules of R 0 using the algebra A 0 , we obtain the following µTRS: This system has two instances of the second rule, one for each possible value assigned to the variable x.Now, despite of the fact that the original TRS is outermost terminating, the labeled system R 0 still admits an infinite rewrite sequence: The reason is that the term f(f(a ⋆ )) is not correctly labeled, as its root symbol f should have been marked.In [Zan95] this problem is avoided by allowing labeling only with models.
Roughly speaking, an algebra is a model for a TRS R if left and right-hand sides of all rewrite rules of R have equal interpretations.However, this requirement is too strict for the purpose of marking redexes, because contraction of a redex at a position p may create a redex above p in the term tree, as exemplified by (1.2).In fact, for R 0 there exists no model which is able to distinguish between redex and non-redex positions.Let us explain.The rewrite step f(a) → f(f(a)) creates a redex at the top.The term f(a) is not a redex, and therefore its root symbol f should not be marked.On the other hand f(f(a)) is a redex and so the outermost f has to be marked.The change of the labeling of a context (here f(✷)) implies that the interpretation of its arguments a and f(a) cannot be the same.Therefore we cannot require the rule a → f(a) to preserve the interpretation.
To that end, we generalize this notion of model and relax the condition ℓ = r to: Thus rules are allowed to change the interpretation as long as the effect is limited to contexts of a bounded depth.We call this depth the C-depth of ℓ → r and denote it by δ A (ℓ → r).
As it turns out, algebras satisfying this weaker requirement (1.3), are strong enough to recognize redex positions.Such algebras we will call C-models.
The algebra A 0 given above is a C-model for the TRS R 0 .As opposed to models, for C-models it is no longer sufficient to simply label the rules.This is demonstrated by the rewrite sequence (1.2) in the µTRS R 0 : an application of the rule a ⋆ → f(a ⋆ ) in the term f(a ⋆ ) creates the incorrectly labeled term f(f(a ⋆ )).
Therefore, in order to preserve correct labeling, labels in the context of the original rewrite step sometimes have to be updated.We present two solutions to this problem: the transformation of context extension and the transformation of dynamic labeling.
In the transformation based on context extension [EH09], worked out in Section 5, the update of semantic labels is established by prefixing appropriate contexts to both sides of a rewrite rule.The depth of these contexts is bounded by the C-depth of the rule.Thus, the update of the labels is coded within the context, and no additional rewrite steps are needed.As a result of that, every outermost rewrite step in the original system is modeled by exactly one rewrite step in the transformed µTRS.A disadvantage of the transformation, however, is that the resulting µTRS can have a large number of rules arising from the prepending of contexts in combination with semantic labeling.
An alternative solution (and new with respect to [EH09]) is dynamic labeling, described in Section 6: instead of extending rules with contexts we now use rewriting to propagate the changed information upward in the term tree.With respect to context extension, this approach results in a smaller number of rules of the transformed system.On the other hand, the property of the context extension of a one-to-one correspondence of the rewrite steps, is now weakened to a one-to-m correspondence where m ≤ 1 + δ A (ℓ → r).This means that an outermost rewrite step is modeled by one step in the transformed system plus a number of auxiliary steps necessary for updating the labels, and this number is bounded by the C-depth of the corresponding rule.In most practical cases this value is typically small (≤ 2).This is shown in Section 10 where we evaluate the implemented transformations.
We illustrate the two transformations by means of our running example, the TRS R 0 together with the algebra A 0 which forms a C-model for R 0 .The algorithm based on context extension transforms R 0 into the following µTRS △ π R 0 , which truthfully simulates outermost rewriting in R 0 : . This enables correct updating of the labeling of the context during rewriting.Because we still have to allow rewrite steps a → f(a) of the original TRS at the top of a term, we extend the signature with a unary function symbol top which represents the top of a term.Thus when prepending contexts we include top(✷), giving rise to the rule top(a ⋆ ) → top(f(a ⋆ )).
The necessity of the symbol top becomes apparent especially when we consider the rule is not an outermost rewrite step; this rule can only be applied at the top of a term.Hence we get the two rules displayed on the right, one for each possible interpretation of the variable x.
The second algorithm we define, that of dynamic labeling, transforms R 0 (using A 0 ) into the following µTRS , which we denote by ↑ π R 0 : where rewriting beneath the redex symbol f ⋆ and the symbols relabel 0,1 and relabel 1,0 is disallowed.Displayed on the left, we recognize the original rules.Since left and righthand side of the original rule a → f(a) have distinct interpretations (0 and 1), in ↑ π R 0 the right-hand side is prefixed with the symbol relabel 0,1 .By application of the relabeling rules (displayed on the right), this symbol moves upward to take care of the update of labels in the context of the original rule application.Likewise, the rule f(f(x)) → b (of which there are two versions in ↑ π R 0 , one for each value x can be assigned to) means a change of interpretation, and relabeling the context is necessary.In this example, each original step is accompanied by exactly one relabel step.The relabel symbols dissolve after one such step.The only (maximal) rewrite sequence from the term top(a ⋆ ) in ↑ π R 0 is: Notice the correspondence with the outermost rewrite sequence (1.1).
Clearly, semantic labeling increases the number of rules and the number of symbols of a TRS.This results in a larger search space for finding termination proofs, and hence may lead to exhaustion of time or memory resources.On the other hand, one can say that semantic labeling does not complicate termination proofs, in the sense that proofs for the unlabeled system carry over to the labeled one: whenever R ′ is a labeling of a TRS R and A = A, • , ≻, ⊒ is a monotone Σ-algebra [EWZ08] which proves termination of R, then the extension of • to the labeled signature Σ ′ by defining f λ = f for every f ∈ Σ and label λ, yields a monotone Σ ′ -algebra witnessing termination of R ′ .Apart from this, the labeled systems often allow for simpler proofs, because the enriched signature provides for more freedom in the choice of interpretations, see [Zan95].As the transformations presented here are based on a variant of semantic labeling, they inherit these properties from semantic labeling.
The two transformations have been implemented by the first author in the termination prover Jambox [End09].Notwithstanding the increased number of rules by semantic labeling and context extension, Jambox performs efficiently on the set of examples from the Termination Problem Database (TPDB [Ter08]), and was best in proving termination in the category of outermost rewriting of the termination competition of 2008 [Ter08], see Section 10.

Related work.
The first tool for proving outermost termination was Cariboo [FGK02,GK09].Cariboo is a stand-alone tool, and its method is based on induction.
For the idea of a transformational approach to outermost termination in order to make use of the power of termination provers we were inspired by [RZ09], which in turn is based on ideas in [GM04].In [RZ09] the signature is enriched with unary symbols top, up, and down and the TRS is extended with 'anti-matching' rules such that down(t) is a redex if and only if t is not a redex with respect to the original TRS.The idea is that the symbol down is moved down in the term tree as long as no redex is encountered.Once a redex is encountered, a rewrite step is performed, and the symbol down is replaced by up, which then moves upwards again to the top of the term, marked by top.This transformation is implemented in the tool TrafO [RZ09], participant in the termination competion of 2008 [Ter08].
Based on a similarly elegant idea, Thiemann [Thi09] defines a complete transformation from outermost to innermost rewriting, which is implemented in AProVE.For traversal to the redex positions, rules of the form down(isRedex(f(. ..))) → f(. . ., down(isRedex(. ..)), . ..) are used.In order to simulate outermost rewriting and to prevent from moving inside redexes, rules isRedex(ℓ) → up(r) are added for every rule ℓ → r of the original TRS.Then, by the innermost rewriting strategy, the latter rules have priority over the traversal rules, whenever an original redex is encountered.
The simplicity of both approaches is attractive, but the yo-yoing effect in the resulting TRSs makes that the original outermost rewrite steps are 'hidden' among a vast amount of auxiliary steps.This increases derivational complexity, and makes it hard for automated termination provers to find proofs for the transformed systems.
The present paper is a modified and extended version of [EH09].In particular, we introduce a novel approach for proving outermost termination: dynamic labeling (Section 6).We stress that the number of extra relabeling steps introduced in the dynamic labeling of a system is typically small and bounded by the C-depth of the applied rewrite rule.

Preliminaries
For a general introduction to term rewriting and to context-sensitive rewriting, we refer to [Ter03] and [Luc98], respectively.Here we repeat some of the main definitions, for the sake of completeness, and to fix notations.
A signature Σ is a non-empty set of symbols each having a fixed arity, given by a mapping ♯ : Σ → N. We write ♯f for the arity of f ∈ Σ, and we define Σ n = {f ∈ Σ | ♯f = n}.Given Σ and a set X of variables, the set T (Σ, X ) of terms over Σ is the smallest set satisfying: X ⊆ T (Σ, X ), and f(t 1 , . . ., t n ) ∈ T (Σ, X ) if f ∈ Σ of arity n and t i ∈ T (Σ, X ) for all 1 ≤ i ≤ n.We use x, y, z, . . . to range over variables, and write Var (t) for the set of variables occurring in a term t.
The set of positions Pos(t) ⊆ N * of a term t ∈ T (Σ, X ) is defined as follows: We write root (t) to denote the root symbol (or variable) of t, and t| p for the subterm of t rooted at position p.Then root (t| p ) is the symbol at position p in t.
A substitution σ is a map σ : X → T (Σ, X ) from variables to terms.For terms t ∈ T (Σ, X ) and substitutions σ, tσ is inductively defined by xσ = σ(x) for x ∈ X , and Let ✷ be a fresh symbol, i.e., ✷ ∈ Σ ∪ X .A context C is a term from T (Σ, X ∪ {✷}) containing precisely one occurrence of ✷.By C[s] we denote the term Cσ where σ(✷) = s and σ(x) = x for all x ∈ X .We use C(Σ, X ) to denote the set of contexts over Σ and X .We write Var (C) with C ∈ C(Σ, X ) to denote the set of variables of C excluding ✷.The depth of a context C is defined as the length |p| of the position p at which ✷ resides, that is, the position p such that root (C| p ) = ✷.
A term rewriting system (TRS) over Σ is a finite set of pairs ℓ, r ∈ T (Σ, X )×T (Σ, 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 ℓ: Var (r) ⊆ Var (ℓ).For a TRS R we define → R , the rewrite relation induced by R as follows: For terms s, t ∈ T (Σ, X ) we write s → R t, or just s → t if R is clear from the context, if there exists a rule ℓ → r ∈ R, a substitution σ and a context C ∈ C(Σ, X ) such that s = C[ℓσ] and t = C[rσ]; we sometimes write s → R,p r to explicitly indicate the rewrite position p, i.e., when root (C| p ) = ✷.A term of the form ℓσ, for some rule ℓ → r ∈ R, and a substitution σ, is called a redex.
For terms s and t, we say that s outermost rewrites to t at a position p ∈ Pos(s), denoted by s out → R,p t, if s → R,p t and for all positions p ′ strictly above p (i.e., p ′ a proper prefix of p) we have that s| p ′ is not a redex with respect to R.
A binary relation ≻ ⊆ A × A over a set A is called well-founded if no infinite decreasing sequence a 1 ≻ a 2 ≻ a 3 ≻ . . .exists.A TRS R is called terminating or strongly normalizing, denoted by SN(R), if → R is well-founded.
A mapping µ : Σ → 2 N is called a replacement map (for Σ) if for all symbols f ∈ Σ we have µ(f) ⊆ {1, . . ., ♯f}.When we define a replacement map µ, the case for constants a ∈ Σ is left implicit, as we always have µ(a) = ∅.A context-sensitive term rewriting system (µTRS) is a pair R, µ consisting of a TRS R and a replacement map µ.The set of µ-replacing positions Pos µ (t) of a term t ∈ T (Σ, X ) is defined by In context-sensitive term rewriting only redexes at µ-replacing positions are contracted: we say s µ-rewrites to t, and denote it by s → R,µ t whenever s → R,p t with p ∈ Pos µ (s).For instance, consider the system R consisting of the single rule: a → cons(b, a) and let µ be given by µ(cons) = {1}.Then, obviously R is non-terminating.On the other hand, the context-sensitive TRS R, µ is terminating, because the replacement map of the symbol cons allows rewriting only in its first argument.
We conclude this section by defining some non-standard notions.
Definition 2.1.A thin context is a context that has at every depth at most one symbol from Σ ∪ {✷}; all other symbols are variables.
Example 2.2.f(f(x, g(✷)), y) is a thin context, whereas f(g(✷), h(x)) is not, since g and h are at the same depth.

Definition 2.3 ([SM08]
).A flat context is a context C ∈ C(Σ, X ) of the form: where f ∈ Σ n with n > 0 and x 1 , x 2 , . . .∈ X are pairwise distinct variables.For a term t ∈ T (Σ, X ) we say that C is fresh for t if Var (C) ∩ Var (t) = ∅.We denote the set of flat contexts fresh for t by C ♭ t (Σ, X ).Definition 2.4 ([RZ09]).A TRS R is called quasi-left-linear if every non-linear left-hand side of a rule in R is an instance of a linear left-hand side from R.

Generalizing Models to C-models
In outermost rewriting the only redexes which are allowed to be rewritten are those which are not nested within any other redex occurrence.We model this strategy by contextsensitive rewriting with the use of semantic labeling: we mark the symbols which are the root of a redex in order to disallow rewriting within that redex.We first recall the definition of semantic labeling and of models from [Zan95], and then generalize these to fit our purpose.Definition 3.1.A Σ-algebra A = A, • consists of a non-empty set A, called the domain of A, and for each n-ary symbol f ∈ Σ a function f : A n → A, called the interpretation of f.Given an assignment α : X → A of the variables to A, the interpretation of a term t ∈ T (Σ, X ) with respect to α is denoted by t, α and inductively defined by: where x ∈ X , f ∈ Σ n , and t i ∈ T (Σ, X ) for 1 ≤ i ≤ n.For substitutions σ : X → T (Σ, X ), we write σ, α for the function λx.σ(x), α .For ground terms t ∈ T (Σ, ∅) and ground substitutions σ : X → T (Σ, ∅) we write t and σ for short.We usually write A for both the algebra and its domain, and we use • to denote the interpretation function of A.
For completeness of the transformation of context extension (Theorem 5.13), it is important that there exist no 'junk' elements in the Σ-algebra, that is, elements a for which there are no ground terms t such that t = a.See Example 5.14.For that reason we restrict Σ-algebras to 'core' Σ-algebras whose domain equals the set of all interpretations of ground terms over Σ.
Definition 3.3.The core of a Σ-algebra A is the Σ-algebra A c = A c , • c where A c is the least set such that f (a 1 , . . ., a n ) ∈ A c whenever f ∈ Σ n and a 1 , . . ., a n ∈ A c , and where • c is the restriction of • to A c .We say that A is core whenever A = A c .
By construction of the core of a Σ-algebra we then obtain: Lemma 3.4.For every element a ∈ A c of the core of a Σ-algebra A there exists a ground term t ∈ T (Σ, ∅) with t = a.
Let R be a TRS over Σ.The semantic labeling of R is the TRS lab(R) over the labeled signature lab For a substitution σ : X → T (Σ, X ), and an assignment α : X → A, we write lab(σ, α) for the function λx.lab(σ(x), α).For ground terms t ∈ T (Σ, ∅) and ground substitutions σ : X → T (Σ, ∅) we write lab(t) and lab(σ) for short.
Term labeling satisfies the following useful property: Zan95]).Let A be a Σ-algebra, let α : X → A be an assignment, and let σ : X → T (Σ, X ) be a substitution.Then, for all terms t ∈ T (Σ, X ) it holds that: Proof.Direct by induction on the term structure, and Lemma 3.2.
The Σ-algebra of a semantic labeling has to satisfy certain constraints in order to obtain that a TRS is terminating if and only if its labeled version is.In [Zan95] the algebra has to be a 'model': Definition 3.7.A Σ-algebra A is called a model for a TRS R if for all rules ℓ → r ∈ R and assignments of variables in the left-hand side α : Var (ℓ) → A we have that ℓ, α = r, α .
In the introduction we argued why this notion of model is too restrictive for the purpose at hand.In order to be able to distinguish between redex and non-redex positions we introduce C-models, a generalization of models.Definition 3.8.A C-model for a TRS R over Σ is a Σ-algebra A where for each rule ℓ → r ∈ R there exists an n ∈ N such that for each context C of depth n and assignment α : When n ∈ N is minimal for a rule ℓ → r with respect to this property, we call n the C-depth for ℓ → r, and denote it by δ A (ℓ → r).The C-depth for R with respect to A, denoted by δ A (R), is defined as the maximal C-depth of the rules of R: δ Example 3.9.Let R 1 be the following TRS over Σ = {c, f, g} (where c is a constant): The algebra A 1 = {⊥, f, ff , g} with the interpretation function defined, for all x ∈ A 1 , by: forms a C-model for R 1 .The C-depth of the rule f(g(x)) → f(f(g(x))) is 1; both contexts f(✷) and g(✷) make that left and right-hand side of the rule have equal interpretations, respectively ff and g, regardless of the value we assign to the variable x.For the other rule the C-depth is 2: If the interpretation of x is ⊥ or g then f(✷) is not yet enough to interpret both sides by the same element of the algebra; an additional context f(✷) or g(✷) has to be wrapped around.Thus the C-depth of the TRS is δ A 1 (R 1 ) = 2.
We now define semantic labelings based on C-models, to which we refer as 'C-labelings'.We define a C-labeling over an extended signature Σ top = Σ ∪ {top}.The symbol top represents the top of a term, and we assume top to be fresh for Σ, i.e., top ∈ Σ.Moreover, a C-labeling includes a set Σ red ⊆ lab(Σ) of 'redex symbols', the set of symbols below which rewriting should be forbidden.For example, for a sound transformation from outermost to context-sensitive rewriting it has to be guaranteed that in a well-labeled term the symbols from Σ red occur at redex positions only.
Definition 3.10.Let R be a TRS over Σ.A C-labeling for R is a tuple A, π, Σ red where A is a C-model for R, A, π is a semantic labeling over the signature Σ top = Σ ∪ {top}, and Σ red ⊆ lab(Σ) is a subset of the labeled signature.We fix the interpretation top of top to be an arbitrary constant function λx.a for some a ∈ A.
A C-labeling A, π, Σ red for R is called: (i) sound if root (lab(t)) ∈ Σ red implies that t is a redex with respect to R, for all ground terms t ∈ T (Σ, ∅); (ii) complete if root (lab(t)) ∈ Σ red whenever t is a redex with respect to R, for all ground terms t ∈ T (Σ, ∅); (iii) maximal if π f (a 1 , . . ., a n ) = a 1 , . . ., a n , for all symbols f ∈ Σ n and all values a 1 , . . ., a n ∈ A ; (iv) core if the Σ-algebra A is core.
Remark 3.11.From Definition 3.10 it follows that a C-labeling A, π, Σ red for R is: − sound if and only if root (lab(t)| p ) ∈ Σ red implies that t| p is a redex with respect to R, for all ground terms t ∈ T (Σ, ∅) and all positions p ∈ Pos(t), and − complete if and only if root (lab(t)| p ) ∈ Σ red whenever t| p is a redex with respect to R, for all ground terms t ∈ T (Σ, ∅) and all positions p ∈ Pos(t).
Example 3.12.We continue with Example 3.9 where we defined a C-model A 1 for the TRS R 1 .We let A 1 , π be the semantic labeling where π labels each symbol with the interpretation of its arguments.The set of redex symbols is defined by Σ red = {f g , f ff }.These symbols correspond to redex positions with respect to the first and the second rule of R 1 .Then A 1 , π, Σ red forms a sound, complete, maximal, core C-labeling for R 1 .
We explain why we fix the interpretation top to be a constant function.First note that if top is a constant function, then the extension of the signature with top does not interfere with the property of A being a C-model for R. Second, the transformation given in Section 5 extends the rules with contexts until the interpretations of the left and right-hand side are equal.If top is constant, then the extension halts at the symbol top, that is, no further contexts are prefixed to top.This corresponds to the intuition of top representing the top of the term.Moreover, it is not important which constant function λx.a we choose for top : as no symbols will be prefixed to top, no symbol will be labeled with its value.
Remark 3.13.The transformations defined in Sections 5 and 6 are sound whenever we use a sound C-labeling.This means that termination of the target system implies outermost termination of the original system.On the other hand, using a complete C-labeling does not guarantee completeness of either transformations.More precisely, using a complete C-labeling does not imply that the transformed system is terminating whenever the original system is outermost terminating.A complete C-labeling guarantees that in a correctly labeled term all redex positions are marked, so that only outermost steps are possible.But, for the transformation to be complete we need two more properties.First, rewriting needs to preserve correct labeling of terms.Secondly, for the labeled system, global termination of all terms (including the not correctly labeled ones) should be equivalent with local termination [EdVW09] of the well-labeled terms.This point is of practical importance because the state of the art of automated analysis for global termination is far more advanced than for local termination.Both properties do in general not hold for complete C-labelings.
Remark 3.14.Maximal C-labelings can be defined in a more general fashion by requiring π f ( a ) = π f ( b ) for all f ∈ Σ n and all a , b ∈ A n with a = b .The important point is that the value of all arguments can be inferred from the label.For the sake of a simple presentation we stick to the definition where labels are tuples of argument values.

Static Context Extension
In this section we describe a naive approach for semantic labeling with C-models.This serves both as an introduction and as a motivation for the transformations that we present in Sections 5 and 6.Input for these transformations is a TRS together with a C-model for this TRS.In Sections 7-9 we explain how C-models are constructed.
As can be inferred from Definition 3.8, it is possible to transform a TRS R by prepending contexts to its rules in such a way that its C-model A becomes a model for the transformed system R, and then apply the usual semantic labeling to R. We call this transformation 'static context extension', as opposed to the transformation of 'dynamic context extension' presented in the next section.In the dynamic version, contexts are prepended only when needed and dependent on the values assigned to the variables in the rules.
Since every context is an instance of a thin context (Definition 2.1) with the same depth, rules are prefixed by thin contexts, in both versions of context extension.Definition 4.1.Let R be a TRS and A, π, Σ red a C-labeling for R. The static context extension of R with respect to A, π, Σ red , is the µTRS △ S π R, µ where △ S π R is the TRS resulting from the steps listed below and where the replacement map µ is defined by µ We let R denote the union of these sets.(ii) Apply semantic labeling to R using the C-labeling A, π .We obtain lab( R). (iii) Remove from lab( R) all labeled rules that contain a redex symbol from Σ red in the prepended context.The TRS thus obtained is denoted by △ S π R.
Note that the rules from item i(b) of Definition 4.1 model the application of an original rule at a depth smaller than its C-depth, that is, 'near' the top of the term.The created rules are hence wrapped into top(✷).
Example 4.2.We illustrate the transformation by static context extension on the TRS R 1 : together with the C-model A 1 = {⊥, f, ff , g} introduced in Example 3.9 and the C-labeling A 1 , π, Σ red defined in Example 3.12.The first step of the transformation yields R1 which consists of the following 10 rules: where C ∈ {top(✷), f(✷), g(✷)}, and Note that the algebra A 1 extended with the symbol top and interpretation top (x) = ⊥ for all x ∈ A 1 , is a model for the TRS R1 (in fact, any value for the interpretation of top will do).The second step is to label the TRS R1 .This yields lab( R1 ) consisting of 4•(3+ 7) = 40 rules, four instances for each of the ten rules, one for each value that can be assigned to x.
The final step is to remove from lab( R1 ) each rule which contains a redex symbol within the context that was prepended in the construction of R1 .Such a rule would enable a rewrite step which is not outermost.Of the 40 rules of above, 12 have to be thrown out.This concerns the labelings of the second rule of R 1 where f(f(✷)), top(f(✷)) or g(f(✷)) has been prepended.They contain the redex symbol f ff in the prepended context.For instance, if we prepend the thin context f(f(✷)) to the rewrite rule f(g(x)) → f(f(g(x))) and then perform semantic labeling, we obtain the following rule in lab( R1 ): This rule (with the redex symbol f ff in the prepended context) has to be discarded as it would admit the following infinite rewrite sequence, altough R 1 is outermost terminating: We note in advance that the dynamic context extension △ π R 1 of R 1 , worked out in Example 5.1, consists of 19 rewrite rules, whereas the static version △ S π R 1 above consists of 28 rules.
In general, the presence of a redex symbol may depend on the interpretation of the variables.This is better demonstrated by the following example.
Example 4.3.Consider the TRS over the signature {c, f, g} (with c a constant): We use the C-model A 2 = {⊥, g, fg } with the interpretation of the symbols defined by: for all x ∈ A 2 .Again we use maximal labeling so that the symbols g fg , f ⊥ , f g and f fg correspond to redex positions.The C-depth of the rule f(x) → x is 2 and its static context extension contains the rule g(g(f(x))) → g(g(x)).From this we obtain three labeled rules: The second rule should not be allowed, as it would enable a rewrite step that is not outermost.This is witnessed by the symbol g fg in the prepended context.

Dynamic Context Extension
We present an approach for semantic labeling with C-models, called 'dynamic context extension',1 where we stepwise extend rules by contexts, only when needed and dependent on the variable interpretation used for the semantic labeling.For different interpretations of the variables usually different context depths are necessary for achieving equal interpretations of left and right-hand side.In each extension step we check whether a candidate symbol is a redex symbol, and, if it is, this symbol is excluded from prepending.Here, by a redex symbol we mean a labeled symbol which indicates the presence of a redex in the original system.Dynamic context extension is more efficient in the sense that both the number and the size of the rules of the resulting µTRS are smaller than in the static version defined in the previous version.
The transformation starts with constructing pairs ℓ → r, α of rules and variable assignments.Then these rules are extended with flat contexts until the interpretations of left and right-hand side are equal.Finally, each obtained rule is labeled using the corresponding interpretation.More precisely, we implement this process as follows.
We iteratively construct sets P 0 , P 1 , . .., until P i+1 = P i for some i.The initial set P 0 consists of pairs ℓ → r, α for each rule ℓ → r, and each interpretation α : Var (ℓ) → A of the variables.Then, in each step, P i+1 is obtained from P i by replacing every pair ℓ → r, α of P i for which the interpretation of the left-hand side differs from the right-hand side ( ℓ, α = r, α ), by the pairs C[ℓ] → C[r], α ′ for every flat context C (Definition 2.3) and every extension α ′ : Var (C[ℓ]) → A of α, such that the root of the labeled, extended left-hand side lab(C[ℓ], α ′ ) is not a redex symbol.Among the flat contexts to be prepended we include top(✷) to cater for the case that the rule is applied at the top of the term.
Example 5.1.We reconsider from Examples 3.9 and 3.12 the term rewriting system R 1 : together with the C-labeling A 1 , π, Σ red , where A 1 = {⊥, f, ff , g}, π labels symbols with their arguments and Σ red = {f g , f ff }.The initial set P 0 of pairs rule, assignment is: The only element ℓ → r, α of P 0 such that ℓ, α = r, α is f(f(f(x))) → x, λx.ff .For this pair no context needs to be prepended.The other pairs have to be replaced by their context extensions and thus P 1 consists of the following (4 In the last line the context f(✷) is excluded, because the labeled left-hand side of the rule would contain the redex symbol f ff within the prepended context, and thus the step would not be outermost.Because of the outermost strategy, the original rule is only applicable in a context C[g(✷)] (where C does not contain any redexes) or at the top of a term.Now for all rules in P 1 the left and right-hand side have equal interpretations, and hence the iterative construction is finished.
Secondly, the obtained set P 1 is labeled using the family π of labeling functions.The desired context-sensitive TRS △ π R 1 then consists of the rules lab(ℓ, α) → lab(r, α) for every ℓ → r, α ∈ P 1 , with the replacement map µ defined by µ(h) = ∅ if h ∈ {f g , f ff }, and µ(h) = {1, . . ., ♯h} otherwise, for all h ∈ lab(Σ).Thus the dynamic context extension of R 1 consists of 19 rules.Recall from Example 4.2 that the static context extension of R 1 had 28 rules.
We now formalize this transformation.
Definition 5.2.Let R be a TRS over Σ, and A, π, Σ red a C-labeling for R. We define P π (R) as the least fixed point of the following construction of sets P 0 , P 1 , . . ., that is, P π (R) = P i as soon as P i+1 = P i for some i.The initial set P 0 is defined by: and for i = 0, 1, . . . the set P i+1 is obtained from P i by replacing every pair ℓ → r, α such that ℓ, α = r, α , or r ∈ X , by all pairs in △(ℓ → r, α) where we define: Here, for partial functions f and g with disjoint domains, we write f + g for the function defined by The construction of P π (R) is guaranteed to terminate because of the assumption that A is a C-model for R.
Definition 5.3 (Dynamic context extension).Let R be a TRS over Σ, and A, π, Σ red a C-labeling for R. The dynamic context extension of R with respect to A, π, Σ red is the µTRS △ π R, µ consisting of: and the replacement map µ, defined by µ(f) = ∅ if f ∈ Σ red , and µ(f) = {1, . . ., ♯f} otherwise, for all f ∈ lab(Σ top ).Whenever the set Σ red , which determines the replacement map, is clear from the context, we write △ π R as a shorthand for △ π R, µ .
Remark 5.4.In the transformation given in Definition 5.3 collapsing rules are always prepended by at least one flat context.Consequently, △ π R, µ contains no collapsing rules.This is used in the proof of Theorem 5.13 in order to apply Theorem 5.12.Without this elimination of collapsing rules, the transformation is still sound (Theorem 5.8).Note that in the TRS R 1 worked out before, we did not eliminate the collapsing rule.
Let us work out another example.
Example 5.5.We consider problem zantema08/dupl_rhs.trsfrom the TPDB [Ter08]: We denote this TRS by R 3 , and take the algebra A 3 = {⊥, c, h, i}, • with • defined by: for all x, y ∈ A 3 .Furthermore, we employ minimal labeling; only the function symbols that are at the root of a redex occurrence are marked.Thus the symbols h, i are always marked: and leave f unmarked otherwise.Also, the symbols s and c are never marked.The dynamic context extension △ π R 3 is then formed by the rules: We now work towards the first main theorem, stating that outermost ground termination of R is implied by termination of the transformed system △ π R.
Lemma 5.6.Let R be a TRS over Σ, and let A, π, Σ red be a sound C-labeling for R.Moreover, let s, t ∈ T (Σ, ∅) be ground terms and p ∈ Pos(s) such that s out → R,p t.Then for all proper prefixes q of 1p we have root (lab(top(s))| q ) ∈ Σ red .
Proof.For q = ǫ this follows from top λ ∈ Σ red for any label λ.Otherwise we have that root (lab(top(s))| q ) = root (lab(s)| q ′ ) with q ′ a proper prefix of p, and if root (lab(s)| q ′ ) ∈ Σ red , then, by definition of sound C-labeling, s contains a redex at position q ′ , quod non.
The following lemma states that any outermost ground rewrite step in R can be transformed into a rewrite step in △ π R.
Lemma 5.7.Let R be a TRS over Σ, and let A, π, Σ red be a sound C-labeling for R. Let s, t ∈ T (Σ, ∅) be ground terms such that s out → R t. Then: Proof.Assume s out → R,p t for some position p ∈ Pos(s).Then there exists a rule ℓ → r ∈ R, a context C with root (C| p ) = ✷ and a ground substitution σ such that s = C[ℓσ] and t = C[rσ].We consider the construction of the dynamic context extension from Definition 5.3, and prove by induction that for all i = 0, 1, . . .there exists a context C i which is a prefix of top(C), a ground substitution σ i , and terms For the base case we have ℓ 0 → r 0 , σ 0 ∈ P 0 with ℓ 0 = ℓ, r 0 = r, σ 0 = σ, and C 0 = top(C).For the induction step we assume the existence of C i , σ i , and ℓ i → r i , σ i ∈ P i with the above properties.If ℓ i , σ i = r i , σ i and r i ∈ X then by definition ℓ i → r i , σ i ∈ P i+1 , and so we are done.For the remaining cases ℓ i , σ i = r i , σ i and r i ∈ X , we first show that C i = ✷.If ℓ i , σ i = r i , σ i and C i = ✷, then ℓ i σ i = top(s) and r i σ i = top(t), and hence root (ℓ i ) = root (r i ) = top, contradicting ℓ i , σ i = r i , σ i (recall that the interpretation of top is constant).Furthermore, we have r i ∈ X only if i = 0, and then , and σ i+1 = σ i + σ ′ .It remains to be shown that ℓ i+1 → r i+1 , σ i+1 ∈ P i+1 .For this it suffices to prove that root (lab(ℓ i+1 , σ i+1 )) ∈ Σ red .We have C i+1 [ℓ i+1 σ i+1 ] = top(s).Let q be the position such that root (C i+1 | q ) = ✷.Then, by Lemma 3.6 we obtain root (lab(ℓ i+1 , σ i+1 )) = root (lab(ℓ i+1 σ i+1 )) = root (top(lab(s))| q ).Note that q is a proper prefix of 1p.By Lemma 5.6 we have root (lab(top(s))| q ) ∈ Σ red .
Let i be such that P i+1 = P i .By the result above we have ℓ i → r i , σ i ∈ P with ℓ i σ i = r i σ i , and lab(ℓ i , σ i ) → lab(r i , σ i ) ∈ △ π R by definition.Let τ and υ be defined by τ (✷) = ℓ i σ i , υ(✷) = r i σ i , and τ (x) = υ(x) = x for x ∈ X .Then we have that lab , by Lemma 3.6.By Lemma 5.6 all symbols above position 1p in the term lab(top(s)) are not in Σ red and hence we have a µ-rewrite step: lab(top(s)) → △ π R,µ lab(top(t)).
Theorem 5.8.Let R be a TRS over Σ, and A, π, Σ red a sound C-labeling for R. Then R is outermost ground terminating if △ π R is terminating.
Proof.Assume that R admits an infinite outermost rewrite sequence: Then from Lemma 5.7 it follows that △ π R admits an infinite rewrite sequence: The following three examples illustrate why our method is sound, but not complete when applied to non-left-linear (and non-quasi-left-linear) TRSs.The first example can be handled by our approach employing the C-labeling constructed in Section 9.The second example fails using the C-labeling from Section 9, but can successfully be treated using a manually constructed C-labeling.For the third example, we show that there exists no C-labeling that can be employed for proving outermost ground termination; this example is out of reach for the approach proposed in this paper.
We label the symbols with the interpretations of their arguments, and define Σ red = {f ⊥,⊥ }.Note that Σ red does not contain g ⊥,⊥ .The reason is that using a finite algebra we can (in general) not recognize redex positions with respect to non-left-linear rules.By excluding g ⊥,⊥ from Σ red we allow rewriting below g even when g is the root of a redex.This is sound for proving outermost termination as it does not restrict the possible rewrite steps, but allows only additional steps.The symbol f ⊥,⊥ is part of Σ red ; due to the rule f(x, y) → y each occurrence of f is a redex position.
The dynamic labeling △ π R 4 is then formed by: where µ(f ⊥,⊥ ) = ∅ and µ(g ⊥,⊥ ) = {1, 2}.This system is terminating which can be seen as follows.After an application of the first rule: the replacement map µ prevents us from reducing the inner f ⊥,⊥ .Moreover, the second rule cannot be applied to the outer f ⊥,⊥ since the left and the right subterm are not equal.
Thus the only rule applicable to the displayed subterm is f ⊥,⊥ (x, y) → y which reduces the size of the term, and we can conclude termination by induction.Hence we conclude outermost ground termination of R 4 by Theorem 5.8.Actually the same C-labeling allows also to infer outermost termination, see Lemma 5.15 (we simply add a fresh constant 0 and a unary symbol s with interpretations 0 = ⊥ and s (⊥) = ⊥).
Example 5.10.We consider the non-left-linear TRS R 5 over the signature Σ 5 = {g, a, b}: This TRS is outermost terminating.However, there exists no C-labeling that recognizes redex positions with respect to the non-left-linear rule g(x, x) → b.A finite algebra cannot be used to check whether two arbitrary subterms t 1 and t 2 of g(t 1 , t 2 ) are equal.Thus it appears that, in order to have a sound transformation, we cannot include any symbol g λ in the set Σ red of redex symbols.But then rewriting below g is allowed, and the rule a → g(a, a) would lead to non-termination of the dynamic labeling △ π R 5 .Nonetheless, in this particular example, the problem can be solved.If some element e of the algebra is the interpretation of precisely one ground term t, then, of course, t 1 = t 2 = e implies that t 1 = t 2 .Let us take the algebra A 5 = {⊥, a} with a = a, b = ⊥, and g (x, y) = ⊥ for all x, y ∈ A 5 .We use maximal labeling and define Σ red = {g a,a }.
That is, we mark redex positions g(t, t) only for the special case t = a.This C-labeling is sound since only redex positions are marked, but it is not complete; not all redex positions are marked.Nevertheless, this labeling can be used to prove outermost ground termination of R 5 .The dynamic labeling △ π R 5 of R 5 consists of: The employed C-labeling is not complete, and so the µTRS △ π R 5 admits rewrite sequences (starting from correctly labeled terms) that do not correspond to outermost rewriting, e.g: Despite of this, the µTRS can be shown to be terminating, and since the C-labeling was sound, we conclude outermost ground termination of R 5 by Theorem 5.8.
Example 5.11.In Examples 5.9 and 5.10 we have seen how our method can be applied to prove outermost termination of non-quasi-left-linear TRSs.We now consider an example which shows that not every non-left-linear TRS can be handled by our method: This TRS is outermost terminating.Now the trick used in Example 5.10 does not work.
In order to construct a terminating µTRS △ π R 6 we need to forbid rewriting in all terms of the form g(f(t), f(t)).This is impossible using a finite algebra.
We need the following adaptation of [Ohl02, Proposition 5.5.24] for µTRSs; the proof proceeds along the same lines.
Theorem 5.12.Let R, µ be a terminating many-sorted µTRS.If the µTRS obtained from R, µ by dropping sorts admits an infinite rewrite sequence, then R, µ is collapsing and duplicating.
While for soundness of the transformation (Theorem 5.8) a sound labeling suffices, for a complete transformation we need the C-labeling to be complete, maximal and core: Theorem 5.13.Let R be a TRS over Σ, and A, π, Σ red a complete, maximal, and core C-labeling for R. Then △ π R is terminating if R is outermost ground terminating.
Proof.Assume that △ π R is not terminating.We turn △ π R into a sorted TRS.The sorts are chosen from the set A ∪ {top}.Since the C-labeling is maximal, for each n-ary symbol f λ ∈ lab(Σ top ) we have λ = a 1 , . . ., a n .We let f λ have input sort λ and output sort f (a 1 , . . ., a n ).The only exception is the output sort of the symbols top λ which we fix to be the sort top.Then by Theorem 5.12 together with non-collapsingness of △ π R yields the existence of a well-sorted infinite rewrite sequence τ in △ π R. Since the C-labeling is core, by Lemma 3.4 there exists a ground term for every sort in A. Thus by applying a ground substitution to τ we obtain a well-sorted infinite ground term rewrite sequence τ ′ .Well-sortedness implies correct labeling: for each well-sorted term t ∈ T (lab(Σ top ), ∅) there exists a term t ′ ∈ T (Σ top , ∅) such that t = lab(t ′ ).Moreover, a symbol top λ can only occur at the top of a term.Without loss of generality we assume that every term in τ ′ has top λ (for some λ ∈ A) as root (as rewriting below top λ is allowed and context-sensitive rewriting is closed under µ-replacing contexts).Hence it suffices to show that for all terms s, t ∈ T (Σ, ∅) with lab(top(s)) → △ π R,µ lab(top(t)) we have s out → R t.By construction, each rule in △ π R is the result of prepending contexts to, and labeling of, a rule in R. Let ρ : s → R t be the step corresponding to lab(top(s)) → △ π R,µ lab(top(t)).We show that ρ is an outermost step.Assume there would be a redex u above the rewrite position.Then by completeness of the C-labeling we get root (lab(u)) ∈ Σ red .But then this symbol must be in lab(top(s)), either above the applied rule from △ π R or within the prepended context.Both cases yield a contradiction: the former since µ(root (lab(u))) = ∅ would prohibit the µ-step, and the latter because we do not prepend symbols from Σ red .Let us consider the three conditions of Theorem 5.13 on C-labelings: complete, maximal and core.To see that completeness and maximality are necessary, we refer to Examples 5.11, and 9.4, respectively.The following example shows the need to restrict to core algebras: Example 5.14.Let R 7 be the following term rewriting system: This TRS is outermost ground terminating: First note that without the first rule R 7 is terminating.So consider a rewrite step f(t) → g(t, f(t)) for t ∈ T ({f, g, a}, ∅).Then one of the three g-rules matches g(t, f(t)) and blocks all inner rules by the outermost strategy.
We take the C-model A 7 = {0, 1} with a = f (x) = g (x, y) = 0, for all x, y ∈ A 7 .We let π be the maximal labeling and define Σ red = {f 0 , g 0,0 }.Then the dynamic context extension △ π R 7 contains, amongst others, the following two rules: where µ(g 0,0 ) = ∅ and µ(g 1,0 ) = {1, 2}.Consequently, the second rule is not terminating, although the original TRS is outermost ground terminating.The C-labeling A 7 , π, Σ red is complete for R and maximal, but not core.Note that there exists no ground term which has the interpretation 1, and hence the label 1 should never occur.
Theorems 5.8 and 5.13 are about outermost ground termination.This is not a severe restriction, as by adding a fresh constant 0 and a fresh unary symbol s outermost ground termination implies (and for quasi-left-linear TRSs coincides with) outermost termination: Lemma 5.15.A TRS R over Σ is outermost terminating if R over Σ ∪ {s, 0} is outermost ground terminating.If R is also quasi-left-linear, the converse direction holds as well.
Proof.Let X be countably infinite, and φ : X → N a bijection.We define a substitution σ by σ(x) = s φ(x) (0).Then, we have sσ out → tσ whenever s out → t with s, t ∈ T (Σ, X ), since the symbols s and 0 do not occur in any pattern of a rule, and for all p, q ∈ Pos(s) we have s| p = s| q ⇔ sσ| p = sσ| q .This concludes the proof of the first part of the theorem.
For the converse direction, let R be a quasi-left-linear TRS such that R over Σ ∪ {s, 0} is not outermost ground terminating.Let t ∈ T (Σ ∪ {s, 0}, ∅) be a ground term of minimal size admitting an infinite rewrite sequence t = t 1 out → t 2 out → t 3 out → . ... By minimality, infinitely many of these steps must be in the prefix of t not containing s and 0. Let t ′ ∈ T (Σ, X ) be obtained from t by replacing all subterms with root symbol s or 0 in t by a (arbitrary, but fixed) variable x.Then t ′ admits an infinite outermost rewrite sequence as well.Note that by replacing the subterms no redex in the {s, 0}-free prefix of t is destroyed since the symbols s and 0 do not occur any rule pattern.Fresh redexes with respect to non-left-linear rules may be created (but not with respect to left-linear rules).By quasi-left-linearity, at each position where a redex is created, there is also redex with respect to a left-linear rule.Hence, no additional redexes get blocked by outermost strategy.
The following example shows that extending the signature with a single fresh constant 0 only is not enough for the implication: R over the extended signature is outermost ground terminating ⇒ R is outermost terminating.
Example 5.16.Consider the following term rewriting system R: Because of the first rule R is not outermost terminating: but the TRS over the extended signature Σ ′ = {a, f, b, 0} is outermost ground terminating: Consider a step f(s, t) → a(f(s, t)) with s, t ∈ T (Σ ′ , ∅).If s = 0 one of the rules in the second column applies, and if t = 0 then one of the rules in the third column is applicable.However if s = t = 0 then the rule a(f(x, x)) → b matches.
Note that for the second part of Lemma 5.15 we require quasi-left-linearity.This requirement was erroneously missing from [EH09], but is necessary as the following example illustrates.
Example 5.17.We consider the following term rewriting system R: and explain why this system is outermost terminating.Without the rule f(x, y, y) → a(f(x, x, y)) outermost termination of R is obvious; Hence, in an infinite rewrite sequence this rule must be applied infinitely often.Let us consider a rewrite step C[f(t, u, u)] out → C[a(f(t, t, u))].If t ∈ X , then u = t since no non-variable term rewrites to a variable; then a(f(x, x, x)) → ⊥ is applicable and has priority (by outermost strategy) over all inner rewrite steps (and we terminate).If t ∈ X , then the second argument u and third argument t in a(f(t, t, u)) have to rewrite to a common non-variable reduct (in order to make the first rule applicable again).However, as soon as the common reduct is reached, one of the rules displayed on the right would be applicable and have priority by outermost rewriting strategy.
Nevertheless, R over the signature Σ ∪ {s, 0} is not outermost ground terminating:

Dynamic Labeling
This paper is about employing context-sensitive rewriting to model outermost rewriting.We do so by marking redexes, and forbid rewriting below them.As we have seen, contracting a redex may create another redex higher up in the term tree.Hence it may be necessary to update some labels during a rewrite step.In Section 5 we defined a transformation where this updating was accounted for by extending rules with contexts.Here we give an alternative transformation from TRSs to context-sensitive TRSs.We call this tranformation 'dynamic labeling'.Instead of extending rules with contexts, we now employ rewriting to propagate the changed information upward in the term tree, and set the labels in the surrounding context right, step by step.Again the C-depth (Definition 3.8) serves as a bound: here on the number of successive ancestor nodes that have to be relabeled.Each original rewrite step will give rise to a corresponding step and a bounded number (≤ the C-depth) of auxiliary steps in the transformed system.Thus, although the derivational complexity (the length of rewrite sequences) is changed, this is only by a constant factor.We prove that dynamic labeling is sound for arbitrary TRSs.Moreover, for left-linear TRSs, the method is complete in a weakened sense, see Theorem 6.12.In Section 10, we compare the performance of this method to the one of dynamic context extension described in Section 5.
We begin with an analysis for evaluating which value changes can occur by rewriting and need to be propagated upward.As we will see, this restricts the number of auxiliary 'relabel symbols', and, in particular, the number of 'relabeling rules'.Definition 6.1.Let R be a TRS over Σ, and let A, π, Σ red be a C-labeling for R.For i = 0, 1, 2, . . ., we define the set L i ⊆ A × A inductively by: Then we define the set L π (R) of value-change pairs by: The 'dynamic labeling' ↑ π R of a TRS R is partitioned into two sets of rules.The first set is denoted by ↑ π 1 R and consists of a semantic labeling of the original rules, where, additionally, a right-hand side is prefixed by a symbol relabel a,a ′ whenever application of the rule causes a change of interpretation from a to a ′ .The second set, ↑ π 2 R, is a set of rules for relabeling the context of the rule application.A symbol relabel a,a ′ , with a, a ′ ∈ L π (R), indicates that the value of its subterm has changed from a to a ′ , and the rules in ↑ π 2 R take care of propagating this change of value upward in the term.Definition 6.2 (Dynamic labeling).Let R be a TRS over Σ, and let A, π, Σ red be a C-labeling for R. The TRS ↑ π R over the signature lab( Here the set ↑ π 1 R of labeled rules contains, for each rule ℓ → r ∈ R and assignment α : Var (ℓ) → A, one of the rules: lab(ℓ, α) → lab(r, α) if ℓ, α = r, α relabel ℓ,α , r,α (lab(r, α)) otherwise Secondly, the set ↑ π 2 R of relabeling rules contains, for each n-ary f ∈ Σ, b, b ′ ∈ L π (R), and a , b, c ∈ A n such that f λ ∈ lab(Σ top ) \ Σ red with λ = π f ( a , b, c ), one of the rules: The dynamic labeling of R (with respect to the C-labeling A, π, Σ red ) is the contextsensitive TRS ↑ π R, µ , where the replacement map µ is defined by µ(relabel a,a ′ ) = ∅ for all a, a ′ ∈ L π (R), µ(f) = ∅ if f ∈ Σ red , and µ(f) = {1, . . ., ♯f} otherwise, for all f ∈ lab(Σ top ).Whenever Σ red is clear from the context, we leave µ implicit, and overload the notation ↑ π R to denote ↑ π R, µ .Example 6.3.We revisit the TRS R 1 from Example 3.9 for which we worked out the static and dynamic context extensions in Examples 4.2 and 5.1.We repeat its definition and the C-labeling from Example 3.12: R 1 is the TRS over Σ = {a, f, g} consisting of the rules: A C-model for R 1 is formed by the Σ-algebra A 1 = {⊥, f, ff , g} with interpretation: for all x ∈ A 1 .Furthermore, A 1 , π denotes the maximal labeling for R 1 , and Σ red = {f g , f ff }.Then A 1 , π, Σ red forms a sound and complete C-labeling of R 1 .Also note that A 1 forms a core algebra; for each value e ∈ A 1 there is a ground term t such that t = e.We first compute the set L π (R 1 ) of value-change pairs.For the initial set L 0 , note that the rule f(g(x)) → f(f(g(x))) changes the interpretation from f to ff , regardless of the value assigned to x.The other rule creates three value-change pairs; one for each of the values g, ⊥, f assigned to x.If the interpretation of x is ff there is no change.Hence we get: All symbols relabel e,e ′ with e, e ′ ∈ L 0 will disappear in one relabeling step, whence for all e ∈ A 1 for all e, e ′ ∈ { ff , ⊥ , ff , f , ff , g } and where ↑ π 2 R 1 is formed by: g e (relabel e,e ′ (x)) → g e ′ (x) for all e, e ′ ∈ L π (R 1 ) In total the dynamic labeling of R 1 has 13 rules.Had we not restricted the construction of the set of the relabeling rules to the 'reachable' symbols relabel e,e ′ (by the requirement e, e ′ ∈ L π (R 1 ) in Definition 6.2), we would have come up with 18 instead of 5 relabeling rules.
Example 6.4.We reconsider the term rewrite system R 3 from Example 5.5: and the algebra A 3 = {⊥, c, h, i}, • with • defined, for all x, y ∈ A 3 , as follows: Moreover, we employ minimal labeling again; see Example 5.5.The set of change-value pairs is: There are four rules with left-hand side ℓ = f ⋆ (i ⋆ (x), y), one for each value assigned to x.
In case α(x) = ⊥ there is no change of interpretation, for we have that ℓ, α = ⊥ for all α : {x, y} → A 3 and so no relabel symbol is inserted.But if, for instance, σ(x) = c for some substitution σ, then some labels in the context C of a rewrite step have to be updated, since the value of ✷ has changed from ⊥ to c, whence the insertion of relabel ⊥,c to the right-hand side x.
The set ↑ π 2 R 3 of relabeling rules is formed by: f(relabel e,e ′ (x), y) → f(x, y) e, e ′ ∈ { ⊥, c , ⊥, h , h, ⊥ } e, e ′ ∈ L π (R 3 ) Some remarks for clarification: First, note that all relabel symbols disappear upon one relabeling step.Secondly, observe the overlap in, for example, the rules with left-hand side f(relabel ⊥,h (x), y).If the value assigned to y is c, then a redex is created; this is witnessed by the marked symbol f ⋆ on the right.For other values for y, this is not the case.Also note that there is no rule for t = f(relabel i,h (x), y).This is because when the left argument of f is interpreted as i, then t forms a redex, and so f should be marked.Definition 6.2 does not allow relabel symbols to commute with redex symbols.Intuitively, a relabel symbol is a witness of a rewrite step which we do not want to occur inside other redexes, as we want to model outermost terminination.However, more technically, sometimes illegal (i.e., non-outermost) relabel steps are allowed.This is illustrated in Example 6.11.The point is that by preventing relabel symbols to commute with redex symbols, for local completeness (Theorem 6.12) it is as if illegal steps never happened.
Remark 6.5.We elaborate on the role of the element a in relabel a,a ′ .Whenever the application of a rule C[ℓσ] → C[rσ] changes the interpretation, i.e., ℓσ = rσ , then a symbol relabel ℓσ , rσ is inserted.A term of the form relabel a,a ′ (t ′ ) can be thought of as a witness of a rewrite step t → t ′ causing a change of interpretation from a = t to a ′ = t ′ .This change of the value then needs to be propagated upward to update the labels accordingly, using the relabeling rules from ↑ π 2 R. At first sight, the value a in relabel a,a ′ (t) seems redundant for relabeling: why would we store the previous value?However, the label a is important in order to restrict the number of applicable rules, and to have a bound on the number of relabeling steps.To see this, consider the system R 8 with single rewrite rule: and the algebra = ⊥ for all x = f , and d = ⊥.We employ minimal labeling, that is, only π f (gf ) = ⋆ , and all the other symbols are unlabeled.The dynamic labeling ↑ π R 8 gives rise to two labelings of the original rule: And, among the fourteen rules in ↑ π R 8 for updating labels, we find the following two: )), and the rewrite sequence: After an application of (6.1), relabeling takes two steps, resulting in a correctly labeled term.
In the alternative, let us say 'forgetful' version of dynamic labeling, where the 'from' value a in symbols relabel a,b is omitted, the rules (6.1)-(6.4)look like this: Due to the overlap in rules (6.3 ′ ) and (6.4 ′ ), the resulting µTRS has a rewrite sequence from t where the symbol relabel ⊥ goes up all the way to the top: From the following lemma it follows that every relabel symbol can be rewritten at most δ A (R) times (before it vanishes).By rewriting a 'relabel symbol' we refer to a notion of residuals that extends the usual definition of orthogonal projection [Ter03] with a concept suggested by the definition of ↑ π 2 R : Whenever we have a rule of the form: then we call relabel b,b ′ in the right-hand side a residual of relabel a,a ′ in the left-hand side.Lemma 6.6.Let R be a TRS over Σ, and let A, π, Σ red be a C-labeling for R. We define the relation Then ❀ is well-founded and every ❀ path has length ≤ δ A (R).
Proof.By definition of value-change pairs we have that for every pair b, b ′ ∈ L π (R) there exists a rule ℓ → r ∈ R and assignment α : Var (ℓ) → A such that ℓ, α , r, α ❀ * b, b ′ .Assume, to arrive at a contradiction, there exists a sequence . For i = 0, 1, . . ., m we construct thin contexts D i and assignments We begin with D 0 = ✷ and α 0 = α.Then we have b 0 = ℓ, α and b ′ 0 = r, α .For i = 1, . . ., m there exist f i ∈ Σ, and and α i is α i−1 extended by mapping variables x i to the corresponding a i and Corollary 6.7.Every relabel symbol disappears at latest after having applied δ A (R) many relabeling rules (to this symbol).
Proof.For every rule in ↑ π 2 R of the form: For the dynamic context extension, the 'intended' terms in T (lab(Σ), ∅) are those terms that can be obtained by correctly labeling terms in T (Σ, ∅).For the purpose of adapting this definition to dynamic labeling, we enrich the (unlabeled) signature Σ to Σ + : and extend the C-labeling to Σ + by: Then labeled symbols are identified by (relabel a ) a ′ = relabel a,a ′ .We obtain the following lemma: Lemma 6.8.Let R be a TRS over Σ, and let A, π, Σ red be a C-labeling for R. Whenever we have a ground term s of the form: with a, a ′ ∈ L π (R), a ′ = t , and where the displayed relabel symbol is at a µ-replacing position, then one of the following steps applies: where λ = π f ( s 1 , . . ., a, . . ., s n ) and λ ′ = π f ( s 1 , . . ., a ′ , . . ., s n ).By Definition 6.2 the dynamic labeling ↑ π R contains a rule of the form: Consequently we have a step of the form: Lemma 6.9.Let R be a TRS over Σ, and let A, π, Σ red be a sound C-labeling for R. Let s, t ∈ T (Σ, ∅) be ground terms such that s out → R t.Then, for some m ≤ δ A (R) : → R,p t for some position p ∈ Pos(s).Then there exists a rule ℓ → r ∈ R, a context C with root (C| p ) = ✷ and a ground substitution σ : X → T (Σ, ∅) such that s = C[ℓσ] and t = C[rσ].Let C a = lab(top(C), ✷ → a) and σ = lab(σ), then by Lemma 3.6 we obtain: and, likewise: By definition of dynamic labeling, one of the following rules is in if ℓσ = rσ (6.9) lab(ℓ, σ ) → relabel ℓσ , rσ (lab(r, σ )) if ℓσ = rσ (6.10) (Note that ℓ, σ = ℓσ , and r, σ = rσ by Lemma 3.2.) In case ℓσ = rσ , no relabeling is needed and we take m = 0: If ℓσ = rσ , we get: )) By Lemma 6.8 the relabel symbol can 'walk' upward until it disappears, and at the latest it vanishes when it meets top.Hence we have: )) for some m ≤ δ A (R) by Lemma 6.6.Theorem 6.10.Let R be a TRS over Σ, and A, π, Σ red a sound C-labeling for R. Then R is outermost ground terminating if ↑ π R is terminating.
Proof.Assume that R admits an infinite outermost rewrite sequence of ground terms: Then from Lemma 6.9 it follows that ↑ π R admits an infinite rewrite sequence: . .We note that Theorem 6.10 can be strengthened by weakening the termination of ↑ π R to local termination of ↑ π R on the set of correctly labeled ground terms without relabel symbols.Let us denote this set by lab(T (Σ, ∅)): Theorem 6.12 below states that dynamic labeling is complete with respect to local termination on lab(T (Σ, ∅)).More precisely, outermost ground termination of R implies termination of ↑ π R on lab(T (Σ, ∅)).The following example helps to understand the proof of that theorem; it illustrates that even when starting from terms in lab(T (Σ, ∅)), not every rewrite step in ↑ π R corresponds to an outermost step in R.
Example 6.11.Let R consist of the following rules: Moreover, let A = {⊥, b} with a = ⊥, b = b, and f (x, y) = ⊥ for all x, y ∈ A. Labeling symbols with the value of their arguments, we obtain for ↑ π 1 R: where Then we obtain the following rewrite sequence in ↑ π R: The second step in this rewrite sequence does not correspond to an outermost step.Nevertheless, Theorem 6.12 states that such 'illegal' steps do not harm completeness of the transformation.The reason is that if the relabeling rules create a redex above some relabel symbol, then this relabel symbol is prevented from further propagating its information upward (until it becomes µ-replacing again).The crucial point is that above relabel symbols the labels are unchanged, thus as if the step would not have taken place.Moreover, it is essential that ↑ π R prohibits relabel to propagate over symbols from Σ red .For instance, in the above example ↑ π R does not contain a rule of the form: This rule would cause non-termination: Theorem 6.12.Let R be a left-linear TRS over Σ, and A, π, Σ red a complete, maximal, and core C-labeling for R. Then ↑ π R is terminating on the set of terms lab(T (Σ, ∅)) if R is outermost ground terminating.
Proof.Define T = lab(T (Σ, ∅)), and an outermost rewrite step in the original TRS R. Therefore it suffices to show that any infinite rewrite sequence t = t 0 → ↑ π R,µ t 1 → ↑ π R,µ . . .gives rise to an infinite rewrite sequence t = s 0 ֒→ s 1 ֒→ . ... We prove the claim by a kind of standardization of reductions.We first classify the rules from ↑ π R: For i = 0, 1, . .., we analyse the steps t i → ↑ π R,µ t i+1 and construct s 0 ֒→ s 1 ֒→ . . .֒→ s j in such a way that s j ¬µ −→ * c2,c4 t i+1 where we use ¬µ −→ c2,c4 to denote standard term rewriting ignoring the replacement map µ, and using rules from (c2) and (c4) only.Observe that then the maximal prefix C i+1 of t i+1 not containing relabel symbols is also a prefix of s j (since everything changed by (c2) and (c4) is 'hidden' inside a relabel symbol).We begin with t = s 0 , and i = j = 0.For i = 0, 1, . .., we consider the step τ i : If τ i is a step with respect to a rule from: − (c2) or (c4), then we append τ i to the rewrite sequence s j ¬µ −→ * c2,c4 t i yielding s j ¬µ −→ * c2,c4 t i+1 .Note that this leaves the ֒→-rewrite sequence s 0 ֒→ * s j untouched.− (c1), then the pattern of τ i lies entirely in C i which is also prefix of s j .Then we append τ i to s 0 ֒→ * s j (using left-linearity of R) yielding s 0 ֒→ * s j τ i ֒→ s j+1 .We have s j+1 ¬µ −→ * c2,c4 t i+1 by orthogonal projection of the steps s j ¬µ −→ * c2,c4 t i over s j τ i ֒→ s j+1 (all steps in s j ¬µ −→ * c2,c4 t i are below the prefix C i ).− (c3), then a relabel symbol 'disappears'.We can trace this symbol back to a sequence of steps σ i : , that is, it must have been created in s j by a (c2) step, followed by a number of (c4) steps.We combine σ i and τ i to a ֒→ step, yielding c2,c4 t i+1 as the remaining steps from s j ¬µ −→ * c2,c4 t i are not harmed by the permutation (performing σ i first).It remains to be shown that the constructed sequence s 0 ֒→ s 1 ֒→ s 2 ֒→ . . . is infinite.This follows from the fact that an infinite number of steps in t 0 → ↑ π R,µ t 1 → ↑ π R,µ . . .must be of type (c1) or (c3).This is a direct consequence of the fact that → c2,c4 is terminating (with every step the prefix in which rewriting is allowed gets smaller).
The following example demonstrates why the completeness result for dynamic labeling (Theorem 6.12) is restricted to the set lab(T (Σ, ∅)) of correctly labeled terms which do not contain relabel symbols.The point is that, although the original TRS is outermost terminating the transformed system may in general be non-terminating due to the existence of 'non-reachable' terms.Example 6.13.We consider the following term rewriting system R: We explain why this TRS is outermost ground terminating.Without the rule ρ : f(c, y) → h(f(y, y)), the system would even be terminating.Now note that the rule ρ can only be applied once to each occurrence of f(c, ✷) since h(f(t, t)) → * h(f(c, t ′ )) implies that t = c, and then the rule h(f(x, c)) → b has priority by the strategy of outermost rewriting.We define a maximal, complete, core C-labeling A, π, Σ red for R (isomorphic to the result of the construction given in the next section) where the algebra A = {bc, fbc, ⊥} with the interpretation function defined by: for all x, y ∈ A with y = bc, and with Σ red = {a, f bc , h fbc }.
The dynamic labeling ↑ π R of R with respect to this C-labeling then includes the rules: Now the context-sensitive TRS ↑ π R admits the following infinite rewrite sequence: Observe that this anomaly is caused by the subterm relabel ⊥,bc (c), which is not reachable from any term in lab(T (Σ, ∅)).
Remark 6.14.Theorem 6.12 states completeness of dynamic labeling with respect to local termination on the set of terms lab(T (Σ, ∅)).We briefly indicate how the theorem can be generalized to termination on T (lab(Σ), ∅) by altering the definition of ↑ π R. Note that lab(T (Σ, ∅)) T (lab(Σ), ∅).In particular, the set T (lab(Σ), ∅) includes terms that are not correctly labeled.The necessary modification of the definition of dynamic labeling concerns the elimination of collapsing rules ℓ → x.This can be achieved by wrapping the right-hand side into relabel a,a (✷) even when the interpretations of the left and right-hand side are equal.Additionaly, we let the symbols relabel a,a disappear after one relabeling step.By an application of Theorem 5.12 it then follows that termination on lab(T (Σ, ∅)) coincides with termination on T (lab(Σ), ∅).

Constructing Suitable Algebras
We construct C-models which are able to recognize redex positions with respect to leftlinear rules.The construction of C-models is similar to the construction of a deterministic tree automaton (DTA, [CDG + 07]) for recognizing left-linear redexes [Com00].A DTA is a Σ-algebra A, • with a distinguished set A F ⊆ A of final states.A term t is accepted by the automaton whenever t ∈ A F .A difference with the construction of a DTA is that for the construction of a C-model we do not distinguish final and non-final states, but instead have a family of functions isRedex f : A ♯f → Bool for indicating the presence of a redex.
The interpretation function • of A, and the functions isRedex are defined by: true if match(cut(ℓ), f(t 1 , . . ., t n )) = true for some ℓ → r ∈ R false otherwise for all function symbols f ∈ Σ with arity n, and terms t 1 , . . ., t n .The core of the algebra F (R), which we denote by F (R) c , is called the full redex-algebra for R. Furthermore, let S ⊆ R be the set consisting of all left-linear rules of R. Then F (S) c is called the left-linear redex-algebra for R.
Of course, if R is a left-linear TRS, then a left-linear redex-algebra for R also is a full redex-algebra for R.Moreover, if R is a quasi-left-linear TRS, then the minimized left-linear and full redex-algebras for R are isomorphic.Minimization of redex-algebras is introduced in the next section.We now consider two examples which illustrate that F (R) c indeed can be a proper subalgebra of F (R).
Example 7.4.We consider the term rewriting system R which consists of the rules: This TRS is outermost ground terminating, but it is not outermost terminating.We construct the redex-algebra F (R) = A, isRedex where A = {⊥, a(⊥), f(⊥, ⊥), b} with a (x) = a(⊥), f (x, y) = f(⊥, ⊥) and b = b for all x, y ∈ A. But note that ⊥ is not part of the core, and hence the left-linear (full) redex-algebra F (R) c contains only the elements {a(⊥), f(⊥, ⊥), b}.
Example 7.5.Consider the term rewriting system R consisting of the rules: The domain of the redex-algebra F (R) is {h(h(⊥)), h(⊥), ⊥, h(a), a} with the interpretation of the symbols defined by: The values ⊥ and h(⊥) are not part of the core, and hence the domain of the left-linear (full) redex-algebra F (R) c is {h(h(⊥)), h(a), a} with isRedex h (h(a)) = isRedex h (h(h(⊥))) = true, and false otherwise.
The next example illustrates the use of the function merge in the construction of a redex-algebra.
Example 7.6.We construct the left-linear (full) redex-algebra for the TRS: For the family of isRedex functions we obtain: and isRedex returns false in all remaining cases.Finally, note that the core of the constructed algebra is the algebra itself, i.e., F (R) c = F (R), because e ∈ Σ with e = ⊥.
The following theorem states that left-linear (full) redex-algebras recognize only redex positions (at least all redex positions).
Theorem 7.7.Let R be a TRS over Σ.The following properties hold: (i) The left-linear redex-algebra for R is sound.
(ii) The full redex-algebra for R is complete.
(iii) Let A be the left-linear redex-algebra for R.For all t ∈ T (Σ, ∅) we have t ∈ L(A) if and only if t is a redex with respect to a left-linear rule in R. Hence, if R is quasi-left-linear, then the left-linear redex-algebra for R is sound and complete.
Proof.We prove (ii) and leave (i) and (iii) to the reader.Let A, isRedex = F (R) c with F the mapping defined in Definition 7.3.Let t ∈ T (Σ, ∅) be a redex with respect to a rule ℓ → r ∈ R.

Minimizing Algebras
In this section we are concerned with the minimization of redex-algebras.The algorithm is similar to the minimization of deterministic tree automata, see [CDG + 07].For the set of 291 TRSs of the outermost termination competition of 2008 [Ter08], the redex-algebras constructed according to Definition 7.3 have an average size of 4.6 elements.After an application of the minimization algorithm described here, the average size falls to 3.4, a reduction of 27%.This reduction has a polynomial influence on the number of rules of the transformed system.Definition 8.1.Two core redex-algebras Lemma 8.2.Let A 1 , A 2 be equivalent, core redex-algebras.Then A 1 is sound or complete if and only if A 2 has the respective property.
For a given core redex-algebra we now construct a minimal equivalent algebra.The difference to the minimization of tree automata from [CDG + 07] lies in the initial equivalence E 0 .For tree automata this initial equivalence consists of two partitions, the final and the non-final states.In our setting two states are initially equivalent if they cannot be distinguished using the isRedex functions, that is, isRedex f ( x , a, y ) = isRedex f ( x , b, y ) for each symbol f ∈ Σ and each assignment of x and y .This can yield any number of partitions between 1 and |A|.Definition 8.3 (Minimization of redex-algebra).Let A, isRedex be a core redex-algebra over Σ.We define equivalence relations E i for i ∈ N on the elements of A. Initially two elements a, b ∈ A are equivalent, a E 0 b, if: for all symbols f ∈ Σ n , j ∈ {1, . . ., n}, x ∈ A j−1 , and y ∈ A n−j .Then for i = 0, 1, . . .and a, b ∈ A we define a E i+1 b if a E i b holds and: f ( x , a, y ) E i f ( x , b, y ) for all n-ary symbols f ∈ Σ, j ∈ {1, . . ., n}, x ∈ A j−1 , and y ∈ A n−j .The process halts when E i+1 = E i for some i ∈ N, and then we define E = E i .Let [a] denote the equivalence class of a ∈ A with respect to E. The minimized redex-algebra of A, denoted A min , is defined as Lemma 8.4.Let A be a core redex-algebra, then A is equivalent to A min .Example 8.5.We consider the TRS R consisting of the following three rules: The left-linear (full) redex-algebra for R is A = {a, i(a), j(a), ⊥} with the interpretation a = a, i (a) = i(a), j (a) = j(a), and the interpretation is ⊥ in all non-listed cases; isRedex f (x) = true for all x = ⊥, and false, otherwise.
The minimization algorithm starts with E 0 = {{a, i(a), j(a)}, {⊥}} as initial equivalence, since ⊥ can be distinguished from the other elements (isRedex f (⊥) = false).The first iteration of the algorithm yields E 1 = {{a}, {i(a), j(a)}, {⊥}} as i (a) = i(a) whereas i (i(a)) = i (j(a)) = ⊥.The elements i(a) and j(a) are indistinguishable, and so in the second iteration we obtain E 2 = E 1 .Thus the elements i(a) and j(a) are identified and we obtain an algebra that has one element less than the algebra we started with.

Constructing Minimal and Maximal C-labelings
In the previous sections we have constructed and minimized redex-algebras for recognizing redex positions.For completing the transformation we still have to explain how to construct C-labelings from the redex-algebras.
In minimal labeling symbols are marked with a ⋆ if they correspond to redex positions and stay unlabeled otherwise.This labeling creates a small signature and thereby results in a small number of rules of the transformed system.Definition 9.1.Let R be a TRS over Σ, and A a redex-algebra.The minimal labeling with respect to A is the C-labeling A, π, Σ red defined for each n-ary symbol f ∈ Σ top by: The set of redex symbols is defined by Σ red = {f ⋆ | f ∈ Σ}.
Theorem 9.2.Let R be a TRS, and A a sound redex-algebra for R. The minimal labeling with respect to A is a sound C-labeling for R.
The construction and minimization of redex-algebras (Definitions 7.3 and 8.3) give rise to sound minimal C-labelings (Theorem 7.7, Lemmas 8.4 and 8.2, and Theorem 9.2).In combination with Theorems 5.8 and 6.10 this provides us with sound transformations for proving outermost termination: Corollary 9.3.Let R be a TRS, and let A, π, Σ red be the minimal labeling with respect to the minimized left-linear redex-algebra for R. Then R is outermost ground terminating whenever the dynamic context extension △ π R or the dynamic labeling ↑ π R is terminating.
Minimal labeling is sound and efficient, but it is not complete (not even for left-linear TRSs where the left-linear redex-algebra is complete): Example 9.4.Let R be the term rewriting system consisting of the rules: Obviously, R is outermost terminating.The minimized left-linear redex-algebra for R is: for all x, y ∈ A. The C-depth of both rules (with respect to A) is 0. Using minimal labeling we obtain π cons (s, x) = ⋆ and π inf (x) = ⋆ for all x ∈ A, and other symbols are left unmarked (ǫ).Thus the set of redex symbols is Σ red = {inf ⋆ , cons ⋆ }.
The dynamic context extension △ π R of R with respect to the C-labeling A, π, Σ red consists of the following rules, the first two of which arise from the inf-rule, with the values ⊥ and s assigned to x respectively: The replacement map is defined by µ(inf ⋆ ) = µ(cons ⋆ ) = ∅.Now △ π R admits an infinite derivation: The third term is labeled incorrectly, as the inner occurrence of cons should be marked.
The reason is that in the second step, instead of the first inf ⋆ -rule, the second should have been applied; however, the left-hand inf ⋆ (x) contains too little information to 'decide' what the labeling of the right-hand side should be.
This motivates the use of maximal labeling for which correct labeling is preserved under rewriting.Function symbols are labeled with the interpretation of their arguments: Definition 9.5.Let R be a TRS over Σ, and let A be a redex-algebra for R. The maximal labeling with respect to A is the C-labeling A, π, Σ red defined for each n-ary f ∈ Σ top by: The set of redex symbols is defined by: Σ red = {f a 1 ,...,an | isRedex f (a 1 , . . ., a n ) = true}.Theorem 9.6.Let R be a TRS, and let A be a redex-algebra for R. The maximal labeling with respect to A is a maximal C-labeling for R, and it is sound, complete, and core whenever A has the respective property.
Proof.Maximality of the maximal labeling is immediate from the definition.Let A be a complete redex-algebra.Let t = f(t 1 , . . ., t n ) ∈ T (Σ, ∅) be a redex.Then by definition of complete redex-algebra isRedex f ( t 1 , . . ., t n ) = true, and it follows that root (lab(t)) = f t 1 ,..., tn ∈ Σ red .Hence the C-labeling is complete.Analogous to the proof of Theorem 9.2, we obtain that maximal labeling is sound whenever the redex-algebra A is sound.Note that the remaining claim concerning coreness is immediate by definition.
The construction and minimization of redex-algebras (Definitions 7.3 and 8.3) give rise to sound and complete maximal C-labelings (Theorem 7.7, Lemmas 8.4 and 8.2, and Theorem 9.6).In combination with Theorems 5.8, 5.13 and 6.10 this provides us with sound transformations for proving outermost termination for arbitrary TRSs.For quasi-left-linear TRSs dynamic context extension is both sound and complete.
Corollary 9.7.Let R be a TRS, and let A, π, Σ red be the maximal labeling for the minimized left-linear redex-algebra for R. Then R is outermost ground terminating whenever the dynamic context extension △ π R or the dynamic labeling ↑ π R is terminating.Moreover, if R is quasi-left-linear, then R is outermost ground terminating if and only if the dynamic context extension △ π R terminates.
As a consequence, the full redex-algebra for an arbitrary TRS can be used to disprove outermost ground termination: Corollary 9.8.Let R be a TRS, and let A, π, Σ red be the maximal labeling for the minimized full redex-algebra for R. Then the dynamic context extension △ π R is terminating whenever R is outermost ground terminating.

Evaluation
With the implementation of the transformation by dynamic context extension, described in Section 5, the termination prover Jambox [End09] gained first place in the category of outermost rewriting of the termination competition of 2008 [Ter08], see Table 1 1 are relative to the total number of term rewriting systems which were proven to be outermost terminating by some participating tool.The TPDB 2008 contained 291 TRSs in the category of outermost rewriting of which 77 were proven outermost terminating, 161 not outermost terminating, and 53 remained unsolved in the competition.We note that around 50 systems in the database are, strictly speaking, not term rewriting systems, as they contain variables in the right-hand sides that do not occur in the left-hand sides.
In the termination competition 2008, Jambox used exclusively the approach of dynamic context extension (Section 5).If we additionally use dynamic labeling, as defined in Section 6, the score of Jambox improves by 4, thus proving 76 systems to be outermost terminating.
The secret behind the efficiency of Jambox is threefold: First, we construct and minimize the algebras employed for marking redex positions, see Sections 7 and 8. Secondly, we try two labeling strategies: minimal and maximal, see Section 9. Minimal labeling is very efficient and contributes to 75% of the success of Jambox.In order to have a complete transformation we also employ maximal labeling.Thirdly, dynamic context extension is the combination of labeling and context extension, where the prefixing of contexts to rules depends on the interpretation of the variables.All these optimizations minimize the number of rules and their size in the transformed systems, which is important to keep a manageable search space.minimum lower quartile median upper quartile maximum Next, we compare the performance of dynamic context extension and dynamic labeling (Section 6). Figure 1 shows the size of the transformed systems in relation to the size of the input system, as measured on the TPDB [Ter08].For each input size we display the minimum, the lower quartile (25th percentile), the median, the upper quartile (75th percentile), and the maximum size of the transformed systems.From Figure 1 it can be inferred that for larger input systems the dynamic labeling usually is a factor 5 or 10 smaller than the dynamic context extension.For systems with more than 10 rules there are only a few examples available in the database, which explains why some of the quartiles fall together.Table 2 shows a comparison of our different methods (dynamic context extension and dynamic labeling, combined with minimal or maximal labeling).Each row lists the total score of one method with the number of systems it can solve that cannot be solved by the method corresponding to the column.For example, the value 3 in and dynamic labeling are roughly equal in strength, and that maximal labeling gives the best results.Table 3 illustrates that the C-depth of rules is typically small (employing left-linear redex-algebras): it is 0 or 1 in 94.5% of the cases.Note that 54% of the rules have C-depth 0, but this does not mean that the same percentage of the TRSs could be handled by a model (Definition 3.7).Only 14% of the TRSs have C-depth 0.

Discussion
For arbitrary TRSs the transformation based on dynamic context extension (including the construction of C-labelings) is sound, and for quasi-left-linear TRSs it is sound and complete.The sound redex-algebra we construct recognizes redexes with respect to leftlinear rules.As a consequence, in the µTRS △ π R rewriting is forbidden only inside such redex positions.This corresponds to a weakening of the outermost rewriting strategy: contraction of a redex is disallowed only if it is contained within a redex with respect to left-linear rule.Let us call this the 'left-linear outermost' rewriting strategy.Dynamic context extension combined with maximal labeling is sound and complete for termination with respect to this rewriting strategy for all TRSs.
In a similar way the transformation of [RZ09] can be generalized from quasi-left-linear TRSs to arbitrary TRSs.For soundness the anti-matching rules do not need to exactly match the non-redex terms, as long as at least all non-redex terms are matched.Then the symbol down can be moved inside redexes with respect to rules which are not left-linear.This enables only additional rewrite steps but does not harm soundness.More precisely, using this generalization the transformation of [RZ09] becomes complete with respect to leftlinear outermost termination.Thereby the score of TrafO in the termination competition of 2008 [Ter08] could possibly have been improved by around 20%, resulting in a score of 57 instead of 47.
We have shown that the transformation of dynamic labeling is complete on the set of correctly labeled terms lab(T (Σ, ∅)) without the auxiliary relabel symbols (Theorem 6.12).The non-completeness with respect to termination on all terms arises from 'illegally placed' relabel symbols in combination with duplicating rules, see Example 6.13.The duplicating rules can multiply the illegal symbols and make them reusable over and over again.To prevent this, one can introduce an extra symbol block with µ(block) = ∅ for disallowing relabel symbols beneath the rule application.For this purpose, we wrap each duplicated variable in the right-hand side of a labeled rule into a context block(✷), and we extend the dynamic labeling with rules of the form block(f(x 1 , . . ., x n )) → f(block(x 1 ), . . ., block(x n )) for each symbol f ∈ lab(Σ n ) (excluding relabel symbols!).Note that this implies that block symbols disappear when meeting a constant.For instance, reconsider the TRS from Example 6.13, which had among others the following rule in its dynamic labeling: This rule would be modified to: f bc,⊥ (c, y) → h ⊥ (f ⊥,⊥ (block(y), block(y))) In this way we 'block' each duplicated variable.
Another question is whether there are interesting labelings between minimal and maximal.In particular, are there more efficient complete labelings?Here efficiency is measured in the size of the signature and the number of rules of the transformed system.In Example 9.9 it would have been sufficient to label cons with the interpretation of the left argument, saving two symbols and two rules of the transformed system.

Figure 1 :
Figure 1: Size of the transformed systems (y-axis) in relation to the size of the input TRS (x-axis) using dynamic context extension (left), and dynamic labeling (right), both with maximal C-labelings.

Table 1 :
[KSZM09]n average time of 4.1 seconds per termination proof, Jambox was also faster than the Results of proving outermost termination in the competition of 2008[Ter08].otherparticipants,providingempiricalevidencefor the efficiency of the transformation of dynamic context extension.Not listed in Table1is TTT2[KSZM09], which did not prove outermost termination, but performed best in disproving outermost termination.The percentages listed in Table

Table 2 :
Table 2 means that three systems can be solved by dynamic maximal labeling, but not by dynamic context extension in combination with maximal labeling.The table shows that dynamic context extension TRANSFORMING OUTERMOST INTO CONTEXT-SENSITIVE REWRITING * 37 Method Total Score ¬△ π R, max ¬↑ π R, max ¬△ π R, min ¬↑ π R, min Comparison of the proposed methods on the TPDB 2008.

Table 3 :
Ratio of rules having a certain C-depth in the TPDB 2008.