Prove that the union of two disjoint countable sets is countable

A formal proof would be something like this. If $A$ and $B$ are countable (and disjoint) sets, then there exist injective functions $f$ and $g$ from $A$ and $B$, respectively, to $\mathbb{N}$. Let $C=A\cup B$ and define a function $h:C\rightarrow\mathbb{N}$ as follows:

$$h(z) = \begin{cases}2f(z) & \text{if } z\in A\\ 2g(z)+1 & \text{if } z\in B\end{cases}$$

Then, if $x\neq y$, we clearly have $h(x)\neq h(y)$ since if $x,y\in A$ this follows from the fact that $f$ is injective (analogously for $x,y\in B$) and if $x\in A$ and $y\in B$, we have that $h(x)$ is even while $h(y)$ is odd (analogously for $x\in B$, $y\in A$). Hence $h$ is an injective function from $C$ to $\mathbb{N}$ and thus, by definition, $C$ is countable.


(In the following, countable means what is often referred to as countably infinite, i.e. countable and not finite)

A set $A$ is called countable if there exists a bijection $f$ between $A$ and the set of natural numbers $\mathbb{N}$. In other words, $A$ is countable if there is some mapping $f \,:\, A \to \mathbb{N}$ such that $f$ hits every element of $\mathbb{N}$ exactly once. Note that any such $f$ has a uniquely defined inverse $f^{-1}$.

It follows that there exists a bijection $f_{A,B}$ between any two countable sets $A$ and $B$, because if $f_A$ is a bijection from $A$ to $\mathbb{N}$, and $f_b$ a bijection from $B$ to $\mathbb{N}$, then $x \mapsto f_B^{-1}(f_A(x))$ is a bijection from $A$ to $B$.

Therefore, to show that the union of two arbitrary disjoint countable sets is countable, it suffices to show that the union of two specific disjoint countable sets $A,B$ is countable. This works because if $X,Y$ are disjoint and countable, by the above there are bijections $f_X \,:\, X \to A$, $f_Y \,:\, Y \to B$, and a bijection $g \,:\, A \cup B \to \mathbb{N}$. We can therefore define a biection from $f \,:\, X \cup Y$ to $\mathbb{N}$ by setting $$ f(z) = \begin{cases} g(f_X(z)) &\text{if $z \in X$,} \\ g(f_Y(z)) &\text{if $z \in Y$.} \end{cases} $$ (I leave the proof that this actually is a bijection to you)

Since we can view $\mathbb{Z}$ as the disjoint union of $\mathbb{N} = \{0,1,\ldots\}$ and $\mathbb{Z} \setminus \mathbb{N} = \{\ldots,-2,-1\}$, it therefore suffices to

  1. show that $\mathbb{Z} \setminus \mathbb{N}$ is countable, i.e. to find a bijection between $\{\ldots,-2,-1\}$ and $\{0,1,\ldots\}$, and

  2. show that $\mathbb{Z}$ is countable.