Is a rational-valued continuous function $f\colon[0,1]\to\mathbb{R}$ constant?

Suppose $f$ isn't constant. Then for some $a,b\in[0,1],$ $f(a)\neq f(b);$ WLOG $f(a)<f(b)$.

Since $f$ is continuous, by the Intermediate Value Theorem, it must take every value in the interval $[f(a),f(b)]$. But this interval contains an irrational number (in fact, uncountably many of them). Contradiction.

This doesn't quite follow fron the fact that $\mathbb{Q}$ is dense in $\mathbb{R}$; it follows more from the density of the irrational numbers, the complement of $\mathbb{Q}$.


Hint: Use the intermediate value theorem


From an advanced standpoint, you know that $\mathbb{R}$ is connected. We know that $\mathbb{Q}$'s connected components are all singleton points. Since the image of the real line under any continuous function is connected, its image must be a point. Therefore it is constant.


Suppose $\alpha \notin \mathbb{Q}$. Let $A_\alpha = f^{-1} (-\infty, \alpha)$, $B_\alpha = f^{-1} (\alpha, \infty)$. Since $f$ is continuous, $A_\alpha,B_\alpha$ are open

Since $\alpha \notin f [0,1]$, we see that $[0,1] \subset A_\alpha \cup B_\alpha$, and since $[0,1]$ is connected, we must have $[0,1] \subset A_\alpha$ or $[0,1] \subset B_\alpha$.

Now suppose $f$ is not constant, then we have $q_1,q_2 \in f[0,1]$ for two rationals $q_1 < q_2$. Pick $\alpha \in (q_1,q_2) \setminus \mathbb{Q}$. Then, as above, we have $[0,1] \subset A_\alpha$ or $[0,1] \subset B_\alpha$. The first case implies $q_2 < \alpha$, the second case implies $q_1 > \alpha$, which is a contradiction. Hence $f$ is a constant.

The proof relies on three things, the continuity of $f$, the connectedness on $[0,1]$ and the fact that between any two distinct rationals there is an irrational.