Computing $\int\limits_{-\pi/2}^{\pi/2} \cos(\tan x)\,dx$ 
How to compute $\int\limits_{-\pi/2}^{\pi/2} \cos(\tan x)\,dx$?

I tried the usual Riemann integral method but could not figure out and thought of contour integral and seemed working. But whenever I tried to find the residue at the essential singularity of $f(z)=\cos (\tan z)$ at $\frac{\pm \pi}{2}$, I got stuck there.
 A: HINT:
Let $I$ be the integral given by
$$\begin{align}
\int_{-\pi/2}^{\pi/2}\cos(\tan(x))\,dx&=\int_{-\infty}^\infty \frac{\cos(x)}{1+x^2}\,dx\\\\
&=\text{Re}\left(\int_{-\infty}^\infty \frac{e^{ix}}{x^2+1}\right)\,dx
\end{align}$$
Now, use contour integration by closing the contour in the upper half plane.
SPOILER ALERT:  Scroll over the highlighted area to reveal the solution

Let $J$ be the contour integral of $\frac{e^{iz}}{z^2+1}$ over the closed contour $C$, where $C$ is comprised of $(i)$ the real line from $-R$ to $R$, and $(ii)$ the semicircle in the upper-half plane with radius $R$ and centered at the origin.  Then, $J$ is given by $$\begin{align}J&=\oint_C \frac{e^{iz}}{z^2+1}\,dz\\\\&=\int_{-R}^R \frac{e^{ix}}{x^2+1}\,dx+\int_0^\pi \frac{e^{iRe^{i\phi}}}{R^2e^{i2\phi}+1}\,iRe^{i\phi}\,d\phi\\\\&=2\pi i \text{Res}\left(\frac{e^{iz}}{z^2+1}, z=i\right)\\\\&=2\pi i \frac{e^{-1}}{2i}\\\\&=\frac{\pi}{e}\end{align}$$Taking the limit as $R\to \infty$ and taking the real part shows that $$\int_{-\infty}^\infty \frac{\cos(x)}{x^2+1}\,=\frac{\pi}{e}$$

A: For a non-complex solution: Using the sub $\tan x\mapsto x$ we get the integral $$\int_{-\infty}^{\infty} \frac{\cos x}{1+x^2}$$
Introduce the parameter $$f(\alpha) = \int_{-\infty}^{\infty} \frac{\cos (\alpha x)}{1 + x^2} \, \mathrm{d}x$$
Now differentiate: $$f'(\alpha) = -\int_{-\infty}^{\infty} \frac{x\sin (\alpha x)}{1+x^2} \, \mathrm{d}x$$
And again 
$$\begin{align*}f''(\alpha) &= -\int_{-\infty}^{\infty} \frac{x^2 \cos (\alpha x)}{1+x^2} \, \mathrm{d}x \\ & =-\int_{-\infty}^{\infty} \frac{(x^2+1) \cos (\alpha x) - \cos (\alpha x)}{1+x^2} \, \mathrm{d}x \\ &=  \int_{-\infty}^{\infty}\frac{ \cos (\alpha x)}{1+x^2} \, \mathrm{d}x  - \int_{-\infty}^{\infty} \cos \alpha x \, \mathrm{d}x\\ & = f(\alpha)\end{align*}$$
This gives $f''(\alpha) -f(\alpha) = 0$ and so $$f(\alpha) = ae^{\alpha} + be^{-\alpha}$$
But $f(0) = a+b = \pi$ and $\lim_{\alpha \to \infty} = 0 \Rightarrow a = 0 $ so $$f(\alpha) = \pi e^{-\alpha}$$
Now recover your integral using $f(1) = \pi e^{-1}$.
A: Let $u=\tan x$, then it can be turned to
$$\frac{1}{2}\int_{-\infty}^\infty\frac{e^{iu}}{1+u^2}du+\frac{1}{2}\int_{-\infty}^\infty\frac{e^{-iu}}{1+u^2}du$$
For the first integral, integrate along an upper semicircle in the counter-clockwise direction to give
$$\frac{1}{2}2\pi i \frac{e^{-1}}{2i}$$
For the second integral, integrate along a lower semicircle in the clockwise direction to give
$$\frac{1}{2}(-2\pi i)\frac{e^{-1}}{-2i}$$
Hence the sum is
$$I =\frac{\pi}{e}$$
A: Following the expression obtained by Dr. MV, here's one more way to find the integral.
Let $\mathcal F\{ f(x) \} (t)$ denote the evaluation of the Fourier transform of $f$ at $t$, i.e.
$$\mathcal F \{f(x)\}(t) = \frac{1}{\sqrt{2\pi}} \int_{-\infty}^{\infty} f(x) e^{-itx} dx$$
We have:
$$\int_{-\infty}^{\infty} \frac{e^{ix}}{1+x^2} dx = \sqrt{2 \pi} \mathcal{F} \left\{ \frac1{1+x^2} \right\} (-1)$$
It is easy to find:
$$\mathcal{F} \left\{ e^{-|x|} \right\} (t) = \sqrt{\frac{2}{\pi}} \frac1{1 + t^2}$$
Using the inversion formula on $L^1$, we find:
$$\mathcal{F} \left\{ \frac1{1+x^2} \right\} (t) = \sqrt{\frac{\pi}2} e^{-|t|}$$
Thus, 
$$\int_{-\infty}^{\infty} \frac{e^{ix}}{1+x^2} dx = \pi e^{-1} = \pi/e = \Re \left( \int_{-\infty}^{\infty} \frac{e^{ix}}{1+x^2} dx\right) = \int_{-\infty}^{\infty} \frac{\cos x}{1+x^2} dx$$
