Innermost Reachability and Context Sensitive Reachability Properties are Decidable for Linear Right-Shallow Term Rewriting Systems Yoshiharu Kojima and Masahiko Sakai Graduate School of Information Science, Nagoya University Furo-cho, Chikusa-ku, Nagoya, 464-8603 Japan {
[email protected].,sakai@}is.nagoya-u.ac.jp
Abstract. A reachability problem is a problem used to decide whether s is reachable to t by R or not for a given two terms s, t and a term rewriting system R. Since it is known that this problem is undecidable, effort has been devoted to finding subclasses of term rewriting systems in which the reachability is decidable. However few works on decidability exist for innermost reduction strategy or context-sensitive rewriting. In this paper, we show that innermost reachability and context-sensitive reachability are decidable for linear right-shallow term rewriting systems. Our approach is based on the tree automata technique that is commonly used for analysis of reachability and its related properties.
1
Introduction
The reachability problem is a problem used to decide whether s is reachable to t by R or not for a given two terms: s, t, and a term rewriting systems (TRS) R. Since it is known that this problem is undecidable even if restricted to linear TRS or to shallow TRS [7], effort has been made to find subclasses of TRSs in which the reachability is decidable. Reachability properties for several subclasses of TRSs have been proved to be decidable [2, 6, 10, 11, 3]. These results are based on the more powerful property of effective preservation of regularity. We say a rewrite relation effectively preserves regularity if it is possible to construct a tree automaton (TA) which recognizes a set of terms reachable from some term in the regular set defined by a given TA. It is easy to see that the reachability property for TRSs is decidable if the TRSs effectively preserve regularity. Innermost reduction, a strategy that rewrites innermost redexes, is used for call-by-value computation. Context-sensitive reduction [8] is a strategy in which rewritable positions are indicated by specifying arguments of function symbols. For innermost reduction strategy, recently Godoy and Huntingford showed that reachability and joinability with respect to innermost reduction for (possibly non-linear) shallow TRSs are decidable [5]. In this case the proof method is not based on tree automata techniques. This paper shows that innermost reduction and context-sensitive reduction effectively preserve regularity for linear right-shallow term rewriting systems: hence, innermost reachability, innermost
joinability, context-sensitive joinability and context-sensitive reachability are decidable for this class.
2
Preliminary
Let F be a set of function symbols with fixed arity and X be an enumerable set of variables. The arity of function symbol f is denoted by ar(f ). Function symbols with ar(f ) = 0 are constants. The set of terms, defined in the usual way, is denoted by T (F, X). A term is linear if no variable occurs more than once in the term. The set of variables occurring in t is denoted by Var(t). A term t is ground if Var(t) = ∅. The set of ground terms is denoted by T (F ). A position in a term t is defined, as usual, as a sequence of positive integers, and the set of all positions in a term t is denoted by Pos(t), where the empty sequence ε is used to denote root position. The depth of a position p is denoted by |p|. A term t is shallow if every variable occurs at depth 0 or 1 in t. The subterm of t at position p is denoted by t|p , and t[t0 ]p represents the term obtained from t by replacing the subterm t|p by t0 . A substitution σ is a mapping from X to T (F, X) whose domain Dom(σ) = {x ∈ X | x 6= σ(x)} is finite. We sometimes represent σ as {x1 7→ t1 , . . . , xn 7→ tn } where xi ∈ Dom(σ) and ti = σ(xi ). The term obtained by applying a substitution σ to a term t is written as tσ. A rewrite rule is an ordered pair of terms in T (F, X), written as l → r, where l 6∈ X and Var(l) ⊇ Var(r). We say that variables x ∈ Var(l) \ Var(r) are erasing. A term rewriting system (over F ) (TRS) is a finite set of rewrite rules. Rewrite relation − induced by a TRS R is as follows: s − t if and only → → R R if s = s[lσ]p , and t = s[rσ]p for some rule l → r ∈ R, with substitution σ and p position p ∈ Pos(s). We call lσ redex. We sometimes write − by presenting → R the position p explicitly. A rewrite rule l → r is left-linear (resp. right-linear, linear, right-shallow) if l is linear (resp. r is linear, l and r are linear, r is shallow). A TRS R is left-linear (resp. right-linear, linear, right-shallow) if every rule in R is left-linear (resp. right-linear, linear, right-shallow). A tree automaton (TA) is a 4-tuple A = (F, Q, Qf , ∆) where Q is a finite set of states, Qf (⊆ Q) is a set of final states, and ∆ is a finite set of transition rules of the forms f (q1 , . . . , qn ) → q or q1 → q where f ∈ F with ar(f ) = n, and q1 , . . . , qn , q ∈ Q. We can regard ∆ as a TRS over F ∪ Q. The rewrite relation induced by ∆ is called a transition relation denoted by −→ or −→ . We say that a ∆ A ∗ term s (∈ T (F )) is accepted by A if s −→ q ∈ Qf . The set of all terms accepted A by A is denoted by L(A). We say A recognizes L(A). We use a notation L(A, q) ∗ ∗ or L(∆, q) to represent the set {s | s −→ q}. A TA A is deterministic if s −→ q A A ∗ and s −→ q 0 implies q = q 0 for any s ∈ T (F ). A TA A is complete if there exists A ∗ q ∈ Q such that s −→ q for any s ∈ T (F ). A set T of terms is regular if there A exists a TA A such that T = L(A).
Let → be a binary relation on a set T (F ). We say s ∈ T (F ) is a normal form (with respect to →) if there exists no term t ∈ T (F ) such that s → t. We ∗ use ◦ to denote the composition of two relations. We write − → for the reflexive n and transitive closure of →. We also write − → for the relation → ◦ · · · ◦ → that is composed of n →’s. The set of reachable terms from a term in T is ∗ defined by →[T ] = {t | s ∈ T, s − → t}. We say that a reduction → effectively preserves regularity if a tree automata A∗ that satisfies L(A∗ ) = →[L(A)] can be effectively constructed from an automata A. The reachability problem (resp. ∗ joinability problem) with respect to → is a problem that decides whether s − → s0 ∗ ∗ 0 0 (resp. s − →◦← − s ) or not, for given terms s and s . Theorem 1 ([4]). Let → be a relation on terms that effectively preserves recognizability. Then both reachability and joinability properties with respect to → are decidable.
3
Regularity preservation for innermost reduction
p We say a step rewrite s − t is innermost if all proper subterms of s|p are → R normal forms. We write − for the innermost rewrite relation induced by R. → in R This section shows that innermost reduction − effectively preserves reg→ R in ularity if R is a linear right-shallow TRS. In order to show the property, we prepare a procedure Pin that inputs a TA A and a TRS R and outputs a TA A∗ , and show that A∗ recognizes a set − [L(A)]. The procedure almost follows → R in the procedure in [6]. The main difference is the construction of states. Each state in the resulting automata consists of a pair of states. The first state originates in the input automata and remembers a reachable set. The second state remembers whether the corresponding terms are a normal form or not, which is necessary because every proper subterm of the innermost redex must be a normal form. First we show an example.
Example 2. Let R = {a → b, f (x) → g(x)} and A be a TA such that L(A) = {f (a)} defined by a finite state {qf a }, and transition rules {a → qa , f (qa ) → qf a }. The procedure produces the following TA defined by final states: Qf∗ = {hqf a , ua i, hqf a , ub i} and transition rules: ∆∗ = {a → hqa , ua i, b → hqa , ub i, f (hqa , ua i) → hqf a , ua i, f (hqa , ub i) → hqf a , ua i, g(hqa , ub i) → hqf a , ub i}. Here ub is a state for normal forms. The TA A∗ accepts terms f (a), f (b) and g(b) in − [{f (a)}], and does not → R in accept g(a). u t We show the procedure Pin in Figure 1, where we use a notation RS(R) for the set of all non-variable direct subterms of the right-hand sides of rules in TRS R: that is, RS(R) = {ri 6∈ X | l → f (r1 , . . . , rn ) ∈ R}. Note that RS(R) is a set of ground terms if R is right shallow. Example 3. Let us follow how procedure Pin works. Consider R and A in Example 2.
Input TA A = hF, Q, Qf , ∆i and left-linear right-shallow TRS R over F . Output TA A∗ = hF, Q∗ , Qf∗ , ∆∗ i such that L(A∗ ) = − [L(A)] if R is right→ R in linear. Step 1 (initialize) 1. Prepare a TA ARS = hF, QRS , QfRS , ∆RS i such that QfRS = {q t | t ∈ RS(R)} and L(ARS , q t ) = {t}. 2. Prepare a deterministic complete TA ANF = hF, QNF , QfNF , ∆NF i such that – L(ANF ) is the set NFR (⊆ T (F )) of all ground normal forms – L(ANF , q) 6= ∅ for any q ∈ QNF . 3. Let – k := 0 – Q∗ = (Q ] QRS ) × QNF – Qf∗ = Qf × QNF – ∆0 = {f (hq1 , u1 i, . . . , hqn , un i) → hq, ui | f (q1 , . . . , qn ) → q ∈ ∆ ] ∆RS , f (u1 , . . . , un ) → u ∈ ∆NF } Step 2 Let ∆k+1 be transition rules produced by augmenting transition rules of ∆k by the following inference rules: f (l1 , ..., ln ) → g(r1 , ..., rm ) ∈ R, f (hq1 , u1 i, . . . , hqn , un i) → hq, ui ∈ ∆k 0 g(hq10 , u01 i, . . . , hqm , u0m i) → hq, u0 i ∈ ∆k+1 if there exists θ : X → (Q ] QRS ) × QfNF such that ∗
f – li θ −∆ −→ hqi , ui i and ui ∈ QNF for all 1 ≤ i ≤ n,
½
k
rj θ · · · rj ∈ X for all 1 ≤ j ≤ m, and hq rj , u00 i · · · rj ∈ 6 X, u00 ∈ QNF – g(u01 , . . . , u0m ) −∆ −−→ u0 . –
hqj0 , u0j i
=
NF
and f (l1 , ..., ln ) → x ∈ R, f (hq1 , u1 i, . . . , hqn , un i) → hq, ui ∈ ∆k hq 0 , u0 i → hq, u0 i ∈ ∆k+1 if there exists θ : X → (Q ] QRS ) × QfNF such that ∗
– li θ −∆ −→ hqi , ui i for all 1 ≤ i ≤ n, and k
– hq 0 , u0 i = xθ.
Step 3 If ∆k+1 = ∆k then stop and set ∆∗ = ∆k . Otherwise, k := k + 1, and go to step 2.
Fig. 1. Procedure Pin
In the initialization step, we have ∆RS = ∅, QfNF = {ub }, ∆NF = {a ua , b → ub , f (ua ) → ua , f (ub ) → ua , g(ua ) → ua , g(ub ) → ub }, Q∗ {qa , qf a } × {ua , ub }, Qf∗ = {qf a } × {ua , ub }, ∆0 = {a → hqa , ua i, f (hqa , ua i) hqf a , ua i, f (hqa , ub i) → hqf a , ua i}. The saturation steps stop at k = 1 and we have ∆1 = ∆0 ∪ {b hqa , ub i, g(hqa , ub i) → hqf a , ub i}, ∆2 = ∆1
→ = → → u t
The procedure Pin eventually terminates at some k, because rewrite rules in R and states Q∗ are finite, and hence, possible transitions rules are finite. Apparently ∆0 ⊂ · · · ⊂ ∆k = ∆k+1 = · · · . A measurement of transitions of ∆∗ is defined as ||s −−→ t|| = 0 and ||s −−−−−−→ t|| = i + 1 for i ≥ 0. This is ∆0
∆i+1 \∆i
extended on transition sequences as a multiset:
||s0 −−→ s1 −−→ · · · −−→ sn || = {||si −−→ si+1 || | 0 ≤ i < n}. ∆ ∆ ∆ ∆ ∗
∗
∗
∗
Now we can define an order A on transition sequences by ∆∗ , which is necessary in proofs. def α A β ⇔ ||α|| >mul ||β|| where >mul is the multiset extension of > on N. ∗
∗
Proposition 4. (a) s −→ q if and only if s −−→ hq, ui for some u ∈ QNF . ∆ ∆0 ∗ ∗ (b) s −−→ hq, ui implies s −−−→ u ∆∗
∆NF
Proof. Direct consequence of the construction of ∆0 and the completeness of ANF . u t ∗
Lemma 5. Let α : s[hq, ui]p −−→ hq 0 , u0 i. If k = 0 or u ∈ QNF \ QfNF then there ∆ k
∗
exists v 0 ∈ QNF such that β : s[hq, vi]p −−→ hq 0 , v 0 i and α w β for any v ∈ QNF . ∆ k
Proof. If k = 0, it trivially holds from the construction of ∆0 . We prove in the n case u ∈ QNF \ QfNF by induction on steps n of transition s[hq, vi]p −−→ hq 0 , v 0 i. ∆k Since it is trivial in the case n = 0, let n > 0. Then we have two cases according to the form of the transition rule applied in the last step. 1. In the case that n−1
s[hq, ui]p −−−→ f (hq1 , u1 i, . . . , hqn , un i) −−→ hq 0 , u0 i, ∆ ∆ k
k
(1)
the position p can be represented as ip0 for 1 ≤ i ≤ n. Here ui 6∈ QfNF follows from u 6∈ QfNF , Proposition 4 (b), and the construction of ∆NF . Since ∗ ∗ αi : (s|i )[hq, ui]p0 −−→ hqi , ui i, we have βi : (s|i )[hq, vi]p0 −−→ hqi , v 00 i and ∆k ∆k αi w βi for some v 00 ∈ QNF by the induction hypothesis. Thus we have ∗ s[hq, vi]p −−→ f (. . . , hqi−1 , ui−1 i, hqi , v 00 i, hqi+1 , ui+1 i, . . .) ∆k (a) If the transition rule in the last step of (1) is in ∆0 , we also have f (. . . , hqi−1 , ui−1 i, hqi , v 00 i, hqi+1 , ui+1 i, . . .) → hq 0 , v 0 i ∈ ∆0 from the construction, where v 0 is determined by f (. . . , ui−1 , v 00 , ui+1 , . . .) → v 0 ∈ ∆NF .
(b) Otherwise we assume that the transition rule in the last step of (1) is in ∆k \ ∆k−1 without loss of generality. It is known that the rule is produced by the first inference rule in Step 2 and hence ri 6∈ X; otherwise ui ∈ QfNF follows from hqi , ui i = ri θ, which contradicts ui 6∈ QfNF . Thus f (. . . , hqi−1 , ui−1 i, hqi , v 00 i, hqi+1 , ui+1 i, . . .) → hq 0 , v 0 i ∈ ∆k \ ∆k−1 and α w β. n−1 2. In the case that s[hq, ui]p −−−→ hq1 , u1 i −−→ hq 0 , u0 i, we can show it similarly ∆k ∆k to the previous case. u t ∗
n
Lemma 6. Let R be left-linear and right-shallow. Then s −∆ −→ hq, ui and s −→ R in ∗
∗
t imply t −∆ −→ hq, u0 i for some u0 ∈ QNF . ∗
∗
Proof. We present the proof in the case where n = 1. Let s −∆ −→ hq, ui and k s = s[lσ]p − s[rσ] = t for some rewrite rule l → r ∈ R. → in p R 1. Consider the case where the rewrite rule is in the form f (l1 , . . . , ln ) → ∗ g(r1 , . . . , rm ). Since this rewrite rule is left-linear, s −∆ −→ hq, ui is represented as s
=
s[f (l1 σ, . . . , ln σ)]p
k
∗
s[f (l1 θ, . . . , ln θ)]p
−∆ −→ k
∗
∗
−∆ −→ k
s[f (hq1 , u1 i, . . . , hqn , un i)]p −∆ −→ s[hq 00 , u00 i]p −∆ −→ hq, ui for some θ : X → Q∗ . k
k
Note that u00 6∈ QfNF since s|p is not a normal form. ∗ We have li θ −−→ hqi , ui i, where ui ∈ QfNF since each li σ is a normal form. We ∆k
∗
also have f (u1 , . . . , un ) −−−→ u00 by Proposition 4 (b). From the construction ∆NF of A∗ , there exists a transition rule g(hq10 , u01 i, . . . , hqn0 , u0m i) → hq 00 , v 0 i ∈ ∆k+1 such that ½ rj θ · · · rj ∈ X 0 0 hqj , uj i = hq rj , v 00 i · · · r 6∈ X where r −∗−→ hq rj , v 00 i j
j
∆0
(a) For j such that rj ∈ X, we have li |p0 = rj for some i and p0 . Hence ∗ rj σ = li |p0 σ −−→ li |p0 θ = rj θ = hqj0 , u0j i. ∆k (b) For j such that rj 6∈ X, we have rj σ = rj since R is right-shallow, and ∗ rj −−→ hq rj , v 00 i = hqj0 , u0j i. ∆0
∗
0 Therefore we have t = s[g(r1 σ, . . . , rm σ)]p −−→ s[g(hq10 , u01 i, . . . , hqm , u0m i)]p ∆ k
∗
−∆−−→ s[hq 00 , v 0 i]p , and s[hq 00 , v 0 i]p −∆ −→ hq, u0 i for some u0 ∈ QNF by Lemma 5. k+1
k
2. In the case that the rewrite rule is in the form f (l1 , . . . , ln ) → x, we can show it similarly to the previous case. u t Now we obtain the following lemma. Lemma 7. If R be left-linear and right-shallow, then L(A∗ ) ⊇ −→ [L(A)]. R in ∗
∗
∗
Proof. Let s − t and s −→ q ∈ Qf . Then we have s −−→ hq, ui ∈ Qf∗ by → R in ∆ ∆ ∗ ∆∗
Proposition 4 (a). Hence t −−→ hq, u0 i ∈ Qf∗ by Lemma 6.
0
u t
$ ()
% # # # #
## ' # # % & ! " % # # # #
Fig. 2. The diagram of proof of lemma 6
Lemma 8. Let ∆∗ be generated from a right-linear right-shallow TRS. Then ∗ ∗ α : t (−−→ ◦ −−−−→ ) hq, u0 i implies s −→in t, β : s −−→ hq, ui and α A β for R ∆k+1 ∆k ∆0 some term s and u ∈ QNF . Proof. Consider the case where the last transition rule applied in α is (in 0 , u0m i) → hq, u0 i and we assume that it is in the form of) g(hq10 , u01 i, . . . , hqm ∆k+1 \ ∆k without loss of generality. Then α can be represented as t = ∗ 0 , u0m i) −−−−−−→ hq, u0 i, and the last transig(t1 , . . . , tm ) −−→ g(hq10 , u01 i, . . . , hqm ∆0
∆k+1 \∆k
tion rule applied is added by the first inference rule in the procedure. Hence there exist f (l1 , . . . , ln ) → g(r1 , . . . , rm ) ∈ R, f (hq1 , u1 i, . . . , hqn , un i) → hq, ui ∈ ∆k , and θ : X → (Q ] QRS ) × QfNF such that – – – –
∗
li θ −−→ hqi , ui i and ui ∈ QfNF , ∆k hqj0 , u0j i = rj θ if rj ∈ X, qj0 = q rj if rj 6∈ X, and L(∆0 , xθ) 6= ∅ for each erasing variable.
Hence, we have the following: ∗
1. For j such that rj ∈ X, we have tj −∆ −→ hqj0 , u0j i = rj θ. 0
∗
2. For j such that rj 6∈ X, we have tj −−−→ q rj hence tj = rj from the ∆RS construction of ∆0 . Thus we have tj = rj θ since R is right-shallow. ∗
∗
0 , u0m i). Thus we have g(t1 , . . . , tm ) −−→ g(r1 θ, . . . , rm θ) −−→ g(hq10 , u01 i, . . . , hqm ∆0 ∆0 We define a substitution σ : Var(f (l1 , . . . , ln )) → T (F ) as follows:
½ xσ =
tj · · · if there exists j such that rj = x ∗ t0 · · · otherwise, choose an arbitral t0 such that t0 −−→ xθ, ∆ 0
where σ is well-defined from the right-linearity of rewrite rules. We can construct ∗ ∗ β : f (l1 , . . . , ln )σ −−→ f (l1 , . . . , ln )θ −−→ f (hq1 , u1 i, . . . , hqn , un i) −−→ hq, ui, ∆0
∆k
∆k
where α A β. Since ui ∈ QfNF , each li σ is a normal form. Hence we have
g(r1 , . . . , rm )σ = g(t1 , . . . , tm ) = t. Therefore the lemma f (l1 , . . . , ln )σ − → R in of the case follows by taking s = f (l1 , . . . , ln )σ. For the case where the transition rule applied last in α is (in the form of) hq 0 , u00 i → hq, u0 i, the lemma can be shown as similar to the previous case. u t Lemma 9. If R be right-linear and right-shallow, then L(A∗ ) ⊆ −→in [L(A)]. R
∗
Proof. From Proposition 4(a), it is enough to show the claim that α : t −∆ −→ ∗ − → R in
∗
∗ −∆ −→ 0
hq, u0 i implies s t, and s hq, ui for some s ∈ T (F ) and u ∈ QNF . We prove it by induction on α with respect to A. 1. Consider the case where the last transition rule applied in α is (in the 0 , u0m i) → hq, ui ∈ ∆k . Then α can be repreform of) g(hq10 , u01 i, . . . , hqm ∗ 0 , u0m i) −−→ hq, ui. Since sented as t = g(t1 , . . . , tm ) −−→ g(hq10 , u01 i, . . . , hqm ∆k
∆∗
∗
∗
tj α A (tj −−→ hqj0 , u0j i), there exists sj for every j such that sj − → ∆ R in ∗
∗
and sj −−→ hqj0 , vj0 i from the induction hypothesis. Here we have vj0 ∈ ∆ 0
QNF \ QfNF or sj = tj for each j since vi0 ∈ QfNF implies that si is a nor∗ ∗ mal form. Hence g(s1 , . . . , sm ) − t and we have α0 : g(s1 , . . . , sm ) −−→ → R in ∆0 0 0 , vm i) −−→ hq, vi and α w α0 by applying Lemma 5 repeatg(hq10 , v10 i, . . . , hqm ∆k 0 , u0m i) −−→ hq, ui. edly to g(hq10 , u01 i, . . . , hqm ∆k If k = 0 then the claim trivially holds by letting s = g(s1 , . . . , sm ). Hence ∗ let k > 0. Then we have β : s0 −−−→ hq, v 0 i with α0 A β and s0 − → R in ∆ k−1
g(s1 , . . . , sm ) for some s0 and v 0 by Lemma 8. Since α A β, the claim of this case follows from the induction hypothesis. 2. In the case where the last transition rule applied in α is (in the form of) hq 0 , u0 i → hq, ui ∈ ∆k , we can show it similarly to the previous case. u t
I.H., Lemma 5 t = g(t1 , . . . , tm ) in
∗ ∆∗
0 g(hq10 , u01 i, . . . , hqm , u0m i)
0 0 g(hq10 , v10 i, . . . , hqm , vm i)
∗ R
g(s1 , . . . , sm ) in Lemma 8
∆k ∆k
∗
∗ ∆0 ∗ R
∗ in
R
s
hq, vi hq, v 0 i
∆k−1 s0
hq, u0 i
∆0
I.H.
Fig. 3. The diagram of proof of lemma 9
hq, ui
We obtain the following theorems from Lemma 7, Lemma 9, and Theorem 1. Theorem 10. Innermost reduction for linear right-shallow TRSs effectively preserves regularity. Thus innermost reachability is a decidable property for linear right-shallow TRSs.
4
Regularity preservation for context-sensitive reduction
A context-sensitive rewrite relation is a subrelation of a rewrite relation in which rewritable positions are indicated by specifying arguments of function symbols. A mapping µ : F → P(N) is said to be a replacement map (or F -map) if µ(f ) ⊆ {1, . . . , ar(f )} for all f ∈ F . A context-sensitive rewriting system (CSTRS) is a pair R = (R, µ) of a TRS and a replacement map. We say R is an underlined TRS of R. The set of µ-replacing positions Posµ (t) (⊆ Pos(t)) is recursively defined: Posµ (t) = {ε} if t is a constant or a variable, otherwise Posµ (f (t1 , . . . , tn )) = {ε} ∪ {ip | i ∈ µ(f ), p ∈ Posµ (ti )}. The rewrite relation p induced by a CS-TRS R is defined: s ,− t and p ∈ Posµ (t). → → t if and only if s − R R Similarly to the previous section, this section shows that a context-sensitive reduction ,− → effectively preserves recognizability if the underlined TRS R of R R is linear and right-shallow. In order to show the property, we prepare a procedure Pcs that inputs a TA A and a CS-TRS R and outputs a TA A∗ , and show that L(A∗ ) = ,− → [L(A)]. R The main idea is the introduction of an extra state q˜ for each state q. The former state q˜ is used for accepting terms in ,− → [L(A, q)], while the latter state R q keeps accepting terms only in L(A, q). Example 11. Let R = (R, µ) where R = {a → b, f (x) → g(x)} and µ(f ) = ∅, µ(g) = {1}. Let A a TA that recognizes {f (a)} defined by a final state {qf a } and transition rules {a → qa , f (qa ) → qf a }. The procedure produces qf a }, and transition rules: the following TA defined by final states: Qf∗ = {˜ ∆∗ = {a → qa , a → q˜a , f (qa ) → qf a , f (qa ) → q˜f a , b → q˜a , g(˜ qa ) → q˜f a }. The TA A∗ accepts terms f (a), g(a) and g(b) in ,− [{f (a)}], and does not → R accept f (b). u t e to repreWe show the procedure Pcs in Figure 4, where we use a notation Q ∗ sent {˜ q | q ∈ Q}, and q to represent either q or q˜. Example 12. Let us follow how procedure Pcs works. Consider R and A in Example 11. In the initializing step, we have ∆RS = ∅ , Q∗ = {qa , qf a , q˜a , q˜f a }, Qf∗ = {˜ qf a }, ∆0 = ∆ ∪ {a → q˜a , f (qa ) → q˜f a }. The saturation steps stop at k = 1, we have ∆1 = ∆0 ∪{b → q˜a , g(˜ qa ) → q˜f a }, ∆2 = ∆1 . u t
Input TA A = hF, Q, Qf , ∆i and right-shallow CS-TRS R = (R, µ) over F . Output TA A∗ = hF, Q∗ , Qf∗ , ∆∗ i such that L(A∗ ) = ,− → [L(A∗ )], if R is linear. R
Step 1 (initialize) 1. Prepare a TA ARS = hF, QRS , QfRS , ∆RS i that recognizes RS(R) (the same as the procedure Pin ). Here we assume QfRS = {q t | t ∈ RS(R)} and L(ARS , q t ) = {t}. 2. Let – k := 0 – Q∗ = (Q ] QRS ) ∪ (Q^ ] QRS ) ff – Qf∗ = Q – ∆0 = ∆∪{˜ q 0 → q˜ | q 0 → q ∈ ∆} ¯ . . . , qn ) → q ∈ ∆, ¯ f (q1 ,½ ¯ q˜i · · · if i ∈ µ(f ), ∪ f (pi , . . . , pn ) → q˜ ¯ ¯ pi = q · · · otherwise i Step 2 Let ∆k+1 be transition rules produced by augmenting transition rules of ∆k by following inference rules: f (l1 , . . . , ln ) → g(r1 , . . . , rm ) ∈ R f (q1∗ , . . . , qn∗ ) → q˜ ∈ ∆k 0∗ g(q10∗ , . . . , qm ) → q˜ ∈ ∆k+1 if there exists θ : X → Q∗ such that ∗
– li θ −∆ −→ qi∗ for all 1 ≤ i ≤ n,
p˜ · · · j ∈ µ(g), rj ∈ X, p∗j = rj θ j∗ ∗
k
– qj0∗ =
pj · · · j 6∈ µ(g), rj ∈ X, pj = rj θ
rj q˜rj · · · j ∈ µ(g), rj 6∈ X
q
for all 1 ≤ j ≤ m
· · · j 6∈ µ(g), rj 6∈ X
and f (l1 , . . . , ln ) → x ∈ R f (q1∗ , . . . , qn∗ ) → q˜ ∈ ∆k q˜0 → q˜ ∈ ∆k+1 if there exists θ : X → Q∗ such that ∗
– li θ −∆ −→ qi∗ for all 1 ≤ i ≤ n, and k
– q˜0 = p˜ where p∗ = xθ.
Step 3 If ∆k+1 = ∆k then stop and set ∆∗ = ∆k ; Otherwise k := k + 1 and goto step 2.
Fig. 4. Procedure Pcs
The procedure Pcs eventually terminates at some k, because rewrite rules in R and states Q∗ are finite and hence possible transitions rules are finite. Apparently ∆0 ⊂ · · · ⊂ ∆k = ∆k+1 = · · · . We show several technical lemmas. ∗
∗
Proposition 13. If t −∆ −→ q ∈ Q ] QRS , then t −∆ −→ q. 0
k
Proof. The proposition follows from the fact that transition rules having q ∈ Q ] QRS on right-hand sides are in ∆ or ∆RS . u t ∗ ∗ Proposition 14. t −−→ q˜ ∈ Q^ ] QRS if and only if t −−→ q ∈ Q ] QRS . ∆0
∆0
Proof. From construction of ∆0 .
u t
∗ ∆k
∗ ∆k
Proposition 15. If t −−→ q ∈ Q ] QRS , then t −−→ q˜. ∗
∗
Proof. Let t −∆ −→ q, then t −∆ −→ q by Proposition 13. The lemma follows from 0 k Proposition 14 and ∆0 ⊆ ∆k . u t ∗
Lemma 16. If t[t0 ]p −−→ q˜ and p ∈ Posµ (t), then there exists q˜0 such that ∆ ∗
k
∗
t0 −−→ q˜0 and t[˜ q 0 ]p −−→ q˜. ∆ ∆ k
k
Proof. We show it by induction on the length n of transition sequence α : n n t[t0 ]p −−→ q˜. Let t[t0 ]p −−→ q˜ and p ∈ Posµ (t). ∆ ∆ k
k
∗
0
1. If p = ε, then t = t , and hence t0 −−→ q˜ follows. ∆k 2. Consider the case p = ip0 for some i ∈ N. Then α can be represented as n−1 ∗ ∗ t[t0 ]p = f (. . . , ti−1 , ti [t0 ]p0 , ti+1 , . . .) −−−→ f (. . . , qi−1 , qi∗ , qi+1 , . . .) −−→ q˜. ∆k ∆k µ 0 ∗ Since ip = p ∈ Pos (t), we have i ∈ µ(f ). Hence qi = q˜i follows from the construction of ∆k . ∗ By the induction hypothesis, there exists q˜0 such that t0 −−→ q˜0 and ∆k
∗
∗
ti [˜ q 0 ]p0 −−→ q˜i . Here we have t[˜ q 0 ]p = f (. . . , ti−1 , ti [˜ q 0 ]p0 , ti+1 , . . .) −−→ ∆k ∆k ∗ ∗ , . . .) −−→ q˜. u t , q˜i , qi+1 f (. . . , qi−1 ∆k
The following lemma is obtained from the above propositions and lemmas. ∗
n
Lemma 17. Let R be left-linear and right-shallow. Then s −−→ q˜ and s ,−→ t ∆∗ R ∗ imply t −−→ q˜. ∆∗
∗
Proof. We present the proof in the case n = 1. Let s −−→ q˜ and s = s[lσ]p ,− → ∆k R µ s[rσ]p = t for some rewrite rule l → r ∈ R, where p ∈ Pos (s). We have a ∗ ∗ transition sequence s −∆ q 0 ]p −∆ −→ s[˜ −→ q˜ by Lemma 16. k
k
1. Consider the case where the rewrite rule is in the form f (l1 , . . . , ln ) → ∗ g(r1 , . . . , rm ). Since this rewrite rule is left-linear, s −−→ q˜ is represented ∆ ∗
k
∗
as s = s[f (l1 σ, . . . , ln σ)]p −−→ s[f (l1 θ, . . . , ln θ)]p −−→ s[f (q1∗ , . . . , qn∗ )]p −−→ ∆ ∆ ∆ k
k
k
∗
∗
s[˜ q 0 ]p −−→ q˜ for some θ : X → Q∗ . Here we have li θ −−→ qi∗ . From the ∆k ∆k construction of A∗ , there exists a transition rule g(q10∗ , . . . , qn0∗ ) → q˜0 ∈ ∆k+1 such that p˜j · · · j ∈ µ(g), rj ∈ X ∗ pj · · · j 6∈ µ(g), rj ∈ X 0∗ qj = q˜rj · · · j ∈ µ(g), rj 6∈ X rj q · · · j 6∈ µ(g), rj 6∈ X where p∗j = rj θ. (a) For j such that rj ∈ X, we have li |p = rj for some i and p. Hence rj σ = ∗ ∗ li |p σ −−→ li |p θ = rj θ = p∗j . Since we have rj σ −−→ p˜j by Proposition 15, ∆k
∗
∆k
∗
we obtain rj σ −−→ qj0 in either case of qj0∗ = p˜j or qj0∗ = pj . ∆k (b) For j such that rj 6∈ X, we have rj σ = rj from the shallowness of rj ∗ ∗ ∗ and also have rj −∆ −→ q rj . Thus rj σ −∆ −→ q rj . Since we have rj σ −∆ −→ q˜rj 0
0
∗
0
∗
by Proposition 15, we obtain rj σ −∆ −→ qj0 in either case of qj0∗ = q˜rj or k 0∗ rj qj = q . ∗ 0∗ Therefore we have t = s[g(r1 , . . . , rm )σ]p −−→ s[g(q10∗ , . . . , qm )]p −−−→ s[˜ q 0 ]p ∆ ∆ k
∗
k+1
−∆ −→ q˜. k 2. In the case where the rewrite rule is in the form f (l1 , . . . , ln ) → x, we can show it similarly to the previous case. u t
∗ ∆k
,
s = s[f (l1 , . . . , ln )σ]p ∗
s[f (l1 , . . . , ln )θ]p
∗ ∆k
s[f (q1∗ , . . . , qn∗ )]p
∗ ∆k
s[˜ q 0 ]p
R
q˜
∆k+1
∗ ∆k
t = s[g(r1 , . . . , rm )σ]p
∗ ∆k
0∗ s[g(q10∗ , . . . , qm )]p
Fig. 5. The diagram of proof of lemma 17
Lemma 18. If R is left-linear and right-shallow then L(A∗ ) ⊇ ,−→ [L(A)]. R
∗
Proof. Let s ,− → t and s R have s
∗ −∆ −→ 0
∗ −∆ →
f
q ∈ Q . Since s
q˜ by Proposition 15. Hence t
∗ −∆ −→ 0
∗ −∆ −→ ∗
q from construction of ∆0 , we
q˜ ∈ Qf∗ by lemma17.
u t
Lemma 19. Let ∆∗ be generated from linear right-shallow CS-TRS. Then ∗
∗
0∗ 1. α : t = g(t1 , . . . , tm ) −−→ g(q10∗ , . . . , qm ) −−−−−−→ q˜ where tj −−→ qj0∗ for all ∆ ∆ ∗
j ∈ µ(g), or ∗ 2. α : t −∆ −→ q˜0 −−−−−−→ q˜, 0
∆k+1 \∆k
∆k+1 \∆k ∗ ∆∗
implies s ,−→ t, β : s −−→ q˜ and α A β for some term s. R
0
Proof. Consider the first case. Since the last transition rule applied in α is introduced by the first inference rule in the procedure, there exist f (l1 , . . . , ln ) → g(r1 , . . . , rm ) ∈ R, f (q1∗ , . . . , qn∗ ) → q˜ ∈ ∆k , and θ : X → Q∗ such that ∗
– li θ −∆ −→ qi∗ for all 1 ≤ i ≤ n, k p˜j · · · j ∈ µ(g), rj ∈ X, p∗j = rj θ ∗ pj · · · j 6∈ µ(g), rj ∈ X, p∗j = rj θ – qj0∗ = for all 1 ≤ j ≤ m, and q˜rj · · · j ∈ µ(g), rj 6∈ X rj q · · · j 6∈ µ(g), rj 6∈ X – L(∆0 , xθ) 6= ∅ for each erasing variable x. We have the following: ∗
1. For j ∈ µ(g) such that rj ∈ X, we have qj0∗ = p˜j and tj −−→ qj0∗ . Hence we ∆ 0
∗
have tj −−→ rj θ by Proposition 14. ∆0 ∗ 2. For j 6∈ µ(g) such that rj ∈ X, we have tj −−→ qj0∗ = rj θ. ∆∗ ∗ ∗ 3. For j ∈ µ(g) such that rj 6∈ X, we have tj −−→ qj0∗ = q˜rj . Since tj −−→ q rj ∆0 ∆0 by Proposition 14, we have tj = rj from the construction of ∆0 . Therefore tj = rj θ follows from right-shallowness. ∗ ∗ 4. For j 6∈ µ(g) such that rj 6∈ X, we have tj −−→ qj0∗ = q rj . Since tj −−→ q rj ∆∗ ∆0 by Proposition 13, we have tj = rj from the construction of ∆0 . Therefore tj = rj θ follows from right-shallowness. ∗
∗
0∗ ). Thus we have g(t1 , . . . , tm ) −−→ g(r1 θ, . . . , rm θ) −−→ g(q10∗ , . . . , qm ∆∗ ∆0 We define a substitution σ : Var(f (l1 , . . . , ln )) → T (F ) as follows: ½ tj · · · if there exists j such that rj = x xσ = t0 · · · otherwise, choose an arbitral t0 such that t0 −∗−→ xθ, ∆0
where σ is well-defined from the right-linearity of rewrite rules. We can construct ∗ ∗ β : f (l1 , . . . , ln )σ −−→ f (l1 , . . . , ln )θ −−→ f (q1∗ , . . . , qn∗ ) −−→ q˜. ∆k ∆∗ ∆k On the other hand, we have f (l1 , . . . , ln )σ ,− → g(r1 , . . . , rm )σ = R g(t1 , . . . , tm ) = t. Therefore the lemma of this case follows by taking f (l1 , . . . , ln )σ as s. Here α A β follows from the left-linearity of rewrite rules. For the case where the transition rule applied last in α is (in the form of) q˜0 → q˜ ∈ ∆k+1 \ ∆k , the lemma can be shown in similar to the previous case. u t Lemma 20. If R be linear and right-shallow then L(A∗ ) ⊆ ,−→ [L(A)]. R
Proof. Let t
∗ −∆ −→ ∗
q˜ ∈
Qf∗
and the following claim holds: ∗ ∆∗
∗ ∆0
∗
α : t −−→ q˜ implies s −−→ q˜ and s ,− → t. ∗
∗
R
Then, we have s −−→ q˜ and s ,− → t for some s. Hence s ∈ L(A) follows from ∆0 R Proposition 14. In the sequel, we prove the claim by induction on α with respect to A.
1. Consider the case that the last transition rule applied in α is (in the form of) ∗ 0∗ g(q10∗ , . . . , qm ) → q˜ ∈ ∆k . Then α can be represented as t = g(t1 , . . . , tm ) −∆ −→ ∗ 0∗ 0∗ g(q1 , . . . , qm ) −−→ q˜. ∆k
∗
(a) For j ∈ µ(g) such that qj0∗ = q˜j0 , there exists sj such that sj ,− → tj and R ∗ ∗ sj −−→ q˜j0 = qj0∗ from the induction hypothesis, since α A (tj −−→ q˜j0 ). ∆∗ ∆0 (b) For j 6∈ µ(g) such that qj0∗ = q˜j0 , we take sj as tj . ∗ (c) For j such that qj0∗ = qj0 , we have tj −−→ qj0 = qj0∗ by Proposition 14. We ∆0 take sj as tj . ∗ ∗ Now we have g(s1 , . . . , sm ) ,− −→ → g(t1 , . . . , tm ) = t and α0 : g(s1 , . . . , sm ) −∆ R
∗
∗
0∗ g(q10∗ , . . . , qm , ) −−→ q˜, where α w α0 and sj −−→ qj0∗ for all j ∈ µ(g). ∆k ∆0 In the subcase k = 0 we have no j that satisfies (b), since j ∈ µ(g) if and only if qj0∗ = q˜j0 from the construction of ∆0 . Thus every transition rule used in α0 is in ∆0 . Therefore the claim trivially holds by letting s = g(s1 , . . . , sm ). ∗ In the subcase k > 0, we have s0 ,− −→ q˜ for → g(s1 , . . . , sm ) and β : s0 −∆ R ∗ some s0 such that α0 A β by Lemma 19. Therefore the claim holds by the induction hypothesis since α A β. 2. In the case where the last transition rule applied in α is (in the form of) q 0∗ → q ∗ ∈ ∆k , we can show it similarly to the previous case. u t
t = g(t1 , . . . , tm ) I.H.
∗ ∆∗
0∗ g(q10∗ , . . . , qm )
∗ ∆0 g(r1 , . . . , rm )θ
∗ R ∗ ∆∗
∆k Lemma 19
q˜
∗ ∆∗
∗ ∆∗
g(s1 , . . . , sm )
=
g(r1 , . . . , rm )σ
R
- s0
∗ ∆0 I.H. ∗ R
- s
Fig. 6. The diagram of proof of lemma 20
The following theorem is proved by lemma 18, lemma 20 and theorem 1. Theorem 21. Context-sensitive reduction for linear right-shallow TRSs effectively preserves recognizability. Thus context-sensitive reachability is decidable for linear right-shallow TRSs.
5
Discussion
The authors think that the left-linear restriction for the context-sensitive case will be removed by modifying the procedure Pcs similar to [11] if all variables that occur in Pos(r) \ Posµ (r) are left-linear. For the innermost case, similar
modification may be possible. However, constructing ANF would be a barrier. Using automata with an equality test between brothers [1] is a possible direction On the other hand, removing the right-linearity restriction is impossible for both cases, because there exists a counter example such as the following. Example 22. For TRS R = {g(x) → f (x, x)} and a regular set G = {g(t) | t ∈ T ({a, h})}, − [G] = − [G] = {g(t), f (t, t) | t ∈ T ({a, h})} is not a regular. u t → → R R in
References 1. Anne-C´ecile Caron, Jean-Luc Coquide, and Max Dauchet. Encompassment Properties and Automata with Constraints. Proc. of 5th international conference on term rewriting and applications (RTA 1993), LNCS, 690, pp.328–342, 1993. 2. Hubert Comon. Sequentiality, second-order monadic logic and tree automata. In 10th annual IEEE symposium on logic in computer science (LICS 1995), pp.508– 517, 1995. 3. Ir´ene Durand and G´eraud S´enizergues. Bottom-Up Rewriting Is Inverse Recognizability Preserving. Proc. of 18th international conference on term rewriting and applications (RTA 2007), LNCS, 4533, pp.107–121, 2007. 4. R´emi Gilleron and Sophie Tison. Regular tree languages and rewrite systems. Fundamenta Informaticae, 24, pp.157–176, 1995. 5. Guillem Godoy and Eduard Huntingford. Innermost-reachability and innermostjoinability are decidable for shallow term rewrite systems. Proc. of 18th international conference on term rewriting and applications (RTA 2007), LNCS, 4533, pp.184–199, 2007. 6. Florent Jacquemard. Decidable approximations of term rewriting systems. Proc. of 7th international conference on rewriting techniques and applications (RTA 1996), LNCS, 1103, pp.362–376, 1996. 7. Florent Jacquemard. Reachability and confluence are undecidable for flat term rewriting systems. Information processing letters, 87(5), pp.265–270, 2003. 8. Salvador Lucas. Context-sensitive computations in functional and functional logic programs. Journal of Functional and Logic Programming, 1998(1), pp.1–61, 1998. 9. Ichiro Mitsuhashi, Michio Oyamaguchi, Florent Jacquemard. The Confluence Problem for Flat TRSs. Proc. of 8th international conference on artificial intelligence and symbolic computation (AISC 2006), LNAI, 4120, pp.68–81, 2006. 10. Takashi Nagaya and Yoshihito Toyama. Decidability for left-linear growing term rewriting systems. Proc. of 10th international conference on rewriting techniques and applications (RTA 1999), LNCS, 1631, pp.256–270, 1999. 11. Toshinori Takai, Yuichi Kaji, and Hiroyuki Seki. Right-linear finite path overlapping term rewriting systems effectively preserve recognizability. Proc. of 11th international conference on rewriting techniques and applications (RTA 2000), LNCS, 1833, pp.246–260, 2000.