Wolfram Research

Function Repository Resource:

SetPartitions

Source Notebook

Give all possible ways to partition a set into blocks, ignoring the order of blocks and order within blocks

Contributed by: Wolfram Staff

ResourceFunction["SetPartitions"][set]

returns the list of set partitions of set.

ResourceFunction["SetPartitions"][n]

returns the list of set partitions of {1,2,, n}.

Details and Options

A set partition of a set S is an unordered set of non-empty disjoint subsets of S (called blocks) whose union is S.
Both the order of the blocks and the order within each block are ignored.

Examples

Basic Examples

There are five set partitions of a three-element set:

In[1]:=
ResourceFunction["SetPartitions"][{a, b, c}]
Out[1]=
In[2]:=
Length@%
Out[2]=

The number of set partitions of a set with n elements is given by the nth Bell number:

In[3]:=
BellB[3]
Out[3]=

Scope

Here is a compact way to see the blocks:

In[4]:=
Map[Row, ResourceFunction["SetPartitions"][5], {2}]
Out[4]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Resource History

See Also

License Information