term rewriting equational logic term rewriting systems
play

Term rewriting Equational logic Term rewriting systems Termination - PDF document

Term rewriting Equational logic Term rewriting systems Termination Confluence Rapid prototyping Summary and Exercises Equational logic Reflexivity t = t t 1 = t 2 Symmetry t 2 = t 1 t 1 = t 2 t 2 = t 3 Transitivity t 1 =


  1. Term rewriting • Equational logic • Term rewriting systems • Termination • Confluence • Rapid prototyping • Summary and Exercises

  2. Equational logic Reflexivity t = t t 1 = t 2 Symmetry t 2 = t 1 t 1 = t 2 t 2 = t 3 Transitivity t 1 = t 3 t 1 = t ′ . . . t n = t ′ Compatibility 1 n f ( t 1 , . . . , t n ) = f ( t ′ 1 , . . . , t ′ n ) t 1 = t 2 Instance t 1 θ = t 2 θ Notation: ⊢ E t 1 = t 2 means t 1 = t 2 is derivable by the rules above starting form equations in E . 2

  3. Example: E := { x + 0 = x, x + succ( y ) = succ( x + y ) } ⊢ E 0 + succ(0) = succ(0) x + 0 = x Inst 0 + 0 = 0 x + succ( y ) = succ( x + y ) Inst Comp 0 + succ(0) = succ(0 + 0) succ(0 + 0) = succ(0) Trans 0 + succ(0) = succ(0)

  4. Soundness Theorem ⊢ E t 1 = t 2 ∀ E | = ∀ ( t 1 = t 2 ) . If then Proof. Assume ⊢ E t 1 = t 2 . Then ∀ E ⊢ ∀ ( t 1 = t 2 ) . Hence ∀ E | = ∀ ( t 1 = t 2 ) , by the soundness theorem for natural deduction.

  5. Completeness Theorem (Birkhoff) ∀ E | = ∀ ( t 1 = t 2 ) ⊢ E t 1 = t 2 . If then Proof. Σ := the signature of E ∪ { t 1 = t 2 } V := the set of all variables for the sorts of Σ. Then T(Σ , V ) is the set of all Σ-terms. t 1 = E t 2 : ⇔ ⊢ E t 1 = t 2 = E is a congruence on the term algebra T(Σ , V ). A := T(Σ , V ) / = E A | = ∀ ( t 1 = t 2 ) ⇔ ⊢ E t 1 = t 2 (++) From (++), ‘ ⇐ ’ it follows that A is a model of ∀ E . Now: Assume ∀ E | = ∀ ( t 1 = t 2 ) . Then A | = t 1 = t 2 , since A is a model of ∀ E . Consequently ⊢ E t 1 = t 2 , by (++), ⇒ .

  6. A term rewriting system over a signature Σ is a finite set R of rewrite rules l �→ r , where r and l are Σ-terms, such that (i) l is not a variable, (ii) FV ( r ) ⊆ FV ( l ). t ≡ u { lθ/x } and t ′ ≡ u { rθ/x } t → R t ′ : ⇔ for some rewrite rule l �→ r ∈ R, some Σ-term u with exactly one occurrence of some variable x , and some substitution θ : X → T(Σ , Y ) → R is called the term rewriting relation generated by R .

  7. t → ∗ : ⇔ t → R . . . → R t ′ R t ′ t → R t ′ or t ′ → R t t ↔ R t ′ : ⇔ t ≃ R t ′ : ⇔ t ↔ R . . . ↔ R t ′ Any finite or infinite sequence t 0 → R t 1 → R . . . is called a reduction sequence . t is in normal form w.r.t. R if it cannot be rewritten, i.e. t �→ R t ′ for any t ′ . t ′ is a normal form of t , or t normalizes to t ′ if R t ′ and t ′ is in normal form. t → ∗ R := { l �→ r | l = r ∈ E } is called the term rewriting system defined by E . We write t → E t ′ instead of t → R t ′ .

  8. Example: E := { x + 0 = x, x + succ( y ) = succ( x + y ) } . 0 + (0 + succ(0)) → E 0 + succ(0 + 0) → E 0 + succ(0) → E succ(0 + 0) → E succ(0) Exercise: normalize succ(0 + 0) + 0 Normal forms: succ n (0) (that is 0, succ(0), succ(succ(0)) . . . ) 0 + (0 + succ(0)) ≃ E succ(0 + 0) + 0. Exercise: normalize 0 + (0 + succ(0)) using a different re- duction sequence.

  9. For a set E of equations and closed terms t, t ′ the following assertions are equivalent: ∀ E | (i) = t = t ′ ∀ E ⊢ c t = t ′ (ii) (iii) ∀ E ⊢ m t = t ′ (iv) ⊢ E t = t ′ (v) t ≃ E t ′

  10. Termination A term rewriting system R is terminating if there is no infinite reduction sequence t 0 → R t 1 → R . . . In a terminating term rewriting system every term has a normal form, but the converse is not true: R := { x + 0 �→ x, x + succ( y ) �→ succ( x + y ) , 0 + y �→ y + 0 } R is not terminating, but every term has a normal form. By removing the last rule the term rewriting system be- comes terminating.

  11. Proving termination A function µ mapping Σ-terms to natural numbers such that t → R t ′ ⇒ µ ( t ) > µ ( t ′ ) is called a termination measure for the term rewriting system R . Lemma. Every rewrite system that has a termination measure is terminating. Lemma. Let R be a term rewriting system such for every rule l �→ r in R r is shorter than l , every variable x ∈ FV ( r ) occurs in r at most as often as it occurs in l . Then R is terminating. Proof. The assumptions imply that the length of terms is a termination measure.

  12. Exercises. Which of the following term rewriting systems are termi- nating? R 1 := { x − 0 �→ x, succ( x ) − succ( y ) �→ x − y } R 2 := { f ( g ( x ) , y ) �→ f ( y, y ) } R 3 := { x + 0 �→ x, x + succ( y ) �→ succ( x + y ) }

  13. Theorem Given: R term rewriting system over Σ. A Σ-algebra, all carriers A s = N . f A strictly monotone for every operation f , i.e. n i > n ′ ⇒ i f A ( n 1 , . . . , n i , . . . , n k ) > f A ( n 1 , . . . , n ′ i , . . . , n k ) l A,α > r A,α for every l �→ r ∈ R and every variable assign- ment α . Then R is terminating. Show that µ ( t ) := t A,α is a termination measure, Proof. where α is an arbitrary variable assignment.

  14. Example R := { x + 0 �→ x, x + succ( y ) �→ succ( x + y ) } Define algebra A by 0 A := 1 succ A ( n ) := n + 1 n + A m := n + 2 ∗ m α arbitrary variable assignment. n := α ( x ), m := α ( y ) ( x + 0) A,α = n + A 0 A = n + 2 ∗ 1 > n = x A,α ( x + succ( y )) A,α = n + A succ A ( m ) = n + 2 ∗ ( m + 1) > n + 2 ∗ m + 1 = succ( x + y ) A,α

  15. R is confluent if for all terms t, t 1 , t 2 : if t → ∗ R t 1 and t → ∗ R t 2 , then there exists t 3 such that t 1 → ∗ R t 3 and t 2 → ∗ R t 3 . t � ❅ ∗ ∗ � ❅ � ✠ ❘ ❅ R R t 1 t 2 ❅ � ∗ ∗ ❅ � ❅ ❘ ✠ � R t 3 R

  16. R is locally confluent if for all terms t, t 1 , t 2 : if t → R t 1 and t → R t 2 , then there exists t 3 such that t 1 → ∗ R t 3 and t 2 → ∗ R t 3 . t � ❅ � ❅ � ✠ ❘ ❅ R R t 1 t 2 ❅ � ∗ ∗ ❅ � ❅ ❘ � ✠ R t 3 R Newman’s Lemma Every terminating and locally confluent term rewriting system is confluent.

  17. Example R := { a �→ b, a �→ c, b �→ a, b �→ d } R is locally confluent. R is not confluent, since a → R c and a → ∗ R d , but c and d cannot reduced to a common term. Exercises. (a) Add one rewrite rule that makes R confluent. (b) Remove one rewrite rule such that R becomes confluent. (c) Is R terminating?

  18. Theorem Every confluent term rewriting R has the Church-Rosser property : For all t 1 , t 2 t 1 ≃ R t 2 ⇔ there exists t 3 s.t. t 1 → ∗ R t 3 and t 2 → ∗ R t 3 t 1 ≃ R t 2 ❅ � ∗ ∗ ❅ � ❅ ❘ � ✠ R t 3 R

  19. Lemma If R is confluent and terminating term rewriting system then every term t has a unique normal form nf( t ). Theorem Let E be a system of equations defining a confluent and terminating term rewriting system . Then for all t 1 , t 2 ∀ E | ⇔ = t 1 = t 2 nf( t 1 ) = nf( t 2 ) In particular, the relation ∀ E | = t 1 = t 2 is decidable. Proof. t 1 ≃ R t 2 if and only if nf( t 1 ) = nf( t 2 ).

  20. Proving confluence: Critical pairs l 1 �→ r 1 , l 2 �→ r 2 variants of rules in R FV ( l 1 ) ∩ FV ( l 2 ) = ∅ . t subterm of l 1 which is not a variable, that is l 1 ≡ u { t/x } , x fresh occurring in u exactly once. tθ ≡ l 2 θ , where θ is a most general unifier. l 1 θ ≡ ( uθ ) { l 2 θ/x } � ❅ � ❅ � ✠ ❅ ❘ R R r 1 θ ( uθ ) { r 2 θ/x } ( r 1 θ, ( uθ ) { r 2 θ/x } ) is a critical pair of R . CP( R ) := the set of all critical pairs of R .

  21. Critical Pair Lemma A term rewriting system R is locally confluent iff for all critical pairs ( t 1 , t 2 ) of R there exists a term t such that t 1 → ∗ R t and t 2 → ∗ R t . Critical Pair Theorem A terminating term rewriting system R is confluent iff for all critical pairs ( t 1 , t 2 ) of R there exists a term t such that t 1 → ∗ R t and t 2 → ∗ R t . In particular, it is decidable whether a terminating term rewriting system is confluent. Proof. Critical Pair Lemma and Newman’s Lemma. Remark. For arbitrary term rewriting systems conflu- ence is undecidable (see e.g. Baader/Nipkov).

  22. Exercise R := { x < x �→ F 0 < succ( x ) �→ T succ( x ) < 0 �→ F succ( x ) < succ( y ) �→ x < y } Is R terminating? Is R confluent?

  23. Knuth-Bendix Completion Algorithm In order to transform a terminating term rewriting system R into an equivalent one that is confluent, do the following: 1. Compute CP( R ). If for all ( t 1 , t 2 ) ∈ CP( R ) there is a t with t 1 → ∗ R t and t 2 → ∗ R t then stop (in this case R is confluent according to the Critical Pair Theorem). 2. For any ( t 1 , t 2 ) ∈ CP( R ) such that there is no t with t 1 → ∗ R t and t 2 → ∗ R t , either add the rule t 1 �→ t 2 , or the rule t 2 �→ t 1 to R , such that the extended term rewriting system remains terminating (that’s the tricky part and not always possible, i.e. the method may fail here). Set R to be the extended system and go to 1.

  24. Exercise R := { g ( g ( z )) �→ c } Is R terminating? Is R confluent? If not, use the Knuth-Bendix Completion Algorithm to make it confluent.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend