mathlib4 review helperopen PRs by @wwylele on leanprover-community/mathlib4

← queue

#33157 feat(Combinatorics): partitions and pentagonal numbers

blocked-by-other-PR merge-conflict t-combinatorics CI success

+207 −80 · 5 files · 8 commits · head 42b5151 · updated 83 days ago · Files changed on GitHub

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


![Open in Gitpod](gitpod.io/from-referrer/)

Conversation on GitHub 20
github-actions[bot] · comment · 2025-12-21
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 relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).
mathlib-merge-conflicts[bot] · comment · 2026-04-29

This pull request has conflicts, please merge master and resolve them.

mathlib-dependent-issues[bot] · comment · 2026-07-15

This PR/issue depends on:

  • ~~leanprover-community/mathlib4#33143~~
  • leanprover-community/mathlib4#43220

By Dependent Issues (🤖). Happy coding!

Copilot · on Mathlib/Combinatorics/Enumerative/Partition/Pentagonal.lean:54 (outdated) · 2026-07-16

Docstring has capitalization and spelling issues ("the" → "The", "coeffient" → "coefficient"), and the parenthetical sentence should end with punctuation.

Copilot · on Mathlib/Combinatorics/Enumerative/Partition/Pentagonal.lean:66 (outdated) · 2026-07-16

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 (∑).

Copilot · on Mathlib/Combinatorics/Enumerative/Partition/Basic.lean:235 (outdated) · 2026-07-16

Grammar: "there are odd number" should be "there are an odd number".

copilot-pull-request-reviewer[bot] · commented · 2026-07-16

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 / evenCountDistincts finsets 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 of pentagonalSeries, 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>.

Copilot · on Mathlib/Combinatorics/Enumerative/Partition/Basic.lean:239 (outdated) · 2026-07-16

Grammar: "there are even number" should be "there are an even number".

wwylele · comment · 2026-07-17

This is ready for review

CoolRmal · on Mathlib/Combinatorics/Enumerative/Partition/Pentagonal.lean:74 (outdated) · 2026-08-17
  convert hasProd_one_sub_X_pow R
  ext n
  simpa using card_evenCountDistincts_sub_card_oddCountDistincts R n
CoolRmal · on Mathlib/Combinatorics/Enumerative/Partition/Pentagonal.lean:22 (outdated) · 2026-08-17

Shouldn'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.)

CoolRmal · on Mathlib/Combinatorics/Enumerative/Partition/Pentagonal.lean:26 (outdated) · 2026-08-17
CoolRmal · on Mathlib/Combinatorics/Enumerative/Partition/Pentagonal.lean:29 (outdated) · 2026-08-17
  · simp [sub_eq_add_neg]
CoolRmal · on Mathlib/Combinatorics/Enumerative/Partition/Pentagonal.lean:27 (outdated) · 2026-08-17

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" />

CoolRmal · on Mathlib/Combinatorics/Enumerative/Partition/Pentagonal.lean:22 (outdated) · 2026-08-17

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.

CoolRmal · comment · 2026-08-17

awaiting-author

CoolRmal · commented · 2026-08-17

Some suggestions for the docstring.

wwylele · comment · 2026-08-19

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.

wwylele · comment · 2026-08-30

I have opened #43220 to refactor the generating function to remove T2Space

mathlib-merge-conflicts[bot] · comment · 2026-09-14

This pull request has conflicts, please merge master and resolve them.

Mathlib.lean +1 −0

public import Mathlib.Combinatorics.Enumerative.InclusionExclusion
3592public import Mathlib.Combinatorics.Enumerative.Partition.Basic
3593public import Mathlib.Combinatorics.Enumerative.Partition.GenFun
3594public import Mathlib.Combinatorics.Enumerative.Partition.Glaisher
3595public import Mathlib.Combinatorics.Enumerative.Partition.Pentagonal
3596public import Mathlib.Combinatorics.Enumerative.Pentagonal
3597public import Mathlib.Combinatorics.Enumerative.Pentagonal.Basic
3598public import Mathlib.Combinatorics.Enumerative.Pentagonal.PowerSeries

Mathlib/Combinatorics/Enumerative/Partition/Basic.lean +8 −0

