Theorem: Primitive of x over Power of Cosine of a x

:$\ds \int \frac {x \rd x} {\cos^n a x} = \frac {x \sin a x} {a \paren {n - 1} \cos^{n - 1} a x} - \frac 1 {a^2 \paren {n - 1} \paren {n - 2} \cos^{n - 2} a x} + \frac {n - 2} {n - 1} \int \frac {\d x} {\cos^{n - 2} a x} + C$

Proof:
With a view to expressing the primitive in the form:
:$\ds \int u \frac {\d v} {\d x} \rd x = u v - \int v \frac {\d u} {\d x} \rd x$
let:
{{begin-eqn}}
{{eqn | l = u
      | r = \frac x {\cos^{n - 2} a x}
      | c = 
}}
{{eqn | r = x \cos^{- n + 2} a x
      | c = 
}}
{{eqn | ll= \leadsto
      | l = \frac {\d u} {\d x}
      | r = x \map {\frac \d {\d x} } {\cos^{-n + 2} a x} + \paren {\frac \d {\d x} x} \paren {\cos^{-n + 2} a x}
      | c = Product Rule for Derivatives
}}
{{eqn | r = -a x \paren {-n + 2} \cos^{-n + 1} a x \sin a x + \cos^{-n + 2} a x
      | c = Derivative of $\cos a x$, Derivative of Power, Chain Rule for Derivatives
}}
{{eqn | r = \frac {a x \paren {n - 2} \sin a x} {\cos^{n - 1} a x} + \cos^{-n + 2} a x
      | c = simplifying
}}
{{end-eqn}}
and let:
{{begin-eqn}}
{{eqn | l = \frac {\d v} {\d x}
      | r = \frac 1 {\cos^2 a x}
      | c = 
}}
{{eqn | r = \sec^2 a x
      | c = Secant is $\dfrac 1 \cos$
}}
{{eqn | ll= \leadsto
      | l = v
      | r = \frac {\tan a x} a
      | c = Primitive of $\sec^2 a x$
}}
{{end-eqn}}
Then:
{{begin-eqn}}
{{eqn | l = \int \frac {x \rd x} {\cos^n a x}
      | r = \paren {\frac x {\cos^{n - 2} a x} } \paren {\frac {\tan a x} a}
      | c = Integration by Parts
}}
{{eqn | o = 
      | ro= -
      | r = \int \paren {\frac {\tan a x} a} \paren {\frac {a x \paren {n - 2} \sin a x} {\cos^{n - 1} a x} + \cos^{- n + 2} a x} \rd x
      | c = 
}}
{{eqn | r = \frac {x \sin a x} {a \cos^{n - 1} a x} - \int \paren {\frac {x \paren {n - 2} \sin^2 a x} {\cos^n a x} -\frac {\sin a x} {a \cos^{n - 1} a x} } \rd x
      | c = simplifying
}}
{{eqn | r = \frac {x \sin a x} {a \cos^{n - 1} a x} - \paren {n - 2} \int \frac {x \sin^2 a x} {\cos^n a x} \rd x + \frac 1 a \int \frac {\sin a x}{\cos^{n - 1} a x} \rd x
      | c = Linear Combination of Primitives
}}
{{eqn | r = \frac {x \sin a x} {a \cos^{n - 1} a x}
      | c = 
}}
{{eqn | o = 
      | ro= -
      | r = \paren {n - 2} \int \frac {x \paren {1 - \cos^2 a x} } {\cos^n a x} \rd x
      | c = Sum of Squares of Sine and Cosine
}}
{{eqn | o = 
      | ro= +
      | r = \frac 1 a \paren {\frac {-1} {\paren {n - 2} \cos^{n - 2} a x} }
      | c = Primitive of $\cos^n a x \sin a x$
}}
{{eqn | r = \frac {x \sin a x} {a \cos^{n - 1} a x}
      | c = 
}}
{{eqn | o = 
      | ro= -
      | r = \paren {n - 2} \int \frac {x \rd x} {\cos^n a x} + \paren {n - 2} \int \frac {x \rd x} {\cos^{n - 2} a x}
      | c = Linear Combination of Primitives and simplifying
}}
{{eqn | o = 
      | ro= +
      | r = \frac 1 a \paren {\frac {-1} {\paren {n - 2} a \cos^{n - 2} a x} }
      | c = 
}}
{{end-eqn}}
This leads to:
{{begin-eqn}}
{{eqn | l = \paren {n - 1} \int \frac {x \rd x} {\cos^n a x}
      | r = \frac {x \sin a x} {a \cos^{n - 1} a x} + \paren {n - 2} \int \frac {x \rd x} {\cos^{n - 2} a x} - \frac 1 {a^2 \paren {n - 2} \cos^{n - 2} a x}
      | c = 
}}
{{eqn | ll= \leadsto
      | l = \int \frac {x \rd x} {\cos^n a x}
      | r = \frac {x \sin a x} {a \paren {n - 1} \cos^{n - 1} a x} - \frac 1 {a^2 \paren {n - 1} \paren {n - 2} \cos^{n - 2} a x} + \frac {n - 2} {n - 1} \int \frac {\d x} {\cos^{n - 2} a x} + C
      | c = 
}}
{{end-eqn}}
{{qed}}