a mechanical soundness proof for subtyping over recursive
play

A Mechanical Soundness Proof for Subtyping over Recursive Types - PowerPoint PPT Presentation

A Mechanical Soundness Proof for Subtyping over Recursive Types Timothy Jones, David Pearce Victoria University of Wellington tim@ecs.vuw.ac.nz July 19, 2016 Recursive Types Recursive Types type IntList is { int data, IntList next } | null 1


  1. A Mechanical Soundness Proof for Subtyping over Recursive Types Timothy Jones, David Pearce Victoria University of Wellington tim@ecs.vuw.ac.nz July 19, 2016

  2. Recursive Types Recursive Types type IntList is { int data, IntList next } | null 1

  3. Recursive Types Syntax T ::= Int | T × T | T ∨ T 2

  4. Recursive Types Syntax T ::= Int | T × T | T ∨ T | µ X . T | X Non-empty list of integers: µ X . Int ∨ Int × X 2

  5. Recursive Types De-Bruijn Indices T ::= Int | T × T | T ∨ T | µ T | N Non-empty list of integers: µ Int ∨ Int × 0 3

  6. Recursive Types Syntax data InductiveType (n : N ) : Set where 4

  7. Recursive Types Syntax data InductiveType (n : N ) : Set where Int : InductiveType n 4

  8. Recursive Types Syntax data InductiveType (n : N ) : Set where Int : InductiveType n _ × _ : (A B : InductiveType n) → InductiveType n _ ∨ _ : (A B : InductiveType n) → InductiveType n 4

  9. Recursive Types Syntax data InductiveType (n : N ) : Set where Int : InductiveType n _ × _ : (A B : InductiveType n) → InductiveType n _ ∨ _ : (A B : InductiveType n) → InductiveType n µ _ : (A : InductiveType (suc n)) → InductiveType n 4

  10. Recursive Types Syntax data InductiveType (n : N ) : Set where Int : InductiveType n _ × _ : (A B : InductiveType n) → InductiveType n _ ∨ _ : (A B : InductiveType n) → InductiveType n µ _ : (A : InductiveType (suc n)) → InductiveType n Var : (x : Fin n) → InductiveType n 4

  11. Recursive Types Syntax data InductiveType (n : N ) : Set where Int : InductiveType n _ × _ : (A B : InductiveType n) → InductiveType n _ ∨ _ : (A B : InductiveType n) → InductiveType n µ _ : (A : InductiveType (suc n)) → InductiveType n Var : (x : Fin n) → InductiveType n Non-empty list of integers: µ Int ∨ Int × Var zero 4

  12. Recursive Types Substitution _[_] : ∀ {n} → InductiveType (suc n) → InductiveType n → InductiveType n Int [ A ] = Int (B × C) [ A ] = B [ A ] × C [ A ] (B ∨ C) [ A ] = B [ A ] ∨ C [ A ] ( µ B) [ A ] = µ B [ inc A ] Ref x [ A ] with max? x Ref ._ [ A ] | yes max = A Ref x [ A ] | no ¬ p = Ref (reduce ¬ p) 5

  13. Recursive Types Substitution _[_] : ∀ {n} → InductiveType (suc n) → InductiveType n → InductiveType n Int [ A ] = Int (B × C) [ A ] = B [ A ] × C [ A ] (B ∨ C) [ A ] = B [ A ] ∨ C [ A ] ( µ B) [ A ] = µ B [ inc A ] Ref x [ A ] with max? x Ref ._ [ A ] | yes max = A Ref x [ A ] | no ¬ p = Ref (reduce ¬ p) unfold : Type 1 → Type 0 unfold A = A [ µ A ] 5

  14. Well Formedness Nonsensical Types Equivalent unfolding: type X is X Contractivity: type Ints is Int | Ints 6

  15. Well Formedness Nonsensical Types Equivalent unfolding: µ X . X Contractivity: type Ints is Int | Ints 6

  16. Well Formedness Nonsensical Types Equivalent unfolding: µ X . X Contractivity: µ X . Int ∨ X 6

  17. Well Formedness Nonsensical Types Equivalent unfolding: µ X . X Contractivity: µ X . Int ∨ X A type T is well-formed if every occurrence of a µ -bound variable in the body is separated from its binder by at least one × . 6

  18. Well Formedness Well Formedness data WF {n} (m : Fin (suc n)) : InductiveType n → Set where 7

  19. Well Formedness Well Formedness data WF {n} (m : Fin (suc n)) : InductiveType n → Set where int : WF m Int 7

  20. Well Formedness Well Formedness data WF {n} (m : Fin (suc n)) : InductiveType n → Set where int : WF m Int pair : ∀ {A B} → WF zero A → WF zero B → WF m (A × B) union : ∀ {A B} → WF m A → WF m B → WF m (A ∨ B) 7

  21. Well Formedness Well Formedness data WF {n} (m : Fin (suc n)) : InductiveType n → Set where int : WF m Int pair : ∀ {A B} → WF zero A → WF zero B → WF m (A × B) union : ∀ {A B} → WF m A → WF m B → WF m (A ∨ B) rec : ∀ {A} → WF (suc m) A → WF m ( µ A) 7

  22. Well Formedness Well Formedness data WF {n} (m : Fin (suc n)) : InductiveType n → Set where int : WF m Int pair : ∀ {A B} → WF zero A → WF zero B → WF m (A × B) union : ∀ {A B} → WF m A → WF m B → WF m (A ∨ B) rec : ∀ {A} → WF (suc m) A → WF m ( µ A) ref : ∀ {x} → m ≤ inject 1 x → WF m (Var x) 7

  23. Well Formedness Corresponding Proofs wf_[_] : ∀ {n m A} {B : InductiveType n} → WF (inject 1 m) A → WF m B → WF m (A [ B ]) wf int [ p ] = int wf pair q r [ p ] = pair (wf q [ weaken! p ]) (wf r [ weaken! p ]) wf union q r [ p ] = union (wf q [ p ]) (wf r [ p ]) wf rec q [ p ] = rec (wf q [ wf-inc p ]) wf ref {x} q [ p ] with max? x wf ref q [ p ] | yes max = p wf ref q [ p ] | no ¬ p = wf-reduce q ¬ p 8

  24. Well Formedness Corresponding Proofs wf_[_] : ∀ {n m A} {B : InductiveType n} → WF (inject 1 m) A → WF m B → WF m (A [ B ]) wf int [ p ] = int wf pair q r [ p ] = pair (wf q [ weaken! p ]) (wf r [ weaken! p ]) wf union q r [ p ] = union (wf q [ p ]) (wf r [ p ]) wf rec q [ p ] = rec (wf q [ wf-inc p ]) wf ref {x} q [ p ] with max? x wf ref q [ p ] | yes max = p wf ref q [ p ] | no ¬ p = wf-reduce q ¬ p wf-unfold : ∀ {n m} {A : Type (suc n)} → WF (suc m) A → WF m (A [ µ A ]) wf-unfold p = wf weaken 1 p [ rec p ] 8

  25. Coinduction Coinductive Representation data CoinductiveType : Set where Int : CoinductiveType _ × _ : (A B : ∞ CoinductiveType) → CoinductiveType _ ∨ _ : (A B : CoinductiveType) → CoinductiveType 9

  26. Coinduction Coinductive Representation data CoinductiveType : Set where Int : CoinductiveType _ × _ : (A B : ∞ CoinductiveType) → CoinductiveType _ ∨ _ : (A B : CoinductiveType) → CoinductiveType type : ∞ CoinductiveType → CoinductiveType 9

  27. Coinduction Infinite Unfolding Linking the two representations ∞ unfold : {A : InductiveType 0} → WF zero A → CoinductiveType 10

  28. Coinduction Infinite Unfolding ∞ unfold : {A : InductiveType 0} → WF zero A → CoinductiveType ∞ unfold int = Int ∞ unfold (pair p q) = ∞ unfold p × ∞ unfold q ∞ unfold (union p q) = ∞ unfold p ∨ ∞ unfold q ∞ unfold (rec p) = ∞ unfold (wf-unfold p) ∞ unfold (ref p) = ⊥ -elim (<-bound p) 11

  29. Coinduction Infinite Unfolding ∞ unfold : {A : InductiveType 0} → WF zero A → CoinductiveType ∞ unfold int = Int ∞ unfold (pair p q) = ∞ unfold p × ∞ unfold q ∞ unfold (union p q) = ∞ unfold p ∨ ∞ unfold q ∞ unfold (rec p) = ∞ unfold (wf-unfold p) ∞ unfold (ref p) = ⊥ -elim (<-bound p) 11

  30. Coinduction Infinite Unfolding ∞ unfold : {A : InductiveType 0} → WF zero A → CoinductiveType delay-unfold : {A : InductiveType 0} → WF zero A → ∞ CoinductiveType ∞ unfold int = Int ∞ unfold (pair p q) = ∞ unfold p × ∞ unfold q ∞ unfold (union p q) = ∞ unfold p ∨ ∞ unfold q ∞ unfold (rec p) = ∞ unfold (wf-unfold p) ∞ unfold (ref p) = ⊥ -elim (<-bound p) 11

  31. Coinduction Infinite Unfolding ∞ unfold : {A : InductiveType 0} → WF zero A → CoinductiveType delay-unfold : {A : InductiveType 0} → WF zero A → ∞ CoinductiveType ∞ unfold int = Int ∞ unfold (pair p q) = ∞ unfold p × ∞ unfold q ∞ unfold (union p q) = ∞ unfold p ∨ ∞ unfold q ∞ unfold (rec p) = ∞ unfold (wf-unfold p) ∞ unfold (ref p) = ⊥ -elim (<-bound p) type (delay-unfold p) = ∞ unfold p 11

  32. Coinduction Infinite Unfolding ∞ unfold : {A : InductiveType 0} → WF zero A → CoinductiveType delay-unfold : {A : InductiveType 0} → WF zero A → ∞ CoinductiveType ∞ unfold int = Int ∞ unfold (pair p q) = delay-unfold p × delay-unfold q ∞ unfold (union p q) = ∞ unfold p ∨ ∞ unfold q ∞ unfold (rec p) = ∞ unfold (wf-unfold p) ∞ unfold (ref p) = ⊥ -elim (<-bound p) type (delay-unfold p) = ∞ unfold p 11

  33. Coinduction Infinite Unfolding ∞ unfold : {A : InductiveType 0} → WF zero A → CoinductiveType delay-unfold : {A : InductiveType 0} → WF zero A → ∞ CoinductiveType ∞ unfold int = Int ∞ unfold (pair p q) = delay-unfold p × delay-unfold q ∞ unfold (union p q) = ∞ unfold p ∨ ∞ unfold q ∞ unfold (rec p) = ∞ unfold (wf-unfold p) ∞ unfold (ref p) = ⊥ -elim (<-bound p) type (delay-unfold p) = ∞ unfold p 11

  34. Coinduction Substitution Delay Substitutions must be held until they can be delayed 12

  35. Coinduction Substitution Delay Substitutions must be held until they can be delayed data Substs : (n : N ) → Fin (suc n) → Set where [] : ∀ {n} → Substs n zero _::_ : ∀ {n m} {A : InductiveType n} → WF m A → Substs n m → Substs (suc n) (suc m) 12

  36. Coinduction Infinite Unfolding ∞ unfold ′ : ∀ {n B} → WF (from N n) B → Substs n (from N n) → CoinductiveType 13

  37. Coinduction Infinite Unfolding ∞ unfold ′ : ∀ {n B} → WF (from N n) B → Substs n (from N n) → CoinductiveType apply-substs : ∀ {n} {B : InductiveType n} → WF zero B → Substs n (from N n) → ∞ CoinductiveType 13

  38. Coinduction Infinite Unfolding ∞ unfold ′ : ∀ {n B} → WF (from N n) B → Substs n (from N n) → CoinductiveType apply-substs : ∀ {n} {B : InductiveType n} → WF zero B → Substs n (from N n) → ∞ CoinductiveType ∞ unfold ′ int v = Int ∞ unfold ′ (pair p q) v = apply-substs p v × apply-substs q v ∞ unfold ′ (union p q) v = ∞ unfold ′ p v ∨ ∞ unfold ′ q v ∞ unfold ′ (rec p) v = ∞ unfold ′ p (rec p :: v) ∞ unfold ′ (ref p) v = ⊥ -elim (<-bound p) 13

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