I'm trying to understand this equality:
$$ \{x \in X : f(x) > g(x) \} = \bigcup_{r \in \mathbb{Q}}{\{x\in X : f(x) > r\}\cap\{x\in X:g(x) < r\}} $$
$X$ is a measurable space and $f,$ $g$ are measurable functions. As, $f$ is measurable, then $\{x\in X : f(x) > r\}$ is measurable. The same goes for $g.$ The intersection between these sets would be measurable, and the countable union, $\bigcup_{r \in \mathbb{Q}}{\{x\in X : f(x) > r\}\cap\{x\in X:g(x) < r\}}$ would then be measurable.
I have been trying to visualize what this union means, employing some examples (not numeric, but general shapes of graphs).
For example, if $f(x) = c, c\in \mathbb{R}$ and, $g(x) = d, d\in \mathbb{R}$, and $c \neq d,$ $\bigcup_{r \in \mathbb{Q}}{\{x\in X : f(x) > r\}\cap\{x\in X:g(x) < r\}} = \mathbb{R}.$
Clearly, the domain where the functions are defined, should be equal, or have at least some intersecting region, because in other case, the union is empty.
It is possible to create graphs, for which the union is empty, even though the functions are defined in a same interval. And in lots of cases, there are one ore several intervals of intersection.
But I still don't have a clue as to why the equality holds. This would show that $ \{x \in X : f(x) > g(x) \}$ is measurable.
If $x\in\bigcup_{r \in \mathbb{Q}}{\{x\in X : f(x) > r\}\cap\{x\in X:g(x) < r\}}$, then, for some $r\in\mathbb Q$, $f(x) > r$ and $g(x) < r$. Therefore, $f(x)>g(x)$.
On the other hand, if $f(x)>g(x)$, then there is a rational $r$ such that $f(x)>r>g(x)$, and so$$x\in{\{x\in X : f(x) > r\}\cap\{x\in X:g(x) < r\}}.$$