next up previous
Next: Infinite Continued Fractions Up: Lecture 18: Continued Fractions Previous: Lecture 18: Continued Fractions

The Continued Fraction Algorithm

Let $ x\in\mathbb{R}$ and write

$\displaystyle x = a_0 + t_0$

with $ a_0\in\mathbb{Z}$ and $ 0\leq t_0 < 1$. If $ t_0\neq 0$, write

$\displaystyle \frac{1}{t_0} = a_1 + t_1$

with $ a_1\in\mathbb{N}$ and $ 0\leq 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\neq 0$ writing

$\displaystyle \frac{1}{t_n} = a_{n+1} + t_{n+1}$

with $ a_{n+1}\in\mathbb{N}$ and $ 0\leq t_{n+1}<1$. This process, which associates to a real number $ x$ the sequence of integers $ a_0, a_1, a_2, \ldots $, 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

$\displaystyle \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

$\displaystyle x = [a_0, a_1, \ldots, a_{n}+t_n],$

and if $ t_{n}\neq 0$ then $ x = [a_0, a_1, \ldots, 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

$\displaystyle x = [a_0,a_1, \ldots, a_{n-1},\frac{1}{t_{n-1}}]
=[a_0,a_1, \ldots, a_{n-1},a_n + t_n]
=[a_0,a_1, \ldots, a_{n-1},a_n, \frac{1}{t_n}].$

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

$ \qedsymbol$

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

$\displaystyle x = 1 + \frac{-1 + \sqrt{5}}{2},
$

so $ a_0 = 1$ and $ t_0 = \frac{-1+\sqrt{5}}{2}$. We have

$\displaystyle \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??

$\displaystyle \frac{1+\sqrt{5}}{2} =
1 + \frac{1}{1 + \frac{1}{1 + \frac{1}{1 + \frac{1}{1 + \frac{1}{1 + \cdots}}}}}
$

Example 1.4   Next suppose $ x = e$. Then

$\displaystyle a_0, a_1, a_2, \ldots = 2,1,2,1,1,4,1,1,6,1,1,8,1,1,\ldots$

? 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 $ \pi$:

? 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...


next up previous
Next: Infinite Continued Fractions Up: Lecture 18: Continued Fractions Previous: Lecture 18: Continued Fractions
William A Stein 2001-10-24