
Cantor function, a.k.a. devil's staircase - memexy
https://en.wikipedia.org/wiki/Cantor_function
======
addcninblue
To be more precise, it has derivative zero _almost everywhere_ , so title is
slightly misleading. To fully grasp this, the article links topics from
measure theory.

~~~
Dylan16807
To be clear, this is the measure/probability theory definition of almost
everywhere, which means that while there are exceptions, it's true 100% of the
time.

~~~
ajkjk
This is one of those things where a surprising fact isn't astounding, but just
makes me think the definitions are badly chosen. After all -- of course if you
pick definitions in weird ways, you get weird results.

In this case, yes, it is true almost-everywhere, meaning that there the set of
points where it is untrue has measure 0. And yet intuitively the function is
increasing and so we ought to define "having a derivative" in such a way that
shows that it is increasing. All this definition has done is crammed all of
the increasing-ness into points that are vanishingly rare, so you can't find
them. But they still exist, per _my_ definition of increasing!

I would instead choose to define "having a derivative != 0" in a different
way, that captures the idea that, over any interval I choose, the function
changes. Nevermind that the function becomes constant as I zoom in to a point.
All that shows is that evaluating at points must not be a great way of
modeling this.

Of course I'm not sure if that works exactly. But this is the reason I can't
get enthusiastic about analysis: it seems like a bunch of silly definitions
with silly consequences, with little relation to the actual mathematics of our
universe that I care about.

~~~
georgewsinger
For most of my life I would have unthinkingly attacked any attacker of the
traditional foundations of mathematics (including the standard definitions in
Analysis, Measure Theory, etc). But after reading Michael Huemer's
"Approaching Infinity"[1], I am now sympathetic with your skepticism.

A shockingly large amount of pure mathematics is asserted (with either no or
little argument) as the best foundational groundwork for numbers, infinities,
measures, etc. Digging a little deeper shows much of the dogma to be a dubious
foundation for mathematics, leading to absurdities like Cantor's function
(which 99.9% of math students marvel at, instead of more appropriately
wondering "wait a minute -- maybe this means our foundations are messed up?").

[1]
[https://www.amazon.com/Approahttps://www.amazon.com/Approach...](https://www.amazon.com/Approahttps://www.amazon.com/Approaching-
Infinity-M-Huemer/dp/1137560851ching-Infinity-M-Huemer/dp/1137560851)

~~~
hilbertseries
There are a couple constructions like this in mathematics that... really make
you think. Like Banach Tarski doesn’t make any sense.

Or the one that still bothers me, ten years after I learned it. Is take an
enumeration of the rationals and take the union of balls of with radius
epsilon/2^n over this enumeration. And you can create dense open subsets of
the real numbers, that miss basically every real number. Despite containing an
open interval around every rational. The conclusion I’ve come to is the real
numbers don’t make any sense.

~~~
Dylan16807
> The conclusion I’ve come to is the real numbers don’t make any sense.

Oh they definitely don't.

 _Almost all_ real numbers are uncomputable, which means they cannot be
written down or communicated in any way.

------
rdimartino
Another fun one is the slippery devil's staircase, Minkowski's question-mark
function. It's strictly increasing but the derivative is 0 at rational
numbers.

[https://en.wikipedia.org/wiki/Minkowski%27s_question-
mark_fu...](https://en.wikipedia.org/wiki/Minkowski%27s_question-
mark_function)

------
clircle
It's also fun to define the cantor function as the CDF of a distribution. The
distribution has neither a pdf nor a pmf (it is singular)

