I have a list of pairs, for example:
pairs={{13, 10}, {12, 14}, {10, 36}, {35, 11}, {3, 5}, {1, 6},
{20, 24}, {21, 22}, {33, 7}, {31, 8}, {31, 27}, {32, 25},
{21, 35}, {34, 19}, {18, 15}, {14, 16}, {9, 5}, {4, 7},
{1, 13}, {15, 2}, {6, 36}, {4, 34}, {8, 2}, {9, 3}, {25, 20},
{19, 26}, {22, 11}, {23, 12}, {32, 28}, {30, 33}, {23, 16},
{24, 17}, {29, 27}, {26, 30}, {17, 28}, {18, 29}};
pairs
can be seen as the definition of a relation $R$. $x$ and $y$ satisfy the relation if and only if {x,y}
$\in$ pairs
. I need to compute the equivalence classes of the symmetric transitive closure of $R$.
In other words, I need to compute a list eqvclss
. The elements of eqvclss
are lists themselves. For example, 13, 10, 36, 6, 1, ... should all be in the same list in eqvclss
. (If you understand that, then I explained the question properly; if you don't, say so in the comments so I can try to improve).
{13,10}
and{10, 36}
, you conclude that10
and13
belong together. But13
also belongs with1
because{1, 13}
exists. However, there is no pair{1, 10}
or{10, 1}
, so1
shouldn't be in the same group as10
, which is in the same group as13
which belongs with1
. So the problem forGather
is that your identity relation is not transitive. As a result, you have to give up some conditions. Maybe you want all gathered groups to be numbers that are at least indirectly connected? $\endgroup$