Elementary fibrations of enriched groupoids

Abstract The present paper aims at stressing the importance of the Hofmann–Streicher groupoid model for Martin Löf Type Theory as a link with the first-order equality and its semantics via adjunctions. The groupoid model was introduced by Martin Hofmann in his Ph.D. thesis and later analysed in collaboration with Thomas Streicher. In this paper, after describing an algebraic weak factorisation system 
$$\mathsf {L, R}$$
 on the category 
$${\cal C}-{\cal Gpd}$$
 of 
$${\cal C}$$
 -enriched groupoids, we prove that its fibration of algebras is elementary (in the sense of Lawvere) and use this fact to produce the factorisation of diagonals for 
$$\mathsf {L, R}$$
 needed to interpret identity types.


Introduction
The work that Martin Hofmann produced in his Ph.D. thesis (Hofmann 1997) was revolutionary at the time. As for many relevant mathematical results, it would require time to be digested, appreciated in full and complemented by the scientific community. When it happened, the effect was stunning as the reader can appreciate browsing through Univalent Foundations Program (2013). The groupoid model which was presented in Hofmann's thesis and put to use in two papers in collaboration with Thomas Streicher (Hofmann and Streicher 1994;1998) became immediately the benchmark for various independence results in type theory whose applications in automated theorem proving were being developed.
The proof-relevant character of dependently typed languages makes equality in that context a much subtler concept than equality in the first-order logic. While the latter has a robust and elegant algebraic description in terms of adjunctions in Lawvere (1970), there is nothing comparable to it for the semantics of equality in dependent type theories. The result of Hofmann and Streicher (1998) showed that it was possible to make sense of the proof-relevant character of equality in Martin-Löf type theory using the structure provided by groupoids.
As already mentioned, this result was pivotal in the recognition of structures from homotopy theory in the semantics of identity types and to the birth of Homotopy Type Theory. The importance of the Hofmann-Streicher groupoid model as the first step towards algebraic treatments of higher equalities is universally recognised.
The present paper relates the groupoid model with the first-order equality and its semantics via adjunctions. More specifically, we prove that the fibration of groupoids in the Hofmann-Streicher model is elementary (in the technical sense specified in Section 2). An analysis of this structure shows that, in the groupoid model, it gives rise to the Hoffman-Streicher interpretation of the identity types. In fact, it is possible to reconstruct the interpretation of identity types (including the elimination rule) from the elementary structure of the fibration.
For this reason, in Section 3, we exhibit a new class of examples with groupoids enriched in a category C with finite limits, which form a category C -Gpd also with finite limits. We begin describing an algebraic weak factorisation system (L, R) on C -Gpd that will serve as providing the interpretation of type dependency. This algebraic weak factorisation system is the enriched version of the algebraic weak factorisation system on Gpd which is part of the canonical (or folk) algebraic Quillen model structure on Gpd . We then prove that the fibration R-Alg G G C -Gpd of algebras for the monad on the right functor R is elementary, generalising the standard (Setenriched) case. We then proceed to investigate the relationship between this elementary structure and the structure needed to interpret identity types in a fibration of algebras for an algebraic weak factorisation system which, as shown in Gambino and Larrea (2021), amounts to a suitable functorial factorisation of diagonals. In Section 4, we prove that the algebraic weak factorisation system on C -Gpd does have such a factorisation. As it clearly appears from the proof, the construction of such a factorisation makes heavy use of the elementary structure of the fibration R-Alg G G C -Gpd . This observation indicates that it should be possible, given an algebraic weak factorisation system on a category C with weak finite limits, to isolate conditions that would ensure the existence of a suitable factorisation of diagonals from the assumption that the fibration of algebras is elementary. We leave this question to future investigations. Section 5 concludes the paper with the observation how the above construction can be iterated. In the specific case of the enrichment in Gpd , the enrichment produces the categories of n-groupoids, together with forgetful functors. Each of these is equipped with an algebraic weak factorisation system whose fibration of algebras is elementary.

