TITLE: Follow-up regarding right-continuous $f:\mathbb{R} \to\mathbb{R}$ is Borel measurable
QUESTION [6 upvotes]: I have a follow-up to another question here on math.stackexchange, Are right continuous functions measurable?.  The thread was a couple of years old, so I hope it's okay if I start a new question.  The person who answered the question claimed that the preimage of an open set under a right-continuous function $f: \mathbb{R} \to \mathbb{R}$ is a Borel measurable set because it is the countable union of half-open intervals.  I was trying to think through the "countable union" part.  If we have an open set $U \subseteq \mathbb{R}$, and let $A = f^{-1}(U)$, then certainly by definition if we take $A \cap \mathbb{Q}$, then for every $a \in A \cap \mathbb{Q}$, there is some $\delta > 0$ such that $[a,a+\delta) \subseteq A$, and thus $\bigcup_{a \in A \cap \mathbb{Q}} [a,a+\delta) \subseteq A$.  But then, why does the reverse containment hold (or does it hold at all)?  I tried to prove that $A \subseteq \bigcup_{a \in A \cap \mathbb{Q}} [a,a+\delta)$ using contradiction, but didn't get anywhere.  The best I could come up with was that if $b \in A$ and $b \notin \bigcup_{a \in A \cap \mathbb{Q}} [a,a+\delta)$, then because of the density of the rationals in the reals, we could write $\{ b \} \cup \bigcup_{n \in \mathbb{N}} [a_n,a_n+\delta_n) \subseteq A$, but this clearly didn't get me anywhere...

REPLY [9 votes]: Instead of considering $A\cap\mathbb{Q}$, let's first see that $A$ is a union of half-open intervals: If $x\in A$, by definition $f(x)\in U$, and by right-continuity, there is a $\delta_x > 0$ such that $f([x,x+\delta_x)) \subset U$, hence
$$A = \bigcup_{x\in A} [x,x+\delta_x).$$
So far, so good. Now consider the open set
$$V = \bigcup_{x\in A} (x,x+\delta_x).$$
We know that every open subset of $\mathbb{R}$ is the disjoint union of countably many open intervals, so
$$V = \bigcup_{n=1}^\infty (a_n,b_n)$$
Now, every $a_n$ either is an element of $A$, or not. Let $M = \{n\in \mathbb{Z}^+ : a_n \in A\}$ and $N = \mathbb{Z}^+ \setminus M$. Then we have
$$A = \bigcup_{n\in M} [a_n,b_n) \cup \bigcup_{n\in N} (a_n,b_n).\tag{1}$$
For if $x\in A$, then $(x,x+\delta_x)$ is contained in one of the $(a_n,b_n)$, and either $a_n < x$, or $a_n = x$.
Now, $(1)$ already shows that $A$ is a Borel set, but to write it as a countable union of half-open intervals, we can further observe that for $n\in N$, we can write
$$(a_n,b_n) = \bigcup_{k=1}^\infty \left[a_n + \frac{b_n-a_n}{2^k},b_n\right)$$
as a countable union of half-open intervals.