Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
List the subsets of a set in lexicographic order
ResourceFunction["LexicographicSubsets"][l] gives all subsets of set l in lexicographic order. | |
ResourceFunction["LexicographicSubsets"][n] gives all subsets of {1,2,…,n} in lexicographic order. |
The subsets of {a,b,c} in lexicographic order:
| In[1]:= |
| Out[1]= |
All subsets of {1,2,3} in lexicographic order:
| In[2]:= |
| Out[2]= |
In canonical order, shorter subsets go first:
| In[3]:= |
| Out[3]= |
Generate subsets in lexicographic order sequentially using the resource function NextLexicographicSubset:
| In[4]:= |
| Out[4]= |
Or together using LexicographicSubsets:
| In[5]:= |
| Out[5]= |
| In[6]:= |
| Out[6]= |
This work is licensed under a Creative Commons Attribution 4.0 International License