Continuous functions taking uncountably many values countably often

How about Devil's staircase (a.k.a. Cantor function) $C(x)$, but with every horizontal segment replaced by a rescaled zigzag $Z(x)$? By a zigzag I mean, for example: $$ Z(x) = \tfrac{2}{\pi} \arcsin(\sin(2\pi x)) .$$ The function $f$ is formally defined as: $$ f(x) = \begin{cases} C(x) & \text{if $x$ has no $1$ in ternary expansion,} \\ C(x) + 2^{-n} Z(3^n(x - a_{n,k})) & \text{if $x \in [a_{n,k}, a_{n,k}+3^{-n}]$,} \end{cases} $$ where $a_{n,k}$, $k = 1, 2, \ldots, 2^n$, is the enumeration of left endpoints of maximal line segments of length exactly $3^{-n}$ on which $C(x)$ is constant.

For every $y_0$ which is not a dyadic rational there is exactly one $x$ with no $1$ in ternary expansion such that $f(x) = C(x) = y_0$, and for each $n = 1, 2, \ldots$ the line $y = y_0$ intersects exactly one zigzag of $f$ of horizontal length $3^{-n}$.

EDIT: To clarify the definition of $f$, write $$ x = \sum_{n = 1}^\infty \frac{x_n}{3^n} $$ for the ternary expansion of $x$, and let $K \in \{1, 2, \ldots, \infty\}$ be the position of first digit $1$. The Cantor function $C(x)$ is equal to $$ C(x) = \sum_{n = 1}^K \frac{\lceil x_n/2 \rceil}{2^n} . $$ The function $f$ is defined by $$ f(x) = \begin{cases} C(x) & \text{if $K = \infty$,} \\ C(x) + 2^{-K} Z\biggl(\sum_{n = 1}^\infty \dfrac{x_{K+n}}{3^n}\biggr) & \text{otherwise.} \end{cases} $$

Here is the plot of $f$:

plot of the devil-type function

To see that $f$ is continuous, it is enough to observe that $f - C$ is an infinite series of continuous "zigzag" functions with disjoint supports and decreasing supremum norms. The series thus converges uniformly, and consequently $f - C$ is continuous.

Regarding the level sets: Suppose that $y$ is not a dyadic rational, with binary digits $y_n$: $$ y = \sum_{n = 1}^\infty \frac{y_n}{2^n} . $$ Then $C(x) = y$ has exactly one solution (namely: an $x$ with $x_n = 2 y_n$), and this will also be a solution of $f(x) = y$. All other solutions $x$ necessarily have $K < \infty$. For such an $x$, we have $|f(x) - C(x)| \le 2^{-K}$, that is, $|y - C(x)| \le 2^{-K}$. Since $y$ is not a dyadic rational, it follows that $x_n = 2 y_n$ for $n = 1, 2, \ldots, K - 1$, and of course $x_K = 1$. Therefore, $$ 2^{-K} Z\biggl(\sum_{n = 1}^\infty \frac{x_{K+n}}{3^n}\biggr) = f(x) - C(x) = y - C(x) = \frac{y_K - 1}{2^K} + \sum_{n = K + 1}^\infty \frac{y_n}{2^n} . $$ The above equation clearly has exactly two solutions ($Z$ is essentially two-to-one). It follows that $f(x) = y$ has one solution with $K = \infty$ and two solutions corresponding to every finite $K$.

By the way, level sets corresponding to dyadic rationals are countable, too, by a very similar argument.


Just to complement the answers that were already given, one can also have $|Z(f,2^{\aleph_0})|= 2^{\aleph_0}$: just take for $f$ a typical sample of Brownian motion. More precisely, almost every realisation of Brownian motion has the property that a set of $c$s of positive Lebesgue measure has a preimage of positive Hausdorff dimension. This can be shown by combining the fact that the zero level set of BM has positive Hausdorff dimension with Fubini and the strong Markov property.


A locally recurrent function takes every value in its range an infinite number of times. There exist nonconstant continuous locally recurrent functions on $[0,1]$. See https://msp.org/pjm/1967/21-3/pjm-v21-n3-p04-s.pdf.