Construction of the Circle in UniMath

We show that the type $\mathrm{T}\mathbb{Z}$ of $\mathbb{Z}$-torsors has the dependent universal property of the circle, which characterizes it up to a unique homotopy equivalence. The construction uses Voevodsky's Univalence Axiom and propositional truncation, yielding a stand-alone construction of the circle not using higher inductive types.


Introduction
In set theoretic foundations of mathematics, the sets have no interesting internal structure, aside from the identity of their elements. By contrast, in homotopy type theory and Voevodsky's univalent foundations, the types are the fundamental objects, serving to classify the objects of mathematics. They behave much like (homotopy types of) spaces, due to the promotion of isomorphisms between objects to equalities, together with the intuition that an equality between two objects of the same type is like a path between two points in the same space.
Synthetic homotopy theory is the study of the homotopy theoretic properties of types. It is a fruitful one, because it turns out that many of the most basic results of standard homotopy theory have true analogues for types, even though the framework, based purely on logical principles, is devoid of the features one normally associates with topology, such as the topology of the real numbers. In standard homotopy theory it is well known that the classifying space of the group Z of integers is homotopy equivalent to the circle. The traditional algebraic notion of Z-torsor yields a category all of whose arrows are isomorphisms, all of whose objects are isomorphic to each other, and a trivial Z-torsor whose automorphism group is Z. Due to univalence, the type BZ of all Z-torsors is a connected pointed type whose fundamental group is Z; we may call it the classifying type of Z. In this paper we show that BZ behaves the way a circle ought to behave, by establishing that maps from it to other types (or families of types) are freely determined by the destinations of the base point and the canonical loop at the base point (corresponding to the element 1 of Z). The proof is constructive, in that it does not appeal to the axiom of choice or the law of the excluded middle.
There are various types equivalent to the type of Z-torsors, and thus they also provide constructions of circles: all one needs is a connected pointed type whose automorphism groups are isomorphic to Z. For example, if one arising from geometry is desired, one may consider the type consisting of all frieze patterns in a Euclidean plane 1 formed from a linear collection of evenly spaced copies of the letter F .
We have formalized the result in UniMath, a name which refers both to a (univalent) foundation of mathematics based on a formal type theoretic language and to a particular repository [8] of formalized proofs, encoded in the language of the proof assistant Coq.
The other standard way to construct a circle in type theory uses higher inductive types, where one posits a new type, an element of it, a path from the element to itself, an induction principle (for defining functions from it), and nothing more. Because UniMath, by a conservative convention aimed at minimizing the burden of proving consistency of the formal system, does not use higher inductive types, the construction presented here is the only way to construct a circle in UniMath. Adding higher inductive types to the system would give another construction of the circle, equivalent to the one described above. Now we give a few more details. As a prerequisite we require, of the reader, a working knowledge of homotopy type theory as described in, for example, the first four chapters of [7]. One extra piece of knowledge we use here is the dependent elimination principle for propositional truncation, mentioned in [7, Ch. 6.9], and qualified as 'not really useful' 2 . We use this principle in Lemma 5.3, and the paragraph after its proof gives some extra attention to the computational aspect.
For convenience we give a direct inductive definition of the set of integers in Section 2. Thus we get a set of integers Z, a constant 0 : Z, and a successor function s : Z → Z that is an equivalence. Considering pairs (X, f ) of type X:U (X → X), we can introduce the pointed type of Z-torsors by adopting the following definitions.
It is not difficult to see that the type pt = TZ pt is equivalent to Z. To see that, begin by observing that every function f : Z → Z commuting with s is propositionally equal to s f (0) . The first projection acting on p : pt = TZ pt gives a path pr 1 (p) : Z = Z such that the corresponding transport function pr 1 (p) * : Z → Z is a bijection commuting with s. We evaluate this bijection in 0. Let ev 0 (p) :≡ pr 1 (p) * (0) for all p : pt = TZ pt, then ev 0 : (pt = TZ pt) → Z. Combining these observations, using the univalence axiom, one proves that ev 0 is an equivalence.
We define 1 :≡ s(0). The preimage of 1 under the equivalence ev 0 is a natural generating path of pt = TZ pt, so we define :≡ ev −1 0 (1), which we call the loop of TZ. Alternatively, we could have obtained directly from s : Z ≃ Z by applying the univalence axiom (with some easy add-ons, e.g., proving that s commutes with itself).
With this in hand, we can formulate a recursion principle for TZ. It states that, given a type A, an element a of A and a path l : a = A a, one can construct a function f : TZ → A such that f (pt) ≡ a and ap f ( ) = l. (This construction was formalised by Grayson in 2014, see [2]; our construction here uses the same basic idea but manages the computations involved in establishing the induction principle better.) We call the resulting function rec A : The universal property of the circle for TZ states that rec A above is an equivalence, for all types A. In order to prove this universal property one needs an induction principle, in which A is not a type but a type family over TZ. On the basis of Grayson's construction of the recursion principle, Shulman sketched an approach to the induction principle, see [6]. Independently of this, but also departing from Grayson's proof of the recursion principle, Buchholtz and Bezem found the construction presented in this paper, which has subsequently been formalized by Grayson [1,5] in UniMath.
Here apd is as defined in [7, Ch. 2.3]. Note that r above is a path between two elements of the same fiber A(pt). Hence r and r −1 are paths over refl pt and can be composed with l. To simplify the statement, we use the left recursive composition * ′ o of paths over paths and the right recursive * o composition of paths over paths. (A composition operation is called left recursive if it computes to its right-hand argument when its left-hand argument is given by reflexivity; similarly with left replaced by right.) The type in Eq. (1.1) is illustrated in Fig. 1. We think of TZ as a circle (and prove that it is), but we illustrate it (and objects depending on it) as periodically recurring, in order to make clearer diagrams.
The type apd f ( ) = r * ′ o l * o r −1 is equivalent to apd f ( ) = λz,z= A z r l, and corresponds to filling the inside of the curvilinear quadrilateral in Fig. 1.
If the underlying type theory has propositional truncation with a dependent eliminator that computes judgmentally on the point constructor, as in [7, Ch. 6.9], then the path r : f (pt) = a above is a reflexivity path. It then follows from the care with which we chose the expression r * ′ o l * o r −1 , that it has the same type as l, and, moreover, the two terms are judgmentally equal. Thus the right side of the equation 1.1 can be replaced by l.
Because the convention in UniMath is to avoid higher inductive types, the formalization in [1] is slightly different from the construction presented below. The formalized construction does not use any higher inductive types, relying instead on the construction of propositional truncation as (the propositional resizing of) X :≡ P :Prop ((X → P ) → P ). Nor, of course, and this is the whole point, do we depend on the previous existence of a type satisfying the induction principle of the circle.
In a type theory where higher inductive types are admitted, one can introduce a circle S 1 as a higher inductive type, as in [7, Ch. 6.1], and it will easily be shown to be equivalent to TZ. The equivalence can be established by observing that TZ and S 1 are pointed connected types with loop spaces equivalent to Z. (For the interested reader: apply [7, Lemma 7.6.2] with n = −2 to reduce to action on paths. Then use connectedness to strengthen this result from embeddings to equivalences. Finally, again using connectedness, reduce to the loop spaces of the respective points, and show they are equivalent to Z and thus to each other.) The induction principle Eq. (1.1) for TZ then follows directly.
One can construct models of type theory with univalent universes and propositional resizing (viz., essentially of UniMath) that do not have higher inductive types, not even suspensions. We can take any model and restrict the nth universe, n = 0, 1, . . . , to consist of homotopy n-types: the new zeroth universe U ′ 0 consists of the sets of the old universe U 0 , the new universe U ′ 1 consists of the groupoids of U 1 (hence including U ′ 0 ), etc. This construction keeps all the propositions, so it preserves propositional resizing. By our construction, U ′ 1 will contain a circle TZ, but it cannot contain the 2-sphere (the suspension of the circle), as this is not a groupoid. Because the 2-sphere in topology is not an n-type for any n, the new model will not contain a 2-sphere.

