# Why does the gather not seem to work?

Why isn't {4, 6} include in the first group? I expected the result would be {{{1, 9}, {2, 3}, {4, 6},{5, 10}}, {{11, 15}}} because Intersection[{2, 3} /. myRule, {4, 6} /. myRule] != {} also gives True but I don't know why it doesn't work here.

myRule = {1 -> x, 2 -> x, 3 -> y, 4 -> y, 5 -> z, 6 -> z, 7 -> t,
8 -> t, 9 -> g, 10 -> g};
Gather[{{1, 9}, {2, 3}, {4, 6}, {5, 10}, {11, 15}},
Intersection[#1 /. myRule, #2 /. myRule] != {} &]
(*{{{1, 9}, {2, 3}, {5, 10}}, {{4, 6}}, {{11, 15}}}*)


Look at what is actually tested:

myRule = {1 -> x, 2 -> x, 3 -> y, 4 -> y, 5 -> z, 6 -> z, 7 -> t,
8 -> t, 9 -> g, 10 -> g};
Gather[{{1, 9}, {2, 3}, {4, 6}, {5, 10}, {11, 15}},
Intersection[
Print[{##, Intersection[#1 /. myRule, #2 /. myRule] != {}}]; #1 /.
myRule, #2 /. myRule] != {} &]


Note that in a group all members must test pairwise to True and a member can not belong to more than one group. You see that {{1, 9}, {2, 3}, {5, 10}} is a group. As {2,3} is already in this group it is not again tested against {4,6} because {4,6} does test to False against the member {1,9}.

• Thanks. If so, I think I misunderstood how the function work. I was thinking that it would test for all pairs, here 10 pairs from the 5 elements and if a pair gives a True then it will add that to the the result. Finally it would delete the duplicates in the result and return the final result. Commented May 31 at 8:18