5.3 W-types

5.3 W-types

Inductive types are very general, which is excellent for their usefulness and applicability, but makes them difficult to study as a whole.
Fortunately, they can all be formally

reduced

to a few special cases.
It is beyond the scope of this book to discuss this

reduction

— which is anyway irrelevant to the mathematician using

type theory

in practice — but we will take a little time to discuss the one of the basic special cases that we have not yet met.
These are Martin-Löf’s

W

-types

, also known as the types of

well-founded

trees

.

𝖶

-types are a

generalization

of such types as

natural numbers

, lists, and

binary trees

, which are sufficiently general to encapsulate the “

recursion

” aspect of

any

inductive type.

A particular

𝖶

-type is specified by giving two

parameters

A

:

𝒰

and

B

:

A

→

𝒰

, in which case the resulting

𝖶

-type is written

𝖶

(

a

:

A

)

⁢

B

⁢

(

a

)

.
The type

A

represents the type of

labels

for

𝖶

(

a

:

A

)

⁢

B

⁢

(

a

)

, which

function

as constructors (however, we reserve that word for the actual functions which arise in inductive definitions). For

instance

, when defining natural numbers as a

𝖶

-type,
the type

A

would be the type

𝟐

inhabited by the two

elements

0

𝟐

and

1

𝟐

, since there are precisely two ways to obtain a natural number — either it will be zero or a

successor

of another natural number.

The type family

B

:

A

→

𝒰

is used to record the arity of labels: a label

a

:

A

will take a family of inductive

arguments

, indexed over

B

⁢

(

a

)

. We can therefore think of the “

B

⁢

(

a

)

-many” arguments of

a

. These arguments are represented by a function

f

:

B

⁢

(

a

)

→

𝖶

(

a

:

A

)

⁢

B

⁢

(

a

)

, with the understanding that for any

b

:

B

⁢

(

a

)

,

f

⁢

(

b

)

is the “

b

-th” argument to the label

a

. The

𝖶

-type

𝖶

(

a

:

A

)

⁢

B

⁢

(

a

)

can thus be thought of as the type of well-founded trees, where nodes are labeled by elements of

A

and each node labeled by

a

:

A

has

B

⁢

(

a

)

-many branches.

In the case of natural numbers, the label

0

𝟐

has arity 0, since it constructs the

constant

zero; the label

1

𝟐

has arity 1, since it constructs the successor of its argument. We can capture this by using simple elimination on

𝟐

to define a function

𝗋𝖾𝖼

𝟐

⁢

(

𝒰

,

𝟎

,

𝟏

)

into a

universe

of types; this function returns the empty type

𝟎

for

0

𝟐

and the unit type

𝟏

for

1

𝟐

. We can thus define

𝐍

𝐰

:

≡

𝖶

(

b

:

𝟐

)

𝗋𝖾𝖼

𝟐

(

𝒰

,

𝟎

,

𝟏

)

where the

superscript

𝐰

serves to distinguish this version of natural numbers from the previously used one.
Similarly, we can define the type of lists over

A

as a

𝖶

-type with

𝟏

+

A

many labels: one nullary label for the empty list, plus one unary label for each

a

:

A

, corresponding to appending

a

to the head of a list:

𝖫𝗂𝗌𝗍

(

A

)

:

≡

𝖶

(

x

:

𝟏

+

A

)

𝗋𝖾𝖼

𝟏

+

A

(

𝒰

,

0

,

λ

a

. 1

)

.

In general, the

𝖶

-type

𝖶

(

x

:

A

)

⁢

B

⁢

(

x

)

specified by

A

:

𝒰

and

B

:

A

→

𝒰

is the inductive type generated by the following constructor:

•

𝗌𝗎𝗉

:

∏

(

a

:

A

)

(

B

(

a

)

→

𝖶

(

x

:

A

)

B

(

x

)

)

→

𝖶

(

x

:

A

)

B

(

x

)

.

The constructor

𝗌𝗎𝗉

(short for

supremum

) takes a label

a

:

A

and a function

f

:

B

⁢

(

a

)

→

𝖶

(

x

:

A

)

⁢

B

⁢

(

x

)

representing the arguments to

a

, and constructs a new element of

𝖶

(

x

:

A

)

⁢

B

⁢

(

x

)

. Using our previous

encoding

of natural numbers as

𝖶

-types, we can for instance define

0

𝐰

:

≡

𝗌𝗎𝗉

(

0

𝟐

,

λ

x

.

𝗋𝖾𝖼

𝟎

(

𝐍

𝐰

,

x

)

)

.

Put differently, we use the label

0

𝟐

to construct

0

𝐰

. Then,

𝗋𝖾𝖼

𝟐

⁢

