How many functions $f$ are there that satisfy $f(x)^{2}=x^{2}$ for all $x$?
My text (Spivak's Calculus; chapter 7 problem 7) asks this question for continuous $f$, for which the answer is, of course 4:$$f(x)=x$$ $$f(x)=-x$$ $$f(x)=\lvert x \rvert$$ $$f(x)=-\lvert x \rvert,$$ and I want to make sure I'm correct that if $f$ does not have to be continuous, there are infinitely many: any piecwise combination of them (infinitely many of which are one of the above, and infinitely many of which are not).
You are correct. In fact there are $2^{2^\omega}=2^\mathfrak{c}$ such functions if they need not be continuous. For each $A\subseteq \mathbb{R}$ define $f_A$ as follows: $$f_A(x)=\begin{cases}x,&x\in A\\-x,&x\notin A\end{cases}$$ Then $f_A(x)^2=x^2$ for all $x\in\mathbb{R}$. It’s easy to see that if $A\setminus\{0\}\ne B\setminus\{0\}$, then $f_A\ne f_B$, so we have one such function for every subset of $\mathbb{R}\setminus\{0\}$. Finally, every function with the desired property is such a function: if $f(x)^2=x^2$ for all $x\in \mathbb{R}$, then $f=f_A$, where $A =$ $\{x\in\mathbb{R}:f(x)=x\}$.
If you limit yourself to piecewise continuous functions, there are only $2^\omega=\mathfrak{c}$ of them: there are $(2^\omega)^\omega=2^\omega$ ways to choose the partition points between the pieces, $2^\omega$ ways to choose $x$ or $-x$ on each interval, and $2^\omega$ ways to choose the values at the endpoints, for a total of $(2^\omega)^3=2^\omega$ functions.