Calculating decimals of pi





Theoretical study




The calculation of pi's decimals on this page is based on Machin's formula from mathematician John Machin (England, 1680-1752):

\( \displaystyle \frac{\pi}{4} = 4 * \arctan\left(\frac15\right) - \arctan\left(\frac{1}{239}\right) \)


This formula was used in 1949 to calculate pi to 2037 decimals places with an ENIAC computer.

Let us develop function arctan(x) as a power series:
The well known formula for the sum of the terms of a geometric series of ratio q: 1+q+q2+...+qn= (1-qn+1)/(1-q)
provides with q=-t2 the following equality:


\( \displaystyle \frac{1}{1+t^2} = 1 - t^2 + t^4 + \dotsb + (-1)^n t^{2n} + (-1)^{n+1} \frac{t^{2n+2}}{1+t^2} \)


which gives after integration between 0 and x:

\( \displaystyle \arctan(x) = x - \frac{x^3}{3} + \frac{x^5}{5} + \dotsb + (-1)^n \frac{x^{2n+1}}{2n+1} + (-1)^{n+1} \int_0^x \frac{t^{2n+2}}{1+t^2} dt \)


Let us call R2n+1(x) the rest of the arctan(x) series: We have:

\( \displaystyle \left| R_{2n+1} \right| = \left| (-1)^{n+1} \int_0^x \frac{t^{2n+2}}{1+t^2} dt \right| \le \left| \int_0^x t^{2n+2} dt \right| = \frac{\left| x \right|^{2n+3}}{2n+3} \)


So, when \( \left| x \right| \le 1 \) then \( \left| R_{2n+1}(x) \right| \) converges to 0 when n goes to infinity and consequently for x such as \( \left| x \right| \le 1, \ \arctan(x) \) can be calculated with a precision of \( 10^{-M} \) (or equivalently to M decimal places) by adding up all power series terms up to \( \displaystyle (-1)^n \frac{x^{2n+1}}{2n+1} \) where n is the smallest integer so that \( \displaystyle \frac{\left| x \right|^{2n+3}}{2n+3} < 10^{-M} \)


For polynomial evaluation, the Horner scheme is used. Thanks to this scheme, polynomials are evaluated with very simple operations only. Without it, you would have to calculate something like x1515 with x being a 100000 digit number which is quite impossible !

Example of utilisation of the Horner scheme for the 9 first terms of arctan(x) power series:

\( \displaystyle x - \frac{x^3}{3} + \frac{x^5}{5} - \frac{x^7}{7} + \frac{x^9}{9} = x\left(1 + x^2\left(-\frac{1}{3} + x^2\left(\frac{1}{5} + x^2\left(-\frac{1}{7} + x^2\left(\frac{1}{9}\right)\right)\right)\right)\right) \)


Example with \( \displaystyle x = \frac15 \): Calculation starts from the most inner bracket ( ) couple

\( \displaystyle A = \frac19 \)
\( \displaystyle A = -\frac17 + \frac{1}{25}A \)
\( \displaystyle A = \frac15 + \frac{1}{25}A \)
\( \displaystyle A = -\frac13 + \frac{1}{25}A \)
\( \displaystyle A = 1 + \frac{1}{25}A \)
\( \displaystyle A = \frac15 A \)
\( \displaystyle \arctan\left(\frac15\right) \simeq A \)



Calculator




Enter the number of pi's decimals you want to calculate and push the "Go!" button:




Return to table of content