1 Introduction

This paper is about type theory in the sense of Martin-Löf [29], a theory which proof assistants such as Coq [7] and Lean [14] as well as programming languages such as Agda [31] and Idris [8] are based on. Recently, Homotopy type theory (HoTT) [34] has been introduced inspired by homotopy theoretic interpretations of type theory by Awodey and Warren [5] and Voevodsky [25, 36].

A central concept in type theory is the concept of inductive definitions, which allows us to define inductive datatypes like the natural numbers, lists and trees just by presenting constructors with strictly positive occurrences of the inductive type being defined. Using the propositions as types explanation, we can use the same mechanism to inductively define predicates and relations, like an order on the natural numbers, or the derivability predicate for a logic defined by rules. Conceptually, HoTT changes what we mean by an inductive definition, because we view a type not only as given by its elements (points) but also by its equality proofs (paths). Hence an inductive definition may not only feature constructors for elements but also for equalities. This concept of higher inductive types (HITs) has been used to represent the homotopical structure of geometric objects, like circles, spheres and tori, and gives rise to synthetic homotopy theory in HoTT [32].

However, as already noted in the HoTT Book [34], HITs have also more quotidian applications, such as a definition of the Cauchy reals for which the use of the axiom of choice can be avoided when proving e.g. Cauchy completeness. Instead of defining the real numbers as a quotient of sequences of rationals, a HIT is used to define them as the Cauchy completion of the rational numbers, with the quotienting happening simultaneously with the completion definition. Similarly, a definition of the partiality monad, which represents potentially diverging operations over a given type, was given using a HIT [2, 13, 35], again avoiding the axiom of choice when showing e.g. that the construction is a monad [12].

As we see from these examples, the idea of generating points and equalities of a type inductively is interesting, even if we do not care about the higher equality structure of types, or if we do not want it. For example: consider trees branching over an arbitrary type A, quotiented by arbitrary permutations of subtrees. We first define the type \(T_0(A)\) of A-branching trees, given by the constructors

$$\begin{aligned}&\mathsf {leaf}_0 : T_0(A) \\&\mathsf {node}_0 : (A \rightarrow T_0(A)) \rightarrow T_0(A). \end{aligned}$$

We then form the binary relation R on \(T_0(A)\) that we want to quotient by as follows: R is the smallest relation such that for any auto-equivalence on A (i.e. any \(e : A \rightarrow A\) which has an inverse) and \(f : A \rightarrow T_0(A)\), we have a proof \(p_{f,e} : R(\mathsf {node}_0(f), \mathsf {node}_0(f \circ e))\), and, secondly, for \(g,h : A \rightarrow T_0(A)\) such that \((n : A) \rightarrow R(g(n), h(n))\), we have a proof \(c_{f,g} : R(\mathsf {node}_0(g),\mathsf {node}_0(h))\). We can then form the quotient type \(T_0(A) / R\), which is the type of unlabelled trees where each node has an A-indexed family of subtrees, and two trees which agree modulo the “order” of its subtrees are equal. For \(A \equiv \mathbf {2}\), these are binary trees where the order of the two subtrees of each node does not matter.

Now, morally, from a family \(A \rightarrow (T_0(A) / R)\), we should be able to construct an element of the quotient \(T_0(A) / R\). This is indeed possible if A is \(\mathbf {2}\) or another finite type, by applying the induction principle of the quotient type A times. However, it seems that, for a general type A, this would require the axiom of choice [34], which unfortunately is not a constructive principle [15]. But using a higher inductive type, we can give an alternative definition for the type of A-branching trees modulo permutation of subtrees.

Example 1

Given a type A, we define \(T(A) : \mathsf {hSet}\) by

$$\begin{aligned}&\mathsf {leaf}: \;\; T(A) \\&\mathsf {node}: \, (A \rightarrow T(A)) \rightarrow T(A) \\&\mathsf {mix}:\;\;\; (f : A \rightarrow T) \rightarrow (e : A \cong A) \rightarrow \mathsf {node}(f) = \mathsf {node}(f \circ e). \end{aligned}$$

Note that the fact that T(A) is a homotopy set (see preliminaries below) is implicitly included in the statement \(T(A) : \mathsf {hSet}\). The construction we were looking for is now directly given by the constructor \(\mathsf {node}\). This demonstration of the usefulness of higher inductive constructions to increase the strength of quotients was first discussed in Altenkirch and Kaposi [1], where such set-truncated HITs are called quotient inductive types (QITs).

Another example of the use of higher inductive types is type theory in type theory [1], where the well-typed syntax of type theory is implemented as a higher inductive-inductive [30] type in type theory itself. A significantly simplified version of this will serve as a running example for us:

Example 2

We define the syntax of a (very basic) type theory by constructing types representing contexts and types as follows. A set \(\mathsf {Con}: \mathsf {hSet}\) and a type family \(\mathsf {Ty}: \mathsf {Con}\rightarrow \mathsf {hSet}\) are simultaneously defined by giving the constructors

