I am stuck in the following question:
Suppose $f: B \rightarrow \mathbb{R}$ be a Borel measurable function. Let $g(x)=\begin{cases} f(x), & \text{if } x \in B,\\ 0, & \text{if } x \in B^c \end{cases}$.
I would like to first show that $B$ is a Borel set and that the function $g$ is Borel measurable. I know the required definitions, but I can't figure out how to put things together to solve this. Would someone please help?
Well the definition of a Borel measurable function is that the preimages of Borel sets are Borel. $\mathbb{R}$ is a very Borelly Borel set, so $f^{-1}(\mathbb{R}) = B$ is Borel as well. Simple as that!
Again to show that $g$ is Borel you need to show that $g^{-1}(A)$ is Borel for every Borel $A \subseteq \mathbb{R}$. But notice we may divide this into two cases: if $0 \in A$, then $g^{-1}(A) = B^{c} \cup f^{-1}(A)$. Both of these are Borel since, again $f$ is Borel measurable and $B^{c}$ is Borel as $B$ is (sigma algebras are closed under complements). And otherwise if $0 \not \in A$, then $g^{-1}(A) = f^{-1}(A)$ which is again Borel as $f$ is Borel measurable. Thus the $g$ preimages of borel sets are Borel, meaning $g$ is Borel.