FLINT3.7.0-dev
Algorithm

Mathematical constants

Cost
O(M(n)log⁡2n)O(M(n) \log^2 n) for the hypergeometric constants by binary splitting and O(M(n)nlog⁡n)O(M(n) \sqrt{n} \log n) for the reciprocal Fibonacci constant; Khinchin's constant and Glaisher's constant (below about 10510^5 to 3.5⋅1053.5 \cdot 10^5 bits, depending on the number of threads) use sums of many full-precision terms and are much slower; Glaisher's constant at higher precision costs O~(n1.5)\tilde O(n^{1.5}).

Most of the mathematical constants provided by arb are sums of hypergeometric series, series whose term ratio is a rational function of the index, and are evaluated by binary splitting. The series for π\pi, ee, log⁡2\log 2, log⁡10\log 10, γ\gamma, Catalan's constant, ζ(3)\zeta(3) and ζ(5)\zeta(5) are summed by the mp_real module, and the arb_const_ functions call it through _mp_real_const_arb; the formulas were chosen as the fastest among those collected by y-cruncher [Yee2025]. The implementation side (splitting trees, threads, the shared cache of exact floors) is described in Constants in mp_real; the sections below give the mathematics and the remaining constants.

Binary splitting#

Consider a sum S=∑k=0N−1a(k)/b(k)⋅∏j<kp(j)/q(j)S = \sum_{k=0}^{N-1} a(k)/b(k) \cdot \prod_{j<k} p(j)/q(j) with polynomials a,b,p,qa, b, p, q with integer coefficients. For 0≤u<v≤N0 \le u < v \le N define P(u,v)=∏j=uv−1p(j)P(u, v) = \prod_{j=u}^{v-1} p(j), Q(u,v)=∏j=uv−1q(j)Q(u, v) = \prod_{j=u}^{v-1} q(j), and T(u,v)=Q(u,v)∑k=uv−1(…)T(u, v) = Q(u, v) \sum_{k=u}^{v-1} (\ldots), the partial sum scaled to an integer. Then for u<w<vu < w < v

P(u,v)=P(u,w)P(w,v),Q(u,v)=Q(u,w)Q(w,v),T(u,v)=T(u,w)Q(w,v)+P(u,w)T(w,v)P(u, v) = P(u, w) P(w, v), \quad Q(u, v) = Q(u, w) Q(w, v), \quad T(u, v) = T(u, w) Q(w, v) + P(u, w) T(w, v)

(with the obvious extension for a/ba/b), so the exact sum is obtained by a balanced recursion and one final division T/QT/Q.

Proposition 1. If the series converges geometrically, so that N=O(n)N = O(n) terms give nn bits, and the integers P(u,v),Q(u,v),T(u,v)P(u, v), Q(u, v), T(u, v) have O((v−u)log⁡v)O((v - u) \log v) bits, binary splitting computes SS to nn bits in O(M(nlog⁡n)log⁡n)O(M(n \log n) \log n) bit operations, which is O(M(n)log⁡2n)O(M(n) \log^2 n).

Proof. At each of the O(log⁡N)O(\log N) levels of the recursion, the numbers multiplied have a total size of O(Nlog⁡N)=O(nlog⁡n)O(N \log N) = O(n \log n) bits, and multiplication is superadditive, so each level costs O(M(nlog⁡n))O(M(n \log n)). The final division costs O(M(n))O(M(n)).

The series below add between 2 and 47 bits per term. The constant factor is what distinguishes the formulas, and it is governed by the number of bits per term and the size of the coefficients [HP1998] [BZ2011].

Caching#

Each arb_const_ function keeps a thread-local cached ball. A request at precision pp above the cached precision recomputes the constant at p+32p + 32 bits; the result is then rounded to pp bits, and later requests at precision at most pp only round the cached value. π\pi, log⁡2\log 2 and γ\gamma are moreover read from static tables (of π/4\pi/4 and log⁡2\log 2 to 4608 bits, of γ\gamma to 3456 bits) below these sizes, correctly rounded to nearest with a radius of half a unit in the last place. The caches are freed by flint_cleanup.

π\pi#

π\pi is computed by the Chudnovsky series [CC1988]

