Constructions of categories of setoids from proof-irrelevant families

When formalizing mathematics in constructive type theories, or more practically in proof assistants such as Coq or Agda, one is often using setoids (types with explicit equivalence relations). In this note we consider two categories of setoids with equality on objects and show, within intensional Martin-Löf type theory, that they are isomorphic. Both categories are constructed from a fixed proof-irrelevant family F of setoids. The objects of the categories form the index setoid I of the family, whereas the definition of arrows differs. The first category has for arrows triples (a,b,f:F(a)→F(b))\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$(a,b,f:F(a)\,\rightarrow \,F(b))$$\end{document} where f is an extensional function. Two such arrows are identified if appropriate composition with transportation maps (given by F) makes them equal. In the second category the arrows are triples (a,b,R↪Σ(I,F)2)\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$(a,b,R \hookrightarrow \Sigma (I,F)^2)$$\end{document} where R is a total functional relation between the subobjects F(a),F(b)↪Σ(I,F)\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$F(a), F(b) \hookrightarrow \Sigma (I,F)$$\end{document} of the setoid sum of the family. This category is simpler to use as the transportation maps disappear. Moreover we also show that the full image of a category along an E-functor into an E-category is a category.


Introduction
When formalizing mathematics in (generalized predicative) constructive type theories, such as Martin-Löf type theory, or more practically in proof assistants such as Coq or Agda, one is often using setoids. A setoid is a type with an explicitly given equivalence relation, and an extensional function between two setoids is a type-theoretic function which respects the equivalence relations of the setoids. Setoids are in fact close to what Bishop [3] called sets in his influential monograph of foundations of constructive analysis. The setoids form a category which has many properties in common with the category of sets. In standard intensional Martin-Löf type theory [7], the theory we shall be concerned with, there is however no natural internal notion of equality on the totality of setoids, as for sets in set theory. Categories of setoids with equality on objects have to be constructed explicitly [8][9][10]. We shall here introduce a new such construction and show it is isomorphic to the previously known. (To avoid a possible misunderstanding, it is possible to construct categories of setoids from the syntactic expressions of type theory, and there the equality of objects is obtained from the definitional equality of types [4,6]. This gives only a category in a meta theory of type theory, and while it gives many interesting results, it does not give us the desired construction inside standard intensional type theory. Meta theories based on mild extensions of intensional theory have been considered [1].) Many arguments of category theory do not require the consideration of equality of two objects. However when studying categories internally to some category, or when making constructions involving strings of composable arrows (such as the nerve of a category), a notion of equality on objects seems ubiquitous. In set theory there is a global notion of equality on all entities which also equips objects of a category with a standard equality. In type theory we have a choice whether categories should be equipped with an equality on objects or not. Categories without such equality are known as E-categories. In standard intensional Martin-Löf type theory one encounters problems to construct rich categories of setoids with equality on objects. This is basically due to the fact that the propositional identity relation (the identity type) in this theory induces a groupoid structure on all types [5]. A consequence is that families of types do not extend nicely to families of setoids; see [8]. However by restricting to so called proof-irrelevant families of setoids, which avoid the unwanted groupoid structure, we obtain a notion of family which is close to that of ordinary set theory. A simple example of such a well-behaved family is the one given by the fibers of an extensional function between setoids f : Y / / X , See Example 2.1 below for details. From any proof-irrelevant family of setoids F over a setoid A arises a category C(A, F) of setoids as shown in [9,10]. This is perhaps the category which is closest to the type-theoretic language: the setoid A constitutes the objects, a morphism (a, b, f ) consists of an extensional function f : and is defined using a transportation function F( p) : commutes. This equality is a slightly cumbersome notion when working with this category. We show (Theorem 3.2) that this category is isomorphic to another category S(A, F) where the morphisms corresponds to functional relations on (A, F), the setoid-sum of the family. In this category the transportation functions are invisible, which makes for a smoother treatment of the category of setoids akin to a category of sets in set theory; see Example 3.1 below. As shown in [9] we may choose F so that C(A, F) is isomorphic to a category of sets in a model of constructive set theory CZF, thus ensuring rich properties of the category.
For the purpose of the final result we consider two different versions of categories with equality on objects as formalized in type theory. One is the algebraic formulation, or rather essentially algebraic formulation, in which the objects, arrows and composable arrows, respectively, forms setoids, and all the operations are extensional functions. In this axiomatization no dependent families occur. The other is the homfamily formulation in which the Hom-sets are regarded as a proof-irrelevant family over the setoid of pairs of objects Just as for sets one can pass between the formulations; see "Appendix". The second formulation is then used to prove the second main result Theorem 4.1, that the full image of a category along an E-functor into an E-category is a category.

