2
$\begingroup$

I'm trying to generate a list of all possible unions of some sets to generate a topological space from a given basic sets. For ex: Given

{1}, {2}, {4}, {1,3}

I should get

{{}, {1}, {2}, {4}, {1, 2}, {1, 3}, {1, 4}, {2, 4}, {1, 2, 3}, {1, 2, 4}, {1, 3, 4}, {1, 2, 3, 4}}

I found the following interesting post

https://stackoverflow.com/questions/8814059/generating-topological-space-diagram-in-mathematica/8815337

But it includes intersection of sets as well.

$\endgroup$
  • 1
    $\begingroup$ Try the topoCover function from this answer in the post you've linked, For example: topoCover[{{1}, {2}, {4}, {1,3}}] returns {{}, {1}, {2}, {4}, {1, 2}, {1, 3}, {1, 4}, {2, 4}, {1, 2, 3}, {1, 2, 4}, {1, 3, 4}, {1, 2, 3, 4}}. $\endgroup$ – creidhne Jan 14 at 9:34
2
$\begingroup$
sets = {{1}, {2}, {4}, {1, 3}};

Union[Union @@@ Subsets[sets]]
(*    {{}, {1}, {2}, {4}, {1, 2}, {1, 3}, {1, 4}, {2, 4},
       {1, 2, 3}, {1, 2, 4}, {1, 3, 4}, {1, 2, 3, 4}}        *)
$\endgroup$

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.