mathlib documentation


Partitions #

A partition of a natural number n is a way of writing n as a sum of positive integers, where the order does not matter: two sums that differ only in the order of their summands are considered the same partition. This notion is closely related to that of a composition of n, but in a composition of n the order does matter. A summand of the partition is called a part.

Main functions #

Implementation details #

The main motivation for this structure and its API is to show Euler's partition theorem, and related results.

The representation of a partition as a multiset is very handy as multisets are very flexible and already have a well-developed API.

Tags #


References #

structure partition (n : ) :

A partition of n is a multiset of positive integers summing to n.

theorem partition.ext {n : } (x y : partition n) (h : = :
x = y
theorem partition.ext_iff {n : } (x y : partition n) :
x = y =

A composition induces a partition (just convert the list to a multiset).

def partition.of_sums (n : ) (l : multiset ) (hl : l.sum = n) :

Given a multiset which sums to n, construct a partition of n with the same multiset, but without the zeros.


A multiset induces a partition on its sum.


The partition of exactly one part.

theorem partition.count_of_sums_of_ne_zero {n : } {l : multiset } (hl : l.sum = n) {i : } (hi : i 0) :

The number of times a positive integer i appears in the partition of_sums n l hl is the same as the number of times it appears in the multiset l. (For i = 0, partition.non_zero combined with multiset.count_eq_zero_of_not_mem gives that this is 0 instead.)


Show there are finitely many partitions by considering the surjection from compositions to partitions.

def partition.odds (n : ) :

The finset of those partitions in which every part is odd.


The finset of those partitions in which each part is used at most once.


The finset of those partitions in which every part is odd and used at most once.