Mathematical constants
- Cost
- for the hypergeometric constants by binary splitting ( from limbs in plus the cost of ) and for the reciprocal Fibonacci constant; Khinchin's constant in word operations by sums of zeta values and in by the approximate functional equation; Glaisher's constant (below about to bits, depending on the number of threads) uses sums of many full-precision terms and is much slower, and costs at higher precision.
Most of the mathematical constants of FLINT 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 , , , , , Catalan's constant, , , and , and Khinchin's constant, are summed by the mp_real module, which arb_const_pi and the other arb_const_ functions call through _mp_real_const_arb; the same values, kept as exact floors, serve the argument reductions of the elementary functions (Elementary functions). The formulas were taken from the collection of y-cruncher [Yee2025], and for each constant the formula measured fastest in this implementation was chosen.
Binary splitting#
Consider a sum with polynomials with integer coefficients. For define , , and , the partial sum scaled to an integer. Then for
(with the obvious extension for ), so the exact sum is obtained by a balanced recursion and one final division .
Proposition 1. If the series converges geometrically, so that terms give bits, and the integers have bits, binary splitting computes to bits in bit operations, which is .
Proof. At each of the levels of the recursion, the numbers multiplied have a total size of bits, and multiplication is superadditive, so each level costs . The final division costs .
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].
In mp_real the splitting is mp_real_hypgeom_series (Binary splitting of hypergeometric series in mp_real), which sums a series given by integer polynomials , , in the format of y-cruncher's formula files, with rigorous tail bounds and threads. Since it gives correct bits, the constants call it with one limb more than they need.
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 |
#
is computed by the Chudnovsky series [CC1988]
which adds about 47 bits (14 digits) per term. Methods based on the arithmetic-geometric mean [Sal1976] [Bre1976agm] have a better asymptotic complexity, , 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.
The Chudnovsky series in the format of mp_real_hypgeom_series is with , , , , and , and ; the example on Hypergeometric series runs it.
#
is summed by binary splitting, with and ; this is the simplest hypergeometric series and its cost is dominated by the final division.
Logarithms of integers#
is computed by Zuniga's series [Zun2025]
which adds 11.9 bits per term. (Earlier versions used another series of Zuniga [Zun2023b], with terms decreasing like .) uses the Machin-type formulas for the first three primes in terms of
for example , with the three series evaluated in parallel (each by Zuniga's series where faster; Computing the logarithms). 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 is computed by the Brent-McMillan formula [BM1980] [MPFR2012]
where is a free parameter and
The first two series are summed together up to with , where satisfies , and the asymptotic series up to . With these parameters the error is bounded by [BJ2013].
Below 3456 bits comes from a static table. Otherwise, writing for the parameter , and come from one binary splitting over about terms in dual numbers.
Proposition 2. 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).
Catalan's constant#
Catalan's constant is computed by the series of Pilehrood and Pilehrood [PP2010]
which adds about 5.4 bits per term and was measured to be the fastest available formula.
and #
Apéry's constant is computed by a hypergeometric series found by Zuniga [Zun2023],
with a polynomial of degree 11 given in the source. is computed from Z.-W. Sun's identity
with the three parts , and computed in parallel when threads are available.
and #
with Guillera's series (2023), and with Ebisu's series (2016); the series and run on separate threads. For above limbs, the formula
is used instead, with the AGM () computed in parallel with .
Khinchin's constant#
Zeta expansion#
Up to about digits, Khinchin's constant is computed from the formula [BBC1997]
where is a free parameter. The finite sum has a minus sign: each product of logarithms is negative. arb_const_khinchin calls mp_real_const_khinchin, which takes between 6 and 12, evaluates the finite sum as a quadratic form in the logarithms of the primes up to , and computes the by direct summation with recycled powers for large and from exact Bernoulli numbers for small (below).
Proposition 3 (Truncation error). If the series over is truncated after , the error inside the brackets is at most .
Proof. The inner alternating sums lie in , so the remainder is bounded in absolute value by . By the integral bound,
and since , this is at most .
For an error of it therefore suffices to take .
The algorithm#
With , and ,
the classical sum over [BBC1997] being the case . Each cell of the double sum is covered in one of three ways.
Rows use with , an integer combination of the logarithms of the primes up to , which come from one set of Machin-type series (Computing the logarithms). The sum of the rows is a quadratic form with small integer , so it costs one full product per prime rather than one per row.
Columns sum directly, in fixed point with fraction limbs, over the with . The powers are recycled from column to column, downward: is kept as an integer with extended limbs and stepped by one mpn_mul_1 by , several times faster than the division by an upward recurrence needs. A downward step multiplies the absolute error by but keeps the relative error, so a power is created (binary powering and one division) with the relative accuracy needed at the bottom of its range, its bottom limb is dropped whenever its error count passes (so that the truncations, one unit of the next limb each, cost a negligible relative amount over thousands of drops), and the range is cut into up to three segments, each created afresh, so that the products shorten with the accuracy actually needed. Only and the odd are summed: the even contribute , so the partial sum is divided by by a few shifted additions.
Streaming every power, and the column sum, once per column is bound by the memory bandwidth once the powers outgrow the L2 cache, and the more so the more threads share it. The columns are therefore taken in batches of 16 with one partial sum per column, and the powers eight at a time by blocks of 256 limbs of the column sums: each block of a power is stepped through the 16 columns while in cache, and the blocks of the 16 sums serve the eight powers. The drops of bottom limbs depend only on the error counts, so they are scheduled before the products, which are those of the column-by-column recurrence; the carries between blocks are kept per power and column. This roughly halves the time per limb and step on one thread for powers of limbs, at a cost of 16 column sums of limbs per task. The subtracted powers of the Bernoulli columns (below) are summed the same way.
Columns use with and the exact Bernoulli numbers of the reverse iterator bernoulli_rev [Blo2009], which recycles odd powers downward at the precision of , below the working precision for these . The factor would cost one full product per column; instead the columns are taken in blocks of and computed in units of ,
with the powers , , computed once: a column then costs one product of the integer by a full-precision power, and a block four full products.
The weights are applied by summation by parts: with , , so that , and ,
two single-limb divisions and two additions per column instead of a product by the real . Since , the suffix sums of the direct columns only occupy the low limbs, and their cost tapers off with the column. All fixed-point errors are counted in ulps and bounded rigorously, including the omitted terms and the columns beyond the last one.
A direct column costs about products of single limbs by numbers of up to limbs, with , and a Bernoulli column about two products of the size of (in the iterator) and one of size by limbs; is chosen where is between and (measured), growing with the precision up to bits. Beyond, is chosen so that has about as many bits as the working precision, so that the direct column takes about as many powers as the iterator does there ( at digits); otherwise the Bernoulli columns, whose cost grows like the cube of the precision with fixed, would take nearly all the time. For limbs, the full products cost in all, and the power sums of the iterator and the direct columns word operations, which dominate at very high precision.
The sums being linear, the direct columns are split into groups of (two per thread), the subtracted powers into ranges of columns (with from exact harmonic numbers) and the Bernoulli columns into ranges of , each with its own summation by parts, which run as independent tasks together with the rows. Each range of Bernoulli columns has its own iterator, whose power table takes about bits (The reverse iterator), which dominates the memory at high precision: with one range per thread, some five times the table of the top range at once (about 5 GB at digits). The ranges are therefore run one per thread only while their tables total below 1 GiB; beyond, as many ranges run at once as stay below it (at least one), each with the threads left over, used inside the iterator and for the columns: a group of 16 columns takes its 16 numbers from the iterator, then their products by the powers of in parallel, the prefix sums , and the divisions by in parallel, the of a block being summed exactly. The direct columns, the subtracted powers and the rows then follow. _mp_real_const_khinchin_tune forces , and the number of Bernoulli ranges run at once.
The approximate functional equation#
From MP_REAL_KHINCHIN_AFE_CUTOFF limbs (about digits), mp_real_const_khinchin uses _mp_real_const_khinchin_afe, which needs evaluations of cost each instead of the cubic power sums above. It starts from the dilogarithm series of [BBC1997, §3],
and the Laplace transform for , with and . The sum over is then an integral of against a theta function. Splitting the integral at and applying the transformation of on gives, for every ,
with
For bits, about terms and terms are needed; the default balances their costs. comes from and by Landen's identity, and is a rational series.
This is a generalization of the approximate functional equation of the Dirichlet -functions (Dirichlet L-functions), which is the same construction for the summand : there the function is a power of , so that every term of the two series is a single incomplete gamma function. Here is an entire function, and the terms and are themselves series, which can still be evaluated by binary splitting since their coefficients are rational.
The -terms. With and , , the truncated exponential series. The terms satisfy a triangular recurrence with rational coefficients, summed by matrix binary splitting; the factors of consecutive are propagated by multiplications by . The tail after terms is bounded through the Poisson weights in .
The dual terms. with and the moments . Integration by parts relates to , to the similar moments of and of 1, and to the boundary values at , which carry the factor ; and shifts by one. So is a holonomic function of of order four whose only finite singularity is , and it is evaluated by the bit-burst algorithm: starting values at a 64-bit dyadic near , from a shift series in terms of (by mp_real_gamma_upper_half_frac) and , then Taylor steps to dyadic points with fractional bits converging to . The parts of the shift series cancel by up to individually but their weighted sums only by about , so guard bits suffice. All Taylor remainders, the tails of the starting values and the final distance to are bounded rigorously through upper incomplete gamma functions; the bounds carry the factor , so that the late stages are computed only to the significant bits of , which is of order .
Matrix binary splitting. The -terms, the dual terms (starting values and Taylor steps), and the continued fraction for all use one internal engine (_mp_real_linrec_eval) for recurrences with sums and a scalar geometric forcing , given by integer leaf matrices. The range is cut into chunks whose exact products (integer matrices over a common denominator) have about half the working precision in bits. Within a chunk, binary splitting combines the two halves in one augmented product that shares the transforms of each entry among the products (fmpz_mat_mul_fft_small, since fmpz_mat_mul does not choose the transformed product for such small matrices) when the entries have at least about bits and the inner dimension is at least 6; for the narrow products of the -terms, separate products were faster at all sizes measured. Each chunk's matrix is then applied to the state vector : above the chunks there are only matrix-vector products. The state is kept scaled by the product of the denominators so far, which is divided out once at the end. For large entries the application is one truncated transformed product (fmpz_mat_mul_fft_small_trunc, which transforms each state entry once for all the rows and accumulates the rows in the transformed domain), each state entry converted to fixed point with its own exponent, so that it keeps its relative accuracy as in ball arithmetic; for small entries it is done in ball arithmetic.
Parallelism and memory. The terms are independent tasks. The dual terms are the most expensive and take about four times the memory of a -term, so they start first and at most maxdual of them run at once (by default half the threads, until the last chunk of -terms has started; then any thread may take one), while the other threads take chunks of consecutive -terms, starting each chunk with and as powers of a shared (about multiplications instead of two exponentials). The exact products of large chunks also fork onto idle threads. Each finished term is added to one fixed-point integer with an integer error count, so no term is kept and the result does not depend on the order in which the terms finish. The memory is then that of the running terms, linear in the precision times the number of threads, and dominated by the transforms of the shared-transform products, which fft_small limits to flint_fft_small_max_transformed_ring_size per product (blocking the products beyond). At digits, a dual term takes about 370 numbers of the working precision with all transforms resident and a -term about 90. The user can reduce memory in exchange for a slight increase in running time by decreasing flint_fft_small_max_transformed_ring_size.
Glaisher's constant#
The Glaisher-Kinkelin constant is computed directly from this formula, with from acb_dirichlet_zeta_jet (see Zeta functions, polylogarithms and L-functions). Up to a cutoff (_acb_dirichlet_l_jet_use_afe: bits with one thread, about bits with 8 threads), this uses Euler-Maclaurin summation directly at ; the reflection formula is not used for , since the arithmetic of Euler-Maclaurin summation is cheaper at than at (by a factor 1.3–1.7 for ).
Euler-Maclaurin summation needs terms and Bernoulli numbers at precision , which costs time and bits of memory (several gigabytes at ). Above the cutoff, acb_dirichlet_zeta_jet instead computes to with the approximate functional equation (acb_dirichlet_l_fmpq_afe_jet), a sum of incomplete gamma function jets evaluated by binary splitting, in time and with memory.
The reciprocal Fibonacci constant#
is computed from Gosper's series [Gos1974], corrected in [Arn2012],
where is a Lucas number. The truncation error after terms is bounded by , so terms give bits. The series is not hypergeometric, but factoring out the multiplicative recurrence for turns it into a product of matrices with -bit entries, which binary splitting evaluates in quasilinear time.
Caching#
Each arb_const_ function keeps a thread-local cached ball. A request at precision above the cached precision recomputes the constant at bits; later requests at precision at most only round the cached value, to nearest with a radius of half a unit in the last place plus the cached error. and up to about 4000 bits are read from the static floors of and (64 limbs on 64-bit machines), and up to 3456 bits from a static table, correctly rounded to nearest with a radius of half a unit in the last place. The caches are freed by flint_cleanup.
Inside mp_real the constants , , and (the last two derived from the first two) 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 4. 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#
void arb_const_pi(arb_t z, slong prec)void arb_const_e(arb_t z, slong prec)void arb_const_log2(arb_t z, slong prec)void arb_const_log10(arb_t z, slong prec)void arb_const_euler(arb_t z, slong prec)void arb_const_catalan(arb_t z, slong prec)void arb_const_apery(arb_t s, slong prec)void arb_const_zeta5(arb_t s, slong prec)void arb_const_khinchin(arb_t z, slong prec)void arb_const_glaisher(arb_t z, slong prec)void arb_const_reciprocal_fibonacci(arb_t res, slong prec)void arb_const_sqrt_pi(arb_t z, slong prec)void arb_const_log_sqrt2pi(arb_t z, slong prec)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)The complex versions in acb (for example acb_const_pi) call these functions, and arb_hypgeom_gamma_fmpq uses and (the gamma function at rational arguments). The argument reductions of the elementary functions read , , and from the cache of floors (static tables up to 64 limbs), and the AGM logarithm and . _mp_real_const_khinchin_afe implements the approximate functional equation for Khinchin's constant, with mp_real_gamma_upper_half_frac for its starting values.
The tutorial Computing π and other constants computes and other constants to many digits in complete programs.
Referenced from#
- Binary splitting of hypergeometric series in mp_real (algorithm)
- Floating-point arithmetic (overview)
- Floating-point arithmetic in FLINT (overview)
- Elementary functions (algorithm)
- Hypergeometric functions (algorithm)
- Special functions (overview)
- Evaluating special functions (overview)
- arb.h (module)
_mp_real_const_khinchin_afe- Mathematical constants
- mp_real.h (module)
- Computing π and other constants (tutorial)
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
- [HP1998] B. Haible and T. Papanikolaou, "Fast multiprecision evaluation of series of rational numbers", Algorithmic Number Theory (ANTS-III), LNCS 1423 (1998), 338–350
- [BZ2011] R. P. Brent and P. Zimmermann, Modern Computer Arithmetic, Cambridge University Press (2011), http://www.loria.fr/~zimmerma/mca/pub226.html
- [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/
- [Sal1976] E. Salamin. Computation of π using arithmetic-geometric mean. Mathematics of Computation 30:135 (1976), 565–570. https://doi.org/10.2307/2005327
- [Bre1976agm] R. P. Brent. Fast multiple-precision evaluation of elementary functions. Journal of the ACM 23:2 (1976), 242–251. https://doi.org/10.1145/321941.321944
- [Zun2023b] J. Zuniga, "Are these fast convergent series for log(2) and log(3) already known and proven?", https://math.stackexchange.com/q/4854073
- [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.
- [MPFR2012] The MPFR team, "MPFR Algorithms" (2012), https://www.mpfr.org/algo.html
- [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
- [Zun2023] J. Zuniga, "Catalan's constant fast convergent series", https://mathoverflow.net/q/424055
- [BBC1997] D. H. Bailey, J. M. Borwein and R. E. Crandall, "On the Khintchine constant", Mathematics of Computation 66 (1997) 417-431
- [Blo2009] R. Bloemen, "Even faster zeta(2n) calculation!", https://web.archive.org/web/20141101133659/http://xn--2-umb.com/09/11/even-faster-zeta-calculation
- [Gos1974] R. W. Gosper, "Acceleration of series", MIT AI Memo no.304, (March-1974). https://dspace.mit.edu/handle/1721.1/6088
- [Arn2012] J. Arndt, "On computing the generalized Lambert series", https://arxiv.org/abs/1202.6525
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-20).
@misc{flint-doc-algorithms-special-functions-constants,
author = {{The FLINT team}},
title = {{Mathematical constants}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/algorithms/special-functions/constants.html},
note = {Generated 2026-11-20}
}