Constants in mp_real
- Cost
- for each constant; from limbs in plus the cost of .
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#
| Constant | Formula |
|---|---|
| Chudnovsky [CC1988], (see below), 47.1 bits per term | |
| Zuniga [Zun2025], , 11.9 bits per term | |
| Pilehrood [PP2010], | |
| a series of Zuniga (2023) with a numerator of degree 11 | |
| Sun's identity (2025), with a -type series | |
| with Guillera's series (2023) | |
| with Ebisu's series (2016), or the AGM |
The Chudnovsky series in the format of mp_real_hypgeom_series is with , , , , and ; the example on Hypergeometric series runs it. Since mp_real_hypgeom_series gives correct bits, the constants call it with one limb more than they need.
The parts of (the series, and ) and of the values (the series and ) are independent and run on separate threads. For above limbs, the formula
is used instead, with the AGM () computed in parallel with . is from the three-term Machin-type formula of the first three primes (, and , each by Zuniga's series where faster; Computing the logarithms). and are derived from and .
Euler's constant#
The Brent–McMillan algorithm [BM1980] with the error bound of [BJ2013] gives, for a parameter ,
with evaluated by its asymptotic series and for bits. and come from one binary splitting over about terms in dual numbers.
Proposition 1. Let over . Then and .
Proof. .
The splitting of carries a scalar , a dual number (so that the denominator is ) and , merged as
five full-size and five half-size products per merge. At the end, with ,
where is a second splitting over 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 is rounded up so that is a combination of a few fast logarithms: over the primes , , or , using and ; , and ; or , , and , each by Zuniga's series. The splittings cost about for the odd part of (powers of two in are free), so every smooth over 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 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 and , . That is, the floor at limbs is the top part of the floor at limbs.
Proof. For any real and integer , ; take and .
So a request at 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 ; for an irrational constant this terminates. When a request exceeds the cached precision , the entry is recomputed at 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#
- The ball and limb functions
mp_real_const_pi4, ...,_mp_real_const_inv_log2_fracand_mp_real_const_clear_cacheimplement the formulas and the cache. arb_const_pi,arb_const_log2,arb_const_e,arb_const_euler,arb_const_log10,arb_const_catalan,arb_const_apery,arb_const_zeta5andarb_hypgeom_gamma_fmpq(at and ) call_mp_real_const_arb.- The argument reductions of the elementary functions read , , and from the cache (static tables up to 64 limbs), and the AGM logarithm and .
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)void _mp_real_const_arb(arb_t res, mp_real_const_func f, slong prec)Referenced from#
- Binary splitting of hypergeometric series in mp_real (algorithm)
- Floating-point arithmetic in FLINT (overview)
- Mathematical constants (algorithm)
- Mathematical constants
- mp_real.h (module)
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
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).
@misc{flint-doc-algorithms-floating-point-constants,
author = {{The FLINT team}},
title = {{Constants in mp\_real}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/algorithms/floating-point/constants.html},
note = {Generated 2026-11-02}
}