Calculation of Infinite Series

bholstege

[H]ard|Gawd
Joined
Dec 31, 2007
Messages
1,054
Hi everyone. I'm not at all an experienced programmer, so if this answer to this is obvious, I apologize.

I was writing a program to calculate the Liebniz series, which states that the sum of 1 - 1/3 + 1/5 - 1/7 etc. equals pi/4. It is very slow - getting pi to 10 digits takes about 10 seconds to run. I tried various optimizations (loop unrolling, reducing variable usage in the loop, pairwise conversion to eliminate the need for negative numbers, etc), which was able to get runtime down to about 4 seconds.

But when I plug this series into WolframAlpha, it can calculate it to any desired precision almost instantly.

So my question is - how does it do this?

Thanks.
 
I'm doing it in Python.

It seems like 10 seconds should be reasonable then? If it needs 5 billion terms to get to 10 digits of accuracy, and we assume it takes 20 clock cycles to run and check a loop, then on a 3ghz machine we get 150 million terms a second, for a runtime of 33.3 seconds?
 
Sure, the basic implementation of it would take that long then.. but it does give several methods that can be used to speed it up. I thought that was what you were looking for.
 
Back
Top