Understanding why $f(x)=2x$ is injective Dr. Charles Pinter's "A Book of Abstract Algebra" shows a proof of why a function '$f$' is injective and surjective.

Given $$f(x)=2x,$$
we claim $f$ is injective. 
Proof. Suppose $$f(a)=f(b);$$ that is,
$$2a=2b.$$ This implies $$a=b.$$ 
Therefore $f$ is injective.

Intuitively, I understand why $$f(x)=2x$$ is injective, but I don't understand the above proof.
Why does showing that $$a=b$$ for $$f(a)=f(b)$$ prove that $f$ is injective?
 A: The typical method for showing something is injective is based off of the logical equivalence of the contrapositive. For something to be injective (i.e one to one), this means that if two different inputs, $a$ and $b$ $\in A$ are sent to $T$ under the function $f: A \rightarrow T$, then we want these two elements to have different values in $T$.
ie: If $a \neq b$, then $f(a)\neq f(b)$. Since the contrapositive is logically equivalent, and in this case, is often much easier to prove, it suffices to prove:
If $f(a) = f(b)$, then $a = b$, which is precisely the contrapositive and is the method being used.
A: Injectivity says that for each $y$ in the range of $f$ there is a unique $x$ in the domain for which, $$f(x)=y.$$
The goal here is to start by supposing that $f(a)$ and $f(b)$ take the same $y$ value. From there you would like to show that $a$ must be equal to be $b$ in order to satisfy the "uniqueness" property of injective functions.
For example, the following function is not injective on $[-1,1]$, $g(x) = x^2$. We can see this because the equation $x^2=1$ has two solutions, so even though $g(-1)=1=g(1)$ the inner parts are not equal.
A: 
Definition.$\quad$ A mapping $\alpha\colon S\to T$ is said to be one-to-one or injective if $$x_1\neq x_2\quad\text{implies}\quad\alpha(x_1)\neq\alpha(x_2)\qquad(x_1,x_2\in S).$$

Here, the set $S$ is the domain and $T$ is the codomain. Because a statement and its contrapositive are equivalent, we see that claiming $\alpha\colon S\to T$ is injective is the same as showing that $\alpha(x_1)=\alpha(x_2)$ implies $x_1=x_2$, where $x_1,x_2\in S$. 
In your problem, you have the mapping $f$ defined by $f(x)=2x$, but what are the domain and codomain? Presumably, your author is considering the mapping $f\colon\mathbb{Z}\to\mathbb{Z}$ defined by $f(x)=2x$, but you need to make sure the domain and codomain are clear at the outset. Otherwise, you cannot provide an adequate proof. That being said, what your author has done is essentially what I alluded to above; that is, he took the contrapositive of the given definition and is using that to show injectivity. 
Since $f(x)=2x$, he considers the following, where $x_1$ and $x_2$ are presumed to be elements in $\mathbb{Z}$ (this is why it's important to specify your domain and codomain; otherwise, it's ambiguous):
$$
f(x_1)=f(x_2)\\[0.5em]
2x_1=2x_2\\[0.5em]
x_1=x_2.
$$
Hence, the mapping $f\colon\mathbb{Z}\to\mathbb{Z}$ defined by $f(x)=2x$ is injective. 
Does this make more sense? 
A: A function is injective iff for $a\neq b$ you always have $f(a)\neq f(b)$. Equivalent to this is to prove that $f(a)=f(b)\Rightarrow a=b$, which is done there.
