After a lot of effort I discovered some pattern that the function:
$$Pair(x,y) = \frac{(x+y)(x+y+1)}{2} + x$$
essentially zigzags along the grid with $\mathbf N$ vs $\mathbf N$ (natural numbers). So intuitively, given any P(x,y) we follow the grid path. However, this seems like a very hacky way to understand it. How could someone have come up with this? Where did it come from? It looks nothing at all random and it has very interesting properties like:
- its bijective
- its computable (easy to prove)
- if $Pair(x,y) =a $ then $Right(a) = x \leq a$ and $Left(a) = y < a$.
number 1 and 3 seem especially especial (and I wonder why they are true). But is this property of zigzagging obvious just by looking at the equation? (as well as the other properties)? Should this zigzaging be obvious without brute forcing the computaiton of 100 of these numbers? I am assuming their is some sort of pattern to this function but I can't see it...
context: comes up in development of Godel numbering: https://faculty.math.illinois.edu/~vddries/main.pdf
page 85.
Zigzagging is kind of obvious if you look at it in the right way. Pair of $x$ and $y$ is equal to the $(x+y)$th triangle number, plus $x$. The $y$ term is guaranteeing that the "plus $x$" term on the end will not cause the traversal to run more than the full length of the hypotenuse. So $y$ is effectively telling you how tall the triangle is (in the sense of distance from the origin along the line $y=x$ to the hypotenuse), and $x$ is telling you where along the hypotenuse you're located.