It’s easy to create rational approximations for π. Every time you write down π to a few decimal places, that’s a rational approximation. For example, 3.14 = 314/100. But that’s not the *best* approximation.

Think of the denominator of your fraction as something you have to buy. If you have enough budget to buy a three-digit denominator, then you’re better off buying 355/113 rather than 314/100 because the former is more accurate. The approximation 355/113 is accurate to 6 decimal places, whereas 314/100 is only accurate to 2 decimal places.

There’s a way to find the most economical rational approximations to π, or any other irrational number, using continued fractions. If you’re interested in details, see the links below.

Here are the 10 best rational approximations to π, found via continued fractions.

|----------------+----------|
| Fraction | Decimals |
|----------------+----------|
| 3 | 0.8 |
| 22/7 | 2.9 |
| 333/106 | 4.1 |
| 355/113 | 6.6 |
| 103993/33102 | 9.2 |
| 104348/33215 | 9.5 |
| 208341/66317 | 9.9 |
| 312689/99532 | 10.5 |
| 833719/265381 | 11.1 |
| 1146408/364913 | 11.8 |
|----------------+----------|

If you only want to know the number of correct decimal places, ignore the fractional parts of the numbers in the Decimals column above. For example, 22/7 gives two correct decimal places. But it almost gives three. (Technically, the Decimals column gives the -log_{10} of the absolute error.)

In case you’re curious, here’s a plot of the absolute errors on a log scale.

## Related posts

The decimals column is usually about 1 less than the total number of digits used in the numerator AND denominator.

I wrote about

Perl6 Pi and continued fractions a few years ago. (I would definitely write the code differently today.)

I note that the number of correct decimals is close to the total number of digits in each fraction. Not a coincidence I guess?

I’d say it’s not entirely a coincidence. It isn’t important how big the numerator is (you can add any integer to a number and that won’t change the accuracy of any estimate). However, to a first approximation, we would expect the number of correct decimals to be close to twice the number of digits in the denominator.

We might ask how accurately you can represent a random number X (let’s say Uniform [0, 1], since only the fractional part affects the accuracy of the estimate anyway) by a fraction with denominator at most N. There are roughly 3N^2 / pi^2, or 0.304 N^2, such fractions in [0, 1] (N^2/2 multiplied by the probability of two large integers being coprime). If these were uniformly distributed, the best one would approximate X with an error of at most pi^2 / 6N^2. Of course this is not the case. The actual situation is much more complicated, and we would expect the approximation to be worse because uniformly distributed numbers are optimal if you want to choose one to approximate an arbitrary number. I’m sure someone could do a more rigorous analysis and find out (at least asymptotically) the expected error of the best estimate; however, it is not surprising that the error is at least close to the order of N^2, which corresponds to twice as many correct digits as the number of digits in the denominator.

I wrote a Haskell program that finds approximations for given constant. It generates lazy infinite list of lazy infinite sublists, each n-th sublist is approximation for precision n (n numbers after decimal point).

Well, an interesting aside. If one looks at ellipses with semi-major and semi-minor axes, one can come up with a list of prime numbers for which round(ellipse area) is NOT prime. The list is fairly sparse. That list begins 7, 113, 265381, 842468587426513207. You will see that corresponds to OEIS A086788. Those will be the prime denominators of rational approximations to Pi with ever improving accuracy.