Ask HN: Is there a math formula that can give me nth pie digit?

21 points by techsin101 ↗ HN
I want to make a function that gives me nth pie digit without calculating it from 1st digit.

So getNthPie(2) -> 4

and getNthPie(1000000) -> 4

7 comments

[ 3.3 ms ] story [ 20.0 ms ] thread
There are BBP formulas. I don't know if they work in decimal though

Update: only in hex: https://en.m.wikipedia.org/wiki/Bailey%E2%80%93Borwein%E2%80...

I was very surprised to learn that Plouffe has actually also devised a formula that gives the nth decimal digit! It looks like this was a much more recent discovery.

https://mathworld.wolfram.com/Digit-ExtractionAlgorithm.html

https://arxiv.org/abs/2201.12601

I first wrote that I thought this was asymptotically much faster than computing the intermediate digits, but somewhat slow because it requires computing Bernoulli numbers as one input. But in Plouffe's PDF, he says that actually the convergence is very slow and you would do significantly better computing the intermediate digits with mainstream pi-calculating methods. For instance, he states that

> The current record for Bernoulli numbers is 100 million. So, we can calculate the 100,000,000th decimal of π with this process. Note that the calculation of Bernoulli numbers can be done in several ways, one of which requires knowing π with good precision.

Does this formula imply that we can find any nth decimal value of pi, even as it tends to infinity?
You can find any (decimal) digit, but the amount of computation required gets larger for higher digits (I'm not sure of the actual scaling) - and the parent comment is saying that the paper's author says it would actually be faster to compute the intermediate digits than to use his formula for a specific digit.

The BBP formula represents pi directly as a sum of increasing powers of 1/16, and provides a given hex digit in constant time. Such a formula has not been found for decimal digits

The nth hex digit takes O(n log n) time. But it doesn’t use much space.
Right, thanks, I was thinking too simply about it