Proving such a function is always constant Let $I \subset R$ be an interval. Let $f : I \to R$ be a continuous function.
Assume that $I := [a, b]$. Assume that for all $c, d \in [a, b]$ such that $c < d$, there exists $e \in [c,d]$ such that $f(e) = f(a)$ or $f(e) = f(b)$. Prove that $f$ is a constant.
Consider this statement: For all $c \in [a,b], f(c) \in \{f(a),f(b)\}$
I figured that proving this statement would allow me to prove the function to be constant, but I'm unable to do so. Any thoughts?

The set $D:=f^{-1}(f(a))\cup f^{-1}(f(b))$ is closed by continuity of $f$ and dense in $I$ by the special property. Clearly $D$ does not intersect the open set $I\setminus D$. By defnition of dense, this means that $I\setminus D$ is empty. Hence $I=D$. This makes $I$ the union of the two non-empty closed sets $f^{-1}(f(a))$, $f^{-1}(f(b))$. As $I$ is connected, these sets must overlap, which means that $f(a)=f(b)$ and ultimately that $f^{-1}(f(a))=I$, i.e., $f$ is constant.
