web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/sli… · defining...

216
Functions

Upload: others

Post on 20-Sep-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Functions

Page 2: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

A function is a means of associating each object in one set with an object in some other set.

Page 3: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element
Page 4: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Dikdik NubianIbex Sloth

Page 5: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Dikdik NubianIbex Sloth

Page 6: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element
Page 7: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element
Page 8: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element
Page 9: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element
Page 10: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Black and White

Page 11: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Black and White

Page 12: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Terminology

● A function f is a mapping such that every value in A is associated with a unique value in B.● For every a ∈ A, there exists some b ∈ B with f(a) = b.

● If f(a) = b0 and f(a) = b

1, then b

0 = b

1.

● If f is a function from A to B, we sometimes say that f is a mapping from A to B.● We call A the domain of f.● We call B the codomain of f.

● We denote that f is a function from A to B by writing

f : A → B

Page 13: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Is this a function?

Page 14: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Is this a function?

Page 15: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Is this a function?

Page 16: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Is this a function?

Each object in the domain has to be associated with exactly one object in the codomain!

Page 17: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Black and White

Is this a function?

Page 18: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Black and White

Is this a function?

Every element of the domain must be associated with an element of the

codomain!

Page 19: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Black and White

Is this a function?

Every element of the domain must be associated with an element of the

codomain!

Page 20: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Is this a function?

Page 21: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Is this a function?

Love-a-Lot

Tenderheart

Wish

Funshine

Friend

Page 22: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Is this a function?

Love-a-Lot

Tenderheart

Wish

Funshine

Friend

Page 23: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Is this a function?

Love-a-Lot

Tenderheart

Wish

Funshine

Friend

It's fine that nothing is associated with Friend; functions do not need to use the entire codomain.

Page 24: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Defining Functions

● Typically, we specify a function by describing a rule that maps every element of the domain to some element of the codomain.

● Examples:● f(n) = n + 1, where f : → ℤ ℤ● f(x) = sin x, where f : → ℝ ℝ● f(x) = ⌈x , where ⌉ f : → ℝ ℤ

● When defining a function it is always a good idea to verify that● The function is uniquely defined for all elements in the

domain, and● The function's output is always in the codomain.

Page 25: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Defining Functions

Typically, we specify a function by describing a rule that maps every element of the domain to some element of the codomain.

Examples:

f(n) = n + 1, where f : → ℤ ℤ

f(x) = sin x, where f : → ℝ ℝ● f(x) = ⌈x , where ⌉ f : → ℝ ℤ

When defining a function it is always a good idea to verify that

The function is uniquely defined for all elements in the domain, and

The function's output is always in the codomain.

This is the ceiling function – the smallest integer greater than or equal to x. For

example, 1 = 1, 1.37 = 2, ⌈ ⌉ ⌈ ⌉

and = 4.⌈π⌉

This is the ceiling function – the smallest integer greater than or equal to x. For

example, 1 = 1, 1.37 = 2, ⌈ ⌉ ⌈ ⌉

and = 4.⌈π⌉

Page 26: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Defining Functions

● Typically, we specify a function by describing a rule that maps every element of the domain to some element of the codomain.

● Examples:● f(n) = n + 1, where f : → ℤ ℤ● f(x) = sin x, where f : → ℝ ℝ● f(x) = ⌈x , where ⌉ f : → ℝ ℤ

● When defining a function it is always a good idea to verify that● The function is uniquely defined for all elements in the

domain, and● The function's output is always in the codomain.

Page 27: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Piecewise Functions

● Some functions may be specified piecewise, with different rules applying to different elements.

● Example:

● Again, the burden is on you to ensure that this is a function!

