Analysis – Counting the rationals

September 18, 2013

It is easy to see that to show that \mathbb Q is countable, it suffices to show the countability of \mathbb Q^+, or even of \mathbb Q\cap(0,1].


There is a straightforward way of enumerating the latter: First list the fractions with denominator 1, then those with denominator 2 (skipping those already listed), then those with denominator 3 (again, skipping repetitions), etc. This list begins

\displaystyle \frac11;\frac12;\frac13,\frac23;\frac14,\frac34;\frac15,\frac25,\frac35,\frac45;\dots

Cantor’s  first proof of the uncountability of the reals (the nested intervals argument) from 1874 proceeds as follows:

Given any (injective) sequence a_1,a_2,\dots of reals, we want to exhibit a real that was not listed. There are two cases: Either there are i\ne j with a_i<a_j, and such that there is no k with a_k\in(a_i,a_j), in which case we are obviously done, or (more interestingly), whenever a_i<a_j, we can find an a_k strictly in between (the range of the sequence is dense in itself). Assume we are in this situation.

Define two sequences b_1,b_2,\dots and c_1,c_2,\dots as follows:

  • First, b_1=a_1 and c_1=a_2.
  • For definiteness, suppose that a_1>a_2. The other case is treated similarly. Let b_2 be a_i, where i is least such that a_i\in(c_1,b_1). Then define c_2 as a_j, where j is least such that a_j\in(c_1,b_2).
  • In general, given c_n<b_n, we define b_{n+1} as a_k, where k is least such that a_k\in(c_n,b_n), and then define c_{n+1} as a_m, where m is least such that a_m\in(c_n,b_{n+1}). Note that these sequences are well defined, because of our density assumption.

The construction just described ensures that if I_n=[c_n,b_n], then:

  1. For any n, we have that a_n\notin I_{n+1}, and
  2. The intervals are nested and decreasing: I_1\supsetneq I_2\supsetneq I_3\dots

It follows (from the completeness of the reals) that \bigcap_n I_n\ne\emptyset, and (from 1.) that any real in this intersection is not in the range of the sequence a_1,a_2,\dots

It turns out that if we carry out Cantor’s construction when the sequence of a_i is the enumeration of the rationals in (0,1] we began with, then \bigcap_n I_n=\{1/\phi\}, where \phi is the golden ratio.

This is proved in the nice note

Mike Krebs, and Thomas Wright. On Cantor’s first uncountability proof, Pick’s theorem, and the irrationality of the golden ratio, Amer. Math. Monthly, 117 (7),  (2010), 633–637. MR2681523 (2011e:11127).


There is a very nice enumeration of \mathbb Q^+ with combinatorial significance.

Binary trees

The rationals are used to label the nodes of the infinite complete binary tree, and the resulting enumeration simply follows the nodes of the tree, lexicographically.

Calkin-WilfWe begin by putting 1/1 at the root of the tree. Once a node has been labelled m/n, its left successor is labelled m/(m+n), and its right successor is latex (m+n)/n.

And that’s all! The list so produced begins

\displaystyle \frac11;\frac12,\frac21;\frac13,\frac32,\frac23,\frac31;\dots

The proof that this is indeed a bijective listing of \mathbb Q^+ is remarkably simple; one verifies in order the following claims:

  1. The numerator and denominator of any of the assigned fractions are relative prime.
  2. Every positive rational is assigned to some node.
  3. Every positive rational is assigned to some node.

For this, one proceeds by induction. For example, if there is a fraction m/n not in reduced form, and used as a label, pick such a fraction appearing in as small a level as  possible, and note that the fraction cannot be 1/1. A contradiction is now attained by noting that \mathrm{gcd}(m,n)=\mathrm{gcd}(m-n,n)=\mathrm{gcd}(m,n-m).

Similarly, if m/n appears in more than one node, then m\ne n, and its immediate predecessor (either (m-n)/n or m/(n-m), depending on whether m>n or m<n) must also appear more than once.

Finally, if some fraction is not listed, we can choose its denominator n least among the denominators of all skipped fractions, and then choose its numerator m least among the numerators of all skipped fractions with denominator n. A contradiction follows because m\ne n, and if m>n, then (m-n)/n must also have been skipped, but m-n<m, while if m<n, then m/(n-m) must have been skipped, but n-m<n.

