TITLE: Prove that there doesn't exist any function $f:\mathbb R\to \mathbb R$ that is continuous only at the rational points.
QUESTION [5 upvotes]: Prove that there doesn't exist any function $f:\mathbb R \to \mathbb R$ that is continuous only at the rational points. Suggestion: For every $n \in \mathbb N$, consider the set $$U_n=\{x \in \mathbb R : \exists U \subset \mathbb R \,\text{open, with}\, x \in U, {\rm diam}(f(U))<1/n\}.$$
I am supposed to prove this statement using the Baire Category theorem. I am not sure but I think that the suggestion points towards trying to express $\mathbb R$ as the union of the sets $U_n$. If I could prove that any $U_n$ is a nowhere dense set and I affirm $\mathbb R=\bigcup_{n \in \mathbb N} U_n$, since the Baire Category theorem says that the interior of a countable union of nowhere dense sets is empty, I would get to an absurd. I have two problems: what does this have to do with the fact that there can't be any function $f$ continuous only at rational points? How can I assure that every $x \in \mathbb R$ is in some $U_n$? Moreover, is there any non-empty $U_n$?

REPLY [2 votes]: Let $f:\Bbb R\to \Bbb R$ and let $D$ be the set of $x\in \Bbb R$ such that $f$ is discontinuous at $x$.
For $q\in \Bbb Q^+$ let $x\in D(q)$ iff $\sup \{|f(y)-f(z)|:y,z\in U\}>q$ whenever U is open and $x\in U.$ 
Every $D(q)$ is closed. For if $x'\in \overline {D(q)}$ and $U$ is any open set with $x'\in U$ then there exists $x\in U\cap D(q).$ Now, since $x\in D(q)$ and $U$ is open with $x\in U,$ we have $\sup \{|f(y)-f(z)|: y,z\in U\}>q.$ So $x'\in D(q).$
We have $D=\cup_{q\in \Bbb Q^+}D(q).$ So $D$ is an $F_{\sigma}$ set. So $C=\Bbb R \setminus D$ is a $G_{\delta}$ set.
Suppose $C$ is also dense. Let $C=\cap_{n\in \Bbb N}\,U_n$  where each $U_n$ is open. Each $U_n$ is dense  because $\overline U_n\supset \overline C=\Bbb R.$ Let $S$ be any countable set, with $S\subseteq \{s_n:n\in \Bbb N\}.$  Then each $U_n\setminus \{s_n\}$ is dense & open, so by Baire, $C\setminus S\supseteq \cap_{n\in \Bbb N}(U_n \setminus \{s_n\})\ne \emptyset.$ So $C$  is not equal to any countable  $S$.  In particular $C\ne \Bbb Q.$
Remarks: (1). Regardless of the Continuum Hypothesis, if $C$ is a dense $G_{\delta}$ subset of $\Bbb R$ then $|C|=2^{\aleph_0}=|\Bbb R|$. (2). If $C$ is any $G_{\delta}$ subset of $\Bbb R$ then there exists $f:\Bbb R \to [0,1]$ such that (i) $f(x)=0\iff  x\in C,$ and (ii) $f$ is continuous at $x \iff x\in C.$