Function $g(x)$, such that $\int_{\mathbb{R}} f(g(x))dx = \int_{\mathbb{R}} f(x)dx$ for all $f\in L^1(\mathbb{R})$

The set of all such functions is closed under composition. As a result, all the functions $g^k$ (in the sense of composition) work.

E.g. $$g^2(x)=x-\frac1x -\frac{1}{x-\frac1x}$$

Adding to that the fact that you can also compose them with affine functions of slope $1$ (lisyarus' answer) yields already a pretty large class.


Incorporating @J.G.'s comment, one gets for instance all rational functions of the form $$\frac{x^2+ax+b}{x+c}$$ with the only requirement that $b<c^2$ ($a$ and $c$ are arbitrary).


We have $\int f\circ g=\int f$ for every integrable $f$ if and only if the same holds for $f=\chi_E$, which says precisely $$m(g^{-1}(E))=m(E)$$for every measurable set $E$, which is to say that $g$ is measure-preserving.

If we assume in addition that $g$ is a smooth bijection this is equivalent to $|g'|=1,$so the only smooth bijections with this property are $$g(x)=\pm x+c.$$

This seemed so obvious that it seemed clear to me at first that $x-1/x$ cannot have the stated property. But of course that function is not injective; if $g(x)=x-1/x$ you can calculate $g^{-1}((a,b))$ explicitly, and sure enough you get two intervals with total length $b-a$.

(This is actually consistent with the analysis above, if you look at it right. The relevant condition for a smooth bijection is actually $|({g^{-1})}'|=1$, which is equivalent to $|g'|=1$. But now if $g(x)=x-1/x$ and you let $y_1$ and $y_2$ denote the two "branches" of $g^{-1}$ you easily calculate that $|y_1'|+|y_2'|=1$.)

One can easily concoct discontinuous examples. For example if $A\subset(0,\infty)$ let $$g(x)=\begin{cases}x,&(|x|\in A), \\-x,&(|x|\notin A).\end{cases};$$then $g$ is a measure-preserving bijection.


There is a not that well known result about these kinds on integrals that quite often comes up on this site. It was already mentioned in the comments by achille hui, but I'll add this as a CW as it's a shame not having it as an answer:

Glasser's master theorem$^{[1]}$ says that if $f(x)$ is integrable then $$\int_{\mathbb{R}}f(x)\,{\rm d}x = \int_{\mathbb{R}}f(\phi(x))\,{\rm d}x$$ for all $\phi(x) = x - \sum_{n=1}^N\frac{|a_n|}{x-b_n}$ where $a_n,b_n$ are arbitrary constants and where the integrals are to be interpreted in a principal value sense.

[1]: Glasser, M. L. "A Remarkable Property of Definite Integrals." Math. Comput. 40, 561-563, 1983