Is there a continuous function $f\colon \mathbb{R} \to \mathbb{R}$ such that $f(\mathbb{Q}) \subseteq \mathbb{R} \setminus \mathbb{Q}$? Is  there  a  continuous  function $f\colon \mathbb{R} \rightarrow \mathbb{R}$ such that   $f(\mathbb{Q}) \subseteq \mathbb{R} \setminus \mathbb{Q}$ and $ f(\mathbb{R} \setminus \mathbb{Q}) \subseteq \mathbb{Q}$ ?
My answer : I think  yes, take  constant function Actually this  logics  came  from my mind that  if A  is connected then $f\colon A \rightarrow  \{\pm 1\}$ is constant function
 A: If you take a constant function, i.e., pick some $a\in\mathbb{R}$ and set $f(x) = a$ for all $x$, then


*

*$f(\mathbb{Q}) = \{a\}$

*$f(\mathbb{R}\setminus \mathbb{Q}) = \{a\}$
and so, by the condition on $f$, you need both $\{a\}\subseteq \mathbb{R}\setminus \mathbb{Q}$ and $\{a\}\subseteq \mathbb{Q}$. That is, you need $a\in\mathbb{Q}\cap (\mathbb{R}\setminus \mathbb{Q})$: this is impossible. 
So no constant function can work.

And actually, there is no continuous function $f$ that works. The argument is similar to this answer to a related question: suppose $f$ works. Then


*

*$f(\mathbb{R}\setminus \mathbb{Q})$ is countable, since $f(\mathbb{R}\setminus \mathbb{Q})\subseteq \mathbb{Q}$ and $\mathbb{Q}$ is countable.

*$f(\mathbb{Q})$ is countable, since it is the image of $\mathbb{Q}$, which is countable.
So $f(\mathbb{R}) = f(\mathbb{R}\setminus \mathbb{Q}) \cup f(\mathbb{Q})$ is countable. But $f$ is continuous and $\mathbb{R}$ is an interval, so $f(\mathbb{R})$ must be an interval too... and the only non-empty countable intervals are the singletons. 
So $f(\mathbb{R})$ must be a singleton, i.e., $f$ must be a constant. But we just saw that this is not possible.
