% Error function erf(x) -- LaTeX source for card 4 of the Options Widget % Compile: pdflatex erf.txt (or rename to .tex) \documentclass[11pt]{article} \usepackage{amsmath,amssymb} \usepackage[margin=1in]{geometry} \begin{document} \section*{Error function \ $\operatorname{erf}(x)$} \begin{align*} \operatorname{erf}(x) &= \frac{2}{\sqrt{\pi}} \int_{0}^{x} e^{-t^2}\,dt \\[4pt] \operatorname{erf}(x) &= 2\,N(x\sqrt{2}) - 1 \end{align*} \subsection*{Properties} \begin{itemize} \item $\operatorname{erf}(0) = 0,\quad \operatorname{erf}(-x) = -\operatorname{erf}(x)\ \text{(odd)},\quad \operatorname{erf}(\infty) = 1$ \item $N(x) = \tfrac{1}{2}\left[1 + \operatorname{erf}(x/\sqrt{2})\right]$ \item $\operatorname{erf}(x)$ = probability a normal variable with mean 0 and variance $\tfrac{1}{2}$ lands in $[-x, x]$ \item $\operatorname{erf}(0.5) \approx 0.5205,\quad \operatorname{erf}(1) \approx 0.8427,\quad \operatorname{erf}(2) \approx 0.9953$ \end{itemize} \subsection*{How the widget computes it} \begin{itemize} \item The widget evaluates the complementary function and uses \[ \operatorname{erf}(x) = 1 - \operatorname{erfc}(x) \] \item $\operatorname{erfc}$ by the Numerical Recipes Chebyshev fit, with $z = |x|$ and $t = \dfrac{1}{1 + z/2}$: \begin{align*} P(t) &= -1.26551223 + t\,(1.00002368 + t\,(0.37409196 + t\,(0.09678418 \\ &\qquad + t\,(-0.18628806 + t\,(0.27886807 + t\,(-1.13520398 \\ &\qquad + t\,(1.48851587 + t\,(-0.82215223 + 0.17087277\,t)))))))) \\[4pt] \operatorname{erfc}(z) &\approx t\,\exp\!\left(-z^2 + P(t)\right) \end{align*} with $\operatorname{erfc}(-z) = 2 - \operatorname{erfc}(z)$ and $|\epsilon_{\text{rel}}| < 1.2\times10^{-7}$. \end{itemize} \end{document}