The Integers as a Higher Inductive Type

We consider the problem of defining the integers in Homotopy Type Theory (HoTT). We can define the type of integers as signed natural numbers (i.e., using a coproduct), but its induction principle is very inconvenient to work with, since it leads to an explosion of cases. An alternative is to use set-quotients, but here we need to use set-truncation to avoid non-trivial higher equalities. This results in a recursion principle that only allows us to define function into sets (types satisfying UIP). In this paper we consider higher inductive types using either a small universe or bi-invertible maps. These types represent integers without explicit set-truncation that are equivalent to the usual coproduct representation. This is an interesting example since it shows how some coherence problems can be handled in HoTT. We discuss some open questions triggered by this work. The proofs have been formally verified using cubical Agda.


Introduction
How to define the integers in Homotopy Type Theory? This can sound like a trivial question. The first answer is as signed natural numbers: Definition 1.1. Let Z w be the inductive type generated by the following constructors: -0 : Z w strpos : N → Z w strneg : N → Z w However, this type is very inconvenient in practice because it creates a lot of unnecessary case distinctions. Nuo [Li15] tried to prove distributivity of multiplication over addition, which resulted in a lot of cases. It is like working with normal forms only, when working with λ-terms.
Nuo shows that it is much better to work with a quotient type, representing integers as differences of natural numbers. That is, we define Z q = N × N/ ∼ where (x + , x − ) ∼ (y + , y − ) is defined as x + + y − = y + + x − 1 . However, this is not the end of the story. Here we use set-quotients, which can be implemented as a higher inductive type with a set-truncation constructor [Uni13, Section 6.10]. However, the set-truncation constructor implies that using its recursion principle we can only define functions into sets, which seems to be an unreasonable limitation when working in HoTT. For example, in the proof that the loop space of the circle is isomorphic to the integers [RLS13], we must map from the integers to the loop space of the circle, when we do not yet know that this will end up being a set.
We would like to have a definition of the integers which is convenient to work with (i.e., does not reduce them to normal forms) but which is not forced to be set-truncated by a set-truncation constructor. Paolo Capriotti suggested the following definition: Definition 1.2. Let Z h be the higher inductive type with the following constructors: -0 : Z h ; succ : Z h → Z h ; pred : Z h → Z h ; sec : (z : Z h ) → pred(succ(z)) = z; ret : (z : Z h ) → succ(pred(z)) = z; coh : (z : Z h ) → ap succ (sec(z)) = ret(succ(z)).
We add succ and pred as constructors, but then we postulate that they are inverse to each other using sec and ret. At this point we could add a set-truncation but then we would suffer from the same shortcoming as the definition using a set-quotient. However, we can add just one coherence condition coh which should look familiar to anybody who has read the HoTT book: indeed the constructors pred, sec, ret, and coh exactly say that succ is a half-adjoint equivalence [Uni13, Section 4.2]. More precisely, sec postulates that succ is a section, ret postulates that succ is a retraction, and coh represents the triangle identity in the definition of half-adjoint equivalence.
The question that now remains is the following. Is Z h a correct definition of the integers, in particular is it a set with decidable equality? The strategy to prove this is to define a normalisation function into the signed integers, Z w , and show that this normalisation function, together with the obvious embedding of Z w into Z h , forms an equivalence. It turns out that this is actually quite hard to prove, due to the presence of higher equalities, and nobody has so far been able to formally verify this.
In this paper, we follow the same idea but use a simpler definition of equivalence, namely bi-invertible maps [Uni13, Section 4.3]: Definition 1.3. Let Z b be the higher inductive type with the following constructors: In this case we postulate that succ has a left inverse, given by pred 1 and sec, and a right inverse, given by pred 2 and ret. The reason why Z b is simpler than Z h is because it only has 0-and 1-dimensional constructors. The higher coherence coh is not needed in this case for the same reason that a 2-dimensional constructor is not needed in the definition of bi-invertible map: having two, a priory, unrelated inverses makes the type of witnesses that a certain map is bi-invertible a proposition ([Uni13, Theorem 4.3.2]).
For this definition we can give a complete proof that Z b is equivalent to Z w , which has been formalized in cubical Agda. We remark that this has previously been verified by Evan Cavallo [Cav18] in RedTT [red19]. However, our approach to prove the equivalence is more general. Our main result is Theorem 2.4, which says that only the components witnessing the preservation of 0 and succ are relevant when comparing morphisms out of Z b .
Another presentation of the integers follows from directly implementing the idea that the integers can be specified as the initial type with an inhabitant and an equivalence: The problem is that this is not a standard definition of a higher inductive type because we state an equality of the type itself. However, this can be fixed by using a small universe: Definition 1.4. Define U : U and El : U → U inductively with the constructors: -z : U ; -q : z = z; -0 : El(z) Now, let Z U :≡ El(z).
While we can show that this is a set without using set-truncation, its recursion principle isn't directly amenable to recursive definitions of functions because even succ is not a constructor. On the other hand the fact that the integers are the loop space of the circle is a rather easy consequence of this definition.
The definition of the integers is also closely related to the free group, indeed as suggested in [KA18] we can define the free group over a type A by simply parametrizing all the constructors but 0: Definition 1.5. Given A : U , define F(A) inductively with the constructors: sec : (a : A) → (z : F(A)) → pred 1 (a, succ(a, z)) = z; ret : (a : A) → (z : F(A)) → succ(a, pred 2 (a, z)) = z; The integers arise as the special case Z = F(1). However, the normal forms get a bit more complicated because we must allow alternating sequences of succ and pred but only for different a : A. This means that a normalisation function is only definable for sets a : A with a decidable equality. The general problem of whether F(A) is a set, if A is, is still open -in [KA18] it is shown to be the case, if we 1-truncate the HIT.
The problem of defining the integers with convenient constructors, and adding only the right coherences to make it a set, can be seen as a simple instance of a more general class of coherence problems in HoTT. Another example that we have in mind is the intrinsic definition of the syntax of type theory as the initial category with families as developed in [AK16]. If we carry out this definition in HoTT, we need to set-truncate the syntax, but this stops us from interpreting the syntax in the standard model formed by sets. We hope that also in this case we can add the correct coherence laws and show that they are sufficient to deduce that the initial algebra is a set.
1.1. Contributions. We show that the definitions of the signed integers, Z w , the definition of the integers as a higher inductive type using bi-invertible maps, Z b , and the definition using a higher inductive-inductive type with a mini universe, Z U , are all equivalent (Theorem 4.7).
For Z b we establish some useful principles such as a recursion principle (Proposition 2.1) which only uses one predecessor, and an induction principle which says that to prove a predicate (i.e., a family of propositions), you only need to prove closure under 0, succ, and pred 1 (Proposition 2.2). This is sufficient to verify all algebraic properties of the integers, e.g., that the integers form a commutative ring. We have formalized [AS19] the constructions using cubical Agda [AMV19].
When formalizing the constructions involving Z b we developed the theory of bi-invertible maps in cubical Agda, which wasn't available. In particular, we prove that bi-invertible maps are equivalent to contractible-fibers maps [Uni13, Section 4.4], and the principle of equivalence induction for bi-invertible maps.
1.2. Related work. The claim that Z h is a set can be found in [AP18] but the proof was flawed: it relies on the assumption that we can ignore propositional parts of an algebra for a certain signature when constructing algebra morphisms, which is not the case in general (Example 6.1). Cavallo [Cav18] verified that Z b ≃ Z w in RedTT. Higher inductive representations of the integers are discussed in [BGvdW17] and it is shown there that Z h without the last constructor is not a set. [Kv19] also discuss [AP18] and note that it is a corollary of their higher Seifert-van Kampen theorem -however, they derive it from initiality not from the induction principle.
1.3. Background. We use Homotopy Type Theory as presented in the book [Uni13]. We adopt the following notational conventions.
If two terms a and b are definitionally equal, we write a ≡ b, and we reserve a = b to denote the type of propositional equalities between a and b.
Given a type A : U and a type family P : A → U , we write the corresponding Π-type as (a : A) → P (a), and the corresponding Σ-type as (a : A) × P (a).
Given a type A : U , a type family P : A → U , an equality e : a = b in A, and p : P (a), we denote the coercion of p along e by e * (p) : P (b). This is defined by induction on e.
A type is contractible if it has exactly one inhabitant. That is, given a type A : U , we define isContr(A) :≡ (a 0 : A) × ((a : A) → a = a 0 ). A type is a proposition if any two inhabitants are equal. That is, given a type A : An equivalence between types A and B is a map f : A → B together with a proof that The general syntax of Higher Inductive Inductive Types (HIITs) is specified in [KK19], where also the types of the eliminators are derived. In the informal exposition, and in the formalisation, we use the cubical approach to path algebra introduced in [LB15].
For the formalisation we use cubical Agda [AMV19] which is based on the cubical type theory of [CCHM18]. The development of HIITs in Agda is based on [CHM18].

