Why is $\cos(x/2)+2\sin(x/2)=\sqrt5 \sin(x/2+\tan^{-1}(1/2))$ true? According to Wolfram Alpha the following equality holds:
$$\cos\left(\frac{x}{2}\right)+2\sin\left(\frac{x}{2}\right)=\sqrt5 \sin\left(\frac{x}{2}+\tan^{-1}\left(\frac{1}{2}\right)\right)$$
I also checked it numerically. Why is it true?

Let us consider the general case $$A=a \sin(x)+b\cos(x)$$ Without changing anything, we can rewrite $$A=\sqrt{a^2+b^2}\Big(\frac{a}{\sqrt{a^2+b^2}} \sin(x)+\frac{b}{\sqrt{a^2+b^2}} \cos(x)\Big)$$ Now, let us define$$\frac{a}{\sqrt{a^2+b^2}}=\cos(\phi)$$ so $$\sin^2(\phi)=1-\cos^2(\phi)=1-\frac{a^2}{a^2+b^2}=\frac{b^2}{a^2+b^2}$$ and so $$\sin(\phi)=\frac{b}{\sqrt{a^2+b^2}}$$ Replacing in the initial expression, we then have $$A=\sqrt{a^2+b^2}\Big(\cos(\phi) \sin(x)+\sin(\phi)\cos(x)\Big)=\sqrt{a^2+b^2}\sin(x+\phi)$$ and from the definitions, you can notice that $$\tan(\phi)=\frac{\sin(\phi)}{\cos(\phi)}=\frac ba$$ which makes $$\phi=\tan^{-1}\big(\frac ba\big)$$
Similar things could be done defining instead $$\frac{a}{\sqrt{a^2+b^2}}=\sin(\theta)$$ which make $$\cos(\theta)=\frac{b}{\sqrt{a^2+b^2}}$$ and then $$A=\sqrt{a^2+b^2}\Big(\sin(\theta) \sin(x)+\cos(\theta)\cos(x)\Big)=\sqrt{a^2+b^2}\cos(x-\theta)$$
So basically, using this approach allows to transform $A$ as a sine or a cosine depending on what you need for the remaining of the work.
