Discrete Mathematics for Computer Scientists -- Lecture Notes on the Hilbert HotelDIT980, HT 2015
Home | Schedule | Assignments | Exercises | Exam | AboutFire | Forum | TimeEdit | Links | 2014
Lecture Notes on the Hilbert Hotel


A good introduction to the Hilbert Hotel is given by this video:

Hilbert's Infinite Hotel on YouTube


What does this have to do with discrete mathematics and computer science?

A natural question that comes up when dealing with infinite sets such as ℕ, ℤ, ℤ+, ℚ, ℝ, all even numbers, 𝕊 (the set of strings): do they all have the same size? Are some of these sets larger than others?

What we learned in the lecture is what you can do if you want to compare the size of two things that are too large to count. Similar to this scene from "5 myror är fler än 4 elefanter":

Comparing who has more balls when you cannot count to 4

What we can do to compare the size of two sets A and B, even if they are really large, is to try to pair up every element in A with exactly one element in B, such that every element in B is paired up with exactly one element in A. (In other words, to find a bijection between A and B.) If we can do this, then A and B have the same size!

We found out that the following sets all have the same size:

  1. the natural numbers ℕ and the even natural numbers. (The bijection is f(n) = 2n.)

  2. the natural numbers ℕ and the odd natural numbers. (The bijection is f(n) = 2n+1.)

  3. the natural numbers ℕ and the strings 𝕊. (We showed this by fitting all strings into the Hilbert hotel.)
This is perhaps surprising. For example, ℕ contains numbers that are not even, but there are as many even numbers as natural numbers.


One question we managed to answer in the lecture was this one:

Can all functions f : ℕ -> ℕ be implemented a program P, such that P computes f?

The answer is NO.

Why? Because we are going to show that there are more functions ℕ -> ℕ than there are programs. Therefore, there must be functions that do not have a corresponding program that implements them.

Step 1: The number of programs is the same as the number of strings. This is easy to see, because a program can be seen as a body of text, which is just a string.

Step 2: There are as many strings as natural numbers. We can see that this is the case by fitting all strings in the Hilbert Hotel. (First all strings of length 0, then all strings of length 1, then of length 2, etc.)

Step 3: There are way more functions ℕ -> ℕ than natural numbers. We show this by showing that the functions ℕ -> ℕ do not fit in the Hilbert Hotel:

Suppose all functions ℕ -> ℕ fit into the Hilbert Hotel. That means that each room (with number n) contains a function fn : ℕ -> ℕ, and for any function g : ℕ -> ℕ, there exists a room number n such that g = fn.

This cannot be the case! Look at the following function h:

h : ℕ -> ℕ
h(n) = fn(n)+1

The function h is a fine function ℕ -> ℕ, but it cannot be in any of the rooms! For any room numer n, we have that h(n) = fn(n)+1 /= fn(n), and thus we have h /= fn.

In other words, our assumption (that "all functions ℕ -> ℕ do fit into the Hilbert Hotel") was wrong, and indeed they don't fit. There must be more functions ℕ -> ℕ than natural numbers.


In this way, we learnt that there are limitations to what kind of things we can implement in a computer as a program. There are functions ℕ -> ℕ that we can define, but we cannot write programs that implement them!