How to Calculate Pi to a Million Decimal Places

0 Comments
Join the Conversation
Poster showing more than 1400 digits of pi. - Mathteacherstore.com
Poster showing more than 1400 digits of pi. - Mathteacherstore.com
From time to time news emerges of a new calculation of pi = 3.14159... to more decimal places. A more modest goal is instructive and entertaining.

The value of pi, the ratio of the circumference of a circle to its diameter, was known approximately by the Ancient Egyptians. They apparently used a value of 256/81.

By the year 480, the Chinese Mathematician Zu Chongzhi discovered the approximation 355/113, which is accurate to 6 decimal places. Pi has had a rich history during which it has been calculated to ever increasing precision. It is now known to over 1 trillion digits, thanks to the power of modern computers. 2.7 trillion digits of pi were reached in January 2010.

A new formula for pi has enabled it to be calculated to much higher precision, perhaps as much as several quadrillion (10^15) digits.

Mathematical Formulae for Pi

Pi relies for its calculation on expansions of power series such as

pi/4 = arctan (1/2) + arctan(1/3) (1)

pi/4 = 4 arctan(1/5) - arctan(1/239) (2)

It is usual to calculate pi using two methods and then to compare the results to ensure that the result is accurate. The power series expansion of arctan (x) is given in many high school text books:

arctan(x) = x - x^3/3 + x^5/5 - x^7/7 ..... (3)

To compute the power series, the computer program has to calculate each term individually and carry out the sum (see description below). The method cannot calculate a specific decimal place.

The new method of computing pi (see also Bailey et al, 1997, reference below) is a much more powerful way of computing the digits directly and uses the Bailey–Borwein–Plouffe formula

pi = sum_k(1/16^k(4/(8k+1) - 2/(8k+4) - 1/(8k+5) - 1/(8k+6)) (4)

The reason why this formula is so powerful is that it can be used to calculate the kth hexadecimal (base 16) digit of pi without first carrying out the calculations of the previous digits. This allows separate processors of a computer to work on independent digits of pi before combining the answers for the final result.

Once the hexadecimal digits are calculated, they can be converted into decimal for usual use.

How to Calculate the Digits of Pi

This was an exercise I carried out myself when I was in high school, when computers were 10,000 times slower (!). I only calculated 100 decimal places, but the principle is the same for a million, or a billion places. It is instructive because it tests one's understanding of logic, while also testing programming skills.

So, the main point to grasp is that the explicit steps in carrying out the arithmetic need to be explicitly programmed. Let's consider the calculation of arctan(1/2). What you need to do is divide up computer storage with integer representation of the calculation in for example blocks of 5 decimal digits. The first term in the power series can be represented exactly:

50000 00000 00000 00000 00000 00000 00000 00000 00000 00000

In this example we are calculating 50 d.p. for illustrative purposes, although because of errors in truncating the series, the last few digits may not be accurate. The second term in the series is -x^3/3 which can be computed in two stages, first -x^3, which can be represented exactly

-12500 00000 00000 00000 00000 00000 00000 00000 00000 00000

Now you have to divide by 3. To do this, you have to program the computer for the division just like you yourself would carry it out. That means carrying the remainder from the division as you progress from the more significant to the less significant digits. The result is

-04166 66666 66666 66666 66666 66666 66666 66666 66666 66666

So to compute the sum in the calculation of arctan(1/2) for formula (1), this procedure needs to be repeated for every term in the power series. It is a tedious job, perfect for a computer!

One of the decisions that you need to make is how many terms in the power series need to be included. An estimate of the error is the size of the next term in the series. After 100 terms, the size is (1/2)^201/201 = 1.5 x 10^(-63), so this would give you roughly 60 decimal places after you allow for the multiplication by 4 and the use of the 2nd power series in the formula.

The formula (2) involving arctan(1/4) converges a lot faster so you need fewer terms for a given accuracy. In fact this was the formula I used 40 years ago!

Writing Your Own Program to Calculate Pi

Ready-made programs tend to be standard for home computers. So, writing your own program on your home computer might be interesting but it is not as challenging as the problem I faced, because of the large memory and processing speed of modern computers.

It is often interesting to accept a limitation and programmable calculators fit the bill. They are powerful enough for this sort of problem, while being limited in memory compared with desktop computers. So, my challenge is: How many d.p.'s can you calculate on a single programmable calculator?

What is the Point of Calculating Pi?

For the professional programmers, writing pi calculation programs tests their ingenuity on parallel processing which can be transferred to real life scientific problems, e.g. climate change. The digits themselves could in principle be used if you need a random number generator.

For you and I, there is no point whatsoever! Just have fun with the challenge!

References

Bailey, David H., Borwein, Peter B., and Plouffe, Simon (April 1997). "On the Rapid Computation of Various Polylogarithmic Constants". Mathematics of Computation 66 (218): 903–913. doi:10.1090/S0025-5718-97-00856-9

Beckmann, P., A history of pi, Barnes and Noble Books, ISBN 0-88029-418-3, 1993.

Yoshio Mikami (1913). Development of Mathematics in China and Japan. B. G. Teubner. p. 136.

Palmer, J. Pi Calculated to a record number of digits, BBC News, 6 January 2010.

Palmer, J. Pi record smashed as team finds two-quadrillionth digit, BBC News, 16 September 2010.

JA enjoying a well-earned break at Bryce N.P., Alda Oliveira-Austin

John Austin - Bringing atmospheric and environmental understanding to the community at large.

rss
Advertisement
Leave a comment

NOTE: Because you are not a Suite101 member, your comment will be moderated before it is viewable.
Submit
What is 4+5?
Advertisement
Advertisement