I've been solving a question,
If $\cos(x) + \sin(x)=\sqrt{2} \cos(\pi/2 - x)$ then find the value of $x$.
We know that $\cos(x) + \sin(x)= \sqrt{2} \sin(\pi/4 + x)$. So, $$\sin(\pi/4 + x) = \cos(\pi/2 - x)$$ But $\cos(\pi/2 - x) = \sin x$, so we must have $$\sin(\pi/4 + x)=\sin(x).$$ Now if I change $\sin(x)$ to $\sin(\pi - x)$ then the correct answer will come, i.e. $$\sin(\pi/4 + x)=\sin(\pi - x) \implies \pi/4 + x = \pi -x \implies x=3\pi/8.$$ But why is $\pi/4 + x=x$ not true. My book says, if $\sin(x)=\sin(y)$ then $ x = (-1)^ny + n\pi $. If I put $n=0$ then $x=y$ but this is not true in my case. Why?
I also looked on the relevant Wikipedia article but could not understand why these formulas are true for any value of $\theta$ that may be more that $\pi/2$ and less than $0$.
Yes, that means if $\sin(x)=\sin(y)$, then there exists some $n$ such that $ x = (-1)^ny + n\pi $, not that you get to choose which $n$, or that the statement is true for every $n$. For example, $$\sin(0)=0=\sin(7\pi)$$ and we do indeed have that $0=(-1)^{n}\pi+n\pi$ for $n=7$, but that is the only $n$ that works.
More generally, you should be aware that most functions do not have the property that $f(x_1)=f(x_2)\implies x_1=x_2$. Take a look at the Wikipedia page on injective functions.