Preprint
Article

Analytic Error Function and Numeric Inverse Obtained by Geometric Means

Altmetrics

Downloads

186

Views

22

Comments

0

A peer-reviewed article of this preprint also exists.

This version is not peer-reviewed

Submitted:

27 February 2023

Posted:

27 February 2023

You are already at the latest version

Alerts
Abstract
Using geometric considerations, we provide a clear derivation of the integral representation for the error function, known as the Craig formula. We calculate the corresponding power series expansion and prove the convergence. The same geometric means finally help to systematically derive handy formulas that approximate the inverse error function. Our approach can be used for applications in e.g. high-speed Monte Carlo simulations where this function is used extensively.
Keywords: 
Subject: Physical Sciences  -   Mathematical Physics

MSC:  62E15; 62E17; 60E15; 26D15

1. Introduction

High-speed Monte Carlo simulations are used for a large spectrum of applications from mathematics to economy. As input for such simulations, the probability distribution are usually generated by pseudo-random number sambling, a method going back to a work of John von Neumann from 1951 [1]. In the era of “big data” such methods have to be fast and reliable, a sign of such neccessity being the release of the very first randomness Quside processing unit in 2023 [2]. Still, these samblings need to be cross-checked by exact methods, and for these the knowledge of analytical functions to describe the stochastic processes, among those the error function, are of tremendous importance.
By definition, a function is called analytic if it locally given by a converging Taylor series expansion. Even if a function itself turns out not to be analytic, its inverse can be analytic. The error function can be given analytically, one of these analytic expressions is the integral representation given by Craig in 1991 [3]. Craig mentioned this representation only in passing and did not give a derivation of it. In the following, there have been a couple of derivations of this formula [4,5,6]. In Sec. 2 we add a further one which is based on the same geometric considerations as employed in Ref. [7]. In Sec. 3 we give the series expansion for Craig’s integral representation and show the fast convergence of this series.
For the inverse error function, handbooks for special functions (cf. e.g., Ref. [8]) do not unveil such an analytic property. Instead, this function have to be approximated. Known approximations are dating back to the late 1960s and early 1970s [9,10]) and reach up to semi-analytical approximations by asymptotic expansion (cf., e.g., Refs. [11,12,13,14,15,16]. Using the same geometric considerations, in Sec. 4 we develop a couple of handy approximations which can easily be implemented in different computer languages, indicating the deviations from an exact treatment. In Sec. 5 we test the CPU time and give our conclusions.

2. Derivation of Craig’s integral representation

Ref. [7] provides an approximation for the Gaussian normal distribution obtained by geometric considerations. The same considerations apply to the error function erf ( t ) which is given by the normal distribution P ( t ) via
erf ( t ) = 1 π t t e x 2 d x = 1 2 π 2 t 2 t e x 2 / 2 d x = P ( 2 t ) .
Translating the results of Ref. [7] to the error function, one obtains the approximation of order p to be
erf p ( t ) 2 = 1 1 N n = 1 N e k n 2 t 2 ,
where the N = 2 p values k n ( n = 1 , 2 , , N ) are found in the intervals between 1 / cos ( π ( n 1 ) / ( 4 N ) ) and 1 / cos ( π n / ( 4 N ) ) and can be optimised. In Ref. [7] it is shown that
| erf ( t ) 1 e k 0 , 1 2 t 2 | < 0.0033
for k 0 , 1 = 1.116 , and with 14 0.0033 / 0.00024 times larger precision
| erf ( t ) 1 1 2 ( e k 1 2 t 2 + e k 2 2 t 2 ) | < 0.00024 ,
where k 1 , 1 = 1.01 , k 1 , 2 = 1.23345 . For the parameters k n taking the values k n = 1 / cos ( π n / ( 4 N ) ) of the upper limits of those intervals, it can be shown that the deviation is given by
| erf ( t ) erf p ( t ) | < exp ( t 2 ) 2 N 1 exp ( t 2 ) .
Given the values k n = 1 / cos ϕ ( n ) with ϕ ( n ) = π n / ( 4 N ) , in the limit N the sum over n in Equation (2) can be replaced by an integral with measure d n = ( 4 N / π ) d ϕ ( n ) to obtain
erf ( t ) 2 = 1 4 π 0 π / 4 exp t 2 cos 2 ϕ d ϕ .

3. Power series expansion

The integral in Equation (6) can be expanded into a power series in t 2 ,
erf ( t ) 2 = 1 4 π n = 0 c n ( 1 ) n n ! ( t 2 ) n
with
c n = 0 π / 4 d ϕ cos 2 n ϕ = 0 π / 4 ( 1 + tan 2 ϕ ) n d ϕ = 0 1 ( 1 + y 2 ) n 1 d y = k = 0 n 1 n 1 k 0 1 y 2 k d y = k = 0 n 1 1 2 k + 1 n 1 k ,
where y = tan ϕ . The coefficients c n can be expressed by the hypergeometric function, c n =   2 F 1 ( 1 / 2 , 1 n ; 3 / 2 ; 1 ) , also known as Barnes’ extended hypergeometric function. On the other hand, we can derive a constraint for the explicit finite series expression for c n that renders the series in Equation (7) to be convergent for all values of t. In order to be self-contained, intermediate steps to derive this constraint and to show the convergence are shown in the following. Necessary is Pascal’s rule
n k + n k 1 = n ! k ! ( n k ) ! + n ! ( k 1 ) ! ( n k + 1 ) ! = n ! ( n k + 1 + k ) k ! ( n k + 1 ) ! = ( n + 1 ) ! k ! ( n + 1 k ) ! = n + 1 k
and the sum over the rows of Pascal’s triangle,
k = 0 n n k = 2 n
which can be shown by mathematical induction. The base case n = 0 is obvious, as ( 0 0 ) = 1 = 2 0 . For the induction step from n to n + 1 we write the first and last elements ( n + 1 0 ) = 1 and ( n + 1 n + 1 ) = 1 separately and use Pascal’s rule to obtain
k = 0 n + 1 n + 1 k = 1 + k = 1 n n + 1 k + 1 = = 1 + k = 1 n n k + k = 1 n n k 1 + 1 = 2 k = 0 n n k = 2 n + 1 .
This proves Equation (10). Returning to Equation (8), one has 0 k n 1 and, therefore,
1 2 n 1 1 2 k + 1 1 .
For the result in Equation (8) this means that
1 2 n 1 k = 0 n 1 n 1 k c n k = 0 n 1 n 1 k = 2 n 1 ,
i.e., the existence of a real number c n * between 1 / ( 2 n 1 ) and 1 such that c n = c n * 2 n 1 . One has
erf p ( t ) 2 = 1 4 π n = 0 N c n ( 1 ) n n ! ( t 2 ) n = 1 2 π n = 0 N c n * ( 2 t 2 ) n n ! ,
and because of 0 c n * 1 there is again a real number c N * * in the corresponding open interval so that
2 π n = 0 N c n * ( 2 t 2 ) n n ! = c N * * 2 π n = 0 N ( 2 t 2 ) n n ! < 2 π n = 0 N ( 2 t 2 ) n n ! .
As the latter is the power series expansion of ( 2 / π ) e 2 t 2 which is convergent for all values of t, also the original series is convergent and, therefore, erf p ( t ) 2 with the limiting value shown in Equation (7). A more compact form of the power series expansion is given by
erf ( t ) 2 = n = 1 c n ( 1 ) n 1 n ! ( t 2 ) n , c n = k = 0 n 1 1 2 k + 1 n 1 k .

4. Approximations for the inverse error function

Based on the geometric approach from Ref. [7], in the following we describe how to find simple, handy formulas that, guided by higher and higher orders of the approximation (2) for the error function lead to more and more advanced approximation of the inverse error function. Starting point is the degree p = 0 , i.e., the approximation in Equation (3). Inverting E = erf 0 ( t ) = ( 1 e k 0 , 1 2 t 2 ) 1 / 2 leads to t 2 = ln ( 1 E 2 ) / k 0 , 1 2 , and using the parameter k 0 , 1 = 1.116 from Equation (3) gives
T 0 = ln ( 1 E 2 ) / k 0 , 1 2 .
For 0 E 0.92 the relative deviation ( T ( 0 ) t ) / t from the exact value t is less than 1.11 % , for 0 E < 1 the deviation is less than 10 % . Therefore, for E > 0.92 a more precise formula has to be used. As such higher values for E appear only in 8 % of the cases, this will not essentially influence the CPU time.
Continuing with p = 1 , we insert T 0 = ln ( 1 E 2 ) / k 0 , 1 2 into Equation (2) to obtain
erf 1 ( T 0 ) = 1 1 2 ( e k 1 , 1 2 T 0 2 + e k 1 , 2 2 T 0 2 ) ,
where k 1 , 1 = 1.01 and k 1 , 2 = 1.23345 are the same as for Equation (4). Taking the derivative of Equation (1) and approximating this by the difference quotient, one obtains
erf ( t ) erf ( T 0 ) t T 0 = Δ erf ( t ) Δ t | t = T 0 d erf ( t ) d t | t = T 0 = 2 π e T 0 2 ,
leading to t T 1 = T 0 + 1 2 π e T 0 2 ( E erf 1 ( T 0 ) ) . In this case, for in the larger interval 0 E 0.995 the relative deviation ( T 1 t ) / t is less than 0.1 % . Using erf 2 ( t ) instead of erf 1 ( t ) and inserting T 1 instead of T 0 one obtains T 2 with a relative deviation of maximally 0.01 % for the same interval. The results are shown in Figure 1.
The method to can be optimised by a method similar to the shooting method in boundary problems, giving dynamics to the calculation. Suppose that following one of the previous methods, for a particular argument E we have found an approximation t 0 for the value of the inverse error function at this argument. Using t 1 = 1.01 t 0 , one can adjust the improved result
t = t 0 + A ( E erf ( t 0 ) )
by inserting E = erf ( t ) and and calculating A for t = t 1 . In general, this procedure gives a vanishing deviation close to E = 0 . In this case and for t 0 = T 1 , in the interval 0 E 0.7 the maximal deviation is slightly larger than 10 6 = 0.0001 % while up to E = 0.92 the deviation is restricted to 10 5 = 0.001 % . A more general ansatz
t = t 0 + A ( E erf ( t 0 ) ) + B ( E erf ( t 0 ) ) 2
can be adjusted by inserting E = erf ( t ) for t = 1.01 t 0 and t = 1.02 t 0 , and the system of equations
Δ t = A Δ E 1 + B Δ E 1 2 , 2 Δ t = A Δ E 2 + B Δ E 2 2
with Δ t = 0.01 t 0 , Δ E i = erf ( t i ) erf ( t 0 ) can be solved for A and B to obtain
A = ( 2 Δ E 1 2 Δ E 2 2 ) Δ t Δ E 1 Δ E 2 ( Δ E 1 Δ E 2 ) , B = ( 2 Δ E 1 + Δ E 2 ) Δ t Δ E 1 Δ E 2 ( Δ E 1 Δ E 2 ) .
For 0 E 0.70 one obtains a relative deviation of 1.5 · 10 8 , for 0 E 0.92 the maximal deviation is 5 · 10 7 . Finally, the adjustment of
t = t 0 + A ( E erf ( t 0 ) ) + B ( E erf ( t 0 ) ) 2 + C ( E erf ( t 0 ) ) 3
leads to
A = ( 3 Δ E 1 2 Δ E 2 2 ( Δ E 1 Δ E 2 ) 2 Δ E 1 2 Δ E 3 2 ( Δ E 1 Δ E 3 ) ( ( + Δ E 2 2 Δ E 3 2 ( Δ E 2 Δ E 3 ) ) Δ t / D , B = ( 3 Δ E 1 Δ E 2 ( Δ E 1 2 Δ E 2 2 ) + 2 Δ E 1 Δ E 3 ( Δ E 1 2 Δ E 3 2 ) ( ( Δ E 2 Δ E 3 ( Δ E 2 2 Δ E 3 2 ) ) Δ t / D , C = ( 3 Δ E 1 Δ E 2 ( Δ E 1 Δ E 2 ) 2 Δ E 1 Δ E 3 ( Δ E 1 Δ E 3 ) ( ( + Δ E 2 Δ E 3 ( Δ E 2 Δ E 3 ) ) Δ t / D ,
where D = Δ E 1 Δ E 2 Δ E 3 ( Δ E 1 Δ E 2 ) ( Δ E 1 Δ E 3 ) ( Δ E 2 Δ E 3 ) . For 0 E 0.70 the relative deviation is restricted to 5 · 10 10 while up to E = 0.92 the maximal relative deviation is 4 · 10 8 . The results for the deviations of T ( n ) ( n = 1 , 2 , 3 ) for linear, quadratic and cubic dynamical approximation are shown in Figure 2.

5. Conclusions

In order to test the feasibility and speed, we have coded our algorithm in the computer language C under Slackware 15.0 on an ordinary hp laptop. The dependence of the CPU time for the calculation is estimated by calculating the value 10 6 times in sequence. The speed of the calculation of course turns does not depend on the value for E, as the precision is not optimised. This would have to be neccessary for a practical application. For an arbitrary starting value E = 0.8 we perform this test, and the results are given in Table 1. An analysis of the table shows that a further step in the degree p doubles the run time while the dynamics for increasing n adds a constant value of approximately 0.06 seconds to the result. Despite the fact the increase of the dynamics needs the solution of a linear system of equations and the coding of the result, this endeavour is justified, as by using the dynamics one can increase the precision of the result without loosing calculational speed.

Author Contributions

Conceptualization, D.M.; methodology, D.M. and S.G.; writing—original draft preparation, D.M.; writing—review and editing, S.G. and D.M.; visualization, S.G.; All authors have read and agreed to the published version of the manuscript.

Funding

This research was funded by the European Regional Development Fund under Grant No. TK133.

Institutional Review Board Statement

Not applicable.

Informed Consent Statement

Not applicable.

Data Availability Statement

Not applicable.

Conflicts of Interest

The authors declare no conflict of interest.

References

  1. von Neumann, J.; von Neumann, J. Various Techniques Used in Connection with Random Digits. in Householder, A.S.; Forsythe, G.E.; and Germond, H.H. (eds.). Monte Carlo Methods. National Bureau of Standards Applied Mathematics Series 1951, 12, 36–38. [Google Scholar]
  2. Available online: https://quside.com/quside-unveils-the-worlds-first-randomness-processing-unit.
  3. Craig, J.W. A new, simple and exact result for calculating the probability of error for two-dimensional signal constellations. Proceedings of the 1991 IEEE Military Communication Conference 1991, 2, 571–575. [Google Scholar]
  4. Lever, K.V. New derivation of Craig’s formula for the Gaussian probability function. Electronics Letters 1998, 34, 1821–1822. [Google Scholar] [CrossRef]
  5. Tellambura, C; Annamalai, A. Derivation of Craig’s formula for Gaussian probability function. Electronics Letters 1999, 35, 1424–1425. [CrossRef]
  6. Stewart, S.M. Some alternative derivations of Craig’s formula. The Mathematical Gazette 2017, 101, 268–279. [Google Scholar] [CrossRef]
  7. Martila, D.; Groote, S. Evaluation of the Gauss Integral. Stats 2022, 5, 538–545. [Google Scholar] [CrossRef]
  8. Andrews, L.C. Special functions of mathematics for engineers. SPIE Press 1998, 110. [Google Scholar]
  9. Strecok, A.J. On the Calculation of the Inverse of the Error Function. Math. Comp. 1968, 22, 144–158. [Google Scholar]
  10. Blair, J. M; Edwards, C.A.; Johnson, J.H. Rational Chebyshev Approximations for the Inverse of the Error Function. Math. Comp. 1976, 30, 827–830. [Google Scholar] [CrossRef]
  11. Bergsma, W.P. A new correlation coefficient, its orthogonal decomposition and associated tests of independence. arXiv:math/0604627 [math.ST].
  12. Dominici, D. Asymptotic analysis of the derivatives of the inverse error function. arXiv:math/0607230 [math.CA].
  13. Dominici, D; Knessl, C. Asymptotic analysis of a family of polynomials associated with the inverse error function. arXiv:0811.2243 [math.CA].
  14. Winitzki, S. A handy approximation for the error function and its inverse. Available online: https://www.academia.edu/9730974/.
  15. Giles, M. Approximating the erfinv function. GPU Computing Gems Jade Edition, 2011; 109–116. [Google Scholar]
  16. Soranzo, A; Epure, E. Simply Explicitly Invertible Approximations to 4 Decimals of Error Function and Normal Cumulative Distribution Function. arXiv:1201.1320 [stat.CO].
Figure 1. Relative deviations for the statical approximations
Figure 1. Relative deviations for the statical approximations
Preprints 69189 g001
Figure 2. Relative deviation for the dynamical approximations (the degree is chosen to be p = 1 )
Figure 2. Relative deviation for the dynamical approximations (the degree is chosen to be p = 1 )
Preprints 69189 g002
Table 1. Run time experiment for our algorithm under C for E = 0.8 and different values of n and p (CPU time in seconds). As indicated, the errors are in the last displayed digit, i.e., ± 0.01 seconds.
Table 1. Run time experiment for our algorithm under C for E = 0.8 and different values of n and p (CPU time in seconds). As indicated, the errors are in the last displayed digit, i.e., ± 0.01 seconds.
n = 0 n = 1 n = 2 n = 3
p = 0 0.06 ( 1 ) 0.12 ( 1 ) 0.15 ( 1 ) 0.18 ( 1 )
p = 1 0.13 ( 1 ) 0.19 ( 1 ) 0.22 ( 1 ) 0.25 ( 1 )
p = 2 0.24 ( 1 ) 0.29 ( 1 ) 0.33 ( 1 ) 0.36 ( 1 )
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.
Copyright: This open access article is published under a Creative Commons CC BY 4.0 license, which permit the free download, distribution, and reuse, provided that the author and preprint are cited in any reuse.
Prerpints.org logo

Preprints.org is a free preprint server supported by MDPI in Basel, Switzerland.

Subscribe

© 2024 MDPI (Basel, Switzerland) unless otherwise stated