Calculating $\cos\frac\pi4$ from the half-angle formula gives $\sqrt{\frac12}$ instead of $\frac{\sqrt{2}}2$. What went wrong? I am using the formula $$\cos\left(\frac x2\right)=\sqrt{\frac{1+\cos(x)}2}$$ to find $\cos\left(\frac{pi}{4}\right)$ but it does not give me the correct result.
$$
\cos\left(\frac{\pi}{4}\right)
= \sqrt{\frac{1+\cos\left(\frac{\pi}{2}\right)}2}
= \sqrt{\frac{1+0}2}
= \sqrt{\frac12}
$$
This contradicts $\cos\left(\frac{\pi}{4}\right) = \frac{\sqrt{2}}{2} $. What did I do wrong?

$\sqrt {\frac 12} = \frac{\sqrt 1} {\sqrt 2} = \frac 1 {\sqrt 2} =  \frac {\sqrt 2} {\sqrt 2 \cdot \sqrt 2} =  \frac {\sqrt 2} {2} $
This process is called 'rationalising the denominator' and you should try to do this when the denominator is an algebraic irrational number.
