Lecture 18: Continued Fractions II: Infinite Continued Fractions

William Stein

Math 124 Harvard University Fall 2001

1 The Continued Fraction Algorithm

Let x ∈ ℝ and write

x = a_{0} + t_{0}

with a_{0} ∈ ℤ and 0 ≤ t_{0} < 1. If t_{0} ≠ 0, write

\frac{1}{t_{0}} = a_{1} + t_{1}

with a_{1} ∈ ℕ and 0 ≤ t_{1} < 1. Thus t_{0} = \frac{1}{a_{1}+t_{1}} = [0, a_{1} + t_{1}], which is a (nonintegral) continued fraction expansion of t_{0}. Continue in this manner so long as t_{n} ≠ 0 writing

\frac{1}{t_{n}} = a_{n+1} + t_{n+1}

with a_{n+1} ∈ ℕ and 0 ≤ t_{n+1} < 1. This process, which associates to a real number x the sequence of integers a_{0}, a_{1}, a_{2}, …, is called the continued fraction algorithm. Example 1.1. Let x = \frac{8}{3}. Then x = 2+ \frac{2}{3}, so a_{0} = 2 and t_{0} = \frac{2}{3}. Then \frac{1}{t_{0}} = \frac{3}{2} = 1+ \frac{1}{2}, so a_{1} = 1 and t_{1} = \frac{1}{2}. Then \frac{1}{t_{1}} = 2, so a_{2} = 2, t_{2} = 0, and the sequence terminates. Notice that

\frac{8}{3} = [2, 1, 2],

so the continued fraction algorithm produces the continued fraction of \frac{8}{3}.

Proposition 1.2. For every n such that a_{n} is defined, we have

x = [a_{0}, a_{1}, …, a_{n} + t_{n}],

and if t_{n} ≠ 0 then x = [a_{0}, a_{1}, …, a_{n}, \frac{1}{t_{n}}].

Proof. Use induction. The statements are both true when n = 0. If the second statement is true for n − 1, then

x = [a_{0}, a_{1}, …, a_{n−1}, \frac{1}{t_{n−1}} ] = [a_{0}, a_{1}, …, a_{n−1}, a_{n} + t_{n}] = [a_{0}, a_{1}, …, a_{n−1}, a_{n}, \frac{1}{t_{n}}].

Similarly, the first statement is true for n if it is true for n − 1.

Example 1.3. Let x = \frac{1+\sqrt{5}}{2}. Then

x = 1 + \frac{−1 + \sqrt{5}}{2},

so a_{0} = 1 and t_{0} = \frac{−1+\sqrt{5}}{2}. We have

\frac{1}{t_{0}} = \frac{2}{−1 + \sqrt{5}} = \frac{−2 − 2\sqrt{5}}{−4} = \frac{1 + \sqrt{5}}{2}

so again a_{1} = 1 and t_{1} = \frac{−1+\sqrt{5}}{2}. Likewise, a_{n} = 1 for all n. Does the following crazy-looking equality makes sense??

\frac{1 + \sqrt{5}}{2} = 1 + \frac{1}{1 + _{\frac{1}{1+_{\frac{1}{1+ \frac{1}{1+ \frac{1}{1+···}}}}}}}

Example 1.4. Next suppose x = e. Then

a_{0}, a_{1}, a_{2}, … = 2, 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, 1, 1, …

? contfrac(exp(1))
%1 = [2, 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, 1, 1, 10, 1, 1,
       12, 1, 1, 14, 1, 1, 16, 1, 1, 18, 1, 1, 20, 2]
? \\ to get more terms, increase the real precision:
? \p60
? contfrac(exp(1),[])
%12 = [2, 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, 1, 1, 10, 1, 1,
   12, 1, 1, 14, 1, 1, 16, 1, 1, 18, 1, 1, 20, 1, 1, 22, 1,
   1, 24, 1, 1, 26, 1, 1, 28, 1, 1, 30, 1, 1, 32, 1, 1, 34,
   1, 1, 36, 1, 1, 38, 1, 1, 40, 1, 1, 42, 2]

The following program uses a proposition we proved yesterday to compute the partial convergents of a continued fraction:

{convergents(v)=
    local(pp,qq,p,q,tp,tq,answer);
    pp=1; qq=0; p=v[1]; q=1;    \\ pp is p_{n-1} and p is p_n.
    answer = vector(length(v)); \\ put answer in this vector
    answer[1] = p/q;
    for(n=2,length(v),
       tp=p; tq=q; p=v[n]*p+pp; q=v[n]*q+qq; pp=tp; qq=tq;
       answer[n] = p/q;
    );
    return(answer);
}

