The Integers as a Higher Inductive Type
Abstract.
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.
1. 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 be the inductive type generated by the following constructors:
-
–
-
–
-
–
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 where is defined as 111This is actually the definition in [Uni13].. 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 be the higher inductive type with the following constructors:
-
–
;
-
–
;
-
–
;
-
–
;
-
–
;
-
–
.
We add and as constructors, but then we postulate that they are inverse to each other using and . 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 which should look familiar to anybody who has read the HoTT book: indeed the constructors , , , and exactly say that is a half-adjoint equivalence [Uni13, Section 4.2]. More precisely, postulates that is a section, postulates that is a retraction, and represents the triangle identity in the definition of half-adjoint equivalence.
The question that now remains is the following. Is 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, , and show that this normalisation function, together with the obvious embedding of into , 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 be the higher inductive type with the following constructors:
-
–
;
-
–
;
-
–
;
-
–
;
-
–
;
-
–
;
In this case we postulate that has a left inverse, given by and , and a right inverse, given by and . The reason why is simpler than is because it only has - and -dimensional constructors. The higher coherence is not needed in this case for the same reason that a -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 is equivalent to , 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 and are relevant when comparing morphisms out of .
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 and inductively with the constructors:
-
–
;
-
–
;
-
–
Now, let .
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 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 by simply parametrizing all the constructors but :
Definition 1.5.
Given , define inductively with the constructors:
-
–
;
-
–
;
-
–
;
-
–
;
-
–
;
-
–
;
The integers arise as the special case . However, the normal forms get a bit more complicated because we must allow alternating sequences of and but only for different . This means that a normalisation function is only definable for sets with a decidable equality. The general problem of whether is a set, if is, is still open — in [KA18] it is shown to be the case, if we -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, , the definition of the integers as a higher inductive type using bi-invertible maps, , and the definition using a higher inductive-inductive type with a mini universe, , are all equivalent (Theorem 4.7).
For 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 , , and (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 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 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 in RedTT. Higher inductive representations of the integers are discussed in [BGvdW17] and it is shown there that 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 and are definitionally equal, we write , and we reserve to denote the type of propositional equalities between and .
Given a type and a type family , we write the corresponding -type as , and the corresponding -type as .
Given a type , a type family , an equality in , and , we denote the coercion of along by . This is defined by induction on .
A type is contractible if it has exactly one inhabitant. That is, given a type , we define . A type is a proposition if any two inhabitants are equal. That is, given a type , we define , [Uni13, Definition 3.3.1]. A type is a set if it satisfies UIP. That is, given a type , we define , [Uni13, Definition 3.1.1].
An equivalence between types and is a map together with a proof that . The type of equivalences between and is denoted by .
2. Representing using bi-invertible maps
The type of natural numbers is usually defined as the inductive type generated by an inhabitant and an endomap . In this section, we define the integers in a similar way. The idea is to give constructors that guarantee that we have , , and that 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 (Proposition 2.1), prove properties about (Proposition 2.2), and recognise when two maps out of are equal (Theorem 2.4).
The result about mapping out of is very simple, and follows immediately from the recursion principle of .
Proposition 2.1 (recsimp).
Given a type with an inhabitant and two maps , , such that is a left and right inverse of , we get a map such that and , definitionally.
The next result is only slightly more involved.
Proposition 2.2 (indsimp).
Given a type family such that , if we have , , and , then it follows that .
Proof.
We use the induction principle of . 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: , , , and . For the first three we just use the assumptions. For the fourth one, we make use of the fact that, for every , there is an equality . This is because using and then . ∎
The result that allows us to compare maps out of is considerably more complicated to prove. In order to explain its proof, we need to talk about bi-invertible maps.
Definition 2.3.
A map between types is a bi-invertible map if there exist , and homotopies and .
The type of bi-invertible structures on such a map is denoted by . The type is denoted by .
Whenever we have , we will abuse notation, and write for the underlying function of the bi-invertible map .
Notice that the constructors , , , , and form a bi-invertible map. Suppose given a type with an inhabitant and a bi-invertible map . The recursion principle of gives us . Now, assume given another map . What do we have to check to be able to conclude that ?
The following theorem gives a simple answer to the question and is the main focus of this section.
Theorem 2.4 (uniqueness).
Given a type , an inhabitant , a bi-invertible map , and a map , if and then .
In order to prove Theorem 2.4 we must study the preservation of bi-invertible maps, which we introduce next.
Fix types , bi-invertible maps and , and maps and :
We now define what it means for and to respect and . By a slight abuse of notation, let the bi-invertible maps and be given by and .
Definition 2.5.
We define the type as the iterated -type with the following fields:
-
–
(preservation of ) ;
-
–
(preservation of ) ;
-
–
(preservation of ) ;
-
–
(preservation of ) ;
-
–
(preservation of ) .
The next proposition follows from the initiality of , although it is a bit involved to prove formally using the constructors and the induction principle.
Proposition 2.6 (uniqueness).
Suppose given a type with an inhabitant , a bi-invertible map , and a map . If and , then .
Proof.
We write for . By function extensionality, it is enough to construct a term . We do this using the induction principle. The case for follows directly from the assumption , and and the corresponding equalities for and follow directly from the assumption that respect the bi-invertible maps and .
It remains to check the cases of and . Since these are symmetric, we only describe the case of . 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 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 , let be the identity function. We have , so we can define a map by path induction, sending to . By [Uni13, Corollary 4.3.3] and the univalence axiom, the map is an equivalence. Let 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 and a type family . If we have , then we have .
Proof.
This is proven by path induction, after translating bi-invertible maps to equalities, using and . ∎
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.
Lemma 2.8.
The type is equivalent to the type .
Proof.
We use equivalence induction (Lemma 2.7) for and and then observe that the type
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. ∎
3. is a set
In this section we relate with the usual definition of the integers as signed natural numbers, which we call . We show that , and since we already know that is a set, we deduce that is a set too.
Definition 3.1.
Let be the inductive type with the following constructors:
-
–
-
–
-
–
Theorem 3.2 (is).
We have an equivalence .
Proof.
On the one hand, one can define by induction, by mapping:
-
–
;
-
–
;
-
–
;
-
–
.
Similarly one defines . The fact that provides a left and right inverse for is straightforward. So, by Proposition 2.1 we get a map . On the other hand, it is easy to construct a map by induction.
Induction on shows that . The hard part is to show that . This is where Theorem 2.4 comes in handy. Theorem 2.4 implies that it is enough to check that and that , and this follows directly by construction. ∎
4. Representing using a universe
In this section we give another definition of the integers, denoted by , 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 -algebras and of -algebra morphisms.
Definition 4.1.
A -algebra is a type together with an inhabitant , and an equality . We denote such a -algebra as , or if the rest of the structure can be inferred from the context.
Definition 4.2.
A morphism of -algebras from to is given by a map , together with an equality , and a proof that . We denote the type of morphisms of -algebras between and by .
We are interested in initial -algebras.
Definition 4.3.
A initial -algebra is a -algebra such that for any other -algebra the type is contractible.
See Definition 1.4 for the definition of the initial -algebra using a mini universe222This is inspired by Zongpu Xie’s proposal how to represent HIITs in Agda [Kap19].. Then define an interpretation function , as the higher inductive family with only one constructor . Define the type . The type has the structure of a -algebra, since we have and . The following result follows by a routine application of the induction principle of .
Theorem 4.4 (isInitial).
The -algebra is initial.∎
In particular, we have.
Proposition 4.5.
Given a type with an inhabitant and an equality , we get a morphism of -algebras .∎
Again, comparing maps out of is easy, thanks to the following theorem.
Theorem 4.6.
Given a type , an inhabitant , an equality , and a map , if and then .∎
Analogously to the case of , this is proven by combining the initiality of with the fact that to preserve an equality in the universe , it is enough to commute with its corresponding coercion function .
Following the argument given in Section 3, one deduces the following.
Theorem 4.7.
There is an equivalence .∎
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 is nothing but the higher inductive type presentation of the circle of [Uni13, Section 6.1], so that . Moreover, the type family is equivalent to the path space fibration of the circle, in the following sense.
Theorem 4.8 (ElisPath).
For every we have .
Proof.
We construct a map using induction on and mapping to , To construct a map going the other way, we use path induction and map to . 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.
Corollary 4.9.
We have an equivalence .∎
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.
5. 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 and is equivalent to the type of equivalences between and , and the principle of bi-invertible induction.
6. Open questions
Preservation of properties
The key result in the above discussion is Lemma 2.8, which can be reformulated as follows. Let , , , , and . We can define the following two types of morphisms between and :
Informally, is the type of maps that respect the endomorphism, and 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 , and what Lemma 2.8 says is that this map is an equivalence.
There is something special about the type family , 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 for a type of algebras, and we extend it to a signature , such that the fields we added take values in propositions. In the above example corresponds to and corresponds to the extension . As usual, given -algebras , we have a forgetful map . Is this map an equivalence in general?
The following example, suggested by Paolo Capriotti, shows that this is not necessarily the case.
Example 6.1.
Consider , the signature , and , the extension
The -algebras are the types with a binary operation, and the -algebras are the sets with a binary operation with a distinguished element that is a left and right unit.
The extension is propositional. This is because being a set is a proposition ([Uni13, Theorem 7.1.10]), so inhabits a proposition, two left and right units must necessarily coincide, so inhabits a proposition (assuming ), and the identity types of a set are propositions and these are closed under pi-types ([Uni13, Theorem 7.1.9]), so inhabits a proposition (assuming ).
Let us see that for -algebras the forgetful map is not an equivalence in general. Let be , where is a proof that the natural numbers form a set, and is a proof that is a left and right unit for . Let be , 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 . This map clearly respects the operations, so we get an inhabitant of . But this morphism does not respect the units, so it cannot come from a morphism in .
This discussion leaves open an interesting question.
Question 6.2.
Given a signature and a propositional extension , are there useful necessary and sufficient conditions for the forgetful map to be an equivalence for every pair of -algebras and ?
Initiality of HIITs
Our original goal was to complete the conjectured result from [AP18] and formally verify that is a set. Using the strategy from this paper this is fairly straightforward: we can show that the natural notion of morphism of -algebras satisfies a principle analogous to Lemma 2.8, and hence that 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 is initial in its corresponding wild category of algebras. Specifically, the proof seems to require the construction of a filler for a -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.
Acknowledgements
The first author would like to thank Paolo Capriotti, Nicolai Kraus and Gun Pinyo for many interesting discussions on the subject of this paper. Both authors would like to thank Christian Sattler for comments and useful discussions. The work by and with Ambrus Kaposi and András Kovács plays an important role in particular in connection with the open questions triggered by this paper.
References
- [AK16] Thorsten Altenkirch and Ambrus Kaposi. Type theory in type theory using quotient inductive types. SIGPLAN Not., 51(1):18–29, January 2016.
- [AMV19] Andreas Abel, Anders Mörtberg, and Andrea Vezzosi. Cubical agda: A dependently typed programming language with univalence and higher inductive types. To appear in ICFP, 2019.
- [AP18] Thorsten Altenkirch and Gun Pinyo. Integers as a higher inductive type. TYPES, 2018.
- [AS19] Thorsten Altenkirch and Luis Scoccola. Implementation of the integers as a higher inductive type. https://github.com/LuisScoccola/integers-as-HITs, 2019.
- [BGvdW17] Henning Basold, Herman Geuvers, and Niels van der Weide. Higher inductive types in programming. J. UCS, 23:63–88, 2017.
- [Cav18] Evan Cavallo. biinv-int. https://github.com/RedPRL/redtt/blob/master/library/cool/biinv-int.red, 2018.
- [CCHM18] Cyril Cohen, Thierry Coquand, Simon Huber, and Anders Mörtberg. Cubical Type Theory: A Constructive Interpretation of the Univalence Axiom. In Tarmo 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.
- [CHM18] Thierry Coquand, Simon Huber, and Anders Mörtberg. On higher inductive types in cubical type theory. In Proceedings of the 33rd Annual ACM/IEEE Symposium on Logic in Computer Science, LICS ’18, pages 255–264, New York, NY, USA, 2018. ACM.
- [KA18] Nicolai Kraus and Thorsten Altenkirch. Free higher groups in homotopy type theory. In Proceedings of the 33rd Annual ACM/IEEE Symposium on Logic in Computer Science, LICS 2018, Oxford, UK, July 09-12, 2018, pages 599–608, 2018.
- [Kap19] Ambrus Kaposi. Separate definition of constructors? Agda mailing ist, May 2019.
- [KK19] Ambrus Kaposi and András Kovács. Signatures and induction principles for higher inductive-inductive types. CoRR, abs/1902.00297, 2019.
- [KKA19] Ambrus Kaposi, András Kovács, and Thorsten Altenkirch. Constructing quotient inductive-inductive types. PACMPL, 3(POPL):2:1–2:24, 2019.
- [Kv19] Nicolai Kraus and Jacob von Raumer. Path spaces of higher inductive types in homotopy type theory. In 2019 34th Annual ACM/IEEE Symposium on Logic in Computer Science (LICS), pages 1–13, 2019.
- [LB15] D. R. Licata and G. Brunerie. A cubical approach to synthetic homotopy theory. In 2015 30th Annual ACM/IEEE Symposium on Logic in Computer Science, pages 92–103, 2015.
- [Li15] Nuo Li. Quotient types in type theory. PhD thesis, University of Nottingham, 2015.
- [red19] Redtt. https://github.com/RedPRL/redtt, 2019.
- [RLS13] Daniel R. Licata and Michael Shulman. Calculating the fundamental group of the circle in homotopy type theory. pages 223–232, 06 2013.
- [Uni13] The Univalent Foundations Program. Homotopy Type Theory: Univalent Foundations of Mathematics. Institute for Advanced Study, Princeton, NJ, 2013.