theorem countRestricted_two (n : ℕ) : countRestricted n 2 = distincts n := by
230def oddDistincts (n : ℕ) : Finset n.Partition :=
231 odds n ∩ distincts n
def oddCountDistincts newL233–235
233/-- The finset of those partitions in which there are an odd number of distinct parts. -/
CoolRmal · 2026-08-17
/-- The finset of partitions into distinct parts with an odd number of parts. -/
234def oddCountDistincts (n : ℕ) : Finset n.Partition :=
235 (distincts n).filter fun x ↦ Odd x.parts.card
def evenCountDistincts changedL237–243
237/-- The finset of those partitions in which there are an even number of distinct parts. -/
CoolRmal · 2026-08-17
/-- The finset of partitions into distinct parts with an even number of parts. -/
238def evenCountDistincts (n : ℕ) : Finset n.Partition :=
239 (distincts n).filter fun x ↦ Even x.parts.card
241/-- If `1 ≤ a` and `a ≤ n`, partitions of `n` containing `a` as a part are equivalent to
242partitions of `n - a`. The forward map removes one occurrence of `a`, and the inverse adds `a` as
243a part. -/

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, \#i
19$$
20where $P_n$ is all partitions of $n$, $\#i$ is the count of $i$ in the partition $p$.
21We give the definition `Nat.Partition.genFun` using the first equation, and prove the second
−equation in `Nat.Partition.hasProd_genFun` (with shifted indices).
22equation in `Nat.Partition.hasProd_genFun` (with shifted indices). To avoid nested infinite
23expression, the factors in the second equation is defined as `Nat.Partition.genFunFactor`, and its
24equivalence to the infinite sum is shown at `Nat.Partition.hasSum_genFunFactor`.
26We also introduce `Nat.Partition.genFunDistincts` for the case where only partitions with
27distinct parts are considered. In this case, the generating function is
28$$
29G_f(X) = \sum_{n = 0}^{\infty} \left(\sum_{p \in P_n'} \prod_{i \in p} f(i)\right) X^n
30= \prod_{i = 1}^{\infty}\left(1 + f(i) X^{i}\right)
31$$
32where $P_n'$ is all partitions of $n$ with distinct parts. We give the definition using the first
33equation, and prove the second equation in `Nat.Partition.hasProd_genFunDistincts`
35This generating function can be specialized to
36* When $f(i, c) = 1$, this is the generating function for partition function $p(n)$
See the module docstring of `Combinatorics.Enumerative.Partition.GenFun` for mor
67noncomputable def genFun (f : ℕ → ℕ → R) : R⟦X⟧ :=
68 PowerSeries.mk fun n ↦ ∑ p : n.Partition, p.parts.toFinsupp.prod f
def genFunDistincts newL70–74
70/-- Generating function associated with character $f(i)$ for partitions with distinct parts. This is
71equivalent to `Nat.Partition.genFun` with a character $f(i, c)$ where only $f(i, 1)$ are non-zero
72and are equal to $f(i)$. (See `Nat.Partition.genFunDistincts_eq_genFun`) -/
73def genFunDistincts (f : ℕ → R) : R⟦X⟧ :=
74 PowerSeries.mk fun n ↦ ∑ p ∈ Nat.Partition.distincts n, (p.parts.map f).prod
lemma coeff_genFun changedL76–80
76@[simp]
77lemma coeff_genFun (f : ℕ → ℕ → R) (n : ℕ) :
78 (genFun f).coeff n = ∑ p : n.Partition, p.parts.toFinsupp.prod f :=
79 PowerSeries.coeff_mk _ _
−/-- The summands in the formula `Nat.Partition.hasProd_genFun` tends to infinity in their order. -/
81-- TODO: this was an intermediate lemma in this file but is no longer in use. Generalize this
82-- and move this to a better place.
83theorem tendsto_order_genFun_term_atTop_nhds_top (f : ℕ → ℕ → R) (i : ℕ) :
84 Filter.Tendsto (fun j ↦ (f (i + 1) (j + 1) • (X : R⟦X⟧) ^ ((i + 1) * (j + 1))).order)
85 Filter.atTop (nhds ⊤) := by
theorem tendsto_order_genFun_term_atTop_nhds_top (f : ℕ → ℕ → R) (i :
92 norm_cast
93 grind
−variable [TopologicalSpace R]
lemma coeff_genFunDistincts newL95–98
95@[simp]
96lemma coeff_genFunDistincts (f : ℕ → R) (n : ℕ) :
97 (genFunDistincts f).coeff n = ∑ p ∈ Nat.Partition.distincts n, (p.parts.map f).prod :=
98 PowerSeries.coeff_mk _ _
theorem summable_genFun_term removedLundefined–undefined
−/-- The infinite sum in the formula `Nat.Partition.hasProd_genFun` always converges. -/
−theorem summable_genFun_term (f : ℕ → ℕ → R) (i : ℕ) :
− Summable fun j ↦ f (i + 1) (j + 1) • (X : R⟦X⟧) ^ ((i + 1) * (j + 1)) := by
− apply WithPiTopology.summable_of_tendsto_order_atTop_nhds_top
− apply tendsto_order_genFun_term_atTop_nhds_top
theorem genFunDistincts_eq_genFun newL100–113
100theorem genFunDistincts_eq_genFun (f : ℕ → R) :
101 genFunDistincts f = genFun (fun i c ↦ Pi.single 1 (f i) c) := by
102 ext n
103 rw [coeff_genFunDistincts, coeff_genFun]
104 refine sum_of_injOn id (Set.injOn_id _) (by simp) (fun p _ hp ↦ ?_) (fun p hp ↦ ?_)
105 · obtain ⟨i, hi⟩ : ∃ i, 1 < p.parts.count i := by
106 simpa [distincts, Multiset.nodup_iff_count_le_one] using hp
107 have : i ∈ p.parts.toFinsupp.support := by
108 simpa [Multiset.mem_toFinset] using Multiset.one_le_count_iff_mem.mp hi.le
109 apply prod_eq_zero this
110 simp [hi.ne.symm]
111 · have hp : p.parts.Nodup := by simpa [distincts] using hp
112 simp +contextual [Finsupp.prod, prod_eq_multiset_prod, Multiset.dedup_eq_self.mpr hp,
113 Multiset.count_eq_one_of_mem hp]
theorem summable_genFun_term' removedLundefined–undefined
−/-- Alternative form of `summable_genFun_term` that unshifts the first index. -/
−theorem summable_genFun_term' (f : ℕ → ℕ → R) {i : ℕ} (hi : i ≠ 0) :
− Summable fun j ↦ f i (j + 1) • (X : R⟦X⟧) ^ (i * (j + 1)) := by
− obtain ⟨a, rfl⟩ := Nat.exists_eq_add_one_of_ne_zero hi
− apply summable_genFun_term
def genFunFactor newL115–118
115/-- Factor for part $i$ of the generating function associated with character $f(i, c)$ for partition
116functions. -/
117noncomputable def genFunFactor (f : ℕ → ℕ → R) (i : ℕ) : R⟦X⟧ :=
118 PowerSeries.mk fun n ↦ if n ≠ 0 ∧ i ∣ n then f i (n / i) else 0
−variable [T2Space R]
theorem constantCoeff_genFunFactor newL120–123
120@[simp]
121theorem constantCoeff_genFunFactor (f : ℕ → ℕ → R) (i : ℕ) :
122 (genFunFactor f i).constantCoeff = 0 := by
123 simp [genFunFactor]
theorem coeff_genFunFactor newL125–128
125@[simp]
126theorem coeff_genFunFactor (f : ℕ → ℕ → R) {i j : ℕ} (hi : i ≠ 0) (hj : j ≠ 0) :
127 (genFunFactor f i).coeff (j * i) = f i j := by
128 simp [genFunFactor, hi, hj]
theorem coeff_genFunFactor_self newL130–133
130@[simp]
131theorem coeff_genFunFactor_self (f : ℕ → ℕ → R) {i : ℕ} (hi : i ≠ 0) :
132 (genFunFactor f i).coeff i = f i 1 := by
133 simpa using coeff_genFunFactor f hi (one_ne_zero)
theorem dvd_of_coeff_genFunFactor_ne_zero newL135–137
135theorem dvd_of_coeff_genFunFactor_ne_zero {f : ℕ → ℕ → R} {i n : ℕ}
136 (h : (genFunFactor f i).coeff n ≠ 0) : i ∣ n := by
137 simp_all [genFunFactor]
theorem aux_dvd_of_coeff_ne_zero removedLundefined–undefined
−private theorem aux_dvd_of_coeff_ne_zero {f : ℕ → ℕ → R} {d : ℕ} {s : Finset ℕ} (hs0 : 0 ∉ s)
− {g : ℕ →₀ ℕ} (hg : g ∈ s.finsuppAntidiag d)
− (hprod : ∀ i ∈ s, (coeff (g i)) (1 + ∑' j, f i (j + 1) • X ^ (i * (j + 1))) ≠ (0 : R)) (x : ℕ) :
theorem aux_prod_f_eq_prod_coeff newL139–148
139private theorem aux_prod_f_eq_prod_coeff (f : ℕ → ℕ → R) {n : ℕ} (p : Partition n) {s : Finset ℕ}
140 (hs : Icc 1 n ⊆ s) :
141 p.parts.toFinsupp.prod f = ∏ i ∈ s, coeff (p.toFinsuppAntidiag i) (1 + genFunFactor f i) := by
142 simp_rw [Finsupp.prod, Multiset.toFinsupp_support, Multiset.toFinsupp_apply]
143 refine prod_subset_one_on_sdiff ?_ (fun i hi ↦ ?_) (fun i hi ↦ ?_)
144 · grind
145 · rw [mem_sdiff, Multiset.mem_toFinset] at hi
146 simp [toFinsuppAntidiag, hi.2]
147 · rw [Multiset.mem_toFinset] at hi
148 simp [toFinsuppAntidiag, (p.parts_pos hi).ne.symm, Multiset.count_ne_zero.mpr hi]
theorem aux_dvd_of_coeff_ne_zero changedL150–162
150private theorem aux_dvd_of_coeff_ne_zero {f : ℕ → ℕ → R} {d : ℕ} {s : Finset ℕ}
151 {g : ℕ →₀ ℕ} (hg : g ∈ s.finsuppAntidiag d) (hcoeff : ∀ i ∈ s, (coeff (g i))
152 (1 + genFunFactor f i) ≠ 0) (x : ℕ) :
153 x ∣ g x := by
154 by_cases hx : x ∈ s
− · specialize hprod x hx
− contrapose hprod
− have hx0 : x ≠ 0 := fun h ↦ hs0 (h ▸ hx)
− rw [map_add, (summable_genFun_term' f hx0).map_tsum _ (WithPiTopology.continuous_coeff _ _)]
− rw [show (0 : R) = 0 + ∑' (i : ℕ), 0 by simp]
− congrm (?_ + ∑' (i : ℕ), ?_)
− · suffices g x ≠ 0 by simp [this]
− contrapose hprod
− simp [hprod]
− · rw [map_smul, coeff_X_pow]
− apply smul_eq_zero_of_right
− suffices g x ≠ x * (i + 1) by simp [this]
− contrapose hprod
− simp [hprod]
155 · by_cases hgx : g x = 0
156 · simp [hgx]
157 specialize hcoeff x hx
158 simp only [map_add, coeff_one, hgx, ↓reduceIte, zero_add] at hcoeff
159 exact dvd_of_coeff_genFunFactor_ne_zero hcoeff
160 · suffices g x = 0 by simp [this]
161 contrapose! hx
162 exact mem_of_subset (mem_finsuppAntidiag.mp hg).2 <| by simpa using hx
theorem aux_prod_coeff_eq_zero_of_notMem_range changedL164–186
164private theorem aux_prod_coeff_eq_zero_of_notMem_range (f : ℕ → ℕ → R) {d : ℕ} {s : Finset ℕ}
165 (hs0 : 0 ∉ s) {g : ℕ →₀ ℕ} (hg : g ∈ s.finsuppAntidiag d)
166 (hg' : g ∉ Set.range (toFinsuppAntidiag (n := d))) :
− ∏ i ∈ s, (coeff (g i)) (1 + ∑' j, f i (j + 1) • X ^ (i * (j + 1)) : R⟦X⟧) = 0 := by
− suffices ∃ i ∈ s, (coeff (g i)) ((1 : R⟦X⟧) + ∑' j, f i (j + 1) • X ^ (i * (j + 1))) = 0 by
167 ∏ i ∈ s, (1 + genFunFactor f i).coeff (g i) = 0 := by
168 suffices ∃ i ∈ s, (1 + genFunFactor f i).coeff (g i) = 0 by
169 obtain ⟨i, hi, hi'⟩ := this
− apply prod_eq_zero hi hi'
170 exact prod_eq_zero hi hi'
171 contrapose! hg' with hprod
− rw [Set.mem_range]
172 have hgne0 (i : ℕ) : g i ≠ 0 ↔ i ≠ 0 ∧ i ≤ g i := by
173 refine ⟨fun h ↦ ⟨?_, ?_⟩, by grind⟩
174 · contrapose hs0 with rfl
175 exact mem_of_subset (mem_finsuppAntidiag.mp hg).2 (by simpa using h)
− · exact Nat.le_of_dvd (Nat.pos_of_ne_zero h) <| aux_dvd_of_coeff_ne_zero hs0 hg hprod _
176 · exact Nat.le_of_dvd (Nat.pos_of_ne_zero h) <| aux_dvd_of_coeff_ne_zero hg hprod _
177 refine ⟨Nat.Partition.mk (Finsupp.mk g.support (fun i ↦ g i / i) ?_).toMultiset ?_ ?_, ?_⟩
178 · simpa using hgne0
− · suffices ∀ i, g i ≠ 0 → i ≠ 0 by simpa [Nat.pos_iff_ne_zero]
− exact fun i h ↦ ((hgne0 i).mp h).1
− · obtain ⟨h1, h2⟩ := mem_finsuppAntidiag.mp hg
− refine Eq.trans ?_ h1
179 · suffices ∀ i, g i ≠ 0 → 0 < i by simpa
180 exact fun i h ↦ Nat.pos_iff_ne_zero.mpr ((hgne0 i).mp h).1
181 · obtain ⟨rfl, h⟩ := mem_finsuppAntidiag.mp hg
182 suffices ∑ x ∈ g.support, g x / x * x = ∑ x ∈ s, g x by simpa [Finsupp.sum]
− apply sum_subset_zero_on_sdiff h2 (by simp)
− exact fun x hx ↦ Nat.div_mul_cancel <| aux_dvd_of_coeff_ne_zero hs0 hg hprod x
183 apply sum_subset_zero_on_sdiff h (by simp)
184 exact fun x hx ↦ Nat.div_mul_cancel <| aux_dvd_of_coeff_ne_zero hg hprod x
185 · ext x
− simpa [toFinsuppAntidiag] using Nat.div_mul_cancel <| aux_dvd_of_coeff_ne_zero hs0 hg hprod x
186 simpa [toFinsuppAntidiag] using Nat.div_mul_cancel <| aux_dvd_of_coeff_ne_zero hg hprod x
theorem aux_prod_f_eq_prod_coeff removedLundefined–undefined
−private theorem aux_prod_f_eq_prod_coeff (f : ℕ → ℕ → R) {n : ℕ} (p : Partition n) {s : Finset ℕ}
− (hs : Icc 1 n ⊆ s) (hs0 : 0 ∉ s) :
− p.parts.toFinsupp.prod f =
− ∏ i ∈ s, coeff (p.toFinsuppAntidiag i) (1 + ∑' j, f i (j + 1) • X ^ (i * (j + 1))) := by
− simp_rw [Finsupp.prod, Multiset.toFinsupp_support, Multiset.toFinsupp_apply]
− apply prod_subset_one_on_sdiff
− · grind
− · intro x hx
− rw [mem_sdiff, Multiset.mem_toFinset] at hx
− have hx0 : x ≠ 0 := fun h ↦ hs0 (h ▸ hx.1)
− have hsum := (summable_genFun_term' f hx0).map_tsum _
− (WithPiTopology.continuous_constantCoeff R)
− simp [toFinsuppAntidiag, hsum, hx.2, hx0]
− · intro i hi
− rw [Multiset.mem_toFinset] at hi
− have hi0 : i ≠ 0 := (p.parts_pos hi).ne.symm
− rw [map_add, (summable_genFun_term' f hi0).map_tsum _ (WithPiTopology.continuous_coeff _ _)]
− suffices f i (Multiset.count i p.parts) =
− ∑' j, if Multiset.count i p.parts * i = i * (j + 1) then f i (j + 1) else 0 by
− simpa [toFinsuppAntidiag, hi, hi0, coeff_X_pow]
− rw [tsum_eq_single (Multiset.count i p.parts - 1) ?_]
− · rw [mul_comm]
− simp [Nat.sub_add_cancel (Multiset.one_le_count_iff_mem.mpr hi)]
− intro b hb
− suffices Multiset.count i p.parts * i ≠ i * (b + 1) by simp [this]
− rw [mul_comm i, (mul_left_inj' (Nat.ne_zero_of_lt (p.parts_pos hi))).ne]
− grind
188variable [TopologicalSpace R]
theorem hasSum_genFunFactor newL190–202
190theorem hasSum_genFunFactor (f : ℕ → ℕ → R) {i : ℕ} (hi : i ≠ 0) :
191 HasSum (fun j ↦ (f i (j + 1) • (X : R⟦X⟧) ^ (i * (j + 1)))) (genFunFactor f i) := by
192 have hinj : Function.Injective (fun j ↦ i * (j + 1)) :=
193 (mul_right_injective₀ hi).comp (add_left_injective 1)
194 convert! (hinj.hasSum_iff ?_).mpr (genFunFactor f i).hasSum_of_monomials_self with j
195 · simp [genFunFactor, hi, monomial_eq_C_mul_X_pow, smul_eq_C_mul]
196 intro n h
197 suffices ¬(n ≠ 0 ∧ i ∣ n) by simp [genFunFactor, this]
198 contrapose! h
199 obtain ⟨h0, k, rfl⟩ := h
200 have : k ≠ 0 := fun h ↦ by simp [h] at h0
201 obtain ⟨j, rfl⟩ := Nat.exists_eq_add_one_of_ne_zero this
202 simp
theorem hasProd_genFun changedL204–221
204theorem hasProd_genFun (f : ℕ → ℕ → R) :
− HasProd (fun i ↦ 1 + ∑' j, f (i + 1) (j + 1) • X ^ ((i + 1) * (j + 1))) (genFun f) := by
205 HasProd (fun i ↦ 1 + genFunFactor f (i + 1)) (genFun f) := by
206 rw [HasProd, WithPiTopology.tendsto_iff_coeff_tendsto]
207 refine fun d ↦ tendsto_atTop_of_eventually_const (fun s (hs : s ≥ range d) ↦ ?_)
− have : ∏ i ∈ s, ((1 : R⟦X⟧) + ∑' j, f (i + 1) (j + 1) • X ^ ((i + 1) * (j + 1)))
− = ∏ i ∈ s.map (addRightEmbedding 1), (1 + ∑' j, f i (j + 1) • X ^ (i * (j + 1))) := by simp
208 have : ∏ i ∈ s, (1 + genFunFactor f (i + 1)) =
209 ∏ i ∈ s.map (addRightEmbedding 1), (1 + genFunFactor f i) := by simp
210 rw [this]
211 have hs : Icc 1 d ⊆ s.map (addRightEmbedding 1) := by
212 intro i
213 suffices 1 ≤ i → i ≤ d → ∃ a ∈ s, a + 1 = i by simpa
214 intro h1 h2
215 refine ⟨i - 1, mem_of_subset hs ?_, ?_⟩ <;> grind
− rw [coeff_genFun, coeff_prod]
216 rw [coeff_prod, coeff_genFun]
217 refine (sum_of_injOn toFinsuppAntidiag (toFinsuppAntidiag_injective d).injOn ?_ ?_ ?_).symm
218 · intro p _
219 exact mem_of_subset (finsuppAntidiag_mono hs _) p.toFinsuppAntidiag_mem_finsuppAntidiag
220 · exact fun g hg hg' ↦ aux_prod_coeff_eq_zero_of_notMem_range f (by simp) hg (by simpa using hg')
− · exact fun p _ ↦ aux_prod_f_eq_prod_coeff f p hs (by simp)
221 · exact fun p _ ↦ aux_prod_f_eq_prod_coeff f p hs
theorem multipliable_genFun removedLundefined–undefined
−theorem multipliable_genFun (f : ℕ → ℕ → R) :
− Multipliable fun i ↦ (1 : R⟦X⟧) + ∑' j, f (i + 1) (j + 1) • X ^ ((i + 1) * (j + 1)) :=
theorem multipliable_one_add_genFunFactor changedL223–225
223theorem multipliable_one_add_genFunFactor (f : ℕ → ℕ → R) :
224 Multipliable fun i ↦ 1 + genFunFactor f (i + 1) :=
225 (hasProd_genFun f).multipliable
227@[deprecated (since := "2026-08-30")] alias multipliable_genFun := multipliable_one_add_genFunFactor
theorem hasProd_genFunDistincts newL229–240
229theorem hasProd_genFunDistincts (f : ℕ → R) :
230 HasProd (fun i ↦ 1 + f (i + 1) • X ^ (i + 1)) (genFunDistincts f) := by
231 rw [genFunDistincts_eq_genFun]
232 convert hasProd_genFun (fun i c ↦ Pi.single 1 (f i) c) with i
233 ext n
234 by_cases hn : n = i + 1
235 · simp [hn]
236 suffices n ≠ 0 → i + 1 ∣ n → n / (i + 1) = 1 → 0 = f (i + 1) by
237 simpa [hn, genFunFactor, Pi.single_apply]
238 intro h0 h1 h2
239 obtain ⟨j, rfl⟩ := h1
240 simp_all
242variable [T2Space R]
theorem hasProd_genFun' newL244–247
244theorem hasProd_genFun' (f : ℕ → ℕ → R) :
245 HasProd (fun i ↦ 1 + ∑' j, f (i + 1) (j + 1) • X ^ ((i + 1) * (j + 1))) (genFun f) := by
246 convert hasProd_genFun f with i
247 exact (hasSum_genFunFactor f (by simp)).tsum_eq
theorem genFun_eq_tprod changedL249–251
249theorem genFun_eq_tprod (f : ℕ → ℕ → R) :
− genFun f = ∏' i, (1 + ∑' j, f (i + 1) (j + 1) • X ^ ((i + 1) * (j + 1))) :=
250 genFun f = ∏' i, (1 + genFunFactor f (i + 1)) :=
251 (hasProd_genFun f).tprod_eq.symm
theorem genFunDistincts_eq_tprod newL253–255
253theorem genFunDistincts_eq_tprod (f : ℕ → R) :
254 genFunDistincts f = ∏' i, (1 + f (i + 1) • X ^ (i + 1)) :=
255 (hasProd_genFunDistincts f).tprod_eq.symm
257end Nat.Partition

Mathlib/Combinatorics/Enumerative/Partition/Glaisher.lean +2 −2

theorem hasProd_powerSeriesMk_card_restricted [IsTopologicalSemiring R]
theorem hasProd_powerSeriesMk_card_restricted body changedL50–56
50 (p : ℕ → Prop) [DecidablePred p] :
51 HasProd (fun i ↦ if p (i + 1) then ∑' j : ℕ, X ^ ((i + 1) * j) else 1)
52 (PowerSeries.mk fun n ↦ (#(restricted n p) : R)) := by
− convert! hasProd_genFun (fun i c ↦ if p i then (1 : R) else 0) using 1
53 convert! hasProd_genFun' (fun i c ↦ if p i then (1 : R) else 0) using 1
54 · ext1 i
55 split_ifs
56 · rw [tsum_eq_zero_add' ?_]
theorem hasProd_powerSeriesMk_card_countRestricted {m : ℕ} (hm : 0 < m) :
theorem hasProd_powerSeriesMk_card_countRestricted body changedL81–87
81 HasProd (fun i ↦ ∑ j ∈ range m, X ^ ((i + 1) * j))
82 (PowerSeries.mk fun n ↦ (#(countRestricted n m) : R)) := by
83 nontriviality R using Subsingleton.eq_one (α := R⟦X⟧)
− convert! hasProd_genFun (fun i c ↦ if c < m then (1 : R) else 0) using 1
84 convert! hasProd_genFun' (fun i c ↦ if c < m then (1 : R) else 0) using 1
85 · ext1 i
86 rw [sum_range_eq_add_Ico _ hm, sum_Ico_eq_sum_range]
87 congrm $(by simp) + ?_

Mathlib/Combinatorics/Enumerative/Partition/Pentagonal.lean +58 −0 new file

1/-
2Copyright (c) 2026 Weiyi Wang. All rights reserved.
3Released under Apache 2.0 license as described in the file LICENSE.
4Authors: Weiyi Wang
5-/
6module
7
8public import Mathlib.Combinatorics.Enumerative.Pentagonal.PowerSeries
9public import Mathlib.Combinatorics.Enumerative.Partition.GenFun
11/-!
12# Connection between pentagonal numbers and partitions
13-/
15variable (R : Type*) [CommRing R]
17namespace Nat.Partition
18open PowerSeries PowerSeries.WithPiTopology Finset
theorem hasProd_powerSeriesMk_card_evenCountDistincts_sub_card_oddCountDistincts newL20–35
20/-- The generating function for `#(evenCountDistincts n) - #(oddCountDistincts n)` is
21$\prod_{n=1}^{\infty} (1 - x^n)$. -/
22theorem hasProd_powerSeriesMk_card_evenCountDistincts_sub_card_oddCountDistincts
23 [TopologicalSpace R] :
24 HasProd (fun i ↦ 1 - X ^ (i + 1))
25 (PowerSeries.mk fun n ↦ (#(evenCountDistincts n) - #(oddCountDistincts n) : R)) := by
26 convert! hasProd_genFunDistincts (fun i ↦ (-1 : R)) using 1
27 · simp [sub_eq_add_neg]
28 ext n
29 simp_rw [coeff_mk, coeff_genFunDistincts, Multiset.map_const', Multiset.prod_replicate,
30 card_eq_sum_ones, cast_sum, cast_one, evenCountDistincts, oddCountDistincts, sum_filter,
31 ← sum_sub_distrib]
32 congr with p
33 rcases even_or_odd p.parts.card with heven | hodd
34 · simp [heven, not_odd_iff_even.mpr heven]
35 · simp [hodd, not_even_iff_odd.mpr hodd]
theorem card_evenCountDistincts_sub_card_oddCountDistincts newL37–49
37/-- The difference between `#(evenCountDistincts n)` and `#(oddCountDistincts n)` equals the `n`-th
38 coefficent of `pentagonalSeries R`, which is `(-1)^k` for the `k`-th pentagonal number, and `0`
CoolRmal · 2026-08-17
  coefficient of `pentagonalSeries R`, which is `(-1)^k` for the `k`-th pentagonal number, and `0`
39 for non-pentagonal numbers. (See also `PowerSeries.coeff_pentagonalSeries_eq_zero` and
40 `PowerSeries.coeff_pentagonalSeries_pentagonal`) -/
41public theorem card_evenCountDistincts_sub_card_oddCountDistincts (n : ℕ) :
42 (#(evenCountDistincts n) - #(oddCountDistincts n) : R) = (pentagonalSeries R).coeff n := by
43 let : TopologicalSpace R := ⊥
44 have : DiscreteTopology R := ⟨rfl⟩
45 have h := (hasProd_powerSeriesMk_card_evenCountDistincts_sub_card_oddCountDistincts R).unique
46 (hasProd_one_sub_X_pow R)
47 have hcoeff := congr(coeff n $h)
48 rw [coeff_mk] at hcoeff
49 exact hcoeff
CoolRmal · 2026-08-17
  simpa using congr(coeff n $h)
theorem card_evenCountDistincts_eq_card_oddCountDistincts_iff newL51–56
51/-- `#(evenCountDistincts n)` and `#(oddCountDistincts n)` are equal iff `n` is not a pentagonal
52number. -/
53public theorem card_evenCountDistincts_eq_card_oddCountDistincts_iff (n : ℕ) :
54 #(evenCountDistincts n) = #(oddCountDistincts n) ↔ n ∉ Set.range pentagonal := by
55 rw [← coeff_pentagonalSeries_eq_zero_iff ℤ, ← card_evenCountDistincts_sub_card_oddCountDistincts,
56 sub_eq_zero, cast_inj]
58end Nat.Partition
0/31 declarations checked

Your review, as Markdown

Paste it as a comment or a review on the PR. Line links to the head commit unfold into code snippets on GitHub.