How to evaluate this improper integral $\int_{0}^{\infty}\frac{1-x}{1-x^{n}}\,\mathrm dx$?

Here are two methods,using real analysis

Method : 1 : using some special functions : $$I=\displaystyle \int_{0}^{\infty}\dfrac{1-x}{1-x^{n}}\,dx=\underbrace{\displaystyle \int_{0}^{1}\dfrac{1-x}{1-x^{n}}\,dx}_{I_{1}(n)}+\underbrace{\displaystyle \int_{1}^{\infty}\dfrac{1-x}{1-x^{n}}\,dx}_{I_{2}(n)} $$ $$I_{1}(n)=\displaystyle \int_{0}^{1}\dfrac{1-x}{1-x^{n}}\,dx$$ Now lets make a substitution , $x^{n}=t \implies dx=\dfrac{1}{n}t^{\frac{1}{n}-1}dt$ , so $I_{1}(n)$ becomes $$I_{1}(n)=\dfrac{1}{n}\displaystyle \int_{0}^{1}\dfrac{1-t^{\frac{1}{n}}}{1-t}.t^{\frac{1}{n}-1}\,dt= \dfrac{1}{n}\left[\displaystyle \int_{0}^{1}\dfrac{t^{\frac{1}{n}-1}}{1-t}\,dt-\displaystyle \int_{0}^{1}\dfrac{{t^{\frac{2}{n}-1}}}{1-t}\,dt \right]$$ $$I_{1}(n)= \dfrac{1}{n}\displaystyle \lim_{m \rightarrow 0}\left[ \beta\left(m,\dfrac{1}{n}\right)-\beta \left(m,\dfrac{2} {n}\right)\right] $$ $$\large \boxed{I_{1}(n)=\dfrac{1}{n} \left[\psi\left(\dfrac{2}{n}\right)-\psi \left(\dfrac{1}{n}\right)\right]}$$ now lets take $I_{2}(n)$ $$I_{2}(n)=\displaystyle \int_{1}^{\infty}\dfrac{1-x}{1-x^{n}}\,dx$$ Now for this one substitute $x=\dfrac{1}{t} \implies dx=-\dfrac{1}{t^{2}} dt$ $$I_{2}(n)=\displaystyle \int_{0}^{1}\dfrac{1-t}{1-t^{n}}t^{n-3}\,dt$$ Now make another substitution $t^{n}=u \implies dt=\dfrac{1}{n}u^{\frac{1}{n}-1}du$ , so the integral becomes $$I_{2}(n)=\dfrac{1}{n}\displaystyle \int_{0}^{1}\dfrac{1-u^{\frac{1}{n}}}{1-u}\left(u^{\frac{1}{n}-1}\right)\left(u^{1-\frac{3}{n}}\right)\,du$$ $$I_{2}(n)= \dfrac{1}{n}\left[\displaystyle \int_{0}^{1}\dfrac{u^{-\frac{2}{n}}}{1-u}\,du-\displaystyle \int_{0}^{1}\dfrac{{u^{-\frac{1}{n}}}}{1-u}\,du \right]$$ $$I_{2}(n)= \dfrac{1}{n}\displaystyle \lim_{m \rightarrow 0}\left[ \beta\left(m,1-\dfrac{2}{n}\right)-\beta \left(m,1-\dfrac{1}{n}\right)\right]$$ $$\large \boxed{I_{2}(n)= \dfrac{1}{n}\left[ \psi\left(1-\dfrac{1}{n}\right)-\psi \left(1-\dfrac{2}{n}\right)\right]}$$ Now we just have to add $I_{1}(n)$ and $I_{2}(n)$ $$\begin{equation} I(n)=\dfrac{1}{n}\left[ -\psi\left(\dfrac{1}{n}\right)+\psi\left(1-\dfrac{1}{n}\right)+\psi\left(\dfrac{2}{n}\right)- \psi \left(1-\dfrac{2}{n}\right)\right]\\= \dfrac{\pi}{n}\left[ \cot \left(\dfrac{\pi}{n}\right)-\cot \left(\dfrac{2\pi}{n}\right)\right]\\= \dfrac{\pi}{n}\csc\left(\dfrac{2 \pi}{n}\right)\end{equation}$$ $$\Large \displaystyle\ \bbox[10pt, border:2pt solid #06f]{I(n)=\dfrac{\pi}{n}\csc\left(\dfrac{2 \pi}{n}\right)} \tag*{}$$

hete $\psi\Rightarrow $Digamma function (https://en.wikipedia.org/wiki/Digamma_function) and $\beta\Rightarrow $Beta function

(https://en.wikipedia.org/wiki/Beta_function#Derivatives). and the reflection formula i used to simplify is known as Euler’s reflection formula which is … $$\boxed{\psi(1-z)-\psi(z)=\pi \cot(\pi z)} $$

Method : 2 : Mellin Transform(http://mathworld.wolfram.com/MellinTransform.html) : $$I(n)=\displaystyle \int_{0}^{\infty}\dfrac{1-x}{1-x^{n}}\,dx$$ so lets use the same substitution again .. $x^{n}=t \implies dx=\dfrac{1}{n}t^{\frac{1}{n}-1}dt $ so the integral becomes $$I(n)=\dfrac{1}{n} \displaystyle \int_{0}^{\infty}\dfrac{1-t^{\frac{1}{n}}}{1-t}t^{\frac{1}{n}-1}\,dt$$ $$I(n)=\dfrac{1}{n}\left[\underbrace{\displaystyle \int_{0}^{\infty}\dfrac{t^{\frac{1}{n}-1}}{1-t}\,dt}_{F_{1}(t)}- \underbrace {\displaystyle \int_{0}^{\infty}\dfrac{t^{\frac{2}{n}-1}}{1-t}\,dt}_{F_{2}(t)}\right]$$ So again we have two separate integrals , now using melling transform we can evaluate these two very easily , so first lets define the

standard Mellin transform of a function let's say $f(t)$ , it is given by .. $$\mathcal{M}[f(t)]=F(s)=\displaystyle \int_{0}^{\infty}f(t)t^{s-1}dt$$ So, now if we compare $F_{1}(t)$ with the above integral then we can see that .. $s_{1}=\dfrac{1}{n}$ and $f_{1}(t)=\dfrac{1}{1-t}$ Now Mellin transform of $f_{1}(t)$ is well known, it is ... $$\mathcal{M}[f_{1}(t)]\bigg{|}_{s_{1}=1/n}=\pi \cot(\pi s)\bigg{|}_{s=s_{1}}=\pi \cot\left(\dfrac{\pi}{n}\right),0<Re(s)<1 $$ and for $f_{2}(t)$ at $s_{2}=\dfrac{2}{n}$ it will be $$\mathcal{M}[f_{2}(t)]\bigg{|}_{s_{2}=2/n}=\pi \cot(\pi s)\bigg{|}_{s=s_{2}}=\pi \cot\left(\dfrac{2\pi}{n}\right),0<Re(s)<1$$ $$I(n)=\dfrac{1}{n} \left[\mathcal{M}[f_{1}(t)]\bigg{|}_{s_{1}=2/n}- \mathcal{M}[f_{2}(t)]\bigg{|}_{s_{2}=2/n} \right]$$ $$I(n)=\dfrac{\pi}{n} \left[\cot\left(\dfrac{\pi}{n}\right)-\cot\left(\dfrac{2\pi}{n}\right)\right]$$ So, again we arrive at the same result i.e $$\Large \displaystyle\ \bbox[10pt, border:2pt solid #06f]{I(n)=\dfrac{\pi}{n}\csc\left(\dfrac{2 \pi}{n}\right)} \tag*{}$$


I am going to assume that $n\in\{3,4,5,6,\ldots\}$. By splitting the integration range as $(0,1)\cup(1,+\infty)$ and applying the substitution $z\mapsto\frac{1}{z}$ on the second interval, we get that

$$ I_n=\int_{0}^{+\infty}\frac{1-z}{1-z^n}\,dz = \int_{0}^{1}\frac{z^{n-3}-z^{n-2}+1-z}{1-z^n}\,dz =\int_{0}^{1}\frac{(1-z)(z^3+z^n)}{1-z^n}\,dz$$ and by performing the substitution $z=u^{1/n}$ it follows that

$$ I_n = \frac{1}{n}\int_{0}^{1}\frac{(1-u^{1/n})(u^{3/n}+u)u^{1/n-1}}{1-u}\,du $$ where the perturbated integral $$ I_n^\varepsilon = \frac{1}{n}\int_{0}^{1}\frac{(1-u^{1/n})(u^{3/n}+u)u^{1/n-1}}{(1-u)^{1-\varepsilon}}\,du $$ can be computed in terms of the $\Gamma$ function due to the integral representation for the Beta function, for any $\varepsilon>0$. By considering the limit as $\varepsilon\to 0^+$ we get an expression involving different values of the $\psi$ function, that by the reflection formula for the $\psi$ function simplifies to

$$ I_n = \color{red}{\frac{\pi}{n\sin\frac{2\pi}{n}}}.$$