# Continuous function which has only rational values. [duplicate]

If $f:[a,b]\to\mathbb{R}$ is a continuous function and $f(x)\in\mathbb{Q}$ for all $x\in[a,b]$ then what can say about $f$?

My try: I think f should be constant, if it is not constant then it contradicts the continuity. Can anyone prove that f is constant?

-

## marked as duplicate by Martin Sleziak, Arthur Fischer♦Jul 16 '14 at 8:22

Intermediate value theorem. –  Adam Hughes Jul 16 '14 at 6:09
@AdamHughes That should be an answer! –  Mike Miller Jul 16 '14 at 6:11
As you wish, one moment. –  Adam Hughes Jul 16 '14 at 6:11
–  Martin Sleziak Jul 16 '14 at 7:14

$$\begin{cases}a\le x,y\le b \\f(x)\ne f(y)\end{cases}$$
WLOG assume $f(x)<f(y)$ (if not: switch their labels). Then by the intermediate value theorem, $f$ takes all values in the interval $[f(x),f(y)]$. Since there are infinitely many irrationals between any two real numbers, $f$ takes on an irrational value: a contradiction. So $f$ is constant.
Suppose if f is not constant then there are x and y in [a,b] such that $f(x)\not=f(y)$ then it also takes any value between f(x) and f(y) at some point in [x,y].Which is contradiction to $f(x)\in\mathbb{Q}$ for all $x\in[a,b]$