I know that the derivative of the Cantor Staircase should be close to 0 since the Cantor Set has a measure of zero. I wanted to graph the derivative of Cantor's Staircase in Mathematica to see if it was closed to 0 from the interval [0,1]. Here is my input:

f[x_] := f[x] = CantorStaircase[x]; 

Plot[f'[x], {x, 0, 1}]

However, the plot of the derivative is not close to 0. I appreciate any suggestions of where I went wrong. Thanks!

  • $\begingroup$ N[CantorStaircase'[1/2]] returns -0.119127 when it should return something close to zero, so I suspect this is a bug of some sort. $\endgroup$ Apr 26, 2021 at 19:09
  • $\begingroup$ Also, N[CantorStaircase'[1/6]] = -0.837313, apparently. Not all rational values return a numerical answer, though; N[CantorStaircase'[1/4]] doesn't give any output in a reasonable time on my computer. $\endgroup$ Apr 26, 2021 at 19:18
  • 1
    $\begingroup$ Curiouser and curiouser: N[CantorStaircase'[1/6], n] for various values of n gives wildly fluctuating values as n increases — but only the first time you run the command in a fresh kernel. So running N[CantorStaircase'[1/6], 5] gives you one number, N[CantorStaircase'[1/6], 10] gives you a second, different number, and N[CantorStaircase'[1/6], 5] gives you the second result rounded off to five significant digits. $\endgroup$ Apr 26, 2021 at 23:12
  • $\begingroup$ @MichaelSeifert I get the same thing looking at the limit as $dx \to 0$ dLim[x_] = Limit[(CantorStaircase[x + dx] - CantorStaircase[x])/dx, dx -> 0, Assumptions -> x \[Element] Reals]; Plot[dLim[x], {x, 0, 1}] I don't understand why the derivative is negative around 1/2 if the function appears to be monotonically increasing $\endgroup$
    – ydd
    Aug 14, 2023 at 23:11

2 Answers 2


It would appear that this simple staircase has "jaggies" where no slope can be defined. I think your function lacks defined slopes, too.

Plot[CantorStaircase[x], {x, 0, 1}]

  • $\begingroup$ And if you want to zoom in: Plot[CantorStaircase[x], {x, 0, 0.0000001}] $\endgroup$
    – bill s
    Mar 27, 2021 at 18:05
  • $\begingroup$ @bill s you may zoom as much as you want, it always looks the same! $\endgroup$ Mar 27, 2021 at 18:10
  • 2
    $\begingroup$ @Youvan it only has "jaggies" on a set with measure zero. At almost all points it is constant. $\endgroup$ Mar 27, 2021 at 18:12

This is not an answer, but something too long to put into comments that I thought could be useful to others with more knowledge in similar subjects. I used the Wikipedia definition of the Cantor staircase to create my own version of the function where we see explicitly what is happening:

cantorFun[x0_] := Module[{x = x0},
  inBase3 = 
   RealDigits[x, 3, 
    100];(*you have to hope the first 1 shows up in the first 100 \
  base3Digs = inBase3[[1]];
  first1 = First@FirstPosition[base3Digs, 1];
   base3Digs[[first1 + 1 ;; All]] = 0;
  base3Digs = base3Digs /. (2 -> 1);
  inBase3[[1]] = base3Digs;
  FromDigits[inBase3, 2]

(Tiny note: there is probably a way to optimize this to only take the base-3 expansion until there is a 1 instead of taking the first 100 digits for every $x$, but I don't know how to tell RealDigits to do that)

What we could do from here to get the derivative is find the locations where the function changes, and put (scaled) Dirac delta functions at those jumps. I am not sure how exactly to determine where those jumps occur, but my guess is it has to do with the base-3 expansion of the number.

Add-on after reading bill s's comment on the answer above, I believe looking for the "jump" locations may be infeasible, as the function is sort of fractal in the sense that the closer you zoom in, the more jumps you see and there are probably infinite jump locations from 0 to 1.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.