Taking the limit of an integral using residues, why is this wrong? I have the integral $\lim\limits_{R\to\infty}\int_{-R}^{R} \frac{\cos(x)}{x^2+a^2} dx$ where $a$ is a positive real number. The strategy was to evaluate the limit of the integral on the boundary of a half-disk of radius $R$ and then subtract the limit of the integral on the half-circle. 
What I am confused with, is that when computing the integral on the boundary of the half-disk, I used the residue theorem to compute the integral thinking that $\cos(x)$ is meromorphic everywhere but infinity, and our domain is a finite (open) disk, and then took the limit.  However, the reference I am using, says that $\cos(x)$ has an essential singularity at infinity and thus uses a different strategy (computing the limit for $\frac{\exp(ix)}{x^2+a^2}$ and then taking the real part). I don't understand why I cannot use the residue theorem, and then take the limit in this case, because our domain (although gets unbounded when taking a limit) is a finite disk on which cosine is meromorphic.
Can someone please explain where I am going wrong in my thinking? 
Thank you very much.
 A: It's very hard to "control" or check how the module of the complex sine or cosine are going to behave. This is one reason why we usually use $\,e^{ix}\,$  instead. So define
$$f(z):=\frac{e^{iz}}{z^2+a^2}\;,\;\;C_R:=[-R,R]\cup\,\left(\gamma_R:=\{z\in\Bbb C\;;\;z=Re^{it}\;,\;0<t<\pi\}\,\right)\;,\;\;0<a<R$$
The only singularity of the above function within the domain enclosed by the above path is at the simple pole
$$z=ai\;\implies\;\;\text{Res}_{z=ai}(f)=\lim_{z\to ai} (z-ai)f(z)\stackrel{\text{l'Hospital}}=\frac{e^{-a}}{2ai}$$
So by CRT we get
$$\frac{\pi e^{-a}}a=\oint\limits_{C_R}f(z)\,dz=\int\limits_{-R}^R\frac{e^{ix}}{x^2+a^2}dz+\int\limits_{\gamma_R}f(z)\,dz$$
But either using Jordan's Lemma or directly by the Estimmation Lemma, we get
$$\left|\,\int\limits_{\gamma_R}f(z)\,dz\,\right|\le \frac{e^{-\text{Im}\,{z}}}{R^2-a^2}\pi R\xrightarrow[R\to\infty]{}0$$
So we finally get
$$\lim_{R\to\infty}\int\limits_{C_R}f(z)\,dz=\int\limits_{-\infty}^\infty\frac{\cos x+i\sin x}{x^2+a^2}dx=\frac{\pi}{ae^a}$$
and comparing real parts we get our integral.
A: Watching the proof of this fact on my note seems that the point it's you need to control the module of your function as $|z|$ goes to infinity. Now the point is that the cosine in the complex plain behaves slightly different regarding the module as its real counterpart. In fact the module of the cosine can assume arbitrarily great values:
$$\cos(z) = \frac{e^{iz}+e^{-iz}}{2}$$
using modules and basical disequalities we obtain $$ \frac{1}{2} | |e^{ix}e^{-y}|-|e^{-ix}e^y|| \leq \frac{1}{2} | e^{ix}e^{-y} -(-e^{-ix}e^{y})|$$
and the former member can be great as you want (note the double module)
So you need to do this "trick" to conclude the proof and therefore use the result. Note,that you have to calculate the residue of $f(z)e^{iz}$ with this method.
