Partition

Author

Eric W. Weisstein
April 24, 2002

This notebook downloaded from http://mathworld.wolfram.com/notebooks/Combinatorics/Partition.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/Partition.html.

©2005 Wolfram Research, Inc. except for portions noted otherwise

Initialization

<<DiscreteMath`Combinatorica`
<<DiscreteMath`IntegerPartitions`

PartitionsJ[p_]:=Reduce`NaturalLinearSolve[{Range[p]},{p},True][[1]]

Examples

Partitions[5]

Plus@@@%

Partitions[10]

Plus@@@%

Mathematica Routines

DiscreteMath`Combinatorica`Partitions

Table[Partitions[n],{n,5}]//ColumnForm

PartitionsJ

Table[PartitionsJ[n],{n,5}]//ColumnForm

DiscreteMath`IntegerPartitions

Table[IntegerPartitions[n],{n,5}]//ColumnForm

System`Private`IntegerPartitions

v4 only

Table[System`Private`IntegerPartitions[n],{n,5}]//ColumnForm

Table of Power Partitions

{#,PartitionsP[#]}&/@{10,50,100,150,200,250,300}//TableForm

Determining the Quickest Conversion of PartitionsJ

PartitionsJ[4]

ToPartitions[ll_]:=Function[l,Flatten[Table[#2,{#1}]&@@@Transpose[{l,Range[Length[ll[[1]]]]}]]]/@ll

ToPartitions[PartitionsJ[4]]

ToPartitions[PartitionsJ[25]];//Timing

ToPartitions[ll_,n_]:=Function[l,Flatten[Table[#2,{#1}]&@@@Transpose[{l,Range[n]}]]]/@ll

ToPartitions[PartitionsJ[30],30];//Timing

ToPartitions[ll_,n_]:=Flatten/@(Function[l,Table[#[[2]],{#[[1]]}]&/@DeleteCases[Transpose[{l,Range[n]}],{0,_}]]/@ll)

ToPartitions[PartitionsJ[30],30];//Timing

ToPartitions[PartitionsJ[3],3]

ToPartitions[ll_,n_]:=Function[l,Flatten[Table[#2,{#1}]&@@@DeleteCases[Transpose[{l,Range[n]}],{0,_}]]]/@ll

ToPartitions[PartitionsJ[30],30];//Timing

ToPartitions[ll_,n_]:=Flatten/@(Function[l,Table[#2,{#1}]&@@@DeleteCases[Transpose[{l,Range[n]}],{0,_}]]/@ll)

ToPartitions[PartitionsJ[30],30];//Timing

ToPartitions[ll_,n_]:=Flatten/@With[{i=Range[n]},(Function[l,Table[#2,{#1}]&@@@DeleteCases[Transpose[{l,i}],{0,_}]]/@ll)
]

ToPartitions[PartitionsJ[30],30];//Timing

ToPartitions[PartitionsJ[40],40];//Timing

Timing comparison

v4.2

$Version

{
a=Partitions[40];//Timing,
b=IntegerPartitions[40];//Timing
}

Length/@{a,b}

Table[Flatten/@Apply[Table[#1,{#2}]&,IntegerPartitions[n],{2}],{n,40}];//Timing

v5

{
a=Partitions[40];//Timing,
b=IntegerPartitions[40];//Timing,
c=PartitionsJ[40];//Timing
}

Length/@{a,b,c}