Calculating the integral $\int_0^{\infty}{\frac{\ln x}{1+x^n}}$ using complex analysis

Using the contour in the question:

$\hspace{4cm}$enter image description here

contour integration gives $$ \begin{align} &2\pi i\,\mathrm{Res}\left(\frac{\log(z)}{1+z^n},z=e^{i\pi/n}\right)\\ &=\frac{2\pi^2e^{i\pi/n}}{n^2}\\ &=\color{#00A000}{\lim_{R\to\infty}\int_0^R\frac{\log(x)}{1+x^n}\,\mathrm{d}x} \color{#C00000}{+\int_0^{2\pi/n}\frac{\log(R)+ix}{1+R^ne^{inx}}iRe^{ix}\mathrm{d}x} \color{#0000FF}{-e^{i2\pi/n}\int_0^R\frac{\log(x)+i2\pi/n}{1+x^n}\,\mathrm{d}x}\\ &=\left(1-e^{i2\pi/n}\right)\int_0^\infty\frac{\log(x)}{1+x^n}\,\mathrm{d}x -e^{i2\pi/n}\int_0^\infty\frac{i2\pi/n}{1+x^n}\,\mathrm{d}x\tag{1} \end{align} $$ where the green integral is the outgoing line, the red integral is the circular arc, and the blue integral is the returning line. For $n>1$, the integral in red vanishes as $R\to\infty$.

Dividing $(1)$ by $-2ie^{i\pi/n}$, we get $$ i\frac{\pi^2}{n^2}=\sin(\pi/n)\int_0^\infty\frac{\log(x)}{1+x^n}\,\mathrm{d}x +e^{i\pi/n}\int_0^\infty\frac{\pi/n}{1+x^n}\,\mathrm{d}x\tag{2} $$ Taking the imaginary part of $(2)$, we get $$ \frac{\pi^2}{n^2}=\sin(\pi/n)\int_0^\infty\frac{\pi/n}{1+x^n}\,\mathrm{d}x\tag{3} $$ and taking the real part of $(2)$, we get $$ \sin(\pi/n)\int_0^\infty\frac{\log(x)}{1+x^n}\,\mathrm{d}x +\cos(\pi/n)\int_0^\infty\frac{\pi/n}{1+x^n}\,\mathrm{d}x=0\tag{4} $$ Combining $(3)$ and $(4)$ yields $$ \int_0^\infty\frac{\log(x)}{1+x^n}\,\mathrm{d}x=-\frac{\pi^2}{n^2}\csc(\pi/n)\cot(\pi/n)\tag{5} $$


An alternate method

Using this result $$ \frac{\pi}{n}\csc\left(\pi\frac{m+1}{n}\right)=\int_0^\infty\frac{x^m}{1+x^n}\,\mathrm{d}x\tag{6} $$ Differentiating in $m$ yields $$ -\frac{\pi^2}{n^2}\csc\left(\pi\frac{m+1}{n}\right)\cot\left(\pi\frac{m+1}{n}\right)=\int_0^\infty\frac{\log(x)x^m}{1+x^n}\,\mathrm{d}x\tag{7} $$ Therefore, setting $m=0$ gives $$ -\frac{\pi^2}{n^2}\csc\left(\frac\pi n\right)\cot\left(\frac\pi n\right)=\int_0^\infty\frac{\log(x)}{1+x^n}\,\mathrm{d}x\tag{7} $$


Let us define, for $r>0$, $$\Gamma_{r}=\{r e^{i\alpha}\ :\ 0\leq\alpha\leq\theta\}$$ The circular arcs of your contour are then $\Gamma_{\epsilon}$ and $\Gamma_{R}$.

We note that, for $z\in\Gamma_{\epsilon}$ $$\left|\frac{\ln z}{1+z^n}\right|\leq|\ln z|\leq 2\ln\epsilon$$ if $\epsilon$ is small enough. So $$\left|\int_{\Gamma_\epsilon} f(z)\right|\leq 2\theta\epsilon\ln\epsilon$$ which goes to $0$ with $\epsilon$. Also, for $R$ large enough, $$|\ln z|\leq 2\ln R$$ when $z\in \Gamma_R$. So $$\left|\frac{\ln z}{1+z^n}\right|\leq\frac{2\ln R}{R^n-1}$$ hence $$\left|\int_{\Gamma_R} f(z)\right|\leq\theta R\frac{2\ln R}{R^n-1}$$ which goes to $0$ when $R\to\infty$, if $n>1$. (So, yes, these two pieces go to zero)

Now take $\Gamma_1=\{r\ :\ \epsilon\leq r\leq R\}$ and $\Gamma_2=e^{i\theta}\Gamma_1$; define the contour $\Gamma$ by walking along $\Gamma_1$, then $\Gamma_R$, then backwards along $\Gamma_2$ and $\Gamma_\epsilon$.

The roots of $1+z^n=0$ are the $n$-th roots of $-1$, that is $$z_k=e^{i\frac{(2k+1)\pi}{n}}$$ so, if we take $\theta\in (\frac{\pi}{n},\frac{3\pi}{n})$, $\Gamma$ surrounds exactly one pole of $f$.

Now, following the hint of Christopher A. Wong, we set $\theta=\frac{2\pi}{n}$; therefore, if $z\in\Gamma_2$, we get $z^n=|z|^ne^{in\theta}=|z|^n$ and $\ln z=\ln|z| + i\frac{2\pi}{n}$.

So $$\int_{\Gamma_2}f(z)=\int_{\epsilon}^R\frac{\ln x + i\frac{2\pi}{n}}{1+x^n}e^{i\frac{2\pi}{n}}dx$$

We recall that $$\int_0^\infty\frac{1}{1+x^n}dx=\frac{\pi/n}{\sin(\pi/n)}$$ with the same method we used now (integrating on $\Gamma$!).

Call $J=\int_{0}^\infty \ln x/(1+x^n) dx$ and $L$ the residue of $f(z)=\ln z /(1+z^n)$ at $z=e^{i\frac{\pi}{n}}$, then $$2i\pi L=J-e^{i\frac{2\pi}{n}}\left(J+i\frac{2\pi}{n}\frac{\pi/n}{\sin(\pi/n)}\right)$$ that is $$J=\frac{2i\pi L+ie^{i\frac{2\pi}{n}}\frac{2\pi^2/n^2}{\sin(\pi/n)}}{1-e^{i\frac{2\pi}{n}}}$$

Now it is enough to perform the computations.


Here's an alternative solution. Consider a standard keyhole contour:

keyhole contour

and let $$f(z) = \frac{(\log z)^2}{1+z^n}$$ where $\log$ denotes the natural branch of the complex logarithm. The usual estimates over $\gamma$ and $\Gamma$ show that $$\int_\gamma f(z)\,dz \to 0 \qquad\text{and}\qquad \int_\Gamma f(z)\,dz \to 0$$ as $r \to 0$ and $R \to \infty$. In the limit, we will be left with $$\int_0^\infty \frac{(\ln x)^2}{1+x^n}\,dx$$ from the ''upper'' part of the real axis and $$-\int_0^\infty \frac{(\ln x + 2\pi i)^2}{1+x^n}\,dx$$ from the ''lower'' part. Adding these together, the $(\ln x)^2$-terms will cancel, and we end up with $$4\pi i \int_0^\infty \frac{\ln x}{1+x^n} - 4\pi^2 \int_0^\infty \frac{1}{1+x^n}\,dx.$$ By the residue theorem, this sum will be equal to $$2\pi i \sum \operatorname{Res}(f; \alpha_k)$$ where the sum is taken over all poles of $f$. These poles are given by the solutions to $z^n = -1$, i.e. $\alpha_k = \exp\Big( \frac{i\pi}{n}(2k+1) \Big)$ for $0 \le j \le n-1$. Also, \begin{align} \operatorname{Res}(f; \alpha_k) &= \frac{(\log \alpha_k)^2}{n\alpha_k^{n-1}} = -\frac{\alpha_k(\log \alpha_k)^2}{n} \\ &= -\frac{\exp\Big( \frac{i\pi}{n}(2k+1) \Big)\Big(\frac{i\pi}{n}(2k+1) \Big)^2}{n} \\ &= \frac{\pi^2}{n^3} \exp\Big( \frac{i\pi}{n}(2k+1) \Big)\Big((2k+1) \Big)^2. \end{align}

Summing up (while keeping track of all the $i$:s), we end up with \begin{align} \int_0^\infty \frac{\ln x}{1+x^n} &= -\frac12 \operatorname{Re} \left( \sum \operatorname{Res}(f; \alpha_k) \right) \\ &= -\frac{\pi^2}{2n^3} \sum_{j=0}^{n-1} \exp\Big( \frac{i\pi}{n}(2k+1) \Big)\Big((2k+1) \Big)^2. \end{align}

(I'll leave the algebra that shows that this answer is the same as the other one given as an exercise.)