Eliminating Reflection from Type Theory Théo Winterhalter, Matthieu Sozeau, Nicolas Tabareau
Total Page:16
File Type:pdf, Size:1020Kb
Eliminating Reflection from Type Theory Théo Winterhalter, Matthieu Sozeau, Nicolas Tabareau To cite this version: Théo Winterhalter, Matthieu Sozeau, Nicolas Tabareau. Eliminating Reflection from Type Theory: To the Legacy of Martin Hofmann. CPP 2019 - 8th ACM SIGPLAN International Conference on Certified Programs and Proofs, Jan 2019, Lisbonne, Portugal. pp.91-103, 10.1145/3293880.3294095. hal-01849166v3 HAL Id: hal-01849166 https://hal.archives-ouvertes.fr/hal-01849166v3 Submitted on 22 Nov 2018 HAL is a multi-disciplinary open access L’archive ouverte pluridisciplinaire HAL, est archive for the deposit and dissemination of sci- destinée au dépôt et à la diffusion de documents entific research documents, whether they are pub- scientifiques de niveau recherche, publiés ou non, lished or not. The documents may come from émanant des établissements d’enseignement et de teaching and research institutions in France or recherche français ou étrangers, des laboratoires abroad, or from public or private research centers. publics ou privés. 1 56 2 Eliminating Reflection from Type Theory 57 3 To the Legacy of Martin Hofmann 58 4 59 5 60 6 Théo Winterhalter Matthieu Sozeau Nicolas Tabareau 61 7 Gallinette Project-Team, Inria Pi.R2 Project-Team, Inria and IRIF Gallinette Project-Team, Inria 62 8 Nantes, France Paris, France Nantes, France 63 9 [email protected] [email protected] [email protected] 64 10 65 Abstract of equality inside type theory, whereas u ≡ v : A means 11 66 that u and v are convertible in the theory—and can thus 12 Type theories with equality reflection, such as extensional 67 be silently replaced by one another in any term. Several 13 type theory (ETT), are convenient theories in which to for- 68 variants of ETT have been considered and implemented, for 14 malise mathematics, as they make it possible to consider 69 example in NuPRL [Allen et al. 2000] and more recently in 15 provably equal terms as convertible. Although type-checking 70 Andromeda [Bauer et al. 2016]. The prototypical example of 16 is undecidable in this context, variants of ETT have been 71 the use of equality reflection is the definition of a coercion 17 implemented, for example in NuPRL and more recently in 72 function between two types A and B that are equal (but not 18 Andromeda. The actual objects that can be checked are not 73 convertible) by taking a term of type A and simply returning 19 proof-terms, but derivations of proof-terms. This suggests 74 it as a term of type B: 20 that any derivation of ETT can be translated into a typecheck- 75 21 able proof term of intensional type theory (ITT). However, λ AB (e : A = B)(x : A): x : Π AB: A = B ! A ! B: 76 this result, investigated categorically by Hofmann in 1995, 22 In intensional type theory (ITT), this term does not type- 77 and 10 years later more syntactically by Oury, has never 23 check because x of type A can not be given the type B by 78 given rise to an effective translation. In this paper, we pro- 24 conversion. In ETT, however, equality reflection can be used 79 vide the first effective syntactical translation from ETTto 25 to turn the witness of equality into a proof of conversion and 80 ITT with uniqueness of identity proofs and functional ex- 26 thus the type system validates the fact that x can be given the 81 tensionality. This translation has been defined and proven 27 type B. This means that one needs to guess equality proofs 82 correct in Coq and yields an executable plugin that translates 28 during type-checking, because the witness of equality has 83 a derivation in ETT into an actual Coq typing judgment. Ad- 29 been lost at the application of the reflection rule. Guessing it 84 ditionally, we show how this result is extended in the context 30 was not so hard in this example but is in general undecidable, 85 of homotopy type theory to a two-level type theory. 31 as one can for instance encode the halting problem of any 86 32 Keywords dependent types, translation, formalisation Turing machine as an equality in ETT. That is, the actual 87 33 objects that can be checked in ETT are not terms, but instead 88 34 1 Introduction derivations of terms. It thus seems natural to wonder whether 89 35 90 Type theories with equality reflection, such as extensional any derivation of ETT can be translated into a typecheckable 36 91 type theory (ETT), are convenient theories in which to for- term of ITT. And indeed, it is well know that one can find 37 92 malise mathematics, as they make it possible to consider a corresponding term of the same type in ITT by explicitly 38 93 provably equal terms as convertible, as expressed in the fol- transporting the term x of type A using the elimination of 39 94 lowing typing rule: internal equality on the witness of equality e, noted e∗: 40 95 λ AB (e : A = B)(x : A): e∗ x : Π AB: A = B ! A ! B: 41 Γ `x e : u =A v 96 42 (1) This can be seen as a way to make explicit the silent use 97 Γ `x u ≡ v : A 43 of reflection. Furthermore, by making the use of transport 98 44 Here, the type u =A v is Martin-Löf’s identity type with as economic as possible, the corresponding ITT term can 99 45 only one constructor refl u : u =A u which represents proofs be seen as a compact witness of the derivation tree of the 100 46 101 Permission to make digital or hard copies of part or all of this work for original ETT term. 47 personal or classroom use is granted without fee provided that copies are This result has first been investigated categorically in the 102 48 not made or distributed for profit or commercial advantage and that copies pioneering work of Hofmann [1995, 1997], by showing that 103 49 bear this notice and the full citation on the first page. Copyrights for third- the term model of ITT can be turned into a model of ETT by 104 50 party components of this work must be honored. For all other uses, contact quotienting this model with propositional equality. However, 105 the owner/author(s). 51 it is not clear how to extend this categorical construction 106 Conference’17, July 2017, Washington, DC, USA 52 107 © 2018 Copyright held by the owner/author(s). to an explicit and constructive translation from a derivation 53 ACM ISBN 978-x-xxxx-xxxx-x/YY/MM. in ETT to a term of ITT. In 2005, this result has been in- 108 54 https://doi.org/10.1145/nnnnnnn.nnnnnnn vestigated more syntactically by Oury [2005]. However, his 109 55 1 110 Conference’17, July 2017, Washington, DC, USA Théo Winterhalter, Matthieu Sozeau, and Nicolas Tabareau 111 presentation does not give rise to an effective translation. discuss limitations and related work. The main proofs are 166 112 By an effective translation we mean that it is entirely con- given in detail in Appendices B and C. 167 113 structive and can be used to deterministically compute the The Coq formalisation can be found in https://github.com/ 168 114 translation of a given ETT typing derivation. Two issues TheoWinterhalter/ett-to-itt. 169 115 prevent deriving an effective translation from Oury’s presen- 170 116 tation, and it is the process of actual formalisation of the 1.1 On the Need for UIP and Functional 171 117 result in a proof assistant that led us to these discoveries. Extensionality. 172 118 First, his handling of related contexts is not explicit enough, Our translation targets ITT plus UIP and functional exten- 173 119 which we fix by framing the translation using ideas coming sionality, which correspond to the two following axioms 174 120 from the parametricity translation (section 1.2). Addition- (where □i denotes the universe of types at level i): 175 121 ally, Oury’s proof requires an additional axiom in ITT on 0 0 176 UIP : Π(A : □i )(x y : A)(e e : x = y): e = e 122 top of functional extensionality and uniqueness of identity 177 FunExt : Π(A : i )(B : A ! i )(f д : Π(x : A): B x): 123 □ □ 178 proofs, that has no clear motivation and can be avoided by (Π(x : A): f x = д x) ! f = д 124 considering an annotated syntax (section 2.1). 179 125 The first axiom says that any two proofs of the same equality 180 126 Contributions. In this paper, we present the first effective are equal, and the other one says that two (dependent) func- 181 2 127 syntactical translation from ETT to ITT (assuming unique- tions are equal whenever they are pointwise equal . These 182 128 ness of identity proofs (UIP) and functional extensionality in two axioms are perfectly valid statements of ITT and they 183 129 ITT). By syntactical translation, we mean an explicit transla- can be proven in ETT. Indeed, UIP can be shown to be equiv- 184 130 tion from a derivation Γ `x t : T of ETT (the x index testifies alent to the Streicher’s axiom K 185 0 0 131 that it is a derivation in ETT) to a context Γ , term t and 186 0 0 0 0 K : Π(A : □i ): Π(x : A): Π(e : x = x): e = reflx 132 type T of ITT such that Γ ` t : T in ITT.