<s>[INST] Discontinuous at infinitely many points While doing a worksheet on real analysis I came across the following problem.
$Q$. Let $f$ be a function defined on $[0,1]$ with the following property.
For every $y \in R$, either there is no $x$ in $[0,1]$ for which $f(x)=y$ or there are exactly two values of $x$ in $[0,1]$ for which $f(x)=y$.
(a) Prove that $f$ cannot be continuous on $[0,1]$.
(b) Construct a function $f$ which has the above property.
(c) Prove that any such function with this property has infinitely many discontinuous on $[0,1]$.
I really have absolutely no idea how to solve the problem. Even constructing the function is proving pretty difficult. Any help would be appreciated asap.
 [/INST] This example shows that the image of $f$ can be the whole of $\mathbb{R}$:
\begin{align*}
f(0) & = 0, \\
f(x) & = \begin{cases}
\frac{3}{2^n} - 8x &
   \left( \frac{1}{2^{n + 1}} \leqslant x < \frac{5}{2^{n + 3}} \right) \\
\frac{1}{2^{n - 2}} - 8x &
   \left( \frac{5}{2^{n + 3}} \leqslant x < \frac{3}{2^{n + 2}} \right) \\
8x - \frac{5}{2^n} &
   \left( \frac{3}{2^{n + 2}} \leqslant x < \frac{7}{2^{n + 3}} \right) \\
8x - \frac{3}{2^{n - 1}} &
   \left( \frac{7}{2^{n + 3}} \leqslant x < \frac{1}{2^n} \right),
\end{cases}
\\
f(x) & = \begin{cases}
\frac{1}{8x - 5} &
   \left( \frac{1}{2} \leqslant x < \frac{5}{8} \right) \\
\frac{1}{8x - 6} &
   \left( \frac{5}{8} \leqslant x < \frac{3}{4} \right) \\
\frac{1}{7 - 8x} &
   \left( \frac{3}{4} \leqslant x < \frac{7}{8} \right) \\
\frac{1}{8 - 8x} &
   \left( \frac{7}{8} \leqslant x < 1 \right),
\end{cases} \\
f(1) & = 0.
\end{align*}
(The variable $n$ takes all positive integral values.)
\begin{alignat*}{2}
f\left(\left[\frac{1}{2^{n + 1}}, \frac{5}{2^{n + 3}}\right)\right) & =
f\left(\left[\frac{5}{2^{n + 3}}, \frac{3}{2^{n + 2}}\right)\right) && =
\left(-\frac{1}{2^{n - 1}}, -\frac{1}{2^n}\right], \\
f\left(\left[\frac{3}{2^{n + 2}}, \frac{7}{2^{n + 3}}\right)\right) & =
f\left(\left[\frac{7}{2^{n + 3}}, \frac{1}{2^n}\right)\right) && =
\left[\frac{1}{2^n}, \frac{1}{2^{n - 1}}\right),
\end{alignat*}
\begin{alignat*}{2}
f\left(\left[\frac{1}{2}, \frac{5}{8}\right)\right) & =
f\left(\left[\frac{5}{8}, \frac{3}{4}\right)\right) && =
\left(-\infty, -1\right], \\ \\
f\left(\left[\frac{3}{4}, \frac{7}{8}\right)\right) & =
f\left(\left[\frac{7}{8}, 1\right)\right) && =
\left[1, \infty\right).
\end{alignat*}
Amusingly, $f$ is continuous at $0$.
</s>