f (n)={ −n/2 if n is even(n+1)/2 otherwise

Page 28: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element
Page 29: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Classical

Country

R&B

Rock

Jazz

Page 30: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Classical

Country

R&B

Rock

Jazz

Page 31: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Classical

Country

R&B

Rock

Jazz

Page 32: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Classical

Country

R&B

Rock

Jazz

Page 33: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Classical

Country

R&B

Rock

Jazz

Page 34: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Classical

Country

R&B

Rock

Jazz

The image of a function f : A → B is the setf [A] = { y | there is some x ∈ A where f(x) = y }

Page 35: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Classical

Country

R&B

Rock

Jazz

Page 36: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Classical

Country

R&B

Rock

Jazz

Page 37: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Classical

Country

R&B

Rock

Jazz

Page 38: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Classical

Country

R&B

Rock

Jazz

The image of a set X ⊆ A under f : A → B is the setf [X] = { y | there is some x ∈ X where f(x) = y }

Page 39: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Classical

Country

R&B

Rock

Jazz

Page 40: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Classical

Country

R&B

Rock

Jazz

Page 41: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Classical

Country

R&B

Rock

Jazz

Page 42: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Classical

Country

R&B

Rock

Jazz

The preimage of a set Y ⊆ B under f : A → B is the setf -1[Y] = { x | f(x) ∈ Y }

Page 43: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Classical

Country

R&B

Rock

Jazz

Page 44: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Classical

Country

R&B

Rock

Jazz

The preimage of a set may be empty.

Page 45: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Images and Preimages

● Let f : A → B.● The image of a set X ⊆ A is the set

f [X] = { y | there is an x ∈ X such that f(x) = y }● The preimage of a set Y B is the set⊆

f -1 [Y] = { x | f(x) ∈ Y }● The term range is sometimes used to refer to

the image of A, though sometimes range refers to the entire codomain.

Page 46: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

♀☿

♂♃♄♅♆

Page 47: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

♀☿

♂♃♄♅♆

Page 48: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Mercury

Venus

Earth

Mars

Jupiter

Saturn

Uranus

Neptune

Pluto

♀☿

♂♃♄♅♆

Page 49: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Mercury

Venus

Earth

Mars

Jupiter

Saturn

Uranus

Neptune

Pluto

♀☿

♂♃♄♅♆

Page 50: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Mercury

Venus

Earth

Mars

Jupiter

Saturn

Uranus

Neptune

♀☿

♂♃♄♅♆

Page 51: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Mercury

Venus

Earth

Mars

Jupiter

Saturn

Uranus

Neptune

♀☿

♂♃♄♅♆

Page 52: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Injective Functions

● A function f : A → B is called injective (or one-to-one) if each element of the codomain has at most one element of the domain associated with it.● A function with this property is called an injection.

● An intuition: injective functions label the objects from A using names from B.

Page 53: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: The function f : → defined by ℕ ℤ f(n) = n is injective.

Proof: First, we need to show that f is a legal function from to .ℕ ℤ Note that since , for any ℕ⊆ ℤ n , we ∈ℕknow that n as well. Thus ∈ℤ f(n) for all ∈ℤ n .∈ℕ

Now, we need to show that for any x , that if ∈ℤ f(n0) = x

and f(n1) = x, then n

0 = n

1. Since f(n

0) = n

0 = x and

f(n1) = n

1 = x, this means that n

0 = n

1 as required.

Thus f is a function from to , and it is injective. ■ℕ ℤ

Page 54: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: The function f : → defined by ℕ ℤ f(n) = n is injective.

Proof: First, we need to show that f is a legal function from to . ℕ ℤ Note that since , for any ℕ⊆ ℤ n , we ∈ℕknow that n as well. Thus ∈ℤ f(n) for all ∈ℤ n .∈ℕ

Now, we need to show that for any x , that if ∈ℤ f(n0) = x

and f(n1) = x, then n

0 = n

1. Since f(n

0) = n

0 = x and

f(n1) = n

1 = x, this means that n

0 = n

1 as required.

Thus f is a function from to , and it is injective. ■ℕ ℤ

Page 55: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: The function f : → defined by ℕ ℤ f(n) = n is injective.

Proof: First, we need to show that f is a legal function from to . Note that since , for any ℕ ℤ ℕ ⊆ ℤ n , we ∈ℕknow that n as well. ∈ℤ Thus f(n) for all ∈ℤ n .∈ℕ

Now, we need to show that for any x , that if ∈ℤ f(n0) = x

and f(n1) = x, then n

0 = n

1. Since f(n

0) = n

0 = x and

f(n1) = n

1 = x, this means that n

0 = n

1 as required.

Thus f is a function from to , and it is injective. ■ℕ ℤ

Page 56: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: The function f : → defined by ℕ ℤ f(n) = n is injective.

Proof: First, we need to show that f is a legal function from to . Note that since , for any ℕ ℤ ℕ ⊆ ℤ n , we ∈ℕknow that n as well. Thus ∈ℤ f(n) for all ∈ℤ n .∈ℕ

Now, we need to show that for any x , that if ∈ℤ f(n0) = x

and f(n1) = x, then n

0 = n

1. Since f(n

0) = n

0 = x and

f(n1) = n

1 = x, this means that n

0 = n

1 as required.

Thus f is a function from to , and it is injective. ■ℕ ℤ

Page 57: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: The function f : → defined by ℕ ℤ f(n) = n is injective.

Proof: First, we need to show that f is a legal function from to . Note that since , for any ℕ ℤ ℕ ⊆ ℤ n , we ∈ℕknow that n as well. Thus ∈ℤ f(n) for all ∈ℤ n .∈ℕ

Now, we need to show that for any x , that if ∈ℤ f(n0) = x

and f(n1) = x, then n

0 = n

1. Since f(n

0) = n

0 = x and

f(n1) = n

1 = x, this means that n

0 = n

1 as required.

Thus f is a function from to , and it is injective. ■ℕ ℤ

We've completely glossed over the detail of showing that f(n) = n is defined for every

n . In general, unless there's a ∈ ℕ

reason to think otherwise, you don't need to justify why the function is defined for all elements of the domain. However, it's a good idea to show that the function does

indeed map into the codomain!

We've completely glossed over the detail of showing that f(n) = n is defined for every

n . In general, unless there's a ∈ ℕ

reason to think otherwise, you don't need to justify why the function is defined for all elements of the domain. However, it's a good idea to show that the function does

indeed map into the codomain!

Page 58: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: The function f : → defined by ℕ ℤ f(n) = n is injective.

Proof: First, we need to show that f is a legal function from to . Note that since , for any ℕ ℤ ℕ ⊆ ℤ n , we ∈ℕknow that n as well. Thus ∈ℤ f(n) for all ∈ℤ n .∈ℕ

Now, we need to show that for any x , that if ∈ℤ f(n0) = x

and f(n1) = x, then n

0 = n

1. Since f(n

0) = n

0 = x and

f(n1) = n

1 = x, this means that n

0 = n

1 as required.

Thus f is a function from to , and it is injective. ■ℕ ℤ

Page 59: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: The function f : → defined by ℕ ℤ f(n) = n is injective.

Proof: First, we need to show that f is a legal function from to . Note that since , for any ℕ ℤ ℕ ⊆ ℤ n , we ∈ℕknow that n as well. Thus ∈ℤ f(n) for all ∈ℤ n .∈ℕ

Now, we need to show that for any x , that if ∈ℤ f(n0) = x

and f(n1) = x, then n

0 = n

1. Since f(n

0) = n

0 = x and

f(n1) = n

1 = x, this means that n

0 = n

1 as required.

Thus f is a function from to , and it is injective. ■ℕ ℤ

Page 60: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: The function f : → defined by ℕ ℤ f(n) = n is injective.

Proof: First, we need to show that f is a legal function from to . Note that since , for any ℕ ℤ ℕ ⊆ ℤ n , we ∈ℕknow that n as well. Thus ∈ℤ f(n) for all ∈ℤ n .∈ℕ

Now, we need to show that for any x , that if ∈ℤ f(n0) = x

and f(n1) = x, then n

0 = n

1. Since f(n

0) = n

0 = x and

f(n1) = n

1 = x, this means that n

0 = n

1 as required.

Thus f is a function from to , and it is injective. ℕ ℤ ■

Page 61: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: The function f : → defined by ℕ ℤ f(n) = n is injective.

Proof: First, we need to show that f is a legal function from to . Note that since , for any ℕ ℤ ℕ ⊆ ℤ n , we ∈ℕknow that n as well. Thus ∈ℤ f(n) for all ∈ℤ n .∈ℕ

Now, we need to show that for any x , that if ∈ℤ f(n0) = x

and f(n1) = x, then n

0 = n

1. Since f(n

0) = n

0 = x and

f(n1) = n

1 = x, this means that n

0 = n

1 as required.

Thus f is a function from to , and it is injective. ■ℕ ℤ

Page 62: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element
Page 63: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element
Page 64: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Front Door

BalconyWindow

BedroomWindow

Page 65: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Front Door

BalconyWindow

BedroomWindow

Page 66: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Surjective Functions

● A function f : A → B is called surjective (or onto) if each element of the codomain has at least one element of the domain associated with it.● A function with this property is called a surjection.

● An intuition: surjective functions cover every element of B with at least one element of A.

Page 67: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: The function f : → defined by ℤ ℕ f(x) = |x| is surjective.

Proof: First, we need to show that f is a function from to ℤ. Consider any x . If ℕ ∈ ℤ x ≥ 0, then |x| = x, and since x

is a nonnegative integer, f(x) = |x| = x . If ∈ℕ x < 0, then|x| = -x, so |x| is a positive integer, and thereforef(x) = |x| = -x . Thus ∈ℕ f is a function from to .ℤ ℕ

We need to show that for any n , that there is some∈ℕx such that ∈ℤ f(x) = n. Given any n, take x = n. Since x = n and n , this means that ∈ℕ x . Then∈ℤf(x) = |x| = |n|. Since n , ∈ℕ n ≥ 0, so |n| = n. Thusf(x) = n as required. ■

Page 68: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Recap

● An injective function associates at most one element of the domain with each element of the codomain.

● A surjective function associates at least one element of the domain with each element of the codomain.

● What about functions that associate exactly one element of the domain with each element of the codomain?

Page 69: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element
Page 70: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element
Page 71: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

LOL

AWWWWWWYEAAAAHHH

Problem?

Page 72: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

LOL

AWWWWWWYEAAAAHHH

Problem?

Page 73: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Bijections

● A function that associates each element of the codomain with a unique element of the domain is called bijective.● Such a function is a bijection.

● Formally, a bijection is a function that is both injective and surjective.

● A bijection is a one-to-one correspondence between two sets.

Page 74: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Compositions

Page 75: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

www.microsoft.com www.apple.com www.google.com

Page 76: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

www.microsoft.com www.apple.com www.google.com

Page 77: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

www.microsoft.com www.apple.com www.google.com

Page 78: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

www.microsoft.com www.apple.com www.google.com

Page 79: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

www.microsoft.com www.apple.com www.google.com

Page 80: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

www.microsoft.com www.apple.com www.google.com

Page 81: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

www.microsoft.com www.apple.com www.google.com

Page 82: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Function Composition

● Let f : A → B and g : B → C● The function g ∘ f : A → C is defined as

(g ∘ f)(x) = g(f(x))● Note that f is applied first, but f is on the right

side!● Function composition is associative:

h (∘ g ∘ f) = (h ∘ g) ∘ f

Page 83: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Function Composition

● Suppose f : A → A and g : A → A.● Then both g ∘ f and f ∘ g are defined.● Does g ∘ f = f ∘ g?● In general, no:

● Let f(x) = 2x● Let g(x) = x + 1● (g ∘ f)(x) = g(f(x)) = g(2x) = 2x + 1● (f ∘ g)(x) = f(g(x)) = f(x + 1) = 2x + 2

Page 84: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Functions and Sets

Page 85: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Cardinality

● Recall (from lecture one!) that the cardinality of a set is the number of elements it contains.● Denoted |S|.

● For finite sets, cardinalities are natural numbers:● |{1, 2, 3}| = 3● |{100, 200, 300}| = 3

● For infinite sets, we introduce infinite cardinals to denote the size of sets:● | | = ℕ ℵ

0

Page 86: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Comparing Cardinalities

● The relationships between set cardinalities are defined in terms of functions between those sets.

● |S| = |T| is defined using bijections.

|S| = |T| iff there is a bijection f : S → T● We define |S| ≤ |T| as follows:

|S| ≤ |T| iff there is an injection f : S → T● Be careful – despite the use of the notation = and ≤, to

rigorously reason about cardinalities, your proof must rely on appropriate definitions of functions.

Page 87: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If |R| = |S| and |S| = |T|, then |R| = |T|.

Proof: We will exhibit a bijection f : R → T. Since |R| = |S|, there is a bijection g : R → S. Since |S| = |T|, there is a bijection h : S → T. Let f = h ∘ g; this means that f : R → T. We prove that f is a bijection by showing that it is injective and surjective.

To see that f is injective, suppose that f(r0) = f(r

1). We will show that r

0 = r

1.

Since f(r0) = t and f(r

1) = t, we know (h ∘ g)(r

0) = t and (h ∘ g)(r

1) = t. By

definition of composition, we have h(g(r0)) = h(g(r

1)). Since h is a bijection, h

is injective, so we have that g(r0) = g(r

1). Since g is a bijection, g is injective,

so we have that r0 = r

1. Therefore, f is injective.

To see that f is surjective, consider any t ∈T. We will show that there is some r ∈ R such that f(r) = t. Since h is a bijection from S to T, h is surjective, so there is some s ∈ S such that h(s) = t. Since g is a bijection from R to S, g is surjective, so there is some r ∈ R such that g(r) = t. Thus f(r) = (h ∘ g)(r) = h(g(r)) = h(s) = t as required, so f is surjective.

Since f is injective and surjective, it is bijective. Thus there is a bijection from R to T, so |R| = |T|. ■

Page 88: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If |R| = |S| and |S| = |T|, then |R| = |T|.

Proof: We will exhibit a bijection f : R → T. Since |R| = |S|, there is a bijection g : R → S. Since |S| = |T|, there is a bijection h : S → T. Let f = h ∘ g; this means that f : R → T. We prove that f is a bijection by showing that it is injective and surjective.

To see that f is injective, suppose that f(r0) = f(r

1). We will show that r

0 = r

1.

Since f(r0) = t and f(r

1) = t, we know (h ∘ g)(r

0) = t and (h ∘ g)(r

1) = t. By

definition of composition, we have h(g(r0)) = h(g(r

1)). Since h is a bijection, h

is injective, so we have that g(r0) = g(r

1). Since g is a bijection, g is injective,

so we have that r0 = r

1. Therefore, f is injective.

To see that f is surjective, consider any t ∈T. We will show that there is some r ∈ R such that f(r) = t. Since h is a bijection from S to T, h is surjective, so there is some s ∈ S such that h(s) = t. Since g is a bijection from R to S, g is surjective, so there is some r ∈ R such that g(r) = t. Thus f(r) = (h ∘ g)(r) = h(g(r)) = h(s) = t as required, so f is surjective.

Since f is injective and surjective, it is bijective. Thus there is a bijection from R to T, so |R| = |T|. ■

Page 89: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If |R| = |S| and |S| = |T|, then |R| = |T|.

Proof: We will exhibit a bijection f : R → T. Since |R| = |S|, there is a bijection g : R → S. Since |S| = |T|, there is a bijection h : S → T. Let f = h ∘ g; this means that f : R → T. We prove that f is a bijection by showing that it is injective and surjective.

To see that f is injective, suppose that f(r0) = f(r

1). We will show that r

0 = r

1.

Since f(r0) = t and f(r

1) = t, we know (h ∘ g)(r

0) = t and (h ∘ g)(r

1) = t. By

definition of composition, we have h(g(r0)) = h(g(r

1)). Since h is a bijection, h

is injective, so we have that g(r0) = g(r

1). Since g is a bijection, g is injective,

so we have that r0 = r

1. Therefore, f is injective.

To see that f is surjective, consider any t ∈T. We will show that there is some r ∈ R such that f(r) = t. Since h is a bijection from S to T, h is surjective, so there is some s ∈ S such that h(s) = t. Since g is a bijection from R to S, g is surjective, so there is some r ∈ R such that g(r) = t. Thus f(r) = (h ∘ g)(r) = h(g(r)) = h(s) = t as required, so f is surjective.

Since f is injective and surjective, it is bijective. Thus there is a bijection from R to T, so |R| = |T|. ■

Page 90: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If |R| = |S| and |S| = |T|, then |R| = |T|.

Proof: We will exhibit a bijection f : R → T. Since |R| = |S|, there is a bijection g : R → S. Since |S| = |T|, there is a bijection h : S → T. Let f = h ∘ g; this means that f : R → T. We prove that f is a bijection by showing that it is injective and surjective.

To see that f is injective, suppose that f(r0) = f(r

1). We will show that r

0 = r

1.

Since f(r0) = t and f(r

1) = t, we know (h ∘ g)(r

0) = t and (h ∘ g)(r

1) = t. By

definition of composition, we have h(g(r0)) = h(g(r

1)). Since h is a bijection, h

is injective, so we have that g(r0) = g(r

1). Since g is a bijection, g is injective,

so we have that r0 = r

1. Therefore, f is injective.

To see that f is surjective, consider any t ∈T. We will show that there is some r ∈ R such that f(r) = t. Since h is a bijection from S to T, h is surjective, so there is some s ∈ S such that h(s) = t. Since g is a bijection from R to S, g is surjective, so there is some r ∈ R such that g(r) = t. Thus f(r) = (h ∘ g)(r) = h(g(r)) = h(s) = t as required, so f is surjective.

Since f is injective and surjective, it is bijective. Thus there is a bijection from R to T, so |R| = |T|. ■

Page 91: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If |R| = |S| and |S| = |T|, then |R| = |T|.

Proof: We will exhibit a bijection f : R → T. Since |R| = |S|, there is a bijection g : R → S. Since |S| = |T|, there is a bijection h : S → T. Let f = h ∘ g; this means that f : R → T. We prove that f is a bijection by showing that it is injective and surjective.

To see that f is injective, suppose that f(r0) = f(r

1). We will show that r

0 = r

1.

Since f(r0) = t and f(r

1) = t, we know (h ∘ g)(r

0) = t and (h ∘ g)(r

1) = t. By

definition of composition, we have h(g(r0)) = h(g(r

1)). Since h is a bijection, h

is injective, so we have that g(r0) = g(r

1). Since g is a bijection, g is injective,

so we have that r0 = r

1. Therefore, f is injective.

To see that f is surjective, consider any t ∈T. We will show that there is some r ∈ R such that f(r) = t. Since h is a bijection from S to T, h is surjective, so there is some s ∈ S such that h(s) = t. Since g is a bijection from R to S, g is surjective, so there is some r ∈ R such that g(r) = t. Thus f(r) = (h ∘ g)(r) = h(g(r)) = h(s) = t as required, so f is surjective.

Since f is injective and surjective, it is bijective. Thus there is a bijection from R to T, so |R| = |T|. ■

Page 92: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If |R| = |S| and |S| = |T|, then |R| = |T|.

Proof: We will exhibit a bijection f : R → T. Since |R| = |S|, there is a bijection g : R → S. Since |S| = |T|, there is a bijection h : S → T. Let f = h ∘ g; this means that f : R → T. We prove that f is a bijection by showing that it is injective and surjective.

To see that f is injective, suppose that f(r0) = f(r

1). We will show that r

0 = r

1.

Since f(r0) = t and f(r

1) = t, we know (h ∘ g)(r

0) = t and (h ∘ g)(r

1) = t. By

definition of composition, we have h(g(r0)) = h(g(r

1)). Since h is a bijection, h

is injective, so we have that g(r0) = g(r

1). Since g is a bijection, g is injective,

so we have that r0 = r

1. Therefore, f is injective.

To see that f is surjective, consider any t ∈T. We will show that there is some r ∈ R such that f(r) = t. Since h is a bijection from S to T, h is surjective, so there is some s ∈ S such that h(s) = t. Since g is a bijection from R to S, g is surjective, so there is some r ∈ R such that g(r) = t. Thus f(r) = (h ∘ g)(r) = h(g(r)) = h(s) = t as required, so f is surjective.

Since f is injective and surjective, it is bijective. Thus there is a bijection from R to T, so |R| = |T|. ■

Page 93: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If |R| = |S| and |S| = |T|, then |R| = |T|.

Proof: We will exhibit a bijection f : R → T. Since |R| = |S|, there is a bijection g : R → S. Since |S| = |T|, there is a bijection h : S → T. Let f = h ∘ g; this means that f : R → T. We prove that f is a bijection by showing that it is injective and surjective.

To see that f is injective, suppose that f(r0) = f(r

1). We will show that r

0 = r

1.

Since f(r0) = t and f(r

1) = t, we know (h ∘ g)(r

0) = t and (h ∘ g)(r

1) = t. By

definition of composition, we have h(g(r0)) = h(g(r

1)). Since h is a bijection, h

is injective, so we have that g(r0) = g(r

1). Since g is a bijection, g is injective,

so we have that r0 = r

1. Therefore, f is injective.

To see that f is surjective, consider any t ∈T. We will show that there is some r ∈ R such that f(r) = t. Since h is a bijection from S to T, h is surjective, so there is some s ∈ S such that h(s) = t. Since g is a bijection from R to S, g is surjective, so there is some r ∈ R such that g(r) = t. Thus f(r) = (h ∘ g)(r) = h(g(r)) = h(s) = t as required, so f is surjective.

Since f is injective and surjective, it is bijective. Thus there is a bijection from R to T, so |R| = |T|. ■

Page 94: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If |R| = |S| and |S| = |T|, then |R| = |T|.

Proof: We will exhibit a bijection f : R → T. Since |R| = |S|, there is a bijection g : R → S. Since |S| = |T|, there is a bijection h : S → T. Let f = h ∘ g; this means that f : R → T. We prove that f is a bijection by showing that it is injective and surjective.

To see that f is injective, suppose that f(r0) = f(r

1). We will show that r

0 = r

1.

Since f(r0) = t and f(r

1) = t, we know (h ∘ g)(r

0) = t and (h ∘ g)(r

1) = t. By

definition of composition, we have h(g(r0)) = h(g(r

1)). Since h is a bijection, h

is injective, so we have that g(r0) = g(r

1). Since g is a bijection, g is injective,

so we have that r0 = r

1. Therefore, f is injective.

To see that f is surjective, consider any t ∈T. We will show that there is some r ∈ R such that f(r) = t. Since h is a bijection from S to T, h is surjective, so there is some s ∈ S such that h(s) = t. Since g is a bijection from R to S, g is surjective, so there is some r ∈ R such that g(r) = t. Thus f(r) = (h ∘ g)(r) = h(g(r)) = h(s) = t as required, so f is surjective.

Since f is injective and surjective, it is bijective. Thus there is a bijection from R to T, so |R| = |T|. ■

Page 95: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If |R| = |S| and |S| = |T|, then |R| = |T|.

Proof: We will exhibit a bijection f : R → T. Since |R| = |S|, there is a bijection g : R → S. Since |S| = |T|, there is a bijection h : S → T. Let f = h ∘ g; this means that f : R → T. We prove that f is a bijection by showing that it is injective and surjective.

To see that f is injective, suppose that f(r0) = f(r

1). We will show that r

0 = r

1.

Since f(r0) = t and f(r

1) = t, we know (h ∘ g)(r

0) = t and (h ∘ g)(r

1) = t. By

definition of composition, we have h(g(r0)) = h(g(r

1)). Since h is a bijection, h

is injective, so we have that g(r0) = g(r

1). Since g is a bijection, g is injective,

so we have that r0 = r

1. Therefore, f is injective.

To see that f is surjective, consider any t ∈T. We will show that there is some r ∈ R such that f(r) = t. Since h is a bijection from S to T, h is surjective, so there is some s ∈ S such that h(s) = t. Since g is a bijection from R to S, g is surjective, so there is some r ∈ R such that g(r) = t. Thus f(r) = (h ∘ g)(r) = h(g(r)) = h(s) = t as required, so f is surjective.

Since f is injective and surjective, it is bijective. Thus there is a bijection from R to T, so |R| = |T|. ■

Page 96: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If |R| = |S| and |S| = |T|, then |R| = |T|.

Proof: We will exhibit a bijection f : R → T. Since |R| = |S|, there is a bijection g : R → S. Since |S| = |T|, there is a bijection h : S → T. Let f = h ∘ g; this means that f : R → T. We prove that f is a bijection by showing that it is injective and surjective.

To see that f is injective, suppose that f(r0) = f(r

1). We will show that r

0 = r

1.

Since f(r0) = t and f(r

1) = t, we know (h ∘ g)(r

0) = t and (h ∘ g)(r

1) = t. By

definition of composition, we have h(g(r0)) = h(g(r

1)). Since h is a bijection, h

is injective, so we have that g(r0) = g(r

1). Since g is a bijection, g is injective,

so we have that r0 = r

1. Therefore, f is injective.

To see that f is surjective, consider any t ∈T. We will show that there is some r ∈ R such that f(r) = t. Since h is a bijection from S to T, h is surjective, so there is some s ∈ S such that h(s) = t. Since g is a bijection from R to S, g is surjective, so there is some r ∈ R such that g(r) = t. Thus f(r) = (h ∘ g)(r) = h(g(r)) = h(s) = t as required, so f is surjective.

Since f is injective and surjective, it is bijective. Thus there is a bijection from R to T, so |R| = |T|. ■

Page 97: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If |R| = |S| and |S| = |T|, then |R| = |T|.

Proof: We will exhibit a bijection f : R → T. Since |R| = |S|, there is a bijection g : R → S. Since |S| = |T|, there is a bijection h : S → T. Let f = h ∘ g; this means that f : R → T. We prove that f is a bijection by showing that it is injective and surjective.

To see that f is injective, suppose that f(r0) = f(r

1). We will show that r

0 = r

1.

Since f(r0) = t and f(r

1) = t, we know (h ∘ g)(r

0) = t and (h ∘ g)(r

1) = t. By

definition of composition, we have h(g(r0)) = h(g(r

1)). Since h is a bijection, h

is injective, so we have that g(r0) = g(r

1). Since g is a bijection, g is injective,

so we have that r0 = r

1. Therefore, f is injective.

To see that f is surjective, consider any t ∈T. We will show that there is some r ∈ R such that f(r) = t. Since h is a bijection from S to T, h is surjective, so there is some s ∈ S such that h(s) = t. Since g is a bijection from R to S, g is surjective, so there is some r ∈ R such that g(r) = t. Thus f(r) = (h ∘ g)(r) = h(g(r)) = h(s) = t as required, so f is surjective.

Since f is injective and surjective, it is bijective. Thus there is a bijection from R to T, so |R| = |T|. ■

Page 98: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If |R| = |S| and |S| = |T|, then |R| = |T|.

Proof: We will exhibit a bijection f : R → T. Since |R| = |S|, there is a bijection g : R → S. Since |S| = |T|, there is a bijection h : S → T. Let f = h ∘ g; this means that f : R → T. We prove that f is a bijection by showing that it is injective and surjective.

To see that f is injective, suppose that f(r0) = f(r

1). We will show that r

0 = r

1.

Since f(r0) = t and f(r

1) = t, we know (h ∘ g)(r

0) = t and (h ∘ g)(r

1) = t. By

definition of composition, we have h(g(r0)) = h(g(r

1)). Since h is a bijection, h

is injective, so we have that g(r0) = g(r

1). Since g is a bijection, g is injective,

so we have that r0 = r

1. Therefore, f is injective.

To see that f is surjective, consider any t ∈T. We will show that there is some r ∈ R such that f(r) = t. Since h is a bijection from S to T, h is surjective, so there is some s ∈ S such that h(s) = t. Since g is a bijection from R to S, g is surjective, so there is some r ∈ R such that g(r) = t. Thus f(r) = (h ∘ g)(r) = h(g(r)) = h(s) = t as required, so f is surjective.

Since f is injective and surjective, it is bijective. Thus there is a bijection from R to T, so |R| = |T|. ■

Page 99: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If |R| = |S| and |S| = |T|, then |R| = |T|.

Proof: We will exhibit a bijection f : R → T. Since |R| = |S|, there is a bijection g : R → S. Since |S| = |T|, there is a bijection h : S → T. Let f = h ∘ g; this means that f : R → T. We prove that f is a bijection by showing that it is injective and surjective.

To see that f is injective, suppose that f(r0) = f(r

1). We will show that r

0 = r

1.

Since f(r0) = t and f(r

1) = t, we know (h ∘ g)(r

0) = t and (h ∘ g)(r

1) = t. By

definition of composition, we have h(g(r0)) = h(g(r

1)). Since h is a bijection, h

is injective, so we have that g(r0) = g(r

1). Since g is a bijection, g is injective,

so we have that r0 = r

1. Therefore, f is injective.

To see that f is surjective, consider any t ∈T. We will show that there is some r ∈ R such that f(r) = t. Since h is a bijection from S to T, h is surjective, so there is some s ∈ S such that h(s) = t. Since g is a bijection from R to S, g is surjective, so there is some r ∈ R such that g(r) = t. Thus f(r) = (h ∘ g)(r) = h(g(r)) = h(s) = t as required, so f is surjective.

Since f is injective and surjective, it is bijective. Thus there is a bijection from R to T, so |R| = |T|. ■

Page 100: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If |R| = |S| and |S| = |T|, then |R| = |T|.

Proof: We will exhibit a bijection f : R → T. Since |R| = |S|, there is a bijection g : R → S. Since |S| = |T|, there is a bijection h : S → T. Let f = h ∘ g; this means that f : R → T. We prove that f is a bijection by showing that it is injective and surjective.

To see that f is injective, suppose that f(r0) = f(r

1). We will show that r

0 = r

1.

Since f(r0) = t and f(r

1) = t, we know (h ∘ g)(r

0) = t and (h ∘ g)(r

1) = t. By

definition of composition, we have h(g(r0)) = h(g(r

1)). Since h is a bijection, h

is injective, so we have that g(r0) = g(r

1). Since g is a bijection, g is injective,

so we have that r0 = r

1. Therefore, f is injective.

To see that f is surjective, consider any t ∈T. We will show that there is some r ∈ R such that f(r) = t. Since h is a bijection from S to T, h is surjective, so there is some s ∈ S such that h(s) = t. Since g is a bijection from R to S, g is surjective, so there is some r ∈ R such that g(r) = t. Thus f(r) = (h ∘ g)(r) = h(g(r)) = h(s) = t as required, so f is surjective.

Since f is injective and surjective, it is bijective. Thus there is a bijection from R to T, so |R| = |T|. ■

Page 101: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If |R| = |S| and |S| = |T|, then |R| = |T|.

Proof: We will exhibit a bijection f : R → T. Since |R| = |S|, there is a bijection g : R → S. Since |S| = |T|, there is a bijection h : S → T. Let f = h ∘ g; this means that f : R → T. We prove that f is a bijection by showing that it is injective and surjective.

To see that f is injective, suppose that f(r0) = f(r

1). We will show that r

0 = r

1.

Since f(r0) = t and f(r

1) = t, we know (h ∘ g)(r

0) = t and (h ∘ g)(r

1) = t. By

definition of composition, we have h(g(r0)) = h(g(r

1)). Since h is a bijection, h

is injective, so we have that g(r0) = g(r

1). Since g is a bijection, g is injective,

so we have that r0 = r

1. Therefore, f is injective.

To see that f is surjective, consider any t ∈T. We will show that there is some r ∈ R such that f(r) = t. Since h is a bijection from S to T, h is surjective, so there is some s ∈ S such that h(s) = t. Since g is a bijection from R to S, g is surjective, so there is some r ∈ R such that g(r) = t. Thus f(r) = (h ∘ g)(r) = h(g(r)) = h(s) = t as required, so f is surjective.

Since f is injective and surjective, it is bijective. Thus there is a bijection from R to T, so |R| = |T|. ■

Page 102: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If |R| = |S| and |S| = |T|, then |R| = |T|.

Proof: We will exhibit a bijection f : R → T. Since |R| = |S|, there is a bijection g : R → S. Since |S| = |T|, there is a bijection h : S → T. Let f = h ∘ g; this means that f : R → T. We prove that f is a bijection by showing that it is injective and surjective.

To see that f is injective, suppose that f(r0) = f(r

1). We will show that r

0 = r

1.

Since f(r0) = t and f(r

1) = t, we know (h ∘ g)(r

0) = t and (h ∘ g)(r

1) = t. By

definition of composition, we have h(g(r0)) = h(g(r

1)). Since h is a bijection, h

is injective, so we have that g(r0) = g(r

1). Since g is a bijection, g is injective,

so we have that r0 = r

1. Therefore, f is injective.

To see that f is surjective, consider any t ∈T. We will show that there is some r ∈ R such that f(r) = t. Since h is a bijection from S to T, h is surjective, so there is some s ∈ S such that h(s) = t. Since g is a bijection from R to S, g is surjective, so there is some r ∈ R such that g(r) = t. Thus f(r) = (h ∘ g)(r) = h(g(r)) = h(s) = t as required, so f is surjective.

Since f is injective and surjective, it is bijective. Thus there is a bijection from R to T, so |R| = |T|. ■

Page 103: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If |R| = |S| and |S| = |T|, then |R| = |T|.

Proof: We will exhibit a bijection f : R → T. Since |R| = |S|, there is a bijection g : R → S. Since |S| = |T|, there is a bijection h : S → T. Let f = h ∘ g; this means that f : R → T. We prove that f is a bijection by showing that it is injective and surjective.

To see that f is injective, suppose that f(r0) = f(r

1). We will show that r

0 = r

1.

Since f(r0) = t and f(r

1) = t, we know (h ∘ g)(r

0) = t and (h ∘ g)(r

1) = t. By

definition of composition, we have h(g(r0)) = h(g(r

1)). Since h is a bijection, h

is injective, so we have that g(r0) = g(r

1). Since g is a bijection, g is injective,

so we have that r0 = r

1. Therefore, f is injective.

To see that f is surjective, consider any t ∈T. We will show that there is some r ∈ R such that f(r) = t. Since h is a bijection from S to T, h is surjective, so there is some s ∈ S such that h(s) = t. Since g is a bijection from R to S, g is surjective, so there is some r ∈ R such that g(r) = s. Thus f(r) = (h ∘ g)(r) = h(g(r)) = h(s) = t as required, so f is surjective.

Since f is injective and surjective, it is bijective. Thus there is a bijection from R to T, so |R| = |T|. ■

Page 104: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If |R| = |S| and |S| = |T|, then |R| = |T|.

Proof: We will exhibit a bijection f : R → T. Since |R| = |S|, there is a bijection g : R → S. Since |S| = |T|, there is a bijection h : S → T. Let f = h ∘ g; this means that f : R → T. We prove that f is a bijection by showing that it is injective and surjective.

To see that f is injective, suppose that f(r0) = f(r

1). We will show that r

0 = r

1.

Since f(r0) = t and f(r

1) = t, we know (h ∘ g)(r

0) = t and (h ∘ g)(r

1) = t. By

definition of composition, we have h(g(r0)) = h(g(r

1)). Since h is a bijection, h

is injective, so we have that g(r0) = g(r

1). Since g is a bijection, g is injective,

so we have that r0 = r

1. Therefore, f is injective.

To see that f is surjective, consider any t ∈T. We will show that there is some r ∈ R such that f(r) = t. Since h is a bijection from S to T, h is surjective, so there is some s ∈ S such that h(s) = t. Since g is a bijection from R to S, g is surjective, so there is some r ∈ R such that g(r) = s. Thus f(r) = (h ∘ g)(r) = h(g(r)) = h(s) = t as required, so f is surjective.

Since f is injective and surjective, it is bijective. Thus there is a bijection from R to T, so |R| = |T|. ■

Page 105: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If |R| = |S| and |S| = |T|, then |R| = |T|.

Proof: We will exhibit a bijection f : R → T. Since |R| = |S|, there is a bijection g : R → S. Since |S| = |T|, there is a bijection h : S → T. Let f = h ∘ g; this means that f : R → T. We prove that f is a bijection by showing that it is injective and surjective.

To see that f is injective, suppose that f(r0) = f(r

1). We will show that r

0 = r

1.

Since f(r0) = t and f(r

1) = t, we know (h ∘ g)(r

0) = t and (h ∘ g)(r

1) = t. By

definition of composition, we have h(g(r0)) = h(g(r

1)). Since h is a bijection, h

is injective, so we have that g(r0) = g(r

1). Since g is a bijection, g is injective,

so we have that r0 = r

1. Therefore, f is injective.

To see that f is surjective, consider any t ∈T. We will show that there is some r ∈ R such that f(r) = t. Since h is a bijection from S to T, h is surjective, so there is some s ∈ S such that h(s) = t. Since g is a bijection from R to S, g is surjective, so there is some r ∈ R such that g(r) = s. Thus f(r) = (h ∘ g)(r) = h(g(r)) = h(s) = t as required, so f is surjective.

Since f is injective and surjective, it is bijective. Thus there is a bijection from R to T, so |R| = |T|. ■

Page 106: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If |R| = |S| and |S| = |T|, then |R| = |T|.

Proof: We will exhibit a bijection f : R → T. Since |R| = |S|, there is a bijection g : R → S. Since |S| = |T|, there is a bijection h : S → T. Let f = h ∘ g; this means that f : R → T. We prove that f is a bijection by showing that it is injective and surjective.

To see that f is injective, suppose that f(r0) = f(r

1). We will show that r

0 = r

1.

Since f(r0) = t and f(r

1) = t, we know (h ∘ g)(r

0) = t and (h ∘ g)(r

1) = t. By

definition of composition, we have h(g(r0)) = h(g(r

1)). Since h is a bijection, h

is injective, so we have that g(r0) = g(r

1). Since g is a bijection, g is injective,

so we have that r0 = r

1. Therefore, f is injective.

To see that f is surjective, consider any t ∈T. We will show that there is some r ∈ R such that f(r) = t. Since h is a bijection from S to T, h is surjective, so there is some s ∈ S such that h(s) = t. Since g is a bijection from R to S, g is surjective, so there is some r ∈ R such that g(r) = s. Thus f(r) = (h ∘ g)(r) = h(g(r)) = h(s) = t as required, so f is surjective.

Since f is injective and surjective, it is bijective. Thus there is a bijection from R to T, so |R| = |T|. ■

Page 107: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If |R| = |S| and |S| = |T|, then |R| = |T|.

Proof: We will exhibit a bijection f : R → T. Since |R| = |S|, there is a bijection g : R → S. Since |S| = |T|, there is a bijection h : S → T. Let f = h ∘ g; this means that f : R → T. We prove that f is a bijection by showing that it is injective and surjective.

To see that f is injective, suppose that f(r0) = f(r

1). We will show that r

0 = r

1.

Since f(r0) = t and f(r

1) = t, we know (h ∘ g)(r

0) = t and (h ∘ g)(r

1) = t. By

definition of composition, we have h(g(r0)) = h(g(r

1)). Since h is a bijection, h

is injective, so we have that g(r0) = g(r

1). Since g is a bijection, g is injective,

so we have that r0 = r

1. Therefore, f is injective.

To see that f is surjective, consider any t ∈T. We will show that there is some r ∈ R such that f(r) = t. Since h is a bijection from S to T, h is surjective, so there is some s ∈ S such that h(s) = t. Since g is a bijection from R to S, g is surjective, so there is some r ∈ R such that g(r) = s. Thus f(r) = (h ∘ g)(r) = h(g(r)) = h(s) = t as required, so f is surjective.

Since f is injective and surjective, it is bijective. Thus there is a bijection from R to T, so |R| = |T|. ■

Page 108: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Operations on Cardinality

● Equality of cardinality is an equivalence relation. For any sets R, S, and T:● |S| = |S|. (reflexivity)● If |R| = |S| and |S| = |T|, then |R| = |T|. (transitivity)● If |S| = |T|, then |T| = |S|. (symmetry)

● How would you prove reflexivity?● One option: Set f(x) = x.

● We need to build up a bit more machinery to prove symmetry.

Page 109: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Operations on Cardinality

● The ≤ relation over set cardinalities is a total order. For any sets R, S, and T:● |S| ≤ |S|. (reflexivity)● If |R| ≤ |S| and |S| ≤ |T|, then |R| ≤ |T|. (transitivity)● If |S| ≤ |T| and |T| ≤ |S|, then |S| = |T|. (antisymmetry)● Either |S| ≤ |T| or |T| ≤ |S|. (totality)

● These last two proofs are extremely hard.● The antisymmetry result is the Cantor-Bernstein-Schroeder

Theorem; a fascinating read, but beyond the scope of this course.● The totality result requires the axiom of choice; also interesting but

far beyond the scope of this course.● Take Math 161 for more details.

Page 110: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: Let S = { 2n | n }. Then ∈ℕ |S| = ℵ .₀

Proof: We prove that |S| = | |; since | | = by definition, ℕ ℕ ℵ₀this proves that |S| = .ℵ₀

To show that |S| = | |, we will find a bijection between the two ℕof them. Consider the function f : → ℕ S defined as f(n) = 2n. By the definition of S, for any n , ∈ℕ f(n) = 2n ∈ S, so f is a function from to ℕ S.

To show that f is a bijection, we show that it is injective and surjective. To show that f is injective, consider any m and n where f(m) = f(n); we will prove that m = n. To see this, note that if f(m) = f(n), then 2m = 2n, and so m = n as required. To show that f is surjective, consider any m ∈ S; we show that there is an n such that ∈ℕ f(n) = m. Since m ∈ S, m = 2k for some k . If we take ∈ℕ n = k, then f(n) = 2n = 2k = m, as required. Thus f is injective and surjective, so it is a bijection, and |S| = | | = . ■ℕ ℵ₀

Page 111: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: Let S = { 2n | n }. Then ∈ℕ |S| = ℵ .₀

Proof: We prove that |S| = | |; since | | = by definition, ℕ ℕ ℵ₀this proves that |S| = .ℵ₀

To show that |S| = | |, we will find a bijection between the two ℕof them. Consider the function f : → ℕ S defined as f(n) = 2n. By the definition of S, for any n , ∈ℕ f(n) = 2n ∈ S, so f is a function from to ℕ S.

To show that f is a bijection, we show that it is injective and surjective. To show that f is injective, consider any m and n where f(m) = f(n); we will prove that m = n. To see this, note that if f(m) = f(n), then 2m = 2n, and so m = n as required. To show that f is surjective, consider any m ∈ S; we show that there is an n such that ∈ℕ f(n) = m. Since m ∈ S, m = 2k for some k . If we take ∈ℕ n = k, then f(n) = 2n = 2k = m, as required. Thus f is injective and surjective, so it is a bijection, and |S| = | | = . ■ℕ ℵ₀

Page 112: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: Let S = { 2n | n }. Then ∈ℕ |S| = ℵ .₀

Proof: We prove that |S| = | |; since | | = by definition, ℕ ℕ ℵ₀this proves that |S| = .ℵ₀

To show that |S| = | |, we will find a bijection between the two ℕof them. Consider the function f : → ℕ S defined as f(n) = 2n. By the definition of S, for any n , ∈ℕ f(n) = 2n ∈ S, so f is a function from to ℕ S.

To show that f is a bijection, we show that it is injective and surjective. To show that f is injective, consider any m and n where f(m) = f(n); we will prove that m = n. To see this, note that if f(m) = f(n), then 2m = 2n, and so m = n as required. To show that f is surjective, consider any m ∈ S; we show that there is an n such that ∈ℕ f(n) = m. Since m ∈ S, m = 2k for some k . If we take ∈ℕ n = k, then f(n) = 2n = 2k = m, as required. Thus f is injective and surjective, so it is a bijection, and |S| = | | = . ■ℕ ℵ₀

Page 113: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: Let S = { 2n | n }. Then ∈ℕ |S| = ℵ .₀

Proof: We prove that |S| = | |; since | | = by definition, ℕ ℕ ℵ₀this proves that |S| = .ℵ₀

To show that |S| = | |, we will find a bijection between the two ℕof them. Consider the function f : → ℕ S defined as f(n) = 2n. By the definition of S, for any n , ∈ℕ f(n) = 2n ∈ S, so f is a function from to ℕ S.

To show that f is a bijection, we show that it is injective and surjective. To show that f is injective, consider any m and n where f(m) = f(n); we will prove that m = n. To see this, note that if f(m) = f(n), then 2m = 2n, and so m = n as required. To show that f is surjective, consider any m ∈ S; we show that there is an n such that ∈ℕ f(n) = m. Since m ∈ S, m = 2k for some k . If we take ∈ℕ n = k, then f(n) = 2n = 2k = m, as required. Thus f is injective and surjective, so it is a bijection, and |S| = | | = . ■ℕ ℵ₀

Page 114: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: Let S = { 2n | n }. Then ∈ℕ |S| = ℵ .₀

Proof: We prove that |S| = | |; since | | = by definition, ℕ ℕ ℵ₀this proves that |S| = .ℵ₀

To show that |S| = | |, we will find a bijection between the two ℕof them. Consider the function f : → ℕ S defined as f(n) = 2n. By the definition of S, for any n , ∈ℕ f(n) = 2n ∈ S, so f is a function from to ℕ S.

To show that f is a bijection, we show that it is injective and surjective. To show that f is injective, consider any m and n where f(m) = f(n); we will prove that m = n. To see this, note that if f(m) = f(n), then 2m = 2n, and so m = n as required. To show that f is surjective, consider any m ∈ S; we show that there is an n such that ∈ℕ f(n) = m. Since m ∈ S, m = 2k for some k . If we take ∈ℕ n = k, then f(n) = 2n = 2k = m, as required. Thus f is injective and surjective, so it is a bijection, and |S| = | | = . ■ℕ ℵ₀

Page 115: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: Let S = { 2n | n }. Then ∈ℕ |S| = ℵ .₀

Proof: We prove that |S| = | |; since | | = by definition, ℕ ℕ ℵ₀this proves that |S| = .ℵ₀

To show that |S| = | |, we will find a bijection between the two ℕof them. Consider the function f : → ℕ S defined as f(n) = 2n. By the definition of S, for any n , ∈ℕ f(n) = 2n ∈ S, so f is a function from to ℕ S.

To show that f is a bijection, we show that it is injective and surjective. To show that f is injective, consider any m and n where f(m) = f(n); we will prove that m = n. To see this, note that if f(m) = f(n), then 2m = 2n, and so m = n as required. To show that f is surjective, consider any m ∈ S; we show that there is an n such that ∈ℕ f(n) = m. Since m ∈ S, m = 2k for some k . If we take ∈ℕ n = k, then f(n) = 2n = 2k = m, as required. Thus f is injective and surjective, so it is a bijection, and |S| = | | = . ■ℕ ℵ₀

Page 116: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: Let S = { 2n | n }. Then ∈ℕ |S| = ℵ .₀

Proof: We prove that |S| = | |; since | | = by definition, ℕ ℕ ℵ₀this proves that |S| = .ℵ₀

To show that |S| = | |, we will find a bijection between the two ℕof them. Consider the function f : → ℕ S defined as f(n) = 2n. By the definition of S, for any n , ∈ℕ f(n) = 2n ∈ S, so f is a function from to ℕ S.

To show that f is a bijection, we show that it is injective and surjective. To show that f is injective, consider any m and n where f(m) = f(n); we will prove that m = n. To see this, note that if f(m) = f(n), then 2m = 2n, and so m = n as required. To show that f is surjective, consider any m ∈ S; we show that there is an n such that ∈ℕ f(n) = m. Since m ∈ S, m = 2k for some k . If we take ∈ℕ n = k, then f(n) = 2n = 2k = m, as required. Thus f is injective and surjective, so it is a bijection, and |S| = | | = . ■ℕ ℵ₀

Page 117: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: Let S = { 2n | n }. Then ∈ℕ |S| = ℵ .₀

Proof: We prove that |S| = | |; since | | = by definition, ℕ ℕ ℵ₀this proves that |S| = .ℵ₀

To show that |S| = | |, we will find a bijection between the two ℕof them. Consider the function f : → ℕ S defined as f(n) = 2n. By the definition of S, for any n , ∈ℕ f(n) = 2n ∈ S, so f is a function from to ℕ S.

To show that f is a bijection, we show that it is injective and surjective. To show that f is injective, consider any m and n where f(m) = f(n); we will prove that m = n. To see this, note that if f(m) = f(n), then 2m = 2n, and so m = n as required. To show that f is surjective, consider any m ∈ S; we show that there is an n such that ∈ℕ f(n) = m. Since m ∈ S, m = 2k for some k . If we take ∈ℕ n = k, then f(n) = 2n = 2k = m, as required. Thus f is injective and surjective, so it is a bijection, and |S| = | | = . ■ℕ ℵ₀

Page 118: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: Let S = { 2n | n }. Then ∈ℕ |S| = ℵ .₀

Proof: We prove that |S| = | |; since | | = by definition, ℕ ℕ ℵ₀this proves that |S| = .ℵ₀

To show that |S| = | |, we will find a bijection between the two ℕof them. Consider the function f : → ℕ S defined as f(n) = 2n. By the definition of S, for any n , ∈ℕ f(n) = 2n ∈ S, so f is a function from to ℕ S.

To show that f is a bijection, we show that it is injective and surjective. To show that f is injective, consider any m and n where f(m) = f(n); we will prove that m = n. To see this, note that if f(m) = f(n), then 2m = 2n, and so m = n as required. To show that f is surjective, consider any m ∈ S; we show that there is an n such that ∈ℕ f(n) = m. Since m ∈ S, m = 2k for some k . If we take ∈ℕ n = k, then f(n) = 2n = 2k = m, as required. Thus f is injective and surjective, so it is a bijection, and |S| = | | = . ■ℕ ℵ₀

Page 119: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: Let S = { 2n | n }. Then ∈ℕ |S| = ℵ .₀

Proof: We prove that |S| = | |; since | | = by definition, ℕ ℕ ℵ₀this proves that |S| = .ℵ₀

To show that |S| = | |, we will find a bijection between the two ℕof them. Consider the function f : → ℕ S defined as f(n) = 2n. By the definition of S, for any n , ∈ℕ f(n) = 2n ∈ S, so f is a function from to ℕ S.

To show that f is a bijection, we show that it is injective and surjective. To show that f is injective, consider any m and n where f(m) = f(n); we will prove that m = n. To see this, note that if f(m) = f(n), then 2m = 2n, and so m = n as required. To show that f is surjective, consider any m ∈ S; we show that there is an n such that ∈ℕ f(n) = m. Since m ∈ S, m = 2k for some k . ∈ℕ If we take n = k, then f(n) = 2n = 2k = m, as required. Thus f is injective and surjective, so it is a bijection, and |S| = | | = . ■ℕ ℵ₀

Page 120: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: Let S = { 2n | n }. Then ∈ℕ |S| = ℵ .₀

Proof: We prove that |S| = | |; since | | = by definition, ℕ ℕ ℵ₀this proves that |S| = .ℵ₀

To show that |S| = | |, we will find a bijection between the two ℕof them. Consider the function f : → ℕ S defined as f(n) = 2n. By the definition of S, for any n , ∈ℕ f(n) = 2n ∈ S, so f is a function from to ℕ S.

To show that f is a bijection, we show that it is injective and surjective. To show that f is injective, consider any m and n where f(m) = f(n); we will prove that m = n. To see this, note that if f(m) = f(n), then 2m = 2n, and so m = n as required. To show that f is surjective, consider any m ∈ S; we show that there is an n such that ∈ℕ f(n) = m. Since m ∈ S, m = 2k for some k . If we take ∈ℕ n = k, then f(n) = 2n = 2k = m, as required. Thus f is injective and surjective, so it is a bijection, and |S| = | | = . ■ℕ ℵ₀

Page 121: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: Let S = { 2n | n }. Then ∈ℕ |S| = ℵ .₀

Proof: We prove that |S| = | |; since | | = by definition, ℕ ℕ ℵ₀this proves that |S| = .ℵ₀

To show that |S| = | |, we will find a bijection between the two ℕof them. Consider the function f : → ℕ S defined as f(n) = 2n. By the definition of S, for any n , ∈ℕ f(n) = 2n ∈ S, so f is a function from to ℕ S.

To show that f is a bijection, we show that it is injective and surjective. To show that f is injective, consider any m and n where f(m) = f(n); we will prove that m = n. To see this, note that if f(m) = f(n), then 2m = 2n, and so m = n as required. To show that f is surjective, consider any m ∈ S; we show that there is an n such that ∈ℕ f(n) = m. Since m ∈ S, m = 2k for some k . If we take ∈ℕ n = k, then f(n) = 2n = 2k = m, as required. Thus f is injective and surjective, so it is a bijection, and |S| = | | = . ℕ ℵ₀ ■

Page 122: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: Let S = { 2n | n }. Then ∈ℕ |S| = ℵ .₀

Proof: We prove that |S| = | |; since | | = by definition, ℕ ℕ ℵ₀this proves that |S| = .ℵ₀

To show that |S| = | |, we will find a bijection between the two ℕof them. Consider the function f : → ℕ S defined as f(n) = 2n. By the definition of S, for any n , ∈ℕ f(n) = 2n ∈ S, so f is a function from to ℕ S.

To show that f is a bijection, we show that it is injective and surjective. To show that f is injective, consider any m and n where f(m) = f(n); we will prove that m = n. To see this, note that if f(m) = f(n), then 2m = 2n, and so m = n as required. To show that f is surjective, consider any m ∈ S; we show that there is an n such that ∈ℕ f(n) = m. Since m ∈ S, m = 2k for some k . If we take ∈ℕ n = k, then f(n) = 2n = 2k = m, as required. Thus f is injective and surjective, so it is a bijection, and |S| = | | = . ■ℕ ℵ₀

Page 123: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Comparing Cardinalities

● Formally, we define < on cardinalities as

|S| < |T| iff |S| ≤ |T| and |S| ≠ |T| ● In other words:

● There is an injection f : S → T.● There is no bijection f : S → T.

Page 124: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Cantor's Theorem

● Cantor's Theorem states that

For every set S, |S| < | (℘ S)| ● This is how we concluded that there are more

problems to solve than programs to solve them.● We informally sketched a proof of this in the

first lecture.● Let's now formally prove Cantor's Theorem.

Page 125: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Lemma: For any set S, |S| ≤ | (℘ S)|.

Proof: Consider any set S. We show that there is an injection f : S → (℘ S). Let f(x) = {x} for any x ∈ S. Since for anyx ∈ S, {x} ⊆ S, we have that {x} (∈ ℘ S), so f is a valid function from S to (℘ S).

To see that f is injective, consider any x0 and x

1 such that

f(x0) = f(x

1). We prove that x

0 = x

1. To see this, note that if

f(x0) = f(x

1), then {x

0} = {x

1}. Since two sets are equal iff their

elements are equal, this means that x0 = x

1 as required. Thus

f is an injection from S to (℘ S), so |S| ≤ | (℘ S)|. ■

Page 126: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Lemma: For any set S, |S| ≤ | (℘ S)|.

Proof: Consider any set S. We show that there is an injection f : S → (℘ S). Let f(x) = {x} for any x ∈ S. Since for anyx ∈ S, {x} ⊆ S, we have that {x} (∈ ℘ S), so f is a valid function from S to (℘ S).

To see that f is injective, consider any x0 and x

1 such that

f(x0) = f(x

1). We prove that x

0 = x

1. To see this, note that if

f(x0) = f(x

1), then {x

0} = {x

1}. Since two sets are equal iff their

elements are equal, this means that x0 = x

1 as required. Thus

f is an injection from S to (℘ S), so |S| ≤ | (℘ S)|. ■

Page 127: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Lemma: For any set S, |S| ≤ | (℘ S)|.

Proof: Consider any set S. We show that there is an injection f : S → (℘ S). Let f(x) = {x} for any x ∈ S. Since for anyx ∈ S, {x} ⊆ S, we have that {x} (∈ ℘ S), so f is a valid function from S to (℘ S).

To see that f is injective, consider any x0 and x

1 such that

f(x0) = f(x

1). We prove that x

0 = x

1. To see this, note that if

f(x0) = f(x

1), then {x

0} = {x

1}. Since two sets are equal iff their

elements are equal, this means that x0 = x

1 as required. Thus

f is an injection from S to (℘ S), so |S| ≤ | (℘ S)|. ■

Page 128: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Lemma: For any set S, |S| ≤ | (℘ S)|.

Proof: Consider any set S. We show that there is an injection f : S → (℘ S). Let f(x) = {x} for any x ∈ S. Since for anyx ∈ S, {x} ⊆ S, we have that {x} (∈ ℘ S), so f is a valid function from S to (℘ S).

To see that f is injective, consider any x0 and x

1 such that

f(x0) = f(x

1). We prove that x

0 = x

1. To see this, note that if

f(x0) = f(x

1), then {x

0} = {x

1}. Since two sets are equal iff their

elements are equal, this means that x0 = x

1 as required. Thus

f is an injection from S to (℘ S), so |S| ≤ | (℘ S)|. ■

Page 129: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Lemma: For any set S, |S| ≤ | (℘ S)|.

Proof: Consider any set S. We show that there is an injection f : S → (℘ S). Let f(x) = {x} for any x ∈ S. Since for anyx ∈ S, {x} ⊆ S, we have that {x} (∈ ℘ S), so f is a valid function from S to (℘ S).

To see that f is injective, consider any x0 and x

1 such that

f(x0) = f(x

1). We prove that x

0 = x

1. To see this, note that if

f(x0) = f(x

1), then {x

0} = {x

1}. Since two sets are equal iff their

elements are equal, this means that x0 = x

1 as required. Thus

f is an injection from S to (℘ S), so |S| ≤ | (℘ S)|. ■

Page 130: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Lemma: For any set S, |S| ≤ | (℘ S)|.

Proof: Consider any set S. We show that there is an injection f : S → (℘ S). Let f(x) = {x} for any x ∈ S. Since for anyx ∈ S, {x} ⊆ S, we have that {x} (∈ ℘ S), so f is a valid function from S to (℘ S).

To see that f is injective, consider any x0 and x

1 such that

f(x0) = f(x

1). We prove that x

0 = x

1. To see this, note that if

f(x0) = f(x

1), then {x

0} = {x

1}. Since two sets are equal iff their

elements are equal, this means that x0 = x

1 as required. Thus

f is an injection from S to (℘ S), so |S| ≤ | (℘ S)|. ■

Page 131: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Lemma: For any set S, |S| ≤ | (℘ S)|.

Proof: Consider any set S. We show that there is an injection f : S → (℘ S). Let f(x) = {x} for any x ∈ S. Since for anyx ∈ S, {x} ⊆ S, we have that {x} (∈ ℘ S), so f is a valid function from S to (℘ S).

To see that f is injective, consider any x0 and x

1 such that

f(x0) = f(x

1). We prove that x

0 = x

1. To see this, note that if

f(x0) = f(x

1), then {x

0} = {x

1}. Since two sets are equal iff their

elements are equal, this means that x0 = x

1 as required. Thus

f is an injection from S to (℘ S), so |S| ≤ | (℘ S)|. ■

Page 132: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Lemma: For any set S, |S| ≤ | (℘ S)|.

Proof: Consider any set S. We show that there is an injection f : S → (℘ S). Let f(x) = {x} for any x ∈ S. Since for anyx ∈ S, {x} ⊆ S, we have that {x} (∈ ℘ S), so f is a valid function from S to (℘ S).

To see that f is injective, consider any x0 and x

1 such that

f(x0) = f(x

1). We prove that x

0 = x

1. To see this, note that if

f(x0) = f(x

1), then {x

0} = {x

1}. Since two sets are equal iff their

elements are equal, this means that x0 = x

1 as required. Thus

f is an injection from S to (℘ S), so |S| ≤ | (℘ S)|. ■

Page 133: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Lemma: For any set S, |S| ≤ | (℘ S)|.

Proof: Consider any set S. We show that there is an injection f : S → (℘ S). Let f(x) = {x} for any x ∈ S. Since for anyx ∈ S, {x} ⊆ S, we have that {x} (∈ ℘ S), so f is a valid function from S to (℘ S).

To see that f is injective, consider any x0 and x

1 such that

f(x0) = f(x

1). We prove that x

0 = x

1. To see this, note that if

f(x0) = f(x

1), then {x

0} = {x

1}. Since two sets are equal iff their

elements are equal, this means that x0 = x

1 as required. Thus

f is an injection from S to (℘ S), so |S| ≤ | (℘ S)|. ■

Page 134: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Lemma: For any set S, |S| ≤ | (℘ S)|.

Proof: Consider any set S. We show that there is an injection f : S → (℘ S). Let f(x) = {x} for any x ∈ S. Since for anyx ∈ S, {x} ⊆ S, we have that {x} (∈ ℘ S), so f is a valid function from S to (℘ S).

To see that f is injective, consider any x0 and x

1 such that

f(x0) = f(x

1). We prove that x

0 = x

1. To see this, note that if

f(x0) = f(x

1), then {x

0} = {x

1}. Since two sets are equal iff their

elements are equal, this means that x0 = x

1 as required. Thus

f is an injection from S to (℘ S), so |S| ≤ | (℘ S)|. ■

Page 135: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Lemma: For any set S, |S| ≤ | (℘ S)|.

Proof: Consider any set S. We show that there is an injection f : S → (℘ S). Let f(x) = {x} for any x ∈ S. Since for anyx ∈ S, {x} ⊆ S, we have that {x} (∈ ℘ S), so f is a valid function from S to (℘ S).

To see that f is injective, consider any x0 and x

1 such that

f(x0) = f(x

1). We prove that x

0 = x

1. To see this, note that if

f(x0) = f(x

1), then {x

0} = {x

1}. Since two sets are equal iff their

elements are equal, this means that x0 = x

1 as required. Thus

f is an injection from S to (℘ S), so |S| ≤ | (℘ S)|. ■

Page 136: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

The Key Step

● We now need to show that

For any set S, |S| ≠ | (℘ S)| ● By definition, |S| = | (℘ S)| iff there exists a bijection f :

S → (℘ S).● This means that

|S| ≠ | (℘ S)| iff there is no bijection f : S → (℘ S)● Prove this by contradiction:

● Assume that there is a bijection f : S → (℘ S).● Derive a contradiction by showing that f is not a bijection.

Page 137: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

x0

x2

x3

x4

x5

x1

...

Page 138: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

x0

x2

x3

x4

x5

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ x0, x

2, x

4, ... }

