FLINT3.7.0-dev
Algorithm

Error functions, incomplete gamma functions and exponential integrals

The error function, the incomplete gamma function and the exponential integrals are confluent hypergeometric functions with one parameter fixed or tied to the argument:

γ(s,z)=zss 1F1(s;s+1;−z),Γ(s,z)=e−zU(1−s,1−s,z)=zse−zU(1,1+s,z),\gamma(s, z) = \frac{z^s}{s}\, {}_1F_1(s; s+1; -z), \qquad \Gamma(s, z) = e^{-z} U(1-s, 1-s, z) = z^s e^{-z} U(1, 1+s, z),
erf⁡(z)=γ(12,z2)π zz2,Es(z)=zs−1Γ(1−s,z),Ei⁡(z)=−E1(−z)+(branch terms).\operatorname{erf}(z) = \frac{\gamma(\tfrac12, z^2)}{\sqrt\pi}\,\frac{z}{\sqrt{z^2}}, \qquad E_s(z) = z^{s-1}\Gamma(1-s,z), \qquad \operatorname{Ei}(z) = -E_1(-z) + \text{(branch terms)}.

Their evaluation therefore follows Hypergeometric functions: a convergent series near the origin, the asymptotic expansion of UU with Olver's error bound for large ∣z∣|z|, and a working precision chosen from the cancellation of the series.

Error functions#

FLINT uses three representations of the error function:

erf⁡(z)=2zπ 1F1(12,32,−z2)=2ze−z2π 1F1(1,32,z2)=zz2−e−z2zπU∗(12,12,z2).\operatorname{erf}(z) = \frac{2z}{\sqrt{\pi}}\, {}_1F_1(\tfrac{1}{2}, \tfrac{3}{2}, -z^2) = \frac{2z e^{-z^2}}{\sqrt{\pi}}\, {}_1F_1(1, \tfrac{3}{2}, z^2) = \frac{z}{\sqrt{z^2}} - \frac{e^{-z^2}}{z \sqrt{\pi}} U^{*}(\tfrac{1}{2}, \tfrac{1}{2}, z^2).

For z=x+yiz = x + yi the terms of the first series have size up to about ex2e^{x^2} when ∣x∣>∣y∣|x| > |y| and the function has size about 11, so the series loses about x2/log⁡2x^2/\log 2 bits; the second series has the opposite behaviour (by Kummer's transformation), losing about y2/log⁡2y^2/\log 2. acb_hypgeom_erf uses the second series if ∣x∣≥∣y∣|x| \ge |y| and the first otherwise, at a working precision raised by 2min⁡(x2,y2)/log⁡22 \min(x^2, y^2)/\log 2 bits, and the asymptotic expansion when its error term ≈e−∣z∣2/∣z∣\approx e^{-|z|^2}/|z| is below 2−p2^{-p}, computing the U∗U^* term at the lower precision that its small prefactor allows. For inexact zz, the series is evaluated at the midpoint and acb_hypgeom_erf_propagated_error bounds the propagated error with the derivative 2πe−z2\frac{2}{\sqrt\pi} e^{-z^2}. The complementary function erfc⁡(z)=1−erf⁡(z)\operatorname{erfc}(z) = 1 - \operatorname{erf}(z) is computed from the U∗U^* representation without the subtraction when Re⁡(z)\operatorname{Re}(z) is large and positive, and erfi⁡(z)=−ierf⁡(iz)\operatorname{erfi}(z) = -i\operatorname{erf}(iz). The normalized Fresnel integrals satisfy [NIST2012, 7.5]

C(z)±iS(z)=1±i2erf⁡(π2(1∓i)z),C(z) \pm i S(z) = \frac{1 \pm i}{2} \operatorname{erf}\left(\frac{\sqrt\pi}{2}(1 \mp i) z\right),

and acb_hypgeom_fresnel computes them from erf⁡((1±i)w)\operatorname{erf}((1 \pm i) w) for a real multiple ww of zz, so that the square ±2iw2\pm 2iw^2 inside the error function is computed without rounding of the real part.

Real arguments#

For real xx, arb_hypgeom_erf uses

erf⁡(x)=2xπe−x2∑k=0∞(x2)k(3/2)k,\operatorname{erf}(x) = \frac{2x}{\sqrt\pi} e^{-x^2} \sum_{k=0}^\infty \frac{(x^2)^k}{(3/2)_k},

whose terms are positive, so that no precision is lost. Since (x2)k/(3/2)k≤(x2)k/k!(x^2)^k/(3/2)_k \le (x^2)^k/k!, the tail after NN terms is at most the tail of the series of ex2e^{x^2}, and NN is chosen with the Lambert WW function. The sum is computed by rectangular splitting (_arb_hypgeom_gamma_lower_sum_rs_1): with m≈Nm \approx \sqrt N powers of x2x^2, the coefficients 1/(3/2)k1/(3/2)_k are accumulated as products of the word-size factors 2/(2k+1)2/(2k+1), and only about 2N2\sqrt N multiplications of full-precision numbers are needed. For ∣x∣>2|x| > 2 the asymptotic expansion

erfc⁡(x)=e−x2xπ(∑k=0N−1(1/2)k(−x2)k+RN),∣RN∣≤(1/2)Nx2N,\operatorname{erfc}(x) = \frac{e^{-x^2}}{x\sqrt\pi} \left(\sum_{k=0}^{N-1} \frac{(1/2)_k}{(-x^2)^k} + R_N\right), \qquad |R_N| \le \frac{(1/2)_N}{x^{2N}},

whose remainder is bounded by the first omitted term for real xx, is used when it reaches the target accuracy; its sum is also computed by rectangular splitting (_arb_hypgeom_gamma_upper_sum_rs_1). arb_hypgeom_erfc uses the asymptotic expansion whenever possible and otherwise the convergent series at a working precision increased by (x2+log⁡x)/log⁡2(x^2 + \log x)/\log 2 bits.

Incomplete gamma functions#

The upper incomplete gamma function is computed from

Γ(s,z)=e−zU(1−s,1−s,z)=Γ(s)−zss 1F1(s,s+1,−z)=Γ(s)−zse−zs 1F1(1,s+1,z).\Gamma(s,z) = e^{-z} U(1-s,1-s,z) = \Gamma(s) - \frac{z^s}{s}\, {}_1F_1(s, s+1, -z) = \Gamma(s) - \frac{z^s e^{-z}}{s}\,{}_1F_1(1, s+1, z).

The first form is the asymptotic expansion Γ(s,z)∼zs−1e−z∑k(1−s)k(−z)−k\Gamma(s,z) \sim z^{s-1}e^{-z}\sum_k (1-s)_k(-z)^{-k}, whose error bound from Asymptotic expansions depends on r=∣b−2a∣=∣s−1∣r = |b - 2a| = |s - 1|. The two convergent forms differ by Kummer's transformation; the second is used for Re⁡z≤0\operatorname{Re} z \le 0 and the third for Re⁡z>0\operatorname{Re} z > 0, so that the series has terms of equal sign on the real axis. For s=−ns = -n a nonpositive integer, Γ(s)\Gamma(s) has a pole that cancels with the series, and the limit

Γ(−n,z)=(−1)nn!(ψ(n+1)−log⁡(z))+(−1)n(n+1)!z 2F2(1,1;2,2+n;−z)−z−n∑k=0n−1(−z)k(k−n)k!\Gamma(-n,z) = \frac{(-1)^n}{n!} (\psi(n+1) - \log(z)) + \frac{(-1)^n}{(n+1)!} z \, {}_2F_2(1,1;2,2+n;-z) - z^{-n} \sum_{k=0}^{n-1} \frac{(-z)^k}{(k-n) k!}

is used instead. acb_hypgeom_gamma_upper chooses the asymptotic expansion for nonnegative real ss and zz when (z−2.39)8>(1.03s)8+(0.33 p)8(z - 2.39)^8 > (1.03 s)^8 + (0.33\,p)^8 (an empirical fit of the region where it reaches pp bits), and for other arguments when acb_hypgeom_u_use_asymp holds and ss is a positive integer or zz lies in one of Olver's regions. The lower incomplete gamma function is γ(s,z)=zss1F1(s;s+1;−z)\gamma(s,z) = \frac{z^s}{s}{}_1F_1(s; s+1; -z), computed with acb_hypgeom_m (regularized when requested), which applies the same choices. The regularized forms Q(s,z)=Γ(s,z)/Γ(s)Q(s,z) = \Gamma(s,z)/\Gamma(s), P(s,z)=γ(s,z)/Γ(s)P(s,z) = \gamma(s,z)/\Gamma(s) and γ∗(s,z)=z−sP(s,z)\gamma^*(s,z) = z^{-s}P(s,z) are computed directly with regularized hypergeometric functions, so that they are defined at the poles of Γ(s)\Gamma(s).

Rational parameters and the bit-burst algorithm#

For a rational parameter a=p/qa = p/q and real z>0z > 0, the internal functions _arb_hypgeom_gamma_upper_fmpq_inf_bsplit and _arb_hypgeom_gamma_lower_fmpq_0_bsplit sum the asymptotic expansion at infinity and the Taylor series

γ(a,z)=zae−za∑n=0∞zn(a+1)n\gamma(a, z) = \frac{z^a e^{-z}}{a} \sum_{n=0}^\infty \frac{z^n}{(a+1)_n}

at zero by binary splitting, with truncation errors bounded by the corresponding _choose_N functions for a prescribed absolute tolerance. This is efficient only when zz has few bits. For a full-precision zz, arb_hypgeom_erf_bb applies the bit-burst algorithm (The bit-burst algorithm) to Γ(1/2,z2)\Gamma(1/2, z^2):

  1. z0z_0 is z2z^2 truncated to 64 fractional bits (or more if z2z^2 is tiny), and Γ(a,z0)\Gamma(a, z_0) is computed with the asymptotic series if it reaches the tolerance and as Γ(a)−γ(a,z0)\Gamma(a) - \gamma(a, z_0) otherwise.
  2. For j=1,2,…j = 1, 2, \ldots, zjz_j is z2z^2 truncated to 2j⋅642^{j} \cdot 64 bits, and _arb_gamma_upper_fmpq_step_bsplit computes Γ(a,zj)\Gamma(a, z_j) from Γ(a,zj−1)\Gamma(a, z_{j-1}) and e−zj−1e^{-z_{j-1}} with the Taylor expansion at zj−1z_{j-1}; the coefficients satisfy a recurrence from the differential equation zy′′+(1+z−a)y′=0z y'' + (1 + z - a) y' = 0 of y=Γ(a,z)y = \Gamma(a, z), so the step is a product of 2×22 \times 2 polynomial matrices computed by binary splitting, with a Cauchy-type bound for the truncation error.
  3. A last step goes from the last truncation to z2z^2 itself.

The working precisions of the two parts are adjusted to the absolute tolerance needed for erf⁡\operatorname{erf} or erfc⁡\operatorname{erfc} (with cancellation when erfc⁡\operatorname{erfc} is computed from the lower series). arb_hypgeom_erf and arb_hypgeom_erfc use this method above 30000 bits for moderately large ∣x∣|x|; it costs O(M(p)log⁡2p)O(M(p)\log^2 p), compared with O(p)O(\sqrt{p}) full multiplications plus O(p)O(p) cheap ones for rectangular splitting. The same functions are used by acb_dirichlet for the incomplete gamma functions in the approximate functional equation of Dirichlet LL-functions at rational ss.

Incomplete beta function#

B(a,b;z)=zaa 2F1(a,1−b,a+1,z),I(a,b;z)=Γ(a+b)Γ(b) za 2F1(a,1−b,a+1,z)B(a,b;z) = \frac{z^a}{a}\, {}_2F_1(a, 1-b, a+1, z), \qquad I(a,b;z) = \frac{\Gamma(a+b)}{\Gamma(b)}\, z^a\, {}_2\mathbf{F}_1(a, 1-b, a+1, z)

are computed with acb_hypgeom_2f1, and inherit its transformations and analytic continuation (The Gauss hypergeometric function).

Exponential, logarithmic and trigonometric integrals#

The generalized exponential integral is Es(z)=zs−1Γ(1−s,z)E_s(z) = z^{s-1}\Gamma(1-s, z) (acb_hypgeom_expint). The other integrals have the representations

Ei⁡(z)=z 2F2(1,1;2,2;z)+γ+12(log⁡(z)−log⁡(1/z))=−ezU(1,1,−z)−log⁡(−z)+12(log⁡(z)−log⁡(1/z)),\operatorname{Ei}(z) = z\, {}_2F_2(1, 1; 2, 2; z) + \gamma + \tfrac{1}{2} \left(\log(z) - \log(1/z)\right) = -e^z U(1,1,-z) - \log(-z) + \tfrac{1}{2} \left(\log(z) - \log(1/z)\right),
Si⁡(z)=z 1F2(12;32,32;−z24)=i2[eizU(1,1,−iz)−e−izU(1,1,iz)+log⁡(−iz)−log⁡(iz)],\operatorname{Si}(z) = z\, {}_1F_2(\tfrac{1}{2}; \tfrac{3}{2}, \tfrac{3}{2}; -\tfrac{z^2}{4}) = \frac{i}{2} \left[ e^{iz} U(1,1,-iz) - e^{-iz} U(1,1,iz) + \log(-iz) - \log(iz) \right],
Ci⁡(z)=log⁡(z)+γ−z24 2F3(1,1;2,2,32;−z24)=log⁡(z)−12[eizU(1,1,−iz)+e−izU(1,1,iz)+log⁡(−iz)+log⁡(iz)],\operatorname{Ci}(z) = \log(z) + \gamma - \tfrac{z^2}{4}\, {}_2F_3(1, 1; 2, 2, \tfrac{3}{2}; -\tfrac{z^2}{4}) = \log(z) - \tfrac{1}{2} \left[ e^{iz} U(1,1,-iz) + e^{-iz} U(1,1,iz) + \log(-iz) + \log(iz) \right],

and similar ones for Shi⁡(z)=−iSi⁡(iz)\operatorname{Shi}(z) = -i\operatorname{Si}(iz) and Chi⁡\operatorname{Chi}, while li⁡(z)=Ei⁡(log⁡z)\operatorname{li}(z) = \operatorname{Ei}(\log z). The logarithmic terms implement the branch cuts of Mathematica: Ei⁡\operatorname{Ei}, Ci⁡\operatorname{Ci} and Chi⁡\operatorname{Chi} have a cut on (−∞,0](-\infty, 0], and the combination 12(log⁡z−log⁡(1/z))\frac12(\log z - \log(1/z)) equals log⁡z\log z except on the cut, where it averages the two sides. For each function the automatic version compares the accuracy of the asymptotic expansion (∣z∣/log⁡2|z|/\log 2 bits) with that of the series after cancellation, as for UU and MM.

For real arguments, arb_hypgeom_si and arb_hypgeom_ci avoid complex arithmetic: the convergent series are summed with arb_hypgeom_sum_fmpq_arb at a working precision raised by ∣z∣/log⁡2|z|/\log 2 bits, and the asymptotic expansions

Si⁡(z)=π2−cos⁡zzf(z)−sin⁡zzg(z),Ci⁡(z)=sin⁡zzf(z)−cos⁡zzg(z),\operatorname{Si}(z) = \frac\pi2 - \frac{\cos z}{z} f(z) - \frac{\sin z}{z} g(z), \qquad \operatorname{Ci}(z) = \frac{\sin z}{z} f(z) - \frac{\cos z}{z} g(z),

where f(z)+ig(z)∼∑kk! (i/z)kf(z) + i g(z) \sim \sum_k k!\,(i/z)^{k}, with arb_hypgeom_sum_fmpq_imag_arb in powers of 1/z1/z; the error of the asymptotic expansion is bounded by the first omitted term N!/zNN!/z^N. The number of terms of the asymptotic expansion is the first NN for which this bound is below 2−p2^{-p}, if the bound reaches it before it starts to grow.

Use in FLINT#

Referenced from#

References#

  • [NIST2012] National Institute of Standards and Technology, Digital Library of Mathematical Functions (2012), https://dlmf.nist.gov/
Cite this page

The FLINT team, “Error functions, incomplete gamma functions and exponential integrals,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/special-functions/error-functions.html (generated 2026-11-02).