Integral $\int_0^\infty \frac{x^n - 2x + 1}{x^{2n} - 1} \mathrm{d}x=0$ Inspired by some of the greats on this site, I've been trying to improve my residue skills. I've come across the integral
$$\int_0^\infty \frac{x^n - 2x + 1}{x^{2n} - 1} \mathrm{d}x=0$$
where $n$ is a positive integer that is at least $2$.
With non-complex methods, I know that the integral is $0$. But I know that it can be done with residue theorem.
The trouble comes in choosing a contour. We're probably going to do some pie-slice contour, perhaps small enough to avoid any of the $2n$th roots of unity, and it's clear that the outer-circle vanishes. But I'm having trouble getting the cancellation for the integral.
Can you help? (Also, do you have a book reference for collections of calculations of integrals with the residue theorem that might have similar examples?)
 A: We want to prove that the integral is $0$ for $n>1$, it is the same thing as 
$$\int_0^{\infty} \frac{\mathrm{d}x}{x^n+1} = 2\int_0^{\infty} \frac{x-1}{x^{2n}-1} \ \mathrm{d}x.$$
The left hand integral is widely known to be $\frac{\pi}{n} \csc \frac{\pi}{n}$, we want to calculate the right hand integral. let $f(x)=\frac{x-1}{x^{2n}-1}$, and consider the contour $C=C_1\cup C_2\cup C_3$ where $$C_1=[0,r],\ C_2=\left\{z \in \mathbb{C} | |z|=r,\ \arg(z) \in \left[0,\frac{\pi}{2n}\right]\right\},\ \ C_3 =e^{\frac{\pi i}{2n}} C_1. $$
Here's what the contour look like  

Notice that $\int_C f(z) \ \mathrm{d}z=0$ (the integral is taken counter clockwise always) since $f$ is holomorphic inside $C$. and 
$$\left|\int_{C_2} f(x)\ \mathrm{d}x \right| =\mathcal{O}(r^{-1}) \to 0.$$
And 
\begin{align*}
\int_{C_3}f(z) \ \mathrm{d}z &= e^{\frac{\pi i}{2n}}\int_0^r f\left(x e^{\frac{\pi i }{2n}}\right) \ \mathrm{d}x \\ 
&=e^{\frac{\pi i}{2n}}\int_0^r \frac{e^{\frac{\pi i}{2n}}x -1}{x^{2n}+1} \ \mathrm{d}x \\ 
&= e^{\frac{\pi i}{n}}\int_0^r \frac{x }{x^{2n}+1} \ \mathrm{d}x-e^{\frac{\pi i}{2n}}\int_0^r \frac{1}{x^{2n}+1} \ \mathrm{d}x.
\end{align*}
Note that $\int_{0}^{\infty} \frac{x}{x^{2n}+1} \ \mathrm{d}x  = \frac{\pi }{2n} \csc \frac{\pi}{n}$, then by taking $r\to \infty$ we get 
$$\int_0^{\infty} f(x) \  \mathrm{d}x =-e^{\frac{\pi i}{n}}\cdot \frac{\pi }{2n} \csc \frac{\pi}{n} + e^{\frac{\pi i}{2n}} \frac{\pi }{2n} \csc \frac{\pi}{2n} = \frac{\pi}{2n} \csc \frac{\pi}{n}.$$ 
Which is what we were looking for.
A: Just in case someone wonders how it can be done the "normal" way, here it is.
By factorization what we are trying to prove is:
$$
\int_0^\infty \frac{1}{x^n-1} dx = 2 \int_0^\infty \frac{x}{x^{2n}-1} dx
$$
On the right hand side let $x \rightarrow \sqrt{t}$.
A: Resolving the integrand into two partial fractions, we have
$$\displaystyle I=\int_0^{\infty} \frac{x^n-2 x+1}{\left(1+x^n\right)\left(1-x^n\right)} d x=\int_0^{\infty}\left(\frac{x}{1+x^n}-\frac{1-x}{1-x^n}\right) d x=J-K\tag*{} $$
For the integral $J$, we are going to transforms it into a Beta function by letting $y=\frac{1}{1+x^n}$.
$$\displaystyle \begin{aligned}J & =\frac{1}{n} \int_0^1 y^{-\frac{2}{n}}(1-y)^{\frac{2}{n}-1} d y \\& =\frac{1}{n} B\left(-\frac{2}{n}+1, \frac{2}{n}\right) \\& =\frac{\pi}{n} \csc \left(\frac{2 \pi}{n}\right) \quad \textrm{ (By Euler Reflection Formula)}\end{aligned}\tag*{} $$