{ x0, x

3, x

4, ... }

{ x4, ... }

{ x1, x

4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ “b”, “ab”, ... }

{ x0, x

1, x

2, x

3, x

4, x

5, ... }

x1

...

{ x0, x

5, ... }

Page 139: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

x0

x2

x3

x4

x5

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ x0, x

2, x

4, ... }

{ x0, x

3, x

4, ... }

{ x4, ... }

{ x1, x

4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ “b”, “ab”, ... }

{ x0, x

1, x

2, x

3, x

4, x

5, ... }

x1

...

{ x0, x

5, ... }

0 1 2 3 4 5 ...x0

x1

x2

x3

x4

x5 ...

Page 140: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

x0

x2

x3

x4

x5

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ x0, x

2, x

4, ... }

{ x0, x

3, x

4, ... }

{ x4, ... }

{ x1, x

4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ “b”, “ab”, ... }

{ x0, x

1, x

2, x

3, x

4, x

5, ... }

x1

...

{ x0, x

5, ... }

0 1 2 3 4 5 ...x0

x1

x2

x3

x4

x5 ...

Y Y YN N N …

Page 141: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

x0

x2

x3

x4

x5

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ x0, x

2, x

4, ... }

{ x0, x

3, x

4, ... }

{ x4, ... }

{ x1, x

4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ “b”, “ab”, ... }

