Why is my proof of Rudin 7.13 (a) incorrect? Here's Rudin 7.13

My attempt at proof of (a):
Following the hints, suppose $f$ is continuous at $x$. Let $\epsilon > 0$. Choose rationals $a, b$ such that $a < x < b$ and $f(a), fb) \in (f(x) - \epsilon, f(x) + \epsilon) = N_\epsilon (f(x))$. Since $N_\epsilon (f(x))$ is open, there exists $\epsilon_a, \epsilon_b > 0$, such that $N_{\epsilon_a}(f(a)) \subset N_\epsilon (f(x)) $ and $N_{\epsilon_b}(f(b)) \subset N_\epsilon (f(x)) $. Choose $k$ sufficiently large so that $f_{n_k}(a) \in N_{\epsilon_a}(f(a))$ and $f_{n_k}(b) \in N_{\epsilon_b}(f(b))$.
Since $f_{n_k}$ is monotonically increasing $f_{n_k}(x) \in [f_{n_k}(a), f_{n_k}(b)] \subset N_\epsilon (f(x))$, so $f_{n_k}(x) \to f(x)$.
I think this is incorrect, because I did not use the definition of $f$ in the proof ($f(x) = \sup\{ f(r): r \in \Bbb{Q}, r \le x\}$, but I can't seem to figure out why.
 A: To prove part (a):
(A) Firstly, we show that there exists a subsequence $(f_{n_{k}})_{k}$
such that $\lim_{k\rightarrow\infty}f_{n_{k}}(r)$ for each $r\in\mathbb{Q}$.
The proof involves an important trick known as Cantor Diagonal Argument.
Fix an enumeration $\mathbb{Q}=\{r_{n}\mid n\in\mathbb{N}\}$. Since
$(f_{n}(r_{1}))_{n}$ is a bounded sequence in $[0,1],$ it has a
convergent subsequence. Denote such a subsequence by $(f_{\theta(1,k)}(r_{1}))_{k}$.
Here, $\theta(1,k)\in\mathbb{N}$ such that $\theta(1,1)<\theta(1,2)<\ldots$
(That is, $\theta(1,k)$ is the usual $n_{k}$ for a subsequence.).
Again, the sequence $(f_{\theta(1,k)}(r_{2}))_{k}$ is a bounded,
so it has a convergent subsequece $(f_{\theta(2,k)}(r_{2}))_{k}$.
Note that $\theta(2,1)<\theta(2,2)<\ldots$ and $\theta(2,k)\geq\theta(1,k)$.
Observe that $(f_{\theta(2,k)}(r_{1}))_{k}$ is a subsequence of $(f_{\theta(1,k)}(r_{1}))_{k}$,
so $(f_{\theta(2,k)}(r_{1}))_{k}$ is also convergent. Repeat the
above argument (more accurately, by recursion theorem), we obtain
$\theta(m,k)\in\mathbb{N}$, $m,k\in\mathbb{N}$ such that:
(1) $(f_{\theta(m,k)})_{k}$ is a subsequence of $(f_{\theta(m-1,k)})_{k}$
($\theta(0,k):=k$ by convention),
(2) $(f_{\theta(m,k)}(x))_{k}$ is convergent for $x\in\{r_{1},r_{2},\ldots,r_{m}\}$.
We assert that $(f_{\theta(k,k)})_{k}$ is a subsequence of $(f_{k})_{k}$
and for each $x\in\mathbb{Q}$, $(f_{\theta(k,k)}(x))_{k}$ converges.
To show that $(f_{\theta(k,k)})_{k}$ is a subsequence of $(f_{k})_{k}$,
it suffices that $\theta(1,1)<\theta(2,2)<\ldots$. Let $k\in\mathbb{N}$.
Since $(f_{\theta(k+1,j)})_{j}$ is a subsequence of $(f_{\theta(k,j)})_{j}$,
we have that $\theta(k+1,j)\geq\theta(k,j)$ for all $j$. In particular,
we have $\theta(k+1,k+1)\geq\theta(k,k+1)>\theta(k,k)$. Let $x\in\mathbb{Q}$,
then $x=r_{k_{0}}$ for some $k_{0}$. Suppose that $\lim_{j\rightarrow\infty}f_{\theta(k_{0},j)}(r_{k_{0}})=l$.
Let $\varepsilon>0$, then there exists $J$ such that $|f_{\theta(k_{0},j)}(r_{k_{0}})-l|<\varepsilon$
whenever $j\geq J$. Now, for any $j\geq\max(J,k_{0})$, observe that
$\theta(j,j)\in\{\theta(k_{0},J),\theta(k_{0},J+1),\ldots\}$. For,
since $(f_{\theta(j,l)})_{l}$ is a subsequence of $(f_{\theta(j-1,l)})_{l}$,
we have that $\theta(j,l)\in\{\theta(j-1,l),\theta(j-1,l+1),\ldots\}$
for each $l$. In particular, $\theta(j,j)\in\{\theta(j-1,j),\theta(j-1,j+1),\ldots\}$.
Argue it inductively, we have
\begin{eqnarray*}
\theta(j,j) & \in & \{\theta(j-1,j),\theta(j-1,j+1),\ldots\}\\
 & \subseteq & \{\theta(j-2,j),\theta(j-2,j+1),\ldots\}\\
 & \subseteq & \ldots\\
 & \subseteq & \{\theta(k_{0},j),\theta(k_{0},j+1),\ldots\}\\
 & \subseteq & \{\theta(k_{0},J),\theta(k_{0},J+1),\ldots\}.
\end{eqnarray*}
Hence, $|f_{\theta(j,j)}(r_{k_{0}})-l|<\varepsilon$. This show that
$\lim_{k}f_{\theta(k,k)}(x)$ converges for each $x\in\mathbb{Q}$.
(B) Construction of $g_{2}$: Define $g_{1}:\mathbb{Q}\rightarrow[0,1]$
by $g_{1}(r)=\lim_{k}f_{\theta(k,k)}(r)$. For each $x,y\in\mathbb{Q}$
with $x<y$, we have $f_{\theta(k.k)}(x)\leq f_{\theta(k,k)}(y)$.
Letting $k\rightarrow\infty$ yields $g_{1}(x)\leq g_{1}(y)$. Therefore
$g_{1}$ is montonic increasing. Define $g_{2}:\mathbb{R}\rightarrow[0,1]$
by $g_{2}(x)=\inf\{g_{1}(r)\mid r\in[x,\infty)\cap\mathbb{Q}\}$.
We go to show that $g_{2}$ is increasing and $f_{\theta(k,k)}(x)\rightarrow g_{2}(x)$
whenever $g_{2}$ is continuous at $x$. Let $x,y\in\mathbb{R}$ with
$x<y$. Clearly $\{g_{1}(r)\mid r\in[x,\infty)\cap\mathbb{Q}\}\supseteq\{g_{1}(r)\mid r\in[y,\infty)\cap\mathbb{Q}\}$,
so $\inf\{g_{1}(r)\mid r\geq x\}\leq\inf\{g_{1}(r)\mid r\geq y\}$.
That is, $g_{2}(x)\leq g_{2}(y)$. Since $g_{1}$ is increasing, it
is clear that $g_{2}(r)=g_{1}(r)$ for each $r\in\mathbb{Q}$. Let
$x\in\mathbb{R}$ such that $g_{2}$ is continuous at $x$. Let $r\in[x,\infty)\cap\mathbb{Q}$
be arbitrary. For each $k$, we have $f_{\theta(k,k)}(x)\leq f_{\theta(k,k)}(r)$.
Therefore, $\limsup_{k}f_{\theta(k,k)}(x)\leq\limsup_{k}f_{\theta(k,k)}(r)=g_{1}(r)$.
Therefore $\limsup_{k}f_{\theta(k,k)}(x)\leq\inf_{r\in[x,\infty)\cap\mathbb{Q}}g_{1}(r)=g_{2}(x)$.
Let $\varepsilon>0$. Since $g_2$ is continuous at $x$, there exists $r\in(-\infty,x)\cap\mathbb{Q}$
such that $|g_{2}(x)-g_{2}(r)|<\varepsilon$. Therefore
\begin{eqnarray*}
g_{2}(x) & \leq & g_{2}(r)+\varepsilon\\
 & = & g_{1}(r)+\varepsilon\\
 & = & \lim_{k}f_{\theta(k,k)}(r)+\varepsilon.
\end{eqnarray*}
On the other hand, for each $k$, $f_{\theta(k,k)}(r)\leq f_{\theta(k,k)}(x)$,
so $\liminf_{k}f_{\theta(k,k)}(r)\leq\liminf_k f_{\theta(k,k)}(x)$.
Combining, we obtain:
\begin{eqnarray*}
g_{2}(x) & \leq & \varepsilon+\liminf_{k}f_{\theta(k,k)}(x).
\end{eqnarray*}
Since $\varepsilon>0$ is arbitrary, we have $g_{2}(x)\leq\liminf f_{\theta(k,k)}(x)$.
Hence, $\limsup_{k}f_{\theta(k,k)}(x)\leq g_{2}(x)\leq\liminf_k f_{\theta(k,k)}(x)$.
It follows that $\lim_{k}f_{\theta(k,k)}=g_{2}(x)$.
(C) Since $g_{2}$ is an increasing function, the set $A=\{x\in\mathbb{R}\mid g_{2}$
is discontinuous at $x\}$ is countable. Starting from the sequence
$(f_{\theta(k,k)})_{k}$ and going through Cantor Diagonal Argument again,
we can choose a subsequence $(f_{n_{k}})_{k}$ of $(f_{\theta(k,k)})_{k}$
such that $(f_{n_{k}}(x))_{k}$ converges at each $x\in A$. For $x\in A^{c}$,
$(f_{\theta(k,k)}(x))_{k}$ is already convergent, so $(f_{n_{k}}(x))_{k}$
is convergent too. In short $\lim_{k}f_{n_{k}}(x)$ converges for
each $x\in\mathbb{R}$.
A: I think your proof is essentially correct at this point. You should show that $f(a) = \sup f(r)$ where the sup is taken over rational numbers $r$ such that $r\leq a$. This follows from the monotonicity of $f_n$ and taking limits. The reason we need $f(x) = \sup f(r)$ here is mostly in step (iv). We need $f(x)$ to have only a countable number of discontinuities, so defining it in this way guarantees that it is monotonically increasing and thus discontinuous at at most countably many points.
A: To prove part(b):
To simplify notation, suppose that there exists a continuous function
$f:\mathbb{R}\rightarrow[0,1]$ such that $f_{n}\rightarrow f$ pointwisely.
We go to show that $f_{n}\rightarrow f$ uniformly on each compact
subset of $\mathbb{R}$. Firstly, observe that $f$ is monotonic increasing.
Let $M>0$ be arbitrary. We go to show that $f_{n}\rightarrow f$
uniformly on $[-M,M]$. Let $\varepsilon>0$ be given. By Cantor theorem,
$f$ is uniformly continuous on $[-M,M]$, so there exists $\delta>0$
such that $|f(x)-f(y)|<\varepsilon$ whenever $x,y\in[-M,M]$ and
$|x-y|<\delta$. Choose $N\in\mathbb{N}$ such that $\frac{2M}{N}<\delta$.
Define $x_{i}=-M+i\cdot\frac{2M}{N}$, $i=0,1,\ldots,N$. Since $f_{k}(x_{i})\rightarrow f(x_{i})$
as $k\rightarrow\infty$, there exists $K\in\mathbb{N}$ such that
$|f_{k}(x_{i})-f(x_{i})|<\varepsilon$ whenever $k\geq K$ and $i=0,1,\ldots,N$.
Let $k\geq K$ and $x\in[-M,M]$ be arbitrary. If $x\in\{x_{0},x_{1},\ldots,x_{N}\}$,
we clearly have $|f_{k}(x)-f(x)|<\varepsilon$. Suppose that $x\notin\{x_{0},x_{1},\ldots,x_{N}\}$,
then there exists $i$ such that $x_{i-1}<x<x_{i}$. Observe that
$|x-x_{i-1}|<\delta$ and $|x-x_{i}|<\delta$, so $|f(x)-f(x_{i-1})|<\varepsilon$
and $|f(x)-f(x_{i})|<\varepsilon$. We have that
\begin{eqnarray*}
f(x)-f_{k}(x) & \leq & f(x)-f_{k}(x_{i-1})\\
 & \leq & f(x_{i-1})-f_{k}(x_{i-1})+\varepsilon\\
 & \leq & 2\varepsilon.
\end{eqnarray*}
Moreover,
\begin{eqnarray*}
f(x)-f_{k}(x) & \geq & f(x)-f_{k}(x_{i})\\
 & \geq & f(x_{i})-f_{k}(x_{i})-\varepsilon\\
 & \geq & -2\varepsilon.
\end{eqnarray*}
That is,
$$
|f(x)-f_{k}(x)|\leq2\varepsilon.
$$
Thefore, $f_{n}\rightarrow f$ uniformly on each compact subset of
$\mathbb{R}$.
