doc has asked for the wisdom of the Perl Monks concerning the following question:
OK so Google wants you to find a prime in e, so lots of people are into e at the moment. Given I can get a couple of million digits of e online (and I've already answered both quiz questions just to see where it led) I am interested in why/how the algorithms at e actually work.
Euler's original equation e = 1 + 1/1! + 1/2! + 1/3! .... is obviously limited in accuracy by the size of the floating point value you can work with. To calculate a lot of digits, an alternative approach is needed which is not limited by the accuracy of the floating point you can work with. Now you can express e as e=1+1+1/2(1+1/3(1+1/4(1+1/5(1+.....)))) which means that when you work from the inside out the calculations only use small integer division. I presume that this is what is being done at e with the reverse walking and a carry up the integer array. The thing is I simply don't get it? Anyone able to enlighten me or provide a reference? This looks simple enough.....
sub e{ @e=(1)x pop; for(1..@e){ for(reverse(1..$#e)){ $e[$_-1]+=$e[$_]/$_; $e[$_]=10*($e[$_]%$_) } print int $e[0]; $e[0]=0 } }
Mazal tov.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Caclulation of e
by tachyon (Chancellor) on Jul 17, 2004 at 10:40 UTC | |
by jdalbec (Deacon) on Jul 17, 2004 at 14:52 UTC | |
|
Re: Caclulation of e
by Dr. Mu (Hermit) on Jul 18, 2004 at 04:48 UTC | |
by tachyon (Chancellor) on Jul 18, 2004 at 11:00 UTC | |
by bageler (Hermit) on Jul 19, 2004 at 01:42 UTC | |
|
Re: Caclulation of e
by pg (Canon) on Jul 17, 2004 at 23:45 UTC | |
|
Re: Caclulation of e
by fredopalus (Friar) on Jul 18, 2004 at 03:09 UTC | |
|
Re: Caclulation of e
by ambrus (Abbot) on Jul 21, 2004 at 10:03 UTC |