Typed recursion in the rewriting calculus
Benjamin Wack
joint work with C. Kirchner, L. Liquori, H. Cirstea
ρWorkshop, March 10th 2004, Nancy
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
joint work with C. Kirchner, L. Liquori, H. Cirstea
ρWorkshop, March 10th 2004, Nancy
Typed recursion in the rewriting calculus Introducing types
Typed recursion in the rewriting calculus Introducing types
Typed recursion in the rewriting calculus Introducing types
Typed recursion in the rewriting calculus Introducing types
Typed recursion in the rewriting calculus Introducing types
Typed recursion in the rewriting calculus Introducing types
Typed recursion in the rewriting calculus Introducing types
Typed recursion in the rewriting calculus Introducing types
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 : ?
Typed recursion in the rewriting calculus Introducing types
Typed recursion in the rewriting calculus A typed divergent term
△
= f •X → X•(f •X)
Typed recursion in the rewriting calculus A typed divergent term
△
= f •X → X•(f •X)
Typed recursion in the rewriting calculus A typed divergent term
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
type t = F of (t -> t);; let omega x = match x with (F y) -> y (F y);;
positive in each Ai:
t) if R does not occur in t;
Typed recursion in the rewriting calculus In other typed formalisms with patterns
Typed recursion in the rewriting calculus Encodings
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
f ⊑ g f(An) ⊑ B if (B ≡ f(Bn) ) ∧ ∃i, Ai ⊑ Bi P ⊑ A if A ≡ ([Q ≪∆ A1].A2 ∧ Q ⊑ A1 ∨ P ⊑ A2)
[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
[mi = ς(Xi)ti]i∈I
△
=
(mi(Xi) → ti)i∈I
Typed recursion in the rewriting calculus Encodings
[mi = ς(Xi)ti]i∈I
△
=
(mi(Xi) → ti)i∈I
t1.t2
△
=
t1•t2(t1)
Typed recursion in the rewriting calculus Encodings
[mi = ς(Xi)ti]i∈I
△
=
(mi(Xi) → ti)i∈I
t1.t2
△
=
t1•t2(t1)
△
= a(S) → b. Then: t.a
△
= t•a(t)
ρ
→ [a(S) ≪ a(t)]b
σ
→ b
Typed recursion in the rewriting calculus Encodings
S : lab → φ ⊢ meth : (lab → φ) → lab ⊢ meth(S) : lab (Appl) ⊢ Tmeth : φ ⊢ meth(S) → Tmeth : lab → φ (Abst)
Typed recursion in the rewriting calculus Encodings
S : lab → φ ⊢ meth : (lab → φ) → lab ⊢ meth(S) : lab (Appl) ⊢ Tmeth : φ ⊢ meth(S) → Tmeth : lab → φ (Abst)
△
= 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
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
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
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
plus
△
=
S → add(0, y) → y; S → add(suc(x), y) → suc
Encodings
plus
△
=
S → add(0, y) → y; S → add(suc(x), y) → suc
→ →ρ
σ δ
[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
plus
△
=
S → add(0, y) → y; S → add(suc(x), y) → suc
→ →ρ
σ δ
[0 ≪ N].M; [0 ≪ N − 1].(M +1) · · · [0 ≪ 0].(M +N); [suc•x ≪ 0]. . . . →stk M + N
func
△
=
S → ; S → (S•S) •
Encodings
plus
△
=
S → add(0, y) → y; S → add(suc(x), y) → suc
→ →ρ
σ δ
[0 ≪ N].M; [0 ≪ N − 1].(M +1) · · · [0 ≪ 0].(M +N); [suc•x ≪ 0]. . . . →stk M + N
func
△
=
S → len([ ]) → 0 ; S → len(Cons(x, l)) → suc
Encodings
plus
△
=
S → add(0, y) → y; S → add(suc(x), y) → suc
→ →ρ
σ δ
[0 ≪ N].M; [0 ≪ N − 1].(M +1) · · · [0 ≪ 0].(M +N); [suc•x ≪ 0]. . . . →stk M + N
and ground reducible if you want completeness. func
△
=
S → len([ ]) → 0 ; S → len(Cons(x, l)) → suc
Encodings
Typed recursion in the rewriting calculus Logical considerations
Γ, ∆ ⊢ T1 : σ Γ, ∆ ⊢ T2 : τ Γ ⊢ T1 →∆ T2 : σ τ (Abs) Γ, ∆ ⊢ σ Γ, ∆ ⊢ τ Γ ⊢ σ τ (→ I)
Typed recursion in the rewriting calculus Logical considerations
Γ, ∆ ⊢ T1 : σ Γ, ∆ ⊢ T2 : τ Γ ⊢ T1 →∆ T2 : σ τ (Abs) Γ, ∆ ⊢ σ Γ, ∆ ⊢ τ Γ ⊢ σ τ (→ I)
⊢ (h⊥αα(X⊥) → X⊥) : α α ⊥ ⊢ (h⊥αα(X⊥) → X⊥)•(Y α → Y α) : ⊥
Typed recursion in the rewriting calculus Logical considerations
Γ, ∆ ⊢ T1 : σ Γ, ∆ ⊢ T2 : τ Γ ⊢ T1 →∆ T2 : σ τ (Abs) Γ, ∆ ⊢ σ Γ, ∆ ⊢ τ Γ ⊢ σ τ (→ I)
⊢ (h⊥αα(X⊥) → X⊥) : α α ⊥ ⊢ (h⊥αα(X⊥) → X⊥)•(Y α → Y α) : ⊥
Γ, Xi : ϕi ⊢ B : ψ Γ ⊢ A → B : ( ϕi) ψ (Abs) , FV (A) = {Xϕi
i }
Typed recursion in the rewriting calculus Logical considerations
Γ, ∆ ⊢ 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