Let's say we have this integral:
\[\int \tan^n(x) \ dx \]
We can rewrite this as:
\[ \int \tan^{n-2}(x) \tan^2(x) \ dx \]
Since \(\tan^2(x) = \sec^2(x) - 1\):
\[ \int \tan^{n-2}(x) (\sec^2(x) - 1) \ dx = \int \tan^{n-2}(x) \sec^2(x) \ dx - \int \tan^{n-2}(x) \ dx \]
For now let's focus on just \(\int \tan^{n-2}(x) \sec^2(x) \ dx\). We can use integration by parts to evaluate this. Let \(u = \tan^{n-2}(x)\) and \(v = \tan(x)\):
\[ \begin{aligned} u=\tan^{n-2}(x) &\implies du = (n-2) \tan^{n-3}(x)\sec^2(x) \ dx \\ v = \tan(x) &\implies dv = \sec^2(x) \ dx \end{aligned} \]
This means:
\[\int \tan^{n-2}(x) \sec^2(x) \ dx = \tan^{n-1}(x) - \int (n-2) \tan^{n-2}(x)\sec^2(x) \ dx \]
Rearranging:
\[\int \tan^{n-2}(x) \sec^2(x) \ dx = \frac{1}{(n-1)} \tan^{n-1}(x) \]
Going back to our main integral:
\[\begin{aligned} \int \tan^{n-2}(x) (\sec^2(x) - 1) \ dx &= \int \tan^{n-2}(x) \sec^2(x) \ dx - \int \tan^{n-2}(x) \ dx \\ \int \tan^n(x) \ dx &= \frac{1}{(n-1)} \tan^{n-1}(x) - \int \tan^{n-2}(x) \ dx \end{aligned}\]