Showing $\int_0^{\infty } \frac{1}{e^{2 x}+2 e^x \cos (x)+1} \, dx=\frac{\log (2)}{2}-\pi \sum _{n=0}^{\infty } \frac{1}{e^{\pi (2 n+1)}+1}$

$$e^{2x}+2e^x\cos(x)+1 = e^{2x} + e^{(1+i)x} + e^{(1-i)x} + 1 = (1+e^{(1+i)x})(1+e^{(1- i)x})$$ so $f(z)=\frac{1}{e^{2z}+2e^z\cos(z)+1}$ is a meromorphic function with simple poles at the odd multiples of $\frac{\pi}{2}(1+i)$ and $\frac{\pi}{2}(1-i)$. The sum of the residues at $(2k+1)\frac{\pi}{2}(1+i)$ and $(2k+1)\frac{\pi}{2}(1-i)$ equals $-\frac{1}{1+e^{\pi(2k+1)}}$.
We may notice that $f((1+i)z)+f((1-i)z)=\frac{1}{1+e^{2z}}$, whose integral on $\mathbb{R}^+$ equals $\frac{\log 2}{2}$. Additionally $f((1+i)z)-f((1-i)z)=\frac{i}{2}\tan(z)(\tanh(z)-1)$. It follows that

$$ \int_{0}^{+\infty}\frac{dz}{e^{2z}+2e^z\cos(z)+1}=\frac{\log 2}{2}-\pi\sum_{k\geq 0}\frac{1}{1+e^{(2k+1)\pi}} $$ can be derived from the residue theorem and the ML lemma, applied to a path made by

  1. a segment from $0$ to $(1+i)R$, with bulges avoiding the poles and enclosing them in the interior;
  2. a quarter-circle joining $(1+i)R$ and $(1-i)R$;
  3. a segment from $(1-i)R$ and $0$, with bulges enclosing the poles.

It is probably simpler to start with the series and to convert it into an integral through the Abel-Plana formula.


Neither of sums $$ \sum^{\infty}_{n=0}\frac{1}{e^{(2n+1)\pi}+1} $$ or $$ \sum^{\infty}_{n=1}\frac{1}{e^{2n\pi}-1} $$ have been evaluated in closed forms. I start searching for evaluations of the above two sums and ended up with this paper or if one don't have a Researchgate account this


Consider closing the contour to the first and fourth quadrant respectively.

Then (with $I$ for your original integral): $$ I + \int_{i\infty}^0 dz f(z)=2\pi i R_U,\quad I + \int_{-i\infty}^0 dz f(z) = 2\pi i R_L, $$ where $R_U$ and $R_L$ - sum of residues in the upper-right quadrant and lower-right quadrant respectively. After simplification we have: $$ I = \pi I (R_U + R_L) + \frac12\int_0^{\infty}\frac{\sin (z)dz}{\cos (z)+\cosh (z)} $$ The last integral is elementary (since its antiderivative can be found) and equals $\ln2$. As a result: $$ I = -\pi \sum _{n=0}^{\infty } \frac{1}{e^{\pi (2 n+1)}+1} + \frac{\ln2}{2}. $$ The same approach works for your second problem. You will need the following real integral (which is again trivial since its primitive is expressible in terms of elementary and $\text{Ci}$ function): $$ \int_0^\infty\frac{\sin (z) \left(z^2+\cos (z)-\cosh (z)\right)dz}{z^2 (\cos (z)-\cosh (z))}=-\frac{\pi }{4}-\gamma +1+\frac{\ln 2}{2}. $$