What are some examples of a doubling function $f:\mathbb{R} \to \mathbb{R}$ A function $f : X \to Y$ is a “doubling” function if for every
$y \in Y$ , there are exactly two distinct values $x_1,x_2 \in X$ such that $f(x_1) = f(x_2) = y$.
I am satisfied with the answer to my previous question - $f:\mathbb{R} \setminus \{0\} \to \mathbb{R}$ given by $f(x) = \log|x|$ has this property. But we want the domain and codomain to be $\mathbb{R}$. Hence choose some bijection $g:\mathbb{R} \to \mathbb{R} \setminus \{0\}$ and $ f \circ g:\mathbb{R} \to \mathbb{R}$ should do the trick.
However, this function cannot be defined when x is 0. What kind of function then would be 'doubling' for all real numbers?
 A: Using the integer part function $\lfloor\ \rfloor$ and the fractional part function $\{\ \}$, a solution is

$$f(x)=\left\lfloor\frac x2\right\rfloor+(-1)^{\lfloor x\rfloor}\{x\}$$

Equivalently, and perhaps more visually, this is the unique function $f$ such that:


*

*for every integer $n$, $f$ is piecewise affine on the interval $[n,n+1)$,

*for every $x$, $f(x+2)=f(x)+1$,

*for every $x$ in $[0,1)$, $f(x)=x$,

*for every $x$ in $[1,2)$, $f(x)=2-x$.

A: [note: this is very similar to my answer on the other post]
$$f(x)=x-\frac{\lceil x \rceil }{2}$$
and
$$g(x)=x-\frac{\lfloor x \rfloor }{2}$$
should do the trick.
Edit: the first posting of this question was deleted, so I've migrated my old answer over here.

$\phantom{fillerfillerfillerfillerfiller}$
\begin{align}f(x)=\begin{cases}
  \vdots \\
  x & 0<x\leq 1\\
  x-1/2 & 1<x \leq 2\\
  x-1 & 2<x \leq 3 \\
  x-3/2 & 3<x \leq 4\\
\vdots 
\end{cases}
\end{align}
Generally, we take $f(x)=x-\frac{z}{2}$ when $z< x \leq z+1$, where $z \in \mathbb{Z}$. 
A: $$f(x)=n+\sin(x-n\pi) \quad \text{for} \quad n\pi \le x \lt (n+1)\pi, n \in \mathbb Z$$
A: No continuous function can be doubling for all real numbers.  Consider a pair of points $f(x_1) = f(x_2) = y_1$. Now at $x_1$ the curve either increases or decreases not doing so would violate the doubling requirement.
Let’s assume that the curve is decreasing (the same argument can be made if the curve is increasing) now the curve must be below $y_1$ until $x_2$ (because it can’t cross over $y_1$ at any point other then $x_2$). Since it is below $y_1$ before $x_2$ then the curve muse be increasing at $x_2$.
If the curve went from increasing to decreasing then there must be a minimum between the two numbers and there can only be one minimum.
In order for there to be a second minimum, the curve would have to go decreasing, minum increaseing, decreasing, minimum increasing. But the bump to separate the two minima would break the doubling condition.
A: HINT: Let $f(x)=\ln|x|$ for $x\in\mathbb{R}\setminus\mathbb{Z}$. Then you can easy define a function on the remaining part (you have a countable set of values to obtain). E.g. $f(0)=f(1)=\text{first remaining value}$, $f(-1)=f(2)=\text{second remaining value}$ and so on.
