Can I use an upper semi-circle to integrate this function? I'm trying to integrate 
$$\int_{-\infty}^{\infty} \frac{e^{iz}}{e^z + e^{-z}}dz$$
Do I have have to integrate this over a box, or can I use my first guess at a contour and use an upper semi-circle just fine?
On the semi-circle, I have the estimate:
$$\int_{-\infty}^{\infty} \frac{e^{iz}}{e^z + e^{-z}}dz$$
$$\le \pi R \frac{|e^{iz}|}{|e^z + e^{-z}|}$$
$$\le \frac {\pi R} {|e^z + e^{-z}|}$$
$$\le \frac {\pi R} {|e^z|}$$
and I'm not sure how to treat the denominator.  I want to show the last term goes to zero, as we let R go to infinity, so that I can just look at the integral over the straight line on the real axis, from -R to R.
Of course, on the semi-circle, the parametrization is $z=Re^{i\theta}$, with $\theta$ ranging from 0 to $\pi$.
A student solution integrates over a suitably chosen box, but I wouldn't have came up with that myself, so I'm wondering whether I could still make it work with my choice of an upper semi-circle.
Thanks,
 A: How about considering the positively oriented rectangle $Q_R$, where $R>0$, with vertices $-R$, $+R$, $2\pi\text{i}+R$, and $2\pi\text{i}-R$?  You should find that there are two poles $\frac{\pi \text{i}}{2}$ and $\frac{3\pi\text{i}}{2}$ of $f(z):=\frac{\exp(\text{i}z)}{\exp(z)+\exp(-z)}$ enclosed by $Q_R$ for each $R>0$.  If $I$ is the required integral, then taking $R\to\infty$, we have
$$\big(1-\exp(-2\pi)\big)\,I=2\pi\text{i}\left(\text{Res}_{z=\frac{\pi \text{i}}{2}}\big(f(z)\big)+\text{Res}_{z=\frac{3\pi \text{i}}{2}}\big(f(z)\big)\right)\,.$$
The final answer should be
$$I=\frac{\pi\,\big(\exp(-\pi/2)-\exp(-3\pi/2)\big)}{1-\exp(-2\pi)}=\frac{\pi}{\exp(+\pi/2)+\exp(-\pi/2)}=\frac{\pi}{2}\text{sech}\left(\frac{\pi}{2}\right)\,.$$
Why is this box $Q_R$ good, but not a semicircle with radius $R$?  That is because, as $R\to\infty$, the semicircle encloses more and more poles of $f(z)$, making the calculation more difficult.
A: Your estimates are wrong.  $|e^{iz}| = 1$ when $z$ is real, but not on the semicircle.  Moreover, the denominator is not so easy to estimate: for example when $z=iy$ is imaginary, $e^z + e^{-z} = 2 \cos(y)$, and this can be $0$ which you need to avoid.
A: Since $\mathcal{L}(\cos z)=\frac{s}{s^2+1}$,
$$I=\int_{0}^{+\infty}\frac{\cos z}{\cosh z}\,dz=2\sum_{k\geq 0}\frac{(2k+1)(-1)^k}{1+(2k+1)^2}=\sum_{k\geq 0}\left(\frac{1}{2k+1-i}+\frac{1}{2k+1+i}\right)(-1)^k $$
but since:
$$ \text{Res}\left(\sec\frac{\pi z}{2},z=2k+1\right)=\frac{2}{\pi}(-1)^{k+1} $$
it follows that:
$$ I = \frac{\pi}{2}\,\text{sech}\left(\frac{\pi}{2}\right).$$
So we may consider every pole, but have to follow a slightly different approach from the usual one.
A: Here is an approach that uses only a small bit of contour integration.
$$
\begin{align}
&2\operatorname{Re}\left(\int_0^\infty e^{(i-1)x}(1-e^{-2x}+e^{-4x}-\dots)\,\mathrm{d}x\right)\tag{1}\\
&=2\operatorname{Re}\left(\frac1{1-i}-\frac1{3-i}+\frac1{5-i}-\dots\right)\tag{2}\\
&=\dots-\frac1{-5-i}+\frac1{-3-i}-\frac1{-1-i}+\frac1{1-i}-\frac1{3-i}+\frac1{5-i}-\dots\tag{3}\\
&=\sum_{k\in\mathbb{Z}}\frac12\frac{(-1)^k}{k+\frac12-\frac i2}\tag{4}\\
&=\frac\pi2\csc\left(\pi\left(\frac12-\frac i2\right)\right)\tag{5}\\
&=\frac\pi2\sec\left(\pi\frac i2\right)\tag{6}\\[2pt]
&=\frac\pi2\operatorname{sech}\left(\frac\pi2\right)\tag{7}
\end{align}
$$
Explanation:
$(1)$: the integral is twice that over half the range; the imaginary part vanishes
$(2)$: integrate each term; use contour integration to justify the imaginary exponent
$(3)$: add the conjugate to get twice the real part
$(4)$: write the sum compactly
$(5)$: $\sum\limits_{k\in\mathbb{Z}}\frac{(-1)^k}{k+z}=\pi\csc(\pi z)$
$(6)$: $\csc\left(\frac\pi2-z\right)=\sec(z)$
$(7)$: $\sec(iz)=\operatorname{sech}(z)$