The integers
We define the type of integers in one of the many possible ways. Definition 2.1. Let Z be the inductive type with the following three constructors: (1) zero : Z for the integer number zero, 0 :≡ zero (2) pos : N → Z for positive numbers, 1 :≡ pos(0), . . ..
The successor function s : Z → Z is defined inductively setting s(zero) :≡ pos(0), s(pos(n)) :≡ pos(S(n)), s(neg(n)) :≡ −i(n). For example, we have s(−1) ≡ s(neg(0)) ≡ −i(0) ≡ zero ≡ 0. By induction on n : N one proves s(i(n)) = i(S(n)), so that one can say that s extends S on the i-image of N. From now on we will identify i(n) : Z with n, and −i(n) : Z with −n, for all n : N.
The successor function s is an equivalence. The inverse s −1 of s is called the predecessor function. We denote the n-fold iteration of s as s n , and the n-fold iteration of s −1 as s −n .
Recall the equivalence ev 0 : (pt = TZ pt) → Z from the introduction. We have refl pt : pt = TZ pt, as well as the operations of path reversal and path composition as defined in [7, Ch. 2.1]. These satisfy the laws as stated and proved in [7, Lemma 2.1.4], equipping pt = TZ pt with a group structure. The equivalence ev 0 maps refl pt via id Z : Z → Z to 0. As explained in the introduction, ev 0 maps any p : pt = TZ pt via s k : Z → Z to some k : Z. Since (s k ) −1 = s −k and s k • s l = s k+l , ev 0 transports path reversal and path composition to negation and addition, respectively. This means that the entire group structure of pt = TZ pt is transported to the usual group structure on Z, including all the proofs of the group laws in Z. (The fact that we do not have to reprove the group laws is one of the benefits of the univalent approach.)

