TITLE: Existence of Function Taking Every Value Uncountably Many Times
QUESTION [5 upvotes]: I am stuck on the following problem coming from a plane geometry theorem I'm working on.  This is a generalization of that problem which might actually prove easier to handle.  All the techniques that I have tried have failed, and it wasn't in Counterexamples in Analysis, which is the only collection of results on this sort of thing I'm familiar with.  Here, by a function $f$ we mean any function, not necessarily continuous or measurable.
Is it possible to find a subset $A \subset \mathbb{R}$ and a function $f: A \rightarrow [0,1]$ such that $f$ takes every value uncountably many times, $f^{-1}(x)$ is totally disconnected for every $x \in [0,1]$ (equivalently, $f$ is not constant on any interval), and satisfying the following local monotonicity condition:
If $a_n \rightarrow a$ are points of $A$ and $a_n \leq a$, then $\limsup f(a_n) \leq f(a)$, and
if $a_n \rightarrow a$ are points of $A$ and $a \leq a_n$, then $f(a) \leq \liminf f(a_n)$?
Thanks!

REPLY [2 votes]: Take any space filling curve, i.e., any continuous surjective function $g : [0, 1] \to [0, 1] \times [0, 1]$ and arrange for $g$ to be non-constant on any open interval (either by adjusting an arbitrary space filling $g$ to shrink any open interval where it is constant to a point or by picking a specific $g$ like the Peano curve that doesn't suffer from this problem). Then define $f(x) = \pi_1(g(x))$, where $\pi_1 : [0, 1]\times[0, 1]\to [0, 1]$ is projection onto the first factor of the product ($\pi_1(x, y) = x)$. Then $f : [0, 1] \to [0, 1]$ is continuous and so certainly meets your monotonicity conditions and for any $x \in [0, 1]$, $f^{-1}(x)$ comprises the set $\{y : [0, 1] \mid g(y) \in \{x\} \times [0, 1]\}$, which is uncountable because $g$ is surjective and $\{x\} \times [0, 1]$ is uncountable.