For simplicity, we do not consider terms. Contexts are either empty \(\varepsilon \), or an extended context \(\mathsf {ext}\,\varGamma \,A\) representing the context \(\varGamma \) extended by a fresh variable of type A. Types are either the base type \(\iota \) (well-typed in any context), or \(\varSigma \)-types represented by \(\sigma \,\varGamma \,A\,B\) (well-typed in context \(\varGamma \) if A is well-typed in context \(\varGamma \), and B is well-typed in the extended context \(\mathsf {ext}\,\varGamma \,A\)). Type theory in type theory as in [1] has plenty of equality constructors, which play a role as soon as terms are introduced. To keep the example simple we instead use another equality, stating that extending a context by A followed by B is equal to extending it by \(\sigma \,\varGamma \,A\,B\). This equality is given by \(\sigma _{\mathrm {eq}}\). Note that it is not possible to list the constructors of \(\mathsf {Con}\) and \(\mathsf {Ty}\) separately: due to the mutual dependency, the \(\mathsf {Ty}\)-constructor \(\sigma \) has to be given in between of the two \(\mathsf {Con}\)-constructors \(\mathsf {ext}\) and \(\sigma _{\mathrm {eq}}\).

Despite a lot of work making use of concrete HITs [4, 9,10,11, 23, 26, 27], and despite the fact that it is usually — on some intuitive level — clear for the expert how the elimination principle for such a HIT can be derived, giving a general specification and a theoretical foundation for HITs has turned out to be a major difficulty. Several approaches have been proposed [6, 18, 28, 33], and they do indeed give a satisfactory specification of HITs in the sense that they cover all HITs which have been used so far (see related work below). However, to the best of our knowledge, no approach covers higher inductive-inductive definitions such as Example 2. The purpose of the current paper is to remedy this. We restrict ourselves to sets, i.e. to quotient inductive-inductive types (QIITs). This is of course a serious restriction, since it means that we cannot capture many ordinary HITs such as e.g. the circle \(\mathbb {S}^1\). At the same time, all higher inductive-inductive types that we know of are indeed sets — the Cauchy reals, the surreal numbers, the partiality monad, type theory in type theory, permutable trees — and will be instances of our framework, which allows arbitrarily complicated dependency structures. In particular, we allow intermixing of constructors as in Example 2.

Contributions. We give a formal specification of quotient inductive-inductive types with arbitrary dependency structure. This can be viewed as the generalisation of the usual semantics of inductive types as initial algebras of a functor to quotient inductive-inductive types. A QIIT is specified by (i) its sorts, which encode the types and type families that it consists of (Sect. 2), and (ii) by a sequence of constructors, that in turn are specified by argument and target functors (Sect. 3). This is a very general framework, covering in particular point (Sect. 3.2) and path constructors (Sect. 3.4). Each constructor specification gives rise to a category of algebras, and we establish conditions on the target functors that allow us to conclude that these categories of algebras are complete (Sect. 3.5). This is important, because it allows us to prove the equivalence of initiality and a principle that we call section induction (Sect. 4), stating that every algebra morphism into the algebra in question has a section; this principle is close to the intuitively expected elimination rules.

A full version of the paper, including all proofs, is available on the arXiv [3].

Related Work. Sojakova [33] shows the correspondence between initiality and induction (a variant of our Theorem 31) for \(\mathsf {W}\)-suspensions, a restricted class of HITs. Basold, Geuvers and van der Weide [6] introduce a syntactic schema for HITs without higher path constructors, and derive their elimination rules. Dybjer and Moeneclaey [18] give a syntactic schema for finitary HITs with at most paths between paths, and give an interpretation in Hofmann and Streicher’s groupoid model [22]. Finally, Lumsdaine and Shulman’s work on the semantics of HITs in model categories [28] is similar to an external version of our approach.

Preliminaries. We work in a standard Martin-Löf style type theory and assume function extensionality. We do not assume univalence, but also do not contradict it; in particular, everything we do works in the type theory from the HoTT Book [34]. We write \(\mathcal {U}\) for “the” universe of types, omitting universe indices in the typical ambiguity style [21]. A type is a set if all its equality proofs are equal, and \(\mathsf {hSet}\) is defined as \(\varSigma (A : \mathcal {U}). \mathsf {is}\text{- }\mathsf {set}(A)\); we implicitly treat elements of \(\mathsf {hSet}\) as their first projections — this allows us to view \(\mathsf {hSet}\) as a universe. By a category, we mean a precategory [34, Definition 9.1.1] in the sense of the HoTT Book (all our categories become univalent categories if univalence is assumed). We write \(\mathcal {C}\Rightarrow \mathcal {D}\) for functors and \(X \rightarrow Y\) for functions between types. We denote the obvious category of sets and functions by \(\mathsf {hSet}\) as well; consequently, \(F : A \rightarrow \mathsf {hSet}\) denotes a type family, while \(F : \mathcal {C}\Rightarrow \mathsf {hSet}\) denotes a functor. For such a functor \(F : \mathcal {C}\Rightarrow \mathsf {hSet}\), we write for the category of elements of F, whose objects are pairs (Xx) of an object X in \(\mathcal {C}\) and an element x : FX. For a function \(f : X \rightarrow Y\) and zw : X, we write \(\mathsf {ap}\;f\; : z = w \rightarrow f(z) = f(w)\) for the usual “action of a function to paths”, \({}^{-1} : x = y \rightarrow y = x\) for “path reversal”, and for “path concatenation” [34, Lemmas 2.2.1, 2.1.1, 2.1.2].

2 Sorts

Single inductive (and quotient inductive) sets are simply elements of \(\mathsf {hSet}\). Inductive families [17] indexed over some fixed type A are families \(A \rightarrow \mathsf {hSet}\). For the inductive-inductive definitions we are considering, the situation is more complicated, since we allow very general dependency structures. Our only requirement is that there is no looping dependency, since this is easily seen to lead to contradictions, e.g. we do not allow the definition of a family \(A : B \rightarrow \mathsf {hSet}\) mutually with a family \(B : A \rightarrow \mathsf {hSet}\) (whatever this would mean). Concretely, we will ensure that the collection of type formation rules (the type signatures) is given in a valid order, and we refer to the types used as family indices as the sorts of the definition. Hence our first step towards a specification of general QIITs is to explain what a valid specification of the sorts is.

