module import TauCeti.RingTheory.DiscreteValuationRing.BlockSolutions public import Mathlib.RingTheory.RegularLocalRing.Defs import Mathlib.RingTheory.Coalgebra.IsFrobenius import Mathlib.RingTheory.Etale.Weakly import Mathlib.RingTheory.HopfAlgebra.Basic import Mathlib.RingTheory.TotallySplit public import Lib.General.Algebra.FittingIdealsAndLengths /-! # A matrix of relations with small block determinant valuation Linear algebra over a discrete valuation ring O (written `DVR O`) with normalized valuation v = `addVal O` and fraction field K. The valuation of a determinant of relations is bounded by the length of a module of solutions in K/O. * `New.Selmer.divQuot`: the map x ↦ x/p from O/p to K/O (`New.Selmer.DivisibleQuot`). For p ≠ 0 it is injective with image the p-torsion. * `New.Selmer.exists_rows_addVal_det_le_of_divisible`: let ψ : A → M_d(O) be onto and N an A-submodule of A^ι. If the vectors with entries in K/O killed by ψ(N) lie in a module of length at most b, then some square matrix B with rows in N has v(det ψ(B)) ≤ b, with ψ(B) read as a block matrix. This is the form that Ribet's lemma uses. `TauCeti.exists_addVal_det_eq_length_blockSolutions` gives an optimal array: its determinant valuation is the length of the solution module, which is contained in Z. ## Relation to the literature General linear algebra over a discrete valuation ring (elementary divisors). -/ @[expose] public section open IsDiscreteValuationRing Matrix Module Submodule Fintype Ideal LinearMap namespace New.Selmer variable {O : Type} [CommRing O] [DVR O] /-- Pointwise application of a coefficient map onto the elements killed by `a` identifies the image of a submodule of functions with the `a`-torsion of the corresponding submodule. -/ lemma range_restrict_compLeft_eq_torsionBy {O B G I : Type*} [CommRing O] [AddCommMonoid B] [Module O B] {a : O} (f : QuotSpan a →ₗ[O] B) (onto : ∀ y : B, a • y = 0 → ∃ x, f x = y) {W : Submodule O (G → I → QuotSpan a)} {V : Submodule O (G → I → B)} (mem : ∀ z, ((f.compLeft I).compLeft G) z ∈ V ↔ z ∈ W) : (((f.compLeft I).compLeft G).restrict (fun z hz ↦ (mem z).2 hz)).range = torsionBy O V a := by ext ⟨y, hy⟩ constructor · rintro ⟨z, hz⟩ rw [← hz] apply (mem_torsionBy_iff _ _).2 ext g i change a • f (z.val g i) = 0 rw [← map_smul, smul_quot_eq_zero_of_dvd dvd_rfl, map_zero] · intro h have hz : a • y = 0 := congrArg Subtype.val ((mem_torsionBy_iff _ _).1 h) choose z he using fun g i ↦ onto (y g i) (congrFun₂ hz g i) have e : ((f.compLeft I).compLeft G) z = y := funext₂ he exact ⟨⟨z, (mem z).1 (e ▸ hy)⟩, Subtype.ext e⟩ variable (O) in /-- The divisible module K/O, where K = Frac(O). -/ abbrev DivisibleQuot : Type := FractionRing O ⧸ (1 : Submodule O (FractionRing O)) /-- Division by `a`, from O/a to K/O: the class of t goes to the class of t/a. -/ noncomputable def divQuot (a : O) : QuotSpan a →ₗ[O] DivisibleQuot O := (Ideal.span {a}).liftQ ((1 : Submodule O (FractionRing O)).mkQ ∘ₗ LinearMap.toSpanSingleton O (FractionRing O) (algebraMap O (FractionRing O) a)⁻¹) (by rw [Ideal.span_singleton_le_iff_mem, mem_ker, LinearMap.comp_apply] rcases eq_or_ne a 0 with rfl | ha · simp · exact (Submodule.Quotient.mk_eq_zero _).2 (mem_one.2 ⟨1, by simp [Algebra.smul_def, ha]⟩)) /-- `divQuot a` sends the class of `t` in `O ⧸ (a)` to the class of `t / a` in `K ⧸ O`. -/ lemma divQuot_mk (a t : O) : divQuot a (Ideal.Quotient.mk _ t) = Submodule.Quotient.mk (t • (algebraMap O (FractionRing O) a)⁻¹) := rfl /-- For `a ≠ 0` there is an `O`-linear equivalence from `QuotSpan a` onto the `a`-torsion of `DivisibleQuot O` that agrees with `divQuot a`. -/ private lemma exists_divQuot_torsionEquiv {a : O} (ha : a ≠ 0) : ∃ e : QuotSpan a ≃ₗ[O] torsionBy O (DivisibleQuot O) a, ∀ x, (e x : DivisibleQuot O) = divQuot a x := by simp_rw [(Ideal.Quotient.mk_surjective (I := Ideal.span {a})).forall, divQuot_mk] unfold DivisibleQuot rw [Submodule.one_eq_range, ← torsionBySet_span_singleton_eq] exact ⟨quotientEquivTorsionBySet ha, coe_quotientEquivTorsionBySet_apply_mk ha⟩ /-- `divQuot a` is injective whenever `a ≠ 0`. -/ lemma divQuot_injective {a : O} (ha : a ≠ 0) : Function.Injective (divQuot a) := by obtain ⟨e, he⟩ := exists_divQuot_torsionEquiv ha simpa only [Function.comp_def, he] using (Subtype.val_injective.comp e.injective) /-- An element of K/O killed by `a ≠ 0` is the image of some x in O/a under division by `a`. -/ lemma exists_divQuot_eq {a : O} (ha : a ≠ 0) {y : DivisibleQuot O} (hy : a • y = 0) : ∃ x : QuotSpan a, divQuot a x = y := by obtain ⟨e, he⟩ := exists_divQuot_torsionEquiv ha obtain ⟨x, hx⟩ := e.surjective ⟨y, hy⟩ exact ⟨x, (he x).symm.trans (congrArg Subtype.val hx)⟩ /-- A finite family in the fraction field modulo the ring has a common nonzero denominator. -/ lemma exists_common_denominator {ι : Type*} [Finite ι] (x : ι → DivisibleQuot O) : ∃ a : O, a ≠ 0 ∧ ∀ i, a • x i = 0 := by choose f hf using fun i ↦ Submodule.Quotient.mk_surjective (1 : Submodule O (FractionRing O)) (x i) obtain ⟨a, ha⟩ := IsLocalization.exist_integer_multiples_of_finite (nonZeroDivisors O) f refine ⟨a, nonZeroDivisors.coe_ne_zero a, fun i ↦ ?_⟩ rw [← hf i, ← Submodule.Quotient.mk_smul] exact (Submodule.Quotient.mk_eq_zero _).2 (mem_one.2 (ha i)) /-- A torsion element `z` over a discrete valuation ring that survives multiplication by `a` gives an embedded copy of `O / a` in the `a`-torsion of its module. -/ lemma exists_injective_quotSpan_torsionBy {X : Type} [AddCommGroup X] [Module O X] {a : O} {z : X} (hz : a • z ≠ 0) (h_tors : ∃ d : O, d ≠ 0 ∧ d • z = 0) : ∃ f : QuotSpan a →ₗ[O] torsionBy O X a, Function.Injective f := by -- The annihilator of `z` is generated by some `b`, which does not divide `a`; so `b = a c`. obtain ⟨b, hb⟩ : ∃ b : O, ∀ t : O, t • z = 0 ↔ b ∣ t := (IsPrincipalIdealRing.principal (torsionOf O X z)).principal.imp fun b h_ann t ↦ by rw [← mem_torsionOf_iff, h_ann, Ideal.mem_span_singleton] obtain ⟨c, rfl⟩ : a ∣ b := (ValuationRing.dvd_total a b).resolve_right fun h ↦ hz ((hb a).2 h) have hc : c ≠ 0 := by rintro rfl simp [hb] at h_tors -- The element `w = c z` is killed exactly by the multiples of `a`, so `t ↦ t w` embeds `O / a`. let w : torsionBy O X a := ⟨c • z, by simp [smul_smul, hb]⟩ let mulW : O →ₗ[O] torsionBy O X a := LinearMap.toSpanSingleton O _ w have h_ker : Ideal.span {a} = LinearMap.ker mulW := by ext t have h_smul : t • w = 0 ↔ a * c ∣ t * c := by simp [w, Subtype.ext_iff, smul_smul, hb] simp [mulW, h_smul, Ideal.mem_span_singleton, mul_dvd_mul_iff_right hc] let e := (quotEquivOfEq _ _ h_ker).trans mulW.quotKerEquivRange exact ⟨mulW.range.subtype.comp e.toLinearMap, mulW.range.injective_subtype.comp e.injective⟩ /-- Let `X` be a torsion module over a discrete valuation ring. If the length of the `a`-torsion is less than the valuation of `a`, then `a` kills all of `X`. -/ lemma torsionBy_eq_top_of_length_lt_addVal {X : Type} [AddCommGroup X] [Module O X] {a : O} (hX : ∀ z : X, ∃ d : O, d ≠ 0 ∧ d • z = 0) (h : length O (torsionBy O X a) < addVal O a) : torsionBy O X a = ⊤ := by by_contra h_ne obtain ⟨z, hz⟩ : ∃ z : X, a • z ≠ 0 := by simpa [eq_top_iff'] using h_ne obtain ⟨f, hf⟩ := exists_injective_quotSpan_torsionBy hz (hX z) exact h.not_ge ((length_quot_span_eq_addVal (a := a)).symm.trans_le (length_le_of_injective f hf)) /-- Let O be a discrete valuation ring with normalized valuation v = `addVal O` and fraction field K, and write `DivisibleQuot O` for K/O. Let ψ : A → M_d(O) be onto and N an A-submodule of A^ι. If all w in ((K/O)^d)^ι with ∑ j, ψ(t j) • w_j = 0 for every t ∈ N lie in a submodule Z of length at most b, then some square matrix B with rows in N has v(det ψ(B)) ≤ b, where ψ(B) is read as a block matrix. A matrix acts on (K/O)^d by multiplication. -/ lemma exists_rows_addVal_det_le_of_divisible {ι A d : Type} [Fintype ι] [DecidableEq ι] [Ring A] [Algebra O A] [Fintype d] [DecidableEq d] (ψ : A →ₐ[O] Matrix d d O) (hψ : Function.Surjective ψ) (N : Submodule A (ι → A)) {b : ℕ} {Z : Submodule O (ι → d → DivisibleQuot O)} (hZ : length O Z ≤ b) (hZ_mem : ∀ w : ι → d → DivisibleQuot O, (∀ t ∈ N, ∑ j : ι, ψ (t j) • w j = 0) → w ∈ Z) : ∃ B : Matrix ι ι A, (∀ i : ι, B i ∈ N) ∧ addVal O (Matrix.comp ι ι d d O (B.map ψ)).det ≤ b := by obtain ⟨B, hB, hdet⟩ := TauCeti.exists_addVal_det_eq_length_blockSolutions (K := FractionRing O) ψ N hψ rw [← Submodule.one_eq_range] at hdet refine ⟨B, hB, hdet.le.trans ((New.length_mono ?_).trans hZ)⟩ intro w hw apply hZ_mem w intro t ht ext i simpa using (TauCeti.mem_blockSolutions ψ N).1 hw t ht i end New.Selmer