Formalizing Category Theory in Agda CPP ’21, January 18–19, 2021, Virtual, Denmark

Formalizing Category Theory in Agda CPP ’21, January 18–19, 2021, Virtual, Denmark

Formalizing Category Theory in Agda Jason Z. S. Hu Jacques Carette [email protected] [email protected] McGill University McMaster University Montréal, Québec, Canada Hamilton, Ontario, Canada Abstract years [4, 16, 18, 24, 26, 28–30, 32, 35, 37, etc.]. All of them em- The generality and pervasiveness of category theory in mod- body choices; some were forced by the ambient logic of the ern mathematics makes it a frequent and useful target of for- host system, others were pragmatic decisions, some were malization. It is however quite challenging to formalize, for philosophical stances, while finally others were simply de- a variety of reasons. Agda currently (i.e. in 2020) does not sign decisions. have a standard, working formalization of category theory. Category theory is often picked as a challenge, as it is We document our work on solving this dilemma. The for- bothbequiteamenableto formalizationand to involve many malization revealed a number of potential design choices, non-trivial decisions that can have drastic effects on the us- and we present, motivate and explain the ones we picked. ability and effectiveness of the results [16]. With the rapid In particular, we find that alternative definitions or alter- rise in the use of category theory as a tool in computer sci- native proofs from those found in standard textbooks can ence, and with the advent of applied category theory, hav- be advantageous, as well as “fit” Agda’s type theory more ing a stable formalization in the standard library of one’s smoothly. Some definitions regarded as equivalent in stan- favourite proof assistant becomes necessary. dard textbooks turn out to make different “universe level” Our journey started as the authors were trying to keep assumptions, with some being more polymorphic than oth- the “old” category theory library for Agda [26] alive. Unfor- ers. We also pay close attention to engineering issues so that tunately, as Agda [3] evolved, some of the features used in the library integrates well with Agda’s own standard library, that library were no longer well-supported, and eventually as well as being compatible with as many of supported type the library simply stopped working. As it became clear that theories in Agda as possible. simply continuing to patch that library was no longer viable, a new version was in order. CCS Concepts: • Theory of computation → Type the- This gave us the opportunity to revisit various design de- ory; Logic and verification. cisions of the earlier implementation — which we will docu- ment. We also wanted to preserve as much formalization ef- Keywords: Agda, category theory, formal mathematics fort as possible, while also use language features introduced ACM Reference Format: in Agda 2.6+ like generalized variables and revise the the- Jason Z. S. Hu and Jacques Carette. 2021. Formalizing Category oretical foundation which the library relies on. This new Theory in Agda. In Proceedings of the 10th ACM SIGPLAN Interna- version is then partly a “port” of the previous one to cur- tional Conference on Certified Programs and Proofs (CPP ’21), Jan- rent versions of Agda, but also heavily refactored, including uary 18–19, 2021, Virtual, Denmark. ACM, New York, NY, USA, some large changes in design. 16 pages. hps://doi.org/10.1145/3437992.3439922 Our principal theoretical contribution is to show that setoid- based proof-relevant category theory works just as well as arXiv:2005.07059v2 [cs.LO] 6 Jan 2021 1 Introduction various other “flavours” of category theory by supporting There have been many formalizations of category theory [7, a large number of definitions and theorems. Our main engi- 21] in many different proof assistants, over more than 25 neering contribution is a coherent set of design decisions for a widely reusable and working library of category theory in 1 Permission to make digital or hard copies of all or part of this work for Agda, freely available . personal or classroom use is granted without fee provided that copies are This paper is structured as follows. In Section 2, we dis- not made or distributed for profit or commercial advantage and that copies cuss our global design choices. We discuss the rationale be- bear this notice and the full citation on the first page. Copyrights for com- hind non-strictness, proof-relevance, hom-setoids, universe ponents of this work owned by others than the author(s) must be honored. polymorphism, (not) requiring extra laws and concepts as Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission record types. In Section 3, we give examples on how proof- and/or a fee. Request permissions from [email protected]. relevance drives us to find concepts in an alternative way. CPP ’21, January 18–19, 2021, Virtual, Denmark In Section 4, we discuss other design decisions and some ef- © 2021 Copyright held by the owner/author(s). Publication rights licensed ficiency issues. In Section 5, we compare category theory to ACM. libraries in other systems. Finally, we conclude in Section 6. ACM ISBN 978-1-4503-8299-1/21/01...$15.00 hps://doi.org/10.1145/3437992.3439922 1at hps://github.com/agda/agda-categories CPP ’21, January 18–19, 2021, Virtual, Denmark Jason Z. S. Hu and Jacques Caree For reasons of space, we have to make some assumptions 2.2 Which Category Theory? of our readership, namely that they are familiar with: Category theory is often presented as a single theory, but 1. category theory, there are in fact a wealth of flavours: set-theoretic, where 2. dependent type theory, a category has a single hom-set equipped with source and 3. formalization, and target maps; ETCS-style [20], where there are no objects at 4. proof assistants (e.g. familiarity with Agda and a pass- all; dependently-typed, where hom-“sets” are parametrized ing knowledge of other systems). by two objects; proof-irrelevant, where the associativity and identity laws are considered to be unique [4, 16, 26, 35]; 2 Design Choices setoid-based, where each category relies on a local notion of equivalence of hom-sets rather than relying on a global Choices arise from both the system and its logic, as well as equality relation [26, 37]. There are also questions of being from the domain itself. strict or weak, whether to do 1-categories, =-categories or even ∞-categories. What to choose? 2.1 Fitting with Agda Standard textbooks often define a category as follows: The previous formalization [26] was done in a much older Agda, with a seriously under-developed standard library. To Definition 2.1. A category C consists of the following data: better fit with modern Agda, we choose to: 1. a collection of objects, C0, 1. use dependent types, 2. a collection of morphisms, C1, between two objects. 2. be constructive, We use 5 : ⇒ to denote the morphism 5 ∈ C1 is 3. re-use as much of the standard library [12] as possible, between objects and , 4. use the naming convention of its standard library when- 3. for each object , we have an identity morphism 1 : ever meaningful, ⇒ , and 5. use the variable generalization feature for levels and 4. morphism composition ◦ composing two morphisms categories, 5 : ⇒ and 6 : ⇒ into another morphism 6. try to fit with as many modes of Agda as possible. 5 ◦ 6 : ⇒ . The first two requirements are natural, as choosing oth- These must satisfy the following laws: erwise would create a clash of philosophy between the sys- 1. identity: for any morphism 5 : ⇒ , we have 5 ◦ tem and one of its libraries. The next two are just good soft- 1 = 5 = 1 ◦ 5 , and ware engineering, while the fifth is mere convenience. Note 2. associativity: for any three morphisms 5 , 6 and ℎ, we that re-using the standard library pushes us towards setoids have (5 ◦ 6) ◦ ℎ = 5 ◦(6 ◦ ℎ). (more on that later) as its formalization of algebra uses them extensively. Embedded in the above definition are a variety of deci- The last requirement is more subtle: we want to allow sions, and we will use these as a running example to explain others to use alternative systems or make postulates if they ours. wish, and still be able to use our library. This means that we 2.2.1 Collections. The first item to notice is the use of need to avoid using features that are incompatible with sup- collection rather than set or type. Textbooks tend to do this ported systems in Agda. For example, when added to Martin- to side-step “size” issues, and then define various kinds of Löf Type Theory (MLTT) [23], axiom K [31], equivalent to categories depending on whether each of the collections (ob- Uniqueness of Identity Proofs (UIP), creates a propositionally jects, all morphisms, all morphisms given a pair of objects) extensional type theory incompatible with univalence [33]. is “small”, i.e. a set. This matters because a number of con- Thus Agda has options such as --without-K [10] to access structions in category theory produce large results. the intensional type theory MLTT, and conversely --with- We define collections of objects to be types, with no further K to turn on axiom K. Separately, there is cubical type the- assumptions or requirements. We do know that in MLTT ory(--cubical)[34] which implements a computational in- types are well modeled by ∞-groupoids [17, 36] — so wouldn’t terpretation of homotopy type theory (HoTT) [33] and sup- this higher structure be a problem? No! This is because we ports univalence. Intensional type theory is compatible with never look at it, i.e.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    16 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us