Prove that if $f: \mathbb{R} \to \mathbb{Q}$ is continuous then $f$ is constant

Suppose that $f: \mathbb{R} \to \mathbb{R}$ is continuous and that $f(x) \in \mathbb{Q}$ for all $x \in \mathbb{R}$. Prove that f is constant.

I have the idea that because there is an irrational number between any two rational number then if the function is continuous, the function must be constant. But I don't know how to write out a proper proof for it.

Any help is appreciated. Thanks in advance.

You can use the intermediate value theorem. Suppose $f(x_1) = q_1$ and $f(x_2) = q_2$. Because $f$ is continuous, by the intermediate value theorem, $f$ takes on all values between $q_1$ and $q_2$. If $q_1 \ne q_2$ then one of these values is irrational, which is impossible, so $q_1 = q_2$. Therefore for all $x_2$, $f(x_2) = f(x_1)$ - in other words, $f$ is constant.

• Interesting that you don't have to use the density of rationals anywhere in here then? Can you be a bit more specific about $q_1$ and $q_2$? Are those both consecutive rational numbers? – guimption Mar 21 at 10:33
• This is telling me that if $f$ is continuous, and it maps from $R$ to some non-dense set, then $f$ must be constant? Is that true? – guimption Mar 21 at 10:40
• @guimption Not in general. $[0, 1]$ is not dense in $\mathbb{R}$ but there are nonconstant functions from $\mathbb{R}$ to $[0, 1]$. However, the argument can be generalized as follows: if $U \subset \mathbb{R}$, $f : \mathbb{R} \rightarrow U$, and $U$ does not contain any open intervals, then $f$ is constant. – Solomonoff's Secret Mar 21 at 14:47

Since $f$ is continuous and $\mathbb{R}$ is connected, then $f(\mathbb{R})$ is connected. Since the only non-empty connected subsets of $\mathbb{Q}$ are single points, we must have that $f$ is constant.

• @MJD: Thanks for catching that. – copper.hat Feb 4 '15 at 15:47
• What does "connected" mean? – guimption Mar 21 at 10:43

Contrary;Supposed $f$ is not constant, so without losing of general we suppose that $f$ has two value $x_{0},x_{1}\in Q$ such taht $x_{0}\neq‎x_{1}$, thus $\{x_{0}\}$ and $\{x_{1}\}$ make disconected for $f(R)$.This is contradiction,since $f(R)$ is conected

• What does "connected" mean? Is it the same as "dense"? – guimption Mar 21 at 10:43