I'm familiar with the concept of an involution. For example, two simple single-variable functions are $f(x) = 1-x$ and $g(x) = 1/x$. If we apply the function twice, we get back to the identity operation: $$f(f(x)) = x,\quad g(g(x)) = x.$$
I'm curious if there are multi-step extensions of this, and how one might go about constructing higher-order involutions. For example, $f(f(f(x))) = x$, where the values $x$, $f(x)$ and $f(f(x))$ are all distinct. I guess what I'm asking for is how to find functions over a subset of the reals that give a cycle of values (so not simply permutations on a vector, which would serve as an example over a finite set).
For order three, there aren't any such functions when you look at the whole $\mathbb{R}$. This is a consequence of Sharkovskii's theorem: if you have a point of period three, ie. $x$ such that $f(f(f(x)))=x$ and $f(x)$, $f(f(x))$ are not $x$, then you have points of all periods. This is a really strong theorem, but in particular it implies existence of $y$ such that $f(f(y))=y$ and $f(y) \neq y$, which means $f(f(f(y))) \neq y$.
Actually that theorem is even stronger than I mentioned: it states that if we have a point of period $m$, then we have a point of period $n$, whenever $n$ appears after $m$ in this peculiar sequence:
$$ 3,5,7,\ldots, 6,10,14,\ldots,12,20,28,\ldots,\ldots,16,8,4,2,1. $$
This is not exactly what you asked for, but this theorem is worth mentioning whenever possible.
After we allow us to restrict ourselves to a subset of $\mathbb{R}$, the situation becomes easier. Or, alternatively, we can look at a superset of $\mathbb{R}$.
To see what I mean, let's return to your example of $g(x) = \frac{1}{x}$. Then $g(0)$ is not quite defined, but let us write $g(0) = \infty$ and $g(\infty) = 0$. Our infinity represents here neither $+ \infty$ nor $-\infty$, but somehow both of them at the same time. Now $g$ is defined everywhere in a continuous way.
We can imagine our set $\mathbb{R} \cup \{ \infty\}$ as the line, whose endpoints were glued together – in other words, a circle. This can be made precise by the notion of a stereographic projection: if you draw a line $y=0$ and the circle $C$ with diameter $(0,0)$, $(0,1)$, then we have a map from $\mathbb{R} \cup \{\infty\}$ to $C$ given by mapping $t$ to the intersection of line through $(t,0)$ and $(0,1)$ with $C$, if $t$ is finite, and $(0,1)$ if $t=\infty$. I will call this map $s$.
Now, if we look how $g$ acts on our circle, it turns out that this is the same as reflection across the vertical diameter. Looking at the circle, we have yet another involution: reflection across its center. On the real line, it corresponds to $h(x) = -\frac{1}{x}$, which actually satisfies $h(h(x)) = x \neq h(x)$ for all $x$.
To find a map of period three, we simply look at a map $r:C \to C$ given by rotation by $120$ degrees. Then $s^{-1} \circ r \circ s$ (ie. we move from line to the circle, we rotate, and then we project back to the line) is a map of period three. The trick here is that composing it three times, consecutive $s$ and $s^{-1}$ will cancel out, leaving $r \circ r \circ r$, which is identity.
It will still work if you take your favourite continuous bijection $f : \mathbb{R} \to \mathbb{R}$, and looked at $f^{-1} \circ s^{-1} \circ r \circ s \circ f$. If you start with linear functions, you should be able to conclude that all maps of form $h(x)=\frac{ax+b}{cx+d}$ with $ad-bc=1$ and $a+d=-1$ have period three.
I'm sorry for that long and winding answer, but there's definitely too much exciting mathematics involved here to keep it short.