A logbook for curious waters
← All Reckonings

The Daily Reckoning

Can You List Every Infinite String of Zeros and Ones?

Assume every endless binary sequence has been numbered. One diagonal walk then constructs a sequence that the list must have missed.

Difficulty
Intermediate
Area
Logic and foundations
Reading time
9 minutes
Prerequisites
Sets and functions · One-to-one correspondence · Proof by contradiction
A luminous diagonal cuts across an endless dark blueprint table of zeros and ones. Along the diagonal, cyan digits flip into magenta digits that stream beyond the table's boundary.

Suppose someone claims to have numbered every endless sequence made from 00s and 11s:

s1,s2,s3,…s_1, s_2, s_3,\ldots

You cannot inspect the whole list. Each row is infinite, and there are infinitely many rows. Yet one precise construction can prove that the list is incomplete.

The construction does not search for a gap. It manufactures a new sequence designed to disagree with row 11, row 22, row 33, and every later row.

Escape along the diagonal

The diagram below shows the first six rows and first six positions of an imagined list. Move through its four stages. The highlighted diagonal takes one bit from each row; flipping those bits produces the escape sequence.

Step-through proof

Build the sequence that the list cannot contain

Step 1: Pretend these rows begin a complete list of every infinite binary sequence.

rowbit 1bit 2bit 3bit 4bit 5bit 6…
s1010011…
s2110100…
s3000110…
s4101101…
s5011001…
s6100110…
d101011…
d vs. s1differs at bit 1
d vs. s2differs at bit 2
d vs. s3differs at bit 3
d vs. s4differs at bit 4
d vs. s5differs at bit 5
d vs. s6differs at bit 6
Step 1 of 4
What to notice: the six visible rows are only examples. In the imagined infinite table, the constructed row d has its ith bit chosen to disagree with row i, so every row is ruled out at a named position. The finite display illustrates the rule; the proof uses every natural-numbered row.

The six-row display is only a window into an infinite argument. If the proposed list continues through every positive integer, the diagonal rule continues with it. Row 10,00010{,}000 is defeated at bit 10,00010{,}000.

The claim, stated precisely

Let BB be the set of all infinite binary sequences. An element of BB has the form

(b1,b2,b3,…),bj∈{0,1}.(b_1,b_2,b_3,\ldots),\qquad b_j\in\{0,1\}.

Here, bjb_j is the bit in position jj. A set is countable if its elements can be placed in a finite list or in a list indexed by the positive integers 1,2,3,…1,2,3,\ldots. Equivalently, an infinite set is countable when there is a one-to-one correspondence between that set and the positive integers.

Cantor’s diagonal claim: the set BB is uncountable. No sequence

s1,s2,s3,…s_1,s_2,s_3,\ldots

can contain every element of BB.

To prove the claim, assume the opposite. Suppose a complete list exists. Write the bit in row ii and position jj as sijs_{ij}, so row ii is

si=(si1,si2,si3,…).s_i=(s_{i1},s_{i2},s_{i3},\ldots).

Now define a new infinite sequence

d=(d1,d2,d3,…)d=(d_1,d_2,d_3,\ldots)

by the rule

di=1−sii.d_i=1-s_{ii}.

The symbol siis_{ii} means the bit where row ii meets position ii: a diagonal entry. Because each bit is either 00 or 11, subtracting it from 11 flips it.

For every positive integer ii,

di≠sii.d_i\ne s_{ii}.

Therefore dd differs from sis_i in at least position ii. It follows that

d≠sid\ne s_i

for every row ii. The supposedly complete list omits dd, contradicting the assumption that the list contains every infinite binary sequence. Thus BB is uncountable.

The proof does not depend on the entries chosen for the proposed list. Give the list any order and any rows; the same rule builds a sequence outside it.

Worked example: defeating six named rows

Consider the visible prefixes

123456s1010011s2110100s3000110s4101101s5011001s6100110\begin{array}{c|cccccc} &1&2&3&4&5&6\\ \hline s_1&0&1&0&0&1&1\\ s_2&1&1&0&1&0&0\\ s_3&0&0&0&1&1&0\\ s_4&1&0&1&1&0&1\\ s_5&0&1&1&0&0&1\\ s_6&1&0&0&1&1&0 \end{array}

Read the diagonal from upper left to lower right:

(s11,s22,s33,s44,s55,s66)=(0,1,0,1,0,0).(s_{11},s_{22},s_{33},s_{44},s_{55},s_{66})=(0,1,0,1,0,0).

Flip every diagonal bit:

(d1,d2,d3,d4,d5,d6)=(1,0,1,0,1,1).(d_1,d_2,d_3,d_4,d_5,d_6)=(1,0,1,0,1,1).

Now compare deliberately, not visually:

  1. dd differs from s1s_1 at bit 11: 1≠01\ne0.
  2. dd differs from s2s_2 at bit 22: 0≠10\ne1.
  3. dd differs from s3s_3 at bit 33: 1≠01\ne0.
  4. dd differs from s4s_4 at bit 44: 0≠10\ne1.
  5. dd differs from s5s_5 at bit 55: 1≠01\ne0.
  6. dd differs from s6s_6 at bit 66: 1≠01\ne0.

The displayed prefix already rules out the six displayed rows. In the full proof, the same comparison rules out every row of the infinite list.

Why finite strings behave differently

Every finite binary string can be listed. Group the strings by length, then use dictionary order within each group:

ε;0,1;00,01,10,11;000,001,010,…\varepsilon;\quad 0,1;\quad 00,01,10,11;\quad 000,001,010,\ldots

The symbol ε\varepsilon denotes the empty string, whose length is zero. Every finite string has some finite length nn, so it appears in the finite block containing all 2n2^n strings of length nn.

Infinite sequences have no final length block. The diagonal construction exploits one new position for each proposed row. “Made from only two symbols” does not imply “countable.”

Try the diagonal rule

Problem 1

An imagined list begins with these four rows:

1234s10110s21100s31010s40111\begin{array}{c|cccc} &1&2&3&4\\ \hline s_1&0&1&1&0\\ s_2&1&1&0&0\\ s_3&1&0&1&0\\ s_4&0&1&1&1 \end{array}

Find the first four bits of the diagonal escape sequence dd. State which position proves that dd differs from each displayed row.

Reveal the solution

The diagonal is

(s11,s22,s33,s44)=(0,1,1,1).(s_{11},s_{22},s_{33},s_{44})=(0,1,1,1).

Flip those four bits:

(d1,d2,d3,d4)=(1,0,0,0).(d_1,d_2,d_3,d_4)=(1,0,0,0).

The first bit separates dd from s1s_1, the second bit separates dd from s2s_2, the third bit separates dd from s3s_3, and the fourth bit separates dd from s4s_4.

Problem 2

Explain why the set of all computer programs written in a fixed programming language is countable, even when programs may be arbitrarily long.

Reveal the solution

A program is a finite string over a finite alphabet of characters. List every one-character string, then every two-character string, then every three-character string, continuing by length. Discard strings that are not syntactically valid programs.

Removing invalid strings leaves a list that still contains every valid program. Therefore the set of programs in the language is countable.

From trigonometric series to different infinities

Georg Cantor did not begin by trying to rank infinities. At the University of Halle, Eduard Heine asked him to study when a function has a unique representation as a trigonometric series. Exceptional sets of points forced Cantor to decide when two infinite collections should count as the same size. The University of St Andrews biography of Cantor traces that path from analysis into set theory.

In 1873 Cantor showed that the rational and algebraic numbers are countable. His 1874 paper gave his first proof that the real numbers are not countable. The short diagonal proof came later, in the 1891 paper Über eine elementare Frage der Mannigfaltigkeitslehre (“On an elementary question of the theory of manifolds”). Cantor phrased the argument with two-valued functions—the same structure as infinite binary sequences.

The surrounding mathematical culture was not uniformly welcoming. Leopold Kronecker rejected Cantor’s treatment of completed infinities, and his editorial influence delayed Cantor’s 1877 work on dimension until Richard Dedekind intervened. Cantor nevertheless helped found the German Mathematical Society in 1890 and chaired its first meeting in Halle in 1891. The dispute was not only personal: it exposed a divide over which infinite objects mathematics was entitled to treat as completed wholes.

What the diagonal unlocks

Each infinite binary sequence identifies a subset of the positive integers: include ii in the subset exactly when bit ii equals 11. The lesson’s proof therefore shows that the power set of the positive integers—the set of all their subsets—is larger than the positive integers themselves. Cantor’s general theorem goes further: for every set AA, its power set P(A)\mathcal P(A) has strictly greater cardinality than AA.

The contrast with programs has a sharp consequence. Programs are finite strings, so there are only countably many programs. Infinite binary sequences are uncountable. Most infinite binary sequences therefore cannot be produced, bit by bit, by any program. This is a counting statement, not a practical complaint about slow computers.

A close relative of diagonal reasoning also marks the limits of automated analysis. In his 1936 paper “On Computable Numbers, with an Application to the Entscheidungsproblem”, Alan Turing encoded machines and showed that no general procedure can settle every question of whether a machine will continue computing. Modern tools can prove termination for many particular programs, but no sound algorithm can decide termination correctly for every possible program and input.

One idea to remember

To defeat a purported complete list, do not search it. Build one object whose iith feature is chosen to disagree with the iith entry. One disagreement per row is enough to escape them all.

To continue, compare this construction with Gödel’s limits on formal proof or study Cantor’s theorem for arbitrary power sets.

Sources