## Weird integral whose simplicity is only apparent in the complex plane

Every so often we come across an integral that seems absolutely impossible on its face, but is easily attacked – in fact, is custom designed – for the residue theorem. I wonder why a first year complex analysis class doesn’t show off this case as Exhibit A in why the residue theorem is so useful.

OK, so here’s the integral:

$$\int_{-\infty}^{\infty} \frac{dx}{\left ( e^x+x+1\right )^2+\pi^2}$$

So what’s wrong? Well, the combination of $x$ and the exponential is ugly. There is no obvious symmetry that helps to keep us strictly in the positive numbers, nor is there any obvious scale that allows for, say, Taylor expansion.

But a very quick look outside the box shows that this integral can be attacked by extension into the complex plane. The reason is that $i \pi$ is a pole of the integrand. (Try it out.) $-i \pi$, too. And that’s all, it turns out. So the residue theorem should work here just fine.

I am going to take a slight detour, while still using the residue theorem. First sub $x=\log{u}$ in the integral and get that the integral is equal to

$$\int_0^{\infty} \frac{du}{u \left [(u+1+\log{u})^2 + \pi^2\right ]}$$

Now consider the following contour integral in the complex plane

$$\oint_C \frac{dz}{z (z+1+\log{z}-i \pi)}$$

where $C$ is a keyhole contour of outer radius $R$ and inner radius $\epsilon$ about the positive real axis. The contour integral is equal to

$$\int_{\epsilon}^R \frac{dx}{x (x+1+\log{x}-i \pi )} + i R \int_0^{2 \pi} d\theta \, \frac{e^{i \theta}}{R e^{i \theta} (R e^{i \theta} + 1 + \log{\left ( R e^{i \theta}\right )-i \pi)}} \\ + \int_R^{\epsilon} \frac{dx}{x (x+1+\log{x}+i \pi )}+i \epsilon \int_{2 \pi}^0 d\phi \, \frac{e^{i \phi}}{\epsilon e^{i \phi} (\epsilon e^{i \phi} + 1 + \log{\left ( \epsilon e^{i \phi}\right )-i \pi)}}$$

In the limit as $R \to \infty$, the magnitude of the second integral vanishes as $2 \pi/R$. As $\epsilon \to 0$, the magnitude of the fourth integral vanishes as $2 \pi/\log{\epsilon}$. Thus, in this limit, the contour integral is equal to

$$\int_0^{\infty} \frac{dx}{x(x+1+\log{x}-i \pi)} – \int_0^{\infty} \frac{dx}{x(x+1+\log{x}+i \pi)} = i 2 \pi \int_0^{\infty} \frac{dx}{x \left[(x+1+\log{x})^2+\pi^2\right]}$$

By the residue theorem, the contour integral is also equal to $i 2 \pi$ times the sum of the residues at the poles of the integrand inside $C$, i.e. outside the origin and the positive real axis. Now, the only pole inside $C$ is at $z=-1$ (this may be verified by examining the polar form of $z$). Also, the pole at $z=-1$ is a double pole; this may be seen by observing that $y+\log{(1-y)} \sim -y^2/2$ as $y \to 0$.

Thus, we need to compute the residue at $z=-1$ as follows:

\begin{align}\operatorname*{Res}_{z=-1} \frac{1}{z (z+1+\log{z}-i \pi)} &= \lim_{z\to -1}\left [\frac{d}{dz} \frac{(z+1)^2}{z (z+1+\log{z}-i \pi)} \right ]\\ &= -\lim_{y\to 0} \left [\frac{d}{dy} \frac{y^2}{(1-y) [y+\log{(1-y)}]} \right ] \\ &= -\lim_{y\to 0} \left [ \frac{y (2 y+(2-y) \log (1-y))}{(1-y)^2 (y+\log (1-y))^2}\right ] \end{align}

This limit is a tricky one. The numerator may be expanded in a series as follows:

\begin{align}-y (2 y +(2-y) \log{(1-y)}) &= -y \left (2 y – 2 y + y^2 – y^2 – \frac{2}{3} y^3 + \frac12 y^3 + O(y^4)\right )\\ &= \frac16 y^4 + O(y^5)\end{align}

The denominator is $y^4/4+O(y^5)$; thus we may say that the limit in question, and therefore the residue, is $2/3$. By the residue theorem

$$i 2 \pi \int_0^{\infty} \frac{dx}{x \left[(x+1+\log{x})^2+\pi^2\right]} = i 2 \pi \frac{2}{3}$$

or

$$\int_{-\infty}^{\infty} \frac{dx}{(e^x+x+1)^2+\pi^2} = \frac{2}{3}$$

Wow. I’ll bet you didn’t guess that. I dare you to find a real method of deriving this that is even half as pretty as this complex method. I was not successful of finding any real method to evaluate this, but maybe the reader will have better luck than me.

Of course, one can apply the residue theorem directly on the given integral by recognizing the pole at $z=i \pi$. Thus, consider a contour integral

$$\oint_C \frac{dz}{(e^z+z+1)^2+\pi^2}$$

where $C$ is a semicircle of radius $R$ in the upper half plane. (The pole at $z=-i \pi$ with the contour being in the lower half plane works as well.) It is straightforward to show that the integral about the arc vanishes as $R \to \infty$. The integral is then simply $i 2 \pi$ times the residue at $z=i \pi$, which is a double pole. I leave this as an exercise for the reader.