I am working on the following problem:
given a matrix of M rows, I calculate a minimal distance matrix containing the absolute differences among all the possible couples of rows.
In order to make the distance matrix as minimal as possible, I do compute only the differences between the row
Iand the following rowsJ.
I now want to find a formula to know at which row K on the distance matrix is mapped the difference of the original matrix rows I and J.
The new matrix will have M(M-1)/2 rows.
E.g.
$$ \begin{matrix} 0 & 8 & 3 & 7\\ 5 & 4 & 8 & 6\\ 3 & 5 & 4 & 3\\ 2 & 3 & 7 & 4\\ \end{matrix} $$
will result in the following minimal distance matrix:
$$ \begin{matrix} 5 & 4 & 5 & 1\\ 3 & 3 & 1 & 4\\ 2 & 5 & 4 & 3\\ 2 & 1 & 4 & 3\\ 3 & 1 & 1 & 2\\ 1 & 2 & 3 & 1\\ \end{matrix} $$
Considering this example, the formula I am looking for should return the following values of K, given I, J and M in input:
$$ \begin{matrix} I & J & K\\ 0 & 1 & 0\\ 0 & 2 & 1\\ 0 & 3 & 2\\ 1 & 2 & 3\\ 1 & 3 & 4\\ 2 & 3 & 5\\ \end{matrix} $$
I am considering the rows and columns index as starting from zero.
Update
Each row I of matrix A M*N has exactly L rows in the minimal distance matrix:
$$ L = M - I - 1 $$