# Approximating $\pi=4\sum_{n=1}^\infty\frac{(-1)^{n-1}}{2n-1}$ with stable decimal places

Consider the Leibniz formula for $$\pi$$ $$\pi=4\sum_{n=1}^\infty\frac{(-1)^{n-1}}{2n-1}.$$ What is the minimum number of terms needed to calculate $$\pi$$ accurate to $$k$$ decimal places, in the sense that the first $$k$$ decimal places remain unchanged?

My attempt: Let's consider $$k=2$$ decimal places for example and set $$a_n=\frac{4}{2n-1}$$. One way to think about this is to consider the remainder of the series and simply use $$|R_n|\leq a_{n+1}\Leftrightarrow |R_n|\leq \frac{4}{2n+1}\leq 10^{-2}$$ which holds for $$n\geq 200$$. Indeed, \begin{align} R_{200}&=4\sum_{n=201}^\infty\frac{(-1)^{n-1}}{2n-1}\simeq 0.004999968751 \leq 10^{-2} \end{align} However, the partial sums give \begin{align} S_{200}&=4\sum_{n=1}^{200}\frac{(-1)^{n-1}}{2n-1}\simeq 3.136592685 \end{align} which is not accurate to two decimal places ($$\pi\simeq 3.14...$$). In fact, the minimum value of $$n$$ I found (computationally) that gives an accuracy to two decimal places was $$n=627$$. Indeed, \begin{align} S_{625}&\simeq 3.143192653\\ S_{626}&\simeq 3.139995211\\ S_{\mathbf{627}}&\simeq 3.143187549\\ S_{628}&\simeq 3.140000298\\ S_{629}&\simeq 3.143182478\\ &\vdots \end{align} And for $$n\geq 627$$ we always get $$3.14...$$. Is there an analytical way of determining the minimum number of terms for any accuracy $$k$$? Note that this is not the same as asking what is the first term for which we get exactly $$k$$ accurate decimal places, which is a seemingly harder question being discussed here.

Thoughts: I feel a general answer might be hard and highly dependent on $$\pi$$, unless I am missing something. If this is not attainable, what is the best approximation? Solving $$\frac{4}{2n+1}\leq 10^{-3}$$ gives $$n\geq 2000$$, which does work, but could this estimate be refined? I fear critical cases where many $$0$$'s or $$9$$'s appear might be trickier to solve. How would one deal with those cases?

• Your mistake is in forgetting that even though all the remaining terms are "small" they might sum to something larger and cause carries. In $\sum 0,008$ all the terms are smaller than $10^{-2}$, but we (obviously) don't get any correct digits (the sum is clearly divergent, so "correct digit" is hard to define) no matter how many terms we include. As long as multiple terms can affect the same digit, there's a chance their sum will affect preceding digits. To be sure you have enough terms to get $k$ digits I think you have to bound the remaining terms. Dec 20, 2023 at 14:58
• What is the difference between this question and this earlier one? math.stackexchange.com/questions/4822777/… Dec 20, 2023 at 15:13
• @BrianTung In that question I am trying to find the minimum number of terms to find the first occurrence that is accurate to a given number of decimal places. For $k=2$, I get $n=119$ in the other question, while here the answer should be $n=627$, because I am looking for the first occurrence after which the first $k$ decimal places remain unchanged. Dec 20, 2023 at 15:15
• The bound is more or less the same, but with the number of digits increased by one. There might be an off by one thing, but with numbers that large, that's negligible. As I mentioned in my comment on the other question, exact values will be essentially impossible to come by. Dec 20, 2023 at 15:18
• Plug. Here is an oldie... Edgar, G. A., Pi: Difficult or easy? Mathematical considerations for the multidigit computation of pi, Math. Mag. 60, 141-150 (1987). ZBL0627.65016. Dec 20, 2023 at 17:59

As you have noticed in your thoughts, without knowing the number you are approximating, you cannot be sure that a certain level of accuracy determined any particular digit accurately (your example of an arbitrary long string of zeros or nines shows this).

In numerical analysis, I believe the standard definition of "accurate to d decimal places" is that the difference between the true value, $$x$$, and the approximate value, $$\tilde x$$ have at least $$d$$ zeros in its decimal expansion (regardless of rounding to that decimal place), that is

$$\vert x - \tilde x\vert \leq 5\times 10^{-(d+1)}.$$

• Makes sense! So, if I wanted to approximate $\pi$ accurate to $10$ decimal places, for example, a required number of terms could be obtained by solving $|R_n|\leq \frac{4}{2n+1}\leq 5\times 10^{-11}$, which gives $n\geq 4\times 10^{10}$. Alternatively, using the refined estimate by Cantabrese's error bound, that is, $\frac{2}{2n+1} < |R_n| < \frac{2}{2n-1}$, with $|R_n|=5\times 10^{-11}$, I could also guarantee that with $n\geq 2\times 10^{10}$, a finer estimate. Is this correct? Dec 21, 2023 at 16:19
• I am just not too sure how they get to the "5 billion terms" here, needed to estimate $\pi$ accurate to $10$ decimal places. Any ideas? Dec 21, 2023 at 16:23
• I think in that article they use the definition that $\vert x-\tilde x\vert < 10^{-d}$ which means to 10 decimal places you need $n > 5\times 10^{9}$ Dec 22, 2023 at 18:54