5.4 Inductive types are initial algebras
As suggested earlier, inductive types also have a category-theoretic universal property.
They are homotopy-initial algebras
: initial objects
(up to coherent homotopy
) in a category
of “algebras” determined by the specified constructors.
As a simple example, consider the natural numbers
.
The appropriate sort of “algebra” here is a type equipped with the same structure
that the constructors of ℕ give to it.
Definition 5.4.1.
A N-algebra is a type C with two elements c0:C, cs:C→C. The type of such algebras is
ℕ𝖠𝗅𝗀:≡∑C:𝒰C×(C→C). |
Definition 5.4.2.
A N-homomorphism
between N-algebras (C,c0,cs) and (D,d0,ds) is a function h:C→D such that h(c0)=d0 and h(cs(c))=ds(h(c)) for all c:C. The type of such homomorphisms is
ℕ𝖧𝗈𝗆((C,c0,cs),(D,d0,ds)):≡∑(h:C→D)(h(c0)=d0)×∏(c:C)(h(cs(c))=ds(h(c))). |
We thus have a category of ℕ-algebras and ℕ-homomorphisms, and the claim is that ℕ is the initial object of this category. A category theorist will immediately recognize this as the definition of a natural numbers object in a category.
Of course, since our types behave like ∞-groupoids, we actually have an (∞,1)-category of ℕ-algebras, and we should ask ℕ to be initial in the appropriate (∞,1)-categorical sense.
Fortunately, we can formulate this without needing to define (∞,1)-categories.
Definition 5.4.3.
A N-algebra I is called homotopy-initial,
or h-initial
for short, if for any other N-algebra C, the type of N-homomorphisms from I to C is contractible. Thus,
𝗂𝗌𝖧𝗂𝗇𝗂𝗍ℕ(I):≡∏C:ℕ𝖠𝗅𝗀𝗂𝗌𝖢𝗈𝗇𝗍𝗋(ℕ𝖧𝗈𝗆(I,C)). |
When they exist, h-initial algebras are unique — not just up to isomorphism, as usual in category theory
, but up to equality, by the univalence axiom.
Theorem 5.4.4.
Any two h-initial N-algebras are equal. Thus, the type of h-initial N-algebras is a mere proposition.
Proof.
Suppose I and J are h-initial ℕ-algebras. Then ℕ𝖧𝗈𝗆(I,J) is contractible, hence inhabited by some ℕ-homomorphism f:I→J, and likewise we have an ℕ-homomorphism g:J→I. Now the composite g∘f is a ℕ-homomorphism from I to I, as is 𝗂𝖽I; but ℕ𝖧𝗈𝗆(I,I) is contractible, so g∘f=𝗂𝖽I. Similarly, f∘g=𝗂𝖽J. Hence I≃J, and so I=J. Since being contractible is a mere proposition and dependent products preserve mere propositions, it follows that being h-initial is itself a mere proposition. Thus any two proofs that I (or J) is h-initial are necessarily equal, which finishes the proof. ∎
We now have the following theorem.
Theorem 5.4.5.
The N-algebra (N,0,succ) is homotopy initial.
Sketch of proof.
Fix an arbitrary ℕ-algebra (C,c0,cs). The recursion principle of ℕ yields a function f:ℕ→C defined by
f(0) | :≡c0 | ||
f(𝗌𝗎𝖼𝖼(n)) | :≡cs(f(n)). |
These two equalities make f an ℕ-homomorphism, which we can take as the center of contraction for ℕ𝖧𝗈𝗆(ℕ,C).
The uniqueness theorem (Theorem 5.1.1 (http://planetmath.org/51introductiontoinductivetypes#Thmprethm1)) then implies that any other ℕ-homomorphism is equal to f.
∎
To place this in a more general context, it is useful to consider the notion of algebra for an endofunctor.
Note that to make a type C into a ℕ-algebra is the same as to give a function c:C+𝟏→C, and a function f:C→D is a ℕ-homomorphism just when f∘c∼d∘(f+𝟏).
In categorical language, this means the ℕ-algebras are the algebras for the endofunctor F(X):≡X+1 of the category of types.
For a more generic case, consider the 𝖶-type associated to A:𝒰 and B:A→𝒰. In this case we have an associated polynomial functor:
P(X)=∑x:A(B(x)→X). | (5.4.6) |
Actually, this assignment is functorial only up to homotopy, but this makes no difference in what follows.
By definition, a P-algebra
is then a type C equipped a function sC:PC→C.
By the universal property of Σ-types, this is equivalent
to giving a function ∏(a:A)(B(a)→C)→C.
We will also call such objects 𝖶-algebras
for A and B, and we write
𝖶𝖠𝗅𝗀(A,B):≡∑(C:𝒰)∏(a:A)(B(a)→C)→C. |
Similarly, for P-algebras (C,sC) and (D,sD), a homomorphism between them (f,sf):(C,sC)→(D,sD) consists of a function f:C→D and a homotopy between maps PC→D
sf:f∘sC=sD∘Pf, |
where Pf:PC→PD is the result of the easily-definable action of P on f:C→D. Such an algebra homomorphism can be represented suggestively in the form:
HoTT_fig_5.4.1.png
In terms of elements, f is a P-homomorphism (or 𝖶-homomorphism) if
f(sC(a,h))=sD(a,λb.f(h(b))). |
We have the type of 𝖶-homomorphisms:
𝖶𝖧𝗈𝗆A,B((C,c),(D,d)):≡∑(h:C→D)∏(a:A)∏(f:B(a)→C)h(c(a,f))=λb.h(f(b)) |
Finally, a P-algebra (C,sC) is said to be homotopy-initial if for every P-algebra (D,sD), the type of all algebra homomorphisms (C,sC)→(D,sD) is contractible. That is,
𝗂𝗌𝖧𝗂𝗇𝗂𝗍𝖶(A,B,I):≡∏C:𝖶𝖠𝗅𝗀(A,B)𝗂𝗌𝖢𝗈𝗇𝗍𝗋(𝖶𝖧𝗈𝗆A,B(I,C)). |
Now the analogous theorem to Theorem 5.4.5 (http://planetmath.org/54inductivetypesareinitialalgebras#Thmprethm2) is:
Theorem 5.4.7.
For any type A:U and type family B:A→U, the W-algebra (W(x:A)B(x),sup) is h-initial.
Sketch of proof.
Suppose we have A:𝒰 and B:A→𝒰,
and consider the associated polynomial functor P(X):≡∑(x:A)(B(x)→X).
Let W:≡𝖶(x:A)B(x). Then using
the 𝖶-introduction rule from §5.3 (http://planetmath.org/53wtypes), we have a structure map sW:≡𝗌𝗎𝗉:PW→W.
We want to show that the algebra (W,sW) is
h-initial. So, let us consider another algebra (C,sC) and show that the type T:≡𝖶𝖧𝗈𝗆A,B((W,sW),(C,sC))
of 𝖶-homomorphisms from (W,sW) to (C,sC) is contractible. To do
so, observe that the 𝖶-elimination rule and the 𝖶-computation
rule allow us to define a 𝖶-homomorphism (f,sf):(W,sW)→(C,sC),
thus showing that T is inhabited. It is furthermore necessary to show that for every 𝖶-homomorphism (g,sg):(W,sW)→(C,sC), there is an identity
proof
p:(f,sf)=(g,sg). | (5.4.8) |
This uses the fact that, in general, a type of the form (f,sf)=(g,sg) is equivalent to the type of what we call algebra 2-cells, whose canonical elements are pairs of the form (e,se), where e:f=g and se is a higher identity proof between the identity proofs represented by the following pasting diagrams:
HoTT_fig_5.4.2.png
In light of this fact, to prove that there exists an element as in (5.4.8), it is sufficient to show that there is an algebra 2-cell
(e,se):(f,sf)=(g,sg). |
The identity proof e:f=g is now constructed by function extensionality and 𝖶-elimination so as to guarantee the existence of the required identity proof se. ∎
Title | 5.4 Inductive types are initial algebras |
\metatable |