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
A set is countably infinite if . It is countable if it is finite or countably infinite, and uncountable otherwise.
A bijection is an enumeration without repetition of , and is often written as a sequence with . The basic fact behind all characterizations is that the subsets of are countable.
Every infinite set is countably infinite. More precisely, the principal function defined by
is a strictly increasing bijection, which enumerates in increasing order.
The minima exist. Indeed ; and if had no element greater than , then would be finite, as a subset of a finite set (Exercise 1.15). By construction is strictly increasing, hence injective, and by induction for all .
For surjectivity, let . The values are unbounded since , so there is a least with . If , then gives . If , then , and is by definition the least element of above , so , hence .
For every set , the following are equivalent.
- is countable.
- : there is an injection from into .
- , or there is a surjection from onto .
(1 ⇒ 2) A bijection with or with is an injection into .
(2 ⇒ 3) Suppose , fix , and let be an injection. Define by if , which determines uniquely, and if . Then for every , so is surjective.
(3 ⇒ 2) The empty set injects into . If is surjective, then by Proposition 1.13: the injection sends to the least with .
(2 ⇒ 1) If is injective, then is equipotent to . If is finite, so is . Otherwise is countably infinite by Lemma 3.2, and so is .
Characterization 3 is the one used most often: a non-empty set is countable when it can be listed as , repetitions allowed. Removing the repetitions is done by the proof, by keeping only the first occurrence of each element.
- Every subset of a countable set is countable.
- The image of a countable set under any function is countable.
- If and is injective, the restriction of to is injective.
- Let be a function defined on a countable set . If , then . Otherwise, if is surjective, then is a surjection from onto .
3.2 The smallest infinity
Every infinite set satisfies .
We define an injection by induction. Pick , which exists since is finite. Having chosen pairwise distinct , the set is finite, so it is not ; pick . The elements 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 comes with an injection into or with a linear order in which every non-empty subset has a least element, one can take to be the least element of , and no choice is needed; this is what Lemma 3.2 does.
An infinite set is countable if and only if it is equipotent to each of its infinite subsets.
If is countably infinite and is infinite, then is countable by Corollary 3.4, and infinite, so . Conversely, if is infinite and equipotent to each of its infinite subsets, then by Proposition 3.5 it has a subset equipotent to , and .
3.3 Pairs and tuples
The set is countably infinite. An explicit bijection is Cantor’s pairing function
List the pairs diagonal by diagonal: first those with , then those with , and so on, each diagonal in order of increasing :
The diagonal contains the pairs , so the diagonals before it contain pairs, and is at position with . Every pair lies on exactly one diagonal and appears once on it, so the listing is a bijection between and , and the position of is .
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”).
- If and are countable, so is .
- For every , is countably infinite.
- If and are injections, then is an injection of into .
- By induction on , identifying with ; the set is infinite since injects into it.
Explicitly, a bijection is obtained by iterating the pairing function: .
- is countably infinite: for and for is a bijection .
- is countably infinite. The map is a surjection from , a countable set by the corollary, onto , so is countable by Corollary 3.4; it is infinite since it contains .
3.4 Unions
Let be a sequence of sets, and let be a sequence of functions such that each is surjective. Then is countable. In particular, a finite union of countable sets is countable.
The map is a surjection from onto : every element of is some . For a finite union of non-empty countable sets, fix surjections and let and for , which does not change the union; the empty sets can be discarded beforehand.
The hypothesis provides the enumerations along with the sets. The statement “a countable union of countable sets is countable”, without given enumerations, requires choosing one enumeration of each 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 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 , whose elements are called letters. A string of length over is a finite sequence of letters, that is, a function ; the string of length is the empty string . The set of strings over is written .
If is countable, then is countable. It is countably infinite if .
Let be an injection, and the primes. The map
sends to and is injective by uniqueness of prime factorization: the code determines , as the number of its distinct prime factors, and each , hence each . If , the strings are pairwise distinct, so is infinite.
The exponents are shifted by one so that the code determines the length: without the shift, strings of letters with would all be coded by .
The set of finite subsets of is countably infinite. An explicit bijection with is .
Every integer has a unique binary expansion, and a finite set is exactly the set of positions of the digits in the binary expansion of .
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 is determined by the string over the countable alphabet , so there is a surjection from onto the non-zero polynomials, by Proposition 3.11. A non-zero polynomial has at most real roots; list them in increasing order as , and let for (if has no real root, let , which is algebraic). Then 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
Let be a surjection onto an infinite set . Construct an explicit bijection between and , without appealing to Proposition 3.5.
Solution
Let be the set of positions of first occurrences. The restriction of to is a bijection from onto : it is surjective, since each has a least with , and this is in ; it is injective, since two first occurrences of the same element would be equal. is infinite since is. So is a bijection, where is the principal function of Lemma 3.2.
Show that the set of eventually periodic sequences is countable. (A sequence is eventually periodic if there are and such that for all .)
Solution
An eventually periodic sequence is determined by two strings and over , with non-empty: its first values , followed by repeated forever. So there is a surjection from a subset of , 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.
Show that a set is infinite if and only if it is equipotent to a proper subset of itself. Which direction uses the axiom of choice?
Solution
If is finite, it is not equipotent to a proper subset, by Corollary 1.10. Conversely, if is infinite, let be an injection, given by Proposition 3.5. The map defined by and for is a bijection from onto . Only the second direction uses choice, through Proposition 3.5.
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 with is uncountable, while the algebraic numbers form a countable set by Example 3.13. If 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 ” 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.