Typed recursion in the rewriting calculus Benjamin Wack joint work - - PowerPoint PPT Presentation

typed recursion in the rewriting calculus
SMART_READER_LITE
LIVE PREVIEW

Typed recursion in the rewriting calculus Benjamin Wack joint work - - PowerPoint PPT Presentation

Typed recursion in the rewriting calculus Benjamin Wack joint work with C. Kirchner, L. Liquori, H. Cirstea Workshop, March 10th 2004, Nancy The type system Typing fixpoints Encoding typed objects and TRS Logical failure Typed recursion in


slide-1
SLIDE 1

Typed recursion in the rewriting calculus

Benjamin Wack

joint work with C. Kirchner, L. Liquori, H. Cirstea

ρWorkshop, March 10th 2004, Nancy

slide-2
SLIDE 2

The type system Typing fixpoints Encoding typed objects and TRS Logical failure

Typed recursion in the rewriting calculus Introducing types

slide-3
SLIDE 3

The Type System I X : σ ∈ Γ Γ ⊢ X : σ (V ar)

Typed recursion in the rewriting calculus Introducing types

slide-4
SLIDE 4

The Type System I X : σ ∈ Γ Γ ⊢ X : σ (V ar) Γ ⊢ T1 : σ τ Γ ⊢ T2 : σ Γ ⊢ T1 T2 : τ (Appl)

Typed recursion in the rewriting calculus Introducing types

slide-5
SLIDE 5

The Type System I X : σ ∈ Γ Γ ⊢ X : σ (V ar) Γ ⊢ T1 : σ τ Γ ⊢ T2 : σ Γ ⊢ T1 T2 : τ (Appl) Γ, ∆ ⊢ T1 : σ Γ, ∆ ⊢ T2 : τ Γ ⊢ T1 →∆ T2 : σ τ (Abs)

Typed recursion in the rewriting calculus Introducing types

slide-6
SLIDE 6

The Type System I X : σ ∈ Γ Γ ⊢ X : σ (V ar) Γ ⊢ T1 : σ τ Γ ⊢ T2 : σ Γ ⊢ T1 T2 : τ (Appl) Γ, ∆ ⊢ T1 : σ Γ, ∆ ⊢ T2 : τ Γ ⊢ T1 →∆ T2 : σ τ (Abs) Γ, ∆ ⊢ T1 : σ Γ ⊢ T2 : σ Γ, ∆ ⊢ T3 : τ Γ ⊢ [T1≪∆T2]T3 : τ (Match)

Typed recursion in the rewriting calculus Introducing types

slide-7
SLIDE 7

The Type System II Γ ⊢ T1 : σ Γ ⊢ T2 : σ Γ ⊢ T1; T2 : σ (Struct)

Typed recursion in the rewriting calculus Introducing types

slide-8
SLIDE 8

The Type System II Γ ⊢ T1 : σ Γ ⊢ T2 : σ Γ ⊢ T1; T2 : σ (Struct) Γ ⊢ T : σ α ∈ FV (Γ) Γ ⊢ T : ∀α.σ (Abs−∀) Γ ⊢ T : σ α ∈ FV (Γ) Γ ⊢ α → T : ∀α.σ (Abs−∀)

Typed recursion in the rewriting calculus Introducing types

slide-9
SLIDE 9

The Type System II Γ ⊢ T1 : σ Γ ⊢ T2 : σ Γ ⊢ T1; T2 : σ (Struct) Γ ⊢ T : σ α ∈ FV (Γ) Γ ⊢ T : ∀α.σ (Abs−∀) Γ ⊢ T : σ α ∈ FV (Γ) Γ ⊢ α → T : ∀α.σ (Abs−∀) Γ ⊢ T : ∀α.σ Γ ⊢ T : σ{τ/α} (Appl−∀) Γ ⊢ T : ∀α.σ Γ ⊢ T τ : σ{τ/α} (Appl−∀)

Typed recursion in the rewriting calculus Introducing types

slide-10
SLIDE 10

Typing properties

