TITLE: What is the integral of n-th root of tan x?
QUESTION [7 upvotes]: What will be the value of
$ \int\sqrt[n]{\tan x},dx $
?
I have solved the cases for n=2 and n=3 but can't see how I can generalize it.

REPLY [11 votes]: The generalization is tedious but actually pretty straight forward. The key is perform partial fraction decomposition of some rational function in a systematic manner.  
Introduce variables $y$ and $z$ such that $y = \tan x = z^{n}$, we have
$$\int \sqrt[n]{\,\tan x} dx = \int \frac{y^{1/n}}{1+y^2} dy = \int \frac{n z^n}{1+z^{2n}} dz$$
For any integer $k$, let $\displaystyle\;\theta_k = \frac{(2k+1)\pi}{2n}\;$. We can factorize the denominator of the integrand as
$$z^{2n}+1 
= \prod_{k=0}^{n-1}\left(z- e^{i\theta_k}\right)\left(z - e^{-i\theta_k}\right)
= \prod_{k=0}^{n-1}\left(z^2 - 2\cos\theta_k z + 1\right)
$$
What make life easier is all the roots of the denominator are simple. Given any two polynomials $p(z)$ and $q(z)$
with $\deg p < \deg q$. If all the roots $\lambda_1, \lambda_2, \ldots, \lambda_{\deg q}$ of $q(z)$ are simple, we can read off the partial fraction decomposition of their quotient easily:
$$\frac{p(z)}{q(z)} = \sum_{k=1}^{\deg q} \frac{p(\lambda_k)}{q'(\lambda_k)(z - \lambda_k)}$$
Apply this to our integrand and notice $e^{in\theta_k} = (-1)^k i$, we can simplify $\displaystyle\;\frac{n z^n}{1+z^{2n}}\;$ as
$$\begin{align}
& n \sum_{k=0}^{n-1} \left[
  \frac{ e^{in\theta_k} }{2n e^{i(2n-1)\theta_k} (z - e^{i\theta_k} ) }
+ \frac{ e^{-in\theta_k} }{2n e^{-i(2n-1)\theta_k} (z - e^{-i\theta_k} ) }
\right]\\
=&
\frac{1}{2i}\sum_{k=0}^{n-1} (-1)^k 
\left[
\frac{e^{i\theta_k}}{z-e^{i\theta_k}} - 
\frac{e^{-i\theta_k}}{z-e^{-i\theta_k}}
\right]\\
=& \sum_{k=0}^{n-1} (-1)^k\sin\theta_k \left( \frac{z}{z^2 - 2\cos\theta_k z + 1}\right)\\
=& \sum_{k=0}^{n-1} (-1)^k\left[ \sin\theta_k \left(\frac{z - \cos\theta_k}{z^2 - 2\cos\theta_k z + 1}\right) + \cos\theta_k\left(\frac{\sin\theta_k}{(z - \cos\theta_k)^2 + (\sin\theta_k)^2}\right)\right]
\end{align}$$
and evaluate the indefinite integral as
$$\sum_{k=0}^{n-1}(-1)^k\left[
\frac{\sin\theta_k}{2}
\log\left(z^2 - 2\cos\theta_k z + 1\right)
+ \cos\theta_k
\arctan\left(\frac{z - \cos\theta_k}{\sin\theta_k}\right)
\right] + \text{const.}
$$