33
An Introduction to high precision calculations of well-known mathematical constants by Kurt Calder Calculating Euler’s Number “e” using continued fractions Calculating the Golden Ratio using continued fractions Calculating the square root of 2 using continued fractions Calculating pi using ArcTan series. Calculating pi to 10 trillion digits!!

Calculating Euler’s Number “e” using continued fractions

  • Upload
    dallon

  • View
    49

  • Download
    3

Embed Size (px)

DESCRIPTION

An Introduction to high precision calculations of well-known mathematical constants by Kurt Calder. Calculating Euler’s Number “e” using continued fractions Calculating the Golden Ratio using continued fractions Calculating the square root of 2 using continued fractions - PowerPoint PPT Presentation

Citation preview

Page 1: Calculating Euler’s Number “e” using continued fractions

An Introduction to high precision calculationsof well-known mathematical constants

byKurt Calder

Calculating Euler’s Number “e” using continued fractionsCalculating the Golden Ratio using continued fractions

Calculating the square root of 2 using continued fractionsCalculating pi using ArcTan series.Calculating pi to 10 trillion digits!!

Page 2: Calculating Euler’s Number “e” using continued fractions

Calculating Euler’s Number “e” using continued fractions

• A continued fraction is a representation of a fraction in the following form:

• It can be a finite continued fraction, where n is a non-negative integer, a0 is an integer, and ai is a positive integer, for i=1,…,n. It can also be an infinite continued fraction. It is the latter that we will examine today.

Page 3: Calculating Euler’s Number “e” using continued fractions

Calculating Euler’s Number “e” using continued fractions

• We will use the following formula to calculate e.

• To evaluate an infinite continued fraction, select a point in the c.f. and omit everything after it. You are left with a finite c.f. which can then be evaluated.

Page 4: Calculating Euler’s Number “e” using continued fractions

Calculating Euler’s Number “e” using continued fractions

•We will use the following formula to calculate e.

An example above. If we omit everything after the 6, we are left with which evaluates to 19/7.

Page 5: Calculating Euler’s Number “e” using continued fractions

Calculating Euler’s Number “e” using continued fractions

•We will use the following formula to calculate e.

An example above. If we omit everything after the 10, we are left with which evaluates to 1 + 122/71.

Page 6: Calculating Euler’s Number “e” using continued fractions

Calculating Euler’s Number “e” using continued fractions

• Now we know what we wish to calculate.• The next question is how do we calculate it.

Page 7: Calculating Euler’s Number “e” using continued fractions

Calculating Euler’s Number “e” using continued fractions

• So our algorithm looks like the followingN=1 ; Numerator is 1D=4*n + 2 ; Denominator is the last termWhile n > 1 { n = n – 1 ; decrement current term m = 4 * n + 2 ; m is the current term multiplier A = m * D + N ; A is temporary placeholder N = D D = A }‘ Calculate 2 / (1 + N/D) = 2D / (D + N)A = D + NN = 2 * DD = A‘ Subtract out integer portionN = N – D‘ Divide N / D

Page 8: Calculating Euler’s Number “e” using continued fractions

Calculating Euler’s Number “e” using continued fractions

• Dividing N / D

A = q * Dwhile A > N ‘ check for overestimate { q = q – 1 A = q * D }Save/print q ‘ Make sure to save leading zeroes

(repeat to get next q until all the digits we have accumulated in q = “digits in N” + “digits in D” – 1)

𝑞=⌊𝑁 𝑖∗10

9+𝑁 𝑖−1

𝐷 𝑗∗109+𝐷 𝑗−1

Page 9: Calculating Euler’s Number “e” using continued fractions

Calculating Euler’s Number “e” using continued fractions

'e' Calculation using 2/1+1/6+1/10…

Terms Numerator (N) Denominator (D) ValueSignificant Digits

# digits in (N) + # digits in (D) Time (sec)

1 5 7 2.71428571428571428571428571428571 2 2 0

2 51 71 2.71830985915492957746478873239437 3 4 0

3 719 1001 2.71828171828171828171828171828172 6 7 0

4 12993 18089 2.71828182873569572668472552379899 9 10 0

