Evaluating an improper integral using complex analysis I am trying to evaluate the improper integral $I:=\int_{-\infty}^\infty f(x)dx$, where
$$
f(z) := \frac{\exp((1+i)z)}{(1+\exp z)^2}.
$$
I tried to do this by using complex integration. Let $L,L^\prime>0$ be real numbers, and $C_1, C_2, C_3, C_4$ be the line segments that go from $-L^\prime$ to $L$, from $L$ to $L+2\pi i$, from $L + 2\pi i$ to $-L^\prime+2\pi i$ and from $-L^\prime+2\pi i$ to $-L^\prime$, respectively.  Let $C = C_1 + C_2 + C_3 + C_4$.
Here we have (for sufficiently large $L$ and $L^\prime$)
$$
\int_{C_2}f(z) dz \le \int_0^{2\pi}\left|\frac{\exp((1+i)(L+iy))}{(\exp(L+iy)+1)}i\right| dy \le \int\frac{1}{(1-e^{-L})(e^L - 1)}dy\rightarrow0\quad(L\rightarrow\infty),
$$
$$
\int_{C_4}f(z)dz\le\int_0^{2\pi}\left|\frac{\exp((1+i)(-L^\prime+iy))}{(\exp(-L^\prime + iy) + 1))^2}(-i)\right|dy\le\int\frac{e^{-L^\prime}}{(1-e^{-L})^2}dy\rightarrow 0\quad(L^\prime\rightarrow\infty),
$$
and
$$
\int_{C_3}f(z)dz = e^{-2\pi}\int_{C_1}f(z)dz.
$$
Thus $$I = \lim_{L,L^\prime\rightarrow\infty}\frac{1}{ (1 + e^{-2\pi})}\oint_Cf(z)dz.$$
Within the perimeter $C$ of the rectangle, 
$f$ has only one pole: $z = \pi i$.  Around this point, $f$ has the expansion
$$
f(z) = \frac{O(1)}{(-(z-\pi i)(1 + O(z-\pi i)))^2} =\frac{O(1)(1+O(z-\pi i))^2}{(z-\pi i)^2} = \frac{1}{(z-\pi i)^2} + O((z-\pi i)^{-1}),
$$
and thus the order of the pole is 2.  Its residue is
$$
\frac{1}{(2-1)!}\frac{d}{dz}\Big|_{z=\pi i}(z-\pi i)^2f(z) = -\pi \exp(i\pi^2)
$$
(after a long calculation) and we have finally $I=-\exp(i\pi^2)/2i(1+\exp(-2\pi))$.
My question is whether this derivation is correct.  I would also like to know if there are easier ways to do this (especially, those of calculating the residue).
I would appreciate if you could help me work on this problem.
 A: Everything appears right except :


*

*(as noted by mrf) the sign in : $$\;\displaystyle\int_{C_3}f(z)dz = -e^{-2\pi}\int_{C_1}f(z)dz$$ (and before $e^{-2\pi}$ in the denominator of $I$ that follows)

