I want to create a bijective mapping $f:\mathbb{N}^2\to\mathbb{N}$ in order to assign a unique single-index coefficient to each polynomial basis function in the following $n^{th}$-order bivariate polynomial (where the terms can be arranged in a triangular grid). Letting $N=(n+1)$, $$P_n(x,y) = \sum^{N}_{s=1}\sum^{N-s}_{r=1} c_{i}x^{r-1}y^{s-1},\ \ i = r + \frac{1}{2}\big[N(N+1) - (N+1-s)(N+2-s)\big]\in[1,N(N+1)/2].$$ I have managed to formulate $i = f(r,s)$ by using the general formula for triangular numbers. However, I require the inverse $f^{-1}:\mathbb{N}\to\mathbb{N}^2$ as well, but I am not sure how to compute this. Can someone advise me on this?
If it helps, the following is a different bivariate polynomial (where the terms can be arranged in a square grid) for which I have both $f$ and $f^{-1}$: $$P_n(x,y) = \sum^{N}_{s=1}\sum^{N}_{r=1} c_{i}x^{r-1}y^{s-1}.$$ where $$i = f(r,s) = r + (s-1)N\in[1,N^2]\quad \text{and}\quad (r,s) = f^{-1}(i) = \big(i-(s-1)N,\ 1+\lfloor (i-1)/N \rfloor\big)$$ The $\lfloor\cdot\rfloor$ denotes the floor function above.
$\text{Edit:}$ I'd appreciate alternate tag suggestions too, as I wasn't quite sure what the most appropriate tags would be for this post.