Trig identity question relating to maximum value on an interval: $\max |\sin nx-\cos nx| = \sqrt2\max |\sin(nx-\frac\pi2)|$ Can somebody please tell me what is happening here? 
$$\max_{[a,b]} |\sin nx-\cos nx| = \sqrt2\max_{[a,b]} |\sin(nx-\frac\pi2)|$$

This is probably something super simple, but I just don't see where the $\sqrt{2}$ is coming from.  Thank you!  
 A: Generally speaking, you can always rewrite a sum of such functions as follows. This is a useful trick, so you should memorize what's going on.
$$A\sin t + B\cos t = \sqrt{A^2+B^2}\left(\underbrace{\tfrac{A}{\sqrt{A^2+B^2}}}_{\cos u\textrm{ for some }u}\sin  t + \underbrace{\tfrac{B}{\sqrt{A^2+B^2}}}_{\sin u\textrm{ for some }u}\cos t\right)$$
$$=\sqrt{A^2+B^2}\left(\sin t \cos u + \cos t\sin u\right)$$
$$= \sqrt{A^2+B^2}\sin( t + u)$$
where $u$ is an appropriate value of $\arctan\tfrac BA$. Note that it is possible to choose a $u$ with
$\cos u = \frac{A}{\sqrt{A^2+B^2}}$ and
$\sin u = \frac{B}{\sqrt{A^2+B^2}}$ because
$$\left(\frac{A}{\sqrt{A^2+B^2}}\right)^2 + \left(\frac{B}{\sqrt{A^2+B^2}}\right)^2 = 1$$ so the point $(\frac{A}{\sqrt{A^2+B^2}},\frac{B}{\sqrt{A^2+B^2}})$ lies on the unit circle.
In your case, $A=1$ and $B=-1$ so it is easy to see you can choose $u=-\frac{\pi}{4}$ (also, your $t=nx$, but that doesn't affect the computation).
A: Observe that
$$\sin(a-b)=\sin a\cos b-\sin b\cos a\implies \sin\left(x-\frac\pi4\right)=\sin\cos\frac\pi4-\sin\frac\pi4\cos x=$$
$$=\frac1{\sqrt2}\left(\sin x-\cos x\right)$$
A: It's just $\sin x-\cos x=\sqrt 2\sin(x-\pi/4)$.
