# Does there exist a continuous nonconstant function $f$ that maps almost all irrationals to rationals? [closed]

Let $$f$$ be a continuous nonconstant function on the reals. Could it map almost all irrationals to rationals?

This is impossible if $$f$$ maps all irrationals to rationals, by a well known result.

This is impossible if $$f$$ preserves measure 0 sets, because then $$\{f(x)| f(x)\textrm{ is irrational}\}$$ has measure $$0$$.

• Why the downvote? Is this well-known or trivial for some reason? May 9, 2019 at 16:56
• "This is impossible if f maps all irrationals to rationals, by a well known result." Can you give a reference to this? May 9, 2019 at 17:11
• @IosifPinelis: if it's nonconstant, its image contains an interval, and you don't have enough rationals to map to all the irrationals in that interval. May 9, 2019 at 19:44
• @NikWeaver : But the statement quoted in my comment was about mapping all irrationals to rationals, rather than vice versa. May 10, 2019 at 0:23
• @IosifPinelis: since $f$ is continuous and nonconstant its range contains an interval $[a,b]$. If all irrationals map to rationals then you don't have enough points left in the domain to hit all the irrationals in $[a,b]$. May 10, 2019 at 2:16

Take the Cantor function $$c:[0,1] \to [0,1]$$. It is rational almost everywhere. To create a function $$f: \mathbb R \to \mathbb R$$, apply a transform like $$x \mapsto \frac {\sin x + 1} 2$$, i.e., $$f(x)=c(\frac {\sin x + 1} 2)$$.
• Or set $f(x+1)=f(x)+1$ for $x\notin[0,1]$. May 9, 2019 at 17:10