Jeff, you can do > sum1: \sum_i\sum_j max(X_i,X_j) > sum2: \sum_i\sum_j max(Y_i,Y_j) sum(x * (2 * rank(x) - 1)) > sum3: \sum_i\sum_j max(X_i,Y_j) sum(outer(x, y, pmax)) Probably, the latter can be speeded up even more... Z