Well-typed matching: If Sol(P≺ ≺T ) = θ, then ∀X ∈ P, Γ ⊢ X : σ ⇒ Γ ⊢ Xθ : σ. Subject Reduction: If Γ ⊢ T1 : σ and T1 → →

ρ σ δ T2, then Γ ⊢ T2 : σ.

Uniqueness: If Γ ⊢ T : ϕ and Γ ⊢ T : ψ, then ϕ =α ψ. Decidability: (typechecking) Γ ⊢ T : ϕ ? (type inference) Γ ⊢ T : ?

  • are decidable.

Typed recursion in the rewriting calculus Introducing types

slide-11
SLIDE 11

The type system Typing fixpoints Encoding typed objects and TRS Logical failure

Typed recursion in the rewriting calculus A typed divergent term

slide-12
SLIDE 12

Normalization failure f : (αα)α and Γ = X : αα, ω

= f •X → X•(f •X)

ω•(f •ω) ≡ (f •X → X•(f •X))•(f •ω) →ρ [f •X ≪ f •ω].(X•(f •X)) →σ ω•(f •ω) →ρ . . .

Typed recursion in the rewriting calculus A typed divergent term

slide-13
SLIDE 13

Normalization failure (cont’d) f : (αα)α and Γ = X : αα, ω

= f •X → X•(f •X)

Γ ⊢ f : (αα)α Γ ⊢ X : αα (b) Γ ⊢ f •X : α Γ ⊢ X : αα (b) Γ ⊢ f •X : α Γ ⊢ X•(f •X) : α (a) ⊢ ω ≡ f •X → X•(f •X) : αα (a) ⊢ ω : αα ⊢ f : (αα)α (a) ⊢ ω : αα ⊢ f •ω : α ⊢ ω•(f •ω) : α

Typed recursion in the rewriting calculus A typed divergent term

slide-14
SLIDE 14

Inductive types with “positive” occurrences

  • In CaML, try to type:

type t = F of (t -> t);; let omega x = match x with (F y) -> y (F y);;

Typed recursion in the rewriting calculus In other typed formalisms with patterns

slide-15
SLIDE 15

Inductive types with “positive” occurrences

  • In CaML, try to type:

type t = F of (t -> t);; let omega x = match x with (F y) -> y (F y);;

  • In CIC, the constructor F : (x1 : A1) . . . (xn : An).R is accepted only if R is

positive in each Ai:

  • 1. R is positive in T if R does not occur in T;
  • 2. R is positive in (R

t) if R does not occur in t;

  • 3. R is positive in (x : A)C if R does not occur in A and R is positive in C.

Typed recursion in the rewriting calculus In other typed formalisms with patterns

slide-16
SLIDE 16

The type system Typing fixpoints Encoding typed objects and TRS Logical failure

Typed recursion in the rewriting calculus Encodings

slide-17
SLIDE 17

Detecting matching failures: the symbol stk

  • 1. The relation P ⊑ A detects (some) definitive matching failures:

f ⊑ g f(An) ⊑ B if (B ≡ f(Bn) ) ∧ ∃i, Ai ⊑ Bi P ⊑ A if A ≡ ([Q ≪∆ A1].A2 ∧ Q ⊑ A1 ∨ P ⊑ A2)

Typed recursion in the rewriting calculus Encodings

slide-18
SLIDE 18

Detecting matching failures: the symbol stk

  • 1. The relation P ⊑ A detects (some) definitive matching failures:

f ⊑ g f(An) ⊑ B if (B ≡ f(Bn) ) ∧ ∃i, Ai ⊑ Bi P ⊑ A if A ≡ ([Q ≪∆ A1].A2 ∧ Q ⊑ A1 ∨ P ⊑ A2)

  • 2. The relation →stk treats matching failures uniformly:

[P ≪∆ A].B →stk stk if P ⊑ A stk; A →stk A A; stk →stk A stk•A →stk stk

Typed recursion in the rewriting calculus Encodings

slide-19
SLIDE 19

Rho and objects

  • Object = record with an explicit account of self, i.e.

[mi = ς(Xi)ti]i∈I

=

(mi(Xi) → ti)i∈I

Typed recursion in the rewriting calculus Encodings