(

𝒰

,

𝟎

,

𝟏

,

0

𝟐

)

evaluates to

𝟎

, as it should since

0

𝟐

is a nullary label. Thus, we need to construct a function

f

:

𝟎

→

𝐍

𝐰

, which represents the (zero) arguments supplied to

0

𝟐

. This is of course

trivial

, using simple elimination on

𝟎

as shown. Similarly, we can define

1

𝐰

:

≡

𝗌𝗎𝗉

(

1

𝟐

,

λ

x

. 0

𝐰

)

2

𝐰

:

≡

𝗌𝗎𝗉

(

1

𝟐

,

λ

x

. 1

𝐰

)

and so on.

We have the following

induction

principle for

𝖶

-types:

•

When proving a statement

E

:

(

𝖶

(

x

:

A

)

⁢

B

⁢

(

x

)

)

→

𝒰

about

all

elements of the

𝖶

-type

𝖶

(

x

:

A

)

⁢

B

⁢

(

x

)

, it suffices to prove it for

𝗌𝗎𝗉

⁢

(

a

,

f

)

, assuming it holds for all

f

⁢

(

b

)

with

b

:

B

⁢

(

a

)

.
In other words, it suffices to give a proof

e

:

∏

(

a

:

A

)

∏

(

f

:

B

(

a

)

→

𝖶

(

x

:

A

)

B

(

x

)

)

∏

(

g

:

∏

(

b

:

B

(

a

)

)

E

(

f

(

b

)

)

)

E

⁢

(

𝗌𝗎𝗉

⁢

(

a

,

f

)

)

The

variable

g

represents our

inductive hypothesis

, namely that all arguments of

a

satisfy

E

. To state this, we quantify over all elements of type

B

⁢

(

a

)

, since each

b

:

B

⁢

(

a

)

corresponds to one argument

f

⁢

(

b

)

of

a

.

How would we define the function

𝖽𝗈𝗎𝖻𝗅𝖾

on natural numbers encoded as a

𝖶

-type? We would like to use the recursion principle of

𝐍

𝐰

with a codomain of

𝐍

𝐰

itself. We thus need to construct a suitable function

e

:

∏

(

a

:

𝟐

)

∏

(

f

:

B

(

a

)

→

𝐍

𝐰

)

∏

(

g

:

B

(

a

)

→

𝐍

𝐰

)

𝐍

𝐰

which will represent the recurrence for the

𝖽𝗈𝗎𝖻𝗅𝖾

function; for simplicity we denote the type family

𝗋𝖾𝖼

𝟐

⁢

(

𝒰

,

𝟎

,

𝟏

)

by

B

.

Clearly,

e

will be a function taking

a

:

𝟐

as its first argument. The next step is to perform case

analysis

on

a

and proceed based on whether it is

0

𝟐

or

1

𝟐

. This suggests the following form

e

:

≡

λ

a

.

𝗋𝖾𝖼

𝟐

(

C

,

e

0

,

e

1

,

a

)

where

C

:

≡

∏

(

f

:

B

(

a

)

→

𝐍

𝐰

)

∏

(

g

:

B

(

a

)

→

𝐍

𝐰

)

𝐍

𝐰

If

a

is

0

𝟐

, the type

B

⁢

(

a

)

becomes

𝟎

. Thus, given

f

:

𝟎

→

𝐍

𝐰

and

g

:

𝟎

→

𝐍

𝐰

, we want to construct an element of

𝐍

𝐰

. Since the label

0

𝟐

represents

𝟎

, it needs zero inductive arguments and the variables

f

and

g

are irrelevant. We return

0

𝐰

as a result:

e

0

:

≡

λ

f

.

λ

g

. 0

𝐰

Analogously, if

a

is

1

𝟐

, the type

B

⁢

(

a

)

becomes

𝟏

.
Since the label

1

𝟐

represents the successor

operator

, it needs one inductive argument — the

predecessor

— which is represented by the variable

f

:

𝟏

→

𝐍

𝐰

.
The value of the

recursive

call on the predecessor is represented by the variable

g

:

𝟏

→

𝐍

𝐰

.
Thus, taking this value (namely

g

⁢

(

⋆

)

) and applying the successor operator twice thus yields the desired result:

e

1

:

≡

λ

f

.

λ

g

.

𝗌𝗎𝗉

(

1

𝟐

,

(

λ

x

.

𝗌𝗎𝗉

(

1

𝟐

,

(

λ

y

.

g

(

⋆

)

)

)

)

)

.

Putting this together, we thus have

𝖽𝗈𝗎𝖻𝗅𝖾

:

≡

𝗋𝖾𝖼

𝐍

𝐰

(

𝐍

𝐰

,

e

)

with

