In mathematics, the error function (also called the Gauss error function), often denoted by erf, is a function defined as:
The integral here is a complex contour integral which is path-independent because is holomorphic on the whole complex plane . In many applications, the function argument is a real number, in which case the function value is also real.
In statistics, for non-negative real values of x, the error function has the following interpretation: for a real random variableY that is normally distributed with mean 0 and standard deviation, erf x is the probability that Y falls in the range [−x, x].
Two closely related functions are the complementary error functionis defined as
The name "error function" and its abbreviation erf were proposed by J. W. L. Glaisher in 1871 on account of its connection with "the theory of Probability, and notably the theory of Errors." The error function complement was also discussed by Glaisher in a separate publication in the same year. For the "law of facility" of errors whose density is given by (the normal distribution), Glaisher calculates the probability of an error lying between p and q as:
Plot of the error function Erf(z) in the complex plane from -2-2i to 2+2i with colors created with Mathematica 13.1 function ComplexPlot3D
Applications
When the results of a series of measurements are described by a normal distribution with standard deviationσ and expected value 0, then erf (a/σ√2) is the probability that the error of a single measurement lies between −a and +a, for positive a. This is useful, for example, in determining the bit error rate of a digital communication system.
The error function and its approximations can be used to estimate results that hold with high probability or with low probability. Given a random variable X ~ Norm[μ,σ] (a normal distribution with mean μ and standard deviation σ) and a constant L > μ, it can be shown via integration by substitution:
where A and B are certain numeric constants. If L is sufficiently far from the mean, specifically μ − L ≥ σ√ln k, then:
so the probability goes to 0 as k → ∞.
The probability for X being in the interval [La, Lb] can be derived as
Properties
Plots in the complex plane
Integrand exp(−z2)
erf z
The property erf (−z) = −erf z means that the error function is an odd function. This directly results from the fact that the integrand e−t2 is an even function (the antiderivative of an even function which is zero at the origin is an odd function and vice versa).
The integrand f = exp(−z2) and f = erf z are shown in the complex z-plane in the figures at right with domain coloring.
The error function at +∞ is exactly 1 (see Gaussian integral). At the real axis, erf z approaches unity at z → +∞ and −1 at z → −∞. At the imaginary axis, it tends to ±i∞.
Taylor series
The error function is an entire function; it has no singularities (except that at infinity) and its Taylor expansion always converges. For x >> 1, however, cancellation of leading terms makes the Taylor expansion unpractical.
For iterative calculation of the above series, the following alternative formulation may be useful: because −(2k − 1)z2/k(2k + 1) expresses the multiplier to turn the kth term into the (k + 1)th term (considering z as the first term).
The imaginary error function has a very similar Maclaurin series, which is: which holds for every complex numberz.
Derivative and integral
The derivative of the error function follows immediately from its definition: From this, the derivative of the imaginary error function is also immediate: An antiderivative of the error function, obtainable by integration by parts, is An antiderivative of the imaginary error function, also obtainable by integration by parts, is Higher order derivatives are given by where H are the physicists' Hermite polynomials.
Bürmann series
An expansion, which converges more rapidly for all real values of x than a Taylor expansion, is obtained by using Hans Heinrich Bürmann's theorem: where sgn is the sign function. By keeping only the first two coefficients and choosing c1 =31/200 and c2 = −341/8000, the resulting approximation shows its largest relative error at x = ±1.40587, where it is less than 0.0034361:
Inverse functions
Inverse error function
Given a complex number z, there is not a unique complex number w satisfying erf w = z, so a true inverse function would be multivalued. However, for −1 < x < 1, there is a unique real number denoted erf−1x satisfying
The inverse error function is usually defined with domain (−1,1), and it is restricted to this domain in many computer algebra systems. However, it can be extended to the disk |z| < 1 of the complex plane, using the Maclaurin series where c0 = 1 and
So we have the series expansion (common factors have been canceled from numerators and denominators): (After cancellation the numerator and denominator values in OEIS: A092676 and OEIS: A092677 respectively; without cancellation the numerator terms are values in OEIS: A002067.) The error function's value at ±∞ is equal to ±1.
For |z| < 1, we have erf(erf−1z) = z.
The inverse complementary error function is defined as For real x, there is a unique real number erfi−1x satisfying erfi(erfi−1x) = x. The inverse imaginary error function is defined as erfi−1x.
For any real x, Newton's method can be used to compute erfi−1x, and for −1 ≤ x ≤ 1, the following Maclaurin series converges: where ck is defined as above.
Asymptotic expansion
A useful asymptotic expansion of the complementary error function (and therefore also of the error function) for large real x is where (2n − 1)!! is the double factorial of (2n − 1), which is the product of all odd numbers up to (2n − 1). This series diverges for every finite x, and its meaning as asymptotic expansion is that for any integer N ≥ 1 one has where the remainder is which follows easily by induction, writing and integrating by parts.
The asymptotic behavior of the remainder term, in Landau notation, is as x → ∞. This can be found by For large enough values of x, only the first few terms of this asymptotic expansion are needed to obtain a good approximation of erfc x (while for not too large values of x, the above Taylor expansion at 0 provides a very fast convergence).
Abramowitz and Stegun give several approximations of varying accuracy (equations 7.1.25–28). This allows one to choose the fastest approximation suitable for a given application. In order of increasing accuracy, they are: (maximum error: 5×10−4)
where p = 0.3275911, a1 = 0.254829592, a2 = −0.284496736, a3 = 1.421413741, a4 = −1.453152027, a5 = 1.061405429
All of these approximations are valid for x ≥ 0. To use these approximations for negative x, use the fact that erf x is an odd function, so erf x = −erf(−x).
Exponential bounds and a pure exponential approximation for the complementary error function are given by
The above have been generalized to sums of N exponentials with increasing accuracy in terms of N so that erfc x can be accurately approximated or bounded by 2Q̃(√2x), where In particular, there is a systematic methodology to solve the numerical coefficients {(an,bn)}N n = 1 that yield a minimax approximation or bound for the closely related Q-function: Q(x) ≈ Q̃(x), Q(x) ≤ Q̃(x), or Q(x) ≥ Q̃(x) for x ≥ 0. The coefficients {(an,bn)}N n = 1 for many variations of the exponential approximations and bounds up to N = 25 have been released to open access as a comprehensive dataset.
A tight approximation of the complementary error function for x ∈ [0,∞) is given by Karagiannidis & Lioumpas (2007) who showed for the appropriate choice of parameters {A,B} that They determined {A,B} = {1.98,1.135}, which gave a good approximation for all x ≥ 0. Alternative coefficients are also available for tailoring accuracy for a specific application or transforming the expression into a tight bound.
A single-term lower bound is where the parameter β can be picked to minimize error on the desired interval of approximation.
Another approximation is given by Sergei Winitzki using his "global Padé approximations": where This is designed to be very accurate in a neighborhood of 0 and a neighborhood of infinity, and the relative error is less than 0.00035 for all real x. Using the alternate value a ≈ 0.147 reduces the maximum relative error to about 0.00013.
This approximation can be inverted to obtain an approximation for the inverse error function:
An approximation with a maximal error of 1.2×10−7 for any real argument is: with and
An approximation of with a maximum relative error less than in absolute value is: for ,and for
A simple approximation for real-valued arguments could be done through Hyperbolic functions: which keeps the absolute difference .
Since the error function and the Gaussian Q-function are closely related through the identity or equivalently , bounds developed for the Q-function can be adapted to approximate the complementary error function. A pair of tight lower and upper bounds on the Gaussian Q-function for positive arguments was introduced by Abreu (2012) based on a simple algebraic expression with only two exponential terms: and These bounds stem from a unified form where the parameters and are selected to ensure the bounding properties: for the lower bound, and , and for the upper bound, and . These expressions maintain simplicity and tightness, providing a practical trade-off between accuracy and ease of computation. They are particularly valuable in theoretical contexts, such as communication theory over fading channels, where both functions frequently appear. Additionally, the original Q-function bounds can be extended to for positive integers via the binomial theorem, suggesting potential adaptability for powers of , though this is less commonly required in error function applications.
The complementary error function, denoted erfc, is defined as
Plot of the complementary error function Erfc(z) in the complex plane from -2-2i to 2+2i with colors created with Mathematica 13.1 function ComplexPlot3D
which also defines erfcx, the scaled complementary error function (which can be used instead of erfc to avoid arithmetic underflow). Another form of erfc x for x ≥ 0 is known as Craig's formula, after its discoverer: This expression is valid only for positive values of x, but it can be used in conjunction with erfc x = 2 − erfc(−x) to obtain erfc(x) for negative values. This form is advantageous in that the range of integration is fixed and finite. An extension of this expression for the erfc of the sum of two non-negative variables is as follows:
Imaginary error function
The imaginary error function, denoted erfi, is defined as
Plot of the imaginary error function Erfi(z) in the complex plane from -2-2i to 2+2i with colors created with Mathematica 13.1 function ComplexPlot3D
Despite the name "imaginary error function", erfi x is real when x is real.
When the error function is evaluated for arbitrary complex arguments z, the resulting complex error function is usually discussed in scaled form as the Faddeeva function:
Cumulative distribution function
The error function is essentially identical to the standard normal cumulative distribution function, denoted Φ, also named norm(x) by some software languages, as they differ only by scaling and translation. Indeed,
the normal cumulative distribution function plotted in the complex plane
or rearranged for erf and erfc:
Consequently, the error function is also closely related to the Q-function, which is the tail probability of the standard normal distribution. The Q-function can be expressed in terms of the error function as
Iterated integrals of the complementary error function
The iterated integrals of the complementary error function are defined by
The general recurrence formula is
They have the power series from which follow the symmetry properties and
Implementations
As real function of a real argument
In POSIX-compliant operating systems, the header math.h shall declare and the mathematical library libm shall provide the functions erf and erfc (double precision) as well as their single precision and extended precision counterparts erff, erfl and erfcf, erfcl.
libcerf, numeric C library for complex error functions, provides the complex functions cerf, cerfc, cerfcx and the real functions erfi, erfcx with approximately 13–14 digits precision, based on the Faddeeva function as implemented in the MIT Faddeeva Package