Let $f: \mathbb{R} \to \mathbb{R}$ be continuous and $D \subset \mathbb{R}$ be a dense subset of $\mathbb{R}$. Furthermore, $\forall y_1,y_2 \in D \ f(y_1)=f(y_2)$. Should $f$ be a constant function?
My attempt: Since $f$ is continuous $$\forall x_0 \ \forall \varepsilon >0 \ \exists \delta>0 \ \forall x \in \mathbb{R} \ \left(|x-x_0|<\delta \Longrightarrow |f(x)-f(x_0)|<\varepsilon \right)$$ Let $f$ be non-constant function. Since $D$ is dense $\exists x_1 \in (x_0-\delta, x_0+\delta) \ : \ x_1 \in D$. Let's take $x_2 \in (x_0-\delta, x_0+\delta)$ such that $f(x_2) \ne f(x_1)$. Let $\varepsilon = \frac{|f(x_2)-f(x_1)|}{2}>0$. Therefore, we have $$|f(x_1)-f(x_0)|<\frac{|f(x_2)-f(x_1)|}{2} \ \ \ |f(x_2)-f(x_0)|<\frac{|f(x_2)-f(x_1)|}{2}$$ Adding the expressions above, we obtain $$|f(x_2)-f(x_1)|\le |f(x_1)-f(x_0)|+|f(x_2)-f(x_0)|<|f(x_2)-f(x_1)|$$ what is the contradiction. Are my mussings correct?