# Continued fractions and strange homeomorphisms.

Usually one thinks of real numbers represented by a sequence (possibly infinite) of numbers between 0 and 9. For example

$$34,140414\dots$$

One can use various bases like binary, hexadesimal, but the most common is decimal, although with the growing trend of computer science the other bases also gain popularity. It is clear what a finite such string means. Say 1,2 is one and one fifth. The infite sequence is a little bit harder, but is conveniently defined as the sum of an infinite series. For example 1,212121… is

$$1\cdot 1+2\cdot 10^{-1}+1\cdot 10^{-2}+2\cdot 10^{-3}+\dots$$

This sum always converges because it is dominated by a geometric series (exercise), but there is one tiny problem. Namely now

$$1 = 0,999\dots,$$

This problem is unavoidable by going from one base to another. In binary representation we have

$$1 = 0,111\dots.$$

The representation is not unique. It suggests a question:

Is there a way to represent real numbers in a unique way?

and
Why should we limit ourselves to some finite list of numbers (like 0…9)?

The answer is continued fractions. There are several articles on them in Wikipedia, but I didn’t find any (satisfactory) proof of Theorem 1 below.

A continued fraction is a sequence (finite or not) of positive natural numbers which represents uniquely a positive real number. Moreover this sequence is finite if and only if it represents a rational number. I will now expose the basic theory of continued fractions and in the end I’ll show how to use them to construct a homeomorphism between $$(\mathbb{R}\setminus \mathbb{Q})$$ and $$(\mathbb{R}\setminus \mathbb{Q})^n$$ for any $$n$$.

From now on in this post I call positive natural numbers (1,2,3,…) just numbers and real numbers just reals.

So, what is a continued fraction? Given a sequence of numbers of length four

$$a=(a_0,a_1,a_2,a_3)$$

let

$$r(a)=a_0+\frac{1}{a_1+\frac{1}{a_2+\frac{1}{a_3}}}.$$

Then $$r(a)$$ is a real whose continued fraction is $$a$$. This real is often denoted by

$$[a_0;a_1,a_2,a_3].$$

More generally, let us define a continued fraction of length $$k$$ by induction. Let $$a$$ be a finite sequence of numbers of length $$k$$. The first element of the sequence can be zero, but not others. If $$k=1$$, then $$a=(a_0)$$ and we put $$r(a)=a_0$$. Suppose $$r(a)$$ is defined for sequences of length $$k$$ and let $$a$$ be a sequence of length $$k+1$$. Let

$$b=(a_1,\dots,a_{k})$$,

so $$b$$ is $$a$$ without the first number, $$a_0$$. Now define

$$r(a)=a_0+\frac{1}{r(b)}$$.

Note that $$r(b)$$ is defined by the induction hypothesis.

Suppose now that we have an infinite sequence $$a=(a_0,a_1,\dots)$$. What is $$r(a)$$? We simply define it as the limit

$$r(a)=\lim_{n\to \infty}r(a\restriction n),$$

where $$a\restriction n=(a_0,\dots,a_{n-1})$$ is the initial subsequence of $$a$$ of length $$n$$.

(A) Every continued fraction represents a real.

Theorem 1 For any sequence $$a$$ of positive natural numbers the limit
$$r(a)=\lim_{n\to \infty}r(a\restriction n)$$ exists.

This theorem is not trivial, because if one substitutes “number” by “complex number”, it is not any more true. The following proof is a product of a discussion with Daisuke Ikegami. I found also some proof on the web, but I didn’t understand it.

Proof. Suppose an infinite sequence $$a=(a_0,a_1,a_2,\dots)$$ is given. Denote by $$s_n$$ the “$$n$$:th partial continued fraction,”
$$s_n=r(a\restriction n)$$
Next we have to be tricky with the “when the denominator gets bigger the ratio gets smaller”. Using this we get

(1) $$s_1\leqslant s_3\leqslant s_5\leqslant\cdots$$
(2) $$s_2\ge s_4\ge s_6\ge\cdots$$
(3) for any $$n,\,s_{2n}\ge s_{2n+1}$$

To show this, define for each number $$n$$ a function $$f_n\colon \mathbb{R_+}\to\mathbb{R}$$ such that for every $$x$$

$$f_n(x)=r(a_0,\dots,a_{n-1},x),$$

i.e. replace the last item of the continued fraction by $$x$$. For convention $$f_0(x)=x$$. Note that $$f_n(x)=r(a_0,\dots,a_{n-1}+\frac{1}{x})=f_{n-1}(a_{n-1}+\frac{1}{x})$$. It is now easy to see that $$f_0$$ is increasing and if $$f_n$$ is increasing, then $$f_{n+1}$$ is decreasing and vice versa. Now moving from $$s_3$$ to $$s_5$$ corresponds to replacing $$a_3$$ by the larger number

$$a_3+\frac{1}{a_4+\frac{1}{a_5}}$$

and because $$f_4$$ is increasing, we get $$s_3\leqslant s_5$$. Similarly for any odd $$n$$, $$s_n\leqslant s_{n+2}$$. The same argument works for (2) and (3). Now the Calculus Student notices that we have two bounded monotone sequences $$(s_{2n+1})$$ and $$(s_{2n})$$, so both converge. We have to show that they converge to the same value. For that it is enough to show that $$s_{2n}-s_{2n+1}$$ approaches zero. Let us prove a stronger statement by induction on $$n$$: whenever $$(b_0,\dots,b_{n-1})$$ is any sequence of numbers and $$k$$ is any number, then

$$|r(b_0,\dots,b_{n-1})-r(b_0,\dots,b_{n-1},k)|<\frac{1}{n}$$.

I call this property continuity and will come back to it later. Continuity clearly implies $$s_{2n}-s_{2n+1}\leqslant\frac{1}{n}$$. For n=1 our claim is

$$|b_0-(b_0+\frac{1}{k})|=|\frac{1}{k}|\leqslant 1.$$

Suppose the claim holds for sequences of length n and consider

$$|r(b_0,\dots,b_{n-1},b_{n})-r(b_0,\dots,b_{n-1},b_{n},k)|$$