{ x0, x

1, x

2, x

3, x

4, x

5, ... }

x1

...

{ x0, x

5, ... }

0 1 2 3 4 5 ...x0

x1

x2

x3

x4

x5 ...

Y Y YN N N …

This string of Ys and Ns is called a characteristic

vector. Every characteristic vector defines a set, and

vice-versa.

This string of Ys and Ns is called a characteristic

vector. Every characteristic vector defines a set, and

vice-versa.

Page 142: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

x0

x2

x3

x4

x5

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ x0, x

2, x

4, ... }

{ x0, x

3, x

4, ... }

{ x4, ... }

{ x1, x

4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ “b”, “ab”, ... }

{ x0, x

1, x

2, x

3, x

4, x

5, ... }

x1

...

{ x0, x

5, ... }

0 1 2 3 4 5 ...x0

x1

x2

x3

x4

x5 ...

Y Y YN N N …

Y Y Y NN N …

Page 143: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

x0

x2

x3

x4

x5

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ x0, x

2, x

4, ... }

{ x0, x

3, x

4, ... }

{ x4, ... }

{ x1, x

4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ “b”, “ab”, ... }

{ x0, x

1, x

2, x

3, x

4, x

5, ... }

x1

...

{ x0, x

5, ... }

0 1 2 3 4 5 ...x0

