<s>[INST] Can we prove the same cardinality of the sets $\mathbb{N}$ and $\mathbb{N^2}$ this way? I tried  to prove that the sets $\mathbb{N}$ and $\mathbb{N^2}$ have the same cardinality and I concluded the following:
Consider the function $f:\mathbb{N}\rightarrow \mathbb{N^2}$ that achieves the mapping:
$ \begin{cases} 1 \rightarrow (0,0) \end{cases} \\ 
\begin{cases} 2 \rightarrow (1,0) \\ 
3 \rightarrow (1,1) \\ 
4 \rightarrow (0,1) \end{cases} \\ 
\begin{cases} 5 \rightarrow (2,0) \\ 
6 \rightarrow (2,1) \\ 
7 \rightarrow (2,2) \\ 
8 \rightarrow (1,2) \\ 
9 \rightarrow (0,2) \end{cases} \\ 
\quad \vdots$
This way $\forall k \in \mathbb{N}\cup\{0\}$ we construct the function:
$f(n) = \begin{cases} \begin{aligned} 
&(\sqrt{n-1},0) \\
&(\sqrt{n-1},1) \\ \vdots \\ 
&(\sqrt{n-1},\sqrt{n-1}-1) \\ 
&(\sqrt{n-1},\sqrt{n-1}) \\ 
&(\sqrt{n-1}-1,\sqrt{n-1}) \\ \vdots \\ 
&(1,\sqrt{n-1}) \\ 
&(0,\sqrt{n-1}) 
\end{aligned} 
&& 
\begin{aligned} 
&, n=k^2+1 \\ 
&, n=k^2+2 \\ \\ 
&, n=k^2+k \\ 
&, n=k^2+k+1 \\ 
&, n=k^2+(k+1)+1 \\ \\ 
&, n=k^2+(2k-1)+1 \\ 
&, n=k^2+2k+1=(k+1)^2 
\end{aligned} \end{cases}$
Is the above mapping correct? If not then why? If yes then how can I prove rigorously that this function is bijective?
 [/INST] With $0 \in \mathbb N$ we trace out a path:
$(0,0) \to$
$(1,0) \to (1,1) \to (0,1) \to $
$(2,0) \to (2,1) \to (2,2) \to (1,2) \to (0,2) \to $
$(3,0) \to (3,1) \to (3,2) \to (3,3) \to (2,3) \to (1,3) \to (0,3) \to $
$\text{etc.} \qquad \text{Figure 1}$
Here is the corresponding mapping:
$$   
    \pi(m,n) = \left\{\begin{array}{lr}
        n^2+2n-m, & \text{for } m \le n\\
        m^2+n, & \text{for } m \gt n
        \end{array}\right\} 
$$
As a check, apply $\pi$ to Figure 1:
$\pi(0,0) = 0$
$\pi(1,0)=1 \; \pi (1,1)=2 \; \pi (0,1)=3$
$\pi(2,0)=4 \; \pi (2,1)=5 \; \pi (2,2)=6 \; \pi (1,2)=7 \; \pi (0,2)=8 $
$\pi(3,0)=9 \; \pi (3,1)=10 \; \pi (3,2)=11 \; \pi (3,3)=12 \;  \pi (2,3) =13 \; \pi (1,3) =14 \; \pi (0,3)=15 $
$\text{etc.} \qquad \pi\text{(Figure 1)}$
Proposition: If $k \in \mathbb N$ then the mapping $\pi$ restricted to
$\quad \{(m,n) \, | \, max(m,n) \le k$}
is $\text{1:1}$ and onto the initial segment $[0,\,{(k+1)}^2-1]$.
Proof
Hint: Use induction on $k$.
</s>