Sorts do not only determine the formation rules of the inductive definitions, but also the types of the eliminators. To capture this, 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.

Definition 3

(Sort specifications). A specification of the sorts of a quotient inductive-inductive definition of n types is given by a list

$$\begin{aligned} H_0, H_1, \ldots , H_{n-1}, \end{aligned}$$

where each \(H_i\) is a functor \(H_i : \mathcal {C}_i \Rightarrow \mathsf {hSet}\). Here, is the terminal category, and \(\mathcal {C}_{i+1}\) is defined as follows:

  • objects are pairs (XP), where X is an object in \(\mathcal {C}_i\), and \(P : H_i(X) \rightarrow \mathsf {hSet}\) is a family of sets;

  • a morphism \((f, g) : (X,P) \rightarrow (Y,Q)\) consists of a morphism \({f : X \rightarrow Y}\) in \(\mathcal {C}_i\), and a dependent function \(g : (x : H_i(X)) \rightarrow P(x) \rightarrow Q(H_i(f)\, x)\) (in \(\mathsf {hSet}\)).

We say that \(\mathcal {C}_n\) is the base category for the sort signature \(H_0, \ldots , H_{n-1}\).

The following examples will hopefully make clear the connection between the specification in Definition 3 and common classes of data types.

Example 4

(Permutable trees). For a single inductive type such as the type of trees T(A) in Example 1, the sorts are specified by a single functor \(H_0 : \mathcal {C}_0 \Rightarrow \mathsf {hSet}\) which maps the single object \(\star \) of \(\mathcal {C}_0\) to the unit type \(\mathbf {1}\). Objects in the base category \(\mathcal {C}_1\) are thus pairs \((\star , W)\), where \(W : \mathbf {1}\rightarrow \mathsf {hSet}\), and morphisms are given by \(f : \star \rightarrow \star \) in \(\mathbbm {1}\) (necessarily the identity morphism), together with a dependent function \(g : (x : \mathbf {1}) \rightarrow W(x) \rightarrow V(x)\). It is easy to see that this category \(\mathcal {C}_1\) is equivalent to the category \(\mathsf {hSet}\).

Example 5

(The finite types). Consider the inductive family \(\mathsf {Fin} : \mathbb {N}\rightarrow \mathsf {hSet}\) of finite types. Again, this is a single type family, i.e. we are in the case \(n \equiv 1\). We have , and the base category \(\mathcal {C}_1\) is equivalent to the category of \(\mathbb {N}\)-indexed families, where objects are families \(X : \mathbb {N}\rightarrow \mathsf {hSet}\) and morphisms \(\mathcal {C}_1(X,Y)\) are dependent functions \(f : (n : \mathbb {N}) \rightarrow X(n) \rightarrow Y(n)\).

Example 6

(Contexts and types). Let us consider the QIIT \((\mathsf {Con}, \mathsf {Ty})\) from Example 2. Here, we need two functors \(H_0\), \(H_1\), the first corresponding to \(\mathsf {Con}\) and the second to \(\mathsf {Ty}\). The first is given by as in Example 4, since \(\mathsf {Con}\) is a type on its own. Next, we need \(H_1 : \mathcal {C}_1 \Rightarrow \mathsf {hSet}\). Applying the equivalence between \(\mathcal {C}_1\) and \(\mathsf {hSet}\) established in Example 4, we define \(H_1\) to be the identity functor , since then \(\mathsf {Ty}: H_1(\mathsf {Con}) \rightarrow \mathsf {hSet}\). The base category \(\mathcal {C}_2\) is equivalent to the category \(\mathsf {Fam}(\mathsf {hSet})\), whose objects are pairs (AB) where \(A : \mathsf {hSet}\) and \(B : A \rightarrow \mathsf {hSet}\), and whose morphisms (AB) to \((A', B')\) consist of functions \(f : A \rightarrow A'\) together with dependent functions \(g : (x:A) \rightarrow B(x) \rightarrow B'(f \, x)\).

Example 7

(the Cauchy reals). Recall that the Cauchy reals in the HoTT book [34] are constructed by simultaneously defining \(\mathbb {R}: \mathsf {hSet}\) and \(\sim : \mathbb {R}\times \mathbb {R}\rightarrow \mathsf {hSet}\) (we ignore the fact that [34] uses \(\mathcal {U}\) instead of \(\mathsf {hSet}\)). This time the sorts \(H_0, H_1\) are given by and , corresponding to the fact that \(\sim \) is a binary relation on \(\mathbb {R}\). The base category has (up to equivalence) pairs (XY) with \(Y : X \times X \rightarrow \mathsf {hSet}\) as objects, and morphisms are defined accordingly.

Example 8

(The full syntax of type theory). Altenkirch and Kaposi [1] give the complete syntax of a basic type theory as a (at that point unspecified) QIIT. Although this construction is far too involved to be treated as an example in the rest of this paper (where we prefer to work with the simplified version of Example 2), we can give the sort signature \(H_0, H_1, H_2, H_3\) of this QIIT. Apart from contexts \(\mathsf {Con}\) and types \(\mathsf {Ty}\), this definition also involves context morphisms \(\mathsf {Tms}\) and terms \(\mathsf {Tm}\):

