A14 · Lesson 2 · Countability
Listing the rationals, and why the reals can't be listed
The rationals are packed everywhere along the number line: between any two reals there are infinitely many. Yet they can be listed one after another, first, second, third, without missing any. The reals can't: every list of real numbers misses most of them. These two facts, both due to Cantor, explain why a computer that works with finitely many numbers can't represent almost any real exactly, why the rationals take up no length at all, and why the completeness of lesson 1 is a genuinely strong property.
- The curves count fractions in (0, 1] with denominator at most N: all of them (repeats like included), and only those in lowest terms, which number about .
- Every rational in (0, 1] shows up once N reaches its denominator, so listing by denominator, then numerator, eventually reaches each one.
- Slide N: the counts grow like , which is fast but finite at every stage. That's what makes the list possible.
Predict
Which of these sets can be listed as a sequence that includes every element?
Only the rationals. The real numbers in [0, 1] and the infinite binary sequences are both uncountable: Cantor's diagonal argument builds, from any proposed list, an element the list misses. The rationals, dense as they are, can be listed by denominator.
Name it
Comparing sizes
Two sets have the same cardinality if there's a bijection between them. A set is countable if it's finite or in bijection with , that is, if its elements can be listed as a sequence. Otherwise it's uncountable.
Countable sets
- The integers: 0, 1, −1, 2, −2, 3, … .
- Pairs of natural numbers: walk the diagonals . The Cantor pairing is a bijection (with 0 counted as natural).
- A countable union of countable sets is countable. So the rationals, the finite strings over any finite alphabet, the polynomials with integer coefficients, and their roots (the algebraic numbers) are all countable.
The reals are uncountable
Diagonal argument. Suppose lists every number in [0, 1], written in binary. Build y by making its k-th digit differ from the k-th digit of . Then y differs from every in at least one digit, so it isn't on the list. (Care is needed with numbers that have two expansions, like , but it doesn't change the conclusion.)
What follows
- Almost every real number is transcendental and irrational: the algebraic numbers and the rationals are countable leftovers.
- Programs are finite strings, so there are countably many; most real numbers can't be computed by any program at all.
- A countable set has length zero: cover its k-th point by an interval of length , total length ε, for any ε > 0 (lesson 46 builds measure on this idea).
- Floating-point formats are finite, so arithmetic on a computer happens on a finite set of rationals.
Worked example
Find the Cantor pairing of (2, 3), and invert the value 18.
Show the solution
- Pair (2, 3).
- Find the diagonal of 18. The largest w with is w = 5, since
- Read off the pair.
- Why it matters. Every natural number comes from exactly one pair, which is what makes countable, and with it the rationals.
Answer , and 18 inverts back to the pair (2, 3).
Worked example
Someone lists infinite binary sequences: , , , . Build a sequence that isn't on the list.
Show the solution
- Take the diagonal digits. The 1st digit of is 0, the 2nd of is 1, the 3rd of is 1, and the 4th of is 0.
- Flip each. y starts 1 0 0 1 … .
- y is not on the list. y differs from in digit 1, from in digit 2, and so on: it can't equal any , because it disagrees with in digit k.
- No list is complete. Since this works for every list, no list contains all binary sequences, and so none contains all the reals in [0, 1].
Answer y = 1 0 0 1 …, the flipped diagonal, differs from every sequence on the list.
Worked example
How many double-precision numbers lie in [1, 2), and what fraction of the reals there do they represent exactly?
Show the solution
- Count the doubles. Doubles in [1, 2) have the form in binary, so there are of them. That's a lot, but finite.
- Compare with the reals. The reals in [1, 2) are uncountable, and even the rationals there are infinite, so the doubles represent a fraction zero of them: a randomly chosen real is never exactly a double.
- What it means in practice. Everything a computer calculates is an approximation from a finite set, which is why error analysis (A13) matters.
Answer there are doubles in [1, 2), a fraction zero of the reals there.
Check
What is the Cantor pairing ?
Check
Invert the Cantor pairing: which (m, n) has = 25?
(a)
What is n?
(b)
What is m?
Check
The integers are listed as 0, 1, −1, 2, −2, 3, −3, … . In what position is −10, counting 0 as position 1?
Check
How many binary strings have length at most 16 (counting the empty string)?
Check
A format has p = 24 significant bits. How many of its numbers lie in [1, 2)?
Check
The rationals in [0, 1] are listed, and the k-th is covered by an interval of length . How long is the interval around the 10th one?
Check
Which of these sets is uncountable?
Check
The Cantor pairing walks the diagonals m + n = 0, 1, 2, … in order.
Step 1
How many pairs lie on the diagonals before diagonal w?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
So what position (counting from 0) does (m, n) get, if pairs on a diagonal are ordered by n?
Explain why
Why doesn't the diagonal argument also prove the rationals uncountable?
Applied to a list of all rationals in [0, 1], the diagonal construction does produce a number y that differs from every listed number. But nothing makes y rational: its digits are chosen one at a time to dodge the list, so they need not repeat, and a number whose expansion never repeats is irrational. The argument shows only that the list misses some real number. For the reals that's a contradiction, since the list was supposed to contain every real; for the rationals it's no contradiction at all, because the missed number lies outside the set being listed.
Practice
Keep practicing
8 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.