TITLE: Proving a function is Borel measurable
QUESTION [5 upvotes]: Prove the function $f:\mathbb{R}\rightarrow \mathbb{R} $ defined by 
$$f(x)= \begin{cases} 
1/p, &\text{if $x=p/q$ is rational}\\
0, &\text{if x is irrational}\\
\end{cases}$$
is Borel measurable.
I began trying to show {$f\geq a$} is a Borel set. So I considered different values for a to find the x's, and unioned all the possible x values, if that makes any sense. But then I got all of $\mathbb{R}$.
I have been doing this for a long time and I am now very confused.

REPLY [6 votes]: If $a \le 0$ then $\{f \ge a\} = \mathbb{R}$ which is Borel.  If $a > 0$ then $\{f \ge a\} \subset \{f > 0\} = \mathbb{Q}$.  But every subset of $\mathbb{Q}$ is countable and hence Borel.