 # Typal Heterogeneous Equality Types

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.

## Authors

##### 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).

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.

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 coe:∀{l}{AB:Setl}→A≡B→A→B satisfying a heterogeneous regularity property: coeIsRegular coeIsRegular:∀{l}{AB:Setl}(e:A≡B)(x:A)→coeex≡≡x

###### Proof.

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 Inj:∀{l}(AB:Setl)→Setl
InjAB=∑f∶(A→B),∀{xy}→fx≡fy→x≡y

id:∀{l}{A:Setl}→A→A
idx=x

idInj:∀{l}(A:Setl)→InjAA
idInj=(id,id) Next we use to define a function coercing equalities into injective functions: icoe icoe:∀{l}{AB:Setl}→A≡B→InjAB
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 fsticoe:∀{l}{A:Setl}(x:A)(B:Setl)(e:A≡B)→Setl
fsticoexBe=∑y∶B,(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 : 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: coeIsRegular{}{A}ex=tpt(λe′→coee′x≡≡x)e(ctre)coerfl
[@l@0]where
coerfl:coe(rflA)x≡x
coerfl=[795I]snd(icoe(rflA))(snd(
[795I][@l@0]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 uip:∀{l}{A:Setl}{xy:A}(ee′:x≡y)→e≡e′

axiomK:[828I]∀{lm}{A:Setl}{x:A}(P:x≡x→Setm)(p:P(rflx))→
[.][@l@][828I]∀e→Pe

axiomKComp:[851I]∀{lm}{A:Setl}{x:A}(P:x≡x→Setm)(p:P(rflx))→
[.][@l@][851I]axiomKPp(rflx)≡p

###### Proof.

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

axiomKPpe=coe(cong₂(λ→P)(rflp)(ctre))p

axiomKCompPp=proof
[@l@0]coe(cong₂(λ→P)(rflp)(ctr(rfl)))p
≡≡[cong(λe→coeep)(uip)]
[@l@0]coe(rfl)p
≡≡[coeIsRegularp]
[@l@0]p
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 ≡Elim:[937I]∀{lm}{A:Setl}{x:A}(P:(y:A)→x≡y→Setm)
[.][@l@][937I](p:Px(rflx))(y:A)(e:x≡y)→Pye
≡Comp:[971I]∀{lm}{A:Setl}{x:A}(P:(y:A)→x≡y→Setm)
[.][@l@][971I](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 ≡≡Elim:[1003I]∀{lm}{A:Setl}{x:A}(P:(B:Setl)(y:B)→x≡≡y→Setm)
[.][@l@][1003I](p:PAx(rflx))(B:Setl)(y:B)(e:x≡≡y)→PBye

≡≡Comp:[1044I]∀{lm}{A:Setl}{x:A}(P:(B:Setl)(y:B)→x≡≡y→Setm)
[.][@l@][1044I](p:PAx(rflx))→≡≡ElimPpAx(rflx)≡p

###### Proof.

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

≡CompPp=proof
[@l@0]coe(cong₂P(rfl)(ctr(rfl)))p
≡≡[cong(λe→coeep)(symm(ctr))]
[@l@0]coe(rfl)p
≡≡[coeIsRegularp]
[@l@0]p
qed

≡≡ElimPpe=coe(cong₃P(eqte)e(ctre))p

≡≡CompPp=proof
[@l@0]coe(cong₃P(eqt(rfl))(rfl)(ctr(rfl)))p
≡≡[cong(λe→coeep)(uip)]
[@l@0]coe(rfl)p
≡≡[coeIsRegularp]
[@l@0]p
[@l@0]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 ∑Elim:∀{lmn}{A:Setl}{B:A→Setm}(C:∑AB→Setn)
(c:(x:A)(y:Bx)→C(x,y))(z:∑AB)→Cz
∑ElimCcz=coe(congC(etaz))(c(fstz)(sndz))

∑Comp:∀{lmn}{A:Setl}{B:A→Setm}(C:∑AB→Setn)
(c:(x:A)(y:Bx)→C(x,y))(x:A)(y:Bx)→
∑ElimCc(x,y)≡cxy
∑CompCcxy=letz=(x,y)in
proof
[@l@0]coe(congC(etaz))(c(fstz)(sndz))
≡≡[coeIsRegular]
[@l@0]c(fstz)(sndz)
≡≡[cong₂c(fprxy)(sprxy)]
[@l@0]cxy
qed

## 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]moduleConsistencywhere
[@l@0]infix3,
infix4≡≡≡

– – without this ≡≡ would have to land in Set (lsuc l)
– {-# NOUNIVERSECHECK #-} data≡≡{l}{A:Setl}:{B:Setl}→A→B→Setlwhere
[@l@0]rfl:(x:A)→x≡≡x
data∑{lm}(A:Setl)(B:A→Setm):Set(l⊔m)where
[@l@0],:(x:A)→Bx→∑AB
– the derived homogeneous equality
≡:∀{l}{A:Setl}→A→A→Setl

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

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

eqt:∀{l}{AB:Setl}{x:A}{y:B}→x≡≡y→A≡B
eqt{}{A}(rfl)=rflA

tpt:[1425I]∀{lmn}{A:Setl}{B:A→Setm}(C:(x:A)→Bx→Setn)
[.][@l@][1425I]{xx′:A}{y:Bx}{y′:Bx′}→x≡x′→y≡≡y′→Cxy→Cx′y′
tpt(rfl)(rfl)y=y

module{lm}{A:Setl}{B:A→Setm}where
[@l@0]fst:∑AB→A
fst(x,)=x

snd:(z:∑AB)→B(fstz)
snd(,y)=y

fpr:(x:A)(y:Bx)→fst(x,y)≡x
fprx=rflx

spr:(x:A)(y:Bx)→snd(x,y)≡≡y
spry=rfly

eta:(z:∑AB)→(fstz,sndz)≡z
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

[hide]moduleAppendixwhere

In this appendix, for completeness sake we consider axioms for homogeneous equality types [@l@1]postulate
[@l@0]≡:∀{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: data∑{lm}(A:Setl)(B:A→Setm):Set(l⊔m)where
[@l@0],:(x:A)→Bx→∑AB
– concrete syntax for ∑-types
syntax∑A(λx→B)=∑x∶A,B
– dependent product projections
module{lm}{A:Setl}{B:A→Setm}where
[@l@0]fst:∑AB→A
fst(x,)=x
snd:(z:∑AB)→B(fstz)
snd(,y)=y The axioms for homogeneous equality are refl cntr sbst postulate
[@l@0]refl:∀{l}{A:Setl}(x:A)→x≡x
cntr:∀{l}{A:Setl}{xy:A}(e:x≡y)→(x,reflx)≡(y,e)
sbst:∀{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 : Inj:∀{l}(AB:Setl)→Setl
InjAB=∑f∶(A→B),∀{xy}→fx≡fy→x≡y

id:∀{l}{A:Setl}→A→A
idx=x

idInj:∀{l}(A:Setl)→InjAA
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 module{lm}{A:Setl}(B:A→Setm){x:A}where
[@l@0]Inj₂:{yz:A}→x≡y→x≡z→Inj(By)(Bz)
Inj₂{y}pq=
[@l@0]sbst(λz′→Inj(By)(Bz′))q
[@l@0](sbst(λy′→Inj(By′)(Bx))p(idInj(Bx)))

sbst₂:{yz:A}→x≡y→x≡z→By→Bz
sbst₂pq=fst(Inj₂pq)

C:{y:A}(p:x≡y)(b:Bx)→∑c∶By,(sbst₂ppc≡sbst₂(reflx)pb)
C[1894I]pb=sbstC′(cntrp)(b,refl)
[.][@l@][1894I]where
C′:∑y∶A,(x≡y)→Setm
C′(y,p)=∑c∶By,(sbst₂ppc≡sbst₂(reflx)pb)

subst:{y:A}→x≡y→Bx→By
substpb=fst(Cpb)

substIsRegular:(b:Bx)→subst(reflx)b≡b
substIsRegularb=snd(Inj₂(reflx)(reflx))(snd(C(reflx)b))

## References

• Agda Wiki (2019) Agda Wiki.
• 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.
• 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.
• 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.
• 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.