How did Gauss discover the invariant density for the Gauss map? The Gauss map is defined on $(0,1)$ by the formula
$$
f(x)=\frac1x-\Big\lfloor\frac1x\Big\rfloor
$$
Then the density
$$
\rho(x)=\frac{1}{\log2(1+x)}
$$
is $f$-invariant.
It appeared in Gauss' diary. Gauss didn't indicate the way he had found the density. Checking invariance is straightforward.
Is there a simple (short) way to come up with this density function?
 A: It is not the density. It is distribution function. Density function $1/(x+1)$ is not so complicated to find it. Rational numbers lead to this function as well. So some experiments can give this function.
Another heuristics you can find in the article Gyldén, H. Quelques remarques relativement à la représentation des nombres irrationnels par des fractions continues C. R. Ac. Sci. Paris., 1888, 107, 1584–1587 They are very rough but one of the Gyldén' answers is correct.
A: Here is a heuristic.
Observe that $f$ is decreasing on any interval of the form $I_n:=(1/(n+1),1/n)$.  If $x\in I_n$ and $f(x)=a$, then $x=\frac{1}{a+n}$, and so $f^{-1}(a,1)$ is the union of the intervals $(1/(n+1),1/(n+a))$.  Supposing there were an $f$-invariant measure $\mu=gdx$, you can see that
$\displaystyle{\sum_{n=1}^\infty \int_{1/n+1}^{1/n+a}g(x)dx=\int_a^1g(x)dx}$.
Supposing that $g$ is continuous, take the derivative of both sides:
(**) $\displaystyle{\sum_{n=1}^\infty g\left(1/(n+a)\right)/(n+a)^2=g(a)}$.
Approximating the sum by an integral, we get
$\displaystyle{g(a)\approx\int_1^\infty g\left(\frac{1}{x+a}\right)\frac{1}{(x+a)^2}dx}$.
Supposing that $g$ is never too big or too small, this gives
$g(a)\approx \frac{C}{1+a}$.
One can then plug this kind of function into (**) to see that such a function works for any C.  Then just pick C to normalize.
Probably someone from the era of Gauss (especially with his acuity at mathematics) did not need to do anything past (**) since people back then seem like magicians when it comes to expressions with infinite sums.
A: I once saw a talk by professor Pierre Arnoux of Institut de Mathématique de Luminy where he talked precisely about that. The baseline was that nobody knows. Apparently gauss wrote in a letter that "an easy calculation shows that....". For the rest of the talk he presented some approaches that Gauss might have taken. But in the end we don't know.
