5 ms·
Ask HN: How do you calculate Pi to N digits?
How do you actually calculate pi to say 1000 digits? or 10,000? Most info I found on google take you to pre-solved lists of digits OR code that is optimised beyond recognition so I'm unsure how you actually do the calculation to begin with.
- Bostonian 3y agoThere was a paper https://maa.org/sites/default/files/pdf/pubs/amm_supplements/Monthly_Reference_12.pdf https://maa.org/sites/default/files/pdf/pubs/amm_supplements... A Spigot Algorithm for the Digits of π Author(s): Stanley Rabinowitz and Stan Wagon Source: The American Mathematical Monthly, Vol. 102, No. 3 (Mar., 1995), pp. 195-203 Fortran code for the algorithm is at https://fortran-lang.discourse.group/t/fortran-code-snippets/2150/27 https://fortran-lang.discourse.group/t/fortran-code-snippets...
- FrankWilhoit 3y agoSearch "infinite series for pi". Several sources contain historical surveys of series: the earliest-discovered converge slowly, the best recent ones I think quadruple the number of digits on each iteration.
- deleted 3y ago[deleted]
- deleted 3y ago[deleted]
- Someone 3y agohttps://en.wikipedia.org/wiki/Approximations_of_π https://en.wikipedia.org/wiki/Approximations_of_π The method of using inscribed and circumscribed n-gons conceptually is the simplest (1), but converges very slowly. See https://arxiv.org/pdf/2008.07995.pdf https://arxiv.org/pdf/2008.07995.pdf. (1) at least to non-mathematicians. Pure mathematicians will want to prove the claims that the circumference of a circle is larger than/smaller than that of its inscribed/circumscribed polygon and that both can get arbitrarily close to it if the number of sides gets large enough.
- otras 3y agoThe Digit extraction methods (https://en.wikipedia.org/wiki/Approximations_of_%CF%80#Digit_extraction_methods https://en.wikipedia.org/wiki/Approximations_of_%CF%80#Digit...) section still amazes me, that we can calculate the Nth digit without needing to calculate the digits before it.
- h2odragon 3y agohttps://www.bellard.org/pi/ https://www.bellard.org/pi/ dig into the links a bit
- westurner 3y agoTo approximate an arbitrary number of digits of pi with sympy: #! pip install sympy gmpy import sympy sympy.evalf(sympy.pi) sympy.N(sympy.pi) https://docs.sympy.org/latest/modules/evalf.html https://docs.sympy.org/latest/modules/evalf.html RosettaCode > [Python] lists quite a few more: https://rosettacode.org/wiki/Pi#Python https://rosettacode.org/wiki/Pi#Python
- eddtries 3y agoI want to try write the underlying code myself, but thanks!
- westurner 3y agogmpy2.const_pi(precision=0: =53bits) probably isn't too helpful then either: https://gmpy2.readthedocs.io/en/latest/mpfr.html#gmpy2.const_pi https://gmpy2.readthedocs.io/en/latest/mpfr.html#gmpy2.const... https://github.com/aleaxit/gmpy/issues/253#issue-499509692 https://github.com/aleaxit/gmpy/issues/253#issue-499509692 RosettaCode has only one solution to the "Approximate Pi with Rationals (not float64s)" in Python problem. I remember having seen a few statistical manifestation of Pi demos on YouTube
- westurner 3y ago"Calculating Pi with Darts by Physics Girl [and Veritasium Derek] (PBS LearningMedia)" https://youtube.com/watch?v=M34TO71SKGk https://youtube.com/watch?v=M34TO71SKGk Monte Carlo method: https://en.wikipedia.org/wiki/Monte_Carlo_method https://en.wikipedia.org/wiki/Monte_Carlo_method "Inferred value of Pi is never 3.1415" (with pymc) https://discourse.pymc.io/t/inferred-value-of-pi-is-never-3-1415/6722 https://discourse.pymc.io/t/inferred-value-of-pi-is-never-3-... https://github.com/pymc-devs/pymc https://github.com/pymc-devs/pymc
- Leftium 3y agoMatt Parker makes a new video on calculating Pi (by hand) every year: https://www.youtube.com/playlist?list=PLhtC92GarkjyYbxI3-4qzIWIRbZaw4wuP https://www.youtube.com/playlist?list=PLhtC92GarkjyYbxI3-4qz... The more practical methods: - Chudnovsky algorithm: https://youtu.be/LhlqCJjbEa0 https://youtu.be/LhlqCJjbEa0 - Newton's method: https://youtu.be/CKl1B8y4qXw?t=160 https://youtu.be/CKl1B8y4qXw?t=160