Error functions of a real ball
#include <flint/arb_hypgeom.h>Sets res to the error function .
Implemented for real arguments with the series , which has positive terms and is summed by rectangular splitting; the asymptotic expansion of for large ; the bound when it is below ; and above 30000 bits, for up to about , a bit-burst algorithm for the incomplete gamma function . See Error functions of a real ball.
Sets res to the complementary error function , accurately also for large positive where is tiny.
For this is . For larger the function uses the asymptotic expansion when it reaches the target accuracy, the bit-burst algorithm above 30000 bits, and otherwise the convergent series at a working precision increased by the bits lost to cancellation. See Error functions of a real ball.
Sets res to the inverse error function for , or the inverse complementary error function for . The values at the endpoints are ; arguments outside the domain give an indeterminate result.
A starting approximation (in double precision [Bla1976], or from the first terms of the asymptotic expansion near ) is refined by Newton iterations with doubling precision, and the final enclosure is proved by an interval Newton step. arb_hypgeom_erfcinv works with itself rather than near 0, so that tiny arguments such as lose no accuracy. The error propagated from an inexact argument is bounded with . See Error functions of a real ball.
arb_hypgeom_erf and arb_hypgeom_erfc compute the error function and its complement for a real ball ; arb_hypgeom_erfinv and arb_hypgeom_erfcinv compute the inverse functions. Unlike most real functions of this module they do not call the complex implementation: for real one of the two convergent series has only positive terms, the asymptotic expansion has a simple error bound, and at very high precision the incomplete gamma function can be computed with the bit-burst algorithm. acb_hypgeom_erf calls arb_hypgeom_erf for real input. The complex algorithms and the incomplete gamma functions in general are described in Error functions, incomplete gamma functions and exponential integrals.
The methods#
arb_hypgeom_erf chooses among the following.
- Tiny or huge . For the series below needs few terms. If exceeds the precision (or ), the function returns with , which bounds .
Convergent series. The default method is
in which all terms are positive, so that no precision is lost to cancellation. The number of terms is estimated with the Lambert function, the tail is bounded by the tail of the exponential series (), and the sum is computed by rectangular splitting with
_arb_hypgeom_gamma_lower_sum_rs_1, so that most multiplications are by small integers.Asymptotic expansion. For , the expansion
is used when some makes the bound smaller than ; the sum is computed at the reduced precision that the factor allows.
- Bit-burst algorithm. Above 30000 bits and for , the function computes with
arb_hypgeom_erf_bb: is approached by numbers with 64, 128, 256, ... bits, the value at comes from the asymptotic or the convergent series of the incomplete gamma function, and each step from to sums a Taylor series by binary splitting. The cost is at bits, asymptotically less than the multiplications by small integers and full multiplications of rectangular splitting. See The bit-burst algorithm.
For inexact , the series are evaluated at the midpoint and the propagated error is bounded by , where is the lower bound of and the radius (and by 2); the precision is reduced to the accuracy of plus the number of bits that gains.
arb_hypgeom_erfc computes for . For larger , where the subtraction would cancel, it uses the asymptotic expansion whenever it reaches the target accuracy (with a single term for ), the bit-burst algorithm above 30000 bits, and otherwise the convergent series for at a working precision increased by bits.
Inverse functions#
arb_hypgeom_erfinv solves by Newton's method with . The starting value comes from a rational approximation in double precision [Bla1976], from the first terms of the asymptotic expansion of near when , and from the same expansion in ball arithmetic when . Each iteration doubles the precision; when an iterate is an interval Newton step contained in the previous enclosure, the existence of the root in it is proved, and the loop stops once a proved enclosure has the target accuracy. Near the iteration works with and , which avoids cancellation. arb_hypgeom_erfcinv passes itself in this form when , so that arguments such as lose no accuracy.
Example#
At 64 bits, is up to a tiny error, and only arb_hypgeom_erfc resolves the difference; arb_hypgeom_erfcinv inverts it for a tiny argument:
#include <flint/arb.h>
#include <flint/arb_hypgeom.h>
int main(void)
{
arb_t x, y, z;
arb_init(x);
arb_init(y);
arb_init(z);
arb_set_ui(x, 30);
arb_hypgeom_erf(y, x, 64);
flint_printf("erf(30) = "); arb_printn(y, 20, 0); flint_printf("\n");
arb_hypgeom_erfc(y, x, 64);
flint_printf("erfc(30) = "); arb_printn(y, 20, 0); flint_printf("\n");
/* 1 - erf(30) cannot resolve the tiny difference at 64 bits */
arb_hypgeom_erf(y, x, 64);
arb_sub_ui(y, y, 1, 64);
arb_neg(y, y);
flint_printf("1 - erf(30) = "); arb_printn(y, 20, 0); flint_printf("\n");
/* inverse functions; erfcinv works directly with tiny arguments */
arb_set_str(x, "0.5", 64);
arb_hypgeom_erfinv(y, x, 64);
flint_printf("erfinv(0.5) = "); arb_printn(y, 20, 0); flint_printf("\n");
arb_set_str(x, "1e-1000", 64);
arb_hypgeom_erfcinv(y, x, 64);
flint_printf("erfcinv(1e-1000) = "); arb_printn(y, 20, 0); flint_printf("\n");
arb_hypgeom_erfc(z, y, 64);
flint_printf("erfc of that = "); arb_printn(z, 20, 0); flint_printf("\n");
arb_clear(x);
arb_clear(y);
arb_clear(z);
flint_cleanup();
return 0;
}erf(30) = [1.0000000000000000000 +/- 2.57e-393] erfc(30) = [2.5646562037561116000e-393 +/- 3.65e-413] 1 - erf(30) = [+/- 2.57e-393] erfinv(0.5) = [0.4769362762044698734 +/- 6.83e-20] erfcinv(1e-1000) = [47.93894640426451069 +/- 3.99e-18] erfc of that = [1.000000000000000e-1000 +/- 3.75e-1016]
The enclosure of is the bound , which is correct but says nothing about itself; computing directly gives 64 significant bits. The string "1e-1000" is not exactly representable, so the input to arb_hypgeom_erfcinv is a ball of relative radius , and the last line recovers it within that radius.
References#
- [Bla1976] J. M. Blair, C. A. Edwards and J. H. Johnson. Rational Chebyshev approximations for the inverse of the error function. Mathematics of Computation 30 (1976), 827–830. https://doi.org/10.1090/S0025-5718-1976-0421040-7
The FLINT team, “Error functions of a real ball (arb_hypgeom.h),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/arb_hypgeom/erf.html (generated 2026-11-02).
@misc{flint-doc-arb-hypgeom-erf,
author = {{The FLINT team}},
title = {{Error functions of a real ball (arb\_hypgeom.h)}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/arb_hypgeom/erf.html},
note = {Generated 2026-11-02}
}