5 286565 398959 2.71828182845856341127785060620264 11 12 0

6 7463683 10391023 2.71828182845904585140462108494996 15 15 0

7 224197055 312129649 2.71828182845904523475756063147977 17 18 0

8 7630163553 10622799089 2.71828182845904523536075323018848 21 21 0

9 290170412069 403978495031 2.71828182845904523536028717990009 24 24 0

10 12194787470451 16977719590391 2.71828182845904523536028747150336 27 28 0100 220 digits 220 digits 439 440 <.1

1000 3172 digits 3172 digits 6343 6344 0.43810000 41683 digits 41683 digits 83365 83366 9.0197001 500002 digits 500003 digits 1000003 1000005 1513

100000 516782 digits 516783 digits 1033564 1033565 1277120000 629640 digits 629640 digits 1259279 1259280 1588

Page 10: Calculating Euler’s Number “e” using continued fractions

Calculating Euler’s Number “e” using continued fractions

• Since the algorithm used here uses simple multiplication and division, both of which are known to be O(n2), the overall efficiency is O(n2).

• Note: The next improvement planned is an FFT multiplication method in “The Art of Computer Programming – Vol. 2” by Donald Knuth, which is O(N1.63).

Page 11: Calculating Euler’s Number “e” using continued fractions

Calculating the Golden Ratio using continued fractions

• We will use the following continued fraction representation to calculate

The Golden Ratio is the solution to the following quadratic equation: x2 – x – 1 = 0. The values are approximately 0.618033988749894848… and 1.618033988749894848…

𝜑=1+1

1+1

1+ 1

1+ 1

1+ 1

1+ 11+…

Page 12: Calculating Euler’s Number “e” using continued fractions

Calculating the Golden Ratio using continued fractions

• The continued fraction form for the Golden Ratio is the simplest of all continued fractions, and we will use this to improve the speed of our calculation.

𝑁 𝑖+42

𝐷𝑖+42=267914296𝐷 𝑖+165580141𝑁 𝑖

433494437𝐷 𝑖+267914296𝑁 𝑖

Page 13: Calculating Euler’s Number “e” using continued fractions

Calculating the Golden Ratio using continued fractions

phi Calculation using 1/1+1/1+1/1…Passes at 42 terms/ pass Numerator (N) Denominator (D) Value

Significant Digits

# digits in (N) + # digits in (D) Time (sec)

1 433494437 7014087330.61803398874989484911360520514078 17 18 0

2 259695496911122585 420196140727489673 0.61803398874989484820458683436563812025 34 36 056 501 digits 501 digits 1000 1002 0.062

556 5004 digits 5004 digits 10006 10008 0.4645557 50006 digits 50006 digits 100010 100012 18.263

55556 500001 digits 500001 digits 1000000 1000002 1162.959

Page 14: Calculating Euler’s Number “e” using continued fractions

Calculating the Square Root of 2 using continued fractions

• We will use the following continued fraction representation to calculate the square root of 2.

√2=1+ 1

2+1

2+ 1

2+ 1

2+ 1

2+ 12+…

Page 15: Calculating Euler’s Number “e” using continued fractions

Calculating the Square Root of 2 using continued fractions

• Since the continued fraction form for the square root of 2 is similar to that for the Golden Ratio, we will use this to improve the speed of our calculation using the same method as before. This gives us the following relationship.

𝑁 𝑖+23

𝐷𝑖+23=225058681𝐷 𝑖+93222358𝑁 𝑖

543339720𝐷𝑖+225058681𝑁 𝑖

Page 16: Calculating Euler’s Number “e” using continued fractions

Calculating the Square Root of 2 using continued fractions

Square Root of 2 Calculation using 1/2+1/2+1/2…

Passes at 23 terms/pass Numerator (N) Denominator (D) Value

Significant Digits

# digits in (N) + # digits in (D) Time (sec)

1 318281039 7683984010.41421356237309504760408786951653 17 18 02 202605639573839043 489133282872437279 0.41421356237309504880168872420969808152 34 36 0

56 502 digits 502 digits 1002 1004 0.064556 5001 digits 5001 digits 10000 10002 0.462

