typed recursion in the rewriting calculus
play

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


  1. Typed recursion in the rewriting calculus Benjamin Wack joint work with C. Kirchner, L. Liquori, H. Cirstea ρ Workshop, March 10th 2004, Nancy

  2. The type system Typing fixpoints Encoding typed objects and TRS Logical failure Typed recursion in the rewriting calculus Introducing types

  3. The Type System I X : σ ∈ Γ Γ ⊢ X : σ ( V ar ) Typed recursion in the rewriting calculus Introducing types

  4. The Type System I X : σ ∈ Γ Γ ⊢ X : σ ( V ar ) Γ ⊢ T 1 : σ � τ Γ ⊢ T 2 : σ ( Appl ) Γ ⊢ T 1 T 2 : τ Typed recursion in the rewriting calculus Introducing types

  5. The Type System I X : σ ∈ Γ Γ ⊢ X : σ ( V ar ) Γ ⊢ T 1 : σ � τ Γ ⊢ T 2 : σ ( Appl ) Γ ⊢ T 1 T 2 : τ Γ , ∆ ⊢ T 1 : σ Γ , ∆ ⊢ T 2 : τ ( Abs ) Γ ⊢ T 1 → ∆ T 2 : σ � τ Typed recursion in the rewriting calculus Introducing types

  6. The Type System I X : σ ∈ Γ Γ ⊢ X : σ ( V ar ) Γ ⊢ T 1 : σ � τ Γ ⊢ T 2 : σ ( Appl ) Γ ⊢ T 1 T 2 : τ Γ , ∆ ⊢ T 1 : σ Γ , ∆ ⊢ T 2 : τ ( Abs ) Γ ⊢ T 1 → ∆ T 2 : σ � τ Γ , ∆ ⊢ T 1 : σ Γ ⊢ T 2 : σ Γ , ∆ ⊢ T 3 : τ ( Match ) Γ ⊢ [ T 1 ≪ ∆ T 2 ] T 3 : τ Typed recursion in the rewriting calculus Introducing types

  7. The Type System II Γ ⊢ T 1 : σ Γ ⊢ T 2 : σ ( Struct ) Γ ⊢ T 1 ; T 2 : σ Typed recursion in the rewriting calculus Introducing types

  8. The Type System II Γ ⊢ T 1 : σ Γ ⊢ T 2 : σ ( Struct ) Γ ⊢ T 1 ; T 2 : σ Γ ⊢ T : σ α �∈ FV (Γ) Γ ⊢ T : σ α �∈ FV (Γ) ( Abs −∀ ) ( Abs −∀ ) Γ ⊢ T : ∀ α.σ Γ ⊢ α → T : ∀ α.σ Typed recursion in the rewriting calculus Introducing types

  9. The Type System II Γ ⊢ T 1 : σ Γ ⊢ T 2 : σ ( Struct ) Γ ⊢ T 1 ; T 2 : σ Γ ⊢ T : σ α �∈ FV (Γ) Γ ⊢ T : σ α �∈ FV (Γ) ( Abs −∀ ) ( Abs −∀ ) Γ ⊢ T : ∀ α.σ Γ ⊢ α → T : ∀ α.σ Γ ⊢ T : ∀ α.σ Γ ⊢ T : ∀ α.σ Γ ⊢ T : σ { τ/α } ( Appl −∀ ) Γ ⊢ T τ : σ { τ/α } ( Appl −∀ ) Typed recursion in the rewriting calculus Introducing types

  10. Typing properties Well-typed matching: If S ol ( P≺ ≺T ) = θ , then ∀ X ∈ P , Γ ⊢ X : σ ⇒ Γ ⊢ Xθ : σ . Subject Reduction: If Γ ⊢ T 1 : σ and T 1 �→ → δ T 2 , then Γ ⊢ T 2 : σ . ρ σ Uniqueness: If Γ ⊢ T : ϕ and Γ ⊢ T : ψ , then ϕ = α ψ . Decidability: � (typechecking) Γ ⊢ T : ϕ ? are decidable. (type inference) Γ ⊢ T : ? Typed recursion in the rewriting calculus Introducing types

  11. The type system Typing fixpoints Encoding typed objects and TRS Logical failure Typed recursion in the rewriting calculus A typed divergent term

  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

  13. Normalization failure (cont’d) △ f : ( α � α ) � α and Γ = X : α � α , ω = f • X → X • ( f • X ) ( b ) Γ ⊢ f : ( α � α ) � α Γ ⊢ X : α � α Γ ⊢ X : α � α Γ ⊢ f • X : α ( b ) Γ ⊢ f • X : α Γ ⊢ X • ( f • X ) : α ( a ) ⊢ ω ≡ f • X → X • ( f • X ) : α � α ( a ) ( a ) ⊢ f : ( α � α ) � α ⊢ ω : α � α ⊢ ω : α � α ⊢ f • ω : α ⊢ ω • ( f • ω ) : α Typed recursion in the rewriting calculus A typed divergent term

  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

  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 : ( x 1 : A 1 ) . . . ( x n : A n ) .R is accepted only if R is positive in each A i : 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

  16. The type system Typing fixpoints Encoding typed objects and TRS Logical failure Typed recursion in the rewriting calculus Encodings

  17. Detecting matching failures: the symbol stk 1. The relation P �⊑ A detects (some) definitive matching failures: f �⊑ g f ( A n ) ⊑ B if ( B ≡ f ( B n ) ) ∧ ∃ i, A i �⊑ B i P �⊑ A if A ≡ ([ Q ≪ ∆ A 1 ] .A 2 ∧ Q �⊑ A 1 ∨ P �⊑ A 2 ) Typed recursion in the rewriting calculus Encodings

  18. Detecting matching failures: the symbol stk 1. The relation P �⊑ A detects (some) definitive matching failures: f �⊑ g f ( A n ) ⊑ B if ( B ≡ f ( B n ) ) ∧ ∃ i, A i �⊑ B i P �⊑ A if A ≡ ([ Q ≪ ∆ A 1 ] .A 2 ∧ Q �⊑ A 1 ∨ P �⊑ A 2 ) 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

  19. Rho and objects • Object = record with an explicit account of self, i . e . △ [ m i = ς ( X i ) t i ] i ∈ I ( m i ( X i ) → t i ) i ∈ I = Typed recursion in the rewriting calculus Encodings

  20. Rho and objects • Object = record with an explicit account of self, i . e . △ [ m i = ς ( X i ) t i ] i ∈ I ( m i ( X i ) → t i ) i ∈ I = • Self-application = the application of an object to the object itself, i . e . △ t 1 .t 2 t 1 • t 2 ( t 1 ) = Typed recursion in the rewriting calculus Encodings

  21. Rho and objects • Object = record with an explicit account of self, i . e . △ [ m i = ς ( X i ) t i ] i ∈ I ( m i ( X i ) → t i ) i ∈ I = • Self-application = the application of an object to the object itself, i . e . △ t 1 .t 2 t 1 • t 2 ( t 1 ) = ρ σ △ △ • Ex: t = a ( S ) → b . Then: t.a = t • a ( t ) �→ [ a ( S ) ≪ a ( t )] b �→ b Typed recursion in the rewriting calculus Encodings

  22. Typed objects • An object has type: S : lab → φ ⊢ meth : ( lab → φ ) → lab ( Appl ) ⊢ meth ( S ) : lab ⊢ T meth : φ ( Abst ) ⊢ meth ( S ) → T meth : lab → φ Typed recursion in the rewriting calculus Encodings

  23. Typed objects • An object has type: S : lab → φ ⊢ meth : ( lab → φ ) → lab ( Appl ) ⊢ meth ( S ) : lab ⊢ T meth : φ ( Abst ) ⊢ meth ( S ) → T meth : lab → φ △ • obj.meth = obj • meth ( obj ) can be typed as follows: ⊢ meth : ( lab → φ ) → lab ⊢ obj : lab → φ ⊢ obj : lab → φ ⊢ meth ( obj ) : lab ⊢ obj • meth ( obj ) : φ Typed recursion in the rewriting calculus Encodings

  24. Encoding rewriting in the ρ -calculus 1. The following operator selects the first applicable rule of a set: △ X → (( stk → A n • X ; I ) • ( . . . • ( stk → A 2 • X ; I ) • ( A 1 X ))) first ( A 1 , A 2 , . . . , A n ) = first ( A 1 , A 2 , . . . , A n ) • B A j +1 • B if ∀ i ≤ j, A i • B �→ and A j +1 • B � �→ �→ → → δ stk → δ stk ρ σ δ ρ σ ρ σ Typed recursion in the rewriting calculus Encodings

  25. Encoding rewriting in the ρ -calculus 1. The following operator selects the first applicable rule of a set: △ X → (( stk → A n • X ; I ) • ( . . . • ( stk → A 2 • X ; I ) • ( A 1 X ))) first ( A 1 , A 2 , . . . , A n ) = first ( A 1 , A 2 , . . . , A n ) • B A j +1 • B if ∀ i ≤ j, A i • B �→ and A j +1 • B � �→ �→ → → δ stk → δ stk ρ σ δ ρ σ ρ σ 2. The Term Rewrite System R = { t i �→ s i } with signature { a j } is encoded by:   t 1 → S • ( rec • S ) • s 1 , · · · ,   ( rec • S ) → first R �  ,   a 1 • X → S • ( Rec • S ) • ( a 1 • S ( rec • S ) • X ) ,    · · · ,  t 1 → S • ( rec • S ) • s 1 ,  ( Rec • S ) → first · · · ,   I Typed recursion in the rewriting calculus Encodings

  26. Example • Addition over Peano integers: � S → add (0 , y ) → y ; � △ plus = � � S → add ( suc ( x ) , y ) → suc ( S • S ) • add ( x, y ) Typed recursion in the rewriting calculus Encodings

  27. Example • Addition over Peano integers: � S → add (0 , y ) → y ; � △ plus = � � 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

  28. Example • Addition over Peano integers: � S → add (0 , y ) → y ; � △ plus = � � 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... � S → � ; △ func = S → ( S • S ) • Typed recursion in the rewriting calculus Encodings

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend