In mathematics, the error function (also called the Gauss error function), often denoted by , is the function[1]
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 , the error function has the following interpretation: for a real random variable that is normally distributed with mean 0 and standard deviation , is the probability that falls in the range .
Two closely related functions are the complementary error function
The name "error function" and its abbreviation 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".[3] The complementary error function was also discussed by Glaisher in a separate publication in the same year.[4] For the "law of facility" of errors whose density is given by
(the normal distribution), Glaisher calculates the probability of an error lying between and as
is the probability that the error of a single measurement lies between and . 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 normally distributed random variable with mean and standard deviation and a constant , it can be shown via integration by substitution that
where and are certain numeric constants. If is sufficiently far from the mean, specifically,
,
then
and so the probability goes to 0 as .
The probability for being in the interval can be derived as
The error function is an odd function. This directly results from the fact that the integrand is an even function (since the antiderivative of an even function which is zero at the origin is an odd function, and vice versa).
The error function at is exactly (see Gaussian integral). At the real axis, approaches at and at . At the imaginary axis, it tends to .
Taylor series
The error function is an entire function; it has no singularities (except at infinity) and its Taylor expansion always converges. For , however, cancellation of leading terms makes the Taylor expansion impractical.
For iterative calculation of the above series, the following alternative formulation may be useful:
because
expresses the multiplier to turn the -th term into the -th term (considering as the first term).
The imaginary error function has a similar Maclaurin series:
which holds for every complex number .
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:
Higher order derivatives are given by
where the are the physicists' Hermite polynomials.[6]
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
Bürmann series
An expansion which converges more rapidly for all real values of than a Taylor expansion[7] is obtained by using Bürmann's theorem:[8]
where is the sign function. By keeping only the first two coefficients and choosing and , the resulting approximation shows its largest relative error at , where it is less than :
Inverse functions
Inverse error function
Given a complex number , there is not a unique complex number satisfying , so a true inverse function would be multivalued. However, for , there is a unique real number denoted satisfying
The inverse error function is usually defined with domain , and it is restricted to this domain in many computer algebra systems. However, it can be extended to the disk of the complex plane, using the Maclaurin series[9]
where and
So we have the series expansion (common factors have been canceled from numerators and denominators):
After cancellation the numerator and denominator are values in (sequence A092676 in the OEIS) and (sequence A092677 in the OEIS) respectively; without cancellation the numerator terms are values in (sequence A002067 in the OEIS). The error function's value at is equal to .
For , we have .
The inverse complementary error function is defined as
For real , there is a unique real number satisfying . The inverse imaginary error function is defined as .[10]
For any real , Newton's method can be used to compute , and for , the following Maclaurin series converges:
where 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 is
where is the double factorial of , i.e. the product of all odd numbers up to . This series diverges for every finite , and its meaning as asymptotic expansion is that for any integer one has
where the remainder is
which follows easily by induction, writing
and integrating by parts. The asymptotic behavior of the remainder term is
as . This can be found by
For large enough values of , only the first few terms of this asymptotic expansion are needed to obtain a good approximation of (while for not too large values of , 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) from C. Hastings, Jr.[15]. 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
One can improve the accuracy of the Hastings approximation by extending it with three extra parameters,
where p1 = 0.406742016006509,
p2 = 0.0072279182302319,
a1 = 0.316879890481381,
a2 = -0.138329314150635,
a3 = 1.08680830347054,
a4 = -1.11694155120396,
a5 = 1.20644903073232,
a6 = -0.393127715207728,
a7 = 0.0382613542530727.
The maximum error of this approximation is about 2×10−9. The parameters are obtained by fitting the extended approximation to the accurate values of the error function using the following Python code.
Python code to fit extended A&S approximation
importnumpyasnpfrommathimporterf,exp,sqrtfromscipy.optimizeimportleast_squares## Extended A&S approximation:# erf(x) ≈ 1 − t * exp(−x^2) * (a1 + a2*t + a3*t^2 + ... + a7*t^6)# where now# t = 1 / (1 + p1*x + p2*x^2)# We fit parameters p1, p2, a1..a7 over x in [0, 10].#defapprox_erf(params,x):p1=params[0]p2=params[1]a=params[2:]t=1.0/(1.0+p1*x+p2*x*x)poly=np.zeros_like(x)tt=np.ones_like(x)# t^0# polynomial: a1*t^0 + a2*t^1 + ... + a7*t^6forakina:poly+=ak*tttt*=treturn1.0-t*np.exp(-x*x)*polydefresiduals(params,xs,ys):returnapprox_erf(params,xs)-ys## Prepare data for fitting#N=300xmin=0xmax=10xs=np.linspace(xmin,xmax,N)ys=np.array([erf(x)forxinxs],dtype=float)## Initial guess for parameters# Start from original A&S values and extend them conservatively#p1_0=0.3275911# original A&S pp2_0=0.0# new denominator parameter# original A&S 5 coefficients, add two => 7 in totala0=[0.254829592,-0.284496736,1.421413741,-1.453152027,1.061405429,0.0,# new term0.0,# another new term]params0=np.array([p1_0,p2_0]+a0,dtype=float)## Fit using nonlinear least squares (Levenberg–Marquardt)#result=least_squares(residuals,params0,args=(xs,ys),xtol=1e-14,ftol=1e-14,gtol=1e-14,max_nfev=5000)params=result.xp1_fit=params[0]p2_fit=params[1]a_fit=params[2:]## Print fitted parameters#print("\nFitted parameters:")print(f"p1 = {p1_fit:.15g},")print(f"p2 = {p2_fit:.15g},")fori,aiinenumerate(a_fit,1):print(f"a{i} = {ai:.15g},")## Evaluate approximation error#approx_vals=approx_erf(params,xs)abs_err=np.abs(approx_vals-ys)print(f"\nMaximum absolute error on [{xmin},{xmax}]:",np.max(abs_err))print("RMS error:",np.sqrt(np.mean(abs_err**2)))print("Done.")
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[16]
The above have been generalized to sums of N exponentials[17] 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.[18]
A tight approximation of the complementary error function for x ∈ [0,∞) is given by Karagiannidis & Lioumpas (2007),[19] 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.[20]
A single-term lower bound is[21]
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":[22][23]:2–3
where
This is designed to be very accurate in the neighborhoods of 0 and 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.[24]
The extended "global Pade" approximation,
provides a maximum error of about 2×10−9, as demonstrated by the following Python script.
Python script to fit extended "global Pade" approximation
importnumpy,mathfromscipy.optimizeimportleast_squares# approximation to erf(x)defapprox_erf(p,x):frac=(4+p[0]*x**2+p[1]*x**4+p[2]*x**6)/(math.pi+p[3]*x**2+p[4]*x**4+p[5]*x**6)returnnumpy.sign(x)*numpy.sqrt(1-numpy.exp(-x*x*frac))defresiduals(params,xs,ys):returnapprox_erf(params,xs)-ys# data for fittingN=200xmin=0xmax=9xs=numpy.linspace(xmin,xmax,N)ys=numpy.array([math.erf(x)forxinxs],dtype=float)params0=numpy.array([0.9,0.1,0.008,0.8,0.1,0.008],dtype=float)# fittingresult=least_squares(residuals,params0,args=(xs,ys),xtol=1e-14,ftol=1e-14,gtol=1e-14,max_nfev=5000)params=result.x# print out fitted parametersprint("\nFitted parameters:")fori,piinenumerate(params,0):print(f"p{i} = {pi:.15g},")# evaluate approximation errorapprox_vals=approx_erf(params,xs)abs_err=numpy.abs(approx_vals-ys)print(f"\nMaximum absolute error on [{xmin},{xmax}]:",numpy.max(abs_err))print("RMS error:",numpy.sqrt(numpy.mean(abs_err**2)))print("Done.")
Winitzki's 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:[25]
An approximation of with a maximum relative error less than in absolute value is:[26]
for ,
and for
A simple approximation for real-valued arguments can 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)[27] based on a simple algebraic expression with only two exponential terms:
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.
Plot of the error function erf(z) in the complex plane from −2 − 2i to 2 + 2i
The complementary error function, denoted erfc, is defined as
which also defines erfcx, the scaled complementary error function[28] (which can be used instead of erfc to avoid arithmetic underflow[28][29]). Another form of erfc x for x ≥ 0 is known as Craig's formula, after its discoverer:[30]
This expression is valid only for positive values of x, but 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[31]
Imaginary error function
Plot of the imaginary error function erfi(z) in the complex plane from −2 − 2i to 2 + 2i
The imaginary error function, denoted erfi, is defined as
where D(x) is the Dawson function (which can be used instead of erfi to avoid arithmetic overflow[28]).
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 normal cumulative distribution function plotted in the complex plane
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,
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
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
↑Zeng, Caibin; Chen, Yang Cuan (2015). "Global Padé approximations of the generalized Mittag-Leffler function and its inverse". Fractional Calculus and Applied Analysis. 18 (6): 1492–1506. arXiv:1310.5592. doi:10.1515/fca-2015-0086. S2CID118148950. Indeed, Winitzki [32] provided the so-called global Padé approximation
You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.