Typal Heterogeneous Equality Types

07/17/2019 ∙ by Andrew M. Pitts, et al. ∙ 0

The usual homogeneous form of equality type in Martin-Löf Type Theory contains identifications between elements of the same type. By contrast, the heterogeneous form of equality contains identifications between elements of possibly different types. This paper introduces a simple set of axioms for such types. The axioms are equivalent to the combination of systematic elimination rules for both forms of equality, albeit with typal (also known as "propositional") computation properties, together with Streicher's Axiom K, or equivalently, the principle of uniqueness of identity proofs.



There are no comments yet.


page 1

page 2

page 3

page 4

This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

1 Introduction

Equality types in the intensional version of Martin-Löf Type Theory (see for example Nordström et al., 1990, Section 8.1) are traditionally formulated in terms of an introduction rule (reflexivity) together with a rule for eliminating proofs of equality and a rule describing how elimination computes when it meets a reflexivity proof. Some recent work (Bezem et al., 2014; Cohen et al., 2018) on models of Homotopy Type Theory (Univalent Foundations Program, 2013) uses a formulation of equality types that differs from this in two respects. First, the elimination operation is replaced by the combination of a simple operation for transporting elements along proofs of equality, together with an axiom asserting contractibility of singleton types. Secondly, the analogue of the computation rule for the eliminator, namely that transporting along a reflexivity proof does nothing, is weakened from a judgemental equality to the existence of an element of the corresponding equality type; see Coquand (2011) and Figure 2 in (Bezem et al., 2014). This formulation is sometimes called a “propositional” equality type (van den Berg, 2018), but here I will follow Shulman (2017, Section 1.6) for the reasons given there and refer to typal equality types. Although these changes to the formulation of equality types affect computation, they do not change what is provable and they make it easier to construct models. Furthermore, they can lead to surprising simplifications. For example, Lumsdaine [private communication] has observed that the computation rule is superfluous (for elimination, but the observation also holds for transport): if a proto-identity type has a transport operation lacking its typal computation property, then the operation can be corrected to a new one that does have the computation property (see Lemma 2.1 and the Appendix).




Axioms for typal heterogeneous equality satisfying Axiom K

≡≡ ≡ rfl ctr eqt tpt ∑ _,_ fst snd fpr spr eta


[2]– the derived homogeneous equality


Axioms for -types with surjective pairing


[2]module{lm}{A:Setl}{B:A→Setm}where [hide][2][@l@1][4]infix3, [4]postulate

[2]– concrete syntax for ∑-types

Figure 1: The Axioms

The above remarks apply to the usual, homogeneous notion of equality in which elements of the same type are compared. The purpose of this paper is to give an analogous treatment of heterogeneous equality (McBride, 1999) in the presence of -types and the Axiom K of Streicher (1993, Section 1.2). Since Axiom K is not compatible with the Univalence Principle of Homotopy Type Theory (Univalent Foundations Program, 2013, Example 3.1.9), the focus here is on the simpler (but still useful!) world of zero-dimensional type theory. The pleasingly simple collection of axioms given in Fig. 1 turns out to capture both homogeneous and heterogeneous equality, Axiom K and -types. It seems necessary to include -types in order to get Lumsdaine’s result mentioned above (see Remark2.5). The axioms we give for such types are familiar, but at least the equality property of dependent second projection (spr) is simplified by the use of heterogeneous rather than homogeneous equality.

The implementation of intensional Martin-Löf Type Theory provided by Agda 2.6 (Agda Wiki, 2019) is used to state the axioms and develop their properties. More precisely, we just make use of Agda’s implementation of a countably infinite, non-cumulative hierarchy of universes , where ranges over a type of universe levels whose closed normal forms are in bijection with the natural numbers. The universes are closed under dependent function types (written in Agda as ) and inductive types. The use of a whole hierarchy of unverses is necessary; for example, the function in Fig. 1 takes a heterogeneous equality type in universe and produces a homogeneous one in the universe one level up, which is denoted in Agda. We also use Agda’s notation for infix and for implicit arguments. For example, the function in Fig. 1 takes five arguments, the first three of which are implicit and the last two of which are infix. In particular, Agda’s ability to infer the values of implicit arguments (or of unspecified explicit arguments, which are denoted by an underscore, ) is used quite aggressively in what follows, in order to be able to see the wood from the trees.