Representing Z using bi-invertible maps
The type N of natural numbers is usually defined as the inductive type generated by an inhabitant 0 : N and an endomap succ : N → N. In this section, we define the integers Z b in a similar way. The idea is to give constructors that guarantee that we have 0 : Z b , succ : Z b → Z b , and that succ is an equivalence using bi-invertible maps, see Definition 1.3. To make it easy to work with this definition, we prove three theorems that let us: map out of Z b (Proposition 2.1), prove properties about Z b (Proposition 2.2), and recognise when two maps out of Z b are equal (Theorem 2.4). The result about mapping out of Z b is very simple, and follows immediately from the recursion principle of Z b .
Proposition 2.1 (recZsimp). Given a type T with an inhabitant t : T and two maps f : T → T , g : T → T , such that g is a left and right inverse of f , we get a map r : Z b → T such that r(0) ≡ t and r(succ(z)) ≡ f (r(z)), definitionally.
The next result is only slightly more involved.
Proposition 2.2 (indZsimp). Given a type family P : Proof. We use the induction principle of Z b . The main idea is that we do not have to check any coherences, since we are proving a proposition. Concretely, this means that we only have to provide inhabitants for the following types: P (0), (z : Z b ) → P (z) → P (succ(z)), (z : Z b ) → P (z) → P (pred 1 (z)), and (z : Z b ) → P (z) → P (pred 2 (z)). For the first three we just use the assumptions. For the fourth one, we make use of the fact that, for every z : Z b , there is an equality pred 1 (z) = pred 2 (z). This is because pred 2 (z) = pred 1 (succ(pred 2 (z))) = pred 1 (z) using sec and then ret.
The result that allows us to compare maps out of Z b is considerably more complicated to prove. In order to explain its proof, we need to talk about bi-invertible maps.
The type of bi-invertible structures on such a map f is denoted by isBiInv(f ). The type Whenever we have f : A ≃ b B, we will abuse notation, and write f : A → B for the underlying function of the bi-invertible map f .
Notice that the constructors succ, pred 1 , pred 2 , sec, and ret form a bi-invertible map. Suppose given a type T with an inhabitant t : T and a bi-invertible map s : T ≃ b T . The recursion principle of Z b gives us rec Z b (T, t, s) : Z b → T . Now, assume given another map f : Z b → T . What do we have to check to be able to conclude that f = rec Z b (T, t, s)?
The following theorem gives a simple answer to the question and is the main focus of this section.
Theorem 2.4 (uniquenessZ). Given a type T , an inhabitant t : T , a bi-invertible map s : T ≃ b T , and a map f : In order to prove Theorem 2.4 we must study the preservation of bi-invertible maps, which we introduce next.
Fix types A, B, A ′ , B ′ : U , bi-invertible maps e : A ≃ b B and e ′ : A ′ ≃ b B ′ , and maps α : A → A ′ and β : B → B ′ : We now define what it means for α and β to respect e and e ′ . By a slight abuse of notation, let the bi-invertible maps e and e ′ be given by (e, g, h, s, r) and (e ′ , g ′ , h ′ , s ′ , r ′ ).
Definition 2.5. We define the type prBiInv(e, e ′ , α, β) as the iterated Σ-type with the following fields: -(preservation of e) p e : e ′ • α = β • e; -(preservation of g) p g : -(preservation of s) p s : (a : A) → s ′ (α(a)) = ap g ′ (p e a) p g (e(a)) ap α (s(a)); -(preservation of r) p r : The next proposition follows from the initiality of Z b , although it is a bit involved to prove formally using the constructors and the induction principle. Proof. We write g for rec Z b (T, t, s). By function extensionality, it is enough to construct a term r : Π x:Z b f (x) = g(x). We do this using the induction principle. The case for 0 follows directly from the assumption f (0) = t, and r(succ(x)) = ap s (g(x)) and the corresponding equalities for pred 1 and pred 2 follow directly from the assumption that f respect the bi-invertible maps succ and s.
It remains to check the cases of sec and ret. Since these are symmetric, we only describe the case of sec. In this case, we have to provide a filler for the following square of equalities: This filler can be obtained by filling the cube in figure 1, as follows. All the sides apart from the square in question can be filled using the fact that f preserves the bi-invertible maps, and simple path algebra, so we can conclude the proof using the Kan filling property of cubes: any open box can be filled.
Given a type A : U , let id A : A → A be the identity function. We have idb A : isBiInv(id A ), so we can define a map toBiInv : A = B → A ≃ b B by path induction, sending refl : A = A to idb A . By [Uni13,Corollary 4.3.3] and the univalence axiom, the map toBiInv is an equivalence. Let toEq : A ≃ b B → A = B be its inverse.
From this we can derive the principle of (based) equivalence induction, which we now state.
Lemma 2.7 (BiInduction). Fix a type A : U and a type family P : Proof. This is proven by path induction, after translating bi-invertible maps to equalities, using toEq and toBiInv.
Using equivalence induction, and singleton elimination, one can finally prove that a map between types together with bi-invertible maps that respects the maps, automatically respects the bi-invertible structure.
Proof. We use equivalence induction (Lemma 2.7) for e and e ′ and then observe that the type prBiInv((id, idb), (id, idb), α, β) is equivalent to the type of equalities α = β.
Proof of Theorem 2.4. The theorem is a corollary of Proposition 2.6 and Lemma 2.8.
One should notice that Lemma 2.8 can be proven directly, avoiding the usage of the univalence axiom (which was used to prove that toBiInv is an equivalence). The reason why we don't do this, is because the path algebra involved in proving Lemma 2.8 directly is non-trivial.