e

as defined above.

The associated

computation

rule for the function

𝗋𝖾𝖼

𝖶

(

x

:

A

)

⁢

B

⁢

(

x

)

⁢

(

E

,

e

)

:

∏

(

w

:

𝖶

(

x

:

A

)

B

(

x

)

)

E

⁢

(

w

)

is as follows.

•

For any

a

:

A

and

f

:

B

⁢

(

a

)

→

𝖶

(

x

:

A

)

⁢

B

⁢

(

x

)

we have

𝗋𝖾𝖼

𝖶

(

x

:

A

)

⁢

B

⁢

(

x

)

(

E

,

e

,

𝗌𝗎𝗉

(

a

,

f

)

)

≡

e

(

a

,

f

,

(

λ

b

.

𝗋𝖾𝖼

𝖶

(

x

:

A

)

⁢

B

⁢

(

x

)

(

E

,

f

(

b

)

)

)

)

.

In other words, the function

𝗋𝖾𝖼

𝖶

(

x

:

A

)

⁢

B

⁢

(

x

)

⁢

(

E

,

e

)

satisfies the recurrence

e

.

By the above computation rule, the function

𝖽𝗈𝗎𝖻𝗅𝖾

behaves as expected:

𝖽𝗈𝗎𝖻𝗅𝖾

⁢

(

0

𝐰

)

≡

𝗋𝖾𝖼

𝐍

𝐰

(

𝐍

𝐰

,

e

,

𝗌𝗎𝗉

(

0

𝟐

,

λ

x

.

𝗋𝖾𝖼

𝟎

(

𝐍

𝐰

,

x

)

)

)

≡

e

(

0

𝟐

,

(

λ

x

.

𝗋𝖾𝖼

𝟎

(

𝐍

𝐰

,

x

)

)

,

(

λ

x

.

𝖽𝗈𝗎𝖻𝗅𝖾

(

𝗋𝖾𝖼

𝟎

(

𝐍

𝐰

,

x

)

)

)

)

≡

e

t

(

(

λ

x

.

𝗋𝖾𝖼

𝟎

(

𝐍

𝐰

,

x

)

)

,

(

λ

x

.

𝖽𝗈𝗎𝖻𝗅𝖾

(

𝗋𝖾𝖼

𝟎

(

𝐍

𝐰

,

x

)

)

)

)

≡

0

𝐰

and

𝖽𝗈𝗎𝖻𝗅𝖾

⁢

(

1

𝐰

)

≡

𝗋𝖾𝖼

𝐍

𝐰

⁢

(

𝐍

𝐰

,

e

,

𝗌𝗎𝗉

⁢

(

1

𝟐

,

λ

⁢

x

⁢

. 0

𝐰

)

)

≡

e

(

1

𝟐

,

(

λ

x

. 0

𝐰

)

,

(

λ

x

.

𝖽𝗈𝗎𝖻𝗅𝖾

(

0

𝐰

)

)

)

≡

e

f

(

(

λ

x

. 0

𝐰

)

,

(

λ

x

.

𝖽𝗈𝗎𝖻𝗅𝖾

(

0

𝐰

)

)

)

≡

𝗌𝗎𝗉

(

1

𝟐

,

(

λ

x

.

𝗌𝗎𝗉

(

1

𝟐

,

(

λ

y

.

𝖽𝗈𝗎𝖻𝗅𝖾

(

0

𝐰

)

)

)

)

)

≡

𝗌𝗎𝗉

(

1

𝟐

,

(

λ

x

.

𝗌𝗎𝗉

(

1

𝟐

,

(

λ

y

. 0

𝐰

)

)

)

)

≡

2

𝐰

and so on.

Just as for natural numbers, we can prove a

uniqueness theorem

for

𝖶

-types:

Theorem 5.3.1

.

Let

g

,

h

:

∏

(

w

:

W

(

x

:

A

)

B

(

x

)

)

E

⁢

(

w

)

be two functions which satisfy the recurrence

e

:

∏

a

,

f

(

∏

b

:

B

⁢

(

a

)

E

⁢

(

f

⁢

(

b

)

)

)

→

E

⁢

(

𝗌𝗎𝗉

⁢

(

a

,

f

)

)

,

i.e., such that

∏

a

,

f

g

(

𝗌𝗎𝗉

(

a

,

f

)

)

=

e

(

a

,

f

,

λ

b

.

g

(

f

(

b

)

)

)

,

∏

a

,

f

h

(

𝗌𝗎𝗉

(

a

,

f

)

)

=

e

(

a

,

f

,

λ

b

.

h

(

f

(

b

)

)

)

.

Then

g

and

h

are equal.

Title

5.3 W-types

\metatable

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

LaTeXML