Although the code in this paper has been checked by Agda, some parts of it that are not essential for understanding the development have been hiden; the complete (non-literate) Agda code can be found at [http://www.cl.cam.ac.uk/~amp12/agda/typhet.html].

2 The axioms and their properties

Figure 1 postulates a family of types in all universes, together with some operations on them that together capture a typal version of heterogeneous equality. Heterogeneous equality types were introduced by McBride (1999, Section 5.1.3) under the name of “John Major equality”. Unlike ordinary, homogeneous equality types, such a type relates elements and of possibly different types, and say. The intention is that elements of type denote proofs that not only are and equal, but so also are their types and . The figure defines homogeneous equality as the special case of when the types of the two arguments are already known to be the same. Axiom  says that is reflexive. Axiom  is a heterogeneous version of the contractibility property of singleton types (cf.  in Figure 2 of Bezem et al. (2014)). Axiom  says that heterogeneously equal things have (homogeneously) equal types. Axiom  is a form of the transport property of equality (cf.  in Figure 2 of Bezem et al. (2014)) involving both homogeneous and heterogeneous equalities. Finally, , , , , , and axiomatise dependent product types satisfying surjective pairing.

symm proof_ _≡≡[_]_ _qed cong cong₂ cong₃ [2]symm:∀{l}{AB:Setl}{x:A}{y:B}→x≡≡y→y≡≡x







Figure 2: Equational reasoning for heterogeneous equality

We begin with some simple lemmas establishing the basics of equational logic for , namely chain-reasoning using reflexivity (already an axiom), symmetry, transitivity and congruence properties. These are given in Fig. 2.

The axioms in Fig. 1 are notably lacking a “regularity” property for , that is, a proof of type . But such a thing is needed if we are to derive the expected elimination and (typal) computation rules for and . To get those, one can define a “corrected” form of transport that has this regularity property, using a simplified version of a trick due to Peter Lumsdaine [unpublished]. In fact, it is enough to produce a function coercing proofs of equality of types into functions and which satisfies the heterogeneous regularity property that (so that, given how we define in terms of , the usual form of regularity, , is just the special case of this when is ).

Lemma 2.1.

The axioms in Fig. 1 imply the existence of a coercion function coe [2]coe:∀{l}{AB:Setl}→A≡B→A→B satisfying a heterogeneous regularity property: coeIsRegular [2]coeIsRegular:∀{l}{AB:Setl}(e:A≡B)(x:A)→coeex≡≡x


First we define the type of functions that are injective with respect to and note that the identity function is one such: Inj id idInj [2]Inj[12]:∀{l}(AB:Setl)→Setl

[2]idInj[12]=(id,id) Next we use to define a function coercing equalities into injective functions: icoe [2]icoe:∀{l}{AB:Setl}→A≡B→InjAB
[2]icoe{l}{A}e=tpt(λC→InjAC)(rfl(Setl))e(idInjA) The injectiveness of is used as follows. Applying the operation to the type family fsticoe [2]fsticoe:∀{l}{A:Setl}(x:A)(B:Setl)(e:A≡B)→Setl
[2]fsticoexBe=∑y∶B[27],(fst(icoe(rflB))y≡fst(icoee)x) we can transport the element of type along and to give an element of type . The first projection of this element gives the value of the desired coercion along at : [2]coeex=fst(tpt(fsticoex)e(ctre)(x,rfl)) and its second projection can be used along with the injectiveness property of to get the regularity property of this coercion: [2]coeIsRegular{}{A}ex=tpt(λe′→coee′x≡≡x)e(ctr[66]e)coerfl
[795I][@l@0][15]tpt(fsticoex)(rflA)(ctr(rflA))(x,rfl))) ∎

An immediate corollary is that the axioms imply the uniqueness of identity proofs (UIP) and hence Streicher’s Axiom K (Streicher, 1993). (We will see in Sect. 3 that in fact it is only the function that contains an implicit use of Axiom K.)

Theorem 2.2 (UIP and Axiom K).

The axioms in Fig. 1 imply that satisfies uip axiomK axiomKComp [2]uip[14]:∀{l}{A:Setl}{xy:A}(ee′:x≡y)→e≡e′



Using the functions from Fig 2 and Lemma 2.1 we have: [2]uipee′[18]=tpt(λe′′→e′′≡≡e′)e(ctre)(ctre′)


[21]qed ∎

The elimination and computation properties of and then follow:

Theorem 2.3 (Elimination and typal computation properties).

The axioms in Fig. 1 imply that has the usual elimination and (typal) computation properties of homogeneous equality (in the form suggested by Paulin-Mohring (1993)) ≡Elim ≡Comp [2]≡Elim:[937I]∀{lm}{A:Setl}{x:A}(P:(y:A)→x≡y→Setm)
[.][@l@][971I][10](p:Px(rflx))→≡ElimPpx(rflx)≡pThe axioms also imply that has the elimination and (typal) computation properties of heterogeneous equality described by McBride (1999, Section 5.1.3) ≡≡Elim ≡≡Comp [2]≡≡Elim[10]:[1003I]∀{lm}{A:Setl}{x:A}(P:(B:Setl)(y:B)→x≡≡y→Setm)


