TITLE: Integral of product of two normal distribution densities
QUESTION [8 upvotes]: 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?

REPLY [5 votes]: 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}$$