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

Let $f\colon[0,1]\to\mathbb{R}$ be continuous such that $f(x)\in\mathbb{Q}$ for any $x\in[0,1]$. Intuitively I feel that $f$ is constant, since $\mathbb{Q}$ is dense in $\mathbb{R}$.

How can I formally write this down?

• It is constant, but not because $\mathbb{Q}$ is dense. It's constant because $\mathbb{Q}$ is totally disconnected but $[0,1]$ is connected. Oct 10, 2013 at 17:46
• @DanielFischer with the mean value theorem, one could use density to prove it must pass through some irrational Oct 10, 2013 at 17:50
• @Jean-Sébastien That would use the denseness of $\mathbb{R}\setminus\mathbb{Q}$. Oct 10, 2013 at 17:51
• @DanielFischer True enough! Oct 10, 2013 at 17:52
• @copper.hat I meant the intermediate value theorem. I somehow always confuse the name of these Oct 10, 2013 at 18:18

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}$.

• Hi, similar argument works if $f$ takes only irrational values, right? :)
– Diya
May 10, 2015 at 16:30
• True - the rational numbers are also dense in \mathbb{R}. May 12, 2015 at 2:48

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.

by ways of contradiction assume $f$ is not constant .

$f$ is continuous on a closed and bounded interval then $f$ has absolute max and min .i.e.$\exists$ $x_0,y_0 \in [0,1]$ such that $f(x_0)\le f(x) \le f(y_0)$ $\forall x \in [0,1]$ from assumption $f(x_0)\ne f(y_0)$ and $f(x_0),f(y_0)$ are rational value (from question) by density theorem $\exists$ $r \in Q'$ such that $f(x_0)<r<f(y_0)$ then by intermediate value theorem $\exists c \in [0,1]$ such that $f(c)=r$ which contradicts with f has only rational value therefore $f$ is constant.

• For some basic information about writing maths on this site see e.g. here, here, here and here. Jan 3, 2015 at 10:36
• thank you I think it's become most better Jan 14, 2015 at 22:53