Proving that if $f$ is continuous on $\mathbb{R}$ and that the image of $f$ is a subset of $\mathbb{R}$\ $\mathbb{Q}$, then $f$ is a constant function I was asked to prove that for a function $f$ that is continuous on $\mathbb{R}$, whose image is a subset of $\Bbb{R}$ \ $\Bbb{Q}$, $f$ is a constant function.
My proof goes as follows:
Suppose for a contradiction that f is not constant, so there exists $x_1$ $\neq$ $x_2$ so that $f(x_1)$ $\neq$ $f(x_2)$, say, $x_1$,$x_2$ $\in$ $\Bbb{Q}$.
Now, f is continuous at c for every c $\in$ $\Bbb{R}$, so $f_{[x_1,x_2]}$:[$x_1$,$x_2$] $\to$ $\Bbb{R}$ is continuous at c for every c $\in$ [$x_1$,$x_2$].
Consider $v \in \Bbb{Q}$ and $v \in (f(x_1),f(x_2))$, which exists by completeness of the set of real numbers.
There exists $x_0 \in (x_1,x_2)$ such that $f(x_0)=v \in \Bbb{Q}$, by the intermediate value theorem.
A contradiction, since the image of $f$ is a subset of $\Bbb{R}$ \ $\Bbb{Q}$.
So $f$ is a constant function. $\square$
I feel there is an easier way, to prove this; nevertheless, what do you think of my proof, does it hold ?
Thank you!
 A: This is exactly the proof that came to mind when I read your question, and you expressed it well - except I would say that $v$ exists by density of $\mathbb Q$ in $\mathbb R$.
A: The proof is good and – as far as I can see – the "go to" proof.
There are a few mistakes I'd like to point out:

*

*You assume that $x_1, x_1 \in \mathbb{Q}$. This is not necessary for your further proof (as Cameron already pointed out in a comment). And it is also not possible to assume this without loss of generality: Why should they be rational?


*Completeness of the real numbers does not yield a rational $v \in (f(x_1), f(x_2))$. As toe-pose points out in their answer, what you need is density of $\mathbb{Q}$.
Completeness of $\mathbb{R}$ is not the same as density of $\mathbb{Q} \subset \mathbb{R}$. However $\mathbb{R}$ is the completion of $\mathbb{Q}$; maybe this confused you?


*For the intervals $(x_1, x_2)$ and $(f(x_1), f(x_2))$ to make sense, you assume silently that $x_1 < x_2$ and $f(x_1) < f(x_2)$. When proceeding as detailed as you did, you could be more explicit about that. While the assumption $x_1 < x_2$ can be arranged without loss of generality, the second one need not hold. You can do a case distinction, for example.
A: The first idea that came to my mind is the following one:
Since $\mathbb{R}$ is connected and $f$ is continuous, $f(\mathbb{R})$ is connected. Consider $x,y\in\mathbb{R}$ with $x\neq y$. If $f(x)\neq f(y)$, we can assume without loss of generality that $f(x)<f(y)$. Then, since $f$ is continuous, $f([x,y]\bigcup[y,x])$ must be an interval (since it has to be connected), so $[f(x),f(y)]\subset f([x,y]\bigcup[y,x])\subset f(\mathbb{R})$ and since is a non-trivial interval, $\exists q\in\mathbb{Q}:q\in[f(x),f(y)]\subset f(\mathbb{R})$ so $f(\mathbb{R})\nsubseteq\mathbb{R}\diagdown\mathbb{Q}$ and we've reached a contradiction because we assumed there were in fact $x,y\in\mathbb{R}$ with $x\neq y$ and $f(x)\neq f(y)$.
This proof (if correct) can be extended to $f(\mathbb{R})\subset\mathbb{Q}$ and $f$ being continuous.
