Integration along real axis with singularities I'm trying to calculate Green function of wave equation
$\begin{align}
\bigg(\nabla^2 - \frac{\partial ^2}{\partial t^2}\bigg)G(\textbf{x},t;\textbf{x'},t')=\delta^3(\textbf{x-x'})\delta(t-t')
\end{align}$
We can earn this Green function by conducting following integration
$\begin{align}
G(r,t) = -\int\frac{d\omega d^3k}{(2\pi)^4} \frac{e^{i(\textbf{k}\cdot \textbf{r}-\omega t)}}{k^2 - \omega ^2}
\end{align}$
Moving into spherical coordinate gives
$\begin{align}
G(r,t)=\frac{1}{4\pi^3}\int^\infty_0dk \, k^2\frac{\sin{kr}}{kr}\int^\infty_{-\infty} d\omega\frac{e^{-i\omega t}}{(\omega -k)(\omega +k)} 
\end{align}$
Problem is to calculating second integration.
According to Complex analysis, we can conduct contour integral to earn above equation.
Since the integrand has singularity on $\omega = \pm k$, so we should concern Cauchy Principal Value.

When t<0, taking contour Upper Half Circle enable us to use Jordan's lemma so we can eliminate contribution from large circle.
$\begin{align}
\oint dz\frac{e^{-iz t}}{(z -k)(z +k)} = PV \int^\infty_{-\infty} d\omega\frac{e^{-i\omega t}}{(\omega -k)(\omega +k)} + \int^0_\pi d\theta i \delta e^{i\theta}\bigg[\frac{\frac{e^{-ikt}}{2k}}{\delta e^{i\theta}} + O(\delta^2)\bigg]
+ \int^0_\pi d\theta' i \delta' e^{i\theta'}\bigg[\frac{-\frac{e^{ikt}}{2k}}{\delta' e^{i\theta'}} + O(\delta'^2)\bigg] = 0 \end{align}$ Since there's no pole inside the contour.
Then the contribution from small circles gives
$\begin{align}
PV\int^\infty_{-\infty} d\omega\frac{e^{-i\omega t}}{(\omega -k)(\omega +k)} = i\pi \bigg(\frac{e^{-ikt}}{2k} - \frac{e^{ikt}}{2k} \bigg) 
\end{align}$
This is what i got from calculating Green function when t<0.
However the lecture notes that i'm referring says

Let’s first look at the case with t < 0. Here, $e^{−i\omega t} \rightarrow 0$ when$ \omega \rightarrow + i \infty $ . This means that, for t<0, we can close the contour C in the upper-half plane as shown in the figure and the extra semi-circle doesn’t give rise to any further contribution. But there are no poles in the upper-half plane. This means that, by the Cauchy residue theorem, $G_{ret}(r, t) = 0$ when t < 0.

Now i get what the Author means that contour integral itself becomes zero since there's no pole inside, but we are now dealing integral along the real axis while there's singularity among it.
I have no idea why the integral when t<0 becomes zero at all.
And also, when t>0,

In contrast, when t > 0 we have $e^{−i \omega t} \rightarrow 0$ when
$\omega \rightarrow −i \infty$, which means that we get to close the contour in the lower-half plane. Now we do pick up contributions to the integral from the two poles at $\omega = \pm k$. This time the Cauchy residue theorem gives


$\begin{align}
\oint d \omega \frac{e^{-i \omega t}}{(\omega -k )(\omega +k)} = -2\pi i \bigg[\frac{e^{-ikt}}{2k} - \frac{e^{ikt}}{2k} \bigg]
\end{align}$

And i'm keep not understanding why the Author bothers with the Residue theorem, while i guess we have to consider Principal value.
What do i have to consider to make integral when t<0 to become zero?
Maybe i should consider real part of the integrand only so i can eliminate actual result of principal value, like
$\begin{align}
\int^\infty_{-\infty} d\omega\frac{e^{-i\omega t}}{(\omega -k)(\omega +k)} \rightarrow_{Real \,part} 
\int^\infty_{-\infty} d\omega\frac{\cos{\omega t}}{(\omega -k)(\omega +k)} = 0
\end{align}$
The lecture note i'm referring is David Tong's Electrodynamics, http://www.damtp.cam.ac.uk/user/tong/em.html page 140
 A: 
Since the integrand has singularity on $\omega=\pm $, so we should concern Cauchy Principal Value.

This, I believe, is where your 'mistake' lies. The Cauchy Principal Value is one way to deal with an integral that is divergent at a set of points, but it is not the way to deal with such an integral.
In this case, the Green function as-is is ill-defined because of the singular points, and we cannot perform the inverse Fourier transform that we want. If we want to make progress, we have to try something else.
One thing we can try is to look at a different integral,
$$\int_{-\infty}^\infty \frac{e^{-i \omega t}}{(\omega + i\eta - k)(\omega+i\eta + k)} \text{d} t,$$
where $\eta$ is a small positive constant. Now the poles have been shifted away from the real axis, and thus this is an integral we can actually solve using the residue theorem. In addition, in the limit $\eta \rightarrow 0$ this function superficially seems to actually approach the integral that we want! If you calculate this integral and then take the limit $\eta \rightarrow 0$ only at the end of the calculation, you will find that you obtain the retarded Green function just as in the lecture note that you link to. If you instead took the limit from below, i.e. let $\eta$ be a negative constant, you would obtain the advanced Green function.
It may seem unintuitive to have to pull these sorts of 'tricks'. To gain some intuitive understanding of the issue let us look at it from a slightly different perspective. The following is by no means meant to be rigorous, but rather an attempt at an intuitive explanation.
The Green function $G(\omega)$ basically tells you what the response of the system is when the 'driving term' is of the form $e^{i \omega t}$.
Let us consider a harmonic oscillator described by the equation
$$ \ddot{x} + \omega_0^2 x = F,$$
where $F$ is a driving force. If $F$ is a harmonic function, $F = F_0 e^{i \omega t}$ then the response will be
$$x(t) = \frac{F_0 e^{i\omega t}}{\omega_0^2 - \omega^2},$$
however this solution is clearly not valid if $\omega = \omega_0$. In that case, we will instead find that $x$ grows without bound as time increases. Consider how this changes if we add a little bit of friction to the system, though. Then the equation of motion becomes
$$\ddot{x} + \eta \dot{x} + \omega_0^2 x = F,$$
and the response to a harmonic driving term $F = F_0 e^{i \omega t}$ becomes
$$x(t) = \frac{F_0 e^{i\omega t}}{\omega_0^2 - \omega^2 + i\omega\eta},$$
which is well-defined for all real $\omega$ and, if we take the limit $\eta \rightarrow 0$, gives the same answer as in the friction-less sytem, except when the frequency of the driving term is at the resonance frequency $\omega_0$.
The problem with the friction-less harmonic oscillator is not really that it is friction-less, but rather the driving term; it is of infinite duration, extending both into the infinite past and the infinite future. Such a driving term is not very physical at all! If you restrict yourself to physical driving terms, e.g. terms that have a finite duration and never diverge, then you wouldn't encounter problems like these. But for such a physical driving term, observed over a finite duration of time, there would not be a difference between the response of the friction-less system, and the system with friction in the limit $\eta \rightarrow 0$. Therefore, we can allow ourselves to replace the "pure", friction-less system that we wanted to describe, by a different system that has a negligible but in principle non-zero friction, if we at the same time restrict ourselves to working only with 'physical' driving terms.
The introduction of an $\eta$ when calculating a retarded (or advanced) Green function can be understood intuitively in a similar manner.
A: *

*The Green function $G(\mathbf{r},t)$ is not uniquely defined by the equation  $$(\Delta - \partial^2/ \partial t^2)G(\mathbf{r},t) = \delta^{(3)}(\mathbf{r}) \delta(t).$$ Suppose you have found a solution $G(\mathbf{r},t)$,  you may always add an arbitrary solution $H(\mathbf{r},t)$ of the homogeneous equation $(\Delta - \partial^2 /\partial t^2) H(\mathbf{r},t) =0$ such that $G^\prime (\mathbf{r},t) = G(\mathbf{r},t) +H(\mathbf{r},t)$ is also a Green function. Depending on the (physical) problem you want to solve, you may single out a specific Green function by imposing certain boundary conditions. Well known examples in the case of your problem are the retarded Green function $G_{\rm ret}(\mathbf{r}, t)$ with $G_{\rm ret}(\mathbf{r},t) =0$ for $t<0$, the advanced Green function $G_{\rm adv} (\mathbf{r},t)$ with $G_{\rm adv} (\mathbf{r}, t) =0$ for $t>0$ or $G_{\rm F}(\mathbf{r},t)$ (in QFT), where Feynman boundary conditions are imposed.


*This ambiguity in the definition of the Green function is reflected by the fact that the integral $$ D(k,t)=\int\limits_{-\infty}^\infty \! d\omega \, \frac{e^{-i \omega t}}{(\omega -k) (\omega +k)} $$ is undefined because of the presence of the poles at $\omega = \pm k$ on the real axis. By deforming the path of integration from the real axis to a slightly different path avoiding the poles, makes (a) the integral well defined and (b) singles out a specific boundary condition imposed on the Green function. (Alternatively, the poles can be shifted by giving them a small imaginary part, leaving the path of integration still on the real axis.)


*The retarded Green function is obtained by circumventing the poles by the two small semicircles around $\pm k$ in the upper half of the complex $\omega$-plane shown in your figure. Denoting this deformation of the real axis by $C_{\rm ret}$, the integral $$D_{\rm ret}(k,t) =\int\limits_{C_{\rm ret}} \! d\omega \, \frac{e^{-i \omega t}}{(\omega-k) (\omega+k)}$$ can now be computed by using the residue theorem by choosing a suitable closed contour, containing $C_{\rm ret}$. For $t<0$ we close the path by a large semicircle $S_+$ defined by $\omega (\varphi) = R e^{i\varphi}$ with $0 \le \varphi \le \pi$. In the limit $R\to \infty$, the contribution from $$ \int\limits_{S_+} \! d\omega \, \frac{e^{-i \omega t}}{(\omega-k)(\omega+k)} = \lim\limits_{R \to \infty} i R \int\limits _0^\pi d\varphi \, e^ {i \varphi} \frac{e^{-i t R \cos \varphi} e^{t R \sin \varphi}}{(R e^{i \varphi} -k)(Re^{i\varphi} +k)} =0$$ vanishes because of the dominant damping factor $e^{t R \sin \varphi}$ for $t \sin \varphi < 0$. Thus, for $t<0$, we can write $D_{\rm ret} (k,t)$ as an integral over the closed path $C_{\rm ret} + S_+$. As the poles at $\omega = \pm k$ are now outside the contour, we obtain $D_{\rm ret}(k,t)=0$ in this case. For $t>0$, we have to close the path by a large semicircle $S_-$ in the lower half plane. The two poles are now inside the contour and the residue theorem gives $D_{\rm ret }(k,t)= -\frac{2 \pi \sin k t}{k}$. Combining both results, we finally obtain $$D_{\rm ret}(k,t) = - 2 \pi \theta(t) \frac{\sin kt}{k},$$ where $\theta(t)$ denotes the Heaviside step function.


*The source of your confusion seems to be your attempt to establish  a connection to the principal value of the integral. Although this can, in principle, be done, it is not necessary to find the (retarded) Green function.


*It is instructive to find the necessary deformations of the path for finding the advanced Green function and the Feynman propagator.


*A minor point: The upper limit of the first integral in your third equation should be $\infty$.
