How to integrate $\int_0^1\frac{dx}{1+x+x^2+\cdots+x^n}$

Decompose the integrand as

$$\frac{1}{1+x+x^2+...+x^n}=\frac{1-x}{1-x^{n+1}}=\sum_{k=1}^{n}\frac{a_k}{x-x_k} $$ where $x_k= e^{i \frac{2\pi k}{n+1}},\> k=1,2...n$ and $a_k=\frac{x_k(x_k-1)}{n+1}$. Then, integrate individual terms in the sum

\begin{align} I_n&=\int_0^1\frac{dx}{1+x+x^2+...+x^n}\\ &=\int_0^1 \sum_{k=1}^{n}\frac{a_k}{x-x_k}dx =\frac1{n+1}\sum_{k=1}^{n} x_k(x_k-1)\ln\left(1-\frac1{x_k}\right) \end{align} Substitute $x_k= e^{i \frac{2\pi k}{n+1}}$ into above summation and, after good amount of manipulation, arrive at the close-form expression below

$$\color{blue}{I_n = \frac\pi{2(n+1)} \csc\frac{2\pi}{n+1}-\frac4{n+1}\sum_{k=1}^{[\frac n2]} \sin\frac{\pi k}{n+1}\sin\frac{3\pi k}{n+1}\ln\left(\sin\frac{\pi k}{n+1}\right)} $$ which is valid for integers $n\ge 2$. Listed below are some sample results \begin{align} I_2 &= \frac{\pi}{3\sqrt3}\\ I_3 &= \frac\pi8 +\frac14\ln2\\ I_4 &= \frac\pi{10}\csc\frac{2\pi}{5}+\frac1{\sqrt5}\ln\left(2\cos\frac\pi5\right)\\ I_5 &= \frac{\pi}{6\sqrt3}+\frac13\ln2\\ I_7 &= \frac{\pi}{8\sqrt2}+\frac18\ln2 + \frac{1}{8\sqrt2}\ln \frac{\sqrt2+1}{\sqrt2-1}\\ I_9 &= \frac\pi{20}\csc\frac{\pi}{5}+\frac15\ln2 +\frac1{2\sqrt5}\ln\left(2\cos\frac\pi5\right)\\ \end{align} \begin{align} I_6 &= \int_0^1\frac{dx}{1+x+x^2+x^3+x^4+x^5+x^6}\\ &=\frac\pi{14}\csc\frac{2\pi}{7}-\frac1{2\sqrt7}\left( \frac{\ln\sin\frac\pi7}{\sin\frac{2\pi}7} +\frac{\ln\sin\frac{2\pi}7}{\sin\frac{3\pi}7}-\frac{\ln\sin\frac{3\pi}7}{\sin\frac{\pi}7}\right) \\ \end{align}

\begin{align} I_8 &= \int_0^1\frac{dx}{1+x+x^2+x^3+x^4+x^5+x^6+x^7+x^8}\\ &=\frac\pi{18}\csc\frac{2\pi}{9}-\frac{2}{3\sqrt3} \left(\frac{\ln\sin\frac\pi9}{\csc\frac{\pi}9} +\frac{\ln\sin\frac{2\pi}9}{\csc\frac{2\pi}9}-\frac{\ln\sin\frac{4\pi}9}{\csc\frac{4\pi}9}\right) \\ \end{align}


$$I_n=\int_{0}^{1}\frac{dx}{1+x+x^2+\ldots+x^n}=\underbrace{\int_{0}^{1}\frac{1-x}{1-x^{n+1}}dx}_{x\rightarrow y^{\frac{1}{n+1}}}=\frac{1}{n+1}\int_{0}^{1}\frac{y^\frac{1}{n+1}-y^\frac{2}{n+1}}{y(1-y)}dy$$

$$=\frac{1}{n+1}\int_{0}^{1}\left(\frac{y^\frac{1}{n+1}-y^\frac{2}{n+1}}{y}+\frac{y^\frac{1}{n+1}-y^\frac{2}{n+1}}{1-y}\right)dy$$

$$1-\frac{n+1}{2(n+2)}+\frac{1}{n+1}\int_{0}^{1}\left(\frac{y^{\frac{1}{n+1}-1}\log{\left(1-y\right)}}{n+1}-\frac{y^{\frac{2}{n+1}-1}\log{\left(1-y\right)}}{n+2}\right)dy$$

