Integral $\int \tan^{5}(x)\text{ d}x$ I would like guidance on evaluating
$$\displaystyle\int \tan^{5}(x)\text{ d}x\text{.}$$
I have attempted using the Pythagorean identities to get
$$\int\tan^{5}(x)\text{ d}x = \int \tan(x)\left[\sec^{2}(x)-1\right]^{2}\text{ d}x\text{.}$$
This doesn't look helpful. So I thought, why not turn only ONE of the $\tan^{2}$ terms to the $\sec^{2}-1$ form? This gives
$$\int\tan^{5}(x)\text{ d}x = \int\tan^{3}(x)\sec^{2}(x)\text{ d}x-\int \tan^{3}(x)\text{ d}x\text{.}$$
Clearly the second term is $\dfrac{\tan^{4}(x)}{4}$ (ignoring the constant term for now). Using a similar trick,
$$\begin{align}
\int\tan^{3}(x)\text{ d}x &= \int \tan(x)\sec^{2}(x)\text{ d}x-\int\tan(x)\text{ d}x \\
&= \dfrac{\tan^{2}(x)}{2} - (-1)\ln|\cos(x)| \\
&= \dfrac{\tan^{2}(x)}{2}+\ln|\cos(x)|\text{.}
\end{align}$$
So this suggests to me that 
$$\int\tan^{5}(x)\text{ d}x = \dfrac{\tan^{4}(x)}{4} - \dfrac{\tan^{2}(x)}{2}-\ln|\cos(x)| + C\text{.}$$
But the answer in Stewart (section 7.2., #31) is 
$$\dfrac{1}{4}\sec^{4}(x)-\tan^{2}(x)+\ln|\sec(x)|+C\text{.}$$
It's very clear where the $\ln|\sec(x)|$ term is coming from - and I tried to take the difference of my answer and Stewart's answer using Wolfram Alpha and unfortunately, the difference is not a constant.
Where did I go wrong?
 A: Short answer: the answers are equivalent, you have nothing to worry about. :)
Long answer:
\begin{align}
\frac{\tan^4 x}{4} - \frac{\tan^2 x}{2} &= \frac{\tan^4 x + 2\tan^2 x}{4} - \tan^2 x\\
&= \frac{\sec^4 x- 1}{4} - \tan^2 x\\
&= \frac{\sec^4x}{4} - \tan^2 x + C
\end{align}
A: Your answer is correct.  We have $\tan^2x=\sec^2x-1$ so $\tan^4x=\sec^4x-2\sec^2x+1$. Replacing your $\tan^4x$ accordingly gives $\frac14\sec^4x-\frac12\sec^2x+\frac14.$ Replacing that $\sec^2x$ with $\tan^2x+1$ results in Stewart's solution. The answers do differ by some constant though.
A: Here's the derivation of a formula that could be of some help to you. Let $n>1$ be an integer.
Consider the integral 
$$I_n=\int\tan^nx\ dx$$
$$I_n=\int\tan^{n-2}x\tan^2x\ dx$$
$$I_n=\int\tan^{n-2}x(\sec^2x-1)dx$$
$$I_n=\int\tan^{n-2}x\sec^2x\ dx-\int\tan^{n-2}x\ dx$$
$$I_n=\int\tan^{n-2}x\sec^2x\ dx-I_{n-2}$$
Substitution: $$u=\tan x\Rightarrow du=\sec^2x\ dx$$
$$\Rightarrow I_n=\int u^{n-2}du-I_{n-2}$$
$$I_n=\frac{u^{n-1}}{n-1}-I_{n-2}$$
$$I_n=\frac{\tan^{n-1}x}{n-1}-I_{n-2}$$
$$\int\tan^nx\ dx=\frac{\tan^{n-1}x}{n-1}-\int\tan^{n-2}x\ dx$$
A: $$z=\tan{x}\Rightarrow dz=(z^{2}+1)dx\\
z^{5}=(z^{2}+1)(z^{3}-z)+z\\
\displaystyle \int z^{5}dx=\int(z^{3}-z)dz+\int zdx=\frac{z^{4}}{4}-\frac{z^{2}}{2}+\int zdx  \\
\displaystyle \int \tan^{5}{x}dx=\frac{\tan^{4}{x}}{4}-\frac{\tan^{2}{x}}{2}-\ln\left| \cos{x} \right|+c$$
A: There is an easy way to evaluate $\int \sin^n(x)\cos^m(x)\,dx$ when at least one of $n,m$ is odd.  Say $n$ is odd.  Then keep one factor of $\sin$ and convert all the rest to $\cos$, and substitute $u=\cos x, du=-\sin x\,dx$.
Here is this case ($n=5,m=-5$):
\begin{align}
\int\tan^5 x\,dx &= \int \frac{\sin^5 x}{\cos^5 x}\,dx
= \int\frac{(\sin x)(\sin^2 x)^2}{\cos^5 x}\,dx
\\ &= \int\frac{(\sin x)(1-\cos^2 x)^2}{\cos^5 x}\,dx
= -\int \frac{(1-u^2)^2}{u^5}\,dx
\\ &= -\int\frac{du}{u}+2\int\frac{du}{u^3}-\int\frac{du}{u^5}
= -\log(u) -\frac{1}{u^2}+\frac{1}{4u^4}+C
\\ &=
-\log(\cos x) - \frac{1}{\cos^2 x}+\frac{1}{4\cos^4 x}+C
\end{align}