Some induction principles for the integers
The definition of Z yields the following induction principle. Given P : Z → U, to construct elements h(z) : P (z) for every z : Z, it suffices to give h(0) : P (0) and functions f : n:N (P (n) → P (n + 1)) and g : n:N (P (−n) → P (−n − 1)), as illustrated in Fig. 2.

Figure 2. Asymmetric integer induction principle
It is possible to give a more symmetric, but less general induction principle, if we assume that the functions are equivalences. In that case we can reorient the g's to point in the same direction as the f 's, allowing us to combine them into a single family f : z:Z P (z) ≃ P (z + 1) of equivalences, as illustrated in Fig. 3.
We shall need that in this case, giving an element h : z:Z P (z) together with identities of type h(z + 1) = f z (h(z)) for all z : Z is · · · · · · · · · Figure 3. Symmetric integer induction principle equivalent to giving the single element h(0). We formulate this precisely as follows.
Theorem 3.1. Let P : Z → U and f : z:Z P (z) ≃ P (z + 1). The function ϕ : for the formalization of the proof, as well as the formalization of a version for Z-torsors.
Proof. We prove that the fiber over any p : P (0) is contractible. We simplify notations a bit by leaving out the types of h and q. The fiber (h,q) h(0) = p consists of triples (h, q, r) with r : h(0) = p. By case distinction, h can (equivalently) be split in three parts (h − , h 0 , h + ) with h 0 : P (0), h + : n:N P (n+ 1), and h − : n:N P (−n−1). Since h(0) = p only depends on h 0 the pair (h 0 , r) with r : h 0 = p contracts away, so we're left with the type The latter type is contractible, because it is the product of two contractible types, each specifying a certain function h ± : n:N Q ± (n), and saying that this function has a certain value at 0 and prescribing the values at successors. But such a specification is unique by the universal property (induction!) of N.
Let us spell out the inverse function produced in the proof. It maps p : P (0) to a pair whose first component is the function that takes z : Z to f z (p) : P (z), where for n : N, (p)), for n : N.