$$\begin{aligned}&\mathsf {Con}: \, \mathsf {hSet}\qquad \qquad \qquad \quad \mathsf {Tms}: \mathsf {Con}\times \mathsf {Con}\rightarrow \mathsf {hSet}\\&\mathsf {Ty}:\;\; \mathsf {Con}\rightarrow \mathsf {hSet}\qquad \qquad \mathsf {Tm}: \,\,\, \big (\varSigma (\varGamma : \mathsf {Con}).\mathsf {Ty}(\varGamma )\big ) \rightarrow \mathsf {hSet}. \end{aligned}$$

We have:

Remark 9

Although we work in type theory also in the meta-theory, we give the presentation informally in natural language. Formally, the specification of sorts and base categories of Definition 3 can be defined as an inductive-recursive definition [19] of the list \(H_0, \ldots , H_n\) simultaneously with a function that turns such a list into a category. Details can be found in Dijkstra’s thesis [16, Sect. 4.3].

The main result of this section states that base categories of sort signatures are complete, i.e. have all small limits. By a small limit, we mean a limit of a diagram \(D : \mathcal {I}\rightarrow \mathcal {C}\), where the shape category \(\mathcal {I}\) has a set of objects, and the collection of morphisms between any two objects is a set. This result will be needed later to show that categories of QIIT algebras are complete. Recall that \(\mathsf {hSet}\) has all small limits by a standard construction.

Theorem 10

(Base categories are complete). For any sort signature \(H_0,\) \(\ldots ,\) \(H_{n-1}\), the corresponding base category \(\mathcal {C}_n\) has all small limits.

Proof

All proofs can be found in the arXiv version of the paper [3].    \(\square \)

3 Algebras

Once the sorts of an inductive definition have been established, the next step is to specify the constructors. In this section, we will give a very general definition of constructor specifications, although we will mainly focus on two specific kinds: point constructors, which can be thought of as the operations of an algebraic signature, and path constructors, which correspond to the axioms.

