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

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

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 {\sin^{n - 2} a x}
      | c = 
}}
{{eqn | r = x \sin^{-n + 2} a x
      | c = 
}}
{{eqn | ll= \leadsto
      | l = \frac {\d u} {\d x}
      | r = x \map {\frac {\d} {\d x} } {\sin^{-n + 2} a x} + \paren {\frac {\d} {\d x} x} \paren {\sin^{-n + 2} a x}
      | c = Product Rule for Derivatives
}}
{{eqn | r = a x \paren {-n + 2} \sin^{-n + 1} a x \cos a x + \sin^{-n + 2} a x
      | c = Derivative of $\sin a x$, Derivative of Power, Chain Rule for Derivatives
}}
{{eqn | r = \frac {-a x \paren {n - 2} \cos a x} {\sin^{n - 1} a x} + \frac 1 {\sin^{n - 2} a x}
      | c = simplifying
}}
{{end-eqn}}
and let:
{{begin-eqn}}
{{eqn | l = \frac {\d v} {\d x}
      | r = \frac 1 {\sin^2 a x}
      | c = 
}}
{{eqn | r = \csc^2 a x
      | c = Cosecant is $\dfrac 1 \sin$
}}
{{eqn | ll= \leadsto
      | l = v
      | r = \frac {-\cot a x} a
      | c = Primitive of $\csc^2 a x$
}}
{{end-eqn}}
Then:
{{begin-eqn}}
{{eqn | l = \int \frac {x \d x} {\sin^n a x}
      | r = \paren {\frac x {\sin^{n - 2} a x} } \paren {\frac {-\cot a x} a}
      | c = Integration by Parts
}}
{{eqn | o = 
      | ro= -
      | r = \int \paren {\frac {-\cot a x} a} \paren {\frac {-a x \paren {n - 2} \cos a x} {\sin^{n - 1} a x} + \frac 1 {\sin^{n - 2} a x} } \rd x
      | c = 
}}
{{eqn | r = \frac {-x \cos a x} {a \sin^{n - 1} a x} - \int \paren {\frac {x \paren {n - 2} \cos^2 a x} {\sin^n a x} - \frac {\cos a x} {a \sin^{n - 1} a x} } \rd x
      | c = simplifying
}}
{{eqn | r = \frac {-x \cos a x} {a \sin^{n - 1} a x} - \paren {n - 2} \int \frac {x \cos^2 a x} {\sin^n a x} \rd x + \frac 1 a \int \frac {\cos a x} {\sin^{n - 1} a x} \rd x
      | c = Linear Combination of Primitives
}}
{{eqn | r = \frac {-x \cos a x} {a \sin^{n - 1} a x}
      | c = 
}}
{{eqn | o = 
      | ro= -
      | r = \paren {n - 2} \int \frac {x \paren {1 - \sin^2 a x} } {\sin^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} a \sin^{n - 2} a x} }
      | c = Primitive of $\sin^n a x \cos a x$
}}
{{eqn | r = \frac {-x \cos a x} {a \sin^{n - 1} a x}
      | c = 
}}
{{eqn | o = 
      | ro= -
      | r = \paren {n - 2} \int \frac {x \rd x} {\sin^n a x} + \paren {n - 2} \int \frac {x \rd x} {\sin^{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 \sin^{n - 2} a x} }
      | c = 
}}
{{end-eqn}}
This leads to:
{{begin-eqn}}
{{eqn | l = \paren {n - 1} \int \frac {x \rd x} {\sin^n a x}
      | r = \frac {-x \cos a x} {a \sin^{n - 1} a x} + \paren {n - 2} \int \frac {x \rd x} {\sin^{n - 2} a x} - \frac 1 {a^2 \paren {n - 2} \sin^{n - 2} a x}
      | c = 
}}
{{eqn | ll= \leadsto
      | l = \int \frac {x \rd x} {\sin^n a x}
      | r = \frac {-x \cos a x} {a \paren {n - 1} \sin^{n - 1} a x} - \frac 1 {a^2 \paren {n - 1} \paren {n - 2} \sin^{n - 2} a x} + \frac {n - 2} {n - 1} \int \frac {x \rd x} {\sin^{n - 2} a x}
      | c = 
}}
{{end-eqn}}
{{qed}}