One-to-one correspondence between the union of rational numbers and the open interval $(0, 1)$ and the open interval $(0, 1)$ Can someone show me how to define a function $g: (0, 1) \cup \mathbb{Q} \mapsto (0, 1)$ such that $g$ is one-to-one and onto? What comes to mind is some sort of diagonalization argument function or a piecewise function of the form $g(x)=x$ if $x \in (0, 1)$ and $g(x)=1/x$ if $x \in \mathbb{Q}$ and $x > 1$. Would any of those work? If not, please define one for me. Intuitively, it seems such a correspondence is possible.
 A: The set $\mathbb Q\setminus(0,1)$ is countable, which means that there is a bijection $b\colon\mathbb N\longrightarrow\mathbb Q\setminus(0,1)$. Now consider the map$$\begin{array}{rccc}\beta\colon&\mathbb Q\cup(0,1)&\longrightarrow&(0,1)\\&x&\mapsto&\begin{cases}x&\text{ if $x\neq\frac1n$ for any $n\in\mathbb N$ and $x\in(0,1)$}\\\frac1{2b^{-1}(n)}&\text{ if }x\in\mathbb Q\setminus(0,1)\\\frac1{2n-1}&\text{ if $x=\frac1n$ for some $n\in\mathbb N$.}\end{cases}\end{array}$$Now, prove that $\beta$ is a bijection.
A: An explicit one, taken from this answer.
$$
f(x)=\begin{cases} 1+\frac{1}{x-2} & x<0 \\ \frac{1}{x+2} & x\ge 0
\end{cases}
$$
is a bijection $\mathbb Q \to (0,1) \cap \mathbb Q$. So now we do what @quarague wrote in their answer:
$$
g(x) = \begin{cases}
x & x\in(0,1)\setminus\mathbb Q \\
f(x) & x\in \mathbb Q
\end{cases}
$$
is a bijection $ (0,1) \cup \mathbb Q \to (0,1)$.
A: Let $b : \mathbb{Q} \rightarrow \mathbb{Q} \cap (0,1)$ be a bijection. This has to exist because both sets are countably infinite. If needed I could construct one explicitly. Then you can simply define $g(x) = x$ for $x \in (0,1) \setminus \mathbb{Q}$ and $g(x) = b(x)$ for $x \in \mathbb{Q}$.
A: Making use of two following facts,


*

*$\mathbb{Q} \approx \mathbb{N}=\{1,2,\cdots\}$

*$(0,1]\approx(0,1)$
we can construct one such a bijection in the question.
First, the second fact above tells us $(0,\frac{1}{2}]\approx(0,\frac{1}{2}) , (\frac{1}{2},\frac{3}{4}]\approx(\frac{1}{2},\frac{3}{4}),\cdots$.
Consequently, $(0,1)=\cup_{k\in\mathbb{N}}\left(1-({\frac{1}{2}})^{k-1},1-({\frac{1}{2}})^k\right] \approx (0,1)-\{\frac{1}{2},{(\frac{1}{2})}^2,\cdots\} =\cup_{k\in\mathbb{N}}\left(1-({\frac{1}{2}})^{k-1},1-({\frac{1}{2}})^k\right)$.
Then, with the clear bijection $\mathbb{N}\approx\{\frac{1}{2},{(\frac{1}{2})}^2,\cdots\}$, it gives us $(0,1)\cup\mathbb{N}\approx(0,1)$. And then the first fact above!
(Now I see, the first fact should be  $\mathbb{Q}-(0,1)\approx \mathbb{N}$. I just cared it as disjoint union...,or if it were disjoint, this kind of answer could be helpful !?)
(Any comments! if needed, or whatever!)
A: What about$$\begin{array}{rccc}g\colon&\mathbb Q\cup(0,1)&\longrightarrow&(0,1)\\&g(x)&\mapsto&\begin{cases}x&\text{ if $x\in(0,1) \setminus \mathbb{Q}$}\\\frac1{x}&\text{ if } x>1 \text{and} x\in\mathbb Q\setminus(0,1)\\\end{cases}\end{array}$$
Why is this not a bijection?
