functions with local maxima everywhere I am curious about the following problem:
If a function $f:\mathbb{R}\to\mathbb{R}$ has the property that $f$ achieves local maxima everywhere, then there exists an interval $I$ such that $f$ is constant on $I$.
I think this proposition holds, but failed to come up with a proof. Can anyone give me some hint on that? Many thanks!
 A: Suppose, toward a contradiction, that $f:\mathbb R\to\mathbb R$ has a local maximum at every point but is not constant on any interval.  Pick an arbitrary point $x_0$ and an interval $I_0$ centered at $x_0$, such that $f(x_0)\geq f(y)$ for all $y\in I_0$.  Shrinking $I_0$ if necessary, we can arrange that $I_0$ is closed and has length $\leq 1$.  Since $f$ is not constant on $I_0$, choose some $x_1\in I_0$ such that $f(x_1)<f(x_0)$, and then choose an interval $I_1$ centered at $x_1$, such that $f(x_1)\geq f(y)$ for all $y\in I_1$; shrink $I_1$ to arrange that it is closed, is a subset of $I_0$, and has length $\leq\frac12$.  Continue, inductively choosing $x_n\in I_{n-1}$ with $f(x_n)<f(x_{n-1})$ and choosing an interval $I_n$, centered at $x_n$ such that $f(x_n)\geq f(y)$ for all $y\in I_n$; shrink $I_n$ so that it is closed, is $\subseteq I_{n-1}$, and has length $\leq2^{-n}$.  The decreasing sequence of closed intervals $I_n$ has a point in their intersection, say $z$.  Since $z\in I_n$, we have $f(z)\leq f(x_n)$ for all $n$; in fact we have strict inequality here because $f(z)\leq f(x_{n+1})<f(x_n)$.  But, thanks to the requirements on the lengths of the intervals $I_n$, we have that $x_n$ is within a distance $2^{-n}$ of $z$. That contradicts the assumption that $f$ has a local maximum at $z$.
Edit: Either I should choose each $x_n$ in the interior of $I_{n-1}$, so that there's room inside $I_{n-1}$ for an $I_n$ centered at $x_n$, or I should forget about "centered at" and just say "containing" instead.
