# Contour Integration yielding wrong result

I've seen a lot of similar questions to the one I'd like to put forth and already read many of the answers provided, anyways I haven't been able to identify any mistakes in my computations. I was trying to solve the following integral $$I = \int_{0}^{\infty}\frac{x^2\log(x)}{(x^2+1)^2}dx$$ I carefully followed the procedure suggested in Functions of a complex variable, E.G.Phillips chapter 5, section 47.

I considered the function $$f(z)$$ obtained via $$x \longmapsto z$$. Since $$log(z)$$ is a multivalued function I put a branch cut in $$Re(z) \ge 0$$ and chose a standard key-hole path $$\Gamma = \gamma_r + \gamma_R + \gamma_+ + \gamma_-$$ that encloses that two $$2^{nd}$$ order poles at $$z = \pm i$$, along the cut's upper and lower edges (the nomenclature of every single path should then be obvious) and encloses the branch point $$z = 0$$ in a small circle of radius $$r$$. Using the residue theorem one easily gets $$\oint_{\Gamma} f(z)dz = 2\pi i\left[\mathcal{R}es(f, +i) + \mathcal{R}es(f,-i)\right] = 2\pi i\left[\left(\frac{\pi}{8} -\frac{i}{4}\right) + \left(\frac{\pi}{8} + \frac{i}{4}\right) \right] = i\frac{\pi^2}{2} \tag{I}$$ where I made sure to give $$\log(z) = \log|z| +i\theta_p$$ the correct values $$|z| = 0, \theta_p = \pm \frac{\pi}{2} \text{ at } z = \pm i$$ when computing the residues of $$f$$. The integrals along $$\gamma_R, \gamma_r$$ both go (as they should) $$0$$ in the limits $$r\to 0^+, R \to +\infty$$ which I'll denote as $$\lim_{r,R}$$. Moreover it can easily been shown that: $$\lim_{r,R}\int_{\gamma_+} \equiv I$$ $$\lim_{r,R}\int_{\gamma_-} = - \left[I+2\pi i\int_{0}^{\infty}\frac{x^2}{(x^2+1)^2}dx\right] = -\left[I + 2\pi i J\right]$$ Hence equation (I) becomes: $$I -[I + 2\pi i J] =\frac{i\pi^2}{2}$$ Therefore $$I = 0, \text{ } J = -\frac{\pi}{4}$$ Unfortunately, the correct result (coming from Wolfram) reads: $$I = \pi/4$$ and interestingly $$J = \pi/4$$ Thanks in advance for any help or suggestions.

• Which $f$ are you using, and do you define $I$ and $J$? I recommend $z^2(a\ln z+b\ln^2z)/(z^2+1)^2$ for constants $a,\,b$ you can find. As long as you can do second-order poles, you should be able to edit in a better calculation. After that, we'll see if you're still stuck.
– J.G.
Commented Jul 15 at 23:01
• Oh, one more thing: $\ln i=\frac{i\pi}{2}$ but $\ln(-i)=\frac{3i\pi}{2}$.
– J.G.
Commented Jul 15 at 23:12
• If $x-(x+y) = c$, you conclude $y=-c$, but you can't conclude $x=0$. Commented Jul 16 at 1:39
• That was not my reasoning. Since $I \in \mathbb{R}$ and the LHS is of the form $a +ib$ and the RHS is purely imaginary I concluded that $a = 0$ Commented Jul 16 at 12:46

The problem is that if you use $$f(z) = z^2\log(z)/(z^2+1)^2$$ as the meromorphic function you integrate around $$\Gamma$$, then the $$\int_{\gamma_+}f(z)+\int_{\gamma_-}f(z)= -2\pi i\int_{\gamma_+}z^2/(z^2+1)^2$$.

One way to fix this is to use the meromorphic function $$g(z) = z^2\log(z)^2/(z^2+1)^2$$ in place of $$f$$: then $$\begin{split} \int_{\gamma_-} g(z)dz &= \int_{R}^r \frac{x^2(\log(x)+2\pi i)^2}{(x^2+1)^2}dx \\ &=-\int_{r}^R\frac{x^2(\log(x)^2-4\pi^2)+4\pi ix^2\log(x)}{(x^2+1)^2}dx \end{split}$$ so that $$\Im(\int_{\gamma_-} g(z)dz) \to -4\pi \int_{0}^\infty x^2\log(x)/(x^2+1)^2 dx$$. Since $$\int_{\gamma_+} g(z)dz$$ is clearly real and the other contributions to the contour integral tend to zero as $$r \to 0$$ and $$R \to \infty$$ it follows that $$\int_{0}^\infty \frac{x^2\log(x)}{(x^2+1)^2}dx = -\frac{1}{4\pi}\Im\left(2\pi i (\mathrm{Res}(g,i)+\mathrm{Res}(g,-i))\right)$$

Now the residues of $$g(z)$$ at $$i$$ and $$-i$$ are $$\frac{\pi}{4}(1-\frac{\pi i}{4})$$ and $$-\frac{3\pi}{4}(1+\frac{3\pi i}{4})$$ (see below for the details) and hence $$\Im(2\pi i(\mathrm{Res}(g,i)+\mathrm{Res}(g,-i))) =-\pi^2$$ and hence it follows that $$\int_{0}^{\infty} x^2\log(x)/(x^2+1)^2 dx = \pi/4$$.

