Build the Cantor set, explore its paradoxes, and animate the devil's staircase
The Cantor ternary set is one of the most remarkable objects in mathematics. Constructed by a simple iterative process of removing middle thirds, it produces a set that is simultaneously uncountably infinite and has Lebesgue measure zero. This combination of properties — being as "large" as ℝ in cardinality yet as "small" as a single point in measure — makes it a fundamental counterexample in analysis and a gateway to understanding the subtleties of measure theory.
Georg Cantor introduced this set in 1883, and it has since become a cornerstone of real analysis, topology, and fractal geometry. The Cantor set is closed, nowhere dense, perfect (every point is a limit point), and totally disconnected. It is homeomorphic to the product space {0, 1}^ℕ, which gives it a natural connection to binary sequences and symbolic dynamics.
In this lesson, we explore the construction of the Cantor set, prove it has measure zero, examine the famous Cantor function (devil's staircase), and reflect on how this single example challenges our geometric intuition about size and continuity.
Start with the unit interval C₀ = [0, 1]. Remove the open middle third (1/3, 2/3) to get C₁ = [0, 1/3] ∪ [2/3, 1]. Remove the middle third of each remaining interval to get C₂ = [0, 1/9] ∪ [2/9, 1/3] ∪ [2/3, 7/9] ∪ [8/9, 1]. Continue this process indefinitely. The Cantor set is C = ∩ₙ₌₀^∞ Cₙ — the set of points that survive every stage of removal.
At stage n, we have 2ⁿ intervals each of length 3⁻ⁿ, so the total length remaining is (2/3)ⁿ. As n → ∞, this tends to zero. Therefore m(C) = limₙ m(Cₙ) = limₙ (2/3)ⁿ = 0. The Cantor set has Lebesgue measure zero. Yet it is uncountable: every point in C corresponds to a ternary expansion using only the digits 0 and 2 (never 1), and the map sending each such expansion to a binary number (replacing 2 with 1) gives a surjection onto [0, 1].
The total length removed is 1/3 + 2/9 + 4/27 + … = (1/3) · 1/(1 − 2/3) = 1. We remove everything in terms of measure, yet an uncountable set remains. This is the first of many surprises the Cantor set has in store.
Watch the middle-third removal process unfold step by step. At each stage, the remaining intervals are shown. Notice how the total length shrinks toward zero while the number of intervals doubles at each step — the set becomes a "dust" of uncountably many points spread throughout [0, 1].
Key insight: The Cantor set is a fractal with Hausdorff dimension log 2 / log 3 ≈ 0.631. It is self-similar: the left third [0, 1/3] ∩ C and the right third [2/3, 1] ∩ C are each scaled copies of the whole set. This self-similarity is the hallmark of fractal geometry.
The Cantor function f : [0, 1] → [0, 1] is defined by taking the ternary expansion of x, replacing all 1s with 0s, all 2s with 1s, and reading the result as a binary expansion. On the removed intervals, f is constant (it takes a single value throughout each gap). The result is a continuous, non-decreasing function that rises from 0 to 1 yet has derivative zero almost everywhere.
How can a function increase from 0 to 1 while having derivative zero at almost every point? The key is that the Cantor function does all its "climbing" on the Cantor set, which has measure zero. The set where f'(x) ≠ 0 (or does not exist) is contained in the Cantor set and therefore has measure zero. Yet this measure-zero set carries all the variation of the function. This shows that a function can be continuous and monotone increasing without being absolutely continuous.
The Cantor function is the standard example of a singular function — a continuous non-decreasing function whose derivative is zero almost everywhere. It demonstrates that the Fundamental Theorem of Calculus, in its strongest form, requires absolute continuity, not mere continuity. The Cantor function also shows that a continuous image of a measure-zero set can have positive measure.
Explore the Cantor function below. Notice the characteristic "staircase" pattern: flat plateaus on each removed interval, with all the increase concentrated on the Cantor set itself. Zoom in to see the self-similar structure — each portion of the staircase resembles the whole.
Key insight: The Cantor function maps [0, 1] onto [0, 1] continuously, yet it is constant on the complement of a measure-zero set. This means its distributional derivative is a singular measure — a probability measure supported entirely on the Cantor set. This is neither absolutely continuous nor discrete: it is a third kind of measure.