Does there exist any continuous function $f:\mathbb{R} \to \mathbb{R}$ such that $f(\mathbb{R}\setminus \mathbb{Q}) = \mathbb{R}$?

My attempt to the problem is first I intend to make a perfect nowhere dense set of irrational numbers of measure $0$ like cantor set(and that I guess we could do)..now make such type of function like cantor function on that closed interval end with irrational endpoints from which we initially start work to make such cantor set types set consisting with irrationals only.


Solution 1:

There is a continuous map of the unit interval onto unit square (so called Peano curve) Compose it with the projection onto $x$ -axis. One gets a continuous map from the unit interval onto unit interval such that inverse image of each point is uncountable. Hence, for each rational there must be an irrational mapped into it.

Solution 2:

Let $g$ be defined on $[0,1]$ with $$g(0)=0, g(1/\sqrt3)=1, g(2/3)=0,g(1)=1,$$ and the function is linear between these values. Then define $$f(x)=g(x-\lfloor x\rfloor )+\lfloor x\rfloor.$$

You can replace $1/\sqrt3,2/3$ with any pair $0<a<b<1$ with exactly one of $a,b$ rational.

Then for any real $r,$ $f^{-1}(r)$ has at least three elements (more if $r$ is an integer) and at least one of these elements is irrational.

Assume $r=n+y$ for $n\in\mathbb Z$ and $0\leq y<1.$

If $y=0,$ $f(n-1+1/\sqrt3)=r.$

If $r$ is irrational, then $f(x)=r$ for $x=n+2/3+y/3,$ which is irrational.

If $r$ is rational and not an integer, then $f(x)=r$ for $x=n+y/\sqrt3,$ which is irrational.