For how many functions $f$ is $f(x)^{2}=x^{2}$?
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).
Solution 1:
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.
Solution 2:
If $f$ doesn't have to be continuous, you can just choose $f(x)$ to be $|x|$ or $-|x|$ arbitrarily at each $x$, so there are lots of possibilities for $f$ (most of which I would not describe as "piecewise" combinations of the 4 continuous solutions).
Solution 3:
Let $s$ be an arbitrary function $\mathbb{R}\to\{-1,+1\}$. Then $f=s\cdot\mathrm{id}$ satisfies the property: $(s(x)x)^2=x^2$. Indeed, this exhausts all possible functions, as $s$ can be constructed by looking at $x/f(x)$ (and making an arbitrary choice when $x=0$).
There are uncountably many of these functions, in fact $2^\mathfrak{c}$ where $\mathfrak{c}=2^{\aleph_0}$ is the cardinality of the continuum.