I'm studying for a real analysis exam and I found the following exercise:
Let $(X, \mathcal{M}, \mu)$ be a measure space and $f, g: X \to \mathbb{R}$ be two measurable and integrable functions. Let
$$ F_t:= \{ x \in X : f(x) > t \} \ \ \& \ \ G_t:=\{ x \in X : g(x) > t \}. $$ Prove that
$$ \int_X |f-g| d\mu = \int _{\mathbb{R}} \mu ( (F_t - G_t) \cup (G_t -F_t) ) dt.$$
I have been trying to solve it for a few days, but I haven't been able to. I would appreciate it if you could give me a hint.
Also, I think this statement is similar to LOTUS (Law of the Unconscious Statistician) because it involves the equality of an abstract integral and a real integral. What do you think about it?
The problem in the OP can be analyzed using Fubini's theorem. Without loss of generality, we may assume that $\mu$ is a a $\sigma$-finite measure on $(X,\mathcal{M})$ (since $f,g\in L_1(\mu)$, $X_{f,g}=\{x\in X:|f(x)-g(x)|>0\}$ is $\sigma$-finite and we may replace $X$ with $X_{g, f}$.
Notice that $F_t\setminus G_t=\{x:g(x)\leq t<f(x)\}$ and $G_t\setminus F_t=\{x:f(x)\leq t<g(x)\}$ are disjoint sets.
An application of Fubini-Tonelli's theorem yields \begin{align} A:=\int_\mathbb{R}\mu(x:g(x)\leq t< f(x))\,dt&=\int_\mathbb{R}\int_X\mathbb{1}_{\{g<f\}}\mathbb{1}_{[g(x),f(x))}(t)\,dt\,\mu(dx)\\ &=\int_X\int_\mathbb{R} \mathbb{1}_{\{g<f\}}\mathbb{1}_{[g(x),f(x))}(t)\,dt\,\mu(dx)\\ &=\int_X\mathbb{1}_{\{g<f\}}(x)(f(x)-g(x))\,\mu(dx) \end{align}
A similar argument shows that
$$B:=\int_\mathbb{R}\mu(x:f(x)\leq t< g(x))\,dt=\int_X\mathbb{1}_{\{f<g\}}(x)(g(x)-f(x))\,\mu(dx)$$
The conclusion follows by adding $A$ and $B$.