1.8 The type of booleans

1.8 The type of booleans

The type of

booleans

𝟐

:

𝒰

is intended to have exactly two

elements

0

𝟐

,

1

𝟐

:

𝟐

. It is clear that we could

construct

this
type out of

coproduct

and unit types as

𝟏

+

𝟏

. However,
since it is used frequently, we give the explicit rules here.
Indeed, we are going to observe that we can also go the other way
and derive binary coproducts from

Σ

-types and

𝟐

.

To derive a

function

f

:

𝟐

→

C

we need

c

0

,

c

1

:

C

and
add the defining equations

f

⁢

(

0

𝟐

)

:

≡

c

0

,

f

⁢

(

1

𝟐

)

:

≡

c

1

.

The recursor corresponds to the if-then-else construct in
functional programming:

𝗋𝖾𝖼

𝟐

:

∏

C

:

𝒰

C

→

C

→

𝟐

→

C

with the defining equations

𝗋𝖾𝖼

𝟐

⁢

(

C

,

c

0

,

c

1

,

0

𝟐

)

:

≡

c

0

,

𝗋𝖾𝖼

𝟐

⁢

(

C

,

c

0

,

c

1

,

1

𝟐

)

:

≡

c

1

.

Given

C

:

𝟐

→

𝒰

, to derive a dependent function

f

:

∏

(

x

:

𝟐

)

C

⁢

(

x

)

we need

c

0

:

C

⁢

(

0

𝟐

)

and

c

1

:

C

⁢

(

1

𝟐

)

, in which case we can give the defining equations

f

⁢

(

0

𝟐

)

:

≡

c

0

,

f

⁢

(

1

𝟐

)

:

≡

c

1

.

We package this up into the

induction

principle

𝗂𝗇𝖽

𝟐

:

∏

(

C

:

𝟐

→

𝒰

)

C

⁢

(

0

𝟐

)

→

C

⁢

(

1

𝟐

)

→

∏

(

x

:

𝟐

)

C

⁢

(

x

)

with the defining equations

𝗂𝗇𝖽

𝟐

⁢

(

C

,

c

0

,

c

1

,

0

𝟐

)

:

≡

c

0

,

𝗂𝗇𝖽

𝟐

⁢

(

C

,

c

0

,

c

1

,

1

𝟐

)

:

≡

c

1

.

As an example, using the induction principle we can prove that, as we expect, every element of

𝟐

is either

1

𝟐

or

0

𝟐

.
As before, we use the equality types which we have not yet introduced, but we need only the fact that everything is equal to itself by

𝗋𝖾𝖿𝗅

x

:

x

=

x

.

Theorem 1.8.1

.

We have

∏

x

:

𝟐

(

x

=

0

𝟐

)

+

(

x

=

1

𝟐

)

.

Proof.

We use the induction principle with

C

(

x

)

:

≡

(

x

=

0

𝟐

)

+

(

x

=

1

𝟐

)

.
The two inputs are

𝗂𝗇𝗅

⁢

(

𝗋𝖾𝖿𝗅

0

𝟐

)

:

C

⁢

(

0

𝟐

)

and

𝗂𝗇𝗋

⁢

(

𝗋𝖾𝖿𝗅

1

𝟐

)

:

C

⁢

(

1

𝟐

)

.
∎

We have remarked that

Σ

-types can be regarded as analogous to indexed

disjoint unions

, while coproducts are binary disjoint unions.
It is natural to expect that a binary disjoint union

A

+

B

could be constructed as an indexed one over the two-element type

𝟐

.
For this we need a type family

P

:

𝟐

→

𝒰

such that

P

⁢

(

0

𝟐

)

≡

A

and

P

⁢

(

1

𝟐

)

≡

B

.
Indeed, we can obtain such a family precisely by the

recursion

principle for

𝟐

.
(The ability to define

type families

by induction and recursion, using the fact that the

universe

𝒰

is itself a type, is a subtle and important aspect of

type theory

.)
Thus, we could have defined

A

+

B

:

≡

∑

x

:

𝟐

𝗋𝖾𝖼

𝟐

(

𝒰

,

A

,

B

,

x

)

.

with

𝗂𝗇𝗅

⁢

(

a

)

:

≡

(

0

𝟐

,

a

)

,

𝗂𝗇𝗋

⁢

(

b

)

:

≡

(

1

𝟐

,

b

)

.

We leave it as an exercise to derive the induction principle of a coproduct type from this definition.
(See also PMlinkexternalExercise 1.5http://planetmath.org/node/87558,§5.2 (

http://planetmath.org/52uniquenessofinductivetypes

).)

We can apply the same idea to

products

and

Π

-types: we could have defined

A

×

B

:

≡

∏

x

:

𝟐

𝗋𝖾𝖼

𝟐

(

𝒰

,

A

,

B

,

x

)

Pairs could then be constructed using induction for

𝟐

:

(

a

,

b

)

:

≡

𝗂𝗇𝖽

𝟐

(

𝗋𝖾𝖼

𝟐

(

𝒰

,

A

,

B

)

,

a

,

b

)

while the

projections

are straightforward applications

𝗉𝗋

1

⁢

(

p

)

:

≡

p

(

0

𝟐

)

,

𝗉𝗋

2

⁢

(

p

)

:

≡

p

(

1

𝟐

)

.

The

derivation

of the induction principle for binary products defined in this way is a bit more involved, and requires function extensionality, which we will introduce in §2.9 (

http://planetmath.org/29pitypesandthefunctionextensionalityaxiom

).
Moreover, we do not get the same judgmental equalities; see

http://planetmath.org/node/87559

Exercise 1.6.
This is a recurrent issue when encoding one type as another; we will return to it in §5.5 (

http://planetmath.org/55homotopyinductivetypes

).

We may occasionally refer to the elements

0

𝟐

and

1

𝟐

of

𝟐

as “false” and “true” respectively.
However, note that unlike in classical mathematics, we do not use elements of

𝟐

as truth values
or as

propositions

.
(Instead we identify propositions with types; see §1.11 (

http://planetmath.org/111propositionsastypes

).)
In particular, the type

A

→

𝟐

is not generally the

power set

of

A

; it

represents

only the “

decidable

” subsets of

A

(see

http://planetmath.org/node/87576

Chapter 3).

Title

1.8 The type of booleans

\metatable

Generated on Thu Feb 8 19:32:42 2018 by

LaTeXML