source stringlengths 17 118 | lean4 stringlengths 0 335k |
|---|---|
.lake/packages/mathlib/Mathlib/NumberTheory/ModularForms/DedekindEta.lean | import Mathlib.Analysis.Complex.LocallyUniformLimit
import Mathlib.Analysis.Complex.UpperHalfPlane.Exp
import Mathlib.Analysis.NormedSpace.MultipliableUniformlyOn
/-!
# Dedekind eta function
## Main definitions
* We define the Dedekind eta function as the infinite product
`η(z) = q ^ 1/24 * ∏' (1 - q ^ (n + 1))` where `q = e ^ (2πiz)` and `z` is in the upper half-plane.
The product is taken over all non-negative integers `n`. We then show it is non-vanishing and
differentiable on the upper half-plane.
## References
* [F. Diamond and J. Shurman, *A First Course in Modular Forms*][diamondshurman2005], section 1.2
-/
open TopologicalSpace Set MeasureTheory intervalIntegral
Metric Filter Function Complex
open UpperHalfPlane hiding I
open scoped Interval Real NNReal ENNReal Topology BigOperators Nat
local notation "𝕢" => Periodic.qParam
local notation "ℍₒ" => upperHalfPlaneSet
namespace ModularForm
/-- The q term inside the product defining the eta function. It is defined as
`eta_q n z = e ^ (2 π i (n + 1) z)`. -/
noncomputable abbrev eta_q (n : ℕ) (z : ℂ) := (𝕢 1 z) ^ (n + 1)
lemma eta_q_eq_cexp (n : ℕ) (z : ℂ) : eta_q n z = cexp (2 * π * I * (n + 1) * z) := by
simp [eta_q, Periodic.qParam, ← Complex.exp_nsmul]
ring_nf
lemma eta_q_eq_pow (n : ℕ) (z : ℂ) : eta_q n z = cexp (2 * π * I * z) ^ (n + 1) := by
simp [eta_q, Periodic.qParam]
lemma one_sub_eta_q_ne_zero (n : ℕ) {z : ℂ} (hz : z ∈ ℍₒ) : 1 - eta_q n z ≠ 0 := by
rw [eta_q_eq_cexp, sub_ne_zero]
intro h
simpa [← mul_assoc, ← h] using norm_exp_two_pi_I_lt_one ⟨(n + 1) • z, by
simpa [(show 0 < (n + 1 : ℝ) by positivity)] using hz⟩
/-- The eta function, whose value at z is `q^ 1 / 24 * ∏' 1 - q ^ (n + 1)` for `q = e ^ 2 π i z`. -/
noncomputable def eta (z : ℂ) := 𝕢 24 z * ∏' n, (1 - eta_q n z)
local notation "η" => eta
theorem summable_eta_q (z : ℍ) : Summable fun n ↦ ‖-eta_q n z‖ := by
simp [eta_q, eta_q_eq_pow, summable_nat_add_iff 1, norm_exp_two_pi_I_lt_one z]
lemma multipliableLocallyUniformlyOn_eta :
MultipliableLocallyUniformlyOn (fun n a ↦ 1 - eta_q n a) ℍₒ:= by
use fun z ↦ ∏' n, (1 - eta_q n z)
simp_rw [sub_eq_add_neg]
apply hasProdLocallyUniformlyOn_of_forall_compact isOpen_upperHalfPlaneSet
intro K hK hcK
by_cases hN : K.Nonempty
· have hc : ContinuousOn (fun x ↦ ‖cexp (2 * π * I * x)‖) K := by fun_prop
obtain ⟨z, hz, hB, HB⟩ := hcK.exists_sSup_image_eq_and_ge hN hc
apply (summable_eta_q ⟨z, hK hz⟩).hasProdUniformlyOn_nat_one_add hcK
· filter_upwards with n x hx
simpa [eta_q, eta_q_eq_pow] using pow_le_pow_left₀ (by simp [norm_nonneg]) (HB x hx) _
· simp_rw [eta_q, Periodic.qParam]
fun_prop
· rw [hasProdUniformlyOn_iff_tendstoUniformlyOn]
simpa [not_nonempty_iff_eq_empty.mp hN] using tendstoUniformlyOn_empty
/-- Eta is non-vanishing on the upper half plane. -/
lemma eta_ne_zero {z : ℂ} (hz : z ∈ ℍₒ) : η z ≠ 0 := by
apply mul_ne_zero (Periodic.qParam_ne_zero z)
refine tprod_one_add_ne_zero_of_summable (f := fun n ↦ -eta_q n z) ?_ ?_
· exact fun i ↦ by simpa using one_sub_eta_q_ne_zero i hz
· simpa [eta_q, ← summable_norm_iff] using summable_eta_q ⟨z, hz⟩
lemma logDeriv_one_sub_cexp (r : ℂ) : logDeriv (fun z ↦ 1 - r * cexp z) =
fun z ↦ -r * cexp z / (1 - r * cexp z) := by
ext z
simp [logDeriv]
lemma logDeriv_one_sub_mul_cexp_comp (r : ℂ) {g : ℂ → ℂ} (hg : Differentiable ℂ g) :
logDeriv ((fun z ↦ 1 - r * cexp z) ∘ g) =
fun z ↦ -r * (deriv g z) * cexp (g z) / (1 - r * cexp (g z)) := by
ext y
rw [logDeriv_comp (by fun_prop) (hg y), logDeriv_one_sub_cexp]
ring
private theorem one_sub_eta_logDeriv_eq (z : ℂ) (n : ℕ) :
logDeriv (1 - eta_q n ·) z = 2 * π * I * (n + 1) * -eta_q n z / (1 - eta_q n z) := by
have h2 : (fun x ↦ 1 - cexp (2 * ↑π * I * (n + 1) * x)) =
((fun z ↦ 1 - 1 * cexp z) ∘ fun x ↦ 2 * ↑π * I * (n + 1) * x) := by aesop
have h3 : deriv (fun x : ℂ ↦ (2 * π * I * (n + 1) * x)) =
fun _ ↦ 2 * π * I * (n + 1) := by
ext y
simpa using deriv_const_mul (2 * π * I * (n + 1)) (d := fun (x : ℂ) ↦ x) (x := y)
simp_rw [eta_q_eq_cexp, h2, logDeriv_one_sub_mul_cexp_comp 1
(g := fun x ↦ (2 * π * I * (n + 1) * x)) (by fun_prop), h3]
simp
lemma tsum_logDeriv_eta_q (z : ℂ) : ∑' n, logDeriv (fun x ↦ 1 - eta_q n x) z =
(2 * π * I) * ∑' n, (n + 1) * (-eta_q n z) / (1 - eta_q n z) := by
rw [tsum_congr (one_sub_eta_logDeriv_eq z), ← tsum_mul_left]
grind
theorem differentiableAt_eta_of_mem_upperHalfPlaneSet {z : ℂ} (hz : z ∈ ℍₒ) :
DifferentiableAt ℂ eta z := by
apply DifferentiableAt.mul (by fun_prop)
refine (multipliableLocallyUniformlyOn_eta.hasProdLocallyUniformlyOn.differentiableOn ?_
isOpen_upperHalfPlaneSet z hz).differentiableAt (isOpen_upperHalfPlaneSet.mem_nhds hz)
filter_upwards with b
simpa [Finset.prod_fn] using DifferentiableOn.finset_prod (by fun_prop)
end ModularForm |
.lake/packages/mathlib/Mathlib/NumberTheory/ModularForms/QExpansion.lean | import Mathlib.Analysis.Complex.TaylorSeries
import Mathlib.Analysis.Complex.UpperHalfPlane.Exp
import Mathlib.NumberTheory.ModularForms.Basic
import Mathlib.NumberTheory.ModularForms.Identities
import Mathlib.RingTheory.PowerSeries.Basic
/-!
# q-expansions of modular forms
We show that a modular form of level `Γ(n)` can be written as `τ ↦ F (𝕢 n τ)` where `F` is
analytic on the open unit disc, and `𝕢 n` is the parameter `τ ↦ exp (2 * I * π * τ / n)`. As an
application, we show that cusp forms decay exponentially to 0 as `im τ → ∞`.
We also define the `q`-expansion of a modular form, either as a power series or as a
`FormalMultilinearSeries`, and show that it converges to `f` on the upper half plane.
## Main definitions and results
* `SlashInvariantFormClass.cuspFunction`: for a level `n` slash-invariant form, this is the function
`F` such that `f τ = F (exp (2 * π * I * τ / n))`, extended by a choice of limit at `0`.
* `ModularFormClass.differentiableAt_cuspFunction`: when `f` is a modular form, its `cuspFunction`
is differentiable on the open unit disc (including at `0`).
* `ModularFormClass.qExpansion`: the `q`-expansion of a modular form (defined as the Taylor series
of its `cuspFunction`), bundled as a `PowerSeries`.
* `ModularFormClass.hasSum_qExpansion`: the `q`-expansion evaluated at `𝕢 n τ` sums to `f τ`, for
`τ` in the upper half plane.
## TO DO:
* generalise to handle arbitrary finite-index subgroups (not just `Γ(n)` for some `n`)
* define the `q`-expansion map on modular form spaces as a linear map (or even a ring hom from
the graded ring of all modular forms?)
-/
open ModularForm Complex Filter UpperHalfPlane Function Matrix.SpecialLinearGroup
open scoped Real MatrixGroups CongruenceSubgroup
noncomputable section
variable {k : ℤ} {F : Type*} [FunLike F ℍ ℂ] {Γ : Subgroup SL(2, ℤ)} (n : ℕ) (f : F)
local notation "I∞" => comap Complex.im atTop
local notation "𝕢" => Periodic.qParam
namespace SlashInvariantFormClass
theorem periodic_comp_ofComplex [SlashInvariantFormClass F Γ(n) k] :
Periodic (f ∘ ofComplex) n := by
intro w
by_cases! hw : 0 < im w
· have : 0 < im (w + n) := by simp only [add_im, natCast_im, add_zero, hw]
simp only [comp_apply, ofComplex_apply_of_im_pos this, ofComplex_apply_of_im_pos hw]
convert SlashInvariantForm.vAdd_width_periodic n k 1 f ⟨w, hw⟩ using 2
simp only [Int.cast_one, mul_one, UpperHalfPlane.ext_iff, coe_mk_subtype, coe_vadd,
ofReal_natCast, add_comm]
· have : im (w + n) ≤ 0 := by simpa only [add_im, natCast_im, add_zero, not_lt] using hw
simp only [comp_apply, ofComplex_apply_of_im_nonpos this,
ofComplex_apply_of_im_nonpos hw]
/--
The analytic function `F` such that `f τ = F (exp (2 * π * I * τ / n))`, extended by a choice of
limit at `0`.
-/
def cuspFunction : ℂ → ℂ := Function.Periodic.cuspFunction n (f ∘ ofComplex)
theorem eq_cuspFunction [NeZero n] [SlashInvariantFormClass F Γ(n) k] (τ : ℍ) :
cuspFunction n f (𝕢 n τ) = f τ := by
simpa only [comp_apply, ofComplex_apply]
using (periodic_comp_ofComplex n f).eq_cuspFunction (NeZero.ne _) τ
end SlashInvariantFormClass
open SlashInvariantFormClass
namespace ModularFormClass
theorem differentiableAt_comp_ofComplex [ModularFormClass F Γ k]
{z : ℂ} (hz : 0 < im z) :
DifferentiableAt ℂ (f ∘ ofComplex) z :=
mdifferentiableAt_iff_differentiableAt.mp ((holo f _).comp z (mdifferentiableAt_ofComplex hz))
theorem bounded_at_infty_comp_ofComplex [ModularFormClass F Γ k] [Γ.FiniteIndex] :
BoundedAtFilter I∞ (f ∘ ofComplex) :=
(ModularFormClass.bdd_at_infty f).comp_tendsto tendsto_comap_im_ofComplex
theorem differentiableAt_cuspFunction [NeZero n] [ModularFormClass F Γ(n) k]
{q : ℂ} (hq : ‖q‖ < 1) :
DifferentiableAt ℂ (cuspFunction n f) q := by
have npos : 0 < (n : ℝ) := mod_cast (Nat.pos_iff_ne_zero.mpr (NeZero.ne _))
rcases eq_or_ne q 0 with rfl | hq'
· exact (periodic_comp_ofComplex n f).differentiableAt_cuspFunction_zero npos
(eventually_of_mem (preimage_mem_comap (Ioi_mem_atTop 0))
(fun _ ↦ differentiableAt_comp_ofComplex f))
(bounded_at_infty_comp_ofComplex f)
· exact Periodic.qParam_right_inv npos.ne' hq' ▸
(periodic_comp_ofComplex n f).differentiableAt_cuspFunction npos.ne'
<| differentiableAt_comp_ofComplex _ <| Periodic.im_invQParam_pos_of_norm_lt_one npos hq hq'
lemma analyticAt_cuspFunction_zero [NeZero n] [ModularFormClass F Γ(n) k] :
AnalyticAt ℂ (cuspFunction n f) 0 :=
DifferentiableOn.analyticAt
(fun q hq ↦ (differentiableAt_cuspFunction _ _ hq).differentiableWithinAt)
(by simpa only [ball_zero_eq] using Metric.ball_mem_nhds (0 : ℂ) zero_lt_one)
/-- The `q`-expansion of a level `n` modular form, bundled as a `PowerSeries`. -/
def qExpansion : PowerSeries ℂ :=
.mk fun m ↦ (↑m.factorial)⁻¹ * iteratedDeriv m (cuspFunction n f) 0
lemma qExpansion_coeff (m : ℕ) :
(qExpansion n f).coeff m = (↑m.factorial)⁻¹ * iteratedDeriv m (cuspFunction n f) 0 := by
simp [qExpansion]
lemma hasSum_qExpansion_of_abs_lt [NeZero n] [ModularFormClass F Γ(n) k]
{q : ℂ} (hq : ‖q‖ < 1) :
HasSum (fun m : ℕ ↦ (qExpansion n f).coeff m • q ^ m) (cuspFunction n f q) := by
simp only [qExpansion_coeff]
have hdiff : DifferentiableOn ℂ (cuspFunction n f) (Metric.ball 0 1) := by
refine fun z hz ↦ (differentiableAt_cuspFunction n f ?_).differentiableWithinAt
simpa using hz
have qmem : q ∈ Metric.ball 0 1 := by simpa using hq
convert hasSum_taylorSeries_on_ball hdiff qmem using 2 with m
rw [sub_zero, smul_eq_mul, smul_eq_mul, mul_right_comm, smul_eq_mul, mul_assoc]
lemma hasSum_qExpansion [NeZero n] [ModularFormClass F Γ(n) k] (τ : ℍ) :
HasSum (fun m : ℕ ↦ (qExpansion n f).coeff m • 𝕢 n τ ^ m) (f τ) := by
simpa only [eq_cuspFunction n f] using
hasSum_qExpansion_of_abs_lt n f (τ.norm_qParam_lt_one n)
/--
The `q`-expansion of a level `n` modular form, bundled as a `FormalMultilinearSeries`.
TODO: Maybe get rid of this and instead define a general API for converting `PowerSeries` to
`FormalMultilinearSeries`.
-/
def qExpansionFormalMultilinearSeries : FormalMultilinearSeries ℂ ℂ ℂ :=
fun m ↦ (qExpansion n f).coeff m • ContinuousMultilinearMap.mkPiAlgebraFin ℂ m _
lemma qExpansionFormalMultilinearSeries_apply_norm (m : ℕ) :
‖qExpansionFormalMultilinearSeries n f m‖ = ‖(qExpansion n f).coeff m‖ := by
rw [qExpansionFormalMultilinearSeries,
← (ContinuousMultilinearMap.piFieldEquiv ℂ (Fin m) ℂ).symm.norm_map]
simp
lemma qExpansionFormalMultilinearSeries_radius [NeZero n] [ModularFormClass F Γ(n) k] :
1 ≤ (qExpansionFormalMultilinearSeries n f).radius := by
refine le_of_forall_lt_imp_le_of_dense fun r hr ↦ ?_
lift r to NNReal using hr.ne_top
apply FormalMultilinearSeries.le_radius_of_summable
simp only [qExpansionFormalMultilinearSeries_apply_norm]
rw [← r.abs_eq]
simp_rw [← Real.norm_eq_abs, ← Complex.norm_real, ← norm_pow, ← norm_mul]
exact (hasSum_qExpansion_of_abs_lt n f (q := r) (by simpa using hr)).summable.norm
/-- The `q`-expansion of `f` is an `FPowerSeries` representing `cuspFunction n f`. -/
lemma hasFPowerSeries_cuspFunction [NeZero n] [ModularFormClass F Γ(n) k] :
HasFPowerSeriesOnBall (cuspFunction n f) (qExpansionFormalMultilinearSeries n f) 0 1 := by
refine ⟨qExpansionFormalMultilinearSeries_radius n f, zero_lt_one, fun hy ↦ ?_⟩
rw [EMetric.mem_ball, edist_zero_right, enorm_eq_nnnorm, ENNReal.coe_lt_one_iff,
← NNReal.coe_lt_one, coe_nnnorm] at hy
simpa [qExpansionFormalMultilinearSeries] using hasSum_qExpansion_of_abs_lt n f hy
end ModularFormClass
open ModularFormClass
namespace CuspFormClass
theorem zero_at_infty_comp_ofComplex [CuspFormClass F Γ k] [Γ.FiniteIndex] :
ZeroAtFilter I∞ (f ∘ ofComplex) :=
(zero_at_infty f).comp tendsto_comap_im_ofComplex
theorem cuspFunction_apply_zero [NeZero n] [CuspFormClass F Γ(n) k] :
cuspFunction n f 0 = 0 :=
Periodic.cuspFunction_zero_of_zero_at_inf (mod_cast (Nat.pos_iff_ne_zero.mpr (NeZero.ne _)))
(zero_at_infty_comp_ofComplex f)
theorem exp_decay_atImInfty [NeZero n] [CuspFormClass F Γ(n) k] :
f =O[atImInfty] fun τ ↦ Real.exp (-2 * π * τ.im / n) := by
simpa only [neg_mul, comp_def, ofComplex_apply, coe_im] using
((periodic_comp_ofComplex n f).exp_decay_of_zero_at_inf
(mod_cast (Nat.pos_iff_ne_zero.mpr (NeZero.ne _)))
(eventually_of_mem (preimage_mem_comap (Ioi_mem_atTop 0))
fun _ ↦ differentiableAt_comp_ofComplex f)
(zero_at_infty_comp_ofComplex f)).comp_tendsto tendsto_coe_atImInfty
end CuspFormClass |
.lake/packages/mathlib/Mathlib/NumberTheory/ModularForms/BoundedAtCusp.lean | import Mathlib.Analysis.Complex.UpperHalfPlane.FunctionsBoundedAtInfty
import Mathlib.NumberTheory.ModularForms.Cusps
import Mathlib.NumberTheory.ModularForms.SlashActions
/-!
# Boundedness and vanishing at cusps
We define the notions of "bounded at c" and "vanishing at c" for functions on `ℍ`, where `c` is
an element of `OnePoint ℝ`.
-/
open Matrix SpecialLinearGroup UpperHalfPlane Filter Polynomial OnePoint
open scoped MatrixGroups LinearAlgebra.Projectivization ModularForm
namespace UpperHalfPlane
variable {g : GL (Fin 2) ℝ} {f : ℍ → ℂ} (k : ℤ)
lemma IsZeroAtImInfty.slash (hg : g 1 0 = 0) (hf : IsZeroAtImInfty f) :
IsZeroAtImInfty (f ∣[k] g) := by
rw [IsZeroAtImInfty, ZeroAtFilter, tendsto_zero_iff_norm_tendsto_zero] at hf ⊢
simpa [ModularForm.slash_def, denom, hg, mul_assoc]
using (hf.comp <| tendsto_smul_atImInfty hg).mul_const _
lemma IsBoundedAtImInfty.slash (hg : g 1 0 = 0) (hf : IsBoundedAtImInfty f) :
IsBoundedAtImInfty (f ∣[k] g) := by
rw [IsBoundedAtImInfty, BoundedAtFilter, ← Asymptotics.isBigO_norm_left] at hf ⊢
suffices (fun x ↦ (‖g.det.val ^ (k - 1)‖ * ‖g 1 1 ^ (-k)‖) * ‖f (g • x)‖) =O[atImInfty] 1 by
simpa [ModularForm.slash_def, denom, hg, mul_assoc, mul_comm ‖f _‖]
apply (hf.comp_tendsto (tendsto_smul_atImInfty hg)).const_mul_left
end UpperHalfPlane
namespace OnePoint
variable (c : OnePoint ℝ) (f : ℍ → ℂ) (k : ℤ)
/-- We say `f` is bounded at `c` if, for all `g` with `g • ∞ = c`, the function `f ∣[k] g` is
bounded at `∞`. -/
def IsBoundedAt : Prop := ∀ g : GL (Fin 2) ℝ, g • ∞ = c → IsBoundedAtImInfty (f ∣[k] g)
/-- We say `f` is zero at `c` if, for all `g` with `g • ∞ = c`, the function `f ∣[k] g` is
zero at `∞`. -/
def IsZeroAt : Prop := ∀ g : GL (Fin 2) ℝ, g • ∞ = c → IsZeroAtImInfty (f ∣[k] g)
variable {c f k} {g : GL (Fin 2) ℝ}
lemma IsBoundedAt.smul_iff : IsBoundedAt (g • c) f k ↔ IsBoundedAt c (f ∣[k] g) k := by
rw [IsBoundedAt, IsBoundedAt, (Equiv.mulLeft g⁻¹).forall_congr_left]
simp [MulAction.mul_smul, ← SlashAction.slash_mul]
lemma IsZeroAt.smul_iff : IsZeroAt (g • c) f k ↔ IsZeroAt c (f ∣[k] g) k := by
rw [IsZeroAt, IsZeroAt, (Equiv.mulLeft g⁻¹).forall_congr_left]
simp [MulAction.mul_smul, ← SlashAction.slash_mul]
lemma IsBoundedAt.add {f' : ℍ → ℂ} (hf : IsBoundedAt c f k) (hf' : IsBoundedAt c f' k) :
IsBoundedAt c (f + f') k :=
fun g hg ↦ by simpa using (hf g hg).add (hf' g hg)
lemma IsZeroAt.add {f' : ℍ → ℂ} (hf : IsZeroAt c f k) (hf' : IsZeroAt c f' k) :
IsZeroAt c (f + f') k :=
fun g hg ↦ by simpa using (hf g hg).add (hf' g hg)
lemma isBoundedAt_infty_iff : IsBoundedAt ∞ f k ↔ IsBoundedAtImInfty f :=
⟨fun h ↦ by simpa using h 1 (by simp), fun h _ hg ↦ h.slash _ (smul_infty_eq_self_iff.mp hg)⟩
lemma isZeroAt_infty_iff : IsZeroAt ∞ f k ↔ IsZeroAtImInfty f :=
⟨fun h ↦ by simpa using h 1 (by simp), fun h _ hg ↦ h.slash _ (smul_infty_eq_self_iff.mp hg)⟩
/-- To check that `f` is bounded at `c`, it suffices for `f ∣[k] g` to be bounded at `∞` for any
single `g` with `g • ∞ = c`. -/
lemma isBoundedAt_iff (hg : g • ∞ = c) : IsBoundedAt c f k ↔ IsBoundedAtImInfty (f ∣[k] g) :=
⟨fun hc ↦ hc g hg , by simp [← hg, IsBoundedAt.smul_iff, isBoundedAt_infty_iff]⟩
/-- To check that `f` is zero at `c`, it suffices for `f ∣[k] g` to be zero at `∞` for any
single `g` with `g • ∞ = c`. -/
lemma isZeroAt_iff (hg : g • ∞ = c) : IsZeroAt c f k ↔ IsZeroAtImInfty (f ∣[k] g) :=
⟨fun hc ↦ hc g hg , by simp [← hg, IsZeroAt.smul_iff, isZeroAt_infty_iff]⟩
section SL2Z
variable {c : OnePoint ℝ} {f : ℍ → ℂ} {k : ℤ}
lemma isBoundedAt_iff_exists_SL2Z (hc : IsCusp c 𝒮ℒ) :
IsBoundedAt c f k ↔ ∃ γ : SL(2, ℤ), mapGL ℝ γ • ∞ = c ∧ IsBoundedAtImInfty (f ∣[k] γ) := by
constructor
· obtain ⟨γ, rfl⟩ := isCusp_SL2Z_iff'.mp hc
simpa [IsBoundedAt.smul_iff, isBoundedAt_infty_iff] using fun hfc ↦ ⟨γ, rfl, hfc⟩
· rintro ⟨γ, rfl, b⟩
simpa [IsBoundedAt.smul_iff, isBoundedAt_infty_iff] using b
lemma isZeroAt_iff_exists_SL2Z (hc : IsCusp c 𝒮ℒ) :
IsZeroAt c f k ↔ ∃ γ : SL(2, ℤ), mapGL ℝ γ • ∞ = c ∧ IsZeroAtImInfty (f ∣[k] γ) := by
constructor
· obtain ⟨γ, rfl⟩ := isCusp_SL2Z_iff'.mp hc
simpa [IsZeroAt.smul_iff, isZeroAt_infty_iff] using fun hfc ↦ ⟨γ, rfl, hfc⟩
· rintro ⟨γ, rfl, b⟩
simpa [IsZeroAt.smul_iff, isZeroAt_infty_iff] using b
lemma isBoundedAt_iff_forall_SL2Z (hc : IsCusp c 𝒮ℒ) :
IsBoundedAt c f k ↔ ∀ γ : SL(2, ℤ), mapGL ℝ γ • ∞ = c → IsBoundedAtImInfty (f ∣[k] γ) := by
refine ⟨fun hc _ hγ ↦ by simpa using hc _ hγ, fun h ↦ ?_⟩
obtain ⟨γ, rfl⟩ := isCusp_SL2Z_iff'.mp hc
simpa [IsBoundedAt.smul_iff, isBoundedAt_infty_iff] using h γ rfl
lemma isZeroAt_iff_forall_SL2Z (hc : IsCusp c 𝒮ℒ) :
IsZeroAt c f k ↔ ∀ γ : SL(2, ℤ), mapGL ℝ γ • ∞ = c → IsZeroAtImInfty (f ∣[k] γ) := by
refine ⟨fun hc _ hγ ↦ by simpa using hc _ hγ, fun h ↦ ?_⟩
obtain ⟨γ, rfl⟩ := isCusp_SL2Z_iff'.mp hc
simpa [IsZeroAt.smul_iff, isZeroAt_infty_iff] using h γ rfl
end SL2Z
end OnePoint |
.lake/packages/mathlib/Mathlib/NumberTheory/ModularForms/LevelOne.lean | import Mathlib.Analysis.Complex.AbsMax
import Mathlib.NumberTheory.Modular
import Mathlib.NumberTheory.ModularForms.QExpansion
/-!
# Level one modular forms
This file contains results specific to modular forms of level one, i.e. modular forms for
`SL(2, ℤ)`.
TODO: Add finite-dimensionality of these spaces of modular forms.
-/
open UpperHalfPlane ModularGroup SlashInvariantForm ModularForm Complex
CongruenceSubgroup Real Function SlashInvariantFormClass ModularFormClass Periodic
local notation "𝕢" => qParam
variable {F : Type*} [FunLike F ℍ ℂ] {k : ℤ}
namespace SlashInvariantForm
variable [SlashInvariantFormClass F Γ(1) k]
lemma exists_one_half_le_im_and_norm_le (hk : k ≤ 0) (f : F) (τ : ℍ) :
∃ ξ : ℍ, 1 / 2 ≤ ξ.im ∧ ‖f τ‖ ≤ ‖f ξ‖ :=
let ⟨γ, hγ, hdenom⟩ := exists_one_half_le_im_smul_and_norm_denom_le τ
⟨γ • τ, hγ, by simpa only [slash_action_eqn_SL'' _ (mem_Gamma_one γ),
norm_mul, norm_zpow] using le_mul_of_one_le_left (norm_nonneg _) <|
one_le_zpow_of_nonpos₀ (norm_pos_iff.2 (denom_ne_zero _ _)) hdenom hk⟩
variable (k) in
/-- If a constant function is modular of weight `k`, then either `k = 0`, or the constant is `0`. -/
lemma wt_eq_zero_of_eq_const {f : F} {c : ℂ} (hf : ⇑f = Function.const _ c) :
k = 0 ∨ c = 0 := by
have hI := slash_action_eqn_SL'' f (mem_Gamma_one S) I
have h2I2 := slash_action_eqn_SL'' f (mem_Gamma_one S) ⟨2 * Complex.I, by simp⟩
simp_rw [sl_moeb, hf, Function.const, denom_S, coe_mk_subtype] at hI h2I2
nth_rw 1 [h2I2] at hI
simp only [mul_zpow, coe_I, mul_eq_mul_right_iff, mul_left_eq_self₀] at hI
refine hI.imp_left (Or.casesOn · (fun H ↦ ?_) (False.elim ∘ zpow_ne_zero k I_ne_zero))
rwa [← ofReal_ofNat, ← ofReal_zpow, ← ofReal_one, ofReal_inj,
zpow_eq_one_iff_right₀ (by simp) (by simp)] at H
end SlashInvariantForm
namespace ModularFormClass
variable [ModularFormClass F Γ(1) k]
private theorem cuspFunction_eqOn_const_of_nonpos_wt (hk : k ≤ 0) (f : F) :
Set.EqOn (cuspFunction 1 f) (const ℂ (cuspFunction 1 f 0)) (Metric.ball 0 1) := by
refine eq_const_of_exists_le (fun q hq ↦ ?_) (exp_nonneg (-π)) ?_ (fun q hq ↦ ?_)
· exact (differentiableAt_cuspFunction 1 f (mem_ball_zero_iff.mp hq)).differentiableWithinAt
· simp only [exp_lt_one_iff, Left.neg_neg_iff, pi_pos]
· simp only [Metric.mem_closedBall, dist_zero_right]
rcases eq_or_ne q 0 with rfl | hq'
· refine ⟨0, by simpa only [norm_zero] using exp_nonneg _, le_rfl⟩
· obtain ⟨ξ, hξ, hξ₂⟩ := exists_one_half_le_im_and_norm_le hk f
⟨_, im_invQParam_pos_of_norm_lt_one Real.zero_lt_one (mem_ball_zero_iff.mp hq) hq'⟩
exact ⟨_, norm_qParam_le_of_one_half_le_im hξ,
by simpa only [← eq_cuspFunction 1 f, Nat.cast_one, coe_mk_subtype,
qParam_right_inv one_ne_zero hq'] using hξ₂⟩
private theorem levelOne_nonpos_wt_const (hk : k ≤ 0) (f : F) :
⇑f = Function.const _ (cuspFunction 1 f 0) := by
ext z
have hQ : 𝕢 1 z ∈ (Metric.ball 0 1) := by
simpa only [Metric.mem_ball, dist_zero_right, neg_mul, mul_zero, div_one, Real.exp_zero]
using (norm_qParam_lt_iff zero_lt_one 0 z.1).mpr z.2
simpa only [← eq_cuspFunction 1 f z, Nat.cast_one, Function.const_apply] using
(cuspFunction_eqOn_const_of_nonpos_wt hk f) hQ
lemma levelOne_neg_weight_eq_zero (hk : k < 0) (f : F) : ⇑f = 0 := by
have hf := levelOne_nonpos_wt_const hk.le f
rcases wt_eq_zero_of_eq_const k hf with rfl | hf₀
· exact (lt_irrefl _ hk).elim
· rw [hf, hf₀, const_zero]
lemma levelOne_weight_zero_const [ModularFormClass F Γ(1) 0] (f : F) :
∃ c, ⇑f = Function.const _ c :=
⟨_, levelOne_nonpos_wt_const le_rfl f⟩
end ModularFormClass
lemma ModularForm.levelOne_weight_zero_rank_one : Module.rank ℂ (ModularForm Γ(1) 0) = 1 := by
refine rank_eq_one (const 1) (by simp [DFunLike.ne_iff]) fun g ↦ ?_
obtain ⟨c', hc'⟩ := levelOne_weight_zero_const g
aesop
lemma ModularForm.levelOne_neg_weight_rank_zero (hk : k < 0) :
Module.rank ℂ (ModularForm Γ(1) k) = 0 := by
refine rank_eq_zero_iff.mpr fun f ↦ ⟨_, one_ne_zero, ?_⟩
simpa only [one_smul, ← DFunLike.coe_injective.eq_iff] using levelOne_neg_weight_eq_zero hk f |
.lake/packages/mathlib/Mathlib/NumberTheory/ModularForms/Identities.lean | import Mathlib.NumberTheory.ModularForms.SlashInvariantForms
import Mathlib.NumberTheory.ModularForms.CongruenceSubgroups
/-!
# Identities of ModularForms and SlashInvariantForms
Collection of useful identities of modular forms.
-/
noncomputable section
open ModularForm UpperHalfPlane Matrix CongruenceSubgroup Matrix.SpecialLinearGroup
namespace SlashInvariantForm
/- TODO: Once we have cusps, do this more generally, same below. -/
theorem vAdd_width_periodic (N : ℕ) (k n : ℤ) (f : SlashInvariantForm (Gamma N) k) (z : ℍ) :
f (((N * n) : ℝ) +ᵥ z) = f z := by
norm_cast
rw [← modular_T_zpow_smul z (N * n), MulAction.compHom_smul_def, slash_action_eqn']
· simp [-map_zpow, ModularGroup.coe_T_zpow (N * n)]
· simpa using Subgroup.mem_map_of_mem (mapGL ℝ) <|
ModularGroup_T_pow_mem_Gamma _ _ (Int.dvd_mul_right N n)
theorem T_zpow_width_invariant (N : ℕ) (k n : ℤ) (f : SlashInvariantForm (Gamma N) k) (z : ℍ) :
f (((ModularGroup.T ^ (N * n))) • z) = f z := by
rw [modular_T_zpow_smul z (N * n)]
simpa only [Int.cast_mul, Int.cast_natCast] using vAdd_width_periodic N k n f z
end SlashInvariantForm |
.lake/packages/mathlib/Mathlib/NumberTheory/ModularForms/Cusps.lean | import Mathlib.Algebra.EuclideanDomain.Int
import Mathlib.Analysis.RCLike.Basic
import Mathlib.GroupTheory.Commensurable
import Mathlib.RingTheory.Localization.NumDen
import Mathlib.Topology.Compactification.OnePoint.ProjectiveLine
import Mathlib.NumberTheory.ModularForms.ArithmeticSubgroups
/-!
# Cusps
We define the cusps of a subgroup of `GL(2, ℝ)` as the fixed points of parabolic elements.
-/
open Matrix SpecialLinearGroup GeneralLinearGroup Filter Polynomial OnePoint
open scoped MatrixGroups LinearAlgebra.Projectivization
namespace OnePoint
variable {K : Type*} [Field K] [DecidableEq K]
/-- The modular group `SL(2, A)` acts transitively on `OnePoint K`, if `A` is a PID whose fraction
field is `K`. (This includes the case `A = ℤ`, `K = ℚ`.) -/
lemma exists_mem_SL2 (A : Type*) [CommRing A] [IsDomain A] [Algebra A K] [IsFractionRing A K]
[IsPrincipalIdealRing A] (c : OnePoint K) :
∃ g : SL(2, A), (mapGL K g) • ∞ = c := by
cases c with
| infty => exact ⟨1, by simp⟩
| coe q =>
obtain ⟨g, hg0, hg1⟩ := (IsFractionRing.num_den_reduced A q).isCoprime.exists_SL2_col 0
exact ⟨g, by simp [hg0, hg1, smul_infty_eq_ite]⟩
end OnePoint
namespace Subgroup.HasDetPlusMinusOne
variable {K : Type*} [Field K] [LinearOrder K] [IsStrictOrderedRing K]
{𝒢 : Subgroup (GL (Fin 2) K)} [𝒢.HasDetPlusMinusOne]
lemma isParabolic_iff_of_upperTriangular {g} (hg : g ∈ 𝒢) (hg10 : g 1 0 = 0) :
g.IsParabolic ↔ (∃ x ≠ 0, g = upperRightHom x) ∨ (∃ x ≠ 0, g = -upperRightHom x) :=
isParabolic_iff_of_upperTriangular_of_det (HasDetPlusMinusOne.det_eq hg) hg10
end Subgroup.HasDetPlusMinusOne
section IsCusp
/-- The *cusps* of a subgroup of `GL(2, ℝ)` are the fixed points of parabolic elements of `g`. -/
def IsCusp (c : OnePoint ℝ) (𝒢 : Subgroup (GL (Fin 2) ℝ)) : Prop :=
∃ g ∈ 𝒢, g.IsParabolic ∧ g • c = c
open Pointwise in
lemma IsCusp.smul {c : OnePoint ℝ} {𝒢 : Subgroup (GL (Fin 2) ℝ)} (hc : IsCusp c 𝒢)
(g : GL (Fin 2) ℝ) : IsCusp (g • c) (ConjAct.toConjAct g • 𝒢) := by
obtain ⟨p, hp𝒢, hpp, hpc⟩ := hc
refine ⟨_, 𝒢.smul_mem_pointwise_smul _ _ hp𝒢, ?_, ?_⟩
· simpa [ConjAct.toConjAct_smul] using hpp
· simp [ConjAct.toConjAct_smul, MulAction.mul_smul, hpc]
lemma IsCusp.smul_of_mem {c : OnePoint ℝ} {𝒢 : Subgroup (GL (Fin 2) ℝ)} (hc : IsCusp c 𝒢)
{g : GL (Fin 2) ℝ} (hg : g ∈ 𝒢) : IsCusp (g • c) 𝒢 := by
convert hc.smul g
ext x
rw [Subgroup.mem_pointwise_smul_iff_inv_smul_mem, ← ConjAct.toConjAct_inv,
ConjAct.toConjAct_smul, inv_inv, Subgroup.mul_mem_cancel_right _ hg,
Subgroup.mul_mem_cancel_left _ (inv_mem hg)]
lemma isCusp_iff_of_relIndex_ne_zero {𝒢 𝒢' : Subgroup (GL (Fin 2) ℝ)}
(h𝒢 : 𝒢' ≤ 𝒢) (h𝒢' : 𝒢'.relIndex 𝒢 ≠ 0) (c : OnePoint ℝ) :
IsCusp c 𝒢' ↔ IsCusp c 𝒢 := by
refine ⟨fun ⟨g, hg, hgp, hgc⟩ ↦ ⟨g, h𝒢 hg, hgp, hgc⟩, fun ⟨g, hg, hgp, hgc⟩ ↦ ?_⟩
obtain ⟨n, hn, -, hgn⟩ := Subgroup.exists_pow_mem_of_relIndex_ne_zero h𝒢' hg
refine ⟨g ^ n, (Subgroup.mem_inf.mpr hgn).1, hgp.pow hn.ne', ?_⟩
rw [Nat.pos_iff_ne_zero] at hn
rwa [(hgp.pow hn).smul_eq_self_iff, hgp.parabolicFixedPoint_pow hn, ← hgp.smul_eq_self_iff]
@[deprecated (since := "2025-09-13")]
alias isCusp_iff_of_relindex_ne_zero := isCusp_iff_of_relIndex_ne_zero
lemma Subgroup.Commensurable.isCusp_iff {𝒢 𝒢' : Subgroup (GL (Fin 2) ℝ)}
(h𝒢 : Commensurable 𝒢 𝒢') {c : OnePoint ℝ} :
IsCusp c 𝒢 ↔ IsCusp c 𝒢' := by
rw [← isCusp_iff_of_relIndex_ne_zero inf_le_left, isCusp_iff_of_relIndex_ne_zero inf_le_right]
· simpa [Subgroup.inf_relIndex_right] using h𝒢.1
· simpa [Subgroup.inf_relIndex_left] using h𝒢.2
@[deprecated (since := "2025-09-17")]
alias Commensurable.isCusp_iff := Subgroup.Commensurable.isCusp_iff
/-- The cusps of `SL(2, ℤ)` are precisely the elements of `ℙ¹(ℚ)`. -/
lemma isCusp_SL2Z_iff {c : OnePoint ℝ} : IsCusp c 𝒮ℒ ↔ c ∈ Set.range (OnePoint.map Rat.cast) := by
constructor
· rintro ⟨-, ⟨g, rfl⟩, hgp, hgc⟩
simpa only [hgp.smul_eq_self_iff.mp hgc] using ⟨(mapGL ℚ g).parabolicFixedPoint,
by simp [GeneralLinearGroup.parabolicFixedPoint, apply_ite]⟩
· rintro ⟨c, rfl⟩
obtain ⟨a, rfl⟩ := c.exists_mem_SL2 ℤ
refine ⟨_, ⟨a * ModularGroup.T * a⁻¹, rfl⟩, ?_, ?_⟩
· suffices (mapGL ℝ ModularGroup.T).IsParabolic by simpa
refine ⟨fun ⟨a, ha⟩ ↦ zero_ne_one' ℝ (by simpa [ModularGroup.T] using congr_fun₂ ha 0 1), ?_⟩
simp [discr_fin_two, trace_fin_two, det_fin_two, ModularGroup.T]
norm_num
· rw [← Rat.coe_castHom, ← (Rat.castHom ℝ).algebraMap_toAlgebra]
simp [OnePoint.map_smul, MulAction.mul_smul, smul_infty_eq_self_iff, ModularGroup.T]
/-- The cusps of `SL(2, ℤ)` are precisely the `SL(2, ℤ)` orbit of `∞`. -/
lemma isCusp_SL2Z_iff' {c : OnePoint ℝ} : IsCusp c 𝒮ℒ ↔ ∃ g : SL(2, ℤ), c = mapGL ℝ g • ∞ := by
rw [isCusp_SL2Z_iff]
constructor
· rintro ⟨c, rfl⟩
obtain ⟨g, rfl⟩ := c.exists_mem_SL2 ℤ
refine ⟨g, ?_⟩
rw [← Rat.coe_castHom, OnePoint.map_smul, OnePoint.map_infty,
← (Rat.castHom ℝ).algebraMap_toAlgebra, g.map_mapGL]
· rintro ⟨g, rfl⟩
refine ⟨mapGL ℚ g • ∞, ?_⟩
rw [← Rat.coe_castHom, OnePoint.map_smul, OnePoint.map_infty,
← (Rat.castHom ℝ).algebraMap_toAlgebra, g.map_mapGL]
/-- The cusps of any arithmetic subgroup are the same as those of `SL(2, ℤ)`. -/
lemma Subgroup.IsArithmetic.isCusp_iff_isCusp_SL2Z (𝒢 : Subgroup (GL (Fin 2) ℝ)) [𝒢.IsArithmetic]
{c : OnePoint ℝ} : IsCusp c 𝒢 ↔ IsCusp c 𝒮ℒ :=
is_commensurable.isCusp_iff
end IsCusp
section CuspOrbits
/-- The action of `𝒢` on its own cusps. -/
def cusps_subMulAction (𝒢 : Subgroup (GL (Fin 2) ℝ)) : SubMulAction 𝒢 (OnePoint ℝ) where
carrier := {c | IsCusp c 𝒢}
smul_mem' g _ hc := IsCusp.smul_of_mem hc g.property
/-- The type of cusp orbits of `𝒢`, i.e. orbits for the action of `𝒢` on its own cusps. -/
abbrev CuspOrbits (𝒢 : Subgroup (GL (Fin 2) ℝ)) :=
MulAction.orbitRel.Quotient 𝒢 (cusps_subMulAction 𝒢)
/-- Surjection from `SL(2, ℤ) / (𝒢 ⊓ SL(2, ℤ))` to cusp orbits of `𝒢`. Mostly useful for showing
that `CuspOrbits 𝒢` is finite for arithmetic subgroups. -/
noncomputable def cosetToCuspOrbit (𝒢 : Subgroup (GL (Fin 2) ℝ)) [𝒢.IsArithmetic] :
SL(2, ℤ) ⧸ (𝒢.comap <| mapGL ℝ) → CuspOrbits 𝒢 :=
Quotient.lift
(fun g ↦ ⟦⟨mapGL ℝ g⁻¹ • ∞,
(Subgroup.IsArithmetic.isCusp_iff_isCusp_SL2Z 𝒢).mpr <| isCusp_SL2Z_iff.mpr
⟨mapGL ℚ g⁻¹ • ∞, by rw [← Rat.coe_castHom, OnePoint.map_smul, OnePoint.map_infty,
← (Rat.castHom ℝ).algebraMap_toAlgebra, map_mapGL]⟩⟩⟧)
(fun a b hab ↦ by
rw [← Quotient.eq_iff_equiv, Quotient.eq, QuotientGroup.leftRel_apply] at hab
refine Quotient.eq.mpr ⟨⟨_, hab⟩, ?_⟩
simp [MulAction.mul_smul])
@[simp]
lemma cosetToCuspOrbit_apply_mk {𝒢 : Subgroup (GL (Fin 2) ℝ)} [𝒢.IsArithmetic] (g : SL(2, ℤ)) :
cosetToCuspOrbit 𝒢 ⟦g⟧ = ⟦⟨mapGL ℝ g⁻¹ • ∞,
(Subgroup.IsArithmetic.isCusp_iff_isCusp_SL2Z 𝒢).mpr <| isCusp_SL2Z_iff.mpr
⟨mapGL ℚ g⁻¹ • ∞, by rw [← Rat.coe_castHom, OnePoint.map_smul, OnePoint.map_infty,
← (Rat.castHom ℝ).algebraMap_toAlgebra, map_mapGL]⟩⟩⟧ :=
rfl
lemma surjective_cosetToCuspOrbit (𝒢 : Subgroup (GL (Fin 2) ℝ)) [𝒢.IsArithmetic] :
(cosetToCuspOrbit 𝒢).Surjective := by
rintro ⟨c, (hc : IsCusp c _)⟩
rw [Subgroup.IsArithmetic.isCusp_iff_isCusp_SL2Z, isCusp_SL2Z_iff'] at hc
obtain ⟨g, rfl⟩ := hc
use ⟦g⁻¹⟧
aesop
/-- An arithmetic subgroup has finitely many cusp orbits. -/
instance (𝒢 : Subgroup (GL (Fin 2) ℝ)) [𝒢.IsArithmetic] : Finite (CuspOrbits 𝒢) :=
.of_surjective _ (surjective_cosetToCuspOrbit 𝒢)
end CuspOrbits |
.lake/packages/mathlib/Mathlib/NumberTheory/ModularForms/SlashActions.lean | import Mathlib.Analysis.Complex.UpperHalfPlane.MoebiusAction
import Mathlib.LinearAlgebra.Matrix.GeneralLinearGroup.Defs
import Mathlib.LinearAlgebra.Matrix.SpecialLinearGroup
import Mathlib.Tactic.AdaptationNote
/-!
# Slash actions
This file defines a class of slash actions, which are families of right actions of a group on an a
additive monoid, parametrized by some index type. This is modeled on the slash action of
`GL (Fin 2) ℝ` on the space of modular forms.
## Notation
Scoped in the `ModularForm` namespace, this file defines
* `f ∣[k] A`: the `k`th slash action by `A` on `f`
-/
open Complex UpperHalfPlane ModularGroup
open scoped MatrixGroups
/-- A general version of the slash action of the space of modular forms. This is the same data as a
family of `DistribMulAction Gᵒᵖ α` indexed by `k`. -/
class SlashAction (β G α : Type*) [Monoid G] [AddMonoid α] where
map : β → G → α → α
zero_slash : ∀ (k : β) (g : G), map k g 0 = 0
slash_one : ∀ (k : β) (a : α), map k 1 a = a
slash_mul : ∀ (k : β) (g h : G) (a : α), map k (g * h) a = map k h (map k g a)
add_slash : ∀ (k : β) (g : G) (a b : α), map k g (a + b) = map k g a + map k g b
scoped[ModularForm] notation:100 f " ∣[" k "] " a:100 => SlashAction.map k a f
open scoped ModularForm
@[simp]
theorem SlashAction.neg_slash {β G α : Type*} [Monoid G] [AddGroup α]
[SlashAction β G α] (k : β) (g : G) (a : α) : (-a) ∣[k] g = -a ∣[k] g :=
eq_neg_of_add_eq_zero_left <| by
rw [← add_slash, neg_add_cancel, zero_slash]
attribute [simp] SlashAction.zero_slash SlashAction.slash_one SlashAction.add_slash
/-- Slash_action induced by a monoid homomorphism. -/
def monoidHomSlashAction {β G H α : Type*} [Monoid G] [AddMonoid α] [Monoid H]
[SlashAction β G α] (h : H →* G) : SlashAction β H α where
map k g := SlashAction.map k (h g)
zero_slash k g := SlashAction.zero_slash k (h g)
slash_one k a := by simp only [map_one, SlashAction.slash_one]
slash_mul k g gg a := by simp only [map_mul, SlashAction.slash_mul]
add_slash _ g _ _ := SlashAction.add_slash _ (h g) _ _
namespace ModularForm
noncomputable section
variable {k : ℤ} (f : ℍ → ℂ)
section privateSlash
/-- The weight `k` action of `GL (Fin 2) ℝ` on functions `f : ℍ → ℂ`. Invoking this directly is
deprecated; it should always be used via the `SlashAction` instance. -/
private def privateSlash (k : ℤ) (γ : GL (Fin 2) ℝ) (f : ℍ → ℂ) (x : ℍ) : ℂ :=
σ γ (f (γ • x)) * |γ.det.val| ^ (k - 1) * UpperHalfPlane.denom γ x ^ (-k)
-- Why is `noncomputable` flag needed here, when we're in a noncomputable section already?
@[deprecated (since := "2025-09-19")] noncomputable alias slash := privateSlash
-- temporary notation until the instance is built
local notation:100 f " ∣[" k "] " γ:100 => ModularForm.privateSlash k γ f
private theorem slash_mul (k : ℤ) (A B : GL (Fin 2) ℝ) (f : ℍ → ℂ) :
f ∣[k] (A * B) = (f ∣[k] A) ∣[k] B := by
ext1 τ
calc σ (A * B) (f ((A * B) • τ)) * |(A * B).det.val| ^ (k - 1) * denom (A * B) τ ^ (-k)
_ = σ B (σ A (f (A • B • τ))) * (|A.det.val| ^ (k - 1) * |B.det.val| ^ (k - 1)) *
(((σ B) (denom A ↑(B • τ) ^ (-k))) * denom B τ ^ (-k)) := by
rw [σ_mul_comm, σ_mul, denom_cocycle_σ, mul_zpow, mul_smul, map_mul, Units.val_mul,
abs_mul, ofReal_mul, mul_zpow, map_zpow₀]
_ = σ B (σ A (f (A • B • τ)) * |A.det.val| ^ (k - 1) * (denom A ↑(B • τ) ^ (-k)))
* |B.det.val| ^ (k - 1) * denom B τ ^ (-k) := by
rw [map_mul, map_zpow₀, map_mul, map_zpow₀, σ_ofReal]
ring
_ = ((f ∣[k] A) ∣[k] B) τ := rfl
private theorem add_slash (k : ℤ) (A : GL (Fin 2) ℝ) (f g : ℍ → ℂ) :
(f + g) ∣[k] A = f ∣[k] A + g ∣[k] A := by
ext1 τ
simp [privateSlash, add_mul]
private theorem slash_one (k : ℤ) (f : ℍ → ℂ) : f ∣[k] 1 = f :=
funext <| by simp [privateSlash, σ, denom]
private theorem zero_slash (k : ℤ) (A : GL (Fin 2) ℝ) : (0 : ℍ → ℂ) ∣[k] A = 0 :=
funext fun _ => by simp [privateSlash]
/-- The weight `k` action of `GL (Fin 2) ℝ` on functions `f : ℍ → ℂ`. -/
instance : SlashAction ℤ (GL (Fin 2) ℝ) (ℍ → ℂ) where
map := privateSlash
zero_slash := zero_slash
slash_one := slash_one
slash_mul := slash_mul
add_slash := add_slash
end privateSlash
theorem slash_def (g : GL (Fin 2) ℝ) :
f ∣[k] g = fun τ ↦ σ g (f (g • τ)) * |g.det.val| ^ (k - 1) * denom g τ ^ (-k) :=
rfl
theorem slash_apply (g : GL (Fin 2) ℝ) (τ : ℍ) :
(f ∣[k] g) τ = σ g (f (g • τ)) * |g.det.val| ^ (k - 1) * denom g τ ^ (-k) :=
rfl
theorem smul_slash (k : ℤ) (A : GL (Fin 2) ℝ) (f : ℍ → ℂ) (c : ℂ) :
(c • f) ∣[k] A = σ A c • f ∣[k] A := by
ext τ : 1
simp only [slash_apply, Pi.smul_apply, smul_eq_mul, map_mul, mul_assoc]
instance SLAction : SlashAction ℤ SL(2, ℤ) (ℍ → ℂ) :=
monoidHomSlashAction (Matrix.SpecialLinearGroup.mapGL ℝ)
theorem SL_slash (γ : SL(2, ℤ)) : f ∣[k] γ = f ∣[k] (γ : GL (Fin 2) ℝ) :=
rfl
theorem SL_slash_def (γ : SL(2, ℤ)) :
f ∣[k] γ = fun τ ↦ f (γ • τ) * denom γ τ ^ (-k) := by
simp [SL_slash, slash_def, σ]
theorem SL_slash_apply (γ : SL(2, ℤ)) (τ : ℍ) :
(f ∣[k] γ) τ = f (γ • τ) * denom γ τ ^ (-k) := by
simp [SL_slash, slash_def, σ]
@[simp]
theorem SL_smul_slash {α : Type*} [SMul α ℂ] [IsScalarTower α ℂ ℂ]
(k : ℤ) (A : SL(2, ℤ)) (f : ℍ → ℂ) (c : α) :
(c • f) ∣[k] A = c • f ∣[k] A := by
ext τ : 1
simp [SL_slash_apply, Pi.smul_apply, smul_mul_assoc]
theorem is_invariant_const (A : SL(2, ℤ)) (x : ℂ) :
Function.const ℍ x ∣[(0 : ℤ)] A = Function.const ℍ x := by
funext
simp [SL_slash, slash_def, σ, zero_lt_one]
/-- The constant function 1 is invariant under any element of `SL(2, ℤ)`. -/
theorem is_invariant_one (A : SL(2, ℤ)) : (1 : ℍ → ℂ) ∣[(0 : ℤ)] A = (1 : ℍ → ℂ) :=
is_invariant_const _ _
/-- Variant of `is_invariant_one` with the left-hand side in simp normal form. -/
@[simp]
theorem is_invariant_one' (A : SL(2, ℤ)) : (1 : ℍ → ℂ) ∣[(0 : ℤ)] (A : GL (Fin 2) ℝ) = 1 := by
simpa using is_invariant_one A
/-- A function `f : ℍ → ℂ` is slash-invariant, of weight `k ∈ ℤ` and level `Γ`,
if for every matrix `γ ∈ Γ` we have `f(γ • z)= (c*z+d)^k f(z)` where `γ= ![![a, b], ![c, d]]`,
and it acts on `ℍ` via Möbius transformations. -/
theorem slash_action_eq'_iff (k : ℤ) (f : ℍ → ℂ) (γ : SL(2, ℤ)) (z : ℍ) :
(f ∣[k] γ) z = f z ↔ f (γ • z) = ((γ 1 0 : ℂ) * z + (γ 1 1 : ℂ)) ^ k * f z := by
simp only [SL_slash_apply]
convert inv_mul_eq_iff_eq_mul₀ (G₀ := ℂ) _ using 2
· simp only [mul_comm (f _), denom, zpow_neg]
rfl
· exact zpow_ne_zero k (denom_ne_zero γ z)
theorem mul_slash (k1 k2 : ℤ) (A : GL (Fin 2) ℝ) (f g : ℍ → ℂ) :
(f * g) ∣[k1 + k2] A = |(A.det : ℝ)| • (f ∣[k1] A * g ∣[k2] A) := by
ext1 x
simp only [slash_apply, Pi.mul_apply, Pi.smul_apply, real_smul, map_mul, neg_add,
zpow_add₀ (denom_ne_zero _ x)]
set d := (↑|A.det.val| : ℂ)
have h1 : d ^ (k1 + k2 - 1) = d * d ^ (k1 - 1) * d ^ (k2 - 1) := by
have : d ≠ 0 := ofReal_ne_zero.mpr <| abs_ne_zero.mpr <| NeZero.ne _
rw [← zpow_one_add₀ this, ← zpow_add₀ this]
ring_nf
rw [h1]
ring
theorem mul_slash_SL2 (k1 k2 : ℤ) (A : SL(2, ℤ)) (f g : ℍ → ℂ) :
(f * g) ∣[k1 + k2] A = f ∣[k1] A * g ∣[k2] A := by
simp [SL_slash, mul_slash]
end
end ModularForm |
.lake/packages/mathlib/Mathlib/NumberTheory/ModularForms/EisensteinSeries/Summable.lean | import Mathlib.Analysis.Complex.UpperHalfPlane.Topology
import Mathlib.Analysis.PSeries
import Mathlib.Order.Interval.Finset.Box
import Mathlib.Analysis.Asymptotics.Defs
/-!
# Summability of Eisenstein series
We gather results about the summability of Eisenstein series, particularly
the summability of the Eisenstein series summands, which are used in the proof of the
boundedness of Eisenstein series at infinity.
-/
noncomputable section
open Complex UpperHalfPlane Set Finset Topology Filter Asymptotics
open scoped UpperHalfPlane Topology BigOperators Nat
variable (z : ℍ)
namespace EisensteinSeries
lemma norm_eq_max_natAbs (x : Fin 2 → ℤ) : ‖x‖ = max (x 0).natAbs (x 1).natAbs := by
rw [← coe_nnnorm, ← NNReal.coe_natCast, NNReal.coe_inj, Nat.cast_max]
refine eq_of_forall_ge_iff fun c ↦ ?_
simp only [pi_nnnorm_le_iff, Fin.forall_fin_two, max_le_iff, NNReal.natCast_natAbs]
lemma norm_symm (x y : ℤ) : ‖![x, y]‖ = ‖![y, x]‖ := by
simp [EisensteinSeries.norm_eq_max_natAbs, max_comm]
theorem abs_le_left_of_norm (m n : ℤ) : |n| ≤ ‖![n, m]‖ := by
simp only [EisensteinSeries.norm_eq_max_natAbs, Fin.isValue, Matrix.cons_val_zero,
Matrix.cons_val_one, Matrix.cons_val_fin_one, Nat.cast_max, le_sup_iff]
left
rw [Int.abs_eq_natAbs]
exact Preorder.le_refl _
theorem abs_le_right_of_norm (m n : ℤ) : |m| ≤ ‖![n, m]‖ := by
simp only [EisensteinSeries.norm_eq_max_natAbs, Fin.isValue, Matrix.cons_val_zero,
Matrix.cons_val_one, Matrix.cons_val_fin_one, Nat.cast_max, le_sup_iff]
right
rw [Int.abs_eq_natAbs]
exact Preorder.le_refl _
lemma abs_norm_eq_max_natAbs (n : ℕ) : ‖![1, (n + 1 : ℤ)]‖ = n + 1 := by
simp only [EisensteinSeries.norm_eq_max_natAbs, Matrix.cons_val_zero, Matrix.cons_val_one,
Matrix.cons_val_fin_one]
norm_cast
simp
lemma abs_norm_eq_max_natAbs_neg (n : ℕ) : ‖![1, -(n + 1 : ℤ)]‖ = n + 1 := by
simp only [EisensteinSeries.norm_eq_max_natAbs, Matrix.cons_val_zero, Matrix.cons_val_one,
Matrix.cons_val_fin_one]
norm_cast
simp
section bounding_functions
/-- Auxiliary function used for bounding Eisenstein series, defined as
`z.im ^ 2 / (z.re ^ 2 + z.im ^ 2)`. -/
def r1 : ℝ := z.im ^ 2 / (z.re ^ 2 + z.im ^ 2)
lemma r1_eq : r1 z = 1 / ((z.re / z.im) ^ 2 + 1) := by
rw [div_pow, div_add_one (by positivity), one_div_div, r1]
lemma r1_pos : 0 < r1 z := by
dsimp only [r1]
positivity
/-- For `c, d ∈ ℝ` with `1 ≤ d ^ 2`, we have `r1 z ≤ |c * z + d| ^ 2`. -/
lemma r1_aux_bound (c : ℝ) {d : ℝ} (hd : 1 ≤ d ^ 2) :
r1 z ≤ (c * z.re + d) ^ 2 + (c * z.im) ^ 2 := by
have H1 : (c * z.re + d) ^ 2 + (c * z.im) ^ 2 =
c ^ 2 * (z.re ^ 2 + z.im ^ 2) + d * 2 * c * z.re + d ^ 2 := by ring
have H2 : (c ^ 2 * (z.re ^ 2 + z.im ^ 2) + d * 2 * c * z.re + d ^ 2) * (z.re ^ 2 + z.im ^ 2)
- z.im ^ 2 = (c * (z.re ^ 2 + z.im ^ 2) + d * z.re) ^ 2 + (d ^ 2 - 1) * z.im ^ 2 := by ring
rw [r1, H1, div_le_iff₀ (by positivity), ← sub_nonneg, H2]
exact add_nonneg (sq_nonneg _) (mul_nonneg (sub_nonneg.mpr hd) (sq_nonneg _))
/-- This function is used to give an upper bound on the summands in Eisenstein series; it is
defined by `z ↦ min z.im √(z.im ^ 2 / (z.re ^ 2 + z.im ^ 2))`. -/
def r : ℝ := min z.im √(r1 z)
lemma r_pos : 0 < r z := by
simp only [r, lt_min_iff, im_pos, Real.sqrt_pos, r1_pos, and_self]
lemma r_lower_bound_on_verticalStrip {A B : ℝ} (h : 0 < B) (hz : z ∈ verticalStrip A B) :
r ⟨⟨A, B⟩, h⟩ ≤ r z := by
apply min_le_min hz.2
rw [Real.sqrt_le_sqrt_iff (by apply (r1_pos z).le)]
simp only [r1_eq, div_pow, one_div]
rw [inv_le_inv₀ (by positivity) (by positivity), add_le_add_iff_right, ← even_two.pow_abs]
gcongr
exacts [hz.1, hz.2]
lemma auxbound1 {c : ℝ} (d : ℝ) (hc : 1 ≤ c ^ 2) : r z ≤ ‖c * (z : ℂ) + d‖ := by
rcases z with ⟨z, hz⟩
have H1 : z.im ≤ √((c * z.re + d) ^ 2 + (c * z).im ^ 2) := by
rw [Real.le_sqrt' hz, im_ofReal_mul, mul_pow]
exact (le_mul_of_one_le_left (sq_nonneg _) hc).trans <| le_add_of_nonneg_left (sq_nonneg _)
simpa only [r, norm_def, normSq_apply, add_re, re_ofReal_mul, coe_re, ← pow_two, add_im, mul_im,
coe_im, ofReal_im, zero_mul, add_zero, min_le_iff] using Or.inl H1
lemma auxbound2 (c : ℝ) {d : ℝ} (hd : 1 ≤ d ^ 2) : r z ≤ ‖c * (z : ℂ) + d‖ := by
have H1 : √(r1 z) ≤ √((c * z.re + d) ^ 2 + (c * z.im) ^ 2) :=
(Real.sqrt_le_sqrt_iff (by positivity)).mpr (r1_aux_bound _ _ hd)
simpa only [r, norm_def, normSq_apply, add_re, re_ofReal_mul, coe_re, ofReal_re, ← pow_two,
add_im, im_ofReal_mul, coe_im, ofReal_im, add_zero, min_le_iff] using Or.inr H1
lemma div_max_sq_ge_one (x : Fin 2 → ℤ) (hx : x ≠ 0) :
1 ≤ (x 0 / ‖x‖) ^ 2 ∨ 1 ≤ (x 1 / ‖x‖) ^ 2 := by
refine (max_choice (x 0).natAbs (x 1).natAbs).imp (fun H0 ↦ ?_) (fun H1 ↦ ?_)
· have : x 0 ≠ 0 := by
rwa [← norm_ne_zero_iff, norm_eq_max_natAbs, H0, Nat.cast_ne_zero, Int.natAbs_ne_zero] at hx
simp only [norm_eq_max_natAbs, H0, Nat.cast_natAbs, Int.cast_abs, div_pow, sq_abs, ne_eq,
OfNat.ofNat_ne_zero, not_false_eq_true, pow_eq_zero_iff, Int.cast_eq_zero, this, div_self,
le_refl]
· have : x 1 ≠ 0 := by
rwa [← norm_ne_zero_iff, norm_eq_max_natAbs, H1, Nat.cast_ne_zero, Int.natAbs_ne_zero] at hx
simp only [norm_eq_max_natAbs, H1, Nat.cast_natAbs, Int.cast_abs, div_pow, sq_abs, ne_eq,
OfNat.ofNat_ne_zero, not_false_eq_true, pow_eq_zero_iff, Int.cast_eq_zero, this, div_self,
le_refl]
lemma r_mul_max_le {x : Fin 2 → ℤ} (hx : x ≠ 0) : r z * ‖x‖ ≤ ‖x 0 * (z : ℂ) + x 1‖ := by
have hn0 : ‖x‖ ≠ 0 := by rwa [norm_ne_zero_iff]
have h11 : x 0 * (z : ℂ) + x 1 = (x 0 / ‖x‖ * z + x 1 / ‖x‖) * ‖x‖ := by
rw [div_mul_eq_mul_div, ← add_div, div_mul_cancel₀ _ (mod_cast hn0)]
rw [norm_eq_max_natAbs, h11, norm_mul, norm_real, norm_norm, norm_eq_max_natAbs]
gcongr
· rcases div_max_sq_ge_one x hx with H1 | H2
· simpa only [norm_eq_max_natAbs, ofReal_div, ofReal_intCast] using auxbound1 z (x 1 / ‖x‖) H1
· simpa only [norm_eq_max_natAbs, ofReal_div, ofReal_intCast] using auxbound2 z (x 0 / ‖x‖) H2
/-- Upper bound for the summand `|c * z + d| ^ (-k)`, as a product of a function of `z` and a
function of `c, d`. -/
lemma summand_bound {k : ℝ} (hk : 0 ≤ k) (x : Fin 2 → ℤ) :
‖x 0 * (z : ℂ) + x 1‖ ^ (-k) ≤ (r z) ^ (-k) * ‖x‖ ^ (-k) := by
by_cases hx : x = 0
· simp only [hx, Pi.zero_apply, Int.cast_zero, zero_mul, add_zero, norm_zero]
by_cases h : -k = 0
· rw [h, Real.rpow_zero, Real.rpow_zero, one_mul]
· rw [Real.zero_rpow h, mul_zero]
· rw [← Real.mul_rpow (r_pos _).le (norm_nonneg _)]
exact Real.rpow_le_rpow_of_nonpos (mul_pos (r_pos _) (norm_pos_iff.mpr hx)) (r_mul_max_le z hx)
(neg_nonpos.mpr hk)
variable {z} in
lemma summand_bound_of_mem_verticalStrip {k : ℝ} (hk : 0 ≤ k) (x : Fin 2 → ℤ)
{A B : ℝ} (hB : 0 < B) (hz : z ∈ verticalStrip A B) :
‖x 0 * (z : ℂ) + x 1‖ ^ (-k) ≤ r ⟨⟨A, B⟩, hB⟩ ^ (-k) * ‖x‖ ^ (-k) := by
refine (summand_bound z hk x).trans (mul_le_mul_of_nonneg_right ?_ (by positivity))
exact Real.rpow_le_rpow_of_nonpos (r_pos _) (r_lower_bound_on_verticalStrip z hB hz)
(neg_nonpos.mpr hk)
lemma linear_isTheta_right (c : ℤ) (z : ℂ) :
(fun (d : ℤ) ↦ (c * z + d)) =Θ[cofinite] fun n ↦ (n : ℝ) := by
refine Asymptotics.IsLittleO.add_isTheta ?_ (Int.cast_complex_isTheta_cast_real )
rw [isLittleO_const_left]
exact Or.inr
(tendsto_norm_comp_cofinite_atTop_of_isClosedEmbedding Int.isClosedEmbedding_coe_real)
lemma linear_isTheta_left (d : ℤ) {z : ℂ} (hz : z ≠ 0) :
(fun (c : ℤ) ↦ (c * z + d)) =Θ[cofinite] fun n ↦ (n : ℝ) := by
apply IsTheta.add_isLittleO
· simp_rw [mul_comm]
apply Asymptotics.IsTheta.const_mul_left hz Int.cast_complex_isTheta_cast_real
· simp only [isLittleO_const_left, Int.cast_eq_zero,
tendsto_norm_comp_cofinite_atTop_of_isClosedEmbedding Int.isClosedEmbedding_coe_real, or_true]
lemma linear_inv_isBigO_right (c : ℤ) (z : ℂ) :
(fun (d : ℤ) ↦ (c * z + d)⁻¹) =O[cofinite] fun n ↦ (n : ℝ)⁻¹ :=
(linear_isTheta_right c z).inv.isBigO
lemma linear_inv_isBigO_left (d : ℤ) {z : ℂ} (hz : z ≠ 0) :
(fun (c : ℤ) ↦ (c * z + d)⁻¹) =O[cofinite] fun n ↦ (n : ℝ)⁻¹ :=
(linear_isTheta_left d hz).inv.isBigO
end bounding_functions
/-- The function `ℤ ^ 2 → ℝ` given by `x ↦ ‖x‖ ^ (-k)` is summable if `2 < k`. We prove this by
splitting into boxes using `Finset.box`. -/
lemma summable_one_div_norm_rpow {k : ℝ} (hk : 2 < k) :
Summable fun (x : Fin 2 → ℤ) ↦ ‖x‖ ^ (-k) := by
rw [← (finTwoArrowEquiv _).symm.summable_iff, summable_partition _ Int.existsUnique_mem_box]
· simp only [finTwoArrowEquiv_symm_apply, Function.comp_def]
refine ⟨fun n ↦ (hasSum_fintype (β := box (α := ℤ × ℤ) n) _).summable, ?_⟩
suffices Summable fun n : ℕ ↦ ∑' (_ : box (α := ℤ × ℤ) n), (n : ℝ) ^ (-k) by
refine this.congr fun n ↦ tsum_congr fun p ↦ ?_
simp only [← Int.mem_box.mp p.2, Nat.cast_max, norm_eq_max_natAbs, Matrix.cons_val_zero,
Matrix.cons_val_one]
simp only [tsum_fintype, univ_eq_attach, sum_const, card_attach, nsmul_eq_mul]
apply ((Real.summable_nat_rpow.mpr (by linarith : 1 - k < -1)).mul_left
8).of_norm_bounded_eventually_nat
filter_upwards [Filter.eventually_gt_atTop 0] with n hn
rw [Int.card_box hn.ne', Real.norm_of_nonneg (by positivity), sub_eq_add_neg,
Real.rpow_add (Nat.cast_pos.mpr hn), Real.rpow_one, Nat.cast_mul, Nat.cast_ofNat, mul_assoc]
· exact fun n ↦ Real.rpow_nonneg (norm_nonneg _) _
/-- If the inverse of a function `isBigO` to `(|(n : ℝ)| ^ a)⁻¹` for `1 < a`, then the function is
Summable. -/
lemma summable_inv_of_isBigO_rpow_inv {α : Type*} [NormedField α] [CompleteSpace α]
{f : ℤ → α} {a : ℝ} (hab : 1 < a)
(hf : (fun n ↦ (f n)⁻¹) =O[cofinite] fun n ↦ (|(n : ℝ)| ^ a)⁻¹) :
Summable fun n ↦ (f n)⁻¹ :=
summable_of_isBigO
((Real.summable_abs_int_rpow hab).congr fun b ↦ Real.rpow_neg (abs_nonneg ↑b) a) hf
/-- For `z : ℂ` the function `d : ℤ ↦ ((c z + d) ^ k)⁻¹` is Summable for `2 ≤ k`. -/
lemma linear_right_summable (z : ℂ) (c : ℤ) {k : ℤ} (hk : 2 ≤ k) :
Summable fun d : ℤ ↦ ((c * z + d) ^ k)⁻¹ := by
apply summable_inv_of_isBigO_rpow_inv (a := k) (by norm_cast)
lift k to ℕ using (by cutsat)
simp only [zpow_natCast, Int.cast_natCast, Real.rpow_natCast, ← inv_pow, ← abs_inv]
apply (linear_inv_isBigO_right c z).abs_right.pow
/-- For `z : ℂ` the function `c : ℤ ↦ ((c z + d) ^ k)⁻¹` is Summable for `2 ≤ k`. -/
lemma linear_left_summable {z : ℂ} (hz : z ≠ 0) (d : ℤ) {k : ℤ} (hk : 2 ≤ k) :
Summable fun c : ℤ ↦ ((c * z + d) ^ k)⁻¹ := by
apply summable_inv_of_isBigO_rpow_inv (a := k) (by norm_cast)
lift k to ℕ using (by cutsat)
simp only [zpow_natCast, Int.cast_natCast, Real.rpow_natCast, ← inv_pow, ← abs_inv]
apply (linear_inv_isBigO_left d hz).abs_right.pow
lemma summable_linear_sub_mul_linear_add (z : ℂ) (c₁ c₂ : ℤ) :
Summable fun n : ℤ ↦ ((c₁ * z - n) * (c₂ * z + n))⁻¹ := by
apply summable_inv_of_isBigO_rpow_inv (a := 2) (by norm_cast)
simp only [Real.rpow_two, abs_mul_abs_self, pow_two]
simpa [sub_eq_add_neg] using (linear_inv_isBigO_right c₂ z).mul
(linear_inv_isBigO_right c₁ z).comp_neg_int
end EisensteinSeries |
.lake/packages/mathlib/Mathlib/NumberTheory/ModularForms/EisensteinSeries/MDifferentiable.lean | import Mathlib.NumberTheory.ModularForms.EisensteinSeries.UniformConvergence
import Mathlib.Analysis.Complex.UpperHalfPlane.Manifold
import Mathlib.Analysis.Complex.LocallyUniformLimit
import Mathlib.Geometry.Manifold.MFDeriv.FDeriv
/-!
# Holomorphicity of Eisenstein series
We show that Eisenstein series of weight `k` and level `Γ(N)` with congruence condition
`a : Fin 2 → ZMod N` are holomorphic on the upper half plane, which is stated as being
MDifferentiable.
-/
noncomputable section
open UpperHalfPlane Filter Function Complex Manifold CongruenceSubgroup
namespace EisensteinSeries
/-- Auxiliary lemma showing that for any `k : ℤ` the function `z → 1/(c*z+d)^k` is
differentiable on `{z : ℂ | 0 < z.im}`. -/
lemma div_linear_zpow_differentiableOn (k : ℤ) (a : Fin 2 → ℤ) :
DifferentiableOn ℂ (fun z : ℂ => (a 0 * z + a 1) ^ (-k)) {z : ℂ | 0 < z.im} := by
rcases ne_or_eq a 0 with ha | rfl
· apply DifferentiableOn.zpow
· fun_prop
· left
exact fun z hz ↦ linear_ne_zero ⟨z, hz⟩
((comp_ne_zero_iff _ Int.cast_injective Int.cast_zero).mpr ha)
· simp only [Pi.zero_apply, Int.cast_zero, zero_mul, add_zero]
apply differentiableOn_const
/-- Auxiliary lemma showing that for any `k : ℤ` and `(a : Fin 2 → ℤ)`
the extension of `eisSummand` is differentiable on `{z : ℂ | 0 < z.im}`. -/
lemma eisSummand_extension_differentiableOn (k : ℤ) (a : Fin 2 → ℤ) :
DifferentiableOn ℂ (↑ₕeisSummand k a) {z : ℂ | 0 < z.im} := by
apply DifferentiableOn.congr (div_linear_zpow_differentiableOn k a)
intro z hz
lift z to ℍ using hz
apply comp_ofComplex
/-- Eisenstein series are MDifferentiable (i.e. holomorphic functions from `ℍ → ℂ`). -/
theorem eisensteinSeries_SIF_MDifferentiable {k : ℤ} {N : ℕ} (hk : 3 ≤ k) (a : Fin 2 → ZMod N) :
MDifferentiable 𝓘(ℂ) 𝓘(ℂ) (eisensteinSeries_SIF a k) := by
intro τ
suffices DifferentiableAt ℂ (↑ₕeisensteinSeries_SIF a k) τ.1 by
convert MDifferentiableAt.comp τ (DifferentiableAt.mdifferentiableAt this) τ.mdifferentiable_coe
exact funext fun z ↦ (comp_ofComplex (eisensteinSeries_SIF a k) z).symm
refine DifferentiableOn.differentiableAt ?_ (isOpen_upperHalfPlaneSet.mem_nhds τ.2)
exact (eisensteinSeries_tendstoLocallyUniformlyOn hk a).differentiableOn
(Eventually.of_forall fun s ↦ DifferentiableOn.fun_sum
fun _ _ ↦ eisSummand_extension_differentiableOn _ _) isOpen_upperHalfPlaneSet
end EisensteinSeries |
.lake/packages/mathlib/Mathlib/NumberTheory/ModularForms/EisensteinSeries/Basic.lean | import Mathlib.NumberTheory.ModularForms.Basic
import Mathlib.NumberTheory.ModularForms.EisensteinSeries.IsBoundedAtImInfty
import Mathlib.NumberTheory.ModularForms.EisensteinSeries.MDifferentiable
/-!
# Eisenstein series are Modular Forms
We show that Eisenstein series of weight `k` and level `Γ(N)` with congruence condition
`a : Fin 2 → ZMod N` are Modular Forms.
## TODO
Add q-expansions and prove that they are not all identically zero.
-/
noncomputable section
namespace ModularForm
open EisensteinSeries CongruenceSubgroup Matrix.SpecialLinearGroup
/-- This defines Eisenstein series as modular forms of weight `k`, level `Γ(N)` and congruence
condition given by `a : Fin 2 → ZMod N`. -/
def eisensteinSeries_MF {k : ℤ} {N : ℕ} [NeZero N] (hk : 3 ≤ k) (a : Fin 2 → ZMod N) :
ModularForm Γ(N) k where
toFun := eisensteinSeries_SIF a k
slash_action_eq' := (eisensteinSeries_SIF a k).slash_action_eq'
holo' := eisensteinSeries_SIF_MDifferentiable hk a
bdd_at_cusps' {c} hc := by
rw [Subgroup.IsArithmetic.isCusp_iff_isCusp_SL2Z] at hc
rw [OnePoint.isBoundedAt_iff_forall_SL2Z hc]
exact fun γ hγ ↦ isBoundedAtImInfty_eisensteinSeries_SIF a hk γ
/-- Normalised Eisenstein series of level 1 and weight `k`,
here they have been scaled by `1/2` since we sum over coprime pairs. -/
noncomputable def E {k : ℕ} (hk : 3 ≤ k) : ModularForm Γ(1) k :=
(1/2 : ℂ) • eisensteinSeries_MF (mod_cast hk) 0
end ModularForm |
.lake/packages/mathlib/Mathlib/NumberTheory/ModularForms/EisensteinSeries/UniformConvergence.lean | import Mathlib.Analysis.Normed.Group.FunctionSeries
import Mathlib.NumberTheory.ModularForms.EisensteinSeries.Defs
import Mathlib.NumberTheory.ModularForms.EisensteinSeries.Summable
/-!
# Uniform convergence of Eisenstein series
We show that the sum of `eisSummand` converges locally uniformly on `ℍ` to the Eisenstein series
of weight `k` and level `Γ(N)` with congruence condition `a : Fin 2 → ZMod N`.
## Outline of argument
The key lemma `r_mul_max_le` shows that, for `z ∈ ℍ` and `c, d ∈ ℤ` (not both zero),
`|c z + d|` is bounded below by `r z * max (|c|, |d|)`, where `r z` is an explicit function of `z`
(independent of `c, d`) satisfying `0 < r z < 1` for all `z`.
We then show in `summable_one_div_rpow_max` that the sum of `max (|c|, |d|) ^ (-k)` over
`(c, d) ∈ ℤ × ℤ` is convergent for `2 < k`. This is proved by decomposing `ℤ × ℤ` using the
`Finset.box` lemmas.
-/
noncomputable section
open Complex UpperHalfPlane Set Finset CongruenceSubgroup Topology
open scoped UpperHalfPlane
variable (z : ℍ)
namespace EisensteinSeries
/-- The sum defining the Eisenstein series (of weight `k` and level `Γ(N)` with congruence
condition `a : Fin 2 → ZMod N`) converges locally uniformly on `ℍ`. -/
theorem eisensteinSeries_tendstoLocallyUniformly {k : ℤ} (hk : 3 ≤ k) {N : ℕ} (a : Fin 2 → ZMod N) :
TendstoLocallyUniformly (fun (s : Finset (gammaSet N 1 a)) ↦ (∑ x ∈ s, eisSummand k x ·))
(eisensteinSeries a k ·) Filter.atTop := by
have hk' : (2 : ℝ) < k := by norm_cast
have p_sum : Summable fun x : gammaSet N 1 a ↦ ‖x.val‖ ^ (-k) :=
mod_cast (summable_one_div_norm_rpow hk').subtype (gammaSet N 1 a)
simp only [tendstoLocallyUniformly_iff_forall_isCompact, eisensteinSeries]
intro K hK
obtain ⟨A, B, hB, HABK⟩ := subset_verticalStrip_of_isCompact hK
refine (tendstoUniformlyOn_tsum (hu := p_sum.mul_left <| r ⟨⟨A, B⟩, hB⟩ ^ (-k : ℝ))
(fun p z hz ↦ ?_)).mono HABK
simpa only [eisSummand, one_div, ← zpow_neg, norm_zpow, ← Real.rpow_intCast,
Int.cast_neg] using summand_bound_of_mem_verticalStrip (by positivity) p hB hz
/-- Variant of `eisensteinSeries_tendstoLocallyUniformly` formulated with maps `ℂ → ℂ`, which is
nice to have for holomorphicity later. -/
lemma eisensteinSeries_tendstoLocallyUniformlyOn {k : ℤ} {N : ℕ} (hk : 3 ≤ k)
(a : Fin 2 → ZMod N) : TendstoLocallyUniformlyOn (fun (s : Finset (gammaSet N 1 a)) ↦
↑ₕ(fun (z : ℍ) ↦ ∑ x ∈ s, eisSummand k x z)) (↑ₕ(eisensteinSeries_SIF a k).toFun)
Filter.atTop {z : ℂ | 0 < z.im} := by
rw [← Subtype.coe_image_univ {z : ℂ | 0 < z.im}]
apply TendstoLocallyUniformlyOn.comp (s := ⊤) _ _ _ (OpenPartialHomeomorph.continuousOn_symm _)
· simp only [SlashInvariantForm.toFun_eq_coe, Set.top_eq_univ, tendstoLocallyUniformlyOn_univ]
apply eisensteinSeries_tendstoLocallyUniformly hk
· simp only [IsOpenEmbedding.toOpenPartialHomeomorph_target, Set.top_eq_univ, mapsTo_range_iff,
Set.mem_univ, forall_const]
end EisensteinSeries |
.lake/packages/mathlib/Mathlib/NumberTheory/ModularForms/EisensteinSeries/IsBoundedAtImInfty.lean | import Mathlib.Analysis.Complex.UpperHalfPlane.FunctionsBoundedAtInfty
import Mathlib.NumberTheory.ModularForms.EisensteinSeries.Defs
import Mathlib.NumberTheory.ModularForms.EisensteinSeries.Summable
import Mathlib.NumberTheory.ModularForms.Identities
/-!
# Boundedness of Eisenstein series
We show that Eisenstein series of weight `k` and level `Γ(N)` with congruence condition
`a : Fin 2 → ZMod N` are bounded at infinity.
## Outline of argument
We need to bound the value of the Eisenstein series (acted on by `A : SL(2,ℤ)`)
at a given point `z` in the upper half plane. Since these are modular forms of level `Γ(N)`,
it suffices to prove this for `z ∈ verticalStrip N z.im`.
We can then, first observe that the slash action just changes our `a` to `(a ᵥ* A)` and
we then use our bounds for Eisenstein series in these vertical strips to get the result.
-/
noncomputable section
open ModularForm UpperHalfPlane Matrix SlashInvariantForm CongruenceSubgroup
open scoped MatrixGroups
namespace EisensteinSeries
lemma summable_norm_eisSummand {k : ℤ} (hk : 3 ≤ k) (z : ℍ) :
Summable fun (x : Fin 2 → ℤ) ↦ ‖(eisSummand k x z)‖ := by
have hk' : (2 : ℝ) < k := by norm_cast
apply ((summable_one_div_norm_rpow hk').mul_left <| r z ^ (-k : ℝ)).of_nonneg_of_le
(fun _ ↦ norm_nonneg _)
intro b
simp only [eisSummand, norm_zpow]
exact_mod_cast summand_bound z (show 0 ≤ (k : ℝ) by positivity) b
/-- The norm of the restricted sum is less than the full sum of the norms. -/
lemma norm_le_tsum_norm (N : ℕ) (a : Fin 2 → ZMod N) (k : ℤ) (hk : 3 ≤ k) (z : ℍ) :
‖eisensteinSeries a k z‖ ≤ ∑' (x : Fin 2 → ℤ), ‖eisSummand k x z‖ := by
simp_rw [eisensteinSeries]
apply le_trans (norm_tsum_le_tsum_norm ((summable_norm_eisSummand hk z).subtype _))
(Summable.tsum_subtype_le (fun (x : Fin 2 → ℤ) ↦ ‖(eisSummand k x z)‖) _ (fun _ ↦ norm_nonneg _)
(summable_norm_eisSummand hk z))
/-- Eisenstein series are bounded at infinity. -/
theorem isBoundedAtImInfty_eisensteinSeries_SIF {N : ℕ} [NeZero N] (a : Fin 2 → ZMod N) {k : ℤ}
(hk : 3 ≤ k) (A : SL(2, ℤ)) : IsBoundedAtImInfty ((eisensteinSeries_SIF a k).toFun ∣[k] A) := by
simp_rw [UpperHalfPlane.isBoundedAtImInfty_iff, eisensteinSeries_SIF] at *
refine ⟨∑'(x : Fin 2 → ℤ), r ⟨⟨N, 2⟩, Nat.ofNat_pos⟩ ^ (-k) * ‖x‖ ^ (-k), 2, ?_⟩
intro z hz
obtain ⟨n, hn⟩ := (ModularGroup_T_zpow_mem_verticalStrip z (NeZero.pos N))
rw [eisensteinSeries_slash_apply, ← eisensteinSeries_SIF_apply,
← T_zpow_width_invariant N k n (eisensteinSeries_SIF (a ᵥ* A) k) z]
apply le_trans (norm_le_tsum_norm N (a ᵥ* A) k hk _)
have hk' : (2 : ℝ) < k := by norm_cast
apply (summable_norm_eisSummand hk _).tsum_le_tsum _
· exact_mod_cast (summable_one_div_norm_rpow hk').mul_left <| r ⟨⟨N, 2⟩, Nat.ofNat_pos⟩ ^ (-k)
· intro x
simp_rw [eisSummand, norm_zpow]
exact_mod_cast
summand_bound_of_mem_verticalStrip (lt_trans two_pos hk').le x two_pos
(verticalStrip_anti_right N hz hn)
end EisensteinSeries |
.lake/packages/mathlib/Mathlib/NumberTheory/ModularForms/EisensteinSeries/Defs.lean | import Mathlib.Algebra.EuclideanDomain.Int
import Mathlib.NumberTheory.ModularForms.SlashInvariantForms
import Mathlib.RingTheory.EuclideanDomain
import Mathlib.NumberTheory.ModularForms.CongruenceSubgroups
/-!
# Eisenstein Series
## Main definitions
* We define Eisenstein series of level `Γ(N)` for any `N : ℕ` and weight `k : ℤ` as the infinite sum
`∑' v : (Fin 2 → ℤ), (1 / (v 0 * z + v 1) ^ k)`, where `z : ℍ` and `v` ranges over all pairs of
coprime integers congruent to a fixed pair `(a, b)` modulo `N`. Note that by using `(Fin 2 → ℤ)`
instead of `ℤ × ℤ` we can state all of the required equivalences using matrices and vectors, which
makes working with them more convenient.
* We show that they define a slash invariant form of level `Γ(N)` and weight `k`.
## References
* [F. Diamond and J. Shurman, *A First Course in Modular Forms*][diamondshurman2005]
-/
noncomputable section
open ModularForm UpperHalfPlane Complex Matrix CongruenceSubgroup Set
open scoped MatrixGroups
namespace EisensteinSeries
variable (N r : ℕ) (a : Fin 2 → ZMod N)
section gammaSet_def
/-- The set of pairs of integers congruent to `a` mod `N` and with `gcd` equal to `r`. -/
def gammaSet := {v : Fin 2 → ℤ | (↑) ∘ v = a ∧ (v 0).gcd (v 1) = r}
open scoped Function in -- required for scoped `on` notation
lemma pairwise_disjoint_gammaSet : Pairwise (Disjoint on gammaSet N r) := by
refine fun u v huv ↦ ?_
contrapose! huv
obtain ⟨f, hf⟩ := Set.not_disjoint_iff.mp huv
exact hf.1.1.symm.trans hf.2.1
/-- For level `N = 1`, the gamma sets are all equal. -/
lemma gammaSet_one_const (a a' : Fin 2 → ZMod 1) : gammaSet 1 r a = gammaSet 1 r a' :=
congr_arg _ (Subsingleton.elim _ _)
/-- For level `N = 1`, the gamma sets simplify to only a `gcd` condition. -/
lemma gammaSet_one_eq (a : Fin 2 → ZMod 1) :
gammaSet 1 r a = {v : Fin 2 → ℤ | (v 0).gcd (v 1) = r} := by
simp [gammaSet, Subsingleton.eq_zero]
lemma gammaSet_one_mem_iff (v : Fin 2 → ℤ) : v ∈ gammaSet 1 r 0 ↔ (v 0).gcd (v 1) = r := by
simp [gammaSet, Subsingleton.eq_zero]
/-- For level `N = 1`, the gamma sets are all equivalent; this is the equivalence. -/
def gammaSet_one_equiv (a a' : Fin 2 → ZMod 1) : gammaSet 1 r a ≃ gammaSet 1 r a' :=
Equiv.setCongr (gammaSet_one_const r a a')
/-- The map from `Fin 2 → ℤ` sending `![a,b]` to `a.gcd b`. -/
abbrev finGcdMap (v : Fin 2 → ℤ) : ℕ := (v 0).gcd (v 1)
lemma finGcdMap_div {r : ℕ} [NeZero r] (v : Fin 2 → ℤ) (hv : finGcdMap v = r) :
IsCoprime ((v / r) 0 ) ((v / r) 1) := by
rw [← hv]
apply isCoprime_div_gcd_div_gcd_of_gcd_ne_zero
have := NeZero.ne r
aesop
lemma finGcdMap_smul {r : ℕ} (a : ℤ) {v : Fin 2 → ℤ} (hv : finGcdMap v = r) :
finGcdMap (a • v) = a.natAbs * r := by
simp [finGcdMap, Int.gcd_mul_left, hv]
/-- An abbreviation of the map which divides a integer vector by an integer. -/
abbrev divIntMap (r : ℤ) {m : ℕ} (v : Fin m → ℤ) : Fin m → ℤ := v / r
lemma mem_gammaSet_one (v : Fin 2 → ℤ) : v ∈ gammaSet 1 1 0 ↔ IsCoprime (v 0) (v 1) := by
rw [gammaSet_one_mem_iff, Int.isCoprime_iff_gcd_eq_one]
lemma gammaSet_div_gcd {r : ℕ} {v : Fin 2 → ℤ} (hv : v ∈ (gammaSet 1 r 0)) (i : Fin 2) :
(r : ℤ) ∣ v i := by
fin_cases i <;> simp [← hv.2, Int.gcd_dvd_left, Int.gcd_dvd_right]
lemma gammaSet_div_gcd_to_gammaSet10_bijection (r : ℕ) [NeZero r] :
Set.BijOn (divIntMap r) (gammaSet 1 r 0) (gammaSet 1 1 0) := by
refine ⟨?_, ?_, ?_⟩
· intro x hx
simp only [divIntMap, mem_gammaSet_one] at *
exact finGcdMap_div _ hx.2
· intro x hx v hv hv2
ext i
exact (Int.ediv_left_inj (gammaSet_div_gcd hx i) (gammaSet_div_gcd hv i)).mp
(congr_fun hv2 i)
· intro x hx
use r • x
simp only [nsmul_eq_mul, divIntMap, Int.cast_natCast]
constructor
· rw [mem_gammaSet_one, Int.isCoprime_iff_gcd_eq_one] at hx
exact ⟨Subsingleton.eq_zero _, by simp [Int.gcd_mul_left, hx]⟩
· ext i
simp_all [NeZero.ne r]
lemma gammaSet_eq_gcd_mul_divIntMap {r : ℕ} {v : Fin 2 → ℤ} (hv : v ∈ gammaSet 1 r 0) :
v = r • (divIntMap r v) := by
by_cases hr : r = 0
· have hv := hv.2
simp only [hr, Fin.isValue, Int.gcd_eq_zero_iff, CharP.cast_eq_zero, zero_smul] at *
ext i
fin_cases i <;> simp [hv]
· ext i
simp_all [Pi.smul_apply, divIntMap, ← Int.mul_ediv_assoc _ (gammaSet_div_gcd hv i)]
/-- The equivalence between `gammaSet 1 r 0` and `gammaSet 1 1 0` for non-zero `r`. -/
def gammaSetDivGcdEquiv (r : ℕ) [NeZero r] : gammaSet 1 r 0 ≃ gammaSet 1 1 0 :=
Set.BijOn.equiv _ (gammaSet_div_gcd_to_gammaSet10_bijection r)
@[simp]
lemma gammaSetDivGcdEquiv_eq (r : ℕ) [NeZero r] (v : gammaSet 1 r 0) :
(gammaSetDivGcdEquiv r) v = divIntMap r v.1 := rfl
/-- The equivalence between `(Fin 2 → ℤ)` and `Σ n : ℕ, gammaSet 1 n 0)` . -/
def gammaSetDivGcdSigmaEquiv : (Fin 2 → ℤ) ≃ (Σ r : ℕ, gammaSet 1 r 0) := by
apply (Equiv.sigmaFiberEquiv finGcdMap).symm.trans
refine Equiv.sigmaCongrRight fun b => ?_
apply Equiv.setCongr
rw [gammaSet_one_eq]
rfl
@[simp]
lemma gammaSetDivGcdSigmaEquiv_symm_eq (v : Σ r : ℕ, gammaSet 1 r 0) :
(gammaSetDivGcdSigmaEquiv.symm v) = v.2 := rfl
end gammaSet_def
variable {N a r} [NeZero r]
section gamma_action
/-- Right-multiplying a vector by a matrix in `SL(2, ℤ)` doesn't change its gcd. -/
lemma vecMulSL_gcd {v : Fin 2 → ℤ} (hab : finGcdMap v = r) (A : SL(2, ℤ)) :
finGcdMap (v ᵥ* A.1) = r := by
have hvr : v = r • (v / r) := by
ext i
refine Eq.symm (Int.mul_ediv_cancel' ?_)
fin_cases i <;> simp [← hab, Int.gcd_dvd_left, Int.gcd_dvd_right]
rw [hvr, smul_vecMul]
simpa using finGcdMap_smul r (Int.isCoprime_iff_gcd_eq_one.mp ((finGcdMap_div v hab).vecMulSL A))
/-- Right-multiplying by `γ ∈ SL(2, ℤ)` sends `gammaSet N a` to `gammaSet N (a ᵥ* γ)`. -/
lemma vecMul_SL2_mem_gammaSet {v : Fin 2 → ℤ} (hv : v ∈ gammaSet N r a)
(γ : SL(2, ℤ)) : v ᵥ* γ ∈ gammaSet N r (a ᵥ* γ) := by
refine ⟨?_, vecMulSL_gcd hv.2 γ⟩
have := RingHom.map_vecMul (m := Fin 2) (n := Fin 2) (Int.castRingHom (ZMod N)) γ v
simp only [eq_intCast, Int.coe_castRingHom] at this
simp_rw [Function.comp_def, this, hv.1]
simp
variable (a) in
/-- The bijection between `GammaSets` given by multiplying by an element of `SL(2, ℤ)`. -/
def gammaSetEquiv (γ : SL(2, ℤ)) : gammaSet N r a ≃ gammaSet N r (a ᵥ* γ) where
toFun v := ⟨v.1 ᵥ* γ, vecMul_SL2_mem_gammaSet v.2 γ⟩
invFun v := ⟨v.1 ᵥ* ↑(γ⁻¹), by
have := vecMul_SL2_mem_gammaSet v.2 γ⁻¹
rw [vecMul_vecMul, ← SpecialLinearGroup.coe_mul] at this
simpa only [SpecialLinearGroup.map_apply_coe, RingHom.mapMatrix_apply, Int.coe_castRingHom,
map_inv, mul_inv_cancel, SpecialLinearGroup.coe_one, vecMul_one]⟩
left_inv v := by simp_rw [vecMul_vecMul, ← SpecialLinearGroup.coe_mul, mul_inv_cancel,
SpecialLinearGroup.coe_one, vecMul_one]
right_inv v := by simp_rw [vecMul_vecMul, ← SpecialLinearGroup.coe_mul, inv_mul_cancel,
SpecialLinearGroup.coe_one, vecMul_one]
end gamma_action
section eisSummand
/-- The function on `(Fin 2 → ℤ)` whose sum defines an Eisenstein series. -/
def eisSummand (k : ℤ) (v : Fin 2 → ℤ) (z : ℍ) : ℂ := (v 0 * z + v 1) ^ (-k)
/-- How the `eisSummand` function changes under the Moebius action. -/
theorem eisSummand_SL2_apply (k : ℤ) (i : (Fin 2 → ℤ)) (A : SL(2, ℤ)) (z : ℍ) :
eisSummand k i (A • z) = (denom A z) ^ k * eisSummand k (i ᵥ* A) z := by
simp only [eisSummand, vecMul, vec2_dotProduct, denom, UpperHalfPlane.specialLinearGroup_apply]
have h (a b c d u v : ℂ) (hc : c * z + d ≠ 0) : (u * ((a * z + b) / (c * z + d)) + v) ^ (-k) =
(c * z + d) ^ k * ((u * a + v * c) * z + (u * b + v * d)) ^ (-k) := by
replace hc : z * c + d ≠ 0 := by convert hc using 1; ring
field_simp
simp [div_zpow]
ring_nf
simpa using h (hc := denom_ne_zero A z) ..
end eisSummand
variable (a)
/-- An Eisenstein series of weight `k` and level `Γ(N)`, with congruence condition `a`. -/
def _root_.eisensteinSeries (k : ℤ) (z : ℍ) : ℂ := ∑' x : gammaSet N 1 a, eisSummand k x z
lemma eisensteinSeries_slash_apply (k : ℤ) (γ : SL(2, ℤ)) :
eisensteinSeries a k ∣[k] γ = eisensteinSeries (a ᵥ* γ) k := by
ext1 z
simp_rw [SL_slash_apply, zpow_neg,
mul_inv_eq_iff_eq_mul₀ (zpow_ne_zero _ <| denom_ne_zero _ z),
eisensteinSeries, eisSummand_SL2_apply, tsum_mul_left, mul_comm (_ ^ k)]
congr 1
exact (gammaSetEquiv a γ).tsum_eq (eisSummand k · z)
/-- The SlashInvariantForm defined by an Eisenstein series of weight `k : ℤ`, level `Γ(N)`,
and congruence condition given by `a : Fin 2 → ZMod N`. -/
def eisensteinSeries_SIF (k : ℤ) : SlashInvariantForm (Gamma N) k where
toFun := eisensteinSeries a k
slash_action_eq' A hA := by
obtain ⟨A, (hA : A ∈ Γ(N)), rfl⟩ := hA
simp [SpecialLinearGroup.mapGL, ← SL_slash, eisensteinSeries_slash_apply, Gamma_mem'.mp hA]
lemma eisensteinSeries_SIF_apply (k : ℤ) (z : ℍ) :
eisensteinSeries_SIF a k z = eisensteinSeries a k z := rfl
end EisensteinSeries |
.lake/packages/mathlib/Mathlib/NumberTheory/ModularForms/EisensteinSeries/QExpansion.lean | import Mathlib.Analysis.Complex.SummableUniformlyOn
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Cotangent
import Mathlib.NumberTheory.LSeries.Dirichlet
import Mathlib.NumberTheory.LSeries.HurwitzZetaValues
import Mathlib.NumberTheory.ModularForms.EisensteinSeries.Basic
import Mathlib.NumberTheory.TsumDivsorsAntidiagonal
/-!
# Eisenstein series q-expansions
We give the q-expansion of Eisenstein series of weight `k` and level 1. In particular, we prove
`EisensteinSeries.q_expansion_bernoulli` which says that for even `k` with `3 ≤ k`
Eisenstein series can we written as `1 - (2k / bernoulli k) ∑' n, σ_{k-1}(n) q^n` where
`q = exp(2πiz)` and `σ_{k-1}(n)` is the sum of the `(k-1)`-th powers of the divisors of `n`.
We need `k` to be even so that the Eisenstein series are non-zero and we require `k ≥ 3` so that
the series converges absolutely.
The proof relies on the identity
`∑' n : ℤ, 1 / (z + n) ^ (k + 1) = ((-2πi)^(k+1) / k!) ∑' n : ℕ, n^k q^n` which comes from
differentiating the expansion of `π cot(πz)` in terms of exponentials. Since our Eisenstein series
are defined as sums over coprime integer pairs, we also need to relate these to sums over all pairs
of integers, which is done in `tsum_eisSummand_eq_riemannZeta_mul_eisensteinSeries`. This then
gives the q-expansion with a Riemann zeta factor, which we simplify using the formula for
`ζ(k)` in terms of Bernoulli numbers to get the final result.
-/
open Set Metric TopologicalSpace Function Filter Complex ArithmeticFunction
ModularForm EisensteinSeries
open scoped Topology Real Nat Complex Pointwise ArithmeticFunction.sigma
open _root_.UpperHalfPlane hiding I
local notation "ℍₒ" => upperHalfPlaneSet
private lemma iteratedDerivWithin_cexp_aux (k m : ℕ) (p : ℝ) {S : Set ℂ} (hs : IsOpen S) :
EqOn (iteratedDerivWithin k (fun s : ℂ ↦ cexp (2 * π * I * m * s / p)) S)
(fun s ↦ (2 * π * I * m / p) ^ k * cexp (2 * π * I * m * s / p)) S := by
apply EqOn.trans (iteratedDerivWithin_of_isOpen hs)
intro x hx
have : (fun s ↦ cexp (2 * π * I * m * s / p)) = fun s ↦ cexp (((2 * π * I * m) / p) * s) := by
ext z
ring_nf
simp only [this, iteratedDeriv_cexp_const_mul]
ring_nf
private lemma aux_IsBigO_mul (k l : ℕ) (p : ℝ) {f : ℕ → ℂ}
(hf : f =O[atTop] fun n ↦ ((n ^ l) : ℝ)) :
(fun n ↦ f n * (2 * π * I * n / p) ^ k) =O[atTop] fun n ↦ (↑(n ^ (l + k)) : ℝ) := by
have h0 : (fun n : ℕ ↦ (2 * π * I * n / p) ^ k) =O[atTop] fun n ↦ ((n ^ k) : ℝ) := by
have h1 : (fun n : ℕ ↦ (2 * π * I * n / p) ^ k) =
fun n : ℕ ↦ ((2 * π * I / p) ^ k) * n ^ k := by
ext z
ring
simpa [h1] using isBigO_ofReal_right.mp (Asymptotics.isBigO_const_mul_self
((2 * π * I / p) ^ k) (fun (n : ℕ) ↦ (↑(n ^ k) : ℝ)) atTop)
simp only [Nat.cast_pow]
convert hf.mul h0
ring
open BoundedContinuousFunction in
/-- The infinte sum of `k`-th iterated derivative of the complex exponential multiplied by a
function that grows polynomially is absolutely and uniformly convergent. -/
theorem summableLocallyUniformlyOn_iteratedDerivWithin_smul_cexp (k l : ℕ) {f : ℕ → ℂ} {p : ℝ}
(hp : 0 < p) (hf : f =O[atTop] (fun n ↦ ((n ^ l) : ℝ))) :
SummableLocallyUniformlyOn (fun n ↦ (f n) •
iteratedDerivWithin k (fun z ↦ cexp (2 * π * I * z / p) ^ n) ℍₒ) ℍₒ := by
apply SummableLocallyUniformlyOn_of_locally_bounded isOpen_upperHalfPlaneSet
intro K hK hKc
have : CompactSpace K := isCompact_univ_iff.mp (isCompact_iff_isCompact_univ.mp hKc)
let c : ContinuousMap K ℂ := ⟨fun r : K ↦ Complex.exp (2 * π * I * r / p), by fun_prop⟩
let r : ℝ := ‖mkOfCompact c‖
have hr : ‖r‖ < 1 := by
simp only [norm_norm, r, norm_lt_iff_of_compact Real.zero_lt_one, mkOfCompact_apply,
ContinuousMap.coe_mk, c]
intro x
have h1 : cexp (2 * π * I * (x / p)) = cexp (2 * π * I * x / p) := by
ring_nf
simpa using h1 ▸ norm_exp_two_pi_I_lt_one ⟨((x : ℂ) / p), by aesop⟩
refine ⟨_, by simpa using (summable_norm_mul_geometric_of_norm_lt_one' hr
(Asymptotics.isBigO_norm_left.mpr (aux_IsBigO_mul k l p hf))), fun n z hz ↦ ?_⟩
have h0 := pow_le_pow_left₀ (norm_nonneg _) (norm_coe_le_norm (mkOfCompact c) ⟨z, hz⟩) n
simp only [norm_mkOfCompact, mkOfCompact_apply, ContinuousMap.coe_mk, ← exp_nsmul', Pi.smul_apply,
iteratedDerivWithin_cexp_aux k n p isOpen_upperHalfPlaneSet (hK hz), smul_eq_mul,
norm_mul, norm_pow, Complex.norm_div, norm_ofNat, norm_real, Real.norm_eq_abs, norm_I, mul_one,
norm_natCast, abs_norm, ge_iff_le, r, c] at *
rw [← mul_assoc]
gcongr
convert h0
rw [← norm_pow, ← exp_nsmul']
/-- This is a version of `summableLocallyUniformlyOn_iteratedDerivWithin_smul_cexp` for level one
and q-expansion coefficients all `1`. -/
theorem summableLocallyUniformlyOn_iteratedDerivWithin_cexp (k : ℕ) :
SummableLocallyUniformlyOn
(fun n ↦ iteratedDerivWithin k (fun z ↦ cexp (2 * π * I * z) ^ n) ℍₒ) ℍₒ := by
have h0 : (fun n : ℕ ↦ (1 : ℂ)) =O[atTop] fun n ↦ ((n ^ 1) : ℝ) := by
simp only [Asymptotics.isBigO_iff, norm_one, norm_pow, Real.norm_natCast,
eventually_atTop, ge_iff_le]
exact ⟨1, 1, fun b hb ↦ by norm_cast; simp [hb]⟩
simpa using summableLocallyUniformlyOn_iteratedDerivWithin_smul_cexp k 1 (p := 1)
(by norm_num) h0
lemma differentiableAt_iteratedDerivWithin_cexp (n a : ℕ) {s : Set ℂ} (hs : IsOpen s)
{r : ℂ} (hr : r ∈ s) : DifferentiableAt ℂ
(iteratedDerivWithin a (fun z ↦ cexp (2 * π * I * z) ^ n) s) r := by
apply DifferentiableOn.differentiableAt _ (hs.mem_nhds hr)
suffices DifferentiableOn ℂ (iteratedDeriv a (fun z ↦ cexp (2 * π * I * z) ^ n)) s by
apply this.congr (iteratedDerivWithin_of_isOpen hs)
fun_prop
lemma iteratedDerivWithin_tsum_cexp_eq (k : ℕ) (z : ℍ) :
iteratedDerivWithin k (fun z ↦ ∑' n : ℕ, cexp (2 * π * I * z) ^ n) ℍₒ z =
∑' n : ℕ, iteratedDerivWithin k (fun s : ℂ ↦ cexp (2 * π * I * s) ^ n) ℍₒ z := by
rw [iteratedDerivWithin_tsum k isOpen_upperHalfPlaneSet (by simpa using z.2)]
· exact fun x hx ↦ summable_geometric_iff_norm_lt_one.mpr
(UpperHalfPlane.norm_exp_two_pi_I_lt_one ⟨x, hx⟩)
· exact fun n _ _ ↦ summableLocallyUniformlyOn_iteratedDerivWithin_cexp n
· exact fun n l z hl hz ↦ differentiableAt_iteratedDerivWithin_cexp n l
isOpen_upperHalfPlaneSet hz
lemma contDiffOn_tsum_cexp (k : ℕ∞) :
ContDiffOn ℂ k (fun z : ℂ ↦ ∑' n : ℕ, cexp (2 * π * I * z) ^ n) ℍₒ :=
contDiffOn_of_differentiableOn_deriv fun m _ z hz ↦
(((summableLocallyUniformlyOn_iteratedDerivWithin_cexp m).differentiableOn
isOpen_upperHalfPlaneSet (fun n _ hz ↦ differentiableAt_iteratedDerivWithin_cexp n m
isOpen_upperHalfPlaneSet hz)) z hz).congr (fun z hz ↦ iteratedDerivWithin_tsum_cexp_eq m ⟨z, hz⟩)
(iteratedDerivWithin_tsum_cexp_eq m ⟨z, hz⟩)
private lemma iteratedDerivWithin_tsum_exp_aux_eq {k : ℕ} (hk : 1 ≤ k) (z : ℍ) :
iteratedDerivWithin k (fun z ↦ ((π * I) -
(2 * π * I) * ∑' n : ℕ, cexp (2 * π * I * z) ^ n)) ℍₒ z =
-(2 * π * I) ^ (k + 1) * ∑' n : ℕ, n ^ k * cexp (2 * π * I * z) ^ n := by
have : iteratedDerivWithin k (fun z ↦ ((π * I) -
(2 * π * I) * ∑' n : ℕ, cexp (2 * π * I * z) ^ n)) ℍₒ z =
-(2 * π * I) * ∑' n : ℕ, iteratedDerivWithin k (fun s : ℂ ↦ cexp (2 * π * I * s) ^ n) ℍₒ z := by
rw [iteratedDerivWithin_const_sub hk, iteratedDerivWithin_fun_neg,
iteratedDerivWithin_const_mul (by simpa using z.2) (isOpen_upperHalfPlaneSet.uniqueDiffOn)]
· simp only [iteratedDerivWithin_tsum_cexp_eq, neg_mul]
· exact (contDiffOn_tsum_cexp k).contDiffWithinAt (by simpa using z.2)
have h : -(2 * π * I * (2 * π * I) ^ k) * ∑' (n : ℕ), n ^ k * cexp (2 * π * I * z) ^ n =
-(2 * π * I) * ∑' n : ℕ, (2 * π * I * n) ^ k * cexp (2 * π * I * z) ^ n := by
simp_rw [← tsum_mul_left]
congr
ext y
ring
simp only [this, neg_mul, pow_succ', h, neg_inj, mul_eq_mul_left_iff, mul_eq_zero,
OfNat.ofNat_ne_zero, ofReal_eq_zero, Real.pi_ne_zero, or_self, I_ne_zero, or_false]
congr
ext n
have := exp_nsmul' (p := 1) (a := 2 * π * I) (n := n)
simp_rw [div_one] at this
simpa [this, UpperHalfPlane.coe] using
iteratedDerivWithin_cexp_aux k n 1 isOpen_upperHalfPlaneSet z.2
/-- This is one key identity relating infinite series to q-expansions which shows that
`∑' n, 1 / (z + n) ^ (k + 1) = ((-2 π I) ^ (k + 1) / k !) * ∑' n, n ^ k q ^n` where
`q = cexp (2 π I z)`. -/
theorem EisensteinSeries.qExpansion_identity {k : ℕ} (hk : 1 ≤ k) (z : ℍ) :
∑' n : ℤ, 1 / ((z : ℂ) + n) ^ (k + 1) = ((-2 * π * I) ^ (k + 1) / k !) *
∑' n : ℕ, n ^ k * cexp (2 * π * I * z) ^ n := by
have : (-1) ^ k * k ! * ∑' n : ℤ, 1 / ((z : ℂ) + n) ^ (k + 1) =
-(2 * π * I) ^ (k + 1) * ∑' n : ℕ, n ^ k * cexp (2 * π * I * z) ^ n := by
rw [← iteratedDerivWithin_tsum_exp_aux_eq hk z,
← iteratedDerivWithin_cot_pi_mul_eq_mul_tsum_div_pow hk (by simpa using z.2)]
exact iteratedDerivWithin_congr (fun x hx ↦ by (simpa using pi_mul_cot_pi_q_exp ⟨x, hx⟩))
(by simpa using z.2)
simp_rw [(eq_inv_mul_iff_mul_eq₀ (by simp [Nat.factorial_ne_zero])).mpr this, ← tsum_mul_left]
congr
ext n
rw [show (-2 * π * I) ^ (k + 1) = (-1) ^ (k + 1) * (2 * π * I) ^ (k + 1) by rw [← neg_pow]; ring]
field_simp
ring_nf
simp [Nat.mul_two]
lemma summable_pow_mul_cexp (k : ℕ) (e : ℕ+) (z : ℍ) :
Summable fun c : ℕ ↦ (c : ℂ) ^ k * cexp (2 * π * I * e * z) ^ c := by
have he : 0 < (e * (z : ℂ)).im := by
simpa using z.2
apply ((summableLocallyUniformlyOn_iteratedDerivWithin_smul_cexp 0 k (p := 1)
(f := fun n ↦ (n ^ k : ℂ)) (by norm_num)
(by simp [← Complex.isBigO_ofReal_right, Asymptotics.isBigO_refl])).summable he).congr
grind [ofReal_one, iteratedDerivWithin_zero, Pi.smul_apply, smul_eq_mul]
/-- This is a version of `EisensteinSeries.qExpansion_identity` for positive naturals,
which shows that `∑' n, 1 / (z + n) ^ (k + 1) = ((-2 π I) ^ (k + 1) / k !) * ∑' n : ℕ+, n ^ k q ^n`
where `q = cexp (2 π I z)`. -/
theorem EisensteinSeries.qExpansion_identity_pnat {k : ℕ} (hk : 1 ≤ k) (z : ℍ) :
∑' n : ℤ, 1 / ((z : ℂ) + n) ^ (k + 1) = ((-2 * π * I) ^ (k + 1) / k !) *
∑' n : ℕ+, n ^ k * cexp (2 * π * I * z) ^ (n : ℕ) := by
rw [EisensteinSeries.qExpansion_identity hk z, ← tsum_zero_pnat_eq_tsum_nat]
· simp [show k ≠ 0 by grind]
· apply (summable_pow_mul_cexp k 1 z).congr
simp
lemma summable_eisSummand {k : ℕ} (hk : 3 ≤ k) (z : ℍ) :
Summable (eisSummand k · z) :=
summable_norm_iff.mp <| summable_norm_eisSummand (Int.toNat_le.mp hk) z
lemma summable_prod_eisSummand {k : ℕ} (hk : 3 ≤ k) (z : ℍ) :
Summable fun x : ℤ × ℤ ↦ eisSummand k ![x.1, x.2] z := by
refine (finTwoArrowEquiv ℤ).summable_iff.mp <| (summable_eisSummand hk z).congr (fun v ↦ ?_)
simp [show ![v 0, v 1] = v from List.ofFn_inj.mp rfl]
lemma tsum_eisSummand_eq_tsum_sigma_mul_cexp_pow {k : ℕ} (hk : 3 ≤ k) (hk2 : Even k) (z : ℍ) :
∑' v, eisSummand k v z = 2 * riemannZeta k + 2 * ((-2 * π * I) ^ k / (k - 1)!) *
∑' (n : ℕ+), σ (k - 1) n * cexp (2 * π * I * z) ^ (n : ℕ) := by
rw [← (finTwoArrowEquiv ℤ).symm.tsum_eq, finTwoArrowEquiv_symm_apply,
Summable.tsum_prod (summable_prod_eisSummand hk z),
tsum_int_eq_zero_add_two_mul_tsum_pnat (fun n ↦ ?h₁)
(by simpa using (summable_prod_eisSummand hk z).prod)]
case h₁ =>
nth_rewrite 1 [← tsum_comp_neg]
exact tsum_congr fun y ↦ by simp [eisSummand, ← neg_add _ (y : ℂ), -neg_add_rev, hk2.neg_pow]
have H (b : ℕ+) := qExpansion_identity_pnat (k := k - 1) (by grind) ⟨b * z, by simpa using z.2⟩
simp_rw [show k - 1 + 1 = k by grind, one_div] at H
simp only [coe_mk_subtype, neg_mul] at H
rw [nsmul_eq_mul, mul_assoc]
congr
· simp [eisSummand, two_mul_riemannZeta_eq_tsum_int_inv_pow_of_even (by grind) hk2]
· suffices ∑' (m : ℕ+) (n : ℕ+), (n : ℕ) ^ (k - 1) * cexp (2 * π * I * (m * z)) ^ (n : ℕ) =
∑' (m : ℕ+) (n : ℕ+), (n : ℕ) ^ (k - 1) * cexp (2 * π * I * z) ^ (m * n : ℕ) by
simp [eisSummand, H, tsum_mul_left,
← tsum_prod_pow_eq_tsum_sigma (k - 1) (norm_exp_two_pi_I_lt_one z), this]
simp_rw [← Complex.exp_nat_mul]
exact tsum_congr₂ (fun m n ↦ by push_cast; ring_nf)
lemma eisSummand_of_gammaSet_eq_divIntMap (k : ℤ) (z : ℍ) {n : ℕ} (v : gammaSet 1 n 0) :
eisSummand k v z = ((n : ℂ) ^ k)⁻¹ * eisSummand k (divIntMap n v) z := by
simp_rw [eisSummand]
nth_rw 1 2 [gammaSet_eq_gcd_mul_divIntMap v.2]
simp [← mul_inv, ← mul_zpow, mul_add, mul_assoc]
lemma tsum_eisSummand_eq_riemannZeta_mul_eisensteinSeries {k : ℕ} (hk : 3 ≤ k) (z : ℍ) :
∑' v : Fin 2 → ℤ, eisSummand k v z = riemannZeta k * eisensteinSeries (N := 1) 0 k z := by
have hk1 : 1 < k := by grind
have hk2 : 3 ≤ (k : ℤ) := mod_cast hk
simp_rw [← gammaSetDivGcdSigmaEquiv.symm.tsum_eq, gammaSetDivGcdSigmaEquiv_symm_eq]
rw [eisensteinSeries, Summable.tsum_sigma ?hsumm, zeta_nat_eq_tsum_of_gt_one hk1,
tsum_mul_tsum_of_summable_norm (by simp [hk1]) ((summable_norm_eisSummand hk2 z).subtype _)]
case hsumm =>
exact gammaSetDivGcdSigmaEquiv.symm.summable_iff.mpr (summable_norm_eisSummand hk2 z).of_norm
|>.congr <| by simp
simp_rw [one_div]
rw [Summable.tsum_prod' ?h₁ fun b ↦ ?h₂]
case h₁ =>
exact summable_mul_of_summable_norm (f := fun (n : ℕ) ↦ ((n : ℂ) ^ k)⁻¹)
(g := fun (v : gammaSet 1 1 0) ↦ eisSummand k v z) (by simp [hk1])
((summable_norm_eisSummand hk2 z).subtype _)
case h₂ =>
simpa using ((summable_norm_eisSummand hk2 z).subtype _).of_norm.mul_left (a := ((b : ℂ) ^ k)⁻¹)
refine tsum_congr fun b ↦ ?_
rcases eq_or_ne b 0 with rfl | hb
· simp [show ((0 : ℂ) ^ k)⁻¹ = 0 by aesop, eisSummand_of_gammaSet_eq_divIntMap]
· have : NeZero b := ⟨hb⟩
simpa [eisSummand_of_gammaSet_eq_divIntMap k z, tsum_mul_left, hb]
using (gammaSetDivGcdEquiv b).tsum_eq (eisSummand k · z)
/-- The q-Expansion of normalised Eisenstein series of level one with `riemannZeta` term. -/
lemma EisensteinSeries.q_expansion_riemannZeta {k : ℕ} (hk : 3 ≤ k) (hk2 : Even k) (z : ℍ) :
E hk z = 1 + (riemannZeta k)⁻¹ * (-2 * π * I) ^ k / (k - 1)! *
∑' n : ℕ+, σ (k - 1) n * cexp (2 * π * I * z) ^ (n : ℤ) := by
have : eisensteinSeries_MF (Int.toNat_le.mp hk) 0 z = eisensteinSeries_SIF (N := 1) 0 k z := rfl
rw [E, ModularForm.IsGLPos.smul_apply, this, eisensteinSeries_SIF_apply 0 k z, eisensteinSeries]
have HE1 := tsum_eisSummand_eq_tsum_sigma_mul_cexp_pow hk hk2 z
have HE2 := tsum_eisSummand_eq_riemannZeta_mul_eisensteinSeries hk z
have z2 : riemannZeta k ≠ 0 := riemannZeta_ne_zero_of_one_lt_re <| by norm_cast; grind
simp [eisSummand, eisensteinSeries, ← inv_mul_eq_iff_eq_mul₀ z2] at HE1 HE2 ⊢
grind
private lemma eisensteinSeries_coeff_identity {k : ℕ} (hk2 : Even k) (hkn0 : k ≠ 0) :
(riemannZeta k)⁻¹ * (-2 * π * I) ^ k / (k - 1)! = -(2 * k / bernoulli k) := by
have h2 : k = 2 * (k / 2 - 1 + 1) := by grind
set m := k / 2 - 1
rw [h2, Nat.cast_mul 2 (m + 1), Nat.cast_two, riemannZeta_two_mul_nat (show m + 1 ≠ 0 by grind),
show (2 * (m + 1))! = 2 * (m + 1) * (2 * m + 1)! by grind [Nat.factorial_succ],
show 2 * (m + 1) - 1 = 2 * m + 1 by grind, mul_pow, mul_pow, pow_mul I, I_sq]
norm_cast
simp [field]
grind
/-- The q-Expansion of normalised Eisenstein series of level one with `bernoulli` term. -/
lemma EisensteinSeries.q_expansion_bernoulli {k : ℕ} (hk : 3 ≤ k) (hk2 : Even k) (z : ℍ) :
E hk z = 1 - (2 * k / bernoulli k) *
∑' n : ℕ+, σ (k - 1) n * cexp (2 * π * I * z) ^ (n : ℤ) := by
convert q_expansion_riemannZeta hk hk2 z using 1
rw [eisensteinSeries_coeff_identity hk2 (by grind), neg_mul, ← sub_eq_add_neg] |
.lake/packages/mathlib/Mathlib/NumberTheory/ModularForms/JacobiTheta/TwoVariable.lean | import Mathlib.Analysis.Calculus.SmoothSeries
import Mathlib.Analysis.Normed.Operator.Prod
import Mathlib.Analysis.SpecialFunctions.Gaussian.PoissonSummation
import Mathlib.LinearAlgebra.Complex.FiniteDimensional
/-!
# The two-variable Jacobi theta function
This file defines the two-variable Jacobi theta function
$$\theta(z, \tau) = \sum_{n \in \mathbb{Z}} \exp (2 i \pi n z + i \pi n ^ 2 \tau),$$
and proves the functional equation relating the values at `(z, τ)` and `(z / τ, -1 / τ)`,
using Poisson's summation formula. We also show holomorphy (jointly in both variables).
Additionally, we show some analogous results about the derivative (in the `z`-variable)
$$\theta'(z, τ) = \sum_{n \in \mathbb{Z}} 2 \pi i n \exp (2 i \pi n z + i \pi n ^ 2 \tau).$$
(Note that the Mellin transform of `θ` will give us functional equations for `L`-functions
of even Dirichlet characters, and that of `θ'` will do the same for odd Dirichlet characters.)
-/
open Complex Real Asymptotics Filter Topology
open scoped ComplexConjugate
noncomputable section
section term_defs
/-!
## Definitions of the summands
-/
/-- Summand in the series for the Jacobi theta function. -/
def jacobiTheta₂_term (n : ℤ) (z τ : ℂ) : ℂ := cexp (2 * π * I * n * z + π * I * n ^ 2 * τ)
/-- Summand in the series for the Fréchet derivative of the Jacobi theta function. -/
def jacobiTheta₂_term_fderiv (n : ℤ) (z τ : ℂ) : ℂ × ℂ →L[ℂ] ℂ :=
cexp (2 * π * I * n * z + π * I * n ^ 2 * τ) •
((2 * π * I * n) • (ContinuousLinearMap.fst ℂ ℂ ℂ) +
(π * I * n ^ 2) • (ContinuousLinearMap.snd ℂ ℂ ℂ))
lemma hasFDerivAt_jacobiTheta₂_term (n : ℤ) (z τ : ℂ) :
HasFDerivAt (fun p : ℂ × ℂ ↦ jacobiTheta₂_term n p.1 p.2)
(jacobiTheta₂_term_fderiv n z τ) (z, τ) := by
let f : ℂ × ℂ → ℂ := fun p ↦ 2 * π * I * n * p.1 + π * I * n ^ 2 * p.2
suffices HasFDerivAt f ((2 * π * I * n) • (ContinuousLinearMap.fst ℂ ℂ ℂ)
+ (π * I * n ^ 2) • (ContinuousLinearMap.snd ℂ ℂ ℂ)) (z, τ) from this.cexp
exact (hasFDerivAt_fst.const_mul _).add (hasFDerivAt_snd.const_mul _)
/-- Summand in the series for the `z`-derivative of the Jacobi theta function. -/
def jacobiTheta₂'_term (n : ℤ) (z τ : ℂ) := 2 * π * I * n * jacobiTheta₂_term n z τ
end term_defs
section term_bounds
/-!
## Bounds for the summands
We show that the sums of the three functions `jacobiTheta₂_term`, `jacobiTheta₂'_term` and
`jacobiTheta₂_term_fderiv` are locally uniformly convergent in the domain `0 < im τ`, and diverge
everywhere else.
-/
lemma norm_jacobiTheta₂_term (n : ℤ) (z τ : ℂ) :
‖jacobiTheta₂_term n z τ‖ = rexp (-π * n ^ 2 * τ.im - 2 * π * n * z.im) := by
rw [jacobiTheta₂_term, Complex.norm_exp, (by push_cast; ring :
(2 * π : ℂ) * I * n * z + π * I * n ^ 2 * τ = (π * (2 * n) :) * z * I + (π * n ^ 2 :) * τ * I),
add_re, mul_I_re, im_ofReal_mul, mul_I_re, im_ofReal_mul]
ring_nf
/-- A uniform upper bound for `jacobiTheta₂_term` on compact subsets. -/
lemma norm_jacobiTheta₂_term_le {S T : ℝ} (hT : 0 < T) {z τ : ℂ}
(hz : |im z| ≤ S) (hτ : T ≤ im τ) (n : ℤ) :
‖jacobiTheta₂_term n z τ‖ ≤ rexp (-π * (T * n ^ 2 - 2 * S * |n|)) := by
simp_rw [norm_jacobiTheta₂_term, Real.exp_le_exp, sub_eq_add_neg, neg_mul, ← neg_add,
neg_le_neg_iff, mul_comm (2 : ℝ), mul_assoc π, ← mul_add, mul_le_mul_iff_right₀ pi_pos,
mul_comm T, mul_comm S]
refine add_le_add (mul_le_mul le_rfl hτ hT.le (sq_nonneg _)) ?_
rw [← mul_neg, mul_assoc, mul_assoc, mul_le_mul_iff_right₀ two_pos, mul_comm, neg_mul, ← mul_neg]
refine le_trans ?_ (neg_abs_le _)
rw [mul_neg, neg_le_neg_iff, abs_mul, Int.cast_abs]
exact mul_le_mul_of_nonneg_left hz (abs_nonneg _)
/-- A uniform upper bound for `jacobiTheta₂'_term` on compact subsets. -/
lemma norm_jacobiTheta₂'_term_le {S T : ℝ} (hT : 0 < T) {z τ : ℂ}
(hz : |im z| ≤ S) (hτ : T ≤ im τ) (n : ℤ) :
‖jacobiTheta₂'_term n z τ‖ ≤ 2 * π * |n| * rexp (-π * (T * n ^ 2 - 2 * S * |n|)) := by
rw [jacobiTheta₂'_term, norm_mul]
refine mul_le_mul (le_of_eq ?_) (norm_jacobiTheta₂_term_le hT hz hτ n)
(norm_nonneg _) (by positivity)
simp only [norm_mul, Complex.norm_two, norm_I, Complex.norm_of_nonneg pi_pos.le,
norm_intCast, mul_one, Int.cast_abs]
/-- The uniform bound we have given is summable, and remains so after multiplying by any fixed
power of `|n|` (we shall need this for `k = 0, 1, 2`). -/
lemma summable_pow_mul_jacobiTheta₂_term_bound (S : ℝ) {T : ℝ} (hT : 0 < T) (k : ℕ) :
Summable (fun n : ℤ ↦ (|n| ^ k : ℝ) * Real.exp (-π * (T * n ^ 2 - 2 * S * |n|))) := by
suffices Summable (fun n : ℕ ↦ (n ^ k : ℝ) * Real.exp (-π * (T * n ^ 2 - 2 * S * n))) by
apply Summable.of_nat_of_neg <;>
simpa only [Int.cast_neg, neg_sq, abs_neg, Int.cast_natCast, Nat.abs_cast]
apply summable_of_isBigO_nat (summable_pow_mul_exp_neg_nat_mul k zero_lt_one)
apply IsBigO.mul (isBigO_refl _ _)
refine Real.isBigO_exp_comp_exp_comp.mpr (Tendsto.isBoundedUnder_le_atBot ?_)
simp_rw [← tendsto_neg_atTop_iff, Pi.sub_apply]
conv =>
enter [1, n]
rw [show -(-π * (T * n ^ 2 - 2 * S * n) - -1 * n) = n * (π * T * n - (2 * π * S + 1)) by ring]
refine tendsto_natCast_atTop_atTop.atTop_mul_atTop₀ (tendsto_atTop_add_const_right _ _ ?_)
exact tendsto_natCast_atTop_atTop.const_mul_atTop (mul_pos pi_pos hT)
/-- The series defining the theta function is summable if and only if `0 < im τ`. -/
lemma summable_jacobiTheta₂_term_iff (z τ : ℂ) : Summable (jacobiTheta₂_term · z τ) ↔ 0 < im τ := by
-- NB. This is a statement of no great mathematical interest; it is included largely to avoid
-- having to impose `0 < im τ` as a hypothesis on many later lemmas.
refine Iff.symm ⟨fun hτ ↦ ?_, fun h ↦ ?_⟩ -- do quicker implication first!
· refine (summable_pow_mul_jacobiTheta₂_term_bound |im z| hτ 0).of_norm_bounded ?_
simpa only [pow_zero, one_mul] using norm_jacobiTheta₂_term_le hτ le_rfl le_rfl
· by_contra! hτ
rcases lt_or_eq_of_le hτ with hτ | hτ
· -- easy case `im τ < 0`
suffices Tendsto (fun n : ℕ ↦ ‖jacobiTheta₂_term ↑n z τ‖) atTop atTop by
replace h := (h.comp_injective (fun a b ↦ Int.ofNat_inj.mp)).tendsto_atTop_zero.norm
exact atTop_neBot.ne (disjoint_self.mp <| h.disjoint (disjoint_nhds_atTop _) this)
simp only [norm_jacobiTheta₂_term, Int.cast_natCast]
conv =>
enter [1, n]
rw [show -π * n ^ 2 * τ.im - 2 * π * n * z.im =
n * (n * (-π * τ.im) - 2 * π * z.im) by ring]
refine tendsto_exp_atTop.comp (tendsto_natCast_atTop_atTop.atTop_mul_atTop₀ ?_)
exact tendsto_atTop_add_const_right _ _ (tendsto_natCast_atTop_atTop.atTop_mul_const
(mul_pos_of_neg_of_neg (neg_lt_zero.mpr pi_pos) hτ))
· -- case im τ = 0: 3-way split according to `im z`
simp_rw [← summable_norm_iff (E := ℂ), norm_jacobiTheta₂_term, hτ, mul_zero, zero_sub] at h
rcases lt_trichotomy (im z) 0 with hz | hz | hz
· replace h := (h.comp_injective (fun a b ↦ Int.ofNat_inj.mp)).tendsto_atTop_zero
simp_rw [Function.comp_def, Int.cast_natCast] at h
refine atTop_neBot.ne (disjoint_self.mp <| h.disjoint (disjoint_nhds_atTop 0) ?_)
refine tendsto_exp_atTop.comp ?_
simp only [tendsto_neg_atTop_iff, mul_assoc]
apply Filter.Tendsto.const_mul_atBot two_pos
exact (tendsto_natCast_atTop_atTop.atTop_mul_const_of_neg hz).const_mul_atBot pi_pos
· revert h
simpa only [hz, mul_zero, neg_zero, Real.exp_zero, summable_const_iff] using one_ne_zero
· have : ((-↑·) : ℕ → ℤ).Injective := fun _ _ ↦ by simp only [neg_inj, Nat.cast_inj, imp_self]
replace h := (h.comp_injective this).tendsto_atTop_zero
simp_rw [Function.comp_def, Int.cast_neg, Int.cast_natCast, mul_neg, neg_mul, neg_neg] at h
refine atTop_neBot.ne (disjoint_self.mp <| h.disjoint (disjoint_nhds_atTop 0) ?_)
exact tendsto_exp_atTop.comp ((tendsto_natCast_atTop_atTop.const_mul_atTop
(mul_pos two_pos pi_pos)).atTop_mul_const hz)
lemma norm_jacobiTheta₂_term_fderiv_le (n : ℤ) (z τ : ℂ) :
‖jacobiTheta₂_term_fderiv n z τ‖ ≤ 3 * π * |n| ^ 2 * ‖jacobiTheta₂_term n z τ‖ := by
-- this is slow to elaborate so do it once and reuse:
have hns (a : ℂ) (f : (ℂ × ℂ) →L[ℂ] ℂ) : ‖a • f‖ = ‖a‖ * ‖f‖ := norm_smul a f
rw [jacobiTheta₂_term_fderiv, jacobiTheta₂_term, hns,
mul_comm _ ‖cexp _‖, (by norm_num : (3 : ℝ) = 2 + 1), add_mul, add_mul]
refine mul_le_mul_of_nonneg_left ((norm_add_le _ _).trans (add_le_add ?_ ?_)) (norm_nonneg _)
· simp_rw [hns, norm_mul, ← ofReal_ofNat, ← ofReal_intCast,
norm_real, norm_of_nonneg zero_le_two, Real.norm_of_nonneg pi_pos.le, norm_I, mul_one,
Real.norm_eq_abs, ← Int.cast_abs, ← Int.cast_pow]
grw [ContinuousLinearMap.norm_fst_le, mul_one, ← Int.le_self_sq]
· simp_rw [hns, norm_mul, one_mul, norm_I, mul_one,
norm_real, norm_of_nonneg pi_pos.le, ← ofReal_intCast, ← ofReal_pow, norm_real,
Real.norm_eq_abs, Int.cast_abs, abs_pow]
apply mul_le_of_le_one_right (mul_nonneg pi_pos.le (pow_nonneg (abs_nonneg _) _))
exact ContinuousLinearMap.norm_snd_le ..
lemma norm_jacobiTheta₂_term_fderiv_ge (n : ℤ) (z τ : ℂ) :
π * |n| ^ 2 * ‖jacobiTheta₂_term n z τ‖ ≤ ‖jacobiTheta₂_term_fderiv n z τ‖ := by
have : ‖(jacobiTheta₂_term_fderiv n z τ) (0, 1)‖ ≤ ‖jacobiTheta₂_term_fderiv n z τ‖ := by
refine (ContinuousLinearMap.le_opNorm _ _).trans ?_
simp_rw [Prod.norm_def, norm_one, norm_zero, max_eq_right zero_le_one, mul_one, le_refl]
refine le_trans ?_ this
simp_rw [jacobiTheta₂_term_fderiv, jacobiTheta₂_term, ContinuousLinearMap.coe_smul',
Pi.smul_apply, ContinuousLinearMap.add_apply, ContinuousLinearMap.coe_smul',
ContinuousLinearMap.coe_fst', ContinuousLinearMap.coe_snd', Pi.smul_apply, smul_zero, zero_add,
smul_eq_mul, mul_one, mul_comm _ ‖cexp _‖, norm_mul]
refine mul_le_mul_of_nonneg_left (le_of_eq ?_) (norm_nonneg _)
simp_rw [norm_real, norm_of_nonneg pi_pos.le, norm_I, mul_one,
Int.cast_abs, ← norm_intCast, norm_pow]
lemma summable_jacobiTheta₂_term_fderiv_iff (z τ : ℂ) :
Summable (jacobiTheta₂_term_fderiv · z τ) ↔ 0 < im τ := by
constructor
· rw [← summable_jacobiTheta₂_term_iff (z := z)]
intro h
have := h.norm
refine this.of_norm_bounded_eventually ?_
have : ∀ᶠ (n : ℤ) in cofinite, n ≠ 0 :=
Int.cofinite_eq ▸ (mem_sup.mpr ⟨eventually_ne_atBot 0, eventually_ne_atTop 0⟩)
filter_upwards [this] with n hn
refine le_trans ?_ (norm_jacobiTheta₂_term_fderiv_ge n z τ)
apply le_mul_of_one_le_left (norm_nonneg _)
refine one_le_pi_div_two.trans (mul_le_mul_of_nonneg_left ?_ pi_pos.le)
refine (by norm_num : 2⁻¹ ≤ (1 : ℝ)).trans ?_
rw [one_le_sq_iff_one_le_abs, ← Int.cast_abs, abs_abs, ← Int.cast_one, Int.cast_le]
exact Int.one_le_abs hn
· intro hτ
refine ((summable_pow_mul_jacobiTheta₂_term_bound
|z.im| hτ 2).mul_left (3 * π)).of_norm_bounded (fun n ↦ ?_)
refine (norm_jacobiTheta₂_term_fderiv_le n z τ).trans
(?_ : 3 * π * |n| ^ 2 * ‖jacobiTheta₂_term n z τ‖ ≤ _)
simp_rw [mul_assoc (3 * π)]
refine mul_le_mul_of_nonneg_left ?_ (mul_pos (by simp : 0 < (3 : ℝ)) pi_pos).le
refine mul_le_mul_of_nonneg_left ?_ (pow_nonneg (Int.cast_nonneg (abs_nonneg _)) _)
exact norm_jacobiTheta₂_term_le hτ le_rfl le_rfl n
lemma summable_jacobiTheta₂'_term_iff (z τ : ℂ) :
Summable (jacobiTheta₂'_term · z τ) ↔ 0 < im τ := by
constructor
· rw [← summable_jacobiTheta₂_term_iff (z := z)]
refine fun h ↦ (h.norm.mul_left (2 * π)⁻¹).of_norm_bounded_eventually ?_
have : ∀ᶠ (n : ℤ) in cofinite, n ≠ 0 :=
Int.cofinite_eq ▸ (mem_sup.mpr ⟨eventually_ne_atBot 0, eventually_ne_atTop 0⟩)
filter_upwards [this] with n hn
rw [jacobiTheta₂'_term, norm_mul, ← mul_assoc]
refine le_mul_of_one_le_left (norm_nonneg _) ?_
simp_rw [norm_mul, norm_I, norm_real, mul_one, norm_of_nonneg pi_pos.le,
← ofReal_ofNat, norm_real, norm_of_nonneg two_pos.le, ← ofReal_intCast, norm_real,
Real.norm_eq_abs, ← Int.cast_abs, ← mul_assoc _ (2 * π),
inv_mul_cancel₀ (mul_pos two_pos pi_pos).ne', one_mul]
rw [← Int.cast_one, Int.cast_le]
exact Int.one_le_abs hn
· refine fun hτ ↦ ((summable_pow_mul_jacobiTheta₂_term_bound
|z.im| hτ 1).mul_left (2 * π)).of_norm_bounded (fun n ↦ ?_)
rw [jacobiTheta₂'_term, norm_mul, ← mul_assoc, pow_one]
refine mul_le_mul (le_of_eq ?_) (norm_jacobiTheta₂_term_le hτ le_rfl le_rfl n)
(norm_nonneg _) (by positivity)
simp_rw [norm_mul, Complex.norm_two, norm_I, Complex.norm_of_nonneg pi_pos.le,
norm_intCast, mul_one, Int.cast_abs]
end term_bounds
/-!
## Definitions of the functions
-/
/-- The two-variable Jacobi theta function,
`θ z τ = ∑' (n : ℤ), cexp (2 * π * I * n * z + π * I * n ^ 2 * τ)`.
-/
def jacobiTheta₂ (z τ : ℂ) : ℂ := ∑' n : ℤ, jacobiTheta₂_term n z τ
/-- Fréchet derivative of the two-variable Jacobi theta function. -/
def jacobiTheta₂_fderiv (z τ : ℂ) : ℂ × ℂ →L[ℂ] ℂ := ∑' n : ℤ, jacobiTheta₂_term_fderiv n z τ
/-- The `z`-derivative of the Jacobi theta function,
`θ' z τ = ∑' (n : ℤ), 2 * π * I * n * cexp (2 * π * I * n * z + π * I * n ^ 2 * τ)`.
-/
def jacobiTheta₂' (z τ : ℂ) := ∑' n : ℤ, jacobiTheta₂'_term n z τ
lemma hasSum_jacobiTheta₂_term (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) :
HasSum (fun n ↦ jacobiTheta₂_term n z τ) (jacobiTheta₂ z τ) :=
((summable_jacobiTheta₂_term_iff z τ).mpr hτ).hasSum
lemma hasSum_jacobiTheta₂_term_fderiv (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) :
HasSum (fun n ↦ jacobiTheta₂_term_fderiv n z τ) (jacobiTheta₂_fderiv z τ) :=
((summable_jacobiTheta₂_term_fderiv_iff z τ).mpr hτ).hasSum
lemma hasSum_jacobiTheta₂'_term (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) :
HasSum (fun n ↦ jacobiTheta₂'_term n z τ) (jacobiTheta₂' z τ) :=
((summable_jacobiTheta₂'_term_iff z τ).mpr hτ).hasSum
lemma jacobiTheta₂_undef (z : ℂ) {τ : ℂ} (hτ : im τ ≤ 0) : jacobiTheta₂ z τ = 0 := by
apply tsum_eq_zero_of_not_summable
rw [summable_jacobiTheta₂_term_iff]
exact not_lt.mpr hτ
lemma jacobiTheta₂_fderiv_undef (z : ℂ) {τ : ℂ} (hτ : im τ ≤ 0) : jacobiTheta₂_fderiv z τ = 0 := by
apply tsum_eq_zero_of_not_summable
rw [summable_jacobiTheta₂_term_fderiv_iff]
exact not_lt.mpr hτ
lemma jacobiTheta₂'_undef (z : ℂ) {τ : ℂ} (hτ : im τ ≤ 0) : jacobiTheta₂' z τ = 0 := by
apply tsum_eq_zero_of_not_summable
rw [summable_jacobiTheta₂'_term_iff]
exact not_lt.mpr hτ
/-!
## Derivatives and continuity
-/
lemma hasFDerivAt_jacobiTheta₂ (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) :
HasFDerivAt (fun p : ℂ × ℂ ↦ jacobiTheta₂ p.1 p.2) (jacobiTheta₂_fderiv z τ) (z, τ) := by
obtain ⟨T, hT, hτ'⟩ := exists_between hτ
obtain ⟨S, hz⟩ := exists_gt |im z|
let V := {u | |im u| < S} ×ˢ {v | T < im v}
have hVo : IsOpen V := by
refine ((_root_.continuous_abs.comp continuous_im).isOpen_preimage _ isOpen_Iio).prod ?_
exact continuous_im.isOpen_preimage _ isOpen_Ioi
have hVmem : (z, τ) ∈ V := ⟨hz, hτ'⟩
have hVp : IsPreconnected V := by
refine (Convex.isPreconnected ?_).prod (convex_halfSpace_im_gt T).isPreconnected
simpa only [abs_lt] using (convex_halfSpace_im_gt _).inter (convex_halfSpace_im_lt _)
let f : ℤ → ℂ × ℂ → ℂ := fun n p ↦ jacobiTheta₂_term n p.1 p.2
let f' : ℤ → ℂ × ℂ → ℂ × ℂ →L[ℂ] ℂ := fun n p ↦ jacobiTheta₂_term_fderiv n p.1 p.2
have hf (n : ℤ) : ∀ p ∈ V, HasFDerivAt (f n) (f' n p) p :=
fun p _ ↦ hasFDerivAt_jacobiTheta₂_term n p.1 p.2
let u : ℤ → ℝ := fun n ↦ 3 * π * |n| ^ 2 * Real.exp (-π * (T * n ^ 2 - 2 * S * |n|))
have hu : ∀ (n : ℤ), ∀ x ∈ V, ‖f' n x‖ ≤ u n := by
refine fun n p hp ↦ (norm_jacobiTheta₂_term_fderiv_le n p.1 p.2).trans ?_
refine mul_le_mul_of_nonneg_left ?_ (by positivity)
exact norm_jacobiTheta₂_term_le hT (le_of_lt hp.1) (le_of_lt hp.2) n
have hu_sum : Summable u := by
simp_rw [u, mul_assoc (3 * π)]
exact (summable_pow_mul_jacobiTheta₂_term_bound S hT 2).mul_left _
have hf_sum : Summable fun n : ℤ ↦ f n (z, τ) := by
refine (summable_pow_mul_jacobiTheta₂_term_bound S hT 0).of_norm_bounded ?_
simpa only [pow_zero, one_mul] using norm_jacobiTheta₂_term_le hT hz.le hτ'.le
simpa only [jacobiTheta₂, jacobiTheta₂_fderiv, f, f'] using
hasFDerivAt_tsum_of_isPreconnected hu_sum hVo hVp hf hu hVmem hf_sum hVmem
lemma continuousAt_jacobiTheta₂ (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) :
ContinuousAt (fun p : ℂ × ℂ ↦ jacobiTheta₂ p.1 p.2) (z, τ) :=
(hasFDerivAt_jacobiTheta₂ z hτ).continuousAt
/-- Differentiability of `Θ z τ` in `z`, for fixed `τ`. -/
lemma differentiableAt_jacobiTheta₂_fst (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) :
DifferentiableAt ℂ (jacobiTheta₂ · τ) z :=
((hasFDerivAt_jacobiTheta₂ z hτ).comp (𝕜 := ℂ) z (hasFDerivAt_prodMk_left z τ) :).differentiableAt
/-- Differentiability of `Θ z τ` in `τ`, for fixed `z`. -/
lemma differentiableAt_jacobiTheta₂_snd (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) :
DifferentiableAt ℂ (jacobiTheta₂ z) τ :=
((hasFDerivAt_jacobiTheta₂ z hτ).comp τ (hasFDerivAt_prodMk_right z τ)).differentiableAt
lemma hasDerivAt_jacobiTheta₂_fst (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) :
HasDerivAt (jacobiTheta₂ · τ) (jacobiTheta₂' z τ) z := by
-- This proof is annoyingly fiddly, because of the need to commute "evaluation at a point"
-- through infinite sums of continuous linear maps.
let eval_fst_CLM : (ℂ × ℂ →L[ℂ] ℂ) →L[ℂ] ℂ :=
{ toFun := fun f ↦ f (1, 0)
cont := continuous_id'.clm_apply continuous_const
map_add' := by simp only [ContinuousLinearMap.add_apply, forall_const]
map_smul' := by simp only [ContinuousLinearMap.coe_smul', Pi.smul_apply, smul_eq_mul,
RingHom.id_apply, forall_const] }
have step1 : HasSum (fun n ↦ (jacobiTheta₂_term_fderiv n z τ) (1, 0))
((jacobiTheta₂_fderiv z τ) (1, 0)) := by
apply eval_fst_CLM.hasSum (hasSum_jacobiTheta₂_term_fderiv z hτ)
have step2 (n : ℤ) : (jacobiTheta₂_term_fderiv n z τ) (1, 0) = jacobiTheta₂'_term n z τ := by
simp only [jacobiTheta₂_term_fderiv, smul_add, ContinuousLinearMap.add_apply,
ContinuousLinearMap.coe_smul', ContinuousLinearMap.coe_fst', Pi.smul_apply, smul_eq_mul,
mul_one, ContinuousLinearMap.coe_snd', mul_zero, add_zero, jacobiTheta₂'_term,
jacobiTheta₂_term, mul_comm _ (cexp _)]
rw [funext step2] at step1
have step3 : HasDerivAt (fun x ↦ jacobiTheta₂ x τ) ((jacobiTheta₂_fderiv z τ) (1, 0)) z :=
(((hasFDerivAt_jacobiTheta₂ z hτ).comp z (hasFDerivAt_prodMk_left z τ)).hasDerivAt :)
rwa [← step1.tsum_eq] at step3
lemma continuousAt_jacobiTheta₂' (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) :
ContinuousAt (fun p : ℂ × ℂ ↦ jacobiTheta₂' p.1 p.2) (z, τ) := by
obtain ⟨T, hT, hτ'⟩ := exists_between hτ
obtain ⟨S, hz⟩ := exists_gt |im z|
let V := {u | |im u| < S} ×ˢ {v | T < im v}
have hVo : IsOpen V := ((_root_.continuous_abs.comp continuous_im).isOpen_preimage _
isOpen_Iio).prod (continuous_im.isOpen_preimage _ isOpen_Ioi)
refine ContinuousOn.continuousAt ?_ (hVo.mem_nhds ⟨hz, hτ'⟩)
let u (n : ℤ) : ℝ := 2 * π * |n| * rexp (-π * (T * n ^ 2 - 2 * S * |n|))
have hu : Summable u := by simpa only [u, mul_assoc, pow_one]
using (summable_pow_mul_jacobiTheta₂_term_bound S hT 1).mul_left (2 * π)
refine continuousOn_tsum (fun n ↦ ?_) hu (fun n ⟨z', τ'⟩ ⟨hz', hτ'⟩ ↦ ?_)
· apply Continuous.continuousOn
unfold jacobiTheta₂'_term jacobiTheta₂_term
fun_prop
· exact norm_jacobiTheta₂'_term_le hT (le_of_lt hz') (le_of_lt hτ') n
/-!
## Periodicity and conjugation
-/
/-- The two-variable Jacobi theta function is periodic in `τ` with period 2. -/
lemma jacobiTheta₂_add_right (z τ : ℂ) : jacobiTheta₂ z (τ + 2) = jacobiTheta₂ z τ := by
refine tsum_congr (fun n ↦ ?_)
simp_rw [jacobiTheta₂_term, Complex.exp_add]
suffices cexp (π * I * n ^ 2 * 2 : ℂ) = 1 by rw [mul_add, Complex.exp_add, this, mul_one]
rw [(by push_cast; ring : (π * I * n ^ 2 * 2 : ℂ) = (n ^ 2 :) * (2 * π * I)), exp_int_mul,
exp_two_pi_mul_I, one_zpow]
/-- The two-variable Jacobi theta function is periodic in `z` with period 1. -/
lemma jacobiTheta₂_add_left (z τ : ℂ) : jacobiTheta₂ (z + 1) τ = jacobiTheta₂ z τ := by
refine tsum_congr (fun n ↦ ?_)
simp_rw [jacobiTheta₂_term, mul_add, Complex.exp_add, mul_one, mul_comm _ (n : ℂ),
exp_int_mul_two_pi_mul_I, mul_one]
/-- The two-variable Jacobi theta function is quasi-periodic in `z` with period `τ`. -/
lemma jacobiTheta₂_add_left' (z τ : ℂ) :
jacobiTheta₂ (z + τ) τ = cexp (-π * I * (τ + 2 * z)) * jacobiTheta₂ z τ := by
conv_rhs => rw [jacobiTheta₂, ← tsum_mul_left, ← (Equiv.addRight 1).tsum_eq]
refine tsum_congr (fun n ↦ ?_)
simp_rw [jacobiTheta₂_term, ← Complex.exp_add, Equiv.coe_addRight, Int.cast_add]
ring_nf
/-- The two-variable Jacobi theta function is even in `z`. -/
@[simp]
lemma jacobiTheta₂_neg_left (z τ : ℂ) : jacobiTheta₂ (-z) τ = jacobiTheta₂ z τ := by
conv_lhs => rw [jacobiTheta₂, ← Equiv.tsum_eq (Equiv.neg ℤ)]
refine tsum_congr (fun n ↦ ?_)
simp_rw [jacobiTheta₂_term, Equiv.neg_apply, Int.cast_neg, neg_sq, mul_assoc, neg_mul_neg]
lemma jacobiTheta₂_conj (z τ : ℂ) :
conj (jacobiTheta₂ z τ) = jacobiTheta₂ (conj z) (-conj τ) := by
rw [← jacobiTheta₂_neg_left, jacobiTheta₂, conj_tsum]
congr 2 with n
simp only [jacobiTheta₂_term, mul_neg, ← exp_conj, map_add, map_neg, map_mul, map_ofNat,
conj_ofReal, conj_I, map_intCast, neg_mul, neg_neg, map_pow]
lemma jacobiTheta₂'_add_right (z τ : ℂ) : jacobiTheta₂' z (τ + 2) = jacobiTheta₂' z τ := by
refine tsum_congr (fun n ↦ ?_)
simp_rw [jacobiTheta₂'_term, jacobiTheta₂_term, Complex.exp_add]
suffices cexp (π * I * n ^ 2 * 2 : ℂ) = 1 by rw [mul_add, Complex.exp_add, this, mul_one]
rw [(by push_cast; ring : (π * I * n ^ 2 * 2 : ℂ) = (n ^ 2 :) * (2 * π * I)), exp_int_mul,
exp_two_pi_mul_I, one_zpow]
lemma jacobiTheta₂'_add_left (z τ : ℂ) : jacobiTheta₂' (z + 1) τ = jacobiTheta₂' z τ := by
unfold jacobiTheta₂' jacobiTheta₂'_term jacobiTheta₂_term
refine tsum_congr (fun n ↦ ?_)
simp only [mul_add, Complex.exp_add, mul_one, mul_comm _ (n : ℂ), exp_int_mul_two_pi_mul_I,
mul_one]
lemma jacobiTheta₂'_add_left' (z τ : ℂ) :
jacobiTheta₂' (z + τ) τ =
cexp (-π * I * (τ + 2 * z)) * (jacobiTheta₂' z τ - 2 * π * I * jacobiTheta₂ z τ) := by
rcases le_or_gt τ.im 0 with hτ | hτ
· simp_rw [jacobiTheta₂_undef _ hτ, jacobiTheta₂'_undef _ hτ, mul_zero, sub_zero, mul_zero]
have (n : ℤ) : jacobiTheta₂'_term n (z + τ) τ =
cexp (-π * I * (τ + 2 * z)) * (jacobiTheta₂'_term (n + 1) z τ -
2 * π * I * jacobiTheta₂_term (n + 1) z τ) := by
simp only [jacobiTheta₂'_term, jacobiTheta₂_term]
conv_rhs => rw [← sub_mul, mul_comm, mul_assoc, ← Complex.exp_add, Int.cast_add, Int.cast_one,
mul_add, mul_one, add_sub_cancel_right]
congr 2
ring
rw [jacobiTheta₂', funext this, tsum_mul_left, ← (Equiv.subRight (1 : ℤ)).tsum_eq]
simp only [jacobiTheta₂, jacobiTheta₂', Equiv.subRight_apply, sub_add_cancel,
(hasSum_jacobiTheta₂'_term z hτ).summable.tsum_sub
((hasSum_jacobiTheta₂_term z hτ).summable.mul_left _), tsum_mul_left]
lemma jacobiTheta₂'_neg_left (z τ : ℂ) : jacobiTheta₂' (-z) τ = -jacobiTheta₂' z τ := by
rw [jacobiTheta₂', jacobiTheta₂', ← tsum_neg, ← (Equiv.neg ℤ).tsum_eq]
congr 1 with n
simp only [jacobiTheta₂'_term, jacobiTheta₂_term]
rw [Equiv.neg_apply, ← neg_mul]
push_cast
ring_nf
lemma jacobiTheta₂'_conj (z τ : ℂ) :
conj (jacobiTheta₂' z τ) = jacobiTheta₂' (conj z) (-conj τ) := by
rw [← neg_inj, ← jacobiTheta₂'_neg_left, jacobiTheta₂', jacobiTheta₂', conj_tsum, ← tsum_neg]
congr 1 with n
simp_rw [jacobiTheta₂'_term, jacobiTheta₂_term, map_mul, ← Complex.exp_conj, map_add, map_mul,
← ofReal_intCast, ← ofReal_ofNat, map_pow, conj_ofReal, conj_I]
ring_nf
/-!
## Functional equations
-/
/-- The functional equation for the Jacobi theta function: `jacobiTheta₂ z τ` is an explicit factor
times `jacobiTheta₂ (z / τ) (-1 / τ)`. This is the key lemma behind the proof of the functional
equation for L-series of even Dirichlet characters. -/
theorem jacobiTheta₂_functional_equation (z τ : ℂ) : jacobiTheta₂ z τ =
1 / (-I * τ) ^ (1 / 2 : ℂ) * cexp (-π * I * z ^ 2 / τ) * jacobiTheta₂ (z / τ) (-1 / τ) := by
rcases le_or_gt (im τ) 0 with hτ | hτ
· have : (-1 / τ).im ≤ 0 := by
rw [neg_div, neg_im, one_div, inv_im, neg_nonpos]
exact div_nonneg (neg_nonneg.mpr hτ) (normSq_nonneg τ)
rw [jacobiTheta₂_undef z hτ, jacobiTheta₂_undef _ this, mul_zero]
unfold jacobiTheta₂ jacobiTheta₂_term
have h2 : 0 < (-I * τ).re := by
simpa only [neg_mul, neg_re, mul_re, I_re, zero_mul, I_im, one_mul, zero_sub, neg_neg] using hτ
calc
_ = ∑' n : ℤ, cexp (-π * (-I * τ) * ↑n ^ 2 + 2 * π * (I * z) * ↑n) :=
tsum_congr (fun n ↦ by ring_nf)
_ = 1 / (-I * τ) ^ (1 / 2 : ℂ) * ∑' (n : ℤ), cexp (-π / (-I * τ) * (n + I * (I * z)) ^ 2) := by
rw [tsum_exp_neg_quadratic h2]
_ = 1 / (-I * τ) ^ (1 / 2 : ℂ) * cexp (π * I * (-1 / τ) * z ^ 2) *
∑' (n : ℤ), cexp (2 * π * I * n * (z / τ) + π * I * n ^ 2 * (-1 / τ)) := by
simp_rw [mul_assoc _ (cexp _), ← tsum_mul_left (a := cexp _), ← Complex.exp_add]
congr 2 with n : 1; congr 1
field_simp
ring_nf
simp_rw [I_sq, I_pow_four]
ring_nf
_ = _ := by
congr 3
ring
/-- The functional equation for the derivative of the Jacobi theta function, relating
`jacobiTheta₂' z τ` to `jacobiTheta₂' (z / τ) (-1 / τ)`. This is the key lemma behind the proof of
the functional equation for L-series of odd Dirichlet characters. -/
theorem jacobiTheta₂'_functional_equation (z τ : ℂ) :
jacobiTheta₂' z τ = 1 / (-I * τ) ^ (1 / 2 : ℂ) * cexp (-π * I * z ^ 2 / τ) / τ *
(jacobiTheta₂' (z / τ) (-1 / τ) - 2 * π * I * z * jacobiTheta₂ (z / τ) (-1 / τ)) := by
rcases le_or_gt (im τ) 0 with hτ | hτ
· rw [jacobiTheta₂'_undef z hτ, jacobiTheta₂'_undef, jacobiTheta₂_undef, mul_zero,
sub_zero, mul_zero] <;>
rw [neg_div, neg_im, one_div, inv_im, neg_nonpos] <;>
exact div_nonneg (neg_nonneg.mpr hτ) (normSq_nonneg τ)
have hτ' : 0 < (-1 / τ).im := by
rw [div_eq_mul_inv, neg_one_mul, neg_im, inv_im, neg_div, neg_neg]
exact div_pos hτ (normSq_pos.mpr (fun h ↦ lt_irrefl 0 (zero_im ▸ h ▸ hτ)))
have hj : HasDerivAt (fun w ↦ jacobiTheta₂ (w / τ) (-1 / τ))
((1 / τ) * jacobiTheta₂' (z / τ) (-1 / τ)) z := by
have := hasDerivAt_jacobiTheta₂_fst (z / τ) hτ'
simpa only [mul_comm, one_div] using this.comp z (hasDerivAt_mul_const τ⁻¹)
calc
_ = deriv (jacobiTheta₂ · τ) z := (hasDerivAt_jacobiTheta₂_fst z hτ).deriv.symm
_ = deriv (fun z ↦ 1 / (-I * τ) ^ (1 / 2 : ℂ) *
cexp (-π * I * z ^ 2 / τ) * jacobiTheta₂ (z / τ) (-1 / τ)) z := by
rw [funext (jacobiTheta₂_functional_equation · τ)]
_ = 1 / (-I * τ) ^ (1 / 2 : ℂ) *
deriv (fun z ↦ cexp (-π * I * z ^ 2 / τ) * jacobiTheta₂ (z / τ) (-1 / τ)) z := by
simp_rw [mul_assoc, deriv_const_mul_field]
_ = 1 / (-I * τ) ^ (1 / 2 : ℂ) *
(deriv (fun z ↦ cexp (-π * I * z ^ 2 / τ)) z * jacobiTheta₂ (z / τ) (-1 / τ)
+ cexp (-π * I * z ^ 2 / τ) * deriv (fun z ↦ jacobiTheta₂ (z / τ) (-1 / τ)) z) := by
rw [deriv_fun_mul _ hj.differentiableAt]
exact (((differentiableAt_pow 2).const_mul _).mul_const _).cexp
_ = _ := by
rw [hj.deriv]
simp only [div_eq_mul_inv _ τ]
rw [deriv_cexp (((differentiableAt_pow _).const_mul _).mul_const _), mul_comm,
deriv_mul_const_field, deriv_const_mul_field, deriv_pow_field]
ring_nf |
.lake/packages/mathlib/Mathlib/NumberTheory/ModularForms/JacobiTheta/OneVariable.lean | import Mathlib.NumberTheory.ModularForms.JacobiTheta.TwoVariable
import Mathlib.Analysis.Complex.UpperHalfPlane.MoebiusAction
/-! # Jacobi's theta function
This file defines the one-variable Jacobi theta function
$$\theta(\tau) = \sum_{n \in \mathbb{Z}} \exp (i \pi n ^ 2 \tau),$$
and proves the modular transformation properties `θ (τ + 2) = θ τ` and
`θ (-1 / τ) = (-I * τ) ^ (1 / 2) * θ τ`, using Poisson's summation formula for the latter. We also
show that `θ` is differentiable on `ℍ`, and `θ(τ) - 1` has exponential decay as `im τ → ∞`.
-/
open Complex Real Asymptotics Filter Topology
open scoped Real UpperHalfPlane
/-- Jacobi's one-variable theta function `∑' (n : ℤ), exp (π * I * n ^ 2 * τ)`. -/
noncomputable def jacobiTheta (τ : ℂ) : ℂ := ∑' n : ℤ, cexp (π * I * (n : ℂ) ^ 2 * τ)
lemma jacobiTheta_eq_jacobiTheta₂ (τ : ℂ) : jacobiTheta τ = jacobiTheta₂ 0 τ :=
tsum_congr (by simp [jacobiTheta₂_term])
theorem jacobiTheta_two_add (τ : ℂ) : jacobiTheta (2 + τ) = jacobiTheta τ := by
simp_rw [jacobiTheta_eq_jacobiTheta₂, add_comm, jacobiTheta₂_add_right]
theorem jacobiTheta_T_sq_smul (τ : ℍ) : jacobiTheta (ModularGroup.T ^ 2 • τ :) = jacobiTheta τ := by
suffices (ModularGroup.T ^ 2 • τ :) = (2 : ℂ) + ↑τ by simp_rw [this, jacobiTheta_two_add]
have : ModularGroup.T ^ (2 : ℕ) = ModularGroup.T ^ (2 : ℤ) := rfl
simp_rw [this, UpperHalfPlane.modular_T_zpow_smul, UpperHalfPlane.coe_vadd]
norm_cast
theorem jacobiTheta_S_smul (τ : ℍ) :
jacobiTheta ↑(ModularGroup.S • τ) = (-I * τ) ^ (1 / 2 : ℂ) * jacobiTheta τ := by
have h0 : (τ : ℂ) ≠ 0 := ne_of_apply_ne im (zero_im.symm ▸ ne_of_gt τ.2)
have h1 : (-I * τ) ^ (1 / 2 : ℂ) ≠ 0 := by
rw [Ne, cpow_eq_zero_iff, not_and_or]
exact Or.inl <| mul_ne_zero (neg_ne_zero.mpr I_ne_zero) h0
simp_rw [UpperHalfPlane.modular_S_smul, jacobiTheta_eq_jacobiTheta₂, ← ofReal_zero]
norm_cast
simp_rw [jacobiTheta₂_functional_equation 0 τ, zero_pow two_ne_zero, mul_zero, zero_div,
Complex.exp_zero, mul_one, ← mul_assoc, mul_one_div, div_self h1, one_mul,
UpperHalfPlane.coe_mk, inv_neg, neg_div, one_div]
theorem norm_exp_mul_sq_le {τ : ℂ} (hτ : 0 < τ.im) (n : ℤ) :
‖cexp (π * I * (n : ℂ) ^ 2 * τ)‖ ≤ rexp (-π * τ.im) ^ n.natAbs := by
let y := rexp (-π * τ.im)
have h : y < 1 := exp_lt_one_iff.mpr (mul_neg_of_neg_of_pos (neg_lt_zero.mpr pi_pos) hτ)
refine (le_of_eq ?_).trans (?_ : y ^ n ^ 2 ≤ _)
· rw [norm_exp]
have : (π * I * n ^ 2 * τ : ℂ).re = -π * τ.im * (n : ℝ) ^ 2 := by
rw [(by push_cast; ring : (π * I * n ^ 2 * τ : ℂ) = (π * n ^ 2 : ℝ) * (τ * I)),
re_ofReal_mul, mul_I_re]
ring
obtain ⟨m, hm⟩ := Int.eq_ofNat_of_zero_le (sq_nonneg n)
rw [this, exp_mul, ← Int.cast_pow, rpow_intCast, hm, zpow_natCast]
· have : n ^ 2 = (n.natAbs ^ 2 :) := by rw [Nat.cast_pow, Int.natAbs_sq]
rw [this, zpow_natCast]
exact pow_le_pow_of_le_one (exp_pos _).le h.le ((sq n.natAbs).symm ▸ n.natAbs.le_mul_self)
theorem hasSum_nat_jacobiTheta {τ : ℂ} (hτ : 0 < im τ) :
HasSum (fun n : ℕ => cexp (π * I * ((n : ℂ) + 1) ^ 2 * τ)) ((jacobiTheta τ - 1) / 2) := by
have := hasSum_jacobiTheta₂_term 0 hτ
simp_rw [jacobiTheta₂_term, mul_zero, zero_add, ← jacobiTheta_eq_jacobiTheta₂] at this
have := this.nat_add_neg
rw [← hasSum_nat_add_iff' 1] at this
simp_rw [Finset.sum_range_one, Int.cast_neg, Int.cast_natCast, Nat.cast_zero, neg_zero,
Int.cast_zero, sq (0 : ℂ), mul_zero, zero_mul, neg_sq, ← mul_two,
Complex.exp_zero, add_sub_assoc, (by norm_num : (1 : ℂ) - 1 * 2 = -1), ← sub_eq_add_neg,
Nat.cast_add, Nat.cast_one] at this
convert this.div_const 2 using 1
simp_rw [mul_div_cancel_right₀ _ (two_ne_zero' ℂ)]
theorem jacobiTheta_eq_tsum_nat {τ : ℂ} (hτ : 0 < im τ) :
jacobiTheta τ = ↑1 + ↑2 * ∑' n : ℕ, cexp (π * I * ((n : ℂ) + 1) ^ 2 * τ) := by
rw [(hasSum_nat_jacobiTheta hτ).tsum_eq, mul_div_cancel₀ _ (two_ne_zero' ℂ), ← add_sub_assoc,
add_sub_cancel_left]
/-- An explicit upper bound for `‖jacobiTheta τ - 1‖`. -/
theorem norm_jacobiTheta_sub_one_le {τ : ℂ} (hτ : 0 < im τ) :
‖jacobiTheta τ - 1‖ ≤ 2 / (1 - rexp (-π * τ.im)) * rexp (-π * τ.im) := by
suffices ‖∑' n : ℕ, cexp (π * I * ((n : ℂ) + 1) ^ 2 * τ)‖ ≤
rexp (-π * τ.im) / (1 - rexp (-π * τ.im)) by
calc
‖jacobiTheta τ - 1‖ = ↑2 * ‖∑' n : ℕ, cexp (π * I * ((n : ℂ) + 1) ^ 2 * τ)‖ := by
rw [sub_eq_iff_eq_add'.mpr (jacobiTheta_eq_tsum_nat hτ), norm_mul, Complex.norm_two]
_ ≤ 2 * (rexp (-π * τ.im) / (1 - rexp (-π * τ.im))) := by gcongr
_ = 2 / (1 - rexp (-π * τ.im)) * rexp (-π * τ.im) := by rw [div_mul_comm, mul_comm]
have : ∀ n : ℕ, ‖cexp (π * I * ((n : ℂ) + 1) ^ 2 * τ)‖ ≤ rexp (-π * τ.im) ^ (n + 1) := by
intro n
simpa only [Int.cast_add, Int.cast_one] using norm_exp_mul_sq_le hτ (n + 1)
have s : HasSum (fun n : ℕ =>
rexp (-π * τ.im) ^ (n + 1)) (rexp (-π * τ.im) / (1 - rexp (-π * τ.im))) := by
simp_rw [pow_succ', div_eq_mul_inv, hasSum_mul_left_iff (Real.exp_ne_zero _)]
exact hasSum_geometric_of_lt_one (exp_pos (-π * τ.im)).le
(exp_lt_one_iff.mpr <| mul_neg_of_neg_of_pos (neg_lt_zero.mpr pi_pos) hτ)
have aux : Summable fun n : ℕ => ‖cexp (π * I * ((n : ℂ) + 1) ^ 2 * τ)‖ :=
.of_nonneg_of_le (fun n => norm_nonneg _) this s.summable
exact (norm_tsum_le_tsum_norm aux).trans ((aux.tsum_mono s.summable this).trans_eq s.tsum_eq)
/-- The norm of `jacobiTheta τ - 1` decays exponentially as `im τ → ∞`. -/
theorem isBigO_at_im_infty_jacobiTheta_sub_one :
(fun τ => jacobiTheta τ - 1) =O[comap im atTop] fun τ => rexp (-π * τ.im) := by
simp_rw [IsBigO, IsBigOWith, Filter.eventually_comap, Filter.eventually_atTop]
refine ⟨2 / (1 - rexp (-(π * 1))), 1, fun y hy τ hτ =>
(norm_jacobiTheta_sub_one_le (hτ.symm ▸ zero_lt_one.trans_le hy : 0 < im τ)).trans ?_⟩
rw [Real.norm_eq_abs, Real.abs_exp, hτ, neg_mul]
gcongr
simp [pi_pos]
theorem differentiableAt_jacobiTheta {τ : ℂ} (hτ : 0 < im τ) :
DifferentiableAt ℂ jacobiTheta τ := by
simp_rw [funext jacobiTheta_eq_jacobiTheta₂]
exact differentiableAt_jacobiTheta₂_snd 0 hτ
theorem continuousAt_jacobiTheta {τ : ℂ} (hτ : 0 < im τ) : ContinuousAt jacobiTheta τ :=
(differentiableAt_jacobiTheta hτ).continuousAt |
.lake/packages/mathlib/Mathlib/NumberTheory/ModularForms/JacobiTheta/Manifold.lean | import Mathlib.Analysis.Complex.UpperHalfPlane.Manifold
import Mathlib.Geometry.Manifold.MFDeriv.FDeriv
import Mathlib.NumberTheory.ModularForms.JacobiTheta.OneVariable
/-!
# Manifold differentiability of the Jacobi theta function
In this file we reformulate differentiability of the Jacobi theta function in terms of manifold
differentiability.
## TODO
Prove smoothness (in terms of `Smooth`).
-/
open scoped UpperHalfPlane Manifold
theorem mdifferentiable_jacobiTheta : MDifferentiable 𝓘(ℂ) 𝓘(ℂ) (jacobiTheta ∘ (↑) : ℍ → ℂ) :=
fun τ => (differentiableAt_jacobiTheta τ.2).mdifferentiableAt.comp τ τ.mdifferentiable_coe |
.lake/packages/mathlib/Mathlib/NumberTheory/ModularForms/JacobiTheta/Bounds.lean | import Mathlib.NumberTheory.ModularForms.JacobiTheta.TwoVariable
/-!
# Asymptotic bounds for Jacobi theta functions
The goal of this file is to establish some technical lemmas about the asymptotics of the sums
`F_nat k a t = ∑' (n : ℕ), (n + a) ^ k * exp (-π * (n + a) ^ 2 * t)`
and
`F_int k a t = ∑' (n : ℤ), |n + a| ^ k * exp (-π * (n + a) ^ 2 * t).`
Here `k : ℕ` and `a : ℝ` (resp `a : UnitAddCircle`) are fixed, and we are interested in
asymptotics as `t → ∞`. These results are needed for the theory of Hurwitz zeta functions (and
hence Dirichlet L-functions, etc).
## Main results
* `HurwitzKernelBounds.isBigO_atTop_F_nat_zero_sub` : for `0 ≤ a`, the function
`F_nat 0 a - (if a = 0 then 1 else 0)` decays exponentially at `∞` (i.e. it satisfies
`=O[atTop] fun t ↦ exp (-p * t)` for some real `0 < p`).
* `HurwitzKernelBounds.isBigO_atTop_F_nat_one` : for `0 ≤ a`, the function `F_nat 1 a` decays
exponentially at `∞`.
* `HurwitzKernelBounds.isBigO_atTop_F_int_zero_sub` : for any `a : UnitAddCircle`, the function
`F_int 0 a - (if a = 0 then 1 else 0)` decays exponentially at `∞`.
* `HurwitzKernelBounds.isBigO_atTop_F_int_one`: the function `F_int 1 a` decays exponentially at
`∞`.
-/
open Set Filter Topology Asymptotics Real
noncomputable section
namespace HurwitzKernelBounds
section lemmas
lemma isBigO_exp_neg_mul_of_le {c d : ℝ} (hcd : c ≤ d) :
(fun t ↦ exp (-d * t)) =O[atTop] fun t ↦ exp (-c * t) := by
apply Eventually.isBigO
filter_upwards [eventually_gt_atTop 0] with t ht
rw [norm_of_nonneg (exp_pos _).le]
gcongr
private lemma exp_lt_aux {t : ℝ} (ht : 0 < t) : rexp (-π * t) < 1 := by
simpa only [exp_lt_one_iff, neg_mul, neg_lt_zero] using mul_pos pi_pos ht
private lemma isBigO_one_aux :
IsBigO atTop (fun t : ℝ ↦ (1 - rexp (-π * t))⁻¹) (fun _ ↦ (1 : ℝ)) := by
refine ((Tendsto.const_sub _ ?_).inv₀ (by simp)).isBigO_one ℝ (c := ((1 - 0)⁻¹ : ℝ))
simpa only [neg_mul, tendsto_exp_comp_nhds_zero, tendsto_neg_atBot_iff]
using tendsto_id.const_mul_atTop pi_pos
end lemmas
section nat
/-- Summand in the sum to be bounded (`ℕ` version). -/
def f_nat (k : ℕ) (a t : ℝ) (n : ℕ) : ℝ := (n + a) ^ k * exp (-π * (n + a) ^ 2 * t)
/-- An upper bound for the summand when `0 ≤ a`. -/
def g_nat (k : ℕ) (a t : ℝ) (n : ℕ) : ℝ := (n + a) ^ k * exp (-π * (n + a ^ 2) * t)
lemma f_le_g_nat (k : ℕ) {a t : ℝ} (ha : 0 ≤ a) (ht : 0 < t) (n : ℕ) :
‖f_nat k a t n‖ ≤ g_nat k a t n := by
rw [f_nat, norm_of_nonneg (by positivity), g_nat]
simp only [neg_mul, add_sq]
gcongr
have H₁ : (n : ℝ) ≤ n ^ 2 := mod_cast Nat.le_self_pow two_ne_zero n
have H₂ : 0 ≤ 2 * n * a := by positivity
linear_combination H₁ + H₂
/-- The sum to be bounded (`ℕ` version). -/
def F_nat (k : ℕ) (a t : ℝ) : ℝ := ∑' n, f_nat k a t n
lemma summable_f_nat (k : ℕ) (a : ℝ) {t : ℝ} (ht : 0 < t) : Summable (f_nat k a t) := by
have : Summable fun n : ℕ ↦ n ^ k * exp (-π * (n + a) ^ 2 * t) := by
refine (((summable_pow_mul_jacobiTheta₂_term_bound (|a| * t) ht k).mul_right
(rexp (-π * a ^ 2 * t))).comp_injective Nat.cast_injective).of_norm_bounded (fun n ↦ ?_)
simp_rw [mul_assoc, Function.comp_apply, ← Real.exp_add, norm_mul, norm_pow, Int.cast_abs,
Int.cast_natCast, norm_eq_abs, Nat.abs_cast, abs_exp]
gcongr
rw [← sub_nonneg]
rw [show -π * (t * n ^ 2 - 2 * (|a| * (t * n))) + -π * (a ^ 2 * t) - -π * ((n + a) ^ 2 * t)
= π * t * n * (|a| + a) * 2 by ring]
refine mul_nonneg (mul_nonneg (by positivity) ?_) two_pos.le
rw [← neg_le_iff_add_nonneg]
apply neg_le_abs
apply (this.mul_left (2 ^ k)).of_norm_bounded_eventually_nat
simp_rw [← mul_assoc, f_nat, norm_mul, norm_eq_abs, abs_exp,
mul_le_mul_iff_of_pos_right (exp_pos _), ← mul_pow, abs_pow, two_mul]
filter_upwards [eventually_ge_atTop (Nat.ceil |a|)] with n hn
gcongr
exact (abs_add_le ..).trans (add_le_add (Nat.abs_cast _).le (Nat.ceil_le.mp hn))
section k_eq_zero
/-!
## Sum over `ℕ` with `k = 0`
Here we use direct comparison with a geometric series.
-/
lemma F_nat_zero_le {a : ℝ} (ha : 0 ≤ a) {t : ℝ} (ht : 0 < t) :
‖F_nat 0 a t‖ ≤ rexp (-π * a ^ 2 * t) / (1 - rexp (-π * t)) := by
refine tsum_of_norm_bounded ?_ (f_le_g_nat 0 ha ht)
convert (hasSum_geometric_of_lt_one (exp_pos _).le <| exp_lt_aux ht).mul_left _ using 1
ext1 n
simp only [g_nat]
rw [← Real.exp_nat_mul, ← Real.exp_add]
ring_nf
lemma F_nat_zero_zero_sub_le {t : ℝ} (ht : 0 < t) :
‖F_nat 0 0 t - 1‖ ≤ rexp (-π * t) / (1 - rexp (-π * t)) := by
convert F_nat_zero_le zero_le_one ht using 2
· rw [F_nat, (summable_f_nat 0 0 ht).tsum_eq_zero_add, f_nat, Nat.cast_zero, add_zero, pow_zero,
one_mul, pow_two, mul_zero, mul_zero, zero_mul, exp_zero, add_comm, add_sub_cancel_right]
simp_rw [F_nat, f_nat, Nat.cast_add, Nat.cast_one, add_zero]
· rw [one_pow, mul_one]
lemma isBigO_atTop_F_nat_zero_sub {a : ℝ} (ha : 0 ≤ a) : ∃ p, 0 < p ∧
(fun t ↦ F_nat 0 a t - (if a = 0 then 1 else 0)) =O[atTop] fun t ↦ exp (-p * t) := by
split_ifs with h
· rw [h]
have : (fun t ↦ F_nat 0 0 t - 1) =O[atTop] fun t ↦ rexp (-π * t) / (1 - rexp (-π * t)) := by
apply Eventually.isBigO
filter_upwards [eventually_gt_atTop 0] with t ht
exact F_nat_zero_zero_sub_le ht
refine ⟨_, pi_pos, this.trans ?_⟩
simpa using (isBigO_refl (fun t ↦ rexp (-π * t)) _).mul isBigO_one_aux
· simp_rw [sub_zero]
have : (fun t ↦ F_nat 0 a t) =O[atTop] fun t ↦ rexp (-π * a ^ 2 * t) / (1 - rexp (-π * t)) := by
apply Eventually.isBigO
filter_upwards [eventually_gt_atTop 0] with t ht
exact F_nat_zero_le ha ht
refine ⟨π * a ^ 2, mul_pos pi_pos (sq_pos_of_ne_zero h), this.trans ?_⟩
simpa only [neg_mul π (a ^ 2), mul_one] using (isBigO_refl _ _).mul isBigO_one_aux
end k_eq_zero
section k_eq_one
/-!
## Sum over `ℕ` with `k = 1`
Here we use comparison with the series `∑ n * r ^ n`, where `r = exp (-π * t)`.
-/
lemma F_nat_one_le {a : ℝ} (ha : 0 ≤ a) {t : ℝ} (ht : 0 < t) :
‖F_nat 1 a t‖ ≤ rexp (-π * (a ^ 2 + 1) * t) / (1 - rexp (-π * t)) ^ 2
+ a * rexp (-π * a ^ 2 * t) / (1 - rexp (-π * t)) := by
refine tsum_of_norm_bounded ?_ (f_le_g_nat 1 ha ht)
unfold g_nat
simp_rw [pow_one, add_mul]
apply HasSum.add
· have h0' : ‖rexp (-π * t)‖ < 1 := by
simpa only [norm_eq_abs, abs_exp] using exp_lt_aux ht
convert (hasSum_coe_mul_geometric_of_norm_lt_one h0').mul_left (exp (-π * a ^ 2 * t)) using 1
· ext1 n
rw [mul_comm (exp _), ← Real.exp_nat_mul, mul_assoc (n : ℝ), ← Real.exp_add]
ring_nf
· rw [mul_add, add_mul, mul_one, exp_add, mul_div_assoc]
· convert (hasSum_geometric_of_lt_one (exp_pos _).le <| exp_lt_aux ht).mul_left _ using 1
ext1 n
rw [← Real.exp_nat_mul, mul_assoc _ (exp _), ← Real.exp_add]
ring_nf
lemma isBigO_atTop_F_nat_one {a : ℝ} (ha : 0 ≤ a) : ∃ p, 0 < p ∧
F_nat 1 a =O[atTop] fun t ↦ exp (-p * t) := by
suffices ∃ p, 0 < p ∧ (fun t ↦ rexp (-π * (a ^ 2 + 1) * t) / (1 - rexp (-π * t)) ^ 2
+ a * rexp (-π * a ^ 2 * t) / (1 - rexp (-π * t))) =O[atTop] fun t ↦ exp (-p * t) by
let ⟨p, hp, hp'⟩ := this
refine ⟨p, hp, (Eventually.isBigO ?_).trans hp'⟩
filter_upwards [eventually_gt_atTop 0] with t ht
exact F_nat_one_le ha ht
have aux' : IsBigO atTop (fun t : ℝ ↦ ((1 - rexp (-π * t)) ^ 2)⁻¹) (fun _ ↦ (1 : ℝ)) := by
simpa only [inv_pow, one_pow] using isBigO_one_aux.pow 2
rcases eq_or_lt_of_le ha with rfl | ha'
· exact ⟨_, pi_pos, by simpa only [zero_pow two_ne_zero, zero_add, mul_one, zero_mul, zero_div,
add_zero] using (isBigO_refl _ _).mul aux'⟩
· refine ⟨π * a ^ 2, mul_pos pi_pos <| pow_pos ha' _, IsBigO.add ?_ ?_⟩
· conv_rhs => enter [t]; rw [← mul_one (rexp _)]
refine (Eventually.isBigO ?_).mul aux'
filter_upwards [eventually_gt_atTop 0] with t ht
rw [norm_of_nonneg (exp_pos _).le, exp_le_exp]
nlinarith [pi_pos]
· simp_rw [mul_div_assoc, ← neg_mul]
apply IsBigO.const_mul_left
simpa only [mul_one] using (isBigO_refl _ _).mul isBigO_one_aux
end k_eq_one
end nat
section int
/-- Summand in the sum to be bounded (`ℤ` version). -/
def f_int (k : ℕ) (a t : ℝ) (n : ℤ) : ℝ := |n + a| ^ k * exp (-π * (n + a) ^ 2 * t)
lemma f_int_ofNat (k : ℕ) {a : ℝ} (ha : 0 ≤ a) (t : ℝ) (n : ℕ) :
f_int k a t (Int.ofNat n) = f_nat k a t n := by
rw [f_int, f_nat, Int.ofNat_eq_coe, Int.cast_natCast, abs_of_nonneg (by positivity)]
lemma f_int_negSucc (k : ℕ) {a : ℝ} (ha : a ≤ 1) (t : ℝ) (n : ℕ) :
f_int k a t (Int.negSucc n) = f_nat k (1 - a) t n := by
have : (Int.negSucc n) + a = -(n + (1 - a)) := by { push_cast; ring }
rw [f_int, f_nat, this, abs_neg, neg_sq, abs_of_nonneg (by linarith)]
lemma summable_f_int (k : ℕ) (a : ℝ) {t : ℝ} (ht : 0 < t) : Summable (f_int k a t) := by
apply Summable.of_norm
suffices ∀ n, ‖f_int k a t n‖ = ‖(Int.rec (f_nat k a t) (f_nat k (1 - a) t) : ℤ → ℝ) n‖ from
funext this ▸ (HasSum.int_rec (summable_f_nat k a ht).hasSum
(summable_f_nat k (1 - a) ht).hasSum).summable.norm
intro n
rcases n with - | m
· simp only [f_int, f_nat, Int.ofNat_eq_coe, Int.cast_natCast, norm_mul, norm_eq_abs, abs_pow,
abs_abs]
· simp only [f_int, f_nat, Int.cast_negSucc, norm_mul, norm_eq_abs, abs_pow, abs_abs,
(by { push_cast; ring } : -↑(m + 1) + a = -(m + (1 - a))), abs_neg, neg_sq]
/-- The sum to be bounded (`ℤ` version). -/
def F_int (k : ℕ) (a : UnitAddCircle) (t : ℝ) : ℝ :=
(show Function.Periodic (fun b ↦ ∑' (n : ℤ), f_int k b t n) 1 by
intro b
simp_rw [← (Equiv.addRight (1 : ℤ)).tsum_eq (f := fun n ↦ f_int k b t n)]
simp only [f_int, ← add_assoc, add_comm, Equiv.coe_addRight, Int.cast_add, Int.cast_one]
).lift a
lemma F_int_eq_of_mem_Icc (k : ℕ) {a : ℝ} (ha : a ∈ Icc 0 1) {t : ℝ} (ht : 0 < t) :
F_int k a t = (F_nat k a t) + (F_nat k (1 - a) t) := by
simp only [F_int, F_nat, Function.Periodic.lift_coe]
convert ((summable_f_nat k a ht).hasSum.int_rec (summable_f_nat k (1 - a) ht).hasSum).tsum_eq
using 3 with n
cases n
· rw [f_int_ofNat _ ha.1]
· rw [f_int_negSucc _ ha.2]
lemma isBigO_atTop_F_int_zero_sub (a : UnitAddCircle) : ∃ p, 0 < p ∧
(fun t ↦ F_int 0 a t - (if a = 0 then 1 else 0)) =O[atTop] fun t ↦ exp (-p * t) := by
obtain ⟨a, ha, rfl⟩ := a.eq_coe_Ico
obtain ⟨p, hp, hp'⟩ := isBigO_atTop_F_nat_zero_sub ha.1
obtain ⟨q, hq, hq'⟩ := isBigO_atTop_F_nat_zero_sub (sub_nonneg.mpr ha.2.le)
simp_rw [AddCircle.coe_eq_zero_iff_of_mem_Ico ha]
simp_rw [eq_false_intro (by linarith [ha.2] : 1 - a ≠ 0), if_false, sub_zero] at hq'
refine ⟨_, lt_min hp hq, ?_⟩
have : (fun t ↦ F_int 0 a t - (if a = 0 then 1 else 0)) =ᶠ[atTop]
fun t ↦ (F_nat 0 a t - (if a = 0 then 1 else 0)) + F_nat 0 (1 - a) t := by
filter_upwards [eventually_gt_atTop 0] with t ht
rw [F_int_eq_of_mem_Icc 0 (Ico_subset_Icc_self ha) ht]
ring
refine this.isBigO.trans ((hp'.trans ?_).add (hq'.trans ?_)) <;>
apply isBigO_exp_neg_mul_of_le
exacts [min_le_left .., min_le_right ..]
lemma isBigO_atTop_F_int_one (a : UnitAddCircle) : ∃ p, 0 < p ∧
F_int 1 a =O[atTop] fun t ↦ exp (-p * t) := by
obtain ⟨a, ha, rfl⟩ := a.eq_coe_Ico
obtain ⟨p, hp, hp'⟩ := isBigO_atTop_F_nat_one ha.1
obtain ⟨q, hq, hq'⟩ := isBigO_atTop_F_nat_one (sub_nonneg.mpr ha.2.le)
refine ⟨_, lt_min hp hq, ?_⟩
have : F_int 1 a =ᶠ[atTop] fun t ↦ F_nat 1 a t + F_nat 1 (1 - a) t := by
filter_upwards [eventually_gt_atTop 0] with t ht
exact F_int_eq_of_mem_Icc 1 (Ico_subset_Icc_self ha) ht
refine this.isBigO.trans ((hp'.trans ?_).add (hq'.trans ?_)) <;>
apply isBigO_exp_neg_mul_of_le
exacts [min_le_left .., min_le_right ..]
end int
end HurwitzKernelBounds |
.lake/packages/mathlib/Mathlib/NumberTheory/LSeries/HurwitzZetaValues.lean | import Mathlib.NumberTheory.ZetaValues
import Mathlib.NumberTheory.LSeries.RiemannZeta
/-!
# Special values of Hurwitz and Riemann zeta functions
This file gives the formula for `ζ (2 * k)`, for `k` a non-zero integer, in terms of Bernoulli
numbers. More generally, we give formulae for any Hurwitz zeta functions at any (strictly) negative
integer in terms of Bernoulli polynomials.
(Note that most of the actual work for these formulae is done elsewhere, in
`Mathlib/NumberTheory/ZetaValues.lean`. This file has only those results which really need the
definition of Hurwitz zeta and related functions, rather than working directly with the defining
sums in the convergence range.)
## Main results
- `hurwitzZeta_neg_nat`: for `k : ℕ` with `k ≠ 0`, and any `x ∈ ℝ / ℤ`, the special value
`hurwitzZeta x (-k)` is equal to `-(Polynomial.bernoulli (k + 1) x) / (k + 1)`.
- `riemannZeta_neg_nat_eq_bernoulli` : for any `k ∈ ℕ` we have the formula
`riemannZeta (-k) = (-1) ^ k * bernoulli (k + 1) / (k + 1)`
- `riemannZeta_two_mul_nat`: formula for `ζ(2 * k)` for `k ∈ ℕ, k ≠ 0` in terms of Bernoulli
numbers
## TODO
* Extend to cover Dirichlet L-functions.
* The formulae are correct for `s = 0` as well, but we do not prove this case, since this requires
Fourier series which are only conditionally convergent, which is difficult to approach using the
methods in the library at the present time (May 2024).
-/
open Complex Real Set
open scoped Nat
namespace HurwitzZeta
variable {k : ℕ} {x : ℝ}
/-- Express the value of `cosZeta` at a positive even integer as a value
of the Bernoulli polynomial. -/
theorem cosZeta_two_mul_nat (hk : k ≠ 0) (hx : x ∈ Icc 0 1) :
cosZeta x (2 * k) = (-1) ^ (k + 1) * (2 * π) ^ (2 * k) / 2 / (2 * k)! *
((Polynomial.bernoulli (2 * k)).map (algebraMap ℚ ℂ)).eval (x : ℂ) := by
rw [← (hasSum_nat_cosZeta x (?_ : 1 < re (2 * k))).tsum_eq]
· refine Eq.trans ?_ <|
(congr_arg ofReal (hasSum_one_div_nat_pow_mul_cos hk hx).tsum_eq).trans ?_
· rw [ofReal_tsum]
refine tsum_congr fun n ↦ ?_
norm_cast
ring_nf
· push_cast
congr 1
have : (Polynomial.bernoulli (2 * k)).map (algebraMap ℚ ℂ) = _ :=
(Polynomial.map_map (algebraMap ℚ ℝ) ofRealHom _).symm
rw [this, ← ofRealHom_eq_coe, ← ofRealHom_eq_coe]
apply Polynomial.map_aeval_eq_aeval_map (by simp)
· norm_cast
cutsat
/--
Express the value of `sinZeta` at an odd integer `> 1` as a value of the Bernoulli polynomial.
Note that this formula is also correct for `k = 0` (i.e. for the value at `s = 1`), but we do not
prove it in this case, owing to the additional difficulty of working with series that are only
conditionally convergent.
-/
theorem sinZeta_two_mul_nat_add_one (hk : k ≠ 0) (hx : x ∈ Icc 0 1) :
sinZeta x (2 * k + 1) = (-1) ^ (k + 1) * (2 * π) ^ (2 * k + 1) / 2 / (2 * k + 1)! *
((Polynomial.bernoulli (2 * k + 1)).map (algebraMap ℚ ℂ)).eval (x : ℂ) := by
rw [← (hasSum_nat_sinZeta x (?_ : 1 < re (2 * k + 1))).tsum_eq]
· refine Eq.trans ?_ <|
(congr_arg ofReal (hasSum_one_div_nat_pow_mul_sin hk hx).tsum_eq).trans ?_
· rw [ofReal_tsum]
refine tsum_congr fun n ↦ ?_
norm_cast
ring_nf
· push_cast
congr 1
have : (Polynomial.bernoulli (2 * k + 1)).map (algebraMap ℚ ℂ) = _ :=
(Polynomial.map_map (algebraMap ℚ ℝ) ofRealHom _).symm
rw [this, ← ofRealHom_eq_coe, ← ofRealHom_eq_coe]
apply Polynomial.map_aeval_eq_aeval_map (by simp)
· norm_cast
cutsat
/-- Reformulation of `cosZeta_two_mul_nat` using `Gammaℂ`. -/
theorem cosZeta_two_mul_nat' (hk : k ≠ 0) (hx : x ∈ Icc (0 : ℝ) 1) :
cosZeta x (2 * k) = (-1) ^ (k + 1) / (2 * k) / Gammaℂ (2 * k) *
((Polynomial.bernoulli (2 * k)).map (algebraMap ℚ ℂ)).eval (x : ℂ) := by
rw [cosZeta_two_mul_nat hk hx]
congr 1
have : (2 * k)! = (2 * k) * Complex.Gamma (2 * k) := by
rw [(by { norm_cast; omega } : 2 * (k : ℂ) = ↑(2 * k - 1) + 1), Complex.Gamma_nat_eq_factorial,
← Nat.cast_add_one, ← Nat.cast_mul, ← Nat.factorial_succ, Nat.sub_add_cancel (by cutsat)]
simp_rw [this, Gammaℂ, cpow_neg, ← div_div, div_inv_eq_mul, div_mul_eq_mul_div, div_div,
mul_right_comm (2 : ℂ) (k : ℂ)]
norm_cast
/-- Reformulation of `sinZeta_two_mul_nat_add_one` using `Gammaℂ`. -/
theorem sinZeta_two_mul_nat_add_one' (hk : k ≠ 0) (hx : x ∈ Icc (0 : ℝ) 1) :
sinZeta x (2 * k + 1) = (-1) ^ (k + 1) / (2 * k + 1) / Gammaℂ (2 * k + 1) *
((Polynomial.bernoulli (2 * k + 1)).map (algebraMap ℚ ℂ)).eval (x : ℂ) := by
rw [sinZeta_two_mul_nat_add_one hk hx]
congr 1
have : (2 * k + 1)! = (2 * k + 1) * Complex.Gamma (2 * k + 1) := by
rw [(by simp : Complex.Gamma (2 * k + 1) = Complex.Gamma (↑(2 * k) + 1)),
Complex.Gamma_nat_eq_factorial, ← Nat.cast_ofNat (R := ℂ), ← Nat.cast_mul,
← Nat.cast_add_one, ← Nat.cast_mul, ← Nat.factorial_succ]
simp_rw [this, Gammaℂ, cpow_neg, ← div_div, div_inv_eq_mul, div_mul_eq_mul_div, div_div]
rw [(by simp : 2 * (k : ℂ) + 1 = ↑(2 * k + 1)), cpow_natCast]
ring
theorem hurwitzZetaEven_one_sub_two_mul_nat (hk : k ≠ 0) (hx : x ∈ Icc (0 : ℝ) 1) :
hurwitzZetaEven x (1 - 2 * k) =
-1 / (2 * k) * ((Polynomial.bernoulli (2 * k)).map (algebraMap ℚ ℂ)).eval (x : ℂ) := by
have h1 (n : ℕ) : (2 * k : ℂ) ≠ -n := by
rw [← Int.cast_ofNat, ← Int.cast_natCast, ← Int.cast_mul, ← Int.cast_natCast n, ← Int.cast_neg,
Ne, Int.cast_inj, ← Ne]
refine ne_of_gt ((neg_nonpos_of_nonneg n.cast_nonneg).trans_lt (mul_pos two_pos ?_))
exact Nat.cast_pos.mpr (Nat.pos_of_ne_zero hk)
have h2 : (2 * k : ℂ) ≠ 1 := by norm_cast; simp
have h3 : Gammaℂ (2 * k) ≠ 0 := by
refine mul_ne_zero (mul_ne_zero two_ne_zero ?_) (Gamma_ne_zero h1)
simp [pi_ne_zero]
rw [hurwitzZetaEven_one_sub _ h1 (Or.inr h2), ← Gammaℂ, cosZeta_two_mul_nat' hk hx, ← mul_assoc,
← mul_div_assoc, mul_assoc, mul_div_cancel_left₀ _ h3, ← mul_div_assoc]
congr 2
rw [mul_div_assoc, mul_div_cancel_left₀ _ two_ne_zero, ← ofReal_natCast, ← ofReal_mul,
← ofReal_cos, mul_comm π, ← sub_zero (k * π), cos_nat_mul_pi_sub, Real.cos_zero, mul_one,
ofReal_pow, ofReal_neg, ofReal_one, pow_succ, mul_neg_one, mul_neg, ← mul_pow, neg_one_mul,
neg_neg, one_pow]
theorem hurwitzZetaOdd_neg_two_mul_nat (hk : k ≠ 0) (hx : x ∈ Icc (0 : ℝ) 1) :
hurwitzZetaOdd x (-(2 * k)) =
-1 / (2 * k + 1) * ((Polynomial.bernoulli (2 * k + 1)).map (algebraMap ℚ ℂ)).eval (x : ℂ) := by
have h1 (n : ℕ) : (2 * k + 1 : ℂ) ≠ -n := by
rw [← Int.cast_ofNat, ← Int.cast_natCast, ← Int.cast_mul, ← Int.cast_natCast n, ← Int.cast_neg,
← Int.cast_one, ← Int.cast_add, Ne, Int.cast_inj, ← Ne]
refine ne_of_gt ((neg_nonpos_of_nonneg n.cast_nonneg).trans_lt ?_)
positivity
have h3 : Gammaℂ (2 * k + 1) ≠ 0 := by
refine mul_ne_zero (mul_ne_zero two_ne_zero ?_) (Gamma_ne_zero h1)
simp [pi_ne_zero]
rw [(by simp : -(2 * k : ℂ) = 1 - (2 * k + 1)),
hurwitzZetaOdd_one_sub _ h1, ← Gammaℂ, sinZeta_two_mul_nat_add_one' hk hx, ← mul_assoc,
← mul_div_assoc, mul_assoc, mul_div_cancel_left₀ _ h3, ← mul_div_assoc]
congr 2
rw [mul_div_assoc, add_div, mul_div_cancel_left₀ _ two_ne_zero, ← ofReal_natCast,
← ofReal_one, ← ofReal_ofNat, ← ofReal_div, ← ofReal_add, ← ofReal_mul,
← ofReal_sin, mul_comm π, add_mul, mul_comm (1 / 2), mul_one_div, Real.sin_add_pi_div_two,
← sub_zero (k * π), cos_nat_mul_pi_sub, Real.cos_zero, mul_one,
ofReal_pow, ofReal_neg, ofReal_one, pow_succ, mul_neg_one, mul_neg, ← mul_pow, neg_one_mul,
neg_neg, one_pow]
-- private because it is superseded by `hurwitzZeta_neg_nat` below
private lemma hurwitzZeta_one_sub_two_mul_nat (hk : k ≠ 0) (hx : x ∈ Icc (0 : ℝ) 1) :
hurwitzZeta x (1 - 2 * k) =
-1 / (2 * k) * ((Polynomial.bernoulli (2 * k)).map (algebraMap ℚ ℂ)).eval (x : ℂ) := by
suffices hurwitzZetaOdd x (1 - 2 * k) = 0 by
rw [hurwitzZeta, this, add_zero, hurwitzZetaEven_one_sub_two_mul_nat hk hx]
obtain ⟨k, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hk
rw [Nat.cast_succ, show (1 : ℂ) - 2 * (k + 1) = -2 * k - 1 by ring,
hurwitzZetaOdd_neg_two_mul_nat_sub_one]
-- private because it is superseded by `hurwitzZeta_neg_nat` below
private lemma hurwitzZeta_neg_two_mul_nat (hk : k ≠ 0) (hx : x ∈ Icc (0 : ℝ) 1) :
hurwitzZeta x (-(2 * k)) = -1 / (2 * k + 1) *
((Polynomial.bernoulli (2 * k + 1)).map (algebraMap ℚ ℂ)).eval (x : ℂ) := by
suffices hurwitzZetaEven x (-(2 * k)) = 0 by
rw [hurwitzZeta, this, zero_add, hurwitzZetaOdd_neg_two_mul_nat hk hx]
obtain ⟨k, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hk
simpa using hurwitzZetaEven_neg_two_mul_nat_add_one x k
/-- Values of Hurwitz zeta functions at (strictly) negative integers.
TODO: This formula is also correct for `k = 0`; but our current proof does not work in this
case. -/
theorem hurwitzZeta_neg_nat (hk : k ≠ 0) (hx : x ∈ Icc (0 : ℝ) 1) :
hurwitzZeta x (-k) =
-1 / (k + 1) * ((Polynomial.bernoulli (k + 1)).map (algebraMap ℚ ℂ)).eval (x : ℂ) := by
rcases Nat.even_or_odd' k with ⟨n, (rfl | rfl)⟩
· exact_mod_cast hurwitzZeta_neg_two_mul_nat (by cutsat : n ≠ 0) hx
· exact_mod_cast hurwitzZeta_one_sub_two_mul_nat (by cutsat : n + 1 ≠ 0) hx
end HurwitzZeta
open HurwitzZeta
/-- Explicit formula for `ζ (2 * k)`, for `k ∈ ℕ` with `k ≠ 0`, in terms of the Bernoulli number
`bernoulli (2 * k)`.
Compare `hasSum_zeta_nat` for a version formulated in terms of a sum over `1 / n ^ (2 * k)`, and
`riemannZeta_neg_nat_eq_bernoulli` for values at negative integers (equivalent to the above via
the functional equation). -/
theorem riemannZeta_two_mul_nat {k : ℕ} (hk : k ≠ 0) :
riemannZeta (2 * k) = (-1) ^ (k + 1) * (2 : ℂ) ^ (2 * k - 1)
* (π : ℂ) ^ (2 * k) * bernoulli (2 * k) / (2 * k)! := by
convert congr_arg ((↑) : ℝ → ℂ) (hasSum_zeta_nat hk).tsum_eq
· rw [← Nat.cast_two, ← Nat.cast_mul, zeta_nat_eq_tsum_of_gt_one (by cutsat)]
simp [push_cast]
· norm_cast
theorem riemannZeta_two : riemannZeta 2 = (π : ℂ) ^ 2 / 6 := by
convert congr_arg ((↑) : ℝ → ℂ) hasSum_zeta_two.tsum_eq
· rw [← Nat.cast_two, zeta_nat_eq_tsum_of_gt_one one_lt_two]
simp [push_cast]
· norm_cast
theorem riemannZeta_four : riemannZeta 4 = π ^ 4 / 90 := by
convert congr_arg ((↑) : ℝ → ℂ) hasSum_zeta_four.tsum_eq
· rw [← Nat.cast_one, show (4 : ℂ) = (4 : ℕ) by simp,
zeta_nat_eq_tsum_of_gt_one (by simp : 1 < 4)]
simp only [push_cast]
· norm_cast
/-- Value of Riemann zeta at `-ℕ` in terms of `bernoulli'`. -/
theorem riemannZeta_neg_nat_eq_bernoulli' (k : ℕ) :
riemannZeta (-k) = -bernoulli' (k + 1) / (k + 1) := by
rcases eq_or_ne k 0 with rfl | hk
· rw [Nat.cast_zero, neg_zero, riemannZeta_zero, zero_add, zero_add, div_one,
bernoulli'_one, Rat.cast_div, Rat.cast_one, Rat.cast_ofNat, neg_div]
· rw [← hurwitzZeta_zero, ← QuotientAddGroup.mk_zero, hurwitzZeta_neg_nat hk
(left_mem_Icc.mpr zero_le_one), ofReal_zero, Polynomial.eval_zero_map,
Polynomial.bernoulli_eval_zero, Algebra.algebraMap_eq_smul_one, Rat.smul_one_eq_cast,
div_mul_eq_mul_div, neg_one_mul, bernoulli_eq_bernoulli'_of_ne_one (by simp [hk])]
/-- Value of Riemann zeta at `-ℕ` in terms of `bernoulli`. -/
theorem riemannZeta_neg_nat_eq_bernoulli (k : ℕ) :
riemannZeta (-k) = (-1 : ℂ) ^ k * bernoulli (k + 1) / (k + 1) := by
rw [riemannZeta_neg_nat_eq_bernoulli', bernoulli, Rat.cast_mul, Rat.cast_pow, Rat.cast_neg,
Rat.cast_one, ← neg_one_mul, ← mul_assoc, pow_succ, ← mul_assoc, ← mul_pow, neg_one_mul (-1),
neg_neg, one_pow, one_mul] |
.lake/packages/mathlib/Mathlib/NumberTheory/LSeries/Dirichlet.lean | import Mathlib.NumberTheory.DirichletCharacter.Bounds
import Mathlib.NumberTheory.LSeries.Convolution
import Mathlib.NumberTheory.LSeries.Deriv
import Mathlib.NumberTheory.LSeries.RiemannZeta
import Mathlib.NumberTheory.SumPrimeReciprocals
import Mathlib.NumberTheory.VonMangoldt
/-!
# L-series of Dirichlet characters and arithmetic functions
We collect some results on L-series of specific (arithmetic) functions, for example,
the Möbius function `μ` or the von Mangoldt function `Λ`. In particular, we show that
`L ↗Λ` is the negative of the logarithmic derivative of the Riemann zeta function
on `re s > 1`; see `LSeries_vonMangoldt_eq_deriv_riemannZeta_div`.
We also prove some general results on L-series associated to Dirichlet characters
(i.e., Dirichlet L-series). For example, we show that the abscissa of absolute convergence
equals `1` (see `DirichletCharacter.absicssaOfAbsConv`) and that the L-series does not
vanish on the open half-plane `re s > 1` (see `DirichletCharacter.LSeries_ne_zero_of_one_lt_re`).
We deduce results on the Riemann zeta function (which is `L 1` or `L ↗ζ` on `re s > 1`)
as special cases.
## Tags
Dirichlet L-series, Möbius function, von Mangoldt function, Riemann zeta function
-/
open scoped LSeries.notation
/-- `δ` is the function underlying the arithmetic function `1`. -/
lemma ArithmeticFunction.one_eq_delta : ↗(1 : ArithmeticFunction ℂ) = δ := by
ext
simp [one_apply, LSeries.delta]
section Moebius
/-!
### The L-series of the Möbius function
We show that `L μ s` converges absolutely if and only if `re s > 1`.
-/
namespace ArithmeticFunction
-- access notation `μ`
open scoped Moebius
open LSeries Nat Complex
lemma not_LSeriesSummable_moebius_at_one : ¬ LSeriesSummable ↗μ 1 := by
refine fun h ↦ not_summable_one_div_on_primes <| summable_ofReal.mp <| .of_neg ?_
refine (h.indicator {n | n.Prime}).congr fun n ↦ ?_
by_cases hn : n.Prime
· simp [hn, hn.ne_zero, moebius_apply_prime hn, push_cast, neg_div]
· simp [hn]
/-- The L-series of the Möbius function converges absolutely at `s` if and only if `re s > 1`. -/
lemma LSeriesSummable_moebius_iff {s : ℂ} : LSeriesSummable ↗μ s ↔ 1 < s.re := by
refine ⟨fun H ↦ ?_, LSeriesSummable_of_bounded_of_one_lt_re (m := 1) fun n _ ↦ ?_⟩
· by_contra! h
exact not_LSeriesSummable_moebius_at_one <| LSeriesSummable.of_re_le_re (by simpa) H
· norm_cast
exact abs_moebius_le_one
/-- The abscissa of absolute convergence of the L-series of the Möbius function is `1`. -/
lemma abscissaOfAbsConv_moebius : abscissaOfAbsConv ↗μ = 1 := by
simpa [abscissaOfAbsConv, LSeriesSummable_moebius_iff, Set.Ioi_def, EReal.image_coe_Ioi]
using csInf_Ioo <| EReal.coe_lt_top 1
end ArithmeticFunction
end Moebius
/-!
### L-series of Dirichlet characters
-/
open Nat
open scoped ArithmeticFunction.zeta in
lemma ArithmeticFunction.const_one_eq_zeta {R : Type*} [AddMonoidWithOne R] {n : ℕ} (hn : n ≠ 0) :
(1 : ℕ → R) n = (ζ ·) n := by
simp [hn]
lemma LSeries.one_convolution_eq_zeta_convolution {R : Type*} [Semiring R] (f : ℕ → R) :
(1 : ℕ → R) ⍟ f = ((ArithmeticFunction.zeta ·) : ℕ → R) ⍟ f :=
convolution_congr ArithmeticFunction.const_one_eq_zeta fun _ ↦ rfl
lemma LSeries.convolution_one_eq_convolution_zeta {R : Type*} [Semiring R] (f : ℕ → R) :
f ⍟ (1 : ℕ → R) = f ⍟ ((ArithmeticFunction.zeta ·) : ℕ → R) :=
convolution_congr (fun _ ↦ rfl) ArithmeticFunction.const_one_eq_zeta
/-- `χ₁` is (local) notation for the (necessarily trivial) Dirichlet character modulo `1`. -/
local notation (name := Dchar_one) "χ₁" => (1 : DirichletCharacter ℂ 1)
namespace DirichletCharacter
open ArithmeticFunction in
/-- The arithmetic function associated to a Dirichlet character is multiplicative. -/
lemma isMultiplicative_toArithmeticFunction {N : ℕ} {R : Type*} [CommMonoidWithZero R]
(χ : DirichletCharacter R N) :
(toArithmeticFunction (χ ·)).IsMultiplicative := by
refine IsMultiplicative.iff_ne_zero.mpr ⟨?_, fun {m} {n} hm hn _ ↦ ?_⟩
· simp [toArithmeticFunction]
· simp [toArithmeticFunction, hm, hn]
lemma apply_eq_toArithmeticFunction_apply {N : ℕ} {R : Type*} [CommMonoidWithZero R]
(χ : DirichletCharacter R N) {n : ℕ} (hn : n ≠ 0) :
χ n = toArithmeticFunction (χ ·) n := by
simp [toArithmeticFunction, hn]
open LSeries Nat Complex
/-- Twisting by a Dirichlet character `χ` distributes over convolution. -/
lemma mul_convolution_distrib {R : Type*} [CommSemiring R] {n : ℕ} (χ : DirichletCharacter R n)
(f g : ℕ → R) :
(((χ ·) : ℕ → R) * f) ⍟ (((χ ·) : ℕ → R) * g) = ((χ ·) : ℕ → R) * (f ⍟ g) := by
ext n
simp only [Pi.mul_apply, LSeries.convolution_def, Finset.mul_sum]
refine Finset.sum_congr rfl fun p hp ↦ ?_
rw [(mem_divisorsAntidiagonal.mp hp).1.symm, cast_mul, map_mul]
exact mul_mul_mul_comm ..
lemma mul_delta {n : ℕ} (χ : DirichletCharacter ℂ n) : ↗χ * δ = δ :=
LSeries.mul_delta <| by rw [cast_one, map_one]
lemma delta_mul {n : ℕ} (χ : DirichletCharacter ℂ n) : δ * ↗χ = δ :=
mul_comm δ _ ▸ mul_delta ..
open ArithmeticFunction in
open scoped Moebius in -- access notation `μ`
/-- The convolution of a Dirichlet character `χ` with the twist `χ * μ` is `δ`,
the indicator function of `{1}`. -/
lemma convolution_mul_moebius {n : ℕ} (χ : DirichletCharacter ℂ n) : ↗χ ⍟ (↗χ * ↗μ) = δ := by
have : (1 : ℕ → ℂ) ⍟ (μ ·) = δ := by
rw [one_convolution_eq_zeta_convolution, ← one_eq_delta]
simp_rw [← natCoe_apply, ← intCoe_apply, coe_mul, coe_zeta_mul_coe_moebius]
nth_rewrite 1 [← mul_one ↗χ]
simpa only [mul_convolution_distrib χ 1 ↗μ, this] using mul_delta _
/-- The Dirichlet character mod `0` corresponds to `δ`. -/
lemma modZero_eq_delta {χ : DirichletCharacter ℂ 0} : ↗χ = δ := by
ext n
rcases eq_or_ne n 0 with rfl | hn
· simp_rw [cast_zero, χ.map_nonunit not_isUnit_zero, delta, reduceCtorEq, if_false]
rcases eq_or_ne n 1 with rfl | hn'
· simp [delta]
have : ¬ IsUnit (n : ZMod 0) := fun h ↦ hn' <| ZMod.eq_one_of_isUnit_natCast h
simp_all [χ.map_nonunit this, delta]
/-- The Dirichlet character mod `1` corresponds to the constant function `1`. -/
lemma modOne_eq_one {R : Type*} [CommMonoidWithZero R] {χ : DirichletCharacter R 1} :
((χ ·) : ℕ → R) = 1 := by
ext
rw [χ.level_one, MulChar.one_apply (isUnit_of_subsingleton _), Pi.one_apply]
lemma LSeries_modOne_eq : L ↗χ₁ = L 1 :=
congr_arg L modOne_eq_one
/-- The L-series of a Dirichlet character mod `N > 0` does not converge absolutely at `s = 1`. -/
lemma not_LSeriesSummable_at_one {N : ℕ} (hN : N ≠ 0) (χ : DirichletCharacter ℂ N) :
¬ LSeriesSummable ↗χ 1 := by
refine fun h ↦ (Real.not_summable_indicator_one_div_natCast hN 1) ?_
refine h.norm.of_nonneg_of_le (fun m ↦ Set.indicator_apply_nonneg (fun _ ↦ by positivity))
(fun n ↦ ?_)
simp only [norm_term_eq, Set.indicator, Set.mem_setOf_eq]
split_ifs with h₁ h₂
· simp [h₂]
· simp [h₁, χ.map_one]
all_goals positivity
/-- The L-series of a Dirichlet character converges absolutely at `s` if `re s > 1`. -/
lemma LSeriesSummable_of_one_lt_re {N : ℕ} (χ : DirichletCharacter ℂ N) {s : ℂ} (hs : 1 < s.re) :
LSeriesSummable ↗χ s :=
LSeriesSummable_of_bounded_of_one_lt_re (fun _ _ ↦ χ.norm_le_one _) hs
/-- The L-series of a Dirichlet character mod `N > 0` converges absolutely at `s` if and only if
`re s > 1`. -/
lemma LSeriesSummable_iff {N : ℕ} (hN : N ≠ 0) (χ : DirichletCharacter ℂ N) {s : ℂ} :
LSeriesSummable ↗χ s ↔ 1 < s.re := by
refine ⟨fun H ↦ ?_, LSeriesSummable_of_one_lt_re χ⟩
by_contra! h
exact not_LSeriesSummable_at_one hN χ <| LSeriesSummable.of_re_le_re (by simp [h]) H
/-- The abscissa of absolute convergence of the L-series of a Dirichlet character mod `N > 0`
is `1`. -/
lemma absicssaOfAbsConv_eq_one {N : ℕ} (hn : N ≠ 0) (χ : DirichletCharacter ℂ N) :
abscissaOfAbsConv ↗χ = 1 := by
simpa [abscissaOfAbsConv, LSeriesSummable_iff hn χ, Set.Ioi_def, EReal.image_coe_Ioi]
using csInf_Ioo <| EReal.coe_lt_top 1
/-- The L-series of the twist of `f` by a Dirichlet character converges at `s` if the L-series
of `f` does. -/
lemma LSeriesSummable_mul {N : ℕ} (χ : DirichletCharacter ℂ N) {f : ℕ → ℂ} {s : ℂ}
(h : LSeriesSummable f s) :
LSeriesSummable (↗χ * f) s := by
refine .of_norm <| h.norm.of_nonneg_of_le (fun _ ↦ norm_nonneg _) fun n ↦ norm_term_le s ?_
simpa using mul_le_of_le_one_left (norm_nonneg <| f n) <| χ.norm_le_one n
open scoped ArithmeticFunction.Moebius in
/-- The L-series of a Dirichlet character `χ` and of the twist of `μ` by `χ` are multiplicative
inverses. -/
lemma LSeries.mul_mu_eq_one {N : ℕ} (χ : DirichletCharacter ℂ N) {s : ℂ}
(hs : 1 < s.re) : L ↗χ s * L (↗χ * ↗μ) s = 1 := by
rw [← LSeries_convolution' (LSeriesSummable_of_one_lt_re χ hs) <|
LSeriesSummable_mul χ <| ArithmeticFunction.LSeriesSummable_moebius_iff.mpr hs,
convolution_mul_moebius, LSeries_delta, Pi.one_apply]
/-!
### L-series of Dirichlet characters do not vanish on re s > 1
-/
/-- The L-series of a Dirichlet character does not vanish on the right half-plane `re s > 1`. -/
lemma LSeries_ne_zero_of_one_lt_re {N : ℕ} (χ : DirichletCharacter ℂ N) {s : ℂ} (hs : 1 < s.re) :
L ↗χ s ≠ 0 :=
fun h ↦ by simpa [h] using LSeries.mul_mu_eq_one χ hs
end DirichletCharacter
section zeta
/-!
### The L-series of the constant sequence 1 / the arithmetic function ζ
Both give the same L-series (since the difference in values at zero has no effect;
see `ArithmeticFunction.LSeries_zeta_eq`), which agrees with the Riemann zeta function
on `re s > 1`. We state most results in two versions, one for `1` and one for `↗ζ`.
-/
open LSeries Nat Complex DirichletCharacter
/-- The abscissa of (absolute) convergence of the constant sequence `1` is `1`. -/
lemma LSeries.abscissaOfAbsConv_one : abscissaOfAbsConv 1 = 1 :=
modOne_eq_one (χ := χ₁) ▸ absicssaOfAbsConv_eq_one one_ne_zero χ₁
/-- The `LSeries` of the constant sequence `1` converges at `s` if and only if `re s > 1`. -/
theorem LSeriesSummable_one_iff {s : ℂ} : LSeriesSummable 1 s ↔ 1 < s.re :=
modOne_eq_one (χ := χ₁) ▸ LSeriesSummable_iff one_ne_zero χ₁
namespace ArithmeticFunction
-- access notation `ζ` and `μ`
open scoped zeta Moebius
/-- The `LSeries` of the arithmetic function `ζ` is the same as the `LSeries` associated
to the constant sequence `1`. -/
lemma LSeries_zeta_eq : L ↗ζ = L 1 := by
ext s
exact (LSeries_congr const_one_eq_zeta s).symm
/-- The `LSeries` associated to the arithmetic function `ζ` converges at `s` if and only if
`re s > 1`. -/
theorem LSeriesSummable_zeta_iff {s : ℂ} : LSeriesSummable (ζ ·) s ↔ 1 < s.re :=
(LSeriesSummable_congr s const_one_eq_zeta).symm.trans <| LSeriesSummable_one_iff
/-- The abscissa of (absolute) convergence of the arithmetic function `ζ` is `1`. -/
lemma abscissaOfAbsConv_zeta : abscissaOfAbsConv ↗ζ = 1 := by
rw [abscissaOfAbsConv_congr (g := 1) fun hn ↦ by simp [hn], abscissaOfAbsConv_one]
/-- The L-series of the arithmetic function `ζ` equals the Riemann Zeta Function on its
domain of convergence `1 < re s`. -/
lemma LSeries_zeta_eq_riemannZeta {s : ℂ} (hs : 1 < s.re) : L ↗ζ s = riemannZeta s := by
suffices ∑' n, term (fun n ↦ if n = 0 then 0 else 1) s n = ∑' n : ℕ, 1 / (n : ℂ) ^ s by
simpa [LSeries, zeta_eq_tsum_one_div_nat_cpow hs]
refine tsum_congr fun n ↦ ?_
rcases eq_or_ne n 0 with hn | hn <;>
simp [hn, ne_zero_of_one_lt_re hs]
/-- The L-series of the arithmetic function `ζ` equals the Riemann Zeta Function on its
domain of convergence `1 < re s`. -/
lemma LSeriesHasSum_zeta {s : ℂ} (hs : 1 < s.re) : LSeriesHasSum ↗ζ s (riemannZeta s) :=
LSeries_zeta_eq_riemannZeta hs ▸ (LSeriesSummable_zeta_iff.mpr hs).LSeriesHasSum
/-- The L-series of the arithmetic function `ζ` and of the Möbius function are inverses. -/
lemma LSeries_zeta_mul_Lseries_moebius {s : ℂ} (hs : 1 < s.re) : L ↗ζ s * L ↗μ s = 1 := by
rw [← LSeries_convolution' (LSeriesSummable_zeta_iff.mpr hs)
(LSeriesSummable_moebius_iff.mpr hs)]
simp [← natCoe_apply, ← intCoe_apply, coe_mul, one_eq_delta, LSeries_delta, -zeta_apply]
/-- The L-series of the arithmetic function `ζ` does not vanish on the right half-plane
`re s > 1`. -/
lemma LSeries_zeta_ne_zero_of_one_lt_re {s : ℂ} (hs : 1 < s.re) : L ↗ζ s ≠ 0 :=
fun h ↦ by simpa [h, -zeta_apply] using LSeries_zeta_mul_Lseries_moebius hs
end ArithmeticFunction
open ArithmeticFunction
/-- The L-series of the constant sequence `1` equals the Riemann Zeta Function on its
domain of convergence `1 < re s`. -/
lemma LSeries_one_eq_riemannZeta {s : ℂ} (hs : 1 < s.re) : L 1 s = riemannZeta s :=
LSeries_zeta_eq ▸ LSeries_zeta_eq_riemannZeta hs
/-- The L-series of the constant sequence `1` equals the Riemann zeta function on its
domain of convergence `1 < re s`. -/
lemma LSeriesHasSum_one {s : ℂ} (hs : 1 < s.re) : LSeriesHasSum 1 s (riemannZeta s) :=
LSeries_one_eq_riemannZeta hs ▸ (LSeriesSummable_one_iff.mpr hs).LSeriesHasSum
open scoped Moebius in -- access notation `μ`
/-- The L-series of the constant sequence `1` and of the Möbius function are inverses. -/
lemma LSeries_one_mul_Lseries_moebius {s : ℂ} (hs : 1 < s.re) : L 1 s * L ↗μ s = 1 :=
LSeries_zeta_eq ▸ LSeries_zeta_mul_Lseries_moebius hs
/-- The L-series of the constant sequence `1` does not vanish on the right half-plane
`re s > 1`. -/
lemma LSeries_one_ne_zero_of_one_lt_re {s : ℂ} (hs : 1 < s.re) : L 1 s ≠ 0 :=
LSeries_zeta_eq ▸ LSeries_zeta_ne_zero_of_one_lt_re hs
/-- The Riemann Zeta Function does not vanish on the half-plane `re s > 1`. -/
lemma riemannZeta_ne_zero_of_one_lt_re {s : ℂ} (hs : 1 < s.re) : riemannZeta s ≠ 0 :=
LSeries_one_eq_riemannZeta hs ▸ LSeries_one_ne_zero_of_one_lt_re hs
end zeta
section vonMangoldt
/-!
### The L-series of the von Mangoldt function
-/
open LSeries Nat Complex ArithmeticFunction
namespace ArithmeticFunction
-- access notation `ζ`
open scoped zeta
/-- A translation of the relation `Λ * ↑ζ = log` of (real-valued) arithmetic functions
to an equality of complex sequences. -/
lemma convolution_vonMangoldt_zeta : ↗Λ ⍟ ↗ζ = ↗Complex.log := by
ext n
simpa [apply_ite, LSeries.convolution_def, -vonMangoldt_mul_zeta]
using congr_arg (ofReal <| · n) vonMangoldt_mul_zeta
lemma convolution_vonMangoldt_const_one : ↗Λ ⍟ 1 = ↗Complex.log :=
(convolution_one_eq_convolution_zeta _).trans convolution_vonMangoldt_zeta
/-- The L-series of the von Mangoldt function `Λ` converges at `s` when `re s > 1`. -/
lemma LSeriesSummable_vonMangoldt {s : ℂ} (hs : 1 < s.re) : LSeriesSummable ↗Λ s := by
have hf := LSeriesSummable_logMul_of_lt_re
(show abscissaOfAbsConv 1 < s.re by rw [abscissaOfAbsConv_one]; exact_mod_cast hs)
rw [LSeriesSummable, ← summable_norm_iff] at hf ⊢
refine hf.of_nonneg_of_le (fun _ ↦ norm_nonneg _) (fun n ↦ norm_term_le s ?_)
have hΛ : ‖↗Λ n‖ ≤ ‖Complex.log n‖ := by
simpa [abs_of_nonneg, vonMangoldt_nonneg, ← natCast_log, Real.log_natCast_nonneg]
using vonMangoldt_le_log
exact hΛ.trans <| by simp
end ArithmeticFunction
namespace DirichletCharacter
/-- A twisted version of the relation `Λ * ↑ζ = log` in terms of complex sequences. -/
lemma convolution_twist_vonMangoldt {N : ℕ} (χ : DirichletCharacter ℂ N) :
(↗χ * ↗Λ) ⍟ ↗χ = ↗χ * ↗Complex.log := by
rw [← convolution_vonMangoldt_const_one, ← χ.mul_convolution_distrib, mul_one]
/-- The L-series of the twist of the von Mangoldt function `Λ` by a Dirichlet character `χ`
converges at `s` when `re s > 1`. -/
lemma LSeriesSummable_twist_vonMangoldt {N : ℕ} (χ : DirichletCharacter ℂ N) {s : ℂ}
(hs : 1 < s.re) :
LSeriesSummable (↗χ * ↗Λ) s :=
LSeriesSummable_mul χ <| LSeriesSummable_vonMangoldt hs
/-- The L-series of the twist of the von Mangoldt function `Λ` by a Dirichlet character `χ` at `s`
equals the negative logarithmic derivative of the L-series of `χ` when `re s > 1`. -/
lemma LSeries_twist_vonMangoldt_eq {N : ℕ} (χ : DirichletCharacter ℂ N) {s : ℂ} (hs : 1 < s.re) :
L (↗χ * ↗Λ) s = -deriv (L ↗χ) s / L ↗χ s := by
rcases eq_or_ne N 0 with rfl | hN
· simp [modZero_eq_delta, delta_mul_eq_smul_delta, LSeries_delta]
-- now `N ≠ 0`
have hχ : LSeriesSummable ↗χ s := (LSeriesSummable_iff hN χ).mpr hs
have hs' : abscissaOfAbsConv ↗χ < s.re := by
rwa [absicssaOfAbsConv_eq_one hN, ← EReal.coe_one, EReal.coe_lt_coe_iff]
have hΛ : LSeriesSummable (↗χ * ↗Λ) s := LSeriesSummable_twist_vonMangoldt χ hs
rw [eq_div_iff <| LSeries_ne_zero_of_one_lt_re χ hs, ← LSeries_convolution' hΛ hχ,
convolution_twist_vonMangoldt, LSeries_deriv hs', neg_neg]
exact LSeries_congr (fun _ ↦ by simp [mul_comm, logMul]) s
end DirichletCharacter
namespace ArithmeticFunction
open DirichletCharacter in
/-- The L-series of the von Mangoldt function `Λ` equals the negative logarithmic derivative
of the L-series of the constant sequence `1` on its domain of convergence `re s > 1`. -/
lemma LSeries_vonMangoldt_eq {s : ℂ} (hs : 1 < s.re) : L ↗Λ s = - deriv (L 1) s / L 1 s := by
refine (LSeries_congr (fun {n} _ ↦ ?_) s).trans <|
LSeries_modOne_eq ▸ LSeries_twist_vonMangoldt_eq χ₁ hs
simp [Subsingleton.eq_one (n : ZMod 1)]
/-- The L-series of the von Mangoldt function `Λ` equals the negative logarithmic derivative
of the Riemann zeta function on its domain of convergence `re s > 1`. -/
lemma LSeries_vonMangoldt_eq_deriv_riemannZeta_div {s : ℂ} (hs : 1 < s.re) :
L ↗Λ s = - deriv riemannZeta s / riemannZeta s := by
suffices deriv (L 1) s = deriv riemannZeta s by
rw [LSeries_vonMangoldt_eq hs, ← LSeries_one_eq_riemannZeta hs, this]
refine Filter.EventuallyEq.deriv_eq <| Filter.eventuallyEq_iff_exists_mem.mpr ?_
exact ⟨{z | 1 < z.re}, (isOpen_lt continuous_const continuous_re).mem_nhds hs,
fun _ ↦ LSeries_one_eq_riemannZeta⟩
end ArithmeticFunction
end vonMangoldt |
.lake/packages/mathlib/Mathlib/NumberTheory/LSeries/Convolution.lean | import Mathlib.Algebra.BigOperators.Field
import Mathlib.Analysis.Normed.Ring.InfiniteSum
import Mathlib.NumberTheory.ArithmeticFunction
import Mathlib.NumberTheory.LSeries.Convergence
/-!
# Dirichlet convolution of sequences and products of L-series
We define the *Dirichlet convolution* `f ⍟ g` of two sequences `f g : ℕ → R` with values in a
semiring `R` by `(f ⍟ g) n = ∑ (k * m = n), f k * g m` when `n ≠ 0` and `(f ⍟ g) 0 = 0`.
Technically, this is done by transporting the existing definition for `ArithmeticFunction R`;
see `LSeries.convolution`. We show that these definitions agree (`LSeries.convolution_def`).
We then consider the case `R = ℂ` and show that `L (f ⍟ g) = L f * L g` on the common domain
of convergence of the L-series `L f` and `L g` of `f` and `g`; see `LSeries_convolution`
and `LSeries_convolution'`.
-/
open scoped LSeries.notation
open Complex LSeries
/-!
### Dirichlet convolution of two functions
-/
open Nat
/-- We turn any function `ℕ → R` into an `ArithmeticFunction R` by setting its value at `0`
to be zero. -/
def toArithmeticFunction {R : Type*} [Zero R] (f : ℕ → R) : ArithmeticFunction R where
toFun n := if n = 0 then 0 else f n
map_zero' := rfl
lemma toArithmeticFunction_congr {R : Type*} [Zero R] {f f' : ℕ → R}
(h : ∀ {n}, n ≠ 0 → f n = f' n) :
toArithmeticFunction f = toArithmeticFunction f' := by
ext
simp_all [toArithmeticFunction]
/-- If we consider an arithmetic function just as a function and turn it back into an
arithmetic function, it is the same as before. -/
@[simp]
lemma ArithmeticFunction.toArithmeticFunction_eq_self {R : Type*} [Zero R]
(f : ArithmeticFunction R) :
toArithmeticFunction f = f := by
ext n
simp +contextual [toArithmeticFunction]
/-- Dirichlet convolution of two sequences.
We define this in terms of the already existing definition for arithmetic functions. -/
noncomputable def LSeries.convolution {R : Type*} [Semiring R] (f g : ℕ → R) : ℕ → R :=
⇑(toArithmeticFunction f * toArithmeticFunction g)
@[inherit_doc]
scoped[LSeries.notation] infixl:70 " ⍟ " => LSeries.convolution
lemma LSeries.convolution_congr {R : Type*} [Semiring R] {f f' g g' : ℕ → R}
(hf : ∀ {n}, n ≠ 0 → f n = f' n) (hg : ∀ {n}, n ≠ 0 → g n = g' n) :
f ⍟ g = f' ⍟ g' := by
simp [convolution, toArithmeticFunction_congr hf, toArithmeticFunction_congr hg]
/-- The product of two arithmetic functions defines the same function as the Dirichlet convolution
of the functions defined by them. -/
lemma ArithmeticFunction.coe_mul {R : Type*} [Semiring R] (f g : ArithmeticFunction R) :
f ⍟ g = ⇑(f * g) := by
simp [convolution]
namespace LSeries
lemma convolution_def {R : Type*} [Semiring R] (f g : ℕ → R) :
f ⍟ g = fun n ↦ ∑ p ∈ n.divisorsAntidiagonal, f p.1 * g p.2 := by
ext n
simpa [convolution, toArithmeticFunction] using
Finset.sum_congr rfl fun p hp ↦ by simp [ne_zero_of_mem_divisorsAntidiagonal hp]
@[simp]
lemma convolution_map_zero {R : Type*} [Semiring R] (f g : ℕ → R) : (f ⍟ g) 0 = 0 := by
simp [convolution_def]
/-!
### Multiplication of L-series
-/
/-- We give an expression of the `LSeries.term` of the convolution of two functions
in terms of a sum over `Nat.divisorsAntidiagonal`. -/
lemma term_convolution (f g : ℕ → ℂ) (s : ℂ) (n : ℕ) :
term (f ⍟ g) s n = ∑ p ∈ n.divisorsAntidiagonal, term f s p.1 * term g s p.2 := by
rcases eq_or_ne n 0 with rfl | hn
· simp
-- now `n ≠ 0`
rw [term_of_ne_zero hn, convolution_def, Finset.sum_div]
refine Finset.sum_congr rfl fun p hp ↦ ?_
have ⟨hp₁, hp₂⟩ := ne_zero_of_mem_divisorsAntidiagonal hp
rw [term_of_ne_zero hp₁, term_of_ne_zero hp₂, mul_comm_div, div_div, ← mul_div_assoc,
← natCast_mul_natCast_cpow, ← cast_mul, mul_comm p.2, (mem_divisorsAntidiagonal.mp hp).1]
open Set in
/-- We give an expression of the `LSeries.term` of the convolution of two functions
in terms of an a priori infinite sum over all pairs `(k, m)` with `k * m = n`
(the set we sum over is infinite when `n = 0`). This is the version needed for the
proof that `L (f ⍟ g) = L f * L g`. -/
lemma term_convolution' (f g : ℕ → ℂ) (s : ℂ) :
term (f ⍟ g) s = fun n ↦
∑' (b : (fun p : ℕ × ℕ ↦ p.1 * p.2) ⁻¹' {n}), term f s b.val.1 * term g s b.val.2 := by
ext n
rcases eq_or_ne n 0 with rfl | hn
· -- show that both sides vanish when `n = 0`; this is the hardest part of the proof!
refine (term_zero ..).trans ?_
-- the right-hand sum is over the union below, but in each term, one factor is always zero
have hS : (fun p ↦ p.1 * p.2) ⁻¹' {0} = {0} ×ˢ univ ∪ univ ×ˢ {0} := by
ext
simp
have : ∀ p : (fun p : ℕ × ℕ ↦ p.1 * p.2) ⁻¹' {0}, term f s p.val.1 * term g s p.val.2 = 0 := by
rintro ⟨⟨_, _⟩, hp⟩
rcases hS ▸ hp with ⟨rfl, -⟩ | ⟨-, rfl⟩ <;> simp
simp [this]
-- now `n ≠ 0`
rw [show (fun p : ℕ × ℕ ↦ p.1 * p.2) ⁻¹' {n} = n.divisorsAntidiagonal by ext; simp [hn],
Finset.tsum_subtype' n.divisorsAntidiagonal fun p ↦ term f s p.1 * term g s p.2,
term_convolution f g s n]
end LSeries
open Set in
/-- The L-series of the convolution product `f ⍟ g` of two sequences `f` and `g`
equals the product of their L-series, assuming both L-series converge. -/
lemma LSeriesHasSum.convolution {f g : ℕ → ℂ} {s a b : ℂ} (hf : LSeriesHasSum f s a)
(hg : LSeriesHasSum g s b) :
LSeriesHasSum (f ⍟ g) s (a * b) := by
have hsum := summable_mul_of_summable_norm hf.summable.norm hg.summable.norm
-- NB: this `simpa` is quite slow if un-squeezed
simpa only [LSeriesHasSum, term_convolution'] using (hf.mul hg hsum).tsum_fiberwise _
/-- The L-series of the convolution product `f ⍟ g` of two sequences `f` and `g`
equals the product of their L-series, assuming both L-series converge. -/
lemma LSeries_convolution' {f g : ℕ → ℂ} {s : ℂ} (hf : LSeriesSummable f s)
(hg : LSeriesSummable g s) :
LSeries (f ⍟ g) s = LSeries f s * LSeries g s :=
(LSeriesHasSum.convolution hf.LSeriesHasSum hg.LSeriesHasSum).LSeries_eq
/-- The L-series of the convolution product `f ⍟ g` of two sequences `f` and `g`
equals the product of their L-series in their common half-plane of absolute convergence. -/
lemma LSeries_convolution {f g : ℕ → ℂ} {s : ℂ}
(hf : abscissaOfAbsConv f < s.re) (hg : abscissaOfAbsConv g < s.re) :
LSeries (f ⍟ g) s = LSeries f s * LSeries g s :=
LSeries_convolution' (LSeriesSummable_of_abscissaOfAbsConv_lt_re hf)
(LSeriesSummable_of_abscissaOfAbsConv_lt_re hg)
/-- The L-series of the convolution product `f ⍟ g` of two sequences `f` and `g`
is summable when both L-series are summable. -/
lemma LSeriesSummable.convolution {f g : ℕ → ℂ} {s : ℂ} (hf : LSeriesSummable f s)
(hg : LSeriesSummable g s) :
LSeriesSummable (f ⍟ g) s :=
(LSeriesHasSum.convolution hf.LSeriesHasSum hg.LSeriesHasSum).LSeriesSummable
/-- The abscissa of absolute convergence of `f ⍟ g` is at most the maximum of those
of `f` and `g`. -/
lemma LSeries.abscissaOfAbsConv_convolution_le (f g : ℕ → ℂ) :
abscissaOfAbsConv (f ⍟ g) ≤ max (abscissaOfAbsConv f) (abscissaOfAbsConv g) :=
abscissaOfAbsConv_binop_le LSeriesSummable.convolution f g
namespace ArithmeticFunction
/-!
### Versions for arithmetic functions
-/
/-- The L-series of the (convolution) product of two `ℂ`-valued arithmetic functions `f` and `g`
equals the product of their L-series, assuming both L-series converge. -/
lemma LSeriesHasSum_mul {f g : ArithmeticFunction ℂ} {s a b : ℂ} (hf : LSeriesHasSum ↗f s a)
(hg : LSeriesHasSum ↗g s b) :
LSeriesHasSum ↗(f * g) s (a * b) :=
coe_mul f g ▸ hf.convolution hg
/-- The L-series of the (convolution) product of two `ℂ`-valued arithmetic functions `f` and `g`
equals the product of their L-series, assuming both L-series converge. -/
lemma LSeries_mul' {f g : ArithmeticFunction ℂ} {s : ℂ} (hf : LSeriesSummable ↗f s)
(hg : LSeriesSummable ↗g s) :
LSeries ↗(f * g) s = LSeries ↗f s * LSeries ↗g s :=
coe_mul f g ▸ LSeries_convolution' hf hg
/-- The L-series of the (convolution) product of two `ℂ`-valued arithmetic functions `f` and `g`
equals the product of their L-series in their common half-plane of absolute convergence. -/
lemma LSeries_mul {f g : ArithmeticFunction ℂ} {s : ℂ}
(hf : abscissaOfAbsConv ↗f < s.re) (hg : abscissaOfAbsConv ↗g < s.re) :
LSeries ↗(f * g) s = LSeries ↗f s * LSeries ↗g s :=
coe_mul f g ▸ LSeries_convolution hf hg
/-- The L-series of the (convolution) product of two `ℂ`-valued arithmetic functions `f` and `g`
is summable when both L-series are summable. -/
lemma LSeriesSummable_mul {f g : ArithmeticFunction ℂ} {s : ℂ} (hf : LSeriesSummable ↗f s)
(hg : LSeriesSummable ↗g s) :
LSeriesSummable ↗(f * g) s :=
coe_mul f g ▸ hf.convolution hg
end ArithmeticFunction |
.lake/packages/mathlib/Mathlib/NumberTheory/LSeries/RiemannZeta.lean | import Mathlib.NumberTheory.LSeries.HurwitzZeta
import Mathlib.Analysis.PSeriesComplex
/-!
# Definition of the Riemann zeta function
## Main definitions:
* `riemannZeta`: the Riemann zeta function `ζ : ℂ → ℂ`.
* `completedRiemannZeta`: the completed zeta function `Λ : ℂ → ℂ`, which satisfies
`Λ(s) = π ^ (-s / 2) Γ(s / 2) ζ(s)` (away from the poles of `Γ(s / 2)`).
* `completedRiemannZeta₀`: the entire function `Λ₀` satisfying
`Λ₀(s) = Λ(s) + 1 / (s - 1) - 1 / s` wherever the RHS is defined.
Note that mathematically `ζ(s)` is undefined at `s = 1`, while `Λ(s)` is undefined at both `s = 0`
and `s = 1`. Our construction assigns some values at these points; exact formulae involving the
Euler-Mascheroni constant will follow in a subsequent PR.
## Main results:
* `differentiable_completedZeta₀` : the function `Λ₀(s)` is entire.
* `differentiableAt_completedZeta` : the function `Λ(s)` is differentiable away from `s = 0` and
`s = 1`.
* `differentiableAt_riemannZeta` : the function `ζ(s)` is differentiable away from `s = 1`.
* `zeta_eq_tsum_one_div_nat_add_one_cpow` : for `1 < re s`, we have
`ζ(s) = ∑' (n : ℕ), 1 / (n + 1) ^ s`.
* `completedRiemannZeta₀_one_sub`, `completedRiemannZeta_one_sub`, and `riemannZeta_one_sub` :
functional equation relating values at `s` and `1 - s`
For special-value formulae expressing `ζ (2 * k)` and `ζ (1 - 2 * k)` in terms of Bernoulli numbers
see `Mathlib/NumberTheory/LSeries/HurwitzZetaValues.lean`. For computation of the constant term as
`s → 1`, see `Mathlib/NumberTheory/Harmonic/ZetaAsymp.lean`.
## Outline of proofs:
These results are mostly special cases of more general results for even Hurwitz zeta functions
proved in `Mathlib/NumberTheory/LSeries/HurwitzZetaEven.lean`.
-/
open CharZero Set Filter HurwitzZeta
open Complex hiding exp continuous_exp
open scoped Topology Real
noncomputable section
/-!
## Definition of the completed Riemann zeta
-/
/-- The completed Riemann zeta function with its poles removed, `Λ(s) + 1 / s - 1 / (s - 1)`. -/
def completedRiemannZeta₀ (s : ℂ) : ℂ := completedHurwitzZetaEven₀ 0 s
/-- The completed Riemann zeta function, `Λ(s)`, which satisfies
`Λ(s) = π ^ (-s / 2) Γ(s / 2) ζ(s)` (up to a minor correction at `s = 0`). -/
def completedRiemannZeta (s : ℂ) : ℂ := completedHurwitzZetaEven 0 s
lemma HurwitzZeta.completedHurwitzZetaEven_zero (s : ℂ) :
completedHurwitzZetaEven 0 s = completedRiemannZeta s := rfl
lemma HurwitzZeta.completedHurwitzZetaEven₀_zero (s : ℂ) :
completedHurwitzZetaEven₀ 0 s = completedRiemannZeta₀ s := rfl
lemma HurwitzZeta.completedCosZeta_zero (s : ℂ) :
completedCosZeta 0 s = completedRiemannZeta s := by
rw [completedRiemannZeta, completedHurwitzZetaEven, completedCosZeta, hurwitzEvenFEPair_zero_symm]
lemma HurwitzZeta.completedCosZeta₀_zero (s : ℂ) :
completedCosZeta₀ 0 s = completedRiemannZeta₀ s := by
rw [completedRiemannZeta₀, completedHurwitzZetaEven₀, completedCosZeta₀,
hurwitzEvenFEPair_zero_symm]
lemma completedRiemannZeta_eq (s : ℂ) :
completedRiemannZeta s = completedRiemannZeta₀ s - 1 / s - 1 / (1 - s) := by
simp_rw [completedRiemannZeta, completedRiemannZeta₀, completedHurwitzZetaEven_eq, if_true]
/-- The modified completed Riemann zeta function `Λ(s) + 1 / s + 1 / (1 - s)` is entire. -/
theorem differentiable_completedZeta₀ : Differentiable ℂ completedRiemannZeta₀ :=
differentiable_completedHurwitzZetaEven₀ 0
/-- The completed Riemann zeta function `Λ(s)` is differentiable away from `s = 0` and `s = 1`. -/
theorem differentiableAt_completedZeta {s : ℂ} (hs : s ≠ 0) (hs' : s ≠ 1) :
DifferentiableAt ℂ completedRiemannZeta s :=
differentiableAt_completedHurwitzZetaEven 0 (Or.inl hs) hs'
/-- Riemann zeta functional equation, formulated for `Λ₀`: for any complex `s` we have
`Λ₀(1 - s) = Λ₀ s`. -/
theorem completedRiemannZeta₀_one_sub (s : ℂ) :
completedRiemannZeta₀ (1 - s) = completedRiemannZeta₀ s := by
rw [← completedHurwitzZetaEven₀_zero, ← completedCosZeta₀_zero, completedHurwitzZetaEven₀_one_sub]
/-- Riemann zeta functional equation, formulated for `Λ`: for any complex `s` we have
`Λ (1 - s) = Λ s`. -/
theorem completedRiemannZeta_one_sub (s : ℂ) :
completedRiemannZeta (1 - s) = completedRiemannZeta s := by
rw [← completedHurwitzZetaEven_zero, ← completedCosZeta_zero, completedHurwitzZetaEven_one_sub]
/-- The residue of `Λ(s)` at `s = 1` is equal to `1`. -/
lemma completedRiemannZeta_residue_one :
Tendsto (fun s ↦ (s - 1) * completedRiemannZeta s) (𝓝[≠] 1) (𝓝 1) :=
completedHurwitzZetaEven_residue_one 0
/-!
## The un-completed Riemann zeta function
-/
/-- The Riemann zeta function `ζ(s)`. -/
def riemannZeta := hurwitzZetaEven 0
lemma HurwitzZeta.hurwitzZetaEven_zero : hurwitzZetaEven 0 = riemannZeta := rfl
lemma HurwitzZeta.cosZeta_zero : cosZeta 0 = riemannZeta := by
simp_rw [cosZeta, riemannZeta, hurwitzZetaEven, if_true, completedHurwitzZetaEven_zero,
completedCosZeta_zero]
lemma HurwitzZeta.hurwitzZeta_zero : hurwitzZeta 0 = riemannZeta := by
ext1 s
simpa [hurwitzZeta, hurwitzZetaEven_zero] using hurwitzZetaOdd_neg 0 s
lemma HurwitzZeta.expZeta_zero : expZeta 0 = riemannZeta := by
ext1 s
rw [expZeta, cosZeta_zero, add_eq_left, mul_eq_zero, eq_false_intro I_ne_zero, false_or,
← eq_neg_self_iff, ← sinZeta_neg, neg_zero]
/-- The Riemann zeta function is differentiable away from `s = 1`. -/
theorem differentiableAt_riemannZeta {s : ℂ} (hs' : s ≠ 1) : DifferentiableAt ℂ riemannZeta s :=
differentiableAt_hurwitzZetaEven _ hs'
/-- We have `ζ(0) = -1 / 2`. -/
theorem riemannZeta_zero : riemannZeta 0 = -1 / 2 := by
simp_rw [riemannZeta, hurwitzZetaEven, Function.update_self, if_true]
lemma riemannZeta_def_of_ne_zero {s : ℂ} (hs : s ≠ 0) :
riemannZeta s = completedRiemannZeta s / Gammaℝ s := by
rw [riemannZeta, hurwitzZetaEven, Function.update_of_ne hs, completedHurwitzZetaEven_zero]
/-- The trivial zeroes of the zeta function. -/
theorem riemannZeta_neg_two_mul_nat_add_one (n : ℕ) : riemannZeta (-2 * (n + 1)) = 0 :=
hurwitzZetaEven_neg_two_mul_nat_add_one 0 n
/-- Riemann zeta functional equation, formulated for `ζ`: if `1 - s ∉ ℕ`, then we have
`ζ (1 - s) = 2 ^ (1 - s) * π ^ (-s) * Γ s * sin (π * (1 - s) / 2) * ζ s`. -/
theorem riemannZeta_one_sub {s : ℂ} (hs : ∀ n : ℕ, s ≠ -n) (hs' : s ≠ 1) :
riemannZeta (1 - s) = 2 * (2 * π) ^ (-s) * Gamma s * cos (π * s / 2) * riemannZeta s := by
rw [riemannZeta, hurwitzZetaEven_one_sub 0 hs (Or.inr hs'), cosZeta_zero, hurwitzZetaEven_zero]
/-- A formal statement of the **Riemann hypothesis** – constructing a term of this type is worth a
million dollars. -/
def RiemannHypothesis : Prop :=
∀ (s : ℂ) (_ : riemannZeta s = 0) (_ : ¬∃ n : ℕ, s = -2 * (n + 1)) (_ : s ≠ 1), s.re = 1 / 2
/-!
## Relating the Mellin transform to the Dirichlet series
-/
theorem completedZeta_eq_tsum_of_one_lt_re {s : ℂ} (hs : 1 < re s) :
completedRiemannZeta s =
(π : ℂ) ^ (-s / 2) * Gamma (s / 2) * ∑' n : ℕ, 1 / (n : ℂ) ^ s := by
have := (hasSum_nat_completedCosZeta 0 hs).tsum_eq.symm
simp only [QuotientAddGroup.mk_zero, completedCosZeta_zero] at this
simp only [this, Gammaℝ_def, mul_zero, zero_mul, Real.cos_zero, ofReal_one, mul_one, mul_one_div,
← tsum_mul_left]
congr 1 with n
split_ifs with h
· simp only [h, Nat.cast_zero, zero_cpow (Complex.ne_zero_of_one_lt_re hs), div_zero]
· rfl
/-- The Riemann zeta function agrees with the naive Dirichlet-series definition when the latter
converges. (Note that this is false without the assumption: when `re s ≤ 1` the sum is divergent,
and we use a different definition to obtain the analytic continuation to all `s`.) -/
theorem zeta_eq_tsum_one_div_nat_cpow {s : ℂ} (hs : 1 < re s) :
riemannZeta s = ∑' n : ℕ, 1 / (n : ℂ) ^ s := by
simpa only [QuotientAddGroup.mk_zero, cosZeta_zero, mul_zero, zero_mul, Real.cos_zero,
ofReal_one] using (hasSum_nat_cosZeta 0 hs).tsum_eq.symm
/-- Alternate formulation of `zeta_eq_tsum_one_div_nat_cpow` with a `+ 1` (to avoid relying
on mathlib's conventions for `0 ^ s`). -/
theorem zeta_eq_tsum_one_div_nat_add_one_cpow {s : ℂ} (hs : 1 < re s) :
riemannZeta s = ∑' n : ℕ, 1 / (n + 1 : ℂ) ^ s := by
have := zeta_eq_tsum_one_div_nat_cpow hs
rw [Summable.tsum_eq_zero_add] at this
· simpa [zero_cpow (Complex.ne_zero_of_one_lt_re hs)]
· rwa [Complex.summable_one_div_nat_cpow]
/-- Special case of `zeta_eq_tsum_one_div_nat_cpow` when the argument is in `ℕ`, so the power
function can be expressed using naïve `pow` rather than `cpow`. -/
theorem zeta_nat_eq_tsum_of_gt_one {k : ℕ} (hk : 1 < k) :
riemannZeta k = ∑' n : ℕ, 1 / (n : ℂ) ^ k := by
simp only [zeta_eq_tsum_one_div_nat_cpow
(by rwa [← ofReal_natCast, ofReal_re, ← Nat.cast_one, Nat.cast_lt] : 1 < re k),
cpow_natCast]
lemma two_mul_riemannZeta_eq_tsum_int_inv_pow_of_even {k : ℕ} (hk : 2 ≤ k) (hk2 : Even k) :
2 * riemannZeta k = ∑' (n : ℤ), ((n : ℂ) ^ k)⁻¹ := by
have hkk : 1 < k := by linarith
rw [tsum_int_eq_zero_add_two_mul_tsum_pnat]
· have h0 : (0 ^ k : ℂ)⁻¹ = 0 := by simp; omega
norm_cast
simp [h0, zeta_eq_tsum_one_div_nat_add_one_cpow (s := k) (by simp [hkk]),
tsum_pnat_eq_tsum_succ (f := fun n => ((n : ℂ) ^ k)⁻¹)]
· simp [Even.neg_pow hk2]
· exact (Summable.of_nat_of_neg (by simp [hkk]) (by simp [hkk])).of_norm
/-- The residue of `ζ(s)` at `s = 1` is equal to 1. -/
lemma riemannZeta_residue_one : Tendsto (fun s ↦ (s - 1) * riemannZeta s) (𝓝[≠] 1) (𝓝 1) := by
exact hurwitzZetaEven_residue_one 0
/-- The residue of `ζ(s)` at `s = 1` is equal to 1, expressed using `tsum`. -/
theorem tendsto_sub_mul_tsum_nat_cpow :
Tendsto (fun s : ℂ ↦ (s - 1) * ∑' (n : ℕ), 1 / (n : ℂ) ^ s) (𝓝[{s | 1 < re s}] 1) (𝓝 1) := by
refine (tendsto_nhdsWithin_mono_left ?_ riemannZeta_residue_one).congr' ?_
· simp only [subset_compl_singleton_iff, mem_setOf_eq, one_re, not_lt, le_refl]
· filter_upwards [eventually_mem_nhdsWithin] with s hs using
congr_arg _ <| zeta_eq_tsum_one_div_nat_cpow hs
/-- The residue of `ζ(s)` at `s = 1` is equal to 1 expressed using `tsum` and for a
real variable. -/
theorem tendsto_sub_mul_tsum_nat_rpow :
Tendsto (fun s : ℝ ↦ (s - 1) * ∑' (n : ℕ), 1 / (n : ℝ) ^ s) (𝓝[>] 1) (𝓝 1) := by
rw [← tendsto_ofReal_iff, ofReal_one]
have : Tendsto (fun s : ℝ ↦ (s : ℂ)) (𝓝[>] 1) (𝓝[{s | 1 < re s}] 1) :=
continuous_ofReal.continuousWithinAt.tendsto_nhdsWithin (fun _ _ ↦ by simp_all)
apply (tendsto_sub_mul_tsum_nat_cpow.comp this).congr fun s ↦ ?_
simp only [one_div, Function.comp_apply, ofReal_mul, ofReal_sub, ofReal_one, ofReal_tsum,
ofReal_inv, ofReal_cpow (Nat.cast_nonneg _), ofReal_natCast] |
.lake/packages/mathlib/Mathlib/NumberTheory/LSeries/DirichletContinuation.lean | import Mathlib.NumberTheory.LSeries.ZMod
import Mathlib.NumberTheory.DirichletCharacter.Basic
import Mathlib.NumberTheory.EulerProduct.DirichletLSeries
/-!
# Analytic continuation of Dirichlet L-functions
We show that if `χ` is a Dirichlet character `ZMod N → ℂ`, for a positive integer `N`, then the
L-series of `χ` has analytic continuation (away from a pole at `s = 1` if `χ` is trivial), and
similarly for completed L-functions.
All definitions and theorems are in the `DirichletCharacter` namespace.
## Main definitions
* `LFunction χ s`: the L-function, defined as a linear combination of Hurwitz zeta functions.
* `completedLFunction χ s`: the completed L-function, which for *almost* all `s` is equal to
`LFunction χ s * gammaFactor χ s` where `gammaFactor χ s` is the archimedean Gamma-factor.
* `rootNumber`: the global root number of the L-series of `χ` (for `χ` primitive; junk otherwise).
## Main theorems
* `LFunction_eq_LSeries`: if `1 < re s` then the `LFunction` coincides with the naive `LSeries`.
* `differentiable_LFunction`: if `χ` is nontrivial then `LFunction χ s` is differentiable
everywhere.
* `LFunction_eq_completed_div_gammaFactor`: we have
`LFunction χ s = completedLFunction χ s / gammaFactor χ s`, unless `s = 0` and `χ` is the trivial
character modulo 1.
* `differentiable_completedLFunction`: if `χ` is nontrivial then `completedLFunction χ s` is
differentiable everywhere.
* `IsPrimitive.completedLFunction_one_sub`: the **functional equation** for Dirichlet L-functions,
showing that if `χ` is primitive modulo `N`, then
`completedLFunction χ s = N ^ (s - 1 / 2) * rootNumber χ * completedLFunction χ⁻¹ s`.
-/
open HurwitzZeta Complex Finset ZMod Filter
open scoped Real Topology
namespace DirichletCharacter
variable {N : ℕ} [NeZero N]
/--
The unique meromorphic function `ℂ → ℂ` which agrees with `∑' n : ℕ, χ n / n ^ s` wherever the
latter is convergent. This is constructed as a linear combination of Hurwitz zeta functions.
Note that this is not the same as `LSeries χ`: they agree in the convergence range, but
`LSeries χ s` is defined to be `0` if `re s ≤ 1`.
-/
@[pp_nodot]
noncomputable def LFunction (χ : DirichletCharacter ℂ N) (s : ℂ) : ℂ := ZMod.LFunction χ s
/--
The L-function of the (unique) Dirichlet character mod 1 is the Riemann zeta function.
(Compare `DirichletCharacter.LSeries_modOne_eq`.)
-/
@[simp] lemma LFunction_modOne_eq {χ : DirichletCharacter ℂ 1} :
LFunction χ = riemannZeta := by
ext; rw [LFunction, ZMod.LFunction_modOne_eq, (by rfl : (0 : ZMod 1) = 1), map_one, one_mul]
/--
For `1 < re s` the L-function of a Dirichlet character agrees with the sum of the naive Dirichlet
series.
-/
lemma LFunction_eq_LSeries (χ : DirichletCharacter ℂ N) {s : ℂ} (hs : 1 < re s) :
LFunction χ s = LSeries (χ ·) s :=
ZMod.LFunction_eq_LSeries χ hs
lemma deriv_LFunction_eq_deriv_LSeries (χ : DirichletCharacter ℂ N) {s : ℂ} (hs : 1 < s.re) :
deriv (LFunction χ) s = deriv (LSeries (χ ·)) s := by
refine Filter.EventuallyEq.deriv_eq ?_
have h : {z | 1 < z.re} ∈ nhds s :=
(isOpen_lt continuous_const continuous_re).mem_nhds hs
filter_upwards [h] with z hz
exact LFunction_eq_LSeries χ hz
/--
The L-function of a Dirichlet character is differentiable, except at `s = 1` if the character is
trivial.
-/
@[fun_prop]
lemma differentiableAt_LFunction (χ : DirichletCharacter ℂ N) (s : ℂ) (hs : s ≠ 1 ∨ χ ≠ 1) :
DifferentiableAt ℂ (LFunction χ) s :=
ZMod.differentiableAt_LFunction χ s (hs.imp_right χ.sum_eq_zero_of_ne_one)
/-- The L-function of a non-trivial Dirichlet character is differentiable everywhere. -/
@[fun_prop]
lemma differentiable_LFunction {χ : DirichletCharacter ℂ N} (hχ : χ ≠ 1) :
Differentiable ℂ (LFunction χ) :=
(differentiableAt_LFunction _ · <| Or.inr hχ)
/-- The L-function of an even Dirichlet character vanishes at strictly negative even integers. -/
@[simp]
lemma Even.LFunction_neg_two_mul_nat_add_one {χ : DirichletCharacter ℂ N} (hχ : Even χ) (n : ℕ) :
LFunction χ (-(2 * (n + 1))) = 0 :=
ZMod.LFunction_neg_two_mul_nat_add_one hχ.to_fun n
/-- The L-function of an even Dirichlet character vanishes at strictly negative even integers. -/
@[simp]
lemma Even.LFunction_neg_two_mul_nat {χ : DirichletCharacter ℂ N} (hχ : Even χ) (n : ℕ) [NeZero n] :
LFunction χ (-(2 * n)) = 0 := by
obtain ⟨m, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (NeZero.ne n)
exact_mod_cast hχ.LFunction_neg_two_mul_nat_add_one m
/-- The L-function of an odd Dirichlet character vanishes at negative odd integers. -/
@[simp] lemma Odd.LFunction_neg_two_mul_nat_sub_one
{χ : DirichletCharacter ℂ N} (hχ : Odd χ) (n : ℕ) :
LFunction χ (-(2 * n) - 1) = 0 :=
ZMod.LFunction_neg_two_mul_nat_sub_one hχ.to_fun n
/-!
### Results on changing levels
-/
private lemma LFunction_changeLevel_aux {M N : ℕ} [NeZero M] [NeZero N] (hMN : M ∣ N)
(χ : DirichletCharacter ℂ M) {s : ℂ} (hs : s ≠ 1) :
LFunction (changeLevel hMN χ) s =
LFunction χ s * ∏ p ∈ N.primeFactors, (1 - χ p * p ^ (-s)) := by
have hpc : IsPreconnected ({1}ᶜ : Set ℂ) :=
(isConnected_compl_singleton_of_one_lt_rank (rank_real_complex ▸ Nat.one_lt_ofNat) _)
|>.isPreconnected
have hne : 2 ∈ ({1}ᶜ : Set ℂ) := by simp
refine AnalyticOnNhd.eqOn_of_preconnected_of_eventuallyEq (𝕜 := ℂ)
(g := fun s ↦ LFunction χ s * ∏ p ∈ N.primeFactors, (1 - χ p * p ^ (-s))) ?_ ?_ hpc hne ?_ hs
· refine DifferentiableOn.analyticOnNhd (fun s hs ↦ ?_) isOpen_compl_singleton
exact (differentiableAt_LFunction _ _ (.inl hs)).differentiableWithinAt
· refine DifferentiableOn.analyticOnNhd (fun s hs ↦ ?_) isOpen_compl_singleton
refine ((differentiableAt_LFunction _ _ (.inl hs)).mul ?_).differentiableWithinAt
refine .fun_finset_prod fun i h ↦ ?_
have : NeZero i := ⟨(Nat.pos_of_mem_primeFactors h).ne'⟩
fun_prop
· refine eventually_of_mem ?_ (fun t (ht : 1 < t.re) ↦ ?_)
· exact (continuous_re.isOpen_preimage _ isOpen_Ioi).mem_nhds (by simp : 1 < (2 : ℂ).re)
· simpa [LFunction_eq_LSeries _ ht] using LSeries_changeLevel hMN χ ht
/-- If `χ` is a Dirichlet character and its level `M` divides `N`, then we obtain the L function
of `χ` considered as a Dirichlet character of level `N` from the L function of `χ` by multiplying
with `∏ p ∈ N.primeFactors, (1 - χ p * p ^ (-s))`.
(Note that `1 - χ p * p ^ (-s) = 1` when `p` divides `M`). -/
lemma LFunction_changeLevel {M N : ℕ} [NeZero M] [NeZero N] (hMN : M ∣ N)
(χ : DirichletCharacter ℂ M) {s : ℂ} (h : χ ≠ 1 ∨ s ≠ 1) :
LFunction (changeLevel hMN χ) s =
LFunction χ s * ∏ p ∈ N.primeFactors, (1 - χ p * p ^ (-s)) := by
rcases h with h | h
· have hχ : changeLevel hMN χ ≠ 1 := h ∘ (changeLevel_eq_one_iff hMN).mp
have h' : Continuous fun s ↦ LFunction χ s * ∏ p ∈ N.primeFactors, (1 - χ p * ↑p ^ (-s)) :=
(differentiable_LFunction h).continuous.mul <| continuous_finset_prod _ fun p hp ↦ by
have : NeZero p := ⟨(Nat.prime_of_mem_primeFactors hp).ne_zero⟩
fun_prop
exact congrFun ((differentiable_LFunction hχ).continuous.ext_on
(dense_compl_singleton 1) h' (fun _ h ↦ LFunction_changeLevel_aux hMN χ h)) s
· exact LFunction_changeLevel_aux hMN χ h
/-!
### The `L`-function of the trivial character mod `N`
-/
/-- The `L`-function of the trivial character mod `N`. -/
noncomputable abbrev LFunctionTrivChar (N : ℕ) [NeZero N] :=
(1 : DirichletCharacter ℂ N).LFunction
/-- The L function of the trivial Dirichlet character mod `N` is obtained from the Riemann
zeta function by multiplying with `∏ p ∈ N.primeFactors, (1 - (p : ℂ) ^ (-s))`. -/
lemma LFunctionTrivChar_eq_mul_riemannZeta {s : ℂ} (hs : s ≠ 1) :
LFunctionTrivChar N s = (∏ p ∈ N.primeFactors, (1 - (p : ℂ) ^ (-s))) * riemannZeta s := by
rw [← LFunction_modOne_eq (χ := 1), LFunctionTrivChar, ← changeLevel_one N.one_dvd, mul_comm]
convert LFunction_changeLevel N.one_dvd 1 (.inr hs) using 4 with p
rw [MulChar.one_apply <| isUnit_of_subsingleton _, one_mul]
/-- The L function of the trivial Dirichlet character mod `N` has a simple pole with
residue `∏ p ∈ N.primeFactors, (1 - p⁻¹)` at `s = 1`. -/
lemma LFunctionTrivChar_residue_one :
Tendsto (fun s ↦ (s - 1) * LFunctionTrivChar N s) (𝓝[≠] 1)
(𝓝 <| ∏ p ∈ N.primeFactors, (1 - (p : ℂ)⁻¹)) := by
have H : (fun s ↦ (s - 1) * LFunctionTrivChar N s) =ᶠ[𝓝[≠] 1]
fun s ↦ (∏ p ∈ N.primeFactors, (1 - (p : ℂ) ^ (-s))) * ((s - 1) * riemannZeta s) := by
refine Set.EqOn.eventuallyEq_nhdsWithin fun s hs ↦ ?_
rw [mul_left_comm, LFunctionTrivChar_eq_mul_riemannZeta hs]
rw [tendsto_congr' H]
conv => enter [3, 1]; rw [← mul_one <| Finset.prod ..]; enter [1, 2, p]; rw [← cpow_neg_one]
refine .mul (f := fun s ↦ ∏ p ∈ N.primeFactors, _) ?_ riemannZeta_residue_one
refine tendsto_nhdsWithin_of_tendsto_nhds <| Continuous.tendsto ?_ 1
exact continuous_finset_prod _ fun p hp ↦ by
have : NeZero p := ⟨(Nat.prime_of_mem_primeFactors hp).ne_zero⟩
fun_prop
/-!
### Completed L-functions and the functional equation
-/
section gammaFactor
omit [NeZero N] -- not required for these declarations
open scoped Classical in
/-- The Archimedean Gamma factor: `Gammaℝ s` if `χ` is even, and `Gammaℝ (s + 1)` otherwise. -/
noncomputable def gammaFactor (χ : DirichletCharacter ℂ N) (s : ℂ) :=
if χ.Even then Gammaℝ s else Gammaℝ (s + 1)
lemma Even.gammaFactor_def {χ : DirichletCharacter ℂ N} (hχ : χ.Even) (s : ℂ) :
gammaFactor χ s = Gammaℝ s := by
simp [gammaFactor, hχ]
lemma Odd.gammaFactor_def {χ : DirichletCharacter ℂ N} (hχ : χ.Odd) (s : ℂ) :
gammaFactor χ s = Gammaℝ (s + 1) := by
simp [gammaFactor, hχ.not_even]
end gammaFactor
/--
The completed L-function of a Dirichlet character, almost everywhere equal to
`LFunction χ s * gammaFactor χ s`.
-/
@[pp_nodot] noncomputable def completedLFunction (χ : DirichletCharacter ℂ N) (s : ℂ) : ℂ :=
ZMod.completedLFunction χ s
/--
The completed L-function of the (unique) Dirichlet character mod 1 is the completed Riemann zeta
function.
-/
lemma completedLFunction_modOne_eq {χ : DirichletCharacter ℂ 1} :
completedLFunction χ = completedRiemannZeta := by
ext; rw [completedLFunction, ZMod.completedLFunction_modOne_eq, map_one, one_mul]
/--
The completed L-function of a Dirichlet character is differentiable, with the following
exceptions: at `s = 1` if `χ` is the trivial character (to any modulus); and at `s = 0` if the
modulus is 1. This result is best possible.
Note both `χ` and `s` are explicit arguments: we will always be able to infer one or other
of them from the hypotheses, but it's not clear which!
-/
lemma differentiableAt_completedLFunction (χ : DirichletCharacter ℂ N) (s : ℂ)
(hs₀ : s ≠ 0 ∨ N ≠ 1) (hs₁ : s ≠ 1 ∨ χ ≠ 1) :
DifferentiableAt ℂ (completedLFunction χ) s :=
ZMod.differentiableAt_completedLFunction _ _ (by have := χ.map_zero'; tauto)
(by have := χ.sum_eq_zero_of_ne_one; tauto)
/-- The completed L-function of a non-trivial Dirichlet character is differentiable everywhere. -/
lemma differentiable_completedLFunction {χ : DirichletCharacter ℂ N} (hχ : χ ≠ 1) :
Differentiable ℂ (completedLFunction χ) := by
refine fun s ↦ differentiableAt_completedLFunction _ _ (Or.inr ?_) (Or.inr hχ)
exact hχ ∘ level_one' _
/--
Relation between the completed L-function and the usual one. We state it this way around so
it holds at the poles of the gamma factor as well.
-/
lemma LFunction_eq_completed_div_gammaFactor (χ : DirichletCharacter ℂ N) (s : ℂ)
(h : s ≠ 0 ∨ N ≠ 1) : LFunction χ s = completedLFunction χ s / gammaFactor χ s := by
rcases χ.even_or_odd with hχ | hχ <;>
rw [hχ.gammaFactor_def]
· exact LFunction_eq_completed_div_gammaFactor_even hχ.to_fun _ (h.imp_right χ.map_zero')
· apply LFunction_eq_completed_div_gammaFactor_odd hχ.to_fun
open scoped Classical in
/--
Global root number of `χ` (for `χ` primitive; junk otherwise). Defined as
`gaussSum χ stdAddChar / I ^ a / N ^ (1 / 2)`, where `a = 0` if even, `a = 1` if odd. (The factor
`1 / I ^ a` is the Archimedean root number.) This is a complex number of absolute value 1.
-/
noncomputable def rootNumber (χ : DirichletCharacter ℂ N) : ℂ :=
gaussSum χ stdAddChar / I ^ (if χ.Even then 0 else 1) / N ^ (1 / 2 : ℂ)
/-- The root number of the unique Dirichlet character modulo 1 is 1. -/
lemma rootNumber_modOne (χ : DirichletCharacter ℂ 1) : rootNumber χ = 1 := by
simp [rootNumber, gaussSum, -univ_unique, ← singleton_eq_univ (1 : ZMod 1),
(show stdAddChar (1 : ZMod 1) = 1 from AddChar.map_zero_eq_one _),
(show χ.Even from map_one _)]
namespace IsPrimitive
/-- **Functional equation** for primitive Dirichlet L-functions. -/
theorem completedLFunction_one_sub {χ : DirichletCharacter ℂ N} (hχ : IsPrimitive χ) (s : ℂ) :
completedLFunction χ (1 - s) = N ^ (s - 1 / 2) * rootNumber χ * completedLFunction χ⁻¹ s := by
classical
-- First handle special case of Riemann zeta
rcases eq_or_ne N 1 with rfl | hN
· simp [completedLFunction_modOne_eq, completedRiemannZeta_one_sub, rootNumber_modOne]
-- facts about `χ` as function
have h_sum : ∑ j, χ j = 0 := by
refine χ.sum_eq_zero_of_ne_one (fun h ↦ hN.symm ?_)
rwa [IsPrimitive, h, conductor_one (NeZero.ne _)] at hχ
let ε := I ^ (if χ.Even then 0 else 1)
-- gather up powers of N
rw [rootNumber, ← mul_comm_div, ← mul_comm_div, ← cpow_sub _ _ (NeZero.ne _), sub_sub, add_halves]
calc completedLFunction χ (1 - s)
_ = N ^ (s - 1) * χ (-1) / ε * ZMod.completedLFunction (𝓕 χ) s := by
simp only [ε]
split_ifs with h
· rw [pow_zero, div_one, h, mul_one, completedLFunction,
completedLFunction_one_sub_even h.to_fun _ (.inr h_sum) (.inr <| χ.map_zero' hN)]
· replace h : χ.Odd := χ.even_or_odd.resolve_left h
rw [completedLFunction, completedLFunction_one_sub_odd h.to_fun,
pow_one, h, div_I, mul_neg_one, ← neg_mul, neg_neg]
_ = (_) * ZMod.completedLFunction (fun j ↦ χ⁻¹ (-1) * gaussSum χ stdAddChar * χ⁻¹ j) s := by
congr 2 with j
rw [hχ.fourierTransform_eq_inv_mul_gaussSum, ← neg_one_mul j, map_mul, mul_right_comm]
_ = N ^ (s - 1) / ε * gaussSum χ stdAddChar * completedLFunction χ⁻¹ s * (χ (-1) * χ⁻¹ (-1)) := by
rw [completedLFunction, completedLFunction_const_mul]
ring
_ = N ^ (s - 1) / ε * gaussSum χ stdAddChar * completedLFunction χ⁻¹ s := by
rw [← MulChar.mul_apply, mul_inv_cancel, MulChar.one_apply (isUnit_one.neg), mul_one]
end IsPrimitive
end DirichletCharacter
/-!
### The logarithmic derivative of the L-function of a Dirichlet character
We show that `s ↦ -(L' χ s) / L χ s + 1 / (s - 1)` is continuous outside the zeros of `L χ`
when `χ` is a trivial Dirichlet character and that `-L' χ / L χ` is continuous outside
the zeros of `L χ` when `χ` is nontrivial.
-/
namespace DirichletCharacter
open Complex
section trivial
variable (n : ℕ) [NeZero n]
/-- The function obtained by "multiplying away" the pole of `L χ` for a trivial Dirichlet
character `χ`. Its (negative) logarithmic derivative is used to prove Dirichlet's Theorem
on primes in arithmetic progression. -/
noncomputable abbrev LFunctionTrivChar₁ : ℂ → ℂ :=
Function.update (fun s ↦ (s - 1) * LFunctionTrivChar n s) 1
(∏ p ∈ n.primeFactors, (1 - (p : ℂ)⁻¹))
lemma LFunctionTrivChar₁_apply_one_ne_zero : LFunctionTrivChar₁ n 1 ≠ 0 := by
simp only [Function.update_self]
refine Finset.prod_ne_zero_iff.mpr fun p hp ↦ ?_
simpa [sub_ne_zero] using (Nat.prime_of_mem_primeFactors hp).ne_one
/-- `s ↦ (s - 1) * L χ s` is an entire function when `χ` is a trivial Dirichlet character. -/
lemma differentiable_LFunctionTrivChar₁ : Differentiable ℂ (LFunctionTrivChar₁ n) := by
rw [← differentiableOn_univ,
← differentiableOn_compl_singleton_and_continuousAt_iff (c := 1) Filter.univ_mem]
refine ⟨DifferentiableOn.congr (f := fun s ↦ (s - 1) * LFunctionTrivChar n s)
(fun _ hs ↦ DifferentiableAt.differentiableWithinAt <| by fun_prop (disch := simp_all))
fun _ hs ↦ Function.update_of_ne (Set.mem_diff_singleton.mp hs).2 ..,
continuousWithinAt_compl_self.mp ?_⟩
simpa using LFunctionTrivChar_residue_one
lemma deriv_LFunctionTrivChar₁_apply_of_ne_one {s : ℂ} (hs : s ≠ 1) :
deriv (LFunctionTrivChar₁ n) s =
(s - 1) * deriv (LFunctionTrivChar n) s + LFunctionTrivChar n s := by
have H : deriv (LFunctionTrivChar₁ n) s =
deriv (fun w ↦ (w - 1) * LFunctionTrivChar n w) s := by
refine eventuallyEq_iff_exists_mem.mpr ?_ |>.deriv_eq
exact ⟨_, isOpen_ne.mem_nhds hs, fun _ hw ↦ Function.update_of_ne (Set.mem_setOf.mp hw) ..⟩
rw [H, deriv_fun_mul (by fun_prop) (differentiableAt_LFunction _ s (.inl hs)), deriv_sub_const,
deriv_id'', one_mul, add_comm]
/-- The negative logarithmic derivative of `s ↦ (s - 1) * L χ s` for a trivial
Dirichlet character `χ` is continuous away from the zeros of `L χ` (including at `s = 1`). -/
lemma continuousOn_neg_logDeriv_LFunctionTrivChar₁ :
ContinuousOn (fun s ↦ -deriv (LFunctionTrivChar₁ n) s / LFunctionTrivChar₁ n s)
{s | s = 1 ∨ LFunctionTrivChar n s ≠ 0} := by
simp_rw [neg_div]
have h := differentiable_LFunctionTrivChar₁ n
refine ((h.contDiff.continuous_deriv le_rfl).continuousOn.div
h.continuous.continuousOn fun w hw ↦ ?_).neg
rcases eq_or_ne w 1 with rfl | hw'
· exact LFunctionTrivChar₁_apply_one_ne_zero _
· rw [LFunctionTrivChar₁, Function.update_of_ne hw', mul_ne_zero_iff]
exact ⟨sub_ne_zero_of_ne hw', (Set.mem_setOf.mp hw).resolve_left hw'⟩
end trivial
section nontrivial
variable {n : ℕ} [NeZero n] {χ : DirichletCharacter ℂ n}
/-- The negative logarithmic derivative of the L-function of a nontrivial Dirichlet character
is continuous away from the zeros of the L-function. -/
lemma continuousOn_neg_logDeriv_LFunction_of_nontriv (hχ : χ ≠ 1) :
ContinuousOn (fun s ↦ -deriv (LFunction χ) s / LFunction χ s) {s | LFunction χ s ≠ 0} := by
have h := differentiable_LFunction hχ
simpa [neg_div] using ((h.contDiff.continuous_deriv le_rfl).continuousOn.div
h.continuous.continuousOn fun _ hw ↦ hw).neg
end nontrivial
end DirichletCharacter |
.lake/packages/mathlib/Mathlib/NumberTheory/LSeries/AbstractFuncEq.lean | import Mathlib.Analysis.MellinTransform
/-!
# Abstract functional equations for Mellin transforms
This file formalises a general version of an argument used to prove functional equations for
zeta and L functions.
### FE-pairs
We define a *weak FE-pair* to be a pair of functions `f, g` on the reals which are locally
integrable on `(0, ∞)`, have the form "constant" + "rapidly decaying term" at `∞`, and satisfy a
functional equation of the form
`f (1 / x) = ε * x ^ k * g x`
for some constants `k ∈ ℝ` and `ε ∈ ℂ`. (Modular forms give rise to natural examples
with `k` being the weight and `ε` the global root number; hence the notation.) We could arrange
`ε = 1` by scaling `g`; but this is inconvenient in applications so we set things up more generally.
A *strong FE-pair* is a weak FE-pair where the constant terms of `f` and `g` at `∞` are both 0.
The main property of these pairs is the following: if `f`, `g` are a weak FE-pair, with constant
terms `f₀` and `g₀` at `∞`, then the Mellin transforms `Λ` and `Λ'` of `f - f₀` and `g - g₀`
respectively both have meromorphic continuation and satisfy a functional equation of the form
`Λ (k - s) = ε * Λ' s`.
The poles (and their residues) are explicitly given in terms of `f₀` and `g₀`; in particular, if
`(f, g)` are a strong FE-pair, then the Mellin transforms of `f` and `g` are entire functions.
### Main definitions and results
See the sections *Main theorems on weak FE-pairs* and
*Main theorems on strong FE-pairs* below.
* Strong FE pairs:
- `StrongFEPair.Λ` : function of `s : ℂ`
- `StrongFEPair.differentiable_Λ`: `Λ` is entire
- `StrongFEPair.hasMellin`: `Λ` is everywhere equal to the Mellin transform of `f`
- `StrongFEPair.functional_equation`: the functional equation for `Λ`
* Weak FE pairs:
- `WeakFEPair.Λ₀`: and `WeakFEPair.Λ`: functions of `s : ℂ`
- `WeakFEPair.differentiable_Λ₀`: `Λ₀` is entire
- `WeakFEPair.differentiableAt_Λ`: `Λ` is differentiable away from `s = 0` and `s = k`
- `WeakFEPair.hasMellin`: for `k < re s`, `Λ s` equals the Mellin transform of `f - f₀`
- `WeakFEPair.functional_equation₀`: the functional equation for `Λ₀`
- `WeakFEPair.functional_equation`: the functional equation for `Λ`
- `WeakFEPair.Λ_residue_k`: computation of the residue at `k`
- `WeakFEPair.Λ_residue_zero`: computation of the residue at `0`.
-/
/- TODO : Consider extending the results to allow functional equations of the form
`f (N / x) = (const) • x ^ k • g x` for a real parameter `0 < N`. This could be done either by
generalising the existing proofs in situ, or by a separate wrapper `FEPairWithLevel` which just
applies a scaling factor to `f` and `g` to reduce to the `N = 1` case.
-/
noncomputable section
open Real Complex Filter Topology Asymptotics Set MeasureTheory
variable (E : Type*) [NormedAddCommGroup E] [NormedSpace ℂ E]
/-!
## Definitions and symmetry
-/
/-- A structure designed to hold the hypotheses for the Mellin-functional-equation argument
(most general version: rapid decay at `∞` up to constant terms) -/
structure WeakFEPair where
/-- The functions whose Mellin transform we study -/
(f g : ℝ → E)
/-- Weight (exponent in the functional equation) -/
(k : ℝ)
/-- Root number -/
(ε : ℂ)
/-- Constant terms at `∞` -/
(f₀ g₀ : E)
(hf_int : LocallyIntegrableOn f (Ioi 0))
(hg_int : LocallyIntegrableOn g (Ioi 0))
(hk : 0 < k)
(hε : ε ≠ 0)
(h_feq : ∀ x ∈ Ioi 0, f (1 / x) = (ε * ↑(x ^ k)) • g x)
(hf_top (r : ℝ) : (f · - f₀) =O[atTop] (· ^ r))
(hg_top (r : ℝ) : (g · - g₀) =O[atTop] (· ^ r))
/-- A structure designed to hold the hypotheses for the Mellin-functional-equation argument
(version without constant terms) -/
structure StrongFEPair extends WeakFEPair E where (hf₀ : f₀ = 0) (hg₀ : g₀ = 0)
variable {E}
section symmetry
/-- Reformulated functional equation with `f` and `g` interchanged. -/
lemma WeakFEPair.h_feq' (P : WeakFEPair E) (x : ℝ) (hx : 0 < x) :
P.g (1 / x) = (P.ε⁻¹ * ↑(x ^ P.k)) • P.f x := by
rw [(div_div_cancel₀ (one_ne_zero' ℝ) ▸ P.h_feq (1 / x) (one_div_pos.mpr hx) :), ← mul_smul]
convert (one_smul ℂ (P.g (1 / x))).symm using 2
rw [one_div, inv_rpow hx.le, ofReal_inv]
field [P.hε, (rpow_pos_of_pos hx _).ne']
/-- The hypotheses are symmetric in `f` and `g`, with the constant `ε` replaced by `ε⁻¹`. -/
def WeakFEPair.symm (P : WeakFEPair E) : WeakFEPair E where
f := P.g
g := P.f
k := P.k
ε := P.ε⁻¹
f₀ := P.g₀
g₀ := P.f₀
hf_int := P.hg_int
hg_int := P.hf_int
hf_top := P.hg_top
hg_top := P.hf_top
hε := inv_ne_zero P.hε
hk := P.hk
h_feq := P.h_feq'
/-- The hypotheses are symmetric in `f` and `g`, with the constant `ε` replaced by `ε⁻¹`. -/
def StrongFEPair.symm (P : StrongFEPair E) : StrongFEPair E where
toWeakFEPair := P.toWeakFEPair.symm
hf₀ := P.hg₀
hg₀ := P.hf₀
end symmetry
namespace WeakFEPair
/-!
## Auxiliary results I: lemmas on asymptotics
-/
/-- As `x → 0`, we have `f x = x ^ (-P.k) • constant` up to a rapidly decaying error. -/
lemma hf_zero (P : WeakFEPair E) (r : ℝ) :
(fun x ↦ P.f x - (P.ε * ↑(x ^ (-P.k))) • P.g₀) =O[𝓝[>] 0] (· ^ r) := by
have := (P.hg_top (-(r + P.k))).comp_tendsto tendsto_inv_nhdsGT_zero
simp_rw [IsBigO, IsBigOWith, eventually_nhdsWithin_iff] at this ⊢
obtain ⟨C, hC⟩ := this
use ‖P.ε‖ * C
filter_upwards [hC] with x hC' (hx : 0 < x)
have h_nv2 : ↑(x ^ P.k) ≠ (0 : ℂ) := ofReal_ne_zero.mpr (rpow_pos_of_pos hx _).ne'
have h_nv : P.ε⁻¹ * ↑(x ^ P.k) ≠ 0 := mul_ne_zero P.symm.hε h_nv2
specialize hC' hx
simp_rw [Function.comp_apply, ← one_div, P.h_feq' _ hx] at hC'
rw [← ((mul_inv_cancel₀ h_nv).symm ▸ one_smul ℂ P.g₀ :), mul_smul _ _ P.g₀, ← smul_sub, norm_smul,
← le_div_iff₀' (lt_of_le_of_ne (norm_nonneg _) (norm_ne_zero_iff.mpr h_nv).symm)] at hC'
convert hC' using 1
· congr 3
rw [rpow_neg hx.le]
simp [field]
· simp_rw [norm_mul, norm_real, one_div, inv_rpow hx.le, rpow_neg hx.le, inv_inv, norm_inv,
norm_of_nonneg (rpow_pos_of_pos hx _).le, rpow_add hx]
field
/-- Power asymptotic for `f - f₀` as `x → 0`. -/
lemma hf_zero' (P : WeakFEPair E) :
(fun x : ℝ ↦ P.f x - P.f₀) =O[𝓝[>] 0] (· ^ (-P.k)) := by
simp_rw [← fun x ↦ sub_add_sub_cancel (P.f x) ((P.ε * ↑(x ^ (-P.k))) • P.g₀) P.f₀]
refine (P.hf_zero _).add (IsBigO.sub ?_ ?_)
· rw [← isBigO_norm_norm]
simp_rw [mul_smul, norm_smul, mul_comm _ ‖P.g₀‖, ← mul_assoc, norm_real]
apply (isBigO_refl _ _).const_mul_left
· refine IsBigO.of_bound ‖P.f₀‖ (eventually_nhdsWithin_iff.mpr ?_)
filter_upwards [eventually_le_nhds zero_lt_one] with x hx' (hx : 0 < x)
apply le_mul_of_one_le_right (norm_nonneg _)
rw [norm_of_nonneg (rpow_pos_of_pos hx _).le, rpow_neg hx.le]
exact (one_le_inv₀ (rpow_pos_of_pos hx _)).2 (rpow_le_one hx.le hx' P.hk.le)
end WeakFEPair
namespace StrongFEPair
variable (P : StrongFEPair E)
/-- As `x → ∞`, `f x` decays faster than any power of `x`. -/
lemma hf_top' (r : ℝ) : P.f =O[atTop] (· ^ r) := by
simpa [P.hf₀] using P.hf_top r
/-- As `x → 0`, `f x` decays faster than any power of `x`. -/
lemma hf_zero' (r : ℝ) : P.f =O[𝓝[>] 0] (· ^ r) := by
simpa using (P.hg₀ ▸ P.hf_zero r :)
/-!
## Main theorems on strong FE-pairs
-/
/-- The completed L-function. -/
def Λ : ℂ → E := mellin P.f
/-- The Mellin transform of `f` is well-defined and equal to `P.Λ s`, for all `s`. -/
theorem hasMellin (s : ℂ) : HasMellin P.f s (P.Λ s) :=
let ⟨_, ht⟩ := exists_gt s.re
let ⟨_, hu⟩ := exists_lt s.re
⟨mellinConvergent_of_isBigO_rpow P.hf_int (P.hf_top' _) ht (P.hf_zero' _) hu, rfl⟩
lemma Λ_eq : P.Λ = mellin P.f := rfl
lemma symm_Λ_eq : P.symm.Λ = mellin P.g := rfl
/-- If `(f, g)` are a strong FE pair, then the Mellin transform of `f` is entire. -/
theorem differentiable_Λ : Differentiable ℂ P.Λ := fun s ↦
let ⟨_, ht⟩ := exists_gt s.re
let ⟨_, hu⟩ := exists_lt s.re
mellin_differentiableAt_of_isBigO_rpow P.hf_int (P.hf_top' _) ht (P.hf_zero' _) hu
/-- Main theorem about strong FE pairs: if `(f, g)` are a strong FE pair, then the Mellin
transforms of `f` and `g` are related by `s ↦ k - s`.
This is proved by making a substitution `t ↦ t⁻¹` in the Mellin transform integral. -/
theorem functional_equation (s : ℂ) :
P.Λ (P.k - s) = P.ε • P.symm.Λ s := by
-- unfold definition:
rw [P.Λ_eq, P.symm_Λ_eq]
-- substitute `t ↦ t⁻¹` in `mellin P.g s`
have step1 := mellin_comp_rpow P.g (-s) (-1)
simp_rw [abs_neg, abs_one, inv_one, one_smul, ofReal_neg, ofReal_one, div_neg, div_one, neg_neg,
rpow_neg_one, ← one_div] at step1
-- introduce a power of `t` to match the hypothesis `P.h_feq`
have step2 := mellin_cpow_smul (fun t ↦ P.g (1 / t)) (P.k - s) (-P.k)
rw [← sub_eq_add_neg, sub_right_comm, sub_self, zero_sub, step1] at step2
-- put in the constant `P.ε`
have step3 := mellin_const_smul (fun t ↦ (t : ℂ) ^ (-P.k : ℂ) • P.g (1 / t)) (P.k - s) P.ε
rw [step2] at step3
rw [← step3]
-- now the integrand matches `P.h_feq'` on `Ioi 0`, so we can apply `setIntegral_congr_fun`
refine setIntegral_congr_fun measurableSet_Ioi (fun t ht ↦ ?_)
simp_rw [P.h_feq' t ht, ← mul_smul]
-- some simple `cpow` arithmetic to finish
rw [cpow_neg, ofReal_cpow (le_of_lt ht)]
have : (t : ℂ) ^ (P.k : ℂ) ≠ 0 := by simpa [← ofReal_cpow ht.le] using (rpow_pos_of_pos ht _).ne'
field_simp [P.hε]
end StrongFEPair
namespace WeakFEPair
variable (P : WeakFEPair E)
/-!
## Auxiliary results II: building a strong FE-pair from a weak FE-pair
-/
/-- Piecewise modified version of `f` with optimal asymptotics. We deliberately choose intervals
which don't quite join up, so the function is `0` at `x = 1`, in order to maintain symmetry;
there is no "good" choice of value at `1`. -/
def f_modif : ℝ → E :=
(Ioi 1).indicator (fun x ↦ P.f x - P.f₀) +
(Ioo 0 1).indicator (fun x ↦ P.f x - (P.ε * ↑(x ^ (-P.k))) • P.g₀)
/-- Piecewise modified version of `g` with optimal asymptotics. -/
def g_modif : ℝ → E :=
(Ioi 1).indicator (fun x ↦ P.g x - P.g₀) +
(Ioo 0 1).indicator (fun x ↦ P.g x - (P.ε⁻¹ * ↑(x ^ (-P.k))) • P.f₀)
lemma hf_modif_int :
LocallyIntegrableOn P.f_modif (Ioi 0) := by
have : LocallyIntegrableOn (fun x : ℝ ↦ (P.ε * ↑(x ^ (-P.k))) • P.g₀) (Ioi 0) := by
refine ContinuousOn.locallyIntegrableOn ?_ measurableSet_Ioi
refine continuousOn_of_forall_continuousAt (fun x (hx : 0 < x) ↦ ?_)
refine (continuousAt_const.mul ?_).smul continuousAt_const
exact continuous_ofReal.continuousAt.comp (continuousAt_rpow_const _ _ (Or.inl hx.ne'))
refine LocallyIntegrableOn.add (fun x hx ↦ ?_) (fun x hx ↦ ?_)
· obtain ⟨s, hs, hs'⟩ := P.hf_int.sub (locallyIntegrableOn_const _) x hx
refine ⟨s, hs, ?_⟩
rw [IntegrableOn, integrable_indicator_iff measurableSet_Ioi, IntegrableOn,
Measure.restrict_restrict measurableSet_Ioi, ← IntegrableOn]
exact hs'.mono_set Set.inter_subset_right
· obtain ⟨s, hs, hs'⟩ := P.hf_int.sub this x hx
refine ⟨s, hs, ?_⟩
rw [IntegrableOn, integrable_indicator_iff measurableSet_Ioo, IntegrableOn,
Measure.restrict_restrict measurableSet_Ioo, ← IntegrableOn]
exact hs'.mono_set Set.inter_subset_right
lemma hf_modif_FE (x : ℝ) (hx : 0 < x) :
P.f_modif (1 / x) = (P.ε * ↑(x ^ P.k)) • P.g_modif x := by
rcases lt_trichotomy 1 x with hx' | rfl | hx'
· have : 1 / x < 1 := by rwa [one_div_lt hx one_pos, div_one]
rw [f_modif, Pi.add_apply, indicator_of_notMem (notMem_Ioi.mpr this.le),
zero_add, indicator_of_mem (mem_Ioo.mpr ⟨div_pos one_pos hx, this⟩), g_modif, Pi.add_apply,
indicator_of_mem (mem_Ioi.mpr hx'), indicator_of_notMem
(notMem_Ioo_of_ge hx'.le), add_zero, P.h_feq _ hx, smul_sub]
simp_rw [rpow_neg (one_div_pos.mpr hx).le, one_div, inv_rpow hx.le, inv_inv]
· simp [f_modif, g_modif]
· have : 1 < 1 / x := by rwa [lt_one_div one_pos hx, div_one]
rw [f_modif, Pi.add_apply, indicator_of_mem (mem_Ioi.mpr this),
indicator_of_notMem (notMem_Ioo_of_ge this.le), g_modif, Pi.add_apply,
indicator_of_notMem (notMem_Ioi.mpr hx'.le),
indicator_of_mem (mem_Ioo.mpr ⟨hx, hx'⟩), P.h_feq _ hx]
simp_rw [rpow_neg hx.le]
match_scalars <;> field [(rpow_pos_of_pos hx P.k).ne', P.hε]
/-- Given a weak FE-pair `(f, g)`, modify it into a strong FE-pair by subtracting suitable
correction terms from `f` and `g`. -/
def toStrongFEPair : StrongFEPair E where
f := P.f_modif
g := P.symm.f_modif
k := P.k
ε := P.ε
f₀ := 0
g₀ := 0
hf_int := P.hf_modif_int
hg_int := P.symm.hf_modif_int
h_feq := P.hf_modif_FE
hε := P.hε
hk := P.hk
hf₀ := rfl
hg₀ := rfl
hf_top r := by
refine (P.hf_top r).congr' ?_ (by rfl)
filter_upwards [eventually_gt_atTop 1] with x hx
rw [f_modif, Pi.add_apply, indicator_of_mem (mem_Ioi.mpr hx),
indicator_of_notMem (notMem_Ioo_of_ge hx.le), add_zero, sub_zero]
hg_top r := by
refine (P.hg_top r).congr' ?_ (by rfl)
filter_upwards [eventually_gt_atTop 1] with x hx
rw [f_modif, Pi.add_apply, indicator_of_mem (mem_Ioi.mpr hx),
indicator_of_notMem (notMem_Ioo_of_ge hx.le), add_zero, sub_zero]
rfl
/- Alternative form for the difference between `f - f₀` and its modified term. -/
lemma f_modif_aux1 : EqOn (fun x ↦ P.f_modif x - P.f x + P.f₀)
((Ioo 0 1).indicator (fun x : ℝ ↦ P.f₀ - (P.ε * ↑(x ^ (-P.k))) • P.g₀)
+ ({1} : Set ℝ).indicator (fun _ ↦ P.f₀ - P.f 1)) (Ioi 0) := by
intro x (hx : 0 < x)
simp_rw [f_modif, Pi.add_apply]
rcases lt_trichotomy x 1 with hx' | rfl | hx'
· simp_rw [indicator_of_notMem (notMem_Ioi.mpr hx'.le),
indicator_of_mem (mem_Ioo.mpr ⟨hx, hx'⟩),
indicator_of_notMem (mem_singleton_iff.not.mpr hx'.ne)]
abel
· simp [add_comm, sub_eq_add_neg]
· simp_rw [indicator_of_mem (mem_Ioi.mpr hx'),
indicator_of_notMem (notMem_Ioo_of_ge hx'.le),
indicator_of_notMem (mem_singleton_iff.not.mpr hx'.ne')]
abel
/-- Compute the Mellin transform of the modifying term used to kill off the constants at
`0` and `∞`. -/
lemma f_modif_aux2 [CompleteSpace E] {s : ℂ} (hs : P.k < re s) :
mellin (fun x ↦ P.f_modif x - P.f x + P.f₀) s = (1 / s) • P.f₀ + (P.ε / (P.k - s)) • P.g₀ := by
have h_re1 : -1 < re (s - 1) := by simpa using P.hk.trans hs
have h_re2 : -1 < re (s - P.k - 1) := by simpa using hs
calc
_ = ∫ (x : ℝ) in Ioi 0, (x : ℂ) ^ (s - 1) •
((Ioo 0 1).indicator (fun t : ℝ ↦ P.f₀ - (P.ε * ↑(t ^ (-P.k))) • P.g₀) x
+ ({1} : Set ℝ).indicator (fun _ ↦ P.f₀ - P.f 1) x) :=
setIntegral_congr_fun measurableSet_Ioi (fun x hx ↦ by simp [f_modif_aux1 P hx])
_ = ∫ (x : ℝ) in Ioi 0, (x : ℂ) ^ (s - 1) • ((Ioo 0 1).indicator
(fun t : ℝ ↦ P.f₀ - (P.ε * ↑(t ^ (-P.k))) • P.g₀) x) := by
refine setIntegral_congr_ae measurableSet_Ioi (eventually_of_mem (U := {1}ᶜ)
(compl_mem_ae_iff.mpr (subsingleton_singleton.measure_zero _)) (fun x hx _ ↦ ?_))
rw [indicator_of_notMem hx, add_zero]
_ = ∫ (x : ℝ) in Ioc 0 1, (x : ℂ) ^ (s - 1) • (P.f₀ - (P.ε * ↑(x ^ (-P.k))) • P.g₀) := by
simp_rw [← indicator_smul, setIntegral_indicator measurableSet_Ioo,
inter_eq_right.mpr Ioo_subset_Ioi_self, integral_Ioc_eq_integral_Ioo]
_ = ∫ x : ℝ in Ioc 0 1, ((x : ℂ) ^ (s - 1) • P.f₀ - P.ε • (x : ℂ) ^ (s - P.k - 1) • P.g₀) := by
refine setIntegral_congr_fun measurableSet_Ioc (fun x ⟨hx, _⟩ ↦ ?_)
rw [ofReal_cpow hx.le, ofReal_neg, smul_sub, ← mul_smul, mul_comm, mul_assoc, mul_smul,
mul_comm, ← cpow_add _ _ (ofReal_ne_zero.mpr hx.ne'), ← sub_eq_add_neg, sub_right_comm]
_ = (∫ (x : ℝ) in Ioc 0 1, (x : ℂ) ^ (s - 1)) • P.f₀
- P.ε • (∫ (x : ℝ) in Ioc 0 1, (x : ℂ) ^ (s - P.k - 1)) • P.g₀ := by
rw [integral_sub, integral_smul, integral_smul_const, integral_smul_const]
· apply Integrable.smul_const
rw [← IntegrableOn, ← intervalIntegrable_iff_integrableOn_Ioc_of_le zero_le_one]
exact intervalIntegral.intervalIntegrable_cpow' h_re1
· refine (Integrable.smul_const ?_ _).smul _
rw [← IntegrableOn, ← intervalIntegrable_iff_integrableOn_Ioc_of_le zero_le_one]
exact intervalIntegral.intervalIntegrable_cpow' h_re2
_ = _ := by simp_rw [← intervalIntegral.integral_of_le zero_le_one,
integral_cpow (Or.inl h_re1), integral_cpow (Or.inl h_re2), ofReal_zero, ofReal_one,
one_cpow, sub_add_cancel, zero_cpow fun h ↦ lt_irrefl _ (P.hk.le.trans_lt (zero_re ▸ h ▸ hs)),
zero_cpow (sub_ne_zero.mpr (fun h ↦ lt_irrefl _ ((ofReal_re _) ▸ h ▸ hs)) : s - P.k ≠ 0),
sub_zero, sub_eq_add_neg (_ • _), ← mul_smul, ← neg_smul, mul_one_div, ← div_neg, neg_sub]
/-!
## Main theorems on weak FE-pairs
-/
/-- An entire function which differs from the Mellin transform of `f - f₀`, where defined, by a
correction term of the form `A / s + B / (k - s)`. -/
def Λ₀ : ℂ → E := mellin P.f_modif
/-- A meromorphic function which agrees with the Mellin transform of `f - f₀` where defined -/
def Λ (s : ℂ) : E := P.Λ₀ s - (1 / s) • P.f₀ - (P.ε / (P.k - s)) • P.g₀
lemma Λ₀_eq (s : ℂ) : P.Λ₀ s = P.Λ s + (1 / s) • P.f₀ + (P.ε / (P.k - s)) • P.g₀ := by
unfold Λ Λ₀
abel
lemma symm_Λ₀_eq (s : ℂ) :
P.symm.Λ₀ s = P.symm.Λ s + (1 / s) • P.g₀ + (P.ε⁻¹ / (P.k - s)) • P.f₀ := by
rw [P.symm.Λ₀_eq]
rfl
theorem differentiable_Λ₀ : Differentiable ℂ P.Λ₀ := P.toStrongFEPair.differentiable_Λ
theorem differentiableAt_Λ {s : ℂ} (hs : s ≠ 0 ∨ P.f₀ = 0) (hs' : s ≠ P.k ∨ P.g₀ = 0) :
DifferentiableAt ℂ P.Λ s := by
refine ((P.differentiable_Λ₀ s).sub ?_).sub ?_
· rcases hs with hs | hs
· simpa using (differentiableAt_inv hs).smul_const _
· simp [hs]
· rcases hs' with hs' | hs'
· apply DifferentiableAt.smul_const
apply (differentiableAt_const _).div ((differentiableAt_const _).sub (differentiable_id _))
simpa [sub_eq_zero, eq_comm]
· simp [hs']
/-- Relation between `Λ s` and the Mellin transform of `f - f₀`, where the latter is defined. -/
theorem hasMellin [CompleteSpace E]
{s : ℂ} (hs : P.k < s.re) : HasMellin (P.f · - P.f₀) s (P.Λ s) := by
have hc1 : MellinConvergent (P.f · - P.f₀) s :=
let ⟨_, ht⟩ := exists_gt s.re
mellinConvergent_of_isBigO_rpow (P.hf_int.sub (locallyIntegrableOn_const _)) (P.hf_top _) ht
P.hf_zero' hs
refine ⟨hc1, ?_⟩
have hc2 : HasMellin P.f_modif s (P.Λ₀ s) := P.toStrongFEPair.hasMellin s
have hc3 : mellin (fun x ↦ f_modif P x - f P x + P.f₀) s =
(1 / s) • P.f₀ + (P.ε / (↑P.k - s)) • P.g₀ := P.f_modif_aux2 hs
have := (hasMellin_sub hc2.1 hc1).2
simp_rw [← sub_add, hc3, eq_sub_iff_add_eq, ← eq_sub_iff_add_eq', ← sub_sub] at this
exact this
/-- Functional equation formulated for `Λ₀`. -/
theorem functional_equation₀ (s : ℂ) : P.Λ₀ (P.k - s) = P.ε • P.symm.Λ₀ s :=
P.toStrongFEPair.functional_equation s
/-- Functional equation formulated for `Λ`. -/
theorem functional_equation (s : ℂ) :
P.Λ (P.k - s) = P.ε • P.symm.Λ s := by
linear_combination (norm := module) P.functional_equation₀ s - P.Λ₀_eq (P.k - s)
+ congr(P.ε • $(P.symm_Λ₀_eq s)) + congr(($(mul_inv_cancel₀ P.hε) / ((P.k:ℂ) - s)) • P.f₀)
/-- The residue of `Λ` at `s = k` is equal to `ε • g₀`. -/
theorem Λ_residue_k :
Tendsto (fun s : ℂ ↦ (s - P.k) • P.Λ s) (𝓝[≠] P.k) (𝓝 (P.ε • P.g₀)) := by
simp_rw [Λ, smul_sub, (by simp : 𝓝 (P.ε • P.g₀) = 𝓝 (0 - 0 - -P.ε • P.g₀))]
refine ((Tendsto.sub ?_ ?_).mono_left nhdsWithin_le_nhds).sub ?_
· rw [(by rw [sub_self, zero_smul] : 𝓝 0 = 𝓝 ((P.k - P.k : ℂ) • P.Λ₀ P.k))]
apply ((continuous_sub_right _).smul P.differentiable_Λ₀.continuous).tendsto
· rw [(by rw [sub_self, zero_smul] : 𝓝 0 = 𝓝 ((P.k - P.k : ℂ) • (1 / P.k : ℂ) • P.f₀))]
refine (continuous_sub_right _).continuousAt.smul (ContinuousAt.smul ?_ continuousAt_const)
exact continuousAt_const.div continuousAt_id (ofReal_ne_zero.mpr P.hk.ne')
· refine (tendsto_const_nhds.mono_left nhdsWithin_le_nhds).congr' ?_
refine eventually_nhdsWithin_of_forall (fun s (hs : s ≠ P.k) ↦ ?_)
match_scalars
field [sub_ne_zero.mpr hs.symm]
/-- The residue of `Λ` at `s = 0` is equal to `-f₀`. -/
theorem Λ_residue_zero :
Tendsto (fun s : ℂ ↦ s • P.Λ s) (𝓝[≠] 0) (𝓝 (-P.f₀)) := by
simp_rw [Λ, smul_sub, (by simp : 𝓝 (-P.f₀) = 𝓝 (((0 : ℂ) • P.Λ₀ 0) - P.f₀ - 0))]
refine ((Tendsto.mono_left ?_ nhdsWithin_le_nhds).sub ?_).sub ?_
· exact (continuous_id.smul P.differentiable_Λ₀.continuous).tendsto _
· refine (tendsto_const_nhds.mono_left nhdsWithin_le_nhds).congr' ?_
refine eventually_nhdsWithin_of_forall (fun s (hs : s ≠ 0) ↦ ?_)
match_scalars
field [sub_ne_zero.mpr hs.symm]
· rw [show 𝓝 0 = 𝓝 ((0 : ℂ) • (P.ε / (P.k - 0 : ℂ)) • P.g₀) by rw [zero_smul]]
exact (continuousAt_id.smul ((continuousAt_const.div ((continuous_sub_left _).continuousAt)
(by simpa using P.hk.ne')).smul continuousAt_const)).mono_left nhdsWithin_le_nhds
end WeakFEPair |
.lake/packages/mathlib/Mathlib/NumberTheory/LSeries/Deriv.lean | import Mathlib.Analysis.Complex.LocallyUniformLimit
import Mathlib.NumberTheory.LSeries.Convergence
import Mathlib.Analysis.SpecialFunctions.Pow.Deriv
import Mathlib.Analysis.Complex.HalfPlane
/-!
# Differentiability and derivatives of L-series
## Main results
* We show that the `LSeries` of `f` is differentiable at `s` when `re s` is greater than
the abscissa of absolute convergence of `f` (`LSeries.hasDerivAt`) and that its derivative
there is the negative of the `LSeries` of the point-wise product `log * f` (`LSeries.deriv`).
* We prove similar results for iterated derivatives (`LSeries.iteratedDeriv`).
* We use this to show that `LSeries f` is holomorphic on the right half-plane of
absolute convergence (`LSeries.analyticOnNhd`).
## Implementation notes
We introduce `LSeries.logMul` as an abbreviation for the point-wise product `log * f`, to avoid
the problem that this expression does not type-check.
-/
open Complex LSeries
/-!
### The derivative of an L-series
-/
/-- The (point-wise) product of `log : ℕ → ℂ` with `f`. -/
noncomputable abbrev LSeries.logMul (f : ℕ → ℂ) (n : ℕ) : ℂ := log n * f n
/-- The derivative of the terms of an L-series. -/
lemma LSeries.hasDerivAt_term (f : ℕ → ℂ) (n : ℕ) (s : ℂ) :
HasDerivAt (fun z ↦ term f z n) (-(term (logMul f) s n)) s := by
rcases eq_or_ne n 0 with rfl | hn
· simp [hasDerivAt_const]
simp_rw [term_of_ne_zero hn, ← neg_div, ← neg_mul, mul_comm, mul_div_assoc, div_eq_mul_inv,
← cpow_neg]
exact HasDerivAt.const_mul (f n) (by simpa only [mul_comm, ← mul_neg_one (log n), ← mul_assoc]
using (hasDerivAt_neg' s).const_cpow (Or.inl <| Nat.cast_ne_zero.mpr hn))
/- This lemma proves two things at once, since their proofs are intertwined; we give separate
non-private lemmas below that extract the two statements. -/
private lemma LSeries.LSeriesSummable_logMul_and_hasDerivAt {f : ℕ → ℂ} {s : ℂ}
(h : abscissaOfAbsConv f < s.re) :
LSeriesSummable (logMul f) s ∧ HasDerivAt (LSeries f) (-LSeries (logMul f) s) s := by
-- The L-series of `f` is summable at some real `x < re s`.
obtain ⟨x, hxs, hf⟩ := LSeriesSummable_lt_re_of_abscissaOfAbsConv_lt_re h
obtain ⟨y, hxy, hys⟩ := exists_between hxs
-- We work in the right half-plane `y < re z`, for some `y` such that `x < y < re s`, on which
-- we have a uniform summable bound on `‖term f z ·‖`.
let S : Set ℂ := {z | y < z.re}
have h₀ : Summable (fun n ↦ ‖term f x n‖) := summable_norm_iff.mpr hf
have h₁ (n) : DifferentiableOn ℂ (term f · n) S :=
fun z _ ↦ (hasDerivAt_term f n _).differentiableAt.differentiableWithinAt
have h₂ : IsOpen S := isOpen_lt continuous_const continuous_re
have h₃ (n z) (hz : z ∈ S) : ‖term f z n‖ ≤ ‖term f x n‖ :=
norm_term_le_of_re_le_re f (by simpa using (hxy.trans hz).le) n
have H := hasSum_deriv_of_summable_norm h₀ h₁ h₂ h₃ hys
simp_rw [(hasDerivAt_term f _ _).deriv] at H
refine ⟨summable_neg_iff.mp H.summable, ?_⟩
simpa [← H.tsum_eq, tsum_neg] using ((differentiableOn_tsum_of_summable_norm
h₀ h₁ h₂ h₃).differentiableAt <| h₂.mem_nhds hys).hasDerivAt
/-- If `re s` is greater than the abscissa of absolute convergence of `f`, then the L-series
of `f` is differentiable with derivative the negative of the L-series of the point-wise
product of `log` with `f`. -/
lemma LSeries_hasDerivAt {f : ℕ → ℂ} {s : ℂ} (h : abscissaOfAbsConv f < s.re) :
HasDerivAt (LSeries f) (-LSeries (logMul f) s) s :=
(LSeriesSummable_logMul_and_hasDerivAt h).2
/-- If `re s` is greater than the abscissa of absolute convergence of `f`, then
the derivative of this L-series at `s` is the negative of the L-series of `log * f`. -/
lemma LSeries_deriv {f : ℕ → ℂ} {s : ℂ} (h : abscissaOfAbsConv f < s.re) :
deriv (LSeries f) s = -LSeries (logMul f) s :=
(LSeries_hasDerivAt h).deriv
/-- The derivative of the L-series of `f` agrees with the negative of the L-series of
`log * f` on the right half-plane of absolute convergence. -/
lemma LSeries_deriv_eqOn {f : ℕ → ℂ} :
{s | abscissaOfAbsConv f < s.re}.EqOn (deriv (LSeries f)) (-LSeries (logMul f)) :=
deriv_eqOn (isOpen_re_gt_EReal _) fun _ hs ↦ (LSeries_hasDerivAt hs).hasDerivWithinAt
/-- If the L-series of `f` is summable at `s` and `re s < re s'`, then the L-series of the
point-wise product of `log` with `f` is summable at `s'`. -/
lemma LSeriesSummable_logMul_of_lt_re {f : ℕ → ℂ} {s : ℂ} (h : abscissaOfAbsConv f < s.re) :
LSeriesSummable (logMul f) s :=
(LSeriesSummable_logMul_and_hasDerivAt h).1
/-- The abscissa of absolute convergence of the point-wise product of `log` and `f`
is the same as that of `f`. -/
@[simp]
lemma LSeries.abscissaOfAbsConv_logMul {f : ℕ → ℂ} :
abscissaOfAbsConv (logMul f) = abscissaOfAbsConv f := by
apply le_antisymm <;> refine abscissaOfAbsConv_le_of_forall_lt_LSeriesSummable' fun s hs ↦ ?_
· exact LSeriesSummable_logMul_of_lt_re <| by simp [hs]
· refine (LSeriesSummable_of_abscissaOfAbsConv_lt_re <| by simp [hs])
|>.norm.of_norm_bounded_eventually_nat (g := fun n ↦ ‖term (logMul f) s n‖) ?_
filter_upwards [Filter.eventually_ge_atTop <| max 1 (Nat.ceil (Real.exp 1))] with n hn
simp only [term_of_ne_zero (show n ≠ 0 by omega), logMul, norm_mul, mul_div_assoc,
← natCast_log, norm_real]
refine le_mul_of_one_le_left (norm_nonneg _) (.trans ?_ <| Real.le_norm_self _)
simpa using Real.log_le_log (Real.exp_pos 1) <| Nat.ceil_le.mp <| (le_max_right _ _).trans hn
/-!
### Higher derivatives of L-series
-/
/-- The abscissa of absolute convergence of the point-wise product of a power of `log` and `f`
is the same as that of `f`. -/
@[simp]
lemma LSeries.absicssaOfAbsConv_logPowMul {f : ℕ → ℂ} {m : ℕ} :
abscissaOfAbsConv (logMul^[m] f) = abscissaOfAbsConv f := by
induction m with
| zero => simp
| succ n ih => simp [ih, Function.iterate_succ', Function.comp_def,
-Function.comp_apply, -Function.iterate_succ]
/-- If `re s` is greater than the abscissa of absolute convergence of `f`, then
the `m`th derivative of this L-series is `(-1)^m` times the L-series of `log^m * f`. -/
lemma LSeries_iteratedDeriv {f : ℕ → ℂ} (m : ℕ) {s : ℂ} (h : abscissaOfAbsConv f < s.re) :
iteratedDeriv m (LSeries f) s = (-1) ^ m * LSeries (logMul^[m] f) s := by
induction m generalizing s with
| zero => simp
| succ m ih =>
have ih' : {s | abscissaOfAbsConv f < re s}.EqOn (iteratedDeriv m (LSeries f))
((-1) ^ m * LSeries (logMul^[m] f)) := fun _ hs ↦ ih hs
have := derivWithin_congr ih' (ih h)
simp_rw [derivWithin_of_isOpen (isOpen_re_gt_EReal _) h] at this
rw [iteratedDeriv_succ, this]
simp [Pi.mul_def, pow_succ, Function.iterate_succ',
LSeries_deriv <| absicssaOfAbsConv_logPowMul.symm ▸ h, -Function.iterate_succ]
/-!
### The L-series is holomorphic
-/
/-- The L-series of `f` is complex differentiable in its open half-plane of absolute
convergence. -/
lemma LSeries_differentiableOn (f : ℕ → ℂ) :
DifferentiableOn ℂ (LSeries f) {s | abscissaOfAbsConv f < s.re} :=
fun _ hz ↦ (LSeries_hasDerivAt hz).differentiableAt.differentiableWithinAt
/-- The L-series of `f` is holomorphic on its open half-plane of absolute convergence. -/
lemma LSeries_analyticOnNhd (f : ℕ → ℂ) :
AnalyticOnNhd ℂ (LSeries f) {s | abscissaOfAbsConv f < s.re} :=
(LSeries_differentiableOn f).analyticOnNhd <| isOpen_re_gt_EReal _
lemma LSeries_analyticOn (f : ℕ → ℂ) :
AnalyticOn ℂ (LSeries f) {s | abscissaOfAbsConv f < s.re} :=
(LSeries_analyticOnNhd f).analyticOn |
.lake/packages/mathlib/Mathlib/NumberTheory/LSeries/PrimesInAP.lean | import Mathlib.Data.ZMod.Coprime
import Mathlib.NumberTheory.DirichletCharacter.Orthogonality
import Mathlib.NumberTheory.LSeries.Linearity
import Mathlib.NumberTheory.LSeries.Nonvanishing
/-!
# Dirichlet's Theorem on primes in arithmetic progression
The goal of this file is to prove **Dirichlet's Theorem**: If `q` is a positive natural number
and `a : ZMod q` is invertible, then there are infinitely many prime numbers `p` such that
`(p : ZMod q) = a`.
The main steps of the proof are as follows.
1. Define `ArithmeticFunction.vonMangoldt.residueClass a` for `a : ZMod q`, which is
a function `ℕ → ℝ` taking the value zero when `(n : ℤMod q) ≠ a` and `Λ n` else
(where `Λ` is the von Mangoldt function `ArithmeticFunction.vonMangoldt`; we have
`Λ (p^k) = log p` for prime powers and `Λ n = 0` otherwise.)
2. Show that this function can be written as a linear combination of functions
of the form `χ * Λ` (pointwise product) with Dirichlet characters `χ` mod `q`.
See `ArithmeticFunction.vonMangoldt.residueClass_eq`.
3. This implies that the L-series of `ArithmeticFunction.vonMangoldt.residueClass a`
agrees (on `re s > 1`) with the corresponding linear combination of negative logarithmic
derivatives of Dirichlet L-functions.
See `ArithmeticFunction.vonMangoldt.LSeries_residueClass_eq`.
4. Define an auxiliary function `ArithmeticFunction.vonMangoldt.LFunctionResidueClassAux a` that is
this linear combination of negative logarithmic derivatives of L-functions minus
`(q.totient)⁻¹/(s-1)`, which cancels the pole at `s = 1`.
See `ArithmeticFunction.vonMangoldt.eqOn_LFunctionResidueClassAux` for the statement
that the auxiliary function agrees with the L-series of
`ArithmeticFunction.vonMangoldt.residueClass` up to the term `(q.totient)⁻¹/(s-1)`.
5. Show that the auxiliary function is continuous on `re s ≥ 1`;
see `ArithmeticFunction.vonMangoldt.continuousOn_LFunctionResidueClassAux`.
This relies heavily on the non-vanishing of Dirichlet L-functions on the *closed*
half-plane `re s ≥ 1` (`DirichletCharacter.LFunction_ne_zero_of_one_le_re`), which
in turn can only be stated since we know that the L-series of a Dirichlet character
extends to an entire function (unless the character is trivial; then there is a
simple pole at `s = 1`); see `DirichletCharacter.LFunction_eq_LSeries`
(contributed by David Loeffler).
6. Show that the sum of `Λ n / n` over any residue class, but *excluding* the primes, converges.
See `ArithmeticFunction.vonMangoldt.summable_residueClass_non_primes_div`.
7. Combining these ingredients, we can deduce that the sum of `Λ n / n` over
the *primes* in a residue class must diverge.
See `ArithmeticFunction.vonMangoldt.not_summable_residueClass_prime_div`.
8. This finally easily implies that there must be infinitely many primes in the residue class.
## Definitions
* `ArithmeticFunction.vonMangoldt.residueClass a` (see above).
* `ArithmeticFunction.vonMangoldt.continuousOn_LFunctionResidueClassAux` (see above).
## Main Result
We give two versions of **Dirichlet's Theorem**:
* `Nat.infinite_setOf_prime_and_eq_mod` states that the set of primes `p`
such that `(p : ZMod q) = a` is infinite (when `a` is invertible in `ZMod q`).
* `Nat.forall_exists_prime_gt_and_eq_mod` states that for any natural number `n`
there is a prime `p > n` such that `(p : ZMod q) = a`.
## Tags
prime number, arithmetic progression, residue class, Dirichlet's Theorem
-/
/-!
### Auxiliary statements
An infinite product or sum over a function supported in prime powers can be written
as an iterated product or sum over primes and natural numbers.
-/
section auxiliary
variable {α β γ : Type*} [CommGroup α] [UniformSpace α] [IsUniformGroup α] [CompleteSpace α]
[T0Space α]
open Nat.Primes in
@[to_additive tsum_eq_tsum_primes_of_support_subset_prime_powers]
lemma tprod_eq_tprod_primes_of_mulSupport_subset_prime_powers {f : ℕ → α}
(hfm : Multipliable f) (hf : Function.mulSupport f ⊆ {n | IsPrimePow n}) :
∏' n : ℕ, f n = ∏' (p : Nat.Primes) (k : ℕ), f (p ^ (k + 1)) := by
have hfm' : Multipliable fun pk : Nat.Primes × ℕ ↦ f (pk.fst ^ (pk.snd + 1)) :=
prodNatEquiv.symm.multipliable_iff.mp <| by
simpa only [← coe_prodNatEquiv_apply, Prod.eta, Function.comp_def, Equiv.apply_symm_apply]
using hfm.subtype _
simp only [← tprod_subtype_eq_of_mulSupport_subset hf, Set.coe_setOf, ← prodNatEquiv.tprod_eq,
← hfm'.tprod_prod]
refine tprod_congr fun (p, k) ↦ congrArg f <| coe_prodNatEquiv_apply ..
@[to_additive tsum_eq_tsum_primes_add_tsum_primes_of_support_subset_prime_powers]
lemma tprod_eq_tprod_primes_mul_tprod_primes_of_mulSupport_subset_prime_powers {f : ℕ → α}
(hfm : Multipliable f) (hf : Function.mulSupport f ⊆ {n | IsPrimePow n}) :
∏' n : ℕ, f n = (∏' p : Nat.Primes, f p) * ∏' (p : Nat.Primes) (k : ℕ), f (p ^ (k + 2)) := by
rw [tprod_eq_tprod_primes_of_mulSupport_subset_prime_powers hfm hf]
have hfs' (p : Nat.Primes) : Multipliable fun k : ℕ ↦ f (p ^ (k + 1)) :=
hfm.comp_injective <| (strictMono_nat_of_lt_succ
fun k ↦ pow_lt_pow_right₀ p.prop.one_lt <| lt_add_one (k + 1)).injective
conv_lhs =>
enter [1, p]; rw [(hfs' p).tprod_eq_zero_mul, zero_add, pow_one]
enter [2, 1, k]; rw [add_assoc, one_add_one_eq_two]
exact (Multipliable.subtype hfm _).tprod_mul <|
Multipliable.prod (f := fun (pk : Nat.Primes × ℕ) ↦ f (pk.1 ^ (pk.2 + 2))) <|
hfm.comp_injective <| Subtype.val_injective |>.comp
Nat.Primes.prodNatEquiv.injective |>.comp <|
Function.Injective.prodMap (fun ⦃_ _⦄ a ↦ a) <| add_left_injective 1
end auxiliary
/-!
### The L-series of the von Mangoldt function restricted to a residue class
-/
section arith_prog
namespace ArithmeticFunction.vonMangoldt
open Complex LSeries DirichletCharacter
open scoped LSeries.notation
variable {q : ℕ} (a : ZMod q)
/-- The von Mangoldt function restricted to the residue class `a` mod `q`. -/
noncomputable abbrev residueClass : ℕ → ℝ :=
{n : ℕ | (n : ZMod q) = a}.indicator (vonMangoldt ·)
lemma residueClass_nonneg (n : ℕ) : 0 ≤ residueClass a n :=
Set.indicator_apply_nonneg fun _ ↦ vonMangoldt_nonneg
lemma residueClass_le (n : ℕ) : residueClass a n ≤ vonMangoldt n :=
Set.indicator_apply_le' (fun _ ↦ le_rfl) (fun _ ↦ vonMangoldt_nonneg)
@[simp]
lemma residueClass_apply_zero : residueClass a 0 = 0 := by
simp only [Set.indicator_apply_eq_zero, Set.mem_setOf_eq, Nat.cast_zero, map_zero,
implies_true]
lemma abscissaOfAbsConv_residueClass_le_one :
abscissaOfAbsConv ↗(residueClass a) ≤ 1 := by
refine abscissaOfAbsConv_le_of_forall_lt_LSeriesSummable fun y hy ↦ ?_
unfold LSeriesSummable
have := LSeriesSummable_vonMangoldt <| show 1 < (y : ℂ).re by simp only [ofReal_re, hy]
convert this.indicator {n : ℕ | (n : ZMod q) = a}
ext1 n
by_cases hn : (n : ZMod q) = a
· simp +contextual only [term, Set.indicator, Set.mem_setOf_eq, hn, ↓reduceIte, apply_ite,
ite_self]
· simp +contextual only [term, Set.mem_setOf_eq, hn, not_false_eq_true, Set.indicator_of_notMem,
ofReal_zero, zero_div, ite_self]
/-- The set we are interested in (prime numbers in the residue class `a`) is the same as the support
of `ArithmeticFunction.vonMangoldt.residueClass` restricted to primes (and divided by `n`;
this is how this result is used later). -/
lemma support_residueClass_prime_div :
Function.support (fun n : ℕ ↦ (if n.Prime then residueClass a n else 0) / n) =
{p : ℕ | p.Prime ∧ (p : ZMod q) = a} := by
simp only [Function.support, ne_eq, div_eq_zero_iff, ite_eq_right_iff,
Set.indicator_apply_eq_zero, Set.mem_setOf_eq, Nat.cast_eq_zero, not_or, Classical.not_imp]
ext1 p
simp only [Set.mem_setOf_eq]
exact ⟨fun H ↦ ⟨H.1.1, H.1.2.1⟩,
fun H ↦ ⟨⟨H.1, H.2, vonMangoldt_ne_zero_iff.mpr H.1.isPrimePow⟩, H.1.ne_zero⟩⟩
private noncomputable def F₀ (n : ℕ) : ℝ := (if n.Prime then 0 else vonMangoldt n) / n
private noncomputable def F' (pk : Nat.Primes × ℕ) : ℝ := F₀ (pk.1 ^ (pk.2 + 1))
private noncomputable def F'' : Nat.Primes × ℕ → ℝ := F' ∘ (Prod.map _root_.id (· + 1))
private lemma F''_le (p : Nat.Primes) (k : ℕ) : F'' (p, k) ≤ 2 * (p : ℝ)⁻¹ ^ (k + 3 / 2 : ℝ) :=
calc _
_ = Real.log p * (p : ℝ)⁻¹ ^ (k + 2) := by
simp only [F'', Function.comp_apply, F', F₀, Prod.map_apply, id_eq, le_add_iff_nonneg_left,
zero_le, Nat.Prime.not_prime_pow, ↓reduceIte, vonMangoldt_apply_prime p.prop,
vonMangoldt_apply_pow (Nat.zero_ne_add_one _).symm, Nat.cast_pow, div_eq_mul_inv,
inv_pow (p : ℝ) (k + 2)]
_ ≤ (p : ℝ) ^ (1 / 2 : ℝ) / (1 / 2) * (p : ℝ)⁻¹ ^ (k + 2) :=
mul_le_mul_of_nonneg_right (Real.log_le_rpow_div p.val.cast_nonneg one_half_pos)
(pow_nonneg (inv_nonneg_of_nonneg (Nat.cast_nonneg ↑p)) (k + 2))
_ = 2 * (p : ℝ)⁻¹ ^ (-1 / 2 : ℝ) * (p : ℝ)⁻¹ ^ (k + 2) := by
simp only [← div_mul, div_one, mul_comm, neg_div, Real.inv_rpow p.val.cast_nonneg,
← Real.rpow_neg p.val.cast_nonneg, neg_neg]
_ = _ := by
rw [mul_assoc, ← Real.rpow_natCast,
← Real.rpow_add <| by have := p.prop.pos; positivity, Nat.cast_add, Nat.cast_two,
add_comm, add_assoc]
norm_num
open Nat.Primes
private lemma summable_F'' : Summable F'' := by
have hp₀ (p : Nat.Primes) : 0 < (p : ℝ)⁻¹ := inv_pos_of_pos (Nat.cast_pos.mpr p.prop.pos)
have hp₁ (p : Nat.Primes) : (p : ℝ)⁻¹ < 1 :=
(inv_lt_one₀ <| mod_cast p.prop.pos).mpr <| Nat.one_lt_cast.mpr <| p.prop.one_lt
suffices Summable fun (pk : Nat.Primes × ℕ) ↦ (pk.1 : ℝ)⁻¹ ^ (pk.2 + 3 / 2 : ℝ) by
refine (Summable.mul_left 2 this).of_nonneg_of_le (fun pk ↦ ?_) (fun pk ↦ F''_le pk.1 pk.2)
simp only [F'', Function.comp_apply, F', F₀, Prod.map_fst, id_eq, Prod.map_snd, Nat.cast_pow]
positivity [vonMangoldt_nonneg (n := (pk.1 : ℕ) ^ (pk.2 + 2))]
conv => enter [1, pk]; rw [Real.rpow_add <| hp₀ pk.1, Real.rpow_natCast]
refine (summable_prod_of_nonneg (fun _ ↦ by positivity)).mpr ⟨(fun p ↦ ?_), ?_⟩
· dsimp only -- otherwise the `exact` below times out
exact Summable.mul_right _ <| summable_geometric_of_lt_one (hp₀ p).le (hp₁ p)
· dsimp only
conv => enter [1, p]; rw [tsum_mul_right, tsum_geometric_of_lt_one (hp₀ p).le (hp₁ p)]
refine (summable_rpow.mpr (by norm_num : -(3 / 2 : ℝ) < -1)).mul_left 2
|>.of_nonneg_of_le (fun p ↦ ?_) (fun p ↦ ?_)
· positivity [sub_pos.mpr (hp₁ p)]
· rw [Real.inv_rpow p.val.cast_nonneg, Real.rpow_neg p.val.cast_nonneg]
gcongr
rw [inv_le_comm₀ (sub_pos.mpr (hp₁ p)) zero_lt_two, le_sub_comm,
show (1 : ℝ) - 2⁻¹ = 2⁻¹ by norm_num, inv_le_inv₀ (mod_cast p.prop.pos) zero_lt_two]
exact Nat.ofNat_le_cast.mpr p.prop.two_le
/-- The function `n ↦ Λ n / n`, restricted to non-primes in a residue class, is summable.
This is used to convert results on `ArithmeticFunction.vonMangoldt.residueClass` to results
on primes in an arithmetic progression. -/
lemma summable_residueClass_non_primes_div :
Summable fun n : ℕ ↦ (if n.Prime then 0 else residueClass a n) / n := by
have h₀ (n : ℕ) : 0 ≤ (if n.Prime then 0 else residueClass a n) / n := by
positivity [residueClass_nonneg a n]
have hleF₀ (n : ℕ) : (if n.Prime then 0 else residueClass a n) / n ≤ F₀ n := by
refine div_le_div_of_nonneg_right ?_ n.cast_nonneg
split_ifs; exacts [le_rfl, residueClass_le a n]
refine Summable.of_nonneg_of_le h₀ hleF₀ ?_
have hF₀ (p : Nat.Primes) : F₀ p.val = 0 := by
simp only [p.prop, ↓reduceIte, zero_div, F₀]
refine (summable_subtype_iff_indicator (s := {n | IsPrimePow n}).mp ?_).congr
fun n ↦ Set.indicator_apply_eq_self.mpr fun (hn : ¬ IsPrimePow n) ↦ ?_
swap
· simp +contextual only [div_eq_zero_iff, ite_eq_left_iff, vonMangoldt_eq_zero_iff, hn,
not_false_eq_true, implies_true, Nat.cast_eq_zero, true_or, F₀]
have hFF' :
F₀ ∘ Subtype.val (p := fun n ↦ n ∈ {n | IsPrimePow n}) = F' ∘ ⇑prodNatEquiv.symm := by
refine (Equiv.eq_comp_symm prodNatEquiv (F₀ ∘ Subtype.val) F').mpr ?_
ext1 n
simp only [Function.comp_apply, F']
congr
rw [hFF']
refine (Nat.Primes.prodNatEquiv.symm.summable_iff (f := F')).mpr ?_
have hF'₀ (p : Nat.Primes) : F' (p, 0) = 0 := by simp only [zero_add, pow_one, hF₀, F']
have hF'₁ : F'' = F' ∘ (Prod.map _root_.id (· + 1)) := by
ext1
simp only [Function.comp_apply, Prod.map_fst, id_eq, Prod.map_snd, F'', F']
refine (Function.Injective.summable_iff ?_ fun u hu ↦ ?_).mp <| hF'₁ ▸ summable_F''
· exact Function.Injective.prodMap (fun ⦃a₁ a₂⦄ a ↦ a) <| add_left_injective 1
· simp only [Set.range_prodMap, Set.range_id, Set.mem_prod, Set.mem_univ, Set.mem_range,
Nat.exists_add_one_eq, true_and, not_lt, nonpos_iff_eq_zero] at hu
rw [← hF'₀ u.1, ← hu]
variable [NeZero q] {a}
/-- We can express `ArithmeticFunction.vonMangoldt.residueClass` as a linear combination
of twists of the von Mangoldt function by Dirichlet characters. -/
lemma residueClass_apply (ha : IsUnit a) (n : ℕ) :
residueClass a n =
(q.totient : ℂ)⁻¹ * ∑ χ : DirichletCharacter ℂ q, χ a⁻¹ * χ n * vonMangoldt n := by
rw [eq_inv_mul_iff_mul_eq₀ <| mod_cast (Nat.totient_pos.mpr q.pos_of_neZero).ne']
simp +contextual only [residueClass, Set.indicator_apply, Set.mem_setOf_eq, apply_ite,
ofReal_zero, mul_zero, ← Finset.sum_mul, sum_char_inv_mul_char_eq ℂ ha n, eq_comm (a := a),
ite_mul, zero_mul, ↓reduceIte, ite_self]
/-- We can express `ArithmeticFunction.vonMangoldt.residueClass` as a linear combination
of twists of the von Mangoldt function by Dirichlet characters. -/
lemma residueClass_eq (ha : IsUnit a) :
↗(residueClass a) = (q.totient : ℂ)⁻¹ •
∑ χ : DirichletCharacter ℂ q, χ a⁻¹ • (fun n : ℕ ↦ χ n * vonMangoldt n) := by
ext1 n
simpa only [Pi.smul_apply, Finset.sum_apply, smul_eq_mul, ← mul_assoc]
using residueClass_apply ha n
/-- The L-series of the von Mangoldt function restricted to the residue class `a` mod `q`
with `a` invertible in `ZMod q` is a linear combination of logarithmic derivatives of
L-functions of the Dirichlet characters mod `q` (on `re s > 1`). -/
lemma LSeries_residueClass_eq (ha : IsUnit a) {s : ℂ} (hs : 1 < s.re) :
LSeries ↗(residueClass a) s =
-(q.totient : ℂ)⁻¹ * ∑ χ : DirichletCharacter ℂ q, χ a⁻¹ *
(deriv (LFunction χ) s / LFunction χ s) := by
simp only [deriv_LFunction_eq_deriv_LSeries _ hs, LFunction_eq_LSeries _ hs, neg_mul, ← mul_neg,
← Finset.sum_neg_distrib, ← neg_div, ← LSeries_twist_vonMangoldt_eq _ hs]
rw [eq_inv_mul_iff_mul_eq₀ <| mod_cast (Nat.totient_pos.mpr q.pos_of_neZero).ne']
simp_rw [← LSeries_smul,
← LSeries_sum <| fun χ _ ↦ (LSeriesSummable_twist_vonMangoldt χ hs).smul _]
refine LSeries_congr (fun {n} _ ↦ ?_) s
simp only [Pi.smul_apply, residueClass_apply ha, smul_eq_mul, ← mul_assoc,
mul_inv_cancel_of_invertible, one_mul, Finset.sum_apply, Pi.mul_apply]
variable (a)
open Classical in
/-- The auxiliary function used, e.g., with the Wiener-Ikehara Theorem to prove
Dirichlet's Theorem. On `re s > 1`, it agrees with the L-series of the von Mangoldt
function restricted to the residue class `a : ZMod q` minus the principal part
`(q.totient)⁻¹/(s-1)` of the pole at `s = 1`;
see `ArithmeticFunction.vonMangoldt.eqOn_LFunctionResidueClassAux`. -/
noncomputable
abbrev LFunctionResidueClassAux (s : ℂ) : ℂ :=
(q.totient : ℂ)⁻¹ * (-deriv (LFunctionTrivChar₁ q) s / LFunctionTrivChar₁ q s -
∑ χ ∈ ({1}ᶜ : Finset (DirichletCharacter ℂ q)), χ a⁻¹ * deriv (LFunction χ) s / LFunction χ s)
/-- The auxiliary function is continuous away from the zeros of the L-functions of the Dirichlet
characters mod `q` (including at `s = 1`). -/
lemma continuousOn_LFunctionResidueClassAux' :
ContinuousOn (LFunctionResidueClassAux a)
{s | s = 1 ∨ ∀ χ : DirichletCharacter ℂ q, LFunction χ s ≠ 0} := by
rw [show LFunctionResidueClassAux a = fun s ↦ _ from rfl]
simp only [LFunctionResidueClassAux, sub_eq_add_neg]
refine continuousOn_const.mul <| ContinuousOn.add ?_ ?_
· refine (continuousOn_neg_logDeriv_LFunctionTrivChar₁ q).mono fun s hs ↦ ?_
have := LFunction_ne_zero_of_one_le_re (1 : DirichletCharacter ℂ q) (s := s)
simp only [ne_eq, Set.mem_setOf_eq] at hs
tauto
· simp only [← Finset.sum_neg_distrib, mul_div_assoc, ← mul_neg, ← neg_div]
refine continuousOn_finset_sum _ fun χ hχ ↦ continuousOn_const.mul ?_
replace hχ : χ ≠ 1 := by simpa only [ne_eq, Finset.mem_compl, Finset.mem_singleton] using hχ
refine (continuousOn_neg_logDeriv_LFunction_of_nontriv hχ).mono fun s hs ↦ ?_
simp only [ne_eq, Set.mem_setOf_eq] at hs
rcases hs with rfl | hs
· simp only [ne_eq, Set.mem_setOf_eq, one_re, le_refl,
LFunction_ne_zero_of_one_le_re χ (.inl hχ), not_false_eq_true]
· exact hs χ
/-- The L-series of the von Mangoldt function restricted to the prime residue class `a` mod `q`
is continuous on `re s ≥ 1` except for a simple pole at `s = 1` with residue `(q.totient)⁻¹`.
The statement as given here in terms of `ArithmeticFunction.vonMangoldt.LFunctionResidueClassAux`
is equivalent. -/
lemma continuousOn_LFunctionResidueClassAux :
ContinuousOn (LFunctionResidueClassAux a) {s | 1 ≤ s.re} := by
refine (continuousOn_LFunctionResidueClassAux' a).mono fun s hs ↦ ?_
rcases eq_or_ne s 1 with rfl | hs₁
· simp only [ne_eq, Set.mem_setOf_eq, true_or]
· simp only [ne_eq, Set.mem_setOf_eq, hs₁, false_or]
exact fun χ ↦ LFunction_ne_zero_of_one_le_re χ (.inr hs₁) <| Set.mem_setOf.mp hs
variable {a}
open scoped LSeries.notation
/-- The auxiliary function agrees on `re s > 1` with the L-series of the von Mangoldt function
restricted to the residue class `a : ZMod q` minus the principal part `(q.totient)⁻¹/(s-1)`
of its pole at `s = 1`. -/
lemma eqOn_LFunctionResidueClassAux (ha : IsUnit a) :
Set.EqOn (LFunctionResidueClassAux a)
(fun s ↦ L ↗(residueClass a) s - (q.totient : ℂ)⁻¹ / (s - 1))
{s | 1 < s.re} := by
intro s hs
replace hs := Set.mem_setOf.mp hs
simp only [LSeries_residueClass_eq ha hs, LFunctionResidueClassAux]
rw [neg_div, ← neg_add', mul_neg, ← neg_mul, div_eq_mul_one_div (q.totient : ℂ)⁻¹,
sub_eq_add_neg, ← neg_mul, ← mul_add]
congrm (_ * ?_)
-- this should be easier, but `IsUnit.inv ha` does not work here
have ha' : IsUnit a⁻¹ := isUnit_of_dvd_one ⟨a, (ZMod.inv_mul_of_unit a ha).symm⟩
classical -- for `Fintype.sum_eq_add_sum_compl`
rw [Fintype.sum_eq_add_sum_compl 1, MulChar.one_apply ha', one_mul, add_right_comm]
simp only [mul_div_assoc]
congrm (?_ + _)
have hs₁ : s ≠ 1 := fun h ↦ ((h ▸ hs).trans_eq one_re).false
rw [deriv_LFunctionTrivChar₁_apply_of_ne_one _ hs₁, LFunctionTrivChar₁,
Function.update_of_ne hs₁, LFunctionTrivChar, add_div,
mul_div_mul_left _ _ (sub_ne_zero_of_ne hs₁)]
conv_lhs => enter [2, 1]; rw [← mul_one (LFunction ..)]
rw [mul_comm _ 1, mul_div_mul_right _ _ <| LFunction_ne_zero_of_one_le_re 1 (.inr hs₁) hs.le]
/-- The auxiliary function takes real values for real arguments `x > 1`. -/
lemma LFunctionResidueClassAux_real (ha : IsUnit a) {x : ℝ} (hx : 1 < x) :
LFunctionResidueClassAux a x = (LFunctionResidueClassAux a x).re := by
rw [eqOn_LFunctionResidueClassAux ha hx]
simp only [sub_re, ofReal_sub]
congr 1
· rw [LSeries, re_tsum <| LSeriesSummable_of_abscissaOfAbsConv_lt_re <|
(abscissaOfAbsConv_residueClass_le_one a).trans_lt <| by norm_cast]
push_cast
refine tsum_congr fun n ↦ ?_
rcases eq_or_ne n 0 with rfl | hn
· simp only [term_zero, zero_re, ofReal_zero]
· simp only [term_of_ne_zero hn, ← ofReal_natCast n, ← ofReal_cpow n.cast_nonneg, ← ofReal_div,
ofReal_re]
· rw [← ofReal_natCast, ← ofReal_one, ← ofReal_sub, ← ofReal_inv,
← ofReal_div, ofReal_re]
variable {q : ℕ} [NeZero q] {a : ZMod q}
/-- As `x` approaches `1` from the right along the real axis, the L-series of
`ArithmeticFunction.vonMangoldt.residueClass` is bounded below by `(q.totient)⁻¹/(x-1) - C`. -/
lemma LSeries_residueClass_lower_bound (ha : IsUnit a) :
∃ C : ℝ, ∀ {x : ℝ} (_ : x ∈ Set.Ioc 1 2),
(q.totient : ℝ)⁻¹ / (x - 1) - C ≤ ∑' n, residueClass a n / (n : ℝ) ^ x := by
have H {x : ℝ} (hx : 1 < x) :
∑' n, residueClass a n / (n : ℝ) ^ x =
(LFunctionResidueClassAux a x).re + (q.totient : ℝ)⁻¹ / (x - 1) := by
refine ofReal_injective ?_
simp only [ofReal_tsum, ofReal_div, ofReal_cpow (Nat.cast_nonneg _), ofReal_natCast,
ofReal_add, ofReal_inv, ofReal_sub, ofReal_one]
simp_rw [← LFunctionResidueClassAux_real ha hx,
eqOn_LFunctionResidueClassAux ha <| Set.mem_setOf.mpr (ofReal_re x ▸ hx), sub_add_cancel,
LSeries, term]
refine tsum_congr fun n ↦ ?_
split_ifs with hn
· simp only [hn, residueClass_apply_zero, ofReal_zero, zero_div]
· rfl
have : ContinuousOn (fun x : ℝ ↦ (LFunctionResidueClassAux a x).re) (Set.Icc 1 2) :=
continuous_re.continuousOn.comp (t := Set.univ) (continuousOn_LFunctionResidueClassAux a)
(fun ⦃x⦄ a ↦ trivial) |>.comp continuous_ofReal.continuousOn fun x hx ↦ by
simpa only [Set.mem_setOf_eq, ofReal_re] using hx.1
obtain ⟨C, hC⟩ := bddBelow_def.mp <| IsCompact.bddBelow_image isCompact_Icc this
replace hC {x : ℝ} (hx : x ∈ Set.Icc 1 2) : C ≤ (LFunctionResidueClassAux a x).re :=
hC (LFunctionResidueClassAux a x).re <|
Set.mem_image_of_mem (fun x : ℝ ↦ (LFunctionResidueClassAux a x).re) hx
refine ⟨-C, fun {x} hx ↦ ?_⟩
rw [H hx.1, add_comm, sub_neg_eq_add, add_le_add_iff_left]
exact hC <| Set.mem_Icc_of_Ioc hx
open vonMangoldt Filter Topology in
/-- The function `n ↦ Λ n / n` restricted to primes in an invertible residue class
is not summable. This then implies that there must be infinitely many such primes. -/
lemma not_summable_residueClass_prime_div (ha : IsUnit a) :
¬ Summable fun n : ℕ ↦ (if n.Prime then residueClass a n else 0) / n := by
intro H
have key : Summable fun n : ℕ ↦ residueClass a n / n := by
convert (summable_residueClass_non_primes_div a).add H using 2 with n
simp only [← add_div, ite_add_ite, zero_add, add_zero, ite_self]
let C := ∑' n, residueClass a n / n
have H₁ {x : ℝ} (hx : 1 < x) : ∑' n, residueClass a n / (n : ℝ) ^ x ≤ C := by
refine Summable.tsum_le_tsum (fun n ↦ ?_) ?_ key
· rcases n.eq_zero_or_pos with rfl | hn
· simp only [Nat.cast_zero, Real.zero_rpow (zero_lt_one.trans hx).ne', div_zero, le_refl]
· refine div_le_div_of_nonneg_left (residueClass_nonneg a _) (mod_cast hn) ?_
conv_lhs => rw [← Real.rpow_one n]
exact Real.rpow_le_rpow_of_exponent_le (by norm_cast) hx.le
· exact summable_real_of_abscissaOfAbsConv_lt <|
(abscissaOfAbsConv_residueClass_le_one a).trans_lt <| mod_cast hx
obtain ⟨C', hC'⟩ := LSeries_residueClass_lower_bound ha
have H₁ {x} (hx : x ∈ Set.Ioc 1 2) : (q.totient : ℝ)⁻¹ ≤ (C + C') * (x - 1) :=
(div_le_iff₀ <| sub_pos.mpr hx.1).mp <|
sub_le_iff_le_add.mp <| (hC' hx).trans (H₁ hx.1)
have hq : 0 < (q.totient : ℝ)⁻¹ := inv_pos.mpr (mod_cast q.totient.pos_of_neZero)
rcases le_or_gt (C + C') 0 with h₀ | h₀
· have := hq.trans_le (H₁ (Set.right_mem_Ioc.mpr one_lt_two))
rw [show (2 : ℝ) - 1 = 1 by norm_num, mul_one] at this
exact (this.trans_le h₀).false
· obtain ⟨ξ, hξ₁, hξ₂⟩ : ∃ ξ ∈ Set.Ioc 1 2, (C + C') * (ξ - 1) < (q.totient : ℝ)⁻¹ := by
refine ⟨min (1 + (q.totient : ℝ)⁻¹ / (C + C') / 2) 2, ⟨?_, min_le_right ..⟩, ?_⟩
· simpa only [lt_inf_iff, lt_add_iff_pos_right, Nat.ofNat_pos, div_pos_iff_of_pos_right,
Nat.one_lt_ofNat, and_true] using div_pos hq h₀
· rw [← min_sub_sub_right, add_sub_cancel_left, ← lt_div_iff₀' h₀]
exact (min_le_left ..).trans_lt <| div_lt_self (div_pos hq h₀) one_lt_two
exact ((H₁ hξ₁).trans_lt hξ₂).false
end ArithmeticFunction.vonMangoldt
end arith_prog
/-!
### Dirichlet's Theorem
-/
section DirichletsTheorem
namespace Nat
open ArithmeticFunction vonMangoldt
variable {q : ℕ} [NeZero q] {a : ZMod q}
/-- **Dirichlet's Theorem** on primes in arithmetic progression: if `q` is a positive
integer and `a : ZMod q` is a unit, then there are infinitely many prime numbers `p`
such that `(p : ZMod q) = a`. -/
theorem infinite_setOf_prime_and_eq_mod (ha : IsUnit a) :
{p : ℕ | p.Prime ∧ (p : ZMod q) = a}.Infinite := by
by_contra H
rw [Set.not_infinite] at H
exact not_summable_residueClass_prime_div ha <|
summable_of_finite_support <| support_residueClass_prime_div a ▸ H
@[deprecated (since := "2025-11-01")]
alias setOf_prime_and_eq_mod_infinite := infinite_setOf_prime_and_eq_mod
/-- **Dirichlet's Theorem** on primes in arithmetic progression: if `q` is a positive
integer and `a : ZMod q` is a unit, then there are infinitely many prime numbers `p`
such that `(p : ZMod q) = a`. -/
theorem forall_exists_prime_gt_and_eq_mod (ha : IsUnit a) (n : ℕ) :
∃ p > n, p.Prime ∧ (p : ZMod q) = a := by
obtain ⟨p, hp₁, hp₂⟩ := Set.infinite_iff_exists_gt.mp (infinite_setOf_prime_and_eq_mod ha) n
exact ⟨p, hp₂.gt, Set.mem_setOf.mp hp₁⟩
/-- **Dirichlet's Theorem** on primes in arithmetic progression: if `q` is a positive
integer and `a : ℤ` is coprime to `q`, then there are infinitely many prime numbers `p`
such that `p ≡ a mod q`. -/
theorem forall_exists_prime_gt_and_zmodEq (n : ℕ) {q : ℕ} {a : ℤ} (hq : q ≠ 0) (h : IsCoprime a q) :
∃ p > n, p.Prime ∧ p ≡ a [ZMOD q] := by
have : NeZero q := ⟨hq⟩
have : IsUnit (a : ZMod q) := by
rwa [ZMod.coe_int_isUnit_iff_isCoprime, isCoprime_comm]
obtain ⟨p, hpn, hpp, heq⟩ := forall_exists_prime_gt_and_eq_mod this n
refine ⟨p, hpn, hpp, ?_⟩
simpa [← ZMod.intCast_eq_intCast_iff] using heq
/-- **Dirichlet's Theorem** on primes in arithmetic progression: if `q` is a positive
integer and `a : ℕ` is coprime to `q`, then there are infinitely many prime numbers `p`
such that `p ≡ a mod q`. -/
theorem forall_exists_prime_gt_and_modEq (n : ℕ) {q a : ℕ} (hq : q ≠ 0) (h : a.Coprime q) :
∃ p > n, p.Prime ∧ p ≡ a [MOD q] := by
simpa using forall_exists_prime_gt_and_zmodEq n (q := q) (a := a) hq (by simpa)
open Filter in
lemma frequently_atTop_prime_and_modEq {q a : ℕ} (hq : q ≠ 0) (h : a.Coprime q) :
∃ᶠ p in atTop, p.Prime ∧ p ≡ a [MOD q] := by
rw [frequently_atTop]
intro n
obtain ⟨p, hn, hp, ha⟩ := forall_exists_prime_gt_and_modEq n hq h
exact ⟨p, hn.le, hp, ha⟩
lemma infinite_setOf_prime_and_modEq {q a : ℕ} (hq : q ≠ 0) (h : a.Coprime q) :
Set.Infinite {p : ℕ | p.Prime ∧ p ≡ a [MOD q]} :=
frequently_atTop_iff_infinite.1 (frequently_atTop_prime_and_modEq hq h)
end Nat
end DirichletsTheorem |
.lake/packages/mathlib/Mathlib/NumberTheory/LSeries/Basic.lean | import Mathlib.Analysis.PSeries
import Mathlib.Analysis.Normed.Module.FiniteDimension
import Mathlib.LinearAlgebra.Complex.FiniteDimensional
/-!
# L-series
Given a sequence `f: ℕ → ℂ`, we define the corresponding L-series.
## Main Definitions
* `LSeries.term f s n` is the `n`th term of the L-series of the sequence `f` at `s : ℂ`.
We define it to be zero when `n = 0`.
* `LSeries f` is the L-series with a given sequence `f` as its coefficients. This is not the
analytic continuation (which does not necessarily exist), just the sum of the infinite series if
it exists and zero otherwise.
* `LSeriesSummable f s` indicates that the L-series of `f` converges at `s : ℂ`.
* `LSeriesHasSum f s a` expresses that the L-series of `f` converges (absolutely) at `s : ℂ` to
`a : ℂ`.
## Main Results
* `LSeriesSummable_of_isBigO_rpow`: the `LSeries` of a sequence `f` such that `f = O(n^(x-1))`
converges at `s` when `x < s.re`.
* `LSeriesSummable.isBigO_rpow`: if the `LSeries` of `f` is summable at `s`, then `f = O(n^(re s))`.
## Notation
We introduce `L` as notation for `LSeries` and `↗f` as notation for `fun n : ℕ ↦ (f n : ℂ)`,
both scoped to `LSeries.notation`. The latter makes it convenient to use arithmetic functions
or Dirichlet characters (or anything that coerces to a function `N → R`, where `ℕ` coerces
to `N` and `R` coerces to `ℂ`) as arguments to `LSeries` etc.
## Reference
For some background on the design decisions made when implementing L-series in Mathlib
(and applications motivating the development), see the paper
[Formalizing zeta and L-functions in Lean](https://arxiv.org/abs/2503.00959)
by David Loeffler and Michael Stoll.
## Tags
L-series
-/
open Complex
/-!
### The terms of an L-series
We define the `n`th term evaluated at a complex number `s` of the L-series associated
to a sequence `f : ℕ → ℂ`, `LSeries.term f s n`, and provide some basic API.
We set `LSeries.term f s 0 = 0`, and for positive `n`, `LSeries.term f s n = f n / n ^ s`.
-/
namespace LSeries
/-- The `n`th term of the L-series of `f` evaluated at `s`. We set it to zero when `n = 0`. -/
noncomputable
def term (f : ℕ → ℂ) (s : ℂ) (n : ℕ) : ℂ :=
if n = 0 then 0 else f n / n ^ s
lemma term_def (f : ℕ → ℂ) (s : ℂ) (n : ℕ) :
term f s n = if n = 0 then 0 else f n / n ^ s :=
rfl
/-- An alternate spelling of `term_def` for the case `f 0 = 0`. -/
lemma term_def₀ {f : ℕ → ℂ} (hf : f 0 = 0) (s : ℂ) (n : ℕ) :
LSeries.term f s n = f n * (n : ℂ) ^ (-s) := by
rw [LSeries.term]
split_ifs with h <;> simp [h, hf, cpow_neg, div_eq_inv_mul, mul_comm]
@[simp]
lemma term_zero (f : ℕ → ℂ) (s : ℂ) : term f s 0 = 0 := rfl
-- We put `hn` first for convenience, so that we can write `rw [LSeries.term_of_ne_zero hn]` etc.
@[simp]
lemma term_of_ne_zero {n : ℕ} (hn : n ≠ 0) (f : ℕ → ℂ) (s : ℂ) :
term f s n = f n / n ^ s :=
if_neg hn
/--
If `s ≠ 0`, then the `if .. then .. else` construction in `LSeries.term` isn't needed, since
`0 ^ s = 0`.
-/
lemma term_of_ne_zero' {s : ℂ} (hs : s ≠ 0) (f : ℕ → ℂ) (n : ℕ) :
term f s n = f n / n ^ s := by
rcases eq_or_ne n 0 with rfl | hn
· rw [term_zero, Nat.cast_zero, zero_cpow hs, div_zero]
· rw [term_of_ne_zero hn]
lemma term_congr {f g : ℕ → ℂ} (h : ∀ {n}, n ≠ 0 → f n = g n) (s : ℂ) (n : ℕ) :
term f s n = term g s n := by
rcases eq_or_ne n 0 with hn | hn <;> simp [hn, h]
lemma pow_mul_term_eq (f : ℕ → ℂ) (s : ℂ) (n : ℕ) :
(n + 1) ^ s * term f s (n + 1) = f (n + 1) := by
simp [term, natCast_add_one_cpow_ne_zero n _, mul_div_assoc']
lemma norm_term_eq (f : ℕ → ℂ) (s : ℂ) (n : ℕ) :
‖term f s n‖ = if n = 0 then 0 else ‖f n‖ / n ^ s.re := by
rcases eq_or_ne n 0 with rfl | hn
· simp
· simp [hn, norm_natCast_cpow_of_pos <| Nat.pos_of_ne_zero hn]
lemma norm_term_le {f g : ℕ → ℂ} (s : ℂ) {n : ℕ} (h : ‖f n‖ ≤ ‖g n‖) :
‖term f s n‖ ≤ ‖term g s n‖ := by
simp only [norm_term_eq]
split
· rfl
· gcongr
lemma norm_term_le_of_re_le_re (f : ℕ → ℂ) {s s' : ℂ} (h : s.re ≤ s'.re) (n : ℕ) :
‖term f s' n‖ ≤ ‖term f s n‖ := by
simp only [norm_term_eq]
split
· next => rfl
· next hn => gcongr; exact Nat.one_le_cast.mpr <| Nat.one_le_iff_ne_zero.mpr hn
section positivity
open scoped ComplexOrder
lemma term_nonneg {a : ℕ → ℂ} {n : ℕ} (h : 0 ≤ a n) (x : ℝ) : 0 ≤ term a x n := by
rw [term_def]
split_ifs with hn
exacts [le_rfl, mul_nonneg h (inv_natCast_cpow_ofReal_pos hn x).le]
lemma term_pos {a : ℕ → ℂ} {n : ℕ} (hn : n ≠ 0) (h : 0 < a n) (x : ℝ) : 0 < term a x n := by
simpa only [term_of_ne_zero hn] using mul_pos h <| inv_natCast_cpow_ofReal_pos hn x
end positivity
end LSeries
/-!
### Definition of the L-series and related statements
We define `LSeries f s` of `f : ℕ → ℂ` as the sum over `LSeries.term f s`.
We also provide predicates `LSeriesSummable f s` stating that `LSeries f s` is summable
and `LSeriesHasSum f s a` stating that the L-series of `f` is summable at `s` and converges
to `a : ℂ`.
-/
open LSeries
/-- The value of the L-series of the sequence `f` at the point `s`
if it converges absolutely there, and `0` otherwise. -/
noncomputable
def LSeries (f : ℕ → ℂ) (s : ℂ) : ℂ :=
∑' n, term f s n
/-- Congruence for `LSeries` with the evaluation variable `s`. -/
lemma LSeries_congr {f g : ℕ → ℂ} (h : ∀ {n}, n ≠ 0 → f n = g n) (s : ℂ) :
LSeries f s = LSeries g s :=
tsum_congr <| term_congr h s
/-- `LSeriesSummable f s` indicates that the L-series of `f` converges absolutely at `s`. -/
def LSeriesSummable (f : ℕ → ℂ) (s : ℂ) : Prop :=
Summable (term f s)
lemma LSeriesSummable_congr {f g : ℕ → ℂ} (s : ℂ) (h : ∀ {n}, n ≠ 0 → f n = g n) :
LSeriesSummable f s ↔ LSeriesSummable g s :=
summable_congr <| term_congr h s
open Filter in
/-- If `f` and `g` agree on large `n : ℕ` and the `LSeries` of `f` converges at `s`,
then so does that of `g`. -/
lemma LSeriesSummable.congr' {f g : ℕ → ℂ} (s : ℂ) (h : f =ᶠ[atTop] g) (hf : LSeriesSummable f s) :
LSeriesSummable g s := by
rw [← Nat.cofinite_eq_atTop] at h
refine (summable_norm_iff.mpr hf).of_norm_bounded_eventually ?_
have : term f s =ᶠ[cofinite] term g s := by
rw [eventuallyEq_iff_exists_mem] at h ⊢
obtain ⟨S, hS, hS'⟩ := h
refine ⟨S \ {0}, diff_mem hS <| (Set.finite_singleton 0).compl_mem_cofinite, fun n hn ↦ ?_⟩
rw [Set.mem_diff, Set.mem_singleton_iff] at hn
simp [hn.2, hS' hn.1]
exact this.symm.mono fun n hn ↦ by simp [hn]
open Filter in
/-- If `f` and `g` agree on large `n : ℕ`, then the `LSeries` of `f` converges at `s`
if and only if that of `g` does. -/
lemma LSeriesSummable_congr' {f g : ℕ → ℂ} (s : ℂ) (h : f =ᶠ[atTop] g) :
LSeriesSummable f s ↔ LSeriesSummable g s :=
⟨fun H ↦ H.congr' s h, fun H ↦ H.congr' s h.symm⟩
theorem LSeries.eq_zero_of_not_LSeriesSummable (f : ℕ → ℂ) (s : ℂ) :
¬ LSeriesSummable f s → LSeries f s = 0 :=
tsum_eq_zero_of_not_summable
@[simp]
theorem LSeriesSummable_zero {s : ℂ} : LSeriesSummable 0 s := by
simp [LSeriesSummable, funext (term_def 0 s), summable_zero]
/-- This states that the L-series of the sequence `f` converges absolutely at `s` and that
the value there is `a`. -/
def LSeriesHasSum (f : ℕ → ℂ) (s a : ℂ) : Prop :=
HasSum (term f s) a
lemma LSeriesHasSum.LSeriesSummable {f : ℕ → ℂ} {s a : ℂ}
(h : LSeriesHasSum f s a) : LSeriesSummable f s :=
h.summable
lemma LSeriesHasSum.LSeries_eq {f : ℕ → ℂ} {s a : ℂ}
(h : LSeriesHasSum f s a) : LSeries f s = a :=
h.tsum_eq
lemma LSeriesSummable.LSeriesHasSum {f : ℕ → ℂ} {s : ℂ} (h : LSeriesSummable f s) :
LSeriesHasSum f s (LSeries f s) :=
h.hasSum
lemma LSeriesHasSum_iff {f : ℕ → ℂ} {s a : ℂ} :
LSeriesHasSum f s a ↔ LSeriesSummable f s ∧ LSeries f s = a :=
⟨fun H ↦ ⟨H.LSeriesSummable, H.LSeries_eq⟩, fun ⟨H₁, H₂⟩ ↦ H₂ ▸ H₁.LSeriesHasSum⟩
lemma LSeriesHasSum_congr {f g : ℕ → ℂ} (s a : ℂ) (h : ∀ {n}, n ≠ 0 → f n = g n) :
LSeriesHasSum f s a ↔ LSeriesHasSum g s a := by
simp [LSeriesHasSum_iff, LSeriesSummable_congr s h, LSeries_congr h s]
lemma LSeriesSummable.of_re_le_re {f : ℕ → ℂ} {s s' : ℂ} (h : s.re ≤ s'.re)
(hf : LSeriesSummable f s) : LSeriesSummable f s' := by
rw [LSeriesSummable, ← summable_norm_iff] at hf ⊢
exact hf.of_nonneg_of_le (fun _ ↦ norm_nonneg _) (norm_term_le_of_re_le_re f h)
theorem LSeriesSummable_iff_of_re_eq_re {f : ℕ → ℂ} {s s' : ℂ} (h : s.re = s'.re) :
LSeriesSummable f s ↔ LSeriesSummable f s' :=
⟨fun H ↦ H.of_re_le_re h.le, fun H ↦ H.of_re_le_re h.symm.le⟩
/-- The indicator function of `{1} ⊆ ℕ` with values in `ℂ`. -/
def LSeries.delta (n : ℕ) : ℂ :=
if n = 1 then 1 else 0
/-!
### Notation
-/
@[inherit_doc]
scoped[LSeries.notation] notation "L" => LSeries
/-- We introduce notation `↗f` for `f` interpreted as a function `ℕ → ℂ`.
Let `R` be a ring with a coercion to `ℂ`. Then we can write `↗χ` when `χ : DirichletCharacter R`
or `↗f` when `f : ArithmeticFunction R` or simply `f : N → R` with a coercion from `ℕ` to `N`
as an argument to `LSeries`, `LSeriesHasSum`, `LSeriesSummable` etc. -/
scoped[LSeries.notation] notation:max "↗" f:max => fun n : ℕ ↦ (f n : ℂ)
@[inherit_doc]
scoped[LSeries.notation] notation "δ" => delta
/-!
### LSeries of 0 and δ
-/
@[simp]
lemma LSeries_zero : LSeries 0 = 0 := by
ext
simp [LSeries, LSeries.term]
section delta
open scoped LSeries.notation
namespace LSeries
open Nat Complex
lemma term_delta (s : ℂ) (n : ℕ) : term δ s n = if n = 1 then 1 else 0 := by
rcases eq_or_ne n 0 with rfl | hn
· simp
· rcases eq_or_ne n 1 with hn' | hn' <;>
simp [hn, hn', delta]
lemma mul_delta_eq_smul_delta {f : ℕ → ℂ} : f * δ = f 1 • δ := by
ext n
by_cases hn : n = 1 <;>
simp [hn, delta]
lemma mul_delta {f : ℕ → ℂ} (h : f 1 = 1) : f * δ = δ := by
rw [mul_delta_eq_smul_delta, h, one_smul]
lemma delta_mul_eq_smul_delta {f : ℕ → ℂ} : δ * f = f 1 • δ :=
mul_comm δ f ▸ mul_delta_eq_smul_delta
lemma delta_mul {f : ℕ → ℂ} (h : f 1 = 1) : δ * f = δ :=
mul_comm δ f ▸ mul_delta h
end LSeries
/-- The L-series of `δ` is the constant function `1`. -/
lemma LSeries_delta : LSeries δ = 1 := by
ext
simp [LSeries, LSeries.term_delta]
end delta
/-!
### Criteria for and consequences of summability of L-series
We relate summability of L-series with bounds on the coefficients in terms of powers of `n`.
-/
/-- If the `LSeries` of `f` is summable at `s`, then `f n` is bounded in absolute value
by a constant times `n^(re s)`. -/
lemma LSeriesSummable.le_const_mul_rpow {f : ℕ → ℂ} {s : ℂ} (h : LSeriesSummable f s) :
∃ C, ∀ n ≠ 0, ‖f n‖ ≤ C * n ^ s.re := by
replace h := h.norm
by_contra! H
obtain ⟨n, hn₀, hn⟩ := H (tsum fun n ↦ ‖term f s n‖)
have := h.le_tsum n fun _ _ ↦ norm_nonneg _
rw [norm_term_eq, if_neg hn₀,
div_le_iff₀ <| Real.rpow_pos_of_pos (Nat.cast_pos.mpr <| Nat.pos_of_ne_zero hn₀) _] at this
exact (this.trans_lt hn).false.elim
open Filter in
/-- If the `LSeries` of `f` is summable at `s`, then `f = O(n^(re s))`. -/
lemma LSeriesSummable.isBigO_rpow {f : ℕ → ℂ} {s : ℂ} (h : LSeriesSummable f s) :
f =O[atTop] fun n ↦ (n : ℝ) ^ s.re := by
obtain ⟨C, hC⟩ := h.le_const_mul_rpow
refine Asymptotics.IsBigO.of_bound C <| eventually_atTop.mpr ⟨1, fun n hn ↦ ?_⟩
convert hC n (Nat.pos_iff_ne_zero.mp hn) using 2
rw [Real.norm_eq_abs, Real.abs_rpow_of_nonneg n.cast_nonneg, abs_of_nonneg n.cast_nonneg]
/-- If `f n` is bounded in absolute value by a constant times `n^(x-1)` and `re s > x`,
then the `LSeries` of `f` is summable at `s`. -/
lemma LSeriesSummable_of_le_const_mul_rpow {f : ℕ → ℂ} {x : ℝ} {s : ℂ} (hs : x < s.re)
(h : ∃ C, ∀ n ≠ 0, ‖f n‖ ≤ C * n ^ (x - 1)) :
LSeriesSummable f s := by
obtain ⟨C, hC⟩ := h
have hC₀ : 0 ≤ C := (norm_nonneg <| f 1).trans <| by simpa using hC 1 one_ne_zero
have hsum : Summable fun n : ℕ ↦ ‖(C : ℂ) / n ^ (s + (1 - x))‖ := by
simp_rw [div_eq_mul_inv, norm_mul, ← cpow_neg]
have hsx : -s.re + x - 1 < -1 := by linarith only [hs]
refine Summable.mul_left _ <|
Summable.of_norm_bounded_eventually_nat (g := fun n ↦ (n : ℝ) ^ (-s.re + x - 1)) ?_ ?_
· simpa
· simp only [norm_norm, Filter.eventually_atTop]
refine ⟨1, fun n hn ↦ le_of_eq ?_⟩
simp only [norm_natCast_cpow_of_pos hn, add_re, sub_re, neg_re, ofReal_re, one_re]
ring_nf
refine Summable.of_norm <| hsum.of_nonneg_of_le (fun _ ↦ norm_nonneg _) (fun n ↦ ?_)
rcases n.eq_zero_or_pos with rfl | hn
· simpa only [term_zero, norm_zero] using norm_nonneg _
have hn' : 0 < (n : ℝ) ^ s.re := Real.rpow_pos_of_pos (Nat.cast_pos.mpr hn) _
simp_rw [term_of_ne_zero hn.ne', norm_div, norm_natCast_cpow_of_pos hn, div_le_iff₀ hn',
norm_real, Real.norm_of_nonneg hC₀, div_eq_mul_inv, mul_assoc,
← Real.rpow_neg <| Nat.cast_nonneg _, ← Real.rpow_add <| Nat.cast_pos.mpr hn]
simpa using hC n <| Nat.pos_iff_ne_zero.mp hn
open Filter Finset Real Nat in
/-- If `f = O(n^(x-1))` and `re s > x`, then the `LSeries` of `f` is summable at `s`. -/
lemma LSeriesSummable_of_isBigO_rpow {f : ℕ → ℂ} {x : ℝ} {s : ℂ} (hs : x < s.re)
(h : f =O[atTop] fun n ↦ (n : ℝ) ^ (x - 1)) :
LSeriesSummable f s := by
obtain ⟨C, hC⟩ := Asymptotics.isBigO_iff.mp h
obtain ⟨m, hm⟩ := eventually_atTop.mp hC
let C' := max C (max' (insert 0 (image (fun n : ℕ ↦ ‖f n‖ / (n : ℝ) ^ (x - 1)) (range m)))
(insert_nonempty 0 _))
have hC'₀ : 0 ≤ C' := (le_max' _ _ (mem_insert.mpr (Or.inl rfl))).trans <| le_max_right ..
have hCC' : C ≤ C' := le_max_left ..
refine LSeriesSummable_of_le_const_mul_rpow hs ⟨C', fun n hn₀ ↦ ?_⟩
rcases le_or_gt m n with hn | hn
· refine (hm n hn).trans ?_
have hn₀ : (0 : ℝ) ≤ n := cast_nonneg _
gcongr
rw [Real.norm_eq_abs, abs_rpow_of_nonneg hn₀, abs_of_nonneg hn₀]
· have hn' : 0 < n := Nat.pos_of_ne_zero hn₀
refine (div_le_iff₀ <| rpow_pos_of_pos (cast_pos.mpr hn') _).mp ?_
refine (le_max' _ _ <| mem_insert_of_mem ?_).trans <| le_max_right ..
exact mem_image.mpr ⟨n, mem_range.mpr hn, rfl⟩
/-- If `f` is bounded, then its `LSeries` is summable at `s` when `re s > 1`. -/
theorem LSeriesSummable_of_bounded_of_one_lt_re {f : ℕ → ℂ} {m : ℝ}
(h : ∀ n ≠ 0, ‖f n‖ ≤ m) {s : ℂ} (hs : 1 < s.re) :
LSeriesSummable f s :=
LSeriesSummable_of_le_const_mul_rpow hs ⟨m, fun n hn ↦ by simp [h n hn]⟩
/-- If `f` is bounded, then its `LSeries` is summable at `s : ℝ` when `s > 1`. -/
theorem LSeriesSummable_of_bounded_of_one_lt_real {f : ℕ → ℂ} {m : ℝ}
(h : ∀ n ≠ 0, ‖f n‖ ≤ m) {s : ℝ} (hs : 1 < s) :
LSeriesSummable f s :=
LSeriesSummable_of_bounded_of_one_lt_re h <| by simp [hs] |
.lake/packages/mathlib/Mathlib/NumberTheory/LSeries/HurwitzZetaEven.lean | import Mathlib.NumberTheory.LSeries.AbstractFuncEq
import Mathlib.NumberTheory.ModularForms.JacobiTheta.Bounds
import Mathlib.Analysis.SpecialFunctions.Gamma.Deligne
import Mathlib.NumberTheory.LSeries.MellinEqDirichlet
import Mathlib.NumberTheory.LSeries.Basic
import Mathlib.Analysis.Complex.RemovableSingularity
/-!
# Even Hurwitz zeta functions
In this file we study the functions on `ℂ` which are the meromorphic continuation of the following
series (convergent for `1 < re s`), where `a ∈ ℝ` is a parameter:
`hurwitzZetaEven a s = 1 / 2 * ∑' n : ℤ, 1 / |n + a| ^ s`
and
`cosZeta a s = ∑' n : ℕ, cos (2 * π * a * n) / |n| ^ s`.
Note that the term for `n = -a` in the first sum is omitted if `a` is an integer, and the term for
`n = 0` is omitted in the second sum (always).
Of course, we cannot *define* these functions by the above formulae (since existence of the
meromorphic continuation is not at all obvious); we in fact construct them as Mellin transforms of
various versions of the Jacobi theta function.
We also define completed versions of these functions with nicer functional equations (satisfying
`completedHurwitzZetaEven a s = Gammaℝ s * hurwitzZetaEven a s`, and similarly for `cosZeta`); and
modified versions with a subscript `0`, which are entire functions differing from the above by
multiples of `1 / s` and `1 / (1 - s)`.
## Main definitions and theorems
* `hurwitzZetaEven` and `cosZeta`: the zeta functions
* `completedHurwitzZetaEven` and `completedCosZeta`: completed variants
* `differentiableAt_hurwitzZetaEven` and `differentiableAt_cosZeta`:
differentiability away from `s = 1`
* `completedHurwitzZetaEven_one_sub`: the functional equation
`completedHurwitzZetaEven a (1 - s) = completedCosZeta a s`
* `hasSum_int_hurwitzZetaEven` and `hasSum_nat_cosZeta`: relation between the zeta functions and
the corresponding Dirichlet series for `1 < re s`.
-/
noncomputable section
open Complex Filter Topology Asymptotics Real Set MeasureTheory
namespace HurwitzZeta
section kernel_defs
/-!
## Definitions and elementary properties of kernels
-/
/-- Even Hurwitz zeta kernel (function whose Mellin transform will be the even part of the
completed Hurwitz zeta function). See `evenKernel_def` for the defining formula, and
`hasSum_int_evenKernel` for an expression as a sum over `ℤ`. -/
@[irreducible] def evenKernel (a : UnitAddCircle) (x : ℝ) : ℝ :=
(show Function.Periodic
(fun ξ : ℝ ↦ rexp (-π * ξ ^ 2 * x) * re (jacobiTheta₂ (ξ * I * x) (I * x))) 1 by
intro ξ
simp only [ofReal_add, ofReal_one, add_mul, one_mul, jacobiTheta₂_add_left']
have : cexp (-↑π * I * ((I * ↑x) + 2 * (↑ξ * I * ↑x))) = rexp (π * (x + 2 * ξ * x)) := by
ring_nf
simp [I_sq]
rw [this, re_ofReal_mul, ← mul_assoc, ← Real.exp_add]
congr
ring).lift a
lemma evenKernel_def (a x : ℝ) :
↑(evenKernel ↑a x) = cexp (-π * a ^ 2 * x) * jacobiTheta₂ (a * I * x) (I * x) := by
simp [evenKernel, re_eq_add_conj, jacobiTheta₂_conj, ← mul_two,
mul_div_cancel_right₀ _ (two_ne_zero' ℂ)]
/-- For `x ≤ 0` the defining sum diverges, so the kernel is 0. -/
lemma evenKernel_undef (a : UnitAddCircle) {x : ℝ} (hx : x ≤ 0) : evenKernel a x = 0 := by
induction a using QuotientAddGroup.induction_on with
| H a' => simp [← ofReal_inj, evenKernel_def, jacobiTheta₂_undef _ (by simpa : (I * ↑x).im ≤ 0)]
/-- Cosine Hurwitz zeta kernel. See `cosKernel_def` for the defining formula, and
`hasSum_int_cosKernel` for expression as a sum. -/
@[irreducible] def cosKernel (a : UnitAddCircle) (x : ℝ) : ℝ :=
(show Function.Periodic (fun ξ : ℝ ↦ re (jacobiTheta₂ ξ (I * x))) 1 by
intro ξ; simp [jacobiTheta₂_add_left]).lift a
lemma cosKernel_def (a x : ℝ) : ↑(cosKernel ↑a x) = jacobiTheta₂ a (I * x) := by
simp [cosKernel, re_eq_add_conj, jacobiTheta₂_conj, ← mul_two,
mul_div_cancel_right₀ _ (two_ne_zero' ℂ)]
lemma cosKernel_undef (a : UnitAddCircle) {x : ℝ} (hx : x ≤ 0) : cosKernel a x = 0 := by
induction a using QuotientAddGroup.induction_on with
| H => simp [← ofReal_inj, cosKernel_def, jacobiTheta₂_undef _ (by simpa : (I * ↑x).im ≤ 0)]
/-- For `a = 0`, both kernels agree. -/
lemma evenKernel_eq_cosKernel_of_zero : evenKernel 0 = cosKernel 0 := by
ext1 x
simp [← QuotientAddGroup.mk_zero, ← ofReal_inj, evenKernel_def, cosKernel_def]
@[simp]
lemma evenKernel_neg (a : UnitAddCircle) (x : ℝ) : evenKernel (-a) x = evenKernel a x := by
induction a using QuotientAddGroup.induction_on with
| H => simp [← QuotientAddGroup.mk_neg, ← ofReal_inj, evenKernel_def, jacobiTheta₂_neg_left]
@[simp]
lemma cosKernel_neg (a : UnitAddCircle) (x : ℝ) : cosKernel (-a) x = cosKernel a x := by
induction a using QuotientAddGroup.induction_on with
| H => simp [← QuotientAddGroup.mk_neg, ← ofReal_inj, cosKernel_def]
lemma continuousOn_evenKernel (a : UnitAddCircle) : ContinuousOn (evenKernel a) (Ioi 0) := by
induction a using QuotientAddGroup.induction_on with | H a' =>
apply continuous_re.comp_continuousOn (f := fun x ↦ (evenKernel a' x : ℂ))
simp only [evenKernel_def]
refine continuousOn_of_forall_continuousAt (fun x hx ↦ .mul (by fun_prop) ?_)
exact (continuousAt_jacobiTheta₂ (a' * I * x) <| by simpa).comp
(f := fun u : ℝ ↦ (a' * I * u, I * u)) (by fun_prop)
lemma continuousOn_cosKernel (a : UnitAddCircle) : ContinuousOn (cosKernel a) (Ioi 0) := by
induction a using QuotientAddGroup.induction_on with | H a' =>
apply continuous_re.comp_continuousOn (f := fun x ↦ (cosKernel a' x : ℂ))
simp only [cosKernel_def]
refine continuousOn_of_forall_continuousAt (fun x hx ↦ ?_)
exact (continuousAt_jacobiTheta₂ a' <| by simpa).comp
(f := fun u : ℝ ↦ ((a' : ℂ), I * u)) (by fun_prop)
lemma evenKernel_functional_equation (a : UnitAddCircle) (x : ℝ) :
evenKernel a x = 1 / x ^ (1 / 2 : ℝ) * cosKernel a (1 / x) := by
rcases le_or_gt x 0 with hx | hx
· rw [evenKernel_undef _ hx, cosKernel_undef, mul_zero]
exact div_nonpos_of_nonneg_of_nonpos zero_le_one hx
induction a using QuotientAddGroup.induction_on with | H a =>
rw [← ofReal_inj, ofReal_mul, evenKernel_def, cosKernel_def, jacobiTheta₂_functional_equation]
have h1 : I * ↑(1 / x) = -1 / (I * x) := by
push_cast
rw [← div_div, mul_one_div, div_I, neg_one_mul, neg_neg]
have hx' : I * x ≠ 0 := mul_ne_zero I_ne_zero (ofReal_ne_zero.mpr hx.ne')
have h2 : a * I * x / (I * x) = a := by
rw [div_eq_iff hx']
ring
have h3 : 1 / (-I * (I * x)) ^ (1 / 2 : ℂ) = 1 / ↑(x ^ (1 / 2 : ℝ)) := by
rw [neg_mul, ← mul_assoc, I_mul_I, neg_one_mul, neg_neg,ofReal_cpow hx.le, ofReal_div,
ofReal_one, ofReal_ofNat]
have h4 : -π * I * (a * I * x) ^ 2 / (I * x) = - (-π * a ^ 2 * x) := by
rw [mul_pow, mul_pow, I_sq, div_eq_iff hx']
ring
rw [h1, h2, h3, h4, ← mul_assoc, mul_comm (cexp _), mul_assoc _ (cexp _) (cexp _),
← Complex.exp_add, neg_add_cancel, Complex.exp_zero, mul_one, ofReal_div, ofReal_one]
end kernel_defs
section asymp
/-!
## Formulae for the kernels as sums
-/
lemma hasSum_int_evenKernel (a : ℝ) {t : ℝ} (ht : 0 < t) :
HasSum (fun n : ℤ ↦ rexp (-π * (n + a) ^ 2 * t)) (evenKernel a t) := by
rw [← hasSum_ofReal, evenKernel_def]
have (n : ℤ) : cexp (-(π * (n + a) ^ 2 * t)) = cexp (-(π * a ^ 2 * t)) *
jacobiTheta₂_term n (a * I * t) (I * t) := by
rw [jacobiTheta₂_term, ← Complex.exp_add]
ring_nf
simp
simpa [this] using (hasSum_jacobiTheta₂_term _ (by simpa)).mul_left _
lemma hasSum_int_cosKernel (a : ℝ) {t : ℝ} (ht : 0 < t) :
HasSum (fun n : ℤ ↦ cexp (2 * π * I * a * n) * rexp (-π * n ^ 2 * t)) ↑(cosKernel a t) := by
rw [cosKernel_def a t]
have (n : ℤ) : cexp (2 * π * I * a * n) * cexp (-(π * n ^ 2 * t)) =
jacobiTheta₂_term n a (I * ↑t) := by
rw [jacobiTheta₂_term, ← Complex.exp_add]
ring_nf
simp [sub_eq_add_neg]
simpa [this] using hasSum_jacobiTheta₂_term _ (by simpa)
/-- Modified version of `hasSum_int_evenKernel` omitting the constant term at `∞`. -/
lemma hasSum_int_evenKernel₀ (a : ℝ) {t : ℝ} (ht : 0 < t) :
HasSum (fun n : ℤ ↦ if n + a = 0 then 0 else rexp (-π * (n + a) ^ 2 * t))
(evenKernel a t - if (a : UnitAddCircle) = 0 then 1 else 0) := by
haveI := Classical.propDecidable -- speed up instance search for `if / then / else`
simp_rw [AddCircle.coe_eq_zero_iff, zsmul_one]
split_ifs with h
· obtain ⟨k, rfl⟩ := h
simpa [← Int.cast_add, add_eq_zero_iff_eq_neg]
using hasSum_ite_sub_hasSum (hasSum_int_evenKernel (k : ℝ) ht) (-k)
· suffices ∀ (n : ℤ), n + a ≠ 0 by simpa [this] using hasSum_int_evenKernel a ht
contrapose! h
let ⟨n, hn⟩ := h
exact ⟨-n, by simpa [neg_eq_iff_add_eq_zero]⟩
lemma hasSum_int_cosKernel₀ (a : ℝ) {t : ℝ} (ht : 0 < t) :
HasSum (fun n : ℤ ↦ if n = 0 then 0 else cexp (2 * π * I * a * n) * rexp (-π * n ^ 2 * t))
(↑(cosKernel a t) - 1) := by
simpa using hasSum_ite_sub_hasSum (hasSum_int_cosKernel a ht) 0
lemma hasSum_nat_cosKernel₀ (a : ℝ) {t : ℝ} (ht : 0 < t) :
HasSum (fun n : ℕ ↦ 2 * Real.cos (2 * π * a * (n + 1)) * rexp (-π * (n + 1) ^ 2 * t))
(cosKernel a t - 1) := by
rw [← hasSum_ofReal, ofReal_sub, ofReal_one]
have := (hasSum_int_cosKernel a ht).nat_add_neg
rw [← hasSum_nat_add_iff' 1] at this
simp_rw [Finset.sum_range_one, Nat.cast_zero, neg_zero, Int.cast_zero, zero_pow two_ne_zero,
mul_zero, zero_mul, Complex.exp_zero, Real.exp_zero, ofReal_one, mul_one, Int.cast_neg,
Int.cast_natCast, neg_sq, ← add_mul, add_sub_assoc, ← sub_sub, sub_self, zero_sub,
← sub_eq_add_neg, mul_neg] at this
refine this.congr_fun fun n ↦ ?_
push_cast
rw [Complex.cos, mul_div_cancel₀ _ two_ne_zero]
congr 3 <;> ring
/-!
## Asymptotics of the kernels as `t → ∞`
-/
/-- The function `evenKernel a - L` has exponential decay at `+∞`, where `L = 1` if
`a = 0` and `L = 0` otherwise. -/
lemma isBigO_atTop_evenKernel_sub (a : UnitAddCircle) : ∃ p : ℝ, 0 < p ∧
(evenKernel a · - (if a = 0 then 1 else 0)) =O[atTop] (rexp <| -p * ·) := by
induction a using QuotientAddGroup.induction_on with | H b =>
obtain ⟨p, hp, hp'⟩ := HurwitzKernelBounds.isBigO_atTop_F_int_zero_sub b
refine ⟨p, hp, (EventuallyEq.isBigO ?_).trans hp'⟩
filter_upwards [eventually_gt_atTop 0] with t h
simp [← (hasSum_int_evenKernel b h).tsum_eq, HurwitzKernelBounds.F_int, HurwitzKernelBounds.f_int]
/-- The function `cosKernel a - 1` has exponential decay at `+∞`, for any `a`. -/
lemma isBigO_atTop_cosKernel_sub (a : UnitAddCircle) :
∃ p, 0 < p ∧ IsBigO atTop (cosKernel a · - 1) (fun x ↦ Real.exp (-p * x)) := by
induction a using QuotientAddGroup.induction_on with | H a =>
obtain ⟨p, hp, hp'⟩ := HurwitzKernelBounds.isBigO_atTop_F_nat_zero_sub zero_le_one
refine ⟨p, hp, (Eventually.isBigO ?_).trans (hp'.const_mul_left 2)⟩
filter_upwards [eventually_gt_atTop 0] with t ht
simp only [eq_false_intro one_ne_zero, if_false, sub_zero,
← (hasSum_nat_cosKernel₀ a ht).tsum_eq, HurwitzKernelBounds.F_nat]
apply tsum_of_norm_bounded ((HurwitzKernelBounds.summable_f_nat 0 1 ht).hasSum.mul_left 2)
intro n
rw [norm_mul, norm_mul, norm_two, mul_assoc, mul_le_mul_iff_of_pos_left two_pos,
norm_of_nonneg (exp_pos _).le, HurwitzKernelBounds.f_nat, pow_zero, one_mul, Real.norm_eq_abs]
exact mul_le_of_le_one_left (exp_pos _).le (abs_cos_le_one _)
end asymp
section FEPair
/-!
## Construction of a FE-pair
-/
/-- A `WeakFEPair` structure with `f = evenKernel a` and `g = cosKernel a`. -/
def hurwitzEvenFEPair (a : UnitAddCircle) : WeakFEPair ℂ where
f := ofReal ∘ evenKernel a
g := ofReal ∘ cosKernel a
hf_int := (continuous_ofReal.comp_continuousOn (continuousOn_evenKernel a)).locallyIntegrableOn
measurableSet_Ioi
hg_int := (continuous_ofReal.comp_continuousOn (continuousOn_cosKernel a)).locallyIntegrableOn
measurableSet_Ioi
k := 1 / 2
hk := one_half_pos
ε := 1
hε := one_ne_zero
f₀ := if a = 0 then 1 else 0
hf_top r := by
let ⟨v, hv, hv'⟩ := isBigO_atTop_evenKernel_sub a
rw [← isBigO_norm_left] at hv' ⊢
conv at hv' =>
enter [2, x]; rw [← norm_real, ofReal_sub, apply_ite ((↑) : ℝ → ℂ), ofReal_one, ofReal_zero]
exact hv'.trans (isLittleO_exp_neg_mul_rpow_atTop hv _).isBigO
g₀ := 1
hg_top r := by
obtain ⟨p, hp, hp'⟩ := isBigO_atTop_cosKernel_sub a
simpa using isBigO_ofReal_left.mpr <| hp'.trans (isLittleO_exp_neg_mul_rpow_atTop hp r).isBigO
h_feq x hx := by simp [← ofReal_mul, evenKernel_functional_equation, inv_rpow (le_of_lt hx)]
@[simp]
lemma hurwitzEvenFEPair_zero_symm :
(hurwitzEvenFEPair 0).symm = hurwitzEvenFEPair 0 := by
unfold hurwitzEvenFEPair WeakFEPair.symm
congr 1 <;> simp [evenKernel_eq_cosKernel_of_zero]
@[simp]
lemma hurwitzEvenFEPair_neg (a : UnitAddCircle) : hurwitzEvenFEPair (-a) = hurwitzEvenFEPair a := by
unfold hurwitzEvenFEPair
congr 1 <;> simp [Function.comp_def]
/-!
## Definition of the completed even Hurwitz zeta function
-/
/--
The meromorphic function of `s` which agrees with
`1 / 2 * Gamma (s / 2) * π ^ (-s / 2) * ∑' (n : ℤ), 1 / |n + a| ^ s` for `1 < re s`.
-/
def completedHurwitzZetaEven (a : UnitAddCircle) (s : ℂ) : ℂ :=
((hurwitzEvenFEPair a).Λ (s / 2)) / 2
/-- The entire function differing from `completedHurwitzZetaEven a s` by a linear combination of
`1 / s` and `1 / (1 - s)`. -/
def completedHurwitzZetaEven₀ (a : UnitAddCircle) (s : ℂ) : ℂ :=
((hurwitzEvenFEPair a).Λ₀ (s / 2)) / 2
lemma completedHurwitzZetaEven_eq (a : UnitAddCircle) (s : ℂ) :
completedHurwitzZetaEven a s =
completedHurwitzZetaEven₀ a s - (if a = 0 then 1 else 0) / s - 1 / (1 - s) := by
rw [completedHurwitzZetaEven, WeakFEPair.Λ, sub_div, sub_div]
congr 1
· change completedHurwitzZetaEven₀ a s - (1 / (s / 2)) • (if a = 0 then 1 else 0) / 2 =
completedHurwitzZetaEven₀ a s - (if a = 0 then 1 else 0) / s
rw [smul_eq_mul, mul_comm, mul_div_assoc, div_div, div_mul_cancel₀ _ two_ne_zero, mul_one_div]
· change (1 / (↑(1 / 2 : ℝ) - s / 2)) • 1 / 2 = 1 / (1 - s)
push_cast
rw [smul_eq_mul, mul_one, ← sub_div, div_div, div_mul_cancel₀ _ two_ne_zero]
/--
The meromorphic function of `s` which agrees with
`Gamma (s / 2) * π ^ (-s / 2) * ∑' n : ℕ, cos (2 * π * a * n) / n ^ s` for `1 < re s`.
-/
def completedCosZeta (a : UnitAddCircle) (s : ℂ) : ℂ :=
((hurwitzEvenFEPair a).symm.Λ (s / 2)) / 2
/-- The entire function differing from `completedCosZeta a s` by a linear combination of
`1 / s` and `1 / (1 - s)`. -/
def completedCosZeta₀ (a : UnitAddCircle) (s : ℂ) : ℂ :=
((hurwitzEvenFEPair a).symm.Λ₀ (s / 2)) / 2
lemma completedCosZeta_eq (a : UnitAddCircle) (s : ℂ) :
completedCosZeta a s =
completedCosZeta₀ a s - 1 / s - (if a = 0 then 1 else 0) / (1 - s) := by
rw [completedCosZeta, WeakFEPair.Λ, sub_div, sub_div]
congr 1
· rw [completedCosZeta₀, WeakFEPair.symm, hurwitzEvenFEPair, smul_eq_mul, mul_one, div_div,
div_mul_cancel₀ _ (two_ne_zero' ℂ)]
· simp_rw [WeakFEPair.symm, hurwitzEvenFEPair, push_cast, inv_one, smul_eq_mul,
mul_comm _ (if _ then _ else _), mul_div_assoc, div_div, ← sub_div,
div_mul_cancel₀ _ (two_ne_zero' ℂ), mul_one_div]
/-!
## Parity and functional equations
-/
@[simp]
lemma completedHurwitzZetaEven_neg (a : UnitAddCircle) (s : ℂ) :
completedHurwitzZetaEven (-a) s = completedHurwitzZetaEven a s := by
simp [completedHurwitzZetaEven]
@[simp]
lemma completedHurwitzZetaEven₀_neg (a : UnitAddCircle) (s : ℂ) :
completedHurwitzZetaEven₀ (-a) s = completedHurwitzZetaEven₀ a s := by
simp [completedHurwitzZetaEven₀]
@[simp]
lemma completedCosZeta_neg (a : UnitAddCircle) (s : ℂ) :
completedCosZeta (-a) s = completedCosZeta a s := by
simp [completedCosZeta]
@[simp]
lemma completedCosZeta₀_neg (a : UnitAddCircle) (s : ℂ) :
completedCosZeta₀ (-a) s = completedCosZeta₀ a s := by
simp [completedCosZeta₀]
/-- Functional equation for the even Hurwitz zeta function. -/
lemma completedHurwitzZetaEven_one_sub (a : UnitAddCircle) (s : ℂ) :
completedHurwitzZetaEven a (1 - s) = completedCosZeta a s := by
rw [completedHurwitzZetaEven, completedCosZeta, sub_div,
(by simp : (1 / 2 : ℂ) = ↑(1 / 2 : ℝ)),
(by rfl : (1 / 2 : ℝ) = (hurwitzEvenFEPair a).k),
(hurwitzEvenFEPair a).functional_equation (s / 2),
(by rfl : (hurwitzEvenFEPair a).ε = 1),
one_smul]
/-- Functional equation for the even Hurwitz zeta function with poles removed. -/
lemma completedHurwitzZetaEven₀_one_sub (a : UnitAddCircle) (s : ℂ) :
completedHurwitzZetaEven₀ a (1 - s) = completedCosZeta₀ a s := by
rw [completedHurwitzZetaEven₀, completedCosZeta₀, sub_div,
(by simp : (1 / 2 : ℂ) = ↑(1 / 2 : ℝ)),
(by rfl : (1 / 2 : ℝ) = (hurwitzEvenFEPair a).k),
(hurwitzEvenFEPair a).functional_equation₀ (s / 2),
(by rfl : (hurwitzEvenFEPair a).ε = 1),
one_smul]
/-- Functional equation for the even Hurwitz zeta function (alternative form). -/
lemma completedCosZeta_one_sub (a : UnitAddCircle) (s : ℂ) :
completedCosZeta a (1 - s) = completedHurwitzZetaEven a s := by
rw [← completedHurwitzZetaEven_one_sub, sub_sub_cancel]
/-- Functional equation for the even Hurwitz zeta function with poles removed (alternative form). -/
lemma completedCosZeta₀_one_sub (a : UnitAddCircle) (s : ℂ) :
completedCosZeta₀ a (1 - s) = completedHurwitzZetaEven₀ a s := by
rw [← completedHurwitzZetaEven₀_one_sub, sub_sub_cancel]
end FEPair
/-!
## Differentiability and residues
-/
section FEPair
/--
The even Hurwitz completed zeta is differentiable away from `s = 0` and `s = 1` (and also at
`s = 0` if `a ≠ 0`)
-/
lemma differentiableAt_completedHurwitzZetaEven
(a : UnitAddCircle) {s : ℂ} (hs : s ≠ 0 ∨ a ≠ 0) (hs' : s ≠ 1) :
DifferentiableAt ℂ (completedHurwitzZetaEven a) s := by
refine (((hurwitzEvenFEPair a).differentiableAt_Λ ?_ (Or.inl ?_)).comp s
(differentiableAt_id.div_const _)).div_const _
· rcases hs with h | h <;>
simp [hurwitzEvenFEPair, h]
· change s / 2 ≠ ↑(1 / 2 : ℝ)
rw [ofReal_div, ofReal_one, ofReal_ofNat]
exact hs' ∘ (div_left_inj' two_ne_zero).mp
lemma differentiable_completedHurwitzZetaEven₀ (a : UnitAddCircle) :
Differentiable ℂ (completedHurwitzZetaEven₀ a) :=
((hurwitzEvenFEPair a).differentiable_Λ₀.comp (differentiable_id.div_const _)).div_const _
/-- The difference of two completed even Hurwitz zeta functions is differentiable at `s = 1`. -/
lemma differentiableAt_one_completedHurwitzZetaEven_sub_completedHurwitzZetaEven
(a b : UnitAddCircle) :
DifferentiableAt ℂ (fun s ↦ completedHurwitzZetaEven a s - completedHurwitzZetaEven b s) 1 := by
have (s : _) : completedHurwitzZetaEven a s - completedHurwitzZetaEven b s =
completedHurwitzZetaEven₀ a s - completedHurwitzZetaEven₀ b s -
((if a = 0 then 1 else 0) - (if b = 0 then 1 else 0)) / s := by
simp_rw [completedHurwitzZetaEven_eq, sub_div]
abel
rw [funext this]
refine .sub ?_ <| (differentiable_const _ _).div (differentiable_id _) one_ne_zero
apply DifferentiableAt.sub <;> apply differentiable_completedHurwitzZetaEven₀
lemma differentiableAt_completedCosZeta
(a : UnitAddCircle) {s : ℂ} (hs : s ≠ 0) (hs' : s ≠ 1 ∨ a ≠ 0) :
DifferentiableAt ℂ (completedCosZeta a) s := by
refine (((hurwitzEvenFEPair a).symm.differentiableAt_Λ (Or.inl ?_) ?_).comp s
(differentiableAt_id.div_const _)).div_const _
· exact div_ne_zero_iff.mpr ⟨hs, two_ne_zero⟩
· change s / 2 ≠ ↑(1 / 2 : ℝ) ∨ (if a = 0 then 1 else 0) = 0
refine Or.imp (fun h ↦ ?_) (fun ha ↦ ?_) hs'
· simpa [push_cast] using h ∘ (div_left_inj' two_ne_zero).mp
· simpa
lemma differentiable_completedCosZeta₀ (a : UnitAddCircle) :
Differentiable ℂ (completedCosZeta₀ a) :=
((hurwitzEvenFEPair a).symm.differentiable_Λ₀.comp (differentiable_id.div_const _)).div_const _
private lemma tendsto_div_two_punctured_nhds (a : ℂ) :
Tendsto (fun s : ℂ ↦ s / 2) (𝓝[≠] a) (𝓝[≠] (a / 2)) :=
le_of_eq ((Homeomorph.mulRight₀ _ (inv_ne_zero (two_ne_zero' ℂ))).map_punctured_nhds_eq a)
/-- The residue of `completedHurwitzZetaEven a s` at `s = 1` is equal to `1`. -/
lemma completedHurwitzZetaEven_residue_one (a : UnitAddCircle) :
Tendsto (fun s ↦ (s - 1) * completedHurwitzZetaEven a s) (𝓝[≠] 1) (𝓝 1) := by
have h1 : Tendsto (fun s : ℂ ↦ (s - ↑(1 / 2 : ℝ)) * _) (𝓝[≠] ↑(1 / 2 : ℝ))
(𝓝 ((1 : ℂ) * (1 : ℂ))) := (hurwitzEvenFEPair a).Λ_residue_k
simp only [push_cast, one_mul] at h1
refine (h1.comp <| tendsto_div_two_punctured_nhds 1).congr (fun s ↦ ?_)
rw [completedHurwitzZetaEven, Function.comp_apply, ← sub_div, div_mul_eq_mul_div, mul_div_assoc]
/-- The residue of `completedHurwitzZetaEven a s` at `s = 0` is equal to `-1` if `a = 0`, and `0`
otherwise. -/
lemma completedHurwitzZetaEven_residue_zero (a : UnitAddCircle) :
Tendsto (fun s ↦ s * completedHurwitzZetaEven a s) (𝓝[≠] 0) (𝓝 (if a = 0 then -1 else 0)) := by
have h1 : Tendsto (fun s : ℂ ↦ s * _) (𝓝[≠] 0)
(𝓝 (-(if a = 0 then 1 else 0))) := (hurwitzEvenFEPair a).Λ_residue_zero
have : -(if a = 0 then (1 : ℂ) else 0) = (if a = 0 then -1 else 0) := by { split_ifs <;> simp }
simp only [this, push_cast] at h1
refine (h1.comp <| zero_div (2 : ℂ) ▸ (tendsto_div_two_punctured_nhds 0)).congr (fun s ↦ ?_)
simp [completedHurwitzZetaEven, div_mul_eq_mul_div, mul_div_assoc]
lemma completedCosZeta_residue_zero (a : UnitAddCircle) :
Tendsto (fun s ↦ s * completedCosZeta a s) (𝓝[≠] 0) (𝓝 (-1)) := by
have h1 : Tendsto (fun s : ℂ ↦ s * _) (𝓝[≠] 0)
(𝓝 (-1)) := (hurwitzEvenFEPair a).symm.Λ_residue_zero
refine (h1.comp <| zero_div (2 : ℂ) ▸ (tendsto_div_two_punctured_nhds 0)).congr (fun s ↦ ?_)
simp [completedCosZeta, div_mul_eq_mul_div, mul_div_assoc]
end FEPair
/-!
## Relation to the Dirichlet series for `1 < re s`
-/
/-- Formula for `completedCosZeta` as a Dirichlet series in the convergence range
(first version, with sum over `ℤ`). -/
lemma hasSum_int_completedCosZeta (a : ℝ) {s : ℂ} (hs : 1 < re s) :
HasSum (fun n : ℤ ↦ Gammaℝ s * cexp (2 * π * I * a * n) / (↑|n| : ℂ) ^ s / 2)
(completedCosZeta a s) := by
let c (n : ℤ) : ℂ := cexp (2 * π * I * a * n) / 2
have hF t (ht : 0 < t) : HasSum (fun n : ℤ ↦ if n = 0 then 0 else c n * rexp (-π * n ^ 2 * t))
((cosKernel a t - 1) / 2) := by
refine ((hasSum_int_cosKernel₀ a ht).div_const 2).congr_fun fun n ↦ ?_
split_ifs <;> simp [c, div_mul_eq_mul_div]
simp only [← Int.cast_eq_zero (α := ℝ)] at hF
rw [show completedCosZeta a s = mellin (fun t ↦ (cosKernel a t - 1 : ℂ) / 2) (s / 2) by
rw [mellin_div_const, completedCosZeta]
congr 1
refine ((hurwitzEvenFEPair a).symm.hasMellin (?_ : 1 / 2 < (s / 2).re)).2.symm
rwa [div_ofNat_re, div_lt_div_iff_of_pos_right two_pos]]
refine (hasSum_mellin_pi_mul_sq (zero_lt_one.trans hs) hF ?_).congr_fun fun n ↦ ?_
· apply (((summable_one_div_int_add_rpow 0 s.re).mpr hs).div_const 2).of_norm_bounded
intro i
simp only [c, (by { push_cast; ring } : 2 * π * I * a * i = ↑(2 * π * a * i) * I), norm_div,
RCLike.norm_ofNat, Complex.norm_exp_ofReal_mul_I, add_zero, norm_one,
norm_of_nonneg (by positivity : 0 ≤ |(i : ℝ)| ^ s.re), div_right_comm, le_rfl]
· simp [c, ← Int.cast_abs, div_right_comm, mul_div_assoc]
/-- Formula for `completedCosZeta` as a Dirichlet series in the convergence range
(second version, with sum over `ℕ`). -/
lemma hasSum_nat_completedCosZeta (a : ℝ) {s : ℂ} (hs : 1 < re s) :
HasSum (fun n : ℕ ↦ if n = 0 then 0 else Gammaℝ s * Real.cos (2 * π * a * n) / (n : ℂ) ^ s)
(completedCosZeta a s) := by
have aux : ((|0| : ℤ) : ℂ) ^ s = 0 := by
rw [abs_zero, Int.cast_zero, zero_cpow (ne_zero_of_one_lt_re hs)]
have hint := (hasSum_int_completedCosZeta a hs).nat_add_neg
rw [aux, div_zero, zero_div, add_zero] at hint
refine hint.congr_fun fun n ↦ ?_
split_ifs with h
· simp only [h, Nat.cast_zero, aux, div_zero, zero_div, neg_zero, zero_add]
· simp only [ofReal_cos, ofReal_mul, ofReal_ofNat, ofReal_natCast, Complex.cos,
show 2 * π * a * n * I = 2 * π * I * a * n by ring, neg_mul, mul_div_assoc,
div_right_comm _ (2 : ℂ), Int.cast_natCast, Nat.abs_cast, Int.cast_neg, mul_neg, abs_neg, ←
mul_add, ← add_div]
/-- Formula for `completedHurwitzZetaEven` as a Dirichlet series in the convergence range. -/
lemma hasSum_int_completedHurwitzZetaEven (a : ℝ) {s : ℂ} (hs : 1 < re s) :
HasSum (fun n : ℤ ↦ Gammaℝ s / (↑|n + a| : ℂ) ^ s / 2) (completedHurwitzZetaEven a s) := by
have hF (t : ℝ) (ht : 0 < t) : HasSum (fun n : ℤ ↦ if n + a = 0 then 0
else (1 / 2 : ℂ) * rexp (-π * (n + a) ^ 2 * t))
((evenKernel a t - (if (a : UnitAddCircle) = 0 then 1 else 0 : ℝ)) / 2) := by
refine (ofReal_sub .. ▸ (hasSum_ofReal.mpr (hasSum_int_evenKernel₀ a ht)).div_const
2).congr_fun fun n ↦ ?_
split_ifs
· rw [ofReal_zero, zero_div]
· rw [mul_comm, mul_one_div]
rw [show completedHurwitzZetaEven a s = mellin (fun t ↦ ((evenKernel (↑a) t : ℂ) -
↑(if (a : UnitAddCircle) = 0 then 1 else 0 : ℝ)) / 2) (s / 2) by
simp_rw [mellin_div_const, apply_ite ofReal, ofReal_one, ofReal_zero]
refine congr_arg (· / 2) ((hurwitzEvenFEPair a).hasMellin (?_ : 1 / 2 < (s / 2).re)).2.symm
rwa [div_ofNat_re, div_lt_div_iff_of_pos_right two_pos]]
refine (hasSum_mellin_pi_mul_sq (zero_lt_one.trans hs) hF ?_).congr_fun fun n ↦ ?_
· simp_rw [← mul_one_div ‖_‖]
apply Summable.mul_left
rwa [summable_one_div_int_add_rpow]
· rw [mul_one_div, div_right_comm]
/-!
## The un-completed even Hurwitz zeta
-/
/-- Technical lemma which will give us differentiability of Hurwitz zeta at `s = 0`. -/
lemma differentiableAt_update_of_residue
{Λ : ℂ → ℂ} (hf : ∀ (s : ℂ) (_ : s ≠ 0) (_ : s ≠ 1), DifferentiableAt ℂ Λ s)
{L : ℂ} (h_lim : Tendsto (fun s ↦ s * Λ s) (𝓝[≠] 0) (𝓝 L)) (s : ℂ) (hs' : s ≠ 1) :
DifferentiableAt ℂ (Function.update (fun s ↦ Λ s / Gammaℝ s) 0 (L / 2)) s := by
have claim (t) (ht : t ≠ 0) (ht' : t ≠ 1) : DifferentiableAt ℂ (fun u : ℂ ↦ Λ u / Gammaℝ u) t :=
(hf t ht ht').mul differentiable_Gammaℝ_inv.differentiableAt
have claim2 : Tendsto (fun s : ℂ ↦ Λ s / Gammaℝ s) (𝓝[≠] 0) (𝓝 <| L / 2) := by
refine Tendsto.congr' ?_ (h_lim.div Gammaℝ_residue_zero two_ne_zero)
filter_upwards [self_mem_nhdsWithin] with s (hs : s ≠ 0)
rw [Pi.div_apply, ← div_div, mul_div_cancel_left₀ _ hs]
rcases ne_or_eq s 0 with hs | rfl
· -- Easy case : `s ≠ 0`
refine (claim s hs hs').congr_of_eventuallyEq ?_
filter_upwards [isOpen_compl_singleton.mem_nhds hs] with x hx
simp [Function.update_of_ne hx]
· -- Hard case : `s = 0`
simp_rw [← claim2.limUnder_eq]
have S_nhds : {(1 : ℂ)}ᶜ ∈ 𝓝 (0 : ℂ) := isOpen_compl_singleton.mem_nhds hs'
refine ((Complex.differentiableOn_update_limUnder_of_isLittleO S_nhds
(fun t ht ↦ (claim t ht.2 ht.1).differentiableWithinAt) ?_) 0 hs').differentiableAt S_nhds
simp only [Gammaℝ, zero_div, div_zero, Complex.Gamma_zero, mul_zero, sub_zero]
-- Remains to show completed zeta is `o (s ^ (-1))` near 0.
refine (isBigO_const_of_tendsto claim2 <| one_ne_zero' ℂ).trans_isLittleO ?_
rw [isLittleO_iff_tendsto']
· exact Tendsto.congr (fun x ↦ by rw [← one_div, one_div_one_div]) nhdsWithin_le_nhds
· exact eventually_of_mem self_mem_nhdsWithin fun x hx hx' ↦ (hx <| inv_eq_zero.mp hx').elim
/-- The even part of the Hurwitz zeta function, i.e. the meromorphic function of `s` which agrees
with `1 / 2 * ∑' (n : ℤ), 1 / |n + a| ^ s` for `1 < re s` -/
noncomputable def hurwitzZetaEven (a : UnitAddCircle) :=
Function.update (fun s ↦ completedHurwitzZetaEven a s / Gammaℝ s)
0 (if a = 0 then -1 / 2 else 0)
lemma hurwitzZetaEven_def_of_ne_or_ne {a : UnitAddCircle} {s : ℂ} (h : a ≠ 0 ∨ s ≠ 0) :
hurwitzZetaEven a s = completedHurwitzZetaEven a s / Gammaℝ s := by
rw [hurwitzZetaEven]
rcases ne_or_eq s 0 with h' | rfl
· rw [Function.update_of_ne h']
· simpa [Gammaℝ] using h
lemma hurwitzZetaEven_apply_zero (a : UnitAddCircle) :
hurwitzZetaEven a 0 = if a = 0 then -1 / 2 else 0 :=
Function.update_self ..
lemma hurwitzZetaEven_neg (a : UnitAddCircle) (s : ℂ) :
hurwitzZetaEven (-a) s = hurwitzZetaEven a s := by
simp [hurwitzZetaEven]
/-- The trivial zeroes of the even Hurwitz zeta function. -/
theorem hurwitzZetaEven_neg_two_mul_nat_add_one (a : UnitAddCircle) (n : ℕ) :
hurwitzZetaEven a (-2 * (n + 1)) = 0 := by
have : (-2 : ℂ) * (n + 1) ≠ 0 :=
mul_ne_zero (neg_ne_zero.mpr two_ne_zero) (Nat.cast_add_one_ne_zero n)
rw [hurwitzZetaEven, Function.update_of_ne this, Gammaℝ_eq_zero_iff.mpr ⟨n + 1, by simp⟩,
div_zero]
/-- The Hurwitz zeta function is differentiable everywhere except at `s = 1`. This is true
even in the delicate case `a = 0` and `s = 0` (where the completed zeta has a pole, but this is
cancelled out by the Gamma factor). -/
lemma differentiableAt_hurwitzZetaEven (a : UnitAddCircle) {s : ℂ} (hs' : s ≠ 1) :
DifferentiableAt ℂ (hurwitzZetaEven a) s := by
have := differentiableAt_update_of_residue
(fun t ht ht' ↦ differentiableAt_completedHurwitzZetaEven a (Or.inl ht) ht')
(completedHurwitzZetaEven_residue_zero a) s hs'
simp_rw [div_eq_mul_inv, ite_mul, zero_mul, ← div_eq_mul_inv] at this
exact this
lemma hurwitzZetaEven_residue_one (a : UnitAddCircle) :
Tendsto (fun s ↦ (s - 1) * hurwitzZetaEven a s) (𝓝[≠] 1) (𝓝 1) := by
have : Tendsto (fun s ↦ (s - 1) * completedHurwitzZetaEven a s / Gammaℝ s) (𝓝[≠] 1) (𝓝 1) := by
simpa only [Gammaℝ_one, inv_one, mul_one] using (completedHurwitzZetaEven_residue_one a).mul
<| (differentiable_Gammaℝ_inv.continuous.tendsto _).mono_left nhdsWithin_le_nhds
refine this.congr' ?_
filter_upwards [eventually_ne_nhdsWithin one_ne_zero] with s hs
simp [hurwitzZetaEven_def_of_ne_or_ne (Or.inr hs), mul_div_assoc]
lemma differentiableAt_hurwitzZetaEven_sub_one_div (a : UnitAddCircle) :
DifferentiableAt ℂ (fun s ↦ hurwitzZetaEven a s - 1 / (s - 1) / Gammaℝ s) 1 := by
suffices DifferentiableAt ℂ
(fun s ↦ completedHurwitzZetaEven a s / Gammaℝ s - 1 / (s - 1) / Gammaℝ s) 1 by
apply this.congr_of_eventuallyEq
filter_upwards [eventually_ne_nhds one_ne_zero] with x hx
rw [hurwitzZetaEven, Function.update_of_ne hx]
simp_rw [← sub_div, div_eq_mul_inv _ (Gammaℝ _)]
refine DifferentiableAt.mul ?_ differentiable_Gammaℝ_inv.differentiableAt
simp_rw [completedHurwitzZetaEven_eq, sub_sub, add_assoc]
conv => enter [2, s, 2]; rw [← neg_sub, div_neg, neg_add_cancel, add_zero]
exact (differentiable_completedHurwitzZetaEven₀ a _).sub
<| (differentiableAt_const _).div differentiableAt_id one_ne_zero
/-- Expression for `hurwitzZetaEven a 1` as a limit. (Mathematically `hurwitzZetaEven a 1` is
undefined, but our construction assigns some value to it; this lemma is mostly of interest for
determining what that value is). -/
lemma tendsto_hurwitzZetaEven_sub_one_div_nhds_one (a : UnitAddCircle) :
Tendsto (fun s ↦ hurwitzZetaEven a s - 1 / (s - 1) / Gammaℝ s) (𝓝 1)
(𝓝 (hurwitzZetaEven a 1)) := by
simpa using (differentiableAt_hurwitzZetaEven_sub_one_div a).continuousAt.tendsto
lemma differentiable_hurwitzZetaEven_sub_hurwitzZetaEven (a b : UnitAddCircle) :
Differentiable ℂ (fun s ↦ hurwitzZetaEven a s - hurwitzZetaEven b s) := by
intro z
rcases ne_or_eq z 1 with hz | rfl
· exact (differentiableAt_hurwitzZetaEven a hz).sub (differentiableAt_hurwitzZetaEven b hz)
· convert (differentiableAt_hurwitzZetaEven_sub_one_div a).fun_sub
(differentiableAt_hurwitzZetaEven_sub_one_div b) using 2 with s
abel
/--
Formula for `hurwitzZetaEven` as a Dirichlet series in the convergence range, with sum over `ℤ`.
-/
lemma hasSum_int_hurwitzZetaEven (a : ℝ) {s : ℂ} (hs : 1 < re s) :
HasSum (fun n : ℤ ↦ 1 / (↑|n + a| : ℂ) ^ s / 2) (hurwitzZetaEven a s) := by
rw [hurwitzZetaEven, Function.update_of_ne (ne_zero_of_one_lt_re hs)]
have := (hasSum_int_completedHurwitzZetaEven a hs).div_const (Gammaℝ s)
exact this.congr_fun fun n ↦ by simp only [div_right_comm _ _ (Gammaℝ _),
div_self (Gammaℝ_ne_zero_of_re_pos (zero_lt_one.trans hs))]
/-- Formula for `hurwitzZetaEven` as a Dirichlet series in the convergence range, with sum over `ℕ`
(version with absolute values) -/
lemma hasSum_nat_hurwitzZetaEven (a : ℝ) {s : ℂ} (hs : 1 < re s) :
HasSum (fun n : ℕ ↦ (1 / (↑|n + a| : ℂ) ^ s + 1 / (↑|n + 1 - a| : ℂ) ^ s) / 2)
(hurwitzZetaEven a s) := by
refine (hasSum_int_hurwitzZetaEven a hs).nat_add_neg_add_one.congr_fun fun n ↦ ?_
simp [← abs_neg (n + 1 - a), -neg_sub, neg_sub', add_div]
/-- Formula for `hurwitzZetaEven` as a Dirichlet series in the convergence range, with sum over `ℕ`
(version without absolute values, assuming `a ∈ Icc 0 1`) -/
lemma hasSum_nat_hurwitzZetaEven_of_mem_Icc {a : ℝ} (ha : a ∈ Icc 0 1) {s : ℂ} (hs : 1 < re s) :
HasSum (fun n : ℕ ↦ (1 / (n + a : ℂ) ^ s + 1 / (n + 1 - a : ℂ) ^ s) / 2)
(hurwitzZetaEven a s) := by
refine (hasSum_nat_hurwitzZetaEven a hs).congr_fun fun n ↦ ?_
congr 2 <;>
rw [abs_of_nonneg (by linarith [ha.1, ha.2])] <;>
simp
/-!
## The un-completed cosine zeta
-/
/-- The cosine zeta function, i.e. the meromorphic function of `s` which agrees
with `∑' (n : ℕ), cos (2 * π * a * n) / n ^ s` for `1 < re s`. -/
noncomputable def cosZeta (a : UnitAddCircle) :=
Function.update (fun s : ℂ ↦ completedCosZeta a s / Gammaℝ s) 0 (-1 / 2)
lemma cosZeta_apply_zero (a : UnitAddCircle) : cosZeta a 0 = -1 / 2 :=
Function.update_self ..
lemma cosZeta_neg (a : UnitAddCircle) (s : ℂ) :
cosZeta (-a) s = cosZeta a s := by
simp [cosZeta]
/-- The trivial zeroes of the cosine zeta function. -/
theorem cosZeta_neg_two_mul_nat_add_one (a : UnitAddCircle) (n : ℕ) :
cosZeta a (-2 * (n + 1)) = 0 := by
have : (-2 : ℂ) * (n + 1) ≠ 0 :=
mul_ne_zero (neg_ne_zero.mpr two_ne_zero) (Nat.cast_add_one_ne_zero n)
rw [cosZeta, Function.update_of_ne this,
Gammaℝ_eq_zero_iff.mpr ⟨n + 1, by rw [neg_mul, Nat.cast_add_one]⟩, div_zero]
/-- The cosine zeta function is differentiable everywhere, except at `s = 1` if `a = 0`. -/
lemma differentiableAt_cosZeta (a : UnitAddCircle) {s : ℂ} (hs' : s ≠ 1 ∨ a ≠ 0) :
DifferentiableAt ℂ (cosZeta a) s := by
rcases ne_or_eq s 1 with hs' | rfl
· exact differentiableAt_update_of_residue (fun _ ht ht' ↦
differentiableAt_completedCosZeta a ht (Or.inl ht')) (completedCosZeta_residue_zero a) s hs'
· apply ((differentiableAt_completedCosZeta a one_ne_zero hs').fun_mul
(differentiable_Gammaℝ_inv.differentiableAt)).congr_of_eventuallyEq
filter_upwards [isOpen_compl_singleton.mem_nhds one_ne_zero] with x hx
rw [cosZeta, Function.update_of_ne hx, div_eq_mul_inv]
/-- If `a ≠ 0` then the cosine zeta function is entire. -/
lemma differentiable_cosZeta_of_ne_zero {a : UnitAddCircle} (ha : a ≠ 0) :
Differentiable ℂ (cosZeta a) :=
fun _ ↦ differentiableAt_cosZeta a (Or.inr ha)
/-- Formula for `cosZeta` as a Dirichlet series in the convergence range, with sum over `ℤ`. -/
lemma hasSum_int_cosZeta (a : ℝ) {s : ℂ} (hs : 1 < re s) :
HasSum (fun n : ℤ ↦ cexp (2 * π * I * a * n) / ↑|n| ^ s / 2) (cosZeta a s) := by
rw [cosZeta, Function.update_of_ne (ne_zero_of_one_lt_re hs)]
refine ((hasSum_int_completedCosZeta a hs).div_const (Gammaℝ s)).congr_fun fun n ↦ ?_
rw [mul_div_assoc _ (cexp _), div_right_comm _ (2 : ℂ),
mul_div_cancel_left₀ _ (Gammaℝ_ne_zero_of_re_pos (zero_lt_one.trans hs))]
/-- Formula for `cosZeta` as a Dirichlet series in the convergence range, with sum over `ℕ`. -/
lemma hasSum_nat_cosZeta (a : ℝ) {s : ℂ} (hs : 1 < re s) :
HasSum (fun n : ℕ ↦ Real.cos (2 * π * a * n) / (n : ℂ) ^ s) (cosZeta a s) := by
have := (hasSum_int_cosZeta a hs).nat_add_neg
simp_rw [abs_neg, Int.cast_neg, Nat.abs_cast, Int.cast_natCast, mul_neg, abs_zero, Int.cast_zero,
zero_cpow (ne_zero_of_one_lt_re hs), div_zero, zero_div, add_zero, ← add_div,
div_right_comm _ _ (2 : ℂ)] at this
simp_rw [push_cast, Complex.cos, neg_mul]
exact this.congr_fun fun n ↦ by rw [show 2 * π * a * n * I = 2 * π * I * a * n by ring]
/-- Reformulation of `hasSum_nat_cosZeta` using `LSeriesHasSum`. -/
lemma LSeriesHasSum_cos (a : ℝ) {s : ℂ} (hs : 1 < re s) :
LSeriesHasSum (Real.cos <| 2 * π * a * ·) s (cosZeta a s) :=
(hasSum_nat_cosZeta a hs).congr_fun (LSeries.term_of_ne_zero' (ne_zero_of_one_lt_re hs) _)
/-!
## Functional equations for the un-completed zetas
-/
/-- If `s` is not in `-ℕ`, and either `a ≠ 0` or `s ≠ 1`, then
`hurwitzZetaEven a (1 - s)` is an explicit multiple of `cosZeta s`. -/
lemma hurwitzZetaEven_one_sub (a : UnitAddCircle) {s : ℂ}
(hs : ∀ (n : ℕ), s ≠ -n) (hs' : a ≠ 0 ∨ s ≠ 1) :
hurwitzZetaEven a (1 - s) = 2 * (2 * π) ^ (-s) * Gamma s * cos (π * s / 2) * cosZeta a s := by
have : hurwitzZetaEven a (1 - s) = completedHurwitzZetaEven a (1 - s) * (Gammaℝ (1 - s))⁻¹ := by
rw [hurwitzZetaEven_def_of_ne_or_ne, div_eq_mul_inv]
simpa [sub_eq_zero, eq_comm (a := s)] using hs'
rw [this, completedHurwitzZetaEven_one_sub, inv_Gammaℝ_one_sub hs, cosZeta,
Function.update_of_ne (by simpa using hs 0), ← Gammaℂ]
generalize Gammaℂ s * cos (π * s / 2) = A -- speeds up ring_nf call
ring_nf
/-- If `s` is not of the form `1 - n` for `n ∈ ℕ`, then `cosZeta a (1 - s)` is an explicit
multiple of `hurwitzZetaEven s`. -/
lemma cosZeta_one_sub (a : UnitAddCircle) {s : ℂ} (hs : ∀ (n : ℕ), s ≠ 1 - n) :
cosZeta a (1 - s) = 2 * (2 * π) ^ (-s) * Gamma s * cos (π * s / 2) * hurwitzZetaEven a s := by
rw [← Gammaℂ]
have : cosZeta a (1 - s) = completedCosZeta a (1 - s) * (Gammaℝ (1 - s))⁻¹ := by
rw [cosZeta, Function.update_of_ne, div_eq_mul_inv]
simpa [sub_eq_zero] using (hs 0).symm
rw [this, completedCosZeta_one_sub, inv_Gammaℝ_one_sub (fun n ↦ by simpa using hs (n + 1)),
hurwitzZetaEven_def_of_ne_or_ne (Or.inr (by simpa using hs 1))]
generalize Gammaℂ s * cos (π * s / 2) = A -- speeds up ring_nf call
ring_nf
end HurwitzZeta |
.lake/packages/mathlib/Mathlib/NumberTheory/LSeries/MellinEqDirichlet.lean | import Mathlib.Analysis.SpecialFunctions.Gamma.Deligne
/-!
# Dirichlet series as Mellin transforms
Here we prove general results of the form "the Mellin transform of a power series in exp (-t) is
a Dirichlet series".
-/
open Filter Topology Asymptotics Real Set MeasureTheory
open Complex
variable {ι : Type*} [Countable ι]
/-- Most basic version of the "Mellin transform = Dirichlet series" argument. -/
lemma hasSum_mellin {a : ι → ℂ} {p : ι → ℝ} {F : ℝ → ℂ} {s : ℂ}
(hp : ∀ i, a i = 0 ∨ 0 < p i) (hs : 0 < s.re)
(hF : ∀ t ∈ Ioi 0, HasSum (fun i ↦ a i * rexp (-p i * t)) (F t))
(h_sum : Summable fun i ↦ ‖a i‖ / (p i) ^ s.re) :
HasSum (fun i ↦ Gamma s * a i / p i ^ s) (mellin F s) := by
simp_rw [mellin, smul_eq_mul, ← setIntegral_congr_fun measurableSet_Ioi
(fun t ht ↦ congr_arg _ (hF t ht).tsum_eq), ← tsum_mul_left]
convert hasSum_integral_of_summable_integral_norm
(F := fun i t ↦ t ^ (s - 1) * (a i * rexp (-p i * t))) (fun i ↦ ?_) ?_ using 2 with i
· simp_rw [← mul_assoc, mul_comm _ (a _), mul_assoc (a _), mul_div_assoc, integral_const_mul]
rcases hp i with hai | hpi
· rw [hai, zero_mul, zero_mul]
have := integral_cpow_mul_exp_neg_mul_Ioi hs hpi
simp_rw [← ofReal_mul, ← ofReal_neg, ← ofReal_exp, ← neg_mul (p i)] at this
rw [this, one_div, inv_cpow _ _ (arg_ofReal_of_nonneg hpi.le ▸ pi_pos.ne), div_eq_inv_mul]
· -- integrability of terms
rcases hp i with hai | hpi
· simp [hai]
simp_rw [← mul_assoc, mul_comm _ (a i), mul_assoc]
have := Complex.GammaIntegral_convergent hs
rw [← mul_zero (p i), ← integrableOn_Ioi_comp_mul_left_iff _ _ hpi] at this
refine (IntegrableOn.congr_fun (this.const_mul (1 / p i ^ (s - 1)))
(fun t (ht : 0 < t) ↦ ?_) measurableSet_Ioi).const_mul _
simp_rw [mul_comm (↑(rexp _) : ℂ), ← mul_assoc, neg_mul, ofReal_mul]
rw [mul_cpow_ofReal_nonneg hpi.le ht.le, ← mul_assoc, one_div, inv_mul_cancel₀, one_mul]
rw [Ne, cpow_eq_zero_iff, not_and_or]
exact Or.inl (ofReal_ne_zero.mpr hpi.ne')
· -- summability of integrals of norms
apply Summable.of_norm
convert h_sum.mul_left (Real.Gamma s.re) using 2 with i
simp_rw [← mul_assoc, mul_comm _ (a i), mul_assoc, norm_mul (a i), integral_const_mul]
rw [← mul_div_assoc, mul_comm (Real.Gamma _), mul_div_assoc, norm_mul ‖a i‖, norm_norm]
rcases hp i with hai | hpi
· simp [hai]
congr 1
have := Real.integral_rpow_mul_exp_neg_mul_Ioi hs hpi
simp_rw [← neg_mul (p i), one_div, inv_rpow hpi.le, ← div_eq_inv_mul] at this
rw [norm_of_nonneg (integral_nonneg (fun _ ↦ norm_nonneg _)), ← this]
refine setIntegral_congr_fun measurableSet_Ioi (fun t ht ↦ ?_)
rw [norm_mul, norm_real, Real.norm_eq_abs, Real.abs_exp,
norm_cpow_eq_rpow_re_of_pos ht, sub_re, one_re]
/-- Shortcut version for the commonly arising special case when `p i = π * q i` for some other
sequence `q`. -/
lemma hasSum_mellin_pi_mul {a : ι → ℂ} {q : ι → ℝ} {F : ℝ → ℂ} {s : ℂ}
(hq : ∀ i, a i = 0 ∨ 0 < q i) (hs : 0 < s.re)
(hF : ∀ t ∈ Ioi 0, HasSum (fun i ↦ a i * rexp (-π * q i * t)) (F t))
(h_sum : Summable fun i ↦ ‖a i‖ / (q i) ^ s.re) :
HasSum (fun i ↦ π ^ (-s) * Gamma s * a i / q i ^ s) (mellin F s) := by
have hp i : a i = 0 ∨ 0 < π * q i := by rcases hq i with h | h <;> simp [h, pi_pos]
convert hasSum_mellin hp hs (by simpa using hF) ?_ using 2 with i
· have : a i / ↑(π * q i) ^ s = π ^ (-s) * a i / q i ^ s := by
rcases hq i with h | h
· simp [h]
· rw [ofReal_mul, mul_cpow_ofReal_nonneg pi_pos.le h.le, ← div_div, cpow_neg,
← div_eq_inv_mul]
simp_rw [mul_div_assoc, this]
ring_nf
· have (i : _) : ‖a i‖ / ↑(π * q i) ^ s.re = π ^ (-s.re) * ‖a i‖ / q i ^ s.re := by
rcases hq i with h | h
· simp [h]
· rw [mul_rpow pi_pos.le h.le, ← div_div, rpow_neg pi_pos.le, ← div_eq_inv_mul]
simpa only [this, mul_div_assoc] using h_sum.mul_left _
/-- Version allowing some constant terms (which are omitted from the sums). -/
lemma hasSum_mellin_pi_mul₀ {a : ι → ℂ} {p : ι → ℝ} {F : ℝ → ℂ} {s : ℂ}
(hp : ∀ i, 0 ≤ p i) (hs : 0 < s.re)
(hF : ∀ t ∈ Ioi 0, HasSum (fun i ↦ if p i = 0 then 0 else a i * rexp (-π * p i * t)) (F t))
(h_sum : Summable fun i ↦ ‖a i‖ / (p i) ^ s.re) :
HasSum (fun i ↦ π ^ (-s) * Gamma s * a i / p i ^ s) (mellin F s) := by
have hs' : s ≠ 0 := fun h ↦ lt_irrefl _ (zero_re ▸ h ▸ hs)
let a' i := if p i = 0 then 0 else a i
have hp' i : a' i = 0 ∨ 0 < p i := by
simp only [a']
split_ifs with h <;> try tauto
exact Or.inr (lt_of_le_of_ne (hp i) (Ne.symm h))
have (i t : _) : (if p i = 0 then 0 else a i * rexp (-π * p i * t)) =
a' i * rexp (-π * p i * t) := by
simp [a']
simp_rw [this] at hF
convert hasSum_mellin_pi_mul hp' hs hF ?_ using 2 with i
· rcases eq_or_ne (p i) 0 with h | h <;>
simp [a', h, ofReal_zero, zero_cpow hs', div_zero]
· refine h_sum.of_norm_bounded (fun i ↦ ?_)
simp only [a']
split_ifs
· simp only [norm_zero, zero_div]
positivity
· have := hp i
rw [norm_of_nonneg (by positivity)]
/-- Tailored version for even Jacobi theta functions. -/
lemma hasSum_mellin_pi_mul_sq {a : ι → ℂ} {r : ι → ℝ} {F : ℝ → ℂ} {s : ℂ} (hs : 0 < s.re)
(hF : ∀ t ∈ Ioi 0, HasSum (fun i ↦ if r i = 0 then 0 else a i * rexp (-π * r i ^ 2 * t)) (F t))
(h_sum : Summable fun i ↦ ‖a i‖ / |r i| ^ s.re) :
HasSum (fun i ↦ Gammaℝ s * a i / |r i| ^ s) (mellin F (s / 2)) := by
have hs' : 0 < (s / 2).re := by rw [div_ofNat_re]; positivity
simp_rw [← sq_eq_zero_iff (a := r _)] at hF
convert hasSum_mellin_pi_mul₀ (fun i ↦ sq_nonneg (r i)) hs' hF ?_ using 3 with i
· rw [← neg_div, Gammaℝ_def]
· rw [← sq_abs, ofReal_pow, ← cpow_nat_mul']
· ring_nf
all_goals rw [arg_ofReal_of_nonneg (abs_nonneg _)]; linarith [pi_pos]
· convert h_sum using 3 with i
rw [← sq_abs, ← rpow_natCast_mul (abs_nonneg _), div_ofNat_re, Nat.cast_ofNat,
mul_div_cancel₀ _ two_pos.ne']
/-- Tailored version for odd Jacobi theta functions. -/
lemma hasSum_mellin_pi_mul_sq' {a : ι → ℂ} {r : ι → ℝ} {F : ℝ → ℂ} {s : ℂ} (hs : 0 < s.re)
(hF : ∀ t ∈ Ioi 0, HasSum (fun i ↦ a i * r i * rexp (-π * r i ^ 2 * t)) (F t))
(h_sum : Summable fun i ↦ ‖a i‖ / |r i| ^ s.re) :
HasSum (fun i ↦ Gammaℝ (s + 1) * a i * SignType.sign (r i) / |r i| ^ s)
(mellin F ((s + 1) / 2)) := by
have hs₁ : s ≠ 0 := fun h ↦ lt_irrefl _ (zero_re ▸ h ▸ hs)
have hs₂ : 0 < (s + 1).re := by rw [add_re, one_re]; positivity
have hs₃ : s + 1 ≠ 0 := fun h ↦ lt_irrefl _ (zero_re ▸ h ▸ hs₂)
have (i t : _) : (a i * r i * rexp (-π * r i ^ 2 * t)) =
if r i = 0 then 0 else (a i * r i * rexp (-π * r i ^ 2 * t)) := by
split_ifs with h <;> simp [h]
conv at hF => enter [t, ht, 1, i]; rw [this]
convert hasSum_mellin_pi_mul_sq hs₂ hF ?_ using 2 with i
· rcases eq_or_ne (r i) 0 with h | h
· rw [h, abs_zero, ofReal_zero, zero_cpow hs₁, zero_cpow hs₃, div_zero, div_zero]
· rw [cpow_add _ _ (ofReal_ne_zero.mpr <| abs_ne_zero.mpr h), cpow_one]
conv_rhs => enter [1]; rw [← sign_mul_abs (r i), ofReal_mul, ← ofRealHom_eq_coe,
SignType.map_cast]
field [h]
· convert h_sum using 2 with i
rcases eq_or_ne (r i) 0 with h | h
· rw [h, abs_zero, ofReal_zero, zero_rpow hs₂.ne', zero_rpow hs.ne', div_zero, div_zero]
· rw [add_re, one_re, rpow_add (abs_pos.mpr h), rpow_one, norm_mul, norm_real,
Real.norm_eq_abs, ← div_div, div_right_comm, mul_div_cancel_right₀ _ (abs_ne_zero.mpr h)] |
.lake/packages/mathlib/Mathlib/NumberTheory/LSeries/Linearity.lean | import Mathlib.Algebra.BigOperators.Field
import Mathlib.NumberTheory.LSeries.Basic
/-!
# Linearity of the L-series of `f` as a function of `f`
We show that the `LSeries` of `f : ℕ → ℂ` is a linear function of `f` (assuming convergence
of both L-series when adding two functions).
-/
/-!
### Addition
-/
open LSeries
lemma LSeries.term_add (f g : ℕ → ℂ) (s : ℂ) : term (f + g) s = term f s + term g s := by
ext ⟨- | n⟩ <;>
simp [add_div]
lemma LSeries.term_add_apply (f g : ℕ → ℂ) (s : ℂ) (n : ℕ) :
term (f + g) s n = term f s n + term g s n := by
simp [term_add]
lemma LSeriesHasSum.add {f g : ℕ → ℂ} {s a b : ℂ} (hf : LSeriesHasSum f s a)
(hg : LSeriesHasSum g s b) :
LSeriesHasSum (f + g) s (a + b) := by
simpa [LSeriesHasSum, term_add] using HasSum.add hf hg
lemma LSeriesSummable.add {f g : ℕ → ℂ} {s : ℂ} (hf : LSeriesSummable f s)
(hg : LSeriesSummable g s) :
LSeriesSummable (f + g) s := by
simpa [LSeriesSummable, ← term_add_apply] using Summable.add hf hg
@[simp]
lemma LSeries_add {f g : ℕ → ℂ} {s : ℂ} (hf : LSeriesSummable f s) (hg : LSeriesSummable g s) :
LSeries (f + g) s = LSeries f s + LSeries g s := by
simpa [LSeries, term_add] using hf.tsum_add hg
/-!
### Negation
-/
lemma LSeries.term_neg (f : ℕ → ℂ) (s : ℂ) : term (-f) s = -term f s := by
ext ⟨- | n⟩ <;>
simp [neg_div]
lemma LSeries.term_neg_apply (f : ℕ → ℂ) (s : ℂ) (n : ℕ) : term (-f) s n = -term f s n := by
simp [term_neg]
lemma LSeriesHasSum.neg {f : ℕ → ℂ} {s a : ℂ} (hf : LSeriesHasSum f s a) :
LSeriesHasSum (-f) s (-a) := by
simpa [LSeriesHasSum, term_neg] using HasSum.neg hf
lemma LSeriesSummable.neg {f : ℕ → ℂ} {s : ℂ} (hf : LSeriesSummable f s) :
LSeriesSummable (-f) s := by
simpa [LSeriesSummable, term_neg] using Summable.neg hf
@[simp]
lemma LSeriesSummable.neg_iff {f : ℕ → ℂ} {s : ℂ} :
LSeriesSummable (-f) s ↔ LSeriesSummable f s :=
⟨fun H ↦ neg_neg f ▸ H.neg, .neg⟩
@[simp]
lemma LSeries_neg (f : ℕ → ℂ) (s : ℂ) : LSeries (-f) s = -LSeries f s := by
simp [LSeries, term_neg_apply, tsum_neg]
/-!
### Subtraction
-/
lemma LSeries.term_sub (f g : ℕ → ℂ) (s : ℂ) : term (f - g) s = term f s - term g s := by
simp_rw [sub_eq_add_neg, term_add, term_neg]
lemma LSeries.term_sub_apply (f g : ℕ → ℂ) (s : ℂ) (n : ℕ) :
term (f - g) s n = term f s n - term g s n := by
rw [term_sub, Pi.sub_apply]
lemma LSeriesHasSum.sub {f g : ℕ → ℂ} {s a b : ℂ} (hf : LSeriesHasSum f s a)
(hg : LSeriesHasSum g s b) :
LSeriesHasSum (f - g) s (a - b) := by
simpa [LSeriesHasSum, term_sub] using HasSum.sub hf hg
lemma LSeriesSummable.sub {f g : ℕ → ℂ} {s : ℂ} (hf : LSeriesSummable f s)
(hg : LSeriesSummable g s) :
LSeriesSummable (f - g) s := by
simpa [LSeriesSummable, ← term_sub_apply] using Summable.sub hf hg
@[simp]
lemma LSeries_sub {f g : ℕ → ℂ} {s : ℂ} (hf : LSeriesSummable f s) (hg : LSeriesSummable g s) :
LSeries (f - g) s = LSeries f s - LSeries g s := by
simpa [LSeries, term_sub] using hf.tsum_sub hg
/-!
### Scalar multiplication
-/
lemma LSeries.term_smul (f : ℕ → ℂ) (c s : ℂ) : term (c • f) s = c • term f s := by
ext ⟨- | n⟩ <;>
simp [mul_div_assoc]
lemma LSeries.term_smul_apply (f : ℕ → ℂ) (c s : ℂ) (n : ℕ) :
term (c • f) s n = c * term f s n := by
simp [term_smul]
lemma LSeriesHasSum.smul {f : ℕ → ℂ} (c : ℂ) {s a : ℂ} (hf : LSeriesHasSum f s a) :
LSeriesHasSum (c • f) s (c * a) := by
simpa [LSeriesHasSum, term_smul] using hf.const_smul c
lemma LSeriesSummable.smul {f : ℕ → ℂ} (c : ℂ) {s : ℂ} (hf : LSeriesSummable f s) :
LSeriesSummable (c • f) s := by
simpa [LSeriesSummable, term_smul] using hf.const_smul c
lemma LSeriesSummable.of_smul {f : ℕ → ℂ} {c s : ℂ} (hc : c ≠ 0) (hf : LSeriesSummable (c • f) s) :
LSeriesSummable f s := by
simpa [hc] using hf.smul (c⁻¹)
lemma LSeriesSummable.smul_iff {f : ℕ → ℂ} {c s : ℂ} (hc : c ≠ 0) :
LSeriesSummable (c • f) s ↔ LSeriesSummable f s :=
⟨of_smul hc, smul c⟩
@[simp]
lemma LSeries_smul (f : ℕ → ℂ) (c s : ℂ) : LSeries (c • f) s = c * LSeries f s := by
simp [LSeries, term_smul_apply, tsum_mul_left]
/-!
### Sums
-/
section sum
variable {ι : Type*} (f : ι → ℕ → ℂ) (S : Finset ι) (s : ℂ)
@[simp]
lemma LSeries.term_sum_apply (n : ℕ) :
term (∑ i ∈ S, f i) s n = ∑ i ∈ S, term (f i) s n := by
rcases eq_or_ne n 0 with hn | hn <;>
simp [hn, Finset.sum_div]
lemma LSeries.term_sum : term (∑ i ∈ S, f i) s = ∑ i ∈ S, term (f i) s :=
funext fun _ ↦ by simp
variable {f S s}
lemma LSeriesHasSum.sum {a : ι → ℂ} (hf : ∀ i ∈ S, LSeriesHasSum (f i) s (a i)) :
LSeriesHasSum (∑ i ∈ S, f i) s (∑ i ∈ S, a i) := by
simpa [LSeriesHasSum, term_sum, Finset.sum_fn S fun i ↦ term (f i) s] using hasSum_sum hf
lemma LSeriesSummable.sum (hf : ∀ i ∈ S, LSeriesSummable (f i) s) :
LSeriesSummable (∑ i ∈ S, f i) s := by
simpa [LSeriesSummable, ← term_sum_apply] using summable_sum hf
@[simp]
lemma LSeries_sum (hf : ∀ i ∈ S, LSeriesSummable (f i) s) :
LSeries (∑ i ∈ S, f i) s = ∑ i ∈ S, LSeries (f i) s := by
simpa [LSeries, term_sum] using Summable.tsum_finsetSum hf
end sum |
.lake/packages/mathlib/Mathlib/NumberTheory/LSeries/SumCoeff.lean | import Mathlib.Analysis.Asymptotics.SpecificAsymptotics
import Mathlib.Analysis.InnerProductSpace.Calculus
import Mathlib.Analysis.SpecialFunctions.ImproperIntegrals
import Mathlib.NumberTheory.AbelSummation
import Mathlib.NumberTheory.LSeries.Basic
/-!
# Partial sums of coefficients of L-series
We prove several results involving partial sums of coefficients (or norm of coefficients) of
L-series.
## Main results
* `LSeriesSummable_of_sum_norm_bigO`: for `f : ℕ → ℂ`, if the partial sums
`∑ k ∈ Icc 1 n, ‖f k‖` are `O(n ^ r)` for some real `0 ≤ r`, then the L-series `LSeries f`
converges at `s : ℂ` for all `s` such that `r < s.re`.
* `LSeries_eq_mul_integral` : for `f : ℕ → ℂ`, if the partial sums `∑ k ∈ Icc 1 n, f k` are
`O(n ^ r)` for some real `0 ≤ r` and the L-series `LSeries f` converges at `s : ℂ` with
`r < s.re`, then `LSeries f s = s * ∫ t in Set.Ioi 1, (∑ k ∈ Icc 1 ⌊t⌋₊, f k) * t ^ (-(s + 1))`.
* `LSeries_tendsto_sub_mul_nhds_one_of_tendsto_sum_div` : assume that `f : ℕ → ℂ` satisfies that
`(∑ k ∈ Icc 1 n, f k) / n` tends to some complex number `l` when `n → ∞` and that the L-series
`LSeries f` converges for all `s : ℝ` such that `1 < s`. Then `(s - 1) * LSeries f s` tends
to `l` when `s → 1` with `1 < s`.
-/
open Finset Filter MeasureTheory Topology Complex Asymptotics
section summable
variable {f : ℕ → ℂ} {r : ℝ} {s : ℂ}
private theorem LSeriesSummable_of_sum_norm_bigO_aux (hf : f 0 = 0)
(hO : (fun n ↦ ∑ k ∈ Icc 1 n, ‖f k‖) =O[atTop] fun n ↦ (n : ℝ) ^ r)
(hr : 0 ≤ r) (hs : r < s.re) :
LSeriesSummable f s := by
have h₁ : -s ≠ 0 := neg_ne_zero.mpr <| ne_zero_of_re_pos (hr.trans_lt hs)
have h₂ : (-s).re + r ≤ 0 := by
rw [neg_re, neg_add_nonpos_iff]
exact hs.le
have h₃ (t : ℝ) (ht : t ∈ Set.Ici 1) : DifferentiableAt ℝ (fun x : ℝ ↦ ‖(x : ℂ) ^ (-s)‖) t :=
have ht' : t ≠ 0 := (zero_lt_one.trans_le ht).ne'
(differentiableAt_id.ofReal_cpow_const ht' h₁).norm ℝ <|
(cpow_ne_zero_iff_of_exponent_ne_zero h₁).mpr <| ofReal_ne_zero.mpr ht'
have h₄ : (deriv fun t : ℝ ↦ ‖(t : ℂ) ^ (-s)‖) =ᶠ[atTop] fun t ↦ -s.re * t ^ (-(s.re + 1)) := by
filter_upwards [eventually_gt_atTop 0] with t ht
rw [deriv_norm_ofReal_cpow _ ht, neg_re, neg_add']
simp_rw [LSeriesSummable, funext (LSeries.term_def₀ hf s), mul_comm (f _)]
refine summable_mul_of_bigO_atTop' (f := fun t ↦ (t : ℂ) ^ (-s))
(g := fun t ↦ t ^ (-(s.re + 1) + r)) _ h₃ ?_ ?_ ?_ ?_
· refine (Iff.mpr integrableOn_Ici_iff_integrableOn_Ioi
(integrableOn_Ioi_deriv_norm_ofReal_cpow zero_lt_one ?_)).locallyIntegrableOn
exact neg_re _ ▸ neg_nonpos.mpr <| hr.trans hs.le
· refine (IsBigO.mul_atTop_rpow_natCast_of_isBigO_rpow _ _ _ ?_ hO h₂).congr_right (by simp)
exact (norm_ofReal_cpow_eventually_eq_atTop _).isBigO.natCast_atTop
· refine h₄.isBigO.of_const_mul_right.mul_atTop_rpow_of_isBigO_rpow _ r _ ?_ le_rfl
exact (hO.comp_tendsto tendsto_nat_floor_atTop).trans <|
isEquivalent_nat_floor.isBigO.rpow hr (eventually_ge_atTop 0)
· rwa [integrableAtFilter_rpow_atTop_iff, neg_add_lt_iff_lt_add, add_neg_cancel_right]
/-- If the partial sums `∑ k ∈ Icc 1 n, ‖f k‖` are `O(n ^ r)` for some real `0 ≤ r`, then the
L-series `LSeries f` converges at `s : ℂ` for all `s` such that `r < s.re`. -/
theorem LSeriesSummable_of_sum_norm_bigO
(hO : (fun n ↦ ∑ k ∈ Icc 1 n, ‖f k‖) =O[atTop] fun n ↦ (n : ℝ) ^ r)
(hr : 0 ≤ r) (hs : r < s.re) :
LSeriesSummable f s := by
have h₁ : (fun n ↦ if n = 0 then 0 else f n) =ᶠ[atTop] f := by
filter_upwards [eventually_ne_atTop 0] with n hn using by simp_rw [if_neg hn]
refine (LSeriesSummable_of_sum_norm_bigO_aux (if_pos rfl) ?_ hr hs).congr' _ h₁
refine hO.congr' (Eventually.of_forall fun _ ↦ Finset.sum_congr rfl fun _ h ↦ ?_) EventuallyEq.rfl
rw [if_neg (zero_lt_one.trans_le (mem_Icc.mp h).1).ne']
/-- If `f` takes nonnegative real values and the partial sums `∑ k ∈ Icc 1 n, f k` are `O(n ^ r)`
for some real `0 ≤ r`, then the L-series `LSeries f` converges at `s : ℂ` for all `s`
such that `r < s.re`. -/
theorem LSeriesSummable_of_sum_norm_bigO_and_nonneg
{f : ℕ → ℝ} (hO : (fun n ↦ ∑ k ∈ Icc 1 n, f k) =O[atTop] fun n ↦ (n : ℝ) ^ r)
(hf : ∀ n, 0 ≤ f n) (hr : 0 ≤ r) (hs : r < s.re) :
LSeriesSummable (fun n ↦ f n) s :=
LSeriesSummable_of_sum_norm_bigO (by simpa [abs_of_nonneg (hf _)]) hr hs
end summable
section integralrepresentation
private theorem LSeries_eq_mul_integral_aux {f : ℕ → ℂ} (hf : f 0 = 0) {r : ℝ} (hr : 0 ≤ r) {s : ℂ}
(hs : r < s.re) (hS : LSeriesSummable f s)
(hO : (fun n ↦ ∑ k ∈ Icc 1 n, f k) =O[atTop] fun n ↦ (n : ℝ) ^ r) :
LSeries f s = s * ∫ t in Set.Ioi (1 : ℝ), (∑ k ∈ Icc 1 ⌊t⌋₊, f k) * t ^ (-(s + 1)) := by
have h₁ : (-s - 1).re + r < -1 := by
rwa [sub_re, one_re, neg_re, neg_sub_left, neg_add_lt_iff_lt_add, add_neg_cancel_comm]
have h₂ : s ≠ 0 := ne_zero_of_re_pos (hr.trans_lt hs)
have h₃ (t : ℝ) (ht : t ∈ Set.Ici 1) : DifferentiableAt ℝ (fun x : ℝ ↦ (x : ℂ) ^ (-s)) t :=
differentiableAt_id.ofReal_cpow_const (zero_lt_one.trans_le ht).ne' (neg_ne_zero.mpr h₂)
have h₄ : ∀ n, ∑ k ∈ Icc 0 n, f k = ∑ k ∈ Icc 1 n, f k := fun n ↦ by
rw [← insert_Icc_add_one_left_eq_Icc n.zero_le, sum_insert (by aesop), hf, zero_add, zero_add]
simp_rw [← h₄] at hO
rw [← integral_const_mul]
refine tendsto_nhds_unique ((tendsto_add_atTop_iff_nat 1).mpr hS.hasSum.tendsto_sum_nat) ?_
simp_rw [Nat.range_succ_eq_Icc_zero, LSeries.term_def₀ hf, mul_comm (f _)]
convert tendsto_sum_mul_atTop_nhds_one_sub_integral₀ (f := fun x ↦ (x : ℂ) ^ (-s)) (l := 0)
?_ hf h₃ ?_ ?_ ?_ (integrableAtFilter_rpow_atTop_iff.mpr h₁)
· rw [zero_sub, ← integral_neg]
refine setIntegral_congr_fun measurableSet_Ioi fun t ht ↦ ?_
rw [deriv_ofReal_cpow_const (zero_lt_one.trans ht).ne', h₄]
· ring_nf
· exact neg_ne_zero.mpr <| ne_zero_of_re_pos (hr.trans_lt hs)
· refine (Iff.mpr integrableOn_Ici_iff_integrableOn_Ioi <|
integrableOn_Ioi_deriv_ofReal_cpow zero_lt_one
(by simpa using hr.trans_lt hs)).locallyIntegrableOn
· have hlim : Tendsto (fun n : ℕ ↦ (n : ℝ) ^ (-(s.re - r))) atTop (𝓝 0) :=
(tendsto_rpow_neg_atTop (by rwa [sub_pos])).comp tendsto_natCast_atTop_atTop
refine (IsBigO.mul_atTop_rpow_natCast_of_isBigO_rpow (-s.re) _ _ ?_ hO ?_).trans_tendsto hlim
· exact isBigO_norm_left.mp <| (norm_ofReal_cpow_eventually_eq_atTop _).isBigO.natCast_atTop
· linarith
· refine .mul_atTop_rpow_of_isBigO_rpow (-(s + 1).re) r _ ?_ ?_ (by rw [← neg_re, neg_add'])
· simpa [-neg_add_rev, neg_add'] using isBigO_deriv_ofReal_cpow_const_atTop _
· exact (hO.comp_tendsto tendsto_nat_floor_atTop).trans <|
isEquivalent_nat_floor.isBigO.rpow hr (eventually_ge_atTop 0)
/-- If the partial sums `∑ k ∈ Icc 1 n, f k` are `O(n ^ r)` for some real `0 ≤ r` and the
L-series `LSeries f` converges at `s : ℂ` with `r < s.re`, then
`LSeries f s = s * ∫ t in Set.Ioi 1, (∑ k ∈ Icc 1 ⌊t⌋₊, f k) * t ^ (-(s + 1))`. -/
theorem LSeries_eq_mul_integral (f : ℕ → ℂ) {r : ℝ} (hr : 0 ≤ r) {s : ℂ} (hs : r < s.re)
(hS : LSeriesSummable f s)
(hO : (fun n ↦ ∑ k ∈ Icc 1 n, f k) =O[atTop] fun n ↦ (n : ℝ) ^ r) :
LSeries f s = s * ∫ t in Set.Ioi (1 : ℝ), (∑ k ∈ Icc 1 ⌊t⌋₊, f k) * t ^ (-(s + 1)) := by
rw [← LSeriesSummable_congr' s (f := fun n ↦ if n = 0 then 0 else f n)
(by filter_upwards [eventually_ne_atTop 0] with n h using if_neg h)] at hS
have (n : _) : ∑ k ∈ Icc 1 n, (if k = 0 then 0 else f k) = ∑ k ∈ Icc 1 n, f k :=
Finset.sum_congr rfl fun k hk ↦ by rw [if_neg (zero_lt_one.trans_le (mem_Icc.mp hk).1).ne']
rw [← LSeries_congr fun _ ↦ if_neg _, LSeries_eq_mul_integral_aux (if_pos rfl) hr hs hS] <;>
simp_all
/-- A version of `LSeries_eq_mul_integral` where we use the stronger condition that the partial sums
`∑ k ∈ Icc 1 n, ‖f k‖` are `O(n ^ r)` to deduce the integral representation. -/
theorem LSeries_eq_mul_integral' (f : ℕ → ℂ) {r : ℝ} (hr : 0 ≤ r) {s : ℂ} (hs : r < s.re)
(hO : (fun n ↦ ∑ k ∈ Icc 1 n, ‖f k‖) =O[atTop] fun n ↦ (n : ℝ) ^ r) :
LSeries f s = s * ∫ t in Set.Ioi (1 : ℝ), (∑ k ∈ Icc 1 ⌊t⌋₊, f k) * t ^ (-(s + 1)) :=
LSeries_eq_mul_integral _ hr hs (LSeriesSummable_of_sum_norm_bigO hO hr hs) <|
(isBigO_of_le _ fun _ ↦ (norm_sum_le _ _).trans <| Real.le_norm_self _).trans hO
/-- If `f` takes nonnegative real values and the partial sums `∑ k ∈ Icc 1 n, f k` are `O(n ^ r)`
for some real `0 ≤ r`, then for `s : ℂ` with `r < s.re`, we have
`LSeries f s = s * ∫ t in Set.Ioi 1, (∑ k ∈ Icc 1 ⌊t⌋₊, f k) * t ^ (-(s + 1))`. -/
theorem LSeries_eq_mul_integral_of_nonneg (f : ℕ → ℝ) {r : ℝ} (hr : 0 ≤ r) {s : ℂ} (hs : r < s.re)
(hO : (fun n ↦ ∑ k ∈ Icc 1 n, f k) =O[atTop] fun n ↦ (n : ℝ) ^ r) (hf : ∀ n, 0 ≤ f n) :
LSeries (fun n ↦ f n) s =
s * ∫ t in Set.Ioi (1 : ℝ), (∑ k ∈ Icc 1 ⌊t⌋₊, (f k : ℂ)) * t ^ (-(s + 1)) :=
LSeries_eq_mul_integral' _ hr hs <| hO.congr_left fun _ ↦ by simp [abs_of_nonneg (hf _)]
end integralrepresentation
noncomputable section residue
variable {f : ℕ → ℂ} {l : ℂ}
section lemmas
private theorem lemma₁ (hlim : Tendsto (fun n : ℕ ↦ (∑ k ∈ Icc 1 n, f k) / n) atTop (𝓝 l))
{s : ℝ} (hs : 1 < s) :
IntegrableOn (fun t : ℝ ↦ (∑ k ∈ Icc 1 ⌊t⌋₊, f k) * (t : ℂ) ^ (-(s : ℂ) - 1)) (Set.Ici 1) := by
have h₁ : LocallyIntegrableOn (fun t : ℝ ↦ (∑ k ∈ Icc 1 ⌊t⌋₊, f k) * (t : ℂ) ^ (-(s : ℂ) - 1))
(Set.Ici 1) := by
simp_rw [mul_comm]
refine locallyIntegrableOn_mul_sum_Icc f zero_le_one ?_
refine ContinuousOn.locallyIntegrableOn (fun t ht ↦ ?_) measurableSet_Ici
exact (continuousAt_ofReal_cpow_const _ _ <|
Or.inr (zero_lt_one.trans_le ht).ne').continuousWithinAt
have h₂ : (fun t : ℝ ↦ ∑ k ∈ Icc 1 ⌊t⌋₊, f k) =O[atTop] fun t ↦ t ^ (1 : ℝ) := by
simp_rw [Real.rpow_one]
refine IsBigO.trans_isEquivalent ?_ isEquivalent_nat_floor
have : Tendsto (fun n ↦ (∑ k ∈ Icc 1 n, f k) / ((n : ℝ) ^ (1 : ℝ) : ℝ)) atTop (𝓝 l) := by
simpa using hlim
simpa using (isBigO_atTop_natCast_rpow_of_tendsto_div_rpow this).comp_tendsto
tendsto_nat_floor_atTop
refine h₁.integrableOn_of_isBigO_atTop (g := fun t ↦ t ^ (-s)) ?_ ?_
· refine IsBigO.mul_atTop_rpow_of_isBigO_rpow 1 (-s - 1) _ h₂ ?_ (by linarith)
exact (norm_ofReal_cpow_eventually_eq_atTop _).isBigO.of_norm_left
· rwa [integrableAtFilter_rpow_atTop_iff, neg_lt_neg_iff]
private theorem lemma₂ {s T ε : ℝ} {S : ℝ → ℂ} (hs : 1 < s)
(hS₁ : LocallyIntegrableOn (fun t ↦ S t) (Set.Ici 1)) (hS₂ : ∀ t ≥ T, ‖S t‖ ≤ ε * t) :
IntegrableOn (fun t : ℝ ↦ ‖S t‖ * (t ^ (-s - 1))) (Set.Ici 1) := by
have h : LocallyIntegrableOn (fun t : ℝ ↦ ‖S t‖ * (t ^ (-s - 1))) (Set.Ici 1) := by
refine hS₁.norm.mul_continuousOn ?_ isLocallyClosed_Ici
exact fun t ht ↦ (Real.continuousAt_rpow_const _ _
<| Or.inl (zero_lt_one.trans_le ht).ne').continuousWithinAt
refine h.integrableOn_of_isBigO_atTop (g := fun t ↦ t ^ (-s)) (isBigO_iff.mpr ⟨ε, ?_⟩) ?_
· filter_upwards [eventually_ge_atTop T, eventually_gt_atTop 0] with t ht ht'
simpa [abs_of_nonneg, Real.rpow_nonneg, ht'.le, Real.rpow_sub ht', mul_assoc, ht'.ne',
mul_div_cancel₀] using mul_le_mul_of_nonneg_right (hS₂ t ht) (norm_nonneg <| t ^ (-s - 1))
· exact integrableAtFilter_rpow_atTop_iff.mpr <| neg_lt_neg_iff.mpr hs
end lemmas
section proof
-- See `LSeries_tendsto_sub_mul_nhds_one_of_tendsto_sum_div_aux₃` for the strategy of proof
private theorem LSeries_tendsto_sub_mul_nhds_one_of_tendsto_sum_div_aux₁
(hlim : Tendsto (fun n : ℕ ↦ (∑ k ∈ Icc 1 n, f k) / n) atTop (𝓝 l)) {ε : ℝ} (hε : 0 < ε) :
∀ᶠ t : ℝ in atTop, ‖(∑ k ∈ Icc 1 ⌊t⌋₊, f k) - l * t‖ < ε * t := by
have h_lim' : Tendsto (fun t : ℝ ↦ (∑ k ∈ Icc 1 ⌊t⌋₊, f k : ℂ) / t) atTop (𝓝 l) := by
refine (mul_one l ▸ ofReal_one ▸ ((hlim.comp tendsto_nat_floor_atTop).mul <|
tendsto_ofReal_iff.mpr <| tendsto_nat_floor_div_atTop)).congr' ?_
filter_upwards [eventually_ge_atTop 1] with t ht
simp [div_mul_div_cancel₀ (show (⌊t⌋₊ : ℂ) ≠ 0 by simpa)]
filter_upwards [eventually_gt_atTop 0, Metric.tendsto_nhds.mp h_lim' ε hε] with t ht₁ ht₂
rwa [dist_eq_norm, div_sub' (ne_zero_of_re_pos ht₁), norm_div, norm_real,
Real.norm_of_nonneg ht₁.le, mul_comm, div_lt_iff₀ ht₁] at ht₂
private theorem LSeries_tendsto_sub_mul_nhds_one_of_tendsto_sum_div_aux₂ {s T ε : ℝ} {S : ℝ → ℂ}
(hS : LocallyIntegrableOn (fun t ↦ S t - l * t) (Set.Ici 1)) (hε : 0 < ε)
(hs : 1 < s) (hT₁ : 1 ≤ T) (hT : ∀ t ≥ T, ‖S t - l * t‖ ≤ ε * t) :
(s - 1) * ∫ (t : ℝ) in Set.Ioi T, ‖S t - l * t‖ * t ^ (-s - 1) ≤ ε := by
have hT₀ : 0 < T := zero_lt_one.trans_le hT₁
have h {t : ℝ} (ht : 0 < t) : t ^ (-s) = t * t ^ (-s - 1) := by
rw [Real.rpow_sub ht, Real.rpow_one, mul_div_cancel₀ _ ht.ne']
calc
_ ≤ (s - 1) * ∫ (t : ℝ) in Set.Ioi T, ε * t ^ (-s) := by
refine mul_le_mul_of_nonneg_left (setIntegral_mono_on ?_ ?_ measurableSet_Ioi fun t ht ↦ ?_)
(sub_pos_of_lt hs).le
· exact (lemma₂ hs hS hT).mono_set <| Set.Ioi_subset_Ici_iff.mpr hT₁
· exact (integrableOn_Ioi_rpow_of_lt (neg_lt_neg_iff.mpr hs) hT₀).const_mul _
· have ht' : 0 < t := hT₀.trans ht
rw [h ht', ← mul_assoc]
exact mul_le_mul_of_nonneg_right (hT t ht.le) (Real.rpow_nonneg ht'.le _)
_ ≤ ε * ((s - 1) * ∫ (t : ℝ) in Set.Ioi 1, t ^ (-s)) := by
rw [integral_const_mul, ← mul_assoc, ← mul_assoc, mul_comm ε]
refine mul_le_mul_of_nonneg_left (setIntegral_mono_set ?_ ?_
(Set.Ioi_subset_Ioi hT₁).eventuallyLE) (mul_nonneg (sub_pos_of_lt hs).le hε.le)
· exact integrableOn_Ioi_rpow_of_lt (neg_lt_neg_iff.mpr hs) zero_lt_one
· exact (ae_restrict_iff' measurableSet_Ioi).mpr <| univ_mem' fun t ht ↦
Real.rpow_nonneg (zero_le_one.trans ht.le) _
_ = ε := by
rw [integral_Ioi_rpow_of_lt (by rwa [neg_lt_neg_iff]) zero_lt_one, Real.one_rpow]
field [show -s + 1 ≠ 0 by linarith]
private theorem LSeries_tendsto_sub_mul_nhds_one_of_tendsto_sum_div_aux₃
(hlim : Tendsto (fun n : ℕ ↦ (∑ k ∈ Icc 1 n, f k) / n) atTop (𝓝 l))
(hfS : ∀ s : ℝ, 1 < s → LSeriesSummable f s) {ε : ℝ} (hε : ε > 0) :
∃ C ≥ 0, (fun s : ℝ ↦ ‖(s - 1) * LSeries f s - s * l‖) ≤ᶠ[𝓝[>] 1]
fun s ↦ (s - 1) * s * C + s * ε := by
obtain ⟨T, hT₁, hT⟩ := (eventually_forall_ge_atTop.mpr
(LSeries_tendsto_sub_mul_nhds_one_of_tendsto_sum_div_aux₁
hlim hε)).frequently.forall_exists_of_atTop 1
let S : ℝ → ℂ := fun t ↦ ∑ k ∈ Icc 1 ⌊t⌋₊, f k
let C := ∫ t in Set.Ioc 1 T, ‖S t - l * t‖ * t ^ (-1 - 1 : ℝ)
have hC : 0 ≤ C := by
refine setIntegral_nonneg_ae measurableSet_Ioc (univ_mem' fun t ht ↦ ?_)
exact mul_nonneg (norm_nonneg _) <| Real.rpow_nonneg (zero_le_one.trans ht.1.le) _
refine ⟨C, hC, ?_⟩
filter_upwards [eventually_mem_nhdsWithin] with s hs
rw [Set.mem_Ioi] at hs
have hs' : 0 ≤ (s - 1) * s := mul_nonneg (sub_nonneg.mpr hs.le) (zero_le_one.trans hs.le)
have h₀ : LocallyIntegrableOn (fun t ↦ S t - l * t) (Set.Ici 1) := by
refine .sub ?_ <| ContinuousOn.locallyIntegrableOn (by fun_prop) measurableSet_Ici
simpa using locallyIntegrableOn_mul_sum_Icc f zero_le_one (locallyIntegrableOn_const 1)
have h₁ : IntegrableOn (fun t ↦ ‖S t - l * t‖ * t ^ (-s - 1)) (Set.Ici 1) :=
lemma₂ hs h₀ fun t ht ↦ (hT t ht).le
have h₂ : IntegrableOn (fun t : ℝ ↦ ‖S t - l * t‖ * (t ^ ((-1 : ℝ) - 1))) (Set.Ioc 1 T) := by
refine ((h₀.norm.mul_continuousOn ?_ isLocallyClosed_Ici).integrableOn_compact_subset
Set.Icc_subset_Ici_self isCompact_Icc).mono_set Set.Ioc_subset_Icc_self
exact fun t ht ↦ (Real.continuousAt_rpow_const _ _
<| Or.inl (zero_lt_one.trans_le ht).ne').continuousWithinAt
have h₃ : (s - 1) * ∫ (t : ℝ) in Set.Ioi 1, (t : ℂ) ^ (-s : ℂ) = 1 := by
rw [integral_Ioi_cpow_of_lt (by rwa [neg_re, neg_lt_neg_iff]) zero_lt_one, ofReal_one,
one_cpow, show -(s : ℂ) + 1 = -(s - 1) by ring, neg_div_neg_eq, mul_div_cancel₀]
exact (sub_ne_zero.trans ofReal_ne_one).mpr hs.ne'
let Cs := ∫ t in Set.Ioc 1 T, ‖S t - l * t‖ * t ^ (-s - 1)
have h₄ : Cs ≤ C := by
refine setIntegral_mono_on ?_ h₂ measurableSet_Ioc fun t ht ↦ ?_
· exact h₁.mono_set <| Set.Ioc_subset_Ioi_self.trans Set.Ioi_subset_Ici_self
· gcongr
exact ht.1.le
calc
-- First, we replace `s * l` by `(s - 1) * s` times the integral of `l * t ^ (-s)` using `h₃`
-- and replace `LSeries f s` by its integral representation.
_ = ‖((s - 1) * s * ∫ t in Set.Ioi 1, S t * ↑t ^ (-(s : ℂ) - 1)) -
l * s * ((s - 1) * ∫ (t : ℝ) in Set.Ioi 1, ↑t ^ (-(s : ℂ)))‖ := by
rw [h₃, mul_one, mul_comm l, LSeries_eq_mul_integral _ zero_le_one (by rwa [ofReal_re])
(hfS _ hs), neg_add', mul_assoc]
exact isBigO_atTop_natCast_rpow_of_tendsto_div_rpow (a := l) (by simpa using hlim)
_ = ‖(s - 1) * s * ∫ t in Set.Ioi 1, (S t * (t : ℂ) ^ (-s - 1 : ℂ) - l * t ^ (-s : ℂ))‖ := by
rw [integral_sub, integral_const_mul]
· congr; ring
· exact (lemma₁ hlim hs).mono_set Set.Ioi_subset_Ici_self
· exact (integrableOn_Ioi_cpow_of_lt
(by rwa [neg_re, ofReal_re, neg_lt_neg_iff]) zero_lt_one).const_mul _
_ = ‖(s - 1) * s * ∫ t in Set.Ioi 1, (S t - l * t) * (t : ℂ) ^ (-s - 1 : ℂ)‖ := by
congr 2
refine setIntegral_congr_fun measurableSet_Ioi fun t ht ↦ ?_
replace ht : (t : ℂ) ≠ 0 := ne_zero_of_one_lt_re ht
rw [sub_mul, cpow_sub _ _ ht, cpow_one, mul_assoc, mul_div_cancel₀ _ ht]
_ ≤ (s - 1) * s * ∫ t in Set.Ioi 1, ‖(S t - l * ↑t) * ↑t ^ (-s - 1 : ℂ)‖ := by
rw [norm_mul, show ((s : ℂ) - 1) * s = ((s - 1) * s : ℝ) by simp, norm_real,
Real.norm_of_nonneg hs']
exact mul_le_mul_of_nonneg_left (norm_integral_le_integral_norm _) hs'
-- Next, step is to bound the integral of `‖S t - l * t‖ * t ^ (-s - 1)`.
_ = (s - 1) * s * ∫ t in Set.Ioi 1, ‖S t - l * t‖ * t ^ (-s - 1) := by
congr 1
refine setIntegral_congr_fun measurableSet_Ioi fun t ht ↦ ?_
replace ht : 0 ≤ t := zero_le_one.trans ht.le
rw [norm_mul, show (-(s : ℂ) - 1) = (-s - 1 : ℝ) by simp, ← ofReal_cpow ht, norm_real,
Real.norm_of_nonneg (Real.rpow_nonneg ht _)]
-- For that, we cut the integral in two parts using `T` as the cutting point.
_ = (s - 1) * s * (Cs + ∫ t in Set.Ioi T, ‖S t - l * t‖ * t ^ (-s - 1)) := by
rw [← Set.Ioc_union_Ioi_eq_Ioi hT₁, setIntegral_union Set.Ioc_disjoint_Ioi_same
measurableSet_Ioi]
· exact h₁.mono_set <| Set.Ioc_subset_Ioi_self.trans Set.Ioi_subset_Ici_self
· exact h₁.mono_set <| Set.Ioi_subset_Ici_self.trans <| Set.Ici_subset_Ici.mpr hT₁
-- The first part can be bounded by `C` using `h₄`.
_ ≤ (s - 1) * s * C + s * ((s - 1) * ∫ t in Set.Ioi T, ‖S t - l * t‖ * t ^ (-s - 1)) := by
rw [mul_add, ← mul_assoc, mul_comm s]
gcongr
-- The second part is bounded using `LSeries_tendsto_sub_mul_nhds_one_of_tendsto_sum_div_aux₂`
-- since `‖S t - l t‖ ≤ ε * t` for all `t ≥ T`.
_ ≤ (s - 1) * s * C + s * ε := by
gcongr
exact LSeries_tendsto_sub_mul_nhds_one_of_tendsto_sum_div_aux₂ h₀ hε hs hT₁
fun t ht ↦ (hT t ht.le).le
theorem LSeries_tendsto_sub_mul_nhds_one_of_tendsto_sum_div
(hlim : Tendsto (fun n : ℕ ↦ (∑ k ∈ Icc 1 n, f k) / n) atTop (𝓝 l))
(hfS : ∀ s : ℝ, 1 < s → LSeriesSummable f s) :
Tendsto (fun s : ℝ ↦ (s - 1) * LSeries f s) (𝓝[>] 1) (𝓝 l) := by
have h₁ {C ε : ℝ} : Tendsto (fun s ↦ (s - 1) * s * C + s * ε) (𝓝[>] 1) (𝓝 ε) := by
rw [show 𝓝 ε = 𝓝 ((1 - 1) * 1 * C + 1 * ε) by congr; ring]
exact tendsto_nhdsWithin_of_tendsto_nhds (ContinuousAt.tendsto (by fun_prop))
have h₂ : IsBoundedUnder
(fun x1 x2 ↦ x1 ≤ x2) (𝓝[>] 1) fun s : ℝ ↦ ‖(s - 1) * LSeries f s - s * l‖ := by
obtain ⟨C, _, hC₂⟩ :=
LSeries_tendsto_sub_mul_nhds_one_of_tendsto_sum_div_aux₃ hlim hfS zero_lt_one
exact h₁.isBoundedUnder_le.mono_le hC₂
suffices Tendsto (fun s : ℝ ↦ (s - 1) * LSeries f s - s * l) (𝓝[>] 1) (𝓝 0) by
rw [show 𝓝 l = 𝓝 (0 + 1 * l) by congr; ring]
have h₃ : Tendsto (fun s : ℝ ↦ s * l) (𝓝[>] 1) (𝓝 (1 * l)) :=
tendsto_nhdsWithin_of_tendsto_nhds (ContinuousAt.tendsto (by fun_prop))
exact (this.add h₃).congr fun _ ↦ by ring
refine tendsto_zero_iff_norm_tendsto_zero.mpr <| tendsto_of_le_liminf_of_limsup_le ?_ ?_ h₂ ?_
· exact le_liminf_of_le h₂.isCoboundedUnder_ge (univ_mem' (fun _ ↦ norm_nonneg _))
· refine le_of_forall_pos_le_add fun ε hε ↦ ?_
rw [zero_add]
obtain ⟨C, hC₁, hC₂⟩ := LSeries_tendsto_sub_mul_nhds_one_of_tendsto_sum_div_aux₃ hlim hfS hε
refine le_of_le_of_eq (limsup_le_limsup hC₂ ?_ h₁.isBoundedUnder_le) h₁.limsup_eq
exact isCoboundedUnder_le_of_eventually_le _ (univ_mem' fun _ ↦ norm_nonneg _)
· exact isBoundedUnder_of_eventually_ge (univ_mem' fun _ ↦ norm_nonneg _)
theorem LSeries_tendsto_sub_mul_nhds_one_of_tendsto_sum_div_and_nonneg (f : ℕ → ℝ) {l : ℝ}
(hf : Tendsto (fun n ↦ (∑ k ∈ Icc 1 n, f k) / (n : ℝ)) atTop (𝓝 l))
(hf' : ∀ n, 0 ≤ f n) :
Tendsto (fun s : ℝ ↦ (s - 1) * LSeries (fun n ↦ f n) s) (𝓝[>] 1) (𝓝 l) := by
refine LSeries_tendsto_sub_mul_nhds_one_of_tendsto_sum_div (f := fun n ↦ f n)
(hf.ofReal.congr fun _ ↦ ?_) fun s hs ↦ ?_
· simp
· refine LSeriesSummable_of_sum_norm_bigO_and_nonneg ?_ hf' zero_le_one hs
exact isBigO_atTop_natCast_rpow_of_tendsto_div_rpow (by simpa)
end proof
end residue |
.lake/packages/mathlib/Mathlib/NumberTheory/LSeries/Positivity.lean | import Mathlib.Analysis.Complex.TaylorSeries
import Mathlib.Analysis.Complex.Positivity
import Mathlib.NumberTheory.ArithmeticFunction
import Mathlib.NumberTheory.LSeries.Deriv
/-!
# Positivity of values of L-series
The main results of this file are as follows.
* If `a : ℕ → ℂ` takes nonnegative real values and `a 1 > 0`, then `L a x > 0`
when `x : ℝ` is in the open half-plane of absolute convergence; see
`LSeries.positive` and `ArithmeticFunction.LSeries_positive`.
* If in addition the L-series of `a` agrees on some open right half-plane where it
converges with an entire function `f`, then `f` is positive on the real axis;
see `LSeries.positive_of_eq_differentiable` and
`ArithmeticFunction.LSeries_positive_of_eq_differentiable`.
-/
open scoped ComplexOrder
open Complex
namespace LSeries
/-- If all values of a `ℂ`-valued arithmetic function are nonnegative reals and `x` is a
real number in the domain of absolute convergence, then the `n`th iterated derivative
of the associated L-series is nonnegative real when `n` is even and nonpositive real
when `n` is odd. -/
lemma iteratedDeriv_alternating {a : ℕ → ℂ} (hn : 0 ≤ a) {x : ℝ}
(h : LSeries.abscissaOfAbsConv a < x) (n : ℕ) :
0 ≤ (-1) ^ n * iteratedDeriv n (LSeries a) x := by
rw [LSeries_iteratedDeriv _ h, LSeries, ← mul_assoc, ← pow_add, Even.neg_one_pow ⟨n, rfl⟩,
one_mul]
refine tsum_nonneg fun k ↦ ?_
rw [LSeries.term_def]
split
· exact le_rfl
· refine mul_nonneg ?_ <| (inv_natCast_cpow_ofReal_pos (by assumption) x).le
induction n with
| zero => simpa only [Function.iterate_zero, id_eq] using hn k
| succ n IH =>
rw [Function.iterate_succ_apply']
refine mul_nonneg ?_ IH
simp only [← natCast_log, zero_le_real, Real.log_natCast_nonneg]
/-- If all values of `a : ℕ → ℂ` are nonnegative reals and `a 1` is positive,
then `L a x` is positive real for all real `x` larger than `abscissaOfAbsConv a`. -/
lemma positive {a : ℕ → ℂ} (ha₀ : 0 ≤ a) (ha₁ : 0 < a 1) {x : ℝ} (hx : abscissaOfAbsConv a < x) :
0 < LSeries a x := by
rw [LSeries]
refine Summable.tsum_pos ?_ (fun n ↦ term_nonneg (ha₀ n) x) 1 <| term_pos one_ne_zero ha₁ x
exact LSeriesSummable_of_abscissaOfAbsConv_lt_re <| by simpa only [ofReal_re] using hx
/-- If all values of `a : ℕ → ℂ` are nonnegative reals and `a 1`
is positive, and the L-series of `a` agrees with an entire function `f` on some open
right half-plane where it converges, then `f` is real and positive on `ℝ`. -/
lemma positive_of_differentiable_of_eqOn {a : ℕ → ℂ} (ha₀ : 0 ≤ a) (ha₁ : 0 < a 1) {f : ℂ → ℂ}
(hf : Differentiable ℂ f) {x : ℝ} (hx : abscissaOfAbsConv a ≤ x)
(hf' : {s | x < s.re}.EqOn f (LSeries a)) (y : ℝ) :
0 < f y := by
have hxy : x < max x y + 1 := (le_max_left x y).trans_lt (lt_add_one _)
have hxy' : abscissaOfAbsConv a < max x y + 1 := hx.trans_lt <| mod_cast hxy
have hys : (max x y + 1 : ℂ) ∈ {s | x < s.re} := by
simp only [Set.mem_setOf_eq, add_re, ofReal_re, one_re, hxy]
have hfx : 0 < f (max x y + 1) := by
simpa only [hf' hys, ofReal_add, ofReal_one] using positive ha₀ ha₁ hxy'
refine (hfx.trans_le <| hf.apply_le_of_iteratedDeriv_alternating (fun n _ ↦ ?_) ?_)
· have hs : IsOpen {s : ℂ | x < s.re} := continuous_re.isOpen_preimage _ isOpen_Ioi
simpa only [hf'.iteratedDeriv_of_isOpen hs n hys, ofReal_add, ofReal_one] using
iteratedDeriv_alternating ha₀ hxy' n
· exact_mod_cast (le_max_right x y).trans (lt_add_one _).le
end LSeries
namespace ArithmeticFunction
/-- If all values of a `ℂ`-valued arithmetic function are nonnegative reals and `x` is a
real number in the domain of absolute convergence, then the `n`th iterated derivative
of the associated L-series is nonnegative real when `n` is even and nonpositive real
when `n` is odd. -/
lemma iteratedDeriv_LSeries_alternating (a : ArithmeticFunction ℂ) (hn : ∀ n, 0 ≤ a n) {x : ℝ}
(h : LSeries.abscissaOfAbsConv a < x) (n : ℕ) :
0 ≤ (-1) ^ n * iteratedDeriv n (LSeries (a ·)) x :=
LSeries.iteratedDeriv_alternating hn h n
/-- If all values of a `ℂ`-valued arithmetic function `a` are nonnegative reals and `a 1` is
positive, then `L a x` is positive real for all real `x` larger than `abscissaOfAbsConv a`. -/
lemma LSeries_positive {a : ℕ → ℂ} (ha₀ : 0 ≤ a) (ha₁ : 0 < a 1) {x : ℝ}
(hx : LSeries.abscissaOfAbsConv a < x) :
0 < LSeries a x :=
LSeries.positive ha₀ ha₁ hx
/-- If all values of a `ℂ`-valued arithmetic function `a` are nonnegative reals and `a 1`
is positive, and the L-series of `a` agrees with an entire function `f` on some open
right half-plane where it converges, then `f` is real and positive on `ℝ`. -/
lemma LSeries_positive_of_differentiable_of_eqOn {a : ArithmeticFunction ℂ} (ha₀ : 0 ≤ (a ·))
(ha₁ : 0 < a 1) {f : ℂ → ℂ} (hf : Differentiable ℂ f) {x : ℝ}
(hx : LSeries.abscissaOfAbsConv a ≤ x) (hf' : {s | x < s.re}.EqOn f (LSeries a)) (y : ℝ) :
0 < f y :=
LSeries.positive_of_differentiable_of_eqOn ha₀ ha₁ hf hx hf' y
end ArithmeticFunction |
.lake/packages/mathlib/Mathlib/NumberTheory/LSeries/Convergence.lean | import Mathlib.Data.EReal.Basic
import Mathlib.NumberTheory.LSeries.Basic
/-!
# Convergence of L-series
We define `LSeries.abscissaOfAbsConv f` (as an `EReal`) to be the infimum
of all real numbers `x` such that the L-series of `f` converges for complex arguments with
real part `x` and provide some results about it.
## Tags
L-series, abscissa of convergence
-/
open Complex
/-- The abscissa `x : EReal` of absolute convergence of the L-series associated to `f`:
the series converges absolutely at `s` when `re s > x` and does not converge absolutely
when `re s < x`. -/
noncomputable def LSeries.abscissaOfAbsConv (f : ℕ → ℂ) : EReal :=
sInf <| Real.toEReal '' {x : ℝ | LSeriesSummable f x}
lemma LSeries.abscissaOfAbsConv_congr {f g : ℕ → ℂ} (h : ∀ {n}, n ≠ 0 → f n = g n) :
abscissaOfAbsConv f = abscissaOfAbsConv g :=
congr_arg sInf <| congr_arg _ <| Set.ext fun x ↦ LSeriesSummable_congr x h
open Filter in
/-- If `f` and `g` agree on large `n : ℕ`, then their `LSeries` have the same
abscissa of absolute convergence. -/
lemma LSeries.abscissaOfAbsConv_congr' {f g : ℕ → ℂ} (h : f =ᶠ[atTop] g) :
abscissaOfAbsConv f = abscissaOfAbsConv g :=
congr_arg sInf <| congr_arg _ <| Set.ext fun x ↦ LSeriesSummable_congr' x h
open LSeries
lemma LSeriesSummable_of_abscissaOfAbsConv_lt_re {f : ℕ → ℂ} {s : ℂ}
(hs : abscissaOfAbsConv f < s.re) : LSeriesSummable f s := by
obtain ⟨y, hy, hys⟩ : ∃ a : ℝ, LSeriesSummable f a ∧ a < s.re := by
simpa [abscissaOfAbsConv, sInf_lt_iff] using hs
exact hy.of_re_le_re <| ofReal_re y ▸ hys.le
lemma LSeriesSummable_lt_re_of_abscissaOfAbsConv_lt_re {f : ℕ → ℂ} {s : ℂ}
(hs : abscissaOfAbsConv f < s.re) :
∃ x : ℝ, x < s.re ∧ LSeriesSummable f x := by
obtain ⟨x, hx₁, hx₂⟩ := EReal.exists_between_coe_real hs
exact ⟨x, by simpa using hx₂, LSeriesSummable_of_abscissaOfAbsConv_lt_re hx₁⟩
lemma LSeriesSummable.abscissaOfAbsConv_le {f : ℕ → ℂ} {s : ℂ} (h : LSeriesSummable f s) :
abscissaOfAbsConv f ≤ s.re :=
sInf_le <| by simpa using h.of_re_le_re (by simp)
lemma LSeries.abscissaOfAbsConv_le_of_forall_lt_LSeriesSummable {f : ℕ → ℂ} {x : ℝ}
(h : ∀ y : ℝ, x < y → LSeriesSummable f y) :
abscissaOfAbsConv f ≤ x := by
refine sInf_le_iff.mpr fun y hy ↦ le_of_forall_gt_imp_ge_of_dense fun a ↦ ?_
replace hy : ∀ (a : ℝ), LSeriesSummable f a → y ≤ a := by simpa [mem_lowerBounds] using hy
cases a with
| coe a₀ => exact_mod_cast fun ha ↦ hy a₀ (h a₀ ha)
| bot => simp
| top => simp
lemma LSeries.abscissaOfAbsConv_le_of_forall_lt_LSeriesSummable' {f : ℕ → ℂ} {x : EReal}
(h : ∀ y : ℝ, x < y → LSeriesSummable f y) :
abscissaOfAbsConv f ≤ x := by
cases x with
| coe => exact abscissaOfAbsConv_le_of_forall_lt_LSeriesSummable <| mod_cast h
| top => exact le_top
| bot =>
refine le_of_eq <| sInf_eq_bot.mpr fun y hy ↦ ?_
cases y with
| bot => simp at hy
| coe y => exact ⟨_, ⟨_, h _ <| EReal.bot_lt_coe _, rfl⟩, mod_cast sub_one_lt y⟩
| top => exact ⟨_, ⟨_, h _ <| EReal.bot_lt_coe 0, rfl⟩, EReal.zero_lt_top⟩
/-- If `‖f n‖` is bounded by a constant times `n^x`, then the abscissa of absolute convergence
of `f` is bounded by `x + 1`. -/
lemma LSeries.abscissaOfAbsConv_le_of_le_const_mul_rpow {f : ℕ → ℂ} {x : ℝ}
(h : ∃ C, ∀ n ≠ 0, ‖f n‖ ≤ C * n ^ x) : abscissaOfAbsConv f ≤ x + 1 := by
rw [show x = x + 1 - 1 by ring] at h
by_contra! H
obtain ⟨y, hy₁, hy₂⟩ := EReal.exists_between_coe_real H
exact (LSeriesSummable_of_le_const_mul_rpow (s := y) (EReal.coe_lt_coe_iff.mp hy₁) h
|>.abscissaOfAbsConv_le.trans_lt hy₂).false
open Filter in
/-- If `‖f n‖` is `O(n^x)`, then the abscissa of absolute convergence
of `f` is bounded by `x + 1`. -/
lemma LSeries.abscissaOfAbsConv_le_of_isBigO_rpow {f : ℕ → ℂ} {x : ℝ}
(h : f =O[atTop] fun n ↦ (n : ℝ) ^ x) :
abscissaOfAbsConv f ≤ x + 1 := by
rw [show x = x + 1 - 1 by ring] at h
by_contra! H
obtain ⟨y, hy₁, hy₂⟩ := EReal.exists_between_coe_real H
exact (LSeriesSummable_of_isBigO_rpow (s := y) (EReal.coe_lt_coe_iff.mp hy₁) h
|>.abscissaOfAbsConv_le.trans_lt hy₂).false
/-- If `f` is bounded, then the abscissa of absolute convergence of `f` is bounded above by `1`. -/
lemma LSeries.abscissaOfAbsConv_le_of_le_const {f : ℕ → ℂ} (h : ∃ C, ∀ n ≠ 0, ‖f n‖ ≤ C) :
abscissaOfAbsConv f ≤ 1 := by
simpa using abscissaOfAbsConv_le_of_le_const_mul_rpow (x := 0) (by simpa using h)
open Filter in
/-- If `f` is `O(1)`, then the abscissa of absolute convergence of `f` is bounded above by `1`. -/
lemma LSeries.abscissaOfAbsConv_le_one_of_isBigO_one {f : ℕ → ℂ} (h : f =O[atTop] fun _ ↦ (1 : ℝ)) :
abscissaOfAbsConv f ≤ 1 := by
simpa using abscissaOfAbsConv_le_of_isBigO_rpow (x := 0) (by simpa using h)
/-- If `f` is real-valued and `x` is strictly greater than the abscissa of absolute convergence
of `f`, then the real series `∑' n, f n / n ^ x` converges. -/
lemma LSeries.summable_real_of_abscissaOfAbsConv_lt {f : ℕ → ℝ} {x : ℝ}
(h : abscissaOfAbsConv (f ·) < x) :
Summable fun n : ℕ ↦ f n / (n : ℝ) ^ x := by
have aux : term (f ·) x = fun n ↦ ↑(if n = 0 then 0 else f n / (n : ℝ) ^ x) := by
ext n
simp [term_def, apply_ite ((↑) : ℝ → ℂ), ofReal_cpow n.cast_nonneg]
have := LSeriesSummable_of_abscissaOfAbsConv_lt_re (ofReal_re x ▸ h)
simp only [LSeriesSummable, aux, summable_ofReal] at this
refine this.congr_cofinite ?_
filter_upwards [(Set.finite_singleton 0).compl_mem_cofinite] with n hn
using if_neg (by simpa using hn)
/-- If `F` is a binary operation on `ℕ → ℂ` with the property that the `LSeries` of `F f g`
converges whenever the `LSeries` of `f` and `g` do, then the abscissa of absolute convergence
of `F f g` is at most the maximum of the abscissa of absolute convergence of `f`
and that of `g`. -/
lemma LSeries.abscissaOfAbsConv_binop_le {F : (ℕ → ℂ) → (ℕ → ℂ) → (ℕ → ℂ)}
(hF : ∀ {f g s}, LSeriesSummable f s → LSeriesSummable g s → LSeriesSummable (F f g) s)
(f g : ℕ → ℂ) :
abscissaOfAbsConv (F f g) ≤ max (abscissaOfAbsConv f) (abscissaOfAbsConv g) := by
refine abscissaOfAbsConv_le_of_forall_lt_LSeriesSummable' fun x hx ↦ hF ?_ ?_
· exact LSeriesSummable_of_abscissaOfAbsConv_lt_re <|
(ofReal_re x).symm ▸ (le_max_left ..).trans_lt hx
· exact LSeriesSummable_of_abscissaOfAbsConv_lt_re <|
(ofReal_re x).symm ▸ (le_max_right ..).trans_lt hx |
.lake/packages/mathlib/Mathlib/NumberTheory/LSeries/Injectivity.lean | import Mathlib.Analysis.Normed.Group.Tannery
import Mathlib.NumberTheory.LSeries.Convergence
import Mathlib.NumberTheory.LSeries.Linearity
/-!
# A converging L-series determines its coefficients
We show that two functions `f` and `g : ℕ → ℂ` whose L-series agree and both converge somewhere
must agree on all nonzero arguments. See `LSeries_eq_iff_of_abscissaOfAbsConv_lt_top`
and `LSeries_injOn`.
-/
open LSeries Complex
-- The following two lemmas need both `LSeries.Linearity` and `LSeries.Convergence`,
-- so cannot live in either of these files.
/-- The abscissa of absolute convergence of `f + g` is at most the maximum of those
of `f` and `g`. -/
lemma LSeries.abscissaOfAbsConv_add_le (f g : ℕ → ℂ) :
abscissaOfAbsConv (f + g) ≤ max (abscissaOfAbsConv f) (abscissaOfAbsConv g) :=
abscissaOfAbsConv_binop_le LSeriesSummable.add f g
/-- The abscissa of absolute convergence of `f - g` is at most the maximum of those
of `f` and `g`. -/
lemma LSeries.abscissaOfAbsConv_sub_le (f g : ℕ → ℂ) :
abscissaOfAbsConv (f - g) ≤ max (abscissaOfAbsConv f) (abscissaOfAbsConv g) :=
abscissaOfAbsConv_binop_le LSeriesSummable.sub f g
private
lemma cpow_mul_div_cpow_eq_div_div_cpow (m n : ℕ) (z : ℂ) (x : ℝ) :
(n + 1) ^ (x : ℂ) * (z / m ^ (x : ℂ)) = z / (m / (n + 1)) ^ (x : ℂ) := by
have Hn : (0 : ℝ) ≤ (n + 1 : ℝ)⁻¹ := by positivity
rw [← mul_div_assoc, mul_comm, div_eq_mul_inv z, mul_div_assoc]
congr
simp_rw [div_eq_mul_inv]
rw [show (n + 1 : ℂ)⁻¹ = (n + 1 : ℝ)⁻¹ by simp,
show (n + 1 : ℂ) = (n + 1 : ℝ) by norm_cast, show (m : ℂ) = (m : ℝ) by norm_cast,
mul_cpow_ofReal_nonneg m.cast_nonneg Hn, mul_inv, mul_comm]
congr
rw [← cpow_neg, show (-x : ℂ) = (-1 : ℝ) * x by simp, cpow_mul_ofReal_nonneg Hn,
Real.rpow_neg_one, inv_inv]
open Filter Real in
/-- If the coefficients `f m` of an L-series are zero for `m ≤ n` and the L-series converges
at some point, then `f (n+1)` is the limit of `(n+1)^x * LSeries f x` as `x → ∞`. -/
lemma LSeries.tendsto_cpow_mul_atTop {f : ℕ → ℂ} {n : ℕ} (h : ∀ m ≤ n, f m = 0)
(ha : abscissaOfAbsConv f < ⊤) :
Tendsto (fun x : ℝ ↦ (n + 1) ^ (x : ℂ) * LSeries f x) atTop (nhds (f (n + 1))) := by
obtain ⟨y, hay, hyt⟩ := exists_between ha
lift y to ℝ using ⟨hyt.ne, ((OrderBot.bot_le _).trans_lt hay).ne'⟩
-- `F x m` is the `m`th term of `(n+1)^x * LSeries f x`, except that `F x (n+1) = 0`
let F := fun (x : ℝ) ↦ {m | n + 1 < m}.indicator (fun m ↦ f m / (m / (n + 1) : ℂ) ^ (x : ℂ))
have hF₀ (x : ℝ) {m : ℕ} (hm : m ≤ n + 1) : F x m = 0 := by simp [F, not_lt_of_ge hm]
have hF (x : ℝ) {m : ℕ} (hm : m ≠ n + 1) : F x m = ((n + 1) ^ (x : ℂ)) * term f x m := by
rcases lt_trichotomy m (n + 1) with H | rfl | H
· simp [Nat.not_lt_of_gt H, term, h m <| Nat.lt_succ_iff.mp H, F]
· exact (hm rfl).elim
· simp [H, term, (n.zero_lt_succ.trans H).ne', F, cpow_mul_div_cpow_eq_div_div_cpow]
have hs {x : ℝ} (hx : x ≥ y) : Summable fun m ↦ (n + 1) ^ (x : ℂ) * term f x m := by
refine (summable_mul_left_iff <| natCast_add_one_cpow_ne_zero n _).mpr <|
LSeriesSummable_of_abscissaOfAbsConv_lt_re ?_
simpa only [ofReal_re] using hay.trans_le <| EReal.coe_le_coe_iff.mpr hx
-- we can write `(n+1)^x * LSeries f x` as `f (n+1)` plus the series over `F x`
have key : ∀ x ≥ y, (n + 1) ^ (x : ℂ) * LSeries f x = f (n + 1) + ∑' m : ℕ, F x m := by
intro x hx
rw [LSeries, ← tsum_mul_left, (hs hx).tsum_eq_add_tsum_ite (n + 1), pow_mul_term_eq f x n]
congr
ext1 m
rcases eq_or_ne m (n + 1) with rfl | hm
· simp [hF₀ x le_rfl]
· simp [hm, hF]
-- reduce to showing that `∑' m, F x m → 0` as `x → ∞`
conv => enter [3, 1]; rw [← add_zero (f _)]
refine Tendsto.congr'
(eventuallyEq_of_mem (s := {x | y ≤ x}) (mem_atTop y) key).symm <| tendsto_const_nhds.add ?_
-- get the prerequisites for applying dominated convergence
have hys : Summable (F y) := by
refine ((hs le_rfl).indicator {m | n + 1 < m}).congr fun m ↦ ?_
by_cases! hm : n + 1 < m
· simp [hF, hm, hm.ne']
· simp [hm, hF₀ _ hm]
have hc (k : ℕ) : Tendsto (F · k) atTop (nhds 0) := by
rcases lt_or_ge (n + 1) k with H | H
· have H₀ : (0 : ℝ) ≤ k / (n + 1) := by positivity
have H₀' : (0 : ℝ) ≤ (n + 1) / k := by positivity
have H₁ : (k / (n + 1) : ℂ) = (k / (n + 1) : ℝ) := by push_cast; rfl
have H₂ : (n + 1) / k < (1 : ℝ) :=
(div_lt_one <| mod_cast n.succ_pos.trans H).mpr <| mod_cast H
simp only [Set.mem_setOf_eq, H, Set.indicator_of_mem, F]
conv =>
enter [1, x]
rw [div_eq_mul_inv, H₁, ← ofReal_cpow H₀, ← ofReal_inv, ← Real.inv_rpow H₀, inv_div]
conv => enter [3, 1]; rw [← mul_zero (f k)]
exact
(tendsto_rpow_atTop_of_base_lt_one _ (neg_one_lt_zero.trans_le H₀') H₂).ofReal.const_mul _
· simp [hF₀ _ H]
rw [show (0 : ℂ) = tsum (fun _ : ℕ ↦ 0) from tsum_zero.symm]
refine tendsto_tsum_of_dominated_convergence hys.norm hc <| eventually_iff.mpr ?_
filter_upwards [mem_atTop y] with y' hy' k
-- it remains to show that `‖F y' k‖ ≤ ‖F y k‖` (for `y' ≥ y`)
rcases lt_or_ge (n + 1) k with H | H
· simp only [Set.mem_setOf_eq, H, Set.indicator_of_mem, norm_div, norm_cpow_real,
Complex.norm_natCast, F]
rw [← Nat.cast_one, ← Nat.cast_add, Complex.norm_natCast]
have hkn : 1 ≤ (k / (n + 1 :) : ℝ) :=
(one_le_div (by positivity)).mpr <| mod_cast Nat.le_of_succ_le H
gcongr
assumption
· simp [hF₀ _ H]
open Filter in
/-- If the L-series of `f` converges at some point, then `f 1` is the limit of `LSeries f x`
as `x → ∞`. -/
lemma LSeries.tendsto_atTop {f : ℕ → ℂ} (ha : abscissaOfAbsConv f < ⊤) :
Tendsto (fun x : ℝ ↦ LSeries f x) atTop (nhds (f 1)) := by
let F (n : ℕ) : ℂ := if n = 0 then 0 else f n
have hF₀ : F 0 = 0 := rfl
have hF {n : ℕ} (hn : n ≠ 0) : F n = f n := if_neg hn
have ha' : abscissaOfAbsConv F < ⊤ := (abscissaOfAbsConv_congr hF).symm ▸ ha
simp_rw [← LSeries_congr hF]
convert LSeries.tendsto_cpow_mul_atTop (n := 0) (fun _ hm ↦ Nat.le_zero.mp hm ▸ hF₀) ha' using 1
simp
lemma LSeries_eq_zero_of_abscissaOfAbsConv_eq_top {f : ℕ → ℂ} (h : abscissaOfAbsConv f = ⊤) :
LSeries f = 0 := by
ext1 s
exact LSeries.eq_zero_of_not_LSeriesSummable f s <| mt LSeriesSummable.abscissaOfAbsConv_le <|
h ▸ fun H ↦ (H.trans_lt <| EReal.coe_lt_top _).false
open Filter Nat in
/-- The `LSeries` of `f` is zero for large real arguments if and only if either `f n = 0`
for all `n ≠ 0` or the L-series converges nowhere. -/
lemma LSeries_eventually_eq_zero_iff' {f : ℕ → ℂ} :
(fun x : ℝ ↦ LSeries f x) =ᶠ[atTop] 0 ↔ (∀ n ≠ 0, f n = 0) ∨ abscissaOfAbsConv f = ⊤ := by
by_cases h : abscissaOfAbsConv f = ⊤
· simpa [h] using
Eventually.of_forall <| by simp [LSeries_eq_zero_of_abscissaOfAbsConv_eq_top h]
· simp only [ne_eq, h, or_false]
refine ⟨fun H ↦ ?_, fun H ↦ Eventually.of_forall fun x ↦ ?_⟩
· let F (n : ℕ) : ℂ := if n = 0 then 0 else f n
have hF₀ : F 0 = 0 := rfl
have hF {n : ℕ} (hn : n ≠ 0) : F n = f n := if_neg hn
suffices ∀ n, F n = 0 from fun n hn ↦ (hF hn).symm.trans (this n)
have ha : ¬ abscissaOfAbsConv F = ⊤ := abscissaOfAbsConv_congr hF ▸ h
have h' (x : ℝ) : LSeries F x = LSeries f x := LSeries_congr hF x
have H' (n : ℕ) : (fun x : ℝ ↦ n ^ (x : ℂ) * LSeries F x) =ᶠ[atTop] fun _ ↦ 0 := by
simp only [h']
rw [eventuallyEq_iff_exists_mem] at H ⊢
obtain ⟨s, hs⟩ := H
exact ⟨s, hs.1, fun x hx ↦ by simp [hs.2 hx]⟩
intro n
induction n using Nat.strongRecOn with | ind n ih =>
-- it suffices to show that `n ^ x * LSeries F x` tends to `F n` as `x` tends to `∞`
suffices Tendsto (fun x : ℝ ↦ n ^ (x : ℂ) * LSeries F x) atTop (nhds (F n)) by
replace this := this.congr' <| H' n
simp only [tendsto_const_nhds_iff] at this
exact this.symm
cases n with
| zero => exact Tendsto.congr' (H' 0).symm <| by simp [hF₀]
| succ n =>
simpa using LSeries.tendsto_cpow_mul_atTop (fun m hm ↦ ih m <| lt_succ_of_le hm) <|
Ne.lt_top ha
· simp [LSeries_congr (fun {n} ↦ H n) x, show (fun _ : ℕ ↦ (0 : ℂ)) = 0 from rfl]
open Nat in
/-- Assuming `f 0 = 0`, the `LSeries` of `f` is zero if and only if either `f = 0` or the
L-series converges nowhere. -/
lemma LSeries_eq_zero_iff {f : ℕ → ℂ} (hf : f 0 = 0) :
LSeries f = 0 ↔ f = 0 ∨ abscissaOfAbsConv f = ⊤ := by
by_cases h : abscissaOfAbsConv f = ⊤
· simpa [h] using LSeries_eq_zero_of_abscissaOfAbsConv_eq_top h
· simp only [h, or_false]
refine ⟨fun H ↦ ?_, fun H ↦ H ▸ LSeries_zero⟩
convert (LSeries_eventually_eq_zero_iff'.mp ?_).resolve_right h
· refine ⟨fun H' _ _ ↦ by rw [H', Pi.zero_apply], fun H' ↦ ?_⟩
ext (- | m)
· simp [hf]
· simp [H']
· simpa only [H] using Filter.EventuallyEq.rfl
open Filter in
/-- If the `LSeries` of `f` and of `g` converge somewhere and agree on large real arguments,
then the L-series of `f - g` is zero for large real arguments. -/
lemma LSeries_sub_eventuallyEq_zero_of_LSeries_eventually_eq {f g : ℕ → ℂ}
(hf : abscissaOfAbsConv f < ⊤) (hg : abscissaOfAbsConv g < ⊤)
(h : (fun x : ℝ ↦ LSeries f x) =ᶠ[atTop] fun x ↦ LSeries g x) :
(fun x : ℝ ↦ LSeries (f - g) x) =ᶠ[atTop] (0 : ℝ → ℂ) := by
rw [EventuallyEq, eventually_atTop] at h ⊢
obtain ⟨x₀, hx₀⟩ := h
obtain ⟨yf, hyf₁, hyf₂⟩ := exists_between hf
obtain ⟨yg, hyg₁, hyg₂⟩ := exists_between hg
lift yf to ℝ using ⟨hyf₂.ne, ((OrderBot.bot_le _).trans_lt hyf₁).ne'⟩
lift yg to ℝ using ⟨hyg₂.ne, ((OrderBot.bot_le _).trans_lt hyg₁).ne'⟩
refine ⟨max x₀ (max yf yg), fun x hx ↦ ?_⟩
have Hf : LSeriesSummable f x := by
refine LSeriesSummable_of_abscissaOfAbsConv_lt_re <|
(ofReal_re x).symm ▸ hyf₁.trans_le (EReal.coe_le_coe_iff.mpr ?_)
exact (le_max_left _ yg).trans <| (le_max_right x₀ _).trans hx
have Hg : LSeriesSummable g x := by
refine LSeriesSummable_of_abscissaOfAbsConv_lt_re <|
(ofReal_re x).symm ▸ hyg₁.trans_le (EReal.coe_le_coe_iff.mpr ?_)
exact (le_max_right yf _).trans <| (le_max_right x₀ _).trans hx
rw [LSeries_sub Hf Hg, hx₀ x <| (le_max_left ..).trans hx, sub_self, Pi.zero_apply]
open Filter in
/-- If the `LSeries` of `f` and of `g` converge somewhere and agree on large real arguments,
then `f n = g n` whenever `n ≠ 0`. -/
lemma LSeries.eq_of_LSeries_eventually_eq {f g : ℕ → ℂ} (hf : abscissaOfAbsConv f < ⊤)
(hg : abscissaOfAbsConv g < ⊤) (h : (fun x : ℝ ↦ LSeries f x) =ᶠ[atTop] fun x ↦ LSeries g x)
{n : ℕ} (hn : n ≠ 0) :
f n = g n := by
have hsub : (fun x : ℝ ↦ LSeries (f - g) x) =ᶠ[atTop] (0 : ℝ → ℂ) :=
LSeries_sub_eventuallyEq_zero_of_LSeries_eventually_eq hf hg h
have ha : abscissaOfAbsConv (f - g) ≠ ⊤ :=
lt_top_iff_ne_top.mp <| (abscissaOfAbsConv_sub_le f g).trans_lt <| max_lt hf hg
simpa only [Pi.sub_apply, sub_eq_zero]
using (LSeries_eventually_eq_zero_iff'.mp hsub).resolve_right ha n hn
/-- If the `LSeries` of `f` and of `g` both converge somewhere, then they are equal if and only
if `f n = g n` whenever `n ≠ 0`. -/
lemma LSeries_eq_iff_of_abscissaOfAbsConv_lt_top {f g : ℕ → ℂ} (hf : abscissaOfAbsConv f < ⊤)
(hg : abscissaOfAbsConv g < ⊤) :
LSeries f = LSeries g ↔ ∀ n ≠ 0, f n = g n := by
refine ⟨fun H n hn ↦ ?_, fun H ↦ funext (LSeries_congr fun {n} ↦ H n)⟩
refine eq_of_LSeries_eventually_eq hf hg ?_ hn
exact Filter.Eventually.of_forall fun x ↦ congr_fun H x
/-- The map `f ↦ LSeries f` is injective on functions `f` such that `f 0 = 0` and the L-series
of `f` converges somewhere. -/
lemma LSeries_injOn : Set.InjOn LSeries {f | f 0 = 0 ∧ abscissaOfAbsConv f < ⊤} := by
intro f hf g hg h
simp only [Set.mem_setOf] at hf hg
replace h := (LSeries_eq_iff_of_abscissaOfAbsConv_lt_top hf.2 hg.2).mp h
ext1 n
cases n with
| zero => exact hf.1.trans hg.1.symm
| succ n => exact h _ n.zero_ne_add_one.symm |
.lake/packages/mathlib/Mathlib/NumberTheory/LSeries/HurwitzZetaOdd.lean | import Mathlib.NumberTheory.LSeries.AbstractFuncEq
import Mathlib.NumberTheory.ModularForms.JacobiTheta.Bounds
import Mathlib.NumberTheory.LSeries.MellinEqDirichlet
import Mathlib.NumberTheory.LSeries.Basic
/-!
# Odd Hurwitz zeta functions
In this file we study the functions on `ℂ` which are the analytic continuation of the following
series (convergent for `1 < re s`), where `a ∈ ℝ` is a parameter:
`hurwitzZetaOdd a s = 1 / 2 * ∑' n : ℤ, sgn (n + a) / |n + a| ^ s`
and
`sinZeta a s = ∑' n : ℕ, sin (2 * π * a * n) / n ^ s`.
The term for `n = -a` in the first sum is understood as 0 if `a` is an integer, as is the term for
`n = 0` in the second sum (for all `a`). Note that these functions are differentiable everywhere,
unlike their even counterparts which have poles.
Of course, we cannot *define* these functions by the above formulae (since existence of the
analytic continuation is not at all obvious); we in fact construct them as Mellin transforms of
various versions of the Jacobi theta function.
## Main definitions and theorems
* `completedHurwitzZetaOdd`: the completed Hurwitz zeta function
* `completedSinZeta`: the completed cosine zeta function
* `differentiable_completedHurwitzZetaOdd` and `differentiable_completedSinZeta`:
differentiability on `ℂ`
* `completedHurwitzZetaOdd_one_sub`: the functional equation
`completedHurwitzZetaOdd a (1 - s) = completedSinZeta a s`
* `hasSum_int_hurwitzZetaOdd` and `hasSum_nat_sinZeta`: relation between
the zeta functions and corresponding Dirichlet series for `1 < re s`
-/
noncomputable section
open Complex
open CharZero Filter Topology Asymptotics Real Set MeasureTheory
open scoped ComplexConjugate
namespace HurwitzZeta
section kernel_defs
/-!
## Definitions and elementary properties of kernels
-/
/-- Variant of `jacobiTheta₂'` which we introduce to simplify some formulae. -/
def jacobiTheta₂'' (z τ : ℂ) : ℂ :=
cexp (π * I * z ^ 2 * τ) * (jacobiTheta₂' (z * τ) τ / (2 * π * I) + z * jacobiTheta₂ (z * τ) τ)
lemma jacobiTheta₂''_conj (z τ : ℂ) :
conj (jacobiTheta₂'' z τ) = jacobiTheta₂'' (conj z) (-conj τ) := by
simp [jacobiTheta₂'', jacobiTheta₂'_conj, jacobiTheta₂_conj, ← exp_conj, map_ofNat, div_neg,
neg_div, jacobiTheta₂'_neg_left]
/-- Restatement of `jacobiTheta₂'_add_left'`: the function `jacobiTheta₂''` is 1-periodic in `z`. -/
lemma jacobiTheta₂''_add_left (z τ : ℂ) : jacobiTheta₂'' (z + 1) τ = jacobiTheta₂'' z τ := by
simp only [jacobiTheta₂'', add_mul z 1, one_mul, jacobiTheta₂'_add_left', jacobiTheta₂_add_left']
generalize jacobiTheta₂ (z * τ) τ = J
generalize jacobiTheta₂' (z * τ) τ = J'
-- clear denominator
simp_rw [div_add' _ _ _ two_pi_I_ne_zero, ← mul_div_assoc]
refine congr_arg (· / (2 * π * I)) ?_
-- get all exponential terms to left
rw [mul_left_comm _ (cexp _), ← mul_add, mul_assoc (cexp _), ← mul_add, ← mul_assoc (cexp _),
← Complex.exp_add]
congrm (cexp ?_ * ?_) <;> ring
lemma jacobiTheta₂''_neg_left (z τ : ℂ) : jacobiTheta₂'' (-z) τ = -jacobiTheta₂'' z τ := by
simp [jacobiTheta₂'', jacobiTheta₂'_neg_left, neg_div, -neg_add_rev, ← neg_add]
lemma jacobiTheta₂'_functional_equation' (z τ : ℂ) :
jacobiTheta₂' z τ = (-2 * π) / (-I * τ) ^ (3 / 2 : ℂ) * jacobiTheta₂'' z (-1 / τ) := by
rcases eq_or_ne τ 0 with rfl | hτ
· rw [jacobiTheta₂'_undef _ (by simp), mul_zero, zero_cpow (by simp), div_zero, zero_mul]
have aux1 : (-2 * π : ℂ) / (2 * π * I) = I := by
rw [div_eq_iff two_pi_I_ne_zero, mul_comm I, mul_assoc _ I I, I_mul_I, neg_mul, mul_neg,
mul_one]
rw [jacobiTheta₂'_functional_equation, ← mul_one_div _ τ, mul_right_comm _ (cexp _),
(by rw [cpow_one, ← div_div, div_self (neg_ne_zero.mpr I_ne_zero)] :
1 / τ = -I / (-I * τ) ^ (1 : ℂ)), div_mul_div_comm,
← cpow_add _ _ (mul_ne_zero (neg_ne_zero.mpr I_ne_zero) hτ), ← div_mul_eq_mul_div,
(by norm_num : (1 / 2 + 1 : ℂ) = 3 / 2), mul_assoc (1 / _), mul_assoc (1 / _),
← mul_one_div (-2 * π : ℂ), mul_comm _ (1 / _), mul_assoc (1 / _)]
congr 1
rw [jacobiTheta₂'', div_add' _ _ _ two_pi_I_ne_zero, ← mul_div_assoc, ← mul_div_assoc,
← div_mul_eq_mul_div (-2 * π : ℂ), mul_assoc, aux1, mul_div z (-1), mul_neg_one, neg_div τ z,
jacobiTheta₂_neg_left, jacobiTheta₂'_neg_left, neg_mul, ← mul_neg, ← mul_neg,
mul_div, mul_neg_one, neg_div, neg_mul, neg_mul, neg_div]
congr 2
rw [neg_sub, ← sub_eq_neg_add, mul_comm _ (_ * I), ← mul_assoc]
/-- Odd Hurwitz zeta kernel (function whose Mellin transform will be the odd part of the completed
Hurwitz zeta function). See `oddKernel_def` for the defining formula, and `hasSum_int_oddKernel`
for an expression as a sum over `ℤ`.
-/
@[irreducible] def oddKernel (a : UnitAddCircle) (x : ℝ) : ℝ :=
(show Function.Periodic (fun a : ℝ ↦ re (jacobiTheta₂'' a (I * x))) 1 by
simp [jacobiTheta₂''_add_left]).lift a
lemma oddKernel_def (a x : ℝ) : ↑(oddKernel a x) = jacobiTheta₂'' a (I * x) := by
simp [oddKernel, ← conj_eq_iff_re, jacobiTheta₂''_conj]
lemma oddKernel_def' (a x : ℝ) : ↑(oddKernel ↑a x) = cexp (-π * a ^ 2 * x) *
(jacobiTheta₂' (a * I * x) (I * x) / (2 * π * I) + a * jacobiTheta₂ (a * I * x) (I * x)) := by
rw [oddKernel_def, jacobiTheta₂'', ← mul_assoc ↑a I x,
(by ring : ↑π * I * ↑a ^ 2 * (I * ↑x) = I ^ 2 * ↑π * ↑a ^ 2 * x), I_sq, neg_one_mul]
lemma oddKernel_undef (a : UnitAddCircle) {x : ℝ} (hx : x ≤ 0) : oddKernel a x = 0 := by
induction a using QuotientAddGroup.induction_on with | H a' =>
rw [← ofReal_eq_zero, oddKernel_def', jacobiTheta₂_undef, jacobiTheta₂'_undef, zero_div, zero_add,
mul_zero, mul_zero] <;>
simpa
/-- Auxiliary function appearing in the functional equation for the odd Hurwitz zeta kernel, equal
to `∑ (n : ℕ), 2 * n * sin (2 * π * n * a) * exp (-π * n ^ 2 * x)`. See `hasSum_nat_sinKernel`
for the defining sum. -/
@[irreducible] def sinKernel (a : UnitAddCircle) (x : ℝ) : ℝ :=
(show Function.Periodic (fun ξ : ℝ ↦ re (jacobiTheta₂' ξ (I * x) / (-2 * π))) 1 by
simp [jacobiTheta₂'_add_left]).lift a
lemma sinKernel_def (a x : ℝ) : ↑(sinKernel ↑a x) = jacobiTheta₂' a (I * x) / (-2 * π) := by
simp [sinKernel, re_eq_add_conj, jacobiTheta₂'_conj, map_ofNat]
lemma sinKernel_undef (a : UnitAddCircle) {x : ℝ} (hx : x ≤ 0) : sinKernel a x = 0 := by
induction a using QuotientAddGroup.induction_on with
| H a => rw [← ofReal_eq_zero, sinKernel_def, jacobiTheta₂'_undef _ (by simpa), zero_div]
lemma oddKernel_neg (a : UnitAddCircle) (x : ℝ) : oddKernel (-a) x = -oddKernel a x := by
induction a using QuotientAddGroup.induction_on with
| H a => simp [← ofReal_inj, ← QuotientAddGroup.mk_neg, oddKernel_def, jacobiTheta₂''_neg_left]
@[simp] lemma oddKernel_zero (x : ℝ) : oddKernel 0 x = 0 := by
simpa using oddKernel_neg 0 x
lemma sinKernel_neg (a : UnitAddCircle) (x : ℝ) :
sinKernel (-a) x = -sinKernel a x := by
induction a using QuotientAddGroup.induction_on with
| H a => simp [← ofReal_inj, ← QuotientAddGroup.mk_neg, sinKernel_def, jacobiTheta₂'_neg_left,
neg_div]
@[simp] lemma sinKernel_zero (x : ℝ) : sinKernel 0 x = 0 := by
simpa using sinKernel_neg 0 x
/-- The odd kernel is continuous on `Ioi 0`. -/
lemma continuousOn_oddKernel (a : UnitAddCircle) : ContinuousOn (oddKernel a) (Ioi 0) := by
induction a using QuotientAddGroup.induction_on with | H a =>
suffices ContinuousOn (fun x ↦ (oddKernel a x : ℂ)) (Ioi 0) from
(continuous_re.comp_continuousOn this).congr fun a _ ↦ (ofReal_re _).symm
simp_rw [oddKernel_def' a]
refine fun x hx ↦ ((Continuous.continuousAt ?_).mul ?_).continuousWithinAt
· fun_prop
· have hf : Continuous fun u : ℝ ↦ (a * I * u, I * u) := by fun_prop
apply ContinuousAt.add
· exact ((continuousAt_jacobiTheta₂' (a * I * x) (by rwa [I_mul_im, ofReal_re])).comp
(f := fun u : ℝ ↦ (a * I * u, I * u)) hf.continuousAt).div_const _
· exact continuousAt_const.mul <| (continuousAt_jacobiTheta₂ (a * I * x)
(by rwa [I_mul_im, ofReal_re])).comp (f := fun u : ℝ ↦ (a * I * u, I * u)) hf.continuousAt
lemma continuousOn_sinKernel (a : UnitAddCircle) : ContinuousOn (sinKernel a) (Ioi 0) := by
induction a using QuotientAddGroup.induction_on with | H a =>
suffices ContinuousOn (fun x ↦ (sinKernel a x : ℂ)) (Ioi 0) from
(continuous_re.comp_continuousOn this).congr fun a _ ↦ (ofReal_re _).symm
simp_rw [sinKernel_def]
apply (continuousOn_of_forall_continuousAt (fun x hx ↦ ?_)).div_const
have h := continuousAt_jacobiTheta₂' a (by rwa [I_mul_im, ofReal_re])
fun_prop
lemma oddKernel_functional_equation (a : UnitAddCircle) (x : ℝ) :
oddKernel a x = 1 / x ^ (3 / 2 : ℝ) * sinKernel a (1 / x) := by
-- first reduce to `0 < x`
rcases le_or_gt x 0 with hx | hx
· rw [oddKernel_undef _ hx, sinKernel_undef _ (one_div_nonpos.mpr hx), mul_zero]
induction a using QuotientAddGroup.induction_on with | H a =>
have h1 : -1 / (I * ↑(1 / x)) = I * x := by rw [one_div, ofReal_inv, mul_comm, ← div_div,
div_inv_eq_mul, div_eq_mul_inv, inv_I, mul_neg, neg_one_mul, neg_mul, neg_neg, mul_comm]
have h2 : (-I * (I * ↑(1 / x))) = 1 / x := by
rw [← mul_assoc, neg_mul, I_mul_I, neg_neg, one_mul, ofReal_div, ofReal_one]
have h3 : (x : ℂ) ^ (3 / 2 : ℂ) ≠ 0 := by
simp only [Ne, cpow_eq_zero_iff, ofReal_eq_zero, hx.ne', false_and, not_false_eq_true]
have h4 : arg x ≠ π := by rw [arg_ofReal_of_nonneg hx.le]; exact pi_ne_zero.symm
rw [← ofReal_inj, oddKernel_def, ofReal_mul, sinKernel_def, jacobiTheta₂'_functional_equation',
h1, h2]
generalize jacobiTheta₂'' a (I * ↑x) = J
rw [one_div (x : ℂ), inv_cpow _ _ h4, div_inv_eq_mul, one_div, ofReal_inv, ofReal_cpow hx.le,
ofReal_div, ofReal_ofNat, ofReal_ofNat, ← mul_div_assoc _ _ (-2 * π : ℂ),
eq_div_iff <| mul_ne_zero (neg_ne_zero.mpr two_ne_zero) (ofReal_ne_zero.mpr pi_ne_zero),
← div_eq_inv_mul, eq_div_iff h3, mul_comm J _, mul_right_comm]
end kernel_defs
section sum_formulas
/-!
## Formulae for the kernels as sums
-/
lemma hasSum_int_oddKernel (a : ℝ) {x : ℝ} (hx : 0 < x) :
HasSum (fun n : ℤ ↦ (n + a) * rexp (-π * (n + a) ^ 2 * x)) (oddKernel ↑a x) := by
rw [← hasSum_ofReal, oddKernel_def' a x]
have h1 := hasSum_jacobiTheta₂_term (a * I * x) (by rwa [I_mul_im, ofReal_re])
have h2 := hasSum_jacobiTheta₂'_term (a * I * x) (by rwa [I_mul_im, ofReal_re])
refine (((h2.div_const (2 * π * I)).add (h1.mul_left ↑a)).mul_left
(cexp (-π * a ^ 2 * x))).congr_fun (fun n ↦ ?_)
rw [jacobiTheta₂'_term, mul_assoc (2 * π * I), mul_div_cancel_left₀ _ two_pi_I_ne_zero, ← add_mul,
mul_left_comm, jacobiTheta₂_term, ← Complex.exp_add]
push_cast
simp only [← mul_assoc, ← add_mul]
congrm _ * cexp (?_ * x)
simp only [mul_right_comm _ I, add_mul, mul_assoc _ I, I_mul_I]
ring_nf
lemma hasSum_int_sinKernel (a : ℝ) {t : ℝ} (ht : 0 < t) : HasSum
(fun n : ℤ ↦ -I * n * cexp (2 * π * I * a * n) * rexp (-π * n ^ 2 * t)) ↑(sinKernel a t) := by
have h : -2 * (π : ℂ) ≠ (0 : ℂ) := by
simp only [neg_mul, ne_eq, neg_eq_zero, mul_eq_zero,
OfNat.ofNat_ne_zero, ofReal_eq_zero, pi_ne_zero, or_self, not_false_eq_true]
rw [sinKernel_def]
refine ((hasSum_jacobiTheta₂'_term a
(by rwa [I_mul_im, ofReal_re])).div_const _).congr_fun fun n ↦ ?_
rw [jacobiTheta₂'_term, jacobiTheta₂_term, ofReal_exp, mul_assoc (-I * n), ← Complex.exp_add,
eq_div_iff h, ofReal_mul, ofReal_mul, ofReal_pow, ofReal_neg, ofReal_intCast,
mul_comm _ (-2 * π : ℂ), ← mul_assoc]
congrm ?_ * cexp (?_ + ?_)
· simp [mul_assoc]
· exact mul_right_comm (2 * π * I) a n
· simp [← mul_assoc, mul_comm _ I]
lemma hasSum_nat_sinKernel (a : ℝ) {t : ℝ} (ht : 0 < t) :
HasSum (fun n : ℕ ↦ 2 * n * Real.sin (2 * π * a * n) * rexp (-π * n ^ 2 * t))
(sinKernel ↑a t) := by
rw [← hasSum_ofReal]
have := (hasSum_int_sinKernel a ht).nat_add_neg
simp only [Int.cast_zero, zero_mul, mul_zero, add_zero] at this
refine this.congr_fun fun n ↦ ?_
simp_rw [Int.cast_neg, neg_sq, mul_neg, ofReal_mul, Int.cast_natCast, ofReal_natCast,
ofReal_ofNat, ← add_mul, ofReal_sin, Complex.sin]
push_cast
congr 1
rw [← mul_div_assoc, ← div_mul_eq_mul_div, ← div_mul_eq_mul_div, div_self two_ne_zero, one_mul,
neg_mul, neg_mul, neg_neg, mul_comm _ I, ← mul_assoc, mul_comm _ I, neg_mul,
← sub_eq_neg_add, mul_sub]
congr 3 <;> ring
end sum_formulas
section asymp
/-!
## Asymptotics of the kernels as `t → ∞`
-/
/-- The function `oddKernel a` has exponential decay at `+∞`, for any `a`. -/
lemma isBigO_atTop_oddKernel (a : UnitAddCircle) :
∃ p, 0 < p ∧ IsBigO atTop (oddKernel a) (fun x ↦ Real.exp (-p * x)) := by
induction a using QuotientAddGroup.induction_on with | H b =>
obtain ⟨p, hp, hp'⟩ := HurwitzKernelBounds.isBigO_atTop_F_int_one b
refine ⟨p, hp, (Eventually.isBigO ?_).trans hp'⟩
filter_upwards [eventually_gt_atTop 0] with t ht
simpa [← (hasSum_int_oddKernel b ht).tsum_eq, HurwitzKernelBounds.F_int,
HurwitzKernelBounds.f_int, abs_of_nonneg (exp_pos _).le] using
norm_tsum_le_tsum_norm (hasSum_int_oddKernel b ht).summable.norm
/-- The function `sinKernel a` has exponential decay at `+∞`, for any `a`. -/
lemma isBigO_atTop_sinKernel (a : UnitAddCircle) :
∃ p, 0 < p ∧ IsBigO atTop (sinKernel a) (fun x ↦ Real.exp (-p * x)) := by
induction a using QuotientAddGroup.induction_on with | H a =>
obtain ⟨p, hp, hp'⟩ := HurwitzKernelBounds.isBigO_atTop_F_nat_one (le_refl 0)
refine ⟨p, hp, (Eventually.isBigO ?_).trans (hp'.const_mul_left 2)⟩
filter_upwards [eventually_gt_atTop 0] with t ht
rw [HurwitzKernelBounds.F_nat, ← (hasSum_nat_sinKernel a ht).tsum_eq]
apply tsum_of_norm_bounded (g := fun n ↦ 2 * HurwitzKernelBounds.f_nat 1 0 t n)
· exact (HurwitzKernelBounds.summable_f_nat 1 0 ht).hasSum.mul_left _
· intro n
rw [norm_mul, norm_mul, norm_mul, norm_two, mul_assoc, mul_assoc,
mul_le_mul_iff_of_pos_left two_pos, HurwitzKernelBounds.f_nat, pow_one, add_zero,
norm_of_nonneg (exp_pos _).le, Real.norm_eq_abs, Nat.abs_cast, ← mul_assoc,
mul_le_mul_iff_of_pos_right (exp_pos _)]
exact mul_le_of_le_one_right (Nat.cast_nonneg _) (abs_sin_le_one _)
end asymp
section FEPair
/-!
## Construction of an FE-pair
-/
/-- A `StrongFEPair` structure with `f = oddKernel a` and `g = sinKernel a`. -/
@[simps]
def hurwitzOddFEPair (a : UnitAddCircle) : StrongFEPair ℂ where
f := ofReal ∘ oddKernel a
g := ofReal ∘ sinKernel a
hf_int := (continuous_ofReal.comp_continuousOn (continuousOn_oddKernel a)).locallyIntegrableOn
measurableSet_Ioi
hg_int := (continuous_ofReal.comp_continuousOn (continuousOn_sinKernel a)).locallyIntegrableOn
measurableSet_Ioi
k := 3 / 2
hk := by norm_num
ε := 1
hε := one_ne_zero
f₀ := 0
hf₀ := rfl
g₀ := 0
hg₀ := rfl
hf_top r := by
let ⟨v, hv, hv'⟩ := isBigO_atTop_oddKernel a
rw [← isBigO_norm_left] at hv' ⊢
simpa using hv'.trans (isLittleO_exp_neg_mul_rpow_atTop hv _).isBigO
hg_top r := by
let ⟨v, hv, hv'⟩ := isBigO_atTop_sinKernel a
rw [← isBigO_norm_left] at hv' ⊢
simpa using hv'.trans (isLittleO_exp_neg_mul_rpow_atTop hv _).isBigO
h_feq x hx := by simp [← ofReal_mul, oddKernel_functional_equation a, inv_rpow (le_of_lt hx)]
end FEPair
/-!
## Definition of the completed odd Hurwitz zeta function
-/
/-- The entire function of `s` which agrees with
`1 / 2 * Gamma ((s + 1) / 2) * π ^ (-(s + 1) / 2) * ∑' (n : ℤ), sgn (n + a) / |n + a| ^ s`
for `1 < re s`.
-/
def completedHurwitzZetaOdd (a : UnitAddCircle) (s : ℂ) : ℂ :=
((hurwitzOddFEPair a).Λ ((s + 1) / 2)) / 2
lemma differentiable_completedHurwitzZetaOdd (a : UnitAddCircle) :
Differentiable ℂ (completedHurwitzZetaOdd a) :=
((hurwitzOddFEPair a).differentiable_Λ.comp
((differentiable_id.add_const 1).div_const 2)).div_const 2
/-- The entire function of `s` which agrees with
` Gamma ((s + 1) / 2) * π ^ (-(s + 1) / 2) * ∑' (n : ℕ), sin (2 * π * a * n) / n ^ s`
for `1 < re s`.
-/
def completedSinZeta (a : UnitAddCircle) (s : ℂ) : ℂ :=
((hurwitzOddFEPair a).symm.Λ ((s + 1) / 2)) / 2
lemma differentiable_completedSinZeta (a : UnitAddCircle) :
Differentiable ℂ (completedSinZeta a) :=
((hurwitzOddFEPair a).symm.differentiable_Λ.comp
((differentiable_id.add_const 1).div_const 2)).div_const 2
/-!
## Parity and functional equations
-/
lemma completedHurwitzZetaOdd_neg (a : UnitAddCircle) (s : ℂ) :
completedHurwitzZetaOdd (-a) s = -completedHurwitzZetaOdd a s := by
simp [completedHurwitzZetaOdd, StrongFEPair.Λ, hurwitzOddFEPair, mellin, oddKernel_neg,
integral_neg, neg_div]
lemma completedSinZeta_neg (a : UnitAddCircle) (s : ℂ) :
completedSinZeta (-a) s = -completedSinZeta a s := by
simp [completedSinZeta, StrongFEPair.Λ, mellin, StrongFEPair.symm, WeakFEPair.symm,
hurwitzOddFEPair, sinKernel_neg, integral_neg, neg_div]
/-- Functional equation for the odd Hurwitz zeta function. -/
theorem completedHurwitzZetaOdd_one_sub (a : UnitAddCircle) (s : ℂ) :
completedHurwitzZetaOdd a (1 - s) = completedSinZeta a s := by
rw [completedHurwitzZetaOdd, completedSinZeta,
(by { push_cast; ring } : (1 - s + 1) / 2 = ↑(3 / 2 : ℝ) - (s + 1) / 2),
← hurwitzOddFEPair_k, (hurwitzOddFEPair a).functional_equation ((s + 1) / 2),
hurwitzOddFEPair_ε, one_smul]
/-- Functional equation for the odd Hurwitz zeta function (alternative form). -/
lemma completedSinZeta_one_sub (a : UnitAddCircle) (s : ℂ) :
completedSinZeta a (1 - s) = completedHurwitzZetaOdd a s := by
simp [← completedHurwitzZetaOdd_one_sub]
/-!
## Relation to the Dirichlet series for `1 < re s`
-/
/-- Formula for `completedSinZeta` as a Dirichlet series in the convergence range
(first version, with sum over `ℤ`). -/
lemma hasSum_int_completedSinZeta (a : ℝ) {s : ℂ} (hs : 1 < re s) :
HasSum (fun n : ℤ ↦ Gammaℝ (s + 1) * (-I) * Int.sign n *
cexp (2 * π * I * a * n) / (↑|n| : ℂ) ^ s / 2) (completedSinZeta a s) := by
let c (n : ℤ) : ℂ := -I * cexp (2 * π * I * a * n) / 2
have hc (n : ℤ) : ‖c n‖ = 1 / 2 := by
simp_rw [c, (by { push_cast; ring } : 2 * π * I * a * n = ↑(2 * π * a * n) * I), norm_div,
RCLike.norm_ofNat, norm_mul, norm_neg, norm_I, one_mul, norm_exp_ofReal_mul_I]
have hF t (ht : 0 < t) :
HasSum (fun n ↦ c n * n * rexp (-π * n ^ 2 * t)) (sinKernel a t / 2) := by
refine ((hasSum_int_sinKernel a ht).div_const 2).congr_fun fun n ↦ ?_
rw [div_mul_eq_mul_div, div_mul_eq_mul_div, mul_right_comm (-I)]
have h_sum : Summable fun i ↦ ‖c i‖ / |↑i| ^ s.re := by
simp_rw [hc, div_right_comm]
apply Summable.div_const
apply Summable.of_nat_of_neg <;>
simpa
refine (mellin_div_const .. ▸ hasSum_mellin_pi_mul_sq' (zero_lt_one.trans hs) hF h_sum).congr_fun
fun n ↦ ?_
simp [Int.sign_eq_sign, ← Int.cast_abs] -- non-terminal simp OK when `ring` follows
ring
/-- Formula for `completedSinZeta` as a Dirichlet series in the convergence range
(second version, with sum over `ℕ`). -/
lemma hasSum_nat_completedSinZeta (a : ℝ) {s : ℂ} (hs : 1 < re s) :
HasSum (fun n : ℕ ↦ Gammaℝ (s + 1) * Real.sin (2 * π * a * n) / (n : ℂ) ^ s)
(completedSinZeta a s) := by
have := (hasSum_int_completedSinZeta a hs).nat_add_neg
simp_rw [Int.sign_zero, Int.cast_zero, mul_zero, zero_mul, zero_div, add_zero, abs_neg,
Int.sign_neg, Nat.abs_cast, Int.cast_neg, Int.cast_natCast, ← add_div] at this
refine this.congr_fun fun n ↦ ?_
rw [div_right_comm]
rcases eq_or_ne n 0 with rfl | h
· simp
simp_rw [Int.sign_natCast_of_ne_zero h, Int.cast_one, ofReal_sin, Complex.sin]
simp only [← mul_div_assoc, push_cast, mul_assoc (Gammaℝ _), ← mul_add]
congr 3
rw [mul_one, mul_neg_one, neg_neg, neg_mul I, ← sub_eq_neg_add, ← mul_sub, mul_comm,
mul_neg, neg_mul]
congr 3 <;> ring
/-- Formula for `completedHurwitzZetaOdd` as a Dirichlet series in the convergence range. -/
lemma hasSum_int_completedHurwitzZetaOdd (a : ℝ) {s : ℂ} (hs : 1 < re s) :
HasSum (fun n : ℤ ↦ Gammaℝ (s + 1) * SignType.sign (n + a) / (↑|n + a| : ℂ) ^ s / 2)
(completedHurwitzZetaOdd a s) := by
let r (n : ℤ) : ℝ := n + a
let c (n : ℤ) : ℂ := 1 / 2
have hF t (ht : 0 < t) : HasSum (fun n ↦ c n * r n * rexp (-π * (r n) ^ 2 * t))
(oddKernel a t / 2) := by
refine ((hasSum_ofReal.mpr (hasSum_int_oddKernel a ht)).div_const 2).congr_fun fun n ↦ ?_
simp [r, c, push_cast, div_mul_eq_mul_div, -one_div]
have h_sum : Summable fun i ↦ ‖c i‖ / |r i| ^ s.re := by
simp_rw [c, ← mul_one_div ‖_‖]
apply Summable.mul_left
rwa [summable_one_div_int_add_rpow]
have := mellin_div_const .. ▸ hasSum_mellin_pi_mul_sq' (zero_lt_one.trans hs) hF h_sum
refine this.congr_fun fun n ↦ ?_
simp only [r, c, mul_one_div, div_mul_eq_mul_div, div_right_comm]
/-!
## Non-completed zeta functions
-/
/-- The odd part of the Hurwitz zeta function, i.e. the meromorphic function of `s` which agrees
with `1 / 2 * ∑' (n : ℤ), sign (n + a) / |n + a| ^ s` for `1 < re s` -/
noncomputable def hurwitzZetaOdd (a : UnitAddCircle) (s : ℂ) :=
completedHurwitzZetaOdd a s / Gammaℝ (s + 1)
lemma hurwitzZetaOdd_neg (a : UnitAddCircle) (s : ℂ) :
hurwitzZetaOdd (-a) s = -hurwitzZetaOdd a s := by
simp_rw [hurwitzZetaOdd, completedHurwitzZetaOdd_neg, neg_div]
/-- The odd Hurwitz zeta function is differentiable everywhere. -/
lemma differentiable_hurwitzZetaOdd (a : UnitAddCircle) :
Differentiable ℂ (hurwitzZetaOdd a) :=
(differentiable_completedHurwitzZetaOdd a).mul <| differentiable_Gammaℝ_inv.comp <|
differentiable_id.add <| differentiable_const _
/-- The sine zeta function, i.e. the meromorphic function of `s` which agrees
with `∑' (n : ℕ), sin (2 * π * a * n) / n ^ s` for `1 < re s`. -/
noncomputable def sinZeta (a : UnitAddCircle) (s : ℂ) :=
completedSinZeta a s / Gammaℝ (s + 1)
lemma sinZeta_neg (a : UnitAddCircle) (s : ℂ) :
sinZeta (-a) s = -sinZeta a s := by
simp_rw [sinZeta, completedSinZeta_neg, neg_div]
/-- The sine zeta function is differentiable everywhere. -/
lemma differentiableAt_sinZeta (a : UnitAddCircle) :
Differentiable ℂ (sinZeta a) :=
(differentiable_completedSinZeta a).mul <| differentiable_Gammaℝ_inv.comp <|
differentiable_id.add <| differentiable_const _
/-- Formula for `hurwitzZetaOdd` as a Dirichlet series in the convergence range (sum over `ℤ`). -/
theorem hasSum_int_hurwitzZetaOdd (a : ℝ) {s : ℂ} (hs : 1 < re s) :
HasSum (fun n : ℤ ↦ SignType.sign (n + a) / (↑|n + a| : ℂ) ^ s / 2) (hurwitzZetaOdd a s) := by
refine ((hasSum_int_completedHurwitzZetaOdd a hs).div_const (Gammaℝ _)).congr_fun fun n ↦ ?_
have : 0 < re (s + 1) := by rw [add_re, one_re]; positivity
simp [div_right_comm _ _ (Gammaℝ _), mul_div_cancel_left₀ _ (Gammaℝ_ne_zero_of_re_pos this)]
/-- Formula for `hurwitzZetaOdd` as a Dirichlet series in the convergence range, with sum over `ℕ`
(version with absolute values) -/
lemma hasSum_nat_hurwitzZetaOdd (a : ℝ) {s : ℂ} (hs : 1 < re s) :
HasSum (fun n : ℕ ↦ (SignType.sign (n + a) / (↑|n + a| : ℂ) ^ s
- SignType.sign (n + 1 - a) / (↑|n + 1 - a| : ℂ) ^ s) / 2) (hurwitzZetaOdd a s) := by
refine (hasSum_int_hurwitzZetaOdd a hs).nat_add_neg_add_one.congr_fun fun n ↦ ?_
rw [Int.cast_neg, Int.cast_add, Int.cast_one, sub_div, sub_eq_add_neg, Int.cast_natCast]
have : -(n + 1) + a = -(n + 1 - a) := by ring_nf
rw [this, Left.sign_neg, abs_neg, SignType.coe_neg, neg_div, neg_div]
/-- Formula for `hurwitzZetaOdd` as a Dirichlet series in the convergence range, with sum over `ℕ`
(version without absolute values, assuming `a ∈ Icc 0 1`) -/
lemma hasSum_nat_hurwitzZetaOdd_of_mem_Icc {a : ℝ} (ha : a ∈ Icc 0 1) {s : ℂ} (hs : 1 < re s) :
HasSum (fun n : ℕ ↦ (1 / (n + a : ℂ) ^ s - 1 / (n + 1 - a : ℂ) ^ s) / 2)
(hurwitzZetaOdd a s) := by
refine (hasSum_nat_hurwitzZetaOdd a hs).congr_fun fun n ↦ ?_
suffices ∀ b : ℝ, 0 ≤ b → SignType.sign (n + b) / (↑|n + b| : ℂ) ^ s = 1 / (n + b) ^ s by
simp only [add_sub_assoc, this a ha.1, this (1 - a) (sub_nonneg.mpr ha.2), push_cast]
intro b hb
rw [abs_of_nonneg (by positivity), (by simp : (n : ℂ) + b = ↑(n + b))]
rcases lt_or_eq_of_le (by positivity : 0 ≤ n + b) with hb | hb
· simp [sign_pos hb]
· rw [← hb, ofReal_zero, zero_cpow ((not_lt.mpr zero_le_one) ∘ (zero_re ▸ · ▸ hs)),
div_zero, div_zero]
/-- Formula for `sinZeta` as a Dirichlet series in the convergence range, with sum over `ℤ`. -/
theorem hasSum_int_sinZeta (a : ℝ) {s : ℂ} (hs : 1 < re s) :
HasSum (fun n : ℤ ↦ -I * n.sign * cexp (2 * π * I * a * n) / ↑|n| ^ s / 2) (sinZeta a s) := by
rw [sinZeta]
refine ((hasSum_int_completedSinZeta a hs).div_const (Gammaℝ (s + 1))).congr_fun fun n ↦ ?_
have : 0 < re (s + 1) := by rw [add_re, one_re]; positivity
simp only [mul_assoc, div_right_comm _ _ (Gammaℝ _),
mul_div_cancel_left₀ _ (Gammaℝ_ne_zero_of_re_pos this)]
/-- Formula for `sinZeta` as a Dirichlet series in the convergence range, with sum over `ℕ`. -/
lemma hasSum_nat_sinZeta (a : ℝ) {s : ℂ} (hs : 1 < re s) :
HasSum (fun n : ℕ ↦ Real.sin (2 * π * a * n) / (n : ℂ) ^ s) (sinZeta a s) := by
have := (hasSum_int_sinZeta a hs).nat_add_neg
simp_rw [abs_neg, Int.sign_neg, Int.cast_neg, Nat.abs_cast, Int.cast_natCast, mul_neg, abs_zero,
Int.cast_zero, zero_cpow (ne_zero_of_one_lt_re hs), div_zero, zero_div, add_zero] at this
simp_rw [push_cast, Complex.sin]
refine this.congr_fun fun n ↦ ?_
rcases ne_or_eq n 0 with h | rfl
· simp only [neg_mul, sub_mul, div_right_comm _ (2 : ℂ), Int.sign_natCast_of_ne_zero h,
Int.cast_one, mul_one, mul_comm I, neg_neg, ← add_div, ← sub_eq_neg_add]
congr 5 <;> ring
· simp
/-- Reformulation of `hasSum_nat_sinZeta` using `LSeriesHasSum`. -/
lemma LSeriesHasSum_sin (a : ℝ) {s : ℂ} (hs : 1 < re s) :
LSeriesHasSum (Real.sin <| 2 * π * a * ·) s (sinZeta a s) :=
(hasSum_nat_sinZeta a hs).congr_fun (LSeries.term_of_ne_zero' (ne_zero_of_one_lt_re hs) _)
/-- The trivial zeroes of the odd Hurwitz zeta function. -/
theorem hurwitzZetaOdd_neg_two_mul_nat_sub_one (a : UnitAddCircle) (n : ℕ) :
hurwitzZetaOdd a (-2 * n - 1) = 0 := by
rw [hurwitzZetaOdd, Gammaℝ_eq_zero_iff.mpr ⟨n, by rw [neg_mul, sub_add_cancel]⟩, div_zero]
/-- The trivial zeroes of the sine zeta function. -/
theorem sinZeta_neg_two_mul_nat_sub_one (a : UnitAddCircle) (n : ℕ) :
sinZeta a (-2 * n - 1) = 0 := by
rw [sinZeta, Gammaℝ_eq_zero_iff.mpr ⟨n, by rw [neg_mul, sub_add_cancel]⟩, div_zero]
/-- If `s` is not in `-ℕ`, then `hurwitzZetaOdd a (1 - s)` is an explicit multiple of
`sinZeta s`. -/
lemma hurwitzZetaOdd_one_sub (a : UnitAddCircle) {s : ℂ} (hs : ∀ (n : ℕ), s ≠ -n) :
hurwitzZetaOdd a (1 - s) = 2 * (2 * π) ^ (-s) * Gamma s * sin (π * s / 2) * sinZeta a s := by
rw [← Gammaℂ, hurwitzZetaOdd, (by ring : 1 - s + 1 = 2 - s), div_eq_mul_inv,
inv_Gammaℝ_two_sub hs, completedHurwitzZetaOdd_one_sub, sinZeta, ← div_eq_mul_inv,
← mul_div_assoc, ← mul_div_assoc, mul_comm]
/-- If `s` is not in `-ℕ`, then `sinZeta a (1 - s)` is an explicit multiple of
`hurwitzZetaOdd s`. -/
lemma sinZeta_one_sub (a : UnitAddCircle) {s : ℂ} (hs : ∀ (n : ℕ), s ≠ -n) :
sinZeta a (1 - s) = 2 * (2 * π) ^ (-s) * Gamma s * sin (π * s / 2) * hurwitzZetaOdd a s := by
rw [← Gammaℂ, sinZeta, (by ring : 1 - s + 1 = 2 - s), div_eq_mul_inv, inv_Gammaℝ_two_sub hs,
completedSinZeta_one_sub, hurwitzZetaOdd, ← div_eq_mul_inv, ← mul_div_assoc, ← mul_div_assoc,
mul_comm]
end HurwitzZeta |
.lake/packages/mathlib/Mathlib/NumberTheory/LSeries/ZMod.lean | import Mathlib.Analysis.Fourier.ZMod
import Mathlib.Analysis.NormedSpace.Connected
import Mathlib.NumberTheory.LSeries.RiemannZeta
/-!
# L-series of functions on `ZMod N`
We show that if `N` is a positive integer and `Φ : ZMod N → ℂ`, then the L-series of `Φ` has
analytic continuation (away from a pole at `s = 1` if `∑ j, Φ j ≠ 0`) and satisfies a functional
equation. We also define completed L-functions (given by multiplying the naive L-function by a
Gamma-factor), and prove analytic continuation and functional equations for these too, assuming `Φ`
is either even or odd.
The most familiar case is when `Φ` is a Dirichlet character, but the results here are valid
for general functions; for the specific case of Dirichlet characters see
`Mathlib/NumberTheory/LSeries/DirichletContinuation.lean`.
## Main definitions
* `ZMod.LFunction Φ s`: the meromorphic continuation of the function `∑ n : ℕ, Φ n * n ^ (-s)`.
* `ZMod.completedLFunction Φ s`: the completed L-function, which for *almost* all `s` is equal to
`LFunction Φ s` multiplied by an Archimedean Gamma-factor.
Note that `ZMod.completedLFunction Φ s` is only mathematically well-defined if `Φ` is either even
or odd. Here we extend it to all functions `Φ` by linearity (but the functional equation only holds
if `Φ` is either even or odd).
## Main theorems
Results for non-completed L-functions:
* `ZMod.LFunction_eq_LSeries`: if `1 < re s` then the `LFunction` coincides with the naive
`LSeries`.
* `ZMod.differentiableAt_LFunction`: `ZMod.LFunction Φ` is differentiable at `s ∈ ℂ` if either
`s ≠ 1` or `∑ j, Φ j = 0`.
* `ZMod.LFunction_one_sub`: the functional equation relating `LFunction Φ (1 - s)` to
`LFunction (𝓕 Φ) s`, where `𝓕` is the Fourier transform.
Results for completed L-functions:
* `ZMod.LFunction_eq_completed_div_gammaFactor_even` and
`LFunction_eq_completed_div_gammaFactor_odd`: we have
`LFunction Φ s = completedLFunction Φ s / Gammaℝ s` for `Φ` even, and
`LFunction Φ s = completedLFunction Φ s / Gammaℝ (s + 1)` for `Φ` odd. (We formulate it this way
around so it is still valid at the poles of the Gamma factor.)
* `ZMod.differentiableAt_completedLFunction`: `ZMod.completedLFunction Φ` is differentiable at
`s ∈ ℂ`, unless `s = 1` and `∑ j, Φ j ≠ 0`, or `s = 0` and `Φ 0 ≠ 0`.
* `ZMod.completedLFunction_one_sub_even` and `ZMod.completedLFunction_one_sub_odd`:
the functional equation relating `completedLFunction Φ (1 - s)` to `completedLFunction (𝓕 Φ) s`.
-/
open HurwitzZeta Complex ZMod Finset Topology Filter Set
open scoped Real
namespace ZMod
variable {N : ℕ} [NeZero N]
/-- If `Φ` is a periodic function, then the L-series of `Φ` converges for `1 < re s`. -/
lemma LSeriesSummable_of_one_lt_re (Φ : ZMod N → ℂ) {s : ℂ} (hs : 1 < re s) :
LSeriesSummable (Φ ·) s := by
let c := max' _ <| univ_nonempty.image (norm ∘ Φ)
refine LSeriesSummable_of_bounded_of_one_lt_re (fun n _ ↦ le_max' _ _ ?_) (m := c) hs
exact mem_image_of_mem _ (mem_univ _)
/--
The unique meromorphic function `ℂ → ℂ` which agrees with `∑' n : ℕ, Φ n / n ^ s` wherever the
latter is convergent. This is constructed as a linear combination of Hurwitz zeta functions.
Note that this is not the same as `LSeries Φ`: they agree in the convergence range, but
`LSeries Φ s` is defined to be `0` if `re s ≤ 1`.
-/
noncomputable def LFunction (Φ : ZMod N → ℂ) (s : ℂ) : ℂ :=
N ^ (-s) * ∑ j : ZMod N, Φ j * hurwitzZeta (toAddCircle j) s
/-- The L-function of a function on `ZMod 1` is a scalar multiple of the Riemann zeta function. -/
lemma LFunction_modOne_eq (Φ : ZMod 1 → ℂ) (s : ℂ) :
LFunction Φ s = Φ 0 * riemannZeta s := by
simp only [LFunction, Nat.cast_one, one_cpow, ← singleton_eq_univ (0 : ZMod 1), sum_singleton,
map_zero, hurwitzZeta_zero, one_mul]
/-- For `1 < re s` the congruence L-function agrees with the sum of the Dirichlet series. -/
lemma LFunction_eq_LSeries (Φ : ZMod N → ℂ) {s : ℂ} (hs : 1 < re s) :
LFunction Φ s = LSeries (Φ ·) s := by
rw [LFunction, LSeries, mul_sum, Nat.sumByResidueClasses (LSeriesSummable_of_one_lt_re Φ hs) N]
congr 1 with j
have : (j.val / N : ℝ) ∈ Set.Icc 0 1 := mem_Icc.mpr ⟨by positivity,
(div_le_one (Nat.cast_pos.mpr <| NeZero.pos _)).mpr <| Nat.cast_le.mpr (val_lt j).le⟩
rw [toAddCircle_apply, ← (hasSum_hurwitzZeta_of_one_lt_re this hs).tsum_eq, ← mul_assoc,
← tsum_mul_left]
congr 1 with m
-- The following manipulation is slightly delicate because `(x * y) ^ s = x ^ s * y ^ s` is
-- false for general complex `x`, `y`, but it is true if `x` and `y` are non-negative reals, so
-- we have to carefully juggle coercions `ℕ → ℝ → ℂ`.
calc N ^ (-s) * Φ j * (1 / (m + (j.val / N : ℝ)) ^ s)
_ = Φ j * (N ^ (-s) * (1 / (m + (j.val / N : ℝ)) ^ s)) := by
rw [← mul_assoc, mul_comm _ (Φ _)]
_ = Φ j * (1 / (N : ℝ) ^ s * (1 / ((j.val + N * m) / N : ℝ) ^ s)) := by
simp only [cpow_neg, ← one_div, ofReal_div, ofReal_natCast, add_comm, add_div, ofReal_add,
ofReal_mul, mul_div_cancel_left₀ (m : ℂ) (Nat.cast_ne_zero.mpr (NeZero.ne N))]
_ = Φ j / ((N : ℝ) * ((j.val + N * m) / N : ℝ)) ^ s := by -- this is the delicate step!
rw [one_div_mul_one_div, mul_one_div, mul_cpow_ofReal_nonneg] <;> positivity
_ = Φ j / (N * (j.val + N * m) / N) ^ s := by
simp only [ofReal_natCast, ofReal_div, ofReal_add, ofReal_mul, mul_div_assoc]
_ = Φ j / (j.val + N * m) ^ s := by
rw [mul_div_cancel_left₀ _ (Nat.cast_ne_zero.mpr (NeZero.ne N))]
_ = Φ ↑(j.val + N * m) / (↑(j.val + N * m)) ^ s := by
simp only [Nat.cast_add, Nat.cast_mul, natCast_zmod_val, natCast_self, zero_mul, add_zero]
_ = LSeries.term (Φ ·) s (j.val + N * m) := by
rw [LSeries.term_of_ne_zero' (ne_zero_of_one_lt_re hs)]
lemma differentiableAt_LFunction (Φ : ZMod N → ℂ) (s : ℂ) (hs : s ≠ 1 ∨ ∑ j, Φ j = 0) :
DifferentiableAt ℂ (LFunction Φ) s := by
refine .mul (by fun_prop) ?_
rcases ne_or_eq s 1 with hs' | rfl
· exact .fun_sum fun j _ ↦ (differentiableAt_hurwitzZeta _ hs').const_mul _
· have := DifferentiableAt.fun_sum (u := univ) fun j _ ↦
(differentiableAt_hurwitzZeta_sub_one_div (toAddCircle j)).const_mul (Φ j)
simpa only [mul_sub, sum_sub_distrib, ← sum_mul, hs.neg_resolve_left rfl, zero_mul, sub_zero]
lemma differentiable_LFunction_of_sum_zero {Φ : ZMod N → ℂ} (hΦ : ∑ j, Φ j = 0) :
Differentiable ℂ (LFunction Φ) :=
fun s ↦ differentiableAt_LFunction Φ s (Or.inr hΦ)
/-- The L-function of `Φ` has a residue at `s = 1` equal to the average value of `Φ`. -/
lemma LFunction_residue_one (Φ : ZMod N → ℂ) :
Tendsto (fun s ↦ (s - 1) * LFunction Φ s) (𝓝[≠] 1) (𝓝 (∑ j, Φ j / N)) := by
simp only [LFunction, mul_sum]
refine tendsto_finset_sum _ fun j _ ↦ ?_
rw [(by ring : Φ j / N = Φ j * (1 / N * 1)), one_div, ← cpow_neg_one]
simp only [show ∀ a b c d : ℂ, a * (b * (c * d)) = c * (b * (a * d)) by intros; ring]
refine tendsto_const_nhds.mul (.mul ?_ <| hurwitzZeta_residue_one _)
exact ((continuous_neg.const_cpow (Or.inl <| NeZero.ne _)).tendsto _).mono_left
nhdsWithin_le_nhds
local notation "𝕖" => stdAddChar
/--
The `LFunction` of the function `x ↦ e (j * x)`, where `e : ZMod N → ℂ` is the standard additive
character, agrees with `expZeta (j / N)` on `1 < re s`. Private since it is a stepping-stone to
the more general result `LFunction_stdAddChar_eq_expZeta` below.
-/
private lemma LFunction_stdAddChar_eq_expZeta_of_one_lt_re (j : ZMod N) {s : ℂ} (hs : 1 < s.re) :
LFunction (fun k ↦ 𝕖 (j * k)) s = expZeta (ZMod.toAddCircle j) s := by
rw [toAddCircle_apply, ← (hasSum_expZeta_of_one_lt_re (j.val / N) hs).tsum_eq,
LFunction_eq_LSeries _ hs, LSeries]
congr 1 with n
rw [LSeries.term_of_ne_zero' (ne_zero_of_one_lt_re hs), ofReal_div, ofReal_natCast,
ofReal_natCast, mul_assoc, div_mul_eq_mul_div, stdAddChar_apply]
have := ZMod.toCircle_intCast (N := N) (j.val * n)
conv_rhs at this => rw [Int.cast_mul, Int.cast_natCast, Int.cast_natCast, mul_div_assoc]
rw [← this, Int.cast_mul, Int.cast_natCast, Int.cast_natCast, natCast_zmod_val]
/--
The `LFunction` of the function `x ↦ e (j * x)`, where `e : ZMod N → ℂ` is the standard additive
character, is `expZeta (j / N)`.
Note this is not at all obvious from the definitions, and we prove it by analytic continuation
from the convergence range.
-/
lemma LFunction_stdAddChar_eq_expZeta (j : ZMod N) (s : ℂ) (hjs : j ≠ 0 ∨ s ≠ 1) :
LFunction (fun k ↦ 𝕖 (j * k)) s = expZeta (ZMod.toAddCircle j) s := by
let U := if j = 0 then {z : ℂ | z ≠ 1} else univ -- region of analyticity of both functions
let V := {z : ℂ | 1 < re z} -- convergence region
have hUo : IsOpen U := by
by_cases h : j = 0
· simpa only [h, ↓reduceIte, U] using isOpen_compl_singleton
· simp only [h, ↓reduceIte, isOpen_univ, U]
let f := LFunction (fun k ↦ stdAddChar (j * k))
let g := expZeta (toAddCircle j)
have hU {u} : u ∈ U ↔ u ≠ 1 ∨ j ≠ 0 := by simp only [mem_ite_univ_right, U]; tauto
-- hypotheses for uniqueness of analytic continuation
have hf : AnalyticOnNhd ℂ f U := by
refine DifferentiableOn.analyticOnNhd (fun u hu ↦ ?_) hUo
refine (differentiableAt_LFunction _ _ ((hU.mp hu).imp_right fun h ↦ ?_)).differentiableWithinAt
simp only [mul_comm j, AddChar.sum_mulShift _ (isPrimitive_stdAddChar _), h,
↓reduceIte, CharP.cast_eq_zero]
have hg : AnalyticOnNhd ℂ g U := by
refine DifferentiableOn.analyticOnNhd (fun u hu ↦ ?_) hUo
refine (differentiableAt_expZeta _ _ ((hU.mp hu).imp_right fun h ↦ ?_)).differentiableWithinAt
rwa [ne_eq, toAddCircle_eq_zero]
have hUc : IsPreconnected U := by
by_cases h : j = 0
· simpa only [h, ↓reduceIte, U] using
(isConnected_compl_singleton_of_one_lt_rank (by simp) _).isPreconnected
· simpa only [h, ↓reduceIte, U] using isPreconnected_univ
have hV : V ∈ 𝓝 2 := (continuous_re.isOpen_preimage _ isOpen_Ioi).mem_nhds (by simp)
have hUmem : 2 ∈ U := by simp [U]
have hUmem' : s ∈ U := hU.mpr hjs.symm
-- apply uniqueness result
refine hf.eqOn_of_preconnected_of_eventuallyEq hg hUc hUmem ?_ hUmem'
-- now remains to prove equality on `1 < re s`
filter_upwards [hV] with z using LFunction_stdAddChar_eq_expZeta_of_one_lt_re _
/-- Explicit formula for the L-function of `𝓕 Φ`, where `𝓕` is the discrete Fourier transform. -/
lemma LFunction_dft (Φ : ZMod N → ℂ) {s : ℂ} (hs : Φ 0 = 0 ∨ s ≠ 1) :
LFunction (𝓕 Φ) s = ∑ j : ZMod N, Φ j * expZeta (toAddCircle (-j)) s := by
have (j : ZMod N) : Φ j * LFunction (fun k ↦ 𝕖 (-j * k)) s =
Φ j * expZeta (toAddCircle (-j)) s := by
by_cases h : -j ≠ 0 ∨ s ≠ 1
· rw [LFunction_stdAddChar_eq_expZeta _ _ h]
· simp only [neg_ne_zero, not_or, not_not] at h
rw [h.1, show Φ 0 = 0 by tauto, zero_mul, zero_mul]
simp only [LFunction, ← this, mul_sum]
rw [dft_def, sum_comm]
simp only [sum_mul, mul_sum, smul_eq_mul, stdAddChar_apply, ← mul_assoc]
congr 1 with j
congr 1 with k
rw [mul_assoc (Φ _), mul_comm (Φ _), neg_mul]
/-- Functional equation for `ZMod` L-functions, in terms of discrete Fourier transform. -/
theorem LFunction_one_sub (Φ : ZMod N → ℂ) {s : ℂ}
(hs : ∀ (n : ℕ), s ≠ -n) (hs' : Φ 0 = 0 ∨ s ≠ 1) :
LFunction Φ (1 - s) = N ^ (s - 1) * (2 * π) ^ (-s) * Gamma s *
(cexp (π * I * s / 2) * LFunction (𝓕 Φ) s
+ cexp (-π * I * s / 2) * LFunction (𝓕 fun x ↦ Φ (-x)) s) := by
rw [LFunction]
have (j : ZMod N) : Φ j * hurwitzZeta (toAddCircle j) (1 - s) = Φ j *
((2 * π) ^ (-s) * Gamma s * (cexp (-π * I * s / 2) *
expZeta (toAddCircle j) s + cexp (π * I * s / 2) * expZeta (-toAddCircle j) s)) := by
rcases eq_or_ne j 0 with rfl | hj
· rcases hs' with hΦ | hs'
· simp only [hΦ, zero_mul]
· rw [hurwitzZeta_one_sub _ hs (Or.inr hs')]
· rw [hurwitzZeta_one_sub _ hs (Or.inl <| toAddCircle_eq_zero.not.mpr hj)]
simp only [this, mul_assoc _ _ (Gamma s)]
-- get rid of Gamma terms and power of N
generalize (2 * π) ^ (-s) * Gamma s = C
simp_rw [← mul_assoc, mul_comm _ C, mul_assoc, ← mul_sum, ← mul_assoc, mul_comm _ C, mul_assoc,
neg_sub]
congr 2
-- now gather sum terms
rw [LFunction_dft _ hs', LFunction_dft _ (hs'.imp_left <| by simp only [neg_zero, imp_self])]
conv_rhs => enter [2, 2]; rw [← (Equiv.neg _).sum_comp _ _ (by simp), Equiv.neg_apply]
simp_rw [neg_neg, mul_sum, ← sum_add_distrib, ← mul_assoc, mul_comm _ (Φ _), mul_assoc,
← mul_add, map_neg, add_comm]
section signed
variable {Φ : ZMod N → ℂ}
lemma LFunction_def_even (hΦ : Φ.Even) (s : ℂ) :
LFunction Φ s = N ^ (-s) * ∑ j : ZMod N, Φ j * hurwitzZetaEven (toAddCircle j) s := by
simp only [LFunction, hurwitzZeta, mul_add (Φ _), sum_add_distrib]
congr 1
simp only [add_eq_left, ← neg_eq_self, ← sum_neg_distrib]
refine Fintype.sum_equiv (.neg _) _ _ fun i ↦ ?_
simp only [Equiv.neg_apply, hΦ i, map_neg, hurwitzZetaOdd_neg, mul_neg]
lemma LFunction_def_odd (hΦ : Φ.Odd) (s : ℂ) :
LFunction Φ s = N ^ (-s) * ∑ j : ZMod N, Φ j * hurwitzZetaOdd (toAddCircle j) s := by
simp only [LFunction, hurwitzZeta, mul_add (Φ _), sum_add_distrib]
congr 1
simp only [add_eq_right, ← neg_eq_self, ← sum_neg_distrib]
refine Fintype.sum_equiv (.neg _) _ _ fun i ↦ ?_
simp only [Equiv.neg_apply, hΦ i, map_neg, hurwitzZetaEven_neg, neg_mul]
/-- Explicit formula for `LFunction Φ 0` when `Φ` is even. -/
@[simp] lemma LFunction_apply_zero_of_even (hΦ : Φ.Even) :
LFunction Φ 0 = -Φ 0 / 2 := by
simp only [LFunction_def_even hΦ, neg_zero, cpow_zero, hurwitzZetaEven_apply_zero,
toAddCircle_eq_zero, mul_ite, mul_div, mul_neg_one, mul_zero, sum_ite_eq', Finset.mem_univ,
↓reduceIte, one_mul]
/-- The L-function of an even function vanishes at negative even integers. -/
@[simp] lemma LFunction_neg_two_mul_nat_add_one (hΦ : Φ.Even) (n : ℕ) :
LFunction Φ (-(2 * (n + 1))) = 0 := by
simp only [LFunction_def_even hΦ, hurwitzZetaEven_neg_two_mul_nat_add_one, mul_zero,
sum_const_zero, ← neg_mul]
/-- The L-function of an odd function vanishes at negative odd integers. -/
@[simp] lemma LFunction_neg_two_mul_nat_sub_one (hΦ : Φ.Odd) (n : ℕ) :
LFunction Φ (-(2 * n) - 1) = 0 := by
simp only [LFunction_def_odd hΦ, hurwitzZetaOdd_neg_two_mul_nat_sub_one, mul_zero, ← neg_mul,
sum_const_zero]
/--
The completed L-function of a function `Φ : ZMod N → ℂ`.
This is only mathematically meaningful if `Φ` is either even, or odd; here we extend this to all `Φ`
by linearity.
-/
noncomputable def completedLFunction (Φ : ZMod N → ℂ) (s : ℂ) : ℂ :=
N ^ (-s) * ∑ j, Φ j * completedHurwitzZetaEven (toAddCircle j) s
+ N ^ (-s) * ∑ j, Φ j * completedHurwitzZetaOdd (toAddCircle j) s
@[simp] lemma completedLFunction_zero (s : ℂ) : completedLFunction (0 : ZMod N → ℂ) s = 0 := by
simp only [completedLFunction, Pi.zero_apply, zero_mul, sum_const_zero, mul_zero, zero_add]
lemma completedLFunction_const_mul (a : ℂ) (Φ : ZMod N → ℂ) (s : ℂ) :
completedLFunction (fun j ↦ a * Φ j) s = a * completedLFunction Φ s := by
simp only [completedLFunction, mul_add, mul_sum]
congr with i <;> ring
lemma completedLFunction_def_even (hΦ : Φ.Even) (s : ℂ) :
completedLFunction Φ s = N ^ (-s) * ∑ j, Φ j * completedHurwitzZetaEven (toAddCircle j) s := by
suffices ∑ j, Φ j * completedHurwitzZetaOdd (toAddCircle j) s = 0 by
rw [completedLFunction, this, mul_zero, add_zero]
refine (hΦ.mul_odd fun j ↦ ?_).sum_eq_zero
rw [map_neg, completedHurwitzZetaOdd_neg]
lemma completedLFunction_def_odd (hΦ : Φ.Odd) (s : ℂ) :
completedLFunction Φ s = N ^ (-s) * ∑ j, Φ j * completedHurwitzZetaOdd (toAddCircle j) s := by
suffices ∑ j, Φ j * completedHurwitzZetaEven (toAddCircle j) s = 0 by
rw [completedLFunction, this, mul_zero, zero_add]
refine (hΦ.mul_even fun j ↦ ?_).sum_eq_zero
rw [map_neg, completedHurwitzZetaEven_neg]
/--
The completed L-function of a function `ZMod 1 → ℂ` is a scalar multiple of the completed Riemann
zeta function.
-/
lemma completedLFunction_modOne_eq (Φ : ZMod 1 → ℂ) (s : ℂ) :
completedLFunction Φ s = Φ 1 * completedRiemannZeta s := by
rw [completedLFunction_def_even (show Φ.Even from fun _ ↦ congr_arg Φ (Subsingleton.elim ..)),
Nat.cast_one, one_cpow, one_mul, ← singleton_eq_univ 0, sum_singleton, map_zero,
completedHurwitzZetaEven_zero, Subsingleton.elim 0 1]
/--
The completed L-function of a function `ZMod N → ℂ`, modified by adding multiples of `N ^ (-s) / s`
and `N ^ (-s) / (1 - s)` to make it entire.
-/
noncomputable def completedLFunction₀ (Φ : ZMod N → ℂ) (s : ℂ) : ℂ :=
N ^ (-s) * ∑ j : ZMod N, Φ j * completedHurwitzZetaEven₀ (toAddCircle j) s
+ N ^ (-s) * ∑ j : ZMod N, Φ j * completedHurwitzZetaOdd (toAddCircle j) s
/-- The function `completedLFunction₀ Φ` is differentiable. -/
lemma differentiable_completedLFunction₀ (Φ : ZMod N → ℂ) :
Differentiable ℂ (completedLFunction₀ Φ) := by
refine .add ?_ ?_ <;>
refine .mul (by fun_prop) (.fun_sum fun i _ ↦ .const_mul ?_ _)
exacts [differentiable_completedHurwitzZetaEven₀ _, differentiable_completedHurwitzZetaOdd _]
lemma completedLFunction_eq (Φ : ZMod N → ℂ) (s : ℂ) :
completedLFunction Φ s =
completedLFunction₀ Φ s - N ^ (-s) * Φ 0 / s - N ^ (-s) * (∑ j, Φ j) / (1 - s) := by
simp only [completedLFunction, completedHurwitzZetaEven_eq, toAddCircle_eq_zero, div_eq_mul_inv,
ite_mul, one_mul, zero_mul, mul_sub, mul_ite, mul_zero, sum_sub_distrib, Fintype.sum_ite_eq',
← sum_mul, completedLFunction₀, mul_assoc]
abel
/--
The completed L-function of a function `ZMod N → ℂ` is differentiable, with the following
exceptions: at `s = 1` if `∑ j, Φ j ≠ 0`; and at `s = 0` if `Φ 0 ≠ 0`.
-/
lemma differentiableAt_completedLFunction (Φ : ZMod N → ℂ) (s : ℂ) (hs₀ : s ≠ 0 ∨ Φ 0 = 0)
(hs₁ : s ≠ 1 ∨ ∑ j, Φ j = 0) : DifferentiableAt ℂ (completedLFunction Φ) s := by
simp only [funext (completedLFunction_eq Φ), mul_div_assoc]
-- We know `completedLFunction₀` is differentiable everywhere, so it suffices to show that the
-- correction terms from `completedLFunction_eq` are differentiable at `s`.
refine ((differentiable_completedLFunction₀ _ _).sub ?_).sub ?_
· -- term with `1 / s`
refine .mul (by fun_prop) (hs₀.elim ?_ ?_)
· exact fun h ↦ (differentiableAt_const _).div differentiableAt_id h
· exact fun h ↦ by simp only [h, funext zero_div, differentiableAt_const]
· -- term with `1 / (1 - s)`
refine .mul (by fun_prop) (hs₁.elim ?_ ?_)
· exact fun h ↦ .div (by fun_prop) (by fun_prop) (by rwa [sub_ne_zero, ne_comm])
· exact fun h ↦ by simp only [h, zero_div, differentiableAt_const]
/--
Special case of `differentiableAt_completedLFunction` asserting differentiability everywhere
under suitable hypotheses.
-/
lemma differentiable_completedLFunction (hΦ₂ : Φ 0 = 0) (hΦ₃ : ∑ j, Φ j = 0) :
Differentiable ℂ (completedLFunction Φ) :=
fun s ↦ differentiableAt_completedLFunction Φ s (.inr hΦ₂) (.inr hΦ₃)
/--
Relation between the completed L-function and the usual one (even case).
We state it this way around so it holds at the poles of the gamma factor as well
(except at `s = 0`, where it is genuinely false if `N > 1` and `Φ 0 ≠ 0`).
-/
lemma LFunction_eq_completed_div_gammaFactor_even (hΦ : Φ.Even) (s : ℂ) (hs : s ≠ 0 ∨ Φ 0 = 0) :
LFunction Φ s = completedLFunction Φ s / Gammaℝ s := by
simp only [completedLFunction_def_even hΦ, LFunction_def_even hΦ, mul_div_assoc, sum_div]
congr 2 with i
rcases ne_or_eq i 0 with hi | rfl
· rw [hurwitzZetaEven_def_of_ne_or_ne (.inl (hi ∘ toAddCircle_eq_zero.mp))]
· rcases hs with hs | hΦ'
· rw [hurwitzZetaEven_def_of_ne_or_ne (.inr hs)]
· simp only [hΦ', map_zero, zero_mul]
/--
Relation between the completed L-function and the usual one (odd case).
We state it this way around so it holds at the poles of the gamma factor as well.
-/
lemma LFunction_eq_completed_div_gammaFactor_odd (hΦ : Φ.Odd) (s : ℂ) :
LFunction Φ s = completedLFunction Φ s / Gammaℝ (s + 1) := by
simp only [LFunction_def_odd hΦ, completedLFunction_def_odd hΦ, hurwitzZetaOdd, mul_div_assoc,
sum_div]
/--
First form of functional equation for completed L-functions (even case).
Private because it is superseded by `completedLFunction_one_sub_even` below, which is valid for a
much wider range of `s`.
-/
private lemma completedLFunction_one_sub_of_one_lt_even (hΦ : Φ.Even) {s : ℂ} (hs : 1 < re s) :
completedLFunction Φ (1 - s) = N ^ (s - 1) * completedLFunction (𝓕 Φ) s := by
have hs₀ : s ≠ 0 := ne_zero_of_one_lt_re hs
have hs₁ : s ≠ 1 := (lt_irrefl _ <| one_re ▸ · ▸ hs)
-- strip down to the key equality:
suffices ∑ x, Φ x * completedCosZeta (toAddCircle x) s = completedLFunction (𝓕 Φ) s by
simp only [completedLFunction_def_even hΦ, neg_sub, completedHurwitzZetaEven_one_sub, this]
-- reduce to equality with un-completed L-functions:
suffices ∑ x, Φ x * cosZeta (toAddCircle x) s = LFunction (𝓕 Φ) s by
simpa only [cosZeta, Function.update_of_ne hs₀, ← mul_div_assoc, ← sum_div,
LFunction_eq_completed_div_gammaFactor_even (dft_even_iff.mpr hΦ) _ (.inl hs₀),
div_left_inj' (Gammaℝ_ne_zero_of_re_pos (zero_lt_one.trans hs))]
-- expand out `LFunction (𝓕 Φ)` and use parity:
simp only [cosZeta_eq, ← mul_div_assoc _ _ (2 : ℂ), mul_add, ← sum_div, sum_add_distrib,
LFunction_dft Φ (.inr hs₁), map_neg, div_eq_iff (two_ne_zero' ℂ), mul_two, add_left_inj]
exact Fintype.sum_equiv (.neg _) _ _ (by simp [hΦ _])
/--
First form of functional equation for completed L-functions (odd case).
Private because it is superseded by `completedLFunction_one_sub_odd` below, which is valid for a
much wider range of `s`.
-/
private lemma completedLFunction_one_sub_of_one_lt_odd (hΦ : Φ.Odd) {s : ℂ} (hs : 1 < re s) :
completedLFunction Φ (1 - s) = N ^ (s - 1) * I * completedLFunction (𝓕 Φ) s := by
-- strip down to the key equality:
suffices ∑ x, Φ x * completedSinZeta (toAddCircle x) s = I * completedLFunction (𝓕 Φ) s by
simp only [completedLFunction_def_odd hΦ, neg_sub, completedHurwitzZetaOdd_one_sub, this,
mul_assoc]
-- reduce to equality with un-completed L-functions:
suffices ∑ x, Φ x * sinZeta (toAddCircle x) s = I * LFunction (𝓕 Φ) s by
have hs' : 0 < re (s + 1) := by simp only [add_re, one_re]; linarith
simpa only [sinZeta, ← mul_div_assoc, ← sum_div, div_left_inj' (Gammaℝ_ne_zero_of_re_pos hs'),
LFunction_eq_completed_div_gammaFactor_odd (dft_odd_iff.mpr hΦ)]
-- now calculate:
calc ∑ x, Φ x * sinZeta (toAddCircle x) s
_ = (∑ x, Φ x * expZeta (toAddCircle x) s) / (2 * I)
- (∑ x, Φ x * expZeta (toAddCircle (-x)) s) / (2 * I) := by
simp only [sinZeta_eq, ← mul_div_assoc, mul_sub, sub_div, sum_sub_distrib, sum_div, map_neg]
_ = (∑ x, Φ (-x) * expZeta (toAddCircle (-x)) s) / (_) - (_) := by
congrm ?_ / _ - _
exact (Fintype.sum_equiv (.neg _) _ _ fun x ↦ by rfl).symm
_ = -I⁻¹ * LFunction (𝓕 Φ) s := by
simp only [hΦ _, neg_mul, sum_neg_distrib, LFunction_dft Φ (.inl hΦ.map_zero)]
ring
_ = I * LFunction (𝓕 Φ) s := by rw [inv_I, neg_neg]
/--
Functional equation for completed L-functions (even case), valid at all points of differentiability.
-/
theorem completedLFunction_one_sub_even (hΦ : Φ.Even) (s : ℂ)
(hs₀ : s ≠ 0 ∨ ∑ j, Φ j = 0) (hs₁ : s ≠ 1 ∨ Φ 0 = 0) :
completedLFunction Φ (1 - s) = N ^ (s - 1) * completedLFunction (𝓕 Φ) s := by
-- We prove this using `AnalyticOnNhd.eqOn_of_preconnected_of_eventuallyEq`, so we need to
-- gather up the ingredients for this big theorem.
-- First set up some notations:
let F (t) := completedLFunction Φ (1 - t)
let G (t) := ↑N ^ (t - 1) * completedLFunction (𝓕 Φ) t
-- Set on which F, G are analytic:
let U := {t : ℂ | (t ≠ 0 ∨ ∑ j, Φ j = 0) ∧ (t ≠ 1 ∨ Φ 0 = 0)}
-- Properties of U:
have hsU : s ∈ U := ⟨hs₀, hs₁⟩
have h2U : 2 ∈ U := ⟨.inl two_ne_zero, .inl (OfNat.ofNat_ne_one _)⟩
have hUo : IsOpen U := (isOpen_compl_singleton.union isOpen_const).inter
(isOpen_compl_singleton.union isOpen_const)
have hUp : IsPreconnected U := by
-- need to write `U` as the complement of an obviously countable set
let Uc : Set ℂ := (if ∑ j, Φ j = 0 then ∅ else {0}) ∪ (if Φ 0 = 0 then ∅ else {1})
have : Uc.Countable := by
apply Countable.union <;>
split_ifs <;>
simp only [countable_singleton, countable_empty]
convert (this.isConnected_compl_of_one_lt_rank ?_).isPreconnected using 1
· ext x
by_cases h : Φ 0 = 0 <;>
by_cases h' : ∑ j, Φ j = 0 <;>
simp [U, Uc, h, h', and_comm]
· simp only [rank_real_complex, Nat.one_lt_ofNat]
-- Analyticity on U:
have hF : AnalyticOnNhd ℂ F U := by
refine DifferentiableOn.analyticOnNhd
(fun t ht ↦ DifferentiableAt.differentiableWithinAt ?_) hUo
refine (differentiableAt_completedLFunction Φ _ ?_ ?_).comp t (differentiableAt_id.const_sub 1)
exacts [ht.2.imp_left (sub_ne_zero.mpr ∘ Ne.symm), ht.1.imp_left sub_eq_self.not.mpr]
have hG : AnalyticOnNhd ℂ G U := by
refine DifferentiableOn.analyticOnNhd
(fun t ht ↦ DifferentiableAt.differentiableWithinAt ?_) hUo
apply ((differentiableAt_id.sub_const 1).const_cpow (.inl (NeZero.ne _))).mul
apply differentiableAt_completedLFunction _ _ (ht.1.imp_right fun h ↦ dft_apply_zero Φ ▸ h)
exact ht.2.imp_right (fun h ↦ by simp only [← dft_apply_zero, dft_dft, neg_zero, h, smul_zero])
-- set where we know equality
have hV : {z | 1 < re z} ∈ 𝓝 2 := (continuous_re.isOpen_preimage _ isOpen_Ioi).mem_nhds (by simp)
have hFG : F =ᶠ[𝓝 2] G := eventually_of_mem hV <| fun t ht ↦ by
simpa only [F, G, pow_zero, mul_one] using completedLFunction_one_sub_of_one_lt_even hΦ ht
-- now apply the big hammer to finish
exact hF.eqOn_of_preconnected_of_eventuallyEq hG hUp h2U hFG hsU
/-- Functional equation for completed L-functions (odd case), valid for all `s`. -/
theorem completedLFunction_one_sub_odd (hΦ : Φ.Odd) (s : ℂ) :
completedLFunction Φ (1 - s) = N ^ (s - 1) * I * completedLFunction (𝓕 Φ) s := by
-- This is much easier than the even case since both functions are entire.
-- First set up some notations:
let F (t) := completedLFunction Φ (1 - t)
let G (t) := ↑N ^ (t - 1) * I * completedLFunction (𝓕 Φ) t
-- check F, G globally differentiable
have hF : Differentiable ℂ F := (differentiable_completedLFunction hΦ.map_zero
hΦ.sum_eq_zero).comp (differentiable_id.const_sub 1)
have hG : Differentiable ℂ G := by
apply (((differentiable_id.sub_const 1).const_cpow (.inl (NeZero.ne _))).mul_const _).mul
rw [← dft_odd_iff] at hΦ
exact differentiable_completedLFunction hΦ.map_zero hΦ.sum_eq_zero
-- set where we know equality
have : {z | 1 < re z} ∈ 𝓝 2 := (continuous_re.isOpen_preimage _ isOpen_Ioi).mem_nhds (by simp)
have hFG : F =ᶠ[𝓝 2] G := by filter_upwards [this] with t ht
using completedLFunction_one_sub_of_one_lt_odd hΦ ht
-- now apply the big hammer to finish
rw [← analyticOnNhd_univ_iff_differentiable] at hF hG
exact congr_fun (hF.eq_of_eventuallyEq hG hFG) s
end signed
end ZMod |
.lake/packages/mathlib/Mathlib/NumberTheory/LSeries/Nonvanishing.lean | import Mathlib.Analysis.SpecialFunctions.Complex.LogBounds
import Mathlib.NumberTheory.Harmonic.ZetaAsymp
import Mathlib.NumberTheory.LSeries.Dirichlet
import Mathlib.NumberTheory.LSeries.DirichletContinuation
import Mathlib.NumberTheory.LSeries.Positivity
/-!
# The L-function of a Dirichlet character does not vanish on Re(s) ≥ 1
The main result in this file is `DirichletCharacter.LFunction_ne_zero_of_one_le_re`:
if `χ` is a Dirichlet character, `s ∈ ℂ` with `1 ≤ s.re`, and either `χ` is nontrivial or `s ≠ 1`,
then the L-function of `χ` does not vanish at `s`.
As a consequence, we have the corresponding statement for the Riemann ζ function:
`riemannZeta_ne_zero_of_one_le_re` (which does not require `s ≠ 1`, since the junk value at `s = 1`
happens to be non-zero).
These results are prerequisites for the **Prime Number Theorem** and
**Dirichlet's Theorem** on primes in arithmetic progressions.
## Outline of proofs
We split into two cases: first, the special case of (non-trivial) quadratic characters at `s = 1`;
then the remaining case when either `s ≠ 1` or `χ ^ 2 ≠ 1`.
The first case is handled using a positivity argument applied to the series `L χ s * ζ s`: we show
that this function has non-negative Dirichlet coefficients, is strictly positive for `s ≫ 0`, but
vanishes at `s = -2`, so it must have a pole somewhere in between.
The second case is dealt with using the product
`L(χ^0, 1 + x)^3 L(χ, 1 + x + I * y)^4 L(χ^2, 1 + x + 2 * I * y)`, which
we show has absolute value `≥ 1` for all positive `x` and real `y`; if `L(χ, 1 + I * y) = 0` then
this product would have to tend to 0 as `x → 0`, which is a contradiction.
-/
/- NB: Many lemmas (and some defs) in this file are private, since they concern properties of
hypothetical objects which we eventually deduce cannot exist. We have only made public the lemmas
whose hypotheses do not turn out to be contradictory.
-/
open Complex Asymptotics Topology Filter
open ArithmeticFunction hiding log
-- We use the ordering on `ℂ` given by comparing real parts for fixed imaginary part
open scoped ComplexOrder
variable {N : ℕ}
namespace DirichletCharacter
section quadratic
/-!
### Convolution of a Dirichlet character with ζ
We define `DirichletCharacter.zetaMul χ` to be the arithmetic function obtained by
taking the product (as arithmetic functions = Dirichlet convolution) of the
arithmetic function `ζ` with `χ`.
We then show that for a quadratic character `χ`, this arithmetic function is multiplicative
and takes nonnegative real values.
-/
/-- The complex-valued arithmetic function that is the convolution of the constant
function `1` with `χ`. -/
def zetaMul (χ : DirichletCharacter ℂ N) : ArithmeticFunction ℂ :=
.zeta * toArithmeticFunction (χ ·)
/-- The arithmetic function `zetaMul χ` is multiplicative. -/
lemma isMultiplicative_zetaMul (χ : DirichletCharacter ℂ N) : χ.zetaMul.IsMultiplicative :=
isMultiplicative_zeta.natCast.mul <| isMultiplicative_toArithmeticFunction χ
lemma LSeriesSummable_zetaMul (χ : DirichletCharacter ℂ N) {s : ℂ} (hs : 1 < s.re) :
LSeriesSummable χ.zetaMul s := by
refine ArithmeticFunction.LSeriesSummable_mul (LSeriesSummable_zeta_iff.mpr hs) <|
LSeriesSummable_of_bounded_of_one_lt_re (m := 1) (fun n hn ↦ ?_) hs
simpa only [toArithmeticFunction, coe_mk, hn, ↓reduceIte]
using norm_le_one χ _
lemma zetaMul_prime_pow_nonneg {χ : DirichletCharacter ℂ N} (hχ : χ ^ 2 = 1) {p : ℕ}
(hp : p.Prime) (k : ℕ) :
0 ≤ zetaMul χ (p ^ k) := by
simp only [zetaMul, toArithmeticFunction, coe_zeta_mul_apply, coe_mk,
Nat.sum_divisors_prime_pow hp, pow_eq_zero_iff', hp.ne_zero, ne_eq, false_and, ↓reduceIte,
Nat.cast_pow, map_pow]
rcases MulChar.isQuadratic_iff_sq_eq_one.mpr hχ p with h | h | h
· refine Finset.sum_nonneg fun i _ ↦ ?_
simp only [h, le_refl, pow_nonneg]
· refine Finset.sum_nonneg fun i _ ↦ ?_
simp only [h, one_pow, zero_le_one]
· simp only [h, neg_one_geom_sum]
split_ifs
exacts [le_rfl, zero_le_one]
/-- `zetaMul χ` takes nonnegative real values when `χ` is a quadratic character. -/
lemma zetaMul_nonneg {χ : DirichletCharacter ℂ N} (hχ : χ ^ 2 = 1) (n : ℕ) :
0 ≤ zetaMul χ n := by
rcases eq_or_ne n 0 with rfl | hn
· simp only [ArithmeticFunction.map_zero, le_refl]
· simpa only [χ.isMultiplicative_zetaMul.multiplicative_factorization _ hn] using
Finset.prod_nonneg
fun p hp ↦ zetaMul_prime_pow_nonneg hχ (Nat.prime_of_mem_primeFactors hp) _
/-
### "Bad" Dirichlet characters
Our goal is to show that `L(χ, 1) ≠ 0` when `χ` is a (nontrivial) quadratic Dirichlet character.
To do that, we package the contradictory properties in a (private) structure
`DirichletCharacter.BadChar` and derive further statements eventually leading to a contradiction.
This entire section is private.
-/
/-- The object we're trying to show doesn't exist: A nontrivial quadratic Dirichlet character
whose L-function vanishes at `s = 1`. -/
private structure BadChar (N : ℕ) [NeZero N] where
/-- The character we want to show cannot exist. -/
χ : DirichletCharacter ℂ N
χ_ne : χ ≠ 1
χ_sq : χ ^ 2 = 1
hχ : χ.LFunction 1 = 0
variable [NeZero N]
namespace BadChar
/-- The product of the Riemann zeta function with the L-function of `B.χ`.
We will show that `B.F (-2) = 0` but also that `B.F (-2)` must be positive,
giving the desired contradiction. -/
private noncomputable
def F (B : BadChar N) : ℂ → ℂ :=
Function.update (fun s : ℂ ↦ riemannZeta s * LFunction B.χ s) 1 (deriv (LFunction B.χ) 1)
private lemma F_differentiableAt_of_ne (B : BadChar N) {s : ℂ} (hs : s ≠ 1) :
DifferentiableAt ℂ B.F s := by
apply DifferentiableAt.congr_of_eventuallyEq
· exact (differentiableAt_riemannZeta hs).mul <| differentiableAt_LFunction B.χ s (.inl hs)
· filter_upwards [eventually_ne_nhds hs] with t ht using Function.update_of_ne ht ..
/-- `B.F` agrees with the L-series of `zetaMul χ` on `1 < s.re`. -/
private lemma F_eq_LSeries (B : BadChar N) {s : ℂ} (hs : 1 < s.re) :
B.F s = LSeries B.χ.zetaMul s := by
rw [F, zetaMul, ← coe_mul, LSeries_convolution']
· have hs' : s ≠ 1 := fun h ↦ by simp only [h, one_re, lt_self_iff_false] at hs
simp only [ne_eq, hs', not_false_eq_true, Function.update_of_ne, B.χ.LFunction_eq_LSeries hs]
congr 1
· simp_rw [← LSeries_zeta_eq_riemannZeta hs, ← natCoe_apply]
· exact LSeries_congr B.χ.apply_eq_toArithmeticFunction_apply s
-- summability side goals from `LSeries_convolution'`
· exact LSeriesSummable_zeta_iff.mpr hs
· exact (LSeriesSummable_congr _ fun h ↦ (B.χ.apply_eq_toArithmeticFunction_apply h).symm).mpr <|
ZMod.LSeriesSummable_of_one_lt_re B.χ hs
/-- If `χ` is a bad character, then `F` is an entire function. -/
private lemma F_differentiable (B : BadChar N) : Differentiable ℂ B.F := by
intro s
rcases ne_or_eq s 1 with hs | rfl
· exact B.F_differentiableAt_of_ne hs
-- now need to deal with `s = 1`
refine (analyticAt_of_differentiable_on_punctured_nhds_of_continuousAt ?_ ?_).differentiableAt
· filter_upwards [self_mem_nhdsWithin] with t ht
exact B.F_differentiableAt_of_ne ht
-- now reduced to showing *continuity* at s = 1
let G := Function.update (fun s ↦ (s - 1) * riemannZeta s) 1 1
let H := Function.update (fun s ↦ (B.χ.LFunction s - B.χ.LFunction 1) / (s - 1)) 1
(deriv B.χ.LFunction 1)
have : B.F = G * H := by
ext1 t
rcases eq_or_ne t 1 with rfl | ht
· simp only [F, G, H, Pi.mul_apply, one_mul, Function.update_self]
· simp only [F, G, H, Function.update_of_ne ht, mul_comm _ (riemannZeta _), B.hχ, sub_zero,
Pi.mul_apply, mul_assoc, mul_div_cancel₀ _ (sub_ne_zero.mpr ht)]
rw [this]
apply ContinuousAt.mul
· simpa only [G, continuousAt_update_same] using riemannZeta_residue_one
· exact (B.χ.differentiableAt_LFunction 1 (.inr B.χ_ne)).hasDerivAt.continuousAt_div
/-- The trivial zero at `s = -2` of the zeta function gives that `F (-2) = 0`.
This is used later to obtain a contradiction. -/
private lemma F_neg_two (B : BadChar N) : B.F (-2 : ℝ) = 0 := by
have := riemannZeta_neg_two_mul_nat_add_one 0
rw [Nat.cast_zero, zero_add, mul_one] at this
rw [F, ofReal_neg, ofReal_ofNat, Function.update_of_ne (mod_cast (by cutsat : (-2 : ℤ) ≠ 1)),
this, zero_mul]
end BadChar
/-- If `χ` is a nontrivial quadratic Dirichlet character, then `L(χ, 1) ≠ 0`. This is private
since it is later superseded by `LFunction_apply_one_ne_zero`. -/
private theorem LFunction_apply_one_ne_zero_of_quadratic {χ : DirichletCharacter ℂ N}
(hχ : χ ^ 2 = 1) (χ_ne : χ ≠ 1) :
χ.LFunction 1 ≠ 0 := by
intro hL
-- construct a "bad character" and put together a contradiction.
let B : BadChar N := {χ := χ, χ_sq := hχ, hχ := hL, χ_ne := χ_ne}
refine B.F_neg_two.not_gt ?_
refine ArithmeticFunction.LSeries_positive_of_differentiable_of_eqOn (zetaMul_nonneg hχ)
(χ.isMultiplicative_zetaMul.map_one ▸ zero_lt_one) B.F_differentiable ?_
(fun _ ↦ B.F_eq_LSeries) _
exact LSeries.abscissaOfAbsConv_le_of_forall_lt_LSeriesSummable
fun _ a ↦ χ.LSeriesSummable_zetaMul a
end quadratic
section nonvanishing
variable (χ : DirichletCharacter ℂ N)
-- This is the key positivity lemma that is used to show that the L-function
-- of a Dirichlet character `χ` does not vanish for `s.re ≥ 1` (unless `χ^2 = 1` and `s = 1`).
private lemma re_log_comb_nonneg' {a : ℝ} (ha₀ : 0 ≤ a) (ha₁ : a < 1) {z : ℂ} (hz : ‖z‖ = 1) :
0 ≤ 3 * (-log (1 - a)).re + 4 * (-log (1 - a * z)).re + (-log (1 - a * z ^ 2)).re := by
have hac₀ : ‖(a : ℂ)‖ < 1 := by
simp only [Complex.norm_of_nonneg ha₀, ha₁]
have hac₁ : ‖a * z‖ < 1 := by rwa [norm_mul, hz, mul_one]
have hac₂ : ‖a * z ^ 2‖ < 1 := by rwa [norm_mul, norm_pow, hz, one_pow, mul_one]
rw [← ((hasSum_re <| hasSum_taylorSeries_neg_log hac₀).mul_left 3).add
((hasSum_re <| hasSum_taylorSeries_neg_log hac₁).mul_left 4) |>.add
(hasSum_re <| hasSum_taylorSeries_neg_log hac₂) |>.tsum_eq]
refine tsum_nonneg fun n ↦ ?_
simp only [← ofReal_pow, div_natCast_re, ofReal_re, mul_pow, mul_re, ofReal_im, zero_mul,
sub_zero]
rcases n.eq_zero_or_pos with rfl | hn
· simp only [pow_zero, Nat.cast_zero, div_zero, mul_zero, one_re, mul_one, add_zero, le_refl]
· simp only [← mul_div_assoc, ← add_div]
refine div_nonneg ?_ n.cast_nonneg
rw [← pow_mul, pow_mul', sq, mul_re, ← sq, ← sq, ← sq_norm_sub_sq_re, norm_pow, hz]
convert (show 0 ≤ 2 * a ^ n * ((z ^ n).re + 1) ^ 2 by positivity) using 1
ring
-- This is the version of the technical positivity lemma for logarithms of Euler factors.
private lemma re_log_comb_nonneg {n : ℕ} (hn : 2 ≤ n) {x : ℝ} (hx : 1 < x) (y : ℝ) :
0 ≤ 3 * (-log (1 - (1 : DirichletCharacter ℂ N) n * n ^ (-x : ℂ))).re +
4 * (-log (1 - χ n * n ^ (-(x + I * y)))).re +
(-log (1 - (χ n ^ 2) * n ^ (-(x + 2 * I * y)))).re := by
by_cases hn' : IsUnit (n : ZMod N)
· have ha₀ : 0 ≤ (n : ℝ) ^ (-x) := Real.rpow_nonneg n.cast_nonneg _
have ha₁ : (n : ℝ) ^ (-x) < 1 := by
rw [Real.rpow_neg (Nat.cast_nonneg n), inv_lt_one_iff₀]
exact .inr <| Real.one_lt_rpow (mod_cast one_lt_two.trans_le hn) <| zero_lt_one.trans hx
have hz : ‖χ n * (n : ℂ) ^ (-(I * y))‖ = 1 := by
rw [norm_mul, ← hn'.unit_spec, DirichletCharacter.unit_norm_eq_one χ hn'.unit,
← ofReal_natCast, norm_cpow_eq_rpow_re_of_pos (mod_cast by cutsat)]
simp only [neg_re, mul_re, I_re, ofReal_re, zero_mul, I_im, ofReal_im, mul_zero, sub_self,
neg_zero, Real.rpow_zero, one_mul]
rw [MulChar.one_apply hn', one_mul]
convert re_log_comb_nonneg' ha₀ ha₁ hz using 6
· simp only [ofReal_cpow n.cast_nonneg (-x), ofReal_natCast, ofReal_neg]
· congr 2
rw [neg_add, cpow_add _ _ <| mod_cast by cutsat, ← ofReal_neg, ofReal_cpow n.cast_nonneg (-x),
ofReal_natCast, mul_left_comm]
· rw [neg_add, cpow_add _ _ <| mod_cast by cutsat, ← ofReal_neg, ofReal_cpow n.cast_nonneg (-x),
ofReal_natCast, show -(2 * I * y) = (2 : ℕ) * -(I * y) by ring, cpow_nat_mul, mul_pow,
mul_left_comm]
· simp only [MulChar.map_nonunit _ hn', zero_mul, sub_zero, log_one, neg_zero, zero_re, mul_zero,
neg_add_rev, add_zero, pow_two, le_refl]
/-- The logarithms of the Euler factors of a Dirichlet L-series form a summable sequence. -/
lemma summable_neg_log_one_sub_mul_prime_cpow {s : ℂ} (hs : 1 < s.re) :
Summable fun p : Nat.Primes ↦ -log (1 - χ p * (p : ℂ) ^ (-s)) := by
have (p : Nat.Primes) : ‖χ p * (p : ℂ) ^ (-s)‖ ≤ (p : ℝ) ^ (-s).re := by
simpa only [norm_mul, norm_natCast_cpow_of_re_ne_zero _ <| re_neg_ne_zero_of_one_lt_re hs]
using mul_le_of_le_one_left (by positivity) (χ.norm_le_one _)
refine (Nat.Primes.summable_rpow.mpr ?_).of_nonneg_of_le (fun _ ↦ norm_nonneg _) this
|>.of_norm.clog_one_sub.neg
simp only [neg_re, neg_lt_neg_iff, hs]
private lemma one_lt_re_one_add {x : ℝ} (hx : 0 < x) (y : ℝ) :
1 < (1 + x : ℂ).re ∧ 1 < (1 + x + I * y).re ∧ 1 < (1 + x + 2 * I * y).re := by
simp only [add_re, one_re, ofReal_re, lt_add_iff_pos_right, hx, mul_re, I_re, zero_mul, I_im,
ofReal_im, mul_zero, sub_self, add_zero, re_ofNat, im_ofNat, mul_one, mul_im, and_self]
open scoped LSeries.notation in
/-- For positive `x` and nonzero `y` and a Dirichlet character `χ` we have that
`|L(χ^0, 1 + x)^3 L(χ, 1 + x + I * y)^4 L(χ^2, 1 + x + 2 * I * y)| ≥ 1. -/
lemma norm_LSeries_product_ge_one {x : ℝ} (hx : 0 < x) (y : ℝ) :
‖L ↗(1 : DirichletCharacter ℂ N) (1 + x) ^ 3 * L ↗χ (1 + x + I * y) ^ 4 *
L ↗(χ ^ 2 :) (1 + x + 2 * I * y)‖ ≥ 1 := by
have ⟨h₀, h₁, h₂⟩ := one_lt_re_one_add hx y
have H₀ := summable_neg_log_one_sub_mul_prime_cpow (N := N) 1 h₀
have H₁ := summable_neg_log_one_sub_mul_prime_cpow χ h₁
have H₂ := summable_neg_log_one_sub_mul_prime_cpow (χ ^ 2) h₂
have hsum₀ := (hasSum_re H₀.hasSum).summable.mul_left 3
have hsum₁ := (hasSum_re H₁.hasSum).summable.mul_left 4
have hsum₂ := (hasSum_re H₂.hasSum).summable
rw [← LSeries_eulerProduct_exp_log _ h₀, ← LSeries_eulerProduct_exp_log χ h₁,
← LSeries_eulerProduct_exp_log _ h₂]
simp only [← exp_nat_mul, Nat.cast_ofNat, ← exp_add, norm_exp, add_re, mul_re,
re_ofNat, im_ofNat, zero_mul, sub_zero, Real.one_le_exp_iff]
rw [re_tsum H₀, re_tsum H₁, re_tsum H₂, ← tsum_mul_left, ← tsum_mul_left,
← hsum₀.tsum_add hsum₁, ← (hsum₀.add hsum₁).tsum_add hsum₂]
simpa only [neg_add_rev, neg_re, mul_neg, χ.pow_apply' two_ne_zero, ge_iff_le, add_re, one_re,
ofReal_re, ofReal_add, ofReal_one] using
tsum_nonneg fun (p : Nat.Primes) ↦ χ.re_log_comb_nonneg p.prop.two_le h₀ y
variable [NeZero N]
/-- A variant of `DirichletCharacter.norm_LSeries_product_ge_one` in terms of the L-functions. -/
lemma norm_LFunction_product_ge_one {x : ℝ} (hx : 0 < x) (y : ℝ) :
‖LFunctionTrivChar N (1 + x) ^ 3 * LFunction χ (1 + x + I * y) ^ 4 *
LFunction (χ ^ 2) (1 + x + 2 * I * y)‖ ≥ 1 := by
have ⟨h₀, h₁, h₂⟩ := one_lt_re_one_add hx y
rw [LFunctionTrivChar, DirichletCharacter.LFunction_eq_LSeries 1 h₀,
χ.LFunction_eq_LSeries h₁, (χ ^ 2).LFunction_eq_LSeries h₂]
exact norm_LSeries_product_ge_one χ hx y
lemma LFunctionTrivChar_isBigO_near_one_horizontal :
(fun x : ℝ ↦ LFunctionTrivChar N (1 + x)) =O[𝓝[>] 0] fun x ↦ (1 : ℂ) / x := by
have : (fun w : ℂ ↦ LFunctionTrivChar N (1 + w)) =O[𝓝[≠] 0] (1 / ·) := by
have H : Tendsto (fun w ↦ w * LFunctionTrivChar N (1 + w)) (𝓝[≠] 0)
(𝓝 <| ∏ p ∈ N.primeFactors, (1 - (p : ℂ)⁻¹)) := by
convert (LFunctionTrivChar_residue_one (N := N)).comp (f := fun w ↦ 1 + w) ?_ using 1
· simp only [Function.comp_def, add_sub_cancel_left]
· simpa only [tendsto_iff_comap, Homeomorph.coe_addLeft, add_zero, map_le_iff_le_comap] using
((Homeomorph.addLeft (1 : ℂ)).map_punctured_nhds_eq 0).le
exact (isBigO_mul_iff_isBigO_div eventually_mem_nhdsWithin).mp <| H.isBigO_one ℂ
exact (isBigO_comp_ofReal_nhds_ne this).mono <| nhdsGT_le_nhdsNE 0
omit [NeZero N] in
private lemma one_add_I_mul_ne_one_or {y : ℝ} (hy : y ≠ 0 ∨ χ ≠ 1) :
1 + I * y ≠ 1 ∨ χ ≠ 1 := by
simpa only [ne_eq, add_eq_left, _root_.mul_eq_zero, I_ne_zero, ofReal_eq_zero, false_or]
using hy
lemma LFunction_isBigO_horizontal {y : ℝ} (hy : y ≠ 0 ∨ χ ≠ 1) :
(fun x : ℝ ↦ LFunction χ (1 + x + I * y)) =O[𝓝[>] 0] fun _ ↦ (1 : ℂ) := by
refine IsBigO.mono ?_ nhdsWithin_le_nhds
simp_rw [add_comm (1 : ℂ), add_assoc]
have := (χ.differentiableAt_LFunction _ <| one_add_I_mul_ne_one_or χ hy).continuousAt
rw [← zero_add (1 + _)] at this
exact this.comp (f := fun x : ℝ ↦ x + (1 + I * y)) (x := 0) (by fun_prop) |>.tendsto.isBigO_one ℂ
private lemma LFunction_isBigO_horizontal_of_eq_zero {y : ℝ} (hy : y ≠ 0 ∨ χ ≠ 1)
(h : LFunction χ (1 + I * y) = 0) :
(fun x : ℝ ↦ LFunction χ (1 + x + I * y)) =O[𝓝[>] 0] fun x : ℝ ↦ (x : ℂ) := by
simp_rw [add_comm (1 : ℂ), add_assoc]
have := (χ.differentiableAt_LFunction _ <| one_add_I_mul_ne_one_or χ hy).hasDerivAt
rw [← zero_add (1 + _)] at this
simpa only [zero_add, h, sub_zero]
using (Complex.isBigO_comp_ofReal_nhds
(this.comp_add_const 0 _).differentiableAt.isBigO_sub) |>.mono nhdsWithin_le_nhds
-- intermediate statement, special case of the next theorem
private lemma LFunction_ne_zero_of_not_quadratic_or_ne_one {t : ℝ} (h : χ ^ 2 ≠ 1 ∨ t ≠ 0) :
LFunction χ (1 + I * t) ≠ 0 := by
intro Hz
have hz₁ : t ≠ 0 ∨ χ ≠ 1 := by
refine h.symm.imp_right (fun h H ↦ ?_)
simp only [H, one_pow, ne_eq, not_true_eq_false] at h
have hz₂ : 2 * t ≠ 0 ∨ χ ^ 2 ≠ 1 :=
h.symm.imp_left <| mul_ne_zero two_ne_zero
have help (x : ℝ) : ((1 / x) ^ 3 * x ^ 4 * 1 : ℂ) = x := by
rcases eq_or_ne x 0 with rfl | h
· rw [ofReal_zero, zero_pow (by cutsat), mul_zero, mul_one]
· rw [one_div, inv_pow, pow_succ _ 3, ← mul_assoc,
inv_mul_cancel₀ <| pow_ne_zero 3 (ofReal_ne_zero.mpr h), one_mul, mul_one]
-- put together the various `IsBigO` statements and `norm_LFunction_product_ge_one`
-- to derive a contradiction
have H₀ : (fun _ : ℝ ↦ (1 : ℝ)) =O[𝓝[>] 0]
fun x ↦ LFunctionTrivChar N (1 + x) ^ 3 * LFunction χ (1 + x + I * t) ^ 4 *
LFunction (χ ^ 2) (1 + x + 2 * I * t) :=
IsBigO.of_bound' <| eventually_nhdsWithin_of_forall
fun _ hx ↦ (norm_one (α := ℝ)).symm ▸ (χ.norm_LFunction_product_ge_one hx t).le
have H := (LFunctionTrivChar_isBigO_near_one_horizontal (N := N)).pow 3 |>.mul <|
(χ.LFunction_isBigO_horizontal_of_eq_zero hz₁ Hz).pow 4 |>.mul <|
LFunction_isBigO_horizontal _ hz₂
simp only [ofReal_mul, ofReal_ofNat, mul_left_comm I, ← mul_assoc, help] at H
-- go via absolute value to translate into a statement over `ℝ`
replace H := (H₀.trans H).norm_right
simp only [norm_real] at H
exact isLittleO_irrefl (.of_forall (fun _ ↦ one_ne_zero)) <|
H.of_norm_right.trans_isLittleO <| isLittleO_id_one.mono nhdsWithin_le_nhds
/-- If `χ` is a Dirichlet character, then `L(χ, s)` does not vanish when `s.re = 1`
except when `χ` is trivial and `s = 1` (then `L(χ, s)` has a simple pole at `s = 1`). -/
theorem LFunction_ne_zero_of_re_eq_one {s : ℂ} (hs : s.re = 1) (hχs : χ ≠ 1 ∨ s ≠ 1) :
LFunction χ s ≠ 0 := by
by_cases h : χ ^ 2 = 1 ∧ s = 1
· exact h.2 ▸ LFunction_apply_one_ne_zero_of_quadratic h.1 <| hχs.neg_resolve_right h.2
· have hs' : s = 1 + I * s.im := by
conv_lhs => rw [← re_add_im s, hs, ofReal_one, mul_comm]
rw [not_and_or, ← ne_eq, ← ne_eq, hs', add_ne_left] at h
replace h : χ ^ 2 ≠ 1 ∨ s.im ≠ 0 :=
h.imp_right (fun H ↦ by exact_mod_cast right_ne_zero_of_mul H)
exact hs'.symm ▸ χ.LFunction_ne_zero_of_not_quadratic_or_ne_one h
/-- If `χ` is a Dirichlet character, then `L(χ, s)` does not vanish for `s.re ≥ 1`
except when `χ` is trivial and `s = 1` (then `L(χ, s)` has a simple pole at `s = 1`). -/
theorem LFunction_ne_zero_of_one_le_re ⦃s : ℂ⦄ (hχs : χ ≠ 1 ∨ s ≠ 1) (hs : 1 ≤ s.re) :
LFunction χ s ≠ 0 :=
hs.eq_or_lt.casesOn (fun hs ↦ LFunction_ne_zero_of_re_eq_one χ hs.symm hχs)
fun hs ↦ LFunction_eq_LSeries χ hs ▸ LSeries_ne_zero_of_one_lt_re χ hs
-- Interesting special case:
variable {χ} in
/-- The L-function of a nontrivial Dirichlet character does not vanish at `s = 1`. -/
theorem LFunction_apply_one_ne_zero (hχ : χ ≠ 1) : LFunction χ 1 ≠ 0 :=
LFunction_ne_zero_of_one_le_re χ (.inl hχ) <| one_re ▸ le_rfl
/-- The Riemann Zeta Function does not vanish on the closed half-plane `re s ≥ 1`.
(Note that the value at `s = 1` is a junk value, which happens to be nonzero.) -/
lemma _root_.riemannZeta_ne_zero_of_one_le_re ⦃s : ℂ⦄ (hs : 1 ≤ s.re) :
riemannZeta s ≠ 0 := by
rcases eq_or_ne s 1 with rfl | hs₀
· exact riemannZeta_one_ne_zero
· exact LFunction_modOne_eq (χ := 1) ▸ LFunction_ne_zero_of_one_le_re _ (.inr hs₀) hs
end nonvanishing
end DirichletCharacter |
.lake/packages/mathlib/Mathlib/NumberTheory/LSeries/HurwitzZeta.lean | import Mathlib.NumberTheory.LSeries.HurwitzZetaEven
import Mathlib.NumberTheory.LSeries.HurwitzZetaOdd
import Mathlib.Analysis.SpecialFunctions.Gamma.Beta
/-!
# The Hurwitz zeta function
This file gives the definition and properties of the following two functions:
* The **Hurwitz zeta function**, which is the meromorphic continuation to all `s ∈ ℂ` of the
function defined for `1 < re s` by the series
`∑' n, 1 / (n + a) ^ s`
for a parameter `a ∈ ℝ`, with the sum taken over all `n` such that `n + a > 0`;
* the related sum, which we call the "**exponential zeta function**" (does it have a standard name?)
`∑' n : ℕ, exp (2 * π * I * n * a) / n ^ s`.
## Main definitions and results
* `hurwitzZeta`: the Hurwitz zeta function (defined to be periodic in `a` with period 1)
* `expZeta`: the exponential zeta function
* `hasSum_hurwitzZeta_of_one_lt_re` and `hasSum_expZeta_of_one_lt_re`:
relation to Dirichlet series for `1 < re s`
* ` hurwitzZeta_residue_one` shows that the residue at `s = 1` equals `1`
* `differentiableAt_hurwitzZeta` and `differentiableAt_expZeta`: analyticity away from `s = 1`
* `hurwitzZeta_one_sub` and `expZeta_one_sub`: functional equations `s ↔ 1 - s`.
-/
open Set Real Complex Filter Topology
namespace HurwitzZeta
/-!
## The Hurwitz zeta function
-/
/-- The Hurwitz zeta function, which is the meromorphic continuation of
`∑ (n : ℕ), 1 / (n + a) ^ s` if `0 ≤ a ≤ 1`. See `hasSum_hurwitzZeta_of_one_lt_re` for the relation
to the Dirichlet series in the convergence range. -/
noncomputable def hurwitzZeta (a : UnitAddCircle) (s : ℂ) :=
hurwitzZetaEven a s + hurwitzZetaOdd a s
lemma hurwitzZetaEven_eq (a : UnitAddCircle) (s : ℂ) :
hurwitzZetaEven a s = (hurwitzZeta a s + hurwitzZeta (-a) s) / 2 := by
simp only [hurwitzZeta, hurwitzZetaEven_neg, hurwitzZetaOdd_neg]
ring_nf
lemma hurwitzZetaOdd_eq (a : UnitAddCircle) (s : ℂ) :
hurwitzZetaOdd a s = (hurwitzZeta a s - hurwitzZeta (-a) s) / 2 := by
simp only [hurwitzZeta, hurwitzZetaEven_neg, hurwitzZetaOdd_neg]
ring_nf
/-- The Hurwitz zeta function is differentiable away from `s = 1`. -/
lemma differentiableAt_hurwitzZeta (a : UnitAddCircle) {s : ℂ} (hs : s ≠ 1) :
DifferentiableAt ℂ (hurwitzZeta a) s :=
(differentiableAt_hurwitzZetaEven a hs).add (differentiable_hurwitzZetaOdd a s)
/-- Formula for `hurwitzZeta s` as a Dirichlet series in the convergence range. We
restrict to `a ∈ Icc 0 1` to simplify the statement. -/
lemma hasSum_hurwitzZeta_of_one_lt_re {a : ℝ} (ha : a ∈ Icc 0 1) {s : ℂ} (hs : 1 < re s) :
HasSum (fun n : ℕ ↦ 1 / (n + a : ℂ) ^ s) (hurwitzZeta a s) := by
convert (hasSum_nat_hurwitzZetaEven_of_mem_Icc ha hs).add
(hasSum_nat_hurwitzZetaOdd_of_mem_Icc ha hs) using 1
ext1 n
-- plain `ring_nf` works here, but the following is faster:
apply show ∀ (x y : ℂ), x = (x + y) / 2 + (x - y) / 2 by intros; ring
/-- The residue of the Hurwitz zeta function at `s = 1` is `1`. -/
lemma hurwitzZeta_residue_one (a : UnitAddCircle) :
Tendsto (fun s ↦ (s - 1) * hurwitzZeta a s) (𝓝[≠] 1) (𝓝 1) := by
simp only [hurwitzZeta, mul_add, (by simp : 𝓝 (1 : ℂ) = 𝓝 (1 + (1 - 1) * hurwitzZetaOdd a 1))]
refine (hurwitzZetaEven_residue_one a).add ((Tendsto.mul ?_ ?_).mono_left nhdsWithin_le_nhds)
exacts [tendsto_id.sub_const _, (differentiable_hurwitzZetaOdd a).continuous.tendsto _]
lemma differentiableAt_hurwitzZeta_sub_one_div (a : UnitAddCircle) :
DifferentiableAt ℂ (fun s ↦ hurwitzZeta a s - 1 / (s - 1) / Gammaℝ s) 1 := by
simp only [hurwitzZeta, add_sub_right_comm]
exact (differentiableAt_hurwitzZetaEven_sub_one_div a).add (differentiable_hurwitzZetaOdd a 1)
/-- Expression for `hurwitzZeta a 1` as a limit. (Mathematically `hurwitzZeta a 1` is
undefined, but our construction assigns some value to it; this lemma is mostly of interest for
determining what that value is). -/
lemma tendsto_hurwitzZeta_sub_one_div_nhds_one (a : UnitAddCircle) :
Tendsto (fun s ↦ hurwitzZeta a s - 1 / (s - 1) / Gammaℝ s) (𝓝 1) (𝓝 (hurwitzZeta a 1)) := by
simp only [hurwitzZeta, add_sub_right_comm]
refine (tendsto_hurwitzZetaEven_sub_one_div_nhds_one a).add
(differentiable_hurwitzZetaOdd a 1).continuousAt.tendsto
/-- The difference of two Hurwitz zeta functions is differentiable everywhere. -/
lemma differentiable_hurwitzZeta_sub_hurwitzZeta (a b : UnitAddCircle) :
Differentiable ℂ (fun s ↦ hurwitzZeta a s - hurwitzZeta b s) := by
simp only [hurwitzZeta, add_sub_add_comm]
refine (differentiable_hurwitzZetaEven_sub_hurwitzZetaEven a b).add (.sub ?_ ?_)
all_goals apply differentiable_hurwitzZetaOdd
/-!
## The exponential zeta function
-/
/-- Meromorphic continuation of the series `∑' (n : ℕ), exp (2 * π * I * a * n) / n ^ s`. See
`hasSum_expZeta_of_one_lt_re` for the relation to the Dirichlet series. -/
noncomputable def expZeta (a : UnitAddCircle) (s : ℂ) :=
cosZeta a s + I * sinZeta a s
lemma cosZeta_eq (a : UnitAddCircle) (s : ℂ) :
cosZeta a s = (expZeta a s + expZeta (-a) s) / 2 := by
rw [expZeta, expZeta, cosZeta_neg, sinZeta_neg]
ring_nf
lemma sinZeta_eq (a : UnitAddCircle) (s : ℂ) :
sinZeta a s = (expZeta a s - expZeta (-a) s) / (2 * I) := by
rw [expZeta, expZeta, cosZeta_neg, sinZeta_neg]
field
lemma hasSum_expZeta_of_one_lt_re (a : ℝ) {s : ℂ} (hs : 1 < re s) :
HasSum (fun n : ℕ ↦ cexp (2 * π * I * a * n) / n ^ s) (expZeta a s) := by
convert (hasSum_nat_cosZeta a hs).add ((hasSum_nat_sinZeta a hs).mul_left I) using 1
ext1 n
simp only [mul_right_comm _ I, ← cos_add_sin_I, push_cast]
rw [add_div, mul_div, mul_comm _ I]
lemma differentiableAt_expZeta (a : UnitAddCircle) (s : ℂ) (hs : s ≠ 1 ∨ a ≠ 0) :
DifferentiableAt ℂ (expZeta a) s := by
apply DifferentiableAt.add
· exact differentiableAt_cosZeta a hs
· apply (differentiableAt_const _).mul (differentiableAt_sinZeta a s)
/-- If `a ≠ 0` then the exponential zeta function is analytic everywhere. -/
lemma differentiable_expZeta_of_ne_zero {a : UnitAddCircle} (ha : a ≠ 0) :
Differentiable ℂ (expZeta a) :=
(differentiableAt_expZeta a · (Or.inr ha))
/-- Reformulation of `hasSum_expZeta_of_one_lt_re` using `LSeriesHasSum`. -/
lemma LSeriesHasSum_exp (a : ℝ) {s : ℂ} (hs : 1 < re s) :
LSeriesHasSum (cexp <| 2 * π * I * a * ·) s (expZeta a s) :=
(hasSum_expZeta_of_one_lt_re a hs).congr_fun
(LSeries.term_of_ne_zero' (ne_zero_of_one_lt_re hs) _)
/-!
## The functional equation
-/
lemma hurwitzZeta_one_sub (a : UnitAddCircle) {s : ℂ}
(hs : ∀ (n : ℕ), s ≠ -n) (hs' : a ≠ 0 ∨ s ≠ 1) :
hurwitzZeta a (1 - s) = (2 * π) ^ (-s) * Gamma s *
(exp (-π * I * s / 2) * expZeta a s + exp (π * I * s / 2) * expZeta (-a) s) := by
rw [hurwitzZeta, hurwitzZetaEven_one_sub a hs hs', hurwitzZetaOdd_one_sub a hs,
expZeta, expZeta, Complex.cos, Complex.sin, sinZeta_neg, cosZeta_neg]
rw [show ↑π * I * s / 2 = ↑π * s / 2 * I by ring,
show -↑π * I * s / 2 = -(↑π * s / 2) * I by ring]
-- these `generalize` commands are not strictly needed for the `ring_nf` call to succeed, but
-- make it run faster:
generalize (2 * π : ℂ) ^ (-s) = x
generalize (↑π * s / 2 * I).exp = y
generalize (-(↑π * s / 2) * I).exp = z
ring_nf
/-- Functional equation for the exponential zeta function. -/
lemma expZeta_one_sub (a : UnitAddCircle) {s : ℂ} (hs : ∀ (n : ℕ), s ≠ 1 - n) :
expZeta a (1 - s) = (2 * π) ^ (-s) * Gamma s *
(exp (π * I * s / 2) * hurwitzZeta a s + exp (-π * I * s / 2) * hurwitzZeta (-a) s) := by
have hs' (n : ℕ) : s ≠ -↑n := by
convert hs (n + 1) using 1
push_cast
ring
rw [expZeta, cosZeta_one_sub a hs, sinZeta_one_sub a hs', hurwitzZeta, hurwitzZeta,
hurwitzZetaEven_neg, hurwitzZetaOdd_neg, Complex.cos, Complex.sin]
rw [show ↑π * I * s / 2 = ↑π * s / 2 * I by ring,
show -↑π * I * s / 2 = -(↑π * s / 2) * I by ring]
-- these `generalize` commands are not strictly needed for the `ring_nf` call to succeed, but
-- make it run faster:
generalize (2 * π : ℂ) ^ (-s) = x
generalize (↑π * s / 2 * I).exp = y
generalize (-(↑π * s / 2) * I).exp = z
ring_nf
rw [I_sq]
ring_nf
end HurwitzZeta |
.lake/packages/mathlib/Mathlib/NumberTheory/LegendreSymbol/Basic.lean | import Mathlib.NumberTheory.LegendreSymbol.QuadraticChar.Basic
/-!
# Legendre symbol
This file contains results about Legendre symbols.
We define the Legendre symbol $\Bigl(\frac{a}{p}\Bigr)$ as `legendreSym p a`.
Note the order of arguments! The advantage of this form is that then `legendreSym p`
is a multiplicative map.
The Legendre symbol is used to define the Jacobi symbol, `jacobiSym a b`, for integers `a`
and (odd) natural numbers `b`, which extends the Legendre symbol.
## Main results
We also prove the supplementary laws that give conditions for when `-1`
is a square modulo a prime `p`:
`legendreSym.at_neg_one` and `ZMod.exists_sq_eq_neg_one_iff` for `-1`.
See `NumberTheory.LegendreSymbol.QuadraticReciprocity` for the conditions when `2` and `-2`
are squares:
`legendreSym.at_two` and `ZMod.exists_sq_eq_two_iff` for `2`,
`legendreSym.at_neg_two` and `ZMod.exists_sq_eq_neg_two_iff` for `-2`.
## Tags
quadratic residue, quadratic nonresidue, Legendre symbol
-/
open Nat
section Euler
namespace ZMod
variable (p : ℕ) [Fact p.Prime]
/-- Euler's Criterion: A unit `x` of `ZMod p` is a square if and only if `x ^ (p / 2) = 1`. -/
theorem euler_criterion_units (x : (ZMod p)ˣ) : (∃ y : (ZMod p)ˣ, y ^ 2 = x) ↔ x ^ (p / 2) = 1 := by
by_cases hc : p = 2
· subst hc
simp only [eq_iff_true_of_subsingleton, exists_const]
· have h₀ := FiniteField.unit_isSquare_iff (by rwa [ringChar_zmod_n]) x
have hs : (∃ y : (ZMod p)ˣ, y ^ 2 = x) ↔ IsSquare x := by
rw [isSquare_iff_exists_sq x]
simp_rw [eq_comm]
rw [hs]
rwa [card p] at h₀
/-- Euler's Criterion: a nonzero `a : ZMod p` is a square if and only if `x ^ (p / 2) = 1`. -/
theorem euler_criterion {a : ZMod p} (ha : a ≠ 0) : IsSquare (a : ZMod p) ↔ a ^ (p / 2) = 1 := by
apply (iff_congr _ (by simp [Units.ext_iff])).mp (euler_criterion_units p (Units.mk0 a ha))
simp only [Units.ext_iff, sq, Units.val_mk0, Units.val_mul]
constructor
· rintro ⟨y, hy⟩; exact ⟨y, hy.symm⟩
· rintro ⟨y, rfl⟩
have hy : y ≠ 0 := by
rintro rfl
simp [mul_zero, ne_eq] at ha
refine ⟨Units.mk0 y hy, ?_⟩; simp
/-- If `a : ZMod p` is nonzero, then `a^(p/2)` is either `1` or `-1`. -/
theorem pow_div_two_eq_neg_one_or_one {a : ZMod p} (ha : a ≠ 0) :
a ^ (p / 2) = 1 ∨ a ^ (p / 2) = -1 := by
rcases Prime.eq_two_or_odd (@Fact.out p.Prime _) with hp2 | hp_odd
· subst p; revert a ha; intro a; fin_cases a
· tauto
· simp
rw [← mul_self_eq_one_iff, ← pow_add, ← two_mul, two_mul_odd_div_two hp_odd]
exact pow_card_sub_one_eq_one ha
end ZMod
end Euler
section Legendre
/-!
### Definition of the Legendre symbol and basic properties
-/
open ZMod
variable (p : ℕ) [Fact p.Prime]
/-- The Legendre symbol of `a : ℤ` and a prime `p`, `legendreSym p a`,
is an integer defined as
* `0` if `a` is `0` modulo `p`;
* `1` if `a` is a nonzero square modulo `p`
* `-1` otherwise.
Note the order of the arguments! The advantage of the order chosen here is
that `legendreSym p` is a multiplicative function `ℤ → ℤ`.
-/
def legendreSym (a : ℤ) : ℤ :=
quadraticChar (ZMod p) a
namespace legendreSym
/-- We have the congruence `legendreSym p a ≡ a ^ (p / 2) mod p`. -/
theorem eq_pow (a : ℤ) : (legendreSym p a : ZMod p) = (a : ZMod p) ^ (p / 2) := by
rcases eq_or_ne (ringChar (ZMod p)) 2 with hc | hc
· by_cases ha : (a : ZMod p) = 0
· rw [legendreSym, ha, quadraticChar_zero,
zero_pow (Nat.div_pos (@Fact.out p.Prime).two_le (succ_pos 1)).ne']
norm_cast
· have := (ringChar_zmod_n p).symm.trans hc
-- p = 2
subst p
rw [legendreSym, quadraticChar_eq_one_of_char_two hc ha]
revert ha
push_cast
generalize (a : ZMod 2) = b; fin_cases b
· tauto
· simp
· convert quadraticChar_eq_pow_of_char_ne_two' hc (a : ZMod p)
exact (card p).symm
/-- If `p ∤ a`, then `legendreSym p a` is `1` or `-1`. -/
theorem eq_one_or_neg_one {a : ℤ} (ha : (a : ZMod p) ≠ 0) :
legendreSym p a = 1 ∨ legendreSym p a = -1 :=
quadraticChar_dichotomy ha
theorem eq_neg_one_iff_not_one {a : ℤ} (ha : (a : ZMod p) ≠ 0) :
legendreSym p a = -1 ↔ ¬legendreSym p a = 1 :=
quadraticChar_eq_neg_one_iff_not_one ha
/-- The Legendre symbol of `p` and `a` is zero iff `p ∣ a`. -/
theorem eq_zero_iff (a : ℤ) : legendreSym p a = 0 ↔ (a : ZMod p) = 0 :=
quadraticChar_eq_zero_iff
@[simp]
theorem at_zero : legendreSym p 0 = 0 := by rw [legendreSym, Int.cast_zero, MulChar.map_zero]
@[simp]
theorem at_one : legendreSym p 1 = 1 := by rw [legendreSym, Int.cast_one, MulChar.map_one]
/-- The Legendre symbol is multiplicative in `a` for `p` fixed. -/
protected theorem mul (a b : ℤ) : legendreSym p (a * b) = legendreSym p a * legendreSym p b := by
simp [legendreSym, Int.cast_mul, map_mul]
/-- The Legendre symbol is a homomorphism of monoids with zero. -/
@[simps]
def hom : ℤ →*₀ ℤ where
toFun := legendreSym p
map_zero' := at_zero p
map_one' := at_one p
map_mul' := legendreSym.mul p
/-- The square of the symbol is 1 if `p ∤ a`. -/
theorem sq_one {a : ℤ} (ha : (a : ZMod p) ≠ 0) : legendreSym p a ^ 2 = 1 :=
quadraticChar_sq_one ha
/-- The Legendre symbol of `a^2` at `p` is 1 if `p ∤ a`. -/
theorem sq_one' {a : ℤ} (ha : (a : ZMod p) ≠ 0) : legendreSym p (a ^ 2) = 1 := by
dsimp only [legendreSym]
rw [Int.cast_pow]
exact quadraticChar_sq_one' ha
/-- The Legendre symbol depends only on `a` mod `p`. -/
protected theorem mod (a : ℤ) : legendreSym p a = legendreSym p (a % p) := by
simp only [legendreSym, intCast_mod]
/-- When `p ∤ a`, then `legendreSym p a = 1` iff `a` is a square mod `p`. -/
theorem eq_one_iff {a : ℤ} (ha0 : (a : ZMod p) ≠ 0) : legendreSym p a = 1 ↔ IsSquare (a : ZMod p) :=
quadraticChar_one_iff_isSquare ha0
theorem eq_one_iff' {a : ℕ} (ha0 : (a : ZMod p) ≠ 0) :
legendreSym p a = 1 ↔ IsSquare (a : ZMod p) := by
rw [eq_one_iff]
· norm_cast
· exact mod_cast ha0
/-- `legendreSym p a = -1` iff `a` is a nonsquare mod `p`. -/
theorem eq_neg_one_iff {a : ℤ} : legendreSym p a = -1 ↔ ¬IsSquare (a : ZMod p) :=
quadraticChar_neg_one_iff_not_isSquare
theorem eq_neg_one_iff' {a : ℕ} : legendreSym p a = -1 ↔ ¬IsSquare (a : ZMod p) := by
rw [eq_neg_one_iff]; norm_cast
/-- The number of square roots of `a` modulo `p` is determined by the Legendre symbol. -/
theorem card_sqrts (hp : p ≠ 2) (a : ℤ) :
↑{x : ZMod p | x ^ 2 = a}.toFinset.card = legendreSym p a + 1 :=
quadraticChar_card_sqrts ((ringChar_zmod_n p).substr hp) a
end legendreSym
end Legendre
section QuadraticForm
/-!
### Applications to binary quadratic forms
-/
namespace legendreSym
/-- The Legendre symbol `legendreSym p a = 1` if there is a solution in `ℤ/pℤ`
of the equation `x^2 - a*y^2 = 0` with `y ≠ 0`. -/
theorem eq_one_of_sq_sub_mul_sq_eq_zero {p : ℕ} [Fact p.Prime] {a : ℤ} (ha : (a : ZMod p) ≠ 0)
{x y : ZMod p} (hy : y ≠ 0) (hxy : x ^ 2 - a * y ^ 2 = 0) : legendreSym p a = 1 := by
apply_fun (· * y⁻¹ ^ 2) at hxy
simp only [zero_mul] at hxy
rw [(by ring : (x ^ 2 - ↑a * y ^ 2) * y⁻¹ ^ 2 = (x * y⁻¹) ^ 2 - a * (y * y⁻¹) ^ 2),
mul_inv_cancel₀ hy, one_pow, mul_one, sub_eq_zero, pow_two] at hxy
exact (eq_one_iff p ha).mpr ⟨x * y⁻¹, hxy.symm⟩
/-- The Legendre symbol `legendreSym p a = 1` if there is a solution in `ℤ/pℤ`
of the equation `x^2 - a*y^2 = 0` with `x ≠ 0`. -/
theorem eq_one_of_sq_sub_mul_sq_eq_zero' {p : ℕ} [Fact p.Prime] {a : ℤ} (ha : (a : ZMod p) ≠ 0)
{x y : ZMod p} (hx : x ≠ 0) (hxy : x ^ 2 - a * y ^ 2 = 0) : legendreSym p a = 1 := by
haveI hy : y ≠ 0 := by
rintro rfl
rw [zero_pow two_ne_zero, mul_zero, sub_zero, sq_eq_zero_iff] at hxy
exact hx hxy
exact eq_one_of_sq_sub_mul_sq_eq_zero ha hy hxy
/-- If `legendreSym p a = -1`, then the only solution of `x^2 - a*y^2 = 0` in `ℤ/pℤ`
is the trivial one. -/
theorem eq_zero_mod_of_eq_neg_one {p : ℕ} [Fact p.Prime] {a : ℤ} (h : legendreSym p a = -1)
{x y : ZMod p} (hxy : x ^ 2 - a * y ^ 2 = 0) : x = 0 ∧ y = 0 := by
have ha : (a : ZMod p) ≠ 0 := by
intro hf
rw [(eq_zero_iff p a).mpr hf] at h
simp at h
by_contra hf
rcases imp_iff_or_not.mp (not_and'.mp hf) with hx | hy
· rw [eq_one_of_sq_sub_mul_sq_eq_zero' ha hx hxy, CharZero.eq_neg_self_iff] at h
exact one_ne_zero h
· rw [eq_one_of_sq_sub_mul_sq_eq_zero ha hy hxy, CharZero.eq_neg_self_iff] at h
exact one_ne_zero h
/-- If `legendreSym p a = -1` and `p` divides `x^2 - a*y^2`, then `p` must divide `x` and `y`. -/
theorem prime_dvd_of_eq_neg_one {p : ℕ} [Fact p.Prime] {a : ℤ} (h : legendreSym p a = -1) {x y : ℤ}
(hxy : (p : ℤ) ∣ x ^ 2 - a * y ^ 2) : ↑p ∣ x ∧ ↑p ∣ y := by
simp_rw [← ZMod.intCast_zmod_eq_zero_iff_dvd] at hxy ⊢
push_cast at hxy
exact eq_zero_mod_of_eq_neg_one h hxy
end legendreSym
end QuadraticForm
section Values
/-!
### The value of the Legendre symbol at `-1`
See `jacobiSym.at_neg_one` for the corresponding statement for the Jacobi symbol.
-/
variable {p : ℕ} [Fact p.Prime]
open ZMod
/-- `legendreSym p (-1)` is given by `χ₄ p`. -/
theorem legendreSym.at_neg_one (hp : p ≠ 2) : legendreSym p (-1) = χ₄ p := by
simp only [legendreSym, card p, quadraticChar_neg_one ((ringChar_zmod_n p).substr hp),
Int.cast_neg, Int.cast_one]
namespace ZMod
/-- `-1` is a square in `ZMod p` iff `p` is not congruent to `3` mod `4`. -/
theorem exists_sq_eq_neg_one_iff : IsSquare (-1 : ZMod p) ↔ p % 4 ≠ 3 := by
rw [FiniteField.isSquare_neg_one_iff, card p]
theorem mod_four_ne_three_of_sq_eq_neg_one {y : ZMod p} (hy : y ^ 2 = -1) : p % 4 ≠ 3 :=
exists_sq_eq_neg_one_iff.1 ⟨y, hy ▸ pow_two y⟩
/-- If two nonzero squares are negatives of each other in `ZMod p`, then `p % 4 ≠ 3`. -/
theorem mod_four_ne_three_of_sq_eq_neg_sq' {x y : ZMod p} (hy : y ≠ 0) (hxy : x ^ 2 = -y ^ 2) :
p % 4 ≠ 3 :=
@mod_four_ne_three_of_sq_eq_neg_one p _ (x / y)
(by
apply_fun fun z => z / y ^ 2 at hxy
rwa [neg_div, ← div_pow, ← div_pow, div_self hy, one_pow] at hxy)
theorem mod_four_ne_three_of_sq_eq_neg_sq {x y : ZMod p} (hx : x ≠ 0) (hxy : x ^ 2 = -y ^ 2) :
p % 4 ≠ 3 :=
mod_four_ne_three_of_sq_eq_neg_sq' hx (neg_eq_iff_eq_neg.mpr hxy).symm
end ZMod
end Values |
.lake/packages/mathlib/Mathlib/NumberTheory/LegendreSymbol/AddCharacter.lean | import Mathlib.NumberTheory.Cyclotomic.PrimitiveRoots
import Mathlib.FieldTheory.Finite.Trace
import Mathlib.Algebra.Group.AddChar
import Mathlib.Data.ZMod.Units
import Mathlib.Analysis.Complex.Polynomial.Basic
/-!
# Additive characters of finite rings and fields
This file collects some results on additive characters whose domain is (the additive group of)
a finite ring or field.
## Main definitions and results
We define an additive character `ψ` to be *primitive* if `mulShift ψ a` is trivial only when
`a = 0`.
We show that when `ψ` is primitive, then the map `a ↦ mulShift ψ a` is injective
(`AddChar.to_mulShift_inj_of_isPrimitive`) and that `ψ` is primitive when `R` is a field
and `ψ` is nontrivial (`AddChar.IsNontrivial.isPrimitive`).
We also show that there are primitive additive characters on `R` (with suitable
target `R'`) when `R` is a field or `R = ZMod n` (`AddChar.primitiveCharFiniteField`
and `AddChar.primitiveZModChar`).
Finally, we show that the sum of all character values is zero when the character
is nontrivial (and the target is a domain); see `AddChar.sum_eq_zero_of_isNontrivial`.
## Tags
additive character
-/
universe u v
namespace AddChar
section Additive
-- The domain and target of our additive characters. Now we restrict to a ring in the domain.
variable {R : Type u} [CommRing R] {R' : Type v} [CommMonoid R']
/-- The values of an additive character on a ring of positive characteristic are roots of unity. -/
lemma val_mem_rootsOfUnity (φ : AddChar R R') (a : R) (h : 0 < ringChar R) :
(φ.val_isUnit a).unit ∈ rootsOfUnity (ringChar R).toPNat' R' := by
simp only [mem_rootsOfUnity', IsUnit.unit_spec, Nat.toPNat'_coe, h, ↓reduceIte,
← map_nsmul_eq_pow, nsmul_eq_mul, CharP.cast_eq_zero, zero_mul, map_zero_eq_one]
/-- An additive character is *primitive* iff all its multiplicative shifts by nonzero
elements are nontrivial. -/
def IsPrimitive (ψ : AddChar R R') : Prop := ∀ ⦃a : R⦄, a ≠ 0 → mulShift ψ a ≠ 1
/-- The composition of a primitive additive character with an injective monoid homomorphism
is also primitive. -/
lemma IsPrimitive.compMulHom_of_isPrimitive {R'' : Type*} [CommMonoid R''] {φ : AddChar R R'}
{f : R' →* R''} (hφ : φ.IsPrimitive) (hf : Function.Injective f) :
(f.compAddChar φ).IsPrimitive := fun a ha ↦ by
simpa [DFunLike.ext_iff] using (MonoidHom.compAddChar_injective_right f hf).ne (hφ ha)
/-- The map associating to `a : R` the multiplicative shift of `ψ` by `a`
is injective when `ψ` is primitive. -/
theorem to_mulShift_inj_of_isPrimitive {ψ : AddChar R R'} (hψ : IsPrimitive ψ) :
Function.Injective ψ.mulShift := by
intro a b h
apply_fun fun x => x * mulShift ψ (-b) at h
simp only [mulShift_mul, mulShift_zero, add_neg_cancel] at h
simpa [← sub_eq_add_neg, sub_eq_zero] using (hψ · h)
-- `AddCommGroup.equiv_direct_sum_zmod_of_fintype`
-- gives the structure theorem for finite abelian groups.
-- This could be used to show that the map above is a bijection.
-- We leave this for a later occasion.
/-- When `R` is a field `F`, then a nontrivial additive character is primitive -/
theorem IsPrimitive.of_ne_one {F : Type u} [Field F] {ψ : AddChar F R'} (hψ : ψ ≠ 1) :
IsPrimitive ψ :=
fun a ha h ↦ hψ <| by simpa [mulShift_mulShift, ha] using congr_arg (mulShift · a⁻¹) h
/-- If `r` is not a unit, then `e.mulShift r` is not primitive. -/
lemma not_isPrimitive_mulShift [Finite R] (e : AddChar R R') {r : R}
(hr : ¬ IsUnit r) : ¬ IsPrimitive (e.mulShift r) := by
simp only [IsPrimitive, not_forall]
simp only [isUnit_iff_mem_nonZeroDivisors_of_finite,
mem_nonZeroDivisors_iff_right, not_forall] at hr
rcases hr with ⟨x, h, h'⟩
exact ⟨x, h', by simp only [mulShift_mulShift, mul_comm r, h, mulShift_zero, not_ne_iff]⟩
/-- Definition for a primitive additive character on a finite ring `R` into a cyclotomic extension
of a field `R'`. It records which cyclotomic extension it is, the character, and the
fact that the character is primitive. -/
structure PrimitiveAddChar (R : Type u) [CommRing R] (R' : Type v) [Field R'] where
/-- The first projection from `PrimitiveAddChar`, giving the cyclotomic field. -/
n : ℕ+
/-- The second projection from `PrimitiveAddChar`, giving the character. -/
char : AddChar R (CyclotomicField n R')
/-- The third projection from `PrimitiveAddChar`, showing that `χ.char` is primitive. -/
prim : IsPrimitive char
/-!
### Additive characters on `ZMod n`
-/
section ZMod
variable {N : ℕ} [NeZero N] {R : Type*} [CommRing R] (e : AddChar (ZMod N) R)
/-- If `e` is not primitive, then `e.mulShift d = 1` for some proper divisor `d` of `N`. -/
lemma exists_divisor_of_not_isPrimitive (he : ¬e.IsPrimitive) :
∃ d : ℕ, d ∣ N ∧ d < N ∧ e.mulShift d = 1 := by
simp_rw [IsPrimitive, not_forall, not_ne_iff] at he
rcases he with ⟨b, hb_ne, hb⟩
-- We have `AddChar.mulShift e b = 1`, but `b ≠ 0`.
obtain ⟨d, hd, u, hu, rfl⟩ := b.eq_unit_mul_divisor
refine ⟨d, hd, lt_of_le_of_ne (Nat.le_of_dvd (NeZero.pos _) hd) ?_, ?_⟩
· exact fun h ↦ by simp only [h, ZMod.natCast_self, mul_zero, ne_eq, not_true_eq_false] at hb_ne
· rw [← mulShift_unit_eq_one_iff _ hu, ← hb, mul_comm]
ext1 y
rw [mulShift_apply, mulShift_apply, mulShift_apply, mul_assoc]
end ZMod
section ZModChar
variable {C : Type v} [CommMonoid C]
section ZModCharDef
/-- We can define an additive character on `ZMod n` when we have an `n`th root of unity `ζ : C`. -/
def zmodChar (n : ℕ) [NeZero n] {ζ : C} (hζ : ζ ^ n = 1) : AddChar (ZMod n) C where
toFun a := ζ ^ a.val
map_zero_eq_one' := by simp only [ZMod.val_zero, pow_zero]
map_add_eq_mul' x y := by simp only [ZMod.val_add, ← pow_eq_pow_mod _ hζ, ← pow_add]
/-- The additive character on `ZMod n` defined using `ζ` sends `a` to `ζ^a`. -/
theorem zmodChar_apply {n : ℕ} [NeZero n] {ζ : C} (hζ : ζ ^ n = 1) (a : ZMod n) :
zmodChar n hζ a = ζ ^ a.val :=
rfl
theorem zmodChar_apply' {n : ℕ} [NeZero n] {ζ : C} (hζ : ζ ^ n = 1) (a : ℕ) :
zmodChar n hζ a = ζ ^ a := by
rw [pow_eq_pow_mod a hζ, zmodChar_apply, ZMod.val_natCast]
end ZModCharDef
/-- An additive character on `ZMod n` is nontrivial iff it takes a value `≠ 1` on `1`. -/
theorem zmod_char_ne_one_iff (n : ℕ) [NeZero n] (ψ : AddChar (ZMod n) C) : ψ ≠ 1 ↔ ψ 1 ≠ 1 := by
rw [ne_one_iff]
refine ⟨?_, fun h => ⟨_, h⟩⟩
contrapose!
rintro h₁ a
have ha₁ : a = a.val • (1 : ZMod ↑n) := by
rw [nsmul_eq_mul, mul_one]; exact (ZMod.natCast_zmod_val a).symm
rw [ha₁, map_nsmul_eq_pow, h₁, one_pow]
/-- A primitive additive character on `ZMod n` takes the value `1` only at `0`. -/
theorem IsPrimitive.zmod_char_eq_one_iff (n : ℕ) [NeZero n]
{ψ : AddChar (ZMod n) C} (hψ : IsPrimitive ψ) (a : ZMod n) :
ψ a = 1 ↔ a = 0 := by
refine ⟨fun h => not_imp_comm.mp (@hψ a) ?_, fun ha => by rw [ha, map_zero_eq_one]⟩
rw [zmod_char_ne_one_iff n (mulShift ψ a), mulShift_apply, mul_one, h, Classical.not_not]
/-- The converse: if the additive character takes the value `1` only at `0`,
then it is primitive. -/
theorem zmod_char_primitive_of_eq_one_only_at_zero (n : ℕ) (ψ : AddChar (ZMod n) C)
(hψ : ∀ a, ψ a = 1 → a = 0) : IsPrimitive ψ := by
refine fun a ha hf => ?_
have h : mulShift ψ a 1 = (1 : AddChar (ZMod n) C) (1 : ZMod n) :=
congr_fun (congr_arg (↑) hf) 1
rw [mulShift_apply, mul_one] at h; norm_cast at h
exact ha (hψ a h)
/-- The additive character on `ZMod n` associated to a primitive `n`th root of unity
is primitive -/
theorem zmodChar_primitive_of_primitive_root (n : ℕ) [NeZero n] {ζ : C} (h : IsPrimitiveRoot ζ n) :
IsPrimitive (zmodChar n ((IsPrimitiveRoot.iff_def ζ n).mp h).left) := by
apply zmod_char_primitive_of_eq_one_only_at_zero
intro a ha
rw [zmodChar_apply, ← pow_zero ζ] at ha
exact (ZMod.val_eq_zero a).mp (IsPrimitiveRoot.pow_inj h (ZMod.val_lt a) (NeZero.pos _) ha)
/-- There is a primitive additive character on `ZMod n` if the characteristic of the target
does not divide `n` -/
noncomputable def primitiveZModChar (n : ℕ+) (F' : Type v) [Field F'] (h : (n : F') ≠ 0) :
PrimitiveAddChar (ZMod n) F' :=
have : NeZero (n : F') := ⟨h⟩
⟨n, zmodChar n (IsCyclotomicExtension.zeta_pow n F' _),
zmodChar_primitive_of_primitive_root n (IsCyclotomicExtension.zeta_spec n F' _)⟩
end ZModChar
end Additive
/-!
### Existence of a primitive additive character on a finite field
-/
/-- There is a primitive additive character on the finite field `F` if the characteristic
of the target is different from that of `F`.
We obtain it as the composition of the trace from `F` to `ZMod p` with a primitive
additive character on `ZMod p`, where `p` is the characteristic of `F`. -/
noncomputable def FiniteField.primitiveChar (F F' : Type*) [Field F] [Finite F] [Field F']
(h : ringChar F' ≠ ringChar F) : PrimitiveAddChar F F' := by
let p := ringChar F
haveI hp : Fact p.Prime := ⟨CharP.char_is_prime F _⟩
let pp := p.toPNat hp.1.pos
have hp₂ : ¬ringChar F' ∣ p := by
rcases CharP.char_is_prime_or_zero F' (ringChar F') with hq | hq
· exact mt (Nat.Prime.dvd_iff_eq hp.1 (Nat.Prime.ne_one hq)).mp h.symm
· rw [hq]
exact fun hf => Nat.Prime.ne_zero hp.1 (zero_dvd_iff.mp hf)
let ψ := primitiveZModChar pp F' (neZero_iff.mp (NeZero.of_not_dvd F' hp₂))
letI : Algebra (ZMod p) F := ZMod.algebra _ _
let ψ' := ψ.char.compAddMonoidHom (Algebra.trace (ZMod p) F).toAddMonoidHom
have hψ' : ψ' ≠ 1 := by
obtain ⟨a, ha⟩ := FiniteField.trace_to_zmod_nondegenerate F one_ne_zero
rw [one_mul] at ha
exact ne_one_iff.2
⟨a, fun hf => ha <| (ψ.prim.zmod_char_eq_one_iff pp <| Algebra.trace (ZMod p) F a).mp hf⟩
exact ⟨ψ.n, ψ', IsPrimitive.of_ne_one hψ'⟩
/-!
### The sum of all character values
-/
section sum
variable {R : Type*} [AddGroup R] [Fintype R] {R' : Type*} [CommRing R']
/-- The sum over the values of a nontrivial additive character vanishes if the target ring
is a domain. -/
theorem sum_eq_zero_of_ne_one [IsDomain R'] {ψ : AddChar R R'} (hψ : ψ ≠ 1) : ∑ a, ψ a = 0 := by
rcases ne_one_iff.1 hψ with ⟨b, hb⟩
have h₁ : ∑ a : R, ψ (b + a) = ∑ a : R, ψ a :=
Fintype.sum_bijective _ (AddGroup.addLeft_bijective b) _ _ fun x => rfl
simp_rw [map_add_eq_mul] at h₁
have h₂ : ∑ a : R, ψ a = Finset.univ.sum ↑ψ := rfl
rw [← Finset.mul_sum, h₂] at h₁
exact eq_zero_of_mul_eq_self_left hb h₁
/-- The sum over the values of the trivial additive character is the cardinality of the source. -/
theorem sum_eq_card_of_eq_one {ψ : AddChar R R'} (hψ : ψ = 1) :
∑ a, ψ a = Fintype.card R := by simp [hψ]
end sum
/-- The sum over the values of `mulShift ψ b` for `ψ` primitive is zero when `b ≠ 0`
and `#R` otherwise. -/
theorem sum_mulShift {R : Type*} [CommRing R] [Fintype R] [DecidableEq R]
{R' : Type*} [CommRing R'] [IsDomain R'] {ψ : AddChar R R'} (b : R)
(hψ : IsPrimitive ψ) : ∑ x : R, ψ (x * b) = if b = 0 then Fintype.card R else 0 := by
split_ifs with h
· -- case `b = 0`
simp only [h, mul_zero, map_zero_eq_one, Finset.sum_const, Nat.smul_one_eq_cast]
rfl
· -- case `b ≠ 0`
simp_rw [mul_comm]
exact mod_cast sum_eq_zero_of_ne_one (hψ h)
/-!
### Complex-valued additive characters
-/
section Ring
variable {R : Type*} [CommRing R]
/-- Post-composing an additive character to `ℂ` with complex conjugation gives the inverse
character. -/
lemma starComp_eq_inv (hR : 0 < ringChar R) {φ : AddChar R ℂ} :
(starRingEnd ℂ).compAddChar φ = φ⁻¹ := by
ext1 a
simp only [RingHom.toMonoidHom_eq_coe, MonoidHom.coe_compAddChar, MonoidHom.coe_coe,
Function.comp_apply, inv_apply']
have H := Complex.norm_eq_one_of_mem_rootsOfUnity <| φ.val_mem_rootsOfUnity a hR
exact (Complex.inv_eq_conj H).symm
lemma starComp_apply (hR : 0 < ringChar R) {φ : AddChar R ℂ} (a : R) :
(starRingEnd ℂ) (φ a) = φ⁻¹ a := by
rw [← starComp_eq_inv hR]
rfl
end Ring
section Field
variable (F : Type*) [Field F] [Finite F]
private lemma ringChar_ne : ringChar ℂ ≠ ringChar F := by
simpa only [ringChar.eq_zero] using (CharP.ringChar_ne_zero_of_finite F).symm
/-- A primitive additive character on the finite field `F` with values in `ℂ`. -/
noncomputable def FiniteField.primitiveChar_to_Complex : AddChar F ℂ := by
letI ch := primitiveChar F ℂ <| ringChar_ne F
refine MonoidHom.compAddChar ?_ ch.char
exact (IsCyclotomicExtension.algEquiv {(ch.n : ℕ)} ℂ (CyclotomicField ch.n ℂ) ℂ).toMonoidHom
lemma FiniteField.primitiveChar_to_Complex_isPrimitive :
(primitiveChar_to_Complex F).IsPrimitive := by
refine IsPrimitive.compMulHom_of_isPrimitive (PrimitiveAddChar.prim _) ?_
let nn := (primitiveChar F ℂ <| ringChar_ne F).n
exact (IsCyclotomicExtension.algEquiv {(nn : ℕ)} ℂ (CyclotomicField nn ℂ) ℂ).injective
end Field
end AddChar |
.lake/packages/mathlib/Mathlib/NumberTheory/LegendreSymbol/QuadraticReciprocity.lean | import Mathlib.NumberTheory.LegendreSymbol.Basic
import Mathlib.NumberTheory.LegendreSymbol.QuadraticChar.GaussSum
/-!
# Quadratic reciprocity.
## Main results
We prove the law of quadratic reciprocity, see `legendreSym.quadratic_reciprocity` and
`legendreSym.quadratic_reciprocity'`, as well as the
interpretations in terms of existence of square roots depending on the congruence mod 4,
`ZMod.exists_sq_eq_prime_iff_of_mod_four_eq_one` and
`ZMod.exists_sq_eq_prime_iff_of_mod_four_eq_three`.
We also prove the supplementary laws that give conditions for when `2` or `-2`
is a square modulo a prime `p`:
`legendreSym.at_two` and `ZMod.exists_sq_eq_two_iff` for `2` and
`legendreSym.at_neg_two` and `ZMod.exists_sq_eq_neg_two_iff` for `-2`.
## Implementation notes
The proofs use results for quadratic characters on arbitrary finite fields
from `NumberTheory.LegendreSymbol.QuadraticChar.GaussSum`, which in turn are based on
properties of quadratic Gauss sums as provided by `NumberTheory.LegendreSymbol.GaussSum`.
## Tags
quadratic residue, quadratic nonresidue, Legendre symbol, quadratic reciprocity
-/
open Nat
section Values
variable {p : ℕ} [Fact p.Prime]
open ZMod
/-!
### The value of the Legendre symbol at `2` and `-2`
See `jacobiSym.at_two` and `jacobiSym.at_neg_two` for the corresponding statements
for the Jacobi symbol.
-/
namespace legendreSym
/-- `legendreSym p 2` is given by `χ₈ p`. -/
theorem at_two (hp : p ≠ 2) : legendreSym p 2 = χ₈ p := by
have : (2 : ZMod p) = (2 : ℤ) := by norm_cast
rw [legendreSym, ← this, quadraticChar_two ((ringChar_zmod_n p).substr hp), card p]
/-- `legendreSym p (-2)` is given by `χ₈' p`. -/
theorem at_neg_two (hp : p ≠ 2) : legendreSym p (-2) = χ₈' p := by
have : (-2 : ZMod p) = (-2 : ℤ) := by norm_cast
rw [legendreSym, ← this, quadraticChar_neg_two ((ringChar_zmod_n p).substr hp), card p]
end legendreSym
namespace ZMod
/-- `2` is a square modulo an odd prime `p` iff `p` is congruent to `1` or `7` mod `8`. -/
theorem exists_sq_eq_two_iff (hp : p ≠ 2) : IsSquare (2 : ZMod p) ↔ p % 8 = 1 ∨ p % 8 = 7 := by
rw [FiniteField.isSquare_two_iff, card p]
have h₁ := (Prime.mod_two_eq_one_iff_ne_two Fact.out).mpr hp
cutsat
/-- `-2` is a square modulo an odd prime `p` iff `p` is congruent to `1` or `3` mod `8`. -/
theorem exists_sq_eq_neg_two_iff (hp : p ≠ 2) : IsSquare (-2 : ZMod p) ↔ p % 8 = 1 ∨ p % 8 = 3 := by
rw [FiniteField.isSquare_neg_two_iff, card p]
have h₁ := (Prime.mod_two_eq_one_iff_ne_two Fact.out).mpr hp
cutsat
end ZMod
end Values
section Reciprocity
/-!
### The Law of Quadratic Reciprocity
See `jacobiSym.quadratic_reciprocity` and variants for a version of Quadratic Reciprocity
for the Jacobi symbol.
-/
variable {p q : ℕ} [Fact p.Prime] [Fact q.Prime]
namespace legendreSym
open ZMod
/-- **The Law of Quadratic Reciprocity**: if `p` and `q` are distinct odd primes, then
`(q / p) * (p / q) = (-1)^((p-1)(q-1)/4)`. -/
theorem quadratic_reciprocity (hp : p ≠ 2) (hq : q ≠ 2) (hpq : p ≠ q) :
legendreSym q p * legendreSym p q = (-1) ^ (p / 2 * (q / 2)) := by
have hp₁ := (Prime.eq_two_or_odd <| @Fact.out p.Prime _).resolve_left hp
have hq₁ := (Prime.eq_two_or_odd <| @Fact.out q.Prime _).resolve_left hq
have hq₂ : ringChar (ZMod q) ≠ 2 := (ringChar_zmod_n q).substr hq
have h :=
quadraticChar_odd_prime ((ringChar_zmod_n p).substr hp) hq ((ringChar_zmod_n p).substr hpq)
rw [card p] at h
have nc : ∀ n r : ℕ, ((n : ℤ) : ZMod r) = n := fun n r => by norm_cast
have nc' : (((-1) ^ (p / 2) : ℤ) : ZMod q) = (-1) ^ (p / 2) := by norm_cast
rw [legendreSym, legendreSym, nc, nc, h, map_mul, mul_rotate', mul_comm (p / 2), ← pow_two,
quadraticChar_sq_one (prime_ne_zero q p hpq.symm), mul_one, pow_mul, χ₄_eq_neg_one_pow hp₁, nc',
map_pow, quadraticChar_neg_one hq₂, card q, χ₄_eq_neg_one_pow hq₁]
/-- The Law of Quadratic Reciprocity: if `p` and `q` are odd primes, then
`(q / p) = (-1)^((p-1)(q-1)/4) * (p / q)`. -/
theorem quadratic_reciprocity' (hp : p ≠ 2) (hq : q ≠ 2) :
legendreSym q p = (-1) ^ (p / 2 * (q / 2)) * legendreSym p q := by
rcases eq_or_ne p q with h | h
· subst p
rw [(eq_zero_iff q q).mpr (mod_cast natCast_self q), mul_zero]
· have qr := congr_arg (· * legendreSym p q) (quadratic_reciprocity hp hq h)
have : ((q : ℤ) : ZMod p) ≠ 0 := mod_cast prime_ne_zero p q h
simpa only [mul_assoc, ← pow_two, sq_one p this, mul_one] using qr
/-- The Law of Quadratic Reciprocity: if `p` and `q` are odd primes and `p % 4 = 1`,
then `(q / p) = (p / q)`. -/
theorem quadratic_reciprocity_one_mod_four (hp : p % 4 = 1) (hq : q ≠ 2) :
legendreSym q p = legendreSym p q := by
rw [quadratic_reciprocity'
((Prime.mod_two_eq_one_iff_ne_two Fact.out).mp (odd_of_mod_four_eq_one hp)) hq,
pow_mul, neg_one_pow_div_two_of_one_mod_four hp, one_pow, one_mul]
/-- The Law of Quadratic Reciprocity: if `p` and `q` are primes that are both congruent
to `3` mod `4`, then `(q / p) = -(p / q)`. -/
theorem quadratic_reciprocity_three_mod_four (hp : p % 4 = 3) (hq : q % 4 = 3) :
legendreSym q p = -legendreSym p q := by
let nop := @neg_one_pow_div_two_of_three_mod_four
rw [quadratic_reciprocity', pow_mul, nop hp, nop hq, neg_one_mul] <;>
rwa [← Prime.mod_two_eq_one_iff_ne_two Fact.out, odd_of_mod_four_eq_three]
end legendreSym
namespace ZMod
open legendreSym
/-- If `p` and `q` are odd primes and `p % 4 = 1`, then `q` is a square mod `p` iff
`p` is a square mod `q`. -/
theorem exists_sq_eq_prime_iff_of_mod_four_eq_one (hp1 : p % 4 = 1) (hq1 : q ≠ 2) :
IsSquare (q : ZMod p) ↔ IsSquare (p : ZMod q) := by
rcases eq_or_ne p q with h | h
· subst p; rfl
· rw [← eq_one_iff' p (prime_ne_zero p q h), ← eq_one_iff' q (prime_ne_zero q p h.symm),
quadratic_reciprocity_one_mod_four hp1 hq1]
/-- If `p` and `q` are distinct primes that are both congruent to `3` mod `4`, then `q` is
a square mod `p` iff `p` is a nonsquare mod `q`. -/
theorem exists_sq_eq_prime_iff_of_mod_four_eq_three (hp3 : p % 4 = 3) (hq3 : q % 4 = 3)
(hpq : p ≠ q) : IsSquare (q : ZMod p) ↔ ¬IsSquare (p : ZMod q) := by
rw [← eq_one_iff' p (prime_ne_zero p q hpq), ← eq_neg_one_iff' q,
quadratic_reciprocity_three_mod_four hp3 hq3, neg_inj]
end ZMod
end Reciprocity |
.lake/packages/mathlib/Mathlib/NumberTheory/LegendreSymbol/GaussEisensteinLemmas.lean | import Mathlib.Data.Nat.Prime.Factorial
import Mathlib.NumberTheory.LegendreSymbol.Basic
/-!
# Lemmas of Gauss and Eisenstein
This file contains the Lemmas of Gauss and Eisenstein on the Legendre symbol.
The main results are `ZMod.gauss_lemma` and `ZMod.eisenstein_lemma`.
-/
open Finset Nat
open scoped Nat
section GaussEisenstein
namespace ZMod
/-- The image of the map sending a nonzero natural number `x ≤ p / 2` to the absolute value
of the integer in `(-p/2, p/2]` that is congruent to `a * x mod p` is the set
of nonzero natural numbers `x` such that `x ≤ p / 2`. -/
theorem Ico_map_valMinAbs_natAbs_eq_Ico_map_id (p : ℕ) [hp : Fact p.Prime] (a : ZMod p)
(hap : a ≠ 0) : ((Ico 1 (p / 2).succ).1.map fun (x : ℕ) => (a * x).valMinAbs.natAbs) =
(Ico 1 (p / 2).succ).1.map fun a => a := by
have he : ∀ {x}, x ∈ Ico 1 (p / 2).succ → x ≠ 0 ∧ x ≤ p / 2 := by
simp +contextual [Nat.lt_succ_iff, Nat.succ_le_iff, pos_iff_ne_zero]
have hep : ∀ {x}, x ∈ Ico 1 (p / 2).succ → x < p := fun hx =>
lt_of_le_of_lt (he hx).2 (Nat.div_lt_self hp.1.pos (by decide))
have hpe : ∀ {x}, x ∈ Ico 1 (p / 2).succ → ¬p ∣ x := fun hx hpx =>
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero (he hx).1) hpx) (hep hx)
have hmem : ∀ (x : ℕ) (_ : x ∈ Ico 1 (p / 2).succ),
(a * x : ZMod p).valMinAbs.natAbs ∈ Ico 1 (p / 2).succ := by
intro x hx
simp [hap, CharP.cast_eq_zero_iff (ZMod p) p, hpe hx, Nat.lt_succ_iff, succ_le_iff,
pos_iff_ne_zero, natAbs_valMinAbs_le _]
have hsurj : ∀ (b : ℕ) (hb : b ∈ Ico 1 (p / 2).succ),
∃ x, ∃ _ : x ∈ Ico 1 (p / 2).succ, (a * x : ZMod p).valMinAbs.natAbs = b := by
intro b hb
refine ⟨(b / a : ZMod p).valMinAbs.natAbs, mem_Ico.mpr ⟨?_, ?_⟩, ?_⟩
· apply Nat.pos_of_ne_zero
simp only [div_eq_mul_inv, hap, CharP.cast_eq_zero_iff (ZMod p) p, hpe hb, not_false_iff,
valMinAbs_eq_zero, inv_eq_zero, Int.natAbs_eq_zero, Ne, _root_.mul_eq_zero, or_self_iff]
· apply lt_succ_of_le; apply natAbs_valMinAbs_le
· rw [natCast_natAbs_valMinAbs]
split_ifs
· rw [mul_div_cancel₀ _ hap, valMinAbs_def_pos, val_cast_of_lt (hep hb),
if_pos (le_of_lt_succ (mem_Ico.1 hb).2), Int.natAbs_natCast]
· rw [mul_neg, mul_div_cancel₀ _ hap, natAbs_valMinAbs_neg, valMinAbs_def_pos,
val_cast_of_lt (hep hb), if_pos (le_of_lt_succ (mem_Ico.1 hb).2), Int.natAbs_natCast]
exact Multiset.map_eq_map_of_bij_of_nodup _ _ (Finset.nodup _) (Finset.nodup _)
(fun x _ => (a * x : ZMod p).valMinAbs.natAbs) hmem
(inj_on_of_surj_on_of_card_le _ hmem hsurj le_rfl) hsurj (fun _ _ => rfl)
private theorem gauss_lemma_aux₁ (p : ℕ) [Fact p.Prime] {a : ℤ} (hap : (a : ZMod p) ≠ 0) :
(a ^ (p / 2) * (p / 2)! : ZMod p) =
(-1 : ZMod p) ^ #{x ∈ Ico 1 (p / 2).succ | ¬ (a * x.cast : ZMod p).val ≤ p / 2} * (p / 2)! :=
calc
(a ^ (p / 2) * (p / 2)! : ZMod p) = ∏ x ∈ Ico 1 (p / 2).succ, a * x := by
rw [prod_mul_distrib, ← prod_natCast, prod_Ico_id_eq_factorial, prod_const, card_Ico,
Nat.add_one_sub_one]; simp
_ = ∏ x ∈ Ico 1 (p / 2).succ, ↑((a * x : ZMod p).val) := by simp
_ = ∏ x ∈ Ico 1 (p / 2).succ, (if (a * x : ZMod p).val ≤ p / 2 then (1 : ZMod p) else -1) *
(a * x : ZMod p).valMinAbs.natAbs :=
(prod_congr rfl fun _ _ => by
simp only [natCast_natAbs_valMinAbs]
split_ifs <;> simp)
_ = (-1 : ZMod p) ^ #{x ∈ Ico 1 (p / 2).succ | ¬(a * x.cast : ZMod p).val ≤ p / 2} *
∏ x ∈ Ico 1 (p / 2).succ, ↑((a * x : ZMod p).valMinAbs.natAbs) := by
have :
(∏ x ∈ Ico 1 (p / 2).succ, if (a * x : ZMod p).val ≤ p / 2 then (1 : ZMod p) else -1) =
∏ x ∈ Ico 1 (p / 2).succ with ¬(a * x.cast : ZMod p).val ≤ p / 2, -1 :=
prod_bij_ne_one (fun x _ _ => x)
(fun x => by split_ifs <;> (dsimp; simp_all))
(fun _ _ _ _ _ _ => id) (fun b h _ => ⟨b, by simp_all [-not_le]⟩)
(by intros; split_ifs at * <;> simp_all)
rw [prod_mul_distrib, this, prod_const]
_ = (-1 : ZMod p) ^ #{x ∈ Ico 1 (p / 2).succ | ¬(a * x.cast : ZMod p).val ≤ p / 2} *
(p / 2)! := by
rw [← prod_natCast, Finset.prod_eq_multiset_prod,
Ico_map_valMinAbs_natAbs_eq_Ico_map_id p a hap, ← Finset.prod_eq_multiset_prod,
prod_Ico_id_eq_factorial]
theorem gauss_lemma_aux (p : ℕ) [hp : Fact p.Prime] {a : ℤ} (hap : (a : ZMod p) ≠ 0) :
(a ^ (p / 2) : ZMod p) =
((-1) ^ #{x ∈ Ico 1 (p / 2).succ | p / 2 < (a * x.cast : ZMod p).val} :) :=
(mul_left_inj' (show ((p / 2)! : ZMod p) ≠ 0 by
rw [Ne, CharP.cast_eq_zero_iff (ZMod p) p, hp.1.dvd_factorial, not_le]
exact Nat.div_lt_self hp.1.pos (by decide))).1 <| by
simpa using gauss_lemma_aux₁ p hap
/-- **Gauss' lemma**. The Legendre symbol can be computed by considering the number of naturals less
than `p/2` such that `(a * x) % p > p / 2`. -/
theorem gauss_lemma {p : ℕ} [h : Fact p.Prime] {a : ℤ} (hp : p ≠ 2) (ha0 : (a : ZMod p) ≠ 0) :
legendreSym p a = (-1) ^ #{x ∈ Ico 1 (p / 2).succ | p / 2 < (a * x.cast : ZMod p).val} := by
replace hp : Odd p := h.out.odd_of_ne_two hp
have : (legendreSym p a : ZMod p) =
(((-1) ^ #{x ∈ Ico 1 (p / 2).succ | p / 2 < (a * x.cast : ZMod p).val} : ℤ) : ZMod p) := by
rw [legendreSym.eq_pow, gauss_lemma_aux p ha0]
cases legendreSym.eq_one_or_neg_one p ha0 <;>
cases neg_one_pow_eq_or ℤ #{x ∈ Ico 1 (p / 2).succ | p / 2 < (a * x.cast : ZMod p).val} <;>
simp_all [ne_neg_self hp one_ne_zero, (ne_neg_self hp one_ne_zero).symm]
private theorem eisenstein_lemma_aux₁ (p : ℕ) [Fact p.Prime] [hp2 : Fact (p % 2 = 1)] {a : ℕ}
(hap : (a : ZMod p) ≠ 0) :
((∑ x ∈ Ico 1 (p / 2).succ, a * x : ℕ) : ZMod 2) =
#{x ∈ Ico 1 (p / 2).succ | p / 2 < (a * x.cast : ZMod p).val} +
∑ x ∈ Ico 1 (p / 2).succ, x + (∑ x ∈ Ico 1 (p / 2).succ, a * x / p : ℕ) :=
have hp2 : (p : ZMod 2) = (1 : ℕ) := (natCast_eq_natCast_iff _ _ _).2 hp2.1
calc
((∑ x ∈ Ico 1 (p / 2).succ, a * x : ℕ) : ZMod 2) =
((∑ x ∈ Ico 1 (p / 2).succ, (a * x % p + p * (a * x / p)) : ℕ) : ZMod 2) := by
simp only [mod_add_div]
_ = (∑ x ∈ Ico 1 (p / 2).succ, ((a * x : ℕ) : ZMod p).val : ℕ) +
(∑ x ∈ Ico 1 (p / 2).succ, a * x / p : ℕ) := by
simp only [val_natCast]
simp [sum_add_distrib, ← mul_sum, Nat.cast_add, Nat.cast_mul, Nat.cast_sum, hp2]
_ = _ :=
congr_arg (· + _) <|
calc
((∑ x ∈ Ico 1 (p / 2).succ, ((a * x : ℕ) : ZMod p).val : ℕ) : ZMod 2) =
∑ x ∈ Ico 1 (p / 2).succ, (((a * x : ZMod p).valMinAbs +
if (a * x : ZMod p).val ≤ p / 2 then 0 else p : ℤ) : ZMod 2) := by
simp only [(val_eq_ite_valMinAbs _).symm]; simp [Nat.cast_sum]
_ = #{x ∈ Ico 1 (p / 2).succ | p / 2 < (a * x.cast : ZMod p).val} +
(∑ x ∈ Ico 1 (p / 2).succ, (a * x.cast : ZMod p).valMinAbs.natAbs : ℕ) := by
simp [add_comm, sum_add_distrib, Finset.sum_ite, hp2, Nat.cast_sum]
_ = _ := by
rw [Finset.sum_eq_multiset_sum, Ico_map_valMinAbs_natAbs_eq_Ico_map_id p a hap, ←
Finset.sum_eq_multiset_sum]
theorem eisenstein_lemma_aux (p : ℕ) [Fact p.Prime] [Fact (p % 2 = 1)] {a : ℕ} (ha2 : a % 2 = 1)
(hap : (a : ZMod p) ≠ 0) :
#{x ∈ Ico 1 (p / 2).succ | p / 2 < (a * x.cast : ZMod p).val} ≡
∑ x ∈ Ico 1 (p / 2).succ, x * a / p [MOD 2] :=
have ha2 : (a : ZMod 2) = (1 : ℕ) := (natCast_eq_natCast_iff _ _ _).2 ha2
(natCast_eq_natCast_iff _ _ 2).1 <| sub_eq_zero.1 <| by
simpa [add_left_comm, sub_eq_add_neg, ← mul_sum, mul_comm, ha2, Nat.cast_sum,
add_neg_eq_iff_eq_add.symm, add_assoc] using
Eq.symm (eisenstein_lemma_aux₁ p hap)
theorem div_eq_filter_card {a b c : ℕ} (hb0 : 0 < b) (hc : a / b ≤ c) :
a / b = #{x ∈ Ico 1 c.succ | x * b ≤ a} :=
calc
a / b = #(Ico 1 (a / b).succ) := by simp
_ = #{x ∈ Ico 1 c.succ | x * b ≤ a} :=
congr_arg _ <| Finset.ext fun x => by
have : x * b ≤ a → x ≤ c := fun h => le_trans (by rwa [le_div_iff_mul_le hb0]) hc
simp [Nat.lt_succ_iff, le_div_iff_mul_le hb0]; tauto
/-- The given sum is the number of integer points in the triangle formed by the diagonal of the
rectangle `(0, p/2) × (0, q/2)`. -/
private theorem sum_Ico_eq_card_lt {p q : ℕ} :
∑ a ∈ Ico 1 (p / 2).succ, a * q / p =
#{x ∈ Ico 1 (p / 2).succ ×ˢ Ico 1 (q / 2).succ | x.2 * p ≤ x.1 * q} :=
if hp0 : p = 0 then by simp [hp0]
else
calc
∑ a ∈ Ico 1 (p / 2).succ, a * q / p =
∑ a ∈ Ico 1 (p / 2).succ, #{x ∈ Ico 1 (q / 2).succ | x * p ≤ a * q} :=
Finset.sum_congr rfl fun x hx => div_eq_filter_card (Nat.pos_of_ne_zero hp0) <|
calc
x * q / p ≤ p / 2 * q / p := by have := le_of_lt_succ (mem_Ico.mp hx).2; gcongr
_ ≤ _ := Nat.div_mul_div_le_div _ _ _
_ = _ := by simp only [card_eq_sum_ones, sum_filter, sum_product]
/-- Each of the sums in this lemma is the cardinality of the set of integer points in each of the
two triangles formed by the diagonal of the rectangle `(0, p/2) × (0, q/2)`. Adding them
gives the number of points in the rectangle. -/
theorem sum_mul_div_add_sum_mul_div_eq_mul (p q : ℕ) [hp : Fact p.Prime] (hq0 : (q : ZMod p) ≠ 0) :
∑ a ∈ Ico 1 (p / 2).succ, a * q / p + ∑ a ∈ Ico 1 (q / 2).succ, a * p / q =
p / 2 * (q / 2) := by
have hswap :
#{x ∈ Ico 1 (q / 2).succ ×ˢ Ico 1 (p / 2).succ | x.2 * q ≤ x.1 * p} =
#{x ∈ Ico 1 (p / 2).succ ×ˢ Ico 1 (q / 2).succ | x.1 * q ≤ x.2 * p} :=
card_equiv (Equiv.prodComm _ _)
(fun ⟨_, _⟩ => by
simp +contextual only [mem_filter, Prod.swap_prod_mk,
mem_product, Equiv.prodComm_apply, and_assoc, and_left_comm])
have hdisj :
Disjoint {x ∈ Ico 1 (p / 2).succ ×ˢ Ico 1 (q / 2).succ | x.2 * p ≤ x.1 * q}
{x ∈ Ico 1 (p / 2).succ ×ˢ Ico 1 (q / 2).succ | x.1 * q ≤ x.2 * p} := by
apply disjoint_filter.2 fun x hx hpq hqp => ?_
have hxp : x.1 < p := lt_of_le_of_lt
(show x.1 ≤ p / 2 by simp_all only [Nat.lt_succ_iff, mem_Ico, mem_product])
(Nat.div_lt_self hp.1.pos (by decide))
have : (x.1 : ZMod p) = 0 := by
simpa [hq0] using congr_arg ((↑) : ℕ → ZMod p) (le_antisymm hpq hqp)
apply_fun ZMod.val at this
rw [val_cast_of_lt hxp, val_zero] at this
simp only [this, nonpos_iff_eq_zero, mem_Ico, one_ne_zero, false_and, mem_product] at hx
have hunion :
{x ∈ Ico 1 (p / 2).succ ×ˢ Ico 1 (q / 2).succ | x.2 * p ≤ x.1 * q} ∪
{x ∈ Ico 1 (p / 2).succ ×ˢ Ico 1 (q / 2).succ | x.1 * q ≤ x.2 * p} =
Ico 1 (p / 2).succ ×ˢ Ico 1 (q / 2).succ :=
Finset.ext fun x => by
have := le_total (x.2 * p) (x.1 * q)
simp only [mem_union, mem_filter, mem_Ico, mem_product]
tauto
rw [sum_Ico_eq_card_lt, sum_Ico_eq_card_lt, hswap, ← card_union_of_disjoint hdisj, hunion,
card_product]
simp only [card_Ico, tsub_zero, succ_sub_succ_eq_sub]
/-- **Eisenstein's lemma** -/
theorem eisenstein_lemma {p : ℕ} [Fact p.Prime] (hp : p ≠ 2) {a : ℕ} (ha1 : a % 2 = 1)
(ha0 : (a : ZMod p) ≠ 0) : legendreSym p a = (-1) ^ ∑ x ∈ Ico 1 (p / 2).succ, x * a / p := by
haveI hp' : Fact (p % 2 = 1) := ⟨(Nat.Prime.mod_two_eq_one_iff_ne_two Fact.out).mpr hp⟩
have ha0' : ((a : ℤ) : ZMod p) ≠ 0 := by norm_cast
rw [neg_one_pow_eq_pow_mod_two, gauss_lemma hp ha0', neg_one_pow_eq_pow_mod_two,
(by norm_cast : ((a : ℤ) : ZMod p) = (a : ZMod p)),
show _ = _ from eisenstein_lemma_aux p ha1 ha0]
end ZMod
end GaussEisenstein |
.lake/packages/mathlib/Mathlib/NumberTheory/LegendreSymbol/ZModChar.lean | import Mathlib.Data.Int.Range
import Mathlib.Data.ZMod.Basic
import Mathlib.NumberTheory.MulChar.Basic
/-!
# Quadratic characters on ℤ/nℤ
This file defines some quadratic characters on the rings ℤ/4ℤ and ℤ/8ℤ.
We set them up to be of type `MulChar (ZMod n) ℤ`, where `n` is `4` or `8`.
## Tags
quadratic character, zmod
-/
/-!
### Quadratic characters mod 4 and 8
We define the primitive quadratic characters `χ₄`on `ZMod 4`
and `χ₈`, `χ₈'` on `ZMod 8`.
-/
namespace ZMod
section QuadCharModP
/-- Define the nontrivial quadratic character on `ZMod 4`, `χ₄`.
It corresponds to the extension `ℚ(√-1)/ℚ`. -/
@[simps]
def χ₄ : MulChar (ZMod 4) ℤ where
toFun a :=
match a with
| 0 | 2 => 0
| 1 => 1
| 3 => -1
map_one' := rfl
map_mul' := by decide
map_nonunit' := by decide
/-- `χ₄` takes values in `{0, 1, -1}` -/
theorem isQuadratic_χ₄ : χ₄.IsQuadratic := by
unfold MulChar.IsQuadratic
decide
/-- The value of `χ₄ n`, for `n : ℕ`, depends only on `n % 4`. -/
theorem χ₄_nat_mod_four (n : ℕ) : χ₄ n = χ₄ (n % 4 : ℕ) := by
rw [← ZMod.natCast_mod n 4]
/-- The value of `χ₄ n`, for `n : ℤ`, depends only on `n % 4`. -/
theorem χ₄_int_mod_four (n : ℤ) : χ₄ n = χ₄ (n % 4 : ℤ) := by
rw [← ZMod.intCast_mod n 4, Nat.cast_ofNat]
/-- An explicit description of `χ₄` on integers / naturals -/
theorem χ₄_int_eq_if_mod_four (n : ℤ) :
χ₄ n = if n % 2 = 0 then 0 else if n % 4 = 1 then 1 else -1 := by
have help : ∀ m : ℤ, 0 ≤ m → m < 4 → χ₄ m = if m % 2 = 0 then 0 else if m = 1 then 1 else -1 := by
decide
rw [← Int.emod_emod_of_dvd n (by cutsat : (2 : ℤ) ∣ 4), ← ZMod.intCast_mod n 4]
exact help (n % 4) (Int.emod_nonneg n (by cutsat)) (Int.emod_lt_abs n (by cutsat))
theorem χ₄_nat_eq_if_mod_four (n : ℕ) :
χ₄ n = if n % 2 = 0 then 0 else if n % 4 = 1 then 1 else -1 :=
mod_cast χ₄_int_eq_if_mod_four n
/-- Alternative description of `χ₄ n` for odd `n : ℕ` in terms of powers of `-1` -/
theorem χ₄_eq_neg_one_pow {n : ℕ} (hn : n % 2 = 1) : χ₄ n = (-1) ^ (n / 2) := by
rw [χ₄_nat_eq_if_mod_four]
simp only [hn, Nat.one_ne_zero, if_false]
nth_rewrite 3 [← Nat.div_add_mod n 4]
nth_rewrite 3 [show 4 = 2 * 2 by cutsat]
rw [mul_assoc, add_comm, Nat.add_mul_div_left _ _ zero_lt_two, pow_add, pow_mul,
neg_one_sq, one_pow, mul_one]
have help : ∀ m : ℕ, m < 4 → m % 2 = 1 → ite (m = 1) (1 : ℤ) (-1) = (-1) ^ (m / 2) := by decide
exact help _ (Nat.mod_lt n (by cutsat)) <| (Nat.mod_mod_of_dvd n (by cutsat : 2 ∣ 4)).trans hn
/-- If `n % 4 = 1`, then `χ₄ n = 1`. -/
theorem χ₄_nat_one_mod_four {n : ℕ} (hn : n % 4 = 1) : χ₄ n = 1 := by
rw [χ₄_nat_mod_four, hn]
rfl
/-- If `n % 4 = 3`, then `χ₄ n = -1`. -/
theorem χ₄_nat_three_mod_four {n : ℕ} (hn : n % 4 = 3) : χ₄ n = -1 := by
rw [χ₄_nat_mod_four, hn]
rfl
/-- If `n % 4 = 1`, then `χ₄ n = 1`. -/
theorem χ₄_int_one_mod_four {n : ℤ} (hn : n % 4 = 1) : χ₄ n = 1 := by
rw [χ₄_int_mod_four, hn]
rfl
/-- If `n % 4 = 3`, then `χ₄ n = -1`. -/
theorem χ₄_int_three_mod_four {n : ℤ} (hn : n % 4 = 3) : χ₄ n = -1 := by
rw [χ₄_int_mod_four, hn]
rfl
/-- If `n % 4 = 1`, then `(-1)^(n/2) = 1`. -/
theorem neg_one_pow_div_two_of_one_mod_four {n : ℕ} (hn : n % 4 = 1) : (-1 : ℤ) ^ (n / 2) = 1 :=
χ₄_eq_neg_one_pow (Nat.odd_of_mod_four_eq_one hn) ▸ χ₄_nat_one_mod_four hn
/-- If `n % 4 = 3`, then `(-1)^(n/2) = -1`. -/
theorem neg_one_pow_div_two_of_three_mod_four {n : ℕ} (hn : n % 4 = 3) : (-1 : ℤ) ^ (n / 2) = -1 :=
χ₄_eq_neg_one_pow (Nat.odd_of_mod_four_eq_three hn) ▸ χ₄_nat_three_mod_four hn
/-- Define the first primitive quadratic character on `ZMod 8`, `χ₈`.
It corresponds to the extension `ℚ(√2)/ℚ`. -/
@[simps]
def χ₈ : MulChar (ZMod 8) ℤ where
toFun a :=
match a with
| 0 | 2 | 4 | 6 => 0
| 1 | 7 => 1
| 3 | 5 => -1
map_one' := rfl
map_mul' := by decide
map_nonunit' := by decide
/-- `χ₈` takes values in `{0, 1, -1}` -/
theorem isQuadratic_χ₈ : χ₈.IsQuadratic := by
unfold MulChar.IsQuadratic
decide
/-- The value of `χ₈ n`, for `n : ℕ`, depends only on `n % 8`. -/
theorem χ₈_nat_mod_eight (n : ℕ) : χ₈ n = χ₈ (n % 8 : ℕ) := by
rw [← ZMod.natCast_mod n 8]
/-- The value of `χ₈ n`, for `n : ℤ`, depends only on `n % 8`. -/
theorem χ₈_int_mod_eight (n : ℤ) : χ₈ n = χ₈ (n % 8 : ℤ) := by
rw [← ZMod.intCast_mod n 8, Nat.cast_ofNat]
/-- An explicit description of `χ₈` on integers / naturals -/
theorem χ₈_int_eq_if_mod_eight (n : ℤ) :
χ₈ n = if n % 2 = 0 then 0 else if n % 8 = 1 ∨ n % 8 = 7 then 1 else -1 := by
have help :
∀ m : ℤ, 0 ≤ m → m < 8 → χ₈ m = if m % 2 = 0 then 0 else if m = 1 ∨ m = 7 then 1 else -1 := by
decide
rw [← Int.emod_emod_of_dvd n (by cutsat : (2 : ℤ) ∣ 8), ← ZMod.intCast_mod n 8]
exact help (n % 8) (Int.emod_nonneg n (by cutsat)) (Int.emod_lt_abs n (by cutsat))
theorem χ₈_nat_eq_if_mod_eight (n : ℕ) :
χ₈ n = if n % 2 = 0 then 0 else if n % 8 = 1 ∨ n % 8 = 7 then 1 else -1 :=
mod_cast χ₈_int_eq_if_mod_eight n
/-- Define the second primitive quadratic character on `ZMod 8`, `χ₈'`.
It corresponds to the extension `ℚ(√-2)/ℚ`. -/
@[simps]
def χ₈' : MulChar (ZMod 8) ℤ where
toFun a :=
match a with
| 0 | 2 | 4 | 6 => 0
| 1 | 3 => 1
| 5 | 7 => -1
map_one' := rfl
map_mul' := by decide
map_nonunit' := by decide
/-- `χ₈'` takes values in `{0, 1, -1}` -/
theorem isQuadratic_χ₈' : χ₈'.IsQuadratic := by
unfold MulChar.IsQuadratic
decide
/-- An explicit description of `χ₈'` on integers / naturals -/
theorem χ₈'_int_eq_if_mod_eight (n : ℤ) :
χ₈' n = if n % 2 = 0 then 0 else if n % 8 = 1 ∨ n % 8 = 3 then 1 else -1 := by
have help :
∀ m : ℤ, 0 ≤ m → m < 8 → χ₈' m = if m % 2 = 0 then 0 else if m = 1 ∨ m = 3 then 1 else -1 := by
decide
rw [← Int.emod_emod_of_dvd n (by cutsat : (2 : ℤ) ∣ 8), ← ZMod.intCast_mod n 8]
exact help (n % 8) (Int.emod_nonneg n (by cutsat)) (Int.emod_lt_abs n (by cutsat))
theorem χ₈'_nat_eq_if_mod_eight (n : ℕ) :
χ₈' n = if n % 2 = 0 then 0 else if n % 8 = 1 ∨ n % 8 = 3 then 1 else -1 :=
mod_cast χ₈'_int_eq_if_mod_eight n
/-- The relation between `χ₄`, `χ₈` and `χ₈'` -/
theorem χ₈'_eq_χ₄_mul_χ₈ : ∀ a : ZMod 8, χ₈' a = χ₄ (cast a) * χ₈ a := by
decide
theorem χ₈'_int_eq_χ₄_mul_χ₈ (a : ℤ) : χ₈' a = χ₄ a * χ₈ a := by
rw [← @cast_intCast 8 (ZMod 4) _ 4 _ (by cutsat) a]
exact χ₈'_eq_χ₄_mul_χ₈ a
end QuadCharModP
end ZMod |
.lake/packages/mathlib/Mathlib/NumberTheory/LegendreSymbol/JacobiSymbol.lean | import Mathlib.NumberTheory.LegendreSymbol.QuadraticReciprocity
/-!
# The Jacobi Symbol
We define the Jacobi symbol and prove its main properties.
## Main definitions
We define the Jacobi symbol, `jacobiSym a b`, for integers `a` and natural numbers `b`
as the product over the prime factors `p` of `b` of the Legendre symbols `legendreSym p a`.
This agrees with the mathematical definition when `b` is odd.
The prime factors are obtained via `Nat.factors`. Since `Nat.factors 0 = []`,
this implies in particular that `jacobiSym a 0 = 1` for all `a`.
## Main statements
We prove the main properties of the Jacobi symbol, including the following.
* Multiplicativity in both arguments (`jacobiSym.mul_left`, `jacobiSym.mul_right`)
* The value of the symbol is `1` or `-1` when the arguments are coprime
(`jacobiSym.eq_one_or_neg_one`)
* The symbol vanishes if and only if `b ≠ 0` and the arguments are not coprime
(`jacobiSym.eq_zero_iff_not_coprime`)
* If the symbol has the value `-1`, then `a : ZMod b` is not a square
(`ZMod.nonsquare_of_jacobiSym_eq_neg_one`); the converse holds when `b = p` is a prime
(`ZMod.nonsquare_iff_jacobiSym_eq_neg_one`); in particular, in this case `a` is a
square mod `p` when the symbol has the value `1` (`ZMod.isSquare_of_jacobiSym_eq_one`).
* Quadratic reciprocity (`jacobiSym.quadratic_reciprocity`,
`jacobiSym.quadratic_reciprocity_one_mod_four`,
`jacobiSym.quadratic_reciprocity_three_mod_four`)
* The supplementary laws for `a = -1`, `a = 2`, `a = -2` (`jacobiSym.at_neg_one`,
`jacobiSym.at_two`, `jacobiSym.at_neg_two`)
* The symbol depends on `a` only via its residue class mod `b` (`jacobiSym.mod_left`)
and on `b` only via its residue class mod `4*a` (`jacobiSym.mod_right`)
* A `csimp` rule for `jacobiSym` and `legendreSym` that evaluates `J(a | b)` efficiently by
reducing to the case `0 ≤ a < b` and `a`, `b` odd, and then swaps `a`, `b` and recurses using
quadratic reciprocity.
## Notation
We define the notation `J(a | b)` for `jacobiSym a b`, localized to `NumberTheorySymbols`.
## Tags
Jacobi symbol, quadratic reciprocity
-/
section Jacobi
/-!
### Definition of the Jacobi symbol
We define the Jacobi symbol $\Bigl(\frac{a}{b}\Bigr)$ for integers `a` and natural numbers `b`
as the product of the Legendre symbols $\Bigl(\frac{a}{p}\Bigr)$, where `p` runs through the
prime divisors (with multiplicity) of `b`, as provided by `b.factors`. This agrees with the
Jacobi symbol when `b` is odd and gives less meaningful values when it is not (e.g., the symbol
is `1` when `b = 0`). This is called `jacobiSym a b`.
We define localized notation (scope `NumberTheorySymbols`) `J(a | b)` for the Jacobi
symbol `jacobiSym a b`.
-/
open Nat ZMod
-- Since we need the fact that the factors are prime, we use `List.pmap`.
/-- The Jacobi symbol of `a` and `b` -/
def jacobiSym (a : ℤ) (b : ℕ) : ℤ :=
(b.primeFactorsList.pmap (fun p pp => @legendreSym p ⟨pp⟩ a) fun _ pf =>
prime_of_mem_primeFactorsList pf).prod
-- Notation for the Jacobi symbol.
@[inherit_doc]
scoped[NumberTheorySymbols] notation "J(" a " | " b ")" => jacobiSym a b
open NumberTheorySymbols
/-!
### Properties of the Jacobi symbol
-/
namespace jacobiSym
/-- The symbol `J(a | 0)` has the value `1`. -/
@[simp]
theorem zero_right (a : ℤ) : J(a | 0) = 1 := by
simp only [jacobiSym, primeFactorsList_zero, List.prod_nil, List.pmap]
/-- The symbol `J(a | 1)` has the value `1`. -/
@[simp]
theorem one_right (a : ℤ) : J(a | 1) = 1 := by
simp only [jacobiSym, primeFactorsList_one, List.prod_nil, List.pmap]
/-- The Legendre symbol `legendreSym p a` with an integer `a` and a prime number `p`
is the same as the Jacobi symbol `J(a | p)`. -/
theorem legendreSym.to_jacobiSym (p : ℕ) [fp : Fact p.Prime] (a : ℤ) :
legendreSym p a = J(a | p) := by
simp only [jacobiSym, primeFactorsList_prime fp.1, List.prod_cons, List.prod_nil, mul_one,
List.pmap]
/-- The Jacobi symbol is multiplicative in its second argument. -/
theorem mul_right' (a : ℤ) {b₁ b₂ : ℕ} (hb₁ : b₁ ≠ 0) (hb₂ : b₂ ≠ 0) :
J(a | b₁ * b₂) = J(a | b₁) * J(a | b₂) := by
rw [jacobiSym, ((perm_primeFactorsList_mul hb₁ hb₂).pmap _).prod_eq, List.pmap_append,
List.prod_append]
pick_goal 2
· exact fun p hp =>
(List.mem_append.mp hp).elim prime_of_mem_primeFactorsList prime_of_mem_primeFactorsList
· rfl
/-- The Jacobi symbol is multiplicative in its second argument. -/
theorem mul_right (a : ℤ) (b₁ b₂ : ℕ) [NeZero b₁] [NeZero b₂] :
J(a | b₁ * b₂) = J(a | b₁) * J(a | b₂) :=
mul_right' a (NeZero.ne b₁) (NeZero.ne b₂)
/-- The Jacobi symbol takes only the values `0`, `1` and `-1`. -/
theorem trichotomy (a : ℤ) (b : ℕ) : J(a | b) = 0 ∨ J(a | b) = 1 ∨ J(a | b) = -1 :=
((MonoidHom.mrange (@SignType.castHom ℤ _ _).toMonoidHom).copy {0, 1, -1} <| by
rw [Set.pair_comm]
exact (SignType.range_eq SignType.castHom).symm).list_prod_mem
(by
intro _ ha'
rcases List.mem_pmap.mp ha' with ⟨p, hp, rfl⟩
haveI : Fact p.Prime := ⟨prime_of_mem_primeFactorsList hp⟩
exact quadraticChar_isQuadratic (ZMod p) a)
/-- The symbol `J(1 | b)` has the value `1`. -/
@[simp]
theorem one_left (b : ℕ) : J(1 | b) = 1 :=
List.prod_eq_one fun z hz => by
let ⟨p, hp, he⟩ := List.mem_pmap.1 hz
rw [← he, legendreSym.at_one]
/-- The Jacobi symbol is multiplicative in its first argument. -/
theorem mul_left (a₁ a₂ : ℤ) (b : ℕ) : J(a₁ * a₂ | b) = J(a₁ | b) * J(a₂ | b) := by
simp_rw [jacobiSym, List.pmap_eq_map_attach, legendreSym.mul _ _ _]
exact List.prod_map_mul (l := (primeFactorsList b).attach)
(f := fun x ↦ @legendreSym x {out := prime_of_mem_primeFactorsList x.2} a₁)
(g := fun x ↦ @legendreSym x {out := prime_of_mem_primeFactorsList x.2} a₂)
/-- The symbol `J(a | b)` vanishes iff `a` and `b` are not coprime (assuming `b ≠ 0`). -/
theorem eq_zero_iff_not_coprime {a : ℤ} {b : ℕ} [NeZero b] : J(a | b) = 0 ↔ a.gcd b ≠ 1 :=
List.prod_eq_zero_iff.trans
(by
rw [List.mem_pmap, Int.gcd_eq_natAbs, Ne, Prime.not_coprime_iff_dvd]
simp_rw [legendreSym.eq_zero_iff _ _, intCast_zmod_eq_zero_iff_dvd,
mem_primeFactorsList (NeZero.ne b), ← Int.natCast_dvd, Int.natCast_dvd_natCast, exists_prop,
and_assoc, _root_.and_comm])
/-- The symbol `J(a | b)` is nonzero when `a` and `b` are coprime. -/
protected theorem ne_zero {a : ℤ} {b : ℕ} (h : a.gcd b = 1) : J(a | b) ≠ 0 := by
rcases eq_zero_or_neZero b with hb | _
· rw [hb, zero_right]
exact one_ne_zero
· contrapose! h; exact eq_zero_iff_not_coprime.1 h
/-- The symbol `J(a | b)` vanishes if and only if `b ≠ 0` and `a` and `b` are not coprime. -/
theorem eq_zero_iff {a : ℤ} {b : ℕ} : J(a | b) = 0 ↔ b ≠ 0 ∧ a.gcd b ≠ 1 :=
⟨fun h => by
rcases eq_or_ne b 0 with hb | hb
· rw [hb, zero_right] at h; cases h
exact ⟨hb, mt jacobiSym.ne_zero <| Classical.not_not.2 h⟩, fun ⟨hb, h⟩ => by
rw [← neZero_iff] at hb; exact eq_zero_iff_not_coprime.2 h⟩
/-- The symbol `J(0 | b)` vanishes when `b > 1`. -/
theorem zero_left {b : ℕ} (hb : 1 < b) : J(0 | b) = 0 :=
(@eq_zero_iff_not_coprime 0 b ⟨ne_zero_of_lt hb⟩).mpr <| by
rw [Int.gcd_zero_left, Int.natAbs_natCast]; exact hb.ne'
/-- The symbol `J(a | b)` takes the value `1` or `-1` if `a` and `b` are coprime. -/
theorem eq_one_or_neg_one {a : ℤ} {b : ℕ} (h : a.gcd b = 1) : J(a | b) = 1 ∨ J(a | b) = -1 :=
(trichotomy a b).resolve_left <| jacobiSym.ne_zero h
/-- We have that `J(a^e | b) = J(a | b)^e`. -/
theorem pow_left (a : ℤ) (e b : ℕ) : J(a ^ e | b) = J(a | b) ^ e :=
Nat.recOn e (by rw [_root_.pow_zero, _root_.pow_zero, one_left]) fun _ ih => by
rw [_root_.pow_succ, _root_.pow_succ, mul_left, ih]
/-- We have that `J(a | b^e) = J(a | b)^e`. -/
theorem pow_right (a : ℤ) (b e : ℕ) : J(a | b ^ e) = J(a | b) ^ e := by
induction e with
| zero => rw [Nat.pow_zero, _root_.pow_zero, one_right]
| succ e ih =>
rcases eq_zero_or_neZero b with hb | _
· rw [hb, zero_pow e.succ_ne_zero, zero_right, one_pow]
· rw [_root_.pow_succ, _root_.pow_succ, mul_right, ih]
/-- The square of `J(a | b)` is `1` when `a` and `b` are coprime. -/
theorem sq_one {a : ℤ} {b : ℕ} (h : a.gcd b = 1) : J(a | b) ^ 2 = 1 := by
rcases eq_one_or_neg_one h with h₁ | h₁ <;> rw [h₁] <;> rfl
/-- The symbol `J(a^2 | b)` is `1` when `a` and `b` are coprime. -/
theorem sq_one' {a : ℤ} {b : ℕ} (h : a.gcd b = 1) : J(a ^ 2 | b) = 1 := by rw [pow_left, sq_one h]
/-- The symbol `J(a | b)` depends only on `a` mod `b`. -/
theorem mod_left (a : ℤ) (b : ℕ) : J(a | b) = J(a % b | b) :=
congr_arg List.prod <|
List.pmap_congr_left _
(by
rintro p hp _ h₂
conv_rhs =>
rw [legendreSym.mod, Int.emod_emod_of_dvd _ (Int.natCast_dvd_natCast.2 <|
dvd_of_mem_primeFactorsList hp), ← legendreSym.mod])
/-- The symbol `J(a | b)` depends only on `a` mod `b`. -/
theorem mod_left' {a₁ a₂ : ℤ} {b : ℕ} (h : a₁ % b = a₂ % b) : J(a₁ | b) = J(a₂ | b) := by
rw [mod_left, h, ← mod_left]
/-- If `p` is prime, `J(a | p) = -1` and `p` divides `x^2 - a*y^2`, then `p` must divide
`x` and `y`. -/
theorem prime_dvd_of_eq_neg_one {p : ℕ} [Fact p.Prime] {a : ℤ} (h : J(a | p) = -1) {x y : ℤ}
(hxy : ↑p ∣ (x ^ 2 - a * y ^ 2 : ℤ)) : ↑p ∣ x ∧ ↑p ∣ y := by
rw [← legendreSym.to_jacobiSym] at h
exact legendreSym.prime_dvd_of_eq_neg_one h hxy
/-- We can pull out a product over a list in the first argument of the Jacobi symbol. -/
theorem list_prod_left {l : List ℤ} {n : ℕ} : J(l.prod | n) = (l.map fun a => J(a | n)).prod := by
induction l with
| nil => simp only [List.prod_nil, List.map_nil, one_left]
| cons n l' ih => rw [List.map, List.prod_cons, List.prod_cons, mul_left, ih]
/-- We can pull out a product over a list in the second argument of the Jacobi symbol. -/
theorem list_prod_right {a : ℤ} {l : List ℕ} (hl : ∀ n ∈ l, n ≠ 0) :
J(a | l.prod) = (l.map fun n => J(a | n)).prod := by
induction l with
| nil => simp only [List.prod_nil, one_right, List.map_nil]
| cons n l' ih =>
have hn := hl n List.mem_cons_self
-- `n ≠ 0`
have hl' := List.prod_ne_zero fun hf => hl 0 (List.mem_cons_of_mem _ hf) rfl
-- `l'.prod ≠ 0`
have h := fun m hm => hl m (List.mem_cons_of_mem _ hm)
-- `∀ (m : ℕ), m ∈ l' → m ≠ 0`
rw [List.map, List.prod_cons, List.prod_cons, mul_right' a hn hl', ih h]
/-- If `J(a | n) = -1`, then `n` has a prime divisor `p` such that `J(a | p) = -1`. -/
theorem eq_neg_one_at_prime_divisor_of_eq_neg_one {a : ℤ} {n : ℕ} (h : J(a | n) = -1) :
∃ p : ℕ, p.Prime ∧ p ∣ n ∧ J(a | p) = -1 := by
have hn₀ : n ≠ 0 := by
rintro rfl
rw [zero_right, CharZero.eq_neg_self_iff] at h
exact one_ne_zero h
have hf₀ (p) (hp : p ∈ n.primeFactorsList) : p ≠ 0 := (Nat.pos_of_mem_primeFactorsList hp).ne.symm
rw [← Nat.prod_primeFactorsList hn₀, list_prod_right hf₀] at h
obtain ⟨p, hmem, hj⟩ := List.mem_map.mp (List.neg_one_mem_of_prod_eq_neg_one h)
exact ⟨p, Nat.prime_of_mem_primeFactorsList hmem, Nat.dvd_of_mem_primeFactorsList hmem, hj⟩
end jacobiSym
namespace ZMod
open jacobiSym
/-- If `J(a | b)` is `-1`, then `a` is not a square modulo `b`. -/
theorem nonsquare_of_jacobiSym_eq_neg_one {a : ℤ} {b : ℕ} (h : J(a | b) = -1) :
¬IsSquare (a : ZMod b) := fun ⟨r, ha⟩ => by
rw [← r.coe_valMinAbs, ← Int.cast_mul, intCast_eq_intCast_iff', ← sq] at ha
apply (by simp : ¬(0 : ℤ) ≤ -1)
rw [← h, mod_left, ha, ← mod_left, pow_left]
apply sq_nonneg
/-- If `p` is prime, then `J(a | p)` is `-1` iff `a` is not a square modulo `p`. -/
theorem nonsquare_iff_jacobiSym_eq_neg_one {a : ℤ} {p : ℕ} [Fact p.Prime] :
J(a | p) = -1 ↔ ¬IsSquare (a : ZMod p) := by
rw [← legendreSym.to_jacobiSym]
exact legendreSym.eq_neg_one_iff p
/-- If `p` is prime and `J(a | p) = 1`, then `a` is a square mod `p`. -/
theorem isSquare_of_jacobiSym_eq_one {a : ℤ} {p : ℕ} [Fact p.Prime] (h : J(a | p) = 1) :
IsSquare (a : ZMod p) :=
Classical.not_not.mp <| by rw [← nonsquare_iff_jacobiSym_eq_neg_one, h]; decide
end ZMod
/-!
### Values at `-1`, `2` and `-2`
-/
namespace jacobiSym
/-- If `χ` is a multiplicative function such that `J(a | p) = χ p` for all odd primes `p`,
then `J(a | b)` equals `χ b` for all odd natural numbers `b`. -/
theorem value_at (a : ℤ) {R : Type*} [Semiring R] (χ : R →* ℤ)
(hp : ∀ (p : ℕ) (pp : p.Prime), p ≠ 2 → @legendreSym p ⟨pp⟩ a = χ p) {b : ℕ} (hb : Odd b) :
J(a | b) = χ b := by
conv_rhs => rw [← prod_primeFactorsList hb.pos.ne', cast_list_prod, map_list_prod χ]
rw [jacobiSym, List.map_map, ← List.pmap_eq_map
fun _ => prime_of_mem_primeFactorsList]
congr 1; apply List.pmap_congr_left
exact fun p h pp _ => hp p pp (hb.ne_two_of_dvd_nat <| dvd_of_mem_primeFactorsList h)
/-- If `b` is odd, then `J(-1 | b)` is given by `χ₄ b`. -/
theorem at_neg_one {b : ℕ} (hb : Odd b) : J(-1 | b) = χ₄ b :=
-- Porting note: In mathlib3, it was written `χ₄` and Lean could guess that it had to use
-- `χ₄.to_monoid_hom`. This is not the case with Lean 4.
value_at (-1) χ₄.toMonoidHom (fun p pp => @legendreSym.at_neg_one p ⟨pp⟩) hb
/-- If `b` is odd, then `J(-a | b) = χ₄ b * J(a | b)`. -/
protected theorem neg (a : ℤ) {b : ℕ} (hb : Odd b) : J(-a | b) = χ₄ b * J(a | b) := by
rw [neg_eq_neg_one_mul, mul_left, at_neg_one hb]
/-- If `b` is odd, then `J(2 | b)` is given by `χ₈ b`. -/
theorem at_two {b : ℕ} (hb : Odd b) : J(2 | b) = χ₈ b :=
value_at 2 χ₈.toMonoidHom (fun p pp => @legendreSym.at_two p ⟨pp⟩) hb
/-- If `b` is odd, then `J(-2 | b)` is given by `χ₈' b`. -/
theorem at_neg_two {b : ℕ} (hb : Odd b) : J(-2 | b) = χ₈' b :=
value_at (-2) χ₈'.toMonoidHom (fun p pp => @legendreSym.at_neg_two p ⟨pp⟩) hb
theorem div_four_left {a : ℤ} {b : ℕ} (ha4 : a % 4 = 0) (hb2 : b % 2 = 1) :
J(a / 4 | b) = J(a | b) := by
obtain ⟨a, rfl⟩ := Int.dvd_of_emod_eq_zero ha4
have : Int.gcd (2 : ℕ) b = 1 := by
rw [Int.gcd_natCast_natCast, ← b.mod_add_div 2, hb2, Nat.gcd_add_mul_left_right,
Nat.gcd_one_right]
rw [Int.mul_ediv_cancel_left _ (by decide), jacobiSym.mul_left,
(by decide : (4 : ℤ) = (2 : ℕ) ^ 2), jacobiSym.sq_one' this, one_mul]
theorem even_odd {a : ℤ} {b : ℕ} (ha2 : a % 2 = 0) (hb2 : b % 2 = 1) :
(if b % 8 = 3 ∨ b % 8 = 5 then -J(a / 2 | b) else J(a / 2 | b)) = J(a | b) := by
obtain ⟨a, rfl⟩ := Int.dvd_of_emod_eq_zero ha2
rw [Int.mul_ediv_cancel_left _ (by decide), jacobiSym.mul_left,
jacobiSym.at_two (Nat.odd_iff.mpr hb2), ZMod.χ₈_nat_eq_if_mod_eight,
if_neg (Nat.mod_two_ne_zero.mpr hb2)]
grind
end jacobiSym
/-!
### Quadratic Reciprocity
-/
/-- The bi-multiplicative map giving the sign in the Law of Quadratic Reciprocity -/
def qrSign (m n : ℕ) : ℤ :=
J(χ₄ m | n)
namespace qrSign
/-- We can express `qrSign m n` as a power of `-1` when `m` and `n` are odd. -/
theorem neg_one_pow {m n : ℕ} (hm : Odd m) (hn : Odd n) :
qrSign m n = (-1) ^ (m / 2 * (n / 2)) := by
rw [qrSign, pow_mul, ← χ₄_eq_neg_one_pow (odd_iff.mp hm)]
rcases odd_mod_four_iff.mp (odd_iff.mp hm) with h | h
· rw [χ₄_nat_one_mod_four h, jacobiSym.one_left, one_pow]
· rw [χ₄_nat_three_mod_four h, ← χ₄_eq_neg_one_pow (odd_iff.mp hn), jacobiSym.at_neg_one hn]
/-- When `m` and `n` are odd, then the square of `qrSign m n` is `1`. -/
theorem sq_eq_one {m n : ℕ} (hm : Odd m) (hn : Odd n) : qrSign m n ^ 2 = 1 := by
rw [neg_one_pow hm hn, ← pow_mul, mul_comm, pow_mul, neg_one_sq, one_pow]
/-- `qrSign` is multiplicative in the first argument. -/
theorem mul_left (m₁ m₂ n : ℕ) : qrSign (m₁ * m₂) n = qrSign m₁ n * qrSign m₂ n := by
simp_rw [qrSign, Nat.cast_mul, map_mul, jacobiSym.mul_left]
/-- `qrSign` is multiplicative in the second argument. -/
theorem mul_right (m n₁ n₂ : ℕ) [NeZero n₁] [NeZero n₂] :
qrSign m (n₁ * n₂) = qrSign m n₁ * qrSign m n₂ :=
jacobiSym.mul_right (χ₄ m) n₁ n₂
/-- `qrSign` is symmetric when both arguments are odd. -/
protected theorem symm {m n : ℕ} (hm : Odd m) (hn : Odd n) : qrSign m n = qrSign n m := by
rw [neg_one_pow hm hn, neg_one_pow hn hm, mul_comm (m / 2)]
/-- We can move `qrSign m n` from one side of an equality to the other when `m` and `n` are odd. -/
theorem eq_iff_eq {m n : ℕ} (hm : Odd m) (hn : Odd n) (x y : ℤ) :
qrSign m n * x = y ↔ x = qrSign m n * y := by
refine
⟨fun h' =>
let h := h'.symm
?_,
fun h => ?_⟩ <;>
rw [h, ← mul_assoc, ← pow_two, sq_eq_one hm hn, one_mul]
end qrSign
namespace jacobiSym
/-- The **Law of Quadratic Reciprocity for the Jacobi symbol**, version with `qrSign` -/
theorem quadratic_reciprocity' {a b : ℕ} (ha : Odd a) (hb : Odd b) :
J(a | b) = qrSign b a * J(b | a) := by
-- define the right-hand side for fixed `a` as a `ℕ →* ℤ`
let rhs : ℕ → ℕ →* ℤ := fun a =>
{ toFun := fun x => qrSign x a * J(x | a)
map_one' := by convert ← mul_one (M := ℤ) _; (on_goal 1 => symm); all_goals apply one_left
map_mul' := fun x y => by
simp_rw [qrSign.mul_left x y a, Nat.cast_mul, mul_left, mul_mul_mul_comm] }
have rhs_apply : ∀ a b : ℕ, rhs a b = qrSign b a * J(b | a) := fun a b => rfl
refine value_at a (rhs a) (fun p pp hp => Eq.symm ?_) hb
have hpo := pp.eq_two_or_odd'.resolve_left hp
rw [@legendreSym.to_jacobiSym p ⟨pp⟩, rhs_apply, Nat.cast_id, qrSign.eq_iff_eq hpo ha,
qrSign.symm hpo ha]
refine value_at p (rhs p) (fun q pq hq => ?_) ha
have hqo := pq.eq_two_or_odd'.resolve_left hq
rw [rhs_apply, Nat.cast_id, ← @legendreSym.to_jacobiSym p ⟨pp⟩, qrSign.symm hqo hpo,
qrSign.neg_one_pow hpo hqo, @legendreSym.quadratic_reciprocity' p q ⟨pp⟩ ⟨pq⟩ hp hq]
/-- The Law of Quadratic Reciprocity for the Jacobi symbol -/
theorem quadratic_reciprocity {a b : ℕ} (ha : Odd a) (hb : Odd b) :
J(a | b) = (-1) ^ (a / 2 * (b / 2)) * J(b | a) := by
rw [← qrSign.neg_one_pow ha hb, qrSign.symm ha hb, quadratic_reciprocity' ha hb]
/-- The Law of Quadratic Reciprocity for the Jacobi symbol: if `a` and `b` are natural numbers
with `a % 4 = 1` and `b` odd, then `J(a | b) = J(b | a)`. -/
theorem quadratic_reciprocity_one_mod_four {a b : ℕ} (ha : a % 4 = 1) (hb : Odd b) :
J(a | b) = J(b | a) := by
rw [quadratic_reciprocity (odd_iff.mpr (odd_of_mod_four_eq_one ha)) hb, pow_mul,
neg_one_pow_div_two_of_one_mod_four ha, one_pow, one_mul]
/-- The Law of Quadratic Reciprocity for the Jacobi symbol: if `a` and `b` are natural numbers
with `a` odd and `b % 4 = 1`, then `J(a | b) = J(b | a)`. -/
theorem quadratic_reciprocity_one_mod_four' {a b : ℕ} (ha : Odd a) (hb : b % 4 = 1) :
J(a | b) = J(b | a) :=
(quadratic_reciprocity_one_mod_four hb ha).symm
/-- The Law of Quadratic Reciprocity for the Jacobi symbol: if `a` and `b` are natural numbers
both congruent to `3` mod `4`, then `J(a | b) = -J(b | a)`. -/
theorem quadratic_reciprocity_three_mod_four {a b : ℕ} (ha : a % 4 = 3) (hb : b % 4 = 3) :
J(a | b) = -J(b | a) := by
let nop := @neg_one_pow_div_two_of_three_mod_four
rw [quadratic_reciprocity, pow_mul, nop ha, nop hb, neg_one_mul] <;>
rwa [odd_iff, odd_of_mod_four_eq_three]
theorem quadratic_reciprocity_if {a b : ℕ} (ha2 : a % 2 = 1) (hb2 : b % 2 = 1) :
(if a % 4 = 3 ∧ b % 4 = 3 then -J(b | a) else J(b | a)) = J(a | b) := by
rcases Nat.odd_mod_four_iff.mp ha2 with ha1 | ha3
· simpa [ha1] using jacobiSym.quadratic_reciprocity_one_mod_four' (Nat.odd_iff.mpr hb2) ha1
rcases Nat.odd_mod_four_iff.mp hb2 with hb1 | hb3
· simpa [hb1] using jacobiSym.quadratic_reciprocity_one_mod_four hb1 (Nat.odd_iff.mpr ha2)
simpa [ha3, hb3] using (jacobiSym.quadratic_reciprocity_three_mod_four ha3 hb3).symm
/-- The Jacobi symbol `J(a | b)` depends only on `b` mod `4*a` (version for `a : ℕ`). -/
theorem mod_right' (a : ℕ) {b : ℕ} (hb : Odd b) : J(a | b) = J(a | b % (4 * a)) := by
rcases eq_or_ne a 0 with (rfl | ha₀)
· rw [mul_zero, mod_zero]
have hb' : Odd (b % (4 * a)) := hb.mod_even (Even.mul_right (by decide) _)
rcases exists_eq_pow_mul_and_not_dvd ha₀ 2 (by simp) with ⟨e, a', ha₁', ha₂⟩
have ha₁ := odd_iff.mpr (two_dvd_ne_zero.mp ha₁')
nth_rw 2 [ha₂]; nth_rw 1 [ha₂]
rw [Nat.cast_mul, mul_left, mul_left, quadratic_reciprocity' ha₁ hb,
quadratic_reciprocity' ha₁ hb', Nat.cast_pow, pow_left, pow_left, Nat.cast_two, at_two hb,
at_two hb']
congr 1; swap
· congr 1
· simp_rw [qrSign]
rw [χ₄_nat_mod_four, χ₄_nat_mod_four (b % (4 * a)), mod_mod_of_dvd b (dvd_mul_right 4 a)]
· rw [mod_left ↑(b % _), mod_left b, Int.natCast_mod, Int.emod_emod_of_dvd b]
simp only [ha₂, Nat.cast_mul, ← mul_assoc]
apply dvd_mul_left
rcases e with - | e; · rfl
· rw [χ₈_nat_mod_eight, χ₈_nat_mod_eight (b % (4 * a)), mod_mod_of_dvd b]
use 2 ^ e * a'; rw [ha₂, Nat.pow_succ]; ring
/-- The Jacobi symbol `J(a | b)` depends only on `b` mod `4*a`. -/
theorem mod_right (a : ℤ) {b : ℕ} (hb : Odd b) : J(a | b) = J(a | b % (4 * a.natAbs)) := by
rcases Int.natAbs_eq a with ha | ha <;> nth_rw 2 [ha] <;> nth_rw 1 [ha]
· exact mod_right' a.natAbs hb
· have hb' : Odd (b % (4 * a.natAbs)) := hb.mod_even (Even.mul_right (by decide) _)
rw [jacobiSym.neg _ hb, jacobiSym.neg _ hb', mod_right' _ hb, χ₄_nat_mod_four,
χ₄_nat_mod_four (b % (4 * _)), mod_mod_of_dvd b (dvd_mul_right 4 _)]
end jacobiSym
end Jacobi
section FastJacobi
/-!
### Fast computation of the Jacobi symbol
We follow the implementation as in `Mathlib/Tactic/NormNum/LegendreSymbol.lean`.
-/
open NumberTheorySymbols jacobiSym
/-- Computes `J(a | b)` (or `-J(a | b)` if `flip` is set to `true`) given assumptions, by reducing
`a` to odd by repeated division and then using quadratic reciprocity to swap `a`, `b`. -/
private def fastJacobiSymAux (a b : ℕ) (flip : Bool) (ha0 : a > 0) : ℤ :=
if ha4 : a % 4 = 0 then
fastJacobiSymAux (a / 4) b flip
(Nat.div_pos (Nat.le_of_dvd ha0 (Nat.dvd_of_mod_eq_zero ha4)) (by decide))
else if ha2 : a % 2 = 0 then
fastJacobiSymAux (a / 2) b (xor (b % 8 = 3 ∨ b % 8 = 5) flip)
(Nat.div_pos (Nat.le_of_dvd ha0 (Nat.dvd_of_mod_eq_zero ha2)) (by decide))
else if ha1 : a = 1 then
if flip then -1 else 1
else if hba : b % a = 0 then
0
else
fastJacobiSymAux (b % a) a (xor (a % 4 = 3 ∧ b % 4 = 3) flip) (Nat.pos_of_ne_zero hba)
termination_by a
decreasing_by
· exact a.div_lt_self ha0 (by decide)
· exact a.div_lt_self ha0 (by decide)
· exact b.mod_lt ha0
private theorem fastJacobiSymAux.eq_jacobiSym {a b : ℕ} {flip : Bool} {ha0 : a > 0}
(hb2 : b % 2 = 1) (hb1 : b > 1) :
fastJacobiSymAux a b flip ha0 = if flip then -J(a | b) else J(a | b) := by
induction a using Nat.strongRecOn generalizing b flip with | ind a IH =>
unfold fastJacobiSymAux
split <;> rename_i ha4
· rw [IH (a / 4) (a.div_lt_self ha0 (by decide)) hb2 hb1]
simp only [Int.natCast_ediv, Nat.cast_ofNat, div_four_left (a := a) (mod_cast ha4) hb2]
split <;> rename_i ha2
· rw [IH (a / 2) (a.div_lt_self ha0 (by decide)) hb2 hb1]
simp only [Int.natCast_ediv, Nat.cast_ofNat, ← even_odd (a := a) (mod_cast ha2) hb2]
by_cases h : b % 8 = 3 ∨ b % 8 = 5 <;> simp [h]; cases flip <;> simp
split <;> rename_i ha1
· subst ha1; simp
split <;> rename_i hba
· suffices J(a | b) = 0 by simp [this]
refine eq_zero_iff.mpr ⟨fun h ↦ absurd (h ▸ hb1) (by decide), ?_⟩
rwa [Int.gcd_natCast_natCast, Nat.gcd_eq_left (Nat.dvd_of_mod_eq_zero hba)]
rw [IH (b % a) (b.mod_lt ha0) (Nat.mod_two_ne_zero.mp ha2) (lt_of_le_of_ne ha0 (Ne.symm ha1))]
simp only [Int.natCast_mod, ← mod_left]
rw [← quadratic_reciprocity_if (Nat.mod_two_ne_zero.mp ha2) hb2]
by_cases h : a % 4 = 3 ∧ b % 4 = 3 <;> simp [h]; cases flip <;> simp
/-- Computes `J(a | b)` by reducing `b` to odd by repeated division and then using
`fastJacobiSymAux`. -/
private def fastJacobiSym (a : ℤ) (b : ℕ) : ℤ :=
if hb0 : b = 0 then
1
else if _ : b % 2 = 0 then
if a % 2 = 0 then
0
else
have : b / 2 < b := b.div_lt_self (Nat.pos_of_ne_zero hb0) one_lt_two
fastJacobiSym a (b / 2)
else if b = 1 then
1
else if hab : a % b = 0 then
0
else
fastJacobiSymAux (a % b).natAbs b false (Int.natAbs_pos.mpr hab)
@[csimp] private theorem fastJacobiSym.eq : jacobiSym = fastJacobiSym := by
ext a b
induction b using Nat.strongRecOn with | ind b IH =>
unfold fastJacobiSym
split_ifs with hb0 hb2 ha2 hb1 hab
· rw [hb0, zero_right]
· refine eq_zero_iff.mpr ⟨hb0, ne_of_gt ?_⟩
refine Nat.le_of_dvd (Int.gcd_pos_iff.mpr (mod_cast .inr hb0)) ?_
refine Nat.dvd_gcd (Int.ofNat_dvd_left.mp (Int.dvd_of_emod_eq_zero ha2)) ?_
exact Int.ofNat_dvd_left.mp (Int.dvd_of_emod_eq_zero (mod_cast hb2))
· dsimp only
rw [← IH (b / 2) (b.div_lt_self (Nat.pos_of_ne_zero hb0) one_lt_two)]
obtain ⟨b, rfl⟩ := Nat.dvd_of_mod_eq_zero hb2
rw [mul_right' a (by decide) fun h ↦ hb0 (mul_eq_zero_of_right 2 h),
b.mul_div_cancel_left (by decide), mod_left a 2, Nat.cast_ofNat,
Int.emod_two_ne_zero.mp ha2, one_left, one_mul]
· rw [hb1, one_right]
· rw [mod_left, hab, zero_left (lt_of_le_of_ne (Nat.pos_of_ne_zero hb0) (Ne.symm hb1))]
· rw [fastJacobiSymAux.eq_jacobiSym, if_neg Bool.false_ne_true, mod_left a b,
Int.natAbs_of_nonneg (a.emod_nonneg (mod_cast hb0))]
· exact Nat.mod_two_ne_zero.mp hb2
· exact lt_of_le_of_ne (Nat.one_le_iff_ne_zero.mpr hb0) (Ne.symm hb1)
/-- Computes `legendreSym p a` using `fastJacobiSym`. -/
@[inline, nolint unusedArguments]
private def fastLegendreSym (p : ℕ) [Fact p.Prime] (a : ℤ) : ℤ := J(a | p)
@[csimp] private theorem fastLegendreSym.eq : legendreSym = fastLegendreSym := by
ext p _ a; rw [legendreSym.to_jacobiSym, fastLegendreSym]
end FastJacobi |
.lake/packages/mathlib/Mathlib/NumberTheory/LegendreSymbol/QuadraticChar/GaussSum.lean | import Mathlib.NumberTheory.LegendreSymbol.QuadraticChar.Basic
import Mathlib.NumberTheory.GaussSum
/-!
# Quadratic characters of finite fields
Further facts relying on Gauss sums.
-/
/-!
### Basic properties of the quadratic character
We prove some properties of the quadratic character.
We work with a finite field `F` here.
The interesting case is when the characteristic of `F` is odd.
-/
section SpecialValues
open ZMod MulChar
variable {F : Type*} [Field F] [Fintype F]
/-- The value of the quadratic character at `2` -/
theorem quadraticChar_two [DecidableEq F] (hF : ringChar F ≠ 2) :
quadraticChar F 2 = χ₈ (Fintype.card F) :=
IsQuadratic.eq_of_eq_coe (quadraticChar_isQuadratic F) isQuadratic_χ₈ hF
((quadraticChar_eq_pow_of_char_ne_two' hF 2).trans (FiniteField.two_pow_card hF))
/-- `2` is a square in `F` iff `#F` is not congruent to `3` or `5` mod `8`. -/
theorem FiniteField.isSquare_two_iff :
IsSquare (2 : F) ↔ Fintype.card F % 8 ≠ 3 ∧ Fintype.card F % 8 ≠ 5 := by
classical
by_cases hF : ringChar F = 2
· have h := FiniteField.even_card_of_char_two hF
simp only [FiniteField.isSquare_of_char_two hF, true_iff]
cutsat
· have h := FiniteField.odd_card_of_char_ne_two hF
rw [← quadraticChar_one_iff_isSquare (Ring.two_ne_zero hF), quadraticChar_two hF,
χ₈_nat_eq_if_mod_eight]
cutsat
/-- The value of the quadratic character at `-2` -/
theorem quadraticChar_neg_two [DecidableEq F] (hF : ringChar F ≠ 2) :
quadraticChar F (-2) = χ₈' (Fintype.card F) := by
rw [(by simp : (-2 : F) = -1 * 2), map_mul, χ₈'_eq_χ₄_mul_χ₈, quadraticChar_neg_one hF,
quadraticChar_two hF, @cast_natCast _ (ZMod 4) _ _ _ (by decide : 4 ∣ 8)]
/-- `-2` is a square in `F` iff `#F` is not congruent to `5` or `7` mod `8`. -/
theorem FiniteField.isSquare_neg_two_iff :
IsSquare (-2 : F) ↔ Fintype.card F % 8 ≠ 5 ∧ Fintype.card F % 8 ≠ 7 := by
classical
by_cases hF : ringChar F = 2
· have h := FiniteField.even_card_of_char_two hF
simp only [FiniteField.isSquare_of_char_two hF, true_iff]
cutsat
· have h := FiniteField.odd_card_of_char_ne_two hF
rw [← quadraticChar_one_iff_isSquare (neg_ne_zero.mpr (Ring.two_ne_zero hF)),
quadraticChar_neg_two hF, χ₈'_nat_eq_if_mod_eight]
cutsat
/-- The relation between the values of the quadratic character of one field `F` at the
cardinality of another field `F'` and of the quadratic character of `F'` at the cardinality
of `F`. -/
theorem quadraticChar_card_card [DecidableEq F] (hF : ringChar F ≠ 2) {F' : Type*} [Field F']
[Fintype F'] [DecidableEq F'] (hF' : ringChar F' ≠ 2) (h : ringChar F' ≠ ringChar F) :
quadraticChar F (Fintype.card F') =
quadraticChar F' (quadraticChar F (-1) * Fintype.card F) := by
let χ := (quadraticChar F).ringHomComp (algebraMap ℤ F')
have hχ₁ : χ ≠ 1 := by
obtain ⟨a, ha⟩ := quadraticChar_exists_neg_one' hF
refine ne_one_iff.mpr ⟨a, ?_⟩
simpa only [ringHomComp_apply, ha, eq_intCast, Int.cast_neg, Int.cast_one, χ] using
Ring.neg_one_ne_one_of_char_ne_two hF'
have h := Char.card_pow_card hχ₁ ((quadraticChar_isQuadratic F).comp _) h hF'
rw [← quadraticChar_eq_pow_of_char_ne_two' hF'] at h
exact (IsQuadratic.eq_of_eq_coe (quadraticChar_isQuadratic F')
(quadraticChar_isQuadratic F) hF' h).symm
/-- The value of the quadratic character at an odd prime `p` different from `ringChar F`. -/
theorem quadraticChar_odd_prime [DecidableEq F] (hF : ringChar F ≠ 2) {p : ℕ} [Fact p.Prime]
(hp₁ : p ≠ 2) (hp₂ : ringChar F ≠ p) :
quadraticChar F p = quadraticChar (ZMod p) (χ₄ (Fintype.card F) * Fintype.card F) := by
rw [← quadraticChar_neg_one hF]
have h := quadraticChar_card_card hF (ne_of_eq_of_ne (ringChar_zmod_n p) hp₁)
(ne_of_eq_of_ne (ringChar_zmod_n p) hp₂.symm)
rwa [card p] at h
/-- An odd prime `p` is a square in `F` iff the quadratic character of `ZMod p` does not
take the value `-1` on `χ₄#F * #F`. -/
theorem FiniteField.isSquare_odd_prime_iff (hF : ringChar F ≠ 2) {p : ℕ} [Fact p.Prime]
(hp : p ≠ 2) :
IsSquare (p : F) ↔ quadraticChar (ZMod p) (χ₄ (Fintype.card F) * Fintype.card F) ≠ -1 := by
classical
rcases eq_or_ne (ringChar F) p with rfl | hFp
· obtain ⟨q, hq, hq'⟩ := FiniteField.card F (ringChar F)
simp [hq']
· rwa [← Iff.not_left quadraticChar_neg_one_iff_not_isSquare, quadraticChar_odd_prime hF hp]
end SpecialValues |
.lake/packages/mathlib/Mathlib/NumberTheory/LegendreSymbol/QuadraticChar/Basic.lean | import Mathlib.Data.Fintype.Parity
import Mathlib.NumberTheory.LegendreSymbol.ZModChar
import Mathlib.FieldTheory.Finite.Basic
/-!
# Quadratic characters of finite fields
This file defines the quadratic character on a finite field `F` and proves
some basic statements about it.
## Tags
quadratic character
-/
/-!
### Definition of the quadratic character
We define the quadratic character of a finite field `F` with values in ℤ.
-/
section Define
/-- Define the quadratic character with values in ℤ on a monoid with zero `α`.
It takes the value zero at zero; for non-zero argument `a : α`, it is `1`
if `a` is a square, otherwise it is `-1`.
This only deserves the name "character" when it is multiplicative,
e.g., when `α` is a finite field. See `quadraticCharFun_mul`.
We will later define `quadraticChar` to be a multiplicative character
of type `MulChar F ℤ`, when the domain is a finite field `F`.
-/
def quadraticCharFun (α : Type*) [MonoidWithZero α] [DecidableEq α]
[DecidablePred (IsSquare : α → Prop)] (a : α) : ℤ :=
if a = 0 then 0 else if IsSquare a then 1 else -1
end Define
/-!
### Basic properties of the quadratic character
We prove some properties of the quadratic character.
We work with a finite field `F` here.
The interesting case is when the characteristic of `F` is odd.
-/
section quadraticChar
open MulChar
variable {F : Type*} [Field F] [Fintype F] [DecidableEq F]
/-- Some basic API lemmas -/
theorem quadraticCharFun_eq_zero_iff {a : F} : quadraticCharFun F a = 0 ↔ a = 0 := by
simp only [quadraticCharFun]
grind
@[simp]
theorem quadraticCharFun_zero : quadraticCharFun F 0 = 0 := by
simp only [quadraticCharFun, if_true]
@[simp]
theorem quadraticCharFun_one : quadraticCharFun F 1 = 1 := by
simp only [quadraticCharFun, one_ne_zero, IsSquare.one, if_true, if_false]
/-- If `ringChar F = 2`, then `quadraticCharFun F` takes the value `1` on nonzero elements. -/
theorem quadraticCharFun_eq_one_of_char_two (hF : ringChar F = 2) {a : F} (ha : a ≠ 0) :
quadraticCharFun F a = 1 := by
simp only [quadraticCharFun, ha, if_false, ite_eq_left_iff]
exact fun h ↦ (h (FiniteField.isSquare_of_char_two hF a)).elim
/-- If `ringChar F` is odd, then `quadraticCharFun F a` can be computed in
terms of `a ^ (Fintype.card F / 2)`. -/
theorem quadraticCharFun_eq_pow_of_char_ne_two (hF : ringChar F ≠ 2) {a : F} (ha : a ≠ 0) :
quadraticCharFun F a = if a ^ (Fintype.card F / 2) = 1 then 1 else -1 := by
simp only [quadraticCharFun, ha, if_false]
simp_rw [FiniteField.isSquare_iff hF ha]
/-- The quadratic character is multiplicative. -/
theorem quadraticCharFun_mul (a b : F) :
quadraticCharFun F (a * b) = quadraticCharFun F a * quadraticCharFun F b := by
by_cases ha : a = 0
· rw [ha, zero_mul, quadraticCharFun_zero, zero_mul]
-- now `a ≠ 0`
by_cases hb : b = 0
· rw [hb, mul_zero, quadraticCharFun_zero, mul_zero]
-- now `a ≠ 0` and `b ≠ 0`
have hab := mul_ne_zero ha hb
by_cases hF : ringChar F = 2
·-- case `ringChar F = 2`
rw [quadraticCharFun_eq_one_of_char_two hF ha, quadraticCharFun_eq_one_of_char_two hF hb,
quadraticCharFun_eq_one_of_char_two hF hab, mul_one]
· -- case of odd characteristic
rw [quadraticCharFun_eq_pow_of_char_ne_two hF ha, quadraticCharFun_eq_pow_of_char_ne_two hF hb,
quadraticCharFun_eq_pow_of_char_ne_two hF hab, mul_pow]
rcases FiniteField.pow_dichotomy hF hb with hb' | hb'
· simp only [hb', mul_one, if_true]
· have h := Ring.neg_one_ne_one_of_char_ne_two hF
-- `-1 ≠ 1`
simp only [hb', mul_neg, mul_one, h, if_false]
rcases FiniteField.pow_dichotomy hF ha with ha' | ha' <;>
simp only [ha', h, neg_neg, if_true, if_false]
variable (F) in
/-- The quadratic character as a multiplicative character. -/
@[simps]
def quadraticChar : MulChar F ℤ where
toFun := quadraticCharFun F
map_one' := quadraticCharFun_one
map_mul' := quadraticCharFun_mul
map_nonunit' a ha := by rw [of_not_not (mt Ne.isUnit ha)]; exact quadraticCharFun_zero
/-- The value of the quadratic character on `a` is zero iff `a = 0`. -/
theorem quadraticChar_eq_zero_iff {a : F} : quadraticChar F a = 0 ↔ a = 0 :=
quadraticCharFun_eq_zero_iff
theorem quadraticChar_zero : quadraticChar F 0 = 0 := by
simp only [quadraticChar_apply, quadraticCharFun_zero]
/-- For nonzero `a : F`, `quadraticChar F a = 1 ↔ IsSquare a`. -/
theorem quadraticChar_one_iff_isSquare {a : F} (ha : a ≠ 0) :
quadraticChar F a = 1 ↔ IsSquare a := by
simp only [quadraticChar_apply, quadraticCharFun, ha, if_false, ite_eq_left_iff,
imp_false, not_not, reduceCtorEq]
/-- The quadratic character takes the value `1` on nonzero squares. -/
theorem quadraticChar_sq_one' {a : F} (ha : a ≠ 0) : quadraticChar F (a ^ 2) = 1 := by
simp only [quadraticChar_apply, quadraticCharFun, sq_eq_zero_iff, ha, IsSquare.sq, if_true,
if_false]
/-- The square of the quadratic character on nonzero arguments is `1`. -/
theorem quadraticChar_sq_one {a : F} (ha : a ≠ 0) : quadraticChar F a ^ 2 = 1 := by
rwa [pow_two, ← map_mul, ← pow_two, quadraticChar_sq_one']
/-- The quadratic character is `1` or `-1` on nonzero arguments. -/
theorem quadraticChar_dichotomy {a : F} (ha : a ≠ 0) :
quadraticChar F a = 1 ∨ quadraticChar F a = -1 :=
sq_eq_one_iff.1 <| quadraticChar_sq_one ha
/-- The quadratic character is `1` or `-1` on nonzero arguments. -/
theorem quadraticChar_eq_neg_one_iff_not_one {a : F} (ha : a ≠ 0) :
quadraticChar F a = -1 ↔ ¬quadraticChar F a = 1 :=
⟨fun h ↦ by rw [h]; cutsat, fun h₂ ↦ (or_iff_right h₂).mp (quadraticChar_dichotomy ha)⟩
/-- For `a : F`, `quadraticChar F a = -1 ↔ ¬ IsSquare a`. -/
theorem quadraticChar_neg_one_iff_not_isSquare {a : F} : quadraticChar F a = -1 ↔ ¬IsSquare a := by
by_cases ha : a = 0
· simp only [ha, MulChar.map_zero, zero_eq_neg, one_ne_zero, IsSquare.zero, not_true]
· rw [quadraticChar_eq_neg_one_iff_not_one ha, quadraticChar_one_iff_isSquare ha]
/-- If `F` has odd characteristic, then `quadraticChar F` takes the value `-1`. -/
theorem quadraticChar_exists_neg_one (hF : ringChar F ≠ 2) : ∃ a, quadraticChar F a = -1 :=
(FiniteField.exists_nonsquare hF).imp fun _ h₁ ↦ quadraticChar_neg_one_iff_not_isSquare.mpr h₁
/-- If `F` has odd characteristic, then `quadraticChar F` takes the value `-1` on some unit. -/
lemma quadraticChar_exists_neg_one' (hF : ringChar F ≠ 2) : ∃ a : Fˣ, quadraticChar F a = -1 := by
refine (fun ⟨a, ha⟩ ↦ ⟨IsUnit.unit ?_, ha⟩) (quadraticChar_exists_neg_one hF)
contrapose ha
exact ne_of_eq_of_ne ((quadraticChar F).map_nonunit ha) (mt zero_eq_neg.mp one_ne_zero)
/-- If `ringChar F = 2`, then `quadraticChar F` takes the value `1` on nonzero elements. -/
theorem quadraticChar_eq_one_of_char_two (hF : ringChar F = 2) {a : F} (ha : a ≠ 0) :
quadraticChar F a = 1 :=
quadraticCharFun_eq_one_of_char_two hF ha
/-- If `ringChar F` is odd, then `quadraticChar F a` can be computed in
terms of `a ^ (Fintype.card F / 2)`. -/
theorem quadraticChar_eq_pow_of_char_ne_two (hF : ringChar F ≠ 2) {a : F} (ha : a ≠ 0) :
quadraticChar F a = if a ^ (Fintype.card F / 2) = 1 then 1 else -1 :=
quadraticCharFun_eq_pow_of_char_ne_two hF ha
theorem quadraticChar_eq_pow_of_char_ne_two' (hF : ringChar F ≠ 2) (a : F) :
(quadraticChar F a : F) = a ^ (Fintype.card F / 2) := by
by_cases ha : a = 0
· have : 0 < Fintype.card F / 2 := Nat.div_pos Fintype.one_lt_card two_pos
simp only [ha, quadraticChar_apply, quadraticCharFun_zero, Int.cast_zero, zero_pow this.ne']
· rw [quadraticChar_eq_pow_of_char_ne_two hF ha]
by_cases ha' : a ^ (Fintype.card F / 2) = 1
· simp only [ha', if_true, Int.cast_one]
· have ha'' := Or.resolve_left (FiniteField.pow_dichotomy hF ha) ha'
simp only [ha'', Int.cast_ite, Int.cast_one, Int.cast_neg, ite_eq_right_iff]
exact Eq.symm
variable (F) in
/-- The quadratic character is quadratic as a multiplicative character. -/
theorem quadraticChar_isQuadratic : (quadraticChar F).IsQuadratic := by
intro a
by_cases ha : a = 0
· left; rw [ha]; exact quadraticChar_zero
· right; exact quadraticChar_dichotomy ha
/-- The quadratic character is nontrivial as a multiplicative character
when the domain has odd characteristic. -/
theorem quadraticChar_ne_one (hF : ringChar F ≠ 2) : quadraticChar F ≠ 1 := by
rcases quadraticChar_exists_neg_one' hF with ⟨a, ha⟩
intro hχ
simp only [hχ, one_apply a.isUnit, reduceCtorEq] at ha
open Finset in
/-- The number of solutions to `x^2 = a` is determined by the quadratic character. -/
theorem quadraticChar_card_sqrts (hF : ringChar F ≠ 2) (a : F) :
#{x : F | x ^ 2 = a}.toFinset = quadraticChar F a + 1 := by
-- we consider the cases `a = 0`, `a` is a nonzero square and `a` is a nonsquare in turn
by_cases h₀ : a = 0
· simp only [h₀, sq_eq_zero_iff, Set.setOf_eq_eq_singleton, Set.toFinset_card,
Set.card_singleton, Int.natCast_succ, Int.ofNat_zero, MulChar.map_zero]
· set s := {x : F | x ^ 2 = a}.toFinset
by_cases h : IsSquare a
· rw [(quadraticChar_one_iff_isSquare h₀).mpr h]
rcases h with ⟨b, h⟩
rw [h, mul_self_eq_zero] at h₀
have h₁ : s = [b, -b].toFinset := by
ext1
rw [← pow_two] at h
simp_rw [s, Set.toFinset_setOf, mem_filter_univ, h, List.toFinset_cons, List.toFinset_nil,
insert_empty_eq, mem_insert, mem_singleton]
exact sq_eq_sq_iff_eq_or_eq_neg
norm_cast
rw [h₁, List.toFinset_cons, List.toFinset_cons, List.toFinset_nil]
exact card_pair (Ne.symm (mt (Ring.eq_self_iff_eq_zero_of_char_ne_two hF).mp h₀))
· rw [quadraticChar_neg_one_iff_not_isSquare.mpr h]
simp only [neg_add_cancel, Int.natCast_eq_zero, card_eq_zero, eq_empty_iff_forall_notMem]
simpa [s, isSquare_iff_exists_sq, eq_comm] using h
/-- The sum over the values of the quadratic character is zero when the characteristic is odd. -/
theorem quadraticChar_sum_zero (hF : ringChar F ≠ 2) : ∑ a : F, quadraticChar F a = 0 :=
sum_eq_zero_of_ne_one (quadraticChar_ne_one hF)
end quadraticChar
/-!
### Special values of the quadratic character
We express `quadraticChar F (-1)` in terms of `χ₄`.
-/
section SpecialValues
open ZMod MulChar
variable {F : Type*} [Field F] [Fintype F]
/-- The value of the quadratic character at `-1` -/
theorem quadraticChar_neg_one [DecidableEq F] (hF : ringChar F ≠ 2) :
quadraticChar F (-1) = χ₄ (Fintype.card F) := by
have h := quadraticChar_eq_pow_of_char_ne_two hF (neg_ne_zero.mpr one_ne_zero)
rw [h, χ₄_eq_neg_one_pow (FiniteField.odd_card_of_char_ne_two hF)]
generalize Fintype.card F / 2 = n
rcases Nat.even_or_odd n with h₂ | h₂
· simp only [Even.neg_one_pow h₂, if_true]
· simp only [Odd.neg_one_pow h₂, Ring.neg_one_ne_one_of_char_ne_two hF, ite_false]
/-- `-1` is a square in `F` iff `#F` is not congruent to `3` mod `4`. -/
theorem FiniteField.isSquare_neg_one_iff : IsSquare (-1 : F) ↔ Fintype.card F % 4 ≠ 3 := by
classical -- suggested by the linter (instead of `[DecidableEq F]`)
by_cases hF : ringChar F = 2
· simp only [FiniteField.isSquare_of_char_two hF, Ne, true_iff]
exact fun hf ↦
one_ne_zero <|
(Nat.odd_of_mod_four_eq_three hf).symm.trans <| FiniteField.even_card_of_char_two hF
· have h₁ := FiniteField.odd_card_of_char_ne_two hF
rw [← quadraticChar_one_iff_isSquare (neg_ne_zero.mpr (one_ne_zero' F)),
quadraticChar_neg_one hF, χ₄_nat_eq_if_mod_four, h₁]
cutsat
end SpecialValues |
.lake/packages/mathlib/Mathlib/NumberTheory/DirichletCharacter/Orthogonality.lean | import Mathlib.FieldTheory.Finite.Basic
import Mathlib.NumberTheory.DirichletCharacter.Basic
import Mathlib.NumberTheory.MulChar.Duality
/-!
# Orthogonality relations for Dirichlet characters
Let `n` be a positive natural number. The main result of this file is
`DirichletCharacter.sum_char_inv_mul_char_eq`, which says that when `a : ZMod n` is a unit
and `b : ZMod n`, then the sum `∑ χ : DirichletCharacter R n, χ a⁻¹ * χ b` vanishes
when `a ≠ b` and has the value `n.totient` otherwise. This requires `R` to have
enough roots of unity (e.g., `R` could be an algebraically closed field of characteristic zero).
-/
namespace DirichletCharacter
-- This is needed to be able to write down sums over characters.
noncomputable instance fintype {R : Type*} [CommRing R] [IsDomain R] {n : ℕ} :
Fintype (DirichletCharacter R n) := .ofFinite _
variable (R : Type*) [CommRing R] (n : ℕ) [NeZero n]
[HasEnoughRootsOfUnity R (Monoid.exponent (ZMod n)ˣ)]
/-- The group of Dirichlet characters mod `n` with values in a ring `R` that has enough
roots of unity is (noncanonically) isomorphic to `(ZMod n)ˣ`. -/
lemma mulEquiv_units : Nonempty (DirichletCharacter R n ≃* (ZMod n)ˣ) :=
MulChar.mulEquiv_units ..
/-- There are `n.totient` Dirichlet characters mod `n` with values in a ring that has enough
roots of unity. -/
lemma card_eq_totient_of_hasEnoughRootsOfUnity :
Nat.card (DirichletCharacter R n) = n.totient := by
rw [← ZMod.card_units_eq_totient n, ← Nat.card_eq_fintype_card]
exact Nat.card_congr (mulEquiv_units R n).some.toEquiv
variable {n}
/-- If `R` is a ring that has enough roots of unity and `n ≠ 0`, then for each
`a ≠ 1` in `ZMod n`, there exists a Dirichlet character `χ` mod `n` with values in `R`
such that `χ a ≠ 1`. -/
theorem exists_apply_ne_one_of_hasEnoughRootsOfUnity [Nontrivial R] ⦃a : ZMod n⦄ (ha : a ≠ 1) :
∃ χ : DirichletCharacter R n, χ a ≠ 1 :=
MulChar.exists_apply_ne_one_of_hasEnoughRootsOfUnity (ZMod n) R ha
variable [IsDomain R]
/-- If `R` is an integral domain that has enough roots of unity and `n ≠ 0`, then
for each `a ≠ 1` in `ZMod n`, the sum of `χ a` over all Dirichlet characters mod `n`
with values in `R` vanishes. -/
theorem sum_characters_eq_zero ⦃a : ZMod n⦄ (ha : a ≠ 1) :
∑ χ : DirichletCharacter R n, χ a = 0 := by
obtain ⟨χ, hχ⟩ := exists_apply_ne_one_of_hasEnoughRootsOfUnity R ha
refine eq_zero_of_mul_eq_self_left hχ ?_
simp only [Finset.mul_sum, ← MulChar.mul_apply]
exact Fintype.sum_bijective _ (Group.mulLeft_bijective χ) _ _ fun χ' ↦ rfl
/-- If `R` is an integral domain that has enough roots of unity and `n ≠ 0`, then
for `a` in `ZMod n`, the sum of `χ a` over all Dirichlet characters mod `n`
with values in `R` vanishes if `a ≠ 1` and has the value `n.totient` if `a = 1`. -/
theorem sum_characters_eq (a : ZMod n) :
∑ χ : DirichletCharacter R n, χ a = if a = 1 then (n.totient : R) else 0 := by
split_ifs with ha
· simpa only [ha, map_one, Finset.sum_const, Finset.card_univ, nsmul_eq_mul, mul_one,
← Nat.card_eq_fintype_card]
using congrArg Nat.cast <| card_eq_totient_of_hasEnoughRootsOfUnity R n
· exact sum_characters_eq_zero R ha
/-- If `R` is an integral domain that has enough roots of unity and `n ≠ 0`, then for `a` and `b`
in `ZMod n` with `a` a unit, the sum of `χ a⁻¹ * χ b` over all Dirichlet characters
mod `n` with values in `R` vanishes if `a ≠ b` and has the value `n.totient` if `a = b`. -/
theorem sum_char_inv_mul_char_eq {a : ZMod n} (ha : IsUnit a) (b : ZMod n) :
∑ χ : DirichletCharacter R n, χ a⁻¹ * χ b = if a = b then (n.totient : R) else 0 := by
simp only [← map_mul, sum_characters_eq, ZMod.inv_mul_eq_one_of_isUnit ha]
end DirichletCharacter |
.lake/packages/mathlib/Mathlib/NumberTheory/DirichletCharacter/GaussSum.lean | import Mathlib.NumberTheory.DirichletCharacter.Basic
import Mathlib.NumberTheory.GaussSum
/-!
# Gauss sums for Dirichlet characters
-/
variable {N : ℕ} [NeZero N] {R : Type*} [CommRing R] (e : AddChar (ZMod N) R)
open AddChar DirichletCharacter
lemma gaussSum_aux_of_mulShift (χ : DirichletCharacter R N) {d : ℕ}
(hd : d ∣ N) (he : e.mulShift d = 1) {u : (ZMod N)ˣ} (hu : ZMod.unitsMap hd u = 1) :
χ u * gaussSum χ e = gaussSum χ e := by
suffices e.mulShift u = e by conv_lhs => rw [← this, gaussSum_mulShift]
rw [(by ring : u.val = (u - 1) + 1), ← mulShift_mul, mulShift_one, mul_eq_right]
rsuffices ⟨a, ha⟩ : (d : ℤ) ∣ (u.val.val - 1 : ℤ)
· have : u.val - 1 = ↑(u.val.val - 1 : ℤ) := by simp only [ZMod.natCast_val, Int.cast_sub,
ZMod.intCast_cast, ZMod.cast_id', id_eq, Int.cast_one]
rw [this, ha]
ext1 y
simpa only [Int.cast_mul, Int.cast_natCast, mulShift_apply, mul_assoc, one_apply]
using DFunLike.ext_iff.mp he (a * y)
rw [← Units.val_inj, Units.val_one, ZMod.unitsMap_def, Units.coe_map] at hu
have : ZMod.castHom hd (ZMod d) u.val = ((u.val.val : ℤ) : ZMod d) := by simp
rwa [MonoidHom.coe_coe, this, ← Int.cast_one, eq_comm,
ZMod.intCast_eq_intCast_iff_dvd_sub] at hu
/-- If `gaussSum χ e ≠ 0`, and `d` is such that `e.mulShift d = 1`, then `χ` must factor through
`d`. (This will be used to show that Gauss sums vanish when `χ` is primitive and `e` is not.) -/
lemma factorsThrough_of_gaussSum_ne_zero [IsDomain R] {χ : DirichletCharacter R N} {d : ℕ}
(hd : d ∣ N) (he : e.mulShift d = 1) (h_ne : gaussSum χ e ≠ 0) :
χ.FactorsThrough d := by
rw [DirichletCharacter.factorsThrough_iff_ker_unitsMap hd]
intro u hu
rw [MonoidHom.mem_ker, ← Units.val_inj, MulChar.coe_toUnitHom]
simpa only [Units.val_one, ne_eq, h_ne, not_false_eq_true, mul_eq_right₀] using
gaussSum_aux_of_mulShift e χ hd he hu
/-- If `χ` is primitive, but `e` is not, then `gaussSum χ e = 0`. -/
lemma gaussSum_eq_zero_of_isPrimitive_of_not_isPrimitive [IsDomain R]
{χ : DirichletCharacter R N} (hχ : IsPrimitive χ) (he : ¬IsPrimitive e) :
gaussSum χ e = 0 := by
contrapose! hχ
rcases e.exists_divisor_of_not_isPrimitive he with ⟨d, hd₁, hd₂, hed⟩
have : χ.conductor ≤ d := Nat.sInf_le <| factorsThrough_of_gaussSum_ne_zero e hd₁ hed hχ
exact (this.trans_lt hd₂).ne
/-- If `χ` is a primitive character, then the function `a ↦ gaussSum χ (e.mulShift a)`, for any
fixed additive character `e`, is a constant multiple of `χ⁻¹`. -/
lemma gaussSum_mulShift_of_isPrimitive [IsDomain R] {χ : DirichletCharacter R N}
(hχ : IsPrimitive χ) (a : ZMod N) :
gaussSum χ (e.mulShift a) = χ⁻¹ a * gaussSum χ e := by
by_cases ha : IsUnit a
· conv_rhs => rw [← gaussSum_mulShift χ e ha.unit]
rw [IsUnit.unit_spec, MulChar.inv_apply_eq_inv, Ring.inverse_mul_cancel_left _ _ (ha.map χ)]
· rw [MulChar.map_nonunit _ ha, zero_mul]
exact gaussSum_eq_zero_of_isPrimitive_of_not_isPrimitive _ hχ (not_isPrimitive_mulShift e ha) |
.lake/packages/mathlib/Mathlib/NumberTheory/DirichletCharacter/Basic.lean | import Mathlib.Algebra.Group.EvenFunction
import Mathlib.Data.ZMod.Units
import Mathlib.NumberTheory.MulChar.Basic
/-!
# Dirichlet Characters
Let `R` be a commutative monoid with zero. A Dirichlet character `χ` of level `n` over `R` is a
multiplicative character from `ZMod n` to `R` sending non-units to 0. We then obtain some properties
of `toUnitHom χ`, the restriction of `χ` to a group homomorphism `(ZMod n)ˣ →* Rˣ`.
Main definitions:
- `DirichletCharacter`: The type representing a Dirichlet character.
- `changeLevel`: Extend the Dirichlet character χ of level `n` to level `m`, where `n` divides `m`.
- `conductor`: The conductor of a Dirichlet character.
- `IsPrimitive`: If the level is equal to the conductor.
## Tags
dirichlet character, multiplicative character
-/
/-!
### Definitions
-/
/-- The type of Dirichlet characters of level `n`. -/
abbrev DirichletCharacter (R : Type*) [CommMonoidWithZero R] (n : ℕ) := MulChar (ZMod n) R
open MulChar
variable {R : Type*} [CommMonoidWithZero R] {n : ℕ} (χ : DirichletCharacter R n)
namespace DirichletCharacter
lemma toUnitHom_eq_char' {a : ZMod n} (ha : IsUnit a) : χ a = χ.toUnitHom ha.unit := by simp
lemma toUnitHom_inj (ψ : DirichletCharacter R n) : toUnitHom χ = toUnitHom ψ ↔ χ = ψ := by simp
lemma eval_modulus_sub (x : ZMod n) : χ (n - x) = χ (-x) := by simp
/-!
### Changing levels
-/
/-- A function that modifies the level of a Dirichlet character to some multiple
of its original level. -/
noncomputable def changeLevel {n m : ℕ} (hm : n ∣ m) :
DirichletCharacter R n →* DirichletCharacter R m where
toFun ψ := MulChar.ofUnitHom (ψ.toUnitHom.comp (ZMod.unitsMap hm))
map_one' := by ext; simp
map_mul' ψ₁ ψ₂ := by ext; simp
lemma changeLevel_def {m : ℕ} (hm : n ∣ m) :
changeLevel hm χ = MulChar.ofUnitHom (χ.toUnitHom.comp (ZMod.unitsMap hm)) := rfl
lemma changeLevel_toUnitHom {m : ℕ} (hm : n ∣ m) :
(changeLevel hm χ).toUnitHom = χ.toUnitHom.comp (ZMod.unitsMap hm) := by
simp [changeLevel]
/-- The `changeLevel` map is injective (except in the degenerate case `m = 0`). -/
lemma changeLevel_injective {m : ℕ} [NeZero m] (hm : n ∣ m) :
Function.Injective (changeLevel (R := R) hm) := by
intro _ _ h
ext1 y
obtain ⟨z, rfl⟩ := ZMod.unitsMap_surjective hm y
rw [MulChar.ext_iff] at h
simpa [changeLevel_def] using h z
@[simp]
lemma changeLevel_eq_one_iff {m : ℕ} {χ : DirichletCharacter R n} (hm : n ∣ m) [NeZero m] :
changeLevel hm χ = 1 ↔ χ = 1 :=
map_eq_one_iff _ (changeLevel_injective hm)
@[simp]
lemma changeLevel_self : changeLevel (dvd_refl n) χ = χ := by
simp [changeLevel, ZMod.unitsMap]
lemma changeLevel_self_toUnitHom : (changeLevel (dvd_refl n) χ).toUnitHom = χ.toUnitHom := by
rw [changeLevel_self]
lemma changeLevel_trans {m d : ℕ} (hm : n ∣ m) (hd : m ∣ d) :
changeLevel (dvd_trans hm hd) χ = changeLevel hd (changeLevel hm χ) := by
simp [changeLevel_def, MonoidHom.comp_assoc, ZMod.unitsMap_comp]
lemma changeLevel_eq_cast_of_dvd {m : ℕ} (hm : n ∣ m) (a : Units (ZMod m)) :
(changeLevel hm χ) a = χ (ZMod.cast (a : ZMod m)) := by
simp [changeLevel_def, ZMod.unitsMap_val]
/-- `χ` of level `n` factors through a Dirichlet character `χ₀` of level `d` if `d ∣ n` and
`χ₀ = χ ∘ (ZMod n → ZMod d)`. -/
def FactorsThrough (d : ℕ) : Prop :=
∃ (h : d ∣ n) (χ₀ : DirichletCharacter R d), χ = changeLevel h χ₀
lemma changeLevel_factorsThrough {m : ℕ} (hm : n ∣ m) : FactorsThrough (changeLevel hm χ) n :=
⟨hm, χ, rfl⟩
namespace FactorsThrough
variable {χ}
/-- The fact that `d` divides `n` when `χ` factors through a Dirichlet character at level `d` -/
lemma dvd {d : ℕ} (h : FactorsThrough χ d) : d ∣ n := h.1
/-- The Dirichlet character at level `d` through which `χ` factors -/
noncomputable
def χ₀ {d : ℕ} (h : FactorsThrough χ d) : DirichletCharacter R d := Classical.choose h.2
/-- The fact that `χ` factors through `χ₀` of level `d` -/
lemma eq_changeLevel {d : ℕ} (h : FactorsThrough χ d) : χ = changeLevel h.dvd h.χ₀ :=
Classical.choose_spec h.2
/-- The character of level `d` through which `χ` factors is uniquely determined. -/
lemma existsUnique {d : ℕ} [NeZero n] (h : FactorsThrough χ d) :
∃! χ' : DirichletCharacter R d, χ = changeLevel h.dvd χ' := by
rcases h with ⟨hd, χ₂, rfl⟩
exact ⟨χ₂, rfl, fun χ₃ hχ₃ ↦ (changeLevel_injective hd hχ₃).symm⟩
variable (χ) in
lemma same_level : FactorsThrough χ n := ⟨dvd_refl n, χ, (changeLevel_self χ).symm⟩
end FactorsThrough
variable {χ} in
/-- A Dirichlet character `χ` factors through `d | n` iff its associated unit-group hom is trivial
on the kernel of `ZMod.unitsMap`. -/
lemma factorsThrough_iff_ker_unitsMap {d : ℕ} [NeZero n] (hd : d ∣ n) :
FactorsThrough χ d ↔ (ZMod.unitsMap hd).ker ≤ χ.toUnitHom.ker := by
refine ⟨fun ⟨_, ⟨χ₀, hχ₀⟩⟩ x hx ↦ ?_, fun h ↦ ?_⟩
· rw [MonoidHom.mem_ker, hχ₀, changeLevel_toUnitHom, MonoidHom.comp_apply, hx, map_one]
· let E := MonoidHom.liftOfSurjective _ (ZMod.unitsMap_surjective hd) ⟨_, h⟩
have hE : E.comp (ZMod.unitsMap hd) = χ.toUnitHom := MonoidHom.liftOfRightInverse_comp ..
refine ⟨hd, MulChar.ofUnitHom E, equivToUnitHom.injective (?_ : toUnitHom _ = toUnitHom _)⟩
simp_rw [changeLevel_toUnitHom, toUnitHom_eq, ofUnitHom_eq, Equiv.apply_symm_apply, hE,
toUnitHom_eq]
/-!
### Edge cases
-/
lemma level_one (χ : DirichletCharacter R 1) : χ = 1 := by
ext
simp [units_eq_one]
lemma level_one' (hn : n = 1) : χ = 1 := by
subst hn
exact level_one _
instance : Subsingleton (DirichletCharacter R 1) := by
refine subsingleton_iff.mpr (fun χ χ' ↦ ?_)
simp [level_one]
noncomputable instance : Unique (DirichletCharacter R 1) := Unique.mk' (DirichletCharacter R 1)
/-- A Dirichlet character of modulus `≠ 1` maps `0` to `0`. -/
lemma map_zero' (hn : n ≠ 1) : χ 0 = 0 :=
have := ZMod.nontrivial_iff.mpr hn; χ.map_zero
lemma changeLevel_one {d : ℕ} (h : d ∣ n) :
changeLevel h (1 : DirichletCharacter R d) = 1 := by
simp
lemma factorsThrough_one_iff : FactorsThrough χ 1 ↔ χ = 1 := by
refine ⟨fun ⟨_, χ₀, hχ₀⟩ ↦ ?_,
fun h ↦ ⟨one_dvd n, 1, by rw [h, changeLevel_one]⟩⟩
rwa [level_one χ₀, changeLevel_one] at hχ₀
/-!
### The conductor
-/
/-- The set of natural numbers `d` such that `χ` factors through a character of level `d`. -/
def conductorSet : Set ℕ := {d : ℕ | FactorsThrough χ d}
lemma mem_conductorSet_iff {x : ℕ} : x ∈ conductorSet χ ↔ FactorsThrough χ x := Iff.refl _
lemma level_mem_conductorSet : n ∈ conductorSet χ := FactorsThrough.same_level χ
lemma mem_conductorSet_dvd {x : ℕ} (hx : x ∈ conductorSet χ) : x ∣ n := hx.dvd
/-- The minimum natural number level `n` through which `χ` factors. -/
noncomputable def conductor : ℕ := sInf (conductorSet χ)
lemma conductor_mem_conductorSet : conductor χ ∈ conductorSet χ :=
Nat.sInf_mem (Set.nonempty_of_mem (level_mem_conductorSet χ))
lemma conductor_dvd_level : conductor χ ∣ n := (conductor_mem_conductorSet χ).dvd
lemma factorsThrough_conductor : FactorsThrough χ (conductor χ) := conductor_mem_conductorSet χ
lemma conductor_ne_zero (hn : n ≠ 0) : conductor χ ≠ 0 :=
fun h ↦ hn <| Nat.eq_zero_of_zero_dvd <| h ▸ conductor_dvd_level _
/-- The conductor of the trivial character is 1. -/
lemma conductor_one (hn : n ≠ 0) : conductor (1 : DirichletCharacter R n) = 1 := by
suffices FactorsThrough (1 : DirichletCharacter R n) 1 by
have h : conductor (1 : DirichletCharacter R n) ≤ 1 :=
Nat.sInf_le <| (mem_conductorSet_iff _).mpr this
exact Nat.le_antisymm h (Nat.pos_of_ne_zero <| conductor_ne_zero _ hn)
exact (factorsThrough_one_iff _).mpr rfl
variable {χ}
lemma eq_one_iff_conductor_eq_one (hn : n ≠ 0) : χ = 1 ↔ conductor χ = 1 := by
refine ⟨fun h ↦ h ▸ conductor_one hn, fun hχ ↦ ?_⟩
obtain ⟨h', χ₀, h⟩ := factorsThrough_conductor χ
exact (level_one' χ₀ hχ ▸ h).trans <| changeLevel_one h'
lemma conductor_eq_zero_iff_level_eq_zero : conductor χ = 0 ↔ n = 0 := by
refine ⟨(conductor_ne_zero χ).mtr, ?_⟩
rintro rfl
exact Nat.sInf_eq_zero.mpr <| Or.inl <| level_mem_conductorSet χ
lemma conductor_le_conductor_mem_conductorSet {d : ℕ} (hd : d ∈ conductorSet χ) :
χ.conductor ≤ (Classical.choose hd.2).conductor := by
refine Nat.sInf_le <| (mem_conductorSet_iff χ).mpr <|
⟨dvd_trans (conductor_dvd_level _) hd.1,
(factorsThrough_conductor (Classical.choose hd.2)).2.choose, ?_⟩
rw [changeLevel_trans _ (conductor_dvd_level _) hd.dvd,
← (factorsThrough_conductor (Classical.choose hd.2)).2.choose_spec]
exact hd.eq_changeLevel
variable (χ)
/-- A character is primitive if its level is equal to its conductor. -/
def IsPrimitive : Prop := conductor χ = n
lemma isPrimitive_def : IsPrimitive χ ↔ conductor χ = n := Iff.rfl
lemma isPrimitive_one_level_one : IsPrimitive (1 : DirichletCharacter R 1) :=
Nat.dvd_one.mp (conductor_dvd_level _)
lemma isPrimitive_one_level_zero : IsPrimitive (1 : DirichletCharacter R 0) :=
conductor_eq_zero_iff_level_eq_zero.mpr rfl
@[deprecated (since := "2025-07-27")] alias isPritive_one_level_zero := isPrimitive_one_level_zero
lemma conductor_one_dvd (n : ℕ) : conductor (1 : DirichletCharacter R 1) ∣ n := by
rw [(isPrimitive_def _).mp isPrimitive_one_level_one]
apply one_dvd _
/-- The primitive character associated to a Dirichlet character. -/
noncomputable def primitiveCharacter : DirichletCharacter R χ.conductor :=
Classical.choose (factorsThrough_conductor χ).choose_spec
lemma primitiveCharacter_isPrimitive : IsPrimitive (χ.primitiveCharacter) := by
by_cases h : χ.conductor = 0
· rw [isPrimitive_def]
convert conductor_eq_zero_iff_level_eq_zero.mpr h
· exact le_antisymm (Nat.le_of_dvd (Nat.pos_of_ne_zero h) (conductor_dvd_level _)) <|
conductor_le_conductor_mem_conductorSet <| conductor_mem_conductorSet χ
lemma primitiveCharacter_one (hn : n ≠ 0) :
(1 : DirichletCharacter R n).primitiveCharacter = 1 := by
rw [eq_one_iff_conductor_eq_one <| (@conductor_one R _ _ hn) ▸ Nat.one_ne_zero,
(isPrimitive_def _).1 (1 : DirichletCharacter R n).primitiveCharacter_isPrimitive,
conductor_one hn]
/-- Dirichlet character associated to multiplication of Dirichlet characters,
after changing both levels to the same -/
noncomputable def mul {m : ℕ} (χ₁ : DirichletCharacter R n) (χ₂ : DirichletCharacter R m) :
DirichletCharacter R (Nat.lcm n m) :=
changeLevel (Nat.dvd_lcm_left n m) χ₁ * changeLevel (Nat.dvd_lcm_right n m) χ₂
/-- Primitive character associated to multiplication of Dirichlet characters,
after changing both levels to the same -/
noncomputable def primitive_mul {m : ℕ} (χ₁ : DirichletCharacter R n)
(χ₂ : DirichletCharacter R m) : DirichletCharacter R (mul χ₁ χ₂).conductor :=
primitiveCharacter (mul χ₁ χ₂)
lemma mul_def {n m : ℕ} {χ : DirichletCharacter R n} {ψ : DirichletCharacter R m} :
χ.primitive_mul ψ = primitiveCharacter (mul χ ψ) :=
rfl
lemma primitive_mul_isPrimitive {m : ℕ} (ψ : DirichletCharacter R m) :
IsPrimitive (primitive_mul χ ψ) :=
primitiveCharacter_isPrimitive _
/-
### Even and odd characters
-/
section CommRing
variable {S : Type*} [CommRing S] {m : ℕ} (ψ : DirichletCharacter S m)
/-- A Dirichlet character is odd if its value at -1 is -1. -/
def Odd : Prop := ψ (-1) = -1
/-- A Dirichlet character is even if its value at -1 is 1. -/
def Even : Prop := ψ (-1) = 1
lemma even_or_odd [NoZeroDivisors S] : ψ.Even ∨ ψ.Odd := by
suffices ψ (-1) ^ 2 = 1 by convert sq_eq_one_iff.mp this
rw [← map_pow _, neg_one_sq, map_one]
lemma not_even_and_odd [NeZero (2 : S)] : ¬(ψ.Even ∧ ψ.Odd) := by
rintro ⟨(h : _ = 1), (h' : _ = -1)⟩
simp only [h', neg_eq_iff_add_eq_zero, one_add_one_eq_two, two_ne_zero] at h
lemma Even.not_odd [NeZero (2 : S)] (hψ : Even ψ) : ¬Odd ψ :=
not_and.mp ψ.not_even_and_odd hψ
lemma Odd.not_even [NeZero (2 : S)] (hψ : Odd ψ) : ¬Even ψ :=
not_and'.mp ψ.not_even_and_odd hψ
lemma Odd.toUnitHom_eval_neg_one (hψ : ψ.Odd) : ψ.toUnitHom (-1) = -1 := by
rw [← Units.val_inj, MulChar.coe_toUnitHom]
exact hψ
lemma Even.toUnitHom_eval_neg_one (hψ : ψ.Even) : ψ.toUnitHom (-1) = 1 := by
rw [← Units.val_inj, MulChar.coe_toUnitHom]
exact hψ
lemma Odd.eval_neg (x : ZMod m) (hψ : ψ.Odd) : ψ (- x) = - ψ x := by
rw [Odd] at hψ
rw [← neg_one_mul, map_mul]
simp [hψ]
lemma Even.eval_neg (x : ZMod m) (hψ : ψ.Even) : ψ (- x) = ψ x := by
rw [Even] at hψ
rw [← neg_one_mul, map_mul]
simp [hψ]
/-- An even Dirichlet character is an even function. -/
lemma Even.to_fun {χ : DirichletCharacter S m} (hχ : Even χ) : Function.Even χ :=
fun _ ↦ by rw [← neg_one_mul, map_mul, hχ, one_mul]
/-- An odd Dirichlet character is an odd function. -/
lemma Odd.to_fun {χ : DirichletCharacter S m} (hχ : Odd χ) : Function.Odd χ :=
fun _ ↦ by rw [← neg_one_mul, map_mul, hχ, neg_one_mul]
end CommRing
end DirichletCharacter |
.lake/packages/mathlib/Mathlib/NumberTheory/DirichletCharacter/Bounds.lean | import Mathlib.Analysis.Normed.Field.Basic
import Mathlib.FieldTheory.Finite.Basic
import Mathlib.NumberTheory.DirichletCharacter.Basic
/-!
# Bounds for values of Dirichlet characters
We consider Dirichlet characters `χ` with values in a normed field `F`.
We show that `‖χ a‖ = 1` if `a` is a unit and `‖χ a‖ ≤ 1` in general.
-/
variable {F : Type*} [NormedField F] {n : ℕ} (χ : DirichletCharacter F n)
namespace DirichletCharacter
/-- The value at a unit of a Dirichlet character with target a normed field has norm `1`. -/
@[simp] lemma unit_norm_eq_one (a : (ZMod n)ˣ) : ‖χ a‖ = 1 := by
refine (pow_eq_one_iff_of_nonneg (norm_nonneg _) (Nat.card_pos (α := (ZMod n)ˣ)).ne').mp ?_
rw [← norm_pow, ← map_pow, ← Units.val_pow_eq_pow_val, pow_card_eq_one', Units.val_one, map_one,
norm_one]
/-- The values of a Dirichlet character with target a normed field have norm bounded by `1`. -/
lemma norm_le_one (a : ZMod n) : ‖χ a‖ ≤ 1 := by
by_cases h : IsUnit a
· exact (χ.unit_norm_eq_one h.unit).le
· rw [χ.map_nonunit h, norm_zero]
exact zero_le_one
end DirichletCharacter |
.lake/packages/mathlib/Mathlib/NumberTheory/Real/GoldenRatio.lean | import Mathlib.Algebra.EuclideanDomain.Basic
import Mathlib.Algebra.LinearRecurrence
import Mathlib.Data.Fin.VecNotation
import Mathlib.Data.Nat.Fib.Basic
import Mathlib.NumberTheory.Real.Irrational
import Mathlib.Tactic.NormNum.NatFib
import Mathlib.Tactic.NormNum.Prime
/-!
# The golden ratio and its conjugate
This file defines the golden ratio `φ := (1 + √5)/2` and its conjugate
`ψ := (1 - √5)/2`, which are the two real roots of `X² - X - 1`.
Along with various computational facts about them, we prove their
irrationality, and we link them to the Fibonacci sequence by proving
Binet's formula.
-/
noncomputable section
open Polynomial
namespace Real
/-- The golden ratio `φ := (1 + √5)/2`. -/
abbrev goldenRatio : ℝ := (1 + √5) / 2
/-- The conjugate of the golden ratio `ψ := (1 - √5)/2`. -/
abbrev goldenConj : ℝ := (1 - √5) / 2
@[inherit_doc] scoped[goldenRatio] notation "φ" => Real.goldenRatio
@[inherit_doc] scoped[goldenRatio] notation "ψ" => Real.goldenConj
open goldenRatio
/-- The inverse of the golden ratio is the opposite of its conjugate. -/
theorem inv_goldenRatio : φ⁻¹ = -ψ := by
grind
@[deprecated (since := "2025-08-23")] alias _root_.inv_gold := inv_goldenRatio
/-- The opposite of the golden ratio is the inverse of its conjugate. -/
theorem inv_goldenConj : ψ⁻¹ = -φ := by
rw [inv_eq_iff_eq_inv, ← neg_inv, ← neg_eq_iff_eq_neg]
exact inv_goldenRatio.symm
@[deprecated (since := "2025-08-23")] alias _root_.inv_goldConj := inv_goldenConj
@[simp]
theorem goldenRatio_mul_goldenConj : φ * ψ = -1 := by
grind
@[deprecated (since := "2025-08-23")] alias _root_.gold_mul_goldConj := goldenRatio_mul_goldenConj
@[simp]
theorem goldenConj_mul_goldenRatio : ψ * φ = -1 := by
rw [mul_comm]
exact goldenRatio_mul_goldenConj
@[deprecated (since := "2025-08-23")] alias _root_.goldConj_mul_gold := goldenConj_mul_goldenRatio
@[simp]
theorem goldenRatio_add_goldenConj : φ + ψ = 1 := by
rw [goldenRatio, goldenConj]
ring
@[deprecated (since := "2025-08-23")] alias _root_.gold_add_goldConj := goldenRatio_add_goldenConj
theorem one_sub_goldenConj : 1 - φ = ψ := by
linarith [goldenRatio_add_goldenConj]
@[deprecated (since := "2025-08-23")] alias _root_.one_sub_goldConj := one_sub_goldenConj
theorem one_sub_goldenRatio : 1 - ψ = φ := by
linarith [goldenRatio_add_goldenConj]
@[deprecated (since := "2025-08-23")] alias _root_.one_sub_gold := one_sub_goldenRatio
@[simp]
theorem goldenRatio_sub_goldenConj : φ - ψ = √5 := by ring
@[deprecated (since := "2025-08-23")] alias _root_.gold_sub_goldConj := goldenRatio_sub_goldenConj
theorem goldenRatio_pow_sub_goldenRatio_pow (n : ℕ) : φ ^ (n + 2) - φ ^ (n + 1) = φ ^ n := by
grind
@[deprecated (since := "2025-08-23")]
alias gold_pow_sub_gold_pow := goldenRatio_pow_sub_goldenRatio_pow
@[simp 1200]
theorem goldenRatio_sq : φ ^ 2 = φ + 1 := by
grind
@[deprecated (since := "2025-08-23")] alias _root_.gold_sq := goldenRatio_sq
@[simp 1200]
theorem goldenConj_sq : ψ ^ 2 = ψ + 1 := by
grind
@[deprecated (since := "2025-08-23")] alias _root_.goldConj_sq := goldenConj_sq
theorem goldenRatio_pos : 0 < φ :=
mul_pos (by apply add_pos <;> norm_num) <| inv_pos.2 zero_lt_two
@[deprecated (since := "2025-08-23")] alias _root_.gold_pos := goldenRatio_pos
theorem goldenRatio_ne_zero : φ ≠ 0 :=
ne_of_gt goldenRatio_pos
@[deprecated (since := "2025-08-23")] alias _root_.gold_ne_zero := goldenRatio_ne_zero
theorem one_lt_goldenRatio : 1 < φ := by
refine lt_of_mul_lt_mul_left ?_ (le_of_lt goldenRatio_pos)
simp [← sq, zero_lt_one]
@[deprecated (since := "2025-08-23")] alias _root_.one_lt_gold := one_lt_goldenRatio
theorem goldenRatio_lt_two : φ < 2 := by calc
(1 + √5) / 2 < (1 + 3) / 2 := by gcongr; rw [sqrt_lt'] <;> norm_num
_ = 2 := by norm_num
@[deprecated (since := "2025-08-23")] alias _root_.gold_lt_two := goldenRatio_lt_two
theorem goldenConj_neg : ψ < 0 := by
linarith [one_sub_goldenConj, one_lt_goldenRatio]
@[deprecated (since := "2025-08-23")] alias _root_.goldConj_neg := goldenConj_neg
theorem goldenConj_ne_zero : ψ ≠ 0 :=
ne_of_lt goldenConj_neg
@[deprecated (since := "2025-08-23")] alias _root_.goldConj_ne_zero := goldenConj_ne_zero
theorem neg_one_lt_goldenConj : -1 < ψ := by
rw [neg_lt, ← inv_goldenRatio]
exact inv_lt_one_of_one_lt₀ one_lt_goldenRatio
@[deprecated (since := "2025-08-23")] alias _root_.neg_one_lt_goldConj := neg_one_lt_goldenConj
/-!
## Irrationality
-/
/-- The golden ratio is irrational. -/
theorem goldenRatio_irrational : Irrational φ := by
have := Nat.Prime.irrational_sqrt (show Nat.Prime 5 by norm_num)
have := this.ratCast_add 1
convert this.ratCast_mul (show (0.5 : ℚ) ≠ 0 by norm_num)
simp
ring
@[deprecated (since := "2025-08-23")] alias _root_.gold_irrational := goldenRatio_irrational
/-- The conjugate of the golden ratio is irrational. -/
theorem goldenConj_irrational : Irrational ψ := by
have := Nat.Prime.irrational_sqrt (show Nat.Prime 5 by norm_num)
have := this.ratCast_sub 1
convert this.ratCast_mul (show (0.5 : ℚ) ≠ 0 by norm_num)
simp
ring
@[deprecated (since := "2025-08-23")] alias _root_.goldConj_irrational := goldenConj_irrational
/-!
## Links with Fibonacci sequence
-/
section Fibrec
variable {α : Type*} [CommSemiring α]
/-- The recurrence relation satisfied by the Fibonacci sequence. -/
def fibRec : LinearRecurrence α where
order := 2
coeffs := ![1, 1]
section Poly
open Polynomial
/-- The characteristic polynomial of `fibRec` is `X² - (X + 1)`. -/
theorem fibRec_charPoly_eq {β : Type*} [CommRing β] :
fibRec.charPoly = X ^ 2 - (X + (1 : β[X])) := by
rw [fibRec, LinearRecurrence.charPoly]
simp [Finset.sum_fin_eq_sum_range, Finset.sum_range_succ', ← smul_X_eq_monomial]
end Poly
/-- As expected, the Fibonacci sequence is a solution of `fibRec`. -/
theorem fib_isSol_fibRec : fibRec.IsSolution (fun x => x.fib : ℕ → α) := by
rw [fibRec]
intro n
simp only
rw [Nat.fib_add_two, add_comm]
simp [Finset.sum_fin_eq_sum_range, Finset.sum_range_succ']
/-- The geometric sequence `fun n ↦ φ^n` is a solution of `fibRec`. -/
theorem geom_goldenRatio_isSol_fibRec : fibRec.IsSolution (φ ^ ·) := by
rw [fibRec.geom_sol_iff_root_charPoly, fibRec_charPoly_eq]
simp
@[deprecated (since := "2025-08-23")]
alias _root_.geom_gold_isSol_fibRec := geom_goldenRatio_isSol_fibRec
/-- The geometric sequence `fun n ↦ ψ^n` is a solution of `fibRec`. -/
theorem geom_goldenConj_isSol_fibRec : fibRec.IsSolution (ψ ^ ·) := by
rw [fibRec.geom_sol_iff_root_charPoly, fibRec_charPoly_eq]
simp
@[deprecated (since := "2025-08-23")]
alias geom_goldConj_isSol_fibRec := geom_goldenConj_isSol_fibRec
end Fibrec
/-- Binet's formula as a function equality. -/
theorem coe_fib_eq' :
(fun n => Nat.fib n : ℕ → ℝ) = fun n => (φ ^ n - ψ ^ n) / √5 := by
rw [fibRec.sol_eq_of_eq_init]
· intro i hi
norm_cast at hi
fin_cases hi
· simp
· simp only [goldenRatio, goldenConj]
ring_nf
rw [mul_inv_cancel₀]; norm_num
· exact fib_isSol_fibRec
· suffices LinearRecurrence.IsSolution fibRec
((fun n ↦ (√5)⁻¹ * φ ^ n) - (fun n ↦ (√5)⁻¹ * ψ ^ n)) by
convert this
rw [Pi.sub_apply]
ring
apply (@fibRec ℝ _).solSpace.sub_mem
· exact Submodule.smul_mem fibRec.solSpace (√5)⁻¹ geom_goldenRatio_isSol_fibRec
· exact Submodule.smul_mem fibRec.solSpace (√5)⁻¹ geom_goldenConj_isSol_fibRec
/-- **Binet's formula** as a dependent equality. -/
theorem coe_fib_eq : ∀ n, (Nat.fib n : ℝ) = (φ ^ n - ψ ^ n) / √5 := by
rw [← funext_iff, Real.coe_fib_eq']
/-- Relationship between the Fibonacci Sequence, Golden Ratio and its conjugate's exponents -/
theorem fib_succ_sub_goldenRatio_mul_fib (n : ℕ) : Nat.fib (n + 1) - φ * Nat.fib n = ψ ^ n := by
repeat rw [coe_fib_eq]
rw [mul_div, div_sub_div_same, mul_sub, ← pow_succ']
ring_nf
have nz : √5 ≠ 0 := by norm_num
rw [← (mul_inv_cancel₀ nz).symm, one_mul]
@[deprecated (since := "2025-08-23")]
alias _root_.fib_golden_conj_exp := fib_succ_sub_goldenRatio_mul_fib
/-- Relationship between the Fibonacci Sequence, Golden Ratio and its exponents -/
lemma goldenRatio_mul_fib_succ_add_fib (n : ℕ) : φ * Nat.fib (n + 1) + Nat.fib n = φ ^ (n + 1) := by
induction n with
| zero => simp
| succ n ih =>
calc
_ = φ * (Nat.fib n) + φ ^ 2 * (Nat.fib (n + 1)) := by
simp only [Nat.fib_add_one (Nat.succ_ne_zero n), Nat.succ_sub_succ_eq_sub, tsub_zero,
Nat.cast_add, goldenRatio_sq]; ring
_ = φ * ((Nat.fib n) + φ * (Nat.fib (n + 1))) := by ring
_ = φ ^ (n + 2) := by rw [add_comm, ih]; ring
@[deprecated (since := "2025-08-23")]
alias _root_.fib_golden_exp' := goldenRatio_mul_fib_succ_add_fib
end Real |
.lake/packages/mathlib/Mathlib/NumberTheory/Real/Irrational.lean | import Mathlib.Algebra.Algebra.Rat
import Mathlib.Data.Nat.Prime.Int
import Mathlib.Data.Rat.Sqrt
import Mathlib.Data.Real.Sqrt
import Mathlib.RingTheory.Algebraic.Basic
import Mathlib.Tactic.IntervalCases
/-!
# Irrational real numbers
In this file we define a predicate `Irrational` on `ℝ`, prove that the `n`-th root of an integer
number is irrational if it is not integer, and that `√(q : ℚ)` is irrational if and only if
`¬IsSquare q ∧ 0 ≤ q`.
We also provide dot-style constructors like `Irrational.add_rat`, `Irrational.rat_sub` etc.
With the `Decidable` instances in this file, is possible to prove `Irrational √n` using `decide`,
when `n` is a numeric literal or cast;
but this only works if you `unseal Nat.sqrt.iter in` before the theorem where you use this proof.
-/
open Rat Real
/-- A real number is irrational if it is not equal to any rational number. -/
def Irrational (x : ℝ) :=
x ∉ Set.range ((↑) : ℚ → ℝ)
theorem irrational_iff_ne_rational (x : ℝ) : Irrational x ↔ ∀ a b : ℤ, b ≠ 0 → x ≠ a / b := by
simp [Irrational, Rat.forall, eq_comm]
theorem Irrational.ne_rational {x : ℝ} (hx : Irrational x) (a b : ℤ) : x ≠ a / b := by
rintro rfl; exact hx ⟨a / b, by simp⟩
/-- A transcendental real number is irrational. -/
theorem Transcendental.irrational {r : ℝ} (tr : Transcendental ℚ r) : Irrational r := by
rintro ⟨a, rfl⟩
exact tr (isAlgebraic_algebraMap a)
/-!
### Irrationality of roots of integer and rational numbers
-/
/-- If `x^n`, `n > 0`, is integer and is not the `n`-th power of an integer, then
`x` is irrational. -/
theorem irrational_nrt_of_notint_nrt {x : ℝ} (n : ℕ) (m : ℤ) (hxr : x ^ n = m)
(hv : ¬∃ y : ℤ, x = y) (hnpos : 0 < n) : Irrational x := by
rintro ⟨⟨N, D, P, C⟩, rfl⟩
rw [← cast_pow] at hxr
have c1 : ((D : ℤ) : ℝ) ≠ 0 := by
rw [Int.cast_ne_zero, Int.natCast_ne_zero]
exact P
have c2 : ((D : ℤ) : ℝ) ^ n ≠ 0 := pow_ne_zero _ c1
rw [mk'_eq_divInt, cast_pow, cast_divInt, div_pow, div_eq_iff_mul_eq c2, ← Int.cast_pow,
← Int.cast_pow, ← Int.cast_mul, Int.cast_inj] at hxr
have hdivn : (D : ℤ) ^ n ∣ N ^ n := Dvd.intro_left m hxr
rw [← Int.dvd_natAbs, ← Int.natCast_pow, Int.natCast_dvd_natCast, Int.natAbs_pow,
Nat.pow_dvd_pow_iff hnpos.ne'] at hdivn
obtain rfl : D = 1 := by rw [← Nat.gcd_eq_right hdivn, C.gcd_eq_one]
refine hv ⟨N, ?_⟩
rw [mk'_eq_divInt, Int.ofNat_one, divInt_one, cast_intCast]
/-- If `x^n = m` is an integer and `n` does not divide the `multiplicity p m`, then `x`
is irrational. -/
theorem irrational_nrt_of_n_not_dvd_multiplicity {x : ℝ} (n : ℕ) {m : ℤ} (hm : m ≠ 0) (p : ℕ)
[hp : Fact p.Prime] (hxr : x ^ n = m)
(hv : multiplicity (p : ℤ) m % n ≠ 0) :
Irrational x := by
rcases Nat.eq_zero_or_pos n with (rfl | hnpos)
· rw [eq_comm, pow_zero, ← Int.cast_one, Int.cast_inj] at hxr
simp [hxr, multiplicity_of_one_right (mt isUnit_iff_dvd_one.1
(mt Int.natCast_dvd_natCast.1 hp.1.not_dvd_one))] at hv
refine irrational_nrt_of_notint_nrt _ _ hxr ?_ hnpos
rintro ⟨y, rfl⟩
rw [← Int.cast_pow, Int.cast_inj] at hxr
subst m
have : y ≠ 0 := by rintro rfl; rw [zero_pow hnpos.ne'] at hm; exact hm rfl
rw [(Int.finiteMultiplicity_iff.2 ⟨by simp [hp.1.ne_one], this⟩).multiplicity_pow
(Nat.prime_iff_prime_int.1 hp.1), Nat.mul_mod_right] at hv
exact hv rfl
theorem irrational_sqrt_of_multiplicity_odd (m : ℤ) (hm : 0 < m) (p : ℕ) [hp : Fact p.Prime]
(Hpv : multiplicity (p : ℤ) m % 2 = 1) :
Irrational (√m) :=
@irrational_nrt_of_n_not_dvd_multiplicity _ 2 _ (Ne.symm (ne_of_lt hm)) p hp
(sq_sqrt (Int.cast_nonneg hm.le)) (by rw [Hpv]; exact one_ne_zero)
@[simp] theorem not_irrational_zero : ¬Irrational 0 := not_not_intro ⟨0, Rat.cast_zero⟩
@[simp] theorem not_irrational_one : ¬Irrational 1 := not_not_intro ⟨1, Rat.cast_one⟩
theorem irrational_sqrt_ratCast_iff_of_nonneg {q : ℚ} (hq : 0 ≤ q) :
Irrational (√q) ↔ ¬IsSquare q := by
refine Iff.not (?_ : Exists _ ↔ Exists _)
constructor
· rintro ⟨y, hy⟩
refine ⟨y, Rat.cast_injective (α := ℝ) ?_⟩
rw [Rat.cast_mul, hy, mul_self_sqrt (Rat.cast_nonneg.2 hq)]
· rintro ⟨q', rfl⟩
exact ⟨|q'|, mod_cast (sqrt_mul_self_eq_abs q').symm⟩
theorem irrational_sqrt_ratCast_iff {q : ℚ} :
Irrational (√q) ↔ ¬IsSquare q ∧ 0 ≤ q := by
obtain hq | hq := le_or_gt 0 q
· simp_rw [irrational_sqrt_ratCast_iff_of_nonneg hq, and_iff_left hq]
· rw [sqrt_eq_zero_of_nonpos (Rat.cast_nonpos.2 hq.le)]
simp_rw [not_irrational_zero, false_iff, not_and, not_le, hq, implies_true]
theorem irrational_sqrt_intCast_iff_of_nonneg {z : ℤ} (hz : 0 ≤ z) :
Irrational (√z) ↔ ¬IsSquare z := by
rw [← Rat.isSquare_intCast_iff, ← irrational_sqrt_ratCast_iff_of_nonneg (mod_cast hz),
Rat.cast_intCast]
theorem irrational_sqrt_intCast_iff {z : ℤ} :
Irrational (√z) ↔ ¬IsSquare z ∧ 0 ≤ z := by
rw [← Rat.cast_intCast, irrational_sqrt_ratCast_iff, Rat.isSquare_intCast_iff,
Int.cast_nonneg_iff]
theorem irrational_sqrt_natCast_iff {n : ℕ} : Irrational (√n) ↔ ¬IsSquare n := by
rw [← Rat.isSquare_natCast_iff, ← irrational_sqrt_ratCast_iff_of_nonneg n.cast_nonneg,
Rat.cast_natCast]
theorem irrational_sqrt_ofNat_iff {n : ℕ} [n.AtLeastTwo] :
Irrational √(ofNat(n)) ↔ ¬IsSquare ofNat(n) :=
irrational_sqrt_natCast_iff
theorem Nat.Prime.irrational_sqrt {p : ℕ} (hp : Nat.Prime p) : Irrational (√p) :=
irrational_sqrt_natCast_iff.mpr hp.not_isSquare
/-- **Irrationality of the Square Root of 2** -/
theorem irrational_sqrt_two : Irrational (√2) := by
simpa using Nat.prime_two.irrational_sqrt
/--
This can be used as
```lean
unseal Nat.sqrt.iter in
example : Irrational √24 := by decide
```
-/
instance {n : ℕ} [n.AtLeastTwo] : Decidable (Irrational √(ofNat(n))) :=
decidable_of_iff' _ irrational_sqrt_ofNat_iff
instance (n : ℕ) : Decidable (Irrational (√n)) :=
decidable_of_iff' _ irrational_sqrt_natCast_iff
instance (z : ℤ) : Decidable (Irrational (√z)) :=
decidable_of_iff' _ irrational_sqrt_intCast_iff
instance (q : ℚ) : Decidable (Irrational (√q)) :=
decidable_of_iff' _ irrational_sqrt_ratCast_iff
/-!
### Dot-style operations on `Irrational`
#### Coercion of a rational/integer/natural number is not irrational
-/
namespace Irrational
variable {x : ℝ}
/-!
#### Irrational number is not equal to a rational/integer/natural number
-/
theorem ne_rat (h : Irrational x) (q : ℚ) : x ≠ q := fun hq => h ⟨q, hq.symm⟩
theorem ne_int (h : Irrational x) (m : ℤ) : x ≠ m := by
rw [← Rat.cast_intCast]
exact h.ne_rat _
theorem ne_nat (h : Irrational x) (m : ℕ) : x ≠ m :=
h.ne_int m
theorem ne_zero (h : Irrational x) : x ≠ 0 := mod_cast h.ne_nat 0
theorem ne_one (h : Irrational x) : x ≠ 1 := by simpa only [Nat.cast_one] using h.ne_nat 1
@[simp] theorem ne_ofNat (h : Irrational x) (n : ℕ) [n.AtLeastTwo] : x ≠ ofNat(n) :=
h.ne_nat n
end Irrational
@[simp]
theorem Rat.not_irrational (q : ℚ) : ¬Irrational q := fun h => h ⟨q, rfl⟩
@[simp]
theorem Int.not_irrational (m : ℤ) : ¬Irrational m := fun h => h.ne_int m rfl
@[simp]
theorem Nat.not_irrational (m : ℕ) : ¬Irrational m := fun h => h.ne_nat m rfl
@[simp] theorem not_irrational_ofNat (n : ℕ) [n.AtLeastTwo] : ¬Irrational ofNat(n) :=
n.not_irrational
namespace Irrational
variable (q : ℚ) {x y : ℝ}
/-!
#### Addition of rational/integer/natural numbers
-/
/-- If `x + y` is irrational, then at least one of `x` and `y` is irrational. -/
theorem add_cases : Irrational (x + y) → Irrational x ∨ Irrational y := by
delta Irrational
contrapose!
rintro ⟨⟨rx, rfl⟩, ⟨ry, rfl⟩⟩
exact ⟨rx + ry, cast_add rx ry⟩
theorem of_ratCast_add (h : Irrational (q + x)) : Irrational x :=
h.add_cases.resolve_left q.not_irrational
theorem ratCast_add (h : Irrational x) : Irrational (q + x) :=
of_ratCast_add (-q) <| by rwa [cast_neg, neg_add_cancel_left]
theorem of_add_ratCast : Irrational (x + q) → Irrational x :=
add_comm (↑q) x ▸ of_ratCast_add q
theorem add_ratCast (h : Irrational x) : Irrational (x + q) :=
add_comm (↑q) x ▸ h.ratCast_add q
theorem of_intCast_add (m : ℤ) (h : Irrational (m + x)) : Irrational x := by
rw [← cast_intCast] at h
exact h.of_ratCast_add m
theorem of_add_intCast (m : ℤ) (h : Irrational (x + m)) : Irrational x :=
of_intCast_add m <| add_comm x m ▸ h
theorem intCast_add (h : Irrational x) (m : ℤ) : Irrational (m + x) := by
rw [← cast_intCast]
exact h.ratCast_add m
theorem add_intCast (h : Irrational x) (m : ℤ) : Irrational (x + m) :=
add_comm (↑m) x ▸ h.intCast_add m
theorem of_natCast_add (m : ℕ) (h : Irrational (m + x)) : Irrational x :=
h.of_intCast_add m
theorem of_add_natCast (m : ℕ) (h : Irrational (x + m)) : Irrational x :=
h.of_add_intCast m
theorem natCast_add (h : Irrational x) (m : ℕ) : Irrational (m + x) :=
h.intCast_add m
theorem add_natCast (h : Irrational x) (m : ℕ) : Irrational (x + m) :=
h.add_intCast m
/-!
#### Negation
-/
theorem of_neg (h : Irrational (-x)) : Irrational x := fun ⟨q, hx⟩ => h ⟨-q, by rw [cast_neg, hx]⟩
protected theorem neg (h : Irrational x) : Irrational (-x) :=
of_neg <| by rwa [neg_neg]
/-!
#### Subtraction of rational/integer/natural numbers
-/
theorem sub_ratCast (h : Irrational x) : Irrational (x - q) := by
simpa only [sub_eq_add_neg, cast_neg] using h.add_ratCast (-q)
theorem ratCast_sub (h : Irrational x) : Irrational (q - x) := by
simpa only [sub_eq_add_neg] using h.neg.ratCast_add q
theorem of_sub_ratCast (h : Irrational (x - q)) : Irrational x :=
of_add_ratCast (-q) <| by simpa only [cast_neg, sub_eq_add_neg] using h
theorem of_ratCast_sub (h : Irrational (q - x)) : Irrational x :=
of_neg (of_ratCast_add q (by simpa only [sub_eq_add_neg] using h))
theorem sub_intCast (h : Irrational x) (m : ℤ) : Irrational (x - m) := by
simpa only [Rat.cast_intCast] using h.sub_ratCast m
theorem intCast_sub (h : Irrational x) (m : ℤ) : Irrational (m - x) := by
simpa only [Rat.cast_intCast] using h.ratCast_sub m
theorem of_sub_intCast (m : ℤ) (h : Irrational (x - m)) : Irrational x :=
of_sub_ratCast m <| by rwa [Rat.cast_intCast]
theorem of_intCast_sub (m : ℤ) (h : Irrational (m - x)) : Irrational x :=
of_ratCast_sub m <| by rwa [Rat.cast_intCast]
theorem sub_natCast (h : Irrational x) (m : ℕ) : Irrational (x - m) :=
h.sub_intCast m
theorem natCast_sub (h : Irrational x) (m : ℕ) : Irrational (m - x) :=
h.intCast_sub m
theorem of_sub_natCast (m : ℕ) (h : Irrational (x - m)) : Irrational x :=
h.of_sub_intCast m
theorem of_natCast_sub (m : ℕ) (h : Irrational (m - x)) : Irrational x :=
h.of_intCast_sub m
/-!
#### Multiplication by rational numbers
-/
theorem mul_cases : Irrational (x * y) → Irrational x ∨ Irrational y := by
delta Irrational
contrapose!
rintro ⟨⟨rx, rfl⟩, ⟨ry, rfl⟩⟩
exact ⟨rx * ry, cast_mul rx ry⟩
theorem of_mul_ratCast (h : Irrational (x * q)) : Irrational x :=
h.mul_cases.resolve_right q.not_irrational
theorem mul_ratCast (h : Irrational x) {q : ℚ} (hq : q ≠ 0) : Irrational (x * q) :=
of_mul_ratCast q⁻¹ <| by rwa [mul_assoc, ← cast_mul, mul_inv_cancel₀ hq, cast_one, mul_one]
theorem of_ratCast_mul : Irrational (q * x) → Irrational x :=
mul_comm x q ▸ of_mul_ratCast q
theorem ratCast_mul (h : Irrational x) {q : ℚ} (hq : q ≠ 0) : Irrational (q * x) :=
mul_comm x q ▸ h.mul_ratCast hq
theorem of_mul_intCast (m : ℤ) (h : Irrational (x * m)) : Irrational x :=
of_mul_ratCast m <| by rwa [cast_intCast]
theorem of_intCast_mul (m : ℤ) (h : Irrational (m * x)) : Irrational x :=
of_ratCast_mul m <| by rwa [cast_intCast]
theorem mul_intCast (h : Irrational x) {m : ℤ} (hm : m ≠ 0) : Irrational (x * m) := by
rw [← cast_intCast]
refine h.mul_ratCast ?_
rwa [Int.cast_ne_zero]
theorem intCast_mul (h : Irrational x) {m : ℤ} (hm : m ≠ 0) : Irrational (m * x) :=
mul_comm x m ▸ h.mul_intCast hm
theorem of_mul_natCast (m : ℕ) (h : Irrational (x * m)) : Irrational x :=
h.of_mul_intCast m
theorem of_natCast_mul (m : ℕ) (h : Irrational (m * x)) : Irrational x :=
h.of_intCast_mul m
theorem mul_natCast (h : Irrational x) {m : ℕ} (hm : m ≠ 0) : Irrational (x * m) :=
h.mul_intCast <| Int.natCast_ne_zero.2 hm
theorem natCast_mul (h : Irrational x) {m : ℕ} (hm : m ≠ 0) : Irrational (m * x) :=
h.intCast_mul <| Int.natCast_ne_zero.2 hm
/-!
#### Inverse
-/
theorem of_inv (h : Irrational x⁻¹) : Irrational x := fun ⟨q, hq⟩ => h <| hq ▸ ⟨q⁻¹, q.cast_inv⟩
protected theorem inv (h : Irrational x) : Irrational x⁻¹ :=
of_inv <| by rwa [inv_inv]
/-!
#### Division
-/
theorem div_cases (h : Irrational (x / y)) : Irrational x ∨ Irrational y :=
h.mul_cases.imp id of_inv
theorem of_ratCast_div (h : Irrational (q / x)) : Irrational x :=
(h.of_ratCast_mul q).of_inv
theorem of_div_ratCast (h : Irrational (x / q)) : Irrational x :=
h.div_cases.resolve_right q.not_irrational
theorem ratCast_div (h : Irrational x) {q : ℚ} (hq : q ≠ 0) : Irrational (q / x) :=
h.inv.ratCast_mul hq
theorem div_ratCast (h : Irrational x) {q : ℚ} (hq : q ≠ 0) : Irrational (x / q) := by
rw [div_eq_mul_inv, ← cast_inv]
exact h.mul_ratCast (inv_ne_zero hq)
theorem of_intCast_div (m : ℤ) (h : Irrational (m / x)) : Irrational x :=
h.div_cases.resolve_left m.not_irrational
theorem of_div_intCast (m : ℤ) (h : Irrational (x / m)) : Irrational x :=
h.div_cases.resolve_right m.not_irrational
theorem intCast_div (h : Irrational x) {m : ℤ} (hm : m ≠ 0) : Irrational (m / x) :=
h.inv.intCast_mul hm
theorem div_intCast (h : Irrational x) {m : ℤ} (hm : m ≠ 0) : Irrational (x / m) := by
rw [← cast_intCast]
refine h.div_ratCast ?_
rwa [Int.cast_ne_zero]
theorem of_natCast_div (m : ℕ) (h : Irrational (m / x)) : Irrational x :=
h.of_intCast_div m
theorem of_div_natCast (m : ℕ) (h : Irrational (x / m)) : Irrational x :=
h.of_div_intCast m
theorem natCast_div (h : Irrational x) {m : ℕ} (hm : m ≠ 0) : Irrational (m / x) :=
h.inv.natCast_mul hm
theorem div_natCast (h : Irrational x) {m : ℕ} (hm : m ≠ 0) : Irrational (x / m) :=
h.div_intCast <| by rwa [Int.natCast_ne_zero]
theorem of_one_div (h : Irrational (1 / x)) : Irrational x :=
of_ratCast_div 1 <| by rwa [cast_one]
/-!
#### Natural and integer power
-/
theorem of_mul_self (h : Irrational (x * x)) : Irrational x :=
h.mul_cases.elim id id
theorem of_pow : ∀ n : ℕ, Irrational (x ^ n) → Irrational x
| 0 => fun h => by
rw [pow_zero] at h
exact (h ⟨1, cast_one⟩).elim
| n + 1 => fun h => by
rw [pow_succ] at h
exact h.mul_cases.elim (of_pow n) id
open Int in
theorem of_zpow : ∀ m : ℤ, Irrational (x ^ m) → Irrational x
| (n : ℕ) => fun h => by
rw [zpow_natCast] at h
exact h.of_pow _
| -[n+1] => fun h => by
rw [zpow_negSucc] at h
exact h.of_inv.of_pow _
end Irrational
section Polynomial
open Polynomial
variable (x : ℝ) (p : ℤ[X])
theorem one_lt_natDegree_of_irrational_root (hx : Irrational x) (p_nonzero : p ≠ 0)
(x_is_root : aeval x p = 0) : 1 < p.natDegree := by
by_contra rid
rcases exists_eq_X_add_C_of_natDegree_le_one (not_lt.1 rid) with ⟨a, b, rfl⟩
clear rid
have : (a : ℝ) * x = -b := by simpa [eq_neg_iff_add_eq_zero] using x_is_root
rcases em (a = 0) with (rfl | ha)
· obtain rfl : b = 0 := by simpa
simp at p_nonzero
· rw [mul_comm, ← eq_div_iff_mul_eq, eq_comm] at this
· refine hx ⟨-b / a, ?_⟩
assumption_mod_cast
· assumption_mod_cast
end Polynomial
section
variable {q : ℚ} {m : ℤ} {n : ℕ} {x : ℝ}
open Irrational
/-!
### Simplification lemmas about operations
-/
@[simp]
theorem irrational_ratCast_add_iff : Irrational (q + x) ↔ Irrational x :=
⟨of_ratCast_add q, ratCast_add q⟩
@[simp]
theorem irrational_intCast_add_iff : Irrational (m + x) ↔ Irrational x :=
⟨of_intCast_add m, fun h => h.intCast_add m⟩
@[simp]
theorem irrational_natCast_add_iff : Irrational (n + x) ↔ Irrational x :=
⟨of_natCast_add n, fun h => h.natCast_add n⟩
@[simp]
theorem irrational_add_ratCast_iff : Irrational (x + q) ↔ Irrational x :=
⟨of_add_ratCast q, add_ratCast q⟩
@[simp]
theorem irrational_add_intCast_iff : Irrational (x + m) ↔ Irrational x :=
⟨of_add_intCast m, fun h => h.add_intCast m⟩
@[simp]
theorem irrational_add_natCast_iff : Irrational (x + n) ↔ Irrational x :=
⟨of_add_natCast n, fun h => h.add_natCast n⟩
@[simp]
theorem irrational_ratCast_sub_iff : Irrational (q - x) ↔ Irrational x :=
⟨of_ratCast_sub q, ratCast_sub q⟩
@[simp]
theorem irrational_intCast_sub_iff : Irrational (m - x) ↔ Irrational x :=
⟨of_intCast_sub m, fun h => h.intCast_sub m⟩
@[simp]
theorem irrational_natCast_sub_iff : Irrational (n - x) ↔ Irrational x :=
⟨of_natCast_sub n, fun h => h.natCast_sub n⟩
@[simp]
theorem irrational_sub_ratCast_iff : Irrational (x - q) ↔ Irrational x :=
⟨of_sub_ratCast q, sub_ratCast q⟩
@[simp]
theorem irrational_sub_intCast_iff : Irrational (x - m) ↔ Irrational x :=
⟨of_sub_intCast m, fun h => h.sub_intCast m⟩
@[simp]
theorem irrational_sub_natCast_iff : Irrational (x - n) ↔ Irrational x :=
⟨of_sub_natCast n, fun h => h.sub_natCast n⟩
@[simp]
theorem irrational_neg_iff : Irrational (-x) ↔ Irrational x :=
⟨of_neg, Irrational.neg⟩
@[simp]
theorem irrational_inv_iff : Irrational x⁻¹ ↔ Irrational x :=
⟨of_inv, Irrational.inv⟩
@[simp]
theorem irrational_ratCast_mul_iff : Irrational (q * x) ↔ q ≠ 0 ∧ Irrational x :=
⟨fun h => ⟨Rat.cast_ne_zero.1 <| left_ne_zero_of_mul h.ne_zero, h.of_ratCast_mul q⟩, fun h =>
h.2.ratCast_mul h.1⟩
@[simp]
theorem irrational_mul_ratCast_iff : Irrational (x * q) ↔ q ≠ 0 ∧ Irrational x := by
rw [mul_comm, irrational_ratCast_mul_iff]
@[simp]
theorem irrational_intCast_mul_iff : Irrational (m * x) ↔ m ≠ 0 ∧ Irrational x := by
rw [← cast_intCast, irrational_ratCast_mul_iff, Int.cast_ne_zero]
@[simp]
theorem irrational_mul_intCast_iff : Irrational (x * m) ↔ m ≠ 0 ∧ Irrational x := by
rw [← cast_intCast, irrational_mul_ratCast_iff, Int.cast_ne_zero]
@[simp]
theorem irrational_natCast_mul_iff : Irrational (n * x) ↔ n ≠ 0 ∧ Irrational x := by
rw [← cast_natCast, irrational_ratCast_mul_iff, Nat.cast_ne_zero]
@[simp]
theorem irrational_mul_natCast_iff : Irrational (x * n) ↔ n ≠ 0 ∧ Irrational x := by
rw [← cast_natCast, irrational_mul_ratCast_iff, Nat.cast_ne_zero]
@[simp]
theorem irrational_ratCast_div_iff : Irrational (q / x) ↔ q ≠ 0 ∧ Irrational x := by
simp [div_eq_mul_inv]
@[simp]
theorem irrational_div_ratCast_iff : Irrational (x / q) ↔ q ≠ 0 ∧ Irrational x := by
rw [div_eq_mul_inv, ← cast_inv, irrational_mul_ratCast_iff, Ne, inv_eq_zero]
@[simp]
theorem irrational_intCast_div_iff : Irrational (m / x) ↔ m ≠ 0 ∧ Irrational x := by
simp [div_eq_mul_inv]
@[simp]
theorem irrational_div_intCast_iff : Irrational (x / m) ↔ m ≠ 0 ∧ Irrational x := by
rw [← cast_intCast, irrational_div_ratCast_iff, Int.cast_ne_zero]
@[simp]
theorem irrational_natCast_div_iff : Irrational (n / x) ↔ n ≠ 0 ∧ Irrational x := by
simp [div_eq_mul_inv]
@[simp]
theorem irrational_div_natCast_iff : Irrational (x / n) ↔ n ≠ 0 ∧ Irrational x := by
rw [← cast_natCast, irrational_div_ratCast_iff, Nat.cast_ne_zero]
/-- There is an irrational number `r` between any two reals `x < r < y`. -/
theorem exists_irrational_btwn {x y : ℝ} (h : x < y) : ∃ r, Irrational r ∧ x < r ∧ r < y :=
let ⟨q, ⟨hq1, hq2⟩⟩ := exists_rat_btwn ((sub_lt_sub_iff_right (√2)).mpr h)
⟨q + √2, irrational_sqrt_two.ratCast_add _, sub_lt_iff_lt_add.mp hq1, lt_sub_iff_add_lt.mp hq2⟩
end |
.lake/packages/mathlib/Mathlib/NumberTheory/Cyclotomic/Rat.lean | import Mathlib.NumberTheory.NumberField.Cyclotomic.Basic
deprecated_module (since := "2025-10-14") |
.lake/packages/mathlib/Mathlib/NumberTheory/Cyclotomic/PID.lean | import Mathlib.NumberTheory.NumberField.Cyclotomic.PID
deprecated_module (since := "2025-10-14") |
.lake/packages/mathlib/Mathlib/NumberTheory/Cyclotomic/Discriminant.lean | import Mathlib.NumberTheory.Cyclotomic.PrimitiveRoots
import Mathlib.RingTheory.DedekindDomain.Dvr
import Mathlib.NumberTheory.NumberField.Discriminant.Defs
/-!
# Discriminant of cyclotomic fields
We compute the discriminant of a `p ^ n`-th cyclotomic extension.
## Main results
* `IsCyclotomicExtension.discr_odd_prime` : if `p` is an odd prime such that
`IsCyclotomicExtension {p} K L` and `Irreducible (cyclotomic p K)`, then
`discr K (hζ.powerBasis K).basis = (-1) ^ ((p - 1) / 2) * p ^ (p - 2)` for any
`hζ : IsPrimitiveRoot ζ p`.
-/
universe u v
open Algebra Polynomial Nat IsPrimitiveRoot PowerBasis
open scoped Polynomial Cyclotomic
namespace IsPrimitiveRoot
variable {n : ℕ} [NeZero n] {K : Type u} [Field K] [CharZero K] {ζ : K}
variable [ce : IsCyclotomicExtension {n} ℚ K]
/-- The discriminant of the power basis given by a primitive root of unity `ζ` is the same as the
discriminant of the power basis given by `ζ - 1`. -/
theorem discr_zeta_eq_discr_zeta_sub_one (hζ : IsPrimitiveRoot ζ n) :
discr ℚ (hζ.powerBasis ℚ).basis = discr ℚ (hζ.subOnePowerBasis ℚ).basis := by
haveI : NumberField K := @NumberField.mk _ _ _ (IsCyclotomicExtension.finiteDimensional {n} ℚ K)
have H₁ : (aeval (hζ.powerBasis ℚ).gen) (X - 1 : ℤ[X]) = (hζ.subOnePowerBasis ℚ).gen := by simp
have H₂ : (aeval (hζ.subOnePowerBasis ℚ).gen) (X + 1 : ℤ[X]) = (hζ.powerBasis ℚ).gen := by simp
refine discr_eq_discr_of_toMatrix_coeff_isIntegral _ (fun i j => toMatrix_isIntegral H₁ ?_ ?_ _ _)
fun i j => toMatrix_isIntegral H₂ ?_ ?_ _ _
· exact hζ.isIntegral (NeZero.pos _)
· refine minpoly.isIntegrallyClosed_eq_field_fractions' (K := ℚ) (hζ.isIntegral (NeZero.pos _))
· exact (hζ.isIntegral (NeZero.pos _)).sub isIntegral_one
· refine minpoly.isIntegrallyClosed_eq_field_fractions' (K := ℚ) ?_
exact (hζ.isIntegral (NeZero.pos _)).sub isIntegral_one
end IsPrimitiveRoot
namespace IsCyclotomicExtension
variable {p : ℕ} {k : ℕ} {K : Type u} {L : Type v} {ζ : L} [Field K] [Field L]
variable [Algebra K L]
/-- If `p` is a prime and `IsCyclotomicExtension {p ^ (k + 1)} K L`, then the discriminant of
`hζ.powerBasis K` is `(-1) ^ ((p ^ (k + 1).totient) / 2) * p ^ (p ^ k * ((p - 1) * (k + 1) - 1))`
if `Irreducible (cyclotomic (p ^ (k + 1)) K))`, and `p ^ (k + 1) ≠ 2`. -/
theorem discr_prime_pow_ne_two [IsCyclotomicExtension {p ^ (k + 1)} K L] [hp : Fact p.Prime]
(hζ : IsPrimitiveRoot ζ (p ^ (k + 1))) (hirr : Irreducible (cyclotomic (p ^ (k + 1)) K))
(hk : p ^ (k + 1) ≠ 2) : discr K (hζ.powerBasis K).basis =
(-1) ^ ((p ^ (k + 1)).totient / 2) * p ^ (p ^ k * ((p - 1) * (k + 1) - 1)) := by
haveI hne := IsCyclotomicExtension.neZero' (p ^ (k + 1)) K L
haveI mf : Module.Finite K L := finiteDimensional {p ^ (k + 1)} K L
haveI se : Algebra.IsSeparable K L := isSeparable {p ^ (k + 1)} K L
rw [discr_powerBasis_eq_norm, finrank L hirr, hζ.powerBasis_gen _,
← hζ.minpoly_eq_cyclotomic_of_irreducible hirr, totient_prime_pow hp.out (succ_pos k),
Nat.add_one_sub_one]
have hp2 : p = 2 → k ≠ 0 := by
rintro rfl rfl
exact absurd rfl hk
congr 1
· rcases eq_or_ne p 2 with (rfl | hp2)
· rcases Nat.exists_eq_succ_of_ne_zero (hp2 rfl) with ⟨k, rfl⟩
rw [succ_sub_succ_eq_sub, tsub_zero, mul_one]; simp only [_root_.pow_succ']
rw [mul_assoc, Nat.mul_div_cancel_left _ zero_lt_two, Nat.mul_div_cancel_left _ zero_lt_two]
cases k
· simp
· simp_rw [_root_.pow_succ', (even_two.mul_right _).neg_one_pow,
((even_two.mul_right _).mul_right _).neg_one_pow]
· have hpo : Odd p := hp.out.odd_of_ne_two hp2
obtain ⟨a, ha⟩ := (hp.out.even_sub_one hp2).two_dvd
rw [ha, mul_left_comm, mul_assoc, Nat.mul_div_cancel_left _ two_pos,
Nat.mul_div_cancel_left _ two_pos, mul_right_comm, pow_mul, (hpo.pow.mul _).neg_one_pow,
pow_mul, hpo.pow.neg_one_pow]
refine Nat.Even.sub_odd ?_ (even_two_mul _) odd_one
rw [mul_left_comm, ← ha]
exact one_le_mul (one_le_pow _ _ hp.1.pos) (succ_le_iff.2 <| tsub_pos_of_lt hp.1.one_lt)
· have H := congr_arg (@derivative K _) (cyclotomic_prime_pow_mul_X_pow_sub_one K p k)
rw [derivative_mul, derivative_sub, derivative_one, sub_zero, derivative_X_pow, C_eq_natCast,
derivative_sub, derivative_one, sub_zero, derivative_X_pow, C_eq_natCast,
hζ.minpoly_eq_cyclotomic_of_irreducible hirr] at H
replace H := congr_arg (fun P => aeval ζ P) H
simp only [aeval_add, aeval_mul, minpoly.aeval, zero_mul, add_zero, aeval_natCast,
map_sub, aeval_one, aeval_X_pow] at H
replace H := congr_arg (Algebra.norm K) H
have hnorm : (norm K) (ζ ^ p ^ k - 1) = (p : K) ^ p ^ k := by
by_cases hp : p = 2
· exact mod_cast hζ.norm_pow_sub_one_eq_prime_pow_of_ne_zero hirr le_rfl (hp2 hp)
· exact mod_cast hζ.norm_pow_sub_one_of_prime_ne_two hirr le_rfl hp
rw [MonoidHom.map_mul, hnorm, MonoidHom.map_mul, ← map_natCast (algebraMap K L),
Algebra.norm_algebraMap, finrank L hirr, ← succ_eq_add_one,
totient_prime_pow hp.out (succ_pos k), Nat.sub_one, Nat.pred_succ] at H
rw [← hζ.minpoly_eq_cyclotomic_of_irreducible hirr, map_pow, hζ.norm_eq_one hk hirr, one_pow,
mul_one, cast_pow, ← pow_mul, ← mul_assoc, mul_comm (k + 1), mul_assoc] at H
have := mul_pos (succ_pos k) (tsub_pos_of_lt hp.out.one_lt)
rw [← succ_pred_eq_of_pos this, mul_succ, pow_add _ _ (p ^ k)] at H
replace H := (mul_left_inj' fun h => ?_).1 H
· simp only [H, mul_comm _ (k + 1)]; norm_cast
· have := hne.1
rw [Nat.cast_pow, Ne, pow_eq_zero_iff (by cutsat)] at this
exact absurd (eq_zero_of_pow_eq_zero h) this
/-- If `p` is a prime and `IsCyclotomicExtension {p ^ (k + 1)} K L`, then the discriminant of
`hζ.powerBasis K` is `(-1) ^ (p ^ k * (p - 1) / 2) * p ^ (p ^ k * ((p - 1) * (k + 1) - 1))`
if `Irreducible (cyclotomic (p ^ (k + 1)) K))`, and `p ^ (k + 1) ≠ 2`. -/
theorem discr_prime_pow_ne_two' [IsCyclotomicExtension {p ^ (k + 1)} K L] [hp : Fact p.Prime]
(hζ : IsPrimitiveRoot ζ (p ^ (k + 1))) (hirr : Irreducible (cyclotomic (p ^ (k + 1)) K))
(hk : p ^ (k + 1) ≠ 2) : discr K (hζ.powerBasis K).basis =
(-1) ^ (p ^ k * (p - 1) / 2) * p ^ (p ^ k * ((p - 1) * (k + 1) - 1)) := by
simpa [totient_prime_pow hp.out (succ_pos k)] using discr_prime_pow_ne_two hζ hirr hk
/-- If `p` is a prime and `IsCyclotomicExtension {p ^ k} K L`, then the discriminant of
`hζ.powerBasis K` is `(-1) ^ ((p ^ k).totient / 2) * p ^ (p ^ (k - 1) * ((p - 1) * k - 1))`
if `Irreducible (cyclotomic (p ^ k) K))`. Beware that in the cases `p ^ k = 1` and `p ^ k = 2`
the formula uses `1 / 2 = 0` and `0 - 1 = 0`. It is useful only to have a uniform result.
See also `IsCyclotomicExtension.discr_prime_pow_eq_unit_mul_pow`. -/
theorem discr_prime_pow [hcycl : IsCyclotomicExtension {p ^ k} K L] [hp : Fact p.Prime]
(hζ : IsPrimitiveRoot ζ (p ^ k)) (hirr : Irreducible (cyclotomic (p ^ k) K)) :
discr K (hζ.powerBasis K).basis =
(-1) ^ ((p ^ k).totient / 2) * p ^ (p ^ (k - 1) * ((p - 1) * k - 1)) := by
rcases k with - | k
· simp only [coe_basis, _root_.pow_zero, powerBasis_gen _ hζ, totient_one, mul_zero,
show 1 / 2 = 0 by rfl, discr, traceMatrix]
have hζone : ζ = 1 := by simpa using hζ
rw [hζ.powerBasis_dim _, hζone, ← (algebraMap K L).map_one,
minpoly.eq_X_sub_C_of_algebraMap_inj _ (algebraMap K L).injective, natDegree_X_sub_C]
simp only [map_one, one_pow, Matrix.det_unique, traceForm_apply, mul_one]
rw [← (algebraMap K L).map_one, trace_algebraMap, finrank _ hirr]
simp
· by_cases hk : p ^ (k + 1) = 2
· obtain rfl : p = 2 := by
rw [← pow_one 2] at hk
exact eq_of_prime_pow_eq (prime_iff.1 hp.out) (prime_iff.1 Nat.prime_two) (succ_pos _) hk
nth_rw 2 [← pow_one 2] at hk
replace hk := Nat.pow_right_injective rfl.le hk
rw [add_eq_right] at hk
subst hk
rw [pow_one] at hζ hcycl
have : natDegree (minpoly K ζ) = 1 := by
rw [hζ.eq_neg_one_of_two_right, show (-1 : L) = algebraMap K L (-1) by simp,
minpoly.eq_X_sub_C_of_algebraMap_inj _ (FaithfulSMul.algebraMap_injective K L)]
exact natDegree_X_sub_C (-1)
rcases Fin.equiv_iff_eq.2 this with ⟨e⟩
rw [← Algebra.discr_reindex K (hζ.powerBasis K).basis e, coe_basis, powerBasis_gen]; norm_num
simp_rw [hζ.eq_neg_one_of_two_right, show (-1 : L) = algebraMap K L (-1) by simp]
convert_to (discr K fun i : Fin 1 ↦ (algebraMap K L) (-1) ^ ↑i) = _
· congr 1
ext i
simp only [map_neg, map_one, Function.comp_apply, Fin.val_eq_zero, _root_.pow_zero]
suffices (e.symm i : ℕ) = 0 by simp [this]
rw [← Nat.lt_one_iff]
convert (e.symm i).2
rw [this]
· simp only [discr, traceMatrix_apply, Matrix.det_unique, Fin.default_eq_zero, Fin.val_zero,
_root_.pow_zero, traceForm_apply, mul_one]
rw [← (algebraMap K L).map_one, trace_algebraMap, finrank _ hirr]; simp
· exact discr_prime_pow_ne_two hζ hirr hk
/-- If `p` is a prime and `IsCyclotomicExtension {p ^ k} K L`, then there are `u : ℤˣ` and
`n : ℕ` such that the discriminant of `hζ.powerBasis K` is `u * p ^ n`. Often this is enough and
less cumbersome to use than `IsCyclotomicExtension.discr_prime_pow`. -/
theorem discr_prime_pow_eq_unit_mul_pow [IsCyclotomicExtension {p ^ k} K L]
[hp : Fact p.Prime] (hζ : IsPrimitiveRoot ζ (p ^ k))
(hirr : Irreducible (cyclotomic (p ^ k) K)) :
∃ (u : ℤˣ) (n : ℕ), discr K (hζ.powerBasis K).basis = u * p ^ n := by
rw [discr_prime_pow hζ hirr]
by_cases heven : Even ((p ^ k).totient / 2)
· exact ⟨1, p ^ (k - 1) * ((p - 1) * k - 1), by rw [heven.neg_one_pow]; simp⟩
· exact ⟨-1, p ^ (k - 1) * ((p - 1) * k - 1), by
rw [(not_even_iff_odd.1 heven).neg_one_pow]; simp⟩
/-- If `p` is an odd prime and `IsCyclotomicExtension {p} K L`, then
`discr K (hζ.powerBasis K).basis = (-1) ^ ((p - 1) / 2) * p ^ (p - 2)` if
`Irreducible (cyclotomic p K)`. -/
theorem discr_odd_prime [IsCyclotomicExtension {p} K L] [hp : Fact p.Prime]
(hζ : IsPrimitiveRoot ζ p) (hirr : Irreducible (cyclotomic p K)) (hodd : p ≠ 2) :
discr K (hζ.powerBasis K).basis = (-1) ^ ((p - 1) / 2) * p ^ (p - 2) := by
have : IsCyclotomicExtension {p ^ (0 + 1)} K L := by
rw [zero_add, pow_one]
infer_instance
have hζ' : IsPrimitiveRoot ζ (p ^ (0 + 1)) := by simpa using hζ
convert discr_prime_pow_ne_two hζ' (by simpa [hirr]) (by simp [hodd]) using 2
· rw [zero_add, pow_one, totient_prime hp.out]
· rw [_root_.pow_zero, one_mul, zero_add, mul_one, Nat.sub_sub]
end IsCyclotomicExtension |
.lake/packages/mathlib/Mathlib/NumberTheory/Cyclotomic/Basic.lean | import Mathlib.RingTheory.Polynomial.Cyclotomic.Roots
import Mathlib.NumberTheory.NumberField.Basic
import Mathlib.FieldTheory.SeparableClosure
import Mathlib.FieldTheory.Galois.Abelian
/-!
# Cyclotomic extensions
Let `A` and `B` be commutative rings with `Algebra A B`. For `S : Set ℕ`, we define a class
`IsCyclotomicExtension S A B` expressing the fact that `B` is obtained from `A` by adding `n`-th
primitive roots of unity, for all nonzero `n ∈ S`.
## Main definitions
* `IsCyclotomicExtension S A B` : means that `B` is obtained from `A` by adding `n`-th primitive
roots of unity, for all nonzero `n ∈ S`.
* `CyclotomicField`: given `n : ℕ` and a field `K`, we define `CyclotomicField n K` as the
splitting field of `cyclotomic n K`. If `n` is nonzero in `K`, it has the instance
`IsCyclotomicExtension {n} K (CyclotomicField n K)`.
* `CyclotomicRing` : if `A` is a domain with fraction field `K` and `n : ℕ`, we define
`CyclotomicRing n A K` as the `A`-subalgebra of `CyclotomicField n K` generated by the roots of
`X ^ n - 1`. If `n` is nonzero in `A`, it has the instance
`IsCyclotomicExtension {n} A (CyclotomicRing n A K)`.
## Main results
* `IsCyclotomicExtension.trans` : if `IsCyclotomicExtension S A B` and
`IsCyclotomicExtension T B C`, then `IsCyclotomicExtension (S ∪ T) A C` if
`Function.Injective (algebraMap B C)`.
* `IsCyclotomicExtension.union_right` : given `IsCyclotomicExtension (S ∪ T) A B`, then
`IsCyclotomicExtension T (adjoin A { b : B | ∃ a : ℕ, a ∈ S ∧ a ≠ 0 ∧ b ^ (a : ℕ) = 1 }) B`.
* `IsCyclotomicExtension.union_left` : given `IsCyclotomicExtension T A B` and `S ⊆ T`, then
`IsCyclotomicExtension S A (adjoin A { b : B | ∃ a : ℕ, a ∈ S ∧ a ≠ 0 ∧ b ^ (a : ℕ) = 1 })`.
* `IsCyclotomicExtension.finite` : if `S` is finite and `IsCyclotomicExtension S A B`, then
`B` is a finite `A`-algebra.
* `IsCyclotomicExtension.numberField` : a finite cyclotomic extension of a number field is a
number field.
* `IsCyclotomicExtension.isSplittingField_X_pow_sub_one` : if `IsCyclotomicExtension {n} K L`,
then `L` is the splitting field of `X ^ n - 1`.
* `IsCyclotomicExtension.splitting_field_cyclotomic` : if `IsCyclotomicExtension {n} K L`,
then `L` is the splitting field of `cyclotomic n K`.
## Implementation details
Our definition of `IsCyclotomicExtension` is very general, to allow rings of any characteristic
and infinite extensions, but it will mainly be used in the case `S = {n}` and for integral domains.
All results are in the `IsCyclotomicExtension` namespace.
Note that some results, for example `IsCyclotomicExtension.trans`,
`IsCyclotomicExtension.finite`, `IsCyclotomicExtension.numberField`,
`IsCyclotomicExtension.finiteDimensional`, `IsCyclotomicExtension.isGalois` and
`CyclotomicField.algebraBase` are lemmas, but they can be made local instances. Some of them are
included in the `Cyclotomic` locale.
-/
open Polynomial Algebra Module Set
universe u v w z
noncomputable section
/-- Given an `A`-algebra `B` and `S : Set ℕ`, we define `IsCyclotomicExtension S A B` requiring
that there is an `n`-th primitive root of unity in `B` for all nonzero `n ∈ S` and that
`B` is generated over `A` by the roots of `X ^ n - 1`. -/
@[mk_iff]
class IsCyclotomicExtension
(S : Set ℕ) (A : Type u) (B : Type v)
[CommRing A] [CommRing B] [Algebra A B] : Prop where
/-- For all nonzero `n ∈ S`, there exists a primitive `n`-th root of unity in `B`. -/
exists_isPrimitiveRoot {S} (A B) {n : ℕ} (ha : n ∈ S) (ha' : n ≠ 0) :
∃ r : B, IsPrimitiveRoot r n
/-- The `n`-th roots of unity, for `n ∈ S` nonzero, generate `B` as an `A`-algebra. -/
adjoin_roots : ∀ x : B, x ∈ adjoin A {b : B | ∃ n : ℕ, n ∈ S ∧ n ≠ 0 ∧ b ^ n = 1}
variable (n : ℕ) [NeZero n] (S T : Set ℕ) (A : Type u) (B : Type v) (K : Type w) (L : Type z)
variable [CommRing A] [CommRing B] [Algebra A B]
variable [Field K] [Field L] [Algebra K L]
namespace IsCyclotomicExtension
section Basic
variable {S B} in
@[deprecated exists_isPrimitiveRoot (since := "2025-05-21")]
theorem exists_prim_root [IsCyclotomicExtension S A B] {n : ℕ} (ha : n ∈ S) (ha' : n ≠ 0) :
∃ r : B, IsPrimitiveRoot r n :=
exists_isPrimitiveRoot A B ha ha'
/-- A reformulation of `IsCyclotomicExtension` that uses `⊤`. -/
theorem iff_adjoin_eq_top :
IsCyclotomicExtension S A B ↔
(∀ n : ℕ, n ∈ S → n ≠ 0 → ∃ r : B, IsPrimitiveRoot r n) ∧
adjoin A {b : B | ∃ n : ℕ, n ∈ S ∧ n ≠ 0 ∧ b ^ n = 1} = ⊤ :=
⟨fun h => ⟨fun _ => h.exists_isPrimitiveRoot, Algebra.eq_top_iff.2 h.adjoin_roots⟩, fun h =>
⟨h.1 _, Algebra.eq_top_iff.1 h.2⟩⟩
/-- A reformulation of `IsCyclotomicExtension` in the case `S` is a singleton. -/
theorem iff_singleton :
IsCyclotomicExtension {n} A B ↔
(∃ r : B, IsPrimitiveRoot r n) ∧ ∀ x, x ∈ adjoin A {b : B | b ^ n = 1} := by
simp [isCyclotomicExtension_iff, NeZero.ne]
instance instSubsingleton [h : IsCyclotomicExtension ∅ A B] : Subsingleton (Subalgebra A B) :=
subsingleton_of_bot_eq_top <| by simpa [Algebra.eq_top_iff, isCyclotomicExtension_iff] using h
theorem eq_self_sdiff_zero :
IsCyclotomicExtension S A B = IsCyclotomicExtension (S \ {0}) A B := by
simp [isCyclotomicExtension_iff, and_assoc]
/-- If `IsCyclotomicExtension {1} A B`, then the image of `A` in `B` equals `B`. -/
theorem singleton_one [h : IsCyclotomicExtension {1} A B] : (⊥ : Subalgebra A B) = ⊤ :=
Algebra.eq_top_iff.2 fun x => by
simpa [adjoin_singleton_one] using ((isCyclotomicExtension_iff _ _ _).1 h).2 x
variable {A B}
/-- If `(⊥ : SubAlgebra A B) = ⊤`, then `IsCyclotomicExtension {0} A B`. -/
theorem singleton_zero_of_bot_eq_top (h : (⊥ : Subalgebra A B) = ⊤) :
IsCyclotomicExtension {0} A B :=
(iff_adjoin_eq_top _ _ _).2 <| by simpa
theorem isCyclotomicExtension_zero_iff :
IsCyclotomicExtension {0} A B ↔ Function.Surjective (algebraMap A B) := by
rw [surjective_algebraMap_iff, eq_comm]
refine ⟨?_, fun h ↦ singleton_zero_of_bot_eq_top h⟩
rw [eq_self_sdiff_zero, sdiff_self, Set.bot_eq_empty, subsingleton_iff_bot_eq_top]
exact fun _ ↦ instSubsingleton A B
variable (A B)
/-- Transitivity of cyclotomic extensions. -/
theorem trans (C : Type w) [CommRing C] [Algebra A C] [Algebra B C] [IsScalarTower A B C]
[hS : IsCyclotomicExtension S A B] [hT : IsCyclotomicExtension T B C]
(h : Function.Injective (algebraMap B C)) : IsCyclotomicExtension (S ∪ T) A C := by
refine ⟨fun hn => ?_, fun x => ?_⟩
· intro hn'
rcases hn with hn | hn
· obtain ⟨b, hb⟩ := ((isCyclotomicExtension_iff _ _ _).1 hS).1 hn hn'
refine ⟨algebraMap B C b, ?_⟩
exact hb.map_of_injective h
· exact ((isCyclotomicExtension_iff _ _ _).1 hT).1 hn hn'
· refine adjoin_induction (hx := ((isCyclotomicExtension_iff T B _).1 hT).2 x)
(fun c ⟨n, hn⟩ => subset_adjoin ⟨n, Or.inr hn.1, hn.2⟩) (fun b => ?_)
(fun x y _ _ hx hy => Subalgebra.add_mem _ hx hy)
fun x y _ _ hx hy => Subalgebra.mul_mem _ hx hy
let f := IsScalarTower.toAlgHom A B C
have hb : f b ∈ (adjoin A {b : B | ∃ a : ℕ, a ∈ S ∧ a ≠ 0 ∧ b ^ a = 1}).map f :=
⟨b, ((isCyclotomicExtension_iff _ _ _).1 hS).2 b, rfl⟩
rw [IsScalarTower.toAlgHom_apply, ← adjoin_image] at hb
refine adjoin_mono (fun y hy => ?_) hb
obtain ⟨b₁, ⟨⟨n, hn⟩, h₁⟩⟩ := hy
exact ⟨n, ⟨mem_union_left T hn.1, hn.2.1, by rw [← h₁, ← map_pow, hn.2.2, map_one]⟩⟩
@[nontriviality]
theorem subsingleton_iff [Subsingleton B] :
IsCyclotomicExtension S A B ↔ S ⊆ {0, 1} := by
have : Subsingleton (Subalgebra A B) := inferInstance
refine ⟨fun ⟨hprim, _⟩ ↦ ?_, fun hS ↦ ?_⟩
· refine subset_pair_iff.mpr fun s hs ↦ or_iff_not_imp_left.mpr fun hs' ↦ ?_
obtain ⟨ζ, hζ⟩ := hprim hs hs'
exact mod_cast hζ.unique (IsPrimitiveRoot.of_subsingleton ζ)
· refine ⟨fun {s} hs hs' ↦ ?_, fun x ↦ by convert (mem_top (R := A) : x ∈ ⊤)⟩
· have : s = 1 := (subset_pair_iff.mp hS s hs).resolve_left hs'
exact ⟨0, this ▸ IsPrimitiveRoot.of_subsingleton 0⟩
/-- If `B` is a cyclotomic extension of `A` given by roots of unity of order in `S ∪ T`, then `B`
is a cyclotomic extension of `adjoin A { b : B | ∃ a : ℕ, a ∈ S ∧ a ≠ 0 ∧ b ^ a = 1 }` given by
roots of unity of order in `T`. -/
theorem union_right [h : IsCyclotomicExtension (S ∪ T) A B] :
IsCyclotomicExtension T (adjoin A {b : B | ∃ a : ℕ, a ∈ S ∧ a ≠ 0 ∧ b ^ a = 1}) B := by
have : {b : B | ∃ n : ℕ, n ∈ S ∪ T ∧ n ≠ 0 ∧ b ^ n = 1} =
{b : B | ∃ n : ℕ, n ∈ S ∧ n ≠ 0 ∧ b ^ n = 1} ∪
{b : B | ∃ n : ℕ, n ∈ T ∧ n ≠ 0 ∧ b ^ n = 1} := by
refine le_antisymm ?_ ?_
· rintro x ⟨n, hn₁ | hn₂, hnpow⟩
· left; exact ⟨n, hn₁, hnpow⟩
· right; exact ⟨n, hn₂, hnpow⟩
· rintro x (⟨n, hn⟩ | ⟨n, hn⟩)
· exact ⟨n, Or.inl hn.1, hn.2⟩
· exact ⟨n, Or.inr hn.1, hn.2⟩
refine ⟨fun hn => ((isCyclotomicExtension_iff _ A _).1 h).1 (mem_union_right S hn), fun b => ?_⟩
replace h := ((isCyclotomicExtension_iff _ _ _).1 h).2 b
rwa [this, adjoin_union_eq_adjoin_adjoin, Subalgebra.mem_restrictScalars] at h
/-- If `B` is a cyclotomic extension of `A` given by roots of unity of order in `T` and `S ⊆ T`,
then `adjoin A { b : B | ∃ a : ℕ, a ∈ S ∧ a ≠ 0 ∧ b ^ a = 1 }` is a cyclotomic extension of `B`
given by roots of unity of order in `S`. -/
theorem union_left [h : IsCyclotomicExtension T A B] (hS : S ⊆ T) :
IsCyclotomicExtension S A (adjoin A {b : B | ∃ a : ℕ, a ∈ S ∧ a ≠ 0 ∧ b ^ a = 1}) := by
refine ⟨fun {n} hn hn' => ?_, fun b => ?_⟩
· obtain ⟨b, hb⟩ := ((isCyclotomicExtension_iff _ _ _).1 h).1 (hS hn) hn'
refine ⟨⟨b, subset_adjoin ⟨n, hn, hn', hb.pow_eq_one⟩⟩, ?_⟩
rwa [← IsPrimitiveRoot.coe_submonoidClass_iff, Subtype.coe_mk]
· convert mem_top (R := A) (x := b)
rw [← adjoin_adjoin_coe_preimage, preimage_setOf_eq]
norm_cast
variable {n S}
/-- If there exists a nonzero `s ∈ S` such that `n ∣ s`, then `IsCyclotomicExtension S A B`
implies `IsCyclotomicExtension (S ∪ {n}) A B`. -/
theorem of_union_of_dvd (h : ∃ s ∈ S, s ≠ 0 ∧ n ∣ s) [H : IsCyclotomicExtension S A B] :
IsCyclotomicExtension (S ∪ {n}) A B := by
refine (iff_adjoin_eq_top _ A _).2 ⟨fun s hs hs' ↦ ?_, ?_⟩
· rw [mem_union, mem_singleton_iff] at hs
obtain hs | rfl := hs
· exact H.exists_isPrimitiveRoot hs hs'
· obtain ⟨m, hm, hm', ⟨x, rfl⟩⟩ := h
obtain ⟨ζ, hζ⟩ := H.exists_isPrimitiveRoot hm hm'
refine ⟨ζ ^ x, ?_⟩
have h_xnz : x ≠ 0 := Nat.ne_zero_of_mul_ne_zero_right hm'
have := hζ.pow_of_dvd h_xnz (dvd_mul_left x s)
rwa [mul_div_cancel_right₀ _ h_xnz] at this
· refine _root_.eq_top_iff.2 ?_
rw [← ((iff_adjoin_eq_top S A B).1 H).2]
refine adjoin_mono fun x hx ↦ ?_
simp only [union_singleton, mem_insert_iff, mem_setOf_eq] at hx ⊢
obtain ⟨m, hm, hm'⟩ := hx
exact ⟨m, ⟨Or.inr hm, hm'⟩⟩
/-- If there exists a nonzero `s ∈ S` such that `n ∣ s`, then `IsCyclotomicExtension S A B`
if and only if `IsCyclotomicExtension (S ∪ {n}) A B`. -/
theorem iff_union_of_dvd (h : ∃ s ∈ S, s ≠ 0 ∧ n ∣ s) :
IsCyclotomicExtension S A B ↔ IsCyclotomicExtension (S ∪ {n}) A B := by
refine
⟨fun H ↦ of_union_of_dvd A B h, fun H => (iff_adjoin_eq_top _ A _).2
⟨fun s hs ↦ ?_, ?_⟩⟩
· exact H.exists_isPrimitiveRoot (subset_union_left hs)
· rw [_root_.eq_top_iff, ← ((iff_adjoin_eq_top _ A B).1 H).2]
refine adjoin_mono fun x hx => ?_
simp only [union_singleton, mem_insert_iff, mem_setOf_eq] at hx ⊢
obtain ⟨m, rfl | hm, hxpow⟩ := hx
· obtain ⟨y, ⟨hy, hy', ⟨z, rfl⟩⟩⟩ := h
exact ⟨_, ⟨hy, hy', by simp only [pow_mul, hxpow, one_pow]⟩⟩
· exact ⟨m, ⟨hm, hxpow⟩⟩
variable (n S)
/-- `IsCyclotomicExtension S A B` is equivalent to `IsCyclotomicExtension (S ∪ {1}) A B`. -/
theorem iff_union_singleton_one :
IsCyclotomicExtension S A B ↔ IsCyclotomicExtension (S ∪ {1}) A B := by
by_cases hS : ∃ s ∈ S, s ≠ 0
· exact iff_union_of_dvd _ _ (by simpa)
· rw [eq_self_sdiff_zero S, eq_self_sdiff_zero (S ∪ {1}), union_diff_distrib,
show S \ {0} = ∅ by aesop, empty_union, show {1} \ {0} = {1} by simp]
refine ⟨fun H ↦ ?_, fun H ↦ ?_⟩
· refine (iff_adjoin_eq_top _ A _).2 ⟨fun s hs _ ↦ ⟨1, by simp [mem_singleton_iff.1 hs]⟩, ?_⟩
simpa [adjoin_singleton_one] using subsingleton_iff_bot_eq_top.mpr inferInstance
· refine (iff_adjoin_eq_top _ A _).2 ⟨fun s hs ↦ (notMem_empty s hs).elim, ?_⟩
simp [singleton_one]
variable {A B}
/-- If `(⊥ : SubAlgebra A B) = ⊤`, then `IsCyclotomicExtension {1} A B`. -/
theorem singleton_one_of_bot_eq_top (h : (⊥ : Subalgebra A B) = ⊤) :
IsCyclotomicExtension {1} A B := by
convert eq_self_sdiff_zero _ A B ▸
(iff_union_singleton_one _ A _).1 (singleton_zero_of_bot_eq_top h)
simp
/-- If `Function.Surjective (algebraMap A B)`, then `IsCyclotomicExtension {1} A B`. -/
theorem singleton_one_of_algebraMap_bijective (h : Function.Surjective (algebraMap A B)) :
IsCyclotomicExtension {1} A B :=
singleton_one_of_bot_eq_top (surjective_algebraMap_iff.1 h).symm
variable (A B)
/-- Given `(f : B ≃ₐ[A] C)`, if `IsCyclotomicExtension S A B` then
`IsCyclotomicExtension S A C`. -/
protected
theorem equiv {C : Type*} [CommRing C] [Algebra A C] [h : IsCyclotomicExtension S A B]
(f : B ≃ₐ[A] C) : IsCyclotomicExtension S A C := by
letI : Algebra B C := f.toAlgHom.toRingHom.toAlgebra
haveI : IsCyclotomicExtension {1} B C := singleton_one_of_algebraMap_bijective f.surjective
haveI : IsScalarTower A B C := IsScalarTower.of_algHom f.toAlgHom
exact (iff_union_singleton_one _ _ _).2 (trans S {1} A B C f.injective)
theorem neZero_of_mem [IsCyclotomicExtension S A B] [IsDomain B] (hn : n ∈ S) : NeZero (n : B) :=
(exists_isPrimitiveRoot A B hn NeZero.out).choose_spec.neZero'
theorem neZero_of_mem' [IsCyclotomicExtension S A B] [IsDomain B] (hn : n ∈ S) : NeZero (n : A) :=
(neZero_of_mem n S A B hn).nat_of_neZero (algebraMap A B)
protected
theorem neZero [IsCyclotomicExtension {n} A B] [IsDomain B] : NeZero (n : B) :=
neZero_of_mem n {n} A B (mem_singleton n)
protected
theorem neZero' [IsCyclotomicExtension {n} A B] [IsDomain B] : NeZero (n : A) :=
neZero_of_mem' n {n} A B (mem_singleton n)
/-- A cyclotomic extension is integral. -/
theorem integral [IsCyclotomicExtension S A B] : Algebra.IsIntegral A B := by
rw [← (Subalgebra.equivOfEq _ _ ((IsCyclotomicExtension.iff_adjoin_eq_top S A B).1 ‹_›).2
|>.trans Subalgebra.topEquiv).isIntegral_iff]
exact Algebra.IsIntegral.adjoin fun x ⟨n, hn, h1, h2⟩ ↦
⟨X ^ n - 1, monic_X_pow_sub_C 1 h1, by simp [h2]⟩
theorem _root_.Algebra.isCyclotomicExtension_adjoin_of_exists_isPrimitiveRoot
(h : ∀ n ∈ S, n ≠ 0 → ∃ r : B, IsPrimitiveRoot r n) :
IsCyclotomicExtension S A (adjoin A {b : B | ∃ n ∈ S, n ≠ 0 ∧ b ^ n = 1}) where
exists_isPrimitiveRoot {n} hn1 hn2 := by
obtain ⟨r, hr1, hr2⟩ := h n hn1 hn2
exact ⟨⟨r, subset_adjoin ⟨n, hn1, hn2, hr1⟩⟩, Subtype.val_injective hr1,
fun l hl ↦ hr2 l congr($hl.1)⟩
adjoin_roots := by
rintro ⟨x, hx⟩
induction hx using adjoin_induction with
| mem x hx =>
obtain ⟨n, hn1, hn2, hx⟩ := hx
exact subset_adjoin ⟨n, hn1, hn2, Subtype.val_injective hx⟩
| algebraMap x => exact Subalgebra.algebraMap_mem _ x
| add x y hx hy ihx ihy => exact Subalgebra.add_mem _ ihx ihy
| mul x y hx hy ihx ihy => exact Subalgebra.mul_mem _ ihx ihy
/-- Two elements in the Galois group of a cyclotomic extension are equal if
their actions on primitive roots are equal. -/
theorem algEquiv_eq_of_apply_eq [IsCyclotomicExtension S A B] [IsDomain B] {f g : B ≃ₐ[A] B}
(H : ∀ n ∈ S, n ≠ 0 → ∃ r : B, IsPrimitiveRoot r n ∧ f r = g r) : f = g := by
ext x
have hx := ‹IsCyclotomicExtension S A B›.adjoin_roots x
induction hx using Algebra.adjoin_induction with
| mem y hy =>
obtain ⟨n, hn, h1, h2⟩ := hy
obtain ⟨r, hr1, hr2⟩ := H n hn h1
have := NeZero.mk h1
obtain ⟨m, -, rfl⟩ := hr1.eq_pow_of_pow_eq_one h2
simp [hr2]
| algebraMap y => simp
| add x y hx hy ihx ihy => simp [ihx, ihy]
| mul x y hx hy ihx ihy => simp [ihx, ihy]
/-- Cyclotomic extensions are abelian. -/
theorem isMulCommutative [IsCyclotomicExtension S A B] [IsDomain B] :
IsMulCommutative (B ≃ₐ[A] B) := by
refine ⟨⟨fun f g ↦ algEquiv_eq_of_apply_eq S A B fun n hn h1 ↦ ?_⟩⟩
obtain ⟨r, hr⟩ := ‹IsCyclotomicExtension S A B›.exists_isPrimitiveRoot hn h1
use r, hr
simp only [AlgEquiv.mul_apply]
have := NeZero.mk h1
obtain ⟨mf, -, hf⟩ := hr.eq_pow_of_pow_eq_one (show f r ^ n = 1 by rw [← map_pow, hr.1, map_one])
obtain ⟨mg, -, hg⟩ := hr.eq_pow_of_pow_eq_one (show g r ^ n = 1 by rw [← map_pow, hr.1, map_one])
simp [← hf, ← hg, ← pow_mul, mul_comm mf mg]
end Basic
section Fintype
theorem finite_of_singleton [IsDomain B] [h : IsCyclotomicExtension {n} A B] :
Module.Finite A B := by
classical
rw [Module.finite_def, ← top_toSubmodule, ← ((iff_adjoin_eq_top _ _ _).1 h).2]
refine fg_adjoin_of_finite ?_ fun b ⟨n, hb⟩ => ?_
· simp only [mem_singleton_iff, exists_eq_left]
have : {b : B | n ≠ 0 ∧ b ^ n = 1} = (nthRoots n (1 : B)).toFinset :=
Set.ext fun x ↦ ⟨fun h ↦ by simpa [n.pos_of_neZero] using h.2,
fun h ↦ by simpa [n.pos_of_neZero, NeZero.ne n] using h⟩
rw [this]
exact (nthRoots n 1).toFinset.finite_toSet
· simp only [mem_singleton_iff] at hb
exact ⟨X ^ n - 1,
⟨monic_X_pow_sub_C _ (hb.1 ▸ NeZero.ne _), by simpa [sub_eq_zero] using hb.2.2⟩⟩
/-- If `S` is finite and `IsCyclotomicExtension S A B`, then `B` is a finite `A`-algebra. -/
protected theorem finite [IsDomain B] [h₁ : Finite S] [h₂ : IsCyclotomicExtension S A B] :
Module.Finite A B := by
rw [finite_coe_iff] at h₁
induction S, h₁ using Set.Finite.induction_on generalizing h₂ A B with
| empty =>
refine Module.finite_def.2 ⟨({1} : Finset B), ?_⟩
simp [← top_toSubmodule, ← subsingleton_iff_bot_eq_top.mpr inferInstance,
toSubmodule_bot, Submodule.one_eq_span]
| @insert n S _ _ H =>
by_cases hn : n = 0
· have : insert n S \ {0} = S \ {0} := by simp_all
rw [eq_self_sdiff_zero, this, ← eq_self_sdiff_zero] at h₂
exact H A B
have : IsCyclotomicExtension S A (adjoin A {b : B | ∃ n : ℕ, n ∈ S ∧ n ≠ 0 ∧ b ^ n = 1}) :=
union_left _ (insert n S) _ _ (subset_insert n S)
have := H A (adjoin A {b : B | ∃ n : ℕ, n ∈ S ∧ n ≠ 0 ∧ b ^ n = 1})
have : Module.Finite (adjoin A {b : B | ∃ n : ℕ, n ∈ S ∧ n ≠ 0 ∧ b ^ n = 1}) B := by
rw [← union_singleton] at h₂
let _ := union_right S {n} A B
have : NeZero n := ⟨hn⟩
exact finite_of_singleton n _ _
exact Module.Finite.trans (adjoin A {b : B | ∃ n : ℕ, n ∈ S ∧ n ≠ 0 ∧ b ^ n = 1}) _
/-- A cyclotomic finite extension of a number field is a number field. -/
theorem numberField [h : NumberField K] [Finite S] [IsCyclotomicExtension S K L] : NumberField L :=
{ to_charZero := charZero_of_injective_algebraMap (algebraMap K L).injective
to_finiteDimensional := by
haveI := charZero_of_injective_algebraMap (algebraMap K L).injective
haveI := IsCyclotomicExtension.finite S K L
exact Module.Finite.trans K _ }
/-- If `S` is finite and `IsCyclotomicExtension S K A`, then `finiteDimensional K A`. -/
theorem finiteDimensional (C : Type z) [Finite S] [CommRing C] [Algebra K C] [IsDomain C]
[IsCyclotomicExtension S K C] : FiniteDimensional K C :=
IsCyclotomicExtension.finite S K C
end Fintype
section
variable {A B}
theorem adjoin_roots_cyclotomic_eq_adjoin_nth_roots [IsDomain B] {ζ : B} {n : ℕ} [NeZero n]
(hζ : IsPrimitiveRoot ζ n) :
adjoin A ((cyclotomic n A).rootSet B) =
adjoin A {b : B | ∃ a : ℕ, a ∈ ({n} : Set ℕ) ∧ a ≠ 0 ∧ b ^ a = 1} := by
simp only [mem_singleton_iff, exists_eq_left]
refine le_antisymm (adjoin_mono fun x hx => ?_) (adjoin_le fun x hx => ?_)
· rw [mem_rootSet'] at hx
simp only [mem_setOf_eq]
rw [isRoot_of_unity_iff (NeZero.pos n)]
refine ⟨NeZero.ne n, n, Nat.mem_divisors_self n (NeZero.ne n), ?_⟩
rw [IsRoot.def, ← map_cyclotomic n (algebraMap A B), eval_map, ← aeval_def]
exact hx.2
· simp only [mem_setOf_eq] at hx
obtain ⟨i, _, rfl⟩ := hζ.eq_pow_of_pow_eq_one hx.2
refine SetLike.mem_coe.2 (Subalgebra.pow_mem _ (subset_adjoin ?_) _)
rw [mem_rootSet', map_cyclotomic, aeval_def, ← eval_map, map_cyclotomic, ← IsRoot]
exact ⟨cyclotomic_ne_zero n B, hζ.isRoot_cyclotomic (NeZero.pos n)⟩
theorem adjoin_roots_cyclotomic_eq_adjoin_root_cyclotomic {n : ℕ} [NeZero n] [IsDomain B] {ζ : B}
(hζ : IsPrimitiveRoot ζ n) : adjoin A ((cyclotomic n A).rootSet B) = adjoin A {ζ} := by
refine le_antisymm (adjoin_le fun x hx => ?_) (adjoin_mono fun x hx => ?_)
· suffices hx : x ^ n = 1 by
obtain ⟨i, _, rfl⟩ := hζ.eq_pow_of_pow_eq_one hx
exact SetLike.mem_coe.2 (Subalgebra.pow_mem _ (subset_adjoin <| mem_singleton ζ) _)
refine (isRoot_of_unity_iff (NeZero.pos n) B).2 ?_
refine ⟨n, Nat.mem_divisors_self n (NeZero.ne n), ?_⟩
rw [mem_rootSet', aeval_def, ← eval_map, map_cyclotomic, ← IsRoot] at hx
exact hx.2
· simp only [mem_singleton_iff] at hx
simpa only [hx, mem_rootSet', map_cyclotomic, aeval_def, ← eval_map, IsRoot] using
And.intro (cyclotomic_ne_zero n B) (hζ.isRoot_cyclotomic (NeZero.pos n))
theorem adjoin_primitive_root_eq_top {n : ℕ} [NeZero n] [IsDomain B]
[h : IsCyclotomicExtension {n} A B]
{ζ : B} (hζ : IsPrimitiveRoot ζ n) : adjoin A ({ζ} : Set B) = ⊤ := by
classical
rw [← adjoin_roots_cyclotomic_eq_adjoin_root_cyclotomic hζ]
rw [adjoin_roots_cyclotomic_eq_adjoin_nth_roots hζ]
exact ((iff_adjoin_eq_top {n} A B).mp h).2
variable (A)
theorem _root_.IsPrimitiveRoot.adjoin_isCyclotomicExtension {ζ : B} {n : ℕ} [NeZero n]
(h : IsPrimitiveRoot ζ n) : IsCyclotomicExtension {n} A (adjoin A ({ζ} : Set B)) :=
{ exists_isPrimitiveRoot := fun hi hi' => by
rw [Set.mem_singleton_iff] at hi
refine ⟨⟨ζ, subset_adjoin <| Set.mem_singleton ζ⟩, ?_⟩
rwa [← IsPrimitiveRoot.coe_submonoidClass_iff, Subtype.coe_mk, hi]
adjoin_roots := fun ⟨x, hx⟩ => by
refine
adjoin_induction
(hx := hx) (fun b hb => ?_) (fun a => ?_) (fun b₁ b₂ _ _ hb₁ hb₂ => ?_)
(fun b₁ b₂ _ _ hb₁ hb₂ => ?_)
· rw [Set.mem_singleton_iff] at hb
refine subset_adjoin ?_
simp only [mem_singleton_iff, exists_eq_left, mem_setOf_eq, hb]
rw [← Subalgebra.coe_eq_one, Subalgebra.coe_pow, Subtype.coe_mk]
exact ⟨NeZero.ne n, ((IsPrimitiveRoot.iff_def ζ n).1 h).1⟩
· exact Subalgebra.algebraMap_mem _ _
· exact Subalgebra.add_mem _ hb₁ hb₂
· exact Subalgebra.mul_mem _ hb₁ hb₂ }
variable {L} in
theorem _root_.IsPrimitiveRoot.intermediateField_adjoin_isCyclotomicExtension
[Algebra.IsIntegral K L] {n : ℕ} [NeZero n] {ζ : L} (hζ : IsPrimitiveRoot ζ n) :
IsCyclotomicExtension {n} K (IntermediateField.adjoin K {ζ}) := by
change IsCyclotomicExtension {n} K (IntermediateField.adjoin K {ζ}).toSubalgebra
rw [IntermediateField.adjoin_simple_toSubalgebra_of_integral (IsIntegral.isIntegral ζ)]
exact hζ.adjoin_isCyclotomicExtension K
end
section Field
variable {n S}
/-- A cyclotomic extension splits `X ^ n - 1` if `n ∈ S`. -/
theorem splits_X_pow_sub_one [H : IsCyclotomicExtension S K L] (hS : n ∈ S) :
Splits (algebraMap K L) (X ^ n - 1) := by
rw [← splits_id_iff_splits, Polynomial.map_sub, Polynomial.map_one, Polynomial.map_pow,
Polynomial.map_X]
obtain ⟨z, hz⟩ := ((isCyclotomicExtension_iff _ _ _).1 H).1 hS (NeZero.ne _)
exact X_pow_sub_one_splits hz
/-- A cyclotomic extension splits `cyclotomic n K` if `n ∈ S`. -/
theorem splits_cyclotomic [IsCyclotomicExtension S K L] (hS : n ∈ S) :
Splits (algebraMap K L) (cyclotomic n K) := by
refine splits_of_splits_of_dvd _ (X_pow_sub_C_ne_zero (NeZero.pos _) _)
(splits_X_pow_sub_one K L hS) ?_
use ∏ i ∈ n.properDivisors, Polynomial.cyclotomic i K
rw [(eq_cyclotomic_iff (NeZero.pos _) _).1 rfl, RingHom.map_one]
variable (n S)
theorem _root_.IntermediateField.isCyclotomicExtension_adjoin_of_exists_isPrimitiveRoot
(h : ∀ n ∈ S, n ≠ 0 → ∃ r : L, IsPrimitiveRoot r n) :
IsCyclotomicExtension S K
(IntermediateField.adjoin K {b : L | ∃ n ∈ S, n ≠ 0 ∧ b ^ n = 1}) := by
have key : ∀ b ∈ {b : L | ∃ n ∈ S, n ≠ 0 ∧ b ^ n = 1}, IsAlgebraic K b := by
rintro b ⟨n, hn, h1, h2⟩
exact ⟨X ^ n - 1, (monic_X_pow_sub_C (1 : K) h1).ne_zero, by simp [h2]⟩
change IsCyclotomicExtension S K (IntermediateField.toSubalgebra _)
rw [congr(IsCyclotomicExtension S K $(IntermediateField.adjoin_algebraic_toSubalgebra key))]
exact Algebra.isCyclotomicExtension_adjoin_of_exists_isPrimitiveRoot S K L h
theorem isSeparable [IsCyclotomicExtension S K L] : Algebra.IsSeparable K L := by
have := integral S K L
have h := (IsCyclotomicExtension.iff_adjoin_eq_top S K L).1 ‹_› |>.2
rw [← IntermediateField.adjoin_algebraic_toSubalgebra
fun b _ ↦ Algebra.IsAlgebraic.isAlgebraic b, ← IntermediateField.top_toSubalgebra] at h
rw [← AlgEquiv.Algebra.isSeparable_iff <|
(IntermediateField.equivOfEq (IntermediateField.toSubalgebra_injective h)).trans
IntermediateField.topEquiv, IntermediateField.isSeparable_adjoin_iff_isSeparable]
rintro b ⟨n, hn, h1, h2⟩
have := NeZero.mk h1
have := Polynomial.X_pow_sub_one_separable_iff.2 (neZero_of_mem' n S K L hn).out
exact this.of_dvd <| minpoly.dvd K b <| by simp [h2]
theorem nonempty_algEquiv_adjoin_of_isSepClosed [IsCyclotomicExtension S K L]
(M : Type*) [Field M] [Algebra K M] [IsSepClosed M] :
Nonempty (L ≃ₐ[K] IntermediateField.adjoin K {x : M | ∃ n ∈ S, n ≠ 0 ∧ x ^ n = 1}) := by
have := isSeparable S K L
let i : L →ₐ[K] M := IsSepClosed.lift
refine ⟨(show L ≃ₐ[K] i.fieldRange from AlgEquiv.ofInjectiveField i).trans
(IntermediateField.equivOfEq (le_antisymm ?_ ?_))⟩
· rintro x (hx : x ∈ i.range)
let e := Subalgebra.equivOfEq _ _ ((IsCyclotomicExtension.iff_adjoin_eq_top S K L).1 ‹_›).2
|>.trans Subalgebra.topEquiv
have hrange : i.range = (i.comp (AlgHomClass.toAlgHom e)).range := by
ext x
simp only [AlgHom.mem_range, AlgHom.coe_comp, AlgHom.coe_coe, Function.comp_apply]
constructor
· rintro ⟨y, rfl⟩; exact ⟨e.symm y, by simp⟩
· rintro ⟨y, rfl⟩; exact ⟨e y, rfl⟩
rw [hrange, AlgHom.mem_range] at hx
obtain ⟨⟨y, hy⟩, rfl⟩ := hx
induction hy using Algebra.adjoin_induction with
| mem x hx =>
obtain ⟨n, hn, h1, h2⟩ := hx
apply IntermediateField.subset_adjoin
use n, hn, h1
rw [← map_pow, ← map_one (i.comp (AlgHomClass.toAlgHom e))]
congr 1
apply_fun _ using Subtype.val_injective
simpa
| algebraMap x =>
convert IntermediateField.algebraMap_mem _ x
exact AlgHom.commutes _ x
| add x y hx hy ihx ihy =>
convert add_mem ihx ihy
exact map_add (i.comp (AlgHomClass.toAlgHom e)) ⟨x, hx⟩ ⟨y, hy⟩
| mul x y hx hy ihx ihy =>
convert mul_mem ihx ihy
exact map_mul (i.comp (AlgHomClass.toAlgHom e)) ⟨x, hx⟩ ⟨y, hy⟩
· rw [IntermediateField.adjoin_le_iff]
rintro x ⟨n, hn, h1, h2⟩
have := NeZero.mk h1
obtain ⟨y, hy⟩ := exists_isPrimitiveRoot K L hn h1
obtain ⟨m, -, rfl⟩ := (hy.map_of_injective (f := i) i.injective).eq_pow_of_pow_eq_one h2
exact ⟨y ^ m, by simp⟩
theorem isGalois [IsCyclotomicExtension S K L] : IsGalois K L := by
rw [isGalois_iff]
use isSeparable S K L
obtain ⟨i⟩ := nonempty_algEquiv_adjoin_of_isSepClosed S K L (AlgebraicClosure K)
rw [i.transfer_normal, IntermediateField.normal_iff_forall_map_le]
intro f x hx
rw [← IntermediateField.mem_toSubalgebra, IntermediateField.toSubalgebra_map,
Subalgebra.mem_map] at hx
obtain ⟨y, hy, rfl⟩ := hx
rw [IntermediateField.mem_toSubalgebra] at hy
induction hy using IntermediateField.adjoin_induction with
| mem x hx =>
obtain ⟨n, hn, h1, h2⟩ := hx
apply IntermediateField.subset_adjoin
use n, hn, h1
rw [← map_pow, ← map_one f, h2]
| algebraMap x =>
convert IntermediateField.algebraMap_mem _ x
exact AlgHom.commutes _ x
| add x y hx hy ihx ihy =>
rw [map_add]
exact add_mem ihx ihy
| mul x y hx hy ihx ihy =>
rw [map_mul]
exact mul_mem ihx ihy
| inv x hx ihx =>
rw [map_inv₀]
exact inv_mem ihx
/-- Cyclotomic extensions are abelian. -/
theorem isAbelianGalois [IsCyclotomicExtension S K L] :
IsAbelianGalois K L where
__ := isGalois S K L
__ := isMulCommutative S K L
/-- Any two `S`-cyclotomic extensions are isomorphic. -/
noncomputable def algEquiv [IsCyclotomicExtension S K L]
(L' : Type*) [Field L'] [Algebra K L'] [IsCyclotomicExtension S K L'] : L ≃ₐ[K] L' :=
(nonempty_algEquiv_adjoin_of_isSepClosed S K L (AlgebraicClosure K)).some.trans
(nonempty_algEquiv_adjoin_of_isSepClosed S K L' (AlgebraicClosure K)).some.symm
theorem nonempty_algEquiv_adjoin_of_exists_isPrimitiveRoot [IsCyclotomicExtension S K L]
(M : Type*) [Field M] [Algebra K M] (h : ∀ n ∈ S, n ≠ 0 → ∃ r : M, IsPrimitiveRoot r n) :
Nonempty (L ≃ₐ[K] IntermediateField.adjoin K {x : M | ∃ n ∈ S, n ≠ 0 ∧ x ^ n = 1}) :=
have := IntermediateField.isCyclotomicExtension_adjoin_of_exists_isPrimitiveRoot S K M h
⟨algEquiv S K L _⟩
section Singleton
variable [IsCyclotomicExtension {n} K L]
/-- If `IsCyclotomicExtension {n} K L`, then `L` is the splitting field of `X ^ n - 1`. -/
theorem isSplittingField_X_pow_sub_one : IsSplittingField K L (X ^ n - 1) :=
{ splits' := splits_X_pow_sub_one K L (mem_singleton n)
adjoin_rootSet' := by
rw [← ((iff_adjoin_eq_top {n} K L).1 inferInstance).2]
congr
refine Set.ext fun x => ?_
simp only [mem_singleton_iff, ne_eq, exists_eq_left, NeZero.ne, not_false_eq_true, true_and,
mem_setOf_eq]
simp only [mem_rootSet', map_sub, map_pow, aeval_one, aeval_X, sub_eq_zero, map_X,
and_iff_right_iff_imp, Polynomial.map_sub, Polynomial.map_pow, Polynomial.map_one]
exact fun _ => X_pow_sub_C_ne_zero (NeZero.pos n) (1 : L) }
scoped[Cyclotomic] attribute [instance] IsCyclotomicExtension.isSplittingField_X_pow_sub_one
/-- If `IsCyclotomicExtension {n} K L`, then `L` is the splitting field of `cyclotomic n K`. -/
theorem splitting_field_cyclotomic : IsSplittingField K L (cyclotomic n K) :=
{ splits' := splits_cyclotomic K L (mem_singleton n)
adjoin_rootSet' := by
rw [← ((iff_adjoin_eq_top {n} K L).1 inferInstance).2]
letI := Classical.decEq L
obtain ⟨ζ : L, hζ⟩ :=
IsCyclotomicExtension.exists_isPrimitiveRoot K L (mem_singleton n) (NeZero.ne _)
exact adjoin_roots_cyclotomic_eq_adjoin_nth_roots hζ }
scoped[Cyclotomic] attribute [instance] IsCyclotomicExtension.splitting_field_cyclotomic
end Singleton
end Field
end IsCyclotomicExtension
section CyclotomicField
/-- Given a nonzero `n : ℕ` and a field `K`, we define `CyclotomicField n K` as the
splitting field of `cyclotomic n K`. If `n` is nonzero in `K`, it has
the instance `IsCyclotomicExtension {n} K (CyclotomicField n K)`. -/
def CyclotomicField : Type w :=
(cyclotomic n K).SplittingField
namespace CyclotomicField
instance : Field (CyclotomicField n K) := by
delta CyclotomicField; infer_instance
instance algebra : Algebra K (CyclotomicField n K) := by
delta CyclotomicField; infer_instance
instance : Inhabited (CyclotomicField n K) := by
delta CyclotomicField; infer_instance
instance [CharZero K] : CharZero (CyclotomicField n K) :=
charZero_of_injective_algebraMap (algebraMap K _).injective
instance isCyclotomicExtension [NeZero (n : K)] :
IsCyclotomicExtension {n} K (CyclotomicField n K) := by
have : NeZero (n : CyclotomicField n K) :=
NeZero.nat_of_injective (algebraMap K _).injective
letI := Classical.decEq (CyclotomicField n K)
obtain ⟨ζ, hζ⟩ :=
exists_root_of_splits (algebraMap K (CyclotomicField n K)) (SplittingField.splits _)
(degree_cyclotomic_pos n K (NeZero.pos n)).ne'
rw [← eval_map, ← IsRoot.def, map_cyclotomic, isRoot_cyclotomic_iff] at hζ
refine ⟨?_, ?_⟩
· simp only [mem_singleton_iff, forall_eq]
exact fun _ ↦ ⟨ζ, hζ⟩
· rw [← Algebra.eq_top_iff, ← SplittingField.adjoin_rootSet, eq_comm]
exact IsCyclotomicExtension.adjoin_roots_cyclotomic_eq_adjoin_nth_roots hζ
instance : IsCyclotomicExtension {0} K (CyclotomicField 0 K) where
exists_isPrimitiveRoot := by aesop
adjoin_roots x := by
have finrank : Module.finrank K (CyclotomicField 0 K) = 1 := by
have : Polynomial.IsSplittingField K K (Polynomial.cyclotomic 0 K) :=
Polynomial.isSplittingField_C 1
let e : K ≃ₗ[K] (CyclotomicField 0 K) :=
(Polynomial.IsSplittingField.algEquiv K (Polynomial.cyclotomic 0 K)).toLinearEquiv
simp [←LinearEquiv.finrank_eq e, finrank_self]
simp [Subalgebra.bot_eq_top_iff_finrank_eq_one.mpr finrank]
omit [NeZero n]
instance [CharZero K] : IsCyclotomicExtension {n} K (CyclotomicField n K) :=
match n with
| 0 => inferInstance
| _ + 1 => inferInstance
instance [NumberField K] : NumberField (CyclotomicField n K) :=
IsCyclotomicExtension.numberField {n} K _
end CyclotomicField
end CyclotomicField
section IsDomain
variable [Algebra A K]
section CyclotomicRing
/-- If `K` is an `A`-algebra, the `A`-algebra structure on `CyclotomicField n K`.
-/
instance CyclotomicField.algebraBase : Algebra A (CyclotomicField n K) :=
SplittingField.instAlgebra (cyclotomic n K)
/-- Ensure there are no diamonds when `A = ℤ` but there are `reducible_and_instances` https://github.com/leanprover-community/mathlib4/issues/10906 -/
example : Ring.toIntAlgebra (CyclotomicField n ℚ) = CyclotomicField.algebraBase _ _ _ := rfl
instance {R : Type*} [CommRing R] [Algebra R K] : IsScalarTower R K (CyclotomicField n K) :=
SplittingField.instIsScalarTower _
instance [IsFractionRing A K] : NoZeroSMulDivisors A (CyclotomicField n K) := by
rw [NoZeroSMulDivisors.iff_faithfulSMul, faithfulSMul_iff_algebraMap_injective,
IsScalarTower.algebraMap_eq A K (CyclotomicField n K)]
exact
(Function.Injective.comp (FaithfulSMul.algebraMap_injective K (CyclotomicField n K))
(IsFractionRing.injective A K) :)
/-- If `A` is a domain with fraction field `K` and `n : ℕ`, we define `CyclotomicRing n A K` as
the `A`-subalgebra of `CyclotomicField n K` generated by the roots of `X ^ n - 1`. If `n`
is nonzero in `A`, it has the instance `IsCyclotomicExtension {n} A (CyclotomicRing n A K)`. -/
@[nolint unusedArguments]
def CyclotomicRing : Type w :=
adjoin A {b : CyclotomicField n K | b ^ n = 1}
namespace CyclotomicRing
instance : CommRing (CyclotomicRing n A K) := by
delta CyclotomicRing; infer_instance
instance : IsDomain (CyclotomicRing n A K) := by
delta CyclotomicRing; infer_instance
instance : Inhabited (CyclotomicRing n A K) := by
delta CyclotomicRing; infer_instance
/-- The `A`-algebra structure on `CyclotomicRing n A K`. -/
instance algebraBase : Algebra A (CyclotomicRing n A K) :=
(adjoin A _).algebra
-- Ensure that there is no diamonds with ℤ.
-- but there is at `reducible_and_instances` https://github.com/leanprover-community/mathlib4/issues/10906
example {n : ℕ} : CyclotomicRing.algebraBase n ℤ ℚ = Ring.toIntAlgebra _ := rfl
instance [IsFractionRing A K] :
NoZeroSMulDivisors A (CyclotomicRing n A K) :=
(adjoin A _).noZeroSMulDivisors_bot
omit [NeZero n] in
theorem algebraBase_injective [IsFractionRing A K] :
Function.Injective <| algebraMap A (CyclotomicRing n A K) :=
FaithfulSMul.algebraMap_injective _ _
instance : Algebra (CyclotomicRing n A K) (CyclotomicField n K) :=
(adjoin A _).toAlgebra
omit [NeZero n] in
theorem adjoin_algebra_injective :
Function.Injective <| algebraMap (CyclotomicRing n A K) (CyclotomicField n K) :=
Subtype.val_injective
instance : NoZeroSMulDivisors (CyclotomicRing n A K) (CyclotomicField n K) :=
NoZeroSMulDivisors.iff_algebraMap_injective.mpr (adjoin_algebra_injective n A K)
instance : IsScalarTower A (CyclotomicRing n A K) (CyclotomicField n K) :=
IsScalarTower.subalgebra' _ _ _ _
instance isCyclotomicExtension [IsFractionRing A K] [NeZero ((n : ℕ) : A)] :
IsCyclotomicExtension {n} A (CyclotomicRing n A K) where
exists_isPrimitiveRoot {a} han _ := by
rw [mem_singleton_iff] at han
subst a
have := NeZero.of_faithfulSMul A K n
have := NeZero.of_faithfulSMul A (CyclotomicField n K) n
obtain ⟨μ, hμ⟩ := (CyclotomicField.isCyclotomicExtension n K).exists_isPrimitiveRoot
(mem_singleton n) (NeZero.ne n)
refine ⟨⟨μ, subset_adjoin ?_⟩, ?_⟩
· apply (isRoot_of_unity_iff (NeZero.pos n) (CyclotomicField n K)).mpr
refine ⟨n, Nat.mem_divisors_self _ (NeZero.ne n), ?_⟩
rwa [← isRoot_cyclotomic_iff] at hμ
· rwa [← IsPrimitiveRoot.coe_submonoidClass_iff, Subtype.coe_mk]
adjoin_roots x := by
obtain ⟨x, hx⟩ := x
refine
adjoin_induction (fun y hy => ?_) (fun a => ?_) (fun y z _ _ hy hz => ?_)
(fun y z _ _ hy hz => ?_) hx
· refine subset_adjoin ?_
simp only [mem_singleton_iff, exists_eq_left, mem_setOf_eq]
exact ⟨NeZero.ne n, by rwa [← Subalgebra.coe_eq_one, Subalgebra.coe_pow, Subtype.coe_mk]⟩
· exact Subalgebra.algebraMap_mem _ a
· exact Subalgebra.add_mem _ hy hz
· exact Subalgebra.mul_mem _ hy hz
instance [IsFractionRing A K] [IsDomain A] [NeZero (n : A)] :
IsFractionRing (CyclotomicRing n A K) (CyclotomicField n K) where
map_units := fun ⟨x, hx⟩ => by
rw [isUnit_iff_ne_zero]
apply map_ne_zero_of_mem_nonZeroDivisors
· apply adjoin_algebra_injective
· exact hx
surj x := by
have : NeZero (n : K) := NeZero.nat_of_injective (IsFractionRing.injective A K)
refine
Algebra.adjoin_induction
(hx := ((IsCyclotomicExtension.iff_singleton n K (CyclotomicField n K)).1
(CyclotomicField.isCyclotomicExtension n K)).2 x)
(fun y hy => ?_) (fun k => ?_) ?_ ?_
· exact ⟨⟨⟨y, subset_adjoin hy⟩, 1⟩, by simp; rfl⟩
· have : IsLocalization (nonZeroDivisors A) K := inferInstance
replace := this.surj
obtain ⟨⟨z, w⟩, hw⟩ := this k
refine ⟨⟨algebraMap A (CyclotomicRing n A K) z, algebraMap A (CyclotomicRing n A K) w,
map_mem_nonZeroDivisors _ (algebraBase_injective n A K) w.2⟩, ?_⟩
letI : IsScalarTower A K (CyclotomicField n K) :=
IsScalarTower.of_algebraMap_eq (congr_fun rfl)
rw [← IsScalarTower.algebraMap_apply, ← IsScalarTower.algebraMap_apply,
@IsScalarTower.algebraMap_apply A K _ _ _ _ _ (_root_.CyclotomicField.algebra n K) _ _ w,
← RingHom.map_mul, hw, ← IsScalarTower.algebraMap_apply]
· rintro y z - - ⟨a, ha⟩ ⟨b, hb⟩
refine ⟨⟨a.1 * b.2 + b.1 * a.2, a.2 * b.2, mul_mem_nonZeroDivisors.2 ⟨a.2.2, b.2.2⟩⟩, ?_⟩
rw [RingHom.map_mul, add_mul, ← mul_assoc, ha,
mul_comm ((algebraMap (CyclotomicRing n A K) _) ↑a.2), ← mul_assoc, hb]
simp only [map_add, map_mul]
· rintro y z - - ⟨a, ha⟩ ⟨b, hb⟩
refine ⟨⟨a.1 * b.1, a.2 * b.2, mul_mem_nonZeroDivisors.2 ⟨a.2.2, b.2.2⟩⟩, ?_⟩
rw [RingHom.map_mul, mul_comm ((algebraMap (CyclotomicRing n A K) _) ↑a.2), mul_assoc, ←
mul_assoc z, hb, ← mul_comm ((algebraMap (CyclotomicRing n A K) _) ↑a.2), ← mul_assoc, ha]
simp only [map_mul]
exists_of_eq {x y} h := ⟨1, by rw [adjoin_algebra_injective n A K h]⟩
theorem eq_adjoin_primitive_root {μ : CyclotomicField n K} (h : IsPrimitiveRoot μ n) :
CyclotomicRing n A K = adjoin A ({μ} : Set (CyclotomicField n K)) := by
rw [← IsCyclotomicExtension.adjoin_roots_cyclotomic_eq_adjoin_root_cyclotomic h,
IsCyclotomicExtension.adjoin_roots_cyclotomic_eq_adjoin_nth_roots h]
simp [CyclotomicRing, NeZero.ne n]
end CyclotomicRing
end CyclotomicRing
end IsDomain
section IsSepClosed
variable [IsSepClosed K]
/-- Separably closed fields are `S`-cyclotomic extensions over themselves if
`NeZero ((a : ℕ) : K)` for all nonzero `a ∈ S`. -/
theorem IsSepClosed.isCyclotomicExtension (h : ∀ a ∈ S, a ≠ 0 → NeZero (a : K)) :
IsCyclotomicExtension S K K := by
refine ⟨fun {a} ha ha' ↦ ?_, Algebra.eq_top_iff.mp <| Subsingleton.elim _ _⟩
have := h a ha ha'
obtain ⟨r, hr⟩ := IsSepClosed.exists_aeval_eq_zero K _
(degree_cyclotomic_pos a K (Nat.pos_of_ne_zero ha')).ne' (separable_cyclotomic a K)
exact ⟨r, by rwa [coe_aeval_eq_eval, ← IsRoot.def, isRoot_cyclotomic_iff] at hr⟩
@[deprecated (since := "2025-06-22")]
alias IsAlgClosed.isCyclotomicExtension := IsSepClosed.isCyclotomicExtension
instance IsSepClosedOfCharZero.isCyclotomicExtension [CharZero K] :
∀ S, IsCyclotomicExtension S K K := fun S => by
rw [IsCyclotomicExtension.eq_self_sdiff_zero]
exact IsSepClosed.isCyclotomicExtension _ K fun _ _ h ↦ ⟨Nat.cast_ne_zero.mpr h⟩
@[deprecated (since := "2025-06-22")]
alias IsAlgClosedOfCharZero.isCyclotomicExtension := IsSepClosedOfCharZero.isCyclotomicExtension
end IsSepClosed
section Subalgebra
variable {A B} [IsDomain B]
theorem IsCyclotomicExtension.mem_of_pow_eq_one (C : Subalgebra A B)
[h : IsCyclotomicExtension S A C] {m : ℕ} {ζ : B} (h₁ : m ∈ S) (h₂ : m ≠ 0)
(hζ : ζ ^ m = 1) : ζ ∈ C := by
obtain ⟨η, hη⟩ := h.1 h₁ h₂
replace hη := hη.map_of_injective (FaithfulSMul.algebraMap_injective C B)
have : NeZero m := ⟨h₂⟩
obtain ⟨k, _, rfl⟩ := hη.eq_pow_of_pow_eq_one hζ
rw [← map_pow]
exact Subalgebra.pow_mem _ η.prop _
theorem isCyclotomicExtension_iff_eq_adjoin (C : Subalgebra A B)
(hS : ∀ n ∈ S, n ≠ 0 → ∃ r : B, IsPrimitiveRoot r n) :
IsCyclotomicExtension S A C ↔ C = Algebra.adjoin A {x : B | ∃ n ∈ S, n ≠ 0 ∧ x ^ n = 1} := by
refine ⟨fun h ↦ ?_, fun h ↦ h ▸ isCyclotomicExtension_adjoin_of_exists_isPrimitiveRoot S A B hS⟩
have := congr_arg (Subalgebra.map C.val) ((IsCyclotomicExtension.iff_adjoin_eq_top _ _ _).mp h).2
rw [← Subalgebra.range_val C, ← Algebra.map_top, ← this, AlgHom.map_adjoin]
congr; ext
simp only [Subalgebra.coe_val, ne_eq, ← Subalgebra.coe_eq_one, SubmonoidClass.coe_pow,
Set.mem_image, Set.mem_setOf_eq, Subtype.exists, exists_and_left, exists_prop,
exists_eq_right_right, and_iff_left_iff_imp, forall_exists_index, and_imp]
exact fun n hn₁ hn₂ hx ↦ h.mem_of_pow_eq_one S C hn₁ hn₂ hx
theorem isCyclotomicExtension_singleton_iff_eq_adjoin (C : Subalgebra A B) {ζ : B}
(hζ : IsPrimitiveRoot ζ n) : IsCyclotomicExtension {n} A C ↔ C = adjoin A {ζ} := by
rw [isCyclotomicExtension_iff_eq_adjoin]
· simp only [Set.mem_singleton_iff, exists_eq_left]
suffices adjoin A {b | n ≠ 0 ∧ b ^ n = 1} = adjoin A {ζ} by rw [this]
apply le_antisymm
· refine adjoin_le fun x ⟨_, hx⟩ ↦ ?_
obtain ⟨k, _, rfl⟩ := hζ.eq_pow_of_pow_eq_one hx
exact Subalgebra.pow_mem _ (self_mem_adjoin_singleton A ζ) _
· exact adjoin_mono <| Set.singleton_subset_iff.mpr ⟨NeZero.ne n, hζ.pow_eq_one⟩
· simpa only [Set.mem_singleton_iff, ne_eq, forall_eq, NeZero.ne n, not_false_eq_true,
forall_const] using ⟨ζ, hζ⟩
theorem IsCyclotomicExtension.eq (C₁ C₂ : Subalgebra A B) [h₁ : IsCyclotomicExtension S A C₁]
[h₂ : IsCyclotomicExtension S A C₂] : C₁ = C₂ := by
have hC (n) (hn₁ : n ∈ S) (hn₂ : n ≠ 0) : ∃ x : B, IsPrimitiveRoot x n := by
obtain ⟨ζ, hζ⟩ := h₁.1 hn₁ hn₂
exact ⟨ζ, IsPrimitiveRoot.coe_submonoidClass_iff.mpr hζ⟩
rw [(isCyclotomicExtension_iff_eq_adjoin S C₁ hC).mp h₁,
(isCyclotomicExtension_iff_eq_adjoin S C₂ hC).mp h₂]
variable (n₁ n₂ : ℕ) (C₁ C₂ : Subalgebra A B) [h₁ : IsCyclotomicExtension {n₁} A C₁]
[h₂ : IsCyclotomicExtension {n₂} A C₂]
theorem IsCyclotomicExtension.le_of_dvd [NeZero n₂] (h : n₁ ∣ n₂) : C₁ ≤ C₂ := by
have : NeZero n₁ := by
constructor
rintro rfl
exact NeZero.ne n₂ <| eq_zero_of_zero_dvd h
obtain ⟨ζ₂, hζ₂⟩ := h₂.1 rfl (NeZero.ne n₂)
replace hζ₂ := hζ₂.map_of_injective (FaithfulSMul.algebraMap_injective C₂ B)
obtain ⟨d, hd⟩ := h
have hζ₁ := IsPrimitiveRoot.pow n₂.pos_of_neZero hζ₂ (by rwa [mul_comm])
simpa [(isCyclotomicExtension_singleton_iff_eq_adjoin n₁ C₁ hζ₁).mp h₁,
(isCyclotomicExtension_singleton_iff_eq_adjoin n₂ C₂ hζ₂).mp h₂] using
adjoin_le <| Set.singleton_subset_iff.mpr <|
Subalgebra.pow_mem _ (self_mem_adjoin_singleton A _) _
theorem IsCyclotomicExtension.lcm_sup [NeZero n₁] [NeZero n₂] :
IsCyclotomicExtension {n₁.lcm n₂} A (C₁ ⊔ C₂ : Subalgebra A B) := by
obtain ⟨ζ₁, hζ₁⟩ := h₁.1 rfl (NeZero.ne n₁)
obtain ⟨ζ₂, hζ₂⟩ := h₂.1 rfl (NeZero.ne n₂)
replace hζ₁ := hζ₁.map_of_injective (FaithfulSMul.algebraMap_injective C₁ B)
replace hζ₂ := hζ₂.map_of_injective (FaithfulSMul.algebraMap_injective C₂ B)
have hζ := hζ₁.pow_mul_pow_lcm hζ₂ (NeZero.ne n₁) (NeZero.ne n₂)
rw [sup_comm, (isCyclotomicExtension_singleton_iff_eq_adjoin n₁ C₁ hζ₁).mp h₁,
(isCyclotomicExtension_singleton_iff_eq_adjoin n₂ C₂ hζ₂).mp h₂, ← adjoin_union,
Set.union_singleton, hζ₁.adjoin_pair_eq A hζ₂ (NeZero.ne _) (NeZero.ne _) hζ]
have : NeZero (n₁.lcm n₂) := ⟨Nat.lcm_ne_zero (NeZero.ne _) (NeZero.ne _)⟩
exact (hζ₁.pow_mul_pow_lcm hζ₂ (NeZero.ne n₁) (NeZero.ne n₂)).adjoin_isCyclotomicExtension A
theorem IntermediateField.isCyclotomicExtension_singleton_iff_eq_adjoin (F : IntermediateField K L)
{ζ : L} (hζ : IsPrimitiveRoot ζ n) :
IsCyclotomicExtension {n} K F ↔ F = IntermediateField.adjoin K {ζ} := by
rw [← toSubalgebra_inj, adjoin_simple_toSubalgebra_of_integral
(hζ.isIntegral (NeZero.pos _)).tower_top]
exact _root_.isCyclotomicExtension_singleton_iff_eq_adjoin n F.toSubalgebra hζ
theorem IntermediateField.isCyclotomicExtension_eq (F₁ F₂ : IntermediateField K L)
[h₁ : IsCyclotomicExtension S K F₁] [h₂ : IsCyclotomicExtension S K F₂] :
F₁ = F₂ :=
toSubalgebra_inj.mp <| _root_.IsCyclotomicExtension.eq S F₁.toSubalgebra F₂.toSubalgebra
variable (F₁ F₂ : IntermediateField K L) [h₁ : IsCyclotomicExtension {n₁} K F₁]
[h₂ : IsCyclotomicExtension {n₂} K F₂]
theorem IntermediateField.isCyclotomicExtension_le_of_dvd [NeZero n₂] (h : n₁ ∣ n₂) : F₁ ≤ F₂ := by
exact toSubalgebra_le_toSubalgebra.mp <|
IsCyclotomicExtension.le_of_dvd n₁ n₂ F₁.toSubalgebra F₂.toSubalgebra h
theorem IntermediateField.isCyclotomicExtension_lcm_sup [NeZero n₁] [NeZero n₂] :
IsCyclotomicExtension {n₁.lcm n₂} K (F₁ ⊔ F₂ : IntermediateField K L) := by
have : FiniteDimensional K F₁ := IsCyclotomicExtension.finite_of_singleton n₁ K F₁
have := IsCyclotomicExtension.lcm_sup n₁ n₂ F₁.toSubalgebra F₂.toSubalgebra
rwa [← sup_toSubalgebra_of_left] at this
end Subalgebra |
.lake/packages/mathlib/Mathlib/NumberTheory/Cyclotomic/Gal.lean | import Mathlib.NumberTheory.Cyclotomic.PrimitiveRoots
import Mathlib.FieldTheory.PolynomialGaloisGroup
/-!
# Galois group of cyclotomic extensions
In this file, we show the relationship between the Galois group of `K(ζₙ)` and `(ZMod n)ˣ`;
it is always a subgroup, and if the `n`th cyclotomic polynomial is irreducible, they are isomorphic.
## Main results
* `IsPrimitiveRoot.autToPow_injective`: `IsPrimitiveRoot.autToPow` is injective
in the case that it's considered over a cyclotomic field extension.
* `IsCyclotomicExtension.autEquivPow`: If the `n`th cyclotomic polynomial is irreducible in `K`,
then `IsPrimitiveRoot.autToPow` is a `MulEquiv` (for example, in `ℚ` and certain `𝔽ₚ`).
* `galXPowEquivUnitsZMod`, `galCyclotomicEquivUnitsZMod`: Repackage
`IsCyclotomicExtension.autEquivPow` in terms of `Polynomial.Gal`.
* `IsCyclotomicExtension.Aut.commGroup`: Cyclotomic extensions are abelian.
## References
* https://kconrad.math.uconn.edu/blurbs/galoistheory/cyclotomic.pdf
## TODO
* We currently can get away with the fact that the power of a primitive root is a primitive root,
but the correct long-term solution for computing other explicit Galois groups is creating
`PowerBasis.map_conjugate`; but figuring out the exact correct assumptions + proof for this is
mathematically nontrivial. (Current thoughts: the correct condition is that the annihilating
ideal of both elements is equal. This may not hold in an ID, and definitely holds in an ICD.)
-/
variable {n : ℕ} [NeZero n] (K : Type*) [Field K] {L : Type*} {μ : L}
open Polynomial IsCyclotomicExtension
open scoped Cyclotomic
namespace IsPrimitiveRoot
variable [CommRing L] [IsDomain L] (hμ : IsPrimitiveRoot μ n) [Algebra K L]
[IsCyclotomicExtension {n} K L]
/-- `IsPrimitiveRoot.autToPow` is injective in the case that it's considered over a cyclotomic
field extension. -/
theorem autToPow_injective : Function.Injective <| hμ.autToPow K := by
intro f g hfg
apply_fun Units.val at hfg
simp only [IsPrimitiveRoot.coe_autToPow_apply] at hfg
generalize_proofs hf' hg' at hfg
have hf := hf'.choose_spec
have hg := hg'.choose_spec
generalize_proofs hζ at hf hg
suffices f (hμ.toRootsOfUnity : Lˣ) = g (hμ.toRootsOfUnity : Lˣ) by
apply AlgEquiv.coe_algHom_injective
apply (hμ.powerBasis K).algHom_ext
exact this
rw [ZMod.natCast_eq_natCast_iff] at hfg
refine (hf.trans ?_).trans hg.symm
rw [← rootsOfUnity.coe_pow _ hf'.choose, ← rootsOfUnity.coe_pow _ hg'.choose]
congr 2
rw [pow_eq_pow_iff_modEq]
convert hfg
conv => enter [2]; rw [hμ.eq_orderOf, ← hμ.val_toRootsOfUnity_coe]
rw [orderOf_units, Subgroup.orderOf_coe]
end IsPrimitiveRoot
namespace IsCyclotomicExtension
@[deprecated (since := "2025-06-26")]
alias Aut.commGroup := isMulCommutative
variable [CommRing L] [IsDomain L] (hμ : IsPrimitiveRoot μ n) [Algebra K L]
[IsCyclotomicExtension {n} K L]
variable {K} (L)
/-- The `MulEquiv` that takes an automorphism `f` to the element `k : (ZMod n)ˣ` such that
`f μ = μ ^ k` for any root of unity `μ`. A strengthening of `IsPrimitiveRoot.autToPow`. -/
@[simps]
noncomputable def autEquivPow (h : Irreducible (cyclotomic n K)) : Gal(L/K) ≃* (ZMod n)ˣ :=
let hζ := zeta_spec n K L
let hμ t := hζ.pow_of_coprime _ (ZMod.val_coe_unit_coprime t)
{ (zeta_spec n K L).autToPow K with
invFun := fun t =>
(hζ.powerBasis K).equivOfMinpoly ((hμ t).powerBasis K)
(by
haveI := IsCyclotomicExtension.neZero' n K L
simp only [IsPrimitiveRoot.powerBasis_gen]
have hr :=
IsPrimitiveRoot.minpoly_eq_cyclotomic_of_irreducible
((zeta_spec n K L).pow_of_coprime _ (ZMod.val_coe_unit_coprime t)) h
exact ((zeta_spec n K L).minpoly_eq_cyclotomic_of_irreducible h).symm.trans hr)
left_inv := fun f => by
simp only [MonoidHom.toFun_eq_coe]
apply AlgEquiv.coe_algHom_injective
apply (hζ.powerBasis K).algHom_ext
simp only [AlgHom.coe_coe]
rw [PowerBasis.equivOfMinpoly_gen]
simp only [IsPrimitiveRoot.powerBasis_gen, IsPrimitiveRoot.autToPow_spec]
right_inv := fun x => by
simp only [MonoidHom.toFun_eq_coe]
generalize_proofs _ h
have key := hζ.autToPow_spec K ((hζ.powerBasis K).equivOfMinpoly ((hμ x).powerBasis K) h)
have := (hζ.powerBasis K).equivOfMinpoly_gen ((hμ x).powerBasis K) h
rw [hζ.powerBasis_gen K] at this
rw [this, IsPrimitiveRoot.powerBasis_gen] at key
nth_rw 1 5 [← hζ.val_toRootsOfUnity_coe] at key
simp only [← rootsOfUnity.coe_pow] at key
replace key := rootsOfUnity.coe_injective key
rw [pow_eq_pow_iff_modEq, ← Subgroup.orderOf_coe, ← orderOf_units, hζ.val_toRootsOfUnity_coe,
← (zeta_spec n K L).eq_orderOf, ← ZMod.natCast_eq_natCast_iff] at key
simp only [ZMod.natCast_val, ZMod.cast_id', id] at key
exact Units.ext key }
variable (h : Irreducible (cyclotomic n K)) {L}
/-- Maps `μ` to the `AlgEquiv` that sends `IsCyclotomicExtension.zeta` to `μ`. -/
noncomputable def fromZetaAut : Gal(L/K) :=
let hζ := (zeta_spec n K L).eq_pow_of_pow_eq_one hμ.pow_eq_one
(autEquivPow L h).symm <|
ZMod.unitOfCoprime hζ.choose <|
((zeta_spec n K L).pow_iff_coprime (NeZero.pos _) hζ.choose).mp <| hζ.choose_spec.2.symm ▸ hμ
theorem fromZetaAut_spec : fromZetaAut hμ h (zeta n K L) = μ := by
simp_rw [fromZetaAut, autEquivPow_symm_apply]
generalize_proofs hζ h _ hμ _
nth_rewrite 4 [← hζ.powerBasis_gen K]
rw [PowerBasis.equivOfMinpoly_gen, hμ.powerBasis_gen K]
convert h.choose_spec.2
exact ZMod.val_cast_of_lt h.choose_spec.1
end IsCyclotomicExtension
section Gal
variable [Field L] [Algebra K L] [IsCyclotomicExtension {n} K L]
(h : Irreducible (cyclotomic n K)) {K}
/-- `IsCyclotomicExtension.autEquivPow` repackaged in terms of `Gal`.
Asserts that the Galois group of `cyclotomic n K` is equivalent to `(ZMod n)ˣ`
if `cyclotomic n K` is irreducible in the base field. -/
noncomputable def galCyclotomicEquivUnitsZMod : (cyclotomic n K).Gal ≃* (ZMod n)ˣ :=
(AlgEquiv.autCongr
(IsSplittingField.algEquiv L _ : L ≃ₐ[K] (cyclotomic n K).SplittingField)).symm.trans
(IsCyclotomicExtension.autEquivPow L h)
/-- `IsCyclotomicExtension.autEquivPow` repackaged in terms of `Gal`.
Asserts that the Galois group of `X ^ n - 1` is equivalent to `(ZMod n)ˣ`
if `cyclotomic n K` is irreducible in the base field. -/
noncomputable def galXPowEquivUnitsZMod : (X ^ n - 1 : K[X]).Gal ≃* (ZMod n)ˣ :=
(AlgEquiv.autCongr
(IsSplittingField.algEquiv L _ : L ≃ₐ[K] (X ^ n - 1 : K[X]).SplittingField)).symm.trans
(IsCyclotomicExtension.autEquivPow L h)
end Gal |
.lake/packages/mathlib/Mathlib/NumberTheory/Cyclotomic/Embeddings.lean | import Mathlib.NumberTheory.NumberField.Cyclotomic.Embeddings
deprecated_module (since := "2025-10-14") |
.lake/packages/mathlib/Mathlib/NumberTheory/Cyclotomic/CyclotomicCharacter.lean | import Mathlib.Algebra.Ring.Aut
import Mathlib.NumberTheory.Padics.RingHoms
import Mathlib.RingTheory.RootsOfUnity.EnoughRootsOfUnity
import Mathlib.RingTheory.RootsOfUnity.Minpoly
import Mathlib.FieldTheory.KrullTopology
/-!
# The cyclotomic character
Let `L` be an integral domain and let `n : ℕ+` be a positive integer. If `μₙ` is the
group of `n`th roots of unity in `L` then any field automorphism `g` of `L`
induces an automorphism of `μₙ` which, being a cyclic group, must be of
the form `ζ ↦ ζ^j` for some integer `j = j(g)`, well-defined in `ZMod d`, with
`d` the cardinality of `μₙ`. The function `j` is a group homomorphism
`(L ≃+* L) →* ZMod d`.
Future work: If `L` is separably closed (e.g. algebraically closed) and `p` is a prime
number such that `p ≠ 0` in `L`, then applying the above construction with
`n = p^i` (noting that the size of `μₙ` is `p^i`) gives a compatible collection of
group homomorphisms `(L ≃+* L) →* ZMod (p^i)` which glue to give
a group homomorphism `(L ≃+* L) →* ℤₚ`; this is the `p`-adic cyclotomic character.
## Important definitions
Let `L` be an integral domain, `g : L ≃+* L` and `n : ℕ+`. Let `d` be the number of `n`th roots
of `1` in `L`.
* `modularCyclotomicCharacter L n hn : (L ≃+* L) →* (ZMod n)ˣ` sends `g` to the unique `j` such
that `g(ζ)=ζ^j` for all `ζ : rootsOfUnity n L`. Here `hn` is a proof that there
are `n` `n`th roots of unity in `L`.
* `cyclotomicCharacter L p : (L ≃+* L) →* ℤ_[p]ˣ` sends `g` to the unique `j` such
that `g(ζ) = ζ ^ (j mod pⁱ)` for all `pⁱ`-th roots of unity `ζ`.
Note: This is defined to be the trivial character if `L` has no enough roots of unity.
## Implementation note
In theory this could be set up as some theory about monoids, being a character
on monoid isomorphisms, but under the hypotheses that the `n`-th roots of unity
are cyclic. The advantage of sticking to integral domains is that finite subgroups
are guaranteed to be cyclic, so the weaker assumption that there are `n` `n`th
roots of unity is enough. All the applications I'm aware of are when `L` is a
field anyway.
Although I don't know whether it's of any use, `modularCyclotomicCharacter'`
is the general case for integral domains, with target in `(ZMod d)ˣ`
where `d` is the number of `n`th roots of unity in `L`.
## TODO
* Prove the compatibility of `modularCyclotomicCharacter n` and `modularCyclotomicCharacter m`
if `n ∣ m`.
## Tags
cyclotomic character
-/
universe u
variable {L : Type u} [CommRing L] [IsDomain L]
/-
## The mod n theory
-/
variable (n : ℕ) [NeZero n]
theorem rootsOfUnity.integer_power_of_ringEquiv (g : L ≃+* L) :
∃ m : ℤ, ∀ t : rootsOfUnity n L, g (t : Lˣ) = (t ^ m : Lˣ) := by
obtain ⟨m, hm⟩ := MonoidHom.map_cyclic ((g : L ≃* L).restrictRootsOfUnity n).toMonoidHom
exact ⟨m, fun t ↦ Units.ext_iff.1 <| SetCoe.ext_iff.2 <| hm t⟩
theorem rootsOfUnity.integer_power_of_ringEquiv' (g : L ≃+* L) :
∃ m : ℤ, ∀ t ∈ rootsOfUnity n L, g (t : Lˣ) = (t ^ m : Lˣ) := by
simpa using rootsOfUnity.integer_power_of_ringEquiv n g
/-- `modularCyclotomicCharacter_aux g n` is a non-canonical auxiliary integer `j`,
only well-defined modulo the number of `n`-th roots of unity in `L`, such that `g(ζ)=ζ^j`
for all `n`-th roots of unity `ζ` in `L`. -/
noncomputable def modularCyclotomicCharacter.aux (g : L ≃+* L) (n : ℕ) [NeZero n] : ℤ :=
(rootsOfUnity.integer_power_of_ringEquiv n g).choose
-- the only thing we know about `modularCyclotomicCharacter_aux g n`
theorem modularCyclotomicCharacter.aux_spec (g : L ≃+* L) (n : ℕ) [NeZero n] :
∀ t : rootsOfUnity n L, g (t : Lˣ) = (t ^ (modularCyclotomicCharacter.aux g n) : Lˣ) :=
(rootsOfUnity.integer_power_of_ringEquiv n g).choose_spec
theorem modularCyclotomicCharacter.pow_dvd_aux_pow_sub_aux_pow
(g : L ≃+* L) (p : ℕ) [Fact p.Prime] [∀ i, HasEnoughRootsOfUnity L (p ^ i)]
{i k : ℕ} (hi : k ≤ i) : (p : ℤ) ^ k ∣ aux g (p ^ i) - aux g (p ^ k) := by
obtain ⟨i, rfl⟩ := exists_add_of_le hi
obtain ⟨ζ, hζ⟩ := HasEnoughRootsOfUnity.exists_primitiveRoot L (p ^ (k + i))
have h := hζ.pow (a := p ^ i) (Nat.pos_of_neZero _) (Nat.pow_add' _ _ _)
have h_unit : (h.isUnit NeZero.out).unit =
(hζ.isUnit NeZero.out).unit ^ (p ^ i) := by ext; rfl
have H₁ := aux_spec g (p ^ (k + i))
⟨_, (hζ.isUnit_unit NeZero.out).mem_rootsOfUnity⟩
have H₂ := aux_spec g (p ^ k)
⟨_, (h.isUnit_unit NeZero.out).mem_rootsOfUnity⟩
simp only [IsUnit.unit_spec, map_pow] at H₁ H₂
rw [H₁, ← Units.val_pow_eq_pow_val, ← Units.ext_iff, h_unit, ← div_eq_one] at H₂
simp only [← zpow_natCast, ← zpow_mul, div_eq_mul_inv, ← zpow_sub] at H₂
rw [(hζ.isUnit_unit NeZero.out).zpow_eq_one_iff_dvd, mul_comm, ← mul_sub] at H₂
conv_lhs at H₂ => rw [Nat.pow_add', Nat.cast_mul]
rwa [mul_dvd_mul_iff_left (by simp [NeZero.ne p]), Nat.cast_pow] at H₂
/-- If `g` is a ring automorphism of `L`, and `n : ℕ+`, then
`modularCyclotomicCharacter.toFun n g` is the `j : ZMod d` such that `g(ζ)=ζ^j` for all
`n`-th roots of unity. Here `d` is the number of `n`th roots of unity in `L`. -/
noncomputable def modularCyclotomicCharacter.toFun (n : ℕ) [NeZero n] (g : L ≃+* L) :
ZMod (Fintype.card (rootsOfUnity n L)) :=
modularCyclotomicCharacter.aux g n
namespace modularCyclotomicCharacter
local notation "χ₀" => modularCyclotomicCharacter.toFun
/-- The formula which characterises the output of `modularCyclotomicCharacter g n`. -/
theorem toFun_spec (g : L ≃+* L) {n : ℕ} [NeZero n] (t : rootsOfUnity n L) :
g (t : Lˣ) = (t ^ (χ₀ n g).val : Lˣ) := by
rw [modularCyclotomicCharacter.aux_spec g n t, ← zpow_natCast, modularCyclotomicCharacter.toFun,
ZMod.val_intCast, ← Subgroup.coe_zpow]
exact Units.ext_iff.1 <| SetCoe.ext_iff.2 <|
zpow_eq_zpow_emod _ pow_card_eq_one (G := rootsOfUnity n L)
theorem toFun_spec' (g : L ≃+* L) {n : ℕ} [NeZero n] {t : Lˣ} (ht : t ∈ rootsOfUnity n L) :
g t = t ^ (χ₀ n g).val :=
toFun_spec g ⟨t, ht⟩
theorem toFun_spec'' (g : L ≃+* L) {n : ℕ} [NeZero n] {t : L} (ht : IsPrimitiveRoot t n) :
g t = t ^ (χ₀ n g).val :=
toFun_spec' g (SetLike.coe_mem ht.toRootsOfUnity)
/-- If g(t)=t^c for all roots of unity, then c=χ(g). -/
theorem toFun_unique (g : L ≃+* L) (c : ZMod (Fintype.card (rootsOfUnity n L)))
(hc : ∀ t : rootsOfUnity n L, g (t : Lˣ) = (t ^ c.val : Lˣ)) : c = χ₀ n g := by
apply IsCyclic.ext Nat.card_eq_fintype_card (fun ζ ↦ ?_)
specialize hc ζ
suffices ((ζ ^ c.val : Lˣ) : L) = (ζ ^ (χ₀ n g).val : Lˣ) by exact_mod_cast this
rw [← toFun_spec g ζ, hc]
theorem toFun_unique' (g : L ≃+* L) (c : ZMod (Fintype.card (rootsOfUnity n L)))
(hc : ∀ t ∈ rootsOfUnity n L, g t = t ^ c.val) : c = χ₀ n g :=
toFun_unique n g c (fun ⟨_, ht⟩ ↦ hc _ ht)
lemma id : χ₀ n (RingEquiv.refl L) = 1 := by
refine (toFun_unique n (RingEquiv.refl L) 1 <| fun t ↦ ?_).symm
have : 1 ≤ Fintype.card { x // x ∈ rootsOfUnity n L } := Fin.size_positive'
obtain (h | h) := this.lt_or_eq
· have := Fact.mk h
simp [ZMod.val_one]
· have := Fintype.card_le_one_iff_subsingleton.mp h.ge
obtain rfl : t = 1 := Subsingleton.elim t 1
simp
lemma comp (g h : L ≃+* L) : χ₀ n (g * h) =
χ₀ n g * χ₀ n h := by
refine (toFun_unique n (g * h) _ <| fun ζ ↦ ?_).symm
change g (h (ζ : Lˣ)) = _
rw [toFun_spec, ← Subgroup.coe_pow, toFun_spec, mul_comm, Subgroup.coe_pow, ← pow_mul,
← Subgroup.coe_pow]
congr 2
norm_cast
simp only [pow_eq_pow_iff_modEq, ← ZMod.natCast_eq_natCast_iff,
ZMod.natCast_val, Nat.cast_mul, ZMod.cast_mul (m := orderOf ζ) orderOf_dvd_card]
end modularCyclotomicCharacter
variable (L)
/-- Given a positive integer `n`, `modularCyclotomicCharacter' n` is a
multiplicative homomorphism from the automorphisms of a field `L` to `(ℤ/dℤ)ˣ`,
where `d` is the number of `n`-th roots of unity in `L`. It is uniquely
characterised by the property that `g(ζ)=ζ^(modularCyclotomicCharacter n g)`
for `g` an automorphism of `L` and `ζ` an `n`th root of unity. -/
noncomputable
def modularCyclotomicCharacter' (n : ℕ) [NeZero n] :
(L ≃+* L) →* (ZMod (Fintype.card { x // x ∈ rootsOfUnity n L }))ˣ := MonoidHom.toHomUnits
{ toFun := modularCyclotomicCharacter.toFun n
map_one' := modularCyclotomicCharacter.id n
map_mul' := modularCyclotomicCharacter.comp n }
lemma modularCyclotomicCharacter'.spec' (g : L ≃+* L) {t : Lˣ} (ht : t ∈ rootsOfUnity n L) :
g t = t ^ ((modularCyclotomicCharacter' L n g) : ZMod
(Fintype.card { x // x ∈ rootsOfUnity n L })).val :=
modularCyclotomicCharacter.toFun_spec' g ht
lemma modularCyclotomicCharacter'.unique' (g : L ≃+* L)
{c : ZMod (Fintype.card { x // x ∈ rootsOfUnity n L })}
(hc : ∀ t ∈ rootsOfUnity n L, g t = t ^ c.val) :
c = modularCyclotomicCharacter' L n g :=
modularCyclotomicCharacter.toFun_unique' _ _ _ hc
/-- Given a positive integer `n` and a field `L` containing `n` `n`th roots
of unity, `modularCyclotomicCharacter n` is a multiplicative homomorphism from the
automorphisms of `L` to `(ℤ/nℤ)ˣ`. It is uniquely characterised by the property that
`g(ζ)=ζ^(modularCyclotomicCharacter n g)` for `g` an automorphism of `L` and `ζ` any `n`th root
of unity. -/
noncomputable def modularCyclotomicCharacter {n : ℕ} [NeZero n]
(hn : Fintype.card { x // x ∈ rootsOfUnity n L } = n) :
(L ≃+* L) →* (ZMod n)ˣ :=
(Units.mapEquiv <| (ZMod.ringEquivCongr hn).toMulEquiv).toMonoidHom.comp
(modularCyclotomicCharacter' L n)
namespace modularCyclotomicCharacter
variable {n : ℕ} [NeZero n] (hn : Fintype.card { x // x ∈ rootsOfUnity n L } = n)
lemma spec (g : L ≃+* L) {t : Lˣ} (ht : t ∈ rootsOfUnity n L) :
g t = t ^ ((modularCyclotomicCharacter L hn g) : ZMod n).val := by
rw [toFun_spec' g ht]
congr 1
exact (ZMod.ringEquivCongr_val _ _).symm
lemma unique (g : L ≃+* L) {c : ZMod n} (hc : ∀ t ∈ rootsOfUnity n L, g t = t ^ c.val) :
c = modularCyclotomicCharacter L hn g := by
change c = (ZMod.ringEquivCongr hn) (toFun n g)
rw [← toFun_unique' n g (ZMod.ringEquivCongr hn.symm c)
(fun t ht ↦ by rw [hc t ht, ZMod.ringEquivCongr_val]), ← ZMod.ringEquivCongr_symm hn,
RingEquiv.apply_symm_apply]
end modularCyclotomicCharacter
variable {L}
/-- The relationship between `IsPrimitiveRoot.autToPow` and
`modularCyclotomicCharacter`. Note that `IsPrimitiveRoot.autToPow`
needs an explicit root of unity, and also an auxiliary "base ring" `R`. -/
lemma IsPrimitiveRoot.autToPow_eq_modularCyclotomicCharacter (n : ℕ) [NeZero n]
(R : Type*) [CommRing R] [Algebra R L] {μ : L} (hμ : IsPrimitiveRoot μ n) (g : Gal(L/R)) :
hμ.autToPow R g = modularCyclotomicCharacter L hμ.card_rootsOfUnity g := by
ext
apply ZMod.val_injective
apply hμ.pow_inj (ZMod.val_lt _) (ZMod.val_lt _)
simpa only [autToPow_spec R hμ g, modularCyclotomicCharacter, RingEquiv.toMulEquiv_eq_coe,
MulEquiv.toMonoidHom_eq_coe, modularCyclotomicCharacter', MonoidHom.coe_comp, MonoidHom.coe_coe,
Function.comp_apply, Units.coe_mapEquiv, MonoidHom.coe_toHomUnits, MonoidHom.coe_mk,
OneHom.coe_mk, RingEquiv.coe_toMulEquiv, ZMod.ringEquivCongr_val, AlgEquiv.coe_ringEquiv]
using modularCyclotomicCharacter.toFun_spec'' g hμ
/-
## The p-adic theory
-/
open modularCyclotomicCharacter in
open scoped Classical in
/-- The underlying function of the cyclotomic character. See `cyclotomicCharacter`. -/
noncomputable def cyclotomicCharacter.toFun (p : ℕ) [Fact p.Prime] (g : L ≃+* L) : ℤ_[p] :=
if H : ∀ (i : ℕ), ∃ ζ : L, IsPrimitiveRoot ζ (p ^ i) then
haveI _ (i) : HasEnoughRootsOfUnity L (p ^ i) := ⟨H i, rootsOfUnity.isCyclic _ _⟩
PadicInt.ofIntSeq _ (PadicInt.isCauSeq_padicNorm_of_pow_dvd_sub
(aux g <| p ^ ·) _ fun i ↦ pow_dvd_aux_pow_sub_aux_pow g p i.le_succ)
else 1
namespace cyclotomicCharacter
local notation "χ" => cyclotomicCharacter.toFun
variable (p : ℕ) [Fact p.Prime] (g : L ≃+* L) [∀ i, HasEnoughRootsOfUnity L (p ^ i)]
open modularCyclotomicCharacter in
theorem toFun_apply :
cyclotomicCharacter.toFun p g =
PadicInt.ofIntSeq _ (PadicInt.isCauSeq_padicNorm_of_pow_dvd_sub
(aux g <| p ^ ·) _ fun i ↦ pow_dvd_aux_pow_sub_aux_pow g p i.le_succ) :=
dif_pos fun _ ↦ HasEnoughRootsOfUnity.exists_primitiveRoot _ _
open modularCyclotomicCharacter in
theorem toZModPow_toFun (n : ℕ) :
(χ p g).toZModPow n =
(modularCyclotomicCharacter _ (Fintype.card_eq_nat_card.trans
(HasEnoughRootsOfUnity.natCard_rootsOfUnity L (p ^ n))) g).val := by
rw [toFun_apply]
refine (PadicInt.toZModPow_ofIntSeq_of_pow_dvd_sub (aux g <| p ^ ·) _ (fun i ↦
pow_dvd_aux_pow_sub_aux_pow g p i.le_succ) n).trans ?_
simp [modularCyclotomicCharacter, modularCyclotomicCharacter', modularCyclotomicCharacter.toFun]
theorem toFun_spec (g : L ≃+* L) {n : ℕ} (t : rootsOfUnity (p ^ n) L) :
g (t : Lˣ) = t.1 ^ ((χ p g).toZModPow n).val := by
rw [toZModPow_toFun, ← modularCyclotomicCharacter.spec (ht := t.2)]
end cyclotomicCharacter
variable (L) in
/--
Suppose `L` is a domain containing all `pⁱ`-th primitive roots with `p` a (rational) prime.
If `g` is a ring automorphism of `L`, then `cyclotomicCharacter L p g` is the unique `j : ℤₚ` such
that `g(ζ) = ζ ^ (j mod pⁱ)` for all `pⁱ`-th roots of unity `ζ`.
Note: This is the trivial character when `L` does not contain all `pⁱ`-th primitive roots.
-/
noncomputable def cyclotomicCharacter (p : ℕ) [Fact p.Prime] :
(L ≃+* L) →* ℤ_[p]ˣ := .toHomUnits
{ toFun g := cyclotomicCharacter.toFun p g
map_one' := by
by_cases H : ∀ (i : ℕ), ∃ ζ : L, IsPrimitiveRoot ζ (p ^ i)
· haveI _ (i) : HasEnoughRootsOfUnity L (p ^ i) := ⟨H i, rootsOfUnity.isCyclic _ _⟩
refine PadicInt.ext_of_toZModPow.mp fun n ↦ ?_
simp [cyclotomicCharacter.toZModPow_toFun]
· simp [cyclotomicCharacter.toFun, dif_neg H]
map_mul' f g := by
by_cases H : ∀ (i : ℕ), ∃ ζ : L, IsPrimitiveRoot ζ (p ^ i)
· haveI _ (i) : HasEnoughRootsOfUnity L (p ^ i) := ⟨H i, rootsOfUnity.isCyclic _ _⟩
refine PadicInt.ext_of_toZModPow.mp fun n ↦ ?_
simp [cyclotomicCharacter.toZModPow_toFun]
· simp [cyclotomicCharacter.toFun, dif_neg H] }
theorem cyclotomicCharacter.spec (p : ℕ) [Fact p.Prime] {n : ℕ}
[∀ i, HasEnoughRootsOfUnity L (p ^ i)] (g : L ≃+* L) (t : L) (ht : t ^ p ^ n = 1) :
g t = t ^ ((cyclotomicCharacter L p g).val.toZModPow n).val :=
toFun_spec p g (rootsOfUnity.mkOfPowEq _ ht)
theorem cyclotomicCharacter.toZModPow (p : ℕ) [Fact p.Prime] {n : ℕ}
[∀ i, HasEnoughRootsOfUnity L (p ^ i)] (g : L ≃+* L) :
(cyclotomicCharacter L p g).val.toZModPow n =
(modularCyclotomicCharacter _ (Fintype.card_eq_nat_card.trans
(HasEnoughRootsOfUnity.natCard_rootsOfUnity L (p ^ n))) g).val :=
toZModPow_toFun _ _ _
open IntermediateField in
lemma cyclotomicCharacter.continuous (p : ℕ) [Fact p.Prime]
(K L : Type*) [Field K] [Field L] [Algebra K L] :
Continuous ((cyclotomicCharacter L p).comp (MulSemiringAction.toRingAut Gal(L/K) L)) := by
by_cases H : ∀ (i : ℕ), ∃ ζ : L, IsPrimitiveRoot ζ (p ^ i); swap
· simp only [cyclotomicCharacter, cyclotomicCharacter.toFun, dif_neg H, MonoidHom.coe_comp]
exact continuous_const (y := 1)
haveI _ (i) : HasEnoughRootsOfUnity L (p ^ i) := ⟨H i, rootsOfUnity.isCyclic _ _⟩
choose ζ hζ using H
refine Continuous.of_coeHom_comp ?_
apply continuous_of_continuousAt_one
rw [ContinuousAt, map_one, (galGroupBasis K L).nhds_one_hasBasis.tendsto_iff
(Metric.nhds_basis_ball (α := ℤ_[p]) (x := 1))]
intro ε hε
obtain ⟨k, hk', hk⟩ : ∃ k : ℕ, k ≠ 0 ∧ p ^ (-k : ℤ) < ε := by
obtain ⟨k, hk⟩ := PadicInt.exists_pow_neg_lt p hε
exact ⟨k + 1, by simp, lt_of_le_of_lt (by gcongr <;> simp [‹Fact p.Prime›.1.one_le]) hk⟩
refine ⟨_, ⟨_, ⟨(K⟮ζ k⟯), adjoin.finiteDimensional ?_, rfl⟩, rfl⟩, ?_⟩
· exact ((hζ k).isIntegral (Nat.pos_of_neZero _)).tower_top
· intro σ hσ
refine lt_of_le_of_lt ?_ hk
dsimp
rw [dist_eq_norm, PadicInt.norm_le_pow_iff_mem_span_pow, ← PadicInt.ker_toZModPow,
RingHom.mem_ker, map_sub, map_one, cyclotomicCharacter.toZModPow,
sub_eq_zero, eq_comm]
apply modularCyclotomicCharacter.unique
intro t ht
obtain ⟨i, hi, rfl⟩ := ((hζ k).isUnit_unit NeZero.out).eq_pow_of_mem_rootsOfUnity ht
rw [ZMod.val_one'', pow_one]
· exact hσ ⟨ζ k ^ i, pow_mem (mem_adjoin_simple_self K (ζ k)) _⟩
· exact (one_lt_pow₀ ‹Fact p.Prime›.1.one_lt hk').ne'
@[deprecated (since := "2025-05-02")]
alias ModularCyclotomicCharacter.aux := modularCyclotomicCharacter.aux
@[deprecated (since := "2025-05-02")]
alias ModularCyclotomicCharacter.aux_spec := modularCyclotomicCharacter.aux_spec
@[deprecated (since := "2025-05-02")]
alias ModularCyclotomicCharacter.pow_dvd_aux_pow_sub_aux_pow :=
modularCyclotomicCharacter.pow_dvd_aux_pow_sub_aux_pow
@[deprecated (since := "2025-05-02")]
alias ModularCyclotomicCharacter.toFun := modularCyclotomicCharacter.toFun
@[deprecated (since := "2025-05-02")]
alias ModularCyclotomicCharacter.toFun_spec := modularCyclotomicCharacter.toFun_spec
@[deprecated (since := "2025-05-02")]
alias ModularCyclotomicCharacter.toFun_spec' := modularCyclotomicCharacter.toFun_spec'
@[deprecated (since := "2025-05-02")]
alias ModularCyclotomicCharacter.toFun_spec'' := modularCyclotomicCharacter.toFun_spec''
@[deprecated (since := "2025-05-02")]
alias ModularCyclotomicCharacter.toFun_unique := modularCyclotomicCharacter.toFun_unique
@[deprecated (since := "2025-05-02")]
alias ModularCyclotomicCharacter.toFun_unique' := modularCyclotomicCharacter.toFun_unique'
@[deprecated (since := "2025-05-02")]
alias ModularCyclotomicCharacter.id := modularCyclotomicCharacter.id
@[deprecated (since := "2025-05-02")]
alias ModularCyclotomicCharacter.comp := modularCyclotomicCharacter.comp
@[deprecated (since := "2025-05-02")]
alias ModularCyclotomicCharacter' := modularCyclotomicCharacter'
@[deprecated (since := "2025-05-02")]
alias ModularCyclotomicCharacter'.spec' := modularCyclotomicCharacter'.spec'
@[deprecated (since := "2025-05-02")]
alias ModularCyclotomicCharacter'.unique' := modularCyclotomicCharacter'.unique'
@[deprecated (since := "2025-05-02")]
alias ModularCyclotomicCharacter := modularCyclotomicCharacter
@[deprecated (since := "2025-05-02")]
alias ModularCyclotomicCharacter.spec := modularCyclotomicCharacter.spec
@[deprecated (since := "2025-05-02")]
alias ModularCyclotomicCharacter.unique := modularCyclotomicCharacter.unique
@[deprecated (since := "2025-05-02")]
alias IsPrimitiveRoot.autToPow_eq_ModularCyclotomicCharacter :=
IsPrimitiveRoot.autToPow_eq_modularCyclotomicCharacter
@[deprecated (since := "2025-05-02")]
alias CyclotomicCharacter.toFun := cyclotomicCharacter.toFun
@[deprecated (since := "2025-05-02")]
alias CyclotomicCharacter.toFun_apply := cyclotomicCharacter.toFun_apply
@[deprecated (since := "2025-05-02")]
alias CyclotomicCharacter.toZModPow_toFun := cyclotomicCharacter.toZModPow_toFun
@[deprecated (since := "2025-05-02")]
alias CyclotomicCharacter.toFun_spec := cyclotomicCharacter.toFun_spec
@[deprecated (since := "2025-05-02")]
alias CyclotomicCharacter := cyclotomicCharacter
@[deprecated (since := "2025-05-02")]
alias CyclotomicCharacter.spec := cyclotomicCharacter.spec
@[deprecated (since := "2025-05-02")]
alias CyclotomicCharacter.toZModPow := cyclotomicCharacter.toZModPow
@[deprecated (since := "2025-05-02")]
alias CyclotomicCharacter.continuous := cyclotomicCharacter.continuous |
.lake/packages/mathlib/Mathlib/NumberTheory/Cyclotomic/Three.lean | import Mathlib.NumberTheory.NumberField.Cyclotomic.Three
deprecated_module (since := "2025-10-14") |
.lake/packages/mathlib/Mathlib/NumberTheory/Cyclotomic/PrimitiveRoots.lean | import Mathlib.Data.Nat.Factorization.LCM
import Mathlib.Data.Nat.Factorization.PrimePow
import Mathlib.Data.PNat.Prime
import Mathlib.NumberTheory.Cyclotomic.Basic
import Mathlib.RingTheory.Adjoin.PowerBasis
import Mathlib.RingTheory.Norm.Transitivity
import Mathlib.RingTheory.Polynomial.Cyclotomic.Eval
import Mathlib.RingTheory.Polynomial.Cyclotomic.Expand
import Mathlib.RingTheory.SimpleModule.Basic
/-!
# Primitive roots in cyclotomic fields
If `IsCyclotomicExtension {n} A B`, we define an element `zeta n A B : B` that is a primitive
`n`th-root of unity in `B` and we study its properties. We also prove related theorems under the
more general assumption of just being a primitive root, for reasons described in the implementation
details section.
## Main definitions
* `IsCyclotomicExtension.zeta n A B`: if `IsCyclotomicExtension {n} A B`, than `zeta n A B`
is a primitive `n`-th root of unity in `B`.
* `IsPrimitiveRoot.powerBasis`: if `K` and `L` are fields such that
`IsCyclotomicExtension {n} K L`, then `IsPrimitiveRoot.powerBasis`
gives a `K`-power basis for `L` given a primitive root `ζ`.
* `IsPrimitiveRoot.embeddingsEquivPrimitiveRoots`: the equivalence between `L →ₐ[K] A`
and `primitiveRoots n A` given by the choice of `ζ`.
## Main results
* `IsCyclotomicExtension.zeta_spec`: `zeta n A B` is a primitive `n`-th root of unity.
* `IsCyclotomicExtension.finrank`: if `Irreducible (cyclotomic n K)` (in particular for
`K = ℚ`), then the `finrank` of a cyclotomic extension is `n.totient`.
* `IsPrimitiveRoot.norm_eq_one`: if `Irreducible (cyclotomic n K)` (in particular for `K = ℚ`),
the norm of a primitive root is `1` if `n ≠ 2`.
* `IsPrimitiveRoot.sub_one_norm_eq_eval_cyclotomic`: if `Irreducible (cyclotomic n K)`
(in particular for `K = ℚ`), then the norm of `ζ - 1` is `eval 1 (cyclotomic n ℤ)`, for a
primitive root `ζ`. We also prove the analogous of this result for `zeta`.
* `IsPrimitiveRoot.norm_pow_sub_one_of_prime_pow_ne_two` : if
`Irreducible (cyclotomic (p ^ (k + 1)) K)` (in particular for `K = ℚ`) and `p` is a prime,
then the norm of `ζ ^ (p ^ s) - 1` is `p ^ (p ^ s)` `p ^ (k - s + 1) ≠ 2`. See the following
lemmas for similar results. We also prove the analogous of this result for `zeta`.
* `IsPrimitiveRoot.norm_sub_one_of_prime_ne_two` : if `Irreducible (cyclotomic (p ^ (k + 1)) K)`
(in particular for `K = ℚ`) and `p` is an odd prime, then the norm of `ζ - 1` is `p`. We also
prove the analogous of this result for `zeta`.
* `IsPrimitiveRoot.embeddingsEquivPrimitiveRoots`: the equivalence between `L →ₐ[K] A`
and `primitiveRoots n A` given by the choice of `ζ`.
## Implementation details
`zeta n A B` is defined as any primitive root of unity in `B`, - this must exist, by definition of
`IsCyclotomicExtension`. It is not true in general that it is a root of `cyclotomic n B`,
but this holds if `isDomain B` and `NeZero (n : B)`.
`zeta n A B` is defined using `Exists.choose`, which means we cannot control it.
For example, in normal mathematics, we can demand that `(zeta p ℤ ℤ[ζₚ] : ℚ(ζₚ))` is equal to
`zeta p ℚ ℚ(ζₚ)`, as we are just choosing "an arbitrary primitive root" and we can internally
specify that our choices agree. This is not the case here, and it is indeed impossible to prove that
these two are equal. Therefore, whenever possible, we prove our results for any primitive root,
and only at the "final step", when we need to provide an "explicit" primitive root, we use `zeta`.
-/
open Polynomial Algebra Finset Module IsCyclotomicExtension Nat PNat Set
open scoped IntermediateField
universe u v w z
variable {p n : ℕ} [NeZero n] (A : Type w) (B : Type z) (K : Type u) {L : Type v} (C : Type w)
variable [CommRing A] [CommRing B] [Algebra A B] [IsCyclotomicExtension {n} A B]
section Zeta
namespace IsCyclotomicExtension
variable (n)
/-- If `B` is an `n`-th cyclotomic extension of `A`, then `zeta n A B` is a primitive root of
unity in `B`. -/
noncomputable def zeta : B :=
(exists_isPrimitiveRoot A B (Set.mem_singleton n) (NeZero.ne _) :
∃ r : B, IsPrimitiveRoot r n).choose
/-- `zeta n A B` is a primitive `n`-th root of unity. -/
@[simp]
theorem zeta_spec : IsPrimitiveRoot (zeta n A B) n :=
(exists_isPrimitiveRoot A B (Set.mem_singleton n) (NeZero.ne _) :
∃ r : B, IsPrimitiveRoot r n).choose_spec
theorem aeval_zeta [IsDomain B] [NeZero (n : B)] :
aeval (zeta n A B) (cyclotomic n A) = 0 := by
rw [aeval_def, ← eval_map, ← IsRoot.def, map_cyclotomic, isRoot_cyclotomic_iff]
exact zeta_spec n A B
theorem zeta_isRoot [IsDomain B] [NeZero (n : B)] : IsRoot (cyclotomic n B) (zeta n A B) := by
convert aeval_zeta n A B using 0
rw [IsRoot.def, aeval_def, eval₂_eq_eval_map, map_cyclotomic]
theorem zeta_pow : zeta n A B ^ n = 1 :=
(zeta_spec n A B).pow_eq_one
end IsCyclotomicExtension
end Zeta
section NoOrder
variable [Field K] [CommRing L] [IsDomain L] [Algebra K L] [IsCyclotomicExtension {n} K L] {ζ : L}
(hζ : IsPrimitiveRoot ζ n)
namespace IsPrimitiveRoot
variable {C}
/-- The `PowerBasis` given by a primitive root `η`. -/
@[simps!]
protected noncomputable def powerBasis : PowerBasis K L :=
-- this is purely an optimization
letI pb := Algebra.adjoin.powerBasis <| (integral {n} K L).isIntegral ζ
pb.map <| (Subalgebra.equivOfEq _ _ (IsCyclotomicExtension.adjoin_primitive_root_eq_top hζ)).trans
Subalgebra.topEquiv
theorem powerBasis_gen_mem_adjoin_zeta_sub_one :
(hζ.powerBasis K).gen ∈ adjoin K ({ζ - 1} : Set L) := by
rw [powerBasis_gen, adjoin_singleton_eq_range_aeval, AlgHom.mem_range]
exact ⟨X + 1, by simp⟩
/-- The `PowerBasis` given by `η - 1`. -/
@[simps!]
noncomputable def subOnePowerBasis : PowerBasis K L := by
apply PowerBasis.ofAdjoinEqTop (((integral {n} K L).isIntegral ζ).sub isIntegral_one)
exact PowerBasis.adjoin_eq_top_of_gen_mem_adjoin (hζ.powerBasis_gen_mem_adjoin_zeta_sub_one _)
variable {K} (C)
-- We are not using @[simps] to avoid a timeout.
/-- The equivalence between `L →ₐ[K] C` and `primitiveRoots n C` given by a primitive root `ζ`. -/
noncomputable def embeddingsEquivPrimitiveRoots (C : Type*) [CommRing C] [IsDomain C] [Algebra K C]
(hirr : Irreducible (cyclotomic n K)) : (L →ₐ[K] C) ≃ primitiveRoots n C :=
(hζ.powerBasis K).liftEquiv.trans
{ toFun := fun x => by
haveI := IsCyclotomicExtension.neZero' n K L
haveI hn := NeZero.of_faithfulSMul K C n
refine ⟨x.1, ?_⟩
cases x
rwa [mem_primitiveRoots (NeZero.pos _), ← isRoot_cyclotomic_iff, IsRoot.def,
← map_cyclotomic _ (algebraMap K C), hζ.minpoly_eq_cyclotomic_of_irreducible hirr,
← eval₂_eq_eval_map, ← aeval_def]
invFun := fun x => by
haveI := IsCyclotomicExtension.neZero' n K L
haveI hn := NeZero.of_faithfulSMul K C n
refine ⟨x.1, ?_⟩
cases x
rwa [aeval_def, eval₂_eq_eval_map, hζ.powerBasis_gen K, ←
hζ.minpoly_eq_cyclotomic_of_irreducible hirr, map_cyclotomic, ← IsRoot.def,
isRoot_cyclotomic_iff, ← mem_primitiveRoots (NeZero.pos _)] }
-- Porting note: renamed argument `φ`: "expected '_' or identifier"
@[simp]
theorem embeddingsEquivPrimitiveRoots_apply_coe (C : Type*) [CommRing C] [IsDomain C] [Algebra K C]
(hirr : Irreducible (cyclotomic n K)) (φ' : L →ₐ[K] C) :
(hζ.embeddingsEquivPrimitiveRoots C hirr φ' : C) = φ' ζ :=
rfl
end IsPrimitiveRoot
namespace IsCyclotomicExtension
variable {K} (L)
/-- If `Irreducible (cyclotomic n K)` (in particular for `K = ℚ`), then the `finrank` of a
cyclotomic extension is `n.totient`. -/
theorem finrank (hirr : Irreducible (cyclotomic n K)) : finrank K L = n.totient := by
haveI := IsCyclotomicExtension.neZero' n K L
rw [((zeta_spec n K L).powerBasis K).finrank, IsPrimitiveRoot.powerBasis_dim, ←
(zeta_spec n K L).minpoly_eq_cyclotomic_of_irreducible hirr, natDegree_cyclotomic]
variable {L} in
/-- If `L` contains both a primitive `p`-th root of unity and `q`-th root of unity, and
`Irreducible (cyclotomic (lcm p q) K)` (in particular for `K = ℚ`), then the `finrank K L` is at
least `(lcm p q).totient`. -/
theorem _root_.IsPrimitiveRoot.lcm_totient_le_finrank [FiniteDimensional K L] {p q : ℕ} {x y : L}
(hx : IsPrimitiveRoot x p) (hy : IsPrimitiveRoot y q)
(hirr : Irreducible (cyclotomic (Nat.lcm p q) K)) :
(Nat.lcm p q).totient ≤ Module.finrank K L := by
rcases Nat.eq_zero_or_pos p with (rfl | hppos)
· simp
rcases Nat.eq_zero_or_pos q with (rfl | hqpos)
· simp
let z := x ^ (p / factorizationLCMLeft p q) * y ^ (q / factorizationLCMRight p q)
let k := PNat.lcm ⟨p, hppos⟩ ⟨q, hqpos⟩
have : IsPrimitiveRoot z k := hx.pow_mul_pow_lcm hy hppos.ne' hqpos.ne'
haveI := IsPrimitiveRoot.adjoin_isCyclotomicExtension K this
convert Submodule.finrank_le (Subalgebra.toSubmodule (adjoin K {z}))
rw [show Nat.lcm p q = (k : ℕ) from rfl] at hirr
simpa using (IsCyclotomicExtension.finrank (Algebra.adjoin K {z}) hirr).symm
end IsCyclotomicExtension
end NoOrder
section Norm
namespace IsPrimitiveRoot
section Field
variable {K} [Field K] [NumberField K]
variable (n) in
/-- If a `n`-th cyclotomic extension of `ℚ` contains a primitive `l`-th root of unity, then
`l ∣ 2 * n`. -/
theorem dvd_of_isCyclotomicExtension [IsCyclotomicExtension {n} ℚ K] {ζ : K}
{l : ℕ} (hζ : IsPrimitiveRoot ζ l) (hl : l ≠ 0) : l ∣ 2 * n := by
have hl : NeZero l := ⟨hl⟩
have hroot := IsCyclotomicExtension.zeta_spec n ℚ K
have key := IsPrimitiveRoot.lcm_totient_le_finrank hζ hroot
(cyclotomic.irreducible_rat <| Nat.lcm_pos (Nat.pos_of_ne_zero hl.1) (NeZero.pos n))
rw [IsCyclotomicExtension.finrank K (cyclotomic.irreducible_rat (NeZero.pos n))] at key
rcases _root_.dvd_lcm_right l n with ⟨r, hr⟩
have ineq := Nat.totient_super_multiplicative n r
rw [← hr] at ineq
replace key := (mul_le_iff_le_one_right (Nat.totient_pos.2 (NeZero.pos n))).mp (le_trans ineq key)
have rpos : 0 < r := by
refine Nat.pos_of_ne_zero (fun h ↦ ?_)
simp only [h, mul_zero, _root_.lcm_eq_zero_iff, NeZero.ne _, or_false] at hr
replace key := (Nat.dvd_prime Nat.prime_two).1 (Nat.dvd_two_of_totient_le_one rpos key)
rcases key with (key | key)
· rw [key, mul_one] at hr
rw [← hr]
exact dvd_mul_of_dvd_right (_root_.dvd_lcm_left l n) 2
· rw [key, mul_comm] at hr
simpa [← hr] using _root_.dvd_lcm_left _ _
/-- If `x` is a root of unity (spelled as `IsOfFinOrder x`) in an `n`-th cyclotomic extension of
`ℚ`, where `n` is odd, and `ζ` is a primitive `n`-th root of unity, then there exist `r`
such that `x = (-ζ)^r`. -/
theorem exists_neg_pow_of_isOfFinOrder [IsCyclotomicExtension {n} ℚ K]
(hno : Odd n) {ζ x : K} (hζ : IsPrimitiveRoot ζ n) (hx : IsOfFinOrder x) :
∃ r : ℕ, x = (-ζ) ^ r := by
have hnegζ : IsPrimitiveRoot (-ζ) (2 * n) := by
convert IsPrimitiveRoot.orderOf (-ζ)
rw [neg_eq_neg_one_mul, (Commute.all _ _).orderOf_mul_eq_mul_orderOf_of_coprime]
· simp [hζ.eq_orderOf]
· simp [← hζ.eq_orderOf, hno]
obtain ⟨k, hkpos, hkn⟩ := isOfFinOrder_iff_pow_eq_one.1 hx
obtain ⟨l, hl, hlroot⟩ := (isRoot_of_unity_iff hkpos _).1 hkn
have hlzero : NeZero l := ⟨fun h ↦ by simp [h] at hl⟩
have : NeZero (l : K) := ⟨NeZero.natCast_ne l K⟩
rw [isRoot_cyclotomic_iff] at hlroot
obtain ⟨a, ha⟩ := hlroot.dvd_of_isCyclotomicExtension n hlzero.1
replace hlroot : x ^ (2 * n) = 1 := by rw [ha, pow_mul, hlroot.pow_eq_one, one_pow]
obtain ⟨s, -, hs⟩ := hnegζ.eq_pow_of_pow_eq_one hlroot
exact ⟨s, hs.symm⟩
/-- If `x` is a root of unity (spelled as `IsOfFinOrder x`) in an `n`-th cyclotomic extension of
`ℚ`, where `n` is odd, and `ζ` is a primitive `n`-th root of unity, then there exists `r < n`
such that `x = ζ^r` or `x = -ζ^r`. -/
theorem exists_pow_or_neg_mul_pow_of_isOfFinOrder [IsCyclotomicExtension {n} ℚ K]
(hno : Odd n) {ζ x : K} (hζ : IsPrimitiveRoot ζ n) (hx : IsOfFinOrder x) :
∃ r : ℕ, r < n ∧ (x = ζ ^ r ∨ x = -ζ ^ r) := by
obtain ⟨r, hr⟩ := hζ.exists_neg_pow_of_isOfFinOrder hno hx
refine ⟨r % n, Nat.mod_lt _ (NeZero.pos _), ?_⟩
rw [show ζ ^ (r % n) = ζ ^ r from (IsPrimitiveRoot.eq_orderOf hζ).symm ▸ pow_mod_orderOf .., hr]
rcases Nat.even_or_odd r with (h | h) <;> simp [neg_pow, h.neg_one_pow]
end Field
section CommRing
variable [CommRing L] {ζ : L}
variable {K} [Field K] [Algebra K L]
/-- This mathematically trivial result is complementary to `norm_eq_one` below. -/
theorem norm_eq_neg_one_pow (hζ : IsPrimitiveRoot ζ 2) [IsDomain L] :
norm K ζ = (-1 : K) ^ finrank K L := by
rw [hζ.eq_neg_one_of_two_right, show -1 = algebraMap K L (-1) by simp, Algebra.norm_algebraMap]
variable (hζ : IsPrimitiveRoot ζ n)
include hζ
/-- If `Irreducible (cyclotomic n K)` (in particular for `K = ℚ`), the norm of a primitive root is
`1` if `n ≠ 2`. -/
theorem norm_eq_one [IsDomain L] [IsCyclotomicExtension {n} K L] (hn : n ≠ 2)
(hirr : Irreducible (cyclotomic n K)) : norm K ζ = 1 := by
haveI := IsCyclotomicExtension.neZero' n K L
by_cases h1 : n = 1
· rw [h1, one_right_iff] at hζ
rw [hζ, show 1 = algebraMap K L 1 by simp, Algebra.norm_algebraMap, one_pow]
· replace h1 : 2 ≤ n := (two_le_iff n).mpr ⟨NeZero.ne _, h1⟩
rw [← hζ.powerBasis_gen K, PowerBasis.norm_gen_eq_coeff_zero_minpoly, hζ.powerBasis_gen K,
← hζ.minpoly_eq_cyclotomic_of_irreducible hirr, cyclotomic_coeff_zero K h1, mul_one,
hζ.powerBasis_dim K, ← hζ.minpoly_eq_cyclotomic_of_irreducible hirr, natDegree_cyclotomic]
exact (totient_even <| h1.lt_of_ne hn.symm).neg_one_pow
omit [NeZero n] in
/-- If `K` is linearly ordered, the norm of a primitive root is `1` if `n` is odd. -/
theorem norm_eq_one_of_linearly_ordered {K : Type*}
[Field K] [LinearOrder K] [IsStrictOrderedRing K] [Algebra K L] (hodd : Odd n) :
norm K ζ = 1 := by
have hz := congr_arg (norm K) ((IsPrimitiveRoot.iff_def _ n).1 hζ).1
rw [← (algebraMap K L).map_one, Algebra.norm_algebraMap, one_pow, map_pow, ← one_pow n] at hz
exact StrictMono.injective hodd.strictMono_pow hz
theorem norm_of_cyclotomic_irreducible [IsDomain L] [IsCyclotomicExtension {n} K L]
(hirr : Irreducible (cyclotomic n K)) : norm K ζ = ite (n = 2) (-1) 1 := by
split_ifs with hn
· subst hn
rw [norm_eq_neg_one_pow (K := K) hζ, IsCyclotomicExtension.finrank _ hirr]
norm_cast
· exact hζ.norm_eq_one hn hirr
end CommRing
section Field
variable [Field L] {ζ : L}
variable {K} [Field K] [Algebra K L]
section
variable (hζ : IsPrimitiveRoot ζ n)
include hζ
/-- If `Irreducible (cyclotomic n K)` (in particular for `K = ℚ`), then the norm of
`ζ - 1` is `eval 1 (cyclotomic n ℤ)`. -/
theorem sub_one_norm_eq_eval_cyclotomic [IsCyclotomicExtension {n} K L] (h : 2 < n)
(hirr : Irreducible (cyclotomic n K)) : norm K (ζ - 1) = ↑(eval 1 (cyclotomic n ℤ)) := by
haveI := IsCyclotomicExtension.neZero' n K L
let E := AlgebraicClosure L
obtain ⟨z, hz⟩ := IsAlgClosed.exists_root _ (degree_cyclotomic_pos n E (NeZero.pos _)).ne.symm
apply (algebraMap K E).injective
letI := IsCyclotomicExtension.finiteDimensional {n} K L
letI := IsCyclotomicExtension.isGalois {n} K L
rw [norm_eq_prod_embeddings]
conv_lhs =>
congr
rfl
ext
rw [← neg_sub, map_neg, map_sub, map_one, neg_eq_neg_one_mul]
rw [prod_mul_distrib, prod_const, Finset.card_univ, AlgHom.card,
IsCyclotomicExtension.finrank L hirr, (totient_even h).neg_one_pow, one_mul]
have Hprod : (Finset.univ.prod fun σ : L →ₐ[K] E => 1 - σ ζ) = eval 1 (cyclotomic' n E) := by
rw [cyclotomic', eval_prod, ← @Finset.prod_attach E E, ← univ_eq_attach]
refine Fintype.prod_equiv (hζ.embeddingsEquivPrimitiveRoots E hirr) _ _ fun σ => ?_
simp
have : NeZero (n : E) := NeZero.of_faithfulSMul K _ n
rw [Hprod, cyclotomic', ← cyclotomic_eq_prod_X_sub_primitiveRoots (isRoot_cyclotomic_iff.1 hz),
← map_cyclotomic_int, _root_.map_intCast, ← Int.cast_one, eval_intCast_map, eq_intCast,
Int.cast_id]
/-- If `IsPrimePow n`, `n ≠ 2` and `Irreducible (cyclotomic n K)` (in particular for
`K = ℚ`), then the norm of `ζ - 1` is `n.minFac`. -/
theorem sub_one_norm_isPrimePow (hn : IsPrimePow n) [IsCyclotomicExtension {n} K L]
(hirr : Irreducible (cyclotomic n K)) (h : n ≠ 2) : norm K (ζ - 1) = n.minFac := by
have := (lt_of_le_of_ne (succ_le_of_lt (IsPrimePow.one_lt hn)) h.symm)
let hprime : Fact n.minFac.Prime := ⟨minFac_prime (IsPrimePow.ne_one hn)⟩
rw [sub_one_norm_eq_eval_cyclotomic hζ this hirr]
nth_rw 1 [← IsPrimePow.minFac_pow_factorization_eq hn]
obtain ⟨k, hk⟩ : ∃ k, n.factorization n.minFac = k + 1 :=
exists_eq_succ_of_ne_zero
((n.factorization.mem_support_toFun n.minFac).1 <|
mem_primeFactors_iff_mem_primeFactorsList.2 <|
(mem_primeFactorsList (IsPrimePow.ne_zero hn)).2 ⟨hprime.out, minFac_dvd _⟩)
simp [hk]
end
variable {A}
theorem minpoly_sub_one_eq_cyclotomic_comp [Algebra K A] [IsDomain A] {ζ : A}
[IsCyclotomicExtension {n} K A] (hζ : IsPrimitiveRoot ζ n)
(h : Irreducible (Polynomial.cyclotomic n K)) :
minpoly K (ζ - 1) = (cyclotomic n K).comp (X + 1) := by
haveI := IsCyclotomicExtension.neZero' n K A
rw [show ζ - 1 = ζ + algebraMap K A (-1) by simp [sub_eq_add_neg],
minpoly.add_algebraMap ζ,
hζ.minpoly_eq_cyclotomic_of_irreducible h]
simp
open scoped Cyclotomic
/-- If `Irreducible (cyclotomic (p ^ (k + 1)) K)` (in particular for `K = ℚ`) and `p` is a prime,
then the norm of `ζ ^ (p ^ s) - 1` is `p ^ (p ^ s)` if `p ^ (k - s + 1) ≠ 2`. See the next lemmas
for similar results. -/
theorem norm_pow_sub_one_of_prime_pow_ne_two {k s : ℕ} (hζ : IsPrimitiveRoot ζ (p ^ (k + 1)))
[hpri : Fact p.Prime] [IsCyclotomicExtension {p ^ (k + 1)} K L]
(hirr : Irreducible (cyclotomic (p ^ (k + 1)) K)) (hs : s ≤ k)
(htwo : p ^ (k - s + 1) ≠ 2) : norm K (ζ ^ p ^ s - 1) = (p : K) ^ p ^ s := by
have hirr₁ : Irreducible (cyclotomic (p ^ (k - s + 1)) K) :=
cyclotomic_irreducible_pow_of_irreducible_pow hpri.1 (by cutsat) hirr
set η := ζ ^ p ^ s - 1
let η₁ : K⟮η⟯ := IntermediateField.AdjoinSimple.gen K η
have hη : IsPrimitiveRoot (η + 1) (p ^ (k + 1 - s)) := by
rw [sub_add_cancel]
refine IsPrimitiveRoot.pow (pos_of_neZero (p ^ (k + 1))) hζ ?_
rw [← pow_add, add_comm s, Nat.sub_add_cancel (le_trans hs (Nat.le_succ k))]
have : IsCyclotomicExtension {p ^ (k - s + 1)} K K⟮η⟯ := by
have HKη : K⟮η⟯ = K⟮η + 1⟯ := by
refine le_antisymm ?_ ?_
all_goals rw [IntermediateField.adjoin_simple_le_iff]
· nth_rw 2 [← add_sub_cancel_right η 1]
exact sub_mem (IntermediateField.mem_adjoin_simple_self K (η + 1)) (one_mem _)
· exact add_mem (IntermediateField.mem_adjoin_simple_self K η) (one_mem _)
rw [HKη]
have H := IntermediateField.adjoin_simple_toSubalgebra_of_integral
((integral {p ^ (k + 1)} K L).isIntegral (η + 1))
refine IsCyclotomicExtension.equiv _ _ _ (h := ?_) (.refl : K⟮η + 1⟯.toSubalgebra ≃ₐ[K] _)
rw [H]
have hη' : IsPrimitiveRoot (η + 1) (p ^ (k + 1 - s)) := by simpa using hη
convert hη'.adjoin_isCyclotomicExtension K using 1
rw [Nat.sub_add_comm hs]
replace hη : IsPrimitiveRoot (η₁ + 1) (p ^ (k - s + 1)) := by
apply coe_submonoidClass_iff.1
convert hη using 1
rw [Nat.sub_add_comm hs]
have := IsCyclotomicExtension.finiteDimensional {p ^ (k + 1)} K L
have := IsCyclotomicExtension.isGalois {p ^ (k + 1)} K L
rw [norm_eq_norm_adjoin K]
have H := hη.sub_one_norm_isPrimePow ?_ hirr₁ htwo
swap; · exact hpri.1.isPrimePow.pow (Nat.succ_ne_zero _)
rw [add_sub_cancel_right] at H
rw [H]
congr
· rw [Nat.pow_minFac, hpri.1.minFac_eq]
exact Nat.succ_ne_zero _
have := Module.finrank_mul_finrank K K⟮η⟯ L
rw [IsCyclotomicExtension.finrank L hirr, IsCyclotomicExtension.finrank K⟮η⟯ hirr₁,
Nat.totient_prime_pow hpri.out (k - s).succ_pos, Nat.totient_prime_pow hpri.out k.succ_pos,
mul_comm _ (p - 1), mul_assoc, mul_comm (p ^ (k.succ - 1))] at this
replace this := mul_left_cancel₀ (tsub_pos_iff_lt.2 hpri.out.one_lt).ne' this
have Hex : k.succ - 1 = (k - s).succ - 1 + s := by
simp only [Nat.succ_sub_succ_eq_sub, tsub_zero]
exact (Nat.sub_add_cancel hs).symm
rw [Hex, pow_add] at this
exact mul_left_cancel₀ (pow_ne_zero _ hpri.out.ne_zero) this
/-- If `Irreducible (cyclotomic (p ^ (k + 1)) K)` (in particular for `K = ℚ`) and `p` is a prime,
then the norm of `ζ ^ (p ^ s) - 1` is `p ^ (p ^ s)` if `p ≠ 2`. -/
theorem norm_pow_sub_one_of_prime_ne_two {k : ℕ} (hζ : IsPrimitiveRoot ζ (p ^ (k + 1)))
[hpri : Fact p.Prime] [IsCyclotomicExtension {p ^ (k + 1)} K L]
(hirr : Irreducible (cyclotomic (p ^ (k + 1)) K)) {s : ℕ} (hs : s ≤ k) (hodd : p ≠ 2) :
norm K (ζ ^ p ^ s - 1) = (p : K) ^ p ^ s := by
refine hζ.norm_pow_sub_one_of_prime_pow_ne_two hirr hs fun h => ?_
rw [← pow_one 2] at h
replace h :=
eq_of_prime_pow_eq (prime_iff.1 hpri.out) (prime_iff.1 Nat.prime_two) (k - s).succ_pos h
exact hodd h
/-- If `Irreducible (cyclotomic (p ^ (k + 1)) K)` (in particular for `K = ℚ`) and `p` is an odd
prime, then the norm of `ζ - 1` is `p`. -/
theorem norm_sub_one_of_prime_ne_two {k : ℕ} (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1)))
[hpri : Fact p.Prime] [IsCyclotomicExtension {p ^ (k + 1)} K L]
(hirr : Irreducible (cyclotomic (p ^ (k + 1)) K)) (h : p ≠ 2) : norm K (ζ - 1) = p := by
simpa using hζ.norm_pow_sub_one_of_prime_ne_two hirr k.zero_le h
/-- If `Irreducible (cyclotomic p K)` (in particular for `K = ℚ`) and `p` is an odd prime,
then the norm of `ζ - 1` is `p`. -/
theorem norm_sub_one_of_prime_ne_two' [hpri : Fact p.Prime]
[hcyc : IsCyclotomicExtension {p} K L] (hζ : IsPrimitiveRoot ζ p)
(hirr : Irreducible (cyclotomic p K)) (h : p ≠ 2) : norm K (ζ - 1) = p := by
replace hirr : Irreducible (cyclotomic (p ^ (0 + 1)) K) := by simp [hirr]
replace hζ : IsPrimitiveRoot ζ (p ^ (0 + 1)) := by simp [hζ]
haveI : IsCyclotomicExtension {p ^ (0 + 1)} K L := by simp [hcyc]
simpa using norm_sub_one_of_prime_ne_two hζ hirr h
/-- If `Irreducible (cyclotomic (2 ^ (k + 1)) K)` (in particular for `K = ℚ`), then the norm of
`ζ ^ (2 ^ k) - 1` is `(-2) ^ (2 ^ k)`. -/
theorem norm_pow_sub_one_two {k : ℕ} (hζ : IsPrimitiveRoot ζ (2 ^ (k + 1)))
[IsCyclotomicExtension {2 ^ (k + 1)} K L]
(hirr : Irreducible (cyclotomic (2 ^ (k + 1)) K)) :
norm K (ζ ^ 2 ^ k - 1) = (-2 : K) ^ 2 ^ k := by
have := hζ.pow_of_dvd
(fun h => two_ne_zero (eq_zero_of_pow_eq_zero h)) (pow_dvd_pow 2 (le_succ k))
rw [Nat.pow_div (le_succ k) zero_lt_two, Nat.succ_sub (le_refl k), Nat.sub_self, pow_one] at this
have H : (-1 : L) - (1 : L) = algebraMap K L (-2) := by
simp only [map_neg, map_ofNat]
ring
replace hirr : Irreducible (cyclotomic (2 ^ (k + 1)) K) := by simp [hirr]
rw [this.eq_neg_one_of_two_right, H, Algebra.norm_algebraMap,
IsCyclotomicExtension.finrank L hirr, totient_prime_pow Nat.prime_two (zero_lt_succ k),
succ_sub_succ_eq_sub, tsub_zero]
simp
/-- If `Irreducible (cyclotomic (2 ^ k) K)` (in particular for `K = ℚ`) and `k` is at least `2`,
then the norm of `ζ - 1` is `2`. -/
theorem norm_sub_one_two {k : ℕ} (hζ : IsPrimitiveRoot ζ (2 ^ k)) (hk : 2 ≤ k)
[H : IsCyclotomicExtension {2 ^ k} K L] (hirr : Irreducible (cyclotomic (2 ^ k) K)) :
norm K (ζ - 1) = 2 := by
have : 2 < 2 ^ k := by
nth_rw 1 [← pow_one 2]
exact Nat.pow_lt_pow_right one_lt_two (lt_of_lt_of_le one_lt_two hk)
replace hirr : Irreducible (cyclotomic (2 ^ k) K) := by simp [hirr]
replace hζ : IsPrimitiveRoot ζ (2 ^ k) := by simp [hζ]
obtain ⟨k₁, hk₁⟩ := exists_eq_succ_of_ne_zero (lt_of_lt_of_le zero_lt_two hk).ne.symm
simpa [hk₁] using sub_one_norm_eq_eval_cyclotomic hζ this hirr
/-- If `Irreducible (cyclotomic (p ^ (k + 1)) K)` (in particular for `K = ℚ`) and `p` is a prime,
then the norm of `ζ ^ (p ^ s) - 1` is `p ^ (p ^ s)` if `k ≠ 0` and `s ≤ k`. -/
theorem norm_pow_sub_one_eq_prime_pow_of_ne_zero {k s : ℕ} (hζ : IsPrimitiveRoot ζ (p ^ (k + 1)))
[hpri : Fact p.Prime] [hcycl : IsCyclotomicExtension {p ^ (k + 1)} K L]
(hirr : Irreducible (cyclotomic (p ^ (k + 1)) K)) (hs : s ≤ k) (hk : k ≠ 0) :
norm K (ζ ^ p ^ s - 1) = (p : K) ^ p ^ s := by
by_cases htwo : p ^ (k - s + 1) = 2
· have hp : p = 2 := by
rw [← pow_one 2] at htwo
exact eq_of_prime_pow_eq (prime_iff.1 hpri.out) (prime_iff.1 Nat.prime_two) (succ_pos _) htwo
replace hs : s = k := by
rw [hp] at htwo
nth_rw 2 [← pow_one 2] at htwo
replace htwo := Nat.pow_right_injective rfl.le htwo
rw [add_eq_right, Nat.sub_eq_zero_iff_le] at htwo
exact le_antisymm hs htwo
simp only [hp, hs] at hζ hirr hcycl ⊢
obtain ⟨k₁, hk₁⟩ := Nat.exists_eq_succ_of_ne_zero hk
rw [hζ.norm_pow_sub_one_two hirr, hk₁, _root_.pow_succ', pow_mul, neg_eq_neg_one_mul,
mul_pow, neg_one_sq, one_mul, ← pow_mul, ← _root_.pow_succ']
simp
· exact hζ.norm_pow_sub_one_of_prime_pow_ne_two hirr hs htwo
end Field
end IsPrimitiveRoot
namespace IsCyclotomicExtension
open IsPrimitiveRoot
variable {K} (L) [Field K] [Field L] [Algebra K L]
/-- If `Irreducible (cyclotomic n K)` (in particular for `K = ℚ`), the norm of `zeta n K L` is `1`
if `n` is odd. -/
theorem norm_zeta_eq_one [IsCyclotomicExtension {n} K L] (hn : n ≠ 2)
(hirr : Irreducible (cyclotomic n K)) : norm K (zeta n K L) = 1 :=
(zeta_spec n K L).norm_eq_one hn hirr
/-- If `IsPrimePow n`, `n ≠ 2` and `Irreducible (cyclotomic n K)` (in particular for `K = ℚ`),
then the norm of `zeta n K L - 1` is `n.minFac`. -/
theorem norm_zeta_sub_one_of_isPrimePow (hn : IsPrimePow n) [IsCyclotomicExtension {n} K L]
(hirr : Irreducible (cyclotomic n K)) (h : n ≠ 2) :
norm K (zeta n K L - 1) = n.minFac :=
(zeta_spec n K L).sub_one_norm_isPrimePow hn hirr h
/-- If `Irreducible (cyclotomic (p ^ (k + 1)) K)` (in particular for `K = ℚ`) and `p` is a prime,
then the norm of `(zeta (p ^ (k + 1)) K L) ^ (p ^ s) - 1` is `p ^ (p ^ s)`
if `p ^ (k - s + 1) ≠ 2`. -/
theorem norm_zeta_pow_sub_one_of_prime_pow_ne_two {k : ℕ} [Fact p.Prime]
[IsCyclotomicExtension {p ^ (k + 1)} K L]
(hirr : Irreducible (cyclotomic (p ^ (k + 1)) K)) {s : ℕ} (hs : s ≤ k)
(htwo : p ^ (k - s + 1) ≠ 2) :
norm K (zeta (p ^ (k + 1)) K L ^ p ^ s - 1) = (p : K) ^ p ^ s :=
(zeta_spec _ K L).norm_pow_sub_one_of_prime_pow_ne_two hirr hs htwo
/-- If `Irreducible (cyclotomic (p ^ (k + 1)) K)` (in particular for `K = ℚ`) and `p` is an odd
prime, then the norm of `zeta (p ^ (k + 1)) K L - 1` is `p`. -/
theorem norm_zeta_pow_sub_one_of_prime_ne_two {k : ℕ} [Fact p.Prime]
[IsCyclotomicExtension {p ^ (k + 1)} K L]
(hirr : Irreducible (cyclotomic (p ^ (k + 1)) K)) (h : p ≠ 2) :
norm K (zeta (p ^ (k + 1)) K L - 1) = p :=
(zeta_spec _ K L).norm_sub_one_of_prime_ne_two hirr h
/-- If `Irreducible (cyclotomic p K)` (in particular for `K = ℚ`) and `p` is an odd prime,
then the norm of `zeta p K L - 1` is `p`. -/
theorem norm_zeta_sub_one_of_prime_ne_two [Fact p.Prime]
[IsCyclotomicExtension {p} K L] (hirr : Irreducible (cyclotomic p K)) (h : p ≠ 2) :
norm K (zeta p K L - 1) = p :=
(zeta_spec _ K L).norm_sub_one_of_prime_ne_two' hirr h
/-- If `Irreducible (cyclotomic (2 ^ k) K)` (in particular for `K = ℚ`) and `k` is at least `2`,
then the norm of `zeta (2 ^ k) K L - 1` is `2`. -/
theorem norm_zeta_pow_sub_one_two {k : ℕ} (hk : 2 ≤ k)
[IsCyclotomicExtension {2 ^ k} K L] (hirr : Irreducible (cyclotomic (2 ^ k) K)) :
norm K (zeta (2 ^ k) K L - 1) = 2 :=
norm_sub_one_two (zeta_spec (2 ^ k) K L) hk hirr
end IsCyclotomicExtension
end Norm |
.lake/packages/mathlib/Mathlib/NumberTheory/ClassNumber/Finite.lean | import Mathlib.Analysis.SpecialFunctions.Pow.Real
import Mathlib.LinearAlgebra.FreeModule.PID
import Mathlib.LinearAlgebra.Matrix.AbsoluteValue
import Mathlib.NumberTheory.ClassNumber.AdmissibleAbsoluteValue
import Mathlib.RingTheory.ClassGroup
import Mathlib.RingTheory.DedekindDomain.IntegralClosure
import Mathlib.RingTheory.Norm.Basic
/-!
# Class numbers of global fields
In this file, we use the notion of "admissible absolute value" to prove
finiteness of the class group for number fields and function fields.
## Main definitions
- `ClassGroup.fintypeOfAdmissibleOfAlgebraic`: if `R` has an admissible absolute value,
its integral closure has a finite class group
-/
open Module Ring
open scoped nonZeroDivisors
namespace ClassGroup
section EuclideanDomain
variable {R S : Type*} (K L : Type*) [EuclideanDomain R] [CommRing S] [IsDomain S]
variable [Field K] [Field L]
variable [Algebra R K] [IsFractionRing R K]
variable [Algebra K L] [FiniteDimensional K L] [Algebra.IsSeparable K L]
variable [algRL : Algebra R L] [IsScalarTower R K L]
variable [Algebra R S] [Algebra S L]
variable [ist : IsScalarTower R S L]
variable (abv : AbsoluteValue R ℤ)
variable {ι : Type*} [DecidableEq ι] [Fintype ι] (bS : Basis ι R S)
/-- If `b` is an `R`-basis of `S` of cardinality `n`, then `normBound abv b` is an integer
such that for every `R`-integral element `a : S` with coordinates `≤ y`,
we have algebra.norm a ≤ norm_bound abv b * y ^ n`. (See also `norm_le` and `norm_lt`). -/
noncomputable def normBound : ℤ :=
let n := Fintype.card ι
let i : ι := Nonempty.some bS.index_nonempty
let m : ℤ :=
Finset.max'
(Finset.univ.image fun ijk : ι × ι × ι =>
abv (Algebra.leftMulMatrix bS (bS ijk.1) ijk.2.1 ijk.2.2))
⟨_, Finset.mem_image.mpr ⟨⟨i, i, i⟩, Finset.mem_univ _, rfl⟩⟩
Nat.factorial n • (n • m) ^ n
theorem normBound_pos : 0 < normBound abv bS := by
obtain ⟨i, j, k, hijk⟩ : ∃ i j k, Algebra.leftMulMatrix bS (bS i) j k ≠ 0 := by
by_contra! h
obtain ⟨i⟩ := bS.index_nonempty
apply bS.ne_zero i
apply
(injective_iff_map_eq_zero (Algebra.leftMulMatrix bS)).mp (Algebra.leftMulMatrix_injective bS)
ext j k
simp [h]
simp only [normBound, Algebra.smul_def, eq_natCast]
apply mul_pos (Int.natCast_pos.mpr (Nat.factorial_pos _))
refine pow_pos (mul_pos (Int.natCast_pos.mpr (Fintype.card_pos_iff.mpr ⟨i⟩)) ?_) _
refine lt_of_lt_of_le (abv.pos hijk) (Finset.le_max' _ _ ?_)
exact Finset.mem_image.mpr ⟨⟨i, j, k⟩, Finset.mem_univ _, rfl⟩
/-- If the `R`-integral element `a : S` has coordinates `≤ y` with respect to some basis `b`,
its norm is less than `normBound abv b * y ^ dim S`. -/
theorem norm_le (a : S) {y : ℤ} (hy : ∀ k, abv (bS.repr a k) ≤ y) :
abv (Algebra.norm R a) ≤ normBound abv bS * y ^ Fintype.card ι := by
conv_lhs => rw [← bS.sum_repr a]
rw [Algebra.norm_apply, ← LinearMap.det_toMatrix bS]
simp only [map_sum, map_smul, map_sum, map_smul,
normBound, smul_mul_assoc, ← mul_pow]
convert Matrix.det_sum_smul_le Finset.univ _ hy using 3
· rw [Finset.card_univ, smul_mul_assoc, mul_comm]
· intro i j k
apply Finset.le_max'
exact Finset.mem_image.mpr ⟨⟨i, j, k⟩, Finset.mem_univ _, rfl⟩
/-- If the `R`-integral element `a : S` has coordinates `< y` with respect to some basis `b`,
its norm is strictly less than `normBound abv b * y ^ dim S`. -/
theorem norm_lt {T : Type*} [Ring T] [LinearOrder T] [IsStrictOrderedRing T] (a : S) {y : T}
(hy : ∀ k, (abv (bS.repr a k) : T) < y) :
(abv (Algebra.norm R a) : T) < normBound abv bS * y ^ Fintype.card ι := by
obtain ⟨i⟩ := bS.index_nonempty
have him : (Finset.univ.image fun k => abv (bS.repr a k)).Nonempty :=
⟨_, Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩⟩
set y' : ℤ := Finset.max' _ him with y'_def
have hy' : ∀ k, abv (bS.repr a k) ≤ y' := by
intro k
exact @Finset.le_max' ℤ _ _ _ (Finset.mem_image.mpr ⟨k, Finset.mem_univ _, rfl⟩)
have : (y' : T) < y := by
rw [y'_def,
← Finset.max'_image (show Monotone (_ : ℤ → T) from fun x y h => Int.cast_le.mpr h)
_ (him.image _)]
apply (Finset.max'_lt_iff _ (him.image _)).mpr
simp only [Finset.mem_image]
rintro _ ⟨x, ⟨k, -, rfl⟩, rfl⟩
exact hy k
have y'_nonneg : 0 ≤ y' := le_trans (abv.nonneg _) (hy' i)
apply (Int.cast_le.mpr (norm_le abv bS a hy')).trans_lt
simp only [Int.cast_mul, Int.cast_pow]
apply mul_lt_mul' le_rfl
· exact pow_lt_pow_left₀ this (Int.cast_nonneg y'_nonneg) (@Fintype.card_ne_zero _ _ ⟨i⟩)
· exact pow_nonneg (Int.cast_nonneg y'_nonneg) _
· exact Int.cast_pos.mpr (normBound_pos abv bS)
/-- A nonzero ideal has an element of minimal norm. -/
theorem exists_min (I : (Ideal S)⁰) :
∃ b ∈ (I : Ideal S),
b ≠ 0 ∧ ∀ c ∈ (I : Ideal S), abv (Algebra.norm R c) < abv (Algebra.norm R b) → c =
(0 : S) := by
obtain ⟨_, ⟨b, b_mem, b_ne_zero, rfl⟩, min⟩ := @Int.exists_least_of_bdd
(fun a => ∃ b ∈ (I : Ideal S), b ≠ (0 : S) ∧ abv (Algebra.norm R b) = a)
(by
use 0
rintro _ ⟨b, _, _, rfl⟩
apply abv.nonneg)
(by
obtain ⟨b, b_mem, b_ne_zero⟩ := (I : Ideal S).ne_bot_iff.mp (nonZeroDivisors.coe_ne_zero I)
exact ⟨_, ⟨b, b_mem, b_ne_zero, rfl⟩⟩)
refine ⟨b, b_mem, b_ne_zero, ?_⟩
intro c hc lt
contrapose! lt with c_ne_zero
exact min _ ⟨c, hc, c_ne_zero, rfl⟩
section IsAdmissible
variable {abv}
variable (adm : abv.IsAdmissible)
/-- If we have a large enough set of elements in `R^ι`, then there will be a pair
whose remainders are close together. We'll show that all sets of cardinality
at least `cardM bS adm` elements satisfy this condition.
The value of `cardM` is not at all optimal: for specific choices of `R`,
the minimum cardinality can be exponentially smaller.
-/
noncomputable def cardM : ℕ :=
adm.card (normBound abv bS ^ (-1 / Fintype.card ι : ℝ)) ^ Fintype.card ι
variable [Infinite R]
/-- In the following results, we need a large set of distinct elements of `R`. -/
noncomputable def distinctElems : Fin (cardM bS adm).succ ↪ R :=
Fin.valEmbedding.trans (Infinite.natEmbedding R)
variable [DecidableEq R]
/-- `finsetApprox` is a finite set such that each fractional ideal in the integral closure
contains an element close to `finsetApprox`. -/
noncomputable def finsetApprox : Finset R :=
(Finset.univ.image fun xy : _ × _ => distinctElems bS adm xy.1 - distinctElems bS adm xy.2).erase
0
theorem finsetApprox.zero_notMem : (0 : R) ∉ finsetApprox bS adm :=
Finset.notMem_erase _ _
@[deprecated (since := "2025-05-23")] alias finsetApprox.zero_not_mem := finsetApprox.zero_notMem
@[simp]
theorem mem_finsetApprox {x : R} :
x ∈ finsetApprox bS adm ↔ ∃ i j, i ≠ j ∧ distinctElems bS adm i - distinctElems bS adm j =
x := by
simp only [finsetApprox, Finset.mem_erase, Finset.mem_image]
constructor
· rintro ⟨hx, ⟨i, j⟩, _, rfl⟩
refine ⟨i, j, ?_, rfl⟩
rintro rfl
simp at hx
· rintro ⟨i, j, hij, rfl⟩
refine ⟨?_, ⟨i, j⟩, Finset.mem_univ _, rfl⟩
rw [Ne, sub_eq_zero]
exact fun h => hij ((distinctElems bS adm).injective h)
section Real
open Real
attribute [-instance] Real.decidableEq
/-- We can approximate `a / b : L` with `q / r`, where `r` has finitely many options for `L`. -/
theorem exists_mem_finsetApprox (a : S) {b} (hb : b ≠ (0 : R)) :
∃ q : S,
∃ r ∈ finsetApprox bS adm, abv (Algebra.norm R (r • a - b • q)) <
abv (Algebra.norm R (algebraMap R S b)) := by
have dim_pos := Fintype.card_pos_iff.mpr bS.index_nonempty
set ε : ℝ := normBound abv bS ^ (-1 / Fintype.card ι : ℝ) with ε_eq
have hε : 0 < ε := Real.rpow_pos_of_pos (Int.cast_pos.mpr (normBound_pos abv bS)) _
have ε_le : (normBound abv bS : ℝ) * (abv b • ε) ^ (Fintype.card ι : ℝ)
≤ abv b ^ (Fintype.card ι : ℝ) := by
have := normBound_pos abv bS
have := abv.nonneg b
rw [ε_eq, Algebra.smul_def, eq_intCast, mul_rpow, ← rpow_mul, div_mul_cancel₀, rpow_neg_one,
mul_left_comm, mul_inv_cancel₀, mul_one, rpow_natCast] <;>
try norm_cast; cutsat
· exact Iff.mpr Int.cast_nonneg_iff this
· linarith
set μ : Fin (cardM bS adm).succ ↪ R := distinctElems bS adm
let s : ι →₀ R := bS.repr a
have s_eq : ∀ i, s i = bS.repr a i := fun i => rfl
let qs : Fin (cardM bS adm).succ → ι → R := fun j i => μ j * s i / b
let rs : Fin (cardM bS adm).succ → ι → R := fun j i => μ j * s i % b
have r_eq : ∀ j i, rs j i = μ j * s i % b := fun i j => rfl
have μ_eq : ∀ i j, μ j * s i = b * qs j i + rs j i := by
intro i j
rw [r_eq, EuclideanDomain.div_add_mod]
have μ_mul_a_eq : ∀ j, μ j • a = b • ∑ i, qs j i • bS i + ∑ i, rs j i • bS i := by
intro j
rw [← bS.sum_repr a]
simp only [μ, qs, rs, Finset.smul_sum, ← Finset.sum_add_distrib]
refine Finset.sum_congr rfl fun i _ => ?_
rw [← s_eq, ← mul_smul, μ_eq, add_smul, mul_smul, ← μ_eq]
obtain ⟨j, k, j_ne_k, hjk⟩ := adm.exists_approx hε hb fun j i => μ j * s i
have hjk' : ∀ i, (abv (rs k i - rs j i) : ℝ) < abv b • ε := by simpa only [r_eq] using hjk
let q := ∑ i, (qs k i - qs j i) • bS i
set r := μ k - μ j with r_eq
refine ⟨q, r, (mem_finsetApprox bS adm).mpr ?_, ?_⟩
· exact ⟨k, j, j_ne_k.symm, rfl⟩
have : r • a - b • q = ∑ x : ι, (rs k x • bS x - rs j x • bS x) := by
simp only [q, r_eq, sub_smul, μ_mul_a_eq, Finset.smul_sum, ← Finset.sum_add_distrib,
← Finset.sum_sub_distrib, smul_sub]
refine Finset.sum_congr rfl fun x _ => ?_
ring
rw [this, Algebra.norm_algebraMap_of_basis bS, abv.map_pow]
refine Int.cast_lt.mp ((norm_lt abv bS _ fun i => lt_of_le_of_lt ?_ (hjk' i)).trans_le ?_)
· apply le_of_eq
congr
simp_rw [map_sum, map_sub, map_smul, Finset.sum_apply',
Finsupp.sub_apply, Finsupp.smul_apply, Finset.sum_sub_distrib, Basis.repr_self_apply,
smul_eq_mul, mul_boole, Finset.sum_ite_eq', Finset.mem_univ, if_true]
· exact mod_cast ε_le
/-- We can approximate `a / b : L` with `q / r`, where `r` has finitely many options for `L`. -/
theorem exists_mem_finset_approx' [Algebra.IsAlgebraic R S] (a : S) {b : S} (hb : b ≠ 0) :
∃ q : S,
∃ r ∈ finsetApprox bS adm, abv (Algebra.norm R (r • a - q * b)) < abv (Algebra.norm R b) := by
obtain ⟨a', b', hb', h⟩ := Algebra.IsAlgebraic.exists_smul_eq_mul R a hb
obtain ⟨q, r, hr, hqr⟩ := exists_mem_finsetApprox bS adm a' hb'
refine ⟨q, r, hr, ?_⟩
refine
lt_of_mul_lt_mul_left ?_ (show 0 ≤ abv (Algebra.norm R (algebraMap R S b')) from abv.nonneg _)
refine
lt_of_le_of_lt (le_of_eq ?_)
(mul_lt_mul hqr le_rfl (abv.pos ((Algebra.norm_ne_zero_iff_of_basis bS).mpr hb))
(abv.nonneg _))
rw [← abv.map_mul, ← MonoidHom.map_mul, ← abv.map_mul, ← MonoidHom.map_mul, ← Algebra.smul_def,
smul_sub b', sub_mul, smul_comm, h, mul_comm b a', Algebra.smul_mul_assoc r a' b,
Algebra.smul_mul_assoc b' q b]
end Real
theorem prod_finsetApprox_ne_zero : algebraMap R S (∏ m ∈ finsetApprox bS adm, m) ≠ 0 := by
refine mt ((injective_iff_map_eq_zero _).mp bS.algebraMap_injective _) ?_
simp only [Finset.prod_eq_zero_iff, not_exists]
rintro x ⟨hx, rfl⟩
exact finsetApprox.zero_notMem bS adm hx
theorem ne_bot_of_prod_finsetApprox_mem (J : Ideal S)
(h : algebraMap _ _ (∏ m ∈ finsetApprox bS adm, m) ∈ J) : J ≠ ⊥ :=
(Submodule.ne_bot_iff _).mpr ⟨_, h, prod_finsetApprox_ne_zero _ _⟩
/-- Each class in the class group contains an ideal `J`
such that `M := Π m ∈ finsetApprox` is in `J`. -/
theorem exists_mk0_eq_mk0 [IsDedekindDomain S] [Algebra.IsAlgebraic R S] (I : (Ideal S)⁰) :
∃ J : (Ideal S)⁰,
ClassGroup.mk0 I = ClassGroup.mk0 J ∧
algebraMap _ _ (∏ m ∈ finsetApprox bS adm, m) ∈ (J : Ideal S) := by
set M := ∏ m ∈ finsetApprox bS adm, m
have hM : algebraMap R S M ≠ 0 := prod_finsetApprox_ne_zero bS adm
obtain ⟨b, b_mem, b_ne_zero, b_min⟩ := exists_min abv I
suffices Ideal.span {b} ∣ Ideal.span {algebraMap _ _ M} * I.1 by
obtain ⟨J, hJ⟩ := this
refine ⟨⟨J, ?_⟩, ?_, ?_⟩
· rw [mem_nonZeroDivisors_iff_ne_zero]
rintro rfl
rw [Ideal.zero_eq_bot, Ideal.mul_bot] at hJ
exact hM (Ideal.span_singleton_eq_bot.mp (I.2.2 _ hJ))
· rw [ClassGroup.mk0_eq_mk0_iff]
exact ⟨algebraMap _ _ M, b, hM, b_ne_zero, hJ⟩
rw [← SetLike.mem_coe, ← Set.singleton_subset_iff, ← Ideal.span_le, ← Ideal.dvd_iff_le]
apply (mul_dvd_mul_iff_left _).mp _
swap; · exact mt Ideal.span_singleton_eq_bot.mp b_ne_zero
rw [Subtype.coe_mk, Ideal.dvd_iff_le, ← hJ, mul_comm]
apply Ideal.mul_mono le_rfl
rw [Ideal.span_le, Set.singleton_subset_iff]
exact b_mem
rw [Ideal.dvd_iff_le, Ideal.mul_le]
intro r' hr' a ha
rw [Ideal.mem_span_singleton] at hr' ⊢
obtain ⟨q, r, r_mem, lt⟩ := exists_mem_finset_approx' bS adm a b_ne_zero
apply @dvd_of_mul_left_dvd _ _ q
simp only [Algebra.smul_def] at lt
rw [←
sub_eq_zero.mp (b_min _ (I.1.sub_mem (I.1.mul_mem_left _ ha) (I.1.mul_mem_left _ b_mem)) lt)]
refine mul_dvd_mul_right (dvd_trans (map_dvd _ ?_) hr') _
exact Multiset.dvd_prod (Multiset.mem_map.mpr ⟨_, r_mem, rfl⟩)
/-- `ClassGroup.mkMMem` is a specialization of `ClassGroup.mk0` to (the finite set of)
ideals that contain `M := ∏ m ∈ finsetApprox L f abs, m`.
By showing this function is surjective, we prove that the class group is finite. -/
noncomputable def mkMMem [IsDedekindDomain S]
(J : { J : Ideal S // algebraMap _ _ (∏ m ∈ finsetApprox bS adm, m) ∈ J }) : ClassGroup S :=
ClassGroup.mk0
⟨J.1, mem_nonZeroDivisors_iff_ne_zero.mpr (ne_bot_of_prod_finsetApprox_mem bS adm J.1 J.2)⟩
theorem mkMMem_surjective [IsDedekindDomain S] [Algebra.IsAlgebraic R S] :
Function.Surjective (ClassGroup.mkMMem bS adm) := by
intro I'
obtain ⟨⟨I, hI⟩, rfl⟩ := ClassGroup.mk0_surjective I'
obtain ⟨J, mk0_eq_mk0, J_dvd⟩ := exists_mk0_eq_mk0 bS adm ⟨I, hI⟩
exact ⟨⟨J, J_dvd⟩, mk0_eq_mk0.symm⟩
open Classical in
/-- The **class number theorem**: the class group of an integral closure `S` of `R` in an
algebraic extension `L` is finite if there is an admissible absolute value.
See also `ClassGroup.fintypeOfAdmissibleOfFinite` where `L` is a finite
extension of `K = Frac(R)`, supplying most of the required assumptions automatically.
-/
noncomputable def fintypeOfAdmissibleOfAlgebraic [IsDedekindDomain S]
[Algebra.IsAlgebraic R S] : Fintype (ClassGroup S) :=
@Fintype.ofSurjective _ _ _
(@Fintype.ofEquiv _
{ J // J ∣ Ideal.span ({algebraMap R S (∏ m ∈ finsetApprox bS adm, m)} : Set S) }
(UniqueFactorizationMonoid.fintypeSubtypeDvd _
(by
rw [Ne, Ideal.zero_eq_bot, Ideal.span_singleton_eq_bot]
exact prod_finsetApprox_ne_zero bS adm))
((Equiv.refl _).subtypeEquiv fun I =>
Ideal.dvd_iff_le.trans (by
rw [Equiv.refl_apply, Ideal.span_le, Set.singleton_subset_iff]; rfl)))
(ClassGroup.mkMMem bS adm) (ClassGroup.mkMMem_surjective bS adm)
/-- The main theorem: the class group of an integral closure `S` of `R` in a
finite extension `L` of `K = Frac(R)` is finite if there is an admissible
absolute value.
See also `ClassGroup.fintypeOfAdmissibleOfAlgebraic` where `L` is an
algebraic extension of `R`, that includes some extra assumptions.
-/
noncomputable def fintypeOfAdmissibleOfFinite [IsIntegralClosure S R L] :
Fintype (ClassGroup S) := by
letI := Classical.decEq L
letI := IsIntegralClosure.isFractionRing_of_finite_extension R K L S
letI := IsIntegralClosure.isDedekindDomain R K L S
choose s b hb_int using FiniteDimensional.exists_is_basis_integral R K L
have : LinearIndependent R ((Algebra.traceForm K L).dualBasis
(traceForm_nondegenerate K L) b) := by
apply (Basis.linearIndependent _).restrict_scalars
simp only [Algebra.smul_def, mul_one]
apply IsFractionRing.injective
obtain ⟨n, b⟩ :=
Submodule.basisOfPidOfLESpan this (IsIntegralClosure.range_le_span_dualBasis S b hb_int)
let f : (S ⧸ LinearMap.ker (LinearMap.restrictScalars R (Algebra.linearMap S L))) ≃ₗ[R] S := by
rw [LinearMap.ker_eq_bot.mpr]
· exact Submodule.quotEquivOfEqBot _ rfl
· exact IsIntegralClosure.algebraMap_injective _ R _
let bS := b.map ((LinearMap.quotKerEquivRange _).symm ≪≫ₗ f)
have : Algebra.IsIntegral R S := IsIntegralClosure.isIntegral_algebra R L
exact fintypeOfAdmissibleOfAlgebraic bS adm
end IsAdmissible
end EuclideanDomain
end ClassGroup |
.lake/packages/mathlib/Mathlib/NumberTheory/ClassNumber/AdmissibleAbsoluteValue.lean | import Mathlib.Data.Real.Basic
import Mathlib.Combinatorics.Pigeonhole
import Mathlib.Algebra.Order.AbsoluteValue.Euclidean
/-!
# Admissible absolute values
This file defines a structure `AbsoluteValue.IsAdmissible` which we use to show the class number
of the ring of integers of a global field is finite.
## Main definitions
* `AbsoluteValue.IsAdmissible abv` states the absolute value `abv : R → ℤ`
respects the Euclidean domain structure on `R`, and that a large enough set
of elements of `R^n` contains a pair of elements whose remainders are
pointwise close together.
## Main results
* `AbsoluteValue.absIsAdmissible` shows the "standard" absolute value on `ℤ`,
mapping negative `x` to `-x`, is admissible.
* `Polynomial.cardPowDegreeIsAdmissible` shows `cardPowDegree`,
mapping `p : Polynomial 𝔽_q` to `q ^ degree p`, is admissible
-/
local infixl:50 " ≺ " => EuclideanDomain.r
namespace AbsoluteValue
variable {R : Type*} [EuclideanDomain R]
variable (abv : AbsoluteValue R ℤ)
/-- An absolute value `R → ℤ` is admissible if it respects the Euclidean domain
structure and a large enough set of elements in `R^n` will contain a pair of
elements whose remainders are pointwise close together. -/
structure IsAdmissible extends IsEuclidean abv where
/-- The cardinality required for a given `ε`. -/
protected card : ℝ → ℕ
/-- For all `ε > 0` and finite families `A`, we can partition the remainders of `A` mod `b`
into `abv.card ε` sets, such that all elements in each part of remainders are close together. -/
exists_partition' :
∀ (n : ℕ) {ε : ℝ} (_ : 0 < ε) {b : R} (_ : b ≠ 0) (A : Fin n → R),
∃ t : Fin n → Fin (card ε), ∀ i₀ i₁, t i₀ = t i₁ → (abv (A i₁ % b - A i₀ % b) : ℝ) < abv b • ε
namespace IsAdmissible
variable {abv}
/-- For all `ε > 0` and finite families `A`, we can partition the remainders of `A` mod `b`
into `abv.card ε` sets, such that all elements in each part of remainders are close together. -/
theorem exists_partition {ι : Type*} [Finite ι] {ε : ℝ} (hε : 0 < ε) {b : R} (hb : b ≠ 0)
(A : ι → R) (h : abv.IsAdmissible) : ∃ t : ι → Fin (h.card ε),
∀ i₀ i₁, t i₀ = t i₁ → (abv (A i₁ % b - A i₀ % b) : ℝ) < abv b • ε := by
rcases Finite.exists_equiv_fin ι with ⟨n, ⟨e⟩⟩
obtain ⟨t, ht⟩ := h.exists_partition' n hε hb (A ∘ e.symm)
refine ⟨t ∘ e, fun i₀ i₁ h ↦ ?_⟩
convert (config := {transparency := .default})
ht (e i₀) (e i₁) h <;> simp only [e.symm_apply_apply]
/-- Any large enough family of vectors in `R^n` has a pair of elements
whose remainders are close together, pointwise. -/
theorem exists_approx_aux (n : ℕ) (h : abv.IsAdmissible) :
∀ {ε : ℝ} (_hε : 0 < ε) {b : R} (_hb : b ≠ 0) (A : Fin (h.card ε ^ n).succ → Fin n → R),
∃ i₀ i₁, i₀ ≠ i₁ ∧ ∀ k, (abv (A i₁ k % b - A i₀ k % b) : ℝ) < abv b • ε := by
haveI := Classical.decEq R
induction n with
| zero =>
intro ε _hε b _hb A
refine ⟨0, 1, ?_, ?_⟩
· simp
rintro ⟨i, ⟨⟩⟩
| succ n ih =>
intro ε hε b hb A
let M := h.card ε
-- By the "nicer" pigeonhole principle, we can find a collection `s`
-- of more than `M^n` remainders where the first components lie close together:
obtain ⟨s, s_inj, hs⟩ :
∃ s : Fin (M ^ n).succ → Fin (M ^ n.succ).succ,
Function.Injective s ∧ ∀ i₀ i₁, (abv (A (s i₁) 0 % b - A (s i₀) 0 % b) : ℝ) < abv b • ε := by
-- We can partition the `A`s into `M` subsets where
-- the first components lie close together:
obtain ⟨t, ht⟩ :
∃ t : Fin (M ^ n.succ).succ → Fin M,
∀ i₀ i₁, t i₀ = t i₁ → (abv (A i₁ 0 % b - A i₀ 0 % b) : ℝ) < abv b • ε :=
h.exists_partition hε hb fun x ↦ A x 0
-- Since the `M` subsets contain more than `M * M^n` elements total,
-- there must be a subset that contains more than `M^n` elements.
obtain ⟨s, hs⟩ :=
Fintype.exists_lt_card_fiber_of_mul_lt_card (f := t)
(by simpa only [Fintype.card_fin, pow_succ'] using Nat.lt_succ_self (M ^ n.succ))
have : (M ^ n).succ ≤ (Finset.toList {x | t x = s}).length := by
rwa [Finset.length_toList]
refine ⟨fun i ↦ (Finset.toList {x | t x = s})[i.castLE this], fun i j h ↦ ?_,
fun i₀ i₁ ↦ ht _ _ ?_⟩
· simpa [(Finset.nodup_toList _).getElem_inj_iff, Fin.val_inj] using h
· have : ∀ (i : Fin (M^n).succ), t (Finset.toList {x | t x = s})[i.castLE this] = s := fun i ↦
(Finset.mem_filter.mp ((Finset.mem_toList (s := {x | t x = s})).mp (List.getElem_mem _))).2
simp_rw [this]
-- Since `s` is large enough, there are two elements of `A ∘ s`
-- where the second components lie close together.
obtain ⟨k₀, k₁, hk, h⟩ := ih hε hb fun x ↦ Fin.tail (A (s x))
refine ⟨s k₀, s k₁, fun h ↦ hk (s_inj h), fun i ↦ Fin.cases ?_ (fun i ↦ ?_) i⟩
· exact hs k₀ k₁
· exact h i
/-- Any large enough family of vectors in `R^ι` has a pair of elements
whose remainders are close together, pointwise. -/
theorem exists_approx {ι : Type*} [Fintype ι] {ε : ℝ} (hε : 0 < ε) {b : R} (hb : b ≠ 0)
(h : abv.IsAdmissible) (A : Fin (h.card ε ^ Fintype.card ι).succ → ι → R) :
∃ i₀ i₁, i₀ ≠ i₁ ∧ ∀ k, (abv (A i₁ k % b - A i₀ k % b) : ℝ) < abv b • ε := by
let e := Fintype.equivFin ι
obtain ⟨i₀, i₁, ne, h⟩ := h.exists_approx_aux (Fintype.card ι) hε hb fun x y ↦ A x (e.symm y)
refine ⟨i₀, i₁, ne, fun k ↦ ?_⟩
convert h (e k) <;> simp only [e.symm_apply_apply]
end IsAdmissible
end AbsoluteValue |
.lake/packages/mathlib/Mathlib/NumberTheory/ClassNumber/AdmissibleAbs.lean | import Mathlib.Algebra.Algebra.Basic
import Mathlib.NumberTheory.ClassNumber.AdmissibleAbsoluteValue
import Mathlib.Data.Real.Archimedean
/-!
# Admissible absolute value on the integers
This file defines an admissible absolute value `AbsoluteValue.absIsAdmissible`
which we use to show the class number of the ring of integers of a number field
is finite.
## Main results
* `AbsoluteValue.absIsAdmissible` shows the "standard" absolute value on `ℤ`,
mapping negative `x` to `-x`, is admissible.
-/
namespace AbsoluteValue
open Int
/-- We can partition a finite family into `partition_card ε` sets, such that the remainders
in each set are close together. -/
theorem exists_partition_int (n : ℕ) {ε : ℝ} (hε : 0 < ε) {b : ℤ} (hb : b ≠ 0) (A : Fin n → ℤ) :
∃ t : Fin n → Fin ⌈1 / ε⌉₊,
∀ i₀ i₁, t i₀ = t i₁ → ↑(abs (A i₁ % b - A i₀ % b)) < abs b • ε := by
have hb' : (0 : ℝ) < ↑(abs b) := Int.cast_pos.mpr (abs_pos.mpr hb)
have hbε : 0 < abs b • ε := by
rw [Algebra.smul_def]
exact mul_pos hb' hε
have hfloor : ∀ i, 0 ≤ floor ((A i % b : ℤ) / abs b • ε : ℝ) :=
fun _ ↦ floor_nonneg.mpr (div_nonneg (cast_nonneg (emod_nonneg _ hb)) hbε.le)
refine ⟨fun i ↦ ⟨natAbs (floor ((A i % b : ℤ) / abs b • ε : ℝ)), ?_⟩, ?_⟩
· rw [← ofNat_lt, natAbs_of_nonneg (hfloor i), floor_lt, Algebra.smul_def, eq_intCast, ← div_div]
apply lt_of_lt_of_le _ (Nat.le_ceil _)
gcongr
rw [div_lt_one hb', cast_lt]
exact Int.emod_lt_abs _ hb
intro i₀ i₁ hi
have hi : (⌊↑(A i₀ % b) / abs b • ε⌋.natAbs : ℤ) = ⌊↑(A i₁ % b) / abs b • ε⌋.natAbs :=
congr_arg ((↑) : ℕ → ℤ) (Fin.mk_eq_mk.mp hi)
rw [natAbs_of_nonneg (hfloor i₀), natAbs_of_nonneg (hfloor i₁)] at hi
have hi := abs_sub_lt_one_of_floor_eq_floor hi
rw [abs_sub_comm, ← sub_div, abs_div, abs_of_nonneg hbε.le, div_lt_iff₀ hbε, one_mul] at hi
rwa [Int.cast_abs, Int.cast_sub]
/-- `abs : ℤ → ℤ` is an admissible absolute value. -/
noncomputable def absIsAdmissible : IsAdmissible AbsoluteValue.abs :=
{ AbsoluteValue.abs_isEuclidean with
card := fun ε ↦ ⌈1 / ε⌉₊
exists_partition' := fun n _ hε _ hb ↦ exists_partition_int n hε hb }
noncomputable instance : Inhabited (IsAdmissible AbsoluteValue.abs) :=
⟨absIsAdmissible⟩
end AbsoluteValue |
.lake/packages/mathlib/Mathlib/NumberTheory/ClassNumber/FunctionField.lean | import Mathlib.NumberTheory.ClassNumber.AdmissibleCardPowDegree
import Mathlib.NumberTheory.ClassNumber.Finite
import Mathlib.NumberTheory.FunctionField
/-!
# Class numbers of function fields
This file defines the class number of a function field as the (finite) cardinality of
the class group of its ring of integers. It also proves some elementary results
on the class number.
## Main definitions
- `FunctionField.classNumber`: the class number of a function field is the (finite)
cardinality of the class group of its ring of integers
-/
namespace FunctionField
open scoped Polynomial
variable (Fq F : Type*) [Field Fq] [Fintype Fq] [Field F]
variable [Algebra Fq[X] F] [Algebra (RatFunc Fq) F]
variable [IsScalarTower Fq[X] (RatFunc Fq) F]
variable [FunctionField Fq F] [Algebra.IsSeparable (RatFunc Fq) F]
namespace RingOfIntegers
open FunctionField
open scoped Classical in
noncomputable instance : Fintype (ClassGroup (ringOfIntegers Fq F)) :=
ClassGroup.fintypeOfAdmissibleOfFinite (RatFunc Fq) F
(Polynomial.cardPowDegreeIsAdmissible :
AbsoluteValue.IsAdmissible (Polynomial.cardPowDegree : AbsoluteValue Fq[X] ℤ))
end RingOfIntegers
/-- The class number in a function field is the (finite) cardinality of the class group. -/
noncomputable def classNumber : ℕ :=
Fintype.card (ClassGroup (ringOfIntegers Fq F))
/-- The class number of a function field is `1` iff the ring of integers is a PID. -/
theorem classNumber_eq_one_iff :
classNumber Fq F = 1 ↔ IsPrincipalIdealRing (ringOfIntegers Fq F) :=
card_classGroup_eq_one_iff
end FunctionField |
.lake/packages/mathlib/Mathlib/NumberTheory/ClassNumber/AdmissibleCardPowDegree.lean | import Mathlib.Algebra.Polynomial.Degree.CardPowDegree
import Mathlib.Analysis.SpecialFunctions.Pow.Real
import Mathlib.NumberTheory.ClassNumber.AdmissibleAbsoluteValue
import Mathlib.RingTheory.LocalRing.Basic
/-!
# Admissible absolute values on polynomials
This file defines an admissible absolute value `Polynomial.cardPowDegreeIsAdmissible` which we
use to show the class number of the ring of integers of a function field is finite.
## Main results
* `Polynomial.cardPowDegreeIsAdmissible` shows `cardPowDegree`,
mapping `p : Polynomial 𝔽_q` to `q ^ degree p`, is admissible
-/
namespace Polynomial
open AbsoluteValue Real
variable {Fq : Type*} [Fintype Fq]
/-- If `A` is a family of enough low-degree polynomials over a finite semiring, there is a
pair of equal elements in `A`. -/
theorem exists_eq_polynomial [Semiring Fq] {d : ℕ} {m : ℕ} (hm : Fintype.card Fq ^ d ≤ m)
(b : Fq[X]) (hb : natDegree b ≤ d) (A : Fin m.succ → Fq[X])
(hA : ∀ i, degree (A i) < degree b) : ∃ i₀ i₁, i₀ ≠ i₁ ∧ A i₁ = A i₀ := by
-- Since there are > q^d elements of A, and only q^d choices for the highest `d` coefficients,
-- there must be two elements of A with the same coefficients at
-- `0`, ... `degree b - 1` ≤ `d - 1`.
-- In other words, the following map is not injective:
set f : Fin m.succ → Fin d → Fq := fun i j => (A i).coeff j
have : Fintype.card (Fin d → Fq) < Fintype.card (Fin m.succ) := by
simpa using lt_of_le_of_lt hm (Nat.lt_succ_self m)
-- Therefore, the differences have all coefficients higher than `deg b - d` equal.
obtain ⟨i₀, i₁, i_ne, i_eq⟩ := Fintype.exists_ne_map_eq_of_card_lt f this
use i₀, i₁, i_ne
ext j
-- The coefficients higher than `deg b` are the same because they are equal to 0.
by_cases! hbj : degree b ≤ j
· rw [coeff_eq_zero_of_degree_lt (lt_of_lt_of_le (hA _) hbj),
coeff_eq_zero_of_degree_lt (lt_of_lt_of_le (hA _) hbj)]
-- So we only need to look for the coefficients between `0` and `deg b`.
apply congr_fun i_eq.symm ⟨j, _⟩
exact lt_of_lt_of_le (coe_lt_degree.mp hbj) hb
/-- If `A` is a family of enough low-degree polynomials over a finite ring,
there is a pair of elements in `A` (with different indices but not necessarily
distinct), such that their difference has small degree. -/
theorem exists_approx_polynomial_aux [Ring Fq] {d : ℕ} {m : ℕ} (hm : Fintype.card Fq ^ d ≤ m)
(b : Fq[X]) (A : Fin m.succ → Fq[X]) (hA : ∀ i, degree (A i) < degree b) :
∃ i₀ i₁, i₀ ≠ i₁ ∧ degree (A i₁ - A i₀) < ↑(natDegree b - d) := by
have hb : b ≠ 0 := by
rintro rfl
specialize hA 0
rw [degree_zero] at hA
exact not_lt_of_ge bot_le hA
-- Since there are > q^d elements of A, and only q^d choices for the highest `d` coefficients,
-- there must be two elements of A with the same coefficients at
-- `degree b - 1`, ... `degree b - d`.
-- In other words, the following map is not injective:
set f : Fin m.succ → Fin d → Fq := fun i j => (A i).coeff (natDegree b - j.succ)
have : Fintype.card (Fin d → Fq) < Fintype.card (Fin m.succ) := by
simpa using lt_of_le_of_lt hm (Nat.lt_succ_self m)
-- Therefore, the differences have all coefficients higher than `deg b - d` equal.
obtain ⟨i₀, i₁, i_ne, i_eq⟩ := Fintype.exists_ne_map_eq_of_card_lt f this
use i₀, i₁, i_ne
refine (degree_lt_iff_coeff_zero _ _).mpr fun j hj => ?_
-- The coefficients higher than `deg b` are the same because they are equal to 0.
by_cases! hbj : degree b ≤ j
· refine coeff_eq_zero_of_degree_lt (lt_of_lt_of_le ?_ hbj)
exact lt_of_le_of_lt (degree_sub_le _ _) (max_lt (hA _) (hA _))
-- So we only need to look for the coefficients between `deg b - d` and `deg b`.
rw [coeff_sub, sub_eq_zero]
rw [degree_eq_natDegree hb] at hbj
have hbj : j < natDegree b := (@WithBot.coe_lt_coe _ _ _).mp hbj
have hj : natDegree b - j.succ < d := by
by_cases! hd : natDegree b < d
· exact lt_of_le_of_lt tsub_le_self hd
· have := lt_of_le_of_lt hj (Nat.lt_succ_self j)
rwa [tsub_lt_iff_tsub_lt hd hbj] at this
have : j = b.natDegree - (natDegree b - j.succ).succ := by
rw [← Nat.succ_sub hbj, Nat.succ_sub_succ, tsub_tsub_cancel_of_le hbj.le]
convert congr_fun i_eq.symm ⟨natDegree b - j.succ, hj⟩
variable [Field Fq]
/-- If `A` is a family of enough low-degree polynomials over a finite field,
there is a pair of elements in `A` (with different indices but not necessarily
distinct), such that the difference of their remainders is close together. -/
theorem exists_approx_polynomial {b : Fq[X]} (hb : b ≠ 0) {ε : ℝ} (hε : 0 < ε)
(A : Fin (Fintype.card Fq ^ ⌈-log ε / log (Fintype.card Fq)⌉₊).succ → Fq[X]) :
∃ i₀ i₁, i₀ ≠ i₁ ∧ (cardPowDegree (A i₁ % b - A i₀ % b) : ℝ) < cardPowDegree b • ε := by
have hbε : 0 < cardPowDegree b • ε := by
rw [Algebra.smul_def, eq_intCast]
exact mul_pos (Int.cast_pos.mpr (AbsoluteValue.pos _ hb)) hε
have one_lt_q : 1 < Fintype.card Fq := Fintype.one_lt_card
have one_lt_q' : (1 : ℝ) < Fintype.card Fq := by assumption_mod_cast
have q_pos : 0 < Fintype.card Fq := by omega
have q_pos' : (0 : ℝ) < Fintype.card Fq := by assumption_mod_cast
-- If `b` is already small enough, then the remainders are equal and we are done.
by_cases! le_b : b.natDegree ≤ ⌈-log ε / log (Fintype.card Fq)⌉₊
· obtain ⟨i₀, i₁, i_ne, mod_eq⟩ :=
exists_eq_polynomial le_rfl b le_b (fun i => A i % b) fun i => EuclideanDomain.mod_lt (A i) hb
refine ⟨i₀, i₁, i_ne, ?_⟩
rwa [mod_eq, sub_self, map_zero, Int.cast_zero]
-- Otherwise, it suffices to choose two elements whose difference is of small enough degree.
obtain ⟨i₀, i₁, i_ne, deg_lt⟩ := exists_approx_polynomial_aux le_rfl b (fun i => A i % b) fun i =>
EuclideanDomain.mod_lt (A i) hb
use i₀, i₁, i_ne
-- Again, if the remainders are equal we are done.
by_cases h : A i₁ % b = A i₀ % b
· rwa [h, sub_self, map_zero, Int.cast_zero]
have h' : A i₁ % b - A i₀ % b ≠ 0 := mt sub_eq_zero.mp h
-- If the remainders are not equal, we'll show their difference is of small degree.
-- In particular, we'll show the degree is less than the following:
suffices (natDegree (A i₁ % b - A i₀ % b) : ℝ) < b.natDegree + log ε / log (Fintype.card Fq) by
rwa [← Real.log_lt_log_iff (Int.cast_pos.mpr (cardPowDegree.pos h')) hbε,
cardPowDegree_nonzero _ h', cardPowDegree_nonzero _ hb, Algebra.smul_def, eq_intCast,
Int.cast_pow, Int.cast_natCast, Int.cast_pow, Int.cast_natCast,
log_mul (pow_ne_zero _ q_pos'.ne') hε.ne', ← rpow_natCast, ← rpow_natCast, log_rpow q_pos',
log_rpow q_pos', ← lt_div_iff₀ (log_pos one_lt_q'), add_div,
mul_div_cancel_right₀ _ (log_pos one_lt_q').ne']
-- And that result follows from manipulating the result from `exists_approx_polynomial_aux`
-- to turn the `-⌈-stuff⌉₊` into `+ stuff`.
apply lt_of_lt_of_le (Nat.cast_lt.mpr (WithBot.coe_lt_coe.mp _)) _
swap
· convert deg_lt
rw [degree_eq_natDegree h']; rfl
rw [← sub_neg_eq_add, ← neg_div, Nat.cast_sub le_b.le]
grw [← Nat.le_ceil]
/-- If `x` is close to `y` and `y` is close to `z`, then `x` and `z` are at least as close. -/
theorem cardPowDegree_anti_archimedean {x y z : Fq[X]} {a : ℤ} (hxy : cardPowDegree (x - y) < a)
(hyz : cardPowDegree (y - z) < a) : cardPowDegree (x - z) < a := by
have ha : 0 < a := lt_of_le_of_lt (AbsoluteValue.nonneg _ _) hxy
by_cases hxy' : x = y
· rwa [hxy']
by_cases hyz' : y = z
· rwa [← hyz']
by_cases hxz' : x = z
· rwa [hxz', sub_self, map_zero]
rw [← Ne, ← sub_ne_zero] at hxy' hyz' hxz'
refine lt_of_le_of_lt ?_ (max_lt hxy hyz)
rw [cardPowDegree_nonzero _ hxz', cardPowDegree_nonzero _ hxy',
cardPowDegree_nonzero _ hyz']
have : (1 : ℤ) ≤ Fintype.card Fq := mod_cast (@Fintype.one_lt_card Fq _ _).le
simp only [le_max_iff]
refine Or.imp (pow_le_pow_right₀ this) (pow_le_pow_right₀ this) ?_
rw [natDegree_le_iff_degree_le, natDegree_le_iff_degree_le, ← le_max_iff, ←
degree_eq_natDegree hxy', ← degree_eq_natDegree hyz']
convert degree_add_le (x - y) (y - z) using 2
exact (sub_add_sub_cancel _ _ _).symm
/-- A slightly stronger version of `exists_partition` on which we perform induction on `n`:
for all `ε > 0`, we can partition the remainders of any family of polynomials `A`
into equivalence classes, where the equivalence(!) relation is "closer than `ε`". -/
theorem exists_partition_polynomial_aux (n : ℕ) {ε : ℝ} (hε : 0 < ε) {b : Fq[X]} (hb : b ≠ 0)
(A : Fin n → Fq[X]) : ∃ t : Fin n → Fin (Fintype.card Fq ^ ⌈-log ε / log (Fintype.card Fq)⌉₊),
∀ i₀ i₁ : Fin n, t i₀ = t i₁ ↔
(cardPowDegree (A i₁ % b - A i₀ % b) : ℝ) < cardPowDegree b • ε := by
have hbε : 0 < cardPowDegree b • ε := by
rw [Algebra.smul_def, eq_intCast]
exact mul_pos (Int.cast_pos.mpr (AbsoluteValue.pos _ hb)) hε
-- We go by induction on the size `A`.
induction n with | zero => refine ⟨finZeroElim, finZeroElim⟩ | succ n ih =>
-- Show `anti_archimedean` also holds for real distances.
have anti_archim' : ∀ {i j k} {ε : ℝ},
(cardPowDegree (A i % b - A j % b) : ℝ) < ε →
(cardPowDegree (A j % b - A k % b) : ℝ) < ε →
(cardPowDegree (A i % b - A k % b) : ℝ) < ε := by
intro i j k ε
simp_rw [← Int.lt_ceil]
exact cardPowDegree_anti_archimedean
obtain ⟨t', ht'⟩ := ih (Fin.tail A)
-- We got rid of `A 0`, so determine the index `j` of the partition we'll re-add it to.
rsuffices ⟨j, hj⟩ :
∃ j, ∀ i, t' i = j ↔ (cardPowDegree (A 0 % b - A i.succ % b) : ℝ) < cardPowDegree b • ε
· refine ⟨Fin.cons j t', fun i₀ i₁ => ?_⟩
refine Fin.cases ?_ (fun i₀ => ?_) i₀ <;> refine Fin.cases ?_ (fun i₁ => ?_) i₁
· simpa using hbε
· rw [Fin.cons_succ, Fin.cons_zero, eq_comm, AbsoluteValue.map_sub]
exact hj i₁
· rw [Fin.cons_succ, Fin.cons_zero]
exact hj i₀
· rw [Fin.cons_succ, Fin.cons_succ]
exact ht' i₀ i₁
-- `exists_approx_polynomial` guarantees that we can insert `A 0` into some partition `j`,
-- but not that `j` is uniquely defined (which is needed to keep the induction going).
obtain ⟨j, hj⟩ : ∃ j, ∀ i : Fin n,
t' i = j → (cardPowDegree (A 0 % b - A i.succ % b) : ℝ) < cardPowDegree b • ε := by
by_contra! hg
obtain ⟨j₀, j₁, j_ne, approx⟩ := exists_approx_polynomial hb hε
(Fin.cons (A 0) fun j => A (Fin.succ (Classical.choose (hg j))))
revert j_ne approx
refine Fin.cases ?_ (fun j₀ => ?_) j₀ <;>
refine Fin.cases (fun j_ne approx => ?_) (fun j₁ j_ne approx => ?_) j₁
· exact absurd rfl j_ne
· rw [Fin.cons_succ, Fin.cons_zero, ← not_le, AbsoluteValue.map_sub] at approx
have := (Classical.choose_spec (hg j₁)).2
contradiction
· rw [Fin.cons_succ, Fin.cons_zero, ← not_le] at approx
have := (Classical.choose_spec (hg j₀)).2
contradiction
· rw [Fin.cons_succ, Fin.cons_succ] at approx
rw [Ne, Fin.succ_inj] at j_ne
have : j₀ = j₁ := (Classical.choose_spec (hg j₀)).1.symm.trans
(((ht' (Classical.choose (hg j₀)) (Classical.choose (hg j₁))).mpr approx).trans
(Classical.choose_spec (hg j₁)).1)
contradiction
-- However, if one of those partitions `j` is inhabited by some `i`, then this `j` works.
by_cases exists_nonempty_j : ∃ j, (∃ i, t' i = j) ∧
∀ i, t' i = j → (cardPowDegree (A 0 % b - A i.succ % b) : ℝ) < cardPowDegree b • ε
· obtain ⟨j, ⟨i, hi⟩, hj⟩ := exists_nonempty_j
refine ⟨j, fun i' => ⟨hj i', fun hi' => _root_.trans ((ht' _ _).mpr ?_) hi⟩⟩
apply anti_archim' _ hi'
rw [AbsoluteValue.map_sub]
exact hj _ hi
-- And otherwise, we can just take any `j`, since those are empty.
refine ⟨j, fun i => ⟨hj i, fun hi => ?_⟩⟩
have := exists_nonempty_j ⟨t' i, ⟨i, rfl⟩, fun i' hi' => anti_archim' hi ((ht' _ _).mp hi')⟩
contradiction
/-- For all `ε > 0`, we can partition the remainders of any family of polynomials `A`
into classes, where all remainders in a class are close together. -/
theorem exists_partition_polynomial (n : ℕ) {ε : ℝ} (hε : 0 < ε) {b : Fq[X]} (hb : b ≠ 0)
(A : Fin n → Fq[X]) : ∃ t : Fin n → Fin (Fintype.card Fq ^ ⌈-log ε / log (Fintype.card Fq)⌉₊),
∀ i₀ i₁ : Fin n, t i₀ = t i₁ →
(cardPowDegree (A i₁ % b - A i₀ % b) : ℝ) < cardPowDegree b • ε := by
obtain ⟨t, ht⟩ := exists_partition_polynomial_aux n hε hb A
exact ⟨t, fun i₀ i₁ hi => (ht i₀ i₁).mp hi⟩
/-- `fun p => Fintype.card Fq ^ degree p` is an admissible absolute value.
We set `q ^ degree 0 = 0`. -/
noncomputable def cardPowDegreeIsAdmissible :
IsAdmissible (cardPowDegree : AbsoluteValue Fq[X] ℤ) :=
{ @cardPowDegree_isEuclidean Fq _
_ with
card := fun ε => Fintype.card Fq ^ ⌈-log ε / log (Fintype.card Fq)⌉₊
exists_partition' := fun n _ hε _ hb => exists_partition_polynomial n hε hb }
end Polynomial |
.lake/packages/mathlib/Mathlib/NumberTheory/JacobiSum/Basic.lean | import Mathlib.NumberTheory.GaussSum
import Mathlib.NumberTheory.MulChar.Lemmas
import Mathlib.RingTheory.RootsOfUnity.Lemmas
/-!
# Jacobi Sums
This file defines the *Jacobi sum* of two multiplicative characters `χ` and `ψ` on a finite
commutative ring `R` with values in another commutative ring `R'`:
`jacobiSum χ ψ = ∑ x : R, χ x * ψ (1 - x)`
(see `jacobiSum`) and provides some basic results and API lemmas on Jacobi sums.
## References
We essentially follow
* [K. Ireland, M. Rosen, *A classical introduction to modern number theory*
(Section 8.3)][IrelandRosen1990]
but generalize where appropriate.
This is based on Lean code written as part of the bachelor's thesis of Alexander Spahl.
-/
open Finset
/-!
### Jacobi sums: definition and first properties
-/
section Def
-- need `Fintype` instead of `Finite` to make `jacobiSum` computable.
variable {R R' : Type*} [CommRing R] [Fintype R] [CommRing R']
/-- The *Jacobi sum* of two multiplicative characters on a finite commutative ring. -/
def jacobiSum (χ ψ : MulChar R R') : R' :=
∑ x : R, χ x * ψ (1 - x)
lemma jacobiSum_comm (χ ψ : MulChar R R') : jacobiSum χ ψ = jacobiSum ψ χ := by
simp only [jacobiSum, mul_comm (χ _)]
rw [← (Equiv.subLeft 1).sum_comp]
simp only [Equiv.subLeft_apply, sub_sub_cancel]
/-- The Jacobi sum is compatible with ring homomorphisms. -/
lemma jacobiSum_ringHomComp {R'' : Type*} [CommRing R''] (χ ψ : MulChar R R') (f : R' →+* R'') :
jacobiSum (χ.ringHomComp f) (ψ.ringHomComp f) = f (jacobiSum χ ψ) := by
simp only [jacobiSum, MulChar.ringHomComp, MulChar.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk,
map_sum, map_mul]
end Def
/-!
### Jacobi sums over finite fields
-/
section CommRing
variable {F R : Type*} [CommRing F] [Nontrivial F] [Fintype F] [DecidableEq F] [CommRing R]
/-- The Jacobi sum of two multiplicative characters on a nontrivial finite commutative ring `F`
can be written as a sum over `F \ {0,1}`. -/
lemma jacobiSum_eq_sum_sdiff (χ ψ : MulChar F R) :
jacobiSum χ ψ = ∑ x ∈ univ \ {0,1}, χ x * ψ (1 - x) := by
simp only [jacobiSum, subset_univ, sum_sdiff_eq_sub, sub_eq_add_neg, left_eq_add,
neg_eq_zero]
apply sum_eq_zero
simp only [mem_insert, mem_singleton, forall_eq_or_imp, χ.map_zero, neg_zero, add_zero, map_one,
mul_one, forall_eq, add_neg_cancel, ψ.map_zero, mul_zero, and_self]
private lemma jacobiSum_eq_aux (χ ψ : MulChar F R) :
jacobiSum χ ψ = ∑ x : F, χ x + ∑ x : F, ψ x - Fintype.card F +
∑ x ∈ univ \ {0, 1}, (χ x - 1) * (ψ (1 - x) - 1) := by
rw [jacobiSum]
conv =>
enter [1, 2, x]
rw [show ∀ x y : R, x * y = x + y - 1 + (x - 1) * (y - 1) by intros; ring]
rw [sum_add_distrib, sum_sub_distrib, sum_add_distrib]
conv => enter [1, 1, 1, 2, 2, x]; rw [← Equiv.subLeft_apply 1]
rw [(Equiv.subLeft 1).sum_comp ψ, Fintype.card_eq_sum_ones, Nat.cast_sum, Nat.cast_one,
sum_sdiff_eq_sub (subset_univ _), ← sub_zero (_ - _ + _), add_sub_assoc]
congr
rw [sum_pair zero_ne_one, sub_zero, ψ.map_one, χ.map_one, sub_self, mul_zero, zero_mul, add_zero]
end CommRing
section FiniteField
variable {F R : Type*} [Field F] [Fintype F] [CommRing R]
/-- The Jacobi sum of twice the trivial multiplicative character on a finite field `F`
equals `#F-2`. -/
theorem jacobiSum_trivial_trivial :
jacobiSum (MulChar.trivial F R) (MulChar.trivial F R) = Fintype.card F - 2 := by
classical
rw [jacobiSum_eq_sum_sdiff]
have : ∀ x ∈ univ \ {0, 1}, (MulChar.trivial F R) x * (MulChar.trivial F R) (1 - x) = 1 := by
intro x hx
rw [← map_mul, MulChar.trivial_apply, if_pos]
simp only [mem_sdiff, mem_univ, mem_insert, mem_singleton, not_or, ← ne_eq, true_and] at hx
simpa only [isUnit_iff_ne_zero, mul_ne_zero_iff, ne_eq, sub_eq_zero, @eq_comm _ _ x] using hx
calc ∑ x ∈ univ \ {0, 1}, (MulChar.trivial F R) x * (MulChar.trivial F R) (1 - x)
_ = ∑ _ ∈ univ \ {0, 1}, 1 := sum_congr rfl this
_ = #(univ \ {0, 1}) := (cast_card _).symm
_ = Fintype.card F - 2 := by
rw [card_sdiff_of_subset (subset_univ _), card_univ, card_pair zero_ne_one,
Nat.cast_sub <| Nat.add_one_le_of_lt Fintype.one_lt_card, Nat.cast_two]
/-- If `1` is the trivial multiplicative character on a finite field `F`, then `J(1,1) = #F-2`. -/
theorem jacobiSum_one_one : jacobiSum (1 : MulChar F R) 1 = Fintype.card F - 2 :=
jacobiSum_trivial_trivial
variable [IsDomain R] -- needed for `MulChar.sum_eq_zero_of_ne_one`
/-- If `χ` is a nontrivial multiplicative character on a finite field `F`, then `J(1,χ) = -1`. -/
theorem jacobiSum_one_nontrivial {χ : MulChar F R} (hχ : χ ≠ 1) : jacobiSum 1 χ = -1 := by
classical
have : ∑ x ∈ univ \ {0, 1}, ((1 : MulChar F R) x - 1) * (χ (1 - x) - 1) = 0 := by
apply Finset.sum_eq_zero
simp +contextual only [mem_sdiff, mem_univ, mem_insert, mem_singleton,
not_or, ← isUnit_iff_ne_zero, true_and, MulChar.one_apply, sub_self, zero_mul,
implies_true]
simp only [jacobiSum_eq_aux, MulChar.sum_one_eq_card_units, MulChar.sum_eq_zero_of_ne_one hχ,
add_zero, Fintype.card_eq_card_units_add_one (α := F), Nat.cast_add, Nat.cast_one,
sub_add_cancel_left, this]
/-- If `χ` is a nontrivial multiplicative character on a finite field `F`,
then `J(χ,χ⁻¹) = -χ(-1)`. -/
theorem jacobiSum_nontrivial_inv {χ : MulChar F R} (hχ : χ ≠ 1) : jacobiSum χ χ⁻¹ = -χ (-1) := by
classical
rw [jacobiSum]
conv => enter [1, 2, x]; rw [MulChar.inv_apply', ← map_mul, ← div_eq_mul_inv]
rw [sum_eq_sum_diff_singleton_add (mem_univ (1 : F)), sub_self, div_zero, χ.map_zero, add_zero]
have : ∑ x ∈ univ \ {1}, χ (x / (1 - x)) = ∑ x ∈ univ \ {-1}, χ x := by
refine sum_bij' (fun a _ ↦ a / (1 - a)) (fun b _ ↦ b / (1 + b)) (fun x hx ↦ ?_)
(fun y hy ↦ ?_) (fun x hx ↦ ?_) (fun y hy ↦ ?_) (fun _ _ ↦ rfl)
· simp only [mem_sdiff, mem_univ, mem_singleton, true_and] at hx ⊢
rw [div_eq_iff <| sub_ne_zero.mpr ((ne_eq ..).symm ▸ hx).symm, mul_sub, mul_one,
neg_one_mul, sub_neg_eq_add, right_eq_add, neg_eq_zero]
exact one_ne_zero
· simp only [mem_sdiff, mem_univ, mem_singleton, true_and] at hy ⊢
rw [div_eq_iff fun h ↦ hy <| eq_neg_of_add_eq_zero_right h, one_mul, right_eq_add]
exact one_ne_zero
· simp only [mem_sdiff, mem_univ, mem_singleton, true_and] at hx
rw [eq_comm, ← sub_eq_zero] at hx
simp [field]
· simp only [mem_sdiff, mem_univ, mem_singleton, true_and] at hy
rw [eq_comm, neg_eq_iff_eq_neg, ← sub_eq_zero, sub_neg_eq_add] at hy
simp [field]
rw [this, ← add_eq_zero_iff_eq_neg, ← sum_eq_sum_diff_singleton_add (mem_univ (-1 : F))]
exact MulChar.sum_eq_zero_of_ne_one hχ
/-- If `χ` and `φ` are multiplicative characters on a finite field `F` such that
`χφ` is nontrivial, then `g(χφ) * J(χ,φ) = g(χ) * g(φ)`. -/
theorem jacobiSum_mul_nontrivial {χ φ : MulChar F R} (h : χ * φ ≠ 1) (ψ : AddChar F R) :
gaussSum (χ * φ) ψ * jacobiSum χ φ = gaussSum χ ψ * gaussSum φ ψ := by
classical
rw [gaussSum_mul _ _ ψ, sum_eq_sum_diff_singleton_add (mem_univ (0 : F))]
conv =>
enter [2, 2, 2, x]
rw [zero_sub, neg_eq_neg_one_mul x, map_mul, mul_left_comm (χ x) (φ (-1)),
← MulChar.mul_apply, ψ.map_zero_eq_one, mul_one]
rw [← mul_sum _ _ (φ (-1)), MulChar.sum_eq_zero_of_ne_one h, mul_zero, add_zero]
have sum_eq : ∀ t ∈ univ \ {0}, (∑ x : F, χ x * φ (t - x)) * ψ t =
(∑ y : F, χ (t * y) * φ (t - (t * y))) * ψ t := by
intro t ht
simp only [mem_sdiff, mem_univ, mem_singleton, true_and] at ht
exact congrArg (· * ψ t) (Equiv.sum_comp (Equiv.mulLeft₀ t ht) _).symm
simp_rw [← sum_mul, sum_congr rfl sum_eq, ← mul_one_sub, map_mul, mul_assoc]
conv => enter [2, 2, t, 1, 2, x, 2]; rw [← mul_assoc, mul_comm (χ x) (φ t)]
simp_rw [← mul_assoc, ← MulChar.mul_apply, mul_assoc, ← mul_sum, mul_right_comm]
rw [← jacobiSum, ← sum_mul, gaussSum, sum_eq_sum_diff_singleton_add (mem_univ (0 : F)),
(χ * φ).map_zero, zero_mul, add_zero]
end FiniteField
section field_field
variable {F F' : Type*} [Fintype F] [Field F] [Field F']
/-- If `χ` and `φ` are multiplicative characters on a finite field `F` with values
in another field `F'` and such that `χφ` is nontrivial, then `J(χ,φ) = g(χ) * g(φ) / g(χφ)`. -/
theorem jacobiSum_eq_gaussSum_mul_gaussSum_div_gaussSum (h : (Fintype.card F : F') ≠ 0)
{χ φ : MulChar F F'} (hχφ : χ * φ ≠ 1) {ψ : AddChar F F'} (hψ : ψ.IsPrimitive) :
jacobiSum χ φ = gaussSum χ ψ * gaussSum φ ψ / gaussSum (χ * φ) ψ := by
rw [eq_div_iff <| gaussSum_ne_zero_of_nontrivial h hχφ hψ, mul_comm]
exact jacobiSum_mul_nontrivial hχφ ψ
open AddChar MulChar in
/-- If `χ` and `φ` are multiplicative characters on a finite field `F` with values in another
field `F'` such that `χ`, `φ` and `χφ` are all nontrivial and `char F' ≠ char F`, then
`J(χ,φ) * J(χ⁻¹,φ⁻¹) = #F` (in `F'`). -/
lemma jacobiSum_mul_jacobiSum_inv (h : ringChar F' ≠ ringChar F) {χ φ : MulChar F F'} (hχ : χ ≠ 1)
(hφ : φ ≠ 1) (hχφ : χ * φ ≠ 1) :
jacobiSum χ φ * jacobiSum χ⁻¹ φ⁻¹ = Fintype.card F := by
obtain ⟨n, hp, hc⟩ := FiniteField.card F (ringChar F)
-- Obtain primitive additive character `ψ : F → FF'`.
let ψ := FiniteField.primitiveChar F F' h
-- the target field of `ψ`
let FF' := CyclotomicField ψ.n F'
-- Consider `χ` and `φ` as characters `F → FF'`.
let χ' := χ.ringHomComp (algebraMap F' FF')
let φ' := φ.ringHomComp (algebraMap F' FF')
have hinj := (algebraMap F' FF').injective
apply hinj
rw [map_mul, ← jacobiSum_ringHomComp, ← jacobiSum_ringHomComp]
have Hχφ : χ' * φ' ≠ 1 := by
rw [← ringHomComp_mul]
exact (MulChar.ringHomComp_ne_one_iff hinj).mpr hχφ
have Hχφ' : χ'⁻¹ * φ'⁻¹ ≠ 1 := by
rwa [← mul_inv, inv_ne_one]
have Hχ : χ' ≠ 1 := (MulChar.ringHomComp_ne_one_iff hinj).mpr hχ
have Hφ : φ' ≠ 1 := (MulChar.ringHomComp_ne_one_iff hinj).mpr hφ
have Hcard : (Fintype.card F : FF') ≠ 0 := by
intro H
simp only [hc, Nat.cast_pow, ne_eq, PNat.ne_zero, not_false_eq_true, pow_eq_zero_iff] at H
exact h <| (Algebra.ringChar_eq F' FF').trans <| CharP.ringChar_of_prime_eq_zero hp H
have H := (gaussSum_mul_gaussSum_eq_card Hχφ ψ.prim).trans_ne Hcard
apply_fun (gaussSum (χ' * φ') ψ.char * gaussSum (χ' * φ')⁻¹ ψ.char⁻¹ * ·)
using mul_right_injective₀ H
simp only
rw [mul_mul_mul_comm, jacobiSum_mul_nontrivial Hχφ, mul_inv, ← ringHomComp_inv,
← ringHomComp_inv, jacobiSum_mul_nontrivial Hχφ', map_natCast, ← mul_mul_mul_comm,
gaussSum_mul_gaussSum_eq_card Hχ ψ.prim, gaussSum_mul_gaussSum_eq_card Hφ ψ.prim,
← mul_inv, gaussSum_mul_gaussSum_eq_card Hχφ ψ.prim]
end field_field
section image
variable {F R : Type*} [Fintype F] [Field F] [CommRing R] [IsDomain R]
/-- If `χ` and `φ` are multiplicative characters on a finite field `F` satisfying `χ^n = φ^n = 1`
and with values in an integral domain `R`, and `μ` is a primitive `n`th root of unity in `R`,
then the Jacobi sum `J(χ,φ)` is in `ℤ[μ] ⊆ R`. -/
lemma jacobiSum_mem_algebraAdjoin_of_pow_eq_one {n : ℕ} [NeZero n] {χ φ : MulChar F R}
(hχ : χ ^ n = 1) (hφ : φ ^ n = 1) {μ : R} (hμ : IsPrimitiveRoot μ n) :
jacobiSum χ φ ∈ Algebra.adjoin ℤ {μ} :=
Subalgebra.sum_mem _ fun _ _ ↦ Subalgebra.mul_mem _
(MulChar.apply_mem_algebraAdjoin_of_pow_eq_one hχ hμ _)
(MulChar.apply_mem_algebraAdjoin_of_pow_eq_one hφ hμ _)
open Algebra in
private
lemma MulChar.exists_apply_sub_one_eq_mul_sub_one {n : ℕ} [NeZero n] {χ : MulChar F R} {μ : R}
(hχ : χ ^ n = 1) (hμ : IsPrimitiveRoot μ n) {x : F} (hx : x ≠ 0) :
∃ z ∈ Algebra.adjoin ℤ {μ}, χ x - 1 = z * (μ - 1) := by
obtain ⟨k, _, hk⟩ := exists_apply_eq_pow hχ hμ hx
refine hk ▸ ⟨(Finset.range k).sum (μ ^ ·), ?_, (geom_sum_mul μ k).symm⟩
exact Subalgebra.sum_mem _ fun m _ ↦ Subalgebra.pow_mem _ (self_mem_adjoin_singleton _ μ) _
private
lemma MulChar.exists_apply_sub_one_mul_apply_sub_one {n : ℕ} [NeZero n] {χ ψ : MulChar F R}
{μ : R} (hχ : χ ^ n = 1) (hψ : ψ ^ n = 1) (hμ : IsPrimitiveRoot μ n) (x : F) :
∃ z ∈ Algebra.adjoin ℤ {μ}, (χ x - 1) * (ψ (1 - x) - 1) = z * (μ - 1) ^ 2 := by
rcases eq_or_ne x 0 with rfl | hx₀
· exact ⟨0, Subalgebra.zero_mem _, by rw [sub_zero, ψ.map_one, sub_self, mul_zero, zero_mul]⟩
rcases eq_or_ne x 1 with rfl | hx₁
· exact ⟨0, Subalgebra.zero_mem _, by rw [χ.map_one, sub_self, zero_mul, zero_mul]⟩
obtain ⟨z₁, hz₁, Hz₁⟩ := MulChar.exists_apply_sub_one_eq_mul_sub_one hχ hμ hx₀
obtain ⟨z₂, hz₂, Hz₂⟩ :=
MulChar.exists_apply_sub_one_eq_mul_sub_one hψ hμ (sub_ne_zero_of_ne hx₁.symm)
rewrite [Hz₁, Hz₂, sq]
exact ⟨z₁ * z₂, Subalgebra.mul_mem _ hz₁ hz₂, mul_mul_mul_comm ..⟩
/-- If `χ` and `ψ` are multiplicative characters of order dividing `n` on a finite field `F`
with values in an integral domain `R` and `μ` is a primitive `n`th root of unity in `R`,
then `J(χ,ψ) = -1 + z*(μ - 1)^2` for some `z ∈ ℤ[μ] ⊆ R`. (We assume that `#F ≡ 1 mod n`.)
Note that we do not state this as a divisibility in `R`, as this would give a weaker statement. -/
lemma exists_jacobiSum_eq_neg_one_add {n : ℕ} (hn : 2 < n) {χ ψ : MulChar F R}
{μ : R} (hχ : χ ^ n = 1) (hψ : ψ ^ n = 1) (hn' : n ∣ Fintype.card F - 1)
(hμ : IsPrimitiveRoot μ n) :
∃ z ∈ Algebra.adjoin ℤ {μ}, jacobiSum χ ψ = -1 + z * (μ - 1) ^ 2 := by
obtain ⟨q, hq⟩ := hn'
rw [Nat.sub_eq_iff_eq_add NeZero.one_le] at hq
obtain ⟨z₁, hz₁, Hz₁⟩ := hμ.self_sub_one_pow_dvd_order hn
by_cases hχ₀ : χ = 1 <;> by_cases hψ₀ : ψ = 1
· rw [hχ₀, hψ₀, jacobiSum_one_one]
refine ⟨q * z₁, Subalgebra.mul_mem _ (Subalgebra.natCast_mem _ q) hz₁, ?_⟩
rw [hq, Nat.cast_add, Nat.cast_mul, Hz₁]
ring
· refine ⟨0, Subalgebra.zero_mem _, ?_⟩
rw [hχ₀, jacobiSum_one_nontrivial hψ₀, zero_mul, add_zero]
· refine ⟨0, Subalgebra.zero_mem _, ?_⟩
rw [jacobiSum_comm, hψ₀, jacobiSum_one_nontrivial hχ₀, zero_mul, add_zero]
· classical
rw [jacobiSum_eq_aux, MulChar.sum_eq_zero_of_ne_one hχ₀, MulChar.sum_eq_zero_of_ne_one hψ₀, hq]
have : NeZero n := ⟨by cutsat⟩
have H := MulChar.exists_apply_sub_one_mul_apply_sub_one hχ hψ hμ
have Hcs x := (H x).choose_spec
refine ⟨-q * z₁ + ∑ x ∈ (univ \ {0, 1} : Finset F), (H x).choose, ?_, ?_⟩
· refine Subalgebra.add_mem _ (Subalgebra.mul_mem _ (Subalgebra.neg_mem _ ?_) hz₁) ?_
· exact Subalgebra.natCast_mem ..
· exact Subalgebra.sum_mem _ fun x _ ↦ (Hcs x).1
· conv => enter [1, 2, 2, x]; rw [(Hcs x).2]
rw [← Finset.sum_mul, Nat.cast_add, Nat.cast_mul, Hz₁]
ring
end image
section GaussSum
variable {F R : Type*} [Fintype F] [Field F] [CommRing R] [IsDomain R]
lemma gaussSum_pow_eq_prod_jacobiSum_aux (χ : MulChar F R) (ψ : AddChar F R) {n : ℕ}
(hn₁ : 0 < n) (hn₂ : n < orderOf χ) :
gaussSum χ ψ ^ n = gaussSum (χ ^ n) ψ * ∏ j ∈ Ico 1 n, jacobiSum χ (χ ^ j) := by
induction n, hn₁ using Nat.le_induction with
| base => simp only [pow_one, le_refl, Ico_eq_empty_of_le, prod_empty, mul_one]
| succ n hn ih =>
specialize ih <| lt_trans (Nat.lt_succ_self n) hn₂
have gauss_rw : gaussSum (χ ^ n) ψ * gaussSum χ ψ =
jacobiSum χ (χ ^ n) * gaussSum (χ ^ (n + 1)) ψ := by
have hχn : χ * (χ ^ n) ≠ 1 :=
pow_succ' χ n ▸ pow_ne_one_of_lt_orderOf n.add_one_ne_zero hn₂
rw [mul_comm, ← jacobiSum_mul_nontrivial hχn, mul_comm, ← pow_succ']
apply_fun (· * gaussSum χ ψ) at ih
rw [mul_right_comm, ← pow_succ, gauss_rw] at ih
rw [ih, Finset.prod_Ico_succ_top hn, mul_rotate, mul_assoc]
/-- If `χ` is a multiplicative character of order `n ≥ 2` on a finite field `F`,
then `g(χ)^n = χ(-1) * #F * J(χ,χ) * J(χ,χ²) * ... * J(χ,χⁿ⁻²)`. -/
theorem gaussSum_pow_eq_prod_jacobiSum {χ : MulChar F R} {ψ : AddChar F R} (hχ : 2 ≤ orderOf χ)
(hψ : ψ.IsPrimitive) :
gaussSum χ ψ ^ orderOf χ =
χ (-1) * Fintype.card F * ∏ i ∈ Ico 1 (orderOf χ - 1), jacobiSum χ (χ ^ i) := by
have := gaussSum_pow_eq_prod_jacobiSum_aux χ ψ (n := orderOf χ - 1) (by cutsat) (by cutsat)
apply_fun (gaussSum χ ψ * ·) at this
rw [← pow_succ', Nat.sub_one_add_one_eq_of_pos (by cutsat)] at this
have hχ₁ : χ ≠ 1 :=
fun h ↦ ((orderOf_one (G := MulChar F R) ▸ h ▸ hχ).trans_lt Nat.one_lt_two).false
rw [this, ← mul_assoc, gaussSum_mul_gaussSum_pow_orderOf_sub_one hχ₁ hψ]
end GaussSum |
.lake/packages/mathlib/Mathlib/NumberTheory/LocalField/Basic.lean | import Mathlib.RingTheory.Valuation.DiscreteValuativeRel
import Mathlib.Topology.Algebra.Valued.LocallyCompact
import Mathlib.Topology.Algebra.Valued.ValuativeRel
/-!
# Definition of (Non-archimedean) local fields
Given a topological field `K` equipped with an equivalence class of valuations (a `ValuativeRel`),
we say that it is a non-archimedean local field if the topology comes from the given valuation,
and it is locally compact and non-discrete.
-/
/--
Given a topological field `K` equipped with an equivalence class of valuations (a `ValuativeRel`),
we say that it is a non-archimedean local field if the topology comes from the given valuation,
and it is locally compact and non-discrete.
This implies the following typeclasses via `inferInstance`
- `IsValuativeTopology K`
- `LocallyCompactSpace K`
- `IsTopologicalDivisionRing K`
- `ValuativeRel.IsNontrivial K`
- `ValuativeRel.IsRankLeOne K`
- `ValuativeRel.IsDiscrete K`
- `IsDiscreteValuationRing 𝒪[K]`
- `Finite 𝓀[K]`
Assuming we have a compatible `UniformSpace K` instance
(e.g. via `IsTopologicalAddGroup.toUniformSpace` and `isUniformAddGroup_of_addCommGroup`) then
- `CompleteSpace K`
- `CompleteSpace 𝒪[K]`
-/
class IsNonarchimedeanLocalField
(K : Type*) [Field K] [ValuativeRel K] [TopologicalSpace K] : Prop extends
IsValuativeTopology K,
LocallyCompactSpace K,
ValuativeRel.IsNontrivial K
open ValuativeRel Valued.integer
open scoped WithZero
namespace IsNonarchimedeanLocalField
section TopologicalSpace
variable (K : Type*) [Field K] [ValuativeRel K] [TopologicalSpace K] [IsNonarchimedeanLocalField K]
attribute [local simp] zero_lt_iff
instance : IsTopologicalDivisionRing K := by
letI := IsTopologicalAddGroup.rightUniformSpace K
haveI := isUniformAddGroup_of_addCommGroup (G := K)
infer_instance
lemma isCompact_closedBall (γ : ValueGroupWithZero K) : IsCompact { x | valuation K x ≤ γ } := by
obtain ⟨γ, rfl⟩ := ValuativeRel.valuation_surjective γ
by_cases hγ : γ = 0
· simp [hγ]
letI := IsTopologicalAddGroup.rightUniformSpace K
letI := isUniformAddGroup_of_addCommGroup (G := K)
obtain ⟨s, hs, -, hs'⟩ := LocallyCompactSpace.local_compact_nhds (0 : K) .univ Filter.univ_mem
obtain ⟨r, hr, hr1, H⟩ :
∃ r', r' ≠ 0 ∧ valuation K r' < 1 ∧ { x | valuation K x ≤ valuation K r' } ⊆ s := by
obtain ⟨r, hr, hrs⟩ := (IsValuativeTopology.hasBasis_nhds_zero' K).mem_iff.mp hs
obtain ⟨r', hr', hr⟩ := Valuation.IsNontrivial.exists_lt_one (v := valuation K)
simp only [ne_eq, map_eq_zero] at hr'
obtain hr1 | hr1 := lt_or_ge r 1
· obtain ⟨r, rfl⟩ := ValuativeRel.valuation_surjective r
simp only [ne_eq, map_eq_zero] at hr
refine ⟨r ^ 2, by simpa using hr, by simpa [pow_two], fun x hx ↦ hrs ?_⟩
simp only [map_pow, Set.mem_setOf_eq] at hx ⊢
exact hx.trans_lt (by simpa [pow_two, hr])
· refine ⟨r', hr', hr, .trans ?_ hrs⟩
intro x hx
dsimp at hx ⊢
exact hx.trans_lt (hr.trans_le hr1)
convert (hs'.of_isClosed_subset (Valued.isClosed_closedBall K _) H).image
(Homeomorph.mulLeft₀ (γ / r) (by simp [hr, div_eq_zero_iff, hγ])).continuous using 1
refine .trans ?_ (Equiv.image_eq_preimage_symm _ _).symm
ext x
simp [div_mul_eq_mul_div, div_le_iff₀, IsValuativeTopology.v_eq_valuation, hγ, hr]
instance : CompactSpace 𝒪[K] := isCompact_iff_compactSpace.mp (isCompact_closedBall K 1)
instance (K : Type*) [Field K] [ValuativeRel K] [UniformSpace K] [IsUniformAddGroup K]
[IsValuativeTopology K] : (Valued.v (R := K) (Γ₀ := ValueGroupWithZero K)).Compatible :=
inferInstanceAs (valuation K).Compatible
instance : IsDiscreteValuationRing 𝒪[K] :=
letI := IsTopologicalAddGroup.rightUniformSpace K
haveI := isUniformAddGroup_of_addCommGroup (G := K)
haveI : CompactSpace (Valued.integer K) := inferInstanceAs (CompactSpace 𝒪[K])
Valued.integer.isDiscreteValuationRing_of_compactSpace
/-- The value group of a local field is (uniquely) isomorphic to `ℤᵐ⁰`. -/
noncomputable
def valueGroupWithZeroIsoInt : ValueGroupWithZero K ≃*o ℤᵐ⁰ := by
apply Nonempty.some
letI := IsTopologicalAddGroup.rightUniformSpace K
haveI := isUniformAddGroup_of_addCommGroup (G := K)
obtain ⟨_⟩ := Valued.integer.locallyFiniteOrder_units_mrange_of_isCompact_integer
(isCompact_iff_compactSpace.mpr (inferInstanceAs (CompactSpace 𝒪[K])))
let e : (MonoidHom.mrange (valuation K)) ≃*o ValueGroupWithZero K :=
⟨.ofBijective (MonoidHom.mrange (valuation K)).subtype ⟨Subtype.val_injective, fun x ↦
⟨⟨x, ValuativeRel.valuation_surjective x⟩, rfl⟩⟩, .rfl⟩
have : Nontrivial (ValueGroupWithZero K)ˣ := isNontrivial_iff_nontrivial_units.mp inferInstance
have : Nontrivial (↥(MonoidHom.mrange (valuation K)))ˣ :=
(Units.map_injective (f := e.symm.toMonoidHom) e.symm.injective).nontrivial
exact ⟨e.symm.trans (LocallyFiniteOrder.orderMonoidWithZeroEquiv _)⟩
instance : ValuativeRel.IsDiscrete K :=
(ValuativeRel.nonempty_orderIso_withZeroMul_int_iff.mp ⟨valueGroupWithZeroIsoInt K⟩).1
instance : ValuativeRel.IsRankLeOne K :=
ValuativeRel.isRankLeOne_iff_mulArchimedean.mpr
(.comap (valueGroupWithZeroIsoInt K).toMonoidHom (valueGroupWithZeroIsoInt K).strictMono)
instance : Finite 𝓀[K] :=
letI := IsTopologicalAddGroup.rightUniformSpace K
haveI := isUniformAddGroup_of_addCommGroup (G := K)
letI : (Valued.v (R := K)).RankOne :=
⟨IsRankLeOne.nonempty.some.emb, IsRankLeOne.nonempty.some.strictMono⟩
(compactSpace_iff_completeSpace_and_isDiscreteValuationRing_and_finite_residueField.mp
(inferInstanceAs (CompactSpace 𝒪[K]))).2.2
proof_wanted isAdicComplete : IsAdicComplete 𝓂[K] 𝒪[K]
end TopologicalSpace
section UniformSpace
variable (K : Type*) [Field K] [ValuativeRel K]
[UniformSpace K] [IsUniformAddGroup K] [IsNonarchimedeanLocalField K]
instance : CompleteSpace K :=
letI : (Valued.v (R := K)).RankOne :=
⟨IsRankLeOne.nonempty.some.emb, IsRankLeOne.nonempty.some.strictMono⟩
open scoped Valued in
have : ProperSpace K := .of_nontriviallyNormedField_of_weaklyLocallyCompactSpace K
(properSpace_iff_completeSpace_and_isDiscreteValuationRing_integer_and_finite_residueField.mp
inferInstance).1
instance : CompleteSpace 𝒪[K] :=
letI : (Valued.v (R := K)).RankOne :=
⟨IsRankLeOne.nonempty.some.emb, IsRankLeOne.nonempty.some.strictMono⟩
(compactSpace_iff_completeSpace_and_isDiscreteValuationRing_and_finite_residueField.mp
(inferInstanceAs (CompactSpace 𝒪[K]))).1
end UniformSpace
end IsNonarchimedeanLocalField |
.lake/packages/mathlib/Mathlib/NumberTheory/Zsqrtd/ToReal.lean | import Mathlib.Data.Real.Sqrt
import Mathlib.NumberTheory.Zsqrtd.Basic
/-!
# Image of `Zsqrtd` in `ℝ`
This file defines `Zsqrtd.toReal` and related lemmas.
It is in a separate file to avoid pulling in all of `Data.Real` into `Data.Zsqrtd`.
-/
namespace Zsqrtd
/-- The image of `Zsqrtd` in `ℝ`, using `Real.sqrt` which takes the positive root of `d`.
If the negative root is desired, use `toReal h (star a)`. -/
@[simps!]
noncomputable def toReal {d : ℤ} (h : 0 ≤ d) : ℤ√d →+* ℝ :=
lift ⟨√↑d, Real.mul_self_sqrt (Int.cast_nonneg h)⟩
theorem toReal_injective {d : ℤ} (h0d : 0 ≤ d) (hd : ∀ n : ℤ, d ≠ n * n) :
Function.Injective (toReal h0d) :=
lift_injective _ hd
end Zsqrtd |
.lake/packages/mathlib/Mathlib/NumberTheory/Zsqrtd/GaussianInt.lean | import Mathlib.Data.Complex.Basic
import Mathlib.Data.Nat.Prime.Basic
import Mathlib.Data.Real.Archimedean
import Mathlib.NumberTheory.Zsqrtd.Basic
/-!
# Gaussian integers
The Gaussian integers are complex integer, complex numbers whose real and imaginary parts are both
integers.
## Main definitions
The Euclidean domain structure on `ℤ[i]` is defined in this file.
The homomorphism `GaussianInt.toComplex` into the complex numbers is also defined in this file.
## See also
See `NumberTheory.Zsqrtd.QuadraticReciprocity` for:
* `prime_iff_mod_four_eq_three_of_nat_prime`:
A prime natural number is prime in `ℤ[i]` if and only if it is `3` mod `4`
## Notation
This file uses the local notation `ℤ[i]` for `GaussianInt`
## Implementation notes
Gaussian integers are implemented using the more general definition `Zsqrtd`, the type of integers
adjoined a square root of `d`, in this case `-1`. The definition is reducible, so that properties
and definitions about `Zsqrtd` can easily be used.
-/
open Zsqrtd Complex
open scoped ComplexConjugate
/-- The Gaussian integers, defined as `ℤ√(-1)`. -/
abbrev GaussianInt : Type :=
Zsqrtd (-1)
local notation "ℤ[i]" => GaussianInt
namespace GaussianInt
instance : Repr ℤ[i] :=
⟨fun x _ => "⟨" ++ repr x.re ++ ", " ++ repr x.im ++ "⟩"⟩
instance instCommRing : CommRing ℤ[i] :=
Zsqrtd.commRing
section
attribute [-instance] Complex.instField -- Avoid making things noncomputable unnecessarily.
/-- The embedding of the Gaussian integers into the complex numbers, as a ring homomorphism. -/
def toComplex : ℤ[i] →+* ℂ :=
Zsqrtd.lift ⟨I, by simp⟩
end
instance : Coe ℤ[i] ℂ :=
⟨toComplex⟩
theorem toComplex_def (x : ℤ[i]) : (x : ℂ) = x.re + x.im * I :=
rfl
theorem toComplex_def' (x y : ℤ) : ((⟨x, y⟩ : ℤ[i]) : ℂ) = x + y * I := by simp [toComplex_def]
theorem toComplex_def₂ (x : ℤ[i]) : (x : ℂ) = ⟨x.re, x.im⟩ := by
apply Complex.ext <;> simp [toComplex_def]
@[simp]
theorem intCast_re (x : ℤ[i]) : ((x.re : ℤ) : ℝ) = (x : ℂ).re := by simp [toComplex_def]
@[deprecated (since := "2025-08-31")] alias to_real_re := intCast_re
@[simp]
theorem intCast_im (x : ℤ[i]) : ((x.im : ℤ) : ℝ) = (x : ℂ).im := by simp [toComplex_def]
@[deprecated (since := "2025-08-31")] alias to_real_im := intCast_im
@[simp]
theorem re_toComplex (x y : ℤ) : ((⟨x, y⟩ : ℤ[i]) : ℂ).re = x := by simp [toComplex_def]
@[deprecated (since := "2025-08-31")] alias toComplex_re := re_toComplex
@[simp]
theorem im_toComplex (x y : ℤ) : ((⟨x, y⟩ : ℤ[i]) : ℂ).im = y := by simp [toComplex_def]
@[deprecated (since := "2025-08-31")] alias toComplex_im := im_toComplex
theorem toComplex_add (x y : ℤ[i]) : ((x + y : ℤ[i]) : ℂ) = x + y :=
toComplex.map_add _ _
theorem toComplex_mul (x y : ℤ[i]) : ((x * y : ℤ[i]) : ℂ) = x * y :=
toComplex.map_mul _ _
theorem toComplex_one : ((1 : ℤ[i]) : ℂ) = 1 :=
toComplex.map_one
theorem toComplex_zero : ((0 : ℤ[i]) : ℂ) = 0 :=
toComplex.map_zero
theorem toComplex_neg (x : ℤ[i]) : ((-x : ℤ[i]) : ℂ) = -x :=
toComplex.map_neg _
theorem toComplex_sub (x y : ℤ[i]) : ((x - y : ℤ[i]) : ℂ) = x - y :=
toComplex.map_sub _ _
@[simp]
theorem toComplex_star (x : ℤ[i]) : ((star x : ℤ[i]) : ℂ) = conj (x : ℂ) := by
rw [toComplex_def₂, toComplex_def₂]
exact congr_arg₂ _ rfl (Int.cast_neg _)
@[simp]
theorem toComplex_inj {x y : ℤ[i]} : (x : ℂ) = y ↔ x = y := by
cases x; cases y; simp [toComplex_def₂]
lemma toComplex_injective : Function.Injective GaussianInt.toComplex :=
fun ⦃_ _⦄ ↦ toComplex_inj.mp
@[simp]
theorem toComplex_eq_zero {x : ℤ[i]} : (x : ℂ) = 0 ↔ x = 0 := by
rw [← toComplex_zero, toComplex_inj]
@[simp]
theorem intCast_real_norm (x : ℤ[i]) : (x.norm : ℝ) = Complex.normSq (x : ℂ) := by
rw [Zsqrtd.norm, normSq]; simp
@[simp]
theorem intCast_complex_norm (x : ℤ[i]) : (x.norm : ℂ) = Complex.normSq (x : ℂ) := by
cases x; rw [Zsqrtd.norm, normSq]; simp
theorem norm_nonneg (x : ℤ[i]) : 0 ≤ norm x :=
Zsqrtd.norm_nonneg (by simp) _
@[simp]
theorem norm_eq_zero {x : ℤ[i]} : norm x = 0 ↔ x = 0 := by rw [← @Int.cast_inj ℝ _ _ _]; simp
theorem norm_pos {x : ℤ[i]} : 0 < norm x ↔ x ≠ 0 := by
rw [lt_iff_le_and_ne, Ne, eq_comm, norm_eq_zero]; simp [norm_nonneg]
theorem abs_natCast_norm (x : ℤ[i]) : (x.norm.natAbs : ℤ) = x.norm :=
Int.natAbs_of_nonneg (norm_nonneg _)
theorem natCast_natAbs_norm {α : Type*} [AddGroupWithOne α] (x : ℤ[i]) :
(x.norm.natAbs : α) = x.norm := by
simp
theorem natAbs_norm_eq (x : ℤ[i]) :
x.norm.natAbs = x.re.natAbs * x.re.natAbs + x.im.natAbs * x.im.natAbs := by
zify
rw [abs_norm (by simp)]
simp [Zsqrtd.norm]
instance : Div ℤ[i] :=
⟨fun x y =>
let n := (norm y : ℚ)⁻¹
let c := star y
⟨round ((x * c).re * n : ℚ), round ((x * c).im * n : ℚ)⟩⟩
theorem div_def (x y : ℤ[i]) :
x / y = ⟨round ((x * star y).re / norm y : ℚ), round ((x * star y).im / norm y : ℚ)⟩ :=
show Zsqrtd.mk _ _ = _ by simp [div_eq_mul_inv]
theorem toComplex_re_div (x y : ℤ[i]) : ((x / y : ℤ[i]) : ℂ).re = round (x / y : ℂ).re := by
rw [div_def, ← @Rat.round_cast ℝ _ _]
simp [-Rat.round_cast, mul_assoc, div_eq_mul_inv, add_mul]
@[deprecated (since := "2025-08-31")] alias toComplex_div_re := toComplex_re_div
theorem toComplex_im_div (x y : ℤ[i]) : ((x / y : ℤ[i]) : ℂ).im = round (x / y : ℂ).im := by
rw [div_def, ← @Rat.round_cast ℝ _ _, ← @Rat.round_cast ℝ _ _]
simp [-Rat.round_cast, mul_assoc, div_eq_mul_inv, add_mul]
@[deprecated (since := "2025-08-31")] alias toComplex_div_im := toComplex_im_div
theorem normSq_le_normSq_of_re_le_of_im_le {x y : ℂ} (hre : |x.re| ≤ |y.re|)
(him : |x.im| ≤ |y.im|) : Complex.normSq x ≤ Complex.normSq y := by
rw [normSq_apply, normSq_apply, ← _root_.abs_mul_self, _root_.abs_mul, ←
_root_.abs_mul_self y.re, _root_.abs_mul y.re, ← _root_.abs_mul_self x.im,
_root_.abs_mul x.im, ← _root_.abs_mul_self y.im, _root_.abs_mul y.im]
gcongr
theorem normSq_div_sub_div_lt_one (x y : ℤ[i]) :
Complex.normSq ((x / y : ℂ) - ((x / y : ℤ[i]) : ℂ)) < 1 :=
calc
Complex.normSq ((x / y : ℂ) - ((x / y : ℤ[i]) : ℂ))
_ = Complex.normSq
((x / y : ℂ).re - ((x / y : ℤ[i]) : ℂ).re + ((x / y : ℂ).im - ((x / y : ℤ[i]) : ℂ).im) *
I : ℂ) :=
congr_arg _ <| by apply Complex.ext <;> simp
_ ≤ Complex.normSq (1 / 2 + 1 / 2 * I) := by
have : |(2⁻¹ : ℝ)| = 2⁻¹ := abs_of_nonneg (by simp)
exact normSq_le_normSq_of_re_le_of_im_le
(by rw [toComplex_re_div]; simp [normSq, this]; simpa using abs_sub_round (x / y : ℂ).re)
(by rw [toComplex_im_div]; simp [normSq, this]; simpa using abs_sub_round (x / y : ℂ).im)
_ < 1 := by simp [normSq]; norm_num
instance : Mod ℤ[i] :=
⟨fun x y => x - y * (x / y)⟩
theorem mod_def (x y : ℤ[i]) : x % y = x - y * (x / y) :=
rfl
theorem norm_mod_lt (x : ℤ[i]) {y : ℤ[i]} (hy : y ≠ 0) : (x % y).norm < y.norm :=
have : (y : ℂ) ≠ 0 := by rwa [Ne, ← toComplex_zero, toComplex_inj]
(@Int.cast_lt ℝ _ _ _ _).1 <|
calc
↑(Zsqrtd.norm (x % y)) = Complex.normSq (x - y * (x / y : ℤ[i]) : ℂ) := by simp [mod_def]
_ = Complex.normSq (y : ℂ) * Complex.normSq (x / y - (x / y : ℤ[i]) : ℂ) := by
rw [← normSq_mul, mul_sub, mul_div_cancel₀ _ this]
_ < Complex.normSq (y : ℂ) * 1 :=
(mul_lt_mul_of_pos_left (normSq_div_sub_div_lt_one _ _) (normSq_pos.2 this))
_ = Zsqrtd.norm y := by simp
theorem natAbs_norm_mod_lt (x : ℤ[i]) {y : ℤ[i]} (hy : y ≠ 0) :
(x % y).norm.natAbs < y.norm.natAbs :=
Int.ofNat_lt.1 <| by simp [norm_mod_lt x hy]
theorem norm_le_norm_mul_left (x : ℤ[i]) {y : ℤ[i]} (hy : y ≠ 0) :
(norm x).natAbs ≤ (norm (x * y)).natAbs := by
rw [Zsqrtd.norm_mul, Int.natAbs_mul]
exact le_mul_of_one_le_right (Nat.zero_le _) (Int.ofNat_le.1 (by
rw [abs_natCast_norm]
exact Int.add_one_le_of_lt (norm_pos.2 hy)))
instance instNontrivial : Nontrivial ℤ[i] :=
⟨⟨0, 1, by decide⟩⟩
instance : EuclideanDomain ℤ[i] :=
{ GaussianInt.instCommRing,
GaussianInt.instNontrivial with
quotient := (· / ·)
remainder := (· % ·)
quotient_zero := by simp [div_def]; rfl
quotient_mul_add_remainder_eq := fun _ _ => by simp [mod_def]
r := _
r_wellFounded := (measure (Int.natAbs ∘ norm)).wf
remainder_lt := natAbs_norm_mod_lt
mul_left_not_lt := fun a _ hb0 => not_lt_of_ge <| norm_le_norm_mul_left a hb0 }
open PrincipalIdealRing
theorem sq_add_sq_of_nat_prime_of_not_irreducible (p : ℕ) [hp : Fact p.Prime]
(hpi : ¬Irreducible (p : ℤ[i])) : ∃ a b, a ^ 2 + b ^ 2 = p :=
have hpu : ¬IsUnit (p : ℤ[i]) :=
mt norm_eq_one_iff.2 <| by
rw [norm_natCast, Int.natAbs_mul, mul_eq_one]
exact fun h => (ne_of_lt hp.1.one_lt).symm h.1
have hab : ∃ a b, (p : ℤ[i]) = a * b ∧ ¬IsUnit a ∧ ¬IsUnit b := by
simpa [irreducible_iff, hpu, not_forall, not_or] using hpi
let ⟨a, b, hpab, hau, hbu⟩ := hab
have hnap : (norm a).natAbs = p :=
((hp.1.mul_eq_prime_sq_iff (mt norm_eq_one_iff.1 hau) (mt norm_eq_one_iff.1 hbu)).1 <| by
rw [← Int.natCast_inj, Int.natCast_pow, sq, ← @norm_natCast (-1), hpab]; simp).1
⟨a.re.natAbs, a.im.natAbs, by simpa [natAbs_norm_eq, sq] using hnap⟩
end GaussianInt |
.lake/packages/mathlib/Mathlib/NumberTheory/Zsqrtd/Basic.lean | import Mathlib.Algebra.Ring.Associated
import Mathlib.Algebra.Star.Unitary
import Mathlib.RingTheory.PrincipalIdealDomain
import Mathlib.Tactic.Ring
import Mathlib.Algebra.EuclideanDomain.Int
/-! # ℤ[√d]
The ring of integers adjoined with a square root of `d : ℤ`.
After defining the norm, we show that it is a linearly ordered commutative ring,
as well as an integral domain.
We provide the universal property, that ring homomorphisms `ℤ√d →+* R` correspond
to choices of square roots of `d` in `R`.
-/
/-- The ring of integers adjoined with a square root of `d`.
These have the form `a + b √d` where `a b : ℤ`. The components
are called `re` and `im` by analogy to the negative `d` case. -/
@[ext]
structure Zsqrtd (d : ℤ) where
/-- Component of the integer not multiplied by `√d` -/
re : ℤ
/-- Component of the integer multiplied by `√d` -/
im : ℤ
deriving DecidableEq
@[inherit_doc] prefix:100 "ℤ√" => Zsqrtd
namespace Zsqrtd
section
variable {d : ℤ}
/-- Convert an integer to a `ℤ√d` -/
def ofInt (n : ℤ) : ℤ√d :=
⟨n, 0⟩
theorem re_ofInt (n : ℤ) : (ofInt n : ℤ√d).re = n :=
rfl
@[deprecated (since := "2025-08-31")] alias ofInt_re := re_ofInt
theorem im_ofInt (n : ℤ) : (ofInt n : ℤ√d).im = 0 :=
rfl
@[deprecated (since := "2025-08-31")] alias ofInt_im := im_ofInt
/-- The zero of the ring -/
instance : Zero (ℤ√d) :=
⟨ofInt 0⟩
@[simp]
theorem re_zero : (0 : ℤ√d).re = 0 :=
rfl
@[deprecated (since := "2025-08-31")] alias zero_re := re_zero
@[simp]
theorem im_zero : (0 : ℤ√d).im = 0 :=
rfl
@[deprecated (since := "2025-08-31")] alias zero_im := im_zero
instance : Inhabited (ℤ√d) :=
⟨0⟩
/-- The one of the ring -/
instance : One (ℤ√d) :=
⟨ofInt 1⟩
@[simp]
theorem re_one : (1 : ℤ√d).re = 1 :=
rfl
@[deprecated (since := "2025-08-31")] alias one_re := re_one
@[simp]
theorem im_one : (1 : ℤ√d).im = 0 :=
rfl
@[deprecated (since := "2025-08-31")] alias one_im := im_one
/-- The representative of `√d` in the ring -/
def sqrtd : ℤ√d :=
⟨0, 1⟩
@[simp]
theorem re_sqrtd : (sqrtd : ℤ√d).re = 0 :=
rfl
@[deprecated (since := "2025-08-31")] alias sqrtd_re := re_sqrtd
@[simp]
theorem im_sqrtd : (sqrtd : ℤ√d).im = 1 :=
rfl
@[deprecated (since := "2025-08-31")] alias sqrtd_im := im_sqrtd
/-- Addition of elements of `ℤ√d` -/
instance : Add (ℤ√d) :=
⟨fun z w => ⟨z.1 + w.1, z.2 + w.2⟩⟩
@[simp]
theorem add_def (x y x' y' : ℤ) : (⟨x, y⟩ + ⟨x', y'⟩ : ℤ√d) = ⟨x + x', y + y'⟩ :=
rfl
@[simp]
theorem re_add (z w : ℤ√d) : (z + w).re = z.re + w.re :=
rfl
@[deprecated (since := "2025-08-31")] alias add_re := re_add
@[simp]
theorem im_add (z w : ℤ√d) : (z + w).im = z.im + w.im :=
rfl
@[deprecated (since := "2025-08-31")] alias add_im := im_add
/-- Negation in `ℤ√d` -/
instance : Neg (ℤ√d) :=
⟨fun z => ⟨-z.1, -z.2⟩⟩
@[simp]
theorem re_neg (z : ℤ√d) : (-z).re = -z.re :=
rfl
@[deprecated (since := "2025-08-31")] alias neg_re := re_neg
@[simp]
theorem im_neg (z : ℤ√d) : (-z).im = -z.im :=
rfl
@[deprecated (since := "2025-08-31")] alias neg_im := im_neg
/-- Multiplication in `ℤ√d` -/
instance : Mul (ℤ√d) :=
⟨fun z w => ⟨z.1 * w.1 + d * z.2 * w.2, z.1 * w.2 + z.2 * w.1⟩⟩
@[simp]
theorem re_mul (z w : ℤ√d) : (z * w).re = z.re * w.re + d * z.im * w.im :=
rfl
@[deprecated (since := "2025-08-31")] alias mul_re := re_mul
@[simp]
theorem im_mul (z w : ℤ√d) : (z * w).im = z.re * w.im + z.im * w.re :=
rfl
@[deprecated (since := "2025-08-31")] alias mul_im := im_mul
instance addCommGroup : AddCommGroup (ℤ√d) := by
refine
{ sub := fun a b => a + -b
nsmul := @nsmulRec (ℤ√d) ⟨0⟩ ⟨(· + ·)⟩
zsmul := @zsmulRec (ℤ√d) ⟨0⟩ ⟨(· + ·)⟩ ⟨Neg.neg⟩ (@nsmulRec (ℤ√d) ⟨0⟩ ⟨(· + ·)⟩)
add_assoc := ?_
zero_add := ?_
add_zero := ?_
neg_add_cancel := ?_
add_comm := ?_ } <;>
intros <;>
ext <;>
simp [add_comm, add_left_comm]
@[simp]
theorem re_sub (z w : ℤ√d) : (z - w).re = z.re - w.re :=
rfl
@[deprecated (since := "2025-08-31")] alias sub_re := re_sub
@[simp]
theorem im_sub (z w : ℤ√d) : (z - w).im = z.im - w.im :=
rfl
@[deprecated (since := "2025-08-31")] alias sub_im := im_sub
instance addGroupWithOne : AddGroupWithOne (ℤ√d) :=
{ Zsqrtd.addCommGroup with
natCast := fun n => ofInt n
intCast := ofInt }
instance commRing : CommRing (ℤ√d) := by
refine
{ Zsqrtd.addGroupWithOne with
npow := @npowRec (ℤ√d) ⟨1⟩ ⟨(· * ·)⟩,
add_comm := ?_
left_distrib := ?_
right_distrib := ?_
zero_mul := ?_
mul_zero := ?_
mul_assoc := ?_
one_mul := ?_
mul_one := ?_
mul_comm := ?_ } <;>
intros <;>
ext <;>
simp <;>
ring
instance : AddMonoid (ℤ√d) := by infer_instance
instance : Monoid (ℤ√d) := by infer_instance
instance : CommMonoid (ℤ√d) := by infer_instance
instance : CommSemigroup (ℤ√d) := by infer_instance
instance : Semigroup (ℤ√d) := by infer_instance
instance : AddCommSemigroup (ℤ√d) := by infer_instance
instance : AddSemigroup (ℤ√d) := by infer_instance
instance : CommSemiring (ℤ√d) := by infer_instance
instance : Semiring (ℤ√d) := by infer_instance
instance : Ring (ℤ√d) := by infer_instance
instance : Distrib (ℤ√d) := by infer_instance
/-- Conjugation in `ℤ√d`. The conjugate of `a + b √d` is `a - b √d`. -/
instance : Star (ℤ√d) where
star z := ⟨z.1, -z.2⟩
@[simp]
theorem star_mk (x y : ℤ) : star (⟨x, y⟩ : ℤ√d) = ⟨x, -y⟩ :=
rfl
@[simp]
theorem re_star (z : ℤ√d) : (star z).re = z.re :=
rfl
@[deprecated (since := "2025-08-31")] alias star_re := re_star
@[simp]
theorem im_star (z : ℤ√d) : (star z).im = -z.im :=
rfl
@[deprecated (since := "2025-08-31")] alias star_im := im_star
instance : StarRing (ℤ√d) where
star_involutive _ := Zsqrtd.ext rfl (neg_neg _)
star_mul a b := by ext <;> simp <;> ring
star_add _ _ := Zsqrtd.ext rfl (neg_add _ _)
-- Porting note: proof was `by decide`
instance nontrivial : Nontrivial (ℤ√d) :=
⟨⟨0, 1, Zsqrtd.ext_iff.not.mpr (by simp)⟩⟩
@[simp]
theorem re_natCast (n : ℕ) : (n : ℤ√d).re = n :=
rfl
@[deprecated (since := "2025-08-31")] alias natCast_re := re_natCast
@[simp]
theorem re_ofNat (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℤ√d).re = n :=
rfl
@[deprecated (since := "2025-08-31")] alias ofNat_re := re_ofNat
@[simp]
theorem im_natCast (n : ℕ) : (n : ℤ√d).im = 0 :=
rfl
@[deprecated (since := "2025-08-31")] alias natCast_im := im_natCast
@[simp]
theorem im_ofNat (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℤ√d).im = 0 :=
rfl
@[deprecated (since := "2025-08-31")] alias ofNat_im := im_ofNat
theorem natCast_val (n : ℕ) : (n : ℤ√d) = ⟨n, 0⟩ :=
rfl
@[simp]
theorem re_intCast (n : ℤ) : (n : ℤ√d).re = n := by cases n <;> rfl
@[deprecated (since := "2025-08-31")] alias intCast_re := re_intCast
@[simp]
theorem im_intCast (n : ℤ) : (n : ℤ√d).im = 0 := by cases n <;> rfl
@[deprecated (since := "2025-08-31")] alias intCast_im := im_intCast
theorem intCast_val (n : ℤ) : (n : ℤ√d) = ⟨n, 0⟩ := by ext <;> simp
instance : CharZero (ℤ√d) where cast_injective m n := by simp [Zsqrtd.ext_iff]
@[simp]
theorem ofInt_eq_intCast (n : ℤ) : (ofInt n : ℤ√d) = n := by ext <;> simp [re_ofInt, im_ofInt]
@[simp]
theorem nsmul_val (n : ℕ) (x y : ℤ) : (n : ℤ√d) * ⟨x, y⟩ = ⟨n * x, n * y⟩ := by ext <;> simp
@[simp]
theorem smul_val (n x y : ℤ) : (n : ℤ√d) * ⟨x, y⟩ = ⟨n * x, n * y⟩ := by ext <;> simp
theorem re_smul (a : ℤ) (b : ℤ√d) : (↑a * b).re = a * b.re := by simp
@[deprecated (since := "2025-08-31")] alias smul_re := re_smul
theorem im_smul (a : ℤ) (b : ℤ√d) : (↑a * b).im = a * b.im := by simp
@[deprecated (since := "2025-08-31")] alias smul_im := im_smul
@[simp]
theorem muld_val (x y : ℤ) : sqrtd (d := d) * ⟨x, y⟩ = ⟨d * y, x⟩ := by ext <;> simp
@[simp]
theorem dmuld : sqrtd (d := d) * sqrtd (d := d) = d := by ext <;> simp
@[simp]
theorem smuld_val (n x y : ℤ) : sqrtd * (n : ℤ√d) * ⟨x, y⟩ = ⟨d * n * y, n * x⟩ := by ext <;> simp
theorem decompose {x y : ℤ} : (⟨x, y⟩ : ℤ√d) = x + sqrtd (d := d) * y := by ext <;> simp
theorem mul_star {x y : ℤ} : (⟨x, y⟩ * star ⟨x, y⟩ : ℤ√d) = x * x - d * y * y := by
ext <;> simp [sub_eq_add_neg, mul_comm]
theorem intCast_dvd (z : ℤ) (a : ℤ√d) : ↑z ∣ a ↔ z ∣ a.re ∧ z ∣ a.im := by
constructor
· rintro ⟨x, rfl⟩
simp only [add_zero, re_intCast, zero_mul, im_mul, dvd_mul_right, and_self_iff,
re_mul, mul_zero, im_intCast]
· rintro ⟨⟨r, hr⟩, ⟨i, hi⟩⟩
use ⟨r, i⟩
rw [smul_val, Zsqrtd.ext_iff]
exact ⟨hr, hi⟩
@[simp, norm_cast]
theorem intCast_dvd_intCast (a b : ℤ) : (a : ℤ√d) ∣ b ↔ a ∣ b := by
rw [intCast_dvd]
constructor
· rintro ⟨hre, -⟩
rwa [re_intCast] at hre
· rw [re_intCast, im_intCast]
exact fun hc => ⟨hc, dvd_zero a⟩
protected theorem eq_of_smul_eq_smul_left {a : ℤ} {b c : ℤ√d} (ha : a ≠ 0) (h : ↑a * b = a * c) :
b = c := by
rw [Zsqrtd.ext_iff] at h ⊢
apply And.imp _ _ h <;> simpa only [re_smul, im_smul] using mul_left_cancel₀ ha
section Gcd
theorem gcd_eq_zero_iff (a : ℤ√d) : Int.gcd a.re a.im = 0 ↔ a = 0 := by
simp only [Int.gcd_eq_zero_iff, Zsqrtd.ext_iff, im_zero, re_zero]
theorem gcd_pos_iff (a : ℤ√d) : 0 < Int.gcd a.re a.im ↔ a ≠ 0 :=
pos_iff_ne_zero.trans <| not_congr a.gcd_eq_zero_iff
theorem isCoprime_of_dvd_isCoprime {a b : ℤ√d} (hcoprime : IsCoprime a.re a.im) (hdvd : b ∣ a) :
IsCoprime b.re b.im := by
apply isCoprime_of_dvd
· rintro ⟨hre, him⟩
obtain rfl : b = 0 := Zsqrtd.ext hre him
rw [zero_dvd_iff] at hdvd
simp [hdvd, im_zero, re_zero, not_isCoprime_zero_zero] at hcoprime
· rintro z hz - hzdvdu hzdvdv
apply hz
obtain ⟨ha, hb⟩ : z ∣ a.re ∧ z ∣ a.im := by
rw [← intCast_dvd]
apply dvd_trans _ hdvd
rw [intCast_dvd]
exact ⟨hzdvdu, hzdvdv⟩
exact hcoprime.isUnit_of_dvd' ha hb
theorem exists_coprime_of_gcd_pos {a : ℤ√d} (hgcd : 0 < Int.gcd a.re a.im) :
∃ b : ℤ√d, a = ((Int.gcd a.re a.im : ℤ) : ℤ√d) * b ∧ IsCoprime b.re b.im := by
obtain ⟨re, im, H1, Hre, Him⟩ := Int.exists_gcd_one hgcd
rw [mul_comm] at Hre Him
refine ⟨⟨re, im⟩, ?_, ?_⟩
· rw [smul_val, ← Hre, ← Him]
· rw [Int.isCoprime_iff_gcd_eq_one, H1]
end Gcd
/-- Read `SqLe a c b d` as `a √c ≤ b √d` -/
def SqLe (a c b d : ℕ) : Prop :=
c * a * a ≤ d * b * b
theorem sqLe_of_le {c d x y z w : ℕ} (xz : z ≤ x) (yw : y ≤ w) (xy : SqLe x c y d) :
SqLe z c w d := calc
c * z * z ≤ c * x * x := by gcongr
_ ≤ d * y * y := xy
_ ≤ d * w * w := by gcongr
theorem sqLe_add_mixed {c d x y z w : ℕ} (xy : SqLe x c y d) (zw : SqLe z c w d) :
c * (x * z) ≤ d * (y * w) :=
Nat.mul_self_le_mul_self_iff.1 <| by
simpa [mul_comm, mul_left_comm] using Nat.mul_le_mul xy zw
theorem sqLe_add {c d x y z w : ℕ} (xy : SqLe x c y d) (zw : SqLe z c w d) :
SqLe (x + z) c (y + w) d := by
have xz := sqLe_add_mixed xy zw
simp only [SqLe, mul_assoc] at xy zw
simp [SqLe, mul_add, mul_comm, mul_left_comm, add_le_add, *]
theorem sqLe_cancel {c d x y z w : ℕ} (zw : SqLe y d x c) (h : SqLe (x + z) c (y + w) d) :
SqLe z c w d := by
apply le_of_not_gt
intro l
refine not_le_of_gt ?_ h
simp only [mul_add, mul_comm, mul_left_comm, add_assoc]
have hm := sqLe_add_mixed zw (le_of_lt l)
simp only [SqLe, mul_assoc] at l zw
grw [zw, hm]
gcongr
theorem sqLe_smul {c d x y : ℕ} (n : ℕ) (xy : SqLe x c y d) : SqLe (n * x) c (n * y) d := by
simpa [SqLe, mul_left_comm, mul_assoc] using Nat.mul_le_mul_left (n * n) xy
theorem sqLe_mul {d x y z w : ℕ} :
(SqLe x 1 y d → SqLe z 1 w d → SqLe (x * w + y * z) d (x * z + d * y * w) 1) ∧
(SqLe x 1 y d → SqLe w d z 1 → SqLe (x * z + d * y * w) 1 (x * w + y * z) d) ∧
(SqLe y d x 1 → SqLe z 1 w d → SqLe (x * z + d * y * w) 1 (x * w + y * z) d) ∧
(SqLe y d x 1 → SqLe w d z 1 → SqLe (x * w + y * z) d (x * z + d * y * w) 1) := by
refine ⟨?_, ?_, ?_, ?_⟩ <;>
· intro xy zw
have :=
Int.mul_nonneg (sub_nonneg_of_le (Int.ofNat_le_ofNat_of_le xy))
(sub_nonneg_of_le (Int.ofNat_le_ofNat_of_le zw))
refine Int.le_of_ofNat_le_ofNat (le_of_sub_nonneg ?_)
convert this using 1
simp only [one_mul, Int.natCast_add, Int.natCast_mul]
ring
open Int in
/-- "Generalized" `nonneg`. `nonnegg c d x y` means `a √c + b √d ≥ 0`;
we are interested in the case `c = 1` but this is more symmetric -/
def Nonnegg (c d : ℕ) : ℤ → ℤ → Prop
| (a : ℕ), (b : ℕ) => True
| (a : ℕ), -[b+1] => SqLe (b + 1) c a d
| -[a+1], (b : ℕ) => SqLe (a + 1) d b c
| -[_+1], -[_+1] => False
theorem nonnegg_comm {c d : ℕ} {x y : ℤ} : Nonnegg c d x y = Nonnegg d c y x := by
cases x <;> cases y <;> rfl
theorem nonnegg_neg_pos {c d} : ∀ {a b : ℕ}, Nonnegg c d (-a) b ↔ SqLe a d b c
| 0, b => ⟨by simp [SqLe], fun _ => trivial⟩
| a + 1, b => by rfl
theorem nonnegg_pos_neg {c d} {a b : ℕ} : Nonnegg c d a (-b) ↔ SqLe b c a d := by
rw [nonnegg_comm]; exact nonnegg_neg_pos
open Int in
theorem nonnegg_cases_right {c d} {a : ℕ} :
∀ {b : ℤ}, (∀ x : ℕ, b = -x → SqLe x c a d) → Nonnegg c d a b
| (b : Nat), _ => trivial
| -[b+1], h => h (b + 1) rfl
theorem nonnegg_cases_left {c d} {b : ℕ} {a : ℤ} (h : ∀ x : ℕ, a = -x → SqLe x d b c) :
Nonnegg c d a b :=
cast nonnegg_comm (nonnegg_cases_right h)
section Norm
/-- The norm of an element of `ℤ[√d]`. -/
def norm (n : ℤ√d) : ℤ :=
n.re * n.re - d * n.im * n.im
theorem norm_def (n : ℤ√d) : n.norm = n.re * n.re - d * n.im * n.im :=
rfl
@[simp]
theorem norm_zero : norm (0 : ℤ√d) = 0 := by simp [norm]
@[simp]
theorem norm_one : norm (1 : ℤ√d) = 1 := by simp [norm]
@[simp]
theorem norm_intCast (n : ℤ) : norm (n : ℤ√d) = n * n := by simp [norm]
@[simp]
theorem norm_natCast (n : ℕ) : norm (n : ℤ√d) = n * n :=
norm_intCast n
@[simp]
theorem norm_mul (n m : ℤ√d) : norm (n * m) = norm n * norm m := by
simp only [norm, im_mul, re_mul]
ring
/-- `norm` as a `MonoidHom`. -/
def normMonoidHom : ℤ√d →* ℤ where
toFun := norm
map_mul' := norm_mul
map_one' := norm_one
theorem norm_eq_mul_conj (n : ℤ√d) : (norm n : ℤ√d) = n * star n := by
ext <;> simp [norm, star, mul_comm, sub_eq_add_neg]
@[simp]
theorem norm_neg (x : ℤ√d) : (-x).norm = x.norm :=
(Int.cast_inj (α := ℤ√d)).1 <| by simp [norm_eq_mul_conj]
@[simp]
theorem norm_conj (x : ℤ√d) : (star x).norm = x.norm :=
(Int.cast_inj (α := ℤ√d)).1 <| by simp [norm_eq_mul_conj, mul_comm]
theorem norm_nonneg (hd : d ≤ 0) (n : ℤ√d) : 0 ≤ n.norm :=
add_nonneg (mul_self_nonneg _)
(by
rw [mul_assoc, neg_mul_eq_neg_mul]
exact mul_nonneg (neg_nonneg.2 hd) (mul_self_nonneg _))
@[simp]
theorem abs_norm (hd : d ≤ 0) (n : ℤ√d) : |n.norm| = n.norm :=
abs_of_nonneg <| norm_nonneg hd n
theorem norm_eq_one_iff {x : ℤ√d} : x.norm.natAbs = 1 ↔ IsUnit x :=
⟨fun h =>
isUnit_iff_dvd_one.2 <|
(le_total 0 (norm x)).casesOn
(fun hx =>
⟨star x, by
rwa [← Int.natCast_inj, Int.natAbs_of_nonneg hx, ← @Int.cast_inj (ℤ√d) _ _,
norm_eq_mul_conj, eq_comm] at h⟩)
fun hx =>
⟨-star x, by
rwa [← Int.natCast_inj, Int.ofNat_natAbs_of_nonpos hx, ← @Int.cast_inj (ℤ√d) _ _,
Int.cast_neg, norm_eq_mul_conj, neg_mul_eq_mul_neg, eq_comm] at h⟩,
fun h => by
let ⟨y, hy⟩ := isUnit_iff_dvd_one.1 h
have := congr_arg (Int.natAbs ∘ norm) hy
rw [Function.comp_apply, Function.comp_apply, norm_mul, Int.natAbs_mul, norm_one,
Int.natAbs_one, eq_comm, mul_eq_one] at this
exact this.1⟩
theorem isUnit_iff_norm_isUnit {d : ℤ} (z : ℤ√d) : IsUnit z ↔ IsUnit z.norm := by
rw [Int.isUnit_iff_natAbs_eq, norm_eq_one_iff]
theorem norm_eq_one_iff' {d : ℤ} (hd : d ≤ 0) (z : ℤ√d) : z.norm = 1 ↔ IsUnit z := by
rw [← norm_eq_one_iff, ← Int.natCast_inj, Int.natAbs_of_nonneg (norm_nonneg hd z), Int.ofNat_one]
theorem norm_eq_zero_iff {d : ℤ} (hd : d < 0) (z : ℤ√d) : z.norm = 0 ↔ z = 0 := by
constructor
· intro h
rw [norm_def, sub_eq_add_neg, mul_assoc] at h
have left := mul_self_nonneg z.re
have right := neg_nonneg.mpr (mul_nonpos_of_nonpos_of_nonneg hd.le (mul_self_nonneg z.im))
obtain ⟨ha, hb⟩ := (add_eq_zero_iff_of_nonneg left right).mp h
ext <;> apply eq_zero_of_mul_self_eq_zero
· exact ha
· rw [neg_eq_zero, mul_eq_zero] at hb
exact hb.resolve_left hd.ne
· rintro rfl
exact norm_zero
theorem norm_eq_of_associated {d : ℤ} (hd : d ≤ 0) {x y : ℤ√d} (h : Associated x y) :
x.norm = y.norm := by
obtain ⟨u, rfl⟩ := h
rw [norm_mul, (norm_eq_one_iff' hd _).mpr u.isUnit, mul_one]
end Norm
end
section
variable {d : ℕ}
/-- Nonnegativity of an element of `ℤ√d`. -/
def Nonneg : ℤ√d → Prop
| ⟨a, b⟩ => Nonnegg d 1 a b
instance : LE (ℤ√d) :=
⟨fun a b => Nonneg (b - a)⟩
instance : LT (ℤ√d) :=
⟨fun a b => ¬b ≤ a⟩
instance decidableNonnegg (c d a b) : Decidable (Nonnegg c d a b) := by
cases a <;> cases b <;> unfold Nonnegg SqLe <;> infer_instance
instance decidableNonneg : ∀ a : ℤ√d, Decidable (Nonneg a)
| ⟨_, _⟩ => Zsqrtd.decidableNonnegg _ _ _ _
instance decidableLE : DecidableLE (ℤ√d) := fun _ _ => decidableNonneg _
open Int in
theorem nonneg_cases : ∀ {a : ℤ√d}, Nonneg a → ∃ x y : ℕ, a = ⟨x, y⟩ ∨ a = ⟨x, -y⟩ ∨ a = ⟨-x, y⟩
| ⟨(x : ℕ), (y : ℕ)⟩, _ => ⟨x, y, Or.inl rfl⟩
| ⟨(x : ℕ), -[y+1]⟩, _ => ⟨x, y + 1, Or.inr <| Or.inl rfl⟩
| ⟨-[x+1], (y : ℕ)⟩, _ => ⟨x + 1, y, Or.inr <| Or.inr rfl⟩
| ⟨-[_+1], -[_+1]⟩, h => False.elim h
open Int in
theorem nonneg_add_lem {x y z w : ℕ} (xy : Nonneg (⟨x, -y⟩ : ℤ√d)) (zw : Nonneg (⟨-z, w⟩ : ℤ√d)) :
Nonneg (⟨x, -y⟩ + ⟨-z, w⟩ : ℤ√d) := by
have : Nonneg ⟨Int.subNatNat x z, Int.subNatNat w y⟩ :=
Int.subNatNat_elim x z
(fun m n i => SqLe y d m 1 → SqLe n 1 w d → Nonneg ⟨i, Int.subNatNat w y⟩)
(fun j k =>
Int.subNatNat_elim w y
(fun m n i => SqLe n d (k + j) 1 → SqLe k 1 m d → Nonneg ⟨Int.ofNat j, i⟩)
(fun _ _ _ _ => trivial) fun m n xy zw => sqLe_cancel zw xy)
(fun j k =>
Int.subNatNat_elim w y
(fun m n i => SqLe n d k 1 → SqLe (k + j + 1) 1 m d → Nonneg ⟨-[j+1], i⟩)
(fun m n xy zw => sqLe_cancel xy zw) fun m n xy zw =>
let t := Nat.le_trans zw (sqLe_of_le (Nat.le_add_right n (m + 1)) le_rfl xy)
have : k + j + 1 ≤ k :=
Nat.mul_self_le_mul_self_iff.1 (by simpa [one_mul] using t)
absurd this (not_le_of_gt <| Nat.succ_le_succ <| Nat.le_add_right _ _))
(nonnegg_pos_neg.1 xy) (nonnegg_neg_pos.1 zw)
rw [add_def, neg_add_eq_sub]
rwa [Int.subNatNat_eq_coe, Int.subNatNat_eq_coe] at this
theorem Nonneg.add {a b : ℤ√d} (ha : Nonneg a) (hb : Nonneg b) : Nonneg (a + b) := by
rcases nonneg_cases ha with ⟨x, y, rfl | rfl | rfl⟩ <;>
rcases nonneg_cases hb with ⟨z, w, rfl | rfl | rfl⟩
· trivial
· refine nonnegg_cases_right fun i h => sqLe_of_le ?_ ?_ (nonnegg_pos_neg.1 hb)
· dsimp only at h
exact Int.ofNat_le.1 (le_of_neg_le_neg (Int.le.intro y (by simp [add_comm, *])))
· apply Nat.le_add_left
· refine nonnegg_cases_left fun i h => sqLe_of_le ?_ ?_ (nonnegg_neg_pos.1 hb)
· dsimp only at h
exact Int.ofNat_le.1 (le_of_neg_le_neg (Int.le.intro x (by simp [add_comm, *])))
· apply Nat.le_add_left
· refine nonnegg_cases_right fun i h => sqLe_of_le ?_ ?_ (nonnegg_pos_neg.1 ha)
· dsimp only at h
exact Int.ofNat_le.1 (le_of_neg_le_neg (Int.le.intro w (by simp [*])))
· apply Nat.le_add_right
· have : Nonneg ⟨_, _⟩ :=
nonnegg_pos_neg.2 (sqLe_add (nonnegg_pos_neg.1 ha) (nonnegg_pos_neg.1 hb))
rw [Nat.cast_add, Nat.cast_add, neg_add] at this
rwa [add_def]
· exact nonneg_add_lem ha hb
· refine nonnegg_cases_left fun i h => sqLe_of_le ?_ ?_ (nonnegg_neg_pos.1 ha)
· dsimp only at h
exact Int.ofNat_le.1 (le_of_neg_le_neg (Int.le.intro _ h))
· apply Nat.le_add_right
· dsimp
rw [add_comm, add_comm (y : ℤ)]
exact nonneg_add_lem hb ha
· have : Nonneg ⟨_, _⟩ :=
nonnegg_neg_pos.2 (sqLe_add (nonnegg_neg_pos.1 ha) (nonnegg_neg_pos.1 hb))
rw [Nat.cast_add, Nat.cast_add, neg_add] at this
rwa [add_def]
theorem nonneg_iff_zero_le {a : ℤ√d} : Nonneg a ↔ 0 ≤ a :=
show _ ↔ Nonneg _ by simp
theorem le_of_le_le {x y z w : ℤ} (xz : x ≤ z) (yw : y ≤ w) : (⟨x, y⟩ : ℤ√d) ≤ ⟨z, w⟩ :=
show Nonneg ⟨z - x, w - y⟩ from
match z - x, w - y, Int.le.dest_sub xz, Int.le.dest_sub yw with
| _, _, ⟨_, rfl⟩, ⟨_, rfl⟩ => trivial
open Int in
protected theorem nonneg_total : ∀ a : ℤ√d, Nonneg a ∨ Nonneg (-a)
| ⟨(x : ℕ), (y : ℕ)⟩ => Or.inl trivial
| ⟨-[_+1], -[_+1]⟩ => Or.inr trivial
| ⟨0, -[_+1]⟩ => Or.inr trivial
| ⟨-[_+1], 0⟩ => Or.inr trivial
| ⟨(_ + 1 : ℕ), -[_+1]⟩ => Nat.le_total _ _
| ⟨-[_+1], (_ + 1 : ℕ)⟩ => Nat.le_total _ _
protected theorem le_total (a b : ℤ√d) : a ≤ b ∨ b ≤ a := by
have t := (b - a).nonneg_total
rwa [neg_sub] at t
instance preorder : Preorder (ℤ√d) where
le_refl a := show Nonneg (a - a) by simp only [sub_self]; trivial
le_trans a b c hab hbc := by simpa [sub_add_sub_cancel'] using hab.add hbc
lt_iff_le_not_ge _ _ := (and_iff_right_of_imp (Zsqrtd.le_total _ _).resolve_left).symm
open Int in
theorem le_arch (a : ℤ√d) : ∃ n : ℕ, a ≤ n := by
obtain ⟨x, y, (h : a ≤ ⟨x, y⟩)⟩ : ∃ x y : ℕ, Nonneg (⟨x, y⟩ + -a) :=
match -a with
| ⟨Int.ofNat x, Int.ofNat y⟩ => ⟨0, 0, by trivial⟩
| ⟨Int.ofNat x, -[y+1]⟩ => ⟨0, y + 1, by simp [add_def, Int.negSucc_eq, add_assoc]; trivial⟩
| ⟨-[x+1], Int.ofNat y⟩ => ⟨x + 1, 0, by simp [Int.negSucc_eq, add_assoc]; trivial⟩
| ⟨-[x+1], -[y+1]⟩ => ⟨x + 1, y + 1, by simp [Int.negSucc_eq, add_assoc]; trivial⟩
refine ⟨x + d * y, h.trans ?_⟩
change Nonneg ⟨↑x + d * y - ↑x, 0 - ↑y⟩
rcases y with - | y
· simp
trivial
have h : ∀ y, SqLe y d (d * y) 1 := fun y => by
simpa [SqLe, mul_comm, mul_left_comm] using Nat.mul_le_mul_right (y * y) (Nat.le_mul_self d)
rw [show (x : ℤ) + d * Nat.succ y - x = d * Nat.succ y by simp]
exact h (y + 1)
protected theorem add_le_add_left (a b : ℤ√d) (ab : a ≤ b) (c : ℤ√d) : c + a ≤ c + b :=
show Nonneg _ by rw [add_sub_add_left_eq_sub]; exact ab
protected theorem le_of_add_le_add_left (a b c : ℤ√d) (h : c + a ≤ c + b) : a ≤ b := by
simpa using Zsqrtd.add_le_add_left _ _ h (-c)
protected theorem add_lt_add_left (a b : ℤ√d) (h : a < b) (c) : c + a < c + b := fun h' =>
h (Zsqrtd.le_of_add_le_add_left _ _ _ h')
theorem nonneg_smul {a : ℤ√d} {n : ℕ} (ha : Nonneg a) : Nonneg ((n : ℤ√d) * a) := by
rw [← Int.cast_natCast n]
exact
match a, nonneg_cases ha, ha with
| _, ⟨x, y, Or.inl rfl⟩, _ => by rw [smul_val]; trivial
| _, ⟨x, y, Or.inr <| Or.inl rfl⟩, ha => by
rw [smul_val]; simpa using nonnegg_pos_neg.2 (sqLe_smul n <| nonnegg_pos_neg.1 ha)
| _, ⟨x, y, Or.inr <| Or.inr rfl⟩, ha => by
rw [smul_val]; simpa using nonnegg_neg_pos.2 (sqLe_smul n <| nonnegg_neg_pos.1 ha)
theorem nonneg_muld {a : ℤ√d} (ha : Nonneg a) : Nonneg (sqrtd * a) :=
match a, nonneg_cases ha, ha with
| _, ⟨_, _, Or.inl rfl⟩, _ => trivial
| _, ⟨x, y, Or.inr <| Or.inl rfl⟩, ha => by
simp only [muld_val, mul_neg]
apply nonnegg_neg_pos.2
simpa [SqLe, mul_comm, mul_left_comm] using Nat.mul_le_mul_left d (nonnegg_pos_neg.1 ha)
| _, ⟨x, y, Or.inr <| Or.inr rfl⟩, ha => by
simp only [muld_val]
apply nonnegg_pos_neg.2
simpa [SqLe, mul_comm, mul_left_comm] using Nat.mul_le_mul_left d (nonnegg_neg_pos.1 ha)
theorem nonneg_mul_lem {x y : ℕ} {a : ℤ√d} (ha : Nonneg a) : Nonneg (⟨x, y⟩ * a) := by
have : (⟨x, y⟩ * a : ℤ√d) = (x : ℤ√d) * a + sqrtd * ((y : ℤ√d) * a) := by
rw [decompose, right_distrib, mul_assoc, Int.cast_natCast, Int.cast_natCast]
rw [this]
exact (nonneg_smul ha).add (nonneg_muld <| nonneg_smul ha)
theorem nonneg_mul {a b : ℤ√d} (ha : Nonneg a) (hb : Nonneg b) : Nonneg (a * b) :=
match a, b, nonneg_cases ha, nonneg_cases hb, ha, hb with
| _, _, ⟨_, _, Or.inl rfl⟩, ⟨_, _, Or.inl rfl⟩, _, _ => trivial
| _, _, ⟨x, y, Or.inl rfl⟩, ⟨z, w, Or.inr <| Or.inr rfl⟩, _, hb => nonneg_mul_lem hb
| _, _, ⟨x, y, Or.inl rfl⟩, ⟨z, w, Or.inr <| Or.inl rfl⟩, _, hb => nonneg_mul_lem hb
| _, _, ⟨x, y, Or.inr <| Or.inr rfl⟩, ⟨z, w, Or.inl rfl⟩, ha, _ => by
rw [mul_comm]; exact nonneg_mul_lem ha
| _, _, ⟨x, y, Or.inr <| Or.inl rfl⟩, ⟨z, w, Or.inl rfl⟩, ha, _ => by
rw [mul_comm]; exact nonneg_mul_lem ha
| _, _, ⟨x, y, Or.inr <| Or.inr rfl⟩, ⟨z, w, Or.inr <| Or.inr rfl⟩, ha, hb => by
rw [calc
(⟨-x, y⟩ * ⟨-z, w⟩ : ℤ√d) = ⟨_, _⟩ := rfl
_ = ⟨x * z + d * y * w, -(x * w + y * z)⟩ := by simp [add_comm]]
exact nonnegg_pos_neg.2 (sqLe_mul.left (nonnegg_neg_pos.1 ha) (nonnegg_neg_pos.1 hb))
| _, _, ⟨x, y, Or.inr <| Or.inr rfl⟩, ⟨z, w, Or.inr <| Or.inl rfl⟩, ha, hb => by
rw [calc
(⟨-x, y⟩ * ⟨z, -w⟩ : ℤ√d) = ⟨_, _⟩ := rfl
_ = ⟨-(x * z + d * y * w), x * w + y * z⟩ := by simp [add_comm]]
exact nonnegg_neg_pos.2 (sqLe_mul.right.left (nonnegg_neg_pos.1 ha) (nonnegg_pos_neg.1 hb))
| _, _, ⟨x, y, Or.inr <| Or.inl rfl⟩, ⟨z, w, Or.inr <| Or.inr rfl⟩, ha, hb => by
rw [calc
(⟨x, -y⟩ * ⟨-z, w⟩ : ℤ√d) = ⟨_, _⟩ := rfl
_ = ⟨-(x * z + d * y * w), x * w + y * z⟩ := by simp [add_comm]]
exact
nonnegg_neg_pos.2 (sqLe_mul.right.right.left (nonnegg_pos_neg.1 ha) (nonnegg_neg_pos.1 hb))
| _, _, ⟨x, y, Or.inr <| Or.inl rfl⟩, ⟨z, w, Or.inr <| Or.inl rfl⟩, ha, hb => by
rw [calc
(⟨x, -y⟩ * ⟨z, -w⟩ : ℤ√d) = ⟨_, _⟩ := rfl
_ = ⟨x * z + d * y * w, -(x * w + y * z)⟩ := by simp [add_comm]]
exact
nonnegg_pos_neg.2
(sqLe_mul.right.right.right (nonnegg_pos_neg.1 ha) (nonnegg_pos_neg.1 hb))
protected theorem mul_nonneg (a b : ℤ√d) : 0 ≤ a → 0 ≤ b → 0 ≤ a * b := by
simp_rw [← nonneg_iff_zero_le]
exact nonneg_mul
theorem not_sqLe_succ (c d y) (h : 0 < c) : ¬SqLe (y + 1) c 0 d :=
not_le_of_gt <| mul_pos (mul_pos h <| Nat.succ_pos _) <| Nat.succ_pos _
/-- A nonsquare is a natural number that is not equal to the square of an
integer. This is implemented as a typeclass because it's a necessary condition
for much of the Pell equation theory. -/
class Nonsquare (x : ℕ) : Prop where
ns (x) : ∀ n : ℕ, x ≠ n * n
@[deprecated (since := "2025-08-28")] alias Nonsquare.ns' := Nonsquare.ns
variable [dnsq : Nonsquare d]
theorem d_pos : 0 < d :=
lt_of_le_of_ne (Nat.zero_le _) <| Ne.symm <| Nonsquare.ns d 0
theorem divides_sq_eq_zero {x y} (h : x * x = d * y * y) : x = 0 ∧ y = 0 :=
let g := x.gcd y
Or.elim g.eq_zero_or_pos
(fun H => ⟨Nat.eq_zero_of_gcd_eq_zero_left H, Nat.eq_zero_of_gcd_eq_zero_right H⟩) fun gpos =>
False.elim <| by
let ⟨m, n, co, (hx : x = m * g), (hy : y = n * g)⟩ := Nat.exists_coprime _ _
rw [hx, hy] at h
have : m * m = d * (n * n) := by
refine mul_left_cancel₀ (mul_pos gpos gpos).ne' ?_
simpa [mul_comm, mul_left_comm, mul_assoc] using h
have co2 :=
let co1 := co.mul_right co
co1.mul_left co1
exact
Nonsquare.ns d m
(Nat.dvd_antisymm (by rw [this]; apply dvd_mul_right) <|
co2.dvd_of_dvd_mul_right <| by simp [this])
theorem divides_sq_eq_zero_z {x y : ℤ} (h : x * x = d * y * y) : x = 0 ∧ y = 0 := by
rw [mul_assoc, ← Int.natAbs_mul_self, ← Int.natAbs_mul_self, ← Int.natCast_mul, ← mul_assoc] at h
exact
let ⟨h1, h2⟩ := divides_sq_eq_zero (Int.ofNat.inj h)
⟨Int.natAbs_eq_zero.mp h1, Int.natAbs_eq_zero.mp h2⟩
theorem not_divides_sq (x y) : (x + 1) * (x + 1) ≠ d * (y + 1) * (y + 1) := fun e => by
have t := (divides_sq_eq_zero e).left
contradiction
open Int in
theorem nonneg_antisymm : ∀ {a : ℤ√d}, Nonneg a → Nonneg (-a) → a = 0
| ⟨0, 0⟩, _, _ => rfl
| ⟨-[_+1], -[_+1]⟩, xy, _ => False.elim xy
| ⟨(_ + 1 : Nat), (_ + 1 : Nat)⟩, _, yx => False.elim yx
| ⟨-[_+1], 0⟩, xy, _ => absurd xy (not_sqLe_succ _ _ _ (by decide))
| ⟨(_ + 1 : Nat), 0⟩, _, yx => absurd yx (not_sqLe_succ _ _ _ (by decide))
| ⟨0, -[_+1]⟩, xy, _ => absurd xy (not_sqLe_succ _ _ _ d_pos)
| ⟨0, (_ + 1 : Nat)⟩, _, yx => absurd yx (not_sqLe_succ _ _ _ d_pos)
| ⟨(x + 1 : Nat), -[y+1]⟩, (xy : SqLe _ _ _ _), (yx : SqLe _ _ _ _) => by
let t := le_antisymm yx xy
rw [one_mul] at t
exact absurd t (not_divides_sq _ _)
| ⟨-[x+1], (y + 1 : Nat)⟩, (xy : SqLe _ _ _ _), (yx : SqLe _ _ _ _) => by
let t := le_antisymm xy yx
rw [one_mul] at t
exact absurd t (not_divides_sq _ _)
theorem le_antisymm {a b : ℤ√d} (ab : a ≤ b) (ba : b ≤ a) : a = b :=
eq_of_sub_eq_zero <| nonneg_antisymm ba (by rwa [neg_sub])
instance linearOrder : LinearOrder (ℤ√d) :=
{ Zsqrtd.preorder with
le_antisymm := fun _ _ => Zsqrtd.le_antisymm
le_total := Zsqrtd.le_total
toDecidableLE := Zsqrtd.decidableLE
toDecidableEq := inferInstance }
protected theorem eq_zero_or_eq_zero_of_mul_eq_zero : ∀ {a b : ℤ√d}, a * b = 0 → a = 0 ∨ b = 0
| ⟨x, y⟩, ⟨z, w⟩, h => by
injection h with h1 h2
have h1 : x * z = -(d * y * w) := eq_neg_of_add_eq_zero_left h1
have h2 : x * w = -(y * z) := eq_neg_of_add_eq_zero_left h2
have fin : x * x = d * y * y → (⟨x, y⟩ : ℤ√d) = 0 := fun e =>
match x, y, divides_sq_eq_zero_z e with
| _, _, ⟨rfl, rfl⟩ => rfl
exact
if z0 : z = 0 then
if w0 : w = 0 then
Or.inr
(match z, w, z0, w0 with
| _, _, rfl, rfl => rfl)
else
Or.inl <|
fin <|
mul_right_cancel₀ w0 <|
calc
x * x * w = -y * (x * z) := by simp [h2, mul_assoc, mul_left_comm]
_ = d * y * y * w := by simp [h1, mul_assoc, mul_left_comm]
else
Or.inl <|
fin <|
mul_right_cancel₀ z0 <|
calc
x * x * z = d * -y * (x * w) := by simp [h1, mul_assoc, mul_left_comm]
_ = d * y * y * z := by simp [h2, mul_assoc, mul_left_comm]
instance : NoZeroDivisors (ℤ√d) where
eq_zero_or_eq_zero_of_mul_eq_zero := Zsqrtd.eq_zero_or_eq_zero_of_mul_eq_zero
instance : IsDomain (ℤ√d) :=
NoZeroDivisors.to_isDomain _
protected theorem mul_pos (a b : ℤ√d) (a0 : 0 < a) (b0 : 0 < b) : 0 < a * b := fun ab =>
Or.elim
(eq_zero_or_eq_zero_of_mul_eq_zero
(le_antisymm ab (Zsqrtd.mul_nonneg _ _ (le_of_lt a0) (le_of_lt b0))))
(fun e => ne_of_gt a0 e) fun e => ne_of_gt b0 e
instance : ZeroLEOneClass (ℤ√d) :=
{ zero_le_one := by trivial }
instance : IsOrderedAddMonoid (ℤ√d) :=
{ add_le_add_left := Zsqrtd.add_le_add_left }
instance : IsStrictOrderedRing (ℤ√d) :=
.of_mul_pos Zsqrtd.mul_pos
end
theorem norm_eq_zero {d : ℤ} (h_nonsquare : ∀ n : ℤ, d ≠ n * n) (a : ℤ√d) : norm a = 0 ↔ a = 0 := by
refine ⟨fun ha => Zsqrtd.ext_iff.mpr ?_, fun h => by rw [h, norm_zero]⟩
dsimp only [norm] at ha
rw [sub_eq_zero] at ha
by_cases! h : 0 ≤ d
· obtain ⟨d', rfl⟩ := Int.eq_ofNat_of_zero_le h
haveI : Nonsquare d' := ⟨fun n h => h_nonsquare n <| mod_cast h⟩
exact divides_sq_eq_zero_z ha
· suffices a.re * a.re = 0 by
rw [eq_zero_of_mul_self_eq_zero this] at ha ⊢
simpa only [true_and, or_self_right, re_zero, im_zero, eq_self_iff_true, zero_eq_mul,
mul_zero, mul_eq_zero, h.ne, false_or, or_self_iff] using ha
apply _root_.le_antisymm _ (mul_self_nonneg _)
rw [ha, mul_assoc]
exact mul_nonpos_of_nonpos_of_nonneg h.le (mul_self_nonneg _)
variable {R : Type}
@[ext]
theorem hom_ext [NonAssocRing R] {d : ℤ} (f g : ℤ√d →+* R) (h : f sqrtd = g sqrtd) : f = g := by
ext ⟨re_x, im_x⟩
simp [decompose, h]
variable [CommRing R]
/-- The unique `RingHom` from `ℤ√d` to a ring `R`, constructed by replacing `√d` with the provided
root. Conversely, this associates to every mapping `ℤ√d →+* R` a value of `√d` in `R`. -/
@[simps]
def lift {d : ℤ} : { r : R // r * r = ↑d } ≃ (ℤ√d →+* R) where
toFun r :=
{ toFun := fun a => a.1 + a.2 * (r : R)
map_zero' := by simp
map_add' := fun a b => by
simp only [re_add, Int.cast_add, im_add]
ring
map_one' := by simp
map_mul' := fun a b => by
have :
(a.re + a.im * r : R) * (b.re + b.im * r) =
a.re * b.re + (a.re * b.im + a.im * b.re) * r + a.im * b.im * (r * r) := by
ring
simp only [re_mul, Int.cast_add, Int.cast_mul, im_mul, this, r.prop]
ring }
invFun f := ⟨f sqrtd, by rw [← f.map_mul, dmuld, map_intCast]⟩
left_inv r := by simp
right_inv f := by
ext
simp
/-- `lift r` is injective if `d` is non-square, and R has characteristic zero (that is, the map from
`ℤ` into `R` is injective). -/
theorem lift_injective [CharZero R] {d : ℤ} (r : { r : R // r * r = ↑d })
(hd : ∀ n : ℤ, d ≠ n * n) : Function.Injective (lift r) :=
(injective_iff_map_eq_zero (lift r)).mpr fun a ha => by
have h_inj : Function.Injective ((↑) : ℤ → R) := Int.cast_injective
suffices lift r a.norm = 0 by
simp only [re_intCast, add_zero, lift_apply_apply, im_intCast, Int.cast_zero,
zero_mul] at this
rwa [← Int.cast_zero, h_inj.eq_iff, norm_eq_zero hd] at this
rw [norm_eq_mul_conj, RingHom.map_mul, ha, zero_mul]
/-- An element of `ℤ√d` has norm equal to `1` if and only if it is contained in the submonoid
of unitary elements. -/
theorem norm_eq_one_iff_mem_unitary {d : ℤ} {a : ℤ√d} : a.norm = 1 ↔ a ∈ unitary (ℤ√d) := by
rw [Unitary.mem_iff_self_mul_star, ← norm_eq_mul_conj]
norm_cast
/-- The kernel of the norm map on `ℤ√d` equals the submonoid of unitary elements. -/
theorem mker_norm_eq_unitary {d : ℤ} : MonoidHom.mker (@normMonoidHom d) = unitary (ℤ√d) :=
Submonoid.ext fun _ => norm_eq_one_iff_mem_unitary
end Zsqrtd |
.lake/packages/mathlib/Mathlib/NumberTheory/Zsqrtd/QuadraticReciprocity.lean | import Mathlib.NumberTheory.Zsqrtd.GaussianInt
import Mathlib.NumberTheory.LegendreSymbol.Basic
/-!
# Facts about the Gaussian integers relying on quadratic reciprocity.
## Main statements
`prime_iff_mod_four_eq_three_of_nat_prime`
A prime natural number is prime in `ℤ[i]` if and only if it is `3` mod `4`
-/
open Zsqrtd Complex
open scoped ComplexConjugate
local notation "ℤ[i]" => GaussianInt
namespace GaussianInt
open PrincipalIdealRing
theorem mod_four_eq_three_of_nat_prime_of_prime (p : ℕ) [hp : Fact p.Prime]
(hpi : Prime (p : ℤ[i])) : p % 4 = 3 :=
hp.1.eq_two_or_odd.elim
(fun hp2 => by
have := hpi.irreducible.isUnit_or_isUnit (a := ⟨1, 1⟩) (b := ⟨1, -1⟩)
simp [hp2, Zsqrtd.ext_iff, ← norm_eq_one_iff, norm_def] at this)
fun hp1 =>
by_contradiction fun hp3 : p % 4 ≠ 3 => by
let ⟨k, hk⟩ := (ZMod.exists_sq_eq_neg_one_iff (p := p)).2 hp3
obtain ⟨k, k_lt_p, rfl⟩ : ∃ (k' : ℕ) (_ : k' < p), (k' : ZMod p) = k := by
exact ⟨k.val, k.val_lt, ZMod.natCast_zmod_val k⟩
have hpk : p ∣ k ^ 2 + 1 := by
rw [pow_two, ← CharP.cast_eq_zero_iff (ZMod p) p, Nat.cast_add, Nat.cast_mul, Nat.cast_one,
← hk, neg_add_cancel]
have hkmul : (k ^ 2 + 1 : ℤ[i]) = ⟨k, 1⟩ * ⟨k, -1⟩ := by ext <;> simp [sq]
have hk₀ : k ≠ 0 := by rintro rfl; simp at hk
have hkltp := calc
1 + k * k ≤ k * (k + 1) := by cutsat
_ < p * p := mul_lt_mul k_lt_p k_lt_p (Nat.succ_pos _) (Nat.zero_le _)
have hpk₁ : ¬(p : ℤ[i]) ∣ ⟨k, -1⟩ := fun ⟨x, hx⟩ =>
lt_irrefl (p * x : ℤ[i]).norm.natAbs <|
calc
(norm (p * x : ℤ[i])).natAbs = (Zsqrtd.norm ⟨k, -1⟩).natAbs := by rw [hx]
_ < (norm (p : ℤ[i])).natAbs := by simpa [add_comm, Zsqrtd.norm] using hkltp
_ ≤ (norm (p * x : ℤ[i])).natAbs :=
norm_le_norm_mul_left _ fun hx0 =>
show (-1 : ℤ) ≠ 0 by decide <| by simpa [hx0] using congr_arg Zsqrtd.im hx
have hpk₂ : ¬(p : ℤ[i]) ∣ ⟨k, 1⟩ := fun ⟨x, hx⟩ =>
lt_irrefl (p * x : ℤ[i]).norm.natAbs <|
calc
(norm (p * x : ℤ[i])).natAbs = (Zsqrtd.norm ⟨k, 1⟩).natAbs := by rw [hx]
_ < (norm (p : ℤ[i])).natAbs := by simpa [add_comm, Zsqrtd.norm] using hkltp
_ ≤ (norm (p * x : ℤ[i])).natAbs :=
norm_le_norm_mul_left _ fun hx0 =>
show (1 : ℤ) ≠ 0 by decide <| by simpa [hx0] using congr_arg Zsqrtd.im hx
obtain ⟨y, hy⟩ := hpk
have := hpi.2.2 ⟨k, 1⟩ ⟨k, -1⟩ ⟨y, by rw [← hkmul, ← Nat.cast_mul p, ← hy]; simp⟩
tauto
theorem prime_of_nat_prime_of_mod_four_eq_three (p : ℕ) [Fact p.Prime] (hp3 : p % 4 = 3) :
Prime (p : ℤ[i]) :=
irreducible_iff_prime.1 <|
by_contradiction fun hpi =>
let ⟨a, b, hab⟩ := sq_add_sq_of_nat_prime_of_not_irreducible p hpi
have : ∀ a b : ZMod 4, a ^ 2 + b ^ 2 ≠ (p : ZMod 4) := by
rw [← ZMod.natCast_mod p 4, hp3]; decide
this a b (hab ▸ by simp)
/-- A prime natural number is prime in `ℤ[i]` if and only if it is `3` mod `4` -/
theorem prime_iff_mod_four_eq_three_of_nat_prime (p : ℕ) [Fact p.Prime] :
Prime (p : ℤ[i]) ↔ p % 4 = 3 :=
⟨mod_four_eq_three_of_nat_prime_of_prime p, prime_of_nat_prime_of_mod_four_eq_three p⟩
end GaussianInt |
.lake/packages/mathlib/Mathlib/NumberTheory/FLT/Four.lean | import Mathlib.Data.Nat.Factors
import Mathlib.NumberTheory.FLT.Basic
import Mathlib.NumberTheory.PythagoreanTriples
import Mathlib.RingTheory.Coprime.Lemmas
import Mathlib.Tactic.LinearCombination
/-!
# Fermat's Last Theorem for the case n = 4
There are no non-zero integers `a`, `b` and `c` such that `a ^ 4 + b ^ 4 = c ^ 4`.
-/
assert_not_exists TwoSidedIdeal
noncomputable section
/-- Shorthand for three non-zero integers `a`, `b`, and `c` satisfying `a ^ 4 + b ^ 4 = c ^ 2`.
We will show that no integers satisfy this equation. Clearly Fermat's Last theorem for n = 4
follows. -/
def Fermat42 (a b c : ℤ) : Prop :=
a ≠ 0 ∧ b ≠ 0 ∧ a ^ 4 + b ^ 4 = c ^ 2
namespace Fermat42
theorem comm {a b c : ℤ} : Fermat42 a b c ↔ Fermat42 b a c := by
delta Fermat42
rw [add_comm]
tauto
theorem mul {a b c k : ℤ} (hk0 : k ≠ 0) :
Fermat42 a b c ↔ Fermat42 (k * a) (k * b) (k ^ 2 * c) := by
delta Fermat42
constructor
· intro f42
constructor
· exact mul_ne_zero hk0 f42.1
constructor
· exact mul_ne_zero hk0 f42.2.1
· have H : a ^ 4 + b ^ 4 = c ^ 2 := f42.2.2
linear_combination k ^ 4 * H
· intro f42
constructor
· exact right_ne_zero_of_mul f42.1
constructor
· exact right_ne_zero_of_mul f42.2.1
apply (mul_right_inj' (pow_ne_zero 4 hk0)).mp
linear_combination f42.2.2
theorem ne_zero {a b c : ℤ} (h : Fermat42 a b c) : c ≠ 0 := by
apply ne_zero_pow two_ne_zero _; apply ne_of_gt
rw [← h.2.2, (by ring : a ^ 4 + b ^ 4 = (a ^ 2) ^ 2 + (b ^ 2) ^ 2)]
exact
add_pos (sq_pos_of_ne_zero (pow_ne_zero 2 h.1)) (sq_pos_of_ne_zero (pow_ne_zero 2 h.2.1))
/-- We say a solution to `a ^ 4 + b ^ 4 = c ^ 2` is minimal if there is no other solution with
a smaller `c` (in absolute value). -/
def Minimal (a b c : ℤ) : Prop :=
Fermat42 a b c ∧ ∀ a1 b1 c1 : ℤ, Fermat42 a1 b1 c1 → Int.natAbs c ≤ Int.natAbs c1
/-- if we have a solution to `a ^ 4 + b ^ 4 = c ^ 2` then there must be a minimal one. -/
theorem exists_minimal {a b c : ℤ} (h : Fermat42 a b c) : ∃ a0 b0 c0, Minimal a0 b0 c0 := by
classical
let S : Set ℕ := { n | ∃ s : ℤ × ℤ × ℤ, Fermat42 s.1 s.2.1 s.2.2 ∧ n = Int.natAbs s.2.2 }
have S_nonempty : S.Nonempty := by
use Int.natAbs c
rw [Set.mem_setOf_eq]
use ⟨a, ⟨b, c⟩⟩
let m : ℕ := Nat.find S_nonempty
have m_mem : m ∈ S := Nat.find_spec S_nonempty
rcases m_mem with ⟨s0, hs0, hs1⟩
use s0.1, s0.2.1, s0.2.2, hs0
intro a1 b1 c1 h1
rw [← hs1]
apply Nat.find_min'
use ⟨a1, ⟨b1, c1⟩⟩
/-- a minimal solution to `a ^ 4 + b ^ 4 = c ^ 2` must have `a` and `b` coprime. -/
theorem coprime_of_minimal {a b c : ℤ} (h : Minimal a b c) : IsCoprime a b := by
apply Int.isCoprime_iff_gcd_eq_one.mpr
by_contra hab
obtain ⟨p, hp, hpa, hpb⟩ := Nat.Prime.not_coprime_iff_dvd.mp hab
obtain ⟨a1, rfl⟩ := Int.natCast_dvd.mpr hpa
obtain ⟨b1, rfl⟩ := Int.natCast_dvd.mpr hpb
have hpc : (p : ℤ) ^ 2 ∣ c := by
rw [← Int.pow_dvd_pow_iff two_ne_zero, ← h.1.2.2]
apply Dvd.intro (a1 ^ 4 + b1 ^ 4)
ring
obtain ⟨c1, rfl⟩ := hpc
have hf : Fermat42 a1 b1 c1 :=
(Fermat42.mul (Int.natCast_ne_zero.mpr (Nat.Prime.ne_zero hp))).mpr h.1
apply Nat.le_lt_asymm (h.2 _ _ _ hf)
rw [Int.natAbs_mul, lt_mul_iff_one_lt_left, Int.natAbs_pow, Int.natAbs_natCast]
· exact Nat.one_lt_pow two_ne_zero (Nat.Prime.one_lt hp)
· exact Nat.pos_of_ne_zero (Int.natAbs_ne_zero.2 (ne_zero hf))
/-- We can swap `a` and `b` in a minimal solution to `a ^ 4 + b ^ 4 = c ^ 2`. -/
theorem minimal_comm {a b c : ℤ} : Minimal a b c → Minimal b a c := fun ⟨h1, h2⟩ =>
⟨Fermat42.comm.mp h1, h2⟩
/-- We can assume that a minimal solution to `a ^ 4 + b ^ 4 = c ^ 2` has positive `c`. -/
theorem neg_of_minimal {a b c : ℤ} : Minimal a b c → Minimal a b (-c) := by
rintro ⟨⟨ha, hb, heq⟩, h2⟩
constructor
· apply And.intro ha (And.intro hb _)
rw [heq]
exact (neg_sq c).symm
rwa [Int.natAbs_neg c]
/-- We can assume that a minimal solution to `a ^ 4 + b ^ 4 = c ^ 2` has `a` odd. -/
theorem exists_odd_minimal {a b c : ℤ} (h : Fermat42 a b c) :
∃ a0 b0 c0, Minimal a0 b0 c0 ∧ a0 % 2 = 1 := by
obtain ⟨a0, b0, c0, hf⟩ := exists_minimal h
rcases Int.emod_two_eq_zero_or_one a0 with hap | hap
· rcases Int.emod_two_eq_zero_or_one b0 with hbp | hbp
· exfalso
have h1 : 2 ∣ (Int.gcd a0 b0 : ℤ) :=
Int.dvd_coe_gcd (Int.dvd_of_emod_eq_zero hap) (Int.dvd_of_emod_eq_zero hbp)
rw [Int.isCoprime_iff_gcd_eq_one.mp (coprime_of_minimal hf)] at h1
revert h1
decide
· exact ⟨b0, ⟨a0, ⟨c0, minimal_comm hf, hbp⟩⟩⟩
exact ⟨a0, ⟨b0, ⟨c0, hf, hap⟩⟩⟩
/-- We can assume that a minimal solution to `a ^ 4 + b ^ 4 = c ^ 2` has
`a` odd and `c` positive. -/
theorem exists_pos_odd_minimal {a b c : ℤ} (h : Fermat42 a b c) :
∃ a0 b0 c0, Minimal a0 b0 c0 ∧ a0 % 2 = 1 ∧ 0 < c0 := by
obtain ⟨a0, b0, c0, hf, hc⟩ := exists_odd_minimal h
rcases lt_trichotomy 0 c0 with (h1 | h1 | h1)
· use a0, b0, c0
· exfalso
exact ne_zero hf.1 h1.symm
· use a0, b0, -c0, neg_of_minimal hf, hc
exact neg_pos.mpr h1
end Fermat42
theorem Int.isCoprime_of_sq_sum {r s : ℤ} (h2 : IsCoprime s r) : IsCoprime (r ^ 2 + s ^ 2) r := by
rw [sq, sq]
exact (IsCoprime.mul_left h2 h2).mul_add_left_left r
theorem Int.isCoprime_of_sq_sum' {r s : ℤ} (h : IsCoprime r s) :
IsCoprime (r ^ 2 + s ^ 2) (r * s) := by
apply IsCoprime.mul_right (Int.isCoprime_of_sq_sum (isCoprime_comm.mp h))
rw [add_comm]; apply Int.isCoprime_of_sq_sum h
namespace Fermat42
-- If we have a solution to a ^ 4 + b ^ 4 = c ^ 2, we can construct a smaller one. This
-- implies there can't be a smallest solution.
theorem not_minimal {a b c : ℤ} (h : Minimal a b c) (ha2 : a % 2 = 1) (hc : 0 < c) : False := by
-- Use the fact that a ^ 2, b ^ 2, c form a pythagorean triple to obtain m and n such that
-- a ^ 2 = m ^ 2 - n ^ 2, b ^ 2 = 2 * m * n and c = m ^ 2 + n ^ 2
-- first the formula:
have ht : PythagoreanTriple (a ^ 2) (b ^ 2) c := by
delta PythagoreanTriple
linear_combination h.1.2.2
-- coprime requirement:
have h2 : Int.gcd (a ^ 2) (b ^ 2) = 1 :=
Int.isCoprime_iff_gcd_eq_one.mp (coprime_of_minimal h).pow
-- in order to reduce the possibilities we get from the classification of pythagorean triples
-- it helps if we know the parity of a ^ 2 (and the sign of c):
have ha22 : a ^ 2 % 2 = 1 := by
rw [sq, Int.mul_emod, ha2]
decide
obtain ⟨m, n, ht1, ht2, ht3, ht4, ht5, ht6⟩ := ht.coprime_classification' h2 ha22 hc
-- Now a, n, m form a pythagorean triple and so we can obtain r and s such that
-- a = r ^ 2 - s ^ 2, n = 2 * r * s and m = r ^ 2 + s ^ 2
-- formula:
have htt : PythagoreanTriple a n m := by
delta PythagoreanTriple
linear_combination ht1
-- a and n are coprime, because a ^ 2 = m ^ 2 - n ^ 2 and m and n are coprime.
have h3 : Int.gcd a n = 1 := by
apply Int.isCoprime_iff_gcd_eq_one.mp
apply @IsCoprime.of_mul_left_left _ _ _ a
rw [← sq, ht1, (by ring : m ^ 2 - n ^ 2 = m ^ 2 + -n * n)]
exact (Int.isCoprime_iff_gcd_eq_one.mpr ht4).pow_left.add_mul_right_left (-n)
-- m is positive because b is non-zero and b ^ 2 = 2 * m * n and we already have 0 ≤ m.
have hb20 : b ^ 2 ≠ 0 := pow_ne_zero _ h.1.2.1
have h4 : 0 < m := by
apply lt_of_le_of_ne ht6
rintro rfl
omega
obtain ⟨r, s, _, htt2, htt3, htt4, htt5, htt6⟩ := htt.coprime_classification' h3 ha2 h4
-- Now use the fact that (b / 2) ^ 2 = m * r * s, and m, r and s are pairwise coprime to obtain
-- i, j and k such that m = i ^ 2, r = j ^ 2 and s = k ^ 2.
-- m and r * s are coprime because m = r ^ 2 + s ^ 2 and r and s are coprime.
have hcp : Int.gcd m (r * s) = 1 := by
rw [htt3]
exact Int.isCoprime_iff_gcd_eq_one.mp
(Int.isCoprime_of_sq_sum' (Int.isCoprime_iff_gcd_eq_one.mpr htt4))
-- b is even because b ^ 2 = 2 * m * n.
have hb2 : 2 ∣ b := by
apply @Int.Prime.dvd_pow' _ 2 _ Nat.prime_two
rw [ht2, mul_assoc]
exact dvd_mul_right 2 (m * n)
obtain ⟨b', hb2'⟩ := hb2
have hs : b' ^ 2 = m * (r * s) := by
apply (mul_right_inj' (by simp : (4 : ℤ) ≠ 0)).mp
linear_combination (-b - 2 * b') * hb2' + ht2 + 2 * m * htt2
have hrsz : r * s ≠ 0 := by grind
have h2b0 : b' ≠ 0 := by grind
obtain ⟨i, hi⟩ := Int.sq_of_gcd_eq_one hcp hs.symm
-- use m is positive to exclude m = - i ^ 2
have hi' : ¬m = -i ^ 2 := by
by_contra h1
have hit : -i ^ 2 ≤ 0 := neg_nonpos.mpr (sq_nonneg i)
rw [← h1] at hit
apply absurd h4 (not_lt.mpr hit)
replace hi : m = i ^ 2 := Or.resolve_right hi hi'
rw [mul_comm] at hs
rw [Int.gcd_comm] at hcp
-- obtain d such that r * s = d ^ 2
obtain ⟨d, hd⟩ := Int.sq_of_gcd_eq_one hcp hs.symm
-- (b / 2) ^ 2 and m are positive so r * s is positive
have hd' : ¬r * s = -d ^ 2 := by
by_contra h1
rw [h1] at hs
have h2 : b' ^ 2 ≤ 0 := by
rw [hs, (by ring : -d ^ 2 * m = -(d ^ 2 * m))]
exact neg_nonpos.mpr ((mul_nonneg_iff_of_pos_right h4).mpr (sq_nonneg d))
have h2' : 0 ≤ b' ^ 2 := by apply sq_nonneg b'
exact absurd (lt_of_le_of_ne h2' (Ne.symm (pow_ne_zero _ h2b0))) (not_lt.mpr h2)
replace hd : r * s = d ^ 2 := Or.resolve_right hd hd'
-- r = +/- j ^ 2
obtain ⟨j, hj⟩ := Int.sq_of_gcd_eq_one htt4 hd
have hj0 : j ≠ 0 := by grind
rw [mul_comm] at hd
rw [Int.gcd_comm] at htt4
-- s = +/- k ^ 2
obtain ⟨k, hk⟩ := Int.sq_of_gcd_eq_one htt4 hd
have hk0 : k ≠ 0 := by grind
have hj2 : r ^ 2 = j ^ 4 := by grind
have hk2 : s ^ 2 = k ^ 4 := by grind
-- from m = r ^ 2 + s ^ 2 we now get a new solution to a ^ 4 + b ^ 4 = c ^ 2:
have hh : i ^ 2 = j ^ 4 + k ^ 4 := by grind
have hn : n ≠ 0 := by grind
-- and it has a smaller c: from c = m ^ 2 + n ^ 2 we see that m is smaller than c, and i ^ 2 = m.
have hic : Int.natAbs i < Int.natAbs c := by
apply Int.ofNat_lt.mp
rw [← Int.eq_natAbs_of_nonneg (le_of_lt hc)]
apply lt_of_le_of_lt (Int.natAbs_le_self_sq i)
rw [← hi, ht3]
apply lt_of_le_of_lt (Int.le_self_sq m)
exact lt_add_of_pos_right (m ^ 2) (sq_pos_of_ne_zero hn)
have hic' : Int.natAbs c ≤ Int.natAbs i := by
apply h.2 j k i
exact ⟨hj0, hk0, hh.symm⟩
apply absurd (not_le_of_gt hic) (not_not.mpr hic')
end Fermat42
theorem not_fermat_42 {a b c : ℤ} (ha : a ≠ 0) (hb : b ≠ 0) : a ^ 4 + b ^ 4 ≠ c ^ 2 := by
intro h
obtain ⟨a0, b0, c0, ⟨hf, h2, hp⟩⟩ :=
Fermat42.exists_pos_odd_minimal (And.intro ha (And.intro hb h))
apply Fermat42.not_minimal hf h2 hp
/--
Fermat's Last Theorem for $n=4$: if `a b c : ℕ` are all non-zero
then `a ^ 4 + b ^ 4 ≠ c ^ 4`.
-/
theorem fermatLastTheoremFour : FermatLastTheoremFor 4 := by
rw [fermatLastTheoremFor_iff_int]
intro a b c ha hb _ heq
apply @not_fermat_42 _ _ (c ^ 2) ha hb
rw [heq]; ring
/--
To prove Fermat's Last Theorem, it suffices to prove it for odd prime exponents.
-/
theorem FermatLastTheorem.of_odd_primes
(hprimes : ∀ p : ℕ, Nat.Prime p → Odd p → FermatLastTheoremFor p) : FermatLastTheorem := by
intro n h
obtain hdvd | ⟨p, hpprime, hdvd, hpodd⟩ := Nat.four_dvd_or_exists_odd_prime_and_dvd_of_two_lt h
<;> apply FermatLastTheoremWith.mono hdvd
· exact fermatLastTheoremFour
· exact hprimes p hpprime hpodd |
.lake/packages/mathlib/Mathlib/NumberTheory/FLT/Basic.lean | import Mathlib.Algebra.EuclideanDomain.Int
import Mathlib.Algebra.GCDMonoid.Finset
import Mathlib.Algebra.GCDMonoid.Nat
import Mathlib.Algebra.Order.Ring.Abs
import Mathlib.RingTheory.PrincipalIdealDomain
/-!
# Statement of Fermat's Last Theorem
This file states Fermat's Last Theorem. We provide a statement over a general semiring with
specific exponent, along with the usual statement over the naturals.
## Main definitions
* `FermatLastTheoremWith R n`: The statement that only solutions to the Fermat
equation `a^n + b^n = c^n` in the semiring `R` have `a = 0`, `b = 0` or `c = 0`.
Note that this statement can certainly be false for certain values of `R` and `n`.
For example `FermatLastTheoremWith ℝ 3` is false as `1^3 + 1^3 = (2^{1/3})^3`, and
`FermatLastTheoremWith ℕ 2` is false, as 3^2 + 4^2 = 5^2.
* `FermatLastTheoremFor n` : The statement that the only solutions to `a^n + b^n = c^n` in `ℕ`
have `a = 0`, `b = 0` or `c = 0`. Again, this statement is not always true, for
example `FermatLastTheoremFor 1` is false because `2^1 + 2^1 = 4^1`.
* `FermatLastTheorem` : The statement of Fermat's Last Theorem, namely that the only solutions to
`a^n + b^n = c^n` in `ℕ` when `n ≥ 3` have `a = 0`, `b = 0` or `c = 0`.
## History
Fermat's Last Theorem was an open problem in number theory for hundreds of years, until it was
finally solved by Andrew Wiles, assisted by Richard Taylor, in 1994 (see
[A. Wiles, *Modular elliptic curves and Fermat's last theorem*][Wiles-FLT] and
[R. Taylor and A. Wiles, *Ring-theoretic properties of certain Hecke algebras*][Taylor-Wiles-FLT]).
An ongoing Lean formalisation of the proof, using mathlib as a dependency, is taking place at
https://github.com/ImperialCollegeLondon/FLT .
-/
open List
/-- Statement of Fermat's Last Theorem over a given semiring with a specific exponent. -/
def FermatLastTheoremWith (R : Type*) [Semiring R] (n : ℕ) : Prop :=
∀ a b c : R, a ≠ 0 → b ≠ 0 → c ≠ 0 → a ^ n + b ^ n ≠ c ^ n
/-- Statement of Fermat's Last Theorem over the naturals for a given exponent. -/
def FermatLastTheoremFor (n : ℕ) : Prop := FermatLastTheoremWith ℕ n
/-- Statement of Fermat's Last Theorem: `a ^ n + b ^ n = c ^ n` has no nontrivial natural solution
when `n ≥ 3`.
This is now a theorem of Wiles and Taylor--Wiles; see
https://github.com/ImperialCollegeLondon/FLT for an ongoing Lean formalisation of
a proof. -/
def FermatLastTheorem : Prop := ∀ n ≥ 3, FermatLastTheoremFor n
lemma fermatLastTheoremFor_zero : FermatLastTheoremFor 0 :=
fun _ _ _ _ _ _ ↦ by simp
lemma not_fermatLastTheoremFor_one : ¬ FermatLastTheoremFor 1 :=
fun h ↦ h 1 1 2 (by simp) (by simp) (by simp) (by simp)
lemma not_fermatLastTheoremFor_two : ¬ FermatLastTheoremFor 2 :=
fun h ↦ h 3 4 5 (by simp) (by simp) (by simp) (by simp)
variable {R : Type*} [Semiring R] [NoZeroDivisors R] {m n : ℕ}
lemma FermatLastTheoremWith.mono (hmn : m ∣ n) (hm : FermatLastTheoremWith R m) :
FermatLastTheoremWith R n := by
rintro a b c ha hb hc
obtain ⟨k, rfl⟩ := hmn
simp_rw [pow_mul']
refine hm _ _ _ ?_ ?_ ?_ <;> exact pow_ne_zero _ ‹_›
lemma FermatLastTheoremFor.mono (hmn : m ∣ n) (hm : FermatLastTheoremFor m) :
FermatLastTheoremFor n := by
exact FermatLastTheoremWith.mono hmn hm
lemma fermatLastTheoremWith_nat_int_rat_tfae (n : ℕ) :
TFAE [FermatLastTheoremWith ℕ n, FermatLastTheoremWith ℤ n, FermatLastTheoremWith ℚ n] := by
tfae_have 1 → 2
| h, a, b, c, ha, hb, hc, habc => by
obtain hn | hn := n.even_or_odd
· refine h a.natAbs b.natAbs c.natAbs (by positivity) (by positivity) (by positivity)
(Int.natCast_inj.1 ?_)
push_cast
simp only [hn.pow_abs, habc]
obtain ha | ha := ha.lt_or_gt <;> obtain hb | hb := hb.lt_or_gt <;>
obtain hc | hc := hc.lt_or_gt
· refine h a.natAbs b.natAbs c.natAbs (by positivity) (by positivity) (by positivity)
(Int.natCast_inj.1 ?_)
push_cast
simp only [abs_of_neg, neg_pow a, neg_pow b, neg_pow c, ← mul_add, *]
· exact (by positivity : 0 < c ^ n).not_gt <| habc.symm.trans_lt <| add_neg (hn.pow_neg ha) <|
hn.pow_neg hb
· refine h b.natAbs c.natAbs a.natAbs (by positivity) (by positivity) (by positivity)
(Int.natCast_inj.1 ?_)
push_cast
simp only [abs_of_pos, abs_of_neg, hn.neg_pow, add_neg_eq_iff_eq_add,
eq_neg_add_iff_add_eq, *]
· refine h a.natAbs c.natAbs b.natAbs (by positivity) (by positivity) (by positivity)
(Int.natCast_inj.1 ?_)
push_cast
simp only [abs_of_pos, abs_of_neg, hn.neg_pow, neg_add_eq_iff_eq_add,
*]
· refine h c.natAbs a.natAbs b.natAbs (by positivity) (by positivity) (by positivity)
(Int.natCast_inj.1 ?_)
push_cast
simp only [abs_of_pos, abs_of_neg, hn.neg_pow, neg_add_eq_iff_eq_add,
eq_add_neg_iff_add_eq, *]
· refine h c.natAbs b.natAbs a.natAbs (by positivity) (by positivity) (by positivity)
(Int.natCast_inj.1 ?_)
push_cast
simp only [abs_of_pos, abs_of_neg, hn.neg_pow, add_neg_eq_iff_eq_add,
*]
· exact (by positivity : 0 < a ^ n + b ^ n).not_gt <| habc.trans_lt <| hn.pow_neg hc
· refine h a.natAbs b.natAbs c.natAbs (by positivity) (by positivity) (by positivity)
(Int.natCast_inj.1 ?_)
push_cast
simp only [abs_of_pos, *]
tfae_have 2 → 3
| h, a, b, c, ha, hb, hc, habc => by
rw [← Rat.num_ne_zero] at ha hb hc
refine h (a.num * b.den * c.den) (a.den * b.num * c.den) (a.den * b.den * c.num)
(by positivity) (by positivity) (by positivity) ?_
have : (a.den * b.den * c.den : ℚ) ^ n ≠ 0 := by positivity
refine Int.cast_injective <| (div_left_inj' this).1 ?_
push_cast
simp only [add_div, ← div_pow, mul_div_mul_comm, div_self (by positivity : (a.den : ℚ) ≠ 0),
div_self (by positivity : (b.den : ℚ) ≠ 0), div_self (by positivity : (c.den : ℚ) ≠ 0),
one_mul, mul_one, Rat.num_div_den, habc]
tfae_have 3 → 1
| h, a, b, c => mod_cast h a b c
tfae_finish
lemma fermatLastTheoremFor_iff_nat {n : ℕ} : FermatLastTheoremFor n ↔ FermatLastTheoremWith ℕ n :=
Iff.rfl
lemma fermatLastTheoremFor_iff_int {n : ℕ} : FermatLastTheoremFor n ↔ FermatLastTheoremWith ℤ n :=
(fermatLastTheoremWith_nat_int_rat_tfae n).out 0 1
lemma fermatLastTheoremFor_iff_rat {n : ℕ} : FermatLastTheoremFor n ↔ FermatLastTheoremWith ℚ n :=
(fermatLastTheoremWith_nat_int_rat_tfae n).out 0 2
/--
A relaxed variant of Fermat's Last Theorem over a given commutative semiring with a specific
exponent, allowing nonzero solutions of units and their common multiples.
1. The variant `FermatLastTheoremWith' R` is weaker than `FermatLastTheoremWith R` in general.
In particular, it holds trivially for `[Field R]`.
2. This variant is equivalent to the original `FermatLastTheoremWith R` for `R = ℕ` or `ℤ`.
In general, they are equivalent if there is no solutions of units to the Fermat equation.
3. For a polynomial ring `R = k[X]`, the original `FermatLastTheoremWith R` is false but the weaker
variant `FermatLastTheoremWith' R` is true. This polynomial variant of Fermat's Last Theorem
can be shown elementarily using Mason--Stothers theorem.
-/
def FermatLastTheoremWith' (R : Type*) [CommSemiring R] (n : ℕ) : Prop :=
∀ a b c : R, a ≠ 0 → b ≠ 0 → c ≠ 0 → a ^ n + b ^ n = c ^ n →
∃ d a' b' c', (a = a' * d ∧ b = b' * d ∧ c = c' * d) ∧ (IsUnit a' ∧ IsUnit b' ∧ IsUnit c')
lemma FermatLastTheoremWith.fermatLastTheoremWith' {R : Type*} [CommSemiring R] {n : ℕ}
(h : FermatLastTheoremWith R n) : FermatLastTheoremWith' R n :=
fun a b c _ _ _ _ ↦ by exfalso; apply h a b c <;> assumption
lemma fermatLastTheoremWith'_of_semifield (𝕜 : Type*) [Semifield 𝕜] (n : ℕ) :
FermatLastTheoremWith' 𝕜 n := fun a b c ha hb hc _ ↦
⟨1, a, b, c,
⟨(mul_one a).symm, (mul_one b).symm, (mul_one c).symm⟩,
⟨ha.isUnit, hb.isUnit, hc.isUnit⟩⟩
lemma FermatLastTheoremWith'.fermatLastTheoremWith {R : Type*} [CommSemiring R] [IsDomain R]
{n : ℕ} (h : FermatLastTheoremWith' R n)
(hn : ∀ a b c : R, IsUnit a → IsUnit b → IsUnit c → a ^ n + b ^ n ≠ c ^ n) :
FermatLastTheoremWith R n := by
intro a b c ha hb hc heq
rcases h a b c ha hb hc heq with ⟨d, a', b', c', ⟨rfl, rfl, rfl⟩, ⟨ua, ub, uc⟩⟩
rw [mul_pow, mul_pow, mul_pow, ← add_mul] at heq
exact hn _ _ _ ua ub uc <| mul_right_cancel₀ (pow_ne_zero _ (right_ne_zero_of_mul ha)) heq
lemma fermatLastTheoremWith'_iff_fermatLastTheoremWith {R : Type*} [CommSemiring R] [IsDomain R]
{n : ℕ} (hn : ∀ a b c : R, IsUnit a → IsUnit b → IsUnit c → a ^ n + b ^ n ≠ c ^ n) :
FermatLastTheoremWith' R n ↔ FermatLastTheoremWith R n :=
Iff.intro (fun h ↦ h.fermatLastTheoremWith hn) (fun h ↦ h.fermatLastTheoremWith')
lemma fermatLastTheoremWith'_nat_int_tfae (n : ℕ) :
TFAE [FermatLastTheoremFor n, FermatLastTheoremWith' ℕ n, FermatLastTheoremWith' ℤ n] := by
tfae_have 2 ↔ 1 := by
apply fermatLastTheoremWith'_iff_fermatLastTheoremWith
simp only [Nat.isUnit_iff]
intro _ _ _ ha hb hc
rw [ha, hb, hc]
simp only [one_pow, Nat.reduceAdd, ne_eq, OfNat.ofNat_ne_one, not_false_eq_true]
tfae_have 3 ↔ 1 := by
rw [fermatLastTheoremFor_iff_int]
apply fermatLastTheoremWith'_iff_fermatLastTheoremWith
intro a b c ha hb hc
by_cases hn : n = 0
· subst hn
simp only [pow_zero, Int.reduceAdd, ne_eq, OfNat.ofNat_ne_one, not_false_eq_true]
· rw [← isUnit_pow_iff hn, Int.isUnit_iff] at ha hb hc
-- case division
rcases ha with ha | ha <;> rcases hb with hb | hb <;> rcases hc with hc | hc <;>
rw [ha, hb, hc] <;> decide
tfae_finish
open Finset in
/-- To prove Fermat Last Theorem in any semiring that is a `NormalizedGCDMonoid` one can assume
that the `gcd` of `{a, b, c}` is `1`. -/
lemma fermatLastTheoremWith_of_fermatLastTheoremWith_coprime {n : ℕ} {R : Type*} [CommSemiring R]
[IsDomain R] [DecidableEq R] [NormalizedGCDMonoid R]
(hn : ∀ a b c : R, a ≠ 0 → b ≠ 0 → c ≠ 0 → ({a, b, c} : Finset R).gcd id = 1 →
a ^ n + b ^ n ≠ c ^ n) :
FermatLastTheoremWith R n := by
intro a b c ha hb hc habc
let s : Finset R := {a, b, c}; let d := s.gcd id
obtain ⟨A, hA⟩ : d ∣ a := gcd_dvd (by simp [s])
obtain ⟨B, hB⟩ : d ∣ b := gcd_dvd (by simp [s])
obtain ⟨C, hC⟩ : d ∣ c := gcd_dvd (by simp [s])
simp only [hA, hB, hC, mul_ne_zero_iff, mul_pow] at ha hb hc habc
rw [← mul_add, mul_right_inj' (pow_ne_zero n ha.1)] at habc
refine hn A B C ha.2 hb.2 hc.2 ?_ habc
rw [← Finset.normalize_gcd, normalize_eq_one]
obtain ⟨u, hu⟩ := normalize_associated d
refine ⟨u, mul_left_cancel₀ (mt normalize_eq_zero.mp ha.1) (hu.symm ▸ ?_)⟩
rw [← Finset.gcd_mul_left, gcd_eq_gcd_image, image_insert, image_insert, image_singleton,
id_eq, id_eq, id_eq, ← hA, ← hB, ← hC]
lemma dvd_c_of_prime_of_dvd_a_of_dvd_b_of_FLT {n : ℕ} {p : ℤ} (hp : Prime p) {a b c : ℤ}
(hpa : p ∣ a) (hpb : p ∣ b) (HF : a ^ n + b ^ n + c ^ n = 0) : p ∣ c := by
rcases eq_or_ne n 0 with rfl | hn
· simp at HF
refine hp.dvd_of_dvd_pow (n := n) (dvd_neg.1 ?_)
rw [add_eq_zero_iff_eq_neg] at HF
exact HF.symm ▸ dvd_add (dvd_pow hpa hn) (dvd_pow hpb hn)
lemma isCoprime_of_gcd_eq_one_of_FLT {n : ℕ} {a b c : ℤ} (Hgcd : Finset.gcd {a, b, c} id = 1)
(HF : a ^ n + b ^ n + c ^ n = 0) : IsCoprime a b := by
rcases eq_or_ne n 0 with rfl | hn
· simp only [pow_zero, Int.reduceAdd, OfNat.ofNat_ne_zero] at HF
refine isCoprime_of_prime_dvd ?_ <| (fun p hp hpa hpb ↦ hp.not_dvd_one ?_)
· rintro ⟨rfl, rfl⟩
simp only [ne_eq, hn, not_false_eq_true, zero_pow, add_zero, zero_add, pow_eq_zero_iff]
at HF
simp only [HF, Finset.mem_singleton, Finset.insert_eq_of_mem, Finset.gcd_singleton, id_eq,
map_zero, zero_ne_one] at Hgcd
· rw [← Hgcd]
refine Finset.dvd_gcd_iff.mpr fun x hx ↦ ?_
simp only [Finset.mem_insert, Finset.mem_singleton] at hx
rcases hx with hx | hx | hx <;> simp only [id_eq, hx, hpa, hpb,
dvd_c_of_prime_of_dvd_a_of_dvd_b_of_FLT hp hpa hpb HF] |
.lake/packages/mathlib/Mathlib/NumberTheory/FLT/MasonStothers.lean | import Mathlib.RingTheory.Polynomial.Radical
/-!
# Mason-Stothers theorem
This file states and proves the Mason-Stothers theorem, which is a polynomial version of the
ABC conjecture. For (pairwise) coprime polynomials `a, b, c` (over a field) with `a + b + c = 0`,
we have `max {deg(a), deg(b), deg(c)} + 1 ≤ deg(rad(abc))` or `a' = b' = c' = 0`.
Proof is based on this online note by Franz Lemmermeyer http://www.fen.bilkent.edu.tr/~franz/ag05/ag-02.pdf,
which is essentially based on Noah Snyder's paper "An Alternative Proof of Mason's Theorem",
but slightly different.
-/
open Polynomial UniqueFactorizationMonoid UniqueFactorizationDomain EuclideanDomain
variable {k : Type*} [Field k] [DecidableEq k]
-- we use this three times; the assumptions are symmetric in a, b, c.
private theorem abc_subcall {a b c w : k[X]} {hw : w ≠ 0} (wab : w = wronskian a b) (ha : a ≠ 0)
(hb : b ≠ 0) (hc : c ≠ 0) (abc_dr_dvd_w : divRadical (a * b * c) ∣ w) :
c.natDegree + 1 ≤ (radical (a * b * c)).natDegree := by
have ab_nz := mul_ne_zero ha hb
have abc_nz := mul_ne_zero ab_nz hc
-- bound the degree of `divRadical (a * b * c)` using Wronskian `w`
set abc_dr := divRadical (a * b * c)
have abc_dr_ndeg_lt : abc_dr.natDegree < a.natDegree + b.natDegree := by
calc
abc_dr.natDegree ≤ w.natDegree := Polynomial.natDegree_le_of_dvd abc_dr_dvd_w hw
_ < a.natDegree + b.natDegree := by rw [wab] at hw ⊢; exact natDegree_wronskian_lt_add hw
-- add the degree of `radical (a * b * c)` to both sides and rearrange
set abc_r := radical (a * b * c)
apply Nat.lt_of_add_lt_add_left
calc
a.natDegree + b.natDegree + c.natDegree = (a * b * c).natDegree := by
rw [Polynomial.natDegree_mul ab_nz hc, Polynomial.natDegree_mul ha hb]
_ = ((divRadical (a * b * c)) * (radical (a * b * c))).natDegree := by
rw [mul_comm _ (radical _), radical_mul_divRadical]
_ = abc_dr.natDegree + abc_r.natDegree := by
rw [← Polynomial.natDegree_mul (divRadical_ne_zero abc_nz) radical_ne_zero]
_ < a.natDegree + b.natDegree + abc_r.natDegree := by
exact Nat.add_lt_add_right abc_dr_ndeg_lt _
/-- **Polynomial ABC theorem.** -/
protected theorem Polynomial.abc
{a b c : k[X]} (ha : a ≠ 0) (hb : b ≠ 0) (hc : c ≠ 0)
(hab : IsCoprime a b) (hsum : a + b + c = 0) :
(natDegree a + 1 ≤ (radical (a * b * c)).natDegree ∧
natDegree b + 1 ≤ (radical (a * b * c)).natDegree ∧
natDegree c + 1 ≤ (radical (a * b * c)).natDegree) ∨
derivative a = 0 ∧ derivative b = 0 ∧ derivative c = 0 := by
set w := wronskian a b with wab
have hbc : IsCoprime b c := by
rw [add_eq_zero_iff_neg_eq] at hsum
rw [← hsum, IsCoprime.neg_right_iff]
convert IsCoprime.add_mul_left_right hab.symm 1
rw [mul_one]
have hsum' : b + c + a = 0 := by rwa [add_rotate] at hsum
have hca : IsCoprime c a := by
rw [add_eq_zero_iff_neg_eq] at hsum'
rw [← hsum', IsCoprime.neg_right_iff]
convert IsCoprime.add_mul_left_right hbc.symm 1
rw [mul_one]
have wbc : w = wronskian b c := wronskian_eq_of_sum_zero hsum
have wca : w = wronskian c a := by
rw [add_rotate] at hsum
simpa only [← wbc] using wronskian_eq_of_sum_zero hsum
-- have `divRadical x` dividing `w` for `x = a, b, c`, and use coprimality
have abc_dr_dvd_w : divRadical (a * b * c) ∣ w := by
have adr_dvd_w := divRadical_dvd_wronskian_left a b
have bdr_dvd_w := divRadical_dvd_wronskian_right a b
have cdr_dvd_w := divRadical_dvd_wronskian_right b c
rw [← wab] at adr_dvd_w bdr_dvd_w
rw [← wbc] at cdr_dvd_w
rw [divRadical_mul (hca.symm.mul_left hbc), divRadical_mul hab]
exact (hca.divRadical.symm.mul_left hbc.divRadical).mul_dvd
(hab.divRadical.mul_dvd adr_dvd_w bdr_dvd_w) cdr_dvd_w
by_cases hw : w = 0
· right
rw [hw] at wab wbc
obtain ⟨ga, gb⟩ := hab.wronskian_eq_zero_iff.mp wab.symm
obtain ⟨_, gc⟩ := hbc.wronskian_eq_zero_iff.mp wbc.symm
exact ⟨ga, gb, gc⟩
· left
-- use `abc_subcall` three times, using the symmetry in `a, b, c`
refine ⟨?_, ?_, ?_⟩
· rw [mul_rotate] at abc_dr_dvd_w ⊢
apply abc_subcall wbc <;> assumption
· rw [← mul_rotate] at abc_dr_dvd_w ⊢
apply abc_subcall wca <;> assumption
· apply abc_subcall wab <;> assumption |
.lake/packages/mathlib/Mathlib/NumberTheory/FLT/Three.lean | import Mathlib.NumberTheory.FLT.Basic
import Mathlib.NumberTheory.NumberField.Cyclotomic.PID
import Mathlib.NumberTheory.NumberField.Cyclotomic.Three
import Mathlib.Algebra.Ring.Divisibility.Lemmas
/-!
# Fermat Last Theorem in the case `n = 3`
The goal of this file is to prove Fermat's Last Theorem in the case `n = 3`.
## Main results
* `fermatLastTheoremThree`: Fermat's Last Theorem for `n = 3`: if `a b c : ℕ` are all non-zero then
`a ^ 3 + b ^ 3 ≠ c ^ 3`.
## Implementation details
We follow the proof in <https://webusers.imj-prg.fr/~marc.hindry/Cours-arith.pdf>, page 43.
The strategy is the following:
* The so called "Case 1", when `3 ∣ a * b * c` is completely elementary and is proved using
congruences modulo `9`.
* To prove case 2, we consider the generalized equation `a ^ 3 + b ^ 3 = u * c ^ 3`, where `a`, `b`,
and `c` are in the cyclotomic ring `ℤ[ζ₃]` (where `ζ₃` is a primitive cube root of unity) and `u`
is a unit of `ℤ[ζ₃]`. `FermatLastTheoremForThree_of_FermatLastTheoremThreeGen` (whose proof is
rather elementary on paper) says that to prove Fermat's last theorem for exponent `3`, it is
enough to prove that this equation has no solutions such that `c ≠ 0`, `¬ λ ∣ a`, `¬ λ ∣ b`,
`λ ∣ c` and `IsCoprime a b` (where we set `λ := ζ₃ - 1`). We call such a tuple a `Solution'`.
A `Solution` is the same as a `Solution'` with the additional assumption that `λ ^ 2 ∣ a + b`.
We then prove that, given `S' : Solution'`, there is `S : Solution` such that the multiplicity of
`λ = ζ₃ - 1` in `c` is the same in `S'` and `S` (see `exists_Solution_of_Solution'`).
In particular it is enough to prove that no `Solution` exists. The key point is a descent argument
on the multiplicity of `λ` in `c`: starting with `S : Solution` we can find `S₁ : Solution` with
multiplicity strictly smaller (see `exists_Solution_multiplicity_lt`) and this finishes the proof.
To construct `S₁` we go through a `Solution'` and then back to a `Solution`. More importantly, we
cannot control the unit `u`, and this is the reason why we need to consider the generalized
equation `a ^ 3 + b ^ 3 = u * c ^ 3`. The construction is completely explicit, but it depends
crucially on `IsCyclotomicExtension.Rat.Three.eq_one_or_neg_one_of_unit_of_congruent`, a special
case of Kummer's lemma.
* Note that we don't prove Case 1 for the generalized equation (in particular we don't prove that
the generalized equation has no nontrivial solutions). This is because the proof, even if
elementary on paper, would be quite annoying to formalize: indeed it involves a lot of explicit
computations in `ℤ[ζ₃] / (λ)`: this ring is isomorphic to `ℤ / 9ℤ`, but of course, even if we
construct such an isomorphism, tactics like `decide` would not work.
-/
section case1
open ZMod
private lemma cube_of_castHom_ne_zero {n : ZMod 9} :
castHom (show 3 ∣ 9 by simp) (ZMod 3) n ≠ 0 → n ^ 3 = 1 ∨ n ^ 3 = 8 := by
revert n; decide
private lemma cube_of_not_dvd {n : ℤ} (h : ¬ 3 ∣ n) :
(n : ZMod 9) ^ 3 = 1 ∨ (n : ZMod 9) ^ 3 = 8 := by
apply cube_of_castHom_ne_zero
rwa [map_intCast, Ne, ZMod.intCast_zmod_eq_zero_iff_dvd]
/-- If `a b c : ℤ` are such that `¬ 3 ∣ a * b * c`, then `a ^ 3 + b ^ 3 ≠ c ^ 3`. -/
theorem fermatLastTheoremThree_case_1 {a b c : ℤ} (hdvd : ¬ 3 ∣ a * b * c) :
a ^ 3 + b ^ 3 ≠ c ^ 3 := by
simp_rw [Int.prime_three.dvd_mul, not_or] at hdvd
apply mt (congrArg (Int.cast : ℤ → ZMod 9))
simp_rw [Int.cast_add, Int.cast_pow]
rcases cube_of_not_dvd hdvd.1.1 with ha | ha <;>
rcases cube_of_not_dvd hdvd.1.2 with hb | hb <;>
rcases cube_of_not_dvd hdvd.2 with hc | hc <;>
rw [ha, hb, hc] <;> decide
end case1
section case2
private lemma three_dvd_b_of_dvd_a_of_gcd_eq_one_of_case2 {a b c : ℤ} (ha : a ≠ 0)
(Hgcd : Finset.gcd {a, b, c} id = 1) (h3a : 3 ∣ a) (HF : a ^ 3 + b ^ 3 + c ^ 3 = 0)
(H : ∀ a b c : ℤ, c ≠ 0 → ¬ 3 ∣ a → ¬ 3 ∣ b → 3 ∣ c → IsCoprime a b → a ^ 3 + b ^ 3 ≠ c ^ 3) :
3 ∣ b := by
have hbc : IsCoprime (-b) (-c) := by
refine IsCoprime.neg_neg ?_
rw [add_comm (a ^ 3), add_assoc, add_comm (a ^ 3), ← add_assoc] at HF
refine isCoprime_of_gcd_eq_one_of_FLT ?_ HF
convert Hgcd using 2
rw [Finset.pair_comm, Finset.insert_comm]
by_contra! h3b
by_cases h3c : 3 ∣ c
· apply h3b
rw [add_assoc, add_comm (b ^ 3), ← add_assoc] at HF
exact dvd_c_of_prime_of_dvd_a_of_dvd_b_of_FLT Int.prime_three h3a h3c HF
· refine H (-b) (-c) a ha (by simp [h3b]) (by simp [h3c]) h3a hbc ?_
rw [add_eq_zero_iff_eq_neg, ← (show Odd 3 by decide).neg_pow] at HF
rw [← HF]
ring
open Finset in
private lemma fermatLastTheoremThree_of_dvd_a_of_gcd_eq_one_of_case2 {a b c : ℤ} (ha : a ≠ 0)
(h3a : 3 ∣ a) (Hgcd : Finset.gcd {a, b, c} id = 1)
(H : ∀ a b c : ℤ, c ≠ 0 → ¬ 3 ∣ a → ¬ 3 ∣ b → 3 ∣ c → IsCoprime a b → a ^ 3 + b ^ 3 ≠ c ^ 3) :
a ^ 3 + b ^ 3 + c ^ 3 ≠ 0 := by
intro HF
apply (show ¬(3 ∣ (1 : ℤ)) by decide)
rw [← Hgcd]
refine dvd_gcd (fun x hx ↦ ?_)
simp only [mem_insert, mem_singleton] at hx
have h3b : 3 ∣ b := by
refine three_dvd_b_of_dvd_a_of_gcd_eq_one_of_case2 ha ?_ h3a HF H
simp only [← Hgcd, gcd_insert, gcd_singleton, id_eq, ← Int.abs_eq_normalize]
rcases hx with hx | hx | hx
· exact hx ▸ h3a
· exact hx ▸ h3b
· simpa [hx] using dvd_c_of_prime_of_dvd_a_of_dvd_b_of_FLT Int.prime_three h3a h3b HF
open Finset Int in
/--
To prove Fermat's Last Theorem for `n = 3`, it is enough to show that for all `a`, `b`, `c`
in `ℤ` such that `c ≠ 0`, `¬ 3 ∣ a`, `¬ 3 ∣ b`, `a` and `b` are coprime and `3 ∣ c`, we have
`a ^ 3 + b ^ 3 ≠ c ^ 3`.
-/
theorem fermatLastTheoremThree_of_three_dvd_only_c
(H : ∀ a b c : ℤ, c ≠ 0 → ¬ 3 ∣ a → ¬ 3 ∣ b → 3 ∣ c → IsCoprime a b → a ^ 3 + b ^ 3 ≠ c ^ 3) :
FermatLastTheoremFor 3 := by
rw [fermatLastTheoremFor_iff_int]
refine fermatLastTheoremWith_of_fermatLastTheoremWith_coprime (fun a b c ha hb hc Hgcd hF ↦ ?_)
by_cases h1 : 3 ∣ a * b * c
swap
· exact fermatLastTheoremThree_case_1 h1 hF
rw [(prime_three).dvd_mul, (prime_three).dvd_mul] at h1
rw [← sub_eq_zero, sub_eq_add_neg, ← (show Odd 3 by decide).neg_pow] at hF
rcases h1 with (h3a | h3b) | h3c
· refine fermatLastTheoremThree_of_dvd_a_of_gcd_eq_one_of_case2 ha h3a ?_ H hF
simp only [← Hgcd, gcd_insert, gcd_singleton, id_eq, ← abs_eq_normalize, abs_neg]
· rw [add_comm (a ^ 3)] at hF
refine fermatLastTheoremThree_of_dvd_a_of_gcd_eq_one_of_case2 hb h3b ?_ H hF
simp only [← Hgcd, insert_comm, gcd_insert, gcd_singleton, id_eq, ← abs_eq_normalize, abs_neg]
· rw [add_comm _ ((-c) ^ 3), ← add_assoc] at hF
refine fermatLastTheoremThree_of_dvd_a_of_gcd_eq_one_of_case2 (neg_ne_zero.2 hc) (by simp [h3c])
?_ H hF
rw [Finset.insert_comm (-c), Finset.pair_comm (-c) b]
simp only [← Hgcd, gcd_insert, gcd_singleton, id_eq, ← abs_eq_normalize, abs_neg]
section eisenstein
open NumberField IsCyclotomicExtension.Rat.Three
variable {K : Type*} [Field K]
variable {ζ : K} (hζ : IsPrimitiveRoot ζ 3)
local notation3 "η" => (IsPrimitiveRoot.isUnit (hζ.toInteger_isPrimitiveRoot) (by decide)).unit
local notation3 "λ" => hζ.toInteger - 1
/-- `FermatLastTheoremForThreeGen` is the statement that `a ^ 3 + b ^ 3 = u * c ^ 3` has no
nontrivial solutions in `𝓞 K` for all `u : (𝓞 K)ˣ` such that `¬ λ ∣ a`, `¬ λ ∣ b` and `λ ∣ c`.
The reason to consider `FermatLastTheoremForThreeGen` is to make a descent argument working. -/
def FermatLastTheoremForThreeGen : Prop :=
∀ a b c : 𝓞 K, ∀ u : (𝓞 K)ˣ, c ≠ 0 → ¬ λ ∣ a → ¬ λ ∣ b → λ ∣ c → IsCoprime a b →
a ^ 3 + b ^ 3 ≠ u * c ^ 3
/-- To prove `FermatLastTheoremFor 3`, it is enough to prove `FermatLastTheoremForThreeGen`. -/
lemma FermatLastTheoremForThree_of_FermatLastTheoremThreeGen
[NumberField K] [IsCyclotomicExtension {3} ℚ K] :
FermatLastTheoremForThreeGen hζ → FermatLastTheoremFor 3 := by
intro H
refine fermatLastTheoremThree_of_three_dvd_only_c (fun a b c hc ha hb ⟨x, hx⟩ hcoprime h ↦ ?_)
refine H a b c 1 (by simp [hc]) (fun hdvd ↦ ha ?_) (fun hdvd ↦ hb ?_) ?_ ?_ ?_
· rwa [← Ideal.norm_dvd_iff (hζ.prime_norm_toInteger_sub_one_of_prime_ne_two' (by decide)),
hζ.norm_toInteger_sub_one_of_prime_ne_two' (by decide)] at hdvd
· rwa [← Ideal.norm_dvd_iff (hζ.prime_norm_toInteger_sub_one_of_prime_ne_two' (by decide)),
hζ.norm_toInteger_sub_one_of_prime_ne_two' (by decide)] at hdvd
· exact dvd_trans hζ.toInteger_sub_one_dvd_prime' ⟨x, by simp [hx]⟩
· rw [show a = algebraMap _ (𝓞 K) a by simp, show b = algebraMap _ (𝓞 K) b by simp]
exact hcoprime.map _
· simp only [Units.val_one, one_mul]
exact_mod_cast h
namespace FermatLastTheoremForThreeGen
/-- `Solution'` is a tuple given by a solution to `a ^ 3 + b ^ 3 = u * c ^ 3`,
where `a`, `b`, `c` and `u` are as in `FermatLastTheoremForThreeGen`.
See `Solution` for the actual structure on which we will do the descent. -/
structure Solution' where
a : 𝓞 K
b : 𝓞 K
c : 𝓞 K
u : (𝓞 K)ˣ
ha : ¬ λ ∣ a
hb : ¬ λ ∣ b
hc : c ≠ 0
coprime : IsCoprime a b
hcdvd : λ ∣ c
H : a ^ 3 + b ^ 3 = u * c ^ 3
attribute [nolint docBlame] Solution'.a
attribute [nolint docBlame] Solution'.b
attribute [nolint docBlame] Solution'.c
attribute [nolint docBlame] Solution'.u
/-- `Solution` is the same as `Solution'` with the additional assumption that `λ ^ 2 ∣ a + b`. -/
structure Solution extends Solution' hζ where
hab : λ ^ 2 ∣ a + b
variable {hζ}
variable (S : Solution hζ) (S' : Solution' hζ)
section IsCyclotomicExtension
variable [NumberField K] [IsCyclotomicExtension {3} ℚ K]
/-- For any `S' : Solution'`, the multiplicity of `λ` in `S'.c` is finite. -/
lemma Solution'.multiplicity_lambda_c_finite :
FiniteMultiplicity (hζ.toInteger - 1) S'.c :=
.of_not_isUnit hζ.zeta_sub_one_prime'.not_unit S'.hc
/-- Given `S' : Solution'`, `S'.multiplicity` is the multiplicity of `λ` in `S'.c`, as a natural
number. -/
noncomputable def Solution'.multiplicity :=
_root_.multiplicity (hζ.toInteger - 1) S'.c
/-- Given `S : Solution`, `S.multiplicity` is the multiplicity of `λ` in `S.c`, as a natural
number. -/
noncomputable def Solution.multiplicity := S.toSolution'.multiplicity
/-- We say that `S : Solution` is minimal if for all `S₁ : Solution`, the multiplicity of `λ` in
`S.c` is less or equal than the multiplicity in `S₁.c`. -/
def Solution.isMinimal : Prop := ∀ (S₁ : Solution hζ), S.multiplicity ≤ S₁.multiplicity
omit [NumberField K] [IsCyclotomicExtension {3} ℚ K] in
include S in
/-- If there is a solution then there is a minimal one. -/
lemma Solution.exists_minimal : ∃ (S₁ : Solution hζ), S₁.isMinimal := by
classical
let T := {n | ∃ (S' : Solution hζ), S'.multiplicity = n}
rcases Nat.find_spec (⟨S.multiplicity, ⟨S, rfl⟩⟩ : T.Nonempty) with ⟨S₁, hS₁⟩
exact ⟨S₁, fun S'' ↦ hS₁ ▸ Nat.find_min' _ ⟨S'', rfl⟩⟩
/-- Given `S' : Solution'`, then `S'.a` and `S'.b` are both congruent to `1` modulo `λ ^ 4` or are
both congruent to `-1`. -/
lemma a_cube_b_cube_congr_one_or_neg_one :
λ ^ 4 ∣ S'.a ^ 3 - 1 ∧ λ ^ 4 ∣ S'.b ^ 3 + 1 ∨ λ ^ 4 ∣ S'.a ^ 3 + 1 ∧ λ ^ 4 ∣ S'.b ^ 3 - 1 := by
obtain ⟨z, hz⟩ := S'.hcdvd
rcases lambda_pow_four_dvd_cube_sub_one_or_add_one_of_lambda_not_dvd hζ S'.ha with
⟨x, hx⟩ | ⟨x, hx⟩ <;>
rcases lambda_pow_four_dvd_cube_sub_one_or_add_one_of_lambda_not_dvd hζ S'.hb with
⟨y, hy⟩ | ⟨y, hy⟩
· exfalso
replace hζ : IsPrimitiveRoot ζ (3 ^ 1) := by rwa [pow_one]
refine hζ.toInteger_sub_one_not_dvd_two (by decide) ⟨S'.u * λ ^ 2 * z ^ 3 - λ ^ 3 * (x + y), ?_⟩
symm
calc _ = S'.u * (λ * z) ^ 3 - λ ^ 4 * x - λ ^ 4 * y := by ring
_ = (S'.a ^ 3 + S'.b ^ 3) - (S'.a ^ 3 - 1) - (S'.b ^ 3 - 1) := by rw [← hx, ← hy, ← hz, ← S'.H]
_ = 2 := by ring
· left
exact ⟨⟨x, hx⟩, ⟨y, hy⟩⟩
· right
exact ⟨⟨x, hx⟩, ⟨y, hy⟩⟩
· exfalso
replace hζ : IsPrimitiveRoot ζ (3 ^ 1) := by rwa [pow_one]
refine hζ.toInteger_sub_one_not_dvd_two (by decide) ⟨λ ^ 3 * (x + y) - S'.u * λ ^ 2 * z ^ 3, ?_⟩
symm
calc _ = λ ^ 4 * x + λ ^ 4 * y - S'.u * (λ * z) ^ 3 := by ring
_ = (S'.a ^ 3 + 1) + (S'.b ^ 3 + 1) - (S'.a ^ 3 + S'.b ^ 3) := by rw [← hx, ← hy, ← hz, ← S'.H]
_ = 2 := by ring
/-- Given `S' : Solution'`, we have that `λ ^ 4` divides `S'.c ^ 3`. -/
lemma lambda_pow_four_dvd_c_cube : λ ^ 4 ∣ S'.c ^ 3 := by
rcases a_cube_b_cube_congr_one_or_neg_one S' with
⟨⟨x, hx⟩, ⟨y, hy⟩⟩ | ⟨⟨x, hx⟩, ⟨y, hy⟩⟩ <;>
· refine ⟨S'.u⁻¹ * (x + y), ?_⟩
symm
calc _ = S'.u⁻¹ * (λ ^ 4 * x + λ ^ 4 * y) := by ring
_ = S'.u⁻¹ * (S'.a ^ 3 + S'.b ^ 3) := by rw [← hx, ← hy]; ring
_ = S'.u⁻¹ * (S'.u * S'.c ^ 3) := by rw [S'.H]
_ = S'.c ^ 3 := by simp
/-- Given `S' : Solution'`, we have that `λ ^ 2` divides `S'.c`. -/
lemma lambda_sq_dvd_c : λ ^ 2 ∣ S'.c := by
have hm := S'.multiplicity_lambda_c_finite
suffices 2 ≤ multiplicity (hζ.toInteger - 1) S'.c by
obtain ⟨x, hx⟩ := pow_multiplicity_dvd (hζ.toInteger - 1) S'.c
refine ⟨λ ^ (multiplicity (hζ.toInteger - 1) S'.c - 2) * x, ?_⟩
rw [← mul_assoc, ← pow_add]
convert hx using 3
simp [this]
have := lambda_pow_four_dvd_c_cube S'
rw [pow_dvd_iff_le_emultiplicity, emultiplicity_pow hζ.zeta_sub_one_prime',
hm.emultiplicity_eq_multiplicity] at this
norm_cast at this
cutsat
/-- Given `S' : Solution'`, we have that `2 ≤ S'.multiplicity`. -/
lemma Solution'.two_le_multiplicity : 2 ≤ S'.multiplicity := by
simpa [Solution'.multiplicity] using
S'.multiplicity_lambda_c_finite.le_multiplicity_of_pow_dvd (lambda_sq_dvd_c S')
/-- Given `S : Solution`, we have that `2 ≤ S.multiplicity`. -/
lemma Solution.two_le_multiplicity : 2 ≤ S.multiplicity :=
S.toSolution'.two_le_multiplicity
end IsCyclotomicExtension
-- This is just a computation and the formulas are too long.
set_option linter.style.commandStart false in
/-- Given `S' : Solution'`, the key factorization of `S'.a ^ 3 + S'.b ^ 3`. -/
lemma a_cube_add_b_cube_eq_mul :
S'.a ^ 3 + S'.b ^ 3 = (S'.a + S'.b) * (S'.a + η * S'.b) * (S'.a + η ^ 2 * S'.b) := by
symm
calc _ = S'.a^3+S'.a^2*S'.b*(η^2+η+1)+S'.a*S'.b^2*(η^2+η+η^3)+η^3*S'.b^3 := by ring
_ = S'.a^3+S'.a^2*S'.b*(η^2+η+1)+S'.a*S'.b^2*(η^2+η+1)+S'.b^3 := by
simp [hζ.toInteger_cube_eq_one]
_ = S'.a ^ 3 + S'.b ^ 3 := by rw [eta_sq]; ring
section IsCyclotomicExtension
variable [NumberField K] [IsCyclotomicExtension {3} ℚ K]
/-- Given `S' : Solution'`, we have that `λ ^ 2` divides one amongst `S'.a + S'.b`,
`S'.a + η * S'.b` and `S'.a + η ^ 2 * S'.b`. -/
lemma lambda_sq_dvd_or_dvd_or_dvd :
λ ^ 2 ∣ S'.a + S'.b ∨ λ ^ 2 ∣ S'.a + η * S'.b ∨ λ ^ 2 ∣ S'.a + η ^ 2 * S'.b := by
by_contra! h
rcases h with ⟨h1, h2, h3⟩
rw [← emultiplicity_lt_iff_not_dvd] at h1 h2 h3
have h1' : FiniteMultiplicity (hζ.toInteger - 1) (S'.a + S'.b) :=
finiteMultiplicity_iff_emultiplicity_ne_top.2 (fun ht ↦ by simp [ht] at h1)
have h2' : FiniteMultiplicity (hζ.toInteger - 1) (S'.a + η * S'.b) := by
refine finiteMultiplicity_iff_emultiplicity_ne_top.2 (fun ht ↦ ?_)
rw [coe_eta] at ht
simp [ht] at h2
have h3' : FiniteMultiplicity (hζ.toInteger - 1) (S'.a + η ^ 2 * S'.b) := by
refine finiteMultiplicity_iff_emultiplicity_ne_top.2 (fun ht ↦ ?_)
rw [coe_eta] at ht
simp [ht] at h3
rw [h1'.emultiplicity_eq_multiplicity, Nat.cast_lt] at h1
rw [h2'.emultiplicity_eq_multiplicity, Nat.cast_lt] at h2
rw [h3'.emultiplicity_eq_multiplicity, Nat.cast_lt] at h3
have := (pow_dvd_pow_of_dvd (lambda_sq_dvd_c S') 3).mul_left S'.u
rw [← pow_mul, ← S'.H, a_cube_add_b_cube_eq_mul, pow_dvd_iff_le_emultiplicity,
emultiplicity_mul hζ.zeta_sub_one_prime', emultiplicity_mul hζ.zeta_sub_one_prime',
h1'.emultiplicity_eq_multiplicity, h2'.emultiplicity_eq_multiplicity,
h3'.emultiplicity_eq_multiplicity, ← Nat.cast_add, ← Nat.cast_add, Nat.cast_le] at this
cutsat
open Units in
/-- Given `S' : Solution'`, we may assume that `λ ^ 2` divides `S'.a + S'.b ∨ λ ^ 2` (see also the
result below). -/
lemma ex_cube_add_cube_eq_and_isCoprime_and_not_dvd_and_dvd :
∃ (a' b' : 𝓞 K), a' ^ 3 + b' ^ 3 = S'.u * S'.c ^ 3 ∧ IsCoprime a' b' ∧ ¬ λ ∣ a' ∧
¬ λ ∣ b' ∧ λ ^ 2 ∣ a' + b' := by
rcases lambda_sq_dvd_or_dvd_or_dvd S' with h | h | h
· exact ⟨S'.a, S'.b, S'.H, S'.coprime, S'.ha, S'.hb, h⟩
· refine ⟨S'.a, η * S'.b, ?_, ?_, S'.ha, fun ⟨x, hx⟩ ↦ S'.hb ⟨η ^ 2 * x, ?_⟩, h⟩
· simp [mul_pow, hζ.toInteger_cube_eq_one, one_mul, S'.H]
· refine (isCoprime_mul_unit_left_right (Units.isUnit η) _ _).2 S'.coprime
· rw [mul_comm _ x, ← mul_assoc, ← hx, mul_comm _ S'.b, mul_assoc, ← pow_succ', coe_eta,
hζ.toInteger_cube_eq_one, mul_one]
· refine ⟨S'.a, η ^ 2 * S'.b, ?_, ?_, S'.ha, fun ⟨x, hx⟩ ↦ S'.hb ⟨η * x, ?_⟩, h⟩
· rw [mul_pow, ← pow_mul, mul_comm 2, pow_mul, coe_eta, hζ.toInteger_cube_eq_one, one_pow,
one_mul, S'.H]
· exact (isCoprime_mul_unit_left_right ((Units.isUnit η).pow _) _ _).2 S'.coprime
· rw [mul_comm _ x, ← mul_assoc, ← hx, mul_comm _ S'.b, mul_assoc, ← pow_succ, coe_eta,
hζ.toInteger_cube_eq_one, mul_one]
/-- Given `S' : Solution'`, then there is `S₁ : Solution` such that
`S₁.multiplicity = S'.multiplicity`. -/
lemma exists_Solution_of_Solution' : ∃ (S₁ : Solution hζ), S₁.multiplicity = S'.multiplicity := by
obtain ⟨a, b, H, coprime, ha, hb, hab⟩ := ex_cube_add_cube_eq_and_isCoprime_and_not_dvd_and_dvd S'
exact ⟨
{ a := a
b := b
c := S'.c
u := S'.u
ha := ha
hb := hb
hc := S'.hc
coprime := coprime
hcdvd := S'.hcdvd
H := H
hab := hab }, rfl⟩
end IsCyclotomicExtension
namespace Solution
lemma a_add_eta_mul_b : S.a + η * S.b = (S.a + S.b) + λ * S.b := by rw [coe_eta]; ring
/-- Given `(S : Solution)`, we have that `λ ∣ (S.a + η * S.b)`. -/
lemma lambda_dvd_a_add_eta_mul_b : λ ∣ (S.a + η * S.b) :=
a_add_eta_mul_b S ▸ dvd_add (dvd_trans (dvd_pow_self _ (by decide)) S.hab) ⟨S.b, by rw [mul_comm]⟩
/-- Given `(S : Solution)`, we have that `λ ∣ (S.a + η ^ 2 * S.b)`. -/
lemma lambda_dvd_a_add_eta_sq_mul_b : λ ∣ (S.a + η ^ 2 * S.b) := by
rw [show S.a + η ^ 2 * S.b = (S.a + S.b) + λ ^ 2 * S.b + 2 * λ * S.b by rw [coe_eta]; ring]
exact dvd_add (dvd_add (dvd_trans (dvd_pow_self _ (by decide)) S.hab) ⟨λ * S.b, by ring⟩)
⟨2 * S.b, by ring⟩
section IsCyclotomicExtension
variable [NumberField K] [IsCyclotomicExtension {3} ℚ K]
/-- Given `(S : Solution)`, we have that `λ ^ 2` does not divide `S.a + η * S.b`. -/
lemma lambda_sq_not_dvd_a_add_eta_mul_b : ¬ λ ^ 2 ∣ (S.a + η * S.b) := by
simp_rw [a_add_eta_mul_b, dvd_add_right S.hab, pow_two, mul_dvd_mul_iff_left
hζ.zeta_sub_one_prime'.ne_zero, S.hb, not_false_eq_true]
/-- Given `(S : Solution)`, we have that `λ ^ 2` does not divide `S.a + η ^ 2 * S.b`. -/
lemma lambda_sq_not_dvd_a_add_eta_sq_mul_b : ¬ λ ^ 2 ∣ (S.a + η ^ 2 * S.b) := by
intro ⟨k, hk⟩
rcases S.hab with ⟨k', hk'⟩
refine S.hb ⟨(k - k') * (-η), ?_⟩
rw [show S.a + η ^ 2 * S.b = S.a + S.b - S.b + η ^ 2 * S.b by ring, hk',
show λ ^ 2 * k' - S.b + η ^ 2 * S.b = λ * (S.b * (η + 1) + λ * k') by rw [coe_eta]; ring,
pow_two, mul_assoc] at hk
simp only [mul_eq_mul_left_iff, hζ.zeta_sub_one_prime'.ne_zero, or_false] at hk
apply_fun (· * -↑η) at hk
rw [show (S.b * (η + 1) + λ * k') * -η = (-S.b) * (η ^ 2 + η + 1 - 1) - η * λ * k' by ring,
eta_sq, show -S.b * (-↑η - 1 + ↑η + 1 - 1) = S.b by ring, sub_eq_iff_eq_add] at hk
rw [hk]
ring
attribute [local instance] IsCyclotomicExtension.Rat.three_pid
attribute [local instance] UniqueFactorizationMonoid.toGCDMonoid
/-- If `p : 𝓞 K` is a prime that divides both `S.a + S.b` and `S.a + η * S.b`, then `p`
is associated with `λ`. -/
lemma associated_of_dvd_a_add_b_of_dvd_a_add_eta_mul_b {p : 𝓞 K} (hp : Prime p)
(hpab : p ∣ S.a + S.b) (hpaηb : p ∣ S.a + η * S.b) : Associated p λ := by
suffices p_lam : p ∣ λ from hp.associated_of_dvd hζ.zeta_sub_one_prime' p_lam
rw [← one_mul S.a, ← one_mul S.b] at hpab
rw [← one_mul S.a] at hpaηb
have := dvd_mul_sub_mul_mul_gcd_of_dvd hpab hpaηb
rwa [one_mul, one_mul, coe_eta, IsUnit.dvd_mul_right <| (gcd_isUnit_iff _ _).2 S.coprime] at this
/-- If `p : 𝓞 K` is a prime that divides both `S.a + S.b` and `S.a + η ^ 2 * S.b`, then `p`
is associated with `λ`. -/
lemma associated_of_dvd_a_add_b_of_dvd_a_add_eta_sq_mul_b {p : 𝓞 K} (hp : Prime p)
(hpab : p ∣ (S.a + S.b)) (hpaηsqb : p ∣ (S.a + η ^ 2 * S.b)) : Associated p λ := by
suffices p_lam : p ∣ λ from hp.associated_of_dvd hζ.zeta_sub_one_prime' p_lam
rw [← one_mul S.a, ← one_mul S.b] at hpab
rw [← one_mul S.a] at hpaηsqb
have := dvd_mul_sub_mul_mul_gcd_of_dvd hpab hpaηsqb
rw [one_mul, mul_one, IsUnit.dvd_mul_right <| (gcd_isUnit_iff _ _).2 S.coprime, ← dvd_neg] at this
convert dvd_mul_of_dvd_left this η using 1
rw [eta_sq, neg_sub, sub_mul, sub_mul, neg_mul, ← pow_two, eta_sq, coe_eta]
ring
/-- If `p : 𝓞 K` is a prime that divides both `S.a + η * S.b` and `S.a + η ^ 2 * S.b`, then `p`
is associated with `λ`. -/
lemma associated_of_dvd_a_add_eta_mul_b_of_dvd_a_add_eta_sq_mul_b {p : 𝓞 K} (hp : Prime p)
(hpaηb : p ∣ S.a + η * S.b) (hpaηsqb : p ∣ S.a + η ^ 2 * S.b) : Associated p λ := by
suffices p_lam : p ∣ λ from hp.associated_of_dvd hζ.zeta_sub_one_prime' p_lam
rw [← one_mul S.a] at hpaηb
rw [← one_mul S.a] at hpaηsqb
have := dvd_mul_sub_mul_mul_gcd_of_dvd hpaηb hpaηsqb
rw [one_mul, mul_one, IsUnit.dvd_mul_right <| (gcd_isUnit_iff _ _).2 S.coprime] at this
convert (dvd_mul_of_dvd_left (dvd_mul_of_dvd_left this η) η) using 1
symm
calc _ = (-η.1 - 1 - η) * (-η - 1) := by rw [eta_sq, mul_assoc, ← pow_two, eta_sq]
_ = 2 * η.1 ^ 2 + 3 * η + 1 := by ring
_ = λ := by rw [eta_sq, coe_eta]; ring
end IsCyclotomicExtension
/-- Given `S : Solution`, we let `S.y` be any element such that `S.a + η * S.b = λ * S.y` -/
private noncomputable def y := (lambda_dvd_a_add_eta_mul_b S).choose
private lemma y_spec : S.a + η * S.b = λ * S.y :=
(lambda_dvd_a_add_eta_mul_b S).choose_spec
/-- Given `S : Solution`, we let `S.z` be any element such that `S.a + η ^ 2 * S.b = λ * S.z` -/
private noncomputable def z := (lambda_dvd_a_add_eta_sq_mul_b S).choose
private lemma z_spec : S.a + η ^ 2 * S.b = λ * S.z :=
(lambda_dvd_a_add_eta_sq_mul_b S).choose_spec
variable [NumberField K] [IsCyclotomicExtension {3} ℚ K]
private lemma lambda_not_dvd_y : ¬ λ ∣ S.y := fun h ↦ by
replace h := mul_dvd_mul_left ((η : 𝓞 K) - 1) h
rw [coe_eta, ← y_spec, ← pow_two] at h
exact lambda_sq_not_dvd_a_add_eta_mul_b _ h
private lemma lambda_not_dvd_z : ¬ λ ∣ S.z := fun h ↦ by
replace h := mul_dvd_mul_left ((η : 𝓞 K) - 1) h
rw [coe_eta, ← z_spec, ← pow_two] at h
exact lambda_sq_not_dvd_a_add_eta_sq_mul_b _ h
/-- We have that `λ ^ (3*S.multiplicity-2)` divides `S.a + S.b`. -/
private lemma lambda_pow_dvd_a_add_b : λ ^ (3 * S.multiplicity - 2) ∣ S.a + S.b := by
have h : λ ^ S.multiplicity ∣ S.c := pow_multiplicity_dvd _ _
replace h : (λ ^ multiplicity S) ^ 3 ∣ S.u * S.c ^ 3 := by simp [h]
rw [← S.H, a_cube_add_b_cube_eq_mul, ← pow_mul, mul_comm, y_spec, z_spec] at h
apply hζ.zeta_sub_one_prime'.pow_dvd_of_dvd_mul_left _ S.lambda_not_dvd_z
apply hζ.zeta_sub_one_prime'.pow_dvd_of_dvd_mul_left _ S.lambda_not_dvd_y
have := S.two_le_multiplicity
rw [show 3 * multiplicity S = 3 * multiplicity S - 2 + 1 + 1 by cutsat, pow_succ, pow_succ,
show (S.a + S.b) * (λ * y S) * (λ * z S) = (S.a + S.b) * y S * z S * λ * λ by ring] at h
simp only [mul_dvd_mul_iff_right hζ.zeta_sub_one_prime'.ne_zero] at h
rwa [show (S.a + S.b) * y S * z S = y S * (z S * (S.a + S.b)) by ring] at h
/-- Given `S : Solution`, we let `S.x` be any element such that
`S.a + S.b = λ ^ (3*S.multiplicity-2) * S.x` -/
private noncomputable def x := (lambda_pow_dvd_a_add_b S).choose
private lemma x_spec : S.a + S.b = λ ^ (3 * S.multiplicity - 2) * S.x :=
(lambda_pow_dvd_a_add_b S).choose_spec
/-- Given `S : Solution`, we let `S.w` be any element such that `S.c = λ ^ S.multiplicity * S.w` -/
private noncomputable def w :=
(pow_multiplicity_dvd (hζ.toInteger - 1) S.c).choose
omit [NumberField K] [IsCyclotomicExtension {3} ℚ K] in
private lemma w_spec : S.c = λ ^ S.multiplicity * S.w :=
(pow_multiplicity_dvd (hζ.toInteger - 1) S.c).choose_spec
private lemma lambda_not_dvd_w : ¬ λ ∣ S.w := fun h ↦ by
refine S.toSolution'.multiplicity_lambda_c_finite.not_pow_dvd_of_multiplicity_lt
(lt_add_one S.multiplicity) ?_
rw [pow_succ', mul_comm]
exact S.w_spec ▸ (mul_dvd_mul_left (λ ^ S.multiplicity) h)
private lemma lambda_not_dvd_x : ¬ λ ∣ S.x := fun h ↦ by
replace h := mul_dvd_mul_left (λ ^ (3 * S.multiplicity - 2)) h
rw [mul_comm, ← x_spec] at h
replace h :=
mul_dvd_mul (mul_dvd_mul h S.lambda_dvd_a_add_eta_mul_b) S.lambda_dvd_a_add_eta_sq_mul_b
simp only [← a_cube_add_b_cube_eq_mul, S.H, w_spec, Units.isUnit, IsUnit.dvd_mul_left] at h
rw [← pow_succ', mul_comm, ← mul_assoc, ← pow_succ'] at h
have := S.two_le_multiplicity
rw [show 3 * multiplicity S - 2 + 1 + 1 = 3 * multiplicity S by cutsat, mul_pow, ← pow_mul,
mul_comm _ 3, mul_dvd_mul_iff_left _] at h
· exact lambda_not_dvd_w _ <| hζ.zeta_sub_one_prime'.dvd_of_dvd_pow h
· simp [hζ.zeta_sub_one_prime'.ne_zero]
attribute [local instance] IsCyclotomicExtension.Rat.three_pid
private lemma isCoprime_helper {r s t w : 𝓞 K} (hr : ¬ λ ∣ r) (hs : ¬ λ ∣ s)
(Hp : ∀ {p}, Prime p → p ∣ t → p ∣ w → Associated p λ) (H₁ : ∀ {q}, q ∣ r → q ∣ t)
(H₂ : ∀ {q}, q ∣ s → q ∣ w) : IsCoprime r s := by
refine isCoprime_of_prime_dvd (not_and.2 (fun _ hz ↦ hs (by simp [hz])))
(fun p hp p_dvd_r p_dvd_s ↦ hr ?_)
rwa [← Associated.dvd_iff_dvd_left <| Hp hp (H₁ p_dvd_r) (H₂ p_dvd_s)]
private lemma isCoprime_x_y : IsCoprime S.x S.y :=
isCoprime_helper (lambda_not_dvd_x S) (lambda_not_dvd_y S)
(associated_of_dvd_a_add_b_of_dvd_a_add_eta_mul_b S) (fun hq ↦ x_spec S ▸ hq.mul_left _)
(fun hq ↦ y_spec S ▸ hq.mul_left _)
private lemma isCoprime_x_z : IsCoprime S.x S.z :=
isCoprime_helper (lambda_not_dvd_x S) (lambda_not_dvd_z S)
(associated_of_dvd_a_add_b_of_dvd_a_add_eta_sq_mul_b S) (fun hq ↦ x_spec S ▸ hq.mul_left _)
(fun hq ↦ z_spec S ▸ hq.mul_left _)
private lemma isCoprime_y_z : IsCoprime S.y S.z :=
isCoprime_helper (lambda_not_dvd_y S) (lambda_not_dvd_z S)
(associated_of_dvd_a_add_eta_mul_b_of_dvd_a_add_eta_sq_mul_b S)
(fun hq ↦ y_spec S ▸ hq.mul_left _) (fun hq ↦ z_spec S ▸ hq.mul_left _)
private lemma x_mul_y_mul_z_eq_u_mul_w_cube : S.x * S.y * S.z = S.u * S.w ^ 3 := by
suffices hh : λ ^ (3 * S.multiplicity - 2) * S.x * λ * S.y * λ * S.z =
S.u * λ ^ (3 * S.multiplicity) * S.w ^ 3 by
rw [show λ ^ (3 * multiplicity S - 2) * x S * λ * y S * λ * z S =
λ ^ (3 * multiplicity S - 2) * λ * λ * x S * y S * z S by ring] at hh
have := S.two_le_multiplicity
rw [mul_comm _ (λ ^ (3 * multiplicity S)), ← pow_succ, ← pow_succ,
show 3 * multiplicity S - 2 + 1 + 1 = 3 * multiplicity S by cutsat, mul_assoc, mul_assoc,
mul_assoc] at hh
simp only [mul_eq_mul_left_iff, pow_eq_zero_iff', hζ.zeta_sub_one_prime'.ne_zero, ne_eq,
mul_eq_zero, OfNat.ofNat_ne_zero, false_or, false_and, or_false] at hh
convert hh using 1
ring
simp only [← x_spec, mul_assoc, ← y_spec, ← z_spec]
rw [mul_comm 3, pow_mul, ← mul_pow, ← w_spec, ← S.H, a_cube_add_b_cube_eq_mul]
ring
private lemma exists_cube_associated :
(∃ X, Associated (X ^ 3) S.x) ∧ (∃ Y, Associated (Y ^ 3) S.y) ∧
∃ Z, Associated (Z ^ 3) S.z := by classical
have h₁ := S.isCoprime_x_z.mul_left S.isCoprime_y_z
have h₂ : Associated (S.w ^ 3) (S.x * S.y * S.z) :=
⟨S.u, by rw [x_mul_y_mul_z_eq_u_mul_w_cube S, mul_comm]⟩
obtain ⟨T, h₃⟩ := exists_associated_pow_of_associated_pow_mul h₁ h₂
exact ⟨exists_associated_pow_of_associated_pow_mul S.isCoprime_x_y h₃,
exists_associated_pow_of_associated_pow_mul S.isCoprime_x_y.symm (mul_comm _ S.x ▸ h₃),
exists_associated_pow_of_associated_pow_mul h₁.symm (mul_comm _ S.z ▸ h₂)⟩
/-- Given `S : Solution`, we let `S.u₁` and `S.X` be any elements such that
`S.X ^ 3 * S.u₁ = S.x` -/
private noncomputable def X := (exists_cube_associated S).1.choose
private noncomputable def u₁ := (exists_cube_associated S).1.choose_spec.choose
private lemma X_u₁_spec : S.X ^ 3 * S.u₁ = S.x :=
(exists_cube_associated S).1.choose_spec.choose_spec
/-- Given `S : Solution`, we let `S.u₂` and `S.Y` be any elements such that
`S.Y ^ 3 * S.u₂ = S.y` -/
private noncomputable def Y := (exists_cube_associated S).2.1.choose
private noncomputable def u₂ := (exists_cube_associated S).2.1.choose_spec.choose
private lemma Y_u₂_spec : S.Y ^ 3 * S.u₂ = S.y :=
(exists_cube_associated S).2.1.choose_spec.choose_spec
/-- Given `S : Solution`, we let `S.u₃` and `S.Z` be any elements such that
`S.Z ^ 3 * S.u₃ = S.z` -/
private noncomputable def Z := (exists_cube_associated S).2.2.choose
private noncomputable def u₃ := (exists_cube_associated S).2.2.choose_spec.choose
private lemma Z_u₃_spec : S.Z ^ 3 * S.u₃ = S.z :=
(exists_cube_associated S).2.2.choose_spec.choose_spec
private lemma X_ne_zero : S.X ≠ 0 :=
fun h ↦ lambda_not_dvd_x S <| by simp [← X_u₁_spec, h]
private lemma lambda_not_dvd_X : ¬ λ ∣ S.X :=
fun h ↦ lambda_not_dvd_x S <| X_u₁_spec S ▸ dvd_mul_of_dvd_left (dvd_pow h (by decide)) _
private lemma lambda_not_dvd_Y : ¬ λ ∣ S.Y :=
fun h ↦ lambda_not_dvd_y S <| Y_u₂_spec S ▸ dvd_mul_of_dvd_left (dvd_pow h (by decide)) _
private lemma lambda_not_dvd_Z : ¬ λ ∣ S.Z :=
fun h ↦ lambda_not_dvd_z S <| Z_u₃_spec S ▸ dvd_mul_of_dvd_left (dvd_pow h (by decide)) _
private lemma isCoprime_Y_Z : IsCoprime S.Y S.Z := by
rw [← IsCoprime.pow_iff (m := 3) (n := 3) (by decide) (by decide),
← isCoprime_mul_unit_right_left S.u₂.isUnit, ← isCoprime_mul_unit_right_right S.u₃.isUnit,
Y_u₂_spec, Z_u₃_spec]
exact isCoprime_y_z S
-- This is just a computation and the formulas are too long.
set_option linter.style.commandStart false in
private lemma formula1 : S.X^3*S.u₁*λ^(3*S.multiplicity-2)+S.Y^3*S.u₂*λ*η+S.Z^3*S.u₃*λ*η^2 = 0 := by
rw [X_u₁_spec, Y_u₂_spec, Z_u₃_spec, mul_comm S.x, ← x_spec, mul_comm S.y, ← y_spec, mul_comm S.z,
← z_spec, eta_sq]
calc _ = S.a+S.b+η^2*S.b-S.a+η^2*S.b+2*η*S.b+S.b := by ring
_ = 0 := by rw [eta_sq]; ring
/-- Let `u₄ := η * S.u₃ * S.u₂⁻¹` -/
private noncomputable def u₄ := η * S.u₃ * S.u₂⁻¹
private lemma u₄_def : S.u₄ = η * S.u₃ * S.u₂⁻¹ := rfl
/-- Let `u₅ := -η ^ 2 * S.u₁ * S.u₂⁻¹` -/
private noncomputable def u₅ := -η ^ 2 * S.u₁ * S.u₂⁻¹
private lemma u₅_def : S.u₅ = -η ^ 2 * S.u₁ * S.u₂⁻¹ := rfl
example (a b : 𝓞 K) (ha : a ≠ 0) (hb : b ≠ 0) : a * b ≠ 0 := by
exact mul_ne_zero ha hb
-- This is just a computation and the formulas are too long.
set_option linter.style.commandStart false in
private lemma formula2 :
S.Y ^ 3 + S.u₄ * S.Z ^ 3 = S.u₅ * (λ ^ (S.multiplicity - 1) * S.X) ^ 3 := by
rw [u₅_def, neg_mul, neg_mul, Units.val_neg, neg_mul, eq_neg_iff_add_eq_zero, add_assoc,
add_comm (S.u₄ * S.Z ^ 3), ← add_assoc, add_comm (S.Y ^ 3)]
apply mul_right_cancel₀ <| mul_ne_zero
(mul_ne_zero hζ.zeta_sub_one_prime'.ne_zero S.u₂.isUnit.ne_zero) (Units.isUnit η).ne_zero
simp only [zero_mul, add_mul]
rw [← formula1 S]
congrm ?_ + ?_ + ?_
· have : (S.multiplicity-1)*3+1 = 3*S.multiplicity-2 := by have := S.two_le_multiplicity; omega
calc _ = S.X^3 *(S.u₂*S.u₂⁻¹)*(η^3*S.u₁)*(λ^((S.multiplicity-1)*3)*λ) := by push_cast; ring
_ = S.X^3*S.u₁*λ^(3*S.multiplicity-2) := by simp [hζ.toInteger_cube_eq_one, ← pow_succ, this]
· ring
· simp only [u₄_def, inv_eq_one_div, mul_div_assoc', mul_one, val_div_eq_divp, Units.val_mul,
IsUnit.unit_spec, divp_mul_eq_mul_divp, divp_eq_iff_mul_eq]
ring
-- This is just a computation and the formulas are too long.
set_option linter.style.commandStart false in
private lemma lambda_sq_div_u₅_mul : λ ^ 2 ∣ S.u₅ * (λ ^ (S.multiplicity - 1) * S.X) ^ 3 := by
use λ^(3*S.multiplicity-5)*S.u₅*(S.X^3)
have : 3*(S.multiplicity-1) = 2+(3*S.multiplicity-5) := by have := S.two_le_multiplicity; omega
calc _ = λ^(3*(S.multiplicity-1))*S.u₅*S.X^3 := by ring
_ = λ^2*λ^(3*S.multiplicity-5)*S.u₅*S.X^3 := by rw [this, pow_add]
_ = λ^2*(λ^(3*S.multiplicity-5)*S.u₅*S.X^3) := by ring
private lemma u₄_eq_one_or_neg_one : S.u₄ = 1 ∨ S.u₄ = -1 := by
have : λ ^ 2 ∣ λ ^ 4 := ⟨λ ^ 2, by ring⟩
have h := S.lambda_sq_div_u₅_mul
apply IsCyclotomicExtension.Rat.Three.eq_one_or_neg_one_of_unit_of_congruent hζ
rcases h with ⟨X, hX⟩
rcases lambda_pow_four_dvd_cube_sub_one_or_add_one_of_lambda_not_dvd hζ S.lambda_not_dvd_Y with
HY | HY <;> rcases lambda_pow_four_dvd_cube_sub_one_or_add_one_of_lambda_not_dvd
hζ S.lambda_not_dvd_Z with HZ | HZ <;> replace HY := this.trans HY <;> replace HZ :=
this.trans HZ <;> rcases HY with ⟨Y, hY⟩ <;> rcases HZ with ⟨Z, hZ⟩
· refine ⟨-1, X - Y - S.u₄ * Z, ?_⟩
rw [show λ ^ 2 * (X - Y - S.u₄ * Z) = λ ^ 2 * X - λ ^ 2 * Y - S.u₄ * (λ ^ 2 * Z) by ring,
← hX, ← hY, ← hZ, ← formula2]
ring
· refine ⟨1, -X + Y + S.u₄ * Z, ?_⟩
rw [show λ ^ 2 * (-X + Y + S.u₄ * Z) = -(λ ^ 2 * X - λ ^ 2 * Y - S.u₄ * (λ ^ 2 * Z)) by ring,
← hX, ← hY, ← hZ, ← formula2]
ring
· refine ⟨1, X - Y - S.u₄ * Z, ?_⟩
rw [show λ ^ 2 * (X - Y - S.u₄ * Z) = λ ^ 2 * X - λ ^ 2 * Y - S.u₄ * (λ ^ 2 * Z) by ring,
← hX, ← hY, ← hZ, ← formula2]
ring
· refine ⟨-1, -X + Y + S.u₄ * Z, ?_⟩
rw [show λ ^ 2 * (-X + Y + S.u₄ * Z) = -(λ ^ 2 * X - λ ^ 2 * Y - S.u₄ * (λ ^ 2 * Z)) by ring,
← hX, ← hY, ← hZ, ← formula2]
ring
private lemma u₄_sq : S.u₄ ^ 2 = 1 := by
rcases S.u₄_eq_one_or_neg_one with h | h <;> simp [h]
/-- Given `S : Solution`, we have that
`S.Y ^ 3 + (S.u₄ * S.Z) ^ 3 = S.u₅ * (λ ^ (S.multiplicity - 1) * S.X) ^ 3`. -/
private lemma formula3 :
S.Y ^ 3 + (S.u₄ * S.Z) ^ 3 = S.u₅ * (λ ^ (S.multiplicity - 1) * S.X) ^ 3 :=
calc S.Y ^ 3 + (S.u₄ * S.Z) ^ 3 = S.Y ^ 3 + S.u₄ ^ 2 * S.u₄ * S.Z ^ 3 := by ring
_ = S.Y ^ 3 + S.u₄ * S.Z ^ 3 := by simp [← Units.val_pow_eq_pow_val, S.u₄_sq]
_ = S.u₅ * (λ ^ (S.multiplicity - 1) * S.X) ^ 3 := S.formula2
/-- Given `S : Solution`, we construct `S₁ : Solution'`, with smaller multiplicity of `λ` in
`c` (see `Solution'_descent_multiplicity_lt` below.). -/
noncomputable def Solution'_descent : Solution' hζ where
a := S.Y
b := S.u₄ * S.Z
c := λ ^ (S.multiplicity - 1) * S.X
u := S.u₅
ha := S.lambda_not_dvd_Y
hb := fun h ↦ S.lambda_not_dvd_Z <| Units.dvd_mul_left.1 h
hc := fun h ↦ S.X_ne_zero <| by simpa [hζ.zeta_sub_one_prime'.ne_zero] using h
coprime := (isCoprime_mul_unit_left_right S.u₄.isUnit _ _).2 S.isCoprime_Y_Z
hcdvd := by
refine dvd_mul_of_dvd_left (dvd_pow_self _ (fun h ↦ ?_)) _
rw [Nat.sub_eq_iff_eq_add (le_trans (by simp) S.two_le_multiplicity), zero_add] at h
simpa [h] using S.two_le_multiplicity
H := formula3 S
/-- We have that `S.Solution'_descent.multiplicity = S.multiplicity - 1`. -/
lemma Solution'_descent_multiplicity : S.Solution'_descent.multiplicity = S.multiplicity - 1 := by
refine multiplicity_eq_of_dvd_of_not_dvd
(by simp [Solution'_descent]) (fun h ↦ S.lambda_not_dvd_X ?_)
obtain ⟨k, hk : λ ^ (S.multiplicity - 1) * S.X = λ ^ (S.multiplicity - 1 + 1) * k⟩ := h
rw [pow_succ, mul_assoc] at hk
simp only [mul_eq_mul_left_iff, pow_eq_zero_iff', hζ.zeta_sub_one_prime'.ne_zero, ne_eq,
false_and, or_false] at hk
simp [hk]
/-- We have that `S.Solution'_descent.multiplicity < S.multiplicity`. -/
lemma Solution'_descent_multiplicity_lt :
(Solution'_descent S).multiplicity < S.multiplicity := by
rw [Solution'_descent_multiplicity S, Nat.sub_one]
exact Nat.pred_lt <| by have := S.two_le_multiplicity; cutsat
/-- Given any `S : Solution`, there is another `S₁ : Solution` such that
`S₁.multiplicity < S.multiplicity` -/
theorem exists_Solution_multiplicity_lt :
∃ S₁ : Solution hζ, S₁.multiplicity < S.multiplicity := by classical
obtain ⟨S', hS'⟩ := exists_Solution_of_Solution' (Solution'_descent S)
exact ⟨S', hS' ▸ Solution'_descent_multiplicity_lt S⟩
end Solution
end FermatLastTheoremForThreeGen
end eisenstein
end case2
/-- Fermat's Last Theorem for `n = 3`: if `a b c : ℕ` are all non-zero then
`a ^ 3 + b ^ 3 ≠ c ^ 3`. -/
theorem fermatLastTheoremThree : FermatLastTheoremFor 3 := by
classical
let K := CyclotomicField 3 ℚ
let hζ := IsCyclotomicExtension.zeta_spec 3 ℚ K
have : NumberField K := IsCyclotomicExtension.numberField {3} ℚ _
apply FermatLastTheoremForThree_of_FermatLastTheoremThreeGen hζ
intro a b c u hc ha hb hcdvd coprime H
let S' : FermatLastTheoremForThreeGen.Solution' hζ :=
{ a := a
b := b
c := c
u := u
ha := ha
hb := hb
hc := hc
coprime := coprime
hcdvd := hcdvd
H := H }
obtain ⟨S, -⟩ := FermatLastTheoremForThreeGen.exists_Solution_of_Solution' S'
obtain ⟨Smin, hSmin⟩ := S.exists_minimal
obtain ⟨Sfin, hSfin⟩ := Smin.exists_Solution_multiplicity_lt
linarith [hSmin Sfin] |
.lake/packages/mathlib/Mathlib/NumberTheory/FLT/Polynomial.lean | import Mathlib.Algebra.Polynomial.Expand
import Mathlib.Algebra.GroupWithZero.Defs
import Mathlib.NumberTheory.FLT.Basic
import Mathlib.NumberTheory.FLT.MasonStothers
import Mathlib.RingTheory.Polynomial.Content
import Mathlib.Tactic.GCongr
/-!
# Fermat's Last Theorem for polynomials over a field
This file states and proves the Fermat's Last Theorem for polynomials over a field.
For `n ≥ 3` not divisible by the characteristic of the coefficient field `k` and (pairwise) nonzero
coprime polynomials `a, b, c` (over a field) with `a ^ n + b ^ n = c ^ n`,
all polynomials must be constants.
More generally, we can prove non-solvability of the Fermat-Catalan equation: there are no
non-constant polynomial solutions to the equation `u * a ^ p + v * b ^ q + w * c ^ r = 0`, where
`p, q, r ≥ 3` with `p * q + q * r + r * p ≤ p * q * r`, `p, q, r` not divisible by `char k`,
and `u, v, w` are nonzero elements in `k`.
FLT is the special case where `p = q = r = n`, `u = v = 1`, and `w = -1`.
The proof uses the Mason-Stothers theorem (Polynomial ABC theorem) and infinite descent
(in the characteristic p case).
-/
open Polynomial UniqueFactorizationMonoid
variable {k R : Type*} [Field k] [CommRing R] [IsDomain R] [NormalizationMonoid R]
[UniqueFactorizationMonoid R]
private lemma Ne.isUnit_C {u : k} (hu : u ≠ 0) : IsUnit (C u) :=
Polynomial.isUnit_C.mpr hu.isUnit
-- auxiliary lemma that 'rotates' coprimality
private lemma rot_coprime
{p q r : ℕ} {a b c : k[X]} {u v w : k}
{hp : p ≠ 0} {hq : q ≠ 0} {hr : r ≠ 0}
{hu : u ≠ 0} {hv : v ≠ 0} {hw : w ≠ 0}
(heq : C u * a ^ p + C v * b ^ q + C w * c ^ r = 0) (hab : IsCoprime a b) : IsCoprime b c := by
have hCu : IsUnit (C u) := hu.isUnit_C
have hCv : IsUnit (C v) := hv.isUnit_C
have hCw : IsUnit (C w) := hw.isUnit_C
rw [← IsCoprime.pow_iff hp.bot_lt hq.bot_lt, ← isCoprime_mul_units_left hCu hCv] at hab
rw [add_eq_zero_iff_neg_eq] at heq
rw [← IsCoprime.pow_iff hq.bot_lt hr.bot_lt, ← isCoprime_mul_units_left hCv hCw,
← heq, IsCoprime.neg_right_iff]
convert IsCoprime.add_mul_left_right hab.symm 1 using 2
rw [mul_one]
private lemma ineq_pqr_contradiction {p q r a b c : ℕ}
(hp : p ≠ 0) (hq : q ≠ 0) (hr : r ≠ 0)
(hineq : q * r + r * p + p * q ≤ p * q * r)
(hpa : p * a < a + b + c)
(hqb : q * b < a + b + c)
(hrc : r * c < a + b + c) : False := by
suffices h : p * q * r * (a + b + c) + 1 ≤ p * q * r * (a + b + c) by simp at h
calc
_ = (p * a) * (q * r) + (q * b) * (r * p) + (r * c) * (p * q) + 1 := by ring
_ ≤ (a + b + c) * (q * r) + (a + b + c) * (r * p) + (a + b + c) * (p * q) := by
rw [Nat.succ_le]
gcongr
_ = (q * r + r * p + p * q) * (a + b + c) := by ring
_ ≤ _ := by gcongr
private theorem Polynomial.flt_catalan_deriv
{p q r : ℕ} (hp : p ≠ 0) (hq : q ≠ 0) (hr : r ≠ 0)
(hineq : q * r + r * p + p * q ≤ p * q * r)
(chp : (p : k) ≠ 0) (chq : (q : k) ≠ 0) (chr : (r : k) ≠ 0)
{a b c : k[X]} (ha : a ≠ 0) (hb : b ≠ 0) (hc : c ≠ 0)
(hab : IsCoprime a b) {u v w : k} (hu : u ≠ 0) (hv : v ≠ 0) (hw : w ≠ 0)
(heq : C u * a ^ p + C v * b ^ q + C w * c ^ r = 0) :
derivative a = 0 ∧ derivative b = 0 ∧ derivative c = 0 := by
have hbc : IsCoprime b c := by apply rot_coprime heq <;> assumption
have hca : IsCoprime c a := by
rw [add_rotate] at heq; apply rot_coprime heq <;> assumption
have hCu := C_ne_zero.mpr hu
have hCv := C_ne_zero.mpr hv
have hCw := C_ne_zero.mpr hw
have hap := pow_ne_zero p ha
have hbq := pow_ne_zero q hb
have hcr := pow_ne_zero r hc
have habp : IsCoprime (C u * a ^ p) (C v * b ^ q) := by
rw [isCoprime_mul_units_left hu.isUnit_C hv.isUnit_C]; exact hab.pow
have hbcp : IsCoprime (C v * b ^ q) (C w * c ^ r) := by
rw [isCoprime_mul_units_left hv.isUnit_C hw.isUnit_C]; exact hbc.pow
have hcap : IsCoprime (C w * c ^ r) (C u * a ^ p) := by
rw [isCoprime_mul_units_left hw.isUnit_C hu.isUnit_C]; exact hca.pow
have habcp := hcap.symm.mul_left hbcp
-- Use Mason-Stothers theorem
classical
rcases Polynomial.abc
(mul_ne_zero hCu hap) (mul_ne_zero hCv hbq) (mul_ne_zero hCw hcr)
habp heq with nd_lt | dr0
· simp_rw [radical_mul habcp.isRelPrime, radical_mul habp.isRelPrime,
radical_mul_of_isUnit_left hu.isUnit_C,
radical_mul_of_isUnit_left hv.isUnit_C,
radical_mul_of_isUnit_left hw.isUnit_C,
radical_pow a hp, radical_pow b hq, radical_pow c hr,
natDegree_mul hCu hap,
natDegree_mul hCv hbq,
natDegree_mul hCw hcr,
natDegree_C, natDegree_pow, zero_add,
← radical_mul hab.isRelPrime,
← radical_mul (hca.symm.mul_left hbc).isRelPrime] at nd_lt
obtain ⟨hpa', hqb', hrc'⟩ := nd_lt
have hpa := hpa'.trans natDegree_radical_le
have hqb := hqb'.trans natDegree_radical_le
have hrc := hrc'.trans natDegree_radical_le
rw [natDegree_mul (mul_ne_zero ha hb) hc,
natDegree_mul ha hb, Nat.add_one_le_iff] at hpa hqb hrc
exfalso
exact (ineq_pqr_contradiction hp hq hr hineq hpa hqb hrc)
· rw [derivative_C_mul, derivative_C_mul, derivative_C_mul,
mul_eq_zero_iff_left (C_ne_zero.mpr hu),
mul_eq_zero_iff_left (C_ne_zero.mpr hv),
mul_eq_zero_iff_left (C_ne_zero.mpr hw),
derivative_pow_eq_zero chp,
derivative_pow_eq_zero chq,
derivative_pow_eq_zero chr] at dr0
exact dr0
-- helper lemma that gives a baggage of small facts on `contract (ringChar k) a`
private lemma find_contract {a : k[X]}
(ha : a ≠ 0) (hda : derivative a = 0) (chn0 : ringChar k ≠ 0) :
∃ ca, ca ≠ 0 ∧
a = expand k (ringChar k) ca ∧
a.natDegree = ca.natDegree * ringChar k := by
have heq := (expand_contract (ringChar k) hda chn0).symm
refine ⟨contract (ringChar k) a, ?_, heq, ?_⟩
· intro h
rw [h, map_zero] at heq
exact ha heq
· rw [← natDegree_expand, ← heq]
private theorem Polynomial.flt_catalan_aux
{p q r : ℕ} {a b c : k[X]} {u v w : k}
(heq : C u * a ^ p + C v * b ^ q + C w * c ^ r = 0)
(hp : p ≠ 0) (hq : q ≠ 0) (hr : r ≠ 0)
(hineq : q * r + r * p + p * q ≤ p * q * r)
(chp : (p : k) ≠ 0) (chq : (q : k) ≠ 0) (chr : (r : k) ≠ 0)
(ha : a ≠ 0) (hb : b ≠ 0) (hc : c ≠ 0) (hab : IsCoprime a b)
(hu : u ≠ 0) (hv : v ≠ 0) (hw : w ≠ 0) :
a.natDegree = 0 := by
rcases eq_or_ne (ringChar k) 0 with ch0 | chn0
-- characteristic zero
· obtain ⟨da, -, -⟩ := flt_catalan_deriv
hp hq hr hineq chp chq chr ha hb hc hab hu hv hw heq
have czk : CharZero k := by
apply charZero_of_inj_zero
intro n
rw [ringChar.spec, ch0]
exact zero_dvd_iff.mp
rw [eq_C_of_derivative_eq_zero da]
exact natDegree_C _
-- characteristic p > 0
· generalize eq_d : a.natDegree = d
-- set up infinite descent
-- strong induct on `d := a.natDegree`
induction d
using Nat.case_strong_induction_on
generalizing a b c ha hb hc hab heq with
| hz => rfl
| hi d ih_d => -- have derivatives of `a, b, c` zero
obtain ⟨ad, bd, cd⟩ := flt_catalan_deriv
hp hq hr hineq chp chq chr ha hb hc hab hu hv hw heq
-- find contracts `ca, cb, cc` so that `a(k) = ca(k^ch)`
obtain ⟨ca, ca_nz, eq_a, eq_deg_a⟩ := find_contract ha ad chn0
obtain ⟨cb, cb_nz, eq_b, eq_deg_b⟩ := find_contract hb bd chn0
obtain ⟨cc, cc_nz, eq_c, eq_deg_c⟩ := find_contract hc cd chn0
set ch := ringChar k
suffices hca : ca.natDegree = 0 by
rw [← eq_d, eq_deg_a, hca, zero_mul]
by_contra hnca; apply hnca
apply ih_d _ _ _ ca_nz cb_nz cc_nz <;> clear ih_d <;> try rfl
· apply (isCoprime_expand chn0).mp
rwa [← eq_a, ← eq_b]
· have _ : ch ≠ 1 := CharP.ringChar_ne_one
have hch2 : 2 ≤ ch := by omega
rw [← add_le_add_iff_right 1, ← eq_d, eq_deg_a]
grw [← hch2]
cutsat
· rw [eq_a, eq_b, eq_c, ← expand_C ch u, ← expand_C ch v, ← expand_C ch w] at heq
simp_rw [← map_pow, ← map_mul, ← map_add] at heq
rwa [Polynomial.expand_eq_zero (zero_lt_iff.mpr chn0)] at heq
/-- Nonsolvability of the Fermat-Catalan equation. -/
theorem Polynomial.flt_catalan
{p q r : ℕ} (hp : p ≠ 0) (hq : q ≠ 0) (hr : r ≠ 0)
(hineq : q * r + r * p + p * q ≤ p * q * r)
(chp : (p : k) ≠ 0) (chq : (q : k) ≠ 0) (chr : (r : k) ≠ 0)
{a b c : k[X]} (ha : a ≠ 0) (hb : b ≠ 0) (hc : c ≠ 0) (hab : IsCoprime a b)
{u v w : k} (hu : u ≠ 0) (hv : v ≠ 0) (hw : w ≠ 0)
(heq : C u * a ^ p + C v * b ^ q + C w * c ^ r = 0) :
a.natDegree = 0 ∧ b.natDegree = 0 ∧ c.natDegree = 0 := by
-- WLOG argument: essentially three times flt_catalan_aux
have hbc : IsCoprime b c := by
apply rot_coprime heq hab <;> assumption
have heq' : C v * b ^ q + C w * c ^ r + C u * a ^ p = 0 := by
rwa [add_rotate] at heq
have hca : IsCoprime c a := by
apply rot_coprime heq' hbc <;> assumption
refine ⟨?_, ?_, ?_⟩
· apply flt_catalan_aux heq <;> assumption
· rw [add_rotate] at heq hineq
rw [mul_rotate] at hineq
apply flt_catalan_aux heq <;> assumption
· rw [← add_rotate] at heq hineq
rw [← mul_rotate] at hineq
apply flt_catalan_aux heq <;> assumption
theorem Polynomial.flt
{n : ℕ} (hn : 3 ≤ n) (chn : (n : k) ≠ 0)
{a b c : k[X]} (ha : a ≠ 0) (hb : b ≠ 0) (hc : c ≠ 0)
(hab : IsCoprime a b) (heq : a ^ n + b ^ n = c ^ n) :
a.natDegree = 0 ∧ b.natDegree = 0 ∧ c.natDegree = 0 := by
have hn' : 0 < n := by linarith
rw [← sub_eq_zero, ← one_mul (a ^ n), ← one_mul (b ^ n), ← one_mul (c ^ n), sub_eq_add_neg,
← neg_mul] at heq
have hone : (1 : k[X]) = C 1 := by rfl
have hneg_one : (-1 : k[X]) = C (-1) := by simp only [map_neg, map_one]
simp_rw [hneg_one, hone] at heq
apply flt_catalan hn'.ne' hn'.ne' hn'.ne' _
chn chn chn ha hb hc hab one_ne_zero one_ne_zero (neg_ne_zero.mpr one_ne_zero) heq
have eq_lhs : n * n + n * n + n * n = 3 * n * n := by ring
rw [eq_lhs, mul_assoc, mul_assoc]
exact Nat.mul_le_mul_right (n * n) hn
theorem fermatLastTheoremWith'_polynomial {n : ℕ} (hn : 3 ≤ n) (chn : (n : k) ≠ 0) :
FermatLastTheoremWith' k[X] n := by
classical
rw [FermatLastTheoremWith']
intro a b c ha hb hc heq
obtain ⟨a', eq_a⟩ := gcd_dvd_left a b
obtain ⟨b', eq_b⟩ := gcd_dvd_right a b
set d := gcd a b
have hd : d ≠ 0 := gcd_ne_zero_of_left ha
rw [eq_a, eq_b, mul_pow, mul_pow, ← mul_add] at heq
have hdc : d ∣ c := by
-- TODO: This is basically reproving `IsIntegrallyClosed.pow_dvd_pow_iff`
have hn : 0 < n := by omega
have hdncn : d ^ n ∣ c ^ n := ⟨_, heq.symm⟩
simpa [dvd_iff_normalizedFactors_le_normalizedFactors, Multiset.le_iff_count, *] using hdncn
obtain ⟨c', eq_c⟩ := hdc
rw [eq_a, mul_ne_zero_iff] at ha
rw [eq_b, mul_ne_zero_iff] at hb
rw [eq_c, mul_ne_zero_iff] at hc
rw [mul_comm] at eq_a eq_b eq_c
refine ⟨d, a', b', c', ⟨eq_a, eq_b, eq_c⟩, ?_⟩
rw [eq_c, mul_pow, mul_comm, mul_left_inj' (pow_ne_zero n hd)] at heq
suffices goal : a'.natDegree = 0 ∧ b'.natDegree = 0 ∧ c'.natDegree = 0 by
simp only [natDegree_eq_zero] at goal
obtain ⟨⟨ca', ha'⟩, ⟨cb', hb'⟩, ⟨cc', hc'⟩⟩ := goal
rw [← ha', ← hb', ← hc']
rw [← ha', C_ne_zero] at ha
rw [← hb', C_ne_zero] at hb
rw [← hc', C_ne_zero] at hc
exact ⟨ha.right.isUnit_C, hb.right.isUnit_C, hc.right.isUnit_C⟩
apply flt hn chn ha.right hb.right hc.right _ heq
convert isCoprime_div_gcd_div_gcd _
· exact EuclideanDomain.eq_div_of_mul_eq_left ha.left eq_a.symm
· exact EuclideanDomain.eq_div_of_mul_eq_left ha.left eq_b.symm
· rw [eq_b]
exact mul_ne_zero hb.right hb.left |
.lake/packages/mathlib/Mathlib/NumberTheory/Transcendental/Liouville/Basic.lean | import Mathlib.Algebra.Polynomial.DenomsClearable
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Analysis.Calculus.Deriv.Polynomial
import Mathlib.NumberTheory.Real.Irrational
import Mathlib.Topology.Algebra.Polynomial
/-!
# Liouville's theorem
This file contains a proof of Liouville's theorem stating that all Liouville numbers are
transcendental.
To obtain this result, there is first a proof that Liouville numbers are irrational and two
technical lemmas. These lemmas exploit the fact that a polynomial with integer coefficients
takes integer values at integers. When evaluating at a rational number, we can clear denominators
and obtain precise inequalities that ultimately allow us to prove transcendence of
Liouville numbers.
-/
/-- A Liouville number is a real number `x` such that for every natural number `n`, there exist
`a, b ∈ ℤ` with `1 < b` such that `0 < |x - a/b| < 1/bⁿ`.
In the implementation, the condition `x ≠ a/b` replaces the traditional equivalent `0 < |x - a/b|`.
-/
def Liouville (x : ℝ) :=
∀ n : ℕ, ∃ a b : ℤ, 1 < b ∧ x ≠ a / b ∧ |x - a / b| < 1 / (b : ℝ) ^ n
namespace Liouville
protected theorem irrational {x : ℝ} (h : Liouville x) : Irrational x := by
-- By contradiction, `x = a / b`, with `a ∈ ℤ`, `0 < b ∈ ℕ` is a Liouville number,
rintro ⟨⟨a, b, bN0, cop⟩, rfl⟩
-- clear up the mess of constructions of rationals
rw [Rat.cast_mk'] at h
-- Since `a / b` is a Liouville number, there are `p, q ∈ ℤ`, with `q1 : 1 < q`,∈
-- `a0 : a / b ≠ p / q` and `a1 : |a / b - p / q| < 1 / q ^ (b + 1)`
rcases h (b + 1) with ⟨p, q, q1, a0, a1⟩
-- A few useful inequalities
have qR0 : (0 : ℝ) < q := Int.cast_pos.mpr (zero_lt_one.trans q1)
have b0 : (b : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr bN0
have bq0 : (0 : ℝ) < b * q := mul_pos (Nat.cast_pos.mpr bN0.bot_lt) qR0
-- At a1, clear denominators...
replace a1 : |a * q - b * p| * q ^ (b + 1) < b * q := by
rw [div_sub_div _ _ b0 qR0.ne', abs_div, div_lt_div_iff₀ (abs_pos.mpr bq0.ne') (pow_pos qR0 _),
abs_of_pos bq0, one_mul] at a1
exact mod_cast a1
-- At a0, clear denominators...
replace a0 : a * q - ↑b * p ≠ 0 := by
rw [Ne, div_eq_div_iff b0 qR0.ne', mul_comm (p : ℝ), ← sub_eq_zero] at a0
exact mod_cast a0
-- Actually, `q` is a natural number
lift q to ℕ using (zero_lt_one.trans q1).le
-- Looks innocuous, but we now have an integer with non-zero absolute value: this is at
-- least one away from zero. The gain here is what gets the proof going.
have ap : 0 < |a * ↑q - ↑b * p| := abs_pos.mpr a0
-- Actually, the absolute value of an integer is a natural number
-- FIXME: This `lift` call duplicates the hypotheses `a1` and `ap`
lift |a * ↑q - ↑b * p| to ℕ using abs_nonneg (a * ↑q - ↑b * p) with e he
norm_cast at a1 ap q1
-- Recall this is by contradiction: we obtained the inequality `b * q ≤ x * q ^ (b + 1)`, so
-- we are done.
exact not_le.mpr a1 (Nat.mul_lt_mul_pow_succ ap q1).le
open Polynomial Metric Set Real RingHom
open scoped Polynomial
/-- Let `Z, N` be types, let `R` be a metric space, let `α : R` be a point and let
`j : Z → N → R` be a function. We aim to estimate how close we can get to `α`, while staying
in the image of `j`. The points `j z a` of `R` in the image of `j` come with a "cost" equal to
`d a`. As we get closer to `α` while staying in the image of `j`, we are interested in bounding
the quantity `d a * dist α (j z a)` from below by a strictly positive amount `1 / A`: the intuition
is that approximating well `α` with the points in the image of `j` should come at a high cost. The
hypotheses on the function `f : R → R` provide us with sufficient conditions to ensure our goal.
The first hypothesis is that `f` is Lipschitz at `α`: this yields a bound on the distance.
The second hypothesis is specific to the Liouville argument and provides the missing bound
involving the cost function `d`.
This lemma collects the properties used in the proof of `exists_pos_real_of_irrational_root`.
It is stated in more general form than needed: in the intended application, `Z = ℤ`, `N = ℕ`,
`R = ℝ`, `d a = (a + 1) ^ f.nat_degree`, `j z a = z / (a + 1)`, `f ∈ ℤ[x]`, `α` is an irrational
root of `f`, `ε` is small, `M` is a bound on the Lipschitz constant of `f` near `α`, `n` is
the degree of the polynomial `f`.
-/
theorem exists_one_le_pow_mul_dist {Z N R : Type*} [PseudoMetricSpace R] {d : N → ℝ}
{j : Z → N → R} {f : R → R} {α : R} {ε M : ℝ}
-- denominators are positive
(d0 : ∀ a : N, 1 ≤ d a)
(e0 : 0 < ε)
-- function is Lipschitz at α
(B : ∀ ⦃y : R⦄, y ∈ closedBall α ε → dist (f α) (f y) ≤ dist α y * M)
-- clear denominators
(L : ∀ ⦃z : Z⦄, ∀ ⦃a : N⦄, j z a ∈ closedBall α ε → 1 ≤ d a * dist (f α) (f (j z a))) :
∃ A : ℝ, 0 < A ∧ ∀ z : Z, ∀ a : N, 1 ≤ d a * (dist α (j z a) * A) := by
-- A useful inequality to keep at hand
have me0 : 0 < max (1 / ε) M := lt_max_iff.mpr (Or.inl (one_div_pos.mpr e0))
-- The maximum between `1 / ε` and `M` works
refine ⟨max (1 / ε) M, me0, fun z a => ?_⟩
-- First, let's deal with the easy case in which we are far away from `α`
by_cases dm1 : 1 ≤ dist α (j z a) * max (1 / ε) M
· exact one_le_mul_of_one_le_of_one_le (d0 a) dm1
· -- `j z a = z / (a + 1)`: we prove that this ratio is close to `α`
have : j z a ∈ closedBall α ε := by
refine mem_closedBall'.mp (le_trans ?_ ((one_div_le me0 e0).mpr (le_max_left _ _)))
exact (le_div_iff₀ me0).mpr (not_le.mp dm1).le
-- use the "separation from `1`" (assumption `L`) for numerators,
refine (L this).trans ?_
-- remove a common factor and use the Lipschitz assumption `B`
gcongr
· exact zero_le_one.trans (d0 a)
· refine (B this).trans ?_
gcongr
apply le_max_right
theorem exists_pos_real_of_irrational_root {α : ℝ} (ha : Irrational α) {f : ℤ[X]} (f0 : f ≠ 0)
(fa : eval α (map (algebraMap ℤ ℝ) f) = 0) :
∃ A : ℝ, 0 < A ∧ ∀ a : ℤ, ∀ b : ℕ,
(1 : ℝ) ≤ ((b : ℝ) + 1) ^ f.natDegree * (|α - a / (b + 1)| * A) := by
-- `fR` is `f` viewed as a polynomial with `ℝ` coefficients.
set fR : ℝ[X] := map (algebraMap ℤ ℝ) f
-- `fR` is non-zero, since `f` is non-zero.
obtain fR0 : fR ≠ 0 := fun fR0 =>
(map_injective (algebraMap ℤ ℝ) fun _ _ A => Int.cast_inj.mp A).ne f0
(fR0.trans (Polynomial.map_zero _).symm)
-- reformulating assumption `fa`: `α` is a root of `fR`.
have ar : α ∈ (fR.roots.toFinset : Set ℝ) :=
Finset.mem_coe.mpr (Multiset.mem_toFinset.mpr ((mem_roots fR0).mpr (IsRoot.def.mpr fa)))
-- Since the polynomial `fR` has finitely many roots, there is a closed interval centered at `α`
-- such that `α` is the only root of `fR` in the interval.
obtain ⟨ζ, z0, U⟩ : ∃ ζ > 0, closedBall α ζ ∩ fR.roots.toFinset = {α} :=
@exists_closedBall_inter_eq_singleton_of_discrete _ _ _ Finite.instDiscreteTopology _ ar
-- Since `fR` is continuous, it is bounded on the interval above.
obtain ⟨xm, -, hM⟩ : ∃ xm : ℝ, xm ∈ Icc (α - ζ) (α + ζ) ∧
IsMaxOn (|fR.derivative.eval ·|) (Icc (α - ζ) (α + ζ)) xm :=
IsCompact.exists_isMaxOn isCompact_Icc
⟨α, (sub_lt_self α z0).le, (lt_add_of_pos_right α z0).le⟩
(continuous_abs.comp fR.derivative.continuous_aeval).continuousOn
-- Use the key lemma `exists_one_le_pow_mul_dist`: we are left to show that ...
refine
@exists_one_le_pow_mul_dist ℤ ℕ ℝ _ _ _ (fun y => fR.eval y) α ζ |fR.derivative.eval xm| ?_ z0
(fun y hy => ?_) fun z a hq => ?_
-- 1: the denominators are positive -- essentially by definition;
· exact fun a => one_le_pow₀ ((le_add_iff_nonneg_left 1).mpr a.cast_nonneg)
-- 2: the polynomial `fR` is Lipschitz at `α` -- as its derivative continuous;
· rw [mul_comm]
rw [Real.closedBall_eq_Icc] at hy
-- apply the Mean Value Theorem: the bound on the derivative comes from differentiability.
refine
Convex.norm_image_sub_le_of_norm_deriv_le (fun _ _ => fR.differentiableAt)
(fun y h => by rw [fR.deriv]; exact hM h) (convex_Icc _ _) hy (mem_Icc_iff_abs_le.mp ?_)
exact @mem_closedBall_self ℝ _ α ζ (le_of_lt z0)
-- 3: the weird inequality of Liouville type with powers of the denominators.
· change 1 ≤ (a + 1 : ℝ) ^ f.natDegree * |eval α fR - eval ((z : ℝ) / (a + 1)) fR|
rw [fa, zero_sub, abs_neg]
rw [show (a + 1 : ℝ) = ((a + 1 : ℕ) : ℤ) by norm_cast] at hq ⊢
-- key observation: the right-hand side of the inequality is an *integer*. Therefore,
-- if its absolute value is not at least one, then it vanishes. Proceed by contradiction
refine one_le_pow_mul_abs_eval_div (Int.natCast_succ_pos a) fun hy => ?_
-- As the evaluation of the polynomial vanishes, we found a root of `fR` that is rational.
-- We know that `α` is the only root of `fR` in our interval, and `α` is irrational:
-- follow your nose.
refine ha.ne_rational z (a + 1) (mem_singleton_iff.mp ?_).symm
refine U.subset ?_
refine ⟨hq, Finset.mem_coe.mp (Multiset.mem_toFinset.mpr ?_)⟩
exact (mem_roots fR0).mpr (IsRoot.def.mpr hy)
/-- **Liouville's Theorem** -/
protected theorem transcendental {x : ℝ} (lx : Liouville x) : Transcendental ℤ x := by
-- Proceed by contradiction: if `x` is algebraic, then `x` is the root (`ef0`) of a
-- non-zero (`f0`) polynomial `f`
rintro ⟨f : ℤ[X], f0, ef0⟩
-- Change `aeval x f = 0` to `eval (map _ f) = 0`, who knew.
replace ef0 : (f.map (algebraMap ℤ ℝ)).eval x = 0 := by
rwa [aeval_def, ← eval_map] at ef0
-- There is a "large" real number `A` such that `(b + 1) ^ (deg f) * |f (x - a / (b + 1))| * A`
-- is at least one. This is obtained from lemma `exists_pos_real_of_irrational_root`.
obtain ⟨A, hA, h⟩ : ∃ A : ℝ, 0 < A ∧ ∀ (a : ℤ) (b : ℕ),
(1 : ℝ) ≤ ((b : ℝ) + 1) ^ f.natDegree * (|x - a / (b + 1)| * A) :=
exists_pos_real_of_irrational_root lx.irrational f0 ef0
-- Since the real numbers are Archimedean, a power of `2` exceeds `A`: `hn : A < 2 ^ r`.
rcases pow_unbounded_of_one_lt A (lt_add_one 1) with ⟨r, hn⟩
-- Use the Liouville property, with exponent `r + deg f`.
obtain ⟨a, b, b1, -, a1⟩ : ∃ a b : ℤ, 1 < b ∧ x ≠ a / b ∧
|x - a / b| < 1 / (b : ℝ) ^ (r + f.natDegree) :=
lx (r + f.natDegree)
have b0 : (0 : ℝ) < b := zero_lt_one.trans (by rw [← Int.cast_one]; exact Int.cast_lt.mpr b1)
-- Prove that `b ^ f.nat_degree * abs (x - a / b)` is strictly smaller than itself
-- recall, this is a proof by contradiction!
refine lt_irrefl ((b : ℝ) ^ f.natDegree * |x - ↑a / ↑b|) ?_
-- clear denominators at `a1`
rw [lt_div_iff₀' (pow_pos b0 _), pow_add, mul_assoc] at a1
-- split the inequality via `1 / A`.
refine (?_ : (b : ℝ) ^ f.natDegree * |x - a / b| < 1 / A).trans_le ?_
-- This branch of the proof uses the Liouville condition and the Archimedean property
· refine (lt_div_iff₀' hA).mpr ?_
refine lt_of_le_of_lt ?_ a1
gcongr
refine hn.le.trans ?_
rw [one_add_one_eq_two]
gcongr
norm_cast
-- this branch of the proof exploits the "integrality" of evaluations of polynomials
-- at ratios of integers.
· lift b to ℕ using zero_le_one.trans b1.le
specialize h a b.pred
rwa [← Nat.cast_succ, Nat.succ_pred_eq_of_pos (zero_lt_one.trans _), ← mul_assoc, ←
div_le_iff₀ hA] at h
exact Int.ofNat_lt.mp b1
end Liouville |
.lake/packages/mathlib/Mathlib/NumberTheory/Transcendental/Liouville/LiouvilleNumber.lean | import Mathlib.NumberTheory.Transcendental.Liouville.Basic
/-!
# Liouville constants
This file contains a construction of a family of Liouville numbers, indexed by a natural number $m$.
The most important property is that they are examples of transcendental real numbers.
This fact is recorded in `transcendental_liouvilleNumber`.
More precisely, for a real number $m$, Liouville's constant is
$$
\sum_{i=0}^\infty\frac{1}{m^{i!}}.
$$
The series converges only for $1 < m$. However, there is no restriction on $m$, since,
if the series does not converge, then the sum of the series is defined to be zero.
We prove that, for $m \in \mathbb{N}$ satisfying $2 \le m$, Liouville's constant associated to $m$
is a transcendental number. Classically, the Liouville number for $m = 2$ is the one called
``Liouville's constant''.
## Implementation notes
The indexing $m$ is eventually a natural number satisfying $2 ≤ m$. However, we prove the first few
lemmas for $m \in \mathbb{R}$.
-/
noncomputable section
open scoped Nat
open Real Finset
/-- For a real number `m`, Liouville's constant is
$$
\sum_{i=0}^\infty\frac{1}{m^{i!}}.
$$
The series converges only for `1 < m`. However, there is no restriction on `m`, since,
if the series does not converge, then the sum of the series is defined to be zero.
-/
def liouvilleNumber (m : ℝ) : ℝ :=
∑' i : ℕ, 1 / m ^ i !
namespace LiouvilleNumber
/-- `LiouvilleNumber.partialSum` is the sum of the first `k + 1` terms of Liouville's constant,
i.e.
$$
\sum_{i=0}^k\frac{1}{m^{i!}}.
$$
-/
def partialSum (m : ℝ) (k : ℕ) : ℝ :=
∑ i ∈ range (k + 1), 1 / m ^ i !
/-- `LiouvilleNumber.remainder` is the sum of the series of the terms in `liouvilleNumber m`
starting from `k+1`, i.e
$$
\sum_{i=k+1}^\infty\frac{1}{m^{i!}}.
$$
-/
def remainder (m : ℝ) (k : ℕ) : ℝ :=
∑' i, 1 / m ^ (i + (k + 1))!
/-!
We start with simple observations.
-/
protected theorem summable {m : ℝ} (hm : 1 < m) : Summable fun i : ℕ => 1 / m ^ i ! :=
summable_one_div_pow_of_le hm Nat.self_le_factorial
theorem remainder_summable {m : ℝ} (hm : 1 < m) (k : ℕ) :
Summable fun i : ℕ => 1 / m ^ (i + (k + 1))! := by
convert (summable_nat_add_iff (k + 1)).2 (LiouvilleNumber.summable hm)
theorem remainder_pos {m : ℝ} (hm : 1 < m) (k : ℕ) : 0 < remainder m k :=
(remainder_summable hm k).tsum_pos (fun _ => by positivity) 0 (by positivity)
theorem partialSum_succ (m : ℝ) (n : ℕ) :
partialSum m (n + 1) = partialSum m n + 1 / m ^ (n + 1)! :=
sum_range_succ _ _
/-- Split the sum defining a Liouville number into the first `k` terms and the rest. -/
theorem partialSum_add_remainder {m : ℝ} (hm : 1 < m) (k : ℕ) :
partialSum m k + remainder m k = liouvilleNumber m :=
(LiouvilleNumber.summable hm).sum_add_tsum_nat_add _
/-! We now prove two useful inequalities, before collecting everything together. -/
/-- An upper estimate on the remainder. This estimate works with `m ∈ ℝ` satisfying `1 < m` and is
stronger than the estimate `LiouvilleNumber.remainder_lt` below. However, the latter estimate is
more useful for the proof. -/
theorem remainder_lt' (n : ℕ) {m : ℝ} (m1 : 1 < m) :
remainder m n < (1 - 1 / m)⁻¹ * (1 / m ^ (n + 1)!) :=
-- two useful inequalities
have m0 : 0 < m := zero_lt_one.trans m1
have mi : 1 / m < 1 := (div_lt_one m0).mpr m1
-- to show the strict inequality between these series, we prove that:
calc
(∑' i, 1 / m ^ (i + (n + 1))!) < ∑' i, 1 / m ^ (i + (n + 1)!) :=
-- 1. the second series dominates the first
Summable.tsum_lt_tsum (fun b => one_div_pow_le_one_div_pow_of_le m1.le
(b.add_factorial_succ_le_factorial_add_succ n))
-- 2. the term with index `i = 2` of the first series is strictly smaller than
-- the corresponding term of the second series
(one_div_pow_strictAnti m1 (n.add_factorial_succ_lt_factorial_add_succ (i := 2) le_rfl))
-- 3. the first series is summable
(remainder_summable m1 n)
-- 4. the second series is summable, since its terms grow quickly
(summable_one_div_pow_of_le m1 fun _ => le_self_add)
-- split the sum in the exponent and massage
_ = ∑' i : ℕ, (1 / m) ^ i * (1 / m ^ (n + 1)!) := by
simp only [pow_add, one_div, mul_inv, inv_pow]
-- factor the constant `(1 / m ^ (n + 1)!)` out of the series
_ = (∑' i, (1 / m) ^ i) * (1 / m ^ (n + 1)!) := tsum_mul_right
-- the series is the geometric series
_ = (1 - 1 / m)⁻¹ * (1 / m ^ (n + 1)!) := by rw [tsum_geometric_of_lt_one (by positivity) mi]
theorem aux_calc (n : ℕ) {m : ℝ} (hm : 2 ≤ m) :
(1 - 1 / m)⁻¹ * (1 / m ^ (n + 1)!) ≤ 1 / (m ^ n !) ^ n :=
calc
(1 - 1 / m)⁻¹ * (1 / m ^ (n + 1)!) ≤ 2 * (1 / m ^ (n + 1)!) := by
-- the second factors coincide (and are non-negative),
-- the first factors satisfy the inequality `sub_one_div_inv_le_two`
gcongr; exact sub_one_div_inv_le_two hm
_ = 2 / m ^ (n + 1)! := mul_one_div 2 _
_ = 2 / m ^ (n ! * (n + 1)) := (congr_arg (2 / ·) (congr_arg (Pow.pow m) (mul_comm _ _)))
_ ≤ 1 / (m ^ n !) ^ n := by
-- Clear denominators and massage*
rw [← pow_mul, div_le_div_iff₀, one_mul, mul_add_one, pow_add, mul_comm 2]
· gcongr
-- `2 ≤ m ^ n!` is a consequence of monotonicity of exponentiation at `2 ≤ m`.
exact hm.trans <| le_self_pow₀ (one_le_two.trans hm) <| by positivity
all_goals positivity
/-- An upper estimate on the remainder. This estimate works with `m ∈ ℝ` satisfying `2 ≤ m` and is
weaker than the estimate `LiouvilleNumber.remainder_lt'` above. However, this estimate is
more useful for the proof. -/
theorem remainder_lt (n : ℕ) {m : ℝ} (m2 : 2 ≤ m) : remainder m n < 1 / (m ^ n !) ^ n :=
(remainder_lt' n <| one_lt_two.trans_le m2).trans_le (aux_calc _ m2)
/-! Starting from here, we specialize to the case in which `m` is a natural number. -/
/-- The sum of the `k` initial terms of the Liouville number to base `m` is a ratio of natural
numbers where the denominator is `m ^ k!`. -/
theorem partialSum_eq_rat {m : ℕ} (hm : 0 < m) (k : ℕ) :
∃ p : ℕ, partialSum m k = p / ((m ^ k ! :) : ℝ) := by
induction k with
| zero => exact ⟨1, by rw [partialSum, range_one, sum_singleton, Nat.cast_one, Nat.factorial,
pow_one, pow_one]⟩
| succ k h =>
rcases h with ⟨p_k, h_k⟩
use p_k * m ^ ((k + 1)! - k !) + 1
rw [partialSum_succ, h_k, div_add_div, div_eq_div_iff, add_mul]
· norm_cast
rw [add_mul, one_mul, Nat.factorial_succ, add_mul, one_mul, add_tsub_cancel_right, pow_add]
simp [mul_assoc]
all_goals positivity
end LiouvilleNumber
open LiouvilleNumber
theorem liouville_liouvilleNumber {m : ℕ} (hm : 2 ≤ m) : Liouville (liouvilleNumber m) := by
-- two useful inequalities
have mZ1 : 1 < (m : ℤ) := by norm_cast
have m1 : 1 < (m : ℝ) := by norm_cast
intro n
-- the first `n` terms sum to `p / m ^ k!`
rcases partialSum_eq_rat (zero_lt_two.trans_le hm) n with ⟨p, hp⟩
refine ⟨p, m ^ n !, one_lt_pow₀ mZ1 n.factorial_ne_zero, ?_⟩
push_cast
rw [Nat.cast_pow] at hp
-- separate out the sum of the first `n` terms and the rest
rw [← partialSum_add_remainder m1 n, ← hp]
have hpos := remainder_pos m1 n
simpa [abs_of_pos hpos, hpos.ne'] using @remainder_lt n m (by assumption_mod_cast)
theorem transcendental_liouvilleNumber {m : ℕ} (hm : 2 ≤ m) :
Transcendental ℤ (liouvilleNumber m) :=
(liouville_liouvilleNumber hm).transcendental |
.lake/packages/mathlib/Mathlib/NumberTheory/Transcendental/Liouville/LiouvilleWith.lean | import Mathlib.Analysis.SpecialFunctions.Pow.Asymptotics
import Mathlib.NumberTheory.Transcendental.Liouville.Basic
import Mathlib.Topology.Instances.Irrational
/-!
# Liouville numbers with a given exponent
We say that a real number `x` is a Liouville number with exponent `p : ℝ` if there exists a real
number `C` such that for infinitely many denominators `n` there exists a numerator `m` such that
`x ≠ m / n` and `|x - m / n| < C / n ^ p`. A number is a Liouville number in the sense of
`Liouville` if it is `LiouvilleWith` any real exponent, see `forall_liouvilleWith_iff`.
* If `p ≤ 1`, then this condition is trivial.
* If `1 < p ≤ 2`, then this condition is equivalent to `Irrational x`. The forward implication
does not require `p ≤ 2` and is formalized as `LiouvilleWith.irrational`; the other implication
follows from approximations by continued fractions and is not formalized yet.
* If `p > 2`, then this is a non-trivial condition on irrational numbers. In particular,
[Thue–Siegel–Roth theorem](https://en.wikipedia.org/wiki/Roth's_theorem) states that such numbers
must be transcendental.
In this file we define the predicate `LiouvilleWith` and prove some basic facts about this
predicate.
## Tags
Liouville number, irrational, irrationality exponent
-/
open Filter Metric Real Set
open scoped Filter Topology
/-- We say that a real number `x` is a Liouville number with exponent `p : ℝ` if there exists a real
number `C` such that for infinitely many denominators `n` there exists a numerator `m` such that
`x ≠ m / n` and `|x - m / n| < C / n ^ p`.
A number is a Liouville number in the sense of `Liouville` if it is `LiouvilleWith` any real
exponent. -/
def LiouvilleWith (p x : ℝ) : Prop :=
∃ C, ∃ᶠ n : ℕ in atTop, ∃ m : ℤ, x ≠ m / n ∧ |x - m / n| < C / n ^ p
/-- For `p = 1` (hence, for any `p ≤ 1`), the condition `LiouvilleWith p x` is trivial. -/
theorem liouvilleWith_one (x : ℝ) : LiouvilleWith 1 x := by
use 2
refine ((eventually_gt_atTop 0).mono fun n hn => ?_).frequently
have hn' : (0 : ℝ) < n := by simpa
have : x < ↑(⌊x * ↑n⌋ + 1) / ↑n := by
rw [lt_div_iff₀ hn', Int.cast_add, Int.cast_one]
exact Int.lt_floor_add_one _
refine ⟨⌊x * n⌋ + 1, this.ne, ?_⟩
rw [abs_sub_comm, abs_of_pos (sub_pos.2 this), rpow_one, sub_lt_iff_lt_add',
add_div_eq_mul_add_div _ _ hn'.ne']
gcongr
calc _ ≤ x * n + 1 := by push_cast; gcongr; apply Int.floor_le
_ < x * n + 2 := by linarith
namespace LiouvilleWith
variable {p q x : ℝ} {r : ℚ} {m : ℤ} {n : ℕ}
/-- The constant `C` provided by the definition of `LiouvilleWith` can be made positive.
We also add `1 ≤ n` to the list of assumptions about the denominator. While it is equivalent to
the original statement, the case `n = 0` breaks many arguments. -/
theorem exists_pos (h : LiouvilleWith p x) :
∃ (C : ℝ) (_h₀ : 0 < C),
∃ᶠ n : ℕ in atTop, 1 ≤ n ∧ ∃ m : ℤ, x ≠ m / n ∧ |x - m / n| < C / n ^ p := by
rcases h with ⟨C, hC⟩
refine ⟨max C 1, zero_lt_one.trans_le <| le_max_right _ _, ?_⟩
refine ((eventually_ge_atTop 1).and_frequently hC).mono ?_
rintro n ⟨hle, m, hne, hlt⟩
refine ⟨hle, m, hne, hlt.trans_le ?_⟩
gcongr
apply le_max_left
/-- If a number is Liouville with exponent `p`, then it is Liouville with any smaller exponent. -/
theorem mono (h : LiouvilleWith p x) (hle : q ≤ p) : LiouvilleWith q x := by
rcases h.exists_pos with ⟨C, hC₀, hC⟩
refine ⟨C, hC.mono ?_⟩; rintro n ⟨hn, m, hne, hlt⟩
refine ⟨m, hne, hlt.trans_le <| ?_⟩
gcongr
exact_mod_cast hn
/-- If `x` satisfies Liouville condition with exponent `p` and `q < p`, then `x`
satisfies Liouville condition with exponent `q` and constant `1`. -/
theorem frequently_lt_rpow_neg (h : LiouvilleWith p x) (hlt : q < p) :
∃ᶠ n : ℕ in atTop, ∃ m : ℤ, x ≠ m / n ∧ |x - m / n| < n ^ (-q) := by
rcases h.exists_pos with ⟨C, _hC₀, hC⟩
have : ∀ᶠ n : ℕ in atTop, C < n ^ (p - q) := by
simpa only [(· ∘ ·), neg_sub, one_div] using
((tendsto_rpow_atTop (sub_pos.2 hlt)).comp tendsto_natCast_atTop_atTop).eventually
(eventually_gt_atTop C)
refine (this.and_frequently hC).mono ?_
rintro n ⟨hnC, hn, m, hne, hlt⟩
replace hn : (0 : ℝ) < n := Nat.cast_pos.2 hn
refine ⟨m, hne, hlt.trans <| (div_lt_iff₀ <| rpow_pos_of_pos hn _).2 ?_⟩
rwa [mul_comm, ← rpow_add hn, ← sub_eq_add_neg]
/-- The product of a Liouville number and a nonzero rational number is again a Liouville number. -/
theorem mul_rat (h : LiouvilleWith p x) (hr : r ≠ 0) : LiouvilleWith p (x * r) := by
rcases h.exists_pos with ⟨C, _hC₀, hC⟩
refine ⟨r.den ^ p * (|r| * C), (tendsto_id.nsmul_atTop r.pos).frequently (hC.mono ?_)⟩
rintro n ⟨_hn, m, hne, hlt⟩
have A : (↑(r.num * m) : ℝ) / ↑(r.den • id n) = m / n * r := by
simp [← div_mul_div_comm, ← r.cast_def, mul_comm]
refine ⟨r.num * m, ?_, ?_⟩
· rw [A]; simp [hne, hr]
· rw [A, ← sub_mul, abs_mul]
simp only [smul_eq_mul, id, Nat.cast_mul]
calc _ < C / ↑n ^ p * |↑r| := by gcongr
_ = ↑r.den ^ p * (↑|r| * C) / (↑r.den * ↑n) ^ p := ?_
rw [mul_rpow, mul_div_mul_left, mul_comm, mul_div_assoc]
· simp only [Rat.cast_abs]
all_goals positivity
/-- The product `x * r`, `r : ℚ`, `r ≠ 0`, is a Liouville number with exponent `p` if and only if
`x` satisfies the same condition. -/
theorem mul_rat_iff (hr : r ≠ 0) : LiouvilleWith p (x * r) ↔ LiouvilleWith p x :=
⟨fun h => by
simpa only [mul_assoc, ← Rat.cast_mul, mul_inv_cancel₀ hr, Rat.cast_one, mul_one] using
h.mul_rat (inv_ne_zero hr),
fun h => h.mul_rat hr⟩
/-- The product `r * x`, `r : ℚ`, `r ≠ 0`, is a Liouville number with exponent `p` if and only if
`x` satisfies the same condition. -/
theorem rat_mul_iff (hr : r ≠ 0) : LiouvilleWith p (r * x) ↔ LiouvilleWith p x := by
rw [mul_comm, mul_rat_iff hr]
theorem rat_mul (h : LiouvilleWith p x) (hr : r ≠ 0) : LiouvilleWith p (r * x) :=
(rat_mul_iff hr).2 h
theorem mul_int_iff (hm : m ≠ 0) : LiouvilleWith p (x * m) ↔ LiouvilleWith p x := by
rw [← Rat.cast_intCast, mul_rat_iff (Int.cast_ne_zero.2 hm)]
theorem mul_int (h : LiouvilleWith p x) (hm : m ≠ 0) : LiouvilleWith p (x * m) :=
(mul_int_iff hm).2 h
theorem int_mul_iff (hm : m ≠ 0) : LiouvilleWith p (m * x) ↔ LiouvilleWith p x := by
rw [mul_comm, mul_int_iff hm]
theorem int_mul (h : LiouvilleWith p x) (hm : m ≠ 0) : LiouvilleWith p (m * x) :=
(int_mul_iff hm).2 h
theorem mul_nat_iff (hn : n ≠ 0) : LiouvilleWith p (x * n) ↔ LiouvilleWith p x := by
rw [← Rat.cast_natCast, mul_rat_iff (Nat.cast_ne_zero.2 hn)]
theorem mul_nat (h : LiouvilleWith p x) (hn : n ≠ 0) : LiouvilleWith p (x * n) :=
(mul_nat_iff hn).2 h
theorem nat_mul_iff (hn : n ≠ 0) : LiouvilleWith p (n * x) ↔ LiouvilleWith p x := by
rw [mul_comm, mul_nat_iff hn]
theorem nat_mul (h : LiouvilleWith p x) (hn : n ≠ 0) : LiouvilleWith p (n * x) := by
rw [mul_comm]; exact h.mul_nat hn
theorem add_rat (h : LiouvilleWith p x) (r : ℚ) : LiouvilleWith p (x + r) := by
rcases h.exists_pos with ⟨C, _hC₀, hC⟩
refine ⟨r.den ^ p * C, (tendsto_id.nsmul_atTop r.pos).frequently (hC.mono ?_)⟩
rintro n ⟨hn, m, hne, hlt⟩
have : (↑(r.den * m + r.num * n : ℤ) / ↑(r.den • id n) : ℝ) = m / n + r := by
rw [Algebra.id.smul_eq_mul, id]
nth_rewrite 4 [← Rat.num_div_den r]
push_cast
rw [add_div, mul_div_mul_left _ _ (by positivity), mul_div_mul_right _ _ (by positivity)]
refine ⟨r.den * m + r.num * n, ?_⟩; rw [this, add_sub_add_right_eq_sub]
refine ⟨by simpa, hlt.trans_le (le_of_eq ?_)⟩
have : (r.den ^ p : ℝ) ≠ 0 := by positivity
simp [mul_rpow, Nat.cast_nonneg, mul_div_mul_left, this]
@[simp]
theorem add_rat_iff : LiouvilleWith p (x + r) ↔ LiouvilleWith p x :=
⟨fun h => by simpa using h.add_rat (-r), fun h => h.add_rat r⟩
@[simp]
theorem rat_add_iff : LiouvilleWith p (r + x) ↔ LiouvilleWith p x := by rw [add_comm, add_rat_iff]
theorem rat_add (h : LiouvilleWith p x) (r : ℚ) : LiouvilleWith p (r + x) :=
add_comm x r ▸ h.add_rat r
@[simp]
theorem add_int_iff : LiouvilleWith p (x + m) ↔ LiouvilleWith p x := by
rw [← Rat.cast_intCast m, add_rat_iff]
@[simp]
theorem int_add_iff : LiouvilleWith p (m + x) ↔ LiouvilleWith p x := by rw [add_comm, add_int_iff]
@[simp]
theorem add_nat_iff : LiouvilleWith p (x + n) ↔ LiouvilleWith p x := by
rw [← Rat.cast_natCast n, add_rat_iff]
@[simp]
theorem nat_add_iff : LiouvilleWith p (n + x) ↔ LiouvilleWith p x := by rw [add_comm, add_nat_iff]
theorem add_int (h : LiouvilleWith p x) (m : ℤ) : LiouvilleWith p (x + m) :=
add_int_iff.2 h
theorem int_add (h : LiouvilleWith p x) (m : ℤ) : LiouvilleWith p (m + x) :=
int_add_iff.2 h
theorem add_nat (h : LiouvilleWith p x) (n : ℕ) : LiouvilleWith p (x + n) :=
h.add_int n
theorem nat_add (h : LiouvilleWith p x) (n : ℕ) : LiouvilleWith p (n + x) :=
h.int_add n
protected theorem neg (h : LiouvilleWith p x) : LiouvilleWith p (-x) := by
rcases h with ⟨C, hC⟩
refine ⟨C, hC.mono ?_⟩
rintro n ⟨m, hne, hlt⟩
refine ⟨-m, by simp [neg_div, hne], ?_⟩
convert hlt using 1
rw [abs_sub_comm]
congr! 1; push_cast; ring
@[simp]
theorem neg_iff : LiouvilleWith p (-x) ↔ LiouvilleWith p x :=
⟨fun h => neg_neg x ▸ h.neg, LiouvilleWith.neg⟩
@[simp]
theorem sub_rat_iff : LiouvilleWith p (x - r) ↔ LiouvilleWith p x := by
rw [sub_eq_add_neg, ← Rat.cast_neg, add_rat_iff]
theorem sub_rat (h : LiouvilleWith p x) (r : ℚ) : LiouvilleWith p (x - r) :=
sub_rat_iff.2 h
@[simp]
theorem sub_int_iff : LiouvilleWith p (x - m) ↔ LiouvilleWith p x := by
rw [← Rat.cast_intCast, sub_rat_iff]
theorem sub_int (h : LiouvilleWith p x) (m : ℤ) : LiouvilleWith p (x - m) :=
sub_int_iff.2 h
@[simp]
theorem sub_nat_iff : LiouvilleWith p (x - n) ↔ LiouvilleWith p x := by
rw [← Rat.cast_natCast, sub_rat_iff]
theorem sub_nat (h : LiouvilleWith p x) (n : ℕ) : LiouvilleWith p (x - n) :=
sub_nat_iff.2 h
@[simp]
theorem rat_sub_iff : LiouvilleWith p (r - x) ↔ LiouvilleWith p x := by simp [sub_eq_add_neg]
theorem rat_sub (h : LiouvilleWith p x) (r : ℚ) : LiouvilleWith p (r - x) :=
rat_sub_iff.2 h
@[simp]
theorem int_sub_iff : LiouvilleWith p (m - x) ↔ LiouvilleWith p x := by simp [sub_eq_add_neg]
theorem int_sub (h : LiouvilleWith p x) (m : ℤ) : LiouvilleWith p (m - x) :=
int_sub_iff.2 h
@[simp]
theorem nat_sub_iff : LiouvilleWith p (n - x) ↔ LiouvilleWith p x := by simp [sub_eq_add_neg]
theorem nat_sub (h : LiouvilleWith p x) (n : ℕ) : LiouvilleWith p (n - x) :=
nat_sub_iff.2 h
theorem ne_cast_int (h : LiouvilleWith p x) (hp : 1 < p) (m : ℤ) : x ≠ m := by
rintro rfl; rename' m => M
rcases ((eventually_gt_atTop 0).and_frequently (h.frequently_lt_rpow_neg hp)).exists with
⟨n : ℕ, hn : 0 < n, m : ℤ, hne : (M : ℝ) ≠ m / n, hlt : |(M - m / n : ℝ)| < n ^ (-1 : ℝ)⟩
refine hlt.not_ge ?_
have hn' : (0 : ℝ) < n := by simpa
rw [rpow_neg_one, ← one_div, sub_div' hn'.ne', abs_div, Nat.abs_cast]
gcongr
norm_cast
rw [← zero_add (1 : ℤ), Int.add_one_le_iff, abs_pos, sub_ne_zero]
rw [Ne, eq_div_iff hn'.ne'] at hne
exact mod_cast hne
/-- A number satisfying the Liouville condition with exponent `p > 1` is an irrational number. -/
protected theorem irrational (h : LiouvilleWith p x) (hp : 1 < p) : Irrational x := by
rintro ⟨r, rfl⟩
rcases eq_or_ne r 0 with (rfl | h0)
· refine h.ne_cast_int hp 0 ?_; rw [Rat.cast_zero, Int.cast_zero]
· refine (h.mul_rat (inv_ne_zero h0)).ne_cast_int hp 1 ?_
rw [Rat.cast_inv, mul_inv_cancel₀]
exacts [Int.cast_one.symm, Rat.cast_ne_zero.mpr h0]
end LiouvilleWith
namespace Liouville
variable {x : ℝ}
/-- If `x` is a Liouville number, then for any `n`, for infinitely many denominators `b` there
exists a numerator `a` such that `x ≠ a / b` and `|x - a / b| < 1 / b ^ n`. -/
theorem frequently_exists_num (hx : Liouville x) (n : ℕ) :
∃ᶠ b : ℕ in atTop, ∃ a : ℤ, x ≠ a / b ∧ |x - a / b| < 1 / (b : ℝ) ^ n := by
refine Classical.not_not.1 fun H => ?_
simp only [not_exists, not_frequently, not_and, not_lt,
eventually_atTop] at H
rcases H with ⟨N, hN⟩
have : ∀ b > (1 : ℕ), ∀ᶠ m : ℕ in atTop, ∀ a : ℤ, 1 / (b : ℝ) ^ m ≤ |x - a / b| := by
intro b hb
replace hb : (1 : ℝ) < b := Nat.one_lt_cast.2 hb
have H : Tendsto (fun m => 1 / (b : ℝ) ^ m : ℕ → ℝ) atTop (𝓝 0) := by
simp only [one_div]
exact tendsto_inv_atTop_zero.comp (tendsto_pow_atTop_atTop_of_one_lt hb)
refine (H.eventually (hx.irrational.eventually_forall_le_dist_cast_div b)).mono ?_
exact fun m hm a => hm a
have : ∀ᶠ m : ℕ in atTop, ∀ b < N, 1 < b → ∀ a : ℤ, 1 / (b : ℝ) ^ m ≤ |x - a / b| :=
(finite_lt_nat N).eventually_all.2 fun b _hb => eventually_imp_distrib_left.2 (this b)
rcases (this.and (eventually_ge_atTop n)).exists with ⟨m, hm, hnm⟩
rcases hx m with ⟨a, b, hb, hne, hlt⟩
lift b to ℕ using zero_le_one.trans hb.le; norm_cast at hb; push_cast at hne hlt
rcases le_or_gt N b with h | h
· refine (hN b h a hne).not_gt (hlt.trans_le ?_)
gcongr
exact_mod_cast hb.le
· exact (hm b h hb _).not_gt hlt
/-- A Liouville number is a Liouville number with any real exponent. -/
protected theorem liouvilleWith (hx : Liouville x) (p : ℝ) : LiouvilleWith p x := by
suffices LiouvilleWith ⌈p⌉₊ x from this.mono (Nat.le_ceil p)
refine ⟨1, ((eventually_gt_atTop 1).and_frequently (hx.frequently_exists_num ⌈p⌉₊)).mono ?_⟩
rintro b ⟨_hb, a, hne, hlt⟩
refine ⟨a, hne, ?_⟩
rwa [rpow_natCast]
end Liouville
/-- A number satisfies the Liouville condition with any exponent if and only if it is a Liouville
number. -/
theorem forall_liouvilleWith_iff {x : ℝ} : (∀ p, LiouvilleWith p x) ↔ Liouville x := by
refine ⟨fun H n => ?_, Liouville.liouvilleWith⟩
rcases ((eventually_gt_atTop 1).and_frequently
((H (n + 1)).frequently_lt_rpow_neg (lt_add_one (n : ℝ)))).exists
with ⟨b, hb, a, hne, hlt⟩
exact ⟨a, b, mod_cast hb, hne, by simpa [rpow_neg] using hlt⟩ |
.lake/packages/mathlib/Mathlib/NumberTheory/Transcendental/Liouville/Measure.lean | import Mathlib.MeasureTheory.Measure.Lebesgue.Basic
import Mathlib.NumberTheory.Transcendental.Liouville.Residual
import Mathlib.NumberTheory.Transcendental.Liouville.LiouvilleWith
import Mathlib.Analysis.PSeries
/-!
# Volume of the set of Liouville numbers
In this file we prove that the set of Liouville numbers with exponent (irrationality measure)
strictly greater than two is a set of Lebesgue measure zero, see
`volume_iUnion_setOf_liouvilleWith`.
Since this set is a residual set, we show that the filters `residual` and `ae volume` are disjoint.
These filters correspond to two common notions of genericity on `ℝ`: residual sets and sets of full
measure. The fact that the filters are disjoint means that two mutually exclusive properties can be
“generic” at the same time (in the sense of different “genericity” filters).
## Tags
Liouville number, Lebesgue measure, residual, generic property
-/
open scoped Filter ENNReal Topology NNReal
open Filter Set Metric MeasureTheory Real
theorem setOf_liouvilleWith_subset_aux :
{ x : ℝ | ∃ p > 2, LiouvilleWith p x } ⊆
⋃ m : ℤ, (· + (m : ℝ)) ⁻¹' ⋃ n > (0 : ℕ),
{ x : ℝ | ∃ᶠ b : ℕ in atTop, ∃ a ∈ Finset.Icc (0 : ℤ) b,
|x - (a : ℤ) / b| < 1 / (b : ℝ) ^ (2 + 1 / n : ℝ) } := by
rintro x ⟨p, hp, hxp⟩
rcases exists_nat_one_div_lt (sub_pos.2 hp) with ⟨n, hn⟩
rw [lt_sub_iff_add_lt'] at hn
suffices ∀ y : ℝ, LiouvilleWith p y → y ∈ Ico (0 : ℝ) 1 → ∃ᶠ b : ℕ in atTop,
∃ a ∈ Finset.Icc (0 : ℤ) b, |y - a / b| < 1 / (b : ℝ) ^ (2 + 1 / (n + 1 : ℕ) : ℝ) by
simp only [mem_iUnion, mem_preimage]
have hx : x + ↑(-⌊x⌋) ∈ Ico (0 : ℝ) 1 := by
simp only [Int.floor_le, Int.lt_floor_add_one, add_neg_lt_iff_le_add', zero_add, and_self_iff,
mem_Ico, Int.cast_neg, le_add_neg_iff_add_le]
exact ⟨-⌊x⌋, n + 1, n.succ_pos, this _ (hxp.add_int _) hx⟩
clear hxp x; intro x hxp hx01
refine ((hxp.frequently_lt_rpow_neg hn).and_eventually (eventually_ge_atTop 1)).mono ?_
rintro b ⟨⟨a, -, hlt⟩, hb⟩
rw [rpow_neg b.cast_nonneg, ← one_div, ← Nat.cast_succ] at hlt
refine ⟨a, ?_, hlt⟩
replace hb : (1 : ℝ) ≤ b := Nat.one_le_cast.2 hb
have hb0 : (0 : ℝ) < b := zero_lt_one.trans_le hb
replace hlt : |x - a / b| < 1 / b := by
refine hlt.trans_le (one_div_le_one_div_of_le hb0 ?_)
calc
(b : ℝ) = (b : ℝ) ^ (1 : ℝ) := (rpow_one _).symm
_ ≤ (b : ℝ) ^ (2 + 1 / (n + 1 : ℕ) : ℝ) :=
rpow_le_rpow_of_exponent_le hb (one_le_two.trans ?_)
simpa using n.cast_add_one_pos.le
rw [sub_div' hb0.ne', abs_div, abs_of_pos hb0, div_lt_div_iff_of_pos_right hb0, abs_sub_lt_iff,
sub_lt_iff_lt_add, sub_lt_iff_lt_add, ← sub_lt_iff_lt_add'] at hlt
rw [Finset.mem_Icc, ← Int.lt_add_one_iff, ← Int.lt_add_one_iff, ← neg_lt_iff_pos_add, add_comm, ←
@Int.cast_lt ℝ, ← @Int.cast_lt ℝ]
push_cast
refine ⟨lt_of_le_of_lt ?_ hlt.1, hlt.2.trans_le ?_⟩
· simp only [mul_nonneg hx01.left b.cast_nonneg, neg_le_sub_iff_le_add, le_add_iff_nonneg_left]
· rw [add_le_add_iff_left]
exact mul_le_of_le_one_left hb0.le hx01.2.le
/-- The set of numbers satisfying the Liouville condition with some exponent `p > 2` has Lebesgue
measure zero. -/
@[simp]
theorem volume_iUnion_setOf_liouvilleWith :
volume (⋃ (p : ℝ) (_hp : 2 < p), { x : ℝ | LiouvilleWith p x }) = 0 := by
simp only [← setOf_exists, exists_prop]
refine measure_mono_null setOf_liouvilleWith_subset_aux ?_
rw [measure_iUnion_null_iff]; intro m; rw [measure_preimage_add_right]; clear m
refine (measure_biUnion_null_iff <| to_countable _).2 fun n (hn : 1 ≤ n) => ?_
generalize hr : (2 + 1 / n : ℝ) = r
replace hr : 2 < r := by simp [← hr, zero_lt_one.trans_le hn]
clear hn n
refine measure_setOf_frequently_eq_zero ?_
simp only [setOf_exists, ← exists_prop, ← Real.dist_eq, ← mem_ball, setOf_mem_eq]
set B : ℤ → ℕ → Set ℝ := fun a b => ball (a / b) (1 / (b : ℝ) ^ r)
have hB : ∀ a b, volume (B a b) = ↑((2 : ℝ≥0) / (b : ℝ≥0) ^ r) := fun a b ↦ by
rw [Real.volume_ball, mul_one_div, ← NNReal.coe_two, ← NNReal.coe_natCast, ← NNReal.coe_rpow,
← NNReal.coe_div, ENNReal.ofReal_coe_nnreal]
have : ∀ b : ℕ, volume (⋃ a ∈ Finset.Icc (0 : ℤ) b, B a b) ≤
↑(2 * ((b : ℝ≥0) ^ (1 - r) + (b : ℝ≥0) ^ (-r))) := fun b ↦
calc
volume (⋃ a ∈ Finset.Icc (0 : ℤ) b, B a b) ≤ ∑ a ∈ Finset.Icc (0 : ℤ) b, volume (B a b) :=
measure_biUnion_finset_le _ _
_ = ↑((b + 1) * (2 / (b : ℝ≥0) ^ r)) := by
simp only [hB, Int.card_Icc, Finset.sum_const, nsmul_eq_mul, sub_zero,
Int.toNat_natCast, ← Nat.cast_succ, ENNReal.coe_mul, ENNReal.coe_natCast]
_ = _ := by
have : 1 - r ≠ 0 := by linarith
rw [ENNReal.coe_inj]
simp [add_mul, div_eq_mul_inv, NNReal.rpow_neg, NNReal.rpow_sub' this, mul_add,
mul_left_comm]
refine ne_top_of_le_ne_top (ENNReal.tsum_coe_ne_top_iff_summable.2 ?_) (ENNReal.tsum_le_tsum this)
refine (Summable.add ?_ ?_).mul_left _ <;> simp only [NNReal.summable_rpow] <;> linarith
theorem ae_not_liouvilleWith : ∀ᵐ x, ∀ p > (2 : ℝ), ¬LiouvilleWith p x := by
simpa only [ae_iff, not_forall, Classical.not_not, setOf_exists] using
volume_iUnion_setOf_liouvilleWith
theorem ae_not_liouville : ∀ᵐ x, ¬Liouville x :=
ae_not_liouvilleWith.mono fun _ h₁ h₂ => h₁ 3 (by norm_num) (h₂.liouvilleWith 3)
/-- The set of Liouville numbers has Lebesgue measure zero. -/
@[simp]
theorem volume_setOf_liouville : volume { x : ℝ | Liouville x } = 0 := by
simpa only [ae_iff, Classical.not_not] using ae_not_liouville
/-- The filters `residual ℝ` and `ae volume` are disjoint. This means that there exists a residual
set of Lebesgue measure zero (e.g., the set of Liouville numbers). -/
theorem Real.disjoint_residual_ae : Disjoint (residual ℝ) (ae volume) :=
disjoint_of_disjoint_of_mem disjoint_compl_right eventually_residual_liouville ae_not_liouville |
.lake/packages/mathlib/Mathlib/NumberTheory/Transcendental/Liouville/Residual.lean | import Mathlib.NumberTheory.Transcendental.Liouville.Basic
import Mathlib.Topology.Baire.Lemmas
import Mathlib.Topology.Baire.LocallyCompactRegular
import Mathlib.Topology.Instances.Irrational
/-!
# Density of Liouville numbers
In this file we prove that the set of Liouville numbers form a dense `Gδ` set. We also prove a
similar statement about irrational numbers.
-/
open scoped Filter
open Filter Set Metric
theorem setOf_liouville_eq_iInter_iUnion :
{ x | Liouville x } =
⋂ n : ℕ, ⋃ (a : ℤ) (b : ℤ) (_ : 1 < b),
ball ((a : ℝ) / b) (1 / (b : ℝ) ^ n) \ {(a : ℝ) / b} := by
ext x
simp only [mem_iInter, mem_iUnion, Liouville, mem_setOf_eq, exists_prop, mem_diff,
mem_singleton_iff, mem_ball, Real.dist_eq, and_comm]
theorem IsGδ.setOf_liouville : IsGδ { x | Liouville x } := by
rw [setOf_liouville_eq_iInter_iUnion]
refine .iInter fun n => IsOpen.isGδ ?_
refine isOpen_iUnion fun a => isOpen_iUnion fun b => isOpen_iUnion fun _hb => ?_
exact isOpen_ball.inter isClosed_singleton.isOpen_compl
theorem setOf_liouville_eq_irrational_inter_iInter_iUnion :
{ x | Liouville x } =
{ x | Irrational x } ∩ ⋂ n : ℕ, ⋃ (a : ℤ) (b : ℤ) (_ : 1 < b),
ball (a / b) (1 / (b : ℝ) ^ n) := by
refine Subset.antisymm ?_ ?_
· refine subset_inter (fun x hx => hx.irrational) ?_
rw [setOf_liouville_eq_iInter_iUnion]
exact iInter_mono fun n => iUnion₂_mono fun a b => iUnion_mono fun _hb => diff_subset
· simp only [inter_iInter, inter_iUnion, setOf_liouville_eq_iInter_iUnion]
refine iInter_mono fun n => iUnion₂_mono fun a b => iUnion_mono fun hb => ?_
rw [inter_comm]
exact diff_subset_diff Subset.rfl (singleton_subset_iff.2 ⟨a / b, by norm_cast⟩)
/-- The set of Liouville numbers is a residual set. -/
theorem eventually_residual_liouville : ∀ᶠ x in residual ℝ, Liouville x := by
rw [Filter.Eventually, setOf_liouville_eq_irrational_inter_iInter_iUnion]
refine eventually_residual_irrational.and ?_
refine residual_of_dense_Gδ ?_ (Rat.isDenseEmbedding_coe_real.dense.mono ?_)
· exact .iInter fun n => IsOpen.isGδ <|
isOpen_iUnion fun a => isOpen_iUnion fun b => isOpen_iUnion fun _hb => isOpen_ball
· rintro _ ⟨r, rfl⟩
simp only [mem_iInter, mem_iUnion]
refine fun n => ⟨r.num * 2, r.den * 2, ?_, ?_⟩
· have := r.pos; cutsat
· convert @mem_ball_self ℝ _ (r : ℝ) _ _
· push_cast
-- Workaround for https://github.com/leanprover/lean4/pull/6438; this eliminates an
-- `Expr.mdata` that would cause `norm_cast` to skip a numeral.
rw [Eq.refl (2 : ℝ)]
norm_cast
simp [Rat.divInt_mul_right (two_ne_zero)]
· refine one_div_pos.2 (pow_pos (Int.cast_pos.2 ?_) _)
exact mul_pos (Int.natCast_pos.2 r.pos) zero_lt_two
/-- The set of Liouville numbers in dense. -/
theorem dense_liouville : Dense { x | Liouville x } :=
dense_of_mem_residual eventually_residual_liouville |
.lake/packages/mathlib/Mathlib/NumberTheory/Transcendental/Lindemann/AnalyticalPart.lean | import Mathlib.Algebra.Polynomial.SumIteratedDerivative
import Mathlib.Analysis.Calculus.Deriv.Polynomial
import Mathlib.Analysis.SpecialFunctions.ExpDeriv
import Mathlib.MeasureTheory.Integral.IntervalIntegral.FundThmCalculus
import Mathlib.RingTheory.Int.Basic
import Mathlib.Topology.Algebra.Polynomial
/-!
# Analytic part of the Lindemann-Weierstrass theorem
-/
namespace LindemannWeierstrass
noncomputable section
open scoped Nat
open Complex Polynomial
theorem hasDerivAt_cexp_mul_sumIDeriv (p : ℂ[X]) (s : ℂ) (x : ℝ) :
HasDerivAt (fun x : ℝ ↦ -(cexp (-(x • s)) * p.sumIDeriv.eval (x • s)))
(s * (cexp (-(x • s)) * p.eval (x • s))) x := by
have h₀ := (hasDerivAt_id' x).smul_const s
have h₁ := h₀.fun_neg.cexp
have h₂ := ((sumIDeriv p).hasDerivAt (x • s)).comp x h₀
convert (h₁.mul h₂).fun_neg using 1
nth_rw 1 [sumIDeriv_eq_self_add p]
simp only [one_smul, eval_add, Function.comp_apply]
ring
theorem integral_exp_mul_eval (p : ℂ[X]) (s : ℂ) :
s * ∫ x in 0..1, exp (-(x • s)) * p.eval (x • s) =
-(exp (-s) * p.sumIDeriv.eval s) + p.sumIDeriv.eval 0 := by
rw [← intervalIntegral.integral_const_mul,
intervalIntegral.integral_eq_sub_of_hasDerivAt
(fun x hx => hasDerivAt_cexp_mul_sumIDeriv p s x)
(ContinuousOn.intervalIntegrable (by fun_prop))]
simp
/--
`P` is a slightly generalized version of `Iᵢ` in
[the wikipedia proof](https://en.wikipedia.org/wiki/Lindemann%E2%80%93Weierstrass_theorem):
`Iᵢ(s) = P(fᵢ, s)`.
-/
private def P (f : ℂ[X]) (s : ℂ) :=
exp s * f.sumIDeriv.eval 0 - f.sumIDeriv.eval s
private theorem P_eq_integral_exp_mul_eval (f : ℂ[X]) (s : ℂ) :
P f s = exp s * (s * ∫ x in 0..1, exp (-(x • s)) * f.eval (x • s)) := by
rw [integral_exp_mul_eval, mul_add, mul_neg, exp_neg, mul_inv_cancel_left₀ (exp_ne_zero s),
neg_add_eq_sub, P]
/--
Given a sequence of complex polynomials `fₚ`, a complex constant `s`, and a real constant `c` such
that `|fₚ(xs)| ≤ c ^ p` for all `p ∈ ℕ` and `x ∈ Ioc 0 1`, then there is also a nonnegative
constant `c'` such that for all nonzero `p ∈ ℕ`, `|P(fₚ, s)| ≤ c' ^ p`.
-/
private theorem P_le_aux (f : ℕ → ℂ[X]) (s : ℂ) (c : ℝ)
(hc : ∀ p : ℕ, ∀ x ∈ Set.Ioc (0 : ℝ) 1, ‖(f p).eval (x • s)‖ ≤ c ^ p) :
∃ c' ≥ 0, ∀ p : ℕ,
‖P (f p) s‖ ≤
Real.exp s.re * (Real.exp ‖s‖ * c' ^ p * ‖s‖) := by
refine ⟨|c|, abs_nonneg _, fun p => ?_⟩
rw [P_eq_integral_exp_mul_eval (f p) s, mul_comm s, norm_mul, norm_mul, norm_exp]
gcongr
rw [intervalIntegral.integral_of_le zero_le_one, ← mul_one (_ * _)]
convert MeasureTheory.norm_setIntegral_le_of_norm_le_const _ _
· rw [Real.volume_real_Ioc_of_le zero_le_one, sub_zero]
· rw [Real.volume_Ioc, sub_zero]; exact ENNReal.ofReal_lt_top
intro x hx
rw [norm_mul, norm_exp]
gcongr
· simp only [Set.mem_Ioc] at hx
apply (re_le_norm _).trans
rw [norm_neg, norm_smul, Real.norm_of_nonneg hx.1.le]
exact mul_le_of_le_one_left (norm_nonneg _) hx.2
· rw [← abs_pow]
exact (hc p x hx).trans (le_abs_self _)
/--
Given a sequence of complex polynomials `fₚ`, a complex constant `s`, and a real constant `c` such
that `|fₚ(xs)| ≤ c ^ p` for all `p ∈ ℕ` and `x ∈ Ioc 0 1`, then there is also a nonnegative
constant `c'` such that for all nonzero `p ∈ ℕ`, `|P(fₚ, s)| ≤ c' ^ p`.
-/
private theorem P_le (f : ℕ → ℂ[X]) (s : ℂ) (c : ℝ)
(hc : ∀ p : ℕ, ∀ x ∈ Set.Ioc (0 : ℝ) 1, ‖(f p).eval (x • s)‖ ≤ c ^ p) :
∃ c' ≥ 0, ∀ p ≠ 0, ‖P (f p) s‖ ≤ c' ^ p := by
obtain ⟨c', hc', h'⟩ := P_le_aux f s c hc; clear c hc
let c₁ := max (Real.exp s.re) 1
let c₂ := max (Real.exp ‖s‖) 1
let c₃ := max ‖s‖ 1
use c₁ * (c₂ * c' * c₃), by positivity
intro p hp
refine (h' p).trans ?_
simp_rw [mul_pow]
have le_max_one_pow {x : ℝ} : x ≤ max x 1 ^ p :=
(max_cases x 1).elim (fun h ↦ h.1.symm ▸ le_self_pow₀ h.2 hp)
fun h ↦ by rw [h.1, one_pow]; exact h.2.le
gcongr <;> exact le_max_one_pow
/--
Given a polynomial with integer coefficients `p` and a complex constant `s`, there is a nonnegative
`c` such that for all nonzero `q ∈ ℕ`, `|P(X ^ (q - 1) * p ^ q, s)| ≤ c ^ q`.
Note: Jacobson writes `h(x)` for `x ^ (q - 1) * p(x) ^ q` and `bⱼ` for its coefficients.
-/
private theorem exp_polynomial_approx_aux (f : ℤ[X]) (s : ℂ) :
∃ c ≥ 0,
∀ p ≠ 0, ‖P (map (algebraMap ℤ ℂ) (X ^ (p - 1) * f ^ p)) s‖ ≤ c ^ p := by
have : Bornology.IsBounded
((fun x : ℝ ↦ max (x * ‖s‖) 1 * ‖aeval (x * s) f‖) '' Set.Ioc 0 1) := by
have h :
(fun x : ℝ ↦ max (x * ‖s‖) 1 * ‖aeval (x * s) f‖) '' Set.Ioc 0 1 ⊆
(fun x : ℝ ↦ max (x * ‖s‖) 1 * ‖aeval (x * s) f‖) '' Set.Icc 0 1 :=
Set.image_mono Set.Ioc_subset_Icc_self
refine (IsCompact.image isCompact_Icc ?_).isBounded.subset h
fun_prop
obtain ⟨c, h⟩ := this.exists_norm_le
simp_rw [Real.norm_eq_abs] at h
refine P_le _ s c (fun p x hx => ?_)
specialize h (max (x * ‖s‖) 1 * ‖aeval (x * s) f‖) (Set.mem_image_of_mem _ hx)
grw [← h]
simp_rw [Polynomial.map_mul, Polynomial.map_pow, map_X, eval_mul, eval_pow, eval_X, norm_mul,
Complex.norm_pow, real_smul, norm_mul, norm_real, ← eval₂_eq_eval_map, ← aeval_def, abs_mul,
abs_norm, mul_pow, Real.norm_of_nonneg hx.1.le]
refine mul_le_mul_of_nonneg_right ?_ (pow_nonneg (norm_nonneg _) _)
rw [← mul_pow, abs_of_nonneg (by positivity), max_def]
split_ifs with hx1
· rw [one_pow]
exact pow_le_one₀ (mul_nonneg hx.1.le (norm_nonneg _)) hx1
· push_neg at hx1
exact pow_le_pow_right₀ hx1.le (Nat.sub_le _ _)
/--
See equation (68), page 285 of [Jacobson, *Basic Algebra I, 4.12*][jacobson1974].
Given a polynomial `f` with integer coefficients, we can find a constant `c : ℝ` and for each prime
`p > |f₀|`, `nₚ : ℤ` and `gₚ : ℤ[X]` such that
* `p` does not divide `nₚ`
* `deg(gₚ) < p * deg(f)`
* all complex roots `r` of `f` satisfy `|nₚ * e ^ r - p * gₚ(r)| ≤ c ^ p / (p - 1)!`
In the proof of Lindemann-Weierstrass, we will take `f` to be a polynomial whose complex roots
are the algebraic numbers whose exponentials we want to prove to be linearly independent.
Note: Jacobson writes `Nₚ` for our `nₚ` and `M` for our `c` (modulo a constant factor).
-/
theorem exp_polynomial_approx (f : ℤ[X]) (hf : f.eval 0 ≠ 0) :
∃ c,
∀ p > (eval 0 f).natAbs, p.Prime →
∃ n : ℤ, ¬ ↑p ∣ n ∧ ∃ gp : ℤ[X], gp.natDegree ≤ p * f.natDegree - 1 ∧
∀ {r : ℂ}, r ∈ f.aroots ℂ →
‖n • exp r - p • aeval r gp‖ ≤ c ^ p / (p - 1)! := by
simp_rw [nsmul_eq_mul, zsmul_eq_mul]
choose c' c'0 Pp'_le using exp_polynomial_approx_aux f
use
if h : ((f.aroots ℂ).map c').toFinset.Nonempty then ((f.aroots ℂ).map c').toFinset.max' h else 0
intro p p_gt prime_p
obtain ⟨gp', -, h'⟩ := eval_sumIDeriv_of_pos (X ^ (p - 1) * f ^ p) prime_p.pos
specialize h' 0 (by rw [C_0, sub_zero])
use f.eval 0 ^ p + p * gp'.eval 0
constructor
· rw [dvd_add_left (dvd_mul_right _ _)]
contrapose! p_gt with h
exact Nat.le_of_dvd (Int.natAbs_pos.mpr hf) (Int.natCast_dvd.mp (Int.Prime.dvd_pow' prime_p h))
obtain ⟨gp, gp'_le, h⟩ := aeval_sumIDeriv ℂ (X ^ (p - 1) * f ^ p) p
refine ⟨gp, ?_, ?_⟩
· refine gp'_le.trans ((tsub_le_tsub_right natDegree_mul_le p).trans ?_)
rw [natDegree_X_pow, natDegree_pow, tsub_add_eq_add_tsub prime_p.one_le, tsub_right_comm,
add_tsub_cancel_left]
intro r hr
specialize h r _
· rw [mem_roots'] at hr
rw [Polynomial.map_mul, f.map_pow]
exact dvd_mul_of_dvd_right (pow_dvd_pow_of_dvd (dvd_iff_isRoot.mpr hr.2) _) _
rw [nsmul_eq_mul] at h
have :
(↑(eval 0 f ^ p + p * eval 0 gp') * cexp r - p * (aeval r) gp) * (p - 1)! =
((eval 0 f ^ p * cexp r) * (p - 1)! +
↑(p * (p - 1)!) * (eval 0 gp' * cexp r - (aeval r) gp)) := by
push_cast; ring
rw [le_div_iff₀ (Nat.cast_pos.mpr (Nat.factorial_pos _) : (0 : ℝ) < _), ← norm_natCast,
← norm_mul, this, Nat.mul_factorial_pred prime_p.ne_zero, mul_sub, ← h]
have :
↑(eval 0 f) ^ p * cexp r * ↑(p - 1)! +
(↑p ! * (↑(eval 0 gp') * cexp r) - (aeval r) (sumIDeriv (X ^ (p - 1) * f ^ p))) =
((p - 1)! • ↑(eval 0 (f ^ p)) + p ! • ↑(eval 0 gp') : ℤ) * cexp r -
(aeval r) (sumIDeriv (X ^ (p - 1) * f ^ p)) := by
simp; ring
rw [this, ← h', mul_comm, ← eq_intCast (algebraMap ℤ ℂ),
← aeval_algebraMap_apply_eq_algebraMap_eval, map_zero,
aeval_sumIDeriv_eq_eval, aeval_sumIDeriv_eq_eval, ← P]
refine (Pp'_le r p prime_p.ne_zero).trans (pow_le_pow_left₀ (c'0 r) ?_ _)
have aux : c' r ∈ (Multiset.map c' (f.aroots ℂ)).toFinset := by
simpa only [Multiset.mem_toFinset] using Multiset.mem_map_of_mem _ hr
have h : ((f.aroots ℂ).map c').toFinset.Nonempty := ⟨c' r, aux⟩
simpa only [h, ↓reduceDIte] using Finset.le_max' _ _ aux
end
end LindemannWeierstrass |
.lake/packages/mathlib/Mathlib/NumberTheory/RamificationInertia/Galois.lean | import Mathlib.FieldTheory.Galois.IsGaloisGroup
import Mathlib.NumberTheory.RamificationInertia.Basic
/-!
# Ramification theory in Galois extensions of Dedekind domains
In this file, we discuss the ramification theory in Galois extensions of Dedekind domains, which is
also called Hilbert's Ramification Theory.
Assume `B / A` is a finite extension of Dedekind domains, `K` is the fraction ring of `A`,
`L` is the fraction ring of `K`, `L / K` is a Galois extension.
## Main definitions
* `Ideal.ramificationIdxIn`: It can be seen from
the theorem `Ideal.ramificationIdx_eq_of_IsGalois` that all `Ideal.ramificationIdx` over a fixed
maximal ideal `p` of `A` are the same, which we define as `Ideal.ramificationIdxIn`.
* `Ideal.inertiaDegIn`: It can be seen from
the theorem `Ideal.inertiaDeg_eq_of_IsGalois` that all `Ideal.inertiaDeg` over a fixed
maximal ideal `p` of `A` are the same, which we define as `Ideal.inertiaDegIn`.
## Main results
* `Ideal.ncard_primesOver_mul_ramificationIdxIn_mul_inertiaDegIn`: Let `p` be a prime of `A`,
`r` be the number of prime ideals lying over `p`, `e` be the ramification index of `p` in `B`,
and `f` be the inertia degree of `p` in `B`. Then `r * (e * f) = [L : K]`. It is the form of the
`Ideal.sum_ramification_inertia` in the case of Galois extension.
* `Ideal.card_inertia_eq_ramificationIdxIn`:
The cardinality of the inertia group is equal to the ramification index.
## References
* [J Neukirch, *Algebraic Number Theory*][Neukirch1992]
-/
open Algebra Pointwise
attribute [local instance] FractionRing.liftAlgebra
namespace Ideal
open scoped Classical in
/-- If `L / K` is a Galois extension, it can be seen from the theorem
`Ideal.ramificationIdx_eq_of_IsGalois` that all `Ideal.ramificationIdx` over a fixed
maximal ideal `p` of `A` are the same, which we define as `Ideal.ramificationIdxIn`. -/
noncomputable def ramificationIdxIn {A : Type*} [CommRing A] (p : Ideal A)
(B : Type*) [CommRing B] [Algebra A B] : ℕ :=
if h : ∃ P : Ideal B, P.IsPrime ∧ P.LiesOver p then p.ramificationIdx (algebraMap A B) h.choose
else 0
open scoped Classical in
/-- If `L / K` is a Galois extension, it can be seen from
the theorem `Ideal.inertiaDeg_eq_of_IsGalois` that all `Ideal.inertiaDeg` over a fixed
maximal ideal `p` of `A` are the same, which we define as `Ideal.inertiaDegIn`. -/
noncomputable def inertiaDegIn {A : Type*} [CommRing A] (p : Ideal A)
(B : Type*) [CommRing B] [Algebra A B] : ℕ :=
if h : ∃ P : Ideal B, P.IsPrime ∧ P.LiesOver p then p.inertiaDeg h.choose else 0
section MulAction
variable {A B : Type*} [CommRing A] [CommRing B] [Algebra A B] {p : Ideal A}
{G : Type*} [Group G] [MulSemiringAction G B] [SMulCommClass G A B]
instance : MulAction G (primesOver p B) where
smul σ Q := primesOver.mk p (σ • Q.1)
one_smul Q := Subtype.ext (one_smul G Q.1)
mul_smul σ τ Q := Subtype.ext (mul_smul σ τ Q.1)
@[simp]
theorem coe_smul_primesOver (σ : G) (P : primesOver p B) : (σ • P).1 = σ • P.1 :=
rfl
@[simp]
theorem coe_smul_primesOver_mk (σ : G) (P : Ideal B) [P.IsPrime] [P.LiesOver p] :
(σ • primesOver.mk p P).1 = σ • P :=
rfl
variable (K L : Type*) [Field K] [Field L] [Algebra A K] [IsFractionRing A K] [Algebra B L]
[Algebra K L] [Algebra A L] [IsScalarTower A B L] [IsScalarTower A K L]
[IsIntegralClosure B A L] [FiniteDimensional K L]
noncomputable instance : MulAction Gal(L/K) (primesOver p B) where
smul σ Q := primesOver.mk p (map (galRestrict A K L B σ) Q.1)
one_smul Q := by
apply Subtype.val_inj.mp
change map _ Q.1 = Q.1
simpa only [map_one] using map_id Q.1
mul_smul σ τ Q := by
apply Subtype.val_inj.mp
change map _ Q.1 = map _ (map _ Q.1)
rw [map_mul]
exact (Q.1.map_map ((galRestrict A K L B) τ).toRingHom ((galRestrict A K L B) σ).toRingHom).symm
theorem coe_smul_primesOver_eq_map_galRestrict (σ : Gal(L/K)) (P : primesOver p B) :
(σ • P).1 = map (galRestrict A K L B σ) P :=
rfl
theorem coe_smul_primesOver_mk_eq_map_galRestrict (σ : Gal(L/K)) (P : Ideal B) [P.IsPrime]
[P.LiesOver p] : (σ • primesOver.mk p P).1 = map (galRestrict A K L B σ) P :=
rfl
end MulAction
section RamificationInertia
variable {A B : Type*} [CommRing A] [CommRing B] [Algebra A B] (p : Ideal A) (P Q : Ideal B)
[hPp : P.IsPrime] [hp : P.LiesOver p] [hQp : Q.IsPrime] [Q.LiesOver p]
(G : Type*) [Group G] [Finite G] [MulSemiringAction G B] [IsGaloisGroup G A B]
include p in
/-- If `p` is a maximal ideal of `A`, `P` and `Q` are prime ideals
lying over `p`, then there exists `σ ∈ Aut (B / A)` such that `σ P = Q`. In other words,
the Galois group `Gal(L / K)` acts transitively on the set of all prime ideals lying over `p`. -/
theorem exists_smul_eq_of_isGaloisGroup : ∃ σ : G, σ • P = Q := by
rcases IsInvariant.exists_smul_of_under_eq A B G P Q <|
(over_def P p).symm.trans (over_def Q p) with ⟨σ, hs⟩
exact ⟨σ, hs.symm⟩
@[deprecated (since := "2025-10-26")]
alias exists_map_eq_of_isGalois := exists_smul_eq_of_isGaloisGroup
instance isPretransitive_of_isGaloisGroup : MulAction.IsPretransitive G (primesOver p B) where
exists_smul_eq := by
intro ⟨P, _, _⟩ ⟨Q, _, _⟩
rcases exists_smul_eq_of_isGaloisGroup p P Q G with ⟨σ, hs⟩
exact ⟨σ, Subtype.val_inj.mp hs⟩
@[deprecated (since := "2025-10-26")]
alias isPretransitive_of_isGalois := isPretransitive_of_isGaloisGroup
include G in
/-- All the `ramificationIdx` over a fixed maximal ideal are the same. -/
theorem ramificationIdx_eq_of_isGaloisGroup :
ramificationIdx (algebraMap A B) p P = ramificationIdx (algebraMap A B) p Q := by
rcases exists_smul_eq_of_isGaloisGroup p P Q G with ⟨σ, rfl⟩
exact (ramificationIdx_map_eq p P (MulSemiringAction.toAlgEquiv A B σ)).symm
@[deprecated (since := "2025-10-26")]
alias ramificationIdx_eq_of_isGalois := ramificationIdx_eq_of_isGaloisGroup
include G in
/-- All the `inertiaDeg` over a fixed maximal ideal are the same. -/
theorem inertiaDeg_eq_of_isGaloisGroup [p.IsMaximal] :
inertiaDeg p P = inertiaDeg p Q := by
rcases exists_smul_eq_of_isGaloisGroup p P Q G with ⟨σ, rfl⟩
exact (inertiaDeg_map_eq p P (MulSemiringAction.toAlgEquiv A B σ)).symm
@[deprecated (since := "2025-10-26")]
alias inertiaDeg_eq_of_isGalois := inertiaDeg_eq_of_isGaloisGroup
include G in
/-- The `ramificationIdxIn` is equal to any ramification index over the same ideal. -/
theorem ramificationIdxIn_eq_ramificationIdx :
ramificationIdxIn p B = ramificationIdx (algebraMap A B) p P := by
have h : ∃ P : Ideal B, P.IsPrime ∧ P.LiesOver p := ⟨P, hPp, hp⟩
obtain ⟨_, _⟩ := h.choose_spec
rw [ramificationIdxIn, dif_pos h]
exact ramificationIdx_eq_of_isGaloisGroup p h.choose P G
include G in
theorem ramificationIdxIn_ne_zero [IsDedekindDomain B] {p : Ideal A} [p.IsPrime] (hp : p ≠ ⊥)
[NoZeroSMulDivisors A B] : p.ramificationIdxIn B ≠ 0 := by
have : Algebra.IsIntegral A B := IsGaloisGroup.isInvariant.isIntegral A B G
obtain ⟨P⟩ := (inferInstance : Nonempty (primesOver p B))
rw [ramificationIdxIn_eq_ramificationIdx p P G]
exact IsDedekindDomain.ramificationIdx_ne_zero_of_liesOver P.1 hp
include G in
/-- The `inertiaDegIn` is equal to any ramification index over the same ideal. -/
theorem inertiaDegIn_eq_inertiaDeg [p.IsMaximal] :
inertiaDegIn p B = inertiaDeg p P := by
have h : ∃ P : Ideal B, P.IsPrime ∧ P.LiesOver p := ⟨P, hPp, hp⟩
obtain ⟨_, _⟩ := h.choose_spec
rw [inertiaDegIn, dif_pos h]
exact inertiaDeg_eq_of_isGaloisGroup p h.choose P G
include G in
theorem inertiaDegIn_ne_zero {p : Ideal A} [p.IsMaximal] [NoZeroSMulDivisors A B]
[Module.Finite A B] [Nontrivial B] :
inertiaDegIn p B ≠ 0 := by
obtain ⟨P⟩ := (inferInstance : Nonempty (primesOver p B))
rw [inertiaDegIn_eq_inertiaDeg p P G]
exact inertiaDeg_ne_zero _ _
end RamificationInertia
section fundamental_identity
variable {A : Type*} [CommRing A] [IsDedekindDomain A] {p : Ideal A} (hpb : p ≠ ⊥) [p.IsMaximal]
(B : Type*) [CommRing B] [IsDedekindDomain B] [Algebra A B] [Module.Finite A B]
[NoZeroSMulDivisors A B]
(G : Type*) [Group G] [Finite G] [MulSemiringAction G B] [IsGaloisGroup G A B]
include hpb in
/-- The form of the **fundamental identity** in the case of Galois extension. -/
theorem ncard_primesOver_mul_ramificationIdxIn_mul_inertiaDegIn :
(primesOver p B).ncard * (ramificationIdxIn p B * inertiaDegIn p B) = Nat.card G := by
let K := FractionRing A
let L := FractionRing B
let _ : MulSemiringAction G L := MulSemiringAction.compHom L
((IsFractionRing.fieldEquivOfAlgEquivHom K L).comp (MulSemiringAction.toAlgAut G A B))
have : SMulDistribClass G B L := ⟨fun g b x ↦ by
rw [Algebra.smul_def', Algebra.smul_def', smul_mul']
congr
exact IsFractionRing.fieldEquivOfAlgEquiv_algebraMap K L L _ b⟩
have hGKL : IsGaloisGroup G K L := IsGaloisGroup.to_isFractionRing G A B K L
rw [← smul_eq_mul, ← coe_primesOverFinset hpb B, Set.ncard_coe_finset, ← Finset.sum_const]
rw [hGKL.card_eq_finrank, ← sum_ramification_inertia B K L hpb]
apply Finset.sum_congr rfl
intro P hp
rw [← Finset.mem_coe, coe_primesOverFinset hpb B] at hp
obtain ⟨_, _⟩ := hp
rw [ramificationIdxIn_eq_ramificationIdx p P G, inertiaDegIn_eq_inertiaDeg p P G]
end fundamental_identity
section inertia
variable {R S G : Type*} [CommRing R] [CommRing S] [Algebra R S] [Group G]
[MulSemiringAction G S] [IsGaloisGroup G R S] [Finite G]
open scoped Pointwise
open Algebra
attribute [local instance 1001] Ideal.Quotient.field Module.Free.of_divisionRing in
lemma ncard_primesOver_mul_card_inertia_mul_finrank (p : Ideal R) [p.IsMaximal]
(P : Ideal S) [P.LiesOver p] [P.IsMaximal] [Algebra.IsSeparable (R ⧸ p) (S ⧸ P)] :
(p.primesOver S).ncard * Nat.card (P.toAddSubgroup.inertia G) *
Module.finrank (R ⧸ p) (S ⧸ P) = Nat.card G := by
trans (p.primesOver S).ncard * Nat.card (MulAction.stabilizer G P); swap
· rw [← IsInvariant.orbit_eq_primesOver R S G p P]
simpa using Nat.card_congr (MulAction.orbitProdStabilizerEquivGroup G P)
rw [mul_assoc]
have : IsGalois (R ⧸ p) (S ⧸ P) := { __ := Ideal.Quotient.normal (A := R) G p P }
have := Ideal.Quotient.finite_of_isInvariant G p P
congr 1
have : Subgroup.index _ = _ := Nat.card_congr
(QuotientGroup.quotientKerEquivOfSurjective (Ideal.Quotient.stabilizerHom P p G)
(Ideal.Quotient.stabilizerHom_surjective G p P)).toEquiv
rw [← IsGalois.card_aut_eq_finrank, ← this]
convert (Ideal.Quotient.stabilizerHom P p G).ker.card_mul_index using 2
rw [Ideal.Quotient.ker_stabilizerHom]
refine Nat.card_congr (Subgroup.subgroupOfEquivOfLe ?_).toEquiv.symm
intro σ hσ
ext x
rw [Ideal.pointwise_smul_eq_comap, Ideal.mem_comap]
convert P.add_mem_iff_right (inv_mem hσ x) (b := x) using 2
simp
/-- The cardinality of the inertia group is equal to the ramification index. -/
lemma card_inertia_eq_ramificationIdxIn
[IsDedekindDomain R] [IsDedekindDomain S] [Module.Finite R S]
[NoZeroSMulDivisors R S]
(p : Ideal R) (hp : p ≠ ⊥)
(P : Ideal S) [P.LiesOver p] [P.IsMaximal] [Algebra.IsSeparable (R ⧸ p) (S ⧸ P)] :
Nat.card (P.toAddSubgroup.inertia G) = Ideal.ramificationIdxIn p S := by
have := (show p.IsPrime from P.over_def p ▸ inferInstance).isMaximal hp
have H := ncard_primesOver_mul_card_inertia_mul_finrank (G := G) p P
refine mul_right_injective₀ (primesOver_ncard_ne_zero p S) ?_
refine mul_left_injective₀ (b := Module.finrank (R ⧸ p) (S ⧸ P)) ?_ ?_
· intro e; simp [e, eq_comm, Nat.card_eq_zero, ‹Finite G›.not_infinite] at H
dsimp only
rw [H, mul_assoc, ← Ideal.inertiaDeg_algebraMap,
← Ideal.inertiaDegIn_eq_inertiaDeg p P G,
Ideal.ncard_primesOver_mul_ramificationIdxIn_mul_inertiaDegIn hp S G]
end inertia
end Ideal |
.lake/packages/mathlib/Mathlib/NumberTheory/RamificationInertia/Unramified.lean | import Mathlib.NumberTheory.RamificationInertia.Basic
import Mathlib.RingTheory.LocalRing.ResidueField.Instances
import Mathlib.RingTheory.Unramified.LocalRing
/-!
# Unramified and ramification index
We connect `Ideal.ramificationIdx` to the commutative algebra notion predicate of `IsUnramifiedAt`.
## Main result
- `Algebra.isUnramifiedAt_iff_of_isDedekindDomain`:
Let `R` be a domain of characteristic 0, finite rank over `ℤ`, `S ⊇ R` be a Dedekind domain
that is a finite `R`-algebra. Let `p` be a prime of `S`, then `p` is unramified iff `e(p) = 1`.
-/
variable {R S T : Type*} [CommRing R] [CommRing S] [CommRing T]
variable [Algebra R S] [Algebra S T] [Algebra R T] [IsScalarTower R S T]
local notation3 "e(" P "|" R ")" =>
Ideal.ramificationIdx (algebraMap _ _) (Ideal.under R P) P
open IsLocalRing Algebra
lemma Ideal.ramificationIdx_eq_one_of_isUnramifiedAt
{p : Ideal S} [p.IsPrime] [IsNoetherianRing S] [IsUnramifiedAt R p]
(hp : p ≠ ⊥) [IsDomain S] [EssFiniteType R S] :
e(p|R) = 1 :=
(Ideal.ramificationIdx_eq_one_of_map_localization Ideal.map_comap_le hp
p.primeCompl_le_nonZeroDivisors
((isUnramifiedAt_iff_map_eq R (p.under R) p).mp ‹_›).2)
variable (R) in
lemma IsUnramifiedAt.of_liesOver_of_ne_bot
(p : Ideal S) (P : Ideal T) [P.LiesOver p] [p.IsPrime] [P.IsPrime]
[IsUnramifiedAt R P] [EssFiniteType R S] [EssFiniteType R T]
[IsDedekindDomain S] (hP₁ : P.primeCompl ≤ nonZeroDivisors T) (hP₂ : p ≠ ⊥ → P ≠ ⊥) :
IsUnramifiedAt R p := by
let p₀ : Ideal R := p.under R
have : P.LiesOver p₀ := .trans P p p₀
have hp₀ : p₀ = P.under R := Ideal.LiesOver.over
have : EssFiniteType S T := .of_comp R S T
have := Algebra.EssFiniteType.isNoetherianRing S T
rw [isUnramifiedAt_iff_map_eq R p₀ p]
have ⟨h₁, h₂⟩ := (isUnramifiedAt_iff_map_eq R p₀ P).mp ‹_›
refine ⟨Algebra.isSeparable_tower_bot_of_isSeparable _ _ P.ResidueField, ?_⟩
by_cases hp : p = ⊥
· have : p₀.map (algebraMap R S) = p := by
subst hp
exact le_bot_iff.mp (Ideal.map_comap_le)
rw [IsScalarTower.algebraMap_eq _ S, ← Ideal.map_map, this,
Localization.AtPrime.map_eq_maximalIdeal]
rw [← Ideal.IsDedekindDomain.ramificationIdx_eq_one_iff hp Ideal.map_comap_le,
← not_ne_iff, Ideal.ramificationIdx_ne_one_iff Ideal.map_comap_le]
intro H
have := Ideal.ramificationIdx_eq_one_of_map_localization
(hp₀ ▸ Ideal.map_comap_le) (hP₂ hp) hP₁ h₂
rw [← not_ne_iff, Ideal.ramificationIdx_ne_one_iff (hp₀ ▸ Ideal.map_comap_le)] at this
replace H := Ideal.map_mono (f := algebraMap S T) H
rw [Ideal.map_map, ← IsScalarTower.algebraMap_eq, Ideal.map_pow] at H
refine this (H.trans (Ideal.pow_right_mono ?_ _))
exact Ideal.map_le_iff_le_comap.mpr Ideal.LiesOver.over.le
variable (R) in
/--
Up to technical conditions, If `T/S/R` is a tower of algebras, `P` is a prime of `T` unramified
in `R`, then `P ∩ S` (as a prime of `S`) is also unramified in `R`.
-/
lemma Algebra.IsUnramifiedAt.of_liesOver
(p : Ideal S) (P : Ideal T) [P.LiesOver p] [p.IsPrime] [P.IsPrime]
[IsUnramifiedAt R P] [EssFiniteType R S] [EssFiniteType R T]
[IsDedekindDomain S] [IsDomain T] [NoZeroSMulDivisors S T] : IsUnramifiedAt R p :=
IsUnramifiedAt.of_liesOver_of_ne_bot R p P P.primeCompl_le_nonZeroDivisors
(Ideal.ne_bot_of_liesOver_of_ne_bot · P)
set_option synthInstance.maxHeartbeats 25000 in -- infer_instance timeout
/-- Let `R` be a domain of characteristic 0, finite rank over `ℤ`, `S` be a Dedekind domain
that is a finite `R`-algebra. Let `p` be a prime of `S`, then `p` is unramified iff `e(p) = 1`. -/
lemma Algebra.isUnramifiedAt_iff_of_isDedekindDomain
{p : Ideal S} [p.IsPrime] [IsDedekindDomain S] [EssFiniteType R S] [IsDomain R]
[Module.Finite ℤ R] [CharZero R] [Algebra.IsIntegral R S]
(hp : p ≠ ⊥) :
Algebra.IsUnramifiedAt R p ↔ e(p|R) = 1 := by
rw [isUnramifiedAt_iff_map_eq R (p.under R) p, and_iff_right,
Ideal.IsDedekindDomain.ramificationIdx_eq_one_iff hp Ideal.map_comap_le]
have : Finite (R ⧸ p.under R) :=
Ideal.finiteQuotientOfFreeOfNeBot _ (mt Ideal.eq_bot_of_comap_eq_bot hp)
have : Finite ((p.under R).ResidueField) := IsLocalization.finite _
(nonZeroDivisors (R ⧸ p.under R))
infer_instance |
.lake/packages/mathlib/Mathlib/NumberTheory/RamificationInertia/Basic.lean | import Mathlib.LinearAlgebra.Dimension.DivisionRing
import Mathlib.RingTheory.DedekindDomain.Ideal.Lemmas
import Mathlib.RingTheory.Finiteness.Quotient
import Mathlib.RingTheory.Ideal.Norm.AbsNorm
/-!
# Ramification index and inertia degree
Given `P : Ideal S` lying over `p : Ideal R` for the ring extension `f : R →+* S`
(assuming `P` and `p` are prime or maximal where needed),
the **ramification index** `Ideal.ramificationIdx f p P` is the multiplicity of `P` in `map f p`,
and the **inertia degree** `Ideal.inertiaDeg f p P` is the degree of the field extension
`(S / P) : (R / p)`.
## Main results
The main theorem `Ideal.sum_ramification_inertia` states that for all coprime `P` lying over `p`,
`Σ P, ramification_idx f p P * inertia_deg f p P` equals the degree of the field extension
`Frac(S) : Frac(R)`.
## Implementation notes
Often the above theory is set up in the case where:
* `R` is the ring of integers of a number field `K`,
* `L` is a finite separable extension of `K`,
* `S` is the integral closure of `R` in `L`,
* `p` and `P` are maximal ideals,
* `P` is an ideal lying over `p`
We will try to relax the above hypotheses as much as possible.
## Notation
In this file, `e` stands for the ramification index and `f` for the inertia degree of `P` over `p`,
leaving `p` and `P` implicit.
-/
namespace Ideal
universe u v
variable {R : Type u} [CommRing R]
variable {S : Type v} [CommRing S] (f : R →+* S)
variable (p : Ideal R) (P : Ideal S)
open Module
open UniqueFactorizationMonoid
attribute [local instance] Ideal.Quotient.field
section DecEq
/-- The ramification index of `P` over `p` is the largest exponent `n` such that
`p` is contained in `P^n`.
In particular, if `p` is not contained in `P^n`, then the ramification index is 0.
If there is no largest such `n` (e.g. because `p = ⊥`), then `ramificationIdx` is
defined to be 0.
-/
noncomputable def ramificationIdx : ℕ := sSup {n | map f p ≤ P ^ n}
variable {f p P}
theorem ramificationIdx_eq_find [DecidablePred fun n ↦ ∀ (k : ℕ), map f p ≤ P ^ k → k ≤ n]
(h : ∃ n, ∀ k, map f p ≤ P ^ k → k ≤ n) :
ramificationIdx f p P = Nat.find h := by
convert Nat.sSup_def h
theorem ramificationIdx_eq_zero (h : ∀ n : ℕ, ∃ k, map f p ≤ P ^ k ∧ n < k) :
ramificationIdx f p P = 0 :=
dif_neg (by push_neg; exact h)
theorem ramificationIdx_spec {n : ℕ} (hle : map f p ≤ P ^ n) (hgt : ¬map f p ≤ P ^ (n + 1)) :
ramificationIdx f p P = n := by
classical
let Q : ℕ → Prop := fun m => ∀ k : ℕ, map f p ≤ P ^ k → k ≤ m
have : Q n := by
intro k hk
refine le_of_not_gt fun hnk => ?_
exact hgt (hk.trans (Ideal.pow_le_pow_right hnk))
rw [ramificationIdx_eq_find ⟨n, this⟩]
refine le_antisymm (Nat.find_min' _ this) (le_of_not_gt fun h : Nat.find _ < n => ?_)
obtain this' := Nat.find_spec ⟨n, this⟩
exact h.not_ge (this' _ hle)
theorem ramificationIdx_lt {n : ℕ} (hgt : ¬map f p ≤ P ^ n) : ramificationIdx f p P < n := by
classical
rcases n with - | n
· simp at hgt
· rw [Nat.lt_succ_iff]
have : ∀ k, map f p ≤ P ^ k → k ≤ n := by
refine fun k hk => le_of_not_gt fun hnk => ?_
exact hgt (hk.trans (Ideal.pow_le_pow_right hnk))
rw [ramificationIdx_eq_find ⟨n, this⟩]
exact Nat.find_min' ⟨n, this⟩ this
@[simp]
theorem ramificationIdx_bot : ramificationIdx f ⊥ P = 0 :=
dif_neg <| not_exists.mpr fun n hn => n.lt_succ_self.not_ge (hn _ (by simp))
@[simp]
theorem ramificationIdx_of_not_le (h : ¬map f p ≤ P) : ramificationIdx f p P = 0 :=
ramificationIdx_spec (by simp) (by simpa using h)
theorem ramificationIdx_ne_zero {e : ℕ} (he : e ≠ 0) (hle : map f p ≤ P ^ e)
(hnle : ¬map f p ≤ P ^ (e + 1)) : ramificationIdx f p P ≠ 0 := by
rwa [ramificationIdx_spec hle hnle]
theorem le_pow_of_le_ramificationIdx {n : ℕ} (hn : n ≤ ramificationIdx f p P) :
map f p ≤ P ^ n := by
contrapose! hn
exact ramificationIdx_lt hn
theorem le_pow_ramificationIdx : map f p ≤ P ^ ramificationIdx f p P :=
le_pow_of_le_ramificationIdx (le_refl _)
theorem le_comap_pow_ramificationIdx : p ≤ comap f (P ^ ramificationIdx f p P) :=
map_le_iff_le_comap.mp le_pow_ramificationIdx
theorem le_comap_of_ramificationIdx_ne_zero (h : ramificationIdx f p P ≠ 0) : p ≤ comap f P :=
Ideal.map_le_iff_le_comap.mp <| le_pow_ramificationIdx.trans <| Ideal.pow_le_self <| h
variable {S₁ : Type*} [CommRing S₁] [Algebra R S₁]
variable (p) in
lemma ramificationIdx_comap_eq [Algebra R S] (e : S ≃ₐ[R] S₁) (P : Ideal S₁) :
ramificationIdx (algebraMap R S) p (P.comap e) = ramificationIdx (algebraMap R S₁) p P := by
dsimp only [ramificationIdx]
congr 1
ext n
simp only [Set.mem_setOf_eq, Ideal.map_le_iff_le_comap]
rw [← comap_coe e, ← e.toRingEquiv_toRingHom, comap_coe, ← RingEquiv.symm_symm (e : S ≃+* S₁),
← map_comap_of_equiv, ← Ideal.map_pow, map_comap_of_equiv, ← comap_coe (RingEquiv.symm _),
comap_comap, RingEquiv.symm_symm, e.toRingEquiv_toRingHom, ← e.toAlgHom_toRingHom,
AlgHom.comp_algebraMap]
variable (p) in
lemma ramificationIdx_map_eq [Algebra R S] {E : Type*} [EquivLike E S S₁] [AlgEquivClass E R S S₁]
(P : Ideal S) (e : E) :
ramificationIdx (algebraMap R S₁) p (P.map e) = ramificationIdx (algebraMap R S) p P := by
rw [show P.map e = _ from P.map_comap_of_equiv (e : S ≃+* S₁)]
exact p.ramificationIdx_comap_eq (e : S ≃ₐ[R] S₁).symm P
lemma ramificationIdx_ne_one_iff (hp : map f p ≤ P) :
ramificationIdx f p P ≠ 1 ↔ p.map f ≤ P ^ 2 := by
classical
by_cases! H : ∀ n : ℕ, ∃ k, p.map f ≤ P ^ k ∧ n < k
· obtain ⟨k, hk, h2k⟩ := H 2
simp [Ideal.ramificationIdx_eq_zero H, hk.trans (Ideal.pow_le_pow_right h2k.le)]
rw [Ideal.ramificationIdx_eq_find H]
constructor
· intro he
have : 1 ≤ Nat.find H := Nat.find_spec H 1 (by simpa)
have := Nat.find_min H (m := 1) (by omega)
push_neg at this
obtain ⟨k, hk, h1k⟩ := this
exact hk.trans (Ideal.pow_le_pow_right (Nat.succ_le.mpr h1k))
· intro he
have := Nat.find_spec H 2 he
omega
open IsLocalRing in
/-- The converse is true when `S` is a Dedekind domain.
See `Ideal.ramificationIdx_eq_one_iff_of_isDedekindDomain`. -/
lemma ramificationIdx_eq_one_of_map_localization
[Algebra R S] {p : Ideal R} {P : Ideal S} [P.IsPrime] [IsNoetherianRing S]
(hpP : map (algebraMap R S) p ≤ P) (hp : P ≠ ⊥) (hp' : P.primeCompl ≤ nonZeroDivisors S)
(H : p.map (algebraMap R (Localization.AtPrime P)) = maximalIdeal (Localization.AtPrime P)) :
ramificationIdx (algebraMap R S) p P = 1 := by
rw [← not_ne_iff (b := 1), Ideal.ramificationIdx_ne_one_iff hpP]
intro h₂
replace h₂ := Ideal.map_mono (f := algebraMap S (Localization.AtPrime P)) h₂
rw [Ideal.map_pow, Localization.AtPrime.map_eq_maximalIdeal, Ideal.map_map,
← IsScalarTower.algebraMap_eq, H, pow_two] at h₂
have := Submodule.eq_bot_of_le_smul_of_le_jacobson_bot _ _ (IsNoetherian.noetherian _) h₂
(maximalIdeal_le_jacobson _)
rw [← Localization.AtPrime.map_eq_maximalIdeal, Ideal.map_eq_bot_iff_of_injective] at this
· exact hp this
· exact IsLocalization.injective _ hp'
namespace IsDedekindDomain
variable [IsDedekindDomain S]
theorem ramificationIdx_eq_normalizedFactors_count [DecidableEq (Ideal S)]
(hp0 : map f p ≠ ⊥) (hP : P.IsPrime)
(hP0 : P ≠ ⊥) : ramificationIdx f p P = (normalizedFactors (map f p)).count P := by
have hPirr := (Ideal.prime_of_isPrime hP0 hP).irreducible
refine ramificationIdx_spec (Ideal.le_of_dvd ?_) (mt Ideal.dvd_iff_le.mpr ?_) <;>
rw [dvd_iff_normalizedFactors_le_normalizedFactors (pow_ne_zero _ hP0) hp0,
normalizedFactors_pow, normalizedFactors_irreducible hPirr, normalize_eq,
Multiset.nsmul_singleton, ← Multiset.le_count_iff_replicate_le]
exact (Nat.lt_succ_self _).not_ge
theorem ramificationIdx_eq_multiplicity (hp : map f p ≠ ⊥) (hP : P.IsPrime) :
ramificationIdx f p P = multiplicity P (Ideal.map f p) := by
classical
by_cases hP₂ : P = ⊥
· rw [hP₂, ← Ideal.zero_eq_bot, multiplicity_zero_eq_zero_of_ne_zero _ hp]
exact Ideal.ramificationIdx_of_not_le (mt le_bot_iff.mp hp)
rw [multiplicity_eq_of_emultiplicity_eq_some]
rw [ramificationIdx_eq_normalizedFactors_count hp hP hP₂, ← normalize_eq P,
← UniqueFactorizationMonoid.emultiplicity_eq_count_normalizedFactors _ hp, normalize_eq]
exact irreducible_iff_prime.mpr <| prime_of_isPrime hP₂ hP
theorem ramificationIdx_eq_factors_count [DecidableEq (Ideal S)]
(hp0 : map f p ≠ ⊥) (hP : P.IsPrime) (hP0 : P ≠ ⊥) :
ramificationIdx f p P = (factors (map f p)).count P := by
rw [IsDedekindDomain.ramificationIdx_eq_normalizedFactors_count hp0 hP hP0,
factors_eq_normalizedFactors]
theorem ramificationIdx_ne_zero (hp0 : map f p ≠ ⊥) (hP : P.IsPrime) (le : map f p ≤ P) :
ramificationIdx f p P ≠ 0 := by
classical
have hP0 : P ≠ ⊥ := by
rintro rfl
exact hp0 (le_bot_iff.mp le)
have hPirr := (Ideal.prime_of_isPrime hP0 hP).irreducible
rw [IsDedekindDomain.ramificationIdx_eq_normalizedFactors_count hp0 hP hP0]
obtain ⟨P', hP', P'_eq⟩ :=
exists_mem_normalizedFactors_of_dvd hp0 hPirr (Ideal.dvd_iff_le.mpr le)
rwa [Multiset.count_ne_zero, associated_iff_eq.mp P'_eq]
theorem ramificationIdx_ne_zero_of_liesOver [Algebra R S] [NoZeroSMulDivisors R S]
(P : Ideal S) [hP : P.IsPrime] {p : Ideal R} (hp : p ≠ ⊥) [hPp : P.LiesOver p] :
ramificationIdx (algebraMap R S) p P ≠ 0 :=
IsDedekindDomain.ramificationIdx_ne_zero (map_ne_bot_of_ne_bot hp) hP <|
map_le_iff_le_comap.mpr <| le_of_eq <| (liesOver_iff _ _).mp hPp
open IsLocalRing in
lemma ramificationIdx_eq_one_iff
[Algebra R S] {p : Ideal R} {P : Ideal S} [P.IsPrime]
(hp : P ≠ ⊥) (hpP : p.map (algebraMap R S) ≤ P) :
ramificationIdx (algebraMap R S) p P = 1 ↔
p.map (algebraMap R (Localization.AtPrime P)) = maximalIdeal (Localization.AtPrime P) := by
refine ⟨?_, ramificationIdx_eq_one_of_map_localization hpP hp (primeCompl_le_nonZeroDivisors _)⟩
let Sₚ := Localization.AtPrime P
rw [← not_ne_iff (b := 1), ramificationIdx_ne_one_iff hpP, pow_two]
intro H₁
obtain ⟨a, ha⟩ : P ∣ p.map (algebraMap R S) := Ideal.dvd_iff_le.mpr hpP
have ha' : ¬ a ≤ P := fun h ↦ H₁ (ha.trans_le (Ideal.mul_mono_right h))
rw [IsScalarTower.algebraMap_eq _ S, ← Ideal.map_map, ha, Ideal.map_mul,
Localization.AtPrime.map_eq_maximalIdeal]
convert Ideal.mul_top _
on_goal 2 => infer_instance
rw [← not_ne_iff, IsLocalization.map_algebraMap_ne_top_iff_disjoint P.primeCompl]
simpa [primeCompl, Set.disjoint_compl_left_iff_subset]
end IsDedekindDomain
variable (f p P) [Algebra R S]
local notation "f" => algebraMap R S
open Classical in
/-- The inertia degree of `P : Ideal S` lying over `p : Ideal R` is the degree of the
extension `(S / P) : (R / p)`.
We do not assume `P` lies over `p` in the definition; we return `0` instead.
See `inertiaDeg_algebraMap` for the common case where `f = algebraMap R S`
and there is an algebra structure `R / p → S / P`.
-/
noncomputable def inertiaDeg : ℕ :=
if hPp : comap f P = p then
letI : Algebra (R ⧸ p) (S ⧸ P) := Quotient.algebraQuotientOfLEComap hPp.ge
finrank (R ⧸ p) (S ⧸ P)
else 0
-- Useful for the `nontriviality` tactic using `comap_eq_of_scalar_tower_quotient`.
@[simp]
theorem inertiaDeg_of_subsingleton [hp : p.IsMaximal] [hQ : Subsingleton (S ⧸ P)] :
inertiaDeg p P = 0 := by
have := Ideal.Quotient.subsingleton_iff.mp hQ
subst this
exact dif_neg fun h => hp.ne_top <| h.symm.trans comap_top
@[simp]
theorem inertiaDeg_algebraMap [P.LiesOver p] [p.IsMaximal] :
inertiaDeg p P = finrank (R ⧸ p) (S ⧸ P) := by
nontriviality S ⧸ P using inertiaDeg_of_subsingleton, finrank_zero_of_subsingleton
rw [inertiaDeg, dif_pos (over_def P p).symm]
theorem inertiaDeg_pos [p.IsMaximal] [Module.Finite R S] [P.LiesOver p] : 0 < inertiaDeg p P :=
haveI : Nontrivial (S ⧸ P) := Quotient.nontrivial_of_liesOver_of_isPrime P p
finrank_pos.trans_eq (inertiaDeg_algebraMap p P).symm
theorem inertiaDeg_ne_zero [p.IsMaximal] [Module.Finite R S] [P.LiesOver p] : inertiaDeg p P ≠ 0 :=
(Nat.ne_of_lt (inertiaDeg_pos p P)).symm
lemma inertiaDeg_comap_eq (e : S ≃ₐ[R] S₁) (P : Ideal S₁) [p.IsMaximal] :
inertiaDeg p (P.comap e) = inertiaDeg p P := by
have he : (P.comap e).comap (algebraMap R S) = p ↔ P.comap (algebraMap R S₁) = p := by
rw [← comap_coe e, comap_comap, ← e.toAlgHom_toRingHom, AlgHom.comp_algebraMap]
by_cases h : P.LiesOver p
· rw [inertiaDeg_algebraMap, inertiaDeg_algebraMap]
exact (Quotient.algEquivOfEqComap p e rfl).toLinearEquiv.finrank_eq
· rw [inertiaDeg, dif_neg (fun eq => h ⟨(he.mp eq).symm⟩)]
rw [inertiaDeg, dif_neg (fun eq => h ⟨eq.symm⟩)]
lemma inertiaDeg_map_eq [p.IsMaximal] (P : Ideal S)
{E : Type*} [EquivLike E S S₁] [AlgEquivClass E R S S₁] (e : E) :
inertiaDeg p (P.map e) = inertiaDeg p P := by
rw [show P.map e = _ from map_comap_of_equiv (e : S ≃+* S₁)]
exact p.inertiaDeg_comap_eq (e : S ≃ₐ[R] S₁).symm P
theorem inertiaDeg_bot [Nontrivial R] [IsDomain S] [Algebra.IsIntegral R S]
[hP : P.LiesOver (⊥ : Ideal R)] :
(⊥ : Ideal R).inertiaDeg P = finrank R S := by
rw [inertiaDeg, dif_pos (over_def P (⊥ : Ideal R)).symm]
replace hP : P = ⊥ := eq_bot_of_liesOver_bot _ P (h := hP)
rw [Algebra.finrank_eq_of_equiv_equiv (RingEquiv.quotientBot R).symm
((quotEquivOfEq hP).trans (RingEquiv.quotientBot S)).symm]
rfl
end DecEq
section absNorm
/-- The absolute norm of an ideal `P` above a rational prime `p` is
`|p| ^ ((span {p}).inertiaDeg P)`.
See `absNorm_eq_pow_inertiaDeg'` for a version with `p` of type `ℕ`. -/
lemma absNorm_eq_pow_inertiaDeg [IsDedekindDomain R] [Module.Free ℤ R] [Module.Finite ℤ R] {p : ℤ}
(P : Ideal R) [P.LiesOver (span {p})] (hp : Prime p) :
absNorm P = p.natAbs ^ ((span {p}).inertiaDeg P) := by
have : (span {p}).IsMaximal :=
(isPrime_of_prime (prime_span_singleton_iff.mpr hp)).isMaximal (by simp [hp.ne_zero])
have h : Module.Finite (ℤ ⧸ span {p}) (R ⧸ P) := module_finite_of_liesOver P (span {p})
let _ : Field (ℤ ⧸ span {p}) := Quotient.field (span {p})
rw [inertiaDeg_algebraMap, absNorm_apply, Submodule.cardQuot_apply,
Module.natCard_eq_pow_finrank (K := ℤ ⧸ span {p})]
simp [Nat.card_congr (Int.quotientSpanEquivZMod p).toEquiv]
/-- The absolute norm of an ideal `P` above a rational (positive) prime `p` is
`p ^ ((span {p}).inertiaDeg P)`.
See `absNorm_eq_pow_inertiaDeg` for a version with `p` of type `ℤ`. -/
lemma absNorm_eq_pow_inertiaDeg' [IsDedekindDomain R] [Module.Free ℤ R] [Module.Finite ℤ R] {p : ℕ}
(P : Ideal R) [P.LiesOver (span {(p : ℤ)})] (hp : p.Prime) :
absNorm P = p ^ ((span {(p : ℤ)}).inertiaDeg P) :=
absNorm_eq_pow_inertiaDeg P ( Nat.prime_iff_prime_int.mp hp)
end absNorm
section FinrankQuotientMap
open scoped nonZeroDivisors
variable [Algebra R S]
variable {K : Type*} [Field K] [Algebra R K]
variable {L : Type*} [Field L] [Algebra S L] [IsFractionRing S L]
variable {V V' V'' : Type*}
variable [AddCommGroup V] [Module R V] [Module K V] [IsScalarTower R K V]
variable [AddCommGroup V'] [Module R V'] [Module S V'] [IsScalarTower R S V']
variable [AddCommGroup V''] [Module R V'']
variable (K)
open scoped Matrix
variable {K} in
/-- If `b` mod `p` spans `S/p` as `R/p`-space, then `b` itself spans `Frac(S)` as `K`-space.
Here,
* `p` is an ideal of `R` such that `R / p` is nontrivial
* `K` is a field that has an embedding of `R` (in particular we can take `K = Frac(R)`)
* `L` is a field extension of `K`
* `S` is the integral closure of `R` in `L`
More precisely, we avoid quotients in this statement and instead require that `b ∪ pS` spans `S`.
-/
theorem FinrankQuotientMap.span_eq_top [IsDomain R] [IsDomain S] [Algebra K L] [Module.Finite R S]
[Algebra R L] [IsScalarTower R S L] [IsScalarTower R K L] [Algebra.IsAlgebraic R S]
[NoZeroSMulDivisors R K] (hp : p ≠ ⊤) (b : Set S)
(hb' : Submodule.span R b ⊔ (p.map (algebraMap R S)).restrictScalars R = ⊤) :
Submodule.span K (algebraMap S L '' b) = ⊤ := by
have hRL : Function.Injective (algebraMap R L) := by
rw [IsScalarTower.algebraMap_eq R K L]
exact (algebraMap K L).injective.comp (FaithfulSMul.algebraMap_injective R K)
-- Let `M` be the `R`-module spanned by the proposed basis elements.
let M : Submodule R S := Submodule.span R b
-- Then `S / M` is generated by some finite set of `n` vectors `a`.
obtain ⟨n, a, ha⟩ := @Module.Finite.exists_fin R (S ⧸ M) _ _ _ _
-- Because the image of `p` in `S / M` is `⊤`,
have smul_top_eq : p • (⊤ : Submodule R (S ⧸ M)) = ⊤ := by
calc
p • ⊤ = Submodule.map M.mkQ (p • ⊤) := by
rw [Submodule.map_smul'', Submodule.map_top, M.range_mkQ]
_ = ⊤ := by rw [Ideal.smul_top_eq_map, (Submodule.map_mkQ_eq_top M _).mpr hb']
-- we can write the elements of `a` as `p`-linear combinations of other elements of `a`.
have exists_sum : ∀ x : S ⧸ M, ∃ a' : Fin n → R, (∀ i, a' i ∈ p) ∧ ∑ i, a' i • a i = x := by
intro x
obtain ⟨a'', ha'', hx⟩ := (Submodule.mem_ideal_smul_span_iff_exists_sum p a x).1
(by { rw [ha, smul_top_eq]; exact Submodule.mem_top } :
x ∈ p • Submodule.span R (Set.range a))
· refine ⟨fun i => a'' i, fun i => ha'' _, ?_⟩
rw [← hx, Finsupp.sum_fintype]
exact fun _ => zero_smul _ _
choose A' hA'p hA' using fun i => exists_sum (a i)
-- This gives us a(n invertible) matrix `A` such that `det A ∈ (M = span R b)`,
let A : Matrix (Fin n) (Fin n) R := Matrix.of A' - 1
let B := A.adjugate
have A_smul : ∀ i, ∑ j, A i j • a j = 0 := by
intros
simp [A, Matrix.sub_apply, Matrix.of_apply, Matrix.one_apply, sub_smul,
Finset.sum_sub_distrib, hA', sub_self]
-- since `span S {det A} / M = 0`.
have d_smul : ∀ i, A.det • a i = 0 := by
intro i
calc
A.det • a i = ∑ j, (B * A) i j • a j := ?_
_ = ∑ k, B i k • ∑ j, A k j • a j := ?_
_ = 0 := Finset.sum_eq_zero fun k _ => ?_
· simp only [B, Matrix.adjugate_mul, Matrix.smul_apply, Matrix.one_apply, smul_eq_mul, ite_true,
mul_ite, mul_one, mul_zero, ite_smul, zero_smul, Finset.sum_ite_eq, Finset.mem_univ]
· simp only [Matrix.mul_apply, Finset.smul_sum, Finset.sum_smul, smul_smul]
rw [Finset.sum_comm]
· rw [A_smul, smul_zero]
-- In the rings of integers we have the desired inclusion.
have span_d : (Submodule.span S ({algebraMap R S A.det} : Set S)).restrictScalars R ≤ M := by
intro x hx
rw [Submodule.restrictScalars_mem] at hx
obtain ⟨x', rfl⟩ := Submodule.mem_span_singleton.mp hx
rw [smul_eq_mul, mul_comm, ← Algebra.smul_def] at hx ⊢
rw [← Submodule.Quotient.mk_eq_zero, Submodule.Quotient.mk_smul]
obtain ⟨a', _, quot_x_eq⟩ := exists_sum (Submodule.Quotient.mk x')
rw [← quot_x_eq, Finset.smul_sum]
conv =>
lhs; congr; next => skip
intro x; rw [smul_comm A.det, d_smul, smul_zero]
exact Finset.sum_const_zero
refine top_le_iff.mp
(calc
⊤ = (Ideal.span {algebraMap R L A.det}).restrictScalars K := ?_
_ ≤ Submodule.span K (algebraMap S L '' b) := ?_)
-- Because `det A ≠ 0`, we have `span L {det A} = ⊤`.
· rw [eq_comm, Submodule.restrictScalars_eq_top_iff, Ideal.span_singleton_eq_top]
refine IsUnit.mk0 _ ((map_ne_zero_iff (algebraMap R L) hRL).mpr ?_)
refine ne_zero_of_map (f := Ideal.Quotient.mk p) ?_
haveI := Ideal.Quotient.nontrivial hp
calc
Ideal.Quotient.mk p A.det = Matrix.det ((Ideal.Quotient.mk p).mapMatrix A) := by
rw [RingHom.map_det]
_ = Matrix.det ((Ideal.Quotient.mk p).mapMatrix (Matrix.of A' - 1)) := rfl
_ = Matrix.det fun i j =>
(Ideal.Quotient.mk p) (A' i j) - (1 : Matrix (Fin n) (Fin n) (R ⧸ p)) i j := ?_
_ = Matrix.det (-1 : Matrix (Fin n) (Fin n) (R ⧸ p)) := ?_
_ = (-1 : R ⧸ p) ^ n := by rw [Matrix.det_neg, Fintype.card_fin, Matrix.det_one, mul_one]
_ ≠ 0 := IsUnit.ne_zero (isUnit_one.neg.pow _)
· refine congr_arg Matrix.det (Matrix.ext fun i j => ?_)
rw [map_sub, RingHom.mapMatrix_apply, map_one]
rfl
· refine congr_arg Matrix.det (Matrix.ext fun i j => ?_)
rw [Ideal.Quotient.eq_zero_iff_mem.mpr (hA'p i j), zero_sub]
rfl
-- And we conclude `L = span L {det A} ≤ span K b`, so `span K b` spans everything.
· intro x hx
rw [Submodule.restrictScalars_mem, IsScalarTower.algebraMap_apply R S L] at hx
exact IsFractionRing.ideal_span_singleton_map_subset R hRL span_d hx
variable [hRK : IsFractionRing R K]
/-- Let `V` be a vector space over `K = Frac(R)`, `S / R` a ring extension
and `V'` a module over `S`. If `b`, in the intersection `V''` of `V` and `V'`,
is linear independent over `S` in `V'`, then it is linear independent over `R` in `V`.
The statement we prove is actually slightly more general:
* it suffices that the inclusion `algebraMap R S : R → S` is nontrivial
* the function `f' : V'' → V'` doesn't need to be injective
-/
theorem FinrankQuotientMap.linearIndependent_of_nontrivial [IsDedekindDomain R]
(hRS : RingHom.ker (algebraMap R S) ≠ ⊤) (f : V'' →ₗ[R] V) (hf : Function.Injective f)
(f' : V'' →ₗ[R] V') {ι : Type*} {b : ι → V''} (hb' : LinearIndependent S (f' ∘ b)) :
LinearIndependent K (f ∘ b) := by
contrapose! hb' with hb
-- Informally, if we have a nontrivial linear dependence with coefficients `g` in `K`,
-- then we can find a linear dependence with coefficients `I.Quotient.mk g'` in `R/I`,
-- where `I = ker (algebraMap R S)`.
-- We make use of the same principle but stay in `R` everywhere.
simp only [linearIndependent_iff', not_forall] at hb ⊢
obtain ⟨s, g, eq, j', hj's, hj'g⟩ := hb
use s
obtain ⟨a, hag, j, hjs, hgI⟩ := Ideal.exist_integer_multiples_notMem hRS s g hj's hj'g
choose g'' hg'' using hag
letI := Classical.propDecidable
let g' i := if h : i ∈ s then g'' i h else 0
have hg' : ∀ i ∈ s, algebraMap _ _ (g' i) = a * g i := by
intro i hi; exact (congr_arg _ (dif_pos hi)).trans (hg'' i hi)
-- Because `R/I` is nontrivial, we can lift `g` to a nontrivial linear dependence in `S`.
have hgI : algebraMap R S (g' j) ≠ 0 := by
simp only [FractionalIdeal.mem_coeIdeal, not_exists, not_and'] at hgI
exact hgI _ (hg' j hjs)
refine ⟨fun i => algebraMap R S (g' i), ?_, j, hjs, hgI⟩
have eq : f (∑ i ∈ s, g' i • b i) = 0 := by
rw [map_sum, ← smul_zero a, ← eq, Finset.smul_sum]
refine Finset.sum_congr rfl ?_
intro i hi
rw [LinearMap.map_smul, ← IsScalarTower.algebraMap_smul K, hg' i hi, ← smul_assoc,
smul_eq_mul, Function.comp_apply]
simp only [IsScalarTower.algebraMap_smul, ← map_smul, ← map_sum,
(f.map_eq_zero_iff hf).mp eq, LinearMap.map_zero, (· ∘ ·)]
variable (L)
/-- If `p` is a maximal ideal of `R`, and `S` is the integral closure of `R` in `L`,
then the dimension `[S/pS : R/p]` is equal to `[Frac(S) : Frac(R)]`. -/
theorem finrank_quotient_map [IsDomain S] [IsDedekindDomain R] [Algebra K L]
[Algebra R L] [IsScalarTower R K L] [IsScalarTower R S L]
[hp : p.IsMaximal] [Module.Finite R S] :
finrank (R ⧸ p) (S ⧸ map (algebraMap R S) p) = finrank K L := by
-- Choose an arbitrary basis `b` for `[S/pS : R/p]`.
-- We'll use the previous results to turn it into a basis on `[Frac(S) : Frac(R)]`.
let ι := Module.Free.ChooseBasisIndex (R ⧸ p) (S ⧸ map (algebraMap R S) p)
let b : Basis ι (R ⧸ p) (S ⧸ map (algebraMap R S) p) := Module.Free.chooseBasis _ _
-- Namely, choose a representative `b' i : S` for each `b i : S / pS`.
let b' : ι → S := fun i => (Ideal.Quotient.mk_surjective (b i)).choose
have b_eq_b' : ⇑b = (Submodule.mkQ (map (algebraMap R S) p)).restrictScalars R ∘ b' :=
funext fun i => (Ideal.Quotient.mk_surjective (b i)).choose_spec.symm
-- We claim `b'` is a basis for `Frac(S)` over `Frac(R)` because it is linear independent
-- and spans the whole of `Frac(S)`.
let b'' : ι → L := algebraMap S L ∘ b'
have b''_li : LinearIndependent K b'' := ?_
· have b''_sp : Submodule.span K (Set.range b'') = ⊤ := ?_
-- Since the two bases have the same index set, the spaces have the same dimension.
· let c : Basis ι K L := Basis.mk b''_li b''_sp.ge
rw [finrank_eq_card_basis b, finrank_eq_card_basis c]
-- It remains to show that the basis is indeed linear independent and spans the whole space.
· rw [Set.range_comp]
refine FinrankQuotientMap.span_eq_top p hp.ne_top _ (top_le_iff.mp ?_)
-- The nicest way to show `S ≤ span b' ⊔ pS` is by reducing both sides modulo pS.
-- However, this would imply distinguishing between `pS` as `S`-ideal,
-- and `pS` as `R`-submodule, since they have different (non-defeq) quotients.
-- Instead we'll lift `x mod pS ∈ span b` to `y ∈ span b'` for some `y - x ∈ pS`.
intro x _
have mem_span_b : ((Submodule.mkQ (map (algebraMap R S) p)) x : S ⧸ map (algebraMap R S) p) ∈
Submodule.span (R ⧸ p) (Set.range b) := b.mem_span _
rw [← @Submodule.restrictScalars_mem R,
Submodule.restrictScalars_span R (R ⧸ p) Ideal.Quotient.mk_surjective, b_eq_b',
Set.range_comp, ← Submodule.map_span] at mem_span_b
obtain ⟨y, y_mem, y_eq⟩ := Submodule.mem_map.mp mem_span_b
suffices y + -(y - x) ∈ _ by simpa
rw [LinearMap.restrictScalars_apply, Submodule.mkQ_apply, Submodule.mkQ_apply,
Submodule.Quotient.eq] at y_eq
exact add_mem (Submodule.mem_sup_left y_mem) (neg_mem <| Submodule.mem_sup_right y_eq)
· have := b.linearIndependent; rw [b_eq_b'] at this
convert FinrankQuotientMap.linearIndependent_of_nontrivial K _
((Algebra.linearMap S L).restrictScalars R) _ ((Submodule.mkQ _).restrictScalars R) this
· rw [Quotient.algebraMap_eq, Ideal.mk_ker]
exact hp.ne_top
· exact IsFractionRing.injective S L
end FinrankQuotientMap
section FactLeComap
variable [Algebra R S]
local notation "f" => algebraMap R S
local notation "e" => ramificationIdx f p P
/-- `R / p` has a canonical map to `S / (P ^ e)`, where `e` is the ramification index
of `P` over `p`. -/
noncomputable instance Quotient.algebraQuotientPowRamificationIdx : Algebra (R ⧸ p) (S ⧸ P ^ e) :=
Quotient.algebraQuotientOfLEComap (Ideal.map_le_iff_le_comap.mp le_pow_ramificationIdx)
@[simp]
theorem Quotient.algebraMap_quotient_pow_ramificationIdx (x : R) :
algebraMap (R ⧸ p) (S ⧸ P ^ e) (Ideal.Quotient.mk p x) = Ideal.Quotient.mk (P ^ e) (f x) := rfl
/-- If `P` lies over `p`, then `R / p` has a canonical map to `S / P`.
This can't be an instance since the map `f : R → S` is generally not inferable.
-/
def Quotient.algebraQuotientOfRamificationIdxNeZero [hfp : NeZero e] :
Algebra (R ⧸ p) (S ⧸ P) :=
Quotient.algebraQuotientOfLEComap (le_comap_of_ramificationIdx_ne_zero hfp.out)
attribute [local instance] Ideal.Quotient.algebraQuotientOfRamificationIdxNeZero
@[simp]
theorem Quotient.algebraMap_quotient_of_ramificationIdx_neZero
[NeZero e] (x : R) :
algebraMap (R ⧸ p) (S ⧸ P) (Ideal.Quotient.mk p x) = Ideal.Quotient.mk P (f x) := rfl
/-- The inclusion `(P^(i + 1) / P^e) ⊂ (P^i / P^e)`. -/
@[simps]
noncomputable def powQuotSuccInclusion (i : ℕ) :
Ideal.map (Ideal.Quotient.mk (P ^ e)) (P ^ (i + 1)) →ₗ[R ⧸ p]
Ideal.map (Ideal.Quotient.mk (P ^ e)) (P ^ i) where
toFun x := ⟨x, Ideal.map_mono (Ideal.pow_le_pow_right i.le_succ) x.2⟩
map_add' _ _ := rfl
map_smul' _ _ := rfl
theorem powQuotSuccInclusion_injective (i : ℕ) :
Function.Injective (powQuotSuccInclusion p P i) := by
rw [← LinearMap.ker_eq_bot, LinearMap.ker_eq_bot']
rintro ⟨x, hx⟩ hx0
rw [Subtype.ext_iff] at hx0 ⊢
rwa [powQuotSuccInclusion_apply_coe] at hx0
/-- `S ⧸ P` embeds into the quotient by `P^(i+1) ⧸ P^e` as a subspace of `P^i ⧸ P^e`.
See `quotientToQuotientRangePowQuotSucc` for this as a linear map,
and `quotientRangePowQuotSuccInclusionEquiv` for this as a linear equivalence.
-/
noncomputable def quotientToQuotientRangePowQuotSuccAux {i : ℕ} {a : S} (a_mem : a ∈ P ^ i) :
S ⧸ P →
(P ^ i).map (Ideal.Quotient.mk (P ^ e)) ⧸ LinearMap.range (powQuotSuccInclusion p P i) :=
Quotient.map' (fun x : S => ⟨_, Ideal.mem_map_of_mem _ (Ideal.mul_mem_right x _ a_mem)⟩)
fun x y h => by
rw [Submodule.quotientRel_def] at h ⊢
simp only [map_mul, LinearMap.mem_range]
refine ⟨⟨_, Ideal.mem_map_of_mem _ (Ideal.mul_mem_mul a_mem h)⟩, ?_⟩
ext
rw [powQuotSuccInclusion_apply_coe, Subtype.coe_mk, Submodule.coe_sub, Subtype.coe_mk,
Subtype.coe_mk, map_mul, map_sub, mul_sub]
theorem quotientToQuotientRangePowQuotSuccAux_mk {i : ℕ} {a : S} (a_mem : a ∈ P ^ i) (x : S) :
quotientToQuotientRangePowQuotSuccAux p P a_mem (Submodule.Quotient.mk x) =
Submodule.Quotient.mk ⟨_, Ideal.mem_map_of_mem _ (Ideal.mul_mem_right x _ a_mem)⟩ := by
apply Quotient.map'_mk''
section
variable [hfp : NeZero (ramificationIdx (algebraMap R S) p P)]
/-- `S ⧸ P` embeds into the quotient by `P^(i+1) ⧸ P^e` as a subspace of `P^i ⧸ P^e`. -/
noncomputable def quotientToQuotientRangePowQuotSucc
{i : ℕ} {a : S} (a_mem : a ∈ P ^ i) :
S ⧸ P →ₗ[R ⧸ p]
(P ^ i).map (Ideal.Quotient.mk (P ^ e)) ⧸ LinearMap.range (powQuotSuccInclusion p P i) where
toFun := quotientToQuotientRangePowQuotSuccAux p P a_mem
map_add' := by
intro x y; refine Quotient.inductionOn' x fun x => Quotient.inductionOn' y fun y => ?_
simp only [Submodule.Quotient.mk''_eq_mk, ← Submodule.Quotient.mk_add,
quotientToQuotientRangePowQuotSuccAux_mk, mul_add]
exact congr_arg Submodule.Quotient.mk rfl
map_smul' := by
intro x y; refine Quotient.inductionOn' x fun x => Quotient.inductionOn' y fun y => ?_
simp only [Submodule.Quotient.mk''_eq_mk, RingHom.id_apply,
quotientToQuotientRangePowQuotSuccAux_mk]
refine congr_arg Submodule.Quotient.mk ?_
ext
simp only [map_mul, Quotient.mk_eq_mk, Submodule.coe_smul_of_tower,
Algebra.smul_def, Quotient.algebraMap_quotient_pow_ramificationIdx]
ring
theorem quotientToQuotientRangePowQuotSucc_mk {i : ℕ} {a : S} (a_mem : a ∈ P ^ i) (x : S) :
quotientToQuotientRangePowQuotSucc p P a_mem (Submodule.Quotient.mk x) =
Submodule.Quotient.mk ⟨_, Ideal.mem_map_of_mem _ (Ideal.mul_mem_right x _ a_mem)⟩ :=
quotientToQuotientRangePowQuotSuccAux_mk p P a_mem x
theorem quotientToQuotientRangePowQuotSucc_injective [IsDedekindDomain S] [P.IsPrime]
{i : ℕ} (hi : i < e) {a : S} (a_mem : a ∈ P ^ i) (a_notMem : a ∉ P ^ (i + 1)) :
Function.Injective (quotientToQuotientRangePowQuotSucc p P a_mem) := fun x =>
Quotient.inductionOn' x fun x y =>
Quotient.inductionOn' y fun y h => by
have Pe_le_Pi1 : P ^ e ≤ P ^ (i + 1) := Ideal.pow_le_pow_right hi
simp only [Submodule.Quotient.mk''_eq_mk, quotientToQuotientRangePowQuotSucc_mk,
Submodule.Quotient.eq, LinearMap.mem_range, Subtype.ext_iff,
Submodule.coe_sub] at h ⊢
rcases h with ⟨⟨⟨z⟩, hz⟩, h⟩
rw [Submodule.Quotient.quot_mk_eq_mk, Ideal.Quotient.mk_eq_mk, Ideal.mem_quotient_iff_mem_sup,
sup_eq_left.mpr Pe_le_Pi1] at hz
rw [powQuotSuccInclusion_apply_coe, Subtype.coe_mk, Submodule.Quotient.quot_mk_eq_mk,
Ideal.Quotient.mk_eq_mk, ← map_sub, Ideal.Quotient.eq, ← mul_sub] at h
exact
(Ideal.IsPrime.mem_pow_mul _
((Submodule.sub_mem_iff_right _ hz).mp (Pe_le_Pi1 h))).resolve_left
a_notMem
theorem quotientToQuotientRangePowQuotSucc_surjective [IsDedekindDomain S]
(hP0 : P ≠ ⊥) [hP : P.IsPrime] {i : ℕ} (hi : i < e) {a : S} (a_mem : a ∈ P ^ i)
(a_notMem : a ∉ P ^ (i + 1)) :
Function.Surjective (quotientToQuotientRangePowQuotSucc p P a_mem) := by
rintro ⟨⟨⟨x⟩, hx⟩⟩
have Pe_le_Pi : P ^ e ≤ P ^ i := Ideal.pow_le_pow_right hi.le
rw [Submodule.Quotient.quot_mk_eq_mk, Ideal.Quotient.mk_eq_mk, Ideal.mem_quotient_iff_mem_sup,
sup_eq_left.mpr Pe_le_Pi] at hx
suffices hx' : x ∈ Ideal.span {a} ⊔ P ^ (i + 1) by
obtain ⟨y', hy', z, hz, rfl⟩ := Submodule.mem_sup.mp hx'
obtain ⟨y, rfl⟩ := Ideal.mem_span_singleton.mp hy'
refine ⟨Submodule.Quotient.mk y, ?_⟩
simp only [Submodule.Quotient.quot_mk_eq_mk, quotientToQuotientRangePowQuotSucc_mk,
Submodule.Quotient.eq, LinearMap.mem_range, Subtype.ext_iff,
Submodule.coe_sub]
refine ⟨⟨_, Ideal.mem_map_of_mem _ (Submodule.neg_mem _ hz)⟩, ?_⟩
rw [powQuotSuccInclusion_apply_coe, Subtype.coe_mk, Ideal.Quotient.mk_eq_mk, map_add,
sub_add_cancel_left, map_neg]
letI := Classical.decEq (Ideal S)
rw [sup_eq_prod_inf_factors _ (pow_ne_zero _ hP0), normalizedFactors_pow,
normalizedFactors_irreducible ((Ideal.prime_iff_isPrime hP0).mpr hP).irreducible, normalize_eq,
Multiset.nsmul_singleton, Multiset.inter_replicate, Multiset.prod_replicate]
· rw [← Submodule.span_singleton_le_iff_mem, Ideal.submodule_span_eq] at a_mem a_notMem
rwa [Ideal.count_normalizedFactors_eq a_mem a_notMem, min_eq_left i.le_succ]
· intro ha
rw [Ideal.span_singleton_eq_bot.mp ha] at a_notMem
have := (P ^ (i + 1)).zero_mem
contradiction
/-- Quotienting `P^i / P^e` by its subspace `P^(i+1) ⧸ P^e` is
`R ⧸ p`-linearly isomorphic to `S ⧸ P`. -/
noncomputable def quotientRangePowQuotSuccInclusionEquiv [IsDedekindDomain S]
[P.IsPrime] (hP : P ≠ ⊥) {i : ℕ} (hi : i < e) :
((P ^ i).map (Ideal.Quotient.mk (P ^ e)) ⧸ LinearMap.range (powQuotSuccInclusion p P i))
≃ₗ[R ⧸ p] S ⧸ P := by
choose a a_mem a_notMem using
SetLike.exists_of_lt
(Ideal.pow_right_strictAnti P hP (Ideal.IsPrime.ne_top inferInstance) (le_refl i.succ))
refine (LinearEquiv.ofBijective ?_ ⟨?_, ?_⟩).symm
· exact quotientToQuotientRangePowQuotSucc p P a_mem
· exact quotientToQuotientRangePowQuotSucc_injective p P hi a_mem a_notMem
· exact quotientToQuotientRangePowQuotSucc_surjective p P hP hi a_mem a_notMem
/-- Since the inclusion `(P^(i + 1) / P^e) ⊂ (P^i / P^e)` has a kernel isomorphic to `P / S`,
`[P^i / P^e : R / p] = [P^(i+1) / P^e : R / p] + [P / S : R / p]` -/
theorem rank_pow_quot_aux [IsDedekindDomain S] [p.IsMaximal] [P.IsPrime] (hP0 : P ≠ ⊥)
{i : ℕ} (hi : i < e) :
Module.rank (R ⧸ p) (Ideal.map (Ideal.Quotient.mk (P ^ e)) (P ^ i)) =
Module.rank (R ⧸ p) (S ⧸ P) +
Module.rank (R ⧸ p) (Ideal.map (Ideal.Quotient.mk (P ^ e)) (P ^ (i + 1))) := by
rw [← rank_range_of_injective _ (powQuotSuccInclusion_injective p P i),
(quotientRangePowQuotSuccInclusionEquiv p P hP0 hi).symm.rank_eq]
exact (Submodule.rank_quotient_add_rank (LinearMap.range (powQuotSuccInclusion p P i))).symm
theorem rank_pow_quot [IsDedekindDomain S] [p.IsMaximal] [P.IsPrime] (hP0 : P ≠ ⊥)
(i : ℕ) (hi : i ≤ e) :
Module.rank (R ⧸ p) (Ideal.map (Ideal.Quotient.mk (P ^ e)) (P ^ i)) =
(e - i) • Module.rank (R ⧸ p) (S ⧸ P) := by
let Q : ℕ → Prop :=
fun i => Module.rank (R ⧸ p) { x // x ∈ map (Quotient.mk (P ^ e)) (P ^ i) }
= (e - i) • Module.rank (R ⧸ p) (S ⧸ P)
refine Nat.decreasingInduction' (P := Q) (fun j lt_e _le_j ih => ?_) hi ?_
· dsimp only [Q]
rw [rank_pow_quot_aux p P _ lt_e, ih, ← succ_nsmul', Nat.sub_succ, ← Nat.succ_eq_add_one,
Nat.succ_pred_eq_of_pos (Nat.sub_pos_of_lt lt_e)]
assumption
· dsimp only [Q]
rw [Nat.sub_self, zero_nsmul, map_quotient_self]
exact rank_bot (R ⧸ p) (S ⧸ P ^ e)
end
/-- If `p` is a maximal ideal of `R`, `S` extends `R` and `P^e` lies over `p`,
then the dimension `[S/(P^e) : R/p]` is equal to `e * [S/P : R/p]`. -/
theorem rank_prime_pow_ramificationIdx [IsDedekindDomain S] [p.IsMaximal] [P.IsPrime]
(hP0 : P ≠ ⊥) (he : e ≠ 0) :
Module.rank (R ⧸ p) (S ⧸ P ^ e) =
e •
@Module.rank (R ⧸ p) (S ⧸ P) _ _
(@Algebra.toModule _ _ _ _ <|
@Quotient.algebraQuotientOfRamificationIdxNeZero _ _ _ _ _ _ _ ⟨he⟩) := by
letI : NeZero e := ⟨he⟩
have := rank_pow_quot p P hP0 0 (Nat.zero_le e)
rw [pow_zero, Nat.sub_zero, Ideal.one_eq_top, Ideal.map_top] at this
exact (rank_top (R ⧸ p) _).symm.trans this
/-- If `p` is a maximal ideal of `R`, `S` extends `R` and `P^e` lies over `p`,
then the dimension `[S/(P^e) : R/p]`, as a natural number, is equal to `e * [S/P : R/p]`. -/
theorem finrank_prime_pow_ramificationIdx [IsDedekindDomain S] (hP0 : P ≠ ⊥)
[p.IsMaximal] [P.IsPrime] (he : e ≠ 0) :
finrank (R ⧸ p) (S ⧸ P ^ e) =
e *
@finrank (R ⧸ p) (S ⧸ P) _ _
(@Algebra.toModule _ _ _ _ <|
@Quotient.algebraQuotientOfRamificationIdxNeZero _ _ _ _ _ _ _ ⟨he⟩) := by
letI : NeZero e := ⟨he⟩
letI : Algebra (R ⧸ p) (S ⧸ P) := Quotient.algebraQuotientOfRamificationIdxNeZero p P
have hdim := rank_prime_pow_ramificationIdx _ _ hP0 he
by_cases hP : FiniteDimensional (R ⧸ p) (S ⧸ P)
· haveI := (finiteDimensional_iff_of_rank_eq_nsmul he hdim).mpr hP
apply @Nat.cast_injective Cardinal
rw [finrank_eq_rank', Nat.cast_mul, finrank_eq_rank', hdim, nsmul_eq_mul]
have hPe := mt (finiteDimensional_iff_of_rank_eq_nsmul he hdim).mp hP
simp only [finrank_of_infinite_dimensional hP, finrank_of_infinite_dimensional hPe,
mul_zero]
end FactLeComap
section FactorsMap
/-! ## Properties of the factors of `p.map (algebraMap R S)` -/
variable [IsDedekindDomain S] [Algebra R S]
open scoped Classical in
theorem Factors.ne_bot (P : (factors (map (algebraMap R S) p)).toFinset) : (P : Ideal S) ≠ ⊥ :=
(prime_of_factor _ (Multiset.mem_toFinset.mp P.2)).ne_zero
open scoped Classical in
instance Factors.isPrime (P : (factors (map (algebraMap R S) p)).toFinset) :
IsPrime (P : Ideal S) :=
Ideal.isPrime_of_prime (prime_of_factor _ (Multiset.mem_toFinset.mp P.2))
open scoped Classical in
theorem Factors.ramificationIdx_ne_zero (P : (factors (map (algebraMap R S) p)).toFinset) :
ramificationIdx (algebraMap R S) p P ≠ 0 :=
IsDedekindDomain.ramificationIdx_ne_zero (ne_zero_of_mem_factors (Multiset.mem_toFinset.mp P.2))
(Factors.isPrime p P) (Ideal.le_of_dvd (dvd_of_mem_factors (Multiset.mem_toFinset.mp P.2)))
open scoped Classical in
instance Factors.fact_ramificationIdx_neZero (P : (factors (map (algebraMap R S) p)).toFinset) :
NeZero (ramificationIdx (algebraMap R S) p P) :=
⟨Factors.ramificationIdx_ne_zero p P⟩
attribute [local instance] Quotient.algebraQuotientOfRamificationIdxNeZero
open scoped Classical in
instance Factors.isScalarTower (P : (factors (map (algebraMap R S) p)).toFinset) :
IsScalarTower R (R ⧸ p) (S ⧸ (P : Ideal S)) :=
IsScalarTower.of_algebraMap_eq' rfl
open scoped Classical in
instance Factors.liesOver [p.IsMaximal] (P : (factors (map (algebraMap R S) p)).toFinset) :
P.1.LiesOver p :=
⟨(comap_eq_of_scalar_tower_quotient (algebraMap (R ⧸ p) (S ⧸ P.1)).injective).symm⟩
open scoped Classical in
theorem Factors.finrank_pow_ramificationIdx [p.IsMaximal]
(P : (factors (map (algebraMap R S) p)).toFinset) :
finrank (R ⧸ p) (S ⧸ (P : Ideal S) ^ ramificationIdx (algebraMap R S) p P) =
ramificationIdx (algebraMap R S) p P * inertiaDeg p (P : Ideal S) := by
rw [finrank_prime_pow_ramificationIdx, inertiaDeg_algebraMap]
exacts [Factors.ne_bot p P, NeZero.ne _]
open scoped Classical in
instance Factors.finiteDimensional_quotient_pow [Module.Finite R S] [p.IsMaximal]
(P : (factors (map (algebraMap R S) p)).toFinset) :
FiniteDimensional (R ⧸ p) (S ⧸ (P : Ideal S) ^ ramificationIdx (algebraMap R S) p P) := by
refine .of_finrank_pos ?_
rw [pos_iff_ne_zero, Factors.finrank_pow_ramificationIdx]
exact mul_ne_zero (Factors.ramificationIdx_ne_zero p P) (inertiaDeg_pos p P.1).ne'
universe w
open scoped Classical in
/-- **Chinese remainder theorem** for a ring of integers: if the prime ideal `p : Ideal R`
factors in `S` as `∏ i, P i ^ e i`, then `S ⧸ I` factors as `Π i, R ⧸ (P i ^ e i)`. -/
noncomputable def Factors.piQuotientEquiv (p : Ideal R) (hp : map (algebraMap R S) p ≠ ⊥) :
S ⧸ map (algebraMap R S) p ≃+*
∀ P : (factors (map (algebraMap R S) p)).toFinset,
S ⧸ (P : Ideal S) ^ ramificationIdx (algebraMap R S) p P :=
(IsDedekindDomain.quotientEquivPiFactors hp).trans <|
@RingEquiv.piCongrRight (factors (map (algebraMap R S) p)).toFinset
(fun P => S ⧸ (P : Ideal S) ^ (factors (map (algebraMap R S) p)).count (P : Ideal S))
(fun P => S ⧸ (P : Ideal S) ^ ramificationIdx (algebraMap R S) p P) _ _
fun P : (factors (map (algebraMap R S) p)).toFinset =>
Ideal.quotEquivOfEq <| by
rw [IsDedekindDomain.ramificationIdx_eq_factors_count hp (Factors.isPrime p P)
(Factors.ne_bot p P)]
@[simp]
theorem Factors.piQuotientEquiv_mk (p : Ideal R) (hp : map (algebraMap R S) p ≠ ⊥) (x : S) :
Factors.piQuotientEquiv p hp (Ideal.Quotient.mk _ x) = fun _ => Ideal.Quotient.mk _ x := rfl
@[simp]
theorem Factors.piQuotientEquiv_map (p : Ideal R) (hp : map (algebraMap R S) p ≠ ⊥) (x : R) :
Factors.piQuotientEquiv p hp (algebraMap _ _ x) = fun _ =>
Ideal.Quotient.mk _ (algebraMap _ _ x) := rfl
variable (S)
open scoped Classical in
/-- **Chinese remainder theorem** for a ring of integers: if the prime ideal `p : Ideal R`
factors in `S` as `∏ i, P i ^ e i`,
then `S ⧸ I` factors `R ⧸ I`-linearly as `Π i, R ⧸ (P i ^ e i)`. -/
noncomputable def Factors.piQuotientLinearEquiv (p : Ideal R) (hp : map (algebraMap R S) p ≠ ⊥) :
(S ⧸ map (algebraMap R S) p) ≃ₗ[R ⧸ p]
∀ P : (factors (map (algebraMap R S) p)).toFinset,
S ⧸ (P : Ideal S) ^ ramificationIdx (algebraMap R S) p P :=
{ Factors.piQuotientEquiv p hp with
map_smul' := by
rintro ⟨c⟩ ⟨x⟩; ext P
simp only [Submodule.Quotient.quot_mk_eq_mk, Quotient.mk_eq_mk, Algebra.smul_def,
Quotient.algebraMap_quotient_map_quotient, Quotient.mk_algebraMap,
RingHomCompTriple.comp_apply, Pi.mul_apply, Pi.algebraMap_apply]
congr }
variable (K L : Type*) [Field K] [Field L] [IsDedekindDomain R] [Algebra R K] [IsFractionRing R K]
[Algebra S L] [IsFractionRing S L] [Algebra K L] [Algebra R L] [IsScalarTower R S L]
[IsScalarTower R K L] [Module.Finite R S]
open scoped Classical in
/-- The **fundamental identity** of ramification index `e` and inertia degree `f`:
for `P` ranging over the primes lying over `p`, `∑ P, e P * f P = [Frac(S) : Frac(R)]`;
here `S` is a finite `R`-module (and thus `Frac(S) : Frac(R)` is a finite extension) and `p`
is maximal. -/
theorem sum_ramification_inertia {p : Ideal R} [p.IsMaximal] (hp0 : p ≠ ⊥) :
∑ P ∈ primesOverFinset p S,
ramificationIdx (algebraMap R S) p P * inertiaDeg p P = finrank K L := by
set e := ramificationIdx (algebraMap R S) p
set f := inertiaDeg p (S := S)
calc
(∑ P ∈ (factors (map (algebraMap R S) p)).toFinset, e P * f P) =
∑ P ∈ (factors (map (algebraMap R S) p)).toFinset.attach,
finrank (R ⧸ p) (S ⧸ (P : Ideal S) ^ e P) := ?_
_ = finrank (R ⧸ p)
(∀ P : (factors (map (algebraMap R S) p)).toFinset, S ⧸ (P : Ideal S) ^ e P) :=
(finrank_pi_fintype (R ⧸ p)).symm
_ = finrank (R ⧸ p) (S ⧸ map (algebraMap R S) p) := ?_
_ = finrank K L := ?_
· rw [← Finset.sum_attach]
refine Finset.sum_congr rfl fun P _ => ?_
rw [Factors.finrank_pow_ramificationIdx]
· refine LinearEquiv.finrank_eq (Factors.piQuotientLinearEquiv S p ?_).symm
rwa [Ne, Ideal.map_eq_bot_iff_le_ker, (RingHom.injective_iff_ker_eq_bot _).mp <|
algebraMap_injective_of_field_isFractionRing R S K L, le_bot_iff]
· exact finrank_quotient_map p K L
theorem inertiaDeg_le_finrank [NoZeroSMulDivisors R S] {p : Ideal R} [p.IsMaximal]
(P : Ideal S) [hP₁ : P.IsPrime] [hP₂ : P.LiesOver p] (hp0 : p ≠ ⊥) :
p.inertiaDeg P ≤ Module.finrank K L := by
classical
have hP : P ∈ primesOverFinset p S := (mem_primesOverFinset_iff hp0 _).mpr ⟨hP₁, hP₂⟩
rw [← sum_ramification_inertia S K L hp0, ← Finset.add_sum_erase _ _ hP]
refine le_trans (Nat.le_mul_of_pos_left _ ?_) (Nat.le_add_right _ _)
exact Nat.pos_iff_ne_zero.mpr <| IsDedekindDomain.ramificationIdx_ne_zero_of_liesOver _ hp0
theorem ramificationIdx_le_finrank [NoZeroSMulDivisors R S] {p : Ideal R} [p.IsMaximal]
(P : Ideal S) [hP₁ : P.IsPrime] [hP₂ : P.LiesOver p] :
p.ramificationIdx (algebraMap R S) P ≤ Module.finrank K L := by
classical
by_cases hp0 : p = ⊥
· simp [hp0]
have hP : P ∈ primesOverFinset p S := (mem_primesOverFinset_iff hp0 _).mpr ⟨hP₁, hP₂⟩
rw [← sum_ramification_inertia S K L hp0, ← Finset.add_sum_erase _ _ hP]
refine le_trans (Nat.le_mul_of_pos_right _ ?_) (Nat.le_add_right _ _)
exact Nat.pos_iff_ne_zero.mpr <| inertiaDeg_ne_zero p P
theorem card_primesOverFinset_le_finrank [NoZeroSMulDivisors R S] {p : Ideal R} [p.IsMaximal]
(hp0 : p ≠ ⊥) : Finset.card (primesOverFinset p S) ≤ Module.finrank K L := by
rw [← sum_ramification_inertia S K L hp0, Finset.card_eq_sum_ones]
refine Finset.sum_le_sum fun P hP ↦ ?_
have : P.IsPrime := ((mem_primesOverFinset_iff hp0 _).mp hP).1
have : P.LiesOver p := ((mem_primesOverFinset_iff hp0 _).mp hP).2
refine Right.one_le_mul ?_ ?_
· exact Nat.pos_iff_ne_zero.mpr <| IsDedekindDomain.ramificationIdx_ne_zero_of_liesOver _ hp0
· exact Nat.pos_iff_ne_zero.mpr <| inertiaDeg_ne_zero p P
/-- `Ideal.sum_ramification_inertia`, in the local (DVR) case. -/
lemma ramificationIdx_mul_inertiaDeg_of_isLocalRing [IsLocalRing S] {p : Ideal R} [p.IsMaximal]
(hp0 : p ≠ ⊥) :
ramificationIdx (algebraMap R S) p (IsLocalRing.maximalIdeal S) *
p.inertiaDeg (IsLocalRing.maximalIdeal S) = Module.finrank K L := by
have := FaithfulSMul.of_field_isFractionRing R S K L
simp_rw [← sum_ramification_inertia S K L hp0, IsLocalRing.primesOverFinset_eq S hp0,
Finset.sum_singleton]
end FactorsMap
section tower
variable {R S T : Type*} [CommRing R] [CommRing S] [CommRing T]
theorem ramificationIdx_tower [IsDedekindDomain S] [IsDedekindDomain T] {f : R →+* S} {g : S →+* T}
{p : Ideal R} {P : Ideal S} {Q : Ideal T} [hpm : P.IsPrime] [hqm : Q.IsPrime]
(hg0 : map g P ≠ ⊥) (hfg : map (g.comp f) p ≠ ⊥) (hg : map g P ≤ Q) :
ramificationIdx (g.comp f) p Q = ramificationIdx f p P * ramificationIdx g P Q := by
classical
have hf0 : map f p ≠ ⊥ :=
ne_bot_of_map_ne_bot (Eq.mp (congrArg (fun I ↦ I ≠ ⊥) (map_map f g).symm) hfg)
have hp0 : P ≠ ⊥ := ne_bot_of_map_ne_bot hg0
have hq0 : Q ≠ ⊥ := ne_bot_of_le_ne_bot hg0 hg
letI : P.IsMaximal := Ring.DimensionLEOne.maximalOfPrime hp0 hpm
rw [IsDedekindDomain.ramificationIdx_eq_normalizedFactors_count hf0 hpm hp0,
IsDedekindDomain.ramificationIdx_eq_normalizedFactors_count hg0 hqm hq0,
IsDedekindDomain.ramificationIdx_eq_normalizedFactors_count hfg hqm hq0, ← map_map]
rcases eq_prime_pow_mul_coprime hf0 P with ⟨I, hcp, heq⟩
have hcp : ⊤ = map g P ⊔ map g I := by rw [← map_sup, hcp, map_top g]
have hntq : ¬ ⊤ ≤ Q := fun ht ↦ IsPrime.ne_top hqm (Iff.mpr (eq_top_iff_one Q) (ht trivial))
nth_rw 1 [heq, Ideal.map_mul, Ideal.map_pow, normalizedFactors_mul (pow_ne_zero _ hg0) <| by
by_contra h
simp only [h, Submodule.zero_eq_bot, bot_le, sup_of_le_left] at hcp
exact hntq (hcp.trans_le hg), Multiset.count_add, normalizedFactors_pow, Multiset.count_nsmul]
exact add_eq_left.mpr <| Decidable.byContradiction fun h ↦ hntq <| hcp.trans_le <|
sup_le hg <| le_of_dvd <| dvd_of_mem_normalizedFactors <| Multiset.count_ne_zero.mp h
variable [Algebra R S] [Algebra S T] [Algebra R T] [IsScalarTower R S T]
/-- Let `T / S / R` be a tower of algebras, `p, P, Q` be ideals in `R, S, T` respectively,
and `P` and `Q` are prime. If `P = Q ∩ S`, then `e (Q | p) = e (P | p) * e (Q | P)`. -/
theorem ramificationIdx_algebra_tower [IsDedekindDomain S] [IsDedekindDomain T]
{p : Ideal R} {P : Ideal S} {Q : Ideal T} [hpm : P.IsPrime] [hqm : Q.IsPrime]
(hg0 : map (algebraMap S T) P ≠ ⊥)
(hfg : map (algebraMap R T) p ≠ ⊥) (hg : map (algebraMap S T) P ≤ Q) :
ramificationIdx (algebraMap R T) p Q =
ramificationIdx (algebraMap R S) p P * ramificationIdx (algebraMap S T) P Q := by
rw [IsScalarTower.algebraMap_eq R S T] at hfg ⊢
exact ramificationIdx_tower hg0 hfg hg
/-- Let `T / S / R` be a tower of algebras, `p, P, I` be ideals in `R, S, T`, respectively,
and `p` and `P` are maximal. If `p = P ∩ S` and `P = I ∩ S`,
then `f (I | p) = f (P | p) * f (I | P)`. -/
theorem inertiaDeg_algebra_tower (p : Ideal R) (P : Ideal S) (I : Ideal T) [p.IsMaximal]
[P.IsMaximal] [P.LiesOver p] [I.LiesOver P] : inertiaDeg p I =
inertiaDeg p P * inertiaDeg P I := by
have h₁ := P.over_def p
have h₂ := I.over_def P
have h₃ := (LiesOver.trans I P p).over
simp only [inertiaDeg, dif_pos h₁.symm, dif_pos h₂.symm, dif_pos h₃.symm]
letI : Algebra (R ⧸ p) (S ⧸ P) := Ideal.Quotient.algebraQuotientOfLEComap h₁.le
letI : Algebra (S ⧸ P) (T ⧸ I) := Ideal.Quotient.algebraQuotientOfLEComap h₂.le
letI : Algebra (R ⧸ p) (T ⧸ I) := Ideal.Quotient.algebraQuotientOfLEComap h₃.le
letI : IsScalarTower (R ⧸ p) (S ⧸ P) (T ⧸ I) := IsScalarTower.of_algebraMap_eq <| by
rintro ⟨x⟩; exact congr_arg _ (IsScalarTower.algebraMap_apply R S T x)
exact (finrank_mul_finrank (R ⧸ p) (S ⧸ P) (T ⧸ I)).symm
end tower
end Ideal |
.lake/packages/mathlib/Mathlib/NumberTheory/MulChar/Duality.lean | import Mathlib.GroupTheory.FiniteAbelian.Duality
import Mathlib.NumberTheory.MulChar.Basic
/-!
# Duality for multiplicative characters
Let `M` be a finite commutative monoid and `R` a ring that has enough `n`th roots of unity,
where `n` is the exponent of `M`. Then the main results of this file are as follows.
* `MulChar.exists_apply_ne_one_of_hasEnoughRootsOfUnity`: multiplicative characters
`M → R` separate elements of `Mˣ`.
* `MulChar.mulEquiv_units`: the group of multiplicative characters `M → R` is
(noncanonically) isomorphic to `Mˣ`.
-/
namespace MulChar
variable {M R : Type*} [CommMonoid M] [CommRing R]
instance finite [Finite Mˣ] [IsDomain R] : Finite (MulChar M R) := by
have : Finite (Mˣ →* Rˣ) := by
have : Fintype Mˣ := .ofFinite _
let S := rootsOfUnity (Fintype.card Mˣ) R
let F := Mˣ →* S
have fF : Finite F := .of_injective _ DFunLike.coe_injective
refine .of_surjective (fun f : F ↦ (Subgroup.subtype _).comp f) fun f ↦ ?_
have H a : f a ∈ S := by simp only [mem_rootsOfUnity, ← map_pow, pow_card_eq_one, map_one, S]
refine ⟨.codRestrict f S H, MonoidHom.ext fun _ ↦ ?_⟩
simp only [MonoidHom.coe_comp, Subgroup.coe_subtype, Function.comp_apply,
MonoidHom.codRestrict_apply]
exact .of_equiv _ MulChar.equivToUnitHom.symm
lemma exists_apply_ne_one_iff_exists_monoidHom (a : Mˣ) :
(∃ χ : MulChar M R, χ a ≠ 1) ↔ ∃ φ : Mˣ →* Rˣ, φ a ≠ 1 := by
refine ⟨fun ⟨χ, hχ⟩ ↦ ⟨χ.toUnitHom, ?_⟩, fun ⟨φ, hφ⟩ ↦ ⟨ofUnitHom φ, ?_⟩⟩
· contrapose! hχ
rwa [Units.ext_iff, coe_toUnitHom] at hχ
· contrapose! hφ
simpa only [ofUnitHom_eq, equivToUnitHom_symm_coe, Units.val_eq_one] using hφ
variable (M R)
variable [Finite M] [HasEnoughRootsOfUnity R (Monoid.exponent Mˣ)]
/-- If `M` is a finite commutative monoid and `R` is a ring that has enough roots of unity,
then for each `a ≠ 1` in `M`, there exists a multiplicative character `χ : M → R` such that
`χ a ≠ 1`. -/
theorem exists_apply_ne_one_of_hasEnoughRootsOfUnity [Nontrivial R] {a : M} (ha : a ≠ 1) :
∃ χ : MulChar M R, χ a ≠ 1 := by
by_cases hu : IsUnit a
· refine (exists_apply_ne_one_iff_exists_monoidHom hu.unit).mpr ?_
refine CommGroup.exists_apply_ne_one_of_hasEnoughRootsOfUnity Mˣ R ?_
contrapose! ha
rw [← hu.unit_spec, ha, Units.val_eq_one]
· exact ⟨1, by simpa only [map_nonunit _ hu] using zero_ne_one⟩
/-- The group of `R`-valued multiplicative characters on a finite commutative monoid `M` is
(noncanonically) isomorphic to its unit group `Mˣ` when `R` is a ring that has enough roots
of unity. -/
lemma mulEquiv_units : Nonempty (MulChar M R ≃* Mˣ) :=
⟨mulEquivToUnitHom.trans
(CommGroup.monoidHom_mulEquiv_of_hasEnoughRootsOfUnity Mˣ R).some⟩
/-- The cardinality of the group of `R`-valued multiplicative characters on a finite commutative
monoid `M` is the same as that of its unit group `Mˣ` when `R` is a ring that has enough roots
of unity. -/
lemma card_eq_card_units_of_hasEnoughRootsOfUnity : Nat.card (MulChar M R) = Nat.card Mˣ :=
Nat.card_congr (mulEquiv_units M R).some.toEquiv
end MulChar |
.lake/packages/mathlib/Mathlib/NumberTheory/MulChar/Lemmas.lean | import Mathlib.NumberTheory.MulChar.Basic
import Mathlib.RingTheory.RootsOfUnity.Complex
/-!
# Further Results on multiplicative characters
-/
namespace MulChar
/-- Two multiplicative characters on a monoid whose unit group is generated by `g`
are equal if and only if they agree on `g`. -/
lemma eq_iff {R R' : Type*} [CommMonoid R] [CommMonoidWithZero R'] {g : Rˣ}
(hg : ∀ x, x ∈ Subgroup.zpowers g) (χ₁ χ₂ : MulChar R R') :
χ₁ = χ₂ ↔ χ₁ g.val = χ₂ g.val := by
rw [← Equiv.apply_eq_iff_eq equivToUnitHom, MonoidHom.eq_iff_eq_on_generator hg,
← coe_equivToUnitHom, ← coe_equivToUnitHom, Units.ext_iff]
section Ring
variable {R R' : Type*} [CommRing R] [CommRing R']
/-- Define the conjugation (`star`) of a multiplicative character by conjugating pointwise. -/
@[simps!]
def starComp [StarRing R'] (χ : MulChar R R') : MulChar R R' :=
χ.ringHomComp (starRingEnd R')
instance instStarMul [StarRing R'] : StarMul (MulChar R R') where
star := starComp
star_involutive χ := by
ext1
simp only [starComp_apply, RingHomCompTriple.comp_apply, RingHom.id_apply]
star_mul χ χ' := by
ext1
simp only [starComp_apply, starRingEnd, coeToFun_mul, Pi.mul_apply, map_mul, RingHom.coe_coe,
starRingAut_apply, mul_comm]
@[simp]
lemma star_apply [StarRing R'] (χ : MulChar R R') (a : R) : (star χ) a = star (χ a) :=
rfl
/-- The values of a multiplicative character on `R` are `n`th roots of unity, where `n = #Rˣ`. -/
lemma apply_mem_rootsOfUnity [Fintype Rˣ] (a : Rˣ) {χ : MulChar R R'} :
equivToUnitHom χ a ∈ rootsOfUnity (Fintype.card Rˣ) R' := by
rw [mem_rootsOfUnity, ← map_pow, ← (equivToUnitHom χ).map_one, pow_card_eq_one]
variable [Finite Rˣ]
open Complex in
/-- The conjugate of a multiplicative character with values in `ℂ` is its inverse. -/
lemma star_eq_inv (χ : MulChar R ℂ) : star χ = χ⁻¹ := by
cases nonempty_fintype Rˣ
ext1 a
simp only [inv_apply_eq_inv']
exact (inv_eq_conj <| norm_eq_one_of_mem_rootsOfUnity <| χ.apply_mem_rootsOfUnity a).symm
lemma star_apply' (χ : MulChar R ℂ) (a : R) : star (χ a) = χ⁻¹ a := by
simp only [RCLike.star_def, ← star_eq_inv, star_apply]
end Ring
section IsCyclic
/-!
### Multiplicative characters on finite monoids with cyclic unit group
-/
variable {M : Type*} [CommMonoid M] [Fintype M] [DecidableEq M]
variable {R : Type*} [CommMonoidWithZero R]
/-- Given a finite monoid `M` with unit group `Mˣ` cyclic of order `n` and an `n`th root of
unity `ζ` in `R`, there is a multiplicative character `M → R` that sends a given generator
of `Mˣ` to `ζ`. -/
noncomputable def ofRootOfUnity {ζ : Rˣ} (hζ : ζ ∈ rootsOfUnity (Fintype.card Mˣ) R)
{g : Mˣ} (hg : ∀ x, x ∈ Subgroup.zpowers g) :
MulChar M R := by
have : orderOf ζ ∣ Fintype.card Mˣ :=
orderOf_dvd_iff_pow_eq_one.mpr <| (mem_rootsOfUnity _ ζ).mp hζ
refine ofUnitHom <| monoidHomOfForallMemZpowers hg <| this.trans <| dvd_of_eq ?_
rw [orderOf_eq_card_of_forall_mem_zpowers hg, Nat.card_eq_fintype_card]
lemma ofRootOfUnity_spec {ζ : Rˣ} (hζ : ζ ∈ rootsOfUnity (Fintype.card Mˣ) R)
{g : Mˣ} (hg : ∀ x, x ∈ Subgroup.zpowers g) :
ofRootOfUnity hζ hg g = ζ := by
simp only [ofRootOfUnity, ofUnitHom_eq, equivToUnitHom_symm_coe,
monoidHomOfForallMemZpowers_apply_gen]
variable (M R) in
/-- The group of multiplicative characters on a finite monoid `M` with cyclic unit group `Mˣ`
of order `n` is isomorphic to the group of `n`th roots of unity in the target `R`. -/
noncomputable def equiv_rootsOfUnity [inst_cyc : IsCyclic Mˣ] :
MulChar M R ≃* rootsOfUnity (Fintype.card Mˣ) R where
toFun χ :=
⟨χ.toUnitHom <| Classical.choose inst_cyc.exists_generator, by
simp only [toUnitHom_eq, mem_rootsOfUnity, ← map_pow, pow_card_eq_one, map_one]⟩
invFun ζ := ofRootOfUnity ζ.prop <| Classical.choose_spec inst_cyc.exists_generator
left_inv χ := by
simp only [toUnitHom_eq, eq_iff <| Classical.choose_spec inst_cyc.exists_generator,
ofRootOfUnity_spec, coe_equivToUnitHom]
right_inv ζ := by
ext
simp only [toUnitHom_eq, coe_equivToUnitHom, ofRootOfUnity_spec]
map_mul' x y := by
simp only [toUnitHom_eq, equivToUnitHom_mul_apply, MulMemClass.mk_mul_mk]
end IsCyclic
section FiniteField
/-!
### Multiplicative characters on finite fields
-/
section Fintype
variable (F : Type*) [Field F] [Fintype F]
variable {R : Type*} [CommRing R]
/-- There is a character of order `n` on `F` if `#F ≡ 1 mod n` and the target contains
a primitive `n`th root of unity. -/
lemma exists_mulChar_orderOf {n : ℕ} (h : n ∣ Fintype.card F - 1) {ζ : R}
(hζ : IsPrimitiveRoot ζ n) :
∃ χ : MulChar F R, orderOf χ = n := by
classical
have hn₀ : 0 < n := by
refine Nat.pos_of_ne_zero fun hn ↦ ?_
simp only [hn, zero_dvd_iff, Nat.sub_eq_zero_iff_le] at h
exact (Fintype.one_lt_card.trans_le h).false
let e := MulChar.equiv_rootsOfUnity F R
let ζ' : Rˣ := (hζ.isUnit hn₀.ne').unit
have h' : ζ' ^ (Fintype.card Fˣ : ℕ) = 1 :=
Units.ext_iff.mpr <| (hζ.pow_eq_one_iff_dvd _).mpr <| Fintype.card_units (α := F) ▸ h
use e.symm ⟨ζ', (mem_rootsOfUnity (Fintype.card Fˣ) ζ').mpr h'⟩
rw [e.symm.orderOf_eq, orderOf_eq_iff hn₀]
refine ⟨?_, fun m hm hm₀ h ↦ ?_⟩
· ext
push_cast
exact hζ.pow_eq_one
· rw [Subtype.ext_iff, Units.ext_iff] at h
push_cast at h
exact ((Nat.le_of_dvd hm₀ <| hζ.dvd_of_pow_eq_one _ h).trans_lt hm).false
/-- If there is a multiplicative character of order `n` on `F`, then `#F ≡ 1 mod n`. -/
lemma orderOf_dvd_card_sub_one (χ : MulChar F R) : orderOf χ ∣ Fintype.card F - 1 := by
classical
rw [← Fintype.card_units]
exact orderOf_dvd_of_pow_eq_one χ.pow_card_eq_one
/-- There is always a character on `F` of order `#F-1` with values in a ring that has
a primitive `(#F-1)`th root of unity. -/
lemma exists_mulChar_orderOf_eq_card_units [DecidableEq F]
{ζ : R} (hζ : IsPrimitiveRoot ζ (Fintype.card Fˣ)) :
∃ χ : MulChar F R, orderOf χ = Fintype.card Fˣ :=
exists_mulChar_orderOf F (by rw [Fintype.card_units]) hζ
end Fintype
variable {F : Type*} [Field F] [Finite F]
variable {R : Type*} [CommRing R]
/- The non-zero values of a multiplicative character of order `n` are `n`th roots of unity. -/
lemma apply_mem_rootsOfUnity_orderOf (χ : MulChar F R) {a : F} (ha : a ≠ 0) :
∃ ζ ∈ rootsOfUnity (orderOf χ) R, ζ = χ a := by
have hu : IsUnit (χ a) := ha.isUnit.map χ
refine ⟨hu.unit, ?_, hu.unit_spec⟩
rw [mem_rootsOfUnity, Units.ext_iff, Units.val_pow_eq_pow_val, Units.val_one,
IsUnit.unit_spec, ← χ.pow_apply' χ.orderOf_pos.ne', pow_orderOf_eq_one,
show a = (isUnit_iff_ne_zero.mpr ha).unit by simp only [IsUnit.unit_spec],
MulChar.one_apply_coe]
/-- The non-zero values of a multiplicative character `χ` such that `χ^n = 1`
are `n`th roots of unity. -/
lemma apply_mem_rootsOfUnity_of_pow_eq_one {χ : MulChar F R} {n : ℕ} (hχ : χ ^ n = 1)
{a : F} (ha : a ≠ 0) :
∃ ζ ∈ rootsOfUnity n R, ζ = χ a := by
obtain ⟨μ, hμ₁, hμ₂⟩ := χ.apply_mem_rootsOfUnity_orderOf ha
exact ⟨μ, rootsOfUnity_le_of_dvd (orderOf_dvd_of_pow_eq_one hχ) hμ₁, hμ₂⟩
-- Results involving primitive roots of unity require `R` to be an integral domain.
variable [IsDomain R]
/-- If `χ` is a multiplicative character with `χ^n = 1` and `μ` is a primitive `n`th root
of unity, then, for `a ≠ 0`, there is some `k` such that `χ a = μ^k`. -/
lemma exists_apply_eq_pow {χ : MulChar F R} {n : ℕ} [NeZero n] (hχ : χ ^ n = 1) {μ : R}
(hμ : IsPrimitiveRoot μ n) {a : F} (ha : a ≠ 0) :
∃ k < n, χ a = μ ^ k := by
obtain ⟨ζ, hζ₁, hζ₂⟩ := apply_mem_rootsOfUnity_of_pow_eq_one hχ ha
have hζ' : ζ.val ^ n = 1 := (mem_rootsOfUnity' n ↑ζ).mp hζ₁
obtain ⟨k, hk₁, hk₂⟩ := hμ.eq_pow_of_pow_eq_one hζ'
exact ⟨k, hk₁, (hζ₂ ▸ hk₂).symm⟩
/-- The values of a multiplicative character `χ` such that `χ^n = 1` are contained in `ℤ[μ]` when
`μ` is a primitive `n`th root of unity. -/
lemma apply_mem_algebraAdjoin_of_pow_eq_one {χ : MulChar F R} {n : ℕ} [NeZero n] (hχ : χ ^ n = 1)
{μ : R} (hμ : IsPrimitiveRoot μ n) (a : F) :
χ a ∈ Algebra.adjoin ℤ {μ} := by
rcases eq_or_ne a 0 with rfl | h
· exact χ.map_zero ▸ Subalgebra.zero_mem _
· obtain ⟨ζ, hζ₁, hζ₂⟩ := apply_mem_rootsOfUnity_of_pow_eq_one hχ h
rw [mem_rootsOfUnity, Units.ext_iff, Units.val_pow_eq_pow_val] at hζ₁
obtain ⟨k, _, hk⟩ := IsPrimitiveRoot.eq_pow_of_pow_eq_one hμ hζ₁
exact hζ₂ ▸ hk ▸ Subalgebra.pow_mem _ (Algebra.self_mem_adjoin_singleton ℤ μ) k
/-- The values of a multiplicative character of order `n` are contained in `ℤ[μ]` when
`μ` is a primitive `n`th root of unity. -/
lemma apply_mem_algebraAdjoin {χ : MulChar F R} {μ : R} (hμ : IsPrimitiveRoot μ (orderOf χ))
(a : F) :
χ a ∈ Algebra.adjoin ℤ {μ} :=
have : NeZero (orderOf χ) := ⟨χ.orderOf_pos.ne'⟩
apply_mem_algebraAdjoin_of_pow_eq_one (pow_orderOf_eq_one χ) hμ a
end FiniteField
end MulChar |
.lake/packages/mathlib/Mathlib/NumberTheory/MulChar/Basic.lean | import Mathlib.Algebra.CharP.Basic
import Mathlib.Algebra.CharP.Lemmas
import Mathlib.Algebra.Ring.Regular
import Mathlib.Data.Fintype.Units
import Mathlib.GroupTheory.OrderOfElement
/-!
# Multiplicative characters of finite rings and fields
Let `R` and `R'` be a commutative rings.
A *multiplicative character* of `R` with values in `R'` is a morphism of
monoids from the multiplicative monoid of `R` into that of `R'`
that sends non-units to zero.
We use the namespace `MulChar` for the definitions and results.
## Main results
We show that the multiplicative characters form a group (if `R'` is commutative);
see `MulChar.commGroup`. We also provide an equivalence with the
homomorphisms `Rˣ →* R'ˣ`; see `MulChar.equivToUnitHom`.
We define a multiplicative character to be *quadratic* if its values
are among `0`, `1` and `-1`, and we prove some properties of quadratic characters.
Finally, we show that the sum of all values of a nontrivial multiplicative
character vanishes; see `MulChar.IsNontrivial.sum_eq_zero`.
## Tags
multiplicative character
-/
/-!
### Definitions related to multiplicative characters
Even though the intended use is when domain and target of the characters
are commutative rings, we define them in the more general setting when
the domain is a commutative monoid and the target is a commutative monoid
with zero. (We need a zero in the target, since non-units are supposed
to map to zero.)
In this setting, there is an equivalence between multiplicative characters
`R → R'` and group homomorphisms `Rˣ → R'ˣ`, and the multiplicative characters
have a natural structure as a commutative group.
-/
section Defi
-- The domain of our multiplicative characters
variable (R : Type*) [CommMonoid R]
-- The target
variable (R' : Type*) [CommMonoidWithZero R']
/-- Define a structure for multiplicative characters.
A multiplicative character from a commutative monoid `R` to a commutative monoid with zero `R'`
is a homomorphism of (multiplicative) monoids that sends non-units to zero. -/
structure MulChar extends MonoidHom R R' where
map_nonunit' : ∀ a : R, ¬IsUnit a → toFun a = 0
instance MulChar.instFunLike : FunLike (MulChar R R') R R' :=
⟨fun χ => χ.toFun,
fun χ₀ χ₁ h => by cases χ₀; cases χ₁; congr; apply MonoidHom.ext (fun _ => congr_fun h _)⟩
/-- This is the corresponding extension of `MonoidHomClass`. -/
class MulCharClass (F : Type*) (R R' : outParam Type*) [CommMonoid R]
[CommMonoidWithZero R'] [FunLike F R R'] : Prop extends MonoidHomClass F R R' where
map_nonunit : ∀ (χ : F) {a : R} (_ : ¬IsUnit a), χ a = 0
initialize_simps_projections MulChar (toFun → apply, -toMonoidHom)
end Defi
namespace MulChar
attribute [scoped simp] MulCharClass.map_nonunit
section Group
-- The domain of our multiplicative characters
variable {R : Type*} [CommMonoid R]
-- The target
variable {R' : Type*} [CommMonoidWithZero R']
variable (R R') in
/-- The trivial multiplicative character. It takes the value `0` on non-units and
the value `1` on units. -/
@[simps]
noncomputable def trivial : MulChar R R' where
toFun := by classical exact fun x => if IsUnit x then 1 else 0
map_nonunit' := by
intro a ha
simp only [ha, if_false]
map_one' := by simp only [isUnit_one, if_true]
map_mul' := by
intro x y
classical
simp only [IsUnit.mul_iff, boole_mul]
split_ifs <;> tauto
@[simp]
theorem coe_mk (f : R →* R') (hf) : (MulChar.mk f hf : R → R') = f :=
rfl
/-- Extensionality. See `ext` below for the version that will actually be used. -/
theorem ext' {χ χ' : MulChar R R'} (h : ∀ a, χ a = χ' a) : χ = χ' := by
cases χ
cases χ'
congr
exact MonoidHom.ext h
instance : MulCharClass (MulChar R R') R R' where
map_mul χ := χ.map_mul'
map_one χ := χ.map_one'
map_nonunit χ := χ.map_nonunit' _
theorem map_nonunit (χ : MulChar R R') {a : R} (ha : ¬IsUnit a) : χ a = 0 :=
χ.map_nonunit' a ha
/-- Extensionality. Since `MulChar`s always take the value zero on non-units, it is sufficient
to compare the values on units. -/
@[ext]
theorem ext {χ χ' : MulChar R R'} (h : ∀ a : Rˣ, χ a = χ' a) : χ = χ' := by
apply ext'
intro a
by_cases ha : IsUnit a
· exact h ha.unit
· rw [map_nonunit χ ha, map_nonunit χ' ha]
/-!
### Equivalence of multiplicative characters with homomorphisms on units
We show that restriction / extension by zero gives an equivalence
between `MulChar R R'` and `Rˣ →* R'ˣ`.
-/
/-- Turn a `MulChar` into a homomorphism between the unit groups. -/
def toUnitHom (χ : MulChar R R') : Rˣ →* R'ˣ :=
Units.map χ
theorem coe_toUnitHom (χ : MulChar R R') (a : Rˣ) : ↑(χ.toUnitHom a) = χ a :=
rfl
/-- Turn a homomorphism between unit groups into a `MulChar`. -/
noncomputable def ofUnitHom (f : Rˣ →* R'ˣ) : MulChar R R' where
toFun := by classical exact fun x => if hx : IsUnit x then f hx.unit else 0
map_one' := by
have h1 : (isUnit_one.unit : Rˣ) = 1 := Units.ext rfl
simp only [h1, dif_pos, Units.val_eq_one, map_one, isUnit_one]
map_mul' := by
classical
intro x y
by_cases hx : IsUnit x
· simp only [hx, IsUnit.mul_iff, true_and, dif_pos]
by_cases hy : IsUnit y
· simp only [hy, dif_pos]
have hm : (hx.mul hy).unit = hx.unit * hy.unit := Units.ext rfl
rw [hm, map_mul]
norm_cast
· simp only [hy, not_false_iff, dif_neg, mul_zero]
· simp only [hx, IsUnit.mul_iff, false_and, not_false_iff, dif_neg, zero_mul]
map_nonunit' := by
intro a ha
simp only [ha, not_false_iff, dif_neg]
theorem ofUnitHom_coe (f : Rˣ →* R'ˣ) (a : Rˣ) : ofUnitHom f ↑a = f a := by simp [ofUnitHom]
/-- The equivalence between multiplicative characters and homomorphisms of unit groups. -/
noncomputable def equivToUnitHom : MulChar R R' ≃ (Rˣ →* R'ˣ) where
toFun := toUnitHom
invFun := ofUnitHom
left_inv := by
intro χ
ext x
rw [ofUnitHom_coe, coe_toUnitHom]
right_inv := by
intro f
ext x
simp only [coe_toUnitHom, ofUnitHom_coe]
@[simp]
theorem toUnitHom_eq (χ : MulChar R R') : toUnitHom χ = equivToUnitHom χ :=
rfl
@[simp]
theorem ofUnitHom_eq (χ : Rˣ →* R'ˣ) : ofUnitHom χ = equivToUnitHom.symm χ :=
rfl
@[simp]
theorem coe_equivToUnitHom (χ : MulChar R R') (a : Rˣ) : ↑(equivToUnitHom χ a) = χ a :=
coe_toUnitHom χ a
@[simp]
theorem equivToUnitHom_symm_coe (f : Rˣ →* R'ˣ) (a : Rˣ) : equivToUnitHom.symm f ↑a = f a :=
ofUnitHom_coe f a
@[simp]
lemma coe_toMonoidHom (χ : MulChar R R')
(x : R) : χ.toMonoidHom x = χ x := rfl
/-!
### Commutative group structure on multiplicative characters
The multiplicative characters `R → R'` form a commutative group.
-/
protected theorem map_one (χ : MulChar R R') : χ (1 : R) = 1 :=
χ.map_one'
/-- If the domain has a zero (and is nontrivial), then `χ 0 = 0`. -/
protected theorem map_zero {R : Type*} [CommMonoidWithZero R] [Nontrivial R] (χ : MulChar R R') :
χ (0 : R) = 0 := by rw [map_nonunit χ not_isUnit_zero]
/-- We can convert a multiplicative character into a homomorphism of monoids with zero when
the source has a zero and another element. -/
@[coe, simps]
def toMonoidWithZeroHom {R : Type*} [CommMonoidWithZero R] [Nontrivial R] (χ : MulChar R R') :
R →*₀ R' where
toFun := χ.toFun
map_zero' := χ.map_zero
map_one' := χ.map_one'
map_mul' := χ.map_mul'
/-- If the domain is a ring `R`, then `χ (ringChar R) = 0`. -/
theorem map_ringChar {R : Type*} [CommSemiring R] [Nontrivial R] (χ : MulChar R R') :
χ (ringChar R) = 0 := by rw [ringChar.Nat.cast_ringChar, χ.map_zero]
noncomputable instance hasOne : One (MulChar R R') :=
⟨trivial R R'⟩
noncomputable instance inhabited : Inhabited (MulChar R R') :=
⟨1⟩
/-- Evaluation of the trivial character -/
@[simp]
theorem one_apply_coe (a : Rˣ) : (1 : MulChar R R') a = 1 := by classical exact dif_pos a.isUnit
/-- Evaluation of the trivial character -/
lemma one_apply {x : R} (hx : IsUnit x) : (1 : MulChar R R') x = 1 := one_apply_coe hx.unit
/-- Multiplication of multiplicative characters. (This needs the target to be commutative.) -/
def mul (χ χ' : MulChar R R') : MulChar R R' :=
{ χ.toMonoidHom * χ'.toMonoidHom with
toFun := χ * χ'
map_nonunit' := fun a ha => by simp only [map_nonunit χ ha, zero_mul, Pi.mul_apply] }
instance hasMul : Mul (MulChar R R') :=
⟨mul⟩
theorem mul_apply (χ χ' : MulChar R R') (a : R) : (χ * χ') a = χ a * χ' a :=
rfl
@[simp]
theorem coeToFun_mul (χ χ' : MulChar R R') : ⇑(χ * χ') = χ * χ' :=
rfl
protected theorem one_mul (χ : MulChar R R') : (1 : MulChar R R') * χ = χ := by
ext
simp only [one_mul, Pi.mul_apply, MulChar.coeToFun_mul, MulChar.one_apply_coe]
protected theorem mul_one (χ : MulChar R R') : χ * 1 = χ := by
ext
simp only [mul_one, Pi.mul_apply, MulChar.coeToFun_mul, MulChar.one_apply_coe]
/-- The inverse of a multiplicative character. We define it as `inverse ∘ χ`. -/
noncomputable def inv (χ : MulChar R R') : MulChar R R' :=
{ MonoidWithZero.inverse.toMonoidHom.comp χ.toMonoidHom with
toFun := fun a => MonoidWithZero.inverse (χ a)
map_nonunit' := fun a ha => by simp [map_nonunit _ ha] }
noncomputable instance hasInv : Inv (MulChar R R') :=
⟨inv⟩
/-- The inverse of a multiplicative character `χ`, applied to `a`, is the inverse of `χ a`. -/
theorem inv_apply_eq_inv (χ : MulChar R R') (a : R) : χ⁻¹ a = Ring.inverse (χ a) :=
Eq.refl <| inv χ a
/-- The inverse of a multiplicative character `χ`, applied to `a`, is the inverse of `χ a`.
Variant when the target is a field -/
theorem inv_apply_eq_inv' {R' : Type*} [CommGroupWithZero R'] (χ : MulChar R R') (a : R) :
χ⁻¹ a = (χ a)⁻¹ :=
(inv_apply_eq_inv χ a).trans <| Ring.inverse_eq_inv (χ a)
/-- When the domain has a zero, then the inverse of a multiplicative character `χ`,
applied to `a`, is `χ` applied to the inverse of `a`. -/
theorem inv_apply {R : Type*} [CommMonoidWithZero R] (χ : MulChar R R') (a : R) :
χ⁻¹ a = χ (Ring.inverse a) := by
by_cases ha : IsUnit a
· rw [inv_apply_eq_inv]
have h := IsUnit.map χ ha
apply_fun (χ a * ·) using IsUnit.mul_right_injective h
dsimp only
rw [Ring.mul_inverse_cancel _ h, ← map_mul, Ring.mul_inverse_cancel _ ha, map_one]
· revert ha
nontriviality R
intro ha
-- `nontriviality R` by itself doesn't do it
rw [map_nonunit _ ha, Ring.inverse_non_unit a ha, MulChar.map_zero χ]
/-- When the domain has a zero, then the inverse of a multiplicative character `χ`,
applied to `a`, is `χ` applied to the inverse of `a`. -/
theorem inv_apply' {R : Type*} [CommGroupWithZero R] (χ : MulChar R R') (a : R) : χ⁻¹ a = χ a⁻¹ :=
(inv_apply χ a).trans <| congr_arg _ (Ring.inverse_eq_inv a)
/-- The product of a character with its inverse is the trivial character. -/
theorem inv_mul (χ : MulChar R R') : χ⁻¹ * χ = 1 := by
ext x
rw [coeToFun_mul, Pi.mul_apply, inv_apply_eq_inv]
simp only [Ring.inverse_mul_cancel _ (IsUnit.map χ x.isUnit)]
rw [one_apply_coe]
/-- The commutative group structure on `MulChar R R'`. -/
noncomputable instance commGroup : CommGroup (MulChar R R') where
inv_mul_cancel := inv_mul
mul_assoc := by
intro χ₁ χ₂ χ₃
ext a
simp only [mul_assoc, Pi.mul_apply, MulChar.coeToFun_mul]
mul_comm := by
intro χ₁ χ₂
ext a
simp only [mul_comm, Pi.mul_apply, MulChar.coeToFun_mul]
one_mul := MulChar.one_mul
mul_one := MulChar.mul_one
/-- If `a` is a unit and `n : ℕ`, then `(χ ^ n) a = (χ a) ^ n`. -/
theorem pow_apply_coe (χ : MulChar R R') (n : ℕ) (a : Rˣ) : (χ ^ n) a = χ a ^ n := by
induction n with
| zero => rw [pow_zero, pow_zero, one_apply_coe]
| succ n ih => rw [pow_succ, pow_succ, mul_apply, ih]
/-- If `n` is positive, then `(χ ^ n) a = (χ a) ^ n`. -/
theorem pow_apply' (χ : MulChar R R') {n : ℕ} (hn : n ≠ 0) (a : R) : (χ ^ n) a = χ a ^ n := by
by_cases ha : IsUnit a
· exact pow_apply_coe χ n ha.unit
· rw [map_nonunit (χ ^ n) ha, map_nonunit χ ha, zero_pow hn]
lemma equivToUnitHom_mul_apply (χ₁ χ₂ : MulChar R R') (a : Rˣ) :
equivToUnitHom (χ₁ * χ₂) a = equivToUnitHom χ₁ a * equivToUnitHom χ₂ a := by
apply_fun ((↑) : R'ˣ → R') using Units.val_injective
push_cast
simp_rw [coe_equivToUnitHom, coeToFun_mul, Pi.mul_apply]
/-- The equivalence between multiplicative characters and homomorphisms of unit groups
as a multiplicative equivalence. -/
noncomputable
def mulEquivToUnitHom : MulChar R R' ≃* (Rˣ →* R'ˣ) :=
{ equivToUnitHom with
map_mul' := by
intro χ ψ
ext
simp only [Equiv.toFun_as_coe, coe_equivToUnitHom, coeToFun_mul, Pi.mul_apply,
MonoidHom.mul_apply, Units.val_mul]
}
end Group
/-!
### Properties of multiplicative characters
We introduce the properties of being nontrivial or quadratic and prove
some basic facts about them.
We now (mostly) assume that the target is a commutative ring.
-/
section Properties
section nontrivial
variable {R : Type*} [CommMonoid R] {R' : Type*} [CommMonoidWithZero R']
lemma eq_one_iff {χ : MulChar R R'} : χ = 1 ↔ ∀ a : Rˣ, χ a = 1 := by
simp only [MulChar.ext_iff, one_apply_coe]
lemma ne_one_iff {χ : MulChar R R'} : χ ≠ 1 ↔ ∃ a : Rˣ, χ a ≠ 1 := by
simp only [Ne, eq_one_iff, not_forall]
end nontrivial
section quadratic_and_comp
variable {R : Type*} [CommMonoid R] {R' : Type*} [CommRing R'] {R'' : Type*} [CommRing R'']
/-- A multiplicative character is *quadratic* if it takes only the values `0`, `1`, `-1`. -/
def IsQuadratic (χ : MulChar R R') : Prop :=
∀ a, χ a = 0 ∨ χ a = 1 ∨ χ a = -1
/-- If two values of quadratic characters with target `ℤ` agree after coercion into a ring
of characteristic not `2`, then they agree in `ℤ`. -/
theorem IsQuadratic.eq_of_eq_coe {χ : MulChar R ℤ} (hχ : IsQuadratic χ) {χ' : MulChar R' ℤ}
(hχ' : IsQuadratic χ') [Nontrivial R''] (hR'' : ringChar R'' ≠ 2) {a : R} {a' : R'}
(h : (χ a : R'') = χ' a') : χ a = χ' a' :=
Int.cast_injOn_of_ringChar_ne_two hR'' (hχ a) (hχ' a') h
/-- We can post-compose a multiplicative character with a ring homomorphism. -/
@[simps]
def ringHomComp (χ : MulChar R R') (f : R' →+* R'') : MulChar R R'' :=
{ f.toMonoidHom.comp χ.toMonoidHom with
toFun := fun a => f (χ a)
map_nonunit' := fun a ha => by simp only [map_nonunit χ ha, map_zero] }
@[simp]
lemma ringHomComp_one (f : R' →+* R'') : (1 : MulChar R R').ringHomComp f = 1 := by
ext1
simp only [MulChar.ringHomComp_apply, MulChar.one_apply_coe, map_one]
lemma ringHomComp_inv {R : Type*} [CommMonoidWithZero R] (χ : MulChar R R') (f : R' →+* R'') :
(χ.ringHomComp f)⁻¹ = χ⁻¹.ringHomComp f := by
ext1
simp only [inv_apply, Ring.inverse_unit, ringHomComp_apply]
lemma ringHomComp_mul (χ φ : MulChar R R') (f : R' →+* R'') :
(χ * φ).ringHomComp f = χ.ringHomComp f * φ.ringHomComp f := by
ext1
simp only [ringHomComp_apply, coeToFun_mul, Pi.mul_apply, map_mul]
lemma ringHomComp_pow (χ : MulChar R R') (f : R' →+* R'') (n : ℕ) :
χ.ringHomComp f ^ n = (χ ^ n).ringHomComp f := by
induction n with
| zero => simp only [pow_zero, ringHomComp_one]
| succ n ih => simp only [pow_succ, ih, ringHomComp_mul]
lemma injective_ringHomComp {f : R' →+* R''} (hf : Function.Injective f) :
Function.Injective (ringHomComp (R := R) · f) := by
simpa
only [Function.Injective, MulChar.ext_iff, ringHomComp, coe_mk, MonoidHom.coe_mk, OneHom.coe_mk]
using fun χ χ' h a ↦ hf (h a)
lemma ringHomComp_eq_one_iff {f : R' →+* R''} (hf : Function.Injective f) {χ : MulChar R R'} :
χ.ringHomComp f = 1 ↔ χ = 1 := by
conv_lhs => rw [← (show (1 : MulChar R R').ringHomComp f = 1 by simp)]
exact (injective_ringHomComp hf).eq_iff
lemma ringHomComp_ne_one_iff {f : R' →+* R''} (hf : Function.Injective f) {χ : MulChar R R'} :
χ.ringHomComp f ≠ 1 ↔ χ ≠ 1 :=
(ringHomComp_eq_one_iff hf).not
/-- Composition with a ring homomorphism preserves the property of being a quadratic character. -/
theorem IsQuadratic.comp {χ : MulChar R R'} (hχ : χ.IsQuadratic) (f : R' →+* R'') :
(χ.ringHomComp f).IsQuadratic := by
intro a
rcases hχ a with (ha | ha | ha) <;> simp [ha]
/-- The inverse of a quadratic character is itself. → -/
theorem IsQuadratic.inv {χ : MulChar R R'} (hχ : χ.IsQuadratic) : χ⁻¹ = χ := by
ext x
rw [inv_apply_eq_inv]
rcases hχ x with (h₀ | h₁ | h₂)
· rw [h₀, Ring.inverse_zero]
· rw [h₁, Ring.inverse_one]
· -- Porting note (#11573): was `by norm_cast`
have : (-1 : R') = (-1 : R'ˣ) := by norm_cast; simp
rw [h₂, this, Ring.inverse_unit (-1 : R'ˣ), inv_neg, inv_one]
/-- The square of a quadratic character is the trivial character. -/
theorem IsQuadratic.sq_eq_one {χ : MulChar R R'} (hχ : χ.IsQuadratic) : χ ^ 2 = 1 := by
rw [← inv_mul_cancel χ, pow_two, hχ.inv]
/-- The `p`th power of a quadratic character is itself, when `p` is the (prime) characteristic
of the target ring. -/
theorem IsQuadratic.pow_char {χ : MulChar R R'} (hχ : χ.IsQuadratic) (p : ℕ) [hp : Fact p.Prime]
[CharP R' p] : χ ^ p = χ := by
ext x
rw [pow_apply_coe]
rcases hχ x with (hx | hx | hx) <;> rw [hx]
· rw [zero_pow (@Fact.out p.Prime).ne_zero]
· rw [one_pow]
· exact neg_one_pow_char R' p
/-- The `n`th power of a quadratic character is the trivial character, when `n` is even. -/
theorem IsQuadratic.pow_even {χ : MulChar R R'} (hχ : χ.IsQuadratic) {n : ℕ} (hn : Even n) :
χ ^ n = 1 := by
obtain ⟨n, rfl⟩ := even_iff_two_dvd.mp hn
rw [pow_mul, hχ.sq_eq_one, one_pow]
/-- The `n`th power of a quadratic character is itself, when `n` is odd. -/
theorem IsQuadratic.pow_odd {χ : MulChar R R'} (hχ : χ.IsQuadratic) {n : ℕ} (hn : Odd n) :
χ ^ n = χ := by
obtain ⟨n, rfl⟩ := hn
rw [pow_add, pow_one, hχ.pow_even (even_two_mul _), one_mul]
/-- A multiplicative character `χ` into an integral domain is quadratic
if and only if `χ^2 = 1`. -/
lemma isQuadratic_iff_sq_eq_one {M R : Type*} [CommMonoid M] [CommRing R] [NoZeroDivisors R]
[Nontrivial R] {χ : MulChar M R} :
IsQuadratic χ ↔ χ ^ 2 = 1:= by
refine ⟨fun h ↦ ext (fun x ↦ ?_), fun h x ↦ ?_⟩
· rw [one_apply_coe, χ.pow_apply_coe]
rcases h x with H | H | H
· exact (not_isUnit_zero <| H ▸ IsUnit.map χ <| x.isUnit).elim
· simp only [H, one_pow]
· simp only [H, even_two, Even.neg_pow, one_pow]
· by_cases hx : IsUnit x
· refine .inr <| sq_eq_one_iff.mp ?_
rw [← χ.pow_apply' two_ne_zero, h, MulChar.one_apply hx]
· exact .inl <| map_nonunit χ hx
end quadratic_and_comp
end Properties
/-!
### Multiplicative characters with finite domain
-/
section Finite
variable {M : Type*} [CommMonoid M]
variable {R : Type*} [CommMonoidWithZero R]
/-- If `χ` is a multiplicative character on a commutative monoid `M` with finitely many units,
then `χ ^ #Mˣ = 1`. -/
protected lemma pow_card_eq_one [Fintype Mˣ] (χ : MulChar M R) : χ ^ (Fintype.card Mˣ) = 1 := by
ext1
rw [pow_apply_coe, ← map_pow, one_apply_coe, ← Units.val_pow_eq_pow_val, pow_card_eq_one,
Units.val_eq_one.mpr rfl, map_one]
/-- A multiplicative character on a commutative monoid with finitely many units
has finite (= positive) order. -/
lemma orderOf_pos [Finite Mˣ] (χ : MulChar M R) : 0 < orderOf χ := by
cases nonempty_fintype Mˣ
apply IsOfFinOrder.orderOf_pos
exact isOfFinOrder_iff_pow_eq_one.2 ⟨_, Fintype.card_pos, χ.pow_card_eq_one⟩
end Finite
section sum
variable {R : Type*} [CommMonoid R] [Fintype R] {R' : Type*} [CommRing R']
/-- The sum over all values of a nontrivial multiplicative character on a finite ring is zero
(when the target is a domain). -/
theorem sum_eq_zero_of_ne_one [IsDomain R'] {χ : MulChar R R'} (hχ : χ ≠ 1) : ∑ a, χ a = 0 := by
rcases ne_one_iff.mp hχ with ⟨b, hb⟩
refine eq_zero_of_mul_eq_self_left hb ?_
simpa only [Finset.mul_sum, ← map_mul] using b.mulLeft_bijective.sum_comp _
/-- The sum over all values of the trivial multiplicative character on a finite ring is
the cardinality of its unit group. -/
theorem sum_one_eq_card_units [DecidableEq R] :
(∑ a, (1 : MulChar R R') a) = Fintype.card Rˣ := by
calc
(∑ a, (1 : MulChar R R') a) = ∑ a : R, if IsUnit a then 1 else 0 :=
Finset.sum_congr rfl fun a _ => ?_
_ = ((Finset.univ : Finset R).filter IsUnit).card := Finset.sum_boole _ _
_ = (Finset.univ.map ⟨((↑) : Rˣ → R), Units.val_injective⟩).card := ?_
_ = Fintype.card Rˣ := congr_arg _ (Finset.card_map _)
· split_ifs with h
· exact one_apply_coe h.unit
· exact map_nonunit _ h
· congr
ext a
simp [IsUnit]
end sum
/-!
### Multiplicative characters on rings
-/
section Ring
variable {R R' : Type*} [CommRing R] [CommMonoidWithZero R']
/-- If `χ` is of odd order, then `χ(-1) = 1` -/
lemma val_neg_one_eq_one_of_odd_order {χ : MulChar R R'} {n : ℕ} (hn : Odd n) (hχ : χ ^ n = 1) :
χ (-1) = 1 := by
rw [← hn.neg_one_pow, map_pow, ← χ.pow_apply' (Nat.ne_of_odd_add hn), hχ]
exact MulChar.one_apply_coe (-1)
end Ring
end MulChar |
.lake/packages/mathlib/Mathlib/NumberTheory/DiophantineApproximation/ContinuedFractions.lean | import Mathlib.Algebra.ContinuedFractions.Computation.ApproximationCorollaries
import Mathlib.Algebra.ContinuedFractions.Computation.Translations
import Mathlib.NumberTheory.DiophantineApproximation.Basic
/-!
# Diophantine Approximation using continued fractions
## Main statements
There are two versions of Legendre's Theorem.`Real.exists_rat_eq_convergent`,
defined in `Mathlib/NumberTheory/DiophantineApproximation/Basic.lean`, uses `Real.convergent`,
a simple recursive definition of the convergents that is also defined in that file.
This file provides `Real.exists_convs_eq_rat`, using `GenContFract.convs` of `GenContFract.of ξ`.
-/
section Convergent
namespace Real
open Int
/-!
Our `convergent`s agree with `GenContFract.convs`.
-/
open GenContFract
/-- The `n`th convergent of the `GenContFract.of ξ` agrees with `ξ.convergent n`. -/
theorem convs_eq_convergent (ξ : ℝ) (n : ℕ) :
(GenContFract.of ξ).convs n = ξ.convergent n := by
induction n generalizing ξ with
| zero => simp only [zeroth_conv_eq_h, of_h_eq_floor, convergent_zero, Rat.cast_intCast]
| succ n ih => rw [convs_succ, ih (fract ξ)⁻¹, convergent_succ, one_div]; norm_cast
end Real
end Convergent
namespace Real
variable {ξ : ℝ} {u v : ℤ}
/-- The main result, *Legendre's Theorem* on rational approximation:
if `ξ` is a real number and `q` is a rational number such that `|ξ - q| < 1/(2*q.den^2)`,
then `q` is a convergent of the continued fraction expansion of `ξ`.
This is the version using `GenContFract.convs`. -/
theorem exists_convs_eq_rat {q : ℚ}
(h : |ξ - q| < 1 / (2 * (q.den : ℝ) ^ 2)) : ∃ n, (GenContFract.of ξ).convs n = q := by
obtain ⟨n, hn⟩ := exists_rat_eq_convergent h
exact ⟨n, hn.symm ▸ convs_eq_convergent ξ n⟩
end Real |
.lake/packages/mathlib/Mathlib/NumberTheory/DiophantineApproximation/Basic.lean | import Mathlib.NumberTheory.Real.Irrational
import Mathlib.RingTheory.Coprime.Lemmas
import Mathlib.RingTheory.Int.Basic
import Mathlib.Tactic.Basic
/-!
# Diophantine Approximation
The first part of this file gives proofs of various versions of
**Dirichlet's approximation theorem** and its important consequence that when $\xi$ is an
irrational real number, then there are infinitely many rationals $x/y$ (in lowest terms)
such that
$$\left|\xi - \frac{x}{y}\right| < \frac{1}{y^2} \,.$$
The proof is based on the pigeonhole principle.
The second part of the file gives a proof of **Legendre's Theorem** on rational approximation,
which states that if $\xi$ is a real number and $x/y$ is a rational number such that
$$\left|\xi - \frac{x}{y}\right| < \frac{1}{2y^2} \,,$$
then $x/y$ must be a convergent of the continued fraction expansion of $\xi$.
## Main statements
The main results are three variants of Dirichlet's approximation theorem:
* `Real.exists_int_int_abs_mul_sub_le`, which states that for all real `ξ` and natural `0 < n`,
there are integers `j` and `k` with `0 < k ≤ n` and `|k*ξ - j| ≤ 1/(n+1)`,
* `Real.exists_nat_abs_mul_sub_round_le`, which replaces `j` by `round(k*ξ)` and uses
a natural number `k`,
* `Real.exists_rat_abs_sub_le_and_den_le`, which says that there is a rational number `q`
satisfying `|ξ - q| ≤ 1/((n+1)*q.den)` and `q.den ≤ n`,
and
* `Real.infinite_rat_abs_sub_lt_one_div_den_sq_of_irrational`, which states that
for irrational `ξ`, the set `{q : ℚ | |ξ - q| < 1/q.den^2}` is infinite.
We also show a converse,
* `Rat.finite_rat_abs_sub_lt_one_div_den_sq`, which states that the set above is finite
when `ξ` is a rational number.
Both statements are combined to give an equivalence,
`Real.infinite_rat_abs_sub_lt_one_div_den_sq_iff_irrational`.
There are two versions of Legendre's Theorem. One, `Real.exists_rat_eq_convergent`, uses
`Real.convergent`, a simple recursive definition of the convergents that is also defined
in this file, whereas the other, `Real.exists_convs_eq_rat` defined in the file
`Mathlib/NumberTheory/DiophantineApproximation/ContinuedFraction.lean`, uses
`GenContFract.convs` of `GenContFract.of ξ`.
## Implementation notes
We use the namespace `Real` for the results on real numbers and `Rat` for the results
on rational numbers. We introduce a secondary namespace `real.contfrac_legendre`
to separate off a definition and some technical auxiliary lemmas used in the proof
of Legendre's Theorem. For remarks on the proof of Legendre's Theorem, see below.
## References
<https://en.wikipedia.org/wiki/Dirichlet%27s_approximation_theorem>
<https://de.wikipedia.org/wiki/Kettenbruch> (The German Wikipedia page on continued
fractions is much more extensive than the English one.)
## Tags
Diophantine approximation, Dirichlet's approximation theorem, continued fraction
-/
namespace Real
section Dirichlet
/-!
### Dirichlet's approximation theorem
We show that for any real number `ξ` and positive natural `n`, there is a fraction `q`
such that `q.den ≤ n` and `|ξ - q| ≤ 1/((n+1)*q.den)`.
-/
open Finset Int
/-- *Dirichlet's approximation theorem:*
For any real number `ξ` and positive natural `n`, there are integers `j` and `k`,
with `0 < k ≤ n` and `|k*ξ - j| ≤ 1/(n+1)`.
See also `Real.exists_nat_abs_mul_sub_round_le`. -/
theorem exists_int_int_abs_mul_sub_le (ξ : ℝ) {n : ℕ} (n_pos : 0 < n) :
∃ j k : ℤ, 0 < k ∧ k ≤ n ∧ |↑k * ξ - j| ≤ 1 / (n + 1) := by
let f : ℤ → ℤ := fun m => ⌊fract (ξ * m) * (n + 1)⌋
have hn : 0 < (n : ℝ) + 1 := mod_cast Nat.succ_pos _
have hfu := fun m : ℤ => mul_lt_of_lt_one_left hn <| fract_lt_one (ξ * ↑m)
conv in |_| ≤ _ => rw [mul_comm, le_div_iff₀ hn, ← abs_of_pos hn, ← abs_mul]
let D := Icc (0 : ℤ) n
by_cases! H : ∃ m ∈ D, f m = n
· obtain ⟨m, hm, hf⟩ := H
have hf' : ((n : ℤ) : ℝ) ≤ fract (ξ * m) * (n + 1) := hf ▸ floor_le (fract (ξ * m) * (n + 1))
have hm₀ : 0 < m := by
have hf₀ : f 0 = 0 := by
simp only [f, cast_zero, mul_zero, fract_zero, zero_mul, floor_zero]
refine Ne.lt_of_le (fun h => n_pos.ne ?_) (mem_Icc.mp hm).1
exact mod_cast hf₀.symm.trans (h.symm ▸ hf : f 0 = n)
refine ⟨⌊ξ * m⌋ + 1, m, hm₀, (mem_Icc.mp hm).2, ?_⟩
rw [cast_add, ← sub_sub, sub_mul, cast_one, one_mul, abs_le]
refine
⟨le_sub_iff_add_le.mpr ?_, sub_le_iff_le_add.mpr <| le_of_lt <| (hfu m).trans <| lt_one_add _⟩
simpa only [neg_add_cancel_comm_assoc] using hf'
· have hD : #(Ico (0 : ℤ) n) < #D := by rw [card_Icc, card_Ico]; exact lt_add_one n
have hfu' : ∀ m, f m ≤ n := fun m => lt_add_one_iff.mp (floor_lt.mpr (mod_cast hfu m))
have hwd : ∀ m : ℤ, m ∈ D → f m ∈ Ico (0 : ℤ) n := fun x hx =>
mem_Ico.mpr
⟨floor_nonneg.mpr (mul_nonneg (fract_nonneg (ξ * x)) hn.le), Ne.lt_of_le (H x hx) (hfu' x)⟩
obtain ⟨x, hx, y, hy, x_lt_y, hxy⟩ : ∃ x ∈ D, ∃ y ∈ D, x < y ∧ f x = f y := by
obtain ⟨x, hx, y, hy, x_ne_y, hxy⟩ := exists_ne_map_eq_of_card_lt_of_maps_to hD hwd
rcases lt_trichotomy x y with (h | h | h)
exacts [⟨x, hx, y, hy, h, hxy⟩, False.elim (x_ne_y h), ⟨y, hy, x, hx, h, hxy.symm⟩]
refine
⟨⌊ξ * y⌋ - ⌊ξ * x⌋, y - x, sub_pos_of_lt x_lt_y,
sub_le_iff_le_add.mpr <| le_add_of_le_of_nonneg (mem_Icc.mp hy).2 (mem_Icc.mp hx).1, ?_⟩
convert_to |fract (ξ * y) * (n + 1) - fract (ξ * x) * (n + 1)| ≤ 1
· congr; push_cast; simp only [fract]; ring
exact (abs_sub_lt_one_of_floor_eq_floor hxy.symm).le
/-- *Dirichlet's approximation theorem:*
For any real number `ξ` and positive natural `n`, there is a natural number `k`,
with `0 < k ≤ n` such that `|k*ξ - round(k*ξ)| ≤ 1/(n+1)`.
-/
theorem exists_nat_abs_mul_sub_round_le (ξ : ℝ) {n : ℕ} (n_pos : 0 < n) :
∃ k : ℕ, 0 < k ∧ k ≤ n ∧ |↑k * ξ - round (↑k * ξ)| ≤ 1 / (n + 1) := by
obtain ⟨j, k, hk₀, hk₁, h⟩ := exists_int_int_abs_mul_sub_le ξ n_pos
have hk := toNat_of_nonneg hk₀.le
rw [← hk] at hk₀ hk₁ h
exact ⟨k.toNat, natCast_pos.mp hk₀, Nat.cast_le.mp hk₁, (round_le (↑k.toNat * ξ) j).trans h⟩
/-- *Dirichlet's approximation theorem:*
For any real number `ξ` and positive natural `n`, there is a fraction `q`
such that `q.den ≤ n` and `|ξ - q| ≤ 1/((n+1)*q.den)`.
See also `AddCircle.exists_norm_nsmul_le`. -/
theorem exists_rat_abs_sub_le_and_den_le (ξ : ℝ) {n : ℕ} (n_pos : 0 < n) :
∃ q : ℚ, |ξ - q| ≤ 1 / ((n + 1) * q.den) ∧ q.den ≤ n := by
obtain ⟨j, k, hk₀, hk₁, h⟩ := exists_int_int_abs_mul_sub_le ξ n_pos
have hk₀' : (0 : ℝ) < k := Int.cast_pos.mpr hk₀
have hden : ((j / k : ℚ).den : ℤ) ≤ k := by
convert le_of_dvd hk₀ (Rat.den_dvd j k)
exact Rat.intCast_div_eq_divInt _ _
refine ⟨j / k, ?_, Nat.cast_le.mp (hden.trans hk₁)⟩
rw [← div_div, le_div_iff₀ (Nat.cast_pos.mpr <| Rat.pos _ : (0 : ℝ) < _)]
refine (mul_le_mul_of_nonneg_left (Int.cast_le.mpr hden : _ ≤ (k : ℝ)) (abs_nonneg _)).trans ?_
rwa [← abs_of_pos hk₀', Rat.cast_div, Rat.cast_intCast, Rat.cast_intCast, ← abs_mul, sub_mul,
div_mul_cancel₀ _ hk₀'.ne', mul_comm]
end Dirichlet
section RatApprox
/-!
### Infinitely many good approximations to irrational numbers
We show that an irrational real number `ξ` has infinitely many "good rational approximations",
i.e., fractions `x/y` in lowest terms such that `|ξ - x/y| < 1/y^2`.
-/
open Set
/-- Given any rational approximation `q` to the irrational real number `ξ`, there is
a good rational approximation `q'` such that `|ξ - q'| < |ξ - q|`. -/
theorem exists_rat_abs_sub_lt_and_lt_of_irrational {ξ : ℝ} (hξ : Irrational ξ) (q : ℚ) :
∃ q' : ℚ, |ξ - q'| < 1 / (q'.den : ℝ) ^ 2 ∧ |ξ - q'| < |ξ - q| := by
have h := abs_pos.mpr (sub_ne_zero.mpr <| Irrational.ne_rat hξ q)
obtain ⟨m, hm⟩ := exists_nat_gt (1 / |ξ - q|)
have m_pos : (0 : ℝ) < m := (one_div_pos.mpr h).trans hm
obtain ⟨q', hbd, hden⟩ := exists_rat_abs_sub_le_and_den_le ξ (Nat.cast_pos.mp m_pos)
have den_pos : (0 : ℝ) < q'.den := Nat.cast_pos.mpr q'.pos
have md_pos := mul_pos (add_pos m_pos zero_lt_one) den_pos
refine
⟨q', lt_of_le_of_lt hbd ?_,
lt_of_le_of_lt hbd <|
(one_div_lt md_pos h).mpr <|
hm.trans <|
lt_of_lt_of_le (lt_add_one _) <|
(le_mul_iff_one_le_right <| add_pos m_pos zero_lt_one).mpr <|
mod_cast (q'.pos : 1 ≤ q'.den)⟩
rw [sq, one_div_lt_one_div md_pos (mul_pos den_pos den_pos), mul_lt_mul_iff_left₀ den_pos]
exact lt_add_of_le_of_pos (Nat.cast_le.mpr hden) zero_lt_one
/-- If `ξ` is an irrational real number, then there are infinitely many good
rational approximations to `ξ`. -/
theorem infinite_rat_abs_sub_lt_one_div_den_sq_of_irrational {ξ : ℝ} (hξ : Irrational ξ) :
{q : ℚ | |ξ - q| < 1 / (q.den : ℝ) ^ 2}.Infinite := by
refine Or.resolve_left (Set.finite_or_infinite _) fun h => ?_
obtain ⟨q, _, hq⟩ :=
exists_min_image {q : ℚ | |ξ - q| < 1 / (q.den : ℝ) ^ 2} (fun q => |ξ - q|) h
⟨⌊ξ⌋, by simp [abs_of_nonneg, Int.fract_lt_one]⟩
obtain ⟨q', hmem, hbetter⟩ := exists_rat_abs_sub_lt_and_lt_of_irrational hξ q
exact lt_irrefl _ (lt_of_le_of_lt (hq q' hmem) hbetter)
end RatApprox
end Real
namespace Rat
/-!
### Finitely many good approximations to rational numbers
We now show that a rational number `ξ` has only finitely many good rational
approximations.
-/
open Set
/-- If `ξ` is rational, then the good rational approximations to `ξ` have bounded
numerator and denominator. -/
theorem den_le_and_le_num_le_of_sub_lt_one_div_den_sq {ξ q : ℚ}
(h : |ξ - q| < 1 / (q.den : ℚ) ^ 2) :
q.den ≤ ξ.den ∧ ⌈ξ * q.den⌉ - 1 ≤ q.num ∧ q.num ≤ ⌊ξ * q.den⌋ + 1 := by
have hq₀ : (0 : ℚ) < q.den := Nat.cast_pos.mpr q.pos
replace h : |ξ * q.den - q.num| < 1 / q.den := by
rw [← mul_lt_mul_iff_left₀ hq₀] at h
conv_lhs at h => rw [← abs_of_pos hq₀, ← abs_mul, sub_mul, mul_den_eq_num]
rwa [sq, div_mul, mul_div_cancel_left₀ _ hq₀.ne'] at h
constructor
· rcases eq_or_ne ξ q with (rfl | H)
· exact le_rfl
· have hξ₀ : (0 : ℚ) < ξ.den := Nat.cast_pos.mpr ξ.pos
rw [← Rat.num_div_den ξ, div_mul_eq_mul_div, div_sub' hξ₀.ne', abs_div, abs_of_pos hξ₀,
div_lt_iff₀ hξ₀, div_mul_comm, mul_one] at h
refine Nat.cast_le.mp ((one_lt_div hq₀).mp <| lt_of_le_of_lt ?_ h).le
norm_cast
rw [mul_comm _ q.num]
exact Int.one_le_abs (sub_ne_zero_of_ne <| mt Rat.eq_iff_mul_eq_mul.mpr H)
· obtain ⟨h₁, h₂⟩ :=
abs_sub_lt_iff.mp
(h.trans_le <|
(one_div_le zero_lt_one hq₀).mp <| (@one_div_one ℚ _).symm ▸ Nat.cast_le.mpr q.pos)
rw [sub_lt_iff_lt_add, add_comm] at h₁ h₂
rw [← sub_lt_iff_lt_add] at h₂
norm_cast at h₁ h₂
exact
⟨sub_le_iff_le_add.mpr (Int.ceil_le.mpr h₁.le), sub_le_iff_le_add.mp (Int.le_floor.mpr h₂.le)⟩
/-- A rational number has only finitely many good rational approximations. -/
theorem finite_rat_abs_sub_lt_one_div_den_sq (ξ : ℚ) :
{q : ℚ | |ξ - q| < 1 / (q.den : ℚ) ^ 2}.Finite := by
let f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
set s := {q : ℚ | |ξ - q| < 1 / (q.den : ℚ) ^ 2}
have hinj : Function.Injective f := by
intro a b hab
simp only [f, Prod.mk_inj] at hab
rw [← Rat.num_div_den a, ← Rat.num_div_den b, hab.1, hab.2]
have H : f '' s ⊆ ⋃ (y : ℕ) (_ : y ∈ Ioc 0 ξ.den), Icc (⌈ξ * y⌉ - 1) (⌊ξ * y⌋ + 1) ×ˢ {y} := by
intro xy hxy
simp only [mem_image] at hxy
obtain ⟨q, hq₁, hq₂⟩ := hxy
obtain ⟨hd, hn⟩ := den_le_and_le_num_le_of_sub_lt_one_div_den_sq hq₁
simp_rw [mem_iUnion]
refine ⟨q.den, Set.mem_Ioc.mpr ⟨q.pos, hd⟩, ?_⟩
simp only [prod_singleton, mem_image, mem_Icc]
exact ⟨q.num, hn, hq₂⟩
refine (Finite.subset ?_ H).of_finite_image hinj.injOn
exact Finite.biUnion (finite_Ioc _ _) fun x _ => Finite.prod (finite_Icc _ _) (finite_singleton _)
end Rat
/-- The set of good rational approximations to a real number `ξ` is infinite if and only if
`ξ` is irrational. -/
theorem Real.infinite_rat_abs_sub_lt_one_div_den_sq_iff_irrational (ξ : ℝ) :
{q : ℚ | |ξ - q| < 1 / (q.den : ℝ) ^ 2}.Infinite ↔ Irrational ξ := by
refine
⟨fun h => (irrational_iff_ne_rational ξ).mpr fun a b _ H => Set.not_infinite.mpr ?_ h,
Real.infinite_rat_abs_sub_lt_one_div_den_sq_of_irrational⟩
convert Rat.finite_rat_abs_sub_lt_one_div_den_sq ((a : ℚ) / b) with q
rw [H, (by (push_cast; rfl) : (1 : ℝ) / (q.den : ℝ) ^ 2 = (1 / (q.den : ℚ) ^ 2 : ℚ))]
norm_cast
/-!
### Legendre's Theorem on Rational Approximation
We prove **Legendre's Theorem** on rational approximation: If $\xi$ is a real number and
$x/y$ is a rational number such that $|\xi - x/y| < 1/(2y^2)$,
then $x/y$ is a convergent of the continued fraction expansion of $\xi$.
The proof is by induction. However, the induction proof does not work with the
statement as given, since the assumption is too weak to imply the corresponding
statement for the application of the induction hypothesis. This can be remedied
by making the statement slightly stronger. Namely, we assume that $|\xi - x/y| < 1/(y(2y-1))$
when $y \ge 2$ and $-\frac{1}{2} < \xi - x < 1$ when $y = 1$.
-/
section Convergent
namespace Real
open Int
/-!
### Convergents: definition and API lemmas
-/
/-- We give a direct recursive definition of the convergents of the continued fraction
expansion of a real number `ξ`. The main reason for that is that we want to have the
convergents as rational numbers; the versions `(GenContFract.of ξ).convs` and
`(GenContFract.of ξ).convs'` always give something of the same type as `ξ`.
We can then also use dot notation `ξ.convergent n`.
Another minor reason is that this demonstrates that the proof
of Legendre's theorem does not need anything beyond this definition.
We provide a proof that this definition agrees with the other one;
see `Real.convs_eq_convergent`.
(Note that we use the fact that `1/0 = 0` here to make it work for rational `ξ`.) -/
noncomputable def convergent : ℝ → ℕ → ℚ
| ξ, 0 => ⌊ξ⌋
| ξ, n + 1 => ⌊ξ⌋ + (convergent (fract ξ)⁻¹ n)⁻¹
/-- The zeroth convergent of `ξ` is `⌊ξ⌋`. -/
@[simp]
theorem convergent_zero (ξ : ℝ) : ξ.convergent 0 = ⌊ξ⌋ :=
rfl
/-- The `(n+1)`th convergent of `ξ` is the `n`th convergent of `1/(fract ξ)`. -/
@[simp]
theorem convergent_succ (ξ : ℝ) (n : ℕ) :
ξ.convergent (n + 1) = ⌊ξ⌋ + ((fract ξ)⁻¹.convergent n)⁻¹ :=
rfl
/-- All convergents of `0` are zero. -/
@[simp]
theorem convergent_of_zero (n : ℕ) : convergent 0 n = 0 := by
induction n with
| zero => simp only [convergent_zero, floor_zero, cast_zero]
| succ n ih =>
simp only [ih, convergent_succ, floor_zero, cast_zero, fract_zero, add_zero, inv_zero]
/-- If `ξ` is an integer, all its convergents equal `ξ`. -/
@[simp]
theorem convergent_of_int {ξ : ℤ} (n : ℕ) : convergent ξ n = ξ := by
cases n
· simp only [convergent_zero, floor_intCast]
· simp only [convergent_succ, floor_intCast, fract_intCast, convergent_of_zero, add_zero,
inv_zero]
end Real
end Convergent
/-!
### The key technical condition for the induction proof
-/
namespace Real
open Int
-- this is not `private`, as it is used in the public `exists_rat_eq_convergent'` below.
/-- Define the technical condition to be used as assumption in the inductive proof. -/
def ContfracLegendre.Ass (ξ : ℝ) (u v : ℤ) : Prop :=
IsCoprime u v ∧ (v = 1 → (-(1 / 2) : ℝ) < ξ - u) ∧
|ξ - u / v| < ((v : ℝ) * (2 * v - 1))⁻¹
-- ### Auxiliary lemmas
-- This saves a few lines below, as it is frequently needed.
private theorem aux₀ {v : ℤ} (hv : 0 < v) : (0 : ℝ) < v ∧ (0 : ℝ) < 2 * v - 1 :=
⟨cast_pos.mpr hv, by norm_cast; cutsat⟩
-- In the following, we assume that `ass ξ u v` holds and `v ≥ 2`.
variable {ξ : ℝ} {u v : ℤ}
section
variable (hv : 2 ≤ v) (h : ContfracLegendre.Ass ξ u v)
include hv h
-- The fractional part of `ξ` is positive.
private theorem aux₁ : 0 < fract ξ := by
have hv₀ : (0 : ℝ) < v := cast_pos.mpr (zero_lt_two.trans_le hv)
obtain ⟨hv₁, hv₂⟩ := aux₀ (zero_lt_two.trans_le hv)
obtain ⟨hcop, _, h⟩ := h
refine fract_pos.mpr fun hf => ?_
rw [hf] at h
have H : (2 * v - 1 : ℝ) < 1 := by
refine (mul_lt_iff_lt_one_right hv₀).1 ((inv_lt_inv₀ hv₀ (mul_pos hv₁ hv₂)).1 (h.trans_le' ?_))
have h' : (⌊ξ⌋ : ℝ) - u / v = (⌊ξ⌋ * v - u) / v := by field
rw [h', abs_div, abs_of_pos hv₀, ← one_div, div_le_div_iff_of_pos_right hv₀]
norm_cast
rw [← zero_add (1 : ℤ), add_one_le_iff, abs_pos, sub_ne_zero]
rintro rfl
cases isUnit_iff.mp (isCoprime_self.mp (IsCoprime.mul_left_iff.mp hcop).2) <;> omega
norm_cast at H
linarith only [hv, H]
-- An auxiliary lemma for the inductive step.
private theorem aux₂ : 0 < u - ⌊ξ⌋ * v ∧ u - ⌊ξ⌋ * v < v := by
obtain ⟨hcop, _, h⟩ := h
obtain ⟨hv₀, hv₀'⟩ := aux₀ (zero_lt_two.trans_le hv)
have hv₁ : 0 < 2 * v - 1 := by linarith only [hv]
rw [← one_div, lt_div_iff₀ (mul_pos hv₀ hv₀'), ← abs_of_pos (mul_pos hv₀ hv₀'), ← abs_mul,
sub_mul, ← mul_assoc, ← mul_assoc, div_mul_cancel₀ _ hv₀.ne', abs_sub_comm, abs_lt,
lt_sub_iff_add_lt, sub_lt_iff_lt_add, mul_assoc] at h
have hu₀ : 0 ≤ u - ⌊ξ⌋ * v := by
refine (mul_nonneg_iff_of_pos_right hv₁).mp ?_
rw [← sub_one_lt_iff, zero_sub]
replace h := h.1
rw [← lt_sub_iff_add_lt, ← mul_assoc, ← sub_mul] at h
exact mod_cast
h.trans_le
((mul_le_mul_iff_left₀ <| hv₀').mpr <|
(sub_le_sub_iff_left (u : ℝ)).mpr ((mul_le_mul_iff_left₀ hv₀).mpr (floor_le ξ)))
have hu₁ : u - ⌊ξ⌋ * v ≤ v := by
refine _root_.le_of_mul_le_mul_right (le_of_lt_add_one ?_) hv₁
replace h := h.2
rw [← sub_lt_iff_lt_add, ← mul_assoc, ← sub_mul, ← add_lt_add_iff_right (v * (2 * v - 1) : ℝ),
add_comm (1 : ℝ)] at h
have :=
flip mul_lt_mul_of_pos_right hv₀' <| (sub_lt_sub_iff_left (u : ℝ)).mpr <|
flip mul_lt_mul_of_pos_right hv₀ <| sub_right_lt_of_lt_add <| lt_floor_add_one ξ
rw [sub_mul ξ, one_mul, ← sub_add, add_mul] at this
exact mod_cast this.trans h
have huv_cop : IsCoprime (u - ⌊ξ⌋ * v) v := by
rwa [sub_eq_add_neg, ← neg_mul, IsCoprime.add_mul_right_left_iff]
refine ⟨lt_of_le_of_ne' hu₀ fun hf => ?_, lt_of_le_of_ne hu₁ fun hf => ?_⟩ <;>
· rw [hf] at huv_cop
simp only [isCoprime_zero_left, isCoprime_self, isUnit_iff] at huv_cop
rcases huv_cop with huv_cop | huv_cop <;> linarith only [hv, huv_cop]
-- The key step: the relevant inequality persists in the inductive step.
private theorem aux₃ :
|(fract ξ)⁻¹ - v / (u - ⌊ξ⌋ * v)| < (((u : ℝ) - ⌊ξ⌋ * v) * (2 * (u - ⌊ξ⌋ * v) - 1))⁻¹ := by
obtain ⟨hu₀, huv⟩ := aux₂ hv h
have hξ₀ := aux₁ hv h
set u' := u - ⌊ξ⌋ * v with hu'
have hu'ℝ : (u' : ℝ) = u - ⌊ξ⌋ * v := mod_cast hu'
rw [← hu'ℝ]
replace hu'ℝ := (eq_sub_iff_add_eq.mp hu'ℝ).symm
obtain ⟨Hu, Hu'⟩ := aux₀ hu₀
obtain ⟨Hv, Hv'⟩ := aux₀ (zero_lt_two.trans_le hv)
have H₁ := div_pos (div_pos Hv Hu) hξ₀
replace h := h.2.2
have h' : |fract ξ - u' / v| < ((v : ℝ) * (2 * v - 1))⁻¹ := by
rwa [hu'ℝ, add_div, mul_div_cancel_right₀ _ Hv.ne', ← sub_sub, sub_right_comm] at h
have H : (2 * u' - 1 : ℝ) ≤ (2 * v - 1) * fract ξ := by
replace h := (abs_lt.mp h).1
have : (2 * (v : ℝ) - 1) * (-((v : ℝ) * (2 * v - 1))⁻¹ + u' / v) = 2 * u' - (1 + u') / v := by
field
rw [hu'ℝ, add_div, mul_div_cancel_right₀ _ Hv.ne', ← sub_sub, sub_right_comm, self_sub_floor,
lt_sub_iff_add_lt, ← mul_lt_mul_iff_right₀ Hv', this] at h
refine LE.le.trans ?_ h.le
rw [sub_le_sub_iff_left, div_le_one Hv, add_comm]
exact mod_cast huv
calc
|(fract ξ)⁻¹ - v / u'| = |(fract ξ - u' / v) * (v / u' / fract ξ)| := by
rw [abs_sub_comm]; congr 1; field
_ = |fract ξ - u' / v| * (v / u' / fract ξ) := by rw [abs_mul, abs_of_pos H₁]
_ < ((v : ℝ) * (2 * v - 1))⁻¹ * (v / u' / fract ξ) := by gcongr
_ = (u' * ((2 * v - 1) * fract ξ))⁻¹ := by field
_ ≤ (u' * (2 * u' - 1) : ℝ)⁻¹ := by gcongr
-- The conditions `ass ξ u v` persist in the inductive step.
private theorem invariant : ContfracLegendre.Ass (fract ξ)⁻¹ v (u - ⌊ξ⌋ * v) := by
refine ⟨?_, fun huv => ?_, mod_cast aux₃ hv h⟩
· rw [sub_eq_add_neg, ← neg_mul, isCoprime_comm, IsCoprime.add_mul_right_left_iff]
exact h.1
· obtain hv₀' := (aux₀ (zero_lt_two.trans_le hv)).2
have Hv : (v * (2 * v - 1) : ℝ)⁻¹ + (v : ℝ)⁻¹ = 2 / (2 * v - 1) := by
simp [field]
have Huv : (u / v : ℝ) = ⌊ξ⌋ + (v : ℝ)⁻¹ := by
rw [sub_eq_iff_eq_add'.mp huv]; simp [field]
have h' := (abs_sub_lt_iff.mp h.2.2).1
rw [Huv, ← sub_sub, sub_lt_iff_lt_add, self_sub_floor, Hv] at h'
rwa [lt_sub_iff_add_lt', (by ring : (v : ℝ) + -(1 / 2) = (2 * v - 1) / 2),
lt_inv_comm₀ (div_pos hv₀' zero_lt_two) (aux₁ hv h), inv_div]
end
/-!
### The main result
-/
/-- The technical version of *Legendre's Theorem*. -/
theorem exists_rat_eq_convergent' {v : ℕ} (h : ContfracLegendre.Ass ξ u v) :
∃ n, (u / v : ℚ) = ξ.convergent n := by
induction v using Nat.strong_induction_on generalizing ξ u with | h v ih => ?_
rcases lt_trichotomy v 1 with (ht | rfl | ht)
· replace h := h.2.2
simp only [Nat.lt_one_iff.mp ht, Nat.cast_zero, div_zero, tsub_zero, zero_mul,
cast_zero, inv_zero] at h
exact False.elim (lt_irrefl _ <| (abs_nonneg ξ).trans_lt h)
· rw [Nat.cast_one, div_one]
obtain ⟨_, h₁, h₂⟩ := h
rcases le_or_gt (u : ℝ) ξ with ht | ht
· use 0
rw [convergent_zero, Rat.coe_int_inj, eq_comm, floor_eq_iff]
convert And.intro ht (sub_lt_iff_lt_add'.mp (abs_lt.mp h₂).2) <;> norm_num
· replace h₁ := lt_sub_iff_add_lt'.mp (h₁ rfl)
have hξ₁ : ⌊ξ⌋ = u - 1 := by
rw [floor_eq_iff, cast_sub, cast_one, sub_add_cancel]
exact ⟨(((sub_lt_sub_iff_left _).mpr one_half_lt_one).trans h₁).le, ht⟩
rcases eq_or_ne ξ ⌊ξ⌋ with Hξ | Hξ
· rw [Hξ, hξ₁, cast_sub, cast_one, ← sub_eq_add_neg, sub_lt_sub_iff_left] at h₁
exact False.elim (lt_irrefl _ <| h₁.trans one_half_lt_one)
· have hξ₂ : ⌊(fract ξ)⁻¹⌋ = 1 := by
rw [floor_eq_iff, cast_one, le_inv_comm₀ zero_lt_one (fract_pos.mpr Hξ), inv_one,
one_add_one_eq_two, inv_lt_comm₀ (fract_pos.mpr Hξ) zero_lt_two]
refine ⟨(fract_lt_one ξ).le, ?_⟩
rw [fract, hξ₁, cast_sub, cast_one, lt_sub_iff_add_lt', sub_add]
convert h₁ using 1
rw [sub_eq_add_neg]
norm_num
use 1
simp [convergent, hξ₁, hξ₂, cast_sub, cast_one]
· obtain ⟨huv₀, huv₁⟩ := aux₂ (Nat.cast_le.mpr ht) h
have Hv : (v : ℚ) ≠ 0 := (Nat.cast_pos.mpr (zero_lt_one.trans ht)).ne'
have huv₁' : (u - ⌊ξ⌋ * v).toNat < v := by zify; rwa [toNat_of_nonneg huv₀.le]
have inv : ContfracLegendre.Ass (fract ξ)⁻¹ v (u - ⌊ξ⌋ * ↑v).toNat :=
(toNat_of_nonneg huv₀.le).symm ▸ invariant (Nat.cast_le.mpr ht) h
obtain ⟨n, hn⟩ := ih (u - ⌊ξ⌋ * v).toNat huv₁' inv
use n + 1
rw [convergent_succ, ← hn,
(mod_cast toNat_of_nonneg huv₀.le : ((u - ⌊ξ⌋ * v).toNat : ℚ) = u - ⌊ξ⌋ * v),
cast_natCast, inv_div, sub_div, mul_div_cancel_right₀ _ Hv, add_sub_cancel]
/-- The main result, *Legendre's Theorem* on rational approximation:
if `ξ` is a real number and `q` is a rational number such that `|ξ - q| < 1/(2*q.den^2)`,
then `q` is a convergent of the continued fraction expansion of `ξ`.
This version uses `Real.convergent`. -/
theorem exists_rat_eq_convergent {q : ℚ} (h : |ξ - q| < 1 / (2 * (q.den : ℝ) ^ 2)) :
∃ n, q = ξ.convergent n := by
refine q.num_div_den ▸ exists_rat_eq_convergent' ⟨?_, fun hd => ?_, ?_⟩
· exact isCoprime_iff_nat_coprime.mpr (natAbs_natCast q.den ▸ q.reduced)
· rw [← q.den_eq_one_iff.mp (Nat.cast_eq_one.mp hd)] at h
simpa only [Rat.den_intCast, Nat.cast_one, one_pow, mul_one] using (abs_lt.mp h).1
· obtain ⟨hq₀, hq₁⟩ := aux₀ (Nat.cast_pos.mpr q.pos)
replace hq₁ := mul_pos hq₀ hq₁
have hq₂ : (0 : ℝ) < 2 * (q.den * q.den) := mul_pos zero_lt_two (mul_pos hq₀ hq₀)
rw [cast_natCast] at *
rw [(by norm_cast : (q.num / q.den : ℝ) = (q.num / q.den : ℚ)), Rat.num_div_den]
exact h.trans (by rw [← one_div, sq, one_div_lt_one_div hq₂ hq₁, ← sub_pos]; ring_nf; exact hq₀)
end Real |
.lake/packages/mathlib/Mathlib/NumberTheory/EulerProduct/DirichletLSeries.lean | import Mathlib.NumberTheory.EulerProduct.ExpLog
import Mathlib.NumberTheory.LSeries.Dirichlet
/-!
# The Euler Product for the Riemann Zeta Function and Dirichlet L-Series
The first main result of this file is the Euler Product formula for the Riemann ζ function
$$\prod_p \frac{1}{1 - p^{-s}}
= \lim_{n \to \infty} \prod_{p < n} \frac{1}{1 - p^{-s}} = \zeta(s)$$
for $s$ with real part $> 1$ ($p$ runs through the primes).
`riemannZeta_eulerProduct` is the second equality above. There are versions
`riemannZeta_eulerProduct_hasProd` and `riemannZeta_eulerProduct_tprod` in terms of `HasProd`
and `tprod`, respectively.
The second result is `dirichletLSeries_eulerProduct` (with variants
`dirichletLSeries_eulerProduct_hasProd` and `dirichletLSeries_eulerProduct_tprod`),
which is the analogous statement for Dirichlet L-series.
-/
open Complex
variable {s : ℂ}
/-- When `s ≠ 0`, the map `n ↦ n^(-s)` is completely multiplicative and vanishes at zero. -/
noncomputable
def riemannZetaSummandHom (hs : s ≠ 0) : ℕ →*₀ ℂ where
toFun n := (n : ℂ) ^ (-s)
map_zero' := by simp [hs]
map_one' := by simp
map_mul' m n := by
simpa only [Nat.cast_mul, ofReal_natCast]
using mul_cpow_ofReal_nonneg m.cast_nonneg n.cast_nonneg _
/-- When `χ` is a Dirichlet character and `s ≠ 0`, the map `n ↦ χ n * n^(-s)` is completely
multiplicative and vanishes at zero. -/
noncomputable
def dirichletSummandHom {n : ℕ} (χ : DirichletCharacter ℂ n) (hs : s ≠ 0) : ℕ →*₀ ℂ where
toFun n := χ n * (n : ℂ) ^ (-s)
map_zero' := by simp [hs]
map_one' := by simp
map_mul' m n := by
simp_rw [← ofReal_natCast]
simpa only [Nat.cast_mul, IsUnit.mul_iff, not_and, map_mul, ofReal_mul,
mul_cpow_ofReal_nonneg m.cast_nonneg n.cast_nonneg _]
using mul_mul_mul_comm ..
/-- When `s.re > 1`, the map `n ↦ n^(-s)` is norm-summable. -/
lemma summable_riemannZetaSummand (hs : 1 < s.re) :
Summable (fun n ↦ ‖riemannZetaSummandHom (ne_zero_of_one_lt_re hs) n‖) := by
simp only [riemannZetaSummandHom, MonoidWithZeroHom.coe_mk, ZeroHom.coe_mk]
convert Real.summable_nat_rpow_inv.mpr hs with n
rw [← ofReal_natCast,
norm_cpow_eq_rpow_re_of_nonneg (Nat.cast_nonneg n) <| re_neg_ne_zero_of_one_lt_re hs,
neg_re, Real.rpow_neg <| Nat.cast_nonneg n]
lemma tsum_riemannZetaSummand (hs : 1 < s.re) :
∑' (n : ℕ), riemannZetaSummandHom (ne_zero_of_one_lt_re hs) n = riemannZeta s := by
have hsum := summable_riemannZetaSummand hs
rw [zeta_eq_tsum_one_div_nat_add_one_cpow hs, hsum.of_norm.tsum_eq_zero_add, map_zero, zero_add]
simp only [riemannZetaSummandHom, cpow_neg, MonoidWithZeroHom.coe_mk, ZeroHom.coe_mk,
Nat.cast_add, Nat.cast_one, one_div]
/-- When `s.re > 1`, the map `n ↦ χ(n) * n^(-s)` is norm-summable. -/
lemma summable_dirichletSummand {N : ℕ} (χ : DirichletCharacter ℂ N) (hs : 1 < s.re) :
Summable (fun n ↦ ‖dirichletSummandHom χ (ne_zero_of_one_lt_re hs) n‖) := by
simp only [dirichletSummandHom, MonoidWithZeroHom.coe_mk, ZeroHom.coe_mk, norm_mul]
exact (summable_riemannZetaSummand hs).of_nonneg_of_le (fun _ ↦ by positivity)
(fun n ↦ mul_le_of_le_one_left (norm_nonneg _) <| χ.norm_le_one n)
open scoped LSeries.notation in
lemma tsum_dirichletSummand {N : ℕ} (χ : DirichletCharacter ℂ N) (hs : 1 < s.re) :
∑' (n : ℕ), dirichletSummandHom χ (ne_zero_of_one_lt_re hs) n = L ↗χ s := by
simp only [dirichletSummandHom, cpow_neg, MonoidWithZeroHom.coe_mk, ZeroHom.coe_mk, LSeries,
LSeries.term_of_ne_zero' (ne_zero_of_one_lt_re hs), div_eq_mul_inv]
open Filter Nat Topology EulerProduct
/-- The Euler product for the Riemann ζ function, valid for `s.re > 1`.
This version is stated in terms of `HasProd`. -/
theorem riemannZeta_eulerProduct_hasProd (hs : 1 < s.re) :
HasProd (fun p : Primes ↦ (1 - (p : ℂ) ^ (-s))⁻¹) (riemannZeta s) := by
rw [← tsum_riemannZetaSummand hs]
apply eulerProduct_completely_multiplicative_hasProd <| summable_riemannZetaSummand hs
/-- The Euler product for the Riemann ζ function, valid for `s.re > 1`.
This version is stated in terms of `tprod`. -/
theorem riemannZeta_eulerProduct_tprod (hs : 1 < s.re) :
∏' p : Primes, (1 - (p : ℂ) ^ (-s))⁻¹ = riemannZeta s :=
(riemannZeta_eulerProduct_hasProd hs).tprod_eq
/-- The Euler product for the Riemann ζ function, valid for `s.re > 1`.
This version is stated in the form of convergence of finite partial products. -/
theorem riemannZeta_eulerProduct (hs : 1 < s.re) :
Tendsto (fun n : ℕ ↦ ∏ p ∈ primesBelow n, (1 - (p : ℂ) ^ (-s))⁻¹) atTop
(𝓝 (riemannZeta s)) := by
rw [← tsum_riemannZetaSummand hs]
apply eulerProduct_completely_multiplicative <| summable_riemannZetaSummand hs
open scoped LSeries.notation
/-- The Euler product for Dirichlet L-series, valid for `s.re > 1`.
This version is stated in terms of `HasProd`. -/
theorem DirichletCharacter.LSeries_eulerProduct_hasProd {N : ℕ} (χ : DirichletCharacter ℂ N)
(hs : 1 < s.re) :
HasProd (fun p : Primes ↦ (1 - χ p * (p : ℂ) ^ (-s))⁻¹) (L ↗χ s) := by
rw [← tsum_dirichletSummand χ hs]
convert eulerProduct_completely_multiplicative_hasProd <| summable_dirichletSummand χ hs
/-- The Euler product for Dirichlet L-series, valid for `s.re > 1`.
This version is stated in terms of `tprod`. -/
theorem DirichletCharacter.LSeries_eulerProduct_tprod {N : ℕ} (χ : DirichletCharacter ℂ N)
(hs : 1 < s.re) :
∏' p : Primes, (1 - χ p * (p : ℂ) ^ (-s))⁻¹ = L ↗χ s :=
(DirichletCharacter.LSeries_eulerProduct_hasProd χ hs).tprod_eq
/-- The Euler product for Dirichlet L-series, valid for `s.re > 1`.
This version is stated in the form of convergence of finite partial products. -/
theorem DirichletCharacter.LSeries_eulerProduct {N : ℕ} (χ : DirichletCharacter ℂ N)
(hs : 1 < s.re) :
Tendsto (fun n : ℕ ↦ ∏ p ∈ primesBelow n, (1 - χ p * (p : ℂ) ^ (-s))⁻¹) atTop
(𝓝 (L ↗χ s)) := by
rw [← tsum_dirichletSummand χ hs]
apply eulerProduct_completely_multiplicative <| summable_dirichletSummand χ hs
open LSeries
/-- A variant of the Euler product for Dirichlet L-series. -/
theorem DirichletCharacter.LSeries_eulerProduct_exp_log {N : ℕ} (χ : DirichletCharacter ℂ N)
{s : ℂ} (hs : 1 < s.re) :
exp (∑' p : Nat.Primes, -log (1 - χ p * p ^ (-s))) = L ↗χ s := by
let f := dirichletSummandHom χ <| ne_zero_of_one_lt_re hs
have h n : term ↗χ s n = f n := by
rcases eq_or_ne n 0 with rfl | hn
· simp only [term_zero, map_zero]
· simp only [ne_eq, hn, not_false_eq_true, term_of_ne_zero, div_eq_mul_inv,
dirichletSummandHom, cpow_neg, MonoidWithZeroHom.coe_mk, ZeroHom.coe_mk, f]
simpa only [LSeries, h]
using exp_tsum_primes_log_eq_tsum (f := f) <| summable_dirichletSummand χ hs
open DirichletCharacter
/-- A variant of the Euler product for the L-series of `ζ`. -/
theorem ArithmeticFunction.LSeries_zeta_eulerProduct_exp_log {s : ℂ} (hs : 1 < s.re) :
exp (∑' p : Nat.Primes, -Complex.log (1 - p ^ (-s))) = L 1 s := by
convert modOne_eq_one (R := ℂ) ▸
DirichletCharacter.LSeries_eulerProduct_exp_log (1 : DirichletCharacter ℂ 1) hs using 7
rw [MulChar.one_apply <| isUnit_of_subsingleton _, one_mul]
/-- A variant of the Euler product for the Riemann zeta function. -/
theorem riemannZeta_eulerProduct_exp_log {s : ℂ} (hs : 1 < s.re) :
exp (∑' p : Nat.Primes, -Complex.log (1 - p ^ (-s))) = riemannZeta s :=
LSeries_one_eq_riemannZeta hs ▸ ArithmeticFunction.LSeries_zeta_eulerProduct_exp_log hs
/-!
### Changing the level of a Dirichlet `L`-series
-/
/-- If `χ` is a Dirichlet character and its level `M` divides `N`, then we obtain the L-series
of `χ` considered as a Dirichlet character of level `N` from the L-series of `χ` by multiplying
with `∏ p ∈ N.primeFactors, (1 - χ p * p ^ (-s))`. -/
lemma DirichletCharacter.LSeries_changeLevel {M N : ℕ} [NeZero N]
(hMN : M ∣ N) (χ : DirichletCharacter ℂ M) {s : ℂ} (hs : 1 < s.re) :
LSeries ↗(changeLevel hMN χ) s =
LSeries ↗χ s * ∏ p ∈ N.primeFactors, (1 - χ p * p ^ (-s)) := by
rw [prod_eq_tprod_mulIndicator, ← DirichletCharacter.LSeries_eulerProduct_tprod _ hs,
← DirichletCharacter.LSeries_eulerProduct_tprod _ hs]
-- convert to a form suitable for `tprod_subtype`
have (f : Primes → ℂ) : ∏' (p : Primes), f p = ∏' (p : ↑{p : ℕ | p.Prime}), f p := rfl
rw [this, tprod_subtype _ fun p : ℕ ↦ (1 - (changeLevel hMN χ) p * p ^ (-s))⁻¹,
this, tprod_subtype _ fun p : ℕ ↦ (1 - χ p * p ^ (-s))⁻¹, ← Multipliable.tprod_mul]
rotate_left -- deal with convergence goals first
· exact multipliable_subtype_iff_mulIndicator.mp
(DirichletCharacter.LSeries_eulerProduct_hasProd χ hs).multipliable
· exact multipliable_subtype_iff_mulIndicator.mp Multipliable.of_finite
· congr 1 with p
simp only [Set.mulIndicator_apply, Set.mem_setOf_eq, Finset.mem_coe, Nat.mem_primeFactors,
ne_eq, mul_ite, ite_mul, one_mul, mul_one]
by_cases h : p.Prime; swap
· simp only [h, false_and, if_false]
simp only [h, true_and, if_true]
by_cases hp' : p ∣ N; swap
· simp only [hp', false_and, ↓reduceIte, inv_inj, sub_right_inj, mul_eq_mul_right_iff,
cpow_eq_zero_iff, Nat.cast_eq_zero, h.ne_zero, ne_eq, neg_eq_zero, or_false]
have hq : IsUnit (p : ZMod N) := (ZMod.isUnit_prime_iff_not_dvd h).mpr hp'
simp only [hq.unit_spec ▸ DirichletCharacter.changeLevel_eq_cast_of_dvd χ hMN hq.unit,
ZMod.cast_natCast hMN]
· simp only [hp', NeZero.ne N, not_false_eq_true, and_self, ↓reduceIte]
have : ¬IsUnit (p : ZMod N) := by rwa [ZMod.isUnit_prime_iff_not_dvd h, not_not]
rw [MulChar.map_nonunit _ this, zero_mul, sub_zero, inv_one]
refine (inv_mul_cancel₀ ?_).symm
rw [sub_ne_zero, ne_comm]
-- Remains to show `χ p * p ^ (-s) ≠ 1`. We show its norm is strictly `< 1`.
apply_fun (‖·‖)
simp only [norm_mul, norm_one]
have ha : ‖χ p‖ ≤ 1 := χ.norm_le_one p
have hb : ‖(p : ℂ) ^ (-s)‖ ≤ 1 / 2 := norm_prime_cpow_le_one_half ⟨p, h⟩ hs
exact ((mul_le_mul ha hb (norm_nonneg _) zero_le_one).trans_lt (by norm_num)).ne |
.lake/packages/mathlib/Mathlib/NumberTheory/EulerProduct/Basic.lean | import Mathlib.Analysis.Normed.Ring.InfiniteSum
import Mathlib.Analysis.SpecificLimits.Normed
import Mathlib.NumberTheory.ArithmeticFunction
import Mathlib.NumberTheory.SmoothNumbers
/-!
# Euler Products
The main result in this file is `EulerProduct.eulerProduct_hasProd`, which says that
if `f : ℕ → R` is norm-summable, where `R` is a complete normed commutative ring and `f` is
multiplicative on coprime arguments with `f 0 = 0`, then
`∏' p : Primes, ∑' e : ℕ, f (p^e)` converges to `∑' n, f n`.
`ArithmeticFunction.IsMultiplicative.eulerProduct_hasProd` is a version
for multiplicative arithmetic functions in the sense of
`ArithmeticFunction.IsMultiplicative`.
There is also a version `EulerProduct.eulerProduct_completely_multiplicative_hasProd`,
which states that `∏' p : Primes, (1 - f p)⁻¹` converges to `∑' n, f n`
when `f` is completely multiplicative with values in a complete normed field `F`
(implemented as `f : ℕ →*₀ F`).
There are variants stating the equality of the infinite product and the infinite sum
(`EulerProduct.eulerProduct_tprod`, `ArithmeticFunction.IsMultiplicative.eulerProduct_tprod`,
`EulerProduct.eulerProduct_completely_multiplicative_tprod`) and also variants stating
the convergence of the sequence of partial products over primes `< n`
(`EulerProduct.eulerProduct`, `ArithmeticFunction.IsMultiplicative.eulerProduct`,
`EulerProduct.eulerProduct_completely_multiplicative`.)
An intermediate step is `EulerProduct.summable_and_hasSum_factoredNumbers_prod_filter_prime_tsum`
(and its variant `EulerProduct.summable_and_hasSum_factoredNumbers_prod_filter_prime_geometric`),
which relates the finite product over primes `p ∈ s` to the sum of `f n` over `s`-factored `n`,
for `s : Finset ℕ`.
## Tags
Euler product, multiplicative function
-/
/-- If `f` is multiplicative and summable, then its values at natural numbers `> 1`
have norm strictly less than `1`. -/
lemma Summable.norm_lt_one {F : Type*} [NormedDivisionRing F] [CompleteSpace F] {f : ℕ →* F}
(hsum : Summable f) {p : ℕ} (hp : 1 < p) :
‖f p‖ < 1 := by
refine summable_geometric_iff_norm_lt_one.mp ?_
simp_rw [← map_pow]
exact hsum.comp_injective <| Nat.pow_right_injective hp
open scoped Topology
open Nat Finset
section General
/-!
### General Euler Products
In this section we consider multiplicative (on coprime arguments) functions `f : ℕ → R`,
where `R` is a complete normed commutative ring. The main result is `EulerProduct.eulerProduct`.
-/
variable {R : Type*} [NormedCommRing R] {f : ℕ → R}
-- local instance to speed up typeclass search
@[local instance] private lemma instT0Space : T0Space R := MetricSpace.instT0Space
variable [CompleteSpace R]
namespace EulerProduct
variable (hf₁ : f 1 = 1) (hmul : ∀ {m n}, Nat.Coprime m n → f (m * n) = f m * f n)
include hf₁ hmul in
/-- We relate a finite product over primes in `s` to an infinite sum over `s`-factored numbers. -/
lemma summable_and_hasSum_factoredNumbers_prod_filter_prime_tsum
(hsum : ∀ {p : ℕ}, p.Prime → Summable (fun n : ℕ ↦ ‖f (p ^ n)‖)) (s : Finset ℕ) :
Summable (fun m : factoredNumbers s ↦ ‖f m‖) ∧
HasSum (fun m : factoredNumbers s ↦ f m)
(∏ p ∈ s with p.Prime, ∑' n : ℕ, f (p ^ n)) := by
induction s using Finset.induction with
| empty =>
rw [factoredNumbers_empty]
simp only [notMem_empty, IsEmpty.forall_iff, forall_const, filter_true_of_mem, prod_empty]
exact ⟨(Set.finite_singleton 1).summable (‖f ·‖), hf₁ ▸ hasSum_singleton 1 f⟩
| insert p s hp ih =>
rw [filter_insert]
split_ifs with hpp
· constructor
· simp only [← (equivProdNatFactoredNumbers hpp hp).summable_iff, Function.comp_def,
equivProdNatFactoredNumbers_apply', factoredNumbers.map_prime_pow_mul hmul hpp hp]
refine Summable.of_nonneg_of_le (fun _ ↦ norm_nonneg _) (fun _ ↦ norm_mul_le ..) ?_
apply Summable.mul_of_nonneg (hsum hpp) ih.1 <;> exact fun n ↦ norm_nonneg _
· have hp' : p ∉ {p ∈ s | p.Prime} := mt (mem_of_mem_filter p) hp
rw [prod_insert hp', ← (equivProdNatFactoredNumbers hpp hp).hasSum_iff, Function.comp_def]
conv =>
enter [1, x]
rw [equivProdNatFactoredNumbers_apply', factoredNumbers.map_prime_pow_mul hmul hpp hp]
have : T3Space R := instT3Space -- speeds up the following
apply (hsum hpp).of_norm.hasSum.mul ih.2
-- `exact summable_mul_of_summable_norm (hsum hpp) ih.1` gives a time-out
apply summable_mul_of_summable_norm (hsum hpp) ih.1
· rwa [factoredNumbers_insert s hpp]
include hf₁ hmul in
/-- A version of `EulerProduct.summable_and_hasSum_factoredNumbers_prod_filter_prime_tsum`
in terms of the value of the series. -/
lemma prod_filter_prime_tsum_eq_tsum_factoredNumbers (hsum : Summable (‖f ·‖)) (s : Finset ℕ) :
∏ p ∈ s with p.Prime, ∑' n : ℕ, f (p ^ n) = ∑' m : factoredNumbers s, f m :=
(summable_and_hasSum_factoredNumbers_prod_filter_prime_tsum hf₁ hmul
(fun hp ↦ hsum.comp_injective <| Nat.pow_right_injective hp.one_lt) _).2.tsum_eq.symm
/-- The following statement says that summing over `s`-factored numbers such that
`s` contains `primesBelow N` for large enough `N` gets us arbitrarily close to the sum
over all natural numbers (assuming `f` is summable and `f 0 = 0`; the latter since
`0` is not `s`-factored). -/
lemma norm_tsum_factoredNumbers_sub_tsum_lt (hsum : Summable f) (hf₀ : f 0 = 0) {ε : ℝ}
(εpos : 0 < ε) :
∃ N : ℕ, ∀ s : Finset ℕ, primesBelow N ≤ s →
‖(∑' m : ℕ, f m) - ∑' m : factoredNumbers s, f m‖ < ε := by
obtain ⟨N, hN⟩ :=
summable_iff_nat_tsum_vanishing.mp hsum (Metric.ball 0 ε) <| Metric.ball_mem_nhds 0 εpos
simp_rw [mem_ball_zero_iff] at hN
refine ⟨N, fun s hs ↦ ?_⟩
have := hN _ <| factoredNumbers_compl hs
rwa [← hsum.tsum_subtype_add_tsum_subtype_compl (factoredNumbers s),
add_sub_cancel_left, tsum_eq_tsum_diff_singleton (factoredNumbers s)ᶜ hf₀]
-- Versions of the three lemmas above for `smoothNumbers N`
include hf₁ hmul in
/-- We relate a finite product over primes to an infinite sum over smooth numbers. -/
lemma summable_and_hasSum_smoothNumbers_prod_primesBelow_tsum
(hsum : ∀ {p : ℕ}, p.Prime → Summable (fun n : ℕ ↦ ‖f (p ^ n)‖)) (N : ℕ) :
Summable (fun m : N.smoothNumbers ↦ ‖f m‖) ∧
HasSum (fun m : N.smoothNumbers ↦ f m) (∏ p ∈ N.primesBelow, ∑' n : ℕ, f (p ^ n)) := by
rw [smoothNumbers_eq_factoredNumbers, primesBelow]
exact summable_and_hasSum_factoredNumbers_prod_filter_prime_tsum hf₁ hmul hsum _
include hf₁ hmul in
/-- A version of `EulerProduct.summable_and_hasSum_smoothNumbers_prod_primesBelow_tsum`
in terms of the value of the series. -/
lemma prod_primesBelow_tsum_eq_tsum_smoothNumbers (hsum : Summable (‖f ·‖)) (N : ℕ) :
∏ p ∈ N.primesBelow, ∑' n : ℕ, f (p ^ n) = ∑' m : N.smoothNumbers, f m :=
(summable_and_hasSum_smoothNumbers_prod_primesBelow_tsum hf₁ hmul
(fun hp ↦ hsum.comp_injective <| Nat.pow_right_injective hp.one_lt) _).2.tsum_eq.symm
/-- The following statement says that summing over `N`-smooth numbers
for large enough `N` gets us arbitrarily close to the sum over all natural numbers
(assuming `f` is norm-summable and `f 0 = 0`; the latter since `0` is not smooth). -/
lemma norm_tsum_smoothNumbers_sub_tsum_lt (hsum : Summable f) (hf₀ : f 0 = 0)
{ε : ℝ} (εpos : 0 < ε) :
∃ N₀ : ℕ, ∀ N ≥ N₀, ‖(∑' m : ℕ, f m) - ∑' m : N.smoothNumbers, f m‖ < ε := by
conv => enter [1, N₀, N]; rw [smoothNumbers_eq_factoredNumbers]
obtain ⟨N₀, hN₀⟩ := norm_tsum_factoredNumbers_sub_tsum_lt hsum hf₀ εpos
refine ⟨N₀, fun N hN ↦ hN₀ (range N) fun p hp ↦ ?_⟩
exact mem_range.mpr <| (lt_of_mem_primesBelow hp).trans_le hN
include hf₁ hmul in
/-- The *Euler Product* for multiplicative (on coprime arguments) functions.
If `f : ℕ → R`, where `R` is a complete normed commutative ring, `f 0 = 0`, `f 1 = 1`, `f` is
multiplicative on coprime arguments, and `‖f ·‖` is summable, then
`∏' p : Nat.Primes, ∑' e, f (p ^ e) = ∑' n, f n`. This version is stated using `HasProd`. -/
theorem eulerProduct_hasProd (hsum : Summable (‖f ·‖)) (hf₀ : f 0 = 0) :
HasProd (fun p : Primes ↦ ∑' e, f (p ^ e)) (∑' n, f n) := by
let F : ℕ → R := fun n ↦ ∑' e, f (n ^ e)
change HasProd (F ∘ Subtype.val (p := (· ∈ {x | Nat.Prime x}))) _
rw [hasProd_subtype_iff_mulIndicator, HasProd, SummationFilter.unconditional,
Metric.tendsto_atTop]
intro ε hε
obtain ⟨N₀, hN₀⟩ := norm_tsum_factoredNumbers_sub_tsum_lt hsum.of_norm hf₀ hε
refine ⟨range N₀, fun s hs ↦ ?_⟩
have : ∏ p ∈ s, {p | Nat.Prime p}.mulIndicator F p = ∏ p ∈ s with p.Prime, F p :=
prod_mulIndicator_eq_prod_filter s (fun _ ↦ F) _ id
rw [this, dist_eq_norm, prod_filter_prime_tsum_eq_tsum_factoredNumbers hf₁ hmul hsum,
norm_sub_rev]
exact hN₀ s fun p hp ↦ hs <| mem_range.mpr <| lt_of_mem_primesBelow hp
include hf₁ hmul in
/-- The *Euler Product* for multiplicative (on coprime arguments) functions.
If `f : ℕ → R`, where `R` is a complete normed commutative ring, `f 0 = 0`, `f 1 = 1`, `f` i
multiplicative on coprime arguments, and `‖f ·‖` is summable, then
`∏' p : ℕ, if p.Prime then ∑' e, f (p ^ e) else 1 = ∑' n, f n`.
This version is stated using `HasProd` and `Set.mulIndicator`. -/
theorem eulerProduct_hasProd_mulIndicator (hsum : Summable (‖f ·‖)) (hf₀ : f 0 = 0) :
HasProd (Set.mulIndicator {p | Nat.Prime p} fun p ↦ ∑' e, f (p ^ e)) (∑' n, f n) := by
rw [← hasProd_subtype_iff_mulIndicator]
exact eulerProduct_hasProd hf₁ hmul hsum hf₀
open Filter in
include hf₁ hmul in
/-- The *Euler Product* for multiplicative (on coprime arguments) functions.
If `f : ℕ → R`, where `R` is a complete normed commutative ring, `f 0 = 0`, `f 1 = 1`, `f` is
multiplicative on coprime arguments, and `‖f ·‖` is summable, then
`∏' p : {p : ℕ | p.Prime}, ∑' e, f (p ^ e) = ∑' n, f n`.
This is a version using convergence of finite partial products. -/
theorem eulerProduct (hsum : Summable (‖f ·‖)) (hf₀ : f 0 = 0) :
Tendsto (fun n : ℕ ↦ ∏ p ∈ primesBelow n, ∑' e, f (p ^ e)) atTop (𝓝 (∑' n, f n)) := by
have := (eulerProduct_hasProd_mulIndicator hf₁ hmul hsum hf₀).tendsto_prod_nat
let F : ℕ → R := fun p ↦ ∑' (e : ℕ), f (p ^ e)
have H (n : ℕ) : ∏ i ∈ range n, Set.mulIndicator {p | Nat.Prime p} F i =
∏ p ∈ primesBelow n, ∑' (e : ℕ), f (p ^ e) :=
prod_mulIndicator_eq_prod_filter (range n) (fun _ ↦ F) (fun _ ↦ {p | Nat.Prime p}) id
simpa only [F, H]
include hf₁ hmul in
/-- The *Euler Product* for multiplicative (on coprime arguments) functions.
If `f : ℕ → R`, where `R` is a complete normed commutative ring, `f 0 = 0`, `f 1 = 1`, `f` is
multiplicative on coprime arguments, and `‖f ·‖` is summable, then
`∏' p : {p : ℕ | p.Prime}, ∑' e, f (p ^ e) = ∑' n, f n`. -/
theorem eulerProduct_tprod (hsum : Summable (‖f ·‖)) (hf₀ : f 0 = 0) :
∏' p : Primes, ∑' e, f (p ^ e) = ∑' n, f n :=
(eulerProduct_hasProd hf₁ hmul hsum hf₀).tprod_eq
end EulerProduct
/-!
### Versions for arithmetic functions
-/
namespace ArithmeticFunction
open EulerProduct
/-- The *Euler Product* for a multiplicative arithmetic function `f` with values in a
complete normed commutative ring `R`: if `‖f ·‖` is summable, then
`∏' p : Nat.Primes, ∑' e, f (p ^ e) = ∑' n, f n`.
This version is stated in terms of `HasProd`. -/
nonrec theorem IsMultiplicative.eulerProduct_hasProd {f : ArithmeticFunction R}
(hf : f.IsMultiplicative) (hsum : Summable (‖f ·‖)) :
HasProd (fun p : Primes ↦ ∑' e, f (p ^ e)) (∑' n, f n) :=
eulerProduct_hasProd hf.1 hf.2 hsum f.map_zero
open Filter in
/-- The *Euler Product* for a multiplicative arithmetic function `f` with values in a
complete normed commutative ring `R`: if `‖f ·‖` is summable, then
`∏' p : Nat.Primes, ∑' e, f (p ^ e) = ∑' n, f n`.
This version is stated in the form of convergence of finite partial products. -/
nonrec theorem IsMultiplicative.eulerProduct {f : ArithmeticFunction R} (hf : f.IsMultiplicative)
(hsum : Summable (‖f ·‖)) :
Tendsto (fun n : ℕ ↦ ∏ p ∈ primesBelow n, ∑' e, f (p ^ e)) atTop (𝓝 (∑' n, f n)) :=
eulerProduct hf.1 hf.2 hsum f.map_zero
/-- The *Euler Product* for a multiplicative arithmetic function `f` with values in a
complete normed commutative ring `R`: if `‖f ·‖` is summable, then
`∏' p : Nat.Primes, ∑' e, f (p ^ e) = ∑' n, f n`. -/
nonrec theorem IsMultiplicative.eulerProduct_tprod {f : ArithmeticFunction R}
(hf : f.IsMultiplicative) (hsum : Summable (‖f ·‖)) :
∏' p : Primes, ∑' e, f (p ^ e) = ∑' n, f n :=
eulerProduct_tprod hf.1 hf.2 hsum f.map_zero
end ArithmeticFunction
end General
section CompletelyMultiplicative
/-!
### Euler Products for completely multiplicative functions
We now assume that `f` is completely multiplicative and has values in a complete normed field `F`.
Then we can use the formula for geometric series to simplify the statement. This leads to
`EulerProduct.eulerProduct_completely_multiplicative_hasProd` and variants.
-/
variable {F : Type*} [NormedField F] [CompleteSpace F]
namespace EulerProduct
-- a helper lemma that is useful below
lemma one_sub_inv_eq_geometric_of_summable_norm {f : ℕ →*₀ F} {p : ℕ} (hp : p.Prime)
(hsum : Summable fun x ↦ ‖f x‖) :
(1 - f p)⁻¹ = ∑' (e : ℕ), f (p ^ e) := by
simp only [map_pow]
refine (tsum_geometric_of_norm_lt_one <| summable_geometric_iff_norm_lt_one.mp ?_).symm
refine Summable.of_norm ?_
simpa only [Function.comp_def, map_pow]
using hsum.comp_injective <| Nat.pow_right_injective hp.one_lt
/-- Given a (completely) multiplicative function `f : ℕ → F`, where `F` is a normed field,
such that `‖f p‖ < 1` for all primes `p`, we can express the sum of `f n` over all `s`-factored
positive integers `n` as a product of `(1 - f p)⁻¹` over the primes `p ∈ s`. At the same time,
we show that the sum involved converges absolutely. -/
lemma summable_and_hasSum_factoredNumbers_prod_filter_prime_geometric {f : ℕ →* F}
(h : ∀ {p : ℕ}, p.Prime → ‖f p‖ < 1) (s : Finset ℕ) :
Summable (fun m : factoredNumbers s ↦ ‖f m‖) ∧
HasSum (fun m : factoredNumbers s ↦ f m) (∏ p ∈ s with p.Prime, (1 - f p)⁻¹) := by
have hmul {m n} (_ : Nat.Coprime m n) := f.map_mul m n
have H₁ :
∏ p ∈ s with p.Prime, ∑' n : ℕ, f (p ^ n) = ∏ p ∈ s with p.Prime, (1 - f p)⁻¹ := by
refine prod_congr rfl fun p hp ↦ ?_
simp only [map_pow]
exact tsum_geometric_of_norm_lt_one <| h (mem_filter.mp hp).2
have H₂ : ∀ {p : ℕ}, p.Prime → Summable fun n ↦ ‖f (p ^ n)‖ := by
intro p hp
simp only [map_pow]
refine Summable.of_nonneg_of_le (fun _ ↦ norm_nonneg _) (fun _ ↦ norm_pow_le ..) ?_
exact summable_geometric_iff_norm_lt_one.mpr <| (norm_norm (f p)).symm ▸ h hp
exact H₁ ▸ summable_and_hasSum_factoredNumbers_prod_filter_prime_tsum f.map_one hmul H₂ s
/-- A version of `EulerProduct.summable_and_hasSum_factoredNumbers_prod_filter_prime_geometric`
in terms of the value of the series. -/
lemma prod_filter_prime_geometric_eq_tsum_factoredNumbers {f : ℕ →* F} (hsum : Summable f)
(s : Finset ℕ) :
∏ p ∈ s with p.Prime, (1 - f p)⁻¹ = ∑' m : factoredNumbers s, f m := by
refine (summable_and_hasSum_factoredNumbers_prod_filter_prime_geometric ?_ s).2.tsum_eq.symm
exact fun {_} hp ↦ hsum.norm_lt_one hp.one_lt
/-- Given a (completely) multiplicative function `f : ℕ → F`, where `F` is a normed field,
such that `‖f p‖ < 1` for all primes `p`, we can express the sum of `f n` over all `N`-smooth
positive integers `n` as a product of `(1 - f p)⁻¹` over the primes `p < N`. At the same time,
we show that the sum involved converges absolutely. -/
lemma summable_and_hasSum_smoothNumbers_prod_primesBelow_geometric {f : ℕ →* F}
(h : ∀ {p : ℕ}, p.Prime → ‖f p‖ < 1) (N : ℕ) :
Summable (fun m : N.smoothNumbers ↦ ‖f m‖) ∧
HasSum (fun m : N.smoothNumbers ↦ f m) (∏ p ∈ N.primesBelow, (1 - f p)⁻¹) := by
rw [smoothNumbers_eq_factoredNumbers, primesBelow]
exact summable_and_hasSum_factoredNumbers_prod_filter_prime_geometric h _
/-- A version of `EulerProduct.summable_and_hasSum_smoothNumbers_prod_primesBelow_geometric`
in terms of the value of the series. -/
lemma prod_primesBelow_geometric_eq_tsum_smoothNumbers {f : ℕ →* F} (hsum : Summable f) (N : ℕ) :
∏ p ∈ N.primesBelow, (1 - f p)⁻¹ = ∑' m : N.smoothNumbers, f m := by
rw [smoothNumbers_eq_factoredNumbers, primesBelow]
exact prod_filter_prime_geometric_eq_tsum_factoredNumbers hsum _
/-- The *Euler Product* for completely multiplicative functions.
If `f : ℕ →*₀ F`, where `F` is a complete normed field and `‖f ·‖` is summable, then
`∏' p : Nat.Primes, (1 - f p)⁻¹ = ∑' n, f n`.
This version is stated in terms of `HasProd`. -/
theorem eulerProduct_completely_multiplicative_hasProd {f : ℕ →*₀ F} (hsum : Summable (‖f ·‖)) :
HasProd (fun p : Primes ↦ (1 - f p)⁻¹) (∑' n, f n) := by
have H : (fun p : Primes ↦ (1 - f p)⁻¹) = fun p : Primes ↦ ∑' (e : ℕ), f (p ^ e) :=
funext <| fun p ↦ one_sub_inv_eq_geometric_of_summable_norm p.prop hsum
simpa only [map_pow, H]
using eulerProduct_hasProd f.map_one (fun {m n} _ ↦ f.map_mul m n) hsum f.map_zero
/-- The *Euler Product* for completely multiplicative functions.
If `f : ℕ →*₀ F`, where `F` is a complete normed field and `‖f ·‖` is summable, then
`∏' p : Nat.Primes, (1 - f p)⁻¹ = ∑' n, f n`. -/
theorem eulerProduct_completely_multiplicative_tprod {f : ℕ →*₀ F} (hsum : Summable (‖f ·‖)) :
∏' p : Primes, (1 - f p)⁻¹ = ∑' n, f n :=
(eulerProduct_completely_multiplicative_hasProd hsum).tprod_eq
open Filter in
/-- The *Euler Product* for completely multiplicative functions.
If `f : ℕ →*₀ F`, where `F` is a complete normed field and `‖f ·‖` is summable, then
`∏' p : Nat.Primes, (1 - f p)⁻¹ = ∑' n, f n`.
This version is stated in the form of convergence of finite partial products. -/
theorem eulerProduct_completely_multiplicative {f : ℕ →*₀ F} (hsum : Summable (‖f ·‖)) :
Tendsto (fun n : ℕ ↦ ∏ p ∈ primesBelow n, (1 - f p)⁻¹) atTop (𝓝 (∑' n, f n)) := by
have hmul {m n} (_ : Nat.Coprime m n) := f.map_mul m n
have := (eulerProduct_hasProd_mulIndicator f.map_one hmul hsum f.map_zero).tendsto_prod_nat
have H (n : ℕ) : ∏ p ∈ range n, {p | Nat.Prime p}.mulIndicator (fun p ↦ (1 - f p)⁻¹) p =
∏ p ∈ primesBelow n, (1 - f p)⁻¹ :=
prod_mulIndicator_eq_prod_filter
(range n) (fun _ ↦ fun p ↦ (1 - f p)⁻¹) (fun _ ↦ {p | Nat.Prime p}) id
have H' : {p | Nat.Prime p}.mulIndicator (fun p ↦ (1 - f p)⁻¹) =
{p | Nat.Prime p}.mulIndicator (fun p ↦ ∑' e : ℕ, f (p ^ e)) :=
Set.mulIndicator_congr fun p hp ↦ one_sub_inv_eq_geometric_of_summable_norm hp hsum
simpa only [← H, H'] using this
end EulerProduct
end CompletelyMultiplicative |
.lake/packages/mathlib/Mathlib/NumberTheory/EulerProduct/ExpLog.lean | import Mathlib.Analysis.Normed.Module.FiniteDimension
import Mathlib.Analysis.SpecialFunctions.Complex.LogDeriv
import Mathlib.LinearAlgebra.Complex.FiniteDimensional
import Mathlib.NumberTheory.EulerProduct.Basic
/-!
# Logarithms of Euler Products
We consider `f : ℕ →*₀ ℂ` and show that `exp (∑ p in Primes, log (1 - f p)⁻¹) = ∑ n : ℕ, f n`
under suitable conditions on `f`. This can be seen as a logarithmic version of the
Euler product for `f`.
-/
open Complex
open Topology in
/-- If `f : α → ℂ` is summable, then so is `n ↦ log (1 - f n)`. -/
lemma Summable.clog_one_sub {α : Type*} {f : α → ℂ} (hsum : Summable f) :
Summable fun n ↦ log (1 - f n) := by
have hg : DifferentiableAt ℂ (fun z ↦ log (1 - z)) 0 := by
have : 1 - 0 ∈ slitPlane := (sub_zero (1 : ℂ)).symm ▸ one_mem_slitPlane
fun_prop (disch := assumption)
have : (fun z ↦ log (1 - z)) =O[𝓝 0] id := by
simpa only [sub_zero, log_one] using hg.isBigO_sub
exact this.comp_summable hsum
namespace EulerProduct
/-- A variant of the Euler Product formula in terms of the exponential of a sum of logarithms. -/
theorem exp_tsum_primes_log_eq_tsum {f : ℕ →*₀ ℂ} (hsum : Summable (‖f ·‖)) :
exp (∑' p : Nat.Primes, -log (1 - f p)) = ∑' n : ℕ, f n := by
have hs {p : ℕ} (hp : 1 < p) : ‖f p‖ < 1 := hsum.of_norm.norm_lt_one (f := f.toMonoidHom) hp
have hp (p : Nat.Primes) : 1 - f p ≠ 0 :=
fun h ↦ (norm_one (α := ℂ) ▸ (sub_eq_zero.mp h) ▸ hs p.prop.one_lt).false
have H := hsum.of_norm.clog_one_sub.neg.subtype {p | p.Prime} |>.hasSum.cexp.tprod_eq
simp only [Set.coe_setOf, Set.mem_setOf_eq, Function.comp_apply, exp_neg, exp_log (hp _)] at H
exact H.symm.trans <| eulerProduct_completely_multiplicative_tprod hsum
end EulerProduct |
.lake/packages/mathlib/Mathlib/NumberTheory/NumberField/EquivReindex.lean | import Mathlib.NumberTheory.NumberField.CanonicalEmbedding.Basic
/-!
# Reindexed basis
This file introduces an equivalence between the set of embeddings of `K` into `ℂ` and the
index set of the chosen basis of the ring of integers of `K`.
## Tags
house, number field, algebraic number
-/
variable (K : Type*) [Field K] [NumberField K]
namespace NumberField
noncomputable section
open Module.Free Module canonicalEmbedding Matrix Finset
/-- An equivalence between the set of embeddings of `K` into `ℂ` and the
index set of the chosen basis of the ring of integers of `K`. -/
abbrev equivReindex : (K →+* ℂ) ≃ ChooseBasisIndex ℤ (𝓞 K) :=
Fintype.equivOfCardEq <| by
rw [Embeddings.card, ← finrank_eq_card_chooseBasisIndex, RingOfIntegers.rank]
/-- The basis matrix for the embeddings of `K` into `ℂ`. This matrix is formed by
taking the lattice basis vectors of `K` and reindexing them according to the
equivalence `equivReindex`, then transposing the resulting matrix. -/
abbrev basisMatrix : Matrix (K →+* ℂ) (K →+* ℂ) ℂ :=
(Matrix.of fun i ↦ latticeBasis K (equivReindex K i))
theorem det_of_basisMatrix_non_zero [DecidableEq (K →+* ℂ)] : (basisMatrix K).det ≠ 0 := by
let e : (K →+* ℂ) ≃ ChooseBasisIndex ℤ (𝓞 K) := equivReindex K
let N := Algebra.embeddingsMatrixReindex ℚ ℂ (fun i => integralBasis K (e i))
RingHom.equivRatAlgHom
rw [show (basisMatrix K) = N by
ext : 2; simp only [N, latticeBasis_apply, integralBasis_apply,
of_apply, apply_at]; rfl, ← pow_ne_zero_iff two_ne_zero]
convert (map_ne_zero_iff _ (algebraMap ℚ ℂ).injective).mpr
(Algebra.discr_not_zero_of_basis ℚ (integralBasis K))
rw [← Algebra.discr_reindex ℚ (integralBasis K) e.symm]
exact (Algebra.discr_eq_det_embeddingsMatrixReindex_pow_two ℚ ℂ
(fun _ => integralBasis K (e _)) RingHom.equivRatAlgHom).symm
instance [DecidableEq (K →+* ℂ)] : Invertible (basisMatrix K) := invertibleOfIsUnitDet _
(Ne.isUnit (det_of_basisMatrix_non_zero K))
variable {K}
theorem canonicalEmbedding_eq_basisMatrix_mulVec (α : K) :
canonicalEmbedding K α = (basisMatrix K).transpose.mulVec
(fun i ↦ (((integralBasis K).reindex (equivReindex K).symm).repr α i : ℂ)) := by
ext i
rw [← (latticeBasis K).sum_repr (canonicalEmbedding K α), ← Equiv.sum_comp (equivReindex K)]
simp only [canonicalEmbedding.integralBasis_repr_apply, mulVec, dotProduct,
transpose_apply, of_apply, Fintype.sum_apply, mul_comm, Basis.repr_reindex,
Finsupp.mapDomain_equiv_apply, Equiv.symm_symm, Pi.smul_apply, smul_eq_mul]
theorem inverse_basisMatrix_mulVec_eq_repr [DecidableEq (K →+* ℂ)] (α : 𝓞 K) :
∀ i, ((basisMatrix K).transpose)⁻¹.mulVec (fun j =>
canonicalEmbedding K (algebraMap (𝓞 K) K α) j) i =
((integralBasis K).reindex (equivReindex K).symm).repr α i := fun i => by
rw [inv_mulVec_eq_vec (canonicalEmbedding_eq_basisMatrix_mulVec ((algebraMap (𝓞 K) K) α))]
end
end NumberField |
.lake/packages/mathlib/Mathlib/NumberTheory/NumberField/DedekindZeta.lean | import Mathlib.Algebra.BigOperators.Ring.Nat
import Mathlib.NumberTheory.LSeries.SumCoeff
import Mathlib.NumberTheory.NumberField.Ideal.Asymptotics
/-!
# The Dedekind zeta function of a number field
In this file, we define and prove results about the Dedekind zeta function of a number field.
## Main definitions and results
* `NumberField.dedekindZeta`: the Dedekind zeta function.
* `NumberField.dedekindZeta_residue`: the value of the residue at `s = 1` of the Dedekind
zeta function.
* `NumberField.tendsto_sub_one_mul_dedekindZeta_nhdsGT`: **Dirichlet class number formula**
computation of the residue of the Dedekind zeta function at `s = 1`, see Chap. 7 of
[D. Marcus, *Number Fields*][marcus1977number]
## TODO
Generalize the construction of the Dedekind zeta function.
-/
variable (K : Type*) [Field K] [NumberField K]
noncomputable section
open Filter Ideal NumberField.InfinitePlace NumberField.Units Topology nonZeroDivisors
namespace NumberField
open scoped Real
/--
The Dedekind zeta function of a number field. It is defined as the `L`-series with coefficients
the number of integral ideals of norm `n`.
-/
def dedekindZeta (s : ℂ) :=
LSeries (fun n ↦ Nat.card {I : Ideal (𝓞 K) // absNorm I = n}) s
/--
The value of the residue at `s = 1` of the Dedekind zeta function, see
`NumberField.tendsto_sub_one_mul_dedekindZeta_nhdsGT`.
-/
def dedekindZeta_residue : ℝ :=
(2 ^ nrRealPlaces K * (2 * π) ^ nrComplexPlaces K * regulator K * classNumber K) /
(torsionOrder K * Real.sqrt |discr K|)
theorem dedekindZeta_residue_def :
dedekindZeta_residue K =
(2 ^ nrRealPlaces K * (2 * π) ^ nrComplexPlaces K * regulator K * classNumber K) /
(torsionOrder K * Real.sqrt |discr K|) := rfl
theorem dedekindZeta_residue_pos : 0 < dedekindZeta_residue K := by
refine div_pos ?_ ?_
· exact mul_pos (mul_pos (by positivity) (regulator_pos K)) (Nat.cast_pos.mpr (classNumber_pos K))
· exact mul_pos (Nat.cast_pos.mpr (torsionOrder_pos K)) <|
Real.sqrt_pos_of_pos <| abs_pos.mpr (Int.cast_ne_zero.mpr (discr_ne_zero K))
theorem dedekindZeta_residue_ne_zero : dedekindZeta_residue K ≠ 0 :=
(dedekindZeta_residue_pos K).ne'
/--
**Dirichlet class number formula**
-/
theorem tendsto_sub_one_mul_dedekindZeta_nhdsGT :
Tendsto (fun s : ℝ ↦ (s - 1) * dedekindZeta K s) (𝓝[>] 1) (𝓝 (dedekindZeta_residue K)) := by
refine LSeries_tendsto_sub_mul_nhds_one_of_tendsto_sum_div_and_nonneg _ ?_
(fun _ ↦ Nat.cast_nonneg _)
refine ((Ideal.tendsto_norm_le_div_atTop₀ K).comp tendsto_natCast_atTop_atTop).congr fun n ↦ ?_
simp only [Function.comp_apply, Nat.cast_le, ← Nat.cast_sum]
congr
rw [← add_left_inj 1, ← card_norm_le_eq_card_norm_le_add_one,
show Finset.Icc 1 n = Finset.Ioc 0 n from Finset.Icc_succ_left_eq_Ioc _ _,
show 1 = Nat.card {I : Ideal (𝓞 K) // absNorm I = 0} by simp [Ideal.absNorm_eq_zero_iff],
Finset.sum_Ioc_add_eq_sum_Icc (n.zero_le),
← Finset.card_preimage_eq_sum_card_image_eq (fun k _ ↦ finite_setOf_absNorm_eq k)]
simp [Set.coe_eq_subtype]
end NumberField |
.lake/packages/mathlib/Mathlib/NumberTheory/NumberField/CMField.lean | import Mathlib.NumberTheory.NumberField.InfinitePlace.TotallyRealComplex
import Mathlib.NumberTheory.NumberField.Units.Regulator
import Mathlib.RingTheory.RootsOfUnity.Complex
/-!
# CM-extension of number fields
A CM-extension `K/F` of number fields is an extension where `K` is totally complex, `F` is
totally real and `K` is a quadratic extension of `F`. In this situation, the totally real
subfield `F` is (isomorphic to) the maximal real subfield `K⁺` of `K`.
## Main definitions and results
* `NumberField.IsCMField`: A predicate that says that if a number field is CM, then it is a totally
complex quadratic extension of its totally real subfield
* `NumberField.CMExtension.equivMaximalRealSubfield`: Any field `F` such that `K/F` is a
CM-extension is isomorphic to the maximal real subfield `K⁺` of `K`.
* `NumberField.CMExtension.complexConj_eq_self_iff`: all the elements of `K` fixed by the
complex conjugation come from the maximal real subfield `F`.
* `NumberField.CMExtension.indexRealUnits_eq_one_or_two`: the index of the subgroup of `(𝓞 K)ˣ`
generated by the real units and the roots of unity is equal to `1` or `2`
(see `NumberField.IsCMField.indexRealUnits_eq_two_iff` for the computation of this index).
* `NumberField.IsCMField.regulator_div_regulator_eq_two_pow_mul_indexRealUnits_inv`: ratio of
regulators of `K` and `K⁺`.
* `NumberField.IsCM.ofIsCMExtension`: Assume that there exists `F` such that `K/F` is a
CM-extension. Then `K` is CM.
* `NumberField.IsCMField.of_isMulCommutative`: A totally complex abelian extension of `ℚ` is CM.
## Implementation note
Most results are proved for the case of a CM field, that is `K` is totally complex quadratic
extension of its totally real. These results live in the `NumberField.IsCMField` namespace. Some
results deal with the general case `K/F`, where `K` is totally complex, `F` is totally real and
`K` is a quadratic extension of `F`, and live in the `NumberField.CMExtension` namespace. Note that
results for the general case can be deduced for the CM case by using the isomorphism
`equivMaximalRealSubfield` between `F` and `K⁺` mentioned above.
-/
open NumberField ComplexEmbedding InfinitePlace Algebra
open scoped ComplexConjugate
namespace NumberField
section maximalRealSubfield
/--
A number field `K` is `CM` if `K` is a totally complex quadratic extension of its maximal
real subfield `K⁺`.
-/
class IsCMField (K : Type*) [Field K] [NumberField K] : Prop where
[to_isTotallyComplex : IsTotallyComplex K]
[is_quadratic : IsQuadraticExtension (maximalRealSubfield K) K]
namespace IsCMField
open ComplexEmbedding
variable (K : Type*) [Field K] [NumberField K] [IsCMField K]
local notation3 "K⁺" => maximalRealSubfield K
instance isQuadraticExtension : IsQuadraticExtension K⁺ K :=
IsCMField.is_quadratic
instance isTotallyComplex : IsTotallyComplex K :=
IsCMField.to_isTotallyComplex
theorem card_infinitePlace_eq_card_infinitePlace :
Fintype.card (InfinitePlace K⁺) = Fintype.card (InfinitePlace K) := by
rw [card_eq_nrRealPlaces_add_nrComplexPlaces, card_eq_nrRealPlaces_add_nrComplexPlaces,
IsTotallyComplex.nrRealPlaces_eq_zero K, IsTotallyReal.nrComplexPlaces_eq_zero, zero_add,
add_zero, ← IsTotallyReal.finrank, ← Nat.mul_left_cancel_iff zero_lt_two,
← IsTotallyComplex.finrank, ← Module.finrank_mul_finrank ℚ K⁺ K, mul_comm,
IsQuadraticExtension.finrank_eq_two _ K]
/--
The equiv between the infinite places of `K` and the infinite places of `K⁺` induced by the
restriction to `K⁺`, see `equivInfinitePlace_apply`.
-/
noncomputable def equivInfinitePlace : InfinitePlace K ≃ InfinitePlace K⁺ :=
Equiv.ofBijective (fun w ↦ w.comap (algebraMap K⁺ K)) <|
(Fintype.bijective_iff_surjective_and_card _).mpr
⟨comap_surjective, (card_infinitePlace_eq_card_infinitePlace K).symm⟩
@[simp]
theorem equivInfinitePlace_apply (w : InfinitePlace K) :
equivInfinitePlace K w = w.comap (algebraMap K⁺ K) := rfl
@[simp]
theorem equivInfinitePlace_symm_apply (w : InfinitePlace K⁺) (x : K⁺) :
(equivInfinitePlace K).symm w (algebraMap K⁺ K x) = w x := by
rw [← comap_apply, ← equivInfinitePlace_apply, Equiv.apply_symm_apply]
theorem units_rank_eq_units_rank :
Units.rank K⁺ = Units.rank K := by
rw [Units.rank, Units.rank, card_infinitePlace_eq_card_infinitePlace K]
theorem exists_isConj (φ : K →+* ℂ) :
∃ σ : K ≃ₐ[K⁺] K, IsConj φ σ :=
exists_isConj_of_isRamified <|
isRamified_iff.mpr ⟨IsTotallyComplex.isComplex _, IsTotallyReal.isReal _⟩
/--
All the conjugations of a CM-field over its maximal real subfield are the same.
-/
theorem isConj_eq_isConj {φ ψ : K →+* ℂ} {σ τ : K ≃ₐ[K⁺] K}
(hφ : IsConj φ σ) (hψ : IsConj ψ τ) : σ = τ := by
have : Nat.card (K ≃ₐ[K⁺] K) = 2 :=
(IsQuadraticExtension.finrank_eq_two K⁺ K) ▸ IsGalois.card_aut_eq_finrank K⁺ K
rw [Nat.card_eq_two_iff' 1] at this
exact ExistsUnique.unique this
((isConj_ne_one_iff hφ).mpr <| IsTotallyComplex.complexEmbedding_not_isReal φ)
((isConj_ne_one_iff hψ).mpr <| IsTotallyComplex.complexEmbedding_not_isReal ψ)
/--
The complex conjugation of the CM-field `K`.
-/
noncomputable def complexConj : K ≃ₐ[K⁺] K :=
(exists_isConj K (Classical.choice (inferInstance : Nonempty _))).choose
/--
The complex conjugation is the conjugation of any complex embedding of a CM-field.
-/
theorem isConj_complexConj (φ : K →+* ℂ) : IsConj φ (complexConj K) := by
obtain ⟨σ, hσ⟩ := exists_isConj _ φ
have := (exists_isConj K (Classical.choice (inferInstance : Nonempty (K →+* ℂ)))).choose_spec
rwa [isConj_eq_isConj K hσ this] at hσ
@[simp]
theorem complexEmbedding_complexConj (φ : K →+* ℂ) (x : K) :
φ (complexConj K x) = conj (φ x) := by
rw [IsConj.eq (isConj_complexConj K φ), RCLike.star_def]
@[simp]
theorem infinitePlace_complexConj (w : InfinitePlace K) (x : K) :
w (complexConj K x) = w x := by
rw [← norm_embedding_eq, complexEmbedding_complexConj, Complex.norm_conj, norm_embedding_eq]
@[simp]
theorem complexConj_apply_apply (x : K) :
complexConj K (complexConj K x) = x := by
let φ : K →+* ℂ := Classical.choice (inferInstance : Nonempty _)
exact isConj_apply_apply (isConj_complexConj K φ) x
theorem complexConj_ne_one :
complexConj K ≠ (1 : K ≃ₐ[K⁺] K) :=
(isConj_ne_one_iff
(exists_isConj K (Classical.choice (inferInstance : Nonempty _))).choose_spec).mpr <|
IsTotallyComplex.complexEmbedding_not_isReal _
@[simp]
theorem complexConj_apply_eq_self (x : K⁺) : complexConj K x = x := AlgEquiv.commutes _ x
/--
The complex conjugation is an automorphism of degree `2`.
-/
theorem orderOf_complexConj :
orderOf (complexConj K) = 2 :=
orderOf_eq_prime_iff.mpr ⟨by ext; simp, complexConj_ne_one K⟩
/--
The complex conjugation generates the Galois group of `K/K⁺`.
-/
theorem zpowers_complexConj_eq_top :
Subgroup.zpowers (complexConj K) = ⊤ := by
refine Subgroup.eq_top_of_card_eq _ ?_
rw [Nat.card_zpowers, orderOf_complexConj, IsGalois.card_aut_eq_finrank,
IsQuadraticExtension.finrank_eq_two]
/--
An element of `K` is fixed by the complex conjugation iff it lies in `K⁺`.
-/
@[simp]
theorem complexConj_eq_self_iff (x : K) :
complexConj K x = x ↔ x ∈ K⁺ := by
convert (IntermediateField.mem_fixedField_iff (⊤ : Subgroup (K ≃ₐ[K⁺] K)) x).symm using 1
· rw [← zpowers_complexConj_eq_top, Subgroup.forall_mem_zpowers]
exact (MulAction.mem_fixedBy_zpowers_iff_mem_fixedBy (g := (complexConj K))).symm
· rw [IsGalois.fixedField_top, IntermediateField.mem_bot]
aesop
protected theorem RingOfIntegers.complexConj_eq_self_iff (x : 𝓞 K) :
complexConj K x = x ↔ ∃ y : 𝓞 K⁺, algebraMap (𝓞 K⁺) K y = x := by
rw [complexConj_eq_self_iff]
refine ⟨fun h ↦ ?_, fun ⟨y, hy⟩ ↦ ?_⟩
· have : IsIntegral ℤ (⟨x, h⟩ : K⁺) :=
(isIntegral_algebraMap_iff (FaithfulSMul.algebraMap_injective K⁺ K)).mp x.isIntegral_coe
refine ⟨⟨⟨x, h⟩, this⟩, ?_⟩
rw [IsScalarTower.algebraMap_apply (𝓞 K⁺) K⁺, RingOfIntegers.map_mk]
rfl
· rw [← hy, IsScalarTower.algebraMap_apply (𝓞 K⁺) K⁺]
exact SetLike.coe_mem _
protected theorem Units.complexConj_eq_self_iff (u : (𝓞 K)ˣ) :
complexConj K u = u ↔ ∃ v : (𝓞 K⁺)ˣ, algebraMap (𝓞 K⁺) K v = u := by
rw [RingOfIntegers.complexConj_eq_self_iff, Units.coe_coe]
refine ⟨fun ⟨y, hy⟩ ↦ ?_, fun ⟨v, hv⟩ ↦ ⟨v, by rw [hv]⟩⟩
have : IsUnit y := by
apply IsUnit.of_map (algebraMap (𝓞 K⁺) (𝓞 K))
rw [show algebraMap (𝓞 K⁺) (𝓞 K) y = u by exact RingOfIntegers.ext hy]
exact u.isUnit
exact ⟨this.unit, by simp [hy]⟩
noncomputable instance starRing : StarRing K where
star := complexConj K
star_involutive _ := complexConj_apply_apply _ _
star_mul _ _ := by rw [map_mul, mul_comm]
star_add _ _ := by rw [map_add]
/--
A variant of the complex conjugation defined as an `AlgEquiv` on the ring of integers.
-/
noncomputable abbrev ringOfIntegersComplexConj : (𝓞 K) ≃ₐ[𝓞 K⁺] (𝓞 K) :=
RingOfIntegers.mapAlgEquiv (complexConj K)
@[simp]
theorem coe_ringOfIntegersComplexConj (x : 𝓞 K) :
(ringOfIntegersComplexConj K x : K) = complexConj K x := rfl
theorem ringOfIntegersComplexConj_eq_self_iff (x : 𝓞 K) :
ringOfIntegersComplexConj K x = x ↔ x ∈ Set.range (algebraMap (𝓞 K⁺) (𝓞 K)) := by
refine ⟨fun h ↦ ?_, ?_⟩
· rw [RingOfIntegers.ext_iff, coe_ringOfIntegersComplexConj,
RingOfIntegers.complexConj_eq_self_iff] at h
obtain ⟨y, hy⟩ := h
exact ⟨y, RingOfIntegers.ext_iff.mpr hy⟩
· rintro ⟨y, rfl⟩
simp
section units
open Units
/--
The complex conjugation as an isomorphism of the units of `K`. -/
noncomputable abbrev unitsComplexConj : (𝓞 K)ˣ ≃* (𝓞 K)ˣ :=
Units.mapEquiv <| RingOfIntegers.mapRingEquiv (complexConj K).toRingEquiv
/--
The subgroup of `(𝓞 K)ˣ` generated by the units of `K⁺`. These units are exactly the units fixed
by the complex conjugation, see `IsCMField.unitsComplexConj_eq_self_iff`.
-/
def realUnits : Subgroup (𝓞 K)ˣ := (Units.map (algebraMap (𝓞 K⁺) (𝓞 K)).toMonoidHom).range
omit [IsCMField K] in
theorem mem_realUnits_iff (u : (𝓞 K)ˣ) :
u ∈ realUnits K ↔ ∃ v : (𝓞 K⁺)ˣ, algebraMap (𝓞 K⁺) (𝓞 K) v = u := by
simp [realUnits, MonoidHom.mem_range, RingHom.toMonoidHom_eq_coe, Units.ext_iff]
theorem unitsComplexConj_eq_self_iff (u : (𝓞 K)ˣ) :
unitsComplexConj K u = u ↔ u ∈ realUnits K := by
simp_rw [Units.ext_iff, mem_realUnits_iff, RingOfIntegers.ext_iff, Units.coe_mapEquiv,
AlgEquiv.toRingEquiv_eq_coe, RingEquiv.coe_toMulEquiv, RingOfIntegers.mapRingEquiv_apply,
AlgEquiv.coe_ringEquiv, Units.complexConj_eq_self_iff,
IsScalarTower.algebraMap_apply (𝓞 K⁺) (𝓞 K) K]
/--
The image of a root of unity by the complex conjugation is its inverse.
This is the version of `Complex.conj_rootsOfUnity` for CM-fields.
-/
@[simp]
theorem complexConj_torsion (ζ : torsion K) :
complexConj K (ζ.val : K) = (ζ.val : K)⁻¹ := by
let φ : K →+* ℂ := Classical.choice (inferInstance : Nonempty _)
apply φ.injective
rw [complexEmbedding_complexConj, ← Units.complexEmbedding_apply,
Complex.conj_rootsOfUnity (n := torsionOrder K), Units.val_inv_eq_inv_val,
Units.complexEmbedding_apply, map_inv₀]
exact map_complexEmbedding_torsion K φ ▸ Subgroup.apply_coe_mem_map _ _ _
theorem unitsComplexConj_torsion (ζ : torsion K) :
unitsComplexConj K ζ = ζ⁻¹ := by
apply coe_injective
simp
/--
The map `(𝓞 K)ˣ →* torsion K` defined by `u ↦ u * (conj u)⁻¹`.
-/
noncomputable def unitsMulComplexConjInv : (𝓞 K)ˣ →* torsion K where
toFun := fun u ↦ ⟨u * (unitsComplexConj K u)⁻¹, (mem_torsion K).mpr fun _ ↦ by simp⟩
map_one' := by simp
map_mul' := by
intro _ _
rw [MulMemClass.mk_mul_mk, Subtype.mk_eq_mk]
apply coe_injective
simp only [map_mul, mul_inv_rev, Units.val_mul, map_units_inv]
ring
theorem unitsMulComplexConjInv_apply (u : (𝓞 K)ˣ) :
unitsMulComplexConjInv K u = u * (unitsComplexConj K u)⁻¹ := rfl
@[simp]
theorem unitsMulComplexConjInv_apply_torsion (ζ : torsion K) :
unitsMulComplexConjInv K ζ = ζ ^ 2 :=
Subtype.eq <| by simp [unitsMulComplexConjInv_apply, unitsComplexConj_torsion, pow_two]
/--
The action of `unitsMulComplexConjInv` of the torsion is the same as the 2-power map.
-/
theorem map_unitsMulComplexConjInv_torsion :
Subgroup.map (unitsMulComplexConjInv K) (torsion K) = (powMonoidHom 2).range := by
rw [← MonoidHom.restrict_range]
exact congr_arg (MonoidHom.range ·) (MonoidHom.ext fun ζ ↦ by simp)
/--
The kernel of `unitsMulComplexConjInv` is the subgroup of real units.
-/
theorem unitsMulComplexConjInv_ker :
(unitsMulComplexConjInv K).ker = realUnits K := by
ext
rw [MonoidHom.mem_ker, Subtype.ext_iff, unitsMulComplexConjInv_apply, OneMemClass.coe_one,
mul_inv_eq_one, eq_comm, unitsComplexConj_eq_self_iff]
/--
The index of the image of `unitsMulComplexConjInv` divides `2`.
-/
theorem index_unitsMulComplexConjInv_range_dvd :
(unitsMulComplexConjInv K).range.index ∣ 2 := by
suffices (powMonoidHom 2 : _ →* torsion K).range.index = 2 by
refine this ▸ Subgroup.index_dvd_of_le ?_
rintro _ ⟨ζ, _, rfl⟩
exact ⟨ζ, Subtype.ext_iff.mpr (by simp [pow_two])⟩
rw [IsCyclic.index_powMonoidHom_range, Nat.gcd_eq_right_iff_dvd, Nat.card_eq_fintype_card]
exact Even.two_dvd <| even_torsionOrder K
/--
The index of the subgroup of `(𝓞 K)ˣ` generated by the real units and the roots of unity. This
index is equal to `1` or `2`, see `indexRealUnits_eq_one_or_two` and `indexRealUnits_eq_two_iff`.
-/
noncomputable abbrev indexRealUnits : ℕ := (realUnits K ⊔ torsion K).index
theorem indexRealUnits_mul_eq :
indexRealUnits K * (unitsMulComplexConjInv K).range.index = 2 := by
rw [indexRealUnits, sup_comm]
convert (Subgroup.index_map (torsion K) (unitsMulComplexConjInv K)).symm
· rw [unitsMulComplexConjInv_ker]
· rw [map_unitsMulComplexConjInv_torsion, IsCyclic.index_powMonoidHom_range, Nat.gcd_eq_right]
rw [Nat.card_eq_fintype_card]
exact even_iff_two_dvd.mp (even_torsionOrder K)
/--
The index of the subgroup of `(𝓞 K)ˣ` generated by the real units and the roots of unity is
equal to `1` or `2` (see `NumberField.IsCMField.indexRealUnits_eq_two_iff` for the computation
of this index).
-/
theorem indexRealUnits_eq_one_or_two :
indexRealUnits K = 1 ∨ indexRealUnits K = 2 := by
have h₁ := indexRealUnits_mul_eq K
obtain h₂ | h₂ := (Nat.dvd_prime Nat.prime_two).mp <| index_unitsMulComplexConjInv_range_dvd K
· exact Or.inr <| by rwa [h₂, mul_one] at h₁
· exact Or.inl <| by rwa [h₂, Nat.mul_eq_right two_ne_zero] at h₁
/--
The index of the subgroup of `(𝓞 K)ˣ` generated by the real units and the roots of unity is equal
to `2` iff there exists a unit whose image by `unitsMulComplexConjInv` generates the torsion
subgroup of `K`.
-/
theorem indexRealUnits_eq_two_iff :
indexRealUnits K = 2 ↔
∃ u : (𝓞 K)ˣ, Subgroup.zpowers (unitsMulComplexConjInv K u) = ⊤ := by
suffices (∃ u : (𝓞 K)ˣ, Subgroup.zpowers (unitsMulComplexConjInv K u) = ⊤) ↔
(unitsMulComplexConjInv K).range.index = 1 by
rw [this]
have h_eq := indexRealUnits_mul_eq K
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rwa [h, Nat.mul_eq_left two_ne_zero] at h_eq
· rwa [h, mul_one] at h_eq
refine ⟨fun ⟨u, hu⟩ ↦ Subgroup.index_eq_one.mpr (top_le_iff.mp ?_), fun h ↦ ?_⟩
· refine le_of_eq_of_le ?_ ((Subgroup.zpowers u).map_le_range (unitsMulComplexConjInv K))
rw [MonoidHom.map_zpowers, ← hu]
· obtain ⟨ζ, hζ⟩ := exists_zpow_surjective (torsion K)
rw [Subgroup.index_eq_one, MonoidHom.range_eq_top] at h
obtain ⟨u, rfl⟩ := h ζ
exact ⟨u, (Subgroup.eq_top_iff' _).mpr hζ⟩
/--
The fundamental system of units of `K⁺` as a family of `(𝓞 K)ˣ`.
-/
noncomputable def realFundSystem (i : Fin (rank K)) : (𝓞 K)ˣ :=
(Units.map (algebraMap (𝓞 K⁺) (𝓞 K)).toMonoidHom)
(fundSystem K⁺ (finCongr (units_rank_eq_units_rank K).symm i))
theorem closure_realFundSystem_sup_torsion :
Subgroup.closure (Set.range (realFundSystem K)) ⊔ torsion K = realUnits K ⊔ torsion K := by
have : Subgroup.map (Units.map (algebraMap (𝓞 K⁺) (𝓞 K))) (torsion K⁺) ≤ torsion K := by
rintro _ ⟨x, hx, rfl⟩
exact MonoidHom.isOfFinOrder _ hx
rw [realUnits, MonoidHom.range_eq_map, ← closure_fundSystem_sup_torsion_eq_top, Subgroup.map_sup,
sup_assoc, RingHom.toMonoidHom_eq_coe, sup_eq_right.mpr this, MonoidHom.map_closure]
congr; ext
simp [realFundSystem, Equiv.exists_congr_left (finCongr (units_rank_eq_units_rank K).symm)]
open dirichletUnitTheorem in
theorem regOfFamily_realFunSystem :
regOfFamily (realFundSystem K) = 2 ^ rank K * regulator K⁺ := by
classical
let W₀ := (equivInfinitePlace K).symm w₀
let f : {w : InfinitePlace K // w ≠ W₀} ≃ {w : InfinitePlace K⁺ // w ≠ w₀} :=
(equivInfinitePlace K).subtypeEquiv fun w ↦ by rw [not_iff_not, Equiv.eq_symm_apply]
let g := ((finCongr (units_rank_eq_units_rank K).symm).trans (equivFinRank K⁺)).trans f.symm
rw [show (2 : ℝ) ^ rank K = |∏ w : {w : InfinitePlace K⁺ // w ≠ w₀}, 2| by
rw [Finset.prod_const, abs_pow, abs_of_pos zero_lt_two, ← units_rank_eq_units_rank K, rank]
simp]
rw [regulator_eq_regOfFamily_fundSystem, regOfFamily_eq_det _ W₀ g.symm, regOfFamily_eq_det',
← abs_mul, ← Matrix.det_mul_column, ← Matrix.det_reindex_self f, Matrix.reindex_apply]
congr; ext i w
rw [Matrix.submatrix_apply, Matrix.of_apply, Matrix.of_apply,
show f.symm w = (equivInfinitePlace K).symm w.1 by rfl,
show algebraMap (𝓞 K) K _ = algebraMap K⁺ K _ by rfl, equivInfinitePlace_symm_apply]
simp [f, g]
theorem regulator_div_regulator_eq_two_pow_mul_indexRealUnits_inv :
regulator K / regulator K⁺ = 2 ^ rank K * (indexRealUnits K : ℝ)⁻¹ := by
rw [indexRealUnits, ← closure_realFundSystem_sup_torsion, ← regOfFamily_div_regulator
(realFundSystem K), regOfFamily_realFunSystem, inv_div, ← mul_div_assoc, mul_div_mul_comm,
div_self (by positivity), one_mul]
end units
end IsCMField
end maximalRealSubfield
namespace CMExtension
variable (F K : Type*) [Field F] [NumberField F] [IsTotallyReal F] [Field K] [NumberField K]
[IsTotallyComplex K] [Algebra F K] [IsQuadraticExtension F K]
theorem eq_maximalRealSubfield (E : Subfield K) [IsTotallyReal E] [IsQuadraticExtension E K] :
E = maximalRealSubfield K := by
refine le_antisymm (IsTotallyReal.le_maximalRealSubfield E) ?_
by_contra! h
have h' : E ⊔ (maximalRealSubfield K) = ⊤ := by
let L : IntermediateField E K := (E ⊔ (maximalRealSubfield K)).toIntermediateField
(fun x ↦ (le_sup_left (a := E)) x.prop)
have := ((IntermediateField.isSimpleOrder_of_finrank_prime E K
(IsQuadraticExtension.finrank_eq_two E K ▸ Nat.prime_two)).eq_bot_or_eq_top L).resolve_left ?_
· simpa [L] using congr_arg IntermediateField.toSubfield this
· contrapose! h
rw [← SetLike.coe_set_eq, Subfield.coe_toIntermediateField] at h
rw [← sup_eq_left, ← SetLike.coe_set_eq, h, IntermediateField.coe_bot]
aesop
have : IsTotallyReal K := (h' ▸ isTotallyReal_sup).ofRingEquiv Subring.topEquiv
obtain w : InfinitePlace K := Classical.choice (inferInstance : Nonempty _)
exact (not_isReal_iff_isComplex.mpr (IsTotallyComplex.isComplex w)) (IsTotallyReal.isReal w)
/--
Any field `F` such that `K/F` is a CM-extension is isomorphic to the maximal real subfield of `K`.
-/
noncomputable def equivMaximalRealSubfield :
F ≃+* maximalRealSubfield K :=
(algebraMap F K).rangeRestrictFieldEquiv.trans (RingEquiv.subfieldCongr (by
have := IsTotallyReal.ofRingEquiv (algebraMap F K).rangeRestrictFieldEquiv
have : IsQuadraticExtension (algebraMap F K).fieldRange K :=
{ finrank_eq_two' :=
(IsQuadraticExtension.finrank_eq_two F K) ▸ Algebra.finrank_eq_of_equiv_equiv
(algebraMap F K).rangeRestrictFieldEquiv.symm (RingEquiv.refl K) (by ext; simp; rfl) }
exact eq_maximalRealSubfield K (algebraMap F K).fieldRange))
@[simp]
theorem equivMaximalRealSubfield_apply (x : F) :
equivMaximalRealSubfield F K x = algebraMap F K x := rfl
@[simp]
theorem algebraMap_equivMaximalRealSubfield_symm_apply (x : maximalRealSubfield K) :
algebraMap F K ((CMExtension.equivMaximalRealSubfield F K).symm x) =
algebraMap (maximalRealSubfield K) K x := by
simpa using (equivMaximalRealSubfield_apply F K ((equivMaximalRealSubfield F K).symm x)).symm
include F in
/--
If `K/F` is a CM-extension then `K` is a CM-field.
-/
theorem _root_.NumberField.IsCMField.ofCMExtension :
IsCMField K where
is_quadratic := ⟨(IsQuadraticExtension.finrank_eq_two F K) ▸ finrank_eq_of_equiv_equiv
(CMExtension.equivMaximalRealSubfield F K).symm (RingEquiv.refl K) (by ext; simp)⟩
open IntermediateField in
/--
A totally complex field that has a unique complex conjugation is CM.
-/
theorem _root_.NumberField.IsCMField.of_forall_isConj {σ : Gal(K/ℚ)}
(hσ : ∀ φ : K →+* ℂ, IsConj φ σ) : IsCMField K := by
have : IsTotallyReal (fixedField (Subgroup.zpowers σ)) := ⟨fun w ↦ by
obtain ⟨W, rfl⟩ := w.comap_surjective (K := K)
let τ := subgroupEquivAlgEquiv _ ⟨σ, Subgroup.mem_zpowers σ⟩
have hτ : IsConj W.embedding τ := hσ _
simpa [← isReal_mk_iff, ← InfinitePlace.comap_mk, mk_embedding] using hτ.isReal_comp⟩
have : IsQuadraticExtension (fixedField (Subgroup.zpowers σ)) K := ⟨by
let φ : K →+* ℂ := Classical.choice (inferInstance : Nonempty _)
have hσ' : σ ≠ 1 :=
(isConj_ne_one_iff (hσ φ)).mpr <| IsTotallyComplex.complexEmbedding_not_isReal φ
rw [finrank_fixedField_eq_card, Nat.card_zpowers, orderOf_isConj_two_of_ne_one (hσ φ) hσ']⟩
exact IsCMField.ofCMExtension (fixedField (Subgroup.zpowers σ)) K
/--
A totally complex abelian extension of `ℚ` is CM.
-/
instance of_isMulCommutative [IsGalois ℚ K] [IsMulCommutative Gal(K/ℚ)] :
IsCMField K := by
let φ : K →+* ℂ := Classical.choice (inferInstance : Nonempty _)
obtain ⟨σ, hσ₁⟩ : ∃ σ : Gal(K/ℚ), ComplexEmbedding.IsConj φ σ :=
exists_isConj_of_isRamified <|
isRamified_iff.mpr ⟨IsTotallyComplex.isComplex _, IsTotallyReal.isReal _⟩
have hσ₂ : ∀ (φ : K →+* ℂ), ComplexEmbedding.IsConj φ σ := by
intro ψ
obtain ⟨ν, rfl⟩ := exists_comp_symm_eq_of_comp_eq (k := ℚ) φ ψ (by ext; simp)
rw [show σ = ν.symm⁻¹ * σ * ν.symm by simp]
exact hσ₁.comp _
exact IsCMField.of_forall_isConj K hσ₂
end CMExtension
end NumberField |
.lake/packages/mathlib/Mathlib/NumberTheory/NumberField/ClassNumber.lean | import Mathlib.NumberTheory.ClassNumber.AdmissibleAbs
import Mathlib.NumberTheory.ClassNumber.Finite
import Mathlib.NumberTheory.NumberField.Discriminant.Basic
import Mathlib.RingTheory.Ideal.IsPrincipal
import Mathlib.NumberTheory.RamificationInertia.Galois
/-!
# Class numbers of number fields
This file defines the class number of a number field as the (finite) cardinality of
the class group of its ring of integers. It also proves some elementary results
on the class number.
## Main definitions
We denote by `M K` the Minkowski bound of a number field `K`, defined as
`(4 / π) ^ nrComplexPlaces K * ((finrank ℚ K)! / (finrank ℚ K) ^ (finrank ℚ K) * √|discr K|)`.
- `NumberField.classNumber`: the class number of a number field is the (finite)
cardinality of the class group of its ring of integers
- `isPrincipalIdealRing_of_isPrincipal_of_pow_le_of_mem_primesOver_of_mem_Icc`: let `K`
be a number field. To show that `𝓞 K` is a PID it is enough to show that, for all (natural) primes
`p ∈ Finset.Icc 1 ⌊(M K)⌋₊`, all ideals `P` above `p` such that
`p ^ (span ({p}).inertiaDeg P) ≤ ⌊(M K)⌋₊` are principal. This is the standard technique to prove
that `𝓞 K` is principal, see [marcus1977number], discussion after Theorem 37.
The way this theorem should be used is to first compute `⌊(M K)⌋₊` and then to use `fin_cases`
to deal with the finite number of primes `p` in the interval.
- `isPrincipalIdealRing_of_isPrincipal_of_lt_or_isPrincipal_of_mem_primesOver_of_mem_Icc`: let `K`
be a number field such that `K/ℚ` is Galois. To show that `𝓞 K` is a PID it is enough to show
that, for all (natural) primes `p ∈ Finset.Icc 1 ⌊(M K)⌋₊`, there is an ideal `P` above `p` such
that either `⌊(M K)⌋₊ < p ^ (span ({p}).inertiaDeg P)` or `P` is principal. This is the standard
technique to prove that `𝓞 K` is principal in the Galois case, see [marcus1977number], discussion
after Theorem 37.
The way this theorem should be used is to first compute `⌊(M K)⌋₊` and then to use `fin_cases`
to deal with the finite number of primes `p` in the interval.
-/
open scoped nonZeroDivisors Real
open Module NumberField InfinitePlace Ideal Nat
variable (K : Type*) [Field K] [NumberField K]
local notation "M " K:70 => (4 / π) ^ nrComplexPlaces K *
((finrank ℚ K)! / (finrank ℚ K) ^ (finrank ℚ K) * √|discr K|)
namespace NumberField
namespace RingOfIntegers
noncomputable instance instFintypeClassGroup : Fintype (ClassGroup (𝓞 K)) :=
ClassGroup.fintypeOfAdmissibleOfFinite ℚ K AbsoluteValue.absIsAdmissible
end RingOfIntegers
/-- The class number of a number field is the (finite) cardinality of the class group. -/
noncomputable def classNumber : ℕ :=
Fintype.card (ClassGroup (𝓞 K))
theorem classNumber_ne_zero : classNumber K ≠ 0 := Fintype.card_ne_zero
theorem classNumber_pos : 0 < classNumber K := Fintype.card_pos
variable {K}
/-- The class number of a number field is `1` iff the ring of integers is a PID. -/
theorem classNumber_eq_one_iff : classNumber K = 1 ↔ IsPrincipalIdealRing (𝓞 K) :=
card_classGroup_eq_one_iff
theorem exists_ideal_in_class_of_norm_le (C : ClassGroup (𝓞 K)) :
∃ I : (Ideal (𝓞 K))⁰, ClassGroup.mk0 I = C ∧
absNorm (I : Ideal (𝓞 K)) ≤ M K := by
obtain ⟨J, hJ⟩ := ClassGroup.mk0_surjective C⁻¹
obtain ⟨_, ⟨a, ha, rfl⟩, h_nz, h_nm⟩ :=
exists_ne_zero_mem_ideal_of_norm_le_mul_sqrt_discr K (FractionalIdeal.mk0 K J)
obtain ⟨I₀, hI⟩ := dvd_iff_le.mpr ((span_singleton_le_iff_mem J).mpr (by exact ha))
have : I₀ ≠ 0 := by
contrapose! h_nz
rw [h_nz, mul_zero, zero_eq_bot, span_singleton_eq_bot] at hI
rw [Algebra.linearMap_apply, hI, map_zero]
let I := (⟨I₀, mem_nonZeroDivisors_iff_ne_zero.mpr this⟩ : (Ideal (𝓞 K))⁰)
refine ⟨I, ?_, ?_⟩
· suffices ClassGroup.mk0 I = (ClassGroup.mk0 J)⁻¹ by rw [this, hJ, inv_inv]
exact ClassGroup.mk0_eq_mk0_inv_iff.mpr ⟨a, Subtype.coe_ne_coe.1 h_nz, by rw [mul_comm, hI]⟩
· rw [← FractionalIdeal.absNorm_span_singleton (𝓞 K), Algebra.linearMap_apply,
← FractionalIdeal.coeIdeal_span_singleton, FractionalIdeal.coeIdeal_absNorm, hI, map_mul,
cast_mul, Rat.cast_mul, absNorm_apply, Rat.cast_natCast, Rat.cast_natCast,
FractionalIdeal.coe_mk0, FractionalIdeal.coeIdeal_absNorm, Rat.cast_natCast, mul_div_assoc,
mul_assoc, mul_assoc] at h_nm
refine le_of_mul_le_mul_of_pos_left h_nm ?_
exact cast_pos.mpr <| pos_of_ne_zero <| absNorm_ne_zero_of_nonZeroDivisors J
end NumberField
namespace RingOfIntegers
variable {K}
open scoped NumberField
theorem isPrincipalIdealRing_of_isPrincipal_of_norm_le
(h : ∀ ⦃I : (Ideal (𝓞 K))⁰⦄, absNorm (I : Ideal (𝓞 K)) ≤ M K →
Submodule.IsPrincipal (I : Ideal (𝓞 K))) : IsPrincipalIdealRing (𝓞 K) := by
rw [← classNumber_eq_one_iff, classNumber, Fintype.card_eq_one_iff]
refine ⟨1, fun C ↦ ?_⟩
obtain ⟨I, rfl, hI⟩ := exists_ideal_in_class_of_norm_le C
simpa [← ClassGroup.mk0_eq_one_iff] using h hI
theorem isPrincipalIdealRing_of_isPrincipal_of_norm_le_of_isPrime
(h : ∀ ⦃I : (Ideal (𝓞 K))⁰⦄, (I : Ideal (𝓞 K)).IsPrime →
absNorm (I : Ideal (𝓞 K)) ≤ M K → Submodule.IsPrincipal (I : Ideal (𝓞 K))) :
IsPrincipalIdealRing (𝓞 K) := by
refine isPrincipalIdealRing_of_isPrincipal_of_norm_le (fun I hI ↦ ?_)
rw [← mem_isPrincipalSubmonoid_iff,
← prod_normalizedFactors_eq_self (nonZeroDivisors.coe_ne_zero I)]
refine Submonoid.multiset_prod_mem _ _ (fun J hJ ↦ mem_isPrincipalSubmonoid_iff.mp ?_)
by_cases hJ0 : J = 0
· simpa [hJ0] using bot_isPrincipal
rw [← Subtype.coe_mk J (mem_nonZeroDivisors_of_ne_zero hJ0)]
refine h (((mem_normalizedFactors_iff (nonZeroDivisors.coe_ne_zero I)).mp hJ).1) ?_
exact (cast_le.mpr <| le_of_dvd (absNorm_pos_of_nonZeroDivisors I) <|
absNorm_dvd_absNorm_of_le <| le_of_dvd <|
UniqueFactorizationMonoid.dvd_of_mem_normalizedFactors hJ).trans hI
set_option linter.style.longLine false in
/-- Let `K` be a number field and let `M K` be the Minkowski bound of `K`.
To show that `𝓞 K` is a PID it is enough to show that, for all (natural) primes
`p ∈ Finset.Icc 1 ⌊(M K)⌋₊`, all ideals `P` above `p` such that
`p ^ (span ({p}).inertiaDeg P) ≤ ⌊(M K)⌋₊` are principal. This is the standard technique to prove
that `𝓞 K` is principal, see [marcus1977number], discussion after Theorem 37.
If `K/ℚ` is Galois, one can use the more convenient
`RingOfIntegers.isPrincipalIdealRing_of_isPrincipal_of_lt_or_isPrincipal_of_mem_primesOver_of_mem_Icc`
below.
The way this theorem should be used is to first compute `⌊(M K)⌋₊` and then to use `fin_cases`
to deal with the finite number of primes `p` in the interval. -/
theorem isPrincipalIdealRing_of_isPrincipal_of_pow_le_of_mem_primesOver_of_mem_Icc
(h : ∀ p ∈ Finset.Icc 1 ⌊(M K)⌋₊, p.Prime → ∀ (P : Ideal (𝓞 K)),
P ∈ primesOver (span {(p : ℤ)}) (𝓞 K) → p ^ ((span ({↑p} : Set ℤ)).inertiaDeg P) ≤ ⌊(M K)⌋₊ →
Submodule.IsPrincipal P) : IsPrincipalIdealRing (𝓞 K) := by
refine isPrincipalIdealRing_of_isPrincipal_of_norm_le_of_isPrime <|
fun ⟨P, HP⟩ hP hPN ↦ ?_
obtain ⟨p, hp⟩ := IsPrincipalIdealRing.principal <| under ℤ P
have hp0 : p ≠ 0 := fun h ↦ nonZeroDivisors.coe_ne_zero ⟨P, HP⟩ <|
eq_bot_of_comap_eq_bot (R := ℤ) <| by simpa only [hp, submodule_span_eq, span_singleton_eq_bot]
have hpprime := (span_singleton_prime hp0).mp
simp only [← submodule_span_eq, ← hp] at hpprime
have hlies : P.LiesOver (span {p}) := by
rcases abs_choice p with h | h <;>
simpa [h, span_singleton_neg p, ← submodule_span_eq, ← hp] using over_under P
have hspan : span {↑p.natAbs} = span {p} := by
rcases abs_choice p with h | h <;> simp [h]
have hple : p.natAbs ^ (span {(p.natAbs : ℤ)}).inertiaDeg P ≤ ⌊(M K)⌋₊ := by
refine le_floor ?_
simpa only [hspan, ← cast_pow, ← absNorm_eq_pow_inertiaDeg P (hpprime (hP.under _))] using hPN
have hpabsprime := Int.prime_iff_natAbs_prime.mp (hpprime (hP.under _))
refine h _ ?_ hpabsprime _ ⟨hP, ?_⟩ hple
· suffices 0 < (span {(p.natAbs : ℤ)}).inertiaDeg P by
exact Finset.mem_Icc.mpr ⟨hpabsprime.one_le, le_trans (le_pow this) hple⟩
have := (isPrime_of_prime (prime_span_singleton_iff.mpr <|
hpprime (hP.under _))).isMaximal <| by simp [((hpprime (hP.under _))).ne_zero]
exact hspan ▸ inertiaDeg_pos ..
· exact hspan ▸ hlies
/-- Let `K` be a number field such that `K/ℚ` is Galois and let `M K` be the Minkowski bound of `K`.
To show that `𝓞 K` is a PID it is enough to show that, for all (natural) primes
`p ∈ Finset.Icc 1 ⌊(M K)⌋₊`, there is an ideal `P` above `p` such that
either `⌊(M K)⌋₊ < p ^ (span ({p}).inertiaDeg P)` or `P` is principal. This is the standard
technique to prove that `𝓞 K` is principal in the Galois case, see [marcus1977number], discussion
after Theorem 37.
The way this theorem should be used is to first compute `⌊(M K)⌋₊` and then to use `fin_cases`
to deal with the finite number of primes `p` in the interval. -/
theorem isPrincipalIdealRing_of_isPrincipal_of_lt_or_isPrincipal_of_mem_primesOver_of_mem_Icc
[IsGalois ℚ K] (h : ∀ p ∈ Finset.Icc 1 ⌊(M K)⌋₊, p.Prime →
∃ P ∈ primesOver (span {(p : ℤ)}) (𝓞 K),
⌊(M K)⌋₊ < p ^ ((span ({↑p} : Set ℤ)).inertiaDeg P) ∨
Submodule.IsPrincipal P) :
IsPrincipalIdealRing (𝓞 K) := by
refine isPrincipalIdealRing_of_isPrincipal_of_pow_le_of_mem_primesOver_of_mem_Icc
(fun p hpmem hp P ⟨hP1, hP2⟩ hple ↦ ?_)
obtain ⟨Q, ⟨hQ1, hQ2⟩, H⟩ := h p hpmem hp
have := (isPrime_of_prime (prime_span_singleton_iff.mpr (prime_iff_prime_int.mp hp))).isMaximal
(by simp [hp.ne_zero])
by_cases h : ⌊(M K)⌋₊ < p ^ ((span ({↑p} : Set ℤ)).inertiaDeg P)
· linarith
rw [inertiaDeg_eq_of_isGaloisGroup _ Q P (K ≃ₐ[ℚ] K)] at H
obtain ⟨σ, rfl⟩ := exists_smul_eq_of_isGaloisGroup (span ({↑p} : Set ℤ)) Q P (K ≃ₐ[ℚ] K)
exact (H.resolve_left h).map_ringHom (MulSemiringAction.toRingHom (K ≃ₐ[ℚ] K) (𝓞 K) σ)
theorem isPrincipalIdealRing_of_abs_discr_lt
(h : |discr K| < (2 * (π / 4) ^ nrComplexPlaces K *
((finrank ℚ K) ^ (finrank ℚ K) / (finrank ℚ K)!)) ^ 2) :
IsPrincipalIdealRing (𝓞 K) := by
have : 0 < finrank ℚ K := finrank_pos -- Lean needs to know this for `positivity` to succeed
rw [← Real.sqrt_lt (by positivity) (by positivity), mul_assoc, ← inv_mul_lt_iff₀' (by positivity),
mul_inv, ← inv_pow, inv_div, inv_div, mul_assoc, Int.cast_abs] at h
refine isPrincipalIdealRing_of_isPrincipal_of_norm_le (fun I hI ↦ ?_)
rw [absNorm_eq_one_iff.mp <| le_antisymm (lt_succ.mp (cast_lt.mp
(lt_of_le_of_lt hI h))) <| one_le_iff_ne_zero.mpr (absNorm_ne_zero_of_nonZeroDivisors I)]
exact top_isPrincipal
end RingOfIntegers
namespace Rat
open NumberField
theorem classNumber_eq : NumberField.classNumber ℚ = 1 :=
classNumber_eq_one_iff.mpr <| IsPrincipalIdealRing.of_surjective
Rat.ringOfIntegersEquiv.symm Rat.ringOfIntegersEquiv.symm.surjective
end Rat |
.lake/packages/mathlib/Mathlib/NumberTheory/NumberField/Norm.lean | import Mathlib.NumberTheory.NumberField.Basic
import Mathlib.RingTheory.Localization.NormTrace
import Mathlib.RingTheory.Norm.Transitivity
/-!
# Norm in number fields
Given a finite extension of number fields, we define the norm morphism as a function between the
rings of integers.
## Main definitions
* `RingOfIntegers.norm K` : `Algebra.norm` as a morphism `(𝓞 L) →* (𝓞 K)`.
## Main results
* `RingOfIntegers.dvd_norm` : if `L/K` is a finite Galois extension of fields, then, for all
`(x : 𝓞 L)` we have that `x ∣ algebraMap (𝓞 K) (𝓞 L) (norm K x)`.
-/
open scoped NumberField
open Finset NumberField Algebra Module IntermediateField
section Rat
variable {K : Type*} [Field K] [NumberField K] (x : 𝓞 K)
theorem Algebra.coe_norm_int : (Algebra.norm ℤ x : ℚ) = Algebra.norm ℚ (x : K) :=
(Algebra.norm_localization (R := ℤ) (Rₘ := ℚ) (S := 𝓞 K) (Sₘ := K) (nonZeroDivisors ℤ) x).symm
theorem Algebra.coe_trace_int : (Algebra.trace ℤ _ x : ℚ) = Algebra.trace ℚ K (x : K) :=
(Algebra.trace_localization (R := ℤ) (Rₘ := ℚ) (S := 𝓞 K) (Sₘ := K) (nonZeroDivisors ℤ) x).symm
end Rat
namespace RingOfIntegers
variable {L : Type*} (K : Type*) [Field K] [Field L] [Algebra K L]
/-- `Algebra.norm` as a morphism between the rings of integers. -/
noncomputable def norm : 𝓞 L →* 𝓞 K :=
RingOfIntegers.restrict_monoidHom
((Algebra.norm K).comp (algebraMap (𝓞 L) L : (𝓞 L) →* L))
fun x => isIntegral_norm K x.2
@[simp] lemma coe_norm (x : 𝓞 L) : norm K x = Algebra.norm K (x : L) :=
rfl
theorem coe_algebraMap_norm (x : 𝓞 L) :
(algebraMap (𝓞 K) (𝓞 L) (norm K x) : L) = algebraMap K L (Algebra.norm K (x : L)) :=
rfl
theorem algebraMap_norm_algebraMap (x : 𝓞 K) :
algebraMap _ K (norm K (algebraMap (𝓞 K) (𝓞 L) x)) =
Algebra.norm K (algebraMap K L (algebraMap _ _ x)) :=
rfl
theorem norm_algebraMap (x : 𝓞 K) : norm K (algebraMap (𝓞 K) (𝓞 L) x) = x ^ finrank K L := by
rw [RingOfIntegers.ext_iff, RingOfIntegers.coe_eq_algebraMap,
RingOfIntegers.algebraMap_norm_algebraMap, Algebra.norm_algebraMap,
RingOfIntegers.coe_eq_algebraMap, map_pow]
theorem isUnit_norm_of_isGalois [FiniteDimensional K L] [IsGalois K L] {x : 𝓞 L} :
IsUnit (norm K x) ↔ IsUnit x := by
classical
refine ⟨fun hx => ?_, IsUnit.map _⟩
replace hx : IsUnit (algebraMap (𝓞 K) (𝓞 L) <| norm K x) := hx.map (algebraMap (𝓞 K) <| 𝓞 L)
refine @isUnit_of_mul_isUnit_right (𝓞 L) _
⟨(univ \ {AlgEquiv.refl}).prod fun σ : Gal(L/K) => σ x,
prod_mem fun σ _ => x.2.map (σ : L →+* L).toIntAlgHom⟩ _ ?_
convert hx using 1
ext
convert_to ((univ \ {AlgEquiv.refl}).prod fun σ : Gal(L/K) => σ x) *
∏ σ ∈ {(AlgEquiv.refl : Gal(L/K))}, σ x = _
· rw [prod_singleton, AlgEquiv.coe_refl, _root_.id, RingOfIntegers.coe_eq_algebraMap, map_mul,
RingOfIntegers.map_mk]
· rw [prod_sdiff <| subset_univ _, ← norm_eq_prod_automorphisms, coe_algebraMap_norm]
/-- If `L/K` is a finite Galois extension of fields, then, for all `(x : 𝓞 L)` we have that
`x ∣ algebraMap (𝓞 K) (𝓞 L) (norm K x)`. -/
theorem dvd_norm [FiniteDimensional K L] [IsGalois K L] (x : 𝓞 L) :
x ∣ algebraMap (𝓞 K) (𝓞 L) (norm K x) := by
classical
have hint :
IsIntegral ℤ (∏ σ ∈ univ.erase (AlgEquiv.refl : Gal(L/K)), σ x) :=
IsIntegral.prod _ (fun σ _ =>
((RingOfIntegers.isIntegral_coe x).map σ))
refine ⟨⟨_, hint⟩, ?_⟩
ext
rw [coe_algebraMap_norm K x, norm_eq_prod_automorphisms]
simp [← Finset.mul_prod_erase _ _ (mem_univ AlgEquiv.refl)]
variable (F : Type*) [Field F] [Algebra K F] [FiniteDimensional K F]
theorem norm_norm [Algebra F L] [FiniteDimensional F L] [IsScalarTower K F L] (x : 𝓞 L) :
norm K (norm F x) = norm K x := by
rw [RingOfIntegers.ext_iff, coe_norm, coe_norm, coe_norm, Algebra.norm_norm]
variable {F}
theorem isUnit_norm [CharZero K] {x : 𝓞 F} : IsUnit (norm K x) ↔ IsUnit x := by
letI : Algebra K (AlgebraicClosure K) := AlgebraicClosure.instAlgebra K
let L := normalClosure K F (AlgebraicClosure F)
haveI : FiniteDimensional F L := FiniteDimensional.right K F L
haveI : IsAlgClosure K (AlgebraicClosure F) :=
IsAlgClosure.ofAlgebraic K F (AlgebraicClosure F)
haveI : IsGalois F L := IsGalois.tower_top_of_isGalois K F L
calc
IsUnit (norm K x) ↔ IsUnit ((norm K) x ^ finrank F L) :=
(isUnit_pow_iff (pos_iff_ne_zero.mp finrank_pos)).symm
_ ↔ IsUnit (norm K (algebraMap (𝓞 F) (𝓞 L) x)) := by
rw [← norm_norm K F (algebraMap (𝓞 F) (𝓞 L) x), norm_algebraMap F _, map_pow]
_ ↔ IsUnit (algebraMap (𝓞 F) (𝓞 L) x) := isUnit_norm_of_isGalois K
_ ↔ IsUnit (norm F (algebraMap (𝓞 F) (𝓞 L) x)) := (isUnit_norm_of_isGalois F).symm
_ ↔ IsUnit (x ^ finrank F L) := (congr_arg IsUnit (norm_algebraMap F _)).to_iff
_ ↔ IsUnit x := isUnit_pow_iff (pos_iff_ne_zero.mp finrank_pos)
end RingOfIntegers |
.lake/packages/mathlib/Mathlib/NumberTheory/NumberField/ProductFormula.lean | import Mathlib.NumberTheory.NumberField.FinitePlaces
import Mathlib.NumberTheory.NumberField.InfinitePlace.Basic
/-!
# The Product Formula for number fields
In this file we prove the Product Formula for number fields: for any non-zero element `x` of a
number field `K`, we have `∏ |x|ᵥ=1` where the product runs over the equivalence classes of absolute
values of `K`. The `|⬝|ᵥ` are normalized as follows:
- for the infinite places, `|⬝|ᵥ` is the absolute value on `K` induced by the corresponding field
embedding in `ℂ` and the usual absolute value on `ℂ`;
- for the finite places and a non-zero `x`, `|x|ᵥ` is equal to the norm of the corresponding maximal
ideal of `𝓞 K` raised to the power of the `v`-adic valuation of `x`.
## Main Results
* `NumberField.FinitePlace.prod_eq_inv_abs_norm`: for any non-zero element `x` of a number field
`K`, the product `∏ |x|ᵥ` of the absolute values of `x` associated to the finite places of `K` is
equal to the inverse of the norm of `x`.
* `NumberField.prod_abs_eq_one`: for any non-zero element `x` of a number field `K`, we have
`∏ |x|ᵥ=1`, where the product runs over the equivalence classes of absolute values of `K`.
## Tags
number field, embeddings, places, infinite places, finite places, product formula
-/
namespace NumberField
variable {K : Type*} [Field K] [NumberField K]
open Algebra
open Function Ideal IsDedekindDomain HeightOneSpectrum in
/-- For any non-zero `x` in `𝓞 K`, the product of `w x`, where `w` runs over `FinitePlace K`, is
equal to the inverse of the absolute value of `Algebra.norm ℤ x`. -/
theorem FinitePlace.prod_eq_inv_abs_norm_int {x : 𝓞 K} (h_x_nezero : x ≠ 0) :
∏ᶠ w : FinitePlace K, w x = (|norm ℤ x| : ℝ)⁻¹ := by
simp only [← finprod_comp_equiv equivHeightOneSpectrum.symm, equivHeightOneSpectrum_symm_apply]
refine (inv_eq_of_mul_eq_one_left ?_).symm
norm_cast
have h_span_nezero : span {x} ≠ 0 := by simp [h_x_nezero]
rw [Int.abs_eq_natAbs, ← absNorm_span_singleton,
← finprod_heightOneSpectrum_factorization h_span_nezero, Int.cast_natCast]
let t₀ := {v : HeightOneSpectrum (𝓞 K) | x ∈ v.asIdeal}
have h_fin₀ : t₀.Finite := by simp only [← dvd_span_singleton, finite_factors h_span_nezero, t₀]
let t₁ := (fun v : HeightOneSpectrum (𝓞 K) ↦ ‖embedding v (x : K)‖).mulSupport
let t₂ :=
(fun v : HeightOneSpectrum (𝓞 K) ↦ (absNorm (v.maxPowDividing (span {x})) : ℝ)).mulSupport
have h_fin₁ : t₁.Finite := h_fin₀.subset <| by simp [norm_eq_one_iff_notMem, t₁, t₀]
have h_fin₂ : t₂.Finite := by
refine h_fin₀.subset ?_
simp only [mulSupport_subset_iff, Set.mem_setOf_eq, t₂, t₀,
maxPowDividing, ← dvd_span_singleton]
intro v hv
simp only [map_pow, Nat.cast_pow, ← pow_zero (absNorm v.asIdeal : ℝ)] at hv
classical
refine (Associates.count_ne_zero_iff_dvd h_span_nezero (irreducible v)).1 <| fun h ↦ hv ?_
congr
have h_prod : (absNorm (∏ᶠ (v : HeightOneSpectrum (𝓞 K)), v.maxPowDividing (span {x})) : ℝ) =
∏ᶠ (v : HeightOneSpectrum (𝓞 K)), (absNorm (v.maxPowDividing (span {x})) : ℝ) :=
((Nat.castRingHom ℝ).toMonoidHom.comp absNorm.toMonoidHom).map_finprod_of_preimage_one
(by simp) _
rw [h_prod, ← finprod_mul_distrib h_fin₁ h_fin₂]
exact finprod_eq_one_of_forall_eq_one fun v ↦ v.embedding_mul_absNorm h_x_nezero
/-- For any non-zero `x` in `K`, the product of `w x`, where `w` runs over `FinitePlace K`, is
equal to the inverse of the absolute value of `Algebra.norm ℚ x`. -/
theorem FinitePlace.prod_eq_inv_abs_norm {x : K} (h_x_nezero : x ≠ 0) :
∏ᶠ w : FinitePlace K, w x = |(Algebra.norm ℚ) x|⁻¹ := by
--reduce to 𝓞 K
rcases IsFractionRing.div_surjective (A := 𝓞 K) x with ⟨a, b, hb, rfl⟩
apply nonZeroDivisors.ne_zero at hb
have ha : a ≠ 0 := by
rintro rfl
simp at h_x_nezero
simp_rw [map_div₀, Rat.cast_inv, Rat.cast_abs, finprod_div_distrib (mulSupport_finite_int ha)
(mulSupport_finite_int hb), prod_eq_inv_abs_norm_int ha, prod_eq_inv_abs_norm_int hb]
rw [← inv_eq_iff_eq_inv, inv_inv_div_inv, ← abs_div]
congr
have hb₀ : ((Algebra.norm ℤ) b : ℝ) ≠ 0 := by simp [hb]
refine (eq_div_of_mul_eq hb₀ ?_).symm
norm_cast
rw [coe_norm_int a, coe_norm_int b, ← MonoidHom.map_mul, div_mul_cancel₀ _
(RingOfIntegers.coe_ne_zero_iff.mpr hb)]
open FinitePlace in
/-- The Product Formula for the Number Field `K`. -/
theorem prod_abs_eq_one {x : K} (h_x_nezero : x ≠ 0) :
(∏ w : InfinitePlace K, w x ^ w.mult) * ∏ᶠ w : FinitePlace K, w x = 1 := by
simp [prod_eq_inv_abs_norm, InfinitePlace.prod_eq_abs_norm, h_x_nezero]
end NumberField |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.