Construct a bijection from $\mathbb{R}$ to $\mathbb{R}\setminus S$, where $S$ is countable

Two questions:

  1. Find a bijective function from $(0,1)$ to $[0,1]$. I haven't found the solution to this since I saw it a few days ago. It strikes me as odd--mapping a open set into a closed set.

  2. $S$ is countable. It's trivial to find a bijective function $f:\mathbb{N}\to\mathbb{N}\setminus S$ when $|\mathbb{N}| = |\mathbb{N}\setminus S|$; let $f(n)$ equal the $n^{\text{th}}$ smallest number in $\mathbb{N}\setminus S$. Are there any analogous trivial solutions to $f:\mathbb{R}\to\mathbb{R}\setminus S$?


Solution 1:

An explicit bijection $(0,1) \to [0,1]$ for part $1$ is given by:

$$f\left(\frac{1}{2}\right) = 0,\quad f\left(\frac{1}{3}\right) = 1,\quad f\left(\frac{1}{n}\right) = \frac{1}{n-2}\ \textrm{for}\ n > 3,$$

$$f(x) = x\ \textrm{for}\ x\ \textrm{not equal to a reciprocal of an integer}$$

For a bijection $\mathbb{R}$ to $\mathbb{R}\setminus S$, we can number the elements of $S$ (because $S$ is countable) as $s_1, s_2, s_3, \dots$ Choose an infinite sequence $t_1, t_2, \dots$ of distinct elements of $\mathbb{R}$, none of which are in $S$. Then define:

$$g(s_i) = t_{2i},\quad g(t_i) = t_{2i+1},\quad g(x) = x\ (\textrm{otherwise}).$$

This is a bijection from $\mathbb{R}$ to $\mathbb{R}\setminus S$.

Solution 2:

The proof of the Schroeder-Bernstein theorem allows you to get a bijection for 1, since we have an injection $(0,1) \to [0,1]$ and a bijection $f: [0,1] \to [1/4, 3/4] \subset (0,1)$ (say $x \to x/2 +1/4$). The function's definition will be somewhat messy (basically, it depends on how many times you can lift a point under these to injections already defined, and specifically the parity of the number of times), but it'll do it.

For 2, iterate this construction to get a bijection $R \to R - N$. Then given any countable set $S$, define the map of $R$ that interchanges $N$ and $S$ and leaves every other point fixed. Then the composition of the first bijection with this second map is your bijection.

Continuity considerations imply that the map can't be continuous: in 1, for instance, we'd otherwise have that $(0,1)$ is compact, which it's not.