Z is a set
In this section we relate Z b with the usual definition of the integers as signed natural numbers, which we call Z w . We show that Z b ≃ Z w , and since we already know that Z w is a set, we deduce that Z b is a set too.
Definition 3.1. Let Z w be the inductive type with the following constructors: Proof. On the one hand, one can define succ w : Z w → Z w by induction, by mapping: -0 → strpos(0); strpos(n) → strpos(succ(n)); strneg(0) → 0; strneg(succ(n)) → strneg(n). Similarly one defines pred w . The fact that pred w provides a left and right inverse for succ w is straightforward. So, by Proposition 2.1 we get a map nf : Z b → Z w . On the other hand, it is easy to construct a map i : Z w → Z b by induction.
Induction on Z w shows that nf • i = id Zw . The hard part is to show that i • nf = id Z b . This is where Theorem 2.4 comes in handy. Theorem 2.4 implies that it is enough to check that (i • nf)(0) = 0 and that succ • (i • nf) = (i • nf) • succ, and this follows directly by construction.

Representing Z using a universe
In this section we give another definition of the integers, denoted by Z U , which allows one to easily prove that they are the initial type together with an inhabitant and an equality from the type to itself.
To make sense of initiality, we first define the type of Z-algebras and of Z-algebra morphisms.
Definition 4.1. A Z-algebra is a type T : U together with an inhabitant t : T , and an equality e : T = T . We denote such a Z-algebra as (T, t, e), or T if the rest of the structure can be inferred from the context. Definition 4.2. A morphism of Z-algebras from (T, t, e) to (T ′ , t ′ , e ′ ) is given by a map f : T → T ′ , together with an equality f (t) = t ′ , and a proof that e * (f ) = e ′ * (f ). We denote the type of morphisms of Z-algebras between T and T ′ by T → Z T ′ .
We are interested in initial Z-algebras.
Definition 4.3. A initial Z-algebra is a Z-algebra (T, t, e) such that for any other Zalgebra (T ′ , t ′ , e ′ ) the type T → Z T ′ is contractible.
See Definition 1.4 for the definition of the initial Z-algebra using a mini universe 2 . Then define an interpretation function El : U → U , as the higher inductive family with only one constructor 0 : El(z). Define the type Z U :≡ El(z). The type Z U has the structure of a Z-algebra, since we have 0 : Z U and s :≡ ap El (q) : Z U = Z U . The following result follows by a routine application of the induction principle of Z U .
In particular, we have.
Proposition 4.5. Given a type T with an inhabitant t : T and an equality e : T = T , we get a morphism of Z-algebras Z U → T .
Again, comparing maps out of Z U is easy, thanks to the following theorem. Analogously to the case of Z b , this is proven by combining the initiality of Z U with the fact that to preserve an equality in the universe e : T = T , it is enough to commute with its corresponding coercion function e * : T → T .
Following the argument given in Section 3, one deduces the following.
Theorem 4.7. There is an equivalence Z U ≃ Z w .
We omit the proof since it is basically the same as the construction presented in [RLS13] when proving that the integers are the loop space of the circle. Indeed, the mini universe U is nothing but the higher inductive type presentation of the circle S 1 of [Uni13, Section 6.1], so that (z = z) ≡ ΩS 1 . Moreover, the type family El is equivalent to the path space fibration of the circle, in the following sense. Proof. We construct a map ed(u) : El(u) → (z = u) using induction on U and mapping 0 : El(z) to refl z , To construct a map going the other way, we use path induction and map refl z to 0. It is then straightforward to see that these maps give an equivalence as in the statement.
As a corollary, we obtain the well-known equivalence between the loop space of the circle and the integers.
This suggests that alternatively one could view the representation of the integers as a universe as an inductive-inductive presentation of the circle equipped with a family that has a point in the fiber over the base point.