5557 50006 digits 50006 digits 100010 100012 12.9955557 500006 digits 500006 digits 1000010 1000012 1060.94

Page 17: Calculating Euler’s Number “e” using continued fractions

Calculating pi using ArcTan series

• For calculating pi, we will use the following infinite series for the inverse tangent.

tan−1𝑥=𝑥− 𝑥3

3+𝑥

5

5−𝑥7

7+…

Page 18: Calculating Euler’s Number “e” using continued fractions

Calculating pi using ArcTan series

• We will use the following three different series to compare efficiency of the formulas.

These formulas were used as recently as the 1970s to compute the world record number of digits of pi.

Page 19: Calculating Euler’s Number “e” using continued fractions

Calculating pi using ArcTan series

If we wish to calculate p digits of pi, then when calculatingthen we must calculate each term until .

Solving for n gives us the exponent that we must calculate to for the desired precision.

𝑛=log𝑥2+𝑝 log𝑥 10+ log𝑥𝑚

Page 20: Calculating Euler’s Number “e” using continued fractions

Calculating pi using ArcTan series

• Using p=1000 digits as an example in the previous equation for each of the three methods for calculating pi, we obtain the following efficiencies.

For -> 797 + 570 + 421 = 1787 terms.

For -> 1431 + 421 = 1852 terms.

For -> 1108 + 570 + 421 = 2098 terms.

Page 21: Calculating Euler’s Number “e” using continued fractions

Calculating pi using ArcTan series

• How do we go about using this formula to calculate pi?

Page 22: Calculating Euler’s Number “e” using continued fractions

Calculating pi using ArcTan series

Comparison of computations

Value Terms Numerator (N) Denominator (D)Significant

Digits Time (sec) CPU (sec) CPU Cycles

e (cont. frac) 97001 500002 digits 500003 digits 1000003 1513 1405.428 4,629,760,711,679

e (inf. Series) 205024 n/a n/a 1000008 1794.415 1792.435 5,897,854,585,415

Golden Ratio 55556 500001 digits 500001 digits 1000000 1162.959 1101.819 3,626,101,120,763

Sqrt(2) 55557 500006 digits 500006 digits 1000010 1060.94 1024.739 3,374,822,480,565

Pi-algorithm 1 1786606 n/a n/a 1000008 9937 9835 32,286,114,285,355

Pi-algorithm 2 1851127 n/a n/a 1000008 9626 9528 31,289,100,638,649

Pi-algorithm 3 2097277 n/a n/a 1000008 10908 10886 35,788,904,940,877

Page 23: Calculating Euler’s Number “e” using continued fractions

Calculating pi to 10 trillion digits!!

• The current world record for the number of digits of pi calculated is 10 trillion digits announced October 17th, 2011, by Alexander Yee and Shigeru Kondo after ten months of computations on a home computer.

• Alexander Yee is currently a graduate student at the University of Illinois studying Computer Science.

Page 24: Calculating Euler’s Number “e” using continued fractions

Calculating pi to 10 trillion digits!!

• How was this feat accomplished?

Page 25: Calculating Euler’s Number “e” using continued fractions

Calculating pi to 10 trillion digits!!

• First, the formulas used are much more efficient.

• For the main computation, the following formula was used:– Chudnovsky Formula:

Page 26: Calculating Euler’s Number “e” using continued fractions

Calculating pi to 10 trillion digits!!

• Verification was done using the following two formulas: – Plouffe's Formula:

– Bellard's Formula:

Page 27: Calculating Euler’s Number “e” using continued fractions

Calculating pi to 10 trillion digits!!

• Next, the multiplication algorithms used are much more efficient than the standard method we are taught in grade school.– The efficiency of the algorithm we are all familiar

with for calculating the product of two n-digit numbers is O(n2).

– The efficiency of the algorithm used here is currently unpublished, however, it is faster than the Fast Fourier Transform, which has efficiency of O(n log(n)). It uses Hybridized Number-Theoretic Transforms.

Page 28: Calculating Euler’s Number “e” using continued fractions

