Experience implementing a performant category-theory library in Coq
Jason Gross, Adam Chlipala, David I. Spivak Massachusetts Institute of Technology
performant category-theory library in Coq Jason Gross, Adam - - PowerPoint PPT Presentation
Experience implementing a performant category-theory library in Coq Jason Gross, Adam Chlipala, David I. Spivak Massachusetts Institute of Technology How should theorem provers work? 2 How theorem provers should work: 1 = 0 1 = 0 No;
Jason Gross, Adam Chlipala, David I. Spivak Massachusetts Institute of Technology
2
3
Coq, is this correct?
No; here’s a proof of 1 = 0 → False
4
Coq, is this correct?
Yes; here’s a proof …
Th Theo eorem rem (curr rryi ying ng) ) : 𝑫𝟐 → 𝑫𝟑 → 𝑬 ≅ (𝑫𝟐 × 𝑫𝟑 → 𝑬) Proof: : homewo ework k ∎
5
Theorem currying : 𝐷1 → 𝐷2 → 𝐸 ≅ 𝐷1 × 𝐷2 → 𝐸 . Proof. trivial. Qed.
Th Theo eorem rem (curr rryi ying ng) ) : 𝑫𝟐 → 𝑫𝟑 → 𝑬 ≅ (𝑫𝟐 × 𝑫𝟑 → 𝑬) Proof: : homewo ework k ∎
6
Theorem currying : 𝐷1 → 𝐷2 → 𝐸 ≅ 𝐷1 × 𝐷2 → 𝐸 . Proof. esplit. { by refine (𝜇F (𝐺 ↦ (𝜇F (𝑑 ↦ 𝐺
{ by refine (𝜇F (𝐺 ↦ (𝜇F (𝑑1 ↦ (𝜇F (𝑑2 ↦ 𝐺
all: trivial. Qed.
Th Theo eorem rem (curr rryi ying ng) ) : 𝑫𝟐 → 𝑫𝟑 → 𝑬 ≅ (𝑫𝟐 × 𝑫𝟑 → 𝑬) Proof: →: : 𝑮 ↦ 𝝁 𝒅𝟐, 𝒅𝟑 . 𝑮 𝒅𝟐 𝒅𝟑 ; morph phisms isms simila larly ly ←: : 𝑮 ↦ 𝝁 𝒅𝟐. 𝝁 𝒅𝟑. 𝑮(𝒅𝟐, 𝒅𝟑); morphis hisms ms simila larly ly Functoriality
, naturality rality, , and congrue uence: nce: straig ightfo htforward.
7
Theorem currying : 𝐷1 → 𝐷2 → 𝐸 ≅ 𝐷1 × 𝐷2 → 𝐸 . Proof. esplit. { by refine (𝜇F (𝐺 ↦ (𝜇F (𝑑 ↦ 𝐺
m 𝑛1 o 𝑡2))
(𝐺 𝐻 𝑈 ↦ (𝜇T (𝑑 ↦ 𝑈 𝑑1 𝑑2)))). } { by refine (𝜇F (𝐺 ↦ (𝜇F (𝑑1 ↦ (𝜇F (𝑑2 ↦ 𝐺
m (1, 𝑛))))
(𝐺 𝐻 𝑈 ↦ (𝜇T (𝑑1 ↦ (𝜇T (𝑑2 ↦ 𝑈 (𝑑1, 𝑑2)))))). } all: trivial. Qed.
Th Theo eorem rem (curr rryi ying ng) ) : 𝑫𝟐 → 𝑫𝟑 → 𝑬 ≅ (𝑫𝟐 × 𝑫𝟑 → 𝑬) Proof: →: : 𝑮 ↦ 𝝁 𝒅𝟐, 𝒅𝟑 . 𝑮 𝒅𝟐 𝒅𝟑 ; morph phisms isms simila larly ly ←: : 𝑮 ↦ 𝝁 𝒅𝟐. 𝝁 𝒅𝟑. 𝑮(𝒅𝟐, 𝒅𝟑); morphis hisms ms simila larly ly Functoriality
, naturality rality, , and congrue uence: nce: straig ightfo htforward.
8
Theorem currying : 𝐷1 → 𝐷2 → 𝐸 ≅ 𝐷1 × 𝐷2 → 𝐸 . Proof. esplit. { by refine (𝜇F (𝐺 ↦ (𝜇F (𝑑 ↦ 𝐺
m 𝑛1 o 𝑡2))
(𝐺 𝐻 𝑈 ↦ (𝜇T (𝑑 ↦ 𝑈 𝑑1 𝑑2)))). } { by refine (𝜇F (𝐺 ↦ (𝜇F (𝑑1 ↦ (𝜇F (𝑑2 ↦ 𝐺
m (1, 𝑛))))
(𝐺 𝐻 𝑈 ↦ (𝜇T (𝑑1 ↦ (𝜇T (𝑑2 ↦ 𝑈 (𝑑1, 𝑑2)))))). } all: trivial. Qed.
Th Theo eorem rem (curr rryi ying ng) ) : 𝑫𝟐 → 𝑫𝟑 → 𝑬 ≅ (𝑫𝟐 × 𝑫𝟑 → 𝑬) Proof: →: : 𝑮 ↦ 𝝁 𝒅𝟐, 𝒅𝟑 . 𝑮 𝒅𝟐 𝒅𝟑 ; morph phisms isms simila larly ly ←: : 𝑮 ↦ 𝝁 𝒅𝟐. 𝝁 𝒅𝟑. 𝑮(𝒅𝟐, 𝒅𝟑); morphis hisms ms simila larly ly Functoriality
, naturality rality, , and congrue uence: nce: straig ightfo htforward.
≈ 0 s 17 s 2m 46 s !!! (5 s, if we use UIP)
If we’re not careful, obvious or trivial things can be very, very slow.
9
10
Theorem : You should listen to me. Proof. by experience. Qed.
Category theory in Coq: https://github.com/HoTT/HoTT (subdirectory theories/categories):
11
Concepts Formalized:
adjunction 𝐺 ⊣ 𝐻 for functors 𝐺: 𝐷 ⇆ 𝐸: 𝐻 and 𝐹 a precategory (still too slow to be merged into the library proper; code here)
applied to Grothendieck construction
12
13
Cartoon from xkcd, adapted by Alan Huang
14
Cartoon from xkcd, adapted by Alan Huang15
Cartoon from xkcd, adapted by Alan Huang16
Cartoon from xkcd, adapted by Alan Huangassist with performance
17
18
19
Dam image from http://www.flickr.com/photos/gammaman/7803829282/ by Eli Christman, CC by 2.0 Fence image from http://www.picgifs.com/clip-art/playing-children/clip-art-playing-children-362018-689955/ Universes image from Abell NGC2218 hst big, NASA, http://en.wikipedia.org/wiki/Abell_2218#mediaviewer/File:A bell_NGC2218_hst_big.jpg, released in Public Domain; Bubble from http://pixabay.com/en/blue-bubble-shiny- 157652/, released in Public Domain CC0, combined in Photoshop by Jason Gross
provers or proof scripts, slow?
20
provers or proof scripts, slow?
21
provers or proof scripts, slow?
22 Snail from http://naolito.deviantart.com/art/Repetitive-task-258126598
provers or proof scripts, slow?
23 Running rooster from http://d.wapday.com:8080/animation/ccontennt/15545-f/mr_rooster_running.gif
provers or proof scripts, slow?
using a quicker one
24
25
about
26
27
28
29
0.01 s 0.1 s 1 s 10 s 100 s 1.0E+0 1.0E+1 1.0E+2 1.0E+3 1.0E+4 1.0E+5 1.0E+6 1.0E+7 1.0E+8
Durations of Various Tactics vs. Term Size (Coq v8.4, 2.4 GHz Intel Xeon CPU, 16 GB RAM)
match goal with |- ?G => set (y := G) end (v8.4) destruct x (v8.4) assert (z := true); destruct z (v8.4) lazymatch goal with |- ?f ?a = ?g ?b => let H := constr:(@f_equal bool bool f a b (@eq_refl bool a)) in apply H end (v8.4) lazymatch goal with |- ?f ?a = ?g ?b => let H := constr:(@f_equal bool bool f a b (@eq_refl bool a)) in exact H end (v8.4) assert (z := true); revert z (v8.4) generalize x (v8.4) apply f_equal (v8.4) lazymatch goal with |- ?f ?a = ?g ?b => let H := constr:(@f_equal bool bool f a b (@eq_refl bool a)) in exact_no_check H end (v8.4) assert (z := true); generalize z (v8.4) lazymatch goal with |- ?f ?a = ?g ?b => let H := constr:(@f_equal bool bool f a b (@eq_refl bool a)) in idtac end (v8.4) set (y := x) (v8.4) set (y := bool) (v8.4) lazymatch goal with |- ?f ?a = ?g ?b => let H := constr:(@f_equal bool bool f a b) in idtac end (v8.4) lazymatch goal with |- ?f ?a = ?g ?b => idtac end (v8.4)
Do terms actually get this large?
31
Do terms actually get this large?
32
33
34
type of 2-arrows
35
vertices:
36
{| LCCMF ≔ _\_inducedF 𝑛22 ∘ 𝑛12 ; LCCMT ≔ 𝜇𝑈 (𝜇 𝑑 ∶ 𝑒2
′ / 𝐺 ⇒ 𝑛21 𝑑. 𝛾 ∘ 𝑛11 𝑑. 𝛾) |} =
{| LCCMF ≔ _\_inducedF 𝑛12 ∘ _\_inducedF 𝑛22; LCCMT ≔ 𝜇𝑈 (𝜇 𝑑 ∶ 𝑒2
′ / 𝐺 ⇒ 𝑛21 𝑑. 𝛾 ∘ 𝑒1 1 𝕁 ∘ 𝑛11 𝑑. 𝛾 ∘ 𝕁) |}
{| LCCMF ≔ _\_inducedF 𝑛22 ∘ 𝑛12 ; LCCMT ≔ 𝜇𝑈 𝜇 𝑑 ∶ 𝑒2
′ / 𝐺 ⇒ 𝑛21 𝑑. 𝛾 ∘ 𝑛11 𝑑. 𝛾
(Π−pf 𝑡2 (𝜇𝑈 𝜇 𝑑 ∶ 𝐷 ⇒ 𝑛21 𝑑 ∘ 𝑛11 𝑑 (∘1 −pf 𝑛21 𝑛11)) (𝑛22 ∘ 𝑛12)) |} = {| LCCMF ≔ _\_inducedF 𝑛12 ∘ _\_inducedF 𝑛22; LCCMT ≔ 𝜇𝑈 (𝜇 𝑑 ∶ 𝑒2
′ / 𝐺 ⇒ 𝑛21 𝑑. 𝛾 ∘ 𝑒1 1 𝕁 ∘ 𝑛11 𝑑. 𝛾 ∘ 𝕁)
(∘1 −pf (𝜇𝑈 𝜇 𝑑 ∶ 𝑒2
′ / 𝐺 ⇒ 𝑛21 𝑑. 𝛾 (Π−pf 𝑒
(𝜇𝑈 𝜇 𝑑 ∶ 𝑒2
′ / 𝐺 ⇒ 𝑒1 1 𝕁 ∘ 𝑛11 𝑑. 𝛾 ∘ 𝕁
(∘1 −pf (𝜇𝑈 𝜇 𝑑 ∶ 𝑒2
′ / 𝐺 ⇒ 𝑒1
(∘0 −pf (𝜇𝑈 𝜇 𝑑 ∶ 𝑒2 / 𝐺 ⇒ 𝑛 (Π−pf 𝑡2 𝑛11 𝑛12)
37
{| LCCMF ≔ _\_inducedF 𝑛22 ∘ 𝑛12 ; LCCMT ≔ 𝜇𝑈 𝜇 𝑑 ∶ 𝑒2
′ / 𝐺 ⇒ 𝑛21 𝑑. 𝛾 ∘ 𝑛11 𝑑. 𝛾
(Π−pf 𝑡2 (𝜇𝑈 𝜇 𝑑 ∶ 𝐷 ⇒ 𝑛21 𝑑 ∘ 𝑛11 𝑑 (∘1 −pf 𝑛21 𝑛11)) (𝑛22 ∘ 𝑛12)) |} = {| LCCMF ≔ _\_inducedF 𝑛12 ∘ _\_inducedF 𝑛22; LCCMT ≔ 𝜇𝑈 (𝜇 𝑑 ∶ 𝑒2
′ / 𝐺 ⇒ 𝑛21 𝑑. 𝛾 ∘ 𝑒1 1 𝕁 ∘ 𝑛11 𝑑. 𝛾 ∘ 𝕁)
(∘1 −pf (𝜇𝑈 𝜇 𝑑 ∶ 𝑒2
′ / 𝐺 ⇒ 𝑛21 𝑑. 𝛾 (Π−pf 𝑒2 𝑛21 𝑛22)))
(𝜇𝑈 𝜇 𝑑 ∶ 𝑒2
′ / 𝐺 ⇒ 𝑒1 1 𝕁 ∘ 𝑛11 𝑑. 𝛾 ∘ 𝕁
(∘1 −pf (𝜇𝑈 𝜇 𝑑 ∶ 𝑒2
′ / 𝐺 ⇒ 𝑒1 1 𝕁 ∘ 𝑛11 𝑑. 𝛾
(∘0 −pf (𝜇𝑈 𝜇 𝑑 ∶ 𝑒2 / 𝐺 ⇒ 𝑛11 𝑑. 𝛾 (Π−pf 𝑡2 𝑛11 𝑛12)) 𝕁)) 𝕁))) |}
38
39
40 Fence from http://imgarcade.com/1/hiding-clipart/
41
42
43
44
Dam image from http://www.flickr.com/photos/gammaman/7803829282/ by Eli Christman, CC by 2.0 Fence image from http://www.picgifs.com/clip-art/playing-children/clip-art-playing-children-362018-689955/
45
A mapping of graphs is a mapping of vetices to vertices and arrows to arrows
46
mapping
At least two options to define graph: Record Graph := { V : Type ; E : V → V → Type }. Record IsGraph (V : Type) (E : V → V → Type) := { }.
47
Record Graph := { V : Type ; E : V → V → Type }. Record IsGraph (𝑊: Type) (𝐹: 𝑊→ 𝑊→ Type) := { }. Big difference for size of functor: Mapping : Graph → Graph → Type. vs. IsMapping : ∀ (𝑊
𝐻 : Type) (𝑊 𝐼 : Type)
(𝐹𝐻 : 𝑊
𝐻 → 𝑊 𝐻 → Type) (𝐹𝐼 : 𝑊 𝐼 → 𝑊 𝐼 → Type),
IsGraph 𝑊
𝐻 𝐹𝐻 → IsGraph 𝑊 𝐼 𝐹𝐼 → Type.
48
49
50
51
52
between them in each direction
53
between them in each direction
to every other vertex
54
between them in each direction
to every other vertex
from every other vertex
55
Theorem initial_unique : ∀ (𝐻 : Graph) (𝑦 𝑧 : 𝐻.V), is_initial 𝑦 → is_initial 𝑧 → 𝑦 ≅ 𝑧
Exercise for the audience
56
Theorem terminal_unique : ∀ (𝐻 : Graph) (𝑦 𝑧 : 𝐻.V), is_terminal 𝑦 → is_terminal 𝑧 → 𝑦 ≅ 𝑧
𝜇 𝐻 𝑦 𝑧 𝐼 𝐼′ ⇒ initial_unique 𝐻op 𝑧 𝑦 𝐼′𝐼
57
constructions
know can't hurt me”
58
59
Leaky abstraction barriers generally only torture programmers
60
Dam image from http://www.flickr.com/photos/gammaman/7803829282/ by Eli Christman, CC by 2.0
Leaky abstraction barriers torture Coq, too!
61
Dam image from http://www.flickr.com/photos/gammaman/7803829282/ by Eli Christman, CC by 2.0
Example: Pairing Two ways to make use of elements of a pair: let (𝑦, 𝑧) := 𝑞 in 𝑔 𝑦 𝑧. (pattern matching) 𝑔 (fst 𝑞) (snd 𝑞). (projections)
62
Example: Pairing Two ways to make use of elements of a pair: let (𝑦, 𝑧) := 𝑞 in 𝑔 𝑦 𝑧. (pattern matching) 𝑔 (let (𝑦, 𝑧) := 𝑞 in 𝑦) (let (𝑦, 𝑧) := 𝑞 in 𝑧). (projections)
63
These ways do not unify!
Leaky abstraction barriers torture Coq, too!
65
Rooster Image from http://www.animationlibrary.com/animation/18342/Chicken_blows_up/ Dam image from http://www.flickr.com/photos/gammaman/7803829282/ by Eli Christman, CC by 2.0Leaky abstraction barriers torture Coq, too!
66
Dam image from ID-L-0010, WaterArchives.org, CC by SA 2.0
67
Local Notation mor_of 𝑍
0 𝑍 1 𝑔:=
(let 𝜃𝑍
1:= IsInitialMorphism_morphism (@HM 𝑍
1) in
(@center _ (IsInitialMorphism_property (@HM 𝑍
0) _ (𝜃𝑍
1 ∘ f))) 1 ) (only parsing).
Lemma composition_of 𝑦 𝑧 𝑨 𝑔: mor_of _ _ (𝑔 ∘ ) = mor_of 𝑧 𝑨 𝑔 ∘ mor_of 𝑦 𝑧 . Proof. simpl. match goal with | [ ⊢ ((@center ?𝐵?𝐼) 2) 1= _ ] ⇒ erewrite (@contr 𝐵 𝐼 (center _; (_; _))) end. simpl; reflexivity. Grab Existential Variables. simpl in ∗. repeat match goal with | [ ⊢ appcontext[(?𝑦 2) 1 ] ] ⇒ generalize (𝑦 2); intro end. rewrite ?composition_of. repeat try_associativity_quick (idtac; match goal with | [ ⊢ appcontext[?𝑦 1] ] ⇒ simpl rewrite 𝑦 2 end). rewrite ?left_identity, ?right_identity, ?associativity. reflexivity. Qed.
Concrete Example (Old Version)
3.5 s 2 s 2.5 s 0.5 s 8 s 0.3 s 20 s
Size of goal (after first simpl): 7312 words Size of proof term: 66 264 words Total time in file: 39 s
69
Local Notation mor_of 𝑍
0 𝑍 1 𝑔:=
(let 𝜃𝑍
1:= IsInitialMorphism_morphism (@HM 𝑍
1) in
IsInitialMorphism_property_morphism (@HM 𝑍
0) _ (𝜃𝑍
1 ∘ 𝑔)) (only parsing).
Lemma composition_of 𝑦 𝑧 𝑨 𝑔: mor_of _ _ (𝑔 ∘ ) = mor_of 𝑧 𝑨 𝑔 ∘ mor_of 𝑦 𝑧 . Proof. simpl. erewrite IsInitialMorphism_property_morphism_unique; [ reflexivity | ]. rewrite ?composition_of. repeat try_associativity_quick rewrite IsInitialMorphism_property_morphism_property. reflexivity. Qed.
Concrete Example (New Version)
0.08 s
(was 10 s)
0.08 s
(was 0.5 s)
0.5 s
(was 3.5 s)
0.5 s
(was 3.5 s)
Size of goal (after first simpl): 191 words (was 7312) Size of proof term: 3 632 words (was 66 264) Total time in file: 3 s (was 39 s)
70
Definition IsInitialMorphism_object (𝑁 : IsInitialMorphism 𝐵𝜒) : 𝐸 := CommaCategory.b 𝐵𝜒. Definition IsInitialMorphism_morphism (𝑁 : IsInitialMorphism 𝐵𝜒) : morphism 𝐷 𝑌 (𝑉 0 (IsInitialMorphism_object 𝑁)) := CommaCategory.f 𝐵𝜒. Definition IsInitialMorphism_property (𝑁 : IsInitialMorphism 𝐵𝜒) (𝑍 : 𝐸) (𝑔 : morphism 𝐷 𝑌 (𝑉 0 𝑍)) : Contr { 𝑛 : morphism 𝐸 (IsInitialMorphism_object 𝑁) 𝑍 | 𝑉 1 𝑛 ∘ (IsInitialMorphism_morphism 𝑁) = 𝑔 }. Proof. (∗∗ We could just [rewrite right_identity], but we want to preserve judgemental computation rules. ∗) pose proof (@trunc_equiv′ _ _ (symmetry _ _ (@CommaCategory.issig_morphism _ _ _ !𝑌 𝑉 _ _)) -2 (𝑁 (CommaCategory.Build_object !𝑌 𝑉 tt 𝑍 𝑔))) as 𝐼′. simpl in 𝐼′. apply contr_inhabited_hprop.
apply @trunc_succ in 𝐼′; eapply @trunc_equiv′; [ | exact 𝐼′ ]; match goal with | [ ⊢ appcontext[?𝑛 ∘ 𝕁] ] ⇒ simpl rewrite (right_identity _ _ _ 𝑛) | [ ⊢ appcontext[𝕁 ∘ ?𝑛] ] ⇒ simpl rewrite (left_identity _ _ _ 𝑛) end; simpl; unfold IsInitialMorphism_object, IsInitialMorphism_morphism; let 𝐵 := match goal with ⊢ Equiv ?𝐵 ?𝐶 ⇒ constr:(𝐵) end in let 𝐶 := match goal with ⊢ Equiv ?𝐵 ?𝐶 ⇒ constr:(𝐶) end in apply (equiv_adjointify (𝜇 𝑦 : 𝐵 ⇒ 𝑦 2) (𝜇 𝑦 : 𝐶 ⇒ (tt; 𝑦))); [ intro; reflexivity | intros [[]]; reflexivity ] ).
abstract (etransitivity; [ apply ((@center _ 𝐼′) 2) 2 | auto with morphism ]). Defined.
Concrete Example (Old Interface)
3 s 1 s
Total file time: 7 s
71
Definition IsInitialMorphism_object (𝑁 : IsInitialMorphism 𝐵𝜒) : 𝐸 := CommaCategory.b 𝐵𝜒. Definition IsInitialMorphism_morphism (𝑁 : IsInitialMorphism 𝐵𝜒) : morphism 𝐷 𝑌 (𝑉 0 (IsInitialMorphism_object 𝑁)) := CommaCategory.f 𝐵𝜒. Definition IsInitialMorphism_property_morphism (𝑁 : IsInitialMorphism 𝐵𝜒) (𝑍 : 𝐸) (f : morphism 𝐷 𝑌 (𝑉 0 𝑍)) : morphism 𝐸 (IsInitialMorphism_object 𝑁) 𝑍 := CommaCategory.h (@center _ (𝑁 (CommaCategory.Build_object !𝑌 𝑉 tt 𝑍 𝑔))). Definition IsInitialMorphism_property_morphism_property (𝑁 : IsInitialMorphism 𝐵𝜒) (𝑍 : 𝐸) (𝑔 : morphism 𝐷 𝑌 (𝑉 0 𝑍)) : 𝑉 1 (IsInitialMorphism_property_morphism 𝑁 𝑍 𝑔) ∘ (IsInitialMorphism_morphism 𝑁) = 𝑔 := CommaCategory.p (@center _ (𝑁 (CommaCategory.Build_object !𝑌 𝑉 tt 𝑍 𝑔))) @ right_identity _ _ _ _. Definition IsInitialMorphism_property_morphism_unique (𝑁 : IsInitialMorphism 𝐵𝜒) (𝑍 : 𝐸) (f : morphism 𝐷 𝑌 (𝑉 0 𝑍)) 𝑛′ (𝐼 : 𝑉 1 𝑛’ ∘ IsInitialMorphism_morphism 𝑁 = 𝑔) : IsInitialMorphism_property_morphism 𝑁 𝑍 𝑔 = 𝑛′ := ap (@CommaCategory.h _ _ _ _ _ _ _) (@contr _ (𝑁 (CommaCategory.Build_object !𝑌 𝑉 tt 𝑍 𝑔)) (CommaCategory.Build_morphism 𝐵𝜒 (CommaCategory.Build_object !𝑌 𝑉 tt 𝑍 𝑔) tt 𝑛′ (𝐼 @ (right_identity _ _ _ _) −1))). Definition IsInitialMorphism_property (𝑁 : IsInitialMorphism 𝐵𝜒) (𝑍 : 𝐸) (f : morphism 𝐷 𝑌 (𝑉 0 𝑍)) : Contr { 𝑛 : morphism 𝐸 (IsInitialMorphism_object 𝑁) 𝑍 | 𝑉 1 𝑛 ∘ (IsInitialMorphism_morphism 𝑁) = 𝑔 }. := {| center := (IsInitialMorphism_property_morphism 𝑁 𝑍 𝑔; IsInitialMorphism_property_morphism_property 𝑁 𝑍 𝑔); contr 𝑛′ := path_sigma _ (IsInitialMorphism_property_morphism 𝑁 𝑍 𝑔; IsInitialMorphism_property_morphism_property 𝑁 𝑍 𝑔) 𝑛′ (@ IsInitialMorphism_property_morphism_unique 𝑁 𝑍 𝑔 𝑛′ 1 𝑛′ 2) (center _) |}.
Concrete Example (New Interface)
0.4 s
Total file time: 7 s
72 Lemma pseudofunctor_to_cat_assoc_helper {𝑦 𝑦0 : 𝐷} {𝑦2 : morphism 𝐷 x x0} {x1 : 𝐷} {𝑦5 : morphism 𝐷 𝑦0 𝑦1} {𝑦4 : 𝐷} {𝑦7 : morphism 𝐷 𝑦1 𝑦4} {𝑞 𝑞0 : PreCategory} {𝑔 : morphism 𝐷 𝑦 𝑦4 → Functor 𝑞0 𝑞} {𝑞1 𝑞2 : PreCategory} {𝑔
0 : Functor 𝑞2 𝑞} {𝑔 1 : Functor 𝑞1 𝑞2} {𝑔 2 : Functor 𝑞0 𝑞2} {𝑔 3 : Functor 𝑞0 𝑞1} {𝑔 4 : Functor 𝑞1 𝑞}
{𝑦16 : morphism (_ → _) (𝑔 (𝑦7 ∘ 𝑦5 ∘ 𝑦2)) (𝑔
4 ∘ 𝑔 3)%functor}
{𝑦15 : morphism (_ → _) 𝑔
2 (𝑔 1 ∘ 𝑔 3)%functor} {𝐼2: IsIsomorphism 𝑦15}
{𝑦11 : morphism (_ → _) (𝑔 (𝑦7 ∘ (𝑦5 ∘ 𝑦2))) (𝑔
0 ∘ 𝑔 2)%functor}
{𝐼1: IsIsomorphism 𝑦11} {𝑦9 : morphism (_ → _) 𝑔
4 (𝑔 0 ∘ 𝑔 1)%functor} {fst_hyp : 𝑦7 ∘ 𝑦5 ∘ 𝑦2 = 𝑦7 ∘ (𝑦5 ∘ 𝑦2)}
(rew_hyp : ∀ 𝑦3 : 𝑞0, (idtoiso (𝑞0 → 𝑞) (ap 𝑔 fst_hyp) : morphism_ _ _) 𝑦3 = 𝑦11 −1 𝑦3 ∘ (𝑔
0 1 (𝑦15 −1 𝑦3) ∘ (𝕁 ∘ (𝑦9 (𝑔 3 𝑦3) ∘ 𝑦16 𝑦3))))
{𝐼0
′ : IsIsomorphism 𝑦16} {𝐼1 ′ : IsIsomorphism 𝑦9} {𝑦13 : 𝑞} {𝑦3 : 𝑞0} {𝑦6 : 𝑞1} {𝑦10 : 𝑞2}
{𝑦14 : morphism 𝑞 (𝑔
0 𝑦10) 𝑦13} {𝑦12 : morphism 𝑞2 (𝑔 1 𝑦6) 𝑦10} {𝑦8 : morphism 𝑞1 (𝑔 3 𝑦3) 𝑦6}
: existT (𝜇 𝑔
5 : morphism 𝐷 𝑦 𝑦4 ⇒ morphism 𝑞 ((𝑔 𝑔 5) 𝑦3) 𝑦13)
(𝑦7 ∘ 𝑦5 ∘ 𝑦2) (𝑦14 ∘ (𝑔
0 1 𝑦12 ∘ 𝑦9 𝑦6) ∘ (𝑔 4 1 𝑦8 ∘ 𝑦16 𝑦3)) = (𝑦7 ∘ (𝑦5 ∘ 𝑦2); 𝑦14 ∘ (𝑔 0 1 (𝑦12 ∘ (𝑔 1 1 𝑦8 ∘ 𝑦15 𝑦3)) ∘ 𝑦11 𝑦3)).
Proof. helper_t assoc_before_commutes_tac. assoc_fin_tac. Qed.
Concrete Example 2 (Generalization)
Speedup: 100x for the file, from 4m 53s to 28 s Time spent: a few hours
75
Dam image from http://www.flickr.com/photos/gammaman/7803829282/ by Eli Christman, CC by 2.0 Fence image from http://www.picgifs.com/clip-art/playing-children/clip-art-playing-children-362018-689955/
76
77
Dam image from http://www.flickr.com/photos/gammaman/7803829282/ by Eli Christman, CC by 2.0 Fence image from http://www.picgifs.com/clip-art/playing-children/clip-art-playing-children-362018-689955/ Universes image from Abell NGC2218 hst big, NASA, http://en.wikipedia.org/wiki/Abell_2218#mediaviewer/File:A bell_NGC2218_hst_big.jpg, released in Public Domain; Bubble from http://pixabay.com/en/blue-bubble-shiny- 157652/, released in Public Domain CC0, combined in Photoshop by Jason Gross
78
Definition 2-Graph := { V : Type & { 1E : V → V → Type & : ∀ 𝑤1 𝑤2, 1E 𝑤1 𝑤2 → 1E 𝑤1 𝑤2 → Type }. Definition V (G : 2-Graph) := pr1 (pr1 G). Definition 1E (G : 2-Graph) := pr1 (pr2 G). Definition 2E (G : 2-Graph) := pr2 (pr2 G).
79
Definition 2-Graph := { V : Type & { 1E : V → V → Type & : ∀ 𝑤1 𝑤2, 1E 𝑤1 𝑤2 → 1E 𝑤1 𝑤2 → Type }. Definition V (G : 2-Graph) := pr1 (pr1 G). Definition 1E (G : 2-Graph) := pr1 (pr2 G). Definition 2E (G : 2-Graph) := pr2 (pr2 G).
80
Definition 2-Graph := { V : Type & { 1E : V → V → Type & : ∀ 𝑤1 𝑤2, 1E 𝑤1 𝑤2 → 1E 𝑤1 𝑤2 → Type }. Definition V (G : 2-Graph) := @pr1 Type (𝜇 V : Type ⇒ { 1E : V → V → Type & : ∀ 𝑤1 𝑤2, 1E 𝑤1 𝑤2 → 1E 𝑤1 𝑤2 → Type }) G. ( G).
81
Definition 2-Graph := { V : Type & { 1E : V → V → Type & : ∀ 𝑤1 𝑤2, 1E 𝑤1 𝑤2 → 1E 𝑤1 𝑤2 → Type }. Definition V (G : 2-Graph) := pr1 (pr1 G). Definition 1E (G : 2-Graph) := pr1 (pr2 G). Definition 2E (G : 2-Graph) := pr2 (pr2 G).
82
Definition 1E (G : 2-Graph) := @pr1 (@pr1 Type (𝜇 V : Type ⇒ { 1E : V → V → Type & : ∀ 𝑤1 𝑤2, 1E 𝑤1 𝑤2 → 1E 𝑤1 𝑤2 → Type }) G → (@pr1 Type (𝜇 V : Type ⇒ { 1E : V → V → Type & : ∀ 𝑤1 𝑤2, 1E 𝑤1 𝑤2 → 1E 𝑤1 𝑤2 → Type }) G → (Type) (𝜇 1E : @pr1 Type (𝜇 V : Type ⇒ { 1E : V → V → Type & : , 1E 1E
83
Definition 1E (G : 2-Graph) := @pr1 (@pr1 Type (𝜇 V : Type ⇒ { 1E : V → V → Type & : ∀ 𝑤1 𝑤2, 1E 𝑤1 𝑤2 → 1E 𝑤1 𝑤2 → Type }) G → (@pr1 Type (𝜇 V : Type ⇒ { 1E : V → V → Type & : ∀ 𝑤1 𝑤2, 1E 𝑤1 𝑤2 → 1E 𝑤1 𝑤2 → Type }) G → (Type) (𝜇 1E : @pr1 Type (𝜇 V : Type ⇒ { 1E: V → V → Type & : ∀ 𝑤1 𝑤2, 1E 𝑤1 𝑤2 → 1E 𝑤1 𝑤2 → Type }) G → @pr1 Type (𝜇 V : Type ⇒ { 1E: V → V → Type & : ∀ 𝑤1 𝑤2, 1E 𝑤1 𝑤2 → 1E 𝑤1 𝑤2 → Type }) G → Type ⇒ ∀ 𝑤1 𝑤2, 1E 𝑤1 𝑤2 → 1E 𝑤1 𝑤2 → Type) (@pr2 Type (𝜇 V : Type ⇒ { 1E : V → V → Type & : ∀ 𝑤1 𝑤2, 1E 𝑤1 𝑤2 → 1E 𝑤1 𝑤2 → Type } G)
84
Definition 1E (G : 2-Graph) := @pr1 (@pr1 Type (𝜇 V : Type ⇒ { 1E : V → V → Type & ∀ (𝑤1 : V) (𝑤2 : V), 1E 𝑤1 𝑤2 → 1E 𝑤1 𝑤2 → Type }) G → (@pr1 Type (𝜇 V : Type ⇒ { 1E : V → V → Type & ∀ (𝑤1 : V) (𝑤2 : V), 1E 𝑤1 𝑤2 → 1E 𝑤1 𝑤2 → Type }) G → (Type) (𝜇 1E : @pr1 Type (𝜇 V : Type ⇒ { 1E : V → V → Type & ∀ (𝑤1 : V) (𝑤2 : V), 1E 𝑤1 𝑤2 → 1E 𝑤1 𝑤2 → Type }) G → @pr1 Type (𝜇 V : Type ⇒ { 1E : V → V → Type & ∀ (𝑤1 : V) (𝑤2 : V), 1E 𝑤1 𝑤2 → 1E 𝑤1 𝑤2 → Type }) G → Type ⇒ ∀(𝑤1 : @pr1 Type (𝜇 V : Type ⇒ { 1E : V → V → Type & ∀ (𝑤1 : V) (𝑤2 : V), 1E 𝑤1 𝑤2 → 1E 𝑤1 𝑤2 → Type }) G) (𝑤2 : @pr1 Type (𝜇 V : Type ⇒ { 1E : V → V → Type & ∀ (𝑤1 : V) (𝑤2 : V), 1E 𝑤1 𝑤2 → 1E 𝑤1 𝑤2 → Type }) G), 1E 𝑤1 𝑤2 → 1E 𝑤1 𝑤2 → Type) (@pr2 Type (𝜇 V : Type ⇒ { 1E : V → V → Type & ∀ (𝑤1 : V) (𝑤2 : V), 1E 𝑤1 𝑤2 → 1E 𝑤1 𝑤2 → Type }) G) :@pr1 Type (𝜇 V : Type ⇒ { 1E : V → V → Type & ∀ (𝑤1 : V) (𝑤2 : V), 1E 𝑤1 𝑤2 → 1E 𝑤1 𝑤2 → Type }) G → @pr1 Type (𝜇 V : Type ⇒ { 1E : V → V → Type & ∀ (𝑤1 : V) (𝑤2 : V), 1E 𝑤1 𝑤2 → 1E 𝑤1 𝑤2 → Type }) G → Type
85
Recall: Original was: Definition 1E (G : 2-Graph) := pr1 (pr2 G).
cutting down the work Coq has to do.
86
87
88
Setoids add lots of baggage to everything
89
Higher inductive types (when implemented) shove the baggage into the meta-theory, where the type-checker doesn’t have to see it
90
(even in proof assistants)
92
The paper and presentation will be available at
http://people.csail.mit.edu/jgross/#category-coq-experience
The library is available at
https://github.com/HoTT/HoTT
subdirectory theories/categories
93