TITLE: Help using theorem: A function between metric spaces is continuous if and only if for all open sets in the codomain the pre-image of the set is open
QUESTION [2 upvotes]: As in the title, I am trying to work with the following theorem:
$f:M_1 \rightarrow M_2$ is continuous $\iff \forall V \subseteq M_2$ open, $f^{-1}(V)$ is open in $M_1$. 
As a corollary we showed we could replace "open" in the above theorem with "closed". My lecturer gave me two examples and its really confused me. I've tried to draw a few diagrams of the function to distinguish the examples but I'm just not seeing it. Here are the two examples:
Note: My definition for an open set is for any point in the set we can construct an open ball around it that lies in the set. And a set S in $M$ is closed if $M \setminus S$ is open 
Example 1: Let   $S=\{(x_1,x_2) \in \mathbb{R}^2 : sin(x_1) + x_1x_2 \leq5\}$. Show S is closed in $\mathbb{R}^2$.
Proof: Let $f:\mathbb{R}^2 \rightarrow \mathbb{R}$ be defined as $f(x_1,x_2) = sin(x_1) + x_1x_2$ then let $S=f^{-1}((-\infty,5])$ Then by algebra of continuous functions f is continuous and since $(-\infty,5]$ is closed in $\mathbb{R}$ we get $S=f^{-1}((-\infty,5])$ is closed. 
This seems fine to me, we have f is continuous and a closed set in $M_2$ who's preimage is $S$ and this is enough to show S is closed.
Example 2: Let $S=\{(x_1,x_2) \in \mathbb{R}^2 : \frac{x_2}{sin(x_1^2x_2^3)} > 2 \}$ show S is open in $\mathbb{R}^2$
Proof: Let  $f:\mathbb{R}^2 \rightarrow \mathbb{R}$ be defined as $f(x_1,x_2) = \frac{x_2}{sin(x_1^2x_2^3)}$. This is continuous where defined. Let $S=f^{-1}((2,\infty))$. Since $(2,\infty)$ is open in $\mathbb{R}$ and f is continuous $f^{-1}((2,\infty))=S$ is open.
This seems to then imply $f^{-1}((2,\infty))=S$ is open in $\mathbb{R}^2$ by the theorem (the fact its not continuous at $x_1=0$ or $x_2=0$ (or both) seems irrelevant for this example, am I correct?) However this is incorrect because it shows S is open on $(2,\infty)$ not $\mathbb{R^2}$
But the proof for the examples seem to be identical and the only difference between them is the function (both are continuous so I can't see this being a problem) and that one we are proving a set is closed and the other open but since we can interchange closed/open in the theorem this also doesn't seem to be the problem. 
I apologize is this is similar to other questions but looking at them and the answers I still can't get my head round the difference between these two examples.
Thanks in advance.

REPLY [0 votes]: It looks like the set $X=\{(x_1,x_2) \in \mathbb{R}^2 \mid \sin(x_1^2 x_2^3) = 0\}$ is much more wild than I initally thought. See here.
This means that the function $f$ is only defined on the subspace $Z=\mathbb{R}^2\setminus X$ and the preimage of $(2,\infty)$ is an open subset of $Z$ with the subspace topology. This does not mean $S$ is an open subset of $\mathbb{R}^2$, but only that there exists an open set $U\subset\mathbb{R}^2$ such that $S=U\cap Z$ (by the definition of the subspace topology).
{"set_name": "stack_exchange", "score": 2, "question_id": 652529}