Identifying elements in members of families of types
In this section we present some additional results that are needed in the sequel.
Let A : U, B : A → U, a i : A, b i : B(a i ) for i = 1, 2, and p : a 1 = a 2 . We are interested in identifications of b 1 and b 2 relative to this data. We cannot in general form the type b 1 = b 2 as their types may be different. There are several ways to solve this problem. One of them is to transport b 1 along p and form an identity type in B(a 2 ). Another way would be to consider identifications (a 1 , b 1 ) = (a 2 , b 2 ) in x:A B(x) and require that the action of the first projection on such identifications is equal to p. These two ways are equivalent. The former way is easier to work with and will be the one we choose here.
Many of the operations on paths have their counterpart for paths over paths. We define the unit path over a path, composition of paths over paths, and reversal of paths over paths. Definition 4.2. Let A : U, B : A → U, a i : A, b i : B(a i ) for i = 1, 2, 3, and p i : a i = a i+1 for i = 1, 2. We define: , defined by induction first on p 2 and then on r : , defined by induction first on p 1 and then on r : b 1 = b 2 , by setting refl −o b 1 :≡ refl b 1 . These operations on paths over paths satisfy many of the laws satisfied by the corresponding operations on paths, after some modification. We illustrate the modification required to treat composition. Suppose we have elements a i : A for 1 ≤ i ≤ 4, paths p i : a i = a i+1 for 1 ≤ i ≤ 3, elements b i : B(a i ) for 1 ≤ i ≤ 4, and paths q i : b i = B p i b i+1 over p i for 1 ≤ i ≤ 3. Then we the following two paths over paths.
Since they are of different types, they cannot be compared directly, but there is an equivalence ε of type b 1 = B p 1 * (p 2 * p 3 ) b 4 ≃ b 1 = B (p 1 * p 2 ) * p 3 b 4 constructed from the associativity law for paths of type p 1 * (p 2 * p 3 ) = (p 1 * p 2 ) * p 3 . The associativity law for composition of paths over paths is an easily constructed identity of type ε(q 1 * o (q 2 * o q 3 )) = (q 1 * o q 2 ) * o q 3 . For more information we refer the reader to the repositories with formalized proofs [1].
In the rest of this section we work in a context with A : is an equivalence. The proof is by induction on first p 1 , and then q, and finally p 2 . Then conclude by reflexivity.
If p = q, then we can transport paths over p to paths over q. Definition 4.4. For every p, q : a 1 = a 2 and 2-dimensional path α : p = q, transport along α induces an equivalence cp α : . The function cp α is called change path, and is defined by induction on α, setting cp refl p : Lemma 4.5. For every p, q, r : a 1 = a 2 and 2-paths α : p = q, β : q = r, we have cp α * β = cp β • cp α .

Z-Torsors
Recall that pairs (X, f ) will be taken to be of type X:U (X → X). Moreover, terms of propositional type whose precise form does not interest us are denoted by "!". Nested pairs may be written as tuples. With these notational simplifications, we rephrase some definitions from the introduction. The variables X, Y, Z will be used for elements of TZ, as well as, by an abuse of notation, for their the first components. The equivalence ev 0 is defined by The loop of TZ is defined as :≡ ev −1 0 (1), satisfying pr 1 ( ) * = s. The type TZ is equivalent to the more traditionally defined type of Ztorsors, but is more parsimonious. (Traditionally, a Z-torsor is defined as a nonempty set upon which the group Z acts freely and transitively.) Another way to think of it is as the type of Cayley diagrams for Z.
We remark that the pointed type TZ is connected, that is, pt = Z for all Z : TZ.
We introduce the induction principle for propositional truncation in the following form (compare with [7, Ch. 6.9]). Definition 5.2. If A is a type and B(x) is a family of propositions parametrized by the elements a of A , and given g : a:A B(|a|), then there is a function f : x: A B(x). The computation rule asserts that f (|a|) ≡ g(a) for all a : A.
In UniMath the induction principle holds, but not the computation rule for it. Lemma 5.3. If P (Z) is a proposition for all Z : TZ, then P (pt) implies that P (Z) holds for all Z : TZ.
Proof. Let P (Z) be a proposition for all Z : TZ, and assume we have a proof p : P (pt). Let (X, f, t) : TZ, then t : (Z, s) = (X, f ) . Since P (X, f, t) is a proposition, it suffices by truncation elimination to prove P (X, f, |e|) for all e : (Z, s) = (X, f ). By induction on e we reduce the Figure 4. Factoring through a contractible type task to proving P (Z, s, |refl (Z,s) |), which is the same as P (pt), so p provides the proof.
The proof q : Z:TZ P (Z) constructed above has the property that q(pt) ≡ p if the computation rule for the induction principle for propositional truncation holds.
The aim of this section is to show that TZ has the universal property of the circle. Although the same method works to derive both the recursion and the induction principles, we opt to do the recursion principle first, as it is slightly simpler, and prepares the way for the more complicated induction principle.