Elementary Fibrations
Let p: E G G B be a functor. An arrow ϕ in E is said to be over an arrow f in B when p(ϕ) = f . For A in B, the fibre E A is the subcategory of E of arrows over id A . In particular, an object E in E is said to be over A when p(E) = A, and an arrow ϕ is vertical when p(ϕ) = id A .
Recall that an arrow ϕ: E G G F is cartesian if, for every χ: E G G F such that p(χ) factors through p(ϕ) via an arrow g: A G G A, there is a unique ψ: E G G E over g such that ϕψ = χ, as in the left-hand diagram below. And an arrow θ: E G G F is cocartesian if it satisfies the dual universal property of cartesian arrows depicted in the right-hand diagram below. (1) Once we fix an arrow f : A G G B in B and an object F in E B , a cartesian arrow ϕ: E G G F over f is uniquely determined up to isomorphism, that is, if ϕ : E G G F is cartesian over f , then there is a unique vertical isomorphism ψ: E G G E such that ϕψ = ϕ . Clearly, every property of cartesian arrows applies dually to cocartesian arrows. So for an arrow f : A G G B in B and an object E in E A , a cocartesian arrow θ: E G G F over f is uniquely determined up to vertical isomorphism.
In the following, we often write cartesian arrows as _ ? and vertical arrows as 1 G G . (2) A cleavage for the fibration p is a choice of a cartesian lift for each arrow f : A G G B in B and object F in E B , and a cloven fibration is a fibration equipped with a cleavage. In a cloven fibration, for every f : assume that fibrations come with a cleavage.
Example 2.1. Let pAsm denote the category whose objects are pairs (A, α) where A is a set and α: A G G P (N) a function, and whose arrows are pairs (f , r) as in the diagram: is a function and r: a∈A α(a) G G b∈B β(b) is a total function obtained as the restriction of a partial recursive function to the two subsets such that for all a ∈ A and all n ∈ α(a) it holds that r(n) ∈ β(f (a)). Composition is (f , r)(f , r ) = (ff , rr ) The functor dom: pAsm G G Set acting as the first projection is a cloven fibration. Given a function f : x is over f . It is actually cartesian. Indeed for every (g, ψ): (g, ψ). For uniqueness, take (k, ψ ), from (g, ψ) = (f , id N )(k, ψ ) = (g, ψ ), follows ψ = ψ .
A fibration p: E G G B has finite products if the base B has finite products as well as each fibre E A , and each reindexing functor preserves products. Equivalently, both B and E have finite products and p preserves them, see (Hermida 1994, Corollary 3.7).
Notation 2.2. When we write 1 we refer to any terminal object in B and, similarly for objects A and B in B, when we write A × B, pr 1 : A × B G G A and pr 2 : A × B G G B, we refer to any diagram of binary products in B. Universal arrows into a product induced by lists of arrows shall be denoted as f 1 , . . . , f n , but lists of projections pr i 1 , . . . , pr i k will always be abbreviated as pr i 1 ,...,i k . In particular, as an object A is a product of length 1, sometimes we find it convenient to denote the identity on A as pr 1 , the diagonal A G G A × A as pr 1,1 and the unique A G G 1 as pr 0 . As the notation is ambiguous, we shall always indicate domain and codomain of lists of projections and sometimes we may distinguish projections decorating some of them with a prime symbol.
We shall employ a similar notation for terminal objects, binary products and projections in a fibre E A , as A , E ∧ A F, π 1 : E ∧ A F G G E and π 2 : E ∧ A F G G F, dropping the subscript in A and ∧ A when it is clear from the context. Moreover, given objects E in E A and F in E B , write for a product diagram of E and F in E, where we employed the notation introduced in (2) in the diagram on the right-hand side. Given a third object G and two arrows ϕ 1 : G G G E and ϕ 2 : G G G F, we denote the induced arrow into E F also as ϕ 1 , ϕ 2 .
Example 2.3. The fibration dom: pAsm G G Set introduced in 2.1 has finite products. Let h: N G G N × N be a recursive bijection and denote its inverse by k: The two projections are π 1 = pr 1 h and π 2 = pr 2 h. To verify that this is a product over A take (id A , r 1 ) and (id A , r 2 ) from (A, γ ) to the first and the second factor. The universal arrow is k r 1 , r 2 as if f is such that π 1 f = pr 1 hf = r 1 and π 2 f = pr 2 hf = r 2 , then hf = r 1 , r 2 , so f = khf = k r 1 , r 2 . The terminal object over A is A = (A, a → {0}) introduced in Example 2.1.
Recall from Streicher (2020) that an arrow ϕ: E G G F is locally epic with respect to p if, for every pair ψ, ψ : F G G F such that p(ψ) = p(ψ ), whenever ψϕ = ψ ϕ it is already ψ = ψ .
Take any s ∈ S. The arrow ( A , λx.s): A G G δ S A is weakly cocartesian over A in the sense that whenever one considers a situation as the one in the diagram below: there is an arrow (k, t): δ S A G G β in pAsm that makes the triangle commute (take as t the constant function whose unique value is r(0)). Fibrations are ubiquitous in mathematics and in this paper we are interested in those called elementary in Lawvere (1970), Jacobs (1999), and Maietti and Rosolini (2013a;2015) that encode the notion of equality as particular fibred left adjoints.

