Conditional term rewrite systems (CTRSs) and conditional equational specifi- cations are very important ..... It is a specialized version of soundness for reduction, but ... if we assume only one condition per rule), computing the final unique result.
Transformations of Conditional Rewrite Systems Revisited Karl Gmeiner and Bernhard Gramlich TU Wien, Austria {gmeiner,gramlich}@logic.at
Abstract. We revisit known transformations of conditional rewrite systems to unconditional ones in a systematic way. We present a unified framework for describing, analyzing and classifying such transformations, discuss the major problems arising, and finally present a new transformation which has some advantages as compared to the approach of [6]. The key feature of our new approach (for left-linear confluent normal 1-CTRSs) is that it is backtracking-free due to an appropriate encoding of the conditions.
1
Background and Overview
Conditional term rewrite systems (CTRSs) and conditional equational specifications are very important in algebraic specification, prototyping, implementation and programming. They naturally occur in most practical applications. Yet, compared to unconditional term rewrite systems (TRSs), CTRSs are much more complicated, both in theory (especially concerning criteria and proof techniques for major properties of such systems like confluence and termination) and practice (implementing conditional rewriting in a clever way is far from being obvious, due to the inherent recursion when evaluating conditions). For these (theoretical and practical) reasons, transforming CTRSs into (unconditional) TRSs in an adequate way has been studied for a long time cf. e.g. [4, 9, 18, 12, 15, 5, 2, 6, 13, 17, 10]. In many other early papers (like [1, 8]) the issue of transforming conditional into unconditional TRSs is not studied in depth, but at least touched from a programming language point of view. Roughly, all transformations work by translating the original syntax (signature and terms) into an extended or modified one using auxiliary function symbols, and by translating the rules in a corresponding way such that the evaluation of conditions and some control structure is (appropriately) encoded within the resulting unconditional TRS (in which in some cases reduction is additionally restricted, see below). In the papers mentioned above certain of these issues have been investigated for particular (quite different) transformations and with different terminology. In order to better understand and relate the different approaches together with their results, we will propose a kind of unified terminology for such transformations and their properties. A. Corradini and U. Montanari (Eds.): WADT 2008, LNCS 5486, pp. 166–186, 2009. c Springer-Verlag Berlin Heidelberg 2009
Transformations of Conditional Rewrite Systems Revisited
167
In the second main part of the paper we will deal with the issue of backtracking and the question whether a transformed system is computationally adequate for simulating the original one. Here we will propose a new approach whose characteristic feature is “backtracking-freeness”. The underlying goal here is as follows: If, for some given conditional system, we start a simulation (a reduction in the transformed TRS) from an “initial” term and obtain a normal form in the transformed system, then the latter should correspond to a normal form of the initial term in the original CTRS (this property, together with a few other requirements, is called computational equivalence in [6]). Otherwise, some form of backtracking would be needed, because then we are stuck with a failed attempt of verifying conditions, and may need to try another conditional rule. The rest of the paper is structured as follows. In Section 2 we introduce the necessary background about (conditional) term rewriting. Then, in Section 3 we present and discuss a unifying framework for describing transformations from CTRSs to TRSs. Furthermore known and new unsoundness phenomena are dealt with briefly. Then, in Section 4 we investigate how to design a transformation that avoids explicit backtracking during simulation in such a way that the transformed system still enjoys most desired preservation properties. We motivate the approach by a careful analysis, give a formal definition and present the main results. Finally, in Section 5 we report on some first experiments with our new transformation, briefly discuss related work, sketch possible optimizations, refinements and alternatives, and mention a few interesting perspectives. Due to lack of space, proofs are omitted in the paper.1
2
Preliminaries
We assume familiarity with the basic notations and terminology in rewriting, cf. e.g. [3]. We denote by O(t) the set of all subterm positions of a term t, that is partitioned into all variable positions OX (t) = {p ∈ O(t) | t|p is a variable} and all non-variable positions O(t) = O(t) \ OX (t). By Vars(t) we denote the set of all variables occurring in a term t. This notion is extended in the obvious way to rules and conditions. The set of normal forms of a rewrite system R is denoted by NF(R). Left- and right-hand sides of rewrite rules are also abbreviated as lhs and rhs, respectively. Slightly abusing notation, we sometimes confuse a rewrite system R = (F , R) and its set R of rewrite rules. Definition 1 (Conditional rewrite system, conditional rewrite relation, depth of reductions). A conditional term rewriting system (CTRS) R (over some signature F ) consists of rules l → r ⇐ c where c is a conjunction of equations si = ti . Equality in the conditions may be interpreted (recursively) e.g. as ↔∗ ( semi-equational case), as ↓ ( join case), or as →∗ ( oriented case). In the latter case, if all right-hand sides of conditions are ground terms that are irreducible 1
More theoretical results, complete proofs and more details about experiments, related work and possible optimizations and refinements can be found in the full version of this paper (forthcoming).
168
K. Gmeiner and B. Gramlich
w.r.t. the unconditional version Ru = {l → r | l → r ⇐ c ∈ R} of R, the system is said to be a normal one. Furthermore, according to the distribution of variables, a conditional rule l → r ⇐ c may satisfy (1) Vars(r) ∪ Vars(c) ⊆ Vars(l), (2) Vars(r) ⊆ Vars(l), (3) Vars(r) ⊆ Vars(l) ∪ Vars(c), or (4) no variable constraints. If all rules of a CTRS R are of type (i), 1 ≤ i ≤ 4, respectively, we say that R is an i-CTRS. The rewrite relation of an oriented CTRS R is recursively def def defined as follows: R0 = ∅, Rn+1 = {lσ → rσ | l → r ⇐ s1 →∗ t1 , . . . , sk →∗ def tk ∈ R, si σ →∗Ri ti σ for all 1 ≤ i ≤ k}, →R = n≥0 Rn . In the rest of the paper we will mainly deal with normal 1-CTRSs.
3 3.1
A Unifying Approach to Transformations Basic Transformation Approaches
Basically, two different lines of approaches can be distinguished, according to the way in which the conditions and the intermediate condition evaluation process are encoded. Consider a conditional rule of a given normal 1-CTRS and a term s = s[lσ] to be reduced. Obviously, the actual reduction of s = s[lσ] into s = s[rσ] has to be delayed until the conditions si σ →∗ ti σ = ti have been verified. To this end, the condition evaluation needs to be initiated and performed, while keeping the relevant context, i.e., about the current rule, in order to be finally able to produce rσ. In one line of approaches (historically the earlier one), the latter information is encoded in an abstract way that hides any concrete structure of l, but keeps the variable bindings of the matching substitution σ. Using the latter, after successful verification of the conditions the corresponding instantiated right-hand side rσ can be produced. This means, we need two rules, an introduction or initialization rule ρ : l → Uρ (s1 , . . . , sn , Vars(l)) where Vars(s) denotes the sequence of the set of all variables occurring in s (in an arbitrary, but fixed order) and the fresh function symbol Uρ (of appropriate arity) stands for rule ρ, and an elimination (or reducing) rule ρ : Uρ (t1 , . . . , tn , Vars(l)) → r that completes the successful rule application after the instantiated conditions si σ →∗ ti σ = ti have been verified (by other rewrite steps in between). The most prominent representative of this type of approach are Marchiori’s unravelings [12]. Early forerunners (with some restrictions/modifications or special cases) and successors of unraveling approaches in the literature are among others [4, 8, 15]. In the other main line of approaches, when trying to apply a conditional rule, the left-hand side is not completely abstracted away during verification of the conditions, but instead is kept in a modified form such that the conditions become additional arguments of some function symbol(s) in l, typically of the root function symbol. That means, the arity of this function symbol is increased appropriately by conditional (argument) positions which are used to represent the conditional arguments. Suppose l = f (u1 , . . . , uk ). Then f is modified into f by increasing its arity to k+n. For example, for the rule ρ : f (x) → x ⇐ x →∗ 0 the
Transformations of Conditional Rewrite Systems Revisited
169
introduction and elimination rules become f (x, ⊥) → f (x, x) and f (x, 0) → x, respectively. Here, the fresh constant ⊥ stands for an uninitialized condition. In order to prevent trivial cases of non-preservation of termination2 we will wrap conditional arguments in some fresh syntactic structure, e.g. as follows: f (x, ⊥) → f (x, x ), f (x, 0 ) → x.3 Now, increasing the arity of some function symbols in general for storing conditional arguments there requires a more sophisticated construction of the transformed system, since for every occurrence of such function symbols in left- and right hand sides as well in the conditions one has to specify how these conditional arguments should be filled and dealt with during rewriting. And the basic transformation step has to be done for every conditional rule! The basic idea underlying this approach goes back at least till [1]. Yet, the work that inspired many later approaches in this direction is by Viry [18].4 Other more recent transformation approaches along this line of reasoning include [2, 6, 16]. Intuitively, in both lines of approaches certain reductions in the transformed system during the evaluation of conditions do not correspond to what is done in the conditional system, e.g., reduction in the variable bindings Vars(l) of Uρ (s1 , . . . , sn , Vars(l)) for unravelings, reduction in the “original arguments” of f (x, x ), i.e., outside of x , in the conditional argument approach, and reduction above “non-completed” conditional arguments (in both approaches). This phenomenon which may have (and indeed has) problematic consequences for transformations is well-known for a long time. For that reason several approaches in the literature impose some form of (context-sensitivity or strategy or order-sortedness) restrictions on rewriting in the transformed system, e.g. [10, 14, 16, 17, 18], which may lead to better results in theory and/or practice. We will keep this issue in mind, but not deepen it here due to lack of space. What makes papers and results about transforming conditional systems sometimes hard to read and to compare, is the diversity of the terminology used to reason about their properties. In particular, soundness and completeness notions are usually defined in different ways. We will instead provide now a proposal for a unified description of such transformations including the relevant terminology. 3.2
A Unified Parameterized Description of Transformations
In view of the existing transformations and since one wants to simulate conditional rewriting in the original system by unconditional rewriting in the transformed one, extending the syntax appears to be unavoidable. So, generally def instead of original terms from T = T (F , V) the simulation will happen with 2 3
4
Note that the introduction rule is obviously non-terminating, whereas the original conditional rule terminates (and is even decreasing cf. [7]). Strictly speaking, the symbols ⊥ and . . . here are variadic, since they have as many arguments as there are conditions in the respective rule. In a fixed-arity setting one would have to use k-adic symbols ⊥k and . . .k instead, for appropriate arities k. Even though several main results (and proofs) in [18] are flawed, the ideas and the concrete approach developed there have been very influential.
170
K. Gmeiner and B. Gramlich def
terms from T = T (F , V) over an extended or modified signature F . Moreover, it may be necessary to initially explicitly translate original terms into the new syntax and associate results obtained in the transformed system to original terms. For unravelings this would not be absolutely necessary, but still yields a generalized point of view that turns out to be beneficial for the analysis. For approaches with encoding conditional arguments at new conditional argument positions these mappings are essential, though. Let us start with the general form of a transformation.5 Definition 2 (Transformations of CTRSs). A transformation from a class of CTRSs into a class of TRSs is a total mapping T that associates to every conditional system R = (F , R) from the class a triple ((F , R , →R ), φ, ψ), where (F , R ) is a TRS and →R is a subset of the rewrite relation induced by R = (F , R ).6 We call φ : T → T the initialization mapping (or encoding) and ψ : T → T the backtranslation (or decoding). Furthermore T has to satisfy the following requirements: (1) If R = (F , R) is finite (i.e., both F and R are finite), then R = (F , R ) is also finite. (2) The restriction of T to finite systems (from the considered class of CTRSs) is effectively constructible. (3) The initialization mapping φ : T → T is an injective total function. (4) The backtranslation ψ : T → T is a (partial) function that is defined at def least on T r , the set of all reachable terms7 which is given by T r = {t ∈ T | φ(s) →∗R t for some s ∈ T }. (5) The backtranslation ψ : T → T satisfies ψ(φ(s)) = s for all s ∈ T , i.e., on all initialized original terms it acts as inverse function w.r.t φ. Discussion of requirements: Let us briefly discuss this abstract definition of transformation and in particular the requirements mentioned. First, we parameterize transformations by the class of CTRSs that we want to transform, because this reflects the fact that for different types of CTRSs transformations are typically defined in different ways. The transformation of R into ((F , R , →R ), φ, ψ) allows to impose particular restrictions on →R like innermost rewriting or context-sensitivity constraints. This ability is crucial in some existing transformation approaches. Intuitively, this happens there in order to simulate more accurately the evaluation of conditions in the transformed setting and to exclude computations that have no analogue in the original system. If such a restriction of ordinary reduction is involved in →R , we will mention this explicitly. Otherwise, again abusing notation, we will simply omit the third component in (F , R , →R ). 5 6 7
Alternatively, instead of transformation also encoding, embedding or simulation are used in the literature. Actually, this is an abuse of notation. By writing →R we simply want to cover the case, too, where the rewrite relation induced by R is somehow restricted. The notion reachable term stems from [6]. In [2], term of interest was used instead.
Transformations of Conditional Rewrite Systems Revisited
171
Next, for a given CTRS of the respective class, the transformation does not only yield a transformed signature and rewrite system, but also an initialization mapping φ and a backtranslation ψ. For practical reasons, here the need for requirement (2) is obvious. Requirement (1) actually is a precondition for (2): When starting with a finite system, we clearly don’t want to end up with an infinite one after transformation which usually would lead to non-computability and undecidability problems. Without (1), the ideal and natural candidatefor the transformed unconditional system would be R = (F , R ) where R = i≥0 Ri with Ri as in Definition 1 (over the same signature), and with φ and ψ the identity function. However, then in general R would be infinite and its rewrite relation undecidable! Actually, from a logical point of view this choice of R would be ideal, since virtually all typical problems with transformations (like unsoundness phenomena) would simply disappear, because the rewrite relations (of the original and the transformed system) are exactly the same in this case. Yet, for the mentioned reasons, this kind of transformation is practically useless. Since in general the transformation may work on a modified or extended syntax, the original terms possibly need to be translated (via φ) before computation starts. Hence, φ should be total and also injective (3), since one clearly wants to be able to distinguish different original terms also after transformation. The other way round is more subtle. Namely, what should one be able to infer from derivations in the transformed system, in terms of the original one? First of all, the backtranslation ψ need not necessarily be total, because there may be terms in T which do not correspond to intermediate results of computations in the transformed system. For such garbage terms nothing should be required. In particular, there need not exist corresponding original terms for them. However, for every reachable term in the transformed system we do require that there exists indeed some original term to which the former corresponds (4). In a sense, this condition is quite strong.8 Yet, on an abstract level in general we do not know how the treatment of conditions (of R) in R actually works. The intuition behind (4) is that ψ should deliver those “original parts” of an intermediate result t ∈ T which can obviously be obtained by translating back (i.e., which directly correspond to original syntax). For the other “conditional parts” which correspond to started attempts of applying conditional rules, ψ should go back to the “beginning” of this attempt and recursively only translate back (conditional) rule applications that have been entirely completed. Since the former aspect requires solving reachability problems which are undecidable in general, due to (2) reasonable computable versions of ψ can only approximate “precise backtranslations”. Injectivity of ψ would be too strong a requirement, because typically there exist many terms in T corresponding in a natural way to a single original term. For initialized original terms φ(s), s ∈ T , it should be obvious and 8
In this sense, (4) is perhaps the most debatable requirement in our abstract definition of transformation. Though this definition covers all the major approaches from the literature, it is conceivable that there exist other transformational approaches for which a step-by-step backtranslation need not make sense.
172
K. Gmeiner and B. Gramlich
intuitive that via ψ we should get back the original term s (5), simply because the initialization φ is the standard or canonical way of translating original terms into the transformed setting. Based on Definition 2 we will now define various important properties of transformations that are crucial not only in theory, but also in practical applications. Note that the resulting terminology differs from the existing literature. Definition 3 (Properties of transformations). Let T be a transformation from a class of CTRSs into the class of TRSs according to Definition 2 and let R = (F , R) range over the former class of CTRSs. We define (two versions of ) soundness and completeness properties relating (properties P of ) the original and the transformed system (the rectangular brackets indicate the second versions; P may be e.g. confluence or termination): (a) T is said to be sound (for reduction) (or simulation sound) [w.r.t. reachable terms] if for every R = (F , R) with T (R) = ((F , R , →R ), φ, ψ) we have: ∀s, t ∈ T : φ(s) →∗R φ(t) =⇒ s →∗R t [ ∀s , t ∈ T r : s →∗R t =⇒ ψ(s ) →∗R ψ(t ))]. (b) T is said to be complete (for reduction) (or simulation complete) [w.r.t. reachable terms] if for every R = (F , R) with T (R) = ((F , R , →R ), φ, ψ) we have: ∀s, t ∈ T : s →∗R t =⇒ φ(s) →∗R φ(t) [ ∀s ∈ T r , t ∈ T : ψ(s ) →∗R t =⇒ ∃t ∈ T r : s →∗R t , ψ(t ) = t ]. (c) T is said to be sound for convertibility [w.r.t. reachable terms] if for every R = (F , R) with T (R) = ((F , R , →R ), φ, ψ) we have: ∀s, t ∈ T : φ(s) ↔∗R φ(t) =⇒ s ↔∗R t [ ∀s , t ∈ T r : s ↔∗R t =⇒ ψ(s ) ↔∗R ψ(t )]. (d) T is said to be sound for preserving normal forms [w.r.t. reachable terms] if for every R = (F , R) with T (R) = ((F , R , →R ), φ, ψ) we have: ∀s, t ∈ T : φ(s) →∗R φ(t) ∈ NF(R ) =⇒ t ∈ NF(R) [ ∀s ∈ T r : s →∗R t ∈ NF(R ) =⇒ ψ(t ) ∈ NF(R)9 ]. (e) T is said to be sound for P [w.r.t. reachable terms] if P(R ) implies P(R) [if P(R ) on reachable terms implies P(R)]. (f ) T is said to be complete for P [w.r.t. reachable terms] if P(R) implies P(R ) [on reachable terms]. The above preservation properties of T are “localized” for particular R, R and T in the obvious way.10 Discussion of terminology: Let us briefly discuss some aspects of these definitions. First, in general the two variants of “T sound / complete for P” and “T sound / complete for P w.r.t. reachable terms” are not equivalent. We will see an example below. One main goal for the design of any transformation should be soundness for reduction. Technically, the stronger soundness for reduction w.r.t. reachable terms may be preferable due to proof-technical reasons. Concerning 9 10
This is equivalent to: ∀s ∈ T ∀t ∈ T : φ(s) →∗R t ∈ NF(R ) =⇒ ψ(t ) ∈ NF(R). Observe that, regarding termination, in practice one is typically interested in slightly different preservation properties, namely of the shape “R operationally terminating (on s) if (only if, iff) R terminating (on φ(s))”.
Transformations of Conditional Rewrite Systems Revisited
173
the computation of normal forms, soundness for preserving normal forms is in general strictly weaker than soundness for preserving normal forms w.r.t. reachable terms, because it is unrealistic to expect that the (or a) normal form of φ(s) (for s ∈ T ) has the shape φ(t) (for some t ∈ T ). Hence, in practice we need here the latter notion. It is a specialized version of soundness for reduction, but strengthened by the requirement that the property of being a normal form is preserved backward. Now, which properties of a transformation T would one expect to have for a computationally feasible simulation of a given system R. Assuming that R is confluent (a) and operationally terminating (b) (or, equivalently, decreasing, if we assume only one condition per rule), computing the final unique result t ∈ NF(R) for some initial s ∈ T could be done via R as follows: Initialize s into φ(s), normalize φ(s) in R yielding some t , and finally translate back into ψ(t ). For this to work properly, one needs (c) completeness for termination w.r.t. reachable terms, (d) soundness for preserving normal forms w.r.t. reachable terms, and (e) soundness for reduction w.r.t. reachable terms. Then we get φ(s) →∗R u ∈ NF(R ) for some u by (b) and (c). Then, by (d) and (e) we obtain s →∗R ψ(u ) ∈ NF(R). This together with s →∗R t ∈ NF(R) and (a) implies ψ(u ) = t, i.e., the desired final result. In fact, it is not difficult to view most transformations from the literature, in particular [12], [2] and [6], as instances of Definition 2 above (with corresponding φ and ψ), together with the appropriately adapted terminology according to Definition 3. Due to lack of space, we refrain from describing this in detail. Let us instead briefly discuss a few aspects of unsoundness. 3.3
On-Unsoundness Phenomena
All transformation approaches that do not strongly restrict rewriting in the transformed system (like [10, 14, 16, 17]) such that the simulation of conditional rule application corresponds very closely to what is done in the original CTRS, exhibit in general unsoundness phenomena. More precisely, soundness for reduction (simulation soundness) is violated in general. This has been shown for unravelings by Marchiori in the technical report version [11] of [12] via a tricky counterexample. We present here a slightly simplified variant of this counterexample.11 Example 1 (unsoundness (for reduction) in general). The normal 1-CTRS R consisting of the rules a → c, a → d, b → c, b → d, c → e, c → k, d → k, h(x, x) → g(x, x, f (d)), g(d, x, x) → A, f (x) → x ⇐ x →∗ e is unraveled according to [12] into R which is R with the conditional rule replaced by f (x) → U (x, x) and U (e, x) → x. In R we have the following derivation between original terms: h(f (a), f (b)) →∗R h(U (c, d), U (c, d)) → g(U (c, d), U (c, d), f (d)) →∗R g(d, U (k, k), U (k, k)) →R A. In the original system, however, h(f (a), f (b)) →∗R A does not hold as is easily seen! 11
Compared to our version, [11, Example 4.3] has two more rules and two more constants.
174
K. Gmeiner and B. Gramlich
Note that Example 1 also constitutes a counterexample to soundness (in general) for most other transformation approaches including [2, 6]. We will not go into details about sufficient conditions that nevertheless ensure soundness for particular transformations (some of them are well-known to exist, cf. e.g. [11], [15], [2], [6]). Instead, let us ask – concerning our proposed terminology – whether soundness w.r.t reachable terms is strictly stronger than ordinary soundness. In fact, the answer is Yes, again for most approaches! Example 2 (soundness is weaker than soundness w.r.t. reachable terms). Consider the normal 1-CTRS R = {a → b, a → c, f (x) → x ⇐ x →∗ c} that, via [2], is transformed into R = {a → b, a → c, f (x, ⊥) → f (x, x ), f (x, c ) → x}. In R we have f (a, ⊥) →R f (a, a ) →∗R f (b, c ) → b. However, backtranslation of the last two reachable terms here yields ψ(f (b, c )) = f (b) and ψ(b) = b. Yet, in R, we clearly do not have f (b) →∗R b. Hence the transformation is not sound w.r.t. reachable terms. Note, however, that we do not obtain ordinary unsoundness here, because φ(f (a)) = f (a, ⊥) →∗R φ(b) = b implies indeed f (a) →∗R b. Furthermore let us just mention that unravelings are in general also unsound for convertibility (a counterexample is obtained by extending Example 1 above. And finally, we observe that some transformations in the literature (e.g. [4] and the technical report version [11] of [12]) are inherently unsound, because they do not transmit all variable bindings in the encoding process (in the introduction rule). Counterexamples for these cases can easily be constructed by adding a non-left-linear rule.
4 4.1
The New Transformation Motivation, Goal and Basic Idea
Our transformation will be based on the approach of [2]. The transformation in [2] is complete, sound w.r.t. reachable terms and sound for preserving normal forms w.r.t. reachable terms for “constructor-based” (normal 1-)CTRSs that are left-linear and confluent. However, for other CTRSs it may be unsound or incomplete for confluence. Example 3 (Incompleteness for confluence cf. [2, Example 4]). Consider the confluent CTRS R = {g(s(x)) → g(x) , f (g(x)) → x ⇐ x →∗ 0}. The transformation of [2] returns the TRS R = {g(s(x)) → g(x), f (g(x), ⊥) → (1)
f (g(x), x ), f (g(x), 0 ) → x}. In R we have the derivation f (g(s(0), ⊥) −→R (2)
f (g(s(0), s(0) ) −→R f (g(0), s(0) ). The latter term is irreducible and does not rewrite to 0 although f (g(0)) →R 0. f (g(s(0)), ⊥) corresponds to f (g(s(0))) in R that is matched by the lhs of the conditional rule l with the matcher τ = {x → s(0)}. After introducing the introduction step (1) the unconditional g-rule is applied to the g-subterm (2). f (g(0), s(0) ) corresponds to f (g(0)) in the original CTRS that is matched by l with the matcher σ = {x → 0}. Since
Transformations of Conditional Rewrite Systems Revisited
175
there are no derivations xτ →∗R xσ (x ∈ Vars(l)) the conditional argument is “outdated” and “inconsistent” with the original argument. Such inconsistencies may block further derivations as in Example 3 or lead to unsound derivations as in [2, Example 6]. We will refer to derivations that reproduce a term that is matched by the lhs of a conditional rule as being pattern preserving. Our goal is to provide a transformation that conservatively extends the transformation of [2] and does not require explicit propagation of reset information such that for confluent normal 1-CTRSs no explicit backtracking is needed. This means that in particular “critical” pattern preserving derivations are dealt with correctly. In the derivation of Example 3, the unconditional rule g(s(x)) → g(x), that is applied in (2) and leads to the “outdated” conditional argument, should eliminate (and re-initialize) the conditional argument that has been introduced in (1). Yet the conditional argument is “out of reach” for the unconditional rule. By encoding the conditional argument in the g-subterm of the conditional rule, however, we can eliminate the conditional argument in the unconditional g-rule. This way R is transformed into R = {g (s(x), z) → g (x, ⊥), f (g (x, ⊥)) → f (g (x, x )), f (g (x, 0 )) → x}. Now the conditional argument can be reintroduced: f (g (s(0), ⊥)) → f (g (s(0), s(0) )) → f (g (0, ⊥)) →∗ 0. Following this example our strategy is to encode the conditions in all subterms of the lhs of a conditional rule that otherwise would give rise to “inconsistencies” of conditional and original arguments. To avoid confusion we will refer to subterms that directly (i.e., as additional argument of the root function symbol) contain a conditional argument as subterms encoding a conditional argument. In certain conditional rules several subterms subterm of the lhs may lead to pattern preserving derivations. Then we have to encode the conditions multiple times: Example 4 (Multiple conditional arguments). Consider the CTRS g(s(x)) → g(x) h(s(x)) → h(x) R= f (g(x), h(y)) → i(x, y) ⇐ x →∗ 0, y →∗ 0 Both subterms g(x) and h(y) of the lhs of the conditional rule lead to a critical pattern preserving derivation. Therefore we need to add a conditional argument to the g-subterm and the h-subterm. Whenever a conditional argument was eliminated and reinitialized, hence has become ⊥, we have to reintroduce both conditional arguments via an introduction step. Therefore we need one introduction rule for each conditional argument. Only if both conditional arguments “satisfy” the conditions we may reproduce the corresponding rhs. Hence the transformed TRS R here should be ⎧ ⎫ g (s(x), z) → g (x, ⊥) h (s(x), z) → h (x, ⊥) ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎨ f (g (x, ⊥), h (y, z2 )) → f (g (x, x, y ), h (y, x, y ))⎬ R = ⎪ f (g (x, z1 ), h (y, ⊥)) → f (g (x, x, y ), h (y, x, y ))⎪ ⎪ ⎪ ⎪ ⎪ ⎩ ⎭ f (g (x, 0, 0 , z2 ), h (y, z1 , 0, 0 )) → i(x, y)
176
K. Gmeiner and B. Gramlich
Consider a conditional rule ρ : l → r ⇐ s1 →∗ t1 , . . . , sn →∗ tn of a CTRS R. Subterms where possibly “critical” pattern preserving derivations start are always (instances of) non-variable subterms l|p (p ∈ O(l)) of l, because inconsistencies of conditional arguments and original arguments in variables can be resolved by rewrite steps in the variable bindings (for confluent CTRSs). However, in order to detect all possibilities of overlaps (also after rewriting in ‘variable parts’), we must linearize l into llin . Then we can identify possible lhs’s that overlap into llin by systematic unification of all non-variable subterms of l with lhs’s of R and encode the conditions in such subterms of l. It is not necessary to encode conditions in all subterms of llin that are unifiable with some lhs. If a subterm does not contain any variables that occur in the conditions, rewrite steps in this subterm do not influence the satisfiability of the conditions and therefore it is not necessary to introduce the conditions here. Yet, we must consider the case that (only) after some rewrite steps in such subterms a rule may become applicable that did not overlap into llin initially. Example 5 (Iterative abstraction of overlapping subterms). Consider the CTRS a→b g(s(x), k(b)) → g(x, h(a)) R= h(b) → k(b) f (g(x, h(a))) → x ⇐ x →∗ 0 The only subterm of the linearized lhs of the conditional rule llin into which an lhs of some rule overlaps is the constant a which does not contain any variable of the condition. Since there are no other overlaps, we would just encode the conditions in the root symbol of the conditional rule: a→b g(s(x), k(b)) → g(x, h(a)) h(b) → k(b) R = f (g(x, h(a)), ⊥) → f (g(x, h(a)), x ) f (g(x, h(a)), s(0) ) → x In R we have the unsound derivation f (g(s(0), h(a)), ⊥) → f (g(s(0), h(a)), s(0) ) → f (g(s(0), h(b)), s(0) ) → f (g(s(0), k(b)), s(0) ) → f (g(0, h(a)), s(0) ) → 0 . Although (the lhs of) the g-rule does not overlap into llin , it is applicable after some rewrite steps. Therefore, we abstract all non-variable subterms of llin , that are unifiable with some lhs of R, into fresh variables iteratively and try to unify the non-variable subterms of the resulting terms with lhs’s of R. In the example, the a-rule overlaps into l0 = f (g(x, h(a))) so that we abstract it into l1 = f (g(x, h(y))). Because of the overlap with the h-rule this term then is abstracted into l2 = f (g(x, z)). Now the g-rule overlaps into the g-subterm of l2 that contains the variable x that also occurs in the conditions. We therefore encode a conditional argument in the g-subterm instead of f and obtain the transformed TRS h(b) → k(b) a→b g (s(x), k(b), z) → g (x, h(a), ⊥) R = f (g (x, h(a), ⊥)) → f (g (x, h(a), x )) f (g (x, h(a), 0 )) → x
Transformations of Conditional Rewrite Systems Revisited
177
In CTRSs that give rise to multiple conditional arguments, it may be possible to “recombine” them in an inconsistent way, if we do not iterate the sketched construction: Example 6 (Recombination of conditional arguments). Consider the CTRS ⎧ ⎫ i(s(0), 0) → 0 f (s(x), y) → s(x) ⎪ ⎪ ⎨ i(0, s(0)) → 0 ⎬ g(s(x)) → g(x) h(s(x)) → h(x) R = f (x, s(y)) → s(y) ⎪ ⎪ ⎩ ⎭ f (s(g(x)), s(h(y))) → i(x, y) ⇐ i(x, y) →∗ 0 The g-rule and the h-rule overlap into the lhs of the conditional rule, therefore we would encode the condition in both subterms: ⎧ ⎫ i(s(0), 0) → 0 f (s(x), y) → s(x) ⎪ ⎪ ⎪ i(0, s(0)) → 0 ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ f (x, s(y)) → s(y) g (s(x), z) → g (x, ⊥) h (s(x), z) → h (x, ⊥) ⎪ ⎪ ⎨ ⎬ R = f (s(g (x, ⊥)), s(h (y, z2 ))) → f (s(g (x, i(x, y) )), s(h (y, i(x, y) ))) ⎪ ⎪ ⎪ ⎪ ⎪ f (s(g (x, z1 )), s(h (y, ⊥))) → f (s(g (x, i(x, y) )), s(h (y, i(x, y) ))) ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎩ ⎭ f (s(g (x, 0 )), s(h (y, 0 ))) → i(x, y) In R , we now have the following derivation: f (f (s(g (0, ⊥)), s(h (s(0), ⊥))), f (s(g (s(0), ⊥)), s(h (0, ⊥)))) →∗ f (f (s(g (0, t1 )), s(h (s(0), t1 ))), f (s(g (s(0), t2 )), s(h (0, t2 )))) →∗ f (s(g (0, t1 )), s(h (0, t2 ))) →∗ f (s(g (0, 0 )), s(h (0, 0 ))) → i(0, 0) with t1 = i(0, s(0)) and t2 = i(s(0), 0) , whereas in R we have f (f (s(g(0)), s(h(s(0)))), f (s(g(s(0))), s(h(0)))) →∗R i(0, 0) . In order to avoid that “fragments” of introduction steps can be inconsistently rearranged, we will iteratively abstract (in parallel) all non-variable subterms of the lhs of the conditional rule, that (after transformation) contain conditional arguments, into new variables. This way the lhs of the conditional rule f (s(g(x), h(y))) is abstracted into f (s(z1 ), s(z2 )). But then we have an overlap with the unconditional f -rules at root position. Hence, we will also encode the conditional argument at root position. Thus the above problem disappears. 4.2
Definition of the Transformation
In our transformation we iteratively abstract “overlapping” subterms of lhs’s of conditional rules into new variables and append conditional arguments to such subterms provided they contain variables that also occur in the conditions. Additionally we have to take into account that also rules into which the lhs of a conditional rule overlaps may lead to inconsistencies. Before defining our transformation we define some mappings to increase (decrease) the arity of function symbols:
178
K. Gmeiner and B. Gramlich
Definition 4 (Initialization mapping and backtranslation) ⎧ ⊥ ⊥ ⎪ ⎨f (φf (t1 ), . . . , φf (tn ), ⊥) if t = f (t1 , . . . , tn ) ⊥ ⊥ ⊥ φf (t) = g(φf (t1 ), . . . , φf (tm )) if t = g(t1 , . . . , tm ), g = f ⎪ ⎩ t if t is a variable ⎧ ⎪ ⎨f (ψf (t1 ), . . . , ψf (tn )) if t = f (t1 , . . . , tn , u1 ) ψf (t ) = g(ψf (t1 ), . . . , ψf (tm )) if t = g(t1 , . . . , tm ), g = f ⎪ ⎩ t if t is a variable ⎧ Xn X1 ⎪ ⎨f (φf (t1 ), . . . , φf (tn ), z) if t = f (t1 , . . . , tn ) Xm 1 φX g(φX if t = g(t1 , . . . , tm ), g = f f (t) = f (t1 ), . . . , φf (tm )) ⎪ ⎩ t if t is a variable where X is an infinite set of new variables, z ∈ X and Xi (i ≥ 1) are infinite disjoint subsets of X such that z ∈ Xi . We abbreviate multiple applications of ⊥ ⊥ these mappings: φ⊥ f1 ,...,fn (t) = φf2 ,...,fn (φf1 (t)), ψf1 ,...,fn (t) = ψf2 ,...,fn (ψf1 (t)) X \Vars(φX f1 (t))
and φX f1 ,...,fn (t) = φf2 ,...,fn
(φX f1 (t)).
By abuse of notation we assume in the following that, if φX is used multiple times in a term, then always only mutually distinct variables are inserted. Definition 5 (Definition of the transformation T ). Let R be a normal 1CTRS so that the rules are arranged in some arbitrary but fixed total order