Pensieve Header: Code to find equivalence classes, given some "decleration of equivalence".

Copied from the FastKh` code within KnotTheory`.

?Fold

?FoldList

?Position

EquivalenceClasses[l_List]:=Module[{pos},
Fold[
(
pos=First/@Position[#1,#2];
Append[Delete[#1,List/@pos],Union@@(#1[[pos]])]
)&,
l,
Union@@l
]];

l={{1,2,3},{2,6},{7,8},{4,7},{5,6}}

Union@@l

EquivalenceClasses[l]