# Showing that a metric space is discrete if and only if any function from it to another metric space is continuous

Let $(X, d)$ be a metric space and $(Y, p)$ is another metric space that has at least two distinct elements. Show that $(X, d)$ is a discrete metric space (a metric space is defined to be discrete if every subset is open) if and only if any function from $X$ to $Y$ is continuous.

I'm not too sure how to prove this, I'm guessing we need to use the open set characterization of continuity, i.e., $f:X \rightarrow Y$ is continuous if and only if for every open set $A \subset Y$, the set $f^{-1}(A) = \{x \in X : f(x) \in A\} \subseteq X$ is open. Can anyone provide a proof?

• Well, what can you say about the topology on $Y$? If, say, $Y$ had the indiscrete topology (the only open sets are $\emptyset,Y$) then every function from $X$ to $Y$ is continuous regardless of the topology on $X$. – lulu Jul 23 '17 at 10:59
• Not sure I was clear: My example shows that the statement you want would be false if you tried to generalize it to topological spaces. This shows that your argument has got to use the fact that $Y$, at least, has a topology induced by a metric. Can you, for example, show that the indiscrete topology on $Y$ can not be induced by a metric? – lulu Jul 23 '17 at 11:07

Suppose every $f: (X,d) \to (Y,p)$ is continuous.
First let $y_0 \neq y_1 \in Y$, which exist by assumption. So $r = d(y_0,y_1) > 0$. Define $U_0 = B_p(y_0, \frac{r}{2}), U_1 = B_p(y_1, \frac{r}{2})$, these are open and disjoint (by the triangle inequality).
Let $A \subseteq X$. Then define $f_A: X \to Y$ by $f(x) = y_0$ for $x \in A$, $f(x) = y_1$ for $x \notin A$. By assumption this is continuous. Note that $A = f^{-1}[U_0]$ (all $x \in A$ map to $y_0 \in U_0$ and all other $x$ map to $y_1 \notin U_0$). So $A$ is open, as the inverse image of an open set.
As $A$ was arbitrary, all subsets of $X$ are open, i.e. $X$ has the discrete topology.
Of $Y$ we only used it has a 2-point discrete subspace $\{y_0, y_1\}$, of $X$ nothing of the metric.
The forward direction follows by the fact that $f^{-1}(A) \subset X \Rightarrow f^{-1}(A)$ is open in $X$, by the definition of the discrete topology.
Suppose $X$ is not discrete. Then there exists some subset $B \subset X$ such that $B$ is not open. Denote the two distinct elements $s,t \in Y$. Let $g$ be the map which takes all elements of $B$ to $s$ and all the elements in $B^c$ to $t$. Now consider the open set \begin{align*} C \doteq \{y \in Y : p(s,y) < \frac{p(s,t)}{2}\} \end{align*} i.e. the open ball around $s$ with radius half the distance between $s$ and $t$. Then $g^{-1}(C) = B$. This is a contradiction since $g$ is assumed to be continuous, but $C$ is open and its inverse image is not.