1. constant and continuous

Let $f: \mathbb{R}\rightarrow \mathbb{R}$ be a continuous function such that $f(x)$ is a rational number for every real input $x$. Show that $f$ must be a constant function.

Heres what I have:

Let $x$ be any real number. There must exist a sequence of rational numbers $\{r_n\}\rightarrow x$. Since $f$ is continuous, we can conclude that $f(x)=\lim_{x\to c}(r_n)=c$.

Im iffy on my last sentence and am thinking there could be a better way to do this using the EVT?

2. Suppose $f(x)\neq f(y)$ where x<y. Chuse an irrational $\xi$ between f(x) and f(y). Then by the IVT, there is point between x and y where f assumes the value $\xi$. But this contradicts the fact that f is always rational.

Topologically, since R is connected and Q is totally disconnected, every continuous map from R to Q is constant. (This is a generalization of the IVT.)

3. So, if f is not constant on an interval [a,b] then it will hit at least one irrational contradicting that f(x) is rational, right? You're saying that, we can always choose an irrational for some c in [a,b] according to the IVT, but....blah I guess i'm having trouble putting the idea into words...ugh

4. Ja. The IVT says that the continuous image of an interval is an interval. So since any interval that is not a single point contains an irrational, the image of f must be a single point.

5. Ah! got it

6. NOTE! OP! This is not meant to help with the question, this is just an interesting side note for maddas...though I'm not sure he'll care. I just noticed it.

There is a slightly weaker condition than totally disconnected that one can impose. Suppose that $\varphi:G\to G'$ is continuous where $G,G'$ are topological groups $G$ is connected and and given any $g\in G'-\{e\}$ there exists a separation of $g$ and $\{e\}$. Then, $\varphi$ must be constant.
This follows since $\psi:G\times G\to G'g,h)\mapsto \varphi(g)(\varphi(h))^{-1}" alt="\psi:G\times G\to G'g,h)\mapsto \varphi(g)(\varphi(h))^{-1}" /> is continuous $\psi(\Delta)=\{e\}$ and so if $\varphi$ weren't constant then $\varphi(x)\ne\varphi(y)\implies \psi(x,y)\ne e$ but since we can separate $\psi(x,y)$ and $\{e\}$ I think you can see where this is going.
EDIT: The above is a farce. Not because it's incorrect but because if you can separate $\{e\}$ and any point then the space is actually totally disconnected. This follows since if $x\ne y\implies xy^{-1}\ne e$ and so there exists a disconnection $A\cup B=G$ such that $xy^{-1}\in A,e\in B$ and so $x\in Ay,y\in By$ there are open, non-empty and disjoint since the mapping $L_y:G\to G:g\mapsto gy$ is a homeomorphism. Ahh! Topological groups always make me look stupid haha.