x1

x2

x3

x4

x5 ...

Y Y YN N N …

Y Y Y NN N …

Y NN N N N …

Page 144: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

x0

x2

x3

x4

x5

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ x0, x

2, x

4, ... }

{ x0, x

3, x

4, ... }

{ x4, ... }

{ x1, x

4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ “b”, “ab”, ... }

{ x0, x

1, x

2, x

3, x

4, x

5, ... }

x1

...

{ x0, x

5, ... }

0 1 2 3 4 5 ...x0

x1

x2

x3

x4

x5 ...

Y Y YN N N …

Y Y Y NN N …

Y NN N N N …

Y Y NN NN …

Page 145: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

x0

x2

x3

x4

x5

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ x0, x

2, x

4, ... }

{ x0, x

3, x

4, ... }

{ x4, ... }

{ x1, x

4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ “b”, “ab”, ... }

{ x0, x

1, x

2, x

3, x

4, x

5, ... }

x1

...

{ x0, x

5, ... }

0 1 2 3 4 5 ...x0

x1

x2

x3

x4

x5 ...

Y Y YN N N …

Y Y Y NN N …

Y NN N N N …

Y Y NN NN …

Y NN …N YN

Page 146: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

x0

x2

x3

x4

x5

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ x0, x

2, x

4, ... }

{ x0, x

3, x

4, ... }

{ x4, ... }

{ x1, x

4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ “b”, “ab”, ... }

{ x0, x

1, x

2, x

3, x

4, x

5, ... }

x1

...

{ x0, x

5, ... }

0 1 2 3 4 5 ...x0

x1

x2

x3

x4

x5 ...

Y Y YN N N …

Y Y Y NN N …

Y NN N N N …

Y Y NN NN …

Y Y Y Y Y Y …

Y NN …N YN

Page 147: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

x0

x2

x3

x4

x5

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ x0, x

2, x

4, ... }

{ x0, x

3, x

4, ... }

{ x4, ... }

{ x1, x

4, ... }

{ 0, 2, 4, ... }

{ 0, 2, 4, ... }

{ “b”, “ab”, ... }

{ x0, x

1, x

2, x

3, x

4, x

5, ... }

x1

...

{ x0, x

5, ... }

0 1 2 3 4 5 ...x0

x1

x2

x3

x4

x5 ...

Y Y YN N N …

Y Y Y NN N …

Y NN N N N …

Y Y NN NN …

Y Y Y Y Y Y …

Y NN …N YN

… … … … … … …

Page 148: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

x0

x2

x3

x4

x5

{ 0, 2, 4, ... }

...

Y Y YN N N …

Y Y Y NN N …

Y NN N N N …

Y Y NN NN …

Y Y NNNN …

Y Y Y Y Y Y …

… … … … … … …

x1

{ 0, 2, 4, ... }{ “b”, “ab”, ... }Y NYN N …N YN

x0

x1

x2

x3

x4

x5 ...

Page 149: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

{ 0, 2, 4, ... }

...

Y Y YN N N …

Y Y Y NN N …

Y NN N N N …

Y Y NN NN …

Y Y NNNN …

Y Y Y Y Y Y …

… … … … … … …

{ 0, 2, 4, ... }{ “b”, “ab”, ... }Y NYN N …N YN

x0

x2

x3

x3

x4

x1

x0

x1

x2

x3

x4

x5 ...

x4

x5

Page 150: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

{ 0, 2, 4, ... }Y Y YN N N …

Y Y Y NN N …

Y NN N N N …

Y Y NN NN …

Y Y NNNN …

Y Y Y Y Y Y …

… … … … … …

…Y N N N N Y

…...

{ 0, 2, 4, ... }{ “b”, “ab”, ... }Y NYN N …N YN

x0

x2

x3

x3

x4

x1

x0

x1

x2

x3

x4

x5 ...

x4

x5

Page 151: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

{ 0, 2, 4, ... }Y Y YN N N …

Y Y Y NN N …

