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$.

  • $\begingroup$ Why the downvote? Is this well-known or trivial for some reason? $\endgroup$ May 9, 2019 at 16:56
  • $\begingroup$ "This is impossible if f maps all irrationals to rationals, by a well known result." Can you give a reference to this? $\endgroup$ May 9, 2019 at 17:11
  • $\begingroup$ @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. $\endgroup$
    – Nik Weaver
    May 9, 2019 at 19:44
  • $\begingroup$ @NikWeaver : But the statement quoted in my comment was about mapping all irrationals to rationals, rather than vice versa. $\endgroup$ May 10, 2019 at 0:23
  • $\begingroup$ @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]$. $\endgroup$
    – Nik Weaver
    May 10, 2019 at 2:16

1 Answer 1


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)$.

  • 1
    $\begingroup$ Or set $f(x+1)=f(x)+1$ for $x\notin[0,1]$. $\endgroup$ May 9, 2019 at 17:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.