There is something wrong in this contour integral I am trying to prove that $$I=\int ^{\infty}_{-\infty}{\frac {dy} {1+y^2} \frac {s+\cosh {(\pi y)}} {s^2+2s\cosh {(\pi y)} +1}} =\frac {\pi} {s-1}-\frac {\pi} {s\ln {s}}$$ One easily can set any real value to $s$ (providing $s>1$) and calculate this integral at any online integral calculator (Wolfram for example), compare it with the right side of equation value and convince himself that the statement above is true. But when I carry out the integration, I find that above the real line there are three poles of integrand: $+i$, $-\frac{\ln{s}}{\pi}+i$, and $\frac{\ln{s}}{\pi}+i$. So I can write $$\oint {\frac {dz} {1+z^2} \frac {s+\cosh {(\pi z)}} {s^2+2s\cosh {(\pi z)} +1}}=I+\lim_{R \rightarrow \infty}\int ^{\pi}_{0}\frac{Re^{i\theta}id\theta}{1+R^2e^{2i\theta}}\frac{s+\cosh{(\pi Re^{i\theta})}}{s^2+2s\cosh{(\pi Re^{i\theta})}+1}$$
The integral in $\theta$ vanishes as $R$ goes to infinity. So, $I$ is the sum of residues at the three poles. Now the trouble appears: the first pole, $i$, generates the $\pi/(s-1)$; and the two other poles generate the term $$-\frac{\pi}{s\ln{s}}\frac{4\pi^2}{(\ln{s})^2+4\pi^2} $$ I must be making some mistake, because that term produces the wrong value, but I can't figure out what is it. If anyone finds it, would be great! Thank you.
 A: The integral along the upper semicircular arc does not necessarily vanish as $R \to \infty$, since the contour will pass through infinitely many poles as $R$ grows.
Indeed, assuming $s > 1$, note that the integrand
$$ f(z) = \frac{1}{z^2 + 1} \frac{s + \cosh(\pi z)}{s^2 + 2s \cosh(\pi z) + 1} $$
has infinitely many simple poles in the upper-half plane, which can be classified into three types:

*

*$z = i$


*$z = z^{+}_k := \frac{1}{\pi} \log s + (2k+1) i$ for $k = 0, 1, 2, \dots$


*$z = z^{-}_k := -\frac{1}{\pi} \log s + (2k+1) i$ for $k = 0, 1, 2, \dots$
Now let $K$ be a positive integer and $R$ be a sufficiently large positive real, and consider the contour integral of $f$ along the boundary of the rectangle with corners $\pm R$ and $\pm R + 2 K i$. If $[z_0, z_1]$ denotes the directed line segment from $z_0$ to $z_1$, the residue theorem tells that
\begin{align*}
\newcommand{\Res}{\mathop{\operatorname{Res}}}
\int_{[-R,R]} f(z) \, \mathrm{d}z
&= 2\pi i \biggl( \Res_{z=i} f(z) + \sum_{k=0}^{K-1} \Res_{z=z^+_k} f(z) + \sum_{k=0}^{K-1} \Res_{z=z^-_k} f(z) \biggr) \\
&\quad - \int_{[R,R+2Ki]} f(z) \, \mathrm{d}z - \int_{[R+2Ki,-R+2Ki]} f(z) \, \mathrm{d}z - \int_{[-R+2Ki,-R]} f(z) \, \mathrm{d}z.
\end{align*}
Letting $R \to \infty$, the integrals along $[R,R+2Ki]$ and $[-R+2Ki,-R]$ vanish, hence
\begin{align*}
\int_{-\infty}^{\infty} f(x) \, \mathrm{d}x
&= 2\pi i \biggl( \Res_{z=i} f(z) + \sum_{k=0}^{K-1} \Res_{z=z^+_k} f(z) + \sum_{k=0}^{K-1} \Res_{z=z^-_k} f(z) \biggr) + \int_{-\infty}^{\infty} f(x + 2Ki) \, \mathrm{d}x
\end{align*}
Then it is not hard to check that the last integral vanishes as $K \to \infty$, and so,
\begin{align*}
\int_{-\infty}^{\infty} f(x) \, \mathrm{d}x
&= 2\pi i \biggl( \Res_{z=i} f(z) + \sum_{k=0}^{\infty} \Res_{z=z^+_k} f(z) + \sum_{k=0}^{\infty} \Res_{z=z^-_k} f(z) \biggr)
\end{align*}
In order to compute this sum, note that
\begin{align*}
\Res_{z=z^+_k} f(z)
&= \frac{1}{1 + (z^+_k)^2} \frac{s + \cosh(\pi z^+_k)}{2 \pi s \sinh(\pi z^+_k)} \\
&= \frac{1}{(z^+_k + i)(z^+_k - i)} \frac{s - \bigl( \frac{1 + s^2}{2s} \bigr)}{2\pi s \bigl( \frac{1 - s^2}{2s} \bigr)} \\
&= -\frac{1}{4\pi i s} \biggl( \frac{1}{z^+_k - i} - \frac{1}{z^+_k + i} \biggr) \\
&= -\frac{1}{4\pi i s} \biggl( \frac{\pi}{\log s + 2k \pi i} - \frac{\pi}{\log s + 2(k+1)\pi i} \biggr)
\end{align*}
and
\begin{align*}
\Res_{z=z^-_k} f(z)
&= -\frac{1}{4\pi i s} \biggl( \frac{\pi}{\log s - 2k \pi i} - \frac{\pi}{\log s - 2(k+1)\pi i} \biggr).
\end{align*}
So the sums are telescoping and hence yield
\begin{align*}
\int_{-\infty}^{\infty} f(x) \, \mathrm{d}x
&= \frac{\pi}{s-1} - \frac{\pi}{s \log s}.
\end{align*}
