The function $f(x,y) = \frac{(x+y-1)(x+y-2)}{2} + y $ is a bijection which maps ordered pairs of positive integers onto the positive integers. I would like to find the functions $g$ and $h$ such that $g(f(x,y)) = x$ and $h(f(x,y)) = y$.
Through examination of a table of values, I noticed that if $t$ is the largest triangular number less than $f(x,y)$ then $f(x,y) - t = y$, and if $T$ is the smallest triangular number greater than or equal to $f(x,y)$ then $T - f(x,y) + 1 = x$. This would reduce the original problem to finding functions for $t$ and $T$, but I am not sure if this is possible.
Any tips/hints would be very appreciated! I am also curious about more generic/algebraic approaches to this type of a problem.
$f(x,y) = \frac{(x+y-1)(x+y-2)}{2} + y = \frac{(x+y)^2-3(x+y)+2}{2} + y = \frac{u^2-3u+2}{2} + y =g(u, y) $ where $u = x+y$.
Since $1 \le y \le u-1$, $1+\frac{u^2-3u+2}{2} \le g(u, y) \le u-1+\frac{u^2-3u+2}{2} $. Therefore $g(u, y) \le \frac{u^2-3u+2+2(u-1)}{2} = \frac{u^2-u}{2} $ and $g(u+1, y) \ge 1+\frac{(u+1)^2-3(u+1)+2}{2} = \frac{u^2+2u+2-3u-3+2+1}{2} = \frac{u^2-u+2}{2} = \frac{u^2-u}{2}+1 $.
Therefore $g(u+1, 1) =g(u, u-1)+1 $, so there is no overlap in the $g$ values between $u$ and $u+1$.
So, for any particular index $n$, find the unique $u$ such that $\frac{u^2-u}{2}+1 \le n \le \frac{u^2-u}{2}+u-1 $. Then $x+y = u$, $y = n-u$, and $x=u-y$.
To find $u$ from $n$:
From the first inequality, $u^2-u \le 2n-2$ or $4u^2-4u+1 \le 8n-7$ or $2u-1 \le \sqrt{8n-7}$ or $u \le 1+\frac12\sqrt{8n-7}$, or $u \le 1+\lfloor\frac12\sqrt{8n-7}\rfloor$.
From the second inequality $n \le \frac{u^2-u}{2}+u-1$ or $8n \le 4u^2-4u+8u-8 =4u^2+4u-8 =4u^2+4u+1-9 $ or $8n+9 \ge (2u+1)^2$, or $2u+1 \ge \sqrt{8n+1}$, or $u \ge \frac12(\sqrt{8n+1}-1)$, or $u \ge \lceil\frac12(\sqrt{8n+1}-1)\rceil$.