Generating Euler's Constant 04-23-2016, 10:10 PM
#1
I got bored in math class, so I figured out how to generate e using the following formulae:
![[Image: lzLpB7p.png]](http://i.imgur.com/lzLpB7p.png)
Edit: I forgot a factorial in these and mathJax sucks, so I'm not editing them.
This can also be explained more simply as:
![[Image: iEWKxcH.png]](http://i.imgur.com/iEWKxcH.png)
The problem with this is that e, like phi and pi, is both transcendental and irrational, meaning it's impossible to get its exact value (which would be infinite decimal places). Also like pi and phi, e is commonly expressed with a concise 2.718. This isn't going to do it for me, because I love pushing systems to their limits (ha). As such, I made the below script for the purpose of (with enough memory and a good cpu) breaking the world record for most decimal places of e calculated.
By using the included method call, e(48), I can generate ~39.1 million decimal places in 15 seconds, which is a decent chunk of disk space but pathetic compared to the current record (1,400,000,000,000 decimal places). So, if anyone has a super beefy computer with Python 3, would you mind running this with something like e(128), piping the output to a text file, and seeing what happens?
![[Image: qYlYotu.png]](http://i.imgur.com/qYlYotu.png)
![[Image: lzLpB7p.png]](http://i.imgur.com/lzLpB7p.png)
Edit: I forgot a factorial in these and mathJax sucks, so I'm not editing them.
This can also be explained more simply as:
![[Image: iEWKxcH.png]](http://i.imgur.com/iEWKxcH.png)
The problem with this is that e, like phi and pi, is both transcendental and irrational, meaning it's impossible to get its exact value (which would be infinite decimal places). Also like pi and phi, e is commonly expressed with a concise 2.718. This isn't going to do it for me, because I love pushing systems to their limits (ha). As such, I made the below script for the purpose of (with enough memory and a good cpu) breaking the world record for most decimal places of e calculated.
Code:
"""
Script to calculate e to a ridiculous number of digits
Pipe output to a file for full represented value via:
python e.py>e.txt
"""
from math import factorial,ceil,floor
from sys import stdout,stderr
from time import strftime
from decimal import *
def fib(n):
a,b,c=1,1,0
for r in bin(n)[3:]:
calc=b*b
a,b,c=a*a+calc,(a+c)*b,c*c+calc
if r=='1': a,b,c=a+b,a,b
return b
def e(prec):
res=[Decimal(1.0)]
getcontext().prec=prec+fib(int(ceil(ceil((prec/2)/1.618/2)+prec/1.618)))-int(floor(prec/2))
stderr.write("digits: "+str(getcontext().prec-1)+"\n")
for i in range(prec+1,0,-1):
res.extend([Decimal(1.0)/Decimal(factorial(i))])
return sum(res)
# set rounding option to the most accurate (essentially just cut off the end and don't round)
getcontext().rounding=ROUND_HALF_UP
# write current time to stderr, which doesn't pipe to a file via stdout
stderr.write(strftime("%H:%M:%S\n"))
# write result to stdout
print(e(48))
# write time after operation to stderr
stderr.write(strftime("%H:%M:%S\n"))
Spoiler: Programming explanation (read if you plan on running this)
By using the included method call, e(48), I can generate ~39.1 million decimal places in 15 seconds, which is a decent chunk of disk space but pathetic compared to the current record (1,400,000,000,000 decimal places). So, if anyone has a super beefy computer with Python 3, would you mind running this with something like e(128), piping the output to a text file, and seeing what happens?
It's often the outcasts, the iconoclasts ... those who have the least to lose because they
don't have much in the first place, who feel the new currents and ride them the farthest.
don't have much in the first place, who feel the new currents and ride them the farthest.