5.7 Generalizations of inductive types
The notion of inductive type has been studied in type theory for many years, and admits of many, many generalizations: inductive type families, mutual inductive types, inductive-inductive types, inductive-recursive types, etc. In this section we give an overview of some of these, a few of which will be used later in the book. (In http://planetmath.org/node/87579Chapter 6 we will study in more depth a very different generalization of inductive types, which is particular to homotopy type theory.)
Most of these generalizations involve allowing ourselves to define more than one type by induction at the same time. One very simple example of this, which we have already seen, is the coproduct . It would be tedious indeed if we had to write down separate inductive definitions for , for , for , and so on every time we wanted to consider the coproduct of two types. Instead, we make one definition in which and are variables standing for types; in type theory they are called parameters. Thus technically speaking, what results from the definition is not a single type, but a family of types , taking two types as input and producing their coproduct. Similarly, the type of lists is a family in which the type is a parameter.
In mathematics, this sort of thing is so obvious as to not be worth mentioning, but we bring it up in order to contrast it with the next example. Note that each type is independently defined inductively, as is each type . By contrast, we might also consider defining a whole type family by induction together. The difference is that now the constructors may change the index , and as a consequence we cannot say that the individual types are inductively defined, only that the entire family is inductively defined.
The standard example is the type of lists of specified length, traditionally called vectors. We fix a parameter type , and define a type family , for , generated by the following constructors:
-
β’
a vector of length zero,
-
β’
a function .
In contrast to lists, vectors (with elements from a fixed type ) form a family of types indexed by their length. While is a parameter, we say that is an index of the inductive family. An individual type such as is not inductively defined: the constructors which build elements of take input from a different type in the family, such as .
In particular, the induction principle must refer to the entire type family as well; thus the hypotheses and the conclusion must quantify over the indices appropriately. In the case of vectors, the induction principle states that given a type family , together with
-
β’
an element , and
-
β’
a function
there exists a function such that
One use of inductive families is to define predicates inductively. For instance, we might define the predicate as an inductive family indexed by , with the following constructors:
-
β’
an element ,
-
β’
a function .
In other words, we stipulate that is even, and that if is even then so is . These constructors βobviouslyβ give no way to construct an element of, say, , and since is supposed to be freely generated by these constructors, there must be no such element. (Actually proving that is not entirely trivial, however). The induction principle for says that to prove something about all even natural numbers, it suffices to prove it for and verify that it is preserved by adding two.
Inductively defined predicates are much used in computer formalization of mathematics and software verification. But we will not have much use for them, with a couple of exceptions in Β§10.3 (http://planetmath.org/103ordinalnumbers),Β§11.5 (http://planetmath.org/115compactnessoftheinterval).
Another important special case is when the indexing type of an inductive family is finite. In this case, we can equivalently express the inductive definition as a finite collection of types defined by mutual induction. For instance, we might define the types and of even and odd natural numbers by mutual induction, where is generated by constructors
-
β’
and
-
β’
,
while is generated by the one constructor
-
β’
.
Note that and are simple types (not type families), but their constructors can refer to each other. If we expressed this definition as an inductive type family , with and representing and respectively, it would instead have constructors:
-
β’
,
-
β’
,
-
β’
.
When expressed explicitly as a mutual inductive definition, the induction principle for and says that given and , along with
-
β’
,
-
β’
,
-
β’
,
there exist and such that
In particular, just as we can only induct over an inductive family βall at onceβ, we have to induct on and simultaneously. We will not have much use for mutual inductive definitions in this book either.
A further, more radical, generalization is to allow definition of a type family in which not only the types , but the type itself, is defined as part of one big induction. In other words, not only do we specify constructors for the s which can take inputs from other s, as with inductive families, we also at the same time specify constructors for itself, which can take inputs from the s. This can be regarded as an inductive family in which the indices are inductively defined simultaneously with the indexed types, or as a mutual inductive definition in which one of the types can depend on the other. More complicated dependency structures are also possible. In general, these are called inductive-inductive definitions. For the most part, we will not use them in this book, but their higher variant (see http://planetmath.org/node/87579Chapter 6) will appear in a couple of experimental examples in http://planetmath.org/node/87585Chapter 11.
The last generalization we wish to mention is inductive-recursive definitions, in which a type is defined inductively at the same time as a recursive function on it. That is, we fix a known type , and give constructors for an inductive type and at the same time define a function using the recursion principle for resulting from its constructors β with the twist that the constructors of are allowed to refer also to the values of . We do not yet know how to justify such definitions from a homotopical perspective, and we will not use any of them in this book.
Title | 5.7 Generalizations of inductive types |
\metatable |