Evaluate $\int \frac{\tan^3x+\tan x}{\tan^3x+3 \tan^2x+2 \tan x+6} dx$ $$\int \frac{\tan^3x+\tan x}{\tan^3x+3 \tan^2x+2 \tan x+6} dx$$
My approaches so far has been using substitution with $\tan x = t$ and $\tan \frac x2 = t$ but the calculations has been harder than I think they should.
I've also tried using ordinary polynom integration to simplify the integral but I'm having problems with factorizing the denominator.
 A: $$\int \frac{\tan^3x+\tan x}{\tan^3x+3 \tan^2x+2 \tan x+6} dx$$
$$\int \frac{\tan x(\tan^2(x)+1)}{\tan^3x+3 \tan^2x+2 \tan x+6} dx$$
$$\int \frac{\tan x(\sec^2(x))}{\tan^3x+3 \tan^2x+2 \tan x+6} dx$$
Frome here, let $u=\tan(x)$, $\dfrac{du}{dx} = \sec^2(x)$., thus,
$$\int \frac{u}{u^3 + 3u^2 + 2u + 6}$$
From there, use partial fractions.
A: Choose $t=\tan x$ and then $dt=(1+\tan^2x)dx$. 
So your integral is:
$$\int \frac{t}{t^3+3 t^2+2 t+6} dt=\int \frac{t}{(t+3)(t^2+2)} dt.$$
We have:
$$\frac{1}{(t+3)(t^2+2)}=\frac{At+B}{t^2+2}+\frac{C}{t+3}=\frac{(A+C)t^2+(3A+B)t+(3B+2C)}{(t+3)(t^2+2)}.$$
We easily get: $A=-C=-\dfrac{1}{11}$ and $B=\dfrac{3}{11}$.
Therefore:
$$\begin{equation}\begin{split}\int \frac{t}{t^3+3 t^2+2 t+6} dt&=\dfrac{1}{11}\int t\left(\frac{3-t}{t^2+2}+\frac{1}{t+3} \right)dt,\\&=\dfrac{1}{11}\int \frac{3t-t^2}{t^2+2}+\frac{t}{t+3}dt\\&=\dfrac{1}{11}\int \frac{3t-t^2}{t^2+2}dt+\dfrac{1}{11}\int\frac{t}{t+3}dt\\&=-\dfrac{1}{11}\int \frac{-3t+t^2+2-2}{t^2+2}dt+\dfrac{1}{11}\int\frac{t+3-3}{t+3}dt\\&=\cdots\end{split}\end{equation}$$
A: Given
$$
\int \frac{\tan^3(x) + \tan(x)}{\tan^3(x) + 3\tan^2(x) + 2\tan(x)+6} dx.
$$

Consider the substitution
$$
\boxed{\color{red}{\tan(x) = \sqrt{2} \tan(y)}},
$$
so
$$
\Big( \tan^2(x) + 1 \Big) dx = \sqrt{2} \Big( \tan^2(y) + 1 \Big) dy.
$$
so we obtain
$$
\begin{eqnarray}
\int \frac{\tan^3(x) + \tan(x)}{\tan^3(x) + 3\tan^2(x) + 2\tan(x)+6} dx
&=& \int \frac{\tan(x) \Big( \tan^2(x) + 1 \Big)}
{ \Big( \tan(x) + 3 \Big) \Big( \tan^2(x) + 2 \Big) } dx\\
&=& \color{blue}{\int \frac{ \tan(y)}{ \sqrt{2} \tan(y) + 3 } dy}.
\end{eqnarray}
$$

Now
$$
\begin{eqnarray}
\int \frac{ \sqrt{2} -  3 \tan(y)}{ \sqrt{2} \tan(y) + 3 } dy
&=& \int \frac{ \sqrt{2} \cos(y) - 3 \sin(y) }{ \sqrt{2} \sin(y) + 3 \cos(y) } dy\\
&=& \int \frac{1}{ \sqrt{2} \sin(y) + 3 \cos(y) }
  d \Big( \sqrt{2} \sin(y) + 3 \cos(y) \Big)\\
&=& \ln\Big( \sqrt{2} \sin(y) + 3 \cos(y) \Big),
\end{eqnarray}
$$
and
$$
\begin{eqnarray}
\int \frac{ \sqrt{2} \tan(y) + 3}{ \sqrt{2} \tan(y) + 3 } dy &=& y.
\end{eqnarray}
$$

We also have
$$
\begin{eqnarray}
\frac{\sqrt{2}}{11} \frac{ \sqrt{2} \tan(y) + 3}{ \sqrt{2} \tan(y) + 3 }
  - \frac{3}{11} \frac{ \sqrt{2} - 3 \tan(y)}{ \sqrt{2} \tan(y) + 3 } &=&
\frac{\tan(y)}{ \sqrt{2} \tan(y) + 3}.
\end{eqnarray}
$$

So we obtain
$$
\begin{eqnarray}
\color{blue}{\int \frac{\tan(y)}{ \sqrt{2} \tan(y) + 3} dy}
&=& \color{darkgreen}{\frac{\sqrt{2}}{11} y - \frac{3}{11} \ln\Big( \sqrt{2} \sin(y) + 3 \cos(y) \Big)}.
\end{eqnarray}
$$

The final result is
$$
\int \frac{\tan^3(x) + \tan(x)}{\tan^3(x) + 3\tan^2(x) + 2\tan(x)+6} dx
= \color{darkgreen}{\frac{\sqrt{2}}{11} y - \frac{3}{11} \ln\Big( \sqrt{2} \sin(y) + 3 \cos(y) \Big)},
$$
where
$$
\color{red}{y = \arctan\left( \frac{ \tan(x) }{ \sqrt{2} } \right)}.
$$

Using the properties
$$
\begin{eqnarray}
\sin(\arctan(z)) &=& \frac{z}{\sqrt{1+z^2}},\\
\cos(\arctan(z)) &=& \frac{1}{\sqrt{1+z^2}},\\
\end{eqnarray}
$$
we obtain
$$
\boxed{
\begin{eqnarray}
\int \frac{\tan^3(x) + \tan(x)}{\tan^3(x) + 3\tan^2(x) + 2\tan(x)+6} dx
&=& \frac{\sqrt{2}}{11} \arctan\left( \frac{\tan(x)}{\sqrt{2}} \right)\\
&& \hspace{1em}
 + \frac{3}{11} \ln\left( \frac{ \tan(x) + 3 }{\sqrt{ 1 + \tan^2(x)/2 }} \right).
\end{eqnarray}}
$$