Next, we are going to evaluate the integral
$ \displaystyle K=\displaystyle \int_{0}^{\infty} \frac{1-x}{1-x^{n}} d x \tag*{} $
by the theorem
$ \displaystyle \displaystyle \sum_{k=-\infty}^{\infty} \frac{1}{k+z}=\pi \cot (\pi z), \textrm{ where } z\notin Z.\tag*{} $
We first split the integral into two integrals
$ \displaystyle \displaystyle \int_{0}^{\infty} \frac{1-x}{1-x^{n}} d x=\int_{0}^{1} \frac{1-x}{1-x^{n}} d x+\int_{1}^{\infty} \frac{1-x}{1-x^{n}} d x \tag*{}$
Transforming the latter integral by the inverse substitution $ x\mapsto \frac{1}{x}$ m, we have
$\displaystyle \displaystyle \int_{1}^{\infty} \frac{1-x}{1-x^{n}} d x=\int_{0}^{1} \frac{x^{n-3}-x^{n-2}}{1-x^{n}} d x \tag*{}  $
Putting back yields
$ \begin{aligned}\displaystyle K&=\int_{0}^{1} \frac{1-x+x^{n-3}-x^{n-2}}{1-x^{n}} d x\\\displaystyle &=\int_{0}^{1}\left[\left(1-x+x^{n-3}-x^{n-2}\right) \sum_{k=0}^{\infty} x^{n k}\right] d x\\ \displaystyle & =\sum_{k=0}^{\infty} \int_{0}^{1}\left[x^{n k}-x^{n k+1}+x^{n(k+1)-3}-x^{n(k+1)-2}\right] d x\\ & =\sum_{k=0}^{\infty}\left(\frac{1}{n k+1}-\frac{1}{n k+2}+\frac{1}{n(k+1)-2}-\frac{1}{n(k+1)-1}\right)\\ & =\sum_{k=0}^{\infty}\left[\frac{1}{n k+1}-\frac{1}{n(k+1)-1}\right]+\sum_{k=0}^{\infty}\left[\frac{1}{n(k+1)-2}-\frac{1}{n k+2}\right] \end{aligned}\tag*{} $
Modifying yields
$$\displaystyle \begin{aligned} K&=\frac{1}{n}\left[\sum_{k=0}^{\infty} \frac{1}{k+\frac{1}{n}}+\sum_{k=-1}^{-\infty} \frac{1}{k+\frac{1}{n}}\right]+\frac{1}{n}\left(\sum_{k=1}^{\infty} \frac{1}{k-\frac{2}{n}}+\sum_{k=0}^{-\infty} \frac{1}{k-\frac{2}{n}}\right)\\& =\frac{1}{n}\left(\sum_{k=-\infty}^{\infty} \frac{1}{k+\frac{1}{n}}+\sum_{k=-\infty}^{\infty} \frac{1}{k-\frac{2}{n}}\right)\end{aligned} \tag*{} $$
By the Theorem,
$$ \displaystyle \displaystyle \sum_{k=-\infty}^{\infty} \frac{1}{k+z}=\pi \cot (\pi z), \tag*{} $$
where $ \displaystyle z\notin Z,$
we have
$$ \displaystyle \displaystyle K=\frac{1}{n}\left[\pi \cot \left(\frac{\pi}{n}\right)+\pi \cot \left(\frac{-2 \pi}{n}\right)\right]=\frac{\pi}{n}\left[\cot \left(\frac{\pi}{n}\right)-\cot \left(\frac{2 \pi}{n}\right)\right] =\frac{\pi}{n} \csc \frac{2 \pi}{n} =J\tag*{} $$

We can now conclude that
$\displaystyle \boxed{I=J-K=0 }\tag*{} $
