performant category theory
play

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;


  1. Experience implementing a performant category-theory library in Coq Jason Gross, Adam Chlipala, David I. Spivak Massachusetts Institute of Technology

  2. How should theorem provers work? 2

  3. How theorem provers should work: 1 = 0 1 = 0 No; hereโ€™s a Coq, is this proof of correct? 1 = 0 โ†’ False 3

  4. How theorem provers should work: Th Theo eorem rem (curr rryi ying ng) ) : ๐‘ซ ๐Ÿ โ†’ ๐‘ซ ๐Ÿ‘ โ†’ ๐‘ฌ โ‰… (๐‘ซ ๐Ÿ ร— ๐‘ซ ๐Ÿ‘ โ†’ ๐‘ฌ) Proof: : homewo ework k โˆŽ Coq, is this Yes; hereโ€™s a correct? proof โ€ฆ 4

  5. How theorem provers should work: Th Theo eorem rem (curr rryi ying ng) ) : ๐‘ซ ๐Ÿ โ†’ ๐‘ซ ๐Ÿ‘ โ†’ ๐‘ฌ โ‰… (๐‘ซ ๐Ÿ ร— ๐‘ซ ๐Ÿ‘ โ†’ ๐‘ฌ) Proof: : homewo ework k โˆŽ Theorem currying : ๐ท 1 โ†’ ๐ท 2 โ†’ ๐ธ โ‰… ๐ท 1 ร— ๐ท 2 โ†’ ๐ธ . Proof. trivial. Qed. 5

  6. How theorem provers should work: Theo Th eorem rem (curr rryi ying ng) ) : ๐‘ซ ๐Ÿ โ†’ ๐‘ซ ๐Ÿ‘ โ†’ ๐‘ฌ โ‰… (๐‘ซ ๐Ÿ ร— ๐‘ซ ๐Ÿ‘ โ†’ ๐‘ฌ) Proof: โ†’ : : ๐‘ฎ โ†ฆ ๐ ๐’… ๐Ÿ , ๐’… ๐Ÿ‘ . ๐‘ฎ ๐’… ๐Ÿ ๐’… ๐Ÿ‘ ; morph phisms isms simila larly ly โ† : : ๐‘ฎ โ†ฆ ๐ ๐’… ๐Ÿ . ๐ ๐’… ๐Ÿ‘ . ๐‘ฎ(๐’… ๐Ÿ , ๐’… ๐Ÿ‘ ) ; morphis hisms ms simila larly ly Functoriality oriality, , naturality rality, , and congrue uence: nce: straig ightfo htforward. rward. โˆŽ Theorem currying : ๐ท 1 โ†’ ๐ท 2 โ†’ ๐ธ โ‰… ๐ท 1 ร— ๐ท 2 โ†’ ๐ธ . Proof. esplit. { by refine ( ๐œ‡ F ( ๐บ โ†ฆ ( ๐œ‡ F ( ๐‘‘ โ†ฆ ๐บ o ๐‘‘ 1 ๐‘‘ 2 )))). } { by refine ( ๐œ‡ F ( ๐บ โ†ฆ ( ๐œ‡ F ( ๐‘‘ 1 โ†ฆ ( ๐œ‡ F ( ๐‘‘ 2 โ†ฆ ๐บ o (๐‘‘ 1 , ๐‘‘ 2 )) ))))). } all: trivial. Qed. 6

  7. How theorem provers should work: Th Theo eorem rem (curr rryi ying ng) ) : ๐‘ซ ๐Ÿ โ†’ ๐‘ซ ๐Ÿ‘ โ†’ ๐‘ฌ โ‰… (๐‘ซ ๐Ÿ ร— ๐‘ซ ๐Ÿ‘ โ†’ ๐‘ฌ) Proof: โ†’ : : ๐‘ฎ โ†ฆ ๐ ๐’… ๐Ÿ , ๐’… ๐Ÿ‘ . ๐‘ฎ ๐’… ๐Ÿ ๐’… ๐Ÿ‘ ; morph phisms isms simila larly ly โ† : : ๐‘ฎ โ†ฆ ๐ ๐’… ๐Ÿ . ๐ ๐’… ๐Ÿ‘ . ๐‘ฎ(๐’… ๐Ÿ , ๐’… ๐Ÿ‘ ) ; morphis hisms ms simila larly ly Functoriality oriality, , naturality rality, , and congrue uence: nce: straig ightfo htforward. rward. โˆŽ Theorem currying : ๐ท 1 โ†’ ๐ท 2 โ†’ ๐ธ โ‰… ๐ท 1 ร— ๐ท 2 โ†’ ๐ธ . Proof. esplit. { by refine ( ๐œ‡ F ( ๐บ โ†ฆ ( ๐œ‡ F ( ๐‘‘ โ†ฆ ๐บ o ๐‘‘ 1 ๐‘‘ 2 ) ( ๐‘ก ๐‘’ ๐‘› โ†ฆ ๐บ o ๐‘’ 1 m ๐‘› 2 โˆ˜ ๐บ m ๐‘› 1 o ๐‘ก 2 )) ( ๐บ ๐ป ๐‘ˆ โ†ฆ ( ๐œ‡ T ( ๐‘‘ โ†ฆ ๐‘ˆ ๐‘‘ 1 ๐‘‘ 2 )))). } { by refine ( ๐œ‡ F ( ๐บ โ†ฆ ( ๐œ‡ F ( ๐‘‘ 1 โ†ฆ ( ๐œ‡ F ( ๐‘‘ 2 โ†ฆ ๐บ o (๐‘‘ 1 , ๐‘‘ 2 )) ( ๐‘ก ๐‘’ ๐‘› โ†ฆ ๐บ m (1, ๐‘›)) )) ( ๐บ ๐ป ๐‘ˆ โ†ฆ ( ๐œ‡ T ( ๐‘‘ 1 โ†ฆ ( ๐œ‡ T ( ๐‘‘ 2 โ†ฆ ๐‘ˆ (๐‘‘ 1 , ๐‘‘ 2 ) ))))). } all: trivial. Qed. 7

  8. How theorem provers do work: Th Theo eorem rem (curr rryi ying ng) ) : ๐‘ซ ๐Ÿ โ†’ ๐‘ซ ๐Ÿ‘ โ†’ ๐‘ฌ โ‰… (๐‘ซ ๐Ÿ ร— ๐‘ซ ๐Ÿ‘ โ†’ ๐‘ฌ) Proof: โ†’ : : ๐‘ฎ โ†ฆ ๐ ๐’… ๐Ÿ , ๐’… ๐Ÿ‘ . ๐‘ฎ ๐’… ๐Ÿ ๐’… ๐Ÿ‘ ; morph phisms isms simila larly ly โ‰ˆ 0 s โ† : : ๐‘ฎ โ†ฆ ๐ ๐’… ๐Ÿ . ๐ ๐’… ๐Ÿ‘ . ๐‘ฎ(๐’… ๐Ÿ , ๐’… ๐Ÿ‘ ) ; morphis hisms ms simila larly ly Functoriality oriality, , naturality rality, , and congrue uence: nce: straig ightfo htforward. rward. โˆŽ 17 s 2m 46 s !!! (5 s, if we use UIP) Theorem currying : ๐ท 1 โ†’ ๐ท 2 โ†’ ๐ธ โ‰… ๐ท 1 ร— ๐ท 2 โ†’ ๐ธ . Proof. esplit. { by refine ( ๐œ‡ F ( ๐บ โ†ฆ ( ๐œ‡ F ( ๐‘‘ โ†ฆ ๐บ o ๐‘‘ 1 ๐‘‘ 2 ) ( ๐‘ก ๐‘’ ๐‘› โ†ฆ ๐บ o ๐‘’ 1 m ๐‘› 2 โˆ˜ ๐บ m ๐‘› 1 o ๐‘ก 2 )) ( ๐บ ๐ป ๐‘ˆ โ†ฆ ( ๐œ‡ T ( ๐‘‘ โ†ฆ ๐‘ˆ ๐‘‘ 1 ๐‘‘ 2 )))). } { by refine ( ๐œ‡ F ( ๐บ โ†ฆ ( ๐œ‡ F ( ๐‘‘ 1 โ†ฆ ( ๐œ‡ F ( ๐‘‘ 2 โ†ฆ ๐บ o (๐‘‘ 1 , ๐‘‘ 2 )) ( ๐‘ก ๐‘’ ๐‘› โ†ฆ ๐บ m (1, ๐‘›)) )) ( ๐บ ๐ป ๐‘ˆ โ†ฆ ( ๐œ‡ T ( ๐‘‘ 1 โ†ฆ ( ๐œ‡ T ( ๐‘‘ 2 โ†ฆ ๐‘ˆ (๐‘‘ 1 , ๐‘‘ 2 ) ))))). } all: trivial. Qed. 8

  9. Performance is important! If weโ€™re not careful, obvious or trivial things can be very, very slow. 9

  10. Why you should listen to me Theorem : You should listen to me. Proof. by experience. Qed. 10

  11. Why you should listen to me Category theory in Coq: https://github.com/HoTT/HoTT (subdirectory theories/categories): ๐ท 1 โ‰… ๐ท ; 1 ๐ท โ‰… 1 โ€ข Concepts Formalized: ๐ท ๐ต+๐ถ โ‰… ๐ท ๐ต ร— ๐ท ๐ถ โ€ข โ€ข 1-precategories (in the sense of the HoTT Book) (๐ต ร— ๐ถ) ๐ท โ‰… ๐ต ๐ท ร— ๐ถ ๐ท โ€ข โ€ข univalent/saturated categories (or just categories, in the HoTT Book) โ€ข โ€ข (๐ต ๐ถ ) ๐ท โ‰… ๐ต ๐ถร—๐ท functor precategories ๐ท โ†’ ๐ธ dual functor isomorphisms Cat โ†’ Cat ; and ๐ท โ†’ ๐ธ op โ†’ (๐ท op โ†’ ๐ธ op ) โ€ข โ€ข Product laws โ€ข โ€ข the category Prop of (U-small) hProps ๐ท ร— ๐ธ โ‰… ๐ธ ร— ๐ท โ€ข โ€ข the category Set of (U-small) hSets ๐ท ร— 0 โ‰… 0 ร— ๐ท โ‰… 0 โ€ข โ€ข the category Cat of (U-small) strict (pre)categories (strict in the sense of the ๐ท ร— 1 โ‰… 1 ร— ๐ท โ‰… ๐ท โ€ข objects being hSets) Grothendieck construction (oplax colimit) of a pseudofunctor to Cat โ€ข โ€ข pseudofunctors Category of sections (gives rise to oplax limit of a pseudofunctor to Cat when โ€ข profunctors applied to Grothendieck construction identity profunction (the hom functor ๐ท op ร— ๐ท โ†’ Set ) โ€ข โ€ข functor composition is functorial (there's a functor ฮ”: ๐ท โ†’ ๐ธ โ†’ (๐ธ โ†’ โ€ข adjoints โ€ข equivalences between a number of definitions: โ€ข unit-counit + zig-zag definition โ€ข unit + UMP definition โ€ข counit + UMP definition โ€ข universal morphism definition โ€ข hom-set definition (porting from old version in progress) โ€ข composition, identity, dual pointwise adjunctions in the library, ๐ป ๐น โŠฃ ๐บ ๐ท and ๐น ๐บ โŠฃ ๐ท ๐ป from an โ€ข adjunction ๐บ โŠฃ ๐ป for functors ๐บ: ๐ท โ‡† ๐ธ: ๐ป and ๐น a precategory (still too slow to be merged into the library proper; code here) โ€ข Yoneda lemma โ€ข Exponential laws 11 ๐ท 0 โ‰… 1 ; 0 ๐ท โ‰… 0 given an object in ๐ท โ€ข

  12. Presentation is not mainly about: 12

  13. Presentation is not mainly about: โ€ข category theory or diagram chasing Cartoon from xkcd, adapted by Alan Huang 13

  14. Presentation is not mainly about: โ€ข category theory or diagram chasing Cartoon from xkcd, adapted by Alan Huang โ€ข my library 14

  15. Presentation is not mainly about: โ€ข category theory or diagram chasing Cartoon from xkcd, adapted by Alan Huang โ€ข my library โ€ข Coq 15

  16. Presentation is not mainly about: โ€ข category theory or diagram chasing Cartoon from xkcd, adapted by Alan Huang โ€ข my library โ€ข Coq (though what I say might not always generalize nicely) 16

  17. Presentation is is about: โ€ข performance โ€ข the design of proof assistants and type theories to assist with performance โ€ข the kind of performance issues I encountered 17

  18. Presentation is is for: โ€ข Users of proof assistants (and Coq in particular) โ€ข Who want to make their code faster โ€ข Designers of (type-theoretic) proof assistants โ€ข Who want to know where to focus their optimization efforts 18

  19. Outline โ€ข Why should we care about performance? โ€ข What makes theorem provers (mainly Coq) slow? โ€ข Examples of particular slowness โ€ข For users (workarounds) โ€ข Arguments vs. fields and packed records โ€ข Proof by duality as proof by unification โ€ข Abstraction barriers โ€ข Proof by reflection โ€ข For developers (features) โ€ข Primitive projections โ€ข Higher inductive types โ€ข Universe Polymorphism Universes image from Abell NGC2218 hst big, NASA, โ€ข More judgmental rules 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 โ€ข Hashconsing Photoshop by Jason Gross 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/

  20. Performance โ€ข Question: What makes programs, particularly theorem provers or proof scripts, slow? 20

  21. Performance โ€ข Question: What makes programs, particularly theorem provers or proof scripts, slow? โ€ข Answer: Doing too much stuff! 21

  22. Performance โ€ข Question: What makes programs, particularly theorem provers or proof scripts, slow? โ€ข Answer: Doing too much stuff! โ€ข doing the same things repeatedly 22 Snail from http://naolito.deviantart.com/art/Repetitive-task-258126598

  23. Performance โ€ข Question: What makes programs, particularly theorem provers or proof scripts, slow? โ€ข Answer: Doing too much stuff! โ€ข doing the same things repeatedly โ€ข doing lots of stuff for no good reason 23 Running rooster from http://d.wapday.com:8080/animation/ccontennt/15545-f/mr_rooster_running.gif

  24. Performance โ€ข Question: What makes programs, particularly theorem provers or proof scripts, slow? โ€ข Answer: Doing too much stuff! โ€ข doing the same things repeatedly โ€ข doing lots of stuff for no good reason โ€ข using a slow language when you could be using a quicker one 24

  25. Proof assistant performance โ€ข What kinds of things does Coq do? โ€ข Type checking โ€ข Term building โ€ข Unification โ€ข Normalization 25

  26. Proof assistant performance (pain) โ€ข When are these slow? โ€ข when you duplicate work โ€ข when you do work on a part of a term you end up not caring about โ€ข when you do them too many times โ€ข when your term is large 26

  27. Proof assistant performance (size) โ€ข How large is slow? 27

Recommend


More recommend