3
$\begingroup$

Given a set $E$, how can I find all pairs of subsets $E_1, E_2$ which are non empty and disjoint? I don't care the order of $E_1, E_2$.

Right now I use a bit complicated code. First find all partitions, and the choose subsets from them.

partition[elist_] := Module[{lengthsAll},
  lengthsAll = 
   Flatten[Permutations /@ IntegerPartitions[Length[elist]], 1];
  FoldPairList[TakeDrop, elist, #] & /@ lengthsAll
  ]

e0e2[elist_] := Module[{part},
  part = partition[elist] // Select[#, Length[#] >= 2 &] &;
  part = Subsets[#, {2}] & /@ part // Flatten[#, 1] &
  ]
$\endgroup$
4
$\begingroup$
ClearAll[f]
f = Select[Apply[DisjointQ]] @ Subsets[Subsets[#, {1, ∞}], {2}] &;

f[{a, b, c}]
{{{a}, {b}}, {{a}, {c}}, {{a}, {b, c}}, {{b}, {c}}, {{b}, {a, c}}, {{c}, {a, b}}}

Note: This is not quite the same as the list produced by OP's e0e2:

Sort @ e0e2[{a, b, c}]
{{{a}, {b}}, {{a}, {c}}, {{a}, {b, c}}, {{b}, {c}}, {{a, b}, {c}}}
$\endgroup$
1
  • $\begingroup$ I see, I made a mistake and missed one. $\endgroup$ – ablmf May 1 '20 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.