How to show that $f(x) = 2x + \frac{|x|}{x}$ is not continuous using open sets? I'm teaching myself topology with a book, and I'm trying to understand the following definition.

If $X$ and $Y$ are topological spaces, a map $f$: $X \rightarrow Y$ is said to be continuous if for every open subset $U \subseteq Y$, its preimage $f^{-1}(U)$ is open in $X$.

But I don't get it. For example I'll use a function that I know is not continuous: 
 $f: \mathbb{R} \rightarrow \mathbb{R} $

$
f(x) = \left\{
        \begin{array}{ll}
            2x + \frac{|x|}{x} & \quad x \neq 0 \\
            0 & \quad x = 0
        \end{array}
    \right.
$
But where is a set that in open in the range, but its preimage is not open?
 A: The problem with your question is that you want to prove a function is discontinuous on $\mathbb R$ without having defined it on $\mathbb R$. You have failed to define $f$ at $x=0$. The function you have defined, on $\mathbb R\setminus\{0\}$, is continuous on that set. But if $f$ is defined at $0$ as well,  you can show $f$ will be discontinuous no matter what $f(0)$ is.

Claim: Let $f:\mathbb R\to\mathbb R$ be such that $f(x)=2x+\frac{|x|}{x}$ when $x\neq 0$. Then $f(x)$ is not continuous on the real line.

The fundamental property you need is: 

$f(x)>1$ if $x>0$ amd $f(x)<-1$ if $x<0$.

I'll leave some steps out.

Proof (outline): Let $U=(-1/2,+\infty)$ and $V=(-\infty,1/2)$. Then $U,V$ are open in $\mathbb R$. Show that $f^{-1}(U)=[0,+\infty)$ when $f(0)\geq 0$ and $f^{-1}(V)=(-\infty,0]$ when $f(0)\leq 0$ so at least one of these sets is not open in $\mathbb R$, depending on the value of $f(0)$, and thus $f$ is not continuous.


Another approach:

Alternative proof (outline): Let $U=(f(0)+1,f(0)-1)$. Then $0\in f^{-1}(U)$. If $f^{-1}(U)$ is open, it must therefore contain both positive an negative values. But when $x_-<0$, $f(x_-)<-1$ and when $x_+>0$ $f(x_+)>1$, so it is not possible for $f(x_+),f(x_-)\in U$, since $f(x_+)-f(x_-)>2$.


Both of these proofs work, no matter what $f(0)$ is defined to be.
A: 
For example in know the function
  $f(x) = 2x + \frac{|x|}{x}$, is not continuous, if the domain and range are real numbers. 

This is an ill-defined statement. $f$ is not even defined at $x=0$. There is no way to say that its domain is the set of all the real numbers. Any specified domain of $f$ must be a subset of $\mathbb{R}\setminus\{0\}$. 
To understand the quoted definition in this specific example, one needs to know the information of $X$ and $Y$:


*

*what is the topological space $X$ (the underlying set and its topology)? 

*what is the topological space $Y$ (the underlying set and its topology)?


Also, you would also need the concept of subspace topology.

For simplicity, consider $g:[-1,1]\to\mathbb{R}$ with
$$
g(x)=\begin{cases}
\frac{|x|}{x},&x\in[-1,1]\setminus\{0\};\\
0,&x=0.
\end{cases}
$$
and $h:[-1,1]\setminus\{0\}\to\mathbb{R}$ with
$$
h(x)=\frac{|x|}{x}.
$$
Also endow the set $[-1,1]$, $[-1,1]\setminus\{0\}$ and $\mathbb{R}$ with the standard (subspace) topology. Then $h$ is continuous while $g$ is not.
To see why $g:X\to Y$ with $X=[-1,1]$ and $Y=\mathbb{R}$ is not open, consider $(-0.5,0.5)$, which is an open set in $Y$. Its preimage 
$$
g^{-1}((-0.5,0.5))=\{0\}
$$
is not open in $X$.
A: You already know why it is not continuous:
The function is $0$ at $0$, but it is approximately $-1$ directly to the left of $0$ and approximately $1$ directly to the right of zero. 
How does that translate into the open set definition? It means that if you look at the pre-image of the open set $(-1/2,1/2)$, it will contain $0$ but no points near zero (the $1/2$ was chosen because it is less then the $1$ that occurred in the text above), i. e. it is not open.