This enumeration is due to Neil Calkin and Herbert Wilf, who also showed that it has the following nice combinatorial properties:

  1. There is a sequence b(0),b(1),b(2),\dots of positive integers such that the n-th fraction in the enumeration is just \displaystyle \frac{b(n)}{b(n+1)} (in reduced form). In particular, the denominator of a fraction is the numerator of its successor in the enumeration. So b(0)=1, b(1)=1, b(2)=2, b(3)=1, b(4)=3, b(5)=2, b(6)=3, etc.
  2. In fact, b(n) is precisely the number of ways of writing n as a sum of powers of 2, where each power can be used at most twice. For example, b(6)=3, because we can write 6 as 2^2+2^1, as 2^2+2^0+2^0, or as 2^1+2^1+2^0+2^0.

This is proved in the nice note

Neil J. Calkin, and Herbert S. Wilf. Recounting the rationals, Amer. Math. Monthly, 107 (4), (2000), 360–363. MR1763062 (2001d:11024).

Some natural questions:

  1. What can we say about the real(s) that comes out when the procedure from Cantor’s proof from section I is applied to this enumeration?
  2. Any infinite path through the binary tree defines a sequence of rationals. What reals appear as limit points of these sequences?

Analysis – Some remarks on continued fractions

September 18, 2013

Most introductory books on number theory have at least one section on the theory of continued fractions. I suggest

William Stein. Elementary number theory: primes, congruences, and secrets. A computational approach.  Undergraduate Texts in Mathematics, Springer, New York, 2009. MR2464052 (2009i:11002).

downloadable from his webpage. Chapter 5 is on continued fractions. Of interest to us is the proof that for any integer a_0 and any infinite sequence of positive integers a_1,a_2,\dots the corresponding continued fraction \displaystyle {}[a_0;a_1,a_2,\dots]=a_0+\frac1{a_1+\frac1{a_2+\dots}} converges to an irrational number. This gives us an explicit bijection between the space of irrationals \mathbb R\setminus\mathbb Q and Baire space, \mathbb N^{\mathbb N}. The bijection is actually a homeomorphism, so the two spaces are equal, as topological spaces. This was first noted by Baire, in

René Baire. Sur la représentation des fonctions discontinues. Deuxième partie, Acta Math. 32 (1), (1909), 97–176. MR1555048.

For a very nice alternative proof of the homeomorphism that does not involve continued fractions, see Chapter 1 of

Arnold W. Miller. Descriptive set theory and forcing. How to prove theorems about Borel sets the hard way. Lecture Notes in Logic, 4. Springer-Verlag, Berlin, 1995.MR1439251 (98g:03119).

Arnie’s homeomorphism also has the nice feature of being an explicit order preserving bijection between \mathbb Z^{\mathbb N}, ordered lexicographically, and the set of irrationals.

In William’s book, you may also want to look at section 5.4, where a proof is provided of Euler’s theorem from 1737 that the continued fraction of e is given by


(No such nice pattern is known for \pi.)

A few nice additional results on continued fractions, with references, are given in this blog entry.

A fascinating open problem, due to Zaremba from 1972, is discussed in

Alex Kontorovich. From Apollonius to Zaremba: local-global phenomena in thin orbits. Bull. Amer. Math. Soc. (N.S.), 50 (2), (2013), 187–228. MR3020826.

To state the problem, fix a positive integer n, and consider the set

\displaystyle N_n=\{m\mid \mbox{ there is an }r\mbox{ such that }1\le r\le m, \displaystyle \mathrm{gcd}(m,r)=1,\mbox{ and if }\frac mr=[a_0;a_1,\dots,a_k], \displaystyle \mbox{ then }a_i\le n\mbox{ for all }i\le k\}.

For example, N_1 consists of all numerators appearing in finite continued fractions consisting solely of ones: {}[1],[1;1],[1;1,1],[1;1,1,1],\dots, that is, \displaystyle 1,2,\frac32,\frac53,\frac85,\dots, so N_1 is the set of positive Fibonacci numbers.

Zaremba’s conjecture is that N_5=\mathbb N^+. In fact, much more is expected to be true. For example, Hensley conjectured in 1996 that N_2 contains all positive integers, with finitely many exceptions. The best result to date is that N_{50} contains almost all positive integers, in the sense that

\displaystyle \lim_{n\to\infty}\frac{N_{50}\cap[1,n]}n=1.

For this, see the announcement,

Jean Bourgain, and Alex Kontorovich. On Zaremba’s conjecture, C. R. Math. Acad. Sci. Paris, 349 (9-10), (2011), 493–495. MR2802911 (2012e:11012),

and the preprint

Jean Bourgain, and Alex Kontorovich. On Zaremba’s conjecture. ArXiv:1107.3776.

(Of immediate interest to us is the fact described in Kontorovich’s survey that for n\ge2, the set of infinite continued fractions


where 1\le a_i\le n for all i is a Cantor set.)