Can a continuous real function take each value exactly 3 times? [duplicate]

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$.


Answer is yes. Consider the piece-wise affine function described in this (poor) chart: enter image description here


Let $\phi\colon[0,1]\to\mathbb{R}$ be defined as $\phi(x)=1-3\,|x-1/3|$ and let $$ f(x)=\sum_{k\in\mathbb{Z}}(\phi(x-k)-k)\,\chi_{[k,k+1]}(x). $$ where $\chi_A$ is the characteristic function of the set $A$. enter image description here


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$.

A piecewise cubic curve

  • 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$.

A smooth curve


With $D=\mathbb R$, let $$f(x)=\begin{cases}2x-3\lfloor x\rfloor &\text{if $\lfloor x\rfloor$ is even}\\3-4x+3\lfloor x\rfloor&\text{if $\lfloor x\rfloor$ is odd}\end{cases}$$