Y NN N N N …

Y Y NN NN …

Y Y NNNN …

Y Y Y Y Y Y …

… … … … … … …

Y N N N Y YN Y Y Y Y N ...

...

Y NYN N …N YN

x0

x2

x3

x3

x4

x1

x0

x1

x2

x3

x4

x5 ...

Flip all Y's to N's and vice-versa to get a

new characteristic vector.

Flip all Y's to N's and vice-versa to get a

new characteristic vector.

…Y N N N N Y

x4

x5

Page 152: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

{ 0, 2, 4, ... }Y Y YN N N …

Y Y Y NN N …

Y NN N N N …

Y Y NN NN …

Y Y NNNN …

Y Y Y Y Y Y …

… … … … … … …

Y N N N Y YN Y Y Y N N ...

...

Y NYN N …N

Y

YN

x0

x2

x3

x3

x4

x1

x0

x1

x2

x3

x4

x5 ...

Flip all Y's to N's and vice-versa to get a

new characteristic vector.

Flip all Y's to N's and vice-versa to get a

new characteristic vector.

x4

x5

Page 153: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

{ 0, 2, 4, ... }Y Y YN N N …

Y Y Y NN N …

Y NN N N N …

Y Y NN NN …

Y Y NNNN …

Y Y Y Y Y Y …

… … … … … … …

Y N N N Y YN Y Y Y N N ...

...

Y NYN N …N

Y

YN

x0

x2

x3

x3

x4

x1

x0

x1

x2

x3

x4

x5 ...

x4

x5

Page 154: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

{ 0, 2, 4, ... }Y Y YN N N …

Y Y Y NN N …

Y NN N N N …

Y Y NN NN …

Y Y NNNN …

Y Y Y Y Y Y …

… … … … … … …

Y N N N Y YN Y Y Y N N ...

...

Y NYN N …N

Y

YN

x0

x2

x3

x3

x4

x1

x0

x1

x2

x3

x4

x5 ...

Which row in the table has this characteristic

vector?

Which row in the table has this characteristic

vector?x4

x5

Page 155: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

{ 0, 2, 4, ... }Y Y YN N N …

Y Y Y NN N …

Y NN N N N …

Y Y NN NN …

Y Y NNNN …

Y Y Y Y Y Y …

… … … … … … …

Y N N N Y YN Y Y Y N N ...

...

Y NYN N …N

Y

YN

x0

x2

x3

x3

x4

x1

x0

x1

x2

x3

x4

x5 ...

...

Which row in the table has this characteristic

vector?

Which row in the table has this characteristic

vector?x4

x5

Page 156: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

{ 0, 2, 4, ... }Y Y YN N N …

Y Y Y NN N …

Y NN N N N …

Y Y NN NN …

Y Y NNNN …

Y Y Y Y Y Y …

… … … … … … …

Y N N N Y YN Y Y Y N N ...

...

Y NYN N …N

Y

YN

x0

x2

x3

x3

x4

x1

x0

x1

x2

x3

x4

x5 ...

...

Which row in the table has this characteristic

vector?

Which row in the table has this characteristic

vector?x4

x5

Page 157: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

{ 0, 2, 4, ... }Y Y YN N N …

Y Y Y NN N …

Y NN N N N …

Y Y NN NN …

Y Y NNNN …

Y Y Y Y Y Y …

… … … … … … …

Y N N N Y YN Y Y Y N N ...

...

Y NYN N …N

Y

YN

x0

x2

x3

x3

x4

x1

x0

x1

x2

x3

x4

x5 ...

...

Which row in the table has this characteristic

vector?

Which row in the table has this characteristic

vector?x4

x5

Page 158: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

{ 0, 2, 4, ... }Y Y YN N N …

Y Y Y NN N …

Y NN N N N …

Y Y NN NN …

Y Y NNNN …

Y Y Y Y Y Y …

… … … … … … …

Y N N N Y YN Y Y Y N N ...

...

Y NYN N …N

Y

YN

x0

x2

x3

x3

x4

x1

x0

x1

x2

x3

x4

x5 ...

...

Which row in the table has this characteristic

vector?

Which row in the table has this characteristic

vector?x4

x5

Page 159: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

{ 0, 2, 4, ... }Y Y YN N N …

Y Y Y NN N …

Y NN N N N …

Y Y NN NN …

Y Y NNNN …

Y Y Y Y Y Y …

… … … … … … …

Y N N N Y YN Y Y Y N N ...

...

Y NYN N …N

Y

YN

x0

x2

x3

x3

x4

x1

x0

x1

x2

x3

x4

x5 ...

...

Which row in the table has this characteristic

vector?

Which row in the table has this characteristic

vector?x4

x5

Page 160: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

{ 0, 2, 4, ... }Y Y YN N N …

Y Y Y NN N …

Y NN N N N …

Y Y NN NN …

Y Y NNNN …

Y Y Y Y Y Y …

… … … … … … …

Y N N N Y YN Y Y Y N N ...

...

Y NYN N …N

Y

YN

x0

x2

x3

x3

x4

x1

x0

x1

x2

x3

x4

x5 ...

...

Which row in the table has this characteristic

vector?

Which row in the table has this characteristic

vector?x4

x5

Page 161: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

{ 0, 2, 4, ... }Y Y YN N N …

Y Y Y NN N …

Y NN N N N …

Y Y NN NN …

Y Y NNNN …

Y Y Y Y Y Y …

… … … … … … …

Y N N N Y YN Y Y Y Y N ...

...

Y NYN N …N YN

x0

x2

x3

x3

x4

x1

x0

x1

x2

x3

x4

x5 ...

...

Which row in the table has this characteristic

vector?

Which row in the table has this characteristic

vector?x4

x5

Page 162: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

{ 0, 2, 4, ... }Y Y YN N N …

Y Y Y NN N …

Y NN N N N …

Y Y NN NN …

Y Y NNNN …

Y Y Y Y Y Y …

… … … … … … …

Y N N N Y YN Y Y Y N N ...

...

Y NYN N …N

Y

YN

x0

x2

x3

x3

x4

x1

x0

x1

x2

x3

x4

x5 ...

...

Which row in the table has this characteristic

vector?

Which row in the table has this characteristic

vector?x4

x5

Page 163: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

...

{ 0, 2, 4, ... }Y Y YN N N …

Y Y Y NN N …

Y NN N N N …

Y Y NN NN …

Y Y NNNN …

Y Y Y Y Y Y …

… … … … … … …

Y N N N Y YN Y Y Y N N ...

...

Y NYN N …N

Y

YN

x0

x2

x3

x3

x4

x1

x0

x1

x2

x3

x4

x5 ...

Which row in the table has this characteristic

vector?

Which row in the table has this characteristic

vector?x4

x5

Page 164: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Formalizing the Diagonal Argument

● We now have a sketch of an argument to prove that we don't have a bijection:● Construct the table given the bijection f.● Construct the complemented diagonal.● Show that the complemented diagonal cannot

appear anywhere in the table.● Conclude, therefore, that f is not a bijection.

For finite sets this is fine, but what if the set is infinitely large?

Page 165: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Formalizing the Diagonal Argument

● We now have a sketch of an argument to prove that we don't have a bijection:● Construct the table given the bijection f.● Construct the complemented diagonal.● Show that the complemented diagonal cannot

appear anywhere in the table.● Conclude, therefore, that f is not a bijection.

For finite sets this is fine, but what if the set is infinitely large?

Page 166: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Formalizing the Diagonal Argument

● We now have a sketch of an argument to prove that we don't have a bijection:● Construct the table given the bijection f.● Construct the complemented diagonal.● Show that the complemented diagonal cannot

appear anywhere in the table.● Conclude, therefore, that f is not a bijection.

● For finite sets this is fine, but what if the set is infinitely large?

Page 167: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

...

{ 0, 2, 4, ... }Y Y YN N N …

Y Y Y NN N …

Y NN N N N …

Y Y NN YN …

Y Y NNNN …

N Y N N Y Y …

… … … … … … …

Y N N N Y YN Y Y N N N ...

...

Y NYN N …N

Y

YN

x0

x2

x3

x4

x5

x1

x0

x1

x2

x3

x4

x5 ...

Page 168: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

...

{ 0, 2, 4, ... }Y Y YN N N …

Y Y Y NN N …

Y NN N N N …

Y Y NN YN …

Y Y NNNN …

N Y N N Y Y …

… … … … … … …

Y N N N Y YN Y Y N N N ...

...

Y NYN N …N

Y

YN

x0

x2

x3

x4

x5

x1

x0

x1

x2

x3

x4

x5 ...

f(x0) = { x

0, x

2, x

4, … }

f(x1) = { x

0, x

3, x

4, … }

f(x2) = { x

4, … }

f(x3) = { x

1, x

3, x

4, … }

f(x4) = { x

1, x

5, … }

f(x5) = { x

1, x

4, x

5, … }

Page 169: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

...

{ 0, 2, 4, ... }Y Y YN N N …

Y Y Y NN N …

Y NN N N N …

Y Y NN YN …

Y Y NNNN …

N Y N N Y Y …

… … … … … … …

Y N N N Y YN Y Y N N N ...

...

Y NYN N …N

Y

YN

x0

x2

x3

x4

x5

x1

x0

x1

x2

x3

x4

x5 ...

f(x0) = { x

0, x

2, x

4, … }

f(x1) = { x

0, x

3, x

4, … }

f(x2) = { x

4, … }

f(x3) = { x

1, x

3, x

4, … }

f(x4) = { x

1, x

5, … }

f(x5) = { x

1, x

4, x

5, … }

Page 170: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

...

{ 0, 2, 4, ... }Y Y YN N N …

Y Y Y NN N …

Y NN N N N …

Y Y NN YN …

Y Y NNNN …

N Y N N Y Y …

… … … … … … …

Y N N N Y YN Y Y N N N ...

...

Y NYN N …N

Y

YN

x0

x2

x3

x3

x4

x1

x0

x1

x2

x3

x4

x5 ...

x4

x5

f(x0) = { x

0, x

2, x

4, … }

f(x1) = { x

0, x

3, x

4, … }

f(x2) = { x

4, … }

f(x3) = { x

1, x

3, x

4, … }

f(x4) = { x

1, x

5, … }

f(x5) = { x

1, x

4, x

5, … }

Page 171: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

...

{ 0, 2, 4, ... }Y Y YN N N …

Y Y Y NN N …

Y NN N N N …

Y Y NN YN …

Y Y NNNN …

N Y N N Y Y …

… … … … … … …

Y N N N Y YN Y Y N N N ...

...

Y NYN N …N

Y

YN

x0

x2

x3

x4

x5

x1

x0

x1

x2

x3

x4

x5 ...

f(x0) = { x

0, x

2, x

4, … }

f(x1) = { x

0, x

3, x

4, … }

f(x2) = { x

4, … }

f(x3) = { x

1, x

3, x

4, … }

f(x4) = { x

1, x

5, … }

f(x5) = { x

1, x

4, x

5, … }

Page 172: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

...

{ 0, 2, 4, ... }Y Y YN N N …

Y Y Y NN N …

Y NN N N N …

Y Y NN YN …

Y Y NNNN …

N Y N N Y Y …

… … … … … … …

Y N N N Y YN Y Y N N N ...

...

Y NYN N …N

Y

YN

x0

x2

x3

x4

x5

x1

x0

x1

x2

x3

x4

x5 ...

f(x0) = { x

0, x

2, x

4, … }

f(x1) = { x

0, x

3, x

4, … }

f(x2) = { x

4, … }

f(x3) = { x

1, x

3, x

4, … }

f(x4) = { x

1, x

5, … }

f(x5) = { x

1, x

4, x

5, … }

Page 173: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

The diagonal set D is the set

D = { x S∈ | x ∉ f(x) }

There is no longer a dependence on theexistence of the two-dimensional table.

Page 174: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Lemma: For any set S, |S| ≠ | (℘ S)|.

Proof: By contradiction; assume that there exists a set S such that|S| = | (℘ S)|. This means that there is a bijection f : S → (℘ S). Consider the set D = { x ∈ S | x ∉ f(S) }. Since by construction every x ∈ D satisfies x ∈ S, D ⊆ S, so D (∈ ℘ S).

Since f is a bijection, it is surjective, so there must be some d ∈ S such that f(d) = D. Now, either d ∈ D, or d ∉ D. We consider these cases separately:

Case 1: d ∈ D. By our definition of d, this means that d ∉ f(d). However, we know that f(d) = D, so this means that d ∉ D, contradicting the fact that d ∈ D.

Case 2: d ∉ D. By our definition of d, this means that d ∈ f(d). However, we know that f(d) = D, so this means that d ∈ D, contradicting the fact that d ∉ D.

In either case we reach a contradiction, so our assumption must have been wrong. Thus for every set S, |S| ≠ | (℘ S)|. ■

Page 175: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Lemma: For any set S, |S| ≠ | (℘ S)|.

Proof: By contradiction; assume that there exists a set S such that|S| = | (℘ S)|. This means that there is a bijection f : S → (℘ S). Consider the set D = { x ∈ S | x ∉ f(S) }. Since by construction every x ∈ D satisfies x ∈ S, D ⊆ S, so D (∈ ℘ S).

Since f is a bijection, it is surjective, so there must be some d ∈ S such that f(d) = D. Now, either d ∈ D, or d ∉ D. We consider these cases separately:

Case 1: d ∈ D. By our definition of d, this means that d ∉ f(d). However, we know that f(d) = D, so this means that d ∉ D, contradicting the fact that d ∈ D.

Case 2: d ∉ D. By our definition of d, this means that d ∈ f(d). However, we know that f(d) = D, so this means that d ∈ D, contradicting the fact that d ∉ D.

In either case we reach a contradiction, so our assumption must have been wrong. Thus for every set S, |S| ≠ | (℘ S)|. ■

Page 176: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Lemma: For any set S, |S| ≠ | (℘ S)|.

Proof: By contradiction; assume that there exists a set S such that|S| = | (℘ S)|. This means that there is a bijection f : S → (℘ S). Consider the set D = { x ∈ S | x ∉ f(S) }. Since by construction every x ∈ D satisfies x ∈ S, D ⊆ S, so D (∈ ℘ S).

Since f is a bijection, it is surjective, so there must be some d ∈ S such that f(d) = D. Now, either d ∈ D, or d ∉ D. We consider these cases separately:

Case 1: d ∈ D. By our definition of d, this means that d ∉ f(d). However, we know that f(d) = D, so this means that d ∉ D, contradicting the fact that d ∈ D.

Case 2: d ∉ D. By our definition of d, this means that d ∈ f(d). However, we know that f(d) = D, so this means that d ∈ D, contradicting the fact that d ∉ D.

