Fixed a bug where the weakest equivalence relation wasn't being updated

With the old code, if you reverse the order of the lists, you get the wrong answer.

e.g.:
List A = Arrays.asList(6, 3, 5, 1);
List B = Arrays.asList(5, 0, 1, 2);

Outputs:
[0, 1, 1, 0, 4, 1, 5]

Instead of:
[0, 1, 1, 0, 4, 1, 1]

This commit fixes that. The equivalent C++ doesn't have the same problem.