Fermat's Last Theorem in Lean 4

โ† all definition modules

Definitions/Def_AutomorphicForm_GaussTwist.lean

definition module

Gauss-sum twisting data for adelic forms

Throughout, F is a number field with ring of integers \mathcal{O}_F, \mathfrak{f} an ideal of \mathcal{O}_F, and c_{\mathfrak{p}} = HeckeCharacter.idealMultiplicity F ๐”ญ ๐”ฃ, the multiplicity of \mathfrak{p} in the factorisation of \mathfrak{f}. The module assembles the vocabulary of a Gauss-sum combination of translates of a function on \mathrm{GL}_2 of the adeles. modulusPrimes F ๐”ฃ is the finite set of primes dividing \mathfrak{f}, empty for \mathfrak{f} = \bot (mem_modulusPrimes, modulusPrimes_bot). LocalGaussFactor F ๐”ฃ ๐”ญ is the unit group of \mathcal{O}_{\mathfrak{p}}/\mathfrak{m}_{\mathfrak{p}}^{c_{\mathfrak{p}}}, where \mathcal{O}_{\mathfrak{p}} is the valuation ring of the \mathfrak{p}-adic completion; GaussIndex F ๐”ฃ is the product of these over \mathfrak{p} \mid \mathfrak{f}, carrying the product commutative group structure, and shown finite. unitQuotLift is a chosen set-theoretic section of the (surjective) reduction A^{\times} \to (A/\mathfrak{m}^n)^{\times} for a local ring A; gaussRep F ๐”ฃ u applies it componentwise, lifting an index u to a family of local units. localUnif (and gaussUnif) is a chosen uniformiser of the completion, of valuation \exp(-1). For a family r of local units, unitIdele F ๐”ฃ r is the idele with archimedean component 1, component r_{\mathfrak{p}} at each \mathfrak{p} \mid \mathfrak{f} and 1 elsewhere; gaussUnitIdele F ๐”ฃ u is this for r = gaussRep F ๐”ฃ u, and gaussWt F ฮท ๐”ฃ u is the complex number \eta of that idele, for a character \eta of the idele group. gaussY F ๐”ฃ u is the family with value \tilde{u}_{\mathfrak{p}}\varpi_{\mathfrak{p}}^{-c_{\mathfrak{p}}} at \mathfrak{p} \mid \mathfrak{f} and 0 elsewhere; adeleOn turns such a family, cut off outside a finite set, into a finite adele; finPair/finLift embed a finite-adelic matrix, resp. element of \mathrm{GL}_2 of the finite adeles, into the adelic one with archimedean part the identity. Thus gaussTrans F ๐”ฃ u is the upper unipotent matrix \begin{pmatrix}1 & y_u\\ 0 & 1\end{pmatrix} with trivial archimedean part, and \mathtt{gaussSumFn}\,F\,\eta\,\mathfrak{f}\,\varphi\,(g) = \sum_{u} \eta(\tilde{u})\,\varphi(g\cdot \mathtt{gaussTrans}\,F\,\mathfrak{f}\,u), the sum over GaussIndex F ๐”ฃ (gaussSumFn_apply). Two results justify the construction: if \eta admits the modulus \mathfrak{f}, in the sense that \eta kills every unit idele with trivial archimedean part all of whose finite components u_v have valuation 1 and satisfy |u_v - 1| \le \exp(-c_v), then \eta(\mathtt{unitIdele}\,r) depends only on the reductions of r_{\mathfrak{p}} modulo \mathfrak{m}_{\mathfrak{p}}^{c_{\mathfrak{p}}} (eta_unitIdele_eq_of_mk_eq), so that gaussWt can be computed from any family of local units reducing to u (gaussWt_eq_of_mk_eq); in particular the weights do not depend on the chosen lifts. Auxiliary material, all of it private, records valuation estimates in the completions (units have valuation 1; membership in \mathfrak{m}^n forces valuation \le \exp(-n), hence congruent elements differ by valuation \le \exp(-n)), the componentwise behaviour of unitIdele and its inverse, and that the combination of the constant function 1 with trivial \eta has value the cardinality of the index group, which is nonzero.

Relation to Mathlib

Mathlib supplies the adele ring, the finite adele ring, the \mathfrak{p}-adic completions and their valuation rings, and \mathrm{GL}_2 of a ring; the Gauss-sum index group, unit ideles, unipotent translates and the Gauss-sum combination defined here are the project's own.

Where it is used

These objects provide the automorphic-side vocabulary for twisting a form on \mathrm{GL}_2 of the adeles of F by a finite-order Hecke character \eta of modulus \mathfrak{f}: the twisted vector is modelled as the Gauss-sum combination of unipotent translates weighted by \eta.

References

  1. D. Bump, Automorphic Forms and Representations, Cambridge Studies in Advanced Mathematics 55, Cambridge University Press, 1997
  2. A. Weil, Basic Number Theory, Grundlehren der mathematischen Wissenschaften 144, Springer, 1974

References are suggested automatically and have not been individually verified.

English text generated automatically from the Lean source; the Lean statement is authoritative.

Source file: Definitions/Def_AutomorphicForm_GaussTwist.lean

Imports

Imported by

  • no other definition module

Declarations

Source

import Definitions.Def_HeckeCharacter_FiniteOrder
import Definitions.Def_NumberField_AdelicLevel
import Definitions.Def_AutomorphicForm_ConstantTerm

set_option autoImplicit false
set_option maxSynthPendingDepth 3

noncomputable section

open NumberField IsDedekindDomain NumberField.AdelicLevel

namespace AutomorphicForm.GaussTwist

section LocalRing

