# 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

• What constant function has the property you want?
– lulu
Aug 3 '19 at 18:34
• I think that simple counting should do the job. If $f$ is not constant, take $a,b$ with $f(b)>f(a)$. Then there are uncountably many irrationals between $f(a)$ and $f(b)$ but only countably many rationals which might be mapped to them.
– lulu
Aug 3 '19 at 18:35
• @lulu $f$ will not nonconstant because continious image of connected set is connected Aug 3 '19 at 18:37

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.

• So, erm. Why the downvote? Aug 3 '19 at 19:51