The Chudnovsky Algorithm
(NOTE: It only does 18 iterations, as if you try to do any more, it raises an OverflowError, how lame.. -__-)
わーい, another π approximation method! (I do love these things. π is gorgeous, is it not?)
This is one of the fastest formulae for π out there, used to approximate out to 50 TRILLION DIGITS of π, in January of this year!
The notation for this in Σ is very long, so I have provided a screenshot of it, from its Wikipedia page:
Feedback is greatly appreciated, please enjoy!
If you are interested in learning more, this is the Wikipedia page:
(EDIT: Wow! I am glad this was a bit of a conversation starter for you all, thank you so much for all the upvotes!!)
(EDIT 2: I am still getting tons of traction on this, and am glad it is so interesting to all of you. Thank you so much!)
Wow, this is really impressive - I've never managed to program this algorithm my self. Do you know why 18 iterations are only giving 15 digits of pi? I thought this algorithm was supposed to do 14 digits per term.
That’s sick! I will say though, it loses basically all accuracy after around the 17th digit it seems. :/
@LizFoster Oh wait, could the overflow be because you are using a factorial function? maybe the factorial function is using recursion, which would easily make a stack overflow. Maybe if you tried implementing your own factorial function without the recursion, maybe try it out like that??
@LizFoster ehh, maybe. I’m not sure how the decimal module works, but if it has a limit, then ya this could likely surpass that. All this would do is increase the amount of space you give up for a number, allowing for more digits. That wasn’t a good explanation was it? Sorry, :( rushed
@Highwayman No, its a perfectly fine explanation. I only recently learned about the decimal module, and pretty much all I know about it is that you can produce floats with as many decimal places as you specify.
Yeah, good point I suppose. I'll see what I can do, as I don't understand Classes very well yet...
What an impressive feat of mathematical programming, too bad Python can't handle the sheer awesomeness of the Chudnovsky Algorithm. The C languages are great for this kinda thing though, so I hear.