5.4 Inductive types are initial algebras

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

c

0

:

C

,

c

s

:

C

→

C

. The type of such algebras is

ℕ

𝖠𝗅𝗀

:

≡

∑

C

:

𝒰

C

×

(

C

→

C

)

.

Definition 5.4.2

.

A

N

-

homomorphism

between

N

-algebras

(

C

,

c

0

,

c

s

)

and

(

D

,

d

0

,

d

s

)

is a

function

h

:

C

→

D

such that

h

⁢

(

c

0

)

=

d

0

and

h

⁢

(

c

s

⁢

(

c

)

)

=

d

s

⁢

(

h

⁢

(

c

)

)

for all

c

:

C

. The type of such homomorphisms is

ℕ

𝖧𝗈𝗆

(

(

C

,

c

0

,

c

s

)

,

(

D

,

d

0

,

d

s

)

)

:

≡

∑

(

h

:

C

→

D

)

(

h

(

c

0

)

=

d

0

)

×

∏

(

c

:

C

)

(

h

(

c

s

(

c

)

)

=

d

s

(

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

,

c

0

,

c

s

)

.
The

recursion

principle of

ℕ

yields a function

f

:

ℕ

→

C

defined by

f

⁢

(

0

)

:

≡

c

0

f

⁢

(

𝗌𝗎𝖼𝖼

⁢

(

n

)

)

:

≡

c

s

(

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

s

C

:

P

⁢

C

→

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

,

s

C

)

and

(

D

,

s

D

)

, a

homomorphism

between them

(

f

,

s

f

)

:

(

C

,

s

C

)

→

(

D

,

s

D

)

consists of a function

f

:

C

→

D

and a homotopy between maps

P

⁢

C

→

D

s

f

:

f

∘

s

C

=

s

D

∘

P

⁢

f

,

where

P

⁢

f

:

P

⁢

C

→

P

⁢

D

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:

\includegraphics

HoTT_fig_5.4.1.png

In terms of elements,

f

is a

P

-homomorphism (or

𝖶

-homomorphism

) if

f

(

s

C

(

a

,

h

)

)

=

s

D

(

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

,

s

C

)

is said to be

homotopy-initial

if for every

P

-algebra

(

D

,

s

D

)

, the type of all algebra homomorphisms

(

C

,

s

C

)

→

(

D

,

s

D

)

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

s

W

:

≡

𝗌𝗎𝗉

:

P

W

→

W

.
We want to show that the algebra

(

W

,

s

W

)

is
h-initial. So, let us consider another algebra

(

C

,

s

C

)

and show that the type

T

:

≡

𝖶𝖧𝗈𝗆

A

,

B

(

(

W

,

s

W

)

,

(

C

,

s

C

)

)

of

𝖶

-homomorphisms from

(

W

,

s

W

)

to

(

C

,

s

C

)

is contractible. To do
so, observe that the

𝖶

-elimination rule and the

𝖶

-computation
rule allow us to define a

𝖶

-homomorphism

(

f

,

s

f

)

:

(

W

,

s

W

)

→

(

C

,

s

C

)

,
thus showing that

T

is inhabited. It is furthermore necessary to show that for every

𝖶

-homomorphism

(

g

,

s

g

)

:

(

W

,

s

W

)

→

(

C

,

s

C

)

, there is an

identity

proof

p

:

(

f

,

s

f

)

=

(

g

,

s

g

)

.

(5.4.8)

This uses the fact that, in general, a type of the form

(

f

,

s

f

)

=

(

g

,

s

g

)

is equivalent to the type of what we call

algebra

2

-cells

,
whose canonical
elements are pairs of the form

(

e

,

s

e

)

, where

e

:

f

=

g

and

s

e

is a higher identity proof between the identity proofs represented by the following pasting diagrams:

\includegraphics

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

,

s

e

)

:

(

f

,

s

f

)

=

(

g

,

s

g

)

.

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

s

e

.
∎

Title

5.4 Inductive types are initial algebras

\metatable

Generated on Thu Feb 8 19:36:37 2018 by

LaTeXML