# There exists a continuous function $f$ such that $f(\Bbb Q) \subseteq \Bbb R\setminus\Bbb Q$ and $f(\Bbb R\setminus\Bbb Q)\subseteq\Bbb Q$ [duplicate]

True or false: There exists a continuous function $$f: \Bbb R \to \Bbb R$$ such that $$f(\Bbb Q) \subseteq {\Bbb R}\setminus {\Bbb Q}$$ and $$f({\Bbb R}\setminus {\Bbb Q}) \subseteq {\Bbb Q}$$.

My attempt: I was trying to use the sequential definition of continuity. Consider $$a \in \Bbb R$$ then we have a seqn $${x_n}$$ of rational numbers converging to $$a$$ and we have a seqn $${y_n}$$ of irrational numbers converging to $$a$$. Then what will be $$f(a)$$? I was thinking that in one way $$f(a) \in \Bbb Q$$ and on the other way $$f(a) \in {\Bbb R}\setminus {\Bbb Q}$$ . But I am wrong $$\{f(x_n)\} \subseteq {\Bbb R}\setminus {\Bbb Q}$$ and $$\{f(y_n)\} \subseteq {\Bbb Q}$$ still $$f(a)$$ can be anywhere.

Is there any way to fix my attempt or any other possible idea?

• Hint: suppose $f$ is nonconstant, and let $a,b$ be two of its values. Then $f$ should take uncountably many irrational values between $a,b$. – Wojowu Jun 16 '19 at 22:11
• @Wojowu In fact you don't have to suppose $f$ is nonconstant, it is a consequence of the assumptions. – TSF Jun 16 '19 at 22:14
• @TonyS.F. My argument would require considering two cases, constant vs nonconstant. The former is immediate though. – Wojowu Jun 16 '19 at 22:20

There is a nice proof of this fact, which doesn't use cardinality. Assume such $$f:\Bbb R\to \Bbb R$$ exists. You can do two modifications to $$f$$ which wont change the property that $$f(\Bbb Q) \subseteq {\Bbb R}\setminus {\Bbb Q}$$ and $$f({\Bbb R}\setminus {\Bbb Q}) \subseteq {\Bbb Q}$$:
• You can add a rationnal number to $$f$$, i.e take $$\tilde{f}$$ defined by $$\tilde{f}(x)=f(x)+p/q$$.
• You can multiply $$f$$ by a rational number, i.e take $$\tilde{f}$$ defined by $$\tilde{f}(x)=(p/q)\times f(x)$$.
Now define $$g=f\vert_{[0,1]}$$. Then $$g$$ is continuous and bounded. By adding a "big" rational number to $$f$$ you can assume $$g\geq 0$$. By multiplying $$f$$ by a "small" positive rational number you can also assume $$g\leq 1$$. Finally you have found $$g:[0,1]\to [0,1]$$ which is continuous and send rational numbers to irrational and conversely. But this is not possible, as $$g$$ must have a fixed point.
• You said “$g$ is continuous and bounded”. What’s $g$? – Lubin Jun 16 '19 at 23:26
• Why does $g$ have a fixed point? Is it immediate? – Ri-Li Jun 16 '19 at 23:45
• @Hunter It's a "classical result", just apply the intermediate value theorem to the continuous function $x\mapsto g(x)-x$. See here. – Adam Chalumeau Jun 16 '19 at 23:47