$$=\frac{n+3}{2(n+2)}+\frac{1}{n+1}\left[\frac{\mathfrak{B}\left(\frac{1}{n+1},1\right)\left(\psi^{\left(0\right)}\left(1\right)-\psi^{\left(0\right)}\left(1+\frac{1}{n+1}\right)\right)}{n+1}-\frac{\mathfrak{B}\left(\frac{2}{n+1},1\right)\left(\psi^{\left(0\right)}\left(1\right)-\psi^{\left(0\right)}\left(1+\frac{2}{n+1}\right)\right)}{n+2}\right]$$

$$=\frac{n+3}{2(n+2)}+\frac{\psi^{\left(0\right)}\left(1+\frac{2}{n+1}\right)-\psi^{\left(0\right)}\left(1+\frac{1}{n+1}\right)}{n+1}=\frac{1}{2\left(n+2\right)}+\frac{\psi^{\left(0\right)}\left(\frac{2}{n+1}\right)-\psi^{\left(0\right)}\left(\frac{1}{n+1}\right)}{n+1}$$

Therefore: $$I_n=\int_{0}^{1}\frac{dx}{1+x+x^2+\ldots+x^n}=\frac{1}{2\left(n+2\right)}+\frac{\psi^{\left(0\right)}\left(\frac{2}{n+1}\right)-\psi^{\left(0\right)}\left(\frac{1}{n+1}\right)}{n+1}$$ Notes: $\mathfrak{B}(x,y)$ stands for the Beta Function and $\psi^{(0)}(z)$ stands for the Digamma Function.


Computing the Integral $$ \begin{align} &\int_0^1\frac{1-x}{1-x^{n+1}}\,\mathrm{d}x\\ &=\int_0^1\sum_{k=0}^\infty\left[x^{(n+1)k}-x^{(n+1)k+1}\right]\tag1\\ &=\sum_{k=0}^\infty\left(\frac1{(n+1)k+1}-\frac1{(n+1)k+2}\right)\tag2\\ &=\frac12+\sum_{k=1}^\infty\left(\frac1{(n+1)k+1}-\frac1{(n+1)k+2}\right)\tag3\\ &=\frac12+\frac1{n+1}\sum_{k=1}^\infty{\scriptsize\left(\frac1k-\frac1{k+\frac2{n+1}}\right)}-\frac1{n+1}\sum_{k=1}^\infty{\scriptsize\left(\frac1k-\frac1{k+\frac1{n+1}}\right)}\tag4\\[3pt] &=\frac12+\frac1{n+1}\left(H\!\left(\frac2{n+1}\right)-H\!\left(\frac1{n+1}\right)\right)\tag5\\[3pt] &=\frac1{n+1}\sum_{k=1}^n\log\left(2\sin\left(\frac{\pi k}{n+1}\right)\right)\left(\cos\left(\frac{4\pi k}{n+1}\right)-\cos\left(\frac{2\pi k}{n+1}\right)\right)\\ &+\frac1{n+1}\sum_{k=1}^n\left(\frac{\pi}2-\frac{\pi k}{n+1}\right)\left(\sin\left(\frac{2\pi k}{n+1}\right)-\sin\left(\frac{4\pi k}{n+1}\right)\right)\tag6 \end{align} $$ Explanation:
$(1)$: expand the Taylor series
$(2)$: integrate
$(3)$: pull the $k=0$ term out front
$(4)$: rearrange into two series
$(5)$: Write as extended Harmonic numbers
$(6)$: apply $(7)$ from this answer

Although $(5)$ is always valid, since $(7)$ from this answer requires $p\le q$, $(6)$ is only valid for $n\gt0$. For $n=0$, the integral is $1$.


Mathematica Implementation

Here is a Mathematica implementation of $(6)$:

how[n_]:=1/(n + 1)Sum[
    Log[2 Sin[Pi k/(n+1)]](Cos[4 Pi k/(n+1)]-Cos[2 Pi k/(n+1)])
    + (Pi/2-Pi k/(n+1))(Sin[2 Pi k/(n+1)]-Sin[4 Pi k/(n+1)]),
    {k,1,n}]