/- Copyright 2026 The Formal Conjectures Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -/ module public import FormalConjecturesUtil

Cohen–Lenstra Heuristics for Quadratic Class Groups

Henri Cohen and Hendrik W. Lenstra Jr. [CL84, Co93] formulated probabilistic heuristics for the odd part of the ideal class group $\operatorname{Cl}(\mathcal{O}_{\mathbb{Q}(\sqrt{d})})$ as $\mathbb{Q}(\sqrt{d})$ varies over imaginary ($d < 0$) or real ($d > 0$) quadratic fields ordered by absolute fundamental discriminant $|D(d)|$.

For an odd prime $p$ and a finite abelian $p$-group $G$, the heuristic at unit rank $u$ ($u = 0$ when $d < 0$, $u = 1$ when $d > 0$) predicts that the proportion of quadratic fields whose $p$-Sylow class-group subgroup is isomorphic to $G$ converges to $$w_{p, u}(G) = \frac{\prod_{k=1}^\infty \left(1 - p^{-(k + u)}\right)}{|G|^u \cdot |\operatorname{Aut}(G)|}.$$ The cited Wikipedia section mentions only that these heuristics exist and quotes their $\approx 75.45%$ class-number-$1$ prediction for prime-radicand real quadratic fields; the explicit odd $p$-part formulas formalized below come from [CL84] and [Co93, §5.10].

References:

    Wikipedia

    [CL84] H. Cohen and H. W. Lenstra Jr. (1984), Lecture Notes in Math. 1068, Springer, 33–62.

    [Co93] H. Cohen (1993), Grad. Texts in Math. 138, Springer, §5.10.

@[expose] public sectionnamespace CohenLenstraHeuristicsopen NumberFieldopen scoped NumberFieldopen scoped Classical in

Negative squarefree radicands $d < 0$ with $|D(d)| \le X$.

noncomputable def imagQuadRadicandsUpTo (X : ℕ) : Finset ℤ := (Finset.Icc (-(X : ℤ)) (-1)).filter (fun d => Squarefree d ∧ (quadFundDisc d).natAbs ≤ X)open scoped Classical in

Positive squarefree radicands $d \ge 2$ with $D(d) \le X$.

noncomputable def realQuadRadicandsUpTo (X : ℕ) : Finset ℤ := (Finset.Icc 2 (X : ℤ)).filter (fun d => Squarefree d ∧ (quadFundDisc d).natAbs ≤ X)

Predicate that $d \ne 1$ is squarefree and the $p$-Sylow subgroup of $\operatorname{Cl}(\mathcal{O}_{\mathbb{Q}(\sqrt{d})})$ is isomorphic to $G$.

def HasQuadPSylowIso (p : ℕ) (G : Type*) [CommGroup G] (d : ℤ) : Prop := ∃ (hsf : Squarefree d) (hne : d ≠ 1), letI : Fact (Squarefree d) := ⟨hsf⟩ letI : Fact (d ≠ 1) := ⟨hne⟩ ∃ P : Sylow p (ClassGroup (𝓞 (QuadraticAlgebra ℚ d 0))), Nonempty (P ≃* G)

Cohen–Lenstra $p$-Sylow probability weight $w_{p, u}(G) = \frac{\prod_{k=1}^\infty (1 - p^{-(k+u)})}{|G|^u \cdot |\operatorname{Aut}(G)|}$ at unit rank $u$ ($u = 0$ in the imaginary case, $u = 1$ in the real case).

