Note
Go to the end to download the full example code.
Integer partitions, the partition function, and Young diagrams#
Enumerates every partition of 6, checks the count against the
partition function p(6), and visualizes one partition’s Young
diagram and its conjugate.
from mathematicskit.combinatorics import YoungDiagram, integer_partitions, partition_function
from mathematicskit.combinatorics.visualizers.plots import plot_partition_counts, plot_young_diagram
Enumerate the partitions of 6#
partitions = integer_partitions(6)
print(f"p(6) = {partition_function(6)}, enumerated {len(partitions)} partitions:")
for p in partitions:
print(" ", p)
p(6) = 11, enumerated 11 partitions:
[6]
[5, 1]
[4, 2]
[4, 1, 1]
[3, 3]
[3, 2, 1]
[3, 1, 1, 1]
[2, 2, 2]
[2, 2, 1, 1]
[2, 1, 1, 1, 1]
[1, 1, 1, 1, 1, 1]
A Young diagram and its conjugate#
diagram = YoungDiagram([4, 2, 1])
print("\nFerrers diagram of (4, 2, 1):")
print(diagram.ferrers_diagram())
print("conjugate partition:", diagram.conjugate().parts)
plot_young_diagram(diagram)
![Young diagram of [4, 2, 1]](../../../../_images/sphx_glr_plot_01_partitions_and_young_diagrams_001.png)
Ferrers diagram of (4, 2, 1):
****
**
*
conjugate partition: [3, 2, 1, 1]
<Axes: title={'center': 'Young diagram of [4, 2, 1]'}>
Growth of the partition function#
plot_partition_counts(30)

<Axes: title={'center': 'Integer partition function'}, xlabel='n', ylabel='p(n)'>
Total running time of the script: (0 minutes 0.042 seconds)