Remark 2.8. It is well known that for
(iii) (Loops are strictly productive) for every A, B in B the following diagram commutes Example 2.10. The fibration dom: pAsm G G Set as in 2.1 has strictly productive loops: let Notation 2.11. Let p: E G G B be a fibration with loops. Given E over A, we find it convenient to write δ E for the arrow pr We shall also need a parametric version of it. We write δ B E for the arrow pr , where θ: E G G pr 2,3 * I A is the unique arrow over pr 1,2,2 obtained by cartesianness of pr 2,3 * I A _ ? I A from the composite: and pr 1,1 pr 2 = pr 2,3 pr 1,2,2 : the class of arrows of the form pr 1,2,2 : Example 2.13. Consider the fibration dom: pAsm G G Set and loops as as in 2.10. Let h: Remark 2.14. The reader may have noticed that the condition of carriers is simply for objects in the fibre over A. But strict productivity of loops allows to generate carriers also in the fibre over B × A as follows. Given F an object in the fibre over B × A, one first considers the carrier t F : (pr 1,2 * F) ∧ I B×A G G F for the loop ρ B×A at F, which is an arrow in E over pr 3,4 : On the other hand, by strict productivity one obtains a composite arrow: Applying (pr 1,2 * F) ∧ − to it and post-composing with t F gives us the desired arrow pr 1,2 Applying the previous Remark 2.14 to the object A with parameter A as well, and taking K as F, one obtains an arrow: Remark 2.16. With the notation of Remark 2.15, the product I A I B is K pr 1 ∧ K pr 2 for pr 1 : A × B G G A and pr 2 : A × B G G B the two projections. From this, one obtains a commutative diagram: where pr 1 : I A×B G G I A and pr 2 : I A×B G G I B are as in Remark 2.15. When both ρ A ρ B and ρ A×B are locally epic, χ A,B and pr 1 , pr 2 are inverse of each other. The request of local epicity is necessary as one easily sees with the fibration in Example 2.4 taking loops with card (S) ≥ 2.
We are at last in a position to state the characterisation theorem that we shall use in the next section. Remark 2.19. Given a weak factorisation system (L, R ) on a category C with finite limits, there is a fibration R G G C and, in fact, a full comprehension category: The fibration R G G C always has strict productive transporters, but the loops are locally epic if and only if the left arrows r A in a factorisation of the diagonal pr 1,1 : solutions to lifting problems. It follows that the fibration R G G C is not elementary in general but it is so when, for instance, the weak factorisation system (L, R ) is an orthogonal factorisation system. We refer the interested reader to the examples and to Section 5 of Emmenegger et al. (2021).