variable (A : Type*) [CommRing A] [IsLocalRing A]

private theorem units_map_quotient_maximalIdeal_pow_surjective (n : โ„•) :
    Function.Surjective
      (Units.map (Ideal.Quotient.mk ((IsLocalRing.maximalIdeal A) ^ n)).toMonoidHom) := by
  rcases Nat.eq_zero_or_pos n with hn | hn
  ยท have hsub : Subsingleton (A โงธ (IsLocalRing.maximalIdeal A) ^ n) :=
      Ideal.Quotient.subsingleton_iff.mpr (by rw [hn, pow_zero, Ideal.one_eq_top])
    exact fun y => โŸจ1, Subsingleton.elim _ _โŸฉ
  ยท refine IsLocalRing.surjective_units_map_of_local_ringHom _ Ideal.Quotient.mk_surjective ?_
    refine isLocalHom_of_le_jacobson_bot _ ?_
    calc (IsLocalRing.maximalIdeal A) ^ n
        โ‰ค IsLocalRing.maximalIdeal A := Ideal.pow_le_self hn.ne'
      _ = Ideal.jacobson โŠฅ := (IsLocalRing.jacobson_eq_maximalIdeal โŠฅ bot_ne_top).symm

def unitQuotLift (n : โ„•) (x : (A โงธ (IsLocalRing.maximalIdeal A) ^ n)หฃ) : Aหฃ :=
  Function.surjInv (units_map_quotient_maximalIdeal_pow_surjective A n) x

private theorem unitQuotLift_spec (n : โ„•) (x : (A โงธ (IsLocalRing.maximalIdeal A) ^ n)หฃ) :
    Units.map (Ideal.Quotient.mk ((IsLocalRing.maximalIdeal A) ^ n)).toMonoidHom
      (unitQuotLift A n x) = x :=
  Function.surjInv_eq (units_map_quotient_maximalIdeal_pow_surjective A n) x

private theorem mk_coe_unitQuotLift (n : โ„•) (x : (A โงธ (IsLocalRing.maximalIdeal A) ^ n)หฃ) :
    Ideal.Quotient.mk ((IsLocalRing.maximalIdeal A) ^ n) (unitQuotLift A n x : A)
      = ((x : (A โงธ (IsLocalRing.maximalIdeal A) ^ n)หฃ) : A โงธ (IsLocalRing.maximalIdeal A) ^ n) :=
  congrArg Units.val (unitQuotLift_spec A n x)

end LocalRing

section Local

variable {R : Type*} (K : Type*) [CommRing R] [IsDedekindDomain R] [Field K] [Algebra R K]
  [IsFractionRing R K] (v : HeightOneSpectrum R)

def localUnif : v.adicCompletion K := ((v.valuation_exists_uniformizer K).choose : K)

