This question might be silly but I am quite puzzled by this problem. In this exercise I am required to solve the following integral
$$\int_{0}^{\infty}\frac{\cos(x)}{1+x^2}dx$$
which I will call $A$ from now on. Since $f(x)= f(-x)$ I conclude $$A = \frac{1}{2} \int_{-\infty}^{\infty}\frac{\cos(x)}{1+x^2}dx.$$ Now I can switch to the complex variable $z$ and rewrite $\cos(z)$ as $\frac{e^{iz}+e^{-iz}}{2}$ and obtain
$$\frac{1}{4}\int_{\gamma}\frac{e^{iz}+e^{-iz}}{1+z^2}dz$$
where $\gamma$ is the upper semicircle with radius $r$. Then I can evaluate the residue for $z=i$ (the radius is eventually going to tend to infinity) and via Jordan's Lemma I get
$$A = \frac{\pi}{4}(e^{-1} + e).$$
Now, my professor solved this integral in a very similar manner but he passed from
$$A = \frac{1}{2} \int_{-\infty}^{\infty}\frac{\cos(x)}{1+x^2}dx = \frac{1}{2} \int_{-\infty}^{\infty}\frac{e^{ix}}{1+x^2}dx $$
I tried to reconstruct the steps that bring me from one form to the other but I am not capable of doing so. What am I missing here?
Thanks in advance to everyone who is going to participate.
Note that $e^{ix}=\cos(x)+i\sin(x)$ and $$\int_{-\infty}^{\infty}\frac{\sin(x)}{1+x^2}dx=0$$ because the integrand is an odd integrable function. Hence $$\int_{-\infty}^{\infty}\frac{e^{ix}}{1+x^2}dx=\int_{-\infty}^{\infty}\frac{\cos(x)}{1+x^2}dx +i\int_{-\infty}^{\infty}\frac{\sin(x)}{1+x^2}dx= \int_{-\infty}^{\infty}\frac{\cos(x)}{1+x^2}dx+0=2A.$$ Now, by using the residue theorem, we find $$A=\pi i \operatorname{Res} \left(\frac{e^{iz}}{z^2+1};i\right) = \pi i \frac{e^{-1}}{2i} = \frac{\pi}{2e}.$$
P.S. As regards your approach, note that the integral of $\frac{e^{iz}+e^{-iz}}{1+z^2}$ does not go to zero along the upper semicircle $\Gamma_R$ with $R>1$. As a bonus question, verify that that integral is equal to $2\pi-\pi e -\pi/e$.