# Prove a non-constant continuous function on a compact interval must admit at least one non-local extremum

If $f:[a,b]\to\Bbb R$ is continuous and non-constant, prove that at least one $x_0\in [a,b]$ is NOT a local extremum.

This proposition isn't as trivial as it seems. For example, in the case of Cantor function, $f$ has zero derivative a.e., therefore almost every $x\in[0,1]$ is a local extremum for $f$. In fact, I'm not even able to show it doesn't stand as a counterexample to the proposition. (By monotonicity, each rational point in the Cantor set is also a local extremum for the Cantor function, since it borders on an open interval where the function has zero derivative. So the only candidates for non local extrema are among the "bad" (irrational) points, which are hard to analyse.)

Assume that every point in $[0,1]$ is a local extremum.
Let $(A_n)$ be the collection of all open balls centered at some $x\in [0,1]\cap \mathbb{Q}$ and with rational radius, and let $B_n := A_n \cap [0,1]$.
For every $n$ let us consider the sets $$C_n := \{x\in B_n:\ f(x) \leq f(y) \ \forall y\in B_n\}, \quad D_n := \{x\in B_n:\ f(x) \geq f(y) \ \forall y\in B_n\}.$$ Clearly, $f$ is constant on each $C_n$ and each $D_n$.
Moreover, by assumption every $x\in [0,1]$ belongs to some $C_n$ or $D_n$, i.e. $$[0,1] = \bigcup_n (C_n \cup D_n).$$ Hence $f([0,1])$ is a countable set, and it is connected (because $f$ is continuous), so that it must be a singleton.