Bossy Lobster

A blog by Danny Hermes; musing on tech, mathematics, etc.

Edit on GitHub

Continued Fractions for the Greater Good part 1

OK, maybe not for the greater good, but still fun. This first post will be relatively short and sweet, intended to give an introduction for the posts that will follow.

Before the introduction, some motivation courtesy of Wikipedia:

...decimal representation has some problems. One problem is that many rational numbers lack finite representations in this system. For example, the number 13\frac{1}{3} is represented by the infinite sequence (0,3,3,3,3,)(0, 3, 3, 3, 3, \ldots ). Another problem is that the constant 1010 is an essentially arbitrary choice, and one which biases the resulting representation toward numbers that have some relation to the integer 1010. For example, 1371600\frac{137}{1600} has a finite decimal representation, while 13\frac{1}{3} does not, not because 1371600\frac{137}{1600} is simpler than 13,\frac{1}{3}, but because 16001600 happens to divide a power of 1010 (106=1600×625)(10^6 = 1600 \times 625). Continued fraction notation is a representation of the real numbers that avoids both these problems. Let us consider how we might describe a number like 41593,\frac{415}{93}, which is around 4.46244.4624. This is approximately 44. Actually it is a little bit more than 4,4, about 4+124 + \frac{1}{2}. But the 22 in the denominator is not correct; the correct denominator is a little bit more than 22 about 2+16,2 + \frac{1}{6}, so 41593\frac{415}{93} is approximately

4+12+16.4 + \cfrac{1}{2+\cfrac{1}{6}}.
But the 66 in the denominator is not correct; the correct denominator is a little bit more than 6,6, actually 6+176+\frac{1}{7}. So 41593\frac{415}{93} is actually
4+12+16+17.4 + \cfrac{1}{2+\cfrac{1}{6 +\cfrac{1}{7}}}.
This is exact...

With this in mind, one can define an infinite continued fraction to be

a0+1a1+1a2+.a_0 + \cfrac{1}{a_1 +\cfrac{1}{a_2 +\ddots}}.

With the denominators a0,a1,a2,,a_0, a_1, a_2, \ldots, we can define a recurrence for the finite approximations (convergents) of this value. For example, the zeroth is a0a_0 and the first is

a0+1a1=a0a1+1a1.\displaystyle a_0 + \frac{1}{a_1} = \frac{a_0 a_1 + 1}{a_1}.

The other motivation (the one I actually learned first in real life) for continued fractions comes from 2\sqrt{2} being represented by an infinite continued fraction. (Instead of saying a probability of 0.01876,0.01876, people would rather say a 11 in 5353 chance.) So we try to write 2=1.41421356\sqrt{2} = 1.41421356\ldots as 1+12.4141 + \frac{1}{2.414}. But, instead, notice that

2=1+(21)=1+12+1.\sqrt{2} = 1 + (\sqrt{2} - 1) = 1 + \frac{1}{\sqrt{2} + 1}.

Plugging this into itself, we have

2=1+11+1+12+1=1+11+1+11+1+12+1\sqrt{2} = 1 + \cfrac{1}{1 +1 + \cfrac{1}{\sqrt{2} + 1}} =1 + \cfrac{1}{1 +1 + \cfrac{1}{1 + 1 + \cfrac{1}{\sqrt{2} + 1}}}

and notice it can be represented by (1;2,2,2,)(1; 2, 2, 2, \ldots).

Define the nnth convergent to be hnkn,\frac{h_n}{k_n}, so above we have h0=a0,k0=1h_0 = a_0, k_0 = 1 and h1=a0a1+1,k0=a1h_1 = a_0 a_1 + 1, k_0 = a_1.

Claim:

hnh_n and knk_n satisfy

hn=anhn1+hn2kn=ankn1+kn2\begin{aligned}h_n &= a_n h_{n - 1} + h_{n - 2} \\k_n &= a_n k_{n - 1} + k_{n - 2}\end{aligned}

along with h1=1,h2=0h_{-1} = 1, h_{-2} = 0 and k1=0,k2=1k_{-1} = 0, k_{-2} = 1.

Proof:

The fraction hnkn\displaystyle \frac{h_n}{k_n} is converted into hn+1kn+1\displaystyle \frac{h_{n + 1}}{k_{n + 1}} simply by changing ana_n to an+1an+1a_n + \frac{1}{a_{n + 1}} in the final denominator. Since

hnkn=anhn1+hn2ankn1+kn2\frac{h_n}{k_n} = \frac{a_n h_{n - 1} + h_{n - 2}}{a_n k_{n - 1} + k_{n - 2}}

we similarly have

hn+1kn+1=(an+1an+1)hn1+hn2(an+1an+1)kn1+kn2=an+1(anhn1+hn2)+hn1an+1(ankn1+kn2)+kn1=an+1hn+hn1an+1kn+kn1\begin{aligned}\frac{h_{n + 1}}{k_{n + 1}} &= \frac{\left(a_n + \frac{1}{a_{n + 1}}\right)h_{n - 1} + h_{n - 2}}{\left(a_n + \frac{1}{a_{n + 1}}\right)k_{n - 1} + k_{n - 2}} \\ &= \frac{a_{n + 1}(a_n h_{n - 1} + h_{n - 2}) + h_{n - 1}}{a_{n + 1}(a_n k_{n - 1} + k_{n - 2}) + k_{n - 1}} \\&= \frac{a_{n + 1} h_n + h_{n - 1}}{a_{n + 1} k_n + k_{n - 1}}\end{aligned}

Thus hn+1h_{n + 1} and kn+1k_{n + 1} satisfy the same recurrence.

It remains to check the initial conditions work, but note

h0=a0h1+h2=a01+0=a0k0=a0k1+k2=a00+1=1\begin{aligned}h_0 &= a_0 h_{-1} + h_{-2} = a_0 \cdot 1 + 0 = a_0 \\k_0 &= a_0 k_{-1} + k_{-2} = a_0 \cdot 0 + 1 = 1 \end{aligned}

and

h1=a1h0+h1=a0a1+1k1=a1k0+k1=a11+0=a1\begin{aligned}h_1 &= a_1 h_{0} + h_{-1} = a_0 a_1 + 1 \\k_1 &= a_1 k_{0} + k_{-1} = a_1 \cdot 1 + 0 = a_1 \end{aligned}

as we checked above. \blacksquare

Check out my next post, where I actually accomplish something with fractions (or at least prepare to accomplish something).

Comments