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
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
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
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
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
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
subst for X:type.X Want subst X:type.X α : A → B Have α : Id type (A, B) 28
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
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
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
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
α : Id A B = Easy ⟼ Hard univalence (f,f -1 ,…) Monoid(A) : Monoid(B) “the easy way” “the hard way” 30
α : 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
α : 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
α : 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
α : 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
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
Specs for Abstract Types signature SEQ = sig type α seq val map : ( α → β ) → ( α seq → β seq) val reduce : … end 32
Specs for Abstract Types signature SEQ = sig type α seq val map : ( α → β ) → ( α seq → β seq) val reduce : … end structure PSeq :> SEQ = <parallel sequences> 32
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
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
Specs for Abstract Types Behavioral: PSeq.map f <x 1 , …, x n > = <f x 1 , …, f x n > How to make this precise? 33
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
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
“PSeq behaves like ListSeq” 34
“PSeq behaves like ListSeq” spec : Id SEQ ListSeq PSeq 34
“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
“PSeq behaves like ListSeq” spec : Id SEQ ListSeq PSeq spec implies 35
“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
“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
“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
Can use this to reason about PSeq: PSeq.map (g . f) ≃ PSeq.map g . PSeq.map f 36
Can use this to reason about PSeq: PSeq.map (g . f) ≃ PSeq.map g . PSeq.map f PSeq.map (g . f) 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 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 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
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
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
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
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
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
More Details on Operational Semantics 39
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
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
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
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
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
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
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
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
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
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
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