1π=12∑k=0∞(−1)k(6k)! (13591409+545140134k)(3k)! (k!)3 6403203k+3/2,\frac{1}{\pi} = 12 \sum_{k=0}^{\infty} \frac{(-1)^k (6k)!\,(13591409 + 545140134 k)}{(3k)!\,(k!)^3\, 640320^{3k + 3/2}},

which adds about 47 bits (14 digits) per term. In the hypergeometric form used by mp_real, π=S/10005\pi = S / \sqrt{10005} with R(k)=(6k−5)(2k−1)(6k−1)R(k) = (6k - 5)(2k - 1)(6k - 1), P(k)=(13591409+545140134k)R(k)P(k) = (13591409 + 545140134 k) R(k) and Q(k)=−(6403203/24)k3Q(k) = -(640320^3/24) k^3. Methods based on the arithmetic-geometric mean [Sal1976] [Bre1976agm] have a better asymptotic complexity, O(M(n)log⁡n)O(M(n) \log n), but are about three times slower in practice. arb_const_sqrt_pi and arb_const_log_sqrt2pi are computed from arb_const_pi with arb_sqrt and arb_log.

ee#

e=∑k≥01/k!e = \sum_{k \ge 0} 1/k! is summed by binary splitting, with P=1P = 1 and Q(k)=kQ(k) = k; this is the simplest hypergeometric series and its cost is dominated by the final division.

Logarithms of integers#

log⁡2\log 2 is computed by Zuniga's series [Zun2025]

log⁡2=12160∑k=0∞(1497+1794k)∏j=1kj(2j−1)216(6j+1)(6j+5),\log 2 = \frac{1}{2160} \sum_{k=0}^{\infty} (1497 + 1794 k) \prod_{j=1}^{k} \frac{j (2j - 1)}{216 (6j + 1)(6j + 5)},

which adds 11.9 bits per term. (Earlier versions used another series of Zuniga [Zun2023b], with terms decreasing like 3888−k3888^{-k}.) log⁡10=log⁡2+log⁡5\log 10 = \log 2 + \log 5 uses the Machin-type formulas for the first three primes in terms of

atanh⁡(1/31),atanh⁡(1/49),atanh⁡(1/161),\operatorname{atanh}(1/31), \quad \operatorname{atanh}(1/49), \quad \operatorname{atanh}(1/161),

for example log⁡10=46atanh⁡(1/31)+34atanh⁡(1/49)+20atanh⁡(1/161)\log 10 = 46 \operatorname{atanh}(1/31) + 34 \operatorname{atanh}(1/49) + 20 \operatorname{atanh}(1/161), with the three series evaluated in parallel. The logarithms of more primes, used by the elementary functions (Elementary functions), come from larger sets of such formulas (arb_log_primes_vec_bsplit).

Euler's constant#

Euler's constant γ\gamma is computed by the Brent-McMillan formula [BM1980] [MPFR2012]

γ=S0(2n)−K0(2n)I0(2n)−log⁡n,\gamma = \frac{S_0(2n) - K_0(2n)}{I_0(2n)} - \log n,

where nn is a free parameter and

S0(x)=∑k=0∞Hk(k!)2(x2)2k,I0(x)=∑k=0∞1(k!)2(x2)2k,2xI0(x)K0(x)∼∑k=0∞[(2k)!]3(k!)482kx2k.S_0(x) = \sum_{k=0}^{\infty} \frac{H_k}{(k!)^2} \left(\frac{x}{2}\right)^{2k}, \quad I_0(x) = \sum_{k=0}^{\infty} \frac{1}{(k!)^2} \left(\frac{x}{2}\right)^{2k}, \quad 2x I_0(x) K_0(x) \sim \sum_{k=0}^{\infty} \frac{[(2k)!]^3}{(k!)^4 8^{2k} x^{2k}}.

The first two series are summed together up to k=N−1k = N - 1 with N≥αn+1N \ge \alpha n + 1, where α≈4.9706257595442318644\alpha \approx 4.9706257595442318644 satisfies α(log⁡α−1)=3\alpha(\log \alpha - 1) = 3, and the asymptotic series up to k=2n−1k = 2n - 1. With these parameters the error is bounded by 24e−8n24 e^{-8n} [BJ2013]. The current implementation sums S0S_0 and I0I_0 in one binary splitting over dual numbers, and chooses nn smooth over {2,3,5,7}\{2, 3, 5, 7\} so that log⁡n\log n is cheap; see Constants in mp_real.

