[Math] Computing the inverse error function

error functionnormal distributionprobability distributions

I need a formula/series to compute the inverse error function, which is the inverse of
$$
\operatorname{erf}(x) = \dfrac{2}{\sqrt{\pi}} \int\limits_{0}^{x} \mathrm{e}^{-t^2} \,\mathrm{d}t.
$$

Apparently the Maclaurin series for the inverse error function is
$$
\operatorname{erf}^{-1}(x) = \sqrt{\pi} \left( \frac{1}{2}x + \frac{1}{24}\pi x^3 + \frac{7}{960}\pi^2 x^5 + \frac{127}{80\,640}\pi^3 x^7 + \ldots \right),
$$
but I have no idea how many terms I need for it to converge (something like 4 decimal places would be fine for me, but I'd like to know the general answer). Alternatively, is there a better way of computing this function?

Best Answer

I'm no expert on the error function, but I can offer you this. To match the series you give, your $\mathrm{erf}(x)$ should be defined with $\frac{2}{\sqrt{\pi}}$ out front.

Also, the error in any series, will be on the order of $t^{n+1}$, where $n$ is the exponent of the last term you included in your series. Since the even-powered terms in this series always have $0$ coefficient, you may as well assume that you included a final zero term, and so your convergence error will be on the order of $t$ to the next odd integer. Since the inverse error function blows up to $\pm\infty$ at $\pm 1$, and you want $\lvert t \rvert^{n+2}<10^{-4}$, the series will converge accurately enough for you in the range: $\lvert t \rvert < 10^{-4/(n+2)}.$ Unfortunately, this doesn't converge very fast and you will need more and more terms the larger and larger $\lvert t \rvert$ gets.

Below, I've used Mathematica to show its built in functions are the ones you're referencing and to work out several more terms for you. From what I've seen of the error function (and reliance on built in functions in software), I don't believe there's a nice or simple general form. (Click the image to embiggen.)

Mathematica code, verifying the series it gives is for the one desired.