This morning Dave Richeson posted a humorous fake proof that depends on the famous approximation 22/7 for pi. It occurred to me that nearly everyone knows a decent rational approximation to pi. Some people may know more. But hardly anyone, myself included, knows a decent rational approximation for e.
Another approximation for pi is 355/113. I like this approximation because it’s easy to remember: take the sequence 113355, split it in the middle, and make it into a fraction. It’s accurate to six decimal places, which is sufficient for most practical applications.
The approximations 22/7 and 355/113 are part of the sequence of approximations coming from the continued fraction approximation for pi. So to come up with rational approximations for e, I turned to its continued fraction representation.
The best analog of the approximation 22/7 for pi may be the approximation 19/7 for e. Obviously the denominators are the same, and the accuracy of the two approximations is roughly comparable.
Here’s how you can make your own rational approximations for e. Find the coefficients in the continued fraction for e, for example here. You can turn this into a sequence of approximations by using the following Python code:
from __future__ import division
from math import e
e_frac = [2,1,2,1,1,4,1,1,6,1,1,8]
def display(n, d, exact):
print n, d, n/d, n/d - exact
def approx(a, exact):
# initialize the recurrence
n0 = a
d0 = 1
n1 = a*a + 1
d1 = a
display(n0, d0, exact)
display(n1, d1, exact)
for x in a[2:]:
n = x*n1 + n0 # numerator
d = x*d1 + d0 # denominator
display(n, d, exact)
n1, n0 = n, n1
d1, d0 = d, d1
This will print the numerator, denominator, value, and error for each approximation. You could include more terms in the continued fraction for e if you’d like. Here are some of the results: 19/7, 87/32, 106/39, etc. Unfortunately it doesn’t look like there are any approximations as memorable as 355/113 for pi.
You could also use the code to create rational approximations to other numbers if you’d like. For example, you can find the continued fraction expansion for pi here and use the code above to find rational approximations for pi.
Update: There’s a more direct way to find continued fractions and rational approximations in Python using Sage. See the next post.
Footnote: The continued fraction coefficients for e have a nice pattern:
… 1, 1, 4, 1, 1, 6, 1, 1, 8, … 1, 1, 2k, 1, 1, 2k+2, …
For daily posts on analysis, follow @AnalysisFact on Twitter.