# Stuck On Starting Proof - Continuous Function Between Metric Spaces

I need to prove that the following definitions are equivalent:

1. Given metric spaces $(X,d_X)$ and $(Y,d_Y)$ and a function $f: X \rightarrow Y$, $f$ is continuous if $\forall x \in X, \forall \epsilon > 0, \exists \delta > 0$ such that $\forall z \in X$, if $d_X(x,z) < \delta$, then $d_Y(f(x), f(z)) < \epsilon$.
2. Given two topological spaces induced by metrics $d_X$ and $d_Y$, $(X, \mathcal{T}_{d_X})$ and $(Y, \mathcal{T}_{d_Y})$ respectively, and a function $f: X \rightarrow Y$, $f$ is continuous if $\forall U \in \mathcal{T}_{d_Y}$, $f^{-1}(U) \in \mathcal{T}_{d_X}$.

I want to prove $1 \rightarrow 2$. Here is where I am having trouble starting my proof:

We know that the topology induced by $d_X$ are generated by sets of the form $B_{d_X}(x,\delta) = \{z \in X : d_X(x,z) < \delta, \delta > 0\}$ and similarly for $d_Y$. This means that when we assume $1.$ and want to consider an open set $U \in \mathcal{T}_{d_Y}$, it is sufficient to consider $U = B_{d_Y}(y,\epsilon)$, for some $y \in Y$ and $\epsilon > 0$. But now here's the issue: What if there are elements in $B_{d_Y}(y,\epsilon)$, such as $y$, which are not in $\text{Image}(f)$? Then we will have trouble using the definition in $1.$ to prove $2.$ since $1.$ refers to the element $f(x)$ and there may be elements which are not in $\text{Image}(f)$.

So I thought a solution to this might be to divide $B_{d_Y}(y,\epsilon)$ into $B_{d_Y}(y,\epsilon) = \{u \in B_{d_Y}(y,\epsilon) : u \in \text{Image}(f)\} \sqcup \{v \in B_{d_Y}(y,\epsilon) : v \notin \text{Image}(f)\}$, since then we would have $f^{-1}(\{u \in B_{d_Y}(y,\epsilon) : u \in \text{Image}(f)\} \sqcup \{v \in B_{d_Y}(y,\epsilon) : v \notin \text{Image}(f)\}) = f^{-1}(\{u \in B_{d_Y}(y,\epsilon) : u \in \text{Image}(f)\}) \sqcup f^{-1}(\{v \in B_{d_Y}(y,\epsilon) : v \notin \text{Image}(f)\}) = f^{-1}(\{u \in B_{d_Y}(y,\epsilon) : u \in \text{Image}(f)\}) \sqcup \varnothing = f^{-1}(\{u \in B_{d_Y}(y,\epsilon) : u \in \text{Image}(f)\})$.

The problem with this is that $\{u \in B_{d_Y}(y,\epsilon) : u \in \text{Image}(f)\}$ may not even be an open set.

How do I begin this proof when I need to consider the image of $f$?

It doesn't matter that $\lbrace u \in B_Y(y, \epsilon) : u \in \operatorname{Image}(f)\rbrace$ isn't open in $Y$; the inverse image of this set will be open.
You don't really need to split into two sets here either; just restrict the index set. If $\mathcal{V} \subseteq Y$ is open, then for each $y \in \mathcal{V}$, there exists an open ball $B(y, \varepsilon_y) \subseteq \mathcal{V}$. Then, for each $x \in f^{-1}(\mathcal{V})$, you can find a ball $B(x, \delta_x)$ such that $$f(B(x, \delta_x)) \subseteq B(f(x), \varepsilon_{f(x)}) \iff B(x, \delta_x) \subseteq f^{-1}(B(f(x), \varepsilon_{f(x)})),$$ using the metric definition of continuity. Then $$\bigcup_{x \in f^{-1}(\mathcal{V})} B(x, \delta_x) = f^{-1}(\mathcal{V}),$$ proving $f^{-1}(\mathcal{V})$ is open.