Lusin's theorem from Rudin RCA 
Hi! Let me ask questions on Lusin's theorem from Rudin's RCA.
$1)$ As we know $s_n=\varphi_n \circ f$ (from Theorem 1.17) then $$2^nt_n(x)=2^n(s_n(x)-s_{n-1}(x))=2^n(\varphi_n \circ f(x)-\varphi_{n-1} \circ f(x))=\dots$$ As $0\leq f<1$ then $$\dots=2^n\left(\dfrac{[2^nf(x)]}{2^n}-\dfrac{[2^{n-1}f(x)]}{2^{n-1}}\right)=[2^nf(x)]-2[2^{n-1}f(x)]$$ where $[\cdot]$ - integer part. Also the last equality above can be equal $0$ or $1$ since $[2\theta]-2[\theta]\in \{0,1\}$. An it's equal to $1$ if $\theta\in \bigcup \limits_{k\in \mathbb{Z}}[k+\frac{1}{2},k+1)$. So $2^nt_n(x)=1$ if $2^{n-1}f(x) \in \bigcup \limits_{k\in \mathbb{Z}}[k+\frac{1}{2},k+1)$ $\Rightarrow$ $x  \in \bigcup \limits_{k\in \mathbb{Z}}f^{-1}([2^{-(n-1)}(k+\frac{1}{2}),2^{-(n-1)}(k+1)))$. So $T_n$ is the last set and it's measurable, i.e. $T_n \in \mathfrak{M}$. Am I right? 
$2)$ When he write that "$(1)$ holds if $A$ is compact and $f$ is a bounded measurable function" what does he mean about $f$? Non-negative function or not? Is non-negative then we must replace $f$ by $\alpha^{-1}f$ where $\alpha=\sup f+1$.
$3)$ Let's Go further. Let's take a look at penultimate paragraph which I marked by red line. I understood that if $A$ is any set with finite measure then by inner regularity we can find compact set $K\subset A$ such that $m(A-K)$ as small as needed. Note that $f$ outside $K$ possibly is not zero! And we can't apply above proof because there we use that $f=0$ on $A^c$.
$4)$ Also why considers sets $B_n$? Also it's not obvious to me how he got the general case.
Would be very grateful if somebody explain what he does in this paragraph. I spent about one day but no results :( In my opinion this paragraph is very brief and horrible.
 A: Let me write you a more detailed version of the second last paragraph. Suppose $f:X\to [0,+\infty)$ is a measurable function, $\mu(A) < +\infty$, and $f = 0$ outside $A$. Note that the general complex case can be decomposed to this case by considering the positive and negative parts of real and imaginary parts. What you know is that you can approximate such an $f$ on a compact set where it's bounded. Your goal is to find some compact set $K\subset A$, such that $f$ is bounded on $K$, and $\mu(A-K)$ is small.
Fix $\epsilon > 0$. Put $B_n = \{x:f(x) \geq n\}$. Then $B_{n+1}\subset B_n$ and $\bigcap B_n = \varnothing$, because $f(x)$ is finite for each $x$. You also know that $B_1 \subset A$, so $\mu(B_1)$ is finite. That means $\mu(B_n) \to 0$ as $n\to \infty$. Let $n$ be such that $\mu(B_n) <\epsilon$. Since $\mu(A-B_n)$ has finite measure, by inner regularity you can find a compact set $K\subset A-B_n$ such that $\mu(K) > \mu(A-B_n) - \epsilon$. Now you have $f$ bounded on a compact set $K$, and $\mu(A-K) < 2\epsilon$.
A: Here is a slight modification of Rudin's proof that maintains the $\sup |g| \le \sup |f|$ condition at easch stage rather than at the end.
1) Suppose $A$ is compact, $f(x) \in [0,1]$ for all $x$, and $\sup f = 1$ (the purpose of the latter condition is to ensure $\sup |g| \le \sup |f|$). Let $T_\infty = f^{-1} (\{1\})$ (which is
measurable).
Now let 
$b_n(x) = (2^n f(x) ) \text{ mod } 1$ (the binary digits of the fractional part of $f(x)$). It
should be clear that the $b_n$ are measurable and $b_n(x) \in \{0,1\}$, hence
$b_n$ is the indicator function of the set $T_n = b_n^{-1} ( \{ 1\})$.
We have $f(x) = 1_{T_\infty}(x)+\sum_n {1 \over 2^n} 1_{T_n}(x)$. Choose
$h_n$ as above, except with $\mu(V_n-K_n) < {1 \over 2^{n+1}} \epsilon$, and,
if $T_\infty$ is non empty, choose $h_\infty$ in a similar manner with
$\mu(V_\infty-K_\infty) < {1 \over 2} \epsilon$. If $T_\infty$ is empty,
set $h_\infty = 0$.
Now let $g(x) = h_\infty(x)+\sum_n {1 \over 2^n} h_n(x)$. It is straightforward to check that $g$ is continuous, $\sup g \le 1 = \sup f$
and $\mu \{ x | g(x) \neq f(x) \} < \epsilon$.
2) Now suppose $f$ is bounded and $A$ is compact. Let $a= \inf f, b = \sup f$.
If $a=b$ then $f$ is continuous and we are finished. Otherwise let
$\tilde{f} = {f-a \over b-a}$ and apply the above to get a function $\tilde{g}$ that approximates $\tilde{f}$ in the above sense. Let $g = a+ (b-a) \tilde {g}$. It is straightforward to verify that $\sup |g| \le \sup |f|$ ($=\max(|a|,|b|)$).
3) Now suppose that $\mu A < \infty$ and $f$ is bounded and real valued. We can find a compact $K \subset A$ such that $\mu (A \setminus K) < {1 \over 2} \epsilon$.
Let $\tilde{f} = f \cdot 1_K$ and let $g$ approximate $\tilde{f}$ as
above with $\mu \{ x | g(x) \neq \tilde{f}(x) \} < {1 \over 2}\epsilon$.
Then $g$ is continuous, $\sup |g| \le \sup |f|$ and 
$\mu \{ x | g(x) \neq {f}(x) \} < \epsilon$.
4) Now suppose $\mu A < \infty$ and $f$ is bounded and complex valued. From Chapter 1, 2.19 (e) we can write $f = \alpha |f|$, where $\alpha$ is a
complex measurable function such that $|\alpha| =1$. There is a measurable map $\theta:\partial B(0,1) \to [0, 2 \pi)$ such that $z = e^{i \theta(z)}$ 
for all $|z|=1$, hence we can write $f(x) = |f|(x) e^{i \phi(x)}$ for bounded
measurable, real valued functions $|f|, \phi$.
Let $n,\beta$
be continuous functions such that 
$\mu \{ x | n(x) \neq |f(x)| \} < {1 \over 2}\epsilon$,
$\mu \{ x | \beta(x) \neq \phi (x) \} < {1 \over 2}\epsilon$
and $\sup |n| \le \sup |f|$, and $0 \le \beta(x) \le \sup |\phi|$.
$\sup |v| \le \sup | \operatorname{im} f(x) |$.
Let $g(x) = n(x) e^{i \beta(x)}$, then $\mu \{ x | g(x) \neq f(x) \} < \epsilon$ and $\sup |g| = \sup |n| \le \sup |f|$.
Now suppose $\mu A < \infty$ and $f$ is complex valued. Choose $n$ such that
$B_n = \{x | |f(x)| > n \}$ satisfies $\mu B_n < { 1\over 2} \epsilon$.
Then $\tilde{f}=(1-1_{B_n})f$ is bounded, and we can find a $g$ such that
$\mu \{ x | g(x) \neq \tilde{f}(x) \} < {1 \over 2}\epsilon$ and so
$\mu \{ x | g(x) \neq {f}(x) \} < \epsilon$.
