<s>[INST] Reduction formula for $\int x\tan^n(x)$ So I've been trying to derive a reduction formula for the following integral
$$\int x\tan^n(x)dx$$
I tried to use integration by parts by factoring out a $\tan^2(x)$ and taking the following:
$$u=x\tan^{n-2}(x)\implies du=\tan^{n-2}(x)+(n-2)x\tan^{n-3}(x)\sec^2(x)dx\\
dv=\tan^2(x)dx=(\sec^2(x)-1)dx\implies v=\tan(x)-x$$
which then gives
$$I_n=x\tan^{n-1}(x)-x^2\tan^{n-2}(x)-\int\left[\tan^{n-1}(x)+(n-3)x\tan^{n-2}(x)+(n-2)x\tan^n(x)\\-(n-2)x^2\tan^{n-3}(x)\sec^2(x)\right]dx\\
\implies(n-1)I_n=x\tan^{n-1}(x)-x^2\tan^{n-2}(x)-\int\tan^{n-1}(x)dx-(n-3)\int x\tan^{n-2}(x)dx\\+(n-2)\int x^2\tan^{n-3}(x)\sec^2(x)dx$$
The final integral evaluates to
$$\int x^2\tan^{n-3}(x)\sec^2(x)dx=\frac{1}{n-2}\left(x^2\tan^{n-2}(x)-2\int x\tan^{n-2}(x)dx\right)$$
so we end up with
$$(n-1)I_n=x\tan^{n-1}(x)-x^2\tan^{n-2}(x)-\int\tan^{n-1}(x)dx-(n-3)\int x\tan^{n-2}(x)dx\\+x^2\tan^{n-2}(x)-2\int x\tan^{n-2}(x)dx\\
\implies(n-1)I_n=x\tan^{n-1}(x)-\int\tan^{n-1}(x)dx-(n-1)\int x\tan^{n-2}(x)dx\\
=x\tan^{n-1}(x)-\int\tan^{n-1}(x)dx-(n-1)I_{n-2}$$
But this isn't entirely a reduction formula given that I'm unable to deal with the $\int\tan^{n-1}(x)dx$ term. Any help?
 [/INST] $$\begin{split}
I_{n+2} +I_n &= \int x \tan^n (x) (1+\tan^2 x)dx \\
&= \frac 1 {n+1}x \tan^{n+1}(x)-\frac 1 {n+1}\underbrace{\int \tan^n x dx}_{J_n} &\,\,\,\,\,\,\,\,(1)
\end{split}$$
where the last line comes by integrating by parts.
Now
$$\begin{split}
J_{n+2}+J_n &= \int \tan^n (x)(1+\tan^2x) dx\\
&= \frac 1 {n+1}\tan^{n+1}x
\end{split}$$
The above implies that
$$J_n = \frac{\tan^{n-1}x}{n-1}-J_{n-2}=\frac{\tan^{n-1}x}{n-1}-\left(\frac{\tan^{n-3}x}{n-3}-J_{n-4}\right)=...$$
In other words, using the fact that $J_0=x$ and $J_1=-\ln \cos x$,
$$\left\{
\begin{split}
J_{2p}&=\sum_{k=0}^{p-1} \frac{(-1)^k \tan^{2p-2k-1}x}{2p-2k-1}+(-1)^px\\
J_{2p+1}&=\sum_{k=0}^{p-1} \frac{(-1)^k \tan^{2p-2k}x}{2p-2k}+(-1)^{p+1}\ln\cos x
\end{split}
\right.
$$
With that done, we can go back to $I_n$. Equation $(1)$ can be rewritten as
$$I_n = \frac{x\tan^{n+1}x}{n+1} -\frac{J_n}{n+1}-I_{n-2}$$
Following a similar path as for the $J_n$'s, one can find expressions for $I_{2p}$ and $I_{2p+1}$ as a function of the $J_n$'s, as well as $I_0$ and $I_1$. The result is a bit ugly, especially for odd indices since $I_1$ involves a dilogarithm.
</s>