# 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.

-
You use $\,f(x)\;,\;f(z)\;$ and "improper integral": is there any real function here for which you want to use complex integration? What function is that? The only function you've written is a complex one... –  DonAntonio Aug 15 '13 at 10:52
You can write: $$\int _{-\infty }^{\infty }\!{\frac {{{\rm e}^{x}}{{\rm e}^{ix}}}{ \left( {{\rm e}^{x}}+1 \right) ^{2}}}{dx}=1/2\,\int _{-\infty }^{ \infty }\!{\frac {\cos \left( x \right) }{\cosh \left( x \right) +1}}{ dx}$$ if that is any use. I can get a series for that integral:$$-2\,\sum _{n=0}^{\infty }{\frac { \left( -1 \right) ^{n}{n}^{2}}{{n}^{ 2}+1}}= 0.2720290550$$ but as of yet no closed form, trying to see if it can be written in terms of digamma function but don't see it yet.# –  Graham Hesketh Aug 15 '13 at 11:18
@DonAntonio Well... what I am working on is an integration of a complex-valued function along the real axis, which is a trivial kind of complex integration and it's safe to say it's real integration. I use the variable $z$ to define the function and use $x$ in the integral but I believe it is not confusing (actually, this is an almost literal copy from a past exam). –  Pteromys Aug 15 '13 at 11:29
@GrahamHesketh, the series you posted can be solved using complex analysis . –  Zaid Alyafeai Aug 15 '13 at 16:56
The series diverges logarithmically. –  Felix Marin Aug 18 '13 at 19:51

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}

-
There is also an error in the orientation of $C_3$: $1+\exp(-2\pi)$ should be $1-\exp(-2\pi)$. –  mrf Aug 15 '13 at 11:58
@Graham: yes sorry (I'll update my answer) –  Raymond Manzoni Aug 15 '13 at 12:00
Thanks @mrf I had missed the sign problem. –  Raymond Manzoni Aug 15 '13 at 12:05
@RaymondManzoni I also computed the residue using Maxima (although I made mistakes in typing the formula) because I felt lazy. What if you must use pen and paper, not computer algebra systems, in an exam, for example? –  Pteromys Aug 15 '13 at 14:42
@Pteromys: Well my spontaneous answer (without computer) is to expand it as this (for $z:=\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(x^2)}{x^2(1+x/2+O(x^2))^2}=-\frac{e^{-\pi}}{x^2}\left((1+(1+i)x)(1-x‌​)+O(x^2)\right)=-\frac{e^{-\pi}}{x^2}\left(1+ix+O(x^2)\right)=\\-\frac{e^{-\pi}}{x‌​^2}-\frac{i\,e^{-\pi}}{x}+O(1)$$ (for this specific problem at least... multiplying by $(z-\pi i)^2$ is another equivalent possibility...) –  Raymond Manzoni Aug 15 '13 at 17:34

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}$$

-
+1 for the effort and the interesting generalization. Just two little typos : the $2$ at the numerator in $(1)$ and in the Corollary should be $1$ (the $2$ in $(2)$ comes from the half-integral). Cheers –  Raymond Manzoni Aug 16 '13 at 17:55
Cheers, fixed them. –  Graham Hesketh Aug 16 '13 at 21:37

\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)$$

-