# Describing a bijection between $\{0,1\} \times \mathbb N$ and $\mathbb Z$.

I'm having a bit of trouble formulating a bijection between the sets $\{0,1\} \times \mathbb N$ and $\mathbb Z$. I understand how to find a bijection between $\mathbb N$ and $\mathbb Z$ using a piecewise function that sends even values of $\mathbb N$ to positive integers and odd values of $\mathbb N$ to negative integers, but I'm a bit stuck formulating a function $f(a,n)$ for these two sets. Any help would be greatly appreciated and I apologize for formatting.

• you can start with $f((0,n))=n$ and $f((1,n))=-n$ this is almost an answer. (the difficult part is dealing with zero) – Yanko Oct 20 '17 at 13:25
• Do you include $0$ in $\mathbb N$? – Wojowu Oct 20 '17 at 13:27
• I believe that ℕ generally excludes 0. – John21 Oct 20 '17 at 13:28
• I quickly saw my mistake, but you guys are faster – Gustavo Oct 20 '17 at 13:31

Visual solution:

$\mathbb N$ looks like this:

$$\times\times\times\times\times\times\times\times\times\times\cdots\\$$

So $\mathbb N\times\{0,1\}$ looks like this:

$$\times\times\times\times\times\times\times\times\times\times\cdots\\ \times\times\times\times\times\times\times\times\times\times\cdots\\$$

While $\mathbb Z$ looks like this:

$$\cdots\times\times\times\times\times\times\times\times\times\times\cdots\\$$

Now, imagine you take the middle picture and you take the upper line of $\times$-s and flip it so you would get:

$$\cdots \times\times\times\times\times\times\times\times\times\times\times\\ \times\times\times\times\times\times\times\times\times\times\cdots\\$$

Now, imagine if I draw a little more space between two arbitrary elements of $\mathbb Z$:

$$\cdots \times\times\times\times\times\times\qquad\times\times\times\times\times\times\cdots\\$$

Can you see the bijection that is naturally appearing between these two sets?

Assuming $\Bbb N$ does not contain zero, you can use

$$f(s,n)\quad=\quad\begin{cases} n&\text{for s=0} \\ 1-n &\text{for s=1}\end{cases} \quad=\quad (-1)^s\left(n-\frac12\right)+\frac12$$

which can be written with or without cases.