Quotient Types in Type Theory
Total Page:16
File Type:pdf, Size:1020Kb
Quotient Types in Type Theory Nuo Li, BSc. Thesis submitted to the University of Nottingham for the degree of Doctor of Philosophy September 2014 Abstract Martin-Löf’s intuitionistic type theory (Type Theory) is a formal system that serves not only as a foundation of constructive mathematics but also as a depen- dently typed programming language. Dependent types are types that depend on values of other types. Type Theory is based on the Curry-Howard isomorphism which relates computer programs with mathematical proofs so that we can do computer-aided formal reasoning and write certified programs in programming lan- guages like Agda, Epigram etc. Martin Löf proposed two variants of Type Theory which are differentiated by the treatment of equality. In Intensional Type Theory, propositional equality defined by identity types does not imply definitional equal- ity, and type checking is decidable. In Extensional Type Theory, propositional equality is identified with definitional equality which makes type checking unde- cidable. Because of the good computational properties, Intensional Type Theory is more popular, however it lacks some important extensional concepts such as functional extensionality and quotient types. This thesis is about quotient types. A quotient type is a new type whose equality is redefined by a given equivalence relation. However, in the usual formulation of Intensional Type Theory, there is no type former to create a quotient. We also lose canonicity if we add quotient types into Intensional Type Theory as axioms. In this thesis, we first investigate the expected syntax of quotient types and explain it with categorical notions. For quotients which can be represented as a setoid as well as defined as a set without a quotient type former, we propose to define an algebraic structure of quotients called definable quotients. It relates the setoid interpretation and the set definition via a normalisation function which returns a normal form (canonical choice) for each equivalence class. It can be seen as a simulation of quotient types and it helps theorem proving because we can benefit from both representations. However this approach cannot be used for all quotients. It seems that we cannot define a normalisation function for some quotients in Type Theory, e.g. Cauchy reals and finite multisets. Quotient types are indeed essential for formalisation of mathematics and reasoning of programs. Then we consider some models of Type Theory where types are interpreted as structured objects such as setoids, groupoids or weak !-groupoids. In these models iii equalities are internalised into types which means that it is possible to redefine equalities. We present an implementation of Altenkirch’s [3] setoid model and show that quotient types can be defined within this model. We also describe a new extension of Martin-Löf type theory called Homotopy Type Theory where types are interpreted as weak !-groupoids. It can be seen as a generalisation of the groupoid model which makes extensional concepts including quotient types available. We also introduce a syntactic encoding of weak !-groupoids which can be seen as a first step towards building a weak !-groupoids model in Intensional Type Theory. All of these implementations were performed in the dependently typed programming language Agda which is based on intensional Martin-Löf type theory. iv Acknowledgements The first person I would like to thank is my supervisor Thorsten Altenkirch. He offered me a great internship opportunity about encoding numbers in Agda, which later developed into my PhD project. He was always patient in answering questions and taught me a lot about research. I would also like to thank him for his guidance and feedback on this thesis. I would also thank my second supervisor Thomas Anberrée who introduced me to functional programming and gave me precious advice on my project. I would also like to thank Venanzio Capretta who examined my first and second year reports and provided me with helpful feedback. I would like to thank Ambrus Kaposi and Nicolai Kraus for their great help in writ- ing my thesis and comments on my drafts, and correcting my grammatical errors for the final version. My friends Nicolai Kraus, Ambrus Kaposi, Christian Sattler, Paolo Capriotti, Florent Balestrieri, Gabe Dijkstra, Ivan Perez, Neil Sculthorpe and all the other PhD students in our lab helped me a lot by either teaching me mathematics, discussing research topics or playing badminton to exercise our bod- ies. The Functional Programming Lab is like a lively family and I really enjoyed the time here. I would like to thank everyone here. Without their kind help, the thesis would not have been finished. I would also like to thank the organizers and other participants of the special year on Homotopy Type Theory at the Institute for Advanced Study where we had many interesting discussions some of which were related to parts of this work, especially Guillaume Brunerie whose proposal made it possible. I would also like to thank F. Nordvall Forsberg with whom we had important discussions related to our work. I would also like to thank my parents and other family members. During the years in Nottingham, my mother Guangfei Lv and my father Youyuan Li were always very supportive of me, even though I was living far from them. They talked to me a lot and sent my favourite foods to me many times. My aunt Guangshu Lv who is living in Germany also helped me a lot. She gave me many advice and has sent mails to me. Without their support I would have never achieved my goals. v Finally, I would like to thank the School of Computer Science and the International Office at the University of Nottingham who financially supported this project by providing a scholarship. vi Contents 1 Introduction1 1.1 Quotient types.............................2 1.2 Structure of the thesis.........................6 2 Type Theory9 2.1 A brief history of Type Theory.................... 10 2.2 The formal system of Type Theory.................. 15 2.3 An implementation of Type Theory: Agda.............. 20 2.4 Extensional concepts.......................... 26 2.5 An Intensional Type Theory with Prop ............... 31 2.6 Homotopy Type Theory........................ 32 2.7 Summary................................ 37 3 Quotient Types 39 3.1 Quotients in Type Theory....................... 39 3.2 Quotients are coequalizers....................... 45 3.3 Quotients as an adjunction....................... 48 3.4 Quotients in Homotopy Type Theory................. 51 3.5 Related work.............................. 59 3.6 Summary................................ 63 4 Definable Quotients 65 4.1 Algebraic structures of quotients.................... 66 4.2 Integers................................. 70 4.3 Rational numbers............................ 73 4.4 The application of definable quotients................. 79 4.5 Related work.............................. 85 4.6 Summary................................ 86 5 Undefinable Quotients 89 5.1 Definability via normalisation..................... 89 vii Contents viii 5.2 Real numbers as Cauchy sequences.................. 91 5.3 R0= ∼ is undefinable via normalisation................ 93 5.4 Other examples............................. 100 5.5 Related work.............................. 104 5.6 Summary................................ 104 6 The Setoid Model 107 6.1 Introduction............................... 108 6.2 Metatheory............................... 109 6.3 Categories with families........................ 114 6.4 Related work.............................. 124 6.5 Summary................................ 125 7 Syntactic !-groupoids 127 7.1 Syntax of weak !-groupoids...................... 129 7.2 Some Important Derivable Constructions............... 136 7.3 Semantics................................ 147 7.4 Related work.............................. 151 7.5 Summary................................ 151 8 Conclusion and Future Work 153 A Definable quotient structures 157 A.1 Rational numbers............................ 171 B Category with families of setoids 175 B.1 Metatheory............................... 175 B.2 Categories with families........................ 177 C syntactic weak !-groupoids 193 C.1 Syntax of T∞−groupoid .......................... 193 C.2 Some Important Derivable Constructions............... 205 C.3 Sematics................................. 222 Bibliography 225 Chapter 1 Introduction Martin-Löf type theory (or just Type Theory) is a type theory which serves as a foundation of constructive mathematics and is also a dependently typed pro- gramming language. Different from other foundations like set theory, it is not based on predicate logic but internalises the BHK interpretation of intuitionistic logic through the Curry-Howard isomorphism. It identifies propositions with types such that proofs of a proposition become terms of the corresponding type. Viewed as a programming language, this means that we can express a specification as a type, and a program of that type will satisfy the specification. Moreover, one can write programs and reason about them in the same language resulting in certified programs. Implementations of Type Theory include NuPRL, LEGO, Coq, Agda, Epigram, Pi-Sigma. Viewed as a foundation for mathematics, Type Theory is a powerful tool for con- structively proving theorems with computerised verification. An example is the formal proof of the four-colour theorem by Georges Gonthier [42] 1. There are two versions of Martin-Löf type theory, the intensional version (Inten- sional Type Theory or ITT)