TITLE: How can I prove that this function is continuous at $0$?
QUESTION [13 upvotes]: The classical example of a functions with only one point of continuity is 
$$
f(x) = \begin{cases}
x & \text{if } x \in \mathbf{Q}, \\
0 & \text{otherwise}.
\end{cases}
$$
I only want to prove the continuity at $0$, using the definition in terms of open sets. Let $(a,b)$ be an open set containing $0$. I want to prove that the preimage of this interval is open in $\mathbf R$. But since every preimage contains the $0$ element, the preimage consists of all irrational numbers and the rational numbers of the interval $(a,b)$, but this set is not open. What am I doing wrong?

REPLY [3 votes]: If a function is continuous everywhere then the pre-image of every open set under that function is open.
But in this problem it is not the case that the function is continuous everywhere, so one should not expect the pre-image of every open set to be open.