Formalization in cubical Agda
We formally checked the results of this paper [AS19] using cubical Agda [AMV19]. There are two differences between the informal presentation in the paper and the formalisation. The first one is that the presentation in the paper is done using book-HoTT [Uni13], whereas the formalisation is done using a cubical type theory. In this case, this difference is not important, since it is easy to translate the formalized arguments to book-HoTT.
The real difference is in the definition of higher inductive types. In the paper we define higher inductive types as initial algebras for a certain signature (Section 1.3). In the formalisation, we use higher inductive types as implemented in cubical Agda, which are based on [CHM18]. Although it is natural to assume that the Agda higher inductive type should be initial in the sense of Section 1.3, proving this fact is actually one of the main difficulties in the formalisation (Proposition 2.6).
In proving the results of Section 2, we developed the theory of bi-invertible maps in cubical Agda, which wasn't available. We prove that the type of bi-invertible maps between A and B is equivalent to the type of equivalences between A and B, and the principle of bi-invertible induction.

Open questions
Preservation of properties. The key result in the above discussion is Lemma 2.8, which can be reformulated as follows. Let T, T ′ : U , s : T → T , s ′ : T ′ → T ′ , φ : isBiInv(s), and φ ′ : isBiInv(s ′ ). We can define the following two types of morphisms between T and T ′ : Informally, Map end (T, T ′ ) is the type of maps that respect the endomorphism, and Map biInv (T, T ′ ) is the type of maps that respect the endomorphism and the proof that the endomorphism is a bi-invertible map.
We have a forgetful map Map biInv (T, T ′ ) → Map end (T, T ′ ), and what Lemma 2.8 says is that this map is an equivalence.
There is something special about the type family isBiInv : (A → B) → U , and that is that it is valued in propositions. One might wonder if Lemma 2.8 is a general principle, in the following sense. Say that we have a signature S for a type of algebras, and we extend it to a signature S ′ , such that the fields we added take values in propositions. In the above example S corresponds to (T : U )(f : T → T ) and S ′ corresponds to the extension (T : U )(f : T → T )(φ : isBiInv(s)). As usual, given S ′ -algebras T, T ′ , we have a forgetful map Map S ′ (T, T ′ ) → Map S (T, T ′ ). Is this map an equivalence in general?
The following example, suggested by Paolo Capriotti, shows that this is not necessarily the case. The S-algebras are the types with a binary operation, and the S ′ -algebras are the sets with a binary operation with a distinguished element that is a left and right unit.
The extension S ′ is propositional. This is because being a set is a proposition ([Uni13, Theorem 7.1.10]), so tr inhabits a proposition, two left and right units must necessarily coincide, so e inhabits a proposition (assuming u), and the identity types of a set are propositions and these are closed under pi-types ([Uni13, Theorem 7.1.9]), so u inhabits a proposition (assuming tr).
Let us see that for S ′ -algebras T, T ′ the forgetful map Map S ′ (T, T ′ ) → Map S (T, T ′ ) is not an equivalence in general. Let T be (N, +, φ, 0, ψ), where φ is a proof that the natural numbers form a set, and ψ is a proof that 0 is a left and right unit for +. Let T ′ be (bool, ∨, φ ′ , ⊥, ψ ′ ), where φ ′ is a proof that the booleans form a set, and φ is a proof that ⊥ is a left and right unit for ∨. Then we have λn.⊤ : N → bool. This map clearly respects the operations, so we get an inhabitant of Map S (T, T ′ ). But this morphism does not respect the units, so it cannot come from a morphism in Map S ′ (T, T ′ ).
This discussion leaves open an interesting question.
Question 6.2. Given a signature S and a propositional extension S ′ , are there useful necessary and sufficient conditions for the forgetful map Map S ′ (T, T ′ ) → Map S (T, T ′ ) to be an equivalence for every pair of S ′ -algebras T and T ′ ?
Initiality of HIITs. Our original goal was to complete the conjectured result from [AP18] and formally verify that Z h is a set. Using the strategy from this paper this is fairly straightforward: we can show that the natural notion of morphism of Z h -algebras satisfies a principle analogous to Lemma 2.8, and hence that Z h is a set. When attempting to formalize this construction we hit an unexpected problem: it turns out that it is rather difficult to verify that the higher inductive type defining Z h is initial in its corresponding wild category of algebras. Specifically, the proof seems to require the construction of a filler for a 4-dimensional cube which is rather laborious. In [KKA19] it is shown that for QIITs (i.e., set-truncated HIITs) elimination and initiality are equivalent, but the extension to higher dimensional HIITs seems non-trivial. In particular it may require developing the higher order categorical structure of the category of algebras.