TITLE: A convex function is differentiable at all but countably many points
QUESTION [30 upvotes]: Let $f:\Bbb R\to\Bbb R$ be a convex function. Then $f$ is differentiable at all but countably many points.

It is clear that a convex function can be non-differentiable at countably many points, for example $f(x)=\int\lfloor x\rfloor\,dx$.
I just made this theorem up, but my heuristic for why it should be true is that the only possible non-differentiable singularities I can imagine in a convex function are corners, and these involve a jump discontinuity in the derivative, so since the derivative is increasing (where it is defined), you get an inequality like $f'(y)-f'(x)\ge \sum_{t\in(x,y)}\omega_t(f')$, where $\omega_t(f')$ is the oscillation at $t$ (limit from right minus limit from left) and the sum is over all real numbers between $x$ and $y$. Since the sum is convergent (assuming that $x\le y$ are points such that $f$ is differentiable at $x$ and $y$ so that this makes sense), there can only be countably many values in the sum which are non-zero, and at all other points the oscillation is zero and so the derivative exists. Thus there are only countably many non-differentiable points in the interval $(x,y)$, so as long as there is a suitable sequence $(x_n)\to-\infty$, $(y_n)\to\infty$ of differentiable points, the total number of non-differentiable points is a countable union of countable sets, which is countable.
Furthermore, I would conjecture that the set of non-differentiable points has empty interior-of-closure, i.e. you can't make a function that is non-differentiable at the rational numbers, but as the above discussion shows there are still a lot of holes in the proof (and I'm making a lot of unjustified assumptions regarding the derivative already being somewhat well-defined). Does anyone know how to approach such a statement?

REPLY [5 votes]: I'm going to post an alternative answer for those who wish to avoid the Axiom of Choice (although that argument is much simpler than the one below).
It's fairly trivial to demonstrate that whenever $f$ is a convex map (on an open set), then $f$ is both left-differentiable and right-differentiable at every point of its domain. It's also quite typically easy to show that both $f_l'$ and $f_r'$ are both increasing functions. Furthermore, it's also typically easy to show that $f_l'(x)\leq f_r'(x)$ for every $x$ in the domain. However, another property that holds (which is much less frequently invoked however quite important here) is that whenever $x< y$, then $f_r'(x)\leq f_l'(y)$. Each of these can be readily proved from the Three Chord lemma.
The idea behind this proof is to use the fact that increasing functions have at most countably many points of discontinuity (which both $f_l'$ and $f_r'$ are). And to use this fact that we are about to prove: if either $f_l'$ or $f_r'$ are continuous at some fixed point, then both of these functions are going to agree at that point.
From the inequalities above, we can conclude for any $x$ that
$$\lim_{y\rightarrow x^-}f_r'(y)\leq f_l'(x)\leq f_r'(x)
\quad\text{and}\quad
f_l'(x)\leq f_r'(x)\leq\lim_{y\rightarrow x^+}f_l'(y).$$
The assertion of equality in the presence of continuity is quickly deduced from these inequalities.
Now let $D$ be the set of points where $f$ is not differentiable. By the lemma we just proved, this set is contained in the set of points where either $f_l'$ or $f_r'$ is discontinuous, which is of course countable.