Is there a simple, constructive, 1-1 mapping between the reals and the irrationals?

Is there a simple, constructive, 1-1 mapping between the reals and the irrationals?

I know that the Cantor–Bernstein–Schroeder theorem implies the existence of a 1-1 mapping between the reals and the irrationals, but the proofs of this theorem are nonconstructive.

I wondered if a simple (not involving an infinite set of mappings) constructive (so the mapping is straightforwardly specified) mapping existed.

I have considered things like mapping the rationals to the rationals plus a fixed irrational, but then I could not figure out how to prevent an infinite (possible uncountably infinite) regression.


Map numbers of the form $q + k\sqrt{2}$ for some $q\in \mathbb{Q}$ and $k \in \mathbb{N}$ to $q + (k+1)\sqrt{2}$ and fix all other numbers.


Let $\phi_i$ be an enumeration of the rationals. Let $\eta_i$ be some countable sequence of distinct irrationals; say for concreteness that $$\eta_i = \frac{\sqrt2}{2^{i}}.$$

Then define $$f(x) = \begin{cases} \eta_{2i} & \text{if $x$ is rational and so equal to $\phi_i$ for some $i$} \\ \eta_{2i+1} & \text{if $x$ is irrational and equal to $\eta_i$ for some $i$} \\ x & \text{otherwise} \end{cases}$$

$f$ is now a bijective mapping between the reals and the irrationals.

This mapping was found by Cantor in 1877; I saw it in the paper "Was Cantor Surprised?" by Fernando Q. Gouvêa. (American Mathematical Monthly, 118, March 2011, pp. 198–209.) The construction is described at the middle of page 208.