$$=|b_0+\frac{1}{r(b_1,\dots,b_{n-1},b_{n})}-(b_0+\frac{1}{r(b_1,\dots,b_{n-1},b_{n},k)}|$$

Denote $$t=r(b_1,\dots,b_{n-1},b_{n})$$ and $$s=r(b_1,\dots,b_{n-1},b_{n},k)$$. By the induction hypothesis $$|s-t|\leqslant\frac{1}{n}$$ and because numbers are positive natural numbers, we have $$s,t\ge 1$$. Denote $$v=\min\{s,t\}$$. Continuing the above:

$$= |\frac{1}{s}-\frac{1}{t}|<|\frac{1}{v}-\frac{1}{v+\frac{1}{n}}| = |\frac{1}{nv(v+\frac{1}{n})}|\leqslant |\frac{1}{n+1}|.$$

In the first inequality above we use the fact that $$x\mapsto x^{-1}$$ is decreasing and if $$s<t$$, then $$(s+\frac{1}{n})$$ is further to the right from $$s$$ than $$t$$ and if $$t<s$$ the same for $$t+\frac{1}{n}$$. In the last inequality we use that $$v\ge 1$$. This completes the proof. $$\square$$

(B) Every real is represented by a continued fraction

Let $$x$$ be a positive real. Define $$x_0=x$$ and $$a_0$$ to be the integer part of it, i.e. the largest integer smaller than $$x_0$$. Then define $$x_{n+1}=\frac{1}{x_n-a_n}$$ and let $$a_{n+1}$$ be the integer part of $$x_{n+1}$$. For rational number $$x$$ this process terminates after finitely many steps: it is easy to see that the reduced denominator of $$x_{n+1}$$ is strictly smaller than that of $$x_n$$, and so $$x_n$$ is an integer for some $$n$$. On the other hand if $$a$$ is a finite sequence, then clearly r(a) is rational.

To see that this continued fraction represents $$x$$ and not some other real number, show by induction that

$$x=r(a_0,\dots,a_n,x_{n+1})$$

whence by the continuity argument in the proof of Theorem 1 we have

$$x-r(a_0,\dots,a_n) = |r(a_0,\dots,a_n,x_{n+1})-r(a_0,\dots,a_n)| \leqslant \frac{1}{n}.$$

(C) Uniqueness

Let us now verify that every real is represented by a unique continued fraction. This is simple. Suppose we have two continued fractions such that $$r(a_0,\dots,a_n) = r(b_0,\dots,b_n)$$. They are of the form $$a_0+\varepsilon$$ and $$b_0+\varepsilon'$$. Since both epsilons are between zero and one, we conclude $$a_0=b_0$$. Continuing this we get $$a_n=b_n$$ by induction.

Homeomorphisms

Let us denote by $$\mathcal{N}$$ the space of all infinite sequences of natural numbers and by $$\mathcal{N}^*$$ the space of all countable (finite and infinite) sequences of natural numbers. By the above (A), (B) and (C), the function $$r$$ which assignes a real to a sequence in $$\mathcal{N}^*$$ is a bijection. Let us define a topology on $$\mathcal{N}^*$$ as follows. For any finite sequence $$s\in\mathcal{N}^*$$ let $$U_s$$ consist of all sequences $$t$$ which begin with $$s$$, i.e.$$t\restriction n=s$$, where $$n$$ is the length of $$s$$ and $$t\restriction n$$ means the initial subsequence of $$t$$ of length $$n$$. The sets $$U_s$$ form a basis for a topology. Thus the basic neighbourhoods of a point $$x\in \mathcal{N}^*$$ are the sets $$U_{x\restriction n}$$. Now from the property that I called continuity in the proof of Theorem 1 it follows that both $$r$$ and $$r^{-1}$$ are continuous with respect to that topology: for the former one for any $$\varepsilon$$ take $$n$$ such that $$\frac{1}{n}$$ is less than $$\varepsilon$$ and the corresponding neighbourhood; for latter, for a neightbourhood of the form $$U_{x\restriction n}$$ take $$\delta$$ to be something less than $$\frac{1}{n}$$.

Hence the space $$\mathcal{N}^*$$ is homeomorphic to the real numbers. Since the infinite sequences are presicely those who get mapped to the irrational numbers, the space $$\mathcal{N}$$ is homeomorphic to the space of irrational numbers $$\mathbb{R}\setminus\mathcal{Q}$$.

Now let us define a map $$f\colon\mathcal{N}\to \mathcal{N}\times \mathcal{N}$$ such that a sequence $$(a_n)_{n=0}^\infty$$ gets mapped to the pair of sequences given by $$\langle (a_{2n})_{n=0}^\infty,(a_{2n+1})_{n=0}^\infty\rangle$$. This is a homeomorphism (exercise) and so provides a homeomorphism between $$(\mathbb{R}\setminus \mathbb{Q})$$ and $$(\mathbb{R}\setminus \mathbb{Q})^2$$.

There is also a homeomorphism between the space of irrational numbers and the space of sequences of irrational numbers:

The space $$\mathcal{N}$$ is in fact precisely the space of all functions from $$\mathbb{N}$$ to $$\mathbb{N}$$ equipped with the standard product topology.
Denote by $$A^B$$ the space of all functions from $$A$$ to $$B$$. So we have $$\mathcal{N}=\mathbb{N}^{\mathbb{N}}$$. But we all know that there is a bijection $$p\colon \mathbb{N}\times \mathbb{N}\to \mathbb{N}$$. Using this bijection we obtain a homeomorphism between the space $$\mathbb{N}^{\mathbb{N}\times\mathbb{N}}$$ and $$\mathcal{N}$$. (The homeomorphism being $$f\mapsto p\circ f$$) On the other hand each function $$f\colon \mathbb{N}\times \mathbb{N}\to \mathbb{N}$$ can be thought as a sequence of functions: for each $$n,\,f(n,\cdot)\colon \mathbb{N}\to \mathbb{N}$$. This gives

$$\mathbb{N}^{\mathbb{N}\times \mathbb{N}}=(\mathbb{N}^{\mathbb{N}})^{\mathbb{N}}.$$

So we get that the space of irrational numbers is homeomorphic to the space of all sequences of irrational numbers.

These techniques are central in descriptive set theory, and is used in particular to show the proper growth of the Borel hierarchy and that there are Analytic non-Borel sets.

Exercise (a) Using continued fractions define a surjective continuous map from the unit interval to the unit square. (b) Is it possible that such a map is differentiable at every point?

For details see this
This entry was posted in Calculus, Mathematics, Topology. Bookmark the permalink.

### 8 Responses to Continued fractions and strange homeomorphisms.

1. Anonymous says:

In aleksandrovs book ” introduction to topology and set theory”(not sure about the precise name ) there is much easier proof that N^N=irrational reals, but you probably know that

anyway thanks for the post, this is interesting

Alex Nuija

Using binary representation of reals? It is some time since I read that book. Note that my proof also gives that R is homeomorphic to N^{\le N}

2. Anonymous says:

” f_3 is increasing ”

tupo, should be decreasing

thanks. I guess it should be f_4

3. Anonymous says:

Using binary representation of reals? ”

no, since its topology its much more elegent :P
not sure though