Cite

This course has no released version yet: the text at this address may change. Cite a released version when one exists.

/courses/countability/countable-sets
@misc{countability-countable-sets,
  title = {{Countable sets}},
  howpublished = {Lesson 3 of \emph{Countability and diagonalization}, Computability Theory course notes},
  url = {/courses/countability/countable-sets},
  note = {Unreleased working version}
}

To cite a single statement, use the # link that appears next to its heading.

Lesson 3 of 6

Countable sets

Characterizations of countable sets; subsets of ℕ; products, unions, finite strings, rationals and algebraic numbers.

40 min6 questions
Countability and diagonalization · lesson 3 of 6
  1. Equipotence and subpotence
  2. The Cantor–Bernstein theorem
  3. Countable sets
  4. The diagonal argument
  5. The cardinality of the continuum
  6. Diagonalization and computation

A set is countable when its elements can be listed in a sequence indexed by integers. Countable sets are the natural setting of computation: inputs, outputs and programs are finite objects, and there are countably many of them. This lesson characterizes countable sets in several equivalent ways and shows that the sets built from integers by finite means — pairs, tuples, finite sequences, finite sets, rational and algebraic numbers — are all countable. The few uses of the axiom of choice are signaled explicitly.

3.1 Definition and characterizations

Definition 3.1.#

A set AA is countably infinite if ∣A∣=∣N∣|A| = |\nat|. It is countable if it is finite or countably infinite, and uncountable otherwise.

A bijection e:N→Ae : \nat \to A is an enumeration without repetition of AA, and is often written as a sequence a0,a1,a2,…a_0, a_1, a_2, \dots with an=e(n)a_n = e(n). The basic fact behind all characterizations is that the subsets of N\nat are countable.

Lemma 3.2.#

Every infinite set S⊆NS \subseteq \nat is countably infinite. More precisely, the principal function pS:N→Sp_S : \nat \to S defined by

pS(0)=min⁡S,pS(n+1)=min⁡{s∈S:s>pS(n)}p_S(0) = \min S, \qquad p_S(n+1) = \min \{ s \in S : s > p_S(n) \}

is a strictly increasing bijection, which enumerates SS in increasing order.

Proof of Lemma 3.2.

The minima exist. Indeed S≠∅S \neq \emptyset; and if SS had no element greater than pS(n)p_S(n), then S⊆pS(n)+1‾S \subseteq \underline{p_S(n) + 1} would be finite, as a subset of a finite set (Exercise 1.15). By construction pSp_S is strictly increasing, hence injective, and by induction pS(n)≥np_S(n) \geq n for all nn.

For surjectivity, let s∈Ss \in S. The values pS(0)<pS(1)<…p_S(0) < p_S(1) < \dots are unbounded since pS(n)≥np_S(n) \geq n, so there is a least nn with pS(n)≥sp_S(n) \geq s. If n=0n = 0, then s≥min⁡S=pS(0)s \geq \min S = p_S(0) gives s=pS(0)s = p_S(0). If n>0n > 0, then pS(n−1)<s≤pS(n)p_S(n-1) < s \leq p_S(n), and pS(n)p_S(n) is by definition the least element of SS above pS(n−1)p_S(n-1), so pS(n)≤sp_S(n) \leq s, hence s=pS(n)s = p_S(n).

Proposition 3.3.#

For every set AA, the following are equivalent.

  1. AA is countable.
  2. ∣A∣≤∣N∣|A| \leq |\nat|: there is an injection from AA into N\nat.
  3. A=∅A = \emptyset, or there is a surjection from N\nat onto AA.
Proof of Proposition 3.3.

(1 ⇒ 2) A bijection with n‾⊆N\underline n \subseteq \nat or with N\nat is an injection into N\nat.

(2 ⇒ 3) Suppose A≠∅A \neq \emptyset, fix a0∈Aa_0 \in A, and let i:A→Ni : A \to \nat be an injection. Define s:N→As : \nat \to A by s(n)=as(n) = a if n=i(a)n = i(a), which determines aa uniquely, and s(n)=a0s(n) = a_0 if n∉i(A)n \notin i(A). Then s(i(a))=as(i(a)) = a for every aa, so ss is surjective.

(3 ⇒ 2) The empty set injects into N\nat. If s:N→As : \nat \to A is surjective, then ∣A∣≤∣N∣|A| \leq |\nat| by Proposition 1.13: the injection sends aa to the least nn with s(n)=as(n) = a.

(2 ⇒ 1) If i:A→Ni : A \to \nat is injective, then AA is equipotent to S=i(A)⊆NS = i(A) \subseteq \nat. If SS is finite, so is AA. Otherwise SS is countably infinite by Lemma 3.2, and so is AA.

Characterization 3 is the one used most often: a non-empty set is countable when it can be listed as a0,a1,a2,…a_0, a_1, a_2, \dots, repetitions allowed. Removing the repetitions is done by the proof, by keeping only the first occurrence of each element.

Corollary 3.4.#
  1. Every subset of a countable set is countable.
  2. The image of a countable set under any function is countable.
Proof of Corollary 3.4.
  1. If B⊆AB \subseteq A and i:A→Ni : A \to \nat is injective, the restriction of ii to BB is injective.
  2. Let ff be a function defined on a countable set AA. If A=∅A = \emptyset, then f(A)=∅f(A) = \emptyset. Otherwise, if s:N→As : \nat \to A is surjective, then f∘sf \circ s is a surjection from N\nat onto f(A)f(A).

3.2 The smallest infinity

Proposition 3.5.#

Every infinite set AA satisfies ∣N∣≤∣A∣|\nat| \leq |A|.

Proof of Proposition 3.5.

We define an injection a:N→Aa : \nat \to A by induction. Pick a0∈Aa_0 \in A, which exists since ∅\emptyset is finite. Having chosen pairwise distinct a0,…,ana_0, \dots, a_n, the set {a0,…,an}\{a_0, \dots, a_n\} is finite, so it is not AA; pick an+1∈A∖{a0,…,an}a_{n+1} \in A \setminus \{a_0, \dots, a_n\}. The elements ana_n are pairwise distinct by construction.

This proof makes infinitely many arbitrary choices, one at each step, each depending on the previous ones. It uses the axiom of dependent choice, a weak form of the axiom of choice, and cannot be carried out in ZF alone: it is consistent with ZF that some infinite set of real numbers has no countably infinite subset (we admit this result of Cohen; a proof is in Jech’s monograph on the axiom of choice). When AA comes with an injection into N\nat or with a linear order in which every non-empty subset has a least element, one can take an+1a_{n+1} to be the least element of A∖{a0,…,an}A \setminus \{a_0, \dots, a_n\}, and no choice is needed; this is what Lemma 3.2 does.

Corollary 3.6.#

An infinite set is countable if and only if it is equipotent to each of its infinite subsets.

Proof of Corollary 3.6.

If AA is countably infinite and B⊆AB \subseteq A is infinite, then BB is countable by Corollary 3.4, and infinite, so ∣B∣=∣N∣=∣A∣|B| = |\nat| = |A|. Conversely, if AA is infinite and equipotent to each of its infinite subsets, then by Proposition 3.5 it has a subset a(N)a(\nat) equipotent to N\nat, and ∣A∣=∣a(N)∣=∣N∣|A| = |a(\nat)| = |\nat|.

3.3 Pairs and tuples

Proposition 3.7.#

The set N×N\nat \times \nat is countably infinite. An explicit bijection is Cantor’s pairing function

⟨x,y⟩=(x+y)(x+y+1)2+y.\langle x, y \rangle = \frac{(x+y)(x+y+1)}{2} + y.

xy001122334401234567891011121314

The pairs (x,y)(x, y) with x+y≤4x + y \leq 4, labeled by ⟨x,y⟩\langle x, y \rangle. The enumeration follows each diagonal upwards, then jumps to the next diagonal.
Proof of Proposition 3.7.

List the pairs diagonal by diagonal: first those with x+y=0x + y = 0, then those with x+y=1x + y = 1, and so on, each diagonal in order of increasing yy:

(0,0), (1,0), (0,1), (2,0), (1,1), (0,2), (3,0), …(0,0),\ (1,0),\ (0,1),\ (2,0),\ (1,1),\ (0,2),\ (3,0),\ \dots

The diagonal x+y=kx + y = k contains the k+1k + 1 pairs (k,0),(k−1,1),…,(0,k)(k, 0), (k-1, 1), \dots, (0, k), so the diagonals before it contain 1+2+⋯+k=k(k+1)/21 + 2 + \dots + k = k(k+1)/2 pairs, and (x,y)(x, y) is at position k(k+1)/2+yk(k+1)/2 + y with k=x+yk = x + y. Every pair lies on exactly one diagonal and appears once on it, so the listing is a bijection between N×N\nat \times \nat and N\nat, and the position of (x,y)(x, y) is ⟨x,y⟩\langle x, y \rangle.

The function and its inverses are studied as computable functions in the course on models of computation (Proposition 1.4 of “Algorithms and partial functions”).

Corollary 3.8.#
  1. If AA and BB are countable, so is A×BA \times B.
  2. For every k≥1k \geq 1, Nk\nat^k is countably infinite.
Proof of Corollary 3.8.
  1. If i:A→Ni : A \to \nat and j:B→Nj : B \to \nat are injections, then (a,b)↦⟨i(a),j(b)⟩(a, b) \mapsto \langle i(a), j(b) \rangle is an injection of A×BA \times B into N\nat.
  2. By induction on kk, identifying Nk+1\nat^{k+1} with Nk×N\nat^k \times \nat; the set is infinite since N\nat injects into it.

Explicitly, a bijection Nk→N\nat^k \to \nat is obtained by iterating the pairing function: ⟨x1,…,xk+1⟩=⟨⟨x1,…,xk⟩,xk+1⟩\langle x_1, \dots, x_{k+1} \rangle = \langle \langle x_1, \dots, x_k \rangle, x_{k+1} \rangle.

Example 3.9.#
  1. Z\mathbb Z is countably infinite: z↦2zz \mapsto 2z for z≥0z \geq 0 and z↦−2z−1z \mapsto -2z - 1 for z<0z < 0 is a bijection Z→N\mathbb Z \to \nat.
  2. Q\mathbb Q is countably infinite. The map (p,q)↦p/(q+1)(p, q) \mapsto p/(q+1) is a surjection from Z×N\mathbb Z \times \nat, a countable set by the corollary, onto Q\mathbb Q, so Q\mathbb Q is countable by Corollary 3.4; it is infinite since it contains N\nat.

3.4 Unions

Proposition 3.10.#

Let (An)n∈N(A_n)_{n \in \nat} be a sequence of sets, and let (sn)n∈N(s_n)_{n \in \nat} be a sequence of functions such that each sn:N→Ans_n : \nat \to A_n is surjective. Then ⋃nAn\bigcup_n A_n is countable. In particular, a finite union of countable sets is countable.

The map ⟨n,m⟩↦sn(m)\langle n, m \rangle \mapsto s_n(m) is a surjection from N\nat onto ⋃nAn\bigcup_n A_n: every element of AnA_n is some sn(m)s_n(m). For a finite union A0∪⋯∪AkA_0 \cup \dots \cup A_k of non-empty countable sets, fix surjections s0,…,sks_0, \dots, s_k and let An=AkA_n = A_k and sn=sks_n = s_k for n>kn > k, which does not change the union; the empty sets can be discarded beforehand.

The hypothesis provides the enumerations sns_n along with the sets. The statement “a countable union of countable sets is countable”, without given enumerations, requires choosing one enumeration of each AnA_n among infinitely many possibilities. It is a consequence of the axiom of countable choice, and it is not provable in ZF: Feferman and Lévy showed that it is consistent with ZF that R\mathbb R is a countable union of countable sets. We admit this result. In practice, as in the examples below, the sets come with natural enumerations, and the proposition applies directly.

3.5 Finite strings and finite sets

An alphabet is a set Σ\Sigma, whose elements are called letters. A string of length kk over Σ\Sigma is a finite sequence w=a1a2⋯akw = a_1 a_2 \cdots a_k of letters, that is, a function {1,…,k}→Σ\{1, \dots, k\} \to \Sigma; the string of length 00 is the empty string ε\varepsilon. The set of strings over Σ\Sigma is written Σ∗\Sigma^*.

Proposition 3.11.#

If Σ\Sigma is countable, then Σ∗\Sigma^* is countable. It is countably infinite if Σ≠∅\Sigma \neq \emptyset.

Let i:Σ→Ni : \Sigma \to \nat be an injection, and p1=2,p2=3,p3=5,…p_1 = 2, p_2 = 3, p_3 = 5, \dots the primes. The map

a1a2⋯ak  ↦  p1 i(a1)+1 p2 i(a2)+1⋯pk i(ak)+1a_1 a_2 \cdots a_k \;\mapsto\; p_1^{\,i(a_1) + 1}\, p_2^{\,i(a_2) + 1} \cdots p_k^{\,i(a_k) + 1}

sends ε\varepsilon to 11 and is injective by uniqueness of prime factorization: the code determines kk, as the number of its distinct prime factors, and each i(aj)i(a_j), hence each aja_j. If a∈Σa \in \Sigma, the strings a,aa,aaa,…a, aa, aaa, \dots are pairwise distinct, so Σ∗\Sigma^* is infinite.

The exponents are shifted by one so that the code determines the length: without the shift, strings of letters aa with i(a)=0i(a) = 0 would all be coded by 11.

Corollary 3.12.#

The set Pfin(N)\mathcal P_{\mathrm{fin}}(\nat) of finite subsets of N\nat is countably infinite. An explicit bijection with N\nat is F↦∑n∈F2nF \mapsto \sum_{n \in F} 2^n.

Proof of Corollary 3.12.

Every integer has a unique binary expansion, and a finite set FF is exactly the set of positions of the digits 11 in the binary expansion of ∑n∈F2n\sum_{n \in F} 2^n.

