Of course PI (Π) can be determined by measuring a circle's circumference and diameter and dividing. The accuracy will be limited to a few digits. To get a lot of digits, other methods are used (why?). Some methods are much better than others. Vieta produced the first formula:
2/Π = √0.5 * √(0.5 + 0.5√0.5) * √(0.5 + 0.5V(0.5 + 0.5√0.5)) * ... (1)
This is another one:
Π2/6 = 1/12 + 1/22 + 1/33 … (2)
Wallis produced this one:
Π/4 = 2/3 * 4/3 * 4/5 * 6/5 * 6/7 * 8/7 * ... (3)
This one from Leibniz is a special case of a formula from James Gregory:
Π/4 = 1 - 1/3 + 1/5 - 1/7 + 1/9 ... (4)
With formulas like these, the more terms you use, the more accurate the results. Some of them give an answer that is too large, then too small, then too large, etc. with each added term. To implement these formulas effectively, you need to write a computer program. Computer programs follow a series of steps called an algorithm. The algorithms for these formulas need to loop back, adding one or more terms to the calculation each loop. This kind of process is called an iterative routine. Most computer languages have a fixed amount of accuracy or precision. Some give you a choice of two. Seven digits of accuracy is called single precision. You get 16 digits with double precision. For more digits than this you need special systems or special programming.
I implemented formula 3 with 2 terms averaged per loop. When done with single precision it converged on the number 3.141330, which is incorrect in the last 3 digits. This demonstrates the result of round-off error. With double precision it got the number 3.141514 after 10,000 loops. That number is correct to 5 digits. Formula 4 was implemented with 4 terms per loop. It got the number 3.141647 after 5,000 loops in single precision, and 3.141621 after 10,000 loops. In double precision it got 3.141618 after 10,000 loops. Formula 3 takes about 20 million terms to get single precision accuracy! Formulas 2 and 4 take about 4 million for the same. Each successive digit with these formulas takes 10 times longer to calculate than the previous one. With formula 4 it took 5 hours for the 10th digit on a Pentium 90 running Microsoft Quick-Basic.
This is a much faster formula that comes from the Hexadecimal expansion of PI:
Π = Σ(n=0 to ∞) {4/(8n +1) – 2/(8n+4) – 1/(8n+5) – 1/(8n+6)} * (1/16)n (5)
Formula 5 (above) achieves double precision accuracy almost instantly in 10 iterations! An even faster algorithm by Robert L. Brown based on arithmetic-geometric mean and circumscribed polygons of constant perimeter (originally discovered by Gauss) is shown below in BASIC language:
1 A = 1: X = 1: B = 1/SQR(2): C = 1/4
2 Y = A
3 A = (A + B) / 2
4 B = SQR(B * Y)
5 C = C - X * (A - Y) ^ 2
6 X = 2 * X
7 PI = ((A + B) ^ 2) / 4C
8 PRINT PI
9 GOTO 2
10 END
This method achieves single precision accuracy in 2 loops, and double precision accuracy in 3 loops! It is the 2nd fastest known method. In a system without accuracy limitations, it can compute PI to thousands of digits of accuracy.
Good Answers:
"Almost" Good Answers: