Rewriting calculus: an introduction Horatiu Cirstea and Claude Kirchner in close collaboration with Gilles Barthe, Clara Bertolissi, Germain Faure, Luigi Liquori, Benjamin Wack Nancy March 11, 2004
2 Rewrite Systems and Lambda Calculus: some dates 1930 Lambda Calculus 1970 Formal definition of rewrite rule and rewrite relation 1975 Rewriting Modulo 1980 CRS 1980 OBJ (rewriting modulo, local strategies) 1990 Combination of lambda calculus and rewriting 1990 Higher-order rewriting systems 1990 Rewriting logic 1995 Deduction Modulo 1997 Rewriting calculus 2000 Combination of CC and rewriting Rewriting calculus, Nancy March 11-12, 2004
3 Pre-history 1980 Jouannaud-Lescanne: Nancy rewriting school 1984 Reve workshop in Nancy: implicit ideas about computation and deduction by rewriting 1984-86 OBJ 1990 Ecolog Nancy-Orsay 1992 ELAN-00 (deduction and computation, user defined strategies) MV 1995 Study of strategies PB 1996 First ideas about the rewriting calculus 2000 Formal definition of the rewriting calculus HC Rewriting calculus, Nancy March 11-12, 2004
4 History ➲ Term rewriting from a functional point of view ➥ rewrite rules as functions applied using an explicit application function ➲ The ρ -calculus ➥ confluence (evaluation strategies) and termination (simply typed calculus) ➥ operational semantics of ELAN ➲ Rho-calculus ➥ representation of object calculi (ObjCal and LambdaObjCal) ➥ sophisticated type systems - the Rho-cube ➲ Exceptional Rho-calculus ➥ delayed matching constraints ➥ exception handling mechanism Rewriting calculus, Nancy March 11-12, 2004
The untyped rewriting calculus - ρ -calculus
6 The Untyped Syntax P ::= T T ::= X | K | P � T | T • T | [ P ≪ T ] T | T ; T 1. T 1 � T 2 denotes a rule abstraction with pattern T 1 and body T 2 ... the free variables of T 1 are bound in T 2 2. [ T 1 ≪ T 2 ] T 3 denotes a delayed matching constraint ... the free variables of T 1 are bound in T 3 but not in T 2 3. The terms can be also structures built using the symbol “;” 4. We work modulo the α -convention and the hygiene-convention Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
7 Some ρ -terms ( X � X ) • a similar to the λ -term ( λx.x ) a ( X � X • X ) • ( X � X • X ) the well-known λ -term ( ωω ) Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
7 Some ρ -terms ( X � X ) • a similar to the λ -term ( λx.x ) a ( X � X • X ) • ( X � X • X ) the well-known λ -term ( ωω ) ( a � b ) • a the application of the rule a � b to the term a ( f ( X , Y ) � g ( X , Y )) • f ( a, b ) a classical rewrite rule application Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
7 Some ρ -terms ( X � X ) • a similar to the λ -term ( λx.x ) a ( X � X • X ) • ( X � X • X ) the well-known λ -term ( ωω ) ( a � b ) • a the application of the rule a � b to the term a ( f ( X , Y ) � g ( X , Y )) • f ( a, b ) a classical rewrite rule application ( a � b ; a � c ) • a “non-deterministic” application Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
8 Some abbreviations △ T ( T 1 , . . . , T n ) T • T 1 . . . • T n function-application ( n = ( T i ) i =1 ...n △ T 1 ; . . . ; T n structure/object ( n ∈ = △ T 1 .T 2 T 1 • T 2 • T 1 Kamin’s self-application = Operator Associate Priority Left > • [ ≪ ] Right > Right > � ; Right > Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
9 Matching Equations and Solutions 1. A match equation is a formula of the form T 1 ≺ ≺ T 2 . △ ≺ T ′ 2. A matching system T i =0 ...n T i ≺ ∧ i is a conjunction of = match equations, where ∧ is associative, commutative, and idempotent. 3. A matching system T is successful if it is empty or: (a) has the shape i =0 ...n X i ≺ ∧ ≺ T i j =0 ...m K j ≺ ∧ ≺K j ; (b) for all h, k = 0 . . . n , such that h � = k , we have X h � = X k ; 4. A substitution σ T = { T 1 / X 1 · · · T n / X n } is the solution of a successful matching system T. The set of solutions of T is denoted by S ol ( T ) . Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
10 Reduction relies on matching power Matching is parametrized over a theory T and an order ≺ on substitutions S ol ( T 1 ≺ ≺ T T 2 ) = σ 1 , . . . , σ n , . . . σ ∈ S ol ( T 1 ≺ ≺ T T 2 ) ⇔ | = T σ ( T 1 ) = T 2 σ 1 ≺ . . . ≺ σ n ( n ≤ ∞ ) ‘ THEORIES ALGORITHM Semantics Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
11 The Small-step Reduction Semantics ( P � A ) • B → ρ [ P ≪ B ] A [ P ≪ B ] A → σ Aθ 1 ; . . . ; Aθ n ; . . . with { θ 1 , . . . , θ n , . . . } = S ol ( ( A ; B ) • C → δ A • C ; B • C Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
12 Intuition on the small-step Semantics ( P � A ) • B → ρ [ P ≪ B ] A → σ Aθ if Pθ = T B ( P � A ) • B → ρ [ P ≪ B ] A STOP ! if � ∃ θ. Pθ = T B Matching Examples Confluence Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
13 Some ρ -reductions ( X � X ) • a ( X � ( X • X )) • ( X � ( X • X )) ( a � b ) • a ( f ( X , Y ) � g ( X , Y )) • ( f ( a, b )) ( f ( X , Y ) � g ( X , Y )) • ( g ( a, b )) ( a � b ; a � c ) • a Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
13 Some ρ -reductions ( X � X ) • a �→ → δ a ρ σ ( X � ( X • X )) • ( X � ( X • X )) ( a � b ) • a ( f ( X , Y ) � g ( X , Y )) • ( f ( a, b )) ( f ( X , Y ) � g ( X , Y )) • ( g ( a, b )) ( a � b ; a � c ) • a Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
13 Some ρ -reductions ( X � X ) • a �→ → δ a ρ σ ( X � ( X • X )) • ( X � ( X • X )) �→ → δ { ω • ω } �→ → δ . . . ρ σ ρ σ ( a � b ) • a ( f ( X , Y ) � g ( X , Y )) • ( f ( a, b )) ( f ( X , Y ) � g ( X , Y )) • ( g ( a, b )) ( a � b ; a � c ) • a Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
13 Some ρ -reductions ( X � X ) • a �→ → δ a ρ σ ( X � ( X • X )) • ( X � ( X • X )) �→ → δ { ω • ω } �→ → δ . . . ρ σ ρ σ ( a � b ) • a �→ → δ b ρ σ ( f ( X , Y ) � g ( X , Y )) • ( f ( a, b )) ( f ( X , Y ) � g ( X , Y )) • ( g ( a, b )) ( a � b ; a � c ) • a Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
13 Some ρ -reductions ( X � X ) • a �→ → δ a ρ σ ( X � ( X • X )) • ( X � ( X • X )) �→ → δ { ω • ω } �→ → δ . . . ρ σ ρ σ ( a � b ) • a �→ → δ b ρ σ ( f ( X , Y ) � g ( X , Y )) • ( f ( a, b )) �→ → δ [ f ( X , Y ) ≪ f ( a, b )] g ( X , ρ σ ( f ( X , Y ) � g ( X , Y )) • ( g ( a, b )) ( a � b ; a � c ) • a Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
13 Some ρ -reductions ( X � X ) • a �→ → δ a ρ σ ( X � ( X • X )) • ( X � ( X • X )) �→ → δ { ω • ω } �→ → δ . . . ρ σ ρ σ ( a � b ) • a �→ → δ b ρ σ ( f ( X , Y ) � g ( X , Y )) • ( f ( a, b )) �→ → δ [ f ( X , Y ) ≪ f ( a, b )] g ( X , Y ) �→ → δ g ( a, b ) ρ σ ρ σ ( f ( X , Y ) � g ( X , Y )) • ( g ( a, b )) �→ → δ [ f ( X , Y ) ≪ g ( a, b )] g ( X , ρ σ ( a � b ; a � c ) • a Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
13 Some ρ -reductions ( X � X ) • a �→ → δ a ρ σ ( X � ( X • X )) • ( X � ( X • X )) �→ → δ { ω • ω } �→ → δ . . . ρ σ ρ σ ( a � b ) • a �→ → δ b ρ σ ( f ( X , Y ) � g ( X , Y )) • ( f ( a, b )) �→ → δ [ f ( X , Y ) ≪ f ( a, b )] g ( X , Y ) �→ → δ g ( a, b ) ρ σ ρ σ ( f ( X , Y ) � g ( X , Y )) • ( g ( a, b )) �→ → δ [ f ( X , Y ) ≪ g ( a, b )] g ( X , Y ) ρ σ ( a � b ; a � c ) • a �→ → δ ( a � b ) • a ; ( a � c ) • a �→ → δ b ; c ρ σ ρ σ Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
14 Simple Success Reduction ( f ( X ) � (3 � 3) X ) • f (3) �→ [ f ( X ) ≪ f (3)]((3 � 3) ρ �→ (3 � 3) • 3 σ �→ [3 ≪ 3]3 ρ �→ 3 σ ( f ( X ) � (3 � 3) X ) • f (3) �→ ( f ( X ) � [3 ≪ X ]3) • f (3) ρ �→ [ f ( X ) ≪ f (3)]([3 ≪ X ]3) ρ �→ [3 ≪ 3]3 σ �→ 3 σ Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
15 Simple Failure Reduction ( f ( X ) � (3 � 3) X ) • f (4) �→ [ f ( X ) ≪ f (4)]((3 � 3) ρ �→ (3 � 3) • 4 σ �→ [3 ≪ 4]3 ρ ( f ( X ) � (3 � 3) X ) • f (4) �→ ( f ( X ) � [3 ≪ X ]3) • f (4) ρ �→ [ f ( X ) ≪ f (4)]([3 ≪ X ]3) ρ �→ [3 ≪ 4]3 σ Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
16 Rewriting: The relation, the logic and the calculus Given a set R of rewrite rules ( l i � r i ), we can define: Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
Recommend
More recommend