# Integral of product of two normal distribution densities

I want to compute the integral:

$\displaystyle \int^{\infty} _{-\infty} \frac{1}{\sqrt{2\pi}} e^{-\frac{(y-x)^2}{2}} \frac{1}{\sqrt{2\pi}ab} e^{-\frac{x^2}{2(ab)^2}} dx$

Maybe we can use that for a normal distribution with mean $\mu$ and variance $\sigma^2$ we have

$\displaystyle \int^{\infty} _{-\infty} \frac{1}{\sqrt{2\pi}\sigma} e^{-\frac{(x-\mu)^2}{2 \sigma^2}} dx = 1$

In an effort to write the integral in this form, I tried to take the exponents together. This gives:

$\displaystyle -\frac{(y-x)^2}{2} - \frac{x^2}{2(ab)^2} = \frac{-[(ab)^2 (y-x)^2 + x^2]}{2(ab)^2} = \frac{-[(ab)^2 (y^2 -2xy +x^2) + x^2]}{2(ab)^2}$

But this leads to nowhere. Any suggestions?

• Hint: considerate variables $X~N(0,ab)$ and $Y~N(X,1)$ – Martín Vacas Vignolo Mar 30 '16 at 14:33

## 3 Answers

Actually, you're on the right track. Just keep on going with \begin{align}(ab)^2(y^2-2xy+x^2)+x^2 & =(a^2b^2+1)x^2-2a^2b^2yx+a^2b^2y^2 \\ & =(a^2b^2+1)\left[x^2-2\frac{a^2b^2y}{a^2b^2+1}x\right]+a^2b^2y^2 \\ & =(a^2b^2+1)\left[\left(x-\frac{a^2b^2y}{a^2b^2+1}\right)^2-\frac{a^4b^4y^2}{(a^2b^2+1)^2}\right]+a^2b^2y^2 \\ & =(a^2b^2+1)\left(x-\frac{a^2b^2y}{a^2b^2+1}\right)^2+\left[a^2b^2-\frac{a^4b^4}{a^2b^2+1}\right]y^2 \\ & =(a^2b^2+1)\left(x-\frac{a^2b^2y}{a^2b^2+1}\right)^2+\left(\frac{a^2b^2}{a^2b^2+1}\right)y^2 \\ \end{align} Then we know that $$\int_{-\infty}^{\infty}e^{\frac{-(a^2b^2+1)\left(x-\frac{a^2b^2y}{a^2b^2+1}\right)^2}{2a^2b^2}}dx=\int_{-\infty}^{\infty}e^{-\frac{(x-\mu)^2}{2\sigma^2}}dx=\sqrt{2\pi}\sigma$$ Where $$\mu=\frac{a^2b^2y}{a^2b^2+1}$$ $$\sigma=\frac{ab}{\sqrt{a^2b^2+1}}$$ So now you have \begin{align}\int_{-\infty}^{\infty}\frac1{\sqrt{2\pi}}e^{-\frac{(y-x)^2}{2}}\frac1{\sqrt{2\pi}ab}e^{-\frac{x^2}{2(ab)^2}}dx & =\frac1{\sqrt{2\pi}}\frac1{\sqrt{2\pi}ab}\frac{\sqrt{2\pi}ab}{\sqrt{a^2b^2+1}}e^{-\frac{y^2}{2\left(\sqrt{a^2b^2+1}\right)^2}} \\ & = \frac1{\sqrt{2\pi}\sqrt{a^2b^2+1}}e^{-\frac{y^2}{2\left(\sqrt{a^2b^2+1}\right)^2}} \end{align} So the means add, $0+0=0$, as do the variances, $1+a^2b^2=\left(\sqrt{a^2b^2+1}\right)^2$, just like they are supposed to.

• Exactly what I would have done. Completing the square is surprisingly useful. – marty cohen Mar 31 '16 at 3:43
• Thanks. These get a lot more tedious in quantum mechanics where there is also a phase factor of $e^{ikx}$ in there. – user5713492 Mar 31 '16 at 3:59
• QM and I have an empty intersection. btw, I think you have a typo in your final variance equality ($a^2+b^2$ instead of $a^2b^2$). – marty cohen Mar 31 '16 at 4:01
• $\text{@marty cohen} \cap QM = \emptyset$ Sorry, just had to practice my MathJax :) Fixed. Thanks. – user5713492 Mar 31 '16 at 4:52
• My MathJax annoys some people because I prefer array to align. I often see editing going on. Doesn't bother me. – marty cohen Mar 31 '16 at 4:55

Here are general formulas for multivariate Gaussian distribution in $$\mathbb{R}^D$$ (derivation): $$\rho_{\mu, \Sigma}(x):= \frac{1}{\sqrt{|2\pi\Sigma|}} e^{-\frac 12 (x-\mu)^T\Sigma^{-1} (x-\mu)}$$

Integral of product of Gaussian distributions with covariance matrix $$\Sigma$$ and $$\Gamma$$, shifted by $$\mu$$ vector:

$$\int_{\mathbb{R}^D} \rho_{\mu, \Sigma}(x)\cdot\rho_{\mathbf{0},\Gamma}(x)\,dx=\frac{\exp\left(-\frac 12 (\mu^T\Sigma^{-1}(\Sigma^{-1}+\Gamma^{-1})^{-1} \Gamma^{-1}\mu) \right)} {\sqrt{(2\pi)^D |\Sigma||\Gamma||\Sigma^{-1}+\Gamma^{-1}|}}$$ For spherically symmetric $$\Sigma=\sigma^2 \mathbf{I}$$, $$\Gamma=\gamma^2 \mathbf{I}$$ shifted by any length $$l$$ vector it becomes: $$\frac{\exp \left(-\frac 12 \frac {l^2}{\sigma^2+\gamma^2} \right)} {\sqrt{2\pi \left(\sigma^{2}+\gamma^{2}\right)}^D}$$

• Can your result be extended to the case where the two Gaussians in the integral are of two different dimensions? Integration, in that case, is taken over the space corresponding to the second Gaussian. – nOp Jun 12 at 22:31
• @nOp, just project the higher dimensional Gaussian to the subspace (center and covariance matrix) and use the above. – Jarek Duda Jun 13 at 5:06

Since the given integral is a convolution an alternative solution could be based on Fouriertransformation.

We know that $$e^{-x^{2}}\overset{\mathcal F}{\longmapsto} \sqrt{\pi}e^{-{\xi}^{2}/4}.$$ where ${\mathcal F}$ is the Fouriertransformation.

It is a basic fact that $$f(x)\overset{\mathcal F}{\longmapsto} F(\xi) \Longrightarrow f(ax)\overset{\mathcal F}{\longmapsto} \dfrac{1}{|a|}F\left(\dfrac{\xi}{a}\right).$$ where $a$ is a non-zero real number. Now the Fourier transformation of the given integral yields that $$\dfrac{1}{\sqrt{2\pi}}\sqrt{2\pi}e^{-2\xi^{2}/4}\dfrac{1}{\sqrt{2\pi}ab}\sqrt{2\pi}abe^{-2(ab)^{2}\xi^{2}/4}= e^{-2(1+(ab)^{2})\xi^{2}/4}.$$ Finally we receive the integral via inverse Fourier transformation $$\dfrac{1}{\sqrt{2\pi}\sqrt{1+a^{2}b^{2}}}e^{-y^{2}/(2(1+a^{2}b^{2}))}.$$