Inference with Rewriting Rules (1)

Inference with Rewriting Rules (1)

. Inference with Rewriting Rules (1) . .. NAKAMURA Masaki . Toyama Pref. Univ. December 17, 2013 NAKAMURA Masaki (Toyama Pref. Univ.) Inference with Rewriting Rules (1) December 17, 2013 1 / 22 . Content 1 Term rewriting systems .. 2 Termination Semantic methods Syntactic methods Incremental proofs of termination .. NAKAMURA Masaki (Toyama Pref. Univ.) Inference with Rewriting Rules (1) December 17, 2013 2 / 22 . Equational reasoning by rewriting The CafeOBJ reduction command implements equational logic by rewriting and can be used as a powerful interactive theorem proving system { { X + 0 = X (1) X + 0 ! X (1) E = R = X + s(Y ) = s(X + Y ) (2) X + s(Y ) ! s(X + Y ) (2) Bidirectional equations are not suitable Equations are regarded as left-to-right for automated equational reasoning rewrite rules s(0) + s(s(0)) =2+ s(s(0) + s(0)) s(0) + s(s(0)) =?E s(s(0)) + s(0) # # =2+ s(s(s(0) + 0)) 2 2 =1+ s(s(s(0))) s(s(0) + s(0)) s(s(s(0)) + 0) # # =1− s(s(s(0)) + 0) 2 1 ! =2− s(s(0)) + s(0) s(s(s(0) + 0)) 1 s(s(s(0))) NAKAMURA Masaki (Toyama Pref. Univ.) Inference with Rewriting Rules (1) December 17, 2013 3 / 22 . How to describe equational specifications Not all equational specifications can work well as rewriting systems R0 = fa ! b; b ! ag may result in an infinite loop ! ! ! ··· a R0 b R0 a R0 R1 = fa ! b; a ! cg cannot prove b = c by rewriting ! 6! 6! b R1 a R1 c; but c R1 a; b R1 a Unfortunately, CafeOBJ system does not find suitable rewrite rules (directions) from input equational specifications. We need a way to describe equational specifications as rewrite systems. NAKAMURA Masaki (Toyama Pref. Univ.) Inference with Rewriting Rules (1) December 17, 2013 4 / 22 . Terms To concentrate to understand a mechanism of rewriting, we first assume simple equational specifications which has only one sort, operators without any attributes (assoc, comm, etc) and unconditional equations Σ : the set of operators f ; g; h;::: 2 Σ TΣ(X ) (abbr. T ): the set of terms constructed from operators in Σ and variables in the variable set X X ; Y ; Z;::: 2 X f (0); g(c; X ); h(f (0); g(c; X ); Y );::: 2 TΣ(X ) NAKAMURA Masaki (Toyama Pref. Univ.) Inference with Rewriting Rules (1) December 17, 2013 5 / 22 . Term rewriting systems A (Σ-)rewrite rule is defined as a pair (l; r) 2 TΣ(X ) × TΣ(X ) of terms, denoted by l ! r, which satisfies the following variable conditions l 62 X , that is, the left-hand side of any rewrite rule is not a variable X + 0 ! X : OK X ! X + 0 : NG V (r) ⊆ V (l), that is, all variables appearing in r should appear in l X + s(Y ) ! s(X + Y ): OK 0 ! X ∗ 0 : NG A pair (Σ; R) of a set Σ of operators and a set R of Σ-rewrite rules is called a term rewriting system (TRS). When we call R a TRS, its Σ is the set of all operators appearing in R. The CafeOBJ reduction command ignores equations which do not satisfy the first variable conditions, e.g. X ! X + 0. NAKAMURA Masaki (Toyama Pref. Univ.) Inference with Rewriting Rules (1) December 17, 2013 6 / 22 . Subterms The set O(t) of positions of a term t is defined as O(x) = f"g and f g [ f 2 N ∗ j 2 f g 2 g O(f (¯tn)) = " i:p + i n¯ ; p O(ti ) Ex: Let t = x + s(y). O(t) = f"; 1; 2; 2:1g where " is the empty string, and ¯tn is abbr. of t1;::: tn. The subterm of a term t at position p 2 O(t), denoted by tjp, is defined as tj" = t and f (¯tn)ji:p = ti jp Ex: tj" = x + s(y); tj1 = x; tj2 = s(y); tj2:1 = y 0 The subterm relation ≥sub is defined as follows: t ≥sub t if and only 0 if t = tjp for some p 2 O(t), and the strict subterm relation >sub is defined as ≥sub n =. Ex: x + s(y) >sub s(y) >sub y NAKAMURA Masaki (Toyama Pref. Univ.) Inference with Rewriting Rules (1) December 17, 2013 7 / 22 . Substitution 0 0 The replacement of t with t at position p 2 O(t), denoted by t[t ]p, 0 0 0 0 is defined as t[t ]" = t and f (¯tn)[t ]i:p = f (:::; ti [t ]p;:::) Ex. Let t = x + s(y). t[0 + 0]1 = (0 + 0) + s(y) and t[0 + 0]2:1 = x + s(0 + 0) A map θ 2 T X from the set of variables X to a set of terms T is called a substitution if Dom(θ) = fx 2 X j θ(x) =6 xg is finite. We write θ = fx0 t0; x1 t1;:::; xn tng when θ(xi ) = ti for all i 2 Dom(θ) The instance of a term t by θ, denoted by tθ, is defined as xθ = θ(x) and f (¯tn)θ = f (tnθ). tθ0 = s(0) + s(0) if θ0 = fx s(0); y 0g tθ1 = s(y) + s(x + z) if θ1 = fx s(y); y x + zg NAKAMURA Masaki (Toyama Pref. Univ.) Inference with Rewriting Rules (1) December 17, 2013 8 / 22 . Rewrite relation For a TRS R, the rewrite relation !R is defined as follows: 0 X 0 t !l!r t () 9θ 2 T :9p 2 O(t): tjp = lθ ^ t = t[rθ]p 0 0 t !R t () 9l ! r 2 R:t !l!r t Ex. Let R+ = f(1) : X + 0 ! X ; (2) : X + s(Y ) ! s(X + Y )g s(s(0)) + s(0) !(2) s(s(s(0)) + 0) !(1) s(s(s(0))) !+ ! R is the transitive closure of R (more than zero steps) !∗ ! R is the reflexive and transitive closure of R (zero or more than zero steps). !∗ s(s(0)) + s(0) R+ s(s(s(0))) An instance of l of some l ! r 2 R is called a redex A term t is called an (R-)normal form if there is no u such that t !R u. NAKAMURA Masaki (Toyama Pref. Univ.) Inference with Rewriting Rules (1) December 17, 2013 9 / 22 . Equational reasoning ∗ A congruence relation =R is defined as (!R [ R ) 0 When we regard R as a set of equations, t =R t means the equation can be deduced from the axioms R. One of the purposes of the TRS 0 is to prove t =R t by rewriting. # 0 !∗ 0 !∗ t R t if and only if there exists u such that t R u and t R u. We call t and t0 joinalble. 0 0 It is trivial that t =R t ( t #R t 0 0 The converse t =R t ) t #R t is not always true as I showed Termination and confluence properties give us a sufficient condition 0 0 under which t =R t , t #R t NAKAMURA Masaki (Toyama Pref. Univ.) Inference with Rewriting Rules (1) December 17, 2013 10 / 22 . Termination and confluece R is terminating if there is no infinite rewrite sequence t0 !R t1 !R ··· . # 0 9 !∗ ^ !∗ 0 R is confluent if t R t whenever u. u R t u R t Termination guarantees the existence of a normal form of an input term and it can be computable in finite time, and confluence guarantees the uniqueness of normal forms. If a term t is reduced into normal forms t1 and t2, then there exists u !∗ ∗ s.t. t1 R u R t2. Since they are normal forms, we have t1 = t2. [Proposition] Let R be a terminating and confluent TRS. Then, 0 0 t =R t , t #R t NAKAMURA Masaki (Toyama Pref. Univ.) Inference with Rewriting Rules (1) December 17, 2013 11 / 22 . Proving termination Termination is undecidable, that is, there is no algorithm to solve the problem: whether R is terminating or not. There are several useful methods and tools to prove termination A basic idea is to find a well-founded ordering > on terms satisfying 0 0 t !R t implies t > t . > is well-founded if there is no infinite decreasing sequence a0 > a1 > ··· , e.g. the strict ordering on natural numbers 0 0 It is not easy to prove t > t for all t !R t since !R may be infinite (even if R is finite) For R0 = ff (X ; Y ) ! X g, ! ! we have f (a; b) R0 a and f (f (a; b); c) R0 f (a; c), and so on NAKAMURA Masaki (Toyama Pref. Univ.) Inference with Rewriting Rules (1) December 17, 2013 12 / 22 . Reduction ordering An irreflexive (t >6 t) and transitive relation is called a strict ordering A relation >⊆ T × T is stable if for all substitution θ and terms t; t0, t > t0 implies tθ > t0θ Let Σ the set of all operators. A relation >⊆ T × T is monotonic if for all f 2 Σ, ¯sn; ti 2 T , si > ti implies f (:::; si−1; si ; si+1;:::) > f (:::; si−1; ti ; si+1;:::) A rewrite ordering is a stable and monotic strict ordering A reduction ordering is a well-founded rewrite ordering [Proposition] R is terminating if and only if there exists a reduction ordering > s.t. l > r for all l ! r 2 R Two kinds of methods to obtain a reduction ordering have been considered: semantic methods and syntactic methods NAKAMURA Masaki (Toyama Pref.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    22 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us