# Continuous function with local maxima everywhere but no global maxima

Can there be such a function:

$f \colon \mathbb R \to \mathbb R$ is continuous and non-constant. It has a local maxima everywhere, i.e., for all $x \in \mathbb R$ there is some $\delta_x>0$ such that $f(x)\geq f(y)$ for all $y \in B(x,\delta_x)$. And, yet $f$ has no global maxima?

Thank you.

PS: $\mathbb R$ is with the usual topology. This is true for $\mathbb R$ with upper-limit topology.

-
What is the source of this problem? Such $f$ must be constant. –  Shai Covo Apr 8 '11 at 12:15

No such function exists. If $f$ is continuous and has a local maximum everywhere, then $f$ is constant. To see this, let $a$ be a real number. By continuity, $\{x:f(x)\leq f(a)\}$ is closed, and by the hypothesis on local maxima, $\{x:f(x)\leq f(a)\}$ is open. The set is nonempty because it contains $a$, so it is all of $\mathbb{R}$ by connectedness. Therefore, for all $a$ and $b$ in $\mathbb{R}$, $f(b)\leq f(a)$ and similarly $f(a)\leq f(b)$.

-
what if $f$ is not a continuous function? –  Ilya Apr 8 '11 at 14:24
Then the proposition does not hold. Try f(x) = 1 if rational, 0 if irrational. –  user7530 Apr 8 '11 at 15:48
@Gortaur: There would be examples if you didn't require the function to be continuous. E.g., take $f(n)=n$ for each positive integer $n$, and $f(x)=0$ otherwise. If you didn't care about having a global maximum, the characteristic function of any proper nonempty closed set would be a nonconstant function with a local maximum everywhere. –  Jonas Meyer Apr 8 '11 at 18:02
@user7530: What is that example supposed to show? –  Jonas Meyer Apr 8 '11 at 18:03
@user7530: for this function there are no local maximas. –  Ilya Apr 8 '11 at 19:19

Surprisingly enough, there are a few papers on this (like here). So other people have considered variations of this problem.

I think that you should also be familiar with a related but incredibly interesting fact: it is possible to have a continuous function that has a local maxima/minima at every rational number. That's a dense subset, which is astounding enough as it is. (One should note that having a countable number of local maxima is all one can ask for. To see this, note that around every maxima one can assign an interval over which it is the maximum, from the definition of a local maximum. But there is a rational number in this interval, and so there can be at most countably many).

One such function is the Weierstrass function. It seems not so hard to alter this so that it has countably many maxima and minima, but no global maxima or minima.

-
(+1); concerning paragraphs 2-3, it is worth recalling math.stackexchange.com/questions/42944/… –  Shai Covo Jun 10 '11 at 7:18

To extend the answer Jonas gave, let me note that if $f$ is continuous and has a local minimum or maximum everywhere, then $f$ is constant. See Problem2010-4/B here for a proof (very recently published).

EDIT (elaborating). If $f$ has a local minimum or maximum everywhere, then the range of $f$ is countable (a proof is provided in the above link; see also here). Hence if $f$ is further continuous it must be constant, for otherwise, by the intermediate value theorem, the range of $f$ would be uncountable, a contradiction.

-