Recursion in TZ. Fix
A : U, a : A and p : a = A a. We want to construct a function from TZ to A that maps pt to a (definitionally), and maps to p (by action on paths).
All input data is present in p and its type. When defining types and functions depending on the input data, we use p in various denotations to express this dependence.
To be able to apply Lemma 5.3, we need to find a suitable proposition. The idea is to expand A to a Σ-type over A (Definition 5.4), and to prove that this Σ-type is contractible (Lemma 5.5). We then obtain a function to A by (double) projection of this proof, as illustrated in Fig. 4. Definition 5.4. For every (X, f ), define Lemma 5.5. The type Q p (X, f ) is contractible for all (X, f, t) : TZ.
Proof. By Lemma 5.3 it suffices to prove that Q p (Z, s) is contractible. Note that Q p (Z, s) is the total space of the family R p : Note furthermore that a ′ :A a = a ′ is contractible with center (a, refl a ). Thus, to show that Q p (Z, s) is contractible, it suffices to define an equivalence ϕ a ′ : for each a ′ : A. The intention is now to invoke Theorem 3.1. Indeed, let us define the constant type family P a ′ (z) :≡ (a = a ′ ) over Z. Also, define f a ′ (z) : P a ′ (z) → P a ′ (z + 1) by f a ′ (z)(q) :≡ p * q for all z : Z and q : a = a ′ . Then each f a ′ (z) is an equivalence (with inverse q → p −1 * q). Thus, applying Theorem 3.1 shows that ϕ a ′ is an equivalence, where ϕ a ′ (h, q) :≡ h(0).
The center of contraction c p (pt) of Q p (Z, s) is implicitly defined in the above proof and can be uncovered by a careful analysis of all proofrelevant steps. First, the center of a ′ :A a = a ′ is (a, refl a ). This center is pulled back by ϕ a to a center (a, c) of Q p (Z, s), where c is the center of ϕ −1 a (refl a ) coming from the proof that ϕ a is an equivalence. The latter proof is the above instance of Theorem 3.1. Unraveling this instance, and using the remark at the end of the proof of Theorem 3.1, tells us that c is a pair (h, q) with h(z) = p z for all z : Z. Indeed, ϕ a (h, q) = h(0) = refl a . Moreover, q has type z:Z h(z + 1) = p * h(z). Wrapping up, c p (pt) :≡ (a, h, q). In general we write c p (Z) :≡ (c p (Z),c p (Z),ĉ p (Z)).
The analysis in the previous paragraph means we have achieved one of our goals, namely that the function c p from TZ to A maps pt to a definitionally. We will now deal with the other goal, namely that c p acting on yields p. Lemma 5.6. For all X, Y : TZ, e : X = Y and x : X we have ap cp (e) =c p (X, x) −1 * c p (Y,ẽ(x)), whereẽ :≡ pr 1 (e) * : X → Y .
Proof. By using induction on e we only have to check the case where X ≡ Y and e ≡ refl X . In this case ap cp (e) is refl cp(X) . On the righthand side we getẽ(x) ≡ x, and hence this side simplifies to a reflexivity path of the correct type, asc p (X, x) has type a = c p (X).
We apply the above lemma with X ≡ Y ≡ pt and e ≡ : pt = pt. Then we haveẽ(x) = s(x) = x + 1. We can take x :≡ 0 and get by the analysis after the proof of Lemma 5.5 thatc p (pt, 1) = p and c p (pt, 0) = refl a . It follows that ap cp ( ) = p by Lemma 5.6. This means we have achieved our second goal as well. We summarize the results in the following recursion principle for TZ. In the next section we will prove an induction principle for TZ. Definition 5.7. The function rec A (a, p) :≡ c p as defined after Lemma 5.5 has type rec A : and satisfies rec A (a, p)(pt) ≡ a and ap rec A (a,p) ( ) = p.

