Functions satisfying $ \forall x \in E: \exists \delta > 0: \forall y \in E \cap (x,x+\delta): f(x) \le f(y)$ I am investigating a function $f : E \rightarrow \mathbb{R}$ which has the following property: $$ \forall x \in E: \exists \delta > 0: \forall y \in E \cap (x,x+\delta): f(x) \le f(y)$$
I need to prove that if $f$ is continuous then $f$ is increasing ($x \le y \implies f(x) \le f(y) $) and disprove that $f$ must be increasing if we remove the continuity requirement.
I think I have a counterexample for the second part: consider $f:\mathbb{R} \rightarrow \mathbb{R}$ given by
$$
f(x) = \left\{\begin{aligned}
&1 ~, x \in (0,1)\\
&0 ~, x \notin (0,1)
\end{aligned}
\right.$$
For any $x\in (0,1)$ we can fix $\delta := (1-x)/2~$ so that we restrict $y$ to $(x,\frac{1+x}{2}) \subset (0,1)$ and thus $f(x) = 1 \le 1 = f(y)$.
However, this doesn't help me see how to construct a proof for when $f$ is continuous. It seems like the proof should be by contradiction. The property's negation is the following:
$$ \exists x \in E: \forall \delta > 0: \exists y \in E \cap (x,x+\delta): f(x) > f(y)$$
If we choose $\delta$ in this statement to match that for which $\forall y \in E:|x-y| < \delta \implies |f(x)-f(y)|<\epsilon$ (by continuity), then this should contradict $f(x) > f(y)$. But I can't work out a suitable value of $\epsilon$ (which we must choose before fixing $y$) or how exactly to derive the contradiction.
 A: This is true for intervals in $\mathbb{R}$, as demonstrated by @Hagen von Eitzen in the comments. Specifically, we require that for $a, b \in E$, $[a,b] \subset E$.
For $a,b \in E$, we want to show $f(a) \leq f(b)$. Let $X = \{x \in [a,b] \mid f(a) \leq f(x)\} \subset E$. Certainly $X$ is non-empty (it contains $a$), and bounded above by $b$. We would like to claim that $b \in X$. Let $y = \sup X$. If $y \notin X$, we get a contradiction. If instead $y \in X$, we show that $y = b$, so $b \in X$.

*

*$\sup X = y \notin X$. Aim to use continuity of $f$ at $y$. In particular, the idea here is that there are points $x$ which are arbitrarily close to $y$ with $f(a) \leq f(x)$, so $$f(a) \leq \lim_{x \to b} f(x) =f(y) < f(a),$$ a contradiction. Formally, we try to construct a sequence $x_n \in X$ with $x_n \to y$:
Let $n \in \mathbb{N}$. Then as $y$ is the least upper bound of $X$, there is some point $x_n$ of $X$ such that $y - \frac{1}{n} < x_n$ (if not, $y - \frac{1}{n}$ is a smaller upper bound). But $x_n < y$, so the sequence $x_n \to y$. By continuity, $f(x_n) \to f(y)$, but $f(a) \leq f(x_n)$ so $f(a) \leq f(y)$, contradicting $y \notin X$.


*$\sup X = y \in X$. For the sake of contradiction, suppose $y < b$. Then since $y \in E$, by the property given, $\exists \delta > 0$ such that $\forall z \in (y, y + \delta)$, we have $f(y) \leq f(z)$. As $y < b$, the intersection of $(y, y+\delta)$ with $[a,b]$ is non-empty: specifically contains $(y, \min(y+\delta, b))$, a non-empty interval. The midpoint of this interval (call it $z$) satisfies $f(y) \leq f(z)$, and $z \in [a,b]$ so $f(a) \leq f(y) \leq f(z)$, so $z \in X$. But $z > y$, contradicting that $y$ was the supremum of $X$.
Hence, we must have that $b = \sup X \in X$.

This proof feels very similar to proving compactness of a closed bounded interval, and goes along similar lines.
Feel free to ask for clarifications - some of this argument is fairly dense.
