A142 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

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 pq in (0, 1] with denominator at most N: all of them (repeats like 24 included), and only those in lowest terms, which number about 3N2π2.
  • 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 N2, 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 a1,a2,a3,… that includes every element?

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 m+n=0,1,2,…. The Cantor pairing π(m,n)=(m+n)(m+n+1)2+n is a bijection ℕ2→ℕ (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 x1,x2,… lists every number in [0, 1], written in binary. Build y by making its k-th digit differ from the k-th digit of xk. Then y differs from every xk in at least one digit, so it isn't on the list. (Care is needed with numbers that have two expansions, like 0.0111…=0.1000…, 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 ε/2k, 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
  1. Pair (2, 3). π(2,3)=5×62+3=18
  2. Find the diagonal of 18. The largest w with w(w+1)2≤18 is w = 5, since 15≤18<21
  3. Read off the pair. n=18−15=3m=w−n=2
  4. Why it matters. Every natural number comes from exactly one pair, which is what makes ℕ×ℕ countable, and with it the rationals.

Answer π(2,3)=18, and 18 inverts back to the pair (2, 3).

Worked example

Someone lists infinite binary sequences: x1=0101…, x2=1100…, x3=0011…, x4=1110…. Build a sequence that isn't on the list.

Show the solution
  1. Take the diagonal digits. The 1st digit of x1 is 0, the 2nd of x2 is 1, the 3rd of x3 is 1, and the 4th of x4 is 0.
  2. Flip each. y starts 1 0 0 1 … .
  3. y is not on the list. y differs from x1 in digit 1, from x2 in digit 2, and so on: it can't equal any xk, because it disagrees with xk in digit k.
  4. 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
  1. Count the doubles. Doubles in [1, 2) have the form 1.b1b2…b52 in binary, so there are 252≈4.5×1015 of them. That's a lot, but finite.
  2. 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.
  3. 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 252≈4.5×1015 doubles in [1, 2), a fraction zero of the reals there.

Check

What is the Cantor pairing π(2,3)?

Check

Invert the Cantor pairing: which (m, n) has π(m,n) = 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 0.01/2k. 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°.

Explain why

Why doesn't the diagonal argument also prove the rationals uncountable?

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.