How can I prove that this function is continuous at $0$? 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?
 A: Hint: What is the definition of continuity at a point in terms of open sets?  How does it differ from the global definition of continuity in terms of open sets?
A: 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.
A: $f$ is continuous at $x$ if the preimage of every open neighborhood of $f(x)$ contains an open neighborhood of $x$.  The preimage need not be open itself.  
For a simpler example, let $g(x)=1$ if $x\geq 0$, and let $g(x)=0$ when $x<0$.  Then $g$ is continuous at $x=1$, but the preimage of $(0,2)$ is $[0,\infty)$, which is not open in $\mathbb R$.  Nonetheless, the preimage contains the open neigborhood $(0,2)$ of $x=1$.
Translating this to $\varepsilon$s and $\delta$s, recall that $f$ is continuous at $x$ if for all $\varepsilon>0$ there exists $\delta>0$ such that $\{y:|x-y|<\delta\}\subseteq f^{-1}(\{y:|f(x)-y|<\varepsilon\})$.  Here $\{y:|x-y|<\delta\}$ is the neighborhood of $x$, and it is only required to be contained in the preimage of the neighborhood $\{y:|f(x)-y|<\varepsilon\}$ of $f(x)$.
