# Find a Continuous Function with Cantor Set Level Sets

This was a problem from a class that I thought was really interesting. It asked to find function $f\in C[0,1]$ such that the sets $\{x:f(x)=c\}$ form a Cantor Set for all $0\leq c\leq 1$. I found a non-constructive proof of the existence of such functions, but would be curious if anyone could give a constructive example of such a function.

Definition: A set is a Cantor Set if it is uncountable, perfect, compact, nowhere-dense set. This makes it homeomorphic to "the Cantor set."

• i'm thinking some characterization of the cantor set may be useful here Apr 21, 2016 at 5:05
• @ForeverMozart I added the topological definition, but a Cantor Set is just a set homeomorphic to the cantor set. I don't particularly care what characterization you use. Apr 21, 2016 at 10:01
• Can you provide reference for the non-constructive approach? I'm interested in seeing it. Apr 21, 2016 at 21:25
• For starters, note that when $f$ is continuous, all these sets will be closed. Also, if in addition $f$ is nowhere differentiable (or even just non-differentiable at a dense set of points), then all these sets will be nowhere dense. For this second result, note that if the sets were "somewhere dense", they would contain an interval (since they're closed), and if any such set is an interval this would mean the function is constant throughout an interval, which means it can't be nowhere differentiable. (In fact, weaker than "densely non-differentiable", you only need "constant in no interval"). Apr 21, 2016 at 21:45
• I need to leave for the day, so I'll add something quick. You of course want more than "constant in no interval", since monotone functions have this property (and the sets will all be singleton sets). Think about what you can deduce if the function is monotone in no interval, which of course is true for any nowhere differentiable function. Also, continuous functions on $[0,1]$ have a maximum and a minimum, so you want to make sure these are high and low enough so that you don't reach them with your $f(x) = c$ sets. Apr 21, 2016 at 21:56

As the Cantor set is self-similar, it makes sense to try to construct a graph with some kind of self-similar structure. The only way the graph of a function can be strictly self-similar is if it is a line segment. Thus, we explore a slight generalization using a self-affine graph. I'll first present an example that is specifically designed to have the desired property and then comment on a couple of cases where such a structure arises quite naturally.

# A rigged example

For our first example, we start with the Iterated Function System of six affine functions defined as follows: \begin{align} f_1(x,y) &= \left(\begin{array}{cc} 1/6 & 0 \\ 0 & 1/4 \end{array}\right) \left(\begin{array}{c} x\\y\end{array}\right) \\ f_2(x,y) &= \left(\begin{array}{cc} 1/6 & 0 \\ 0 & 1/4 \end{array}\right) \left(\begin{array}{c} x\\y\end{array}\right) + \left(\begin{array}{c} 1/6\\1/2\end{array}\right) \\ f_3(x,y) &= \left(\begin{array}{cc} 1/6 & 0 \\ 0 & -1/4 \end{array}\right) \left(\begin{array}{c} x\\y\end{array}\right) + \left(\begin{array}{c} 2/6\\1\end{array}\right) \\ f_4(x,y) &= \left(\begin{array}{cc} 1/6 & 0 \\ 0 & -1/4 \end{array}\right) \left(\begin{array}{c} x\\y\end{array}\right) + \left(\begin{array}{c} 3/6\\1/2\end{array}\right)\\ f_5(x,y) &= \left(\begin{array}{cc} 1/6 & 0 \\ 0 & 1/4 \end{array}\right) \left(\begin{array}{c} x\\y\end{array}\right) + \left(\begin{array}{c} 4/6\\0\end{array}\right)\\ f_6(x,y) &= \left(\begin{array}{cc} 1/6 & 0 \\ 0 & 1/4 \end{array}\right) \left(\begin{array}{c} x\\y\end{array}\right) + \left(\begin{array}{c} 5/6\\1/2\end{array}\right) \end{align}

The geometric action of this IFS on the upwardly oriented unit square is illustrated in the following figure:

This image shows the oriented initial set, the first two levels of approximation using rectangles, and a higher order approximation to the attractor, which is the graph of a continuous function. Now, it's pretty easy to see that the intersection with the level $n$ approximation by rectangles with a horizontal line segment is just a collection of line segments and that these contain the corresponding intersection at level $n-1$. The intersection of all these is perfect, non-empty, and no where dense. Thus, it's a Cantor set.

This function maps $[0,1]\to[0,1]$ but it's easy to extend to $\mathbb R$, if desired.

# Natural examples

There are some examples of functions with Cantor type level sets that occur naturally - i.e. constructed for some other purpose but happen to have the desired property.

## Space-filling curves

The coordinate functions of Hilbert's space filling curve have Cantor type level sets. I proved this in my paper The Hausdorff Dimension of Hilbertʼs Coordinate Functions. I also published a more elementary exposition in The Math Mag. If you understood the previous example, you can see what's going on in figure 7 of that paper:

## The Takagi function

Finally, the Takagi function has this property at many points. More specifically, let $\varphi(x)$ denote the distance from $x$ to the nearest integer and let $$\tau(x) = \sum_{k=0}^{\infty} \frac{1}{2^k}\varphi(2^kx).$$ Then, the maximum value of $\tau$ is $2/3$ and $\tau^{-1}(2/3)$ is a self-similar Cantor set with dimension $1/2$. The partial self-similar structure of the Takagi function implies that the level sets are Cantor sets for a dense set of points in $[0,2/3]$.

This an many other fun facts are proved in The Takagi function: a survey. It's not hard at all to see what's going on by examining the even partial sums of the series that generates $\tau$:

The image shows $$\tau(x) = \sum_{k=0}^{n} \frac{1}{2^k}\varphi(2^kx)$$ for the first few even values of $n$. Note that the top is always a set of segments. As we move from $n=2$ to $n=4$, the one segment is replaced by two smaller sub-segments. The partial self-similar structure of the object suggests that this pattern repeats and, in the limit, the top of the object is a Cantor set.

Again referring to the partial self-similar structure, there is a dense set of points in $[0,2/3]$ whose inverse image is a Cantor set. This is formalized in Lemma 3.3 of the linked paper. Specifically, the portion of the graph of $\tau$ above the interval $[k/2^{2m},(k+1)/2^2m]$ is a similar copy of the full graph reduced by the factor $1/2^{2m}$ and shifted up by $\tau(k/2^{2m})$.

• This is pretty interesting. It clearly doesn't have the desired property for large $c$, as the function never takes on those values. My intuition says it doesn't have the property for small $c$ either, but it's conceivable that for extremely large $n$ I'm just miss extrapolating. What numbers do you think it works for? Apr 22, 2016 at 17:48
• @StellaBiderman There is definitely a countable but dense set of points in $[0,2/3]$ for which $\tau^{-1}(c)$ is a Cantor set. I expanded my answer substantially to explain this and presented a couple of examples as well. Apr 28, 2016 at 14:09
• Also relevant is the mathoverflow question Is it possible to have the set $f^{-1}(\lbrace x \rbrace)$ perfect for every $x$? and my 24 November 2000 sci.math post on locally recurrent functions. Apr 28, 2016 at 14:33