Rewriting calculus: an introduction Horatiu Cirstea and Claude - - PDF document

rewriting calculus an introduction
SMART_READER_LITE
LIVE PREVIEW

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:


slide-1
SLIDE 1

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

slide-2
SLIDE 2

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

slide-3
SLIDE 3

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

slide-4
SLIDE 4

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

slide-5
SLIDE 5

The untyped rewriting calculus - ρ-calculus

slide-6
SLIDE 6

6

The Untyped Syntax P ::= T T ::= X | K | P T | T •T | [P ≪ T ]T | T ; T

  • 1. T1 T2 denotes a rule abstraction with pattern T1 and

body T2 ... the free variables of T1 are bound in T2

  • 2. [T1 ≪ T2]T3 denotes a delayed matching constraint

... the free variables of T1 are bound in T3 but not in T2

  • 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

slide-7
SLIDE 7

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

slide-8
SLIDE 8

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

slide-9
SLIDE 9

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

slide-10
SLIDE 10

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

  • Left

> [ ≪ ] Right >

  • Right

> ; Right >

Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus

slide-11
SLIDE 11

9

Matching Equations and Solutions

  • 1. A match equation is a formula of the form T1≺

≺T2.

  • 2. A matching system T

=

i=0...n Ti≺

≺T ′

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...nXi≺

≺Ti ∧

j=0...m Kj≺

≺Kj; (b) for all h, k = 0 . . . n, such that h = k, we have Xh = Xk;

  • 4. A substitution σT = {T1/X1 · · · Tn/Xn} is the solution of a

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

slide-12
SLIDE 12

10

Reduction relies on matching power

Matching is parametrized over a theory T and an order ≺ on substitutions

Sol(T1≺ ≺TT2) = σ1, . . . , σn, . . . σ ∈ Sol(T1≺ ≺TT2) ⇔ | =T σ(T1) = T2 σ1 ≺ . . . ≺ σn (n ≤ ∞)

THEORIES ALGORITHM Semantics ‘

Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus

slide-13
SLIDE 13

11

The Small-step Reduction Semantics

(P A)•B →

ρ [P ≪ B]A

[P ≪ B]A →

σ Aθ1; . . . ; Aθn; . . .

