5.1 Introduction to inductive types

5.1 Introduction to inductive types

An

inductive type

X

can be intuitively understood as a type “freely generated” by a certain finite

collection

of

constructors

, each of which is a

function

(of some number of

arguments

) with codomain

X

.
This includes functions of zero arguments, which are simply elements of

X

.

When describing a particular inductive type, we list the constructors with bullets.
For

instance

, the type

𝟐

from §1.8 (

http://planetmath.org/18thetypeofbooleans

) is inductively generated by the following constructors:

•

0

𝟐

:

𝟐

•

1

𝟐

:

𝟐

Similarly,

𝟏

is inductively generated by the constructor:

•

⋆

:

𝟏

while

𝟎

is inductively generated by no constructors at all.
An example where the constructor functions take arguments is the

coproduct

A

+

B

, which is generated by the two constructors

•

𝗂𝗇𝗅

:

A

→

A

+

B

•

𝗂𝗇𝗋

:

B

→

A

+

B

.

And an example with a constructor taking multiple arguments is the

cartesian product

A

×

B

, which is generated by one constructor

•

(

–

,

–

)

:

A

→

B

→

A

×

B

.

Crucially, we also allow constructors of inductive types that take arguments from the inductive type being defined.
For instance, the type

ℕ

of

natural numbers

has constructors

•

0

:

ℕ

•

𝗌𝗎𝖼𝖼

:

ℕ

→

ℕ

.

Another useful example is the type

𝖫𝗂𝗌𝗍

⁢

(

A

)

of finite lists of elements of some type

A

, which has constructors

•

𝗇𝗂𝗅

:

𝖫𝗂𝗌𝗍

⁢

(

A

)

•

𝖼𝗈𝗇𝗌

:

A

→

𝖫𝗂𝗌𝗍

⁢

(

A

)

→

𝖫𝗂𝗌𝗍

⁢

(

A

)

.

Intuitively, we should understand an inductive type as being

freely generated by

its constructors.
That is, the elements of an inductive type are exactly what can be obtained by starting from nothing and applying the constructors repeatedly.
(We will see in §5.8 (

http://planetmath.org/58identitytypesandidentitysystems

),

http://planetmath.org/node/87579

Chapter 6 that this conception has to be modified slightly for more general kinds of inductive definitions, but for now it is

sufficient

.)
For instance, in the case of

𝟐

, we should expect that the only

elements

are

0

𝟐

and

1

𝟐

.
Similarly, in the case of

ℕ

, we should expect that every element is either

0

or obtained by applying

𝗌𝗎𝖼𝖼

to some “previously constructed” natural number.

Rather than assert

properties

such as this directly, however, we express them by means of an

induction

principle

, also called a

(dependent) elimination rule

.
We have seen these principles already in

http://planetmath.org/node/87533

Chapter 1.
For instance, the induction principle for

𝟐

is:

•

When proving a statement

E

:

𝟐

→

𝒰

about

all

inhabitants of

𝟐

, it suffices to prove it for

0

𝟐

and

1

𝟐

, i.e., to give proofs

e

0

:

E

⁢

(

0

𝟐

)

and

e

1

:

E

⁢

(

1

𝟐

)

.

Furthermore, the resulting proof

𝗂𝗇𝖽

𝟐

⁢

(

E

,

e

0

,

e

1

)

:

∏

(

b

:

𝟐

)

E

⁢

(

b

)

behaves as expected when applied to the constructors

0

𝟐

and

1

𝟐

; this principle is expressed by the

computation rules

:

•

We have

𝗂𝗇𝖽

𝟐

⁢

(

E

,

e

0

,

e

1

,

0

𝟐

)

≡

e

0

.

•

We have

𝗂𝗇𝖽

𝟐

⁢

(

E

,

e

0

,

e

1

,

1

𝟐

)

≡

e

1

.

Thus, the induction principle for the type

𝟐

of

booleans

allow us to reason by

case

analysis

.
Since neither of the two constructors takes any arguments, this is all we need for booleans.

For natural numbers, however, case analysis is generally not sufficient: in the case corresponding to the inductive step

𝗌𝗎𝖼𝖼

⁢

(

n

)

, we also want to presume that the statement being proven has already been shown for

n

.
This gives us the following induction principle:

•

When proving a statement

E

:

ℕ

→

𝒰

about

all

natural numbers, it suffices to prove it for

0

and for

𝗌𝗎𝖼𝖼

⁢

(

n

)

, assuming it holds
for

n

, i.e., we

construct

e

z

:

E

⁢

(

0

)

and

e

s

:

∏

(

n

:

ℕ

)

∏

(

y

:

E

(

n

)

)

E

⁢

(

𝗌𝗎𝖼𝖼

⁢

(

n

)

)

.

The

variable

y

represents

our

inductive hypothesis

. As in the case of booleans, we also have the associated computation rules for the function

𝗂𝗇𝖽

ℕ

⁢

