Skip to content

Lean formalization of the Riemann Hypothesis (Alpöge, 2026-11-20) being cleaned up by members of the Lean community.

Python
13.5 KB
Raw Blame
module

public import Aesop.BuiltinRules
import Mathlib.LinearAlgebra.Matrix.Module
import TauCeti.RingTheory.Valuation.FinsetDvd
public import Lib.Speed
import Lib.General.LinearAlgebra.HermiteForm

/-!
# Colength of modules, and endomorphisms surjective up to a bounded colength

A substitute for the colength of one module in another, and the bookkeeping of such colengths under
images, preimages, sums of submodules and products of endomorphisms.

* `New.ColengthDvd`: every finite family in `M` is carried into `N` by a square matrix whose
  determinant divides `z`; read it as "the colength of `N` in `M` divides `z`" or, over a valuation
  ring, "`N` has colength at most `v(z)` in `M`". `N ≤ M` is not required.
* `New.ColengthDvd.comap`, `New.ColengthDvd.map`, `New.ColengthDvd.trans`, `New.ColengthDvd.comp`:
  it passes along linear maps, and the bounds multiply along chains and compositions.
* `New.IsOntoUpToColength`, `New.IsOntoUpToColength.prod`: endomorphisms that keep `M` and are onto
  modulo `p ^ n` up to a colength dividing `p ^ l` with `l ≤ c`; the bounds `c` add under products.
* `New.ColengthDvd.of_det_dvd`: over a valuation domain the image of a square matrix `A` has
  colength dividing every multiple of `det A`, by the Smith normal form.
-/

@[expose] public section

namespace New

open Matrix Submodule Finset Pointwise Module

