Continuous Functions from $\mathbb{R}$ to $\mathbb{Q}$

Your argument is correct. Perhaps what is unsatisfying is that you're actually making an argument which applies much more generally. You seem to be proving the following theorem:

Suppose $X,Y$ are topological spaces and $f:X\to Y$ is a continuous map. If $X$ is connected, then $f(X)$ is connected.

If you are comfortable simply quoting this, then you're done once you've shown that $\mathbb{Q}$ is totally disconnected and $\mathbb{R}$ is connected: the image of $\mathbb{R}$ under any continuous map must be connected and the only connected subspaces of $\mathbb{Q}$ are singletons, so the image of $\mathbb{R}$ under any continuous map is a singleton.

If not, simply modify your argument to prove the theorem I stated. Your proof is correct: a disconnecting pair of open sets in the range will pull back to a disconnecting pair of open sets in the domain, giving a contradiction. The only modification you need is removing reference to $\mathbb{R}$ and $\mathbb{Q}$ and replacing them with general topological spaces.


Suppose you know that

  • Every continuous function from $\mathbb{R}$ to $\mathbb{Q}$ is a continuous function from $\mathbb{R}$ to $\mathbb{R}$.
  • The intermediate value theorem holds.
  • The irrationals are dense in $\mathbb{R}$.

Then a nonconstant continuous function would have to pass through the irrational numbers between any two of its values.

So then I suppose I would ask which of the three bulleted points were already established and which to prove as lemmas.

Nobody should ever write "Prove that any continuous function from whatever to whatever is constant." That could be understood as "Pick any continuous function from whatever to whatever and prove that it's constant", but what is more likely intended is "Prove that every continuous function from whatever to whatever is constant." Merely changing "any" to "every" eliminates all ambiguity.


The topology on $\mathbb Q$ is the one induced on $\mathbb Q$ as a subset of $\mathbb R$. Thus, for every open set $U_{\mathbb R}$ of $\mathbb R$ the set $U_{\mathbb Q}=U_{\mathbb R}\cap \mathbb Q$ is open in $\mathbb Q$. If $f:\mathbb{R}\rightarrow \mathbb{Q}$ is continuous, the preimage $f^{-1}(U_{\mathbb Q})$ of every open set $U_{\mathbb Q}$ of $\mathbb Q$ is open in $\mathbb R$. But then we can consider $f$ as a function from $\mathbb R$ to $\mathbb R$, and by the above the preimage of every open set will still be open, so this is a continuous function from $\mathbb R$ to $\mathbb R$ that takes only rational values. Since there are irrational numbers between any two rational numbers, such a function must be constant by the intermediate value theorem.