10 best rational approximations for pi

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 -log10 of the absolute error.)

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

Errors in rational approximations to pi

Related posts

5 thoughts on “10 best rational approximations for pi

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

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

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

  4. 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).

    approx constant = [
        [
          (rnd x, rnd y, diff) | 
            y <- [1..],
            t <- [fl $ y * constant .. ceil $ y * constant],
            let x = fromIntegral t,
            let k = 1 / 10^p,
            let diff = abs(x / y - constant),
            diff < k
        ] | 
        p <- [1..]
      ]
      where
        [rnd, fl, ceil] = map (toInteger .) [round, floor, ceiling]
    
    piApprox = (approx pi !!) 
    expApprox = (approx (exp 1) !!)
    
    main = do
     print "Approximations of pi with precision up to 5 digits" 
     print $ take 10 $ piApprox 5
     print "Approximations of e with precision up to 5 digits"
     print $ take 10 $ expApprox 5
     print "Approximations of pi with precision from 1 to 11 digits"
     print $ map (take 10) $ take 11 $ approx pi
    

Leave a Reply

Your email address will not be published. Required fields are marked *