variable {O U V ι : Type*} [CommRing O] [AddCommGroup U] [Module O U] [AddCommGroup V] [Module O V]
  {M N P : Submodule O V} {M' N' : Submodule O U} {z z' a : O}

variable (M N z) in
/-- `New.ColengthDvd M N z`, for submodules `M`, `N` of `V` and `z : O`, is read as "the colength of
`N` in `M` divides `z`" (over a valuation ring: it is at most `v(z)`). It needs no bases and no
inclusion `N ≤ M`: for every finite family `Φ k` (`k : Fin n`) of vectors of `M` there is a square
matrix `m` indexed by `Fin n` with `det m ∣ z` such that all `∑ k, m i k • Φ k` lie in `N`. -/
def ColengthDvd : Prop :=
  ∀ (n : ℕ) (Φ : Fin n → V), (∀ k : Fin n, Φ k ∈ M) → ∃ m : Matrix (Fin n) (Fin n) O,
    det m ∣ z ∧ ∀ i : Fin n, ∑ k : Fin n, m i k • Φ k ∈ N

@[simp]
lemma ColengthDvd.of_le (hMN : M ≤ N) : ColengthDvd M N z := fun _ _ hΦ ↦
  ⟨1, by simp, fun i ↦ by simpa [Matrix.one_apply] using hMN (hΦ i)⟩

/-- Enlarging the target submodule preserves a colength divisibility bound. -/
lemma ColengthDvd.mono_right (hMN : ColengthDvd M N z) (hNP : N ≤ P) :
    ColengthDvd M P z := fun n Φ hΦ ↦
  (hMN n Φ hΦ).imp fun _ ⟨hm_det, hm_mem⟩ ↦ ⟨hm_det, fun i ↦ hNP (hm_mem i)⟩

lemma ColengthDvd.of_dvd (hMN : ColengthDvd M N z) (hz : z ∣ z') : ColengthDvd M N z' :=
  fun n Φ hΦ ↦ (hMN n Φ hΦ).imp fun _ ⟨h_det, h_mem⟩ ↦ ⟨h_det.trans hz, h_mem⟩

/-- Colength bounds multiply along chains. Let `M`, `N`, `P` be submodules of `V`, with no inclusion
assumed. If every finite family in `M` is carried into `N` by a square matrix whose determinant
divides `z` (this is `ColengthDvd M N z`), and likewise from `N` into `P` with `a`, then every
finite family in `M` is carried into `P` by a square matrix whose determinant divides `z * a`. -/
lemma ColengthDvd.trans (hMN : ColengthDvd M N z) (hNP : ColengthDvd N P a) :
    ColengthDvd M P (z * a) := by
  intro n Φ hΦ
  -- combine `Φ` by `m` into `N`, then combine the results by `m'` into `P`
  obtain ⟨m, hm_det, hm_mem⟩ := hMN n Φ hΦ
  obtain ⟨m', hm'_det, hm'_mem⟩ := hNP n (m • Φ) hm_mem
  refine ⟨m' * m, ?_, ?_⟩
  · simpa [mul_comm z] using mul_dvd_mul hm'_det hm_det
  · change ∀ i, ((m' * m) • Φ) i ∈ P
    rw [mul_smul]
    exact hm'_mem

/-- Colength bounds pull back along a linear map `f : U → V`. Let every finite family in `M` be
carried into `N` by a square matrix whose determinant divides `z` (this is `ColengthDvd M N z`). If
`M'`, `N'` are submodules of `U` such that `f (M') ⊆ M` and every `x ∈ M'` with `f x ∈ N` lies in
`N'`, then the same holds for `M'`, `N'` and `z`. -/
lemma ColengthDvd.comap (hMN : ColengthDvd M N z) (f : U →ₗ[O] V) (hM : M' ≤ M.comap f)
    (hN : ∀ x ∈ M', f x ∈ N → x ∈ N') : ColengthDvd M' N' z := by
  intro n Φ hΦ
  obtain ⟨m, hm_det, hm_mem⟩ := hMN n (f ∘ Φ) fun k ↦ hM (hΦ k)
  exact ⟨m, hm_det, fun i ↦ hN _ (sum_smul_mem M' _ fun k _ ↦ hΦ k) (by simpa using hm_mem i)⟩

/-- Colength bounds push forward along a linear map `f : V → U`. Let every finite family in `M` be
carried into `N` by a square matrix whose determinant divides `z` (this is `ColengthDvd M N z`). If
`M'`, `N'` are submodules of `U` such that `M' ⊆ f (M) + N'` and `f (N) ⊆ N'`, then the same holds
for `M'`, `N'` and `z`. -/
lemma ColengthDvd.map (hMN : ColengthDvd M N z) (f : V →ₗ[O] U) (hM' : M' ≤ M.map f ⊔ N')
    (hN : N.map f ≤ N') : ColengthDvd M' N' z := by
  intro n Φ hΦ
  -- Write `Φ k = f (x k) + y k` with `x k ∈ M` and `y k ∈ N'`.
  have h_split (k : Fin n) : ∃ x ∈ M, ∃ y ∈ N', f x + y = Φ k := by
    simpa using mem_sup.1 (hM' (hΦ k))
  choose x hx y hy hxy using h_split
  obtain ⟨m, hm_det, hm_mem⟩ := hMN n x hx
  refine ⟨m, hm_det, fun i ↦ ?_⟩
  -- The combination of the Φ k is f (∑ k, m i k • x k) plus a combination of the y k.
  simpa [← hxy, sum_add_distrib] using
    add_mem (hN (mem_map_of_mem (hm_mem i))) (sum_smul_mem N' (m i) fun k _ ↦ hy k)

/-- Let `M`, `N` be submodules of `V` and let the endomorphism `f` keep `M`. If every finite family
in `M` is carried into `f (M) + a • M` by a square matrix whose determinant divides `z`, and into
`N + a • M` by one whose determinant divides `z'` (these are instances of `ColengthDvd`), then it is
carried into `f (N) + a • M` by one whose determinant divides `z * z'`. -/
lemma ColengthDvd.comp {f : V →ₗ[O] V} (hf_keep : M.map f ≤ M)
    (hf_onto : ColengthDvd M (M.map f ⊔ a • M) z) (hMN : ColengthDvd M (N ⊔ a • M) z') :
    ColengthDvd M (N.map f ⊔ a • M) (z * z') := by
  -- Push `hMN` forward by `f` and chain it after `hf_onto`; `f (a • M) ≤ a • M` because `f` keeps
  -- `M`.
  refine hf_onto.trans (hMN.map f (by order) ?_)
  grw [Submodule.map_sup, map_pointwise_smul, hf_keep]

/-! ### Endomorphisms that are onto up to a bounded colength -/

/-- The endomorphism `y` of `V` keeps `M` and is onto on `M` modulo `p ^ n` up to a colength
dividing `p ^ l`, for some natural number `l ≤ c`: every finite family in `M` is carried into
`y (M) + p ^ n • M` by a square matrix whose determinant divides `p ^ l` (see `ColengthDvd`). -/
def IsOntoUpToColength (p : O) (M : Submodule O V) (n : ℕ) (y : End O V) (c : ℝ) : Prop :=
  M.map y ≤ M ∧ ∃ l : ℕ, l ≤ c ∧ ColengthDvd M (M.map y ⊔ p ^ n • M) (p ^ l)

/-- The bounds on exponents add under products. Here `IsOntoUpToColength z M s y c` says that the
endomorphism `y` keeps the submodule `M` and that, for some natural number `j ≤ c`, every finite
family in `M` is carried into `y (M) + z ^ s • M` by a square matrix whose determinant divides
`z ^ j`. If each `T l`, `l` in the list `L`, satisfies this with bound `t l`, then the product of
the `T l` satisfies it with bound the sum of the `t l`. -/
lemma IsOntoUpToColength.prod {s : ℕ} {T : ι → End O V} {t : ι → ℝ} (L : List ι)
    (hT : ∀ l ∈ L, IsOntoUpToColength z M s (T l) (t l)) :
    IsOntoUpToColength z M s (L.map T).prod (L.map t).sum := by
  induction L with
  | nil => simp [IsOntoUpToColength, End.one_eq_id]
  | cons a L ih =>
    -- The product `T a ∘ ∏ L` keeps `M`, and the bounds multiply by `ColengthDvd.comp`.
    obtain ⟨ha_map, i, hi, ha⟩ := hT a List.mem_cons_self
    obtain ⟨hL_map, j, hj, hL⟩ := ih fun l hl ↦ hT l (List.mem_cons_of_mem a hl)
    rw [IsOntoUpToColength, List.map_cons, List.prod_cons, End.mul_eq_comp, map_comp]
    refine ⟨by grw [hL_map, ha_map], i + j, by simpa using add_le_add hi hj, ?_⟩
    simpa [pow_add] using ColengthDvd.comp ha_map ha hL

/-! ### The image of a square matrix over a valuation domain -/

/-- Suppose divisibility in the commutative ring `O` is total. The vectors of a submodule `M` on
which a linear form `f` takes values divisible by `a` have colength dividing `a` in `M`: every
finite family in `M` is carried into them by a square matrix whose determinant divides `a`. -/
lemma colengthDvd_inf_comap_span [PreValuationRing O] (M : Submodule O V) (f : V →ₗ[O] O)
    (a : O) : ColengthDvd M (M ⊓ Submodule.comap f (Ideal.span {a})) a := by
  intro n Φ hΦ
  obtain rfl | hn := n.eq_zero_or_pos
  · exact ⟨1, by simp, finZeroElim⟩
  -- Take a member `Φ p` whose value divides the others, subtract multiples of it to clear them,
  -- and multiply it by `a`.
  classical
  have : Nonempty (Fin n) := ⟨⟨0, hn⟩⟩
  obtain ⟨p, hp⟩ := TauCeti.PreValuationRing.exists_forall_dvd (fun k ↦ f (Φ k))
  choose c hc using hp
  let m : Matrix (Fin n) (Fin n) O := updateCol 1 p fun i ↦ if i = p then a else -c i
  have h_det : m.det = a := by simp [m, ← cramer_apply, cramer_one]
  have h_comb (i : Fin n) : ∑ k, m i k • Φ k = if i = p then a • Φ p else Φ i - c i • Φ p := by
    obtain rfl | hip := eq_or_ne i p
    · rw [Fintype.sum_eq_single i] <;> simp +contextual [m, eq_comm]
    · rw [Fintype.sum_eq_add i p hip] <;>
        simp +contextual [m, hip, Ne.symm hip, sub_eq_add_neg, eq_comm]
  refine ⟨m, h_det.dvd, fun i ↦ ⟨sum_smul_mem M _ fun k _ ↦ hΦ k, ?_⟩⟩
  rw [h_comb]
  split_ifs <;> simp [Ideal.mem_span_singleton, hc i, mul_comm]

/-- The simultaneous divisibility conditions `d j ∣ f j x` on finitely many linear forms
have colength dividing the product of the moduli. -/
lemma colengthDvd_iInf_comap_span [IsDomain O] [ValuationRing O] (f : ι → V →ₗ[O] O) (d : ι → O)
    (s : Finset ι) : ColengthDvd ⊤ (⨅ j ∈ s, Submodule.comap (f j) (Ideal.span {d j}))
      (∏ j ∈ s, d j) := by
  classical
  induction s using Finset.induction with
  | empty => exact .of_le (by simp)
  | insert j s hj ih =>
    simpa only [Finset.iInf_insert, inf_comm, prod_insert hj, mul_comm] using
      ih.trans (colengthDvd_inf_comap_span _ (f j) (d j))

/-- Let `O` be a valuation domain and `A` a square matrix over `O` indexed by `ι` whose determinant
divides `z`. If the submodule `L` of `ι → O` contains the image of `A`, then `L` has colength
dividing `z` in the sense of `ColengthDvd`: every finite family in `ι → O` is carried into `L` by a
square matrix, of the size of the family, whose determinant divides `z`.

A consequence of the elementary divisor theorem (Smith normal form) over a valuation domain. -/
lemma ColengthDvd.of_det_dvd [IsDomain O] [ValuationRing O] [Fintype ι] [DecidableEq ι]
    {A : Matrix ι ι O} {L : Submodule O (ι → O)} (h_dvd : A.det ∣ z)
    (h_le : LinearMap.range A.mulVecLin ≤ L) : ColengthDvd (⊤ : Submodule O (ι → O)) L z := by
  -- Write `A = g · diag(d) · g'` with `g`, `g'` invertible. Let `S s` consist of the vectors `x`
  -- such that the `j`-th coordinate of `g⁻¹ x` is divisible by `d j` for all `j ∈ s`.
  obtain ⟨g, -, g', -, d, rfl⟩ := isValuationPair_top.smith_normal_form A
  let f (j : ι) : (ι → O) →ₗ[O] O := .proj j ∘ₗ g⁻¹.val.mulVecLin
  let S (s : Finset ι) : Submodule O (ι → O) := ⨅ j ∈ s, Submodule.comap (f j) (Ideal.span {d j})
  -- Each further coordinate costs `d j`.
  have h_chain (s : Finset ι) : ColengthDvd ⊤ (S s) (∏ j ∈ s, d j) :=
    colengthDvd_iInf_comap_span f d s
  -- The last module lies in the image of `A`.
  have h_image : S univ ≤ LinearMap.range (g.val * diagonal d * g'.val).mulVecLin := by
    intro x hx
    simp only [S, mem_iInf, mem_univ, forall_const] at hx
    choose w hw using fun j ↦ Ideal.mem_span_singleton.1 (hx j)
    have h_diag : diagonal d *ᵥ w = g⁻¹.val *ᵥ x :=
      funext fun j ↦ by simpa [f, mulVec_diagonal] using (hw j).symm
    exact ⟨g'⁻¹.val *ᵥ w, by simp [mul_assoc, h_diag]⟩
  have h_prod : ∏ j, d j ∣ z := .trans (by simp) h_dvd
  exact ((h_chain univ).of_dvd h_prod).mono_right (h_image.trans h_le)

/-- Over a valuation domain `O`, the submodule `a • O ^ ι` of `O ^ ι` has colength dividing
`a ^ #ι` in the sense of `ColengthDvd`: every finite family in `O ^ ι` is carried into `a • O ^ ι`
by a square matrix whose determinant divides `a ^ #ι`. -/
lemma colengthDvd_top_smul_top [IsDomain O] [ValuationRing O] [Fintype ι] [DecidableEq ι] (a : O) :
    ColengthDvd (⊤ : Submodule O (ι → O)) (a • ⊤) (a ^ Fintype.card ι) := by
  refine .of_det_dvd (A := a • (1 : Matrix ι ι O)) (by simp) ?_
  rintro _ ⟨v, rfl⟩
  simpa [smul_mulVec] using smul_mem_pointwise_smul v a ⊤ mem_top

/-- Over a valuation domain `O`, let `N` be a submodule of `V` and `s` a finite set of vectors. The
colength of `N + z • V` in `N + span s` divides `z ^ #s`, in the sense of `ColengthDvd`: every
finite family in `N + span s` is carried into `N + z • V` by a square matrix whose determinant
divides `z ^ #s`. -/
lemma colengthDvd_sup_span [IsDomain O] [ValuationRing O] (N : Submodule O V) (s : Finset V)
    (z : O) : ColengthDvd (N ⊔ span O (s : Set V)) (N ⊔ z • ⊤) (z ^ #s) := by
  -- Push the bound for `z • O ^ s` in `O ^ s` forward along the map to linear combinations of `s`.
  classical
  let comb : (s → O) →ₗ[O] V := Fintype.linearCombination O fun v : s ↦ (v : V)
  have h_range : Submodule.map comb ⊤ = span O s := by simp [comb, Fintype.range_linearCombination]
  have h_free : ColengthDvd (⊤ : Submodule O (s → O)) (z • ⊤) (z ^ #s) := by
    simpa using colengthDvd_top_smul_top (ι := s) z
  refine h_free.map comb (by order) ?_
  grw [map_pointwise_smul, le_top (a := Submodule.map comb ⊤), ← le_sup_right]

/-! ### Comparison with lengths -/

end New