How do I prove that a multi-part function is injective and/or surjective? Consider the following function I came up with to demonstrate that $\left|\mathbb{Z}\right|=\aleph_{0}$...
$f:\mathbb{N}\to\mathbb{Z}$, $f(x)=\begin{cases}-x/2&\mbox{if }x\equiv 0\\(x+1)/2&\mbox{if }x\equiv 1.\end{cases}\pmod 2$
I want to prove that this is both injective and surjective, but given the fact that it is in two parts, I'm not sure how to approach it. I've only ever proven that a function is injective and/or surjective when it is a simple (not in multiple parts).
 A: Hint: Your function maps evens into positive integers and odds into nonpositive integers. Because of the sign difference, it is clear that no even maps to the same value as an odd. So you just have to show that evens are in bijective correspondence with positives, and odds are in bijective correspondence with nonpositives. 
It will probably be useful to note that for an even $2k$, one has $f(2k)=-k$ and for an odd $2k-1$, one has $f(2k-1)=k$ (where $k=1,2,3,\ldots$).
A: Here is a little sketch:
$f$ is surjective. Let $n$ be an arbitrary integer. There are two possibilities, either $n>0$ or $n\leqslant0.$
Case I. $n>0.$ Let $x:=2n-1.$ This number is clearly positive and so $x\in\mathbb N.$  Case II. $n\leqslant0.$ Let $x:=-2n.$ This number is clearly non-negative and so $x\in\mathbb N.$
Therefore, no matter which $n\in\mathbb Z$ you take, there will always exist some $x\in\mathbb N$ such that $f(x)=n.$
$f$ is injective. Suppose that $f(i)=f(j)=r$ for some $i,j\in\mathbb N.$ There are four possibilities: 
$(a)$ $i\equiv j\equiv0\pmod2.$ 
$(b)$ $i\equiv j+1\equiv0\pmod2.$  
$(c)$ $i\equiv j\equiv1\pmod2.$ 
$(d)$ $i\equiv j+1\equiv1\pmod2.$
Consider each of those cases and conclude that only $(a)$ and $(c)$ can happen.