Let’s try this with π:

? contfrac(Pi)
%26 = [3, 7, 15, 1, 292, 1, 1, ...]
? convergents([3,7,15])
%27 = [3, 22/7, 333/106]
? convergents([3,7,15,1,292])
%28 = [3, 22/7, 333/106, 355/113, 103993/33102]
? %[5]*1.0
%29 = 3.1415926530119026040...
? % - Pi
%30 = -0.000000000577890634...

2 Infinite Continued Fractions

Theorem 2.1. Let a_{0}, a_{1}, a_{2}, … be a sequence of integers such that a_{n} > 0 for all n ≥ 1, and for each n ≥ 0, set c_{n} = [a_{0}, a_{1}, … a_{n}]. Then lim_{n→∞} c_{n} exists.

Proof. For any m ≥ n, the number c_{n} is a partial convergent of [a_{0}, …, a_{m}]. Recall from the previous lecture that the even convergents c_{2n} form a strictly increasing sequence and the odd convergents c_{2n+1} form a strictly decreasing sequence. Moreover, the even convergents are all ≤ c_{1} and the odd convergents are all ≥ c_{0}. Hence α_{0} = lim_{n→∞} c_{2n} and α_{1} = lim_{n→∞} c_{2n+1} both exist and α_{0} ≤ α_{1}. Finally, by a proposition from last time

|c_{2n} − c_{2n−1}| = \frac{1}{q_{2n} · q_{2n−1}} ≤ \frac{1}{2n(2n − 1)} → 0,

so α_{0} = α_{1}.

We define

[a_{0}, a_{1}, …] = lim_{n→∞} c_{n}.

Example 2.2. We use PARI to illustrate the convergence of the theorem for x = π.

? a = contfrac(Pi)
%38 = [3, 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2, ...]
? c = convergents(a)
%39 = [3, 22/7, 333/106, 355/113, 103993/33102, 104348/33215, ...]
? \p9                      \\ so we can see.
   realprecision = 9 significant digits
? [c[1]*1.0, c[3]*1.0, c[5]*1.0, c[7]*1.0]  \\ odd ones converge up to pi
%43 = [3.00000000, 3.14150943, 3.14159265, 3.14159265]
? [c[2]*1.0,c[4]*1.0,c[6]*1.0,c[8]*1.0]     \\ even ones swoop down on pi.
%44 = [3.14285714, 3.14159291, 3.14159265, 3.14159265]

Theorem 2.3. Let x ∈ ℝ be a real number. Then

x = [a_{0}, a_{1}, a_{2}, …],

where a_{0}, a_{1}, a_{2}, … is the sequence produced by the continued fraction algorithm. Proof. If the sequence is finite then some t_{n} = 0 and the result follows by Proposition 1.2. Suppose the sequence is infinite. By Proposition 1.2,

x = [a_{0}, a_{1}, …, a_{n}, \frac{1}{t_{n}}].

By a proposition from the last lecture^{1},

x = \frac{\frac{1}{t_{n}} p_{n} + p_{n−1}}{\frac{1}{t_{n}} q_{n} + q_{n−1}} .

Thus if c_{n} = [a_{0}, a_{1}, …, a_{n}], then

x − c_{n} = x − \frac{p_{n}}{q_{n}}

= \frac{\frac{1}{t_{n}} p_{n}q_{n} + p_{n−1}q_{n} − \frac{1}{t_{n}} p_{n}q_{n} − p_{n}q_{n−1}}{q_{n} (\frac{1}{t_{n}} q_{n} + q_{n−1})} .

= \frac{p_{n−1}q_{n} − p_{n}q_{n−1}}{q_{n} (\frac{1}{t_{n}} q_{n} + q_{n−1})}

= \frac{(−1)^{n}}{q_{n} (\frac{1}{t_{n}} q_{n} + q_{n−1})}.

Thus

|x − c_{n}| = \frac{1}{q_{n} (\frac{1}{t_{n}} q_{n} + q_{n−1})}

< \frac{1}{q_{n}(a_{n+1}q_{n} + q_{n−1})}

= \frac{1}{q_{n} · q_{n+1}} ≤ \frac{1}{n(n + 1)} → 0.

(In the inequality we use that a_{n+1} is the integer part of \frac{1}{t_{n}}, and is hence ≤ \frac{1}{t_{n}}.)

1Which we apply in a case when the partial quotients of the continued fraction are not integers!