Does there exist a continuous onto function from $\mathbb{R}-\mathbb{Q}$ to $\mathbb{Q}$? (where domain is all irrational numbers)

I found many answers for contradicting the fact that there doesnt exist a continuous function which maps rationals to irrationals and vice versa.

But proving that thing was easier since our domain of definition of function was a connected set, we could use that connectedness or we could use the fact that rationals are countable and irrationals are uncountable.

But in this case those properties are not useful. I somehow think that baire category theorem might be useful but I am not good at using it.

  • $\begingroup$ Try $f(x)=1$... $\endgroup$ Sep 13, 2015 at 18:07
  • 2
    $\begingroup$ you missed onto. $\endgroup$ Sep 13, 2015 at 18:07
  • 1
    $\begingroup$ @DavidC.Ullrich - OP asked for an onto function. $\endgroup$ Sep 13, 2015 at 18:07

2 Answers 2


Yes. Say $E_n$ is the set of irrationals in the interval $(n,n+1)$. Say $(q_n)$ is an enumeration of $\Bbb Q$. Define $f(x)=q_n$ for $x\in E_n$.

  • $\begingroup$ This is amazing!! How could you create such a function? I mean how did you come up with this? $\endgroup$ Sep 13, 2015 at 18:14
  • 1
    $\begingroup$ Can you give more explanation , what is enumeration of rational ? $\endgroup$ Sep 13, 2015 at 18:21
  • $\begingroup$ I guess this construction can also be used to show that, if $X$ is any topological space which can be partitioned into a countably infinite collection of open sets (which are then automatically closed too) and $Y$ is any countable topological space, then there exists a continuous surjection $X \to Y$. $\endgroup$
    – Mike F
    Sep 13, 2015 at 18:25
  • $\begingroup$ @ShubhamUgare The rationals are countable. An enumeration of the rationals is just a sequence containing each rational exactly once. (Here just for convenience we took that "sequence" to be indexed by integers instead of natural numbers.) $\endgroup$ Sep 13, 2015 at 18:27
  • $\begingroup$ @LandonCarter I have a hard time saying how I came up with that, sorry. Seemed like an obvious thing... $\endgroup$ Sep 13, 2015 at 18:30

Yes, there exists such a function.

Biject $\mathbb{Q}$ with $\mathbb{Z}$ to get $\mathbb{Q} = \{q_n \mid n \in \mathbb{Z}\}$, and let $\mathbb{I}$ be the set of irrational numbers.

Define $I_n$ for $n \in \mathbb{Z}$ as $\mathbb{I} \cap (n, n+1)$. Then define $f(x) = q_n$ for all $x \in I_n$.

This is continuous, since for any irrational number in $I_n$, there is a small neighbourhood of it which is contained entirely within $I_n$ (because the "endpoints" of $I_n$ were chosen to be rational)

  • $\begingroup$ Did you notice that that's exactly the same as the example I gave? $\endgroup$ Sep 13, 2015 at 18:26
  • 5
    $\begingroup$ Yes - but we answered at almost the same time. $\endgroup$ Sep 13, 2015 at 18:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .