The integral here is a complexcontour integral which is path-independent because isholomorphic on the whole complex plane. In many applications, the function argument is areal number, in which case the function value is also real.
In statistics, for non-negative real values ofx, the error function has the following interpretation: for a realrandom variableY that isnormally distributed withmean 0 andstandard deviation,erf(x) is the probability thatY falls in the range[−x,x].
Two closely related functions are thecomplementary error function erfc: defined as
The name "error function" and its abbreviationerf were proposed byJ. W. L. Glaisher in 1871 on account of its connection with "the theory of probability, and notably the theory oferrors".[3] The error function complement was also discussed by Glaisher in a separate publication in the same year.[4]For the "law of facility" of errors whosedensity is given by(thenormal distribution), Glaisher calculates the probability of an error lying betweenp andq as
When the results of a series of measurements are described by anormal distribution withstandard deviationσ andexpected value 0, thenerf (a/σ√2) is the probability that the error of a single measurement lies between−a and+a, for positivea. This is useful, for example, in determining thebit error rate of a digital communication system.
The error function and its approximations can be used to estimate results that holdwith high probability or with low probability. Given a random variableX ~ Norm[μ,σ] (a normal distribution with meanμ and standard deviationσ) and a constantL >μ, it can be shown viaintegration by substitution:
whereA andB are certain numeric constants. IfL is sufficiently far from the mean, specificallyμ −L ≥σ√ln(k), then:
so the probability goes to 0 ask → ∞.
The probability forX being in the interval[La,Lb] can be derived as
The propertyerf (−z) = −erf(z) means that the error function is anodd function. This directly results from the fact that the integrande−t2 is aneven function (the antiderivative of an even function which is zero at the origin is an odd function and vice versa).
The integrandf = exp(−z2) andf = erf(z) are shown in the complexz-plane in the figures at right withdomain coloring.
The error function at+∞ is exactly 1 (seeGaussian integral). At the real axis,erfz approaches unity atz → +∞ and −1 atz → −∞. At the imaginary axis, it tends to±i∞.
The error function is anentire function; it has no singularities (except that at infinity) and itsTaylor expansion always converges. Forx >> 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 thekth term into the(k + 1)th term (consideringz as the first term).
The imaginary error function has a very similar Maclaurin series, which is:which holds for everycomplex numberz.
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 bywhereH are the physicists'Hermite polynomials.[5]
Anantiderivative of the error function, obtainable byintegration by parts, isAn antiderivative of the imaginary error function, also obtainable by integration by parts, is
An expansion[6] which converges more rapidly for all real values ofx than a Taylor expansion is obtained by usingHans Heinrich Bürmann's theorem:[7]wheresgn is thesign function. By keeping only the first two coefficients and choosingc1 =31/200 andc2 = −341/8000, the resulting approximation shows its largestrelative error atx = ±1.40587, where it is less than 0.0034361:
Given a complex numberz, there is not aunique complex numberw satisfyingerf(w) =z, so a true inverse function would be multivalued. However, for−1 <x < 1, there is a uniquereal number denotederf−1(x) satisfying
Theinverse error function is usually defined with domain(−1,1), and it is restricted to this domain in manycomputer algebra systems. However, it can be extended to the disk|z| < 1 of the complex plane, using the Maclaurin series[8]wherec0 = 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 (sequenceA092676 in theOEIS) and (sequenceA092677 in theOEIS) respectively; without cancellation the numerator terms are values in (sequenceA002067 in theOEIS).) The error function's value at ±∞ is equal to ±1.
For|z| < 1, we haveerf(erf−1(z)) =z.
Theinverse complementary error function is defined asFor realx, there is a uniquereal numbererfi−1(x) satisfyingerfi(erfi−1(x)) =x. Theinverse imaginary error function is defined aserfi−1(x).[9]
For any realx,Newton's method can be used to computeerfi−1(x), and for−1 ≤x ≤ 1, the following Maclaurin series converges:whereck is defined as above.
A usefulasymptotic expansion of the complementary error function (and therefore also of the error function) for large realx iswhere(2n − 1)!! is thedouble factorial of(2n − 1), which is the product of all odd numbers up to(2n − 1). This series diverges for every finitex, and its meaning as asymptotic expansion is that for any integerN ≥ 1 one haswhere the remainder iswhich follows easily by induction, writingand integrating by parts.
The asymptotic behavior of the remainder term, inLandau notation, isasx → ∞. This can be found byFor large enough values ofx, only the first few terms of this asymptotic expansion are needed to obtain a good approximation oferfcx (while for not too large values ofx, 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)
One can improve the accuracy of the A&S 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 about2×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 forx ≥ 0. To use these approximations for negativex, use the fact thaterf(x) is an odd function, soerf(x) = −erf(−x).
Exponential bounds and a pure exponential approximation for the complementary error function are given by[14]
The above have been generalized to sums ofN exponentials[15] with increasing accuracy in terms ofN so thaterfc(x) can be accurately approximated or bounded by2Q̃(√2x), whereIn particular, there is a systematic methodology to solve the numerical coefficients{(an,bn)}N n = 1 that yield aminimax approximation or bound for the closely relatedQ-function:Q(x) ≈Q̃(x),Q(x) ≤Q̃(x), orQ(x) ≥Q̃(x) forx ≥ 0. The coefficients{(an,bn)}N n = 1 for many variations of the exponential approximations and bounds up toN = 25 have been released to open access as a comprehensive dataset.[16]
A tight approximation of the complementary error function forx ∈ [0,∞) is given byKaragiannidis & Lioumpas (2007),[17] who showed for the appropriate choice of parameters{A,B} thatThey determined{A,B} = {1.98,1.135}, which gave a good approximation[which?] for allx ≥ 0. Alternative coefficients are also available for tailoring accuracy for a specific application or transforming the expression into a tight bound.[18]
A single-term lower bound is[19]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":[20][21]: 2–3 whereThis is designed to be very accurate in the neighborhoods of 0 and infinity, and therelative error is less than 0.00035 for all realx. Using the alternate valuea ≈ 0.147 reduces the maximum relative error to about 0.00013.[22]
The extended "global Pade" approximation,provides a maximum error of about2×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 of1.2×10−7 for any real argument is:[23]
An approximation of with a maximum relative error less than in absolute value is:[24]for,and for
A simple approximation for real-valued arguments can be done throughhyperbolic 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)[25] based on a simplealgebraic 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 thebinomial 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 to2 + 2i
Thecomplementary error function, denotederfc, is defined aswhich also defineserfcx, thescaled complementary error function[26] (which can be used instead oferfc to avoidarithmetic underflow[26][27]). Another form oferfcx forx ≥ 0 is known as Craig's formula, after its discoverer:[28]This expression is valid only for positive values ofx, but can be used in conjunction witherfc(x) = 2 − erfc(−x) to obtainerfc(x) for negative values. This form is advantageous in that the range of integration is fixed and finite. An extension of this expression for theerfc of the sum of two non-negative variables is[29]
Plot of the imaginary error function erfi(z) in the complex plane from−2 − 2i to2 + 2i
Theimaginary error function, denotederfi, is defined aswhereD(x) is theDawson function (which can be used instead oferfi to avoidarithmetic overflow[26]).
Despite the name "imaginary error function",erfi(x) is real whenx is real.
When the error function is evaluated for arbitrarycomplex argumentsz, the resultingcomplex error function is usually discussed in scaled form as theFaddeeva function:
The normal cumulative distribution function plotted in the complex plane
The error function is essentially identical to the standardnormal cumulative distribution function, denotedΦ, also namednorm(x) by some software languages[citation needed], as they differ only by scaling and translation. Indeed,or rearranged forerf anderfc:
Consequently, the error function is also closely related to theQ-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 functionscerf,cerfc,cerfcx and the real functionserfi,erfcx with approximately 13–14 digits precision, based on theFaddeeva function as implemented in theMIT Faddeeva Package
^Cuyt, Annie A. M.; Petersen, Vigdis B.; Verdonk, Brigitte; Waadeland, Haakon; Jones, William B. (2008).Handbook of Continued Fractions for Special Functions. Springer-Verlag.ISBN978-1-4020-6948-2.
^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