# Erf squared approximation

I found a nice and useful approximation of squared error function $$\mathrm{erf}^{2}\!\left(x\right)=1-\exp\!\left(-\frac{\pi^{2}}{8}x^{2}\right)+\varepsilon\!\left(x\right).$$

I checked numerically that maximum error is bounded by $\left|\varepsilon\!\left(x\right)\right| < 61\cdot10^{-4}$ but I was asked if this could be somehow proved analytically. Or at least if order of the error could be determined in such manner.

Error function is defined as $$\mathrm{erf}\left(x\right)=\frac{2}{\sqrt{\pi}}\int_{0}^{x}\exp\left(-t^{2}\right)\,\mathrm{d}t = 2\Phi\!\left(x\sqrt{2}\right)-1,$$ where $\Phi\!\left(x\right)$ is normal cumulative distribution function.

And more generally: is numerical check not enough in such cases?

## 2 Answers

Such kind of inequalities can be proved through Fubini's theorem, since:

$$\operatorname{erf}(x)^2 = \frac{4}{\pi}\iint_{[0,x]^2}e^{-(u^2+v^2)}\,du\,dv=\frac{1}{\pi}\iint_{[-x,x]^2}e^{-(u^2+v^2)}\,du\,dv$$ and the last integral, over a square, can be effectively approximated with an integral over a suitable circle, whose explicit form is given by: $$1-\exp\left({-\rho^2 x^2}\right).$$ For instance, it is trivial that: $$\operatorname{erf}(x)^2 \geq \frac{1}{\pi}\iint_{u^2+v^2\leq x^2}e^{-(u^2+v^2)}\,du\,dv = 1-e^{-x^2}.$$ as well as: $$\operatorname{erf}(x)^2 \leq \frac{1}{\pi}\iint_{u^2+v^2\leq 2x^2}e^{-(u^2+v^2)}\,du\,dv = 1-e^{-2x^2}.$$ A tight approximation is given by considering the circle that has the same area of the original square of integration, $[-x,x]^2$:

$$\operatorname{erf}(x)^2 \approx 1-e^{-4x^2/\pi}.$$

One may even try to find "the best" constant $\rho$ such that: $$\operatorname{erf}(x)^2 \approx 1-e^{-\rho^2 x^2}$$ by solving a least-square minimization problem. Numerically, such optimal value is around: $$\rho = 1.1131$$ that is extremely close to $\rho=\frac{\pi}{\sqrt{8}}=1.11072\ldots$ given by your approximation.

• Thanks Jack D'Aurizio. I need to digest your answer first but for now I can say that I know the approximation $\operatorname{erf}(x)^2 \approx 1-e^{-4x^2/\pi}$ but my is better. FYI the least-squares method gives $\rho^{2}=1.239$, but I find $\rho^{2}=\pi^{2}/8=1.2337$ more elegant, if I might say so :-) – petru Mar 2 '15 at 22:19

Just to be part of this interesting discussion, I fully agree that $$F(a)=\int_0^{\infty}\left(\text{erf}(x)^2-(1-e^{-a x^2})\right)^2$$ is minimum for $a\approx 1.23907$ (same value as the one given by Jack D'Aurizio) but, according to $RIES$, this number seems to be much closer to $$a=(1+\pi )^{2/3} \log ^2(2)\approx 1.23907$$ than to $\frac{\pi^2}8\approx 1.23370$ even if this does make very large difference (the maximum error is reduced from $0.006$ to $0.004$ and the value of the integral $F(a)$ changes from $0.00002769$ to $0.00002572$).

If we look for a still better approximation, we could consider $\log\big(1-\text{erf}(x)^2\big)$ (which, for sure, introduces a bias in the problem) and establish a Pade approximant and finally arrive to $$\mathrm{erf}\!\left(x\right)^2\approx1-\exp\Big(-\frac 4 {\pi}\,\frac{1+\alpha x^2}{1+\beta x^2}\,x^2 \Big)$$ where $$\alpha=\frac{10-\pi ^2}{5 (\pi -3) \pi }$$ $$\beta=\frac{120-60 \pi +7 \pi ^2}{15 (\pi -3) \pi }$$ The value of the corresponding error function is $1.1568\times 10^{-7}$ that is to say almost $250$ times smaller than with the initial formulation; the maximum error is $0.00035$.

• Thanks a lot @Claude Leibovici for valuable insight into the approximation. I will clarify though that I'm not interested in the best approximation possible. In fact I need to use it to evaluate some integrals with erf squared, and my approximation seems more convenient (you can check my older posts). And BTW, could you explain what REIS is? – petru Mar 3 '15 at 10:42
• You are very welcome ! You provided fun to the old man ! I enjoy this kind of problems. Sorry for the typo : have fun with mrob.com/pub/ries/index.html – Claude Leibovici Mar 3 '15 at 11:08