Find a real function $f:\mathbb{R}\to\mathbb{R}$ such that $f(f(x)) = -x$?
An important piece of information is:
Theorem: $f$ is not continuous.
Proof: Observe that $f$ is invertible, because
$$f(f(f(f(x)))) = f(f(-x)) = x$$
and so $f \circ f \circ f = f^{-1}$. Any continuous invertible function on $\mathbb{R}$ is either strictly increasing or strictly decreasing.
If $f$ is strictly increasing, then:
- $1 < 2$
- $f(1) < f(2)$
- $f(f(1)) < f(f(2))$
- $-1 < -2$
contradiction! Similarly, if $f$ is strictly decreasing, then:
- $1 < 2$
- $f(1) > f(2)$
- $f(f(1)) < f(f(2))$
- $-1 < -2$
contradiction! Therefore, we conclude $f$ is not continuous. $\square$
For the sake of completeness, the entire solution space for $f$ consists of functions defined as follows:
- Partition the set of all positive real numbers into ordered pairs $(a,b)$
- Define $f$ by, whenever $(a,b)$ is one of our chosen pairs,
- $f(0) = 0$
- $f(a) = b$
- $f(b) = -a$
- $f(-a) = -b$
- $f(-b) = a$
To see that every solution is of this form, let $f$ be a solution. Then we must have $f(0) = 0$ because:
- Let $f(0) = a$. Then $f(a) = f(f(0)) = 0$ but $-a = f(f(a)) = f(0) = a$, and so $f(0) = 0$
If $a \neq 0$, then let $f(a) = b$. We have:
- $f(b) = f(f(a)) = -a$
- $f(-a) = f(f(b)) = -b$
- $f(-b) = f(f(-a)) = a$
From here it's easy to see the set $\{ (a,f(a)) \mid a>0, f(a)>0 \}$ partitions the positive real numbers and so is of the form I describe above.
One particular solution is
$$ f(x) = \begin{cases} 0 & x = 0 \\ x+1 & x > 0 \wedge \lceil x \rceil \text{ is odd} \\ 1-x & x > 0 \wedge \lceil x \rceil \text{ is even} \\ x-1 & x < 0 \wedge \lfloor x \rfloor \text{ is odd} \\ -1-x & x < 0 \wedge \lfloor x \rfloor \text{ is even} \end{cases}$$
e.g. $f(1/2) = 3/2$, $f(3/2) = -1/2$, $f(-1/2) = -3/2$, and $f(-3/2) = 1/2$.
(This works out to be Jyrki Lahtonen's example)
Here is a graph of one such function, piecewise continuous.
Here's another picture to clarify endpoint behavior.
Hint: If all the real numbers in existence were $1,2,-1,-2$, then the function $f: 1\mapsto 2\mapsto -1\mapsto-2\mapsto 1$ would work.
Spoiler:
Similarly permute $t,1+t,-t,-1-t$ for all $t\in(2n,2n+1]$ and for all natural numbers $n$. Handle $x=0$ separately.