With a view to expressing the primitive in the form: :$\displaystyle \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 {\cos^{m - 1} a x} {\sin^n a x}       | c =  }} {{eqn | ll= \leadsto       | l = \frac {\d u} {\d x}       | r = \frac {\sin^n a x \dfrac \d {\d x} \cos^{m - 1} a x - \cos^{m - 1} a x \dfrac \d {\d x} \sin^n a x} {\sin^{2 n} a x}       | c = Quotient Rule for Derivatives }} {{end-eqn}} Thus: {{begin-eqn}} {{eqn | l = \frac \d {\d x} \cos^{m - 1} a x       | r = a \paren {m - 1} \cos^{m - 2} a x \paren {-\sin a x}       | c = Derivative of $\cos a x$, Derivative of Power, Chain Rule for Derivatives }} {{eqn | r = -a \paren {m - 1} \cos^{m - 2} a x \sin a x       | c =  }} {{eqn | l = \frac \d {\d x} \sin^n a x       | r = a n \sin^{n - 1} a x \cos a x       | c = Derivative of $\sin a x$, Derivative of Power, Chain Rule for Derivatives }} {{end-eqn}} and so: {{begin-eqn}} {{eqn | l = \frac {\d u} {\d x}       | r = \frac {\sin^n a x \paren {-a \paren {m - 1} \cos^{m - 2} a x \sin a x} - \cos^{m - 1} a x \paren {a n \sin^{n - 1} a x \cos a x} } {\sin^{2 n} a x}       | c =  }} {{eqn | r = \frac {-a \paren {m - 1} \cos^{m - 2} a x \sin^2 a x + a n \cos^m a x} {\sin^{n + 1} a x}       | c = simplifying and cancelling $\sin^{n - 1}$ }} {{eqn | r = \frac {-a \cos^{m - 2} a x \paren {\paren {m - 1} \sin^2 a x + n \cos^2 a x} } {\sin^{n + 1} a x}       | c = factorising }} {{eqn | r = \frac {-a \cos^{m - 2} a x \paren {\paren {m - 1} \paren {1 - \cos^2 a x} + n \cos^2 a x} } {\sin^{n + 1} a x}       | c = Sum of Squares of Sine and Cosine }} {{eqn | r = \frac {-a \cos^{m - 2} a x \paren {\paren {n - m + 1} \cos^2 a x + \paren {m - 1} } } {\sin^{n + 1} a x}       | c = simplifying }} {{eqn | r = \frac {-a \paren {n - m + 1} \cos^m a x} {\sin^{n + 1} a x} + \frac {a \paren {m - 1} \cos^{m - 2} a x} {\sin^{n + 1} a x}       | c = separating }} {{end-eqn}} Then let: {{begin-eqn}} {{eqn | l = \frac {\d v} {\d x}       | r = \cos a x       | c =  }} {{eqn | ll= \leadsto       | l = v       | r = \frac {\sin a x} a       | c = Primitive of $\cos a x$ }} {{end-eqn}} Then: {{begin-eqn}} {{eqn | l = \int \frac {\cos^m a x} {\sin^n a x} \rd x       | r = \int \frac {\cos^{m - 1} a x} {\sin^n a x} \cos^a x \rd x        | c =  }} {{eqn | r = \paren {\frac {\cos^{m - 1} a x} {\sin^n a x} } \paren {\frac {\sin a x} a}       | c = Integration by Parts }} {{eqn | o =        | ro= -       | r = \int \paren {\frac {\sin a x} a} \paren {\frac {-a \paren {n - m + 1} \cos^m a x} {\sin^{n + 1} a x} + \frac {a \paren {m - 1} \cos^{m - 2} a x} {\sin^{n + 1} a x} } \rd x + C       | c =  }} {{eqn | r = \frac {\cos^{m - 1} a x} {a \sin^{n - 1} a x}       | c =  }} {{eqn | o =        | ro= +       | r = \paren {n - m + 1} \int \frac {\cos^m a x} {\sin^n a x} \rd x       | c = Linear Combination of Integrals }} {{eqn | o =        | ro= +       | r = \paren {m - 1} \int \frac {\cos^{m - 2} a x} {\sin^n a x} \rd x + C       | c =  }} {{end-eqn}} {{begin-eqn}} {{eqn | ll= \leadsto       | l = \paren {1 - \paren {n - m + 1} } \int \frac {\cos^m a x} {\sin^n a x} \rd x       | r = \frac {\cos^{m - 1} a x} {a \sin^{n - 1} a x} + \paren {m - 1} \int \frac {\cos^{m - 2} a x} {\sin^n a x} \rd x + C       | c =  }} {{eqn | ll= \leadsto       | l = \paren {m - n} \int \frac {\cos^m a x} {\sin^n a x} \rd x       | r = \frac {\cos^{m - 1} a x} {a \sin^{n - 1} a x} + \paren {m - 1} \int \frac {\cos^{m - 2} a x} {\sin^n a x} \rd x + C       | c =  }} {{eqn | ll= \leadsto       | l = \int \frac {\cos^m a x} {\sin^n a x} \rd x       | r = \frac {\cos^{m - 1} a x} {a \paren {m - n} \sin^{n - 1} a x} + \frac {m - 1} {m - n} \int \frac {\cos^{m - 2} a x} {\sin^n a x} \rd x + C       | c =  }} {{end-eqn}} {{qed}}