TransWikia.com

List of all possible unions of given sets

Mathematica Asked by Topologica on April 13, 2021

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.

One Answer

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}}        *)

Correct answer by Roman on April 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP