I recently became interested in programs that calculate pi, and I was reading about various spigot algorithms when I came across this Wolfram MathWorld site: https://mathworld.wolfram.com/Digit-ExtractionAlgorithm.html.
I wrote a very crude implementation of this formula in Mathematica, which can be accessed here: https://www.wolframcloud.com/obj/640de853-ec52-4a33-8a2f-6ba750f5d392. I haven't used Mathematica recently, so I apologize if the code is bad.
I am unable to get the decimal digits of $\pi$ to pop out of this formula. Could someone shed some light on what it is I might be doing wrong? My understanding is that I should be able us the "digit-extraction algorithm for the decimal digits of pi" to get the "$n$th digit to the right of the decimal point of $\pi$." However, when I try, I get something like X.XX1248631... (as this only works for $n \ge 3$). I have triple-checked that the code matches the formulas on MathWorld, but I keep getting the same results. Is this not how the algorithm is supposed to be used?
Thanks for any help.
Change your $-n$ exponents in the denominator to $-2n$ and try again.
Refer to the original equation from Simon P and multiply the numerator by $-1^{1+n/2}$ and add $1$ to any n which is odd to make it the next higher even number then evaluate.
Bernoulli's numbers equal zero when odd and dividing by zero results divide by zero errors. Bernoulli's numbers which are divisible by $4$ are negative and the even root of a negative number is imaginary.
arxiv.org/abs/2201.12601
I tried the same thing in sagemath and did not get $n$ digits of precision for pi for an $n$ input. I realized that to overcome odd Bernoulli numbers when $n$ was odd, they replaced n with 2n in the original equation except they forgot to change all the $n$ to $2n$.They also added a $-1^{n+1}$ factor to overcome negative Bernoulli numbers. If you did replace all the $n$ with $2n$ though you should get $2n$ digits of precision which is twice as much as you need to extract the nth digit.