On this page
The Cantor function, also called the devil's staircase, is continuous everywhere on [0, 1], has derivative zero almost everywhere, and still climbs from 0 to 1, as the Cantor function article on Wikipedia sets out. Georg Cantor described it in a letter published in Acta Mathematica in 1884.
What is the Cantor function?
Build the Cantor set: take [0, 1], remove the open middle third, remove the middle third of each piece left, and repeat forever. Our explainer on why the Cantor set has length zero yet uncountably many points walks through it.
The Cantor function is flat on every removed gap: 1/2 on the middle third, 1/4 and 3/4 on the next two gaps, and so on, with no jumps. The cleanest definition, from the Cantor function article, uses base 3:
Write x in base 3, using the digits 0, 1 and 2.
If a 1 appears, keep it and replace every digit after the first 1 with 0.
Change every remaining 2 into a 1.
Read the result as a binary number. That number is f(x).
How do you work out f(1/4) and f(3/4)?
To get base-3 digits, multiply by 3 and peel off the whole-number part each time.
For x = 1/4: 3 × 1/4 = 3/4, first digit 0. Then 3 × 3/4 = 9/4, next digit 2, leaving 1/4 again. So 1/4 = 0.020202... in base 3. There is no 1, so turn each 2 into a 1: 0.010101... in binary, which is 1/4 + 1/16 + 1/64 + ... = (1/4)/(1 − 1/4) = 1/3. So f(1/4) = 1/3.
For x = 3/4: 3 × 3/4 = 9/4, first digit 2, leaving 1/4, which then gives 0, 2, 0, 2... So 3/4 = 0.202020... in base 3, which becomes 0.101010... in binary, summing to (1/2)/(1 − 1/4) = 2/3. So f(3/4) = 2/3.
The two answers add to 1 because the function satisfies f(1 − x) = 1 − f(x), one of the self-similarity rules it obeys. Another is f(x/3) = f(x)/2, so f(1/12) = 1/6.
Why is the derivative of the Cantor function 0 almost everywhere?
Add up the gaps: one of length 1/3, then two of length 1/9, then four of length 1/27. The total is 1/3 + 2/9 + 4/27 + ... = (1/3)/(1 − 2/3) = 1. The gaps use up the whole length of [0, 1], so the Cantor set left behind has Lebesgue measure (length) zero, as the Cantor function article states.
On each gap the function is constant, so its derivative there is 0. "Almost everywhere" means everywhere except a set of length zero, here the Cantor set. The same article notes that on an uncountable part of the Cantor set the function has no derivative at all.
All the climbing happens on a set with no length, never by a jump. Compare the Weierstrass function, continuous but nowhere differentiable: that one is jagged everywhere, while the staircase is calm almost everywhere and still gets from 0 to 1.
Why does the fundamental theorem of calculus fail for it?
The fundamental theorem says the integral of f′ from a to b equals f(b) − f(a). Here f′ = 0 almost everywhere, so its Lebesgue integral over [0, 1] is 0. But f(1) − f(0) = 1.
The general theorem needs a stronger condition than continuity, called absolute continuity, and the Cantor function is continuous but not absolutely continuous, according to the Cantor function article. The same source records that Cantor's 1884 letter mentioned Scheeffer's point that the function was a counterexample to an extension of the fundamental theorem claimed by Harnack, and that Vitali noted in 1905 that it is not the integral of its derivative. Our piece on Lebesgue vs Riemann integration explains why a set of length zero can be ignored when you integrate.
How can you check you have understood it?
Try these, then check the answers in brackets:
f(1/9) (0.01 in base 3, so 1/4)
f(2/9) (0.02 in base 3, so 0.01 in binary, also 1/4: same tread)
f(1/10) (0.00220022... in base 3, so 0.00110011... in binary, which is 1/5)
The length removed after three steps (1/3 + 2/9 + 4/27 = 19/27)
Then explain to a friend, in two sentences, why f′ = 0 almost everywhere does not force f to be constant. If base-3 expansions or geometric series are the sticking point, the Fermi Concept Library has a lesson for every concept in mathematics, so you can go back to the piece you are missing. For practice with series, the Fermi Problem Library has worked problems with a step-by-step solver that explains the reasoning.



