Can a continuous function $f$ on a compact, convex set $D$ have a discrete range with more than $2$ elements?

63 Views Asked by At

Give an example of a compact set $D \subset \mathbb{R}^n$ and a continuous function $f:D \to \mathbb{R}$ such that $f(D)$ consists of precisely $k\geq 2$ points. Is this possible if $D$ is convex? Why or why not?

My solution:

For the first part, let $D =\{1,2,3\}$. This set is trivially closed and bounded and therefore, is compact. Let $f(x) = x \; \forall x\in D$. f is continuous on $D$ and $f(D)$ has exactly $3$ points.

I am unable to proof the second part. Intuitively it makes sense to me. If $D$ is convex, then $\forall x, y \in D$, $\lambda x + (1-\lambda)y \in D$ $\forall \lambda \in [0,1]$. $f$ needs to be defined over all points in $D$ and f needs to be continuous, so when moving from $f(x)$ to $f(\lambda x + (1-\lambda)y)$ for $\lambda$ very close to $1$, there cannot be any "jump", which means for $\lambda$ very close to 1, $f(\lambda x + (1-\lambda)y)$ needs to be "very close" to $f(x)$, and for $\lambda$ very close to 0 $f(\lambda x + (1-\lambda)y)$ needs to be "very close" to $f(y)$. The only continuous function with a discrete $f(D)$ that can do this is a constant one which contradicts $k\geq 2$ condition (where k is the number of points in $f(D)$).

Am I thinking along the correct lines? I am unable to prove it formally? Should I try to prove that $f(D)$ will be a convex too?