TITLE: Computing $\int_{-\infty}^{\infty} \frac{\cos x}{x^{2} + a^{2}}dx$ using residue calculus
QUESTION [35 upvotes]: I need to find $\displaystyle\int_{-\infty}^{\infty} \frac{\cos x}{x^{2} + a^{2}}\ dx$ where $a > 0$. To do this, I set $f(z) = \displaystyle\frac{\cos z}{z^{2} + a^{2}}$ and integrate along the semi-circle of radius $R$. For the residue at $ia$ I get $\displaystyle\frac{\cos(ia)}{2ia}$. Then letting $R \rightarrow \infty$, the integral over the arc is zero, so I get $\displaystyle\int_{-\infty}^{\infty} \frac{\cos x}{x^{2} + a^{2}}\ dx = 2 \pi i \frac{\cos(ia)}{2ia} = \frac{\pi \cos(ia)}{a}$. But this is supposed to be $\displaystyle\frac{\pi e^{-a}}{a}$, so I am doing something wrong.
In a similar problem, I have to evaluate $\displaystyle\int_{-\infty}^{\infty} \frac{x \sin x}{x^{2} + a^{2}}\ dx$ and get $\pi i \sin(ia)$ whereas this is supposed to be $\pi e^{-a}$. I think I am getting some detail wrong in both cases. Can anyone enlighten me?

REPLY [2 votes]: Following method makes no use of contour integration and Leibniz integral rule, $\mathcal{P}\{\}$ is Cauchy principal value.
Assume $a>0$,
$\int_{-\infty}^\infty\frac{\cos(x)}{x^2+a^2}\text{d}x=\frac{1}{2a}\Re\Bigg\{\int_{-\infty}^\infty\left(\frac{e^{xi}}{a+xi}+\frac{e^{xi}}{a-xi}\right)\text{d}x\Bigg\}$
$$\operatorname{Ei}(z):=-\mathcal{P}\Bigg\{\int_1^\infty\frac{e^{zt}}{t}\text{d}t\Bigg\}$$
\begin{align*}\operatorname{Ei}(z)-\operatorname{Ei}(\overline{z})=-2i\mathcal{P}\Bigg\{\int_1^{\infty}\frac{e^{\Re(z)t}\sin(\Im(z)t)}{t} \text{d}t\Bigg\}\\=-2i\mathcal{P}\Bigg\{\int_{\Im(z)}^\infty\frac{e^{\frac{\Re(z)}{\Im(z)}t}\sin(t)}{t}\text{d}t\Bigg\}\end{align*}
Let $z\mapsto \overline{z}$,
$$\operatorname{Ei}(z)-\operatorname{Ei}(\overline{z})=2i\mathcal{P}\Bigg\{\int_{-\Im(z)}^\infty\frac{e^{-\frac{\Re(z)}{\Im(z)}t}\sin(t)}{t}\text{d}t\Bigg\}$$
We have for $\Re(z)>0$,
$$\lim_{\Im(z)\to\infty}\operatorname{Ei}(z)-\operatorname{Ei}(\overline{z})=2\pi i$$
Clearly for $\Re(z)<0$,
$$\lim_{\Im(z)\to\infty}\operatorname{Ei}(z)-\operatorname{Ei}(\overline{z})=0$$
Using above limits and the fact that $\operatorname{Ei}'(z)=\frac{e^z}{z}$,
\begin{align*}\int_{-\infty}^\infty\frac{e^{xi}}{a+xi}\text{d}x=-ie^{-a}\int_{a-\infty i}^{a+\infty i}\frac{e^t }{t} \text{d}t=-ie^{-a}\lim_{z\to\infty}\left(\operatorname{Ei}(a+zi)-\operatorname{Ei}(a-zi)\right)\\=2\pi e^{-a}\end{align*}
\begin{align*}\int_{-\infty}^\infty\frac{e^{xi}}{a-xi}\text{d}x=ie^{a}\int_{-a-\infty i}^{-a+\infty i}\frac{e^{t}}{t}\text{d}t=ie^a\lim_{z\to\infty}\left(\operatorname{Ei}(-a+zi)-\operatorname{Ei}(-a-zi)\right)\\=0\end{align*}
$$\implies\int_{-\infty}^\infty\frac{\cos(x)}{x^2+a^2}\text{d}x=\frac{\pi}{ae^a}$$