• date post

23-Aug-2019
• Category

## Documents

• view

215

0

Embed Size (px)

### Transcript of Programs to Calculate some Mathematical Constants to Large ... · PDF filePrograms to...

• Programs to Calculate some Mathematical

Constants to Large Precision

Document Version 1.50

Prepared Using LATEX

by

Stefan Spännare

E-mail: [email protected]paennare.se

September 19, 2007

1

• Contents

1 Introduction

2 Disclaimer

3 General information

4 Some numerical values

5 Algorithms for π 5.1 π, Borwein’s 4-th order 5.2 π, Borwein’s 2-th order 5.3 π, Gauss-Legendre, AGM 5.4 π, Ramanujan series 5.5 π, Chudnovsky series

6 Algorithms for ex = exp (x) and e = exp (1) 6.1 ex = exp (x), Newton’s Iteration 6.2 e = exp (1), using the series

1/k! 6.3 e = exp (1),

1/k! using FEE

7 Algorithms for ln (x) and ln (2) 7.1 ln (x), AGM 7.2 ln (2), arctanh(x) based methods

8 Algorithms for Euler C, γ

9 Algorithms for Γ(1/3) and Γ(1/4) 9.1 Γ(1/3) 9.2 Γ(1/4) 9.3 AGM

10 Algorithms for Catalan’s constant G

11 Algorithms for Apery’s constant ζ(3)

12 Algorithms for ζ(s)

13 Algorithms for inversion, division, square and cube roots 13.1 Inversion 1/v and division 13.2 1/

√ v and

√ v

13.3 1/v 1 3 and v

1 3

13.4 1/v 1 4 and v

1 4

14 Time complexity of algorithms

15 Accuracy and benchmarks 15.1 Accuracy of calculations 15.2 Benchmarks

16 References 16.1 Book and article references 16.2 Internet references

2

• 1 Introduction

Note, this document is under development. Please look back for updated versions.

This documents describes algorithms to calculate some mathematical constants used by some of the C- programs in the program package SSPROG. Some timings, benchmarks and references are also given. The programs are not so fast (much faster programs exist especially for π) but they demonstrates the principle of multi precision calculations. See also the header of each C-program source code for more information.

At present algorithms used by the programs sspi, sseln2, ssgamma, ssgam134, sscatal, sszeta3, sszeta and sspieln2 (in the NUMBERS directory) are described in this document.

The home page of the author and the web page of the program package and this document are found here:

http://www.spaennare.se/index.html

http://www.spaennare.se/ssprog.html

2 Disclaimer

For all the programs in this package the following statement is valid:

I make no warranties that this program is (1) free of errors, (2) consistent with any standard merchantabil- ity, or (3) meeting the requirements of a particular application. This software shall not, partly or as a whole, participate in a process, whose outcome can result in injury to a person or loss of property. It is solely designed for analytical work. Permission to use, copy, and distribute is hereby granted without fee, providing that the header above including this notice appears in all copies.

Please report comments and bugs in both the programs and this document to:

E-mail: [email protected]

3 General information

The mathematical constants are calculated to desired precision (i.e. n decimal digits). Functions for multi precision calculations are included in the programs in this package. Especially fast FFT based multiplication must be used for large numbers. This presentation of the algorithms is quite brief (only the formulas). To put the constants in a wider context see for example reference . This is the default reference throughout this document.

The natural logarithm is sometimes denoted log (x) and sometimes ln (x). The author prefers ln (x) which is used in this document.

A comment regarding the FEE (Fast E-function Evaluation) method for very fast evaluation of transcen- dental functions (series). The method was invented 1991 by Ekatherina A. Karatsuba, Russia. Another method called ”divide and conquer” was invented earlier by Anatoly Karatsuba. This method was then called ”binary splitting” by some people. However, by later years it seems as if ”binary splitting” has been erroneously taken as a name also for the FEE method by some people preferably in the western countries. The correct name FEE is used throughout this document. See also references ,  and .

3

• 4 Some numerical values

Here are presented numerical values of some mathematical constants to 75 decimal places.

π = 3.141592653589793238462643383279502884197169399375105820974944592307816406286 . . .

e = 2.718281828459045235360287471352662497757247093699959574966967627724076630353 . . .

ln(2) = 0.693147180559945309417232121458176568075500134360255254120680009493393621969 . . .

γ = 0.577215664901532860606512090082402431042159335939923598805767234884867726777 . . .

Γ(1/3) = 2.678938534707747633655692940974677644128689377957301100950428327590417610167 . . .

Γ(1/4) = 3.625609908221908311930685155867672002995167682880065467433377999569919243538 . . .

