3.12 Continued Fractions

There are many situations where we want to approximate a real number by a rational number. For example, we can approximate π=3.14159265 by 314/100=157/50. But 22/7 is a slightly better approximation, and it is more efficient in the sense that it uses a smaller denominator than 157/50. The method of continued fractions is a procedure that yields this type of good approximations. In this section, we summarize some basic facts. For proofs and more details, see, for example, [Hardy-Wright], [Niven et al.], [Rosen], and [KraftW].

An easy way to approximate a real number x is to take the largest integer less than or equal to x. This is often denoted by [x]. For example, [π]=3. If we want to get a better approximation, we need to look at the remaining fractional part. For π=3.14159,  this is .14159. This looks close to 1/7=.142857. One way to express this is to look at 1/.14159=7.06251. We can approximate this last number by [7.06251]=7 and therefore conclude that 1/7 is indeed a good approximation for .14159 and that 22/7 is a good approximation for π. Continuing in this manner yields even better approximations. For example, the next step is to compute 1/.06251=15.9966 and then take the greatest integer to get 15 (yes, 16 is closer, but the algorithm corrects for this in the next step). We now have

π3+17+115=333106.

If we continue one more step, we obtain

π=3+17+115+11=355113.

This last approximation is very accurate:

π=3.14159265,  and 355/113=3.14159292.

This procedure works for arbitrary real numbers. Start with a real number x. Let a0=[x] and x0=x. Then (if xiai; otherwise, stop) define

xi+1=1xiai, ai+1=[xi+1].

We obtain the approximations

pnqn=a0+1a1+1a2+1+1an.

We have therefore produced a sequence of rational numbers p1/q1, p2/q2, . It can be shown that each rational number pk/qk gives a better approximation to x than any of the preceding rational numbers pj/qj with 1j<k. Moreover, the following holds.

Theorem

If |x(r/s)|<1/2s2 for integers r, s,  then r/s=pi/qi for some i.

For example, |π22/7|.001<1/98 and 22/7=p2/q2.

Continued fractions yield a convenient way to recognize rational numbers from their decimal expansions. For example, suppose we encounter the decimal 3.764705882 and we suspect that it is the beginning of the decimal expansion of a rational number with small denominator. The first few terms of the continued fraction are

3+11+13+14+19803921.

The fact that 9803921 is large indicates that the preceding approximation is quite good, so we calculate

3+11+13+14=6417=3.7647058823529, 

which agrees with all of the terms of the original 3.764605882. Therefore, 64/17 is a likely candidate for the answer. Note that if we had included the 9803921, we would have obtained a fraction that also agrees with the original decimal expansion but has a significantly larger denominator.

Now let’s apply the procedure to 12345/11111. We have

1234511111=1+19+1246+11+14.

This yields the numbers

1, 109, 24612215, 24712224, 1234511111.

Note that the numbers 1, 9, 246, 1, 4 are the quotients obtained during the computation of gcd(12345, 11111) in Subsection 3.1.3 (see Exercise 49).

Calculating the fractions such as

24612215=1+19+1246

can become tiresome when done in the straightforward way. Fortunately, there is a faster method. Define

p2=0, p1=1, q2=1, q1=0, pn+1=n+1pn+pn1qn+1=an+1qn+qn1.

Then

pnqn=a0+1a1+1a2+1+1an.

Using these relations, we can compute the partial quotients pn/qn from the previous ones, rather than having to start a new computation every time a new an is found.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.93.136