During my studies I faced a function $f:\mathbb{R} \to \mathbb{R}^+ $ with the property: for all $x \in \mathbb{R} $ and all $y$ in open interval $(x-\frac{1}{f(x)} ,x+\frac{1}{f(x)}) $ we have $f(x) \leq f(y)$.
At first I guessed maybe it is necessarily constant function but I could not show this. I tried to generate a counter example for my guess and unfortunately I could not again. would anyone please help me?



If all points of a real function with positive values would be local minimum, can one say it is constant function?
My answer is: Such a function must be constant. Suppose (for puoposes of contradiction) $f$ is a nonconstant function $f : \mathbb R \to (0,+\infty)$ such that
$$
\forall x\in\left(a-\frac{1}{f(a)},a+\frac{1}{f(a)}\right),\quad
f(x) \ge f(a) .
$$


For $m > 0$, define $U\_m := \{x : f(x)>m\}$.


**Lemma 1:** For all $m \in \mathbb R$, the set $U\_m$
is open.  

*Proof.* Let $x \in U\_m$. Then $(x-1/f(x),x+1/f(x)) \subseteq U\_m$. So $U\_m$ is open.


Define
$\mathcal G = \{(a,b,m) : 
a < b, f(a)\le m, f(b)\le m, \text{ and }\forall x\in(a,b),f(x)> m\}$.


**Lemma 2:** Let $a,b \in \mathbb R$ with $f(a) \ne f(b)$, and $m>0$.
Then there exists $a\_1, b\_1$ with $a < a\_1 < b\_1 < b$ and $m\_1 \ge m$ such that
$(a\_1,b\_1,m\_1) \in \mathcal G$.  

*Proof.* One of $f(a), f(b)$ is smaller, assume WLOG that $f(a) < f(b)$.
Now $U\_{f(a)}$ is open,
$a \notin U\_{f(a)}$, and $b \in U\_{f(a)}$. The maximal open interval
$(c,d) \subseteq U\_{f(a)}$ with $c<b< d$ is nonempty, in fact $(c,b) = (c,d) \cap (a,b) \ne \varnothing$. By maximality, $f(c) \le f(a)$. Choose $e$ with $c < e < b$. For $x \in (c,e)$
we have $f(c) < f(x)$ so $c \le x-1/f(x)$ and thus
$f(x) \ge 1/(x-c)$. Thus $f(x)$ is unbounded on $(c,e)$.
Let $m\_1$ be such that $m\_1 \ge m, m\_1 > f(c), m\_1 > f(e)$.
The open set $U\_{m\_1}$ has $U\_{m\_1} \cap (c,e) \ne \varnothing$
and $c,e \notin U\_{m\_1}$. So let $(a\_1,b\_1)$ be a maximal open subinterval
of the open set $U\_{m\_1} \cap (c,e)$.


**Lemma 3:** Let $(a\_1, b\_1, m\_1) \in \mathcal G$, and let $m > m\_1$.
Then there exist $a\_2, b\_2$ with $a\_1 < a\_2 < b\_2 < b\_1$ and $m\_2 \ge m$
such that
$(a\_2, b\_2, m\_2) \in \mathcal G$.  

*Proof:* If $f(a\_1) \ne f(b\_1)$, apply Lemma 2 directly. Otherwise, pick any $c \in (a\_1,b\_1)$ and apply Lemma 2 to $a\_1, c, m$.


**Main Proof:** We assume $f$ is not constant. So there exist $a\_1 < b\_1$ with
$f(a\_1) \ne f(b\_1)$. By Lemma 2 there exist $a\_2, b\_2$ with
$a\_1 < a\_2 < b\_2 < b\_1$ and $m\_2 > 2$ so that $(a\_2,b\_2,m\_2) \in \mathcal G$.
Then by Lemma 3, there exist $a\_3, b\_3$ with
$a\_2 < a\_3 < b\_3 < b\_2$ and $m\_3 > 3$ so that $(a\_3,b\_3,m\_3) \in \mathcal G$.
Continuing recursively, we get sequences $(a\_k), (b\_k), (m\_k)$ so that
$$
\forall k:\quad a\_k < a\_{k+1} < b\_{k+1} < b\_k,\quad m\_k > k,\quad\text{and }
(a\_k,b\_k,m\_k)\in\mathcal G .
$$
The sequence $(a\_k)$ is increasing and bounded above, so it converges.
Let $a = \lim\_{k\to\infty} a\_k$. Then $a\_k < a\_{k+1} \le a \le b\_{k+1} < b\_k$.
From $(a\_k,b\_k,m\_k) \in \mathcal G$ we conclude $f(a) > m\_k > k$.
This is true for all $k$, so $f(a)$ is not a real number, a
contradiction.