noncomputable def cohenLenstraWeight (p u : ℕ) (G : Type*) [CommGroup G] [Finite G] : ℝ := (∏' k : ℕ, (1 - (p : ℝ) ^ (-((k + u + 1 : ℕ) : ℤ)))) / (((Nat.card G) ^ u * Nat.card (G ≃* G) : ℕ) : ℝ)open scoped Classical in

Cohen–Lenstra Heuristic (Imaginary Quadratic Case, $u = 0$) [CL84; Co93, §5.10]: given an odd prime $p$ and finite abelian $p$-group $G$, the fraction of imaginary quadratic discriminants $|D(d)| \le X$ whose $p$-Sylow class-group subgroup is isomorphic to $G$ tends to cohenLenstraWeight p 0 G. (Wikipedia notes only the existence of the heuristics and their $\approx 75.45%$ real-quadratic prediction; this odd-$p$-part formula comes from [CL84] and [Co93, §5.10].)

@[category research open, AMS 11] theorem cohen_lenstra_imaginary_quadratic_p_sylow_conjecture (p : ℕ) [Fact p.Prime] (hp : p ≠ 2) (G : Type*) [CommGroup G] [Fintype G] (hG : IsPGroup p G) : Filter.Tendsto (fun X : ℕ => (((imagQuadRadicandsUpTo X).filter (HasQuadPSylowIso p G)).card : ℝ) / ((imagQuadRadicandsUpTo X).card : ℝ)) Filter.atTop (nhds (cohenLenstraWeight p 0 G)) := p:ℕinst✝²:Fact (Nat.Prime p)hp:p ≠ 2G:Type u_1inst✝¹:CommGroup Ginst✝:Fintype GhG:IsPGroup p G⊢ Filter.Tendsto (fun X ↦ ↑(Finset.filter (HasQuadPSylowIso p G) (imagQuadRadicandsUpTo X)).card / ↑(imagQuadRadicandsUpTo X).card) Filter.atTop (nhds (cohenLenstraWeight p 0 G)) All goals completed! 🐙open scoped Classical in

Cohen–Lenstra Heuristic (Real Quadratic Case, $u = 1$) [CL84; Co93, §5.10]: given an odd prime $p$ and finite abelian $p$-group $G$, the fraction of real quadratic discriminants $0 < D(d) \le X$ whose $p$-Sylow class-group subgroup is isomorphic to $G$ tends to cohenLenstraWeight p 1 G. (Wikipedia notes only the existence of the heuristics and their $\approx 75.45%$ prediction; this odd-$p$-part formula comes from [CL84] and [Co93, §5.10].)

@[category research open, AMS 11] theorem cohen_lenstra_real_quadratic_p_sylow_conjecture (p : ℕ) [Fact p.Prime] (hp : p ≠ 2) (G : Type*) [CommGroup G] [Fintype G] (hG : IsPGroup p G) : Filter.Tendsto (fun X : ℕ => (((realQuadRadicandsUpTo X).filter (HasQuadPSylowIso p G)).card : ℝ) / ((realQuadRadicandsUpTo X).card : ℝ)) Filter.atTop (nhds (cohenLenstraWeight p 1 G)) := p:ℕinst✝²:Fact (Nat.Prime p)hp:p ≠ 2G:Type u_1inst✝¹:CommGroup Ginst✝:Fintype GhG:IsPGroup p G⊢ Filter.Tendsto (fun X ↦ ↑(Finset.filter (HasQuadPSylowIso p G) (realQuadRadicandsUpTo X)).card / ↑(realQuadRadicandsUpTo X).card) Filter.atTop (nhds (cohenLenstraWeight p 1 G)) All goals completed! 🐙

Degenerate radicands $d = 0$ and $d = 1$ never satisfy HasQuadPSylowIso.

@[category API, AMS 11] theorem not_hasQuadPSylowIso_zero_and_one (p : ℕ) (G : Type*) [CommGroup G] : ¬ HasQuadPSylowIso p G 0 ∧ ¬ HasQuadPSylowIso p G 1 := p:ℕG:Type u_1inst✝:CommGroup G⊢ ¬HasQuadPSylowIso p G 0 ∧ ¬HasQuadPSylowIso p G 1 p:ℕG:Type u_1inst✝:CommGroup G⊢ ¬HasQuadPSylowIso p G 0p:ℕG:Type u_1inst✝:CommGroup G⊢ ¬HasQuadPSylowIso p G 1 p:ℕG:Type u_1inst✝:CommGroup G⊢ ¬HasQuadPSylowIso p G 0 p:ℕG:Type u_1inst✝:CommGroup Ghsf:Squarefree 0w✝:0 ≠ 1h✝:∃ P, Nonempty (↥↑P ≃* G)⊢ False All goals completed! 🐙 p:ℕG:Type u_1inst✝:CommGroup G⊢ ¬HasQuadPSylowIso p G 1 p:ℕG:Type u_1inst✝:CommGroup Gw✝:Squarefree 1hne:1 ≠ 1h✝:∃ P, Nonempty (↥↑P ≃* G)⊢ False All goals completed! 🐙

Small-cutoff checks for quadFundDisc, imagQuadRadicandsUpTo, and realQuadRadicandsUpTo.

⊢ (2 ≤ 2 ∧ 2 ≤ ↑8) ∧ Squarefree 2 ∧ (quadFundDisc 2).natAbs ≤ 8 exact ⟨⟨⊢ 2 ≤ 2 All goals completed! 🐙, ⊢ 2 ≤ ↑8 All goals completed! 🐙⟩, Int.squarefree_natAbs.mp Nat.prime_two.squarefree, ⊢ (quadFundDisc 2).natAbs ≤ 8 All goals completed! 🐙⟩

At $p = 3$ and $u = 0$, the Euler product cohenLenstraWeight 3 0 Unit converges to a real in $[1/2, 2/3]$ (verifying genuine tprod convergence away from $0$ and $1$).

g:ℕ → ℝ := fun k ↦ 1 / 3 * (1 / 3) ^ khunit:cohenLenstraWeight 3 0 Unit = ∏' (k : ℕ), (1 - g k)h0:∀ (k : ℕ), 0 ≤ 1 - g khweier:∀ (s : Finset ℕ), 1 - ∑ k ∈ s, g k ≤ ∏ k ∈ s, (1 - g k)hbdd:BddBelow (Set.range fun s ↦ ∏ k ∈ s, (1 - g k))hanti:Antitone fun s ↦ ∏ k ∈ s, (1 - g k)s:Finset ℕhg_sum:HasSum (fun n ↦ (1 / 3) ^ n) (1 - 1 / 3)⁻¹hle:∑ i ∈ s, 1 / 3 * (1 / 3) ^ i ≤ 1 / 3 * (1 - 1 / 3)⁻¹⊢ 1 / 2 ≤ ∏ b ∈ s, (fun k ↦ 1 - g k) b linarith [show (1 / 3 : ℝ) * (1 - 1 / 3)⁻¹ = 1 / 2 ⊢ 1 / 2 ≤ cohenLenstraWeight 3 0 Unit ∧ cohenLenstraWeight 3 0 Unit ≤ 2 / 3 All goals completed! 🐙, hweier s]end CohenLenstraHeuristics