I encountered this question along with its proof in which I have to prove that the Cartesian product $ \mathbb{Z}^{+} \times \mathbb{Z}^{+} $ is countably infinite. (I don't know any advanced set theory and so my only understanding is that I have to find a bijection between $ \mathbb{Z}^{+} \times \mathbb{Z}^{+} $ and $ \mathbb{Z}^{+}. $)
Here's the proof from my textbook (Munkres Topology), quoted verbatim: First we define a bijection $ f : \mathbb{Z}^{+} \times \mathbb{Z}^{+} \to A $ where $ A $ is a subset of $ \mathbb{Z}^{+} \times \mathbb{Z}^{+} $ consisting of pairs $ (x,y) $ for which $ y \leq x, $ by the equation $ f(x, y) = (x + y - 1, y). $ Then we define a bijection $ g : A \to \mathbb{Z}^{+} $ by the rule $ \displaystyle g(x, y) = \frac{1}{2}(x - 1)x + y. $
I have successfully showed that $ f $ is a bijection and that $ g $ is one-to-one. To show that $ g $ is onto, suppose that $ a \in \mathbb{Z}^{+}, $ I need to find a pair $ (x, y) $ such that $ y \leq x $ and that $ \displaystyle a = \frac{1}{2}(x - 1)x + y. $ Solving this in terms of $ x $ yields $ \displaystyle x = \frac{1 \pm \sqrt{1 - 8(y - a)}}{2}, $ but there's no guarantee that you can find such integers $ x $ and $ y $ that satisfies these requirements. Am I doing anything wrong? If I redefine $ g(x, y) = (y - 1)y + x, $ then for every $ a \in \mathbb{Z}^{+}, $ I can simply choose $ x = a $ and $ y = 1 \; (x \geq y $ in this case) and it follows that $ g(a, 1) = a. $
Also, if anyone could help me understand the motivation behind this proof, i.e. why the author defines $ f $ and $ g $ in the first place. I seem to get the proof but not the process of coming up with such a proof.