Created
March 14, 2012 18:12
-
-
Save thephysicsvirtuosi/2038329 to your computer and use it in GitHub Desktop.
Ridiculously Fast Pi approximation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bigfloat import * | |
N = 5 | |
setcontext(precision(10**N)) | |
def f(x): | |
return x + sin(x) | |
def g(n): | |
x = 3 | |
for i in xrange(n): | |
x = f(x) | |
return x | |
import sympy | |
goodpi = str(sympy.pi.evalf(10**N)) | |
def goodtill(n): | |
cand = g(n) | |
for i,(a,b) in enumerate(zip(str(cand),goodpi)): | |
if a != b: | |
return i-1 | |
inds = range(20) | |
print map(goodtill,inds) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment