Skip to content

SetPartitions ​

The partitions of the set {1,…,n}\{1, …, n\} into non-empty blocks, a lazy indexed family.

✓ checked against that system · ! checked, with disagreements (hover a chip)WikipediaPartition of a setMathWorldSetPartitionWikidataQ381060Britannicatopic/partition-of-a-setOEISA000110✓A203646✓A203645✓Wolfram LanguageBellB✓SageMathSetPartitions(n)✓SymPymultiset_partitionsmathlib4Finpartition (Finset.univ : Finset (Fin n))Nat.bell
SetPartitions(n)every way to split {1,…,n}\{1, …, n\} into disjoint non-empty blocks.
CombinatoricaSetPartitions[If[ListQ[n], n, Range[n]]]
SetPartitions(n, k)the set partitions of {1,…,n}\{1, …, n\} into exactly kk blocks.
CombinatoricaKSetPartitions[Range[n], k]
SetPartitions(collection)the set partitions of any finite collection.
CombinatoricaSetPartitions[If[ListQ[collection], collection, Range[collection]]]
Typed signatures
TypePackageApplies
(collection<any> | integer, integer?) -> indexed_collection<set_partition> | list<list<list<any>> | set_partition>combinatoricsalways

Domain: Collections

Details
  • A lazy indexed collection; the count is the Bell number BnB_n — B4=15B_4 = 15. See BellNumber.
  • The partitions into exactly kk blocks number the Stirling numbers of the second kind S(n,k)S(n, k); summing over kk gives BnB_n. See Stirling.
  • Each element is the block list; the setset-partitionpartition glyph draws it from its restricted-growth string.

Definition

Epsil, as the implementation runs it.

count(_n)

_tables[_n * (_n + 1) + 0 + 1]

unrank(_n, _r)

Apply(
       (uend: list<integer>) => Map(Function(Filter(
                                                     Range(1, _n, 1),
                                                     Function(Drop(uend, 2)[p] ==
                                                              j, p),
                                                   ), j), Range(
                                                                0,
                                                                uend[2] - 1,
                                                                1,
                                                              )),
       Fold(
             Function(Apply((ur: integer) => Apply((uo: integer) => Apply(
                                                                           (ua: integer) => Join(
                                                                                                  [ur % ua, uo],
                                                                                                  Drop(us, 2),
                                                                                                  [(ur -
                                                                                                    ur % ua) /
                                                                                                   ua],
                                                                                                ) if ur <
                                                                                                    uo * ua else Join([ur -
                                                                                                                uo * ua, uo + 1], Drop(us, 2), [uo]),
                                                                           _tables[(_n - ui) *
                                                                                   (_n + 1) + uo + 1],
                                                                         ), us[2]), us[1]), us, ui),
             [_r, 0],
             Range(1, _n, 1),
           ),
     )

rank(_n, _x)

Apply(
       (rgs0: list<integer>) => Fold(
                                      Function(Apply((rr: integer) => Apply((ro: integer) => Apply(
                                                                                                    (ra: integer) => [rr +
                                                                                                                      rv * ra, ro, rs[3] + 1] if rv < ro else [rr +
                                                                                                                                                        ro * ra, ro + 1, rs[3] + 1],
                                                                                                    _tables[(_n - rs[3]) *
                                                                                                            (_n + 1) + ro + 1],
                                                                                                  ), rs[2]), rs[1]), rs, rv),
                                      [0, 0, 1],
                                      rgs0,
                                    )[1],
       Apply((mins: list<integer>) => Map(
                                           Function(Fold(Function(
                                                                   Count(Filter(
                                                                                 mins,
                                                                                 Function(z < mins[j], z),
                                                                               )) if Contains(_x[j], x) else lbl,
                                                                   lbl,
                                                                   j,
                                                                 ), 0, Range(
                                                                             1,
                                                                             Length(_x),
                                                                             1,
                                                                           )), x),
                                           Range(1, _n, 1),
                                         ), Map(Function(Min(blk), blk), _x)),
     )

valid(_n, _x)

Apply((flat: list<integer>) => Length(flat) == _n &&
                               Fold(Function(
                                              ok_blk && Length(blk) >= 1,
                                              ok_blk,
                                              blk,
                                            ), True, _x) && Fold(
                                                                 Function(ok_x &&
                                                                          Contains(flat, x), ok_x, x),
                                                                 True,
                                                                 Range(1, _n, 1),
                                                               ), Flatten(_x))

tables(_n)

Fold(
      Function(Join(b_t, Fold(
                               Function(ReplaceAt(
                                                   b_row,
                                                   b_c + 1,
                                                   b_c * b_t[(b_s - 1) *
                                                             (_n + 1) + b_c + 1] +
                                                   (b_t[(b_s - 1) * (_n + 1) +
                                                        b_c + 1 + 1] if b_c < _n else 0),
                                                 ), b_row, b_c),
                               Map(Function(0, b_z), Range(0, _n + 1 - 1, 1)),
                               Range(0, _n + 1 - 1, 1),
                             )), b_t, b_s),
      Fold(
            Function(ReplaceAt(b_row, b_c + 1, 1), b_row, b_c),
            Map(Function(0, b_z), Range(0, _n + 1 - 1, 1)),
            Range(0, _n + 1 - 1, 1),
          ),
      Range(1, _n + 1 - 1, 1),
    )

Statistics

On SetPartition, called as CombinatorialStat(x, "Name").

Maps

Into and out of SetPartition, called as CombinatorialMap(x, "Name"). Properties are the laws we state and what FindStat records.

From SetPartition

  • ArcRepresentationSetPartition → EndofunctionEach position linked to the next in its block, or to itself when last.
  • AssociatedStandardTableauSetPartition → StandardTableauSurjectionMp00258The standard tableau whose j-th column holds the j-th smallest elements of the blocks, in increasing order.
  • BlockSizeCompositionSetPartition → IntegerCompositionsurjectionSurjectionGraded mapMp00128The block sizes of a set partition, its blocks taken in order of their least elements.
  • BlockSizePartitionSetPartition → IntegerPartitionsurjectionSurjectionGraded mapMp00079The partition of n a set partition's block sizes form, largest first.
  • CallanSwitchSetPartition → SetPartitionBijectionGraded mapInvolutionMp00249Callan's involution: switches the first closer with the lesser of the least closer and the second element of the block of 1.
  • ComplementSetPartition → SetPartitioninvolutionBijectionGraded mapInvolutionMp00112Each element i replaced by n + 1 - i: the set partition seen from the other end.
  • DecreasingRotationSetPartition → SetPartitionbijectioninverseBijectionGraded mapMp00176Every element lowered by one, cyclically: 1 becomes the largest.
  • DualMajorIndexToIntertwiningSetPartition → SetPartitionbijectioninverseBijectionGraded mapMp00174The inverse of IntertwiningToDualMajorIndex: read the growth word as an intertwining word and rebuild the blocks.
  • IncreasingCyclePermutationSetPartition → PermutationInjectionGraded mapMp00080The permutation whose cycles are the blocks, each cycle increasing: every element goes to the next larger in its block, the largest to the least.
  • IncreasingRotationSetPartition → SetPartitionbijectioninverseBijectionGraded mapMp00091Every element raised by one, cyclically: the largest becomes 1.
  • IntertwiningToDualMajorIndexSetPartition → SetPartitionbijectioninverseBijectionGraded mapMp00171The set partition whose growth word is the intertwining word: a bijection taking the intertwining number to the dual major index.
  • InverseWachsWhiteSetPartition → SetPartitionbijectioninverseBijectionGraded mapMp00216The set partition joined by the arcs of the rook placement that Wachs and White's bijection gamma assigns to the set partition.
  • InverseWachsWhiteRhoSetPartition → SetPartitionbijectioninverseBijectionGraded mapMp00218The set partition joined by the arcs of the rook placement that Wachs and White's bijection rho assigns to the set partition.
  • InverseYipSetPartition → SetPartitionbijectioninverseBijectionGraded mapMp00219The set partition joined by the arcs of the rook placement that Yip's bijection psi assigns to the set partition.
  • KasraouiZengSetPartition → SetPartitionBijectionGraded mapInvolutionMp00115The Kasraoui-Zeng involution: exchanges the number of crossings with the number of nestings.
  • RestrictedGrowthStringSetPartition → RestrictedGrowthStringinverseA set partition's restricted growth string: each position labelled with its block's index, from 0.
  • WachsWhiteSetPartition → SetPartitionbijectioninverseBijectionGraded mapMp00215The set partition whose arcs, read as a rook placement, Wachs and White's bijection gamma carries to a set partition.
  • WachsWhiteRhoSetPartition → SetPartitionbijectioninverseBijectionGraded mapMp00217The set partition whose arcs, read as a rook placement, Wachs and White's bijection rho carries to a set partition.
  • YipSetPartition → SetPartitionbijectioninverseBijectionGraded mapMp00220The set partition whose arcs, read as a rook placement, Yip's bijection psi carries to a set partition.

To SetPartition

  • CyclePartitionPermutation → SetPartitionsurjectionSurjectionGraded mapMp00151The orbits, as a set partition of the positions.
  • NoncrossingPartitionDyckPath → SetPartitionInjectionGraded mapMp00138Biane's noncrossing set partition: the up steps whose matching downs lie in one run of downs form a block.
  • RowSetPartitionStandardTableau → SetPartitionInjectionGraded mapMp00284The set partition whose blocks are the rows of the tableau.
  • SetPartitionRestrictedGrowthString → SetPartitioninverseThe set partition a restricted growth string labels: block j holds the positions labelled j.
  • UnderlyingSetPartitionSetComposition → SetPartitionsurjectionSurjectionGraded mapMp00285The set partition with the same blocks, the order of the blocks forgotten.
  • WeakExceedancePartitionPermutation → SetPartitionSurjectionGraded mapMp00240The coarsest set partition containing every arc from i to π(i) with i ≤ π(i).
3 more in FindStat, not implemented here
  • Mp00092PerfectMatching → SetPartitionInjectionGraded mapto set partition
  • Mp00164SetPartition → SetPartitionBijectionGraded mapInvolutionChen Deng Du Stanley Yan
  • Mp00221SetPartition → SetPartitionBijectionGraded mapInvolutionconjugate

Enumeration

Examples

Basic #

The set partitions of an explicit list, in the family's own RGS order

live ↗
InSetPartitions([a,b,c])\mathrm{SetPartitions}(\bigl\lbrack a, b, c\bigr\rbrack)Out[[[a,b,c]],[[a,b],[c]],[[a,c],[b]],[[a],[b,c]],[[a],[b],[c]]]\bigl\lbrack\bigl\lbrack\bigl\lbrack a, b, c\bigr\rbrack\bigr\rbrack, \bigl\lbrack\bigl\lbrack a, b\bigr\rbrack, \bigl\lbrack c\bigr\rbrack\bigr\rbrack, \bigl\lbrack\bigl\lbrack a, c\bigr\rbrack, \bigl\lbrack b\bigr\rbrack\bigr\rbrack, \bigl\lbrack\bigl\lbrack a\bigr\rbrack, \bigl\lbrack b, c\bigr\rbrack\bigr\rbrack, \bigl\lbrack\bigl\lbrack a\bigr\rbrack, \bigl\lbrack b\bigr\rbrack, \bigl\lbrack c\bigr\rbrack\bigr\rbrack\bigr\rbrack

B4B_4

live ↗
InCount(SetPartitions(4))\mathrm{Count}(\mathrm{SetPartitions}(4))Out1515
Scope #

Exactly 2 blocks

live ↗
InSetPartitions(3,2)\mathrm{SetPartitions}(3, 2)Out[SetPartition⁡([[1,2],[3]]),SetPartition⁡([[1,3],[2]]),SetPartition⁡([[1],[2,3]])]\bigl\lbrack{\operatorname{SetPartition}}([[1, 2], [3]]), {\operatorname{SetPartition}}([[1, 3], [2]]), {\operatorname{SetPartition}}([[1], [2, 3]])\bigr\rbrack

The partitions of a 4-set into 2 blocks number S(4,2)=7S(4, 2) = 7

live ↗
InCount(SetPartitions(4,2))\mathrm{Count}(\mathrm{SetPartitions}(4, 2))Out77
Properties #

The family has B4=15B_4 = 15 members. See BellNumber

live ↗
InBellNumber(4)\mathrm{BellNumber}(4)Out1515

Those with exactly 2 blocks number S(4,2)=7S(4, 2) = 7. See Stirling

live ↗
InStirling(4,2)\mathrm{Stirling}(4, 2)Out77
Statistics #

set partitions of 5 by blocks: the Stirling numbers of the second kind

live ↗
InTally(CombinatorialStat(SetPartitions(5),Blocks))\mathrm{Tally}(\mathrm{CombinatorialStat}(\mathrm{SetPartitions}(5), \text{Blocks}))OutTuple⁡([1,2,3,4,5],[1,15,25,10,1])\operatorname{Tuple}(\bigl\lbrack1, 2, 3, 4, 5\bigr\rbrack,\bigl\lbrack1, 15, 25, 10, 1\bigr\rbrack)

by singleton blocks

live ↗
InTally(CombinatorialStat(SetPartitions(5),SingletonBlocks))\mathrm{Tally}(\mathrm{CombinatorialStat}(\mathrm{SetPartitions}(5), \text{SingletonBlocks}))OutTuple⁡([0,1,2,3,5],[11,20,10,10,1])\operatorname{Tuple}(\bigl\lbrack0, 1, 2, 3, 5\bigr\rbrack,\bigl\lbrack11, 20, 10, 10, 1\bigr\rbrack)

by crossings: the 14 non-crossing ones, a Catalan number, and one more

live ↗
InTally(CombinatorialStat(SetPartitions(4),Crossings))\mathrm{Tally}(\mathrm{CombinatorialStat}(\mathrm{SetPartitions}(4), \text{Crossings}))OutTuple⁡([0,1],[14,1])\operatorname{Tuple}(\bigl\lbrack0, 1\bigr\rbrack,\bigl\lbrack14, 1\bigr\rbrack)
About
Examples9
Checked againstCombinatorica 2 agree2 differWolfram Language 2 agreeSageMath 2 agreeSymPy 2 agreemathlib4 2 agreeOscar 1 agreeJulia 2 agreempmath 1 agree
CrosswalkWikipediaMathWorldWikidataBritannicaOEIS ×3Wolfram LanguageCombinatorica ×2SageMathSymPymathlib4 ×2

Implementation

mappedcombinatoricapackages/oracle/src/mappings.ts

Combinatorica lists set partitions in a different order than ours, so a listing may differ where the count agrees.

mappedcombinatoricapackages/oracle/src/mappings.ts

Combinatorica lists set partitions in a different order than ours, so a listing may differ where the count agrees.

See also: BellNumber, Stirling, Count, At, IntegerPartitions