[https://en.wikipedia.org/wiki/Cantor_distribution](https://en.wikipedia.org/wiki/Cantor_distribution)

------
ephaptic
My favorite function is the Devil's Staircase found by plotting the map-
winding number of a circle map, which has steps at every rational number:
[https://en.wikipedia.org/wiki/Arnold_tongue](https://en.wikipedia.org/wiki/Arnold_tongue)
.

~~~
memexy
Thanks. I hadn't heard of Arnold tongue. That page has really nice
illustrations.

------
OkGoDoIt
Is there any practical application or real world implication of this? I’m
having trouble understanding why this is interesting. I don’t have much formal
math background, so tying this to something non-abstract would be helpful to
appreciate it.

~~~
memexy
I posted it because someone mentioned measure theory and I remembered this
example from a graduate course in real analysis. Cantor's function shows there
are functions that are not the integrals of their derivatives. The Cantor
function goes from 0 to 1, it's increasing and continuous, but it's derivative
is 0 almost everywhere. Integrating the 0 function gives us back the 0
function so it's a kind of counter-example to the fundamental theorem of
calculus.

> Georg Cantor (1884) introduced the Cantor function and mentioned that
> Scheeffer pointed out that it was a counterexample to an extension of the
> fundamental theorem of calculus claimed by Harnack.

I don't know if it has any real world applications other than as a reminder to
be careful about assumptions and definitions. Most people think that
increasing/monotone functions must have positive derivatives but the Cantor
function shows this is not the case.

~~~
yorwba
> Cantor's function shows there are functions that are not the integrals of
> their derivatives.

That's because Cantor's function does not have a derivative that's defined
everywhere. Of course a function without derivative is not the integral of
that non-existent derivative.

If most people think that increasing/monotone functions must have positive
derivatives, they're apparently forgetting about non-differentiable functions.

~~~
memexy
The function is differentiable almost everywhere (this is a technical term
from measure theory). Here's a pretty good explanation of its properties:
[https://epicmath.org/2012/11/27/5-the-cantor-set-and-the-
can...](https://epicmath.org/2012/11/27/5-the-cantor-set-and-the-cantor-
function/).

> The Cantor function, also known as the Cantor Staircase, is a bizarre
> function that is continuous and has a derivative of 0 at every point where
> it is differentiable. In fact, it is differentiable at every point other
> than on the Cantor set, which is a set of measure zero.

So from a measure theoretic perspective the derivative of the Cantor function
is well defined and it is equal to 0 almost everywhere. Almost everywhere
equality is an equivalence relation and the derivative of the Cantor function
is in the same equivalence class as the 0 function.

~~~
yorwba
> Almost everywhere equality is an equivalence relation and the derivative of
> the Cantor function is in the same equivalence class as the 0 function.

And a function in that equivalence class will have an integral that is equal
to a constant function on all intervals where that function is defined. If you
also integrate over intervals where the function is only defined almost
everywhere, all bets are off.

------
throwawayiionqz
Some reference is Exercise 84 (Cantor function) in Tao's lecture notes at
[https://terrytao.wordpress.com/2010/10/16/245a-notes-5-diffe...](https://terrytao.wordpress.com/2010/10/16/245a-notes-5-differentiation-
theorems/#more-4290)

The results before/after that result have other niceties: a one sided
fundamental theorem of calculus for monotone functions (even though the Cantor
function has 0 derivative!) or the fact that monotone functions can also be
decomposed as the sum of continuous monotone function and a jump function such
as Cantor's function.

------
MaxBarraclough
Nice. I'm reminded of the Weierstrass function, which is continuous everywhere
but differentiable nowhere.

[https://en.wikipedia.org/wiki/Weierstrass_function](https://en.wikipedia.org/wiki/Weierstrass_function)

~~~
memexy
Yup. It's one of the first counter-examples I learned about in undergrad
analysis class. What's amazing about these things is that many extremely smart
mathematicians at the time thought this was impossible, i.e. that continuous
functions had to be at least differentiable somewhere.

------
hoseja
See also: Weierstrass function [0], continuous everywhere but differentiable
nowhere.

[0]
[https://en.wikipedia.org/wiki/Weierstrass_function](https://en.wikipedia.org/wiki/Weierstrass_function)

------
rmrfstar
People should read Cantor's bio page too.

He was treated horrifically by the mathematics establishment. There is some
justice in learning his history all these years later.

------
throwgeorge
This function is closely related to the cantor ternary set which is
uncountable but has measure zero

[https://en.wikipedia.org/wiki/Cantor_set](https://en.wikipedia.org/wiki/Cantor_set)

This and other wacky analysis things is what inspired me to study pure math in
undergrad.

~~~
JadeNB
Not just related—the staircase is built by, in essence, putting stairs on the
ternary set. There's enough Cantor set to get from 0 to 1, but not enough to
disturb the almost-everywhere vanishing of the derivative.

