TITLE: Must a continuous $\varphi:\mathbb R^n\to\mathbb R^n$ with $\mathbb Q^n \subseteq \varphi[\mathbb Q^n]$ be surjective?
QUESTION [8 upvotes]: Let $\varphi:\mathbb R^n \to \mathbb R^n$ be just some continuous function.
If the image of $\varphi$ happens to contain $\mathbb Q^n$, does it follow that in fact all of $\mathbb R^n$ is contained in the image as well?
No, it does not.  For instance, the map given by
$$(x,y)\overset{\varphi}{\longmapsto} (xy-1+\pi, x^2(xy-1)+y)$$
has as its image every point in $\mathbb R^2$ except for $(\pi,0)$.
But now suppose instead that $\mathbb Q^n$ is actually contained in the image of just $\mathbb Q^n$.  That is, instead of requiring only that
$$\mathbb Q^n \subseteq \varphi[\mathbb R^n]\phantom{.}$$
we require that in fact
$$\mathbb Q^n \subseteq \varphi[\mathbb Q^n].$$
Question. Does it then follow that $\varphi[\mathbb R^n]=\mathbb R^n$, or is there a counterexample?

REPLY [13 votes]: A counterexample for $n=2$ is the map $\varphi(x,y) = (x,(x^2-2)y)$. Each point $(r,s)\in\mathbb{Q}^2$ is the image of $\left(r,\frac{s}{r^2-2}\right)\in\mathbb{Q}^2$, but e.g. $(\sqrt{2},1)\not\in\varphi(\mathbb{R}^2)$.