The equivalence of open-set definition of continuous mappings to the $\epsilon-\delta$ definition A function $f: M\rightarrow N$ is defined to be continuous iff $\forall$ open set $U\subseteq N$, the preimage of $U$ is also open.
I was trying to prove that such a definition would be equivalent to the $\epsilon -\delta$ definition in a metric space, and I could only do so if I assume $f$ is surjective, or otherwise a counterexample would be $g: \mathbb{R}\rightarrow\mathbb{R}$ where $g(x)=x^2$. As if I take $U=(-1,1)$, then its preimage is $[0,1)$, which is neither open or closed. In fact, any $U$ containing elements that cannot be achieved by $g$ would face the same problem.
So I was wondering that have I remembered the definition of preimage wrong, or do I need to make sure that $U$ must be chosen from the image set of $f$?
 A: Not so: given $g\colon x \mapsto x^2\colon \mathbb{R} \to \mathbb{R}$,
the preimage (aka inverse image) of $(-1, 1)$ under g is $g^{-1}[(-1, 1)]$ is $(-1, 1)$. Each $y > 0$ is the image under $g$ of two points: $g^{-1}[\{y\}] = \{- \sqrt y, \sqrt y \}$.
For $\varepsilon > 0$, the preimage of $(-\varepsilon, \varepsilon)$ is $(-\sqrt \varepsilon, \sqrt \varepsilon)$. In the case of $x = 0$, an obvious choice of $\delta$ presents itself...
Re:

In fact, any [open] $U$ containing elements that [are not in the range of] $g$ would face [some] problem.

There's no problem, $g$ doesn't have to be surjective. The preimage of $U$ equals the preimage of $U \cap image(g)$.
A: You're probably confusing the mapping $x\mapsto x^2$ with $x\mapsto\sqrt{x}$, which is defined on $\mathbb{R}_{\ge0}$ (the set of non negative real numbers), with values in $\mathbb{R}$.
In this case it's indeed true that the inverse image of $(-1,1)$ is $[0,1)$, but this set is open in $\mathbb{R}_{\ge0}$, because, for instance,
$$
[0,1)=(-1,1)\cap\mathbb{R}_{\ge0}
$$
and so $[0,1)$ is an open set in the relative topology on $\mathbb{R}_{\ge0}$.
The inverse image of $(-1,1)$ with respect to the mapping $x\mapsto x^2$ is
$$
\{x\in\mathbb{R}:x^2\in(-1,1)\}
$$
and this is again $(-1,1)$. The fact that the function maps $(-1,1)$ onto $[0,1)$ is of no concern, because we're interested in inverse images, not in direct images and a continuous function can map open sets onto non open ones.
Elements in the codomain that are not in the image of the function make no problem.
