## Approximations with continued fractions

In an excellent blog post earlier this year, Dave Richeson commented on the approximation:

.

The reason for this is the well-known approximation

from which

And this approximation, and more, can be obtained from the continued fraction for . This raises the question: can other interesting approximations be obtained from other continued fractions? Before we start, here’s the beginning of the continued fraction for :

Since 292 is a fairly large number, we would expect a good approximation if we chopped the continued fraction at this point:

.

We can do this easily in Sage:

```sage: F=continued_fraction(pi)
sage: F
[3, 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 3]
sage: i=list(F).index(max(F))
sage: convergent(F,i-1)
355/113
```

So here’s a recipe for finding interesting approximations: find a continued fraction containing a large integer, and take the convergent up to that value.

Here are some examples, first a “near integer” :

```sage: F=continued_fraction(log(24))
sage: F
[3, 5, 1, 1, 1, 1, 1, 1, 6, 35660, 1, 3]
sage: i=list(F).index(max(F))
sage: convergent(F,i-1)
1535/48
sage: exp(1535/483).n()
23.9999999971151
```

Next, an approximation to (this one is actually quite well known) :

```sage: F=continued_fraction(pi^4)
sage: F
[97, 2, 2, 3, 1, 16539, 1, 6, 3]
sage: i=list(F).index(max(F))
sage: convergent(F,i-1)
2143/22
sage: (2143/22)^(1/4).n()
3.14159265258265
```

And an approximation to the Euler-Mascheroni constant :

```sage: F=continued_fraction(sqrt(euler_gamma))
sage: F
[0, 1, 3, 6, 6, 5, 1, 301, 2, 24, 3, 1]
sage: i=list(F).index(max(F))
sage: x=convergent(F,i-1);x
721/949
sage: x^2.n()
0.577215659320831
sage: euler_gamma().n()
0.577215664901533
```

To read more about continued fractions, the Wikipedia page is a good start, and there’s lots of detail here (including some discussion about approximations). For those of you with access to a good library, William Stein’s superb book “Elementary Number Theory: Primes, Congruences, and Secrets” has a chapter on continued fractions.

## 2 thoughts on “Approximations with continued fractions”

1. Chris Johansen says:

Marvellous blog!

A tiny slip of the finger at “chopped the continued fraction at this point: . . . 335/113”

Sage got it right (of course):

sage: convergent(F,i-1)
355/113

I noticed only because 11 3|3 55 (| means “divides”) is a well-known and easily remembered approximation for small, four-function calculators. It was especially useful eons ago, at the dawn of the calculator age (think Bomar), when four-function meant just and only four functions with eight or fewer significant digits.

Off-topic aside: I enjoy your music for the end of the week.

Thanks.

2. amca01 says:

Thanks for that – I’ve now changed it.

And thanks for your kind words, too!