Find all continuous functions $f(x)^2=x^2$ Find all functions $f$ which are continuous on $\mathbb R$ and which satisfy the equation $f(x)^2=x^2$ for all $x \in \mathbb R$. 
Clearly $f(x)=x, -x, |x|, -|x|$ all satisfy the condition. However, how can I show that these must be the only possible choices? The condition guarantees that $|f(x)|=|x|$, for all $x$ so I think it's quite obvious that these four choices are the only possibilities. But I don't see why continuity is necessary. If $f$ does not need to be continuous, are there other possibilities? Then how can I use continuity to guarantee that these are the only choices? 
 A: From $f(x)^2 = x^2$ follows "only" that $f(x) = x$ or $f(x) = -x$ for each $x \in \mathbb R$. Without the continuity requirement, you could choose from both
possibilities for each $x$ independently. For example, 
$f(x)=x$ if $x$ is rational and $f(x)=−x$ if $x$ is irrational.
So what you need to show is that either
$$
  f(x) = x \text{ for all } x > 0 
$$
or
$$
  f(x) = -x \text{ for all } x > 0 \, .
$$
and this follows from the continuity: If there were $x_1, x_2 > 0$ such that
$f(x_1) = x_1 > 0$ and $f(x_2) = -x_2 < 0$ then because of the Intermediate Value Theorem
there would be a $x_3 > 0$ such that $f(x_3) = 0$, contradicting
the requirement $f(x_3)^2 = x_3^2$.
For the same reason you have either
$$
  f(x) = x \text{ for all } x < 0 
$$
or
$$
  f(x) = -x \text{ for all } x < 0 \, .
$$
This gives the four possible functions $f(x)=x, -x, |x|, -|x|$.
A: As you mention, for any $x\in \mathbb{R}$, $f(x) = \pm x$. Let $S$ denote the set on which $f(x) = x$, and $T$ be the set where $f(x) = -x$, then $S$ and $T$ are both closed and $S\cap T = \{0\}$.
Suppose $0 < x\in S$, then $f(x) > 0$, so by continuity, $f$ must be positive on a neighbourhood of $x$. Since $f(y) = \pm y$ on that neighbourhood, it follows that $f(y) = y$. Hence, $S\setminus \{0\}$ is an open set. Similarly, $T\setminus\{0\}$ is an open set.
By connectedness of $(-\infty,0)$, it follows that either $(-\infty,0) \subset S$ or $(-\infty,0) \subset T$. Similarly, for $(0,\infty)$, which gives the four different possibilities.
