Different solution for same contour integral $\int_{0}^{\infty}\frac{\cos(x)}{1+x^2}dx$ 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.
 A: 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$.
A: Since $\sin$ is an odd function, $\int_{-\infty}^\infty\frac{\sin x}{1+x^2}\,\mathrm dx=0$ and therefore\begin{align}\int_{-\infty}^\infty\frac{e^{ix}}{1+x^2}\,\mathrm dx&=\int_{-\infty}^\infty\frac{\cos(x)+\sin(x)i}{1+x^2}\,\mathrm dx\\&=\int_{-\infty}^\infty\frac{\cos(x)}{1+x^2}\,\mathrm dx.\end{align}
A: Unfortunately your choice of function and curve don't work and is why proof of contours vanishing or not vanishing are important (I wish physicists would take note here).
Using the residue theorem and equating it to your integral relies on the integral along the circular arc vanishing. But at the top of the arc 
$$\frac{e^{iz}+ e^{-iz}}{1+z^2} \to \frac{e^{-y}+e^y}{1-y^2} \not\to 0$$ because it is exponentially growing, not decaying, as you take the radius of the arc to be larger and larger. This is in fact true for all points on the arc in the upper half plane, so this is not a problem that can be principal valued away by ignoring the imaginary axis.