Using the functions from Fig 2 and Lemma 2.1 we have: [2]≡ElimPpe[21]=coe(cong₂Pe(ctre))p



[21][@l@0][23]qed ∎

Note that a corollary of the above two theorems is that is uniquely determined up to bijection by the axioms in Fig. 1. In other words, for any other such family of types , there are functions in either direction between and ; and because of UIP these are necessarily mutually inverse up to (or ).

Remark 2.4.

is the elimination form systematically derived (Backhouse et al., 1989) from and , regarding them as the formation and introduction rules for an inductive type. As McBride (1999, page 120) points out, is not very useful, because of the way it’s motive involves abstraction over an arbitrary type . McBride goes on to give another, more useful form of elimination for , but in our setting where is a special case of , that coincides with the eliminator .

Remark 2.5 (The role of -types).

One of the strengths of machine-checked mathematics is that it aids the detection of logical dependency. Although we included the equations , and for -types in Fig. 1, they have not been used for the results so far, as may be verified by commenting them out from this literate Agda file and re-checking it up to this point.

So only the weak form of dependent product given by , , and in the figure is used to define the regular version of coercion in Lemma 2.1 and then prove Theorems 2.2 and 2.3. It would be nice if there was some way to define , , and just using dependent function types and universes.

However, the extra equations , and for are of course very natural. Let us record the fact that they enable one to define the usual elimination rule for dependent products, with a typal computation rule: ∑Elim ∑Comp [2]∑Elim[17]:[20]∀{lmn}{A:Setl}{B:A→Setm}(C:∑AB→Setn)

3 Consistency of the axioms

