Cantor Set and Function

A continuous function may grow considerably virtually without changing.

The function with this property is easily constructed on the Cantor set C0. So I'll proceed in two steps. First we'll look into C0 and then define the promised function.

When I was a freshman, a graduate student showed me the Cantor set, and remarked that although there were supposed to be points in the set other than the endpoints, he had never been able to find any. I regret to say that it was several years before I found any for myself.

Ralph P. Boas, Jr
Lion Hunting & Other Mathematical Pursuits
MAA, 1995

Cantor set C0

First of all C0 is a subset of the closed unit interval [0, 1] = {x: 0 ≤ x ≤ 1}. C0 is what's left over after the removal of a sequence of open subintervals of [0, 1]. The algorithm is as follows:

  1. Divide the remaining intervals each into three equal parts.
  2. Remove the open middle interval.
  3. Repeat 1.

Thus first we remove the open interval (1/3, 2/3). This leaves a union of two closed intervals: [0, 1/3] ∪ [2/3, 1]. I'll call the removed interval d1,1. Next we split each of the remaining intervals [0, 1/3] and [2/3, 1] into three smaller ones and remove the middle part d2, 1= (1/9, 2/9) from the first and d2,2 = (7/9, 8/9) from the second, respectively. We are left with the union of four intervals: [0, 1/9]∪[2/9, 1/3]∪[2/3, 7/9]∪[8/9, 1].

Observe that we started with the interval [0, 1] of length 1. After removing d1,1, the total length of the remaining intervals became 2/3. d2,1 and d2,2 each contributed 1/3 to the total. So after their removal, the four remaining intervals had the total length of (2/3)2. Next we remove 4 middle intervals d3,1, ..., d3,4 leaving 8 smaller (closed) intervals with the total length of (2/3)3. The process never stops. In general, on the step number p we remove 2p-1 intervals dp,1, ..., dp,2p-1. The total length of the remaining intervals is (2/3)p. Obviously, as p grows, the length (2/3)p tends to 0. However, this does not mean that C0 is empty. Moreover, the set is not even countable. The most convenient way to see this is by using ternary representation of the decimals from [0, 1]. In the ternary system the only digits allowed are 0, 1, and 2.

For example (1/3)10 = (0.1)3, (2/3)10 = (0.2)3, (1/9)103, (2/9)10 = (0.02)3, (7/9)10 = (0.21)3, and (8/9)10 = (0.22)3. It's important to note that the points inside the interval (1/3, 2/3) all have the first digit equal to 1. The only other point with this feature is 1/3. However, 1/3 can also be written as 0.022222.... Therefore, if we adopt the convention of replacing ternary representations that end with 1000... with those that end with 0222..., we can say that on the first step all the decimals whose ternary representation starts with 1 have been removed. Similarly, on the second step we removed all the decimals (among the remaining ones) whose second digit was 1. On the third step the numbers with the third digit equal 1 have been removed. And so on. On the other hand, numbers in [0, 1] whose ternary representation contains no 1's will be left over even after an infinite number of steps. The conclusion is that

C0 = {x: x = (0.a1a2a3...)3, where each aj = 0 or 2}.

Applying the diagonal process we immediately see that C0 is not countable.

Thus, this is the Cantor set C0 which has many remarkable properties. For example, the Cantor set has no isolated points. In other words, every neighborhood of every point in C0 contains infinitely many other points from C0. (A point of a set is isolated if in some of its neighborhoods there are no other points from that set.) This makes C0 a perfect set (since it is obviously closed.) I'll use C0 as a basis for the construction of the function announced at the beginning of the page.


  1. 1/4∈C0. Indeed, (0.25)10 = (0.020202...)3. Similarly, since (0.75)10 = (0.202020...)3, 3/4∈C0. The reciprocal of 13 also happens to be sufficiently "lucky" to be a member of C0: 1/13 = (0.002002002...)3.

  2. A similar construction yields Cantor sets of positive measure.

Cantor function

Let x = (0.a1a2a3...)3∈C0 which means that all ai's are either 0 or 2. Let define a function f: C0→[0, 1] the following way:

let bi = ai/2, then define f(x) = (0.b1b2b3...)2, where x = (0.a1a2a3...)3.

What's interesting is that at the end points of the intervals dp,k so defined function takes on equal values. Consider, for example, d1,1 = (1/3, 2/3). Then

f(1/3) = f(0.0222...) = (0.0111...)2 = (0.1)2 = 1/2.

On the other hand, f(2/3) = f(0.2) = (0.1)2. Therefore f(1/3) = f(2/3). The same argument works for other intervals as well. So far f has been defined on C0. Using the feature we just mentioned, we can extend (lift) the definition of f to the whole [0, 1] by setting f constant on every interval dp,k. Since C0 has no isolated points, and is monotonous on C0, the extended function is actually continuous being constant on intervals of total length 1!. In other words, a nonconstant function f that has a derivative equal to 0 on intervals of total length 1 manages to grow from 0 to 1 on the interval [0, 1]. The derivative is, of course, discontinuous; it's undefined at the points of the Cantor set C0.

Remark 1

Cantor function is as famous as it is useful for other exceptional constructs. For example, let g: [0, 1]→[0, 1]×[0, 1] be a Peano curve. Then g(f): [0, 1]→[0, 1]×[0, 1] is another Peano curve that is constant almost everywhere.

Remark 2

Cantor's function serves a very specific example for Lebesgue's Theorem

Every monotone function has a well defined finite derivative almost everywhere.

Cantor's function is monotone increasing and is also continuous - a condition not required by Lebesgue's Theorem. It has a derivative everywhere except at Cantor's set which is a set of (Lebesgue) measure zero. This explains the term "almost everywhere".


  1. B.R.Gelbaum and J.M.H.Olmsted, Counterexamples in Analysis, Holden-Day, 1964
  2. B.R.Gelbaum and J.M.H.Olmsted, Theorems and Counterexamples in Mathematics, Springer-Verlag, 1990

Cantor Set

  1. Cantor set and function
  2. Cantor Sets
  3. Difference of two Cantor sets
  4. Difference of two Cantor sets, II
  5. Sum of two Cantor sets
  6. Plane Filling Curves: the Lebesgue Curve

Related material

  • Apollonian Gasket
  • Iterated Function Systems
  • Iterations in the Mandelbrot Set
  • Mandelbrot Set and Indexing of Julia Sets
  • Color Cycling on the Mandelbrot Set
  • Emergence of Chaos
  • Cantor set and function
  • |Contact| |Front page| |Contents| |Did you know?| |Geometry|

    Copyright © 1996-2018 Alexander Bogomolny