*the computation of the residue : $$\frac{d}{dz}\Big|_{z=\pi i}(z-\pi i)^2f(z) = i e^{(i-1)\pi}=-i\, e^{-\pi}$$ so that the integral will simply be $\;2\pi\,i\sum_{\text{res}}=2\pi i\;\left(-i e^{-\pi}\right)\;$ and the answer (corresponding to Graham's series and numerical evaluation) : $$\;\frac{2\pi\,e^{-\pi}}{1-e^{-2\pi}}=\frac{\pi}{\sinh(\pi)}\approx 0.272029055$$


Computing residues in a practical way is often done using our favorite software to get the Laurent series of $f(z)$ at $z=\pi i$.
Without computer I spontaneously expanded $f(z)$ this way (for $\,z:=\pi i+x\,$ with $\,|x|\ll 1$) :
\begin{align}
f(\pi i+x)&=\frac{e^{(1+i)(\pi i+x)}}{(1+e^{\pi i+x})^2}=\frac{-e^{-\pi}\;e^{(1+i)x}}{(1-e^x)^2}\\
&=-e^{-\pi}\frac {1+(1+i)x+O\bigl(x^2\bigr)}{x^2\left(1+x/2+O\bigl(x^2\bigr)\right)^2}\\
&=-\frac{e^{-\pi}}{x^2}\left((1+(1+i)x)(1-x)+O\bigl(x^2\bigr)\right)\\
&=-\frac{e^{-\pi}}{x^2}\left(1+ix+O\bigl(x^2\bigr)\right)\\
&=-\frac{e^{-\pi}}{x^2}-\frac{i\,e^{-\pi}}{x}+O(1)
\end{align} 
A: Just for fun, here is an alternative way to do the integration without calculating residues. First define the following even function:
$$f(x)=\dfrac{e^x}{\left(1+e^x\right)^2}=\dfrac{1}{2+2\cosh{x}}=-\dfrac{d}{dx}\dfrac{1}{1+e^x}\tag{1}$$
and it's Fourier transform; technically it's the inverse (or conjugate) but that is not particularly important:
\begin{aligned}
\hat{F}(k)&=\int_{-\infty}^{\infty}\dfrac{e^x}{\left(1+e^x\right)^2}e^{ixk}{dx}\\
&=2\,\Re{\left(\int_{0}^{\infty}-\left(\dfrac{d}{dx}\dfrac{1}{1+e^x}\right)e^{ixk}{dx}\right)}\\
&=1-2\,\Im{\left(k\int_{0}^{\infty}\dfrac{e^{-x(1-ik)}}{1+e^{-x}}{dx}\right)}
\tag{2}\end{aligned}
where $\Re,\Im$ are real and imaginary parts respectively. We note that the OP is interested in $\hat{F}(1)$. To move from the first line to the second in $(2)$ I used $(1)$ and the eveness of the integrand, to move from the second to the third I used integration by parts and finally multiplied the integrand top and bottom by $e^{-x}$. Next I'll show that $(2)$ can be written in terms of the digamma function:
$$\hat{F}(k)=1+2\,k\,\Im \left( \Psi \left( \dfrac{1-ik}{2}
 \right) -\Psi \left( 1-ik \right)  \right)\tag{3}$$
Proof
First some algebra on the definite integral: 
\begin{aligned}
\int_{\epsilon}^{1/\epsilon}\dfrac{e^{-x(1-ik)}}{1+e^{-x}}{dx}=&\int_{\epsilon}^{1/\epsilon}\dfrac{2e^{-x(1-ik)}}{1-e^{-2x}}{dx}-\int_{\epsilon}^{1/\epsilon}\dfrac{e^{-x(1-ik)}}{1-e^{-x}}{dx}\\
=&-\int_{\epsilon}^{1/\epsilon}\dfrac{e^{-2x}}{x}-\dfrac{2e^{-x(1-ik)}}{1-e^{-2x}}{dx}+\int_{\epsilon}^{1/\epsilon}\dfrac{e^{-x}}{x}-\dfrac{e^{-x(1-ik)}}{1-e^{-x}}{dx}\\&+\int_{\epsilon}^{1/\epsilon}\dfrac{e^{-2x}}{x}-\dfrac{e^{-x}}{x}{dx}\\
=&-\int_{2\epsilon}^{2/\epsilon}\dfrac{e^{-x}}{x}-\dfrac{e^{-x(1-ik)/2}}{1-e^{-x}}{dx}+\int_{\epsilon}^{1/\epsilon}\dfrac{e^{-x}}{x}-\dfrac{e^{-x(1-ik)}}{1-e^{-x}}{dx}\\&-\int_{\epsilon}^{1/\epsilon}{\frac {{e^{-3x/2}}\sinh \left( \frac{x}{2} \right) }{x}}{dx}
\end{aligned}
then we note that for $\Re(t)>0$ we have the following integral representation of the digamma function:
$$\Psi(t)=\int_{0}^{\infty}\frac{e^{-x}}{x}-\frac{e^{-xt}}{1-e^{-t}}{dx}\tag{4}$$
and that taking the limit in which $\epsilon\rightarrow 0$ we then have by comparison with $(4)$:
\begin{aligned}
\int_{0}^{\infty}\dfrac{e^{-x(1-ik)}}{1+e^{-x}}{dx}&=-\Psi\left(\frac{1-ik}{2}\right)+\Psi\left(1-ik\right)-\int_{0}^{\infty}{\frac {{e^{-3x/2}}\sinh \left( \frac{x}{2} \right) }{x}}{dx}\\
&=-\Psi\left(\frac{1-ik}{2}\right)+\Psi\left(1-ik\right)-\ln(2)
\end{aligned}
and $(3)$ follows. (Note: Maple was used to evaluate the real $\sinh$ integral but I won't pursue a proof as I am only interested in the imaginary part).
Then from $\bar{\Psi}(z)=\Psi{(\bar{z})}$ and the reflection formula
$\Psi(1-z)-\Psi(z)=\pi\cot(\pi z)$ we have:
\begin{aligned}
\hat{F}(k)&=1+2\,k\,\Im \left( \Psi \left( \dfrac{1-ik}{2}
 \right) -\Psi \left( 1-ik \right)  \right)\\
& =\pi k\left( -\tanh \left( \frac{\pi k}{2} \right)+
\coth \left( \pi \,k \right)\right)\\
&={\frac {\pi k}{\sinh \left( \pi k \right) }}\tag{5}
\end{aligned}
Residue theory would, in all likelyhood, also arrive at the more general result in $(5)$ but it is interesting to have  an alternative method.
Corollary
Having found the well defined integral:
\begin{aligned}
\hat{F}(k)&=\int_{-\infty}^{\infty}\dfrac{e^xe^{ixk}}{\left(1+e^x\right)^2}{dx}=-\int_{-\infty}^{\infty}\left(\dfrac{d}{dx}\dfrac{1}{1+e^x}\right)e^{ixk}{dx}\\
&=\dfrac{\pi k}{\sinh(\pi k)}
\end{aligned}
we may then use the law for the Fourier transform of a derivative to assign the following meaning to the not so well defined integral:
$$ \dfrac{1}{ \sinh \left( \pi k \right) }=\frac{i}{\pi}\int _{-
\infty }^{\infty }\!{\frac {{e^{ixk}}}{1+{e^{x}}}}{dx}\tag{6}$$
A: \begin{eqnarray*}
\int_{-\infty}^{\infty}
{{\rm e}^{\left(1\ +\ {\rm i}\right)x} \over \left(1 + {\rm e}^{x}\right)^2}\,{\rm d}x
& = &
\int_{0}^{\infty}\left\lbrack%
{{\rm e}^{\left(-1\ +\ {\rm i}\right)x} \over \left(1 + {\rm e}^{-x}\right)^2}
+
{{\rm e}^{-\left(1\ +\ {\rm i}\right)x} \over \left(1 + {\rm e}^{-x}\right)^2}
\right\rbrack
{\rm d}x
\\
& = &
2\,\Re\int_{0}^{\infty}
{{\rm e}^{-\left(1\ -\ {\rm i}\right)x} \over \left(1 + {\rm e}^{-x}\right)^2}\,{\rm d}x
=
2\,\Re\int_{0}^{\infty}
{\rm e}^{-\left(1\ -\ {\rm i}\right)x}
\sum_{n = 1}^{\infty}\left(-1\right)^{n}\,n\,{\rm e}^{-\left(n - 1\right)x}\,{\rm d}x
\\
& = &
2\,\Re\sum_{n = 1}^{\infty}\left(-1\right)^{n}\,n
\int_{0}^{\infty}{\rm e}^{-\left(n - {\rm i}\right)x}
=
2\,\Re\sum_{n = 1}^{\infty}\left(-1\right)^{n}\,{n \over n - {\rm i}}
\\
& = &
2\,\Re\sum_{n = 1}^{\infty}\left(%
-\,{2n - 1\over 2n - 1 - {\rm i}} + {2n \over 2n - {\rm i}}
\right)
\\
& = &
2\,\Re\sum_{n = 1}^{\infty}\left\lbrack%
\left(-1 - {{\rm i} \over 2n - 1 - {\rm i}}\right)
+
\left(1
+
{{\rm i} \over 2n - {\rm i}}\right)
\right\rbrack
\\
& = &
2\,\Im\sum_{n = 1}^{\infty}\left(
{1 \over -{\rm i} + 2n} - {1 \over -{\rm i} + 2n - 1}
\right)
=
2\,\Im\sum_{n = 1}^{\infty}
{\left(-1\right)^{n} \over -{\rm i} + n}
\\
& = &
2\,\Im\left\lbrack\sum_{n = 0}^{\infty}
{\left(-1\right)^{n} \over -{\rm i} + n} - {1 \over -{\rm i}}
\right\rbrack
=
-2 + 2\,\Im\sum_{n = 0}^{\infty}{\left(-1\right)^{n} \over -{\rm i} + n}
\\[1cm]&&
\end{eqnarray*}
$$
\int_{-\infty}^{\infty}
{{\rm e}^{\left(1\ +\ {\rm i}\right)x} \over \left(1 + {\rm e}^{x}\right)^2}\,{\rm d}x
=
-2 + 2\,\Im\beta\left(-{\rm i}\right)
$$
