Hello. Many years ago I published a paper showing how to easily accelerate the convergence of the classic series approximation for , Sum[1/k!, {k, 0, Infinity}]. That paper is attached for reference.
e
Many of the derived formulas appear here:
https://functions.wolfram.com/Constants/E/06/01/
While I am not a computational scientist, it’s clear that these methods do minimize the number of divisions necessary for any given degree of accuracy. In the simplest case
1/n! + 1/(n-1)! = (n+1)/n!
For large n, we are roughly trading 2n multiplications and 2 divisions for n multiplications and 1 division while achieving very close to the same accuracy. Granted, the multiplications for the factorials can be stored, but the reduction in division operations is a gift.
I mention all of this because I read that Mathematica computes using the classic series. While I’m pretty sure that the fast calculation of many digits of is not a high priority for most users, it seems that these new compressed series would add an easily obtainable efficiency.
The experiments I’ve done in the front end indicate that Mathematica executes these compressed series much faster than it does with the classic method. Here is code from the attached notebook showing a comparison of timings:
https://functions.wolfram.com/Constants/E/06/01/
While I am not a computational scientist, it’s clear that these methods do minimize the number of divisions necessary for any given degree of accuracy. In the simplest case
1/n! + 1/(n-1)! = (n+1)/n!
For large n, we are roughly trading 2n multiplications and 2 divisions for n multiplications and 1 division while achieving very close to the same accuracy. Granted, the multiplications for the factorials can be stored, but the reduction in division operations is a gift.
I mention all of this because I read that Mathematica computes
e
e
The experiments I’ve done in the front end indicate that Mathematica executes these compressed series much faster than it does with the classic method. Here is code from the attached notebook showing a comparison of timings:
Timings for compression schemes of 1024 terms:
Timings for compression schemes of 1024 terms:
First row shows uncompressed sum
(*Executethiscell*)i=1024;acc=2750;dat
Out[]//TableForm=
Compressed Block Size | Compressed Terms in Sum | Timing (Sec) | Speedup Ratio | ~Error |
N/A | 1024 | 0.032732 | 1 | 1.847321661× -2640 10 |
2 | 512 | 0.014775 | 2.21536 | 1.891659185× -2637 10 |
4 | 256 | 0.007013 | 4.66733 | 1.977744811× -2631 10 |
8 | 128 | 0.003965 | 8.25523 | 2.136583159× -2619 10 |
16 | 64 | 0.0024 | 13.6383 | 2.378506424× -2595 10 |
32 | 32 | 0.001921 | 17.039 | 2.435863258× -2547 10 |
32 | 33 | 0.002105 | 15.5496 | 4.911959761× -2740 10 |
Timings for compression schemes of 4096 terms:
Timings for compression schemes of 4096 terms:
i=4096;acc=13150;dat
Out[]//TableForm=
Compressed Block Size | Compressed Terms in Sum | Timing (Sec) | Speedup Ratio | ~Error |
N/A | 4096 | 0.862403 | 1 | 2.745859249× -13020 10 |
2 | 2048 | 0.430241 | 2.00446 | 1.124704015× -13016 10 |
4 | 1024 | 0.215873 | 3.99496 | 1.885558634× -13009 10 |
8 | 512 | 0.111672 | 7.72264 | 5.284091178× -12995 10 |
16 | 256 | 0.057973 | 14.8759 | 4.101395809× -12966 10 |
32 | 128 | 0.031621 | 27.2731 | 2.357280062× -12908 10 |
32 | 129 | 0.032878 | 26.2304 | 1.484152120× -13139 10 |
Timings for compression schemes of 16384 terms:
Timings for compression schemes of 16384 terms:
i=16384;acc=62100;dat
Out[]//TableForm=
Compressed Block Size | Compressed Terms in Sum | Timing (Sec) | Speedup Ratio | ~Error |
N/A | 16384 | 35.7969 | 1 | 8.283816599× -61937 10 |
2 | 8192 | 17.9078 | 1.99896 | 1.357220517× -61932 10 |
4 | 4096 | 8.91602 | 4.0149 | 3.642594036× -61924 10 |
8 | 2048 | 4.4952 | 7.96337 | 2.621883172× -61907 10 |
16 | 1024 | 2.2864 | 15.6564 | 1.354395519× -61873 10 |
32 | 512 | 1.14881 | 31.1599 | 3.572030227× -61806 10 |
32 | 513 | 1.16212 | 30.8031 | 6.722208723× -62076 10 |
Because compression slightly reduces accuracy, the bottom row in each of the comparisons includes one extra term to show the time required to achieve at least the accuracy of the classic series for the specified number of original terms.
Any feedback would be welcome, thanks!
Any feedback would be welcome, thanks!
Initialization
Initialization
In[]:=
dat:=Style[#,Bold]&/@{"Compressed Block Size","Compressed Terms in Sum","Timing (Sec)","Speedup Ratio","~Error"},"N/A",terms=1;uls=,timingS1=TimingS1=[[1]],1,NumberForm[N[,acc]-S1,dsplDig],terms=2,uls=,timingS2=TimingS2=[[1]],timingS1timingS2,NumberForm[N[,acc]-S2,dsplDig],terms=4,uls=,timingS3=TimingS3=[[1]],timingS1timingS3,NumberForm[N[,acc]-S3,dsplDig],terms=8,uls=,timingS4=TimingS4=[[1]],timingS1timingS4,NumberForm[N[,acc]-S4,dsplDig],terms=16,uls=,timingS5=TimingS5=[[1]],timingS1timingS5,NumberForm[N[,acc]-S5,dsplDig],terms=32,uls=,timingS6=TimingS6=[[1]],timingS1timingS6,NumberForm[N[,acc]-S6,dsplDig],terms=32,uls=+1,timingS7=TimingS7=[[1]],timingS1timingS7,NumberForm[N[,acc]-S7,dsplDig]//TableForm;num8=32k(155+2k(-1531+8k(1429+8k(-659+8k(161+32k(-5+2k))))))+1;num16=64k(20348414255+4k(-265038487471+16k(367352409641+32k(-145996005555+8k(150378281285+16k(-53520821605+32k(6830440645+32k(-638250957+4k(352460031+16k(-35891701+64k(665327+4k(-139671+16k(4915+128k(-13+2k))))))))))))))+1;num32=128k(64176371417383836892001528894255+8k(-1025810234036842624467949834423471+32k(1842666161978822595260356332316841+64k(-1003001341431430723176213473349675+16k(1500005122565885378479911593123141+32k(-825987027673041670459565379951501+64k(175067236077414657592776373254273+16k(-117802090287245822385996036138523+32k(32162266945836491239392702246043+1024k(-226394398103861869809539690594+k(1363507973661823147365483045485+32k(-216526252580067004439157103147+128k(7307637305851792586784204981+8k(-3373746657684852871206032795+32k(334310624190536992335131933+32k(-28522099062146945612556367+32k(2098472979579276635681045+64k(-66599106273462651550173+16k(7288347065845901344361+32k(-343088088310148695653+64k(6922973049526159653+16k(-476599721931925591+32k(13892761183759795+64k(-169804322311637+16k(6869695756821+32k(-112896320705+64k(734239139+16k(-14541295+32k(102951+512k(-29+2k))))))))))))))))))))))))))))))+1;dsplDig=10;
i
terms
uls-1
∑
k=0
1
k!
i
terms
uls-1
∑
k=0
2k+1
(2k)!
i
terms
uls-1
∑
k=0
64-32+8k+1
3
k
2
k
(4k)!
i
terms
uls-1
∑
k=0
num8
(8k)!
i
terms
uls-1
∑
k=0
num16
(16k)!
i
terms
uls-1
∑
k=0
num32
(32k)!
i
terms
uls
∑
k=0
num32
(32k)!