A Formula For The N'TH Digits of Pi
A Formula For The N'TH Digits of Pi
of 𝜋 and 𝜋
Simon Plouffe
January 29, 2022
Abstract
By using an asymptotic formula known for the numbers of Euler and Bernoulli it is possible to
obtain an explicit expression of the nth digit of π in decimal or in binary, it also makes it possible to obtain
the nth digit of 𝜋 . The calculation is made from the two inequalities
2 2𝑛 ! 1 2 2𝑛 !
1 𝐵 ,𝑛 1, 2, …
2𝜋 1 2 2𝜋
et
4 2𝑛 ! 4 2𝑛 ! 1
𝐸 ,𝑛 0, 1 , …
𝜋 𝜋 1 3
By isolating π in both cases, we can derive an approximation of the latter. The approximation is so good
that in fact it allows to extract the nth bit of π, the nth decimal of π and even the nth decimal of de 𝜋 , n ∈
𝕫∗ .
/
2𝑛!
𝜋
𝐵 2
Here the 𝐵 are positive and n is even. It is easy to verify that with n 1000, the error on
π is of the order of 0.293193 10 , which is less than 2 . So the thousandth
position of this expression is the 1000th bit of the number π. As soon as n 10, the
formula is valid: it allows to have the nth position. Note that given the parity of Bernoulli
numbers, we obtain 2 bits at each n, that of rand n and that of rank n-1. This is valid from
1
10 because Bernoulli numbers are a little chaotic when n is small, the rapid growth of
these numbers is felt from n 12.
The good question that comes next is: is it possible to calculate the nth decimal place? The
answer is actually yes. Here's how.
Given the known relationship with the Zeta function, it is possible to stretch the formula
by adding enough terms to it to have an error of less than 10 . In the book of Abramowitz
and Stegun 3 precisely in the same chapter we have the formula
2𝜋
𝜁 2𝑛 |𝐵 |
2 2𝑛 !
As we know, ζ 2n can be represented as an infinite product due to Euler, by carefully
taking the first 4 terms we therefore add them to our expression to have:
/
2𝑛!
𝜋
1 1 1 1
𝐵 2 1 1 1 1
2 3 5 7
Knowing that the next term would be 1 this assures us that the error committed
will be less than 10^ -n . Indeed, by checking with n 1000 and even 10000 we find an
error of the order of 0.1271934403 10 .We conclude that for each n in the
expression it seems possible to obtain the nth decimal of the number π. The difficulty is
then to be able to calculate B_2n when n is large. 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. Until 2002, the Bernoulli calculation record used
precisely this formula and some values of the series for 𝜁 n , see 5 on this subject.
Currently, the calculation uses properties of congruences and the Chinese remainder
theorem.
The formula is precise enough to get even more if we raise to the power n. In fact we will
have
2𝑛!
𝜋
1 1 1 1
𝐵 2 1 1 1 1
2 3 5 7
By checking with n 1000 we obtain the first 1000 valid digits of π^1000, so the 1000th
position if we want. To get the 1000th position of x, just calculate
𝑝𝑜𝑠𝑖𝑡𝑖𝑜𝑛 𝑛, 𝑥 10 10 𝑥
2
and being the integer and fractional parts. If calculating π^n, the formula must be
converted to treat the number as a string.
/
2𝑛 ! 2
𝜋
𝐸
Here the 𝐸 are the positive Euler numbers obtained by the series expansion of 1/𝑐𝑜𝑠 𝑥 .
It is easy to verify that with n 1000 we obtain a precision of 957 decimal digits. But
knowing the error made and the first formula, we can deduce that this error is
proportional to 9^ -1000 . So, we can say that in base 8 the expression gives the nth digit
of π in octal, a fortiori in binary.
To go further as with the Bernoulli numbers, it is enough to add only 1 term to have an
error lower than 10^ -n . Which gives us
/
2𝑛 ! 2 1
𝜋 1
𝐸 3
And if we check with n 1, for n 1000 we have here an error on π of the order of 10^ -
1198 , so the nth decimal of π can be calculated with the formula using the position
function n,x .
To get the nth digit in base 10 of 𝜋 using Euler numbers, we add terms until the error is
smaller than 10 . We have to take more terms here since the powers of π take us away
from the decimal point. So we finally have the following formula
2𝑛 ! 2 1 1 1 1
𝜋 1 1 1 1
𝐸 3 5 7 9
For 1/ π, in base 10 still with Euler, we can simply invert
/
1 𝐸 1
1
𝜋 2𝑛 ! 2 3
It therefore makes it possible to obtain the nth decimal of 1/ π in base 10. The scope of
this formula is limited by the ability to evaluate E_2n . With an Intel icore 9900K clocked
at 5 ghz, I managed without too much difficulty to calculate E_ 2,300,000 . So position
2,300,000 can be calculated by this process.
3
In the end, we can therefore calculate the nth decimal digit of π and π^n. In the end, we
can therefore calculate the nth decimal digit of π and π^n. The same process also makes
it possible to calculate the nth decimal of the following numbers.
𝑒 , ln 𝜋 , √𝜋
By isolating n! from the equation we obtain a much better formula than that of Stirling.
2𝜋 𝐵
𝑛!
2
The same with Euler numbers
𝜋 𝐸
𝑛!
2
The 2 expressions are in absolute value and n even. A summary analysis of the error shows
for 𝑛 1000 shows that for the first the error is of the order of 2 , i.e. 10 and
3 or 10 for the 2nd. With Stirling's formula, the error is of the order of 10 only.
As with the previous formulas, we can improve even more if we add terms drawn from
the function ζ n .
But there is better, by comparing two successive terms of the expression with the
Bernoulli numbers it allows to get rid of the exponent n. If we make the ratio, in fact we
obtain for 𝜋 a closed expression.
We had
/
2𝑛!
𝜋
𝐵 2
By comparing 2 successive terms we get
1𝐵 𝑛 1 2𝑛 1
𝜋
2 𝐵
Which is valid for base 4 given that the error is of the order of 4 , by applying the same
technique with Euler numbers we then have:
8𝐸 𝑛 1 2𝑛 1
𝜋
𝐸
Whose error with respect to π^2 is 9 . So in base 9. We could use the same arguments
for base 10 in both cases by adding terms. Hence the age-old question: is there an
4
interpretation of successive Bernoulli numbers allowing a combinatorial interpretation
of the binary digits of 𝜋 , the question is plausible. For the first 20 terms, the thing is
possible I believe.
/
2𝑛!
1 1 1 1
𝐵 2 1 1 1 1 …
2 3 5 7
So, with n 100 million, and even if we take 1000 billion terms, we will have at best 1.2
billion digits of precision 1000 billion 10 so 12 digits only. This is a lot but little
compared to the 62,000 billion digits obtained recently with the Chudnovsky formula, the
latter has a convergence speed which is geometric, of the order of 14 decimal digits per
term.
𝑛 1 1 139
𝑛! √2𝜋𝑛 1 ⋯
𝑒 12𝑛 288 𝑛 51840 𝑛
Which, once we isolate 𝜋 and use the bootstrap method,
Γ 𝑛 𝑛 𝑒
𝜋
1 5 1
2 1 1 1
6𝑛 36𝑛 72𝑛
Will give some digits of 𝜋 but even with n 10 only 30 digits of precision is obtained. It
is possible to stretch the first expression as desired but this convergence is polynomial,
the gain is marginal.
Another one used by Ramanujan and Hardy for the partition of n, 𝑝 𝑛 , is approximately
equal to
5
1 /
𝑝 𝑛 𝑒
4𝑛√3
When 𝜋 is isolated then we have
ln 48 𝑝 𝑛 𝑛 √6
𝜋
4√𝑛
Which also has a fairly slow convergence even if n 10 , here we could extend the
expression with Rademacher's formula, which is much more complex but which makes
the number π appear in several places, which makes the inversion operation for isolate
rather difficult. This possibility cannot be ruled out at this time.
This time the approximation is the best so far, for n 10 we get 100 digits of precision.
The precision obtained if n ≫1 is much higher than the other 2 formulas but is not
sufficient to obtain a precision of the order of the nth bit even if n is very large. If n 10
we still obtain a hundred decimal places of precision. The asymptotic expansion is known
and brings out the Bernoulli numbers which grow in size quite quickly beyond 14 terms.
So the formulas obtained with Euler or Bernoulli numbers are by far the most accurate.
6
References
3 Abramowitz, Milton Stegun, Irene Ann, eds. 1983 June 1964 . Handbook of
Mathematical Functions with Formulas, Graphs, and Mathematical Tables. Applied
Mathematics Series. 55 Ninth reprint with additional corrections of tenth original
printing with corrections December 1972 ; first ed. . Washington D.C.; New York: United
States Department of Commerce, National Bureau of Standards; Dover Publications.
ISBN 978-0-486-61272-0. LCCN 64-60036. MR 0167642. LCCN 65-12253.
4 Plouffe, Simon, On the computation of the n’th decimal digit of various transcendental
numbers, 1996. https://arxiv.org/abs/0912.0303.
5 Plouffe, Simon, An efficient algorithm for the computation of the Bernoulli Numbers.
Arxiv : https://arxiv.org/abs/math/0702300
6 Plouffe, Simon, The Construction of Certain Numbers with Ruler and Compass, le
Calcul de Certains Nombres Avec la Règle et le Compas. Vixra :
https://vixra.org/abs/1409.0135
7