path
stringlengths
11
71
content
stringlengths
75
124k
NumberTheory\KummerDedekind.lean
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Paul Lezeau -/ import Mathlib.RingTheory.DedekindDomain.Ideal import Mathlib.RingTheory.IsAdjoinRoot /-! # Kummer-Dedekind theorem This file proves the monogenic version of the Kummer-Dedekind theorem on the splitting of prime ideals in an extension of the ring of integers. This states that if `I` is a prime ideal of Dedekind domain `R` and `S = R[α]` for some `α` that is integral over `R` with minimal polynomial `f`, then the prime factorisations of `I * S` and `f mod I` have the same shape, i.e. they have the same number of prime factors, and each prime factors of `I * S` can be paired with a prime factor of `f mod I` in a way that ensures multiplicities match (in fact, this pairing can be made explicit with a formula). ## Main definitions * `normalizedFactorsMapEquivNormalizedFactorsMinPolyMk` : The bijection in the Kummer-Dedekind theorem. This is the pairing between the prime factors of `I * S` and the prime factors of `f mod I`. ## Main results * `normalized_factors_ideal_map_eq_normalized_factors_min_poly_mk_map` : The Kummer-Dedekind theorem. * `Ideal.irreducible_map_of_irreducible_minpoly` : `I.map (algebraMap R S)` is irreducible if `(map (Ideal.Quotient.mk I) (minpoly R pb.gen))` is irreducible, where `pb` is a power basis of `S` over `R`. ## TODO * Prove the Kummer-Dedekind theorem in full generality. * Prove the converse of `Ideal.irreducible_map_of_irreducible_minpoly`. * Prove that `normalizedFactorsMapEquivNormalizedFactorsMinPolyMk` can be expressed as `normalizedFactorsMapEquivNormalizedFactorsMinPolyMk g = ⟨I, G(α)⟩` for `g` a prime factor of `f mod I` and `G` a lift of `g` to `R[X]`. ## References * [J. Neukirch, *Algebraic Number Theory*][Neukirch1992] ## Tags kummer, dedekind, kummer dedekind, dedekind-kummer, dedekind kummer -/ variable (R : Type*) {S : Type*} [CommRing R] [CommRing S] [Algebra R S] open Ideal Polynomial DoubleQuot UniqueFactorizationMonoid Algebra RingHom local notation:max R "<" x:max ">" => adjoin R ({x} : Set S) /-- Let `S / R` be a ring extension and `x : S`, then the conductor of `R<x>` is the biggest ideal of `S` contained in `R<x>`. -/ def conductor (x : S) : Ideal S where carrier := {a | ∀ b : S, a * b ∈ R<x>} zero_mem' b := by simpa only [zero_mul] using Subalgebra.zero_mem _ add_mem' ha hb c := by simpa only [add_mul] using Subalgebra.add_mem _ (ha c) (hb c) smul_mem' c a ha b := by simpa only [smul_eq_mul, mul_left_comm, mul_assoc] using ha (c * b) variable {R} {x : S} theorem conductor_eq_of_eq {y : S} (h : (R<x> : Set S) = R<y>) : conductor R x = conductor R y := Ideal.ext fun _ => forall_congr' fun _ => Set.ext_iff.mp h _ theorem conductor_subset_adjoin : (conductor R x : Set S) ⊆ R<x> := fun y hy => by simpa only [mul_one] using hy 1 theorem mem_conductor_iff {y : S} : y ∈ conductor R x ↔ ∀ b : S, y * b ∈ R<x> := ⟨fun h => h, fun h => h⟩ theorem conductor_eq_top_of_adjoin_eq_top (h : R<x> = ⊤) : conductor R x = ⊤ := by simp only [Ideal.eq_top_iff_one, mem_conductor_iff, h, mem_top, forall_const] theorem conductor_eq_top_of_powerBasis (pb : PowerBasis R S) : conductor R pb.gen = ⊤ := conductor_eq_top_of_adjoin_eq_top pb.adjoin_gen_eq_top open IsLocalization in lemma mem_coeSubmodule_conductor {L} [CommRing L] [Algebra S L] [Algebra R L] [IsScalarTower R S L] [NoZeroSMulDivisors S L] {x : S} {y : L} : y ∈ coeSubmodule L (conductor R x) ↔ ∀ z : S, y * (algebraMap S L) z ∈ Algebra.adjoin R {algebraMap S L x} := by cases subsingleton_or_nontrivial L · rw [Subsingleton.elim (coeSubmodule L _) ⊤, Subsingleton.elim (Algebra.adjoin R _) ⊤]; simp trans ∀ z, y * (algebraMap S L) z ∈ (Algebra.adjoin R {x}).map (IsScalarTower.toAlgHom R S L) · simp only [coeSubmodule, Submodule.mem_map, Algebra.linearMap_apply, Subalgebra.mem_map, IsScalarTower.coe_toAlgHom'] constructor · rintro ⟨y, hy, rfl⟩ z exact ⟨_, hy z, map_mul _ _ _⟩ · intro H obtain ⟨y, _, e⟩ := H 1 rw [_root_.map_one, mul_one] at e subst e simp only [← _root_.map_mul, (NoZeroSMulDivisors.algebraMap_injective S L).eq_iff, exists_eq_right] at H exact ⟨_, H, rfl⟩ · rw [AlgHom.map_adjoin, Set.image_singleton]; rfl variable {I : Ideal R} /-- This technical lemma tell us that if `C` is the conductor of `R<x>` and `I` is an ideal of `R` then `p * (I * S) ⊆ I * R<x>` for any `p` in `C ∩ R` -/ theorem prod_mem_ideal_map_of_mem_conductor {p : R} {z : S} (hp : p ∈ Ideal.comap (algebraMap R S) (conductor R x)) (hz' : z ∈ I.map (algebraMap R S)) : algebraMap R S p * z ∈ algebraMap R<x> S '' ↑(I.map (algebraMap R R<x>)) := by rw [Ideal.map, Ideal.span, Finsupp.mem_span_image_iff_total] at hz' obtain ⟨l, H, H'⟩ := hz' rw [Finsupp.total_apply] at H' rw [← H', mul_comm, Finsupp.sum_mul] have lem : ∀ {a : R}, a ∈ I → l a • algebraMap R S a * algebraMap R S p ∈ algebraMap R<x> S '' I.map (algebraMap R R<x>) := by intro a ha rw [Algebra.id.smul_eq_mul, mul_assoc, mul_comm, mul_assoc, Set.mem_image] refine Exists.intro (algebraMap R R<x> a * ⟨l a * algebraMap R S p, show l a * algebraMap R S p ∈ R<x> from ?h⟩) ?_ case h => rw [mul_comm] exact mem_conductor_iff.mp (Ideal.mem_comap.mp hp) _ · refine ⟨?_, ?_⟩ · rw [mul_comm] apply Ideal.mul_mem_left (I.map (algebraMap R R<x>)) _ (Ideal.mem_map_of_mem _ ha) · simp only [RingHom.map_mul, mul_comm (algebraMap R S p) (l a)] rfl refine Finset.sum_induction _ (fun u => u ∈ algebraMap R<x> S '' I.map (algebraMap R R<x>)) (fun a b => ?_) ?_ ?_ · rintro ⟨z, hz, rfl⟩ ⟨y, hy, rfl⟩ rw [← RingHom.map_add] exact ⟨z + y, Ideal.add_mem _ (SetLike.mem_coe.mp hz) hy, rfl⟩ · exact ⟨0, SetLike.mem_coe.mpr <| Ideal.zero_mem _, RingHom.map_zero _⟩ · intro y hy exact lem ((Finsupp.mem_supported _ l).mp H hy) /-- A technical result telling us that `(I * S) ∩ R<x> = I * R<x>` for any ideal `I` of `R`. -/ theorem comap_map_eq_map_adjoin_of_coprime_conductor (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (h_alg : Function.Injective (algebraMap R<x> S)) : (I.map (algebraMap R S)).comap (algebraMap R<x> S) = I.map (algebraMap R R<x>) := by apply le_antisymm · -- This is adapted from [Neukirch1992]. Let `C = (conductor R x)`. The idea of the proof -- is that since `I` and `C ∩ R` are coprime, we have -- `(I * S) ∩ R<x> ⊆ (I + C) * ((I * S) ∩ R<x>) ⊆ I * R<x> + I * C * S ⊆ I * R<x>`. intro y hy obtain ⟨z, hz⟩ := y obtain ⟨p, hp, q, hq, hpq⟩ := Submodule.mem_sup.mp ((Ideal.eq_top_iff_one _).mp hx) have temp : algebraMap R S p * z + algebraMap R S q * z = z := by simp only [← add_mul, ← RingHom.map_add (algebraMap R S), hpq, map_one, one_mul] suffices z ∈ algebraMap R<x> S '' I.map (algebraMap R R<x>) ↔ (⟨z, hz⟩ : R<x>) ∈ I.map (algebraMap R R<x>) by rw [← this, ← temp] obtain ⟨a, ha⟩ := (Set.mem_image _ _ _).mp (prod_mem_ideal_map_of_mem_conductor hp (show z ∈ I.map (algebraMap R S) by rwa [Ideal.mem_comap] at hy)) use a + algebraMap R R<x> q * ⟨z, hz⟩ refine ⟨Ideal.add_mem (I.map (algebraMap R R<x>)) ha.left ?_, by simp only [ha.right, map_add, _root_.map_mul, add_right_inj]; rfl⟩ rw [mul_comm] exact Ideal.mul_mem_left (I.map (algebraMap R R<x>)) _ (Ideal.mem_map_of_mem _ hq) refine ⟨fun h => ?_, fun h => (Set.mem_image _ _ _).mpr (Exists.intro ⟨z, hz⟩ ⟨by simp [h], rfl⟩)⟩ obtain ⟨x₁, hx₁, hx₂⟩ := (Set.mem_image _ _ _).mp h have : x₁ = ⟨z, hz⟩ := by apply h_alg simp [hx₂, algebraMap_eq_smul_one] rwa [← this] · -- The converse inclusion is trivial have : algebraMap R S = (algebraMap _ S).comp (algebraMap R R<x>) := by ext; rfl rw [this, ← Ideal.map_map] apply Ideal.le_comap_map /-- The canonical morphism of rings from `R<x> ⧸ (I*R<x>)` to `S ⧸ (I*S)` is an isomorphism when `I` and `(conductor R x) ∩ R` are coprime. -/ noncomputable def quotAdjoinEquivQuotMap (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (h_alg : Function.Injective (algebraMap R<x> S)) : R<x> ⧸ I.map (algebraMap R R<x>) ≃+* S ⧸ I.map (algebraMap R S) := by let f : R<x> ⧸ I.map (algebraMap R R<x>) →+* S ⧸ I.map (algebraMap R S) := (Ideal.Quotient.lift (I.map (algebraMap R R<x>)) ((Ideal.Quotient.mk (I.map (algebraMap R S))).comp (algebraMap R<x> S)) (fun r hr => by have : algebraMap R S = (algebraMap R<x> S).comp (algebraMap R R<x>) := by ext; rfl rw [RingHom.comp_apply, Ideal.Quotient.eq_zero_iff_mem, this, ← Ideal.map_map] exact Ideal.mem_map_of_mem _ hr)) refine RingEquiv.ofBijective f ⟨?_, ?_⟩ · --the kernel of the map is clearly `(I * S) ∩ R<x>`. To get injectivity, we need to show that --this is contained in `I * R<x>`, which is the content of the previous lemma. refine RingHom.lift_injective_of_ker_le_ideal _ _ fun u hu => ?_ rwa [RingHom.mem_ker, RingHom.comp_apply, Ideal.Quotient.eq_zero_iff_mem, ← Ideal.mem_comap, comap_map_eq_map_adjoin_of_coprime_conductor hx h_alg] at hu · -- Surjectivity follows from the surjectivity of the canonical map `R<x> → S ⧸ (I * S)`, -- which in turn follows from the fact that `I * S + (conductor R x) = S`. refine Ideal.Quotient.lift_surjective_of_surjective _ _ fun y => ?_ obtain ⟨z, hz⟩ := Ideal.Quotient.mk_surjective y have : z ∈ conductor R x ⊔ I.map (algebraMap R S) := by suffices conductor R x ⊔ I.map (algebraMap R S) = ⊤ by simp only [this, Submodule.mem_top] rw [Ideal.eq_top_iff_one] at hx ⊢ replace hx := Ideal.mem_map_of_mem (algebraMap R S) hx rw [Ideal.map_sup, RingHom.map_one] at hx exact (sup_le_sup (show ((conductor R x).comap (algebraMap R S)).map (algebraMap R S) ≤ conductor R x from Ideal.map_comap_le) (le_refl (I.map (algebraMap R S)))) hx rw [← Ideal.mem_quotient_iff_mem_sup, hz, Ideal.mem_map_iff_of_surjective] at this · obtain ⟨u, hu, hu'⟩ := this use ⟨u, conductor_subset_adjoin hu⟩ simp only [← hu'] rfl · exact Ideal.Quotient.mk_surjective @[simp] theorem quotAdjoinEquivQuotMap_apply_mk (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (h_alg : Function.Injective (algebraMap R<x> S)) (a : R<x>) : quotAdjoinEquivQuotMap hx h_alg (Ideal.Quotient.mk (I.map (algebraMap R R<x>)) a) = Ideal.Quotient.mk (I.map (algebraMap R S)) ↑a := rfl namespace KummerDedekind open scoped Polynomial variable [IsDomain R] [IsIntegrallyClosed R] variable [IsDedekindDomain S] variable [NoZeroSMulDivisors R S] attribute [local instance] Ideal.Quotient.field open Classical in /-- The first half of the **Kummer-Dedekind Theorem** in the monogenic case, stating that the prime factors of `I*S` are in bijection with those of the minimal polynomial of the generator of `S` over `R`, taken `mod I`. -/ noncomputable def normalizedFactorsMapEquivNormalizedFactorsMinPolyMk (hI : IsMaximal I) (hI' : I ≠ ⊥) (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (hx' : IsIntegral R x) : {J : Ideal S | J ∈ normalizedFactors (I.map (algebraMap R S))} ≃ {d : (R ⧸ I)[X] | d ∈ normalizedFactors (Polynomial.map (Ideal.Quotient.mk I) (minpoly R x))} := by -- Porting note: Lean needs to be reminded about this so it does not time out have : IsPrincipalIdealRing (R ⧸ I)[X] := inferInstance let f : S ⧸ map (algebraMap R S) I ≃+* (R ⧸ I)[X] ⧸ span {Polynomial.map (Ideal.Quotient.mk I) (minpoly R x)} := by refine (quotAdjoinEquivQuotMap hx ?_).symm.trans (((Algebra.adjoin.powerBasis' hx').quotientEquivQuotientMinpolyMap I).toRingEquiv.trans (quotEquivOfEq ?_)) · exact NoZeroSMulDivisors.algebraMap_injective (Algebra.adjoin R {x}) S · rw [Algebra.adjoin.powerBasis'_minpoly_gen hx'] refine (normalizedFactorsEquivOfQuotEquiv f ?_ ?_).trans ?_ · rwa [Ne, map_eq_bot_iff_of_injective (NoZeroSMulDivisors.algebraMap_injective R S), ← Ne] · by_contra h exact (show Polynomial.map (Ideal.Quotient.mk I) (minpoly R x) ≠ 0 from Polynomial.map_monic_ne_zero (minpoly.monic hx')) (span_singleton_eq_bot.mp h) · refine (normalizedFactorsEquivSpanNormalizedFactors ?_).symm exact Polynomial.map_monic_ne_zero (minpoly.monic hx') open Classical in /-- The second half of the **Kummer-Dedekind Theorem** in the monogenic case, stating that the bijection `FactorsEquiv'` defined in the first half preserves multiplicities. -/ theorem multiplicity_factors_map_eq_multiplicity (hI : IsMaximal I) (hI' : I ≠ ⊥) (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (hx' : IsIntegral R x) {J : Ideal S} (hJ : J ∈ normalizedFactors (I.map (algebraMap R S))) : multiplicity J (I.map (algebraMap R S)) = multiplicity (↑(normalizedFactorsMapEquivNormalizedFactorsMinPolyMk hI hI' hx hx' ⟨J, hJ⟩)) (Polynomial.map (Ideal.Quotient.mk I) (minpoly R x)) := by rw [normalizedFactorsMapEquivNormalizedFactorsMinPolyMk, Equiv.coe_trans, Function.comp_apply, multiplicity_normalizedFactorsEquivSpanNormalizedFactors_symm_eq_multiplicity, normalizedFactorsEquivOfQuotEquiv_multiplicity_eq_multiplicity] open Classical in /-- The **Kummer-Dedekind Theorem**. -/ theorem normalizedFactors_ideal_map_eq_normalizedFactors_min_poly_mk_map (hI : IsMaximal I) (hI' : I ≠ ⊥) (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (hx' : IsIntegral R x) : normalizedFactors (I.map (algebraMap R S)) = Multiset.map (fun f => ((normalizedFactorsMapEquivNormalizedFactorsMinPolyMk hI hI' hx hx').symm f : Ideal S)) (normalizedFactors (Polynomial.map (Ideal.Quotient.mk I) (minpoly R x))).attach := by ext J -- WLOG, assume J is a normalized factor by_cases hJ : J ∈ normalizedFactors (I.map (algebraMap R S)) swap · rw [Multiset.count_eq_zero.mpr hJ, eq_comm, Multiset.count_eq_zero, Multiset.mem_map] simp only [Multiset.mem_attach, true_and_iff, not_exists] rintro J' rfl exact hJ ((normalizedFactorsMapEquivNormalizedFactorsMinPolyMk hI hI' hx hx').symm J').prop -- Then we just have to compare the multiplicities, which we already proved are equal. have := multiplicity_factors_map_eq_multiplicity hI hI' hx hx' hJ rw [multiplicity_eq_count_normalizedFactors, multiplicity_eq_count_normalizedFactors, UniqueFactorizationMonoid.normalize_normalized_factor _ hJ, UniqueFactorizationMonoid.normalize_normalized_factor, PartENat.natCast_inj] at this · refine this.trans ?_ -- Get rid of the `map` by applying the equiv to both sides. generalize hJ' : (normalizedFactorsMapEquivNormalizedFactorsMinPolyMk hI hI' hx hx') ⟨J, hJ⟩ = J' have : ((normalizedFactorsMapEquivNormalizedFactorsMinPolyMk hI hI' hx hx').symm J' : Ideal S) = J := by rw [← hJ', Equiv.symm_apply_apply _ _, Subtype.coe_mk] subst this -- Get rid of the `attach` by applying the subtype `coe` to both sides. rw [Multiset.count_map_eq_count' fun f => ((normalizedFactorsMapEquivNormalizedFactorsMinPolyMk hI hI' hx hx').symm f : Ideal S), Multiset.count_attach] · exact Subtype.coe_injective.comp (Equiv.injective _) · exact (normalizedFactorsMapEquivNormalizedFactorsMinPolyMk hI hI' hx hx' _).prop · exact irreducible_of_normalized_factor _ (normalizedFactorsMapEquivNormalizedFactorsMinPolyMk hI hI' hx hx' _).prop · exact Polynomial.map_monic_ne_zero (minpoly.monic hx') · exact irreducible_of_normalized_factor _ hJ · rwa [← bot_eq_zero, Ne, map_eq_bot_iff_of_injective (NoZeroSMulDivisors.algebraMap_injective R S)] theorem Ideal.irreducible_map_of_irreducible_minpoly (hI : IsMaximal I) (hI' : I ≠ ⊥) (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (hx' : IsIntegral R x) (hf : Irreducible (Polynomial.map (Ideal.Quotient.mk I) (minpoly R x))) : Irreducible (I.map (algebraMap R S)) := by classical have mem_norm_factors : normalize (Polynomial.map (Ideal.Quotient.mk I) (minpoly R x)) ∈ normalizedFactors (Polynomial.map (Ideal.Quotient.mk I) (minpoly R x)) := by simp [normalizedFactors_irreducible hf] suffices ∃ y, normalizedFactors (I.map (algebraMap R S)) = {y} by obtain ⟨y, hy⟩ := this have h := normalizedFactors_prod (show I.map (algebraMap R S) ≠ 0 by rwa [← bot_eq_zero, Ne, map_eq_bot_iff_of_injective (NoZeroSMulDivisors.algebraMap_injective R S)]) rw [associated_iff_eq, hy, Multiset.prod_singleton] at h rw [← h] exact irreducible_of_normalized_factor y (show y ∈ normalizedFactors (I.map (algebraMap R S)) by simp [hy]) rw [normalizedFactors_ideal_map_eq_normalizedFactors_min_poly_mk_map hI hI' hx hx'] use ((normalizedFactorsMapEquivNormalizedFactorsMinPolyMk hI hI' hx hx').symm ⟨normalize (Polynomial.map (Ideal.Quotient.mk I) (minpoly R x)), mem_norm_factors⟩ : Ideal S) rw [Multiset.map_eq_singleton] use ⟨normalize (Polynomial.map (Ideal.Quotient.mk I) (minpoly R x)), mem_norm_factors⟩ refine ⟨?_, rfl⟩ apply Multiset.map_injective Subtype.coe_injective rw [Multiset.attach_map_val, Multiset.map_singleton, Subtype.coe_mk] exact normalizedFactors_irreducible hf end KummerDedekind
NumberTheory\LucasLehmer.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Scott Morrison, Ainsley Pahljina -/ import Mathlib.Algebra.Order.Ring.Abs import Mathlib.Algebra.Order.Ring.Basic import Mathlib.Algebra.Ring.Nat import Mathlib.Data.ZMod.Basic import Mathlib.GroupTheory.OrderOfElement import Mathlib.RingTheory.Fintype import Mathlib.Tactic.IntervalCases import Mathlib.Tactic.Zify /-! # The Lucas-Lehmer test for Mersenne primes. We define `lucasLehmerResidue : Π p : ℕ, ZMod (2^p - 1)`, and prove `lucasLehmerResidue p = 0 → Prime (mersenne p)`. We construct a `norm_num` extension to calculate this residue to certify primality of Mersenne primes using `lucas_lehmer_sufficiency`. ## TODO - Show reverse implication. - Speed up the calculations using `n ≡ (n % 2^p) + (n / 2^p) [MOD 2^p - 1]`. - Find some bigger primes! ## History This development began as a student project by Ainsley Pahljina, and was then cleaned up for mathlib by Scott Morrison. The tactic for certified computation of Lucas-Lehmer residues was provided by Mario Carneiro. This tactic was ported by Thomas Murrills to Lean 4, and then it was converted to a `norm_num` extension and made to use kernel reductions by Kyle Miller. -/ /-- The Mersenne numbers, 2^p - 1. -/ def mersenne (p : ℕ) : ℕ := 2 ^ p - 1 theorem strictMono_mersenne : StrictMono mersenne := fun m n h ↦ (Nat.sub_lt_sub_iff_right <| Nat.one_le_pow _ _ two_pos).2 <| by gcongr; norm_num1 @[simp] theorem mersenne_lt_mersenne {p q : ℕ} : mersenne p < mersenne q ↔ p < q := strictMono_mersenne.lt_iff_lt @[gcongr] protected alias ⟨_, GCongr.mersenne_lt_mersenne⟩ := mersenne_lt_mersenne @[simp] theorem mersenne_le_mersenne {p q : ℕ} : mersenne p ≤ mersenne q ↔ p ≤ q := strictMono_mersenne.le_iff_le @[gcongr] protected alias ⟨_, GCongr.mersenne_le_mersenne⟩ := mersenne_le_mersenne @[simp] theorem mersenne_zero : mersenne 0 = 0 := rfl @[simp] theorem mersenne_pos {p : ℕ} : 0 < mersenne p ↔ 0 < p := mersenne_lt_mersenne (p := 0) namespace Mathlib.Meta.Positivity open Lean Meta Qq Function alias ⟨_, mersenne_pos_of_pos⟩ := mersenne_pos /-- Extension for the `positivity` tactic: `mersenne`. -/ @[positivity mersenne _] def evalMersenne : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℕ), ~q(mersenne $a) => let ra ← core q(inferInstance) q(inferInstance) a assertInstancesCommute match ra with | .positive pa => pure (.positive q(mersenne_pos_of_pos $pa)) | _ => pure (.nonnegative q(Nat.zero_le (mersenne $a))) | _, _, _ => throwError "not mersenne" end Mathlib.Meta.Positivity @[simp] theorem one_lt_mersenne {p : ℕ} : 1 < mersenne p ↔ 1 < p := mersenne_lt_mersenne (p := 1) @[simp] theorem succ_mersenne (k : ℕ) : mersenne k + 1 = 2 ^ k := by rw [mersenne, tsub_add_cancel_of_le] exact one_le_pow_of_one_le (by norm_num) k namespace LucasLehmer open Nat /-! We now define three(!) different versions of the recurrence `s (i+1) = (s i)^2 - 2`. These versions take values either in `ℤ`, in `ZMod (2^p - 1)`, or in `ℤ` but applying `% (2^p - 1)` at each step. They are each useful at different points in the proof, so we take a moment setting up the lemmas relating them. -/ /-- The recurrence `s (i+1) = (s i)^2 - 2` in `ℤ`. -/ def s : ℕ → ℤ | 0 => 4 | i + 1 => s i ^ 2 - 2 /-- The recurrence `s (i+1) = (s i)^2 - 2` in `ZMod (2^p - 1)`. -/ def sZMod (p : ℕ) : ℕ → ZMod (2 ^ p - 1) | 0 => 4 | i + 1 => sZMod p i ^ 2 - 2 /-- The recurrence `s (i+1) = ((s i)^2 - 2) % (2^p - 1)` in `ℤ`. -/ def sMod (p : ℕ) : ℕ → ℤ | 0 => 4 % (2 ^ p - 1) | i + 1 => (sMod p i ^ 2 - 2) % (2 ^ p - 1) theorem mersenne_int_pos {p : ℕ} (hp : p ≠ 0) : (0 : ℤ) < 2 ^ p - 1 := sub_pos.2 <| mod_cast Nat.one_lt_two_pow hp theorem mersenne_int_ne_zero (p : ℕ) (hp : p ≠ 0) : (2 ^ p - 1 : ℤ) ≠ 0 := (mersenne_int_pos hp).ne' theorem sMod_nonneg (p : ℕ) (hp : p ≠ 0) (i : ℕ) : 0 ≤ sMod p i := by cases i <;> dsimp [sMod] · exact sup_eq_right.mp rfl · apply Int.emod_nonneg exact mersenne_int_ne_zero p hp theorem sMod_mod (p i : ℕ) : sMod p i % (2 ^ p - 1) = sMod p i := by cases i <;> simp [sMod] theorem sMod_lt (p : ℕ) (hp : p ≠ 0) (i : ℕ) : sMod p i < 2 ^ p - 1 := by rw [← sMod_mod] refine (Int.emod_lt _ (mersenne_int_ne_zero p hp)).trans_eq ?_ exact abs_of_nonneg (mersenne_int_pos hp).le theorem sZMod_eq_s (p' : ℕ) (i : ℕ) : sZMod (p' + 2) i = (s i : ZMod (2 ^ (p' + 2) - 1)) := by induction' i with i ih · dsimp [s, sZMod] norm_num · push_cast [s, sZMod, ih]; rfl -- These next two don't make good `norm_cast` lemmas. theorem Int.natCast_pow_pred (b p : ℕ) (w : 0 < b) : ((b ^ p - 1 : ℕ) : ℤ) = (b : ℤ) ^ p - 1 := by have : 1 ≤ b ^ p := Nat.one_le_pow p b w norm_cast @[deprecated (since := "2024-05-25")] alias Int.coe_nat_pow_pred := Int.natCast_pow_pred theorem Int.coe_nat_two_pow_pred (p : ℕ) : ((2 ^ p - 1 : ℕ) : ℤ) = (2 ^ p - 1 : ℤ) := Int.natCast_pow_pred 2 p (by decide) theorem sZMod_eq_sMod (p : ℕ) (i : ℕ) : sZMod p i = (sMod p i : ZMod (2 ^ p - 1)) := by induction i <;> push_cast [← Int.coe_nat_two_pow_pred p, sMod, sZMod, *] <;> rfl /-- The Lucas-Lehmer residue is `s p (p-2)` in `ZMod (2^p - 1)`. -/ def lucasLehmerResidue (p : ℕ) : ZMod (2 ^ p - 1) := sZMod p (p - 2) theorem residue_eq_zero_iff_sMod_eq_zero (p : ℕ) (w : 1 < p) : lucasLehmerResidue p = 0 ↔ sMod p (p - 2) = 0 := by dsimp [lucasLehmerResidue] rw [sZMod_eq_sMod p] constructor · -- We want to use that fact that `0 ≤ s_mod p (p-2) < 2^p - 1` -- and `lucas_lehmer_residue p = 0 → 2^p - 1 ∣ s_mod p (p-2)`. intro h simp? [ZMod.intCast_zmod_eq_zero_iff_dvd] at h says simp only [ZMod.intCast_zmod_eq_zero_iff_dvd, ofNat_pos, pow_pos, cast_pred, cast_pow, cast_ofNat] at h apply Int.eq_zero_of_dvd_of_nonneg_of_lt _ _ h <;> clear h · exact sMod_nonneg _ (by positivity) _ · exact sMod_lt _ (by positivity) _ · intro h rw [h] simp /-- **Lucas-Lehmer Test**: a Mersenne number `2^p-1` is prime if and only if the Lucas-Lehmer residue `s p (p-2) % (2^p - 1)` is zero. -/ def LucasLehmerTest (p : ℕ) : Prop := lucasLehmerResidue p = 0 -- Porting note: We have a fast `norm_num` extension, and we would rather use that than accidentally -- have `simp` use `decide`! /- instance : DecidablePred LucasLehmerTest := inferInstanceAs (DecidablePred (lucasLehmerResidue · = 0)) -/ /-- `q` is defined as the minimum factor of `mersenne p`, bundled as an `ℕ+`. -/ def q (p : ℕ) : ℕ+ := ⟨Nat.minFac (mersenne p), Nat.minFac_pos (mersenne p)⟩ -- It would be nice to define this as (ℤ/qℤ)[x] / (x^2 - 3), -- obtaining the ring structure for free, -- but that seems to be more trouble than it's worth; -- if it were easy to make the definition, -- cardinality calculations would be somewhat more involved, too. /-- We construct the ring `X q` as ℤ/qℤ + √3 ℤ/qℤ. -/ def X (q : ℕ+) : Type := ZMod q × ZMod q namespace X variable {q : ℕ+} instance : Inhabited (X q) := inferInstanceAs (Inhabited (ZMod q × ZMod q)) instance : Fintype (X q) := inferInstanceAs (Fintype (ZMod q × ZMod q)) instance : DecidableEq (X q) := inferInstanceAs (DecidableEq (ZMod q × ZMod q)) instance : AddCommGroup (X q) := inferInstanceAs (AddCommGroup (ZMod q × ZMod q)) @[ext] theorem ext {x y : X q} (h₁ : x.1 = y.1) (h₂ : x.2 = y.2) : x = y := by cases x; cases y; congr @[simp] theorem zero_fst : (0 : X q).1 = 0 := rfl @[simp] theorem zero_snd : (0 : X q).2 = 0 := rfl @[simp] theorem add_fst (x y : X q) : (x + y).1 = x.1 + y.1 := rfl @[simp] theorem add_snd (x y : X q) : (x + y).2 = x.2 + y.2 := rfl @[simp] theorem neg_fst (x : X q) : (-x).1 = -x.1 := rfl @[simp] theorem neg_snd (x : X q) : (-x).2 = -x.2 := rfl instance : Mul (X q) where mul x y := (x.1 * y.1 + 3 * x.2 * y.2, x.1 * y.2 + x.2 * y.1) @[simp] theorem mul_fst (x y : X q) : (x * y).1 = x.1 * y.1 + 3 * x.2 * y.2 := rfl @[simp] theorem mul_snd (x y : X q) : (x * y).2 = x.1 * y.2 + x.2 * y.1 := rfl instance : One (X q) where one := ⟨1, 0⟩ @[simp] theorem one_fst : (1 : X q).1 = 1 := rfl @[simp] theorem one_snd : (1 : X q).2 = 0 := rfl instance : Monoid (X q) := { inferInstanceAs (Mul (X q)), inferInstanceAs (One (X q)) with mul_assoc := fun x y z => by ext <;> dsimp <;> ring one_mul := fun x => by ext <;> simp mul_one := fun x => by ext <;> simp } instance : NatCast (X q) where natCast := fun n => ⟨n, 0⟩ @[simp] theorem fst_natCast (n : ℕ) : (n : X q).fst = (n : ZMod q) := rfl @[simp] theorem snd_natCast (n : ℕ) : (n : X q).snd = (0 : ZMod q) := rfl -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_fst (n : ℕ) [n.AtLeastTwo] : (no_index (OfNat.ofNat n) : X q).fst = OfNat.ofNat n := rfl -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_snd (n : ℕ) [n.AtLeastTwo] : (no_index (OfNat.ofNat n) : X q).snd = 0 := rfl instance : AddGroupWithOne (X q) := { inferInstanceAs (Monoid (X q)), inferInstanceAs (AddCommGroup (X q)), inferInstanceAs (NatCast (X q)) with natCast_zero := by ext <;> simp natCast_succ := fun _ ↦ by ext <;> simp intCast := fun n => ⟨n, 0⟩ intCast_ofNat := fun n => by ext <;> simp intCast_negSucc := fun n => by ext <;> simp } theorem left_distrib (x y z : X q) : x * (y + z) = x * y + x * z := by ext <;> dsimp <;> ring theorem right_distrib (x y z : X q) : (x + y) * z = x * z + y * z := by ext <;> dsimp <;> ring instance : Ring (X q) := { inferInstanceAs (AddGroupWithOne (X q)), inferInstanceAs (AddCommGroup (X q)), inferInstanceAs (Monoid (X q)) with left_distrib := left_distrib right_distrib := right_distrib mul_zero := fun _ ↦ by ext <;> simp zero_mul := fun _ ↦ by ext <;> simp } instance : CommRing (X q) := { inferInstanceAs (Ring (X q)) with mul_comm := fun _ _ ↦ by ext <;> dsimp <;> ring } instance [Fact (1 < (q : ℕ))] : Nontrivial (X q) := ⟨⟨0, 1, ne_of_apply_ne Prod.fst zero_ne_one⟩⟩ @[simp] theorem fst_intCast (n : ℤ) : (n : X q).fst = (n : ZMod q) := rfl @[simp] theorem snd_intCast (n : ℤ) : (n : X q).snd = (0 : ZMod q) := rfl @[deprecated (since := "2024-05-25")] alias nat_coe_fst := fst_natCast @[deprecated (since := "2024-05-25")] alias nat_coe_snd := snd_natCast @[deprecated (since := "2024-05-25")] alias int_coe_fst := fst_intCast @[deprecated (since := "2024-05-25")] alias int_coe_snd := snd_intCast @[norm_cast] theorem coe_mul (n m : ℤ) : ((n * m : ℤ) : X q) = (n : X q) * (m : X q) := by ext <;> simp @[norm_cast] theorem coe_natCast (n : ℕ) : ((n : ℤ) : X q) = (n : X q) := by ext <;> simp @[deprecated (since := "2024-04-05")] alias coe_nat := coe_natCast /-- The cardinality of `X` is `q^2`. -/ theorem card_eq : Fintype.card (X q) = q ^ 2 := by dsimp [X] rw [Fintype.card_prod, ZMod.card q, sq] /-- There are strictly fewer than `q^2` units, since `0` is not a unit. -/ nonrec theorem card_units_lt (w : 1 < q) : Fintype.card (X q)ˣ < q ^ 2 := by have : Fact (1 < (q : ℕ)) := ⟨w⟩ convert card_units_lt (X q) rw [card_eq] /-- We define `ω = 2 + √3`. -/ def ω : X q := (2, 1) /-- We define `ωb = 2 - √3`, which is the inverse of `ω`. -/ def ωb : X q := (2, -1) theorem ω_mul_ωb (q : ℕ+) : (ω : X q) * ωb = 1 := by dsimp [ω, ωb] ext <;> simp; ring theorem ωb_mul_ω (q : ℕ+) : (ωb : X q) * ω = 1 := by rw [mul_comm, ω_mul_ωb] /-- A closed form for the recurrence relation. -/ theorem closed_form (i : ℕ) : (s i : X q) = (ω : X q) ^ 2 ^ i + (ωb : X q) ^ 2 ^ i := by induction' i with i ih · dsimp [s, ω, ωb] ext <;> norm_num · calc (s (i + 1) : X q) = (s i ^ 2 - 2 : ℤ) := rfl _ = (s i : X q) ^ 2 - 2 := by push_cast; rfl _ = (ω ^ 2 ^ i + ωb ^ 2 ^ i) ^ 2 - 2 := by rw [ih] _ = (ω ^ 2 ^ i) ^ 2 + (ωb ^ 2 ^ i) ^ 2 + 2 * (ωb ^ 2 ^ i * ω ^ 2 ^ i) - 2 := by ring _ = (ω ^ 2 ^ i) ^ 2 + (ωb ^ 2 ^ i) ^ 2 := by rw [← mul_pow ωb ω, ωb_mul_ω, one_pow, mul_one, add_sub_cancel_right] _ = ω ^ 2 ^ (i + 1) + ωb ^ 2 ^ (i + 1) := by rw [← pow_mul, ← pow_mul, _root_.pow_succ] end X open X /-! Here and below, we introduce `p' = p - 2`, in order to avoid using subtraction in `ℕ`. -/ /-- If `1 < p`, then `q p`, the smallest prime factor of `mersenne p`, is more than 2. -/ theorem two_lt_q (p' : ℕ) : 2 < q (p' + 2) := by refine (minFac_prime (one_lt_mersenne.2 ?_).ne').two_le.lt_of_ne' ?_ · exact le_add_left _ _ · rw [Ne, minFac_eq_two_iff, mersenne, Nat.pow_succ'] exact Nat.two_not_dvd_two_mul_sub_one Nat.one_le_two_pow theorem ω_pow_formula (p' : ℕ) (h : lucasLehmerResidue (p' + 2) = 0) : ∃ k : ℤ, (ω : X (q (p' + 2))) ^ 2 ^ (p' + 1) = k * mersenne (p' + 2) * (ω : X (q (p' + 2))) ^ 2 ^ p' - 1 := by dsimp [lucasLehmerResidue] at h rw [sZMod_eq_s p'] at h simp? [ZMod.intCast_zmod_eq_zero_iff_dvd] at h says simp only [add_tsub_cancel_right, ZMod.intCast_zmod_eq_zero_iff_dvd, ofNat_pos, pow_pos, cast_pred, cast_pow, cast_ofNat] at h cases' h with k h use k replace h := congr_arg (fun n : ℤ => (n : X (q (p' + 2)))) h -- coercion from ℤ to X q dsimp at h rw [closed_form] at h replace h := congr_arg (fun x => ω ^ 2 ^ p' * x) h dsimp at h have t : 2 ^ p' + 2 ^ p' = 2 ^ (p' + 1) := by ring rw [mul_add, ← pow_add ω, t, ← mul_pow ω ωb (2 ^ p'), ω_mul_ωb, one_pow] at h rw [mul_comm, coe_mul] at h rw [mul_comm _ (k : X (q (p' + 2)))] at h replace h := eq_sub_of_add_eq h have : 1 ≤ 2 ^ (p' + 2) := Nat.one_le_pow _ _ (by decide) exact mod_cast h /-- `q` is the minimum factor of `mersenne p`, so `M p = 0` in `X q`. -/ theorem mersenne_coe_X (p : ℕ) : (mersenne p : X (q p)) = 0 := by ext <;> simp [mersenne, q, ZMod.natCast_zmod_eq_zero_iff_dvd, -pow_pos] apply Nat.minFac_dvd theorem ω_pow_eq_neg_one (p' : ℕ) (h : lucasLehmerResidue (p' + 2) = 0) : (ω : X (q (p' + 2))) ^ 2 ^ (p' + 1) = -1 := by cases' ω_pow_formula p' h with k w rw [mersenne_coe_X] at w simpa using w theorem ω_pow_eq_one (p' : ℕ) (h : lucasLehmerResidue (p' + 2) = 0) : (ω : X (q (p' + 2))) ^ 2 ^ (p' + 2) = 1 := calc (ω : X (q (p' + 2))) ^ 2 ^ (p' + 2) = (ω ^ 2 ^ (p' + 1)) ^ 2 := by rw [← pow_mul, ← Nat.pow_succ] _ = (-1) ^ 2 := by rw [ω_pow_eq_neg_one p' h] _ = 1 := by simp /-- `ω` as an element of the group of units. -/ def ωUnit (p : ℕ) : Units (X (q p)) where val := ω inv := ωb val_inv := ω_mul_ωb _ inv_val := ωb_mul_ω _ @[simp] theorem ωUnit_coe (p : ℕ) : (ωUnit p : X (q p)) = ω := rfl /-- The order of `ω` in the unit group is exactly `2^p`. -/ theorem order_ω (p' : ℕ) (h : lucasLehmerResidue (p' + 2) = 0) : orderOf (ωUnit (p' + 2)) = 2 ^ (p' + 2) := by apply Nat.eq_prime_pow_of_dvd_least_prime_pow -- the order of ω divides 2^p · exact Nat.prime_two · intro o have ω_pow := orderOf_dvd_iff_pow_eq_one.1 o replace ω_pow := congr_arg (Units.coeHom (X (q (p' + 2))) : Units (X (q (p' + 2))) → X (q (p' + 2))) ω_pow simp? at ω_pow says simp only [map_pow, Units.coeHom_apply, ωUnit_coe, map_one] at ω_pow have h : (1 : ZMod (q (p' + 2))) = -1 := congr_arg Prod.fst (ω_pow.symm.trans (ω_pow_eq_neg_one p' h)) haveI : Fact (2 < (q (p' + 2) : ℕ)) := ⟨two_lt_q _⟩ apply ZMod.neg_one_ne_one h.symm · apply orderOf_dvd_iff_pow_eq_one.2 apply Units.ext push_cast exact ω_pow_eq_one p' h theorem order_ineq (p' : ℕ) (h : lucasLehmerResidue (p' + 2) = 0) : 2 ^ (p' + 2) < (q (p' + 2) : ℕ) ^ 2 := calc 2 ^ (p' + 2) = orderOf (ωUnit (p' + 2)) := (order_ω p' h).symm _ ≤ Fintype.card (X (q (p' + 2)))ˣ := orderOf_le_card_univ _ < (q (p' + 2) : ℕ) ^ 2 := card_units_lt (Nat.lt_of_succ_lt (two_lt_q _)) end LucasLehmer export LucasLehmer (LucasLehmerTest lucasLehmerResidue) open LucasLehmer theorem lucas_lehmer_sufficiency (p : ℕ) (w : 1 < p) : LucasLehmerTest p → (mersenne p).Prime := by let p' := p - 2 have z : p = p' + 2 := (tsub_eq_iff_eq_add_of_le w.nat_succ_le).mp rfl have w : 1 < p' + 2 := Nat.lt_of_sub_eq_succ rfl contrapose intro a t rw [z] at a rw [z] at t have h₁ := order_ineq p' t have h₂ := Nat.minFac_sq_le_self (mersenne_pos.2 (Nat.lt_of_succ_lt w)) a have h := lt_of_lt_of_le h₁ h₂ exact not_lt_of_ge (Nat.sub_le _ _) h namespace LucasLehmer /-! ### `norm_num` extension Next we define a `norm_num` extension that calculates `LucasLehmerTest p` for `1 < p`. It makes use of a version of `sMod` that is specifically written to be reducible by the Lean 4 kernel, which has the capability of efficiently reducing natural number expressions. With this reduction in hand, it's a simple matter of applying the lemma `LucasLehmer.residue_eq_zero_iff_sMod_eq_zero`. See [Archive/Examples/MersennePrimes.lean] for certifications of all Mersenne primes up through `mersenne 4423`. -/ namespace norm_num_ext open Qq Lean Elab.Tactic Mathlib.Meta.NormNum /-- Version of `sMod` that is `ℕ`-valued. One should have `q = 2 ^ p - 1`. This can be reduced by the kernel. -/ def sMod' (q : ℕ) : ℕ → ℕ | 0 => 4 % q | i + 1 => (sMod' q i ^ 2 + (q - 2)) % q theorem sMod'_eq_sMod (p k : ℕ) (hp : 2 ≤ p) : (sMod' (2 ^ p - 1) k : ℤ) = sMod p k := by have h1 := calc 4 = 2 ^ 2 := by norm_num _ ≤ 2 ^ p := Nat.pow_le_pow_of_le_right (by norm_num) hp have h2 : 1 ≤ 2 ^ p := by omega induction k with | zero => rw [sMod', sMod, Int.ofNat_emod] simp [h2] | succ k ih => rw [sMod', sMod, ← ih] have h3 : 2 ≤ 2 ^ p - 1 := by zify [h2] calc (2 : Int) ≤ 4 - 1 := by norm_num _ ≤ 2 ^ p - 1 := by zify at h1; exact Int.sub_le_sub_right h1 _ zify [h2, h3] rw [← add_sub_assoc, sub_eq_add_neg, add_assoc, add_comm _ (-2), ← add_assoc, Int.add_emod_self, ← sub_eq_add_neg] lemma testTrueHelper (p : ℕ) (hp : Nat.blt 1 p = true) (h : sMod' (2 ^ p - 1) (p - 2) = 0) : LucasLehmerTest p := by rw [Nat.blt_eq] at hp rw [LucasLehmerTest, LucasLehmer.residue_eq_zero_iff_sMod_eq_zero p hp, ← sMod'_eq_sMod p _ hp, h] rfl lemma testFalseHelper (p : ℕ) (hp : Nat.blt 1 p = true) (h : Nat.ble 1 (sMod' (2 ^ p - 1) (p - 2))) : ¬ LucasLehmerTest p := by rw [Nat.blt_eq] at hp rw [Nat.ble_eq, Nat.succ_le, Nat.pos_iff_ne_zero] at h rw [LucasLehmerTest, LucasLehmer.residue_eq_zero_iff_sMod_eq_zero p hp, ← sMod'_eq_sMod p _ hp] simpa using h theorem isNat_lucasLehmerTest : {p np : ℕ} → IsNat p np → LucasLehmerTest np → LucasLehmerTest p | _, _, ⟨rfl⟩, h => h theorem isNat_not_lucasLehmerTest : {p np : ℕ} → IsNat p np → ¬ LucasLehmerTest np → ¬ LucasLehmerTest p | _, _, ⟨rfl⟩, h => h /-- Calculate `LucasLehmer.LucasLehmerTest p` for `2 ≤ p` by using kernel reduction for the `sMod'` function. -/ @[norm_num LucasLehmer.LucasLehmerTest (_ : ℕ)] def evalLucasLehmerTest : NormNumExt where eval {u α} e := do let .app _ (p : Q(ℕ)) ← Meta.whnfR e | failure let ⟨ep, hp⟩ ← deriveNat p _ let np := ep.natLit! unless 1 < np do failure haveI' h1ltp : Nat.blt 1 $ep =Q true := ⟨⟩ if sMod' (2 ^ np - 1) (np - 2) = 0 then haveI' hs : sMod' (2 ^ $ep - 1) ($ep - 2) =Q 0 := ⟨⟩ have pf : Q(LucasLehmerTest $ep) := q(testTrueHelper $ep $h1ltp $hs) have pf' : Q(LucasLehmerTest $p) := q(isNat_lucasLehmerTest $hp $pf) return .isTrue pf' else haveI' hs : Nat.ble 1 (sMod' (2 ^ $ep - 1) ($ep - 2)) =Q true := ⟨⟩ have pf : Q(¬ LucasLehmerTest $ep) := q(testFalseHelper $ep $h1ltp $hs) have pf' : Q(¬ LucasLehmerTest $p) := q(isNat_not_lucasLehmerTest $hp $pf) return .isFalse pf' end norm_num_ext end LucasLehmer /-! This implementation works successfully to prove `(2^4423 - 1).Prime`, and all the Mersenne primes up to this point appear in [Archive/Examples/MersennePrimes.lean]. These can be calculated nearly instantly, and `(2^9689 - 1).Prime` only fails due to deep recursion. (Note by kmill: the following notes were for the Lean 3 version. They seem like they could still be useful, so I'm leaving them here.) There's still low hanging fruit available to do faster computations based on the formula ``` n ≡ (n % 2^p) + (n / 2^p) [MOD 2^p - 1] ``` and the fact that `% 2^p` and `/ 2^p` can be very efficient on the binary representation. Someone should do this, too! -/ theorem modEq_mersenne (n k : ℕ) : k ≡ k / 2 ^ n + k % 2 ^ n [MOD 2 ^ n - 1] := -- See https://leanprover.zulipchat.com/#narrow/stream/113489-new-members/topic/help.20finding.20a.20lemma/near/177698446 calc k = 2 ^ n * (k / 2 ^ n) + k % 2 ^ n := (Nat.div_add_mod k (2 ^ n)).symm _ ≡ 1 * (k / 2 ^ n) + k % 2 ^ n [MOD 2 ^ n - 1] := ((Nat.modEq_sub <| Nat.succ_le_of_lt <| pow_pos zero_lt_two _).mul_right _).add_right _ _ = k / 2 ^ n + k % 2 ^ n := by rw [one_mul] -- It's hard to know what the limiting factor for large Mersenne primes would be. -- In the purely computational world, I think it's the squaring operation in `s`.
NumberTheory\LucasPrimality.lean
/- Copyright (c) 2020 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey -/ import Mathlib.Data.Fintype.Basic import Mathlib.GroupTheory.OrderOfElement import Mathlib.Tactic.Zify import Mathlib.Data.Nat.Totient /-! # The Lucas test for primes. This file implements the Lucas test for primes (not to be confused with the Lucas-Lehmer test for Mersenne primes). A number `a` witnesses that `n` is prime if `a` has order `n-1` in the multiplicative group of integers mod `n`. This is checked by verifying that `a^(n-1) = 1 (mod n)` and `a^d ≠ 1 (mod n)` for any divisor `d | n - 1`. This test is the basis of the Pratt primality certificate. ## TODO - Bonus: Show the reverse implication i.e. if a number is prime then it has a Lucas witness. Use `Units.IsCyclic` from `RingTheory/IntegralDomain` to show the group is cyclic. - Write a tactic that uses this theorem to generate Pratt primality certificates - Integrate Pratt primality certificates into the norm_num primality verifier ## Implementation notes Note that the proof for `lucas_primality` relies on analyzing the multiplicative group modulo `p`. Despite this, the theorem still holds vacuously for `p = 0` and `p = 1`: In these cases, we can take `q` to be any prime and see that `hd` does not hold, since `a^((p-1)/q)` reduces to `1`. -/ /-- If `a^(p-1) = 1 mod p`, but `a^((p-1)/q) ≠ 1 mod p` for all prime factors `q` of `p-1`, then `p` is prime. This is true because `a` has order `p-1` in the multiplicative group mod `p`, so this group must itself have order `p-1`, which only happens when `p` is prime. -/ theorem lucas_primality (p : ℕ) (a : ZMod p) (ha : a ^ (p - 1) = 1) (hd : ∀ q : ℕ, q.Prime → q ∣ p - 1 → a ^ ((p - 1) / q) ≠ 1) : p.Prime := by have h0 : p ≠ 0 := by rintro ⟨⟩ exact hd 2 Nat.prime_two (dvd_zero _) (pow_zero _) have h1 : p ≠ 1 := by rintro ⟨⟩ exact hd 2 Nat.prime_two (dvd_zero _) (pow_zero _) have hp1 : 1 < p := lt_of_le_of_ne h0.bot_lt h1.symm have order_of_a : orderOf a = p - 1 := by apply orderOf_eq_of_pow_and_pow_div_prime _ ha hd exact tsub_pos_of_lt hp1 haveI : NeZero p := ⟨h0⟩ rw [Nat.prime_iff_card_units] -- Prove cardinality of `Units` of `ZMod p` is both `≤ p-1` and `≥ p-1` refine le_antisymm (Nat.card_units_zmod_lt_sub_one hp1) ?_ have hp' : p - 2 + 1 = p - 1 := tsub_add_eq_add_tsub hp1 let a' : (ZMod p)ˣ := Units.mkOfMulEqOne a (a ^ (p - 2)) (by rw [← pow_succ', hp', ha]) calc p - 1 = orderOf a := order_of_a.symm _ = orderOf a' := (orderOf_injective (Units.coeHom (ZMod p)) Units.ext a') _ ≤ Fintype.card (ZMod p)ˣ := orderOf_le_card_univ
NumberTheory\MaricaSchoenheim.lean
/- Copyright (c) 2023 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Combinatorics.SetFamily.FourFunctions import Mathlib.Data.Nat.Squarefree /-! # The Marica-Schönheim special case of Graham's conjecture Graham's conjecture states that if $0 < a_1 < \dots a_n$ are integers, then $\max_{i, j} \frac{a_i}{\gcd(a_i, a_j)} \ge n$. This file proves the conjecture when the $a_i$ are squarefree as a corollary of the Marica-Schönheim inequality. ## References [*Applications of the FKG Inequality and Its Relatives*, Graham][Graham1983] -/ open Finset open scoped FinsetFamily namespace Nat /-- Statement of Graham's conjecture (which is now a theorem in the literature). Graham's conjecture states that if $0 < a_1 < \dots a_n$ are integers, then $\max_{i, j} \frac{a_i}{\gcd(a_i, a_j)} \ge n$. -/ def GrahamConjecture (n : ℕ) (f : ℕ → ℕ) : Prop := n ≠ 0 → StrictMonoOn f (Set.Iio n) → ∃ i < n, ∃ j < n, (f i).gcd (f j) * n ≤ f i /-- The special case of Graham's conjecture where all numbers are squarefree. -/ lemma grahamConjecture_of_squarefree {n : ℕ} (f : ℕ → ℕ) (hf' : ∀ k < n, Squarefree (f k)) : GrahamConjecture n f := by rintro hn hf by_contra! set 𝒜 := (Iio n).image fun n ↦ primeFactors (f n) have hf'' : ∀ i < n, ∀ j, Squarefree (f i / (f i).gcd (f j)) := fun i hi j ↦ (hf' _ hi).squarefree_of_dvd <| div_dvd_of_dvd <| gcd_dvd_left _ _ refine lt_irrefl n ?_ calc n = 𝒜.card := ?_ _ ≤ (𝒜 \\ 𝒜).card := 𝒜.card_le_card_diffs _ ≤ (Ioo 0 n).card := card_le_card_of_injOn (fun s ↦ ∏ p ∈ s, p) ?_ ?_ _ = n - 1 := by rw [card_Ioo, tsub_zero] _ < n := tsub_lt_self hn.bot_lt zero_lt_one · rw [Finset.card_image_of_injOn, card_Iio] simpa using prod_primeFactors_invOn_squarefree.2.injOn.comp hf.injOn hf' · simp only [forall_mem_diffs, forall_image, mem_Ioo, mem_Iio] rintro i hi j hj rw [← primeFactors_div_gcd (hf' _ hi) (hf' _ hj).ne_zero, prod_primeFactors_of_squarefree <| hf'' _ hi _] exact ⟨Nat.div_pos (gcd_le_left _ (hf' _ hi).ne_zero.bot_lt) <| Nat.gcd_pos_of_pos_left _ (hf' _ hi).ne_zero.bot_lt, Nat.div_lt_of_lt_mul <| this _ hi _ hj⟩ · simp only [Set.InjOn, mem_coe, forall_mem_diffs, forall_image, mem_Ioo, mem_Iio] rintro a ha b hb c hc d hd rw [← primeFactors_div_gcd (hf' _ ha) (hf' _ hb).ne_zero, ← primeFactors_div_gcd (hf' _ hc) (hf' _ hd).ne_zero, prod_primeFactors_of_squarefree (hf'' _ ha _), prod_primeFactors_of_squarefree (hf'' _ hc _)] rintro h rw [h] end Nat
NumberTheory\Modular.lean
/- Copyright (c) 2021 Alex Kontorovich and Heather Macbeth and Marc Masdeu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alex Kontorovich, Heather Macbeth, Marc Masdeu -/ import Mathlib.Analysis.Complex.UpperHalfPlane.Basic import Mathlib.LinearAlgebra.GeneralLinearGroup import Mathlib.LinearAlgebra.Matrix.GeneralLinearGroup.Basic import Mathlib.Topology.Instances.Matrix import Mathlib.Topology.Algebra.Module.FiniteDimension /-! # The action of the modular group SL(2, ℤ) on the upper half-plane We define the action of `SL(2,ℤ)` on `ℍ` (via restriction of the `SL(2,ℝ)` action in `Analysis.Complex.UpperHalfPlane`). We then define the standard fundamental domain (`ModularGroup.fd`, `𝒟`) for this action and show (`ModularGroup.exists_smul_mem_fd`) that any point in `ℍ` can be moved inside `𝒟`. ## Main definitions The standard (closed) fundamental domain of the action of `SL(2,ℤ)` on `ℍ`, denoted `𝒟`: `fd := {z | 1 ≤ (z : ℂ).normSq ∧ |z.re| ≤ (1 : ℝ) / 2}` The standard open fundamental domain of the action of `SL(2,ℤ)` on `ℍ`, denoted `𝒟ᵒ`: `fdo := {z | 1 < (z : ℂ).normSq ∧ |z.re| < (1 : ℝ) / 2}` These notations are localized in the `Modular` locale and can be enabled via `open scoped Modular`. ## Main results Any `z : ℍ` can be moved to `𝒟` by an element of `SL(2,ℤ)`: `exists_smul_mem_fd (z : ℍ) : ∃ g : SL(2,ℤ), g • z ∈ 𝒟` If both `z` and `γ • z` are in the open domain `𝒟ᵒ` then `z = γ • z`: `eq_smul_self_of_mem_fdo_mem_fdo {z : ℍ} {g : SL(2,ℤ)} (hz : z ∈ 𝒟ᵒ) (hg : g • z ∈ 𝒟ᵒ) : z = g • z` # Discussion Standard proofs make use of the identity `g • z = a / c - 1 / (c (cz + d))` for `g = [[a, b], [c, d]]` in `SL(2)`, but this requires separate handling of whether `c = 0`. Instead, our proof makes use of the following perhaps novel identity (see `ModularGroup.smul_eq_lcRow0_add`): `g • z = (a c + b d) / (c^2 + d^2) + (d z - c) / ((c^2 + d^2) (c z + d))` where there is no issue of division by zero. Another feature is that we delay until the very end the consideration of special matrices `T=[[1,1],[0,1]]` (see `ModularGroup.T`) and `S=[[0,-1],[1,0]]` (see `ModularGroup.S`), by instead using abstract theory on the properness of certain maps (phrased in terms of the filters `Filter.cocompact`, `Filter.cofinite`, etc) to deduce existence theorems, first to prove the existence of `g` maximizing `(g•z).im` (see `ModularGroup.exists_max_im`), and then among those, to minimize `|(g•z).re|` (see `ModularGroup.exists_row_one_eq_and_min_re`). -/ open Complex hiding abs_two open Matrix hiding mul_smul open Matrix.SpecialLinearGroup UpperHalfPlane ModularGroup noncomputable section local notation "SL(" n ", " R ")" => SpecialLinearGroup (Fin n) R local macro "↑ₘ" t:term:80 : term => `(term| ($t : Matrix (Fin 2) (Fin 2) ℤ)) open scoped UpperHalfPlane ComplexConjugate namespace ModularGroup variable {g : SL(2, ℤ)} (z : ℍ) section BottomRow /-- The two numbers `c`, `d` in the "bottom_row" of `g=[[*,*],[c,d]]` in `SL(2, ℤ)` are coprime. -/ theorem bottom_row_coprime {R : Type*} [CommRing R] (g : SL(2, R)) : IsCoprime ((↑g : Matrix (Fin 2) (Fin 2) R) 1 0) ((↑g : Matrix (Fin 2) (Fin 2) R) 1 1) := by use -(↑g : Matrix (Fin 2) (Fin 2) R) 0 1, (↑g : Matrix (Fin 2) (Fin 2) R) 0 0 rw [add_comm, neg_mul, ← sub_eq_add_neg, ← det_fin_two] exact g.det_coe /-- Every pair `![c, d]` of coprime integers is the "bottom_row" of some element `g=[[*,*],[c,d]]` of `SL(2,ℤ)`. -/ theorem bottom_row_surj {R : Type*} [CommRing R] : Set.SurjOn (fun g : SL(2, R) => (↑g : Matrix (Fin 2) (Fin 2) R) 1) Set.univ {cd | IsCoprime (cd 0) (cd 1)} := by rintro cd ⟨b₀, a, gcd_eqn⟩ let A := of ![![a, -b₀], cd] have det_A_1 : det A = 1 := by convert gcd_eqn rw [det_fin_two] simp [A, (by ring : a * cd 1 + b₀ * cd 0 = b₀ * cd 0 + a * cd 1)] refine ⟨⟨A, det_A_1⟩, Set.mem_univ _, ?_⟩ ext; simp [A] end BottomRow section TendstoLemmas open Filter ContinuousLinearMap attribute [local simp] ContinuousLinearMap.coe_smul /-- The function `(c,d) → |cz+d|^2` is proper, that is, preimages of bounded-above sets are finite. -/ theorem tendsto_normSq_coprime_pair : Filter.Tendsto (fun p : Fin 2 → ℤ => normSq ((p 0 : ℂ) * z + p 1)) cofinite atTop := by -- using this instance rather than the automatic `Function.module` makes unification issues in -- `LinearEquiv.closedEmbedding_of_injective` less bad later in the proof. letI : Module ℝ (Fin 2 → ℝ) := NormedSpace.toModule let π₀ : (Fin 2 → ℝ) →ₗ[ℝ] ℝ := LinearMap.proj 0 let π₁ : (Fin 2 → ℝ) →ₗ[ℝ] ℝ := LinearMap.proj 1 let f : (Fin 2 → ℝ) →ₗ[ℝ] ℂ := π₀.smulRight (z : ℂ) + π₁.smulRight 1 have f_def : ⇑f = fun p : Fin 2 → ℝ => (p 0 : ℂ) * ↑z + p 1 := by ext1 dsimp only [π₀, π₁, f, LinearMap.coe_proj, real_smul, LinearMap.coe_smulRight, LinearMap.add_apply] rw [mul_one] have : (fun p : Fin 2 → ℤ => normSq ((p 0 : ℂ) * ↑z + ↑(p 1))) = normSq ∘ f ∘ fun p : Fin 2 → ℤ => ((↑) : ℤ → ℝ) ∘ p := by ext1 rw [f_def] dsimp only [Function.comp_def] rw [ofReal_intCast, ofReal_intCast] rw [this] have hf : LinearMap.ker f = ⊥ := by let g : ℂ →ₗ[ℝ] Fin 2 → ℝ := LinearMap.pi ![imLm, imLm.comp ((z : ℂ) • ((conjAe : ℂ →ₐ[ℝ] ℂ) : ℂ →ₗ[ℝ] ℂ))] suffices ((z : ℂ).im⁻¹ • g).comp f = LinearMap.id by exact LinearMap.ker_eq_bot_of_inverse this apply LinearMap.ext intro c have hz : (z : ℂ).im ≠ 0 := z.2.ne' rw [LinearMap.comp_apply, LinearMap.smul_apply, LinearMap.id_apply] ext i dsimp only [Pi.smul_apply, LinearMap.pi_apply, smul_eq_mul] fin_cases i · show (z : ℂ).im⁻¹ * (f c).im = c 0 rw [f_def, add_im, im_ofReal_mul, ofReal_im, add_zero, mul_left_comm, inv_mul_cancel hz, mul_one] · show (z : ℂ).im⁻¹ * ((z : ℂ) * conj (f c)).im = c 1 rw [f_def, RingHom.map_add, RingHom.map_mul, mul_add, mul_left_comm, mul_conj, conj_ofReal, conj_ofReal, ← ofReal_mul, add_im, ofReal_im, zero_add, inv_mul_eq_iff_eq_mul₀ hz] simp only [ofReal_im, ofReal_re, mul_im, zero_add, mul_zero] have hf' : ClosedEmbedding f := f.closedEmbedding_of_injective hf have h₂ : Tendsto (fun p : Fin 2 → ℤ => ((↑) : ℤ → ℝ) ∘ p) cofinite (cocompact _) := by convert Tendsto.pi_map_coprodᵢ fun _ => Int.tendsto_coe_cofinite · rw [coprodᵢ_cofinite] · rw [coprodᵢ_cocompact] exact tendsto_normSq_cocompact_atTop.comp (hf'.tendsto_cocompact.comp h₂) /-- Given `coprime_pair` `p=(c,d)`, the matrix `[[a,b],[*,*]]` is sent to `a*c+b*d`. This is the linear map version of this operation. -/ def lcRow0 (p : Fin 2 → ℤ) : Matrix (Fin 2) (Fin 2) ℝ →ₗ[ℝ] ℝ := ((p 0 : ℝ) • LinearMap.proj (0 : Fin 2) + (p 1 : ℝ) • LinearMap.proj (1 : Fin 2) : (Fin 2 → ℝ) →ₗ[ℝ] ℝ).comp (LinearMap.proj 0) @[simp] theorem lcRow0_apply (p : Fin 2 → ℤ) (g : Matrix (Fin 2) (Fin 2) ℝ) : lcRow0 p g = p 0 * g 0 0 + p 1 * g 0 1 := rfl /-- Linear map sending the matrix [a, b; c, d] to the matrix [ac₀ + bd₀, - ad₀ + bc₀; c, d], for some fixed `(c₀, d₀)`. -/ @[simps!] def lcRow0Extend {cd : Fin 2 → ℤ} (hcd : IsCoprime (cd 0) (cd 1)) : Matrix (Fin 2) (Fin 2) ℝ ≃ₗ[ℝ] Matrix (Fin 2) (Fin 2) ℝ := LinearEquiv.piCongrRight ![by refine LinearMap.GeneralLinearGroup.generalLinearEquiv ℝ (Fin 2 → ℝ) (GeneralLinearGroup.toLinear (planeConformalMatrix (cd 0 : ℝ) (-(cd 1 : ℝ)) ?_)) norm_cast rw [neg_sq] exact hcd.sq_add_sq_ne_zero, LinearEquiv.refl ℝ (Fin 2 → ℝ)] -- `simpNF` times out, but only in CI where all of `Mathlib` is imported attribute [nolint simpNF] lcRow0Extend_apply lcRow0Extend_symm_apply /-- The map `lcRow0` is proper, that is, preimages of cocompact sets are finite in `[[* , *], [c, d]]`. -/ theorem tendsto_lcRow0 {cd : Fin 2 → ℤ} (hcd : IsCoprime (cd 0) (cd 1)) : Tendsto (fun g : { g : SL(2, ℤ) // (↑ₘg) 1 = cd } => lcRow0 cd ↑(↑g : SL(2, ℝ))) cofinite (cocompact ℝ) := by let mB : ℝ → Matrix (Fin 2) (Fin 2) ℝ := fun t => of ![![t, (-(1 : ℤ) : ℝ)], (↑) ∘ cd] have hmB : Continuous mB := by refine continuous_matrix ?_ simp only [mB, Fin.forall_fin_two, continuous_const, continuous_id', of_apply, cons_val_zero, cons_val_one, and_self_iff] refine Filter.Tendsto.of_tendsto_comp ?_ (comap_cocompact_le hmB) let f₁ : SL(2, ℤ) → Matrix (Fin 2) (Fin 2) ℝ := fun g => Matrix.map (↑g : Matrix _ _ ℤ) ((↑) : ℤ → ℝ) have cocompact_ℝ_to_cofinite_ℤ_matrix : Tendsto (fun m : Matrix (Fin 2) (Fin 2) ℤ => Matrix.map m ((↑) : ℤ → ℝ)) cofinite (cocompact _) := by simpa only [coprodᵢ_cofinite, coprodᵢ_cocompact] using Tendsto.pi_map_coprodᵢ fun _ : Fin 2 => Tendsto.pi_map_coprodᵢ fun _ : Fin 2 => Int.tendsto_coe_cofinite have hf₁ : Tendsto f₁ cofinite (cocompact _) := cocompact_ℝ_to_cofinite_ℤ_matrix.comp Subtype.coe_injective.tendsto_cofinite have hf₂ : ClosedEmbedding (lcRow0Extend hcd) := (lcRow0Extend hcd).toContinuousLinearEquiv.toHomeomorph.closedEmbedding convert hf₂.tendsto_cocompact.comp (hf₁.comp Subtype.coe_injective.tendsto_cofinite) using 1 ext ⟨g, rfl⟩ i j : 3 fin_cases i <;> [fin_cases j; skip] -- the following are proved by `simp`, but it is replaced by `simp only` to avoid timeouts. · simp only [mB, mulVec, dotProduct, Fin.sum_univ_two, coe_matrix_coe, Int.coe_castRingHom, lcRow0_apply, Function.comp_apply, cons_val_zero, lcRow0Extend_apply, LinearMap.GeneralLinearGroup.coeFn_generalLinearEquiv, GeneralLinearGroup.coe_toLinear, val_planeConformalMatrix, neg_neg, mulVecLin_apply, cons_val_one, head_cons, of_apply, Fin.mk_zero, Fin.mk_one] · convert congr_arg (fun n : ℤ => (-n : ℝ)) g.det_coe.symm using 1 simp only [f₁, mulVec, dotProduct, Fin.sum_univ_two, Matrix.det_fin_two, Function.comp_apply, Subtype.coe_mk, lcRow0Extend_apply, cons_val_zero, LinearMap.GeneralLinearGroup.coeFn_generalLinearEquiv, GeneralLinearGroup.coe_toLinear, val_planeConformalMatrix, mulVecLin_apply, cons_val_one, head_cons, map_apply, neg_mul, Int.cast_sub, Int.cast_mul, neg_sub, of_apply, Fin.mk_zero, Fin.mk_one] ring · rfl /-- This replaces `(g•z).re = a/c + *` in the standard theory with the following novel identity: `g • z = (a c + b d) / (c^2 + d^2) + (d z - c) / ((c^2 + d^2) (c z + d))` which does not need to be decomposed depending on whether `c = 0`. -/ theorem smul_eq_lcRow0_add {p : Fin 2 → ℤ} (hp : IsCoprime (p 0) (p 1)) (hg : (↑ₘg) 1 = p) : ↑(g • z) = (lcRow0 p ↑(g : SL(2, ℝ)) : ℂ) / ((p 0 : ℂ) ^ 2 + (p 1 : ℂ) ^ 2) + ((p 1 : ℂ) * z - p 0) / (((p 0 : ℂ) ^ 2 + (p 1 : ℂ) ^ 2) * (p 0 * z + p 1)) := by have nonZ1 : (p 0 : ℂ) ^ 2 + (p 1 : ℂ) ^ 2 ≠ 0 := mod_cast hp.sq_add_sq_ne_zero have : ((↑) : ℤ → ℝ) ∘ p ≠ 0 := fun h => hp.ne_zero (by ext i; simpa using congr_fun h i) have nonZ2 : (p 0 : ℂ) * z + p 1 ≠ 0 := by simpa using linear_ne_zero _ z this field_simp [nonZ1, nonZ2, denom_ne_zero, num] rw [(by simp : (p 1 : ℂ) * z - p 0 = (p 1 * z - p 0) * ↑(Matrix.det (↑g : Matrix (Fin 2) (Fin 2) ℤ)))] rw [← hg, det_fin_two] simp only [Int.coe_castRingHom, coe_matrix_coe, Int.cast_mul, ofReal_intCast, map_apply, denom, Int.cast_sub, coe_GLPos_coe_GL_coe_matrix, coe'_apply_complex] ring theorem tendsto_abs_re_smul {p : Fin 2 → ℤ} (hp : IsCoprime (p 0) (p 1)) : Tendsto (fun g : { g : SL(2, ℤ) // (↑ₘg) 1 = p } => |((g : SL(2, ℤ)) • z).re|) cofinite atTop := by suffices Tendsto (fun g : (fun g : SL(2, ℤ) => (↑ₘg) 1) ⁻¹' {p} => ((g : SL(2, ℤ)) • z).re) cofinite (cocompact ℝ) by exact tendsto_norm_cocompact_atTop.comp this have : ((p 0 : ℝ) ^ 2 + (p 1 : ℝ) ^ 2)⁻¹ ≠ 0 := by apply inv_ne_zero exact mod_cast hp.sq_add_sq_ne_zero let f := Homeomorph.mulRight₀ _ this let ff := Homeomorph.addRight (((p 1 : ℂ) * z - p 0) / (((p 0 : ℂ) ^ 2 + (p 1 : ℂ) ^ 2) * (p 0 * z + p 1))).re convert (f.trans ff).closedEmbedding.tendsto_cocompact.comp (tendsto_lcRow0 hp) with _ _ g change ((g : SL(2, ℤ)) • z).re = lcRow0 p ↑(↑g : SL(2, ℝ)) / ((p 0 : ℝ) ^ 2 + (p 1 : ℝ) ^ 2) + Complex.re (((p 1 : ℂ) * z - p 0) / (((p 0 : ℂ) ^ 2 + (p 1 : ℂ) ^ 2) * (p 0 * z + p 1))) exact mod_cast congr_arg Complex.re (smul_eq_lcRow0_add z hp g.2) end TendstoLemmas section FundamentalDomain attribute [local simp] UpperHalfPlane.coe_smul re_smul /-- For `z : ℍ`, there is a `g : SL(2,ℤ)` maximizing `(g•z).im` -/ theorem exists_max_im : ∃ g : SL(2, ℤ), ∀ g' : SL(2, ℤ), (g' • z).im ≤ (g • z).im := by classical let s : Set (Fin 2 → ℤ) := {cd | IsCoprime (cd 0) (cd 1)} have hs : s.Nonempty := ⟨![1, 1], isCoprime_one_left⟩ obtain ⟨p, hp_coprime, hp⟩ := Filter.Tendsto.exists_within_forall_le hs (tendsto_normSq_coprime_pair z) obtain ⟨g, -, hg⟩ := bottom_row_surj hp_coprime refine ⟨g, fun g' => ?_⟩ rw [ModularGroup.im_smul_eq_div_normSq, ModularGroup.im_smul_eq_div_normSq, div_le_div_left] · simpa [← hg] using hp ((↑ₘg') 1) (bottom_row_coprime g') · exact z.im_pos · exact normSq_denom_pos g' z · exact normSq_denom_pos g z /-- Given `z : ℍ` and a bottom row `(c,d)`, among the `g : SL(2,ℤ)` with this bottom row, minimize `|(g•z).re|`. -/ theorem exists_row_one_eq_and_min_re {cd : Fin 2 → ℤ} (hcd : IsCoprime (cd 0) (cd 1)) : ∃ g : SL(2, ℤ), (↑ₘg) 1 = cd ∧ ∀ g' : SL(2, ℤ), (↑ₘg) 1 = (↑ₘg') 1 → |(g • z).re| ≤ |(g' • z).re| := by haveI : Nonempty { g : SL(2, ℤ) // (↑ₘg) 1 = cd } := let ⟨x, hx⟩ := bottom_row_surj hcd ⟨⟨x, hx.2⟩⟩ obtain ⟨g, hg⟩ := Filter.Tendsto.exists_forall_le (tendsto_abs_re_smul z hcd) refine ⟨g, g.2, ?_⟩ intro g1 hg1 have : g1 ∈ (fun g : SL(2, ℤ) => (↑ₘg) 1) ⁻¹' {cd} := by rw [Set.mem_preimage, Set.mem_singleton_iff] exact Eq.trans hg1.symm (Set.mem_singleton_iff.mp (Set.mem_preimage.mp g.2)) exact hg ⟨g1, this⟩ theorem coe_T_zpow_smul_eq {n : ℤ} : (↑(T ^ n • z) : ℂ) = z + n := by rw [sl_moeb, UpperHalfPlane.coe_smul] simp [coe_T_zpow, denom, num, -map_zpow] theorem re_T_zpow_smul (n : ℤ) : (T ^ n • z).re = z.re + n := by rw [← coe_re, coe_T_zpow_smul_eq, add_re, intCast_re, coe_re] theorem im_T_zpow_smul (n : ℤ) : (T ^ n • z).im = z.im := by rw [← coe_im, coe_T_zpow_smul_eq, add_im, intCast_im, add_zero, coe_im] theorem re_T_smul : (T • z).re = z.re + 1 := by simpa using re_T_zpow_smul z 1 theorem im_T_smul : (T • z).im = z.im := by simpa using im_T_zpow_smul z 1 theorem re_T_inv_smul : (T⁻¹ • z).re = z.re - 1 := by simpa using re_T_zpow_smul z (-1) theorem im_T_inv_smul : (T⁻¹ • z).im = z.im := by simpa using im_T_zpow_smul z (-1) variable {z} -- If instead we had `g` and `T` of type `PSL(2, ℤ)`, then we could simply state `g = T^n`. theorem exists_eq_T_zpow_of_c_eq_zero (hc : (↑ₘg) 1 0 = 0) : ∃ n : ℤ, ∀ z : ℍ, g • z = T ^ n • z := by have had := g.det_coe replace had : (↑ₘg) 0 0 * (↑ₘg) 1 1 = 1 := by rw [det_fin_two, hc] at had; linarith rcases Int.eq_one_or_neg_one_of_mul_eq_one' had with (⟨ha, hd⟩ | ⟨ha, hd⟩) · use (↑ₘg) 0 1 suffices g = T ^ (↑ₘg) 0 1 by intro z; conv_lhs => rw [this] ext i j; fin_cases i <;> fin_cases j <;> simp [ha, hc, hd, coe_T_zpow, show (1 : Fin (0 + 2)) = (1 : Fin 2) from rfl] · use -((↑ₘg) 0 1) suffices g = -T ^ (-((↑ₘg) 0 1)) by intro z; conv_lhs => rw [this, SL_neg_smul] ext i j; fin_cases i <;> fin_cases j <;> simp [ha, hc, hd, coe_T_zpow, show (1 : Fin (0 + 2)) = (1 : Fin 2) from rfl] -- If `c = 1`, then `g` factorises into a product terms involving only `T` and `S`. theorem g_eq_of_c_eq_one (hc : (↑ₘg) 1 0 = 1) : g = T ^ (↑ₘg) 0 0 * S * T ^ (↑ₘg) 1 1 := by have hg := g.det_coe.symm replace hg : (↑ₘg) 0 1 = (↑ₘg) 0 0 * (↑ₘg) 1 1 - 1 := by rw [det_fin_two, hc] at hg; linarith refine Subtype.ext ?_ conv_lhs => rw [Matrix.eta_fin_two (↑ₘg)] rw [hc, hg] simp only [coe_mul, coe_T_zpow, coe_S, mul_fin_two] congrm !![?_, ?_; ?_, ?_] <;> ring /-- If `1 < |z|`, then `|S • z| < 1`. -/ theorem normSq_S_smul_lt_one (h : 1 < normSq z) : normSq ↑(S • z) < 1 := by simpa [coe_S, num, denom] using (inv_lt_inv z.normSq_pos zero_lt_one).mpr h /-- If `|z| < 1`, then applying `S` strictly decreases `im`. -/ theorem im_lt_im_S_smul (h : normSq z < 1) : z.im < (S • z).im := by have : z.im < z.im / normSq (z : ℂ) := by have imz : 0 < z.im := im_pos z apply (lt_div_iff z.normSq_pos).mpr nlinarith convert this simp only [ModularGroup.im_smul_eq_div_normSq] simp [denom, coe_S] /-- The standard (closed) fundamental domain of the action of `SL(2,ℤ)` on `ℍ`. -/ def fd : Set ℍ := {z | 1 ≤ normSq (z : ℂ) ∧ |z.re| ≤ (1 : ℝ) / 2} /-- The standard open fundamental domain of the action of `SL(2,ℤ)` on `ℍ`. -/ def fdo : Set ℍ := {z | 1 < normSq (z : ℂ) ∧ |z.re| < (1 : ℝ) / 2} @[inherit_doc ModularGroup.fd] scoped[Modular] notation "𝒟" => ModularGroup.fd @[inherit_doc ModularGroup.fdo] scoped[Modular] notation "𝒟ᵒ" => ModularGroup.fdo open scoped Modular theorem abs_two_mul_re_lt_one_of_mem_fdo (h : z ∈ 𝒟ᵒ) : |2 * z.re| < 1 := by rw [abs_mul, abs_two, ← lt_div_iff' (zero_lt_two' ℝ)] exact h.2 theorem three_lt_four_mul_im_sq_of_mem_fdo (h : z ∈ 𝒟ᵒ) : 3 < 4 * z.im ^ 2 := by have : 1 < z.re * z.re + z.im * z.im := by simpa [Complex.normSq_apply] using h.1 have := h.2 cases abs_cases z.re <;> nlinarith /-- If `z ∈ 𝒟ᵒ`, and `n : ℤ`, then `|z + n| > 1`. -/ theorem one_lt_normSq_T_zpow_smul (hz : z ∈ 𝒟ᵒ) (n : ℤ) : 1 < normSq (T ^ n • z : ℍ) := by have hz₁ : 1 < z.re * z.re + z.im * z.im := hz.1 have hzn := Int.nneg_mul_add_sq_of_abs_le_one n (abs_two_mul_re_lt_one_of_mem_fdo hz).le have : 1 < (z.re + ↑n) * (z.re + ↑n) + z.im * z.im := by linarith simpa [coe_T_zpow, normSq, num, denom, -map_zpow] theorem eq_zero_of_mem_fdo_of_T_zpow_mem_fdo {n : ℤ} (hz : z ∈ 𝒟ᵒ) (hg : T ^ n • z ∈ 𝒟ᵒ) : n = 0 := by suffices |(n : ℝ)| < 1 by rwa [← Int.cast_abs, ← Int.cast_one, Int.cast_lt, Int.abs_lt_one_iff] at this have h₁ := hz.2 have h₂ := hg.2 rw [re_T_zpow_smul] at h₂ calc |(n : ℝ)| ≤ |z.re| + |z.re + (n : ℝ)| := abs_add' (n : ℝ) z.re _ < 1 / 2 + 1 / 2 := add_lt_add h₁ h₂ _ = 1 := add_halves 1 /-- First Fundamental Domain Lemma: Any `z : ℍ` can be moved to `𝒟` by an element of `SL(2,ℤ)` -/ theorem exists_smul_mem_fd (z : ℍ) : ∃ g : SL(2, ℤ), g • z ∈ 𝒟 := by -- obtain a g₀ which maximizes im (g • z), obtain ⟨g₀, hg₀⟩ := exists_max_im z -- then among those, minimize re obtain ⟨g, hg, hg'⟩ := exists_row_one_eq_and_min_re z (bottom_row_coprime g₀) refine ⟨g, ?_⟩ -- `g` has same max im property as `g₀` have hg₀' : ∀ g' : SL(2, ℤ), (g' • z).im ≤ (g • z).im := by have hg'' : (g • z).im = (g₀ • z).im := by rw [ModularGroup.im_smul_eq_div_normSq, ModularGroup.im_smul_eq_div_normSq, denom_apply, denom_apply, hg] simpa only [hg''] using hg₀ constructor · -- Claim: `1 ≤ ⇑norm_sq ↑(g • z)`. If not, then `S•g•z` has larger imaginary part contrapose! hg₀' refine ⟨S * g, ?_⟩ rw [mul_smul] exact im_lt_im_S_smul hg₀' · show |(g • z).re| ≤ 1 / 2 -- if not, then either `T` or `T'` decrease |Re|. rw [abs_le] constructor · contrapose! hg' refine ⟨T * g, (T_mul_apply_one _).symm, ?_⟩ rw [mul_smul, re_T_smul] cases abs_cases ((g • z).re + 1) <;> cases abs_cases (g • z).re <;> linarith · contrapose! hg' refine ⟨T⁻¹ * g, (T_inv_mul_apply_one _).symm, ?_⟩ rw [mul_smul, re_T_inv_smul] cases abs_cases ((g • z).re - 1) <;> cases abs_cases (g • z).re <;> linarith section UniqueRepresentative /-- An auxiliary result en route to `ModularGroup.c_eq_zero`. -/ theorem abs_c_le_one (hz : z ∈ 𝒟ᵒ) (hg : g • z ∈ 𝒟ᵒ) : |(↑ₘg) 1 0| ≤ 1 := by let c' : ℤ := (↑ₘg) 1 0 let c : ℝ := (c' : ℝ) suffices 3 * c ^ 2 < 4 by rw [← Int.cast_pow, ← Int.cast_three, ← Int.cast_four, ← Int.cast_mul, Int.cast_lt] at this replace this : c' ^ 2 ≤ 1 ^ 2 := by linarith rwa [sq_le_sq, abs_one] at this suffices c ≠ 0 → 9 * c ^ 4 < 16 by rcases eq_or_ne c 0 with (hc | hc) · rw [hc]; norm_num · refine (abs_lt_of_sq_lt_sq' ?_ (by norm_num)).2 specialize this hc linarith intro hc replace hc : 0 < c ^ 4 := by change 0 < c ^ (2 * 2); rw [pow_mul]; apply sq_pos_of_pos (sq_pos_of_ne_zero hc) have h₁ := mul_lt_mul_of_pos_right (mul_lt_mul'' (three_lt_four_mul_im_sq_of_mem_fdo hg) (three_lt_four_mul_im_sq_of_mem_fdo hz) (by linarith) (by linarith)) hc have h₂ : (c * z.im) ^ 4 / normSq (denom (↑g) z) ^ 2 ≤ 1 := div_le_one_of_le (pow_four_le_pow_two_of_pow_two_le (UpperHalfPlane.c_mul_im_sq_le_normSq_denom z g)) (sq_nonneg _) let nsq := normSq (denom g z) calc 9 * c ^ 4 < c ^ 4 * z.im ^ 2 * (g • z).im ^ 2 * 16 := by linarith _ = c ^ 4 * z.im ^ 4 / nsq ^ 2 * 16 := by rw [ModularGroup.im_smul_eq_div_normSq, div_pow] ring _ ≤ 16 := by rw [← mul_pow]; linarith /-- An auxiliary result en route to `ModularGroup.eq_smul_self_of_mem_fdo_mem_fdo`. -/ theorem c_eq_zero (hz : z ∈ 𝒟ᵒ) (hg : g • z ∈ 𝒟ᵒ) : (↑ₘg) 1 0 = 0 := by have hp : ∀ {g' : SL(2, ℤ)}, g' • z ∈ 𝒟ᵒ → (↑ₘg') 1 0 ≠ 1 := by intro g' hg' by_contra hc let a := (↑ₘg') 0 0 let d := (↑ₘg') 1 1 have had : T ^ (-a) * g' = S * T ^ d := by rw [g_eq_of_c_eq_one hc]; group let w := T ^ (-a) • g' • z have h₁ : w = S • T ^ d • z := by simp only [w, ← mul_smul, had] replace h₁ : normSq w < 1 := h₁.symm ▸ normSq_S_smul_lt_one (one_lt_normSq_T_zpow_smul hz d) have h₂ : 1 < normSq w := one_lt_normSq_T_zpow_smul hg' (-a) linarith have hn : (↑ₘg) 1 0 ≠ -1 := by intro hc replace hc : (↑ₘ(-g)) 1 0 = 1 := by simp [← neg_eq_iff_eq_neg.mpr hc] replace hg : -g • z ∈ 𝒟ᵒ := (SL_neg_smul g z).symm ▸ hg exact hp hg hc specialize hp hg rcases Int.abs_le_one_iff.mp <| abs_c_le_one hz hg with ⟨⟩ <;> tauto /-- Second Fundamental Domain Lemma: if both `z` and `g • z` are in the open domain `𝒟ᵒ`, where `z : ℍ` and `g : SL(2,ℤ)`, then `z = g • z`. -/ theorem eq_smul_self_of_mem_fdo_mem_fdo (hz : z ∈ 𝒟ᵒ) (hg : g • z ∈ 𝒟ᵒ) : z = g • z := by obtain ⟨n, hn⟩ := exists_eq_T_zpow_of_c_eq_zero (c_eq_zero hz hg) rw [hn] at hg ⊢ simp [eq_zero_of_mem_fdo_of_T_zpow_mem_fdo hz hg, one_smul] end UniqueRepresentative end FundamentalDomain end ModularGroup
NumberTheory\Multiplicity.lean
/- Copyright (c) 2022 Tian Chen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Tian Chen, Mantas Bakšys -/ import Mathlib.Algebra.GeomSum import Mathlib.Algebra.Order.Ring.Basic import Mathlib.Algebra.Ring.Int import Mathlib.NumberTheory.Padics.PadicVal import Mathlib.RingTheory.Ideal.Quotient /-! # Multiplicity in Number Theory This file contains results in number theory relating to multiplicity. ## Main statements * `multiplicity.Int.pow_sub_pow` is the lifting the exponent lemma for odd primes. We also prove several variations of the lemma. ## References * [Wikipedia, *Lifting-the-exponent lemma*] (https://en.wikipedia.org/wiki/Lifting-the-exponent_lemma) -/ open Ideal Ideal.Quotient Finset variable {R : Type*} {n : ℕ} section CommRing variable [CommRing R] {a b x y : R} theorem dvd_geom_sum₂_iff_of_dvd_sub {x y p : R} (h : p ∣ x - y) : (p ∣ ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) ↔ p ∣ n * y ^ (n - 1) := by rw [← mem_span_singleton, ← Ideal.Quotient.eq] at h simp only [← mem_span_singleton, ← eq_zero_iff_mem, RingHom.map_geom_sum₂, h, geom_sum₂_self, _root_.map_mul, map_pow, map_natCast] theorem dvd_geom_sum₂_iff_of_dvd_sub' {x y p : R} (h : p ∣ x - y) : (p ∣ ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) ↔ p ∣ n * x ^ (n - 1) := by rw [geom_sum₂_comm, dvd_geom_sum₂_iff_of_dvd_sub]; simpa using h.neg_right theorem dvd_geom_sum₂_self {x y : R} (h : ↑n ∣ x - y) : ↑n ∣ ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i) := (dvd_geom_sum₂_iff_of_dvd_sub h).mpr (dvd_mul_right _ _) theorem sq_dvd_add_pow_sub_sub (p x : R) (n : ℕ) : p ^ 2 ∣ (x + p) ^ n - x ^ (n - 1) * p * n - x ^ n := by cases' n with n n · simp only [pow_zero, Nat.cast_zero, sub_zero, sub_self, dvd_zero, Nat.zero_eq, mul_zero] · simp only [Nat.succ_sub_succ_eq_sub, tsub_zero, Nat.cast_succ, add_pow, Finset.sum_range_succ, Nat.choose_self, Nat.succ_sub _, tsub_self, pow_one, Nat.choose_succ_self_right, pow_zero, mul_one, Nat.cast_zero, zero_add, Nat.succ_eq_add_one, add_tsub_cancel_left] suffices p ^ 2 ∣ ∑ i ∈ range n, x ^ i * p ^ (n + 1 - i) * ↑((n + 1).choose i) by convert this; abel apply Finset.dvd_sum intro y hy calc p ^ 2 ∣ p ^ (n + 1 - y) := pow_dvd_pow p (le_tsub_of_add_le_left (by linarith [Finset.mem_range.mp hy])) _ ∣ x ^ y * p ^ (n + 1 - y) * ↑((n + 1).choose y) := dvd_mul_of_dvd_left (dvd_mul_left _ _) _ theorem not_dvd_geom_sum₂ {p : R} (hp : Prime p) (hxy : p ∣ x - y) (hx : ¬p ∣ x) (hn : ¬p ∣ n) : ¬p ∣ ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i) := fun h => hx <| hp.dvd_of_dvd_pow <| (hp.dvd_or_dvd <| (dvd_geom_sum₂_iff_of_dvd_sub' hxy).mp h).resolve_left hn variable {p : ℕ} (a b) theorem odd_sq_dvd_geom_sum₂_sub (hp : Odd p) : (p : R) ^ 2 ∣ (∑ i ∈ range p, (a + p * b) ^ i * a ^ (p - 1 - i)) - p * a ^ (p - 1) := by have h1 : ∀ (i : ℕ), (p : R) ^ 2 ∣ (a + ↑p * b) ^ i - (a ^ (i - 1) * (↑p * b) * i + a ^ i) := by intro i calc ↑p ^ 2 ∣ (↑p * b) ^ 2 := by simp only [mul_pow, dvd_mul_right] _ ∣ (a + ↑p * b) ^ i - (a ^ (i - 1) * (↑p * b) * ↑i + a ^ i) := by simp only [sq_dvd_add_pow_sub_sub (↑p * b) a i, ← sub_sub] simp_rw [← mem_span_singleton, ← Ideal.Quotient.eq] at * let s : R := (p : R)^2 calc (Ideal.Quotient.mk (span {s})) (∑ i ∈ range p, (a + (p : R) * b) ^ i * a ^ (p - 1 - i)) = ∑ i ∈ Finset.range p, mk (span {s}) ((a ^ (i - 1) * (↑p * b) * ↑i + a ^ i) * a ^ (p - 1 - i)) := by simp_rw [RingHom.map_geom_sum₂, ← map_pow, h1, ← _root_.map_mul] _ = mk (span {s}) (∑ x ∈ Finset.range p, a ^ (x - 1) * (a ^ (p - 1 - x) * (↑p * (b * ↑x)))) + mk (span {s}) (∑ x ∈ Finset.range p, a ^ (x + (p - 1 - x))) := by ring_nf simp only [← pow_add, map_add, Finset.sum_add_distrib, ← map_sum] congr simp [pow_add a, mul_assoc] _ = mk (span {s}) (∑ x ∈ Finset.range p, a ^ (x - 1) * (a ^ (p - 1 - x) * (↑p * (b * ↑x)))) + mk (span {s}) (∑ _x ∈ Finset.range p, a ^ (p - 1)) := by rw [add_right_inj] have : ∀ (x : ℕ), (hx : x ∈ range p) → a ^ (x + (p - 1 - x)) = a ^ (p - 1) := by intro x hx rw [← Nat.add_sub_assoc _ x, Nat.add_sub_cancel_left] exact Nat.le_sub_one_of_lt (Finset.mem_range.mp hx) rw [Finset.sum_congr rfl this] _ = mk (span {s}) (∑ x ∈ Finset.range p, a ^ (x - 1) * (a ^ (p - 1 - x) * (↑p * (b * ↑x)))) + mk (span {s}) (↑p * a ^ (p - 1)) := by simp only [add_right_inj, Finset.sum_const, Finset.card_range, nsmul_eq_mul] _ = mk (span {s}) (↑p * b * ∑ x ∈ Finset.range p, a ^ (p - 2) * x) + mk (span {s}) (↑p * a ^ (p - 1)) := by simp only [Finset.mul_sum, ← mul_assoc, ← pow_add] rw [Finset.sum_congr rfl] rintro (⟨⟩ | ⟨x⟩) hx · rw [Nat.cast_zero, mul_zero, mul_zero] · have : x.succ - 1 + (p - 1 - x.succ) = p - 2 := by rw [← Nat.add_sub_assoc (Nat.le_sub_one_of_lt (Finset.mem_range.mp hx))] exact congr_arg Nat.pred (Nat.add_sub_cancel_left _ _) rw [this] ring1 _ = mk (span {s}) (↑p * a ^ (p - 1)) := by have : Finset.sum (range p) (fun (x : ℕ) ↦ (x : R)) = ((Finset.sum (range p) (fun (x : ℕ) ↦ (x : ℕ)))) := by simp only [Nat.cast_sum] simp only [add_left_eq_self, ← Finset.mul_sum, this] norm_cast simp only [Finset.sum_range_id] norm_cast simp only [Nat.cast_mul, _root_.map_mul, Nat.mul_div_assoc p (even_iff_two_dvd.mp (Nat.Odd.sub_odd hp odd_one))] ring_nf rw [mul_assoc, mul_assoc] refine mul_eq_zero_of_left ?_ _ refine Ideal.Quotient.eq_zero_iff_mem.mpr ?_ simp [mem_span_singleton] namespace multiplicity section IntegralDomain variable [IsDomain R] [@DecidableRel R (· ∣ ·)] theorem pow_sub_pow_of_prime {p : R} (hp : Prime p) {x y : R} (hxy : p ∣ x - y) (hx : ¬p ∣ x) {n : ℕ} (hn : ¬p ∣ n) : multiplicity p (x ^ n - y ^ n) = multiplicity p (x - y) := by rw [← geom_sum₂_mul, multiplicity.mul hp, multiplicity_eq_zero.2 (not_dvd_geom_sum₂ hp hxy hx hn), zero_add] variable (hp : Prime (p : R)) (hp1 : Odd p) (hxy : ↑p ∣ x - y) (hx : ¬↑p ∣ x) theorem geom_sum₂_eq_one : multiplicity (↑p) (∑ i ∈ range p, x ^ i * y ^ (p - 1 - i)) = 1 := by rw [← Nat.cast_one] refine multiplicity.eq_coe_iff.2 ⟨?_, ?_⟩ · rw [pow_one] exact dvd_geom_sum₂_self hxy rw [dvd_iff_dvd_of_dvd_sub hxy] at hx cases' hxy with k hk rw [one_add_one_eq_two, eq_add_of_sub_eq' hk] refine mt (dvd_iff_dvd_of_dvd_sub (@odd_sq_dvd_geom_sum₂_sub _ _ y k _ hp1)).mp ?_ rw [pow_two, mul_dvd_mul_iff_left hp.ne_zero] exact mt hp.dvd_of_dvd_pow hx theorem pow_prime_sub_pow_prime : multiplicity (↑p) (x ^ p - y ^ p) = multiplicity (↑p) (x - y) + 1 := by rw [← geom_sum₂_mul, multiplicity.mul hp, geom_sum₂_eq_one hp hp1 hxy hx, add_comm] theorem pow_prime_pow_sub_pow_prime_pow (a : ℕ) : multiplicity (↑p) (x ^ p ^ a - y ^ p ^ a) = multiplicity (↑p) (x - y) + a := by induction' a with a h_ind · rw [Nat.cast_zero, add_zero, pow_zero, pow_one, pow_one] rw [Nat.cast_add, Nat.cast_one, ← add_assoc, ← h_ind, pow_succ, pow_mul, pow_mul] apply pow_prime_sub_pow_prime hp hp1 · rw [← geom_sum₂_mul] exact dvd_mul_of_dvd_right hxy _ · exact fun h => hx (hp.dvd_of_dvd_pow h) end IntegralDomain section LiftingTheExponent variable (hp : Nat.Prime p) (hp1 : Odd p) /-- **Lifting the exponent lemma** for odd primes. -/ theorem Int.pow_sub_pow {x y : ℤ} (hxy : ↑p ∣ x - y) (hx : ¬↑p ∣ x) (n : ℕ) : multiplicity (↑p) (x ^ n - y ^ n) = multiplicity (↑p) (x - y) + multiplicity p n := by cases' n with n · simp only [multiplicity.zero, add_top, pow_zero, sub_self, Nat.zero_eq] have h : (multiplicity _ _).Dom := finite_nat_iff.mpr ⟨hp.ne_one, n.succ_pos⟩ simp only [Nat.succ_eq_add_one] at h rcases eq_coe_iff.mp (PartENat.natCast_get h).symm with ⟨⟨k, hk⟩, hpn⟩ conv_lhs => rw [hk, pow_mul, pow_mul] rw [Nat.prime_iff_prime_int] at hp rw [pow_sub_pow_of_prime hp, pow_prime_pow_sub_pow_prime_pow hp hp1 hxy hx, PartENat.natCast_get] · rw [← geom_sum₂_mul] exact dvd_mul_of_dvd_right hxy _ · exact fun h => hx (hp.dvd_of_dvd_pow h) · rw [Int.natCast_dvd_natCast] rintro ⟨c, rfl⟩ refine hpn ⟨c, ?_⟩ rwa [pow_succ, mul_assoc] theorem Int.pow_add_pow {x y : ℤ} (hxy : ↑p ∣ x + y) (hx : ¬↑p ∣ x) {n : ℕ} (hn : Odd n) : multiplicity (↑p) (x ^ n + y ^ n) = multiplicity (↑p) (x + y) + multiplicity p n := by rw [← sub_neg_eq_add] at hxy rw [← sub_neg_eq_add, ← sub_neg_eq_add, ← Odd.neg_pow hn] exact Int.pow_sub_pow hp hp1 hxy hx n theorem Nat.pow_sub_pow {x y : ℕ} (hxy : p ∣ x - y) (hx : ¬p ∣ x) (n : ℕ) : multiplicity p (x ^ n - y ^ n) = multiplicity p (x - y) + multiplicity p n := by obtain hyx | hyx := le_total y x · iterate 2 rw [← Int.natCast_multiplicity] rw [Int.ofNat_sub (Nat.pow_le_pow_left hyx n)] rw [← Int.natCast_dvd_natCast] at hxy hx rw [Int.natCast_sub hyx] at * push_cast at * exact Int.pow_sub_pow hp hp1 hxy hx n · simp only [Nat.sub_eq_zero_iff_le.mpr hyx, Nat.sub_eq_zero_iff_le.mpr (Nat.pow_le_pow_left hyx n), multiplicity.zero, PartENat.top_add] theorem Nat.pow_add_pow {x y : ℕ} (hxy : p ∣ x + y) (hx : ¬p ∣ x) {n : ℕ} (hn : Odd n) : multiplicity p (x ^ n + y ^ n) = multiplicity p (x + y) + multiplicity p n := by iterate 2 rw [← Int.natCast_multiplicity] rw [← Int.natCast_dvd_natCast] at hxy hx push_cast at * exact Int.pow_add_pow hp hp1 hxy hx hn end LiftingTheExponent end multiplicity end CommRing theorem pow_two_pow_sub_pow_two_pow [CommRing R] {x y : R} (n : ℕ) : x ^ 2 ^ n - y ^ 2 ^ n = (∏ i ∈ Finset.range n, (x ^ 2 ^ i + y ^ 2 ^ i)) * (x - y) := by induction' n with d hd · simp only [pow_zero, pow_one, range_zero, prod_empty, one_mul, Nat.zero_eq] · suffices x ^ 2 ^ d.succ - y ^ 2 ^ d.succ = (x ^ 2 ^ d + y ^ 2 ^ d) * (x ^ 2 ^ d - y ^ 2 ^ d) by rw [this, hd, Finset.prod_range_succ, ← mul_assoc, mul_comm (x ^ 2 ^ d + y ^ 2 ^ d)] rw [Nat.succ_eq_add_one] ring -- Porting note: simplified proof because `fin_cases` was not available in that case theorem Int.sq_mod_four_eq_one_of_odd {x : ℤ} : Odd x → x ^ 2 % 4 = 1 := by intro hx unfold Odd at hx rcases hx with ⟨_, rfl⟩ ring_nf rw [add_assoc, ← add_mul, Int.add_mul_emod_self] decide theorem Int.two_pow_two_pow_add_two_pow_two_pow {x y : ℤ} (hx : ¬2 ∣ x) (hxy : 4 ∣ x - y) (i : ℕ) : multiplicity 2 (x ^ 2 ^ i + y ^ 2 ^ i) = ↑(1 : ℕ) := by have hx_odd : Odd x := by rwa [Int.odd_iff_not_even, even_iff_two_dvd] have hxy_even : Even (x - y) := even_iff_two_dvd.mpr (dvd_trans (by decide) hxy) have hy_odd : Odd y := by simpa using hx_odd.sub_even hxy_even refine multiplicity.eq_coe_iff.mpr ⟨?_, ?_⟩ · rw [pow_one, ← even_iff_two_dvd] exact hx_odd.pow.add_odd hy_odd.pow cases' i with i · intro hxy' have : 2 * 2 ∣ 2 * x := by have := dvd_add hxy hxy' norm_num at * rw [two_mul] exact this have : 2 ∣ x := (mul_dvd_mul_iff_left (by norm_num)).mp this contradiction suffices ∀ x : ℤ, Odd x → x ^ 2 ^ (i + 1) % 4 = 1 by rw [show (2 ^ (1 + 1) : ℤ) = 4 by norm_num, Int.dvd_iff_emod_eq_zero, Int.add_emod, this _ hx_odd, this _ hy_odd] decide intro x hx rw [pow_succ', mul_comm, pow_mul, Int.sq_mod_four_eq_one_of_odd hx.pow] theorem Int.two_pow_two_pow_sub_pow_two_pow {x y : ℤ} (n : ℕ) (hxy : 4 ∣ x - y) (hx : ¬2 ∣ x) : multiplicity 2 (x ^ 2 ^ n - y ^ 2 ^ n) = multiplicity 2 (x - y) + n := by simp only [pow_two_pow_sub_pow_two_pow n, multiplicity.mul Int.prime_two, multiplicity.Finset.prod Int.prime_two, add_comm, Nat.cast_one, Finset.sum_const, Finset.card_range, nsmul_one, Int.two_pow_two_pow_add_two_pow_two_pow hx hxy] theorem Int.two_pow_sub_pow' {x y : ℤ} (n : ℕ) (hxy : 4 ∣ x - y) (hx : ¬2 ∣ x) : multiplicity 2 (x ^ n - y ^ n) = multiplicity 2 (x - y) + multiplicity (2 : ℤ) n := by have hx_odd : Odd x := by rwa [Int.odd_iff_not_even, even_iff_two_dvd] have hxy_even : Even (x - y) := even_iff_two_dvd.mpr (dvd_trans (by decide) hxy) have hy_odd : Odd y := by simpa using hx_odd.sub_even hxy_even cases' n with n · simp only [pow_zero, sub_self, multiplicity.zero, Int.ofNat_zero, Nat.zero_eq, add_top] have h : (multiplicity 2 n.succ).Dom := multiplicity.finite_nat_iff.mpr ⟨by norm_num, n.succ_pos⟩ simp only [Nat.succ_eq_add_one] at h rcases multiplicity.eq_coe_iff.mp (PartENat.natCast_get h).symm with ⟨⟨k, hk⟩, hpn⟩ rw [hk, pow_mul, pow_mul, multiplicity.pow_sub_pow_of_prime, Int.two_pow_two_pow_sub_pow_two_pow _ hxy hx, ← hk, PartENat.natCast_get] · norm_cast · exact Int.prime_two · simpa only [even_iff_two_dvd] using hx_odd.pow.sub_odd hy_odd.pow · simpa only [even_iff_two_dvd, Int.odd_iff_not_even] using hx_odd.pow erw [Int.natCast_dvd_natCast] -- `erw` to deal with `2 : ℤ` vs `(2 : ℕ) : ℤ` contrapose! hpn rw [pow_succ] conv_rhs => rw [hk] exact mul_dvd_mul_left _ hpn /-- **Lifting the exponent lemma** for `p = 2` -/ theorem Int.two_pow_sub_pow {x y : ℤ} {n : ℕ} (hxy : 2 ∣ x - y) (hx : ¬2 ∣ x) (hn : Even n) : multiplicity 2 (x ^ n - y ^ n) + 1 = multiplicity 2 (x + y) + multiplicity 2 (x - y) + multiplicity (2 : ℤ) n := by have hy : Odd y := by rw [← even_iff_two_dvd, ← Int.odd_iff_not_even] at hx replace hxy := (@even_neg _ _ (x - y)).mpr (even_iff_two_dvd.mpr hxy) convert Even.add_odd hxy hx abel cases' hn with d hd subst hd simp only [← two_mul, pow_mul] have hxy4 : 4 ∣ x ^ 2 - y ^ 2 := by rw [Int.dvd_iff_emod_eq_zero, Int.sub_emod, Int.sq_mod_four_eq_one_of_odd _, Int.sq_mod_four_eq_one_of_odd hy] · norm_num · simp only [Int.odd_iff_not_even, even_iff_two_dvd, hx, not_false_iff] rw [Int.two_pow_sub_pow' d hxy4 _, sq_sub_sq, ← Int.ofNat_mul_out, multiplicity.mul Int.prime_two, multiplicity.mul Int.prime_two] · suffices multiplicity (2 : ℤ) ↑(2 : ℕ) = 1 by rw [this, add_comm (1 : PartENat), ← add_assoc] norm_cast rw [multiplicity.multiplicity_self _ _] · apply Prime.not_unit simp only [← Nat.prime_iff, Nat.prime_two] · exact two_ne_zero · rw [← even_iff_two_dvd, ← Int.odd_iff_not_even] apply Odd.pow simp only [Int.odd_iff_not_even, even_iff_two_dvd, hx, not_false_iff] theorem Nat.two_pow_sub_pow {x y : ℕ} (hxy : 2 ∣ x - y) (hx : ¬2 ∣ x) {n : ℕ} (hn : Even n) : multiplicity 2 (x ^ n - y ^ n) + 1 = multiplicity 2 (x + y) + multiplicity 2 (x - y) + multiplicity 2 n := by obtain hyx | hyx := le_total y x · iterate 3 rw [← multiplicity.Int.natCast_multiplicity] simp only [Int.ofNat_sub hyx, Int.ofNat_sub (pow_le_pow_left' hyx _), Int.ofNat_add, Int.natCast_pow] rw [← Int.natCast_dvd_natCast] at hx rw [← Int.natCast_dvd_natCast, Int.ofNat_sub hyx] at hxy convert Int.two_pow_sub_pow hxy hx hn using 2 rw [← multiplicity.Int.natCast_multiplicity] rfl · simp only [Nat.sub_eq_zero_iff_le.mpr hyx, Nat.sub_eq_zero_iff_le.mpr (pow_le_pow_left' hyx n), multiplicity.zero, PartENat.top_add, PartENat.add_top] namespace padicValNat variable {x y : ℕ} theorem pow_two_sub_pow (hyx : y < x) (hxy : 2 ∣ x - y) (hx : ¬2 ∣ x) {n : ℕ} (hn : n ≠ 0) (hneven : Even n) : padicValNat 2 (x ^ n - y ^ n) + 1 = padicValNat 2 (x + y) + padicValNat 2 (x - y) + padicValNat 2 n := by simp only [← PartENat.natCast_inj, Nat.cast_add] iterate 4 rw [padicValNat_def, PartENat.natCast_get] · convert Nat.two_pow_sub_pow hxy hx hneven using 2 · exact hn.bot_lt · exact Nat.sub_pos_of_lt hyx · omega · simp only [tsub_pos_iff_lt, pow_lt_pow_left hyx zero_le' hn] variable {p : ℕ} [hp : Fact p.Prime] (hp1 : Odd p) theorem pow_sub_pow (hyx : y < x) (hxy : p ∣ x - y) (hx : ¬p ∣ x) {n : ℕ} (hn : n ≠ 0) : padicValNat p (x ^ n - y ^ n) = padicValNat p (x - y) + padicValNat p n := by rw [← PartENat.natCast_inj, Nat.cast_add] iterate 3 rw [padicValNat_def, PartENat.natCast_get] · exact multiplicity.Nat.pow_sub_pow hp.out hp1 hxy hx n · exact hn.bot_lt · exact Nat.sub_pos_of_lt hyx · exact Nat.sub_pos_of_lt (Nat.pow_lt_pow_left hyx hn) theorem pow_add_pow (hxy : p ∣ x + y) (hx : ¬p ∣ x) {n : ℕ} (hn : Odd n) : padicValNat p (x ^ n + y ^ n) = padicValNat p (x + y) + padicValNat p n := by cases' y with y · contradiction rw [← PartENat.natCast_inj, Nat.cast_add] iterate 3 rw [padicValNat_def, PartENat.natCast_get] · exact multiplicity.Nat.pow_add_pow hp.out hp1 hxy hx hn · exact Odd.pos hn · simp only [add_pos_iff, Nat.succ_pos', or_true_iff] · exact Nat.lt_add_left _ (pow_pos y.succ_pos _) end padicValNat
NumberTheory\Ostrowski.lean
/- Copyright (c) 2024 María Inés de Frutos-Fernández. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Kurniadi Angdinata, Fabrizio Barroero, Laura Capuano, Nirvana Coppola, María Inés de Frutos Fernández, Sam van Gool, Silvain Rideau-Kikuchi, Amos Turchet, Francesco Veneziano -/ import Mathlib.Analysis.Normed.Field.Basic import Mathlib.Analysis.SpecialFunctions.Log.Base import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Analysis.Normed.Ring.Seminorm import Mathlib.NumberTheory.Padics.PadicNorm /-! # Ostrowski’s Theorem The goal of this file is to prove Ostrowski’s Theorem which gives a list of all the nontrivial absolute values on a number field up to equivalence. (TODO) ## References * [K. Conrad, *Ostroski's Theorem for Q*][conradQ] * [K. Conrad, *Ostroski for number fields*][conradnumbfield] * [J. W. S. Cassels, *Local fields*][cassels1986local] ## Tags ring_norm, ostrowski -/ namespace Rat.MulRingNorm open Int variable {f g : MulRingNorm ℚ} /-- Values of a multiplicative norm of the rationals coincide on ℕ if and only if they coincide on `ℤ`. -/ lemma eq_on_nat_iff_eq_on_Int : (∀ n : ℕ , f n = g n) ↔ (∀ n : ℤ , f n = g n) := by refine ⟨fun h z ↦ ?_, fun a n ↦ a n⟩ obtain ⟨n , rfl | rfl⟩ := eq_nat_or_neg z <;> simp only [Int.cast_neg, Int.cast_natCast, map_neg_eq_map, h n] /-- Values of a multiplicative norm of the rationals are determined by the values on the natural numbers. -/ lemma eq_on_nat_iff_eq : (∀ n : ℕ , f n = g n) ↔ f = g := by refine ⟨fun h ↦ ?_, fun h n ↦ congrFun (congrArg DFunLike.coe h) ↑n⟩ ext z rw [← Rat.num_div_den z, map_div₀, map_div₀, h, eq_on_nat_iff_eq_on_Int.mp h] /-- The equivalence class of a multiplicative norm on the rationals is determined by its values on the natural numbers. -/ lemma equiv_on_nat_iff_equiv : (∃ c : ℝ, 0 < c ∧ (∀ n : ℕ , (f n) ^ c = g n)) ↔ f.equiv g := by refine ⟨fun ⟨c, hc, h⟩ ↦ ⟨c, ⟨hc, ?_⟩⟩, fun ⟨c, hc, h⟩ ↦ ⟨c, ⟨hc, fun n ↦ by rw [← h]⟩⟩⟩ ext x rw [← Rat.num_div_den x, map_div₀, map_div₀, Real.div_rpow (apply_nonneg f _) (apply_nonneg f _), h x.den, ← MulRingNorm.apply_natAbs_eq,← MulRingNorm.apply_natAbs_eq, h (natAbs x.num)] open Rat.MulRingNorm section Non_archimedean -- ## Non-archimedean case /-- The mulRingNorm corresponding to the p-adic norm on `ℚ`. -/ def mulRingNorm_padic (p : ℕ) [Fact p.Prime] : MulRingNorm ℚ := { toFun := fun x : ℚ ↦ (padicNorm p x : ℝ), map_zero' := by simp only [padicNorm.zero, Rat.cast_zero] add_le' := by simp only; norm_cast; exact fun r s ↦ padicNorm.triangle_ineq r s neg' := by simp only [forall_const, padicNorm.neg] eq_zero_of_map_eq_zero' := by simp only [Rat.cast_eq_zero] apply padicNorm.zero_of_padicNorm_eq_zero map_one' := by simp only [ne_eq, one_ne_zero, not_false_eq_true, padicNorm.eq_zpow_of_nonzero, padicValRat.one, neg_zero, zpow_zero, Rat.cast_one] map_mul' := by simp only [padicNorm.mul, Rat.cast_mul, forall_const] } @[simp] lemma mulRingNorm_eq_padic_norm (p : ℕ) [Fact p.Prime] (r : ℚ) : mulRingNorm_padic p r = padicNorm p r := rfl -- ## Step 1: define `p = minimal n s. t. 0 < f n < 1` variable (hf_nontriv : f ≠ 1) (bdd : ∀ n : ℕ, f n ≤ 1) /-- There exists a minimal positive integer with absolute value smaller than 1. -/ lemma exists_minimal_nat_zero_lt_mulRingNorm_lt_one : ∃ p : ℕ, (0 < f p ∧ f p < 1) ∧ ∀ m : ℕ, 0 < f m ∧ f m < 1 → p ≤ m := by -- There is a positive integer with absolute value different from one. obtain ⟨n, hn1, hn2⟩ : ∃ n : ℕ, n ≠ 0 ∧ f n ≠ 1 := by contrapose! hf_nontriv rw [← eq_on_nat_iff_eq] intro n rcases eq_or_ne n 0 with rfl | hn0 · simp only [Nat.cast_zero, map_zero] · simp only [MulRingNorm.apply_one, Nat.cast_eq_zero, hn0, ↓reduceIte, hf_nontriv n hn0] set P := {m : ℕ | 0 < f ↑m ∧ f ↑m < 1} -- p is going to be the minimum of this set. have hP : P.Nonempty := ⟨n, map_pos_of_ne_zero f (Nat.cast_ne_zero.mpr hn1), lt_of_le_of_ne (bdd n) hn2⟩ exact ⟨sInf P, Nat.sInf_mem hP, fun m hm ↦ Nat.sInf_le hm⟩ -- ## Step 2: p is prime variable {p : ℕ} (hp0 : 0 < f p) (hp1 : f p < 1) (hmin : ∀ m : ℕ, 0 < f m ∧ f m < 1 → p ≤ m) /-- The minimal positive integer with absolute value smaller than 1 is a prime number.-/ lemma is_prime_of_minimal_nat_zero_lt_mulRingNorm_lt_one : p.Prime := by rw [← Nat.irreducible_iff_nat_prime] constructor -- Two goals: p is not a unit and any product giving p must contain a unit. · rw [Nat.isUnit_iff] rintro rfl simp only [Nat.cast_one, map_one, lt_self_iff_false] at hp1 · rintro a b rfl rw [Nat.isUnit_iff, Nat.isUnit_iff] by_contra! con obtain ⟨ha₁, hb₁⟩ := con obtain ⟨ha₀, hb₀⟩ : a ≠ 0 ∧ b ≠ 0 := by refine mul_ne_zero_iff.1 fun h ↦ ?_ rwa [h, Nat.cast_zero, map_zero, lt_self_iff_false] at hp0 have hap : a < a * b := lt_mul_of_one_lt_right (by omega) (by omega) have hbp : b < a * b := lt_mul_of_one_lt_left (by omega) (by omega) have ha := le_of_not_lt <| not_and.1 ((hmin a).mt hap.not_le) (map_pos_of_ne_zero f (mod_cast ha₀)) have hb := le_of_not_lt <| not_and.1 ((hmin b).mt hbp.not_le) (map_pos_of_ne_zero f (mod_cast hb₀)) rw [Nat.cast_mul, map_mul] at hp1 exact ((one_le_mul_of_one_le_of_one_le ha hb).trans_lt hp1).false -- ## Step 3: if p does not divide m, then f m = 1 open Real /-- A natural number not divible by `p` has absolute value 1. -/ lemma mulRingNorm_eq_one_of_not_dvd {m : ℕ} (hpm : ¬ p ∣ m) : f m = 1 := by apply le_antisymm (bdd m) by_contra! hm set M := f p ⊔ f m with hM set k := Nat.ceil (M.logb (1 / 2)) + 1 with hk obtain ⟨a, b, bezout⟩ : IsCoprime (p ^ k : ℤ) (m ^ k) := by apply IsCoprime.pow (Nat.Coprime.isCoprime _) exact (Nat.Prime.coprime_iff_not_dvd (is_prime_of_minimal_nat_zero_lt_mulRingNorm_lt_one hp0 hp1 hmin)).2 hpm have le_half {x} (hx0 : 0 < x) (hx1 : x < 1) (hxM : x ≤ M) : x ^ k < 1 / 2 := by calc x ^ k = x ^ (k : ℝ) := (rpow_natCast x k).symm _ < x ^ M.logb (1 / 2) := by apply rpow_lt_rpow_of_exponent_gt hx0 hx1 rw [hk] push_cast exact lt_add_of_le_of_pos (Nat.le_ceil (M.logb (1 / 2))) zero_lt_one _ ≤ x ^ x.logb (1 / 2) := by apply rpow_le_rpow_of_exponent_ge hx0 (le_of_lt hx1) simp only [one_div, ← log_div_log, Real.log_inv, neg_div, ← div_neg, hM] gcongr simp only [Left.neg_pos_iff] exact log_neg (lt_sup_iff.2 <| Or.inl hp0) (sup_lt_iff.2 ⟨hp1, hm⟩) _ = 1 / 2 := rpow_logb hx0 (ne_of_lt hx1) one_half_pos apply lt_irrefl (1 : ℝ) calc 1 = f 1 := (map_one f).symm _ = f (a * p ^ k + b * m ^ k) := by rw_mod_cast [bezout]; norm_cast _ ≤ f (a * p ^ k) + f (b * m ^ k) := f.add_le' (a * p ^ k) (b * m ^ k) _ ≤ 1 * (f p) ^ k + 1 * (f m) ^ k := by simp only [map_mul, map_pow, le_refl] gcongr all_goals rw [← MulRingNorm.apply_natAbs_eq]; apply bdd _ = (f p) ^ k + (f m) ^ k := by simp only [one_mul] _ < 1 := by have hm₀ : 0 < f m := map_pos_of_ne_zero _ <| Nat.cast_ne_zero.2 fun H ↦ hpm <| H ▸ dvd_zero p linarith only [le_half hp0 hp1 le_sup_left, le_half hm₀ hm le_sup_right] -- ## Step 4: f p = p ^ (- t) for some positive real t /-- The absolute value of `p` is `p ^ (-t)` for some positive real number `t`. -/ lemma exists_pos_mulRingNorm_eq_pow_neg : ∃ t : ℝ, 0 < t ∧ f p = p ^ (-t) := by have pprime := is_prime_of_minimal_nat_zero_lt_mulRingNorm_lt_one hp0 hp1 hmin refine ⟨- logb p (f p), Left.neg_pos_iff.2 <| logb_neg (mod_cast pprime.one_lt) hp0 hp1, ?_⟩ rw [neg_neg] refine (rpow_logb (mod_cast pprime.pos) ?_ hp0).symm simp only [ne_eq, Nat.cast_eq_one,Nat.Prime.ne_one pprime, not_false_eq_true] -- ## Non-archimedean case: end goal /-- If `f` is bounded and not trivial, then it is equivalent to a p-adic absolute value. -/ theorem mulRingNorm_equiv_padic_of_bounded : ∃! p, ∃ (hp : Fact (p.Prime)), MulRingNorm.equiv f (mulRingNorm_padic p) := by obtain ⟨p, hfp, hmin⟩ := exists_minimal_nat_zero_lt_mulRingNorm_lt_one hf_nontriv bdd have hprime := is_prime_of_minimal_nat_zero_lt_mulRingNorm_lt_one hfp.1 hfp.2 hmin have hprime_fact : Fact (p.Prime) := ⟨hprime⟩ obtain ⟨t, h⟩ := exists_pos_mulRingNorm_eq_pow_neg hfp.1 hfp.2 hmin simp_rw [← equiv_on_nat_iff_equiv] use p constructor -- 2 goals: MulRingNorm.equiv f (mulRingNorm_padic p) and p is unique. · use hprime_fact refine ⟨t⁻¹, by simp only [inv_pos, h.1], fun n ↦ ?_⟩ have ht : t⁻¹ ≠ 0 := inv_ne_zero h.1.ne' rcases eq_or_ne n 0 with rfl | hn -- Separate cases n=0 and n ≠ 0 · simp only [Nat.cast_zero, map_zero, ne_eq, ht, not_false_eq_true, zero_rpow] · /- Any natural number can be written as a power of p times a natural number not divisible by p -/ rcases Nat.exists_eq_pow_mul_and_not_dvd hn p hprime.ne_one with ⟨e, m, hpm, rfl⟩ simp only [Nat.cast_mul, Nat.cast_pow, map_mul, map_pow, mulRingNorm_eq_padic_norm, padicNorm.padicNorm_p_of_prime, Rat.cast_inv, Rat.cast_natCast, inv_pow, mulRingNorm_eq_one_of_not_dvd bdd hfp.1 hfp.2 hmin hpm, h.2] rw [← padicNorm.nat_eq_one_iff] at hpm simp only [← rpow_natCast, p.cast_nonneg, ← rpow_mul, mul_one, ← rpow_neg, hpm, cast_one] congr field_simp [h.1.ne'] ring · intro q ⟨hq_prime, h_equiv⟩ by_contra! hne apply Prime.ne_one (Nat.Prime.prime (Fact.elim hq_prime)) rw [ne_comm, ← Nat.coprime_primes hprime (Fact.elim hq_prime), Nat.Prime.coprime_iff_not_dvd hprime] at hne rcases h_equiv with ⟨c, _, h_eq⟩ have h_eq' := h_eq q simp only [mulRingNorm_eq_one_of_not_dvd bdd hfp.1 hfp.2 hmin hne, one_rpow, mulRingNorm_eq_padic_norm, padicNorm.padicNorm_p_of_prime, cast_inv, cast_natCast, eq_comm, inv_eq_one] at h_eq' norm_cast at h_eq' end Non_archimedean end Rat.MulRingNorm
NumberTheory\Pell.lean
/- Copyright (c) 2023 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Geißer, Michael Stoll -/ import Mathlib.Tactic.Qify import Mathlib.Data.ZMod.Basic import Mathlib.NumberTheory.DiophantineApproximation import Mathlib.NumberTheory.Zsqrtd.Basic /-! # Pell's Equation *Pell's Equation* is the equation $x^2 - d y^2 = 1$, where $d$ is a positive integer that is not a square, and one is interested in solutions in integers $x$ and $y$. In this file, we aim at providing all of the essential theory of Pell's Equation for general $d$ (as opposed to the contents of `NumberTheory.PellMatiyasevic`, which is specific to the case $d = a^2 - 1$ for some $a > 1$). We begin by defining a type `Pell.Solution₁ d` for solutions of the equation, show that it has a natural structure as an abelian group, and prove some basic properties. We then prove the following **Theorem.** Let $d$ be a positive integer that is not a square. Then the equation $x^2 - d y^2 = 1$ has a nontrivial (i.e., with $y \ne 0$) solution in integers. See `Pell.exists_of_not_isSquare` and `Pell.Solution₁.exists_nontrivial_of_not_isSquare`. We then define the *fundamental solution* to be the solution with smallest $x$ among all solutions satisfying $x > 1$ and $y > 0$. We show that every solution is a power (in the sense of the group structure mentioned above) of the fundamental solution up to a (common) sign, see `Pell.IsFundamental.eq_zpow_or_neg_zpow`, and that a (positive) solution has this property if and only if it is fundamental, see `Pell.pos_generator_iff_fundamental`. ## References * [K. Ireland, M. Rosen, *A classical introduction to modern number theory* (Section 17.5)][IrelandRosen1990] ## Tags Pell's equation ## TODO * Extend to `x ^ 2 - d * y ^ 2 = -1` and further generalizations. * Connect solutions to the continued fraction expansion of `√d`. -/ namespace Pell /-! ### Group structure of the solution set We define a structure of a commutative multiplicative group with distributive negation on the set of all solutions to the Pell equation `x^2 - d*y^2 = 1`. The type of such solutions is `Pell.Solution₁ d`. It corresponds to a pair of integers `x` and `y` and a proof that `(x, y)` is indeed a solution. The multiplication is given by `(x, y) * (x', y') = (x*y' + d*y*y', x*y' + y*x')`. This is obtained by mapping `(x, y)` to `x + y*√d` and multiplying the results. In fact, we define `Pell.Solution₁ d` to be `↥(unitary (ℤ√d))` and transport the "commutative group with distributive negation" structure from `↥(unitary (ℤ√d))`. We then set up an API for `Pell.Solution₁ d`. -/ open Zsqrtd /-- An element of `ℤ√d` has norm one (i.e., `a.re^2 - d*a.im^2 = 1`) if and only if it is contained in the submonoid of unitary elements. TODO: merge this result with `Pell.isPell_iff_mem_unitary`. -/ theorem is_pell_solution_iff_mem_unitary {d : ℤ} {a : ℤ√d} : a.re ^ 2 - d * a.im ^ 2 = 1 ↔ a ∈ unitary (ℤ√d) := by rw [← norm_eq_one_iff_mem_unitary, norm_def, sq, sq, ← mul_assoc] -- We use `solution₁ d` to allow for a more general structure `solution d m` that -- encodes solutions to `x^2 - d*y^2 = m` to be added later. /-- `Pell.Solution₁ d` is the type of solutions to the Pell equation `x^2 - d*y^2 = 1`. We define this in terms of elements of `ℤ√d` of norm one. -/ def Solution₁ (d : ℤ) : Type := ↥(unitary (ℤ√d)) namespace Solution₁ variable {d : ℤ} -- Porting note(https://github.com/leanprover-community/mathlib4/issues/5020): manual deriving instance instCommGroup : CommGroup (Solution₁ d) := inferInstanceAs (CommGroup (unitary (ℤ√d))) instance instHasDistribNeg : HasDistribNeg (Solution₁ d) := inferInstanceAs (HasDistribNeg (unitary (ℤ√d))) instance instInhabited : Inhabited (Solution₁ d) := inferInstanceAs (Inhabited (unitary (ℤ√d))) instance : Coe (Solution₁ d) (ℤ√d) where coe := Subtype.val /-- The `x` component of a solution to the Pell equation `x^2 - d*y^2 = 1` -/ protected def x (a : Solution₁ d) : ℤ := (a : ℤ√d).re /-- The `y` component of a solution to the Pell equation `x^2 - d*y^2 = 1` -/ protected def y (a : Solution₁ d) : ℤ := (a : ℤ√d).im /-- The proof that `a` is a solution to the Pell equation `x^2 - d*y^2 = 1` -/ theorem prop (a : Solution₁ d) : a.x ^ 2 - d * a.y ^ 2 = 1 := is_pell_solution_iff_mem_unitary.mpr a.property /-- An alternative form of the equation, suitable for rewriting `x^2`. -/ theorem prop_x (a : Solution₁ d) : a.x ^ 2 = 1 + d * a.y ^ 2 := by rw [← a.prop]; ring /-- An alternative form of the equation, suitable for rewriting `d * y^2`. -/ theorem prop_y (a : Solution₁ d) : d * a.y ^ 2 = a.x ^ 2 - 1 := by rw [← a.prop]; ring /-- Two solutions are equal if their `x` and `y` components are equal. -/ @[ext] theorem ext {a b : Solution₁ d} (hx : a.x = b.x) (hy : a.y = b.y) : a = b := Subtype.ext <| Zsqrtd.ext hx hy /-- Construct a solution from `x`, `y` and a proof that the equation is satisfied. -/ def mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : Solution₁ d where val := ⟨x, y⟩ property := is_pell_solution_iff_mem_unitary.mp prop @[simp] theorem x_mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : (mk x y prop).x = x := rfl @[simp] theorem y_mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : (mk x y prop).y = y := rfl @[simp] theorem coe_mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : (↑(mk x y prop) : ℤ√d) = ⟨x, y⟩ := Zsqrtd.ext (x_mk x y prop) (y_mk x y prop) @[simp] theorem x_one : (1 : Solution₁ d).x = 1 := rfl @[simp] theorem y_one : (1 : Solution₁ d).y = 0 := rfl @[simp] theorem x_mul (a b : Solution₁ d) : (a * b).x = a.x * b.x + d * (a.y * b.y) := by rw [← mul_assoc] rfl @[simp] theorem y_mul (a b : Solution₁ d) : (a * b).y = a.x * b.y + a.y * b.x := rfl @[simp] theorem x_inv (a : Solution₁ d) : a⁻¹.x = a.x := rfl @[simp] theorem y_inv (a : Solution₁ d) : a⁻¹.y = -a.y := rfl @[simp] theorem x_neg (a : Solution₁ d) : (-a).x = -a.x := rfl @[simp] theorem y_neg (a : Solution₁ d) : (-a).y = -a.y := rfl /-- When `d` is negative, then `x` or `y` must be zero in a solution. -/ theorem eq_zero_of_d_neg (h₀ : d < 0) (a : Solution₁ d) : a.x = 0 ∨ a.y = 0 := by have h := a.prop contrapose! h have h1 := sq_pos_of_ne_zero h.1 have h2 := sq_pos_of_ne_zero h.2 nlinarith /-- A solution has `x ≠ 0`. -/ theorem x_ne_zero (h₀ : 0 ≤ d) (a : Solution₁ d) : a.x ≠ 0 := by intro hx have h : 0 ≤ d * a.y ^ 2 := mul_nonneg h₀ (sq_nonneg _) rw [a.prop_y, hx, sq, zero_mul, zero_sub] at h exact not_le.mpr (neg_one_lt_zero : (-1 : ℤ) < 0) h /-- A solution with `x > 1` must have `y ≠ 0`. -/ theorem y_ne_zero_of_one_lt_x {a : Solution₁ d} (ha : 1 < a.x) : a.y ≠ 0 := by intro hy have prop := a.prop rw [hy, sq (0 : ℤ), zero_mul, mul_zero, sub_zero] at prop exact lt_irrefl _ (((one_lt_sq_iff <| zero_le_one.trans ha.le).mpr ha).trans_eq prop) /-- If a solution has `x > 1`, then `d` is positive. -/ theorem d_pos_of_one_lt_x {a : Solution₁ d} (ha : 1 < a.x) : 0 < d := by refine pos_of_mul_pos_left ?_ (sq_nonneg a.y) rw [a.prop_y, sub_pos] exact one_lt_pow ha two_ne_zero /-- If a solution has `x > 1`, then `d` is not a square. -/ theorem d_nonsquare_of_one_lt_x {a : Solution₁ d} (ha : 1 < a.x) : ¬IsSquare d := by have hp := a.prop rintro ⟨b, rfl⟩ simp_rw [← sq, ← mul_pow, sq_sub_sq, Int.mul_eq_one_iff_eq_one_or_neg_one] at hp rcases hp with (⟨hp₁, hp₂⟩ | ⟨hp₁, hp₂⟩) <;> omega /-- A solution with `x = 1` is trivial. -/ theorem eq_one_of_x_eq_one (h₀ : d ≠ 0) {a : Solution₁ d} (ha : a.x = 1) : a = 1 := by have prop := a.prop_y rw [ha, one_pow, sub_self, mul_eq_zero, or_iff_right h₀, sq_eq_zero_iff] at prop exact ext ha prop /-- A solution is `1` or `-1` if and only if `y = 0`. -/ theorem eq_one_or_neg_one_iff_y_eq_zero {a : Solution₁ d} : a = 1 ∨ a = -1 ↔ a.y = 0 := by refine ⟨fun H => H.elim (fun h => by simp [h]) fun h => by simp [h], fun H => ?_⟩ have prop := a.prop rw [H, sq (0 : ℤ), mul_zero, mul_zero, sub_zero, sq_eq_one_iff] at prop exact prop.imp (fun h => ext h H) fun h => ext h H /-- The set of solutions with `x > 0` is closed under multiplication. -/ theorem x_mul_pos {a b : Solution₁ d} (ha : 0 < a.x) (hb : 0 < b.x) : 0 < (a * b).x := by simp only [x_mul] refine neg_lt_iff_pos_add'.mp (abs_lt.mp ?_).1 rw [← abs_of_pos ha, ← abs_of_pos hb, ← abs_mul, ← sq_lt_sq, mul_pow a.x, a.prop_x, b.prop_x, ← sub_pos] ring_nf rcases le_or_lt 0 d with h | h · positivity · rw [(eq_zero_of_d_neg h a).resolve_left ha.ne', (eq_zero_of_d_neg h b).resolve_left hb.ne'] -- Porting note: was -- rw [zero_pow two_ne_zero, zero_add, zero_mul, zero_add] -- exact one_pos -- but this relied on the exact output of `ring_nf` simp /-- The set of solutions with `x` and `y` positive is closed under multiplication. -/ theorem y_mul_pos {a b : Solution₁ d} (hax : 0 < a.x) (hay : 0 < a.y) (hbx : 0 < b.x) (hby : 0 < b.y) : 0 < (a * b).y := by simp only [y_mul] positivity /-- If `(x, y)` is a solution with `x` positive, then all its powers with natural exponents have positive `x`. -/ theorem x_pow_pos {a : Solution₁ d} (hax : 0 < a.x) (n : ℕ) : 0 < (a ^ n).x := by induction' n with n ih · simp only [Nat.zero_eq, pow_zero, x_one, zero_lt_one] · rw [pow_succ] exact x_mul_pos ih hax /-- If `(x, y)` is a solution with `x` and `y` positive, then all its powers with positive natural exponents have positive `y`. -/ theorem y_pow_succ_pos {a : Solution₁ d} (hax : 0 < a.x) (hay : 0 < a.y) (n : ℕ) : 0 < (a ^ n.succ).y := by induction' n with n ih · simp only [Nat.zero_eq, ← Nat.one_eq_succ_zero, hay, pow_one] · rw [pow_succ'] exact y_mul_pos hax hay (x_pow_pos hax _) ih /-- If `(x, y)` is a solution with `x` and `y` positive, then all its powers with positive exponents have positive `y`. -/ theorem y_zpow_pos {a : Solution₁ d} (hax : 0 < a.x) (hay : 0 < a.y) {n : ℤ} (hn : 0 < n) : 0 < (a ^ n).y := by lift n to ℕ using hn.le norm_cast at hn ⊢ rw [← Nat.succ_pred_eq_of_pos hn] exact y_pow_succ_pos hax hay _ /-- If `(x, y)` is a solution with `x` positive, then all its powers have positive `x`. -/ theorem x_zpow_pos {a : Solution₁ d} (hax : 0 < a.x) (n : ℤ) : 0 < (a ^ n).x := by cases n with | ofNat n => rw [Int.ofNat_eq_coe, zpow_natCast] exact x_pow_pos hax n | negSucc n => rw [zpow_negSucc] exact x_pow_pos hax (n + 1) /-- If `(x, y)` is a solution with `x` and `y` positive, then the `y` component of any power has the same sign as the exponent. -/ theorem sign_y_zpow_eq_sign_of_x_pos_of_y_pos {a : Solution₁ d} (hax : 0 < a.x) (hay : 0 < a.y) (n : ℤ) : (a ^ n).y.sign = n.sign := by rcases n with ((_ | n) | n) · rfl · rw [Int.ofNat_eq_coe, zpow_natCast] exact Int.sign_eq_one_of_pos (y_pow_succ_pos hax hay n) · rw [zpow_negSucc] exact Int.sign_eq_neg_one_of_neg (neg_neg_of_pos (y_pow_succ_pos hax hay n)) /-- If `a` is any solution, then one of `a`, `a⁻¹`, `-a`, `-a⁻¹` has positive `x` and nonnegative `y`. -/ theorem exists_pos_variant (h₀ : 0 < d) (a : Solution₁ d) : ∃ b : Solution₁ d, 0 < b.x ∧ 0 ≤ b.y ∧ a ∈ ({b, b⁻¹, -b, -b⁻¹} : Set (Solution₁ d)) := by refine (lt_or_gt_of_ne (a.x_ne_zero h₀.le)).elim ((le_total 0 a.y).elim (fun hy hx => ⟨-a⁻¹, ?_, ?_, ?_⟩) fun hy hx => ⟨-a, ?_, ?_, ?_⟩) ((le_total 0 a.y).elim (fun hy hx => ⟨a, hx, hy, ?_⟩) fun hy hx => ⟨a⁻¹, hx, ?_, ?_⟩) <;> simp only [neg_neg, inv_inv, neg_inv, Set.mem_insert_iff, Set.mem_singleton_iff, true_or_iff, eq_self_iff_true, x_neg, x_inv, y_neg, y_inv, neg_pos, neg_nonneg, or_true_iff] <;> assumption end Solution₁ section Existence /-! ### Existence of nontrivial solutions -/ variable {d : ℤ} open Set Real /-- If `d` is a positive integer that is not a square, then there is a nontrivial solution to the Pell equation `x^2 - d*y^2 = 1`. -/ theorem exists_of_not_isSquare (h₀ : 0 < d) (hd : ¬IsSquare d) : ∃ x y : ℤ, x ^ 2 - d * y ^ 2 = 1 ∧ y ≠ 0 := by let ξ : ℝ := √d have hξ : Irrational ξ := by refine irrational_nrt_of_notint_nrt 2 d (sq_sqrt <| Int.cast_nonneg.mpr h₀.le) ?_ two_pos rintro ⟨x, hx⟩ refine hd ⟨x, @Int.cast_injective ℝ _ _ d (x * x) ?_⟩ rw [← sq_sqrt <| Int.cast_nonneg.mpr h₀.le, Int.cast_mul, ← hx, sq] obtain ⟨M, hM₁⟩ := exists_int_gt (2 * |ξ| + 1) have hM : {q : ℚ | |q.1 ^ 2 - d * (q.2 : ℤ) ^ 2| < M}.Infinite := by refine Infinite.mono (fun q h => ?_) (infinite_rat_abs_sub_lt_one_div_den_sq_of_irrational hξ) have h0 : 0 < (q.2 : ℝ) ^ 2 := pow_pos (Nat.cast_pos.mpr q.pos) 2 have h1 : (q.num : ℝ) / (q.den : ℝ) = q := mod_cast q.num_div_den rw [mem_setOf, abs_sub_comm, ← @Int.cast_lt ℝ, ← div_lt_div_right (abs_pos_of_pos h0)] push_cast rw [← abs_div, abs_sq, sub_div, mul_div_cancel_right₀ _ h0.ne', ← div_pow, h1, ← sq_sqrt (Int.cast_pos.mpr h₀).le, sq_sub_sq, abs_mul, ← mul_one_div] refine mul_lt_mul'' (((abs_add ξ q).trans ?_).trans_lt hM₁) h (abs_nonneg _) (abs_nonneg _) rw [two_mul, add_assoc, add_le_add_iff_left, ← sub_le_iff_le_add'] rw [mem_setOf, abs_sub_comm] at h refine (abs_sub_abs_le_abs_sub (q : ℝ) ξ).trans (h.le.trans ?_) rw [div_le_one h0, one_le_sq_iff_one_le_abs, Nat.abs_cast, Nat.one_le_cast] exact q.pos obtain ⟨m, hm⟩ : ∃ m : ℤ, {q : ℚ | q.1 ^ 2 - d * (q.den : ℤ) ^ 2 = m}.Infinite := by contrapose! hM simp only [not_infinite] at hM ⊢ refine (congr_arg _ (ext fun x => ?_)).mp (Finite.biUnion (finite_Ioo (-M) M) fun m _ => hM m) simp only [abs_lt, mem_setOf, mem_Ioo, mem_iUnion, exists_prop, exists_eq_right'] have hm₀ : m ≠ 0 := by rintro rfl obtain ⟨q, hq⟩ := hm.nonempty rw [mem_setOf, sub_eq_zero, mul_comm] at hq obtain ⟨a, ha⟩ := (Int.pow_dvd_pow_iff two_ne_zero).mp ⟨d, hq⟩ rw [ha, mul_pow, mul_right_inj' (pow_pos (Int.natCast_pos.mpr q.pos) 2).ne'] at hq exact hd ⟨a, sq a ▸ hq.symm⟩ haveI := neZero_iff.mpr (Int.natAbs_ne_zero.mpr hm₀) let f : ℚ → ZMod m.natAbs × ZMod m.natAbs := fun q => (q.num, q.den) obtain ⟨q₁, h₁ : q₁.num ^ 2 - d * (q₁.den : ℤ) ^ 2 = m, q₂, h₂ : q₂.num ^ 2 - d * (q₂.den : ℤ) ^ 2 = m, hne, hqf⟩ := hm.exists_ne_map_eq_of_mapsTo (mapsTo_univ f _) finite_univ obtain ⟨hq1 : (q₁.num : ZMod m.natAbs) = q₂.num, hq2 : (q₁.den : ZMod m.natAbs) = q₂.den⟩ := Prod.ext_iff.mp hqf have hd₁ : m ∣ q₁.num * q₂.num - d * (q₁.den * q₂.den) := by rw [← Int.natAbs_dvd, ← ZMod.intCast_zmod_eq_zero_iff_dvd] push_cast rw [hq1, hq2, ← sq, ← sq] norm_cast rw [ZMod.intCast_zmod_eq_zero_iff_dvd, Int.natAbs_dvd, Nat.cast_pow, ← h₂] have hd₂ : m ∣ q₁.num * q₂.den - q₂.num * q₁.den := by rw [← Int.natAbs_dvd, ← ZMod.intCast_eq_intCast_iff_dvd_sub] push_cast rw [hq1, hq2] replace hm₀ : (m : ℚ) ≠ 0 := Int.cast_ne_zero.mpr hm₀ refine ⟨(q₁.num * q₂.num - d * (q₁.den * q₂.den)) / m, (q₁.num * q₂.den - q₂.num * q₁.den) / m, ?_, ?_⟩ · qify [hd₁, hd₂] field_simp [hm₀] norm_cast conv_rhs => rw [sq] congr · rw [← h₁] · rw [← h₂] push_cast ring · qify [hd₂] refine div_ne_zero_iff.mpr ⟨?_, hm₀⟩ exact mod_cast mt sub_eq_zero.mp (mt Rat.eq_iff_mul_eq_mul.mpr hne) /-- If `d` is a positive integer, then there is a nontrivial solution to the Pell equation `x^2 - d*y^2 = 1` if and only if `d` is not a square. -/ theorem exists_iff_not_isSquare (h₀ : 0 < d) : (∃ x y : ℤ, x ^ 2 - d * y ^ 2 = 1 ∧ y ≠ 0) ↔ ¬IsSquare d := by refine ⟨?_, exists_of_not_isSquare h₀⟩ rintro ⟨x, y, hxy, hy⟩ ⟨a, rfl⟩ rw [← sq, ← mul_pow, sq_sub_sq] at hxy simpa [hy, mul_self_pos.mp h₀, sub_eq_add_neg, eq_neg_self_iff] using Int.eq_of_mul_eq_one hxy namespace Solution₁ /-- If `d` is a positive integer that is not a square, then there exists a nontrivial solution to the Pell equation `x^2 - d*y^2 = 1`. -/ theorem exists_nontrivial_of_not_isSquare (h₀ : 0 < d) (hd : ¬IsSquare d) : ∃ a : Solution₁ d, a ≠ 1 ∧ a ≠ -1 := by obtain ⟨x, y, prop, hy⟩ := exists_of_not_isSquare h₀ hd refine ⟨mk x y prop, fun H => ?_, fun H => ?_⟩ <;> apply_fun Solution₁.y at H <;> simp [hy] at H /-- If `d` is a positive integer that is not a square, then there exists a solution to the Pell equation `x^2 - d*y^2 = 1` with `x > 1` and `y > 0`. -/ theorem exists_pos_of_not_isSquare (h₀ : 0 < d) (hd : ¬IsSquare d) : ∃ a : Solution₁ d, 1 < a.x ∧ 0 < a.y := by obtain ⟨x, y, h, hy⟩ := exists_of_not_isSquare h₀ hd refine ⟨mk |x| |y| (by rwa [sq_abs, sq_abs]), ?_, abs_pos.mpr hy⟩ rw [x_mk, ← one_lt_sq_iff_one_lt_abs, eq_add_of_sub_eq h, lt_add_iff_pos_right] exact mul_pos h₀ (sq_pos_of_ne_zero hy) end Solution₁ end Existence /-! ### Fundamental solutions We define the notion of a *fundamental solution* of Pell's equation and show that it exists and is unique (when `d` is positive and non-square) and generates the group of solutions up to sign. -/ variable {d : ℤ} /-- We define a solution to be *fundamental* if it has `x > 1` and `y > 0` and its `x` is the smallest possible among solutions with `x > 1`. -/ def IsFundamental (a : Solution₁ d) : Prop := 1 < a.x ∧ 0 < a.y ∧ ∀ {b : Solution₁ d}, 1 < b.x → a.x ≤ b.x namespace IsFundamental open Solution₁ /-- A fundamental solution has positive `x`. -/ theorem x_pos {a : Solution₁ d} (h : IsFundamental a) : 0 < a.x := zero_lt_one.trans h.1 /-- If a fundamental solution exists, then `d` must be positive. -/ theorem d_pos {a : Solution₁ d} (h : IsFundamental a) : 0 < d := d_pos_of_one_lt_x h.1 /-- If a fundamental solution exists, then `d` must be a non-square. -/ theorem d_nonsquare {a : Solution₁ d} (h : IsFundamental a) : ¬IsSquare d := d_nonsquare_of_one_lt_x h.1 /-- If there is a fundamental solution, it is unique. -/ theorem subsingleton {a b : Solution₁ d} (ha : IsFundamental a) (hb : IsFundamental b) : a = b := by have hx := le_antisymm (ha.2.2 hb.1) (hb.2.2 ha.1) refine Solution₁.ext hx ?_ have : d * a.y ^ 2 = d * b.y ^ 2 := by rw [a.prop_y, b.prop_y, hx] exact (sq_eq_sq ha.2.1.le hb.2.1.le).mp (Int.eq_of_mul_eq_mul_left ha.d_pos.ne' this) /-- If `d` is positive and not a square, then a fundamental solution exists. -/ theorem exists_of_not_isSquare (h₀ : 0 < d) (hd : ¬IsSquare d) : ∃ a : Solution₁ d, IsFundamental a := by obtain ⟨a, ha₁, ha₂⟩ := exists_pos_of_not_isSquare h₀ hd -- convert to `x : ℕ` to be able to use `Nat.find` have P : ∃ x' : ℕ, 1 < x' ∧ ∃ y' : ℤ, 0 < y' ∧ (x' : ℤ) ^ 2 - d * y' ^ 2 = 1 := by have hax := a.prop lift a.x to ℕ using by positivity with ax norm_cast at ha₁ exact ⟨ax, ha₁, a.y, ha₂, hax⟩ classical -- to avoid having to show that the predicate is decidable let x₁ := Nat.find P obtain ⟨hx, y₁, hy₀, hy₁⟩ := Nat.find_spec P refine ⟨mk x₁ y₁ hy₁, by rw [x_mk]; exact mod_cast hx, hy₀, fun {b} hb => ?_⟩ rw [x_mk] have hb' := (Int.toNat_of_nonneg <| zero_le_one.trans hb.le).symm have hb'' := hb rw [hb'] at hb ⊢ norm_cast at hb ⊢ refine Nat.find_min' P ⟨hb, |b.y|, abs_pos.mpr <| y_ne_zero_of_one_lt_x hb'', ?_⟩ rw [← hb', sq_abs] exact b.prop /-- The map sending an integer `n` to the `y`-coordinate of `a^n` for a fundamental solution `a` is stritcly increasing. -/ theorem y_strictMono {a : Solution₁ d} (h : IsFundamental a) : StrictMono fun n : ℤ => (a ^ n).y := by have H : ∀ n : ℤ, 0 ≤ n → (a ^ n).y < (a ^ (n + 1)).y := by intro n hn rw [← sub_pos, zpow_add, zpow_one, y_mul, add_sub_assoc] rw [show (a ^ n).y * a.x - (a ^ n).y = (a ^ n).y * (a.x - 1) by ring] refine add_pos_of_pos_of_nonneg (mul_pos (x_zpow_pos h.x_pos _) h.2.1) (mul_nonneg ?_ (by rw [sub_nonneg]; exact h.1.le)) rcases hn.eq_or_lt with (rfl | hn) · simp only [zpow_zero, y_one, le_refl] · exact (y_zpow_pos h.x_pos h.2.1 hn).le refine strictMono_int_of_lt_succ fun n => ?_ rcases le_or_lt 0 n with hn | hn · exact H n hn · let m : ℤ := -n - 1 have hm : n = -m - 1 := by simp only [m, neg_sub, sub_neg_eq_add, add_tsub_cancel_left] rw [hm, sub_add_cancel, ← neg_add', zpow_neg, zpow_neg, y_inv, y_inv, neg_lt_neg_iff] exact H _ (by omega) /-- If `a` is a fundamental solution, then `(a^m).y < (a^n).y` if and only if `m < n`. -/ theorem zpow_y_lt_iff_lt {a : Solution₁ d} (h : IsFundamental a) (m n : ℤ) : (a ^ m).y < (a ^ n).y ↔ m < n := by refine ⟨fun H => ?_, fun H => h.y_strictMono H⟩ contrapose! H exact h.y_strictMono.monotone H /-- The `n`th power of a fundamental solution is trivial if and only if `n = 0`. -/ theorem zpow_eq_one_iff {a : Solution₁ d} (h : IsFundamental a) (n : ℤ) : a ^ n = 1 ↔ n = 0 := by rw [← zpow_zero a] exact ⟨fun H => h.y_strictMono.injective (congr_arg Solution₁.y H), fun H => H ▸ rfl⟩ /-- A power of a fundamental solution is never equal to the negative of a power of this fundamental solution. -/ theorem zpow_ne_neg_zpow {a : Solution₁ d} (h : IsFundamental a) {n n' : ℤ} : a ^ n ≠ -a ^ n' := by intro hf apply_fun Solution₁.x at hf have H := x_zpow_pos h.x_pos n rw [hf, x_neg, lt_neg, neg_zero] at H exact lt_irrefl _ ((x_zpow_pos h.x_pos n').trans H) /-- The `x`-coordinate of a fundamental solution is a lower bound for the `x`-coordinate of any positive solution. -/ theorem x_le_x {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d} (hax : 1 < a.x) : a₁.x ≤ a.x := h.2.2 hax /-- The `y`-coordinate of a fundamental solution is a lower bound for the `y`-coordinate of any positive solution. -/ theorem y_le_y {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d} (hax : 1 < a.x) (hay : 0 < a.y) : a₁.y ≤ a.y := by have H : d * (a₁.y ^ 2 - a.y ^ 2) = a₁.x ^ 2 - a.x ^ 2 := by rw [a.prop_x, a₁.prop_x]; ring rw [← abs_of_pos hay, ← abs_of_pos h.2.1, ← sq_le_sq, ← mul_le_mul_left h.d_pos, ← sub_nonpos, ← mul_sub, H, sub_nonpos, sq_le_sq, abs_of_pos (zero_lt_one.trans h.1), abs_of_pos (zero_lt_one.trans hax)] exact h.x_le_x hax -- helper lemma for the next three results theorem x_mul_y_le_y_mul_x {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d} (hax : 1 < a.x) (hay : 0 < a.y) : a.x * a₁.y ≤ a.y * a₁.x := by rw [← abs_of_pos <| zero_lt_one.trans hax, ← abs_of_pos hay, ← abs_of_pos h.x_pos, ← abs_of_pos h.2.1, ← abs_mul, ← abs_mul, ← sq_le_sq, mul_pow, mul_pow, a.prop_x, a₁.prop_x, ← sub_nonneg] ring_nf rw [sub_nonneg, sq_le_sq, abs_of_pos hay, abs_of_pos h.2.1] exact h.y_le_y hax hay /-- If we multiply a positive solution with the inverse of a fundamental solution, the `y`-coordinate remains nonnegative. -/ theorem mul_inv_y_nonneg {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d} (hax : 1 < a.x) (hay : 0 < a.y) : 0 ≤ (a * a₁⁻¹).y := by simpa only [y_inv, mul_neg, y_mul, le_neg_add_iff_add_le, add_zero] using h.x_mul_y_le_y_mul_x hax hay /-- If we multiply a positive solution with the inverse of a fundamental solution, the `x`-coordinate stays positive. -/ theorem mul_inv_x_pos {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d} (hax : 1 < a.x) (hay : 0 < a.y) : 0 < (a * a₁⁻¹).x := by simp only [x_mul, x_inv, y_inv, mul_neg, lt_add_neg_iff_add_lt, zero_add] refine (mul_lt_mul_left <| zero_lt_one.trans hax).mp ?_ rw [(by ring : a.x * (d * (a.y * a₁.y)) = d * a.y * (a.x * a₁.y))] refine ((mul_le_mul_left <| mul_pos h.d_pos hay).mpr <| x_mul_y_le_y_mul_x h hax hay).trans_lt ?_ rw [← mul_assoc, mul_assoc d, ← sq, a.prop_y, ← sub_pos] ring_nf exact zero_lt_one.trans h.1 /-- If we multiply a positive solution with the inverse of a fundamental solution, the `x`-coordinate decreases. -/ theorem mul_inv_x_lt_x {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d} (hax : 1 < a.x) (hay : 0 < a.y) : (a * a₁⁻¹).x < a.x := by simp only [x_mul, x_inv, y_inv, mul_neg, add_neg_lt_iff_le_add'] refine (mul_lt_mul_left h.2.1).mp ?_ rw [(by ring : a₁.y * (a.x * a₁.x) = a.x * a₁.y * a₁.x)] refine ((mul_le_mul_right <| zero_lt_one.trans h.1).mpr <| x_mul_y_le_y_mul_x h hax hay).trans_lt ?_ rw [mul_assoc, ← sq, a₁.prop_x, ← sub_neg] -- Porting note: was `ring_nf` suffices a.y - a.x * a₁.y < 0 by convert this using 1; ring rw [sub_neg, ← abs_of_pos hay, ← abs_of_pos h.2.1, ← abs_of_pos <| zero_lt_one.trans hax, ← abs_mul, ← sq_lt_sq, mul_pow, a.prop_x] calc a.y ^ 2 = 1 * a.y ^ 2 := (one_mul _).symm _ ≤ d * a.y ^ 2 := (mul_le_mul_right <| sq_pos_of_pos hay).mpr h.d_pos _ < d * a.y ^ 2 + 1 := lt_add_one _ _ = (1 + d * a.y ^ 2) * 1 := by rw [add_comm, mul_one] _ ≤ (1 + d * a.y ^ 2) * a₁.y ^ 2 := (mul_le_mul_left (by have := h.d_pos; positivity)).mpr (sq_pos_of_pos h.2.1) /-- Any nonnegative solution is a power with nonnegative exponent of a fundamental solution. -/ theorem eq_pow_of_nonneg {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d} (hax : 0 < a.x) (hay : 0 ≤ a.y) : ∃ n : ℕ, a = a₁ ^ n := by lift a.x to ℕ using hax.le with ax hax' -- Porting note: added clear hax induction' ax using Nat.strong_induction_on with x ih generalizing a rcases hay.eq_or_lt with hy | hy · -- case 1: `a = 1` refine ⟨0, ?_⟩ simp only [pow_zero] ext <;> simp only [x_one, y_one] · have prop := a.prop rw [← hy, sq (0 : ℤ), zero_mul, mul_zero, sub_zero, sq_eq_one_iff] at prop refine prop.resolve_right fun hf => ?_ have := (hax.trans_eq hax').le.trans_eq hf norm_num at this · exact hy.symm · -- case 2: `a ≥ a₁` have hx₁ : 1 < a.x := by nlinarith [a.prop, h.d_pos] have hxx₁ := h.mul_inv_x_pos hx₁ hy have hxx₂ := h.mul_inv_x_lt_x hx₁ hy have hyy := h.mul_inv_y_nonneg hx₁ hy lift (a * a₁⁻¹).x to ℕ using hxx₁.le with x' hx' -- Porting note: `ih` has its arguments in a different order compared to lean 3. obtain ⟨n, hn⟩ := ih x' (mod_cast hxx₂.trans_eq hax'.symm) hyy hx' hxx₁ exact ⟨n + 1, by rw [pow_succ', ← hn, mul_comm a, ← mul_assoc, mul_inv_self, one_mul]⟩ /-- Every solution is, up to a sign, a power of a given fundamental solution. -/ theorem eq_zpow_or_neg_zpow {a₁ : Solution₁ d} (h : IsFundamental a₁) (a : Solution₁ d) : ∃ n : ℤ, a = a₁ ^ n ∨ a = -a₁ ^ n := by obtain ⟨b, hbx, hby, hb⟩ := exists_pos_variant h.d_pos a obtain ⟨n, hn⟩ := h.eq_pow_of_nonneg hbx hby rcases hb with (rfl | rfl | rfl | hb) · exact ⟨n, Or.inl (mod_cast hn)⟩ · exact ⟨-n, Or.inl (by simp [hn])⟩ · exact ⟨n, Or.inr (by simp [hn])⟩ · rw [Set.mem_singleton_iff] at hb rw [hb] exact ⟨-n, Or.inr (by simp [hn])⟩ end IsFundamental open Solution₁ IsFundamental /-- When `d` is positive and not a square, then the group of solutions to the Pell equation `x^2 - d*y^2 = 1` has a unique positive generator (up to sign). -/ theorem existsUnique_pos_generator (h₀ : 0 < d) (hd : ¬IsSquare d) : ∃! a₁ : Solution₁ d, 1 < a₁.x ∧ 0 < a₁.y ∧ ∀ a : Solution₁ d, ∃ n : ℤ, a = a₁ ^ n ∨ a = -a₁ ^ n := by obtain ⟨a₁, ha₁⟩ := IsFundamental.exists_of_not_isSquare h₀ hd refine ⟨a₁, ⟨ha₁.1, ha₁.2.1, ha₁.eq_zpow_or_neg_zpow⟩, fun a (H : 1 < _ ∧ _) => ?_⟩ obtain ⟨Hx, Hy, H⟩ := H obtain ⟨n₁, hn₁⟩ := H a₁ obtain ⟨n₂, hn₂⟩ := ha₁.eq_zpow_or_neg_zpow a rcases hn₂ with (rfl | rfl) · rw [← zpow_mul, eq_comm, @eq_comm _ a₁, ← mul_inv_eq_one, ← @mul_inv_eq_one _ _ _ a₁, ← zpow_neg_one, neg_mul, ← zpow_add, ← sub_eq_add_neg] at hn₁ cases' hn₁ with hn₁ hn₁ · rcases Int.isUnit_iff.mp (isUnit_of_mul_eq_one _ _ <| sub_eq_zero.mp <| (ha₁.zpow_eq_one_iff (n₂ * n₁ - 1)).mp hn₁) with (rfl | rfl) · rw [zpow_one] · rw [zpow_neg_one, y_inv, lt_neg, neg_zero] at Hy exact False.elim (lt_irrefl _ <| ha₁.2.1.trans Hy) · rw [← zpow_zero a₁, eq_comm] at hn₁ exact False.elim (ha₁.zpow_ne_neg_zpow hn₁) · rw [x_neg, lt_neg] at Hx have := (x_zpow_pos (zero_lt_one.trans ha₁.1) n₂).trans Hx norm_num at this /-- A positive solution is a generator (up to sign) of the group of all solutions to the Pell equation `x^2 - d*y^2 = 1` if and only if it is a fundamental solution. -/ theorem pos_generator_iff_fundamental (a : Solution₁ d) : (1 < a.x ∧ 0 < a.y ∧ ∀ b : Solution₁ d, ∃ n : ℤ, b = a ^ n ∨ b = -a ^ n) ↔ IsFundamental a := by refine ⟨fun h => ?_, fun H => ⟨H.1, H.2.1, H.eq_zpow_or_neg_zpow⟩⟩ have h₀ := d_pos_of_one_lt_x h.1 have hd := d_nonsquare_of_one_lt_x h.1 obtain ⟨a₁, ha₁⟩ := IsFundamental.exists_of_not_isSquare h₀ hd obtain ⟨b, -, hb₂⟩ := existsUnique_pos_generator h₀ hd rwa [hb₂ a h, ← hb₂ a₁ ⟨ha₁.1, ha₁.2.1, ha₁.eq_zpow_or_neg_zpow⟩] end Pell
NumberTheory\PellMatiyasevic.lean
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Order.Group.Basic import Mathlib.Algebra.Order.Ring.Basic import Mathlib.Data.Nat.ModEq import Mathlib.NumberTheory.Zsqrtd.Basic /-! # Pell's equation and Matiyasevic's theorem This file solves Pell's equation, i.e. integer solutions to `x ^ 2 - d * y ^ 2 = 1` *in the special case that `d = a ^ 2 - 1`*. This is then applied to prove Matiyasevic's theorem that the power function is Diophantine, which is the last key ingredient in the solution to Hilbert's tenth problem. For the definition of Diophantine function, see `NumberTheory.Dioph`. For results on Pell's equation for arbitrary (positive, non-square) `d`, see `NumberTheory.Pell`. ## Main definition * `pell` is a function assigning to a natural number `n` the `n`-th solution to Pell's equation constructed recursively from the initial solution `(0, 1)`. ## Main statements * `eq_pell` shows that every solution to Pell's equation is recursively obtained using `pell` * `matiyasevic` shows that a certain system of Diophantine equations has a solution if and only if the first variable is the `x`-component in a solution to Pell's equation - the key step towards Hilbert's tenth problem in Davis' version of Matiyasevic's theorem. * `eq_pow_of_pell` shows that the power function is Diophantine. ## Implementation notes The proof of Matiyasevic's theorem doesn't follow Matiyasevic's original account of using Fibonacci numbers but instead Davis' variant of using solutions to Pell's equation. ## References * [M. Carneiro, _A Lean formalization of Matiyasevič's theorem_][carneiro2018matiyasevic] * [M. Davis, _Hilbert's tenth problem is unsolvable_][MR317916] ## Tags Pell's equation, Matiyasevic's theorem, Hilbert's tenth problem -/ namespace Pell open Nat section variable {d : ℤ} /-- The property of being a solution to the Pell equation, expressed as a property of elements of `ℤ√d`. -/ def IsPell : ℤ√d → Prop | ⟨x, y⟩ => x * x - d * y * y = 1 theorem isPell_norm : ∀ {b : ℤ√d}, IsPell b ↔ b * star b = 1 | ⟨x, y⟩ => by simp [Zsqrtd.ext_iff, IsPell, mul_comm]; ring_nf theorem isPell_iff_mem_unitary : ∀ {b : ℤ√d}, IsPell b ↔ b ∈ unitary (ℤ√d) | ⟨x, y⟩ => by rw [unitary.mem_iff, isPell_norm, mul_comm (star _), and_self_iff] theorem isPell_mul {b c : ℤ√d} (hb : IsPell b) (hc : IsPell c) : IsPell (b * c) := isPell_norm.2 (by simp [mul_comm, mul_left_comm c, mul_assoc, star_mul, isPell_norm.1 hb, isPell_norm.1 hc]) theorem isPell_star : ∀ {b : ℤ√d}, IsPell b ↔ IsPell (star b) | ⟨x, y⟩ => by simp [IsPell, Zsqrtd.star_mk] end section -- Porting note: was parameter in Lean3 variable {a : ℕ} (a1 : 1 < a) private def d (_a1 : 1 < a) := a * a - 1 @[simp] theorem d_pos : 0 < d a1 := tsub_pos_of_lt (mul_lt_mul a1 (le_of_lt a1) (by decide) (Nat.zero_le _) : 1 * 1 < a * a) -- TODO(lint): Fix double namespace issue /-- The Pell sequences, i.e. the sequence of integer solutions to `x ^ 2 - d * y ^ 2 = 1`, where `d = a ^ 2 - 1`, defined together in mutual recursion. -/ --@[nolint dup_namespace] def pell : ℕ → ℕ × ℕ -- Porting note: used pattern matching because `Nat.recOn` is noncomputable | 0 => (1, 0) | n+1 => ((pell n).1 * a + d a1 * (pell n).2, (pell n).1 + (pell n).2 * a) /-- The Pell `x` sequence. -/ def xn (n : ℕ) : ℕ := (pell a1 n).1 /-- The Pell `y` sequence. -/ def yn (n : ℕ) : ℕ := (pell a1 n).2 @[simp] theorem pell_val (n : ℕ) : pell a1 n = (xn a1 n, yn a1 n) := show pell a1 n = ((pell a1 n).1, (pell a1 n).2) from match pell a1 n with | (_, _) => rfl @[simp] theorem xn_zero : xn a1 0 = 1 := rfl @[simp] theorem yn_zero : yn a1 0 = 0 := rfl @[simp] theorem xn_succ (n : ℕ) : xn a1 (n + 1) = xn a1 n * a + d a1 * yn a1 n := rfl @[simp] theorem yn_succ (n : ℕ) : yn a1 (n + 1) = xn a1 n + yn a1 n * a := rfl --@[simp] Porting note (#10618): `simp` can prove it theorem xn_one : xn a1 1 = a := by simp --@[simp] Porting note (#10618): `simp` can prove it theorem yn_one : yn a1 1 = 1 := by simp /-- The Pell `x` sequence, considered as an integer sequence. -/ def xz (n : ℕ) : ℤ := xn a1 n /-- The Pell `y` sequence, considered as an integer sequence. -/ def yz (n : ℕ) : ℤ := yn a1 n section /-- The element `a` such that `d = a ^ 2 - 1`, considered as an integer. -/ def az (a : ℕ) : ℤ := a end theorem asq_pos : 0 < a * a := le_trans (le_of_lt a1) (by have := @Nat.mul_le_mul_left 1 a a (le_of_lt a1); rwa [mul_one] at this) theorem dz_val : ↑(d a1) = az a * az a - 1 := have : 1 ≤ a * a := asq_pos a1 by rw [Pell.d, Int.ofNat_sub this]; rfl @[simp] theorem xz_succ (n : ℕ) : (xz a1 (n + 1)) = xz a1 n * az a + d a1 * yz a1 n := rfl @[simp] theorem yz_succ (n : ℕ) : yz a1 (n + 1) = xz a1 n + yz a1 n * az a := rfl /-- The Pell sequence can also be viewed as an element of `ℤ√d` -/ def pellZd (n : ℕ) : ℤ√(d a1) := ⟨xn a1 n, yn a1 n⟩ @[simp] theorem pellZd_re (n : ℕ) : (pellZd a1 n).re = xn a1 n := rfl @[simp] theorem pellZd_im (n : ℕ) : (pellZd a1 n).im = yn a1 n := rfl theorem isPell_nat {x y : ℕ} : IsPell (⟨x, y⟩ : ℤ√(d a1)) ↔ x * x - d a1 * y * y = 1 := ⟨fun h => Nat.cast_inj.1 (by rw [Int.ofNat_sub (Int.le_of_ofNat_le_ofNat <| Int.le.intro_sub _ h)]; exact h), fun h => show ((x * x : ℕ) - (d a1 * y * y : ℕ) : ℤ) = 1 by rw [← Int.ofNat_sub <| le_of_lt <| Nat.lt_of_sub_eq_succ h, h]; rfl⟩ @[simp] theorem pellZd_succ (n : ℕ) : pellZd a1 (n + 1) = pellZd a1 n * ⟨a, 1⟩ := by ext <;> simp theorem isPell_one : IsPell (⟨a, 1⟩ : ℤ√(d a1)) := show az a * az a - d a1 * 1 * 1 = 1 by simp [dz_val] theorem isPell_pellZd : ∀ n : ℕ, IsPell (pellZd a1 n) | 0 => rfl | n + 1 => by let o := isPell_one a1 simpa using Pell.isPell_mul (isPell_pellZd n) o @[simp] theorem pell_eqz (n : ℕ) : xz a1 n * xz a1 n - d a1 * yz a1 n * yz a1 n = 1 := isPell_pellZd a1 n @[simp] theorem pell_eq (n : ℕ) : xn a1 n * xn a1 n - d a1 * yn a1 n * yn a1 n = 1 := let pn := pell_eqz a1 n have h : (↑(xn a1 n * xn a1 n) : ℤ) - ↑(d a1 * yn a1 n * yn a1 n) = 1 := by repeat' rw [Int.ofNat_mul]; exact pn have hl : d a1 * yn a1 n * yn a1 n ≤ xn a1 n * xn a1 n := Nat.cast_le.1 <| Int.le.intro _ <| add_eq_of_eq_sub' <| Eq.symm h Nat.cast_inj.1 (by rw [Int.ofNat_sub hl]; exact h) instance dnsq : Zsqrtd.Nonsquare (d a1) := ⟨fun n h => have : n * n + 1 = a * a := by rw [← h]; exact Nat.succ_pred_eq_of_pos (asq_pos a1) have na : n < a := Nat.mul_self_lt_mul_self_iff.1 (by rw [← this]; exact Nat.lt_succ_self _) have : (n + 1) * (n + 1) ≤ n * n + 1 := by rw [this]; exact Nat.mul_self_le_mul_self na have : n + n ≤ 0 := @Nat.le_of_add_le_add_right _ (n * n + 1) _ (by ring_nf at this ⊢; assumption) Nat.ne_of_gt (d_pos a1) <| by rwa [Nat.eq_zero_of_le_zero ((Nat.le_add_left _ _).trans this)] at h⟩ theorem xn_ge_a_pow : ∀ n : ℕ, a ^ n ≤ xn a1 n | 0 => le_refl 1 | n + 1 => by simp only [_root_.pow_succ, xn_succ] exact le_trans (Nat.mul_le_mul_right _ (xn_ge_a_pow n)) (Nat.le_add_right _ _) theorem n_lt_a_pow : ∀ n : ℕ, n < a ^ n | 0 => Nat.le_refl 1 | n + 1 => by have IH := n_lt_a_pow n have : a ^ n + a ^ n ≤ a ^ n * a := by rw [← mul_two] exact Nat.mul_le_mul_left _ a1 simp only [_root_.pow_succ, gt_iff_lt] refine lt_of_lt_of_le ?_ this exact add_lt_add_of_lt_of_le IH (lt_of_le_of_lt (Nat.zero_le _) IH) theorem n_lt_xn (n) : n < xn a1 n := lt_of_lt_of_le (n_lt_a_pow a1 n) (xn_ge_a_pow a1 n) theorem x_pos (n) : 0 < xn a1 n := lt_of_le_of_lt (Nat.zero_le n) (n_lt_xn a1 n) theorem eq_pell_lem : ∀ (n) (b : ℤ√(d a1)), 1 ≤ b → IsPell b → b ≤ pellZd a1 n → ∃ n, b = pellZd a1 n | 0, b => fun h1 _ hl => ⟨0, @Zsqrtd.le_antisymm _ (dnsq a1) _ _ hl h1⟩ | n + 1, b => fun h1 hp h => have a1p : (0 : ℤ√(d a1)) ≤ ⟨a, 1⟩ := trivial have am1p : (0 : ℤ√(d a1)) ≤ ⟨a, -1⟩ := show (_ : Nat) ≤ _ by simp; exact Nat.pred_le _ have a1m : (⟨a, 1⟩ * ⟨a, -1⟩ : ℤ√(d a1)) = 1 := isPell_norm.1 (isPell_one a1) if ha : (⟨↑a, 1⟩ : ℤ√(d a1)) ≤ b then let ⟨m, e⟩ := eq_pell_lem n (b * ⟨a, -1⟩) (by rw [← a1m]; exact mul_le_mul_of_nonneg_right ha am1p) (isPell_mul hp (isPell_star.1 (isPell_one a1))) (by have t := mul_le_mul_of_nonneg_right h am1p rwa [pellZd_succ, mul_assoc, a1m, mul_one] at t) ⟨m + 1, by rw [show b = b * ⟨a, -1⟩ * ⟨a, 1⟩ by rw [mul_assoc, Eq.trans (mul_comm _ _) a1m]; simp, pellZd_succ, e]⟩ else suffices ¬1 < b from ⟨0, show b = 1 from (Or.resolve_left (lt_or_eq_of_le h1) this).symm⟩ fun h1l => by cases' b with x y exact by have bm : (_ * ⟨_, _⟩ : ℤ√d a1) = 1 := Pell.isPell_norm.1 hp have y0l : (0 : ℤ√d a1) < ⟨x - x, y - -y⟩ := sub_lt_sub h1l fun hn : (1 : ℤ√d a1) ≤ ⟨x, -y⟩ => by have t := mul_le_mul_of_nonneg_left hn (le_trans zero_le_one h1) erw [bm, mul_one] at t exact h1l t have yl2 : (⟨_, _⟩ : ℤ√_) < ⟨_, _⟩ := show (⟨x, y⟩ - ⟨x, -y⟩ : ℤ√d a1) < ⟨a, 1⟩ - ⟨a, -1⟩ from sub_lt_sub ha fun hn : (⟨x, -y⟩ : ℤ√d a1) ≤ ⟨a, -1⟩ => by have t := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hn (le_trans zero_le_one h1)) a1p erw [bm, one_mul, mul_assoc, Eq.trans (mul_comm _ _) a1m, mul_one] at t exact ha t simp only [sub_self, sub_neg_eq_add] at y0l; simp only [Zsqrtd.neg_re, add_right_neg, Zsqrtd.neg_im, neg_neg] at yl2 exact match y, y0l, (yl2 : (⟨_, _⟩ : ℤ√_) < ⟨_, _⟩) with | 0, y0l, _ => y0l (le_refl 0) | (y + 1 : ℕ), _, yl2 => yl2 (Zsqrtd.le_of_le_le (by simp [sub_eq_add_neg]) (let t := Int.ofNat_le_ofNat_of_le (Nat.succ_pos y) add_le_add t t)) | Int.negSucc _, y0l, _ => y0l trivial theorem eq_pellZd (b : ℤ√(d a1)) (b1 : 1 ≤ b) (hp : IsPell b) : ∃ n, b = pellZd a1 n := let ⟨n, h⟩ := @Zsqrtd.le_arch (d a1) b eq_pell_lem a1 n b b1 hp <| h.trans <| by rw [Zsqrtd.natCast_val] exact Zsqrtd.le_of_le_le (Int.ofNat_le_ofNat_of_le <| le_of_lt <| n_lt_xn _ _) (Int.ofNat_zero_le _) /-- Every solution to **Pell's equation** is recursively obtained from the initial solution `(1,0)` using the recursion `pell`. -/ theorem eq_pell {x y : ℕ} (hp : x * x - d a1 * y * y = 1) : ∃ n, x = xn a1 n ∧ y = yn a1 n := have : (1 : ℤ√(d a1)) ≤ ⟨x, y⟩ := match x, hp with | 0, (hp : 0 - _ = 1) => by rw [zero_tsub] at hp; contradiction | x + 1, _hp => Zsqrtd.le_of_le_le (Int.ofNat_le_ofNat_of_le <| Nat.succ_pos x) (Int.ofNat_zero_le _) let ⟨m, e⟩ := eq_pellZd a1 ⟨x, y⟩ this ((isPell_nat a1).2 hp) ⟨m, match x, y, e with | _, _, rfl => ⟨rfl, rfl⟩⟩ theorem pellZd_add (m) : ∀ n, pellZd a1 (m + n) = pellZd a1 m * pellZd a1 n | 0 => (mul_one _).symm | n + 1 => by rw [← add_assoc, pellZd_succ, pellZd_succ, pellZd_add _ n, ← mul_assoc] theorem xn_add (m n) : xn a1 (m + n) = xn a1 m * xn a1 n + d a1 * yn a1 m * yn a1 n := by injection pellZd_add a1 m n with h _ zify rw [h] simp [pellZd] theorem yn_add (m n) : yn a1 (m + n) = xn a1 m * yn a1 n + yn a1 m * xn a1 n := by injection pellZd_add a1 m n with _ h zify rw [h] simp [pellZd] theorem pellZd_sub {m n} (h : n ≤ m) : pellZd a1 (m - n) = pellZd a1 m * star (pellZd a1 n) := by let t := pellZd_add a1 n (m - n) rw [add_tsub_cancel_of_le h] at t rw [t, mul_comm (pellZd _ n) _, mul_assoc, isPell_norm.1 (isPell_pellZd _ _), mul_one] theorem xz_sub {m n} (h : n ≤ m) : xz a1 (m - n) = xz a1 m * xz a1 n - d a1 * yz a1 m * yz a1 n := by rw [sub_eq_add_neg, ← mul_neg] exact congr_arg Zsqrtd.re (pellZd_sub a1 h) theorem yz_sub {m n} (h : n ≤ m) : yz a1 (m - n) = xz a1 n * yz a1 m - xz a1 m * yz a1 n := by rw [sub_eq_add_neg, ← mul_neg, mul_comm, add_comm] exact congr_arg Zsqrtd.im (pellZd_sub a1 h) theorem xy_coprime (n) : (xn a1 n).Coprime (yn a1 n) := Nat.coprime_of_dvd' fun k _ kx ky => by let p := pell_eq a1 n rw [← p] exact Nat.dvd_sub (le_of_lt <| Nat.lt_of_sub_eq_succ p) (kx.mul_left _) (ky.mul_left _) theorem strictMono_y : StrictMono (yn a1) | m, 0, h => absurd h <| Nat.not_lt_zero _ | m, n + 1, h => by have : yn a1 m ≤ yn a1 n := Or.elim (lt_or_eq_of_le <| Nat.le_of_succ_le_succ h) (fun hl => le_of_lt <| strictMono_y hl) fun e => by rw [e] simp; refine lt_of_le_of_lt ?_ (Nat.lt_add_of_pos_left <| x_pos a1 n) rw [← mul_one (yn a1 m)] exact mul_le_mul this (le_of_lt a1) (Nat.zero_le _) (Nat.zero_le _) theorem strictMono_x : StrictMono (xn a1) | m, 0, h => absurd h <| Nat.not_lt_zero _ | m, n + 1, h => by have : xn a1 m ≤ xn a1 n := Or.elim (lt_or_eq_of_le <| Nat.le_of_succ_le_succ h) (fun hl => le_of_lt <| strictMono_x hl) fun e => by rw [e] simp; refine lt_of_lt_of_le (lt_of_le_of_lt this ?_) (Nat.le_add_right _ _) have t := Nat.mul_lt_mul_of_pos_left a1 (x_pos a1 n) rwa [mul_one] at t theorem yn_ge_n : ∀ n, n ≤ yn a1 n | 0 => Nat.zero_le _ | n + 1 => show n < yn a1 (n + 1) from lt_of_le_of_lt (yn_ge_n n) (strictMono_y a1 <| Nat.lt_succ_self n) theorem y_mul_dvd (n) : ∀ k, yn a1 n ∣ yn a1 (n * k) | 0 => dvd_zero _ | k + 1 => by rw [Nat.mul_succ, yn_add]; exact dvd_add (dvd_mul_left _ _) ((y_mul_dvd _ k).mul_right _) theorem y_dvd_iff (m n) : yn a1 m ∣ yn a1 n ↔ m ∣ n := ⟨fun h => Nat.dvd_of_mod_eq_zero <| (Nat.eq_zero_or_pos _).resolve_right fun hp => by have co : Nat.Coprime (yn a1 m) (xn a1 (m * (n / m))) := Nat.Coprime.symm <| (xy_coprime a1 _).coprime_dvd_right (y_mul_dvd a1 m (n / m)) have m0 : 0 < m := m.eq_zero_or_pos.resolve_left fun e => by rw [e, Nat.mod_zero] at hp;rw [e] at h exact _root_.ne_of_lt (strictMono_y a1 hp) (eq_zero_of_zero_dvd h).symm rw [← Nat.mod_add_div n m, yn_add] at h exact not_le_of_gt (strictMono_y _ <| Nat.mod_lt n m0) (Nat.le_of_dvd (strictMono_y _ hp) <| co.dvd_of_dvd_mul_right <| (Nat.dvd_add_iff_right <| (y_mul_dvd _ _ _).mul_left _).2 h), fun ⟨k, e⟩ => by rw [e]; apply y_mul_dvd⟩ theorem xy_modEq_yn (n) : ∀ k, xn a1 (n * k) ≡ xn a1 n ^ k [MOD yn a1 n ^ 2] ∧ yn a1 (n * k) ≡ k * xn a1 n ^ (k - 1) * yn a1 n [MOD yn a1 n ^ 3] | 0 => by constructor <;> simpa using Nat.ModEq.refl _ | k + 1 => by let ⟨hx, hy⟩ := xy_modEq_yn n k have L : xn a1 (n * k) * xn a1 n + d a1 * yn a1 (n * k) * yn a1 n ≡ xn a1 n ^ k * xn a1 n + 0 [MOD yn a1 n ^ 2] := (hx.mul_right _).add <| modEq_zero_iff_dvd.2 <| by rw [_root_.pow_succ] exact mul_dvd_mul_right (dvd_mul_of_dvd_right (modEq_zero_iff_dvd.1 <| (hy.of_dvd <| by simp [_root_.pow_succ]).trans <| modEq_zero_iff_dvd.2 <| by simp) _) _ have R : xn a1 (n * k) * yn a1 n + yn a1 (n * k) * xn a1 n ≡ xn a1 n ^ k * yn a1 n + k * xn a1 n ^ k * yn a1 n [MOD yn a1 n ^ 3] := ModEq.add (by rw [_root_.pow_succ] exact hx.mul_right' _) <| by have : k * xn a1 n ^ (k - 1) * yn a1 n * xn a1 n = k * xn a1 n ^ k * yn a1 n := by cases' k with k <;> simp [_root_.pow_succ]; ring_nf rw [← this] exact hy.mul_right _ rw [add_tsub_cancel_right, Nat.mul_succ, xn_add, yn_add, pow_succ (xn _ n), Nat.succ_mul, add_comm (k * xn _ n ^ k) (xn _ n ^ k), right_distrib] exact ⟨L, R⟩ theorem ysq_dvd_yy (n) : yn a1 n * yn a1 n ∣ yn a1 (n * yn a1 n) := modEq_zero_iff_dvd.1 <| ((xy_modEq_yn a1 n (yn a1 n)).right.of_dvd <| by simp [_root_.pow_succ]).trans (modEq_zero_iff_dvd.2 <| by simp [mul_dvd_mul_left, mul_assoc]) theorem dvd_of_ysq_dvd {n t} (h : yn a1 n * yn a1 n ∣ yn a1 t) : yn a1 n ∣ t := have nt : n ∣ t := (y_dvd_iff a1 n t).1 <| dvd_of_mul_left_dvd h n.eq_zero_or_pos.elim (fun n0 => by rwa [n0] at nt ⊢) fun n0l : 0 < n => by let ⟨k, ke⟩ := nt have : yn a1 n ∣ k * xn a1 n ^ (k - 1) := Nat.dvd_of_mul_dvd_mul_right (strictMono_y a1 n0l) <| modEq_zero_iff_dvd.1 <| by have xm := (xy_modEq_yn a1 n k).right; rw [← ke] at xm exact (xm.of_dvd <| by simp [_root_.pow_succ]).symm.trans h.modEq_zero_nat rw [ke] exact dvd_mul_of_dvd_right (((xy_coprime _ _).pow_left _).symm.dvd_of_dvd_mul_right this) _ theorem pellZd_succ_succ (n) : pellZd a1 (n + 2) + pellZd a1 n = (2 * a : ℕ) * pellZd a1 (n + 1) := by have : (1 : ℤ√(d a1)) + ⟨a, 1⟩ * ⟨a, 1⟩ = ⟨a, 1⟩ * (2 * a) := by rw [Zsqrtd.natCast_val] change (⟨_, _⟩ : ℤ√(d a1)) = ⟨_, _⟩ rw [dz_val] dsimp [az] ext <;> dsimp <;> ring_nf simpa [mul_add, mul_comm, mul_left_comm, add_comm] using congr_arg (· * pellZd a1 n) this theorem xy_succ_succ (n) : xn a1 (n + 2) + xn a1 n = 2 * a * xn a1 (n + 1) ∧ yn a1 (n + 2) + yn a1 n = 2 * a * yn a1 (n + 1) := by have := pellZd_succ_succ a1 n; unfold pellZd at this erw [Zsqrtd.smul_val (2 * a : ℕ)] at this injection this with h₁ h₂ constructor <;> apply Int.ofNat.inj <;> [simpa using h₁; simpa using h₂] theorem xn_succ_succ (n) : xn a1 (n + 2) + xn a1 n = 2 * a * xn a1 (n + 1) := (xy_succ_succ a1 n).1 theorem yn_succ_succ (n) : yn a1 (n + 2) + yn a1 n = 2 * a * yn a1 (n + 1) := (xy_succ_succ a1 n).2 theorem xz_succ_succ (n) : xz a1 (n + 2) = (2 * a : ℕ) * xz a1 (n + 1) - xz a1 n := eq_sub_of_add_eq <| by delta xz; rw [← Int.ofNat_add, ← Int.ofNat_mul, xn_succ_succ] theorem yz_succ_succ (n) : yz a1 (n + 2) = (2 * a : ℕ) * yz a1 (n + 1) - yz a1 n := eq_sub_of_add_eq <| by delta yz; rw [← Int.ofNat_add, ← Int.ofNat_mul, yn_succ_succ] theorem yn_modEq_a_sub_one : ∀ n, yn a1 n ≡ n [MOD a - 1] | 0 => by simp [Nat.ModEq.refl] | 1 => by simp [Nat.ModEq.refl] | n + 2 => (yn_modEq_a_sub_one n).add_right_cancel <| by rw [yn_succ_succ, (by ring : n + 2 + n = 2 * (n + 1))] exact ((modEq_sub a1.le).mul_left 2).mul (yn_modEq_a_sub_one (n + 1)) theorem yn_modEq_two : ∀ n, yn a1 n ≡ n [MOD 2] | 0 => by rfl | 1 => by simp; rfl | n + 2 => (yn_modEq_two n).add_right_cancel <| by rw [yn_succ_succ, mul_assoc, (by ring : n + 2 + n = 2 * (n + 1))] exact (dvd_mul_right 2 _).modEq_zero_nat.trans (dvd_mul_right 2 _).zero_modEq_nat section theorem x_sub_y_dvd_pow_lem (y2 y1 y0 yn1 yn0 xn1 xn0 ay a2 : ℤ) : (a2 * yn1 - yn0) * ay + y2 - (a2 * xn1 - xn0) = y2 - a2 * y1 + y0 + a2 * (yn1 * ay + y1 - xn1) - (yn0 * ay + y0 - xn0) := by ring end theorem x_sub_y_dvd_pow (y : ℕ) : ∀ n, (2 * a * y - y * y - 1 : ℤ) ∣ yz a1 n * (a - y) + ↑(y ^ n) - xz a1 n | 0 => by simp [xz, yz, Int.ofNat_zero, Int.ofNat_one] | 1 => by simp [xz, yz, Int.ofNat_zero, Int.ofNat_one] | n + 2 => by have : (2 * a * y - y * y - 1 : ℤ) ∣ ↑(y ^ (n + 2)) - ↑(2 * a) * ↑(y ^ (n + 1)) + ↑(y ^ n) := ⟨-↑(y ^ n), by simp [_root_.pow_succ, mul_add, Int.ofNat_mul, show ((2 : ℕ) : ℤ) = 2 from rfl, mul_comm, mul_left_comm] ring⟩ rw [xz_succ_succ, yz_succ_succ, x_sub_y_dvd_pow_lem ↑(y ^ (n + 2)) ↑(y ^ (n + 1)) ↑(y ^ n)] exact _root_.dvd_sub (dvd_add this <| (x_sub_y_dvd_pow _ (n + 1)).mul_left _) (x_sub_y_dvd_pow _ n) theorem xn_modEq_x2n_add_lem (n j) : xn a1 n ∣ d a1 * yn a1 n * (yn a1 n * xn a1 j) + xn a1 j := by have h1 : d a1 * yn a1 n * (yn a1 n * xn a1 j) + xn a1 j = (d a1 * yn a1 n * yn a1 n + 1) * xn a1 j := by simp [add_mul, mul_assoc] have h2 : d a1 * yn a1 n * yn a1 n + 1 = xn a1 n * xn a1 n := by zify at * apply add_eq_of_eq_sub' (Eq.symm (pell_eqz a1 n)) rw [h2] at h1; rw [h1, mul_assoc]; exact dvd_mul_right _ _ theorem xn_modEq_x2n_add (n j) : xn a1 (2 * n + j) + xn a1 j ≡ 0 [MOD xn a1 n] := by rw [two_mul, add_assoc, xn_add, add_assoc, ← zero_add 0] refine (dvd_mul_right (xn a1 n) (xn a1 (n + j))).modEq_zero_nat.add ?_ rw [yn_add, left_distrib, add_assoc, ← zero_add 0] exact ((dvd_mul_right _ _).mul_left _).modEq_zero_nat.add (xn_modEq_x2n_add_lem _ _ _).modEq_zero_nat theorem xn_modEq_x2n_sub_lem {n j} (h : j ≤ n) : xn a1 (2 * n - j) + xn a1 j ≡ 0 [MOD xn a1 n] := by have h1 : xz a1 n ∣ d a1 * yz a1 n * yz a1 (n - j) + xz a1 j := by rw [yz_sub _ h, mul_sub_left_distrib, sub_add_eq_add_sub] exact dvd_sub (by delta xz; delta yz rw [mul_comm (xn _ _ : ℤ)] exact mod_cast (xn_modEq_x2n_add_lem _ n j)) ((dvd_mul_right _ _).mul_left _) rw [two_mul, add_tsub_assoc_of_le h, xn_add, add_assoc, ← zero_add 0] exact (dvd_mul_right _ _).modEq_zero_nat.add (Int.natCast_dvd_natCast.1 <| by simpa [xz, yz] using h1).modEq_zero_nat theorem xn_modEq_x2n_sub {n j} (h : j ≤ 2 * n) : xn a1 (2 * n - j) + xn a1 j ≡ 0 [MOD xn a1 n] := (le_total j n).elim (xn_modEq_x2n_sub_lem a1) fun jn => by have : 2 * n - j + j ≤ n + j := by rw [tsub_add_cancel_of_le h, two_mul]; exact Nat.add_le_add_left jn _ let t := xn_modEq_x2n_sub_lem a1 (Nat.le_of_add_le_add_right this) rwa [tsub_tsub_cancel_of_le h, add_comm] at t theorem xn_modEq_x4n_add (n j) : xn a1 (4 * n + j) ≡ xn a1 j [MOD xn a1 n] := ModEq.add_right_cancel' (xn a1 (2 * n + j)) <| by refine @ModEq.trans _ _ 0 _ ?_ (by rw [add_comm]; exact (xn_modEq_x2n_add _ _ _).symm) rw [show 4 * n = 2 * n + 2 * n from right_distrib 2 2 n, add_assoc] apply xn_modEq_x2n_add theorem xn_modEq_x4n_sub {n j} (h : j ≤ 2 * n) : xn a1 (4 * n - j) ≡ xn a1 j [MOD xn a1 n] := have h' : j ≤ 2 * n := le_trans h (by rw [Nat.succ_mul]) ModEq.add_right_cancel' (xn a1 (2 * n - j)) <| by refine @ModEq.trans _ _ 0 _ ?_ (by rw [add_comm]; exact (xn_modEq_x2n_sub _ h).symm) rw [show 4 * n = 2 * n + 2 * n from right_distrib 2 2 n, add_tsub_assoc_of_le h'] apply xn_modEq_x2n_add theorem eq_of_xn_modEq_lem1 {i n} : ∀ {j}, i < j → j < n → xn a1 i % xn a1 n < xn a1 j % xn a1 n | 0, ij, _ => absurd ij (Nat.not_lt_zero _) | j + 1, ij, jn => by suffices xn a1 j % xn a1 n < xn a1 (j + 1) % xn a1 n from (lt_or_eq_of_le (Nat.le_of_succ_le_succ ij)).elim (fun h => lt_trans (eq_of_xn_modEq_lem1 h (le_of_lt jn)) this) fun h => by rw [h]; exact this rw [Nat.mod_eq_of_lt (strictMono_x _ (Nat.lt_of_succ_lt jn)), Nat.mod_eq_of_lt (strictMono_x _ jn)] exact strictMono_x _ (Nat.lt_succ_self _) theorem eq_of_xn_modEq_lem2 {n} (h : 2 * xn a1 n = xn a1 (n + 1)) : a = 2 ∧ n = 0 := by rw [xn_succ, mul_comm] at h have : n = 0 := n.eq_zero_or_pos.resolve_right fun np => _root_.ne_of_lt (lt_of_le_of_lt (Nat.mul_le_mul_left _ a1) (Nat.lt_add_of_pos_right <| mul_pos (d_pos a1) (strictMono_y a1 np))) h cases this; simp at h; exact ⟨h.symm, rfl⟩ theorem eq_of_xn_modEq_lem3 {i n} (npos : 0 < n) : ∀ {j}, i < j → j ≤ 2 * n → j ≠ n → ¬(a = 2 ∧ n = 1 ∧ i = 0 ∧ j = 2) → xn a1 i % xn a1 n < xn a1 j % xn a1 n | 0, ij, _, _, _ => absurd ij (Nat.not_lt_zero _) | j + 1, ij, j2n, jnn, ntriv => have lem2 : ∀ k > n, k ≤ 2 * n → (↑(xn a1 k % xn a1 n) : ℤ) = xn a1 n - xn a1 (2 * n - k) := fun k kn k2n => by let k2nl := lt_of_add_lt_add_right <| show 2 * n - k + k < n + k by rw [tsub_add_cancel_of_le] · rw [two_mul] exact add_lt_add_left kn n exact k2n have xle : xn a1 (2 * n - k) ≤ xn a1 n := le_of_lt <| strictMono_x a1 k2nl suffices xn a1 k % xn a1 n = xn a1 n - xn a1 (2 * n - k) by rw [this, Int.ofNat_sub xle] rw [← Nat.mod_eq_of_lt (Nat.sub_lt (x_pos a1 n) (x_pos a1 (2 * n - k)))] apply ModEq.add_right_cancel' (xn a1 (2 * n - k)) rw [tsub_add_cancel_of_le xle] have t := xn_modEq_x2n_sub_lem a1 k2nl.le rw [tsub_tsub_cancel_of_le k2n] at t exact t.trans dvd_rfl.zero_modEq_nat (lt_trichotomy j n).elim (fun jn : j < n => eq_of_xn_modEq_lem1 _ ij (lt_of_le_of_ne jn jnn)) fun o => o.elim (fun jn : j = n => by cases jn apply Int.lt_of_ofNat_lt_ofNat rw [lem2 (n + 1) (Nat.lt_succ_self _) j2n, show 2 * n - (n + 1) = n - 1 by rw [two_mul, tsub_add_eq_tsub_tsub, add_tsub_cancel_right]] refine lt_sub_left_of_add_lt (Int.ofNat_lt_ofNat_of_lt ?_) rcases lt_or_eq_of_le <| Nat.le_of_succ_le_succ ij with lin | ein · rw [Nat.mod_eq_of_lt (strictMono_x _ lin)] have ll : xn a1 (n - 1) + xn a1 (n - 1) ≤ xn a1 n := by rw [← two_mul, mul_comm, show xn a1 n = xn a1 (n - 1 + 1) by rw [tsub_add_cancel_of_le (succ_le_of_lt npos)], xn_succ] exact le_trans (Nat.mul_le_mul_left _ a1) (Nat.le_add_right _ _) have npm : (n - 1).succ = n := Nat.succ_pred_eq_of_pos npos have il : i ≤ n - 1 := by apply Nat.le_of_succ_le_succ rw [npm] exact lin rcases lt_or_eq_of_le il with ill | ile · exact lt_of_lt_of_le (Nat.add_lt_add_left (strictMono_x a1 ill) _) ll · rw [ile] apply lt_of_le_of_ne ll rw [← two_mul] exact fun e => ntriv <| by let ⟨a2, s1⟩ := @eq_of_xn_modEq_lem2 _ a1 (n - 1) (by rwa [tsub_add_cancel_of_le (succ_le_of_lt npos)]) have n1 : n = 1 := le_antisymm (tsub_eq_zero_iff_le.mp s1) npos rw [ile, a2, n1]; exact ⟨rfl, rfl, rfl, rfl⟩ · rw [ein, Nat.mod_self, add_zero] exact strictMono_x _ (Nat.pred_lt npos.ne')) fun jn : j > n => have lem1 : j ≠ n → xn a1 j % xn a1 n < xn a1 (j + 1) % xn a1 n → xn a1 i % xn a1 n < xn a1 (j + 1) % xn a1 n := fun jn s => (lt_or_eq_of_le (Nat.le_of_succ_le_succ ij)).elim (fun h => lt_trans (eq_of_xn_modEq_lem3 npos h (le_of_lt (Nat.lt_of_succ_le j2n)) jn fun ⟨a1, n1, i0, j2⟩ => by rw [n1, j2] at j2n; exact absurd j2n (by decide)) s) fun h => by rw [h]; exact s lem1 (_root_.ne_of_gt jn) <| Int.lt_of_ofNat_lt_ofNat <| by rw [lem2 j jn (le_of_lt j2n), lem2 (j + 1) (Nat.le_succ_of_le jn) j2n] refine sub_lt_sub_left (Int.ofNat_lt_ofNat_of_lt <| strictMono_x _ ?_) _ rw [Nat.sub_succ] exact Nat.pred_lt (_root_.ne_of_gt <| tsub_pos_of_lt j2n) theorem eq_of_xn_modEq_le {i j n} (ij : i ≤ j) (j2n : j ≤ 2 * n) (h : xn a1 i ≡ xn a1 j [MOD xn a1 n]) (ntriv : ¬(a = 2 ∧ n = 1 ∧ i = 0 ∧ j = 2)) : i = j := if npos : n = 0 then by simp_all else (lt_or_eq_of_le ij).resolve_left fun ij' => if jn : j = n then by refine _root_.ne_of_gt ?_ h rw [jn, Nat.mod_self] have x0 : 0 < xn a1 0 % xn a1 n := by rw [Nat.mod_eq_of_lt (strictMono_x a1 (Nat.pos_of_ne_zero npos))] exact Nat.succ_pos _ cases' i with i · exact x0 rw [jn] at ij' exact x0.trans (eq_of_xn_modEq_lem3 _ (Nat.pos_of_ne_zero npos) (Nat.succ_pos _) (le_trans ij j2n) (_root_.ne_of_lt ij') fun ⟨_, n1, _, i2⟩ => by rw [n1, i2] at ij'; exact absurd ij' (by decide)) else _root_.ne_of_lt (eq_of_xn_modEq_lem3 a1 (Nat.pos_of_ne_zero npos) ij' j2n jn ntriv) h theorem eq_of_xn_modEq {i j n} (i2n : i ≤ 2 * n) (j2n : j ≤ 2 * n) (h : xn a1 i ≡ xn a1 j [MOD xn a1 n]) (ntriv : a = 2 → n = 1 → (i = 0 → j ≠ 2) ∧ (i = 2 → j ≠ 0)) : i = j := (le_total i j).elim (fun ij => eq_of_xn_modEq_le a1 ij j2n h fun ⟨a2, n1, i0, j2⟩ => (ntriv a2 n1).left i0 j2) fun ij => (eq_of_xn_modEq_le a1 ij i2n h.symm fun ⟨a2, n1, j0, i2⟩ => (ntriv a2 n1).right i2 j0).symm theorem eq_of_xn_modEq' {i j n} (ipos : 0 < i) (hin : i ≤ n) (j4n : j ≤ 4 * n) (h : xn a1 j ≡ xn a1 i [MOD xn a1 n]) : j = i ∨ j + i = 4 * n := have i2n : i ≤ 2 * n := by apply le_trans hin; rw [two_mul]; apply Nat.le_add_left (le_or_gt j (2 * n)).imp (fun j2n : j ≤ 2 * n => eq_of_xn_modEq a1 j2n i2n h fun a2 n1 => ⟨fun j0 i2 => by rw [n1, i2] at hin; exact absurd hin (by decide), fun _ i0 => _root_.ne_of_gt ipos i0⟩) fun j2n : 2 * n < j => suffices i = 4 * n - j by rw [this, add_tsub_cancel_of_le j4n] have j42n : 4 * n - j ≤ 2 * n := Nat.le_of_add_le_add_right <| by rw [tsub_add_cancel_of_le j4n, show 4 * n = 2 * n + 2 * n from right_distrib 2 2 n] exact Nat.add_le_add_left (le_of_lt j2n) _ eq_of_xn_modEq a1 i2n j42n (h.symm.trans <| by let t := xn_modEq_x4n_sub a1 j42n rwa [tsub_tsub_cancel_of_le j4n] at t) fun a2 n1 => ⟨fun i0 => absurd i0 (_root_.ne_of_gt ipos), fun i2 => by rw [n1, i2] at hin exact absurd hin (by decide)⟩ theorem modEq_of_xn_modEq {i j n} (ipos : 0 < i) (hin : i ≤ n) (h : xn a1 j ≡ xn a1 i [MOD xn a1 n]) : j ≡ i [MOD 4 * n] ∨ j + i ≡ 0 [MOD 4 * n] := let j' := j % (4 * n) have n4 : 0 < 4 * n := mul_pos (by decide) (ipos.trans_le hin) have jl : j' < 4 * n := Nat.mod_lt _ n4 have jj : j ≡ j' [MOD 4 * n] := by delta ModEq; rw [Nat.mod_eq_of_lt jl] have : ∀ j q, xn a1 (j + 4 * n * q) ≡ xn a1 j [MOD xn a1 n] := by intro j q; induction' q with q IH · simp [ModEq.refl] rw [Nat.mul_succ, ← add_assoc, add_comm] exact (xn_modEq_x4n_add _ _ _).trans IH Or.imp (fun ji : j' = i => by rwa [← ji]) (fun ji : j' + i = 4 * n => (jj.add_right _).trans <| by rw [ji] exact dvd_rfl.modEq_zero_nat) (eq_of_xn_modEq' a1 ipos hin jl.le <| (h.symm.trans <| by rw [← Nat.mod_add_div j (4 * n)] exact this j' _).symm) end theorem xy_modEq_of_modEq {a b c} (a1 : 1 < a) (b1 : 1 < b) (h : a ≡ b [MOD c]) : ∀ n, xn a1 n ≡ xn b1 n [MOD c] ∧ yn a1 n ≡ yn b1 n [MOD c] | 0 => by constructor <;> rfl | 1 => by simpa using ⟨h, ModEq.refl 1⟩ | n + 2 => ⟨(xy_modEq_of_modEq a1 b1 h n).left.add_right_cancel <| by rw [xn_succ_succ a1, xn_succ_succ b1] exact (h.mul_left _).mul (xy_modEq_of_modEq _ _ h (n + 1)).left, (xy_modEq_of_modEq _ _ h n).right.add_right_cancel <| by rw [yn_succ_succ a1, yn_succ_succ b1] exact (h.mul_left _).mul (xy_modEq_of_modEq _ _ h (n + 1)).right⟩ theorem matiyasevic {a k x y} : (∃ a1 : 1 < a, xn a1 k = x ∧ yn a1 k = y) ↔ 1 < a ∧ k ≤ y ∧ (x = 1 ∧ y = 0 ∨ ∃ u v s t b : ℕ, x * x - (a * a - 1) * y * y = 1 ∧ u * u - (a * a - 1) * v * v = 1 ∧ s * s - (b * b - 1) * t * t = 1 ∧ 1 < b ∧ b ≡ 1 [MOD 4 * y] ∧ b ≡ a [MOD u] ∧ 0 < v ∧ y * y ∣ v ∧ s ≡ x [MOD u] ∧ t ≡ k [MOD 4 * y]) := ⟨fun ⟨a1, hx, hy⟩ => by rw [← hx, ← hy] refine ⟨a1, (Nat.eq_zero_or_pos k).elim (fun k0 => by rw [k0]; exact ⟨le_rfl, Or.inl ⟨rfl, rfl⟩⟩) fun kpos => ?_⟩ exact let x := xn a1 k let y := yn a1 k let m := 2 * (k * y) let u := xn a1 m let v := yn a1 m have ky : k ≤ y := yn_ge_n a1 k have yv : y * y ∣ v := (ysq_dvd_yy a1 k).trans <| (y_dvd_iff _ _ _).2 <| dvd_mul_left _ _ have uco : Nat.Coprime u (4 * y) := have : 2 ∣ v := modEq_zero_iff_dvd.1 <| (yn_modEq_two _ _).trans (dvd_mul_right _ _).modEq_zero_nat have : Nat.Coprime u 2 := (xy_coprime a1 m).coprime_dvd_right this (this.mul_right this).mul_right <| (xy_coprime _ _).coprime_dvd_right (dvd_of_mul_left_dvd yv) let ⟨b, ba, bm1⟩ := chineseRemainder uco a 1 have m1 : 1 < m := have : 0 < k * y := mul_pos kpos (strictMono_y a1 kpos) Nat.mul_le_mul_left 2 this have vp : 0 < v := strictMono_y a1 (lt_trans zero_lt_one m1) have b1 : 1 < b := have : xn a1 1 < u := strictMono_x a1 m1 have : a < u := by simpa using this lt_of_lt_of_le a1 <| by delta ModEq at ba; rw [Nat.mod_eq_of_lt this] at ba; rw [← ba] apply Nat.mod_le let s := xn b1 k let t := yn b1 k have sx : s ≡ x [MOD u] := (xy_modEq_of_modEq b1 a1 ba k).left have tk : t ≡ k [MOD 4 * y] := have : 4 * y ∣ b - 1 := Int.natCast_dvd_natCast.1 <| by rw [Int.ofNat_sub (le_of_lt b1)]; exact bm1.symm.dvd (yn_modEq_a_sub_one _ _).of_dvd this ⟨ky, Or.inr ⟨u, v, s, t, b, pell_eq _ _, pell_eq _ _, pell_eq _ _, b1, bm1, ba, vp, yv, sx, tk⟩⟩, fun ⟨a1, ky, o⟩ => ⟨a1, match o with | Or.inl ⟨x1, y0⟩ => by rw [y0] at ky; rw [Nat.eq_zero_of_le_zero ky, x1, y0]; exact ⟨rfl, rfl⟩ | Or.inr ⟨u, v, s, t, b, xy, uv, st, b1, rem⟩ => match x, y, eq_pell a1 xy, u, v, eq_pell a1 uv, s, t, eq_pell b1 st, rem, ky with | _, _, ⟨i, rfl, rfl⟩, _, _, ⟨n, rfl, rfl⟩, _, _, ⟨j, rfl, rfl⟩, ⟨(bm1 : b ≡ 1 [MOD 4 * yn a1 i]), (ba : b ≡ a [MOD xn a1 n]), (vp : 0 < yn a1 n), (yv : yn a1 i * yn a1 i ∣ yn a1 n), (sx : xn b1 j ≡ xn a1 i [MOD xn a1 n]), (tk : yn b1 j ≡ k [MOD 4 * yn a1 i])⟩, (ky : k ≤ yn a1 i) => (Nat.eq_zero_or_pos i).elim (fun i0 => by simp [i0] at ky; rw [i0, ky]; exact ⟨rfl, rfl⟩) fun ipos => by suffices i = k by rw [this]; exact ⟨rfl, rfl⟩ clear o rem xy uv st have iln : i ≤ n := le_of_not_gt fun hin => not_lt_of_ge (Nat.le_of_dvd vp (dvd_of_mul_left_dvd yv)) (strictMono_y a1 hin) have yd : 4 * yn a1 i ∣ 4 * n := mul_dvd_mul_left _ <| dvd_of_ysq_dvd a1 yv have jk : j ≡ k [MOD 4 * yn a1 i] := have : 4 * yn a1 i ∣ b - 1 := Int.natCast_dvd_natCast.1 <| by rw [Int.ofNat_sub (le_of_lt b1)]; exact bm1.symm.dvd ((yn_modEq_a_sub_one b1 _).of_dvd this).symm.trans tk have ki : k + i < 4 * yn a1 i := lt_of_le_of_lt (_root_.add_le_add ky (yn_ge_n a1 i)) <| by rw [← two_mul] exact Nat.mul_lt_mul_of_pos_right (by decide) (strictMono_y a1 ipos) have ji : j ≡ i [MOD 4 * n] := have : xn a1 j ≡ xn a1 i [MOD xn a1 n] := (xy_modEq_of_modEq b1 a1 ba j).left.symm.trans sx (modEq_of_xn_modEq a1 ipos iln this).resolve_right fun ji : j + i ≡ 0 [MOD 4 * n] => not_le_of_gt ki <| Nat.le_of_dvd (lt_of_lt_of_le ipos <| Nat.le_add_left _ _) <| modEq_zero_iff_dvd.1 <| (jk.symm.add_right i).trans <| ji.of_dvd yd have : i % (4 * yn a1 i) = k % (4 * yn a1 i) := (ji.of_dvd yd).symm.trans jk rwa [Nat.mod_eq_of_lt (lt_of_le_of_lt (Nat.le_add_left _ _) ki), Nat.mod_eq_of_lt (lt_of_le_of_lt (Nat.le_add_right _ _) ki)] at this⟩⟩ theorem eq_pow_of_pell_lem {a y k : ℕ} (hy0 : y ≠ 0) (hk0 : k ≠ 0) (hyk : y ^ k < a) : (↑(y ^ k) : ℤ) < 2 * a * y - y * y - 1 := have hya : y < a := (Nat.le_self_pow hk0 _).trans_lt hyk calc (↑(y ^ k) : ℤ) < a := Nat.cast_lt.2 hyk _ ≤ (a : ℤ) ^ 2 - (a - 1 : ℤ) ^ 2 - 1 := by rw [sub_sq, mul_one, one_pow, sub_add, sub_sub_cancel, two_mul, sub_sub, ← add_sub, le_add_iff_nonneg_right, sub_nonneg, Int.add_one_le_iff] norm_cast exact lt_of_le_of_lt (Nat.succ_le_of_lt (Nat.pos_of_ne_zero hy0)) hya _ ≤ (a : ℤ) ^ 2 - (a - y : ℤ) ^ 2 - 1 := by have := hya.le gcongr <;> norm_cast <;> omega _ = 2 * a * y - y * y - 1 := by ring theorem eq_pow_of_pell {m n k} : n ^ k = m ↔ k = 0 ∧ m = 1 ∨0 < k ∧ (n = 0 ∧ m = 0 ∨ 0 < n ∧ ∃ (w a t z : ℕ) (a1 : 1 < a), xn a1 k ≡ yn a1 k * (a - n) + m [MOD t] ∧ 2 * a * n = t + (n * n + 1) ∧ m < t ∧ n ≤ w ∧ k ≤ w ∧ a * a - ((w + 1) * (w + 1) - 1) * (w * z) * (w * z) = 1) := by constructor · rintro rfl refine k.eq_zero_or_pos.imp (fun k0 : k = 0 => k0.symm ▸ ⟨rfl, rfl⟩) fun hk => ⟨hk, ?_⟩ refine n.eq_zero_or_pos.imp (fun n0 : n = 0 ↦ n0.symm ▸ ⟨rfl, zero_pow hk.ne'⟩) fun hn ↦ ⟨hn, ?_⟩ set w := max n k have nw : n ≤ w := le_max_left _ _ have kw : k ≤ w := le_max_right _ _ have wpos : 0 < w := hn.trans_le nw have w1 : 1 < w + 1 := Nat.succ_lt_succ wpos set a := xn w1 w have a1 : 1 < a := strictMono_x w1 wpos have na : n ≤ a := nw.trans (n_lt_xn w1 w).le set x := xn a1 k set y := yn a1 k obtain ⟨z, ze⟩ : w ∣ yn w1 w := modEq_zero_iff_dvd.1 ((yn_modEq_a_sub_one w1 w).trans dvd_rfl.modEq_zero_nat) have nt : (↑(n ^ k) : ℤ) < 2 * a * n - n * n - 1 := by refine eq_pow_of_pell_lem hn.ne' hk.ne' ?_ calc n ^ k ≤ n ^ w := Nat.pow_le_pow_of_le_right hn kw _ < (w + 1) ^ w := Nat.pow_lt_pow_left (Nat.lt_succ_of_le nw) wpos.ne' _ ≤ a := xn_ge_a_pow w1 w lift (2 * a * n - n * n - 1 : ℤ) to ℕ using (Nat.cast_nonneg _).trans nt.le with t te have tm : x ≡ y * (a - n) + n ^ k [MOD t] := by apply modEq_of_dvd rw [Int.ofNat_add, Int.ofNat_mul, Int.ofNat_sub na, te] exact x_sub_y_dvd_pow a1 n k have ta : 2 * a * n = t + (n * n + 1) := by zify rw [te] ring_nf have zp : a * a - ((w + 1) * (w + 1) - 1) * (w * z) * (w * z) = 1 := ze ▸ pell_eq w1 w exact ⟨w, a, t, z, a1, tm, ta, Nat.cast_lt.1 nt, nw, kw, zp⟩ · rintro (⟨rfl, rfl⟩ | ⟨hk0, ⟨rfl, rfl⟩ | ⟨hn0, w, a, t, z, a1, tm, ta, mt, nw, kw, zp⟩⟩) · exact _root_.pow_zero n · exact zero_pow hk0.ne' have hw0 : 0 < w := hn0.trans_le nw have hw1 : 1 < w + 1 := Nat.succ_lt_succ hw0 rcases eq_pell hw1 zp with ⟨j, rfl, yj⟩ have hj0 : 0 < j := by apply Nat.pos_of_ne_zero rintro rfl exact lt_irrefl 1 a1 have wj : w ≤ j := Nat.le_of_dvd hj0 (modEq_zero_iff_dvd.1 <| (yn_modEq_a_sub_one hw1 j).symm.trans <| modEq_zero_iff_dvd.2 ⟨z, yj.symm⟩) have hnka : n ^ k < xn hw1 j := calc n ^ k ≤ n ^ j := Nat.pow_le_pow_of_le_right hn0 (le_trans kw wj) _ < (w + 1) ^ j := Nat.pow_lt_pow_left (Nat.lt_succ_of_le nw) hj0.ne' _ ≤ xn hw1 j := xn_ge_a_pow hw1 j have nt : (↑(n ^ k) : ℤ) < 2 * xn hw1 j * n - n * n - 1 := eq_pow_of_pell_lem hn0.ne' hk0.ne' hnka have na : n ≤ xn hw1 j := (Nat.le_self_pow hk0.ne' _).trans hnka.le have te : (t : ℤ) = 2 * xn hw1 j * n - n * n - 1 := by rw [sub_sub, eq_sub_iff_add_eq] exact mod_cast ta.symm have : xn a1 k ≡ yn a1 k * (xn hw1 j - n) + n ^ k [MOD t] := by apply modEq_of_dvd rw [te, Nat.cast_add, Nat.cast_mul, Int.ofNat_sub na] exact x_sub_y_dvd_pow a1 n k have : n ^ k % t = m % t := (this.symm.trans tm).add_left_cancel' _ rw [← te] at nt rwa [Nat.mod_eq_of_lt (Nat.cast_lt.1 nt), Nat.mod_eq_of_lt mt] at this end Pell
NumberTheory\PrimeCounting.lean
/- Copyright (c) 2021 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Ralf Stephan -/ import Mathlib.Data.Nat.Totient import Mathlib.Data.Nat.Nth import Mathlib.NumberTheory.SmoothNumbers /-! # The Prime Counting Function In this file we define the prime counting function: the function on natural numbers that returns the number of primes less than or equal to its input. ## Main Results The main definitions for this file are - `Nat.primeCounting`: The prime counting function π - `Nat.primeCounting'`: π(n - 1) We then prove that these are monotone in `Nat.monotone_primeCounting` and `Nat.monotone_primeCounting'`. The last main theorem `Nat.primeCounting'_add_le` is an upper bound on `π'` which arises by observing that all numbers greater than `k` and not coprime to `k` are not prime, and so only at most `φ(k)/k` fraction of the numbers from `k` to `n` are prime. ## Notation Wtih `open scoped Nat.Prime`, we use the standard notation `π` to represent the prime counting function (and `π'` to represent the reindexed version). -/ namespace Nat open Finset /-- A variant of the traditional prime counting function which gives the number of primes *strictly* less than the input. More convenient for avoiding off-by-one errors. With `open scoped Nat.Prime`, this has notation `π'`. -/ def primeCounting' : ℕ → ℕ := Nat.count Prime /-- The prime counting function: Returns the number of primes less than or equal to the input. With `open scoped Nat.Prime`, this has notation `π`. -/ def primeCounting (n : ℕ) : ℕ := primeCounting' (n + 1) @[inherit_doc] scoped[Nat.Prime] notation "π" => Nat.primeCounting @[inherit_doc] scoped[Nat.Prime] notation "π'" => Nat.primeCounting' open scoped Nat.Prime theorem monotone_primeCounting' : Monotone primeCounting' := count_monotone Prime theorem monotone_primeCounting : Monotone primeCounting := monotone_primeCounting'.comp (monotone_id.add_const _) @[simp] theorem primeCounting'_nth_eq (n : ℕ) : π' (nth Prime n) = n := count_nth_of_infinite infinite_setOf_prime _ @[simp] theorem prime_nth_prime (n : ℕ) : Prime (nth Prime n) := nth_mem_of_infinite infinite_setOf_prime _ /-- The cardinality of the finset `primesBelow n` equals the counting function `primeCounting'` at `n`. -/ lemma primesBelow_card_eq_primeCounting' (n : ℕ) : n.primesBelow.card = primeCounting' n := by simp only [primesBelow, primeCounting'] exact (count_eq_card_filter_range Prime n).symm /-- A linear upper bound on the size of the `primeCounting'` function -/ theorem primeCounting'_add_le {a k : ℕ} (h0 : 0 < a) (h1 : a < k) (n : ℕ) : π' (k + n) ≤ π' k + Nat.totient a * (n / a + 1) := calc π' (k + n) ≤ ((range k).filter Prime).card + ((Ico k (k + n)).filter Prime).card := by rw [primeCounting', count_eq_card_filter_range, range_eq_Ico, ← Ico_union_Ico_eq_Ico (zero_le k) le_self_add, filter_union] apply card_union_le _ ≤ π' k + ((Ico k (k + n)).filter Prime).card := by rw [primeCounting', count_eq_card_filter_range] _ ≤ π' k + ((Ico k (k + n)).filter (Coprime a)).card := by refine add_le_add_left (card_le_card ?_) k.primeCounting' simp only [subset_iff, and_imp, mem_filter, mem_Ico] intro p succ_k_le_p p_lt_n p_prime constructor · exact ⟨succ_k_le_p, p_lt_n⟩ · rw [coprime_comm] exact coprime_of_lt_prime h0 (gt_of_ge_of_gt succ_k_le_p h1) p_prime _ ≤ π' k + totient a * (n / a + 1) := by rw [add_le_add_iff_left] exact Ico_filter_coprime_le k n h0 @[simp] theorem zeroth_prime_eq_two : nth Prime 0 = 2 := nth_count prime_two /-- The `n`th prime is greater or equal to `n + 2`. -/ lemma add_two_le_nth_prime (n : ℕ) : n + 2 ≤ nth Prime n := zeroth_prime_eq_two ▸ (nth_strictMono infinite_setOf_prime).add_le_nat n 0 end Nat
NumberTheory\PrimesCongruentOne.lean
/- Copyright (c) 2020 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.RingTheory.Polynomial.Cyclotomic.Eval /-! # Primes congruent to one We prove that, for any positive `k : ℕ`, there are infinitely many primes `p` such that `p ≡ 1 [MOD k]`. -/ namespace Nat open Polynomial Nat Filter open scoped Nat /-- For any positive `k : ℕ` there exists an arbitrarily large prime `p` such that `p ≡ 1 [MOD k]`. -/ theorem exists_prime_gt_modEq_one {k : ℕ} (n : ℕ) (hk0 : k ≠ 0) : ∃ p : ℕ, Nat.Prime p ∧ n < p ∧ p ≡ 1 [MOD k] := by rcases (one_le_iff_ne_zero.2 hk0).eq_or_lt with (rfl | hk1) · rcases exists_infinite_primes (n + 1) with ⟨p, hnp, hp⟩ exact ⟨p, hp, hnp, modEq_one⟩ let b := k * (n !) have hgt : 1 < (eval (↑b) (cyclotomic k ℤ)).natAbs := by rcases le_iff_exists_add'.1 hk1.le with ⟨k, rfl⟩ have hb : 2 ≤ b := le_mul_of_le_of_one_le hk1 n.factorial_pos calc 1 ≤ b - 1 := le_tsub_of_add_le_left hb _ < (eval (b : ℤ) (cyclotomic (k + 1) ℤ)).natAbs := sub_one_lt_natAbs_cyclotomic_eval hk1 (succ_le_iff.1 hb).ne' let p := minFac (eval (↑b) (cyclotomic k ℤ)).natAbs haveI hprime : Fact p.Prime := ⟨minFac_prime (ne_of_lt hgt).symm⟩ have hroot : IsRoot (cyclotomic k (ZMod p)) (castRingHom (ZMod p) b) := by have : ((b : ℤ) : ZMod p) = ↑(Int.castRingHom (ZMod p) b) := by simp rw [IsRoot.def, ← map_cyclotomic_int k (ZMod p), eval_map, coe_castRingHom, ← Int.cast_natCast, this, eval₂_hom, Int.coe_castRingHom, ZMod.intCast_zmod_eq_zero_iff_dvd] apply Int.dvd_natAbs.1 exact mod_cast minFac_dvd (eval (↑b) (cyclotomic k ℤ)).natAbs have hpb : ¬p ∣ b := hprime.1.coprime_iff_not_dvd.1 (coprime_of_root_cyclotomic hk0.bot_lt hroot).symm refine ⟨p, hprime.1, not_le.1 fun habs => ?_, ?_⟩ · exact hpb (dvd_mul_of_dvd_right (dvd_factorial (minFac_pos _) habs) _) · have hdiv : orderOf (b : ZMod p) ∣ p - 1 := ZMod.orderOf_dvd_card_sub_one (mt (CharP.cast_eq_zero_iff _ _ _).1 hpb) haveI : NeZero (k : ZMod p) := NeZero.of_not_dvd (ZMod p) fun hpk => hpb (dvd_mul_of_dvd_left hpk _) have : k = orderOf (b : ZMod p) := (isRoot_cyclotomic_iff.mp hroot).eq_orderOf rw [← this] at hdiv exact ((modEq_iff_dvd' hprime.1.pos).2 hdiv).symm theorem frequently_atTop_modEq_one {k : ℕ} (hk0 : k ≠ 0) : ∃ᶠ p in atTop, Nat.Prime p ∧ p ≡ 1 [MOD k] := by refine frequently_atTop.2 fun n => ?_ obtain ⟨p, hp⟩ := exists_prime_gt_modEq_one n hk0 exact ⟨p, ⟨hp.2.1.le, hp.1, hp.2.2⟩⟩ /-- For any positive `k : ℕ` there are infinitely many primes `p` such that `p ≡ 1 [MOD k]`. -/ theorem infinite_setOf_prime_modEq_one {k : ℕ} (hk0 : k ≠ 0) : Set.Infinite {p : ℕ | Nat.Prime p ∧ p ≡ 1 [MOD k]} := frequently_atTop_iff_infinite.1 (frequently_atTop_modEq_one hk0) end Nat
NumberTheory\Primorial.lean
/- Copyright (c) 2020 Patrick Stevens. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Stevens, Yury Kudryashov -/ import Mathlib.Algebra.BigOperators.Associated import Mathlib.Algebra.Order.BigOperators.Ring.Finset import Mathlib.Algebra.Order.Ring.Abs import Mathlib.Data.Nat.Choose.Sum import Mathlib.Data.Nat.Choose.Dvd import Mathlib.Data.Nat.Prime.Defs /-! # Primorial This file defines the primorial function (the product of primes less than or equal to some bound), and proves that `primorial n ≤ 4 ^ n`. ## Notations We use the local notation `n#` for the primorial of `n`: that is, the product of the primes less than or equal to `n`. -/ open Finset open Nat open Nat /-- The primorial `n#` of `n` is the product of the primes less than or equal to `n`. -/ def primorial (n : ℕ) : ℕ := ∏ p ∈ filter Nat.Prime (range (n + 1)), p local notation x "#" => primorial x theorem primorial_pos (n : ℕ) : 0 < n# := prod_pos fun _p hp ↦ (mem_filter.1 hp).2.pos theorem primorial_succ {n : ℕ} (hn1 : n ≠ 1) (hn : Odd n) : (n + 1)# = n# := by refine prod_congr ?_ fun _ _ ↦ rfl rw [range_succ, filter_insert, if_neg fun h ↦ odd_iff_not_even.mp hn _] exact fun h ↦ h.even_sub_one <| mt succ.inj hn1 theorem primorial_add (m n : ℕ) : (m + n)# = m# * ∏ p ∈ filter Nat.Prime (Ico (m + 1) (m + n + 1)), p := by rw [primorial, primorial, ← Ico_zero_eq_range, ← prod_union, ← filter_union, Ico_union_Ico_eq_Ico] exacts [Nat.zero_le _, add_le_add_right (Nat.le_add_right _ _) _, disjoint_filter_filter <| Ico_disjoint_Ico_consecutive _ _ _] theorem primorial_add_dvd {m n : ℕ} (h : n ≤ m) : (m + n)# ∣ m# * choose (m + n) m := calc (m + n)# = m# * ∏ p ∈ filter Nat.Prime (Ico (m + 1) (m + n + 1)), p := primorial_add _ _ _ ∣ m# * choose (m + n) m := mul_dvd_mul_left _ <| prod_primes_dvd _ (fun k hk ↦ (mem_filter.1 hk).2.prime) fun p hp ↦ by rw [mem_filter, mem_Ico] at hp exact hp.2.dvd_choose_add hp.1.1 (h.trans_lt (m.lt_succ_self.trans_le hp.1.1)) (Nat.lt_succ_iff.1 hp.1.2) theorem primorial_add_le {m n : ℕ} (h : n ≤ m) : (m + n)# ≤ m# * choose (m + n) m := le_of_dvd (mul_pos (primorial_pos _) (choose_pos <| Nat.le_add_right _ _)) (primorial_add_dvd h) theorem primorial_le_4_pow (n : ℕ) : n# ≤ 4 ^ n := by induction' n using Nat.strong_induction_on with n ihn cases' n with n; · rfl rcases n.even_or_odd with (⟨m, rfl⟩ | ho) · rcases m.eq_zero_or_pos with (rfl | hm) · decide calc (m + m + 1)# = (m + 1 + m)# := by rw [add_right_comm] _ ≤ (m + 1)# * choose (m + 1 + m) (m + 1) := primorial_add_le m.le_succ _ = (m + 1)# * choose (2 * m + 1) m := by rw [choose_symm_add, two_mul, add_right_comm] _ ≤ 4 ^ (m + 1) * 4 ^ m := mul_le_mul' (ihn _ <| succ_lt_succ <| (lt_add_iff_pos_left _).2 hm) (choose_middle_le_pow _) _ ≤ 4 ^ (m + m + 1) := by rw [← pow_add, add_right_comm] · rcases Decidable.eq_or_ne n 1 with (rfl | hn) · decide · calc (n + 1)# = n# := primorial_succ hn ho _ ≤ 4 ^ n := ihn n n.lt_succ_self _ ≤ 4 ^ (n + 1) := pow_le_pow_of_le_right four_pos n.le_succ
NumberTheory\PythagoreanTriples.lean
/- Copyright (c) 2020 Paul van Wamelen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Paul van Wamelen -/ import Mathlib.Algebra.Field.Basic import Mathlib.Algebra.Order.Group.Basic import Mathlib.Algebra.Order.Ring.Basic import Mathlib.RingTheory.Int.Basic import Mathlib.Tactic.Ring import Mathlib.Tactic.FieldSimp import Mathlib.Data.Int.NatPrime import Mathlib.Data.ZMod.Basic /-! # Pythagorean Triples The main result is the classification of Pythagorean triples. The final result is for general Pythagorean triples. It follows from the more interesting relatively prime case. We use the "rational parametrization of the circle" method for the proof. The parametrization maps the point `(x / z, y / z)` to the slope of the line through `(-1 , 0)` and `(x / z, y / z)`. This quickly shows that `(x / z, y / z) = (2 * m * n / (m ^ 2 + n ^ 2), (m ^ 2 - n ^ 2) / (m ^ 2 + n ^ 2))` where `m / n` is the slope. In order to identify numerators and denominators we now need results showing that these are coprime. This is easy except for the prime 2. In order to deal with that we have to analyze the parity of `x`, `y`, `m` and `n` and eliminate all the impossible cases. This takes up the bulk of the proof below. -/ theorem sq_ne_two_fin_zmod_four (z : ZMod 4) : z * z ≠ 2 := by change Fin 4 at z fin_cases z <;> decide theorem Int.sq_ne_two_mod_four (z : ℤ) : z * z % 4 ≠ 2 := by suffices ¬z * z % (4 : ℕ) = 2 % (4 : ℕ) by exact this rw [← ZMod.intCast_eq_intCast_iff'] simpa using sq_ne_two_fin_zmod_four _ noncomputable section /-- Three integers `x`, `y`, and `z` form a Pythagorean triple if `x * x + y * y = z * z`. -/ def PythagoreanTriple (x y z : ℤ) : Prop := x * x + y * y = z * z /-- Pythagorean triples are interchangeable, i.e `x * x + y * y = y * y + x * x = z * z`. This comes from additive commutativity. -/ theorem pythagoreanTriple_comm {x y z : ℤ} : PythagoreanTriple x y z ↔ PythagoreanTriple y x z := by delta PythagoreanTriple rw [add_comm] /-- The zeroth Pythagorean triple is all zeros. -/ theorem PythagoreanTriple.zero : PythagoreanTriple 0 0 0 := by simp only [PythagoreanTriple, zero_mul, zero_add] namespace PythagoreanTriple variable {x y z : ℤ} (h : PythagoreanTriple x y z) theorem eq : x * x + y * y = z * z := h @[symm] theorem symm : PythagoreanTriple y x z := by rwa [pythagoreanTriple_comm] /-- A triple is still a triple if you multiply `x`, `y` and `z` by a constant `k`. -/ theorem mul (k : ℤ) : PythagoreanTriple (k * x) (k * y) (k * z) := calc k * x * (k * x) + k * y * (k * y) = k ^ 2 * (x * x + y * y) := by ring _ = k ^ 2 * (z * z) := by rw [h.eq] _ = k * z * (k * z) := by ring /-- `(k*x, k*y, k*z)` is a Pythagorean triple if and only if `(x, y, z)` is also a triple. -/ theorem mul_iff (k : ℤ) (hk : k ≠ 0) : PythagoreanTriple (k * x) (k * y) (k * z) ↔ PythagoreanTriple x y z := by refine ⟨?_, fun h => h.mul k⟩ simp only [PythagoreanTriple] intro h rw [← mul_left_inj' (mul_ne_zero hk hk)] convert h using 1 <;> ring /-- A Pythagorean triple `x, y, z` is “classified” if there exist integers `k, m, n` such that either * `x = k * (m ^ 2 - n ^ 2)` and `y = k * (2 * m * n)`, or * `x = k * (2 * m * n)` and `y = k * (m ^ 2 - n ^ 2)`. -/ @[nolint unusedArguments] def IsClassified (_ : PythagoreanTriple x y z) := ∃ k m n : ℤ, (x = k * (m ^ 2 - n ^ 2) ∧ y = k * (2 * m * n) ∨ x = k * (2 * m * n) ∧ y = k * (m ^ 2 - n ^ 2)) ∧ Int.gcd m n = 1 /-- A primitive Pythagorean triple `x, y, z` is a Pythagorean triple with `x` and `y` coprime. Such a triple is “primitively classified” if there exist coprime integers `m, n` such that either * `x = m ^ 2 - n ^ 2` and `y = 2 * m * n`, or * `x = 2 * m * n` and `y = m ^ 2 - n ^ 2`. -/ @[nolint unusedArguments] def IsPrimitiveClassified (_ : PythagoreanTriple x y z) := ∃ m n : ℤ, (x = m ^ 2 - n ^ 2 ∧ y = 2 * m * n ∨ x = 2 * m * n ∧ y = m ^ 2 - n ^ 2) ∧ Int.gcd m n = 1 ∧ (m % 2 = 0 ∧ n % 2 = 1 ∨ m % 2 = 1 ∧ n % 2 = 0) theorem mul_isClassified (k : ℤ) (hc : h.IsClassified) : (h.mul k).IsClassified := by obtain ⟨l, m, n, ⟨⟨rfl, rfl⟩ | ⟨rfl, rfl⟩, co⟩⟩ := hc · use k * l, m, n apply And.intro _ co left constructor <;> ring · use k * l, m, n apply And.intro _ co right constructor <;> ring theorem even_odd_of_coprime (hc : Int.gcd x y = 1) : x % 2 = 0 ∧ y % 2 = 1 ∨ x % 2 = 1 ∧ y % 2 = 0 := by cases' Int.emod_two_eq_zero_or_one x with hx hx <;> cases' Int.emod_two_eq_zero_or_one y with hy hy -- x even, y even · exfalso apply Nat.not_coprime_of_dvd_of_dvd (by decide : 1 < 2) _ _ hc · apply Int.natCast_dvd.1 apply Int.dvd_of_emod_eq_zero hx · apply Int.natCast_dvd.1 apply Int.dvd_of_emod_eq_zero hy -- x even, y odd · left exact ⟨hx, hy⟩ -- x odd, y even · right exact ⟨hx, hy⟩ -- x odd, y odd · exfalso obtain ⟨x0, y0, rfl, rfl⟩ : ∃ x0 y0, x = x0 * 2 + 1 ∧ y = y0 * 2 + 1 := by cases' exists_eq_mul_left_of_dvd (Int.dvd_sub_of_emod_eq hx) with x0 hx2 cases' exists_eq_mul_left_of_dvd (Int.dvd_sub_of_emod_eq hy) with y0 hy2 rw [sub_eq_iff_eq_add] at hx2 hy2 exact ⟨x0, y0, hx2, hy2⟩ apply Int.sq_ne_two_mod_four z rw [show z * z = 4 * (x0 * x0 + x0 + y0 * y0 + y0) + 2 by rw [← h.eq] ring] simp only [Int.add_emod, Int.mul_emod_right, zero_add] decide theorem gcd_dvd : (Int.gcd x y : ℤ) ∣ z := by by_cases h0 : Int.gcd x y = 0 · have hx : x = 0 := by apply Int.natAbs_eq_zero.mp apply Nat.eq_zero_of_gcd_eq_zero_left h0 have hy : y = 0 := by apply Int.natAbs_eq_zero.mp apply Nat.eq_zero_of_gcd_eq_zero_right h0 have hz : z = 0 := by simpa only [PythagoreanTriple, hx, hy, add_zero, zero_eq_mul, mul_zero, or_self_iff] using h simp only [hz, dvd_zero] obtain ⟨k, x0, y0, _, h2, rfl, rfl⟩ : ∃ (k : ℕ) (x0 y0 : _), 0 < k ∧ Int.gcd x0 y0 = 1 ∧ x = x0 * k ∧ y = y0 * k := Int.exists_gcd_one' (Nat.pos_of_ne_zero h0) rw [Int.gcd_mul_right, h2, Int.natAbs_ofNat, one_mul] rw [← Int.pow_dvd_pow_iff two_ne_zero, sq z, ← h.eq] rw [(by ring : x0 * k * (x0 * k) + y0 * k * (y0 * k) = (k : ℤ) ^ 2 * (x0 * x0 + y0 * y0))] exact dvd_mul_right _ _ theorem normalize : PythagoreanTriple (x / Int.gcd x y) (y / Int.gcd x y) (z / Int.gcd x y) := by by_cases h0 : Int.gcd x y = 0 · have hx : x = 0 := by apply Int.natAbs_eq_zero.mp apply Nat.eq_zero_of_gcd_eq_zero_left h0 have hy : y = 0 := by apply Int.natAbs_eq_zero.mp apply Nat.eq_zero_of_gcd_eq_zero_right h0 have hz : z = 0 := by simpa only [PythagoreanTriple, hx, hy, add_zero, zero_eq_mul, mul_zero, or_self_iff] using h simp only [hx, hy, hz, Int.zero_div] exact zero rcases h.gcd_dvd with ⟨z0, rfl⟩ obtain ⟨k, x0, y0, k0, h2, rfl, rfl⟩ : ∃ (k : ℕ) (x0 y0 : _), 0 < k ∧ Int.gcd x0 y0 = 1 ∧ x = x0 * k ∧ y = y0 * k := Int.exists_gcd_one' (Nat.pos_of_ne_zero h0) have hk : (k : ℤ) ≠ 0 := by norm_cast rwa [pos_iff_ne_zero] at k0 rw [Int.gcd_mul_right, h2, Int.natAbs_ofNat, one_mul] at h ⊢ rw [mul_comm x0, mul_comm y0, mul_iff k hk] at h rwa [Int.mul_ediv_cancel _ hk, Int.mul_ediv_cancel _ hk, Int.mul_ediv_cancel_left _ hk] theorem isClassified_of_isPrimitiveClassified (hp : h.IsPrimitiveClassified) : h.IsClassified := by obtain ⟨m, n, H⟩ := hp use 1, m, n rcases H with ⟨t, co, _⟩ rw [one_mul, one_mul] exact ⟨t, co⟩ theorem isClassified_of_normalize_isPrimitiveClassified (hc : h.normalize.IsPrimitiveClassified) : h.IsClassified := by convert h.normalize.mul_isClassified (Int.gcd x y) (isClassified_of_isPrimitiveClassified h.normalize hc) <;> rw [Int.mul_ediv_cancel'] · exact Int.gcd_dvd_left · exact Int.gcd_dvd_right · exact h.gcd_dvd theorem ne_zero_of_coprime (hc : Int.gcd x y = 1) : z ≠ 0 := by suffices 0 < z * z by rintro rfl norm_num at this rw [← h.eq, ← sq, ← sq] have hc' : Int.gcd x y ≠ 0 := by rw [hc] exact one_ne_zero cases' Int.ne_zero_of_gcd hc' with hxz hyz · apply lt_add_of_pos_of_le (sq_pos_of_ne_zero hxz) (sq_nonneg y) · apply lt_add_of_le_of_pos (sq_nonneg x) (sq_pos_of_ne_zero hyz) theorem isPrimitiveClassified_of_coprime_of_zero_left (hc : Int.gcd x y = 1) (hx : x = 0) : h.IsPrimitiveClassified := by subst x change Nat.gcd 0 (Int.natAbs y) = 1 at hc rw [Nat.gcd_zero_left (Int.natAbs y)] at hc cases' Int.natAbs_eq y with hy hy · use 1, 0 rw [hy, hc, Int.gcd_zero_right] decide · use 0, 1 rw [hy, hc, Int.gcd_zero_left] decide theorem coprime_of_coprime (hc : Int.gcd x y = 1) : Int.gcd y z = 1 := by by_contra H obtain ⟨p, hp, hpy, hpz⟩ := Nat.Prime.not_coprime_iff_dvd.mp H apply hp.not_dvd_one rw [← hc] apply Nat.dvd_gcd (Int.Prime.dvd_natAbs_of_coe_dvd_sq hp _ _) hpy rw [sq, eq_sub_of_add_eq h] rw [← Int.natCast_dvd] at hpy hpz exact dvd_sub (hpz.mul_right _) (hpy.mul_right _) end PythagoreanTriple section circleEquivGen /-! ### A parametrization of the unit circle For the classification of Pythagorean triples, we will use a parametrization of the unit circle. -/ variable {K : Type*} [Field K] /-- A parameterization of the unit circle that is useful for classifying Pythagorean triples. (To be applied in the case where `K = ℚ`.) -/ def circleEquivGen (hk : ∀ x : K, 1 + x ^ 2 ≠ 0) : K ≃ { p : K × K // p.1 ^ 2 + p.2 ^ 2 = 1 ∧ p.2 ≠ -1 } where toFun x := ⟨⟨2 * x / (1 + x ^ 2), (1 - x ^ 2) / (1 + x ^ 2)⟩, by field_simp [hk x, div_pow] ring, by simp only [Ne, div_eq_iff (hk x), neg_mul, one_mul, neg_add, sub_eq_add_neg, add_left_inj] simpa only [eq_neg_iff_add_eq_zero, one_pow] using hk 1⟩ invFun p := (p : K × K).1 / ((p : K × K).2 + 1) left_inv x := by have h2 : (1 + 1 : K) = 2 := by norm_num -- Porting note: rfl is not enough to close this have h3 : (2 : K) ≠ 0 := by convert hk 1 rw [one_pow 2, h2] field_simp [hk x, h2, add_assoc, add_comm, add_sub_cancel, mul_comm] right_inv := fun ⟨⟨x, y⟩, hxy, hy⟩ => by change x ^ 2 + y ^ 2 = 1 at hxy have h2 : y + 1 ≠ 0 := mt eq_neg_of_add_eq_zero_left hy have h3 : (y + 1) ^ 2 + x ^ 2 = 2 * (y + 1) := by rw [(add_neg_eq_iff_eq_add.mpr hxy.symm).symm] ring have h4 : (2 : K) ≠ 0 := by convert hk 1 rw [one_pow 2] ring -- Porting note: rfl is not enough to close this simp only [Prod.mk.inj_iff, Subtype.mk_eq_mk] constructor · field_simp [h3] ring · field_simp [h3] rw [← add_neg_eq_iff_eq_add.mpr hxy.symm] ring @[simp] theorem circleEquivGen_apply (hk : ∀ x : K, 1 + x ^ 2 ≠ 0) (x : K) : (circleEquivGen hk x : K × K) = ⟨2 * x / (1 + x ^ 2), (1 - x ^ 2) / (1 + x ^ 2)⟩ := rfl @[simp] theorem circleEquivGen_symm_apply (hk : ∀ x : K, 1 + x ^ 2 ≠ 0) (v : { p : K × K // p.1 ^ 2 + p.2 ^ 2 = 1 ∧ p.2 ≠ -1 }) : (circleEquivGen hk).symm v = (v : K × K).1 / ((v : K × K).2 + 1) := rfl end circleEquivGen private theorem coprime_sq_sub_sq_add_of_even_odd {m n : ℤ} (h : Int.gcd m n = 1) (hm : m % 2 = 0) (hn : n % 2 = 1) : Int.gcd (m ^ 2 - n ^ 2) (m ^ 2 + n ^ 2) = 1 := by by_contra H obtain ⟨p, hp, hp1, hp2⟩ := Nat.Prime.not_coprime_iff_dvd.mp H rw [← Int.natCast_dvd] at hp1 hp2 have h2m : (p : ℤ) ∣ 2 * m ^ 2 := by convert dvd_add hp2 hp1 using 1 ring have h2n : (p : ℤ) ∣ 2 * n ^ 2 := by convert dvd_sub hp2 hp1 using 1 ring have hmc : p = 2 ∨ p ∣ Int.natAbs m := prime_two_or_dvd_of_dvd_two_mul_pow_self_two hp h2m have hnc : p = 2 ∨ p ∣ Int.natAbs n := prime_two_or_dvd_of_dvd_two_mul_pow_self_two hp h2n by_cases h2 : p = 2 -- Porting note: norm_num is not enough to close h3 · have h3 : (m ^ 2 + n ^ 2) % 2 = 1 := by simp only [sq, Int.add_emod, Int.mul_emod, hm, hn, dvd_refl, Int.emod_emod_of_dvd] decide have h4 : (m ^ 2 + n ^ 2) % 2 = 0 := by apply Int.emod_eq_zero_of_dvd rwa [h2] at hp2 rw [h4] at h3 exact zero_ne_one h3 · apply hp.not_dvd_one rw [← h] exact Nat.dvd_gcd (Or.resolve_left hmc h2) (Or.resolve_left hnc h2) private theorem coprime_sq_sub_sq_add_of_odd_even {m n : ℤ} (h : Int.gcd m n = 1) (hm : m % 2 = 1) (hn : n % 2 = 0) : Int.gcd (m ^ 2 - n ^ 2) (m ^ 2 + n ^ 2) = 1 := by rw [Int.gcd, ← Int.natAbs_neg (m ^ 2 - n ^ 2)] rw [(by ring : -(m ^ 2 - n ^ 2) = n ^ 2 - m ^ 2), add_comm] apply coprime_sq_sub_sq_add_of_even_odd _ hn hm; rwa [Int.gcd_comm] private theorem coprime_sq_sub_mul_of_even_odd {m n : ℤ} (h : Int.gcd m n = 1) (hm : m % 2 = 0) (hn : n % 2 = 1) : Int.gcd (m ^ 2 - n ^ 2) (2 * m * n) = 1 := by by_contra H obtain ⟨p, hp, hp1, hp2⟩ := Nat.Prime.not_coprime_iff_dvd.mp H rw [← Int.natCast_dvd] at hp1 hp2 have hnp : ¬(p : ℤ) ∣ Int.gcd m n := by rw [h] norm_cast exact mt Nat.dvd_one.mp (Nat.Prime.ne_one hp) cases' Int.Prime.dvd_mul hp hp2 with hp2m hpn · rw [Int.natAbs_mul] at hp2m cases' (Nat.Prime.dvd_mul hp).mp hp2m with hp2 hpm · have hp2' : p = 2 := (Nat.le_of_dvd zero_lt_two hp2).antisymm hp.two_le revert hp1 rw [hp2'] apply mt Int.emod_eq_zero_of_dvd -- Porting note: norm_num is not enough to close this simp only [sq, Nat.cast_ofNat, Int.sub_emod, Int.mul_emod, hm, hn, mul_zero, EuclideanDomain.zero_mod, mul_one, zero_sub] decide apply mt (Int.dvd_gcd (Int.natCast_dvd.mpr hpm)) hnp apply or_self_iff.mp apply Int.Prime.dvd_mul' hp rw [(by ring : n * n = -(m ^ 2 - n ^ 2) + m * m)] exact hp1.neg_right.add ((Int.natCast_dvd.2 hpm).mul_right _) rw [Int.gcd_comm] at hnp apply mt (Int.dvd_gcd (Int.natCast_dvd.mpr hpn)) hnp apply or_self_iff.mp apply Int.Prime.dvd_mul' hp rw [(by ring : m * m = m ^ 2 - n ^ 2 + n * n)] apply dvd_add hp1 exact (Int.natCast_dvd.mpr hpn).mul_right n private theorem coprime_sq_sub_mul_of_odd_even {m n : ℤ} (h : Int.gcd m n = 1) (hm : m % 2 = 1) (hn : n % 2 = 0) : Int.gcd (m ^ 2 - n ^ 2) (2 * m * n) = 1 := by rw [Int.gcd, ← Int.natAbs_neg (m ^ 2 - n ^ 2)] rw [(by ring : 2 * m * n = 2 * n * m), (by ring : -(m ^ 2 - n ^ 2) = n ^ 2 - m ^ 2)] apply coprime_sq_sub_mul_of_even_odd _ hn hm; rwa [Int.gcd_comm] private theorem coprime_sq_sub_mul {m n : ℤ} (h : Int.gcd m n = 1) (hmn : m % 2 = 0 ∧ n % 2 = 1 ∨ m % 2 = 1 ∧ n % 2 = 0) : Int.gcd (m ^ 2 - n ^ 2) (2 * m * n) = 1 := by cases' hmn with h1 h2 · exact coprime_sq_sub_mul_of_even_odd h h1.left h1.right · exact coprime_sq_sub_mul_of_odd_even h h2.left h2.right private theorem coprime_sq_sub_sq_sum_of_odd_odd {m n : ℤ} (h : Int.gcd m n = 1) (hm : m % 2 = 1) (hn : n % 2 = 1) : 2 ∣ m ^ 2 + n ^ 2 ∧ 2 ∣ m ^ 2 - n ^ 2 ∧ (m ^ 2 - n ^ 2) / 2 % 2 = 0 ∧ Int.gcd ((m ^ 2 - n ^ 2) / 2) ((m ^ 2 + n ^ 2) / 2) = 1 := by cases' exists_eq_mul_left_of_dvd (Int.dvd_sub_of_emod_eq hm) with m0 hm2 cases' exists_eq_mul_left_of_dvd (Int.dvd_sub_of_emod_eq hn) with n0 hn2 rw [sub_eq_iff_eq_add] at hm2 hn2 subst m subst n have h1 : (m0 * 2 + 1) ^ 2 + (n0 * 2 + 1) ^ 2 = 2 * (2 * (m0 ^ 2 + n0 ^ 2 + m0 + n0) + 1) := by ring have h2 : (m0 * 2 + 1) ^ 2 - (n0 * 2 + 1) ^ 2 = 2 * (2 * (m0 ^ 2 - n0 ^ 2 + m0 - n0)) := by ring have h3 : ((m0 * 2 + 1) ^ 2 - (n0 * 2 + 1) ^ 2) / 2 % 2 = 0 := by rw [h2, Int.mul_ediv_cancel_left, Int.mul_emod_right] decide refine ⟨⟨_, h1⟩, ⟨_, h2⟩, h3, ?_⟩ have h20 : (2 : ℤ) ≠ 0 := by decide rw [h1, h2, Int.mul_ediv_cancel_left _ h20, Int.mul_ediv_cancel_left _ h20] by_contra h4 obtain ⟨p, hp, hp1, hp2⟩ := Nat.Prime.not_coprime_iff_dvd.mp h4 apply hp.not_dvd_one rw [← h] rw [← Int.natCast_dvd] at hp1 hp2 apply Nat.dvd_gcd · apply Int.Prime.dvd_natAbs_of_coe_dvd_sq hp convert dvd_add hp1 hp2 ring · apply Int.Prime.dvd_natAbs_of_coe_dvd_sq hp convert dvd_sub hp2 hp1 ring namespace PythagoreanTriple variable {x y z : ℤ} (h : PythagoreanTriple x y z) theorem isPrimitiveClassified_aux (hc : x.gcd y = 1) (hzpos : 0 < z) {m n : ℤ} (hm2n2 : 0 < m ^ 2 + n ^ 2) (hv2 : (x : ℚ) / z = 2 * m * n / ((m : ℚ) ^ 2 + (n : ℚ) ^ 2)) (hw2 : (y : ℚ) / z = ((m : ℚ) ^ 2 - (n : ℚ) ^ 2) / ((m : ℚ) ^ 2 + (n : ℚ) ^ 2)) (H : Int.gcd (m ^ 2 - n ^ 2) (m ^ 2 + n ^ 2) = 1) (co : Int.gcd m n = 1) (pp : m % 2 = 0 ∧ n % 2 = 1 ∨ m % 2 = 1 ∧ n % 2 = 0) : h.IsPrimitiveClassified := by have hz : z ≠ 0 := ne_of_gt hzpos have h2 : y = m ^ 2 - n ^ 2 ∧ z = m ^ 2 + n ^ 2 := by apply Rat.div_int_inj hzpos hm2n2 (h.coprime_of_coprime hc) H rw [hw2] norm_cast use m, n apply And.intro _ (And.intro co pp) right refine ⟨?_, h2.left⟩ rw [← Rat.coe_int_inj _ _, ← div_left_inj' ((mt (Rat.coe_int_inj z 0).mp) hz), hv2, h2.right] norm_cast theorem isPrimitiveClassified_of_coprime_of_odd_of_pos (hc : Int.gcd x y = 1) (hyo : y % 2 = 1) (hzpos : 0 < z) : h.IsPrimitiveClassified := by by_cases h0 : x = 0 · exact h.isPrimitiveClassified_of_coprime_of_zero_left hc h0 let v := (x : ℚ) / z let w := (y : ℚ) / z have hq : v ^ 2 + w ^ 2 = 1 := by field_simp [v, w, sq] norm_cast have hvz : v ≠ 0 := by field_simp [v] exact h0 have hw1 : w ≠ -1 := by contrapose! hvz with hw1 -- Porting note: `contrapose` unfolds local names, refold them replace hw1 : w = -1 := hw1; show v = 0 rw [hw1, neg_sq, one_pow, add_left_eq_self] at hq exact pow_eq_zero hq have hQ : ∀ x : ℚ, 1 + x ^ 2 ≠ 0 := by intro q apply ne_of_gt exact lt_add_of_pos_of_le zero_lt_one (sq_nonneg q) have hp : (⟨v, w⟩ : ℚ × ℚ) ∈ { p : ℚ × ℚ | p.1 ^ 2 + p.2 ^ 2 = 1 ∧ p.2 ≠ -1 } := ⟨hq, hw1⟩ let q := (circleEquivGen hQ).symm ⟨⟨v, w⟩, hp⟩ have ht4 : v = 2 * q / (1 + q ^ 2) ∧ w = (1 - q ^ 2) / (1 + q ^ 2) := by apply Prod.mk.inj have := ((circleEquivGen hQ).apply_symm_apply ⟨⟨v, w⟩, hp⟩).symm exact congr_arg Subtype.val this let m := (q.den : ℤ) let n := q.num have hm0 : m ≠ 0 := by -- Added to adapt to leanprover/lean4#2734. -- Without `unfold_let`, `norm_cast` can't see the coercion. -- One might try `zeta := true` in `Tactic.NormCast.derive`, -- but that seems to break many other things. unfold_let m norm_cast apply Rat.den_nz q have hq2 : q = n / m := (Rat.num_div_den q).symm have hm2n2 : 0 < m ^ 2 + n ^ 2 := by positivity have hm2n20 : (m ^ 2 + n ^ 2 : ℚ) ≠ 0 := by positivity have hx1 {j k : ℚ} (h₁ : k ≠ 0) (h₂ : k ^ 2 + j ^ 2 ≠ 0) : (1 - (j / k) ^ 2) / (1 + (j / k) ^ 2) = (k ^ 2 - j ^ 2) / (k ^ 2 + j ^ 2) := by field_simp have hw2 : w = ((m : ℚ) ^ 2 - (n : ℚ) ^ 2) / ((m : ℚ) ^ 2 + (n : ℚ) ^ 2) := by calc w = (1 - q ^ 2) / (1 + q ^ 2) := by apply ht4.2 _ = (1 - (↑n / ↑m) ^ 2) / (1 + (↑n / ↑m) ^ 2) := by rw [hq2] _ = _ := by exact hx1 (Int.cast_ne_zero.mpr hm0) hm2n20 have hx2 {j k : ℚ} (h₁ : k ≠ 0) (h₂ : k ^ 2 + j ^ 2 ≠ 0) : 2 * (j / k) / (1 + (j / k) ^ 2) = 2 * k * j / (k ^ 2 + j ^ 2) := have h₃ : k * (k ^ 2 + j ^ 2) ≠ 0 := mul_ne_zero h₁ h₂ by field_simp; ring have hv2 : v = 2 * m * n / ((m : ℚ) ^ 2 + (n : ℚ) ^ 2) := by calc v = 2 * q / (1 + q ^ 2) := by apply ht4.1 _ = 2 * (n / m) / (1 + (↑n / ↑m) ^ 2) := by rw [hq2] _ = _ := by exact hx2 (Int.cast_ne_zero.mpr hm0) hm2n20 have hnmcp : Int.gcd n m = 1 := q.reduced have hmncp : Int.gcd m n = 1 := by rw [Int.gcd_comm] exact hnmcp cases' Int.emod_two_eq_zero_or_one m with hm2 hm2 <;> cases' Int.emod_two_eq_zero_or_one n with hn2 hn2 · -- m even, n even exfalso have h1 : 2 ∣ (Int.gcd n m : ℤ) := Int.dvd_gcd (Int.dvd_of_emod_eq_zero hn2) (Int.dvd_of_emod_eq_zero hm2) rw [hnmcp] at h1 revert h1 decide · -- m even, n odd apply h.isPrimitiveClassified_aux hc hzpos hm2n2 hv2 hw2 _ hmncp · apply Or.intro_left exact And.intro hm2 hn2 · apply coprime_sq_sub_sq_add_of_even_odd hmncp hm2 hn2 · -- m odd, n even apply h.isPrimitiveClassified_aux hc hzpos hm2n2 hv2 hw2 _ hmncp · apply Or.intro_right exact And.intro hm2 hn2 apply coprime_sq_sub_sq_add_of_odd_even hmncp hm2 hn2 · -- m odd, n odd exfalso have h1 : 2 ∣ m ^ 2 + n ^ 2 ∧ 2 ∣ m ^ 2 - n ^ 2 ∧ (m ^ 2 - n ^ 2) / 2 % 2 = 0 ∧ Int.gcd ((m ^ 2 - n ^ 2) / 2) ((m ^ 2 + n ^ 2) / 2) = 1 := coprime_sq_sub_sq_sum_of_odd_odd hmncp hm2 hn2 have h2 : y = (m ^ 2 - n ^ 2) / 2 ∧ z = (m ^ 2 + n ^ 2) / 2 := by apply Rat.div_int_inj hzpos _ (h.coprime_of_coprime hc) h1.2.2.2 · show w = _ rw [← Rat.divInt_eq_div, ← Rat.divInt_mul_right (by norm_num : (2 : ℤ) ≠ 0)] rw [Int.ediv_mul_cancel h1.1, Int.ediv_mul_cancel h1.2.1, hw2] norm_cast · apply (mul_lt_mul_right (by norm_num : 0 < (2 : ℤ))).mp rw [Int.ediv_mul_cancel h1.1, zero_mul] exact hm2n2 rw [h2.1, h1.2.2.1] at hyo revert hyo norm_num theorem isPrimitiveClassified_of_coprime_of_pos (hc : Int.gcd x y = 1) (hzpos : 0 < z) : h.IsPrimitiveClassified := by cases' h.even_odd_of_coprime hc with h1 h2 · exact h.isPrimitiveClassified_of_coprime_of_odd_of_pos hc h1.right hzpos rw [Int.gcd_comm] at hc obtain ⟨m, n, H⟩ := h.symm.isPrimitiveClassified_of_coprime_of_odd_of_pos hc h2.left hzpos use m, n; tauto theorem isPrimitiveClassified_of_coprime (hc : Int.gcd x y = 1) : h.IsPrimitiveClassified := by by_cases hz : 0 < z · exact h.isPrimitiveClassified_of_coprime_of_pos hc hz have h' : PythagoreanTriple x y (-z) := by simpa [PythagoreanTriple, neg_mul_neg] using h.eq apply h'.isPrimitiveClassified_of_coprime_of_pos hc apply lt_of_le_of_ne _ (h'.ne_zero_of_coprime hc).symm exact le_neg.mp (not_lt.mp hz) theorem classified : h.IsClassified := by by_cases h0 : Int.gcd x y = 0 · have hx : x = 0 := by apply Int.natAbs_eq_zero.mp apply Nat.eq_zero_of_gcd_eq_zero_left h0 have hy : y = 0 := by apply Int.natAbs_eq_zero.mp apply Nat.eq_zero_of_gcd_eq_zero_right h0 use 0, 1, 0 field_simp [hx, hy] apply h.isClassified_of_normalize_isPrimitiveClassified apply h.normalize.isPrimitiveClassified_of_coprime apply Int.gcd_div_gcd_div_gcd (Nat.pos_of_ne_zero h0) theorem coprime_classification : PythagoreanTriple x y z ∧ Int.gcd x y = 1 ↔ ∃ m n, (x = m ^ 2 - n ^ 2 ∧ y = 2 * m * n ∨ x = 2 * m * n ∧ y = m ^ 2 - n ^ 2) ∧ (z = m ^ 2 + n ^ 2 ∨ z = -(m ^ 2 + n ^ 2)) ∧ Int.gcd m n = 1 ∧ (m % 2 = 0 ∧ n % 2 = 1 ∨ m % 2 = 1 ∧ n % 2 = 0) := by clear h -- Porting note: don't want this variable, but can't use `include` / `omit` constructor · intro h obtain ⟨m, n, H⟩ := h.left.isPrimitiveClassified_of_coprime h.right use m, n rcases H with ⟨⟨rfl, rfl⟩ | ⟨rfl, rfl⟩, co, pp⟩ · refine ⟨Or.inl ⟨rfl, rfl⟩, ?_, co, pp⟩ have : z ^ 2 = (m ^ 2 + n ^ 2) ^ 2 := by rw [sq, ← h.left.eq] ring simpa using eq_or_eq_neg_of_sq_eq_sq _ _ this · refine ⟨Or.inr ⟨rfl, rfl⟩, ?_, co, pp⟩ have : z ^ 2 = (m ^ 2 + n ^ 2) ^ 2 := by rw [sq, ← h.left.eq] ring simpa using eq_or_eq_neg_of_sq_eq_sq _ _ this · delta PythagoreanTriple rintro ⟨m, n, ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩, rfl | rfl, co, pp⟩ <;> first | constructor; ring; exact coprime_sq_sub_mul co pp | constructor; ring; rw [Int.gcd_comm]; exact coprime_sq_sub_mul co pp /-- by assuming `x` is odd and `z` is positive we get a slightly more precise classification of the Pythagorean triple `x ^ 2 + y ^ 2 = z ^ 2`-/ theorem coprime_classification' {x y z : ℤ} (h : PythagoreanTriple x y z) (h_coprime : Int.gcd x y = 1) (h_parity : x % 2 = 1) (h_pos : 0 < z) : ∃ m n, x = m ^ 2 - n ^ 2 ∧ y = 2 * m * n ∧ z = m ^ 2 + n ^ 2 ∧ Int.gcd m n = 1 ∧ (m % 2 = 0 ∧ n % 2 = 1 ∨ m % 2 = 1 ∧ n % 2 = 0) ∧ 0 ≤ m := by obtain ⟨m, n, ht1, ht2, ht3, ht4⟩ := PythagoreanTriple.coprime_classification.mp (And.intro h h_coprime) rcases le_or_lt 0 m with hm | hm · use m, n cases' ht1 with h_odd h_even · apply And.intro h_odd.1 apply And.intro h_odd.2 cases' ht2 with h_pos h_neg · apply And.intro h_pos (And.intro ht3 (And.intro ht4 hm)) · exfalso revert h_pos rw [h_neg] exact imp_false.mpr (not_lt.mpr (neg_nonpos.mpr (add_nonneg (sq_nonneg m) (sq_nonneg n)))) exfalso rcases h_even with ⟨rfl, -⟩ rw [mul_assoc, Int.mul_emod_right] at h_parity exact zero_ne_one h_parity · use -m, -n cases' ht1 with h_odd h_even · rw [neg_sq m] rw [neg_sq n] apply And.intro h_odd.1 constructor · rw [h_odd.2] ring cases' ht2 with h_pos h_neg · apply And.intro h_pos constructor · delta Int.gcd rw [Int.natAbs_neg, Int.natAbs_neg] exact ht3 · rw [Int.neg_emod_two, Int.neg_emod_two] apply And.intro ht4 linarith · exfalso revert h_pos rw [h_neg] exact imp_false.mpr (not_lt.mpr (neg_nonpos.mpr (add_nonneg (sq_nonneg m) (sq_nonneg n)))) exfalso rcases h_even with ⟨rfl, -⟩ rw [mul_assoc, Int.mul_emod_right] at h_parity exact zero_ne_one h_parity /-- **Formula for Pythagorean Triples** -/ theorem classification : PythagoreanTriple x y z ↔ ∃ k m n, (x = k * (m ^ 2 - n ^ 2) ∧ y = k * (2 * m * n) ∨ x = k * (2 * m * n) ∧ y = k * (m ^ 2 - n ^ 2)) ∧ (z = k * (m ^ 2 + n ^ 2) ∨ z = -k * (m ^ 2 + n ^ 2)) := by clear h constructor · intro h obtain ⟨k, m, n, H⟩ := h.classified use k, m, n rcases H with (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩) · refine ⟨Or.inl ⟨rfl, rfl⟩, ?_⟩ have : z ^ 2 = (k * (m ^ 2 + n ^ 2)) ^ 2 := by rw [sq, ← h.eq] ring simpa using eq_or_eq_neg_of_sq_eq_sq _ _ this · refine ⟨Or.inr ⟨rfl, rfl⟩, ?_⟩ have : z ^ 2 = (k * (m ^ 2 + n ^ 2)) ^ 2 := by rw [sq, ← h.eq] ring simpa using eq_or_eq_neg_of_sq_eq_sq _ _ this · rintro ⟨k, m, n, ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩, rfl | rfl⟩ <;> delta PythagoreanTriple <;> ring end PythagoreanTriple
NumberTheory\RamificationInertia.lean
/- Copyright (c) 2022 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.LinearAlgebra.Dimension.DivisionRing import Mathlib.RingTheory.DedekindDomain.Ideal /-! # 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 FiniteDimensional open UniqueFactorizationMonoid 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_lt 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_le (this' _ hle) theorem ramificationIdx_lt {n : ℕ} (hgt : ¬map f p ≤ P ^ n) : ramificationIdx f p P < n := by classical cases' n with n 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_lt 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_le (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 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_le 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 have := le_bot_iff.mp le contradiction 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] end IsDedekindDomain variable (f p P) attribute [local instance] Ideal.Quotient.field 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 [p.IsMaximal] : ℕ := if hPp : comap f P = p then @finrank (R ⧸ p) (S ⧸ P) _ _ <| @Algebra.toModule _ _ _ _ <| RingHom.toAlgebra <| Ideal.Quotient.lift p ((Ideal.Quotient.mk P).comp f) fun _ ha => Quotient.eq_zero_iff_mem.mpr <| mem_comap.mp <| hPp.symm ▸ ha 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 f 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 [Algebra R S] [Algebra (R ⧸ p) (S ⧸ P)] [IsScalarTower R (R ⧸ p) (S ⧸ P)] [hp : p.IsMaximal] : inertiaDeg (algebraMap R S) p P = finrank (R ⧸ p) (S ⧸ P) := by nontriviality S ⧸ P using inertiaDeg_of_subsingleton, finrank_zero_of_subsingleton have := comap_eq_of_scalar_tower_quotient (algebraMap (R ⧸ p) (S ⧸ P)).injective rw [inertiaDeg, dif_pos this] congr refine Algebra.algebra_ext _ _ fun x' => Quotient.inductionOn' x' fun x => ?_ change Ideal.Quotient.lift p _ _ (Ideal.Quotient.mk p x) = algebraMap _ _ (Ideal.Quotient.mk p x) rw [Ideal.Quotient.lift_mk, ← Ideal.Quotient.algebraMap_eq P, ← IsScalarTower.algebraMap_eq, ← Ideal.Quotient.algebraMap_eq, ← IsScalarTower.algebraMap_apply] end DecEq 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} /-- 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] [IsNoetherian R S] [Algebra R L] [IsScalarTower R S L] [IsScalarTower R K L] [IsIntegralClosure S R L] [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 (NoZeroSMulDivisors.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`. letI h : Module.Finite R (S ⧸ M) := Module.Finite.of_surjective (Submodule.mkQ _) (Submodule.Quotient.mk_surjective _) obtain ⟨n, a, ha⟩ := @Module.Finite.exists_fin _ _ _ _ _ h -- 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, ne_eq, 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 have : Algebra.IsAlgebraic R L := by have : NoZeroSMulDivisors R L := NoZeroSMulDivisors.of_algebraMap_injective hRL rw [← IsFractionRing.isAlgebraic_iff' R S] infer_instance refine IsFractionRing.ideal_span_singleton_map_subset R hRL span_d hx variable (K) 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_not_mem 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] [IsIntegralClosure S R L] [hp : p.IsMaximal] [IsNoetherian 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)]`. letI : Field (R ⧸ p) := Ideal.Quotient.field _ 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 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 inferrable. -/ def Quotient.algebraQuotientOfRamificationIdxNeZero [hfp : NeZero (ramificationIdx f p P)] : Algebra (R ⧸ p) (S ⧸ P) := Quotient.algebraQuotientOfLEComap (le_comap_of_ramificationIdx_ne_zero hfp.out) set_option synthInstance.checkSynthOrder false -- Porting note: this is okay by the remark below -- In this file, the value for `f` can be inferred. attribute [local instance] Ideal.Quotient.algebraQuotientOfRamificationIdxNeZero @[simp] theorem Quotient.algebraMap_quotient_of_ramificationIdx_neZero [NeZero (ramificationIdx f p P)] (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] 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 f 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 f 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_r_def] at h ⊢ simp only [_root_.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, _root_.map_mul, map_sub, mul_sub] theorem quotientToQuotientRangePowQuotSuccAux_mk {i : ℕ} {a : S} (a_mem : a ∈ P ^ i) (x : S) : quotientToQuotientRangePowQuotSuccAux f 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 f 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 f p P i) where toFun := quotientToQuotientRangePowQuotSuccAux f 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 [mul_assoc, _root_.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 f 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 f p P a_mem x theorem quotientToQuotientRangePowQuotSucc_injective [IsDedekindDomain S] [P.IsPrime] {i : ℕ} (hi : i < e) {a : S} (a_mem : a ∈ P ^ i) (a_not_mem : a ∉ P ^ (i + 1)) : Function.Injective (quotientToQuotientRangePowQuotSucc f 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, Subtype.coe_mk, 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_not_mem theorem quotientToQuotientRangePowQuotSucc_surjective [IsDedekindDomain S] (hP0 : P ≠ ⊥) [hP : P.IsPrime] {i : ℕ} (hi : i < e) {a : S} (a_mem : a ∈ P ^ i) (a_not_mem : a ∉ P ^ (i + 1)) : Function.Surjective (quotientToQuotientRangePowQuotSucc f 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, Subtype.coe_mk, 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_not_mem rwa [Ideal.count_normalizedFactors_eq a_mem a_not_mem, min_eq_left i.le_succ] · intro ha rw [Ideal.span_singleton_eq_bot.mp ha] at a_not_mem 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 f p P i)) ≃ₗ[R ⧸ p] S ⧸ P := by choose a a_mem a_not_mem 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 f p P a_mem · exact quotientToQuotientRangePowQuotSucc_injective f p P hi a_mem a_not_mem · exact quotientToQuotientRangePowQuotSucc_surjective f p P hP hi a_mem a_not_mem /-- 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 letI : Field (R ⧸ p) := Ideal.Quotient.field _ rw [← rank_range_of_injective _ (powQuotSuccInclusion_injective f p P i), (quotientRangePowQuotSuccInclusionEquiv f p P hP0 hi).symm.rank_eq] exact (rank_quotient_add_rank (LinearMap.range (powQuotSuccInclusion f 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 -- Porting note: Lean cannot figure out what to prove by itself 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 f 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 f 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 f p P letI := Ideal.Quotient.field p have hdim := rank_prime_pow_ramificationIdx _ _ _ hP0 he by_cases hP : FiniteDimensional (R ⧸ p) (S ⧸ P) · haveI := hP haveI := (finiteDimensional_iff_of_rank_eq_nsmul he hdim).mpr hP refine Cardinal.natCast_injective ?_ 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 open scoped Classical /-! ## Properties of the factors of `p.map (algebraMap R S)` -/ variable [IsDedekindDomain S] [Algebra R S] 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 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)) 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))) 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⟩ set_option synthInstance.checkSynthOrder false -- Porting note: this is okay since, as noted above, in this file the value of `f` can be inferred attribute [local instance] Quotient.algebraQuotientOfRamificationIdxNeZero instance Factors.isScalarTower (P : (factors (map (algebraMap R S) p)).toFinset) : IsScalarTower R (R ⧸ p) (S ⧸ (P : Ideal S)) := IsScalarTower.of_algebraMap_eq fun x => by simp attribute [local instance] Ideal.Quotient.field 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 (algebraMap R S) p P := by rw [finrank_prime_pow_ramificationIdx, inertiaDeg_algebraMap] exacts [Factors.ne_bot p P, NeZero.ne _] instance Factors.finiteDimensional_quotient [IsNoetherian R S] [p.IsMaximal] (P : (factors (map (algebraMap R S) p)).toFinset) : FiniteDimensional (R ⧸ p) (S ⧸ (P : Ideal S)) := IsNoetherian.iff_fg.mp <| isNoetherian_of_tower R <| isNoetherian_of_surjective S (Ideal.Quotient.mkₐ _ _).toLinearMap <| LinearMap.range_eq_top.mpr Ideal.Quotient.mk_surjective theorem Factors.inertiaDeg_ne_zero [IsNoetherian R S] [p.IsMaximal] (P : (factors (map (algebraMap R S) p)).toFinset) : inertiaDeg (algebraMap R S) p P ≠ 0 := by rw [inertiaDeg_algebraMap]; exact (FiniteDimensional.finrank_pos_iff.mpr inferInstance).ne' instance Factors.finiteDimensional_quotient_pow [IsNoetherian 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) (Factors.inertiaDeg_ne_zero p P) universe w /-- **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) /-- **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 {S} /-- 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 (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] [IsNoetherian R S] [IsIntegralClosure S R L] [p.IsMaximal] (hp0 : p ≠ ⊥) : (∑ P ∈ (factors (map (algebraMap R S) p)).toFinset, ramificationIdx (algebraMap R S) p P * inertiaDeg (algebraMap R S) p P) = finrank K L := by set e := ramificationIdx (algebraMap R S) p set f := inertiaDeg (algebraMap R S) p have inj_RL : Function.Injective (algebraMap R L) := by rw [IsScalarTower.algebraMap_eq R K L, RingHom.coe_comp] exact (RingHom.injective _).comp (IsFractionRing.injective R K) have inj_RS : Function.Injective (algebraMap R S) := by refine Function.Injective.of_comp (show Function.Injective (algebraMap S L ∘ _) from ?_) rw [← RingHom.coe_comp, ← IsScalarTower.algebraMap_eq] exact inj_RL 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 inj_RS, le_bot_iff] · exact finrank_quotient_map p K L end FactorsMap end Ideal
NumberTheory\Rayleigh.lean
/- Copyright (c) 2023 Jason Yuen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jason Yuen -/ import Mathlib.Data.Real.ConjExponents import Mathlib.Data.Real.Irrational /-! # Rayleigh's theorem on Beatty sequences This file proves Rayleigh's theorem on Beatty sequences. We start by proving `compl_beattySeq`, which is a generalization of Rayleigh's theorem, and eventually prove `Irrational.beattySeq_symmDiff_beattySeq_pos`, which is Rayleigh's theorem. ## Main definitions * `beattySeq`: In the Beatty sequence for real number `r`, the `k`th term is `⌊k * r⌋`. * `beattySeq'`: In this variant of the Beatty sequence for `r`, the `k`th term is `⌈k * r⌉ - 1`. ## Main statements Define the following Beatty sets, where `r` denotes a real number: * `B_r := {⌊k * r⌋ | k ∈ ℤ}` * `B'_r := {⌈k * r⌉ - 1 | k ∈ ℤ}` * `B⁺_r := {⌊r⌋, ⌊2r⌋, ⌊3r⌋, ...}` * `B⁺'_r := {⌈r⌉-1, ⌈2r⌉-1, ⌈3r⌉-1, ...}` The main statements are: * `compl_beattySeq`: Let `r` be a real number greater than 1, and `1/r + 1/s = 1`. Then the complement of `B_r` is `B'_s`. * `beattySeq_symmDiff_beattySeq'_pos`: Let `r` be a real number greater than 1, and `1/r + 1/s = 1`. Then `B⁺_r` and `B⁺'_s` partition the positive integers. * `Irrational.beattySeq_symmDiff_beattySeq_pos`: Let `r` be an irrational number greater than 1, and `1/r + 1/s = 1`. Then `B⁺_r` and `B⁺_s` partition the positive integers. ## References * [Wikipedia, *Beatty sequence*](https://en.wikipedia.org/wiki/Beatty_sequence) ## Tags beatty, sequence, rayleigh, irrational, floor, positive -/ /-- In the Beatty sequence for real number `r`, the `k`th term is `⌊k * r⌋`. -/ noncomputable def beattySeq (r : ℝ) : ℤ → ℤ := fun k ↦ ⌊k * r⌋ /-- In this variant of the Beatty sequence for `r`, the `k`th term is `⌈k * r⌉ - 1`. -/ noncomputable def beattySeq' (r : ℝ) : ℤ → ℤ := fun k ↦ ⌈k * r⌉ - 1 namespace Beatty variable {r s : ℝ} (hrs : r.IsConjExponent s) {j k : ℤ} /-- Let `r > 1` and `1/r + 1/s = 1`. Then `B_r` and `B'_s` are disjoint (i.e. no collision exists). -/ private theorem no_collision : Disjoint {beattySeq r k | k} {beattySeq' s k | k} := by rw [Set.disjoint_left] intro j ⟨k, h₁⟩ ⟨m, h₂⟩ rw [beattySeq, Int.floor_eq_iff, ← div_le_iff hrs.pos, ← lt_div_iff hrs.pos] at h₁ rw [beattySeq', sub_eq_iff_eq_add, Int.ceil_eq_iff, Int.cast_add, Int.cast_one, add_sub_cancel_right, ← div_lt_iff hrs.symm.pos, ← le_div_iff hrs.symm.pos] at h₂ have h₃ := add_lt_add_of_le_of_lt h₁.1 h₂.1 have h₄ := add_lt_add_of_lt_of_le h₁.2 h₂.2 simp_rw [div_eq_inv_mul, ← right_distrib, hrs.inv_add_inv_conj, one_mul] at h₃ h₄ rw [← Int.cast_one] at h₄ simp_rw [← Int.cast_add, Int.cast_lt, Int.lt_add_one_iff] at h₃ h₄ exact h₄.not_lt h₃ /-- Let `r > 1` and `1/r + 1/s = 1`. Suppose there is an integer `j` where `B_r` and `B'_s` both jump over `j` (i.e. an anti-collision). Then this leads to a contradiction. -/ private theorem no_anticollision : ¬∃ j k m : ℤ, k < j / r ∧ (j + 1) / r ≤ k + 1 ∧ m ≤ j / s ∧ (j + 1) / s < m + 1 := by intro ⟨j, k, m, h₁₁, h₁₂, h₂₁, h₂₂⟩ have h₃ := add_lt_add_of_lt_of_le h₁₁ h₂₁ have h₄ := add_lt_add_of_le_of_lt h₁₂ h₂₂ simp_rw [div_eq_inv_mul, ← right_distrib, hrs.inv_add_inv_conj, one_mul] at h₃ h₄ rw [← Int.cast_one, ← add_assoc, add_lt_add_iff_right, add_right_comm] at h₄ simp_rw [← Int.cast_add, Int.cast_lt, Int.lt_add_one_iff] at h₃ h₄ exact h₄.not_lt h₃ /-- Let `0 < r ∈ ℝ` and `j ∈ ℤ`. Then either `j ∈ B_r` or `B_r` jumps over `j`. -/ private theorem hit_or_miss (h : r > 0) : j ∈ {beattySeq r k | k} ∨ ∃ k : ℤ, k < j / r ∧ (j + 1) / r ≤ k + 1 := by -- for both cases, the candidate is `k = ⌈(j + 1) / r⌉ - 1` cases lt_or_ge ((⌈(j + 1) / r⌉ - 1) * r) j · refine Or.inr ⟨⌈(j + 1) / r⌉ - 1, ?_⟩ rw [Int.cast_sub, Int.cast_one, lt_div_iff h, sub_add_cancel] exact ⟨‹_›, Int.le_ceil _⟩ · refine Or.inl ⟨⌈(j + 1) / r⌉ - 1, ?_⟩ rw [beattySeq, Int.floor_eq_iff, Int.cast_sub, Int.cast_one, ← lt_div_iff h, sub_lt_iff_lt_add] exact ⟨‹_›, Int.ceil_lt_add_one _⟩ /-- Let `0 < r ∈ ℝ` and `j ∈ ℤ`. Then either `j ∈ B'_r` or `B'_r` jumps over `j`. -/ private theorem hit_or_miss' (h : r > 0) : j ∈ {beattySeq' r k | k} ∨ ∃ k : ℤ, k ≤ j / r ∧ (j + 1) / r < k + 1 := by -- for both cases, the candidate is `k = ⌊(j + 1) / r⌋` cases le_or_gt (⌊(j + 1) / r⌋ * r) j · exact Or.inr ⟨⌊(j + 1) / r⌋, (le_div_iff h).2 ‹_›, Int.lt_floor_add_one _⟩ · refine Or.inl ⟨⌊(j + 1) / r⌋, ?_⟩ rw [beattySeq', sub_eq_iff_eq_add, Int.ceil_eq_iff, Int.cast_add, Int.cast_one] constructor · rwa [add_sub_cancel_right] exact sub_nonneg.1 (Int.sub_floor_div_mul_nonneg (j + 1 : ℝ) h) end Beatty /-- Generalization of Rayleigh's theorem on Beatty sequences. Let `r` be a real number greater than 1, and `1/r + 1/s = 1`. Then the complement of `B_r` is `B'_s`. -/ theorem compl_beattySeq {r s : ℝ} (hrs : r.IsConjExponent s) : {beattySeq r k | k}ᶜ = {beattySeq' s k | k} := by ext j by_cases h₁ : j ∈ {beattySeq r k | k} <;> by_cases h₂ : j ∈ {beattySeq' s k | k} · exact (Set.not_disjoint_iff.2 ⟨j, h₁, h₂⟩ (Beatty.no_collision hrs)).elim · simp only [Set.mem_compl_iff, h₁, h₂, not_true_eq_false] · simp only [Set.mem_compl_iff, h₁, h₂, not_false_eq_true] · have ⟨k, h₁₁, h₁₂⟩ := (Beatty.hit_or_miss hrs.pos).resolve_left h₁ have ⟨m, h₂₁, h₂₂⟩ := (Beatty.hit_or_miss' hrs.symm.pos).resolve_left h₂ exact (Beatty.no_anticollision hrs ⟨j, k, m, h₁₁, h₁₂, h₂₁, h₂₂⟩).elim theorem compl_beattySeq' {r s : ℝ} (hrs : r.IsConjExponent s) : {beattySeq' r k | k}ᶜ = {beattySeq s k | k} := by rw [← compl_beattySeq hrs.symm, compl_compl] open scoped symmDiff /-- Generalization of Rayleigh's theorem on Beatty sequences. Let `r` be a real number greater than 1, and `1/r + 1/s = 1`. Then `B⁺_r` and `B⁺'_s` partition the positive integers. -/ theorem beattySeq_symmDiff_beattySeq'_pos {r s : ℝ} (hrs : r.IsConjExponent s) : {beattySeq r k | k > 0} ∆ {beattySeq' s k | k > 0} = {n | 0 < n} := by apply Set.eq_of_subset_of_subset · rintro j (⟨⟨k, hk, hjk⟩, -⟩ | ⟨⟨k, hk, hjk⟩, -⟩) · rw [Set.mem_setOf_eq, ← hjk, beattySeq, Int.floor_pos] exact one_le_mul_of_one_le_of_one_le (by norm_cast) hrs.one_lt.le · rw [Set.mem_setOf_eq, ← hjk, beattySeq', sub_pos, Int.lt_ceil, Int.cast_one] exact one_lt_mul_of_le_of_lt (by norm_cast) hrs.symm.one_lt intro j (hj : 0 < j) have hb₁ : ∀ s ≥ 0, j ∈ {beattySeq s k | k > 0} ↔ j ∈ {beattySeq s k | k} := by intro _ hs refine ⟨fun ⟨k, _, hk⟩ ↦ ⟨k, hk⟩, fun ⟨k, hk⟩ ↦ ⟨k, ?_, hk⟩⟩ rw [← hk, beattySeq, Int.floor_pos] at hj exact_mod_cast pos_of_mul_pos_left (zero_lt_one.trans_le hj) hs have hb₂ : ∀ s ≥ 0, j ∈ {beattySeq' s k | k > 0} ↔ j ∈ {beattySeq' s k | k} := by intro _ hs refine ⟨fun ⟨k, _, hk⟩ ↦ ⟨k, hk⟩, fun ⟨k, hk⟩ ↦ ⟨k, ?_, hk⟩⟩ rw [← hk, beattySeq', sub_pos, Int.lt_ceil, Int.cast_one] at hj exact_mod_cast pos_of_mul_pos_left (zero_lt_one.trans hj) hs rw [Set.mem_symmDiff, hb₁ _ hrs.nonneg, hb₂ _ hrs.symm.nonneg, ← compl_beattySeq hrs, Set.not_mem_compl_iff, Set.mem_compl_iff, and_self, and_self] exact or_not theorem beattySeq'_symmDiff_beattySeq_pos {r s : ℝ} (hrs : r.IsConjExponent s) : {beattySeq' r k | k > 0} ∆ {beattySeq s k | k > 0} = {n | 0 < n} := by rw [symmDiff_comm, beattySeq_symmDiff_beattySeq'_pos hrs.symm] /-- Let `r` be an irrational number. Then `B⁺_r` and `B⁺'_r` are equal. -/ theorem Irrational.beattySeq'_pos_eq {r : ℝ} (hr : Irrational r) : {beattySeq' r k | k > 0} = {beattySeq r k | k > 0} := by dsimp only [beattySeq, beattySeq'] congr! 4; rename_i k; rw [and_congr_right_iff]; intro hk; congr! rw [sub_eq_iff_eq_add, Int.ceil_eq_iff, Int.cast_add, Int.cast_one, add_sub_cancel_right] refine ⟨(Int.floor_le _).lt_of_ne fun h ↦ ?_, (Int.lt_floor_add_one _).le⟩ exact (hr.int_mul hk.ne').ne_int ⌊k * r⌋ h.symm /-- **Rayleigh's theorem** on Beatty sequences. Let `r` be an irrational number greater than 1, and `1/r + 1/s = 1`. Then `B⁺_r` and `B⁺_s` partition the positive integers. -/ theorem Irrational.beattySeq_symmDiff_beattySeq_pos {r s : ℝ} (hrs : r.IsConjExponent s) (hr : Irrational r) : {beattySeq r k | k > 0} ∆ {beattySeq s k | k > 0} = {n | 0 < n} := by rw [← hr.beattySeq'_pos_eq, beattySeq'_symmDiff_beattySeq_pos hrs]
NumberTheory\SiegelsLemma.lean
/- Copyright (c) 2024 Fabrizio Barroero. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Fabrizio Barroero, Laura Capuano, Amos Turchet -/ import Mathlib.Analysis.Matrix import Mathlib.Data.Pi.Interval import Mathlib.Tactic.Rify /-! # Siegel's Lemma In this file we introduce and prove Siegel's Lemma in its most basic version. This is a fundamental tool in diophantine approximation and transcendency and says that there exists a "small" integral non-zero solution of a non-trivial underdetermined system of linear equations with integer coefficients. ## Main results - `exists_ne_zero_int_vec_norm_le`: Given a non-zero `m × n` matrix `A` with `m < n` the linear system it determines has a non-zero integer solution `t` with `‖t‖ ≤ ((n * ‖A‖) ^ ((m : ℝ) / (n - m)))` ## Notation - `‖_‖ ` : Matrix.seminormedAddCommGroup is the sup norm, the maximum of the absolute values of the entries of the matrix ## References See [M. Hindry and J. Silverman, Diophantine Geometry: an Introduction][hindrysilverman00]. -/ /- We set ‖⬝‖ to be Matrix.seminormedAddCommGroup -/ attribute [local instance] Matrix.seminormedAddCommGroup open Matrix Finset namespace Int.Matrix variable {α β : Type*} [Fintype α] [Fintype β] (A : Matrix α β ℤ) (v : β → ℤ) (hn : Fintype.card α < Fintype.card β) (hm : 0 < Fintype.card α) -- Some definitions and relative properties local notation3 "m" => Fintype.card α local notation3 "n" => Fintype.card β local notation3 "e" => m / ((n : ℝ) - m) -- exponent local notation3 "B" => Nat.floor (((n : ℝ) * max 1 ‖A‖) ^ e) -- B' is the vector with all components = B local notation3 "B'" => fun _ : β => (B : ℤ) -- T is the box [0 B]^n local notation3 "T" => Finset.Icc 0 B' local notation3 "P" => fun i : α => ∑ j : β, B * posPart (A i j) local notation3 "N" => fun i : α => ∑ j : β, B * (- negPart (A i j)) -- S is the box where the image of T goes local notation3 "S" => Finset.Icc N P section preparation variable [DecidableEq α] [DecidableEq β] /- In order to apply Pigeonhole we need: # Step 1: ∀ v ∈ T, A *ᵥ v ∈ S and # Step 2: S.card < T.card Pigeonhole will give different x and y in T with A.mulVec x = A.mulVec y in S Their difference is the solution we are looking for -/ -- # Step 1: ∀ v ∈ T, A *ᵥ v ∈ S private lemma image_T_subset_S (v) (hv : v ∈ T) : A *ᵥ v ∈ S := by rw [mem_Icc] at hv ⊢ have mulVec_def : A.mulVec v = fun i ↦ Finset.sum univ fun j : β ↦ A i j * v j := rfl rw [mulVec_def] refine ⟨fun i ↦ ?_, fun i ↦ ?_⟩ all_goals simp only [mul_neg] gcongr ∑ _ : α, ?_ with j _ -- Get rid of sums rw [← mul_comm (v j)] -- Move A i j to the right of the products rcases le_total 0 (A i j) with hsign | hsign-- We have to distinguish cases: we have now 4 goals · rw [negPart_eq_zero.2 hsign] exact mul_nonneg (hv.1 j) hsign · rw [negPart_eq_neg.2 hsign] simp only [mul_neg, neg_neg] exact mul_le_mul_of_nonpos_right (hv.2 j) hsign · rw [posPart_eq_self.2 hsign] exact mul_le_mul_of_nonneg_right (hv.2 j) hsign · rw [posPart_eq_zero.2 hsign] exact mul_nonpos_of_nonneg_of_nonpos (hv.1 j) hsign -- # Preparation for Step 2 private lemma card_T_eq : (T).card = (B + 1) ^ n := by rw [Pi.card_Icc 0 B'] simp only [Pi.zero_apply, card_Icc, sub_zero, toNat_ofNat_add_one, prod_const, card_univ, add_pos_iff, zero_lt_one, or_true] -- This lemma is necessary to be able to apply the formula (Icc a b).card = b + 1 - a private lemma N_le_P_add_one (i : α) : N i ≤ P i + 1 := by calc N i _ ≤ 0 := by apply Finset.sum_nonpos intro j _ simp only [mul_neg, Left.neg_nonpos_iff] exact mul_nonneg (Nat.cast_nonneg B) (negPart_nonneg (A i j)) _ ≤ P i + 1 := by apply le_trans (Finset.sum_nonneg _) (Int.le_add_one (le_refl P i)) intro j _ exact mul_nonneg (Nat.cast_nonneg B) (posPart_nonneg (A i j)) private lemma card_S_eq : (Finset.Icc N P).card = ∏ i : α, (P i - N i + 1) := by rw [Pi.card_Icc N P, Nat.cast_prod] congr ext i rw [Int.card_Icc_of_le (N i) (P i) (N_le_P_add_one A i)] exact add_sub_right_comm (P i) 1 (N i) /-- The sup norm of a non-zero integer matrix is at least one -/ lemma one_le_norm_A_of_ne_zero (hA : A ≠ 0) : 1 ≤ ‖A‖ := by by_contra! h apply hA ext i j simp only [zero_apply] rw [norm_lt_iff Real.zero_lt_one] at h specialize h i j rw [Int.norm_eq_abs] at h norm_cast at h exact Int.abs_lt_one_iff.1 h -- # Step 2: S.card < T.card open Real Nat private lemma card_S_lt_card_T : (S).card < (T).card := by zify -- This is necessary to use card_S_eq rw [card_T_eq A, card_S_eq] rify -- This is necessary because ‖A‖ is a real number calc ∏ x : α, (∑ x_1 : β, ↑B * ↑(A x x_1)⁺ - ∑ x_1 : β, ↑B * -↑(A x x_1)⁻ + 1) ≤ ∏ x : α, (n * max 1 ‖A‖ * B + 1) := by refine Finset.prod_le_prod (fun i _ ↦ ?_) (fun i _ ↦ ?_) · have h := N_le_P_add_one A i rify at h linarith only [h] · simp only [mul_neg, sum_neg_distrib, sub_neg_eq_add, add_le_add_iff_right] have h1 : n * max 1 ‖A‖ * B = ∑ _ : β, max 1 ‖A‖ * B := by simp only [sum_const, card_univ, nsmul_eq_mul] ring simp_rw [h1, ← Finset.sum_add_distrib, ← mul_add, mul_comm (max 1 ‖A‖), ← Int.cast_add] gcongr with j _ rw [posPart_add_negPart (A i j), Int.cast_abs] exact le_trans (norm_entry_le_entrywise_sup_norm A) (le_max_right ..) _ = (n * max 1 ‖A‖ * B + 1) ^ m := by simp only [prod_const, card_univ] _ ≤ (n * max 1 ‖A‖) ^ m * (B + 1) ^ m := by rw [← mul_pow, mul_add, mul_one] gcongr have H : 1 ≤ (n : ℝ) := mod_cast (hm.trans hn) exact one_le_mul_of_one_le_of_one_le H <| le_max_left .. _ = ((n * max 1 ‖A‖) ^ (m / ((n : ℝ) - m))) ^ ((n : ℝ) - m) * (B + 1) ^ m := by congr 1 rw [← rpow_mul (mul_nonneg (Nat.cast_nonneg' n) (le_trans zero_le_one (le_max_left ..))), ← Real.rpow_natCast, div_mul_cancel₀] exact sub_ne_zero_of_ne (mod_cast hn.ne') _ < (B + 1) ^ ((n : ℝ) - m) * (B + 1) ^ m := by gcongr · exact sub_pos.mpr (mod_cast hn) · exact Nat.lt_floor_add_one ((n * max 1 ‖A‖) ^ e) _ = (B + 1) ^ n := by rw [← rpow_natCast, ← rpow_add (Nat.cast_add_one_pos B), ← rpow_natCast, sub_add_cancel] end preparation theorem exists_ne_zero_int_vec_norm_le : ∃ t : β → ℤ, t ≠ 0 ∧ A *ᵥ t = 0 ∧ ‖t‖ ≤ (n * max 1 ‖A‖) ^ ((m : ℝ) / (n - m)) := by classical -- Pigeonhole rcases Finset.exists_ne_map_eq_of_card_lt_of_maps_to (card_S_lt_card_T A hn hm) (image_T_subset_S A) with ⟨x, hxT, y, hyT, hneq, hfeq⟩ -- Proofs that x - y ≠ 0 and x - y is a solution refine ⟨x - y, sub_ne_zero.mpr hneq, by simp only [mulVec_sub, sub_eq_zero, hfeq], ?_⟩ -- Inequality have n_mul_norm_A_pow_e_nonneg : 0 ≤ (n * max 1 ‖A‖) ^ e := by positivity rw [← norm_col (ι := Unit), norm_le_iff n_mul_norm_A_pow_e_nonneg] intro i j simp only [col_apply, Pi.sub_apply] rw [Int.norm_eq_abs, ← Int.cast_abs] refine le_trans ?_ (Nat.floor_le n_mul_norm_A_pow_e_nonneg) norm_cast rw [abs_le] rw [Finset.mem_Icc] at hxT hyT constructor · simp only [neg_le_sub_iff_le_add] apply le_trans (hyT.2 i) norm_cast simp only [le_add_iff_nonneg_left] exact hxT.1 i · simp only [tsub_le_iff_right] apply le_trans (hxT.2 i) norm_cast simp only [le_add_iff_nonneg_right] exact hyT.1 i theorem exists_ne_zero_int_vec_norm_le' (hA : A ≠ 0) : ∃ t : β → ℤ, t ≠ 0 ∧ A *ᵥ t = 0 ∧ ‖t‖ ≤ (n * ‖A‖) ^ ((m : ℝ) / (n - m)) := by have := exists_ne_zero_int_vec_norm_le A hn hm rwa [max_eq_right] at this exact Int.Matrix.one_le_norm_A_of_ne_zero _ hA end Int.Matrix
NumberTheory\SmoothNumbers.lean
/- Copyright (c) 2023 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll, Ralf Stephan -/ import Mathlib.Data.Nat.Factorization.Defs import Mathlib.Data.Nat.Squarefree /-! # Smooth numbers For `s : Finset ℕ` we define the set `Nat.factoredNumbers s` of "`s`-factored numbers" consisting of the positive natural numbers all of whose prime factors are in `s`, and we provide some API for this. We then define the set `Nat.smoothNumbers n` consisting of the positive natural numbers all of whose prime factors are strictly less than `n`. This is the special case `s = Finset.range n` of the set of `s`-factored numbers. We also define the finite set `Nat.primesBelow n` to be the set of prime numbers less than `n`. The main definition `Nat.equivProdNatSmoothNumbers` establishes the bijection between `ℕ × (smoothNumbers p)` and `smoothNumbers (p+1)` given by sending `(e, n)` to `p^e * n`. Here `p` is a prime number. It is obtained from the more general bijection between `ℕ × (factoredNumbers s)` and `factoredNumbers (s ∪ {p})`; see `Nat.equivProdNatFactoredNumbers`. Additionally, we define `Nat.smoothNumbersUpTo N n` as the `Finset` of `n`-smooth numbers up to and including `N`, and similarly `Nat.roughNumbersUpTo` for its complement in `{1, ..., N}`, and we provide some API, in particular bounds for their cardinalities; see `Nat.smoothNumbersUpTo_card_le` and `Nat.roughNumbersUpTo_card_le`. -/ namespace Nat /-- `primesBelow n` is the set of primes less than `n` as a `Finset`. -/ def primesBelow (n : ℕ) : Finset ℕ := (Finset.range n).filter (fun p ↦ p.Prime) @[simp] lemma primesBelow_zero : primesBelow 0 = ∅ := by rw [primesBelow, Finset.range_zero, Finset.filter_empty] lemma mem_primesBelow {k n : ℕ} : n ∈ primesBelow k ↔ n < k ∧ n.Prime := by simp [primesBelow] lemma prime_of_mem_primesBelow {p n : ℕ} (h : p ∈ n.primesBelow) : p.Prime := (Finset.mem_filter.mp h).2 lemma lt_of_mem_primesBelow {p n : ℕ} (h : p ∈ n.primesBelow) : p < n := Finset.mem_range.mp <| Finset.mem_of_mem_filter p h lemma primesBelow_succ (n : ℕ) : primesBelow n.succ = if n.Prime then insert n (primesBelow n) else primesBelow n := by rw [primesBelow, primesBelow, Finset.range_succ, Finset.filter_insert] lemma not_mem_primesBelow (n : ℕ) : n ∉ primesBelow n := fun hn ↦ (lt_of_mem_primesBelow hn).false /-! ### `s`-factored numbers -/ /-- `factoredNumbers s`, for a finite set `s` of natural numbers, is the set of positive natural numbers all of whose prime factors are in `s`. -/ def factoredNumbers (s : Finset ℕ) : Set ℕ := {m | m ≠ 0 ∧ ∀ p ∈ primeFactorsList m, p ∈ s} lemma mem_factoredNumbers {s : Finset ℕ} {m : ℕ} : m ∈ factoredNumbers s ↔ m ≠ 0 ∧ ∀ p ∈ primeFactorsList m, p ∈ s := Iff.rfl /-- Membership in `Nat.factoredNumbers n` is decidable. -/ instance (s : Finset ℕ) : DecidablePred (· ∈ factoredNumbers s) := inferInstanceAs <| DecidablePred fun x ↦ x ∈ {m | m ≠ 0 ∧ ∀ p ∈ primeFactorsList m, p ∈ s} /-- A number that divides an `s`-factored number is itself `s`-factored. -/ lemma mem_factoredNumbers_of_dvd {s : Finset ℕ} {m k : ℕ} (h : m ∈ factoredNumbers s) (h' : k ∣ m) : k ∈ factoredNumbers s := by obtain ⟨h₁, h₂⟩ := h have hk := ne_zero_of_dvd_ne_zero h₁ h' refine ⟨hk, fun p hp ↦ h₂ p ?_⟩ rw [mem_primeFactorsList <| by assumption] at hp ⊢ exact ⟨hp.1, hp.2.trans h'⟩ /-- `m` is `s`-factored if and only if `m` is nonzero and all prime divisors `≤ m` of `m` are in `s`. -/ lemma mem_factoredNumbers_iff_forall_le {s : Finset ℕ} {m : ℕ} : m ∈ factoredNumbers s ↔ m ≠ 0 ∧ ∀ p ≤ m, p.Prime → p ∣ m → p ∈ s := by simp_rw [mem_factoredNumbers, mem_primeFactorsList'] exact ⟨fun ⟨H₀, H₁⟩ ↦ ⟨H₀, fun p _ hp₂ hp₃ ↦ H₁ p ⟨hp₂, hp₃, H₀⟩⟩, fun ⟨H₀, H₁⟩ ↦ ⟨H₀, fun p ⟨hp₁, hp₂, hp₃⟩ ↦ H₁ p (le_of_dvd (Nat.pos_of_ne_zero hp₃) hp₂) hp₁ hp₂⟩⟩ /-- `m` is `s`-factored if and only if all prime divisors of `m` are in `s`. -/ lemma mem_factoredNumbers' {s : Finset ℕ} {m : ℕ} : m ∈ factoredNumbers s ↔ ∀ p, p.Prime → p ∣ m → p ∈ s := by obtain ⟨p, hp₁, hp₂⟩ := exists_infinite_primes (1 + Finset.sup s id) rw [mem_factoredNumbers_iff_forall_le] refine ⟨fun ⟨H₀, H₁⟩ ↦ fun p hp₁ hp₂ ↦ H₁ p (le_of_dvd (Nat.pos_of_ne_zero H₀) hp₂) hp₁ hp₂, fun H ↦ ⟨fun h ↦ lt_irrefl p ?_, fun p _ ↦ H p⟩⟩ calc p ≤ s.sup id := Finset.le_sup (f := @id ℕ) <| H p hp₂ <| h.symm ▸ dvd_zero p _ < 1 + s.sup id := lt_one_add _ _ ≤ p := hp₁ lemma ne_zero_of_mem_factoredNumbers {s : Finset ℕ} {m : ℕ} (h : m ∈ factoredNumbers s) : m ≠ 0 := h.1 /-- The `Finset` of prime factors of an `s`-factored number is contained in `s`. -/ lemma primeFactors_subset_of_mem_factoredNumbers {s : Finset ℕ} {m : ℕ} (hm : m ∈ factoredNumbers s) : m.primeFactors ⊆ s := by rw [mem_factoredNumbers] at hm exact fun n hn ↦ hm.2 n (mem_primeFactors_iff_mem_primeFactorsList.mp hn) /-- If `m ≠ 0` and the `Finset` of prime factors of `m` is contained in `s`, then `m` is `s`-factored. -/ lemma mem_factoredNumbers_of_primeFactors_subset {s : Finset ℕ} {m : ℕ} (hm : m ≠ 0) (hp : m.primeFactors ⊆ s) : m ∈ factoredNumbers s := by rw [mem_factoredNumbers] exact ⟨hm, fun p hp' ↦ hp <| mem_primeFactors_iff_mem_primeFactorsList.mpr hp'⟩ /-- `m` is `s`-factored if and only if `m ≠ 0` and its `Finset` of prime factors is contained in `s`. -/ lemma mem_factoredNumbers_iff_primeFactors_subset {s : Finset ℕ} {m : ℕ} : m ∈ factoredNumbers s ↔ m ≠ 0 ∧ m.primeFactors ⊆ s := ⟨fun h ↦ ⟨ne_zero_of_mem_factoredNumbers h, primeFactors_subset_of_mem_factoredNumbers h⟩, fun ⟨h₁, h₂⟩ ↦ mem_factoredNumbers_of_primeFactors_subset h₁ h₂⟩ @[simp] lemma factoredNumbers_empty : factoredNumbers ∅ = {1} := by ext m simp only [mem_factoredNumbers, Finset.not_mem_empty, ← List.eq_nil_iff_forall_not_mem, primeFactorsList_eq_nil, and_or_left, not_and_self_iff, ne_and_eq_iff_right zero_ne_one, false_or, Set.mem_singleton_iff] /-- The product of two `s`-factored numbers is again `s`-factored. -/ lemma mul_mem_factoredNumbers {s : Finset ℕ} {m n : ℕ} (hm : m ∈ factoredNumbers s) (hn : n ∈ factoredNumbers s) : m * n ∈ factoredNumbers s := by have hm' := primeFactors_subset_of_mem_factoredNumbers hm have hn' := primeFactors_subset_of_mem_factoredNumbers hn exact mem_factoredNumbers_of_primeFactors_subset (mul_ne_zero hm.1 hn.1) <| primeFactors_mul hm.1 hn.1 ▸ Finset.union_subset hm' hn' /-- The product of the prime factors of `n` that are in `s` is an `s`-factored number. -/ lemma prod_mem_factoredNumbers (s : Finset ℕ) (n : ℕ) : (n.primeFactorsList.filter (· ∈ s)).prod ∈ factoredNumbers s := by have h₀ : (n.primeFactorsList.filter (· ∈ s)).prod ≠ 0 := List.prod_ne_zero fun h ↦ (pos_of_mem_primeFactorsList (List.mem_of_mem_filter h)).false refine ⟨h₀, fun p hp ↦ ?_⟩ obtain ⟨H₁, H₂⟩ := (mem_primeFactorsList h₀).mp hp simpa only [decide_eq_true_eq] using List.of_mem_filter <| mem_list_primes_of_dvd_prod H₁.prime (fun _ hq ↦ (prime_of_mem_primeFactorsList (List.mem_of_mem_filter hq)).prime) H₂ /-- The sets of `s`-factored and of `s ∪ {N}`-factored numbers are the same when `N` is not prime. See `Nat.equivProdNatFactoredNumbers` for when `N` is prime. -/ lemma factoredNumbers_insert (s : Finset ℕ) {N : ℕ} (hN : ¬ N.Prime) : factoredNumbers (insert N s) = factoredNumbers s := by ext m refine ⟨fun hm ↦ ⟨hm.1, fun p hp ↦ ?_⟩, fun hm ↦ ⟨hm.1, fun p hp ↦ Finset.mem_insert_of_mem <| hm.2 p hp⟩⟩ exact Finset.mem_of_mem_insert_of_ne (hm.2 p hp) fun h ↦ hN <| h ▸ prime_of_mem_primeFactorsList hp @[gcongr] lemma factoredNumbers_mono {s t : Finset ℕ} (hst : s ≤ t) : factoredNumbers s ⊆ factoredNumbers t := fun _ hx ↦ ⟨hx.1, fun p hp ↦ hst <| hx.2 p hp⟩ /-- The non-zero non-`s`-factored numbers are `≥ N` when `s` contains all primes less than `N`. -/ lemma factoredNumbers_compl {N : ℕ} {s : Finset ℕ} (h : primesBelow N ≤ s) : (factoredNumbers s)ᶜ \ {0} ⊆ {n | N ≤ n} := by intro n hn simp only [Set.mem_compl_iff, mem_factoredNumbers, Set.mem_diff, ne_eq, not_and, not_forall, not_lt, exists_prop, Set.mem_singleton_iff] at hn simp only [Set.mem_setOf_eq] obtain ⟨p, hp₁, hp₂⟩ := hn.1 hn.2 have : N ≤ p := by contrapose! hp₂ exact h <| mem_primesBelow.mpr ⟨hp₂, prime_of_mem_primeFactorsList hp₁⟩ exact this.trans <| le_of_mem_primeFactorsList hp₁ /-- If `p` is a prime and `n` is `s`-factored, then every product `p^e * n` is `s ∪ {p}`-factored. -/ lemma pow_mul_mem_factoredNumbers {s : Finset ℕ} {p n : ℕ} (hp : p.Prime) (e : ℕ) (hn : n ∈ factoredNumbers s) : p ^ e * n ∈ factoredNumbers (insert p s) := by have hp' := pow_ne_zero e hp.ne_zero refine ⟨mul_ne_zero hp' hn.1, fun q hq ↦ ?_⟩ rcases (mem_primeFactorsList_mul hp' hn.1).mp hq with H | H · rw [mem_primeFactorsList hp'] at H rw [(prime_dvd_prime_iff_eq H.1 hp).mp <| H.1.dvd_of_dvd_pow H.2] exact Finset.mem_insert_self p s · exact Finset.mem_insert_of_mem <| hn.2 _ H /-- If `p ∉ s` is a prime and `n` is `s`-factored, then `p` and `n` are coprime. -/ lemma Prime.factoredNumbers_coprime {s : Finset ℕ} {p n : ℕ} (hp : p.Prime) (hs : p ∉ s) (hn : n ∈ factoredNumbers s) : Nat.Coprime p n := by rw [hp.coprime_iff_not_dvd, ← mem_primeFactorsList_iff_dvd hn.1 hp] exact fun H ↦ hs <| hn.2 p H /-- If `f : ℕ → F` is multiplicative on coprime arguments, `p ∉ s` is a prime and `m` is `s`-factored, then `f (p^e * m) = f (p^e) * f m`. -/ lemma factoredNumbers.map_prime_pow_mul {F : Type*} [CommSemiring F] {f : ℕ → F} (hmul : ∀ {m n}, Coprime m n → f (m * n) = f m * f n) {s : Finset ℕ} {p : ℕ} (hp : p.Prime) (hs : p ∉ s) (e : ℕ) {m : factoredNumbers s} : f (p ^ e * m) = f (p ^ e) * f m := hmul <| Coprime.pow_left _ <| hp.factoredNumbers_coprime hs <| Subtype.mem m open List Perm in /-- We establish the bijection from `ℕ × factoredNumbers s` to `factoredNumbers (s ∪ {p})` given by `(e, n) ↦ p^e * n` when `p ∉ s` is a prime. See `Nat.factoredNumbers_insert` for when `p` is not prime. -/ def equivProdNatFactoredNumbers {s : Finset ℕ} {p : ℕ} (hp : p.Prime) (hs : p ∉ s) : ℕ × factoredNumbers s ≃ factoredNumbers (insert p s) where toFun := fun ⟨e, n⟩ ↦ ⟨p ^ e * n, pow_mul_mem_factoredNumbers hp e n.2⟩ invFun := fun ⟨m, _⟩ ↦ (m.factorization p, ⟨(m.primeFactorsList.filter (· ∈ s)).prod, prod_mem_factoredNumbers ..⟩) left_inv := by rintro ⟨e, m, hm₀, hm⟩ simp (config := { etaStruct := .all }) only [Set.coe_setOf, Set.mem_setOf_eq, Prod.mk.injEq, Subtype.mk.injEq] constructor · rw [factorization_mul (pos_iff_ne_zero.mp <| pos_pow_of_pos e hp.pos) hm₀] simp only [factorization_pow, Finsupp.coe_add, Finsupp.coe_smul, nsmul_eq_mul, Pi.natCast_def, cast_id, Pi.add_apply, Pi.mul_apply, hp.factorization_self, mul_one, add_right_eq_self] rw [← primeFactorsList_count_eq, count_eq_zero] exact fun H ↦ hs (hm p H) · nth_rewrite 2 [← prod_primeFactorsList hm₀] refine prod_eq <| (filter _ <| perm_primeFactorsList_mul (pow_ne_zero e hp.ne_zero) hm₀).trans ?_ rw [filter_append, hp.primeFactorsList_pow, filter_eq_nil.mpr fun q hq ↦ by rw [mem_replicate] at hq; simp [hq.2, hs], nil_append, filter_eq_self.mpr fun q hq ↦ by simp only [hm q hq, decide_True]] right_inv := by rintro ⟨m, hm₀, hm⟩ simp only [Set.coe_setOf, Set.mem_setOf_eq, Subtype.mk.injEq] rw [← primeFactorsList_count_eq, ← prod_replicate, ← prod_append] nth_rewrite 3 [← prod_primeFactorsList hm₀] have : m.primeFactorsList.filter (· = p) = m.primeFactorsList.filter (¬ · ∈ s) := by refine (filter_congr fun q hq ↦ ?_).symm simp only [decide_not, Bool.not_eq_true', decide_eq_false_iff_not, decide_eq_true_eq] rcases Finset.mem_insert.mp <| hm _ hq with h | h · simp only [h, hs, decide_False, Bool.not_false, decide_True] · simp only [h, decide_True, Bool.not_true, false_eq_decide_iff] exact fun H ↦ hs <| H ▸ h refine prod_eq <| (filter_eq m.primeFactorsList p).symm ▸ this ▸ perm_append_comm.trans ?_ simp only [decide_not] exact filter_append_perm (· ∈ s) (primeFactorsList m) @[simp] lemma equivProdNatFactoredNumbers_apply {s : Finset ℕ} {p e m : ℕ} (hp : p.Prime) (hs : p ∉ s) (hm : m ∈ factoredNumbers s) : equivProdNatFactoredNumbers hp hs (e, ⟨m, hm⟩) = p ^ e * m := rfl @[simp] lemma equivProdNatFactoredNumbers_apply' {s : Finset ℕ} {p : ℕ} (hp : p.Prime) (hs : p ∉ s) (x : ℕ × factoredNumbers s) : equivProdNatFactoredNumbers hp hs x = p ^ x.1 * x.2 := rfl /-! ### `n`-smooth numbers -/ /-- `smoothNumbers n` is the set of *`n`-smooth positive natural numbers*, i.e., the positive natural numbers all of whose prime factors are less than `n`. -/ def smoothNumbers (n : ℕ) : Set ℕ := {m | m ≠ 0 ∧ ∀ p ∈ primeFactorsList m, p < n} lemma mem_smoothNumbers {n m : ℕ} : m ∈ smoothNumbers n ↔ m ≠ 0 ∧ ∀ p ∈ primeFactorsList m, p < n := Iff.rfl /-- The `n`-smooth numbers agree with the `Finset.range n`-factored numbers. -/ lemma smoothNumbers_eq_factoredNumbers (n : ℕ) : smoothNumbers n = factoredNumbers (Finset.range n) := by simp only [smoothNumbers, ne_eq, mem_primeFactorsList', and_imp, factoredNumbers, Finset.mem_range] /-- The `n`-smooth numbers agree with the `primesBelow n`-factored numbers. -/ lemma smmoothNumbers_eq_factoredNumbers_primesBelow (n : ℕ) : smoothNumbers n = factoredNumbers n.primesBelow := by rw [smoothNumbers_eq_factoredNumbers] refine Set.Subset.antisymm (fun m hm ↦ ?_) <| factoredNumbers_mono Finset.mem_of_mem_filter simp_rw [mem_factoredNumbers'] at hm ⊢ exact fun p hp hp' ↦ mem_primesBelow.mpr ⟨Finset.mem_range.mp <| hm p hp hp', hp⟩ /-- Membership in `Nat.smoothNumbers n` is decidable. -/ instance (n : ℕ) : DecidablePred (· ∈ smoothNumbers n) := inferInstanceAs <| DecidablePred fun x ↦ x ∈ {m | m ≠ 0 ∧ ∀ p ∈ primeFactorsList m, p < n} /-- A number that divides an `n`-smooth number is itself `n`-smooth. -/ lemma mem_smoothNumbers_of_dvd {n m k : ℕ} (h : m ∈ smoothNumbers n) (h' : k ∣ m) : k ∈ smoothNumbers n := by simp only [smoothNumbers_eq_factoredNumbers] at h ⊢ exact mem_factoredNumbers_of_dvd h h' /-- `m` is `n`-smooth if and only if `m` is nonzero and all prime divisors `≤ m` of `m` are less than `n`. -/ lemma mem_smoothNumbers_iff_forall_le {n m : ℕ} : m ∈ smoothNumbers n ↔ m ≠ 0 ∧ ∀ p ≤ m, p.Prime → p ∣ m → p < n := by simp only [smoothNumbers_eq_factoredNumbers, mem_factoredNumbers_iff_forall_le, Finset.mem_range] /-- `m` is `n`-smooth if and only if all prime divisors of `m` are less than `n`. -/ lemma mem_smoothNumbers' {n m : ℕ} : m ∈ smoothNumbers n ↔ ∀ p, p.Prime → p ∣ m → p < n := by simp only [smoothNumbers_eq_factoredNumbers, mem_factoredNumbers', Finset.mem_range] /-- The `Finset` of prime factors of an `n`-smooth number is contained in the `Finset` of primes below `n`. -/ lemma primeFactors_subset_of_mem_smoothNumbers {m n : ℕ} (hms : m ∈ n.smoothNumbers) : m.primeFactors ⊆ n.primesBelow := primeFactors_subset_of_mem_factoredNumbers <| smmoothNumbers_eq_factoredNumbers_primesBelow n ▸ hms /-- `m` is an `n`-smooth number if the `Finset` of its prime factors consists of numbers `< n`. -/ lemma mem_smoothNumbers_of_primeFactors_subset {m n : ℕ} (hm : m ≠ 0) (hp : m.primeFactors ⊆ Finset.range n) : m ∈ n.smoothNumbers := smoothNumbers_eq_factoredNumbers n ▸ mem_factoredNumbers_of_primeFactors_subset hm hp /-- `m` is an `n`-smooth number if and only if `m ≠ 0` and the `Finset` of its prime factors is contained in the `Finset` of primes below `n` -/ lemma mem_smoothNumbers_iff_primeFactors_subset {m n : ℕ} : m ∈ n.smoothNumbers ↔ m ≠ 0 ∧ m.primeFactors ⊆ n.primesBelow := ⟨fun h ↦ ⟨h.1, primeFactors_subset_of_mem_smoothNumbers h⟩, fun h ↦ mem_smoothNumbers_of_primeFactors_subset h.1 <| h.2.trans <| Finset.filter_subset ..⟩ /-- Zero is never a smooth number -/ lemma ne_zero_of_mem_smoothNumbers {n m : ℕ} (h : m ∈ smoothNumbers n) : m ≠ 0 := h.1 @[simp] lemma smoothNumbers_zero : smoothNumbers 0 = {1} := by simp only [smoothNumbers_eq_factoredNumbers, Finset.range_zero, factoredNumbers_empty] /-- The product of two `n`-smooth numbers is an `n`-smooth number. -/ theorem mul_mem_smoothNumbers {m₁ m₂ n : ℕ} (hm1 : m₁ ∈ n.smoothNumbers) (hm2 : m₂ ∈ n.smoothNumbers) : m₁ * m₂ ∈ n.smoothNumbers := by rw [smoothNumbers_eq_factoredNumbers] at hm1 hm2 ⊢ exact mul_mem_factoredNumbers hm1 hm2 /-- The product of the prime factors of `n` that are less than `N` is an `N`-smooth number. -/ lemma prod_mem_smoothNumbers (n N : ℕ) : (n.primeFactorsList.filter (· < N)).prod ∈ smoothNumbers N := by simp only [smoothNumbers_eq_factoredNumbers, ← Finset.mem_range, prod_mem_factoredNumbers] /-- The sets of `N`-smooth and of `(N+1)`-smooth numbers are the same when `N` is not prime. See `Nat.equivProdNatSmoothNumbers` for when `N` is prime. -/ lemma smoothNumbers_succ {N : ℕ} (hN : ¬ N.Prime) : N.succ.smoothNumbers = N.smoothNumbers := by simp only [smoothNumbers_eq_factoredNumbers, Finset.range_succ, factoredNumbers_insert _ hN] @[simp] lemma smoothNumbers_one : smoothNumbers 1 = {1} := by simp (config := { decide := true }) only [not_false_eq_true, smoothNumbers_succ, smoothNumbers_zero] @[gcongr] lemma smoothNumbers_mono {N M : ℕ} (hNM : N ≤ M) : N.smoothNumbers ⊆ M.smoothNumbers := fun _ hx ↦ ⟨hx.1, fun p hp => (hx.2 p hp).trans_le hNM⟩ /-- All `m`, `0 < m < n` are `n`-smooth numbers -/ lemma mem_smoothNumbers_of_lt {m n : ℕ} (hm : 0 < m) (hmn : m < n) : m ∈ n.smoothNumbers := smoothNumbers_eq_factoredNumbers _ ▸ ⟨not_eq_zero_of_lt hm, fun _ h => Finset.mem_range.mpr <| lt_of_le_of_lt (le_of_mem_primeFactorsList h) hmn⟩ /-- The non-zero non-`N`-smooth numbers are `≥ N`. -/ lemma smoothNumbers_compl (N : ℕ) : (N.smoothNumbers)ᶜ \ {0} ⊆ {n | N ≤ n} := by simpa only [smoothNumbers_eq_factoredNumbers] using factoredNumbers_compl <| Finset.filter_subset _ (Finset.range N) /-- If `p` is positive and `n` is `p`-smooth, then every product `p^e * n` is `(p+1)`-smooth. -/ lemma pow_mul_mem_smoothNumbers {p n : ℕ} (hp : p ≠ 0) (e : ℕ) (hn : n ∈ smoothNumbers p) : p ^ e * n ∈ smoothNumbers (succ p) := by -- This cannot be easily reduced to `pow_mul_mem_factoredNumbers`, as there `p.Prime` is needed. have : NoZeroDivisors ℕ := inferInstance -- this is needed twice --> speed-up have hp' := pow_ne_zero e hp refine ⟨mul_ne_zero hp' hn.1, fun q hq ↦ ?_⟩ rcases (mem_primeFactorsList_mul hp' hn.1).mp hq with H | H · rw [mem_primeFactorsList hp'] at H exact lt_succ.mpr <| le_of_dvd hp.bot_lt <| H.1.dvd_of_dvd_pow H.2 · exact (hn.2 q H).trans <| lt_succ_self p /-- If `p` is a prime and `n` is `p`-smooth, then `p` and `n` are coprime. -/ lemma Prime.smoothNumbers_coprime {p n : ℕ} (hp : p.Prime) (hn : n ∈ smoothNumbers p) : Nat.Coprime p n := by simp only [smoothNumbers_eq_factoredNumbers] at hn exact hp.factoredNumbers_coprime Finset.not_mem_range_self hn /-- If `f : ℕ → F` is multiplicative on coprime arguments, `p` is a prime and `m` is `p`-smooth, then `f (p^e * m) = f (p^e) * f m`. -/ lemma map_prime_pow_mul {F : Type*} [CommSemiring F] {f : ℕ → F} (hmul : ∀ {m n}, Nat.Coprime m n → f (m * n) = f m * f n) {p : ℕ} (hp : p.Prime) (e : ℕ) {m : p.smoothNumbers} : f (p ^ e * m) = f (p ^ e) * f m := hmul <| Coprime.pow_left _ <| hp.smoothNumbers_coprime <| Subtype.mem m open List Perm Equiv in /-- We establish the bijection from `ℕ × smoothNumbers p` to `smoothNumbers (p+1)` given by `(e, n) ↦ p^e * n` when `p` is a prime. See `Nat.smoothNumbers_succ` for when `p` is not prime. -/ def equivProdNatSmoothNumbers {p : ℕ} (hp : p.Prime) : ℕ × smoothNumbers p ≃ smoothNumbers p.succ := ((prodCongrRight fun _ ↦ setCongr <| smoothNumbers_eq_factoredNumbers p).trans <| equivProdNatFactoredNumbers hp Finset.not_mem_range_self).trans <| setCongr <| (smoothNumbers_eq_factoredNumbers p.succ) ▸ Finset.range_succ ▸ rfl @[simp] lemma equivProdNatSmoothNumbers_apply {p e m : ℕ} (hp : p.Prime) (hm : m ∈ p.smoothNumbers) : equivProdNatSmoothNumbers hp (e, ⟨m, hm⟩) = p ^ e * m := rfl @[simp] lemma equivProdNatSmoothNumbers_apply' {p : ℕ} (hp : p.Prime) (x : ℕ × p.smoothNumbers) : equivProdNatSmoothNumbers hp x = p ^ x.1 * x.2 := rfl /-! ### Smooth and rough numbers up to a bound We consider the sets of smooth and non-smooth ("rough") positive natural numbers `≤ N` and prove bounds for their sizes. -/ /-- The `k`-smooth numbers up to and including `N` as a `Finset` -/ def smoothNumbersUpTo (N k : ℕ) : Finset ℕ := (Finset.range N.succ).filter (· ∈ smoothNumbers k) lemma mem_smoothNumbersUpTo {N k n : ℕ} : n ∈ smoothNumbersUpTo N k ↔ n ≤ N ∧ n ∈ smoothNumbers k := by simp [smoothNumbersUpTo, lt_succ] /-- The positive non-`k`-smooth (so "`k`-rough") numbers up to and including `N` as a `Finset` -/ def roughNumbersUpTo (N k : ℕ) : Finset ℕ := (Finset.range N.succ).filter (fun n ↦ n ≠ 0 ∧ n ∉ smoothNumbers k) lemma smoothNumbersUpTo_card_add_roughNumbersUpTo_card (N k : ℕ) : (smoothNumbersUpTo N k).card + (roughNumbersUpTo N k).card = N := by rw [smoothNumbersUpTo, roughNumbersUpTo, ← Finset.card_union_of_disjoint <| Finset.disjoint_filter.mpr fun n _ hn₂ h ↦ h.2 hn₂, Finset.filter_union_right] suffices Finset.card (Finset.filter (fun x ↦ x ≠ 0) (Finset.range (succ N))) = N by have hn' (n) : n ∈ smoothNumbers k ∨ n ≠ 0 ∧ n ∉ smoothNumbers k ↔ n ≠ 0 := by have : n ∈ smoothNumbers k → n ≠ 0 := ne_zero_of_mem_smoothNumbers refine ⟨fun H ↦ Or.elim H this fun H ↦ H.1, fun H ↦ ?_⟩ simp only [ne_eq, H, not_false_eq_true, true_and, or_not] rwa [Finset.filter_congr (s := Finset.range (succ N)) fun n _ ↦ hn' n] rw [Finset.filter_ne', Finset.card_erase_of_mem <| Finset.mem_range_succ_iff.mpr <| zero_le N] simp only [Finset.card_range, succ_sub_succ_eq_sub, tsub_zero] /-- A `k`-smooth number can be written as a square times a product of distinct primes `< k`. -/ lemma eq_prod_primes_mul_sq_of_mem_smoothNumbers {n k : ℕ} (h : n ∈ smoothNumbers k) : ∃ s ∈ k.primesBelow.powerset, ∃ m, n = m ^ 2 * (s.prod id) := by obtain ⟨l, m, H₁, H₂⟩ := sq_mul_squarefree n have hl : l ∈ smoothNumbers k := mem_smoothNumbers_of_dvd h (Dvd.intro_left (m ^ 2) H₁) refine ⟨l.primeFactorsList.toFinset, ?_, m, ?_⟩ · simp only [toFinset_factors, Finset.mem_powerset] refine fun p hp ↦ mem_primesBelow.mpr ⟨?_, (mem_primeFactors.mp hp).1⟩ rw [mem_primeFactors] at hp exact mem_smoothNumbers'.mp hl p hp.1 hp.2.1 rw [← H₁] congr simp only [toFinset_factors] exact (prod_primeFactors_of_squarefree H₂).symm /-- The set of `k`-smooth numbers `≤ N` is contained in the set of numbers of the form `m^2 * P`, where `m ≤ √N` and `P` is a product of distinct primes `< k`. -/ lemma smoothNumbersUpTo_subset_image (N k : ℕ) : smoothNumbersUpTo N k ⊆ Finset.image (fun (s, m) ↦ m ^ 2 * (s.prod id)) (k.primesBelow.powerset ×ˢ (Finset.range N.sqrt.succ).erase 0) := by intro n hn obtain ⟨hn₁, hn₂⟩ := mem_smoothNumbersUpTo.mp hn obtain ⟨s, hs, m, hm⟩ := eq_prod_primes_mul_sq_of_mem_smoothNumbers hn₂ simp only [id_eq, Finset.mem_range, zero_lt_succ, not_true_eq_false, Finset.mem_image, Finset.mem_product, Finset.mem_powerset, Finset.mem_erase, Prod.exists] refine ⟨s, m, ⟨Finset.mem_powerset.mp hs, ?_, ?_⟩, hm.symm⟩ · have := hm ▸ ne_zero_of_mem_smoothNumbers hn₂ simp only [ne_eq, _root_.mul_eq_zero, sq_eq_zero_iff, not_or] at this exact this.1 · rw [lt_succ, le_sqrt'] refine LE.le.trans ?_ (hm ▸ hn₁) nth_rw 1 [← mul_one (m ^ 2)] exact mul_le_mul_left' (Finset.one_le_prod' fun p hp ↦ (prime_of_mem_primesBelow <| Finset.mem_powerset.mp hs hp).one_lt.le) _ /-- The cardinality of the set of `k`-smooth numbers `≤ N` is bounded by `2^π(k-1) * √N`. -/ lemma smoothNumbersUpTo_card_le (N k : ℕ) : (smoothNumbersUpTo N k).card ≤ 2 ^ k.primesBelow.card * N.sqrt := by convert (Finset.card_le_card <| smoothNumbersUpTo_subset_image N k).trans <| Finset.card_image_le simp only [Finset.card_product, Finset.card_powerset, Finset.mem_range, zero_lt_succ, Finset.card_erase_of_mem, Finset.card_range, succ_sub_succ_eq_sub, tsub_zero] /-- The set of `k`-rough numbers `≤ N` can be written as the union of the sets of multiples `≤ N` of primes `k ≤ p ≤ N`. -/ lemma roughNumbersUpTo_eq_biUnion (N k) : roughNumbersUpTo N k = (N.succ.primesBelow \ k.primesBelow).biUnion fun p ↦ (Finset.range N.succ).filter (fun m ↦ m ≠ 0 ∧ p ∣ m) := by ext m simp only [roughNumbersUpTo, mem_smoothNumbers_iff_forall_le, not_and, not_forall, not_lt, exists_prop, exists_and_left, Finset.mem_range, not_le, Finset.mem_filter, Finset.filter_congr_decidable, Finset.mem_biUnion, Finset.mem_sdiff, mem_primesBelow, show ∀ P Q : Prop, P ∧ (P → Q) ↔ P ∧ Q by tauto] simp_rw [← exists_and_left, ← not_lt] refine exists_congr fun p ↦ ?_ have H₁ : m ≠ 0 → p ∣ m → m < N.succ → p < N.succ := fun h₁ h₂ h₃ ↦ (le_of_dvd (Nat.pos_of_ne_zero h₁) h₂).trans_lt h₃ have H₂ : m ≠ 0 → p ∣ m → ¬ m < p := fun h₁ h₂ ↦ not_lt.mpr <| le_of_dvd (Nat.pos_of_ne_zero h₁) h₂ constructor · rintro ⟨h₁, h₂, _, h₄, h₅, h₆⟩ exact ⟨⟨⟨H₁ h₂ h₅ h₁, h₄⟩, fun h _ ↦ h₆ h⟩, h₁, h₂, h₅⟩ · rintro ⟨⟨⟨_, h₂⟩, h₃⟩, h₄, h₅, h₆⟩ exact ⟨h₄, h₅, H₂ h₅ h₆, h₂, h₆, fun h ↦ h₃ h h₂⟩ /-- The cardinality of the set of `k`-rough numbers `≤ N` is bounded by the sum of `⌊N/p⌋` over the primes `k ≤ p ≤ N`. -/ lemma roughNumbersUpTo_card_le (N k : ℕ) : (roughNumbersUpTo N k).card ≤ (N.succ.primesBelow \ k.primesBelow).sum (fun p ↦ N / p) := by rw [roughNumbersUpTo_eq_biUnion] exact Finset.card_biUnion_le.trans <| Finset.sum_le_sum fun p _ ↦ (card_multiples' N p).le end Nat
NumberTheory\SumFourSquares.lean
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.Ring.Int import Mathlib.Data.ZMod.Basic import Mathlib.FieldTheory.Finite.Basic import Mathlib.Data.Fintype.BigOperators /-! # Lagrange's four square theorem The main result in this file is `sum_four_squares`, a proof that every natural number is the sum of four square numbers. ## Implementation Notes The proof used is close to Lagrange's original proof. -/ open Finset Polynomial FiniteField Equiv /-- **Euler's four-square identity**. -/ theorem euler_four_squares {R : Type*} [CommRing R] (a b c d x y z w : R) : (a * x - b * y - c * z - d * w) ^ 2 + (a * y + b * x + c * w - d * z) ^ 2 + (a * z - b * w + c * x + d * y) ^ 2 + (a * w + b * z - c * y + d * x) ^ 2 = (a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2) * (x ^ 2 + y ^ 2 + z ^ 2 + w ^ 2) := by ring /-- **Euler's four-square identity**, a version for natural numbers. -/ theorem Nat.euler_four_squares (a b c d x y z w : ℕ) : ((a : ℤ) * x - b * y - c * z - d * w).natAbs ^ 2 + ((a : ℤ) * y + b * x + c * w - d * z).natAbs ^ 2 + ((a : ℤ) * z - b * w + c * x + d * y).natAbs ^ 2 + ((a : ℤ) * w + b * z - c * y + d * x).natAbs ^ 2 = (a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2) * (x ^ 2 + y ^ 2 + z ^ 2 + w ^ 2) := by rw [← Int.natCast_inj] push_cast simp only [sq_abs, _root_.euler_four_squares] namespace Int theorem sq_add_sq_of_two_mul_sq_add_sq {m x y : ℤ} (h : 2 * m = x ^ 2 + y ^ 2) : m = ((x - y) / 2) ^ 2 + ((x + y) / 2) ^ 2 := have : Even (x ^ 2 + y ^ 2) := by simp [← h, even_mul] have hxaddy : Even (x + y) := by simpa [sq, parity_simps] have hxsuby : Even (x - y) := by simpa [sq, parity_simps] mul_right_injective₀ (show (2 * 2 : ℤ) ≠ 0 by decide) <| calc 2 * 2 * m = (x - y) ^ 2 + (x + y) ^ 2 := by rw [mul_assoc, h]; ring _ = (2 * ((x - y) / 2)) ^ 2 + (2 * ((x + y) / 2)) ^ 2 := by rw [even_iff_two_dvd] at hxsuby hxaddy rw [Int.mul_ediv_cancel' hxsuby, Int.mul_ediv_cancel' hxaddy] _ = 2 * 2 * (((x - y) / 2) ^ 2 + ((x + y) / 2) ^ 2) := by set_option simprocs false in simp [mul_add, pow_succ, mul_comm, mul_assoc, mul_left_comm] theorem lt_of_sum_four_squares_eq_mul {a b c d k m : ℕ} (h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = k * m) (ha : 2 * a < m) (hb : 2 * b < m) (hc : 2 * c < m) (hd : 2 * d < m) : k < m := by refine _root_.lt_of_mul_lt_mul_right (_root_.lt_of_mul_lt_mul_left ?_ (zero_le (2 ^ 2))) (zero_le m) calc 2 ^ 2 * (k * ↑m) = ∑ i : Fin 4, (2 * ![a, b, c, d] i) ^ 2 := by simp [← h, Fin.sum_univ_succ, mul_add, mul_pow, add_assoc] _ < ∑ _i : Fin 4, m ^ 2 := Finset.sum_lt_sum_of_nonempty Finset.univ_nonempty fun i _ ↦ by refine pow_lt_pow_left ?_ (zero_le _) two_ne_zero fin_cases i <;> assumption _ = 2 ^ 2 * (m * m) := by simp; ring theorem exists_sq_add_sq_add_one_eq_mul (p : ℕ) [hp : Fact p.Prime] : ∃ (a b k : ℕ), 0 < k ∧ k < p ∧ a ^ 2 + b ^ 2 + 1 = k * p := by rcases hp.1.eq_two_or_odd' with (rfl | hodd) · use 1, 0, 1; simp rcases Nat.sq_add_sq_zmodEq p (-1) with ⟨a, b, ha, hb, hab⟩ rcases Int.modEq_iff_dvd.1 hab.symm with ⟨k, hk⟩ rw [sub_neg_eq_add, mul_comm] at hk have hk₀ : 0 < k := by refine pos_of_mul_pos_left ?_ (Nat.cast_nonneg p) rw [← hk] positivity lift k to ℕ using hk₀.le refine ⟨a, b, k, Nat.cast_pos.1 hk₀, ?_, mod_cast hk⟩ replace hk : a ^ 2 + b ^ 2 + 1 ^ 2 + 0 ^ 2 = k * p := mod_cast hk refine lt_of_sum_four_squares_eq_mul hk ?_ ?_ ?_ ?_ · exact (mul_le_mul' le_rfl ha).trans_lt (Nat.mul_div_lt_iff_not_dvd.2 hodd.not_two_dvd_nat) · exact (mul_le_mul' le_rfl hb).trans_lt (Nat.mul_div_lt_iff_not_dvd.2 hodd.not_two_dvd_nat) · exact lt_of_le_of_ne hp.1.two_le (hodd.ne_two_of_dvd_nat (dvd_refl _)).symm · exact hp.1.pos end Int namespace Nat open Int private theorem sum_four_squares_of_two_mul_sum_four_squares {m a b c d : ℤ} (h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 2 * m) : ∃ w x y z : ℤ, w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 = m := by have : ∀ f : Fin 4 → ZMod 2, f 0 ^ 2 + f 1 ^ 2 + f 2 ^ 2 + f 3 ^ 2 = 0 → ∃ i : Fin 4, f i ^ 2 + f (swap i 0 1) ^ 2 = 0 ∧ f (swap i 0 2) ^ 2 + f (swap i 0 3) ^ 2 = 0 := by decide set f : Fin 4 → ℤ := ![a, b, c, d] obtain ⟨i, hσ⟩ := this (fun x => ↑(f x)) <| by rw [← @zero_mul (ZMod 2) _ m, ← show ((2 : ℤ) : ZMod 2) = 0 from rfl, ← Int.cast_mul, ← h] simp only [Int.cast_add, Int.cast_pow] rfl set σ := swap i 0 obtain ⟨x, hx⟩ : (2 : ℤ) ∣ f (σ 0) ^ 2 + f (σ 1) ^ 2 := (CharP.intCast_eq_zero_iff (ZMod 2) 2 _).1 <| by simpa only [σ, Int.cast_pow, Int.cast_add, Equiv.swap_apply_right, ZMod.pow_card] using hσ.1 obtain ⟨y, hy⟩ : (2 : ℤ) ∣ f (σ 2) ^ 2 + f (σ 3) ^ 2 := (CharP.intCast_eq_zero_iff (ZMod 2) 2 _).1 <| by simpa only [Int.cast_pow, Int.cast_add, ZMod.pow_card] using hσ.2 refine ⟨(f (σ 0) - f (σ 1)) / 2, (f (σ 0) + f (σ 1)) / 2, (f (σ 2) - f (σ 3)) / 2, (f (σ 2) + f (σ 3)) / 2, ?_⟩ rw [← Int.sq_add_sq_of_two_mul_sq_add_sq hx.symm, add_assoc, ← Int.sq_add_sq_of_two_mul_sq_add_sq hy.symm, ← mul_right_inj' two_ne_zero, ← h, mul_add] have : (∑ x, f (σ x) ^ 2) = ∑ x, f x ^ 2 := Equiv.sum_comp σ (f · ^ 2) simpa only [← hx, ← hy, Fin.sum_univ_four, add_assoc] using this /-- Lagrange's **four squares theorem** for a prime number. Use `Nat.sum_four_squares` instead. -/ protected theorem Prime.sum_four_squares {p : ℕ} (hp : p.Prime) : ∃ a b c d : ℕ, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = p := by classical have := Fact.mk hp -- Find `a`, `b`, `c`, `d`, `0 < m < p` such that `a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p` have natAbs_iff {a b c d : ℤ} {k : ℕ} : a.natAbs ^ 2 + b.natAbs ^ 2 + c.natAbs ^ 2 + d.natAbs ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = k := by rw [← @Nat.cast_inj ℤ]; push_cast [sq_abs]; rfl have hm : ∃ m < p, 0 < m ∧ ∃ a b c d : ℕ, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p := by obtain ⟨a, b, k, hk₀, hkp, hk⟩ := exists_sq_add_sq_add_one_eq_mul p refine ⟨k, hkp, hk₀, a, b, 1, 0, ?_⟩ simpa -- Take the minimal possible `m` rcases Nat.findX hm with ⟨m, ⟨hmp, hm₀, a, b, c, d, habcd⟩, hmin⟩ -- If `m = 1`, then we are done rcases (Nat.one_le_iff_ne_zero.2 hm₀.ne').eq_or_gt with rfl | hm₁ · use a, b, c, d; simpa using habcd -- Otherwise, let us find a contradiction exfalso have : NeZero m := ⟨hm₀.ne'⟩ by_cases hm : 2 ∣ m · -- If `m` is an even number, then `(m / 2) * p` can be represented as a sum of four squares rcases hm with ⟨m, rfl⟩ rw [mul_pos_iff_of_pos_left two_pos] at hm₀ have hm₂ : m < 2 * m := by simpa [two_mul] apply_fun (Nat.cast : ℕ → ℤ) at habcd push_cast [mul_assoc] at habcd obtain ⟨_, _, _, _, h⟩ := sum_four_squares_of_two_mul_sum_four_squares habcd exact hmin m hm₂ ⟨hm₂.trans hmp, hm₀, _, _, _, _, natAbs_iff.2 h⟩ · -- For each `x` in `a`, `b`, `c`, `d`, take a number `f x ≡ x [ZMOD m]` with least possible -- absolute value obtain ⟨f, hf_lt, hf_mod⟩ : ∃ f : ℕ → ℤ, (∀ x, 2 * (f x).natAbs < m) ∧ ∀ x, (f x : ZMod m) = x := by refine ⟨fun x ↦ (x : ZMod m).valMinAbs, fun x ↦ ?_, fun x ↦ (x : ZMod m).coe_valMinAbs⟩ exact (mul_le_mul' le_rfl (x : ZMod m).natAbs_valMinAbs_le).trans_lt (Nat.mul_div_lt_iff_not_dvd.2 hm) -- Since `|f x| ^ 2 = (f x) ^ 2 ≡ x ^ 2 [ZMOD m]`, we have -- `m ∣ |f a| ^ 2 + |f b| ^ 2 + |f c| ^ 2 + |f d| ^ 2` obtain ⟨r, hr⟩ : m ∣ (f a).natAbs ^ 2 + (f b).natAbs ^ 2 + (f c).natAbs ^ 2 + (f d).natAbs ^ 2 := by simp only [← Int.natCast_dvd_natCast, ← ZMod.intCast_zmod_eq_zero_iff_dvd] push_cast [hf_mod, sq_abs] norm_cast simp [habcd] -- The quotient `r` is not zero, because otherwise `f a = f b = f c = f d = 0`, hence -- `m` divides each `a`, `b`, `c`, `d`, thus `m ∣ p` which is impossible. rcases (zero_le r).eq_or_gt with rfl | hr₀ · replace hr : f a = 0 ∧ f b = 0 ∧ f c = 0 ∧ f d = 0 := by simpa [and_assoc] using hr obtain ⟨⟨a, rfl⟩, ⟨b, rfl⟩, ⟨c, rfl⟩, ⟨d, rfl⟩⟩ : m ∣ a ∧ m ∣ b ∧ m ∣ c ∧ m ∣ d := by simp only [← ZMod.natCast_zmod_eq_zero_iff_dvd, ← hf_mod, hr, Int.cast_zero, and_self] have : m * m ∣ m * p := habcd ▸ ⟨a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2, by ring⟩ rw [mul_dvd_mul_iff_left hm₀.ne'] at this exact (hp.eq_one_or_self_of_dvd _ this).elim hm₁.ne' hmp.ne -- Since `2 * |f x| < m` for each `x ∈ {a, b, c, d}`, we have `r < m` have hrm : r < m := by rw [mul_comm] at hr apply lt_of_sum_four_squares_eq_mul hr <;> apply hf_lt -- Now it suffices to represent `r * p` as a sum of four squares -- More precisely, we will represent `(m * r) * (m * p)` as a sum of squares of four numbers, -- each of them is divisible by `m` rsuffices ⟨w, x, y, z, hw, hx, hy, hz, h⟩ : ∃ w x y z : ℤ, ↑m ∣ w ∧ ↑m ∣ x ∧ ↑m ∣ y ∧ ↑m ∣ z ∧ w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 = ↑(m * r) * ↑(m * p) · have : (w / m) ^ 2 + (x / m) ^ 2 + (y / m) ^ 2 + (z / m) ^ 2 = ↑(r * p) := by refine mul_left_cancel₀ (pow_ne_zero 2 (Nat.cast_ne_zero.2 hm₀.ne')) ?_ conv_rhs => rw [← Nat.cast_pow, ← Nat.cast_mul, sq m, mul_mul_mul_comm, Nat.cast_mul, ← h] simp only [mul_add, ← mul_pow, Int.mul_ediv_cancel', *] rw [← natAbs_iff] at this exact hmin r hrm ⟨hrm.trans hmp, hr₀, _, _, _, _, this⟩ -- To do the last step, we apply the Euler's four square identity once more replace hr : (f b) ^ 2 + (f a) ^ 2 + (f d) ^ 2 + (-f c) ^ 2 = ↑(m * r) := by rw [← natAbs_iff, natAbs_neg, ← hr] ac_rfl have := congr_arg₂ (· * Nat.cast ·) hr habcd simp only [← _root_.euler_four_squares, Nat.cast_add, Nat.cast_pow] at this refine ⟨_, _, _, _, ?_, ?_, ?_, ?_, this⟩ · simp [← ZMod.intCast_zmod_eq_zero_iff_dvd, hf_mod, mul_comm] · suffices ((a : ZMod m) ^ 2 + (b : ZMod m) ^ 2 + (c : ZMod m) ^ 2 + (d : ZMod m) ^ 2) = 0 by simpa [← ZMod.intCast_zmod_eq_zero_iff_dvd, hf_mod, sq, add_comm, add_assoc, add_left_comm] using this norm_cast simp [habcd] · simp [← ZMod.intCast_zmod_eq_zero_iff_dvd, hf_mod, mul_comm] · simp [← ZMod.intCast_zmod_eq_zero_iff_dvd, hf_mod, mul_comm] /-- **Four squares theorem** -/ theorem sum_four_squares (n : ℕ) : ∃ a b c d : ℕ, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = n := by -- The proof is by induction on prime factorization. The case of prime `n` was proved above, -- the inductive step follows from `Nat.euler_four_squares`. induction n using Nat.recOnMul with | h0 => exact ⟨0, 0, 0, 0, rfl⟩ | h1 => exact ⟨1, 0, 0, 0, rfl⟩ | hp p hp => exact hp.sum_four_squares | h m n hm hn => rcases hm with ⟨a, b, c, d, rfl⟩ rcases hn with ⟨w, x, y, z, rfl⟩ exact ⟨_, _, _, _, euler_four_squares _ _ _ _ _ _ _ _⟩ end Nat
NumberTheory\SumPrimeReciprocals.lean
/- Copyright (c) 2023 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.NumberTheory.SmoothNumbers import Mathlib.Analysis.PSeries /-! # The sum of the reciprocals of the primes diverges We show that the sum of `1/p`, where `p` runs through the prime numbers, diverges. We follow the elementary proof by Erdős that is reproduced in "Proofs from THE BOOK". There are two versions of the main result: `not_summable_one_div_on_primes`, which expresses the sum as a sub-sum of the harmonic series, and `Nat.Primes.not_summable_one_div`, which writes it as a sum over `Nat.Primes`. We also show that the sum of `p^r` for `r : ℝ` converges if and only if `r < -1`; see `Nat.Primes.summable_rpow`. ## References See the sixth proof for the infinity of primes in Chapter 1 of [aigner1999proofs]. The proof is due to Erdős. -/ open Set Nat open scoped Topology /-- The cardinality of the set of `k`-rough numbers `≤ N` is bounded by `N` times the sum of `1/p` over the primes `k ≤ p ≤ N`. -/ -- This needs `Mathlib.Analysis.RCLike.Basic`, so we put it here -- instead of in `Mathlib.NumberTheory.SmoothNumbers`. lemma Nat.roughNumbersUpTo_card_le' (N k : ℕ) : (roughNumbersUpTo N k).card ≤ N * (N.succ.primesBelow \ k.primesBelow).sum (fun p ↦ (1 : ℝ) / p) := by simp_rw [Finset.mul_sum, mul_one_div] exact (Nat.cast_le.mpr <| roughNumbersUpTo_card_le N k).trans <| (cast_sum (β := ℝ) ..) ▸ Finset.sum_le_sum fun n _ ↦ cast_div_le /-- The sum over primes `k ≤ p ≤ 4^(π(k-1)+1)` over `1/p` (as a real number) is at least `1/2`. -/ lemma one_half_le_sum_primes_ge_one_div (k : ℕ) : 1 / 2 ≤ ∑ p ∈ (4 ^ (k.primesBelow.card + 1)).succ.primesBelow \ k.primesBelow, (1 / p : ℝ) := by set m : ℕ := 2 ^ k.primesBelow.card set N₀ : ℕ := 2 * m ^ 2 with hN₀ let S : ℝ := ((2 * N₀).succ.primesBelow \ k.primesBelow).sum (fun p ↦ (1 / p : ℝ)) suffices 1 / 2 ≤ S by convert this using 5 rw [show 4 = 2 ^ 2 by norm_num, pow_right_comm] ring suffices 2 * N₀ ≤ m * (2 * N₀).sqrt + 2 * N₀ * S by rwa [hN₀, ← mul_assoc, ← pow_two 2, ← mul_pow, sqrt_eq', ← sub_le_iff_le_add', cast_mul, cast_mul, cast_pow, cast_two, show (2 * (2 * m ^ 2) - m * (2 * m) : ℝ) = 2 * (2 * m ^ 2) * (1 / 2) by ring, _root_.mul_le_mul_left <| by positivity] at this calc (2 * N₀ : ℝ) _ = ((2 * N₀).smoothNumbersUpTo k).card + ((2 * N₀).roughNumbersUpTo k).card := by exact_mod_cast ((2 * N₀).smoothNumbersUpTo_card_add_roughNumbersUpTo_card k).symm _ ≤ m * (2 * N₀).sqrt + ((2 * N₀).roughNumbersUpTo k).card := by exact_mod_cast Nat.add_le_add_right ((2 * N₀).smoothNumbersUpTo_card_le k) _ _ ≤ m * (2 * N₀).sqrt + 2 * N₀ * S := add_le_add_left ?_ _ exact_mod_cast roughNumbersUpTo_card_le' (2 * N₀) k /-- The sum over the reciprocals of the primes diverges. -/ theorem not_summable_one_div_on_primes : ¬ Summable (indicator {p | p.Prime} (fun n : ℕ ↦ (1 : ℝ) / n)) := by intro h obtain ⟨k, hk⟩ := h.nat_tsum_vanishing (Iio_mem_nhds one_half_pos : Iio (1 / 2 : ℝ) ∈ 𝓝 0) specialize hk ({p | Nat.Prime p} ∩ {p | k ≤ p}) inter_subset_right rw [tsum_subtype, indicator_indicator, inter_eq_left.mpr fun n hn ↦ hn.1, mem_Iio] at hk have h' : Summable (indicator ({p | Nat.Prime p} ∩ {p | k ≤ p}) fun n ↦ (1 : ℝ) / n) := by convert h.indicator {n : ℕ | k ≤ n} using 1 simp only [indicator_indicator, inter_comm] refine ((one_half_le_sum_primes_ge_one_div k).trans_lt <| LE.le.trans_lt ?_ hk).false convert sum_le_tsum (primesBelow ((4 ^ (k.primesBelow.card + 1)).succ) \ primesBelow k) (fun n _ ↦ indicator_nonneg (fun p _ ↦ by positivity) _) h' using 2 with p hp obtain ⟨hp₁, hp₂⟩ := mem_setOf_eq ▸ Finset.mem_sdiff.mp hp have hpp := prime_of_mem_primesBelow hp₁ refine (indicator_of_mem (mem_def.mpr ⟨hpp, ?_⟩) fun n : ℕ ↦ (1 / n : ℝ)).symm exact not_lt.mp <| (not_and_or.mp <| (not_congr mem_primesBelow).mp hp₂).neg_resolve_right hpp /-- The sum over the reciprocals of the primes diverges. -/ theorem Nat.Primes.not_summable_one_div : ¬ Summable (fun p : Nat.Primes ↦ (1 / p : ℝ)) := by convert summable_subtype_iff_indicator.mp.mt not_summable_one_div_on_primes /-- The series over `p^r` for primes `p` converges if and only if `r < -1`. -/ theorem Nat.Primes.summable_rpow {r : ℝ} : Summable (fun p : Nat.Primes ↦ (p : ℝ) ^ r) ↔ r < -1 := by by_cases h : r < -1 · -- case `r < -1` simp only [h, iff_true] exact (Real.summable_nat_rpow.mpr h).subtype _ · -- case `-1 ≤ r` simp only [h, iff_false] refine fun H ↦ Nat.Primes.not_summable_one_div <| H.of_nonneg_of_le (fun _ ↦ by positivity) ?_ intro p rw [one_div, ← Real.rpow_neg_one] exact Real.rpow_le_rpow_of_exponent_le (by exact_mod_cast p.prop.one_lt.le) <| not_lt.mp h
NumberTheory\SumTwoSquares.lean
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Michael Stoll -/ import Mathlib.Data.Nat.Squarefree import Mathlib.NumberTheory.Zsqrtd.QuadraticReciprocity import Mathlib.Tactic.LinearCombination /-! # Sums of two squares Fermat's theorem on the sum of two squares. Every prime `p` congruent to 1 mod 4 is the sum of two squares; see `Nat.Prime.sq_add_sq` (which has the weaker assumption `p % 4 ≠ 3`). We also give the result that characterizes the (positive) natural numbers that are sums of two squares as those numbers `n` such that for every prime `q` congruent to 3 mod 4, the exponent of the largest power of `q` dividing `n` is even; see `Nat.eq_sq_add_sq_iff`. There is an alternative characterization as the numbers of the form `a^2 * b`, where `b` is a natural number such that `-1` is a square modulo `b`; see `Nat.eq_sq_add_sq_iff_eq_sq_mul`. -/ section Fermat open GaussianInt /-- **Fermat's theorem on the sum of two squares**. Every prime not congruent to 3 mod 4 is the sum of two squares. Also known as **Fermat's Christmas theorem**. -/ theorem Nat.Prime.sq_add_sq {p : ℕ} [Fact p.Prime] (hp : p % 4 ≠ 3) : ∃ a b : ℕ, a ^ 2 + b ^ 2 = p := by apply sq_add_sq_of_nat_prime_of_not_irreducible p rwa [_root_.irreducible_iff_prime, prime_iff_mod_four_eq_three_of_nat_prime p] end Fermat /-! ### Generalities on sums of two squares -/ section General /-- The set of sums of two squares is closed under multiplication in any commutative ring. See also `sq_add_sq_mul_sq_add_sq`. -/ theorem sq_add_sq_mul {R} [CommRing R] {a b x y u v : R} (ha : a = x ^ 2 + y ^ 2) (hb : b = u ^ 2 + v ^ 2) : ∃ r s : R, a * b = r ^ 2 + s ^ 2 := ⟨x * u - y * v, x * v + y * u, by rw [ha, hb]; ring⟩ /-- The set of natural numbers that are sums of two squares is closed under multiplication. -/ theorem Nat.sq_add_sq_mul {a b x y u v : ℕ} (ha : a = x ^ 2 + y ^ 2) (hb : b = u ^ 2 + v ^ 2) : ∃ r s : ℕ, a * b = r ^ 2 + s ^ 2 := by zify at ha hb ⊢ obtain ⟨r, s, h⟩ := _root_.sq_add_sq_mul ha hb refine ⟨r.natAbs, s.natAbs, ?_⟩ simpa only [Int.natCast_natAbs, sq_abs] end General /-! ### Results on when -1 is a square modulo a natural number -/ section NegOneSquare -- This could be formulated for a general integer `a` in place of `-1`, -- but it would not directly specialize to `-1`, -- because `((-1 : ℤ) : ZMod n)` is not the same as `(-1 : ZMod n)`. /-- If `-1` is a square modulo `n` and `m` divides `n`, then `-1` is also a square modulo `m`. -/ theorem ZMod.isSquare_neg_one_of_dvd {m n : ℕ} (hd : m ∣ n) (hs : IsSquare (-1 : ZMod n)) : IsSquare (-1 : ZMod m) := by let f : ZMod n →+* ZMod m := ZMod.castHom hd _ rw [← RingHom.map_one f, ← RingHom.map_neg] exact hs.map f /-- If `-1` is a square modulo coprime natural numbers `m` and `n`, then `-1` is also a square modulo `m*n`. -/ theorem ZMod.isSquare_neg_one_mul {m n : ℕ} (hc : m.Coprime n) (hm : IsSquare (-1 : ZMod m)) (hn : IsSquare (-1 : ZMod n)) : IsSquare (-1 : ZMod (m * n)) := by have : IsSquare (-1 : ZMod m × ZMod n) := by rw [show (-1 : ZMod m × ZMod n) = ((-1 : ZMod m), (-1 : ZMod n)) from rfl] obtain ⟨x, hx⟩ := hm obtain ⟨y, hy⟩ := hn rw [hx, hy] exact ⟨(x, y), rfl⟩ simpa only [RingEquiv.map_neg_one] using this.map (ZMod.chineseRemainder hc).symm /-- If a prime `p` divides `n` such that `-1` is a square modulo `n`, then `p % 4 ≠ 3`. -/ theorem Nat.Prime.mod_four_ne_three_of_dvd_isSquare_neg_one {p n : ℕ} (hpp : p.Prime) (hp : p ∣ n) (hs : IsSquare (-1 : ZMod n)) : p % 4 ≠ 3 := by obtain ⟨y, h⟩ := ZMod.isSquare_neg_one_of_dvd hp hs rw [← sq, eq_comm, show (-1 : ZMod p) = -1 ^ 2 by ring] at h haveI : Fact p.Prime := ⟨hpp⟩ exact ZMod.mod_four_ne_three_of_sq_eq_neg_sq' one_ne_zero h /-- If `n` is a squarefree natural number, then `-1` is a square modulo `n` if and only if `n` is not divisible by a prime `q` such that `q % 4 = 3`. -/ theorem ZMod.isSquare_neg_one_iff {n : ℕ} (hn : Squarefree n) : IsSquare (-1 : ZMod n) ↔ ∀ {q : ℕ}, q.Prime → q ∣ n → q % 4 ≠ 3 := by refine ⟨fun H q hqp hqd => hqp.mod_four_ne_three_of_dvd_isSquare_neg_one hqd H, fun H => ?_⟩ induction' n using induction_on_primes with p n hpp ih · exact False.elim (hn.ne_zero rfl) · exact ⟨0, by simp only [mul_zero, eq_iff_true_of_subsingleton]⟩ · haveI : Fact p.Prime := ⟨hpp⟩ have hcp : p.Coprime n := by by_contra hc exact hpp.not_unit (hn p <| mul_dvd_mul_left p <| hpp.dvd_iff_not_coprime.mpr hc) have hp₁ := ZMod.exists_sq_eq_neg_one_iff.mpr (H hpp (dvd_mul_right p n)) exact ZMod.isSquare_neg_one_mul hcp hp₁ (ih hn.of_mul_right fun hqp hqd => H hqp <| dvd_mul_of_dvd_right hqd _) /-- If `n` is a squarefree natural number, then `-1` is a square modulo `n` if and only if `n` has no divisor `q` that is `≡ 3 mod 4`. -/ theorem ZMod.isSquare_neg_one_iff' {n : ℕ} (hn : Squarefree n) : IsSquare (-1 : ZMod n) ↔ ∀ {q : ℕ}, q ∣ n → q % 4 ≠ 3 := by have help : ∀ a b : ZMod 4, a ≠ 3 → b ≠ 3 → a * b ≠ 3 := by decide rw [ZMod.isSquare_neg_one_iff hn] refine ⟨?_, fun H q _ => H⟩ intro H refine @induction_on_primes _ ?_ ?_ (fun p q hp hq hpq => ?_) · exact fun _ => by norm_num · exact fun _ => by norm_num · replace hp := H hp (dvd_of_mul_right_dvd hpq) replace hq := hq (dvd_of_mul_left_dvd hpq) rw [show 3 = 3 % 4 by norm_num, Ne, ← ZMod.natCast_eq_natCast_iff'] at hp hq ⊢ rw [Nat.cast_mul] exact help p q hp hq /-! ### Relation to sums of two squares -/ /-- If `-1` is a square modulo the natural number `n`, then `n` is a sum of two squares. -/ theorem Nat.eq_sq_add_sq_of_isSquare_mod_neg_one {n : ℕ} (h : IsSquare (-1 : ZMod n)) : ∃ x y : ℕ, n = x ^ 2 + y ^ 2 := by induction' n using induction_on_primes with p n hpp ih · exact ⟨0, 0, rfl⟩ · exact ⟨0, 1, rfl⟩ · haveI : Fact p.Prime := ⟨hpp⟩ have hp : IsSquare (-1 : ZMod p) := ZMod.isSquare_neg_one_of_dvd ⟨n, rfl⟩ h obtain ⟨u, v, huv⟩ := Nat.Prime.sq_add_sq (ZMod.exists_sq_eq_neg_one_iff.mp hp) obtain ⟨x, y, hxy⟩ := ih (ZMod.isSquare_neg_one_of_dvd ⟨p, mul_comm _ _⟩ h) exact Nat.sq_add_sq_mul huv.symm hxy /-- If the integer `n` is a sum of two squares of coprime integers, then `-1` is a square modulo `n`. -/ theorem ZMod.isSquare_neg_one_of_eq_sq_add_sq_of_isCoprime {n x y : ℤ} (h : n = x ^ 2 + y ^ 2) (hc : IsCoprime x y) : IsSquare (-1 : ZMod n.natAbs) := by obtain ⟨u, v, huv⟩ : IsCoprime x n := by have hc2 : IsCoprime (x ^ 2) (y ^ 2) := hc.pow rw [show y ^ 2 = n + -1 * x ^ 2 by rw [h]; ring] at hc2 exact (IsCoprime.pow_left_iff zero_lt_two).mp hc2.of_add_mul_right_right have H : u * y * (u * y) - -1 = n * (-v ^ 2 * n + u ^ 2 + 2 * v) := by linear_combination -u ^ 2 * h + (n * v - u * x - 1) * huv refine ⟨u * y, ?_⟩ conv_rhs => tactic => norm_cast rw [(by norm_cast : (-1 : ZMod n.natAbs) = (-1 : ℤ))] exact (ZMod.intCast_eq_intCast_iff_dvd_sub _ _ _).mpr (Int.natAbs_dvd.mpr ⟨_, H⟩) /-- If the natural number `n` is a sum of two squares of coprime natural numbers, then `-1` is a square modulo `n`. -/ theorem ZMod.isSquare_neg_one_of_eq_sq_add_sq_of_coprime {n x y : ℕ} (h : n = x ^ 2 + y ^ 2) (hc : x.Coprime y) : IsSquare (-1 : ZMod n) := by zify at h exact ZMod.isSquare_neg_one_of_eq_sq_add_sq_of_isCoprime h hc.isCoprime /-- A natural number `n` is a sum of two squares if and only if `n = a^2 * b` with natural numbers `a` and `b` such that `-1` is a square modulo `b`. -/ theorem Nat.eq_sq_add_sq_iff_eq_sq_mul {n : ℕ} : (∃ x y : ℕ, n = x ^ 2 + y ^ 2) ↔ ∃ a b : ℕ, n = a ^ 2 * b ∧ IsSquare (-1 : ZMod b) := by constructor · rintro ⟨x, y, h⟩ by_cases hxy : x = 0 ∧ y = 0 · exact ⟨0, 1, by rw [h, hxy.1, hxy.2, zero_pow two_ne_zero, add_zero, zero_mul], ⟨0, by rw [zero_mul, neg_eq_zero, Fin.one_eq_zero_iff]⟩⟩ · have hg := Nat.pos_of_ne_zero (mt Nat.gcd_eq_zero_iff.mp hxy) obtain ⟨g, x₁, y₁, _, h₂, h₃, h₄⟩ := Nat.exists_coprime' hg exact ⟨g, x₁ ^ 2 + y₁ ^ 2, by rw [h, h₃, h₄]; ring, ZMod.isSquare_neg_one_of_eq_sq_add_sq_of_coprime rfl h₂⟩ · rintro ⟨a, b, h₁, h₂⟩ obtain ⟨x', y', h⟩ := Nat.eq_sq_add_sq_of_isSquare_mod_neg_one h₂ exact ⟨a * x', a * y', by rw [h₁, h]; ring⟩ end NegOneSquare /-! ### Characterization in terms of the prime factorization -/ section Main /-- A (positive) natural number `n` is a sum of two squares if and only if the exponent of every prime `q` such that `q % 4 = 3` in the prime factorization of `n` is even. (The assumption `0 < n` is not present, since for `n = 0`, both sides are satisfied; the right hand side holds, since `padicValNat q 0 = 0` by definition.) -/ theorem Nat.eq_sq_add_sq_iff {n : ℕ} : (∃ x y : ℕ, n = x ^ 2 + y ^ 2) ↔ ∀ {q : ℕ}, q.Prime → q % 4 = 3 → Even (padicValNat q n) := by rcases n.eq_zero_or_pos with (rfl | hn₀) · exact ⟨fun _ q _ _ => (@padicValNat.zero q).symm ▸ even_zero, fun _ => ⟨0, 0, rfl⟩⟩ -- now `0 < n` rw [Nat.eq_sq_add_sq_iff_eq_sq_mul] refine ⟨fun H q hq h => ?_, fun H => ?_⟩ · obtain ⟨a, b, h₁, h₂⟩ := H have hqb := padicValNat.eq_zero_of_not_dvd fun hf => (hq.mod_four_ne_three_of_dvd_isSquare_neg_one hf h₂) h have hab : a ^ 2 * b ≠ 0 := h₁ ▸ hn₀.ne' have ha₂ := left_ne_zero_of_mul hab have ha := mt sq_eq_zero_iff.mpr ha₂ have hb := right_ne_zero_of_mul hab haveI hqi : Fact q.Prime := ⟨hq⟩ simp_rw [h₁, padicValNat.mul ha₂ hb, padicValNat.pow 2 ha, hqb, add_zero] exact even_two_mul _ · obtain ⟨b, a, hb₀, ha₀, hab, hb⟩ := Nat.sq_mul_squarefree_of_pos hn₀ refine ⟨a, b, hab.symm, (ZMod.isSquare_neg_one_iff hb).mpr fun {q} hqp hqb hq4 => ?_⟩ refine Nat.odd_iff_not_even.mp ?_ (H hqp hq4) have hqb' : padicValNat q b = 1 := b.factorization_def hqp ▸ le_antisymm (hb.natFactorization_le_one _) ((hqp.dvd_iff_one_le_factorization hb₀.ne').mp hqb) haveI hqi : Fact q.Prime := ⟨hqp⟩ simp_rw [← hab, padicValNat.mul (pow_ne_zero 2 ha₀.ne') hb₀.ne', hqb', padicValNat.pow 2 ha₀.ne'] exact odd_two_mul_add_one _ end Main
NumberTheory\VonMangoldt.lean
/- Copyright (c) 2022 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.Algebra.IsPrimePow import Mathlib.NumberTheory.ArithmeticFunction import Mathlib.Analysis.SpecialFunctions.Log.Basic /-! # The von Mangoldt Function In this file we define the von Mangoldt function: the function on natural numbers that returns `log p` if the input can be expressed as `p^k` for a prime `p`. ## Main Results The main definition for this file is - `ArithmeticFunction.vonMangoldt`: The von Mangoldt function `Λ`. We then prove the classical summation property of the von Mangoldt function in `ArithmeticFunction.vonMangoldt_sum`, that `∑ i ∈ n.divisors, Λ i = Real.log n`, and use this to deduce alternative expressions for the von Mangoldt function via Möbius inversion, see `ArithmeticFunction.sum_moebius_mul_log_eq`. ## Notation We use the standard notation `Λ` to represent the von Mangoldt function. It is accessible in the locales `ArithmeticFunction` (like the notations for other arithmetic functions) and also in the locale `ArithmeticFunction.vonMangoldt`. -/ namespace ArithmeticFunction open Finset Nat open scoped ArithmeticFunction /-- `log` as an arithmetic function `ℕ → ℝ`. Note this is in the `ArithmeticFunction` namespace to indicate that it is bundled as an `ArithmeticFunction` rather than being the usual real logarithm. -/ noncomputable def log : ArithmeticFunction ℝ := ⟨fun n => Real.log n, by simp⟩ @[simp] theorem log_apply {n : ℕ} : log n = Real.log n := rfl /-- The `vonMangoldt` function is the function on natural numbers that returns `log p` if the input can be expressed as `p^k` for a prime `p`. In the case when `n` is a prime power, `min_fac` will give the appropriate prime, as it is the smallest prime factor. In the `ArithmeticFunction` locale, we have the notation `Λ` for this function. This is also available in the `ArithmeticFunction.vonMangoldt` locale, allowing for selective access to the notation. -/ noncomputable def vonMangoldt : ArithmeticFunction ℝ := ⟨fun n => if IsPrimePow n then Real.log (minFac n) else 0, if_neg not_isPrimePow_zero⟩ @[inherit_doc] scoped[ArithmeticFunction] notation "Λ" => ArithmeticFunction.vonMangoldt @[inherit_doc] scoped[ArithmeticFunction.vonMangoldt] notation "Λ" => ArithmeticFunction.vonMangoldt theorem vonMangoldt_apply {n : ℕ} : Λ n = if IsPrimePow n then Real.log (minFac n) else 0 := rfl @[simp] theorem vonMangoldt_apply_one : Λ 1 = 0 := by simp [vonMangoldt_apply] @[simp] theorem vonMangoldt_nonneg {n : ℕ} : 0 ≤ Λ n := by rw [vonMangoldt_apply] split_ifs · exact Real.log_nonneg (one_le_cast.2 (Nat.minFac_pos n)) rfl theorem vonMangoldt_apply_pow {n k : ℕ} (hk : k ≠ 0) : Λ (n ^ k) = Λ n := by simp only [vonMangoldt_apply, isPrimePow_pow_iff hk, pow_minFac hk] theorem vonMangoldt_apply_prime {p : ℕ} (hp : p.Prime) : Λ p = Real.log p := by rw [vonMangoldt_apply, Prime.minFac_eq hp, if_pos hp.prime.isPrimePow] theorem vonMangoldt_ne_zero_iff {n : ℕ} : Λ n ≠ 0 ↔ IsPrimePow n := by rcases eq_or_ne n 1 with (rfl | hn); · simp [not_isPrimePow_one] exact (Real.log_pos (one_lt_cast.2 (minFac_prime hn).one_lt)).ne'.ite_ne_right_iff theorem vonMangoldt_pos_iff {n : ℕ} : 0 < Λ n ↔ IsPrimePow n := vonMangoldt_nonneg.lt_iff_ne.trans (ne_comm.trans vonMangoldt_ne_zero_iff) theorem vonMangoldt_eq_zero_iff {n : ℕ} : Λ n = 0 ↔ ¬IsPrimePow n := vonMangoldt_ne_zero_iff.not_right theorem vonMangoldt_sum {n : ℕ} : ∑ i ∈ n.divisors, Λ i = Real.log n := by refine recOnPrimeCoprime ?_ ?_ ?_ n · simp · intro p k hp rw [sum_divisors_prime_pow hp, cast_pow, Real.log_pow, Finset.sum_range_succ', Nat.pow_zero, vonMangoldt_apply_one] simp [vonMangoldt_apply_pow (Nat.succ_ne_zero _), vonMangoldt_apply_prime hp] intro a b ha' hb' hab ha hb simp only [vonMangoldt_apply, ← sum_filter] at ha hb ⊢ rw [mul_divisors_filter_prime_pow hab, filter_union, sum_union (disjoint_divisors_filter_isPrimePow hab), ha, hb, Nat.cast_mul, Real.log_mul (cast_ne_zero.2 (pos_of_gt ha').ne') (cast_ne_zero.2 (pos_of_gt hb').ne')] @[simp] theorem vonMangoldt_mul_zeta : Λ * ζ = log := by ext n; rw [coe_mul_zeta_apply, vonMangoldt_sum]; rfl @[simp] theorem zeta_mul_vonMangoldt : (ζ : ArithmeticFunction ℝ) * Λ = log := by rw [mul_comm]; simp @[simp] theorem log_mul_moebius_eq_vonMangoldt : log * μ = Λ := by rw [← vonMangoldt_mul_zeta, mul_assoc, coe_zeta_mul_coe_moebius, mul_one] @[simp] theorem moebius_mul_log_eq_vonMangoldt : (μ : ArithmeticFunction ℝ) * log = Λ := by rw [mul_comm]; simp theorem sum_moebius_mul_log_eq {n : ℕ} : (∑ d ∈ n.divisors, (μ d : ℝ) * log d) = -Λ n := by simp only [← log_mul_moebius_eq_vonMangoldt, mul_comm log, mul_apply, log_apply, intCoe_apply, ← Finset.sum_neg_distrib, neg_mul_eq_mul_neg] rw [sum_divisorsAntidiagonal fun i j => (μ i : ℝ) * -Real.log j] have : (∑ i ∈ n.divisors, (μ i : ℝ) * -Real.log (n / i : ℕ)) = ∑ i ∈ n.divisors, ((μ i : ℝ) * Real.log i - μ i * Real.log n) := by apply sum_congr rfl simp only [and_imp, Int.cast_eq_zero, mul_eq_mul_left_iff, Ne, neg_inj, mem_divisors] intro m mn hn have : (m : ℝ) ≠ 0 := by rw [cast_ne_zero] rintro rfl exact hn (by simpa using mn) rw [Nat.cast_div mn this, Real.log_div (cast_ne_zero.2 hn) this, neg_sub, mul_sub] rw [this, sum_sub_distrib, ← sum_mul, ← Int.cast_sum, ← coe_mul_zeta_apply, eq_comm, sub_eq_self, moebius_mul_coe_zeta] rcases eq_or_ne n 1 with (hn | hn) <;> simp [hn] theorem vonMangoldt_le_log : ∀ {n : ℕ}, Λ n ≤ Real.log (n : ℝ) | 0 => by simp | n + 1 => by rw [← vonMangoldt_sum] exact single_le_sum (by exact fun _ _ => vonMangoldt_nonneg) (mem_divisors_self _ n.succ_ne_zero) end ArithmeticFunction
NumberTheory\WellApproximable.lean
/- Copyright (c) 2022 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Dynamics.Ergodic.AddCircle import Mathlib.MeasureTheory.Covering.LiminfLimsup /-! # Well-approximable numbers and Gallagher's ergodic theorem Gallagher's ergodic theorem is a result in metric number theory. It thus belongs to that branch of mathematics concerning arithmetic properties of real numbers which hold almost eveywhere with respect to the Lebesgue measure. Gallagher's theorem concerns the approximation of real numbers by rational numbers. The input is a sequence of distances `δ₁, δ₂, ...`, and the theorem concerns the set of real numbers `x` for which there is an infinity of solutions to: $$ |x - m/n| < δₙ, $$ where the rational number `m/n` is in lowest terms. The result is that for any `δ`, this set is either almost all `x` or almost no `x`. This result was proved by Gallagher in 1959 [P. Gallagher, *Approximation by reduced fractions*](Gallagher1961). It is formalised here as `AddCircle.addWellApproximable_ae_empty_or_univ` except with `x` belonging to the circle `ℝ ⧸ ℤ` since this turns out to be more natural. Given a particular `δ`, the Duffin-Schaeffer conjecture (now a theorem) gives a criterion for deciding which of the two cases in the conclusion of Gallagher's theorem actually occurs. It was proved by Koukoulopoulos and Maynard in 2019 [D. Koukoulopoulos, J. Maynard, *On the Duffin-Schaeffer conjecture*](KoukoulopoulosMaynard2020). We do *not* include a formalisation of the Koukoulopoulos-Maynard result here. ## Main definitions and results: * `approxOrderOf`: in a seminormed group `A`, given `n : ℕ` and `δ : ℝ`, `approxOrderOf A n δ` is the set of elements within a distance `δ` of a point of order `n`. * `wellApproximable`: in a seminormed group `A`, given a sequence of distances `δ₁, δ₂, ...`, `wellApproximable A δ` is the limsup as `n → ∞` of the sets `approxOrderOf A n δₙ`. Thus, it is the set of points that lie in infinitely many of the sets `approxOrderOf A n δₙ`. * `AddCircle.addWellApproximable_ae_empty_or_univ`: *Gallagher's ergodic theorem* says that for the (additive) circle `𝕊`, for any sequence of distances `δ`, the set `addWellApproximable 𝕊 δ` is almost empty or almost full. * `NormedAddCommGroup.exists_norm_nsmul_le`: a general version of Dirichlet's approximation theorem * `AddCircle.exists_norm_nsmul_le`: Dirichlet's approximation theorem ## TODO The hypothesis `hδ` in `AddCircle.addWellApproximable_ae_empty_or_univ` can be dropped. An elementary (non-measure-theoretic) argument shows that if `¬ hδ` holds then `addWellApproximable 𝕊 δ = univ` (provided `δ` is non-negative). Use `AddCircle.exists_norm_nsmul_le` to prove: `addWellApproximable 𝕊 (fun n ↦ 1 / n^2) = { ξ | ¬ IsOfFinAddOrder ξ }` (which is equivalent to `Real.infinite_rat_abs_sub_lt_one_div_den_sq_iff_irrational`). -/ open Set Filter Function Metric MeasureTheory open scoped MeasureTheory Topology Pointwise /-- In a seminormed group `A`, given `n : ℕ` and `δ : ℝ`, `approxOrderOf A n δ` is the set of elements within a distance `δ` of a point of order `n`. -/ @[to_additive "In a seminormed additive group `A`, given `n : ℕ` and `δ : ℝ`, `approxAddOrderOf A n δ` is the set of elements within a distance `δ` of a point of order `n`."] def approxOrderOf (A : Type*) [SeminormedGroup A] (n : ℕ) (δ : ℝ) : Set A := thickening δ {y | orderOf y = n} @[to_additive mem_approx_add_orderOf_iff] theorem mem_approxOrderOf_iff {A : Type*} [SeminormedGroup A] {n : ℕ} {δ : ℝ} {a : A} : a ∈ approxOrderOf A n δ ↔ ∃ b : A, orderOf b = n ∧ a ∈ ball b δ := by simp only [approxOrderOf, thickening_eq_biUnion_ball, mem_iUnion₂, mem_setOf_eq, exists_prop] /-- In a seminormed group `A`, given a sequence of distances `δ₁, δ₂, ...`, `wellApproximable A δ` is the limsup as `n → ∞` of the sets `approxOrderOf A n δₙ`. Thus, it is the set of points that lie in infinitely many of the sets `approxOrderOf A n δₙ`. -/ @[to_additive addWellApproximable "In a seminormed additive group `A`, given a sequence of distances `δ₁, δ₂, ...`, `addWellApproximable A δ` is the limsup as `n → ∞` of the sets `approxAddOrderOf A n δₙ`. Thus, it is the set of points that lie in infinitely many of the sets `approxAddOrderOf A n δₙ`."] def wellApproximable (A : Type*) [SeminormedGroup A] (δ : ℕ → ℝ) : Set A := blimsup (fun n => approxOrderOf A n (δ n)) atTop fun n => 0 < n @[to_additive mem_add_wellApproximable_iff] theorem mem_wellApproximable_iff {A : Type*} [SeminormedGroup A] {δ : ℕ → ℝ} {a : A} : a ∈ wellApproximable A δ ↔ a ∈ blimsup (fun n => approxOrderOf A n (δ n)) atTop fun n => 0 < n := Iff.rfl namespace approxOrderOf variable {A : Type*} [SeminormedCommGroup A] {a : A} {m n : ℕ} (δ : ℝ) @[to_additive] theorem image_pow_subset_of_coprime (hm : 0 < m) (hmn : n.Coprime m) : (fun (y : A) => y ^ m) '' approxOrderOf A n δ ⊆ approxOrderOf A n (m * δ) := by rintro - ⟨a, ha, rfl⟩ obtain ⟨b, hb, hab⟩ := mem_approxOrderOf_iff.mp ha replace hb : b ^ m ∈ {u : A | orderOf u = n} := by rw [← hb] at hmn ⊢; exact hmn.orderOf_pow apply ball_subset_thickening hb ((m : ℝ) • δ) convert pow_mem_ball hm hab using 1 simp only [nsmul_eq_mul, Algebra.id.smul_eq_mul] @[to_additive] theorem image_pow_subset (n : ℕ) (hm : 0 < m) : (fun (y : A) => y ^ m) '' approxOrderOf A (n * m) δ ⊆ approxOrderOf A n (m * δ) := by rintro - ⟨a, ha, rfl⟩ obtain ⟨b, hb : orderOf b = n * m, hab : a ∈ ball b δ⟩ := mem_approxOrderOf_iff.mp ha replace hb : b ^ m ∈ {y : A | orderOf y = n} := by rw [mem_setOf_eq, orderOf_pow' b hm.ne', hb, Nat.gcd_mul_left_left, n.mul_div_cancel hm] apply ball_subset_thickening hb (m * δ) convert pow_mem_ball hm hab using 1 simp only [nsmul_eq_mul] @[to_additive] theorem smul_subset_of_coprime (han : (orderOf a).Coprime n) : a • approxOrderOf A n δ ⊆ approxOrderOf A (orderOf a * n) δ := by simp_rw [approxOrderOf, thickening_eq_biUnion_ball, ← image_smul, image_iUnion₂, image_smul, smul_ball'', smul_eq_mul, mem_setOf_eq] refine iUnion₂_subset_iff.mpr fun b hb c hc => ?_ simp only [mem_iUnion, exists_prop] refine ⟨a * b, ?_, hc⟩ rw [← hb] at han ⊢ exact (Commute.all a b).orderOf_mul_eq_mul_orderOf_of_coprime han @[to_additive vadd_eq_of_mul_dvd] theorem smul_eq_of_mul_dvd (hn : 0 < n) (han : orderOf a ^ 2 ∣ n) : a • approxOrderOf A n δ = approxOrderOf A n δ := by simp_rw [approxOrderOf, thickening_eq_biUnion_ball, ← image_smul, image_iUnion₂, image_smul, smul_ball'', smul_eq_mul, mem_setOf_eq] replace han : ∀ {b : A}, orderOf b = n → orderOf (a * b) = n := by intro b hb rw [← hb] at han hn rw [sq] at han rwa [(Commute.all a b).orderOf_mul_eq_right_of_forall_prime_mul_dvd (orderOf_pos_iff.mp hn) fun p _ hp' => dvd_trans (mul_dvd_mul_right hp' <| orderOf a) han] let f : {b : A | orderOf b = n} → {b : A | orderOf b = n} := fun b => ⟨a * b, han b.property⟩ have hf : Surjective f := by rintro ⟨b, hb⟩ refine ⟨⟨a⁻¹ * b, ?_⟩, ?_⟩ · rw [mem_setOf_eq, ← orderOf_inv, mul_inv_rev, inv_inv, mul_comm] apply han simpa · simp only [f, Subtype.mk_eq_mk, Subtype.coe_mk, mul_inv_cancel_left] simpa only [mem_setOf_eq, Subtype.coe_mk, iUnion_coe_set] using hf.iUnion_comp fun b => ball (b : A) δ end approxOrderOf namespace UnitAddCircle theorem mem_approxAddOrderOf_iff {δ : ℝ} {x : UnitAddCircle} {n : ℕ} (hn : 0 < n) : x ∈ approxAddOrderOf UnitAddCircle n δ ↔ ∃ m < n, gcd m n = 1 ∧ ‖x - ↑((m : ℝ) / n)‖ < δ := by simp only [mem_approx_add_orderOf_iff, mem_setOf_eq, ball, exists_prop, dist_eq_norm, AddCircle.addOrderOf_eq_pos_iff hn, mul_one] constructor · rintro ⟨y, ⟨m, hm₁, hm₂, rfl⟩, hx⟩; exact ⟨m, hm₁, hm₂, hx⟩ · rintro ⟨m, hm₁, hm₂, hx⟩; exact ⟨↑((m : ℝ) / n), ⟨m, hm₁, hm₂, rfl⟩, hx⟩ theorem mem_addWellApproximable_iff (δ : ℕ → ℝ) (x : UnitAddCircle) : x ∈ addWellApproximable UnitAddCircle δ ↔ {n : ℕ | ∃ m < n, gcd m n = 1 ∧ ‖x - ↑((m : ℝ) / n)‖ < δ n}.Infinite := by simp only [mem_add_wellApproximable_iff, ← Nat.cofinite_eq_atTop, cofinite.blimsup_set_eq, mem_setOf_eq] refine iff_of_eq (congr_arg Set.Infinite <| ext fun n => ⟨fun hn => ?_, fun hn => ?_⟩) · exact (mem_approxAddOrderOf_iff hn.1).mp hn.2 · have h : 0 < n := by obtain ⟨m, hm₁, _, _⟩ := hn; exact pos_of_gt hm₁ exact ⟨h, (mem_approxAddOrderOf_iff h).mpr hn⟩ end UnitAddCircle namespace AddCircle variable {T : ℝ} [hT : Fact (0 < T)] local notation a "∤" b => ¬a ∣ b local notation a "∣∣" b => a ∣ b ∧ (a * a)∤b local notation "𝕊" => AddCircle T /-- **Gallagher's ergodic theorem** on Diophantine approximation. -/ theorem addWellApproximable_ae_empty_or_univ (δ : ℕ → ℝ) (hδ : Tendsto δ atTop (𝓝 0)) : (∀ᵐ x, ¬addWellApproximable 𝕊 δ x) ∨ ∀ᵐ x, addWellApproximable 𝕊 δ x := by /- Sketch of proof: Let `E := addWellApproximable 𝕊 δ`. For each prime `p : ℕ`, we can partition `E` into three pieces `E = (A p) ∪ (B p) ∪ (C p)` where: `A p = blimsup (approxAddOrderOf 𝕊 n (δ n)) atTop (fun n => 0 < n ∧ (p ∤ n))` `B p = blimsup (approxAddOrderOf 𝕊 n (δ n)) atTop (fun n => 0 < n ∧ (p ∣∣ n))` `C p = blimsup (approxAddOrderOf 𝕊 n (δ n)) atTop (fun n => 0 < n ∧ (p*p ∣ n))`. In other words, `A p` is the set of points `x` for which there exist infinitely-many `n` such that `x` is within a distance `δ n` of a point of order `n` and `p ∤ n`. Similarly for `B`, `C`. These sets have the following key properties: 1. `A p` is almost invariant under the ergodic map `y ↦ p • y` 2. `B p` is almost invariant under the ergodic map `y ↦ p • y + 1/p` 3. `C p` is invariant under the map `y ↦ y + 1/p` To prove 1 and 2 we need the key result `blimsup_thickening_mul_ae_eq` but 3 is elementary. It follows from `AddCircle.ergodic_nsmul_add` and `Ergodic.ae_empty_or_univ_of_image_ae_le` that if either `A p` or `B p` is not almost empty for any `p`, then it is almost full and thus so is `E`. We may therefore assume that `A p` and `B p` are almost empty for all `p`. We thus have `E` is almost equal to `C p` for every prime. Combining this with 3 we find that `E` is almost invariant under the map `y ↦ y + 1/p` for every prime `p`. The required result then follows from `AddCircle.ae_empty_or_univ_of_forall_vadd_ae_eq_self`. -/ letI : SemilatticeSup Nat.Primes := Nat.Subtype.semilatticeSup _ set μ : Measure 𝕊 := volume set u : Nat.Primes → 𝕊 := fun p => ↑((↑(1 : ℕ) : ℝ) / ((p : ℕ) : ℝ) * T) have hu₀ : ∀ p : Nat.Primes, addOrderOf (u p) = (p : ℕ) := by rintro ⟨p, hp⟩; exact addOrderOf_div_of_gcd_eq_one hp.pos (gcd_one_left p) have hu : Tendsto (addOrderOf ∘ u) atTop atTop := by rw [(funext hu₀ : addOrderOf ∘ u = (↑))] have h_mono : Monotone ((↑) : Nat.Primes → ℕ) := fun p q hpq => hpq refine h_mono.tendsto_atTop_atTop fun n => ?_ obtain ⟨p, hp, hp'⟩ := n.exists_infinite_primes exact ⟨⟨p, hp'⟩, hp⟩ set E := addWellApproximable 𝕊 δ set X : ℕ → Set 𝕊 := fun n => approxAddOrderOf 𝕊 n (δ n) set A : ℕ → Set 𝕊 := fun p => blimsup X atTop fun n => 0 < n ∧ p∤n set B : ℕ → Set 𝕊 := fun p => blimsup X atTop fun n => 0 < n ∧ p∣∣n set C : ℕ → Set 𝕊 := fun p => blimsup X atTop fun n => 0 < n ∧ p ^ 2 ∣ n have hA₀ : ∀ p, MeasurableSet (A p) := fun p => MeasurableSet.measurableSet_blimsup fun n _ => isOpen_thickening.measurableSet have hB₀ : ∀ p, MeasurableSet (B p) := fun p => MeasurableSet.measurableSet_blimsup fun n _ => isOpen_thickening.measurableSet have hE₀ : NullMeasurableSet E μ := by refine (MeasurableSet.measurableSet_blimsup fun n hn => IsOpen.measurableSet ?_).nullMeasurableSet exact isOpen_thickening have hE₁ : ∀ p, E = A p ∪ B p ∪ C p := by intro p simp only [E, A, B, C, addWellApproximable, ← blimsup_or_eq_sup, ← and_or_left, ← sup_eq_union, sq] congr ext n tauto have hE₂ : ∀ p : Nat.Primes, A p =ᵐ[μ] (∅ : Set 𝕊) ∧ B p =ᵐ[μ] (∅ : Set 𝕊) → E =ᵐ[μ] C p := by rintro p ⟨hA, hB⟩ rw [hE₁ p] exact union_ae_eq_right_of_ae_eq_empty ((union_ae_eq_right_of_ae_eq_empty hA).trans hB) have hA : ∀ p : Nat.Primes, A p =ᵐ[μ] (∅ : Set 𝕊) ∨ A p =ᵐ[μ] univ := by rintro ⟨p, hp⟩ let f : 𝕊 → 𝕊 := fun y => (p : ℕ) • y suffices f '' A p ⊆ blimsup (fun n => approxAddOrderOf 𝕊 n (p * δ n)) atTop fun n => 0 < n ∧ p∤n by apply (ergodic_nsmul hp.one_lt).ae_empty_or_univ_of_image_ae_le (hA₀ p) apply (HasSubset.Subset.eventuallyLE this).congr EventuallyEq.rfl exact blimsup_thickening_mul_ae_eq μ (fun n => 0 < n ∧ p∤n) (fun n => {y | addOrderOf y = n}) (Nat.cast_pos.mpr hp.pos) _ hδ refine (sSupHom.setImage f).apply_blimsup_le.trans (mono_blimsup fun n hn => ?_) replace hn := Nat.coprime_comm.mp (hp.coprime_iff_not_dvd.2 hn.2) exact approxAddOrderOf.image_nsmul_subset_of_coprime (δ n) hp.pos hn have hB : ∀ p : Nat.Primes, B p =ᵐ[μ] (∅ : Set 𝕊) ∨ B p =ᵐ[μ] univ := by rintro ⟨p, hp⟩ let x := u ⟨p, hp⟩ let f : 𝕊 → 𝕊 := fun y => p • y + x suffices f '' B p ⊆ blimsup (fun n => approxAddOrderOf 𝕊 n (p * δ n)) atTop fun n => 0 < n ∧ p∣∣n by apply (ergodic_nsmul_add x hp.one_lt).ae_empty_or_univ_of_image_ae_le (hB₀ p) apply (HasSubset.Subset.eventuallyLE this).congr EventuallyEq.rfl exact blimsup_thickening_mul_ae_eq μ (fun n => 0 < n ∧ p∣∣n) (fun n => {y | addOrderOf y = n}) (Nat.cast_pos.mpr hp.pos) _ hδ refine (sSupHom.setImage f).apply_blimsup_le.trans (mono_blimsup ?_) rintro n ⟨hn, h_div, h_ndiv⟩ have h_cop : (addOrderOf x).Coprime (n / p) := by obtain ⟨q, rfl⟩ := h_div rw [hu₀, Subtype.coe_mk, hp.coprime_iff_not_dvd, q.mul_div_cancel_left hp.pos] exact fun contra => h_ndiv (mul_dvd_mul_left p contra) replace h_div : n / p * p = n := Nat.div_mul_cancel h_div have hf : f = (fun y => x + y) ∘ fun y => p • y := by ext; simp [add_comm x] simp_rw [Function.comp_apply, le_eq_subset] rw [sSupHom.setImage_toFun, hf, image_comp] have := @monotone_image 𝕊 𝕊 fun y => x + y specialize this (approxAddOrderOf.image_nsmul_subset (δ n) (n / p) hp.pos) simp only [h_div] at this ⊢ refine this.trans ?_ convert approxAddOrderOf.vadd_subset_of_coprime (p * δ n) h_cop rw [hu₀, Subtype.coe_mk, mul_comm p, h_div] change (∀ᵐ x, x ∉ E) ∨ E ∈ ae volume rw [← eventuallyEq_empty, ← eventuallyEq_univ] have hC : ∀ p : Nat.Primes, u p +ᵥ C p = C p := by intro p let e := (AddAction.toPerm (u p) : Equiv.Perm 𝕊).toOrderIsoSet change e (C p) = C p rw [OrderIso.apply_blimsup e, ← hu₀ p] exact blimsup_congr (eventually_of_forall fun n hn => approxAddOrderOf.vadd_eq_of_mul_dvd (δ n) hn.1 hn.2) by_cases h : ∀ p : Nat.Primes, A p =ᵐ[μ] (∅ : Set 𝕊) ∧ B p =ᵐ[μ] (∅ : Set 𝕊) · replace h : ∀ p : Nat.Primes, (u p +ᵥ E : Set _) =ᵐ[μ] E := by intro p replace hE₂ : E =ᵐ[μ] C p := hE₂ p (h p) have h_qmp : Measure.QuasiMeasurePreserving (-u p +ᵥ ·) μ μ := (measurePreserving_vadd _ μ).quasiMeasurePreserving refine (h_qmp.vadd_ae_eq_of_ae_eq (u p) hE₂).trans (ae_eq_trans ?_ hE₂.symm) rw [hC] exact ae_empty_or_univ_of_forall_vadd_ae_eq_self hE₀ h hu · right simp only [not_forall, not_and_or] at h obtain ⟨p, hp⟩ := h rw [hE₁ p] cases hp · cases' hA p with _ h; · contradiction simp only [h, union_ae_eq_univ_of_ae_eq_univ_left] · cases' hB p with _ h; · contradiction simp only [h, union_ae_eq_univ_of_ae_eq_univ_left, union_ae_eq_univ_of_ae_eq_univ_right] /-- A general version of **Dirichlet's approximation theorem**. See also `AddCircle.exists_norm_nsmul_le`. -/ lemma _root_.NormedAddCommGroup.exists_norm_nsmul_le {A : Type*} [NormedAddCommGroup A] [CompactSpace A] [ConnectedSpace A] [MeasurableSpace A] [BorelSpace A] {μ : Measure A} [μ.IsAddHaarMeasure] (ξ : A) {n : ℕ} (hn : 0 < n) (δ : ℝ) (hδ : μ univ ≤ (n + 1) • μ (closedBall (0 : A) (δ/2))) : ∃ j ∈ Icc 1 n, ‖j • ξ‖ ≤ δ := by have : IsFiniteMeasure μ := CompactSpace.isFiniteMeasure let B : Icc 0 n → Set A := fun j ↦ closedBall ((j : ℕ) • ξ) (δ/2) have hB : ∀ j, IsClosed (B j) := fun j ↦ isClosed_ball suffices ¬ Pairwise (Disjoint on B) by obtain ⟨i, j, hij, x, hx⟩ := exists_lt_mem_inter_of_not_pairwise_disjoint this refine ⟨j - i, ⟨le_tsub_of_add_le_left hij, ?_⟩, ?_⟩ · simpa only [tsub_le_iff_right] using j.property.2.trans le_self_add · rw [sub_nsmul _ (Subtype.coe_le_coe.mpr hij.le), ← sub_eq_add_neg, ← dist_eq_norm] exact (dist_triangle ((j : ℕ) • ξ) x ((i : ℕ) • ξ)).trans (by linarith [mem_closedBall.mp hx.1, mem_closedBall'.mp hx.2]) by_contra h apply hn.ne' have h' : ⋃ j, B j = univ := by rw [← (isClosed_iUnion_of_finite hB).measure_eq_univ_iff_eq (μ := μ)] refine le_antisymm (μ.mono (subset_univ _)) ?_ simp_rw [measure_iUnion h (fun _ ↦ measurableSet_closedBall), tsum_fintype, μ.addHaar_closedBall_center, Finset.sum_const, Finset.card_univ, Nat.card_fintypeIcc, tsub_zero] exact hδ replace hδ : 0 ≤ δ/2 := by by_contra contra suffices μ (closedBall 0 (δ/2)) = 0 by apply isOpen_univ.measure_ne_zero μ univ_nonempty <| le_zero_iff.mp <| le_trans hδ _ simp [this] rw [not_le, ← closedBall_eq_empty (x := (0 : A))] at contra simp [contra] have h'' : ∀ j, (B j).Nonempty := by intro j; rwa [nonempty_closedBall] simpa using subsingleton_of_disjoint_isClosed_iUnion_eq_univ h'' h hB h' /-- **Dirichlet's approximation theorem** See also `Real.exists_rat_abs_sub_le_and_den_le`. -/ lemma exists_norm_nsmul_le (ξ : 𝕊) {n : ℕ} (hn : 0 < n) : ∃ j ∈ Icc 1 n, ‖j • ξ‖ ≤ T / ↑(n + 1) := by apply NormedAddCommGroup.exists_norm_nsmul_le (μ := volume) ξ hn rw [AddCircle.measure_univ, volume_closedBall, ← ENNReal.ofReal_nsmul, mul_div_cancel₀ _ two_ne_zero, min_eq_right (div_le_self hT.out.le <| by simp), nsmul_eq_mul, mul_div_cancel₀ _ (Nat.cast_ne_zero.mpr n.succ_ne_zero)] end AddCircle
NumberTheory\Wilson.lean
/- Copyright (c) 2022 John Nicol. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: John Nicol -/ import Mathlib.FieldTheory.Finite.Basic /-! # Wilson's theorem. This file contains a proof of Wilson's theorem. The heavy lifting is mostly done by the previous `wilsons_lemma`, but here we also prove the other logical direction. This could be generalized to similar results about finite abelian groups. ## References * [Wilson's Theorem](https://en.wikipedia.org/wiki/Wilson%27s_theorem) ## TODO * Give `wilsons_lemma` a descriptive name. -/ open Finset Nat FiniteField ZMod open scoped Nat namespace ZMod variable (p : ℕ) [Fact p.Prime] /-- **Wilson's Lemma**: the product of `1`, ..., `p-1` is `-1` modulo `p`. -/ @[simp] theorem wilsons_lemma : ((p - 1)! : ZMod p) = -1 := by refine calc ((p - 1)! : ZMod p) = ∏ x ∈ Ico 1 (succ (p - 1)), (x : ZMod p) := by rw [← Finset.prod_Ico_id_eq_factorial, prod_natCast] _ = ∏ x : (ZMod p)ˣ, (x : ZMod p) := ?_ _ = -1 := by -- Porting note: `simp` is less powerful. -- simp_rw [← Units.coeHom_apply, ← (Units.coeHom (ZMod p)).map_prod, -- prod_univ_units_id_eq_neg_one, Units.coeHom_apply, Units.val_neg, Units.val_one] simp_rw [← Units.coeHom_apply] rw [← map_prod (Units.coeHom (ZMod p))] simp_rw [prod_univ_units_id_eq_neg_one, Units.coeHom_apply, Units.val_neg, Units.val_one] have hp : 0 < p := (Fact.out (p := p.Prime)).pos symm refine prod_bij (fun a _ => (a : ZMod p).val) ?_ ?_ ?_ ?_ · intro a ha rw [mem_Ico, ← Nat.succ_sub hp, Nat.add_one_sub_one] constructor · apply Nat.pos_of_ne_zero; rw [← @val_zero p] intro h; apply Units.ne_zero a (val_injective p h) · exact val_lt _ · intro _ _ _ _ h; rw [Units.ext_iff]; exact val_injective p h · intro b hb rw [mem_Ico, Nat.succ_le_iff, ← succ_sub hp, Nat.add_one_sub_one, pos_iff_ne_zero] at hb refine ⟨Units.mk0 b ?_, Finset.mem_univ _, ?_⟩ · intro h; apply hb.1; apply_fun val at h simpa only [val_cast_of_lt hb.right, val_zero] using h · simp only [val_cast_of_lt hb.right, Units.val_mk0] · rintro a -; simp only [cast_id, natCast_val] @[simp] theorem prod_Ico_one_prime : ∏ x ∈ Ico 1 p, (x : ZMod p) = -1 := by -- Porting note: was `conv in Ico 1 p =>` conv => congr congr rw [← Nat.add_one_sub_one p, succ_sub (Fact.out (p := p.Prime)).pos] rw [← prod_natCast, Finset.prod_Ico_id_eq_factorial, wilsons_lemma] end ZMod namespace Nat variable {n : ℕ} /-- For `n ≠ 1`, `(n-1)!` is congruent to `-1` modulo `n` only if n is prime. -/ theorem prime_of_fac_equiv_neg_one (h : ((n - 1)! : ZMod n) = -1) (h1 : n ≠ 1) : Prime n := by rcases eq_or_ne n 0 with (rfl | h0) · norm_num at h replace h1 : 1 < n := n.two_le_iff.mpr ⟨h0, h1⟩ by_contra h2 obtain ⟨m, hm1, hm2 : 1 < m, hm3⟩ := exists_dvd_of_not_prime2 h1 h2 have hm : m ∣ (n - 1)! := Nat.dvd_factorial (pos_of_gt hm2) (le_pred_of_lt hm3) refine hm2.ne' (Nat.dvd_one.mp ((Nat.dvd_add_right hm).mp (hm1.trans ?_))) rw [← ZMod.natCast_zmod_eq_zero_iff_dvd, cast_add, cast_one, h, add_left_neg] /-- **Wilson's Theorem**: For `n ≠ 1`, `(n-1)!` is congruent to `-1` modulo `n` iff n is prime. -/ theorem prime_iff_fac_equiv_neg_one (h : n ≠ 1) : Prime n ↔ ((n - 1)! : ZMod n) = -1 := by refine ⟨fun h1 => ?_, fun h2 => prime_of_fac_equiv_neg_one h2 h⟩ haveI := Fact.mk h1 exact ZMod.wilsons_lemma n end Nat assert_not_exists legendre_sym.quadratic_reciprocity
NumberTheory\ZetaValues.lean
/- Copyright (c) 2022 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.NumberTheory.BernoulliPolynomials import Mathlib.MeasureTheory.Integral.IntervalIntegral import Mathlib.Analysis.Calculus.Deriv.Polynomial import Mathlib.Analysis.Fourier.AddCircle import Mathlib.Analysis.PSeries /-! # Critical values of the Riemann zeta function In this file we prove formulae for the critical values of `ζ(s)`, and more generally of Hurwitz zeta functions, in terms of Bernoulli polynomials. ## Main results: * `hasSum_zeta_nat`: the final formula for zeta values, $$\zeta(2k) = \frac{(-1)^{(k + 1)} 2 ^ {2k - 1} \pi^{2k} B_{2 k}}{(2 k)!}.$$ * `hasSum_zeta_two` and `hasSum_zeta_four`: special cases given explicitly. * `hasSum_one_div_nat_pow_mul_cos`: a formula for the sum `∑ (n : ℕ), cos (2 π i n x) / n ^ k` as an explicit multiple of `Bₖ(x)`, for any `x ∈ [0, 1]` and `k ≥ 2` even. * `hasSum_one_div_nat_pow_mul_sin`: a formula for the sum `∑ (n : ℕ), sin (2 π i n x) / n ^ k` as an explicit multiple of `Bₖ(x)`, for any `x ∈ [0, 1]` and `k ≥ 3` odd. -/ noncomputable section open scoped Nat Real Interval open Complex MeasureTheory Set intervalIntegral local notation "𝕌" => UnitAddCircle section BernoulliFunProps /-! Simple properties of the Bernoulli polynomial, as a function `ℝ → ℝ`. -/ /-- The function `x ↦ Bₖ(x) : ℝ → ℝ`. -/ def bernoulliFun (k : ℕ) (x : ℝ) : ℝ := (Polynomial.map (algebraMap ℚ ℝ) (Polynomial.bernoulli k)).eval x theorem bernoulliFun_eval_zero (k : ℕ) : bernoulliFun k 0 = bernoulli k := by rw [bernoulliFun, Polynomial.eval_zero_map, Polynomial.bernoulli_eval_zero, eq_ratCast] theorem bernoulliFun_endpoints_eq_of_ne_one {k : ℕ} (hk : k ≠ 1) : bernoulliFun k 1 = bernoulliFun k 0 := by rw [bernoulliFun_eval_zero, bernoulliFun, Polynomial.eval_one_map, Polynomial.bernoulli_eval_one, bernoulli_eq_bernoulli'_of_ne_one hk, eq_ratCast] theorem bernoulliFun_eval_one (k : ℕ) : bernoulliFun k 1 = bernoulliFun k 0 + ite (k = 1) 1 0 := by rw [bernoulliFun, bernoulliFun_eval_zero, Polynomial.eval_one_map, Polynomial.bernoulli_eval_one] split_ifs with h · rw [h, bernoulli_one, bernoulli'_one, eq_ratCast] push_cast; ring · rw [bernoulli_eq_bernoulli'_of_ne_one h, add_zero, eq_ratCast] theorem hasDerivAt_bernoulliFun (k : ℕ) (x : ℝ) : HasDerivAt (bernoulliFun k) (k * bernoulliFun (k - 1) x) x := by convert ((Polynomial.bernoulli k).map <| algebraMap ℚ ℝ).hasDerivAt x using 1 simp only [bernoulliFun, Polynomial.derivative_map, Polynomial.derivative_bernoulli k, Polynomial.map_mul, Polynomial.map_natCast, Polynomial.eval_mul, Polynomial.eval_natCast] theorem antideriv_bernoulliFun (k : ℕ) (x : ℝ) : HasDerivAt (fun x => bernoulliFun (k + 1) x / (k + 1)) (bernoulliFun k x) x := by convert (hasDerivAt_bernoulliFun (k + 1) x).div_const _ using 1 field_simp [Nat.cast_add_one_ne_zero k] theorem integral_bernoulliFun_eq_zero {k : ℕ} (hk : k ≠ 0) : ∫ x : ℝ in (0)..1, bernoulliFun k x = 0 := by rw [integral_eq_sub_of_hasDerivAt (fun x _ => antideriv_bernoulliFun k x) ((Polynomial.continuous _).intervalIntegrable _ _)] rw [bernoulliFun_eval_one] split_ifs with h · exfalso; exact hk (Nat.succ_inj'.mp h) · simp end BernoulliFunProps section BernoulliFourierCoeffs /-! Compute the Fourier coefficients of the Bernoulli functions via integration by parts. -/ /-- The `n`-th Fourier coefficient of the `k`-th Bernoulli function on the interval `[0, 1]`. -/ def bernoulliFourierCoeff (k : ℕ) (n : ℤ) : ℂ := fourierCoeffOn zero_lt_one (fun x => bernoulliFun k x) n /-- Recurrence relation (in `k`) for the `n`-th Fourier coefficient of `Bₖ`. -/ theorem bernoulliFourierCoeff_recurrence (k : ℕ) {n : ℤ} (hn : n ≠ 0) : bernoulliFourierCoeff k n = 1 / (-2 * π * I * n) * (ite (k = 1) 1 0 - k * bernoulliFourierCoeff (k - 1) n) := by unfold bernoulliFourierCoeff rw [fourierCoeffOn_of_hasDerivAt zero_lt_one hn (fun x _ => (hasDerivAt_bernoulliFun k x).ofReal_comp) ((continuous_ofReal.comp <| continuous_const.mul <| Polynomial.continuous _).intervalIntegrable _ _)] simp_rw [ofReal_one, ofReal_zero, sub_zero, one_mul] rw [QuotientAddGroup.mk_zero, fourier_eval_zero, one_mul, ← ofReal_sub, bernoulliFun_eval_one, add_sub_cancel_left] congr 2 · split_ifs <;> simp only [ofReal_one, ofReal_zero, one_mul] · simp_rw [ofReal_mul, ofReal_natCast, fourierCoeffOn.const_mul] /-- The Fourier coefficients of `B₀(x) = 1`. -/ theorem bernoulli_zero_fourier_coeff {n : ℤ} (hn : n ≠ 0) : bernoulliFourierCoeff 0 n = 0 := by simpa using bernoulliFourierCoeff_recurrence 0 hn /-- The `0`-th Fourier coefficient of `Bₖ(x)`. -/ theorem bernoulliFourierCoeff_zero {k : ℕ} (hk : k ≠ 0) : bernoulliFourierCoeff k 0 = 0 := by simp_rw [bernoulliFourierCoeff, fourierCoeffOn_eq_integral, neg_zero, fourier_zero, sub_zero, div_one, one_smul, intervalIntegral.integral_ofReal, integral_bernoulliFun_eq_zero hk, ofReal_zero] theorem bernoulliFourierCoeff_eq {k : ℕ} (hk : k ≠ 0) (n : ℤ) : bernoulliFourierCoeff k n = -k ! / (2 * π * I * n) ^ k := by rcases eq_or_ne n 0 with (rfl | hn) · rw [bernoulliFourierCoeff_zero hk, Int.cast_zero, mul_zero, zero_pow hk, div_zero] refine Nat.le_induction ?_ (fun k hk h'k => ?_) k (Nat.one_le_iff_ne_zero.mpr hk) · rw [bernoulliFourierCoeff_recurrence 1 hn] simp only [Nat.cast_one, tsub_self, neg_mul, one_mul, eq_self_iff_true, if_true, Nat.factorial_one, pow_one, inv_I, mul_neg] rw [bernoulli_zero_fourier_coeff hn, sub_zero, mul_one, div_neg, neg_div] · rw [bernoulliFourierCoeff_recurrence (k + 1) hn, Nat.add_sub_cancel k 1] split_ifs with h · exfalso; exact (ne_of_gt (Nat.lt_succ_iff.mpr hk)) h · rw [h'k, Nat.factorial_succ, zero_sub, Nat.cast_mul, pow_add, pow_one, neg_div, mul_neg, mul_neg, mul_neg, neg_neg, neg_mul, neg_mul, neg_mul, div_neg] field_simp [Int.cast_ne_zero.mpr hn, I_ne_zero] ring_nf end BernoulliFourierCoeffs section BernoulliPeriodized /-! In this section we use the above evaluations of the Fourier coefficients of Bernoulli polynomials, together with the theorem `has_pointwise_sum_fourier_series_of_summable` from Fourier theory, to obtain an explicit formula for `∑ (n:ℤ), 1 / n ^ k * fourier n x`. -/ /-- The Bernoulli polynomial, extended from `[0, 1)` to the unit circle. -/ def periodizedBernoulli (k : ℕ) : 𝕌 → ℝ := AddCircle.liftIco 1 0 (bernoulliFun k) theorem periodizedBernoulli.continuous {k : ℕ} (hk : k ≠ 1) : Continuous (periodizedBernoulli k) := AddCircle.liftIco_zero_continuous (mod_cast (bernoulliFun_endpoints_eq_of_ne_one hk).symm) (Polynomial.continuous _).continuousOn theorem fourierCoeff_bernoulli_eq {k : ℕ} (hk : k ≠ 0) (n : ℤ) : fourierCoeff ((↑) ∘ periodizedBernoulli k : 𝕌 → ℂ) n = -k ! / (2 * π * I * n) ^ k := by have : ((↑) ∘ periodizedBernoulli k : 𝕌 → ℂ) = AddCircle.liftIco 1 0 ((↑) ∘ bernoulliFun k) := by ext1 x; rfl rw [this, fourierCoeff_liftIco_eq] simpa only [zero_add] using bernoulliFourierCoeff_eq hk n theorem summable_bernoulli_fourier {k : ℕ} (hk : 2 ≤ k) : Summable (fun n => -k ! / (2 * π * I * n) ^ k : ℤ → ℂ) := by have : ∀ n : ℤ, -(k ! : ℂ) / (2 * π * I * n) ^ k = -k ! / (2 * π * I) ^ k * (1 / (n : ℂ) ^ k) := by intro n; rw [mul_one_div, div_div, ← mul_pow] simp_rw [this] refine Summable.mul_left _ <| .of_norm ?_ have : (fun x : ℤ => ‖1 / (x : ℂ) ^ k‖) = fun x : ℤ => |1 / (x : ℝ) ^ k| := by ext1 x rw [norm_eq_abs, ← Complex.abs_ofReal] congr 1 norm_cast simp_rw [this] rwa [summable_abs_iff, Real.summable_one_div_int_pow] theorem hasSum_one_div_pow_mul_fourier_mul_bernoulliFun {k : ℕ} (hk : 2 ≤ k) {x : ℝ} (hx : x ∈ Icc (0 : ℝ) 1) : HasSum (fun n : ℤ => 1 / (n : ℂ) ^ k * fourier n (x : 𝕌)) (-(2 * π * I) ^ k / k ! * bernoulliFun k x) := by -- first show it suffices to prove result for `Ico 0 1` suffices ∀ {y : ℝ}, y ∈ Ico (0 : ℝ) 1 → HasSum (fun (n : ℤ) ↦ 1 / (n : ℂ) ^ k * fourier n y) (-(2 * (π : ℂ) * I) ^ k / k ! * bernoulliFun k y) by rw [← Ico_insert_right (zero_le_one' ℝ), mem_insert_iff, or_comm] at hx rcases hx with (hx | rfl) · exact this hx · convert this (left_mem_Ico.mpr zero_lt_one) using 1 · rw [AddCircle.coe_period, QuotientAddGroup.mk_zero] · rw [bernoulliFun_endpoints_eq_of_ne_one (by omega : k ≠ 1)] intro y hy let B : C(𝕌, ℂ) := ContinuousMap.mk ((↑) ∘ periodizedBernoulli k) (continuous_ofReal.comp (periodizedBernoulli.continuous (by omega))) have step1 : ∀ n : ℤ, fourierCoeff B n = -k ! / (2 * π * I * n) ^ k := by rw [ContinuousMap.coe_mk]; exact fourierCoeff_bernoulli_eq (by omega : k ≠ 0) have step2 := has_pointwise_sum_fourier_series_of_summable ((summable_bernoulli_fourier hk).congr fun n => (step1 n).symm) y simp_rw [step1] at step2 convert step2.mul_left (-(2 * ↑π * I) ^ k / (k ! : ℂ)) using 2 with n · rw [smul_eq_mul, ← mul_assoc, mul_div, mul_neg, div_mul_cancel₀, neg_neg, mul_pow _ (n : ℂ), ← div_div, div_self] · rw [Ne, pow_eq_zero_iff', not_and_or] exact Or.inl two_pi_I_ne_zero · exact Nat.cast_ne_zero.mpr (Nat.factorial_ne_zero _) · rw [ContinuousMap.coe_mk, Function.comp_apply, ofReal_inj, periodizedBernoulli, AddCircle.liftIco_coe_apply (show y ∈ Ico 0 (0 + 1) by rwa [zero_add])] end BernoulliPeriodized section Cleanup -- This section is just reformulating the results in a nicer form. theorem hasSum_one_div_nat_pow_mul_fourier {k : ℕ} (hk : 2 ≤ k) {x : ℝ} (hx : x ∈ Icc (0 : ℝ) 1) : HasSum (fun n : ℕ => (1 : ℂ) / (n : ℂ) ^ k * (fourier n (x : 𝕌) + (-1 : ℂ) ^ k * fourier (-n) (x : 𝕌))) (-(2 * π * I) ^ k / k ! * bernoulliFun k x) := by convert (hasSum_one_div_pow_mul_fourier_mul_bernoulliFun hk hx).nat_add_neg using 1 · ext1 n rw [Int.cast_neg, mul_add, ← mul_assoc] conv_rhs => rw [neg_eq_neg_one_mul, mul_pow, ← div_div] congr 2 rw [div_mul_eq_mul_div₀, one_mul] congr 1 rw [eq_div_iff, ← mul_pow, ← neg_eq_neg_one_mul, neg_neg, one_pow] apply pow_ne_zero; rw [neg_ne_zero]; exact one_ne_zero · rw [Int.cast_zero, zero_pow (by positivity : k ≠ 0), div_zero, zero_mul, add_zero] theorem hasSum_one_div_nat_pow_mul_cos {k : ℕ} (hk : k ≠ 0) {x : ℝ} (hx : x ∈ Icc (0 : ℝ) 1) : HasSum (fun n : ℕ => 1 / (n : ℝ) ^ (2 * k) * Real.cos (2 * π * n * x)) ((-1 : ℝ) ^ (k + 1) * (2 * π) ^ (2 * k) / 2 / (2 * k)! * (Polynomial.map (algebraMap ℚ ℝ) (Polynomial.bernoulli (2 * k))).eval x) := by have : HasSum (fun n : ℕ => 1 / (n : ℂ) ^ (2 * k) * (fourier n (x : 𝕌) + fourier (-n) (x : 𝕌))) ((-1 : ℂ) ^ (k + 1) * (2 * (π : ℂ)) ^ (2 * k) / (2 * k)! * bernoulliFun (2 * k) x) := by convert hasSum_one_div_nat_pow_mul_fourier (by omega : 2 ≤ 2 * k) hx using 3 · rw [pow_mul (-1 : ℂ), neg_one_sq, one_pow, one_mul] · rw [pow_add, pow_one] conv_rhs => rw [mul_pow] congr congr · skip · rw [pow_mul, I_sq] ring have ofReal_two : ((2 : ℝ) : ℂ) = 2 := by norm_cast convert ((hasSum_iff _ _).mp (this.div_const 2)).1 with n · convert (ofReal_re _).symm rw [ofReal_mul]; rw [← mul_div]; congr · rw [ofReal_div, ofReal_one, ofReal_pow]; rfl · rw [ofReal_cos, ofReal_mul, fourier_coe_apply, fourier_coe_apply, cos, ofReal_one, div_one, div_one, ofReal_mul, ofReal_mul, ofReal_two, Int.cast_neg, Int.cast_natCast, ofReal_natCast] congr 3 · ring · ring · convert (ofReal_re _).symm rw [ofReal_mul, ofReal_div, ofReal_div, ofReal_mul, ofReal_pow, ofReal_pow, ofReal_neg, ofReal_natCast, ofReal_mul, ofReal_two, ofReal_one] rw [bernoulliFun] ring theorem hasSum_one_div_nat_pow_mul_sin {k : ℕ} (hk : k ≠ 0) {x : ℝ} (hx : x ∈ Icc (0 : ℝ) 1) : HasSum (fun n : ℕ => 1 / (n : ℝ) ^ (2 * k + 1) * Real.sin (2 * π * n * x)) ((-1 : ℝ) ^ (k + 1) * (2 * π) ^ (2 * k + 1) / 2 / (2 * k + 1)! * (Polynomial.map (algebraMap ℚ ℝ) (Polynomial.bernoulli (2 * k + 1))).eval x) := by have : HasSum (fun n : ℕ => 1 / (n : ℂ) ^ (2 * k + 1) * (fourier n (x : 𝕌) - fourier (-n) (x : 𝕌))) ((-1 : ℂ) ^ (k + 1) * I * (2 * π : ℂ) ^ (2 * k + 1) / (2 * k + 1)! * bernoulliFun (2 * k + 1) x) := by convert hasSum_one_div_nat_pow_mul_fourier (by omega : 2 ≤ 2 * k + 1) hx using 1 · ext1 n rw [pow_add (-1 : ℂ), pow_mul (-1 : ℂ), neg_one_sq, one_pow, one_mul, pow_one, ← neg_eq_neg_one_mul, ← sub_eq_add_neg] · congr rw [pow_add, pow_one] conv_rhs => rw [mul_pow] congr congr · skip · rw [pow_add, pow_one, pow_mul, I_sq] ring have ofReal_two : ((2 : ℝ) : ℂ) = 2 := by norm_cast convert ((hasSum_iff _ _).mp (this.div_const (2 * I))).1 · convert (ofReal_re _).symm rw [ofReal_mul]; rw [← mul_div]; congr · rw [ofReal_div, ofReal_one, ofReal_pow]; rfl · rw [ofReal_sin, ofReal_mul, fourier_coe_apply, fourier_coe_apply, sin, ofReal_one, div_one, div_one, ofReal_mul, ofReal_mul, ofReal_two, Int.cast_neg, Int.cast_natCast, ofReal_natCast, ← div_div, div_I, div_mul_eq_mul_div₀, ← neg_div, ← neg_mul, neg_sub] congr 4 · ring · ring · convert (ofReal_re _).symm rw [ofReal_mul, ofReal_div, ofReal_div, ofReal_mul, ofReal_pow, ofReal_pow, ofReal_neg, ofReal_natCast, ofReal_mul, ofReal_two, ofReal_one, ← div_div, div_I, div_mul_eq_mul_div₀] have : ∀ α β γ δ : ℂ, α * I * β / γ * δ * I = I ^ 2 * α * β / γ * δ := by intros; ring rw [this, I_sq] rw [bernoulliFun] ring theorem hasSum_zeta_nat {k : ℕ} (hk : k ≠ 0) : HasSum (fun n : ℕ => 1 / (n : ℝ) ^ (2 * k)) ((-1 : ℝ) ^ (k + 1) * (2 : ℝ) ^ (2 * k - 1) * π ^ (2 * k) * bernoulli (2 * k) / (2 * k)!) := by convert hasSum_one_div_nat_pow_mul_cos hk (left_mem_Icc.mpr zero_le_one) using 1 · ext1 n; rw [mul_zero, Real.cos_zero, mul_one] rw [Polynomial.eval_zero_map, Polynomial.bernoulli_eval_zero, eq_ratCast] have : (2 : ℝ) ^ (2 * k - 1) = (2 : ℝ) ^ (2 * k) / 2 := by rw [eq_div_iff (two_ne_zero' ℝ)] conv_lhs => congr · skip · rw [← pow_one (2 : ℝ)] rw [← pow_add, Nat.sub_add_cancel] omega rw [this, mul_pow] ring end Cleanup section Examples theorem hasSum_zeta_two : HasSum (fun n : ℕ => (1 : ℝ) / (n : ℝ) ^ 2) (π ^ 2 / 6) := by convert hasSum_zeta_nat one_ne_zero using 1; rw [mul_one] rw [bernoulli_eq_bernoulli'_of_ne_one (by decide : 2 ≠ 1), bernoulli'_two] norm_num [Nat.factorial]; field_simp; ring theorem hasSum_zeta_four : HasSum (fun n : ℕ => (1 : ℝ) / (n : ℝ) ^ 4) (π ^ 4 / 90) := by convert hasSum_zeta_nat two_ne_zero using 1; norm_num rw [bernoulli_eq_bernoulli'_of_ne_one, bernoulli'_four] · norm_num [Nat.factorial]; field_simp; ring · decide theorem Polynomial.bernoulli_three_eval_one_quarter : (Polynomial.bernoulli 3).eval (1 / 4) = 3 / 64 := by simp_rw [Polynomial.bernoulli, Finset.sum_range_succ, Polynomial.eval_add, Polynomial.eval_monomial] rw [Finset.sum_range_zero, Polynomial.eval_zero, zero_add, bernoulli_one] rw [bernoulli_eq_bernoulli'_of_ne_one zero_ne_one, bernoulli'_zero, bernoulli_eq_bernoulli'_of_ne_one (by decide : 2 ≠ 1), bernoulli'_two, bernoulli_eq_bernoulli'_of_ne_one (by decide : 3 ≠ 1), bernoulli'_three] norm_num /-- Explicit formula for `L(χ, 3)`, where `χ` is the unique nontrivial Dirichlet character modulo 4. -/ theorem hasSum_L_function_mod_four_eval_three : HasSum (fun n : ℕ => (1 : ℝ) / (n : ℝ) ^ 3 * Real.sin (π * n / 2)) (π ^ 3 / 32) := by -- Porting note: times out with -- convert hasSum_one_div_nat_pow_mul_sin one_ne_zero (_ : 1 / 4 ∈ Icc (0 : ℝ) 1) apply (congr_arg₂ HasSum ?_ ?_).to_iff.mp <| hasSum_one_div_nat_pow_mul_sin one_ne_zero (?_ : 1 / 4 ∈ Icc (0 : ℝ) 1) · ext1 n norm_num left congr 1 ring · have : (1 / 4 : ℝ) = (algebraMap ℚ ℝ) (1 / 4 : ℚ) := by norm_num rw [this, mul_pow, Polynomial.eval_map, Polynomial.eval₂_at_apply, (by decide : 2 * 1 + 1 = 3), Polynomial.bernoulli_three_eval_one_quarter] norm_num [Nat.factorial]; field_simp; ring · rw [mem_Icc]; constructor · linarith · linarith end Examples
NumberTheory\ClassNumber\AdmissibleAbs.lean
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ 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.mpr (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] apply lt_of_lt_of_le _ (Nat.le_ceil _) rw [Algebra.smul_def, eq_intCast, ← div_div, div_lt_div_right hε, div_lt_iff hb', one_mul, cast_lt] exact Int.emod_lt _ 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
NumberTheory\ClassNumber\AdmissibleAbsoluteValue.lean
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.Data.Real.Basic import Mathlib.Combinatorics.Pigeonhole import Mathlib.Algebra.Order.EuclideanAbsoluteValue /-! # 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 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 • ε -- Porting note: no docstrings for IsAdmissible attribute [nolint docBlame] IsAdmissible.card 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 n ih · intro ε _hε b _hb A refine ⟨0, 1, ?_, ?_⟩ · simp rintro ⟨i, ⟨⟩⟩ 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)) refine ⟨fun i ↦ (Finset.univ.filter fun x ↦ t x = s).toList.get <| i.castLE ?_, fun i j h ↦ ?_, fun i₀ i₁ ↦ ht _ _ ?_⟩ · rwa [Finset.length_toList] · ext simpa [(Finset.nodup_toList _).getElem_inj_iff] using h · #adaptation_note /-- This proof was nicer prior to leanprover/lean4#4400. Please feel welcome to improve it, by avoiding use of `List.get` in favour of `GetElem`. -/ have : ∀ i h, t ((Finset.univ.filter fun x ↦ t x = s).toList.get ⟨i, h⟩) = s := fun i h ↦ (Finset.mem_filter.mp (Finset.mem_toList.mp (List.get_mem _ i h))).2 simp only [Nat.succ_eq_add_one, Finset.length_toList, List.get_eq_getElem] at this simp only [Nat.succ_eq_add_one, List.get_eq_getElem, Fin.coe_castLE] rw [this _ (Nat.lt_of_le_of_lt (Nat.le_of_lt_succ i₁.2) hs), this _ (Nat.lt_of_le_of_lt (Nat.le_of_lt_succ i₀.2) hs)] -- 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
NumberTheory\ClassNumber\AdmissibleCardPowDegree.lean
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ 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 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`. rw [not_le] at hbj 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_le 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 [not_le, 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 · rw [not_lt] at 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. rw [not_le] at le_b 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] refine le_trans ?_ (sub_le_sub_left (Nat.le_ceil _) (b.natDegree : ℝ)) rw [← neg_div] exact le_of_eq (Nat.cast_sub le_b.le) /-- 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 [Int.cast_pow, Int.cast_natCast, 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 n ih · refine ⟨finZeroElim, finZeroElim⟩ -- 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
NumberTheory\ClassNumber\Finite.lean
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ 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 scoped nonZeroDivisors namespace ClassGroup open Ring 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] [iic : IsIntegralClosure S R 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, DMatrix.zero_apply] 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 [Algebra.norm_apply, map_sum, map_smul, map_sum, map_smul, Algebra.toMatrix_lmul_eq, 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*} [LinearOrderedRing 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)] apply (Finset.max'_lt_iff _ (him.image _)).mpr simp only [Finset.mem_image, exists_prop] 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.mpr y'_nonneg) (@Fintype.card_ne_zero _ _ ⟨i⟩) · exact pow_nonneg (Int.cast_nonneg.mpr 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_not_mem : (0 : R) ∉ finsetApprox bS adm := Finset.not_mem_erase _ _ @[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; omega · exact Iff.mpr Int.cast_nonneg this · linarith set μ : Fin (cardM bS adm).succ ↪ R := distinctElems bS adm with hμ 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 _ => ?_ -- Porting note `← hμ, ← r_eq` and the final `← μ_eq` were not needed. rw [← hμ, ← r_eq, ← 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 L] (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 have inj : Function.Injective (algebraMap R L) := by rw [IsScalarTower.algebraMap_eq R S L] exact (IsIntegralClosure.algebraMap_injective S R L).comp bS.algebraMap_injective obtain ⟨a', b', hb', h⟩ := IsIntegralClosure.exists_smul_eq_mul inj 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_not_mem 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 L] (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 _ 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' L 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 (RingHom.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 L] : 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 L 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 L] : 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 L 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 : 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 -- Porting note: `this` and `f` below where solved at the end rather than being defined at first. 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.IsAlgebraic R L := ⟨fun x => (IsFractionRing.isAlgebraic_iff R K L).mpr (Algebra.IsAlgebraic.isAlgebraic x)⟩ exact fintypeOfAdmissibleOfAlgebraic L bS adm end IsAdmissible end EuclideanDomain end ClassGroup
NumberTheory\ClassNumber\FunctionField.lean
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ 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] open scoped Classical namespace RingOfIntegers open FunctionField 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
NumberTheory\Cyclotomic\Basic.lean
/- Copyright (c) 2021 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.Init.Core import Mathlib.RingTheory.Polynomial.Cyclotomic.Roots import Mathlib.NumberTheory.NumberField.Basic import Mathlib.FieldTheory.Galois /-! # 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 `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 `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 ∧ 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 ∧ 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 FiniteDimensional Set universe u v w z variable (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] 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 `n ∈ S` and that `B` is generated over `A` by the roots of `X ^ n - 1`. -/ @[mk_iff] class IsCyclotomicExtension : Prop where /-- For all `n ∈ S`, there exists a primitive `n`-th root of unity in `B`. -/ exists_prim_root {n : ℕ+} (ha : n ∈ S) : ∃ r : B, IsPrimitiveRoot r n /-- The `n`-th roots of unity, for `n ∈ S`, generate `B` as an `A`-algebra. -/ adjoin_roots : ∀ x : B, x ∈ adjoin A {b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1} namespace IsCyclotomicExtension section Basic /-- A reformulation of `IsCyclotomicExtension` that uses `⊤`. -/ theorem iff_adjoin_eq_top : IsCyclotomicExtension S A B ↔ (∀ n : ℕ+, n ∈ S → ∃ r : B, IsPrimitiveRoot r n) ∧ adjoin A {b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1} = ⊤ := ⟨fun h => ⟨fun _ => h.exists_prim_root, 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] /-- If `IsCyclotomicExtension ∅ A B`, then the image of `A` in `B` equals `B`. -/ theorem empty [h : IsCyclotomicExtension ∅ A B] : (⊥ : Subalgebra A B) = ⊤ := by simpa [Algebra.eq_top_iff, isCyclotomicExtension_iff] using h /-- 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 ∅ A B`. -/ theorem singleton_zero_of_bot_eq_top (h : (⊥ : Subalgebra A B) = ⊤) : IsCyclotomicExtension ∅ A B := by -- Porting note: Lean3 is able to infer `A`. refine (iff_adjoin_eq_top _ A _).2 ⟨fun s hs => by simp at hs, _root_.eq_top_iff.2 fun x hx => ?_⟩ rw [← h] at hx simpa using hx 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 => ?_⟩ · cases' hn with hn hn · obtain ⟨b, hb⟩ := ((isCyclotomicExtension_iff _ _ _).1 hS).1 hn refine ⟨algebraMap B C b, ?_⟩ exact hb.map_of_injective h · exact ((isCyclotomicExtension_iff _ _ _).1 hT).1 hn · refine adjoin_induction (((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 ∧ 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, by rw [← h₁, ← map_pow, hn.2, map_one]⟩⟩ @[nontriviality] theorem subsingleton_iff [Subsingleton B] : IsCyclotomicExtension S A B ↔ S = { } ∨ S = {1} := by have : Subsingleton (Subalgebra A B) := inferInstance constructor · rintro ⟨hprim, -⟩ rw [← subset_singleton_iff_eq] intro t ht obtain ⟨ζ, hζ⟩ := hprim ht rw [mem_singleton_iff, ← PNat.coe_eq_one_iff] exact mod_cast hζ.unique (IsPrimitiveRoot.of_subsingleton ζ) · rintro (rfl | rfl) -- Porting note: `R := A` was not needed. · exact ⟨fun h => h.elim, fun x => by convert (mem_top (R := A) : x ∈ ⊤)⟩ · rw [iff_singleton] exact ⟨⟨0, IsPrimitiveRoot.of_subsingleton 0⟩, fun x => by convert (mem_top (R := A) : x ∈ ⊤)⟩ /-- 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 ∧ 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 ∧ b ^ (a : ℕ) = 1}) B := by have : {b : B | ∃ n : ℕ+, n ∈ S ∪ T ∧ b ^ (n : ℕ) = 1} = {b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1} ∪ {b : B | ∃ n : ℕ+, n ∈ T ∧ 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 ∧ 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 ∧ b ^ (a : ℕ) = 1}) := by refine ⟨@fun n hn => ?_, fun b => ?_⟩ · obtain ⟨b, hb⟩ := ((isCyclotomicExtension_iff _ _ _).1 h).1 (hS hn) refine ⟨⟨b, subset_adjoin ⟨n, 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 `∀ s ∈ S, n ∣ s` and `S` is not empty, then `IsCyclotomicExtension S A B` implies `IsCyclotomicExtension (S ∪ {n}) A B`. -/ theorem of_union_of_dvd (h : ∀ s ∈ S, n ∣ s) (hS : S.Nonempty) [H : IsCyclotomicExtension S A B] : IsCyclotomicExtension (S ∪ {n}) A B := by refine (iff_adjoin_eq_top _ A _).2 ⟨fun s hs => ?_, ?_⟩ · rw [mem_union, mem_singleton_iff] at hs obtain hs | rfl := hs · exact H.exists_prim_root hs · obtain ⟨m, hm⟩ := hS obtain ⟨x, rfl⟩ := h m hm obtain ⟨ζ, hζ⟩ := H.exists_prim_root hm refine ⟨ζ ^ (x : ℕ), ?_⟩ convert hζ.pow_of_dvd x.ne_zero (dvd_mul_left (x : ℕ) s) simp only [PNat.mul_coe, Nat.mul_div_left, PNat.pos] · 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⟩ := hx exact ⟨m, ⟨Or.inr hm.1, hm.2⟩⟩ /-- If `∀ s ∈ S, n ∣ s` and `S` is not empty, then `IsCyclotomicExtension S A B` if and only if `IsCyclotomicExtension (S ∪ {n}) A B`. -/ theorem iff_union_of_dvd (h : ∀ s ∈ S, n ∣ s) (hS : S.Nonempty) : IsCyclotomicExtension S A B ↔ IsCyclotomicExtension (S ∪ {n}) A B := by refine ⟨fun H => of_union_of_dvd A B h hS, fun H => (iff_adjoin_eq_top _ A _).2 ⟨fun s hs => ?_, ?_⟩⟩ · exact H.exists_prim_root (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⟩ := hS refine ⟨y, ⟨hy, ?_⟩⟩ obtain ⟨z, rfl⟩ := h y hy simp only [PNat.mul_coe, 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 obtain hS | rfl := S.eq_empty_or_nonempty.symm · exact iff_union_of_dvd _ _ (fun s _ => one_dvd _) hS rw [empty_union] refine ⟨fun H => ?_, fun H => ?_⟩ · refine (iff_adjoin_eq_top _ A _).2 ⟨fun s hs => ⟨1, by simp [mem_singleton_iff.1 hs]⟩, ?_⟩ simp [adjoin_singleton_one, empty] · refine (iff_adjoin_eq_top _ A _).2 ⟨fun s hs => (not_mem_empty s hs).elim, ?_⟩ simp [@singleton_one A B _ _ _ H] 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 (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) protected theorem neZero [h : IsCyclotomicExtension {n} A B] [IsDomain B] : NeZero ((n : ℕ) : B) := by obtain ⟨⟨r, hr⟩, -⟩ := (iff_singleton n A B).1 h exact hr.neZero' protected theorem neZero' [IsCyclotomicExtension {n} A B] [IsDomain B] : NeZero ((n : ℕ) : A) := by haveI := IsCyclotomicExtension.neZero n A B exact NeZero.nat_of_neZero (algebraMap A B) 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 hb => ?_ · simp only [mem_singleton_iff, exists_eq_left] have : {b : B | b ^ (n : ℕ) = 1} = (nthRoots n (1 : B)).toFinset := Set.ext fun x => ⟨fun h => by simpa using h, fun h => by simpa using h⟩ rw [this] exact (nthRoots (↑n) 1).toFinset.finite_toSet · simp only [mem_singleton_iff, exists_eq_left, mem_setOf_eq] at hb exact ⟨X ^ (n : ℕ) - 1, ⟨monic_X_pow_sub_C _ n.pos.ne.symm, by simp [hb]⟩⟩ /-- 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 cases' nonempty_fintype S with h revert h₂ A B refine Set.Finite.induction_on h₁ (fun A B => ?_) @fun n S _ _ H A B => ?_ · intro _ _ _ _ _ refine Module.finite_def.2 ⟨({1} : Finset B), ?_⟩ simp [← top_toSubmodule, ← empty, toSubmodule_bot, Submodule.one_eq_span] · intro _ _ _ _ h haveI : IsCyclotomicExtension S A (adjoin A {b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1}) := union_left _ (insert n S) _ _ (subset_insert n S) haveI := H A (adjoin A {b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1}) have : Module.Finite (adjoin A {b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1}) B := by rw [← union_singleton] at h letI := @union_right S {n} A B _ _ _ h exact finite_of_singleton n _ _ exact Module.Finite.trans (adjoin A {b : B | ∃ n : ℕ+, n ∈ S ∧ 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 _ } /-- A finite cyclotomic extension of an integral noetherian domain is integral -/ theorem integral [IsDomain B] [IsNoetherianRing A] [Finite S] [IsCyclotomicExtension S A B] : Algebra.IsIntegral A B := have := IsCyclotomicExtension.finite S A B ⟨isIntegral_of_noetherian inferInstance⟩ /-- 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 : ℕ+} (hζ : IsPrimitiveRoot ζ n) : adjoin A ((cyclotomic n A).rootSet B) = adjoin A {b : B | ∃ a : ℕ+, a ∈ ({n} : Set ℕ+) ∧ b ^ (a : ℕ) = 1} := by simp only [mem_singleton_iff, exists_eq_left, map_cyclotomic] refine le_antisymm (adjoin_mono fun x hx => ?_) (adjoin_le fun x hx => ?_) · rw [mem_rootSet'] at hx simp only [mem_singleton_iff, exists_eq_left, mem_setOf_eq] rw [isRoot_of_unity_iff n.pos] refine ⟨n, Nat.mem_divisors_self n n.ne_zero, ?_⟩ rw [IsRoot.def, ← map_cyclotomic n (algebraMap A B), eval_map, ← aeval_def] exact hx.2 · simp only [mem_singleton_iff, exists_eq_left, mem_setOf_eq] at hx obtain ⟨i, _, rfl⟩ := hζ.eq_pow_of_pow_eq_one hx n.pos 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 n.pos⟩ theorem adjoin_roots_cyclotomic_eq_adjoin_root_cyclotomic {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 = 1 by obtain ⟨i, _, rfl⟩ := hζ.eq_pow_of_pow_eq_one hx n.pos exact SetLike.mem_coe.2 (Subalgebra.pow_mem _ (subset_adjoin <| mem_singleton ζ) _) refine (isRoot_of_unity_iff n.pos B).2 ?_ refine ⟨n, Nat.mem_divisors_self n n.ne_zero, ?_⟩ rw [mem_rootSet', aeval_def, ← eval_map, map_cyclotomic, ← IsRoot] at hx exact hx.2 · simp only [mem_singleton_iff, exists_eq_left, mem_setOf_eq] 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 n.pos) theorem adjoin_primitive_root_eq_top {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 : ℕ+} (h : IsPrimitiveRoot ζ n) : IsCyclotomicExtension {n} A (adjoin A ({ζ} : Set B)) := { exists_prim_root := fun 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 => by refine adjoin_induction' (x := x) (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 ((IsPrimitiveRoot.iff_def ζ n).1 h).1 · exact Subalgebra.algebraMap_mem _ _ · exact Subalgebra.add_mem _ hb₁ hb₂ · exact Subalgebra.mul_mem _ hb₁ hb₂ } 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 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 n.pos _) (splits_X_pow_sub_one K L hS) ?_ use ∏ i ∈ (n : ℕ).properDivisors, Polynomial.cyclotomic i K rw [(eq_cyclotomic_iff n.pos _).1 rfl, RingHom.map_one] variable (n S) 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 [Polynomial.map_pow, mem_singleton_iff, Multiset.mem_toFinset, exists_eq_left, mem_setOf_eq, Polynomial.map_X, Polynomial.map_one, Finset.mem_coe, Polynomial.map_sub] 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 n.pos (1 : L) } /-- Any two `n`-th cyclotomic extensions are isomorphic. -/ def algEquiv (L' : Type*) [Field L'] [Algebra K L'] [IsCyclotomicExtension {n} K L'] : L ≃ₐ[K] L' := let h₁ := isSplittingField_X_pow_sub_one n K L let h₂ := isSplittingField_X_pow_sub_one n K L' (@IsSplittingField.algEquiv K L _ _ _ (X ^ (n : ℕ) - 1) h₁).trans (@IsSplittingField.algEquiv K L' _ _ _ (X ^ (n : ℕ) - 1) h₂).symm scoped[Cyclotomic] attribute [instance] IsCyclotomicExtension.isSplittingField_X_pow_sub_one theorem isGalois : IsGalois K L := letI := isSplittingField_X_pow_sub_one n K L IsGalois.of_separable_splitting_field (X_pow_sub_one_separable_iff.2 (IsCyclotomicExtension.neZero' n K L).1) /-- 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 -- todo: make `exists_prim_root` take an explicit `L` obtain ⟨ζ : L, hζ⟩ := IsCyclotomicExtension.exists_prim_root K (B := L) (mem_singleton n) 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 `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 -- Porting note: could not be derived instance : Field (CyclotomicField n K) := by delta CyclotomicField; infer_instance -- Porting note: could not be derived instance algebra : Algebra K (CyclotomicField n K) := by delta CyclotomicField; infer_instance -- Porting note: could not be derived 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 haveI : 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 n.pos).ne' rw [← eval_map, ← IsRoot.def, map_cyclotomic, isRoot_cyclotomic_iff] at hζ -- Porting note: the first `?_` was `forall_eq.2 ⟨ζ, hζ⟩` that now fails. refine ⟨?_, ?_⟩ · simp only [mem_singleton_iff, forall_eq] exact ⟨ζ, hζ⟩ · rw [← Algebra.eq_top_iff, ← SplittingField.adjoin_rootSet, eq_comm] exact IsCyclotomicExtension.adjoin_roots_cyclotomic_eq_adjoin_nth_roots hζ end CyclotomicField end CyclotomicField section IsDomain variable [Algebra A K] [IsFractionRing A K] section CyclotomicRing /-- If `K` is the fraction field of `A`, the `A`-algebra structure on `CyclotomicField n K`. -/ @[nolint unusedArguments] instance CyclotomicField.algebraBase : Algebra A (CyclotomicField n K) := SplittingField.algebra' (cyclotomic n K) /-- Ensure there are no diamonds when `A = ℤ` but there are `reducible_and_instances` #10906 -/ example : Ring.toIntAlgebra (CyclotomicField n ℚ) = CyclotomicField.algebraBase _ _ _ := rfl instance CyclotomicField.algebra' {R : Type*} [CommRing R] [Algebra R K] : Algebra R (CyclotomicField n K) := SplittingField.algebra' (cyclotomic n K) instance {R : Type*} [CommRing R] [Algebra R K] : IsScalarTower R K (CyclotomicField n K) := SplittingField.isScalarTower _ instance CyclotomicField.noZeroSMulDivisors : NoZeroSMulDivisors A (CyclotomicField n K) := by refine NoZeroSMulDivisors.of_algebraMap_injective ?_ rw [IsScalarTower.algebraMap_eq A K (CyclotomicField n K)] exact (Function.Injective.comp (NoZeroSMulDivisors.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} --deriving CommRing, IsDomain, Inhabited namespace CyclotomicRing -- Porting note: could not be derived instance : CommRing (CyclotomicRing n A K) := by delta CyclotomicRing; infer_instance -- Porting note: could not be derived instance : IsDomain (CyclotomicRing n A K) := by delta CyclotomicRing; infer_instance -- Porting note: could not be derived 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` #10906 example {n : ℕ+} : CyclotomicRing.algebraBase n ℤ ℚ = Ring.toIntAlgebra _ := rfl instance : NoZeroSMulDivisors A (CyclotomicRing n A K) := (adjoin A _).noZeroSMulDivisors_bot theorem algebraBase_injective : Function.Injective <| algebraMap A (CyclotomicRing n A K) := NoZeroSMulDivisors.algebraMap_injective _ _ instance : Algebra (CyclotomicRing n A K) (CyclotomicField n K) := (adjoin A _).toAlgebra 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.of_algebraMap_injective (adjoin_algebra_injective n A K) instance : IsScalarTower A (CyclotomicRing n A K) (CyclotomicField n K) := IsScalarTower.subalgebra' _ _ _ _ instance isCyclotomicExtension [NeZero ((n : ℕ) : A)] : IsCyclotomicExtension {n} A (CyclotomicRing n A K) where exists_prim_root := @fun a han => by rw [mem_singleton_iff] at han subst a haveI := NeZero.of_noZeroSMulDivisors A K n haveI := NeZero.of_noZeroSMulDivisors A (CyclotomicField n K) n obtain ⟨μ, hμ⟩ := (CyclotomicField.isCyclotomicExtension n K).exists_prim_root (mem_singleton n) refine ⟨⟨μ, subset_adjoin ?_⟩, ?_⟩ · apply (isRoot_of_unity_iff n.pos (CyclotomicField n K)).mpr refine ⟨n, Nat.mem_divisors_self _ n.ne_zero, ?_⟩ rwa [← isRoot_cyclotomic_iff] at hμ · rwa [← IsPrimitiveRoot.coe_submonoidClass_iff, Subtype.coe_mk] adjoin_roots x := by refine adjoin_induction' (fun y hy => ?_) (fun a => ?_) (fun y z hy hz => ?_) (fun y z hy hz => ?_) x · refine subset_adjoin ?_ simp only [mem_singleton_iff, exists_eq_left, mem_setOf_eq] 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 [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 letI : NeZero ((n : ℕ) : K) := NeZero.nat_of_injective (IsFractionRing.injective A K) refine Algebra.adjoin_induction (((IsCyclotomicExtension.iff_singleton n K (CyclotomicField n K)).1 (CyclotomicField.isCyclotomicExtension n K)).2 x) (fun y hy => ?_) (fun k => ?_) ?_ ?_ -- Porting note: the last goal was `by simpa` that now fails. · 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] end CyclotomicRing end CyclotomicRing end IsDomain section IsAlgClosed variable [IsAlgClosed K] /-- Algebraically closed fields are `S`-cyclotomic extensions over themselves if `NeZero ((a : ℕ) : K))` for all `a ∈ S`. -/ theorem IsAlgClosed.isCyclotomicExtension (h : ∀ a ∈ S, NeZero ((a : ℕ) : K)) : IsCyclotomicExtension S K K := by refine ⟨@fun a ha => ?_, Algebra.eq_top_iff.mp <| Subsingleton.elim _ _⟩ obtain ⟨r, hr⟩ := IsAlgClosed.exists_aeval_eq_zero K _ (degree_cyclotomic_pos a K a.pos).ne' refine ⟨r, ?_⟩ haveI := h a ha rwa [coe_aeval_eq_eval, ← IsRoot.def, isRoot_cyclotomic_iff] at hr instance IsAlgClosedOfCharZero.isCyclotomicExtension [CharZero K] : ∀ S, IsCyclotomicExtension S K K := fun S => IsAlgClosed.isCyclotomicExtension S K fun _ _ => inferInstance end IsAlgClosed
NumberTheory\Cyclotomic\CyclotomicCharacter.lean
/- Copyright (c) 2023 Hanneke Wiersema. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Hanneke Wiersema -/ import Mathlib.RingTheory.RootsOfUnity.Basic /-! # 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`. ## 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`. * Define the cyclotomic character. * Prove that it's continuous. ## Tags cyclotomic character -/ universe u variable {L : Type u} [CommRing L] [IsDomain L] /- ## The mod n theory -/ variable (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 : ℕ+) : ℤ := (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 : ℕ+) : ∀ t : rootsOfUnity n L, g (t : Lˣ) = (t ^ (ModularCyclotomicCharacter_aux g n) : Lˣ) := (rootsOfUnity.integer_power_of_ringEquiv n g).choose_spec /-- 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 : ℕ+) (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 : ℕ+} (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 theorem toFun_spec' (g : L ≃+* L) {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 : ℕ+} {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 rfl (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, SubmonoidClass.coe_pow, 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 : ℕ+) : (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 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 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 : ℕ+} (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 : ℕ+} (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 : ℕ+) (R : Type*) [CommRing R] [Algebra R L] {μ : L} (hμ : IsPrimitiveRoot μ n) (g : L ≃ₐ[R] L) : 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 [autToPow_spec R hμ g, ModularCyclotomicCharacter', ModularCyclotomicCharacter, ZMod.ringEquivCongr_val] using ModularCyclotomicCharacter.toFun_spec'' g hμ
NumberTheory\Cyclotomic\Discriminant.lean
/- Copyright (c) 2022 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.NumberTheory.Cyclotomic.PrimitiveRoots import Mathlib.NumberTheory.NumberField.Discriminant /-! # 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 : ℕ+} {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 n.pos · refine minpoly.isIntegrallyClosed_eq_field_fractions' (K := ℚ) (hζ.isIntegral n.pos) · exact (hζ.isIntegral n.pos).sub isIntegral_one · refine minpoly.isIntegrallyClosed_eq_field_fractions' (K := ℚ) ?_ exact (hζ.isIntegral n.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] set_option tactic.skipAssignedInstances false in /-- 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 -- Porting note: these two instances are not automatically synthesised and must be constructed haveI mf : Module.Finite K L := finiteDimensional {p ^ (k + 1)} K L haveI se : Algebra.IsSeparable K L := (isGalois (p ^ (k + 1)) K L).to_isSeparable rw [discr_powerBasis_eq_norm, finrank L hirr, hζ.powerBasis_gen _, ← hζ.minpoly_eq_cyclotomic_of_irreducible hirr, PNat.pow_coe, totient_prime_pow hp.out (succ_pos k), Nat.add_one_sub_one] have coe_two : ((2 : ℕ+) : ℕ) = 2 := rfl 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 [coe_two, 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] · replace hp2 : (p : ℕ) ≠ 2 := by rwa [Ne, ← coe_two, PNat.coe_inj] 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, ← PNat.pow_coe, 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, _root_.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] at H conv_rhs at H => -- Porting note: need to drill down to successfully rewrite the totient enter [1, 2] rw [PNat.pow_coe, ← succ_eq_add_one, totient_prime_pow hp.out (succ_pos k), Nat.sub_one, Nat.pred_succ] rw [← hζ.minpoly_eq_cyclotomic_of_irreducible hirr, map_pow, hζ.norm_eq_one hk hirr, one_pow, mul_one, PNat.pow_coe, 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 · -- Porting note: was `replace h := pow_eq_zero h; rw [coe_coe] at h; simpa using hne.1` have := hne.1 rw [PNat.pow_coe, Nat.cast_pow, Ne, pow_eq_zero_iff (by omega)] at this exact absurd (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 set_option tactic.skipAssignedInstances false in /-- 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 cases' k with k k · simp only [coe_basis, _root_.pow_zero, powerBasis_gen _ hζ, totient_one, mul_zero, mul_one, 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 [traceMatrix, map_one, one_pow, Matrix.det_unique, traceForm_apply, mul_one] rw [← (algebraMap K L).map_one, trace_algebraMap, finrank _ hirr] norm_num · by_cases hk : p ^ (k + 1) = 2 · have coe_two : 2 = ((2 : ℕ+) : ℕ) := rfl have hp : p = 2 := by rw [← PNat.coe_inj, PNat.pow_coe, ← pow_one 2] at hk replace hk := eq_of_prime_pow_eq (prime_iff.1 hp.out) (prime_iff.1 Nat.prime_two) (succ_pos _) hk rwa [coe_two, PNat.coe_inj] at hk subst hp rw [← PNat.coe_inj, PNat.pow_coe] at hk nth_rw 2 [← pow_one 2] at hk replace hk := Nat.pow_right_injective rfl.le hk rw [add_left_eq_self] 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 _ (NoZeroSMulDivisors.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 ext i simp only [map_neg, map_one, Function.comp_apply, Fin.coe_fin_one, _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]; norm_num · exact discr_prime_pow_ne_two hζ hirr hk set_option tactic.skipAssignedInstances false in /-- 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]; norm_num⟩ · exact ⟨-1, (p : ℕ) ^ (k - 1) * ((p - 1) * k - 1), by rw [(odd_iff_not_even.2 heven).neg_one_pow]; norm_num⟩ /-- 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
NumberTheory\Cyclotomic\Embeddings.lean
/- Copyright (c) 2024 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.NumberTheory.Cyclotomic.PrimitiveRoots import Mathlib.NumberTheory.NumberField.Embeddings /-! # Cyclotomic extensions of `ℚ` are totally complex number fields. We prove that cyclotomic extensions of `ℚ` are totally complex, meaning that `NrRealPlaces K = 0` if `IsCyclotomicExtension {n} ℚ K` and `2 < n`. ## Main results * `nrRealPlaces_eq_zero`: If `K` is a `n`-th cyclotomic extension of `ℚ`, where `2 < n`, then there are no real places of `K`. -/ universe u namespace IsCyclotomicExtension.Rat open NumberField InfinitePlace FiniteDimensional Complex Nat Polynomial variable {n : ℕ+} (K : Type u) [Field K] [CharZero K] /-- If `K` is a `n`-th cyclotomic extension of `ℚ`, where `2 < n`, then there are no real places of `K`. -/ theorem nrRealPlaces_eq_zero [IsCyclotomicExtension {n} ℚ K] (hn : 2 < n) : haveI := IsCyclotomicExtension.numberField {n} ℚ K NrRealPlaces K = 0 := by have := IsCyclotomicExtension.numberField {n} ℚ K apply (IsCyclotomicExtension.zeta_spec n ℚ K).nrRealPlaces_eq_zero_of_two_lt hn variable (n) /-- If `K` is a `n`-th cyclotomic extension of `ℚ`, then there are `φ n / n` complex places of `K`. Note that this uses `1 / 2 = 0` in the cases `n = 1, 2`. -/ theorem nrComplexPlaces_eq_totient_div_two [h : IsCyclotomicExtension {n} ℚ K] : haveI := IsCyclotomicExtension.numberField {n} ℚ K NrComplexPlaces K = φ n / 2 := by have := IsCyclotomicExtension.numberField {n} ℚ K by_cases hn : 2 < n · obtain ⟨k, hk : φ n = k + k⟩ := totient_even hn have key := card_add_two_mul_card_eq_rank K rw [nrRealPlaces_eq_zero K hn, zero_add, IsCyclotomicExtension.finrank (n := n) K (cyclotomic.irreducible_rat n.pos), hk, ← two_mul, Nat.mul_right_inj (by norm_num)] at key simp [hk, key, ← two_mul] · have : φ n = 1 := by by_cases h1 : 1 < n.1 · convert totient_two exact (eq_of_le_of_not_lt (succ_le_of_lt h1) hn).symm · convert totient_one rw [← PNat.one_coe, PNat.coe_inj] exact eq_of_le_of_not_lt (not_lt.mp h1) (PNat.not_lt_one _) rw [this] apply nrComplexPlaces_eq_zero_of_finrank_eq_one rw [IsCyclotomicExtension.finrank K (cyclotomic.irreducible_rat n.pos), this] end IsCyclotomicExtension.Rat
NumberTheory\Cyclotomic\Gal.lean
/- Copyright (c) 2022 Eric Rodriguez. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Rodriguez -/ 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 : ℕ+} (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.eq_iff_modEq_nat] 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 rw [hμ.eq_orderOf] -- Porting note: was `{occs := occurrences.pos [2]}` conv_rhs => rw [← hμ.val_toRootsOfUnity_coe] rw [orderOf_units, Subgroup.orderOf_coe] end IsPrimitiveRoot namespace IsCyclotomicExtension variable [CommRing L] [IsDomain L] (hμ : IsPrimitiveRoot μ n) [Algebra K L] [IsCyclotomicExtension {n} K L] /-- Cyclotomic extensions are abelian. -/ noncomputable def Aut.commGroup : CommGroup (L ≃ₐ[K] L) := ((zeta_spec n K L).autToPow_injective K).commGroup _ (map_one _) (map_mul _) (map_inv _) (map_div _) (map_pow _) (map_zpow _) variable (h : Irreducible (cyclotomic n K)) {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 : (L ≃ₐ[K] L) ≃* (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 -- Porting note: the proof is slightly different because of coercions. 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 -- Porting note: was `rw ← hζ.coe_to_roots_of_unity_coe at key {occs := occurrences.pos [1, 5]}`. conv at key => congr; congr rw [← hζ.val_toRootsOfUnity_coe] rfl; rfl rw [← hζ.val_toRootsOfUnity_coe] 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.eq_iff_modEq_nat] at key simp only [ZMod.natCast_val, ZMod.cast_id', id] at key exact Units.ext key } variable {L} /-- Maps `μ` to the `AlgEquiv` that sends `IsCyclotomicExtension.zeta` to `μ`. -/ noncomputable def fromZetaAut : L ≃ₐ[K] L := let hζ := (zeta_spec n K L).eq_pow_of_pow_eq_one hμ.pow_eq_one n.pos (autEquivPow L h).symm <| ZMod.unitOfCoprime hζ.choose <| ((zeta_spec n K L).pow_iff_coprime n.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] (hμ : IsPrimitiveRoot μ n) [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
NumberTheory\Cyclotomic\PID.lean
/- Copyright (c) 2024 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.NumberTheory.NumberField.ClassNumber import Mathlib.NumberTheory.Cyclotomic.Rat import Mathlib.NumberTheory.Cyclotomic.Embeddings /-! # Cyclotomic fields whose ring of integers is a PID. We prove that `ℤ [ζₚ]` is a PID for specific values of `p`. The result holds for `p ≤ 19`, but the proof is more and more involved. ## Main results * `three_pid`: If `IsCyclotomicExtension {3} ℚ K` then `𝓞 K` is a principal ideal domain. * `five_pid`: If `IsCyclotomicExtension {5} ℚ K` then `𝓞 K` is a principal ideal domain. -/ universe u namespace IsCyclotomicExtension.Rat open NumberField Polynomial InfinitePlace Nat Real cyclotomic variable (K : Type u) [Field K] [NumberField K] /-- If `IsCyclotomicExtension {3} ℚ K` then `𝓞 K` is a principal ideal domain. -/ theorem three_pid [IsCyclotomicExtension {3} ℚ K] : IsPrincipalIdealRing (𝓞 K) := by apply RingOfIntegers.isPrincipalIdealRing_of_abs_discr_lt rw [absdiscr_prime 3 K, IsCyclotomicExtension.finrank (n := 3) K (irreducible_rat (by norm_num)), nrComplexPlaces_eq_totient_div_two 3, totient_prime PNat.prime_three] simp only [Int.reduceNeg, PNat.val_ofNat, succ_sub_succ_eq_sub, tsub_zero, zero_lt_two, Nat.div_self, pow_one, cast_ofNat, neg_mul, one_mul, abs_neg, Int.cast_abs, Int.cast_ofNat, factorial_two, gt_iff_lt, abs_of_pos (show (0 : ℝ) < 3 by norm_num)] suffices (2 * (3 / 4) * (2 ^ 2 / 2)) ^ 2 < (2 * (π / 4) * (2 ^ 2 / 2)) ^ 2 from lt_trans (by norm_num) this gcongr exact pi_gt_three /-- If `IsCyclotomicExtension {5} ℚ K` then `𝓞 K` is a principal ideal domain. -/ theorem five_pid [IsCyclotomicExtension {5} ℚ K] : IsPrincipalIdealRing (𝓞 K) := by apply RingOfIntegers.isPrincipalIdealRing_of_abs_discr_lt rw [absdiscr_prime 5 K, IsCyclotomicExtension.finrank (n := 5) K (irreducible_rat (by norm_num)), nrComplexPlaces_eq_totient_div_two 5, totient_prime PNat.prime_five] simp only [Int.reduceNeg, PNat.val_ofNat, succ_sub_succ_eq_sub, tsub_zero, reduceDiv, even_two, Even.neg_pow, one_pow, cast_ofNat, Int.reducePow, one_mul, Int.cast_abs, Int.cast_ofNat, div_pow, gt_iff_lt, show 4! = 24 by rfl, abs_of_pos (show (0 : ℝ) < 125 by norm_num)] suffices (2 * (3 ^ 2 / 4 ^ 2) * (4 ^ 4 / 24)) ^ 2 < (2 * (π ^ 2 / 4 ^ 2) * (4 ^ 4 / 24)) ^ 2 from lt_trans (by norm_num) this gcongr exact pi_gt_three end IsCyclotomicExtension.Rat
NumberTheory\Cyclotomic\PrimitiveRoots.lean
/- Copyright (c) 2022 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alex Best, Riccardo Brasca, Eric Rodriguez -/ import Mathlib.Data.PNat.Prime import Mathlib.Algebra.IsPrimePow import Mathlib.NumberTheory.Cyclotomic.Basic import Mathlib.RingTheory.Adjoin.PowerBasis import Mathlib.RingTheory.Polynomial.Cyclotomic.Eval import Mathlib.RingTheory.Norm.Basic import Mathlib.RingTheory.Polynomial.Cyclotomic.Expand /-! # 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 FiniteDimensional IsCyclotomicExtension Nat PNat Set open scoped IntermediateField universe u v w z variable {p 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_prim_root A <| Set.mem_singleton n : ∃ 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 := Classical.choose_spec (exists_prim_root A (Set.mem_singleton n) : ∃ r : B, IsPrimitiveRoot r n) 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 := PowerBasis.map (Algebra.adjoin.powerBasis <| (integral {n} K L).isIntegral ζ) <| (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 := (hζ.powerBasis K).ofGenMemAdjoin (((integral {n} K L).isIntegral ζ).sub isIntegral_one) (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_noZeroSMulDivisors K C n refine ⟨x.1, ?_⟩ cases x rwa [mem_primitiveRoots n.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_noZeroSMulDivisors 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 n.pos] left_inv := fun x => Subtype.ext rfl right_inv := fun x => Subtype.ext rfl } -- 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 ≤ FiniteDimensional.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 [NumberField K] [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) n.2) rw [IsCyclotomicExtension.finrank K (cyclotomic.irreducible_rat n.2)] 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 n.2)).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, PNat.ne_zero, or_false] at hr exact hl.1 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 [NumberField K] [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, Nat.odd_iff_not_even.1 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 (by simp) 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 [NumberField K] [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 _ n.2, ?_⟩ 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} (hζ : IsPrimitiveRoot ζ n) 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] /-- 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_coe, one_right_iff] at hζ rw [hζ, show 1 = algebraMap K L 1 by simp, Algebra.norm_algebraMap, one_pow] · replace h1 : 2 ≤ n := by by_contra! h exact h1 (PNat.eq_one_of_lt_two h) -- Porting note: specyfing the type of `cyclotomic_coeff_zero K h1` was not needed. 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 : coeff (cyclotomic n K) 0 = 1), 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 /-- 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*} [LinearOrderedField 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 convert norm_eq_neg_one_pow (K := K) hζ erw [IsCyclotomicExtension.finrank _ hirr, totient_two, pow_one] · exact hζ.norm_eq_one hn hirr end CommRing section Field variable [Field L] {ζ : L} (hζ : IsPrimitiveRoot ζ n) variable {K} [Field K] [Algebra K L] /-- 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 n.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, 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 haveI : NeZero ((n : ℕ) : E) := NeZero.of_noZeroSMulDivisors 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 := (coe_lt_coe 2 _).1 (lt_of_le_of_ne (succ_le_of_lt (IsPrimePow.one_lt hn)) (Function.Injective.ne PNat.coe_injective h).symm) letI 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, sub_one_norm_eq_eval_cyclotomic hζ this hirr] 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 ((integral {n} K A).isIntegral ζ), 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 -- Porting note: `by simp` was `by linarith` that now fails. have hirr₁ : Irreducible (cyclotomic ((p : ℕ) ^ (k - s + 1)) K) := cyclotomic_irreducible_pow_of_irreducible_pow hpri.1 (by simp) hirr rw [← PNat.pow_coe] at 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 (p ^ (k + 1)).pos hζ ?_ rw [PNat.pow_coe, ← 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 suffices IsCyclotomicExtension {p ^ (k - s + 1)} K K⟮η + 1⟯.toSubalgebra by have H : K⟮η + 1⟯.toSubalgebra = K⟮η⟯.toSubalgebra := by simp only [IntermediateField.adjoin_simple_toSubalgebra_of_integral ((integral {p ^ (k + 1)} K L).isIntegral _)] refine Subalgebra.ext fun x => ⟨fun hx => adjoin_le ?_ hx, fun hx => adjoin_le ?_ hx⟩ · simp only [Set.singleton_subset_iff, SetLike.mem_coe] exact Subalgebra.add_mem _ (subset_adjoin (mem_singleton η)) (Subalgebra.one_mem _) · simp only [Set.singleton_subset_iff, SetLike.mem_coe] nth_rw 1 [← add_sub_cancel_right η 1] exact Subalgebra.sub_mem _ (subset_adjoin (mem_singleton _)) (Subalgebra.one_mem _) -- Porting note: the previous proof was `rw [H] at this; exact this` but it now fails. exact IsCyclotomicExtension.equiv _ _ _ (Subalgebra.equivOfEq _ _ H) -- Porting note: the next `refine` was `rw [H]`, abusing defeq, and it now fails. have H := IntermediateField.adjoin_simple_toSubalgebra_of_integral ((integral {p ^ (k + 1)} K L).isIntegral (η + 1)) refine @IsCyclotomicExtension.equiv _ _ _ _ _ _ _ _ _ ?_ (Subalgebra.equivOfEq _ _ H).symm have hη' : IsPrimitiveRoot (η + 1) ↑(p ^ (k + 1 - s)) := by simpa using hη -- Porting note: `using 1` was not needed. 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, pow_coe] -- Porting note: the following `haveI` were not needed because the locale `cyclotomic` set them -- as instances. haveI := IsCyclotomicExtension.finiteDimensional {p ^ (k + 1)} K L haveI := IsCyclotomicExtension.isGalois (p ^ (k + 1)) K L rw [norm_eq_norm_adjoin K] have H := hη.sub_one_norm_isPrimePow ?_ hirr₁ htwo swap; · rw [PNat.pow_coe]; exact hpri.1.isPrimePow.pow (Nat.succ_ne_zero _) rw [add_sub_cancel_right] at H rw [H] congr · rw [PNat.pow_coe, Nat.pow_minFac, hpri.1.minFac_eq] exact Nat.succ_ne_zero _ have := FiniteDimensional.finrank_mul_finrank K K⟮η⟯ L rw [IsCyclotomicExtension.finrank L hirr, IsCyclotomicExtension.finrank K⟮η⟯ hirr₁, PNat.pow_coe, PNat.pow_coe, 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 => ?_ have coe_two : ((2 : ℕ+) : ℕ) = 2 := by norm_cast rw [← PNat.coe_inj, coe_two, PNat.pow_coe, ← pow_one 2] at h -- Porting note: the proof is slightly different because of coercions. 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 (PNat.coe_injective 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)`. -/ -- Porting note: writing `(2 : ℕ+)` was not needed (similarly everywhere). 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 (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 -- Porting note: `simpa using hirr` was `simp [hirr]`. replace hirr : Irreducible (cyclotomic ((2 : ℕ+) ^ (k + 1) : ℕ+) K) := by simpa using hirr -- Porting note: the proof is slightly different because of coercions. rw [this.eq_neg_one_of_two_right, H, Algebra.norm_algebraMap, IsCyclotomicExtension.finrank L hirr, pow_coe, show ((2 : ℕ+) : ℕ) = 2 from rfl, 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 simp only [← coe_lt_coe, one_coe, pow_coe] nth_rw 1 [← pow_one 2] exact pow_lt_pow_right one_lt_two (lt_of_lt_of_le one_lt_two hk) -- Porting note: `simpa using hirr` was `simp [hirr]`_ replace hirr : Irreducible (cyclotomic ((2 : ℕ+) ^ k : ℕ+) K) := by simpa using hirr -- Porting note: `simpa using hζ` was `simp [hζ]`_ replace hζ : IsPrimitiveRoot ζ (2 ^ k : ℕ+) := by simpa using hζ obtain ⟨k₁, hk₁⟩ := exists_eq_succ_of_ne_zero (lt_of_lt_of_le zero_lt_two hk).ne.symm -- Porting note: the proof is slightly different because of coercions. simpa [hk₁, show ((2 : ℕ+) : ℕ) = 2 from rfl] 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 [← PNat.coe_inj, PNat.pow_coe, ← pow_one 2] at htwo replace htwo := eq_of_prime_pow_eq (prime_iff.1 hpri.out) (prime_iff.1 Nat.prime_two) (succ_pos _) htwo rwa [show 2 = ((2 : ℕ+) : ℕ) by decide, PNat.coe_inj] at htwo replace hs : s = k := by rw [hp, ← PNat.coe_inj, PNat.pow_coe] at htwo nth_rw 2 [← pow_one 2] at htwo replace htwo := Nat.pow_right_injective rfl.le htwo rw [add_left_eq_self, Nat.sub_eq_zero_iff_le] at htwo exact le_antisymm hs htwo simp only [hs, hp, one_coe, cast_one, pow_coe, show ((2 : ℕ+) : ℕ) = 2 from rfl] at hζ hirr hcycl ⊢ obtain ⟨k₁, hk₁⟩ := Nat.exists_eq_succ_of_ne_zero hk -- Porting note: the proof is slightly different because of coercions. 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 @[deprecated (since := "2024-04-02")] alias IsPrimitiveRoot.pow_sub_one_norm_prime_pow_ne_two := IsPrimitiveRoot.norm_pow_sub_one_of_prime_pow_ne_two @[deprecated (since := "2024-04-02")] alias IsPrimitiveRoot.pow_sub_one_norm_prime_ne_two := IsPrimitiveRoot.norm_pow_sub_one_of_prime_ne_two @[deprecated (since := "2024-04-02")] alias IsPrimitiveRoot.sub_one_norm_prime_ne_two := IsPrimitiveRoot.norm_sub_one_of_prime_ne_two @[deprecated (since := "2024-04-02")] alias IsPrimitiveRoot.sub_one_norm_prime := IsPrimitiveRoot.norm_sub_one_of_prime_ne_two' @[deprecated (since := "2024-04-02")] alias IsPrimitiveRoot.pow_sub_one_norm_two := IsPrimitiveRoot.norm_pow_sub_one_two @[deprecated (since := "2024-04-02")] alias IsPrimitiveRoot.sub_one_norm_two := IsPrimitiveRoot.norm_sub_one_two @[deprecated (since := "2024-04-02")] alias IsPrimitiveRoot.pow_sub_one_norm_prime_pow_of_ne_zero := IsPrimitiveRoot.norm_pow_sub_one_eq_prime_pow_of_ne_zero @[deprecated (since := "2024-04-02")] alias IsCyclotomicExtension.isPrimePow_norm_zeta_sub_one := IsCyclotomicExtension.norm_zeta_sub_one_of_isPrimePow @[deprecated (since := "2024-04-02")] alias IsCyclotomicExtension.prime_ne_two_pow_norm_zeta_pow_sub_one := IsCyclotomicExtension.norm_zeta_pow_sub_one_of_prime_pow_ne_two @[deprecated (since := "2024-04-02")] alias IsCyclotomicExtension.prime_ne_two_pow_norm_zeta_sub_one := IsCyclotomicExtension.norm_zeta_pow_sub_one_of_prime_ne_two @[deprecated (since := "2024-04-02")] alias IsCyclotomicExtension.prime_ne_two_norm_zeta_sub_one := IsCyclotomicExtension.norm_zeta_sub_one_of_prime_ne_two @[deprecated (since := "2024-04-02")] alias IsCyclotomicExtension.two_pow_norm_zeta_sub_one := IsCyclotomicExtension.norm_zeta_pow_sub_one_two end Norm
NumberTheory\Cyclotomic\Rat.lean
/- Copyright (c) 2022 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.NumberTheory.Cyclotomic.Discriminant import Mathlib.RingTheory.Polynomial.Eisenstein.IsIntegral import Mathlib.RingTheory.Ideal.Norm /-! # Ring of integers of `p ^ n`-th cyclotomic fields We gather results about cyclotomic extensions of `ℚ`. In particular, we compute the ring of integers of a `p ^ n`-th cyclotomic extension of `ℚ`. ## Main results * `IsCyclotomicExtension.Rat.isIntegralClosure_adjoin_singleton_of_prime_pow`: if `K` is a `p ^ k`-th cyclotomic extension of `ℚ`, then `(adjoin ℤ {ζ})` is the integral closure of `ℤ` in `K`. * `IsCyclotomicExtension.Rat.cyclotomicRing_isIntegralClosure_of_prime_pow`: the integral closure of `ℤ` inside `CyclotomicField (p ^ k) ℚ` is `CyclotomicRing (p ^ k) ℤ ℚ`. * `IsCyclotomicExtension.Rat.absdiscr_prime_pow` and related results: the absolute discriminant of cyclotomic fields. -/ universe u open Algebra IsCyclotomicExtension Polynomial NumberField open scoped Cyclotomic Nat variable {p : ℕ+} {k : ℕ} {K : Type u} [Field K] {ζ : K} [hp : Fact (p : ℕ).Prime] namespace IsCyclotomicExtension.Rat variable [CharZero K] /-- The discriminant of the power basis given by `ζ - 1`. -/ theorem discr_prime_pow_ne_two' [IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) (hk : p ^ (k + 1) ≠ 2) : discr ℚ (hζ.subOnePowerBasis ℚ).basis = (-1) ^ ((p ^ (k + 1) : ℕ).totient / 2) * p ^ ((p : ℕ) ^ k * ((p - 1) * (k + 1) - 1)) := by rw [← discr_prime_pow_ne_two hζ (cyclotomic.irreducible_rat (p ^ (k + 1)).pos) hk] exact hζ.discr_zeta_eq_discr_zeta_sub_one.symm theorem discr_odd_prime' [IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) (hodd : p ≠ 2) : discr ℚ (hζ.subOnePowerBasis ℚ).basis = (-1) ^ (((p : ℕ) - 1) / 2) * p ^ ((p : ℕ) - 2) := by rw [← discr_odd_prime hζ (cyclotomic.irreducible_rat hp.out.pos) hodd] exact hζ.discr_zeta_eq_discr_zeta_sub_one.symm /-- The discriminant of the power basis given by `ζ - 1`. 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.Rat.discr_prime_pow_eq_unit_mul_pow'`. -/ theorem discr_prime_pow' [IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : discr ℚ (hζ.subOnePowerBasis ℚ).basis = (-1) ^ ((p ^ k : ℕ).totient / 2) * p ^ ((p : ℕ) ^ (k - 1) * ((p - 1) * k - 1)) := by rw [← discr_prime_pow hζ (cyclotomic.irreducible_rat (p ^ k).pos)] exact hζ.discr_zeta_eq_discr_zeta_sub_one.symm /-- If `p` is a prime and `IsCyclotomicExtension {p ^ k} K L`, then there are `u : ℤˣ` and `n : ℕ` such that the discriminant of the power basis given by `ζ - 1` is `u * p ^ n`. Often this is enough and less cumbersome to use than `IsCyclotomicExtension.Rat.discr_prime_pow'`. -/ theorem discr_prime_pow_eq_unit_mul_pow' [IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : ∃ (u : ℤˣ) (n : ℕ), discr ℚ (hζ.subOnePowerBasis ℚ).basis = u * p ^ n := by rw [hζ.discr_zeta_eq_discr_zeta_sub_one.symm] exact discr_prime_pow_eq_unit_mul_pow hζ (cyclotomic.irreducible_rat (p ^ k).pos) /-- If `K` is a `p ^ k`-th cyclotomic extension of `ℚ`, then `(adjoin ℤ {ζ})` is the integral closure of `ℤ` in `K`. -/ theorem isIntegralClosure_adjoin_singleton_of_prime_pow [hcycl : IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : IsIntegralClosure (adjoin ℤ ({ζ} : Set K)) ℤ K := by refine ⟨Subtype.val_injective, @fun x => ⟨fun h => ⟨⟨x, ?_⟩, rfl⟩, ?_⟩⟩ swap · rintro ⟨y, rfl⟩ exact IsIntegral.algebraMap ((le_integralClosure_iff_isIntegral.1 (adjoin_le_integralClosure (hζ.isIntegral (p ^ k).pos))).isIntegral _) let B := hζ.subOnePowerBasis ℚ have hint : IsIntegral ℤ B.gen := (hζ.isIntegral (p ^ k).pos).sub isIntegral_one -- Porting note: the following `haveI` was not needed because the locale `cyclotomic` set it -- as instances. letI := IsCyclotomicExtension.finiteDimensional {p ^ k} ℚ K have H := discr_mul_isIntegral_mem_adjoin ℚ hint h obtain ⟨u, n, hun⟩ := discr_prime_pow_eq_unit_mul_pow' hζ rw [hun] at H replace H := Subalgebra.smul_mem _ H u.inv -- Porting note: the proof is slightly different because of coercions. rw [← smul_assoc, ← smul_mul_assoc, Units.inv_eq_val_inv, zsmul_eq_mul, ← Int.cast_mul, Units.inv_mul, Int.cast_one, one_mul, smul_def, map_pow] at H cases k · haveI : IsCyclotomicExtension {1} ℚ K := by simpa using hcycl have : x ∈ (⊥ : Subalgebra ℚ K) := by rw [singleton_one ℚ K] exact mem_top obtain ⟨y, rfl⟩ := mem_bot.1 this replace h := (isIntegral_algebraMap_iff (algebraMap ℚ K).injective).1 h obtain ⟨z, hz⟩ := IsIntegrallyClosed.isIntegral_iff.1 h rw [← hz, ← IsScalarTower.algebraMap_apply] exact Subalgebra.algebraMap_mem _ _ · have hmin : (minpoly ℤ B.gen).IsEisensteinAt (Submodule.span ℤ {((p : ℕ) : ℤ)}) := by have h₁ := minpoly.isIntegrallyClosed_eq_field_fractions' ℚ hint have h₂ := hζ.minpoly_sub_one_eq_cyclotomic_comp (cyclotomic.irreducible_rat (p ^ _).pos) rw [IsPrimitiveRoot.subOnePowerBasis_gen] at h₁ rw [h₁, ← map_cyclotomic_int, show Int.castRingHom ℚ = algebraMap ℤ ℚ by rfl, show X + 1 = map (algebraMap ℤ ℚ) (X + 1) by simp, ← map_comp] at h₂ rw [IsPrimitiveRoot.subOnePowerBasis_gen, map_injective (algebraMap ℤ ℚ) (algebraMap ℤ ℚ).injective_int h₂] exact cyclotomic_prime_pow_comp_X_add_one_isEisensteinAt p _ refine adjoin_le ?_ (mem_adjoin_of_smul_prime_pow_smul_of_minpoly_isEisensteinAt (n := n) (Nat.prime_iff_prime_int.1 hp.out) hint h (by simpa using H) hmin) simp only [Set.singleton_subset_iff, SetLike.mem_coe] exact Subalgebra.sub_mem _ (self_mem_adjoin_singleton ℤ _) (Subalgebra.one_mem _) theorem isIntegralClosure_adjoin_singleton_of_prime [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ ↑p) : IsIntegralClosure (adjoin ℤ ({ζ} : Set K)) ℤ K := by rw [← pow_one p] at hζ hcycl exact isIntegralClosure_adjoin_singleton_of_prime_pow hζ /-- The integral closure of `ℤ` inside `CyclotomicField (p ^ k) ℚ` is `CyclotomicRing (p ^ k) ℤ ℚ`. -/ theorem cyclotomicRing_isIntegralClosure_of_prime_pow : IsIntegralClosure (CyclotomicRing (p ^ k) ℤ ℚ) ℤ (CyclotomicField (p ^ k) ℚ) := by have hζ := zeta_spec (p ^ k) ℚ (CyclotomicField (p ^ k) ℚ) refine ⟨IsFractionRing.injective _ _, @fun x => ⟨fun h => ⟨⟨x, ?_⟩, rfl⟩, ?_⟩⟩ -- Porting note: having `.isIntegral_iff` inside the definition of `this` causes an error. · have := isIntegralClosure_adjoin_singleton_of_prime_pow hζ obtain ⟨y, rfl⟩ := this.isIntegral_iff.1 h refine adjoin_mono ?_ y.2 simp only [PNat.pow_coe, Set.singleton_subset_iff, Set.mem_setOf_eq] exact hζ.pow_eq_one · rintro ⟨y, rfl⟩ exact IsIntegral.algebraMap ((IsCyclotomicExtension.integral {p ^ k} ℤ _).isIntegral _) theorem cyclotomicRing_isIntegralClosure_of_prime : IsIntegralClosure (CyclotomicRing p ℤ ℚ) ℤ (CyclotomicField p ℚ) := by rw [← pow_one p] exact cyclotomicRing_isIntegralClosure_of_prime_pow end IsCyclotomicExtension.Rat section PowerBasis open IsCyclotomicExtension.Rat namespace IsPrimitiveRoot section CharZero variable [CharZero K] /-- The algebra isomorphism `adjoin ℤ {ζ} ≃ₐ[ℤ] (𝓞 K)`, where `ζ` is a primitive `p ^ k`-th root of unity and `K` is a `p ^ k`-th cyclotomic extension of `ℚ`. -/ @[simps!] noncomputable def _root_.IsPrimitiveRoot.adjoinEquivRingOfIntegers [IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : adjoin ℤ ({ζ} : Set K) ≃ₐ[ℤ] 𝓞 K := let _ := isIntegralClosure_adjoin_singleton_of_prime_pow hζ IsIntegralClosure.equiv ℤ (adjoin ℤ ({ζ} : Set K)) K (𝓞 K) /-- The ring of integers of a `p ^ k`-th cyclotomic extension of `ℚ` is a cyclotomic extension. -/ instance IsCyclotomicExtension.ringOfIntegers [IsCyclotomicExtension {p ^ k} ℚ K] : IsCyclotomicExtension {p ^ k} ℤ (𝓞 K) := let _ := (zeta_spec (p ^ k) ℚ K).adjoin_isCyclotomicExtension ℤ IsCyclotomicExtension.equiv _ ℤ _ (zeta_spec (p ^ k) ℚ K).adjoinEquivRingOfIntegers /-- The integral `PowerBasis` of `𝓞 K` given by a primitive root of unity, where `K` is a `p ^ k` cyclotomic extension of `ℚ`. -/ noncomputable def integralPowerBasis [IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : PowerBasis ℤ (𝓞 K) := (Algebra.adjoin.powerBasis' (hζ.isIntegral (p ^ k).pos)).map hζ.adjoinEquivRingOfIntegers /-- Abbreviation to see a primitive root of unity as a member of the ring of integers. -/ abbrev toInteger {k : ℕ+} (hζ : IsPrimitiveRoot ζ k) : 𝓞 K := ⟨ζ, hζ.isIntegral k.pos⟩ end CharZero lemma coe_toInteger {k : ℕ+} (hζ : IsPrimitiveRoot ζ k) : hζ.toInteger.1 = ζ := rfl /-- `𝓞 K ⧸ Ideal.span {ζ - 1}` is finite. -/ lemma finite_quotient_toInteger_sub_one [NumberField K] {k : ℕ+} (hk : 1 < k) (hζ : IsPrimitiveRoot ζ k) : Finite (𝓞 K ⧸ Ideal.span {hζ.toInteger - 1}) := by refine (finite_iff_nonempty_fintype _).2 ⟨?_⟩ refine Ideal.fintypeQuotientOfFreeOfNeBot _ (fun h ↦ ?_) simp only [Ideal.span_singleton_eq_bot, sub_eq_zero, ← Subtype.coe_inj] at h exact hζ.ne_one hk (RingOfIntegers.ext_iff.1 h) /-- We have that `𝓞 K ⧸ Ideal.span {ζ - 1}` has cardinality equal to the norm of `ζ - 1`. See the results below to compute this norm in various cases. -/ lemma card_quotient_toInteger_sub_one [NumberField K] {k : ℕ+} (hk : 1 < k) (hζ : IsPrimitiveRoot ζ k) : Nat.card (𝓞 K ⧸ Ideal.span {hζ.toInteger - 1}) = (Algebra.norm ℤ (hζ.toInteger - 1)).natAbs := by have := hζ.finite_quotient_toInteger_sub_one hk let _ := Fintype.ofFinite (𝓞 K ⧸ Ideal.span {hζ.toInteger - 1}) rw [← Submodule.cardQuot_apply, ← Ideal.absNorm_apply, Ideal.absNorm_span_singleton] lemma toInteger_isPrimitiveRoot {k : ℕ+} (hζ : IsPrimitiveRoot ζ k) : IsPrimitiveRoot hζ.toInteger k := IsPrimitiveRoot.of_map_of_injective (by exact hζ) RingOfIntegers.coe_injective variable [CharZero K] -- Porting note: the proof changed because `simp` unfolds too much. @[simp] theorem integralPowerBasis_gen [hcycl : IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : hζ.integralPowerBasis.gen = hζ.toInteger := Subtype.ext <| show algebraMap _ K hζ.integralPowerBasis.gen = _ by rw [integralPowerBasis, PowerBasis.map_gen, adjoin.powerBasis'_gen] simp only [adjoinEquivRingOfIntegers_apply, IsIntegralClosure.algebraMap_lift] rfl @[simp] theorem integralPowerBasis_dim [hcycl : IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : hζ.integralPowerBasis.dim = φ (p ^ k) := by simp [integralPowerBasis, ← cyclotomic_eq_minpoly hζ, natDegree_cyclotomic] /-- The algebra isomorphism `adjoin ℤ {ζ} ≃ₐ[ℤ] (𝓞 K)`, where `ζ` is a primitive `p`-th root of unity and `K` is a `p`-th cyclotomic extension of `ℚ`. -/ @[simps!] noncomputable def _root_.IsPrimitiveRoot.adjoinEquivRingOfIntegers' [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) : adjoin ℤ ({ζ} : Set K) ≃ₐ[ℤ] 𝓞 K := @adjoinEquivRingOfIntegers p 1 K _ _ _ _ (by convert hcycl; rw [pow_one]) (by rwa [pow_one]) /-- The ring of integers of a `p`-th cyclotomic extension of `ℚ` is a cyclotomic extension. -/ instance _root_.IsCyclotomicExtension.ring_of_integers' [IsCyclotomicExtension {p} ℚ K] : IsCyclotomicExtension {p} ℤ (𝓞 K) := let _ := (zeta_spec p ℚ K).adjoin_isCyclotomicExtension ℤ IsCyclotomicExtension.equiv _ ℤ _ (zeta_spec p ℚ K).adjoinEquivRingOfIntegers' /-- The integral `PowerBasis` of `𝓞 K` given by a primitive root of unity, where `K` is a `p`-th cyclotomic extension of `ℚ`. -/ noncomputable def integralPowerBasis' [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) : PowerBasis ℤ (𝓞 K) := @integralPowerBasis p 1 K _ _ _ _ (by convert hcycl; rw [pow_one]) (by rwa [pow_one]) @[simp] theorem integralPowerBasis'_gen [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) : hζ.integralPowerBasis'.gen = hζ.toInteger := @integralPowerBasis_gen p 1 K _ _ _ _ (by convert hcycl; rw [pow_one]) (by rwa [pow_one]) @[simp] theorem power_basis_int'_dim [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) : hζ.integralPowerBasis'.dim = φ p := by erw [@integralPowerBasis_dim p 1 K _ _ _ _ (by convert hcycl; rw [pow_one]) (by rwa [pow_one]), pow_one] /-- The integral `PowerBasis` of `𝓞 K` given by `ζ - 1`, where `K` is a `p ^ k` cyclotomic extension of `ℚ`. -/ noncomputable def subOneIntegralPowerBasis [IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : PowerBasis ℤ (𝓞 K) := PowerBasis.ofGenMemAdjoin' hζ.integralPowerBasis (RingOfIntegers.isIntegral _) (by simp only [integralPowerBasis_gen, toInteger] convert Subalgebra.add_mem _ (self_mem_adjoin_singleton ℤ (⟨ζ - 1, _⟩ : 𝓞 K)) (Subalgebra.one_mem _) -- Porting note: `simp` was able to finish the proof. · simp only [Subsemiring.coe_add, Subalgebra.coe_toSubsemiring, OneMemClass.coe_one, sub_add_cancel] · exact Subalgebra.sub_mem _ (hζ.isIntegral (by simp)) (Subalgebra.one_mem _)) @[simp] theorem subOneIntegralPowerBasis_gen [IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : hζ.subOneIntegralPowerBasis.gen = ⟨ζ - 1, Subalgebra.sub_mem _ (hζ.isIntegral (p ^ k).pos) (Subalgebra.one_mem _)⟩ := by simp [subOneIntegralPowerBasis] /-- The integral `PowerBasis` of `𝓞 K` given by `ζ - 1`, where `K` is a `p`-th cyclotomic extension of `ℚ`. -/ noncomputable def subOneIntegralPowerBasis' [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) : PowerBasis ℤ (𝓞 K) := @subOneIntegralPowerBasis p 1 K _ _ _ _ (by convert hcycl; rw [pow_one]) (by rwa [pow_one]) @[simp] theorem subOneIntegralPowerBasis'_gen [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) : hζ.subOneIntegralPowerBasis'.gen = hζ.toInteger - 1 := @subOneIntegralPowerBasis_gen p 1 K _ _ _ _ (by convert hcycl; rw [pow_one]) (by rwa [pow_one]) /-- `ζ - 1` is prime if `p ≠ 2` and `ζ` is a primitive `p ^ (k + 1)`-th root of unity. See `zeta_sub_one_prime` for a general statement. -/ theorem zeta_sub_one_prime_of_ne_two [IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) (hodd : p ≠ 2) : Prime (hζ.toInteger - 1) := by letI := IsCyclotomicExtension.numberField {p ^ (k + 1)} ℚ K refine Ideal.prime_of_irreducible_absNorm_span (fun h ↦ ?_) ?_ · apply hζ.pow_ne_one_of_pos_of_lt zero_lt_one (one_lt_pow hp.out.one_lt (by simp)) rw [sub_eq_zero] at h simpa using congrArg (algebraMap _ K) h rw [Nat.irreducible_iff_prime, Ideal.absNorm_span_singleton, ← Nat.prime_iff, ← Int.prime_iff_natAbs_prime] convert Nat.prime_iff_prime_int.1 hp.out apply RingHom.injective_int (algebraMap ℤ ℚ) rw [← Algebra.norm_localization (Sₘ := K) ℤ (nonZeroDivisors ℤ)] simp only [PNat.pow_coe, id.map_eq_id, RingHomCompTriple.comp_eq, RingHom.coe_coe, Subalgebra.coe_val, algebraMap_int_eq, map_natCast] exact hζ.norm_sub_one_of_prime_ne_two (Polynomial.cyclotomic.irreducible_rat (PNat.pos _)) hodd /-- `ζ - 1` is prime if `ζ` is a primitive `2 ^ (k + 1)`-th root of unity. See `zeta_sub_one_prime` for a general statement. -/ theorem zeta_sub_one_prime_of_two_pow [IsCyclotomicExtension {(2 : ℕ+) ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑((2 : ℕ+) ^ (k + 1))) : Prime (hζ.toInteger - 1) := by letI := IsCyclotomicExtension.numberField {(2 : ℕ+) ^ (k + 1)} ℚ K refine Ideal.prime_of_irreducible_absNorm_span (fun h ↦ ?_) ?_ · apply hζ.pow_ne_one_of_pos_of_lt zero_lt_one (one_lt_pow (by decide) (by simp)) rw [sub_eq_zero] at h simpa using congrArg (algebraMap _ K) h rw [Nat.irreducible_iff_prime, Ideal.absNorm_span_singleton, ← Nat.prime_iff, ← Int.prime_iff_natAbs_prime] cases k · convert Prime.neg Int.prime_two apply RingHom.injective_int (algebraMap ℤ ℚ) rw [← Algebra.norm_localization (Sₘ := K) ℤ (nonZeroDivisors ℤ)] simp only [Nat.zero_eq, PNat.pow_coe, id.map_eq_id, RingHomCompTriple.comp_eq, RingHom.coe_coe, Subalgebra.coe_val, algebraMap_int_eq, map_neg, map_ofNat] simpa only [zero_add, pow_one, AddSubgroupClass.coe_sub, OneMemClass.coe_one, Nat.zero_eq, pow_zero] using hζ.norm_pow_sub_one_two (cyclotomic.irreducible_rat (by simp only [Nat.zero_eq, zero_add, pow_one, Nat.ofNat_pos])) convert Int.prime_two apply RingHom.injective_int (algebraMap ℤ ℚ) rw [← Algebra.norm_localization (Sₘ := K) ℤ (nonZeroDivisors ℤ)] simp only [PNat.pow_coe, id.map_eq_id, RingHomCompTriple.comp_eq, RingHom.coe_coe, Subalgebra.coe_val, algebraMap_int_eq, map_natCast] exact hζ.norm_sub_one_two Nat.AtLeastTwo.prop (cyclotomic.irreducible_rat (by simp)) /-- `ζ - 1` is prime if `ζ` is a primitive `p ^ (k + 1)`-th root of unity. -/ theorem zeta_sub_one_prime [IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) : Prime (hζ.toInteger - 1) := by by_cases htwo : p = 2 · subst htwo apply hζ.zeta_sub_one_prime_of_two_pow · apply hζ.zeta_sub_one_prime_of_ne_two htwo /-- `ζ - 1` is prime if `ζ` is a primitive `p`-th root of unity. -/ theorem zeta_sub_one_prime' [h : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) : Prime ((hζ.toInteger - 1)) := by convert zeta_sub_one_prime (k := 0) (by simpa only [zero_add, pow_one]) simpa only [zero_add, pow_one] theorem subOneIntegralPowerBasis_gen_prime [IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) : Prime hζ.subOneIntegralPowerBasis.gen := by simpa only [subOneIntegralPowerBasis_gen] using hζ.zeta_sub_one_prime theorem subOneIntegralPowerBasis'_gen_prime [IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ ↑p) : Prime hζ.subOneIntegralPowerBasis'.gen := by simpa only [subOneIntegralPowerBasis'_gen] using hζ.zeta_sub_one_prime' /-- The norm, relative to `ℤ`, of `ζ ^ p ^ s - 1` in a `p ^ (k + 1)`-th cyclotomic extension of `ℚ` is p ^ p ^ s` if `s ≤ k` and `p ^ (k - s + 1) ≠ 2`. -/ lemma norm_toInteger_pow_sub_one_of_prime_pow_ne_two [IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) {s : ℕ} (hs : s ≤ k) (htwo : p ^ (k - s + 1) ≠ 2) : Algebra.norm ℤ (hζ.toInteger ^ (p : ℕ) ^ s - 1) = p ^ (p : ℕ) ^ s := by have : NumberField K := IsCyclotomicExtension.numberField {p ^ (k + 1)} ℚ K rw [Algebra.norm_eq_iff ℤ (Sₘ := K) (Rₘ := ℚ) rfl.le] simp [hζ.norm_pow_sub_one_of_prime_pow_ne_two (cyclotomic.irreducible_rat (by simp only [PNat.pow_coe, gt_iff_lt, PNat.pos, pow_pos])) hs htwo] /-- The norm, relative to `ℤ`, of `ζ ^ 2 ^ k - 1` in a `2 ^ (k + 1)`-th cyclotomic extension of `ℚ` is `(-2) ^ 2 ^ k`. -/ lemma norm_toInteger_pow_sub_one_of_two [IsCyclotomicExtension {2 ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑((2 : ℕ+) ^ (k + 1))) : Algebra.norm ℤ (hζ.toInteger ^ 2 ^ k - 1) = (-2) ^ (2 : ℕ) ^ k := by have : NumberField K := IsCyclotomicExtension.numberField {2 ^ (k + 1)} ℚ K rw [Algebra.norm_eq_iff ℤ (Sₘ := K) (Rₘ := ℚ) rfl.le] simp [hζ.norm_pow_sub_one_two (cyclotomic.irreducible_rat (pow_pos (by decide) _))] /-- The norm, relative to `ℤ`, of `ζ ^ p ^ s - 1` in a `p ^ (k + 1)`-th cyclotomic extension of `ℚ` is `p ^ p ^ s` if `s ≤ k` and `p ≠ 2`. -/ lemma norm_toInteger_pow_sub_one_of_prime_ne_two [IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) {s : ℕ} (hs : s ≤ k) (hodd : p ≠ 2) : Algebra.norm ℤ (hζ.toInteger ^ (p : ℕ) ^ s - 1) = p ^ (p : ℕ) ^ s := by refine hζ.norm_toInteger_pow_sub_one_of_prime_pow_ne_two hs (fun h ↦ hodd ?_) suffices h : (p : ℕ) = 2 from PNat.coe_injective h apply eq_of_prime_pow_eq hp.out.prime Nat.prime_two.prime (k - s).succ_pos rw [pow_one] exact congr_arg Subtype.val h /-- The norm, relative to `ℤ`, of `ζ - 1` in a `p ^ (k + 1)`-th cyclotomic extension of `ℚ` is `p` if `p ≠ 2`. -/ lemma norm_toInteger_sub_one_of_prime_ne_two [IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) (hodd : p ≠ 2) : Algebra.norm ℤ (hζ.toInteger - 1) = p := by simpa only [pow_zero, pow_one] using hζ.norm_toInteger_pow_sub_one_of_prime_ne_two (Nat.zero_le _) hodd /-- The norm, relative to `ℤ`, of `ζ - 1` in a `p`-th cyclotomic extension of `ℚ` is `p` if `p ≠ 2`. -/ lemma norm_toInteger_sub_one_of_prime_ne_two' [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) (h : p ≠ 2) : Algebra.norm ℤ (hζ.toInteger - 1) = p := by have : IsCyclotomicExtension {p ^ (0 + 1)} ℚ K := by simpa using hcycl replace hζ : IsPrimitiveRoot ζ (p ^ (0 + 1)) := by simpa using hζ exact hζ.norm_toInteger_sub_one_of_prime_ne_two h /-- The norm, relative to `ℤ`, of `ζ - 1` in a `p ^ (k + 1)`-th cyclotomic extension of `ℚ` is a prime if `p ^ (k + 1) ≠ 2`. -/ lemma prime_norm_toInteger_sub_one_of_prime_pow_ne_two [IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) (htwo : p ^ (k + 1) ≠ 2) : Prime (Algebra.norm ℤ (hζ.toInteger - 1)) := by have := hζ.norm_toInteger_pow_sub_one_of_prime_pow_ne_two (zero_le _) htwo simp only [pow_zero, pow_one] at this rw [this] exact Nat.prime_iff_prime_int.1 hp.out /-- The norm, relative to `ℤ`, of `ζ - 1` in a `p ^ (k + 1)`-th cyclotomic extension of `ℚ` is a prime if `p ≠ 2`. -/ lemma prime_norm_toInteger_sub_one_of_prime_ne_two [hcycl : IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) (hodd : p ≠ 2) : Prime (Algebra.norm ℤ (hζ.toInteger - 1)) := by have := hζ.norm_toInteger_sub_one_of_prime_ne_two hodd simp only [pow_zero, pow_one] at this rw [this] exact Nat.prime_iff_prime_int.1 hp.out /-- The norm, relative to `ℤ`, of `ζ - 1` in a `p`-th cyclotomic extension of `ℚ` is a prime if `p ≠ 2`. -/ lemma prime_norm_toInteger_sub_one_of_prime_ne_two' [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ ↑p) (hodd : p ≠ 2) : Prime (Algebra.norm ℤ (hζ.toInteger - 1)) := by have : IsCyclotomicExtension {p ^ (0 + 1)} ℚ K := by simpa using hcycl replace hζ : IsPrimitiveRoot ζ (p ^ (0 + 1)) := by simpa using hζ exact hζ.prime_norm_toInteger_sub_one_of_prime_ne_two hodd /-- In a `p ^ (k + 1)`-th cyclotomic extension of `ℚ `, we have that `ζ` is not congruent to an integer modulo `p` if `p ^ (k + 1) ≠ 2`. -/ theorem not_exists_int_prime_dvd_sub_of_prime_pow_ne_two [hcycl : IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) (htwo : p ^ (k + 1) ≠ 2) : ¬(∃ n : ℤ, (p : 𝓞 K) ∣ (hζ.toInteger - n : 𝓞 K)) := by intro ⟨n, x, h⟩ -- Let `pB` be the power basis of `𝓞 K` given by powers of `ζ`. let pB := hζ.integralPowerBasis have hdim : pB.dim = ↑p ^ k * (↑p - 1) := by simp [integralPowerBasis_dim, pB, Nat.totient_prime_pow hp.1 (Nat.zero_lt_succ k)] replace hdim : 1 < pB.dim := by rw [Nat.one_lt_iff_ne_zero_and_ne_one, hdim] refine ⟨by simp only [ne_eq, mul_eq_zero, pow_eq_zero_iff', PNat.ne_zero, false_and, false_or, Nat.sub_eq_zero_iff_le, not_le, Nat.Prime.one_lt hp.out], ne_of_gt ?_⟩ by_cases hk : k = 0 · simp only [hk, zero_add, pow_one, pow_zero, one_mul, Nat.lt_sub_iff_add_lt, Nat.reduceAdd] at htwo ⊢ exact htwo.symm.lt_of_le hp.1.two_le · exact one_lt_mul_of_lt_of_le (one_lt_pow hp.1.one_lt hk) (have := Nat.Prime.two_le hp.out; by omega) rw [sub_eq_iff_eq_add] at h -- We are assuming that `ζ = n + p * x` for some integer `n` and `x : 𝓞 K`. Looking at the -- coordinates in the base `pB`, we obtain that `1` is a multiple of `p`, contradiction. replace h := pB.basis.ext_elem_iff.1 h ⟨1, hdim⟩ have := pB.basis_eq_pow ⟨1, hdim⟩ rw [hζ.integralPowerBasis_gen] at this simp only [PowerBasis.coe_basis, pow_one] at this rw [← this, show pB.gen = pB.gen ^ (⟨1, hdim⟩ : Fin pB.dim).1 by simp, ← pB.basis_eq_pow, pB.basis.repr_self_apply] at h simp only [↓reduceIte, map_add, Finsupp.coe_add, Pi.add_apply] at h rw [show (p : 𝓞 K) * x = (p : ℤ) • x by simp, ← pB.basis.coord_apply, LinearMap.map_smul, ← zsmul_one, ← pB.basis.coord_apply, LinearMap.map_smul, show 1 = pB.gen ^ (⟨0, by linarith⟩ : Fin pB.dim).1 by simp, ← pB.basis_eq_pow, pB.basis.coord_apply, pB.basis.coord_apply, pB.basis.repr_self_apply] at h simp only [smul_eq_mul, Fin.mk.injEq, zero_ne_one, ↓reduceIte, mul_zero, add_zero] at h exact (Int.prime_iff_natAbs_prime.2 (by simp [hp.1])).not_dvd_one ⟨_, h⟩ /-- In a `p ^ (k + 1)`-th cyclotomic extension of `ℚ `, we have that `ζ` is not congruent to an integer modulo `p` if `p ≠ 2`. -/ theorem not_exists_int_prime_dvd_sub_of_prime_ne_two [hcycl : IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) (hodd : p ≠ 2) : ¬(∃ n : ℤ, (p : 𝓞 K) ∣ (hζ.toInteger - n : 𝓞 K)) := by refine not_exists_int_prime_dvd_sub_of_prime_pow_ne_two hζ (fun h ↦ ?_) simp_all only [(@Nat.Prime.pow_eq_iff 2 p (k+1) Nat.prime_two).mp (by assumption_mod_cast), pow_one, ne_eq] /-- In a `p`-th cyclotomic extension of `ℚ `, we have that `ζ` is not congruent to an integer modulo `p` if `p ≠ 2`. -/ theorem not_exists_int_prime_dvd_sub_of_prime_ne_two' [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ ↑p) (hodd : p ≠ 2) : ¬(∃ n : ℤ, (p : 𝓞 K) ∣ (hζ.toInteger - n : 𝓞 K)) := by have : IsCyclotomicExtension {p ^ (0 + 1)} ℚ K := by simpa using hcycl replace hζ : IsPrimitiveRoot ζ (p ^ (0 + 1)) := by simpa using hζ exact not_exists_int_prime_dvd_sub_of_prime_ne_two hζ hodd theorem finite_quotient_span_sub_one [hcycl : IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) : Finite (𝓞 K ⧸ Ideal.span {hζ.toInteger - 1}) := by have : NumberField K := IsCyclotomicExtension.numberField {p ^ (k + 1)} ℚ K refine Fintype.finite <| Ideal.fintypeQuotientOfFreeOfNeBot _ (fun h ↦ ?_) simp only [Ideal.span_singleton_eq_bot, sub_eq_zero, ← Subtype.coe_inj] at h exact hζ.ne_one (one_lt_pow hp.1.one_lt (Nat.zero_ne_add_one k).symm) (RingOfIntegers.ext_iff.1 h) theorem finite_quotient_span_sub_one' [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ ↑p) : Finite (𝓞 K ⧸ Ideal.span {hζ.toInteger - 1}) := by have : IsCyclotomicExtension {p ^ (0 + 1)} ℚ K := by simpa using hcycl replace hζ : IsPrimitiveRoot ζ (p ^ (0 + 1)) := by simpa using hζ exact hζ.finite_quotient_span_sub_one /-- In a `p ^ (k + 1)`-th cyclotomic extension of `ℚ`, we have that `ζ - 1` divides `p` in `𝓞 K`. -/ lemma toInteger_sub_one_dvd_prime [hcycl : IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) : ((hζ.toInteger - 1)) ∣ p := by by_cases htwo : p ^ (k + 1) = 2 · replace htwo : (p : ℕ) ^ (k + 1) = 2 := by exact_mod_cast htwo have ⟨hp2, hk⟩ := (Nat.Prime.pow_eq_iff Nat.prime_two).1 htwo simp only [add_left_eq_self] at hk have hζ' : ζ = -1 := by refine IsPrimitiveRoot.eq_neg_one_of_two_right ?_ rwa [hk, zero_add, pow_one, hp2] at hζ replace hζ' : hζ.toInteger = -1 := by ext exact hζ' rw [hζ', hp2] exact ⟨-1, by ring⟩ suffices (hζ.toInteger - 1) ∣ (p : ℤ) by simpa have := IsCyclotomicExtension.numberField {p ^ (k + 1)} ℚ K have H := hζ.norm_toInteger_pow_sub_one_of_prime_pow_ne_two (zero_le _) htwo rw [pow_zero, pow_one] at H rw [← Ideal.norm_dvd_iff, H] · simp · exact prime_norm_toInteger_sub_one_of_prime_pow_ne_two hζ htwo /-- In a `p`-th cyclotomic extension of `ℚ`, we have that `ζ - 1` divides `p` in `𝓞 K`. -/ lemma toInteger_sub_one_dvd_prime' [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ ↑p) : ((hζ.toInteger - 1)) ∣ p := by have : IsCyclotomicExtension {p ^ (0 + 1)} ℚ K := by simpa using hcycl replace hζ : IsPrimitiveRoot ζ (p ^ (0 + 1)) := by simpa using hζ exact toInteger_sub_one_dvd_prime hζ /-- We have that `hζ.toInteger - 1` does not divide `2`. -/ lemma toInteger_sub_one_not_dvd_two [IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) (hodd : p ≠ 2) : ¬ hζ.toInteger - 1 ∣ 2 := fun h ↦ by have : NumberField K := IsCyclotomicExtension.numberField {p ^ (k + 1)} ℚ K replace h : hζ.toInteger - 1 ∣ ↑(2 : ℤ) := by simp [h] rw [← Ideal.norm_dvd_iff, hζ.norm_toInteger_sub_one_of_prime_ne_two hodd] at h · refine hodd <| PNat.coe_inj.1 <| (prime_dvd_prime_iff_eq ?_ ?_).1 ?_ · exact Nat.prime_iff.1 hp.1 · exact Nat.prime_iff.1 Nat.prime_two · exact Int.ofNat_dvd.mp h · rw [hζ.norm_toInteger_sub_one_of_prime_ne_two hodd] exact Nat.prime_iff_prime_int.1 hp.1 end IsPrimitiveRoot section absdiscr namespace IsCyclotomicExtension.Rat open nonZeroDivisors IsPrimitiveRoot variable (K p k) variable [CharZero K] /-- We compute the absolute discriminant of a `p ^ k`-th cyclotomic field. Beware that in the cases `p ^ k = 1` and `p ^ k = 2` the formula uses `1 / 2 = 0` and `0 - 1 = 0`. See also the results below. -/ theorem absdiscr_prime_pow [IsCyclotomicExtension {p ^ k} ℚ K] : haveI : NumberField K := IsCyclotomicExtension.numberField {p ^ k} ℚ K NumberField.discr K = (-1) ^ ((p ^ k : ℕ).totient / 2) * p ^ ((p : ℕ) ^ (k - 1) * ((p - 1) * k - 1)) := by have hζ := IsCyclotomicExtension.zeta_spec (p ^ k) ℚ K have : NumberField K := IsCyclotomicExtension.numberField {p ^ k} ℚ K let pB₁ := integralPowerBasis hζ apply (algebraMap ℤ ℚ).injective_int rw [← NumberField.discr_eq_discr _ pB₁.basis, ← Algebra.discr_localizationLocalization ℤ ℤ⁰ K] convert IsCyclotomicExtension.discr_prime_pow hζ (cyclotomic.irreducible_rat (p ^ k).2) using 1 · have : pB₁.dim = (IsPrimitiveRoot.powerBasis ℚ hζ).dim := by rw [← PowerBasis.finrank, ← PowerBasis.finrank] exact RingOfIntegers.rank K rw [← Algebra.discr_reindex _ _ (finCongr this)] congr 1 ext i simp_rw [Function.comp_apply, Basis.localizationLocalization_apply, powerBasis_dim, PowerBasis.coe_basis, pB₁, integralPowerBasis_gen] convert ← ((IsPrimitiveRoot.powerBasis ℚ hζ).basis_eq_pow i).symm using 1 · simp_rw [algebraMap_int_eq, map_mul, map_pow, map_neg, map_one, map_natCast] open Nat in /-- We compute the absolute discriminant of a `p ^ (k + 1)`-th cyclotomic field. Beware that in the case `p ^ k = 2` the formula uses `1 / 2 = 0`. See also the results below. -/ theorem absdiscr_prime_pow_succ [IsCyclotomicExtension {p ^ (k + 1)} ℚ K] : haveI : NumberField K := IsCyclotomicExtension.numberField {p ^ (k + 1)} ℚ K NumberField.discr K = (-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 absdiscr_prime_pow p (k + 1) K /-- We compute the absolute discriminant of a `p`-th cyclotomic field where `p` is prime. -/ theorem absdiscr_prime [IsCyclotomicExtension {p} ℚ K] : haveI : NumberField K := IsCyclotomicExtension.numberField {p} ℚ K NumberField.discr K = (-1) ^ (((p : ℕ) - 1) / 2) * p ^ ((p : ℕ) - 2) := by have : IsCyclotomicExtension {p ^ (0 + 1)} ℚ K := by rw [zero_add, pow_one] infer_instance rw [absdiscr_prime_pow_succ p 0 K] simp only [Int.reduceNeg, pow_zero, one_mul, zero_add, mul_one, mul_eq_mul_left_iff, gt_iff_lt, Nat.cast_pos, PNat.pos, pow_eq_zero_iff', neg_eq_zero, one_ne_zero, ne_eq, false_and, or_false] rfl end IsCyclotomicExtension.Rat end absdiscr end PowerBasis
NumberTheory\Cyclotomic\Three.lean
/- Copyright (c) 2024 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca, Pietro Monticone -/ import Mathlib.NumberTheory.Cyclotomic.Embeddings import Mathlib.NumberTheory.Cyclotomic.Rat import Mathlib.NumberTheory.NumberField.Units.DirichletTheorem import Mathlib.RingTheory.Fintype /-! # Third Cyclotomic Field We gather various results about the third cyclotomic field. The following notations are used in this file: `K` is a number field such that `IsCyclotomicExtension {3} ℚ K`, `ζ` is any primitive `3`-rd root of unity in `K`, `η` is the element in the units of the ring of integers corresponding to `ζ` and `λ = η - 1`. ## Main results * `IsCyclotomicExtension.Rat.Three.Units.mem`: Given a unit `u : (𝓞 K)ˣ`, we have that `u ∈ {1, -1, η, -η, η^2, -η^2}`. * `IsCyclotomicExtension.Rat.Three.eq_one_or_neg_one_of_unit_of_congruent`: Given a unit `u : (𝓞 K)ˣ`, if `u` is congruent to an integer modulo `3`, then `u = 1` or `u = -1`. This is a special case of the so-called *Kummer's lemma* (see for example [washington_cyclotomic], Theorem 5.36 -/ open NumberField Units InfinitePlace nonZeroDivisors Polynomial namespace IsCyclotomicExtension.Rat.Three variable {K : Type*} [Field K] variable {ζ : K} (hζ : IsPrimitiveRoot ζ ↑(3 : ℕ+)) (u : (𝓞 K)ˣ) local notation3 "η" => (IsPrimitiveRoot.isUnit (hζ.toInteger_isPrimitiveRoot) (by decide)).unit local notation3 "λ" => hζ.toInteger - 1 lemma coe_eta : (η : 𝓞 K) = hζ.toInteger := rfl lemma _root_.IsPrimitiveRoot.toInteger_cube_eq_one : hζ.toInteger ^ 3 = 1 := hζ.toInteger_isPrimitiveRoot.pow_eq_one /-- Let `u` be a unit in `(𝓞 K)ˣ`, then `u ∈ [1, -1, η, -η, η^2, -η^2]`. -/ -- Here `List` is more convenient than `Finset`, even if further from the informal statement. -- For example, `fin_cases` below does not work with a `Finset`. theorem Units.mem [NumberField K] [IsCyclotomicExtension {3} ℚ K] : u ∈ [1, -1, η, -η, η ^ 2, -η ^ 2] := by have hrank : rank K = 0 := by dsimp only [rank] rw [card_eq_nrRealPlaces_add_nrComplexPlaces, nrRealPlaces_eq_zero (n := 3) K (by decide), zero_add, nrComplexPlaces_eq_totient_div_two (n := 3)] rfl obtain ⟨⟨x, e⟩, hxu, -⟩ := exist_unique_eq_mul_prod _ u replace hxu : u = x := by rw [← mul_one x.1, hxu] apply congr_arg rw [← Finset.prod_empty] congr rw [Finset.univ_eq_empty_iff, hrank] infer_instance obtain ⟨n, hnpos, hn⟩ := isOfFinOrder_iff_pow_eq_one.1 <| (CommGroup.mem_torsion _ _).1 x.2 replace hn : (↑u : K) ^ ((⟨n, hnpos⟩ : ℕ+) : ℕ) = 1 := by rw [← map_pow] convert map_one (algebraMap (𝓞 K) K) rw_mod_cast [hxu, hn] simp obtain ⟨r, hr3, hru⟩ := hζ.exists_pow_or_neg_mul_pow_of_isOfFinOrder (by decide) (isOfFinOrder_iff_pow_eq_one.2 ⟨n, hnpos, hn⟩) replace hr : r ∈ Finset.Ico 0 3 := Finset.mem_Ico.2 ⟨by simp, hr3⟩ replace hru : ↑u = η ^ r ∨ ↑u = -η ^ r := by rcases hru with h | h · left; ext; exact h · right; ext; exact h fin_cases hr <;> rcases hru with h | h <;> simp [h] /-- We have that `λ ^ 2 = -3 * η`. -/ private lemma lambda_sq : λ ^ 2 = -3 * η := by ext calc (λ ^ 2 : K) = η ^ 2 + η + 1 - 3 * η := by simp only [RingOfIntegers.map_mk, IsUnit.unit_spec]; ring _ = 0 - 3 * η := by simpa using hζ.isRoot_cyclotomic (by decide) _ = -3 * η := by ring /-- We have that `η ^ 2 = -η - 1`. -/ lemma eta_sq : (η ^ 2 : 𝓞 K) = - η - 1 := by rw [← neg_add', ← add_eq_zero_iff_eq_neg, ← add_assoc] ext; simpa using hζ.isRoot_cyclotomic (by decide) /-- If a unit `u` is congruent to an integer modulo `λ ^ 2`, then `u = 1` or `u = -1`. This is a special case of the so-called *Kummer's lemma*. -/ theorem eq_one_or_neg_one_of_unit_of_congruent [NumberField K] [IsCyclotomicExtension {3} ℚ K] (hcong : ∃ n : ℤ, λ ^ 2 ∣ (u - n : 𝓞 K)) : u = 1 ∨ u = -1 := by replace hcong : ∃ n : ℤ, (3 : 𝓞 K) ∣ (↑u - n : 𝓞 K) := by obtain ⟨n, x, hx⟩ := hcong exact ⟨n, -η * x, by rw [← mul_assoc, mul_neg, ← neg_mul, ← lambda_sq, hx]⟩ have hζ := IsCyclotomicExtension.zeta_spec 3 ℚ K have := Units.mem hζ u fin_cases this · left; rfl · right; rfl all_goals exfalso · exact hζ.not_exists_int_prime_dvd_sub_of_prime_ne_two' (by decide) hcong · apply hζ.not_exists_int_prime_dvd_sub_of_prime_ne_two' (by decide) obtain ⟨n, x, hx⟩ := hcong rw [sub_eq_iff_eq_add] at hx refine ⟨-n, -x, sub_eq_iff_eq_add.2 ?_⟩ simp only [PNat.val_ofNat, Nat.cast_ofNat, mul_neg, Int.cast_neg, ← neg_add, ← hx, Units.val_neg, IsUnit.unit_spec, RingOfIntegers.neg_mk, neg_neg] · exact (hζ.pow_of_coprime 2 (by decide)).not_exists_int_prime_dvd_sub_of_prime_ne_two' (by decide) hcong · apply (hζ.pow_of_coprime 2 (by decide)).not_exists_int_prime_dvd_sub_of_prime_ne_two' (by decide) obtain ⟨n, x, hx⟩ := hcong refine ⟨-n, -x, sub_eq_iff_eq_add.2 ?_⟩ have : (hζ.pow_of_coprime 2 (by decide)).toInteger = hζ.toInteger ^ 2 := by ext; simp simp only [this, PNat.val_ofNat, Nat.cast_ofNat, mul_neg, Int.cast_neg, ← neg_add, ← sub_eq_iff_eq_add.1 hx, Units.val_neg, val_pow_eq_pow_val, IsUnit.unit_spec, neg_neg] variable (x : 𝓞 K) /-- Let `(x : 𝓞 K)`. Then we have that `λ` divides one amongst `x`, `x - 1` and `x + 1`. -/ lemma lambda_dvd_or_dvd_sub_one_or_dvd_add_one [NumberField K] [IsCyclotomicExtension {3} ℚ K] : λ ∣ x ∨ λ ∣ x - 1 ∨ λ ∣ x + 1 := by classical have := hζ.finite_quotient_toInteger_sub_one (by decide) let _ := Fintype.ofFinite (𝓞 K ⧸ Ideal.span {λ}) let _ : Ring (𝓞 K ⧸ Ideal.span {λ}) := CommRing.toRing -- to speed up instance synthesis let _ : AddGroup (𝓞 K ⧸ Ideal.span {λ}) := AddGroupWithOne.toAddGroup -- dito have := Finset.mem_univ (Ideal.Quotient.mk (Ideal.span {λ}) x) have h3 : Fintype.card (𝓞 K ⧸ Ideal.span {λ}) = 3 := by rw [← Nat.card_eq_fintype_card, hζ.card_quotient_toInteger_sub_one (by decide), hζ.norm_toInteger_sub_one_of_prime_ne_two' (by decide)] simp only [PNat.val_ofNat, Nat.cast_ofNat, Int.reduceAbs] rw [Finset.univ_of_card_le_three h3.le] at this simp only [Finset.mem_insert, Finset.mem_singleton] at this rcases this with h | h | h · left exact Ideal.mem_span_singleton.1 <| Ideal.Quotient.eq_zero_iff_mem.1 h · right; left refine Ideal.mem_span_singleton.1 <| Ideal.Quotient.eq_zero_iff_mem.1 ?_ rw [RingHom.map_sub, h, RingHom.map_one, sub_self] · right; right refine Ideal.mem_span_singleton.1 <| Ideal.Quotient.eq_zero_iff_mem.1 ?_ rw [RingHom.map_add, h, RingHom.map_one, add_left_neg] /-- We have that `η ^ 2 + η + 1 = 0`. -/ lemma eta_sq_add_eta_add_one : (η : 𝓞 K) ^ 2 + η + 1 = 0 := by rw [eta_sq] ring /-- We have that `x ^ 3 - 1 = (x - 1) * (x - η) * (x - η ^ 2)`. -/ lemma cube_sub_one_eq_mul : x ^ 3 - 1 = (x - 1) * (x - η) * (x - η ^ 2) := by symm calc _ = x ^ 3 - x ^ 2 * (η ^ 2 + η + 1) + x * (η ^ 2 + η + η ^ 3) - η ^ 3 := by ring _ = x ^ 3 - x ^ 2 * (η ^ 2 + η + 1) + x * (η ^ 2 + η + 1) - 1 := by simp [hζ.toInteger_cube_eq_one] _ = x ^ 3 - 1 := by rw [eta_sq_add_eta_add_one hζ]; ring variable [NumberField K] [IsCyclotomicExtension {3} ℚ K] /-- We have that `λ` divides `x * (x - 1) * (x - (η + 1))`. -/ lemma lambda_dvd_mul_sub_one_mul_sub_eta_add_one : λ ∣ x * (x - 1) * (x - (η + 1)) := by rcases lambda_dvd_or_dvd_sub_one_or_dvd_add_one hζ x with h | h | h · exact dvd_mul_of_dvd_left (dvd_mul_of_dvd_left h _) _ · exact dvd_mul_of_dvd_left (dvd_mul_of_dvd_right h _) _ · refine dvd_mul_of_dvd_right ?_ _ rw [show x - (η + 1) = x + 1 - (η - 1 + 3) by ring] exact dvd_sub h <| dvd_add dvd_rfl hζ.toInteger_sub_one_dvd_prime' /-- If `λ` divides `x - 1`, then `λ ^ 4` divides `x ^ 3 - 1`. -/ lemma lambda_pow_four_dvd_cube_sub_one_of_dvd_sub_one {x : 𝓞 K} (h : λ ∣ x - 1) : λ ^ 4 ∣ x ^ 3 - 1 := by obtain ⟨y, hy⟩ := h have : x ^ 3 - 1 = λ ^ 3 * (y * (y - 1) * (y - (η + 1))) := by calc _ = (x - 1) * (x - 1 - λ) * (x - 1 - λ * (η + 1)) := by simp only [coe_eta, cube_sub_one_eq_mul hζ x]; ring _ = _ := by rw [hy]; ring rw [this, pow_succ] exact mul_dvd_mul_left _ (lambda_dvd_mul_sub_one_mul_sub_eta_add_one hζ y) /-- If `λ` divides `x + 1`, then `λ ^ 4` divides `x ^ 3 + 1`. -/ lemma lambda_pow_four_dvd_cube_add_one_of_dvd_add_one {x : 𝓞 K} (h : λ ∣ x + 1) : λ ^ 4 ∣ x ^ 3 + 1 := by replace h : λ ∣ -x - 1 := by convert h.neg_right using 1 exact (neg_add' x 1).symm convert (lambda_pow_four_dvd_cube_sub_one_of_dvd_sub_one hζ h).neg_right using 1 ring /-- If `λ` does not divide `x`, then `λ ^ 4` divides `x ^ 3 - 1` or `x ^ 3 + 1`. -/ lemma lambda_pow_four_dvd_cube_sub_one_or_add_one_of_lambda_not_dvd {x : 𝓞 K} (h : ¬ λ ∣ x) : λ ^ 4 ∣ x ^ 3 - 1 ∨ λ ^ 4 ∣ x ^ 3 + 1 := by rcases lambda_dvd_or_dvd_sub_one_or_dvd_add_one hζ x with H | H | H · contradiction · left exact lambda_pow_four_dvd_cube_sub_one_of_dvd_sub_one hζ H · right exact lambda_pow_four_dvd_cube_add_one_of_dvd_add_one hζ H end Three end Rat end IsCyclotomicExtension
NumberTheory\DirichletCharacter\Basic.lean
/- Copyright (c) 2023 Ashvni Narayanan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ashvni Narayanan, Moritz Firsching, Michael Stoll -/ 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_eq_iff (ψ : 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 set_option tactic.skipAssignedInstances false in simpa [changeLevel_def, Function.comp_apply, MonoidHom.coe_comp] using toUnitHom_eq_char' _ <| ZMod.IsUnit_cast_of_dvd hm a /-- `χ` 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) lemma changeLevel_one {d : ℕ} (h : d ∣ n) : changeLevel h (1 : DirichletCharacter R d) = 1 := by simp [changeLevel] 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 @[deprecated (since := "2024-06-16")] alias isPrimitive := IsPrimitive 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 isPritive_one_level_zero : IsPrimitive (1 : DirichletCharacter R 0) := conductor_eq_zero_iff_level_eq_zero.mpr rfl 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 _ @[deprecated (since := "2024-06-16")] alias isPrimitive.primitive_mul := primitive_mul_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 Odd.toUnitHom_eval_neg_one (hψ : ψ.Odd) : ψ.toUnitHom (-1) = -1 := by rw [← Units.eq_iff, MulChar.coe_toUnitHom] exact hψ lemma Even.toUnitHom_eval_neg_one (hψ : ψ.Even) : ψ.toUnitHom (-1) = 1 := by rw [← Units.eq_iff, 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ψ] end CommRing end DirichletCharacter
NumberTheory\DirichletCharacter\Bounds.lean
/- Copyright (c) 2023 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ 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
NumberTheory\DirichletCharacter\GaussSum.lean
/- Copyright (c) 2024 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ 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_left_eq_self] 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.eq_iff, 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.eq_iff, 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)
NumberTheory\EulerProduct\Basic.lean
/- Copyright (c) 2023 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.Analysis.Normed.Field.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*} [NormedField 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] [CompleteSpace R] {f : ℕ → R} variable (hf₁ : f 1 = 1) (hmul : ∀ {m n}, Nat.Coprime m n → f (m * n) = f m * f n) -- local instance to speed up typeclass search @[local instance] private lemma instT0Space : T0Space R := MetricSpace.instT0Space namespace EulerProduct /-- 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.filter Nat.Prime, ∑' n : ℕ, f (p ^ n)) := by induction' s using Finset.induction with p s hp ih · rw [factoredNumbers_empty] simp only [not_mem_empty, IsEmpty.forall_iff, forall_const, filter_true_of_mem, prod_empty] exact ⟨(Set.finite_singleton 1).summable (‖f ·‖), hf₁ ▸ hasSum_singleton 1 f⟩ · 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 ∉ s.filter Nat.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] /-- 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.filter Nat.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 [← tsum_subtype_add_tsum_subtype_compl hsum (factoredNumbers s), add_sub_cancel_left, tsum_eq_tsum_diff_singleton (factoredNumbers s)ᶜ hf₀] -- Versions of the three lemmas above for `smoothNumbers N` /-- 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 _ /-- 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 /-- 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) _ rw [hasProd_subtype_iff_mulIndicator, show Set.mulIndicator (fun p : ℕ ↦ Irreducible p) = {p | Nat.Prime p}.mulIndicator from rfl, HasProd, 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.filter Nat.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 /-- 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 /-- 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 [H] /-- 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.filter Nat.Prime, (1 - f p)⁻¹) := by have hmul {m n} (_ : Nat.Coprime m n) := f.map_mul m n have H₁ : ∏ p ∈ s.filter Nat.Prime, ∑' n : ℕ, f (p ^ n) = ∏ p ∈ s.filter Nat.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.filter Nat.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
NumberTheory\EulerProduct\DirichletLSeries.lean
/- Copyright (c) 2023 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.NumberTheory.DirichletCharacter.Bounds import Mathlib.NumberTheory.EulerProduct.Basic import Mathlib.NumberTheory.LSeries.Basic import Mathlib.NumberTheory.LSeries.RiemannZeta /-! # 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, Complex.norm_eq_abs, abs_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, tsum_eq_zero_add hsum.of_norm, 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 [LSeries, LSeries.term, dirichletSummandHom] refine tsum_congr (fun n ↦ ?_) rcases eq_or_ne n 0 with rfl | hn · simp only [map_zero, ↓reduceIte] · simp only [cpow_neg, MonoidWithZeroHom.coe_mk, ZeroHom.coe_mk, hn, ↓reduceIte, Field.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 dirichletLSeries_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 dirichletLSeries_eulerProduct_tprod {N : ℕ} (χ : DirichletCharacter ℂ N) (hs : 1 < s.re) : ∏' p : Primes, (1 - χ p * (p : ℂ) ^ (-s))⁻¹ = L ↗χ s := (dirichletLSeries_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 dirichletLSeries_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
NumberTheory\FLT\Basic.lean
/- Copyright (c) 2023 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Yaël Dillies -/ import Mathlib.Algebra.EuclideanDomain.Int import Mathlib.Algebra.GCDMonoid.Finset import Mathlib.Algebra.GCDMonoid.Nat import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.Order.Ring.Abs import Mathlib.Data.Rat.Defs import Mathlib.RingTheory.PrincipalIdealDomain import Mathlib.Tactic.NormNum import Mathlib.Tactic.Positivity.Basic import Mathlib.Tactic.TFAE /-! # 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 (α : Type*) [Semiring α] (n : ℕ) : Prop := ∀ a b c : α, 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 norm_num lemma not_fermatLastTheoremFor_one : ¬ FermatLastTheoremFor 1 := fun h ↦ h 1 1 2 (by norm_num) (by norm_num) (by norm_num) (by norm_num) lemma not_fermatLastTheoremFor_two : ¬ FermatLastTheoremFor 2 := fun h ↦ h 3 4 5 (by norm_num) (by norm_num) (by norm_num) (by norm_num) variable {α : Type*} [Semiring α] [NoZeroDivisors α] {m n : ℕ} lemma FermatLastTheoremWith.mono (hmn : m ∣ n) (hm : FermatLastTheoremWith α m) : FermatLastTheoremWith α 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 · rintro h a b c ha hb hc habc 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_lt <;> obtain hb | hb := hb.lt_or_lt <;> obtain hc | hc := hc.lt_or_lt · 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, habc, *] · exact (by positivity : 0 < c ^ n).not_lt <| 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, habc, 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, habc, neg_add_eq_iff_eq_add, eq_neg_add_iff_add_eq, *] · 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, habc, 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, habc, add_neg_eq_iff_eq_add, eq_add_neg_iff_add_eq, *] · exact (by positivity : 0 < a ^ n + b ^ n).not_lt <| 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, habc, *] tfae_have 2 → 3 · rintro h a b c ha hb hc habc 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 · rintro h a b c exact 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 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]
NumberTheory\FLT\Four.lean
/- Copyright (c) 2020 Paul van Wamelen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Paul van Wamelen -/ 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`. -/ 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.gcd_eq_one_iff_coprime.mp 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_ofNat] · 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 cases' Int.emod_two_eq_zero_or_one a0 with hap hap · cases' Int.emod_two_eq_zero_or_one b0 with hbp hbp · exfalso have h1 : 2 ∣ (Int.gcd a0 b0 : ℤ) := Int.dvd_gcd (Int.dvd_of_emod_eq_zero hap) (Int.dvd_of_emod_eq_zero hbp) rw [Int.gcd_eq_one_iff_coprime.mpr (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.coprime_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.coprime_of_sq_sum' {r s : ℤ} (h : IsCoprime r s) : IsCoprime (r ^ 2 + s ^ 2) (r * s) := by apply IsCoprime.mul_right (Int.coprime_of_sq_sum (isCoprime_comm.mp h)) rw [add_comm]; apply Int.coprime_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.gcd_eq_one_iff_coprime.mpr (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.gcd_eq_one_iff_coprime.mpr apply @IsCoprime.of_mul_left_left _ _ _ a rw [← sq, ht1, (by ring : m ^ 2 - n ^ 2 = m ^ 2 + -n * n)] exact (Int.gcd_eq_one_iff_coprime.mp 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 := mt pow_eq_zero h.1.2.1 have h4 : 0 < m := by apply lt_of_le_of_ne ht6 rintro rfl revert hb20 rw [ht2] simp 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.gcd_eq_one_iff_coprime.mpr (Int.coprime_of_sq_sum' (Int.gcd_eq_one_iff_coprime.mp 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) cases' hb2 with b' hb2' have hs : b' ^ 2 = m * (r * s) := by apply (mul_right_inj' (by norm_num : (4 : ℤ) ≠ 0)).mp linear_combination (-b - 2 * b') * hb2' + ht2 + 2 * m * htt2 have hrsz : r * s ≠ 0 := by -- because b ^ 2 is not zero and (b / 2) ^ 2 = m * (r * s) by_contra hrsz revert hb20 rw [ht2, htt2, mul_assoc, @mul_assoc _ _ _ r s, hrsz] simp have h2b0 : b' ≠ 0 := by apply ne_zero_pow two_ne_zero rw [hs] apply mul_ne_zero · exact ne_of_gt h4 · exact hrsz 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 intro h0 rw [h0, zero_pow two_ne_zero, neg_zero, or_self_iff] at hj apply left_ne_zero_of_mul hrsz hj 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 intro h0 rw [h0, zero_pow two_ne_zero, neg_zero, or_self_iff] at hk apply right_ne_zero_of_mul hrsz hk have hj2 : r ^ 2 = j ^ 4 := by cases' hj with hjp hjp <;> · rw [hjp] ring have hk2 : s ^ 2 = k ^ 4 := by cases' hk with hkp hkp <;> · rw [hkp] ring -- 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 rw [← hi, htt3, hj2, hk2] have hn : n ≠ 0 := by rw [ht2] at hb20 apply right_ne_zero_of_mul hb20 -- 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_zero_le (le_of_lt hc)] apply gt_of_gt_of_ge _ (Int.natAbs_le_self_sq i) rw [← hi, ht3] apply gt_of_gt_of_ge _ (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_lt 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
NumberTheory\FLT\Three.lean
/- Copyright (c) 2024 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca, Sanyam Gupta, Omar Haddad, David Lowry-Duda, Lorenzo Luccioli, Pietro Monticone, Alexis Saurin, Florent Schaffhauser -/ import Mathlib.NumberTheory.FLT.Basic import Mathlib.NumberTheory.Cyclotomic.PID import Mathlib.NumberTheory.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 norm_num) (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, abs_neg] 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 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, Insert.comm, 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, Insert.comm, 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 : multiplicity.Finite (hζ.toInteger - 1) S'.c := multiplicity.finite_of_not_isUnit hζ.zeta_sub_one_prime'.not_unit S'.hc section DecidableRel variable [DecidableRel fun (a b : 𝓞 K) ↦ a ∣ b] /-- Given `S' : Solution'`, `S'.multiplicity` is the multiplicity of `λ` in `S'.c`, as a natural number. -/ def Solution'.multiplicity := (_root_.multiplicity (hζ.toInteger - 1) S'.c).get (multiplicity_lambda_c_finite S') /-- Given `S : Solution`, `S.multiplicity` is the multiplicity of `λ` in `S.c`, as a natural number. -/ 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 /-- 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⟩⟩ end DecidableRel /-- 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 section DecidableRel variable [DecidableRel fun (a b : 𝓞 K) ↦ a ∣ b] /-- 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).get hm by obtain ⟨x, hx⟩ := multiplicity.pow_multiplicity_dvd hm refine ⟨λ ^ ((multiplicity ((hζ.toInteger - 1)) S'.c).get hm - 2) * x, ?_⟩ rw [← mul_assoc, ← pow_add] convert hx using 3 simp [this] have := lambda_pow_four_dvd_c_cube S' have hm1 : (multiplicity (hζ.toInteger - 1) (S'.c ^ 3)).get (multiplicity.finite_pow hζ.zeta_sub_one_prime' hm) = multiplicity (hζ.toInteger - 1) (S'.c ^ 3) := by simp rw [multiplicity.pow_dvd_iff_le_multiplicity, ← hm1, multiplicity.pow' hζ.zeta_sub_one_prime' hm, Nat.cast_ofNat, Nat.ofNat_le_cast] at this omega /-- Given `S' : Solution'`, we have that `2 ≤ S'.multiplicity`. -/ lemma Solution'.two_le_multiplicity : 2 ≤ S'.multiplicity := by simpa [← PartENat.coe_le_coe, Solution'.multiplicity] using multiplicity.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 DecidableRel end IsCyclotomicExtension /-- 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 DecidableRel variable [NumberField K] [IsCyclotomicExtension {3} ℚ K] [DecidableRel fun (a b : 𝓞 K) ↦ a ∣ b] open PartENat in /-- 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 [← multiplicity.multiplicity_lt_iff_not_dvd] at h1 h2 h3 have h1' : multiplicity.Finite (hζ.toInteger - 1) (S'.a + S'.b) := multiplicity.ne_top_iff_finite.1 (fun ht ↦ by simp [ht] at h1) have h2' : multiplicity.Finite (hζ.toInteger - 1) (S'.a + η * S'.b) := by refine multiplicity.ne_top_iff_finite.1 (fun ht ↦ ?_) rw [coe_eta] at ht simp [ht] at h2 have h3' : multiplicity.Finite (hζ.toInteger - 1) (S'.a + η ^ 2 * S'.b) := by refine multiplicity.ne_top_iff_finite.1 (fun ht ↦ ?_) rw [coe_eta] at ht simp [ht] at h3 replace h1' : (multiplicity (hζ.toInteger - 1) (S'.a + S'.b)).get h1' = multiplicity (hζ.toInteger - 1) (S'.a + S'.b) := by simp replace h2' : (multiplicity (hζ.toInteger - 1) (S'.a + η * S'.b)).get h2' = multiplicity (hζ.toInteger - 1) (S'.a + η * S'.b) := by simp replace h3' : (multiplicity (hζ.toInteger - 1) (S'.a + η ^ 2 * S'.b)).get h3' = multiplicity (hζ.toInteger - 1) (S'.a + η ^ 2 * S'.b) := by simp rw [← h1', coe_lt_coe] at h1; rw [← h2', coe_lt_coe] at h2; rw [← h3', coe_lt_coe] 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, multiplicity.pow_dvd_iff_le_multiplicity, multiplicity.mul hζ.zeta_sub_one_prime', multiplicity.mul hζ.zeta_sub_one_prime', ← h1', ← h2', ← h3', ← Nat.cast_add, ← Nat.cast_add, coe_le_coe] at this omega 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, ← val_pow_eq_pow_val, hζ.toInteger_cube_eq_one, val_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 DecidableRel 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 section DecidableRel variable [DecidableRel fun (a b : 𝓞 K) ↦ a ∣ b] /-- 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 := multiplicity.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 omega, 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 := (multiplicity.pow_multiplicity_dvd S.toSolution'.multiplicity_lambda_c_finite).choose private lemma w_spec : S.c = λ ^ S.multiplicity * S.w := (multiplicity.pow_multiplicity_dvd S.toSolution'.multiplicity_lambda_c_finite).choose_spec private lemma lambda_not_dvd_w : ¬ λ ∣ S.w := fun h ↦ by refine multiplicity.is_greatest' S.toSolution'.multiplicity_lambda_c_finite (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 omega, 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] end DecidableRel 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 [DecidableRel fun (a b : 𝓞 K) ↦ a ∣ b] : 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 [DecidableRel fun (a b : 𝓞 K) ↦ a ∣ b] : 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 _) variable [DecidableRel fun (a b : 𝓞 K) ↦ a ∣ b] 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 omega, 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 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 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 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 · field_simp [u₄_def] ring 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 norm_num) 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.unique' (by simp [Solution'_descent]) (fun h ↦ S.lambda_not_dvd_X ?_)).symm 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; omega /-- 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 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]
NumberTheory\Harmonic\Bounds.lean
/- Copyright (c) 2024 Arend Mellendijk. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Arend Mellendijk -/ import Mathlib.Analysis.SpecialFunctions.Integrals import Mathlib.Analysis.SumIntegralComparisons import Mathlib.NumberTheory.Harmonic.Defs /-! This file proves $\log(n+1) \le H_n \le 1 + \log(n)$ for all natural numbers $n$. -/ theorem log_add_one_le_harmonic (n : ℕ) : Real.log ↑(n+1) ≤ harmonic n := by calc _ = ∫ x in (1 : ℕ)..↑(n+1), x⁻¹ := ?_ _ ≤ ∑ d ∈ Finset.Icc 1 n, (d : ℝ)⁻¹ := ?_ _ = harmonic n := ?_ · rw [Nat.cast_one, integral_inv (by simp [(show ¬ (1 : ℝ) ≤ 0 by norm_num)]), div_one] · exact (inv_antitoneOn_Icc_right <| by norm_num).integral_le_sum_Ico (Nat.le_add_left 1 n) · simp only [harmonic_eq_sum_Icc, Rat.cast_sum, Rat.cast_inv, Rat.cast_natCast] theorem harmonic_le_one_add_log (n : ℕ) : harmonic n ≤ 1 + Real.log n := by by_cases hn0 : n = 0 · simp [hn0] have hn : 1 ≤ n := Nat.one_le_iff_ne_zero.mpr hn0 simp_rw [harmonic_eq_sum_Icc, Rat.cast_sum, Rat.cast_inv, Rat.cast_natCast] rw [← Finset.sum_erase_add (Finset.Icc 1 n) _ (Finset.left_mem_Icc.mpr hn), add_comm, Nat.cast_one, inv_one] refine add_le_add_left ?_ 1 simp only [Nat.lt_one_iff, Finset.mem_Icc, Finset.Icc_erase_left] calc ∑ d ∈ .Ico 2 (n + 1), (d : ℝ)⁻¹ _ = ∑ d ∈ .Ico 2 (n + 1), (↑(d + 1) - 1)⁻¹ := ?_ _ ≤ ∫ x in (2).. ↑(n + 1), (x - 1)⁻¹ := ?_ _ = ∫ x in (1)..n, x⁻¹ := ?_ _ = Real.log ↑n := ?_ · simp_rw [Nat.cast_add, Nat.cast_one, add_sub_cancel_right] · exact @AntitoneOn.sum_le_integral_Ico 2 (n + 1) (fun x : ℝ ↦ (x - 1)⁻¹) (by linarith [hn]) <| sub_inv_antitoneOn_Icc_right (by norm_num) · convert intervalIntegral.integral_comp_sub_right _ 1 · norm_num · simp only [Nat.cast_add, Nat.cast_one, add_sub_cancel_right] · convert integral_inv _ · rw [div_one] · simp only [Nat.one_le_cast, hn, Set.uIcc_of_le, Set.mem_Icc, Nat.cast_nonneg, and_true, not_le, zero_lt_one] theorem log_le_harmonic_floor (y : ℝ) (hy : 0 ≤ y) : Real.log y ≤ harmonic ⌊y⌋₊ := by by_cases h0 : y = 0 · simp [h0] · calc _ ≤ Real.log ↑(Nat.floor y + 1) := ?_ _ ≤ _ := log_add_one_le_harmonic _ gcongr apply (Nat.le_ceil y).trans norm_cast exact Nat.ceil_le_floor_add_one y theorem harmonic_floor_le_one_add_log (y : ℝ) (hy : 1 ≤ y) : harmonic ⌊y⌋₊ ≤ 1 + Real.log y := by refine (harmonic_le_one_add_log _).trans ?_ gcongr · exact_mod_cast Nat.floor_pos.mpr hy · exact Nat.floor_le <| zero_le_one.trans hy
NumberTheory\Harmonic\Defs.lean
/- Copyright (c) 2023 Koundinya Vajjha. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Koundinya Vajjha, Thomas Browning -/ import Mathlib.Algebra.BigOperators.Intervals import Mathlib.Algebra.Order.BigOperators.Ring.Finset import Mathlib.Algebra.Order.Field.Basic import Mathlib.Tactic.Linarith /-! This file defines the harmonic numbers. * `Mathilb/NumberTheory/Harmonic/Int.lean` proves that the `n`th harmonic number is not an integer. * `Mathlib/NumberTheory/Harmonic/Bounds.lean` provides basic log bounds. -/ /-- The nth-harmonic number defined as a finset sum of consecutive reciprocals. -/ def harmonic : ℕ → ℚ := fun n => ∑ i ∈ Finset.range n, (↑(i + 1))⁻¹ @[simp] lemma harmonic_zero : harmonic 0 = 0 := rfl @[simp] lemma harmonic_succ (n : ℕ) : harmonic (n + 1) = harmonic n + (↑(n + 1))⁻¹ := Finset.sum_range_succ .. lemma harmonic_pos {n : ℕ} (Hn : n ≠ 0) : 0 < harmonic n := by unfold harmonic rw [← Finset.nonempty_range_iff] at Hn positivity lemma harmonic_eq_sum_Icc {n : ℕ} : harmonic n = ∑ i ∈ Finset.Icc 1 n, (↑i)⁻¹ := by rw [harmonic, Finset.range_eq_Ico, Finset.sum_Ico_add' (fun (i : ℕ) ↦ (i : ℚ)⁻¹) 0 n (c := 1)] -- It might be better to restate `Nat.Ico_succ_right` in terms of `+ 1`, -- as we try to move away from `Nat.succ`. simp only [Nat.add_one, Nat.Ico_succ_right]
NumberTheory\Harmonic\EulerMascheroni.lean
/- Copyright (c) 2024 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.Data.Complex.ExponentialBounds import Mathlib.NumberTheory.Harmonic.Defs import Mathlib.Analysis.Normed.Order.Lattice import Mathlib.Analysis.SpecialFunctions.Pow.Real /-! # The Euler-Mascheroni constant `γ` We define the constant `γ`, and give upper and lower bounds for it. ## Main definitions and results * `Real.eulerMascheroniConstant`: the constant `γ` * `Real.tendsto_harmonic_sub_log`: the sequence `n ↦ harmonic n - log n` tends to `γ` as `n → ∞` * `one_half_lt_eulerMascheroniConstant` and `eulerMascheroniConstant_lt_two_thirds`: upper and lower bounds. ## Outline of proofs We show that * the sequence `eulerMascheroniSeq` given by `n ↦ harmonic n - log (n + 1)` is strictly increasing; * the sequence `eulerMascheroniSeq'` given by `n ↦ harmonic n - log n`, modified with a junk value for `n = 0`, is strictly decreasing; * the difference `eulerMascheroniSeq' n - eulerMascheroniSeq n` is non-negative and tends to 0. It follows that both sequences tend to a common limit `γ`, and we have the inequality `eulerMascheroniSeq n < γ < eulerMascheroniSeq' n` for all `n`. Taking `n = 6` gives the bounds `1 / 2 < γ < 2 / 3`. -/ open Filter Topology namespace Real section LowerSequence /-- The sequence with `n`-th term `harmonic n - log (n + 1)`. -/ noncomputable def eulerMascheroniSeq (n : ℕ) : ℝ := harmonic n - log (n + 1) lemma eulerMascheroniSeq_zero : eulerMascheroniSeq 0 = 0 := by simp [eulerMascheroniSeq, harmonic_zero] lemma strictMono_eulerMascheroniSeq : StrictMono eulerMascheroniSeq := by refine strictMono_nat_of_lt_succ (fun n ↦ ?_) rw [eulerMascheroniSeq, eulerMascheroniSeq, ← sub_pos, sub_sub_sub_comm, harmonic_succ, add_comm, Rat.cast_add, add_sub_cancel_right, ← log_div (by positivity) (by positivity), add_div, Nat.cast_add_one, Nat.cast_add_one, div_self (by positivity), sub_pos, one_div, Rat.cast_inv, Rat.cast_add, Rat.cast_one, Rat.cast_natCast] refine (log_lt_sub_one_of_pos ?_ (ne_of_gt <| lt_add_of_pos_right _ ?_)).trans_le (le_of_eq ?_) · positivity · positivity · simp only [add_sub_cancel_left] lemma one_half_lt_eulerMascheroniSeq_six : 1 / 2 < eulerMascheroniSeq 6 := by have : eulerMascheroniSeq 6 = 49 / 20 - log 7 := by rw [eulerMascheroniSeq] norm_num rw [this, lt_sub_iff_add_lt, ← lt_sub_iff_add_lt', log_lt_iff_lt_exp (by positivity)] refine lt_of_lt_of_le ?_ (Real.sum_le_exp_of_nonneg (by norm_num) 7) simp_rw [Finset.sum_range_succ, Nat.factorial_succ] norm_num end LowerSequence section UpperSequence /-- The sequence with `n`-th term `harmonic n - log n`. We use a junk value for `n = 0`, in order to have the sequence be strictly decreasing. -/ noncomputable def eulerMascheroniSeq' (n : ℕ) : ℝ := if n = 0 then 2 else ↑(harmonic n) - log n lemma eulerMascheroniSeq'_one : eulerMascheroniSeq' 1 = 1 := by simp [eulerMascheroniSeq'] lemma strictAnti_eulerMascheroniSeq' : StrictAnti eulerMascheroniSeq' := by refine strictAnti_nat_of_succ_lt (fun n ↦ ?_) rcases Nat.eq_zero_or_pos n with rfl | hn · simp [eulerMascheroniSeq'] simp_rw [eulerMascheroniSeq', eq_false_intro hn.ne', if_false] rw [← sub_pos, sub_sub_sub_comm, harmonic_succ, Rat.cast_add, ← sub_sub, sub_self, zero_sub, sub_eq_add_neg, neg_sub, ← sub_eq_neg_add, sub_pos, ← log_div (by positivity) (by positivity), ← neg_lt_neg_iff, ← log_inv] refine (log_lt_sub_one_of_pos ?_ ?_).trans_le (le_of_eq ?_) · positivity · field_simp · field_simp lemma eulerMascheroniSeq'_six_lt_two_thirds : eulerMascheroniSeq' 6 < 2 / 3 := by have h1 : eulerMascheroniSeq' 6 = 49 / 20 - log 6 := by rw [eulerMascheroniSeq'] norm_num rw [h1, sub_lt_iff_lt_add, ← sub_lt_iff_lt_add', lt_log_iff_exp_lt (by positivity)] norm_num have := rpow_lt_rpow (exp_pos _).le exp_one_lt_d9 (by norm_num : (0 : ℝ) < 107 / 60) rw [exp_one_rpow] at this refine lt_trans this ?_ rw [← rpow_lt_rpow_iff (z := 60), ← rpow_mul, div_mul_cancel₀, ← Nat.cast_ofNat, ← Nat.cast_ofNat, rpow_natCast, Nat.cast_ofNat, ← Nat.cast_ofNat (n := 60), rpow_natCast] · norm_num all_goals positivity lemma eulerMascheroniSeq_lt_eulerMascheroniSeq' (m n : ℕ) : eulerMascheroniSeq m < eulerMascheroniSeq' n := by have (r : ℕ) : eulerMascheroniSeq r < eulerMascheroniSeq' r := by rcases eq_zero_or_pos r with rfl | hr · simp [eulerMascheroniSeq, eulerMascheroniSeq'] simp only [eulerMascheroniSeq, eulerMascheroniSeq', hr.ne', if_false] gcongr linarith apply (strictMono_eulerMascheroniSeq.monotone (le_max_left m n)).trans_lt exact (this _).trans_le (strictAnti_eulerMascheroniSeq'.antitone (le_max_right m n)) end UpperSequence /-- The Euler-Mascheroni constant `γ`. -/ noncomputable def eulerMascheroniConstant : ℝ := limUnder atTop eulerMascheroniSeq lemma tendsto_eulerMascheroniSeq : Tendsto eulerMascheroniSeq atTop (𝓝 eulerMascheroniConstant) := by have := tendsto_atTop_ciSup strictMono_eulerMascheroniSeq.monotone ?_ · rwa [eulerMascheroniConstant, this.limUnder_eq] · exact ⟨_, fun _ ⟨_, hn⟩ ↦ hn ▸ (eulerMascheroniSeq_lt_eulerMascheroniSeq' _ 1).le⟩ lemma tendsto_harmonic_sub_log_add_one : Tendsto (fun n : ℕ ↦ harmonic n - log (n + 1)) atTop (𝓝 eulerMascheroniConstant) := tendsto_eulerMascheroniSeq lemma tendsto_eulerMascheroniSeq' : Tendsto eulerMascheroniSeq' atTop (𝓝 eulerMascheroniConstant) := by suffices Tendsto (fun n ↦ eulerMascheroniSeq' n - eulerMascheroniSeq n) atTop (𝓝 0) by simpa using this.add tendsto_eulerMascheroniSeq suffices Tendsto (fun x : ℝ ↦ log (x + 1) - log x) atTop (𝓝 0) by apply (this.comp tendsto_natCast_atTop_atTop).congr' filter_upwards [eventually_ne_atTop 0] with n hn simp [eulerMascheroniSeq, eulerMascheroniSeq', eq_false_intro hn] suffices Tendsto (fun x : ℝ ↦ log (1 + 1 / x)) atTop (𝓝 0) by apply this.congr' filter_upwards [eventually_gt_atTop 0] with x hx rw [← log_div (by positivity) (by positivity), add_div, div_self hx.ne'] simpa only [add_zero, log_one] using ((tendsto_const_nhds.div_atTop tendsto_id).const_add 1).log (by positivity) lemma tendsto_harmonic_sub_log : Tendsto (fun n : ℕ ↦ harmonic n - log n) atTop (𝓝 eulerMascheroniConstant) := by apply tendsto_eulerMascheroniSeq'.congr' filter_upwards [eventually_ne_atTop 0] with n hn simp_rw [eulerMascheroniSeq', hn, if_false] lemma eulerMascheroniSeq_lt_eulerMascheroniConstant (n : ℕ) : eulerMascheroniSeq n < eulerMascheroniConstant := by refine (strictMono_eulerMascheroniSeq (Nat.lt_succ_self n)).trans_le ?_ apply strictMono_eulerMascheroniSeq.monotone.ge_of_tendsto tendsto_eulerMascheroniSeq lemma eulerMascheroniConstant_lt_eulerMascheroniSeq' (n : ℕ) : eulerMascheroniConstant < eulerMascheroniSeq' n := by refine lt_of_le_of_lt ?_ (strictAnti_eulerMascheroniSeq' (Nat.lt_succ_self n)) apply strictAnti_eulerMascheroniSeq'.antitone.le_of_tendsto tendsto_eulerMascheroniSeq' /-- Lower bound for `γ`. (The true value is about 0.57.) -/ lemma one_half_lt_eulerMascheroniConstant : 1 / 2 < eulerMascheroniConstant := one_half_lt_eulerMascheroniSeq_six.trans (eulerMascheroniSeq_lt_eulerMascheroniConstant _) /-- Upper bound for `γ`. (The true value is about 0.57.) -/ lemma eulerMascheroniConstant_lt_two_thirds : eulerMascheroniConstant < 2 / 3 := (eulerMascheroniConstant_lt_eulerMascheroniSeq' _).trans eulerMascheroniSeq'_six_lt_two_thirds end Real
NumberTheory\Harmonic\GammaDeriv.lean
/- Copyright (c) 2024 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.NumberTheory.Harmonic.EulerMascheroni import Mathlib.Analysis.SpecialFunctions.Gamma.Deligne import Mathlib.Data.Nat.Factorial.Basic /-! # Derivative of Γ at positive integers We prove the formula for the derivative of `Real.Gamma` at a positive integer: `deriv Real.Gamma (n + 1) = Nat.factorial n * (-Real.eulerMascheroniConstant + harmonic n)` -/ open Nat Set Filter Topology local notation "γ" => Real.eulerMascheroniConstant namespace Real /-- Explicit formula for the derivative of the Gamma function at positive integers, in terms of harmonic numbers and the Euler-Mascheroni constant `γ`. -/ lemma deriv_Gamma_nat (n : ℕ) : deriv Gamma (n + 1) = n ! * (-γ + harmonic n) := by /- This follows from two properties of the function `f n = log (Gamma n)`: firstly, the elementary computation that `deriv f (n + 1) = deriv f n + 1 / n`, so that `deriv f n = deriv f 1 + harmonic n`; secondly, the convexity of `f` (the Bohr-Mollerup theorem), which shows that `deriv f n` is `log n + o(1)` as `n → ∞`. `-/ let f := log ∘ Gamma -- First reduce to computing derivative of `log ∘ Gamma`. suffices deriv (log ∘ Gamma) (n + 1) = -γ + harmonic n by rwa [Function.comp_def, deriv.log (differentiableAt_Gamma (fun m ↦ by linarith)) (by positivity), Gamma_nat_eq_factorial, div_eq_iff_mul_eq (by positivity), mul_comm, Eq.comm] at this have hc : ConvexOn ℝ (Ioi 0) f := convexOn_log_Gamma have h_rec (x : ℝ) (hx : 0 < x) : f (x + 1) = f x + log x := by simp only [f, Function.comp_apply, Gamma_add_one hx.ne', log_mul hx.ne' (Gamma_pos_of_pos hx).ne', add_comm] have hder {x : ℝ} (hx : 0 < x) : DifferentiableAt ℝ f x := by refine ((differentiableAt_Gamma ?_).log (Gamma_ne_zero ?_)) <;> exact fun m ↦ ne_of_gt (by linarith) -- Express derivative at general `n` in terms of value at `1` using recurrence relation have hder_rec (x : ℝ) (hx : 0 < x) : deriv f (x + 1) = deriv f x + 1 / x := by rw [← deriv_comp_add_const _ _ (hder <| by positivity), one_div, ← deriv_log, ← deriv_add (hder <| by positivity) (differentiableAt_log hx.ne')] apply EventuallyEq.deriv_eq filter_upwards [eventually_gt_nhds hx] using h_rec have hder_nat (n : ℕ) : deriv f (n + 1) = deriv f 1 + harmonic n := by induction' n with n hn · simp · rw [cast_succ, hder_rec (n + 1) (by positivity), hn, harmonic_succ] push_cast ring suffices -deriv f 1 = γ by rw [hder_nat n, ← this, neg_neg] -- Use convexity to show derivative of `f` at `n + 1` is between `log n` and `log (n + 1)` have derivLB (n : ℕ) (hn : 0 < n) : log n ≤ deriv f (n + 1) := by refine (le_of_eq ?_).trans <| hc.slope_le_deriv (mem_Ioi.mpr <| Nat.cast_pos.mpr hn) (by positivity : _ < (_ : ℝ)) (by linarith) (hder <| by positivity) rw [slope_def_field, show n + 1 - n = (1 : ℝ) by ring, div_one, h_rec n (by positivity), add_sub_cancel_left] have derivUB (n : ℕ) : deriv f (n + 1) ≤ log (n + 1) := by refine (hc.deriv_le_slope (by positivity : (0 : ℝ) < n + 1) (by positivity : (0 : ℝ) < n + 2) (by linarith) (hder <| by positivity)).trans (le_of_eq ?_) rw [slope_def_field, show n + 2 - (n + 1) = (1 : ℝ) by ring, div_one, show n + 2 = (n + 1) + (1 : ℝ) by ring, h_rec (n + 1) (by positivity), add_sub_cancel_left] -- deduce `-deriv f 1` is bounded above + below by sequences which both tend to `γ` apply le_antisymm · apply ge_of_tendsto tendsto_harmonic_sub_log filter_upwards [eventually_gt_atTop 0] with n hn rw [le_sub_iff_add_le', ← sub_eq_add_neg, sub_le_iff_le_add', ← hder_nat] exact derivLB n hn · apply le_of_tendsto tendsto_harmonic_sub_log_add_one filter_upwards with n rw [sub_le_iff_le_add', ← sub_eq_add_neg, le_sub_iff_add_le', ← hder_nat] exact derivUB n lemma hasDerivAt_Gamma_nat (n : ℕ) : HasDerivAt Gamma (n ! * (-γ + harmonic n)) (n + 1) := (deriv_Gamma_nat n).symm ▸ (differentiableAt_Gamma fun m ↦ (by linarith : (n : ℝ) + 1 ≠ -m)).hasDerivAt lemma eulerMascheroniConstant_eq_neg_deriv : γ = -deriv Gamma 1 := by rw [show (1 : ℝ) = ↑(0 : ℕ) + 1 by simp, deriv_Gamma_nat 0] simp lemma hasDerivAt_Gamma_one : HasDerivAt Gamma (-γ) 1 := by simpa only [factorial_zero, cast_one, harmonic_zero, Rat.cast_zero, add_zero, mul_neg, one_mul, cast_zero, zero_add] using hasDerivAt_Gamma_nat 0 lemma hasDerivAt_Gamma_one_half : HasDerivAt Gamma (-√π * (γ + 2 * log 2)) (1 / 2) := by have h_diff {s : ℝ} (hs : 0 < s) : DifferentiableAt ℝ Gamma s := differentiableAt_Gamma fun m ↦ ((neg_nonpos.mpr m.cast_nonneg).trans_lt hs).ne' have h_diff' {s : ℝ} (hs : 0 < s) : DifferentiableAt ℝ (fun s ↦ Gamma (2 * s)) s := .comp (g := Gamma) _ (h_diff <| mul_pos two_pos hs) (differentiableAt_id.const_mul _) refine (h_diff one_half_pos).hasDerivAt.congr_deriv ?_ -- We calculate the deriv of Gamma at 1/2 using the doubling formula, since we already know -- the derivative of Gamma at 1. calc deriv Gamma (1 / 2) _ = (deriv (fun s ↦ Gamma s * Gamma (s + 1 / 2)) (1 / 2)) + √π * γ := by rw [deriv_mul, Gamma_one_half_eq, add_assoc, ← mul_add, deriv_comp_add_const, (by norm_num : 1/2 + 1/2 = (1 : ℝ)), Gamma_one, mul_one, eulerMascheroniConstant_eq_neg_deriv, add_neg_self, mul_zero, add_zero] · apply h_diff; norm_num -- s = 1 · apply h_diff; norm_num -- s = 1/2 · exact ((h_diff (by norm_num)).hasDerivAt.comp_add_const).differentiableAt -- s = 1 _ = (deriv (fun s ↦ Gamma (2 * s) * 2 ^ (1 - 2 * s) * √π) (1 / 2)) + √π * γ := by rw [funext Gamma_mul_Gamma_add_half] _ = √π * (deriv (fun s ↦ Gamma (2 * s) * 2 ^ (1 - 2 * s)) (1 / 2) + γ) := by rw [mul_comm √π, mul_comm √π, deriv_mul_const, add_mul] apply DifferentiableAt.mul · exact .comp (g := Gamma) _ (by apply h_diff; norm_num) -- s = 1 (differentiableAt_id.const_mul _) · exact (differentiableAt_const _).rpow (by fun_prop) two_ne_zero _ = √π * (deriv (fun s ↦ Gamma (2 * s)) (1 / 2) + deriv (fun s : ℝ ↦ 2 ^ (1 - 2 * s)) (1 / 2) + γ) := by congr 2 rw [deriv_mul] · congr 1 <;> norm_num · exact h_diff' one_half_pos · exact DifferentiableAt.rpow (by fun_prop) (by fun_prop) two_ne_zero _ = √π * (-2 * γ + deriv (fun s : ℝ ↦ 2 ^ (1 - 2 * s)) (1 / 2) + γ) := by congr 3 change deriv (Gamma ∘ fun s ↦ 2 * s) _ = _ rw [deriv.comp, deriv_const_mul, mul_one_div, div_self two_ne_zero, deriv_id''] <;> dsimp only · rw [mul_one, mul_comm, hasDerivAt_Gamma_one.deriv, mul_neg, neg_mul] · fun_prop · apply h_diff; norm_num -- s = 1 · fun_prop _ = √π * (-2 * γ + -(2 * log 2) + γ) := by congr 3 apply HasDerivAt.deriv have := HasDerivAt.rpow (hasDerivAt_const (1 / 2 : ℝ) (2 : ℝ)) (?_ : HasDerivAt (fun s : ℝ ↦ 1 - 2 * s) (-2) (1 / 2)) two_pos · norm_num at this; exact this simp_rw [mul_comm (2 : ℝ) _] apply HasDerivAt.const_sub exact hasDerivAt_mul_const (2 : ℝ) _ = -√π * (γ + 2 * log 2) := by ring end Real namespace Complex open scoped Real private lemma HasDerivAt.complex_of_real {f : ℂ → ℂ} {g : ℝ → ℝ} {g' s : ℝ} (hf : DifferentiableAt ℂ f s) (hg : HasDerivAt g g' s) (hfg : ∀ s : ℝ, f ↑s = ↑(g s)) : HasDerivAt f ↑g' s := by refine HasDerivAt.congr_deriv hf.hasDerivAt ?_ rw [← (funext hfg ▸ hf.hasDerivAt.comp_ofReal.deriv :)] exact hg.ofReal_comp.deriv lemma differentiable_at_Gamma_nat_add_one (n : ℕ) : DifferentiableAt ℂ Gamma (n + 1) := by refine differentiableAt_Gamma _ (fun m ↦ ?_) simp only [Ne, ← ofReal_natCast, ← ofReal_one, ← ofReal_add, ← ofReal_neg, ofReal_inj, eq_neg_iff_add_eq_zero] positivity lemma hasDerivAt_Gamma_nat (n : ℕ) : HasDerivAt Gamma (n ! * (-γ + harmonic n)) (n + 1) := by exact_mod_cast HasDerivAt.complex_of_real (by exact_mod_cast differentiable_at_Gamma_nat_add_one n) (Real.hasDerivAt_Gamma_nat n) Gamma_ofReal /-- Explicit formula for the derivative of the complex Gamma function at positive integers, in terms of harmonic numbers and the Euler-Mascheroni constant `γ`. -/ lemma deriv_Gamma_nat (n : ℕ) : deriv Gamma (n + 1) = n ! * (-γ + harmonic n) := (hasDerivAt_Gamma_nat n).deriv lemma hasDerivAt_Gamma_one : HasDerivAt Gamma (-γ) 1 := by simpa only [factorial_zero, cast_one, harmonic_zero, Rat.cast_zero, add_zero, mul_neg, one_mul, cast_zero, zero_add] using hasDerivAt_Gamma_nat 0 lemma hasDerivAt_Gamma_one_half : HasDerivAt Gamma (-√π * (γ + 2 * log 2)) (1 / 2) := by have := HasDerivAt.complex_of_real (differentiableAt_Gamma _ ?_) Real.hasDerivAt_Gamma_one_half Gamma_ofReal · simpa only [neg_mul, one_div, ofReal_neg, ofReal_mul, ofReal_add, ofReal_ofNat, ofNat_log, ofReal_inv] using this · intro m rw [← ofReal_natCast, ← ofReal_neg, ne_eq, ofReal_inj] exact ((neg_nonpos.mpr m.cast_nonneg).trans_lt one_half_pos).ne' lemma hasDerivAt_Gammaℂ_one : HasDerivAt Gammaℂ (-(γ + log (2 * π)) / π) 1 := by let f (s : ℂ) : ℂ := 2 * (2 * π) ^ (-s) have : HasDerivAt (fun s : ℂ ↦ 2 * (2 * π : ℂ) ^ (-s)) (-log (2 * π) / π) 1 := by have := (hasDerivAt_neg' (1 : ℂ)).const_cpow (c := 2 * π) (Or.inl (by exact_mod_cast Real.two_pi_pos.ne')) refine (this.const_mul 2).congr_deriv ?_ rw [mul_neg_one, mul_neg, cpow_neg_one, ← div_eq_inv_mul, ← mul_div_assoc, mul_div_mul_left _ _ two_ne_zero, neg_div] have := this.mul hasDerivAt_Gamma_one simp only [f] at this rwa [Gamma_one, mul_one, cpow_neg_one, ← div_eq_mul_inv, ← div_div, div_self two_ne_zero, mul_comm (1 / _), mul_one_div, ← _root_.add_div, ← neg_add, add_comm] at this lemma hasDerivAt_Gammaℝ_one : HasDerivAt Gammaℝ (-(γ + log (4 * π)) / 2) 1 := by let f (s : ℂ) : ℂ := π ^ (-s / 2) let g (s : ℂ) : ℂ := Gamma (s / 2) have aux : (π : ℂ) ^ (1 / 2 : ℂ) = ↑√π := by rw [Real.sqrt_eq_rpow, ofReal_cpow Real.pi_pos.le, ofReal_div, ofReal_one, ofReal_ofNat] have aux2 : (√π : ℂ) ≠ 0 := by rw [ofReal_ne_zero]; positivity have hf : HasDerivAt f (-log π / 2 / √π) 1 := by have := ((hasDerivAt_neg (1 : ℂ)).div_const 2).const_cpow (c := π) (Or.inr (by norm_num)) refine this.congr_deriv ?_ rw [mul_assoc, ← mul_div_assoc, mul_neg_one, neg_div, cpow_neg, ← div_eq_inv_mul, aux] have hg : HasDerivAt g (-√π * (γ + 2 * log 2) / 2) 1 := by have := hasDerivAt_Gamma_one_half.comp 1 (?_ : HasDerivAt (fun s : ℂ ↦ s / 2) (1 / 2) 1) · rwa [mul_one_div] at this · exact (hasDerivAt_id _).div_const _ refine HasDerivAt.congr_deriv (hf.mul hg) ?_ simp only [f] rw [Gamma_one_half_eq, aux, div_mul_cancel₀ _ aux2, neg_div _ (1 : ℂ), cpow_neg, aux, mul_div_assoc, ← mul_assoc, mul_neg, inv_mul_cancel aux2, neg_one_mul, ← neg_div, ← _root_.add_div, ← neg_add, add_comm, add_assoc, ← ofReal_log Real.pi_pos.le, ← ofReal_ofNat, ← ofReal_log zero_le_two, ← ofReal_mul, ← Nat.cast_ofNat (R := ℝ), ← Real.log_pow, ← ofReal_add, ← Real.log_mul (by positivity) (by positivity), Nat.cast_ofNat, ofReal_ofNat, ofReal_log (by positivity)] norm_num end Complex
NumberTheory\Harmonic\Int.lean
/- Copyright (c) 2023 Koundinya Vajjha. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Koundinya Vajjha, Thomas Browning -/ import Mathlib.NumberTheory.Harmonic.Defs import Mathlib.NumberTheory.Padics.PadicNumbers /-! The nth Harmonic number is not an integer. We formalize the proof using 2-adic valuations. This proof is due to Kürschák. Reference: https://kconrad.math.uconn.edu/blurbs/gradnumthy/padicharmonicsum.pdf -/ /-- The 2-adic valuation of the n-th harmonic number is the negative of the logarithm of n. -/ theorem padicValRat_two_harmonic (n : ℕ) : padicValRat 2 (harmonic n) = -Nat.log 2 n := by induction' n with n ih · simp · rcases eq_or_ne n 0 with rfl | hn · simp rw [harmonic_succ] have key : padicValRat 2 (harmonic n) ≠ padicValRat 2 (↑(n + 1))⁻¹ := by rw [ih, padicValRat.inv, padicValRat.of_nat, Ne, neg_inj, Nat.cast_inj] exact Nat.log_ne_padicValNat_succ hn rw [padicValRat.add_eq_min (harmonic_succ n ▸ (harmonic_pos n.succ_ne_zero).ne') (harmonic_pos hn).ne' (inv_ne_zero (Nat.cast_ne_zero.mpr n.succ_ne_zero)) key, ih, padicValRat.inv, padicValRat.of_nat, min_neg_neg, neg_inj, ← Nat.cast_max, Nat.cast_inj] exact Nat.max_log_padicValNat_succ_eq_log_succ n /-- The 2-adic norm of the n-th harmonic number is 2 raised to the logarithm of n in base 2. -/ lemma padicNorm_two_harmonic {n : ℕ} (hn : n ≠ 0) : ‖(harmonic n : ℚ_[2])‖ = 2 ^ (Nat.log 2 n) := by rw [padicNormE.eq_padicNorm, padicNorm.eq_zpow_of_nonzero (harmonic_pos hn).ne', padicValRat_two_harmonic, neg_neg, zpow_natCast, Rat.cast_pow, Rat.cast_natCast, Nat.cast_ofNat] /-- The n-th harmonic number is not an integer for n ≥ 2. -/ theorem harmonic_not_int {n : ℕ} (h : 2 ≤ n) : ¬ (harmonic n).isInt := by apply padicNorm.not_int_of_not_padic_int 2 rw [padicNorm.eq_zpow_of_nonzero (harmonic_pos (ne_zero_of_lt h)).ne', padicValRat_two_harmonic, neg_neg, zpow_natCast] exact one_lt_pow one_lt_two (Nat.log_pos one_lt_two h).ne'
NumberTheory\Harmonic\ZetaAsymp.lean
/- Copyright (c) 2024 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.NumberTheory.LSeries.RiemannZeta import Mathlib.NumberTheory.Harmonic.GammaDeriv /-! # Asymptotics of `ζ s` as `s → 1` The goal of this file is to evaluate the limit of `ζ s - 1 / (s - 1)` as `s → 1`. ### Main results * `tendsto_riemannZeta_sub_one_div`: the limit of `ζ s - 1 / (s - 1)`, at the filter of punctured neighbourhoods of 1 in `ℂ`, exists and is equal to the Euler-Mascheroni constant `γ`. * `riemannZeta_one_ne_zero`: with our definition of `ζ 1` (which is characterised as the limit of `ζ s - 1 / (s - 1) / Gammaℝ s` as `s → 1`), we have `ζ 1 ≠ 0`. ### Outline of arguments We consider the sum `F s = ∑' n : ℕ, f (n + 1) s`, where `s` is a real variable and `f n s = ∫ x in n..(n + 1), (x - n) / x ^ (s + 1)`. We show that `F s` is continuous on `[1, ∞)`, that `F 1 = 1 - γ`, and that `F s = 1 / (s - 1) - ζ s / s` for `1 < s`. By combining these formulae, one deduces that the limit of `ζ s - 1 / (s - 1)` at `𝓝[>] (1 : ℝ)` exists and is equal to `γ`. Finally, using this and the Riemann removable singularity criterion we obtain the limit along punctured neighbourhoods of 1 in `ℂ`. -/ open Real Set MeasureTheory Filter Topology @[inherit_doc] local notation "γ" => eulerMascheroniConstant namespace ZetaAsymptotics -- since the intermediate lemmas are of little interest in themselves we put them in a namespace /-! ## Definitions -/ /-- Auxiliary function used in studying zeta-function asymptotics. -/ noncomputable def term (n : ℕ) (s : ℝ) : ℝ := ∫ x : ℝ in n..(n + 1), (x - n) / x ^ (s + 1) /-- Sum of finitely many `term`s. -/ noncomputable def term_sum (s : ℝ) (N : ℕ) : ℝ := ∑ n ∈ Finset.range N, term (n + 1) s /-- Topological sum of `term`s. -/ noncomputable def term_tsum (s : ℝ) : ℝ := ∑' n, term (n + 1) s lemma term_nonneg (n : ℕ) (s : ℝ) : 0 ≤ term n s := by rw [term, intervalIntegral.integral_of_le (by simp)] refine setIntegral_nonneg measurableSet_Ioc (fun x hx ↦ ?_) refine div_nonneg ?_ (rpow_nonneg ?_ _) all_goals linarith [hx.1] lemma term_welldef {n : ℕ} (hn : 0 < n) {s : ℝ} (hs : 0 < s) : IntervalIntegrable (fun x : ℝ ↦ (x - n) / x ^ (s + 1)) volume n (n + 1) := by rw [intervalIntegrable_iff_integrableOn_Icc_of_le (by linarith)] refine (ContinuousAt.continuousOn fun x hx ↦ ContinuousAt.div ?_ ?_ ?_).integrableOn_Icc · fun_prop · apply continuousAt_id.rpow_const (Or.inr <| by linarith) · exact (rpow_pos_of_pos ((Nat.cast_pos.mpr hn).trans_le hx.1) _).ne' section s_eq_one /-! ## Evaluation of the sum for `s = 1` -/ lemma term_one {n : ℕ} (hn : 0 < n) : term n 1 = (log (n + 1) - log n) - 1 / (n + 1) := by have hv : ∀ x ∈ uIcc (n : ℝ) (n + 1), 0 < x := by intro x hx rw [uIcc_of_le (by simp only [le_add_iff_nonneg_right, zero_le_one])] at hx exact (Nat.cast_pos.mpr hn).trans_le hx.1 calc term n 1 _ = ∫ x : ℝ in n..(n + 1), (x - n) / x ^ 2 := by simp_rw [term, one_add_one_eq_two, ← Nat.cast_two (R := ℝ), rpow_natCast] _ = ∫ x : ℝ in n..(n + 1), (1 / x - n / x ^ 2) := by refine intervalIntegral.integral_congr (fun x hx ↦ ?_) field_simp [(hv x hx).ne'] ring _ = (∫ x : ℝ in n..(n + 1), 1 / x) - n * ∫ x : ℝ in n..(n + 1), 1 / x ^ 2 := by simp_rw [← mul_one_div (n : ℝ)] rw [intervalIntegral.integral_sub] · simp_rw [intervalIntegral.integral_const_mul] · exact intervalIntegral.intervalIntegrable_one_div (fun x hx ↦ (hv x hx).ne') (by fun_prop) · exact (intervalIntegral.intervalIntegrable_one_div (fun x hx ↦ (sq_pos_of_pos (hv x hx)).ne') (by fun_prop)).const_mul _ _ = (log (↑n + 1) - log ↑n) - n * ∫ x : ℝ in n..(n + 1), 1 / x ^ 2 := by congr 1 rw [integral_one_div_of_pos, log_div] all_goals positivity _ = (log (↑n + 1) - log ↑n) - n * ∫ x : ℝ in n..(n + 1), x ^ (-2 : ℝ) := by congr 2 refine intervalIntegral.integral_congr (fun x hx ↦ ?_) rw [rpow_neg, one_div, ← Nat.cast_two (R := ℝ), rpow_natCast] exact (hv x hx).le _ = log (↑n + 1) - log ↑n - n * (1 / n - 1 / (n + 1)) := by rw [integral_rpow] · simp_rw [sub_div, (by norm_num : (-2 : ℝ) + 1 = -1), div_neg, div_one, neg_sub_neg, rpow_neg_one, ← one_div] · refine Or.inr ⟨by norm_num, not_mem_uIcc_of_lt ?_ ?_⟩ all_goals positivity _ = log (↑n + 1) - log ↑n - 1 / (↑n + 1) := by congr 1 field_simp lemma term_sum_one (N : ℕ) : term_sum 1 N = log (N + 1) - harmonic (N + 1) + 1 := by induction' N with N hN · simp_rw [term_sum, Finset.sum_range_zero, harmonic_succ, harmonic_zero, Nat.cast_zero, zero_add, Nat.cast_one, inv_one, Rat.cast_one, log_one, sub_add_cancel] · unfold term_sum at hN ⊢ rw [Finset.sum_range_succ, hN, harmonic_succ (N + 1), term_one (by positivity : 0 < N + 1)] push_cast ring_nf /-- The topological sum of `ZetaAsymptotics.term (n + 1) 1` over all `n : ℕ` is `1 - γ`. This is proved by directly evaluating the sum of the first `N` terms and using the limit definition of `γ`. -/ lemma term_tsum_one : HasSum (fun n ↦ term (n + 1) 1) (1 - γ) := by rw [hasSum_iff_tendsto_nat_of_nonneg (fun n ↦ term_nonneg (n + 1) 1)] show Tendsto (fun N ↦ term_sum 1 N) atTop _ simp_rw [term_sum_one, sub_eq_neg_add] refine Tendsto.add ?_ tendsto_const_nhds have := (tendsto_eulerMascheroniSeq'.comp (tendsto_add_atTop_nat 1)).neg refine this.congr' (eventually_of_forall (fun n ↦ ?_)) simp_rw [Function.comp_apply, eulerMascheroniSeq', if_false] push_cast abel end s_eq_one section s_gt_one /-! ## Evaluation of the sum for `1 < s` -/ lemma term_of_lt {n : ℕ} (hn : 0 < n) {s : ℝ} (hs : 1 < s) : term n s = 1 / (s - 1) * (1 / n ^ (s - 1) - 1 / (n + 1) ^ (s - 1)) - n / s * (1 / n ^ s - 1 / (n + 1) ^ s) := by have hv : ∀ x ∈ uIcc (n : ℝ) (n + 1), 0 < x := by intro x hx rw [uIcc_of_le (by simp only [le_add_iff_nonneg_right, zero_le_one])] at hx exact (Nat.cast_pos.mpr hn).trans_le hx.1 calc term n s _ = ∫ x : ℝ in n..(n + 1), (x - n) / x ^ (s + 1) := by rfl _ = ∫ x : ℝ in n..(n + 1), (x ^ (-s) - n * x ^ (-(s + 1))) := by refine intervalIntegral.integral_congr (fun x hx ↦ ?_) rw [sub_div, rpow_add_one (hv x hx).ne', mul_comm, ← div_div, div_self (hv x hx).ne', rpow_neg (hv x hx).le, rpow_neg (hv x hx).le, one_div, rpow_add_one (hv x hx).ne', mul_comm, div_eq_mul_inv] _ = (∫ x : ℝ in n..(n + 1), x ^ (-s)) - n * (∫ x : ℝ in n..(n + 1), x ^ (-(s + 1))) := by rw [intervalIntegral.integral_sub, intervalIntegral.integral_const_mul] <;> [skip; apply IntervalIntegrable.const_mul] <;> · refine intervalIntegral.intervalIntegrable_rpow (Or.inr <| not_mem_uIcc_of_lt ?_ ?_) · exact_mod_cast hn · linarith _ = 1 / (s - 1) * (1 / n ^ (s - 1) - 1 / (n + 1) ^ (s - 1)) - n / s * (1 / n ^ s - 1 / (n + 1) ^ s) := by have : 0 ∉ uIcc (n : ℝ) (n + 1) := (lt_irrefl _ <| hv _ ·) rw [integral_rpow (Or.inr ⟨by linarith, this⟩), integral_rpow (Or.inr ⟨by linarith, this⟩)] congr 1 · rw [show -s + 1 = -(s - 1) by ring, div_neg, ← neg_div, mul_comm, mul_one_div, neg_sub, rpow_neg (Nat.cast_nonneg _), one_div, rpow_neg (by linarith), one_div] · rw [show -(s + 1) + 1 = -s by ring, div_neg, ← neg_div, neg_sub, div_mul_eq_mul_div, mul_div_assoc, rpow_neg (Nat.cast_nonneg _), one_div, rpow_neg (by linarith), one_div] lemma term_sum_of_lt (N : ℕ) {s : ℝ} (hs : 1 < s) : term_sum s N = 1 / (s - 1) * (1 - 1 / (N + 1) ^ (s - 1)) - 1 / s * ((∑ n ∈ Finset.range N, 1 / (n + 1 : ℝ) ^ s) - N / (N + 1) ^ s) := by simp only [term_sum] conv => enter [1, 2, n]; rw [term_of_lt (by simp) hs] rw [Finset.sum_sub_distrib] congr 1 · induction' N with N hN · simp · rw [Finset.sum_range_succ, hN, Nat.cast_add_one] ring_nf · simp_rw [mul_comm (_ / _), ← mul_div_assoc, div_eq_mul_inv _ s, ← Finset.sum_mul, mul_one] congr 1 induction' N with N hN · simp · simp_rw [Finset.sum_range_succ, hN, Nat.cast_add_one, sub_eq_add_neg, add_assoc] congr 1 ring_nf /-- For `1 < s`, the topological sum of `ZetaAsymptotics.term (n + 1) s` over all `n : ℕ` is `1 / (s - 1) - ζ s / s`. -/ lemma term_tsum_of_lt {s : ℝ} (hs : 1 < s) : term_tsum s = (1 / (s - 1) - 1 / s * ∑' n : ℕ, 1 / (n + 1 : ℝ) ^ s) := by apply HasSum.tsum_eq rw [hasSum_iff_tendsto_nat_of_nonneg (fun n ↦ term_nonneg (n + 1) s)] change Tendsto (fun N ↦ term_sum s N) atTop _ simp_rw [term_sum_of_lt _ hs] apply Tendsto.sub · rw [show 𝓝 (1 / (s - 1)) = 𝓝 (1 / (s - 1) - 1 / (s - 1) * 0) by simp] simp_rw [mul_sub, mul_one] refine tendsto_const_nhds.sub (Tendsto.const_mul _ ?_) refine tendsto_const_nhds.div_atTop <| (tendsto_rpow_atTop (by linarith)).comp ?_ exact tendsto_atTop_add_const_right _ _ tendsto_natCast_atTop_atTop · rw [← sub_zero (tsum _)] apply (((Summable.hasSum ?_).tendsto_sum_nat).sub ?_).const_mul · exact_mod_cast (summable_nat_add_iff 1).mpr (summable_one_div_nat_rpow.mpr hs) · apply tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds · change Tendsto (fun n : ℕ ↦ (1 / ↑(n + 1) : ℝ) ^ (s - 1)) .. rw [show 𝓝 (0 : ℝ) = 𝓝 (0 ^ (s - 1)) by rw [zero_rpow]; linarith] refine Tendsto.rpow_const ?_ (Or.inr <| by linarith) exact (tendsto_const_div_atTop_nhds_zero_nat _).comp (tendsto_add_atTop_nat _) · intro n positivity · intro n dsimp only transitivity (n + 1) / (n + 1) ^ s · gcongr linarith · apply le_of_eq rw [rpow_sub_one, ← div_mul, div_one, mul_comm, one_div, inv_rpow, ← div_eq_mul_inv] · norm_cast all_goals positivity /-- Reformulation of `ZetaAsymptotics.term_tsum_of_lt` which is useful for some computations below. -/ lemma zeta_limit_aux1 {s : ℝ} (hs : 1 < s) : (∑' n : ℕ, 1 / (n + 1 : ℝ) ^ s) - 1 / (s - 1) = 1 - s * term_tsum s := by rw [term_tsum_of_lt hs] generalize (∑' n : ℕ, 1 / (n + 1 : ℝ) ^ s) = Z field_simp [(show s - 1 ≠ 0 by linarith)] ring_nf end s_gt_one section continuity /-! ## Continuity of the sum -/ lemma continuousOn_term (n : ℕ) : ContinuousOn (fun x ↦ term (n + 1) x) (Ici 1) := by -- TODO: can this be shortened using the lemma -- `continuous_parametric_intervalIntegral_of_continuous'` from #11185? simp only [term, intervalIntegral.integral_of_le (by linarith : (↑(n + 1) : ℝ) ≤ ↑(n + 1) + 1)] apply continuousOn_of_dominated (bound := fun x ↦ (x - ↑(n + 1)) / x ^ (2 : ℝ)) · exact fun s hs ↦ (term_welldef (by simp) (zero_lt_one.trans_le hs)).1.1 · intro s (hs : 1 ≤ s) rw [ae_restrict_iff' measurableSet_Ioc] filter_upwards with x hx have : 0 < x := lt_trans (by positivity) hx.1 rw [norm_of_nonneg (div_nonneg (sub_nonneg.mpr hx.1.le) (by positivity)), Nat.cast_add_one] apply div_le_div_of_nonneg_left · exact_mod_cast sub_nonneg.mpr hx.1.le · positivity · exact rpow_le_rpow_of_exponent_le (le_trans (by simp) hx.1.le) (by linarith) · rw [← IntegrableOn, ← intervalIntegrable_iff_integrableOn_Ioc_of_le (by linarith)] exact_mod_cast term_welldef (by linarith : 0 < (n + 1)) zero_lt_one · rw [ae_restrict_iff' measurableSet_Ioc] filter_upwards with x hx refine ContinuousAt.continuousOn (fun s (hs : 1 ≤ s) ↦ continuousAt_const.div ?_ ?_) · exact continuousAt_const.rpow (continuousAt_id.add continuousAt_const) (Or.inr (by linarith)) · exact (rpow_pos_of_pos ((Nat.cast_pos.mpr (by simp)).trans hx.1) _).ne' lemma continuousOn_term_tsum : ContinuousOn term_tsum (Ici 1) := by -- We use dominated convergence, using `fun n ↦ term n 1` as our uniform bound (since `term` is -- monotone decreasing in `s`.) refine continuousOn_tsum (fun i ↦ continuousOn_term _) term_tsum_one.summable (fun n s hs ↦ ?_) rw [term, term, norm_of_nonneg] · simp_rw [intervalIntegral.integral_of_le (by linarith : (↑(n + 1) : ℝ) ≤ ↑(n + 1) + 1)] refine setIntegral_mono_on ?_ ?_ measurableSet_Ioc (fun x hx ↦ ?_) · exact (term_welldef n.succ_pos (zero_lt_one.trans_le hs)).1 · exact (term_welldef n.succ_pos zero_lt_one).1 · rw [div_le_div_left] -- leave side-goals to end and kill them all together · apply rpow_le_rpow_of_exponent_le · exact (lt_of_le_of_lt (by simp) hx.1).le · linarith [mem_Ici.mp hs] · linarith [hx.1] all_goals apply rpow_pos_of_pos ((Nat.cast_nonneg _).trans_lt hx.1) · rw [intervalIntegral.integral_of_le (by linarith)] refine setIntegral_nonneg measurableSet_Ioc (fun x hx ↦ div_nonneg ?_ (rpow_nonneg ?_ _)) all_goals linarith [hx.1] /-- First version of the limit formula, with a limit over real numbers tending to 1 from above. -/ lemma tendsto_riemannZeta_sub_one_div_nhds_right : Tendsto (fun s : ℝ ↦ riemannZeta s - 1 / (s - 1)) (𝓝[>] 1) (𝓝 γ) := by suffices Tendsto (fun s : ℝ ↦ (∑' n : ℕ, 1 / (n + 1 : ℝ) ^ s) - 1 / (s - 1)) (𝓝[>] 1) (𝓝 γ) by apply ((Complex.continuous_ofReal.tendsto _).comp this).congr' filter_upwards [self_mem_nhdsWithin] with s hs simp only [Function.comp_apply, Complex.ofReal_sub, Complex.ofReal_div, Complex.ofReal_one, sub_left_inj, Complex.ofReal_tsum] rw [zeta_eq_tsum_one_div_nat_add_one_cpow (by simpa using hs)] congr 1 with n rw [Complex.ofReal_cpow (by positivity)] norm_cast suffices aux2 : Tendsto (fun s : ℝ ↦ (∑' n : ℕ, 1 / (n + 1 : ℝ) ^ s) - 1 / (s - 1)) (𝓝[>] 1) (𝓝 (1 - term_tsum 1)) by have := term_tsum_one.tsum_eq rw [← term_tsum, eq_sub_iff_add_eq, ← eq_sub_iff_add_eq'] at this simpa only [this] using aux2 apply Tendsto.congr' · filter_upwards [self_mem_nhdsWithin] with s hs using (zeta_limit_aux1 hs).symm · apply tendsto_const_nhds.sub rw [← one_mul (term_tsum 1)] apply (tendsto_id.mono_left nhdsWithin_le_nhds).mul have := continuousOn_term_tsum.continuousWithinAt left_mem_Ici exact Tendsto.mono_left this (nhdsWithin_mono _ Ioi_subset_Ici_self) /-- The function `ζ s - 1 / (s - 1)` tends to `γ` as `s → 1`. -/ theorem _root_.tendsto_riemannZeta_sub_one_div : Tendsto (fun s : ℂ ↦ riemannZeta s - 1 / (s - 1)) (𝓝[≠] 1) (𝓝 γ) := by -- We use the removable-singularity theorem to show that *some* limit over `𝓝[≠] (1 : ℂ)` exists, -- and then use the previous result to deduce that this limit must be `γ`. let f (s : ℂ) := riemannZeta s - 1 / (s - 1) suffices ∃ C, Tendsto f (𝓝[≠] 1) (𝓝 C) by cases' this with C hC suffices Tendsto (fun s : ℝ ↦ f s) _ _ from (tendsto_nhds_unique this tendsto_riemannZeta_sub_one_div_nhds_right) ▸ hC refine hC.comp (tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ ?_ ?_) · exact (Complex.continuous_ofReal.tendsto 1).mono_left (nhdsWithin_le_nhds ..) · filter_upwards [self_mem_nhdsWithin] with a ha rw [mem_compl_singleton_iff, ← Complex.ofReal_one, Ne, Complex.ofReal_inj] exact ne_of_gt ha refine ⟨_, Complex.tendsto_limUnder_of_differentiable_on_punctured_nhds_of_isLittleO ?_ ?_⟩ · filter_upwards [self_mem_nhdsWithin] with s hs refine (differentiableAt_riemannZeta hs).sub ((differentiableAt_const _).div ?_ ?_) · fun_prop · rwa [mem_compl_singleton_iff, ← sub_ne_zero] at hs · refine Asymptotics.isLittleO_of_tendsto' ?_ ?_ · filter_upwards [self_mem_nhdsWithin] with t ht ht' rw [inv_eq_zero, sub_eq_zero] at ht' tauto · simp_rw [div_eq_mul_inv, inv_inv, sub_mul, (by ring_nf : 𝓝 (0 : ℂ) = 𝓝 ((1 - 1) - f 1 * (1 - 1)))] apply Tendsto.sub · simp_rw [mul_comm (f _), f, mul_sub] apply riemannZeta_residue_one.sub refine Tendsto.congr' ?_ (tendsto_const_nhds.mono_left nhdsWithin_le_nhds) filter_upwards [self_mem_nhdsWithin] with x hx field_simp [sub_ne_zero.mpr <| mem_compl_singleton_iff.mp hx] · exact ((tendsto_id.sub tendsto_const_nhds).mono_left nhdsWithin_le_nhds).const_mul _ lemma _root_.isBigO_riemannZeta_sub_one_div {F : Type*} [Norm F] [One F] [NormOneClass F] : (fun s : ℂ ↦ riemannZeta s - 1 / (s - 1)) =O[𝓝 1] (fun _ ↦ 1 : ℂ → F) := by simpa only [Asymptotics.isBigO_one_nhds_ne_iff] using tendsto_riemannZeta_sub_one_div.isBigO_one (F := F) end continuity section val_at_one open Complex lemma tendsto_Gamma_term_aux : Tendsto (fun s ↦ 1 / (s - 1) - 1 / Gammaℝ s / (s - 1)) (𝓝[≠] 1) (𝓝 (-(γ + Complex.log (4 * ↑π)) / 2)) := by have h := hasDerivAt_Gammaℝ_one rw [hasDerivAt_iff_tendsto_slope, slope_fun_def_field, Gammaℝ_one] at h have := h.div (hasDerivAt_Gammaℝ_one.continuousAt.tendsto.mono_left nhdsWithin_le_nhds) (Gammaℝ_one.trans_ne one_ne_zero) rw [Gammaℝ_one, div_one] at this refine this.congr' ?_ have : {z | 0 < re z} ∈ 𝓝 (1 : ℂ) := by apply (continuous_re.isOpen_preimage _ isOpen_Ioi).mem_nhds simp only [mem_preimage, one_re, mem_Ioi, zero_lt_one] rw [EventuallyEq, eventually_nhdsWithin_iff] filter_upwards [this] with a ha _ rw [Pi.div_apply, ← sub_div, div_right_comm, sub_div' _ _ _ (Gammaℝ_ne_zero_of_re_pos ha), one_mul] lemma tendsto_riemannZeta_sub_one_div_Gammaℝ : Tendsto (fun s ↦ riemannZeta s - 1 / Gammaℝ s / (s - 1)) (𝓝[≠] 1) (𝓝 ((γ - Complex.log (4 * ↑π)) / 2)) := by have := tendsto_riemannZeta_sub_one_div.add tendsto_Gamma_term_aux simp_rw [sub_add_sub_cancel] at this convert this using 2 ring_nf /-- Formula for `ζ 1`. Note that mathematically `ζ 1` is undefined, but our construction ascribes this particular value to it. -/ lemma _root_.riemannZeta_one : riemannZeta 1 = (γ - Complex.log (4 * ↑π)) / 2 := by have := (HurwitzZeta.tendsto_hurwitzZetaEven_sub_one_div_nhds_one 0).mono_left <| nhdsWithin_le_nhds (s := {1}ᶜ) simp only [HurwitzZeta.hurwitzZetaEven_zero, div_right_comm _ _ (Gammaℝ _)] at this exact tendsto_nhds_unique this tendsto_riemannZeta_sub_one_div_Gammaℝ /-- Formula for `Λ 1`. Note that mathematically `Λ 1` is undefined, but our construction ascribes this particular value to it. -/ lemma _root_.completedRiemannZeta_one : completedRiemannZeta 1 = (γ - Complex.log (4 * ↑π)) / 2 := (riemannZeta_one ▸ div_one (_ : ℂ) ▸ Gammaℝ_one ▸ riemannZeta_def_of_ne_zero one_ne_zero).symm /-- Formula for `Λ₀ 1`, where `Λ₀` is the entire function satisfying `Λ₀ s = π ^ (-s / 2) Γ(s / 2) ζ(s) + 1 / s + 1 / (1 - s)` away from `s = 0, 1`. Note that `s = 1` is _not_ a pole of `Λ₀`, so this statement (unlike `riemannZeta_one`) is a mathematically meaningful statement and is not dependent on Mathlib's particular conventions for division by zero. -/ lemma _root_.completedRiemannZeta₀_one : completedRiemannZeta₀ 1 = (γ - Complex.log (4 * ↑π)) / 2 + 1 := by have := completedRiemannZeta_eq 1 rw [sub_self, div_zero, div_one, sub_zero, eq_sub_iff_add_eq] at this rw [← this, completedRiemannZeta_one] /-- With Mathlib's particular conventions, we have `ζ 1 ≠ 0`. -/ lemma _root_.riemannZeta_one_ne_zero : riemannZeta 1 ≠ 0 := by -- This one's for you, Kevin. suffices (γ - (4 * π).log) / 2 ≠ 0 by simpa only [riemannZeta_one, ← ofReal_ne_zero, ofReal_log (by positivity : 0 ≤ 4 * π), push_cast] refine div_ne_zero (sub_lt_zero.mpr (lt_trans ?_ ?_ (b := 1))).ne two_ne_zero · exact Real.eulerMascheroniConstant_lt_two_thirds.trans (by norm_num) · rw [lt_log_iff_exp_lt (by positivity)] exact (lt_trans Real.exp_one_lt_d9 (by norm_num)).trans_le <| mul_le_mul_of_nonneg_left two_le_pi (by norm_num) end val_at_one end ZetaAsymptotics
NumberTheory\LegendreSymbol\AddCharacter.lean
/- Copyright (c) 2022 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ 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 mooid 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_right_neg, mulShift_apply] 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, 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. -/ -- Porting note(#5171): this linter isn't ported yet. -- can't prove that they always exist (referring to providing an `Inhabited` instance) -- @[nolint has_nonempty_instance] 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 a] 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 cases' 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ψ'⟩ @[deprecated (since := "2024-05-30")] alias primitiveCharFiniteField := FiniteField.primitiveChar /-! ### 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] [DecidableEq 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 refine MonoidHom.compAddChar ?_ (primitiveChar F ℂ <| ringChar_ne F).char exact (IsCyclotomicExtension.algEquiv ?n ℂ (CyclotomicField ?n ℂ) ℂ : CyclotomicField ?n ℂ →* ℂ) 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
NumberTheory\LegendreSymbol\Basic.lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Michael Stoll -/ 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 [zero_pow, mul_zero, ne_eq, not_true] 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 cases' 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, quadraticCharFun_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 cases' 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, eq_neg_self_iff] at h exact one_ne_zero h · rw [eq_one_of_sq_sub_mul_sq_eq_zero ha hy hxy, 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
NumberTheory\LegendreSymbol\GaussEisensteinLemmas.lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.NumberTheory.LegendreSymbol.Basic import Mathlib.Analysis.Normed.Field.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 (config := { contextual := true }) [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 : ℕ) (hx : 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 · erw [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_ofNat] · erw [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_ofNat] 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) ^ ((Ico 1 (p / 2).succ).filter fun x : ℕ => ¬(a * x : ZMod p).val ≤ p / 2).card * (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) ^ ((Ico 1 (p / 2).succ).filter fun x : ℕ => ¬(a * x : ZMod p).val ≤ p / 2).card * ∏ 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).filter fun x : ℕ => ¬(a * x : 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) ^ ((Ico 1 (p / 2).succ).filter fun x : ℕ => ¬(a * x : ZMod p).val ≤ p / 2).card * (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) ^ ((Ico 1 (p / 2).succ).filter fun x : ℕ => p / 2 < (a * x : ZMod p).val).card :) := (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) ^ ((Ico 1 (p / 2).succ).filter fun x : ℕ => p / 2 < (a * x : ZMod p).val).card := by replace hp : Odd p := h.out.odd_of_ne_two hp have : (legendreSym p a : ZMod p) = (((-1) ^ ((Ico 1 (p / 2).succ).filter fun x : ℕ => p / 2 < (a * x : ZMod p).val).card : ℤ) : 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 ℤ ((Ico 1 (p / 2).succ).filter fun x : ℕ => p / 2 < (a * x : ZMod p).val).card <;> 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) = ((Ico 1 (p / 2).succ).filter fun x : ℕ => p / 2 < (a * x : ZMod p).val).card + ∑ x ∈ Ico 1 (p / 2).succ, x + (∑ x ∈ Ico 1 (p / 2).succ, a * x / p : ℕ) := have hp2 : (p : ZMod 2) = (1 : ℕ) := (eq_iff_modEq_nat _).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] _ = ((Ico 1 (p / 2).succ).filter fun x : ℕ => p / 2 < (a * x : ZMod p).val).card + (∑ x ∈ Ico 1 (p / 2).succ, (a * x : 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]) rfl theorem eisenstein_lemma_aux (p : ℕ) [Fact p.Prime] [Fact (p % 2 = 1)] {a : ℕ} (ha2 : a % 2 = 1) (hap : (a : ZMod p) ≠ 0) : ((Ico 1 (p / 2).succ).filter fun x : ℕ => p / 2 < (a * x : ZMod p).val).card ≡ ∑ x ∈ Ico 1 (p / 2).succ, x * a / p [MOD 2] := have ha2 : (a : ZMod 2) = (1 : ℕ) := (eq_iff_modEq_nat _).2 ha2 (eq_iff_modEq_nat 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, neg_eq_self_mod_two, 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 = ((Ico 1 c.succ).filter fun x => x * b ≤ a).card := calc a / b = (Ico 1 (a / b).succ).card := by simp _ = ((Ico 1 c.succ).filter fun x => x * b ≤ a).card := 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 = ((Ico 1 (p / 2).succ ×ˢ Ico 1 (q / 2).succ).filter fun x : ℕ × ℕ => x.2 * p ≤ x.1 * q).card := if hp0 : p = 0 then by simp [hp0, Finset.ext_iff] else calc ∑ a ∈ Ico 1 (p / 2).succ, a * q / p = ∑ a ∈ Ico 1 (p / 2).succ, ((Ico 1 (q / 2).succ).filter fun x => x * p ≤ a * q).card := 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 rw [← card_sigma] exact card_nbij' (fun a ↦ ⟨a.1, a.2⟩) (fun a ↦ ⟨a.1, a.2⟩) (by simp (config := { contextual := true }) only [mem_filter, mem_sigma, and_self_iff, forall_true_iff, mem_product]) (by simp (config := { contextual := true }) only [mem_filter, mem_sigma, and_self_iff, forall_true_iff, mem_product]) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) /-- 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 : ((Ico 1 (q / 2).succ ×ˢ Ico 1 (p / 2).succ).filter fun x : ℕ × ℕ => x.2 * q ≤ x.1 * p).card = ((Ico 1 (p / 2).succ ×ˢ Ico 1 (q / 2).succ).filter fun x : ℕ × ℕ => x.1 * q ≤ x.2 * p).card := card_equiv (Equiv.prodComm _ _) (fun ⟨_, _⟩ => by simp (config := { contextual := true }) only [mem_filter, and_self_iff, Prod.swap_prod_mk, forall_true_iff, mem_product, Equiv.prodComm_apply, and_assoc, and_left_comm]) have hdisj : Disjoint ((Ico 1 (p / 2).succ ×ˢ Ico 1 (q / 2).succ).filter fun x : ℕ × ℕ => x.2 * p ≤ x.1 * q) ((Ico 1 (p / 2).succ ×ˢ Ico 1 (q / 2).succ).filter fun x : ℕ × ℕ => 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_iff, mem_product] at hx have hunion : (((Ico 1 (p / 2).succ ×ˢ Ico 1 (q / 2).succ).filter fun x : ℕ × ℕ => x.2 * p ≤ x.1 * q) ∪ (Ico 1 (p / 2).succ ×ˢ Ico 1 (q / 2).succ).filter fun x : ℕ × ℕ => 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.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
NumberTheory\LegendreSymbol\JacobiSymbol.lean
/- Copyright (c) 2022 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll, Thomas Zhu, Mario Carneiro -/ 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. ## Notations 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 (locale `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 -- Porting note: Without the following line, Lean expected `|` on several lines, e.g. line 102. 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] case h => exact fun p hp => (List.mem_append.mp hp).elim prime_of_mem_primeFactorsList prime_of_mem_primeFactorsList case _ => 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 := ((@SignType.castHom ℤ _ _).toMonoidHom.mrange.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 -- Porting note: The line 150 was added because Lean does not synthesize the instance -- `[Fact (Nat.Prime p)]` automatically (it is needed for `legendreSym.at_one`) letI : Fact p.Prime := ⟨prime_of_mem_primeFactorsList hp⟩ 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] -- Porting note: Initially, `and_assoc'` and `and_comm'` were used on line 164 but they have -- been deprecated so we replace them with `and_assoc` and `and_comm` 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, 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 cases' 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_ofNat]; 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 e ih · rw [Nat.pow_zero, _root_.pow_zero, one_right] · cases' 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 cases' 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 _ (by -- Porting note: Lean does not synthesize the instance [Fact (Nat.Prime p)] automatically -- (it is needed for `legendreSym.mod` on line 227). Thus, we name the hypothesis -- `Nat.Prime p` explicitly on line 224 and prove `Fact (Nat.Prime p)` on line 225. rintro p hp _ h₂ letI : Fact p.Prime := ⟨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 n l' ih · simp only [List.prod_nil, List.map_nil, one_left] · 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 n l' ih · simp only [List.prod_nil, one_right, List.map_nil] · have hn := hl n (List.mem_cons_self n l') -- `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, 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 norm_num : ¬(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*} [CommSemiring 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 Nat.Prime _ _ fun _ => prime_of_mem_primeFactorsList] congr 1; apply List.pmap_congr 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)] have := Nat.mod_lt b (by decide : 0 < 8) interval_cases h : b % 8 <;> simp_all <;> · have := hb2 ▸ h ▸ Nat.mod_mod_of_dvd b (by decide : 2 ∣ 8) simp_all 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)] cases' 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 -- Porting note: `simp_rw` on line 423 replaces `rw` to allow the rewrite rules to be -- applied under the binder `fun ↦ ...` 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 norm_num) 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 -- Porting note: In mathlib3, it was written `cases' e`. In Lean 4, this resulted in the choice -- of a name other than e (for the case distinction of line 482) so we indicate the name -- to use explicitly. cases' 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 cases' 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`. -/ 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 (a.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) (a.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.strongInductionOn with a IH generalizing b flip unfold fastJacobiSymAux split <;> rename_i ha4 · rw [IH (a / 4) (a.div_lt_self ha0 (by decide)) hb2 hb1] simp only [Int.ofNat_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.ofNat_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 hb2 : 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.strongInductionOn with 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)) · 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
NumberTheory\LegendreSymbol\QuadraticReciprocity.lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Michael Stoll -/ 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 variable (hp : p ≠ 2) /-- `legendreSym p 2` is given by `χ₈ p`. -/ theorem at_two : 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 : 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 variable (hp : p ≠ 2) /-- `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 : 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.mpr hp rw [← mod_mod_of_dvd p (by decide : 2 ∣ 8)] at h₁ have h₂ := mod_lt p (by norm_num : 0 < 8) revert h₂ h₁ generalize p % 8 = m; clear! p intros; interval_cases m <;> simp_all -- Porting note (#11043): was `decide!` /-- `-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 : 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.mpr hp rw [← mod_mod_of_dvd p (by decide : 2 ∣ 8)] at h₁ have h₂ := mod_lt p (by norm_num : 0 < 8) revert h₂ h₁ generalize p % 8 = m; clear! p intros; interval_cases m <;> simp_all -- Porting note (#11043): was `decide!` 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.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, 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
NumberTheory\LegendreSymbol\ZModChar.lean
/- Copyright (c) 2022 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ 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 omega : (2 : ℤ) ∣ 4), ← ZMod.intCast_mod n 4] exact help (n % 4) (Int.emod_nonneg n (by omega)) (Int.emod_lt n (by omega)) 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 omega] 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 omega)) <| (Nat.mod_mod_of_dvd n (by omega : 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 omega : (2 : ℤ) ∣ 8), ← ZMod.intCast_mod n 8] exact help (n % 8) (Int.emod_nonneg n (by omega)) (Int.emod_lt n (by omega)) 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 omega : (2 : ℤ) ∣ 8), ← ZMod.intCast_mod n 8] exact help (n % 8) (Int.emod_nonneg n (by omega)) (Int.emod_lt n (by omega)) 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 omega) a] exact χ₈'_eq_χ₄_mul_χ₈ a end QuadCharModP end ZMod
NumberTheory\LegendreSymbol\QuadraticChar\Basic.lean
/- Copyright (c) 2022 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ 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] by_cases ha : a = 0 · simp only [ha, if_true] · simp only [ha, if_false, iff_false_iff] split_ifs <;> simp only [neg_eq_zero, one_ne_zero, not_false_iff] @[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] cases' 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] cases' FiniteField.pow_dichotomy hF ha with ha' ha' <;> simp only [ha', h, neg_neg, if_true, if_false] variable (F) /-- 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 variable {F} /-- 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 -- @[simp] -- Porting note (#10618): simp can prove this 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, (by omega : (-1 : ℤ) ≠ 1), imp_false, not_not] /-- 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]; omega, 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) /-- 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 variable {F} /-- 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, eq_neg_self_iff, one_ne_zero] at ha set_option linter.deprecated false in @[deprecated quadraticChar_ne_one (since := "2024-06-16")] theorem quadraticChar_isNontrivial (hF : ringChar F ≠ 2) : (quadraticChar F).IsNontrivial := (isNontrivial_iff _).mpr <| quadraticChar_ne_one hF 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.card = 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.ofNat_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 only [Set.toFinset_setOf, h, mem_filter, mem_univ, true_and, List.toFinset_cons, List.toFinset_nil, insert_emptyc_eq, mem_insert, mem_singleton, s] 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 [add_left_neg, Int.natCast_eq_zero, card_eq_zero] ext1 -- Porting note(https://github.com/leanprover-community/mathlib4/issues/5026): -- added (Set.mem_toFinset), Set.mem_setOf simp only [(Set.mem_toFinset), Set.mem_setOf, not_mem_empty, iff_false_iff] rw [isSquare_iff_exists_sq] at h exact fun h' ↦ h ⟨_, h'.symm⟩ /-- 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 cases' 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_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₁] simp only [Nat.one_ne_zero, if_false, ite_eq_left_iff, (by omega : (-1 : ℤ) ≠ 1), imp_false, not_not, Ne] exact ⟨fun h ↦ ne_of_eq_of_ne h (by omega), (Nat.odd_mod_four_iff.mp h₁).resolve_right⟩ end SpecialValues
NumberTheory\LegendreSymbol\QuadraticChar\GaussSum.lean
/- Copyright (c) 2022 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ 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_iff] omega · 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] omega /-- 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 norm_num : (-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_iff] omega · 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] omega /-- 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 by_cases hFp : ringChar F = p · rw [show (p : F) = 0 by rw [← hFp]; exact ringChar.Nat.cast_ringChar] simp only [isSquare_zero, Ne, true_iff_iff, map_mul] obtain ⟨n, _, hc⟩ := FiniteField.card F (ringChar F) have hchar : ringChar F = ringChar (ZMod p) := by rw [hFp]; exact (ringChar_zmod_n p).symm conv => enter [1, 1, 2]; rw [hc, Nat.cast_pow, map_pow, hchar, map_ringChar] simp only [zero_pow n.ne_zero, mul_zero, zero_eq_neg, one_ne_zero, not_false_iff] · rw [← Iff.not_left (@quadraticChar_neg_one_iff_not_isSquare F _ _ _ _), quadraticChar_odd_prime hF hp] exact hFp end SpecialValues
NumberTheory\Liouville\Basic.lean
/- Copyright (c) 2020 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa, Jujian Zhang -/ import Mathlib.Algebra.Polynomial.DenomsClearable import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Analysis.Calculus.Deriv.Polynomial import Mathlib.Data.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` refine mul_le_mul_of_nonneg_left ((B this).trans ?_) (zero_le_one.trans (d0 a)) exact mul_le_mul_of_nonneg_left (le_max_right _ M) dist_nonneg 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_of_one_le ((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. · show 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 (irrational_iff_ne_rational α).mp ha 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 exact Int.cast_two.symm.le.trans (Int.cast_le.mpr (Int.add_one_le_iff.mpr b1)) -- 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
NumberTheory\Liouville\LiouvilleNumber.lean
/- Copyright (c) 2020 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa, Jujian Zhang -/ import Mathlib.NumberTheory.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 := tsum_pos (remainder_summable hm k) (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 := sum_add_tsum_nat_add _ (LiouvilleNumber.summable hm) /-! 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 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 j => 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)!) := -- the second factors coincide (and are non-negative), -- the first factors satisfy the inequality `sub_one_div_inv_le_two` mul_le_mul_of_nonneg_right (sub_one_div_inv_le_two hm) (by positivity) _ = 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 -- [NB: in this block, I do not follow the brace convention for subgoals -- I wait until -- I solve all extraneous goals at once with `exact pow_pos (zero_lt_two.trans_le hm) _`.] -- Clear denominators and massage* apply (div_le_div_iff _ _).mpr focus conv_rhs => rw [one_mul, mul_add, pow_add, mul_one, pow_mul, mul_comm, ← pow_mul] -- the second factors coincide, so we prove the inequality of the first factors* refine (mul_le_mul_right ?_).mpr ?_ -- solve all the inequalities `0 < m ^ ??` any_goals exact pow_pos (zero_lt_two.trans_le hm) _ -- `2 ≤ m ^ n!` is a consequence of monotonicity of exponentiation at `2 ≤ m`. exact _root_.trans (_root_.trans hm (pow_one _).symm.le) (pow_right_mono (one_le_two.trans hm) n.factorial_pos) _ = 1 / (m ^ n !) ^ n := congr_arg (1 / ·) (pow_mul m n ! n) /-- 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 k h · exact ⟨1, by rw [partialSum, range_one, sum_singleton, Nat.cast_one, Nat.factorial, pow_one, pow_one]⟩ · 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
NumberTheory\Liouville\LiouvilleWith.lean
/- Copyright (c) 2021 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.Analysis.SpecialFunctions.Pow.Asymptotics import Mathlib.NumberTheory.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 y : ℝ} {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, le_refl] 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_le ?_ have hn' : (0 : ℝ) < n := by simpa rw [rpow_neg_one, ← one_div, sub_div' _ _ _ hn'.ne', abs_div, Nat.abs_cast, div_le_div_right hn'] 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 [Liouville, not_forall, 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_lt N b with h | h · refine (hN b h a hne).not_lt (hlt.trans_le ?_) gcongr exact_mod_cast hb.le · exact (hm b h hb _).not_lt 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⟩
NumberTheory\Liouville\Measure.lean
/- Copyright (c) 2021 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.MeasureTheory.Measure.Lebesgue.Basic import Mathlib.NumberTheory.Liouville.Residual import Mathlib.NumberTheory.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_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.ofNat_succ, 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 x 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
NumberTheory\Liouville\Residual.lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.NumberTheory.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 @[deprecated (since := "2024-02-15")] alias isGδ_setOf_liouville := IsGδ.setOf_liouville theorem setOf_liouville_eq_irrational_inter_iInter_iUnion : { x | Liouville x } = { x | Irrational x } ∩ ⋂ n : ℕ, ⋃ (a : ℤ) (b : ℤ) (hb : 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.denseEmbedding_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 := Int.ofNat_le.2 r.pos; rw [Int.ofNat_one] at this; omega · convert @mem_ball_self ℝ _ (r : ℝ) _ _ · push_cast; norm_cast; simp [Rat.divInt_mul_right (two_ne_zero), Rat.mkRat_self] · 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
NumberTheory\LSeries\AbstractFuncEq.lean
/- Copyright (c) 2024 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ 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] [CompleteSpace 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_simp [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 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_zero_atTop 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] field_simp · 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_simp ring /-- 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 _) (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 only [P.hf₀, sub_zero] 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 have := P.hg₀ ▸ P.hf_zero r simpa only [smul_zero, sub_zero] /-! ## 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` refine setIntegral_congr 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 only [← ofReal_cpow (le_of_lt ht), ofReal_ne_zero] 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 ContinuousAt.continuousOn (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_not_mem (not_mem_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_not_mem (not_mem_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_not_mem (not_mem_Ioo_of_ge this.le), add_zero, g_modif, Pi.add_apply, indicator_of_not_mem (not_mem_Ioi.mpr hx'.le), indicator_of_mem (mem_Ioo.mpr ⟨hx, hx'⟩), zero_add, P.h_feq _ hx, smul_sub] simp_rw [rpow_neg hx.le, ← mul_smul] field_simp [(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 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_not_mem (not_mem_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_not_mem (not_mem_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_not_mem (not_mem_Ioi.mpr hx'.le), indicator_of_mem (mem_Ioo.mpr ⟨hx, hx'⟩), indicator_of_not_mem (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_not_mem (not_mem_Ioo_of_ge hx'.le), indicator_of_not_mem (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 {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 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_not_mem 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 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 only [one_div] using (differentiableAt_inv' hs).smul_const P.f₀ · simpa only [hs, smul_zero] using differentiableAt_const (0 : E) · rcases hs' with hs' | hs' · apply DifferentiableAt.smul_const apply (differentiableAt_const _).div ((differentiableAt_const _).sub (differentiable_id _)) rwa [sub_ne_zero, ne_comm] · simpa only [hs', smul_zero] using differentiableAt_const (0 : E) /-- Relation between `Λ s` and the Mellin transform of `f - f₀`, where the latter is defined. -/ theorem hasMellin {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 have := P.functional_equation₀ s rw [P.Λ₀_eq, P.symm_Λ₀_eq, sub_sub_cancel] at this rwa [smul_add, smul_add, ← mul_smul, mul_one_div, ← mul_smul, ← mul_div_assoc, mul_inv_cancel P.hε, add_assoc, add_comm (_ • _), add_assoc, add_left_inj] at this /-- 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) ↦ ?_) simp_rw [← mul_smul] congr 1 field_simp [sub_ne_zero.mpr hs.symm] ring /-- 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) ↦ ?_) simp_rw [← mul_smul] field_simp [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
NumberTheory\LSeries\Basic.lean
/- Copyright (c) 2021 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Michael Stoll -/ import Mathlib.Analysis.PSeries import Mathlib.Analysis.Normed.Module.FiniteDimension import Mathlib.Data.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. ## 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 @[simp] lemma term_zero (f : ℕ → ℂ) (s : ℂ) : term f s 0 = 0 := rfl -- We put `hn` first for convnience, 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 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 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 only [term_zero, norm_zero, ↓reduceIte] · rw [if_neg hn, term_of_ne_zero hn, norm_div, 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 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 lemma LSeries_congr {f g : ℕ → ℂ} (s : ℂ) (h : ∀ {n}, n ≠ 0 → f n = g n) : 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 ↦ ?_⟩ simp only [Set.mem_diff, Set.mem_singleton_iff] at hn simp only [term_of_ne_zero hn.2, hS' hn.1] exact Eventually.mono this.symm fun n hn ↦ by simp only [hn, le_rfl] 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 only [LSeriesSummable, funext (term_def 0 s), Pi.zero_apply, zero_div, ite_self, 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 only [LSeriesHasSum_iff, LSeriesSummable_congr s h, LSeries_congr s h] 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 only [LSeries, LSeries.term, Pi.zero_apply, zero_div, ite_self, tsum_zero] 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 only [term_zero, zero_ne_one, ↓reduceIte] · simp only [ne_eq, hn, not_false_eq_true, term_of_ne_zero, delta] rcases eq_or_ne n 1 with rfl | hn' · simp only [↓reduceIte, cast_one, one_cpow, ne_eq, one_ne_zero, not_false_eq_true, div_self] · simp only [hn', ↓reduceIte, zero_div] lemma mul_delta_eq_smul_delta {f : ℕ → ℂ} : f * δ = f 1 • δ := by ext n simp only [Pi.mul_apply, delta, mul_ite, mul_one, mul_zero, Pi.smul_apply, smul_eq_mul] split_ifs with hn <;> simp only [hn] 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 only [LSeries, LSeries.term_delta, tsum_ite_eq, Pi.one_apply] 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 := le_tsum h 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, _root_.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 := by specialize hC 1 one_ne_zero simp only [Nat.cast_one, Real.one_rpow, mul_one] at hC exact (norm_nonneg _).trans hC 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 (fun n ↦ (n : ℝ) ^ (-s.re + x - 1)) ?_ ?_ · simp only [Real.summable_nat_rpow, hsx] · simp only [neg_add_rev, neg_sub, norm_norm, Filter.eventually_atTop] refine ⟨1, fun n hn ↦ ?_⟩ simp only [norm_natCast_cpow_of_pos hn, add_re, sub_re, neg_re, ofReal_re, one_re] convert le_refl ?_ using 2 ring refine Summable.of_norm <| hsum.of_nonneg_of_le (fun _ ↦ norm_nonneg _) (fun n ↦ ?_) rcases n.eq_zero_or_pos with rfl | hn · simp only [term_zero, norm_zero] exact 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_eq_abs (C : ℂ), abs_ofReal, _root_.abs_of_nonneg hC₀, div_eq_mul_inv, mul_assoc, ← Real.rpow_neg <| Nat.cast_nonneg _, ← Real.rpow_add <| Nat.cast_pos.mpr hn] simp only [add_re, sub_re, one_re, ofReal_re, neg_add_rev, neg_sub, neg_add_cancel_right] exact 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_lt 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₀, _root_.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, Complex.abs (f n) ≤ m) {s : ℂ} (hs : 1 < s.re) : LSeriesSummable f s := by refine LSeriesSummable_of_le_const_mul_rpow hs ⟨m, fun n hn ↦ ?_⟩ simp only [norm_eq_abs, sub_self, Real.rpow_zero, mul_one, 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, Complex.abs (f n) ≤ m) {s : ℝ} (hs : 1 < s) : LSeriesSummable f s := LSeriesSummable_of_bounded_of_one_lt_re h <| by simp only [ofReal_re, hs]
NumberTheory\LSeries\Convergence.lean
/- Copyright (c) 2024 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.NumberTheory.LSeries.Basic import Mathlib.Data.Real.EReal /-! # 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 simp only [abscissaOfAbsConv, sInf_lt_iff, Set.mem_image, Set.mem_setOf_eq, exists_exists_and_eq_and, EReal.coe_lt_coe_iff] at hs obtain ⟨y, hy, hys⟩ := 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, EReal.coe_lt_coe_iff.mp hx₂, LSeriesSummable_of_abscissaOfAbsConv_lt_re hx₁⟩ lemma LSeriesSummable.abscissaOfAbsConv_le {f : ℕ → ℂ} {s : ℂ} (h : LSeriesSummable f s) : abscissaOfAbsConv f ≤ s.re := by refine sInf_le <| Membership.mem.out ?_ simp only [Set.mem_setOf_eq, Set.mem_image, EReal.coe_eq_coe_iff, exists_eq_right] exact h.of_re_le_re <| by simp only [ofReal_re, le_refl] 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 ↦ ?_ simp only [mem_lowerBounds, Set.mem_image, Set.mem_setOf_eq, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] at hy have H (a : EReal) : x < a → y ≤ a := by induction' a with a₀ · simp only [not_lt_bot, le_bot_iff, IsEmpty.forall_iff] · exact_mod_cast fun ha ↦ hy a₀ (h a₀ ha) · simp only [EReal.coe_lt_top, le_top, forall_true_left] exact Set.Ioi_subset_Ici_iff.mp H lemma LSeries.abscissaOfAbsConv_le_of_forall_lt_LSeriesSummable' {f : ℕ → ℂ} {x : EReal} (h : ∀ y : ℝ, x < y → LSeriesSummable f y) : abscissaOfAbsConv f ≤ x := by induction' x with y · refine le_of_eq <| sInf_eq_bot.mpr fun y hy ↦ ?_ induction' y with z · simp only [gt_iff_lt, lt_self_iff_false] at hy · exact ⟨z - 1, ⟨z-1, h (z - 1) <| EReal.bot_lt_coe _, rfl⟩, by norm_cast; exact sub_one_lt z⟩ · exact ⟨0, ⟨0, h 0 <| EReal.bot_lt_coe 0, rfl⟩, EReal.zero_lt_top⟩ · exact abscissaOfAbsConv_le_of_forall_lt_LSeriesSummable <| by exact_mod_cast h · exact le_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 convert abscissaOfAbsConv_le_of_le_const_mul_rpow (x := 0) ?_ · simp only [EReal.coe_zero, zero_add] · simpa only [norm_eq_abs, Real.rpow_zero, mul_one] 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] (1 : ℕ → ℝ)) : abscissaOfAbsConv f ≤ 1 := by convert abscissaOfAbsConv_le_of_isBigO_rpow (x := 0) ?_ · simp only [EReal.coe_zero, zero_add] · simpa only [Real.rpow_zero] using h
NumberTheory\LSeries\Convolution.lean
/- Copyright (c) 2024 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.Analysis.InnerProductSpace.Basic import Mathlib.Analysis.Normed.Field.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 only [zero_eq, ArithmeticFunction.map_zero] · simp only [toArithmeticFunction, ArithmeticFunction.coe_mk, succ_ne_zero, ↓reduceIte, ne_eq, not_false_eq_true, h] /-- 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 (config := {contextual := true}) [toArithmeticFunction, ArithmeticFunction.map_zero] /-- 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 only [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 only [convolution, ArithmeticFunction.toArithmeticFunction_eq_self] 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 simp only [convolution, toArithmeticFunction, ArithmeticFunction.mul_apply, ArithmeticFunction.coe_mk, mul_ite, mul_zero, ite_mul, zero_mul] refine Finset.sum_congr rfl fun p hp ↦ ?_ obtain ⟨h₁, h₂⟩ := ne_zero_of_mem_divisorsAntidiagonal hp simp only [h₂, ↓reduceIte, h₁] @[simp] lemma convolution_map_zero {R : Type*} [Semiring R] (f g : ℕ → R) : (f ⍟ g) 0 = 0 := by simp only [convolution_def, divisorsAntidiagonal_zero, Finset.sum_empty] /-! ### 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 only [term_zero, divisorsAntidiagonal_zero, Finset.sum_empty] -- 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₁ f s, term_of_ne_zero hp₂ g s, 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 infinte 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 only [mem_preimage, mem_singleton_iff, Nat.mul_eq_zero, mem_union, mem_prod, mem_univ, and_true, true_and] have : ∀ p : (fun p : ℕ × ℕ ↦ p.1 * p.2) ⁻¹' {0}, term f s p.val.1 * term g s p.val.2 = 0 := by rintro ⟨⟨p₁, p₂⟩, hp⟩ rcases hS ▸ hp with ⟨rfl, -⟩ | ⟨-, rfl⟩ <;> simp only [term_zero, zero_mul, mul_zero] simp only [this, tsum_zero] -- 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 simp only [LSeriesHasSum, term_convolution'] have hsum := summable_mul_of_summable_norm hf.summable.norm hg.summable.norm exact (HasSum.mul hf hg hsum).tsum_fiberwise (fun p ↦ p.1 * p.2) /-- 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 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
NumberTheory\LSeries\Deriv.lean
/- Copyright (c) 2024 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ 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.analyticOn`). ## 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 only [term_zero, neg_zero, 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, ?_⟩ have H' := differentiableOn_tsum_of_summable_norm h₀ h₁ h₂ h₃ simpa only [← H.tsum_eq, tsum_neg] using (H'.differentiableAt <| IsOpen.mem_nhds h₂ 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 only [ofReal_re, hs]) |>.norm.of_norm_bounded_eventually_nat (‖term (logMul f) s ·‖) ?_ 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 _) rw [← Real.log_exp 1] exact 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 n ih · simp only [Nat.zero_eq, Function.iterate_zero, id_eq] · simp only [ih, Function.iterate_succ', Function.comp_def, abscissaOfAbsConv_logMul] /-- 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 with m ih generalizing s · simp only [Nat.zero_eq, iteratedDeriv_zero, pow_zero, Function.iterate_zero, id_eq, one_mul] · 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 only [Pi.mul_def, Pi.pow_apply, Pi.neg_apply, Pi.one_apply, deriv_const_mul_field', pow_succ, mul_assoc, neg_one_mul, Function.iterate_succ', Function.comp_def, LSeries_deriv <| absicssaOfAbsConv_logPowMul.symm ▸ h] /-! ### 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_analyticOn (f : ℕ → ℂ) : AnalyticOn ℂ (LSeries f) {s | abscissaOfAbsConv f < s.re} := (LSeries_differentiableOn f).analyticOn <| isOpen_re_gt_EReal _
NumberTheory\LSeries\Dirichlet.lean
/- Copyright (c) 2024 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ 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 only [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 open LSeries Nat Complex lemma not_LSeriesSummable_moebius_at_one : ¬ LSeriesSummable ↗μ 1 := by intro h refine not_summable_one_div_on_primes <| summable_ofReal.mp <| Summable.of_neg ?_ simp only [← Pi.neg_def, Set.indicator_comp_of_zero ofReal_zero, ofReal_inv, ofReal_natCast] refine (h.indicator {n | n.Prime}).congr (fun n ↦ ?_) by_cases hn : n ∈ {p | p.Prime} · simp only [Pi.neg_apply, Set.indicator_of_mem hn, term_of_ne_zero hn.ne_zero, moebius_apply_prime hn, cpow_one, push_cast, neg_div] · simp only [one_div, Pi.neg_apply, Set.indicator_of_not_mem hn, ofReal_zero, neg_zero] /-- 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 have h' : s.re ≤ (1 : ℂ).re := by simp only [one_re, h] exact not_LSeriesSummable_moebius_at_one <| LSeriesSummable.of_re_le_re h' H · rw [abs_intCast] -- not done by `norm_cast` 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 only [abscissaOfAbsConv, LSeriesSummable_moebius_iff, ofReal_re, Set.Ioi_def, EReal.image_coe_Ioi, EReal.coe_one] using csInf_Ioo <| EReal.coe_lt_top _ end ArithmeticFunction end Moebius /-! ### L-series of Dirichlet characters -/ open Nat open scoped ArithmeticFunction.zeta in lemma ArithmeticFunction.const_one_eq_zeta {R : Type*} [Semiring R] {n : ℕ} (hn : n ≠ 0) : (1 : ℕ → R) n = (ζ ·) n := by simp only [Pi.one_apply, zeta_apply, hn, ↓reduceIte, cast_one] 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 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 /-- 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, if_false] rcases eq_or_ne n 1 with rfl | hn' · simp only [cast_one, map_one, delta, ↓reduceIte] have : ¬ IsUnit (n : ZMod 0) := fun h ↦ hn' <| ZMod.eq_one_of_isUnit_natCast h simp only [χ.map_nonunit this, delta, hn', ↓reduceIte] /-- The Dirichlet character mod `1` corresponds to the constant function `1`. -/ lemma modOne_eq_one {R : Type*} [CommSemiring 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 ↦ ?_) rw [norm_term_eq, one_re, Real.rpow_one, Set.indicator] split_ifs with h₁ h₂ · rw [h₂, cast_zero, div_zero] · rw [h₁, χ.map_one, norm_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 only [one_re, 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 only [abscissaOfAbsConv, LSeriesSummable_iff hn χ, ofReal_re, Set.Ioi_def, EReal.image_coe_Ioi, EReal.coe_one] using csInf_Ioo <| EReal.coe_lt_top _ /-- 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 ?_ rw [Pi.mul_apply, norm_mul] exact mul_le_of_le_one_left (norm_nonneg _) <| norm_le_one .. 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 only [h, zero_mul, zero_ne_one] 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 /-- 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 s const_one_eq_zeta).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 @[deprecated (since := "2024-03-29")] alias zeta_LSeriesSummable_iff_one_lt_re := LSeriesSummable_zeta_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 simp only [LSeries, natCoe_apply, zeta_apply, cast_ite, cast_zero, cast_one, zeta_eq_tsum_one_div_nat_cpow hs] refine tsum_congr fun n ↦ ?_ rcases eq_or_ne n 0 with rfl | hn · simp only [term_zero, cast_zero, zero_cpow (ne_zero_of_one_lt_re hs), div_zero] · simp only [term_of_ne_zero hn, hn, ↓reduceIte, one_div] /-- 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 only [← natCoe_apply, ← intCoe_apply, coe_mul, coe_zeta_mul_coe_moebius, one_eq_delta, LSeries_delta, Pi.one_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 only [h, zero_mul, zero_ne_one] 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 /-- 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 /-- 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 only [zeta_apply, apply_ite, cast_zero, cast_one, LSeries.convolution_def, mul_zero, mul_one, mul_apply, natCoe_apply, ofReal_sum, ofReal_zero, log_apply, ofReal_log n.cast_nonneg] 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 Summable.of_nonneg_of_le (fun _ ↦ norm_nonneg _) (fun n ↦ norm_term_le s ?_) hf have hΛ : ‖↗Λ n‖ ≤ ‖Complex.log n‖ := by simp only [norm_eq_abs, abs_ofReal, _root_.abs_of_nonneg vonMangoldt_nonneg, ← Complex.natCast_log, _root_.abs_of_nonneg <| Real.log_natCast_nonneg n] exact ArithmeticFunction.vonMangoldt_le_log exact hΛ.trans <| by simp only [norm_eq_abs, norm_mul, Pi.one_apply, norm_one, mul_one, le_refl] 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 · simpa only [modZero_eq_delta, delta_mul_eq_smul_delta, vonMangoldt_apply_one, ofReal_zero, zero_smul, LSeries_zero, Pi.zero_apply, LSeries_delta, Pi.one_apply, div_one, zero_eq_neg] using deriv_const s 1 -- 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 s fun _ ↦ by simp only [Pi.mul_apply, mul_comm, logMul] 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 s fun {n} _ ↦ ?_).trans <| LSeries_modOne_eq ▸ LSeries_twist_vonMangoldt_eq χ₁ hs simp only [Subsingleton.eq_one (n : ZMod 1), map_one, Pi.mul_apply, one_mul] /-- 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
NumberTheory\LSeries\HurwitzZeta.lean
/- Copyright (c) 2024 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ 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 ?_ exact (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 (Differentiable.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_simp ring_nf 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) := by refine (hasSum_expZeta_of_one_lt_re a hs).congr_fun (fun n ↦ ?_) rcases eq_or_ne n 0 with rfl | hn · rw [LSeries.term_zero, Nat.cast_zero, zero_cpow (ne_zero_of_one_lt_re hs), div_zero] · apply LSeries.term_of_ne_zero hn /-! ## 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
NumberTheory\LSeries\HurwitzZetaEven.lean
/- Copyright (c) 2024 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ 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 Classical 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 Hurwit 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 only [I_sq, mul_neg, mul_one, neg_mul, neg_neg, sub_neg_eq_add, ofReal_exp, ofReal_add, ofReal_mul, ofReal_ofNat] 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 unfold evenKernel simp only [neg_mul, Function.Periodic.lift_coe, ofReal_mul, ofReal_exp, ofReal_neg, ofReal_pow, re_eq_add_conj, jacobiTheta₂_conj, map_mul, conj_ofReal, conj_I, mul_neg, neg_neg, jacobiTheta₂_neg_left, ← 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 have : (I * ↑x).im ≤ 0 := by rwa [I_mul_im, ofReal_re] induction' a using QuotientAddGroup.induction_on with a' rw [← ofReal_inj, evenKernel_def, jacobiTheta₂_undef _ this, mul_zero, ofReal_zero] /-- 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_rw [ofReal_add, ofReal_one, jacobiTheta₂_add_left]).lift a lemma cosKernel_def (a x : ℝ) : ↑(cosKernel ↑a x) = jacobiTheta₂ a (I * x) := by unfold cosKernel simp only [Function.Periodic.lift_coe, re_eq_add_conj, jacobiTheta₂_conj, conj_ofReal, map_mul, conj_I, neg_mul, neg_neg, ← 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 a' rw [← ofReal_inj, cosKernel_def, jacobiTheta₂_undef _ (by rwa [I_mul_im, ofReal_re]), ofReal_zero] /-- For `a = 0`, both kernels agree. -/ lemma evenKernel_eq_cosKernel_of_zero : evenKernel 0 = cosKernel 0 := by ext1 x simp only [← QuotientAddGroup.mk_zero, ← ofReal_inj, evenKernel_def, ofReal_zero, sq, mul_zero, zero_mul, Complex.exp_zero, one_mul, cosKernel_def] lemma evenKernel_neg (a : UnitAddCircle) (x : ℝ) : evenKernel (-a) x = evenKernel a x := by induction' a using QuotientAddGroup.induction_on with a' simp only [← QuotientAddGroup.mk_neg, ← ofReal_inj, evenKernel_def, ofReal_neg, neg_sq, neg_mul, jacobiTheta₂_neg_left] lemma cosKernel_neg (a : UnitAddCircle) (x : ℝ) : cosKernel (-a) x = cosKernel a x := by induction' a using QuotientAddGroup.induction_on with a' simp only [← QuotientAddGroup.mk_neg, ← ofReal_inj, cosKernel_def, ofReal_neg, jacobiTheta₂_neg_left] lemma continuousOn_evenKernel (a : UnitAddCircle) : ContinuousOn (evenKernel a) (Ioi 0) := by induction' a using QuotientAddGroup.induction_on with a' apply continuous_re.comp_continuousOn (f := fun x ↦ (evenKernel a' x : ℂ)) simp only [evenKernel_def a'] refine ContinuousAt.continuousOn (fun x hx ↦ ((Continuous.continuousAt ?_).mul ?_)) · exact Complex.continuous_exp.comp (continuous_const.mul continuous_ofReal) · have h := continuousAt_jacobiTheta₂ (a' * I * x) (?_ : 0 < im (I * x)) · exact h.comp (f := fun u : ℝ ↦ (a' * I * u, I * u)) (by fun_prop) · rwa [mul_im, I_re, I_im, zero_mul, one_mul, zero_add, ofReal_re] lemma continuousOn_cosKernel (a : UnitAddCircle) : ContinuousOn (cosKernel a) (Ioi 0) := by induction' a using QuotientAddGroup.induction_on with a' apply continuous_re.comp_continuousOn (f := fun x ↦ (cosKernel a' x : ℂ)) simp only [cosKernel_def] refine ContinuousAt.continuousOn (fun x hx ↦ ?_) have : 0 < im (I * x) := by rwa [mul_im, I_re, I_im, zero_mul, one_mul, zero_add, ofReal_re] exact (continuousAt_jacobiTheta₂ a' this).comp (f := fun u : ℝ ↦ (_, 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_lt 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 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_self, 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 : ℤ) : ↑(rexp (-π * (↑n + a) ^ 2 * t)) = cexp (-↑π * ↑a ^ 2 * ↑t) * jacobiTheta₂_term n (↑a * I * ↑t) (I * ↑t) := by rw [jacobiTheta₂_term, ← Complex.exp_add] push_cast congr ring_nf simp only [I_sq, mul_neg, neg_mul, mul_one] simp only [this] apply (hasSum_jacobiTheta₂_term _ (by rwa [I_mul_im, ofReal_re])).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) * ↑(rexp (-π * ↑n ^ 2 * t)) = jacobiTheta₂_term n (↑a) (I * ↑t) := by rw [jacobiTheta₂_term, ofReal_exp, ← Complex.exp_add] push_cast ring_nf simp only [I_sq, mul_neg, neg_mul, mul_one, sub_eq_add_neg] simp only [this] exact hasSum_jacobiTheta₂_term _ (by rwa [I_mul_im, ofReal_re]) /-- 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 simp_rw [← Int.cast_add, Int.cast_eq_zero, add_eq_zero_iff_eq_neg] simpa only [Int.cast_add, neg_mul, Int.cast_neg, add_left_neg, ne_eq, OfNat.ofNat_ne_zero, not_false_eq_true, zero_pow, mul_zero, zero_mul, Real.exp_zero] 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 rwa [Int.cast_neg, 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 says simpa only [neg_mul, ofReal_exp, ofReal_neg, ofReal_mul, ofReal_pow, ofReal_intCast, Int.cast_zero, mul_zero, Complex.exp_zero, ne_eq, OfNat.ofNat_ne_zero, not_false_eq_true, zero_pow, zero_mul, Real.exp_zero, ofReal_one, mul_one] 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 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 ht simp only [← (hasSum_int_evenKernel b ht).tsum_eq, HurwitzKernelBounds.F_int, HurwitzKernelBounds.f_int, pow_zero, one_mul, Function.Periodic.lift_coe] /-- 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 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)⟩ simp only [eq_false_intro one_ne_zero, if_false, sub_zero] filter_upwards [eventually_gt_atTop 0] with t ht rw [← (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 hk := one_half_pos 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 rw [← isBigO_norm_left] at hp' ⊢ have (x : ℝ) : ‖(ofReal' ∘ cosKernel a) x - 1‖ = ‖cosKernel a x - 1‖ := by rw [← norm_real, ofReal_sub, ofReal_one, Function.comp_apply] simp only [this] exact hp'.trans (isLittleO_exp_neg_mul_rpow_atTop hp _).isBigO h_feq x hx := by simp_rw [Function.comp_apply, one_mul, smul_eq_mul, ← ofReal_mul, evenKernel_functional_equation, one_div x, one_div x⁻¹, inv_rpow (le_of_lt hx), one_div, inv_inv] lemma hurwitzEvenFEPair_zero_symm : (hurwitzEvenFEPair 0).symm = hurwitzEvenFEPair 0 := by unfold hurwitzEvenFEPair WeakFEPair.symm congr 1 <;> simp only [evenKernel_eq_cosKernel_of_zero, inv_one, if_true] lemma hurwitzEvenFEPair_neg (a : UnitAddCircle) : hurwitzEvenFEPair (-a) = hurwitzEvenFEPair a := by unfold hurwitzEvenFEPair congr 1 <;> simp only [Function.comp_def, evenKernel_neg, cosKernel_neg, neg_eq_zero] /-! ## 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 -/ lemma completedHurwitzZetaEven_neg (a : UnitAddCircle) (s : ℂ) : completedHurwitzZetaEven (-a) s = completedHurwitzZetaEven a s := by simp only [completedHurwitzZetaEven, hurwitzEvenFEPair_neg] lemma completedHurwitzZetaEven₀_neg (a : UnitAddCircle) (s : ℂ) : completedHurwitzZetaEven₀ (-a) s = completedHurwitzZetaEven₀ a s := by simp only [completedHurwitzZetaEven₀, hurwitzEvenFEPair_neg] lemma completedCosZeta_neg (a : UnitAddCircle) (s : ℂ) : completedCosZeta (-a) s = completedCosZeta a s := by simp only [completedCosZeta, hurwitzEvenFEPair_neg] lemma completedCosZeta₀_neg (a : UnitAddCircle) (s : ℂ) : completedCosZeta₀ (-a) s = completedCosZeta₀ a s := by simp only [completedCosZeta₀, hurwitzEvenFEPair_neg] /-- 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 norm_num : (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 norm_num : (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 _ · simp only [ne_eq, div_eq_zero_iff, OfNat.ofNat_ne_zero, or_false] rcases hs with h | h · exact Or.inl h · simp only [hurwitzEvenFEPair, one_div, h, ↓reduceIte, or_true] · 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 only [push_cast] using h ∘ (div_left_inj' two_ne_zero).mp · simp_rw [eq_false_intro ha, if_false] 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, one_mul] at h1 refine (h1.comp <| zero_div (2 : ℂ) ▸ (tendsto_div_two_punctured_nhds 0)).congr (fun s ↦ ?_) rw [completedHurwitzZetaEven, Function.comp_apply, 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 ↦ ?_) rw [completedCosZeta, Function.comp_apply, 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 only [zero_div, 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_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, norm_norm, 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 only [c, Int.cast_eq_zero, ← Int.cast_abs, ofReal_intCast, 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_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 only [Function.update_noteq 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, cpow_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_noteq h] · simpa only [Gammaℝ, Function.update_same, neg_zero, zero_div, cpow_zero, Complex.Gamma_zero, mul_zero, div_zero, ite_eq_right_iff, div_eq_zero_iff, neg_eq_zero, one_ne_zero, OfNat.ofNat_ne_zero, or_self, imp_false, ne_eq, not_true_eq_false, or_false] using h lemma hurwitzZetaEven_apply_zero (a : UnitAddCircle) : hurwitzZetaEven a 0 = if a = 0 then -1 / 2 else 0 := Function.update_same _ _ _ lemma hurwitzZetaEven_neg (a : UnitAddCircle) (s : ℂ) : hurwitzZetaEven (-a) s = hurwitzZetaEven a s := by simp_rw [hurwitzZetaEven, neg_eq_zero, completedHurwitzZetaEven_neg] /-- 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_noteq this, Gammaℝ_eq_zero_iff.mpr ⟨n + 1, by rw [neg_mul, Nat.cast_add_one]⟩, 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_rw [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_noteq 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_self, 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 only [one_div, sub_self, div_zero, Gammaℝ_one, div_one, sub_zero] 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).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_noteq (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 only [← abs_neg (n + 1 - a), neg_sub', sub_neg_eq_add, add_div, Int.cast_natCast, Int.cast_neg, Int.cast_add, Int.cast_one] /-- 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 [_root_.abs_of_nonneg (by linarith [ha.1, ha.2])] <;> simp only [one_div, ofReal_sub, ofReal_add, ofReal_natCast, ofReal_one] /-! ## 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_same _ _ _ lemma cosZeta_neg (a : UnitAddCircle) (s : ℂ) : cosZeta (-a) s = cosZeta a s := by simp_rw [cosZeta, completedCosZeta_neg] /-- 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_noteq 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').mul (differentiable_Gammaℝ_inv.differentiableAt)).congr_of_eventuallyEq filter_upwards [isOpen_compl_singleton.mem_nhds one_ne_zero] with x hx simp_rw [cosZeta, Function.update_noteq 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_noteq (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) := by refine (hasSum_nat_cosZeta a hs).congr_fun (fun n ↦ ?_) rcases eq_or_ne n 0 with rfl | hn · rw [LSeries.term_zero, Nat.cast_zero, Nat.cast_zero, zero_cpow (ne_zero_of_one_lt_re hs), div_zero] · apply LSeries.term_of_ne_zero hn /-! ## 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_noteq (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_noteq, 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
NumberTheory\LSeries\HurwitzZetaOdd.lean
/- Copyright (c) 2024 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ 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 hiding abs_of_nonneg open 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 only [jacobiTheta₂'', jacobiTheta₂'_conj, jacobiTheta₂_conj, ← exp_conj, conj_ofReal, conj_I, map_mul, map_add, map_div₀, mul_neg, map_pow, map_ofNat, neg_mul, div_neg, neg_div, jacobiTheta₂'_neg_left, 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 only [jacobiTheta₂'', jacobiTheta₂'_neg_left, jacobiTheta₂_neg_left, neg_mul, neg_div, ← neg_add, mul_neg, neg_sq] 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 norm_num), 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 intro a; simp only [ofReal_add, ofReal_one, jacobiTheta₂''_add_left]).lift a lemma oddKernel_def (a x : ℝ) : ↑(oddKernel a x) = jacobiTheta₂'' a (I * x) := by rw [oddKernel, Function.Periodic.lift_coe, ← conj_eq_iff_re, jacobiTheta₂''_conj, map_mul, conj_I, neg_mul, neg_neg, conj_ofReal, conj_ofReal] 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 a' rw [← ofReal_eq_zero, oddKernel_def', jacobiTheta₂_undef, jacobiTheta₂'_undef, zero_div, zero_add, mul_zero, mul_zero] <;> rwa [I_mul_im, ofReal_re] /-- 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 intro ξ; simp_rw [ofReal_add, ofReal_one, jacobiTheta₂'_add_left]).lift a lemma sinKernel_def (a x : ℝ) : ↑(sinKernel ↑a x) = jacobiTheta₂' a (I * x) / (-2 * π) := by rw [sinKernel, Function.Periodic.lift_coe, re_eq_add_conj, map_div₀, jacobiTheta₂'_conj] simp_rw [map_mul, conj_I, conj_ofReal, map_neg, map_ofNat, neg_mul, neg_neg, add_self_div_two] lemma sinKernel_undef (a : UnitAddCircle) {x : ℝ} (hx : x ≤ 0) : sinKernel a x = 0 := by induction' a using QuotientAddGroup.induction_on with a' rw [← ofReal_eq_zero, sinKernel_def, jacobiTheta₂'_undef _ (by rwa [I_mul_im, ofReal_re]), zero_div] lemma oddKernel_neg (a : UnitAddCircle) (x : ℝ) : oddKernel (-a) x = -oddKernel a x := by induction' a using QuotientAddGroup.induction_on with a' rw [← ofReal_inj, ← QuotientAddGroup.mk_neg, oddKernel_def, ofReal_neg, ofReal_neg, oddKernel_def, jacobiTheta₂''_neg_left] lemma oddKernel_zero (x : ℝ) : oddKernel 0 x = 0 := by simpa only [neg_zero, eq_neg_self_iff] 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 a' rw [← ofReal_inj, ← QuotientAddGroup.mk_neg, ofReal_neg, sinKernel_def, sinKernel_def, ofReal_neg, jacobiTheta₂'_neg_left, neg_div] lemma sinKernel_zero (x : ℝ) : sinKernel 0 x = 0 := by simpa only [neg_zero, eq_neg_self_iff] 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 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 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 (ContinuousAt.continuousOn (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_lt 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 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 only [neg_mul, mul_neg, neg_neg, mul_assoc] · exact mul_right_comm (2 * π * I) a n · simp only [← mul_assoc, mul_comm _ I, I_mul_I, neg_one_mul] 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, sq (0 : ℂ), 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 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 only [← (hasSum_int_oddKernel b ht).tsum_eq, Real.norm_eq_abs, HurwitzKernelBounds.F_int, HurwitzKernelBounds.f_int, pow_one, norm_mul, 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 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 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' ⊢ simp_rw [Function.comp_def, sub_zero, norm_real] exact 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' ⊢ simp_rw [Function.comp_def, sub_zero, norm_real] exact hv'.trans (isLittleO_exp_neg_mul_rpow_atTop hv _).isBigO h_feq x hx := by simp_rw [Function.comp_apply, one_mul, smul_eq_mul, ← ofReal_mul, oddKernel_functional_equation a, one_div x, one_div x⁻¹, inv_rpow (le_of_lt hx), one_div, inv_inv] 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 only [completedHurwitzZetaOdd, StrongFEPair.Λ, hurwitzOddFEPair, mellin, Function.comp_def, oddKernel_neg, ofReal_neg, smul_neg] rw [integral_neg, neg_div] lemma completedSinZeta_neg (a : UnitAddCircle) (s : ℂ) : completedSinZeta (-a) s = -completedSinZeta a s := by simp only [completedSinZeta, StrongFEPair.Λ, mellin, StrongFEPair.symm, WeakFEPair.symm, hurwitzOddFEPair, Function.comp_def, sinKernel_neg, ofReal_neg, smul_neg] rw [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 rw [← completedHurwitzZetaOdd_one_sub, sub_sub_cancel] /-! ## 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 <;> · simp only [Int.cast_neg, abs_neg, Int.cast_natCast, Nat.abs_cast] rwa [summable_one_div_nat_rpow] refine (mellin_div_const .. ▸ hasSum_mellin_pi_mul_sq' (zero_lt_one.trans hs) hF h_sum).congr_fun fun n ↦ ?_ simp only [Int.sign_eq_sign, SignType.intCast_cast, sign_intCast, ← Int.cast_abs, ofReal_intCast] 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 only [Nat.cast_zero, mul_zero, Real.sin_zero, ofReal_zero, zero_div, mul_neg, Int.sign_zero, Int.cast_zero, Complex.exp_zero, mul_one, neg_zero, add_zero] 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 only [r, c, push_cast, div_mul_eq_mul_div, one_mul] 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 [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 only [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 · rw [sign_pos hb, SignType.coe_one] · 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 only [Nat.cast_zero, Int.sign_zero, Int.cast_zero, mul_zero, zero_mul, neg_zero, sub_self, zero_div, zero_add] /-- 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) := by refine (hasSum_nat_sinZeta a hs).congr_fun (fun n ↦ ?_) rcases eq_or_ne n 0 with rfl | hn · rw [LSeries.term_zero, Nat.cast_zero, mul_zero, Real.sin_zero, ofReal_zero, zero_div] · apply LSeries.term_of_ne_zero hn /-- 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
NumberTheory\LSeries\HurwitzZetaValues.lean
/- Copyright (c) 2024 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ 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`. 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 ↦ ?_ rw [mul_comm (1 / _), mul_one_div, ofReal_div, mul_assoc (2 * π), mul_comm x n, ← mul_assoc, ← Nat.cast_ofNat (R := ℂ), ← Nat.cast_mul, cpow_natCast, ofReal_pow, ofReal_natCast] · simp only [ofReal_mul, ofReal_div, ofReal_pow, ofReal_natCast, ofReal_ofNat, ofReal_neg, ofReal_one] congr 1 have : (Polynomial.bernoulli (2 * k)).map (algebraMap ℚ ℂ) = _ := (Polynomial.map_map (algebraMap ℚ ℝ) ofReal _).symm rw [this, ← ofReal_eq_coe, ← ofReal_eq_coe] apply Polynomial.map_aeval_eq_aeval_map simp only [Algebra.id.map_eq_id, RingHomCompTriple.comp_eq] · rw [← Nat.cast_ofNat, ← Nat.cast_one, ← Nat.cast_mul, natCast_re, Nat.cast_lt] omega /-- 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 ↦ ?_ rw [mul_comm (1 / _), mul_one_div, ofReal_div, mul_assoc (2 * π), mul_comm x n, ← mul_assoc] congr 1 rw [← Nat.cast_ofNat, ← Nat.cast_mul, ← Nat.cast_add_one, cpow_natCast, ofReal_pow, ofReal_natCast] · simp only [ofReal_mul, ofReal_div, ofReal_pow, ofReal_natCast, ofReal_ofNat, ofReal_neg, ofReal_one] congr 1 have : (Polynomial.bernoulli (2 * k + 1)).map (algebraMap ℚ ℂ) = _ := (Polynomial.map_map (algebraMap ℚ ℝ) ofReal _).symm rw [this, ← ofReal_eq_coe, ← ofReal_eq_coe] apply Polynomial.map_aeval_eq_aeval_map simp only [Algebra.id.map_eq_id, RingHomCompTriple.comp_eq] · rw [← Nat.cast_ofNat, ← Nat.cast_one, ← Nat.cast_mul, ← Nat.cast_add_one, natCast_re, Nat.cast_lt, lt_add_iff_pos_left] exact mul_pos two_pos (Nat.pos_of_ne_zero hk) /-- 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 omega)] 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 only [mul_eq_one, OfNat.ofNat_ne_one, false_and, not_false_eq_true] have h3 : Gammaℂ (2 * k) ≠ 0 := by refine mul_ne_zero (mul_ne_zero two_ne_zero ?_) (Gamma_ne_zero h1) simp only [ne_eq, cpow_eq_zero_iff, mul_eq_zero, OfNat.ofNat_ne_zero, ofReal_eq_zero, pi_ne_zero, Nat.cast_eq_zero, false_or, false_and, not_false_eq_true] 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 only [ne_eq, cpow_eq_zero_iff, mul_eq_zero, OfNat.ofNat_ne_zero, ofReal_eq_zero, pi_ne_zero, Nat.cast_eq_zero, false_or, false_and, not_false_eq_true] 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 only [Nat.cast_succ, ← neg_mul] 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 omega : n ≠ 0) hx · exact_mod_cast hurwitzZeta_one_sub_two_mul_nat (by omega : 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 omega)] simp only [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 only [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 norm_num, zeta_nat_eq_tsum_of_gt_one (by norm_num : 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]
NumberTheory\LSeries\Linearity.lean
/- Copyright (c) 2024 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ 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 only [term_zero, Pi.add_apply, add_zero] · simp only [term_of_ne_zero (Nat.succ_ne_zero _), Pi.add_apply, 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 rw [term_add, Pi.add_apply] 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 only [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 only [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 only [LSeries, term_add, Pi.add_apply] using tsum_add hf hg /-! ### Negation -/ lemma LSeries.term_neg (f : ℕ → ℂ) (s : ℂ) : term (-f) s = -term f s := by ext ⟨- | n⟩ · simp only [Nat.zero_eq, term_zero, Pi.neg_apply, neg_zero] · simp only [term_of_ne_zero (Nat.succ_ne_zero _), Pi.neg_apply, Nat.cast_succ, neg_div] lemma LSeries.term_neg_apply (f : ℕ → ℂ) (s : ℂ) (n : ℕ) : term (-f) s n = -term f s n := by rw [term_neg, Pi.neg_apply] lemma LSeriesHasSum.neg {f : ℕ → ℂ} {s a : ℂ} (hf : LSeriesHasSum f s a) : LSeriesHasSum (-f) s (-a) := by simpa only [LSeriesHasSum, term_neg] using HasSum.neg hf lemma LSeriesSummable.neg {f : ℕ → ℂ} {s : ℂ} (hf : LSeriesSummable f s) : LSeriesSummable (-f) s := by simpa only [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 only [LSeries, term_neg_apply, tsum_neg] /-! ### Subtraction -/ open LSeries 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 only [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 only [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 only [LSeries, term_sub, Pi.sub_apply] using tsum_sub hf hg /-! ### Scalar multiplication -/ lemma LSeries.term_smul (f : ℕ → ℂ) (c s : ℂ) : term (c • f) s = c • term f s := by ext ⟨- | n⟩ · simp only [Nat.zero_eq, term_zero, Pi.smul_apply, smul_eq_mul, mul_zero] · simp only [term_of_ne_zero (Nat.succ_ne_zero _), Pi.smul_apply, smul_eq_mul, Nat.cast_succ, mul_div_assoc] lemma LSeries.term_smul_apply (f : ℕ → ℂ) (c s : ℂ) (n : ℕ) : term (c • f) s n = c * term f s n := by rw [term_smul, Pi.smul_apply, smul_eq_mul] lemma LSeriesHasSum.smul {f : ℕ → ℂ} (c : ℂ) {s a : ℂ} (hf : LSeriesHasSum f s a) : LSeriesHasSum (c • f) s (c * a) := by simpa only [LSeriesHasSum, term_smul, smul_eq_mul] using hf.const_smul c lemma LSeriesSummable.smul {f : ℕ → ℂ} (c : ℂ) {s : ℂ} (hf : LSeriesSummable f s) : LSeriesSummable (c • f) s := by simpa only [LSeriesSummable, term_smul, smul_eq_mul] 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 only [ne_eq, hc, not_false_eq_true, inv_smul_smul₀] 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 only [LSeries, term_smul_apply, tsum_mul_left]
NumberTheory\LSeries\MellinEqDirichlet.lean
/- Copyright (c) 2024 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ 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 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_mul_left] 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 · simpa only [hai, zero_mul, mul_zero] using integrable_zero _ _ _ 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_mul_left] rw [← mul_div_assoc, mul_comm (Real.Gamma _), mul_div_assoc, norm_mul ‖a i‖, norm_norm] rcases hp i with hai | hpi · simp only [hai, norm_zero, zero_mul] 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 measurableSet_Ioi (fun t ht ↦ ?_) rw [norm_mul, norm_real, Real.norm_eq_abs, Real.abs_exp, Complex.norm_eq_abs, abs_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 <;> 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 only [a', ite_mul, zero_mul] 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, if_false, 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 [← _root_.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 [← _root_.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, ← ofReal_eq_coe, SignType.map_cast] field_simp [h] ring_nf · 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)]
NumberTheory\LSeries\RiemannZeta.lean
/- Copyright (c) 2023 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ 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`. For computation of the constant term as `s → 1`, see `Mathlib.NumberTheory.Harmonic.ZetaAsymp`. ## Outline of proofs: These results are mostly special cases of more general results for even Hurwitz zeta functions proved in `Mathlib.NumberTheory.LSeries.HurwitzZetaEven`. -/ open MeasureTheory Set Filter Asymptotics TopologicalSpace Real Asymptotics Classical HurwitzZeta open Complex hiding exp norm_eq_abs abs_of_nonneg abs_two continuous_exp open scoped Topology Real Nat 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_right_eq_self, 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_same, if_true] lemma riemannZeta_def_of_ne_zero {s : ℂ} (hs : s ≠ 0) : riemannZeta s = completedRiemannZeta s / Gammaℝ s := by rw [riemannZeta, hurwitzZetaEven, Function.update_noteq 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 [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] /-- 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 /- naming scheme was changed from from `riemannCompletedZeta` to `completedRiemannZeta`; add aliases for the old names -/ section aliases @[deprecated (since := "2024-05-27")] noncomputable alias riemannCompletedZeta₀ := completedRiemannZeta₀ @[deprecated (since := "2024-05-27")] noncomputable alias riemannCompletedZeta := completedRiemannZeta @[deprecated (since := "2024-05-27")] alias riemannCompletedZeta₀_one_sub := completedRiemannZeta₀_one_sub @[deprecated (since := "2024-05-27")] alias riemannCompletedZeta_one_sub := completedRiemannZeta_one_sub @[deprecated (since := "2024-05-27")] alias riemannCompletedZeta_residue_one := completedRiemannZeta_residue_one end aliases
NumberTheory\ModularForms\Basic.lean
/- Copyright (c) 2022 Chris Birkbeck. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Birkbeck -/ import Mathlib.Algebra.DirectSum.Algebra import Mathlib.Analysis.Complex.UpperHalfPlane.FunctionsBoundedAtInfty import Mathlib.Analysis.Complex.UpperHalfPlane.Manifold import Mathlib.Geometry.Manifold.MFDeriv.SpecificFunctions import Mathlib.NumberTheory.ModularForms.SlashInvariantForms /-! # Modular forms This file defines modular forms and proves some basic properties about them. Including constructing the graded ring of modular forms. We begin by defining modular forms and cusp forms as extension of `SlashInvariantForm`s then we define the space of modular forms, cusp forms and prove that the product of two modular forms is a modular form. -/ open Complex UpperHalfPlane open scoped Topology Manifold UpperHalfPlane noncomputable section local notation "GL(" n ", " R ")" "⁺" => Matrix.GLPos (Fin n) R local notation "SL(" n ", " R ")" => Matrix.SpecialLinearGroup (Fin n) R section ModularForm open ModularForm variable (F : Type*) (Γ : Subgroup SL(2, ℤ)) (k : ℤ) open scoped ModularForm /-- These are `SlashInvariantForm`'s that are holomorphic and bounded at infinity. -/ structure ModularForm extends SlashInvariantForm Γ k where holo' : MDifferentiable 𝓘(ℂ) 𝓘(ℂ) (toSlashInvariantForm : ℍ → ℂ) bdd_at_infty' : ∀ A : SL(2, ℤ), IsBoundedAtImInfty (toSlashInvariantForm ∣[k] A) /-- The `SlashInvariantForm` associated to a `ModularForm`. -/ add_decl_doc ModularForm.toSlashInvariantForm /-- These are `SlashInvariantForm`s that are holomorphic and zero at infinity. -/ structure CuspForm extends SlashInvariantForm Γ k where holo' : MDifferentiable 𝓘(ℂ) 𝓘(ℂ) (toSlashInvariantForm : ℍ → ℂ) zero_at_infty' : ∀ A : SL(2, ℤ), IsZeroAtImInfty (toSlashInvariantForm ∣[k] A) /-- The `SlashInvariantForm` associated to a `CuspForm`. -/ add_decl_doc CuspForm.toSlashInvariantForm /-- `ModularFormClass F Γ k` says that `F` is a type of bundled functions that extend `SlashInvariantFormClass` by requiring that the functions be holomorphic and bounded at infinity. -/ class ModularFormClass (F : Type*) (Γ : outParam <| Subgroup (SL(2, ℤ))) (k : outParam ℤ) [FunLike F ℍ ℂ] extends SlashInvariantFormClass F Γ k : Prop where holo : ∀ f : F, MDifferentiable 𝓘(ℂ) 𝓘(ℂ) (f : ℍ → ℂ) bdd_at_infty : ∀ (f : F) (A : SL(2, ℤ)), IsBoundedAtImInfty (f ∣[k] A) /-- `CuspFormClass F Γ k` says that `F` is a type of bundled functions that extend `SlashInvariantFormClass` by requiring that the functions be holomorphic and zero at infinity. -/ class CuspFormClass (F : Type*) (Γ : outParam <| Subgroup (SL(2, ℤ))) (k : outParam ℤ) [FunLike F ℍ ℂ] extends SlashInvariantFormClass F Γ k : Prop where holo : ∀ f : F, MDifferentiable 𝓘(ℂ) 𝓘(ℂ) (f : ℍ → ℂ) zero_at_infty : ∀ (f : F) (A : SL(2, ℤ)), IsZeroAtImInfty (f ∣[k] A) instance (priority := 100) ModularForm.funLike : FunLike (ModularForm Γ k) ℍ ℂ where coe f := f.toFun coe_injective' f g h := by cases f; cases g; congr; exact DFunLike.ext' h instance (priority := 100) ModularFormClass.modularForm : ModularFormClass (ModularForm Γ k) Γ k where slash_action_eq f := f.slash_action_eq' holo := ModularForm.holo' bdd_at_infty := ModularForm.bdd_at_infty' instance (priority := 100) CuspForm.funLike : FunLike (CuspForm Γ k) ℍ ℂ where coe f := f.toFun coe_injective' f g h := by cases f; cases g; congr; exact DFunLike.ext' h instance (priority := 100) CuspFormClass.cuspForm : CuspFormClass (CuspForm Γ k) Γ k where slash_action_eq f := f.slash_action_eq' holo := CuspForm.holo' zero_at_infty := CuspForm.zero_at_infty' variable {F Γ k} theorem ModularForm.toFun_eq_coe (f : ModularForm Γ k) : f.toFun = (f : ℍ → ℂ) := rfl @[simp] theorem ModularForm.toSlashInvariantForm_coe (f : ModularForm Γ k) : ⇑f.1 = f := rfl theorem CuspForm.toFun_eq_coe {f : CuspForm Γ k} : f.toFun = (f : ℍ → ℂ) := rfl @[simp] theorem CuspForm.toSlashInvariantForm_coe (f : CuspForm Γ k) : ⇑f.1 = f := rfl @[ext] theorem ModularForm.ext {f g : ModularForm Γ k} (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h @[ext] theorem CuspForm.ext {f g : CuspForm Γ k} (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h /-- Copy of a `ModularForm` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def ModularForm.copy (f : ModularForm Γ k) (f' : ℍ → ℂ) (h : f' = ⇑f) : ModularForm Γ k where toSlashInvariantForm := f.1.copy f' h holo' := h.symm ▸ f.holo' bdd_at_infty' A := h.symm ▸ f.bdd_at_infty' A /-- Copy of a `CuspForm` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def CuspForm.copy (f : CuspForm Γ k) (f' : ℍ → ℂ) (h : f' = ⇑f) : CuspForm Γ k where toSlashInvariantForm := f.1.copy f' h holo' := h.symm ▸ f.holo' zero_at_infty' A := h.symm ▸ f.zero_at_infty' A end ModularForm namespace ModularForm open SlashInvariantForm variable {F : Type*} {Γ : Subgroup SL(2, ℤ)} {k : ℤ} instance add : Add (ModularForm Γ k) := ⟨fun f g => { toSlashInvariantForm := f + g holo' := f.holo'.add g.holo' bdd_at_infty' := fun A => by simpa using (f.bdd_at_infty' A).add (g.bdd_at_infty' A) }⟩ @[simp] theorem coe_add (f g : ModularForm Γ k) : ⇑(f + g) = f + g := rfl @[simp] theorem add_apply (f g : ModularForm Γ k) (z : ℍ) : (f + g) z = f z + g z := rfl instance instZero : Zero (ModularForm Γ k) := ⟨ { toSlashInvariantForm := 0 holo' := fun _ => mdifferentiableAt_const 𝓘(ℂ, ℂ) 𝓘(ℂ, ℂ) bdd_at_infty' := fun A => by simpa using zero_form_isBoundedAtImInfty } ⟩ @[simp] theorem coe_zero : ⇑(0 : ModularForm Γ k) = (0 : ℍ → ℂ) := rfl @[simp] theorem zero_apply (z : ℍ) : (0 : ModularForm Γ k) z = 0 := rfl section variable {α : Type*} [SMul α ℂ] [IsScalarTower α ℂ ℂ] instance instSMul : SMul α (ModularForm Γ k) := ⟨fun c f => { toSlashInvariantForm := c • f.1 holo' := by simpa using f.holo'.const_smul (c • (1 : ℂ)) bdd_at_infty' := fun A => by simpa using (f.bdd_at_infty' A).const_smul_left (c • (1 : ℂ)) }⟩ @[simp] theorem coe_smul (f : ModularForm Γ k) (n : α) : ⇑(n • f) = n • ⇑f := rfl @[simp] theorem smul_apply (f : ModularForm Γ k) (n : α) (z : ℍ) : (n • f) z = n • f z := rfl end instance instNeg : Neg (ModularForm Γ k) := ⟨fun f => { toSlashInvariantForm := -f.1 holo' := f.holo'.neg bdd_at_infty' := fun A => by simpa using (f.bdd_at_infty' A).neg }⟩ @[simp] theorem coe_neg (f : ModularForm Γ k) : ⇑(-f) = -f := rfl @[simp] theorem neg_apply (f : ModularForm Γ k) (z : ℍ) : (-f) z = -f z := rfl instance instSub : Sub (ModularForm Γ k) := ⟨fun f g => f + -g⟩ @[simp] theorem coe_sub (f g : ModularForm Γ k) : ⇑(f - g) = f - g := rfl @[simp] theorem sub_apply (f g : ModularForm Γ k) (z : ℍ) : (f - g) z = f z - g z := rfl instance : AddCommGroup (ModularForm Γ k) := DFunLike.coe_injective.addCommGroup _ rfl coe_add coe_neg coe_sub coe_smul coe_smul /-- Additive coercion from `ModularForm` to `ℍ → ℂ`. -/ @[simps] def coeHom : ModularForm Γ k →+ ℍ → ℂ where toFun f := f map_zero' := coe_zero map_add' _ _ := rfl instance : Module ℂ (ModularForm Γ k) := Function.Injective.module ℂ coeHom DFunLike.coe_injective fun _ _ => rfl instance : Inhabited (ModularForm Γ k) := ⟨0⟩ /-- The modular form of weight `k_1 + k_2` given by the product of two modular forms of weights `k_1` and `k_2`. -/ def mul {k_1 k_2 : ℤ} {Γ : Subgroup SL(2, ℤ)} (f : ModularForm Γ k_1) (g : ModularForm Γ k_2) : ModularForm Γ (k_1 + k_2) where toSlashInvariantForm := f.1.mul g.1 holo' := f.holo'.mul g.holo' bdd_at_infty' A := by -- Porting note: was `by simpa using ...` -- `mul_slash_SL2` is no longer a `simp` and `simpa only [mul_slash_SL2] using ...` failed rw [SlashInvariantForm.coe_mul, mul_slash_SL2] exact (f.bdd_at_infty' A).mul (g.bdd_at_infty' A) @[simp] theorem mul_coe {k_1 k_2 : ℤ} {Γ : Subgroup SL(2, ℤ)} (f : ModularForm Γ k_1) (g : ModularForm Γ k_2) : (f.mul g : ℍ → ℂ) = f * g := rfl /-- The constant function with value `x : ℂ` as a modular form of weight 0 and any level. -/ @[simps! (config := .asFn) toFun toSlashInvariantForm] def const (x : ℂ) : ModularForm Γ 0 where toSlashInvariantForm := .const x holo' x := mdifferentiableAt_const 𝓘(ℂ, ℂ) 𝓘(ℂ, ℂ) bdd_at_infty' A := by simpa only [SlashInvariantForm.const_toFun, ModularForm.is_invariant_const] using atImInfty.const_boundedAtFilter x instance : One (ModularForm Γ 0) where one := { const 1 with toSlashInvariantForm := 1 } @[simp] theorem one_coe_eq_one : ⇑(1 : ModularForm Γ 0) = 1 := rfl instance (Γ : Subgroup SL(2, ℤ)) : NatCast (ModularForm Γ 0) where natCast n := const n @[simp, norm_cast] lemma coe_natCast (Γ : Subgroup SL(2, ℤ)) (n : ℕ) : ⇑(n : ModularForm Γ 0) = n := rfl lemma toSlashInvariantForm_natCast (Γ : Subgroup SL(2, ℤ)) (n : ℕ) : (n : ModularForm Γ 0).toSlashInvariantForm = n := rfl instance (Γ : Subgroup SL(2, ℤ)) : IntCast (ModularForm Γ 0) where intCast z := const z @[simp, norm_cast] lemma coe_intCast (Γ : Subgroup SL(2, ℤ)) (z : ℤ) : ⇑(z : ModularForm Γ 0) = z := rfl lemma toSlashInvariantForm_intCast (Γ : Subgroup SL(2, ℤ)) (z : ℤ) : (z : ModularForm Γ 0).toSlashInvariantForm = z := rfl end ModularForm namespace CuspForm open ModularForm variable {F : Type*} {Γ : Subgroup SL(2, ℤ)} {k : ℤ} instance hasAdd : Add (CuspForm Γ k) := ⟨fun f g => { toSlashInvariantForm := f + g holo' := f.holo'.add g.holo' zero_at_infty' := fun A => by simpa using (f.zero_at_infty' A).add (g.zero_at_infty' A) }⟩ @[simp] theorem coe_add (f g : CuspForm Γ k) : ⇑(f + g) = f + g := rfl @[simp] theorem add_apply (f g : CuspForm Γ k) (z : ℍ) : (f + g) z = f z + g z := rfl instance instZero : Zero (CuspForm Γ k) := ⟨ { toSlashInvariantForm := 0 holo' := fun _ => mdifferentiableAt_const 𝓘(ℂ, ℂ) 𝓘(ℂ, ℂ) zero_at_infty' := by simpa using Filter.zero_zeroAtFilter _ } ⟩ @[simp] theorem coe_zero : ⇑(0 : CuspForm Γ k) = (0 : ℍ → ℂ) := rfl @[simp] theorem zero_apply (z : ℍ) : (0 : CuspForm Γ k) z = 0 := rfl section variable {α : Type*} [SMul α ℂ] [IsScalarTower α ℂ ℂ] instance instSMul : SMul α (CuspForm Γ k) := ⟨fun c f => { toSlashInvariantForm := c • f.1 holo' := by simpa using f.holo'.const_smul (c • (1 : ℂ)) zero_at_infty' := fun A => by simpa using (f.zero_at_infty' A).smul (c • (1 : ℂ)) }⟩ @[simp] theorem coe_smul (f : CuspForm Γ k) (n : α) : ⇑(n • f) = n • ⇑f := rfl @[simp] theorem smul_apply (f : CuspForm Γ k) (n : α) {z : ℍ} : (n • f) z = n • f z := rfl end instance instNeg : Neg (CuspForm Γ k) := ⟨fun f => { toSlashInvariantForm := -f.1 holo' := f.holo'.neg zero_at_infty' := fun A => by simpa using (f.zero_at_infty' A).neg }⟩ @[simp] theorem coe_neg (f : CuspForm Γ k) : ⇑(-f) = -f := rfl @[simp] theorem neg_apply (f : CuspForm Γ k) (z : ℍ) : (-f) z = -f z := rfl instance instSub : Sub (CuspForm Γ k) := ⟨fun f g => f + -g⟩ @[simp] theorem coe_sub (f g : CuspForm Γ k) : ⇑(f - g) = f - g := rfl @[simp] theorem sub_apply (f g : CuspForm Γ k) (z : ℍ) : (f - g) z = f z - g z := rfl instance : AddCommGroup (CuspForm Γ k) := DFunLike.coe_injective.addCommGroup _ rfl coe_add coe_neg coe_sub coe_smul coe_smul /-- Additive coercion from `CuspForm` to `ℍ → ℂ`. -/ @[simps] def coeHom : CuspForm Γ k →+ ℍ → ℂ where toFun f := f map_zero' := CuspForm.coe_zero map_add' _ _ := rfl instance : Module ℂ (CuspForm Γ k) := Function.Injective.module ℂ coeHom DFunLike.coe_injective fun _ _ => rfl instance : Inhabited (CuspForm Γ k) := ⟨0⟩ instance (priority := 99) [FunLike F ℍ ℂ] [CuspFormClass F Γ k] : ModularFormClass F Γ k where slash_action_eq := SlashInvariantFormClass.slash_action_eq holo := CuspFormClass.holo bdd_at_infty _ _ := (CuspFormClass.zero_at_infty _ _).boundedAtFilter end CuspForm namespace ModularForm section GradedRing /-- Cast for modular forms, which is useful for avoiding `Heq`s. -/ def mcast {a b : ℤ} {Γ : Subgroup SL(2, ℤ)} (h : a = b) (f : ModularForm Γ a) : ModularForm Γ b where toFun := (f : ℍ → ℂ) slash_action_eq' A := h ▸ f.slash_action_eq' A holo' := f.holo' bdd_at_infty' A := h ▸ f.bdd_at_infty' A @[ext (iff := false)] theorem gradedMonoid_eq_of_cast {Γ : Subgroup SL(2, ℤ)} {a b : GradedMonoid (ModularForm Γ)} (h : a.fst = b.fst) (h2 : mcast h a.snd = b.snd) : a = b := by obtain ⟨i, a⟩ := a obtain ⟨j, b⟩ := b cases h exact congr_arg _ h2 instance (Γ : Subgroup SL(2, ℤ)) : GradedMonoid.GOne (ModularForm Γ) where one := 1 instance (Γ : Subgroup SL(2, ℤ)) : GradedMonoid.GMul (ModularForm Γ) where mul f g := f.mul g instance instGCommRing (Γ : Subgroup SL(2, ℤ)) : DirectSum.GCommRing (ModularForm Γ) where one_mul a := gradedMonoid_eq_of_cast (zero_add _) (ext fun _ => one_mul _) mul_one a := gradedMonoid_eq_of_cast (add_zero _) (ext fun _ => mul_one _) mul_assoc a b c := gradedMonoid_eq_of_cast (add_assoc _ _ _) (ext fun _ => mul_assoc _ _ _) mul_zero {i j} f := ext fun _ => mul_zero _ zero_mul {i j} f := ext fun _ => zero_mul _ mul_add {i j} f g h := ext fun _ => mul_add _ _ _ add_mul {i j} f g h := ext fun _ => add_mul _ _ _ mul_comm a b := gradedMonoid_eq_of_cast (add_comm _ _) (ext fun _ => mul_comm _ _) natCast := Nat.cast natCast_zero := ext fun _ => Nat.cast_zero natCast_succ n := ext fun _ => Nat.cast_succ _ intCast := Int.cast intCast_ofNat n := ext fun _ => AddGroupWithOne.intCast_ofNat _ intCast_negSucc_ofNat n := ext fun _ => AddGroupWithOne.intCast_negSucc _ instance instGAlgebra (Γ : Subgroup SL(2, ℤ)) : DirectSum.GAlgebra ℂ (ModularForm Γ) where toFun := { toFun := const, map_zero' := rfl, map_add' := fun _ _ => rfl } map_one := rfl map_mul _x _y := rfl commutes _c _x := gradedMonoid_eq_of_cast (add_comm _ _) (ext fun _ => mul_comm _ _) smul_def _x _x := gradedMonoid_eq_of_cast (zero_add _).symm (ext fun _ => rfl) open scoped DirectSum in example (Γ : Subgroup SL(2, ℤ)) : Algebra ℂ (⨁ i, ModularForm Γ i) := inferInstance end GradedRing end ModularForm
NumberTheory\ModularForms\CongruenceSubgroups.lean
/- Copyright (c) 2022 Chris Birkbeck. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Birkbeck -/ import Mathlib.Algebra.Group.Subgroup.Pointwise import Mathlib.Data.ZMod.Basic import Mathlib.GroupTheory.GroupAction.ConjAct import Mathlib.LinearAlgebra.Matrix.SpecialLinearGroup /-! # Congruence subgroups This defines congruence subgroups of `SL(2, ℤ)` such as `Γ(N)`, `Γ₀(N)` and `Γ₁(N)` for `N` a natural number. It also contains basic results about congruence subgroups. -/ local notation "SL(" n ", " R ")" => Matrix.SpecialLinearGroup (Fin n) R attribute [-instance] Matrix.SpecialLinearGroup.instCoeFun local notation:1024 "↑ₘ" A:1024 => ((A : SL(2, ℤ)) : Matrix (Fin 2) (Fin 2) ℤ) open Matrix.SpecialLinearGroup Matrix variable (N : ℕ) local notation "SLMOD(" N ")" => @Matrix.SpecialLinearGroup.map (Fin 2) _ _ _ _ _ _ (Int.castRingHom (ZMod N)) @[simp] theorem SL_reduction_mod_hom_val (N : ℕ) (γ : SL(2, ℤ)) : ∀ i j : Fin 2, (SLMOD(N) γ : Matrix (Fin 2) (Fin 2) (ZMod N)) i j = ((↑ₘγ i j : ℤ) : ZMod N) := fun _ _ => rfl namespace CongruenceSubgroup /-- The full level `N` congruence subgroup of `SL(2, ℤ)` of matrices that reduce to the identity modulo `N`. -/ def Gamma (N : ℕ) : Subgroup SL(2, ℤ) := SLMOD(N).ker theorem Gamma_mem' (N : ℕ) (γ : SL(2, ℤ)) : γ ∈ Gamma N ↔ SLMOD(N) γ = 1 := Iff.rfl @[simp] theorem Gamma_mem (N : ℕ) (γ : SL(2, ℤ)) : γ ∈ Gamma N ↔ ((↑ₘγ 0 0 : ℤ) : ZMod N) = 1 ∧ ((↑ₘγ 0 1 : ℤ) : ZMod N) = 0 ∧ ((↑ₘγ 1 0 : ℤ) : ZMod N) = 0 ∧ ((↑ₘγ 1 1 : ℤ) : ZMod N) = 1 := by rw [Gamma_mem'] constructor · intro h simp [← SL_reduction_mod_hom_val N γ, h] · intro h ext i j rw [SL_reduction_mod_hom_val N γ] fin_cases i <;> fin_cases j <;> simp only [h] exacts [h.1, h.2.1, h.2.2.1, h.2.2.2] theorem Gamma_normal (N : ℕ) : Subgroup.Normal (Gamma N) := SLMOD(N).normal_ker theorem Gamma_one_top : Gamma 1 = ⊤ := by ext simp [eq_iff_true_of_subsingleton] theorem Gamma_zero_bot : Gamma 0 = ⊥ := by ext simp only [Gamma_mem, coe_matrix_coe, Int.coe_castRingHom, map_apply, Int.cast_id, Subgroup.mem_bot] constructor · intro h ext i j fin_cases i <;> fin_cases j <;> simp only [h] exacts [h.1, h.2.1, h.2.2.1, h.2.2.2] · intro h simp [h] lemma ModularGroup_T_pow_mem_Gamma (N M : ℤ) (hNM : N ∣ M) : (ModularGroup.T ^ M) ∈ Gamma (Int.natAbs N) := by simp only [Gamma_mem, Fin.isValue, ModularGroup.coe_T_zpow, of_apply, cons_val', cons_val_zero, empty_val', cons_val_fin_one, Int.cast_one, cons_val_one, head_cons, head_fin_const, Int.cast_zero, and_self, and_true, true_and] refine Iff.mpr (ZMod.intCast_zmod_eq_zero_iff_dvd M (Int.natAbs N)) ?_ simp only [Int.natCast_natAbs, abs_dvd, hNM] /-- The congruence subgroup of `SL(2, ℤ)` of matrices whose lower left-hand entry reduces to zero modulo `N`. -/ def Gamma0 (N : ℕ) : Subgroup SL(2, ℤ) where carrier := { g : SL(2, ℤ) | ((↑ₘg 1 0 : ℤ) : ZMod N) = 0 } one_mem' := by simp mul_mem' := by intro a b ha hb simp only [Set.mem_setOf_eq] have h := (Matrix.two_mul_expl a.1 b.1).2.2.1 simp only [coe_matrix_coe, coe_mul, Int.coe_castRingHom, map_apply, Set.mem_setOf_eq] at * rw [h] simp [ha, hb] inv_mem' := by intro a ha simp only [Set.mem_setOf_eq] rw [SL2_inv_expl a] simp only [cons_val_zero, cons_val_one, head_cons, coe_matrix_coe, coe_mk, Int.coe_castRingHom, map_apply, Int.cast_neg, neg_eq_zero, Set.mem_setOf_eq] at * exact ha @[simp] theorem Gamma0_mem (N : ℕ) (A : SL(2, ℤ)) : A ∈ Gamma0 N ↔ ((↑ₘA 1 0 : ℤ) : ZMod N) = 0 := Iff.rfl theorem Gamma0_det (N : ℕ) (A : Gamma0 N) : (A.1.1.det : ZMod N) = 1 := by simp [A.1.property] /-- The group homomorphism from `CongruenceSubgroup.Gamma0` to `ZMod N` given by mapping a matrix to its lower right-hand entry. -/ def Gamma0Map (N : ℕ) : Gamma0 N →* ZMod N where toFun g := ((↑ₘg 1 1 : ℤ) : ZMod N) map_one' := by simp map_mul' := by intro A B have := (two_mul_expl A.1.1 B.1.1).2.2.2 simp only [Subgroup.coe_mul, coe_matrix_coe, coe_mul, Int.coe_castRingHom, map_apply] at * rw [this] have ha := A.property simp only [Int.cast_add, Int.cast_mul, add_left_eq_self, Gamma0_mem, coe_matrix_coe, Int.coe_castRingHom, map_apply] at * rw [ha] simp /-- The congruence subgroup `Gamma1` (as a subgroup of `Gamma0`) of matrices whose bottom row is congruent to `(0,1)` modulo `N`. -/ def Gamma1' (N : ℕ) : Subgroup (Gamma0 N) := (Gamma0Map N).ker @[simp] theorem Gamma1_mem' (N : ℕ) (γ : Gamma0 N) : γ ∈ Gamma1' N ↔ (Gamma0Map N) γ = 1 := Iff.rfl theorem Gamma1_to_Gamma0_mem (N : ℕ) (A : Gamma0 N) : A ∈ Gamma1' N ↔ ((↑ₘA 0 0 : ℤ) : ZMod N) = 1 ∧ ((↑ₘA 1 1 : ℤ) : ZMod N) = 1 ∧ ((↑ₘA 1 0 : ℤ) : ZMod N) = 0 := by constructor · intro ha have hA := A.property rw [Gamma0_mem] at hA have adet := Gamma0_det N A rw [Matrix.det_fin_two] at adet simp only [Gamma0Map, coe_matrix_coe, Int.coe_castRingHom, map_apply, Gamma1_mem', MonoidHom.coe_mk, OneHom.coe_mk, Int.cast_sub, Int.cast_mul] at * rw [hA, ha] at adet simp only [mul_one, mul_zero, sub_zero] at adet simp only [adet, hA, ha, eq_self_iff_true, and_self_iff] · intro ha simp only [Gamma1_mem', Gamma0Map, MonoidHom.coe_mk, coe_matrix_coe, Int.coe_castRingHom, map_apply] exact ha.2.1 /-- The congruence subgroup `Gamma1` of `SL(2, ℤ)` consisting of matrices whose bottom row is congruent to `(0,1)` modulo `N`. -/ def Gamma1 (N : ℕ) : Subgroup SL(2, ℤ) := Subgroup.map ((Gamma0 N).subtype.comp (Gamma1' N).subtype) ⊤ @[simp] theorem Gamma1_mem (N : ℕ) (A : SL(2, ℤ)) : A ∈ Gamma1 N ↔ ((↑ₘA 0 0 : ℤ) : ZMod N) = 1 ∧ ((↑ₘA 1 1 : ℤ) : ZMod N) = 1 ∧ ((↑ₘA 1 0 : ℤ) : ZMod N) = 0 := by constructor · intro ha simp_rw [Gamma1, Subgroup.mem_map] at ha obtain ⟨⟨x, hx⟩, hxx⟩ := ha rw [Gamma1_to_Gamma0_mem] at hx simp only [Subgroup.mem_top, true_and] at hxx rw [← hxx] convert hx · intro ha simp_rw [Gamma1, Subgroup.mem_map] have hA : A ∈ Gamma0 N := by simp [ha.right.right, Gamma0_mem] have HA : (⟨A, hA⟩ : Gamma0 N) ∈ Gamma1' N := by simp only [Gamma1_to_Gamma0_mem, Subgroup.coe_mk, coe_matrix_coe, Int.coe_castRingHom, map_apply] exact ha refine ⟨(⟨(⟨A, hA⟩ : Gamma0 N), HA⟩ : (Gamma1' N : Subgroup (Gamma0 N))), ?_⟩ simp theorem Gamma1_in_Gamma0 (N : ℕ) : Gamma1 N ≤ Gamma0 N := by intro x HA simp only [Gamma0_mem, Gamma1_mem, coe_matrix_coe, Int.coe_castRingHom, map_apply] at * exact HA.2.2 section CongruenceSubgroups /-- A congruence subgroup is a subgroup of `SL(2, ℤ)` which contains some `Gamma N` for some `(N : ℕ+)`. -/ def IsCongruenceSubgroup (Γ : Subgroup SL(2, ℤ)) : Prop := ∃ N : ℕ+, Gamma N ≤ Γ theorem isCongruenceSubgroup_trans (H K : Subgroup SL(2, ℤ)) (h : H ≤ K) (h2 : IsCongruenceSubgroup H) : IsCongruenceSubgroup K := by obtain ⟨N, hN⟩ := h2 exact ⟨N, le_trans hN h⟩ theorem Gamma_is_cong_sub (N : ℕ+) : IsCongruenceSubgroup (Gamma N) := ⟨N, by simp only [le_refl]⟩ theorem Gamma1_is_congruence (N : ℕ+) : IsCongruenceSubgroup (Gamma1 N) := by refine ⟨N, ?_⟩ intro A hA simp only [Gamma1_mem, Gamma_mem] at * simp only [hA, eq_self_iff_true, and_self_iff] theorem Gamma0_is_congruence (N : ℕ+) : IsCongruenceSubgroup (Gamma0 N) := isCongruenceSubgroup_trans _ _ (Gamma1_in_Gamma0 N) (Gamma1_is_congruence N) end CongruenceSubgroups section Conjugation open Pointwise theorem Gamma_cong_eq_self (N : ℕ) (g : ConjAct SL(2, ℤ)) : g • Gamma N = Gamma N := by apply Subgroup.Normal.conjAct (Gamma_normal N) theorem conj_cong_is_cong (g : ConjAct SL(2, ℤ)) (Γ : Subgroup SL(2, ℤ)) (h : IsCongruenceSubgroup Γ) : IsCongruenceSubgroup (g • Γ) := by obtain ⟨N, HN⟩ := h refine ⟨N, ?_⟩ rw [← Gamma_cong_eq_self N g, Subgroup.pointwise_smul_le_pointwise_smul_iff] exact HN end Conjugation end CongruenceSubgroup
NumberTheory\ModularForms\Identities.lean
/- Copyright (c) 2024 Chris Birkbeck. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Birkbeck -/ 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 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)] have Hn := (ModularGroup_T_pow_mem_Gamma N (N * n) (by simp)) simp only [zpow_natCast, Int.natAbs_ofNat] at Hn convert (SlashInvariantForm.slash_action_eqn' k (Gamma N) f ⟨((ModularGroup.T ^ (N * n))), Hn⟩ z) unfold SpecialLinearGroup.coeToGL simp only [Fin.isValue, ModularGroup.coe_T_zpow (N * n), of_apply, cons_val', cons_val_zero, empty_val', cons_val_fin_one, cons_val_one, head_fin_const, Int.cast_zero, zero_mul, head_cons, Int.cast_one, zero_add, one_zpow, one_mul] 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
NumberTheory\ModularForms\SlashActions.lean
/- Copyright (c) 2022 Chris Birkbeck. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Birkbeck -/ import Mathlib.Analysis.Complex.UpperHalfPlane.Basic 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 given group parametrized by some Type. This is modeled on the slash action of `GLPos (Fin 2) ℝ` on the space of modular forms. ## Notation In the `ModularForm` locale, this provides * `f ∣[k;γ] A`: the `k`th `γ`-compatible slash action by `A` on `f` * `f ∣[k] A`: the `k`th `ℂ`-compatible slash action by `A` on `f`; a shorthand for `f ∣[k;ℂ] A` -/ open Complex UpperHalfPlane ModularGroup open scoped UpperHalfPlane local notation "GL(" n ", " R ")" "⁺" => Matrix.GLPos (Fin n) R local notation "SL(" n ", " R ")" => Matrix.SpecialLinearGroup (Fin n) R local notation:1024 "↑ₘ" A:1024 => (((A : GL(2, ℝ)⁺) : GL (Fin 2) ℝ) : Matrix (Fin 2) (Fin 2) _) -- like `↑ₘ`, but allows the user to specify the ring `R`. Useful to help Lean elaborate. local notation:1024 "↑ₘ[" R "]" A:1024 => ((A : GL (Fin 2) R) : Matrix (Fin 2) (Fin 2) R) /-- A general version of the slash action of the space of modular forms. -/ class SlashAction (β G α γ : Type*) [Group G] [AddMonoid α] [SMul γ α] 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) smul_slash : ∀ (k : β) (g : G) (a : α) (z : γ), map k g (z • a) = z • 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 scoped[ModularForm] notation:100 f " ∣[" k "] " a:100 => SlashAction.map ℂ k a f open scoped ModularForm @[simp] theorem SlashAction.neg_slash {β G α γ : Type*} [Group G] [AddGroup α] [SMul γ α] [SlashAction β G α γ] (k : β) (g : G) (a : α) : (-a) ∣[k;γ] g = -a ∣[k;γ] g := eq_neg_of_add_eq_zero_left <| by rw [← SlashAction.add_slash, add_left_neg, SlashAction.zero_slash] @[simp] theorem SlashAction.smul_slash_of_tower {R β G α : Type*} (γ : Type*) [Group G] [AddGroup α] [Monoid γ] [MulAction γ α] [SMul R γ] [SMul R α] [IsScalarTower R γ α] [SlashAction β G α γ] (k : β) (g : G) (a : α) (r : R) : (r • a) ∣[k;γ] g = r • a ∣[k;γ] g := by rw [← smul_one_smul γ r a, SlashAction.smul_slash, smul_one_smul] attribute [simp] SlashAction.zero_slash SlashAction.slash_one SlashAction.smul_slash SlashAction.add_slash /-- Slash_action induced by a monoid homomorphism. -/ def monoidHomSlashAction {β G H α γ : Type*} [Group G] [AddMonoid α] [SMul γ α] [Group 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] smul_slash _ _ := SlashAction.smul_slash _ _ add_slash _ g _ _ := SlashAction.add_slash _ (h g) _ _ namespace ModularForm noncomputable section /-- The weight `k` action of `GL(2, ℝ)⁺` on functions `f : ℍ → ℂ`. -/ def slash (k : ℤ) (γ : GL(2, ℝ)⁺) (f : ℍ → ℂ) (x : ℍ) : ℂ := f (γ • x) * (((↑ₘγ).det : ℝ) : ℂ) ^ (k - 1) * UpperHalfPlane.denom γ x ^ (-k) variable {Γ : Subgroup SL(2, ℤ)} {k : ℤ} (f : ℍ → ℂ) section -- temporary notation until the instance is built local notation:100 f " ∣[" k "]" γ:100 => ModularForm.slash k γ f #adaptation_note /-- after v4.7.0-rc1, there is a performance problem in `field_simp`. (Part of the code was ignoring the `maxDischargeDepth` setting: now that we have to increase it, other paths become slow.) -/ set_option maxHeartbeats 400000 in private theorem slash_mul (k : ℤ) (A B : GL(2, ℝ)⁺) (f : ℍ → ℂ) : f ∣[k](A * B) = (f ∣[k]A) ∣[k]B := by ext1 x simp_rw [slash, UpperHalfPlane.denom_cocycle A B x] have e3 : (A * B) • x = A • B • x := by convert UpperHalfPlane.mul_smul' A B x rw [e3] simp only [UpperHalfPlane.num, UpperHalfPlane.denom, ofReal_mul, Subgroup.coe_mul, UpperHalfPlane.coe_smul, Units.val_mul, Matrix.det_mul, UpperHalfPlane.smulAux, UpperHalfPlane.smulAux', UpperHalfPlane.coe_mk] at * field_simp have : (((↑(↑A : GL (Fin 2) ℝ) : Matrix (Fin 2) (Fin 2) ℝ).det : ℂ) * ((↑(↑B : GL (Fin 2) ℝ) : Matrix (Fin 2) (Fin 2) ℝ).det : ℂ)) ^ (k - 1) = ((↑(↑A : GL (Fin 2) ℝ) : Matrix (Fin 2) (Fin 2) ℝ).det : ℂ) ^ (k - 1) * ((↑(↑B : GL (Fin 2) ℝ) : Matrix (Fin 2) (Fin 2) ℝ).det : ℂ) ^ (k - 1) := by rw [← mul_zpow] simp_rw [this, ← mul_assoc, ← mul_zpow] private theorem add_slash (k : ℤ) (A : GL(2, ℝ)⁺) (f g : ℍ → ℂ) : (f + g) ∣[k]A = f ∣[k]A + g ∣[k]A := by ext1 simp only [slash, Pi.add_apply, denom, zpow_neg] ring private theorem slash_one (k : ℤ) (f : ℍ → ℂ) : f ∣[k]1 = f := funext <| by simp [slash, denom] variable {α : Type*} [SMul α ℂ] [IsScalarTower α ℂ ℂ] private theorem smul_slash (k : ℤ) (A : GL(2, ℝ)⁺) (f : ℍ → ℂ) (c : α) : (c • f) ∣[k]A = c • f ∣[k]A := by simp_rw [← smul_one_smul ℂ c f, ← smul_one_smul ℂ c (f ∣[k]A)] ext1 simp_rw [slash] simp only [slash, Algebra.id.smul_eq_mul, Matrix.GeneralLinearGroup.val_det_apply, Pi.smul_apply] ring private theorem zero_slash (k : ℤ) (A : GL(2, ℝ)⁺) : (0 : ℍ → ℂ) ∣[k]A = 0 := funext fun _ => by simp only [slash, Pi.zero_apply, zero_mul] instance : SlashAction ℤ GL(2, ℝ)⁺ (ℍ → ℂ) ℂ where map := slash zero_slash := zero_slash slash_one := slash_one slash_mul := slash_mul smul_slash := smul_slash add_slash := add_slash end theorem slash_def (A : GL(2, ℝ)⁺) : f ∣[k] A = slash k A f := rfl instance subgroupAction (Γ : Subgroup SL(2, ℤ)) : SlashAction ℤ Γ (ℍ → ℂ) ℂ := monoidHomSlashAction (MonoidHom.comp Matrix.SpecialLinearGroup.toGLPos (MonoidHom.comp (Matrix.SpecialLinearGroup.map (Int.castRingHom ℝ)) (Subgroup.subtype Γ))) @[simp] theorem subgroup_slash (Γ : Subgroup SL(2, ℤ)) (γ : Γ) : f ∣[k] γ = f ∣[k] (γ : GL(2, ℝ)⁺) := rfl instance SLAction : SlashAction ℤ SL(2, ℤ) (ℍ → ℂ) ℂ := monoidHomSlashAction (MonoidHom.comp Matrix.SpecialLinearGroup.toGLPos (Matrix.SpecialLinearGroup.map (Int.castRingHom ℝ))) @[simp] theorem SL_slash (γ : SL(2, ℤ)) : f ∣[k] γ = f ∣[k] (γ : GL(2, ℝ)⁺) := rfl theorem is_invariant_const (A : SL(2, ℤ)) (x : ℂ) : Function.const ℍ x ∣[(0 : ℤ)] A = Function.const ℍ x := by have : ((↑ₘ(A : GL(2, ℝ)⁺)).det : ℝ) = 1 := det_coe' funext rw [SL_slash, slash_def, slash, zero_sub, this] simp /-- The constant function 1 is invariant under any element of `SL(2, ℤ)`. -/ -- @[simp] -- Porting note: simpNF says LHS simplifies to something more complex theorem is_invariant_one (A : SL(2, ℤ)) : (1 : ℍ → ℂ) ∣[(0 : ℤ)] A = (1 : ℍ → ℂ) := is_invariant_const _ _ /-- 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 : ℤ) (Γ : Subgroup SL(2, ℤ)) (f : ℍ → ℂ) (γ : Γ) (z : ℍ) : (f ∣[k] γ) z = f z ↔ f (γ • z) = ((↑ₘ[ℤ] γ 1 0 : ℂ) * z + (↑ₘ[ℤ] γ 1 1 : ℂ)) ^ k * f z := by simp only [subgroup_slash, slash_def, ModularForm.slash] convert inv_mul_eq_iff_eq_mul₀ (G₀ := ℂ) _ using 2 · rw [mul_comm] simp only [denom, zpow_neg, det_coe', ofReal_one, one_zpow, mul_one, subgroup_to_sl_moeb, sl_moeb] rfl · convert zpow_ne_zero k (denom_ne_zero γ z) theorem mul_slash (k1 k2 : ℤ) (A : GL(2, ℝ)⁺) (f g : ℍ → ℂ) : (f * g) ∣[k1 + k2] A = ((↑ₘA).det : ℝ) • f ∣[k1] A * g ∣[k2] A := by ext1 x simp only [slash_def, slash, Matrix.GeneralLinearGroup.val_det_apply, Pi.mul_apply, Pi.smul_apply, Algebra.smul_mul_assoc, real_smul] set d : ℂ := ↑((↑ₘA).det : ℝ) have h1 : d ^ (k1 + k2 - 1) = d * d ^ (k1 - 1) * d ^ (k2 - 1) := by have : d ≠ 0 := by dsimp [d] norm_cast exact Matrix.GLPos.det_ne_zero A rw [← zpow_one_add₀ this, ← zpow_add₀ this] congr; ring have h22 : denom A x ^ (-(k1 + k2)) = denom A x ^ (-k1) * denom A x ^ (-k2) := by rw [Int.neg_add, zpow_add₀] exact UpperHalfPlane.denom_ne_zero A x rw [h1, h22] ring -- @[simp] -- Porting note: simpNF says LHS simplifies to something more complex theorem mul_slash_SL2 (k1 k2 : ℤ) (A : SL(2, ℤ)) (f g : ℍ → ℂ) : (f * g) ∣[k1 + k2] A = f ∣[k1] A * g ∣[k2] A := calc (f * g) ∣[k1 + k2] (A : GL(2, ℝ)⁺) = ((↑ₘA).det : ℝ) • f ∣[k1] A * g ∣[k2] A := by apply mul_slash _ = (1 : ℝ) • f ∣[k1] A * g ∣[k2] A := by rw [det_coe'] _ = f ∣[k1] A * g ∣[k2] A := by rw [one_smul] theorem mul_slash_subgroup (k1 k2 : ℤ) (Γ : Subgroup SL(2, ℤ)) (A : Γ) (f g : ℍ → ℂ) : (f * g) ∣[k1 + k2] A = f ∣[k1] A * g ∣[k2] A := mul_slash_SL2 k1 k2 A f g end end ModularForm
NumberTheory\ModularForms\SlashInvariantForms.lean
/- Copyright (c) 2022 Chris Birkbeck. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Birkbeck -/ import Mathlib.NumberTheory.ModularForms.SlashActions /-! # Slash invariant forms This file defines functions that are invariant under a `SlashAction` which forms the basis for defining `ModularForm` and `CuspForm`. We prove several instances for such spaces, in particular that they form a module. -/ open Complex UpperHalfPlane open scoped UpperHalfPlane ModularForm noncomputable section local notation "GL(" n ", " R ")" "⁺" => Matrix.GLPos (Fin n) R local notation "SL(" n ", " R ")" => Matrix.SpecialLinearGroup (Fin n) R local notation:1024 "↑ₘ" A:1024 => (((A : GL(2, ℝ)⁺) : GL (Fin 2) ℝ) : Matrix (Fin 2) (Fin 2) _) -- like `↑ₘ`, but allows the user to specify the ring `R`. Useful to help Lean elaborate. local notation:1024 "↑ₘ[" R "]" A:1024 => ((A : GL (Fin 2) R) : Matrix (Fin 2) (Fin 2) R) section SlashInvariantForms open ModularForm variable (F : Type*) (Γ : outParam <| Subgroup SL(2, ℤ)) (k : outParam ℤ) /-- Functions `ℍ → ℂ` that are invariant under the `SlashAction`. -/ structure SlashInvariantForm where toFun : ℍ → ℂ slash_action_eq' : ∀ γ : Γ, toFun ∣[k] γ = toFun /-- `SlashInvariantFormClass F Γ k` asserts `F` is a type of bundled functions that are invariant under the `SlashAction`. -/ class SlashInvariantFormClass [FunLike F ℍ ℂ] : Prop where slash_action_eq : ∀ (f : F) (γ : Γ), (f : ℍ → ℂ) ∣[k] γ = f instance (priority := 100) SlashInvariantForm.funLike : FunLike (SlashInvariantForm Γ k) ℍ ℂ where coe := SlashInvariantForm.toFun coe_injective' f g h := by cases f; cases g; congr instance (priority := 100) SlashInvariantFormClass.slashInvariantForm : SlashInvariantFormClass (SlashInvariantForm Γ k) Γ k where slash_action_eq := SlashInvariantForm.slash_action_eq' variable {F Γ k} @[simp] theorem SlashInvariantForm.toFun_eq_coe {f : SlashInvariantForm Γ k} : f.toFun = (f : ℍ → ℂ) := rfl @[simp] theorem SlashInvariantForm.coe_mk (f : ℍ → ℂ) (hf : ∀ γ : Γ, f ∣[k] γ = f) : ⇑(mk f hf) = f := rfl @[ext] theorem SlashInvariantForm.ext {f g : SlashInvariantForm Γ k} (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h /-- Copy of a `SlashInvariantForm` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def SlashInvariantForm.copy (f : SlashInvariantForm Γ k) (f' : ℍ → ℂ) (h : f' = ⇑f) : SlashInvariantForm Γ k where toFun := f' slash_action_eq' := h.symm ▸ f.slash_action_eq' end SlashInvariantForms namespace SlashInvariantForm open SlashInvariantForm variable {F : Type*} {Γ : Subgroup SL(2, ℤ)} {k : ℤ} [FunLike F ℍ ℂ] -- @[simp] -- Porting note: simpNF says LHS simplifies to something more complex theorem slash_action_eqn [SlashInvariantFormClass F Γ k] (f : F) (γ : Γ) : ↑f ∣[k] γ = ⇑f := SlashInvariantFormClass.slash_action_eq f γ theorem slash_action_eqn' (k : ℤ) (Γ : Subgroup SL(2, ℤ)) [SlashInvariantFormClass F Γ k] (f : F) (γ : Γ) (z : ℍ) : f (γ • z) = ((↑ₘ[ℤ] γ 1 0 : ℂ) * z + (↑ₘ[ℤ] γ 1 1 : ℂ)) ^ k * f z := by rw [← ModularForm.slash_action_eq'_iff, slash_action_eqn] instance [SlashInvariantFormClass F Γ k] : CoeTC F (SlashInvariantForm Γ k) := ⟨fun f => { toFun := f slash_action_eq' := slash_action_eqn f }⟩ @[simp] theorem SlashInvariantFormClass.coe_coe [SlashInvariantFormClass F Γ k] (f : F) : ((f : SlashInvariantForm Γ k) : ℍ → ℂ) = f := rfl instance instAdd : Add (SlashInvariantForm Γ k) := ⟨fun f g => { toFun := f + g slash_action_eq' := fun γ => by rw [SlashAction.add_slash, slash_action_eqn, slash_action_eqn] }⟩ @[simp] theorem coe_add (f g : SlashInvariantForm Γ k) : ⇑(f + g) = f + g := rfl @[simp] theorem add_apply (f g : SlashInvariantForm Γ k) (z : ℍ) : (f + g) z = f z + g z := rfl instance instZero : Zero (SlashInvariantForm Γ k) := ⟨{toFun := 0 slash_action_eq' := SlashAction.zero_slash _}⟩ @[simp] theorem coe_zero : ⇑(0 : SlashInvariantForm Γ k) = (0 : ℍ → ℂ) := rfl section variable {α : Type*} [SMul α ℂ] [IsScalarTower α ℂ ℂ] instance instSMul : SMul α (SlashInvariantForm Γ k) := ⟨fun c f => { toFun := c • ↑f slash_action_eq' := fun γ => by rw [SlashAction.smul_slash_of_tower, slash_action_eqn] }⟩ @[simp] theorem coe_smul (f : SlashInvariantForm Γ k) (n : α) : ⇑(n • f) = n • ⇑f := rfl @[simp] theorem smul_apply (f : SlashInvariantForm Γ k) (n : α) (z : ℍ) : (n • f) z = n • f z := rfl end instance instNeg : Neg (SlashInvariantForm Γ k) := ⟨fun f => { toFun := -f slash_action_eq' := fun γ => by rw [SlashAction.neg_slash, slash_action_eqn] }⟩ @[simp] theorem coe_neg (f : SlashInvariantForm Γ k) : ⇑(-f) = -f := rfl @[simp] theorem neg_apply (f : SlashInvariantForm Γ k) (z : ℍ) : (-f) z = -f z := rfl instance instSub : Sub (SlashInvariantForm Γ k) := ⟨fun f g => f + -g⟩ @[simp] theorem coe_sub (f g : SlashInvariantForm Γ k) : ⇑(f - g) = f - g := rfl @[simp] theorem sub_apply (f g : SlashInvariantForm Γ k) (z : ℍ) : (f - g) z = f z - g z := rfl instance : AddCommGroup (SlashInvariantForm Γ k) := DFunLike.coe_injective.addCommGroup _ rfl coe_add coe_neg coe_sub coe_smul coe_smul /-- Additive coercion from `SlashInvariantForm` to `ℍ → ℂ`. -/ def coeHom : SlashInvariantForm Γ k →+ ℍ → ℂ where toFun f := f map_zero' := rfl map_add' _ _ := rfl theorem coeHom_injective : Function.Injective (@coeHom Γ k) := DFunLike.coe_injective instance : Module ℂ (SlashInvariantForm Γ k) := coeHom_injective.module ℂ coeHom fun _ _ => rfl /-- The `SlashInvariantForm` corresponding to `Function.const _ x`. -/ @[simps (config := .asFn)] def const (x : ℂ) : SlashInvariantForm Γ 0 where toFun := Function.const _ x slash_action_eq' A := ModularForm.is_invariant_const A x instance : One (SlashInvariantForm Γ 0) where one := { const 1 with toFun := 1 } @[simp] theorem one_coe_eq_one : ((1 : SlashInvariantForm Γ 0) : ℍ → ℂ) = 1 := rfl instance : Inhabited (SlashInvariantForm Γ k) := ⟨0⟩ /-- The slash invariant form of weight `k₁ + k₂` given by the product of two modular forms of weights `k₁` and `k₂`. -/ def mul {k₁ k₂ : ℤ} {Γ : Subgroup SL(2, ℤ)} (f : SlashInvariantForm Γ k₁) (g : SlashInvariantForm Γ k₂) : SlashInvariantForm Γ (k₁ + k₂) where toFun := f * g slash_action_eq' A := by simp_rw [ModularForm.mul_slash_subgroup, SlashInvariantFormClass.slash_action_eq] @[simp] theorem coe_mul {k₁ k₂ : ℤ} {Γ : Subgroup SL(2, ℤ)} (f : SlashInvariantForm Γ k₁) (g : SlashInvariantForm Γ k₂) : ⇑(f.mul g) = ⇑f * ⇑g := rfl instance (Γ : Subgroup SL(2, ℤ)) : NatCast (SlashInvariantForm Γ 0) where natCast n := const n @[simp, norm_cast] theorem coe_natCast (n : ℕ) : ⇑(n : SlashInvariantForm Γ 0) = n := rfl instance (Γ : Subgroup SL(2, ℤ)) : IntCast (SlashInvariantForm Γ 0) where intCast z := const z @[simp, norm_cast] theorem coe_intCast (z : ℤ) : ⇑(z : SlashInvariantForm Γ 0) = z := rfl end SlashInvariantForm
NumberTheory\ModularForms\EisensteinSeries\Basic.lean
/- Copyright (c) 2024 Chris Birkbeck. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Birkbeck -/ 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 /-- 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 : ℕ+} (hk : 3 ≤ k) (a : Fin 2 → ZMod N) : ModularForm (Gamma 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_infty' := isBoundedAtImInfty_eisensteinSeries_SIF a hk end ModularForm
NumberTheory\ModularForms\EisensteinSeries\Defs.lean
/- Copyright (c) 2024 Chris Birkbeck. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Birkbeck, David Loeffler -/ import Mathlib.NumberTheory.ModularForms.SlashInvariantForms 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 open scoped MatrixGroups namespace EisensteinSeries variable (N : ℕ) (a : Fin 2 → ZMod N) section gammaSet_def /-- The set of pairs of coprime integers congruent to `a` mod `N`. -/ def gammaSet := {v : Fin 2 → ℤ | (↑) ∘ v = a ∧ IsCoprime (v 0) (v 1)} lemma pairwise_disjoint_gammaSet : Pairwise (Disjoint on gammaSet N) := 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_eq (a a' : Fin 2 → ZMod 1) : gammaSet 1 a = gammaSet 1 a' := congr_arg _ (Subsingleton.elim _ _) /-- 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 a ≃ gammaSet 1 a' := Equiv.Set.ofEq (gammaSet_one_eq a a') end gammaSet_def variable {N a} section gamma_action /-- 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 a) (γ : SL(2, ℤ)) : v ᵥ* γ ∈ gammaSet N (a ᵥ* γ) := by refine ⟨?_, hv.2.vecMulSL γ⟩ 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, 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 a ≃ gammaSet N (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_right_inv, SpecialLinearGroup.coe_one, vecMul_one]⟩ left_inv v := by simp_rw [vecMul_vecMul, ← SpecialLinearGroup.coe_mul, mul_inv_self, SpecialLinearGroup.coe_one, vecMul_one] right_inv v := by simp_rw [vecMul_vecMul, ← SpecialLinearGroup.coe_mul, inv_mul_self, 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.1 + 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) = (z.denom A) ^ k * eisSummand k (i ᵥ* A) z := by simp only [eisSummand, vecMul, vec2_dotProduct] push_cast 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 field_simp [hc] ring_nf apply h (hc := z.denom_ne_zero A) 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 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, slash_def, slash, ModularGroup.det_coe', ofReal_one, one_zpow, mul_one, zpow_neg, mul_inv_eq_iff_eq_mul₀ (zpow_ne_zero _ <| z.denom_ne_zero _), mul_comm, eisensteinSeries, ← ModularGroup.sl_moeb, eisSummand_SL2_apply, tsum_mul_left] erw [(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 := by rw [subgroup_slash, ← SL_slash, eisensteinSeries_slash_apply, (Gamma_mem' N A).mp A.2, SpecialLinearGroup.coe_one, vecMul_one] lemma eisensteinSeries_SIF_apply (k : ℤ) (z : ℍ) : eisensteinSeries_SIF a k z = eisensteinSeries a k z := rfl end EisensteinSeries
NumberTheory\ModularForms\EisensteinSeries\IsBoundedAtImInfty.lean
/- Copyright (c) 2024 Chris Birkbeck. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Birkbeck -/ import Mathlib.Analysis.Complex.UpperHalfPlane.FunctionsBoundedAtInfty import Mathlib.Analysis.Normed.Order.Lattice import Mathlib.NumberTheory.ModularForms.EisensteinSeries.UniformConvergence 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 _ => Complex.abs.nonneg _) intro b simp only [eisSummand, map_zpow₀] exact_mod_cast summand_bound z (show 0 ≤ (k : ℝ) by positivity) b /-- The absolute value of the restricted sum is less than the full sum of the absolute values. -/ lemma abs_le_tsum_abs (N : ℕ) (a : Fin 2 → ZMod N) (k : ℤ) (hk : 3 ≤ k) (z : ℍ) : Complex.abs (eisensteinSeries a k z) ≤ ∑' (x : Fin 2 → ℤ), Complex.abs (eisSummand k x z) := by simp_rw [← Complex.norm_eq_abs, eisensteinSeries] apply le_trans (norm_tsum_le_tsum_norm ((summable_norm_eisSummand hk z).subtype _)) (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 : ℕ+} (a : Fin 2 → ZMod N) {k : ℤ} (hk : 3 ≤ k) (A : SL(2, ℤ)) : IsBoundedAtImInfty ((eisensteinSeries_SIF a k).toFun ∣[k] A) := by simp_rw [UpperHalfPlane.bounded_mem, 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 N.2) rw [eisensteinSeries_slash_apply, ← eisensteinSeries_SIF_apply, ← T_zpow_width_invariant N k n (eisensteinSeries_SIF (a ᵥ* A) k) z] apply le_trans (abs_le_tsum_abs N (a ᵥ* A) k hk _) have hk' : (2 : ℝ) < k := by norm_cast apply tsum_le_tsum _ (summable_norm_eisSummand hk _) · 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
NumberTheory\ModularForms\EisensteinSeries\MDifferentiable.lean
/- Copyright (c) 2024 Chris Birkbeck. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Birkbeck -/ 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 /-- Auxilary 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 [Fin.isValue, Pi.zero_apply, Int.cast_zero, zero_mul, add_zero, one_div] apply differentiableOn_const /-- Auxilary 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_lt continuous_const Complex.continuous_im).mem_nhds τ.2) exact (eisensteinSeries_tendstoLocallyUniformlyOn hk a).differentiableOn (eventually_of_forall fun s ↦ DifferentiableOn.sum fun _ _ ↦ eisSummand_extension_differentiableOn _ _) (isOpen_lt continuous_const continuous_im) end EisensteinSeries
NumberTheory\ModularForms\EisensteinSeries\UniformConvergence.lean
/- Copyright (c) 2024 Chris Birkbeck. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Birkbeck, David Loeffler -/ import Mathlib.Analysis.Complex.UpperHalfPlane.Topology import Mathlib.Analysis.NormedSpace.FunctionSeries import Mathlib.Analysis.PSeries import Mathlib.Order.Interval.Finset.Box import Mathlib.NumberTheory.ModularForms.EisensteinSeries.Defs /-! # 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 open scoped UpperHalfPlane 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] 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] apply div_le_div (sq_nonneg _) _ (by positivity) (pow_le_pow_left h.le hz.2 2) simpa only [even_two.pow_abs] using pow_le_pow_left (abs_nonneg _) hz.1 2 lemma auxbound1 {c : ℝ} (d : ℝ) (hc : 1 ≤ c ^ 2) : r z ≤ Complex.abs (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, abs_apply, 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 ≤ Complex.abs (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, abs_apply, 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, Int.cast_natAbs, Int.cast_abs, div_pow, _root_.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, Int.cast_natAbs, Int.cast_abs, div_pow, _root_.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‖ ≤ Complex.abs (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, map_mul, Complex.abs_ofReal, abs_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 → ℤ) : Complex.abs (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_eq_abs, 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) : Complex.abs (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) end bounding_functions section summability /-- 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, Matrix.head_cons] 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 _) _ /-- 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 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 a ↦ ‖x.val‖ ^ (-k) := mod_cast (summable_one_div_norm_rpow hk').subtype (gammaSet N 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_eq_abs, abs_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 a )) ↦ ↑ₕ(fun (z : ℍ) ↦ ∑ x in 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 := ⊤) _ _ _ (PartialHomeomorph.continuousOn_symm _) · simp only [SlashInvariantForm.toFun_eq_coe, Set.top_eq_univ, tendstoLocallyUniformlyOn_univ] apply eisensteinSeries_tendstoLocallyUniformly hk · simp only [OpenEmbedding.toPartialHomeomorph_target, Set.top_eq_univ, mapsTo_range_iff, Set.mem_univ, forall_const] end summability end EisensteinSeries
NumberTheory\ModularForms\JacobiTheta\Bounds.lean
/- Copyright (c) 2024 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ 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 Classical 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 rwa [norm_of_nonneg (exp_pos _).le, exp_le_exp, mul_le_mul_right ht, neg_le_neg_iff] 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 norm_num)).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)] refine mul_le_mul_of_nonneg_left ?_ (by positivity) rw [Real.exp_le_exp, mul_le_mul_right ht, mul_le_mul_left_of_neg (neg_lt_zero.mpr pi_pos), ← sub_nonneg] have u : (n : ℝ) ≤ (n : ℝ) ^ 2 := by simpa only [← Nat.cast_pow, Nat.cast_le] using Nat.le_self_pow two_ne_zero _ convert add_nonneg (sub_nonneg.mpr u) (by positivity : 0 ≤ 2 * n * a) using 1 ring /-- 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] refine mul_le_mul_of_nonneg_left ?_ (pow_nonneg (Nat.cast_nonneg _) _) rw [exp_le_exp, ← 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 apply pow_le_pow_left (abs_nonneg _) ((abs_add_le _ _).trans (add_le_add (le_of_eq (Nat.abs_cast _)) (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, tsum_eq_zero_add (summable_f_nat 0 0 ht), 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 cases' n with m 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 with m m · 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) have ha' : (a : UnitAddCircle) = 0 ↔ a = 0 := by rw [← AddCircle.coe_eq_coe_iff_of_mem_Ico (hp := ⟨zero_lt_one' ℝ⟩), QuotientAddGroup.mk_zero] · rw [zero_add]; exact ha · simp simp_rw [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
NumberTheory\ModularForms\JacobiTheta\Manifold.lean
/- Copyright (c) 2023 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ 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
NumberTheory\ModularForms\JacobiTheta\OneVariable.lean
/- Copyright (c) 2023 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.NumberTheory.ModularForms.JacobiTheta.TwoVariable import Mathlib.Analysis.Complex.UpperHalfPlane.Basic /-! # 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₂] conv_rhs => erw [← ofReal_zero, jacobiTheta₂_functional_equation 0 τ] rw [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 [Complex.norm_eq_abs, Complex.abs_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_eq_abs, Complex.abs_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 ((tsum_mono aux 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, 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] refine mul_le_mul_of_nonneg_right ?_ (exp_pos _).le rw [div_le_div_left (zero_lt_two' ℝ), sub_le_sub_iff_left, exp_le_exp, neg_mul, neg_le_neg_iff] · exact le_mul_of_one_le_right pi_pos.le (hτ.symm ▸ hy) · rw [sub_pos, exp_lt_one_iff, neg_mul, neg_lt_zero] exact mul_pos pi_pos (hτ.symm ▸ zero_lt_one.trans_le hy) · rw [sub_pos, exp_lt_one_iff, neg_lt_zero]; exact 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
NumberTheory\ModularForms\JacobiTheta\TwoVariable.lean
/- Copyright (c) 2023 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Gaussian.PoissonSummation import Mathlib.Analysis.Calculus.SmoothSeries import Mathlib.Analysis.NormedSpace.OperatorNorm.Prod /-! # 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_eq_abs, Complex.abs_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_left 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_left 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_eq_abs, Complex.abs_two, abs_I, Complex.abs_of_nonneg pi_pos.le, abs_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_zero, Function.comp_def, 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, mul_assoc] refine mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left ?_ pi_pos.le) two_pos.le refine le_trans ?_ (?_ : |(n : ℝ)| ≤ |(n : ℝ)| ^ 2) · exact mul_le_of_le_one_right (abs_nonneg _) (ContinuousLinearMap.norm_fst_le ..) · exact_mod_cast Int.le_self_sq |n| · 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, _root_.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, ← abs_intCast, Complex.norm_eq_abs, Complex.abs_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, _root_.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 norm_num : 0 < (3 : ℝ)) pi_pos).le refine mul_le_mul_of_nonneg_left ?_ (pow_nonneg (Int.cast_nonneg.mpr (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_eq_abs, Complex.abs_two, abs_I, Complex.abs_of_nonneg pi_pos.le, abs_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_prod_mk_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_prod_mk_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_prod_mk_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 => erw [← 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`. -/ 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_lt τ.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, tsum_sub (hasSum_jacobiTheta₂'_term z hτ).summable ((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 explict 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_lt (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 h0 : τ ≠ 0 := by contrapose! hτ; rw [hτ, zero_im] 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 [I_ne_zero] 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_lt (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_mul _ hj.differentiableAt] exact (((differentiableAt_pow 2).const_mul _).mul_const _).cexp _ = _ := by rw [hj.deriv] erw [deriv_cexp (((differentiableAt_pow _).const_mul _).mul_const _)] rw [mul_comm, deriv_mul_const_field, deriv_const_mul_field, deriv_pow] ring_nf
NumberTheory\MulChar\Basic.lean
/- Copyright (c) 2022 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.Algebra.CharP.Basic 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'] extends MonoidHomClass F R R' : Prop where map_nonunit : ∀ (χ : F) {a : R} (_ : ¬IsUnit a), χ a = 0 initialize_simps_projections MulChar (toFun → apply, -toMonoidHom) attribute [simp] MulCharClass.map_nonunit end Defi namespace MulChar 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.eq_iff.mp 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_iff, dif_pos] by_cases hy : IsUnit y · simp only [hy, dif_pos] have hm : (IsUnit.mul_iff.mpr ⟨hx, hy⟩).unit = hx.unit * hy.unit := Units.eq_iff.mp 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_iff, 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*} [CommRing 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*} [Field 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*} [Field 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. -/ -- Porting note (#10618): @[simp] can prove this (later) 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') := { one := 1 mul := (· * ·) inv := Inv.inv mul_left_inv := 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 n ih · rw [pow_zero, pow_zero, one_apply_coe] · 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.ext 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] /-- A multiplicative character is *nontrivial* if it takes a value `≠ 1` on a unit. -/ @[deprecated (since := "2024-06-16")] def IsNontrivial (χ : MulChar R R') : Prop := ∃ a : Rˣ, χ a ≠ 1 set_option linter.deprecated false in /-- A multiplicative character is nontrivial iff it is not the trivial character. -/ @[deprecated (since := "2024-06-16")] theorem isNontrivial_iff (χ : MulChar R R') : χ.IsNontrivial ↔ χ ≠ 1 := by simp only [IsNontrivial, Ne, MulChar.ext_iff, not_forall, one_apply_coe] 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*} [CommRing 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 ext; 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 set_option linter.deprecated false in /-- Composition with an injective ring homomorphism preserves nontriviality. -/ @[deprecated ringHomComp_ne_one_iff (since := "2024-06-16")] theorem IsNontrivial.comp {χ : MulChar R R'} (hχ : χ.IsNontrivial) {f : R' →+* R''} (hf : Function.Injective f) : (χ.ringHomComp f).IsNontrivial := by obtain ⟨a, ha⟩ := hχ use a simp_rw [ringHomComp_apply, ← RingHom.map_one f] exact fun h => ha (hf h) /-- 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: was `by norm_cast` have : (-1 : R') = (-1 : R'ˣ) := by rw [Units.val_neg, Units.val_one] rw [h₂, this, Ring.inverse_unit (-1 : R'ˣ)] rfl /-- The square of a quadratic character is the trivial character. -/ theorem IsQuadratic.sq_eq_one {χ : MulChar R R'} (hχ : χ.IsQuadratic) : χ ^ 2 = 1 := by rw [← mul_left_inv χ, 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 CharP.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] 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 _ set_option linter.deprecated false in @[deprecated (since := "2024-06-16")] lemma IsNontrivial.sum_eq_zero [IsDomain R'] {χ : MulChar R R'} (hχ : χ.IsNontrivial) : ∑ a, χ a = 0 := sum_eq_zero_of_ne_one ((isNontrivial_iff _).mp hχ) /-- 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.ext⟩).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 only [Finset.mem_filter, Finset.mem_univ, true_and_iff, Finset.mem_map, Function.Embedding.coeFn_mk, exists_true_left, 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
NumberTheory\MulChar\Lemmas.lean
/- Copyright (c) 2024 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ 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ˣ, Fintype.card_pos⟩ R' := by rw [mem_rootsOfUnity, ← map_pow, ← (equivToUnitHom χ).map_one, PNat.mk_coe, 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] variable (M) in /-- The order of the unit group of a finite monoid as a `PNat` (for use in `rootsOfUnity`). -/ abbrev Monoid.orderUnits : ℕ+ := ⟨Fintype.card Mˣ, Fintype.card_pos⟩ /-- 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 (Monoid.orderUnits M) R) {g : Mˣ} (hg : ∀ x, x ∈ Subgroup.zpowers g) : MulChar M R := by have : orderOf ζ ∣ Monoid.orderUnits M := orderOf_dvd_iff_pow_eq_one.mpr <| (mem_rootsOfUnity _ ζ).mp hζ refine ofUnitHom <| monoidHomOfForallMemZpowers hg <| this.trans <| dvd_of_eq ?_ rw [orderOf_generator_eq_natCard hg, Nat.card_eq_fintype_card, PNat.mk_coe] lemma ofRootOfUnity_spec {ζ : Rˣ} (hζ : ζ ∈ rootsOfUnity (Monoid.orderUnits 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 (Monoid.orderUnits M) R where toFun χ := ⟨χ.toUnitHom <| Classical.choose inst_cyc.exists_generator, by simp only [toUnitHom_eq, mem_rootsOfUnity, PNat.mk_coe, ← 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, Submonoid.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₀).unit have h' : ζ' ^ (Monoid.orderUnits F : ℕ) = 1 := by have hn : n ∣ Monoid.orderUnits F := by rwa [Monoid.orderUnits, PNat.mk_coe, Fintype.card_units] exact Units.ext_iff.mpr <| (IsPrimitiveRoot.pow_eq_one_iff_dvd hζ _).mpr hn use e.symm ⟨ζ', (mem_rootsOfUnity (Monoid.orderUnits 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 ζ (Monoid.orderUnits 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 χ, χ.orderOf_pos⟩ R, ζ = χ a := by have hu : IsUnit (χ a) := ha.isUnit.map χ refine ⟨hu.unit, ?_, IsUnit.unit_spec hu⟩ rw [mem_rootsOfUnity, PNat.mk_coe, 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 : ℕ} (hn : n ≠ 0) (hχ : χ ^ n = 1) {a : F} (ha : a ≠ 0) : ∃ ζ ∈ rootsOfUnity ⟨n, Nat.pos_of_ne_zero hn⟩ R, ζ = χ a := by obtain ⟨μ, hμ₁, hμ₂⟩ := χ.apply_mem_rootsOfUnity_orderOf ha have hχ' : PNat.val ⟨orderOf χ, χ.orderOf_pos⟩ ∣ PNat.val ⟨n, Nat.pos_of_ne_zero hn⟩ := orderOf_dvd_of_pow_eq_one hχ exact ⟨μ, rootsOfUnity_le_of_dvd (PNat.dvd_iff.mpr 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 : ℕ} (hn : n ≠ 0) (hχ : χ ^ n = 1) {μ : R} (hμ : IsPrimitiveRoot μ n) {a : F} (ha : a ≠ 0) : ∃ k < n, χ a = μ ^ k := by have hn' := Nat.pos_of_ne_zero hn obtain ⟨ζ, hζ₁, hζ₂⟩ := apply_mem_rootsOfUnity_of_pow_eq_one hn hχ ha have hζ' : ζ.val ^ n = 1 := (mem_rootsOfUnity' ⟨n, hn'⟩ ↑ζ).mp hζ₁ obtain ⟨k, hk₁, hk₂⟩ := hμ.eq_pow_of_pow_eq_one hζ' hn' 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 : ℕ} (hn : n ≠ 0) (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 hn 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ζ₁ (Nat.pos_of_ne_zero hn) 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 ℤ {μ} := apply_mem_algebraAdjoin_of_pow_eq_one χ.orderOf_pos.ne' (pow_orderOf_eq_one χ) hμ a end FiniteField end MulChar
NumberTheory\NumberField\Basic.lean
/- Copyright (c) 2021 Ashvni Narayanan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ashvni Narayanan, Anne Baanen -/ import Mathlib.Algebra.Ring.Int import Mathlib.RingTheory.DedekindDomain.IntegralClosure import Mathlib.Algebra.Algebra.Rat /-! # Number fields This file defines a number field and the ring of integers corresponding to it. ## Main definitions - `NumberField` defines a number field as a field which has characteristic zero and is finite dimensional over ℚ. - `RingOfIntegers` defines the ring of integers (or number ring) corresponding to a number field as the integral closure of ℤ in the number field. ## Implementation notes The definitions that involve a field of fractions choose a canonical field of fractions, but are independent of that choice. ## References * [D. Marcus, *Number Fields*][marcus1977number] * [J.W.S. Cassels, A. Frölich, *Algebraic Number Theory*][cassels1967algebraic] * [P. Samuel, *Algebraic Theory of Numbers*][samuel1970algebraic] ## Tags number field, ring of integers -/ /-- A number field is a field which has characteristic zero and is finite dimensional over ℚ. -/ class NumberField (K : Type*) [Field K] : Prop where [to_charZero : CharZero K] [to_finiteDimensional : FiniteDimensional ℚ K] open Function Module open scoped nonZeroDivisors /-- `ℤ` with its usual ring structure is not a field. -/ theorem Int.not_isField : ¬IsField ℤ := fun h => Int.not_even_one <| (h.mul_inv_cancel two_ne_zero).imp fun a => by rw [← two_mul]; exact Eq.symm namespace NumberField variable (K L : Type*) [Field K] [Field L] -- See note [lower instance priority] attribute [instance] NumberField.to_charZero NumberField.to_finiteDimensional protected theorem isAlgebraic [NumberField K] : Algebra.IsAlgebraic ℚ K := Algebra.IsAlgebraic.of_finite _ _ instance [NumberField K] [NumberField L] [Algebra K L] : FiniteDimensional K L := Module.Finite.of_restrictScalars_finite ℚ K L /-- The ring of integers (or number ring) corresponding to a number field is the integral closure of ℤ in the number field. This is defined as its own type, rather than a `Subalgebra`, for performance reasons: looking for instances of the form `SMul (RingOfIntegers _) (RingOfIntegers _)` makes much more effective use of the discrimination tree than instances of the form `SMul (Subtype _) (Subtype _)`. The drawback is we have to copy over instances manually. -/ def RingOfIntegers : Type _ := integralClosure ℤ K @[inherit_doc] scoped notation "𝓞" => NumberField.RingOfIntegers namespace RingOfIntegers instance : CommRing (𝓞 K) := inferInstanceAs (CommRing (integralClosure _ _)) instance : IsDomain (𝓞 K) := inferInstanceAs (IsDomain (integralClosure _ _)) instance [NumberField K] : CharZero (𝓞 K) := inferInstanceAs (CharZero (integralClosure _ _)) instance : Algebra (𝓞 K) K := inferInstanceAs (Algebra (integralClosure _ _) _) instance : NoZeroSMulDivisors (𝓞 K) K := inferInstanceAs (NoZeroSMulDivisors (integralClosure _ _) _) instance : Nontrivial (𝓞 K) := inferInstanceAs (Nontrivial (integralClosure _ _)) instance {L : Type*} [Ring L] [Algebra K L] : Algebra (𝓞 K) L := inferInstanceAs (Algebra (integralClosure _ _) L) instance {L : Type*} [Ring L] [Algebra K L] : IsScalarTower (𝓞 K) K L := inferInstanceAs (IsScalarTower (integralClosure _ _) K L) variable {K} /-- The canonical coercion from `𝓞 K` to `K`. -/ @[coe] abbrev val (x : 𝓞 K) : K := algebraMap _ _ x /-- This instance has to be `CoeHead` because we only want to apply it from `𝓞 K` to `K`. -/ instance : CoeHead (𝓞 K) K := ⟨val⟩ lemma coe_eq_algebraMap (x : 𝓞 K) : (x : K) = algebraMap _ _ x := rfl @[ext] theorem ext {x y : 𝓞 K} (h : (x : K) = (y : K)) : x = y := Subtype.ext h @[norm_cast] theorem eq_iff {x y : 𝓞 K} : (x : K) = (y : K) ↔ x = y := NumberField.RingOfIntegers.ext_iff.symm @[simp] lemma map_mk (x : K) (hx) : algebraMap (𝓞 K) K ⟨x, hx⟩ = x := rfl lemma coe_mk {x : K} (hx) : ((⟨x, hx⟩ : 𝓞 K) : K) = x := rfl lemma mk_eq_mk (x y : K) (hx hy) : (⟨x, hx⟩ : 𝓞 K) = ⟨y, hy⟩ ↔ x = y := by simp @[simp] lemma mk_one : (⟨1, one_mem _⟩ : 𝓞 K) = 1 := rfl @[simp] lemma mk_zero : (⟨0, zero_mem _⟩ : 𝓞 K) = 0 := rfl -- TODO: these lemmas don't seem to fire? @[simp] lemma mk_add_mk (x y : K) (hx hy) : (⟨x, hx⟩ : 𝓞 K) + ⟨y, hy⟩ = ⟨x + y, add_mem hx hy⟩ := rfl @[simp] lemma mk_mul_mk (x y : K) (hx hy) : (⟨x, hx⟩ : 𝓞 K) * ⟨y, hy⟩ = ⟨x * y, mul_mem hx hy⟩ := rfl @[simp] lemma mk_sub_mk (x y : K) (hx hy) : (⟨x, hx⟩ : 𝓞 K) - ⟨y, hy⟩ = ⟨x - y, sub_mem hx hy⟩ := rfl @[simp] lemma neg_mk (x : K) (hx) : (-⟨x, hx⟩ : 𝓞 K) = ⟨-x, neg_mem hx⟩ := rfl end RingOfIntegers /-- Given an algebra between two fields, create an algebra between their two rings of integers. -/ instance inst_ringOfIntegersAlgebra [Algebra K L] : Algebra (𝓞 K) (𝓞 L) := RingHom.toAlgebra { toFun := fun k => ⟨algebraMap K L (algebraMap _ K k), IsIntegral.algebraMap k.2⟩ map_zero' := by ext; simp only [RingOfIntegers.map_mk, map_zero] map_one' := by ext; simp only [RingOfIntegers.map_mk, map_one] map_add' := fun x y => by ext; simp only [RingOfIntegers.map_mk, map_add] map_mul' := fun x y => by ext; simp only [RingOfIntegers.map_mk, map_mul] } -- diamond at `reducible_and_instances` #10906 example : Algebra.id (𝓞 K) = inst_ringOfIntegersAlgebra K K := rfl namespace RingOfIntegers variable {K} /-- The canonical map from `𝓞 K` to `K` is injective. This is a convenient abbreviation for `NoZeroSMulDivisors.algebraMap_injective`. -/ lemma coe_injective : Function.Injective (algebraMap (𝓞 K) K) := NoZeroSMulDivisors.algebraMap_injective _ _ /-- The canonical map from `𝓞 K` to `K` is injective. This is a convenient abbreviation for `map_eq_zero_iff` applied to `NoZeroSMulDivisors.algebraMap_injective`. -/ @[simp] lemma coe_eq_zero_iff {x : 𝓞 K} : algebraMap _ K x = 0 ↔ x = 0 := map_eq_zero_iff _ coe_injective /-- The canonical map from `𝓞 K` to `K` is injective. This is a convenient abbreviation for `map_ne_zero_iff` applied to `NoZeroSMulDivisors.algebraMap_injective`. -/ lemma coe_ne_zero_iff {x : 𝓞 K} : algebraMap _ K x ≠ 0 ↔ x ≠ 0 := map_ne_zero_iff _ coe_injective theorem isIntegral_coe (x : 𝓞 K) : IsIntegral ℤ (algebraMap _ K x) := x.2 theorem isIntegral (x : 𝓞 K) : IsIntegral ℤ x := by obtain ⟨P, hPm, hP⟩ := x.isIntegral_coe refine ⟨P, hPm, ?_⟩ rwa [IsScalarTower.algebraMap_eq (S := 𝓞 K), ← Polynomial.hom_eval₂, coe_eq_zero_iff] at hP instance [NumberField K] : IsFractionRing (𝓞 K) K := integralClosure.isFractionRing_of_finite_extension ℚ _ instance : IsIntegralClosure (𝓞 K) ℤ K := integralClosure.isIntegralClosure _ _ instance [NumberField K] : IsIntegrallyClosed (𝓞 K) := integralClosure.isIntegrallyClosedOfFiniteExtension ℚ /-- The ring of integers of `K` are equivalent to any integral closure of `ℤ` in `K` -/ protected noncomputable def equiv (R : Type*) [CommRing R] [Algebra R K] [IsIntegralClosure R ℤ K] : 𝓞 K ≃+* R := (IsIntegralClosure.equiv ℤ R K _).symm.toRingEquiv variable (K) instance [CharZero K] : CharZero (𝓞 K) := CharZero.of_module _ K variable [NumberField K] instance : IsNoetherian ℤ (𝓞 K) := IsIntegralClosure.isNoetherian _ ℚ K _ /-- The ring of integers of a number field is not a field. -/ theorem not_isField : ¬IsField (𝓞 K) := by have h_inj : Function.Injective (algebraMap ℤ (𝓞 K)) := RingHom.injective_int (algebraMap ℤ (𝓞 K)) intro hf exact Int.not_isField (((IsIntegralClosure.isIntegral_algebra ℤ K).isField_iff_isField h_inj).mpr hf) instance : IsDedekindDomain (𝓞 K) := IsIntegralClosure.isDedekindDomain ℤ ℚ K _ instance : Free ℤ (𝓞 K) := IsIntegralClosure.module_free ℤ ℚ K (𝓞 K) instance : IsLocalization (Algebra.algebraMapSubmonoid (𝓞 K) ℤ⁰) K := IsIntegralClosure.isLocalization_of_isSeparable ℤ ℚ K (𝓞 K) /-- A ℤ-basis of the ring of integers of `K`. -/ noncomputable def basis : Basis (Free.ChooseBasisIndex ℤ (𝓞 K)) ℤ (𝓞 K) := Free.chooseBasis ℤ (𝓞 K) variable {K} {M : Type*} /-- Given `f : M → K` such that `∀ x, IsIntegral ℤ (f x)`, the corresponding function `M → 𝓞 K`. -/ def restrict (f : M → K) (h : ∀ x, IsIntegral ℤ (f x)) (x : M) : 𝓞 K := ⟨f x, h x⟩ /-- Given `f : M →+ K` such that `∀ x, IsIntegral ℤ (f x)`, the corresponding function `M →+ 𝓞 K`. -/ def restrict_addMonoidHom [AddZeroClass M] (f : M →+ K) (h : ∀ x, IsIntegral ℤ (f x)) : M →+ 𝓞 K where toFun := restrict f h map_zero' := by simp only [restrict, map_zero, mk_zero] map_add' x y := by simp only [restrict, map_add, mk_add_mk _] /-- Given `f : M →* K` such that `∀ x, IsIntegral ℤ (f x)`, the corresponding function `M →* 𝓞 K`. -/ @[to_additive existing] -- TODO: why doesn't it figure this out by itself? def restrict_monoidHom [MulOneClass M] (f : M →* K) (h : ∀ x, IsIntegral ℤ (f x)) : M →* 𝓞 K where toFun := restrict f h map_one' := by simp only [restrict, map_one, mk_one] map_mul' x y := by simp only [restrict, map_mul, mk_mul_mk _] end RingOfIntegers variable [NumberField K] /-- A basis of `K` over `ℚ` that is also a basis of `𝓞 K` over `ℤ`. -/ noncomputable def integralBasis : Basis (Free.ChooseBasisIndex ℤ (𝓞 K)) ℚ K := Basis.localizationLocalization ℚ (nonZeroDivisors ℤ) K (RingOfIntegers.basis K) @[simp] theorem integralBasis_apply (i : Free.ChooseBasisIndex ℤ (𝓞 K)) : integralBasis K i = algebraMap (𝓞 K) K (RingOfIntegers.basis K i) := Basis.localizationLocalization_apply ℚ (nonZeroDivisors ℤ) K (RingOfIntegers.basis K) i @[simp] theorem integralBasis_repr_apply (x : (𝓞 K)) (i : Free.ChooseBasisIndex ℤ (𝓞 K)) : (integralBasis K).repr (algebraMap _ _ x) i = (algebraMap ℤ ℚ) ((RingOfIntegers.basis K).repr x i) := Basis.localizationLocalization_repr_algebraMap ℚ (nonZeroDivisors ℤ) K _ x i theorem mem_span_integralBasis {x : K} : x ∈ Submodule.span ℤ (Set.range (integralBasis K)) ↔ x ∈ (algebraMap (𝓞 K) K).range := by rw [integralBasis, Basis.localizationLocalization_span, LinearMap.mem_range, IsScalarTower.coe_toAlgHom', RingHom.mem_range] theorem RingOfIntegers.rank : FiniteDimensional.finrank ℤ (𝓞 K) = FiniteDimensional.finrank ℚ K := IsIntegralClosure.rank ℤ ℚ K (𝓞 K) end NumberField namespace Rat open NumberField instance numberField : NumberField ℚ where to_charZero := inferInstance to_finiteDimensional := by -- The vector space structure of `ℚ` over itself can arise in multiple ways: -- all fields are vector spaces over themselves (used in `Rat.finiteDimensional`) -- all char 0 fields have a canonical embedding of `ℚ` (used in `NumberField`). -- Show that these coincide: convert (inferInstance : FiniteDimensional ℚ ℚ) /-- The ring of integers of `ℚ` as a number field is just `ℤ`. -/ noncomputable def ringOfIntegersEquiv : 𝓞 ℚ ≃+* ℤ := RingOfIntegers.equiv ℤ end Rat namespace AdjoinRoot section open scoped Polynomial attribute [-instance] DivisionRing.toRatAlgebra /-- The quotient of `ℚ[X]` by the ideal generated by an irreducible polynomial of `ℚ[X]` is a number field. -/ instance {f : Polynomial ℚ} [hf : Fact (Irreducible f)] : NumberField (AdjoinRoot f) where to_charZero := charZero_of_injective_algebraMap (algebraMap ℚ _).injective to_finiteDimensional := by convert (AdjoinRoot.powerBasis hf.out.ne_zero).finite end end AdjoinRoot
NumberTheory\NumberField\ClassNumber.lean
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.NumberTheory.ClassNumber.AdmissibleAbs import Mathlib.NumberTheory.ClassNumber.Finite import Mathlib.NumberTheory.NumberField.Discriminant /-! # 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 - `NumberField.classNumber`: the class number of a number field is the (finite) cardinality of the class group of its ring of integers -/ namespace NumberField variable (K : Type*) [Field K] [NumberField K] 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)) 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 open FiniteDimensional NumberField.InfinitePlace open scoped nonZeroDivisors Real theorem exists_ideal_in_class_of_norm_le (C : ClassGroup (𝓞 K)) : ∃ I : (Ideal (𝓞 K))⁰, ClassGroup.mk0 I = C ∧ Ideal.absNorm (I : Ideal (𝓞 K)) ≤ (4 / π) ^ NrComplexPlaces K * ((finrank ℚ K).factorial / (finrank ℚ K) ^ (finrank ℚ K) * Real.sqrt |discr 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⟩ := Ideal.dvd_iff_le.mpr ((Ideal.span_singleton_le_iff_mem J).mpr (by convert ha)) have : I₀ ≠ 0 := by contrapose! h_nz rw [h_nz, mul_zero, show 0 = (⊥ : Ideal (𝓞 K)) by rfl, Ideal.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, Nat.cast_mul, Rat.cast_mul, show Ideal.absNorm I₀ = Ideal.absNorm (I : Ideal (𝓞 K)) by rfl, 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 Nat.cast_pos.mpr <| Nat.pos_of_ne_zero <| Ideal.absNorm_ne_zero_of_nonZeroDivisors J theorem _root_.RingOfIntegers.isPrincipalIdealRing_of_abs_discr_lt (h : |discr K| < (2 * (π / 4) ^ NrComplexPlaces K * ((finrank ℚ K) ^ (finrank ℚ K) / (finrank ℚ K).factorial)) ^ 2) : IsPrincipalIdealRing (𝓞 K) := by have : 0 < finrank ℚ K := finrank_pos -- Lean needs to know that 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 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 have : Ideal.absNorm I.1 = 1 := by refine le_antisymm (Nat.lt_succ.mp ?_) (Nat.one_le_iff_ne_zero.mpr (Ideal.absNorm_ne_zero_of_nonZeroDivisors I)) exact Nat.cast_lt.mp <| lt_of_le_of_lt hI h rw [ClassGroup.mk0_eq_one_iff, Ideal.absNorm_eq_one_iff.mp this] exact top_isPrincipal end NumberField namespace Rat open NumberField theorem classNumber_eq : NumberField.classNumber ℚ = 1 := classNumber_eq_one_iff.mpr <| by convert IsPrincipalIdealRing.of_surjective (Rat.ringOfIntegersEquiv.symm : ℤ →+* 𝓞 ℚ) Rat.ringOfIntegersEquiv.symm.surjective end Rat
NumberTheory\NumberField\Discriminant.lean
/- Copyright (c) 2023 Xavier Roblot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Xavier Roblot -/ import Mathlib.Data.Real.Pi.Bounds import Mathlib.NumberTheory.NumberField.CanonicalEmbedding.ConvexBody import Mathlib.Tactic.Rify /-! # Number field discriminant This file defines the discriminant of a number field. ## Main definitions * `NumberField.discr`: the absolute discriminant of a number field. ## Main result * `NumberField.abs_discr_gt_two`: **Hermite-Minkowski Theorem**. A nontrivial number field has discriminant greater than `2`. * `NumberField.finite_of_discr_bdd`: **Hermite Theorem**. Let `N` be an integer. There are only finitely many number fields (in some fixed extension of `ℚ`) of discriminant bounded by `N`. ## Tags number field, discriminant -/ -- TODO. Rewrite some of the FLT results on the disciminant using the definitions and results of -- this file namespace NumberField open FiniteDimensional NumberField NumberField.InfinitePlace Matrix open scoped Classical Real nonZeroDivisors variable (K : Type*) [Field K] [NumberField K] /-- The absolute discriminant of a number field. -/ noncomputable abbrev discr : ℤ := Algebra.discr ℤ (RingOfIntegers.basis K) theorem coe_discr : (discr K : ℚ) = Algebra.discr ℚ (integralBasis K) := (Algebra.discr_localizationLocalization ℤ _ K (RingOfIntegers.basis K)).symm theorem discr_ne_zero : discr K ≠ 0 := by rw [← (Int.cast_injective (α := ℚ)).ne_iff, coe_discr] exact Algebra.discr_not_zero_of_basis ℚ (integralBasis K) theorem discr_eq_discr {ι : Type*} [Fintype ι] [DecidableEq ι] (b : Basis ι ℤ (𝓞 K)) : Algebra.discr ℤ b = discr K := by let b₀ := Basis.reindex (RingOfIntegers.basis K) (Basis.indexEquiv (RingOfIntegers.basis K) b) rw [Algebra.discr_eq_discr (𝓞 K) b b₀, Basis.coe_reindex, Algebra.discr_reindex] theorem discr_eq_discr_of_algEquiv {L : Type*} [Field L] [NumberField L] (f : K ≃ₐ[ℚ] L) : discr K = discr L := by let f₀ : 𝓞 K ≃ₗ[ℤ] 𝓞 L := (f.restrictScalars ℤ).mapIntegralClosure.toLinearEquiv rw [← Rat.intCast_inj, coe_discr, Algebra.discr_eq_discr_of_algEquiv (integralBasis K) f, ← discr_eq_discr L ((RingOfIntegers.basis K).map f₀)] change _ = algebraMap ℤ ℚ _ rw [← Algebra.discr_localizationLocalization ℤ (nonZeroDivisors ℤ) L] congr ext simp only [Function.comp_apply, integralBasis_apply, Basis.localizationLocalization_apply, Basis.map_apply] rfl open MeasureTheory MeasureTheory.Measure Zspan NumberField.mixedEmbedding NumberField.InfinitePlace ENNReal NNReal Complex theorem _root_.NumberField.mixedEmbedding.volume_fundamentalDomain_latticeBasis : volume (fundamentalDomain (latticeBasis K)) = (2 : ℝ≥0∞)⁻¹ ^ NrComplexPlaces K * sqrt ‖discr K‖₊ := by let f : Module.Free.ChooseBasisIndex ℤ (𝓞 K) ≃ (K →+* ℂ) := (canonicalEmbedding.latticeBasis K).indexEquiv (Pi.basisFun ℂ _) let e : (index K) ≃ Module.Free.ChooseBasisIndex ℤ (𝓞 K) := (indexEquiv K).trans f.symm let M := (mixedEmbedding.stdBasis K).toMatrix ((latticeBasis K).reindex e.symm) let N := Algebra.embeddingsMatrixReindex ℚ ℂ (integralBasis K ∘ f.symm) RingHom.equivRatAlgHom suffices M.map Complex.ofReal = (matrixToStdBasis K) * (Matrix.reindex (indexEquiv K).symm (indexEquiv K).symm N).transpose by calc volume (fundamentalDomain (latticeBasis K)) _ = ‖((mixedEmbedding.stdBasis K).toMatrix ((latticeBasis K).reindex e.symm)).det‖₊ := by rw [← fundamentalDomain_reindex _ e.symm, ← norm_toNNReal, measure_fundamentalDomain ((latticeBasis K).reindex e.symm), volume_fundamentalDomain_stdBasis, mul_one] rfl _ = ‖(matrixToStdBasis K).det * N.det‖₊ := by rw [← nnnorm_real, ← ofReal_eq_coe, RingHom.map_det, RingHom.mapMatrix_apply, this, det_mul, det_transpose, det_reindex_self] _ = (2 : ℝ≥0∞)⁻¹ ^ Fintype.card {w : InfinitePlace K // IsComplex w} * sqrt ‖N.det ^ 2‖₊ := by have : ‖Complex.I‖₊ = 1 := by rw [← norm_toNNReal, norm_eq_abs, abs_I, Real.toNNReal_one] rw [det_matrixToStdBasis, nnnorm_mul, nnnorm_pow, nnnorm_mul, this, mul_one, nnnorm_inv, coe_mul, ENNReal.coe_pow, ← norm_toNNReal, RCLike.norm_two, Real.toNNReal_ofNat, coe_inv two_ne_zero, coe_ofNat, nnnorm_pow, NNReal.sqrt_sq] _ = (2 : ℝ≥0∞)⁻¹ ^ Fintype.card { w // IsComplex w } * NNReal.sqrt ‖discr K‖₊ := by rw [← Algebra.discr_eq_det_embeddingsMatrixReindex_pow_two, Algebra.discr_reindex, ← coe_discr, map_intCast, ← Complex.nnnorm_int] ext : 2 dsimp only [M] rw [Matrix.map_apply, Basis.toMatrix_apply, Basis.coe_reindex, Function.comp_apply, Equiv.symm_symm, latticeBasis_apply, ← commMap_canonical_eq_mixed, Complex.ofReal_eq_coe, stdBasis_repr_eq_matrixToStdBasis_mul K _ (fun _ => rfl)] rfl theorem exists_ne_zero_mem_ideal_of_norm_le_mul_sqrt_discr (I : (FractionalIdeal (𝓞 K)⁰ K)ˣ) : ∃ a ∈ (I : FractionalIdeal (𝓞 K)⁰ K), a ≠ 0 ∧ |Algebra.norm ℚ (a : K)| ≤ FractionalIdeal.absNorm I.1 * (4 / π) ^ NrComplexPlaces K * (finrank ℚ K).factorial / (finrank ℚ K) ^ (finrank ℚ K) * Real.sqrt |discr K| := by -- The smallest possible value for `exists_ne_zero_mem_ideal_of_norm_le` let B := (minkowskiBound K I * (convexBodySumFactor K)⁻¹).toReal ^ (1 / (finrank ℚ K : ℝ)) have h_le : (minkowskiBound K I) ≤ volume (convexBodySum K B) := by refine le_of_eq ?_ rw [convexBodySum_volume, ← ENNReal.ofReal_pow (by positivity), ← Real.rpow_natCast, ← Real.rpow_mul toReal_nonneg, div_mul_cancel₀, Real.rpow_one, ofReal_toReal, mul_comm, mul_assoc, ← coe_mul, inv_mul_cancel (convexBodySumFactor_ne_zero K), ENNReal.coe_one, mul_one] · exact mul_ne_top (ne_of_lt (minkowskiBound_lt_top K I)) coe_ne_top · exact (Nat.cast_ne_zero.mpr (ne_of_gt finrank_pos)) convert exists_ne_zero_mem_ideal_of_norm_le K I h_le rw [div_pow B, ← Real.rpow_natCast B, ← Real.rpow_mul (by positivity), div_mul_cancel₀ _ (Nat.cast_ne_zero.mpr <| ne_of_gt finrank_pos), Real.rpow_one, mul_comm_div, mul_div_assoc'] congr 1 rw [eq_comm] calc _ = FractionalIdeal.absNorm I.1 * (2 : ℝ)⁻¹ ^ NrComplexPlaces K * sqrt ‖discr K‖₊ * (2 : ℝ) ^ finrank ℚ K * ((2 : ℝ) ^ NrRealPlaces K * (π / 2) ^ NrComplexPlaces K / (Nat.factorial (finrank ℚ K)))⁻¹ := by simp_rw [minkowskiBound, convexBodySumFactor, volume_fundamentalDomain_fractionalIdealLatticeBasis, volume_fundamentalDomain_latticeBasis, toReal_mul, toReal_pow, toReal_inv, coe_toReal, toReal_ofNat, mixedEmbedding.finrank, mul_assoc] rw [ENNReal.toReal_ofReal (Rat.cast_nonneg.mpr (FractionalIdeal.absNorm_nonneg I.1))] simp_rw [NNReal.coe_inv, NNReal.coe_div, NNReal.coe_mul, NNReal.coe_pow, NNReal.coe_div, coe_real_pi, NNReal.coe_ofNat, NNReal.coe_natCast] _ = FractionalIdeal.absNorm I.1 * (2 : ℝ) ^ (finrank ℚ K - NrComplexPlaces K - NrRealPlaces K + NrComplexPlaces K : ℤ) * Real.sqrt ‖discr K‖ * Nat.factorial (finrank ℚ K) * π⁻¹ ^ (NrComplexPlaces K) := by simp_rw [inv_div, div_eq_mul_inv, mul_inv, ← zpow_neg_one, ← zpow_natCast, mul_zpow, ← zpow_mul, neg_one_mul, mul_neg_one, neg_neg, Real.coe_sqrt, coe_nnnorm, sub_eq_add_neg, zpow_add₀ (two_ne_zero : (2 : ℝ) ≠ 0)] ring _ = FractionalIdeal.absNorm I.1 * (2 : ℝ) ^ (2 * NrComplexPlaces K : ℤ) * Real.sqrt ‖discr K‖ * Nat.factorial (finrank ℚ K) * π⁻¹ ^ (NrComplexPlaces K) := by congr rw [← card_add_two_mul_card_eq_rank, Nat.cast_add, Nat.cast_mul, Nat.cast_ofNat] ring _ = FractionalIdeal.absNorm I.1 * (4 / π) ^ NrComplexPlaces K * (finrank ℚ K).factorial * Real.sqrt |discr K| := by rw [Int.norm_eq_abs, zpow_mul, show (2 : ℝ) ^ (2 : ℤ) = 4 by norm_cast, div_pow, inv_eq_one_div, div_pow, one_pow, zpow_natCast] ring theorem exists_ne_zero_mem_ringOfIntegers_of_norm_le_mul_sqrt_discr : ∃ (a : 𝓞 K), a ≠ 0 ∧ |Algebra.norm ℚ (a : K)| ≤ (4 / π) ^ NrComplexPlaces K * (finrank ℚ K).factorial / (finrank ℚ K) ^ (finrank ℚ K) * Real.sqrt |discr K| := by obtain ⟨_, h_mem, h_nz, h_nm⟩ := exists_ne_zero_mem_ideal_of_norm_le_mul_sqrt_discr K ↑1 obtain ⟨a, rfl⟩ := (FractionalIdeal.mem_one_iff _).mp h_mem refine ⟨a, ne_zero_of_map h_nz, ?_⟩ simp_rw [Units.val_one, FractionalIdeal.absNorm_one, Rat.cast_one, one_mul] at h_nm exact h_nm variable {K} theorem abs_discr_ge (h : 1 < finrank ℚ K) : (4 / 9 : ℝ) * (3 * π / 4) ^ finrank ℚ K ≤ |discr K| := by -- We use `exists_ne_zero_mem_ringOfIntegers_of_norm_le_mul_sqrt_discr` to get a nonzero -- algebraic integer `x` of small norm and the fact that `1 ≤ |Norm x|` to get a lower bound -- on `sqrt |discr K|`. obtain ⟨x, h_nz, h_bd⟩ := exists_ne_zero_mem_ringOfIntegers_of_norm_le_mul_sqrt_discr K have h_nm : (1 : ℝ) ≤ |Algebra.norm ℚ (x : K)| := by rw [← Algebra.coe_norm_int, ← Int.cast_one, ← Int.cast_abs, Rat.cast_intCast, Int.cast_le] exact Int.one_le_abs (Algebra.norm_ne_zero_iff.mpr h_nz) replace h_bd := le_trans h_nm h_bd rw [← inv_mul_le_iff (by positivity), inv_div, mul_one, Real.le_sqrt (by positivity) (by positivity), ← Int.cast_abs, div_pow, mul_pow, ← pow_mul, ← pow_mul] at h_bd refine le_trans ?_ h_bd -- The sequence `a n` is a lower bound for `|discr K|`. We prove below by induction an uniform -- lower bound for this sequence from which we deduce the result. let a : ℕ → ℝ := fun n => (n : ℝ) ^ (n * 2) / ((4 / π) ^ n * (n.factorial : ℝ) ^ 2) suffices ∀ n, 2 ≤ n → (4 / 9 : ℝ) * (3 * π / 4) ^ n ≤ a n by refine le_trans (this (finrank ℚ K) h) ?_ simp only [a] gcongr · exact (one_le_div Real.pi_pos).2 Real.pi_le_four · rw [← card_add_two_mul_card_eq_rank, mul_comm] exact Nat.le_add_left _ _ intro n hn induction n, hn using Nat.le_induction with | base => exact le_of_eq <| by norm_num [a, Nat.factorial_two]; field_simp; ring | succ m _ h_m => suffices (3 : ℝ) ≤ (1 + 1 / m : ℝ) ^ (2 * m) by convert_to _ ≤ (a m) * (1 + 1 / m : ℝ) ^ (2 * m) / (4 / π) · simp_rw [a, add_mul, one_mul, pow_succ, Nat.factorial_succ] field_simp; ring · rw [_root_.le_div_iff (by positivity), pow_succ] convert (mul_le_mul h_m this (by positivity) (by positivity)) using 1 field_simp; ring refine le_trans (le_of_eq (by field_simp; norm_num)) (one_add_mul_le_pow ?_ (2 * m)) exact le_trans (by norm_num : (-2 : ℝ) ≤ 0) (by positivity) /-- **Hermite-Minkowski Theorem**. A nontrivial number field has discriminant greater than `2`. -/ theorem abs_discr_gt_two (h : 1 < finrank ℚ K) : 2 < |discr K| := by rw [← Nat.succ_le_iff] at h rify calc (2 : ℝ) < (4 / 9) * (3 * π / 4) ^ 2 := by nlinarith [Real.pi_gt_three] _ ≤ (4 / 9 : ℝ) * (3 * π / 4) ^ finrank ℚ K := by gcongr linarith [Real.pi_gt_three] _ ≤ |(discr K : ℝ)| := mod_cast abs_discr_ge h /-! ### Hermite Theorem This section is devoted to the proof of Hermite theorem. Let `N` be an integer . We prove that the set `S` of finite extensions `K` of `ℚ` (in some fixed extension `A` of `ℚ`) such that `|discr K| ≤ N` is finite by proving, using `finite_of_finite_generating_set`, that there exists a finite set `T ⊆ A` such that `∀ K ∈ S, ∃ x ∈ T, K = ℚ⟮x⟯` . To find the set `T`, we construct a finite set `T₀` of polynomials in `ℤ[X]` containing, for each `K ∈ S`, the minimal polynomial of a primitive element of `K`. The set `T` is then the union of roots in `A` of the polynomials in `T₀`. More precisely, the set `T₀` is the set of all polynomials in `ℤ[X]` of degrees and coefficients bounded by some explicit constants depending only on `N`. Indeed, we prove that, for any field `K` in `S`, its degree is bounded, see `rank_le_rankOfDiscrBdd`, and also its Minkowski bound, see `minkowskiBound_lt_boundOfDiscBdd`. Thus it follows from `mixedEmbedding.exists_primitive_element_lt_of_isComplex` and `mixedEmbedding.exists_primitive_element_lt_of_isReal` that there exists an algebraic integer `x` of `K` such that `K = ℚ(x)` and the conjugates of `x` are all bounded by some quantity depending only on `N`. Since the primitive element `x` is constructed differently depending on wether `K` has a infinite real place or not, the theorem is proved in two parts. -/ namespace hermiteTheorem open Polynomial open scoped IntermediateField variable (A : Type*) [Field A] [CharZero A] theorem finite_of_finite_generating_set {p : IntermediateField ℚ A → Prop} (S : Set {F : IntermediateField ℚ A // p F}) {T : Set A} (hT : T.Finite) (h : ∀ F ∈ S, ∃ x ∈ T, F = ℚ⟮x⟯) : S.Finite := by rw [← Set.finite_coe_iff] at hT refine Set.finite_coe_iff.mp <| Finite.of_injective (fun ⟨F, hF⟩ ↦ (⟨(h F hF).choose, (h F hF).choose_spec.1⟩ : T)) (fun _ _ h_eq ↦ ?_) rw [Subtype.ext_iff_val, Subtype.ext_iff_val] convert congr_arg (ℚ⟮·⟯) (Subtype.mk_eq_mk.mp h_eq) all_goals exact (h _ (Subtype.mem _)).choose_spec.2 variable (N : ℕ) /-- An upper bound on the degree of a number field `K` with `|discr K| ≤ N`, see `rank_le_rankOfDiscrBdd`. -/ noncomputable abbrev rankOfDiscrBdd : ℕ := max 1 (Nat.floor ((Real.log ((9 / 4 : ℝ) * N) / Real.log (3 * π / 4)))) /-- An upper bound on the Minkowski bound of a number field `K` with `|discr K| ≤ N`; see `minkowskiBound_lt_boundOfDiscBdd`. -/ noncomputable abbrev boundOfDiscBdd : ℝ≥0 := sqrt N * (2 : ℝ≥0) ^ rankOfDiscrBdd N + 1 variable {N} (hK : |discr K| ≤ N) /-- If `|discr K| ≤ N` then the degree of `K` is at most `rankOfDiscrBdd`. -/ theorem rank_le_rankOfDiscrBdd : finrank ℚ K ≤ rankOfDiscrBdd N := by have h_nz : N ≠ 0 := by refine fun h ↦ discr_ne_zero K ?_ rwa [h, Nat.cast_zero, abs_nonpos_iff] at hK have h₂ : 1 < 3 * π / 4 := by rw [_root_.lt_div_iff (by positivity), ← _root_.div_lt_iff' (by positivity), one_mul] linarith [Real.pi_gt_three] obtain h | h := lt_or_le 1 (finrank ℚ K) · apply le_max_of_le_right rw [Nat.le_floor_iff] · have h := le_trans (abs_discr_ge h) (Int.cast_le.mpr hK) contrapose! h rw [← Real.rpow_natCast] rw [Real.log_div_log] at h refine lt_of_le_of_lt ?_ (mul_lt_mul_of_pos_left (Real.rpow_lt_rpow_of_exponent_lt h₂ h) (by positivity : (0 : ℝ) < 4 / 9)) rw [Real.rpow_logb (lt_trans zero_lt_one h₂) (ne_of_gt h₂) (by positivity), ← mul_assoc, ← inv_div, inv_mul_cancel (by norm_num), one_mul, Int.cast_natCast] · refine div_nonneg (Real.log_nonneg ?_) (Real.log_nonneg (le_of_lt h₂)) rw [mul_comm, ← mul_div_assoc, _root_.le_div_iff (by positivity), one_mul, ← _root_.div_le_iff (by positivity)] exact le_trans (by norm_num) (Nat.one_le_cast.mpr (Nat.one_le_iff_ne_zero.mpr h_nz)) · exact le_max_of_le_left h /-- If `|discr K| ≤ N` then the Minkowski bound of `K` is less than `boundOfDiscrBdd`. -/ theorem minkowskiBound_lt_boundOfDiscBdd : minkowskiBound K ↑1 < boundOfDiscBdd N := by have : boundOfDiscBdd N - 1 < boundOfDiscBdd N := by simp_rw [boundOfDiscBdd, add_tsub_cancel_right, lt_add_iff_pos_right, zero_lt_one] refine lt_of_le_of_lt ?_ (coe_lt_coe.mpr this) rw [minkowskiBound, volume_fundamentalDomain_fractionalIdealLatticeBasis, boundOfDiscBdd, add_tsub_cancel_right, Units.val_one, FractionalIdeal.absNorm_one, Rat.cast_one, ENNReal.ofReal_one, one_mul, mixedEmbedding.finrank, volume_fundamentalDomain_latticeBasis, coe_mul, ENNReal.coe_pow, coe_ofNat, show sqrt N = (1 : ℝ≥0∞) * sqrt N by rw [one_mul]] gcongr · exact pow_le_one _ (by positivity) (by norm_num) · rwa [sqrt_le_sqrt, ← NNReal.coe_le_coe, coe_nnnorm, Int.norm_eq_abs, ← Int.cast_abs, NNReal.coe_natCast, ← Int.cast_natCast, Int.cast_le] · exact one_le_two · exact rank_le_rankOfDiscrBdd hK theorem natDegree_le_rankOfDiscrBdd (a : 𝓞 K) (h : ℚ⟮(a : K)⟯ = ⊤) : natDegree (minpoly ℤ (a : K)) ≤ rankOfDiscrBdd N := by rw [Field.primitive_element_iff_minpoly_natDegree_eq, minpoly.isIntegrallyClosed_eq_field_fractions' ℚ a.isIntegral_coe, (minpoly.monic a.isIntegral_coe).natDegree_map] at h exact h.symm ▸ rank_le_rankOfDiscrBdd hK variable (N) theorem finite_of_discr_bdd_of_isReal : {K : { F : IntermediateField ℚ A // FiniteDimensional ℚ F} | haveI : NumberField K := @NumberField.mk _ _ inferInstance K.prop {w : InfinitePlace K | IsReal w}.Nonempty ∧ |discr K| ≤ N }.Finite := by -- The bound on the degree of the generating polynomials let D := rankOfDiscrBdd N -- The bound on the Minkowski bound let B := boundOfDiscBdd N -- The bound on the coefficients of the generating polynomials let C := Nat.ceil ((max B 1) ^ D * Nat.choose D (D / 2)) refine finite_of_finite_generating_set A _ (bUnion_roots_finite (algebraMap ℤ A) D (Set.finite_Icc (-C : ℤ) C)) (fun ⟨K, hK₀⟩ ⟨hK₁, hK₂⟩ ↦ ?_) -- We now need to prove that each field is generated by an element of the union of the rootset simp_rw [Set.mem_iUnion] haveI : NumberField K := @NumberField.mk _ _ inferInstance hK₀ obtain ⟨w₀, hw₀⟩ := hK₁ suffices minkowskiBound K ↑1 < (convexBodyLTFactor K) * B by obtain ⟨x, hx₁, hx₂⟩ := exists_primitive_element_lt_of_isReal K hw₀ this have hx := x.isIntegral_coe refine ⟨x, ⟨⟨minpoly ℤ (x : K), ⟨?_, fun i ↦ ?_⟩, ?_⟩, ?_⟩⟩ · exact natDegree_le_rankOfDiscrBdd hK₂ x hx₁ · rw [Set.mem_Icc, ← abs_le, ← @Int.cast_le ℝ] refine (Eq.trans_le ?_ <| Embeddings.coeff_bdd_of_norm_le ((le_iff_le (x : K) _).mp (fun w ↦ le_of_lt (hx₂ w))) i).trans ?_ · rw [minpoly.isIntegrallyClosed_eq_field_fractions' ℚ hx, coeff_map, eq_intCast, Int.norm_cast_rat, Int.norm_eq_abs, Int.cast_abs] · refine le_trans ?_ (Nat.le_ceil _) rw [show max ↑(max (B : ℝ≥0) 1) (1 : ℝ) = max (B : ℝ) 1 by simp, val_eq_coe, NNReal.coe_mul, NNReal.coe_pow, NNReal.coe_max, NNReal.coe_one, NNReal.coe_natCast] gcongr · exact le_max_right _ 1 · exact rank_le_rankOfDiscrBdd hK₂ · exact (Nat.choose_le_choose _ (rank_le_rankOfDiscrBdd hK₂)).trans (Nat.choose_le_middle _ _) · refine mem_rootSet.mpr ⟨minpoly.ne_zero hx, ?_⟩ exact (aeval_algebraMap_eq_zero_iff _ _ _).mpr (minpoly.aeval ℤ (x : K)) · rw [← (IntermediateField.lift_injective _).eq_iff, eq_comm] at hx₁ convert hx₁ <;> simp have := one_le_convexBodyLTFactor K convert lt_of_le_of_lt (mul_right_mono (coe_le_coe.mpr this)) (ENNReal.mul_lt_mul_left' (by positivity) coe_ne_top (minkowskiBound_lt_boundOfDiscBdd hK₂)) simp_rw [ENNReal.coe_one, one_mul] theorem finite_of_discr_bdd_of_isComplex : {K : { F : IntermediateField ℚ A // FiniteDimensional ℚ F} | haveI : NumberField K := @NumberField.mk _ _ inferInstance K.prop {w : InfinitePlace K | IsComplex w}.Nonempty ∧ |discr K| ≤ N }.Finite := by -- The bound on the degree of the generating polynomials let D := rankOfDiscrBdd N -- The bound on the Minkowski bound let B := boundOfDiscBdd N -- The bound on the coefficients of the generating polynomials let C := Nat.ceil ((max (sqrt (1 + B ^ 2)) 1) ^ D * Nat.choose D (D / 2)) refine finite_of_finite_generating_set A _ (bUnion_roots_finite (algebraMap ℤ A) D (Set.finite_Icc (-C : ℤ) C)) (fun ⟨K, hK₀⟩ ⟨hK₁, hK₂⟩ ↦ ?_) -- We now need to prove that each field is generated by an element of the union of the rootset simp_rw [Set.mem_iUnion] haveI : NumberField K := @NumberField.mk _ _ inferInstance hK₀ obtain ⟨w₀, hw₀⟩ := hK₁ suffices minkowskiBound K ↑1 < (convexBodyLT'Factor K) * boundOfDiscBdd N by obtain ⟨x, hx₁, hx₂⟩ := exists_primitive_element_lt_of_isComplex K hw₀ this have hx := x.isIntegral_coe refine ⟨x, ⟨⟨minpoly ℤ (x : K), ⟨?_, fun i ↦ ?_⟩, ?_⟩, ?_⟩⟩ · exact natDegree_le_rankOfDiscrBdd hK₂ x hx₁ · rw [Set.mem_Icc, ← abs_le, ← @Int.cast_le ℝ] refine (Eq.trans_le ?_ <| Embeddings.coeff_bdd_of_norm_le ((le_iff_le (x : K) _).mp (fun w ↦ le_of_lt (hx₂ w))) i).trans ?_ · rw [minpoly.isIntegrallyClosed_eq_field_fractions' ℚ hx, coeff_map, eq_intCast, Int.norm_cast_rat, Int.norm_eq_abs, Int.cast_abs] · refine le_trans ?_ (Nat.le_ceil _) rw [val_eq_coe, NNReal.coe_mul, NNReal.coe_pow, NNReal.coe_max, NNReal.coe_one, Real.coe_sqrt, NNReal.coe_add 1, NNReal.coe_one, NNReal.coe_pow] gcongr · exact le_max_right _ 1 · exact rank_le_rankOfDiscrBdd hK₂ · rw [NNReal.coe_natCast, Nat.cast_le] exact (Nat.choose_le_choose _ (rank_le_rankOfDiscrBdd hK₂)).trans (Nat.choose_le_middle _ _) · refine mem_rootSet.mpr ⟨minpoly.ne_zero hx, ?_⟩ exact (aeval_algebraMap_eq_zero_iff _ _ _).mpr (minpoly.aeval ℤ (x : K)) · rw [← (IntermediateField.lift_injective _).eq_iff, eq_comm] at hx₁ convert hx₁ <;> simp have := one_le_convexBodyLT'Factor K convert lt_of_le_of_lt (mul_right_mono (coe_le_coe.mpr this)) (ENNReal.mul_lt_mul_left' (by positivity) coe_ne_top (minkowskiBound_lt_boundOfDiscBdd hK₂)) simp_rw [ENNReal.coe_one, one_mul] /-- **Hermite Theorem**. Let `N` be an integer. There are only finitely many number fields (in some fixed extension of `ℚ`) of discriminant bounded by `N`. -/ theorem _root_.NumberField.finite_of_discr_bdd : {K : { F : IntermediateField ℚ A // FiniteDimensional ℚ F} | haveI : NumberField K := @NumberField.mk _ _ inferInstance K.prop |discr K| ≤ N }.Finite := by refine Set.Finite.subset (Set.Finite.union (finite_of_discr_bdd_of_isReal A N) (finite_of_discr_bdd_of_isComplex A N)) ?_ rintro ⟨K, hK₀⟩ hK₁ haveI : NumberField K := @NumberField.mk _ _ inferInstance hK₀ obtain ⟨w₀⟩ := (inferInstance : Nonempty (InfinitePlace K)) by_cases hw₀ : IsReal w₀ · apply Set.mem_union_left exact ⟨⟨w₀, hw₀⟩, hK₁⟩ · apply Set.mem_union_right exact ⟨⟨w₀, not_isReal_iff_isComplex.mp hw₀⟩, hK₁⟩ end hermiteTheorem end NumberField namespace Rat open NumberField /-- The absolute discriminant of the number field `ℚ` is 1. -/ @[simp] theorem numberField_discr : discr ℚ = 1 := by let b : Basis (Fin 1) ℤ (𝓞 ℚ) := Basis.map (Basis.singleton (Fin 1) ℤ) ringOfIntegersEquiv.toAddEquiv.toIntLinearEquiv.symm calc NumberField.discr ℚ _ = Algebra.discr ℤ b := by convert (discr_eq_discr ℚ b).symm _ = Algebra.trace ℤ (𝓞 ℚ) (b default * b default) := by rw [Algebra.discr_def, Matrix.det_unique, Algebra.traceMatrix_apply, Algebra.traceForm_apply] _ = Algebra.trace ℤ (𝓞 ℚ) 1 := by rw [Basis.map_apply, RingEquiv.toAddEquiv_eq_coe, AddEquiv.toIntLinearEquiv_symm, AddEquiv.coe_toIntLinearEquiv, Basis.singleton_apply, show (AddEquiv.symm ↑ringOfIntegersEquiv) (1 : ℤ) = ringOfIntegersEquiv.symm 1 by rfl, map_one, mul_one] _ = 1 := by rw [Algebra.trace_eq_matrix_trace b]; norm_num alias _root_.NumberField.discr_rat := numberField_discr end Rat variable {ι ι'} (K) [Field K] [DecidableEq ι] [DecidableEq ι'] [Fintype ι] [Fintype ι'] /-- If `b` and `b'` are `ℚ`-bases of a number field `K` such that `∀ i j, IsIntegral ℤ (b.toMatrix b' i j)` and `∀ i j, IsIntegral ℤ (b'.toMatrix b i j)` then `discr ℚ b = discr ℚ b'`. -/ theorem Algebra.discr_eq_discr_of_toMatrix_coeff_isIntegral [NumberField K] {b : Basis ι ℚ K} {b' : Basis ι' ℚ K} (h : ∀ i j, IsIntegral ℤ (b.toMatrix b' i j)) (h' : ∀ i j, IsIntegral ℤ (b'.toMatrix b i j)) : discr ℚ b = discr ℚ b' := by replace h' : ∀ i j, IsIntegral ℤ (b'.toMatrix (b.reindex (b.indexEquiv b')) i j) := by intro i j convert h' i ((b.indexEquiv b').symm j) simp [Basis.toMatrix_apply] classical rw [← (b.reindex (b.indexEquiv b')).toMatrix_map_vecMul b', discr_of_matrix_vecMul, ← one_mul (discr ℚ b), Basis.coe_reindex, discr_reindex] congr have hint : IsIntegral ℤ ((b.reindex (b.indexEquiv b')).toMatrix b').det := IsIntegral.det fun i j => h _ _ obtain ⟨r, hr⟩ := IsIntegrallyClosed.isIntegral_iff.1 hint have hunit : IsUnit r := by have : IsIntegral ℤ (b'.toMatrix (b.reindex (b.indexEquiv b'))).det := IsIntegral.det fun i j => h' _ _ obtain ⟨r', hr'⟩ := IsIntegrallyClosed.isIntegral_iff.1 this refine isUnit_iff_exists_inv.2 ⟨r', ?_⟩ suffices algebraMap ℤ ℚ (r * r') = 1 by rw [← RingHom.map_one (algebraMap ℤ ℚ)] at this exact (IsFractionRing.injective ℤ ℚ) this rw [RingHom.map_mul, hr, hr', ← Matrix.det_mul, Basis.toMatrix_mul_toMatrix_flip, Matrix.det_one] rw [← RingHom.map_one (algebraMap ℤ ℚ), ← hr] cases' Int.isUnit_iff.1 hunit with hp hm · simp [hp] · simp [hm]
NumberTheory\NumberField\Embeddings.lean
/- Copyright (c) 2022 Xavier Roblot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alex J. Best, Xavier Roblot -/ import Mathlib.Algebra.Algebra.Hom.Rat import Mathlib.Analysis.Complex.Polynomial.Basic import Mathlib.NumberTheory.NumberField.Norm import Mathlib.NumberTheory.NumberField.Basic import Mathlib.RingTheory.Norm.Basic import Mathlib.Topology.Instances.Complex import Mathlib.RingTheory.RootsOfUnity.Basic /-! # Embeddings of number fields This file defines the embeddings of a number field into an algebraic closed field. ## Main Definitions and Results * `NumberField.Embeddings.range_eval_eq_rootSet_minpoly`: let `x ∈ K` with `K` number field and let `A` be an algebraic closed field of char. 0, then the images of `x` by the embeddings of `K` in `A` are exactly the roots in `A` of the minimal polynomial of `x` over `ℚ`. * `NumberField.Embeddings.pow_eq_one_of_norm_eq_one`: an algebraic integer whose conjugates are all of norm one is a root of unity. * `NumberField.InfinitePlace`: the type of infinite places of a number field `K`. * `NumberField.InfinitePlace.mk_eq_iff`: two complex embeddings define the same infinite place iff they are equal or complex conjugates. * `NumberField.InfinitePlace.prod_eq_abs_norm`: the infinite part of the product formula, that is for `x ∈ K`, we have `Π_w ‖x‖_w = |norm(x)|` where the product is over the infinite place `w` and `‖·‖_w` is the normalized absolute value for `w`. ## Tags number field, embeddings, places, infinite places -/ open scoped Classical namespace NumberField.Embeddings section Fintype open FiniteDimensional variable (K : Type*) [Field K] [NumberField K] variable (A : Type*) [Field A] [CharZero A] /-- There are finitely many embeddings of a number field. -/ noncomputable instance : Fintype (K →+* A) := Fintype.ofEquiv (K →ₐ[ℚ] A) RingHom.equivRatAlgHom.symm variable [IsAlgClosed A] /-- The number of embeddings of a number field is equal to its finrank. -/ theorem card : Fintype.card (K →+* A) = finrank ℚ K := by rw [Fintype.ofEquiv_card RingHom.equivRatAlgHom.symm, AlgHom.card] instance : Nonempty (K →+* A) := by rw [← Fintype.card_pos_iff, NumberField.Embeddings.card K A] exact FiniteDimensional.finrank_pos end Fintype section Roots open Set Polynomial variable (K A : Type*) [Field K] [NumberField K] [Field A] [Algebra ℚ A] [IsAlgClosed A] (x : K) /-- Let `A` be an algebraically closed field and let `x ∈ K`, with `K` a number field. The images of `x` by the embeddings of `K` in `A` are exactly the roots in `A` of the minimal polynomial of `x` over `ℚ`. -/ theorem range_eval_eq_rootSet_minpoly : (range fun φ : K →+* A => φ x) = (minpoly ℚ x).rootSet A := by convert (NumberField.isAlgebraic K).range_eval_eq_rootSet_minpoly A x using 1 ext a exact ⟨fun ⟨φ, hφ⟩ => ⟨φ.toRatAlgHom, hφ⟩, fun ⟨φ, hφ⟩ => ⟨φ.toRingHom, hφ⟩⟩ end Roots section Bounded open FiniteDimensional Polynomial Set variable {K : Type*} [Field K] [NumberField K] variable {A : Type*} [NormedField A] [IsAlgClosed A] [NormedAlgebra ℚ A] theorem coeff_bdd_of_norm_le {B : ℝ} {x : K} (h : ∀ φ : K →+* A, ‖φ x‖ ≤ B) (i : ℕ) : ‖(minpoly ℚ x).coeff i‖ ≤ max B 1 ^ finrank ℚ K * (finrank ℚ K).choose (finrank ℚ K / 2) := by have hx := Algebra.IsSeparable.isIntegral ℚ x rw [← norm_algebraMap' A, ← coeff_map (algebraMap ℚ A)] refine coeff_bdd_of_roots_le _ (minpoly.monic hx) (IsAlgClosed.splits_codomain _) (minpoly.natDegree_le x) (fun z hz => ?_) i classical rw [← Multiset.mem_toFinset] at hz obtain ⟨φ, rfl⟩ := (range_eval_eq_rootSet_minpoly K A x).symm.subset hz exact h φ variable (K A) /-- Let `B` be a real number. The set of algebraic integers in `K` whose conjugates are all smaller in norm than `B` is finite. -/ theorem finite_of_norm_le (B : ℝ) : {x : K | IsIntegral ℤ x ∧ ∀ φ : K →+* A, ‖φ x‖ ≤ B}.Finite := by let C := Nat.ceil (max B 1 ^ finrank ℚ K * (finrank ℚ K).choose (finrank ℚ K / 2)) have := bUnion_roots_finite (algebraMap ℤ K) (finrank ℚ K) (finite_Icc (-C : ℤ) C) refine this.subset fun x hx => ?_; simp_rw [mem_iUnion] have h_map_ℚ_minpoly := minpoly.isIntegrallyClosed_eq_field_fractions' ℚ hx.1 refine ⟨_, ⟨?_, fun i => ?_⟩, mem_rootSet.2 ⟨minpoly.ne_zero hx.1, minpoly.aeval ℤ x⟩⟩ · rw [← (minpoly.monic hx.1).natDegree_map (algebraMap ℤ ℚ), ← h_map_ℚ_minpoly] exact minpoly.natDegree_le x rw [mem_Icc, ← abs_le, ← @Int.cast_le ℝ] refine (Eq.trans_le ?_ <| coeff_bdd_of_norm_le hx.2 i).trans (Nat.le_ceil _) rw [h_map_ℚ_minpoly, coeff_map, eq_intCast, Int.norm_cast_rat, Int.norm_eq_abs, Int.cast_abs] /-- An algebraic integer whose conjugates are all of norm one is a root of unity. -/ theorem pow_eq_one_of_norm_eq_one {x : K} (hxi : IsIntegral ℤ x) (hx : ∀ φ : K →+* A, ‖φ x‖ = 1) : ∃ (n : ℕ) (_ : 0 < n), x ^ n = 1 := by obtain ⟨a, -, b, -, habne, h⟩ := @Set.Infinite.exists_ne_map_eq_of_mapsTo _ _ _ _ (x ^ · : ℕ → K) Set.infinite_univ (by exact fun a _ => ⟨hxi.pow a, fun φ => by simp [hx φ]⟩) (finite_of_norm_le K A (1 : ℝ)) wlog hlt : b < a · exact this K A hxi hx b a habne.symm h.symm (habne.lt_or_lt.resolve_right hlt) refine ⟨a - b, tsub_pos_of_lt hlt, ?_⟩ rw [← Nat.sub_add_cancel hlt.le, pow_add, mul_left_eq_self₀] at h refine h.resolve_right fun hp => ?_ specialize hx (IsAlgClosed.lift (R := ℚ)).toRingHom rw [pow_eq_zero hp, map_zero, norm_zero] at hx; norm_num at hx end Bounded end NumberField.Embeddings section Place variable {K : Type*} [Field K] {A : Type*} [NormedDivisionRing A] [Nontrivial A] (φ : K →+* A) /-- An embedding into a normed division ring defines a place of `K` -/ def NumberField.place : AbsoluteValue K ℝ := (IsAbsoluteValue.toAbsoluteValue (norm : A → ℝ)).comp φ.injective @[simp] theorem NumberField.place_apply (x : K) : (NumberField.place φ) x = norm (φ x) := rfl end Place namespace NumberField.ComplexEmbedding open Complex NumberField open scoped ComplexConjugate variable {K : Type*} [Field K] {k : Type*} [Field k] /-- The conjugate of a complex embedding as a complex embedding. -/ abbrev conjugate (φ : K →+* ℂ) : K →+* ℂ := star φ @[simp] theorem conjugate_coe_eq (φ : K →+* ℂ) (x : K) : (conjugate φ) x = conj (φ x) := rfl theorem place_conjugate (φ : K →+* ℂ) : place (conjugate φ) = place φ := by ext; simp only [place_apply, norm_eq_abs, abs_conj, conjugate_coe_eq] /-- An embedding into `ℂ` is real if it is fixed by complex conjugation. -/ abbrev IsReal (φ : K →+* ℂ) : Prop := IsSelfAdjoint φ theorem isReal_iff {φ : K →+* ℂ} : IsReal φ ↔ conjugate φ = φ := isSelfAdjoint_iff theorem isReal_conjugate_iff {φ : K →+* ℂ} : IsReal (conjugate φ) ↔ IsReal φ := IsSelfAdjoint.star_iff /-- A real embedding as a ring homomorphism from `K` to `ℝ` . -/ def IsReal.embedding {φ : K →+* ℂ} (hφ : IsReal φ) : K →+* ℝ where toFun x := (φ x).re map_one' := by simp only [map_one, one_re] map_mul' := by simp only [Complex.conj_eq_iff_im.mp (RingHom.congr_fun hφ _), map_mul, mul_re, mul_zero, tsub_zero, eq_self_iff_true, forall_const] map_zero' := by simp only [map_zero, zero_re] map_add' := by simp only [map_add, add_re, eq_self_iff_true, forall_const] @[simp] theorem IsReal.coe_embedding_apply {φ : K →+* ℂ} (hφ : IsReal φ) (x : K) : (hφ.embedding x : ℂ) = φ x := by apply Complex.ext · rfl · rw [ofReal_im, eq_comm, ← Complex.conj_eq_iff_im] exact RingHom.congr_fun hφ x lemma IsReal.comp (f : k →+* K) {φ : K →+* ℂ} (hφ : IsReal φ) : IsReal (φ.comp f) := by ext1 x; simpa using RingHom.congr_fun hφ (f x) lemma isReal_comp_iff {f : k ≃+* K} {φ : K →+* ℂ} : IsReal (φ.comp (f : k →+* K)) ↔ IsReal φ := ⟨fun H ↦ by convert H.comp f.symm.toRingHom; ext1; simp, IsReal.comp _⟩ lemma exists_comp_symm_eq_of_comp_eq [Algebra k K] [IsGalois k K] (φ ψ : K →+* ℂ) (h : φ.comp (algebraMap k K) = ψ.comp (algebraMap k K)) : ∃ σ : K ≃ₐ[k] K, φ.comp σ.symm = ψ := by letI := (φ.comp (algebraMap k K)).toAlgebra letI := φ.toAlgebra have : IsScalarTower k K ℂ := IsScalarTower.of_algebraMap_eq' rfl let ψ' : K →ₐ[k] ℂ := { ψ with commutes' := fun r ↦ (RingHom.congr_fun h r).symm } use (AlgHom.restrictNormal' ψ' K).symm ext1 x exact AlgHom.restrictNormal_commutes ψ' K x variable [Algebra k K] (φ : K →+* ℂ) (σ : K ≃ₐ[k] K) /-- `IsConj φ σ` states that `σ : K ≃ₐ[k] K` is the conjugation under the embedding `φ : K →+* ℂ`. -/ def IsConj : Prop := conjugate φ = φ.comp σ variable {φ σ} lemma IsConj.eq (h : IsConj φ σ) (x) : φ (σ x) = star (φ x) := RingHom.congr_fun h.symm x lemma IsConj.ext {σ₁ σ₂ : K ≃ₐ[k] K} (h₁ : IsConj φ σ₁) (h₂ : IsConj φ σ₂) : σ₁ = σ₂ := AlgEquiv.ext fun x ↦ φ.injective ((h₁.eq x).trans (h₂.eq x).symm) lemma IsConj.ext_iff {σ₁ σ₂ : K ≃ₐ[k] K} (h₁ : IsConj φ σ₁) : σ₁ = σ₂ ↔ IsConj φ σ₂ := ⟨fun e ↦ e ▸ h₁, h₁.ext⟩ lemma IsConj.isReal_comp (h : IsConj φ σ) : IsReal (φ.comp (algebraMap k K)) := by ext1 x simp only [conjugate_coe_eq, RingHom.coe_comp, Function.comp_apply, ← h.eq, starRingEnd_apply, AlgEquiv.commutes] lemma isConj_one_iff : IsConj φ (1 : K ≃ₐ[k] K) ↔ IsReal φ := Iff.rfl alias ⟨_, IsReal.isConjGal_one⟩ := ComplexEmbedding.isConj_one_iff lemma IsConj.symm (hσ : IsConj φ σ) : IsConj φ σ.symm := RingHom.ext fun x ↦ by simpa using congr_arg star (hσ.eq (σ.symm x)) lemma isConj_symm : IsConj φ σ.symm ↔ IsConj φ σ := ⟨IsConj.symm, IsConj.symm⟩ end NumberField.ComplexEmbedding section InfinitePlace open NumberField variable {k : Type*} [Field k] (K : Type*) [Field K] {F : Type*} [Field F] /-- An infinite place of a number field `K` is a place associated to a complex embedding. -/ def NumberField.InfinitePlace := { w : AbsoluteValue K ℝ // ∃ φ : K →+* ℂ, place φ = w } instance [NumberField K] : Nonempty (NumberField.InfinitePlace K) := Set.instNonemptyRange _ variable {K} /-- Return the infinite place defined by a complex embedding `φ`. -/ noncomputable def NumberField.InfinitePlace.mk (φ : K →+* ℂ) : NumberField.InfinitePlace K := ⟨place φ, ⟨φ, rfl⟩⟩ namespace NumberField.InfinitePlace open NumberField instance {K : Type*} [Field K] : FunLike (InfinitePlace K) K ℝ where coe w x := w.1 x coe_injective' := fun _ _ h => Subtype.eq (AbsoluteValue.ext fun x => congr_fun h x) instance : MonoidWithZeroHomClass (InfinitePlace K) K ℝ where map_mul w _ _ := w.1.map_mul _ _ map_one w := w.1.map_one map_zero w := w.1.map_zero instance : NonnegHomClass (InfinitePlace K) K ℝ where apply_nonneg w _ := w.1.nonneg _ @[simp] theorem apply (φ : K →+* ℂ) (x : K) : (mk φ) x = Complex.abs (φ x) := rfl /-- For an infinite place `w`, return an embedding `φ` such that `w = infinite_place φ` . -/ noncomputable def embedding (w : InfinitePlace K) : K →+* ℂ := w.2.choose @[simp] theorem mk_embedding (w : InfinitePlace K) : mk (embedding w) = w := Subtype.ext w.2.choose_spec @[simp] theorem mk_conjugate_eq (φ : K →+* ℂ) : mk (ComplexEmbedding.conjugate φ) = mk φ := by refine DFunLike.ext _ _ (fun x => ?_) rw [apply, apply, ComplexEmbedding.conjugate_coe_eq, Complex.abs_conj] theorem norm_embedding_eq (w : InfinitePlace K) (x : K) : ‖(embedding w) x‖ = w x := by nth_rewrite 2 [← mk_embedding w] rfl theorem eq_iff_eq (x : K) (r : ℝ) : (∀ w : InfinitePlace K, w x = r) ↔ ∀ φ : K →+* ℂ, ‖φ x‖ = r := ⟨fun hw φ => hw (mk φ), by rintro hφ ⟨w, ⟨φ, rfl⟩⟩; exact hφ φ⟩ theorem le_iff_le (x : K) (r : ℝ) : (∀ w : InfinitePlace K, w x ≤ r) ↔ ∀ φ : K →+* ℂ, ‖φ x‖ ≤ r := ⟨fun hw φ => hw (mk φ), by rintro hφ ⟨w, ⟨φ, rfl⟩⟩; exact hφ φ⟩ theorem pos_iff {w : InfinitePlace K} {x : K} : 0 < w x ↔ x ≠ 0 := AbsoluteValue.pos_iff w.1 @[simp] theorem mk_eq_iff {φ ψ : K →+* ℂ} : mk φ = mk ψ ↔ φ = ψ ∨ ComplexEmbedding.conjugate φ = ψ := by constructor · -- We prove that the map ψ ∘ φ⁻¹ between φ(K) and ℂ is uniform continuous, thus it is either the -- inclusion or the complex conjugation using `Complex.uniformContinuous_ringHom_eq_id_or_conj` intro h₀ obtain ⟨j, hiφ⟩ := (φ.injective).hasLeftInverse let ι := RingEquiv.ofLeftInverse hiφ have hlip : LipschitzWith 1 (RingHom.comp ψ ι.symm.toRingHom) := by change LipschitzWith 1 (ψ ∘ ι.symm) apply LipschitzWith.of_dist_le_mul intro x y rw [NNReal.coe_one, one_mul, NormedField.dist_eq, Function.comp_apply, Function.comp_apply, ← map_sub, ← map_sub] apply le_of_eq suffices ‖φ (ι.symm (x - y))‖ = ‖ψ (ι.symm (x - y))‖ by rw [← this, ← RingEquiv.ofLeftInverse_apply hiφ _, RingEquiv.apply_symm_apply ι _] rfl exact congrFun (congrArg (↑) h₀) _ cases Complex.uniformContinuous_ringHom_eq_id_or_conj φ.fieldRange hlip.uniformContinuous with | inl h => left; ext1 x conv_rhs => rw [← hiφ x] exact (congrFun h (ι x)).symm | inr h => right; ext1 x conv_rhs => rw [← hiφ x] exact (congrFun h (ι x)).symm · rintro (⟨h⟩ | ⟨h⟩) · exact congr_arg mk h · rw [← mk_conjugate_eq] exact congr_arg mk h /-- An infinite place is real if it is defined by a real embedding. -/ def IsReal (w : InfinitePlace K) : Prop := ∃ φ : K →+* ℂ, ComplexEmbedding.IsReal φ ∧ mk φ = w /-- An infinite place is complex if it is defined by a complex (ie. not real) embedding. -/ def IsComplex (w : InfinitePlace K) : Prop := ∃ φ : K →+* ℂ, ¬ComplexEmbedding.IsReal φ ∧ mk φ = w theorem embedding_mk_eq (φ : K →+* ℂ) : embedding (mk φ) = φ ∨ embedding (mk φ) = ComplexEmbedding.conjugate φ := by rw [@eq_comm _ _ φ, @eq_comm _ _ (ComplexEmbedding.conjugate φ), ← mk_eq_iff, mk_embedding] @[simp] theorem embedding_mk_eq_of_isReal {φ : K →+* ℂ} (h : ComplexEmbedding.IsReal φ) : embedding (mk φ) = φ := by have := embedding_mk_eq φ rwa [ComplexEmbedding.isReal_iff.mp h, or_self] at this theorem isReal_iff {w : InfinitePlace K} : IsReal w ↔ ComplexEmbedding.IsReal (embedding w) := by refine ⟨?_, fun h => ⟨embedding w, h, mk_embedding w⟩⟩ rintro ⟨φ, ⟨hφ, rfl⟩⟩ rwa [embedding_mk_eq_of_isReal hφ] theorem isComplex_iff {w : InfinitePlace K} : IsComplex w ↔ ¬ComplexEmbedding.IsReal (embedding w) := by refine ⟨?_, fun h => ⟨embedding w, h, mk_embedding w⟩⟩ rintro ⟨φ, ⟨hφ, rfl⟩⟩ contrapose! hφ cases mk_eq_iff.mp (mk_embedding (mk φ)) with | inl h => rwa [h] at hφ | inr h => rwa [← ComplexEmbedding.isReal_conjugate_iff, h] at hφ @[simp] theorem conjugate_embedding_eq_of_isReal {w : InfinitePlace K} (h : IsReal w) : ComplexEmbedding.conjugate (embedding w) = embedding w := ComplexEmbedding.isReal_iff.mpr (isReal_iff.mp h) @[simp] theorem not_isReal_iff_isComplex {w : InfinitePlace K} : ¬IsReal w ↔ IsComplex w := by rw [isComplex_iff, isReal_iff] @[simp] theorem not_isComplex_iff_isReal {w : InfinitePlace K} : ¬IsComplex w ↔ IsReal w := by rw [isComplex_iff, isReal_iff, not_not] theorem isReal_or_isComplex (w : InfinitePlace K) : IsReal w ∨ IsComplex w := by rw [← not_isReal_iff_isComplex]; exact em _ theorem ne_of_isReal_isComplex {w w' : InfinitePlace K} (h : IsReal w) (h' : IsComplex w') : w ≠ w' := fun h_eq ↦ not_isReal_iff_isComplex.mpr h' (h_eq ▸ h) variable (K) in theorem disjoint_isReal_isComplex : Disjoint {(w : InfinitePlace K) | IsReal w} {(w : InfinitePlace K) | IsComplex w} := Set.disjoint_iff.2 <| fun _ hw ↦ not_isReal_iff_isComplex.2 hw.2 hw.1 /-- The real embedding associated to a real infinite place. -/ noncomputable def embedding_of_isReal {w : InfinitePlace K} (hw : IsReal w) : K →+* ℝ := ComplexEmbedding.IsReal.embedding (isReal_iff.mp hw) @[simp] theorem embedding_of_isReal_apply {w : InfinitePlace K} (hw : IsReal w) (x : K) : ((embedding_of_isReal hw) x : ℂ) = (embedding w) x := ComplexEmbedding.IsReal.coe_embedding_apply (isReal_iff.mp hw) x theorem norm_embedding_of_isReal {w : InfinitePlace K} (hw : IsReal w) (x : K) : ‖embedding_of_isReal hw x‖ = w x := by rw [← norm_embedding_eq, ← embedding_of_isReal_apply hw, Complex.norm_real] @[simp] theorem isReal_of_mk_isReal {φ : K →+* ℂ} (h : IsReal (mk φ)) : ComplexEmbedding.IsReal φ := by contrapose! h rw [not_isReal_iff_isComplex] exact ⟨φ, h, rfl⟩ lemma isReal_mk_iff {φ : K →+* ℂ} : IsReal (mk φ) ↔ ComplexEmbedding.IsReal φ := ⟨isReal_of_mk_isReal, fun H ↦ ⟨_, H, rfl⟩⟩ lemma isComplex_mk_iff {φ : K →+* ℂ} : IsComplex (mk φ) ↔ ¬ ComplexEmbedding.IsReal φ := not_isReal_iff_isComplex.symm.trans isReal_mk_iff.not @[simp] theorem not_isReal_of_mk_isComplex {φ : K →+* ℂ} (h : IsComplex (mk φ)) : ¬ ComplexEmbedding.IsReal φ := by rwa [← isComplex_mk_iff] /-- The multiplicity of an infinite place, that is the number of distinct complex embeddings that define it, see `card_filter_mk_eq`. -/ noncomputable def mult (w : InfinitePlace K) : ℕ := if (IsReal w) then 1 else 2 theorem mult_pos {w : InfinitePlace K} : 0 < mult w := by rw [mult] split_ifs <;> norm_num @[simp] theorem mult_ne_zero {w : InfinitePlace K} : mult w ≠ 0 := ne_of_gt mult_pos theorem one_le_mult {w : InfinitePlace K} : (1 : ℝ) ≤ mult w := by rw [← Nat.cast_one, Nat.cast_le] exact mult_pos theorem card_filter_mk_eq [NumberField K] (w : InfinitePlace K) : (Finset.univ.filter fun φ => mk φ = w).card = mult w := by conv_lhs => congr; congr; ext rw [← mk_embedding w, mk_eq_iff, ComplexEmbedding.conjugate, star_involutive.eq_iff] simp_rw [Finset.filter_or, Finset.filter_eq' _ (embedding w), Finset.filter_eq' _ (ComplexEmbedding.conjugate (embedding w)), Finset.mem_univ, ite_true, mult] split_ifs with hw · rw [ComplexEmbedding.isReal_iff.mp (isReal_iff.mp hw), Finset.union_idempotent, Finset.card_singleton] · refine Finset.card_pair ?_ rwa [Ne, eq_comm, ← ComplexEmbedding.isReal_iff, ← isReal_iff] noncomputable instance NumberField.InfinitePlace.fintype [NumberField K] : Fintype (InfinitePlace K) := Set.fintypeRange _ theorem sum_mult_eq [NumberField K] : ∑ w : InfinitePlace K, mult w = FiniteDimensional.finrank ℚ K := by rw [← Embeddings.card K ℂ, Fintype.card, Finset.card_eq_sum_ones, ← Finset.univ.sum_fiberwise (fun φ => InfinitePlace.mk φ)] exact Finset.sum_congr rfl (fun _ _ => by rw [Finset.sum_const, smul_eq_mul, mul_one, card_filter_mk_eq]) /-- The map from real embeddings to real infinite places as an equiv -/ noncomputable def mkReal : { φ : K →+* ℂ // ComplexEmbedding.IsReal φ } ≃ { w : InfinitePlace K // IsReal w } := by refine (Equiv.ofBijective (fun φ => ⟨mk φ, ?_⟩) ⟨fun φ ψ h => ?_, fun w => ?_⟩) · exact ⟨φ, φ.prop, rfl⟩ · rwa [Subtype.mk.injEq, mk_eq_iff, ComplexEmbedding.isReal_iff.mp φ.prop, or_self, ← Subtype.ext_iff] at h · exact ⟨⟨embedding w, isReal_iff.mp w.prop⟩, by simp⟩ /-- The map from nonreal embeddings to complex infinite places -/ noncomputable def mkComplex : { φ : K →+* ℂ // ¬ComplexEmbedding.IsReal φ } → { w : InfinitePlace K // IsComplex w } := Subtype.map mk fun φ hφ => ⟨φ, hφ, rfl⟩ @[simp] theorem mkReal_coe (φ : { φ : K →+* ℂ // ComplexEmbedding.IsReal φ }) : (mkReal φ : InfinitePlace K) = mk (φ : K →+* ℂ) := rfl @[simp] theorem mkComplex_coe (φ : { φ : K →+* ℂ // ¬ComplexEmbedding.IsReal φ }) : (mkComplex φ : InfinitePlace K) = mk (φ : K →+* ℂ) := rfl section NumberField variable [NumberField K] /-- The infinite part of the product formula : for `x ∈ K`, we have `Π_w ‖x‖_w = |norm(x)|` where `‖·‖_w` is the normalized absolute value for `w`. -/ theorem prod_eq_abs_norm (x : K) : ∏ w : InfinitePlace K, w x ^ mult w = abs (Algebra.norm ℚ x) := by convert (congr_arg Complex.abs (@Algebra.norm_eq_prod_embeddings ℚ _ _ _ _ ℂ _ _ _ _ _ x)).symm · rw [map_prod, ← Fintype.prod_equiv RingHom.equivRatAlgHom (fun f => Complex.abs (f x)) (fun φ => Complex.abs (φ x)) fun _ => by simp [RingHom.equivRatAlgHom_apply]; rfl] rw [← Finset.prod_fiberwise Finset.univ (fun φ => mk φ) (fun φ => Complex.abs (φ x))] have : ∀ w : InfinitePlace K, ∀ φ ∈ Finset.filter (fun a ↦ mk a = w) Finset.univ, Complex.abs (φ x) = w x := by intro _ _ hφ rw [← (Finset.mem_filter.mp hφ).2] rfl simp_rw [Finset.prod_congr rfl (this _), Finset.prod_const, card_filter_mk_eq] · rw [eq_ratCast, Rat.cast_abs, ← Complex.abs_ofReal, Complex.ofReal_ratCast] theorem one_le_of_lt_one {w : InfinitePlace K} {a : (𝓞 K)} (ha : a ≠ 0) (h : ∀ ⦃z⦄, z ≠ w → z a < 1) : 1 ≤ w a := by suffices (1 : ℝ) ≤ |Algebra.norm ℚ (a : K)| by contrapose! this rw [← InfinitePlace.prod_eq_abs_norm, ← Finset.prod_const_one] refine Finset.prod_lt_prod_of_nonempty (fun _ _ ↦ ?_) (fun z _ ↦ ?_) Finset.univ_nonempty · exact pow_pos (pos_iff.mpr ((Subalgebra.coe_eq_zero _).not.mpr ha)) _ · refine pow_lt_one (apply_nonneg _ _) ?_ (by rw [mult]; split_ifs <;> norm_num) by_cases hz : z = w · rwa [hz] · exact h hz rw [← Algebra.coe_norm_int, ← Int.cast_one, ← Int.cast_abs, Rat.cast_intCast, Int.cast_le] exact Int.one_le_abs (Algebra.norm_ne_zero_iff.mpr ha) open scoped IntermediateField in theorem _root_.NumberField.is_primitive_element_of_infinitePlace_lt {x : 𝓞 K} {w : InfinitePlace K} (h₁ : x ≠ 0) (h₂ : ∀ ⦃w'⦄, w' ≠ w → w' x < 1) (h₃ : IsReal w ∨ |(w.embedding x).re| < 1) : ℚ⟮(x : K)⟯ = ⊤ := by rw [Field.primitive_element_iff_algHom_eq_of_eval ℚ ℂ ?_ _ w.embedding.toRatAlgHom] · intro ψ hψ have h : 1 ≤ w x := one_le_of_lt_one h₁ h₂ have main : w = InfinitePlace.mk ψ.toRingHom := by erw [← norm_embedding_eq, hψ] at h contrapose! h exact h₂ h.symm rw [(mk_embedding w).symm, mk_eq_iff] at main cases h₃ with | inl hw => rw [conjugate_embedding_eq_of_isReal hw, or_self] at main exact congr_arg RingHom.toRatAlgHom main | inr hw => refine congr_arg RingHom.toRatAlgHom (main.resolve_right fun h' ↦ hw.not_le ?_) have : (embedding w x).im = 0 := by erw [← Complex.conj_eq_iff_im, RingHom.congr_fun h' x] exact hψ.symm rwa [← norm_embedding_eq, ← Complex.re_add_im (embedding w x), this, Complex.ofReal_zero, zero_mul, add_zero, Complex.norm_eq_abs, Complex.abs_ofReal] at h · exact fun x ↦ IsAlgClosed.splits_codomain (minpoly ℚ x) theorem _root_.NumberField.adjoin_eq_top_of_infinitePlace_lt {x : 𝓞 K} {w : InfinitePlace K} (h₁ : x ≠ 0) (h₂ : ∀ ⦃w'⦄, w' ≠ w → w' x < 1) (h₃ : IsReal w ∨ |(w.embedding x).re| < 1) : Algebra.adjoin ℚ {(x : K)} = ⊤ := by rw [← IntermediateField.adjoin_simple_toSubalgebra_of_integral (IsIntegral.of_finite ℚ _)] exact congr_arg IntermediateField.toSubalgebra <| NumberField.is_primitive_element_of_infinitePlace_lt h₁ h₂ h₃ end NumberField open Fintype FiniteDimensional variable (K) section NumberField variable [NumberField K] /-- The number of infinite real places of the number field `K`. -/ noncomputable abbrev NrRealPlaces := card { w : InfinitePlace K // IsReal w } /-- The number of infinite complex places of the number field `K`. -/ noncomputable abbrev NrComplexPlaces := card { w : InfinitePlace K // IsComplex w } theorem card_real_embeddings : card { φ : K →+* ℂ // ComplexEmbedding.IsReal φ } = NrRealPlaces K := Fintype.card_congr mkReal theorem card_eq_nrRealPlaces_add_nrComplexPlaces : Fintype.card (InfinitePlace K) = NrRealPlaces K + NrComplexPlaces K := by convert Fintype.card_subtype_or_disjoint (IsReal (K := K)) (IsComplex (K := K)) (disjoint_isReal_isComplex K) using 1 exact (Fintype.card_of_subtype _ (fun w ↦ ⟨fun _ ↦ isReal_or_isComplex w, fun _ ↦ by simp⟩)).symm theorem card_complex_embeddings : card { φ : K →+* ℂ // ¬ComplexEmbedding.IsReal φ } = 2 * NrComplexPlaces K := by suffices ∀ w : { w : InfinitePlace K // IsComplex w }, (Finset.univ.filter fun φ : { φ // ¬ ComplexEmbedding.IsReal φ } => mkComplex φ = w).card = 2 by rw [Fintype.card, Finset.card_eq_sum_ones, ← Finset.sum_fiberwise _ (fun φ => mkComplex φ)] simp_rw [Finset.sum_const, this, smul_eq_mul, mul_one, Fintype.card, Finset.card_eq_sum_ones, Finset.mul_sum, Finset.sum_const, smul_eq_mul, mul_one] rintro ⟨w, hw⟩ convert card_filter_mk_eq w · rw [← Fintype.card_subtype, ← Fintype.card_subtype] refine Fintype.card_congr (Equiv.ofBijective ?_ ⟨fun _ _ h => ?_, fun ⟨φ, hφ⟩ => ?_⟩) · exact fun ⟨φ, hφ⟩ => ⟨φ.val, by rwa [Subtype.ext_iff] at hφ⟩ · rwa [Subtype.mk_eq_mk, ← Subtype.ext_iff, ← Subtype.ext_iff] at h · refine ⟨⟨⟨φ, not_isReal_of_mk_isComplex (hφ.symm ▸ hw)⟩, ?_⟩, rfl⟩ rwa [Subtype.ext_iff, mkComplex_coe] · simp_rw [mult, not_isReal_iff_isComplex.mpr hw, ite_false] theorem card_add_two_mul_card_eq_rank : NrRealPlaces K + 2 * NrComplexPlaces K = finrank ℚ K := by rw [← card_real_embeddings, ← card_complex_embeddings, Fintype.card_subtype_compl, ← Embeddings.card K ℂ, Nat.add_sub_of_le] exact Fintype.card_subtype_le _ variable {K} theorem nrComplexPlaces_eq_zero_of_finrank_eq_one (h : finrank ℚ K = 1) : NrComplexPlaces K = 0 := by linarith [card_add_two_mul_card_eq_rank K] theorem nrRealPlaces_eq_one_of_finrank_eq_one (h : finrank ℚ K = 1) : NrRealPlaces K = 1 := by have := card_add_two_mul_card_eq_rank K rwa [nrComplexPlaces_eq_zero_of_finrank_eq_one h, h, mul_zero, add_zero] at this /-- The restriction of an infinite place along an embedding. -/ def comap (w : InfinitePlace K) (f : k →+* K) : InfinitePlace k := ⟨w.1.comp f.injective, w.embedding.comp f, by { ext x; show _ = w.1 (f x); rw [← w.2.choose_spec]; rfl }⟩ end NumberField variable {K} @[simp] lemma comap_mk (φ : K →+* ℂ) (f : k →+* K) : (mk φ).comap f = mk (φ.comp f) := rfl lemma comap_id (w : InfinitePlace K) : w.comap (RingHom.id K) = w := rfl lemma comap_comp (w : InfinitePlace K) (f : F →+* K) (g : k →+* F) : w.comap (f.comp g) = (w.comap f).comap g := rfl lemma IsReal.comap (f : k →+* K) {w : InfinitePlace K} (hφ : IsReal w) : IsReal (w.comap f) := by rw [← mk_embedding w, comap_mk, isReal_mk_iff] rw [← mk_embedding w, isReal_mk_iff] at hφ exact hφ.comp f lemma isReal_comap_iff (f : k ≃+* K) {w : InfinitePlace K} : IsReal (w.comap (f : k →+* K)) ↔ IsReal w := by rw [← mk_embedding w, comap_mk, isReal_mk_iff, isReal_mk_iff, ComplexEmbedding.isReal_comp_iff] lemma comap_surjective [Algebra k K] [Algebra.IsAlgebraic k K] : Function.Surjective (comap · (algebraMap k K)) := fun w ↦ letI := w.embedding.toAlgebra ⟨mk (IsAlgClosed.lift (M := ℂ) (R := k)).toRingHom, by simp [comap_mk, RingHom.algebraMap_toAlgebra]⟩ lemma mult_comap_le (f : k →+* K) (w : InfinitePlace K) : mult (w.comap f) ≤ mult w := by rw [mult, mult] split_ifs with h₁ h₂ h₂ pick_goal 3 · exact (h₁ (h₂.comap _)).elim all_goals decide variable [Algebra k K] (σ : K ≃ₐ[k] K) (w : InfinitePlace K) variable (k K) lemma card_mono [NumberField k] [NumberField K] : card (InfinitePlace k) ≤ card (InfinitePlace K) := have := Module.Finite.of_restrictScalars_finite ℚ k K Fintype.card_le_of_surjective _ comap_surjective variable {k K} /-- The action of the galois group on infinite places. -/ @[simps! smul_coe_apply] instance : MulAction (K ≃ₐ[k] K) (InfinitePlace K) where smul := fun σ w ↦ w.comap σ.symm one_smul := fun _ ↦ rfl mul_smul := fun _ _ _ ↦ rfl lemma smul_eq_comap : σ • w = w.comap σ.symm := rfl @[simp] lemma smul_apply (x) : (σ • w) x = w (σ.symm x) := rfl @[simp] lemma smul_mk (φ : K →+* ℂ) : σ • mk φ = mk (φ.comp σ.symm) := rfl lemma comap_smul {f : F →+* K} : (σ • w).comap f = w.comap (RingHom.comp σ.symm f) := rfl variable {σ w} lemma isReal_smul_iff : IsReal (σ • w) ↔ IsReal w := isReal_comap_iff (f := σ.symm.toRingEquiv) lemma isComplex_smul_iff : IsComplex (σ • w) ↔ IsComplex w := by rw [← not_isReal_iff_isComplex, ← not_isReal_iff_isComplex, isReal_smul_iff] lemma ComplexEmbedding.exists_comp_symm_eq_of_comp_eq [IsGalois k K] (φ ψ : K →+* ℂ) (h : φ.comp (algebraMap k K) = ψ.comp (algebraMap k K)) : ∃ σ : K ≃ₐ[k] K, φ.comp σ.symm = ψ := by letI := (φ.comp (algebraMap k K)).toAlgebra letI := φ.toAlgebra have : IsScalarTower k K ℂ := IsScalarTower.of_algebraMap_eq' rfl let ψ' : K →ₐ[k] ℂ := { ψ with commutes' := fun r ↦ (RingHom.congr_fun h r).symm } use (AlgHom.restrictNormal' ψ' K).symm ext1 x exact AlgHom.restrictNormal_commutes ψ' K x lemma exists_smul_eq_of_comap_eq [IsGalois k K] {w w' : InfinitePlace K} (h : w.comap (algebraMap k K) = w'.comap (algebraMap k K)) : ∃ σ : K ≃ₐ[k] K, σ • w = w' := by rw [← mk_embedding w, ← mk_embedding w', comap_mk, comap_mk, mk_eq_iff] at h cases h with | inl h => obtain ⟨σ, hσ⟩ := ComplexEmbedding.exists_comp_symm_eq_of_comp_eq w.embedding w'.embedding h use σ rw [← mk_embedding w, ← mk_embedding w', smul_mk, hσ] | inr h => obtain ⟨σ, hσ⟩ := ComplexEmbedding.exists_comp_symm_eq_of_comp_eq ((starRingEnd ℂ).comp (embedding w)) w'.embedding h use σ rw [← mk_embedding w, ← mk_embedding w', smul_mk, mk_eq_iff] exact Or.inr hσ lemma mem_orbit_iff [IsGalois k K] {w w' : InfinitePlace K} : w' ∈ MulAction.orbit (K ≃ₐ[k] K) w ↔ w.comap (algebraMap k K) = w'.comap (algebraMap k K) := by refine ⟨?_, exists_smul_eq_of_comap_eq⟩ rintro ⟨σ, rfl : σ • w = w'⟩ rw [← mk_embedding w, comap_mk, smul_mk, comap_mk] congr 1; ext1; simp /-- The orbits of infinite places under the action of the galois group are indexed by the infinite places of the base field. -/ noncomputable def orbitRelEquiv [IsGalois k K] : Quotient (MulAction.orbitRel (K ≃ₐ[k] K) (InfinitePlace K)) ≃ InfinitePlace k := by refine Equiv.ofBijective (Quotient.lift (comap · (algebraMap k K)) fun _ _ e ↦ (mem_orbit_iff.mp e).symm) ⟨?_, ?_⟩ · rintro ⟨w⟩ ⟨w'⟩ e exact Quotient.sound (mem_orbit_iff.mpr e.symm) · intro w obtain ⟨w', hw⟩ := comap_surjective (K := K) w exact ⟨⟦w'⟧, hw⟩ lemma orbitRelEquiv_apply_mk'' [IsGalois k K] (w : InfinitePlace K) : orbitRelEquiv (Quotient.mk'' w) = comap w (algebraMap k K) := rfl variable (k w) /-- An infinite place is unramified in a field extension if the restriction has the same multiplicity. -/ def IsUnramified : Prop := mult (w.comap (algebraMap k K)) = mult w variable {k} lemma isUnramified_self : IsUnramified K w := rfl variable {w} lemma IsUnramified.eq (h : IsUnramified k w) : mult (w.comap (algebraMap k K)) = mult w := h lemma isUnramified_iff_mult_le : IsUnramified k w ↔ mult w ≤ mult (w.comap (algebraMap k K)) := by rw [IsUnramified, le_antisymm_iff, and_iff_right] exact mult_comap_le _ _ variable [Algebra k F] lemma IsUnramified.comap_algHom {w : InfinitePlace F} (h : IsUnramified k w) (f : K →ₐ[k] F) : IsUnramified k (w.comap (f : K →+* F)) := by rw [InfinitePlace.isUnramified_iff_mult_le, ← InfinitePlace.comap_comp, f.comp_algebraMap, h.eq] exact InfinitePlace.mult_comap_le _ _ variable (K) variable [Algebra K F] [IsScalarTower k K F] lemma IsUnramified.of_restrictScalars {w : InfinitePlace F} (h : IsUnramified k w) : IsUnramified K w := by rw [InfinitePlace.isUnramified_iff_mult_le, ← h.eq, IsScalarTower.algebraMap_eq k K F, InfinitePlace.comap_comp] exact InfinitePlace.mult_comap_le _ _ lemma IsUnramified.comap {w : InfinitePlace F} (h : IsUnramified k w) : IsUnramified k (w.comap (algebraMap K F)) := h.comap_algHom (IsScalarTower.toAlgHom k K F) variable {K} lemma not_isUnramified_iff : ¬ IsUnramified k w ↔ IsComplex w ∧ IsReal (w.comap (algebraMap k K)) := by rw [IsUnramified, mult, mult, ← not_isReal_iff_isComplex] split_ifs with h₁ h₂ h₂ <;> simp only [not_true_eq_false, false_iff, and_self, forall_true_left, IsEmpty.forall_iff, not_and, OfNat.one_ne_ofNat, not_false_eq_true, true_iff, OfNat.ofNat_ne_one, h₁, h₂] exact h₁ (h₂.comap _) lemma isUnramified_iff : IsUnramified k w ↔ IsReal w ∨ IsComplex (w.comap (algebraMap k K)) := by rw [← not_iff_not, not_isUnramified_iff, not_or, not_isReal_iff_isComplex, not_isComplex_iff_isReal] variable (k) lemma IsReal.isUnramified (h : IsReal w) : IsUnramified k w := isUnramified_iff.mpr (Or.inl h) variable {k} lemma _root_.NumberField.ComplexEmbedding.IsConj.isUnramified_mk_iff {φ : K →+* ℂ} (h : ComplexEmbedding.IsConj φ σ) : IsUnramified k (mk φ) ↔ σ = 1 := by rw [h.ext_iff, ComplexEmbedding.isConj_one_iff, ← not_iff_not, not_isUnramified_iff, ← not_isReal_iff_isComplex, comap_mk, isReal_mk_iff, isReal_mk_iff, eq_true h.isReal_comp, and_true] lemma isUnramified_mk_iff_forall_isConj [IsGalois k K] {φ : K →+* ℂ} : IsUnramified k (mk φ) ↔ ∀ σ : K ≃ₐ[k] K, ComplexEmbedding.IsConj φ σ → σ = 1 := by refine ⟨fun H σ hσ ↦ hσ.isUnramified_mk_iff.mp H, fun H ↦ ?_⟩ by_contra hφ rw [not_isUnramified_iff] at hφ rw [comap_mk, isReal_mk_iff, ← not_isReal_iff_isComplex, isReal_mk_iff, ← ComplexEmbedding.isConj_one_iff (k := k)] at hφ letI := (φ.comp (algebraMap k K)).toAlgebra letI := φ.toAlgebra have : IsScalarTower k K ℂ := IsScalarTower.of_algebraMap_eq' rfl let φ' : K →ₐ[k] ℂ := { star φ with commutes' := fun r ↦ by simpa using RingHom.congr_fun hφ.2 r } have : ComplexEmbedding.IsConj φ (AlgHom.restrictNormal' φ' K) := (RingHom.ext <| AlgHom.restrictNormal_commutes φ' K).symm exact hφ.1 (H _ this ▸ this) local notation "Stab" => MulAction.stabilizer (K ≃ₐ[k] K) lemma mem_stabilizer_mk_iff (φ : K →+* ℂ) (σ : K ≃ₐ[k] K) : σ ∈ Stab (mk φ) ↔ σ = 1 ∨ ComplexEmbedding.IsConj φ σ := by simp only [MulAction.mem_stabilizer_iff, smul_mk, mk_eq_iff] rw [← ComplexEmbedding.isConj_symm, ComplexEmbedding.conjugate, star_eq_iff_star_eq] refine or_congr ⟨fun H ↦ ?_, fun H ↦ H ▸ rfl⟩ Iff.rfl exact congr_arg AlgEquiv.symm (AlgEquiv.ext (g := AlgEquiv.refl) fun x ↦ φ.injective (RingHom.congr_fun H x)) lemma IsUnramified.stabilizer_eq_bot (h : IsUnramified k w) : Stab w = ⊥ := by rw [eq_bot_iff, ← mk_embedding w, SetLike.le_def] simp only [mem_stabilizer_mk_iff, Subgroup.mem_bot, forall_eq_or_imp, true_and] exact fun σ hσ ↦ hσ.isUnramified_mk_iff.mp ((mk_embedding w).symm ▸ h) lemma _root_.NumberField.ComplexEmbedding.IsConj.coe_stabilzer_mk {φ : K →+* ℂ} (h : ComplexEmbedding.IsConj φ σ) : (Stab (mk φ) : Set (K ≃ₐ[k] K)) = {1, σ} := by ext rw [SetLike.mem_coe, mem_stabilizer_mk_iff, Set.mem_insert_iff, Set.mem_singleton_iff, ← h.ext_iff, eq_comm (a := σ)] variable (k w) lemma nat_card_stabilizer_eq_one_or_two : Nat.card (Stab w) = 1 ∨ Nat.card (Stab w) = 2 := by rw [← SetLike.coe_sort_coe, ← mk_embedding w] by_cases h : ∃ σ, ComplexEmbedding.IsConj (k := k) (embedding w) σ · obtain ⟨σ, hσ⟩ := h simp only [hσ.coe_stabilzer_mk, Nat.card_eq_fintype_card, card_ofFinset, Set.toFinset_singleton] by_cases 1 = σ · left; simp [*] · right; simp [*] · push_neg at h left trans Nat.card ({1} : Set (K ≃ₐ[k] K)) · congr with x simp only [SetLike.mem_coe, mem_stabilizer_mk_iff, Set.mem_singleton_iff, or_iff_left_iff_imp, h x, IsEmpty.forall_iff] · simp variable {k w} lemma isUnramified_iff_stabilizer_eq_bot [IsGalois k K] : IsUnramified k w ↔ Stab w = ⊥ := by rw [← mk_embedding w, isUnramified_mk_iff_forall_isConj] simp only [eq_bot_iff, SetLike.le_def, mem_stabilizer_mk_iff, Subgroup.mem_bot, forall_eq_or_imp, true_and] lemma isUnramified_iff_card_stabilizer_eq_one [IsGalois k K] : IsUnramified k w ↔ Nat.card (Stab w) = 1 := by rw [isUnramified_iff_stabilizer_eq_bot, Subgroup.card_eq_one] lemma not_isUnramified_iff_card_stabilizer_eq_two [IsGalois k K] : ¬ IsUnramified k w ↔ Nat.card (Stab w) = 2 := by rw [isUnramified_iff_card_stabilizer_eq_one] obtain (e|e) := nat_card_stabilizer_eq_one_or_two k w <;> rw [e] <;> decide lemma card_stabilizer [IsGalois k K] : Nat.card (Stab w) = if IsUnramified k w then 1 else 2 := by split · rwa [← isUnramified_iff_card_stabilizer_eq_one] · rwa [← not_isUnramified_iff_card_stabilizer_eq_two] lemma even_nat_card_aut_of_not_isUnramified [IsGalois k K] (hw : ¬ IsUnramified k w) : Even (Nat.card <| K ≃ₐ[k] K) := by by_cases H : Finite (K ≃ₐ[k] K) · cases nonempty_fintype (K ≃ₐ[k] K) rw [even_iff_two_dvd, ← not_isUnramified_iff_card_stabilizer_eq_two.mp hw] exact Subgroup.card_subgroup_dvd_card (Stab w) · convert even_zero by_contra e exact H (Nat.finite_of_card_ne_zero e) lemma even_card_aut_of_not_isUnramified [IsGalois k K] [FiniteDimensional k K] (hw : ¬ IsUnramified k w) : Even (Fintype.card <| K ≃ₐ[k] K) := Nat.card_eq_fintype_card (α := K ≃ₐ[k] K) ▸ even_nat_card_aut_of_not_isUnramified hw lemma even_finrank_of_not_isUnramified [IsGalois k K] (hw : ¬ IsUnramified k w) : Even (finrank k K) := by by_cases FiniteDimensional k K · exact IsGalois.card_aut_eq_finrank k K ▸ even_card_aut_of_not_isUnramified hw · exact finrank_of_not_finite ‹_› ▸ even_zero lemma isUnramified_smul_iff : IsUnramified k (σ • w) ↔ IsUnramified k w := by rw [isUnramified_iff, isUnramified_iff, isReal_smul_iff, comap_smul, ← AlgEquiv.toAlgHom_toRingHom, AlgHom.comp_algebraMap] variable (K) /-- A infinite place of the base field is unramified in a field extension if every infinite place over it is unramified. -/ def IsUnramifiedIn (w : InfinitePlace k) : Prop := ∀ v, comap v (algebraMap k K) = w → IsUnramified k v variable {K} lemma isUnramifiedIn_comap [IsGalois k K] {w : InfinitePlace K} : (w.comap (algebraMap k K)).IsUnramifiedIn K ↔ w.IsUnramified k := by refine ⟨fun H ↦ H _ rfl, fun H v hv ↦ ?_⟩ obtain ⟨σ, rfl⟩ := exists_smul_eq_of_comap_eq hv rwa [isUnramified_smul_iff] at H lemma even_card_aut_of_not_isUnramifiedIn [IsGalois k K] [FiniteDimensional k K] {w : InfinitePlace k} (hw : ¬ w.IsUnramifiedIn K) : Even (Fintype.card <| K ≃ₐ[k] K) := by obtain ⟨v, rfl⟩ := comap_surjective (K := K) w rw [isUnramifiedIn_comap] at hw exact even_card_aut_of_not_isUnramified hw lemma even_finrank_of_not_isUnramifiedIn [IsGalois k K] {w : InfinitePlace k} (hw : ¬ w.IsUnramifiedIn K) : Even (finrank k K) := by obtain ⟨v, rfl⟩ := comap_surjective (K := K) w rw [isUnramifiedIn_comap] at hw exact even_finrank_of_not_isUnramified hw variable (k K) variable [NumberField K] open Finset in lemma card_isUnramified [NumberField k] [IsGalois k K] : Finset.card (univ.filter <| IsUnramified k (K := K)) = Finset.card (univ.filter <| IsUnramifiedIn K (k := k)) * (finrank k K) := by letI := Module.Finite.of_restrictScalars_finite ℚ k K rw [← IsGalois.card_aut_eq_finrank, Finset.card_eq_sum_card_fiberwise (f := (comap · (algebraMap k K))) (t := (univ.filter <| IsUnramifiedIn K (k := k))), ← smul_eq_mul, ← sum_const] · refine sum_congr rfl (fun w hw ↦ ?_) obtain ⟨w, rfl⟩ := comap_surjective (K := K) w simp only [mem_univ, forall_true_left, mem_filter, true_and] at hw trans Finset.card (MulAction.orbit (K ≃ₐ[k] K) w).toFinset · congr; ext w' simp only [mem_univ, forall_true_left, filter_congr_decidable, mem_filter, true_and, Set.mem_toFinset, mem_orbit_iff, @eq_comm _ (comap w' _), and_iff_right_iff_imp] intro e; rwa [← isUnramifiedIn_comap, ← e] · rw [← MulAction.card_orbit_mul_card_stabilizer_eq_card_group _ w, ← Nat.card_eq_fintype_card (α := Stab w), card_stabilizer, if_pos, mul_one, Set.toFinset_card] rwa [← isUnramifiedIn_comap] · simp [isUnramifiedIn_comap] open Finset in lemma card_isUnramified_compl [NumberField k] [IsGalois k K] : Finset.card (univ.filter <| IsUnramified k (K := K))ᶜ = Finset.card (univ.filter <| IsUnramifiedIn K (k := k))ᶜ * (finrank k K / 2) := by letI := Module.Finite.of_restrictScalars_finite ℚ k K rw [← IsGalois.card_aut_eq_finrank, Finset.card_eq_sum_card_fiberwise (f := (comap · (algebraMap k K))) (t := (univ.filter <| IsUnramifiedIn K (k := k))ᶜ), ← smul_eq_mul, ← sum_const] · refine sum_congr rfl (fun w hw ↦ ?_) obtain ⟨w, rfl⟩ := comap_surjective (K := K) w simp only [mem_univ, forall_true_left, compl_filter, not_not, mem_filter, true_and] at hw trans Finset.card (MulAction.orbit (K ≃ₐ[k] K) w).toFinset · congr; ext w' simp only [compl_filter, filter_congr_decidable, mem_filter, mem_univ, true_and, @eq_comm _ (comap w' _), Set.mem_toFinset, mem_orbit_iff, and_iff_right_iff_imp] intro e; rwa [← isUnramifiedIn_comap, ← e] · rw [← MulAction.card_orbit_mul_card_stabilizer_eq_card_group _ w, ← Nat.card_eq_fintype_card (α := Stab w), InfinitePlace.card_stabilizer, if_neg, Nat.mul_div_cancel _ zero_lt_two, Set.toFinset_card] rwa [← isUnramifiedIn_comap] · simp [isUnramifiedIn_comap] lemma card_eq_card_isUnramifiedIn [NumberField k] [IsGalois k K] : Fintype.card (InfinitePlace K) = Finset.card (Finset.univ.filter <| IsUnramifiedIn K (k := k)) * finrank k K + Finset.card (Finset.univ.filter <| IsUnramifiedIn K (k := k))ᶜ * (finrank k K / 2) := by rw [← card_isUnramified, ← card_isUnramified_compl, Finset.card_add_card_compl] end NumberField.InfinitePlace variable (k K F) variable [Algebra k K] [Algebra k F] [Algebra K F] [IsScalarTower k K F] /-- A field extension is unramified at infinite places if every infinite place is unramified. -/ class IsUnramifiedAtInfinitePlaces : Prop where isUnramified : ∀ w : InfinitePlace K, w.IsUnramified k instance IsUnramifiedAtInfinitePlaces.id : IsUnramifiedAtInfinitePlaces K K where isUnramified w := w.isUnramified_self lemma IsUnramifiedAtInfinitePlaces.trans [h₁ : IsUnramifiedAtInfinitePlaces k K] [h₂ : IsUnramifiedAtInfinitePlaces K F] : IsUnramifiedAtInfinitePlaces k F where isUnramified w := Eq.trans (IsScalarTower.algebraMap_eq k K F ▸ h₁.1 (w.comap (algebraMap _ _))) (h₂.1 w) lemma IsUnramifiedAtInfinitePlaces.top [h : IsUnramifiedAtInfinitePlaces k F] : IsUnramifiedAtInfinitePlaces K F where isUnramified w := (h.1 w).of_restrictScalars K lemma IsUnramifiedAtInfinitePlaces.bot [h₁ : IsUnramifiedAtInfinitePlaces k F] [Algebra.IsAlgebraic K F] : IsUnramifiedAtInfinitePlaces k K where isUnramified w := by obtain ⟨w, rfl⟩ := InfinitePlace.comap_surjective (K := F) w exact (h₁.1 w).comap K variable {K} lemma NumberField.InfinitePlace.isUnramified [IsUnramifiedAtInfinitePlaces k K] (w : InfinitePlace K) : IsUnramified k w := IsUnramifiedAtInfinitePlaces.isUnramified w variable {k} (K) lemma NumberField.InfinitePlace.isUnramifiedIn [IsUnramifiedAtInfinitePlaces k K] (w : InfinitePlace k) : IsUnramifiedIn K w := fun v _ ↦ v.isUnramified k variable {K} lemma IsUnramifiedAtInfinitePlaces_of_odd_card_aut [IsGalois k K] [FiniteDimensional k K] (h : Odd (Fintype.card <| K ≃ₐ[k] K)) : IsUnramifiedAtInfinitePlaces k K := ⟨fun _ ↦ not_not.mp (Nat.odd_iff_not_even.mp h ∘ InfinitePlace.even_card_aut_of_not_isUnramified)⟩ lemma IsUnramifiedAtInfinitePlaces_of_odd_finrank [IsGalois k K] (h : Odd (FiniteDimensional.finrank k K)) : IsUnramifiedAtInfinitePlaces k K := ⟨fun _ ↦ not_not.mp (Nat.odd_iff_not_even.mp h ∘ InfinitePlace.even_finrank_of_not_isUnramified)⟩ variable (k K) open FiniteDimensional in lemma IsUnramifiedAtInfinitePlaces.card_infinitePlace [NumberField k] [NumberField K] [IsGalois k K] [IsUnramifiedAtInfinitePlaces k K] : Fintype.card (InfinitePlace K) = Fintype.card (InfinitePlace k) * finrank k K := by rw [InfinitePlace.card_eq_card_isUnramifiedIn (k := k) (K := K), Finset.filter_true_of_mem, Finset.card_univ, Finset.card_eq_zero.mpr, zero_mul, add_zero] · exact Finset.compl_univ simp only [Finset.mem_univ, forall_true_left, Finset.filter_eq_empty_iff] exact InfinitePlace.isUnramifiedIn K end InfinitePlace namespace IsPrimitiveRoot variable {K : Type*} [Field K] [NumberField K] {ζ : K} {k : ℕ} theorem nrRealPlaces_eq_zero_of_two_lt (hk : 2 < k) (hζ : IsPrimitiveRoot ζ k) : NumberField.InfinitePlace.NrRealPlaces K = 0 := by refine (@Fintype.card_eq_zero_iff _ (_)).2 ⟨fun ⟨w, hwreal⟩ ↦ ?_⟩ rw [NumberField.InfinitePlace.isReal_iff] at hwreal let f := w.embedding have hζ' : IsPrimitiveRoot (f ζ) k := hζ.map_of_injective f.injective have him : (f ζ).im = 0 := by rw [← Complex.conj_eq_iff_im, ← NumberField.ComplexEmbedding.conjugate_coe_eq] congr have hre : (f ζ).re = 1 ∨ (f ζ).re = -1 := by rw [← Complex.abs_re_eq_abs] at him have := Complex.norm_eq_one_of_pow_eq_one hζ'.pow_eq_one (by linarith) rwa [Complex.norm_eq_abs, ← him, ← abs_one, abs_eq_abs] at this cases hre with | inl hone => exact hζ'.ne_one (by linarith) <| Complex.ext (by simp [hone]) (by simp [him]) | inr hnegone => replace hζ' := hζ'.eq_orderOf simp only [show f ζ = -1 from Complex.ext (by simp [hnegone]) (by simp [him]), orderOf_neg_one, ringChar.eq_zero, OfNat.zero_ne_ofNat, ↓reduceIte] at hζ' linarith end IsPrimitiveRoot
NumberTheory\NumberField\EquivReindex.lean
/- Copyright (c) 2024 Michail Karatarakis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michail Karatarakis -/ 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`. ## Tagshouse number field, algebraic number -/ variable (K : Type*) [Field K] [NumberField K] namespace NumberField noncomputable section open Module.Free FiniteDimensional 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, transpose_apply, 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
NumberTheory\NumberField\FractionalIdeal.lean
/- Copyright (c) 2024 Xavier Roblot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Xavier Roblot -/ import Mathlib.NumberTheory.NumberField.Basic import Mathlib.RingTheory.FractionalIdeal.Norm import Mathlib.RingTheory.FractionalIdeal.Operations /-! # Fractional ideals of number fields Prove some results on the fractional ideals of number fields. ## Main definitions and results * `NumberField.basisOfFractionalIdeal`: A `ℚ`-basis of `K` that spans `I` over `ℤ` where `I` is a fractional ideal of a number field `K`. * `NumberField.det_basisOfFractionalIdeal_eq_absNorm`: for `I` a fractional ideal of a number field `K`, the absolute value of the determinant of the base change from `integralBasis` to `basisOfFractionalIdeal I` is equal to the norm of `I`. -/ variable (K : Type*) [Field K] [NumberField K] namespace NumberField open scoped nonZeroDivisors section Basis open Module -- This is necessary to avoid several timeouts attribute [local instance 2000] Submodule.module instance (I : FractionalIdeal (𝓞 K)⁰ K) : Module.Free ℤ I := by refine Free.of_equiv (LinearEquiv.restrictScalars ℤ (I.equivNum ?_)).symm exact nonZeroDivisors.coe_ne_zero I.den instance (I : FractionalIdeal (𝓞 K)⁰ K) : Module.Finite ℤ I := by refine Module.Finite.of_surjective (LinearEquiv.restrictScalars ℤ (I.equivNum ?_)).symm.toLinearMap (LinearEquiv.surjective _) exact nonZeroDivisors.coe_ne_zero I.den instance (I : (FractionalIdeal (𝓞 K)⁰ K)ˣ) : IsLocalizedModule ℤ⁰ ((Submodule.subtype (I : Submodule (𝓞 K) K)).restrictScalars ℤ) where map_units x := by rw [← (Algebra.lmul _ _).commutes, Algebra.lmul_isUnit_iff, isUnit_iff_ne_zero, eq_intCast, Int.cast_ne_zero] exact nonZeroDivisors.coe_ne_zero x surj' x := by obtain ⟨⟨a, _, d, hd, rfl⟩, h⟩ := IsLocalization.surj (Algebra.algebraMapSubmonoid (𝓞 K) ℤ⁰) x refine ⟨⟨⟨Ideal.absNorm I.1.num * (algebraMap _ K a), I.1.num_le ?_⟩, d * Ideal.absNorm I.1.num, ?_⟩ , ?_⟩ · simp_rw [FractionalIdeal.val_eq_coe, FractionalIdeal.coe_coeIdeal] refine (IsLocalization.mem_coeSubmodule _ _).mpr ⟨Ideal.absNorm I.1.num * a, ?_, ?_⟩ · exact Ideal.mul_mem_right _ _ I.1.num.absNorm_mem · rw [map_mul, map_natCast] · refine Submonoid.mul_mem _ hd (mem_nonZeroDivisors_of_ne_zero ?_) rw [Nat.cast_ne_zero, ne_eq, Ideal.absNorm_eq_zero_iff] exact FractionalIdeal.num_eq_zero_iff.not.mpr <| Units.ne_zero I · simp_rw [LinearMap.coe_restrictScalars, Submodule.coeSubtype] at h ⊢ rw [← h] simp only [Submonoid.mk_smul, zsmul_eq_mul, Int.cast_mul, Int.cast_natCast, algebraMap_int_eq, eq_intCast, map_intCast] ring exists_of_eq h := ⟨1, by rwa [one_smul, one_smul, ← (Submodule.injective_subtype I.1.coeToSubmodule).eq_iff]⟩ /-- A `ℤ`-basis of a fractional ideal. -/ noncomputable def fractionalIdealBasis (I : FractionalIdeal (𝓞 K)⁰ K) : Basis (Free.ChooseBasisIndex ℤ I) ℤ I := Free.chooseBasis ℤ I /-- A `ℚ`-basis of `K` that spans `I` over `ℤ`, see `mem_span_basisOfFractionalIdeal` below. -/ noncomputable def basisOfFractionalIdeal (I : (FractionalIdeal (𝓞 K)⁰ K)ˣ) : Basis (Free.ChooseBasisIndex ℤ I) ℚ K := (fractionalIdealBasis K I.1).ofIsLocalizedModule ℚ ℤ⁰ ((Submodule.subtype (I : Submodule (𝓞 K) K)).restrictScalars ℤ) theorem basisOfFractionalIdeal_apply (I : (FractionalIdeal (𝓞 K)⁰ K)ˣ) (i : Free.ChooseBasisIndex ℤ I) : basisOfFractionalIdeal K I i = fractionalIdealBasis K I.1 i := (fractionalIdealBasis K I.1).ofIsLocalizedModule_apply ℚ ℤ⁰ _ i theorem mem_span_basisOfFractionalIdeal {I : (FractionalIdeal (𝓞 K)⁰ K)ˣ} {x : K} : x ∈ Submodule.span ℤ (Set.range (basisOfFractionalIdeal K I)) ↔ x ∈ (I : Set K) := by rw [basisOfFractionalIdeal, (fractionalIdealBasis K I.1).ofIsLocalizedModule_span ℚ ℤ⁰ _] simp open FiniteDimensional in theorem fractionalIdeal_rank (I : (FractionalIdeal (𝓞 K)⁰ K)ˣ) : finrank ℤ I = finrank ℤ (𝓞 K) := by rw [finrank_eq_card_chooseBasisIndex, RingOfIntegers.rank, finrank_eq_card_basis (basisOfFractionalIdeal K I)] end Basis section Norm open Module /-- The absolute value of the determinant of the base change from `integralBasis` to `basisOfFractionalIdeal I` is equal to the norm of `I`. -/ theorem det_basisOfFractionalIdeal_eq_absNorm (I : (FractionalIdeal (𝓞 K)⁰ K)ˣ) (e : (Free.ChooseBasisIndex ℤ (𝓞 K)) ≃ (Free.ChooseBasisIndex ℤ I)) : |(integralBasis K).det ((basisOfFractionalIdeal K I).reindex e.symm)| = FractionalIdeal.absNorm I.1 := by rw [← FractionalIdeal.abs_det_basis_change (RingOfIntegers.basis K) I.1 ((fractionalIdealBasis K I.1).reindex e.symm)] congr ext simpa using basisOfFractionalIdeal_apply K I _ end Norm end NumberField