Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Give all possible ways to partition a set into a given number of subsets, ignoring order of blocks and within blocks
ResourceFunction["KSetPartitions"][set,k] returns the list of set partitions of set with k blocks. | |
ResourceFunction["KSetPartitions"][n,k] returns the list of set partitions of {1,2,…, n} with k blocks. |
There are 15 set partitions of a five-element set into two subsets:
In[1]:= |
Out[1]= |
The number of such set partitions is given by a Stirling number of the second kind:
In[2]:= |
Out[2]= |
In[3]:= |
Out[3]= |
Here is a compact way to see the blocks:
In[4]:= |
Out[4]= |
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License