|
| 1 | +/- |
| 2 | +Copyright (c) 2025 Weiyi Wang. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Weiyi Wang |
| 5 | +-/ |
| 6 | +module |
| 7 | + |
| 8 | +public import Mathlib.Combinatorics.Enumerative.Partition.GenFun |
| 9 | +public import Mathlib.RingTheory.PowerSeries.NoZeroDivisors |
| 10 | + |
| 11 | +/-! |
| 12 | +# Glaisher's theorem |
| 13 | +
|
| 14 | +This file proves Glaisher's theorem: the number of partitions of an integer $n$ into parts not |
| 15 | +divisible by $d$ is equal to the number of partitions in which no part is repeated $d$ or more |
| 16 | +times. |
| 17 | +
|
| 18 | +## Main declarations |
| 19 | +* `Nat.Partition.card_restricted_eq_card_countRestricted`: Glaisher's theorem. |
| 20 | +
|
| 21 | +## References |
| 22 | +https://en.wikipedia.org/wiki/Glaisher%27s_theorem |
| 23 | +-/ |
| 24 | + |
| 25 | +@[expose] public section |
| 26 | + |
| 27 | +variable (R) [TopologicalSpace R] [T2Space R] |
| 28 | + |
| 29 | +namespace Nat.Partition |
| 30 | +open PowerSeries PowerSeries.WithPiTopology Finset |
| 31 | + |
| 32 | +section Semiring |
| 33 | +variable [CommSemiring R] |
| 34 | + |
| 35 | +/-- The generating function of `Nat.Partition.restricted n p` is |
| 36 | +$$ |
| 37 | +\prod_{i \mem p} \sum_{j = 0}^{\infty} X^{ij} |
| 38 | +$$ -/ |
| 39 | +theorem hasProd_powerSeriesMk_card_restricted [IsTopologicalSemiring R] |
| 40 | + (p : ℕ → Prop) [DecidablePred p] : |
| 41 | + HasProd (fun i ↦ if p (i + 1) then ∑' j : ℕ, X ^ ((i + 1) * j) else 1) |
| 42 | + (PowerSeries.mk fun n ↦ (#(restricted n p) : R)) := by |
| 43 | + convert hasProd_genFun (fun i c ↦ if p i then (1 : R) else 0) using 1 |
| 44 | + · ext1 i |
| 45 | + split_ifs |
| 46 | + · rw [tsum_eq_zero_add' ?_] |
| 47 | + · simp |
| 48 | + simp_rw [pow_mul, pow_add] |
| 49 | + apply Summable.mul_right |
| 50 | + exact summable_pow_of_constantCoeff_eq_zero (by simp) |
| 51 | + · simp |
| 52 | + · simp_rw [genFun, restricted, card_filter, Finsupp.prod, prod_boole] |
| 53 | + simp |
| 54 | + |
| 55 | +theorem multipliable_powerSeriesMk_card_restricted [IsTopologicalSemiring R] |
| 56 | + (p : ℕ → Prop) [DecidablePred p] : |
| 57 | + Multipliable (fun i ↦ if p (i + 1) then ∑' j : ℕ, (X ^ ((i + 1) * j) : R⟦X⟧) else 1) := |
| 58 | + (hasProd_powerSeriesMk_card_restricted R p).multipliable |
| 59 | + |
| 60 | +theorem powerSeriesMk_card_restricted_eq_tprod [IsTopologicalSemiring R] |
| 61 | + (p : ℕ → Prop) [DecidablePred p] : |
| 62 | + PowerSeries.mk (fun n ↦ (#(restricted n p) : R)) = |
| 63 | + ∏' i, if p (i + 1) then ∑' j : ℕ, X ^ ((i + 1) * j) else 1 := |
| 64 | + (hasProd_powerSeriesMk_card_restricted R p).tprod_eq.symm |
| 65 | + |
| 66 | +/-- The generating function of `Nat.Partition.countRestricted n m` is |
| 67 | +$$ |
| 68 | +\prod_{i = 1}^{\infty} \sum_{j = 0}^{m - 1} X^{ij} |
| 69 | +$$ -/ |
| 70 | +theorem hasProd_powerSeriesMk_card_countRestricted {m : ℕ} (hm : 0 < m) : |
| 71 | + HasProd (fun i ↦ ∑ j ∈ range m, X ^ ((i + 1) * j)) |
| 72 | + (PowerSeries.mk fun n ↦ (#(countRestricted n m) : R)) := by |
| 73 | + nontriviality R using Subsingleton.eq_one |
| 74 | + convert hasProd_genFun (fun i c ↦ if c < m then (1 : R) else 0) using 1 |
| 75 | + · ext1 i |
| 76 | + rw [sum_range_eq_add_Ico _ hm, sum_Ico_eq_sum_range] |
| 77 | + congrm $(by simp) + ?_ |
| 78 | + trans ∑ k ∈ range (m - 1), (if k + 1 < m then (1 : R) else 0) • X ^ ((i + 1) * (k + 1)) |
| 79 | + · refine sum_congr rfl fun b hn ↦ ?_ |
| 80 | + rw [add_comm 1 b] |
| 81 | + have : b + 1 < m := by grind |
| 82 | + simp [this] |
| 83 | + · exact (tsum_eq_sum (fun b hb ↦ smul_eq_zero_of_left (by simpa using hb) _)).symm |
| 84 | + · simp_rw [genFun, countRestricted, card_filter, Finsupp.prod, prod_boole] |
| 85 | + simp |
| 86 | + |
| 87 | +theorem multipliable_powerSeriesMk_card_countRestricted (m : ℕ) : |
| 88 | + Multipliable fun i ↦ ∑ j ∈ range m, (X ^ ((i + 1) * j) : R⟦X⟧) := by |
| 89 | + rcases Nat.eq_zero_or_pos m with rfl | hm |
| 90 | + · simpa using multipliable_of_exists_eq_zero ⟨0, rfl⟩ |
| 91 | + · exact (hasProd_powerSeriesMk_card_countRestricted R hm).multipliable |
| 92 | + |
| 93 | +theorem powerSeriesMk_card_countRestricted_eq_tprod {m : ℕ} (hm : 0 < m) : |
| 94 | + PowerSeries.mk (fun n ↦ (#(countRestricted n m) : R)) = |
| 95 | + ∏' i, ∑ j ∈ range m, X ^ ((i + 1) * j) := |
| 96 | + (hasProd_powerSeriesMk_card_countRestricted R hm).tprod_eq.symm |
| 97 | + |
| 98 | +end Semiring |
| 99 | + |
| 100 | +section Ring |
| 101 | +variable [CommRing R] [NoZeroDivisors R] |
| 102 | + |
| 103 | +private theorem aux_mul_one_sub_X_pow [IsTopologicalRing R] {m : ℕ} (hm : 0 < m) : |
| 104 | + (∏' i, if ¬m ∣ i + 1 then ∑' j, (X : R⟦X⟧) ^ ((i + 1) * j) else 1) * ∏' i, (1 - X ^ (i + 1)) = |
| 105 | + ∏' i, (1 - X ^ ((i + 1) * m)) := by |
| 106 | + nontriviality R |
| 107 | + rw [← (multipliable_powerSeriesMk_card_restricted R (¬ m ∣ ·)).tprod_mul |
| 108 | + (multipliable_one_sub_X_pow _)] |
| 109 | + simp_rw [ite_not, ite_mul, pow_mul] |
| 110 | + conv in fun b ↦ _ => |
| 111 | + ext b |
| 112 | + rw [tsum_pow_mul_one_sub_of_constantCoeff_eq_zero (by simp)] |
| 113 | + refine tprod_eq_tprod_of_ne_one_bij (fun i ↦ (i.val + 1) * m - 1) ?_ ?_ ?_ |
| 114 | + · intro a b h |
| 115 | + rw [tsub_left_inj (by nlinarith) (by nlinarith), mul_left_inj' (hm.ne.symm), add_left_inj] at h |
| 116 | + exact SetCoe.ext h |
| 117 | + · suffices ∀ (i : ℕ), m ∣ i + 1 → ∃ j ≠ 0, j * m - 1 = i by simpa |
| 118 | + intro i hi |
| 119 | + obtain ⟨j, hj⟩ := dvd_def.mp hi |
| 120 | + refine ⟨j, by grind, Nat.sub_eq_of_eq_add ?_⟩ |
| 121 | + rw [hj, mul_comm m j] |
| 122 | + · intro i |
| 123 | + have : (i + 1) * m - 1 + 1 = (i + 1) * m := by grind |
| 124 | + simp [this, pow_mul] |
| 125 | + |
| 126 | +omit [TopologicalSpace R] in |
| 127 | +theorem powerSeriesMk_card_restricted_eq_powerSeriesMk_card_countRestricted {m : ℕ} (hm : 0 < m) : |
| 128 | + (PowerSeries.mk fun n ↦ (#(restricted n (¬ m ∣ ·)) : R)) = |
| 129 | + PowerSeries.mk fun n ↦ (#(countRestricted n m) : R) := by |
| 130 | + nontriviality R |
| 131 | + let _ : TopologicalSpace R := ⊥ |
| 132 | + have _ : DiscreteTopology R := ⟨rfl⟩ |
| 133 | + rw [powerSeriesMk_card_restricted_eq_tprod R (¬ m ∣ ·)] |
| 134 | + rw [powerSeriesMk_card_countRestricted_eq_tprod R hm] |
| 135 | + apply mul_right_cancel₀ (tprod_one_sub_X_pow_ne_zero R) |
| 136 | + rw [aux_mul_one_sub_X_pow R hm] |
| 137 | + rw [← (multipliable_powerSeriesMk_card_countRestricted R m).tprod_mul |
| 138 | + (multipliable_one_sub_X_pow _)] |
| 139 | + exact tprod_congr (fun i ↦ by simp_rw [pow_mul, geom_sum_mul_neg]) |
| 140 | + |
| 141 | +end Ring |
| 142 | + |
| 143 | +theorem card_restricted_eq_card_countRestricted (n : ℕ) {m : ℕ} (hm : 0 < m) : |
| 144 | + #(restricted n (¬ m ∣ ·)) = #(countRestricted n m) := by |
| 145 | + simpa using PowerSeries.ext_iff.mp |
| 146 | + (powerSeriesMk_card_restricted_eq_powerSeriesMk_card_countRestricted ℤ hm) n |
| 147 | + |
| 148 | +end Nat.Partition |
0 commit comments