naturality for free
play

Naturality for Free The category interpretation of directed type - PowerPoint PPT Presentation

Naturality for Free The category interpretation of directed type theory Thorsten Altenkirch, Filippo Sestini Functional Programming Laboratory School of Computer Science University of Nottingham Homotopy Type Theory 2019 Thorsten Altenkirch,


  1. Naturality for Free The category interpretation of directed type theory Thorsten Altenkirch, Filippo Sestini Functional Programming Laboratory School of Computer Science University of Nottingham Homotopy Type Theory 2019 Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 1 / 29

  2. Types are abstract This has powerful consequences: Parametricity Polymorphic functions preserve all logical relations. Univalence Isomorphic types are equal. How are these related? Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 2 / 29

  3. List reversal is natural List : Set → Set � rev : List A → List A A :Set f : A → B rev A List A List A List f List f List B List B rev B List f ◦ rev A = rev B ◦ List f Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 3 / 29

  4. Proof by induction List f [ a 0 , a 1 , . . . , a n − 1 ] = [ f a 0 , f a 1 , . . . , f a n − 1 ] rev A [ a 0 , a 1 , . . . , a n − 1 ] = [ a n − 1 , . . . , a 1 , a 0 ] (rev B ◦ List f ) [ a 0 , a 1 , . . . , a n − 1 ] = rev B (List f [ a 0 , a 1 , . . . , a n − 1 ]) = rev B [ f a 0 , f a 1 , . . . , f a n − 1 ]) = [ f a n − 1 , . . . , f a 1 , f a 0 ]) = List f [ a n − 1 , . . . , a 1 , a 0 ] = List f (rev A [ a 0 , a 1 , . . . , a n − 1 ]) = (List f ◦ rev A ) [ a 0 , a 1 , . . . , a n − 1 ] Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 4 / 29

  5. Everything is natural . . . F , G : Set → Set � α : F A → G A A :Set f : A → B α A F A G A F f G f F B G B α B Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 5 / 29

  6. . . . but we can’t prove it. Naturality (parametricity) is a metatheorem, but we cannot prove it internally Solution: extend MLTT with constructs to internalise free theorems (Nuyts et al., Bernardy et al., ...) Can we link this to Univalence/HoTT? Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 6 / 29

  7. The hint (HoTT) F , G : Set → Set � α : F A ≃ G A A :Set f : A ≃ B α A F A G A F f G f F B G B α B A ≃ B means isomorphism (we work in a set-level setting); This is provable in HoTT, from Univalence + J. Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 7 / 29

  8. Set-level univalent type theory can be interpreted into the groupoid model (Hofmann & Streicher). The model validates a univalent universe of sets; Idea: replace groupoids with categories; This gives a semantics for a directed type theory with ◮ an internal Hom type; ◮ directed Univalence ; Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 8 / 29

  9. The category with families of categories Contexts Con : Set Γ : Con [[Γ]] : Cat Types Ty : Con → Set A : Ty Γ [[ A ]] : [[Γ]] → Cat [[ a ]] : Sect � Terms Tm : (Γ : Con) → Ty Γ → Set a : Tm Γ A [[ A ]] Substitutions Tms : Con → Con → Set γ : Tms Γ ∆ [[ γ ]] : [[Γ]] → [[∆]] Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 9 / 29

  10. Operations on contexts A : Ty Γ • : Con Γ . A : Con [[ • ]] := 1 | [[Γ . A ]] | := ( γ : | [[Γ]] | ) × | [[ A ]] γ | [[Γ . A ]](( γ, a ) , ( γ ′ , a ′ )) := ( f : [[Γ]]( γ, γ ′ )) × ([[ A ]] γ ′ )([[ A ]] f a , a ′ ) Grothendieck construction Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 10 / 29

  11. Opposites A : Ty Γ Γ : Con Γ − : Con A − : Ty Γ [[Γ − ]] := [[Γ]] op [[ A − ]] := op ◦ [[ A ]] → Cat takes C into C op . where op : Cat − Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 11 / 29

  12. Opposites A : Ty Γ Γ : Con Γ − : Con A − : Ty Γ [[Γ − ]] := [[Γ]] op [[ A − ]] := op ◦ [[ A ]] → Cat takes C into C op . where op : Cat − But what is (Γ . A ) − ? Γ − . A − doesn’t typecheck. Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 11 / 29

  13. Contravariant context extension A : Ty Γ − Γ . − A : Con | [[Γ . − A ]] | := ( γ : | [[Γ]] | ) × | [[ A ]] γ | [[Γ . − A ]](( γ, a ) , ( γ ′ , a ′ )) := ( f : [[Γ]]( γ, γ ′ )) × ([[ A ]] γ )( a , [[ A ]] f a ′ ) (Γ . A ) − = Γ − . − A − Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 12 / 29

  14. Σ-types A : Ty Γ B : Ty Γ . A Σ A B : Ty Γ On objects: [[Σ A B ]] γ := ([[ A ]] γ ) . ([[ B ]] γ ) Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 13 / 29

  15. Σ-types A : Ty Γ B : Ty Γ . A Σ A B : Ty Γ On objects: [[Σ A B ]] γ := ([[ A ]] γ ) . ([[ B ]] γ ) What about (Σ A B ) − ? Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 13 / 29

  16. Σ − -types B : Ty (Γ . A − ) A : Ty Γ Σ − A B : Ty Γ On objects: [[Σ − A B ]] γ := ([[ A ]] γ ) . − ([[ B ]] γ ) (Σ A B ) − = Σ − A − B − Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 14 / 29

  17. Σ-types with polarities M : Tm s Γ A N : Tm s Γ B [ M ] B : Ty (Γ . A s ) A : Ty Γ � M , N � s : Tm s Γ (Σ s A B ) Σ s A B : Ty Γ M : Tm s Γ (Σ s A B ) M : Tm s Γ (Σ s A B ) 1 M : Tm s Γ A 2 M : Tm s Γ ( B [ π s π s π s 1 M ]) where s = { + , −} and Tm − Γ A ≡ Tm Γ − A − . Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 15 / 29

  18. Π-types Groupoid construction of Π generalises to categories... ... but we need to be careful with polarities. A : Ty Γ − B : Ty (Γ . − A ) Π A B : Ty Γ Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 16 / 29

  19. Π-types with polarities B : Ty (Γ . − A s ) A : Ty Γ − Π s A B : Ty Γ t : Tm s Γ (Π s A B ) t : Tm s (Γ . − s A ) B λ s t : Tm s Γ (Π s A B ) app s t : Tm s (Γ . − s A ) B (Π s A B ) − = Π − s A − B − Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 17 / 29

  20. Universe of sets A : Tm Γ U s El A : Ty Γ s U : Ty Γ closed under Π , Σ , ... . | [[U]] γ | := Set ([[U]] γ )( A , B ) := A → B | [[El a ]] γ | := [[ a ]] γ ([[El a ]] γ )( y , z ) := ( y = z ) (El A ) − = El A Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 18 / 29

  21. The Hom type a : Tm Γ A − b : Tm Γ A Hom A a b : Ty Γ we also write a ⊑ A b for Hom A a b . On objects: [[Hom A a b ]] γ := A γ ( a γ, b γ ) Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 19 / 29

  22. The Hom type a : Tm Γ A − b : Tm Γ A Hom A a b : Ty Γ we also write a ⊑ A b for Hom A a b . On objects: [[Hom A a b ]] γ := A γ ( a γ, b γ ) But what about id (aka refl)? We would like to say a : Tm Γ A id a : Hom A a a Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 19 / 29

  23. The Hom type a : Tm Γ A − b : Tm Γ A Hom A a b : Ty Γ we also write a ⊑ A b for Hom A a b . On objects: [[Hom A a b ]] γ := A γ ( a γ, b γ ) But what about id (aka refl)? We would like to say a : Tm Γ A id a : Hom A a a but this doesn’t type check! Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 19 / 29

  24. Core types A : Ty Γ a : Tm Γ ¯ A a s : Tm Γ A s A : Ty Γ [[ A ]] := core ◦ [[ A ]] a , b : Tm Γ ¯ A f : Tm Γ ( a − ⊑ A b + ) g : Tm Γ ( b − ⊑ A a + ) l : Tm Γ ( f ◦ g ⊑ id b ) r : Tm Γ ( g ◦ f ⊑ id a ) f , g , l , r : Tm Γ Hom A a b Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 20 / 29

  25. Some issues with cores Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 21 / 29

  26. Some issues with cores Introduction rule? A �− → A a : Tm Γ A a : Tm Γ A Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 21 / 29

  27. Some issues with cores Introduction rule? A �− → A a : Tm Γ A a : Tm Γ A Rules for core contexts? Γ . A ≃ Γ . A [ ... ] Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 21 / 29

  28. Some issues with cores Introduction rule? A �− → A a : Tm Γ A a : Tm Γ A Rules for core contexts? Γ . A ≃ Γ . A [ ... ] A ∼ = A Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 21 / 29

  29. Identity morphisms a : Tm Γ A id a : Hom A a − a + Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 22 / 29

  30. Morphism induction (J s ) a : Tm Γ A b : Tm Γ A M : Ty Γ , x : A , z : Hom A s a − s x m : Tm Γ M [ x := a + , z := id a ] p : Tm Γ Hom A s a − s b J s M m p : M [ x := b , z := p ] Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 23 / 29

  31. Morphism induction II (J) a : Tm Γ A b : Tm Γ A M : Ty (Γ , x : A , z : Hom A a − x + ) m : Tm Γ M [ x := a , z := id a ] p : Tm Γ (Hom A a − b + ) J M m p : M [ x := b , z := p ] Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 24 / 29

  32. Directed Univalence A : Tm Γ U − B : Tm Γ U Hom U A B = El ( A → B ) Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 25 / 29

  33. Directed Univalence A : Tm Γ U − B : Tm Γ U Hom U A B = El ( A → B ) “Undirected” Univalence follows from the directed one. Hom U A B = f : A − → B + , g : B − → A + , +proofs Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 25 / 29

  34. Every type family is functorial X : U ⊢ F : U For any A , B : U , f : A − → B + We can construct ap F f : F [ A ] − → F [ B ] + from directed UA + J Thorsten Altenkirch, Filippo Sestini Naturality for Free HoTT 2019 26 / 29

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