Proving that $\Bbb Z$ has the same cardinality has $\Bbb N_0$

I have seen some proofs concerning that $\Bbb Z$ is countable and in most of them, it's done by defining the following function:

\begin{equation*} f(n) = \begin{cases} f(n) = \frac{n}{2} \text{ if $n$ even } \\[.15cm] f(n) = -\left(\frac{n-1}{2}\right) \text{ if $n$ odd} \end{cases} \end{equation*} But my only problem is the following: Consider the case where $\Bbb N_0$ is the domain of $f$. Thus we would have $f(0) = 0/2 = 0$ and $f(1) = -0/2 = 0$ which would prove that we aren't in a bijection. This is indeed a surjective function, is it being a surjective funciton enough to prove $\Bbb Z$ has the same size has $\Bbb N_0$? Thanks for all the help in advance.


Solution 1:

Simply take $f(n) = -\frac{n+1}{2}$ for $n$ odd.

And yes, your original function is surjective but not injective. This suffices to prove the existence of a bijection. You have $f^{-1}(0) =\{0,1\}$ and all other fibers are singletons. Thus you can remove one of $0,1$ from $\mathbb N_0$ and obtain a bijection from the smaller $\mathbb N_0 \setminus \{i\}$ to $\mathbb Z$. But if you remove a finite set from an infinite set, you do not change cardinality.

Solution 2:

The function $f$ as given is a bijection $\mathbb N^{\geq1}\to\mathbb Z.$ If you want a bijection $\mathbb N^{\geq0}\to \mathbb Z$, you can just use the bijection $h:\mathbb N^{\geq0}\to\mathbb N^{\geq1},$ defined as $h(n)=n+1.$

The bijection $g=f\circ h:\mathbb N^{\geq0}\to \mathbb Z$ becomes:

$$g(n)=f(h(n))=f(n+1)=\begin{cases}\frac{n+1}2&n+1\text{ even}\\-\frac{n}2&n+1\text{ odd}\end{cases}$$ Of course, “$n+1$ even/odd” means “$n$ odd/even,” respectively. So this becomes: $$g(n)=\begin{cases}\frac{n+1}2&n\text{ odd}\\-\frac{n}2&n\text{ even}\end{cases}$$


This works in general, if you have a bijection $f:\mathbb N^{\geq1}\to X,$ there is a bijection $f\circ h:\mathbb N^{\geq0}\to X.$

Even more generally, a bijection $a:X\to Y$ and a bijection $b:Y\to Z$ means we get a bijection $b\circ a:X\to Z.$