with {θ1, . . . , θn, . . .} = Sol( (A; B)•C →

δ A•C; B•C

Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus

slide-14
SLIDE 14

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

slide-15
SLIDE 15

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

slide-16
SLIDE 16

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

slide-17
SLIDE 17

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

slide-18
SLIDE 18

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

slide-19
SLIDE 19

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

slide-20
SLIDE 20

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

slide-21
SLIDE 21

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

slide-22
SLIDE 22

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

slide-23
SLIDE 23

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

slide-24
SLIDE 24

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

slide-25
SLIDE 25

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

slide-26
SLIDE 26

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

slide-27
SLIDE 27

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

slide-28
SLIDE 28

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

slide-29
SLIDE 29

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

slide-30
SLIDE 30

19

Transitivity π1 : t1 ⇒ t2 π2 : t2 ⇒ t3 π1; π2 : t1 ⇒ t3

Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus

slide-31
SLIDE 31

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

slide-32
SLIDE 32

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

slide-33
SLIDE 33

21

Why a new calculus?

Rewriting is nice, but

  • the rewrite relation or the rewriting logic are difficult to

control

  • non-reducibility is impossible to express
  • it is too close to first-order

Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus

slide-34
SLIDE 34

21

Why a new calculus?

Rewriting is nice, but

  • the rewrite relation or the rewriting logic are difficult to

control

  • non-reducibility is impossible to express
  • it is too close to first-order

Lambda-calculus is great, but

  • lacks of discrimination capabilities
  • difficult to control

Rewriting calculus, Nancy March 11-12, 2004 The untyped rewriting calculus

slide-35
SLIDE 35

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

slide-36
SLIDE 36

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

slide-37
SLIDE 37

22

A calculus with more explicit features

Like for explicit substitution calculi, explicitation of all the ingredients is useful. In “basic” rewriting calculus,

  • rules are first class object

Rewriting calculus, Nancy March 11-12, 2004 Expressiveness

slide-38
SLIDE 38

22

A calculus with more explicit features

Like for explicit substitution calculi, explicitation of all the ingredients is useful. In “basic” rewriting calculus,

  • rules are first class object
  • application is explicit

Rewriting calculus, Nancy March 11-12, 2004 Expressiveness

slide-39
SLIDE 39

22

A calculus with more explicit features

Like for explicit substitution calculi, explicitation of all the ingredients is useful. In “basic” rewriting calculus,

  • rules are first class object
  • application is explicit
  • decision of redex reduction is explicit

Rewriting calculus, Nancy March 11-12, 2004 Expressiveness

slide-40
SLIDE 40

22

A calculus with more explicit features

Like for explicit substitution calculi, explicitation of all the ingredients is useful. In “basic” rewriting calculus,

  • rules are first class object
  • application is explicit
  • decision of redex reduction is explicit
  • matching is a main explicit parameter

Rewriting calculus, Nancy March 11-12, 2004 Expressiveness

slide-41
SLIDE 41

22

A calculus with more explicit features

Like for explicit substitution calculi, explicitation of all the ingredients is useful. In “basic” rewriting calculus,

  • rules are first class object
  • application is explicit
  • decision of redex reduction is explicit
  • matching is a main explicit parameter
  • results are first class

Rewriting calculus, Nancy March 11-12, 2004 Expressiveness

slide-42
SLIDE 42

22

A calculus with more explicit features

Like for explicit substitution calculi, explicitation of all the ingredients is useful. In “basic” rewriting calculus,

  • rules are first class object
  • application is explicit
  • decision of redex reduction is explicit
  • matching is a main explicit parameter
  • results are first class

This allows for advanced calculi,

Rewriting calculus, Nancy March 11-12, 2004 Expressiveness

slide-43
SLIDE 43

22

A calculus with more explicit features

Like for explicit substitution calculi, explicitation of all the ingredients is useful. In “basic” rewriting calculus,

  • rules are first class object
  • application is explicit
  • decision of redex reduction is explicit
  • matching is a main explicit parameter
  • results are first class

This allows for advanced calculi,

  • with constraints explicit substitutions

Rewriting calculus, Nancy March 11-12, 2004 Expressiveness

slide-44
SLIDE 44

22

A calculus with more explicit features

Like for explicit substitution calculi, explicitation of all the ingredients is useful. In “basic” rewriting calculus,

  • rules are first class object
  • application is explicit
  • decision of redex reduction is explicit
  • matching is a main explicit parameter
  • results are first class

This allows for advanced calculi,

  • with constraints explicit substitutions
  • to even dissociate binding from matching when abstracting

Rewriting calculus, Nancy March 11-12, 2004 Expressiveness

slide-45
SLIDE 45

23

About the expressiveness of the rewriting calculus in T∅

  • 1. Compiling the Λ into the ρ-calculus. ϕ : Λ ⇒ ρ-calculus

(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

slide-46
SLIDE 46

23

About the expressiveness of the rewriting calculus in T∅

  • 1. Compiling the Λ into the ρ-calculus. ϕ : Λ ⇒ ρ-calculus

(a) ϕ(X) = X (b) ϕ(λX.M) = X ϕ(M) (c) ϕ(M N) = ϕ(M)•ϕ(N) Theorem: If M →β N, then ϕ(M) → →

ρ σ δ ϕ(N)

  • 2. Encoding Rewriting

(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

slide-47
SLIDE 47

24

About the expressiveness of the rewriting calculus

  • 3. Representation of Higher-order term rewriting (CRS)

(term-rewrite system + abstractor)

  • Definition of the ρ¶-calculus (HO matching theory)
  • Translation of CRS-components into RHO-terms
  • Correction and completeness of the translation

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 . . .

  • Rewriting calculus, Nancy March 11-12, 2004

Expressiveness

slide-48
SLIDE 48

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

slide-49
SLIDE 49

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

slide-50
SLIDE 50

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

slide-51
SLIDE 51

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

slide-52
SLIDE 52

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

slide-53
SLIDE 53

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

slide-54
SLIDE 54

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

slide-55
SLIDE 55

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

slide-56
SLIDE 56

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)

  • t2

.n Back to objects

Rewriting calculus, Nancy March 11-12, 2004 Examples

slide-57
SLIDE 57

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)

  • t2

.n

=

t2•n•t2 Back to objects

Rewriting calculus, Nancy March 11-12, 2004 Examples

slide-58
SLIDE 58

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)

  • t2

.n

=

t2•n•t2 → →

ρ σ δ

((addn . . .)•n; (n S′ 1)•n)•t2 Back to objects

Rewriting calculus, Nancy March 11-12, 2004 Examples

slide-59
SLIDE 59

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)

  • t2

.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

slide-60
SLIDE 60

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)

  • t2

.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

slide-61
SLIDE 61

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)

  • t2

.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

slide-62
SLIDE 62

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

slide-63
SLIDE 63

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

slide-64
SLIDE 64

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

slide-65
SLIDE 65

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

slide-66
SLIDE 66

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

slide-67
SLIDE 67

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

slide-68
SLIDE 68

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

slide-69
SLIDE 69

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

slide-70
SLIDE 70

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′)

  • bj

... back to other examples

Rewriting calculus, Nancy March 11-12, 2004 Overview

slide-71
SLIDE 71

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′)

  • bj
  • bj.set(y S 4) →

ρ σ δ (y S 4; x S 3; set

S′ Y (Y ; S′)) ... back to other examples

Rewriting calculus, Nancy March 11-12, 2004 Overview

slide-72
SLIDE 72

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

slide-73
SLIDE 73

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

slide-74
SLIDE 74

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

slide-75
SLIDE 75

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

slide-76
SLIDE 76

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

slide-77
SLIDE 77

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

slide-78
SLIDE 78

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

slide-79
SLIDE 79

46

On the (non-)confluence

Variables in applicative position (X •Y X)((Z Z)a)

ρ σ δ

  • ρ

σ δ

  • [X •Y ≪ (Z Z)a]X

ρ σ δ

  • (X •Y

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

slide-80
SLIDE 80

47

On the (non-)confluence

Rewriting calculus, Nancy March 11-12, 2004 Overview