Catalan's constant#

Catalan's constant is computed by the series of Pilehrood and Pilehrood [PP2010]

G=164∑k=1∞256k(580k2−184k+15) (2k)!3 (3k)!2k3(2k−1) (6k)!2,G = \frac{1}{64} \sum_{k=1}^{\infty} \frac{256^k (580 k^2 - 184 k + 15) \,(2k)!^3\,(3k)!^2}{k^3 (2k - 1)\,(6k)!^2},

which adds about 5.4 bits per term and was measured to be the fastest available formula.

ζ(3)\zeta(3) and ζ(5)\zeta(5)#

Apéry's constant ζ(3)\zeta(3) is computed by a hypergeometric series found by Zuniga [Zun2023],

ζ(3)=148∑k=1∞(−1)k−1P(k)k5(2k−1)3(3k−1)(3k−2)(4k−1)(4k−3)(6k−1)(6k−5)(5kk)(5k2k)(9k4k)(10k5k)(12k6k),\zeta(3) = \frac{1}{48} \sum_{k=1}^{\infty} \frac{(-1)^{k-1} P(k)}{k^5 (2k-1)^3 (3k-1)(3k-2)(4k-1)(4k-3)(6k-1)(6k-5) \binom{5k}{k}\binom{5k}{2k}\binom{9k}{4k}\binom{10k}{5k}\binom{12k}{6k}},

with P(k)P(k) a polynomial of degree 11 given in the source. ζ(5)\zeta(5) is computed from Z.-W. Sun's identity

ζ(5)=3S+56π2ζ(3)540,S=∑n=1∞(−127)n(560n4−640n3+408n2−136n+17) n!2(1/3)n(2/3)n n5(2n−1)4,\zeta(5) = \frac{3 S + 56 \pi^2 \zeta(3)}{540}, \quad S = \sum_{n=1}^{\infty} \left(-\frac{1}{27}\right)^n \frac{(560 n^4 - 640 n^3 + 408 n^2 - 136 n + 17)\, n!^2}{(1/3)_n (2/3)_n\, n^5 (2n-1)^4},

with the three parts SS, ζ(3)\zeta(3) and π\pi computed in parallel when threads are available.

Khinchin's constant#

Khinchin's constant K0K_0 is computed from the formula [BBC1997]

log⁡K0=1log⁡2[−∑k=2N−1log⁡(k−1k)log⁡(k+1k)+∑n=1∞ζ(2n,N)n∑k=12n−1(−1)k+1k],\log K_0 = \frac{1}{\log 2} \left[ -\sum_{k=2}^{N-1} \log \left(\frac{k-1}{k}\right) \log \left(\frac{k+1}{k}\right) + \sum_{n=1}^{\infty} \frac{\zeta(2n, N)}{n} \sum_{k=1}^{2n-1} \frac{(-1)^{k+1}}{k} \right],

where N≥2N \ge 2 is a free parameter (arb_const_khinchin uses N≈p0.35N \approx p^{0.35}). The finite sum has a minus sign: each product of logarithms is negative.

Proposition 2 (Truncation error). If the series over nn is truncated after n=Mn = M, the error inside the brackets is at most 1/N2M1/N^{2M}.

Proof. The inner alternating sums lie in (0,1](0, 1], so the remainder is bounded in absolute value by ∑n>Mζ(2n,N)/n≤∑n>Mζ(2n,N)\sum_{n > M} \zeta(2n, N)/n \le \sum_{n > M} \zeta(2n, N). By the integral bound,

∑n=M+1∞ζ(2n,N)=∑n=M+1∞∑k=0∞(k+N)−2n≤∑n=M+1∞(N−2n+∫0∞(t+N)−2n dt)=∑n=M+1∞1N2n(1+N2n−1),\sum_{n=M+1}^{\infty} \zeta(2n, N) = \sum_{n=M+1}^{\infty} \sum_{k=0}^{\infty} (k + N)^{-2n} \le \sum_{n=M+1}^{\infty} \left(N^{-2n} + \int_0^{\infty} (t + N)^{-2n}\, dt\right) = \sum_{n=M+1}^{\infty} \frac{1}{N^{2n}} \left(1 + \frac{N}{2n - 1}\right),