We have seen that the axioms in Fig. 1 suffice to define dependent products and both heterogeneous and homogeneous equality types with uniqueness of identity proofs, all satisfying the usual elimination properties, albeit with typal computation rules. Conversely it is not hard to see that the elimination and computation rules in Theorem 2.3 and Remark 2.5, together with Axiom K, imply the axioms in Fig. 1. Instead of doing that, in this section we just check that the axioms are provable from inductive definitions of equality and dependent product types. One can make these inductive definitions in Agda as follows: [hide][0]moduleConsistencywhere
[2]– – without this ≡≡ would have to land in Set (lsuc l)
[2]– {-# NOUNIVERSECHECK #-} [2]data≡≡{l}{A:Setl}:{B:Setl}→A→B→Setlwhere
[2]– the derived homogeneous equality

[2]x≡y=x≡≡y Then Agda’s implementation of dependent pattern matching enables straightforward definitions of the functions from Fig. 

1, as follows: [2]ctr:∀{l}{AB:Setl}{x:A}{y:B}(e:x≡≡y)→rflx≡≡e

[4]eta(x,y)=rfl(x,y) Since we know from the previous section that these functions entail Axiom K, the above definitions have to use Agda’s default --with-K option to switch the existing implementation of dependent pattern matching (Cockx and Abel, 2018) back to the original version due to Coquand (1992), which is known to imply Axiom K (Goguen et al., 2006). More precisely, it is only the match on the first occurrence of the pattern in the definition of that involves an implicit use of Axiom K (to discharge the unification constraint ); all the other functions can be defined without Axiom K.

4 Conclusion

This paper has investigated heterogeneous equality and produced a simple collection of axioms for its typal form, in the spirit of Coquand (2011). The point of view is foundational. From a practical perspective, the use of heterogeneous equality has much to recommend it for formalizing mathematics in dependent type theory when assuming uniqueness of identity proofs111Such is the approach of Lean (The Lean Theorem Prover, 2019) since version 3, for example.; but that is another story.

Appendix: typal homogeneous equality without K


In this appendix, for completeness sake we consider axioms for homogeneous equality types [0][@l@1][2]postulate
[2][@l@0][4]≡:∀{l}{A:Setl}→A→A→Setl in dependent type theory without Axiom K, following Coquand (2011). One of the axioms makes use of dependent product types. Although one could axiomatize those types as we did in the main part of the paper, it is simpler to use an inductive defintion and corresponding pair patterns: [2]data∑{lm}(A:Setl)(B:A→Setm):Set(l⊔m)where
[2]– concrete syntax for ∑-types
[2]– dependent product projections
[4]snd(,y)=y The axioms for homogeneous equality are refl cntr sbst [2]postulate
[4]sbst[10]:∀{lm}{A:Setl}(B:A→Setm){xx′:A}→x≡x′→Bx→Bx′ Coquand also considers a regularity axiom for ( in loc.cit.), but one can do without that by using Peter Lumsdaine’s trick to correct to a version for which there is a proof , as follows. The proof begins as for Lemma 2.1 by considering functions that are injective modulo : [2]Inj:∀{l}(AB:Setl)→Setl
[2]idInj=(id,id) But then to construct and , one has to work a bit harder than in the proof of the lemma, because of the lack of uniqueness of identity proofs: subst substIsRegular [2]module{lm}{A:Setl}(B:A→Setm){x:A}where





  • Agda Wiki (2019) Agda Wiki. https://wiki.portal.chalmers.se/agda/pmwiki.php, 2019.
  • Backhouse et al. (1989) R. Backhouse, P. Chisholm, G. Malcolm, and E. Saaman. Do-it-yourself type theory. Formal Aspects of Computing, 1:19–84, 1989.
  • Bezem et al. (2014) M. Bezem, T. Coquand, and S. Huber. A model of type theory in cubical sets. In R. Matthes and A. Schubert, editors, 19th International Conference on Types for Proofs and Programs (TYPES 2013), volume 26 of Leibniz International Proceedings in Informatics (LIPIcs), pages 107–128, Dagstuhl, Germany, 2014. Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik.
  • Cockx and Abel (2018) J. Cockx and A. Abel. Elaborating dependent (co)pattern matching. Proc. ACM Program. Lang., 2(ICFP):75:1–75:30, July 2018. ISSN 2475-1421. URL http://doi.acm.org/10.1145/3236770.
  • Cohen et al. (2018) C. Cohen, T. Coquand, S. Huber, and A. Mörtberg. Cubical type theory: A constructive interpretation of the univalence axiom. In T. Uustalu, editor, 21st International Conference on Types for Proofs and Programs (TYPES 2015), volume 69 of Leibniz International Proceedings in Informatics (LIPIcs), pages 5:1–5:34, Dagstuhl, Germany, 2018. Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik. URL http://drops.dagstuhl.de/opus/volltexte/2018/8475.
  • Coquand (1992) T. Coquand. Pattern matching with dependent types. In B. Nordström, K. Petersson, and G. D. Plotkin, editors, Proceedings of the 1992 Workshop on Types for Proofs and Programs, Båstad, Sweden, pages 66–79, June 1992.
  • Coquand (2011) T. Coquand. Equality and dependent type theory. A talk given for the 24th AILA meeting, Bologna (http://www.cse.chalmers.se/~coquand/bologna.pdf), February 2011.
  • Goguen et al. (2006) H. Goguen, C. McBride, and J. McKinna. Eliminating dependent pattern matching. In K. Futatsugi, J.-P. Jouannaud, and J. Meseguer, editors, Algebra, Meaning, and Computation: Essays dedicated to Joseph A. Goguen on the Occasion of His 65th Birthday, pages 521–540. Springer Berlin Heidelberg, Berlin, Heidelberg, 2006. URL https://doi.org/10.1007/11780274_27.
  • McBride (1999) C. McBride. Dependently Typed Functional Programs and their Proofs. PhD thesis, University of Edinburgh, 1999.
  • Nordström et al. (1990) B. Nordström, K. Petersson, and J. M. Smith. Programming in Martin-Löf’s Type Theory. Oxford University Press, 1990.
  • Paulin-Mohring (1993) Chr. Paulin-Mohring. Inductive definitions in the system Coq; rules and properties. In M. Bezem and J. F. Groote, editors, Typed Lambda Calculus and Applications, volume 664 of Lecture Notes in Computer Science, pages 328–345. Springer-Verlag, Berlin, 1993.
  • Shulman (2017) M. Shulman. Brouwer’s fixed-point theorem in real-cohesive homotopy type theory. Mathematical Structures in Computer Science, pages 1–86, 2017.
  • Streicher (1993) T. Streicher. Investigations into Intensional Type Theory. Habilitation thesis, Ludwig Maximilian University, Munich, 1993.
  • The Lean Theorem Prover (2019) The Lean Theorem Prover. https://leanprover.github.io, 2019.
  • Univalent Foundations Program (2013) The Univalent Foundations Program. Homotopy Type Theory: Univalent Foundations for Mathematics. http://homotopytypetheory.org/book, Institute for Advanced Study, 2013.
  • van den Berg (2018) B. van den Berg. Path categories and propositional identity types. ACM Trans. Comput. Logic, 19(2):15:1–15:32, June 2018. URL http://doi.acm.org/10.1145/3204492.