Error function and the normal distribution (source code)

= Error function and the normal distribution
{title2=$\Phi(z)=\tfrac12[1+\operatorname{erf}(z/\sqrt2)]$}

For a <standard normal random variable> $Z$, its <standard normal distribution function> is
$$
\Phi(z)=\frac{1}{\sqrt{2\pi}}\int_{-\infty}^{z}e^{-u^2/2}\,du
=\frac12\left[1+\operatorname{erf}\!\left(\frac{z}{\sqrt2}\right)\right].
$$
The <change of variables> $t=u/\sqrt2$ and the <symmetric distribution> of the <standard normal random variable> give the second expression. For $X\sim N(\mu,\sigma^2)$ with $\sigma>0$, <standardization of a normal random variable> then gives
$$
\mathbb P(X\le x)=\frac12\left[1+\operatorname{erf}\!\left(\frac{x-\mu}{\sigma\sqrt2}\right)\right],\qquad
\mathbb P(|X-\mu|\le a\sigma)=\operatorname{erf}\!\left(\frac{a}{\sqrt2}\right),\quad a\ge0.
$$
In particular, the intervals within one, two, and three <standard deviations> have calculated <probabilities> about $0.682689$, $0.954500$, and $0.997300$. These values depend on a <normal distribution>; they are not universal coverage guarantees for an arbitrary <random variable>. This is the direct connection between a <Gaussian function> area and the familiar central intervals.

For a small upper-tail <probability>, use the <complementary error function> directly:
$$
\boxed{\mathbb P(Z>z)=\frac12\operatorname{erfc}\!\left(\frac{z}{\sqrt2}\right).}
$$
Computing this as $1-\Phi(z)$ instead can lose the tail to <catastrophic cancellation>. The <Gaussian tail bound> gives another useful estimate without requiring an exact <error function> value.