Construction of Cantor-like function I have a countable collection of proper disjoint closed intervals $\mathcal{C} = \left\lbrace I_n\right\rbrace$ in the unit interval $[0,1]$. I want to construct a certain non-decreasing surjective continuous function $f:[0,1]\to [0,1]$ which is locally constant (only) on the above intervals.
More precisely, $f$ is surjective, $t_1 \leq t_2$ should imply $f(t_1)\leq f(t_2)$, and
$$
f(t_1) = f(t_2) \iff t_1, t_2 \in I_n \text{ for some } n.
$$
In general the union of these disjoint intervals can have full measure so I guess I would have to imitate the Cantor function construction? So letting $U_n = [0,1] \setminus \bigcup\limits_{i=1}^n I_n$ be written as a disjoint union of open (in $[0,1]$) intervals $U_n = \bigcup V_j$, my thought was to define
$$f_1(x) = \frac{1}{|V_1| + |V_2|}\int^x_0 \left(1_{V_1}+1_{V_2}\right)
$$
and iterate the process by splitting $V_i$ based on where the next $I_n$ showed up? I'm not sure this works since I'm not convinced there will be some uniform convergence.
Can someone please help me out?
 A: Here's one way of doing this that imitates a sequential approach to defining the Cantor function. Note that we'll write $I_n = [a_n, b_n]$.
We'll also assume for convenience that among the $I_n$ there's no interval of the form $[0, b]$ or $[a, 1]$ in our collection. If one or both is in play, the process below can be adjusted slightly. (We'd want to take all the functions below to be $0$ on $[0, b]$, and $1$ on $[a, 1]$.)
Step 0:
Define $f_0(x) = x$ for all $x \in [0, 1]$.
Step 1:
Define $f_1$ as follows. On $I_1 = [a_1, b_1]$, set $f_1$ equal to the average value of $f_0$ on $I_1$; call this value $y_1$. (Equivalently, this is the value of $f_0$ at the interval midpoint $(a_1 + b_1) / 2$.) Then linearly interpolate between $f_1(0) = f_0(0) = 0$ and $f_1(a_1) = y_1$; and between $f_1(b_1) = y_1$ and $f_1(1) = f_0(1) = 1$.
Step 2:
For $j \geq 2$, define $f_j$ as follows. First locate $I_j$ with respect to $I_1, I_2, \ldots I_{j-1}$: suppose that $I_j$ is immediately to the right of $I_{j_1} = [a_{j_1}, b_{j_1}]$, and immediately to the left of $I_{j_2} = [a_{j_2}, b_{j_2}]$. (If $I_j$ doesn't have a neighbor to one side, we can adjust what follows slightly.) For $x \leq b_{j_1}$ or $x \geq a_{j_2}$, set $f_j(x) = f_{j-1}(x)$. For $x \in I_j$, set $f_j(x)$ equal to the average value of $f_{j-1}$ on $I_j$; call this value $y_j$. (Equivalently, this is the value of $f_{j-1}$ at the interval midpoint $(a_j + b_j) / 2$.) Finally, linearly interpolate between $f_j(b_{j_1}) = f_{j-1}(b_{j_1})$ and $f_j(a_j) = y_j$; and between $f_j(b_j) = y_j$ and $f_j(a_{j_2}) = f_{j-1}(a_{j_2})$.
Step 3:
Define $f(x) = \lim_{j \to \infty} f_j(x)$. I haven't been able to figure out how to show Cauchy convergence of the $f_j$ in the uniform norm, so as to simultaneously establish the existence of the limit and its continuity. But we can definitely prove the pointwise convergence of the $f_j$.

The most complicated part of the pointwise convergence, to my mind, is for a point $x \notin \bigcup I_n$ that is arbitrarily close to these intervals to both the left and right sides. To see how convergence works in this case, we first write $(0, 1) \setminus \left( \bigcup_{j=1}^{k} I_j \right)$ as the union of disjoint open intervals $V_{k,1}, V_{k,2}, \ldots, V_{k, k+1}$; and let $V_{k, \ell_k} = (c_k, d_k)$ be the interval containing $x$. Without loss of generality we can assume that $I_{k+1}$ is contained in $V_{k, \ell_k}$ for every $k$, i.e. that at each step the interval we're "removing" is in the remaining piece where $x$ lives.
Our assumption is now that $s_k = d_k - c_k \to 0$, and it's sufficient to show that $f_k(d_k) - f_k(c_k) \to 0$ as well. Recursively, we have
$$f_k(d_k) - f_k(c_k)
= [ f_{k-1}(d_{k-1}) - f_{k-1}(c_{k-1}) ]
\frac{d_k - c_k + (b_k - a_k) / 2}{d_{k-1} - c_{k-1}},$$
and tracing this back gives the product expansion
$$f_k(d_k) - f_k(c_k)
= \prod_{j=1}^{k}
\frac{d_j - c_j + (b_j - a_j) / 2}{d_{j-1} - c_{j-1}}.$$
Since $b_j - a_j < (d_{j-1} - c_{j-1}) - (d_j - c_j) = s_{j-1} - s_j$, we can estimate
$$f_k(d_k) - f_k(c_k)
\leq \prod_{j=1}^{k}
\frac{s_{j-1} + s_j}{2 s_{j-1}}
= \prod_{j=1}^{k}
\left(
1 - \frac{1}{2} \left( 1 - \frac{s_j}{s_{j-1}} \right)
\right).$$
Meanwhile, the similar-in-form products
$$\prod_{j=1}^{k}
\left(
1 - \left( 1 - \frac{s_j}{s_{j-1}} \right)
\right)$$
simplify to $s_k$, which we know go to $0$.
Letting $r_j = 1 - s_j / s_{j-1} \in (0,1)$, we can reduce things to the following result for series: if $\{ r_j \}$ has values in $(0,1)$, and $\sum \log(1 - r_j)$ diverges, then $\sum \log(1 - r_j/2)$ diverges as well. This is true, for example, because the divergence of the first series implies the divergence of $\sum r_j$, which implies the divergence of $\sum r_j/2$, which implies the divergence of $\sum \log(1 - r_j/2)$.

After all of this, there's still the question of $f$ being continuous and locally constant only on the $I_n$.
Once we know the limit exists, it's evidently a monotonic function since each $f_j$ is, and this helps with the continuity. We can then look at pointwise continuity by breaking things into cases, for example based on whether there are $I_n$ arbitrarily close to the point to one or both sides (i.e. left and right). In some cases, continuity follows from a very similar argument to the one above establishing the existence of the limit.
Being locally constant only on the $I_n$ can be handled by a similar casewise approach. It helps here to recognize that the value of $f$ on each $I_n$ is distinct. (This can be seen inductively.) You can then argue, for example, that at points which have some $I_n$ between them, $f$ takes on distinct values.