Induction in TZ. Fix
A : TZ → U, a : A(pt), and p : a = A a. On the basis of this input data, we will construct a function of type Z:TZ A(Z) that maps pt to a (definitionally), and maps to p (by dependent action on paths). We follow the pattern of the nondependent case in Section 5.1, but keep in mind that A is now not constant and p is a path over a path.
The following lemma follows from the fact that Z is a set and s : Z → Z is an equivalence. Lemma 5.8. Suppose p : (Z, s) = (X, f ). Then X is a set and f : X → X is an equivalence. Morever, withp :≡ pr 1 (p) * the equivalence induced by p, we have f n (x) = (p • s n •p −1 )(x) =p(p −1 (x) + n), for all n : Z and x : X.
Note that for fixed x : X the expressionp −1 (x) + n can be seen as the function shifting n : Z byp −1 (x) positions, indeed an equivalence. Hence f n (x) as a function of n is an equivalence from Z to X. For simplicity, we may denote f n (x) by x + n. Definition 5.9. For every Z :≡ (X, f, t) : TZ and x : X, define s Z x : pt = TZ Z by the equivalence e x (n) :≡ f n (x) using the univalence axiom. Indeed, f • e x = e x • s, as both functions map n to f n+1 (x).
Applying Theorem 3.1 we will need two auxiliary results about the paths s pt x , one for x = 0 and the other for the (symmetric) induction step. In Definition 5.9, if Z ≡ pt and x = 0, we get e 0 = id. Applying the univalence axiom gives thus the first result. Lemma 5.10. There is a path γ 0 : refl pt = s pt 0 . For the second result, note that prefixing s Z x by amounts to precomposing the equivalence e x with s. We have (e x • s)(n) = e x (n+ 1) = f n+1 (x) = f n (f (x)) = e f (x) (n), so e x • s = e x+1 . Applying the univalence axiom we get: Lemma 5.11. For every Z :≡ (X, f, t) : TZ and x : X, we have a path δ Z x : * s Z x = s Z x+1 . Now we are ready to derive the induction principle using the same technique as for the recursion principle. We reuse notations as much as possible, but take care that all types are different. where δ Z x comes from Lemma 5.11. Lemma 5.13. For every Z : TZ, the type Q p (Z) is contractible.
In order to make ends meet between the first and the fourth typing we invoke Lemma 5.14 and Definition 4.4.
A great simplification is obtained by using that TZ is a groupoid: all 2-paths having the same endpoints are equal. Hence the functions cp α only depend on the (path-)type of α, and we may replace the subscript α by its type. However, if α is shorter than its type we may prefer to keep α in cp α . Also, as cp refl is the identity, so is any cp α when the endpoints of α are definitionally equal. We make extensive use of this and of the functions and lemmas from Section 4.

Conclusion and Future Research
We have proved the induction principle of the circle for TZ: with ind A mapping (a, p) to c p satisfying c p (pt) ≡ a and apd cp ( ) = p. It would be interesting to see whether our method can be generalised from TZ to the type of G-torsors, where G is a free group with a set of generators with decidable equality.