Algorithms for mathematical constants

Most mathematical constants are evaluated using the generic hypergeometric summation code.

Pi

π is computed using the Chudnovsky series

1π=12k=0(1)k(6k)!(13591409+545140134k)(3k)!(k!)36403203k+3/2

which is hypergeometric and adds roughly 14 digits per term. Methods based on the arithmetic-geometric mean seem to be slower by a factor three in practice.

A small trick is to compute 1/640320 instead of 640320 at the end.

Logarithms of integers

The standalone constant log(2) is computed using Zuniga’s series [Zun2023b]

log(2)=12n=113888n(1794n297)n(2n1)n!(12)n(16)n(56)n.

Logarithms of other small integers are in certain situations computed using Machin-like formulas, e.g.:

log(10)=46atanh(1/31)+34atanh(1/49)+20atanh(1/161)

Euler’s constant

Euler’s constant γ is computed using the Brent-McMillan formula ([BM1980], [MPFR2012])

γ=S0(2n)K0(2n)I0(2n)log(n)

in which n is a free parameter and

S0(x)=k=0Hk(k!)2(x2)2k,I0(x)=k=01(k!)2(x2)2k
2xI0(x)K0(x)k=0[(2k)!]3(k!)482kx2k.

All series are evaluated using binary splitting. The first two series are evaluated simultaneously, with the summation taken up to k=N1 inclusive where Nαn+1 and α4.9706257595442318644 satisfies α(logα1)=3. The third series is taken up to k=2n1 inclusive. With these parameters, it is shown in [BJ2013] that the error is bounded by 24e8n.

Catalan’s constant

Catalan’s constant is computed using the hypergeometric series

C=1768k=1(4096)kP(k)k3(2k1)(3k1)(3k2)(6k1)(6k5)(5kk)(10k5k)(12k6k)

where

P(k)=43203456k6+92809152k576613904k4+30494304k36004944k2+536620k17325,

discovered by Zuniga [Zun2023]. It was previously computed using a series given in [PP2010].

Apery’s constant

Apery’s constant ζ(3) is computed using the hypergeometric series

ζ(3)=148k=1(1)k1P(k)k5(2k1)3(3k1)(3k2)(4k1)(4k3)(6k1)(6k5)(5kk)(5k2k)(9k4k)(10k5k)(12k6k)

where

P(k)=1565994397644288k116719460725627136k10+12632254526031264k913684352515879536k8+9451223531851808k74348596587040104k6+1352700034136826k5282805786014979k4+38721705264979k33292502315430k2+156286859400k3143448000,

discovered by Zuniga [Zun2023].

Khinchin’s constant

Khinchin’s constant K0 is computed using the formula

logK0=1log2[k=2N1log(k1k)log(k+1k)+n=1ζ(2n,N)nk=12n1(1)k+1k]

where N2 is a free parameter that can be used for tuning [BBC1997]. If the infinite series is truncated after n=M, the remainder is smaller in absolute value than

n=M+1ζ(2n,N)=n=M+1k=0(k+N)2nn=M+1(N2n+0(t+N)2ndt)=n=M+11N2n(1+N2n1)n=M+1N+1N2n=1N2M(N1)1N2M.

Thus, for an error of at most 2p in the series, it is sufficient to choose Mp/(2log2N).

Glaisher’s constant

Glaisher’s constant A=exp(1/12ζ(1)) is computed directly from this formula. We don’t use the reflection formula for the zeta function, as the arithmetic in Euler-Maclaurin summation is faster at s=1 than at s=2.

Reciprocal Fibonacci constant

We use Gosper’s series ([Gos1974], corrected in [Arn2012])

n=11Fn=n=0(1)n(n1)/2(F4n+3+(1)nF2n+2)F2n+1F2n+2L1L3L2n+1

where Ln=2Fn1+Fn denotes a Lucas number. The truncation error after N1 terms is bounded by (1/ϕ)N2. The series is not of hypergeometric type, but we can evaluate it in quasilinar time using binary splitting; factoring out a multiplicative recurrence for L1L3 allows computing the series as a product of O(p) matrices with O(p)-bit entries.