Counting infinity

Why the rationals can be numbered

Numbering pairs of integers

The starting point is the enumeration of N2\mathbb{N}^2 along successive diagonals. We first go through the pairs whose coordinates sum to 00, then 11, then 22, and so on. Each diagonal contains only finitely many pairs, so the traversal reaches every pair in finite time.

Diagonal i+ji + j Pairs visited Ranks assigned
00 (0,0)(0,0) 00
11 (0,1)(0,1), (1,0)(1,0) 11, 22
22 (0,2)(0,2), (1,1)(1,1), (2,0)(2,0) 33, 44, 55
33 (0,3)(0,3), (1,2)(1,2), (2,1)(2,1), (3,0)(3,0) 66 to 99

Cantor's pairing formula gives the rank explicitly:

π(i,j)=(i+j)(i+j+1)2+i\pi(i, j) = \frac{(i + j)(i + j + 1)}{2} + i

It is a bijection from N2\mathbb{N}^2 onto N\mathbb{N}: N2\mathbb{N}^2 is countable.

Q\mathbb{Q} is countable

Every strictly positive rational can be written uniquely as pq\dfrac{p}{q} in lowest terms, with pp and qq coprime strictly positive integers. The map

pq⟼(p,q)\frac{p}{q} \longmapsto (p, q)

is therefore an injection from Q+∗\mathbb{Q}_+^* into N2\mathbb{N}^2, which is countable. Since an infinite subset of a countable set is countable, so is Q+∗\mathbb{Q}_+^*.

We conclude by putting the pieces together: Q\mathbb{Q} is the union of Q+∗\mathbb{Q}_+^*, Q−∗\mathbb{Q}_-^* and {0}\{0\}, hence a finite union of countable sets — it is countable.

A concrete enumeration

The positive rationals can also be enumerated by increasing height, where the height is the sum p+qp + q of the reduced form, ordering by increasing numerator for equal heights:

11, 12, 21, 13, 31, 14, 23, 32, 41, …\frac{1}{1},\ \frac{1}{2},\ \frac{2}{1},\ \frac{1}{3},\ \frac{3}{1},\ \frac{1}{4},\ \frac{2}{3},\ \frac{3}{2},\ \frac{4}{1},\ \ldots

Fractions not in lowest terms, such as 22\dfrac{2}{2}, are skipped to avoid repetitions. Since each height gives only finitely many fractions, every rational eventually appears, exactly once.

Algebraic numbers too

The same argument goes further than you might think. An algebraic number is a root of a nonzero polynomial with integer coefficients. Now, for a fixed degree nn and a fixed bound HH, there are only finitely many polynomials with integer coefficients bounded by HH, each having at most nn roots.

The set of algebraic numbers is therefore a countable union of finite sets: it is countable. This remark, combined with the next chapter, will produce a spectacular result.

Classic pitfall

Proposing as an enumeration of Q+∗\mathbb{Q}_+^* the traversal "first all the 1q\dfrac{1}{q}, then all the 2q\dfrac{2}{q}, and so on." This list never finishes the first row, so it never reaches 21\dfrac{2}{1}: it is not an enumeration. A proper bijection must assign every element a finite rank, which is guaranteed by cutting into finite slices — diagonals or heights.