programming in homotopy type theory
play

Programming in Homotopy Type Theory Dan Licata Institute for - PowerPoint PPT Presentation

Programming in Homotopy Type Theory Dan Licata Institute for Advanced Study Joint work with Robert Harper 1 Dependent Type Theory 2 Dependent Type Theory Basis of proof assistants (Agda, Coq, NuPRL) Formalization of math Certified


  1. Computation? Standard computation rule for subst is: subst C refl P ≡ P Therefore subst Monoid (univalence (f, f -1 , α , β )) is well-typed but stuck: violates progress Solution: subst C α P computes in a type-directed way, guided by the family C 26

  2. subst for x.A(x) → B(x) Want subst x:A0.A(x) → B(x) α F : A[N] B[N] → A[M] → B[M] F 27

  3. subst for x.A(x) → B(x) x:A0 ⊢ A(x) → B(x) type Id A0 (M,N) Want subst x:A0.A(x) → B(x) α F : A[N] B[N] → A[M] → B[M] F 27

  4. subst for x.A(x) → B(x) x:A0 ⊢ A(x) → B(x) type Id A0 (M,N) Want subst x:A0.A(x) → B(x) α F : A[N] B[N] → subst A α -1 A[M] → B[M] F 27

  5. subst for x.A(x) → B(x) x:A0 ⊢ A(x) → B(x) type Id A0 (M,N) Want subst x:A0.A(x) → B(x) α F : A[N] B[N] → subst B α subst A α -1 A[M] → B[M] F 27

  6. subst for x.A(x) → B(x) x:A0 ⊢ A(x) → B(x) type Id A0 (M,N) Want subst x:A0.A(x) → B(x) α F : A[N] B[N] → subst B α subst A α -1 A[M] → B[M] F subst x.A(x) → B(x) α F ≡ subst x.B(x) α . F . subst x.A(x) α -1 27

  7. subst for X:type.X Want subst X:type.X α : A → B Have α : Id type (A, B) 28

  8. subst for X:type.X Want subst X:type.X α : A → B Have α : Id type (A, B) the only paths in the universe are constructed by univalence 28

  9. subst for X:type.X Want subst X:type.X α : A → B Have α : Id type (A, B) the only paths in the universe are constructed by univalence subst X.X α ≡ f when α ≡ univalence(f:A → B,g, α , β ) 28

  10. subst for X:type.X Want subst X:type.X α : A → B Have α : Id type (A, B) the only paths in the universe are constructed by univalence subst X.X α ≡ f when α ≡ univalence(f:A → B,g, α , β ) β -reduction for univalence: deploy the isomorphism 28

  11. Monoid : type → type Monoid X = Σ ⊙ :X → X → X. Σ u:X. … f : A → B Given (f,f -1 , α , β ) : Iso(A, B) f -1 : B → A ( ⊙ ,u,…) : Monoid(A) and α : Id A → A (f -1 o f, id) ( ⊙ ’,u’,…) : Monoid(B) make β : Id B → B (f o f -1 , id) Define: ⊙ ’ = λ y 1 ,y 2 :B . f ((f -1 y 1 ) ⊙ (f -1 y 2 )) “the hard way” u’ = f u (y ⊙ ’ u’) ≃ f ((f -1 y) ⊙ (f -1 (f u))) ≃ f (f -1 y ⊙ u) by α ≃ f (f -1 y) by unit law for ⊙ and u ≃ y by β 29

  12. α : Id A B = Easy ⟼ Hard univalence (f,f -1 ,…) Monoid(A) : Monoid(B) “the easy way” “the hard way” 30

  13. α : Id A B = Easy ⟼ Hard univalence (f,f -1 ,…) Monoid(A) subst X:type.Monoid(X) α ( ⊙ ,u,…) : Monoid(B) “the easy way” ≡ ( λ y 1 ,y 2 . f ( (f -1 y 1 ) ⊙ (f -1 y 2 ) ) “the hard way” f u, …) 30

  14. α : Id A B = Easy ⟼ Hard univalence (f,f -1 ,…) Monoid(A) subst X:type.Monoid(X) α ( ⊙ ,u,…) : Monoid(B) “the easy way” ≡ subst X:type. Σ ⊙ :X → X → X. Σ u:X…. α ( ⊙ ,u,…) ≡ ( λ y 1 ,y 2 . f ( (f -1 y 1 ) ⊙ (f -1 y 2 ) ) “the hard way” f u, …) 30

  15. α : Id A B = Easy ⟼ Hard univalence (f,f -1 ,…) Monoid(A) subst X:type.Monoid(X) α ( ⊙ ,u,…) : Monoid(B) “the easy way” ≡ subst X:type. Σ ⊙ :X → X → X. Σ u:X…. α ( ⊙ ,u,…) ≡ (subst X.X → X → X α ⊙ , subst X.X α u, …) ≡ ( λ y 1 ,y 2 . f ( (f -1 y 1 ) ⊙ (f -1 y 2 ) ) “the hard way” f u, …) 30

  16. α : Id A B = Easy ⟼ Hard univalence (f,f -1 ,…) Monoid(A) subst X:type.Monoid(X) α ( ⊙ ,u,…) : Monoid(B) “the easy way” ≡ subst X:type. Σ ⊙ :X → X → X. Σ u:X…. α ( ⊙ ,u,…) ≡ (subst X.X → X → X α ⊙ , subst X.X α u, …) ≡ ( λ y 1 ,y 2 . subst X.X α ( (subst X.X α -1 y 1 ) ⊙ (subst X.X α -1 y 2 ) ) subst X.X α u, …) ≡ ( λ y 1 ,y 2 . f ( (f -1 y 1 ) ⊙ (f -1 y 2 ) ) “the hard way” f u, …) 30

  17. Programming Cat. theory & homotopy theory useful for type theory Work “up to isomorphism” 1.code reuse 2.specs for abstract types Functorial abstract syntax [LH, MFPS 2011] There is a generic program hidden inside of dependent type theory 31

  18. Specs for Abstract Types signature SEQ = sig type α seq val map : ( α → β ) → ( α seq → β seq) val reduce : … end 32

  19. Specs for Abstract Types signature SEQ = sig type α seq val map : ( α → β ) → ( α seq → β seq) val reduce : … end structure PSeq :> SEQ = <parallel sequences> 32

  20. Specs for Abstract Types signature SEQ = sig type α seq val map : ( α → β ) → ( α seq → β seq) val reduce : … end structure PSeq :> SEQ = <parallel sequences> Behavioral spec: PSeq.map f <x 1 , …, x n > = <f x 1 , …, f x n > Operationally: evaluated in parallel 32

  21. Specs for Abstract Types key abstraction for 1 st &2 nd -year FP/parallel algorithms classes signature SEQ = at CMU sig type α seq val map : ( α → β ) → ( α seq → β seq) val reduce : … end structure PSeq :> SEQ = <parallel sequences> Behavioral spec: PSeq.map f <x 1 , …, x n > = <f x 1 , …, f x n > Operationally: evaluated in parallel 32

  22. Specs for Abstract Types Behavioral: PSeq.map f <x 1 , …, x n > = <f x 1 , …, f x n > How to make this precise? 33

  23. Specs for Abstract Types Behavioral: PSeq.map f <x 1 , …, x n > = <f x 1 , …, f x n > How to make this precise? structure ListSeq : SEQ = struct type α seq = α list val map = List.map … end 33

  24. Specs for Abstract Types Behavioral: PSeq.map f <x 1 , …, x n > = <f x 1 , …, f x n > How to make this precise? structure ListSeq : SEQ = struct type α seq = α list val map = List.map … end Spec: “PSeq behaves like ListSeq” 33

  25. “PSeq behaves like ListSeq” 34

  26. “PSeq behaves like ListSeq” spec : Id SEQ ListSeq PSeq 34

  27. “PSeq behaves like ListSeq” spec : Id SEQ ListSeq PSeq i subst i ListSeq.map ListSeq.map PSeq.map i α ListSeq.seq α PSeq.seq type 34

  28. “PSeq behaves like ListSeq” spec : Id SEQ ListSeq PSeq spec implies 35

  29. “PSeq behaves like ListSeq” spec : Id SEQ ListSeq PSeq spec implies i : Iso( α ListSeq.seq, α PSeq.seq) = (fromList : α ListSeq.seq → α PSeq.seq, toList : α PSeq.seq → α ListSeq.seq, …) 35

  30. “PSeq behaves like ListSeq” spec : Id SEQ ListSeq PSeq spec implies i : Iso( α ListSeq.seq, α PSeq.seq) = (fromList : α ListSeq.seq → α PSeq.seq, toList : α PSeq.seq → α ListSeq.seq, …) PSeq.map ≃ subst (s:type → type. ( α→β ) → α s → β s) i ListSeq.map ≃ λ f. fromList . List.map f . toList 35

  31. “PSeq behaves like ListSeq” spec : Id SEQ ListSeq PSeq spec implies i : Iso( α ListSeq.seq, α PSeq.seq) = (fromList : α ListSeq.seq → α PSeq.seq, toList : α PSeq.seq → α ListSeq.seq, …) PSeq.map ≃ subst (s:type → type. ( α→β ) → α s → β s) i ListSeq.map ≃ λ f. fromList . List.map f . toList and so on for reduce, … easier than writing out by hand 35

  32. Can use this to reason about PSeq: PSeq.map (g . f) ≃ PSeq.map g . PSeq.map f 36

  33. Can use this to reason about PSeq: PSeq.map (g . f) ≃ PSeq.map g . PSeq.map f PSeq.map (g . f) 36

  34. Can use this to reason about PSeq: PSeq.map (g . f) ≃ PSeq.map g . PSeq.map f PSeq.map (g . f) ≃ fromList . List.map (g.f) . toList 36

  35. Can use this to reason about PSeq: PSeq.map (g . f) ≃ PSeq.map g . PSeq.map f PSeq.map (g . f) ≃ fromList . List.map (g.f) . toList ≃ fromList . List.map g . List.map f . toList 36

  36. Can use this to reason about PSeq: PSeq.map (g . f) ≃ PSeq.map g . PSeq.map f PSeq.map (g . f) ≃ fromList . List.map (g.f) . toList ≃ fromList . List.map g . List.map f . toList PSeq.map g . PSeq.map f 36

  37. Can use this to reason about PSeq: PSeq.map (g . f) ≃ PSeq.map g . PSeq.map f PSeq.map (g . f) ≃ fromList . List.map (g.f) . toList ≃ fromList . List.map g . List.map f . toList PSeq.map g . PSeq.map f ≃ (fromList . List.map g . toList) . (fromList . List.map f . toList) 36

  38. Can use this to reason about PSeq: PSeq.map (g . f) ≃ PSeq.map g . PSeq.map f PSeq.map (g . f) ≃ fromList . List.map (g.f) . toList ≃ fromList . List.map g . List.map f . toList PSeq.map g . PSeq.map f ≃ (fromList . List.map g . toList) . (fromList . List.map f . toList) ≃ fromList . List.map g . (toList . fromList) . List.map f . toList 36

  39. Can use this to reason about PSeq: PSeq.map (g . f) ≃ PSeq.map g . PSeq.map f PSeq.map (g . f) ≃ fromList . List.map (g.f) . toList ≃ fromList . List.map g . List.map f . toList PSeq.map g . PSeq.map f ≃ (fromList . List.map g . toList) . (fromList . List.map f . toList) ≃ fromList . List.map g . (toList . fromList) . List.map f . toList ≃ fromList . List.map g . List.map f . toList 36

  40. Programming Cat. theory & homotopy theory useful for type theory Work “up to isomorphism” 1.code reuse 2.specs for abstract types Functorial abstract syntax [LH, MFPS 2011] There is a generic program hidden inside of dependent type theory 37

  41. Status LH, POPL’12: computational interpretation for simplest generalization (2-dimensional -- no paths between paths); non-algorithmic (up to ≡ ) Conjectured algorithm for 2D: have an operational semantics; metatheory in progress Generalization to higher dimensions is a hard open problem 38

  42. More Details on Operational Semantics 39

  43. Type A * B Members: (M, N) where M : A and N : B Paths: α : Id A (M,N) β : Id B (M’, N’) pair ≃ α β : Id A*B (M,N)(M’,N’) Refl (M,N) ≡ pair ≃ Refl M Refl N (pair ≃ α β ) -1 ≡ (pair ≃ α -1 β -1 ) (pair ≃ α β ) o (pair ≃ α ’ β ’) ≡ (pair ≃ α o α ’ β o β ’) 40

  44. Type type Members: <names for small sets>, which determine types Paths: (f,g, α , β ) : Iso A B ua(f,g, α , β ) : Id type ( A, B) Refl A ≡ (x:A.x,x:A.x,x.Refl x ,x.Refl x ) (ua(f,g, α , β )) -1 ≡ … (ua(f’,g’, α ’, β ’)) o (ua(f’,g’, α ’, β ’)) ≡ … 41

  45. Computational interpretation 1.Define each type by members and paths, with refl -1 o satisfying groupoid laws 2.Define subst C α M for each C 3.Define resp F α for each F 4.Define full Id-elim rule J using subst (1,2,3 simultaneous) 42

  46. Subst C : A → type α : Id A (M,N) P : C [M] subst C α P : C[N] To be a family of types over A, C must have an associated operation subst C Functionality (à la NuPRL) becomes functoriality 43

  47. Case for x.A(x) * B(x) Id( θ 1, θ 2) Want subst x.A(x) x B(x) α : A[ θ 1] * B[ θ 1] A[ θ 2] * B[ θ 2] → Have: 44

  48. Case for x.A(x) * B(x) Id( θ 1, θ 2) Want subst x.A(x) x B(x) α : A[ θ 1] * B[ θ 1] A[ θ 2] * B[ θ 2] → Have: subst A α : A[ θ 1] → A[ θ 2] 44

  49. Case for x.A(x) * B(x) Id( θ 1, θ 2) Want subst x.A(x) x B(x) α : A[ θ 1] * B[ θ 1] A[ θ 2] * B[ θ 2] → Have: subst A α : A[ θ 1] → A[ θ 2] subst B α : B[ θ 1] → B[ θ 2] 44

  50. Case for x.A(x) * B(x) Id( θ 1, θ 2) Want subst x.A(x) x B(x) α : A[ θ 1] * B[ θ 1] A[ θ 2] * B[ θ 2] → Have: subst A α : A[ θ 1] → A[ θ 2] subst B α : B[ θ 1] → B[ θ 2] subst x.A(x) x B(x) α (M1,M2) ≡ (subst x.A(x) α M1, subst X:U.B(x) α M2) 44

  51. Case for x.A(x) → B(x) Id( θ 1, θ 2) Want subst x.A(x) → B(x) α F : A[ θ 2] B[ θ 2] → A[ θ 1] → B[ θ 1] F subst x.A(X) → B(X) α F ≡ ( λ x.subst xB(X) α (F (subst X:U.A(X) α -1 x)) 45

  52. Case for x.A(x) → B(x) Id( θ 1, θ 2) Want subst x.A(x) → B(x) α F : A[ θ 2] B[ θ 2] → subst A α -1 A[ θ 1] → B[ θ 1] F subst x.A(X) → B(X) α F ≡ ( λ x.subst xB(X) α (F (subst X:U.A(X) α -1 x)) 45

  53. Case for x.A(x) → B(x) Id( θ 1, θ 2) Want subst x.A(x) → B(x) α F : A[ θ 2] B[ θ 2] → subst B α subst A α -1 A[ θ 1] → B[ θ 1] F subst x.A(X) → B(X) α F ≡ ( λ x.subst xB(X) α (F (subst X:U.A(X) α -1 x)) 45

Recommend


More recommend