The Chudnovsky Algorithm
LizFoster (592)

(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:
https://en.wikipedia.org/wiki/Chudnovsky_algorithm

(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!)

You are viewing a single comment. View All
Highwayman (1319)

That’s sick! I will say though, it loses basically all accuracy after around the 17th digit it seems. :/

LizFoster (592)

@Highwayman Yes, unfortunately. I can't get it accurate past that due to Python's OverflowErrors. If I could avoid those completely somehow, I could make it as accurate as I'd like. Any suggestions?

Highwayman (1319)

@LizFoster ehh sadly I can’t think of any. I’d suggest making a BigInt class you self, but floating point will probably be hard enough as it is with out having to deal with making the BigInt as fast/efficient as you can. I bet you could do it though 😏

Highwayman (1319)

@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 (592)

@Highwayman Oh! That's a very convenient idea, as I actually made a Product Operator Factorial calculator! (https://repl.it/@LizFoster/Factorials-using-the-Product-Operator)

Highwayman (1319)

@LizFoster yeah that does seem pretty perfect! Why don’t you try it out? :P

LizFoster (592)

@Highwayman Oh dear, it still does not work, even when implementing my own factorial calculator...

Highwayman (1319)

@LizFoster :( dam. It must really be the fact that the BigInt has to be bigger then? Oh well.

LizFoster (592)

@Highwayman Yeah, makes sense after all. After calculating it by hand, a 19th iteration would have a denominator of approximately:

6.56900722e68 * 5.902416928318210e336

wwwwwww

Highwayman (1319)

@LizFoster ohhh yeesh yeah definitely BigInt then! Wow, um. Yeah you’d have to work on a better Bignum then :(

LizFoster (592)

@Highwayman Yeah.. I don't think Python can handle numbers that big, no matter what. I wonder if there is a way to scale it down to a level that Python can calculate, then scale it back up for the final calculations....?

HM(¯▿¯)

Highwayman (1319)

@LizFoster I mean you could make a class for that though, can you do bit manipulation in python?

LizFoster (592)

@Highwayman Hm. Okay. Quick question though, how exactly would I implement this in the context of this program, and how would this help lighten the load? It appears that this method would make the numbers much longer, unless I misunderstand. So sorry..

Highwayman (1319)

@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

LizFoster (592)

@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...

Highwayman (1319)

@LizFoster awesome! Classes shouldn’t be too hard I’m guessing, they’re literally just a bunch of variables and functions bunched together basically, and you definitely won’t need any of the more complicated concepts for this anyways I’d say.

LizFoster (592)

@Highwayman Yeah, exactly. Thank you so much for your feedback here, it's quite helpful. ^ ^ *

Highwayman (1319)

@LizFoster yw, I like doing it. this is fun :P

Highwayman (1319)

@nt998302 actually C++ would be perfect for this, it’s what I’ve been using.

...

Granted I still haven’t finished implementing a BigNum class after a full year of trying.

nt998302 (160)

@Highwayman I see you have some experience with servers. Can you give me some instructions as to how I can host a c++ server with replit for a unity game?

nt998302 (160)

@Highwayman I love c++, but I got to templates and operator overloading when I switched and started full time unity. I started watching this guy named Sloan Kelly recently tho

Highwayman (1319)

@nt998302 I’m telling you right now you don’t want to do that. Trust me. You’d have to implement the http protocol and that’s a nightmare.

Highwayman (1319)

@nt998302 hm. Wait so isn’t unity c#?

nt998302 (160)

@Highwayman Yeah. It's soo easy compared to UE4 c++, which I used for a few months. The memory management becomes a little tough... Movement script is A LOT to do.

nt998302 (160)

@Highwayman Then how would I host some random server thingy?

Highwayman (1319)

@nt998302 actually now that I think about it, maybe if you can figure out how to install curlib on repl.it that would make it easy as pie

Highwayman (1319)

@nt998302 hosting is easy, you just set up the server and click run, repl.it then just wakes up your server every time it gets a request.

nt998302 (160)

@Highwayman Ohhhhh. I thought there was some secret to it xD

Highwayman (1319)

@nt998302 nah, it’s super easy XD. gotta love repl.it :P