Let $(X,\mathcal{A})$ a measurable space and $f:X\rightarrow \mathbb{R}$ a measurable function and $g:X\rightarrow \mathbb{R}$
$g(x)=\left\{\begin{matrix} 0 & \text{if} \ f(x)\in \mathbb{Q} \\ 1 & \text{if} \ f(x)\in\mathbb{R}\setminus \mathbb{Q} \end{matrix}\right.$
How do we prove that g is also measurable ?? I know how to prove when a characteristic function is measurable but I dont know how to handle $f(x)$ inside $g$ in order to prove that is measurable.
Notice that $\{ x : f(x) \in \mathbb{R} \setminus \mathbb{Q} \} = f^{-1} (\mathbb{R} \setminus \mathbb{Q})$ and $\{ x : f(x) \in\mathbb{Q} \} = f^{-1} ( \mathbb{Q})$ are both measurable sets since $f$ is measurable. Then we simply have that $g = 1_{f^{-1} (\mathbb{R} \setminus \mathbb{Q})}$ so you should be able to finish from here.
Alternatively, this is an example of a general result. We have that $g = 1_{\mathbb{R} \setminus \mathbb{Q}} \circ f$ is a composition of measurable functions and a composition of measurable functions is measurable.