For a continuous function $f:\mathbb{R}^{+}\to\mathbb{R}^{+}$ does $(f(x)-f(y)) (f(\frac{x+y}{2}) - f(\sqrt{xy}))=0$ imply that $f$ is constant? Suppose that $f: \mathbb{R}^+ \to \mathbb{R}^+$ is a continuous function such that for all positive real numbers $x,y$ the following is true :
$$(f(x)-f(y)) \left ( f \left ( \frac{x+y}{2} \right ) - f ( \sqrt{xy} ) \right )=0.$$
Is it true that the only solution to this is the constant function ?
 A: Yes.  If $f$ were not constant, then (since ${\bf R}^+$ is connected) it could not be locally constant, thus there exists $x_0 \in {\bf R}^+$ such that $f$ is not constant in any neighbourhood of $x_0$.  By rescaling (replacing $f(x)$ with $f(x_0 x)$) we may assume without loss of generality that $x_0=1$.
For any $y \in {\bf R}^+$, there thus exists $x$ arbitrarily close to $1$ for which $f(x) \neq f(y)$, hence $f((x+y)/2) = f(\sqrt{xy})$.  By continuity, this implies that $f((1+y)/2) = f(\sqrt{y})$ for all $y \in {\bf R}^+$.  Making the substitution $z := (1+y)/2$, we conclude that $f(z) = f(g(z))$ for all $z > 1/2$, where $g(z) := \sqrt{2z-1}$. The function $g$ attracts $[1, \infty)$ to the fixed point $z=1$, so on iteration and by using the continuity of $f$ we conclude that $f(z)=f(1)$ for all $z >1$. Similarly, $h = g^{-1}$ defined by $h(z) = (z^2 + 1)/2$ attracts $(0, 1]$ to the fixed point $z = 1$, so by the same argument $f(z) = f(1)$ for $z < 1$, making $f$ constant on all of $\bf R^+$.
A: Trying to make sense of Igor's argument. Assume further that $f$ is defined on 0 and relaxt the continuity assumption by only assuming that the set $A=\{x>0:f (x)\neq f (0)\}$ is open.
It is shown that $A=\emptyset  $ by showing that


*

*$A $ is dense in $A+\mathbb R^+$, and

*$A\cap 2A=\emptyset $.


Proof. (1) Let $(a,b) $ be a connected component of  $A $. For every $0 <r <b-a  $, $b+r\in A $ since the arithmetic average of $b\pm r $ is not in $A $ whereas the geometric is. It follows that the next connected component contains $(b,2b-a) $ and, by applying the same argument on the next component, the elements of $[a,\infty )\setminus A $ are at least $b-a $ apart from one another.
(2) Let $a\in A $. $a $ is the arithmetic average of 0 and $2a $ and 0 is their geometric.
A: if $\mathbb{R}^+$ is the set of non-negative real numbers, your condition implies that 
$$(f(x)-f(0)) (f(\frac{x}2)-f(0)) = 0$$ for all positive $x,$ which is pretty convincing (setting $g(x) = f(x) - f(0),$ the function $g$ will be identically $0.$).
Addendum Since the map $(x, y) -> (x+y)/2, \sqrt{x y})$ is surjective onto the set $x>y,$ if your function were real analytic and nonconstant, then the set where your condition held would be a subvariety of $R^+ \times R^+,$ so assuming more regularity makes the problem easy, as pointed out in comments.
A: Yet another solution (to the original question).
Define an equivalence relation on $\mathbb R^+$ by $x\sim y$ iff $f(x)=f(y)$. 
Since $f$ is continuous,


*

*every equivalence class is closed.


Let $0<x<y$. Since $y=\frac {x +(2y-x)}{2}$, either $x\sim 2y-x$ or there exists $z\in (x,y)$ such that $z\sim y$. Therefore,   


*for every $x<y$, if [$\forall z\in(x,y)$ $z\not\sim y$] then $x\sim 2y-x$.


It suffices to prove the following proposition.

Proposition 1. Every equivalence relation on $\mathbb R^+$ that satisfies (1) and (2) is trivial (i.e., has one equivalence class). 

Proof.
Suppose there were a non-trivial equivalence relation "$\sim$" satisfying (1) and (2).
Step 1. Every equivalence class is unbounded and its interior is either unbounded or empty.
Suppose $\langle x\rangle$ were an equivalence class which is either bounded or has a non-empty bounded interior. There exits $\epsilon\geq 0$ such that $\langle x\rangle$ contains an interval of length $\epsilon$, and there exists $x'=\max\{x'': [x'',x''+\epsilon]\subset \langle x\rangle\}$. Take some $y \in (x',\infty)\setminus \langle x\rangle$, and let $y'=\min (
\langle  y\rangle\cap[x',\infty))$. By (2), $[x',x'+\epsilon]'\sim 2y'-[x',x'+\epsilon]$ contradicting the maximality of $x'$.
Step 2. Every equivalence class is an arithmetic sequence.
Let $\langle x\rangle$ be an equivalence class. If $x_0=\inf \langle x \langle >0$, then by (2) the elements of $(x_0,2x_0)$ are not in $\langle x\rangle$. Since $\langle x\rangle$ is unbounded and closed, there is a minimal $r_x\geq x_0$ such that $x_0+r_x\in\langle x\rangle$. By (2), the elements of $(x_0,x_0+r_x)$ are not in $\langle x\rangle$ and $x_0+r_x$ is in $\langle x\rangle$. Applying the same argument inductively on all intervals $[x_0+nr_x,x_0+(n+1)r_x]$, we get $\langle x\rangle=\mathbb R^+\cap (x+r_x\mathbb Z)$. 
Suppose $\inf \langle x \rangle = 0$ then, the compliment of $\langle x \rangle$ contains an interval $(a,b)$ such that $a,b\in \langle x \rangle$ and starting from that interval $\langle x \rangle$ is an arithmetic sequence with period $b-a$. Since this is the case for any such intervals, they must all have the same length; therefore $\inf \mathbb R^+\setminus\langle x\rangle >0$. Since $\langle x\rangle$ has a bounded interior it must have an empty interior (by Claim 1); therefore it does not contain a prefix of $\mathbb R^+$, so $\inf \langle x \rangle >0$.
Step 3. For every $x$ and  $y$, $r_y \leq r_x$ with strict inequality for some $x,y$. Contradiction!
Let $x\not\sim y$. There exists $x'\sim x$ such that $\langle y\rangle\cap(x',x'+r_x)\neq\emptyset$. By (2), since $\forall z\in(x',x'+r_x)\ z\not\sim x'+r_x$, $\langle y\rangle\cap(x'+r_x,x'+2r_x)\neq\emptyset$. By induction, $\langle y\rangle\cap(x'+nr_x,x'+(n+1)r_x)\neq\emptyset$, for all $n\in\mathbb N$; therefore $r_y\leq r_x$. Take $x$ and $y=x+\frac 2 3 r_x$. By (2), $y\sim y'=x+\frac 4 3 r_x$. It follows that $r_y\leq |y'-y|<r_x$.
