FLINT3.7.0-dev
Algorithm

Constants in mp_real

Cost
O(M(n)log⁡2n)O(M(n)\log^2 n) for each constant; Γ(1/4)\Gamma(1/4) from 2162^{16} limbs in O(M(n)log⁡n)O(M(n)\log n) plus the cost of π\pi.

mp_real computes the constants used throughout FLINT's floating-point code by binary splitting of hypergeometric series (Binary splitting of hypergeometric series in mp_real). The formulas were taken from the collection of y-cruncher [Yee2025], and for each constant the formula measured fastest in this implementation was chosen; the mathematical background of most of them is described in Mathematical constants.

The series#

ConstantFormula
π\piChudnovsky [CC1988], π=S/10005\pi = S/\sqrt{10005} (see below), 47.1 bits per term
log⁡2\log 2Zuniga [Zun2025], 12160∑k≥0(1497+1794k)∏j=1kj(2j−1)216(6j+1)(6j+5)\frac{1}{2160}\sum_{k \ge 0}(1497 + 1794k)\prod_{j=1}^k \frac{j(2j-1)}{216(6j+1)(6j+5)}, 11.9 bits per term
ee∑k≥01/k!\sum_{k \ge 0} 1/k!
GGPilehrood [PP2010], 164∑k≥1256k(580k2−184k+15)(2k)!3(3k)!2k3(2k−1)(6k)!2\frac{1}{64}\sum_{k \ge 1}\frac{256^k(580k^2 - 184k + 15)(2k)!^3(3k)!^2}{k^3(2k-1)(6k)!^2}
ζ(3)\zeta(3)a series of Zuniga (2023) with a numerator of degree 11
ζ(5)\zeta(5)Sun's identity (2025), ζ(5)=(3S+56π2ζ(3))/540\zeta(5) = (3S + 56\pi^2\zeta(3))/540 with a 3F2{}_3F_2-type series SS
Γ(1/3)\Gamma(1/3)(8101/4π/X)1/3(810^{1/4}\pi/X)^{1/3} with Guillera's series XX (2023)
Γ(1/4)\Gamma(1/4)(π6/(322S4))1/8(\pi^6/(322S^4))^{1/8} with Ebisu's series SS (2016), or the AGM

The Chudnovsky series in the format of mp_real_hypgeom_series is S=((cQ+cP∑k≥1P(k)Q(k)∏j<kR(j)Q(j))/cD)−1S = \bigl((c_Q + c_P\sum_{k \ge 1}\frac{P(k)}{Q(k)}\prod_{j<k}\frac{R(j)}{Q(j)})/c_D\bigr)^{-1} with cP=1c_P = 1, cQ=13591409c_Q = 13591409, cD=4270934400c_D = 4270934400, 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 + 545140134k)R(k) and Q(k)=−(6403203/24)k3Q(k) = -(640320^3/24)k^3; the example on Hypergeometric series runs it. Since mp_real_hypgeom_series gives FLINT_BITS(n−1)\mathtt{FLINT\_BITS}(n - 1) correct bits, the constants call it with one limb more than they need.

The parts of ζ(5)\zeta(5) (the series, ζ(3)\zeta(3) and π\pi) and of the Γ\Gamma values (the series and π\pi) are independent and run on separate threads. For Γ(1/4)\Gamma(1/4) above 2162^{16} limbs, the formula

Γ(1/4)=(2π)3/2agm⁡(1,2)\Gamma(1/4) = \sqrt{\frac{(2\pi)^{3/2}}{\operatorname{agm}(1, \sqrt 2)}}