Example 3.13.#

A real number is algebraic if it is a root of a non-zero polynomial with integer coefficients. The set of real algebraic numbers is countable. Indeed, a polynomial c0+c1X+⋯+cdXdc_0 + c_1 X + \dots + c_d X^d is determined by the string c0c1⋯cdc_0 c_1 \cdots c_d over the countable alphabet Z\mathbb Z, so there is a surjection n↦Pnn \mapsto P_n from N\nat onto the non-zero polynomials, by Proposition 3.11. A non-zero polynomial PnP_n has at most deg⁡Pn\deg P_n real roots; list them in increasing order as rn,0<⋯<rn,k−1r_{n,0} < \dots < r_{n,k-1}, and let rn,m=rn,k−1r_{n,m} = r_{n,k-1} for m≥km \geq k (if PnP_n has no real root, let rn,m=0r_{n,m} = 0, which is algebraic). Then ⟨n,m⟩↦rn,m\langle n, m \rangle \mapsto r_{n,m} is a surjection onto the real algebraic numbers. The ordering of the roots replaces an arbitrary choice of enumeration of each finite set of roots.

The computational consequence of Proposition 3.11 is the starting point of the last lesson: programs, in any programming language, are strings over a finite alphabet, so there are countably many of them, and countably many computable functions.

3.6 Exercises

Exercise 3.14 ★.

Let s:N→As : \nat \to A be a surjection onto an infinite set AA. Construct an explicit bijection between N\nat and AA, without appealing to Proposition 3.5.

Solution

Let S={n:s(n)≠s(m) for all m<n}S = \{ n : s(n) \neq s(m) \text{ for all } m < n \} be the set of positions of first occurrences. The restriction of ss to SS is a bijection from SS onto AA: it is surjective, since each a∈Aa \in A has a least nn with s(n)=as(n) = a, and this nn is in SS; it is injective, since two first occurrences of the same element would be equal. SS is infinite since AA is. So s∘pS:N→As \circ p_S : \nat \to A is a bijection, where pSp_S is the principal function of Lemma 3.2.

Exercise 3.15 ★.

Show that the set of eventually periodic sequences X:N→{0,1}X : \nat \to \{0, 1\} is countable. (A sequence is eventually periodic if there are n0n_0 and p≥1p \geq 1 such that X(n+p)=X(n)X(n + p) = X(n) for all n≥n0n \geq n_0.)

Solution

An eventually periodic sequence is determined by two strings uu and vv over {0,1}\{0, 1\}, with vv non-empty: its first n0n_0 values uu, followed by vv repeated forever. So there is a surjection from a subset of {0,1}∗×{0,1}∗\{0, 1\}^* \times \{0, 1\}^*, which is countable by Proposition 3.11 and Corollary 3.8, onto the set of eventually periodic sequences, which is therefore countable by Corollary 3.4.

Exercise 3.16 ★★.#

Show that a set AA is infinite if and only if it is equipotent to a proper subset of itself. Which direction uses the axiom of choice?

Solution

If AA is finite, it is not equipotent to a proper subset, by Corollary 1.10. Conversely, if AA is infinite, let a:N→Aa : \nat \to A be an injection, given by Proposition 3.5. The map hh defined by h(an)=an+1h(a_n) = a_{n+1} and h(x)=xh(x) = x for x∉a(N)x \notin a(\nat) is a bijection from AA onto A∖{a0}A \setminus \{a_0\}. Only the second direction uses choice, through Proposition 3.5.

Exercise 3.17 ★★.

A real number is transcendental if it is not algebraic. Show that every non-empty open interval contains a transcendental number, admitting that intervals are uncountable (this is proved in the next lessons).

Solution

An open interval (a,b)(a, b) with a<ba < b is uncountable, while the algebraic numbers form a countable set by Example 3.13. If (a,b)(a, b) contained only algebraic numbers, it would be countable, by Corollary 3.4.

3.7 Notes and references

The countability of the algebraic numbers is the first result of Cantor’s paper of 1874, which also proves, by a different argument than the diagonal one, that the real numbers are not countable; together, the two results give a new proof of the existence of transcendental numbers, first established by Liouville in 1844. The consistency of ”R\mathbb R is a countable union of countable sets” with ZF is due to Feferman and Lévy (1963); a proof is in Jech’s monograph on the axiom of choice.

  • G. Cantor, Über eine Eigenschaft des Inbegriffes aller reellen algebraischen Zahlen, Journal für die reine und angewandte Mathematik 77 (1874), 258–262.
  • T. Jech, The Axiom of Choice, North-Holland, 1973.
  • K. Hrbacek and T. Jech, Introduction to Set Theory, 3rd edition, Marcel Dekker, 1999.