Prove that continuous functions mapping irrationals to rationals must be constant

Let $f\colon[0,1] \to \mathbb{R}$ be a continuous function such that any irrational number is mapped to a rational number. Then $f$ must be a constant.

Well, the context isn't that much, I was reading some interesting function constructions on Hardy's book. Then raised this question.

As the solution suggest it is an elementary exercise. But definitely interesting.


For convenience, let $\mathbb{I} = [0,1]\cap (\mathbb{R}\setminus\mathbb{Q})$, which is uncountable, and $\mathbb{J} = [0,1]\cap\mathbb{Q}$, which is countable.

  • $f(\mathbb{I}) \subseteq \mathbb{Q}$ is countable.
  • $f(\mathbb{J})$ is countable since $\mathbb{J}$ is.

So $f([0,1])=f(\mathbb{I})\cup f(\mathbb{J})$ is countable.

Now, $[0,1]$ is an interval, and the image of an interval by a continuous function is an interval. So $f([0,1])$ is a countable interval, which means...