Similarly to how sorts are specified inductively in Sect. 2, we construct suitable categories of algebras by starting with a finitely complete category \(\mathcal {C}\) such as the one obtained from a sort signature, specify a constructor on \(\mathcal {C}\), and then extend \(\mathcal {C}\) using this constructor specification to get a new finitely complete category \(\mathcal {C}'\). This process is repeated until all constructors have been added, and we obtain the sought-after inductive type as the underlying set of an initial object of the category at the last stage, provided this initial object exists. In the case of the inductive definition of natural numbers, this process will turn out as follows:

  • we start with \(\mathsf {hSet}\) as our base category (only one trivial sort, as in Example 4);

  • we add a point constructor for the constant corresponding to 0; the category of algebras at this stage is the category of pointed sets;

  • we add a second point constructor for the operation corresponding to \(\mathsf {suc}\); the category of algebras at this stage is the category of sets equipped with a point and a unary operation;

  • the set of natural numbers, together with its usual structure, can now be regarded as an initial object in the category of algebras just constructed.

3.1 Relative Continuity and Constructor Specifications

Roughly speaking, constructors at each stage are given by pairs of \(\mathsf {hSet}\)-valued functors F and G on \(\mathcal {C}\), where G is continuous (i.e. preserves all small limits). The intuition is that F specifies the arguments of the constructor, while G determines its target. For instance, in the example of the natural numbers when specifying the constructor \(\mathsf {suc} : \mathbb {N}\rightarrow \mathbb {N}\), \(\mathcal {C}\) is the category of pointed sets, and both F and G are the forgetful functor to \(\mathsf {hSet}\). The continuity condition on G is needed for the corresponding category of algebras to be complete. Intuitively, this expresses that a constructor should only “construct” elements of one of the sorts, or equalities thereof.Footnote 1 In particular, a constant functor is usually not a valid choice for G.

Unfortunately, this simple description falls short of capturing many of the examples of QIITs mentioned in Sect. 1. The problem is that we want G to be able to depend on the elements of F. However, since F is assumed to be an arbitrary functor, its category of elements is not necessarily complete, and so we need to refine the notion of G being continuous to this case.

Definition 11

(Relative continuity). Let \(\mathcal {C}\) be a category, \(\mathcal {C}_0\) a complete category, and \(U : \mathcal {C}\Rightarrow \mathcal {C}_0\) a functor. If I is a small category, and \(X : I \rightarrow \mathcal {C}\) is a diagram, we say that a cone \(A \rightarrow X\) in \(\mathcal {C}\) is a U-limit cone, or limit cone relative to U, if the induced cone \(UA \rightarrow UX\) is a limit cone in \(\mathcal {C}_0\). A functor \(\mathcal {C}\Rightarrow \mathsf {hSet}\) is continuous relative to U if it maps U-limit cones to limit cones in \(\mathsf {hSet}\).

In the special case \(\mathcal {C}_0 \equiv \mathsf {hSet}\), the functor U in Definition 11 is continuous relative to itself. Also note that if \(\mathcal {C}\) is complete and U creates limits, then relative continuity with respect to U reduces to ordinary continuity. If \(\mathcal {C}\) is a complete category, and \(F : \mathcal {C}\Rightarrow \mathsf {hSet}\) is an arbitrary functor, the category of elements of F is equipped with a forgetful functor into \(\mathcal {C}\). We will implicitly consider relative limit cones and relative continuity with respect to this forgetful functor, unless specified otherwise. Note that if \(\mathcal {C}\) is complete and F is continuous, then is also complete, and relative continuity of functors on is the same as continuity, as observed above.

We can now give a precise definition of what is needed to specify a constructor:

Definition 12

(Constructor specifications). A constructor specification on a complete category \(\mathcal {C}\) is given by:

  • a functor \(F : \mathcal {C}\Rightarrow \mathsf {hSet}\), called the argument functor of the specification;

  • a relatively continuous functor , called the target functor.

Given a constructor specification, we can define the corresponding category of algebras. In Theorem 25, we will see that the assumptions of Definition 12 guarantee that this category is complete.

Definition 13

(Category of algebras). Let (FG) be a constructor specification on a complete category \(\mathcal {C}\). The category of algebras of (FG) is denoted \(\mathcal {C}.(F,G)\), and is defined as follows:

  • objects are pairs \((X, \theta )\), where X is an object of \(\mathcal {C}\), and \(\theta : (x : F X) \rightarrow G(X, x)\) is a dependent function (in \(\mathsf {hSet}\));

  • morphisms \((X, \theta ) \rightarrow (Y, \psi )\) are given by morphisms \(f : X \rightarrow Y\) in \(\mathcal {C}\), with the property that for all x : FX,

    $$\begin{aligned} \psi (F(f)\,x) = G(\overline{f}) (\theta \,x), \end{aligned}$$

    where \(\overline{f} : (X, x) \rightarrow (Y, F(f)\,x)\) is the morphism in determined by f.

We think of \(\mathcal {C}.(F,G)\) as a category of “dependent dialgebras” [20]. Note that there is an obvious forgetful functor \(\mathcal {C}.(F,G) \rightarrow \mathcal {C}\).

Similarly to how we defined sort specifications (Definition 3), we now have all the necessary notions in place to be able to give the full definition of a QIIT.

Definition 14

(QIIT descriptions). A QIIT description is given by

  • a sort specification \(H_0, \ldots , H_{n-1}\);

  • a list of constructor specifications \((F_0, G_0), \ldots , (F_{n-1}, G_{n-1})\) on \(\mathcal {B}_0, \ldots , \mathcal {B}_{n-1}\) respectively, where \(\mathcal {B}_0\) is the base category of the given sort specification, and \(\mathcal {B}_{i+1}\) is the category of algebras of \((F_i, G_i)\).

For Definition 14 to make sense, the categories \(\mathcal {B}_i\) need to be complete, since constructor specifications are only defined on complete categories. This will follow from Theorem 25.

Example 15

(Permutable trees). The constructor \(\mathsf {leaf}: T(A)\) from Example 1 can be specified by functors \(F_0 : \mathsf {hSet}\Rightarrow \mathsf {hSet}\) and , where and . Note how \(F_0\) specifies the (trivial) arguments of \(\mathsf {leaf}\), and \(G_0\) the target. Next the constructor \(\mathsf {node}: (A \rightarrow T(A)) \rightarrow T(A)\) can be specified by functors \(F_1 : \mathsf {hSet}_{\bullet } \Rightarrow \mathsf {hSet}\) and , where \(\mathsf {hSet}_{\bullet }\) is the category of pointed sets (we think of the point as the previous constructor \(\mathsf {leaf}\)): \(F_1\) and \(G_1\) are defined as and , so that

$$\begin{aligned} \mathsf {node}: (f : F_1(T(A),\mathsf {leaf})) \rightarrow G_1(T(A), \mathsf {leaf}, f). \end{aligned}$$

Theorem 18 will show that \(G_0\) and \(G_1\) are relatively continuous.

The corresponding category of algebras for this constructor specification \((F_1, G_1)\) for \(\mathsf {node}\) is equivalent to the category whose objects are triples (Xln) where \(X : \mathsf {hSet}\), l : A, and \(n : (A \rightarrow X) \rightarrow X\). After specifying also the \(\mathsf {mix}\)-constructor, the new category of algebras further contains a dependent function \(p : (f : A \rightarrow X) \rightarrow (e : X \cong X) \rightarrow n(f) = n(f \circ e)\).

Example 16

(Contexts and types). The constructor \(\sigma _{\mathrm {eq}}\) of type

$$\begin{aligned} (\varGamma : \mathsf {Con})(A : \mathsf {Ty}(\varGamma ))(B : \mathsf {Ty}(\mathsf {ext}\, \varGamma \, A)) \rightarrow \mathsf {ext}\, (\mathsf {ext}\, \varGamma \, A) \, B =_{\mathsf {Con}} \mathsf {ext}\, \varGamma \, (\sigma \, \varGamma \, A \, B) \end{aligned}$$

from Example 2 is specified in the context of the previous constructors \(\varepsilon \), \(\mathsf {ext}\) and \(\sigma \) by functors \(F : \mathcal {C}\Rightarrow \mathsf {hSet}\) and , where \(\mathcal {C}\) is the category of algebras of the previous constructors, with

and

Theorem 23 will show that G is relatively continuous. The corresponding category of algebras for this constructor specification has objects tuples \((C, T, e, c, b, s, s_{\mathrm {eq}})\) where (CTecbs) is an algebra for the previous constructors, and

$$\begin{aligned} s_{\mathrm {eq}} : (\varGamma : C) \rightarrow (A : T(\varGamma )) \rightarrow (B : T(c \, \varGamma \, A)) \rightarrow c \, (c \, \varGamma \, A) \, B =_{C} c \, \varGamma \, (s \, \varGamma \, A \, B). \end{aligned}$$

3.2 Point Constructors

If \(\mathcal {C}\) is the base category for a sort signature as in Definition 3, we can define specific target functors \(\mathcal {C}\Rightarrow \mathsf {hSet}\) which are guaranteed to be relatively continuous. Constructors having those as targets are referred to as point constructors. Intuitively, a point constructor is an operation that returns an element (point) of one of the sorts. The corresponding target functor is the forgetful functor that projects out the chosen sort. However, sorts can be dependent, so such a projection needs to be defined on a category of elements.

Specifically, let \(\mathcal {C}\) be a finitely complete category, \(H : \mathcal {C}\Rightarrow \mathsf {hSet}\) a functor, and \(\mathcal {C}'\) the extended base category with one more sort indexed over H. Recall from Definition 13 that the objects of \(\mathcal {C}'\) are pairs (XP), where X is an object of \(\mathcal {C}\), and P is a family of sets indexed over HX. Let \(V_H : \mathcal {C}' \Rightarrow \mathcal {C}\) be the forgetful functor. We define the base target functor corresponding to H to be the functor given by

$$\begin{aligned} U_H (X, P, x) = P(x). \end{aligned}$$

In other words, given an object X of \(\mathcal {C}\), a family P over HX, and a point x in the base, the functor \(U_H\) returns the fibre of the family P over x. The action of \(U_H\) on morphisms is the obvious one.

Example 17

(Permutable trees). In Example 15, the functor specifying the target of \(\mathsf {leaf}\) is the composition of the forgetful with the base target functor for the only sort, in this case the identity \(\mathsf {id}: \mathsf {hSet}\Rightarrow \mathsf {hSet}\).

Note that \(U_H = \mathsf {id}\) in Example 17 is relatively continuous, as required by Definition 12. In the rest of this section, we will show that this is true in general. Given a category \(\mathcal {C}\) and a functor \(F : \mathcal {C}\Rightarrow \mathsf {hSet}\), it is well known that the slice category over F of the functor category \(\mathcal {C}\Rightarrow \mathsf {hSet}\) is equivalent to the functor category (see for example [24, Proposition 1.1.7]). Given a functor \(G : \mathcal {C}\Rightarrow \mathsf {hSet}\) and a natural transformation \(\alpha : G \rightarrow F\), we will refer to the functor corresponding to \(\alpha \) as the functor of fibres of \(\alpha \). Concretely, \(\overline{G}\) maps an object (Xx), where x : FX, to the fibre of \(\alpha _X\) over x. The following theorem is proved by noting that \(U_H\) is a functor of fibres.

Theorem 18

(Base target functors are relatively continuous). Let \(\mathcal {C}\) be a complete category, \(H : \mathcal {C}\Rightarrow \mathsf {hSet}\) any functor, and \(\mathcal {C}'\) the extended base category corresponding to H. Then the base target functor \(U_H\) is relatively continuous.    \(\square \)

3.3 Reindexing Target Functors

In many cases, we can obtain suitable target functors by composing the desired base target functor with the forgetful functor to the appropriate stage of the base category. When building constructors one at a time, it will follow from Theorems 25 and 10 applied to the previous steps that this forgetful functor is continuous, and the relative continuity of the target functor will follow. In more complicated examples, composing with a forgetful functor is not quite enough. We often want to “substitute into” or reindex a target functor to target a specific element. For example, in the context of Example 2, consider a hypothetical modified \(\sigma \) constructor of the form

$$\begin{aligned} \sigma ': \big (\varSigma (\varGamma : \mathsf {Con}). \varSigma (A : \mathsf {Ty}(\varGamma )).\mathsf {Ty}(\mathsf {ext}\,\varGamma \,A)\big ) \rightarrow \mathsf {Ty}(\mathsf {ext}\,\varGamma \,A). \end{aligned}$$

We want the target functor to return the set \(\mathsf {Ty}(\mathsf {ext}\,\varGamma \,A)\), and not just \(\mathsf {Ty}(x)\) for a new argument x, which is the result of the base target functor. We can obtain the desired target functor as a composition

(1)

where \(\mathcal {C}\) is the category with objects tuples \((C,T,\varepsilon , \mathsf {ext})\), \(F : \mathcal {C}\Rightarrow \mathsf {hSet}\) is the functor giving the arguments of the constructor \(\sigma '\), \(U_H\) is the base target functor corresponding to the second sort, and S is the functor defined by .

Since the functors S that we compose with in order to “substitute” are of a special form, the resulting functor will still be relatively continuous when starting with a relatively continuous functor. This is made precise by the following result:

figure a

Lemma 19

(Preservation of relative limit cones). Suppose given is a commutative diagram of categories and functors as shown on the right, where \(\mathcal {C}_0\) and \(\mathcal {D}_0\) are complete, and G maps U-limit cones to V-limit cones. Then F maps \((U \circ U')\)-limit cones to \((V \circ V')\)-limit cones. In particular, if \(\mathcal {C}\) and \(\mathcal {D}\) are complete and G is continuous, then F preserves relative limit cones.    \(\square \)

figure b

Example 20

Starting from the situation in (1) we can form the diagram shown on the left, where \(V : \mathcal {C}\Rightarrow \mathsf {Fam}(\mathsf {hSet})\) is the forgetful functor and hence continuous. It follows from the second statement of Lemma 19 that S preserves relative limit cones, hence \(G = U_H \circ S\) is relatively continuous by Theorem 18.

3.4 Path Constructors

Path constructors are constructors where the target functor G returns an equality type. They can e.g. be used to express laws when constructing an initial algebra of an algebraic theory as a QIT. We saw an example of this in Example 1, where we had a path constructor of the form

$$\begin{aligned} \mathsf {mix}: (f : A \rightarrow T) \rightarrow (e : A \cong A) \rightarrow \mathsf {node}(f) = \mathsf {node}(f \circ e). \end{aligned}$$

The argument functor for \(\mathsf {mix}\) is entirely unproblematic. However, it is perhaps not so clear that the target functor, which sends (Xlnfe) to the equality type \(n(f) =_{X} n(f \circ e)\), is relatively continuous. The aim of the current section is to show this for any functor of this form. We first observe that the prototypical such equality functor is relatively continuous, and then show that any other target functor for a path constructor can be obtained by substitution using Lemma 19.

Definition 21

Let be the functor defined on objects by and on morphisms by .

It is not hard to see that \(\mathsf {Eq}\) is a functor. Furthermore, \(\mathsf {Eq}\) is the functor of fibres of the obvious diagonal natural transformation \(\varDelta : \mathsf {id}\rightarrow \mathsf {id}\times \mathsf {id}\).

Lemma 22

The standard equality functor \(\mathsf {Eq}\) is relatively continuous.    \(\square \)

The lemma we have just given is central to the observation that a large class of equality functors are suitable targets for constructors:

Theorem 23

(Equality functors are relatively continuous). Let \(\mathcal {C}\) be a complete category, \(F : \mathcal {C}\Rightarrow \mathsf {hSet}\) any functor, and a relatively continuous functor. Suppose given two global elements lr of G, i.e. natural transformations \(l , r : \mathbf {1}\rightarrow G\). The map

with \(\mathsf {Eq}_G(l, r)(Y) = (l_{Y} =_{G(Y)} r_{Y})\) extends to a relatively continuous functor.    \(\square \)

Example 24

(Permutable trees). The target of the \(\mathsf {mix}\) constructor from Example 1 can be obtained as an equality functor in this sense. We take G to be the underlying sort, which is relatively continuous by the results of the previous section. The global elements l and r are defined by and . Their naturality can easily be verified directly.

Iterating equality functors, one can also express higher path constructors, but in our limited setting of inductively defined sets, there is little reason to go beyond one level of path constructors — higher ones will have no effect on the resulting inductive type. However, we believe that the ease with which Theorem 23 can be applied iteratively will be an important feature when generalising our technique to general higher inductive types. We discuss this further in Sect. 5.

3.5 Categories of Algebras are Complete

Recall from Definition 13 that the category of algebras \(\mathcal {C}.(F,G)\) for a constructor specification (FG) on a complete category \(\mathcal {C}\) has “dependent (FG)-dialgebras” as objects, and maps that commute with the dialgebra structure as morphisms. In this section, we will show that \(\mathcal {C}.(F,G)\) is complete, and that its forgetful functor is continuous. The significance of this result is twofold: First of all, it enables the use of limits when reasoning about algebras; in particular, we will show in Sect. 4 how, using products and equalisers, one can extend the classical equivalence between initiality and induction for ordinary inductive types to our setting. Secondly, it goes a long way towards establishing existence of initial algebras; since a category of algebras over \(n + 1\) constructors is complete, and the forgetful functor to the category of algebras over the first n preserves limits, the adjoint functor theorem says that this functor has a left adjoint if and only if it satisfies the solution set condition. Applying this argument at every stage, we get a left adjoint for the forgetful functor down to \(\mathsf {hSet}\), and in particular an initial object. There is no reason to expect the solution set condition to hold at this generality, but we expect it to follow from appropriate “accessibility” conditions on the argument functors. This is discussed further in Sect. 5.

Theorem 25

(Categories of algebras are complete). Let (FG) be a constructor specification on a complete category \(\mathcal {C}\). Then \(\mathcal {C}.(F,G)\) is complete.    \(\square \)

4 Elimination Principles

So far, we have given rules for specifying a QIIT by giving a sort signature and a list of constructors. As type-theoretical rules, these correspond to the formation and introduction rules for the QIIT. In this section, we introduce the corresponding elimination rules, stating that a QIIT is the smallest type closed under its constructors. We show that a categorical formulation of the elimination rules is equivalent to the universal property of initiality.

4.1 The Section Induction Principle

The elimination principle for an algebra \(X\) states that every fibred algebra over \(X\) has a section, where a fibred algebra over \(X\) is an algebra family “\(Q : X \rightarrow \mathsf {hSet}\)”, and a section of it a dependent algebra morphism “\((x : X) \rightarrow Q(x)\)”.Footnote 2 The usual correspondence between type families and fibrations extends to algebras, and so we formulate the elimination rule for \(X\) as \(X\) being section inductive in the category of algebras in the following sense:

Definition 26

(Section inductive). An object X of a category \(\mathcal {C}\) is section inductive if for every object Y of \(\mathcal {C}\) and morphism \(p : Y \rightarrow X\), there exists \(s : X \rightarrow Y\) such that \(p \circ s = \mathsf {id}_X\).

For an algebra \(X\), the existence of the underlying function(s) \(X \rightarrow Y\) corresponds to the elimination rules, while the fact that they are algebra morphisms corresponds to the computation rules.

Example 27

(Permutable trees). Consider permutable-tree algebras, e.g. tuples (Xlnp) as in Example 15. A fibred permutable-tree algebra over (Xlnp) consists of \(Q : X \rightarrow \mathsf {hSet}\) together with \(m_l : Q(l)\) and

Here the type \(x =[p]~y\) is the types of equalities between elements x : A and y : B in different types, themselves related by an equality proof \(p : A = B\). This data can be arranged into an ordinary algebra \(\varSigma (x : X).Q(x)\), together with an algebra morphism \(\pi _1 : \big (\varSigma (x : X). Q(x)\big ) \rightarrow X\). A section of \(\pi _1\) is a dependent function \(h : (x : X) \rightarrow Q(x)\). Since h comes from an algebra morphism, we further know e.g. \(h(l) = m_l\) and \(h(n\,f) = m_n\, f\,(h \circ f)\). Conversely, every algebra morphism \(g : (X', l', n', p') \rightarrow (X, l, n, p)\) gives rise to a fibred algebra \((Q, m_l, m_n, m_p)\) by considering the fibres \(Q(x) = \varSigma (y : A').g(y) = x\) of p. The points \(m_l\), \(m_n\) and the path \(m_p\) arise from the proof that g preserves \(l'\), \(n'\) and \(p'\).

Example 28

(Contexts and types). For context-and-types algebras from Example 16, a fibred algebra over \((C, T, e, c, b, s, s_{\mathrm {eq}})\) consists of \(Q : C \rightarrow \mathsf {hSet}\) and \(R : (x : C) \rightarrow T(x) \rightarrow Q(x) \rightarrow \mathsf {hSet}\), together with \(m_e : Q(e)\) and

Again, this data can be arranged into an ordinary algebra with base \(C' : \mathsf {hSet}\), \(T' : C' \rightarrow \mathsf {hSet}\), where \(C' = \varSigma (x : C).Q(x)\) and \(T'(x, q) = \varSigma (y : T(x)).R(x,y,q)\), together with an algebra morphism \((\pi _1, \pi _1) : (C', T') \rightarrow (C, T)\). A section of this morphism gives functions \(f : (x : C) \rightarrow Q(x)\) and \(g : (x : C) \rightarrow (y : T(x)) \rightarrow R(x, y, f\,x)\) that preserve the algebra structure.

A general account of the equivalence between the usual formulation of the elimination rules and the section induction principle is in Dijkstra [16, Sect. 5.4].

4.2 Initiality, and its Relation to the Section Induction Principle

The section induction principle for an algebra \(X\) matches our intuitive understanding of the elimination rules for \(X\) quite well, but it is perhaps a priori not so clear that e.g. satisfying it defines an algebra uniquely up to equivalence. In this section, we show that this is the case by proving that the section induction principle is equivalent to the categorical property of initiality. Recall that a type is contractible if it is equivalent to the unit type [34, Definition 3.11.1].

Definition 29

(Initiality). An object X of a category \(\mathcal {C}\) is (homotopy) initial if for every object Y of \(\mathcal {C}\), the set of morphisms \(X \rightarrow Y\) is contractible.

It is easy to see that initiality implies section induction, while the converse requires additional structure on \(\mathcal {C}\):

Lemma 30

If an object X in a category \(\mathcal {C}\) is initial, then it is section inductive. If \(\mathcal {C}\) has finite limits and X is section inductive, then X is initial.    \(\square \)

From here, we can show the main theorem of the current section. The proof uses the fact that both statements involved are mere propositions, i.e. they have at most one proof.

Theorem 31

(Initiality \(\cong \) section induction). An object X in a in a category of algebras \(\mathcal {C}.(F,G)\) being initial is equivalent to it being section inductive.    \(\square \)

As an application, we can now reason about QIITs using their categories of algebras. For instance, we get a short proof of the following fact:

Corollary 32

The interval is equivalent to the unit type.

Proof

By Theorem 31, the interval is the initial object in the category with objects \(\varSigma (X : \mathsf {hSet}).\varSigma (x : X).\varSigma (y : X).x =_{X} y\), while the unit type is the initial object in the category with objects \(\varSigma (X : \mathsf {hSet}).X\). By contractibility of singleton types [34, Lemma 3.11.8], the former is equivalent to the latter, and since initiality is a universal property, the two initial objects coincide up to equivalence.    \(\square \)

5 Conclusions and Further Work

We have developed a semantic framework for QIITs: A QIIT description gives rise to a category of algebras, and the initial object of this category represent the types and constructors of the QIIT. This generalises the usual functorial semantics of inductive types to a more general setting. So far we have verified the appropriateness of this setting by means of examples. In future work, we would like to explicitly relate the syntax of QIITs to the corresponding semantics.

Our categories of algebras are complete. This is helpful for the metatheory of QIITs, as demonstrated by the proof of initiality being equivalent to section induction (Theorem 31), justifying elimination principles. Of course, completeness is not by itself sufficient to derive the existence of initial algebras, but it suggests that it should be possible to restrict the argument functors to guarantee this, possibly by reducing QIITs to a basic type former playing an analogous role to that of W-types for inductive types. We believe that completeness of the categories of algebras allows an existence proof using the adjoint functor theorem.

We have restricted our attention to QIITs, but we believe that our construction is applicable to general HITs (and even HIITs). While at first glance such an extension of our framework seems to require an internal theory of \((\infty ,1)\)-categories, we believe that it is enough to keep track of only a very limited number of coherence conditions, making this extension possible even without solving the well-known problem of specifying an infinite tower of coherences in HoTT.

Other possible future directions include the combination of QIITs and induction-recursion, and the possibility of generalising coinductive types along similar lines. These generalisations should be driven by examples, similar to how the examples discussed in the current paper have motivated the need for a theory of QIITs.