Quotient inductive-inductive types

In type theory one usually defines data types inductively. Over the years, many principles have been invented, such as inductive families, and inductive-recursive and inductive-inductive definitions. More recently, higher inductive types have been proposed in the context of homotopy type theory. Specific instances of higher inductive types have been successfully used in formalisations of homotopy theory and in formalising type theory in type theory. However, a general definition and theory of higher inductive types is still lacking. As an intermediate goal, we give a principle which unifies ordinary, indexed and inductive-inductive definitions, extended with path constructors from higher inductive types, but with no non-trivial structure between paths, i.e. we consider sets only. For this reason, we call these types quotient inductive-inductive types. We give an initial algebra semantics for these definitions, give the induction principle, and show that these two interpretations coincide.


Introduction
Martin-Löf Type Theory [29] is a powerful functional programming language with a very expressive type system.Implementations of Type Theory such as Agda [31], Coq [10] and Idris [11] extend the basic system with mechanisms for defining data types in order to increase the strength and expressiveness of the language.These extensions are justified by theoretical work on definitional principles in Type Theory, such as inductive families [14,17], and inductive-recursive [18,19] and inductive-inductive [5,30] definitions.Here, inductive-recursive means the definition of an inductively generated type A, simultaneously with a recursively defined [Copyright notice will appear here once 'preprint' option is removed.]family B : A → Set indexed by A, while inductive-inductive means that both A and B are inductively generated.One can also imagine more complicated dependency structures, such as e.g.B : A × A → Set, or a further family C : (x : A) → B x → Set.Furthermore, constructors can refer to previously given constructors in their type.
Recently, new models of Type Theory based on homotopytheoretic ideas [8,36,38] have given rise to a new kind of data types called higher inductive types [35].Specific instances of higher inductive types have been successfully used in synthetic homotopy theory [22,[24][25][26], as well as computer science applications [3,7], and a restricted class of higher inductive types has been studied by Sojakova [33].However, a general definition and theory covering all higher inductive types is still lacking.In this paper, we move significantly beyond the current state-of-the-art and give a definition that works for arbitrary higher inductive types, under the simplifying assumption of uniqueness of identity proofs, i.e. we consider only types with trivial higher-dimensional structure.We give a principle which unifies ordinary, indexed and inductiveinductive definitions with arbitrary dependency structure, extended with path constructors from higher inductive types.Because of our assumption of trivial higher-dimensional structure, such paths only serve to identify elements, and we call the resulting types quotient inductive-inductive types.
Our definition of quotient inductive-inductive types takes the form of a data type of descriptions of such types within Type Theory itself.Such an internal representation has several advantages: (i) it gives a small core type theory, easy to comprehend and implement [13]; (ii) it opens up the possibility for generic programming [9], e.g.deriving functoriality or decidable equality for a data type by writing a program manipulating descriptions; and (iii) all results we prove about quotient inductive-inductive types are automatically valid in all models of the theory.Our main result is an equivalence between the dependent induction principle for quotient inductive-inductive types and an initiality principle from initial algebra semantics.

Examples
To show that interesting structures can be encoded using quotient inductive-inductive types, we give some examples.

Type theory in type theory
The quintessential example of an inductive-inductive definition is the syntax of Type Theory itself.If we take the rules of Type Theory and write them down as a bunch of mutually dependent inductive types, we naturally see constructors referring to "previous" con-

Cauchy reals
If one wants to define the real numbers as Cauchy reals (i.e. the Cauchy completion of Q) in Type Theory, there are several choices to be made.Classically one takes the set of Cauchy sequences and quotients it by a relation.Showing that this quotient is Cauchy complete then requires us to use the axiom of countable choice.As described in the HoTT book [35], using quotient inductive-inductive types, we can define the set of Cauchy sequences and the relation mutually, quotienting "at the same time" as doing induction.This approach then avoids having to use countable choice to show 1 Our notational conventions will be explained in Section 1.3.
Cauchy completeness.In a little more detail, we mutually define . . .Note that we refer to Q and Q+: these types can be defined as quotients themselves, but they can also be defined directly without needing quotients [4].

Quotients
Of course, a simple example of a quotient inductive-inductive type (which is not inductive-inductive, but just inductive) is the definition of a quotient: Using quotients, we can define an interval type I :≡ 2/R by quotienting the type 2 of Booleans by the relation R that relates true and false only.Hence, we see that adding quotient inductive-inductive types is not a conservative extension of Type Theory, because an interval type can be used to derive function extensionality [21,32].The quotient of A by the relation R can be regarded as the coequaliser of the diagram where and the two arrows π and π are the obvious projections.
Therefore, using Σ-types and quotients we can obtain any colimit in Set, since any colimit can be written as a coequaliser of coproducts.

Infinitely branching trees
To illustrate that quotient inductive types are strictly more expressive than quotient types combined with inductive types, we consider a type of infinitely branching trees where the order of the subtrees is irrelevant.Using quotient types, we can first define the type of trees data T0 : Set where leaf0 : T0 node0 : (N → T0) → T0 and then quotient it by the relation R which relates node0 f and node0 (f • g) for every f : N → T0 and bijection g : N → N in order to get a candidate type T :≡ T0/R.We can easily define leaf : T by leaf :≡ [ leaf0 ], but if we try to lift node0 to node : (N → T) → T, we run into problems: in order to define node f , we need to get our hands on a representative in T0 for each f n.For finitely branching trees, this can be achieved by sequentially iterating the eliminator for the quotient type depending on the branching factor, but this clearly breaks down for infinitely branching trees.In fact, the assumption that quotients lift to function spaces in general is equivalent to the axiom of choice [21], which is a constructive taboo since it implies the law of excluded middle [15].However, if T is defined by the following quotient inductive definition, the problem disappears altogether:

Contributions
• We give a grammar for formally specifying inductive-inductive types with arbitrary dependency structure in Type Theory; such a specification is given by specifying its dependent sorts (what the types and families over types we are defining are and how they depend on one another), together with a list of constructors.• We further extend the specification to also encompass path constructors from Homotopy Type Theory, resulting in a a grammar for quotient inductive-inductive types.• We give a categorical characterisation of the induction principle and give a general proof that this characterisation coincides with initiality.
• We prove that the category of algebras arising from a quotient inductive-inductive definition satisfies the categorical characterisation of the induction principle, which shows that a quotient inductive-inductive type satisfies the abstract induction principle if and only if it describes an initial algebra.• We finally sketch how one can derive the traditional induction principle from the categorical characterisation.

Preliminaries and notation
We work in Martin-Löf Type Theory, mostly using Agda syntax.We write (x : A) → B for the dependent function type and (x : A) × B for the dependent pair type.The keyword data is used to declare inductively defined types.Like in Agda, we use mixfix notation when convenient, and use underscores to indicate the placement of arguments, e.g.we wrote , for the context extension in Section 1.1.We write * for the unique inhabitant of the unit type 1, and also for the unique object of the terminal category.The identity type (propositional equality) is denoted by =, while we write ≡ for judgemental (definitional) equality.We assume function extensionality (as remarked in Section 1.1.3,this follows in any case in the presence of quotient types), but not the univalence axiom.In fact, we will usually assume Uniqueness of Identity Proofs, which is incompatible with the univalence axiom.
We discuss how this restriction can be lifted in Section 5. We write A : Set to indicate that A is a type with unique identity proofs, and A : Type if we really mean that A is a type possibly without UIP.As is standard, we employ a hierarchy of universes Set0 : Set1 : . .., but will leave the universe levels implicit.
Given a category C : Cat, we denote the type of objects of C as |C| : Set and for any objects X, Y : |C| its hom-sets as C(X, Y ) : Set.

Defining quotient inductive-inductive types
When we specify an inductive type in a proof assistant, we write down type formation rules (the sorts of the inductive definition) and list the introduction rules (the constructors).However, the type formation and introduction rules are not enough -apart from constructing the data, we also want to manipulate it: we need an induction principle.The shape of this elimination rule can be mechanically derived from the introduction rules, as we will see in Section 3. In this section, we focus on the formation and introduction rules.The inductive definitions we describe here differ from ordinary inductive definitions in three ways: • We may define several types and type families mutually; instead of defining a single type (family), we have a collection of dependent sorts.
• Constructors may refer to any preceding constructors.
• We do not only allow for constructors to construct points, but also paths (or equations) between points.

Specifying Set-sorted inductive-inductive definitions
As a first step, we show how to specify inductive-inductive definitions with arbitrary dependency structure, but without path constructors, before tackling the general case in Section 2.3.

Dependent sorts
Quotient inductive definitions can define several mutually dependent types and type families.Hence, before we can talk about constructors, we need to be able to specify what the types and the dependencies between them are.For example, the inductiveinductive definition of contexts and types in a context defines a type Con : Set along with a family on Con, namely Ty : Con → Set.
We call the collection (Con, Ty) the sorts of the definition.Since it is not just a collection of types, but we may also have families over previous types, we speak of dependent sorts, since new sorts may depend on any of the previous sorts in various ways.One additional example is Rel, where the sort consists of (X : Set) × (Y : X → X → Set), i.e. a type X together with a (possibly proof-relevant) relation Y on it.Sorts do not only determine the formation rules of the inductive definition, but also the type of the eliminator.For instance, the Setsorted inductive definition of the natural numbers comes with a recursion principle which gives a way to define functions N → X for types X : Set, while for contexts and types (Con, Ty), the recursion principle enables the definition of a function f : Con → X together with a dependent function g : (Γ : Con) → Ty Γ → Y (f x) for families X : Set, Y : X → Set.For this reason, it is not enough to specify a type of sorts -in order to take the shape of the elimination rules into account, we need to specify a category.
Describing how a sort depends the previous sorts can be done by providing a functor of the previous category of sorts into Set.A complete description is then a snoc-list of functors, which can be formalised inductive-recursively together with the function that interprets the list as a category.with nil defined as the terminal category 1, and given S : Sorts and R : Func S Set, snoc S R has: • objects: Example 2. The sort of an ordinary inductive definition can be represented by the list [R0] (i.e.snoc nil R0) where R0 : 1 → Set is defined by R0 x :≡ 1.The resulting category R0 has objects ( * : 1) × (A : 1 → Set) and a morphism (x, A) → (y, B) is given by, since trivially x = y = * , a trivial morphism * → * together with a function f x : A x → B x for every x : 1.In other words, this category is equivalent to the category Set.
Example 3. The sort of the context and types example (Con, Ty) can be represented by the list [R0, R1] with The category R0, R1 has objects (x : 1)×(A : 1 → Set)×(B : A x → Set).We see that this category is equivalent to the category Fam of families of sets.
Example 4. Similarly, the category Rel can be represented by the list [R0, R1] with We see that R0, R1 is equivalent to the category with objects given by f : X → Y together with g : (x y : A specification S = [R0, . . ., Rn] : Sorts defines a chain of categories where n is the number of functors in the list and Si = R0, . . ., Ri is the category of sorts truncated to the first i elements.Every ti is the forgetful functor that maps (X, Y ) to X.
Example 5.In the case of Rel, we get the sequence When giving a quotient inductive-inductive definition, we start out by defining its sorts.When specifying a constructor, we need to say what sort we want to construct points or paths in.To this end, we can define a membership relation We can avoid induction-recursion here by instead defining Sorts as a list of functors along with a proof that the domains of these functors are correct.
where C ∈ S means that C appears in the chain 1 ← S0 ← . . .← Sn corresponding to S, ı.e C is either 1, or Si for some 0 ≤ i ≤ n.For a quotient inductive-inductive definition with sorts S : Sorts, specifying the sort for a constructor is done by giving a category A : Cat along with a proof of A ∈ S.

Specifying constructors referring to previous constructors
Let us consider again our definition of the family (Con, Ty) of contexts and types in a context.Since we are defining this family inductively, one might at first think that it should be definable as the initial algebra of an endofunctor on Fam.However, if we look at the constructor 'Π with type we see that it refers to not only elements of Con and elements of fibres of Ty, but also to a previously introduced constructor, namely the context extension constructor , .An endofunctor on Fam only allows us to refer to the types being defined, but not the constructors acting on them.
Referring to previous constructors is a phenomenon that pops up also for higher inductive types, e.g. in the higher inductive definition of the circle: We have a constructor for the base point and a path constructor loop that connects that point with itself.The end points of the path constructor refer to the previous constructor base.
As opposed to having one functor specifying the arguments of all the constructors, we will have a separate functor for every constructor.The domain of such a functor will not be just the category of sorts (such as Set or Fam), but the "category of algebras of all previous constructors".To illustrate this concept, we consider the following (rather silly) example (which can be shown to be equivalent to the Booleans): The arguments of constructor a can be defined by the endofunctor F0 X :≡ 1 on Set.The arguments of b can then be defined by a functor F1 : F0−alg → Set: Since F1 is not an endofunctor, we cannot describe T with both its constructors as an algebra.However, the category F0−alg comes equipped with another functor into Set, namely its forgetful functor U : F0−alg → Set which gives us the carrier of the algebra.We can then think of (T, a, b) as an initial (F1, U0)-dialgebra [20].
Definition 6.Let F, G : C → D be functors.The category (F, G)−dialg has as objects pairs (A, f ) where A : |C| and f : The category of dialgebras also has a forgetful functor U1 : (F1, U0)−dialg → Set.If we were to add a third and a fourth constructor, we would have to define a functors F2 : (F1, U0)−dialg → Set and F3 : (F2, U1)−dialg → Set, and so on.Note that we build the category of dialgebras over another category of dialgebras, i.e. we are working with iterated dialgebras.
Giving a specification of a quotient inductive-inductive definition is very similar to describing the sorts: we have a list of constructor specifications, each of which depends on the interpretation of all the constructors preceding itself.For definitions which have sort Set and no path constructors, we can formalise the type of specifications using the following inductive-recursive definition: Definition 7. The specification of a Set-sorted inductive-inductive definition and its category of algebras and underlying carrier functor is given by the following inductive-recursive definition 3  An object in Alg [F 0 ] consists of a set X : Set and elements a : 1 → X and b : ((x : X) × (a * = x)) → X.
In Section 2.3 we will see how this definition can be generalised to arbitrary sorts, also allowing path constructors.

Path constructors
Apart from having constructors that construct points of any of the types involved in the definition, we may also use path constructors to construct paths between points.One example of an inductive definition with a path constructors is the interval I, defined by data I : Set where zero : I one : Here, seg is a path constructor, since it constructs a path with endpoints zero and one.In this example, the path constructor seg does not have any arguments and only refers to previous constructors, which also happen to have no arguments, but in general, a path constructor may of course take arguments, and the end points can be some complicated combination of arguments and previous constructors.To describe a path constructor we therefore have to supply two pieces of data: a functor describing its arguments and a way to relate the arguments to points in the type being defined, which will be the end points of the path it constructs. 3Induction-recursion can be avoided here in the same way as with Sorts

A Rel-sorted quotient inductive-inductive definition
In this section we will give an example of how the specification and the categories of algebras look like for the following quotient inductive-inductive definition:

Specifying sorts
We see from the type of A and B that we want the category of sorts to be Rel from Example 4, i.e. the category with objects (X : i.e. functions f that preserve relatedness.The category Rel comes equipped with a forgetful functor W : Rel → Set.The first category of algebras (with no constructors) is the category of sorts, so we have Alg 0 = Rel.

Specifying constructors
The first constructor c0 has no arguments and is of sort A : Set.Its arguments can be described by the functor F0 : Rel → Set with F0 (X, R) :≡ 1.The category of algebras for the first constructor is then (F0, W )−dialg. Strictly speaking, an (F0, W )-dialgebra structure on a relation (X, R) is a function 1 → X, but for this example we will work with the equivalent definition |Alg 1 | ≡ (X : Set) × (R : X → X → Set) × (θ0 : X).Morphisms (X, R, θ0) → (Y, S, ρ0) consist of: We see that we get a morphism in Rel along with a computation rule that tells us that the morphism in Rel preserves the (F0, W )dialgebra structure.Note that F0 is a functor from Rel to Set and is not an endofunctor on Set: the constructor may refer to elements of fibres of the relation X → X → Set being defined.The category Alg 1 also comes with a forgetful functor U1 : Alg 1 → Alg 0 defined by U1((X, R), θ0) :≡ (X, R) -in fact, every category of algebras Alg i+1 has a similarly defined forgetful functor Ui+1 : Alg i+1 → Alg 0 .
For the second constructor c1, the specification is largely similar: it is given by the functor F1 : Alg 1 → Set defined by F1 (X, R, θ0) :≡ 1.
The third constructor c3 is a path constructor.Hence, not only do we need to supply a functor F3 : Alg 3 → Rel to specify the arguments, but we also need to specify the endpoints of the path.Just as for c2, we will first need to rewrite the type of the constructor.We denote again by θ 2 the Henry Ford-version of θ2.We then have that the type (n : N) → θ2 n = θ2 (n + 1) is equivalent to the type The endpoints can then be specified as natural transformations l, r : F3 → U3, where F3 : Alg 3 → Rel is defined in a way similar to F2.Given an algebra A : Alg 3 , lA and rA both define a morphism in Rel.l ((X,Y ),θ 0 ,θ 1 ,θ 2 ) and r ((X,Y ),θ 0 ,θ 1 ,θ 2 ) are defined as ((X,Y ),θ 0 ,θ 1 ,θ 2 ) a b (p, q, n) :≡ θ 2 a b p q (n + 1) By function extensionality, we can then say the category of algebras Alg 3 has objects (X : |Alg 2 |)×(θ3 : lX = rX ), i.e. it is a equaliser category.The morphisms are just morphisms in Alg 2 with no extra structure.For higher inductive types, one usually expects a path computation rule for any path constructor, but as we are working with sets, equalities between paths are trivial.

Specifying arbitrary quotient inductive-inductive types
We have already seen how Set-sorted inductive-inductive definitions can be formalised.Generalising this to arbitrary quotient inductive-inductive definitions means that we have to generalise in two aspects: we have to be able to deal arbitrary sorts, as well as with path constructors.
Let S : Sorts be a specification of sorts.Recall that we have a predicate A ∈ S that tells us that A : Cat is one of the sort categories in S. Specifying a constructor now requires us to specify a sort, which is done by using the predicate.The type of quotient inductive-inductive specifications is then refined to the following definition: The recursive functions Constr0, Constr1, Alg and U will be defined in the remainder of this section.
Let us briefly discuss the defining clauses for Constr s A p, which is meant to describe the data needed to specify a constructor of sort A. There should not be any constructors of the trivial sort A = 1, and if A is a non-trivial sort, then a constructor can either be a point constructor specified by Constr0 s A p, or a path constructor specified by Constr1 s A p. The next two subsections will describe the data needed for point and path constructors respectively.

Point constructors
Suppose we have Si ∈ S and s : Spec, and we have already constructed • Alg s : Cat, • Us : Alg s → S its forgetful functor, and • the extension Ūs : Alg s → Si of Us, which we get from Si ∈ S.
Recall that Ri : Si−1 → Set is the functor that describes how the family Xi depends on the previous sorts X0, . . ., Xi−1.A point constructor structure on X is of the form Note that the functor Ūs can be decomposed into two parts: we have Ū0 : Alg s → Si−1 and Ū1 : (X : Alg s ) → Ri ( Ū0 X) → Set.Ū0 can also be written as ti • Ūs, where ti : Si → Si−1 is the forgetful functor of Si.In order for the point constructor specified by F1 to be well-defined, i.e. to make sense of its computation rule, we need F X :≡ ( Ū0 X, F1 X) to be a functor Alg s → Si.This leads us to the definition of a point constructor specification: Definition 10.Given a specification s : Spec, a point constructor of sort Si ∈ S is specified by giving a functor F : Alg s → Si such that the following commutes: In other words, we have Constr0 s Si p :≡ (F : The fact that F must satisfy the commutativity condition intuitively means that F leaves the sorts (X0, . . ., Xi−1) "untouched".
We now explain how to construct the category Alg s of algebras for a an specification with an additional point constructor.Suppose the specification s has been obtained as the extension of a specification s by a point constructor given by a functor F : Alg s → Si, which decomposes as F = ( Ū0, F1).The previous characterisation of a point constructor algebra structure on an object X : |Alg s | can be summarised as having a dependent function of morphisms A morphism (X, θ) → (Y, ρ) consists of a morphism f : Alg s (X, Y ) along with a "computation rule": This category of algebras look similar to (F, Ūs)−dialg.However, as we have seen previously, the category of dialgebras contains too much: morphisms there also come with a superfluous endomorphism in Si−1.We want this morphism to be an identity morphism, which we can achieve by taking an equaliser.The category (F, Ūs)−dialg comes with two forgetful functors: V that gives us the carrier of the algebra and V I that gives us algebra structure on the carrier, which is a morphism in Si or equivalently, an object in the arrow category S I i .The definition of the new category of algebras is as follows: Definition 11.Let s : Spec be the specification s extended with a 0-constructor of sort Si given by a functor F : Alg s → Si satisfying ti • F = ti • Ūs.The category of algebras Alg s is as the following equaliser in Cat: where e is the projection map of the equaliser, t I i is the functor ti lifted to a functor between the respective arrow categories and id is the functor that assigns to each object the identity morphism of that object.
The forgetful functor U s : Alg s → S is defined as the composite:
Algebra morphisms (X, θ) → (Y, ρ) are simply morphisms X → Y in Alg s .As we are working with sets, we do not need computation rules for the paths: any equation between paths is trivial.
Summarising the above, we get to the following definition of 1-constructor specification: Definition 12.Given a specification s : Spec, a 1-constructor of sort Si ∈ S is specified by a functor F : Alg s → Si satisfying ti • F = ti • Ūs and two natural transformations , r : F → Ūs satisfying ti = ti r = id t i • Ūs , i.e.

Constr1 s Si p :≡ (F :
The restriction on the natural transformations and r is the same kind of restriction as the restriction on F : the natural transformations must leave the sorts below Si untouched. Note that by function extensionality, the type of θ in ( 3) is equivalent to l 1 X = r 1 X .Since ti (l X) = ti (r X) = id t i • Ū , the equality l1 X = r1 X of dependent functions in Set is equivalent to the equality l X = r X of morphisms in Si.We also observe that a natural transformation α : F → Ū gives rise to a functor α : Alg s → S I i , mapping X : |Alg s | to αX : Si(F X, Ū X).Functoriality of this functor comes from the naturality of α.This leads us to the definition of the category of algebras for a path constructor: Definition 13.Let s : Spec be the specification s extended with a path constructor of sort Si given by a functor F : Alg s → Si satisfying ti • F = ti • Ūs and natural transformations l, r : F → Ūs satisfying ti l = ti r = id t i • Ūs .The category of algebras Alg s is defined as the following equaliser in Cat:

The induction principle and initiality
So far we have seen how to specify a quotient inductive-inductive type by specifying a sort and listing its constructors.We have seen what the categories of algebras are for such a specification.
As such, we have given the type formation rules (objects of the sort categories) and the introduction rules (the algebra structure).
We have not yet fully addressed the elimination rules and the corresponding computation rules.In this section we will give a categorical version of the induction principle for an algebra, and show that it coincides with the property of initiality.This proof can be done abstractly after proving that the categories of algebras have certain limits.We will conclude this section by sketching how one can derive a traditional induction principle from the categorical version.
The induction principle gives us a way of showing that predicates on an inductive type hold for all elements of that type.For example, if we have a predicate P : N → Set (also called the motive of the induction) on the natural numbers, and given • mzero : P zero, • msucc : (n : N) → P n → P (succ n), the induction principle states the existence of a dependent function s : (x : N) → P x.This function comes with a computation rule for every method: We can think of the triple (P, mzero, msucc) as an algebra family over the algebra (N, zero, succ), i.e. we have (P, mzero, msucc) : Fam Alg λX.1+X (N, zero, succ), where Fam Alg λX.1+X (X, θ0, θ1) :≡ (P : X → Set) Similarly, dependent functions (x : X) → P x for a predicate P : X → Set correspond to sections of the function p : Y → X corresponding to P .The notion of function into X and section readily generalises to any category.We can then state the induction principle for an algebra as the following section principle: any algebra fibration has an algebra section.Definition 14.The section principle for an object X in a category C says that for every Y : |C| and p : C(Y, X), there exists s : C(X, Y ) and a proof of p • s = idX , i.e. that there is a term

Initiality and the section principle coincide
The section principle can be stated for any category, so we do not have to work with the details of the categories of algebras.Assuming a bit more structure of the category, namely that finite limits, we can show that an object satisfies the section principle if and only if it is an initial object.
Proof.Assume X is initial.Given a morphism p : Y → X, we need to produce a morphism s : X → Y such that p • s = idX .Since X is initial, we get for any Y a unique arrow X → Y .If we postcompose this with p, we will get a morphism X → X, which by initiality has to be the identity morphism.
Lemma 16.Let C : Cat and assume C has finite limits.If X : |C| satisfies the section principle, then X is initial.
Proof.Given Y : |C|, we need to provide a unique arrow X → Y .Consider the projection π1 : X × Y → X, which is an arrow into X and therefore has a section s : X → X × Y .Our candidate arrow is then π2 • s : X → Y , which we have to show is unique.
Using equalisers, we can show that any two arrows f, g out of X to some other object Y are equal: Let E be the equaliser of f and g, then we get a projection map i : E → X.By the section principle, this map has a section s : In the rest of this section, we show that the categories of algebras we are working with have products and equalisers, and hence satisfy the assumption of Lemma 16.This can be done by induction on the specification, i.e. by induction on the number of constructors.We will see that we also need that the forgetful functors into the category of sorts preserve these limits, which we can prove simultaneously with the construction of the limits.For a quotient inductive-inductive type with no constructors, the category of algebras is the category of sorts, so we first show that this category has finite limits.
Lemma 17 (Limits in the category of sorts).For each sort S : Sorts, the category S has products and equalisers.
Proof.We proceed by induction on the specification of sorts S : Sorts.If S = nil, then S = 1, which trivially satisfies our criteria.In the induction step case, we have a category Si which is built out of the previous category of sorts Si−1 : Cat with Ri : Si−1 → Set.By the induction hypothesis Si−1 has products and equalisers.We can then define products in Si as follows: suppose (X, Y ), (Z, W ) : |Si|, i.e.X, Y : |Si−1| and Y : RiX → Set, W : RiZ → Set, since Si−1 has products, we can define: where Y × W : Ri(X × Z) → Set is defined pointwise as: The definition satisfies the universal property of products, which can be shown by appealing to the universal properties of products in Si−1 and Set.
Equalisers can be constructed in a similar way, however it involves equalities between morphisms.Suppose (f, f ), (g, g ) : Si((X, Y ), (Z, W )), then we have by function extensionality and using that an equality of pairs is equivalent a pair of equalities: where we denote the action of Ri on a proof of equality p : f = g by Ri(p) x : Ri(f ) x = Ri(g) x.Since f x y : W (Ri(f ) x) and g x y : W (Ri(g) x), we have to transport (or coerce) the left hand side of the equation along the equality Ri(p) x.Given (f, f ), (g, g ) : Si((X, Y ), (Z, W )), by the induction hypothesis we get an equaliser E : |Si−1| with a projection map e : Si−1(E, X).This equaliser comes equipped with a proof p : f • e = g • e.The equaliser is then defined as (E, F ) with: with (e, e ) : Si((E, F ), (X, Y )) the projection morphism where e x (y, p) :≡ y Showing that (f, f ) • (e, e ) = (g, g ) • (e, e ) is then straightforward.The universal property can be shown similarly to that of the product: we have to appeal to the universal properties of equalisers in Si−1 and Set.
When specifying a quotient inductive-inductive type with at least one constructor, we also need the category of algebras to have finite products.
Lemma 18 (Limits in the category of algebras).For each sort S : Sorts and specification s : Spec, the category of algebras Alg s has products and equalisers.Furthermore, the forgetful functor Us : Alg s → S preserves finite limits.
Proof.We prove both properties simultaneously by induction on s : Spec.For the empty quotient inductive-inductive type specification, the first statement is Lemma 17, and the forgetful functor of the category of algebras into the category of sorts is the identity functor, which trivially preserves limits.By the way the limits here are constructed, the functor ti : Si → Si−1 also preserves them.This means that if we have a forgetful functor U : Alg s → S for some s : Spec, then for any Si ∈ S, the extension Ū : Alg s → Si of U also preserves products and equalisers.
For the induction step case, we have a specification s : Spec such that Alg s : Cat has products and equalisers and the forgetful functor U : Alg s → S preserves them.To define a constructor on s, we need to specify its sort first.Suppose we have Si ∈ S, then either Si = 1 or Si is built out of Si−1 with some functor Ri : Si−1 → Set and we have a forgetful functor ti : Si → Si−1.In the first case, we are done: adding constructors to an object in 1 does not do anything.In the remainder we will assume the latter is the case.
A 0-constructor of sort Si on a specification s : Spec is given by a functor F : Alg s → Si such that ti •F = ti • Ū .The algebras we are interested in are dialgebras (X : Alg s ) × (θ : Si(F X, Ū X)) such that tiθ = id t i ( Ū X) .
Let (X, θ), (Y, ρ) : |(F, Ū )−dialg|, then by the induction hypothesis we have that the projections map Ū (X ×Y ) → Ū X × Ū Y has an inverse φ.We can define the algebra structure on X × Y as follows: If ti θ = id t i ( Ū X) and ti ρ = id t i ( Ū Y ) , then the composite will also satisfy this property, hence we are done.By the construction of products, the forgetful functor out of the new category of algebras preserves products.
Equalisers are constructed in an analogous fashion.For 1-constructors the situation is also similar: we have to appeal to the Ū preserving the limits and have to use the fact that an equality between dependent pairs is equivalent to a dependent pair of equalities.
Together with Lemmas 15 and 16, this immediately gives the main theorem of this section: Theorem 19.For each sort S : Sorts and specification s : Spec, let X be an object in the category of algebras Alg s .Then X is initial if and only if X satisfies the section principle.
In particular, this means that when implementing or formalising quotient inductive-inductive types, one can restrict attention to the conceptually simpler notion of initial algebra.

Deriving the induction principle
If we unfold the section principle for our categories of algebras, we will not end up with a very natural induction principle.One of the key features of type theory is that we have special notation for families.If we want to define a predicate on a type X, the most natural way to do it is usually to define a family X → Set, not to define another type Y with a function Y → X.
Since our categories of sorts and algebras are built out of types, we can try and derive a notion of families in these categories.In Set, we have the equivalence, for any X : Set: where the function left to right is defined as λP.((x : X) × P x, π0), i.e. we map the family to its "total space" and its projection function.The inverse operation is the preimage family: (Y, p) is mapped to λx.(y : Y ) × (p y = x).If we want to derive the notion of families of F -algebras for some endofunctor F : Set → Set, then we proceed as follows: let (X, θ) : |F −alg|, we want to solve the equivalence for the type τ : We set Y to (x : X) × P x and p to π0.We then have to simplify the type (ρ : F ((x : X) × P x)) × (p0 : π0 • ρ = θ • F π0), which leads us to: This can be simplified even further if we define the operation F : (X → Set) → F X → Set, i.e. the action of F on type families, which has the defining equation F ((x : X) × P x) (x : F X) × F P x.Rewriting the type of m using this notation gives us: m : (x : F X) × F P x → P (θ x) Intuitively the type F P x is the induction hypothesis.
If we were to consider families of dialgebras over F −alg, we can proceed in the same way by generalising the total space construction of Set to F −alg and so on.The operations we need from a category C to talk about families are as follows: The operations should also satisfy the following correctness conditions, for any X : |C|: • for any family P : FamC X, preimage X (total X P, proj X P ) = P • for any object Y : |C| with p : C(Y, X), (total X (preimage X (Y, p)), proj X (preimage X (Y, p)))

= (Y, p)
To define these operations for the sort and algebra categories, we can perform induction on the specification and apply the same techniques as we did to derive the notion of families in F −alg.
Given these operations, we can generalise the operator to any F : C → D, given we have FamC and FamD: given X : |C| and P : FamC X, F : (X : |C|) → FamC → FamD is defined as: Having defined families, we can then go on to generalise the notion of dependent functions.In Set, given a family P : X → Set, a dependent function (x : X) → P x corresponds to a function s : X → (x : X) × P x along with s0 : π0 • s = idX .The function from left to right sends a dependent function s to its graph λx.(x, s x), which is trivially a section.The other direction composes the section s with π1, but we have to transport along the proof given by s0 to make it typecheck.
To generalise dependent morphisms to a category C, we need a family DepHom C : (X : |C|) (P : FamC X) → Type along with the following operations, given an object X : |C| and a family P : FamC X: • graph : DepHom X P → Section X (total X P, proj X P ) • snd : Section X (total X P, proj X P ) → DepHom C X P The correctness conditions are: • for any f : DepHom C X P , snd X P s (graph X P f ) = f • for any s : Section X (total X P, proj X P ), graph X P (snd X P s) = s These operations can be defined on the categories of sorts and algebras by induction on their specifications, and one can then state the "traditional" induction principle, and show that it is equivalent to the section principle that we have used here.Although the idea is straightforward and the process mechanical, it is rather heavy on notation and takes up a lot of space to fully describe.Hence this is outside the scope of the current paper.

Related work
We have already mentioned the work of Sojakova [33], who proves our Theorem 19 (but with the section principle replaced by the "traditional" induction principle) for a much more restricted class of Higher Inductive Types, but without the assumption of Uniqueness of Identity Proofs.
Our definition of the category of algebras for a constructor is inspired by the work on the semantics of inductive-inductive definitions by Altenkirch et al. [5].Our construction is more general, in that it allows for an arbitrary number of constructors with arbitrary (non-circular) dependencies among them, as well as path constructors.The notion of dependent sorts introduced in this paper is a generalisation of both generalised families and telescopes, as described in [30].They are very closely related to the dependent sorts of Makkai [28].
The work by Lumsdaine and Shulman on the semantics of higher inductive types in model categories [27] bears strong similarities with the approach taken in this paper.Of course, since we work only with sets, their work is in one sense much more general, since it covers non-truncated higher inductive types.On the other hand, the semantics proposed in [27] is restricted to a single inductive definition, so it is not powerful enough to express most of the examples in Section 1.1.Related is also the work by Basold, Geuvers, and van der Weide [37], where also dialgebras are used, but path constructors are rephrased in terms of maps out of the interval type and given a semantics in terms of (homotopy) pushouts.

Conclusions and future work
We have seen how quotient inductive-inductive definitions can be characterised as iterated dialgebras, starting with the category of its dependent sorts and adding a dialgebra structure for every constructor of the definition.The result is a very general notion that subsumes ordinary inductive types, indexed families, inductiveinductive definitions and set-truncated higher inductive types.For these definitions, we have shown that its initial algebra semantics coincide with a categorical version of the induction principle.We have given a sketch of how to derive the actual induction principle.

Higher inductive types
If we want to generalise the constructions in this paper to also support higher inductive types, we need to solve two problems: we need a way to deal with the coherence problems and we need a way to uniformly describe higher path constructors.
The coherence problems already show up if we consider Typesorted inductive definitions without any path constructors.If we look at the initial algebra semantics, everything seems fine as it only depends on the objects and morphisms being defined, it does not even require providing identity morphisms and composition.However, the proof that initiality is logically equivalent to satisfying the induction principle uses more structure of the categories of algebras.Stating the induction principle already relies on composition and identity morphisms being defined in the category of algebras.
As it turns out, the number of coherence problems increases with the number of constructors.To illustrate this, consider a functor F : Type → Type and the category F −alg.In the definition of identity morphisms in F −alg, we have to appeal to the identity laws of the category Type.If we have one constructor, this is fine, as Type satisfies all the category laws and their coherence properties trivially.If we were to consider dialgebras on F −alg, we see that defining identity morphisms now requires us to appeal to the identity laws of F −alg.As opposed to Type, F −alg no longer satisfies the identity laws definitionally.Adding another constructor, we have to talk about the coherence laws of the identity laws of F −alg of the next category of algebras.
To state these coherence laws and deal with them succinctly, one needs to have a notion of (∞, 1)-categories at hand.Achieving this may involve having to extend the type theory with an internal notion of strict equality [6,34].

Constructing quotient inductive-inductive types
So far we have focused on defining quotient inductive-inductive types and relating initiality to induction.We still have to establish whether given a quotient inductive-inductive definition, the initial algebra exists.Naturally we have to put restrictions on the functors describing the arguments: they have to be strictly positive.Strictly positive endofunctors on Set have a succinct formulation as containers [1].We would like to generalise this notion to not just endofunctors on Set, but functors from our categories of algebras into a category of sorts.
Given that all the functors involved in a specification are strictly positive, it seems that it is the case that we can construct the initial algebra as a sequential colimit.For 0-constructors, this will be a generalisation of Adámek's theorem that constructs the initial algebra of an endofunctor as a sequential colimit [2].For 1constructors, it seems there might be a similar construction.The propositional truncation has been constructed as a sequential colimit by Kraus [23] and slightly differently by van Doorn [16].
Since we can describe the specifications described in this paper using a small core type theory with W-types, it seems that if we add quotients to this core theory, we are able to talk about sequential colimits.It then seems that we might be able to construct quotient inductive-inductive types in this theory, given that the arguments functors are strictly positive.

Formalisation
A formalisation in Agda of the specifications and constructions given in this paper is underway.

Definition 1 .
The specification of sorts and their interpretation as a categories is given by the following inductive-recursive definition2  of data Sorts : Set : Sorts → Cat where Sorts is inductively generated by data Sorts where nil : Sorts snoc : (S : Sorts) → Func S Set → Sorts

Example 8 .
of Spec : Set Alg : Spec → Cat U : (s : Spec) → Func Alg s Set where Spec is inductively generated by data Spec : Set where nil : Spec snoc : (s : Spec) → Func Alg s Set → Spec and Alg and U are defined by Alg nil :≡ Set Alg (snoc s F ) :≡ (F, Us)−dialg U nil :≡ id U (snoc s F ) :≡ Us • V where V is the forgetful functor that gives the underlying object of a dialgebra, and Func C D is the type of functors C to D. The example in (2) can be represented by the specification [F0, F1], where F0 : Set → Set is defined by F0 X :≡ 1 and F1 : Alg [F 0 ] → Set is defined by F1 (X, a) :≡ (x : X) × (a * = x) .

Definition 9 (
Specification of quotient inductive-inductive types).The specification of a quotient inductive-inductive type and its category of algebras and underlying carrier functor is given by the following inductive-recursive definition of Spec : Set Constr : (s : Spec) (A : Cat) → A ∈ S → Set Alg : Spec → Cat U : (s : Spec) → Func Alg s S with Spec inductively defined by data Spec : Set where nil : Spec snoc : (s : Spec)(A : Cat)(p : A ∈ S) → Constr s A p → Spec where Constr s A p is defined by recursion on p : A ∈ S such that Constr s 1 p :≡ 0 Constr s A p :≡ Constr0 s A p + Constr1 s A p