On one representation of Green's function

The Green's function for heat equation on finite interval is well known (with Dirichlet conditions): $$G(x,x', t) = \frac{2}{l}\sum\limits_{n=1}^{\infty} \exp\left(-\frac{\pi^2n^2}{l^2}at\right)\sin\left(\frac{x\pi n}{l}\right) \sin\left(\frac{x'\pi n}{l}\right)$$

But recently I have encountered another representation. It is claimed that we can use method of images to obtain following representation of same Greens function: $$G(x,x',t) = \frac{1}{2\sqrt{\pi a t}}\sum\limits_{k=-\infty}^{+\infty}(-1)^k \exp\left(-\frac{(x-x_k)^2}{4\pi t}\right)$$ where $x_k$ -- is places of images (or, as it is sometimes said, ''fake sources'')

It is not obvious at all... Can anyone explain or advise some materials where I could find explanation with proof?

-

You have the Green function corresponding to the whole real line, we write $G(x,y,t)$ for this function and we denote the initial data as $f$. Assume now that the heat equation is posed on the interval (-L,L) with homogeneous Dirichlet BC. Then, you can't use the gaussian because the BC are not fulfilled.
The idea now is, for each time $t$ (let's say that the time is a parameter), to substract something that ensures that the BC are fulfilled. If you use $G$ you have $$G(-L,y,t)\approx\exp\left(\frac{(-L-y)^2}{4t}\right), y\in(-L,L)$$ Notice that you can use $$G_1(x,y,t)\approx\exp\left(\frac{(x+2L+y)^2}{4t}\right), y\in(-L,L),$$ and you have $$G(-L,y,t)-G_1(-L,y,t)=\exp\left(\frac{(-L-y)^2}{4t}\right)-\exp\left(\frac{(-L+2L+y)^2}{4t}\right)=0.$$ This is the term corresponding to one of the "images", i.e. a symmetric $\delta(x)$ in the appropriate point, in this case $2L$. The point is that you need infinitely many of these terms. For instance, $G_1$ influences the value at the other boundary $x=L$, thus, when we deal with the BC at $x=L$ we need a function $G_2$ which depends on $G_1$ but then an extra $G_3$ should be taken into account... Finally you obtain infinitely many $G_i$.