Contour Integration yielding wrong result

contour-integration

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.

Best Answer

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

Related Question