# 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).

-

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.

-
@Jonas: Yep, that was sloppy of me; fixed. Thanks. – Brian M. Scott Sep 15 '11 at 4:37
@Brian: Excellent, thanks! There is some notation I'm not familiar with ($\omega$?) and other's I'm guessing at ($\setminus$) but I get the gist and this fully answers my question. – raxacoricofallapatorius Sep 15 '11 at 13:21
@raxacoricofallapatorius: $\omega$ is the smallest infinite cardinal number; you may know it under the alias $\aleph_0$. $A\setminus B$ is the set of things that are in $A$ but not $B$; in older and elementary texts it’s often written $A-B$. $\mathbb{R}\setminus\{0\}$ is the set of all non-zero real numbers. – Brian M. Scott Sep 15 '11 at 17:39
It's really only $2^{2^\omega-1}$, since the apparent choice is illusory in the case of $x=0$. – MJD Oct 8 '12 at 17:50

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).

-
This is pretty much the answer I was looking for (it's exactly "my level") and I'd love to vote it the answer, but Brian's ended up being more complete and the one that's probably most widely useful. Thanks! – raxacoricofallapatorius Sep 15 '11 at 13:23

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.

-