(

E

,

e

z

,

e

s

)

:

∏

(

x

:

ℕ

)

E

⁢

(

x

)

:

•

𝗂𝗇𝖽

ℕ

⁢

(

E

,

e

z

,

e

s

,

0

)

≡

e

z

.

•

𝗂𝗇𝖽

ℕ

⁢

(

E

,

e

z

,

e

s

,

𝗌𝗎𝖼𝖼

⁢

(

n

)

)

≡

e

s

⁢

(

n

,

𝗂𝗇𝖽

ℕ

⁢

(

E

,

e

z

,

e

s

,

n

)

)

for any

n

:

ℕ

.

The dependent function

𝗂𝗇𝖽

ℕ

⁢

(

E

,

e

z

,

e

s

)

can thus be understood as being defined recursively on the argument

x

:

ℕ

, via the functions

e

z

and

e

s

which we call the

recurrences

.
When

x

is zero, the function simply returns

e

z

.
When

x

is the

successor

of another natural number

n

, the result is obtained by taking the recurrence

e

s

and substituting the specific

predecessor

n

and the

recursive

call value

𝗂𝗇𝖽

ℕ

⁢

(

E

,

e

z

,

e

s

,

n

)

.

The induction principles for all the examples mentioned above share this family resemblance.
In §5.6 (

http://planetmath.org/56thegeneralsyntaxofinductivedefinitions

) we will discuss a general notion of “inductive definition” and how to derive an appropriate

induction principle

for it, but first we investigate various commonalities between inductive definitions.

For instance, we have remarked in every case in

http://planetmath.org/node/87533

Chapter 1 that from the induction principle we can derive a

recursion

principle

in which the codomain is a simple type (rather than a family).
Both induction and recursion principles may seem odd, since they yield only the

existence

of a function without seeming to characterize it uniquely.
However, in fact the induction principle is strong enough also to prove its own

uniqueness principle

, as in the following

theorem

.

Theorem 5.1.1

.

Let

f

,

g

:

∏

(

x

:

N

)

E

⁢

(

x

)

be two functions which

satisfy

the recurrences

e

z

:

E

⁢

(

0

)

𝑎𝑛𝑑

e

s

:

∏

(

n

:

ℕ

)

∏

(

y

:

E

(

n

)

)

E

⁢

(

𝗌𝗎𝖼𝖼

⁢

(

n

)

)

up to propositional equality, i.e., such that

f

⁢

(

0

)

=

e

z

𝑎𝑛𝑑

g

⁢

(

0

)

=

e

z

as well as

∏

n

:

ℕ

f

⁢

(

𝗌𝗎𝖼𝖼

⁢

(

n

)

)

=

e

s

⁢

(

n

,

f

⁢

(

n

)

)

,

∏

n

:

ℕ

g

⁢

(

𝗌𝗎𝖼𝖼

⁢

(

n

)

)

=

e

s

⁢

(

n

,

g

⁢

(

n

)

)

.

Then

f

and

g

are equal.

Proof.

We use induction on the type family

D

(

x

)

:

≡

f

(

x

)

=

g

(

x

)

. For the base case, we have

f

⁢

(

0

)

=

e

z

=

g

⁢

(

0

)

For the inductive case, assume

n

:

ℕ

such that

f

⁢

(

n

)

=

g

⁢

(

n

)

. Then

f

⁢

(

𝗌𝗎𝖼𝖼

⁢

(

n

)

)

=

e

s

⁢

(

n

,

f

⁢

(

n

)

)

=

e

s

⁢

(

n

,

g

⁢

(

n

)

)

=

g

⁢

(

𝗌𝗎𝖼𝖼

⁢

(

n

)

)

The first and last equality follow from the

assumptions

on

f

and

g

. The middle equality follows from the inductive hypothesis and the fact that application

preserves

equality. This gives us

pointwise

equality between

f

and

g

; invoking function extensionality finishes the proof.
∎

Note that the uniqueness principle applies even to functions that only satisfy the recurrences

up to propositional equality

, i.e. a path.
Of course, the particular function obtained from the induction principle satisfies these recurrences judgmentally; we will return to this point in §5.5 (

http://planetmath.org/55homotopyinductivetypes

).
On the other hand, the theorem itself only asserts a propositional equality between functions (see also

http://planetmath.org/node/87832

Exercise 5.2).
From a homotopical viewpoint it is natural to ask whether this path is

coherent

, i.e. whether the equality

f

=

g

is unique up to higher paths; in §5.4 (

http://planetmath.org/54inductivetypesareinitialalgebras

) we will see that this is in fact the case.

Of course,

similar

uniqueness theorems

for functions can generally be formulated and shown for other inductive types as well.
In the next

section

, we show how this uniqueness property, together with univalence, implies that an inductive type such as the natural numbers is completely characterized by its

introduction

, elimination, and computation rules.

Title

5.1 Introduction to inductive types

\metatable

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

LaTeXML