and since N/(2n−1)≤NN/(2n - 1) \le N, this is at most ∑n>M(N+1)N−2n=1N2M(N−1)≤1N2M\sum_{n > M} (N + 1) N^{-2n} = \frac{1}{N^{2M}(N - 1)} \le \frac{1}{N^{2M}}.

For an error of 2−p2^{-p} it therefore suffices to take M≥p/(2log⁡2N)M \ge p / (2 \log_2 N). The Hurwitz zeta values are computed as ζ(2n,N)=ζ(2n)−∑k=1N−1k−2n\zeta(2n, N) = \zeta(2n) - \sum_{k=1}^{N-1} k^{-2n}, with arb_zeta_ui and a vector of powers k−2nk^{-2n} that is updated from one nn to the next.

Glaisher's constant#

The Glaisher-Kinkelin constant A=exp⁡(1/12−ζ′(−1))A = \exp(1/12 - \zeta'(-1)) is computed directly from this formula, with ζ′(−1)\zeta'(-1) from acb_dirichlet_zeta_jet (see Zeta functions, polylogarithms and L-functions). Up to a cutoff (_acb_dirichlet_l_jet_use_afe: 3.5⋅1053.5 \cdot 10^5 bits with one thread, about 8⋅1048 \cdot 10^4 bits with 8 threads), this uses Euler-Maclaurin summation directly at s=−1s = -1; the reflection formula is not used for −4<Re⁡(s)<0-4 < \operatorname{Re}(s) < 0, since the arithmetic of Euler-Maclaurin summation is cheaper at s=−1s = -1 than at s=2s = 2 (by a factor 1.3–1.7 for ζ′(−1)\zeta'(-1)).

Euler-Maclaurin summation needs O(p)O(p) terms and O(p)O(p) Bernoulli numbers at precision pp, which costs O~(p2)\tilde O(p^2) time and O(p2)O(p^2) bits of memory (several gigabytes at p=4⋅105p = 4 \cdot 10^5). Above the cutoff, acb_dirichlet_zeta_jet instead computes ζ(−1+x)\zeta(-1+x) to O(x2)O(x^2) with the approximate functional equation (acb_dirichlet_l_fmpq_afe_jet), a sum of O(p)O(\sqrt{p}) incomplete gamma function jets evaluated by binary splitting, in time O~(p1.5)\tilde O(p^{1.5}) and with O(p)O(p) memory.

The reciprocal Fibonacci constant#

∑n≥11/Fn\sum_{n \ge 1} 1/F_n is computed from Gosper's series [Gos1974], corrected in [Arn2012],

∑n=1∞1Fn=∑n=0∞(−1)n(n−1)/2(F4n+3+(−1)nF2n+2)F2n+1F2n+2L1L3⋯L2n+1,\sum_{n=1}^{\infty} \frac{1}{F_n} = \sum_{n=0}^{\infty} \frac{(-1)^{n(n-1)/2} (F_{4n+3} + (-1)^n F_{2n+2})}{F_{2n+1} F_{2n+2} L_1 L_3 \cdots L_{2n+1}},

where Ln=2Fn−1+FnL_n = 2F_{n-1} + F_n is a Lucas number. The truncation error after N≥1N \ge 1 terms is bounded by (1/ϕ)N2(1/\phi)^{N^2}, so N≈1.2pN \approx 1.2 \sqrt{p} terms give pp bits. The series is not hypergeometric, but factoring out the multiplicative recurrence for L1L3⋯L_1 L_3 \cdots turns it into a product of O(p)O(\sqrt{p}) matrices with O(p)O(\sqrt{p})-bit entries, which binary splitting evaluates in quasilinear time.

Use in FLINT#

The complex versions in acb (for example acb_const_pi) call these functions. The constants Γ(1/3)\Gamma(1/3) and Γ(1/4)\Gamma(1/4), used by arb_hypgeom_gamma_fmpq, are also computed by mp_real; see Constants in mp_real and the gamma function at rational arguments.

The tutorial Computing π and other constants computes π\pi and other constants to many digits in complete programs.

Referenced from#

References#

Cite this page

The FLINT team, “Mathematical constants,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/special-functions/constants.html (generated 2026-11-02).