Complex integral using cauchy residue formula I want to compute $ \displaystyle \int_{0}^{+\infty} \frac{dx}{x^n-1} $  
I've proved that $ \displaystyle \int_{0}^{+\infty} \frac{dx}{x^n+1} = \frac{\pi}{n\sin\left(\frac{\pi}{n}\right)}$ in a previous question by using some contour integration (in 3 parts like here : image ) and using cauchy residue formula. 
Given that $ \displaystyle \frac{1}{x^{n}-1}-\frac{1}{x^{n}+1} = 2 \frac{1}{x^{2n}-1}$ so  we just have to compute $ \displaystyle \int_{-\infty}^{\infty} \frac{dx}{x^{2n}-1} $ , the other integral being $\displaystyle \frac{\pi}{n\sin\left(\frac{\pi}{n}\right)}$. 
The singularities in this integral are $ z_k=e^{i k \pi / n} $ for $ k=0,\dots,2n-1  $
 If we use cauchy residue formula we would find, if I note $ S=\{ z_k \big| \Im(z_k) \geq 0 \} $  $$ \displaystyle \int_{-\infty}^{\infty} \frac{dx}{x^{2n}-1} =  2i\pi \sum_{z_k \in S} Res(z_k) = \frac{i\pi}{n} \sum_{z_k \in S} z_k  $$

For instance for $n=2$ the solution with positive imaginary part of $z^4=1$ gives $S=\{1,-1,i\}$ and then using this formula $ \displaystyle \int_{-\infty}^{\infty} \frac{dx} {x^4-1}  = -\frac{\pi}{2} $ , which seems to be correct using some calculator.


So, can it be simplified ? I don't like the fact that I need to use S. Thanks in advance.
 A: We can in fact evaluate the Cauchy principal value of the integral as follows.