G = 0.915965594177219015054603514932384110774149374281672134266498119621763019776 . . .

ζ(2) = 1.644934066848226436472415166646025189218949901206798437735558229370007470403 . . .

ζ(3) = 1.202056903159594285399738161511449990764986292340498881792271555341838205786 . . .

ζ(5) = 1.036927755143369926331365486457034168057080919501912811974192677903803589786 . . .

ζ(7) = 1.008349277381922826839797549849796759599863560565238706417283136571601478317 . . .

ζ(10) = 1.000994575127818085337145958900319017006019531564477517257788994636291465151 . . .

ζ(100) = 1.000000000000000000000000000000788860905221011807352053782766041368789625343 . . .

√ 2 = 1.414213562373095048801688724209698078569671875376948073176679737990732478462 . . .

√ 3 = 1.732050807568877293527446341505872366942805253810380628055806979451933016908 . . .

√ 5 = 2.236067977499789696409173668731276235440618359611525724270897245410520925637 . . .

√ 7 = 2.645751311064590590501615753639260425710259183082450180368334459201068823230 . . .

√ 5+1

2 = 1.618033988749894848204586834365638117720309179805762862135448622705260462818 . . .

4

• 5 Algorithms for π

5.1 π, Borwein’s 4-th order

This algorithm gives four times more digits per iteration.

1. Initial value settings:

a0 = 6 − 4 √

2

y0 = √

2 − 1

s0 = 8

2. Iterate the following to desired accuracy:

yk+1 = 1 − (1 − y4k)

1 4

1 + (1 − y4k) 1 4

ak+1 = ak(1 + yk+1) 4 − skyk+1(1 + yk+1 + y2k+1)

sk+1 = 4sk

3. π is approximated after n iterations as:

π ≈ 1

an

5.2 π, Borwein’s 2-th order

This algorithm gives two times more digits per iteration.

1. Initial value settings:

x0 = √

2

π0 = 2 + √

2

y0 = 2 1 4

2. Iterate the following to desired accuracy:

xi+1 = 1

2 ( √

xi + 1

√ xi

)

πi+1 = πi xi+1 + 1

yi + 1

yi+1 = yi √

xi+1 + 1√

xi+1

yi + 1

3. π is approximated after n iterations as:

π ≈ πn

5

• 5.3 π, Gauss-Legendre, AGM

This algorithm of calculating π is based on AGM (Arithmetic Geometric Mean).

This algorithm gives two times more digits per iteration.

1. Initial value settings:

a0 = 1

b0 = 1 √

2

t0 = 1

4

s0 = 1

2. Iterate the following to desired accuracy:

ak+1 = ak + bk

2 arithmetic mean

bk+1 = √

akbk geometric mean

tk+1 = tk − sk(ak − ak+1)2

sk+1 = 2sk

3. π is approximated after n iterations as:

π ≈ (an + bn)

2

4tn

5.4 π, Ramanujan series

In 1914 the mathematician S. Ramanujan from India published the following famous series for π:

1

π =

2 √

2

9801

∞ ∑

n=0

(4n)! (1103 + 26390n)

(n!)4 (396)4n

Each term of the series adds about 8 digits to π. The series can be computed very fast to desired precision using FEE.

5.5 π, Chudnovsky series

In the 1990s David and Gregory Chudnovsky found the following series (of Ramanujan type) for π:

1

π =

12

C √

C

∞ ∑

n=0

(−1)n (6n)! (A + Bn) (3n)! (n!)3 (C)3n

Here A = 13591409, B = 545140134 and C = 640320.

Each term of the series adds about 14 digits to π, which is remarkable. The series can be computed very fast to desired precision using FEE.

6

• 6 Algorithms for ex = exp (x) and e = exp (1)

6.1 ex = exp (x), Newton’s Iteration

exp (x) can be calculated using Newton’s iteration:

yk+1 = yk − f(yk)

f ′(yk)

If f(y) = ln (y) − x Newton’s iteration for exp (x) is defined by:

yk+1 = yk · (1 + x − ln (yk))

Here y0 should be a good starting value for exp (x). This algorithm gives two times more digits per iteration.

6.2 e = exp (1), using the series ∑

1/k!

e = exp (1) can be calculated by the series:

e = exp (1) =

∞ ∑

k=0

1

k!

By rearranging ∑

1/k!, e = exp(1) can be calculated by the following algorithm (C-like notation):

a=1;

b=0;

for (i=n; i>=1; i--) {

a=a*i;

b=b+a;

} /* for i */

e=b/a;

Here n! is the factorial that fits into t