is used instead, with the AGM (O(M(n)log⁡n)O(M(n)\log n)) computed in parallel with π\pi. log⁡10\log 10 is log⁡2+log⁡5\log 2 + \log 5 from the three-term Machin-type formula of the first three primes (atanh⁡(1/31)\operatorname{atanh}(1/31), atanh⁡(1/49)\operatorname{atanh}(1/49) and atanh⁡(1/161)\operatorname{atanh}(1/161), each by Zuniga's series where faster; Computing the logarithms). 2/π2/\pi and 1/log⁡2−11/\log 2 - 1 are derived from π\pi and log⁡2\log 2.

Euler's constant#

The Brent–McMillan algorithm [BM1980] with the error bound of [BJ2013] gives, for a parameter mm,

γ=S0I0−K0I02−log⁡m+O(e−8m),I0=∑k≥0(mkk!)2,S0=∑k≥0(mkk!)2Hk,\gamma = \frac{S_0}{I_0} - \frac{K_0}{I_0^2} - \log m + O(e^{-8m}), \qquad I_0 = \sum_{k \ge 0}\Bigl(\frac{m^k}{k!}\Bigr)^2, \quad S_0 = \sum_{k \ge 0}\Bigl(\frac{m^k}{k!}\Bigr)^2 H_k,

with K0=I0(2m)K0(2m)K_0 = I_0(2m)K_0(2m) evaluated by its asymptotic series and 8m≥plog⁡28m \ge p\log 2 for pp bits. S0S_0 and I0I_0 come from one binary splitting over about 4.97m4.97m terms in dual numbers.

Proposition 1. Let F(ε)=∑k≥0m2k/∏j=1k(j+ε)2F(\varepsilon) = \sum_{k \ge 0} m^{2k}\big/\prod_{j=1}^k (j + \varepsilon)^2 over Q[ε]/(ε2)\mathbb{Q}[\varepsilon]/(\varepsilon^2). Then I0=F(0)I_0 = F(0) and S0=−12F′(0)S_0 = -\tfrac12 F'(0).

Proof. ddε∏j=1k(j+ε)−2∣ε=0=−2∑j=1k1j∏j=1kj−2=−2Hk/k!2\frac{d}{d\varepsilon}\prod_{j=1}^k (j + \varepsilon)^{-2}\big|_{\varepsilon=0} = -2\sum_{j=1}^k \frac1j \prod_{j=1}^k j^{-2} = -2H_k/k!^2.

The splitting of FF carries a scalar PP, a dual number D=D0+D1ε=∏(k+1+ε)D = D_0 + D_1\varepsilon = \prod(k + 1 + \varepsilon) (so that the denominator is D2D^2) and T=T0+T1εT = T_0 + T_1\varepsilon, merged as

T=P1T2+D22T1,D=D1D2,P=P1P2,T = P_1 T_2 + D_2^2 T_1, \qquad D = D_1D_2, \qquad P = P_1P_2,

five full-size and five half-size products per merge. At the end, with X=T0+D02X = T_0 + D_0^2,

S0I0=2T0D1−T1D02D0X,K0I02=D04 TKX2QK,\frac{S_0}{I_0} = \frac{2T_0D_1 - T_1D_0}{2D_0X}, \qquad \frac{K_0}{I_0^2} = \frac{D_0^4\, T_K}{X^2 Q_K},

where TK/QKT_K/Q_K is a second splitting over 2m2m terms at half the precision. The main sum runs first and leaves only its quotient and two half-precision values, so that the peak memory is that of the main sum.

The parameter mm is rounded up so that log⁡m\log m is a combination of a few fast logarithms: over the primes {2}\{2\}, {2,3}\{2, 3\}, {2,3,5}\{2, 3, 5\} or {2,3,5,7}\{2, 3, 5, 7\}, using log⁡(9/8)\log(9/8) and log⁡(256/243)\log(256/243); log⁡(81/80)\log(81/80), log⁡(32805/32768)\log(32805/32768) and log⁡(25/24)\log(25/24); or log⁡(2401/2400)\log(2401/2400), log⁡(4375/4374)\log(4375/4374), log⁡(225/224)\log(225/224) and log⁡(64/63)\log(64/63), each by Zuniga's series. The splittings cost about m(61+log⁡2o)m(61 + \log_2 o) for the odd part oo of mm (powers of two in mm are free), so every m∈[m0,1.5m0]m \in [m_0, 1.5m_0] smooth over {2,3,5,7}\{2, 3, 5, 7\} is scored by this cost plus that of its logarithms, and the best is taken (_mp_real_const_euler_tune forces the set of primes). Below 3456 bits γ\gamma comes from a static table.

The cache of floors#

The constants are needed over and over by the argument reductions, at precisions that grow during a computation. They are kept as exact floors, which have the property that makes a single cache entry serve every precision.

Lemma 2. For c≥0c \ge 0 and n≤Nn \le N, ⌊cBn⌋=⌊⌊cBN⌋/BN−n⌋\lfloor cB^n \rfloor = \lfloor \lfloor cB^N \rfloor / B^{N-n} \rfloor. That is, the floor at nn limbs is the top part of the floor at NN limbs.

Proof. For any real yy and integer q≥1q \ge 1, ⌊⌊y⌋/q⌋=⌊y/q⌋\lfloor \lfloor y \rfloor / q \rfloor = \lfloor y/q \rfloor; take y=cBNy = cB^N and q=BN−nq = B^{N-n}.

So a request at nn limbs reads the top limbs of the cached entry, and its result does not depend on the precision at which the entry was computed. A floor is obtained from a ball at a few guard limbs, retried with more guard limbs if the ball contains a multiple of B−nB^{-n}; for an irrational constant this terminates. When a request exceeds the cached precision NN, the entry is recomputed at max⁡(n+5,1.5N)\max(n + 5, 1.5N) limbs, so that a sequence of growing requests costs at most a constant factor more than its last one. The entry is a process-wide shared cache (thread_support.h): one version at a time, replaced under a lock and published with a release store, so readers never wait.

Use in FLINT#

void mp_real_const_pi4(mp_real_t res, slong n, int cache)
void _mp_real_const_pi4(nn_ptr res, ulong * err, slong n, int cache)

Referenced from#

References#

  • [Yee2025] A. J. Yee. y-cruncher: a multi-threaded pi-program, and its formula collection. http://www.numberworld.org/y-cruncher/ and https://github.com/Mysticial/y-cruncher-Formulas
  • [CC1988] D. V. Chudnovsky and G. V. Chudnovsky. Approximations and complex multiplication according to Ramanujan. In Ramanujan Revisited, Academic Press, 1988, 375–472.
  • [Zun2025] J. Zuniga, "Fast Ramanujan-type Series for Logarithms. Part I", 2025, https://arxiv.org/abs/2506.08245
  • [PP2010] K. H. Pilehrood and T. H. Pilehrood. "Series acceleration formulas for beta values", Discrete Mathematics and Theoretical Computer Science, DMTCS, 12 (2) (2010), 223-236, https://hal.inria.fr/hal-00990465/
  • [BM1980] R. P. Brent and E. M. McMillan, "Some new algorithms for high-precision computation of Euler's constant", Mathematics of Computation 34 (1980) 305-312.
  • [BJ2013] R. P. Brent and F. Johansson, "A bound for the error term in the Brent-McMillan algorithm", preprint (2013), https://arxiv.org/abs/1312.0039
Cite this page

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