manga wrote: |
---|
So what you are saying then, is that the post by zerbo1000, which looks like insane gibberish, might actually be more advanced mathematical genius? |
Hmm, I don't think I'd put it quite that highly!
icy1 wrote: |
---|
So you basically took OP's code with a grain of salt and actually recalled some approximations for PI that looked like OP's code. |
No, I ignored the OP's code and read his/her formula
$ pi_i = sum_ (j = 0) ^ i (-1) ^ j * 4 / (2j + 1) $ |
(which - you and @mbozzi are right, I'm wrong - isn't LaTeX or even TeX, but is a similar markup language), typed it up in Microsoft word (almost exactly as written, in fact: see
http://pages.mtu.edu/~tbco/cm416/EquationEditor_main.pdf
or
https://www.unicode.org/notes/tn28/UTN28-PlainTextMath-v2.pdf
to use Word's equation editor without a mouse) and screenshot it. It can be recognised as (4 times) arctan(x) when x = 1, ... which is Pi. If you want to prove that, just expand 1/(1+x
2) by the binomial theorem and integrate both sides. That particular standard integral is very common and useful; the corresponding series isn't, as the convergence is dreadful. Yes, it's called Leibnitz' theorem (which is a bit awkward, since there are several calculus-related formulae going by the same designation).
The convergence is terrible since the sum always lies between successive partial sums (it's a decreasing-in-magnitude alternating series) and the last term is of magnitude 1/(2N+1), so even 10 million terms is bound to give you an error in the 7th decimal place ... as your code demonstrates very effectively, icy1! ... as well as the accumulated round-off error of 10 million combinations.
And finally, back to answering the OP's original question ... !
- For the first code just form a sum to N terms.
- For the second code, stop adding terms when the last term added is less than epsilon -
don't calculate an entire sum twice.