I'm having some troubles when I try to solve improper integrals exercises that have singularities on the real axis. I have made a lot of exercises where singularities are inside a semicircle in the upper half side, but I don't know how to solve them when the singularities are on the real axis. I read some books but I think they are not very good explained (at least, I can't understood them).
This is the exercise: $$\int_{-\infty}^{\infty} \frac{\cos(2\pi x)}{x^2-1} dx$$
Using complex variable, I have:
$$f(z) =\frac{e^{i2\pi z}}{z^2-1}$$ so there are 2 singularities: $z_1 = -1$ and $z_2 = 1$
I use a curve $C$ that is holomorphic inside it, because both singularities are out of it. Of course, I can divide $C$ in 6 curves: $C_R$ that is the "roof" of the curve and, using Jordan's Lemma, I can prove that
$$\int_{C_R}^{ } \frac{e^{i2\pi z}}{z^2-1} dx = 0$$
but I don't know what do I have to do now. I saw in some places they said that the Residue Theorem over the semicircle around the singularities was something like: $$-i\pi\sum{}{}Res[f(z), z_k]$$ but I didn't understand why.
I hope you can help me, because I don't know what can I do. Thanks!!
Divergent Integral
Note that $$ \frac{\cos(2\pi x)}{x^2-1}=\frac{\cos(2\pi x)}2\left(\frac1{x-1}-\frac1{x+1}\right) $$ The integral diverges at $x=-1$ and $x=1$, but we can compute the Cauchy Principal Value, which involves removing a small interval centered around each singularity.
Cauchy Principal Value
The reason that centering is important is that if the singularity is of the first order, then we have a situation similar to $$ \int_{-1}^{-r}\frac1x\,\mathrm{d}x+\int_r^1\frac1x\,\mathrm{d}x=0 $$ where the effect of the singularity is cancelled around an interval centered on $0$ since $\frac1x$ is an odd function.
An easy way to approach the evaluation of the Cauchy Principal Value is using contour integration. Consider the integral of $\frac1z$ along the contour $\color{#0000FF}{[-1,-r]}\cup\color{#C000FF}{re^{i[\pi,0]}}\cup\color{#0000FF}{[r,1]}$:
$$
\begin{align}
&\int_{-1}^{-r}\frac1z\,\mathrm{d}z+\int_{\pi}^0\overbrace{\frac1{re^{i\theta}}}^{1/z}\,\overbrace{\vphantom{\frac1z}ire^{i\theta}\mathrm{d}\theta}^{\mathrm{d}z}+\int_r^1\frac1z\,\mathrm{d}z\\
&=\log(r)+\int_\pi^0i\,\mathrm{d}\theta-\log(r)\\
&=-\pi i
\end{align}
$$
which is $-\pi i$ times the residue of $\frac1z$ at $0$ since the contour takes $\frac12$ turn clockwise around $0$.
Thus, we can compute the Cauchy Principal Value by computing a contour integral and subtracting the contributions of semicircles around the singularities, which will be $\pi i$ times the residues of those singularities.
There are at least two ways to evaluate the Cauchy Principal Value for this problem.
Contour Integration
Using the counter-clockwise contour, which contains no singularities, $$ \small\color{#00A000}{\gamma}=\color{#0000FF}{[-R,-1-r]}\cup\overbrace{\color{#C000FF}{re^{i[\pi,0]}-1}}^{\begin{array}{c}\text{$\frac12$ turn clockwise}\\\text{about $-1$}\end{array}}\cup\color{#0000FF}{[-1+r,1-r]}\cup\overbrace{\color{#C000FF}{re^{i[\pi,0]}+1}}^{\begin{array}{c}\text{$\frac12$ turn clockwise}\\\text{about $+1$}\end{array}}\cup\color{#0000FF}{[1+r,R]}\cup\overbrace{\color{#C00000}{Re^{i[0,\pi]}}}^{\text{vanishes}} $$
as $R\to\infty$ and $r\to0$, we get that $$ \begin{align} \small\mathrm{PV}\int_{-\infty}^\infty\frac{\cos(2\pi x)}{x^2-1}\,\mathrm{d}x &\,\small=\mathrm{Re}\!\left(\color{#0000FF}{\int_{-R}^{-1-r}\frac{e^{2\pi ix}}{x^2-1}\,\mathrm{d}x} +\color{#0000FF}{\int_{-1+r}^{1-r}\frac{e^{2\pi ix}}{x^2-1}\,\mathrm{d}x} +\color{#0000FF}{\int_{1+r}^R\frac{e^{2\pi ix}}{x^2-1}\,\mathrm{d}x}\right)\\ &\small=\mathrm{Re}\!\left(\color{#00A000}{\int_\gamma\frac{e^{2\pi iz}}{z^2-1}\,\mathrm{d}z} +\color{#C000FF}{\pi i\operatorname*{Res}_{z=-1}\left(\frac{e^{2\pi iz}}{z^2-1}\right)} +\color{#C000FF}{\pi i\operatorname*{Res}_{z=1}\left(\frac{e^{2\pi iz}}{z^2-1}\right)}\right)\\ &\small=\mathrm{Re}\!\left(\color{#00A000}{0}\,-\,\color{#C000FF}{\frac{\pi i}4}\,+\,\color{#C000FF}{\frac{\pi i}4}\right)\\[4pt] &\small=0 \end{align} $$
Exploitation of Periodicity $$ \begin{align} \mathrm{PV}\int_{-\infty}^\infty\frac{\cos(2\pi x)}{x^2-1}\,\mathrm{d}x &=\frac12\mathrm{PV}\int_{-\infty}^\infty\frac{\cos(2\pi x)}{x-1}\,\mathrm{d}x -\frac12\mathrm{PV}\int_{-\infty}^\infty\frac{\cos(2\pi x)}{x+1}\,\mathrm{d}x\\ &=\frac12\mathrm{PV}\int_{-\infty}^\infty\frac{\cos(2\pi x)}x\,\mathrm{d}x -\frac12\mathrm{PV}\int_{-\infty}^\infty\frac{\cos(2\pi x)}x\,\mathrm{d}x\\[6pt] &=0 \end{align} $$