TITLE: Can a continuous real function take each value exactly 3 times?
QUESTION [6 upvotes]: Let $f: \mathbb{R} \to D \subseteq \mathbb{R}$ be a continuous function. Is there a function $f$ that satisfies the following property? $\forall y \in D$, there are exactly 3 $ x_1,x_2,x_3 \in \mathbb{R}$ such that $f(x_1) = f(x_2) = f(x_3) = y$.

REPLY [6 votes]: There are many examples, e.g

as a piecewise cubic curve
$$x + 16\{x\}^3 - 24\{x\}^2 + 8\{x\}
= x + \frac12\bigg[T_{n}(2\{x\}-1)-(2\{x\}-1)\bigg]
$$
where $T_n(x)$ is the $n^{th}$ Chebyshev polynomials of first kind. Please note that if one replace $n$ by other odd positive integers, we will obtain a function whose pre-images come in group of $n$ instead of group of $3$.



or even as a smooth curve
$$(\cos\theta) x - \sin x \quad\text{ with }\quad \cos\theta \sim 0.21723362821122$$
and $\theta$ is a root of $\;\tan\theta = \pi + \theta\;$ near $1.35$.