In either case we reach a contradiction, so our assumption must have been wrong. Thus for every set S, |S| ≠ | (℘ S)|. ■

Page 177: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Lemma: For any set S, |S| ≠ | (℘ S)|.

Proof: By contradiction; assume that there exists a set S such that|S| = | (℘ S)|. This means that there is a bijection f : S → (℘ S). Consider the set D = { x ∈ S | x ∉ f(x) }. Since by construction every x ∈ D satisfies x ∈ S, D ⊆ S, so D (∈ ℘ S).

Since f is a bijection, it is surjective, so there must be some d ∈ S such that f(d) = D. Now, either d ∈ D, or d ∉ D. We consider these cases separately:

Case 1: d ∈ D. By our definition of d, this means that d ∉ f(d). However, we know that f(d) = D, so this means that d ∉ D, contradicting the fact that d ∈ D.

Case 2: d ∉ D. By our definition of d, this means that d ∈ f(d). However, we know that f(d) = D, so this means that d ∈ D, contradicting the fact that d ∉ D.

In either case we reach a contradiction, so our assumption must have been wrong. Thus for every set S, |S| ≠ | (℘ S)|. ■

Page 178: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Lemma: For any set S, |S| ≠ | (℘ S)|.

Proof: By contradiction; assume that there exists a set S such that|S| = | (℘ S)|. This means that there is a bijection f : S → (℘ S). Consider the set D = { x ∈ S | x ∉ f(x) }. Since by construction every x ∈ D satisfies x ∈ S, D ⊆ S, so D (∈ ℘ S).

Since f is a bijection, it is surjective, so there must be some d ∈ S such that f(d) = D. Now, either d ∈ D, or d ∉ D. We consider these cases separately:

Case 1: d ∈ D. By our definition of d, this means that d ∉ f(d). However, we know that f(d) = D, so this means that d ∉ D, contradicting the fact that d ∈ D.

Case 2: d ∉ D. By our definition of d, this means that d ∈ f(d). However, we know that f(d) = D, so this means that d ∈ D, contradicting the fact that d ∉ D.

In either case we reach a contradiction, so our assumption must have been wrong. Thus for every set S, |S| ≠ | (℘ S)|. ■

Page 179: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Lemma: For any set S, |S| ≠ | (℘ S)|.

Proof: By contradiction; assume that there exists a set S such that|S| = | (℘ S)|. This means that there is a bijection f : S → (℘ S). Consider the set D = { x ∈ S | x ∉ f(x) }. Since by construction every x ∈ D satisfies x ∈ S, D ⊆ S, so D (∈ ℘ S).

Since f is a bijection, it is surjective, so there must be some d ∈ S such that f(d) = D. Now, either d ∈ D, or d ∉ D. We consider these cases separately:

Case 1: d ∈ D. By our definition of d, this means that d ∉ f(d). However, we know that f(d) = D, so this means that d ∉ D, contradicting the fact that d ∈ D.

Case 2: d ∉ D. By our definition of d, this means that d ∈ f(d). However, we know that f(d) = D, so this means that d ∈ D, contradicting the fact that d ∉ D.

In either case we reach a contradiction, so our assumption must have been wrong. Thus for every set S, |S| ≠ | (℘ S)|. ■

Page 180: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Lemma: For any set S, |S| ≠ | (℘ S)|.

Proof: By contradiction; assume that there exists a set S such that|S| = | (℘ S)|. This means that there is a bijection f : S → (℘ S). Consider the set D = { x ∈ S | x ∉ f(x) }. Since by construction every x ∈ D satisfies x ∈ S, D ⊆ S, so D (∈ ℘ S).

Since f is a bijection, it is surjective, so there must be some d ∈ S such that f(d) = D. Now, either d ∈ D, or d ∉ D. We consider these cases separately:

Case 1: d ∈ D. By our definition of d, this means that d ∉ f(d). However, we know that f(d) = D, so this means that d ∉ D, contradicting the fact that d ∈ D.

Case 2: d ∉ D. By our definition of d, this means that d ∈ f(d). However, we know that f(d) = D, so this means that d ∈ D, contradicting the fact that d ∉ D.

In either case we reach a contradiction, so our assumption must have been wrong. Thus for every set S, |S| ≠ | (℘ S)|. ■

Page 181: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Lemma: For any set S, |S| ≠ | (℘ S)|.

Proof: By contradiction; assume that there exists a set S such that|S| = | (℘ S)|. This means that there is a bijection f : S → (℘ S). Consider the set D = { x ∈ S | x ∉ f(x) }. Since by construction every x ∈ D satisfies x ∈ S, D ⊆ S, so D (∈ ℘ S).

Since f is a bijection, it is surjective, so there must be some d ∈ S such that f(d) = D. Now, either d ∈ D, or d ∉ D. We consider these cases separately:

Case 1: d ∈ D. By our definition of d, this means that d ∉ f(d). However, we know that f(d) = D, so this means that d ∉ D, contradicting the fact that d ∈ D.

Case 2: d ∉ D. By our definition of d, this means that d ∈ f(d). However, we know that f(d) = D, so this means that d ∈ D, contradicting the fact that d ∉ D.

In either case we reach a contradiction, so our assumption must have been wrong. Thus for every set S, |S| ≠ | (℘ S)|. ■

Page 182: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Lemma: For any set S, |S| ≠ | (℘ S)|.

Proof: By contradiction; assume that there exists a set S such that|S| = | (℘ S)|. This means that there is a bijection f : S → (℘ S). Consider the set D = { x ∈ S | x ∉ f(x) }. Since by construction every x ∈ D satisfies x ∈ S, D ⊆ S, so D (∈ ℘ S).

Since f is a bijection, it is surjective, so there must be some d ∈ S such that f(d) = D. Now, either d ∈ D, or d ∉ D. We consider these cases separately:

Case 1: d ∈ D. By our definition of D, this means that d ∉ f(d). However, we know that f(d) = D, so this means that d ∉ D, contradicting the fact that d ∈ D.

Case 2: d ∉ D. By our definition of d, this means that d ∈ f(d). However, we know that f(d) = D, so this means that d ∈ D, contradicting the fact that d ∉ D.

In either case we reach a contradiction, so our assumption must have been wrong. Thus for every set S, |S| ≠ | (℘ S)|. ■

Page 183: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Lemma: For any set S, |S| ≠ | (℘ S)|.

Proof: By contradiction; assume that there exists a set S such that|S| = | (℘ S)|. This means that there is a bijection f : S → (℘ S). Consider the set D = { x ∈ S | x ∉ f(x) }. Since by construction every x ∈ D satisfies x ∈ S, D ⊆ S, so D (∈ ℘ S).

Since f is a bijection, it is surjective, so there must be some d ∈ S such that f(d) = D. Now, either d ∈ D, or d ∉ D. We consider these cases separately:

Case 1: d ∈ D. By our definition of D, this means that d ∉ f(d). However, we know that f(d) = D, so this means that d ∉ D, contradicting the fact that d ∈ D.

Case 2: d ∉ D. By our definition of d, this means that d ∈ f(d). However, we know that f(d) = D, so this means that d ∈ D, contradicting the fact that d ∉ D.

In either case we reach a contradiction, so our assumption must have been wrong. Thus for every set S, |S| ≠ | (℘ S)|. ■

Page 184: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Lemma: For any set S, |S| ≠ | (℘ S)|.

Proof: By contradiction; assume that there exists a set S such that|S| = | (℘ S)|. This means that there is a bijection f : S → (℘ S). Consider the set D = { x ∈ S | x ∉ f(x) }. Since by construction every x ∈ D satisfies x ∈ S, D ⊆ S, so D (∈ ℘ S).

Since f is a bijection, it is surjective, so there must be some d ∈ S such that f(d) = D. Now, either d ∈ D, or d ∉ D. We consider these cases separately:

Case 1: d ∈ D. By our definition of D, this means that d ∉ f(d). However, we know that f(d) = D, so this means that d ∉ D, contradicting the fact that d ∈ D.

Case 2: d ∉ D. By our definition of D, this means that d ∈ f(d). However, we know that f(d) = D, so this means that d ∈ D, contradicting the fact that d ∉ D.

In either case we reach a contradiction, so our assumption must have been wrong. Thus for every set S, |S| ≠ | (℘ S)|. ■

Page 185: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Lemma: For any set S, |S| ≠ | (℘ S)|.

Proof: By contradiction; assume that there exists a set S such that|S| = | (℘ S)|. This means that there is a bijection f : S → (℘ S). Consider the set D = { x ∈ S | x ∉ f(x) }. Since by construction every x ∈ D satisfies x ∈ S, D ⊆ S, so D (∈ ℘ S).

Since f is a bijection, it is surjective, so there must be some d ∈ S such that f(d) = D. Now, either d ∈ D, or d ∉ D. We consider these cases separately:

Case 1: d ∈ D. By our definition of D, this means that d ∉ f(d). However, we know that f(d) = D, so this means that d ∉ D, contradicting the fact that d ∈ D.

Case 2: d ∉ D. By our definition of D, this means that d ∈ f(d). However, we know that f(d) = D, so this means that d ∈ D, contradicting the fact that d ∉ D.

In either case we reach a contradiction, so our assumption must have been wrong. Thus for every set S, |S| ≠ | (℘ S)|. ■

Page 186: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Lemma: For any set S, |S| ≠ | (℘ S)|.

Proof: By contradiction; assume that there exists a set S such that|S| = | (℘ S)|. This means that there is a bijection f : S → (℘ S). Consider the set D = { x ∈ S | x ∉ f(x) }. Since by construction every x ∈ D satisfies x ∈ S, D ⊆ S, so D (∈ ℘ S).

Since f is a bijection, it is surjective, so there must be some d ∈ S such that f(d) = D. Now, either d ∈ D, or d ∉ D. We consider these cases separately:

Case 1: d ∈ D. By our definition of D, this means that d ∉ f(d). However, we know that f(d) = D, so this means that d ∉ D, contradicting the fact that d ∈ D.

Case 2: d ∉ D. By our definition of D, this means that d ∈ f(d). However, we know that f(d) = D, so this means that d ∈ D, contradicting the fact that d ∉ D.

In either case we reach a contradiction, so our assumption must have been wrong. Thus for every set S, |S| ≠ | (℘ S)|. ■

Page 187: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Lemma: For any set S, |S| ≠ | (℘ S)|.

Proof: By contradiction; assume that there exists a set S such that|S| = | (℘ S)|. This means that there is a bijection f : S → (℘ S). Consider the set D = { x ∈ S | x ∉ f(x) }. Since by construction every x ∈ D satisfies x ∈ S, D ⊆ S, so D (∈ ℘ S).

Since f is a bijection, it is surjective, so there must be some d ∈ S such that f(d) = D. Now, either d ∈ D, or d ∉ D. We consider these cases separately:

Case 1: d ∈ D. By our definition of D, this means that d ∉ f(d). However, we know that f(d) = D, so this means that d ∉ D, contradicting the fact that d ∈ D.

Case 2: d ∉ D. By our definition of D, this means that d ∈ f(d). However, we know that f(d) = D, so this means that d ∈ D, contradicting the fact that d ∉ D.

In either case we reach a contradiction, so our assumption must have been wrong. Thus for every set S, |S| ≠ | (℘ S)|. ■

Page 188: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Lemma: For any set S, |S| ≠ | (℘ S)|.

Proof: By contradiction; assume that there exists a set S such that|S| = | (℘ S)|. This means that there is a bijection f : S → (℘ S). Consider the set D = { x ∈ S | x ∉ f(x) }. Since by construction every x ∈ D satisfies x ∈ S, D ⊆ S, so D (∈ ℘ S).

Since f is a bijection, it is surjective, so there must be some d ∈ S such that f(d) = D. Now, either d ∈ D, or d ∉ D. We consider these cases separately:

Case 1: d ∈ D. By our definition of D, this means that d ∉ f(d). However, we know that f(d) = D, so this means that d ∉ D, contradicting the fact that d ∈ D.

Case 2: d ∉ D. By our definition of D, this means that d ∈ f(d). However, we know that f(d) = D, so this means that d ∈ D, contradicting the fact that d ∉ D.

In either case we reach a contradiction, so our assumption must have been wrong. Thus for every set S, |S| ≠ | (℘ S)|. ■

Page 189: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem (Cantor's Theorem): For any set S, |S| < | (S)|.℘

Proof: Consider any set S. By our first lemma, |S| ≤ |℘(S)|. By our second lemma, |S| ≠ | (℘ S)|. Thus |S| < |℘(S)|. ■

Page 190: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

What This Means

Page 191: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

A Formal Definition of Functions

Page 192: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Formalizing Functions

● Formally, a function f : A → B is a subset of A × B.

● By definition:

f(a) = b iff (a, b) ∈ f● In other words, a function is a relation with the

extra property that

For all a ∈ A, there exists someunique b such that (a, b) ∈ f.

Page 193: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element
Page 194: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element
Page 195: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Mercury

Venus

Earth

Mars

Jupiter

Saturn

Uranus

Neptune

♀☿

♂♃♄♅♆

Page 196: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Mercury

Venus

Earth

Mars

Jupiter

Saturn

Uranus

Neptune

♀☿

♂♃♄♅♆

Page 197: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Front Door

BalconyWindow

BedroomWindow

Page 198: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Front Door

BalconyWindow

BedroomWindow

Page 199: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Inverses

● Given any function f : A → B, the inverse of f is the relation f -1

f -1 = { (b, a) | (a, b) ∈ f }● Equivalently:

f -1 = { (b, a) | f(a) = b }● Note that this is not necessarily a function.

● If f(a0) = b and f(a

1) = b with a

0 ≠ a

1, then f -1(b) is not

uniquely defined.● If there is some b ∈ B with nothing mapping to it, then f -1

is not defined at all.

Page 200: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If f : A → B is a bijection, then f -1 is a function from B to A.

Proof: Let f be a bijection from A to B. Consider the relation f -1. We need to show that for any b ∈ B, there is a unique a ∈ A such that(b, a) ∈ f -1.

We first prove that for any b ∈ B, there is at least one a ∈ A such that(b, a) ∈ f -1. Since f is a bijection, it is surjective, so for any b ∈ B, there is some a ∈ A such that f(a) = b. Since f(a) = b, (b, a) ∈ f -1, as required.

Now, we prove that for any b in B, there is at most one a ∈ A such that (b, a) ∈ f -1. To see this, consider any a

0, a

1 such that (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1. We will prove that a

0 = a

1. Since (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1, we know that f(a

0) = b and f(a

1) = b. Since f is a bijection, f

is injective. Therefore, because f(a0) = f(a

1), we have that a

0 = a

1 as

required.

Thus for any b ∈ B, there is a unique a ∈ A such that (b, a) ∈ f -1. ■

Page 201: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If f : A → B is a bijection, then f -1 is a function from B to A.

Proof: Let f be a bijection from A to B. Consider the relation f -1. We need to show that for any b ∈ B, there is a unique a ∈ A such that(b, a) ∈ f -1.

We first prove that for any b ∈ B, there is at least one a ∈ A such that(b, a) ∈ f -1. Since f is a bijection, it is surjective, so for any b ∈ B, there is some a ∈ A such that f(a) = b. Since f(a) = b, (b, a) ∈ f -1, as required.

Now, we prove that for any b in B, there is at most one a ∈ A such that (b, a) ∈ f -1. To see this, consider any a

0, a

1 such that (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1. We will prove that a

0 = a

1. Since (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1, we know that f(a

0) = b and f(a

1) = b. Since f is a bijection, f

is injective. Therefore, because f(a0) = f(a

1), we have that a

0 = a

1 as

required.

Thus for any b ∈ B, there is a unique a ∈ A such that (b, a) ∈ f -1. ■

Page 202: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If f : A → B is a bijection, then f -1 is a function from B to A.

Proof: Let f be a bijection from A to B. Consider the relation f -1. We need to show that for any b ∈ B, there is a unique a ∈ A such that(b, a) ∈ f -1.

We first prove that for any b ∈ B, there is at least one a ∈ A such that(b, a) ∈ f -1. Since f is a bijection, it is surjective, so for any b ∈ B, there is some a ∈ A such that f(a) = b. Since f(a) = b, (b, a) ∈ f -1, as required.

Now, we prove that for any b in B, there is at most one a ∈ A such that (b, a) ∈ f -1. To see this, consider any a

0, a

1 such that (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1. We will prove that a

0 = a

1. Since (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1, we know that f(a

0) = b and f(a

1) = b. Since f is a bijection, f

is injective. Therefore, because f(a0) = f(a

1), we have that a

0 = a

1 as

required.

Thus for any b ∈ B, there is a unique a ∈ A such that (b, a) ∈ f -1. ■

Page 203: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If f : A → B is a bijection, then f -1 is a function from B to A.

Proof: Let f be a bijection from A to B. Consider the relation f -1. We need to show that for any b ∈ B, there is a unique a ∈ A such that(b, a) ∈ f -1.

We first prove that for any b ∈ B, there is at least one a ∈ A such that(b, a) ∈ f -1. Since f is a bijection, it is surjective, so for any b ∈ B, there is some a ∈ A such that f(a) = b. Since f(a) = b, (b, a) ∈ f -1, as required.

Now, we prove that for any b in B, there is at most one a ∈ A such that (b, a) ∈ f -1. To see this, consider any a

0, a

1 such that (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1. We will prove that a

0 = a

1. Since (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1, we know that f(a

0) = b and f(a

1) = b. Since f is a bijection, f

is injective. Therefore, because f(a0) = f(a

1), we have that a

0 = a

1 as

required.

Thus for any b ∈ B, there is a unique a ∈ A such that (b, a) ∈ f -1. ■

Page 204: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If f : A → B is a bijection, then f -1 is a function from B to A.

Proof: Let f be a bijection from A to B. Consider the relation f -1. We need to show that for any b ∈ B, there is a unique a ∈ A such that(b, a) ∈ f -1.

We first prove that for any b ∈ B, there is at least one a ∈ A such that(b, a) ∈ f -1. Since f is a bijection, it is surjective, so for any b ∈ B, there is some a ∈ A such that f(a) = b. Since f(a) = b, (b, a) ∈ f -1, as required.

Now, we prove that for any b in B, there is at most one a ∈ A such that (b, a) ∈ f -1. To see this, consider any a

0, a

1 such that (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1. We will prove that a

0 = a

1. Since (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1, we know that f(a

0) = b and f(a

1) = b. Since f is a bijection, f

is injective. Therefore, because f(a0) = f(a

1), we have that a

0 = a

1 as

required.

Thus for any b ∈ B, there is a unique a ∈ A such that (b, a) ∈ f -1. ■

Page 205: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If f : A → B is a bijection, then f -1 is a function from B to A.

Proof: Let f be a bijection from A to B. Consider the relation f -1. We need to show that for any b ∈ B, there is a unique a ∈ A such that(b, a) ∈ f -1.

We first prove that for any b ∈ B, there is at least one a ∈ A such that(b, a) ∈ f -1. Since f is a bijection, it is surjective, so for any b ∈ B, there is some a ∈ A such that f(a) = b. Since f(a) = b, (b, a) ∈ f -1, as required.

Now, we prove that for any b in B, there is at most one a ∈ A such that (b, a) ∈ f -1. To see this, consider any a

0, a

1 such that (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1. We will prove that a

0 = a

1. Since (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1, we know that f(a

0) = b and f(a

1) = b. Since f is a bijection, f

is injective. Therefore, because f(a0) = f(a

1), we have that a

0 = a

1 as

required.

Thus for any b ∈ B, there is a unique a ∈ A such that (b, a) ∈ f -1. ■

Page 206: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If f : A → B is a bijection, then f -1 is a function from B to A.

Proof: Let f be a bijection from A to B. Consider the relation f -1. We need to show that for any b ∈ B, there is a unique a ∈ A such that(b, a) ∈ f -1.

We first prove that for any b ∈ B, there is at least one a ∈ A such that(b, a) ∈ f -1. Since f is a bijection, it is surjective, so for any b ∈ B, there is some a ∈ A such that f(a) = b. Since f(a) = b, (b, a) ∈ f -1, as required.

Now, we prove that for any b in B, there is at most one a ∈ A such that (b, a) ∈ f -1. To see this, consider any a

0, a

1 such that (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1. We will prove that a

0 = a

1. Since (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1, we know that f(a

0) = b and f(a

1) = b. Since f is a bijection, f

is injective. Therefore, because f(a0) = f(a

1), we have that a

0 = a

1 as

required.

Thus for any b ∈ B, there is a unique a ∈ A such that (b, a) ∈ f -1. ■

Page 207: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If f : A → B is a bijection, then f -1 is a function from B to A.

Proof: Let f be a bijection from A to B. Consider the relation f -1. We need to show that for any b ∈ B, there is a unique a ∈ A such that(b, a) ∈ f -1.

We first prove that for any b ∈ B, there is at least one a ∈ A such that(b, a) ∈ f -1. Since f is a bijection, it is surjective, so for any b ∈ B, there is some a ∈ A such that f(a) = b. Since f(a) = b, (b, a) ∈ f -1, as required.

Now, we prove that for any b in B, there is at most one a ∈ A such that (b, a) ∈ f -1. To see this, consider any a

0, a

1 such that (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1. We will prove that a

0 = a

1. Since (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1, we know that f(a

0) = b and f(a

1) = b. Since f is a bijection, f

is injective. Therefore, because f(a0) = f(a

1), we have that a

0 = a

1 as

required.

Thus for any b ∈ B, there is a unique a ∈ A such that (b, a) ∈ f -1. ■

Page 208: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If f : A → B is a bijection, then f -1 is a function from B to A.

Proof: Let f be a bijection from A to B. Consider the relation f -1. We need to show that for any b ∈ B, there is a unique a ∈ A such that(b, a) ∈ f -1.

We first prove that for any b ∈ B, there is at least one a ∈ A such that(b, a) ∈ f -1. Since f is a bijection, it is surjective, so for any b ∈ B, there is some a ∈ A such that f(a) = b. Since f(a) = b, (b, a) ∈ f -1, as required.

Now, we prove that for any b in B, there is at most one a ∈ A such that (b, a) ∈ f -1. To see this, consider any a

0, a

1 such that (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1. We will prove that a

0 = a

1. Since (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1, we know that f(a

0) = b and f(a

1) = b. Since f is a bijection, f

is injective. Therefore, because f(a0) = f(a

1), we have that a

0 = a

1 as

required.

Thus for any b ∈ B, there is a unique a ∈ A such that (b, a) ∈ f -1. ■

Page 209: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If f : A → B is a bijection, then f -1 is a function from B to A.

Proof: Let f be a bijection from A to B. Consider the relation f -1. We need to show that for any b ∈ B, there is a unique a ∈ A such that(b, a) ∈ f -1.

We first prove that for any b ∈ B, there is at least one a ∈ A such that(b, a) ∈ f -1. Since f is a bijection, it is surjective, so for any b ∈ B, there is some a ∈ A such that f(a) = b. Since f(a) = b, (b, a) ∈ f -1, as required.

Now, we prove that for any b in B, there is at most one a ∈ A such that (b, a) ∈ f -1. To see this, consider any a

0, a

1 such that (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1. We will prove that a

0 = a

1. Since (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1, we know that f(a

0) = b and f(a

1) = b. Since f is a bijection, f

is injective. Therefore, because f(a0) = f(a

1), we have that a

0 = a

1 as

required.

Thus for any b ∈ B, there is a unique a ∈ A such that (b, a) ∈ f -1. ■

Page 210: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If f : A → B is a bijection, then f -1 is a function from B to A.

Proof: Let f be a bijection from A to B. Consider the relation f -1. We need to show that for any b ∈ B, there is a unique a ∈ A such that(b, a) ∈ f -1.

We first prove that for any b ∈ B, there is at least one a ∈ A such that(b, a) ∈ f -1. Since f is a bijection, it is surjective, so for any b ∈ B, there is some a ∈ A such that f(a) = b. Since f(a) = b, (b, a) ∈ f -1, as required.

Now, we prove that for any b in B, there is at most one a ∈ A such that (b, a) ∈ f -1. To see this, consider any a

0, a

1 such that (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1. We will prove that a

0 = a

1. Since (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1, we know that f(a

0) = b and f(a

1) = b. Since f is a bijection, f

is injective. Therefore, because f(a0) = f(a

1), we have that a

0 = a

1 as

required.

Thus for any b ∈ B, there is a unique a ∈ A such that (b, a) ∈ f -1. ■

Page 211: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If f : A → B is a bijection, then f -1 is a function from B to A.

Proof: Let f be a bijection from A to B. Consider the relation f -1. We need to show that for any b ∈ B, there is a unique a ∈ A such that(b, a) ∈ f -1.

We first prove that for any b ∈ B, there is at least one a ∈ A such that(b, a) ∈ f -1. Since f is a bijection, it is surjective, so for any b ∈ B, there is some a ∈ A such that f(a) = b. Since f(a) = b, (b, a) ∈ f -1, as required.

Now, we prove that for any b in B, there is at most one a ∈ A such that (b, a) ∈ f -1. To see this, consider any a

0, a

1 such that (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1. We will prove that a

0 = a

1. Since (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1, we know that f(a

0) = b and f(a

1) = b. Since f is a bijection, f

is injective. Therefore, because f(a0) = f(a

1), we have that a

0 = a

1 as

required.

Thus for any b ∈ B, there is a unique a ∈ A such that (b, a) ∈ f -1. ■

Page 212: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If f : A → B is a bijection, then f -1 is a function from B to A.

Proof: Let f be a bijection from A to B. Consider the relation f -1. We need to show that for any b ∈ B, there is a unique a ∈ A such that(b, a) ∈ f -1.

We first prove that for any b ∈ B, there is at least one a ∈ A such that(b, a) ∈ f -1. Since f is a bijection, it is surjective, so for any b ∈ B, there is some a ∈ A such that f(a) = b. Since f(a) = b, (b, a) ∈ f -1, as required.

Now, we prove that for any b in B, there is at most one a ∈ A such that (b, a) ∈ f -1. To see this, consider any a

0, a

1 such that (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1. We will prove that a

0 = a

1. Since (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1, we know that f(a

0) = b and f(a

1) = b. Since f is a bijection, f

is injective. Therefore, because f(a0) = f(a

1), we have that a

0 = a

1 as

required.

Thus for any b ∈ B, there is a unique a ∈ A such that (b, a) ∈ f -1. ■

Page 213: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If f : A → B is a bijection, then f -1 is a function from B to A.

Proof: Let f be a bijection from A to B. Consider the relation f -1. We need to show that for any b ∈ B, there is a unique a ∈ A such that(b, a) ∈ f -1.

We first prove that for any b ∈ B, there is at least one a ∈ A such that(b, a) ∈ f -1. Since f is a bijection, it is surjective, so for any b ∈ B, there is some a ∈ A such that f(a) = b. Since f(a) = b, (b, a) ∈ f -1, as required.

Now, we prove that for any b in B, there is at most one a ∈ A such that (b, a) ∈ f -1. To see this, consider any a

0, a

1 such that (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1. We will prove that a

0 = a

1. Since (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1, we know that f(a

0) = b and f(a

1) = b. Since f is a bijection, f

is injective. Therefore, because f(a0) = f(a

1), we have that a

0 = a

1 as

required.

Thus for any b ∈ B, there is a unique a ∈ A such that (b, a) ∈ f -1. ■

Page 214: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Theorem: If f : A → B is a bijection, then f -1 is a function from B to A.

Proof: Let f be a bijection from A to B. Consider the relation f -1. We need to show that for any b ∈ B, there is a unique a ∈ A such that(b, a) ∈ f -1.

We first prove that for any b ∈ B, there is at least one a ∈ A such that(b, a) ∈ f -1. Since f is a bijection, it is surjective, so for any b ∈ B, there is some a ∈ A such that f(a) = b. Since f(a) = b, (b, a) ∈ f -1, as required.

Now, we prove that for any b in B, there is at most one a ∈ A such that (b, a) ∈ f -1. To see this, consider any a

0, a

1 such that (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1. We will prove that a

0 = a

1. Since (b, a

0) ∈ f -1 and

(b, a1) ∈ f -1, we know that f(a

0) = b and f(a

1) = b. Since f is a bijection, f

is injective. Therefore, because f(a0) = f(a

1), we have that a

0 = a

1 as

required.

Thus for any b ∈ B, there is a unique a ∈ A such that (b, a) ∈ f -1. ■

Page 215: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

The Other Direction

● We have just proven that

if f : A → B is a bijection, then f -1 : B → A.

● It can also be shown (fun times!) that

if f -1 : B → A, then f : A → B is a bijection.

● and

if f : A → B is a bijection, then f -1 : B → A is a bijection.

● Using the fact that (f -1)-1 = f, regardless of whether f is a function, we can use this to prove prove

f : A → B is a bijectioniff

f -1 : B → A is a bijection

Page 216: web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1126/lectures/06/Sli… · Defining Functions Typically, we specify a function by describing a rule that maps every element

Next Time

● The Pigeonhole Principle● Particularly pleasing and poignant pigeon-powered

proofs!