# Basic question about showing bijection when a function is defined piece wise

Hello there everyone,

I was told that the standard proof for showing that

$$| \mathbb{N} | = | \mathbb{Z} |$$

is to define $$f: \mathbb{Z} \to \mathbb{N}$$ as $$f(x)= \begin{cases} 2x &\text{ if x \ge 0} \\ -2x-1 &\text{ if x \lt 0} \end{cases}$$

Now, I am a bit confused. I am used to working with non piece wise functions, were we must show that $f(x_1)=f(x_2)$ implies $x_1=x_2$ and that for every $n \in \mathbb{N}$ there must exist a $z \in \mathbb{z}$ such that $f(z)=n$

But I am not sure how to do this for this type of function.

Thank you all

• Do it by cases. Case 1: $x_1\ge0,x_2\ge0.$ Case 2: $x_1\ge0,x_2\lt0.$ Case 3: $x_1\lt0,x_2\ge0.$ Case 4: $x_1\lt0,x_2\lt0.$
– bof
Aug 9, 2015 at 0:52

For a positive integer, $x$, $2x$ is even and positive. For a negative integer, $x$, $-2x-1$ is positive and odd.
${\color{red}0},{\color{blue}{-1}},{\color{red}1},{\color{blue}{-2}},{\color{red}2},{\color{blue}{-3}},{\color{red}3},...,{\color{blue}{-n}},{\color{red}n},... \longrightarrow {\color{red}0},{\color{blue}{1}},{\color{red}2},{\color{blue}{3}},{\color{red}4},{\color{blue}{5}},{\color{red}6},...,{\color{blue}{2n-1}},{\color{red}{2n}},...$
1. Assume $f(x_1) = f(x_2)$ and wlog assume it to be an even number, then clearly $x_1 = x_2$ because we know the function $x \mapsto 2x$ to be a bijection.
2. For the reverse direction, consider the function $g(n) = n/2$ if $n$ is even and $-(n+1)/2$ if $n$ is odd.