Is there a way to prove the following result using connectedness?

Result:Let J=R∖Q denote the set of irrational numbers. There is no continuous map f:R→R such that f(Q)⊆J and f(J)⊆Q.

**Answer**

Here’s a way to use connectedness, really amounting to using the intermediate value theorem.

If f(Q)⊆R∖Q and f(R∖Q)⊆Q, then f(0)≠f(√2). Because intervals are connected in R and f is continuous, f[0,√2] is connected. Because connected subsets of R are intervals, f[0,√2] contains the interval [min{f(0),f(√2)},max{f(0),f(√2)}]. The set of irrational numbers in this interval is uncountable, yet contained in the countable set f(Q), a contradiction.

A slightly briefer outline: The hypothesis implies that f is nonconstant with range contained in the countable set Q∪f(Q), whereas the intermediate value theorem and uncountability of R imply that a nonconstant continuous function f:R→R has uncountable range.

**Attribution***Source : Link , Question Author : user10 , Answer Author : Jonas Meyer*