slide-20
SLIDE 20

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

Typed recursion in the rewriting calculus Encodings

slide-21
SLIDE 21

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

ρ

→ [a(S) ≪ a(t)]b

σ

→ b

Typed recursion in the rewriting calculus Encodings

slide-22
SLIDE 22

Typed objects

  • An object has type:

S : lab → φ ⊢ meth : (lab → φ) → lab ⊢ meth(S) : lab (Appl) ⊢ Tmeth : φ ⊢ meth(S) → Tmeth : lab → φ (Abst)

Typed recursion in the rewriting calculus Encodings

slide-23
SLIDE 23

Typed objects

  • An object has type:

S : lab → φ ⊢ meth : (lab → φ) → lab ⊢ meth(S) : lab (Appl) ⊢ Tmeth : φ ⊢ meth(S) → Tmeth : lab → φ (Abst)

  • obj.meth

= obj•meth(obj) can be typed as follows:

⊢ obj : lab → φ ⊢ meth : (lab → φ) → lab ⊢ obj : lab → φ ⊢ meth(obj) : lab ⊢ obj•meth(obj) : φ

Typed recursion in the rewriting calculus Encodings

slide-24
SLIDE 24

Encoding rewriting in the ρ-calculus

  • 1. The following operator selects the first applicable rule of a set:

first(A1, A2, . . . , An)

= X → ((stk → An•X; I)• (. . . •(stk → A2•X; I)•(A1X))) first(A1, A2, . . . , An)•B → →

ρ σ δ

Aj+1•B if ∀i ≤ j, Ai•B → →

ρ σ δ stk

and Aj+1•B → →

ρ σ δ stk Typed recursion in the rewriting calculus Encodings

slide-25
SLIDE 25

Encoding rewriting in the ρ-calculus

  • 1. The following operator selects the first applicable rule of a set:

first(A1, A2, . . . , An)

= X → ((stk → An•X; I)• (. . . •(stk → A2•X; I)•(A1X))) first(A1, A2, . . . , An)•B → →

ρ σ δ

Aj+1•B if ∀i ≤ j, Ai•B → →

ρ σ δ stk

and Aj+1•B → →

ρ σ δ stk

  • 2. The Term Rewrite System R = {ti → si} with signature {aj} is encoded by:

R (rec•S) → first      t1 → S•(rec•S)•s1, · · · , a1•X → S•(Rec•S)•(a1•S(rec•S)•X), · · · ,      , (Rec•S) → first   t1 → S•(rec•S)•s1, · · · , I  

Typed recursion in the rewriting calculus Encodings

slide-26
SLIDE 26

Example

  • Addition over Peano integers:

plus

=

S → add(0, y) → y; S → add(suc(x), y) → suc

  • (S•S)•add(x, y)
  • Typed recursion in the rewriting calculus

Encodings

slide-27
SLIDE 27

Example

  • Addition over Peano integers:

plus

=

S → add(0, y) → y; S → add(suc(x), y) → suc

  • (S•S)•add(x, y)
  • (plus • plus) • add(N, M)

→ →ρ

σ δ

[0 ≪ N].M; [0 ≪ N − 1].(M +1) · · · [0 ≪ 0].(M +N); [suc•x ≪ 0]. . . . →stk M + N

Typed recursion in the rewriting calculus Encodings

slide-28
SLIDE 28

Example

  • Addition over Peano integers:

plus

=

S → add(0, y) → y; S → add(suc(x), y) → suc

  • (S•S)•add(x, y)
  • (plus • plus) • add(N, M)

→ →ρ

σ δ

[0 ≪ N].M; [0 ≪ N − 1].(M +1) · · · [0 ≪ 0].(M +N); [suc•x ≪ 0]. . . . →stk M + N

  • Fill in the blanks with your favorite rewrite system...

func

=

S → ; S → (S•S) •

  • Typed recursion in the rewriting calculus

Encodings

slide-29
SLIDE 29

Example

  • Addition over Peano integers:

plus

=

S → add(0, y) → y; S → add(suc(x), y) → suc

  • (S•S)•add(x, y)
  • (plus • plus) • add(N, M)

