It was late last night when I wrote the first post so it was short on explanation ... so here is a brief explanation ...
Every time one ballot ranks x before y and the other one doesn't, there is a discrepancy that separates them in ballot space. A complete reversal to y ahead of x is twice as serious as a mere change to equality in rank.
To assure freedom from clone bias the discrepancy is weighted by the product P(x)P(y) where P is a probability.distribution that distributes P(x) among x1,x2,x3, etc. when x is is replaced by a set of closely clustered clones.
The matrix manipulation keeps track of the count of weighted discrepancies... in particular, the entry in row x, column y of M1 is (supposed to be) a one if x is ranked ahead or equal to y, otherwise zero.
So M1(x, y) minus M1(y, x) is one, zero, or negative one, depending on whether x>y, x=y, or x<y. So if M, defined as
(M1 - transposeM1) - (M2 - transposeM2)
is zero, the two ballot rankings are identical.
Otherwise, the absolute values of the entries in M reflect the severity of descrepency., which brings us to the matrix A of absolute values of the entries in M.
Finally pre and post multiplying A by b and b', the row of benchmark probabilites (random ballot probabilities) and its transpose puts in the weights, and sums the weighted discrepancies. Divide by two (or four) as desired to normalize the distance.