Solutions of sin(x) = cos(x) I know that the solutions to the equation $\sin(x) = \cos(x)$ are :
$ x= \frac{\pi}{4}$  (45°) ; $ x= \frac{5 \pi}{4}$ (225°)
However when I try to solve it algebraically I get the following :
$$  \sin x = \cos x$$
$$  \sin^2 x = \cos^2 x$$
$$  \sin^2 = 1 - \sin^2 x$$
$$  2\sin^2 x = 1$$
$$  sin^2 x = \frac{1}{2}$$
$$ \sqrt {sin^2 x} = \sqrt{\frac{1}{2}}$$
$$ \sqrt {sin^2 x} = \sqrt{\frac{1}{2}}$$
$$ \sin x= \lvert\frac{1}{\sqrt2}\rvert$$
$$ \sin x= \frac{\sqrt2}{2}  ;  \sin x= -\frac{\sqrt2}{2}$$
So if I look for all the values of $x$ that solve the above I should get not only $ x= \frac{\pi}{4}$  (45°) ; $ x= \frac{5 \pi}{4}$ (225°) but also $ x= \frac{3\pi}{4}$  (135°) ; $ x= \frac{7 \pi}{4}$ (315°).
What am I doing wrong?
 A: The issue :
when you write out $\sin x = \cos x$ implies $\sin^2 x = \cos^2  x$, there is no problem with the implication. However, an implication leads to a weaker statement, which may admit "extraneous" solutions. For example, the above implication is got by multiplying by squaring both sides, but then that ends up including the case when $\sin x = -\cos x$.
Therefore you need to ensure that your implications are both ways, so that the solutions of both equations are retained, or you have to eliminate extraneous solutions once you reach the end.
The two extraneous solutions  $\frac{3\pi}4 , \frac{7\pi}4$ obtained are of the equation $\sin x = -\cos x$, which got included as solutions of the equation $\sin^2 x = \cos^2 x$ when you moved to this statement from the one you were given.
A: A better alternative would be to do the following: $$\begin{aligned}\sin x&=\cos x\\\tan x&=1\\x&=\arctan 1\\ x&=\dfrac{\pi}{4}+\pi n, n\in \mathbb{Z}\end{aligned}$$
A: The problem is a pretty generic one. By squaring both sides of the equation earlier on, you introduced extraneous solutions. It's sort of like how in solving the equation
$$x+\sqrt{x+9} = 2$$
you can get to
$$\sqrt{x+9} = 2-x$$
and then square both sides to get
$$x+9 = 4 - 4x + x^2 \implies x^2 - 5x - 5 = 0$$
You should get
$$x = \frac{5 \pm 3\sqrt 5}{2}$$
Not the cleanest expression, but you'll notice that, if you substitute the positive root into the original equation, it won't work, though the negative root does. This applies beyond the context of polynomials. For example, if we have
$$x = x$$
we can square and get
$$x^2 = x^2$$
Obvious, right? But a problem: if you wanted to work backward, how would you know whether either is positive or negative? After all, $x^2 = (-x)^2$ in the usual arithmetic. Same problem here: 
$$(\sin(x))^2 = (-\sin(x))^2 = (\cos(x))^2 = (-\cos(x))^2$$
Extra solutions galore. 

This doesn't make your method of solution invalid, necessarily, but you have to be conscious of extraneous solutions, and always substitute each solution back in to check its validity. In fact, substituting both $x=3\pi/4$ and $x = 7\pi/4$ into the original equation, you should notice that the two differ by $\sqrt 2$ and $-\sqrt 2$, respectively, so you don't have equality in those cases!
A: $\cos x=\sin x=\cos\left(\frac{\pi}{2}-x\right)$ thus $x=\frac{\pi}{2}-x \bmod [2\pi]$ or $x=-\frac{\pi}{2}+x \bmod [2\pi]$. The first equation has $\pi/4$ as solution and the second does not provide a solution.
