I would like to evaluate the following integral. I suspect it just doesn't have an analytic form but thought I'd check to see if there's anything I'm missing,

$\int_{-\infty}^{\infty} \mathcal{N}(z;\mu,\sigma) \int_{z-a}^{z+a} \mathcal{N}(x;\mu,\sigma) \mathrm{d}x \mathrm{d}z.$

The reason for doing so is to determine $Pr(|x-z| < a)$ where (both independently drawn) $x\sim \mathcal{N}(\mu,\sigma)$ and $z\sim \mathcal{N}(\mu,\sigma)$.

I can determine the inner integral easy enough,

Integrate[PDF[NormalDistribution[mu, sigma], x], {x, z - a, z + a}]

which yields,

1/2 (Erf[(a + z - mu)/(Sqrt[2] sigma)] + Erf[(a - z + mu)/(Sqrt[2] sigma)])

Attempting to do the full integral using this intermediate expression results in returning unevaluated, however,

Integrate[1/2 (Erf[(a + z - mu)/(Sqrt[2] sigma)] + Erf[(a - z + mu)/(Sqrt[2] sigma)])
          PDF[NormalDistribution[mu, sigma], z], {z, -\[Infinity], \[Infinity]}]

Anyone got any idea on tricks to perform this integral?

Failing that, does anyone have any ideas for how to approximate it?


1 Answer 1


Yes, I'm being stupid (no shock there!). There is a work around since things are Gaussian. If $z\sim \mathcal{N}(\mu, \sigma)$ and $x\sim \mathcal{N}(\mu, \sigma)$, then $x-z \sim \mathcal{N}(0, \sqrt{2} \sigma)$. Then the result follows easily,

$Pr(|x-z|<a) = \text{Erf}(a/(2 \sigma))$.

  • 3
    $\begingroup$ Using Mathematica: dist = TransformedDistribution[x - z, { x \[Distributed] NormalDistribution[\[Mu], \[Sigma]], z \[Distributed] NormalDistribution[\[Mu], \[Sigma]]}] // Simplify[#, DistributionParameterAssumptions[ NormalDistribution[\[Mu], \[Sigma]]]] &; Probability[Abs[y] < a, y \[Distributed] dist] $\endgroup$
    – Bob Hanlon
    Jul 2, 2019 at 18:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.