Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Curve-duality library (Poincaré duality on curves over finite fields), part 8 of 71

Definition
RPLib_S4_CDPack08

by Nickrobbins95 · Nov 18, 2026 · Mathlib 0df444a (Lean v4.33.1)

algebraic-geometryfinite-fieldsnumber-theory

Part 8 of 71 of the curve-duality library: the following library modules, in dependency order.

  • Def_RP_CdOne_Field: S4-PD (3), field layer: HypL for Gal(Ω/E₀) from Tsen + Kummer
  • Def_RP_CdOne_Trans: S4-PD (3)(iii), part T: transport of HypL to π₁^geo
  • Def_RP_CdOne_KumMain: S4-PD (3)(iii)(K), main: the Kummer-closure property of K_U / E₀ from the divisibility of Pic(V̄)
  • Def_RP_CdOne_C1: S4-PD (3)(iii), part C: the field E₀ generated by the constants is C1 (Tsen)
  • Def_RP_CdOne: S4-PD item (3): cd_l(π₁^geo(Ū)) ≤ 1, with Pic(V̄)/l = 0 as the explicit hypothesis

Formalization note. Library package of a formalization of Poincaré duality for constant coefficients on an affine curve over a finite field (the cup pairing Hc1(Uˉ,Λ)×H1(Uˉ,σ)→ΛH^1_c(\bar U,\Lambda)\times H^1(\bar U,\sigma)\to\LambdaHc1​(Uˉ,Λ)×H1(Uˉ,σ)→Λ of the geometric fundamental group is perfect). The modules are copied verbatim (import lines removed), each inside its own section ... end, in dependency order. They contain definitions together with proved lemmas (no sorry; where divisibility facts about Picard groups are used they are explicit hypotheses), so that later solution files can import them.

Definition code
import Mathlib
import Definitions.Def_RPLib_S4_CDPack02
import Definitions.Def_RPLib_S4_CDPack01
import Definitions.Def_RPLib_S4_KummerFix
import Definitions.Def_RPLib_S4_Tsen

/-!
# Curve-duality library package, part 8 of 71

Library modules of the formalization of Poincaré duality for constant coefficients on an affine curve over a
finite field (`RamanujanPetersson.CupDuality.constDuality_S3_perfect`). Each module below is copied verbatim
(import lines removed) inside its own `section` ... `end`:

* `Def_RP_CdOne_Field`: S4-PD (3), field layer: `HypL` for `Gal(Ω/E₀)` from Tsen + Kummer
* `Def_RP_CdOne_Trans`: S4-PD (3)(iii), part T: transport of `HypL` to `π₁^geo`
* `Def_RP_CdOne_KumMain`: S4-PD (3)(iii)(K), main: the Kummer-closure property of `K_U / E₀` from the divisibility of `Pic(V̄)`
* `Def_RP_CdOne_C1`: S4-PD (3)(iii), part C: the field `E₀` generated by the constants is C1 (Tsen)
* `Def_RP_CdOne`: S4-PD item (3): `cd_l(π₁^geo(Ū)) ≤ 1`, with `Pic(V̄)/l = 0` as the explicit hypothesis
-/

set_option autoImplicit false

-- ===== S4.Def_RP_CdOne_Field =====
section

/-!
# S4-PD (3), field layer: `HypL` for `Gal(Ω/E₀)` from Tsen + Kummer

Let `Ω/E₀` be a (possibly infinite) Galois extension with a primitive `l`-th root of unity in `E₀`, such that every
finite subextension `E/E₀` is C1 and satisfies the **Kummer closure** property: if `L/E` is a finite Galois
subextension and `b ∈ Lˣ` has `σ b / b ∈ Lˣˡ` for all `σ ∈ Gal(L/E)`, then some `a·b` (`a ∈ Eˣ`) has an `l`-th root
in `Ω` (for `Ω` the maximal unramified extension this is where `Pic(V̄)/l = 0` enters). Then `HypL l Gal(Ω/E₀)`
holds (`hypL_of_field`): for open `N ⊴ Q` with `Q/N` an `l`-group, `E := Ω^Q`, `L := Ω^N`, a `ℤ/l`-valued
2-cocycle on `Q` factoring through `Q/N = Gal(L/E)` is killed in `Gal(Ω/E) = Q` by `exists_kummer_data` and
`emb_coboundary`.
-/

set_option autoImplicit false
set_option linter.unusedSectionVars false

namespace RamanujanPetersson.CdOne

open IntermediateField RamanujanPetersson.Tsen Topology

/-- A function constant on left cosets of an open subgroup is locally constant. -/
theorem lc_of_coset {P X : Type*} [Group P] [TopologicalSpace P] [IsTopologicalGroup P] (W : Subgroup P)
    (hW : IsOpen (W : Set P)) (u : P → X) (hu : ∀ g, ∀ w ∈ W, u (g * w) = u g) : IsLocallyConstant u := by
  rw [IsLocallyConstant.iff_eventually_eq]
  intro g
  have h1 : (W : Set P) ∈ 𝓝 (1 : P) := hW.mem_nhds W.one_mem
  have h2 : Filter.Tendsto (fun x : P => g⁻¹ * x) (𝓝 g) (𝓝 1) := by
    have := (continuous_const_mul g⁻¹).tendsto g
    rwa [inv_mul_cancel] at this
  filter_upwards [h2 h1] with x hx
  have := hu g _ hx
  rwa [mul_inv_cancel_left] at this

variable {E₀ Ω : Type*} [Field E₀] [Field Ω] [Algebra E₀ Ω] [IsGalois E₀ Ω]

theorem fix_fixed_of_isOpen (Q : Subgroup Gal(Ω/E₀)) (hQ : IsOpen (Q : Set Gal(Ω/E₀))) :
    (fixedField Q).fixingSubgroup = Q :=
  InfiniteGalois.fixingSubgroup_fixedField ⟨Q, Q.isClosed_of_isOpen hQ⟩

theorem finiteDimensional_fixedField_of_isOpen (Q : Subgroup Gal(Ω/E₀))
    (hQ : IsOpen (Q : Set Gal(Ω/E₀))) : FiniteDimensional E₀ (fixedField Q) :=
  (InfiniteGalois.isOpen_iff_finite (fixedField Q)).mp (by
    rw [fix_fixed_of_isOpen Q hQ]; exact hQ)

