All Rational Approximations of Pi Are Useless
When I first learned about π, I was told that a good approximation was 22/7. Even when I was 12 years old, I thought this was utterly pointless. 22/7 agrees with π to two decimal places (so three matching digits):
Since there are three digits to remember in 22 and 7, what have you gained? You have just as much to remember, but have lost the notion that π is “just over 3”.
Is there a better rational approximation where we actually get out more digits than we put in? Here is a brief and rather low-brow investigation (and the chance to win something if you can do better).
First we need a function to count digits in the fraction. I am going to generalize a bit and count all characters in the plaintext form of the input. This function is slightly over-engineered to avoid automatic simplification and to strip white space, for reasons that will become clear at the end.
This counts the “/” as a character, but, to be fair, we will add 1 to the matching digits to count the “.” in the output as a character too.
I don’t want to have to specify the number of digits to evaluate expressions to, so I will give Mathematica permission to use as much automation as it needs to resolve numerical values:
Now I will enumerate a lot of rational approximations. This gets increasingly slow as the approximations get better, so it’s best to do this once and then analyze the resulting list.
Here for example is the 100th candidate:
It has 103 characters to remember:
And yields 103 characters of π:
Let’s look at the trend.
That’s pretty linear; we are not going to get better just by virtue of going larger. Let’s look at how many more or less digits we get out compared to those we put in (higher is better).
So it is possible to get three free digits in the first thousand trials. And in fact, we find that we get four such wins:
Let’s get the first candidate that gives us three free digits.
Hmm, that’s a lot to remember for just three free digits.
Less than 1% return on our investment. Perhaps we should really be looking for the best fractional gain rather than largest absolute gain. Again, let’s look at the trend:
It looks like the trend works against us, and the best values are near the start. The best result is 1 free character for every 7 remembered.
Putting all these steps together, here is a function to find the best approximation for a number by fractional gain:
So if you have to tell people to learn a rational approximation of π, it should be 355/113, which gives you 8 characters of correct results for only 7 memorized. But that is still pretty useless.
I searched as high as 10,000 candidates and found no better. If you repeat this analysis with other well-known irrational numbers √2 and e, you find the same behavior. No doubt this is obvious to number theorists! Here are the best results for √2 and e:
…with 1 free digit for 5 remembered, and…
…with only 1 free digit for 19 remembered.
When I sent this to the blog team to put on the website, Ed Pegg, who writes here regularly, suggested a nice non-rational approximation:
Which by my metrics gives:
Which is an impressive gain of 26%.
Can anyone beat that? If anyone can, I will send a Mathematica T-shirt to the person with the best score at the end of July. (Scoring uses the functions in this blog. Anything that I judge to be outside of the spirit of the competition will be disqualified—that includes the use of programs, integrals, sums, inverse trig functions, π-related values of special functions, or π-related constants (such as π).)