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.
12 comments
[ 3.0 ms ] story [ 22.7 ms ] threadhttps://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...
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.
(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.
dig into the links a bit
RosettaCode > [Python] lists quite a few more: https://rosettacode.org/wiki/Pi#Python
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
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-... https://github.com/pymc-devs/pymc
The more practical methods:
- Chudnovsky algorithm: https://youtu.be/LhlqCJjbEa0
- Newton's method: https://youtu.be/CKl1B8y4qXw?t=160