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
Rewriting calculus: an introduction Horatiu Cirstea and Claude - - PDF document
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:
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
6
The Untyped Syntax P ::= T T ::= X | K | P T | T •T | [P ≪ T ]T | T ; T
body T2 ... the free variables of T1 are bound in T2
... the free variables of T1 are bound in T3 but not in T2
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(T1, . . . , Tn)
△
=
T •T1 . . . •Tn function-application (n (Ti)i=1...n
△
=
T1; . . . ; Tn structure/object (n ∈ T1.T2
△
=
T1•T2•T1 Kamin’s self-application Operator Associate Priority
> [ ≪ ] Right >
> ; Right >
Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
9
Matching Equations and Solutions
≺T2.
△
=
∧
i=0...n Ti≺
≺T ′
i is a conjunction of
match equations, where ∧ is associative, commutative, and idempotent.
(a) has the shape ∧
i=0...nXi≺
≺Ti ∧
j=0...m Kj≺
≺Kj; (b) for all h, k = 0 . . . n, such that h = k, we have Xh = Xk;
successful matching system T. The set of solutions of T is denoted by Sol(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
THEORIES ALGORITHM Semantics ‘
Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
11
The Small-step Reduction Semantics
ρ [P ≪ B]A
σ Aθ1; . . . ; Aθn; . . .
δ A•C; B•C
Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
12
Intuition on the small-step Semantics
ρ [P ≪ B]A
σ Aθ
ρ [P ≪ B]A
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 (li ri), we can define:
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 (li ri), we can define: The rewrite relation : t − →R t′ i.e. the smallest relation containing the rewrite rules and stable by context et substitution.
Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
17
Rewriting: The relation, the logic and the calculus
Given a set R of labeled rewrite rules ([ℓi] li ri), we can define:
Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
17
Rewriting: The relation, the logic and the calculus
Given a set R of labeled rewrite rules ([ℓi] li ri), we can define: The rewriting logic : R ⊢ t ⇒ t′ [Jos´ e Meseguer, TCS1992]
Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
17
Rewriting: The relation, the logic and the calculus
Given a set R of labeled rewrite rules ([ℓi] li ri), we can define: The rewriting logic : R ⊢ t ⇒ t′ [Jos´ e Meseguer, TCS1992] Formulas are sequents of the form π : t ⇒ t′ where π is a proof term, built on F ∪ L ∪ {; } recording the proof of the sequent. Models are computation spaces (quotiented set of proof terms). R ⊢ π : t ⇒ t′ if π : t ⇒ t′ can be obtained by finite application of the following rules.
Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
18
Reflexivity For any t ∈ T (F): t : t ⇒ t Congruence For any f ∈ F with arity(f) = n: π1 : t1 ⇒ t′
1
. . . πn : tn ⇒ t′
n
f(π1, . . . , πn) : f(t1, . . . , tn) ⇒ f(t′
1, . . . , t′ n)
Replacement For any ℓ : l(x1, . . . , xn) ⇒ r(x1, . . . , xn) ∈ R, π1 : t1 ⇒ t′
1
. . . πn : tn ⇒ t′
n
ℓ(π1, . . . , πn) : l(t1, . . . , tn) ⇒ r(t′
1, . . . , t′ n)
Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
19
Transitivity π1 : t1 ⇒ t2 π2 : t2 ⇒ t3 π1; π2 : t1 ⇒ t3
Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
20
Rewriting: The relation, the logic and the calculus
Given a set R of rewrite rules (li ri), we can define:
Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
20
Rewriting: The relation, the logic and the calculus
Given a set R of rewrite rules (li ri), we can define: The rewriting calculus : (lmim(R) t)→ →
ρ σ δt′
Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
21
Why a new calculus?
Rewriting is nice, but
control
Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
21
Why a new calculus?
Rewriting is nice, but
control
Lambda-calculus is great, but
Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus
22
A calculus with more explicit features
Like for explicit substitution calculi, explicitation of all the ingredients is useful.
Rewriting calculus, Nancy March 11-12, 2004 Expressiveness
22
A calculus with more explicit features
Like for explicit substitution calculi, explicitation of all the ingredients is useful. In “basic” rewriting calculus,
Rewriting calculus, Nancy March 11-12, 2004 Expressiveness
22
A calculus with more explicit features
Like for explicit substitution calculi, explicitation of all the ingredients is useful. In “basic” rewriting calculus,
Rewriting calculus, Nancy March 11-12, 2004 Expressiveness
22
A calculus with more explicit features
Like for explicit substitution calculi, explicitation of all the ingredients is useful. In “basic” rewriting calculus,
Rewriting calculus, Nancy March 11-12, 2004 Expressiveness
22
A calculus with more explicit features
Like for explicit substitution calculi, explicitation of all the ingredients is useful. In “basic” rewriting calculus,
Rewriting calculus, Nancy March 11-12, 2004 Expressiveness
22
A calculus with more explicit features
Like for explicit substitution calculi, explicitation of all the ingredients is useful. In “basic” rewriting calculus,
Rewriting calculus, Nancy March 11-12, 2004 Expressiveness
22
A calculus with more explicit features
Like for explicit substitution calculi, explicitation of all the ingredients is useful. In “basic” rewriting calculus,
Rewriting calculus, Nancy March 11-12, 2004 Expressiveness
22
A calculus with more explicit features
Like for explicit substitution calculi, explicitation of all the ingredients is useful. In “basic” rewriting calculus,
This allows for advanced calculi,
Rewriting calculus, Nancy March 11-12, 2004 Expressiveness
22
A calculus with more explicit features
Like for explicit substitution calculi, explicitation of all the ingredients is useful. In “basic” rewriting calculus,
This allows for advanced calculi,
Rewriting calculus, Nancy March 11-12, 2004 Expressiveness
22
A calculus with more explicit features
Like for explicit substitution calculi, explicitation of all the ingredients is useful. In “basic” rewriting calculus,
This allows for advanced calculi,
Rewriting calculus, Nancy March 11-12, 2004 Expressiveness
23
About the expressiveness of the rewriting calculus in T∅
(a) ϕ(X) = X (b) ϕ(λX.M) = X ϕ(M) (c) ϕ(M N) = ϕ(M)•ϕ(N) Theorem: If M →β N, then ϕ(M) → →
ρ σ δ ϕ(N)
Rewriting calculus, Nancy March 11-12, 2004 Expressiveness
23
About the expressiveness of the rewriting calculus in T∅
(a) ϕ(X) = X (b) ϕ(λX.M) = X ϕ(M) (c) ϕ(M N) = ϕ(M)•ϕ(N) Theorem: If M →β N, then ϕ(M) → →
ρ σ δ ϕ(N)
(a) A rewrite system R can be represented as the structure containing all the rules (b) Reduction strategies can be encoded Theorem: If T1 →R T2, then ∃ TR such that TR•T1 → →
ρ σ δ T2
Rewriting calculus, Nancy March 11-12, 2004 Expressiveness
24
About the expressiveness of the rewriting calculus
(term-rewrite system + abstractor)
Theorem: If T1 →R T2 . . . →R Tn, then ∃ Un . . . U1 such that every correspondent RHO-derivation terminates and converges to Tn . . .
∗
. . . . . . . . . . . . . . Un(. . . (U1 T1))
∗
. . Tn . . .
∗
Expressiveness
25
ρ-calculus and records
Record = structure composed of rewriting rules, i.e.: (Ti)i=1...n
△
=
T1; . . . ; Tn (n ∈ Nat) [mi = Ti]i∈I
△
=
(mi Ti)i∈I [cx = 0, cy = 0]
△
=
(cx 0; cy 0) Record selection = the application of the record to the label, i.e. T1.T2 as T1•T2. (cx 0; cy 0)•cx →
δ
(cx 0)•cx; (cy 0)•cx → →
ρ σ δ
0; [cy ≪ cx]0 =T (0; stk) =T 0 (TςO
bj)
. . . the matching theory
Rewriting calculus, Nancy March 11-12, 2004 Examples
26
ρ-calculus and objects
Object = record with an explicit account of self, i.e. [mi = ς(Xi)Ti]i∈I
△
=
(mi Xi Ti)i∈I Self-application = the application of an object to the object itself, i.e. T1.T2
△
=
T1•T2•T1 Ex: T
△
= a S b. Then:
T.a
△
= T •a•T
→ →
ρ σ δ (S b)•T
→ →
ρ σ δ
b Ex: T
△
= ω S S.ω. Then:
T.ω → →
ρ σ δ (S S.ω)•T
→ →
ρ σ δ
T.ω → →
ρ σ δ
. . .
Rewriting calculus, Nancy March 11-12, 2004 Examples
27
A “ping-pong” object
Let T
△
= (ping S S.pong; pong S S.ping)
Then: T.ping
△
=
T •ping•T → →
ρ σ δ
((ping S S.pong)•ping; (pong S S.ping)•ping)•T → →
ρ σ δ
((S S.pong); stk)•T → →
ρ σ δ
(S S.pong)•T; stk•T → →
ρ σ δ
(S S.pong)•T; stk =T (S S.pong)•T (TςO
bj)
→ →
ρ σ δ
T.pong → →
ρ σ δ
T.ping → →
ρ σ δ
. . .
Rewriting calculus, Nancy March 11-12, 2004 Examples
28
Functional object update
Update (a.m := b)
△
= (a; m b)
Point
△
=
val S v(1, 1); get S S.val; set S v(X, Y ) (S.val := S′ v(X, Y )) Then: Point.get → →
ρ σ δ
v(1, 1) Point.set(v(2, 2)) → →
ρ σ δ
Point; (val S′ v(2, 2)) Point.set(v(2, 2)).get → →
ρ σ δ
v(1, 1); v(2, 2)
Rewriting calculus, Nancy March 11-12, 2004 Examples
29
Imperative object update
Killm rule: killm
△
=
(m X; Y ) Y (in TςO
bj)
Update (a.m :=I b)
△
= (killm(a); m b)
Rewriting calculus, Nancy March 11-12, 2004 Examples
29
Imperative object update
Killm rule: killm
△
=
(m X; Y ) Y (in TςO
bj)
Update (a.m :=I b)
△
= (killm(a); m b)
Then: PointI.get → →
ρ σ δ
v(1, 1) PointI.set(v(2, 2)) → →
ρ σ δ
val S′ v(2, 2); get . . . , set PointI.set(v(2, 2)).get → →
ρ σ δ
v(2, 2)
Rewriting calculus, Nancy March 11-12, 2004 Examples
30
More on objects in ρ-calculus
➲ Other examples ➥ An object with “self-extension” ➥ Inheritance in the ρ-calculus ➲ Encodings ➥ The Lambda Calculus of Objects λObj ➥ The Object Calculus ςObj ➲ More sophisticated examples ➥ The Para object: labels as first-class entities ➥ The object Daemon: methods as first-class entities ➲ Types
Rewriting calculus, Nancy March 11-12, 2004 Examples
31
An object with “self-extension”
Let t1
△
= addn S (S; n S′ 1)
(t1.addn).n → →
ρ σ δ
((S (S; n S′ 1))•t1).n Back to objects
Rewriting calculus, Nancy March 11-12, 2004 Examples
31
An object with “self-extension”
Let t1
△
= addn S (S; n S′ 1)
(t1.addn).n → →
ρ σ δ
((S (S; n S′ 1))•t1).n → →
ρ σ δ
(t1; n S′ 1)
.n Back to objects
Rewriting calculus, Nancy March 11-12, 2004 Examples
31
An object with “self-extension”
Let t1
△
= addn S (S; n S′ 1)
(t1.addn).n → →
ρ σ δ
((S (S; n S′ 1))•t1).n → →
ρ σ δ
(t1; n S′ 1)
.n
△
=
t2•n•t2 Back to objects
Rewriting calculus, Nancy March 11-12, 2004 Examples
31
An object with “self-extension”
Let t1
△
= addn S (S; n S′ 1)
(t1.addn).n → →
ρ σ δ
((S (S; n S′ 1))•t1).n → →
ρ σ δ
(t1; n S′ 1)
.n
△
=
t2•n•t2 → →
ρ σ δ
((addn . . .)•n; (n S′ 1)•n)•t2 Back to objects
Rewriting calculus, Nancy March 11-12, 2004 Examples
31
An object with “self-extension”
Let t1
△
= addn S (S; n S′ 1)
(t1.addn).n → →
ρ σ δ
((S (S; n S′ 1))•t1).n → →
ρ σ δ
(t1; n S′ 1)
.n
△
=
t2•n•t2 → →
ρ σ δ
((addn . . .)•n; (n S′ 1)•n)•t2 → →
ρ σ δ
stk; (S′ 1)•t2 Back to objects
Rewriting calculus, Nancy March 11-12, 2004 Examples
31
An object with “self-extension”
Let t1
△
= addn S (S; n S′ 1)
(t1.addn).n → →
ρ σ δ
((S (S; n S′ 1))•t1).n → →
ρ σ δ
(t1; n S′ 1)
.n
△
=
t2•n•t2 → →
ρ σ δ
((addn . . .)•n; (n S′ 1)•n)•t2 → →
ρ σ δ
stk; (S′ 1)•t2 =T (S′ 1)•t2 (TςO
bj)
Back to objects
Rewriting calculus, Nancy March 11-12, 2004 Examples
31
An object with “self-extension”
Let t1
△
= addn S (S; n S′ 1)
(t1.addn).n → →
ρ σ δ
((S (S; n S′ 1))•t1).n → →
ρ σ δ
(t1; n S′ 1)
.n
△
=
t2•n•t2 → →
ρ σ δ
((addn . . .)•n; (n S′ 1)•n)•t2 → →
ρ σ δ
stk; (S′ 1)•t2 =T (S′ 1)•t2 (TςO
bj)
→ →
ρ σ δ
1 Back to objects
Rewriting calculus, Nancy March 11-12, 2004 Examples
32
Inheritance in the ρ-calculus (Abadi & Cardelli encoding of classes-as-objects)
PClass
△
=
new S (val S′ (S.preval)•S′; get S′ (S.preget)•S′; set S′ (S.preset)•S′); preval S S′ v(1, 1); preget S S′ S′.val; preset S S′ v(X, Y ) (S′.val := S′′ v( Then: PClass.new → →
ρ σ δ Point
Back to objects
Rewriting calculus, Nancy March 11-12, 2004 Examples
33
The Lambda Calculus of Objects λObj
Abstract syntax M, N ::= c | X | λX.M | MN | | M ← −n = N | M ← − +n = N | M ⇐ n | Sel(M, m, N) Small-step semantics (← ∗ = ← − or add) (Beta) (λX.M) N ❀ {X/N}M (Sel) M ⇐ m ❀ Sel(M, m, M) (Next) Sel(M ← ∗ n = N, m, P) ❀ Sel(M, m, P) (Succ) Sel(M ← ∗ n = N, n, P) ❀ NP
Rewriting calculus, Nancy March 11-12, 2004 Examples
34
Compiling λObj in ρ-calculus
[ [c] ]
△
=
c [ [X] ]
△
=
X [ [λX.M] ]
△
=
X [ [M] ] [ [MN] ]
△
=
[ [M] ]•[ [N] ] [ [ < > ] ]
△
=
stk [ [ < M ← −n = N > ] ]
△
=
killn([ [M] ]); n [ [N] ] [ [ < M ← − +n = N > ] ]
△
=
[ [M] ]; n [ [N] ] [ [M” <= ”m] ]
△
=
[ [M] ].m
△
= [
[M] ]•m•[ [M] ] [ [Sel(M, m, N)] ]
△
=
[ [M] ]•m•[ [N] ] Theorem: If M ❀λO
bj N, then [
[M] ] → →
ρ σ δTλO
bj [
[N] ].
Rewriting calculus, Nancy March 11-12, 2004 Examples
35
The Object Calculus ςObj
Abstract syntax a, b ::= X | [mi = ς(X)bi]i∈I | a.m | a.m := ς(X)b Small-step semantics Let a
△
=
[mi = ς(X)bi]i∈I (Select) a.mj ❀ {X/a}bj (Update) a.mj := ς(X)b ❀ [mi = ς(X)bi, mj = ς(X)b]i∈I\{ (Extend) a.mj := ς(X)b ❀ [mi = ς(X)bi, mj = ς(X)b]i∈I
Rewriting calculus, Nancy March 11-12, 2004 Examples
36
Compiling ςObj in ρ-calculus
[ [X] ]
△
=
X [ [a.mj] ]
△
=
[ [a] ].mj [ [ [mi = ς(X)bi]i∈I ] ]
△
=
(mi X [ [bi] ])i∈I [ [a.m := ς(X)b] ]
△
=
[ [a] ].m := X [ [b] ] Theorem: If a ❀ςO
bj b, then [
[a] ] → →
ρ σ δTςO
bj [
[b] ]. ... back to other examples
Rewriting calculus, Nancy March 11-12, 2004 Examples
37
The Para object: labels as first-class entities
Para
△
= (ten S 10; par(X) S S.X)
This object has a method par(X) which seeks for a method name that is assigned to the variable X and then sends this method to the object itself. ... back to other examples
Rewriting calculus, Nancy March 11-12, 2004 Examples
37
The Para object: labels as first-class entities
Para
△
= (ten S 10; par(X) S S.X)
This object has a method par(X) which seeks for a method name that is assigned to the variable X and then sends this method to the object itself. Para.(par(ten))
△
=
Para•(par(ten))•Para → →
ρ σ δ
((ten S 10)•(par(ten)); (par(X) S S.X)•(par(ten)))•Par → →
ρ σ δ
stk; (S S.ten)•Para =T (S S.ten)•Para (TςO
bj)
→ →
ρ σ δ
Para.ten → →
ρ σ δ
10 ... back to other examples
Rewriting calculus, Nancy March 11-12, 2004 Examples
38
The object Daemon: methods as first-class entities
Daemon
△
= set S X (X; set S′ Y (Y ; S′))
... back to other examples
Rewriting calculus, Nancy March 11-12, 2004 Overview
38
The object Daemon: methods as first-class entities
Daemon
△
= set S X (X; set S′ Y (Y ; S′))
Daemon.set(x S 3)
△
=
Daemon•set•Daemon•(x S 3) → →
ρ σ δ
(S X (X; set S′ Y (Y ; S′)))•Daemon•(x → →
ρ σ δ
(X (X; set S′ Y (Y ; S′)))•(x S 3) → →
ρ σ δ
x S 3; set S′ Y (Y ; S′)
... back to other examples
Rewriting calculus, Nancy March 11-12, 2004 Overview
38
The object Daemon: methods as first-class entities
Daemon
△
= set S X (X; set S′ Y (Y ; S′))
Daemon.set(x S 3)
△
=
Daemon•set•Daemon•(x S 3) → →
ρ σ δ
(S X (X; set S′ Y (Y ; S′)))•Daemon•(x → →
ρ σ δ
(X (X; set S′ Y (Y ; S′)))•(x S 3) → →
ρ σ δ
x S 3; set S′ Y (Y ; S′)
→
ρ σ δ (y S 4; x S 3; set
S′ Y (Y ; S′)) ... back to other examples
Rewriting calculus, Nancy March 11-12, 2004 Overview
39
Overview
➲ Integration of first-order rewriting and higher-order theories ➥ rewrite rules considered as first-class objects ➥ explicit concept of rewrite rule application ➥ matching theories as the basic parameter passing mechanism ➥ sophisticated type systems ➲ Significant expressive power ➥ first order rewriting (with (non-deterministic) strategies) ➱ rewrite based languages semantics (ELAN, Maude, OBJ,. . . ) ➥ lambda calculus ➥ object calculi: Object Calculus and Lambda Calculus of Objects
Rewriting calculus, Nancy March 11-12, 2004 Overview
40
“Untyped” Matching theories I
Empty theory T∅ of equality (up to α-conversion)
T1 = T2 T2 = T3 T1 = T3 (Trans) T1 = T2 T2 = T1 (Symm T1 = T2 T3⌈T1⌉p = T3⌈T2⌉p (Cont) t = t (Re fl)
T1⌈T2⌉p: term T1 with term T2 at position p BACK
Rewriting calculus, Nancy March 11-12, 2004 Overview
41
“Untyped” Matching theories II
Theory of Associativity TA(f) (resp. Commutativity TC(f)) is defined as T∅ plus:
f(f(T1, T2), T3) = f(T1, f(T2, T3)) (Assoc) f(T1, T2) = f(T2, T1) (Comm)
BACK
Rewriting calculus, Nancy March 11-12, 2004 Overview
42
“Untyped” Matching theories III
Theory of Idempotency TI(f) is defined as T∅ plus the axiom
f(T, T) = t (Idem)
Theory of Neutral Element TN(f0) is defined as T∅ plus
f(0, T) = T (0−Left) f(T, 0) = T (0−Right)
BACK
Rewriting calculus, Nancy March 11-12, 2004 Overview
43
“Untyped” Matching theories IV
The Theory of Stuck Tstk is defined as TN(,stk) plus the axioms
∀θ1, θ2, ∀C, Aθ2 → →
ρ σ δ C ⇒ C ≡ Pθ1
[P ≪ A]B = stk stk•T = stk
Examples [3 ≪ 4]5 = stk [3 ≪ 3]5 = stk [3 ≪ X]5 = stk BACK
Rewriting calculus, Nancy March 11-12, 2004 Overview
44
“Untyped” Matching theories V
Theory of the Lambda Calculus of Objects TλO
bj is obtained by
considering the symbol “;” as associative and stk as its neutral element, i.e.:
TλO
bj = TA(;) ∪ Tstk
Theory of the Object Calculus TςO
bj is obtained by considering
the symbol “;” as associative and commutative and stk as its neutral element, i.e.:
TςO
bj = TA(;) ∪ TC(;) ∪ Tstk = TλO bj ∪ TC(;)
THEORIES RECORDS
Rewriting calculus, Nancy March 11-12, 2004 Overview
45
The Matching Algorithm for T∅
The matching substitution solving a matching equation can be computed by the following matching reduction system:
(Appl) (T1•T2)≺ ≺(T3•T4) ❀ T1≺ ≺T3 ∧ T2≺ ≺T4 (Struct) (T1; T2)≺ ≺(T3; T4) ❀ T1≺ ≺T3 ∧ T2≺ ≺T4
Example f(X, Y)≺ ≺f(a, b) ❀ X≺ ≺a ∧ Y≺ ≺b successful f(X, X)≺ ≺f(a, b) ❀ X≺ ≺a ∧ Y≺ ≺b unsuccessful BACK
Rewriting calculus, Nancy March 11-12, 2004 Overview
46
On the (non-)confluence
Variables in applicative position (X •Y X)((Z Z)a)
ρ σ δ
σ δ
ρ σ δ
Z Z (X • Rigid Pattern Condition (RPC) [van Oostrom 90] P
△
= {T ∈ NF(ρσδ) | T is “linear” with no “active” variables}
BACK
Rewriting calculus, Nancy March 11-12, 2004 Overview
47
On the (non-)confluence
Rewriting calculus, Nancy March 11-12, 2004 Overview