1

I think I can use a bijection between $\mathbb{Z}$ and $\mathbb{N}$ to transform $\mathbb{Z}\times\mathbb{Z}$ into $\mathbb{N}\times\mathbb{N}$ and then use the Cantor pairing function, but is there an explicit bijection with fewer computational steps?

Alexey
  • 151
  • 4

2 Answers2

3

The function $f=\left( -1\right)^n\lfloor \frac{n}{2}\rfloor$ bijects $\mathbb{N}$ with $\mathbb{Z}$ if we define $0\notin\mathbb{N}$. (Whatever bijects with this definition of $\mathbb{N}$ can trivially be modified otherwise with the shift $n\mapsto n-1$.) The function $g\left(2^k r\right)=\left(k+1, \frac{r+1}{2}\right)$ with $r$ odd bijects $\mathbb{N}$ with $\mathbb{N}^2$. Thus the function $h\left(2^k r\right)=\left(f\left( k+1\right), f\left(\frac{r+1}{2}\right)\right)$ bijects $\mathbb{N}$ with $\mathbb{Z}^2$.

J.G.
  • 115,835
1

Originating at $(0,0) \in \mathbb{Z} \times \mathbb{Z}$, imagine walking a square spiral where each step would add one to our counter and biject to the appropriate number in $\mathbb{N}$. For example, first you would walk up 1 step, left 1 step, down 2, right 2, up 3, and so on...

It is easy to see that this is a bijection and would cover the entire space of $\mathbb{Z} \times \mathbb{Z}$. It is perhaps very easy to visualize, however writing the bijection explicitly may be tougher.