value of pi and 22/7
Gerald Britton
gerald.britton at gmail.com
Sun Mar 20 08:22:31 EDT 2011
Surely on track for the *slowest* way to compute pi in Python (or any
language for that matter):
math.sqrt( sum( pow(k,-2) for k in xrange(sys.maxint,0,-1) ) * 6. )
Based on the Riemann zeta function:
The sum of
1/k^2 for k = 1:infinity
converges to pi^2 / 6
Depending on your horsepower and the size of sys.maxint on your
machine, this may take a few *days* to run.
Note: The sum in the Python expression above runs in reverse to
minimize rounding errors.
--
Gerald Britton
More information about the Python-list
mailing list