5.6 The general syntax of inductive definitions
So far, we have been discussing only particular inductive types: $\mathrm{\U0001d7ce}$, $\mathrm{\U0001d7cf}$, $\mathrm{\U0001d7d0}$, $\mathbb{N}$, coproducts^{}, products^{}, $\mathrm{\Sigma}$types, $\U0001d5b6$types, etc. However, an important aspect of type theory^{} is the ability to define new inductive types, rather than being restricted only to some particular fixed list of them. In order to be able to do this, however, we need to know what sorts of “inductive definitions” are valid or reasonable.
To see that not everything which “looks like an inductive definition” makes sense, consider the following “constructor” of a type $C$:

•
$g:(C\to \mathbb{N})\to C$.
The recursion principle for such a type $C$ ought to say that given a type $P$, in order to construct a function $f:C\to P$, it suffices to consider the case when the input $c:C$ is of the form $g(\alpha )$ for some $\alpha :C\to \mathbb{N}$. Moreover, we would expect to be able to use the “recursive data” of $f$ applied to $\alpha $ in some way. However, it is not at all clear how to “apply $f$ to $\alpha $”, since both are functions with domain $C$.
We could write down a “recursion principle” for $C$ by just supposing (unjustifiably) that there is some way to apply $f$ to $\alpha $ and obtain a function $P\to \mathbb{N}$. Then the input to the recursion rule would ask for a type $P$ together with a function
$$h:(C\to \mathbb{N})\to (P\to \mathbb{N})\to P$$  (5.6.1) 
where the two arguments^{} of $h$ are $\alpha $ and “the result of applying $f$ to $\alpha $”. However, what would the computation rule for the resulting function $f:C\to P$ be? Looking at other computation rules, we would expect something like “$f(g(\alpha ))\equiv h(\alpha ,f(\alpha ))$” for $\alpha :C\to \mathbb{N}$, but as we have seen, “$f(\alpha )$” does not make sense. The induction^{} principle of $C$ is even more problematic; it’s not even clear how to write down the hypotheses. (See also http://planetmath.org/node/87788Exercise 5.7,http://planetmath.org/node/87866Exercise 5.8.)
This example suggests one restriction^{} on inductive definitions: the domains of all the constructors must be covariant functors^{} of the type being defined, so that we can “apply $f$ to them” to get the result of the “recursive call”. In other words, if we replace all occurrences of the type being defined with a variable^{} $X:\mathcal{U}$, then each domain of a constructor must be an expression that can be made into a covariant functor of $X$. This is the case for all the examples we have considered so far. For instance, with the constructor $\mathrm{\U0001d5c2\U0001d5c7\U0001d5c5}:A\to A+B$, the relevant functor is constant at $A$ (i.e. $X\mapsto A$), while for the constructor $\mathrm{\U0001d5cc\U0001d5ce\U0001d5bc\U0001d5bc}:\mathbb{N}\to \mathbb{N}$, the functor is the identity functor ($X\mapsto X$).
However, this necessary condition is also not sufficient. Covariance prevents the inductive type from occurring on the left of a single function type, as in the argument $C\to \mathbb{N}$ of the “constructor” $g$ considered above, since this yields a contravariant functor rather than a covariant one. However, since the composite of two contravariant functors is covariant, double function types such as $((X\to \mathbb{N})\to \mathbb{N})$ are once again covariant. This enables us to reproduce Cantorianstyle paradoxes^{}.
For instance, consider an “inductive type” $D$ with the following constructor:

•
$k:((D\to \mathrm{\U0001d5af\U0001d5cb\U0001d5c8\U0001d5c9})\to \mathrm{\U0001d5af\U0001d5cb\U0001d5c8\U0001d5c9})\to D$.
Assuming such a type exists, we define functions
$r$  $:D\to (D\to \mathrm{\U0001d5af\U0001d5cb\U0001d5c8\U0001d5c9})\to \mathrm{\U0001d5af\U0001d5cb\U0001d5c8\U0001d5c9},$  
$f$  $:(D\to \mathrm{\U0001d5af\U0001d5cb\U0001d5c8\U0001d5c9})\to D,$  
$p$  $:(D\to \mathrm{\U0001d5af\U0001d5cb\U0001d5c8\U0001d5c9})\to (D\to \mathrm{\U0001d5af\U0001d5cb\U0001d5c8\U0001d5c9})\to \mathrm{\U0001d5af\U0001d5cb\U0001d5c8\U0001d5c9},$  
by  
$r(k(\theta ))$  $:\equiv \theta ,$  
$f(\delta )$  $:\equiv k(\lambda x.(x=\delta )),$  
$p(\delta )$  $:\equiv \lambda x.\delta (f(x)).$ 
Here $r$ is defined by the recursion principle of $D$, while $f$ and $p$ are defined explicitly. Then for any $\delta :D\to \mathrm{\U0001d5af\U0001d5cb\U0001d5c8\U0001d5c9}$, we have $r(f(\delta ))=\lambda x.(x=\delta )$.
In particular, therefore, if $f(\delta )=f({\delta}^{\prime})$, then we have a path $s:(\lambda x.(x=\delta ))=(\lambda x.(x={\delta}^{\prime}))$. Thus, $\mathrm{\U0001d5c1\U0001d5ba\U0001d5c9\U0001d5c9\U0001d5c5\U0001d5d2}(s,\delta ):(\delta =\delta )=(\delta ={\delta}^{\prime})$, and so in particular $\delta ={\delta}^{\prime}$ holds. Hence, $f$ is “injective^{}” (although a priori $D$ may not be a set). This already sounds suspicious — we have an “injection” of the “power set^{}” of $D$ into $D$ — and with a little more work we can massage it into a contradiction^{}.
Suppose given $\theta :(D\to \mathrm{\U0001d5af\U0001d5cb\U0001d5c8\U0001d5c9})\to \mathrm{\U0001d5af\U0001d5cb\U0001d5c8\U0001d5c9}$, and define $\delta :D\to \mathrm{\U0001d5af\U0001d5cb\U0001d5c8\U0001d5c9}$ by
$$\delta (d):\equiv \exists (\gamma :D\to \mathrm{\U0001d5af\U0001d5cb\U0001d5c8\U0001d5c9}).(f(\gamma )=d)\times \theta (\gamma ).$$  (5.6.2) 
We claim that $p(\delta )=\theta $. By function extensionality, it suffices to show $p(\delta )(\gamma ){=}_{\mathrm{\U0001d5af\U0001d5cb\U0001d5c8\U0001d5c9}}\theta (\gamma )$ for any $\gamma :D\to \mathrm{\U0001d5af\U0001d5cb\U0001d5c8\U0001d5c9}$. And by univalence, for this it suffices to show that each implies the other. Now by definition of $p$, we have
$p(\delta )(\gamma )$  $\equiv \delta (f(\gamma ))$  
$\equiv \exists ({\gamma}^{\prime}:D\to \mathrm{\U0001d5af\U0001d5cb\U0001d5c8\U0001d5c9}).(f({\gamma}^{\prime})=f(\gamma ))\times \theta ({\gamma}^{\prime}).$ 
Clearly this holds if $\theta (\gamma )$, since we may take ${\gamma}^{\prime}:\equiv \gamma $. On the other hand, if we have ${\gamma}^{\prime}$ with $f({\gamma}^{\prime})=f(\gamma )$ and $\theta ({\gamma}^{\prime})$, then ${\gamma}^{\prime}=\gamma $ since $f$ is injective, hence also $\theta (\gamma )$.
This completes^{} the proof that $p(\delta )=\theta $. Thus, every element $\theta :(D\to \mathrm{\U0001d5af\U0001d5cb\U0001d5c8\U0001d5c9})\to \mathrm{\U0001d5af\U0001d5cb\U0001d5c8\U0001d5c9}$ is the image under $p$ of some element $\delta :D\to \mathrm{\U0001d5af\U0001d5cb\U0001d5c8\U0001d5c9}$. However, if we define $\theta $ by a classic diagonalization:
$$\theta (\gamma ):\equiv \mathrm{\neg}p(\gamma )(\gamma )\mathit{\hspace{1em}}\text{for all}\gamma :D\to \mathrm{\U0001d5af\U0001d5cb\U0001d5c8\U0001d5c9}$$ 
then from $\theta =p(\delta )$ we deduce $p(\delta )(\delta )=\mathrm{\neg}p(\delta )(\delta )$. This is a contradiction: no proposition^{} can be equivalent^{} to its negation^{}. (Supposing $P\iff \mathrm{\neg}P$, if $P$, then $\mathrm{\neg}P$, and so $\mathrm{\U0001d7ce}$; hence $\mathrm{\neg}P$, but then $P$, and so $\mathrm{\U0001d7ce}$.)
Remark 5.6.3.
There is a question of universe^{} size to be addressed. In general, an inductive type must live in a universe that already contains all the types going into its definition. Thus if in the definition of $D$, the ambiguous notation $\mathrm{Prop}$ means ${\mathrm{Prop}}_{\mathrm{U}}$, then we do not have $D\mathrm{:}\mathrm{U}$ but only $D\mathrm{:}{\mathrm{U}}^{\mathrm{\prime}}$ for some larger universe ${\mathrm{U}}^{\mathrm{\prime}}$ with $\mathrm{U}\mathrm{:}{\mathrm{U}}^{\mathrm{\prime}}$. In a predicative theory, therefore, the righthand side of (5.6.2) lives in ${\mathrm{Prop}}_{{\mathrm{U}}^{\mathrm{\prime}}}$, not ${\mathrm{Prop}}_{\mathrm{U}}$. So this contradiction does require the propositional resizing axiom mentioned in §3.5 (http://planetmath.org/35subsetsandpropositionalresizing).
This counterexample suggests that we should ban an inductive type from ever appearing on the left of an arrow in the domain of its constructors, even if that appearance is nested in other arrows so as to eventually become covariant. (Similarly, we also forbid it from appearing in the domain of a dependent function type.) This restriction is called strict positivity (ordinary “positivity” being essentially covariance), and it turns out to suffice.
In conclusion^{}, therefore, a valid inductive definition of a type $W$ consists of a list of constructors. Each constructor is assigned a type that is a function type taking some number (possibly zero) of inputs (possibly dependent on one another) and returning an element of $W$. Finally, we allow $W$ itself to occur in the input types of its constructors, but only strictly positively. This essentially means that each argument of a constructor is either a type not involving $W$, or some iterated function type with codomain $W$. For instance, the following is a valid constructor type:
$$c:(A\to W)\to (B\to C\to W)\to D\to W\to W.$$  (5.6.4) 
All of these function types can also be dependent functions ($\mathrm{\Pi}$types).^{1}^{1}In the language^{} of §5.4 (http://planetmath.org/54inductivetypesareinitialalgebras), the condition of strict positivity ensures that the relevant endofunctor is polynomial^{}. It is wellknown in category theory^{} that not all endofunctors can have initial algebras; restricting to polynomial functors ensures consistency. One can consider various relaxations of this condition, but in this book we will restrict ourselves to strict positivity as defined here.
Note we require that an inductive definition is given by a finite list of constructors. This is simply because we have to write it down on the page. If we want an inductive type which behaves as if it has an infinite^{} number of constructors, we can simply parametrize one constructor by some infinite type. For instance, a constructor such as $\mathbb{N}\to W\to W$ can be thought of as equivalent to countably many constructors of the form $W\to W$. (Of course, the infinity^{} is now internal to the type theory, but this is as it should be for any foundational system.) Similarly, if we want a constructor that takes “infinitely many arguments”, we can allow it to take a family of arguments parametrized by some infinite type, such as $(\mathbb{N}\to W)\to W$ which takes an infinite sequence^{} of elements of $W$.
Now, once we have such an inductive definition, what can we do with it? Firstly, there is a recursion principle stating that in order to define a function $f:W\to P$, it suffices to consider the case when the input $w:W$ arises from one of the constructors, allowing ourselves to recursively call $f$ on the inputs to that constructor. For the example constructor (5.6.4), we would require $P$ to be equipped with a function of type
$$d:(A\to W)\to (A\to P)\to (B\to C\to W)\to (B\to C\to P)\to D\to W\to P\to P.$$  (5.6.5) 
Under these hypotheses, the recursion principle yields $f:W\to P$, which moreover “preserves the constructor data” in the evident way — this is the computation rule, where we use covariance of the inputs. For instance, in the example (5.6.4), the computation rule says that for any $\alpha :A\to W$, $\beta :B\to C\to W$, $\delta :d$, and $\omega :W$, we have
$$f(c(\alpha ,\beta ,\delta ,\omega ))\equiv d(\alpha ,f\circ \alpha ,\beta ,f\circ \beta ,\delta ,\omega ,f(\omega )).$$  (5.6.5) 
The induction principle for a general inductive type $W$ is only a little more complicated. Of course, we start with a type family $P:W\to \mathcal{U}$, which we require to be equipped with constructor data “lying over” the constructor data of $W$. That means the “recursive call” arguments such as $A\to P$ above must be replaced by dependent functions with types such as ${\prod}_{(a:A)}P(\alpha (a))$. In the full example of (5.6.4), the corresponding hypothesis^{} for the induction principle would require
$$\begin{array}{c}d:\prod _{\alpha :A\to W}\left(\prod _{a:A}P(\alpha (a))\right)\to \prod _{\beta :B\to C\to W}\left(\prod _{(b:B)}\prod _{(c:C)}P(\beta (b,c))\right)\to \hfill \\ \hfill \prod _{\delta :D}\prod _{\omega :W}P(\omega )\to P(c(\alpha ,\beta ,\delta ,\omega )).\end{array}$$  (5.6.6) 
The corresponding computation rule looks identical to (5.6.5). Of course, the recursion principle is the special case of the induction principle where $P$ is a constant family. As we have mentioned before, the induction principle is also called the eliminator, and the recursion principle the nondependent eliminator.
As discussed in §1.10 (http://planetmath.org/110patternmatchingandrecursion), we also allow ourselves to invoke the induction and recursion principles implicitly, writing a definitional equation with $:\equiv $ for each expression that would be the hypotheses of the induction principle. This is called giving a definition by (dependent) pattern matching. In our running example, this means we could define $f:{\prod}_{(w:W)}P(w)$ by
$$f(c(\alpha ,\beta ,\delta ,\omega )):\equiv \mathrm{\cdots}$$ 
where $\alpha :A\to W$ and $\beta :B\to C\to W$ and $\delta :D$ and $\omega :W$ are variables that are bound in the righthand side. Moreover, the righthand side may involve recursive calls to $f$ of the form $f(\alpha (a))$, $f(\beta (b,c))$, and $f(\omega )$. When this definition is repackaged in terms of the induction principle, we replace such recursive calls by $\overline{\alpha}(a)$, $\overline{\beta}(b,c)$, and $\overline{\omega}$, respectively, for new variables
$\overline{\alpha}$  $:{\displaystyle \prod _{a:A}}P(\alpha (a))$  
$\overline{\beta}$  $:{\displaystyle \prod _{(b:B)}}{\displaystyle \prod _{(c:C)}}P(\beta (b,c))$  
$\overline{\omega}$  $:P(\omega ).$ 
Then we could write
$$f:\equiv {\mathrm{\U0001d5c2\U0001d5c7\U0001d5bd}}_{W}(P,\lambda \alpha .\lambda \overline{\alpha}.\lambda \beta .\lambda \overline{\beta}.\lambda \delta .\lambda \omega .\lambda \overline{\omega}.\mathrm{\cdots})$$ 
where the second argument to ${\mathrm{\U0001d5c2\U0001d5c7\U0001d5bd}}_{W}$ has the type of (5.6.6).
We will not attempt to give a formal presentation^{} of the grammar^{} of a valid inductive definition and its resulting induction and recursion principles and pattern matching rules. This is possible to do (indeed, it is necessary to do if implementing a computer proof assistant), but provides no additional insight. With practice, one learns to automatically deduce the induction and recursion principles for any inductive definition, and to use them without having to think twice.
Title  5.6 The general syntax of inductive definitions 
\metatable 