Bijection between an open and a closed interval Recently, I answered to this problem:

Given $a<b\in \mathbb{R}$, find explicitly a bijection $f(x)$ from
  $]a,b[$ to $[a,b]$.

using an "iterative construction" (see below the rule).
My question is: is it possible to solve the problem finding a less exotic function?
I mean: I know such a bijection cannot be monotone, nor globally continuous; but my $f(x)$ has a lot of jumps... Hence, can one do without so many discontinuities?

W.l.o.g. assume $a=-1$ and $b=1$ (the general case can be handled by translation and rescaling).
Let:
(1) $X_0:=]-1,-\frac{1}{2}] \cup [\frac{1}{2} ,1[$, and
(2) $f_0(x):=\begin{cases}
    -x-\frac{3}{2} &\text{, if } -1<x\leq -\frac{1}{2} \\ -x+\frac{3}{2} &\text{,
    if } \frac{1}{2}\leq
    x<1\\ 0 &\text{, otherwise} \end{cases}$,
so that the graph of $f_0(x)$ is made of two segments (parallel to the line $y=x$) and one segment laying on the $x$ axis; then define by induction:
(3) $X_{n+1}:=\frac{1}{2} X_n$, and
(4) $f_{n+1}(x):= \frac{1}{2} f_n(2 x)$
for $n\in \mathbb{N}$ (hence $X_n=\frac{1}{2^n} X_0$ and $f_n=\frac{1}{2^n} f_0(2^n x)$).
Then the function $f:]-1,1[\to \mathbb{R}$:
(5) $f(x):=\sum_{n=0}^{+\infty} f_n(x)$
is a bijection from $]-1,1[$ to $[-1,1]$.
Proof: i. First of all, note that $\{ X_n\}_{n\in \mathbb{N}}$ is a pairwise disjoint covering of $]-1,1[\setminus \{ 0\}$. Moreover the range of each $f_n(x)$ is $f_n(]-1,1[)=[-\frac{1}{2^n}, -\frac{1}{2^{n+1}}[\cup \{ 0\} \cup ]\frac{1}{2^{n+1}}, \frac{1}{2^n}]$.
ii. Let $x\in ]-1,1[$. If $x=0$, then $f(x)=0$ by (5). If $x\neq 0$, then there exists only one $\nu\in \mathbb{N}$ s.t. $x\in X_\nu$, hence $f(x)=f_\nu (x)$. Therefore $f(x)$ is well defined.
iii. By i and ii, $f(x)\lesseqgtr 0$ for $x\lesseqgtr 0$ and the range of $f(x)$ is:
$f(]-1,1[)=\bigcup_{n\in \mathbb{N}} f(]-1,1[) =[-1,1]$,
therefore $f(x)$ is surjective.
iv. On the other hand, if $x\neq y \in ]-1,1[$, then: if there exists $\nu \in \mathbb{N}$ s.t. $x,y\in X_\nu$, then $f(x)=f_\nu (x)\neq f_\nu (y)=f(y)$ (for $f_\nu (x)$ restrited to $X_\nu$ is injective); if $x\in X_\nu$ and $y\in X_\mu$, then $f(x)=f_\nu (x)\neq f_\mu(y)=f(y)$ (for the restriction of $f_\nu (x)$ to $X_\nu$ and of $f_\mu(x)$ to $X_\mu$ have disjoint ranges); finally if $x=0\neq y$, then $f(x)=0\neq f(y)$ (because of ii).
Therefore $f(x)$ is injective, hence a bijection between $]-1,1[$ and $[-1,1]$. $\square$
 A: Here you have simpler construction.
Let $(a_n)$ be the sequence in $(a,b)$ defined by $a_n = a + \frac{b-a}{2^n}$. Then let $f\colon [a,b] \to (a,b)$ be given by
$$
f(x) = \begin{cases}
a_1, & x = a,\\
a_2, & x = b,\\
a_{n+2}, & x = a_n, n = 1,2,\dots\\
x, & x \in [a,b] \setminus \{a,b,a_1,a_2,\dots\}.
\end{cases}
$$
Of course definition of $(a_n)$ could be different. The only important thing is that it is a sequence in $(a,b)$.
A: It seems that your construction is fine, however coarse and crude. We usually give this question in the introductory course of set theory, the solution is quite elegant too.
Firstly, it is very clear that this function cannot be continuous. Consider a sequence approaching the ends of the interval, the function cannot be continuous there.
Secondly, without the loss of generality assume the interval is $[0,1]$. Define $f(x)$ as following:
$$f(x) = \left\{
 \begin{array}{1 1}
  \frac{1}{2}  & \mbox{if } x = 0\\
  \frac{1}{2^{n+2}} & \mbox{if } x = \frac{1}{2^n}\\
                x & \mbox{otherwise}
 \end{array}
\right.$$
It is relatively simple to show that this function is as needed.
A: Define a bijection $f:(-1,1)\rightarrow[-1,1]$ as follows: $f(x)=2x$ if $|x|=2^{-k}$ for some $k\in\mathbb{N}$; otherwise $f(x)=x$.
A: For background to this 'turn-the-crank' technique see this answer.
Let $A = (0,1)$ and $B = [0,1]$. Let $f: A \to B$ be the inclusion mapping $f(x) = x$ and $g: B \to A$ be given by
$$ g(x) = \frac{x}{2} + \frac{1}{4}$$
We can build our bijective mapping using these two injective functions (thanks to Julius König of Schröder–Bernstein-Cantor theorem fame).
The number $0 \in B = [0,1]$ is a B-stopper; let
$$ D_0 = \{\, \frac{1}{2} - \frac{1}{2^n} \, | \, n \text{ is a positive integer}\,\}$$
The number $1 \in B = [0,1]$ is a B-stopper; let
$$ D_1 = \{\, \frac{1}{2} + \frac{1}{2^n} \, | \, n \text{ is a positive integer}\,\}$$
Define $h: A \to B$ as follows:
$$h(x) = \left\{
 \begin{array}{1 1}
  \frac{1}{2} - \frac{1}{2^{n-1}}  & \mbox{if } x = \frac{1}{2} - \frac{1}{2^{n}} \, \land \, n \gt 1\\
  \frac{1}{2} + \frac{1}{2^{n-1}}  & \mbox{if } x = \frac{1}{2} + \frac{1}{2^{n}} \, \land \, n \gt 1\\
                x & \mbox{otherwise}
 \end{array}
\right.$$
The function $h: A \to B$ is a bijection with $h(\frac{1}{2}) = \frac{1}{2}$.
