Arctan Formulae for Computing π


Contrary to popular belief and what most mathematicians will tell you, all of the digits in the decimal expansion of π are known! They are: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. It is the order that they appear that is not known.


The Maclaurin series for arctan(x) provides a reasonable method for computing π:

arctan(x)  =  x − x3/3 + x5/5 − x7/7 + x9/9 − x11/11 + . . .

This is useful since we can derive formulae that involve known values for tan kπ.  In particular 1 = tan π/4 from which we can obtain π = 4·arctan(1).

The arctan(x) series converges for x ≤ 1 and is particularly easy to compute for x = 1/q, where q is an integer.  We compute it term by term adding or subtracting the new term to the partial sum.  Let a particular "partial" term contain just the powers of q; that is, as an example the third "partial" term:

x5 = 1/q5

To get the next "partial" term simply divide by q2 to get 1/q7.  We save this for use in computing the subsequent "partial" term.  To get the next complete term also divide by 7.  This value can then be subtracted from the partial sum.  (Note, we alternately add and subtract these terms.)

Each step to obtain a term then consists of two "long division" processes each by a relatively small integer (by small we mean under 1,000,000 which can be represented by a single variable—not an array of digits).

Finally, to compute a large number of digits of π we need to maintain explicitly large arrays of digits that contain partial terms, terms, sums, and, eventually, the value of π.  The necessary arithmetic functions then consist of the three processes:

We carry out these processes until the last term in arctan series is smaller than 10−d where d is the number of digits of π that are desired.

Several formulae involving arctan series that use arctan(1/q) can be shown to give π:

  1π  =    4·arctan(1) 
  2π  =    4·arctan(1/2) +    4·arctan(1/3) 
  3π  =    4·arctan(1/2)+    4·arctan(1/5) +    4·arctan(1/8) 
  4π  =    8·arctan(1/2) −    4·arctan(1/7) 
  5π  =    8·arctan(1/3)+    4·arctan(1/7) 
  6π  =  12·arctan(1/4)+    4·arctan(1/20)+    4·arctan(1/1985) 
  7π  =  16·arctan(1/5)    4·arctan(1/70)+    4·arctan(1/99) 
  8π  =  16·arctan(1/5)    4·arctan(1/239)Machin Formula—derivation
  9π  =  24·arctan(1/8)+    8·arctan(1/57)+    4·arctan(1/239) 
10π  =  32·arctan(1/10)    4·arctan(1/239)  16·arctan(1/515) 
11π  =  48·arctan(1/18)+  32·arctan(1/57)  20·arctan(1/239) 
12π  =  48·arctan(1/49)+128·arctan(1/57)  20·arctan(1/239) +    48·arctan(1/110443) 
13π  =176·arctan(1/57)+  28·arctan(1/239)  48·arctan(1/682) +    96·arctan(1/12943) 

The first formula comes from tan 1 = π/4.  While it does converge, it converges much too slowly to be of any great use taking 5,000,000,000 terms just to compute 10 decimal digits!

Essentially if we wish to compute 1000 digits of π, then we need to compute sufficient terms of each of the series so that the last term in each series is < 10−1000.  The larger the value of q in the arctan(1/q) expression, the faster the series converges.

Number of terms

The time spent in computing each series for Formula 11, as an example, is best illustrated using, of course, a Pi Chart!

Computer Limitations

To ensure that "round-off" error in the last digit does not affect any of the desired digits, simply add an extra 20 or so digits to be thrown away when the computation is complete as potentially being in error.  It would take on the order of 1020 operations for any erroneous value (roundoff could be as large as 0.5 in the last digit) in the last place to accumulate to affect the 20-th digit from the end.  For a modern computer performing 1 billion operations per second, it would take over 3000 years to perform 1020 operations!

And, always keep in mind that the time to complete the computation is proportional to the square of the number of digits; that is, to compute an approximation to π with double the number of digits will take 4 times as long.  This is because it will take twice as many terms to reach convergence and each arithmetic function is acting on twice as many digits.