Enriched Groupoids
Let C be a category with finite limits and let C -Gpd be the category of C -enriched groupoids and C -enriched functors with respect to the symmetric monoidal structure of C given by finite products. There is an algebraic weak factorisation system (L, R) on C -Gpd whose fibration of algebras for the monad on R is elementary and such that these algebras are the C -enriched isofibrations with a splitting. In the following, we present that algebraic weak factorisation system and describe the enriched isofibrations.
Recall that a C -enriched groupoid A consists of a set |A|, a family hom A (A, A ) A,A ∈|A| of objects of C , and three families: of arrows in C , where 1 is the terminal object of C , satisfying the usual equations. Given x: X G G hom A (A 1 , A 2 ) and y: consists of a function |F|: |A| G G |B| and a family of arrows in C satisfying the usual functoriality conditions. We may drop subscripts when these are clear from the context. The standard reference for enriched category theory is Kelly (1982), but see also Borceux (1994, Chapter 6). One difference with the general theory, which makes the groupoid case more manageable, is that the symmetric monoidal structure in C used for the enrichment is cartesian.

C -Gpd
G G Gpd . Recall that an algebraic weak factorisation system on a category C consists of a pair of functors L, R: C 2 G G C 2 that give rise to a functorial factorisation f = (Rf )(Lf ) of arrows of C , together with suitable monad and comonad structures on R and L, respectively, with a distributivity law between them. We refer the reader to Grandis and Tholen (2006), Garner (2008), and Bourke and Garner (2016) for a precise definition and the basic properties of algebraic weak factorisation systems. We shall denote as M the functor codL = domR: C 2 G G C . In particular, every f : X G G Y in C fits in a commutative triangle as shown below: Proposition 3.2. Let C be a category with finite limits. There is an algebraic weak factorisation system (L, R) on C -Gpd .
Proof. For a C -enriched functor F: A G G B between C -enriched groupoids, we begin by constructing the factorisation in (6).
Define the C -enriched groupoid MF as follows. The set |MF| consists of triples (A, B, 1 x −→ hom B (B, |F|(A))) with A ∈ |A| and B ∈ |B|, and whose family of hom-objects is given, on objects (A, B, x) and (A , B , x ), by the equaliser below: The three families of arrows in (5) is an iso in C and we may take the component (LF) A,A to be its inverse.
The actions of L and R extend to functors C -Gpd 2 G G C -Gpd 2 similarly.
Clearly, F = (RF)(LF). It follows that the functor R is pointed, with transformation Id . G G R given by L and, dually, that L is copointed.
The component of the multiplication μ: R 2 G G R on F is defined as follows. Elements of |MRF| are those ((A, x), y) where (A, 1 x G G hom B (B 1 , |F|(A)) ∈ |MF| and 1 y G G hom B (B 2 , B 1 )) maps an element of |MRF|. We define The action on arrows is induced by: The component of the comultiplication δ: L G G L 2 on F is defined as follows. Elements of |MLF| are those (A 1 , (A 2 , x), a) where A 1 ∈ |A|, (A 2 , 1 x G G hom B (B, A 2 )) ∈ |MF| and 1 a G G hom A (A 2 , A 1 ). Note that a induces a unique global element of hom MF ((A 2 , x), |LF|(A 1 )). We define The action on arrows is induced by: It is now not difficult to see that μ F and δ F are natural in F and make the pointed functor R into a monad and the copointed functor L into a comonad and, in fact, make L and R the underlying functors of an algebraic weak factorisation system on C -Gpd .
When the category C is the category Set of sets and functions, it is well known that the algebras for the monad on R are split (cloven) isofibrations, see e.g. van Woerkom (2021) (Chapter 7). In the enriched case, a definition of a fibration enriched over a suitable fibration T between monoidal categories is given in Vasilakopoulou (2018). Specialising to the case where T is the identity functor on a cartesian category C , this notion reduces to that of a fibration that is also a C -enriched functor. By further specialising to the case of isofibrations, one reaches the notion of C -enriched isofibration. As we show in Proposition 3.4, these are the algebras for the monad on R.
Let us first give an alternative characterisation of the C -enriched groupoid MF for a C -enriched functor F: A G G B. Its objects are triples (B 2 , B 1 , 1 y − → hom B (B 1 , B 2 )) and, unfolding (7), one sees that hom-objects consist of commuting squares in B. There is a C -enriched functor c B , d B : Iso(B) G G B × B where d B := RId B , the function |c B | maps (B 2 , B 1 , y) to B 2 , and (c B ) y,y := pr 1 e y,y : hom Iso(B) (y, y ) G G hom B (B 2 , B 2 ).
Given a C -enriched functor F: A G G B, there is a pullback in C -Gpd : where |c B |(A, B, x) = A and (c B ) x,x = pr 1 e x,x , the C -enriched functor F is the identity on objects and F x,x is the unique arrow induced by (F A,A × id)e x,x .
Note also that, since the global section functor : C G G Set preserves limits, the C -enriched groupoid MF is in fact the enrichment of the (Set -enriched) groupoid which appears in , Section 5) for the (Set -enriched) functor F.

