Doubts in finding an example of a bijective function $f:\mathbb{N} \to \mathbb{Z}$ 
Give an example of a bijective function $f:\mathbb{N} \to \mathbb{Z}$.

I consider the function $f:\mathbb{N} \to \mathbb{Z}$ defined as
$$f(n):=\begin{cases} n/2, \ \text{if} \ n \ \text{is even} \\ -(n+1)/2, \ \text{if} \ n \ \text{is odd}\end{cases}$$
I have two questions: one on my work and one more general.

*

*For my work: about injectivity, is easy to show that if $n_1$ and $n_2$ are both even or both odd then the implication $f(n_1)=f(n_2) \implies n_1=n_2$ holds; if, without loss of generality, it is $n_1$ even and $n_2$ odd I get that $f(n_1)=f(n_2) \iff n_1=-n_2-1$ which is absurd because $n_1 \ge 0$ and $-n_2-1 <0$. So I deduced that this case can't occur, because it leads to a contradiction. So, since all the comtemplable cases implies that $f$ is injective, I deduced that $f$ is overall injective. Is this correct? Moreover, I have a "logic" doubt: I am not fully convinced why the fact that the case $n_1$ even and $n_2$ odd leads to a contradiction allow us to conclude that $f$ is injective and not to the conclusion that that $f$ is not injective. Is this related to the fact that injectivity is defined as an implication and so we assume $f(n_1)=f(n_2)$ true and it is not that we already know that $f(n_1)=f(n_2)$ is true, and so any contradiction obtained from that the assumption means that $f(n_1)=f(n_2)$ cannot occur and so it is not a contemplable case, so it must be excluded in the study of the injectivity and so, consequently, it doesn't give any information about the injectivity or not injectivity of the function and so this information is only related to all the other possible cases?


*For the general theory: some authours define $\mathbb{N}$ as the set of positive integers, hence for some authors $0 \notin \mathbb{N}$; how things work in this cases? I tried to use a similar function
$$g(n):=\begin{cases} n/2, \ \text{if} \ n \ \text{is even} \\ -(n-1)/2, \ \text{if} \ n \ \text{is odd}\end{cases}$$
All works for the most part the same, except for the fact that I get a similar contradiction for $n_1$ even and $n_2$ odd given by the fact that $f(n_1)=f(n_2) \iff n_1+n_2=1$ and, since $n_1$ is even and $n_2$ is odd, this is possible only if $n_1=0$ and $n_2=1$ but $n_1$ can't be $0$ because, in this convention, $0 \notin \mathbb{N}$. Could this be correct? If this is correct, it is normal that if some mathematical object (like functions) has a property (like injectivity) then this property could be independent of the way we define a certain set like the positive/nonnegative integers? Or this was just a lucky situation?
 A: For (1) your argument is just fine. When $a$ and $b$ have the same parity you proved that if $f(a) = f(b)$ then $a = b$, so each element in the range is hit at most once. Your argument when one is odd and one is even is correct too, but awkward. Here's a direct way that does not use contradiction:

If $a$ is even and $b$ is odd then $f(a) \ge 0$ and $f(b) <0 $  so can't be equal.

For (2) your argument when the definition of $\mathbb{N}$ excludes $0$ is correct too. You puzzle is

if some mathematical object (like functions) has a property (like
injectivity) then this property could be independent of the way we
define a certain set like the positive/nonnegative integers?

That doesn't really make sense. Injectivity is a property of a function. Part of the definition of a function is specifying the domain. You are dealing with two different domains and (necessarily)  different functions. Each happens to be a bijection. They look somewhat alike because you created the second by modifying the first but they are just different functions. Nothing in the argument says anything about whether $0$ is or is not included in when you define the natural numbers.
You could have created the second bijection from the first by using rather than modifying the first.
The three sets you are interested in are
$$
A = \{0, 1, 2, \ldots\}\\
B = \{ 1, 2, \ldots\}\\
C = \{ \dots -2, -1, 0, 1, 2, \ldots\} 
$$
Since you have constructed a bijection between $A$ and $C$ the easiest way to find one between $B$ and $C$ is to compose it with the obvious "shift by $1$" bijection between $A$ and $B$.
