/-- The finset of partitions into distinct parts with an odd number of parts. -/#33157 feat(Combinatorics): partitions and pentagonal numbers
In plain words
Adds the generating function genFunDistincts f for partitions into distinct parts, with the product formula , as a special case of Nat.Partition.genFun. Taking and comparing with Euler's pentagonal number theorem (hasProd_one_sub_X_pow, already in mathlib) gives the classical combinatorial corollary: the number of partitions of into an even number of distinct parts minus those into an odd number is the coefficient of the pentagonal series, so the two counts agree iff is not a generalised pentagonal number. The genFunFactor refactor comes from #43220, but this PR sits on an older version of it (no @[simps] on toFinsuppAntidiag, and summable_genFun_term/summable_genFun_term' deleted rather than kept); it should be rebased.
Transcriptions are drafted with an LLM from the diff and are a reading aid, not a verified statement: the Lean code is the reference.
PR description
We prove a corollary of pentagonal number theorem: the number of partitions with odd number of distinct parts and the number of partitions with even number of distinct parts are either equal (n is not pentagonal), or (-1)^k for the k-th pentagonal number
Conversation on GitHub 20
PR summary 42b515122f
Import changes for modified files
No significant changes to the import graph
<details><summary>Import changes for all files</summary>
|Files|Import difference|
|-|-|
| Mathlib.Combinatorics.Enumerative.Partition.Pentagonal (new file)|1502|
</details>
<details><summary>
Declarations diff (regex)
</summary>
+ card_evenCountDistincts_eq_card_oddCountDistincts_iff
+ card_evenCountDistincts_sub_card_oddCountDistincts
+ coeff_genFunDistincts
+ coeff_genFunFactor
+ coeff_genFunFactor_self
+ constantCoeff_genFunFactor
+ dvd_of_coeff_genFunFactor_ne_zero
+ evenCountDistincts
+ genFunDistincts
+ genFunDistincts_eq_genFun
+ genFunDistincts_eq_tprod
+ genFunFactor
+ hasProd_genFun'
+ hasProd_genFunDistincts
+ hasProd_powerSeriesMk_card_evenCountDistincts_sub_card_oddCountDistincts
+ hasSum_genFunFactor
+ multipliable_one_add_genFunFactor
+ oddCountDistincts
- summable_genFun_term
- summable_genFun_term'
<details>
<summary>You can run this locally as follows</summary>
## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>
## more verbose report:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh long <optional_commit>
</details>
The doc-module for scripts/pr_summary/declarations_diff.sh in the undefined repository contains some details about this script.
</details>
<details><summary>
Declarations diff (Lean)
</summary>
✅ Lean-aware diff — post-build, computed from the Lean environment (commit
42b5151).
- +17 new declarations
- −2 removed declarations
+Nat.Partition.card_evenCountDistincts_eq_card_oddCountDistincts_iff
+Nat.Partition.card_evenCountDistincts_sub_card_oddCountDistincts
+Nat.Partition.coeff_genFunDistincts
+Nat.Partition.coeff_genFunFactor
+Nat.Partition.coeff_genFunFactor_self
+Nat.Partition.constantCoeff_genFunFactor
+Nat.Partition.dvd_of_coeff_genFunFactor_ne_zero
+Nat.Partition.evenCountDistincts
+Nat.Partition.genFunDistincts
+Nat.Partition.genFunDistincts_eq_genFun
+Nat.Partition.genFunDistincts_eq_tprod
+Nat.Partition.genFunFactor
+Nat.Partition.hasProd_genFun'
+Nat.Partition.hasProd_genFunDistincts
+Nat.Partition.hasSum_genFunFactor
+Nat.Partition.multipliable_one_add_genFunFactor
+Nat.Partition.oddCountDistincts
-Nat.Partition.summable_genFun_term
-Nat.Partition.summable_genFun_term'
</details>
No changes to strong technical debt.
No changes to weak technical debt.
Current commit 42b515122f Reference commit 4ac22c7efc
This script lives in the undefined repository. To run it locally, from your mathlib4 directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
../mathlib-ci/scripts/reporting/technical-debt-metrics.sh pr_summary
- The
relativevalue is the weighted sum of the differences with weight given by the inverse of the current value of the statistic. - The
absolutevalue is therelativevalue divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).
This pull request has conflicts, please merge master and resolve them.
This PR/issue depends on:
- ~~leanprover-community/mathlib4#33143~~
- leanprover-community/mathlib4#43220
By Dependent Issues (🤖). Happy coding!
Docstring has capitalization and spelling issues ("the" → "The", "coeffient" → "coefficient"), and the parenthetical sentence should end with punctuation.
This docstring states the generating function as a sum, but the theorem proves a HasProd statement (an infinite product). The displayed formula should use a product (∏), not a sum (∑).
Grammar: "there are odd number" should be "there are an odd number".
Pull request overview
This PR adds a new combinatorics bridge between partitions into distinct parts and the pentagonal-number power series, leveraging the pentagonal number theorem infrastructure introduced in #33143.
Changes:
- Introduces
oddCountDistincts/evenCountDistinctsfinsets for partitions into distinct parts, filtered by parity of the number of parts. - Adds a new file proving that
#(evenCountDistincts n) - #(oddCountDistincts n)matches coefficients ofpentagonalSeries, and derives the “equal iff non-pentagonal” corollary. - Registers the new module in
Mathlib.lean.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
| ---- | ----------- |
| Mathlib/Combinatorics/Enumerative/Partition/Pentagonal.lean | New results connecting parity-counted distinct-part partitions to pentagonalSeries coefficients and a HasProd generating function statement. |
| Mathlib/Combinatorics/Enumerative/Partition/Basic.lean | Adds finsets selecting distinct-part partitions by odd/even number of parts. |
| Mathlib.lean | Exposes the new Partition.Pentagonal module via a public import. |
💡 <a href="/leanprover-community/mathlib4/new/master?filename=.github/instructions/*.instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add Copilot custom instructions</a> for smarter, more guided reviews. <a href="docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn how to get started</a>.
Grammar: "there are even number" should be "there are an even number".
This is ready for review
convert hasProd_one_sub_X_pow R
ext n
simpa using card_evenCountDistincts_sub_card_oddCountDistincts R nShouldn't this be private theorem? (and also I found a bit weird to make the other theorems below public as I rarely see that, but I think you probably know much more about this than I do.)
· simp [sub_eq_add_neg]Why don't we prove a slightly more general theorem by replacing -1 : R with an arbitrary z : R? Or even a weight w : ℕ → R?
<img width="451" height="105" alt="Image" src="github.com/user-attachments/assets/ea932c8d-b29d-4ef4-8878-f263c74cc6d6" />
and then prove the following formulae:
<img width="609" height="183" alt="Image" src="github.com/user-attachments/assets/41d4e040-559c-4ebe-acf8-b521e2c88104" />
After some thoughts I think you can avoid this issue by reconsidering theorems in Mathlib/Combinatorics/Enumerative/Partition/GenFun.lean. In particular, my AI confirms that you can prove the following theorem:
theorem Nat.Partition.hasProd_one_add_powerSeriesMk_genFun {R : Type*} [CommSemiring R]
[TopologicalSpace R] (f : ℕ → ℕ → R) :
HasProd (fun i ↦ 1 + PowerSeries.mk fun n ↦
if 0 < n ∧ i + 1 ∣ n then f (i + 1) (n / (i + 1)) else 0) (genFun f) := by
sorry
You can then use this theorem instead of hasProd_genFun. This allows you to drop the [T2Space R] assumption and thus there is no need to create a pair of public and private theorems.
And another completely optional task that you can do: only [T1Space R] is needed in hasProd_genFun.
awaiting-author
Some suggestions for the docstring.
Thanks for the review. It has been awhile since I started the code about the generating function for partitions, and I have since thought more about it. I particularly like the comment about use PowerSeries.mk fun n ↦ if 0 < n ∧ i + 1 ∣ n then f (i + 1) (n / (i + 1)) else 0), because that was one of the alternative statement I had in mind, but I dropped for aesthetic reason. Looking back, I started liking it again because it can help with dropping a bunch of usage of [T2Space R]
I am going to work on refactoring the existing GenFun.lean file and make it a dependency of this one. It can take a while.
I have opened #43220 to refactor the generating function to remove T2Space
This pull request has conflicts, please merge master and resolve them.
Mathlib.lean +1 −0
public import Mathlib.Combinatorics.Enumerative.InclusionExclusionMathlib/Combinatorics/Enumerative/Partition/Basic.lean +8 −0
theorem countRestricted_two (n : ℕ) : countRestricted n 2 = distincts n := by/-- The finset of partitions into distinct parts with an even number of parts. -/Mathlib/Combinatorics/Enumerative/Partition/GenFun.lean +138 −78
G_f(X) = \sum_{n = 0}^{\infty} \left(\sum_{p \in P_{n}} \prod_{i \in p} f(i, \#iSee the module docstring of `Combinatorics.Enumerative.Partition.GenFun` for mortheorem tendsto_order_genFun_term_atTop_nhds_top (f : ℕ → ℕ → R) (i :Mathlib/Combinatorics/Enumerative/Partition/Glaisher.lean +2 −2
theorem hasProd_powerSeriesMk_card_restricted [IsTopologicalSemiring R]theorem hasProd_powerSeriesMk_card_countRestricted {m : ℕ} (hm : 0 < m) :Mathlib/Combinatorics/Enumerative/Partition/Pentagonal.lean +58 −0 new file
coefficient of `pentagonalSeries R`, which is `(-1)^k` for the `k`-th pentagonal number, and `0` simpa using congr(coeff n $h)