private theorem valued_localUnif : Valued.v (localUnif K v) = WithZero.exp (-1 : โ„ค) := by
  unfold localUnif
  rw [HeightOneSpectrum.valuedAdicCompletion_eq_valuation']
  exact (v.valuation_exists_uniformizer K).choose_spec

private theorem integers_adicCompletionIntegers :
    (Valued.v : Valuation (v.adicCompletion K) (WithZero (Multiplicative โ„ค))).Integers
      (v.adicCompletionIntegers K) :=
  Valuation.valuationSubring.integers _

private theorem valued_coe_eq_one_of_isUnit {x : v.adicCompletionIntegers K} (hx : IsUnit x) :
    Valued.v ((x : v.adicCompletionIntegers K) : v.adicCompletion K) = 1 :=
  (integers_adicCompletionIntegers K v).one_of_isUnit hx

private theorem isUnit_of_valued_coe_eq_one {x : v.adicCompletionIntegers K}
    (hx : Valued.v ((x : v.adicCompletionIntegers K) : v.adicCompletion K) = 1) : IsUnit x :=
  (integers_adicCompletionIntegers K v).isUnit_of_one' hx

private theorem valued_units_coe (r : (v.adicCompletionIntegers K)หฃ) :
    Valued.v (((r : v.adicCompletionIntegers K) : v.adicCompletion K)) = 1 :=
  valued_coe_eq_one_of_isUnit K v r.isUnit

private theorem le_exp_neg_one_of_lt_one {ฮณ : WithZero (Multiplicative โ„ค)} (h : ฮณ < 1) :
    ฮณ โ‰ค WithZero.exp (-1 : โ„ค) := by
  rcases eq_or_ne ฮณ 0 with rfl | h0
  ยท exact zero_le'
  ยท obtain โŸจm, hmโŸฉ : โˆƒ m : โ„ค, ฮณ = WithZero.exp m := โŸจWithZero.log ฮณ, (WithZero.exp_log h0).symmโŸฉ
    subst hm
    rw [โ† WithZero.exp_zero, WithZero.exp_lt_exp] at h
    exact WithZero.exp_le_exp.mpr (by omega)

private theorem valued_coe_le_exp_neg_one_of_mem_maximalIdeal {x : v.adicCompletionIntegers K}
    (hx : x โˆˆ IsLocalRing.maximalIdeal (v.adicCompletionIntegers K)) :
    Valued.v ((x : v.adicCompletionIntegers K) : v.adicCompletion K) โ‰ค WithZero.exp (-1 : โ„ค) := by
  refine le_exp_neg_one_of_lt_one (lt_of_le_of_ne
    ((HeightOneSpectrum.mem_adicCompletionIntegers R K v).mp x.2) fun h => ?_)
  exact (mem_nonunits_iff.mp ((IsLocalRing.mem_maximalIdeal x).mp hx))
    (isUnit_of_valued_coe_eq_one K v h)

private theorem valued_coe_le_exp_neg_of_mem_maximalIdeal_pow {n : โ„•} {x : v.adicCompletionIntegers K}
    (hx : x โˆˆ (IsLocalRing.maximalIdeal (v.adicCompletionIntegers K)) ^ n) :
    Valued.v ((x : v.adicCompletionIntegers K) : v.adicCompletion K)
      โ‰ค WithZero.exp (-(n : โ„ค)) := by
  induction n generalizing x with
  | zero =>
      rw [Nat.cast_zero, neg_zero, WithZero.exp_zero]
      exact (HeightOneSpectrum.mem_adicCompletionIntegers R K v).mp x.2
  | succ n ih =>
      rw [pow_succ] at hx
      refine Submodule.mul_induction_on hx (fun m hm y hy => ?_) (fun y z hy hz => ?_)
      ยท rw [show ((m * y : v.adicCompletionIntegers K) : v.adicCompletion K)
            = (m : v.adicCompletion K) * y from rfl, map_mul, Nat.cast_succ, neg_add,
          WithZero.exp_add]
        exact mul_le_mul' (ih hm) (valued_coe_le_exp_neg_one_of_mem_maximalIdeal K v hy)
      ยท rw [show ((y + z : v.adicCompletionIntegers K) : v.adicCompletion K)
            = (y : v.adicCompletion K) + z from rfl]
        exact Valuation.map_add_le _ hy hz

private theorem valued_coe_sub_le_of_mk_eq {n : โ„•} {x y : v.adicCompletionIntegers K}
    (h : Ideal.Quotient.mk ((IsLocalRing.maximalIdeal (v.adicCompletionIntegers K)) ^ n) x
      = Ideal.Quotient.mk ((IsLocalRing.maximalIdeal (v.adicCompletionIntegers K)) ^ n) y) :
    Valued.v ((x : v.adicCompletion K) - y) โ‰ค WithZero.exp (-(n : โ„ค)) := by
  have h' := valued_coe_le_exp_neg_of_mem_maximalIdeal_pow K v (Ideal.Quotient.eq.mp h)
  rwa [AddSubgroupClass.coe_sub] at h'

end Local

section Adelic

variable {R K : Type*} [CommRing R] [IsDedekindDomain R] [Field K] [Algebra R K]
  [IsFractionRing R K]

def adeleOn (S : Finset (HeightOneSpectrum R)) [DecidablePred (ยท โˆˆ S)]
    (y : (w : HeightOneSpectrum R) โ†’ w.adicCompletion K) : FiniteAdeleRing R K :=
  โŸจfun w => if w โˆˆ S then y w else 0,
    S.eventually_cofinite_notMem.mono fun w hw => by
      dsimp only
      rw [if_neg hw]
      exact (w.adicCompletionIntegers K).zero_memโŸฉ

private theorem adeleOn_apply (S : Finset (HeightOneSpectrum R)) [DecidablePred (ยท โˆˆ S)]
    (y : (w : HeightOneSpectrum R) โ†’ w.adicCompletion K) (w : HeightOneSpectrum R) :
    adeleOn S y w = if w โˆˆ S then y w else 0 := rfl

private theorem adeleOn_apply_of_mem (S : Finset (HeightOneSpectrum R)) [DecidablePred (ยท โˆˆ S)]
    (y : (w : HeightOneSpectrum R) โ†’ w.adicCompletion K) {w : HeightOneSpectrum R} (hw : w โˆˆ S) :
    adeleOn S y w = y w := by
  rw [adeleOn_apply, if_pos hw]

private theorem adeleOn_apply_of_not_mem (S : Finset (HeightOneSpectrum R)) [DecidablePred (ยท โˆˆ S)]
    (y : (w : HeightOneSpectrum R) โ†’ w.adicCompletion K) {w : HeightOneSpectrum R}
    (hw : w โˆ‰ S) : adeleOn S y w = 0 := by
  rw [adeleOn_apply, if_neg hw]

private theorem matrix_eq_of_parts {M M' : Matrix (Fin 2) (Fin 2) (AdeleRing R K)}
    (ha : (adeleArch R K).mapMatrix M = (adeleArch R K).mapMatrix M')
    (hf : (adeleFin R K).mapMatrix M = (adeleFin R K).mapMatrix M') : M = M' := by
  ext i j
  exact Prod.ext (congrFun (congrFun ha i) j) (congrFun (congrFun hf i) j)

def finPair (m : Matrix (Fin 2) (Fin 2) (FiniteAdeleRing R K)) :
    Matrix (Fin 2) (Fin 2) (AdeleRing R K) :=
  Matrix.of fun i j =>
    (((1 : Matrix (Fin 2) (Fin 2) (InfiniteAdeleRing K)) i j, m i j) : AdeleRing R K)

private theorem mapMatrix_adeleArch_finPair (m : Matrix (Fin 2) (Fin 2) (FiniteAdeleRing R K)) :
    (adeleArch R K).mapMatrix (finPair m) = 1 := by
  ext i j
  rfl

private theorem mapMatrix_adeleFin_finPair (m : Matrix (Fin 2) (Fin 2) (FiniteAdeleRing R K)) :
    (adeleFin R K).mapMatrix (finPair m) = m := by
  ext i j
  rfl

private theorem finPair_one : finPair (R := R) (K := K) 1 = 1 :=
  matrix_eq_of_parts (by rw [mapMatrix_adeleArch_finPair, map_one])
    (by rw [mapMatrix_adeleFin_finPair, map_one])

private theorem finPair_mul (m m' : Matrix (Fin 2) (Fin 2) (FiniteAdeleRing R K)) :
    finPair m * finPair m' = finPair (m * m') :=
  matrix_eq_of_parts
    (by rw [map_mul, mapMatrix_adeleArch_finPair, mapMatrix_adeleArch_finPair,
      mapMatrix_adeleArch_finPair, mul_one])
    (by rw [map_mul, mapMatrix_adeleFin_finPair, mapMatrix_adeleFin_finPair,
      mapMatrix_adeleFin_finPair])

def finLift (g : GL (Fin 2) (FiniteAdeleRing R K)) : GL (Fin 2) (AdeleRing R K) where
  val := finPair (g : Matrix (Fin 2) (Fin 2) (FiniteAdeleRing R K))
  inv := finPair
    ((gโปยน : GL (Fin 2) (FiniteAdeleRing R K)) : Matrix (Fin 2) (Fin 2) (FiniteAdeleRing R K))
  val_inv := by rw [finPair_mul, Units.mul_inv, finPair_one]
  inv_val := by rw [finPair_mul, Units.inv_mul, finPair_one]

private theorem glArch_finLift (g : GL (Fin 2) (FiniteAdeleRing R K)) : glArch R K (finLift g) = 1 := by
  ext i j
  rw [Units.val_one]
  rfl

private theorem glFin_finLift (g : GL (Fin 2) (FiniteAdeleRing R K)) : glFin R K (finLift g) = g := by
  ext i j
  rfl

private theorem coe_prod_apply_of_units {ฮน : Type*} (s : Finset ฮน)
    (f : ฮน โ†’ (FiniteAdeleRing R K)หฃ) (w : HeightOneSpectrum R) :
    ((โˆ i โˆˆ s, f i : (FiniteAdeleRing R K)หฃ) : FiniteAdeleRing R K) w
      = โˆ i โˆˆ s, (((f i : (FiniteAdeleRing R K)หฃ) : FiniteAdeleRing R K) w) := by
  classical
  induction s using Finset.cons_induction with
  | empty => simp [coe_one_apply]
  | cons a s ha ih => simp only [Finset.prod_cons, Units.val_mul, coe_mul_apply, ih]

end Adelic

section Gauss

variable (F : Type) [Field F] [NumberField F]

open scoped Classical

def modulusPrimes (๐”ฃ : Ideal (๐“ž F)) : Finset (HeightOneSpectrum (๐“ž F)) :=
  if h : ๐”ฃ = โŠฅ then โˆ… else (Ideal.finite_factors (fun h' => h h')).toFinset

theorem mem_modulusPrimes {๐”ฃ : Ideal (๐“ž F)} (h๐”ฃ : ๐”ฃ โ‰  โŠฅ) (v : HeightOneSpectrum (๐“ž F)) :
    v โˆˆ modulusPrimes F ๐”ฃ โ†” v.asIdeal โˆฃ ๐”ฃ := by
  rw [modulusPrimes, dif_neg h๐”ฃ, Set.Finite.mem_toFinset, Set.mem_setOf_eq]

theorem modulusPrimes_bot : modulusPrimes F โŠฅ = โˆ… := by
  rw [modulusPrimes, dif_pos rfl]

abbrev LocalGaussFactor (๐”ฃ : Ideal (๐“ž F)) (๐”ญ : HeightOneSpectrum (๐“ž F)) : Type :=
  ((๐”ญ.adicCompletionIntegers F) โงธ
    (IsLocalRing.maximalIdeal (๐”ญ.adicCompletionIntegers F))
      ^ (HeckeCharacter.idealMultiplicity F ๐”ญ ๐”ฃ))หฃ

def GaussIndex (๐”ฃ : Ideal (๐“ž F)) : Type :=
  โˆ€ ๐”ญ : modulusPrimes F ๐”ฃ, LocalGaussFactor F ๐”ฃ ๐”ญ.1

instance (๐”ฃ : Ideal (๐“ž F)) : CommGroup (GaussIndex F ๐”ฃ) := Pi.commGroup

instance (๐”ฃ : Ideal (๐“ž F)) (๐”ญ : modulusPrimes F ๐”ฃ) : Finite (LocalGaussFactor F ๐”ฃ ๐”ญ.1) := by
  have : Finite ((๐”ญ.1.adicCompletionIntegers F) โงธ
      (IsLocalRing.maximalIdeal (๐”ญ.1.adicCompletionIntegers F))
        ^ (HeckeCharacter.idealMultiplicity F ๐”ญ.1 ๐”ฃ)) :=
    IsLocalRing.isOpen_iff_finite_quotient.mp
      (IsLocalRing.isOpen_maximalIdeal_pow (๐”ญ.1.adicCompletionIntegers F) _)
  exact instFiniteUnits

instance (๐”ฃ : Ideal (๐“ž F)) : Fintype (GaussIndex F ๐”ฃ) := by
  have : Finite (GaussIndex F ๐”ฃ) := Pi.finite
  exact Fintype.ofFinite _

noncomputable def gaussRep (๐”ฃ : Ideal (๐“ž F)) (u : GaussIndex F ๐”ฃ)
    (๐”ญ : modulusPrimes F ๐”ฃ) : (๐”ญ.1.adicCompletionIntegers F)หฃ :=
  unitQuotLift (๐”ญ.1.adicCompletionIntegers F)
    (HeckeCharacter.idealMultiplicity F ๐”ญ.1 ๐”ฃ) (u ๐”ญ)

private theorem mk_coe_gaussRep (๐”ฃ : Ideal (๐“ž F)) (u : GaussIndex F ๐”ฃ) (๐”ญ : modulusPrimes F ๐”ฃ) :
    Ideal.Quotient.mk ((IsLocalRing.maximalIdeal (๐”ญ.1.adicCompletionIntegers F))
        ^ (HeckeCharacter.idealMultiplicity F ๐”ญ.1 ๐”ฃ))
      ((gaussRep F ๐”ฃ u ๐”ญ : (๐”ญ.1.adicCompletionIntegers F)หฃ) : ๐”ญ.1.adicCompletionIntegers F)
    = ((u ๐”ญ : LocalGaussFactor F ๐”ฃ ๐”ญ.1) : ๐”ญ.1.adicCompletionIntegers F
        โงธ (IsLocalRing.maximalIdeal (๐”ญ.1.adicCompletionIntegers F))
          ^ (HeckeCharacter.idealMultiplicity F ๐”ญ.1 ๐”ฃ)) :=
  mk_coe_unitQuotLift _ _ (u ๐”ญ)

noncomputable def gaussUnif (๐”ญ : HeightOneSpectrum (๐“ž F)) : ๐”ญ.adicCompletion F :=
  localUnif F ๐”ญ

noncomputable def gaussY (๐”ฃ : Ideal (๐“ž F)) (u : GaussIndex F ๐”ฃ)
    (๐”ญ : HeightOneSpectrum (๐“ž F)) : ๐”ญ.adicCompletion F :=
  if h : ๐”ญ โˆˆ modulusPrimes F ๐”ฃ then
    ((gaussRep F ๐”ฃ u โŸจ๐”ญ, hโŸฉ : ๐”ญ.adicCompletionIntegers F) : ๐”ญ.adicCompletion F)
      * (gaussUnif F ๐”ญ)โปยน ^ (HeckeCharacter.idealMultiplicity F ๐”ญ ๐”ฃ)
  else 0

def unitIdele (๐”ฃ : Ideal (๐“ž F))
    (r : โˆ€ ๐”ญ : modulusPrimes F ๐”ฃ, (๐”ญ.1.adicCompletionIntegers F)หฃ) : (AdeleRing (๐“ž F) F)หฃ :=
  Units.map (finIncl (๐“ž F) F) (โˆ ๐”ญ : modulusPrimes F ๐”ฃ, localUnit (๐“ž F) F ๐”ญ.1
    โŸจ(r ๐”ญ : ๐”ญ.1.adicCompletionIntegers F), (r ๐”ญ)โปยน, by simp, by simpโŸฉ)

def gaussUnitIdele (๐”ฃ : Ideal (๐“ž F)) (u : GaussIndex F ๐”ฃ) : (AdeleRing (๐“ž F) F)หฃ :=
  Units.map (finIncl (๐“ž F) F) (โˆ ๐”ญ : modulusPrimes F ๐”ฃ, localUnit (๐“ž F) F ๐”ญ.1
    โŸจ(gaussRep F ๐”ฃ u ๐”ญ : ๐”ญ.1.adicCompletionIntegers F),
     (gaussRep F ๐”ฃ u ๐”ญ)โปยน, by simp, by simpโŸฉ)

private theorem gaussUnitIdele_eq (๐”ฃ : Ideal (๐“ž F)) (u : GaussIndex F ๐”ฃ) :
    gaussUnitIdele F ๐”ฃ u = unitIdele F ๐”ฃ (gaussRep F ๐”ฃ u) := rfl

def gaussWt (ฮท : (AdeleRing (๐“ž F) F)หฃ โ†’* โ„‚หฃ) (๐”ฃ : Ideal (๐“ž F)) (u : GaussIndex F ๐”ฃ) : โ„‚ :=
  ((ฮท (gaussUnitIdele F ๐”ฃ u) : โ„‚หฃ) : โ„‚)

def gaussTrans (๐”ฃ : Ideal (๐“ž F)) (u : GaussIndex F ๐”ฃ) : AdelicGL2 (๐“ž F) F :=
  finLift (unipotentGL2 (adeleOn (modulusPrimes F ๐”ฃ) (gaussY F ๐”ฃ u)))

def gaussSumFn (ฮท : (AdeleRing (๐“ž F) F)หฃ โ†’* โ„‚หฃ) (๐”ฃ : Ideal (๐“ž F))
    (ฯ† : AdelicGL2 (๐“ž F) F โ†’ โ„‚) : AdelicGL2 (๐“ž F) F โ†’ โ„‚ :=
  fun g => โˆ‘ u : GaussIndex F ๐”ฃ, gaussWt F ฮท ๐”ฃ u * ฯ† (g * gaussTrans F ๐”ฃ u)

theorem gaussSumFn_apply (ฮท : (AdeleRing (๐“ž F) F)หฃ โ†’* โ„‚หฃ) (๐”ฃ : Ideal (๐“ž F))
    (ฯ† : AdelicGL2 (๐“ž F) F โ†’ โ„‚) (g : AdelicGL2 (๐“ž F) F) :
    gaussSumFn F ฮท ๐”ฃ ฯ† g = โˆ‘ u : GaussIndex F ๐”ฃ, gaussWt F ฮท ๐”ฃ u * ฯ† (g * gaussTrans F ๐”ฃ u) :=
  rfl

private theorem unitIdele_fst (๐”ฃ : Ideal (๐“ž F))
    (r : โˆ€ ๐”ญ : modulusPrimes F ๐”ฃ, (๐”ญ.1.adicCompletionIntegers F)หฃ) :
    ((unitIdele F ๐”ฃ r : (AdeleRing (๐“ž F) F)หฃ) : AdeleRing (๐“ž F) F).1 = 1 := by
  rw [unitIdele, Units.coe_map]; exact finIncl_apply_fst (๐“ž F) F _

private theorem unitIdele_inv_fst (๐”ฃ : Ideal (๐“ž F))
    (r : โˆ€ ๐”ญ : modulusPrimes F ๐”ฃ, (๐”ญ.1.adicCompletionIntegers F)หฃ) :
    (((unitIdele F ๐”ฃ r)โปยน : (AdeleRing (๐“ž F) F)หฃ) : AdeleRing (๐“ž F) F).1 = 1 := by
  rw [unitIdele, โ† map_inv, Units.coe_map]; exact finIncl_apply_fst (๐“ž F) F _

private theorem unitIdele_snd_apply_of_not_mem (๐”ฃ : Ideal (๐“ž F))
    (r : โˆ€ ๐”ญ : modulusPrimes F ๐”ฃ, (๐”ญ.1.adicCompletionIntegers F)หฃ)
    {w : HeightOneSpectrum (๐“ž F)} (hw : w โˆ‰ modulusPrimes F ๐”ฃ) :
    ((unitIdele F ๐”ฃ r : (AdeleRing (๐“ž F) F)หฃ) : AdeleRing (๐“ž F) F).2 w = 1 := by
  rw [unitIdele, Units.coe_map, finIncl_apply_snd, coe_prod_apply_of_units]
  exact Finset.prod_eq_one fun ๐”ญ _ =>
    localUnit_apply_of_ne (๐“ž F) F ๐”ญ.1 _ (fun h => hw (h โ–ธ ๐”ญ.2))

private theorem unitIdele_snd_apply_of_mem (๐”ฃ : Ideal (๐“ž F))
    (r : โˆ€ ๐”ญ : modulusPrimes F ๐”ฃ, (๐”ญ.1.adicCompletionIntegers F)หฃ)
    {๐”ญ : HeightOneSpectrum (๐“ž F)} (h๐”ญ : ๐”ญ โˆˆ modulusPrimes F ๐”ฃ) :
    ((unitIdele F ๐”ฃ r : (AdeleRing (๐“ž F) F)หฃ) : AdeleRing (๐“ž F) F).2 ๐”ญ
      = (((r โŸจ๐”ญ, h๐”ญโŸฉ : (๐”ญ.adicCompletionIntegers F)หฃ)
            : ๐”ญ.adicCompletionIntegers F) : ๐”ญ.adicCompletion F) := by
  rw [unitIdele, Units.coe_map, finIncl_apply_snd, coe_prod_apply_of_units]
  refine (Finset.prod_eq_single (โŸจ๐”ญ, h๐”ญโŸฉ : modulusPrimes F ๐”ฃ)
    (fun ๐”ฎ _ h๐”ฎ => localUnit_apply_of_ne (๐“ž F) F ๐”ฎ.1 _ ?_)
    (fun h => absurd (Finset.mem_univ _) h)).trans ?_
  ยท exact fun h => h๐”ฎ (Subtype.ext h.symm)
  ยท exact localUnit_apply_self (๐“ž F) F ๐”ญ _

private theorem valued_unitIdele_snd_apply (๐”ฃ : Ideal (๐“ž F))
    (r : โˆ€ ๐”ญ : modulusPrimes F ๐”ฃ, (๐”ญ.1.adicCompletionIntegers F)หฃ)
    (w : HeightOneSpectrum (๐“ž F)) :
    Valued.v (((unitIdele F ๐”ฃ r : (AdeleRing (๐“ž F) F)หฃ) : AdeleRing (๐“ž F) F).2 w) = 1 := by
  by_cases hw : w โˆˆ modulusPrimes F ๐”ฃ
  ยท rw [unitIdele_snd_apply_of_mem F ๐”ฃ r hw]
    exact valued_units_coe F w (r โŸจw, hwโŸฉ)
  ยท rw [unitIdele_snd_apply_of_not_mem F ๐”ฃ r hw]; exact map_one _

private theorem inv_snd_apply_mul_snd_apply (x : (AdeleRing (๐“ž F) F)หฃ) (w : HeightOneSpectrum (๐“ž F)) :
    ((xโปยน : (AdeleRing (๐“ž F) F)หฃ) : AdeleRing (๐“ž F) F).2 w * (x : AdeleRing (๐“ž F) F).2 w = 1 := by
  have h : ((xโปยน : (AdeleRing (๐“ž F) F)หฃ) : AdeleRing (๐“ž F) F) * (x : AdeleRing (๐“ž F) F) = 1 :=
    x.inv_mul
  calc ((xโปยน : (AdeleRing (๐“ž F) F)หฃ) : AdeleRing (๐“ž F) F).2 w * (x : AdeleRing (๐“ž F) F).2 w
      = (((xโปยน : (AdeleRing (๐“ž F) F)หฃ) : AdeleRing (๐“ž F) F) * (x : AdeleRing (๐“ž F) F)).2 w := rfl
    _ = (1 : AdeleRing (๐“ž F) F).2 w := by rw [h]
    _ = 1 := rfl

private theorem valued_unitIdele_inv_snd_apply (๐”ฃ : Ideal (๐“ž F))
    (r : โˆ€ ๐”ญ : modulusPrimes F ๐”ฃ, (๐”ญ.1.adicCompletionIntegers F)หฃ)
    (w : HeightOneSpectrum (๐“ž F)) :
    Valued.v ((((unitIdele F ๐”ฃ r)โปยน : (AdeleRing (๐“ž F) F)หฃ) : AdeleRing (๐“ž F) F).2 w) = 1 := by
  have h := congrArg Valued.v (inv_snd_apply_mul_snd_apply F (unitIdele F ๐”ฃ r) w)
  rwa [map_mul, valued_unitIdele_snd_apply, mul_one, map_one] at h

private theorem unitIdele_inv_snd_apply_of_not_mem (๐”ฃ : Ideal (๐“ž F))
    (r : โˆ€ ๐”ญ : modulusPrimes F ๐”ฃ, (๐”ญ.1.adicCompletionIntegers F)หฃ)
    {w : HeightOneSpectrum (๐“ž F)} (hw : w โˆ‰ modulusPrimes F ๐”ฃ) :
    (((unitIdele F ๐”ฃ r)โปยน : (AdeleRing (๐“ž F) F)หฃ) : AdeleRing (๐“ž F) F).2 w = 1 := by
  have h := inv_snd_apply_mul_snd_apply F (unitIdele F ๐”ฃ r) w
  rwa [unitIdele_snd_apply_of_not_mem F ๐”ฃ r hw, mul_one] at h

private theorem unitIdele_inv_snd_apply_of_mem (๐”ฃ : Ideal (๐“ž F))
    (r : โˆ€ ๐”ญ : modulusPrimes F ๐”ฃ, (๐”ญ.1.adicCompletionIntegers F)หฃ)
    {๐”ญ : HeightOneSpectrum (๐“ž F)} (h๐”ญ : ๐”ญ โˆˆ modulusPrimes F ๐”ฃ) :
    (((unitIdele F ๐”ฃ r)โปยน : (AdeleRing (๐“ž F) F)หฃ) : AdeleRing (๐“ž F) F).2 ๐”ญ
      = ((((r โŸจ๐”ญ, h๐”ญโŸฉ : (๐”ญ.adicCompletionIntegers F)หฃ)
            : ๐”ญ.adicCompletionIntegers F) : ๐”ญ.adicCompletion F))โปยน := by
  have h := inv_snd_apply_mul_snd_apply F (unitIdele F ๐”ฃ r) ๐”ญ
  rw [unitIdele_snd_apply_of_mem F ๐”ฃ r h๐”ญ] at h
  exact eq_inv_of_mul_eq_one_left h

theorem eta_unitIdele_eq_of_mk_eq (ฮท : (AdeleRing (๐“ž F) F)หฃ โ†’* โ„‚หฃ) (๐”ฃ : Ideal (๐“ž F))
    (hmod : HeckeCharacter.AdmitsModulus F ฮท ๐”ฃ)
    {r r' : โˆ€ ๐”ญ : modulusPrimes F ๐”ฃ, (๐”ญ.1.adicCompletionIntegers F)หฃ}
    (h : โˆ€ ๐”ญ : modulusPrimes F ๐”ฃ,
      Ideal.Quotient.mk ((IsLocalRing.maximalIdeal (๐”ญ.1.adicCompletionIntegers F))
          ^ (HeckeCharacter.idealMultiplicity F ๐”ญ.1 ๐”ฃ))
        ((r ๐”ญ : (๐”ญ.1.adicCompletionIntegers F)หฃ) : ๐”ญ.1.adicCompletionIntegers F)
      = Ideal.Quotient.mk ((IsLocalRing.maximalIdeal (๐”ญ.1.adicCompletionIntegers F))
          ^ (HeckeCharacter.idealMultiplicity F ๐”ญ.1 ๐”ฃ))
        ((r' ๐”ญ : (๐”ญ.1.adicCompletionIntegers F)หฃ) : ๐”ญ.1.adicCompletionIntegers F)) :
    ฮท (unitIdele F ๐”ฃ r) = ฮท (unitIdele F ๐”ฃ r') := by

  have hsnd : โˆ€ w : HeightOneSpectrum (๐“ž F),
      ((unitIdele F ๐”ฃ r * (unitIdele F ๐”ฃ r')โปยน : (AdeleRing (๐“ž F) F)หฃ) : AdeleRing (๐“ž F) F).2 w
        = ((unitIdele F ๐”ฃ r : (AdeleRing (๐“ž F) F)หฃ) : AdeleRing (๐“ž F) F).2 w
          * (((unitIdele F ๐”ฃ r')โปยน : (AdeleRing (๐“ž F) F)หฃ) : AdeleRing (๐“ž F) F).2 w :=
    fun _ => rfl
  have harch : ((unitIdele F ๐”ฃ r * (unitIdele F ๐”ฃ r')โปยน : (AdeleRing (๐“ž F) F)หฃ)
      : AdeleRing (๐“ž F) F).1 = 1 := by
    have e : ((unitIdele F ๐”ฃ r * (unitIdele F ๐”ฃ r')โปยน : (AdeleRing (๐“ž F) F)หฃ)
          : AdeleRing (๐“ž F) F).1
        = ((unitIdele F ๐”ฃ r : (AdeleRing (๐“ž F) F)หฃ) : AdeleRing (๐“ž F) F).1
          * (((unitIdele F ๐”ฃ r')โปยน : (AdeleRing (๐“ž F) F)หฃ) : AdeleRing (๐“ž F) F).1 := rfl
    rw [e, unitIdele_fst, unitIdele_inv_fst, mul_one]
  have hunit : โˆ€ w : HeightOneSpectrum (๐“ž F),
      Valued.v (((unitIdele F ๐”ฃ r * (unitIdele F ๐”ฃ r')โปยน : (AdeleRing (๐“ž F) F)หฃ)
        : AdeleRing (๐“ž F) F).2 w) = 1 := fun w => by
    rw [hsnd, map_mul, valued_unitIdele_snd_apply, valued_unitIdele_inv_snd_apply, mul_one]
  have hcong : โˆ€ w : HeightOneSpectrum (๐“ž F),
      Valued.v (((unitIdele F ๐”ฃ r * (unitIdele F ๐”ฃ r')โปยน : (AdeleRing (๐“ž F) F)หฃ)
          : AdeleRing (๐“ž F) F).2 w - 1)
        โ‰ค WithZero.exp (-(HeckeCharacter.idealMultiplicity F w ๐”ฃ : โ„ค)) := fun w => by
    rw [hsnd]
    by_cases hw : w โˆˆ modulusPrimes F ๐”ฃ
    ยท rw [unitIdele_snd_apply_of_mem F ๐”ฃ r hw, unitIdele_inv_snd_apply_of_mem F ๐”ฃ r' hw]
      have hy : Valued.v (((r' โŸจw, hwโŸฉ : (w.adicCompletionIntegers F)หฃ)
          : w.adicCompletionIntegers F) : w.adicCompletion F) = 1 := valued_units_coe F w _
      have hy0 : (((r' โŸจw, hwโŸฉ : (w.adicCompletionIntegers F)หฃ)
          : w.adicCompletionIntegers F) : w.adicCompletion F) โ‰  0 :=
        (Valuation.ne_zero_iff _).mp (by rw [hy]; exact one_ne_zero)
      rw [show (((r โŸจw, hwโŸฉ : (w.adicCompletionIntegers F)หฃ) : w.adicCompletionIntegers F)
            : w.adicCompletion F)
          * ((((r' โŸจw, hwโŸฉ : (w.adicCompletionIntegers F)หฃ) : w.adicCompletionIntegers F)
            : w.adicCompletion F))โปยน - 1
        = ((((r โŸจw, hwโŸฉ : (w.adicCompletionIntegers F)หฃ) : w.adicCompletionIntegers F)
            : w.adicCompletion F)
          - (((r' โŸจw, hwโŸฉ : (w.adicCompletionIntegers F)หฃ) : w.adicCompletionIntegers F)
            : w.adicCompletion F))
          * ((((r' โŸจw, hwโŸฉ : (w.adicCompletionIntegers F)หฃ) : w.adicCompletionIntegers F)
            : w.adicCompletion F))โปยน from by rw [sub_mul, mul_inv_cancelโ‚€ hy0],
        map_mul, map_invโ‚€, hy, inv_one, mul_one]
      exact valued_coe_sub_le_of_mk_eq F w (h โŸจw, hwโŸฉ)
    ยท rw [unitIdele_snd_apply_of_not_mem F ๐”ฃ r hw, unitIdele_inv_snd_apply_of_not_mem F ๐”ฃ r' hw,
        mul_one, sub_self, map_zero]
      exact zero_le'
  have hฮท : ฮท (unitIdele F ๐”ฃ r * (unitIdele F ๐”ฃ r')โปยน) = 1 :=
    hmod _ harch fun w => โŸจhunit w, hcong wโŸฉ
  rwa [map_mul, map_inv, mul_inv_eq_one] at hฮท

theorem gaussWt_eq_of_mk_eq (ฮท : (AdeleRing (๐“ž F) F)หฃ โ†’* โ„‚หฃ) (๐”ฃ : Ideal (๐“ž F))
    (hmod : HeckeCharacter.AdmitsModulus F ฮท ๐”ฃ) (u : GaussIndex F ๐”ฃ)
    (r : โˆ€ ๐”ญ : modulusPrimes F ๐”ฃ, (๐”ญ.1.adicCompletionIntegers F)หฃ)
    (hr : โˆ€ ๐”ญ : modulusPrimes F ๐”ฃ,
      Ideal.Quotient.mk ((IsLocalRing.maximalIdeal (๐”ญ.1.adicCompletionIntegers F))
          ^ (HeckeCharacter.idealMultiplicity F ๐”ญ.1 ๐”ฃ))
        ((r ๐”ญ : (๐”ญ.1.adicCompletionIntegers F)หฃ) : ๐”ญ.1.adicCompletionIntegers F)
      = ((u ๐”ญ : LocalGaussFactor F ๐”ฃ ๐”ญ.1) : ๐”ญ.1.adicCompletionIntegers F
          โงธ (IsLocalRing.maximalIdeal (๐”ญ.1.adicCompletionIntegers F))
            ^ (HeckeCharacter.idealMultiplicity F ๐”ญ.1 ๐”ฃ))) :
    gaussWt F ฮท ๐”ฃ u = ((ฮท (unitIdele F ๐”ฃ r) : โ„‚หฃ) : โ„‚) := by
  unfold gaussWt
  rw [gaussUnitIdele_eq]
  congr 1
  exact eta_unitIdele_eq_of_mk_eq F ฮท ๐”ฃ hmod fun ๐”ญ => (mk_coe_gaussRep F ๐”ฃ u ๐”ญ).trans (hr ๐”ญ).symm

private theorem gaussSumFn_one_const (๐”ฃ : Ideal (๐“ž F)) (g : AdelicGL2 (๐“ž F) F) :
    gaussSumFn F 1 ๐”ฃ (fun _ => 1) g = (Fintype.card (GaussIndex F ๐”ฃ) : โ„‚) := by
  simp [gaussSumFn, gaussWt]

private theorem gaussSumFn_one_const_ne_zero (๐”ฃ : Ideal (๐“ž F)) (g : AdelicGL2 (๐“ž F) F) :
    gaussSumFn F 1 ๐”ฃ (fun _ => 1) g โ‰  0 := by
  haveI : Nonempty (GaussIndex F ๐”ฃ) := โŸจ1โŸฉ
  rw [gaussSumFn_one_const]
  exact_mod_cast Fintype.card_ne_zero

end Gauss

end AutomorphicForm.GaussTwist

Statements phrased using this module (5)