Count the number of elements in each diagonal. The first diagonal contains only the number $0$, the second one contains $1$ and $2$, and so on. In the $kth$ diagonal, there are $k$ elements starting from $k=1$.
After traversing each diagonal, the starting x-coordinate $m$ always resets to $0$ while the starting y-coordinate $n$ increases by $1$ for each diagonal. While traversing each of the diagonals, $m$ increases by $1$ and $n$ decreases by $1$ until $n=0$. The formula $J(m,n)$ is generated as follows:
k-value |
first item |
second item |
third item |
$1$ |
$f(0,0)=0$ |
|
|
$2$ |
$f(0,1)=1$ |
$f(1,0)=2$ |
|
$3$ |
$f(0,2)=3$ |
$f(1,1)=4$ |
$f(2,0)=5$ |
To come up with a general expression for the first item in each diagonal, take the sum of all previous $k$ values. For instance, the first element in the diagonal $k=4$ would be $J(0,3)=1+2+3=6$ if the table was to be extended. The first item in each diagonal is generated by adding each of the integers from $1$ to $k-1$, yielding the expression $J(0,k-1)=\frac{(k-1)}{2}(1+(k-1))=\frac{k(k-1)}{2}$. Since each of the elements in the diagonals increases by $1$ each time $m$ increases by $1$, the expression for all items in the diagonals can be generalized as $J(m,n)=\frac{k(k-1)}{2}+m$.
To find $k$ in terms of $m$ and $n$, notice the pattern in each of the diagonals. $m$ increases from $0$ to $k-1$, while $n$ decreases from $k-1$ to $0$. This means $m+n=k-1$, or $k=m+n+1$. Substituting that into the general expression yields $J(m,n)=(m+n+1)(m+n)/2+m=\frac{1}{2} [(m+n)^2+3m+n]$, the desired result.