Consider the following contour integral:
$$\oint_C dz \frac{\log{z}}{z^n-1}$$
$C$ is a modified keyhole contour about the positive real axis of outer radius $R$ and inner radius $\epsilon$.  The modification lies on small semicircular bumps above and below $z=1$ of radius $\epsilon$, and we will consider the limits as $\epsilon \to 0$ and $R\to\infty$.
Let's evaluate this integral over the contours.  There are $8$ pieces to evaluate, as follows:
$$\int_{\epsilon}^{1-\epsilon} dx \frac{\log{x}}{x^n-1} + i \epsilon \int_{\pi}^0 d\phi \, e^{i \phi} \frac{\log{\left (1+\epsilon e^{i \phi}\right )}}{(1+\epsilon e^{i \phi})^n-1} \\ + \int_{1+\epsilon}^R   dx \frac{\log{x}}{x^n-1} + i R \int_0^{2 \pi} d\theta \, e^{i \theta} \frac{\log{\left (R e^{i \theta}\right )}}{R^n e^{i n \theta}-1} \\ + \int_R^{1+\epsilon} dx \frac{\log{x}+i 2 \pi}{x^n-1} + i \epsilon \int_{2 \pi}^{\pi} d\phi \, e^{i \phi} \frac{\log{\left (1+\epsilon e^{i \phi}\right ) }+i 2 \pi}{(1+\epsilon e^{i \phi})^n-1} \\ + \int_{1-\epsilon}^{\epsilon} dx \frac{\log{x}+i 2 \pi}{x^n-1} + i \epsilon \int_{2 \pi}^0 d\phi \, e^{i \phi} \frac{\log{\left (\epsilon e^{i \phi}\right )}}{\epsilon^n e^{i n \phi}-1} $$ 
(To see this, draw the contour out, including the bumps about $z=1$.)
As $R \to \infty$, the fourth integral vanishes as $\log{R}/R^{n-1}$.  As $\epsilon \to 0$, the second integral vanishes as it is $O(\epsilon)$, while the eighth integral vanishes as $\epsilon \log{\epsilon}$.  This leaves the first, third, fifth, sixth and seventh integrals, which in the above limits, become
$$PV \int_0^{\infty} dx \frac{\log{x} - (\log{x}+i 2 \pi)}{x^n-1} + \frac{2 \pi^2}{n}$$
It should be appreciated that, in the fifth, sixth, and seventh integrals, the $i 2 \pi $ factor appears because, on the lower branch of the real axis, we write $z=x \, e^{i 2 \pi}$.  In the sixth integral, in fact, $z = e^{i 2 \pi} + \epsilon \, e^{i \phi + 2 \pi}$.
The $PV$ denotes the Cauchy principal value of the integral.  As it stands, the integral does not actually converge.  Nevertheless, we are not actually considering the integral straight through the pole at $z=1$, but a very small detour around the pole.  Thus, in the limit, we get the Cauchy PV.  A little rearranging cancels the $\log$ term, and we now have:
$$-i 2 \pi PV \int_0^{\infty} \frac{dx}{x^n-1} + \frac{2 \pi^2}{n}$$
The contour integral is also equal to $i 2 \pi$ times the sum of the residues at the poles. The poles here are at $z=e^{i 2 \pi k/n}$, $k=1,\cdots,n-1$. Note that the pole at $z=1$ is not inside the contour $C$ because of the detour around that "pole".  It should be appreciated that the poles must have their arguments between $[0,2 \pi]$ because of the way we defined $C$.
In any case, we now have that the above 1D integrals over the positive real line are equal to
$$i 2 \pi \sum_{k=1}^{n-1} \frac{i 2 \pi k/n}{n e^{i 2 \pi k (n-1)/n}} = \frac{2 \pi ^2}{n}+i \frac{2\pi ^2}{n} \cot{\frac{\pi}{n}} $$
(The evaluation of the sum is a bit messy but very doable by hand, which I did.  I will skip the details in the name of brevity but will supply them upon request.)
We may now solve for the principal value and get:
$$ PV \int_0^{\infty} \frac{dx}{x^n-1} = -\frac{\pi}{n}\cot{\frac{\pi}{n}}  $$
A: $\newcommand{\angles}[1]{\left\langle\, #1 \,\right\rangle}
 \newcommand{\braces}[1]{\left\lbrace\, #1 \,\right\rbrace}
 \newcommand{\bracks}[1]{\left\lbrack\, #1 \,\right\rbrack}
 \newcommand{\ceil}[1]{\,\left\lceil\, #1 \,\right\rceil\,}
 \newcommand{\dd}{{\rm d}}
 \newcommand{\ds}[1]{\displaystyle{#1}}
 \newcommand{\expo}[1]{\,{\rm e}^{#1}\,}
 \newcommand{\fermi}{\,{\rm f}}
 \newcommand{\floor}[1]{\,\left\lfloor #1 \right\rfloor\,}
 \newcommand{\half}{{1 \over 2}}
 \newcommand{\ic}{{\rm i}}
 \newcommand{\iff}{\Longleftrightarrow}
 \newcommand{\imp}{\Longrightarrow}
 \newcommand{\Li}[1]{\,{\rm Li}_{#1}}
 \newcommand{\pars}[1]{\left(\, #1 \,\right)}
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\pp}{{\cal P}}
 \newcommand{\root}[2][]{\,\sqrt[#1]{\vphantom{\large A}\,#2\,}\,}
 \newcommand{\sech}{\,{\rm sech}}
 \newcommand{\sgn}{\,{\rm sgn}}
 \newcommand{\totald}[3][]{\frac{{\rm d}^{#1} #2}{{\rm d} #3^{#1}}}
 \newcommand{\ul}[1]{\underline{#1}}
 \newcommand{\verts}[1]{\left\vert\, #1 \,\right\vert}$
\begin{align}&\color{#66f}{\large\pp\int_{0}^{\infty}{\dd x \over x^{n} - 1}}
=\lim_{\epsilon\ \to 0^{+}}\pars{\int_{0}^{1 - \epsilon}{\dd x \over x^{n} - 1}
+\ \overbrace{\int_{1 + \epsilon}^{\infty}{\dd x \over x^{n} - 1}}
^{\ds{\color{#c00000}{x\ \mapsto\ {1 \over x}}}}}
\\[5mm]&=\lim_{\epsilon\ \to 0^{+}}\pars{%
\int_{0}^{1 - \epsilon}{\dd x \over x^{n} - 1}
+\int_{1/\pars{1 + \epsilon}}^{0}{-\,\dd x/x^{2} \over x^{-n} - 1}}
\\[5mm]&=\lim_{\epsilon\ \to 0^{+}}\pars{%
-\int_{0}^{1 - \epsilon}{\dd x \over 1 - x^{n}}
+\int_{0}^{1/\pars{1 + \epsilon}}{x^{n - 2}\,\dd x \over 1 - x^{n}}}\ =\
\overbrace{\int_{0}^{1}{x^{n - 2} - 1 \over 1 - x^{n}}\,\dd x}
^{\ds{\color{#c00000}{x^{n}\ \mapsto\ x}}}
\\[5mm]&=\int_{0}^{1}{x^{1 - 2/n} - 1 \over 1 - x}\,{1 \over n}\,x^{1/n - 1}\,\dd x
={1 \over n}\int_{0}^{1}{x^{-1/n} - x^{1/n - 1} \over 1 - x}\,\dd x
\\[5mm]&={1 \over n}\bracks{%
\int_{0}^{1}{1 - x^{1/n - 1} \over 1 - x}\,\dd x
-\int_{0}^{1}{1 - x^{-1/n} \over 1 - x}\,\dd x}
={1 \over n}\bracks{\Psi\pars{1 \over n} - \Psi\pars{1 - {1 \over n}}}
\\[5mm]&={1 \over n}\bracks{-\pi\,\cot\pars{\pi \over n}}
=\color{#66f}{\large -\,{\pi \over n}\,\cot\pars{\pi \over n}}
\end{align}
