Form class number , the automorph count and the Pell unit
DefinitionClassNumberFormula_FormClassNumberThis file defines the quantities , and in Dirichlet's class number formula.
-
Binary quadratic forms. A form with is the polynomial ; its discriminant is . For the form is . Two forms are (properly) equivalent if one is obtained from the other by some .
-
Form class number. For an integer , is the number of equivalence classes of forms of discriminant ; when only positive definite forms () are counted.
-
Automorph count. For ,
- Pell unit. For , let , be the solution of with as small as possible, and put
These are the quantities on the left- and right-hand sides of Dirichlet's formula for , and its real-quadratic analogue.
Formalization Note is Nat.card of the quotient of the set of forms of discriminant (positive definite when ) by -equivalence; Lean's Nat.card would be if this set of classes were infinite, which does not happen for a non-square discriminant. is an sInf over the solution set and is the matching positive solution, so if no solution existed the values would be junk (); solvability is a separate milestone. For a fundamental discriminant every form of discriminant is primitive, so no primitivity condition is imposed.
import Mathlib
namespace ClassNumberFormula
/-- The integral binary quadratic form `a x² + b x y + c y²`. -/
@[ext] structure BinaryQuadForm where
a : ℤ
b : ℤ
c : ℤ
namespace BinaryQuadForm
/-- The discriminant `b² - 4ac`. -/
def disc (f : BinaryQuadForm) : ℤ := f.b ^ 2 - 4 * f.a * f.c
/-- The value `f(x, y) = a x² + b x y + c y²`. -/
def eval (f : BinaryQuadForm) (x y : ℤ) : ℤ := f.a * x ^ 2 + f.b * x * y + f.c * y ^ 2
/-- The form `(x, y) ↦ f(p x + q y, r x + s y)` obtained from `f` by the substitution
`γ = !![p, q; r, s] ∈ SL₂(ℤ)`. -/
def comp (f : BinaryQuadForm) (γ : Matrix.SpecialLinearGroup (Fin 2) ℤ) : BinaryQuadForm :=
let p := (γ : Matrix (Fin 2) (Fin 2) ℤ) 0 0
let q := (γ : Matrix (Fin 2) (Fin 2) ℤ) 0 1
let r := (γ : Matrix (Fin 2) (Fin 2) ℤ) 1 0
let s := (γ : Matrix (Fin 2) (Fin 2) ℤ) 1 1
⟨f.a * p ^ 2 + f.b * p * r + f.c * r ^ 2,
2 * f.a * p * q + f.b * (p * s + q * r) + 2 * f.c * r * s,
f.a * q ^ 2 + f.b * q * s + f.c * s ^ 2⟩
/-- Two forms are (properly) equivalent if one is carried to the other by a substitution
of determinant `1`. -/
def ProperlyEquivalent (f g : BinaryQuadForm) : Prop :=
∃ γ : Matrix.SpecialLinearGroup (Fin 2) ℤ, f.comp γ = g
end BinaryQuadForm
/-- The forms counted by `h(d)`: forms of discriminant `d`, positive definite (`a > 0`)
when `d < 0`. -/
def FormsOfDisc (d : ℤ) : Type :=
{f : BinaryQuadForm // f.disc = d ∧ (d < 0 → 0 < f.a)}
/-- `h(d)`: the number of proper equivalence classes of forms of discriminant `d`
(positive definite ones when `d < 0`). -/
noncomputable def formClassNumber (d : ℤ) : ℕ :=
Nat.card (Quot (fun f g : FormsOfDisc d => BinaryQuadForm.ProperlyEquivalent f.1 g.1))
/-- `w = w(d)` for `d < 0`: `2` if `d < -4`, `4` if `d = -4`, `6` if `d = -3`. -/
def formAutomorphCount (d : ℤ) : ℕ :=
if d = -4 then 4 else if d = -3 then 6 else 2
/-- `u > 0` smallest such that `t² - d u² = 4` for some `t > 0`. -/
noncomputable def pellU (d : ℤ) : ℕ :=
sInf {u : ℕ | 0 < u ∧ ∃ t : ℕ, 0 < t ∧ (t : ℤ) ^ 2 - d * (u : ℤ) ^ 2 = 4}
/-- The `t > 0` paired with `pellU d`. -/
noncomputable def pellT (d : ℤ) : ℕ :=
sInf {t : ℕ | 0 < t ∧ (t : ℤ) ^ 2 - d * (pellU d : ℤ) ^ 2 = 4}
/-- `ε = (t + u √d) / 2` for the solution of `t² - d u² = 4` with `t, u > 0` and `u` least. -/
noncomputable def pellEpsilon (d : ℤ) : ℝ :=
((pellT d : ℝ) + (pellU d : ℝ) * Real.sqrt d) / 2
end ClassNumberFormula
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.