→ →ρ

σ δ

[0 ≪ N].M; [0 ≪ N − 1].(M +1) · · · [0 ≪ 0].(M +N); [suc•x ≪ 0]. . . . →stk M + N

  • Fill in the blanks with your favorite rewrite system...

func

=

S → len([ ]) → 0 ; S → len(Cons(x, l)) → suc

  • (S•S) • len(l)
  • Typed recursion in the rewriting calculus

Encodings

slide-30
SLIDE 30

Example

  • Addition over Peano integers:

plus

=

S → add(0, y) → y; S → add(suc(x), y) → suc

  • (S•S)•add(x, y)
  • (plus • plus) • add(N, M)

→ →ρ

σ δ

[0 ≪ N].M; [0 ≪ N − 1].(M +1) · · · [0 ≪ 0].(M +N); [suc•x ≪ 0]. . . . →stk M + N

  • Fill in the blanks with your favorite rewrite system... provided it is convergent

and ground reducible if you want completeness. func

=

S → len([ ]) → 0 ; S → len(Cons(x, l)) → suc

  • (S•S) • len(l)
  • Typed recursion in the rewriting calculus

Encodings

slide-31
SLIDE 31

The type system Typing fixpoints Encoding typed objects and TRS Logical failure

Typed recursion in the rewriting calculus Logical considerations

slide-32
SLIDE 32

Logical inconsistency

  • As is, the Curry-Howard isomorphism is not valid:

Γ, ∆ ⊢ T1 : σ Γ, ∆ ⊢ T2 : τ Γ ⊢ T1 →∆ T2 : σ τ (Abs) Γ, ∆ ⊢ σ Γ, ∆ ⊢ τ Γ ⊢ σ τ (→ I)

Typed recursion in the rewriting calculus Logical considerations

slide-33
SLIDE 33

Logical inconsistency

  • As is, the Curry-Howard isomorphism is not valid:

Γ, ∆ ⊢ T1 : σ Γ, ∆ ⊢ T2 : τ Γ ⊢ T1 →∆ T2 : σ τ (Abs) Γ, ∆ ⊢ σ Γ, ∆ ⊢ τ Γ ⊢ σ τ (→ I)

  • Thus, for instance,

⊢ (h⊥αα(X⊥) → X⊥) : α α ⊥ ⊢ (h⊥αα(X⊥) → X⊥)•(Y α → Y α) : ⊥

Typed recursion in the rewriting calculus Logical considerations

slide-34
SLIDE 34

Logical inconsistency

  • As is, the Curry-Howard isomorphism is not valid:

Γ, ∆ ⊢ T1 : σ Γ, ∆ ⊢ T2 : τ Γ ⊢ T1 →∆ T2 : σ τ (Abs) Γ, ∆ ⊢ σ Γ, ∆ ⊢ τ Γ ⊢ σ τ (→ I)

  • Thus, for instance,

⊢ (h⊥αα(X⊥) → X⊥) : α α ⊥ ⊢ (h⊥αα(X⊥) → X⊥)•(Y α → Y α) : ⊥

  • How to fix it ?

Γ, Xi : ϕi ⊢ B : ψ Γ ⊢ A → B : ( ϕi) ψ (Abs) , FV (A) = {Xϕi

i }

Typed recursion in the rewriting calculus Logical considerations

slide-35
SLIDE 35

Dependent type discipline

Γ, ∆ ⊢ T1 : σ Γ, ∆ ⊢ T2 : τ Γ ⊢ T1 : ∆ → T2 : στ (Abs) Γ ⊢ T1 : στ Γ ⊢ T2 : σ Γ ⊢ T1 T2 : τ (Appl) Γ, ∆ ⊢ T2 : τ Γ ⊢ (T1 : ∆) → T2 : (T1 : ∆)τ (Abs) Γ ⊢ T1 : (T11 : ∆)τ Γ ⊢ T2 : σ Γ, ∆ ⊢ T11 : σ Γ ⊢ T1 T2 : [T11≪∆T2].τ (Appl)

Typed recursion in the rewriting calculus Logical considerations