The areas / V30. Combinatorics
Mathlib.Combinatorics.Enumerative.Partition.Basic
49 declarations. Mathlib docs · Source
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
p : Partition nis a structure, made of a multiset of integers which are all positive and add up ton.
Implementation notes
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
Partition
References
theorem Nat.Partition.mk.congr_simp E1 #
∀ {n : ℕ} (parts parts_1 : Multiset ℕ) (e_parts : parts = parts_1) (parts_pos : ∀ {i : ℕ}, i ∈ parts → 0 < i)
(parts_sum : parts.sum = n),
{ parts := parts, parts_pos := parts_pos, parts_sum := parts_sum } =
{ parts := parts_1, parts_pos := ⋯, parts_sum := ⋯ }
theorem Nat.Partition.mk.injEq E0 #
∀ {n : ℕ} (parts : Multiset ℕ) (parts_pos : ∀ {i : ℕ}, i ∈ parts → 0 < i) (parts_sum : parts.sum = n)
(parts_1 : Multiset ℕ) (parts_pos_1 : ∀ {i : ℕ}, i ∈ parts_1 → 0 < i) (parts_sum_1 : parts_1.sum = n),
({ parts := parts, parts_pos := parts_pos, parts_sum := parts_sum } =
{ parts := parts_1, parts_pos := parts_pos_1, parts_sum := parts_sum_1 }) =
(parts = parts_1)
theorem Nat.Partition.ofSums.congr_simp E1 #
∀ (n : ℕ) (l l_1 : Multiset ℕ) (e_l : l = l_1) (hl : l.sum = n),
Nat.Partition.ofSums n l hl = Nat.Partition.ofSums n l_1 ⋯
def Nat.Partition.ctorIdx E1 #
{n : ℕ} → n.Partition → ℕ
theorem Nat.Partition.mk.inj E1 #
∀ {n : ℕ} {parts : Multiset ℕ} {parts_pos : ∀ {i : ℕ}, i ∈ parts → 0 < i} {parts_sum : parts.sum = n}
{parts_1 : Multiset ℕ} {parts_pos_1 : ∀ {i : ℕ}, i ∈ parts_1 → 0 < i} {parts_sum_1 : parts_1.sum = n},
{ parts := parts, parts_pos := parts_pos, parts_sum := parts_sum } =
{ parts := parts_1, parts_pos := parts_pos_1, parts_sum := parts_sum_1 } →
parts = parts_1
theorem Nat.Partition.ofSym.congr_simp E1 #
∀ {n : ℕ} {σ : Type u_1} (s s_1 : Sym σ n),
s = s_1 → ∀ {inst : DecidableEq σ} [inst_1 : DecidableEq σ], Nat.Partition.ofSym s = Nat.Partition.ofSym s_1
structure Nat.Partition E1 #
ℕ → Type
A partition of n is a multiset of positive integers summing to n.
theorem Nat.Partition.ext E1 #
∀ {n : ℕ} {x y : n.Partition}, x.parts = y.parts → x = y
theorem Nat.Partition.ext_iff E0 #
∀ {n : ℕ} {x y : n.Partition}, x = y ↔ x.parts = y.parts
ctor Nat.Partition.mk E0 #
{n : ℕ} → (parts : Multiset ℕ) → (∀ {i : ℕ}, i ∈ parts → 0 < i) → parts.sum = n → n.Partition
abbrev Nat.Partition.parts E1 #
{n : ℕ} → n.Partition → Multiset ℕ
positive integers summing to n
theorem Nat.Partition.parts_pos E1 #
∀ {n : ℕ} (self : n.Partition) {i : ℕ}, i ∈ self.parts → 0 < i
proof that the parts are positive
theorem Nat.Partition.parts_sum E1 #
∀ {n : ℕ} (self : n.Partition), self.parts.sum = n
proof that the parts sum to n
def Nat.instDecidableEqPartition.decEq E1 #
{n : ℕ} → (x x_1 : n.Partition) → Decidable (x = x_1)
instance Nat.instDecidableEqPartition E0 #
{n : ℕ} → DecidableEq n.Partition
theorem Nat.Partition.le_of_mem_parts E1 #
∀ {n : ℕ} {p : n.Partition} {m : ℕ}, m ∈ p.parts → m ≤ n
def Nat.Partition.ofComposition E1 #
(n : ℕ) → Composition n → n.Partition
A composition induces a partition (just convert the list to a multiset).
theorem Nat.Partition.ofComposition_parts E0 #
∀ (n : ℕ) (c : Composition n), (Nat.Partition.ofComposition n c).parts = ↑c.blocks
theorem Nat.Partition.ofComposition_surj E1 #
∀ {n : ℕ}, Function.Surjective (Nat.Partition.ofComposition n)
def Nat.Partition.ofSums E1 #
(n : ℕ) → (l : Multiset ℕ) → l.sum = n → n.Partition
Given a multiset which sums to n, construct a partition of n with the same multiset, but
without the zeros.
theorem Nat.Partition.ofSums_parts E0 #
∀ (n : ℕ) (l : Multiset ℕ) (hl : l.sum = n), (Nat.Partition.ofSums n l hl).parts = Multiset.filter (fun x ↦ x ≠ 0) l
def Nat.Partition.ofMultiset E1 #
(l : Multiset ℕ) → l.sum.Partition
A Multiset ℕ induces a partition on its sum.
theorem Nat.Partition.ofMultiset_parts E0 #
∀ (l : Multiset ℕ), (Nat.Partition.ofMultiset l).parts = Multiset.filter (fun x ↦ ¬x = 0) l
def Nat.Partition.ofSym E1 #
{n : ℕ} → {σ : Type u_1} → Sym σ n → [DecidableEq σ] → n.Partition
An element s of Sym σ n induces a partition given by its multiplicities.
theorem Nat.Partition.ofSym_map E0 #
∀ {n : ℕ} {σ : Type u_1} {τ : Type u_2} [inst : DecidableEq σ] [inst_1 : DecidableEq τ] (e : σ ≃ τ) (s : Sym σ n),
Nat.Partition.ofSym (Sym.map (⇑e) s) = Nat.Partition.ofSym s
def Nat.Partition.ofSymShapeEquiv E1 #
{n : ℕ} →
{σ : Type u_1} →
{τ : Type u_2} →
[inst : DecidableEq σ] →
[inst_1 : DecidableEq τ] →
(μ : n.Partition) → σ ≃ τ → { x // Nat.Partition.ofSym x = μ } ≃ { x // Nat.Partition.ofSym x = μ }
An equivalence between σ and τ induces an equivalence between the subtypes of Sym σ n and
Sym τ n corresponding to a given partition.
def Nat.Partition.toFinsuppAntidiag E1 #
{n : ℕ} → n.Partition → ℕ →₀ ℕ
Convert a Partition n to a member of (Finset.Icc 1 n).finsuppAntidiag n
(see Nat.Partition.toFinsuppAntidiag_mem_finsuppAntidiag for the proof).
p.toFinsuppAntidiag i is defined as i times the number of occurrence of i in p.
theorem Nat.Partition.toFinsuppAntidiag_injective E1 #
∀ (n : ℕ), Function.Injective Nat.Partition.toFinsuppAntidiag
theorem Nat.Partition.toFinsuppAntidiag_mem_finsuppAntidiag E1 #
∀ {n : ℕ} (p : n.Partition), p.toFinsuppAntidiag ∈ (Finset.Icc 1 n).finsuppAntidiag n
def Nat.Partition.indiscrete E1 #
(n : ℕ) → n.Partition
The partition of exactly one part.
instance Nat.Partition.instInhabited E0 #
{n : ℕ} → Inhabited n.Partition
theorem Nat.Partition.indiscrete_parts E0 #
∀ {n : ℕ}, n ≠ 0 → (Nat.Partition.indiscrete n).parts = {n}
theorem Nat.Partition.partition_zero_parts E0 #
∀ (p : Nat.Partition 0), p.parts = 0
instance Nat.Partition.UniquePartitionZero E0 #
Unique (Nat.Partition 0)
theorem Nat.Partition.partition_one_parts E0 #
∀ (p : Nat.Partition 1), p.parts = {1}
instance Nat.Partition.UniquePartitionOne E0 #
Unique (Nat.Partition 1)
theorem Nat.Partition.ofSym_one E0 #
∀ {σ : Type u_1} [inst : DecidableEq σ] (s : Sym σ 1), Nat.Partition.ofSym s = Nat.Partition.indiscrete 1
theorem Nat.Partition.count_ofSums_of_ne_zero E1 #
∀ {n : ℕ} {l : Multiset ℕ} (hl : l.sum = n) {i : ℕ},
i ≠ 0 → Multiset.count i (Nat.Partition.ofSums n l hl).parts = Multiset.count i l
The number of times a positive integer i appears in the partition ofSums 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_notMem gives that
this is 0 instead.)
theorem Nat.Partition.count_ofSums_zero E1 #
∀ {n : ℕ} {l : Multiset ℕ} (hl : l.sum = n), Multiset.count 0 (Nat.Partition.ofSums n l hl).parts = 0
instance Nat.Partition.instFintype E0 #
(n : ℕ) → Fintype n.Partition
Show there are finitely many partitions by considering the surjection from compositions to partitions.
def Nat.Partition.restricted E1 #
(n : ℕ) → (p : ℕ → Prop) → [DecidablePred p] → Finset n.Partition
The finset of those partitions in which every part satisfies a certain condition.
def Nat.Partition.countRestricted E1 #
(n : ℕ) → ℕ → Finset n.Partition
The finset of those partitions in which every part is used less than m times.
def Nat.Partition.odds E1 #
(n : ℕ) → Finset n.Partition
The finset of those partitions in which every part is odd.
def Nat.Partition.distincts E1 #
(n : ℕ) → Finset n.Partition
The finset of those partitions in which each part is used at most once.
theorem Nat.Partition.countRestricted_two E1 #
∀ (n : ℕ), Nat.Partition.countRestricted n 2 = Nat.Partition.distincts n
def Nat.Partition.oddDistincts E1 #
(n : ℕ) → Finset n.Partition
The finset of those partitions in which every part is odd and used at most once.
def Nat.Partition.partitionWithPartEquiv E1 #
{n a : ℕ} → 1 ≤ a → a ≤ n → { p // a ∈ p.parts } ≃ (n - a).Partition
If 1 ≤ a and a ≤ n, partitions of n containing a as a part are equivalent to
partitions of n - a. The forward map removes one occurrence of a, and the inverse adds a as
a part.
theorem Nat.Partition.partitionWithPartEquiv_apply_parts E0 #
∀ {n a : ℕ} (ha1 : 1 ≤ a) (ha : a ≤ n) (p : { p // a ∈ p.parts }),
((Nat.Partition.partitionWithPartEquiv ha1 ha) p).parts = (↑p).parts.erase a
theorem Nat.Partition.partitionWithPartEquiv_symm_apply_parts E0 #
∀ {n a : ℕ} (ha1 : 1 ≤ a) (ha : a ≤ n) (p : (n - a).Partition),
(↑((Nat.Partition.partitionWithPartEquiv ha1 ha).symm p)).parts = a ::ₘ p.parts