Proposition 3.4. Let C be a category with finite limits. The algebras of the monad on R are the C -enriched split isofibrations, namely C -enriched functors F:
wherex is the global element induced on the equaliser (7) by the pair (1 A , x). Condition (i) holds by construction. As F c 0 (A,x),A • S x,1 |F|(A) = pr 2 • e x,1 |F|(A) , condition (ii) is satisfied. Condition (iii) follows immediately from the functoriality of S on identities since, for every (A, 1 x G G hom B (B, A)), the identity 1 (A,x) is the global element induced by the pair (1 A , 1 B ). Since Sμ F = SM(Id B , S), in particular it is c 0 (A, y · x) = c 0 (c 0 (A, x), y). Condition (iv) then follows from commutativity of the diagram: and using functoriality of μ F and S, as well as commutativity of hom MF ((A, 1 |F|(A) ), (A , 1 |F|(A ) )) which follows from S • LF = Id A . Thus F is an enriched split isofibration. Conversely, let F: A G G B be an enriched functor and let c: |MF| G G |Iso(A)| be as in the statement. We need to construct an enriched functor S: MF G G A that makes (F, S) an algebra for the monad on R.
Functoriality of S then follows from the groupoid laws of A. Condition (ii) ensures that S defines a morphism from F to RF over B and conditions (iii) and (iv) ensure that S is an algebra map.
Notation 3.5. We adopt the notation in Gambino and Larrea (2021) and denote as R-Alg G G C -Gpd the fibration of algebras for the monad on R.
Theorem 3.6. The fibration R-Alg The proof of Theorem 3.6 is given in the remainder of the section. Thanks to the characterisation of elementary fibrations in Theorem 2.17, it is enough to check that R-Alg G G C -Gpd has strictly productive transporters (see Definitions 2.9 and 2.12), which we do in Lemmas 3.7 and 3.9, and that certain arrows are locally epic in Lemma 3.10. Not only are these conditions easier to verify than the existence of left adjoints to certain reindexing functors, but Lemmas 3.7 and 3.9 also expose part of the structure that makes C -Gpd suitable to interpret Martin-Löf 's identity types. We elaborate on this in the next section.  ((B 2 , B 1 , y) (B 1 , B 2 )). and the family component on (y, b 2 , b 1 ), (z, c 2 , c 1 ) is the unique arrow in hom M c B ,d B ((y, b 2 , b 1 ), (z, c 2 , c 1 )) (s B ) (y,b 2 ,b 1 ),(z,c 2 ,c 1 ) e G G hom Iso(B) (y, y )×hom B (B 2 , C 2 )×hom B (B 1 , C 1 ) pr 2,3 hom Iso(B) (|s B |(y, b 2 , b 1 ), |s B |(z, c 2 , c 1 given by the universal property of the equaliser in the bottom row. It follows that is an algebra for the monad on R. Let now r B := LId B : B G G Iso(B). To have a loop on B, it is enough to show that (pr 1,1 , r B ): Id B G G c B , d B is a morphism of algebras from (Id B , RId B ) to I B , that is, that the diagram of C -enriched functor below commutes (pr 1,1 , r B On an object (B 2 , B 1 , y) it is On arrows from (B 2 , B 1 , y) to (B 2 , B 1 , y ), it amounts to the commutativity of the back square below, which follows from the commutativity of the front square, where we dropped indices from hom-objects, families of arrows and equalisers of the form (7): This choice of loops is strictly productive. Indeed, |Iso(A × B)| ∼ = |Iso(A)| × |Iso(B)| by Remark 3.1 and, for 1 x G G hom A (A 1 , A 2 ), 1 y G G hom B (B 1 , B 2 ), 1 x G G hom A (A 1 , A 2 ) and 1 y G G hom B (B 1 , B 2 ), because Remark 3.1 ensures that the corresponding equalisers are isomorphic. The isomorphism Iso(A × B) ∼ = Iso(A) × Iso(B) extends to an isomorphism of algebras: which clearly commutes with the loops.
Remark 3.8. The isomorphism in (9) is the same as the one arising in Remark 2.15. That this must be the case will be clear after we have proved that R-Alg G G C -Gpd is indeed elementary.
Lemma 3.9. Given an algebra (F: A G G B, S: MF G G A) in R-Alg, there is exactly one carrier for the loop (pr 1,1 , Proof. By Remark 3.3, we may assume, without loss of generality, that the underlying functor of the algebra pr 1  (A, B 1 , b 1 ) where the C -enriched functor T: MF G G A has to fit in the commutative diagram: and, since it has to be a homomorphism of algebras, the following diagram must commute Moreover, the strictness condition imposes that the diagram: shows that the only possible choice for T is the structural functor S: MF G G A, and it is straightforward to see that that choice makes diagrams (10) and (11) commute.
It follows from Lemma 3.7 and Lemma 3.9 that the fibration R-Alg G G C -Gpd has strictly productive transporters.
Recall the definition of the class of arrows p as in (4) of Notation 2.11. When p is the fibration R-Alg G G C -Gpd , it consists of those arrows of the form: (F, S) δ I F = (pr 1,2,2 , Id A , r B pr 2 F ) G G (pr 1,2 * (F, S)) ∧ (pr 2,3 for (F: A G G I × B, S: MF G G A) in the fibre of R-Alg over I × B. In the following, we simply write for this class.
As δ I F = (pr 1,2,2 , Id A , r B pr 2 F ), algebra morphisms out of ( c B , d B , s B ) are determined by their precomposition with δ I F . This concludes the proof of Theorem 3.6, that the fibration R-Alg G G C -Gpd is elementary.
Remark 3.11. The value of the left adjoint to reindexing along a parametrised diagonal pr 1,2,2 : I × B G G I × B × B at an algebra (F, S) over I × B is given by a cocartesian lift of pr 1,2,2 at (F, S), see Remark 2.8. By Theorem 3.6, the class provides a choice of cocartesian lifts. It follows that the value of the left adjoint at (F, S) is the codomain of the arrow δ I F in (12).
Remark 3.12. We have seen in Remark 2.19 that a sufficient condition for the right class of a weak factorisation system to give rise to an elementary fibration is the factorisation system being orthogonal. The underlying weak factorisation system of the a.w.f.s. on C -Gpd from Proposition 3.2 is not orthogonal and the above proof rather makes use of the structure given by the a.w.f.s. itself and, crucially, of the possibility to factor a suitable section of S D through M(Id I×B×B , Id A , r B pr 2 F ).

Enriched Groupoid Models of Identity Types
We have seen in the previous section that there is an algebraic weak factorisation system (L, R) on C -Gpd such that the fibration R-Alg G G C -Gpd is elementary. That fibration is also part of a comprehension category: where the functor U forgets the algebra structure.
When C is the category Set of sets and functions, the comprehension category (13) is equivalent to the Hofmann-Streicher groupoid model in Hofmann and Streicher (1998). The choice of a loop on a groupoid B given in the proof of Lemma 3.7 coincides with the interpretation, in the groupoid model, of the identity type and its reflexivity term on the type interpreted by B. In fact, strict productive transporters in R-Alg G G Gpd ensure that the upper component r B : of a loop (pr 1,1 , r B ): Id B G G I B has the left lifting property against algebras for the monad and, also, algebras for the pointed endofunctor (Emmenegger et al. 2021, Section 5). These lifts provide an interpretation for the eliminator of the identity type on B.
It is then natural to ask under which hypotheses on C the comprehension category of enriched groupoids in (13) interprets identity types. As described in Gambino and Larrea (2021) (Section 2), in the context of an algebraic weak factorisation system (L, R) on a category C with finite limits, an interpretation of the identity type can be obtained from a suitable functorial factorisation of diagonals A G G A × X A, for f : A G G X an object in C 2 . We hasten to add that definitions and results in Gambino and Larrea (2021) (Section 2) are cast in terms of algebras for R as a pointed endofunctor. Nevertheless, these definitions and results can be phrased and proved in terms of algebras for R as a monad as well, see van Woerkom (2021).
A functorial factorisation of diagonals in a category C with finite limits is a functor P: C 2 G G C 2 × C C 2 that maps f : A G G X to a factorisation of the diagonal A G G A × X A. Recall from Gambino and Larrea (2021) and van Woerkom (2021) that a stable functorial choice of path objects for an algebraic weak factorisation system (L, R) consists of a lift: of a functorial factorisation of diagonals P that is stable, in the sense that the right-hand component: maps cartesian squares to cartesian squares, that is, taking the right-hand component commutes with pullback. Note that the functorial factorisation of diagonals provided by the algebraic weak factorisation system itself does lift to a functor between algebras as above, simply by equipping its values with the cofree and free structure, respectively. However, it is an observation that goes back to van den Berg and Garner (van den Berg and Garner 2012, Remark 3.3.4) that this factorisation of diagonals is seldom stable as free structures need not be stable under pullback. In what follows, we investigate how to obtain a stable functorial choice of path objects for the algebraic weak factorisation system on C -enriched groupoids described in the proof of Proposition 3.2 from the elementary structure on R-Alg Proposition 4.1. Let C be a category with finite limits. The algebraic weak factorisation system (L, R) on C -Gpd from Proposition 3.2 has a stable functorial choice of path objects.
Proof. The choice of loops given in the proof of Lemma 3.7 provides a factorisation of diagonals over terminal arrows: and, as loops are cocartesian arrows, this assignment extends to a functor: In order to extend this functor further to a functorial factorisation of diagonals C -Gpd 2 G G C -Gpd 2 × C -Gpd C -Gpd 2 , consider the set: for F: A G G X an object in C -Gpd 2 . There is an obvious inclusion |V|: |P F A| G G |Iso(A)|, and functions |r F |: |A| G G |P F A| and |I F |: |P F A| G G |A × X A| mapping A to (|F|(A), A, A, 1 A ) and (X, A 1 , A 2 , a) to (X, A 1 , A 2 ), respectively. Note that for (X, A 1 , A 2 , a), (X , A 1 , A 2 , a ) ∈ |P F A|. Defining hom P F A (a, a ) := hom Iso(A) (a, a ), we obtain a C -enriched category P F A and a C -enriched functor V: P F A G G Iso(A) which is full, faithful and injective on objects, that is, P F (A) is a C -enriched full subcategory of Iso(A). These fit in a pullback square in C -Gpd which is the one in the back of diagram (??). It is then easy to see that the functions |r F | and |I F | extend to C -enriched functors making the diagram (??) commute: The assignment F → (r F , P F A, I F ) is easily seen to be functorial. To see that it is also stable, it is enough to observe that, whenever the left-hand square in C -Gpd below is a pullback, so is the right-hand square: Therefore we have constructed a stable functorial factorisation of diagonals P: To obtain a stable functorial choice of path objects it is enough to equip I F and r F with algebra and coalgebra structures, respectively, for F a C -enriched functor.
For the former, by functoriality of F the function |s A |: |M c A , d A | G G |Iso(A)| restricts along the inclusion |V|: |P F A| G G |Iso(A)| as shown below: where an element of |MI F | consists of an element (X, A 1 , A 2 , a) ∈ P F A, an element (X , A 1 , A 2 ) ∈ |A × X A| and a triple 1 A 2 ) such that F A 1 ,A 1 a 1 = x = F A 2 ,A 2 a 2 , and it is sent by |s F | to (X , A 1 , A 2 , a 1 · a · a 2 i ). As P F A is a C -enriched full subcategory of Iso(A), the component of s F on a pair of elements of |MI F | is simply given composing the corresponding components of M(F × F, V) and s A . It is straightforward to check that the pair (I F , s F ) is an algebra for the monad on R.
To construct a coalgebra structure on r F , note that an element of |Mr F | consists of A ∈ |A|, (X, A 1 , A 2 , a) ∈ |P F A| and a pair 1 a 1 ,a 2 −−−→ hom A (A 1 , A) × hom A (A 2 , A) such that a 2 · a = a 1 .
Consider the function |t F |: |P F A| G G |Mr F | that maps (X, A 1 , A 2 , a) to (A 2 , (X, A 1 , A 2 , a), 1 a,1 A 2 − −−− → hom A (A 1 , A 2 ) × hom A (A 2 , A 2 )). The component of t F on a pair (X, A 1 , A 2 , a), (X A 1 , A 2 , a ) is the arrow induced by the equaliser defining hom Mr F as depicted below: hom Mr F ((A 2 , a, a, 1 A 2 ), (A 2 , a , a , 1 A 1 )) e hom A (A 2 , A 2 ) × hom P F A (a, a ) ( a, 1 A 2 !) · pr 1 , pr 1 pr 2 · ( a , 1 A 2 !) hom P F A (a, 1 A 2 ) A comprehension category is suitable to interpret identity types if it has a pseudo-stable choice of Id-types, see Gambino and Larrea (2021) (Definition 1.4). Indeed in this case, its right adjoint splitting can be equipped with a strictly stable choice of Id-types that allows for a sound interpretation of identity types, see Gambino and Larrea (2021) x x r r r r r C -Gpd has a pseudo-stable choice of Id-types. Hence, its right adjoint splitting models identity types.
Proof. Proposition 59 in van Woerkom (2021) ensures that a stable functorial choice of path objects in R-Alg G G C -Gpd yields a pseudo-stable choice of Id-types in the associated comprehension category (13). It thus follows from Proposition 4.1 that the comprehension category associated with the fibration R-Alg G G C -Gpd has a pseudo-stable choice of Id-types. By Gambino and Larrea (2021) (Proposition 1.9 and Theorem 1.6), its right adjoint splitting models identity types.

Iterations of Enrichment
In this section, we intend to analyse the enrichment over the category Gpd of groupoids themselves. The first direct consequence of Theorem 3.6 is the following.
Theorem 5.1. The fibration R-Alg G G Gpd -Gpd is elementary.
Proof. As remarked in Remark 3.1, the category Gpd has limits.
Remark 5.2. One may wonder if there is any gain in enriching over the category Cat of all categories. But Cat -Gpd = Gpd -Gpd . Indeed, Gpd -Gpd is clearly a full subcategory of Cat -Gpd . But a Cat -enriched groupoid is a 2-category with an inverse: Since the category Gpd -Gpd has finite limits by Remark 3.1, one sees immediately that there is the possibility to iterate the last two results. Write nGpd for the category of n-groupoids, that is, let 0Gpd be the category Set and let (n + 1)Gpd be the category of nGpd -enriched groupoids. Write (L n+1 , R n+1 ) for the algebraic weak factorisation system on (n + 1)Gpd from Proposition 3.2.
Theorem 5.4. The fibration R n+1 -Alg G G (n + 1)Gpd is elementary and the comprehension category associated with the fibration R n+1 -Alg G G (n + 1)Gpd has a pseudo-stable choice of Id-types.