<s>[INST] Why is $ \cos^{n+1}(x) - n\sin^2(x)\cos^{n-1}(x)$ equal to $\cos^{n-1}(x)((n+1)\cos^2(x) -n)$ In reading a correction for an exercice, I stumbled on a strange equality.
Suppose $x \in [0, \pi]$, let $f_n(x)= \cos^n(x)\sin(x)$, then the derivative is equal to: 

$$ \cos^{n+1}(x) - n\sin^2(x)\cos^{n-1}(x)=\cos^{n-1}(x)\left[(n+1)\cos^2(x) -n\right]$$

Could someone explain to me, how is the right part of the equation found? 
 [/INST] $$\begin{align}
\cos^{n+1}(x)-n\sin^2(x)\cos^{n-1}(x)&=\cos^2(x)\cos^{n-1}(x)-n\sin^2(x)\cos^{n-1}(x)\\
&=\cos^{n-1}(x)\bigl(\cos^2(x)-n\sin^2(x)\bigr)\\
&=\cos^{n-1}(x)\bigl(\cos^2(x)-n\sin^2(x)+n(\underbrace{\cos^2(x)+\sin^2(x)-1}_{=0})\bigr)\\
&=\cos^{n-1}(x)\bigl((n+1)\cos^2(x)-n\bigr)\\
\end{align} $$
Or
$$\begin{align}
\cos^{n+1}(x)-n\sin^2(x)\cos^{n-1}(x)&=\cos^{n+1}(x)-n(1-\cos^2(x))\cos^{n-1}(x)\\
&=\cos^{n+1}(x)-n\cos^{n-1}(x)+n\cos^{n+1}(x)\\
&=(n+1)\cos^{n+1}(x)-n\cos^{n-1}(x)\\
&=\cos^{n-1}(x)\bigl((n+1)\cos^2(x)-n\bigr)
\end{align} $$
</s>