theorem finiteDimensional_extendScalars {E L' : IntermediateField E₀ Ω} (h : E ≤ L')
    [FiniteDimensional E₀ L'] : FiniteDimensional E (extendScalars h) := by
  have : Module.Finite E₀ (extendScalars h) := Module.Finite.of_surjective
    ({ toFun := fun x : L' => (⟨x.1, x.2⟩ : extendScalars h)
       map_add' := fun _ _ => rfl
       map_smul' := fun _ _ => rfl } : L' →ₗ[E₀] extendScalars h)
    (fun y => ⟨⟨y.1, y.2⟩, rfl⟩)
  exact Module.Finite.of_restrictScalars_finite E₀ E (extendScalars h)

theorem isGalois_extendScalars {Q N : Subgroup Gal(Ω/E₀)} (hQ : IsOpen (Q : Set Gal(Ω/E₀)))
    (hN : IsOpen (N : Set Gal(Ω/E₀))) (hnorm : ∀ q ∈ Q, ∀ n ∈ N, q * n * q⁻¹ ∈ N)
    (h : fixedField Q ≤ fixedField N) : IsGalois (fixedField Q) (extendScalars h) := by
  rw [← InfiniteGalois.normal_iff_isGalois]
  constructor
  intro τ hτ g
  rw [IntermediateField.mem_fixingSubgroup_iff] at hτ ⊢
  intro x hx
  have hg : ((fixingSubgroupEquiv (fixedField Q)).symm g : Gal(Ω/E₀)) ∈ Q :=
    (fix_fixed_of_isOpen Q hQ).le ((fixingSubgroupEquiv _).symm g).2
  have hτ' : ((fixingSubgroupEquiv (fixedField Q)).symm τ : Gal(Ω/E₀)) ∈ N :=
    (fix_fixed_of_isOpen N hN).le
      ((IntermediateField.mem_fixingSubgroup_iff _ _).mpr (fun y hy => hτ y hy))
  have := (IntermediateField.mem_fixingSubgroup_iff _ _).mp
    ((fix_fixed_of_isOpen N hN).ge (hnorm _ hg _ hτ'))
  exact this x hx

set_option synthInstance.maxHeartbeats 400000 in
set_option maxHeartbeats 800000 in
/-- **`HypL` from field theory.** If every finite subextension of `Ω/E₀` is C1 and has the Kummer closure
property, and `E₀` contains a primitive `l`-th root of unity, then `Gal(Ω/E₀)` satisfies `HypL l`. -/
theorem hypL_of_field (l : ℕ) [hl : Fact l.Prime] {ζ : E₀} (hζ : IsPrimitiveRoot ζ l)
    (hC1 : ∀ E : IntermediateField E₀ Ω, FiniteDimensional E₀ E → IsC1 E)
    (hKum : ∀ (E : IntermediateField E₀ Ω) (L : IntermediateField E Ω), FiniteDimensional E₀ E →
      FiniteDimensional E L → IsGalois E L → ∀ b : Lˣ, (∀ σ : Gal(L/E), ∃ c : Lˣ, σ • b / b = c ^ l) →
      ∃ a : E, a ≠ 0 ∧ ∃ y : Ω, y ^ l = algebraMap E Ω a * ((b : L) : Ω)) :
    HypL l Gal(Ω/E₀) := by
  classical
  intro Q N hQ hN hNQ hnorm hlq f hf hc hinv
  have hQE : (fixedField Q).fixingSubgroup = Q := fix_fixed_of_isOpen Q hQ
  have hNL : (fixedField N).fixingSubgroup = N := fix_fixed_of_isOpen N hN
  have hEL : fixedField Q ≤ fixedField N := fixedField_le hNQ
  have hfinE : FiniteDimensional E₀ (fixedField Q) := finiteDimensional_fixedField_of_isOpen Q hQ
  have : FiniteDimensional E₀ (fixedField N) := finiteDimensional_fixedField_of_isOpen N hN
  have : FiniteDimensional (fixedField Q) (extendScalars hEL) := finiteDimensional_extendScalars hEL
  have hGal : IsGalois (fixedField Q) (extendScalars hEL) := isGalois_extendScalars hQ hN hnorm hEL
  set E := fixedField Q with hE
  set L := extendScalars hEL with hL
  set ρ : Gal(Ω/E) →* Gal(L/E) := AlgEquiv.restrictNormalHom (K₁ := Ω) L with hρ
  have hρs : Function.Surjective ρ := AlgEquiv.restrictNormalHom_surjective (F := E) (K₁ := L) Ω
  let ι : Q ≃* Gal(Ω/E) := (MulEquiv.subgroupCongr hQE.symm).trans (fixingSubgroupEquiv E)
  let π : Q →* Gal(L/E) := ρ.comp ι.toMonoidHom
  have hπs : Function.Surjective π := hρs.comp ι.surjective
  have hπx : ∀ (σ : Q) (x : L), ((π σ x : L) : Ω) = (σ : Gal(Ω/E₀)) x := fun σ x =>
    AlgEquiv.restrictNormalHom_apply L (ι σ) x
  -- the kernel of `π` is `N`
  have hker : ∀ σ τ : Q, π σ = π τ → (τ : Gal(Ω/E₀))⁻¹ * σ ∈ N := by
    intro σ τ hστ
    rw [← hNL, IntermediateField.mem_fixingSubgroup_iff]
    intro x hx
    have h1 := hπx σ ⟨x, hx⟩
    rw [hστ, hπx τ ⟨x, hx⟩] at h1
    rw [AlgEquiv.mul_apply, ← h1, AlgEquiv.aut_inv, AlgEquiv.symm_apply_apply]
  have hN1 : ∀ σ : Q, (σ : Gal(Ω/E₀)) ∈ N → π σ = 1 := by
    intro σ hσ
    rw [← hNL, IntermediateField.mem_fixingSubgroup_iff] at hσ
    ext x
    rw [hπx]
    exact hσ x x.2
  have hinv' : ∀ σ σ' τ τ' : Q, π σ = π σ' → π τ = π τ' →
      f ((σ : Gal(Ω/E₀)), (τ : Gal(Ω/E₀))) = f ((σ' : Gal(Ω/E₀)), (τ' : Gal(Ω/E₀))) := by
    intro σ σ' τ τ' h1 h2
    have := hinv σ' σ'.2 τ' τ'.2 _ (hker σ σ' h1) _ (hker τ τ' h2)
    simpa only [mul_inv_cancel_left] using this
  -- the descended cocycle on `Gal(L/E)`
  let lift : Gal(L/E) → Q := Function.surjInv hπs
  have hlift : ∀ s, π (lift s) = s := Function.surjInv_eq hπs
  let fb : Gal(L/E) × Gal(L/E) → ZMod l := fun p => f ((lift p.1 : Gal(Ω/E₀)), (lift p.2 : Gal(Ω/E₀)))
  have hfb : ∀ σ τ : Q, fb (π σ, π τ) = f ((σ : Gal(Ω/E₀)), (τ : Gal(Ω/E₀))) := fun σ τ =>
    hinv' _ _ _ _ (hlift _) (hlift _)
  have hcoc : ∀ g h j, fb (g * h, j) + fb (g, h) = fb (h, j) + fb (g, h * j) := by
    intro g h j
    obtain ⟨a, rfl⟩ := hπs g
    obtain ⟨b, rfl⟩ := hπs h
    obtain ⟨c, rfl⟩ := hπs j
    rw [← map_mul, ← map_mul, hfb, hfb, hfb, hfb]
    exact hc a a.2 b b.2 c c.2
  have hG : IsPGroup l Gal(L/E) := by
    intro s
    obtain ⟨σ, rfl⟩ := hπs s
    obtain ⟨k, hk⟩ := hlq σ σ.2
    refine ⟨k, ?_⟩
    rw [← map_pow]
    exact hN1 _ (by rw [SubmonoidClass.coe_pow]; exact hk)
  have hζE : IsPrimitiveRoot (algebraMap E₀ E ζ) l := hζ.map_of_injective (algebraMap E₀ E).injective
  have hζE0 : algebraMap E₀ E ζ ≠ 0 := hζE.ne_zero hl.out.ne_zero
  obtain ⟨β, b, hβ, hb⟩ := exists_kummer_data (hC1 E hfinE) l hG hζE hζE0 fb hcoc
  obtain ⟨a, ha, y, hy⟩ := hKum E L hfinE inferInstance hGal b (fun σ => ⟨β σ, hb σ⟩)
  obtain ⟨γ₀, hγ₀, hγ₀'⟩ := emb_coboundary L hζE hζE0 fb β b hβ hb a ha y hy
  -- the cochain on `Gal(Ω/E₀)`
  let γ : Gal(Ω/E₀) → ZMod l := fun g => if h : g ∈ Q then γ₀ (ι ⟨g, h⟩) else 0
  have hstab : IsOpen (MulAction.stabilizer Gal(Ω/E₀) y : Set Gal(Ω/E₀)) :=
    stabilizer_isOpen_of_isIntegral y
  refine ⟨γ, lc_of_coset (N ⊓ MulAction.stabilizer Gal(Ω/E₀) y) (hN.inter hstab) γ ?_, ?_⟩
  · intro g w hw
    have hwN : w ∈ N := (Subgroup.mem_inf.mp hw).1
    have hwy : w y = y := MulAction.mem_stabilizer_iff.mp (Subgroup.mem_inf.mp hw).2
    by_cases hg : g ∈ Q
    · have hgw : g * w ∈ Q := Q.mul_mem hg (hNQ hwN)
      rw [show γ (g * w) = γ₀ (ι ⟨g * w, hgw⟩) from dif_pos hgw,
        show γ g = γ₀ (ι ⟨g, hg⟩) from dif_pos hg]
      apply hγ₀'
      · show π ⟨g * w, hgw⟩ = π ⟨g, hg⟩
        rw [show (⟨g * w, hgw⟩ : Q) = ⟨g, hg⟩ * ⟨w, hNQ hwN⟩ from rfl, map_mul,
          hN1 ⟨w, hNQ hwN⟩ hwN, mul_one]
      · show (g * w) y = g y
        rw [AlgEquiv.mul_apply, hwy]
    · have hgw : g * w ∉ Q := fun h => hg (by simpa using Q.mul_mem h (Q.inv_mem (hNQ hwN)))
      rw [show γ (g * w) = 0 from dif_neg hgw, show γ g = 0 from dif_neg hg]
  · intro g hg h hh
    rw [show γ g = γ₀ (ι ⟨g, hg⟩) from dif_pos hg, show γ h = γ₀ (ι ⟨h, hh⟩) from dif_pos hh,
      show γ (g * h) = γ₀ (ι ⟨g * h, Q.mul_mem hg hh⟩) from dif_pos (Q.mul_mem hg hh)]
    have := hγ₀ (ι ⟨g, hg⟩) (ι ⟨h, hh⟩)
    rw [← map_mul] at this
    rw [← hfb ⟨g, hg⟩ ⟨h, hh⟩]
    exact this

end RamanujanPetersson.CdOne

end

-- ===== S4.Def_RP_CdOne_Trans =====
section

/-!
# S4-PD (3)(iii), part T: transport of `HypL` to `π₁^geo`

* `hypL_of_equiv`: `HypL` transports along an isomorphism of topological groups;
* `geoEquiv A K q : π₁^geo ≃* Gal(K_U / E₀)` with `E₀ = constFieldU A K q` the field generated by the constants
  (`fixingSubgroup_constFieldU`); it is a homeomorphism (`geoEquiv_continuous`, `geoEquiv_symm_continuous`:
  compact to Hausdorff);
* `hypL_pi1geo`: `HypL l Gal(K_U/E₀) → HypL l π₁^geo`;
* `exists_zeta_constFieldU`: `E₀` contains a primitive `N`-th root of unity (`N` prime to `p`);
* `AllC1 E₀ Ω`, `KumClosure l E₀ Ω`: the two field hypotheses of `hypL_of_field`, as named propositions;
* `hypL_pi1geo_of_field`: `HypL l π₁^geo` from `AllC1` and `KumClosure` for `K_U / E₀`.
-/

set_option autoImplicit false
set_option linter.unusedSectionVars false

namespace RamanujanPetersson.CdOne

open IntermediateField RamanujanPetersson.Tsen Topology RamanujanPetersson.CurveCoh RamanujanPetersson.Kummer

/-- `HypL` transports along an isomorphism of topological groups. -/
theorem hypL_of_equiv (l : ℕ) {P P' : Type*} [Group P] [TopologicalSpace P] [Group P'] [TopologicalSpace P']
    (e : P ≃* P') (he : Continuous e) (he' : Continuous e.symm) (hL : HypL l P') : HypL l P := by
  intro Q N hQ hN hNQ hnorm hlq f hf hc hinv
  let Q' : Subgroup P' := Q.comap e.symm.toMonoidHom
  let N' : Subgroup P' := N.comap e.symm.toMonoidHom
  obtain ⟨γ, hγ, hγf⟩ := hL Q' N' (he'.isOpen_preimage _ hQ) (he'.isOpen_preimage _ hN) (fun x hx => hNQ hx)
    (fun q hq n hn => by
      show e.symm (q * n * q⁻¹) ∈ N
      rw [map_mul, map_mul, map_inv]
      exact hnorm _ hq _ hn)
    (fun q hq => by
      obtain ⟨k, hk⟩ := hlq _ hq
      exact ⟨k, show e.symm (q ^ l ^ k) ∈ N by rw [map_pow]; exact hk⟩)
    (fun x => f (e.symm x.1, e.symm x.2)) (hf.comp_continuous (he'.prodMap he'))
    (fun g hg h hh j hj => by
      show f (e.symm (g * h), e.symm j) + f (e.symm g, e.symm h) =
        f (e.symm h, e.symm j) + f (e.symm g, e.symm (h * j))
      rw [map_mul, map_mul]
      exact hc _ hg _ hh _ hj)
    (fun g hg h hh n hn n' hn' => by
      show f (e.symm (g * n), e.symm (h * n')) = f (e.symm g, e.symm h)
      rw [map_mul, map_mul]
      exact hinv _ hg _ hh _ hn _ hn')
  refine ⟨fun x => γ (e x), hγ.comp_continuous he, fun g hg h hh => ?_⟩
  have hg' : e g ∈ Q' := show e.symm (e g) ∈ Q by rw [MulEquiv.symm_apply_apply]; exact hg
  have hh' : e h ∈ Q' := show e.symm (e h) ∈ Q by rw [MulEquiv.symm_apply_apply]; exact hh
  have h1 := hγf (e g) hg' (e h) hh'
  simp only [MulEquiv.symm_apply_apply] at h1
  rw [h1]
  simp only [map_mul]

/-- The C1 hypothesis of `hypL_of_field`: every finite subextension of `Ω/E₀` is C1. -/
def AllC1 (E₀ Ω : Type*) [Field E₀] [Field Ω] [Algebra E₀ Ω] : Prop :=
  ∀ E : IntermediateField E₀ Ω, FiniteDimensional E₀ E → IsC1 E

set_option synthInstance.maxHeartbeats 400000 in
/-- The Kummer-closure hypothesis of `hypL_of_field`. -/
def KumClosure (l : ℕ) (E₀ Ω : Type*) [Field E₀] [Field Ω] [Algebra E₀ Ω] : Prop :=
  ∀ (E : IntermediateField E₀ Ω) (L : IntermediateField E Ω), FiniteDimensional E₀ E →
    FiniteDimensional E L → IsGalois E L → ∀ b : Lˣ, (∀ σ : Gal(L/E), ∃ c : Lˣ, σ • b / b = c ^ l) →
    ∃ a : E, a ≠ 0 ∧ ∃ y : Ω, y ^ l = algebraMap E Ω a * ((b : L) : Ω)

section Geo

variable (A K : Type) [CommRing A] [Field K] [Algebra A K] (q : ℕ)

/-- `π₁^geo ≃* Gal(K_U / E₀)`, `E₀ = constFieldU` the field generated by the constants. -/
noncomputable def geoEquiv : pi1geo A K q ≃* Gal(maxUnram A K / constFieldU A K q) :=
  (MulEquiv.subgroupCongr (fixingSubgroup_constFieldU A K q).symm).trans (fixingSubgroupEquiv _)

theorem geoEquiv_apply (σ : pi1geo A K q) (x : maxUnram A K) : geoEquiv A K q σ x = (σ : Pi1 A K) x := rfl

set_option synthInstance.maxHeartbeats 400000 in
theorem geoEquiv_continuous : Continuous (geoEquiv A K q) := by
  refine continuous_of_continuousAt_one (geoEquiv A K q) ?_
  intro s hs
  rw [map_one] at hs
  rw [Filter.mem_map]
  obtain ⟨F, hF, hFs⟩ := (krullTopology_mem_nhds_one_iff (constFieldU A K q) (maxUnram A K) s).1 hs
  have := hF
  let b := Module.finBasis (constFieldU A K q) F
  let W : Set (pi1geo A K q) :=
    Subtype.val ⁻¹' ⋂ i, (fixElt A K (b i : maxUnram A K) : Set (Pi1 A K))
  have hW : IsOpen W :=
    continuous_subtype_val.isOpen_preimage _ (isOpen_iInter_of_finite fun i => fixElt_isOpen A K _)
  have h1 : (1 : pi1geo A K q) ∈ W :=
    show ((1 : pi1geo A K q) : Pi1 A K) ∈ ⋂ i, (fixElt A K (b i : maxUnram A K) : Set (Pi1 A K)) from
      Set.mem_iInter.2 fun i => (fixElt A K _).one_mem
  refine Filter.mem_of_superset (hW.mem_nhds h1) ?_
  intro σ hσ
  have hσ' : ∀ i, (σ : Pi1 A K) (b i : maxUnram A K) = (b i : maxUnram A K) := fun i =>
    (Set.mem_iInter.1 (show (σ : Pi1 A K) ∈ ⋂ i, (fixElt A K (b i : maxUnram A K) : Set (Pi1 A K)) from hσ)) i
  apply hFs
  rw [SetLike.mem_coe, IntermediateField.mem_fixingSubgroup_iff]
  intro x hx
  have hlin : (geoEquiv A K q σ).toLinearMap ∘ₗ F.val.toLinearMap = F.val.toLinearMap :=
    b.ext fun i => hσ' i
  exact LinearMap.congr_fun hlin ⟨x, hx⟩

theorem geoEquiv_symm_continuous : Continuous (geoEquiv A K q).symm := by
  have : T2Space Gal(maxUnram A K / constFieldU A K q) := krullTopology_t2
  exact (Continuous.homeoOfEquivCompactToT2 (f := (geoEquiv A K q).toEquiv)
    (geoEquiv_continuous A K q)).symm.continuous

theorem hypL_pi1geo (l : ℕ) (hL : HypL l Gal(maxUnram A K / constFieldU A K q)) : HypL l (pi1geo A K q) :=
  hypL_of_equiv l (geoEquiv A K q) (geoEquiv_continuous A K q) (geoEquiv_symm_continuous A K q) hL

variable {p : ℕ} [Fact p.Prime] [CharP K p]

/-- `E₀` contains a primitive `N`-th root of unity for `N` prime to `p`. -/
theorem exists_zeta_constFieldU {e : ℕ} (he : 0 < e) (N : ℕ) [NeZero N] (hN : (N : K) ≠ 0) :
    ∃ ζ : constFieldU A K (p ^ e), IsPrimitiveRoot ζ N := by
  obtain ⟨ζ, hζ, hc⟩ := Kummer.exists_zeta A K p he N hN
  have hmem : ζ ∈ constFieldU A K (p ^ e) := IntermediateField.subset_adjoin _ _ hc
  exact ⟨⟨ζ, hmem⟩, (IsPrimitiveRoot.map_iff_of_injective (ζ := (⟨ζ, hmem⟩ : constFieldU A K (p ^ e)))
    (f := (constFieldU A K (p ^ e)).val) Subtype.val_injective).1 hζ⟩

/-- `HypL l π₁^geo` from the C1 and Kummer-closure hypotheses on the finite extensions of `E₀`. -/
theorem hypL_pi1geo_of_field (l : ℕ) [Fact l.Prime] {e : ℕ} (he : 0 < e) (hl : (l : K) ≠ 0)
    (hC1 : AllC1 (constFieldU A K (p ^ e)) (maxUnram A K))
    (hKum : KumClosure l (constFieldU A K (p ^ e)) (maxUnram A K)) :
    HypL l (pi1geo A K (p ^ e)) := by
  have : NeZero l := ⟨(Fact.out : l.Prime).ne_zero⟩
  obtain ⟨ζ, hζ⟩ := exists_zeta_constFieldU A K he l hl
  exact hypL_pi1geo A K (p ^ e) l (hypL_of_field l hζ hC1 hKum)

end Geo

end RamanujanPetersson.CdOne

end

-- ===== S4.Def_RP_CdOne_KumMain =====
section

/-!
# S4-PD (3)(iii)(K), main: the Kummer-closure property of `K_U / E₀` from the divisibility of `Pic(V̄)`

* `PicDivU A K p l`: **`Pic(V̄)` is `l`-divisible at every finite level** -- for every finite `M ≤ K_U` and every
  divisor `D` of `B_M` (finite support), after a constant extension `M·𝔽_{p^m}` some `a ≠ 0` has
  `D + div(a) ≡ 0 mod l`. This is the explicit hypothesis of S4-PD item (3) (discharged by S4-CoreB).
* `kumClosure_of_picDiv`: `PicDivU` gives `KumClosure l E₀ K_U` for `E₀ = constFieldU`: a Kummer element `b` of a
  finite Galois `L/E` becomes an `l`-th power in `K_U` after multiplying by some `a ∈ E^×`.
  Proof: `D(P) = v_{w(P)}(b)` on `B_{ML ∩ E}` is well defined mod `l` (`orbit_dvd`, `hgrp_dvd`); `PicDivU` gives `a`;
  then `a·b` has `l`-divisible valuations on `ML·𝔽_{p^m}` (`val_underI`) and `root_mem_maxUnram_of_dvd` applies.
-/

set_option autoImplicit false
set_option linter.unusedSectionVars false

namespace RamanujanPetersson.CdOne

open IntermediateField IsDedekindDomain RamanujanPetersson.Kummer RamanujanPetersson.CurveCoh

noncomputable section

/-- **`Pic(V̄)/l = 0` at every finite level `M ≤ K_U`**: every divisor `D` of `B_M` becomes, after a constant
extension `M·𝔽_{p^m}`, congruent mod `l` to a principal divisor `-div(a)`. -/
def PicDivU (A K : Type) [CommRing A] [IsDedekindDomain A] [Field K] [Algebra A K] [IsFractionRing A K]
    (p : ℕ) [Fact p.Prime] [CharP K p] (l : ℕ) : Prop :=
  ∀ M : IntermediateField K (AlgebraicClosure K), FiniteDimensional K M → M ≤ maxUnram A K →
    ∀ [IsDedekindDomain (integralClosure A M)] [IsFractionRing (integralClosure A M) M]
      (D : HeightOneSpectrum (integralClosure A M) → ℤ), (Function.support D).Finite →
    ∃ m : ℕ, 0 < m ∧ ∃ a : ↥(M ⊔ constLevel K p m), a ≠ 0 ∧
      ∀ [IsDedekindDomain (integralClosure A ↥(M ⊔ constLevel K p m))]
        [IsFractionRing (integralClosure A ↥(M ⊔ constLevel K p m)) ↥(M ⊔ constLevel K p m)]
        (w : HeightOneSpectrum (integralClosure A ↥(M ⊔ constLevel K p m))),
        (l : ℤ) ∣ D (underI A (le_sup_left : M ≤ M ⊔ constLevel K p m) w) +
          WithZero.log (w.valuation (↥(M ⊔ constLevel K p m)) a)

variable {K : Type} [Field K] (A : Type) [CommRing A] [IsDedekindDomain A] [Algebra A K] [IsFractionRing A K]
  {p : ℕ} [Fact p.Prime] [CharP K p]

set_option synthInstance.maxHeartbeats 400000 in
set_option maxHeartbeats 1600000 in
/-- **The Kummer-closure property of `K_U / E₀` from `Pic(V̄)/l = 0`.** -/
theorem kumClosure_of_picDiv (hperf : ∀ (P : Ideal A) [P.IsMaximal], PerfectField P.ResidueField)
    (e : ℕ) (l : ℕ) [NeZero l] (hN : IsUnit (l : A)) (hPic : PicDivU A K p l) :
    KumClosure l (constFieldU A K (p ^ e)) (maxUnram A K) := by
  intro E L _ _ hGal b hb
  haveI := hGal
  have hb' : ∀ σ : L ≃ₐ[E] L, ∃ c : L, σ (b : L) = c ^ l * (b : L) := by
    intro σ
    obtain ⟨c, hc⟩ := hb σ
    refine ⟨(c : L), ?_⟩
    have h1 := congrArg Units.val hc
    rw [Units.val_div_eq_div_val, Units.val_pow_eq_pow_val] at h1
    change σ (b : L) / (b : L) = (c : L) ^ l at h1
    rw [← h1, div_mul_cancel₀ _ b.ne_zero]
  -- the finite level `ML ∋ b`
  obtain ⟨ML, hML, hβML⟩ := exists_unramSet_of_finite A K {(((b : L) : maxUnram A K) : AlgebraicClosure K)}
    (fun x hx => by rw [Finset.mem_singleton.1 hx]; exact ((b : L) : maxUnram A K).2)
  haveI : FiniteDimensional K ML := hML.1
  haveI : IsGalois K ML := hML.2.1
  have hLU : ML ≤ maxUnram A K := by
    rw [maxUnram_eq_sSup]
    exact le_sSup hML
  obtain ⟨bL, hbL⟩ : ∃ bL : ML, (bL : AlgebraicClosure K) = (((b : L) : maxUnram A K) : AlgebraicClosure K) :=
    ⟨⟨(((b : L) : maxUnram A K) : AlgebraicClosure K), hβML (IntermediateField.subset_adjoin K _ (by simp))⟩, rfl⟩
  -- `ME = ML ∩ E`
  obtain ⟨E', hE'⟩ : ∃ E' : IntermediateField K (AlgebraicClosure K),
      E' = (E.restrictScalars K).map (maxUnram A K).val := ⟨_, rfl⟩
  obtain ⟨ME, hMEd⟩ : ∃ ME : IntermediateField K (AlgebraicClosure K), ME = ML ⊓ E' := ⟨_, rfl⟩
  have hle : ME ≤ ML := by rw [hMEd]; exact inf_le_left
  have hMEE : ME ≤ E' := by rw [hMEd]; exact inf_le_right
  have hME : ∀ x : ML, (x : AlgebraicClosure K) ∈ ME ↔
      ∃ e : E, ((e : maxUnram A K) : AlgebraicClosure K) = x := by
    intro x
    rw [hMEd, IntermediateField.mem_inf]
    constructor
    · rintro ⟨-, h⟩
      rw [hE', ← SetLike.mem_coe, IntermediateField.coe_map] at h
      obtain ⟨y, hy, hyx⟩ := h
      exact ⟨⟨y, hy⟩, hyx⟩
    · rintro ⟨e, he⟩
      refine ⟨x.2, ?_⟩
      rw [hE', ← SetLike.mem_coe, IntermediateField.coe_map]
      exact ⟨(e : maxUnram A K), e.2, he⟩
  haveI : FiniteDimensional K ME := FiniteDimensional.of_injective
    (IntermediateField.inclusion hle).toLinearMap (IntermediateField.inclusion hle).injective
  haveI : Algebra.IsSeparable K ME := Algebra.IsSeparable.of_algHom (F := K) (E' := ML) (IntermediateField.inclusion hle)
  haveI : IsFractionRing (integralClosure A ML) ML := integralClosure.isFractionRing_of_finite_extension (A := A) K ML
  haveI : IsDedekindDomain (integralClosure A ML) := integralClosure.isDedekindDomain (A := A) (K := K) (L := ML)
  haveI : IsFractionRing (integralClosure A ME) ME := integralClosure.isFractionRing_of_finite_extension (A := A) K ME
  haveI : IsDedekindDomain (integralClosure A ME) := integralClosure.isDedekindDomain (A := A) (K := K) (L := ME)
  have hb0 : (b : L) ≠ 0 := b.ne_zero
  -- valuations of `bL` on a fibre over `B_ME` agree mod `l`
  have horb : ∀ w w' : HeightOneSpectrum (integralClosure A ML), underI A hle w = underI A hle w' →
      (l : ℤ) ∣ WithZero.log (w.valuation ML bL) - WithZero.log (w'.valuation ML bL) := fun w w' h =>
    orbit_dvd A (constFieldU A K (p ^ e)) E hLU hle hME (l : ℤ) bL
      (fun τ hτ w => hgrp_dvd A hperf _ E L l hLU hML (b : L) hb0 hb' bL hbL hτ w) w w' h
  -- the divisor `D = v(b)` on `B_ME`
  let w₀ : HeightOneSpectrum (integralClosure A ME) → HeightOneSpectrum (integralClosure A ML) :=
    fun P => Classical.choose (exists_underI_eq A hle P)
  have hw₀ : ∀ P, underI A hle (w₀ P) = P := fun P => Classical.choose_spec (exists_underI_eq A hle P)
  let D : HeightOneSpectrum (integralClosure A ME) → ℤ := fun P => WithZero.log ((w₀ P).valuation ML bL)
  have hfin : (Function.support D).Finite := by
    refine ((finite_log_val_ne_zero (B := integralClosure A ML) bL).image (underI A hle)).subset ?_
    intro P hP
    exact ⟨w₀ P, hP, hw₀ P⟩
  obtain ⟨m, hm, a, ha0, hdivD⟩ := hPic ME inferInstance (hle.trans hLU) D hfin
  -- the level `M = ML ⊔ C_m`
  have hM : ML ⊔ constLevel K p m ∈ unramSet A K := sup_mem_unramSet A K hML (constLevel_mem_unramSet A hm)
  haveI : FiniteDimensional K ↥(ML ⊔ constLevel K p m) := hM.1
  haveI : IsGalois K ↥(ML ⊔ constLevel K p m) := hM.2.1
  have hMC : ME ⊔ constLevel K p m ≤ ML ⊔ constLevel K p m := sup_le_sup_right hle _
  have hLM : ML ≤ ML ⊔ constLevel K p m := le_sup_left
  haveI : FiniteDimensional K ↥(ME ⊔ constLevel K p m) := FiniteDimensional.of_injective
    (IntermediateField.inclusion hMC).toLinearMap (IntermediateField.inclusion hMC).injective
  haveI : Algebra.IsSeparable K ↥(ME ⊔ constLevel K p m) :=
    Algebra.IsSeparable.of_algHom (F := K) (E' := ↥(ML ⊔ constLevel K p m)) (IntermediateField.inclusion hMC)
  haveI : IsFractionRing (integralClosure A ↥(ML ⊔ constLevel K p m)) ↥(ML ⊔ constLevel K p m) :=
    integralClosure.isFractionRing_of_finite_extension (A := A) K _
  haveI : IsDedekindDomain (integralClosure A ↥(ML ⊔ constLevel K p m)) :=
    integralClosure.isDedekindDomain (A := A) (K := K) (L := ↥(ML ⊔ constLevel K p m))
  haveI : IsFractionRing (integralClosure A ↥(ME ⊔ constLevel K p m)) ↥(ME ⊔ constLevel K p m) :=
    integralClosure.isFractionRing_of_finite_extension (A := A) K _
  haveI : IsDedekindDomain (integralClosure A ↥(ME ⊔ constLevel K p m)) :=
    integralClosure.isDedekindDomain (A := A) (K := K) (L := ↥(ME ⊔ constLevel K p m))
  have hbL0 : bL ≠ 0 := by
    intro h
    apply hb0
    have h2 : (((b : L) : maxUnram A K) : AlgebraicClosure K) = 0 := by rw [← hbL, h, ZeroMemClass.coe_zero]
    simpa using h2
  have hbM0 : IntermediateField.inclusion hLM bL ≠ 0 := (map_ne_zero _).2 hbL0
  have ha'0 : IntermediateField.inclusion hMC a ≠ 0 := (map_ne_zero _).2 ha0
  have hdiv : ∀ W : HeightOneSpectrum (integralClosure A ↥(ML ⊔ constLevel K p m)), (l : ℤ) ∣
      WithZero.log (W.valuation (↥(ML ⊔ constLevel K p m))
        (IntermediateField.inclusion hMC a * IntermediateField.inclusion hLM bL)) := by
    intro W
    rw [log_val_mul W ha'0 hbM0, ← val_underI A hMC hM hperf W a, ← val_underI A hLM hM hperf W bL]
    have hP : underI A hle (underI A hLM W) =
        underI A (le_sup_left : ME ≤ ME ⊔ constLevel K p m) (underI A hMC W) := by
      rw [underI_trans, underI_trans]
    have h1 : (l : ℤ) ∣ WithZero.log ((w₀ (underI A (le_sup_left : ME ≤ ME ⊔ constLevel K p m)
        (underI A hMC W))).valuation ML bL) +
        WithZero.log ((underI A hMC W).valuation (↥(ME ⊔ constLevel K p m)) a) := hdivD (underI A hMC W)
    have h2 := horb (underI A hLM W) _ (hP.trans (hw₀ _).symm)
    have h3 := dvd_add h1 h2
    rwa [show ∀ x y z : ℤ, x + y + (z - x) = y + z from fun x y z => by ring] at h3
  obtain ⟨γ, hγ⟩ := IsAlgClosed.exists_pow_nat_eq
    (((IntermediateField.inclusion hMC a * IntermediateField.inclusion hLM bL : ↥(ML ⊔ constLevel K p m)) :
      AlgebraicClosure K)) (Nat.pos_of_ne_zero (NeZero.ne l))
  have hγU : γ ∈ maxUnram A K := root_mem_maxUnram_of_dvd A hM hN (mul_ne_zero ha'0 hbM0) hdiv hγ
  -- `a ∈ E`
  have haE' : (a : AlgebraicClosure K) ∈ E' := sup_le hMEE (by rw [hE']; exact constLevel_le_map A hm E) a.2
  rw [← SetLike.mem_coe, hE', IntermediateField.coe_map] at haE'
  obtain ⟨y, hyE, hya⟩ := haE'
  refine ⟨⟨y, hyE⟩, ?_, ⟨γ, hγU⟩, Subtype.ext ?_⟩
  · intro h0
    apply ha0
    apply Subtype.ext
    have hy0 : y = 0 := congrArg Subtype.val h0
    rw [ZeroMemClass.coe_zero, ← hya, hy0, map_zero]
  · simp only [IntermediateField.coe_pow, IntermediateField.coe_mul, IntermediateField.algebraMap_apply]
    rw [hγ, IntermediateField.coe_mul]
    exact congrArg₂ (· * ·) hya.symm hbL

end

end RamanujanPetersson.CdOne

end

-- ===== S4.Def_RP_CdOne_C1 =====
section

/-!
# S4-PD (3)(iii), part C: the field `E₀` generated by the constants is C1 (Tsen)

`K` algebraic over `𝔽_q(t)` (`[Algebra.IsAlgebraic (RatFunc Fq) K]`), `q = #𝔽_q = p ^ e`. Then
`E₀ = constFieldU A K q ⊆ K_U` contains `𝔽̄_q` (`constEmb`) and is algebraic over `𝔽̄_q(t)` with `t` transcendental,
so it is C1 by Tsen (`isC1_constFieldU`), and so is every finite extension (`allC1_constFieldU`).
-/

set_option autoImplicit false
set_option linter.unusedSectionVars false

namespace RamanujanPetersson.CdOne

open IntermediateField RamanujanPetersson.Tsen RamanujanPetersson.CurveCoh RamanujanPetersson.Kummer Polynomial

/-- Tsen, abstract form: a field algebraic over `k(t)`, `k` algebraically closed, `t` transcendental, is C1. -/
theorem isC1_of_transcendental (k M : Type*) [Field k] [IsAlgClosed k] [Field M] [Algebra k M] (t : M)
    (ht : Transcendental k t) [Algebra.IsAlgebraic (adjoin k {t}) M] : IsC1 M := by
  let e := RatFunc.algEquivOfTranscendental t ht
  let _ : Algebra (RatFunc k) (adjoin k {t}) := e.toRingEquiv.toRingHom.toAlgebra
  have : Algebra.IsAlgebraic (RatFunc k) (adjoin k {t}) := ⟨fun x => by
    have h2 : algebraMap (RatFunc k) (adjoin k {t}) (e.symm x) = x := e.apply_symm_apply x
    exact h2 ▸ isAlgebraic_algebraMap _⟩
  exact (tsen k (adjoin k {t})).of_algebraic

/-- Every element of `𝔽̄_q` is a constant: `c ^ (q ^ n) = c` for some `n > 0`. -/
theorem exists_pow_card_pow_eq (Fq : Type*) [Field Fq] [Fintype Fq] (c : AlgebraicClosure Fq) :
    ∃ n : ℕ, 0 < n ∧ c ^ Fintype.card Fq ^ n = c := by
  have hc : IsIntegral Fq c := (Algebra.IsAlgebraic.isAlgebraic c).isIntegral
  have : FiniteDimensional Fq (adjoin Fq {c}) := adjoin.finiteDimensional hc
  let _ : Fintype (adjoin Fq {c}) := Module.fintypeOfFintype (Module.finBasis Fq (adjoin Fq {c}))
  refine ⟨Module.finrank Fq (adjoin Fq {c}), Module.finrank_pos, ?_⟩
  have h1 := FiniteField.pow_card (⟨c, mem_adjoin_simple_self Fq c⟩ : adjoin Fq {c})
  rw [Module.card_eq_pow_finrank (K := Fq)] at h1
  have h2 := congrArg (fun x : adjoin Fq {c} => (x : AlgebraicClosure Fq)) h1
  simp only [SubmonoidClass.coe_pow] at h2
  exact h2

section Const

variable (A K : Type) [CommRing A] [Field K] [Algebra A K] {p : ℕ} [Fact p.Prime] [CharP K p]
  (Fq : Type) [Field Fq] [Fintype Fq] [Algebra Fq K] {e : ℕ} (he : 0 < e) (hq : Fintype.card Fq = p ^ e)

/-- The embedding `𝔽̄_q → K̄` over `𝔽_q`. -/
noncomputable def fqBar : AlgebraicClosure Fq →ₐ[Fq] AlgebraicClosure K := IsAlgClosed.lift

include hq in
theorem fqBar_isConst (c : AlgebraicClosure Fq) : IsConst (p ^ e) (fqBar K Fq c) := by
  obtain ⟨n, hn, h⟩ := exists_pow_card_pow_eq Fq c
  rw [hq] at h
  exact IsConst.map (fqBar K Fq) ⟨n, hn, h⟩

include he hq in
theorem fqBar_mem_maxUnram (c : AlgebraicClosure Fq) : fqBar K Fq c ∈ maxUnram A K :=
  mem_maxUnram_of_isConst (A := A) (K := K) (p := p) he (fqBar_isConst K Fq hq c)

include he hq in
theorem fqBar_mem_constFieldU (c : AlgebraicClosure Fq) :
    (⟨fqBar K Fq c, fqBar_mem_maxUnram A K Fq he hq c⟩ : maxUnram A K) ∈ constFieldU A K (p ^ e) := by
  obtain ⟨n, hn, h⟩ := fqBar_isConst K Fq hq c
  exact IntermediateField.subset_adjoin _ _ ⟨n, hn, Subtype.ext h⟩

/-- `𝔽̄_q ⊆ E₀`. -/
noncomputable def constEmb : AlgebraicClosure Fq →+* constFieldU A K (p ^ e) where
  toFun c := ⟨⟨fqBar K Fq c, fqBar_mem_maxUnram A K Fq he hq c⟩, fqBar_mem_constFieldU A K Fq he hq c⟩
  map_one' := Subtype.ext (Subtype.ext (map_one (fqBar K Fq)))
  map_mul' x y := Subtype.ext (Subtype.ext (map_mul (fqBar K Fq) x y))
  map_zero' := Subtype.ext (Subtype.ext (map_zero (fqBar K Fq)))
  map_add' x y := Subtype.ext (Subtype.ext (map_add (fqBar K Fq) x y))

/-- The inclusion `E₀ → K̄`. -/
noncomputable def nuE : constFieldU A K (p ^ e) →ₐ[K] AlgebraicClosure K :=
  (maxUnram A K).val.comp (constFieldU A K (p ^ e)).val

variable [Algebra (RatFunc Fq) K] [IsScalarTower Fq (RatFunc Fq) K] [Algebra.IsAlgebraic (RatFunc Fq) K]

include he hq in
/-- `E₀` is C1 (Tsen). -/
theorem isC1_constFieldU : IsC1 (constFieldU A K (p ^ e)) := by
  classical
  set E₀ := constFieldU A K (p ^ e)
  set ι := constEmb A K Fq he hq
  let _ : Algebra (AlgebraicClosure Fq) E₀ := ι.toAlgebra
  set θ : RatFunc Fq →+* E₀ := (algebraMap K E₀).comp (algebraMap (RatFunc Fq) K)
  set t : E₀ := θ RatFunc.X
  -- `t` is transcendental over `𝔽̄_q`
  have htr : Transcendental (AlgebraicClosure Fq) t := by
    rintro ⟨P, hP, hev⟩
    let _ : Algebra (AlgebraicClosure Fq) (AlgebraicClosure K) := (fqBar K Fq).toRingHom.toAlgebra
    have : IsScalarTower Fq (AlgebraicClosure Fq) (AlgebraicClosure K) :=
      IsScalarTower.of_algebraMap_eq fun a => ((fqBar K Fq).commutes a).symm
    set x0 : K := algebraMap (RatFunc Fq) K RatFunc.X
    have hA : IsAlgebraic (AlgebraicClosure Fq) (algebraMap K (AlgebraicClosure K) x0) := by
      refine ⟨P, hP, ?_⟩
      have h1 := congrArg (nuE A K) hev
      rw [aeval_def, RingHom.algebraMap_toAlgebra, map_zero, ← AlgHom.coe_toRingHom, hom_eval₂] at h1
      rw [aeval_def, RingHom.algebraMap_toAlgebra]
      exact h1
    have hB : IsAlgebraic Fq (algebraMap K (AlgebraicClosure K) x0) := IsAlgebraic.restrictScalars (R := Fq) hA
    have hC : IsAlgebraic Fq x0 :=
      (isAlgebraic_algHom_iff (IsScalarTower.toAlgHom Fq K (AlgebraicClosure K))
        (algebraMap K (AlgebraicClosure K)).injective).1 hB
    have hD : IsAlgebraic Fq (RatFunc.X : RatFunc Fq) :=
      (isAlgebraic_algHom_iff (IsScalarTower.toAlgHom Fq (RatFunc Fq) K)
        (algebraMap (RatFunc Fq) K).injective).1 hC
    exact RatFunc.transcendental_X hD
  set F₀ := adjoin (AlgebraicClosure Fq) {t}
  -- step 1: `θ (𝔽_q(t)) ⊆ F₀`
  have hcst : ∀ a : Fq, θ (algebraMap Fq (RatFunc Fq) a) ∈ F₀ := fun a => by
    have h : θ (algebraMap Fq (RatFunc Fq) a) = algebraMap (AlgebraicClosure Fq) E₀ (algebraMap Fq _ a) := by
      apply Subtype.ext; apply Subtype.ext
      show algebraMap K (AlgebraicClosure K) (algebraMap (RatFunc Fq) K (algebraMap Fq (RatFunc Fq) a)) =
        fqBar K Fq (algebraMap Fq (AlgebraicClosure Fq) a)
      rw [← IsScalarTower.algebraMap_apply, ← IsScalarTower.algebraMap_apply, AlgHom.commutes]
    rw [h]
    exact F₀.algebraMap_mem _
  let S : IntermediateField Fq (RatFunc Fq) :=
    Subfield.toIntermediateField (F₀.toSubfield.comap θ) hcst
  have hS : ∀ r, θ r ∈ F₀ := by
    have hle : adjoin Fq {(RatFunc.X : RatFunc Fq)} ≤ S :=
      adjoin_simple_le_iff.2 (show θ RatFunc.X ∈ F₀ from mem_adjoin_simple_self _ t)
    rw [RatFunc.adjoin_X] at hle
    exact fun r => hle (Set.mem_univ r)
  -- step 2: `K ⊆ E₀` is integral over `F₀`
  have hK : ∀ y : K, IsIntegral F₀ (algebraMap K E₀ y) := fun y =>
    IsIntegral.map_of_comp_eq (θ.codRestrict F₀ hS) (algebraMap K E₀) (RingHom.ext fun _ => rfl)
      (Algebra.IsAlgebraic.isAlgebraic y).isIntegral
  -- step 3 and 4: `E₀` is algebraic over `F₀ (K)`, which is algebraic over `F₀`
  set L₁ := adjoin F₀ (Set.range (algebraMap K E₀))
  have : Algebra.IsAlgebraic F₀ L₁ := isAlgebraic_adjoin (by rintro _ ⟨y, rfl⟩; exact hK y)
  have hx : ∀ x : E₀, IsAlgebraic F₀ x := fun x => by
    have h1 : IsIntegral K x := (isIntegral_algHom_iff (nuE A K) (Subtype.val_injective.comp
      Subtype.val_injective)).1 (Algebra.IsIntegral.isIntegral _)
    have h2 : IsIntegral L₁ x :=
      IsIntegral.map_of_comp_eq ((algebraMap K E₀).codRestrict L₁ fun y => subset_adjoin _ _ ⟨y, rfl⟩)
        (RingHom.id E₀) (RingHom.ext fun _ => rfl) h1
    exact IsAlgebraic.restrictScalars (R := F₀) (S := L₁) h2.isAlgebraic
  have : Algebra.IsAlgebraic F₀ E₀ := ⟨hx⟩
  exact isC1_of_transcendental (AlgebraicClosure Fq) E₀ t htr

include he hq in
/-- Every finite extension of `E₀` inside `K_U` is C1. -/
theorem allC1_constFieldU : AllC1 (constFieldU A K (p ^ e)) (maxUnram A K) := fun E hE => by
  have := hE
  exact (isC1_constFieldU A K Fq he hq).of_finite

end Const

end RamanujanPetersson.CdOne

end

-- ===== S4.Def_RP_CdOne =====
section

/-!
# S4-PD item (3): `cd_l(π₁^geo(Ū)) ≤ 1`, with `Pic(V̄)/l = 0` as the explicit hypothesis

Setting: `K` a function field over `𝔽_q` (`q = p^e`, `K` algebraic over `𝔽_q(t)`), `A ⊆ K` a Dedekind domain with
fraction field `K` and perfect residue fields (`U = Spec A`), `l` a unit of `A`.
* `hypL_pi1geo_of_picDiv`: `π₁^geo = Gal(K_U / K·𝔽̄_q)` satisfies `HypL l` (Tsen: `allC1_constFieldU`; Kummer closure:
  `kumClosure_of_picDiv` from `PicDivU A K p l`);
* `h2_pi1geo_eq_zero`: **`H²(π₁^geo, M) = 0`** for every finite `M` killed by `lⁿ` with a continuous action of
  `π₁(U)` (locally constant 2-cocycles are coboundaries of locally constant 1-cochains).
-/

set_option autoImplicit false
set_option linter.unusedSectionVars false

universe u

namespace RamanujanPetersson.CdOne

open IntermediateField RamanujanPetersson.Kummer RamanujanPetersson.CurveCoh

noncomputable section

variable {K : Type} [Field K] (A : Type) [CommRing A] [IsDedekindDomain A] [Algebra A K] [IsFractionRing A K]
  {p : ℕ} [Fact p.Prime] [CharP K p]
  (Fq : Type) [Field Fq] [Fintype Fq] [Algebra Fq K] {e : ℕ} (he : 0 < e) (hq : Fintype.card Fq = p ^ e)
  [Algebra (RatFunc Fq) K] [IsScalarTower Fq (RatFunc Fq) K] [Algebra.IsAlgebraic (RatFunc Fq) K]

include he hq in
/-- **`HypL l π₁^geo`** (hence `cd_l(π₁^geo) ≤ 1`) from `Pic(V̄)/l = 0`. -/
theorem hypL_pi1geo_of_picDiv (hperf : ∀ (P : Ideal A) [P.IsMaximal], PerfectField P.ResidueField)
    (l : ℕ) [Fact l.Prime] (hN : IsUnit (l : A)) (hPic : PicDivU A K p l) :
    HypL l (pi1geo A K (p ^ e)) := by
  haveI : NeZero l := ⟨(Fact.out : l.Prime).ne_zero⟩
  have hl : (l : K) ≠ 0 := by
    rw [← map_natCast (algebraMap A K) l]
    exact (hN.map (algebraMap A K)).ne_zero
  exact hypL_pi1geo_of_field A K l he hl (allC1_constFieldU A K Fq he hq)
    (kumClosure_of_picDiv A hperf e l hN hPic)

include he hq in
/-- **`H²(π₁^geo(Ū), M) = 0`** for a finite `lⁿ`-torsion `π₁(U)`-module `M` with open kernel, given
`Pic(V̄)/l = 0` (`PicDivU`). -/
theorem h2_pi1geo_eq_zero (hperf : ∀ (P : Ideal A) [P.IsMaximal], PerfectField P.ResidueField)
    (l : ℕ) [Fact l.Prime] (hN : IsUnit (l : A)) (hPic : PicDivU A K p l)
    {k : Type*} [CommRing k] {M : Type u} [AddCommGroup M] [Module k M] (ρ : Representation k (Pi1 A K) M)
    (n : ℕ) [Finite M] (hM : ∀ m : M, (l ^ n) • m = 0) (hρ : IsOpen (ρ.ker : Set (Pi1 A K)))
    {f : pi1geo A K (p ^ e) × pi1geo A K (p ^ e) → M} (hf : IsLocallyConstant f)
    (hc : ∀ g h j : pi1geo A K (p ^ e), f (g * h, j) + f (g, h) = ρ g (f (h, j)) + f (g, h * j)) :
    ∃ b : pi1geo A K (p ^ e) → M, IsLocallyConstant b ∧
      ∀ g h : pi1geo A K (p ^ e), f (g, h) = ρ g (b h) - b (g * h) + b g :=
  h2_eq_zero ρ (pi1geo A K (p ^ e)) l (hypL_pi1geo_of_picDiv A Fq he hq hperf l hN hPic) n hM hρ hf hc

end

end RamanujanPetersson.CdOne

end
Source
J. S. Milne, Étale Cohomology, Princeton University Press (1980), Chapter V, §2 (Poincaré duality for curves); P. Deligne, Cohomologie étale (SGA 4½), Lecture Notes in Math. 569, Springer (1977), « Dualité »; J. S. Milne, Jacobian varieties, in Arithmetic Geometry (G. Cornell, J. H. Silverman, eds.), Springer (1986), 167-212; H. Stichtenoth, Algebraic Function Fields and Codes, 2nd ed., GTM 254, Springer (2009)

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me