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?

2$\begingroup$ The answer to the question in the title is (of course) no. [Define $f(x) = 2$ for $x \ne 0$ and $f(0)=1$.] But the question in the text is more complicated. $\endgroup$– Gerald EdgarAug 6, 2020 at 9:31

2$\begingroup$ What is $\mathbb{R}^+$? Is $f(x)=0$ allowed? $\endgroup$– Wilberd van der KallenAug 6, 2020 at 9:52

$\begingroup$ $\mathbb{R}^+ $ is denoted for the open interval $(0,+\infty)$ $\endgroup$– M. Reza. KAug 6, 2020 at 10:12
2 Answers
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 $(x1/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 x1/f(x)$ and thus
$f(x) \ge 1/(xc)$. 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.

1$\begingroup$ Your answer was enjoyable and very nice to me. It really engaged me and I am thinking if instead of $\mathbb{R}$ in domain of the $f$, replace a complete metrically convex metric space, does your answer still work? $\endgroup$ Aug 7, 2020 at 12:11

$\begingroup$ @M.Reza.K for every $x,y$ in the complete metrically convex space there is an isometry $g:[a,b]\to X$ such that $g(a)=x, g(b)=y$. Apply the result to $h=f\circ g$. It follows that $f(x)=h(a)=h(b)=f(y)$. I am interested if we can drop the completeness: the proof seems to work for rational numbers... Perhaps it also works for intrinsic metric spaces? $\endgroup$– erzAug 7, 2020 at 12:40

1$\begingroup$ @erz My proof certainly fails for rational numbers. A decreasing sequence of closed intervals may have empty intersection in $\mathbb Q$. $\endgroup$ Aug 7, 2020 at 13:32
This is not an answer but it greatly narrows down the class of functions $f$ with the described property.
 If $c>0$, then the sets $f^{1}([c,+\infty))$ and $f^{1}((c,+\infty))$ are both open.
Indeed, every $x$ in any of these sets comes with an open ball of radius $\frac{1}{f(x)}$.
Consequently, the sets $A_c=f^{1}((\infty, c))$ and $B_c=f^{1}((\infty, c])$ are both closed. In particular, $f$ is lower semicontinuous.
 Let $x\in B_c$. We know that if $d(y,x)<\frac{1}{c}\le \frac{1}{f(x)}$, then $f(x)\le f(y)$. On the other hand, if $y\in B_c$ and $d(y,x)<\frac{1}{c}$, then $d(y,x)<\frac{1}{f(y)}$, from where $f(y)\le f(x)$. Hence, if $y\in B_c$ and $d(y,x)<\frac{1}{c}$, we get $f(y)= f(x)$.
Not only this means that $f$ is locally a constant on $B_c$, but also that $f^{1}(c)$ is closed.
 Let us prove the following strengthening of the Baire's theorem: let $X$ be a complete metric space, and let $B_n$ be a sequence of closed sets such that $X=\bigcup B_n$. Then $X=\overline{\bigcup int B_n}$.
Indeed, if $U\subset X\backslash \bigcup int B_n$ is open and nonempty, it is metrizable with a complete metric, and $B_n\cap U$ is closed in $U$. Since $U=\bigcup (B_n\cap U)$, from the usual Baire's theorem, there is $m$ such that $V=int (B_m\cap U) \ne \varnothing$. But then $V=int (B_m\cap U)=int B_m\cap U\subset int B_m \backslash \bigcup int B_n=\varnothing$. contradiction.
 So, combining these observation we get the following picture: there is a dense open set $U$ such that $f$ is locally constant on $U$; every level set of $f$ is closed, and the distance between elements of $f^{1}(c)$ and $f^{1}(d)$ is at least $\frac{1}{\max \{c,d\}}$.
The only way it's not a constant function is when the components of $U$ are like the gaps in the Cantor set. So the possible counterexample may be constructed like the Cantor's staircase, but the smaller the component, the larger is the value on it. I was unable to perform this fine tuning though, maybe it's impossible.