# Continuity leads to constant function (Assignment question)

I have been attempting to do the following question by contradiction. However, I just got stuck at where to use the given continuity condition. It would be really appreciated if you can possibly give a further hint to solving this problem.

Here it goes

Let $f(x):\mathbb{R} \rightarrow \mathbb{Q}$ is a continuous function. Prove that $f$ is a constant.

-
Can you find a real number between two given rationals? –  Pedro Tamaroff May 5 '12 at 0:18
More to the point, can you find an irrational number between two rationals? –  Robert Israel May 5 '12 at 0:31
Yes, it was my initial idea of using Density Theorem. However, I do not see the connection between that with the function. –  Viet Hoang Quoc May 5 '12 at 0:42
Look at this –  leo May 5 '12 at 0:49

Now, $\mathbb{R}$ is connected--that is just a fact. Now, $\mathbb{Q}$ is not connected (in fact, it's totally disconnected) since given any irrational number $\xi$ one has that $\mathbb{Q}=[(-\infty,\xi)\cap\mathbb{Q}]\cup[(\xi,\infty)\cap\mathbb{Q}]$ is a disconnection.
The formal one as follows For all $\epsilon >0$, there exists $\delta >0$ such that for all $x \in \mathbb{R}$ satisfying $|x-x_0| < \delta$, one has $|f(x)-f(x_0)| < \epsilon$. –  Viet Hoang Quoc May 5 '12 at 0:43
@VietHoangQuoc Ditch that definition here. Use the following definition: A function $f: X \rightarrow Y$ between two topological spaces is continuous if for every open set $U$ in $Y$, the preimage of $U$ under $f$ is open in $X$. –  user38268 May 5 '12 at 0:46
Here is another similar type of question proving the function is constant using the continuity definition, Let $f: [-1,1] \to \mathbb{R}$ be a function with $f(x)=f(x^2)$ for all $x \in (-1,1)$. Suppose that $f$ is continuous at 0. Prove that $f$ is a constant. –  Viet Hoang Quoc May 5 '12 at 1:03