TITLE: How to solve $f(f(x)) = x$?
QUESTION [7 upvotes]: Seems simple enough, but I have no idea how one would get all solutions to this. Wolfram Alpha gives $5$ answers, the first $2$ of which I could get myself, but the following $3$ completely defeat me.

REPLY [8 votes]: If you want a continuous solution:

Draw a graph of $y=x$ (this is an auxiliary construction, you will erase it later).
Starting at any point on the graph, draw a freehand graph of a decreasing function.
Draw the reflection of that graph with respect to the line $y=x$.
Erase the line $y=x$. What remains is the graph of your function.

If you want just any solution:

Select two arbitrary non-intersecting equinumerous sets $A,B\in\mathbb R$. (They can be empty, or finite, or countably infinite, or uncountably infinite; that doesn't matter.)
Select any bijection $A\leftrightarrow B$.
For any $x\in A$, let $f(x)$ be the image of $x$ in $B$ under that bijection, and vice versa.
For any $x\in\mathbb R\setminus(A\cup B)$, let $f(x)=x$.