On the bijection between the naturals and a countable number of countable sets. I am assuming we are utilizing the axiom of choice because I read in the suggested questions that may have my answer that it's needed for the following bijection to work.
Suppose I am given a countable number of sets $A_1, A_2 \dots$ each with a countable number of elements, I will use the notation that given a set $A$ the first element will be represented as $A(1)$ and so forth.
I was shown a bijection $f$ that puts these in correspondence with the natural numbers as follows:
$$f(1) = A_1(1), \quad f(2) = A_1(2), \quad f(3) = A_2(1), \quad f(4) = A_1(3), \quad f(5) = A_2(2), \quad f(6) = A_3(1) \quad \dots $$
And I was told that the explicit bijection is $$f(\frac{n^2+2nx + x^2 -3x - n +2}{2}) = A_n(x)$$
Where $x$ takes values in the naturals.
How is the formula for this bijection derived?
 A: The pattern being followed is shown here. As Gae. S. indicates, this works off of a particular map from $\Bbb N \to \Bbb N \times \Bbb N$ that follows this path:

(taken from http://www.cut-the-knot.org/do_you_know/countRatsX.shtml)
Someone apparently has taken the time to calculate this map is the inverse function of $$\rho\ :\ \Bbb N \times \Bbb N \to \Bbb N\ :\ (n, x) \mapsto \frac{n^2+2nx + x^2 -3x - n +2}{2}$$
(I've never seen anyone bother to figure that out, before. Usually, they just take it as obvious from the path that such a map exists, which is all that you need to prove the theorem.)
So far, the axiom of choice is not involved. The only place it comes up is this: All you know about the $A_i$ is that they are countable. But in proclaiming that there is a "least element" of $A_1$ to be called $A_1(1)$, etc. you are actually choosing for each $i$, a particular mapping from some initial segment of $\Bbb N$ to $A_i$. This requires using the Axiom of Choice (or at least, of Countable Choice, which is weaker). Once you have made these choices, then you can define a map from $$g\ :\ \Bbb N \times \Bbb N \to \bigcup_{i=1}^\infty A_i\ :\ (n, x) \mapsto A_n(x)$$
Then your $f = g\circ \rho^{-1}$.
But there are two problems with calling this a bijection, or even fully defined. "Countable" does not imply infinite. Finite sets are also countable. ("Denumerable" is the condition of being both countable and infinite.) If the number of sets $A_i$ is finite, or if any of the $A_i$ are themselves finite, then $f$ is not a bijection between $\Bbb N$ and $\bigcup_{i=1}^\infty A_i$. In fact, there are some $n$ for which $f(n)$ is not even defined. $f$ will only be a bijection when the collection $\{A_i\}$ is infinite, and each $A_i$ is also infinite. Or at least, if it doesn't run afoul of the second problem.
The second problem is that we don't know if $A_i$ are disjoint. It could even be that for all $i > 1, A_i \subseteq A_1$. Even if everything is denumerable, if there is even one element common to two of the sets, say $A_i(x) = A_j(y)$, then $f$ will not be an injection, as $$f(\frac{i^2+2ix + x^2 -3x - i + 2}{2}) = f(\frac{j^2+2jy + y^2 -3y - j + 2}{2})$$
Finally, to answer the exact question you asked, if you look at the figure above, the indexes for the first column are $1,3,6,10,16,...$. These are the triangular numbers. The $n$th such number is the sum from $1$ to $n$, and is well-known to be $\frac{n(n+1)}2$. To get the rest of the indices along a diagonal, subtract the column number less $1$ from the triangular number from the first column. For row $n$ column $x$, the triangular number is for $n + x - 1$, so it is $\frac{(n+x)(n+x-1)}2 - (x - 1)$, which simplifies to your formula.
