Bijection/Examples/-1^x of Floor of Half x from Natural Numbers to Integers

Example of Bijection
Let $f: \N \to \Z$ be the mapping defined from the natural numbers to the integers as:
 * $\forall x \in \N: f \paren x = \paren {-1}^x \floor {\dfrac x 2}$

Then $f$ is a bijection.

Proof
Let $x_1, x_2 \in \N$.

Suppose $f \paren {x_1} = f \paren {x_2}$.

Then, for a start:
 * $\paren {-1}^{x_1} = \paren {-1}^{x_2}$

and so $x_1$ and $x_2$ are either both even or both odd.

Suppose $x_1$ and $x_2$ are both even.

Then:

Suppose $x_1$ and $x_2$ are both odd.

Then:

Thus:
 * $\forall x_1, x_2 \in \N: f \paren {x_1} = f \paren {x_2} \implies x_1 = x_2$

and so $f$ is an injection by definition.

Let $y \in \Z$ such that $y \ge 0$.

Consider the natural number $x = 2 y$.

Then:

Thus:
 * $\forall y \in \Z_{\ge 0}: \exists x \in \N: f \paren x = y$

Let $y \in \Z$ such that $y < 0$.

Consider the natural number $x = 2 \paren {-y} + 1$.

Then:

Thus:
 * $\forall y \in \Z_{<0}: \exists x \in \N: f \paren x = y$

Thus by definition $f$ is a surjection by definition.

Thus $f$ is both an injection and a surjection, and so by definition a bijection.