Calculating pi to 10 trillion digits!!

• Next, the code (written in C++) was optimized for Intel processors, using multi-threading and multi-core capabilities, which allow many computations to be done in parallel.

• Error-detection and correction is implemented. Errors that were observed in about 1 in 1017 calculations had to be detected and corrected.

Page 29: Calculating Euler’s Number “e” using continued fractions

Calculating pi to 10 trillion digits!!

• Next, even though off-the-shelf hardware was used, the configuration of the home PC is more than almost any hardcore PC gamer/enthusiast.

Page 30: Calculating Euler’s Number “e” using continued fractions

Calculating pi to 10 trillion digits!!

• The computer had the following specifications:– Processor: 2 x Intel Xeon X5680 @ 3.33 GHz - (12 physical cores,

24 hyperthreaded)– Memory:96 GB DDR3 @ 1066 MHz - (12 x 8 GB - 6 channels) -

Samsung (M393B1K70BH1)– Motherboard:Asus Z8PE-D12– Hard Drives:1 TB SATA II (Boot drive) - Hitachi (HDS721010CLA332)

3 x 2 TB SATA II (Store Pi Output) - Seagate (ST32000542AS)16 x 2 TB SATA II (Computation) - Seagate (ST32000641AS)

– Raid Controller:2 x LSI MegaRaid SAS 9260-8i– Operating System:Windows Server 2008 R2 Enterprise x64– Built By:Shigeru Kondo

Page 31: Calculating Euler’s Number “e” using continued fractions

Calculating pi to 10 trillion digits!!

Comparison of computations

Value Terms Numerator (N) Denominator (D)Significant

Digits Time (sec) CPU (sec) CPU Cycles

e (cont. frac) 97001 500002 digits 500003 digits 1000003 1513 1405.428 4,629,760,711,679

e (inf. Series) 205024 n/a n/a 1000008 1794.415 1792.435 5,897,854,585,415

Golden Ratio 55556 500001 digits 500001 digits 1000000 1162.959 1101.819 3,626,101,120,763

Sqrt(2) 55557 500006 digits 500006 digits 1000010 1060.94 1024.739 3,374,822,480,565

Pi-algorithm 1 1786606 n/a n/a 1000008 9937 9835 32,286,114,285,355

Pi-algorithm 2 1851127 n/a n/a 1000008 9626 9528 31,289,100,638,649

Pi-algorithm 3 2097277 n/a n/a 1000008 10908 10886 35,788,904,940,877

y-cruncher 73942 n/a n/a 1048576 ??? ??? ???

Page 32: Calculating Euler’s Number “e” using continued fractions

Calculating pi to 10 trillion digits!!

The world record pi program is over 10,000 times faster than the program demonstrated today!!!

Comparison of computations

Value Terms Numerator (N) Denominator (D)Significant

Digits Time (sec) CPU (sec) CPU Cycles

e (cont. frac) 97001 500002 digits 500003 digits 1000003 1513 1405.428 4,629,760,711,679

e (inf. Series) 205024 n/a n/a 1000008 1794.415 1792.435 5,897,854,585,415

Golden Ratio 55556 500001 digits 500001 digits 1000000 1162.959 1101.819 3,626,101,120,763

Sqrt(2) 55557 500006 digits 500006 digits 1000010 1060.94 1024.739 3,374,822,480,565

Pi-algorithm 1 1786606 n/a n/a 1000008 9937 9835 32,286,114,285,355

Pi-algorithm 2 1851127 n/a n/a 1000008 9626 9528 31,289,100,638,649

Pi-algorithm 3 2097277 n/a n/a 1000008 10908 10886 35,788,904,940,877

y-cruncher 73942 n/a n/a 1048576 0.352 0.352 3,011,376,940

Page 33: Calculating Euler’s Number “e” using continued fractions

References

• “A trillion digits of pi” http://www.numberworld.org/misc_runs/pi-10t/details.html

• FFT algorithm http://numbers.computation.free.fr/Constants/Algorithms/fft.html

• D.E. Knuth, The Art of Computer Programming, Vol. II, Seminumerical Algorithms, Addison Wesley, (1998)