Families of setoids
Here and in the rest of the paper we work in standard intensional Martin-Löf type theory [7]. This means in particular that we do not use the extensional identity type, or any of its consequences such as Streicher's K-axiom [5,10]. We shall also use one type universe. By staying in this fragment of the theory, the results can be transferred to computer-aided proof systems such as Agda and Coq. Recall from, for instance [8] or [9], that a good notion of a family of setoids over a setoid is the following. A proof-irrelevant family F of setoids over a setoid Aor just a family of setoids -consists of a setoid F(x) = (|F(x)|, = F(x) ) for each x ∈ A, and for p : (x = A y) an extensional function F( p) : F(x) / / F(y) (the transportation function) which satisfies the three conditions: Here r (x) is the canonical proof object for x = A x and = ext denotes the extensional equality of functions. (F2) F( p) = ext F(q) for p, q : x = A y and x, y ∈ A. Since F( p) does not depend on p, this is the so-called proof-irrelevance condition.
(F3) F(q) • F( p) = ext F(q • p) for p : x = A y, q : y = A z and x, y, z ∈ A.
Example 2.1 A typical example of a proof-irrelevant family arises from the fibers of an extensional function f : Y / / X . Define F(x) to be the setoid with underlying type ( y ∈ Y )( f (y) = X x) and where two elements (y, q) and (y , q ) are considered equal just in case y = Y y . The transportation function F( p) for p : x = X x , takes (y, q) to (y, q • p), where q • p is the proof of f (y) = X x obtained by transitivity from q : f (y) = X x and p.
Proof-irrelevant families may also arise as functions I / / P(A) from the index setoid I into the collection of subsetoids of a fixed setoid A in the following way. We first define some basic notions. Let A be the fixed setoid. Let P(A) denote the following preorder. Its elements are injections m : we get using unique choice Thus we see that (U, m)= (V, n) is the extensional equality. If Q(x) is any property on A which respects equality, i.e. Q(x) and x = A y implies Q(y), we can form a subsetoid {x ∈ A : Q(x)} of A which is given by the injection Using this method we can define standard set-theoretic operations, domain and range of a relation R ∈ P(X × Y ). E.g A family of subsetoids of A indexed by a setoid I is an extensional function F : We may now extendF to a proof-irrelevant family in a canonical way: for a proof p of i = I j, we have F(i)= F( j) so there is a unique f such that the following diagram commuteŝ We letF( p) = def f . By the above it is unique and independent of p, so (F2) holds. If i = j definitionally, then f is extensionally equal to the identity onF(i). This verifies (F1). The condition (F3) ofF is easy to check using uniqueness.
Conversely, from every proof-irrelevant family F on I we get a familyF : I / / P(A) for a canonical A; see Proposition 2.2 below. To prove this we introduce the setoid-sum construction. Let F be a family of setoids over the setoid I . The disjoint sum of the family exists in Setoids and may be explicitly given by where the equivalence is given by The injections are given by ι x (y) = (x, y), and satisfy This construction satisfies the universal property that if C is a setoid and j x : then there is a unique extensional k :

Proposition 2.2 Let F be a proof-irrelevant family of setoids indexed by the setoid I . Then F induces an extensional functioň
Proof It follows from (1) that p : x = I y, impliesF(x)⊆F(y) and similarly p −1 : y = I x impliesF(y)⊆F(x). ThusF(x)=F(y).

Two categories of setoids and their isomorphism
We provide some more details to the construction sketched in the introduction; see [9] for full details. A family F of setoids over a setoid I gives rise to a category of setoids C = C(I, F) as follows. The objects are given by the index setoid C 0 = I , and are thus equipped with an equality, and the setoid of arrows C 1 is Here Ext(F(i), F( j)) denotes the setoid of all extensional functions from F(i) to F( j), and where the equality is extensional equality.
is an extensional function, and where we define two arrows and only if, there are proof objects p : i = I i and q : j = I j such that the diagram commutes. The domain of the arrow (i, j, f ) is i and its codomain is j.
Note that F( p) and hence the composition is independent of p. The setoid C 2 of composable arrows consists of such triples ((i, j, f ), ( j , k, g), p). Then C is a category in the essentially algebraic sense as shown in [9]. (See "Appendix" for the formal definition of essentially algebraic category.) The second category construction is as follows. Define a category S(I, F) whose setoid of objects is I , and whose arrows 1 are triples (i, j, R) where R is one-valued binary relation (i.e. a functional relation) on S = (I, F) with dom(R)= F(i) and ran(R)⊆ F( j). Two arrows (i, j, R) and (i , j , R ) are equal when i = I i , j = I j and R= R . The domain and codomain of (i, j, R) are i and j respectively. The composition of (i, j, R) and ( j , k, Q) is (i, k, Q • R) when j = I j . Here Q • R denotes the relational composition.  (a, b, f ) and g = (a , b , g) are two parallel arrows in C, and that h = (c, d, h) is third arrow composable with both these on the left. To prove h • f = h • g, we need to exhibit proof objects p : a = a , q : b = c, q : b = c and r : d = d , and to show In more complicated diagrams, the proliferation of transportation maps F( p) is considerable, and leads to an excess of equations, which can be difficult to manage in a formal proof system. In the category S we need only to check that the proof objects exists, and then check that the relational equation holds, which is familiar from set theory.
We show that M is well-defined on arrows: Suppose that (i, j, f ) and (i , j , f ) are equal arrows in C(I, F), that is, there are p : i = I i and q : j = J j such that the diagram (2) commutes. Note that for . Inserting this in (3), substituting x = F( p −1 )(x ) and then using the commutative square we get Thus M is well-defined. For objects (i, j, f ) and ( j , k, g) with p : j = I j we check functoriality by verifying that and that is the identity relation on the subsetF(i). To see (4) expand the definition and use that F( p) = F(q) for q : j = I j : Let Thus by the type-theoretic axiom of choice there is a unique extensional f : If (u, v)∈ G f , then by (3) there is an x ∈ F(i) such that Thus by (7): (u, v)∈ R. Conversely, suppose (u, v)∈ R. Then since dom(R) = F(i) and ran(R)⊆F( j), there are x ∈ F(i) and y ∈ F( j), with u = S i, x and v = S j, y . By uniqueness in (7), y = f (x), so indeed (u, v)∈ G f . Thus (6) holds.
Uniqueness of f : Suppose that G f = R for some f : By uniqueness in (7), f = f .
We show that N is well-defined on arrows: Suppose (i, j, R) and (i , j , R ) are equal morphisms with N (i, j, R) = (i, j, f ) and N (i , j , R ) = (i , j , f ). Thus p : i = I i and q : j = J j and R= R , and hence We show that (2) commutes. Let x ∈ F(i). Then by definition of the graph G f , we get ( i, x , j, f (x) )∈ G f , and hence also ( i, x , j, f (x) )∈ G f . Again by the definition of a graph: Thus for some x ∈ Fi , p : i = I i and some q : j = I j we have and since F(q) = F(q ) and F( p) = F( p ), we are done proving that the diagram commutes.
We check that N is functorial: is unique such that G f= R, and g : F( j ) / / F(k) is unique such that G g= Q. By (*) above we have By (**) above Hence f = id F(i) as required. The functors M and N form an isomorphism of categories. This is clear for objects. Let (i, j, R) be an arrow of S(I, F). Then N (i, j, R Thus we have established: The category on the left uses a universe to define the arrows, so it is in a predicative sense large, but the isomorphism shows that the arrows can be represented by a set in the universe.

Full images of categories in E-categories
The construction of C(I, F) may actually be constructed as a full image of F regarded as an E-functor from I (as discrete category) into the E-category of setoids. This follows from a general full image construction (Theorem 4.1). To prepare for a formal proof of this we need to present some further notions.
An equivalent formulation of a category is the following (see "Appendix" for a proof of equivalence). A hom family presented category C (or just HF-category) consists of a setoid Ob C = Ob and a (proof-irrelevant) family Hom = Hom C of setoids indexed by the setoid Ob × Ob. Note that for p : a = Ob c and q : b = Ob d there is thereby a transportation map Hom( p, q) : Hom(a, b) / / Hom(c, d).
We often write, as is usual, C(a, b) for Hom C (a, b). For each a ∈ Ob, there is an element id a ∈ Hom(a, a). Moreover for all a, b, c ∈ Ob there is an extensional function Hom(a, c).
These satisfy the usual equations of identity and associativity. Moreover, for p : a = Ob a , and for p : a = Ob a , q : b = Ob b and r : c = Ob c this diagram commutes: Hom(a , b ) Hom(q,r )×Hom( p,q) Hom(a, c) Hom(a , c ) The Eqs. (8) and (9) are coherence conditions for the transportation maps of the homfamily.
A weaker notion is that of an E-category, where we require in the above instead that Ob is a type, and that Hom is a family of setoids indexed by the type Ob×Ob. Moreover we drop Eqs. (8) and (9). Any HF-category may be considered as an E-category by omitting the equality on objects.
A functor F from the HF-category C to the HF-category D consists of an extensional function F 0 : Ob C / / Ob D and for each pair of objects a, b ∈ Ob C, an extensional function F a,b : Hom C (a, b) / / Hom D (F 0 (a), F 0 (b)) satisfying the usual functoriality equations. Moreover it is required that for p : commutes. Here ext(F 0 , r ) denotes the canonical proof that F 0 (c) = Ob D F 0 (c ) for r : c = Ob C c . (Because of the proof-irrelevance of Hom, it does not matter what this proof object actually is the diagram above.) For an E-functor between E-categories the condition that F 0 is extensional is omitted, and the coherence condition (10) is dropped.
We may construct the full image of an E-functor as an HF-category if the source category is an HF-category.
there is a functor G : C / / S given by G(a) = def a and G a,b ( f

which is surjective on objects. The HF-category S is a full E-subcategory of D.
Proof It is clear that S is an E-category. We show it is an HF-category as well. For p : a = Ob S a and q : b = Ob S b , we need to define the transportation map From the transportation maps of C, we have C( p, r (a)) : C(a, a) / / C(a , a) and C(r (b), q) : , r (a))(id a ) ∈ C(a , a) and (C( p, r (a))(id a )). S( p, q) is extensional. We also have S( p, q) = ext S( p , q ) for all p, p : a = S a and all q, q : b = S b , since C is a proof-irrelevant family. Moreover • p, r (a))(id a )).
Hence Hom S is a proof-irrelevant family over Ob S × Ob S. The equations for identity and associativity are clearly fulfilled, since they are inherited from D. The coherence conditions (8) and (9)  Regarding the condition (9) suppose that p : a = Ob S a , q : b = Ob S b and r : c = Ob S c and that f ∈ S(b, c) and g ∈ S(a, b), G is evidently an E-functor surjective on objects. We check the coherence condition (10): Suppose that p : a = Ob C a , q : b = Ob C b and that f ∈ C(a, b). Write p = ext(G, p) and q = ext(G, q). r (a))(id a )) (9) = F(C(r (a), q )(id b • f ) • C( p , r (a))(id a )) (9) Example 4.2 Let C be discrete category arising from a setoid A and let D = Setoids be the E-category of setoids. Suppose that F is a proof-irrelevant family of setoids indexed by A. Then F may be considered as an E-functor C / / Setoids, and the full image S is essentially C(A, F).

Equivalence to the Hom family formulation
Let C be a category formulated in the essentially algebraic way. We define an HFcategory C. The setoid of objects of C is C 0 . For a, b ∈ C define the setoid where r is some proof of dom( f ) = a ∧ cod( f ) = b obtained from r , p and g. As the second component r is irrelevant, Hom is a proof-irrelevant family of setoids on C 0 × C 0 .
The irrelevance property of the second component also entails (9). Conversely suppose that C is an HF-category. Define an essentially algebraic category C, by letting C 0 = Ob C. Then define C 1 to be the setoid consisting of triples   (a, b, f ) where f ∈ Hom C (a, b). Define a relation ∼ by letting This is an equivalence relation since Hom C is a proof-irrelevant family. Define  dom(a, b, f ) = a and cod(a, b, f ) The setoid C 2 of composable maps consists of triples (f, g, p) where f ∈ C 1 , g ∈ C 1 and p : cod(f) = C 0 dom(g). Define (f, g, p) = C 2 (f , g , p ) ⇐⇒ def f = C 1 f ∧ g = C 1 g .