Calculation of residues: To compute the residues, note that since $$\pm i$$ are double poles, we have $$\mathrm{Res}(g,\pm i) = \lim_{z \to \pm i}\frac{d}{dz}\left((z\mp i)^2g(z)\right).$$ Now $$(z\mp i)^2g(z) = [z\log(z)/(z\pm i)]^2$$ and thus $$\begin{split} \frac{d}{dz}\left((z\mp i)^2 g(z)\right) &= 2\frac{z\log(z)}{z \pm i}\left\{\frac{\log(z)}{z\pm i}+\frac{1}{z\pm i}-\frac{z\log(z)}{(z\pm i)^2}\right\} \\ &=\frac{2z\log(z)}{(z\pm i)^2}\left\{\log(z)+1-\frac{z\log(z)}{(z\pm i)}\right\}. \end{split}$$ Noting that for $$z =\pm i$$ we have $$\log(z)=\pi i(1 \mp \frac{1}{2})$$ we see that $$\begin{split} \mathrm{Res}(g,\pm i)&= \frac{\pi i(1\mp \frac{1}{2})}{\pm 2i}\left\{\pi i(1\mp \frac{1}{2}) + 1 -\frac{1}{2}\pi i(1\mp \frac{1}{2})\right\}\\ &= \pm\frac{\pi}{2}(1\mp \frac{1}{2})\left\{\frac{\pi i}{2}(1\mp \frac{1}{2}) +1\right\} \end{split}$$ and hence $$\mathrm{Res}(g,i) = \frac{\pi}{4}(\frac{\pi i}{4}+1)$$ and $$\mathrm{Res}(g,-i) = -\frac{3\pi}{4}(\frac{3\pi i}{4}+1)$$.

Use, instead, the following contour of integration$$^{(*)}$$:

In the limits $$r\to 0$$, $$R\to\infty$$, the integrals along $$c_r$$ and $$C_R$$ vanish, hence \begin{align} \oint_{\Gamma}\frac{z^2\log z}{(z^2+1)^2}\,dz &=\int_{-\infty}^0\frac{x^2(\log|x|+i\pi)}{(x^2+1)^2}\,dx +\int_{0}^{\infty}\frac{x^2\log x}{(x^2+1)^2}\,dx \\ &=2\int_{0}^{\infty}\frac{x^2\log x}{(x^2+1)^2}\,dx +i\pi\int_{0}^{\infty}\frac{x^2}{(x^2+1)^2}\,dx \\ &=2\pi i\operatorname{Res}_{z=i}\left[\frac{z^2\log z}{(z^2+1)^2}\right] \\ &=2\pi i\left(\frac{\pi}{8}-\frac{i}{4}\right), \tag{1} \end{align} which implies $$\int_{0}^{\infty}\frac{x^2\log x}{(x^2+1)^2}\,dx=\frac{\pi}{4}, \qquad \int_{0}^{\infty}\frac{x^2}{(x^2+1)^2}\,dx=\frac{\pi}{4}. \tag{2}$$

$$^{(*)}$$ Source of the figure: https://steemit.com/mathematics/@drifter1/mathematics-mathematical-analysis-surface-and-contour-integrals

• Mathematica: $\frac{\pi}{4}$. Commented Jul 16 at 3:07
• If you replace $\ln x$ with $\ln(x+i\epsilon)$ then take $\epsilon\to0^+$, you don't need the small arc.
– J.G.
Commented Jul 16 at 8:19

Here's another way using the same contour:

For a real parameter $$0, let

$$\mathcal I(a) = \int_0^\infty \frac{x^a}{(x+1)^2} \, dx$$

Note that this is exactly $$\operatorname{B}(1+a,1-a)=a\pi\csc(a\pi)$$, which will be verified with the residue theorem.

By substituting $$x\to\sqrt x$$ in OP's integral, we eliminate one of the poles and end up with

\begin{align*} I &= \int_0^\infty \frac{x^2 \log x}{\left(x^2+1\right)^2} \, dx \\ &= \frac14 \int_0^\infty \frac{\sqrt x \log x}{(x+1)^2} \, dx \\ &= \frac14 \mathcal I'\left(\frac12\right) \end{align*}

Let $$F(z) = z^a(1+z)^{-2}$$ on the branch $$\arg z\in(0,2\pi)$$. By the res. thm.

\begin{align*} \oint_\Gamma F(z) \, dz &= \left(1 - e^{i2a\pi}\right) \mathcal I(a) = i2\pi \underset{z=-1}{\operatorname{Res}} F(z) \\ \implies \mathcal I(a) &= \frac{i2a\pi e^{i(a-1)\pi}}{1-e^{i2a\pi}} = a\pi \csc(a\pi) \end{align*}

and so, as expected,

$$I = \frac\pi4 \csc(a\pi) \left(1 - a\pi \cot(a\pi)\right) \bigg|_{a=\tfrac12} = \frac\pi4$$