I have a doubt with the following problem. I have to find if the function is injective, surjective and if bijective find the inverse function
$$f : \mathbb{Z} \longrightarrow \mathbb{N},\qquad f(a) = \begin{cases} 2a & \text{if } a >0, \\ 1 - 2a & \text{if } a \le 0. \\ \end{cases}$$
The solution to the problem:
Injectivity: $f(a)=f(b) \Rightarrow a=b$. Taking a $x_{1}$,$x_{2} \in \mathbb{Z}$, I separate into the following cases:
1) $x_ {1} > 0$, $x_{2} > 0:\; 2x_{1} = 2x_{2} \Rightarrow x_{1} = x_{2}$
2) $x_ {1} \le 0$, $x_{2} \le 0:\; 1-2x_{1} = 1-2x_{2} \Rightarrow x_{1} = x_{2}$
3) $x_{1} > 0, x_{2} \le 0:\;2x_{1} = 1-2x_{2} \Rightarrow 2x_{1} + 2x_{2} = 1 \Rightarrow (x_{1} + x_{2}) = 1/2$
The case $x_{2} > 0$, $x_{1} \le 0$, gives the same answer as the third case. My question is that if this conclusion makes the function not injective, or it simply is telling me that this is a case that cannot happen since $x_{1}$,$x_{2} \in \mathbb{Z}$.
Putting aside this, the function also is surjective and I could find the inverse function, that is
$$f^{-1} : \mathbb{N} \longrightarrow \mathbb{Z},\qquad f^{-1}(a) = \begin{cases} \text{a/2} &\text{if $a$ is even,} \\ \text{(1 - a)/2} &\text{if $a$ is odd.} \\ \end{cases} $$
Is this correct?
PD: First time writing LATEX, feedback is very welcomed!
For the 3rd and 4th cases, you just have to say it can't happen since $x_1$ and $x_2$ are integers.
However, I would put all this differently: the restrictions of $f$ to positive integers and to nonpositive integers are, separately, injective (affine functions).
Furthermore, if one of $x_1,x_ 2$ is $>0$ and the other $\le0$, one of $f(x_1), f(x_2)$ is an even and the other an odd integer. So they can't be equal, which proves that, globally, $f$ is injective.