TITLE: Borel measurability is a local property
QUESTION [12 upvotes]: I am looking at Exercise 5.2 (page 44) in "Real Analysis for Graduate Students" by Richard Bass. 

Let $f:(0, 1)\to \mathbb{R}$ be a function such that for every $x\in (0, 1)$,
  there exist $r>0$ and a Borel measurable function $g$, both depending
  on $x$, such that $f$ and $g$ agree on $(x-r, x+r)\cap (0, 1)$. Prove
  that $f$ is Borel measurable.

Attempt. For each $x\in (0, 1)$, let's denote $r_{x}$ and $g_{x}$ to be the quantities given in the problem statement. By choosing $r_x$ sufficiently small, we may assume that $(x-r_{x}, x+r_{x})\subseteq (0, 1)$. Then for $a\in\mathbb{R}$, we have
$$
f^{-1}((a, \infty))=\{y: f(y)>a\}=\bigcup_{x\in (0, 1)} \{y: g_{x}(y)>a\}\cap (x-r_{x}, x+r_{x})
$$
Since $g_{x}$ is Borel measurable, we know that $\{y: g_{x}(y)>a\}\cap (x-r_{x}, x+r_{x})$ is a Borel set. But the union above is uncountable; so how do we show that $f^{-1}((a, \infty))$ is a Borel set?
Attempt 2. Since $\mathbb{Q}$ is countable and dense in $(0, 1)$, we can try looking at the points $x\in\mathbb{Q}\cap (0, 1)$. But then the intervals $(x-r_{x}, x+r_{x})$ need not cover $(0, 1)$. The standard example is as follows. Suppose $\{q_1, q_2, …\}$ is enumeration of rationals in $(0, 1)$, and let $\varepsilon>0$. If we let $r_{q_{j}}$ to be $\varepsilon 2^{-j}$, then the measure of $\bigcup_{j=1}^{\infty} (q_j-r_{q_{j}}, q_{j}+r_{q_{j}})$ is at most $2\varepsilon$. 
Attempt 3. If each $g_{x}$ is continuous, we would be done. In that case, $$\{y: g_{x}(y)>a\}\cap (x-r_{x}, x+r_{x})$$ would be an open set; so as a union of open sets, $f^{-1}((a, \infty))$ would be an open set, and hence Borel.

REPLY [3 votes]: By hypothesis, for every $x\in (0, 1)$ we find Borel measurable function $g_{x}$ and $r_x>0$ such that $f=g_{x}$ on the open interval $(x-r_x, x+r_x)\subset (0, 1)$. This gives an open cover of $(0, 1)$:
$$
(0, 1) = \bigcup_{x\in (0, 1)} (x-r_{x}, x+r_x)
$$
Since $(0, 1)$ is a Lindelöf space, this open cover has a countable subcover, i.e. we can find $x_1, x_2, x_3, …$ in $(0, 1)$ such that
$$
(0, 1)=\bigcup_{n=1}^{\infty} (x_{n}-r_{x_{n}}, x+r_{x_{n}})
$$ 
Now for any $a>0$, we have that
$$
f^{-1}((a, \infty))=\{y: f(y)>a\}=\bigcup_{n=1}^{\infty} \{y: g_{x_n}(y)>a\}\cap (x_n-r_{x_{n}}, x_n+r_{x_{n}})
$$
Each $\{y: g_{x_n}(y)>a\}\cap (x_n-r_{x_{n}}, x_n+r_{x_{n}})$ is a Borel measurable set. As a countable union of measurable sets, $f^{-1}((a, \infty))$ is measurable. Thus, $f$ is Borel measurable.