path
stringlengths
11
71
content
stringlengths
75
124k
RingTheory\Ideal\Basis.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.Algebra.Algebra.Bilinear import Mathlib.LinearAlgebra.Basis import Mathlib.RingTheory.Ideal.Basic /-! # The basis of ideals Some results involving `Ideal` and `Basis`. -/ namespace Ideal variable {ι R S : Type*} [CommSemiring R] [CommRing S] [IsDomain S] [Algebra R S] /-- A basis on `S` gives a basis on `Ideal.span {x}`, by multiplying everything by `x`. -/ noncomputable def basisSpanSingleton (b : Basis ι R S) {x : S} (hx : x ≠ 0) : Basis ι R (span ({x} : Set S)) := b.map <| LinearEquiv.ofInjective (Algebra.lmul R S x) (LinearMap.mul_injective hx) ≪≫ₗ LinearEquiv.ofEq _ _ (by ext simp [mem_span_singleton', mul_comm]) ≪≫ₗ (Submodule.restrictScalarsEquiv R S S (Ideal.span ({x} : Set S))).restrictScalars R @[simp] theorem basisSpanSingleton_apply (b : Basis ι R S) {x : S} (hx : x ≠ 0) (i : ι) : (basisSpanSingleton b hx i : S) = x * b i := by simp only [basisSpanSingleton, Basis.map_apply, LinearEquiv.trans_apply, Submodule.restrictScalarsEquiv_apply, LinearEquiv.ofInjective_apply, LinearEquiv.coe_ofEq_apply, LinearEquiv.restrictScalars_apply, Algebra.coe_lmul_eq_mul, LinearMap.mul_apply'] @[simp] theorem constr_basisSpanSingleton {N : Type*} [Semiring N] [Module N S] [SMulCommClass R N S] (b : Basis ι R S) {x : S} (hx : x ≠ 0) : (b.constr N).toFun (((↑) : _ → S) ∘ (basisSpanSingleton b hx)) = Algebra.lmul R S x := b.ext fun i => by erw [Basis.constr_basis, Function.comp_apply, basisSpanSingleton_apply, LinearMap.mul_apply'] end Ideal -- Porting note: added explicit coercion `(b i : S)` /-- If `I : Ideal S` has a basis over `R`, `x ∈ I` iff it is a linear combination of basis vectors. -/ theorem Basis.mem_ideal_iff {ι R S : Type*} [CommRing R] [CommRing S] [Algebra R S] {I : Ideal S} (b : Basis ι R I) {x : S} : x ∈ I ↔ ∃ c : ι →₀ R, x = Finsupp.sum c fun i x => x • (b i : S) := (b.map ((I.restrictScalarsEquiv R _ _).restrictScalars R).symm).mem_submodule_iff /-- If `I : Ideal S` has a finite basis over `R`, `x ∈ I` iff it is a linear combination of basis vectors. -/ theorem Basis.mem_ideal_iff' {ι R S : Type*} [Fintype ι] [CommRing R] [CommRing S] [Algebra R S] {I : Ideal S} (b : Basis ι R I) {x : S} : x ∈ I ↔ ∃ c : ι → R, x = ∑ i, c i • (b i : S) := (b.map ((I.restrictScalarsEquiv R _ _).restrictScalars R).symm).mem_submodule_iff'
RingTheory\Ideal\Colon.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.LinearAlgebra.Quotient import Mathlib.RingTheory.Ideal.Operations /-! # The colon ideal This file defines `Submodule.colon N P` as the ideal of all elements `r : R` such that `r • P ⊆ N`. The normal notation for this would be `N : P` which has already been taken by type theory. -/ namespace Submodule open Pointwise variable {R M M' F G : Type*} [CommRing R] [AddCommGroup M] [Module R M] variable {N N₁ N₂ P P₁ P₂ : Submodule R M} /-- `N.colon P` is the ideal of all elements `r : R` such that `r • P ⊆ N`. -/ def colon (N P : Submodule R M) : Ideal R := annihilator (P.map N.mkQ) theorem mem_colon {r} : r ∈ N.colon P ↔ ∀ p ∈ P, r • p ∈ N := mem_annihilator.trans ⟨fun H p hp => (Quotient.mk_eq_zero N).1 (H (Quotient.mk p) (mem_map_of_mem hp)), fun H _ ⟨p, hp, hpm⟩ => hpm ▸ ((Quotient.mk_eq_zero N).2 <| H p hp)⟩ theorem mem_colon' {r} : r ∈ N.colon P ↔ P ≤ comap (r • (LinearMap.id : M →ₗ[R] M)) N := mem_colon @[simp] theorem colon_top {I : Ideal R} : I.colon ⊤ = I := by simp_rw [SetLike.ext_iff, mem_colon, smul_eq_mul] exact fun x ↦ ⟨fun h ↦ mul_one x ▸ h 1 trivial, fun h _ _ ↦ I.mul_mem_right _ h⟩ @[simp] theorem colon_bot : colon ⊥ N = N.annihilator := by simp_rw [SetLike.ext_iff, mem_colon, mem_annihilator, mem_bot, forall_const] theorem colon_mono (hn : N₁ ≤ N₂) (hp : P₁ ≤ P₂) : N₁.colon P₂ ≤ N₂.colon P₁ := fun _ hrnp => mem_colon.2 fun p₁ hp₁ => hn <| mem_colon.1 hrnp p₁ <| hp hp₁ theorem iInf_colon_iSup (ι₁ : Sort*) (f : ι₁ → Submodule R M) (ι₂ : Sort*) (g : ι₂ → Submodule R M) : (⨅ i, f i).colon (⨆ j, g j) = ⨅ (i) (j), (f i).colon (g j) := le_antisymm (le_iInf fun _ => le_iInf fun _ => colon_mono (iInf_le _ _) (le_iSup _ _)) fun _ H => mem_colon'.2 <| iSup_le fun j => map_le_iff_le_comap.1 <| le_iInf fun i => map_le_iff_le_comap.2 <| mem_colon'.1 <| have := (mem_iInf _).1 H i have := (mem_iInf _).1 this j this @[simp] theorem mem_colon_singleton {N : Submodule R M} {x : M} {r : R} : r ∈ N.colon (Submodule.span R {x}) ↔ r • x ∈ N := calc r ∈ N.colon (Submodule.span R {x}) ↔ ∀ a : R, r • a • x ∈ N := by simp [Submodule.mem_colon, Submodule.mem_span_singleton] _ ↔ r • x ∈ N := by simp_rw [fun (a : R) ↦ smul_comm r a x]; exact SetLike.forall_smul_mem_iff @[simp] theorem _root_.Ideal.mem_colon_singleton {I : Ideal R} {x r : R} : r ∈ I.colon (Ideal.span {x}) ↔ r * x ∈ I := by simp only [← Ideal.submodule_span_eq, Submodule.mem_colon_singleton, smul_eq_mul] theorem annihilator_quotient {N : Submodule R M} : Module.annihilator R (M ⧸ N) = N.colon ⊤ := by simp_rw [SetLike.ext_iff, Module.mem_annihilator, colon, mem_annihilator, map_top, LinearMap.range_eq_top.mpr (mkQ_surjective N), mem_top, forall_true_left, forall_const] theorem _root_.Ideal.annihilator_quotient {I : Ideal R} : Module.annihilator R (R ⧸ I) = I := by rw [Submodule.annihilator_quotient, colon_top] end Submodule
RingTheory\Ideal\Cotangent.lean
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.RingTheory.Ideal.Operations import Mathlib.Algebra.Module.Torsion import Mathlib.Algebra.Ring.Idempotents import Mathlib.LinearAlgebra.Dimension.FreeAndStrongRankCondition import Mathlib.LinearAlgebra.FiniteDimensional.Defs import Mathlib.RingTheory.LocalRing.ResidueField.Basic import Mathlib.RingTheory.Filtration import Mathlib.RingTheory.Nakayama /-! # The module `I ⧸ I ^ 2` In this file, we provide special API support for the module `I ⧸ I ^ 2`. The official definition is a quotient module of `I`, but the alternative definition as an ideal of `R ⧸ I ^ 2` is also given, and the two are `R`-equivalent as in `Ideal.cotangentEquivIdeal`. Additional support is also given to the cotangent space `m ⧸ m ^ 2` of a local ring. -/ namespace Ideal -- Porting note: universes need to be explicit to avoid bad universe levels in `quotCotangent` universe u v w variable {R : Type u} {S : Type v} {S' : Type w} [CommRing R] [CommSemiring S] [Algebra S R] variable [CommSemiring S'] [Algebra S' R] [Algebra S S'] [IsScalarTower S S' R] (I : Ideal R) -- Porting note: instances that were derived automatically need to be proved by hand (see below) /-- `I ⧸ I ^ 2` as a quotient of `I`. -/ def Cotangent : Type _ := I ⧸ (I • ⊤ : Submodule R I) instance : AddCommGroup I.Cotangent := by delta Cotangent; infer_instance instance cotangentModule : Module (R ⧸ I) I.Cotangent := by delta Cotangent; infer_instance instance : Inhabited I.Cotangent := ⟨0⟩ instance Cotangent.moduleOfTower : Module S I.Cotangent := Submodule.Quotient.module' _ instance Cotangent.isScalarTower : IsScalarTower S S' I.Cotangent := Submodule.Quotient.isScalarTower _ _ instance [IsNoetherian R I] : IsNoetherian R I.Cotangent := inferInstanceAs (IsNoetherian R (I ⧸ (I • ⊤ : Submodule R I))) /-- The quotient map from `I` to `I ⧸ I ^ 2`. -/ @[simps! (config := .lemmasOnly) apply] def toCotangent : I →ₗ[R] I.Cotangent := Submodule.mkQ _ theorem map_toCotangent_ker : I.toCotangent.ker.map I.subtype = I ^ 2 := by rw [Ideal.toCotangent, Submodule.ker_mkQ, pow_two, Submodule.map_smul'' I ⊤ (Submodule.subtype I), Algebra.id.smul_eq_mul, Submodule.map_subtype_top] theorem mem_toCotangent_ker {x : I} : x ∈ LinearMap.ker I.toCotangent ↔ (x : R) ∈ I ^ 2 := by rw [← I.map_toCotangent_ker] simp theorem toCotangent_eq {x y : I} : I.toCotangent x = I.toCotangent y ↔ (x - y : R) ∈ I ^ 2 := by rw [← sub_eq_zero] exact I.mem_toCotangent_ker theorem toCotangent_eq_zero (x : I) : I.toCotangent x = 0 ↔ (x : R) ∈ I ^ 2 := I.mem_toCotangent_ker theorem toCotangent_surjective : Function.Surjective I.toCotangent := Submodule.mkQ_surjective _ theorem toCotangent_range : LinearMap.range I.toCotangent = ⊤ := Submodule.range_mkQ _ theorem cotangent_subsingleton_iff : Subsingleton I.Cotangent ↔ IsIdempotentElem I := by constructor · intro H refine (pow_two I).symm.trans (le_antisymm (Ideal.pow_le_self two_ne_zero) ?_) exact fun x hx => (I.toCotangent_eq_zero ⟨x, hx⟩).mp (Subsingleton.elim _ _) · exact fun e => ⟨fun x y => Quotient.inductionOn₂' x y fun x y => I.toCotangent_eq.mpr <| ((pow_two I).trans e).symm ▸ I.sub_mem x.prop y.prop⟩ /-- The inclusion map `I ⧸ I ^ 2` to `R ⧸ I ^ 2`. -/ def cotangentToQuotientSquare : I.Cotangent →ₗ[R] R ⧸ I ^ 2 := Submodule.mapQ (I • ⊤) (I ^ 2) I.subtype (by rw [← Submodule.map_le_iff_le_comap, Submodule.map_smul'', Submodule.map_top, Submodule.range_subtype, smul_eq_mul, pow_two] ) theorem to_quotient_square_comp_toCotangent : I.cotangentToQuotientSquare.comp I.toCotangent = (I ^ 2).mkQ.comp (Submodule.subtype I) := LinearMap.ext fun _ => rfl @[simp] theorem toCotangent_to_quotient_square (x : I) : I.cotangentToQuotientSquare (I.toCotangent x) = (I ^ 2).mkQ x := rfl lemma Cotangent.smul_eq_zero_of_mem {I : Ideal R} {x} (hx : x ∈ I) (m : I.Cotangent) : x • m = 0 := by obtain ⟨m, rfl⟩ := Ideal.toCotangent_surjective _ m rw [← map_smul, Ideal.toCotangent_eq_zero, pow_two] exact Ideal.mul_mem_mul hx m.2 lemma isTorsionBySet_cotangent : Module.IsTorsionBySet R I.Cotangent I := fun m x ↦ m.smul_eq_zero_of_mem x.2 /-- `I ⧸ I ^ 2` as an ideal of `R ⧸ I ^ 2`. -/ def cotangentIdeal (I : Ideal R) : Ideal (R ⧸ I ^ 2) := Submodule.map (Quotient.mk (I ^ 2)|>.toSemilinearMap) I theorem cotangentIdeal_square (I : Ideal R) : I.cotangentIdeal ^ 2 = ⊥ := by rw [eq_bot_iff, pow_two I.cotangentIdeal, ← smul_eq_mul] intro x hx refine Submodule.smul_induction_on hx ?_ ?_ · rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩; apply (Submodule.Quotient.eq _).mpr _ rw [sub_zero, pow_two]; exact Ideal.mul_mem_mul hx hy · intro x y hx hy; exact add_mem hx hy theorem to_quotient_square_range : LinearMap.range I.cotangentToQuotientSquare = I.cotangentIdeal.restrictScalars R := by trans LinearMap.range (I.cotangentToQuotientSquare.comp I.toCotangent) · rw [LinearMap.range_comp, I.toCotangent_range, Submodule.map_top] · rw [to_quotient_square_comp_toCotangent, LinearMap.range_comp, I.range_subtype]; ext; rfl /-- The equivalence of the two definitions of `I / I ^ 2`, either as the quotient of `I` or the ideal of `R / I ^ 2`. -/ noncomputable def cotangentEquivIdeal : I.Cotangent ≃ₗ[R] I.cotangentIdeal := by refine { LinearMap.codRestrict (I.cotangentIdeal.restrictScalars R) I.cotangentToQuotientSquare fun x => by { rw [← to_quotient_square_range]; exact LinearMap.mem_range_self _ _ }, Equiv.ofBijective _ ⟨?_, ?_⟩ with } · rintro x y e replace e := congr_arg Subtype.val e obtain ⟨x, rfl⟩ := I.toCotangent_surjective x obtain ⟨y, rfl⟩ := I.toCotangent_surjective y rw [I.toCotangent_eq] dsimp only [toCotangent_to_quotient_square, Submodule.mkQ_apply] at e rwa [Submodule.Quotient.eq] at e · rintro ⟨_, x, hx, rfl⟩ exact ⟨I.toCotangent ⟨x, hx⟩, Subtype.ext rfl⟩ @[simp] theorem cotangentEquivIdeal_apply (x : I.Cotangent) : ↑(I.cotangentEquivIdeal x) = I.cotangentToQuotientSquare x := rfl theorem cotangentEquivIdeal_symm_apply (x : R) (hx : x ∈ I) : -- Note: #8386 had to specify `(R₂ := R)` because `I.toCotangent` suggested `R ⧸ I^2` instead I.cotangentEquivIdeal.symm ⟨(I ^ 2).mkQ x, Submodule.mem_map_of_mem (R₂ := R) hx⟩ = I.toCotangent ⟨x, hx⟩ := by apply I.cotangentEquivIdeal.injective rw [I.cotangentEquivIdeal.apply_symm_apply] ext rfl variable {A B : Type*} [CommRing A] [CommRing B] [Algebra R A] [Algebra R B] /-- The lift of `f : A →ₐ[R] B` to `A ⧸ J ^ 2 →ₐ[R] B` with `J` being the kernel of `f`. -/ def _root_.AlgHom.kerSquareLift (f : A →ₐ[R] B) : A ⧸ RingHom.ker f.toRingHom ^ 2 →ₐ[R] B := by refine { Ideal.Quotient.lift (RingHom.ker f.toRingHom ^ 2) f.toRingHom ?_ with commutes' := ?_ } · intro a ha; exact Ideal.pow_le_self two_ne_zero ha · intro r rw [IsScalarTower.algebraMap_apply R A, RingHom.toFun_eq_coe, Ideal.Quotient.algebraMap_eq, Ideal.Quotient.lift_mk] exact f.map_algebraMap r theorem _root_.AlgHom.ker_kerSquareLift (f : A →ₐ[R] B) : RingHom.ker f.kerSquareLift.toRingHom = f.toRingHom.ker.cotangentIdeal := by apply le_antisymm · intro x hx; obtain ⟨x, rfl⟩ := Ideal.Quotient.mk_surjective x; exact ⟨x, hx, rfl⟩ · rintro _ ⟨x, hx, rfl⟩; exact hx instance Algebra.kerSquareLift : Algebra (R ⧸ (RingHom.ker (algebraMap R A) ^ 2)) A := (Algebra.ofId R A).kerSquareLift.toAlgebra instance [Algebra A B] [IsScalarTower R A B] : IsScalarTower R (A ⧸ (RingHom.ker (algebraMap A B) ^ 2)) B := IsScalarTower.of_algebraMap_eq' (IsScalarTower.toAlgHom R A B).kerSquareLift.comp_algebraMap.symm /-- The quotient ring of `I ⧸ I ^ 2` is `R ⧸ I`. -/ def quotCotangent : (R ⧸ I ^ 2) ⧸ I.cotangentIdeal ≃+* R ⧸ I := by refine (Ideal.quotEquivOfEq (Ideal.map_eq_submodule_map _ _).symm).trans ?_ refine (DoubleQuot.quotQuotEquivQuotSup _ _).trans ?_ exact Ideal.quotEquivOfEq (sup_eq_right.mpr <| Ideal.pow_le_self two_ne_zero) /-- The map `I/I² → J/J²` if `I ≤ f⁻¹(J)`. -/ def mapCotangent (I₁ : Ideal A) (I₂ : Ideal B) (f : A →ₐ[R] B) (h : I₁ ≤ I₂.comap f) : I₁.Cotangent →ₗ[R] I₂.Cotangent := by refine Submodule.mapQ ((I₁ • ⊤ : Submodule A I₁).restrictScalars R) ((I₂ • ⊤ : Submodule B I₂).restrictScalars R) ?_ ?_ · exact f.toLinearMap.restrict (p := I₁.restrictScalars R) (q := I₂.restrictScalars R) h · intro x hx refine Submodule.smul_induction_on hx ?_ (fun _ _ ↦ add_mem) rintro a ha ⟨b, hb⟩ - simp only [SetLike.mk_smul_mk, smul_eq_mul, Submodule.mem_comap, Submodule.restrictScalars_mem] convert (Submodule.smul_mem_smul (M := I₂) (r := f a) (n := ⟨f b, h hb⟩) (h ha) (Submodule.mem_top)) using 1 ext exact _root_.map_mul f a b @[simp] lemma mapCotangent_toCotangent (I₁ : Ideal A) (I₂ : Ideal B) (f : A →ₐ[R] B) (h : I₁ ≤ I₂.comap f) (x : I₁) : Ideal.mapCotangent I₁ I₂ f h (Ideal.toCotangent I₁ x) = Ideal.toCotangent I₂ ⟨f x, h x.2⟩ := rfl end Ideal namespace LocalRing variable (R : Type*) [CommRing R] [LocalRing R] /-- The `A ⧸ I`-vector space `I ⧸ I ^ 2`. -/ abbrev CotangentSpace : Type _ := (maximalIdeal R).Cotangent instance : Module (ResidueField R) (CotangentSpace R) := Ideal.cotangentModule _ instance : IsScalarTower R (ResidueField R) (CotangentSpace R) := Module.IsTorsionBySet.isScalarTower _ instance [IsNoetherianRing R] : FiniteDimensional (ResidueField R) (CotangentSpace R) := Module.Finite.of_restrictScalars_finite R _ _ variable {R} lemma subsingleton_cotangentSpace_iff [IsNoetherianRing R] : Subsingleton (CotangentSpace R) ↔ IsField R := by refine (maximalIdeal R).cotangent_subsingleton_iff.trans ?_ rw [LocalRing.isField_iff_maximalIdeal_eq, Ideal.isIdempotentElem_iff_eq_bot_or_top_of_localRing] simp [(maximalIdeal.isMaximal R).ne_top] lemma CotangentSpace.map_eq_top_iff [IsNoetherianRing R] {M : Submodule R (maximalIdeal R)} : M.map (maximalIdeal R).toCotangent = ⊤ ↔ M = ⊤ := by refine ⟨fun H ↦ eq_top_iff.mpr ?_, by rintro rfl; simp [Ideal.toCotangent_range]⟩ refine (Submodule.map_le_map_iff_of_injective (Submodule.injective_subtype _) _ _).mp ?_ rw [Submodule.map_top, Submodule.range_subtype] apply Submodule.le_of_le_smul_of_le_jacobson_bot (IsNoetherian.noetherian _) (LocalRing.jacobson_eq_maximalIdeal _ bot_ne_top).ge rw [smul_eq_mul, ← pow_two, ← Ideal.map_toCotangent_ker, ← Submodule.map_sup, ← Submodule.comap_map_eq, H, Submodule.comap_top, Submodule.map_top, Submodule.range_subtype] lemma CotangentSpace.span_image_eq_top_iff [IsNoetherianRing R] {s : Set (maximalIdeal R)} : Submodule.span (ResidueField R) ((maximalIdeal R).toCotangent '' s) = ⊤ ↔ Submodule.span R s = ⊤ := by rw [← map_eq_top_iff, ← (Submodule.restrictScalars_injective R ..).eq_iff, Submodule.restrictScalars_span] · simp only [Ideal.toCotangent_apply, Submodule.restrictScalars_top, Submodule.map_span] · exact Ideal.Quotient.mk_surjective open FiniteDimensional lemma finrank_cotangentSpace_eq_zero_iff [IsNoetherianRing R] : finrank (ResidueField R) (CotangentSpace R) = 0 ↔ IsField R := by rw [finrank_zero_iff, subsingleton_cotangentSpace_iff] lemma finrank_cotangentSpace_eq_zero (R) [Field R] : finrank (ResidueField R) (CotangentSpace R) = 0 := finrank_cotangentSpace_eq_zero_iff.mpr (Field.toIsField R) open Submodule in theorem finrank_cotangentSpace_le_one_iff [IsNoetherianRing R] : finrank (ResidueField R) (CotangentSpace R) ≤ 1 ↔ (maximalIdeal R).IsPrincipal := by rw [Module.finrank_le_one_iff_top_isPrincipal, isPrincipal_iff, (maximalIdeal R).toCotangent_surjective.exists, isPrincipal_iff] simp_rw [← Set.image_singleton, eq_comm (a := ⊤), CotangentSpace.span_image_eq_top_iff, ← (map_injective_of_injective (injective_subtype _)).eq_iff, map_span, Set.image_singleton, Submodule.map_top, range_subtype, eq_comm (a := maximalIdeal R)] exact ⟨fun ⟨x, h⟩ ↦ ⟨_, h⟩, fun ⟨x, h⟩ ↦ ⟨⟨x, h ▸ subset_span (Set.mem_singleton x)⟩, h⟩⟩ end LocalRing
RingTheory\Ideal\IdempotentFG.lean
/- Copyright (c) 2018 Mario Carneiro, Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Kevin Buzzard -/ import Mathlib.Algebra.Ring.Idempotents import Mathlib.RingTheory.Finiteness import Mathlib.Order.Basic /-! ## Lemmas on idempotent finitely generated ideals -/ namespace Ideal /-- A finitely generated idempotent ideal is generated by an idempotent element -/ theorem isIdempotentElem_iff_of_fg {R : Type*} [CommRing R] (I : Ideal R) (h : I.FG) : IsIdempotentElem I ↔ ∃ e : R, IsIdempotentElem e ∧ I = R ∙ e := by constructor · intro e obtain ⟨r, hr, hr'⟩ := Submodule.exists_mem_and_smul_eq_self_of_fg_of_le_smul I I h (by rw [smul_eq_mul] exact e.ge) simp_rw [smul_eq_mul] at hr' refine ⟨r, hr' r hr, antisymm ?_ ((Submodule.span_singleton_le_iff_mem _ _).mpr hr)⟩ intro x hx rw [← hr' x hx] exact Ideal.mem_span_singleton'.mpr ⟨_, mul_comm _ _⟩ · rintro ⟨e, he, rfl⟩ simp [IsIdempotentElem, Ideal.span_singleton_mul_span_singleton, he.eq] theorem isIdempotentElem_iff_eq_bot_or_top {R : Type*} [CommRing R] [IsDomain R] (I : Ideal R) (h : I.FG) : IsIdempotentElem I ↔ I = ⊥ ∨ I = ⊤ := by constructor · intro H obtain ⟨e, he, rfl⟩ := (I.isIdempotentElem_iff_of_fg h).mp H simp only [Ideal.submodule_span_eq, Ideal.span_singleton_eq_bot] apply Or.imp id _ (IsIdempotentElem.iff_eq_zero_or_one.mp he) rintro rfl simp · rintro (rfl | rfl) <;> simp [IsIdempotentElem] end Ideal
RingTheory\Ideal\IsPrimary.lean
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.RingTheory.Ideal.Operations /-! # Primary ideals A proper ideal `I` is primary iff `xy ∈ I` implies `x ∈ I` or `y ∈ radical I`. ## Main definitions - `Ideal.IsPrimary` -/ namespace Ideal variable {R : Type*} [CommSemiring R] /-- A proper ideal `I` is primary iff `xy ∈ I` implies `x ∈ I` or `y ∈ radical I`. -/ def IsPrimary (I : Ideal R) : Prop := I ≠ ⊤ ∧ ∀ {x y : R}, x * y ∈ I → x ∈ I ∨ y ∈ radical I theorem IsPrime.isPrimary {I : Ideal R} (hi : IsPrime I) : IsPrimary I := ⟨hi.1, fun {_ _} hxy => (hi.mem_or_mem hxy).imp id fun hyi => le_radical hyi⟩ theorem isPrime_radical {I : Ideal R} (hi : IsPrimary I) : IsPrime (radical I) := ⟨mt radical_eq_top.1 hi.1, fun {x y} ⟨m, hxy⟩ => by rw [mul_pow] at hxy; cases' hi.2 hxy with h h · exact Or.inl ⟨m, h⟩ · exact Or.inr (mem_radical_of_pow_mem h)⟩ theorem isPrimary_inf {I J : Ideal R} (hi : IsPrimary I) (hj : IsPrimary J) (hij : radical I = radical J) : IsPrimary (I ⊓ J) := ⟨ne_of_lt <| lt_of_le_of_lt inf_le_left (lt_top_iff_ne_top.2 hi.1), fun {x y} ⟨hxyi, hxyj⟩ => by rw [radical_inf, hij, inf_idem] cases' hi.2 hxyi with hxi hyi · cases' hj.2 hxyj with hxj hyj · exact Or.inl ⟨hxi, hxj⟩ · exact Or.inr hyj · rw [hij] at hyi exact Or.inr hyi⟩ end Ideal
RingTheory\Ideal\IsPrincipal.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.RingTheory.PrincipalIdealDomain /-! # Principal Ideals This file deals with the set of principal ideals of a `CommRing R`. ## Main definitions and results * `Ideal.isPrincipalSubmonoid`: the submonoid of `Ideal R` formed by the principal ideals of `R`. * `Ideal.isPrincipalNonZeroDivisorSubmonoid`: the submonoid of `(Ideal R)⁰` formed by the non-zero-divisors principal ideals of `R`. * `Ideal.associatesMulEquivIsPrincipal`: the `MulEquiv` between the monoid of `Associates R` and the submonoid of principal ideals of `R`. * `Ideal.associatesNonZeroDivisorsMulEquivIsPrincipal`: the `MulEquiv` between the monoid of `Associates R⁰` and the submonoid of non-zero-divisors principal ideals of `R`. -/ variable {R : Type*} [CommRing R] namespace Ideal open Submodule Associates open scoped nonZeroDivisors variable (R) in /-- The principal ideals of `R` form a submonoid of `Ideal R`. -/ def isPrincipalSubmonoid : Submonoid (Ideal R) where carrier := {I | IsPrincipal I} mul_mem' := by rintro _ _ ⟨x, rfl⟩ ⟨y, rfl⟩ exact ⟨x * y, span_singleton_mul_span_singleton x y⟩ one_mem' := ⟨1, one_eq_span⟩ theorem mem_isPrincipalSubmonoid_iff {I : Ideal R} : I ∈ isPrincipalSubmonoid R ↔ IsPrincipal I := Iff.rfl theorem span_singleton_mem_isPrincipalSubmonoid (a : R) : span {a} ∈ isPrincipalSubmonoid R := mem_isPrincipalSubmonoid_iff.mpr ⟨a, rfl⟩ variable (R) in /-- The non-zero-divisors principal ideals of `R` form a submonoid of `(Ideal R)⁰`. -/ def isPrincipalNonZeroDivisorsSubmonoid : Submonoid (Ideal R)⁰ where carrier := {I | IsPrincipal I.val} mul_mem' := by rintro ⟨_, _⟩ ⟨_, _⟩ ⟨x, rfl⟩ ⟨y, rfl⟩ exact ⟨x * y, by simp_rw [Submonoid.mk_mul_mk, submodule_span_eq, span_singleton_mul_span_singleton]⟩ one_mem' := ⟨1, by simp⟩ variable [IsDomain R] variable (R) in /-- The equivalence between `Associates R` and the principal ideals of `R` defined by sending the class of `x` to the principal ideal generated by `x`. -/ noncomputable def associatesEquivIsPrincipal : Associates R ≃ {I : Ideal R // IsPrincipal I} where toFun := Quotient.lift (fun x ↦ ⟨span {x}, x, rfl⟩) (fun _ _ _ ↦ by simpa [span_singleton_eq_span_singleton]) invFun I := .mk I.2.generator left_inv := Quotient.ind fun _ ↦ by simpa using Ideal.span_singleton_eq_span_singleton.mp (@Ideal.span_singleton_generator _ _ _ ⟨_, rfl⟩) right_inv I := by simp only [Quotient.lift_mk, span_singleton_generator, Subtype.coe_eta] @[simp] theorem associatesEquivIsPrincipal_apply (x : R) : associatesEquivIsPrincipal R (.mk x) = span {x} := rfl @[simp] theorem associatesEquivIsPrincipal_symm_apply {I : Ideal R} (hI : IsPrincipal I) : (associatesEquivIsPrincipal R).symm ⟨I, hI⟩ = .mk hI.generator := rfl theorem associatesEquivIsPrincipal_mul (x y : Associates R) : (associatesEquivIsPrincipal R (x * y) : Ideal R) = (associatesEquivIsPrincipal R x) * (associatesEquivIsPrincipal R y) := by rw [← quot_out x, ← quot_out y] simp_rw [mk_mul_mk, associatesEquivIsPrincipal_apply, span_singleton_mul_span_singleton] @[simp] theorem associatesEquivIsPrincipal_map_zero : (associatesEquivIsPrincipal R 0 : Ideal R) = 0 := by rw [← mk_zero, associatesEquivIsPrincipal_apply, Submodule.zero_eq_bot, span_singleton_eq_bot] @[simp] theorem associatesEquivIsPrincipal_map_one : (associatesEquivIsPrincipal R 1 : Ideal R) = 1 := by rw [one_eq_mk_one, associatesEquivIsPrincipal_apply, span_singleton_one, one_eq_top] variable (R) in /-- The `MulEquiv` version of `Ideal.associatesEquivIsPrincipal`. -/ noncomputable def associatesMulEquivIsPrincipal : Associates R ≃* (isPrincipalSubmonoid R) where __ := associatesEquivIsPrincipal R map_mul' _ _ := by erw [Subtype.ext_iff, associatesEquivIsPrincipal_mul] rfl variable (R) in /-- A version of `Ideal.associatesEquivIsPrincipal` for non-zero-divisors generators. -/ noncomputable def associatesNonZeroDivisorsEquivIsPrincipal : Associates R⁰ ≃ {I : (Ideal R)⁰ // IsPrincipal (I : Ideal R)} := calc Associates R⁰ ≃ (Associates R)⁰ := associatesNonZeroDivisorsEquiv.toEquiv.symm _ ≃ {I : {I : Ideal R // IsPrincipal I} // I.1 ∈ (Ideal R)⁰} := Equiv.subtypeEquiv (associatesEquivIsPrincipal R) (fun x ↦ by rw [← quot_out x, mk_mem_nonZeroDivisors_associates, associatesEquivIsPrincipal_apply, span_singleton_nonZeroDivisors]) _ ≃ {I : Ideal R // IsPrincipal I ∧ I ∈ (Ideal R)⁰} := Equiv.subtypeSubtypeEquivSubtypeInter (fun I ↦ IsPrincipal I) (fun I ↦ I ∈ (Ideal R)⁰) _ ≃ {I : Ideal R // I ∈ (Ideal R)⁰ ∧ IsPrincipal I} := Equiv.setCongr (by simp_rw [and_comm]) _ ≃ {I : (Ideal R)⁰ // IsPrincipal I.1} := (Equiv.subtypeSubtypeEquivSubtypeInter _ _).symm @[simp] theorem associatesNonZeroDivisorsEquivIsPrincipal_apply (x : R⁰) : associatesNonZeroDivisorsEquivIsPrincipal R (.mk x) = Ideal.span {(x : R)} := rfl theorem associatesNonZeroDivisorsEquivIsPrincipal_coe (x : Associates R⁰) : (associatesNonZeroDivisorsEquivIsPrincipal R x : Ideal R) = (associatesEquivIsPrincipal R (associatesNonZeroDivisorsEquiv.symm x)) := rfl theorem associatesNonZeroDivisorsEquivIsPrincipal_mul (x y : Associates R⁰) : (associatesNonZeroDivisorsEquivIsPrincipal R (x * y) : Ideal R) = (associatesNonZeroDivisorsEquivIsPrincipal R x) * (associatesNonZeroDivisorsEquivIsPrincipal R y) := by simp_rw [associatesNonZeroDivisorsEquivIsPrincipal_coe, _root_.map_mul, Submonoid.coe_mul, associatesEquivIsPrincipal_mul] @[simp] theorem associatesNonZeroDivisorsEquivIsPrincipal_map_one : (associatesNonZeroDivisorsEquivIsPrincipal R 1 : Ideal R) = 1 := by rw [associatesNonZeroDivisorsEquivIsPrincipal_coe, map_one, OneMemClass.coe_one, associatesEquivIsPrincipal_map_one] variable (R) in /-- The `MulEquiv` version of `Ideal.associatesNonZeroDivisorsEquivIsPrincipal`. -/ noncomputable def associatesNonZeroDivisorsMulEquivIsPrincipal : Associates R⁰ ≃* (isPrincipalNonZeroDivisorsSubmonoid R) where __ := associatesNonZeroDivisorsEquivIsPrincipal R map_mul' _ _ := by erw [Subtype.ext_iff, Subtype.ext_iff, associatesNonZeroDivisorsEquivIsPrincipal_mul] rfl end Ideal
RingTheory\Ideal\Maps.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.RingTheory.Ideal.Operations /-! # Maps on modules and ideals -/ assert_not_exists Basis -- See `RingTheory.Ideal.Basis` assert_not_exists Submodule.hasQuotient -- See `RingTheory.Ideal.QuotientOperations` universe u v w x open Pointwise namespace Ideal section MapAndComap variable {R : Type u} {S : Type v} section Semiring variable {F : Type*} [Semiring R] [Semiring S] variable [FunLike F R S] [RingHomClass F R S] variable (f : F) variable {I J : Ideal R} {K L : Ideal S} /-- `I.map f` is the span of the image of the ideal `I` under `f`, which may be bigger than the image itself. -/ def map (I : Ideal R) : Ideal S := span (f '' I) /-- `I.comap f` is the preimage of `I` under `f`. -/ def comap (I : Ideal S) : Ideal R where carrier := f ⁻¹' I add_mem' {x y} hx hy := by simp only [Set.mem_preimage, SetLike.mem_coe, map_add f] at hx hy ⊢ exact add_mem hx hy zero_mem' := by simp only [Set.mem_preimage, map_zero, SetLike.mem_coe, Submodule.zero_mem] smul_mem' c x hx := by simp only [smul_eq_mul, Set.mem_preimage, map_mul, SetLike.mem_coe] at * exact mul_mem_left I _ hx @[simp] theorem coe_comap (I : Ideal S) : (comap f I : Set R) = f ⁻¹' I := rfl variable {f} theorem map_mono (h : I ≤ J) : map f I ≤ map f J := span_mono <| Set.image_subset _ h theorem mem_map_of_mem (f : F) {I : Ideal R} {x : R} (h : x ∈ I) : f x ∈ map f I := subset_span ⟨x, h, rfl⟩ theorem apply_coe_mem_map (f : F) (I : Ideal R) (x : I) : f x ∈ I.map f := mem_map_of_mem f x.2 theorem map_le_iff_le_comap : map f I ≤ K ↔ I ≤ comap f K := span_le.trans Set.image_subset_iff @[simp] theorem mem_comap {x} : x ∈ comap f K ↔ f x ∈ K := Iff.rfl theorem comap_mono (h : K ≤ L) : comap f K ≤ comap f L := Set.preimage_mono fun _ hx => h hx variable (f) theorem comap_ne_top (hK : K ≠ ⊤) : comap f K ≠ ⊤ := (ne_top_iff_one _).2 <| by rw [mem_comap, map_one]; exact (ne_top_iff_one _).1 hK variable {G : Type*} [FunLike G S R] theorem map_le_comap_of_inv_on [RingHomClass G S R] (g : G) (I : Ideal R) (hf : Set.LeftInvOn g f I) : I.map f ≤ I.comap g := by refine Ideal.span_le.2 ?_ rintro x ⟨x, hx, rfl⟩ rw [SetLike.mem_coe, mem_comap, hf hx] exact hx theorem comap_le_map_of_inv_on (g : G) (I : Ideal S) (hf : Set.LeftInvOn g f (f ⁻¹' I)) : I.comap f ≤ I.map g := fun x (hx : f x ∈ I) => hf hx ▸ Ideal.mem_map_of_mem g hx /-- The `Ideal` version of `Set.image_subset_preimage_of_inverse`. -/ theorem map_le_comap_of_inverse [RingHomClass G S R] (g : G) (I : Ideal R) (h : Function.LeftInverse g f) : I.map f ≤ I.comap g := map_le_comap_of_inv_on _ _ _ <| h.leftInvOn _ /-- The `Ideal` version of `Set.preimage_subset_image_of_inverse`. -/ theorem comap_le_map_of_inverse (g : G) (I : Ideal S) (h : Function.LeftInverse g f) : I.comap f ≤ I.map g := comap_le_map_of_inv_on _ _ _ <| h.leftInvOn _ instance IsPrime.comap [hK : K.IsPrime] : (comap f K).IsPrime := ⟨comap_ne_top _ hK.1, fun {x y} => by simp only [mem_comap, map_mul]; apply hK.2⟩ variable (I J K L) theorem map_top : map f ⊤ = ⊤ := (eq_top_iff_one _).2 <| subset_span ⟨1, trivial, map_one f⟩ theorem gc_map_comap : GaloisConnection (Ideal.map f) (Ideal.comap f) := fun _ _ => Ideal.map_le_iff_le_comap @[simp] theorem comap_id : I.comap (RingHom.id R) = I := Ideal.ext fun _ => Iff.rfl @[simp] theorem map_id : I.map (RingHom.id R) = I := (gc_map_comap (RingHom.id R)).l_unique GaloisConnection.id comap_id theorem comap_comap {T : Type*} [Semiring T] {I : Ideal T} (f : R →+* S) (g : S →+* T) : (I.comap g).comap f = I.comap (g.comp f) := rfl theorem map_map {T : Type*} [Semiring T] {I : Ideal R} (f : R →+* S) (g : S →+* T) : (I.map f).map g = I.map (g.comp f) := ((gc_map_comap f).compose (gc_map_comap g)).l_unique (gc_map_comap (g.comp f)) fun _ => comap_comap _ _ theorem map_span (f : F) (s : Set R) : map f (span s) = span (f '' s) := by refine (Submodule.span_eq_of_le _ ?_ ?_).symm · rintro _ ⟨x, hx, rfl⟩; exact mem_map_of_mem f (subset_span hx) · rw [map_le_iff_le_comap, span_le, coe_comap, ← Set.image_subset_iff] exact subset_span variable {f I J K L} theorem map_le_of_le_comap : I ≤ K.comap f → I.map f ≤ K := (gc_map_comap f).l_le theorem le_comap_of_map_le : I.map f ≤ K → I ≤ K.comap f := (gc_map_comap f).le_u theorem le_comap_map : I ≤ (I.map f).comap f := (gc_map_comap f).le_u_l _ theorem map_comap_le : (K.comap f).map f ≤ K := (gc_map_comap f).l_u_le _ @[simp] theorem comap_top : (⊤ : Ideal S).comap f = ⊤ := (gc_map_comap f).u_top @[simp] theorem comap_eq_top_iff {I : Ideal S} : I.comap f = ⊤ ↔ I = ⊤ := ⟨fun h => I.eq_top_iff_one.mpr (map_one f ▸ mem_comap.mp ((I.comap f).eq_top_iff_one.mp h)), fun h => by rw [h, comap_top]⟩ @[simp] theorem map_bot : (⊥ : Ideal R).map f = ⊥ := (gc_map_comap f).l_bot variable (f I J K L) @[simp] theorem map_comap_map : ((I.map f).comap f).map f = I.map f := (gc_map_comap f).l_u_l_eq_l I @[simp] theorem comap_map_comap : ((K.comap f).map f).comap f = K.comap f := (gc_map_comap f).u_l_u_eq_u K theorem map_sup : (I ⊔ J).map f = I.map f ⊔ J.map f := (gc_map_comap f : GaloisConnection (map f) (comap f)).l_sup theorem comap_inf : comap f (K ⊓ L) = comap f K ⊓ comap f L := rfl variable {ι : Sort*} theorem map_iSup (K : ι → Ideal R) : (iSup K).map f = ⨆ i, (K i).map f := (gc_map_comap f : GaloisConnection (map f) (comap f)).l_iSup theorem comap_iInf (K : ι → Ideal S) : (iInf K).comap f = ⨅ i, (K i).comap f := (gc_map_comap f : GaloisConnection (map f) (comap f)).u_iInf theorem map_sSup (s : Set (Ideal R)) : (sSup s).map f = ⨆ I ∈ s, (I : Ideal R).map f := (gc_map_comap f : GaloisConnection (map f) (comap f)).l_sSup theorem comap_sInf (s : Set (Ideal S)) : (sInf s).comap f = ⨅ I ∈ s, (I : Ideal S).comap f := (gc_map_comap f : GaloisConnection (map f) (comap f)).u_sInf theorem comap_sInf' (s : Set (Ideal S)) : (sInf s).comap f = ⨅ I ∈ comap f '' s, I := _root_.trans (comap_sInf f s) (by rw [iInf_image]) theorem comap_isPrime [H : IsPrime K] : IsPrime (comap f K) := ⟨comap_ne_top f H.ne_top, fun {x y} h => H.mem_or_mem <| by rwa [mem_comap, map_mul] at h⟩ variable {I J K L} theorem map_inf_le : map f (I ⊓ J) ≤ map f I ⊓ map f J := (gc_map_comap f : GaloisConnection (map f) (comap f)).monotone_l.map_inf_le _ _ theorem le_comap_sup : comap f K ⊔ comap f L ≤ comap f (K ⊔ L) := (gc_map_comap f : GaloisConnection (map f) (comap f)).monotone_u.le_map_sup _ _ -- TODO: Should these be simp lemmas? theorem _root_.element_smul_restrictScalars {R S M} [CommSemiring R] [CommSemiring S] [Algebra R S] [AddCommMonoid M] [Module R M] [Module S M] [IsScalarTower R S M] (r : R) (N : Submodule S M) : (algebraMap R S r • N).restrictScalars R = r • N.restrictScalars R := SetLike.coe_injective (congrArg (· '' _) (funext (algebraMap_smul S r))) theorem smul_restrictScalars {R S M} [CommSemiring R] [CommSemiring S] [Algebra R S] [AddCommMonoid M] [Module R M] [Module S M] [IsScalarTower R S M] (I : Ideal R) (N : Submodule S M) : (I.map (algebraMap R S) • N).restrictScalars R = I • N.restrictScalars R := by simp_rw [map, Submodule.span_smul_eq, ← Submodule.coe_set_smul, Submodule.set_smul_eq_iSup, ← element_smul_restrictScalars, iSup_image] exact (_root_.map_iSup₂ (Submodule.restrictScalarsLatticeHom R S M) _) @[simp] theorem smul_top_eq_map {R S : Type*} [CommSemiring R] [CommSemiring S] [Algebra R S] (I : Ideal R) : I • (⊤ : Submodule R S) = (I.map (algebraMap R S)).restrictScalars R := Eq.trans (smul_restrictScalars I (⊤ : Ideal S)).symm <| congrArg _ <| Eq.trans (Ideal.smul_eq_mul _ _) (Ideal.mul_top _) @[simp] theorem coe_restrictScalars {R S : Type*} [CommSemiring R] [Semiring S] [Algebra R S] (I : Ideal S) : (I.restrictScalars R : Set S) = ↑I := rfl /-- The smallest `S`-submodule that contains all `x ∈ I * y ∈ J` is also the smallest `R`-submodule that does so. -/ @[simp] theorem restrictScalars_mul {R S : Type*} [CommSemiring R] [CommSemiring S] [Algebra R S] (I J : Ideal S) : (I * J).restrictScalars R = I.restrictScalars R * J.restrictScalars R := le_antisymm (fun _ hx => Submodule.mul_induction_on hx (fun _ hx _ hy => Submodule.mul_mem_mul hx hy) fun _ _ => Submodule.add_mem _) (Submodule.mul_le.mpr fun _ hx _ hy => Ideal.mul_mem_mul hx hy) section Surjective variable (hf : Function.Surjective f) open Function theorem map_comap_of_surjective (I : Ideal S) : map f (comap f I) = I := le_antisymm (map_le_iff_le_comap.2 le_rfl) fun s hsi => let ⟨r, hfrs⟩ := hf s hfrs ▸ (mem_map_of_mem f <| show f r ∈ I from hfrs.symm ▸ hsi) /-- `map` and `comap` are adjoint, and the composition `map f ∘ comap f` is the identity -/ def giMapComap : GaloisInsertion (map f) (comap f) := GaloisInsertion.monotoneIntro (gc_map_comap f).monotone_u (gc_map_comap f).monotone_l (fun _ => le_comap_map) (map_comap_of_surjective _ hf) theorem map_surjective_of_surjective : Surjective (map f) := (giMapComap f hf).l_surjective theorem comap_injective_of_surjective : Injective (comap f) := (giMapComap f hf).u_injective theorem map_sup_comap_of_surjective (I J : Ideal S) : (I.comap f ⊔ J.comap f).map f = I ⊔ J := (giMapComap f hf).l_sup_u _ _ theorem map_iSup_comap_of_surjective (K : ι → Ideal S) : (⨆ i, (K i).comap f).map f = iSup K := (giMapComap f hf).l_iSup_u _ theorem map_inf_comap_of_surjective (I J : Ideal S) : (I.comap f ⊓ J.comap f).map f = I ⊓ J := (giMapComap f hf).l_inf_u _ _ theorem map_iInf_comap_of_surjective (K : ι → Ideal S) : (⨅ i, (K i).comap f).map f = iInf K := (giMapComap f hf).l_iInf_u _ theorem mem_image_of_mem_map_of_surjective {I : Ideal R} {y} (H : y ∈ map f I) : y ∈ f '' I := Submodule.span_induction H (fun _ => id) ⟨0, I.zero_mem, map_zero f⟩ (fun _ _ ⟨x1, hx1i, hxy1⟩ ⟨x2, hx2i, hxy2⟩ => ⟨x1 + x2, I.add_mem hx1i hx2i, hxy1 ▸ hxy2 ▸ map_add f _ _⟩) fun c _ ⟨x, hxi, hxy⟩ => let ⟨d, hdc⟩ := hf c ⟨d * x, I.mul_mem_left _ hxi, hdc ▸ hxy ▸ map_mul f _ _⟩ theorem mem_map_iff_of_surjective {I : Ideal R} {y} : y ∈ map f I ↔ ∃ x, x ∈ I ∧ f x = y := ⟨fun h => (Set.mem_image _ _ _).2 (mem_image_of_mem_map_of_surjective f hf h), fun ⟨_, hx⟩ => hx.right ▸ mem_map_of_mem f hx.left⟩ theorem le_map_of_comap_le_of_surjective : comap f K ≤ I → K ≤ map f I := fun h => map_comap_of_surjective f hf K ▸ map_mono h theorem map_eq_submodule_map (f : R →+* S) [h : RingHomSurjective f] (I : Ideal R) : I.map f = Submodule.map f.toSemilinearMap I := Submodule.ext fun _ => mem_map_iff_of_surjective f h.1 end Surjective section Injective theorem comap_bot_le_of_injective (hf : Function.Injective f) : comap f ⊥ ≤ I := by refine le_trans (fun x hx => ?_) bot_le rw [mem_comap, Submodule.mem_bot, ← map_zero f] at hx exact Eq.symm (hf hx) ▸ Submodule.zero_mem ⊥ theorem comap_bot_of_injective (hf : Function.Injective f) : Ideal.comap f ⊥ = ⊥ := le_bot_iff.mp (Ideal.comap_bot_le_of_injective f hf) end Injective /-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `map f.symm (map f I) = I`. -/ @[simp] theorem map_of_equiv (I : Ideal R) (f : R ≃+* S) : (I.map (f : R →+* S)).map (f.symm : S →+* R) = I := by rw [← RingEquiv.toRingHom_eq_coe, ← RingEquiv.toRingHom_eq_coe, map_map, RingEquiv.toRingHom_eq_coe, RingEquiv.toRingHom_eq_coe, RingEquiv.symm_comp, map_id] /-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `comap f (comap f.symm I) = I`. -/ @[simp] theorem comap_of_equiv (I : Ideal R) (f : R ≃+* S) : (I.comap (f.symm : S →+* R)).comap (f : R →+* S) = I := by rw [← RingEquiv.toRingHom_eq_coe, ← RingEquiv.toRingHom_eq_coe, comap_comap, RingEquiv.toRingHom_eq_coe, RingEquiv.toRingHom_eq_coe, RingEquiv.symm_comp, comap_id] /-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `map f I = comap f.symm I`. -/ theorem map_comap_of_equiv (I : Ideal R) (f : R ≃+* S) : I.map (f : R →+* S) = I.comap f.symm := le_antisymm (Ideal.map_le_comap_of_inverse _ _ _ (Equiv.left_inv' _)) (Ideal.comap_le_map_of_inverse _ _ _ (Equiv.right_inv' _)) /-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `comap f.symm I = map f I`. -/ @[simp] theorem comap_symm (I : Ideal R) (f : R ≃+* S) : I.comap f.symm = I.map f := (map_comap_of_equiv I f).symm /-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `map f.symm I = comap f I`. -/ @[simp] theorem map_symm (I : Ideal S) (f : R ≃+* S) : I.map f.symm = I.comap f := map_comap_of_equiv I (RingEquiv.symm f) end Semiring section Ring variable {F : Type*} [Ring R] [Ring S] variable [FunLike F R S] [RingHomClass F R S] (f : F) {I : Ideal R} section Surjective theorem comap_map_of_surjective (hf : Function.Surjective f) (I : Ideal R) : comap f (map f I) = I ⊔ comap f ⊥ := le_antisymm (fun r h => let ⟨s, hsi, hfsr⟩ := mem_image_of_mem_map_of_surjective f hf h Submodule.mem_sup.2 ⟨s, hsi, r - s, (Submodule.mem_bot S).2 <| by rw [map_sub, hfsr, sub_self], add_sub_cancel s r⟩) (sup_le (map_le_iff_le_comap.1 le_rfl) (comap_mono bot_le)) /-- Correspondence theorem -/ def relIsoOfSurjective (hf : Function.Surjective f) : Ideal S ≃o { p : Ideal R // comap f ⊥ ≤ p } where toFun J := ⟨comap f J, comap_mono bot_le⟩ invFun I := map f I.1 left_inv J := map_comap_of_surjective f hf J right_inv I := Subtype.eq <| show comap f (map f I.1) = I.1 from (comap_map_of_surjective f hf I).symm ▸ le_antisymm (sup_le le_rfl I.2) le_sup_left map_rel_iff' {I1 I2} := ⟨fun H => map_comap_of_surjective f hf I1 ▸ map_comap_of_surjective f hf I2 ▸ map_mono H, comap_mono⟩ /-- The map on ideals induced by a surjective map preserves inclusion. -/ def orderEmbeddingOfSurjective (hf : Function.Surjective f) : Ideal S ↪o Ideal R := (relIsoOfSurjective f hf).toRelEmbedding.trans (Subtype.relEmbedding (fun x y => x ≤ y) _) theorem map_eq_top_or_isMaximal_of_surjective (hf : Function.Surjective f) {I : Ideal R} (H : IsMaximal I) : map f I = ⊤ ∨ IsMaximal (map f I) := by refine or_iff_not_imp_left.2 fun ne_top => ⟨⟨fun h => ne_top h, fun J hJ => ?_⟩⟩ · refine (relIsoOfSurjective f hf).injective (Subtype.ext_iff.2 (Eq.trans (H.1.2 (comap f J) (lt_of_le_of_ne ?_ ?_)) comap_top.symm)) · exact map_le_iff_le_comap.1 (le_of_lt hJ) · exact fun h => hJ.right (le_map_of_comap_le_of_surjective f hf (le_of_eq h.symm)) theorem comap_isMaximal_of_surjective (hf : Function.Surjective f) {K : Ideal S} [H : IsMaximal K]: IsMaximal (comap f K) := by refine ⟨⟨comap_ne_top _ H.1.1, fun J hJ => ?_⟩⟩ suffices map f J = ⊤ by have := congr_arg (comap f) this rw [comap_top, comap_map_of_surjective _ hf, eq_top_iff] at this rw [eq_top_iff] exact le_trans this (sup_le (le_of_eq rfl) (le_trans (comap_mono bot_le) (le_of_lt hJ))) refine H.1.2 (map f J) (lt_of_le_of_ne (le_map_of_comap_le_of_surjective _ hf (le_of_lt hJ)) fun h => ne_of_lt hJ (_root_.trans (congr_arg (comap f) h) ?_)) rw [comap_map_of_surjective _ hf, sup_eq_left] exact le_trans (comap_mono bot_le) (le_of_lt hJ) theorem comap_le_comap_iff_of_surjective (hf : Function.Surjective f) (I J : Ideal S) : comap f I ≤ comap f J ↔ I ≤ J := ⟨fun h => (map_comap_of_surjective f hf I).symm.le.trans (map_le_of_le_comap h), fun h => le_comap_of_map_le ((map_comap_of_surjective f hf I).le.trans h)⟩ end Surjective section Bijective /-- Special case of the correspondence theorem for isomorphic rings -/ def relIsoOfBijective (hf : Function.Bijective f) : Ideal S ≃o Ideal R where toFun := comap f invFun := map f left_inv := (relIsoOfSurjective f hf.right).left_inv right_inv J := Subtype.ext_iff.1 ((relIsoOfSurjective f hf.right).right_inv ⟨J, comap_bot_le_of_injective f hf.left⟩) map_rel_iff' {_ _} := (relIsoOfSurjective f hf.right).map_rel_iff' theorem comap_le_iff_le_map (hf : Function.Bijective f) {I : Ideal R} {K : Ideal S} : comap f K ≤ I ↔ K ≤ map f I := ⟨fun h => le_map_of_comap_le_of_surjective f hf.right h, fun h => (relIsoOfBijective f hf).right_inv I ▸ comap_mono h⟩ theorem map.isMaximal (hf : Function.Bijective f) {I : Ideal R} (H : IsMaximal I) : IsMaximal (map f I) := by refine or_iff_not_imp_left.1 (map_eq_top_or_isMaximal_of_surjective f hf.right H) fun h => H.1.1 ?_ calc I = comap f (map f I) := ((relIsoOfBijective f hf).right_inv I).symm _ = comap f ⊤ := by rw [h] _ = ⊤ := by rw [comap_top] end Bijective theorem RingEquiv.bot_maximal_iff (e : R ≃+* S) : (⊥ : Ideal R).IsMaximal ↔ (⊥ : Ideal S).IsMaximal := ⟨fun h => map_bot (f := e.toRingHom) ▸ map.isMaximal e.toRingHom e.bijective h, fun h => map_bot (f := e.symm.toRingHom) ▸ map.isMaximal e.symm.toRingHom e.symm.bijective h⟩ end Ring section CommRing variable {F : Type*} [CommRing R] [CommRing S] variable [FunLike F R S] [rc : RingHomClass F R S] variable (f : F) variable {I J : Ideal R} {K L : Ideal S} variable (I J K L) theorem map_mul : map f (I * J) = map f I * map f J := le_antisymm (map_le_iff_le_comap.2 <| mul_le.2 fun r hri s hsj => show (f (r * s)) ∈ map f I * map f J by rw [_root_.map_mul]; exact mul_mem_mul (mem_map_of_mem f hri) (mem_map_of_mem f hsj)) (span_mul_span (↑f '' ↑I) (↑f '' ↑J) ▸ (span_le.2 <| Set.iUnion₂_subset fun i ⟨r, hri, hfri⟩ => Set.iUnion₂_subset fun j ⟨s, hsj, hfsj⟩ => Set.singleton_subset_iff.2 <| hfri ▸ hfsj ▸ by rw [← _root_.map_mul]; exact mem_map_of_mem f (mul_mem_mul hri hsj))) /-- The pushforward `Ideal.map` as a monoid-with-zero homomorphism. -/ @[simps] def mapHom : Ideal R →*₀ Ideal S where toFun := map f map_mul' I J := Ideal.map_mul f I J map_one' := by simp only [one_eq_top]; exact Ideal.map_top f map_zero' := Ideal.map_bot protected theorem map_pow (n : ℕ) : map f (I ^ n) = map f I ^ n := map_pow (mapHom f) I n theorem comap_radical : comap f (radical K) = radical (comap f K) := by ext simp [radical] variable {K} theorem IsRadical.comap (hK : K.IsRadical) : (comap f K).IsRadical := by rw [← hK.radical, comap_radical] apply radical_isRadical variable {I J L} theorem map_radical_le : map f (radical I) ≤ radical (map f I) := map_le_iff_le_comap.2 fun r ⟨n, hrni⟩ => ⟨n, map_pow f r n ▸ mem_map_of_mem f hrni⟩ theorem le_comap_mul : comap f K * comap f L ≤ comap f (K * L) := map_le_iff_le_comap.1 <| (map_mul f (comap f K) (comap f L)).symm ▸ mul_mono (map_le_iff_le_comap.2 <| le_rfl) (map_le_iff_le_comap.2 <| le_rfl) theorem le_comap_pow (n : ℕ) : K.comap f ^ n ≤ (K ^ n).comap f := by induction' n with n n_ih · rw [pow_zero, pow_zero, Ideal.one_eq_top, Ideal.one_eq_top] exact rfl.le · rw [pow_succ, pow_succ] exact (Ideal.mul_mono_left n_ih).trans (Ideal.le_comap_mul f) end CommRing end MapAndComap end Ideal namespace RingHom variable {R : Type u} {S : Type v} {T : Type w} section Semiring variable {F : Type*} {G : Type*} [Semiring R] [Semiring S] [Semiring T] variable [FunLike F R S] [rcf : RingHomClass F R S] [FunLike G T S] [rcg : RingHomClass G T S] variable (f : F) (g : G) /-- Kernel of a ring homomorphism as an ideal of the domain. -/ def ker : Ideal R := Ideal.comap f ⊥ /-- An element is in the kernel if and only if it maps to zero. -/ theorem mem_ker {r} : r ∈ ker f ↔ f r = 0 := by rw [ker, Ideal.mem_comap, Submodule.mem_bot] theorem ker_eq : (ker f : Set R) = Set.preimage f {0} := rfl theorem ker_eq_comap_bot (f : F) : ker f = Ideal.comap f ⊥ := rfl theorem comap_ker (f : S →+* R) (g : T →+* S) : f.ker.comap g = ker (f.comp g) := by rw [RingHom.ker_eq_comap_bot, Ideal.comap_comap, RingHom.ker_eq_comap_bot] /-- If the target is not the zero ring, then one is not in the kernel. -/ theorem not_one_mem_ker [Nontrivial S] (f : F) : (1 : R) ∉ ker f := by rw [mem_ker, map_one] exact one_ne_zero theorem ker_ne_top [Nontrivial S] (f : F) : ker f ≠ ⊤ := (Ideal.ne_top_iff_one _).mpr <| not_one_mem_ker f lemma _root_.Pi.ker_ringHom {ι : Type*} {R : ι → Type*} [∀ i, Semiring (R i)] (φ : ∀ i, S →+* R i) : ker (Pi.ringHom φ) = ⨅ i, ker (φ i) := by ext x simp [mem_ker, Ideal.mem_iInf, Function.funext_iff] @[simp] theorem ker_rangeSRestrict (f : R →+* S) : ker f.rangeSRestrict = ker f := Ideal.ext fun _ ↦ Subtype.ext_iff end Semiring section Ring variable {F : Type*} [Ring R] [Semiring S] [FunLike F R S] [rc : RingHomClass F R S] (f : F) theorem injective_iff_ker_eq_bot : Function.Injective f ↔ ker f = ⊥ := by rw [SetLike.ext'_iff, ker_eq, Set.ext_iff] exact injective_iff_map_eq_zero' f theorem ker_eq_bot_iff_eq_zero : ker f = ⊥ ↔ ∀ x, f x = 0 → x = 0 := by rw [← injective_iff_map_eq_zero f, injective_iff_ker_eq_bot] @[simp] theorem ker_coe_equiv (f : R ≃+* S) : ker (f : R →+* S) = ⊥ := by simpa only [← injective_iff_ker_eq_bot] using EquivLike.injective f @[simp] theorem ker_equiv {F' : Type*} [EquivLike F' R S] [RingEquivClass F' R S] (f : F') : ker f = ⊥ := by simpa only [← injective_iff_ker_eq_bot] using EquivLike.injective f end Ring section RingRing variable {F : Type*} [Ring R] [Ring S] [FunLike F R S] [rc : RingHomClass F R S] (f : F) theorem sub_mem_ker_iff {x y} : x - y ∈ ker f ↔ f x = f y := by rw [mem_ker, map_sub, sub_eq_zero] @[simp] theorem ker_rangeRestrict (f : R →+* S) : ker f.rangeRestrict = ker f := Ideal.ext fun _ ↦ Subtype.ext_iff end RingRing /-- The kernel of a homomorphism to a domain is a prime ideal. -/ theorem ker_isPrime {F : Type*} [Ring R] [Ring S] [IsDomain S] [FunLike F R S] [RingHomClass F R S] (f : F) : (ker f).IsPrime := ⟨by rw [Ne, Ideal.eq_top_iff_one] exact not_one_mem_ker f, fun {x y} => by simpa only [mem_ker, map_mul] using @eq_zero_or_eq_zero_of_mul_eq_zero S _ _ _ _ _⟩ /-- The kernel of a homomorphism to a field is a maximal ideal. -/ theorem ker_isMaximal_of_surjective {R K F : Type*} [Ring R] [Field K] [FunLike F R K] [RingHomClass F R K] (f : F) (hf : Function.Surjective f) : (ker f).IsMaximal := by refine Ideal.isMaximal_iff.mpr ⟨fun h1 => one_ne_zero' K <| map_one f ▸ (mem_ker f).mp h1, fun J x hJ hxf hxJ => ?_⟩ obtain ⟨y, hy⟩ := hf (f x)⁻¹ have H : 1 = y * x - (y * x - 1) := (sub_sub_cancel _ _).symm rw [H] refine J.sub_mem (J.mul_mem_left _ hxJ) (hJ ?_) rw [mem_ker] simp only [hy, map_sub, map_one, map_mul, inv_mul_cancel (mt (mem_ker f).mpr hxf), sub_self] end RingHom namespace Ideal variable {R : Type*} {S : Type*} {F : Type*} section Semiring variable [Semiring R] [Semiring S] [FunLike F R S] [rc : RingHomClass F R S] theorem map_eq_bot_iff_le_ker {I : Ideal R} (f : F) : I.map f = ⊥ ↔ I ≤ RingHom.ker f := by rw [RingHom.ker, eq_bot_iff, map_le_iff_le_comap] theorem ker_le_comap {K : Ideal S} (f : F) : RingHom.ker f ≤ comap f K := fun _ hx => mem_comap.2 (((RingHom.mem_ker f).1 hx).symm ▸ K.zero_mem) theorem map_isPrime_of_equiv {F' : Type*} [EquivLike F' R S] [RingEquivClass F' R S] (f : F') {I : Ideal R} [IsPrime I] : IsPrime (map f I) := by have h : I.map f = I.map ((f : R ≃+* S) : R →+* S) := rfl rw [h, map_comap_of_equiv I (f : R ≃+* S)] exact Ideal.IsPrime.comap (RingEquiv.symm (f : R ≃+* S)) end Semiring section Ring variable [Ring R] [Ring S] [FunLike F R S] [rc : RingHomClass F R S] theorem map_sInf {A : Set (Ideal R)} {f : F} (hf : Function.Surjective f) : (∀ J ∈ A, RingHom.ker f ≤ J) → map f (sInf A) = sInf (map f '' A) := by refine fun h => le_antisymm (le_sInf ?_) ?_ · intro j hj y hy cases' (mem_map_iff_of_surjective f hf).1 hy with x hx cases' (Set.mem_image _ _ _).mp hj with J hJ rw [← hJ.right, ← hx.right] exact mem_map_of_mem f (sInf_le_of_le hJ.left (le_of_eq rfl) hx.left) · intro y hy cases' hf y with x hx refine hx ▸ mem_map_of_mem f ?_ have : ∀ I ∈ A, y ∈ map f I := by simpa using hy rw [Submodule.mem_sInf] intro J hJ rcases (mem_map_iff_of_surjective f hf).1 (this J hJ) with ⟨x', hx', rfl⟩ have : x - x' ∈ J := by apply h J hJ rw [RingHom.mem_ker, map_sub, hx, sub_self] simpa only [sub_add_cancel] using J.add_mem this hx' theorem map_isPrime_of_surjective {f : F} (hf : Function.Surjective f) {I : Ideal R} [H : IsPrime I] (hk : RingHom.ker f ≤ I) : IsPrime (map f I) := by refine ⟨fun h => H.ne_top (eq_top_iff.2 ?_), fun {x y} => ?_⟩ · replace h := congr_arg (comap f) h rw [comap_map_of_surjective _ hf, comap_top] at h exact h ▸ sup_le (le_of_eq rfl) hk · refine fun hxy => (hf x).recOn fun a ha => (hf y).recOn fun b hb => ?_ rw [← ha, ← hb, ← _root_.map_mul f, mem_map_iff_of_surjective _ hf] at hxy rcases hxy with ⟨c, hc, hc'⟩ rw [← sub_eq_zero, ← map_sub] at hc' have : a * b ∈ I := by convert I.sub_mem hc (hk (hc' : c - a * b ∈ RingHom.ker f)) using 1 abel exact (H.mem_or_mem this).imp (fun h => ha ▸ mem_map_of_mem f h) fun h => hb ▸ mem_map_of_mem f h theorem map_eq_bot_iff_of_injective {I : Ideal R} {f : F} (hf : Function.Injective f) : I.map f = ⊥ ↔ I = ⊥ := by rw [map_eq_bot_iff_le_ker, (RingHom.injective_iff_ker_eq_bot f).mp hf, le_bot_iff] end Ring section CommRing variable [CommRing R] [CommRing S] theorem map_eq_iff_sup_ker_eq_of_surjective {I J : Ideal R} (f : R →+* S) (hf : Function.Surjective f) : map f I = map f J ↔ I ⊔ RingHom.ker f = J ⊔ RingHom.ker f := by rw [← (comap_injective_of_surjective f hf).eq_iff, comap_map_of_surjective f hf, comap_map_of_surjective f hf, RingHom.ker_eq_comap_bot] theorem map_radical_of_surjective {f : R →+* S} (hf : Function.Surjective f) {I : Ideal R} (h : RingHom.ker f ≤ I) : map f I.radical = (map f I).radical := by rw [radical_eq_sInf, radical_eq_sInf] have : ∀ J ∈ {J : Ideal R | I ≤ J ∧ J.IsPrime}, RingHom.ker f ≤ J := fun J hJ => h.trans hJ.left convert map_sInf hf this refine funext fun j => propext ⟨?_, ?_⟩ · rintro ⟨hj, hj'⟩ haveI : j.IsPrime := hj' exact ⟨comap f j, ⟨⟨map_le_iff_le_comap.1 hj, comap_isPrime f j⟩, map_comap_of_surjective f hf j⟩⟩ · rintro ⟨J, ⟨hJ, hJ'⟩⟩ haveI : J.IsPrime := hJ.right exact ⟨hJ' ▸ map_mono hJ.left, hJ' ▸ map_isPrime_of_surjective hf (le_trans h hJ.left)⟩ end CommRing end Ideal namespace RingHom variable {A B C : Type*} [Ring A] [Ring B] [Ring C] variable (f : A →+* B) (f_inv : B → A) /-- Auxiliary definition used to define `liftOfRightInverse` -/ def liftOfRightInverseAux (hf : Function.RightInverse f_inv f) (g : A →+* C) (hg : RingHom.ker f ≤ RingHom.ker g) : B →+* C := { AddMonoidHom.liftOfRightInverse f.toAddMonoidHom f_inv hf ⟨g.toAddMonoidHom, hg⟩ with toFun := fun b => g (f_inv b) map_one' := by rw [← map_one g, ← sub_eq_zero, ← map_sub g, ← mem_ker g] apply hg rw [mem_ker f, map_sub f, sub_eq_zero, map_one f] exact hf 1 map_mul' := by intro x y rw [← map_mul g, ← sub_eq_zero, ← map_sub g, ← mem_ker g] apply hg rw [mem_ker f, map_sub f, sub_eq_zero, map_mul f] simp only [hf _] } @[simp] theorem liftOfRightInverseAux_comp_apply (hf : Function.RightInverse f_inv f) (g : A →+* C) (hg : RingHom.ker f ≤ RingHom.ker g) (a : A) : (f.liftOfRightInverseAux f_inv hf g hg) (f a) = g a := f.toAddMonoidHom.liftOfRightInverse_comp_apply f_inv hf ⟨g.toAddMonoidHom, hg⟩ a /-- `liftOfRightInverse f hf g hg` is the unique ring homomorphism `φ` * such that `φ.comp f = g` (`RingHom.liftOfRightInverse_comp`), * where `f : A →+* B` has a right_inverse `f_inv` (`hf`), * and `g : B →+* C` satisfies `hg : f.ker ≤ g.ker`. See `RingHom.eq_liftOfRightInverse` for the uniqueness lemma. ``` A . | \ f | \ g | \ v \⌟ B ----> C ∃!φ ``` -/ def liftOfRightInverse (hf : Function.RightInverse f_inv f) : { g : A →+* C // RingHom.ker f ≤ RingHom.ker g } ≃ (B →+* C) where toFun g := f.liftOfRightInverseAux f_inv hf g.1 g.2 invFun φ := ⟨φ.comp f, fun x hx => (mem_ker _).mpr <| by simp [(mem_ker _).mp hx]⟩ left_inv g := by ext simp only [comp_apply, liftOfRightInverseAux_comp_apply, Subtype.coe_mk] right_inv φ := by ext b simp [liftOfRightInverseAux, hf b] /-- A non-computable version of `RingHom.liftOfRightInverse` for when no computable right inverse is available, that uses `Function.surjInv`. -/ @[simp] noncomputable abbrev liftOfSurjective (hf : Function.Surjective f) : { g : A →+* C // RingHom.ker f ≤ RingHom.ker g } ≃ (B →+* C) := f.liftOfRightInverse (Function.surjInv hf) (Function.rightInverse_surjInv hf) theorem liftOfRightInverse_comp_apply (hf : Function.RightInverse f_inv f) (g : { g : A →+* C // RingHom.ker f ≤ RingHom.ker g }) (x : A) : (f.liftOfRightInverse f_inv hf g) (f x) = g.1 x := f.liftOfRightInverseAux_comp_apply f_inv hf g.1 g.2 x theorem liftOfRightInverse_comp (hf : Function.RightInverse f_inv f) (g : { g : A →+* C // RingHom.ker f ≤ RingHom.ker g }) : (f.liftOfRightInverse f_inv hf g).comp f = g := RingHom.ext <| f.liftOfRightInverse_comp_apply f_inv hf g theorem eq_liftOfRightInverse (hf : Function.RightInverse f_inv f) (g : A →+* C) (hg : RingHom.ker f ≤ RingHom.ker g) (h : B →+* C) (hh : h.comp f = g) : h = f.liftOfRightInverse f_inv hf ⟨g, hg⟩ := by simp_rw [← hh] exact ((f.liftOfRightInverse f_inv hf).apply_symm_apply _).symm end RingHom namespace AlgHom variable {R A B : Type*} [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] (f : A →ₐ[R] B) lemma coe_ker : RingHom.ker f = RingHom.ker (f : A →+* B) := rfl lemma coe_ideal_map (I : Ideal A) : Ideal.map f I = Ideal.map (f : A →+* B) I := rfl end AlgHom namespace Algebra variable {R : Type*} [CommSemiring R] (S : Type*) [Semiring S] [Algebra R S] /-- The induced linear map from `I` to the span of `I` in an `R`-algebra `S`. -/ @[simps!] def idealMap (I : Ideal R) : I →ₗ[R] I.map (algebraMap R S) := (Algebra.linearMap R S).restrict (q := (I.map (algebraMap R S)).restrictScalars R) (fun _ ↦ Ideal.mem_map_of_mem _) end Algebra
RingTheory\Ideal\MinimalPrime.lean
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.RingTheory.Ideal.IsPrimary import Mathlib.RingTheory.Localization.AtPrime import Mathlib.Order.Minimal /-! # Minimal primes We provide various results concerning the minimal primes above an ideal ## Main results - `Ideal.minimalPrimes`: `I.minimalPrimes` is the set of ideals that are minimal primes over `I`. - `minimalPrimes`: `minimalPrimes R` is the set of minimal primes of `R`. - `Ideal.exists_minimalPrimes_le`: Every prime ideal over `I` contains a minimal prime over `I`. - `Ideal.radical_minimalPrimes`: The minimal primes over `I.radical` are precisely the minimal primes over `I`. - `Ideal.sInf_minimalPrimes`: The intersection of minimal primes over `I` is `I.radical`. - `Ideal.exists_minimalPrimes_comap_eq` If `p` is a minimal prime over `f ⁻¹ I`, then it is the preimage of some minimal prime over `I`. - `Ideal.minimalPrimes_eq_comap`: The minimal primes over `I` are precisely the preimages of minimal primes of `R ⧸ I`. - `Localization.AtPrime.prime_unique_of_minimal`: When localizing at a minimal prime ideal `I`, the resulting ring only has a single prime ideal. -/ section variable {R S : Type*} [CommSemiring R] [CommSemiring S] (I J : Ideal R) /-- `I.minimalPrimes` is the set of ideals that are minimal primes over `I`. -/ protected def Ideal.minimalPrimes : Set (Ideal R) := {p | Minimal (fun q ↦ q.IsPrime ∧ I ≤ q) p} variable (R) in /-- `minimalPrimes R` is the set of minimal primes of `R`. This is defined as `Ideal.minimalPrimes ⊥`. -/ def minimalPrimes : Set (Ideal R) := Ideal.minimalPrimes ⊥ lemma minimalPrimes_eq_minimals : minimalPrimes R = {x | Minimal Ideal.IsPrime x} := congr_arg Minimal (by simp) variable {I J} theorem Ideal.exists_minimalPrimes_le [J.IsPrime] (e : I ≤ J) : ∃ p ∈ I.minimalPrimes, p ≤ J := by suffices ∃ m ∈ { p : (Ideal R)ᵒᵈ | Ideal.IsPrime p ∧ I ≤ OrderDual.ofDual p }, OrderDual.toDual J ≤ m ∧ ∀ z ∈ { p : (Ideal R)ᵒᵈ | Ideal.IsPrime p ∧ I ≤ p }, m ≤ z → z = m by obtain ⟨p, h₁, h₂, h₃⟩ := this simp_rw [← @eq_comm _ p] at h₃ exact ⟨p, ⟨h₁, fun a b c => le_of_eq (h₃ a b c)⟩, h₂⟩ apply zorn_nonempty_partialOrder₀ swap · refine ⟨show J.IsPrime by infer_instance, e⟩ rintro (c : Set (Ideal R)) hc hc' J' hJ' refine ⟨OrderDual.toDual (sInf c), ⟨Ideal.sInf_isPrime_of_isChain ⟨J', hJ'⟩ hc'.symm fun x hx => (hc hx).1, ?_⟩, ?_⟩ · rw [OrderDual.ofDual_toDual, le_sInf_iff] exact fun _ hx => (hc hx).2 · rintro z hz rw [OrderDual.le_toDual] exact sInf_le hz @[simp] theorem Ideal.radical_minimalPrimes : I.radical.minimalPrimes = I.minimalPrimes := by rw [Ideal.minimalPrimes, Ideal.minimalPrimes] ext p refine ⟨?_, ?_⟩ <;> rintro ⟨⟨a, ha⟩, b⟩ · refine ⟨⟨a, a.radical_le_iff.1 ha⟩, ?_⟩ simp only [Set.mem_setOf_eq, and_imp] at * exact fun _ h2 h3 h4 => b h2 (h2.radical_le_iff.2 h3) h4 · refine ⟨⟨a, a.radical_le_iff.2 ha⟩, ?_⟩ simp only [Set.mem_setOf_eq, and_imp] at * exact fun _ h2 h3 h4 => b h2 (h2.radical_le_iff.1 h3) h4 @[simp] theorem Ideal.sInf_minimalPrimes : sInf I.minimalPrimes = I.radical := by rw [I.radical_eq_sInf] apply le_antisymm · intro x hx rw [Ideal.mem_sInf] at hx ⊢ rintro J ⟨e, hJ⟩ obtain ⟨p, hp, hp'⟩ := Ideal.exists_minimalPrimes_le e exact hp' (hx hp) · apply sInf_le_sInf _ intro I hI exact hI.1.symm theorem Ideal.exists_comap_eq_of_mem_minimalPrimes_of_injective {f : R →+* S} (hf : Function.Injective f) (p) (H : p ∈ minimalPrimes R) : ∃ p' : Ideal S, p'.IsPrime ∧ p'.comap f = p := by have := H.1.1 have : Nontrivial (Localization (Submonoid.map f p.primeCompl)) := by refine ⟨⟨1, 0, ?_⟩⟩ convert (IsLocalization.map_injective_of_injective p.primeCompl (Localization.AtPrime p) (Localization <| p.primeCompl.map f) hf).ne one_ne_zero · rw [map_one] · rw [map_zero] obtain ⟨M, hM⟩ := Ideal.exists_maximal (Localization (Submonoid.map f p.primeCompl)) refine ⟨M.comap (algebraMap S <| Localization (Submonoid.map f p.primeCompl)), inferInstance, ?_⟩ rw [Ideal.comap_comap, ← @IsLocalization.map_comp _ _ _ _ _ _ _ _ Localization.isLocalization _ _ _ _ p.primeCompl.le_comap_map _ Localization.isLocalization, ← Ideal.comap_comap] suffices _ ≤ p by exact this.antisymm (H.2 ⟨inferInstance, bot_le⟩ this) intro x hx by_contra h apply hM.ne_top apply M.eq_top_of_isUnit_mem hx apply IsUnit.map apply IsLocalization.map_units _ (show p.primeCompl from ⟨x, h⟩) end section variable {R S : Type*} [CommRing R] [CommRing S] {I J : Ideal R} theorem Ideal.exists_comap_eq_of_mem_minimalPrimes {I : Ideal S} (f : R →+* S) (p) (H : p ∈ (I.comap f).minimalPrimes) : ∃ p' : Ideal S, p'.IsPrime ∧ I ≤ p' ∧ p'.comap f = p := by have := H.1.1 let f' := (Ideal.Quotient.mk I).comp f have e : RingHom.ker f' = I.comap f := by ext1 exact Submodule.Quotient.mk_eq_zero _ have : RingHom.ker (Ideal.Quotient.mk <| RingHom.ker f') ≤ p := by rw [Ideal.mk_ker, e] exact H.1.2 suffices _ by have ⟨p', hp₁, hp₂⟩ := Ideal.exists_comap_eq_of_mem_minimalPrimes_of_injective (RingHom.kerLift_injective f') (p.map <| Ideal.Quotient.mk <| RingHom.ker f') this refine ⟨p'.comap <| Ideal.Quotient.mk I, Ideal.IsPrime.comap _, ?_, ?_⟩ · exact Ideal.mk_ker.symm.trans_le (Ideal.comap_mono bot_le) · convert congr_arg (Ideal.comap <| Ideal.Quotient.mk <| RingHom.ker f') hp₂ rwa [Ideal.comap_map_of_surjective (Ideal.Quotient.mk <| RingHom.ker f') Ideal.Quotient.mk_surjective, eq_comm, sup_eq_left] refine ⟨⟨?_, bot_le⟩, ?_⟩ · apply Ideal.map_isPrime_of_surjective _ this exact Ideal.Quotient.mk_surjective · rintro q ⟨hq, -⟩ hq' rw [← Ideal.map_comap_of_surjective (Ideal.Quotient.mk (RingHom.ker ((Ideal.Quotient.mk I).comp f))) Ideal.Quotient.mk_surjective q] apply Ideal.map_mono apply H.2 · refine ⟨inferInstance, (Ideal.mk_ker.trans e).symm.trans_le (Ideal.comap_mono bot_le)⟩ · refine (Ideal.comap_mono hq').trans ?_ rw [Ideal.comap_map_of_surjective] exacts [sup_le rfl.le this, Ideal.Quotient.mk_surjective] theorem Ideal.exists_minimalPrimes_comap_eq {I : Ideal S} (f : R →+* S) (p) (H : p ∈ (I.comap f).minimalPrimes) : ∃ p' ∈ I.minimalPrimes, Ideal.comap f p' = p := by obtain ⟨p', h₁, h₂, h₃⟩ := Ideal.exists_comap_eq_of_mem_minimalPrimes f p H obtain ⟨q, hq, hq'⟩ := Ideal.exists_minimalPrimes_le h₂ refine ⟨q, hq, Eq.symm ?_⟩ have := hq.1.1 have := (Ideal.comap_mono hq').trans_eq h₃ exact (H.2 ⟨inferInstance, Ideal.comap_mono hq.1.2⟩ this).antisymm this theorem Ideal.minimal_primes_comap_of_surjective {f : R →+* S} (hf : Function.Surjective f) {I J : Ideal S} (h : J ∈ I.minimalPrimes) : J.comap f ∈ (I.comap f).minimalPrimes := by have := h.1.1 refine ⟨⟨inferInstance, Ideal.comap_mono h.1.2⟩, ?_⟩ rintro K ⟨hK, e₁⟩ e₂ have : RingHom.ker f ≤ K := (Ideal.comap_mono bot_le).trans e₁ rw [← sup_eq_left.mpr this, RingHom.ker_eq_comap_bot, ← Ideal.comap_map_of_surjective f hf] apply Ideal.comap_mono _ apply h.2 _ _ · exact ⟨Ideal.map_isPrime_of_surjective hf this, Ideal.le_map_of_comap_le_of_surjective f hf e₁⟩ · exact Ideal.map_le_of_le_comap e₂ theorem Ideal.comap_minimalPrimes_eq_of_surjective {f : R →+* S} (hf : Function.Surjective f) (I : Ideal S) : (I.comap f).minimalPrimes = Ideal.comap f '' I.minimalPrimes := by ext J constructor · intro H obtain ⟨p, h, rfl⟩ := Ideal.exists_minimalPrimes_comap_eq f J H exact ⟨p, h, rfl⟩ · rintro ⟨J, hJ, rfl⟩ exact Ideal.minimal_primes_comap_of_surjective hf hJ theorem Ideal.minimalPrimes_eq_comap : I.minimalPrimes = Ideal.comap (Ideal.Quotient.mk I) '' minimalPrimes (R ⧸ I) := by rw [minimalPrimes, ← Ideal.comap_minimalPrimes_eq_of_surjective Ideal.Quotient.mk_surjective, ← RingHom.ker_eq_comap_bot, Ideal.mk_ker] theorem Ideal.minimalPrimes_eq_subsingleton (hI : I.IsPrimary) : I.minimalPrimes = {I.radical} := by ext J constructor · exact fun H => let e := H.1.1.radical_le_iff.mpr H.1.2 (H.2 ⟨Ideal.isPrime_radical hI, Ideal.le_radical⟩ e).antisymm e · rintro (rfl : J = I.radical) exact ⟨⟨Ideal.isPrime_radical hI, Ideal.le_radical⟩, fun _ H _ => H.1.radical_le_iff.mpr H.2⟩ theorem Ideal.minimalPrimes_eq_subsingleton_self [I.IsPrime] : I.minimalPrimes = {I} := by ext J constructor · exact fun H => (H.2 ⟨inferInstance, rfl.le⟩ H.1.2).antisymm H.1.2 · rintro (rfl : J = I) exact ⟨⟨inferInstance, rfl.le⟩, fun _ h _ => h.2⟩ end namespace Localization.AtPrime variable {R : Type*} [CommSemiring R] {I : Ideal R} [hI : I.IsPrime] (hMin : I ∈ minimalPrimes R) theorem _root_.IsLocalization.AtPrime.prime_unique_of_minimal {S} [CommSemiring S] [Algebra R S] [IsLocalization.AtPrime S I] {J K : Ideal S} [J.IsPrime] [K.IsPrime] : J = K := haveI : Subsingleton {i : Ideal R // i.IsPrime ∧ i ≤ I} := ⟨fun i₁ i₂ ↦ Subtype.ext <| by rw [minimalPrimes_eq_minimals, Set.mem_setOf] at hMin rw [hMin.eq_of_le i₁.2.1 i₁.2.2, hMin.eq_of_le i₂.2.1 i₂.2.2]⟩ Subtype.ext_iff.mp <| (IsLocalization.AtPrime.orderIsoOfPrime S I).injective (a₁ := ⟨J, ‹_›⟩) (a₂ := ⟨K, ‹_›⟩) (Subsingleton.elim _ _) theorem prime_unique_of_minimal (J : Ideal (Localization I.primeCompl)) [J.IsPrime] : J = LocalRing.maximalIdeal (Localization I.primeCompl) := IsLocalization.AtPrime.prime_unique_of_minimal hMin theorem nilpotent_iff_mem_maximal_of_minimal {x : _} : IsNilpotent x ↔ x ∈ LocalRing.maximalIdeal (Localization I.primeCompl) := by rw [nilpotent_iff_mem_prime] exact ⟨(· (LocalRing.maximalIdeal _) (Ideal.IsMaximal.isPrime' _)), fun _ J _ => by simpa [prime_unique_of_minimal hMin J]⟩ theorem nilpotent_iff_not_unit_of_minimal {x : Localization I.primeCompl} : IsNilpotent x ↔ x ∈ nonunits _ := by simpa only [← LocalRing.mem_maximalIdeal] using nilpotent_iff_mem_maximal_of_minimal hMin end Localization.AtPrime
RingTheory\Ideal\Norm.lean
/- Copyright (c) 2022 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Alex J. Best -/ import Mathlib.Algebra.CharP.Quotient import Mathlib.Algebra.GroupWithZero.NonZeroDivisors import Mathlib.Data.Finsupp.Fintype import Mathlib.Data.Int.AbsoluteValue import Mathlib.Data.Int.Associated import Mathlib.LinearAlgebra.FreeModule.Determinant import Mathlib.LinearAlgebra.FreeModule.IdealQuotient import Mathlib.RingTheory.DedekindDomain.PID import Mathlib.RingTheory.Ideal.Basis import Mathlib.RingTheory.LocalProperties import Mathlib.RingTheory.Localization.NormTrace /-! # Ideal norms This file defines the absolute ideal norm `Ideal.absNorm (I : Ideal R) : ℕ` as the cardinality of the quotient `R ⧸ I` (setting it to 0 if the cardinality is infinite), and the relative ideal norm `Ideal.spanNorm R (I : Ideal S) : Ideal S` as the ideal spanned by the norms of elements in `I`. ## Main definitions * `Submodule.cardQuot (S : Submodule R M)`: the cardinality of the quotient `M ⧸ S`, in `ℕ`. This maps `⊥` to `0` and `⊤` to `1`. * `Ideal.absNorm (I : Ideal R)`: the absolute ideal norm, defined as the cardinality of the quotient `R ⧸ I`, as a bundled monoid-with-zero homomorphism. * `Ideal.spanNorm R (I : Ideal S)`: the ideal spanned by the norms of elements in `I`. This is used to define `Ideal.relNorm`. * `Ideal.relNorm R (I : Ideal S)`: the relative ideal norm as a bundled monoid-with-zero morphism, defined as the ideal spanned by the norms of elements in `I`. ## Main results * `map_mul Ideal.absNorm`: multiplicativity of the ideal norm is bundled in the definition of `Ideal.absNorm` * `Ideal.natAbs_det_basis_change`: the ideal norm is given by the determinant of the basis change matrix * `Ideal.absNorm_span_singleton`: the ideal norm of a principal ideal is the norm of its generator * `map_mul Ideal.relNorm`: multiplicativity of the relative ideal norm -/ open scoped nonZeroDivisors section abs_norm namespace Submodule variable {R M : Type*} [Ring R] [AddCommGroup M] [Module R M] section /-- The cardinality of `(M ⧸ S)`, if `(M ⧸ S)` is finite, and `0` otherwise. This is used to define the absolute ideal norm `Ideal.absNorm`. -/ noncomputable def cardQuot (S : Submodule R M) : ℕ := AddSubgroup.index S.toAddSubgroup theorem cardQuot_apply (S : Submodule R M) : cardQuot S = Nat.card (M ⧸ S) := by rfl variable (R M) @[simp] theorem cardQuot_bot [Infinite M] : cardQuot (⊥ : Submodule R M) = 0 := AddSubgroup.index_bot.trans Nat.card_eq_zero_of_infinite @[simp] theorem cardQuot_top : cardQuot (⊤ : Submodule R M) = 1 := AddSubgroup.index_top variable {R M} @[simp] theorem cardQuot_eq_one_iff {P : Submodule R M} : cardQuot P = 1 ↔ P = ⊤ := AddSubgroup.index_eq_one.trans (by simp [SetLike.ext_iff]) end end Submodule section RingOfIntegers variable {S : Type*} [CommRing S] open Submodule /-- Multiplicity of the ideal norm, for coprime ideals. This is essentially just a repackaging of the Chinese Remainder Theorem. -/ theorem cardQuot_mul_of_coprime {I J : Ideal S} (coprime : IsCoprime I J) : cardQuot (I * J) = cardQuot I * cardQuot J := by rw [cardQuot_apply, cardQuot_apply, cardQuot_apply, Nat.card_congr (Ideal.quotientMulEquivQuotientProd I J coprime).toEquiv, Nat.card_prod] /-- If the `d` from `Ideal.exists_mul_add_mem_pow_succ` is unique, up to `P`, then so are the `c`s, up to `P ^ (i + 1)`. Inspired by [Neukirch], proposition 6.1 -/ theorem Ideal.mul_add_mem_pow_succ_inj (P : Ideal S) {i : ℕ} (a d d' e e' : S) (a_mem : a ∈ P ^ i) (e_mem : e ∈ P ^ (i + 1)) (e'_mem : e' ∈ P ^ (i + 1)) (h : d - d' ∈ P) : a * d + e - (a * d' + e') ∈ P ^ (i + 1) := by have : a * d - a * d' ∈ P ^ (i + 1) := by simp only [← mul_sub] exact Ideal.mul_mem_mul a_mem h convert Ideal.add_mem _ this (Ideal.sub_mem _ e_mem e'_mem) using 1 ring section PPrime variable {P : Ideal S} [P_prime : P.IsPrime] /-- If `a ∈ P^i \ P^(i+1)` and `c ∈ P^i`, then `a * d + e = c` for `e ∈ P^(i+1)`. `Ideal.mul_add_mem_pow_succ_unique` shows the choice of `d` is unique, up to `P`. Inspired by [Neukirch], proposition 6.1 -/ theorem Ideal.exists_mul_add_mem_pow_succ [IsDedekindDomain S] (hP : P ≠ ⊥) {i : ℕ} (a c : S) (a_mem : a ∈ P ^ i) (a_not_mem : a ∉ P ^ (i + 1)) (c_mem : c ∈ P ^ i) : ∃ d : S, ∃ e ∈ P ^ (i + 1), a * d + e = c := by suffices eq_b : P ^ i = Ideal.span {a} ⊔ P ^ (i + 1) by rw [eq_b] at c_mem simp only [mul_comm a] exact Ideal.mem_span_singleton_sup.mp c_mem refine (Ideal.eq_prime_pow_of_succ_lt_of_le hP (lt_of_le_of_ne le_sup_right ?_) (sup_le (Ideal.span_le.mpr (Set.singleton_subset_iff.mpr a_mem)) (Ideal.pow_succ_lt_pow hP i).le)).symm contrapose! a_not_mem with this rw [this] exact mem_sup.mpr ⟨a, mem_span_singleton_self a, 0, by simp, by simp⟩ theorem Ideal.mem_prime_of_mul_mem_pow [IsDedekindDomain S] {P : Ideal S} [P_prime : P.IsPrime] (hP : P ≠ ⊥) {i : ℕ} {a b : S} (a_not_mem : a ∉ P ^ (i + 1)) (ab_mem : a * b ∈ P ^ (i + 1)) : b ∈ P := by simp only [← Ideal.span_singleton_le_iff_mem, ← Ideal.dvd_iff_le, pow_succ, ← Ideal.span_singleton_mul_span_singleton] at a_not_mem ab_mem ⊢ exact (prime_pow_succ_dvd_mul (Ideal.prime_of_isPrime hP P_prime) ab_mem).resolve_left a_not_mem /-- The choice of `d` in `Ideal.exists_mul_add_mem_pow_succ` is unique, up to `P`. Inspired by [Neukirch], proposition 6.1 -/ theorem Ideal.mul_add_mem_pow_succ_unique [IsDedekindDomain S] (hP : P ≠ ⊥) {i : ℕ} (a d d' e e' : S) (a_not_mem : a ∉ P ^ (i + 1)) (e_mem : e ∈ P ^ (i + 1)) (e'_mem : e' ∈ P ^ (i + 1)) (h : a * d + e - (a * d' + e') ∈ P ^ (i + 1)) : d - d' ∈ P := by have h' : a * (d - d') ∈ P ^ (i + 1) := by convert Ideal.add_mem _ h (Ideal.sub_mem _ e'_mem e_mem) using 1 ring exact Ideal.mem_prime_of_mul_mem_pow hP a_not_mem h' /-- Multiplicity of the ideal norm, for powers of prime ideals. -/ theorem cardQuot_pow_of_prime [IsDedekindDomain S] (hP : P ≠ ⊥) {i : ℕ} : cardQuot (P ^ i) = cardQuot P ^ i := by induction' i with i ih · simp have : P ^ (i + 1) < P ^ i := Ideal.pow_succ_lt_pow hP i suffices hquot : map (P ^ i.succ).mkQ (P ^ i) ≃ S ⧸ P by rw [pow_succ' (cardQuot P), ← ih, cardQuot_apply (P ^ i.succ), ← card_quotient_mul_card_quotient (P ^ i) (P ^ i.succ) this.le, cardQuot_apply (P ^ i), cardQuot_apply P, Nat.card_congr hquot] choose a a_mem a_not_mem using SetLike.exists_of_lt this choose f g hg hf using fun c (hc : c ∈ P ^ i) => Ideal.exists_mul_add_mem_pow_succ hP a c a_mem a_not_mem hc choose k hk_mem hk_eq using fun c' (hc' : c' ∈ map (mkQ (P ^ i.succ)) (P ^ i)) => Submodule.mem_map.mp hc' refine Equiv.ofBijective (fun c' => Quotient.mk'' (f (k c' c'.prop) (hk_mem c' c'.prop))) ⟨?_, ?_⟩ · rintro ⟨c₁', hc₁'⟩ ⟨c₂', hc₂'⟩ h rw [Subtype.mk_eq_mk, ← hk_eq _ hc₁', ← hk_eq _ hc₂', mkQ_apply, mkQ_apply, Submodule.Quotient.eq, ← hf _ (hk_mem _ hc₁'), ← hf _ (hk_mem _ hc₂')] refine Ideal.mul_add_mem_pow_succ_inj _ _ _ _ _ _ a_mem (hg _ _) (hg _ _) ?_ simpa only [Submodule.Quotient.mk''_eq_mk, Submodule.Quotient.mk''_eq_mk, Submodule.Quotient.eq] using h · intro d' refine Quotient.inductionOn' d' fun d => ?_ have hd' := (mem_map (f := mkQ (P ^ i.succ))).mpr ⟨a * d, Ideal.mul_mem_right d _ a_mem, rfl⟩ refine ⟨⟨_, hd'⟩, ?_⟩ simp only [Submodule.Quotient.mk''_eq_mk, Ideal.Quotient.mk_eq_mk, Ideal.Quotient.eq, Subtype.coe_mk] refine Ideal.mul_add_mem_pow_succ_unique hP a _ _ _ _ a_not_mem (hg _ (hk_mem _ hd')) (zero_mem _) ?_ rw [hf, add_zero] exact (Submodule.Quotient.eq _).mp (hk_eq _ hd') end PPrime /-- Multiplicativity of the ideal norm in number rings. -/ theorem cardQuot_mul [IsDedekindDomain S] [Module.Free ℤ S] (I J : Ideal S) : cardQuot (I * J) = cardQuot I * cardQuot J := by let b := Module.Free.chooseBasis ℤ S haveI : Infinite S := Infinite.of_surjective _ b.repr.toEquiv.surjective exact UniqueFactorizationMonoid.multiplicative_of_coprime cardQuot I J (cardQuot_bot _ _) (fun {I J} hI => by simp [Ideal.isUnit_iff.mp hI, Ideal.mul_top]) (fun {I} i hI => have : Ideal.IsPrime I := Ideal.isPrime_of_prime hI cardQuot_pow_of_prime hI.ne_zero) fun {I J} hIJ => cardQuot_mul_of_coprime <| Ideal.isCoprime_iff_sup_eq.mpr (Ideal.isUnit_iff.mp (hIJ (Ideal.dvd_iff_le.mpr le_sup_left) (Ideal.dvd_iff_le.mpr le_sup_right))) /-- The absolute norm of the ideal `I : Ideal R` is the cardinality of the quotient `R ⧸ I`. -/ noncomputable def Ideal.absNorm [Nontrivial S] [IsDedekindDomain S] [Module.Free ℤ S] : Ideal S →*₀ ℕ where toFun := Submodule.cardQuot map_mul' I J := by dsimp only; rw [cardQuot_mul] map_one' := by dsimp only; rw [Ideal.one_eq_top, cardQuot_top] map_zero' := by have : Infinite S := Module.Free.infinite ℤ S rw [Ideal.zero_eq_bot, cardQuot_bot] namespace Ideal variable [Nontrivial S] [IsDedekindDomain S] [Module.Free ℤ S] theorem absNorm_apply (I : Ideal S) : absNorm I = cardQuot I := rfl @[simp] theorem absNorm_bot : absNorm (⊥ : Ideal S) = 0 := by rw [← Ideal.zero_eq_bot, _root_.map_zero] @[simp] theorem absNorm_top : absNorm (⊤ : Ideal S) = 1 := by rw [← Ideal.one_eq_top, _root_.map_one] @[simp] theorem absNorm_eq_one_iff {I : Ideal S} : absNorm I = 1 ↔ I = ⊤ := by rw [absNorm_apply, cardQuot_eq_one_iff] theorem absNorm_ne_zero_iff (I : Ideal S) : Ideal.absNorm I ≠ 0 ↔ Finite (S ⧸ I) := ⟨fun h => Nat.finite_of_card_ne_zero h, fun h => (@AddSubgroup.finiteIndex_of_finite_quotient _ _ _ h).finiteIndex⟩ theorem absNorm_dvd_absNorm_of_le {I J : Ideal S} (h : J ≤ I) : Ideal.absNorm I ∣ Ideal.absNorm J := map_dvd absNorm (dvd_iff_le.mpr h) theorem irreducible_of_irreducible_absNorm {I : Ideal S} (hI : Irreducible (Ideal.absNorm I)) : Irreducible I := irreducible_iff.mpr ⟨fun h => hI.not_unit (by simpa only [Ideal.isUnit_iff, Nat.isUnit_iff, absNorm_eq_one_iff] using h), by rintro a b rfl simpa only [Ideal.isUnit_iff, Nat.isUnit_iff, absNorm_eq_one_iff] using hI.isUnit_or_isUnit (_root_.map_mul absNorm a b)⟩ theorem isPrime_of_irreducible_absNorm {I : Ideal S} (hI : Irreducible (Ideal.absNorm I)) : I.IsPrime := isPrime_of_prime (UniqueFactorizationMonoid.irreducible_iff_prime.mp (irreducible_of_irreducible_absNorm hI)) theorem prime_of_irreducible_absNorm_span {a : S} (ha : a ≠ 0) (hI : Irreducible (Ideal.absNorm (Ideal.span ({a} : Set S)))) : Prime a := (Ideal.span_singleton_prime ha).mp (isPrime_of_irreducible_absNorm hI) theorem absNorm_mem (I : Ideal S) : ↑(Ideal.absNorm I) ∈ I := by rw [absNorm_apply, cardQuot, ← Ideal.Quotient.eq_zero_iff_mem, map_natCast, Quotient.index_eq_zero] theorem span_singleton_absNorm_le (I : Ideal S) : Ideal.span {(Ideal.absNorm I : S)} ≤ I := by simp only [Ideal.span_le, Set.singleton_subset_iff, SetLike.mem_coe, Ideal.absNorm_mem I] theorem span_singleton_absNorm {I : Ideal S} (hI : (Ideal.absNorm I).Prime) : Ideal.span (singleton (Ideal.absNorm I : ℤ)) = I.comap (algebraMap ℤ S) := by have : Ideal.IsPrime (Ideal.span (singleton (Ideal.absNorm I : ℤ))) := by rwa [Ideal.span_singleton_prime (Int.ofNat_ne_zero.mpr hI.ne_zero), ← Nat.prime_iff_prime_int] apply (this.isMaximal _).eq_of_le · exact ((isPrime_of_irreducible_absNorm ((Nat.irreducible_iff_nat_prime _).mpr hI)).comap (algebraMap ℤ S)).ne_top · rw [span_singleton_le_iff_mem, mem_comap, algebraMap_int_eq, map_natCast] exact absNorm_mem I · rw [Ne, span_singleton_eq_bot] exact Int.ofNat_ne_zero.mpr hI.ne_zero variable [Module.Finite ℤ S] /-- Let `e : S ≃ I` be an additive isomorphism (therefore a `ℤ`-linear equiv). Then an alternative way to compute the norm of `I` is given by taking the determinant of `e`. See `natAbs_det_basis_change` for a more familiar formulation of this result. -/ theorem natAbs_det_equiv (I : Ideal S) {E : Type*} [EquivLike E S I] [AddEquivClass E S I] (e : E) : Int.natAbs (LinearMap.det ((Submodule.subtype I).restrictScalars ℤ ∘ₗ AddMonoidHom.toIntLinearMap (e : S →+ I))) = Ideal.absNorm I := by -- `S ⧸ I` might be infinite if `I = ⊥`, but then `e` can't be an equiv. by_cases hI : I = ⊥ · subst hI have : (1 : S) ≠ 0 := one_ne_zero have : (1 : S) = 0 := EquivLike.injective e (Subsingleton.elim _ _) contradiction let ι := Module.Free.ChooseBasisIndex ℤ S let b := Module.Free.chooseBasis ℤ S cases isEmpty_or_nonempty ι · nontriviality S exact (not_nontrivial_iff_subsingleton.mpr (Function.Surjective.subsingleton b.repr.toEquiv.symm.surjective) (by infer_instance)).elim -- Thus `(S ⧸ I)` is isomorphic to a product of `ZMod`s, so it is a fintype. letI := Ideal.fintypeQuotientOfFreeOfNeBot I hI -- Use the Smith normal form to choose a nice basis for `I`. letI := Classical.decEq ι let a := I.smithCoeffs b hI let b' := I.ringBasis b hI let ab := I.selfBasis b hI have ab_eq := I.selfBasis_def b hI let e' : S ≃ₗ[ℤ] I := b'.equiv ab (Equiv.refl _) let f : S →ₗ[ℤ] S := (I.subtype.restrictScalars ℤ).comp (e' : S →ₗ[ℤ] I) let f_apply : ∀ x, f x = b'.equiv ab (Equiv.refl _) x := fun x => rfl suffices (LinearMap.det f).natAbs = Ideal.absNorm I by calc _ = (LinearMap.det ((Submodule.subtype I).restrictScalars ℤ ∘ₗ (AddEquiv.toIntLinearEquiv e : S ≃ₗ[ℤ] I))).natAbs := rfl _ = (LinearMap.det ((Submodule.subtype I).restrictScalars ℤ ∘ₗ _)).natAbs := Int.natAbs_eq_iff_associated.mpr (LinearMap.associated_det_comp_equiv _ _ _) _ = absNorm I := this have ha : ∀ i, f (b' i) = a i • b' i := by intro i; rw [f_apply, b'.equiv_apply, Equiv.refl_apply, ab_eq] -- `det f` is equal to `∏ i, a i`, letI := Classical.decEq ι calc Int.natAbs (LinearMap.det f) = Int.natAbs (LinearMap.toMatrix b' b' f).det := by rw [LinearMap.det_toMatrix] _ = Int.natAbs (Matrix.diagonal a).det := ?_ _ = Int.natAbs (∏ i, a i) := by rw [Matrix.det_diagonal] _ = ∏ i, Int.natAbs (a i) := map_prod Int.natAbsHom a Finset.univ _ = Nat.card (S ⧸ I) := ?_ _ = absNorm I := (Submodule.cardQuot_apply _).symm -- since `LinearMap.toMatrix b' b' f` is the diagonal matrix with `a` along the diagonal. · congr 2; ext i j rw [LinearMap.toMatrix_apply, ha, LinearEquiv.map_smul, Basis.repr_self, Finsupp.smul_single, smul_eq_mul, mul_one] by_cases h : i = j · rw [h, Matrix.diagonal_apply_eq, Finsupp.single_eq_same] · rw [Matrix.diagonal_apply_ne _ h, Finsupp.single_eq_of_ne (Ne.symm h)] -- Now we map everything through the linear equiv `S ≃ₗ (ι → ℤ)`, -- which maps `(S ⧸ I)` to `Π i, ZMod (a i).nat_abs`. haveI : ∀ i, NeZero (a i).natAbs := fun i => ⟨Int.natAbs_ne_zero.mpr (Ideal.smithCoeffs_ne_zero b I hI i)⟩ simp_rw [Nat.card_congr (Ideal.quotientEquivPiZMod I b hI).toEquiv, Nat.card_pi, Nat.card_zmod] /-- Let `b` be a basis for `S` over `ℤ` and `bI` a basis for `I` over `ℤ` of the same dimension. Then an alternative way to compute the norm of `I` is given by taking the determinant of `bI` over `b`. -/ theorem natAbs_det_basis_change {ι : Type*} [Fintype ι] [DecidableEq ι] (b : Basis ι ℤ S) (I : Ideal S) (bI : Basis ι ℤ I) : (b.det ((↑) ∘ bI)).natAbs = Ideal.absNorm I := by let e := b.equiv bI (Equiv.refl _) calc (b.det ((Submodule.subtype I).restrictScalars ℤ ∘ bI)).natAbs = (LinearMap.det ((Submodule.subtype I).restrictScalars ℤ ∘ₗ (e : S →ₗ[ℤ] I))).natAbs := by rw [Basis.det_comp_basis] _ = _ := natAbs_det_equiv I e @[simp] theorem absNorm_span_singleton (r : S) : absNorm (span ({r} : Set S)) = (Algebra.norm ℤ r).natAbs := by rw [Algebra.norm_apply] by_cases hr : r = 0 · simp only [hr, Ideal.span_zero, Algebra.coe_lmul_eq_mul, eq_self_iff_true, Ideal.absNorm_bot, LinearMap.det_zero'', Set.singleton_zero, _root_.map_zero, Int.natAbs_zero] letI := Ideal.fintypeQuotientOfFreeOfNeBot (span {r}) (mt span_singleton_eq_bot.mp hr) let b := Module.Free.chooseBasis ℤ S rw [← natAbs_det_equiv _ (b.equiv (basisSpanSingleton b hr) (Equiv.refl _))] congr refine b.ext fun i => ?_ simp theorem absNorm_dvd_norm_of_mem {I : Ideal S} {x : S} (h : x ∈ I) : ↑(Ideal.absNorm I) ∣ Algebra.norm ℤ x := by rw [← Int.dvd_natAbs, ← absNorm_span_singleton x, Int.natCast_dvd_natCast] exact absNorm_dvd_absNorm_of_le ((span_singleton_le_iff_mem _).mpr h) @[simp] theorem absNorm_span_insert (r : S) (s : Set S) : absNorm (span (insert r s)) ∣ gcd (absNorm (span s)) (Algebra.norm ℤ r).natAbs := (dvd_gcd_iff _ _ _).mpr ⟨absNorm_dvd_absNorm_of_le (span_mono (Set.subset_insert _ _)), _root_.trans (absNorm_dvd_absNorm_of_le (span_mono (Set.singleton_subset_iff.mpr (Set.mem_insert _ _)))) (by rw [absNorm_span_singleton])⟩ theorem absNorm_eq_zero_iff {I : Ideal S} : Ideal.absNorm I = 0 ↔ I = ⊥ := by constructor · intro hI rw [← le_bot_iff] intros x hx rw [mem_bot, ← Algebra.norm_eq_zero_iff (R := ℤ), ← Int.natAbs_eq_zero, ← Ideal.absNorm_span_singleton, ← zero_dvd_iff, ← hI] apply Ideal.absNorm_dvd_absNorm_of_le rwa [Ideal.span_singleton_le_iff_mem] · rintro rfl exact absNorm_bot theorem absNorm_ne_zero_of_nonZeroDivisors (I : (Ideal S)⁰) : Ideal.absNorm (I : Ideal S) ≠ 0 := Ideal.absNorm_eq_zero_iff.not.mpr <| nonZeroDivisors.coe_ne_zero _ theorem finite_setOf_absNorm_eq [CharZero S] {n : ℕ} (hn : 0 < n) : {I : Ideal S | Ideal.absNorm I = n}.Finite := by let f := fun I : Ideal S => Ideal.map (Ideal.Quotient.mk (@Ideal.span S _ {↑n})) I refine @Set.Finite.of_finite_image _ _ _ f ?_ ?_ · suffices Finite (S ⧸ @Ideal.span S _ {↑n}) by let g := ((↑) : Ideal (S ⧸ @Ideal.span S _ {↑n}) → Set (S ⧸ @Ideal.span S _ {↑n})) refine @Set.Finite.of_finite_image _ _ _ g ?_ SetLike.coe_injective.injOn exact Set.Finite.subset (@Set.finite_univ _ (@Set.finite' _ this)) (Set.subset_univ _) rw [← absNorm_ne_zero_iff, absNorm_span_singleton] simpa only [Ne, Int.natAbs_eq_zero, Algebra.norm_eq_zero_iff, Nat.cast_eq_zero] using ne_of_gt hn · intro I hI J hJ h rw [← comap_map_mk (span_singleton_absNorm_le I), ← hI.symm, ← comap_map_mk (span_singleton_absNorm_le J), ← hJ.symm] congr theorem norm_dvd_iff {x : S} (hx : Prime (Algebra.norm ℤ x)) {y : ℤ} : Algebra.norm ℤ x ∣ y ↔ x ∣ y := by rw [← Ideal.mem_span_singleton (y := x), ← eq_intCast (algebraMap ℤ S), ← Ideal.mem_comap, ← Ideal.span_singleton_absNorm, Ideal.mem_span_singleton, Ideal.absNorm_span_singleton, Int.natAbs_dvd] rwa [Ideal.absNorm_span_singleton, ← Int.prime_iff_natAbs_prime] end Ideal end RingOfIntegers end abs_norm section SpanNorm namespace Ideal open Submodule variable (R : Type*) [CommRing R] {S : Type*} [CommRing S] [Algebra R S] /-- `Ideal.spanNorm R (I : Ideal S)` is the ideal generated by mapping `Algebra.norm R` over `I`. See also `Ideal.relNorm`. -/ def spanNorm (I : Ideal S) : Ideal R := Ideal.span (Algebra.norm R '' (I : Set S)) @[simp] theorem spanNorm_bot [Nontrivial S] [Module.Free R S] [Module.Finite R S] : spanNorm R (⊥ : Ideal S) = ⊥ := span_eq_bot.mpr fun x hx => by simpa using hx variable {R} @[simp] theorem spanNorm_eq_bot_iff [IsDomain R] [IsDomain S] [Module.Free R S] [Module.Finite R S] {I : Ideal S} : spanNorm R I = ⊥ ↔ I = ⊥ := by simp only [spanNorm, Ideal.span_eq_bot, Set.mem_image, SetLike.mem_coe, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂, Algebra.norm_eq_zero_iff_of_basis (Module.Free.chooseBasis R S), @eq_bot_iff _ _ _ I, SetLike.le_def] rfl variable (R) theorem norm_mem_spanNorm {I : Ideal S} (x : S) (hx : x ∈ I) : Algebra.norm R x ∈ I.spanNorm R := subset_span (Set.mem_image_of_mem _ hx) @[simp] theorem spanNorm_singleton {r : S} : spanNorm R (span ({r} : Set S)) = span {Algebra.norm R r} := le_antisymm (span_le.mpr fun x hx => mem_span_singleton.mpr (by obtain ⟨x, hx', rfl⟩ := (Set.mem_image _ _ _).mp hx exact map_dvd _ (mem_span_singleton.mp hx'))) ((span_singleton_le_iff_mem _).mpr (norm_mem_spanNorm _ _ (mem_span_singleton_self _))) @[simp] theorem spanNorm_top : spanNorm R (⊤ : Ideal S) = ⊤ := by -- Porting note: was -- simp [← Ideal.span_singleton_one] rw [← Ideal.span_singleton_one, spanNorm_singleton] simp theorem map_spanNorm (I : Ideal S) {T : Type*} [CommRing T] (f : R →+* T) : map f (spanNorm R I) = span (f ∘ Algebra.norm R '' (I : Set S)) := by rw [spanNorm, map_span, Set.image_image] -- Porting note: `Function.comp` reducibility rfl @[mono] theorem spanNorm_mono {I J : Ideal S} (h : I ≤ J) : spanNorm R I ≤ spanNorm R J := Ideal.span_mono (Set.monotone_image h) theorem spanNorm_localization (I : Ideal S) [Module.Finite R S] [Module.Free R S] (M : Submonoid R) {Rₘ : Type*} (Sₘ : Type*) [CommRing Rₘ] [Algebra R Rₘ] [CommRing Sₘ] [Algebra S Sₘ] [Algebra Rₘ Sₘ] [Algebra R Sₘ] [IsScalarTower R Rₘ Sₘ] [IsScalarTower R S Sₘ] [IsLocalization M Rₘ] [IsLocalization (Algebra.algebraMapSubmonoid S M) Sₘ] : spanNorm Rₘ (I.map (algebraMap S Sₘ)) = (spanNorm R I).map (algebraMap R Rₘ) := by cases subsingleton_or_nontrivial R · haveI := IsLocalization.unique R Rₘ M simp [eq_iff_true_of_subsingleton] let b := Module.Free.chooseBasis R S rw [map_spanNorm] refine span_eq_span (Set.image_subset_iff.mpr ?_) (Set.image_subset_iff.mpr ?_) · rintro a' ha' simp only [Set.mem_preimage, submodule_span_eq, ← map_spanNorm, SetLike.mem_coe, IsLocalization.mem_map_algebraMap_iff (Algebra.algebraMapSubmonoid S M) Sₘ, IsLocalization.mem_map_algebraMap_iff M Rₘ, Prod.exists] at ha' ⊢ obtain ⟨⟨a, ha⟩, ⟨_, ⟨s, hs, rfl⟩⟩, has⟩ := ha' refine ⟨⟨Algebra.norm R a, norm_mem_spanNorm _ _ ha⟩, ⟨s ^ Fintype.card (Module.Free.ChooseBasisIndex R S), pow_mem hs _⟩, ?_⟩ simp only [Submodule.coe_mk, Subtype.coe_mk, map_pow] at has ⊢ apply_fun Algebra.norm Rₘ at has rwa [_root_.map_mul, ← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R Rₘ, Algebra.norm_algebraMap_of_basis (b.localizationLocalization Rₘ M Sₘ), Algebra.norm_localization R M a] at has · intro a ha rw [Set.mem_preimage, Function.comp_apply, ← Algebra.norm_localization (Sₘ := Sₘ) R M a] exact subset_span (Set.mem_image_of_mem _ (mem_map_of_mem _ ha)) theorem spanNorm_mul_spanNorm_le (I J : Ideal S) : spanNorm R I * spanNorm R J ≤ spanNorm R (I * J) := by rw [spanNorm, spanNorm, spanNorm, Ideal.span_mul_span', ← Set.image_mul] refine Ideal.span_mono (Set.monotone_image ?_) rintro _ ⟨x, hxI, y, hyJ, rfl⟩ exact Ideal.mul_mem_mul hxI hyJ /-- This condition `eq_bot_or_top` is equivalent to being a field. However, `Ideal.spanNorm_mul_of_field` is harder to apply since we'd need to upgrade a `CommRing R` instance to a `Field R` instance. -/ theorem spanNorm_mul_of_bot_or_top [IsDomain R] [IsDomain S] [Module.Free R S] [Module.Finite R S] (eq_bot_or_top : ∀ I : Ideal R, I = ⊥ ∨ I = ⊤) (I J : Ideal S) : spanNorm R (I * J) = spanNorm R I * spanNorm R J := by refine le_antisymm ?_ (spanNorm_mul_spanNorm_le R _ _) cases' eq_bot_or_top (spanNorm R I) with hI hI · rw [hI, spanNorm_eq_bot_iff.mp hI, bot_mul, spanNorm_bot] exact bot_le rw [hI, Ideal.top_mul] cases' eq_bot_or_top (spanNorm R J) with hJ hJ · rw [hJ, spanNorm_eq_bot_iff.mp hJ, mul_bot, spanNorm_bot] rw [hJ] exact le_top @[simp] theorem spanNorm_mul_of_field {K : Type*} [Field K] [Algebra K S] [IsDomain S] [Module.Finite K S] (I J : Ideal S) : spanNorm K (I * J) = spanNorm K I * spanNorm K J := spanNorm_mul_of_bot_or_top K eq_bot_or_top I J variable [IsDomain R] [IsDomain S] [IsDedekindDomain R] [IsDedekindDomain S] variable [Module.Finite R S] [Module.Free R S] /-- Multiplicativity of `Ideal.spanNorm`. simp-normal form is `map_mul (Ideal.relNorm R)`. -/ theorem spanNorm_mul (I J : Ideal S) : spanNorm R (I * J) = spanNorm R I * spanNorm R J := by nontriviality R cases subsingleton_or_nontrivial S · have : ∀ I : Ideal S, I = ⊤ := fun I => Subsingleton.elim I ⊤ simp [this I, this J, this (I * J)] refine eq_of_localization_maximal ?_ intro P hP by_cases hP0 : P = ⊥ · subst hP0 rw [spanNorm_mul_of_bot_or_top] intro I refine or_iff_not_imp_right.mpr fun hI => ?_ exact (hP.eq_of_le hI bot_le).symm let P' := Algebra.algebraMapSubmonoid S P.primeCompl letI : Algebra (Localization.AtPrime P) (Localization P') := localizationAlgebra P.primeCompl S haveI : IsScalarTower R (Localization.AtPrime P) (Localization P') := IsScalarTower.of_algebraMap_eq (fun x => (IsLocalization.map_eq (T := P') (Q := Localization P') P.primeCompl.le_comap_map x).symm) have h : P' ≤ S⁰ := map_le_nonZeroDivisors_of_injective _ (NoZeroSMulDivisors.algebraMap_injective _ _) P.primeCompl_le_nonZeroDivisors haveI : IsDomain (Localization P') := IsLocalization.isDomain_localization h haveI : IsDedekindDomain (Localization P') := IsLocalization.isDedekindDomain S h _ letI := Classical.decEq (Ideal (Localization P')) haveI : IsPrincipalIdealRing (Localization P') := IsDedekindDomain.isPrincipalIdealRing_localization_over_prime S P hP0 rw [Ideal.map_mul, ← spanNorm_localization R I P.primeCompl (Localization P'), ← spanNorm_localization R J P.primeCompl (Localization P'), ← spanNorm_localization R (I * J) P.primeCompl (Localization P'), Ideal.map_mul, ← (I.map _).span_singleton_generator, ← (J.map _).span_singleton_generator, span_singleton_mul_span_singleton, spanNorm_singleton, spanNorm_singleton, spanNorm_singleton, span_singleton_mul_span_singleton, _root_.map_mul] /-- The relative norm `Ideal.relNorm R (I : Ideal S)`, where `R` and `S` are Dedekind domains, and `S` is an extension of `R` that is finite and free as a module. -/ def relNorm : Ideal S →*₀ Ideal R where toFun := spanNorm R map_zero' := spanNorm_bot R map_one' := by dsimp only; rw [one_eq_top, spanNorm_top R, one_eq_top] map_mul' := spanNorm_mul R theorem relNorm_apply (I : Ideal S) : relNorm R I = span (Algebra.norm R '' (I : Set S) : Set R) := rfl @[simp] theorem spanNorm_eq (I : Ideal S) : spanNorm R I = relNorm R I := rfl @[simp] theorem relNorm_bot : relNorm R (⊥ : Ideal S) = ⊥ := by simpa only [zero_eq_bot] using _root_.map_zero (relNorm R : Ideal S →*₀ _) @[simp] theorem relNorm_top : relNorm R (⊤ : Ideal S) = ⊤ := by simpa only [one_eq_top] using map_one (relNorm R : Ideal S →*₀ _) variable {R} @[simp] theorem relNorm_eq_bot_iff {I : Ideal S} : relNorm R I = ⊥ ↔ I = ⊥ := spanNorm_eq_bot_iff variable (R) theorem norm_mem_relNorm (I : Ideal S) {x : S} (hx : x ∈ I) : Algebra.norm R x ∈ relNorm R I := norm_mem_spanNorm R x hx @[simp] theorem relNorm_singleton (r : S) : relNorm R (span ({r} : Set S)) = span {Algebra.norm R r} := spanNorm_singleton R theorem map_relNorm (I : Ideal S) {T : Type*} [CommRing T] (f : R →+* T) : map f (relNorm R I) = span (f ∘ Algebra.norm R '' (I : Set S)) := map_spanNorm R I f @[mono] theorem relNorm_mono {I J : Ideal S} (h : I ≤ J) : relNorm R I ≤ relNorm R J := spanNorm_mono R h end Ideal end SpanNorm
RingTheory\Ideal\Operations.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.Algebra.Operations import Mathlib.Data.Fintype.Lattice import Mathlib.RingTheory.Coprime.Lemmas /-! # More operations on modules and ideals -/ assert_not_exists Basis -- See `RingTheory.Ideal.Basis` assert_not_exists Submodule.hasQuotient -- See `RingTheory.Ideal.QuotientOperations` universe u v w x open Pointwise namespace Submodule variable {R : Type u} {M : Type v} {M' F G : Type*} section CommSemiring variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid M'] [Module R M'] open Pointwise instance hasSMul' : SMul (Ideal R) (Submodule R M) := ⟨Submodule.map₂ (LinearMap.lsmul R M)⟩ /-- This duplicates the global `smul_eq_mul`, but doesn't have to unfold anywhere near as much to apply. -/ protected theorem _root_.Ideal.smul_eq_mul (I J : Ideal R) : I • J = I * J := rfl variable (R M) in /-- `Module.annihilator R M` is the ideal of all elements `r : R` such that `r • M = 0`. -/ def _root_.Module.annihilator : Ideal R := LinearMap.ker (LinearMap.lsmul R M) theorem _root_.Module.mem_annihilator {r} : r ∈ Module.annihilator R M ↔ ∀ m : M, r • m = 0 := ⟨fun h ↦ (congr($h ·)), (LinearMap.ext ·)⟩ theorem _root_.LinearMap.annihilator_le_of_injective (f : M →ₗ[R] M') (hf : Function.Injective f) : Module.annihilator R M' ≤ Module.annihilator R M := fun x h ↦ by rw [Module.mem_annihilator] at h ⊢; exact fun m ↦ hf (by rw [map_smul, h, f.map_zero]) theorem _root_.LinearMap.annihilator_le_of_surjective (f : M →ₗ[R] M') (hf : Function.Surjective f) : Module.annihilator R M ≤ Module.annihilator R M' := fun x h ↦ by rw [Module.mem_annihilator] at h ⊢ intro m; obtain ⟨m, rfl⟩ := hf m rw [← map_smul, h, f.map_zero] theorem _root_.LinearEquiv.annihilator_eq (e : M ≃ₗ[R] M') : Module.annihilator R M = Module.annihilator R M' := (e.annihilator_le_of_surjective e.surjective).antisymm (e.annihilator_le_of_injective e.injective) /-- `N.annihilator` is the ideal of all elements `r : R` such that `r • N = 0`. -/ abbrev annihilator (N : Submodule R M) : Ideal R := Module.annihilator R N theorem annihilator_top : (⊤ : Submodule R M).annihilator = Module.annihilator R M := topEquiv.annihilator_eq variable {I J : Ideal R} {N P : Submodule R M} theorem mem_annihilator {r} : r ∈ N.annihilator ↔ ∀ n ∈ N, r • n = (0 : M) := by simp_rw [annihilator, Module.mem_annihilator, Subtype.forall, Subtype.ext_iff]; rfl theorem mem_annihilator' {r} : r ∈ N.annihilator ↔ N ≤ comap (r • (LinearMap.id : M →ₗ[R] M)) ⊥ := mem_annihilator.trans ⟨fun H n hn => (mem_bot R).2 <| H n hn, fun H _ hn => (mem_bot R).1 <| H hn⟩ theorem mem_annihilator_span (s : Set M) (r : R) : r ∈ (Submodule.span R s).annihilator ↔ ∀ n : s, r • (n : M) = 0 := by rw [Submodule.mem_annihilator] constructor · intro h n exact h _ (Submodule.subset_span n.prop) · intro h n hn refine Submodule.span_induction hn ?_ ?_ ?_ ?_ · intro x hx exact h ⟨x, hx⟩ · exact smul_zero _ · intro x y hx hy rw [smul_add, hx, hy, zero_add] · intro a x hx rw [smul_comm, hx, smul_zero] theorem mem_annihilator_span_singleton (g : M) (r : R) : r ∈ (Submodule.span R ({g} : Set M)).annihilator ↔ r • g = 0 := by simp [mem_annihilator_span] theorem annihilator_bot : (⊥ : Submodule R M).annihilator = ⊤ := (Ideal.eq_top_iff_one _).2 <| mem_annihilator'.2 bot_le theorem annihilator_eq_top_iff : N.annihilator = ⊤ ↔ N = ⊥ := ⟨fun H => eq_bot_iff.2 fun (n : M) hn => (mem_bot R).2 <| one_smul R n ▸ mem_annihilator.1 ((Ideal.eq_top_iff_one _).1 H) n hn, fun H => H.symm ▸ annihilator_bot⟩ theorem annihilator_mono (h : N ≤ P) : P.annihilator ≤ N.annihilator := fun _ hrp => mem_annihilator.2 fun n hn => mem_annihilator.1 hrp n <| h hn theorem annihilator_iSup (ι : Sort w) (f : ι → Submodule R M) : annihilator (⨆ i, f i) = ⨅ i, annihilator (f i) := le_antisymm (le_iInf fun _ => annihilator_mono <| le_iSup _ _) fun _ H => mem_annihilator'.2 <| iSup_le fun i => have := (mem_iInf _).1 H i mem_annihilator'.1 this theorem smul_mem_smul {r} {n} (hr : r ∈ I) (hn : n ∈ N) : r • n ∈ I • N := apply_mem_map₂ _ hr hn theorem smul_le {P : Submodule R M} : I • N ≤ P ↔ ∀ r ∈ I, ∀ n ∈ N, r • n ∈ P := map₂_le @[simp, norm_cast] lemma coe_set_smul : (I : Set R) • N = I • N := Submodule.set_smul_eq_of_le _ _ _ (fun _ _ hr hx => smul_mem_smul hr hx) (smul_le.mpr fun _ hr _ hx => mem_set_smul_of_mem_mem hr hx) @[elab_as_elim] theorem smul_induction_on {p : M → Prop} {x} (H : x ∈ I • N) (smul : ∀ r ∈ I, ∀ n ∈ N, p (r • n)) (add : ∀ x y, p x → p y → p (x + y)) : p x := by have H0 : p 0 := by simpa only [zero_smul] using smul 0 I.zero_mem 0 N.zero_mem refine Submodule.iSup_induction (x := x) _ H ?_ H0 add rintro ⟨i, hi⟩ m ⟨j, hj, hj'⟩ rw [← hj'] exact smul _ hi _ hj /-- Dependent version of `Submodule.smul_induction_on`. -/ @[elab_as_elim] theorem smul_induction_on' {x : M} (hx : x ∈ I • N) {p : ∀ x, x ∈ I • N → Prop} (smul : ∀ (r : R) (hr : r ∈ I) (n : M) (hn : n ∈ N), p (r • n) (smul_mem_smul hr hn)) (add : ∀ x hx y hy, p x hx → p y hy → p (x + y) (Submodule.add_mem _ ‹_› ‹_›)) : p x hx := by refine Exists.elim ?_ fun (h : x ∈ I • N) (H : p x h) => H exact smul_induction_on hx (fun a ha x hx => ⟨_, smul _ ha _ hx⟩) fun x y ⟨_, hx⟩ ⟨_, hy⟩ => ⟨_, add _ _ _ _ hx hy⟩ theorem mem_smul_span_singleton {I : Ideal R} {m : M} {x : M} : x ∈ I • span R ({m} : Set M) ↔ ∃ y ∈ I, y • m = x := ⟨fun hx => smul_induction_on hx (fun r hri n hnm => let ⟨s, hs⟩ := mem_span_singleton.1 hnm ⟨r * s, I.mul_mem_right _ hri, hs ▸ mul_smul r s m⟩) fun m1 m2 ⟨y1, hyi1, hy1⟩ ⟨y2, hyi2, hy2⟩ => ⟨y1 + y2, I.add_mem hyi1 hyi2, by rw [add_smul, hy1, hy2]⟩, fun ⟨y, hyi, hy⟩ => hy ▸ smul_mem_smul hyi (subset_span <| Set.mem_singleton m)⟩ theorem smul_le_right : I • N ≤ N := smul_le.2 fun r _ _ => N.smul_mem r theorem smul_mono (hij : I ≤ J) (hnp : N ≤ P) : I • N ≤ J • P := map₂_le_map₂ hij hnp theorem smul_mono_left (h : I ≤ J) : I • N ≤ J • N := map₂_le_map₂_left h instance : CovariantClass (Ideal R) (Submodule R M) HSMul.hSMul LE.le := ⟨fun _ _ => map₂_le_map₂_right⟩ @[deprecated smul_mono_right (since := "2024-03-31")] protected theorem smul_mono_right (h : N ≤ P) : I • N ≤ I • P := _root_.smul_mono_right I h theorem map_le_smul_top (I : Ideal R) (f : R →ₗ[R] M) : Submodule.map f I ≤ I • (⊤ : Submodule R M) := by rintro _ ⟨y, hy, rfl⟩ rw [← mul_one y, ← smul_eq_mul, f.map_smul] exact smul_mem_smul hy mem_top @[simp] theorem annihilator_smul (N : Submodule R M) : annihilator N • N = ⊥ := eq_bot_iff.2 (smul_le.2 fun _ => mem_annihilator.1) @[simp] theorem annihilator_mul (I : Ideal R) : annihilator I * I = ⊥ := annihilator_smul I @[simp] theorem mul_annihilator (I : Ideal R) : I * annihilator I = ⊥ := by rw [mul_comm, annihilator_mul] variable (I J N P) @[simp] theorem smul_bot : I • (⊥ : Submodule R M) = ⊥ := map₂_bot_right _ _ @[simp] theorem bot_smul : (⊥ : Ideal R) • N = ⊥ := map₂_bot_left _ _ @[simp] theorem top_smul : (⊤ : Ideal R) • N = N := le_antisymm smul_le_right fun r hri => one_smul R r ▸ smul_mem_smul mem_top hri theorem smul_sup : I • (N ⊔ P) = I • N ⊔ I • P := map₂_sup_right _ _ _ _ theorem sup_smul : (I ⊔ J) • N = I • N ⊔ J • N := map₂_sup_left _ _ _ _ protected theorem smul_assoc : (I • J) • N = I • J • N := le_antisymm (smul_le.2 fun _ hrsij t htn => smul_induction_on hrsij (fun r hr s hs => (@smul_eq_mul R _ r s).symm ▸ smul_smul r s t ▸ smul_mem_smul hr (smul_mem_smul hs htn)) fun x y => (add_smul x y t).symm ▸ Submodule.add_mem _) (smul_le.2 fun r hr _ hsn => suffices J • N ≤ Submodule.comap (r • (LinearMap.id : M →ₗ[R] M)) ((I • J) • N) from this hsn smul_le.2 fun s hs n hn => show r • s • n ∈ (I • J) • N from mul_smul r s n ▸ smul_mem_smul (smul_mem_smul hr hs) hn) @[deprecated smul_inf_le (since := "2024-03-31")] protected theorem smul_inf_le (M₁ M₂ : Submodule R M) : I • (M₁ ⊓ M₂) ≤ I • M₁ ⊓ I • M₂ := smul_inf_le _ _ _ theorem smul_iSup {ι : Sort*} {I : Ideal R} {t : ι → Submodule R M} : I • iSup t = ⨆ i, I • t i := map₂_iSup_right _ _ _ @[deprecated smul_iInf_le (since := "2024-03-31")] protected theorem smul_iInf_le {ι : Sort*} {I : Ideal R} {t : ι → Submodule R M} : I • iInf t ≤ ⨅ i, I • t i := smul_iInf_le variable (S : Set R) (T : Set M) theorem span_smul_span : Ideal.span S • span R T = span R (⋃ (s ∈ S) (t ∈ T), {s • t}) := (map₂_span_span _ _ _ _).trans <| congr_arg _ <| Set.image2_eq_iUnion _ _ _ theorem ideal_span_singleton_smul (r : R) (N : Submodule R M) : (Ideal.span {r} : Ideal R) • N = r • N := by have : span R (⋃ (t : M) (_ : t ∈ N), {r • t}) = r • N := by convert span_eq (r • N) exact (Set.image_eq_iUnion _ (N : Set M)).symm conv_lhs => rw [← span_eq N, span_smul_span] simpa theorem mem_of_span_top_of_smul_mem (M' : Submodule R M) (s : Set R) (hs : Ideal.span s = ⊤) (x : M) (H : ∀ r : s, (r : R) • x ∈ M') : x ∈ M' := by suffices (⊤ : Ideal R) • span R ({x} : Set M) ≤ M' by rw [top_smul] at this exact this (subset_span (Set.mem_singleton x)) rw [← hs, span_smul_span, span_le] simpa using H /-- Given `s`, a generating set of `R`, to check that an `x : M` falls in a submodule `M'` of `x`, we only need to show that `r ^ n • x ∈ M'` for some `n` for each `r : s`. -/ theorem mem_of_span_eq_top_of_smul_pow_mem (M' : Submodule R M) (s : Set R) (hs : Ideal.span s = ⊤) (x : M) (H : ∀ r : s, ∃ n : ℕ, ((r : R) ^ n : R) • x ∈ M') : x ∈ M' := by obtain ⟨s', hs₁, hs₂⟩ := (Ideal.span_eq_top_iff_finite _).mp hs replace H : ∀ r : s', ∃ n : ℕ, ((r : R) ^ n : R) • x ∈ M' := fun r => H ⟨_, hs₁ r.2⟩ choose n₁ n₂ using H let N := s'.attach.sup n₁ have hs' := Ideal.span_pow_eq_top (s' : Set R) hs₂ N apply M'.mem_of_span_top_of_smul_mem _ hs' rintro ⟨_, r, hr, rfl⟩ convert M'.smul_mem (r ^ (N - n₁ ⟨r, hr⟩)) (n₂ ⟨r, hr⟩) using 1 simp only [Subtype.coe_mk, smul_smul, ← pow_add] rw [tsub_add_cancel_of_le (Finset.le_sup (s'.mem_attach _) : n₁ ⟨r, hr⟩ ≤ N)] variable {M' : Type w} [AddCommMonoid M'] [Module R M'] @[simp] theorem map_smul'' (f : M →ₗ[R] M') : (I • N).map f = I • N.map f := le_antisymm (map_le_iff_le_comap.2 <| smul_le.2 fun r hr n hn => show f (r • n) ∈ I • N.map f from (f.map_smul r n).symm ▸ smul_mem_smul hr (mem_map_of_mem hn)) <| smul_le.2 fun r hr _ hn => let ⟨p, hp, hfp⟩ := mem_map.1 hn hfp ▸ f.map_smul r p ▸ mem_map_of_mem (smul_mem_smul hr hp) open Pointwise in @[simp] theorem map_pointwise_smul (r : R) (N : Submodule R M) (f : M →ₗ[R] M') : (r • N).map f = r • N.map f := by simp_rw [← ideal_span_singleton_smul, map_smul''] variable {I} theorem mem_smul_span {s : Set M} {x : M} : x ∈ I • Submodule.span R s ↔ x ∈ Submodule.span R (⋃ (a ∈ I) (b ∈ s), ({a • b} : Set M)) := by rw [← I.span_eq, Submodule.span_smul_span, I.span_eq] rfl variable (I) /-- If `x` is an `I`-multiple of the submodule spanned by `f '' s`, then we can write `x` as an `I`-linear combination of the elements of `f '' s`. -/ theorem mem_ideal_smul_span_iff_exists_sum {ι : Type*} (f : ι → M) (x : M) : x ∈ I • span R (Set.range f) ↔ ∃ (a : ι →₀ R) (_ : ∀ i, a i ∈ I), (a.sum fun i c => c • f i) = x := by constructor; swap · rintro ⟨a, ha, rfl⟩ exact Submodule.sum_mem _ fun c _ => smul_mem_smul (ha c) <| subset_span <| Set.mem_range_self _ refine fun hx => span_induction (mem_smul_span.mp hx) ?_ ?_ ?_ ?_ · simp only [Set.mem_iUnion, Set.mem_range, Set.mem_singleton_iff] rintro x ⟨y, hy, x, ⟨i, rfl⟩, rfl⟩ refine ⟨Finsupp.single i y, fun j => ?_, ?_⟩ · letI := Classical.decEq ι rw [Finsupp.single_apply] split_ifs · assumption · exact I.zero_mem refine @Finsupp.sum_single_index ι R M _ _ i _ (fun i y => y • f i) ?_ simp · exact ⟨0, fun _ => I.zero_mem, Finsupp.sum_zero_index⟩ · rintro x y ⟨ax, hax, rfl⟩ ⟨ay, hay, rfl⟩ refine ⟨ax + ay, fun i => I.add_mem (hax i) (hay i), Finsupp.sum_add_index' ?_ ?_⟩ <;> intros <;> simp only [zero_smul, add_smul] · rintro c x ⟨a, ha, rfl⟩ refine ⟨c • a, fun i => I.mul_mem_left c (ha i), ?_⟩ rw [Finsupp.sum_smul_index, Finsupp.smul_sum] <;> intros <;> simp only [zero_smul, mul_smul] theorem mem_ideal_smul_span_iff_exists_sum' {ι : Type*} (s : Set ι) (f : ι → M) (x : M) : x ∈ I • span R (f '' s) ↔ ∃ (a : s →₀ R) (_ : ∀ i, a i ∈ I), (a.sum fun i c => c • f i) = x := by rw [← Submodule.mem_ideal_smul_span_iff_exists_sum, ← Set.image_eq_range] theorem mem_smul_top_iff (N : Submodule R M) (x : N) : x ∈ I • (⊤ : Submodule R N) ↔ (x : M) ∈ I • N := by change _ ↔ N.subtype x ∈ I • N have : Submodule.map N.subtype (I • ⊤) = I • N := by rw [Submodule.map_smul'', Submodule.map_top, Submodule.range_subtype] rw [← this] exact (Function.Injective.mem_set_image N.injective_subtype).symm @[simp] theorem smul_comap_le_comap_smul (f : M →ₗ[R] M') (S : Submodule R M') (I : Ideal R) : I • S.comap f ≤ (I • S).comap f := by refine Submodule.smul_le.mpr fun r hr x hx => ?_ rw [Submodule.mem_comap] at hx ⊢ rw [f.map_smul] exact Submodule.smul_mem_smul hr hx end CommSemiring end Submodule namespace Ideal section Add variable {R : Type u} [Semiring R] @[simp] theorem add_eq_sup {I J : Ideal R} : I + J = I ⊔ J := rfl -- dsimp loops when applying this lemma to its LHS, -- probably https://github.com/leanprover/lean4/pull/2867 @[simp, nolint simpNF] theorem zero_eq_bot : (0 : Ideal R) = ⊥ := rfl @[simp] theorem sum_eq_sup {ι : Type*} (s : Finset ι) (f : ι → Ideal R) : s.sum f = s.sup f := rfl end Add section MulAndRadical variable {R : Type u} {ι : Type*} [CommSemiring R] variable {I J K L : Ideal R} instance : Mul (Ideal R) := ⟨(· • ·)⟩ @[simp] theorem one_eq_top : (1 : Ideal R) = ⊤ := by erw [Submodule.one_eq_range, LinearMap.range_id] theorem add_eq_one_iff : I + J = 1 ↔ ∃ i ∈ I, ∃ j ∈ J, i + j = 1 := by rw [one_eq_top, eq_top_iff_one, add_eq_sup, Submodule.mem_sup] theorem mul_mem_mul {r s} (hr : r ∈ I) (hs : s ∈ J) : r * s ∈ I * J := Submodule.smul_mem_smul hr hs theorem mul_mem_mul_rev {r s} (hr : r ∈ I) (hs : s ∈ J) : s * r ∈ I * J := mul_comm r s ▸ mul_mem_mul hr hs theorem pow_mem_pow {x : R} (hx : x ∈ I) (n : ℕ) : x ^ n ∈ I ^ n := Submodule.pow_mem_pow _ hx _ theorem prod_mem_prod {ι : Type*} {s : Finset ι} {I : ι → Ideal R} {x : ι → R} : (∀ i ∈ s, x i ∈ I i) → (∏ i ∈ s, x i) ∈ ∏ i ∈ s, I i := by classical refine Finset.induction_on s ?_ ?_ · intro rw [Finset.prod_empty, Finset.prod_empty, one_eq_top] exact Submodule.mem_top · intro a s ha IH h rw [Finset.prod_insert ha, Finset.prod_insert ha] exact mul_mem_mul (h a <| Finset.mem_insert_self a s) (IH fun i hi => h i <| Finset.mem_insert_of_mem hi) theorem mul_le : I * J ≤ K ↔ ∀ r ∈ I, ∀ s ∈ J, r * s ∈ K := Submodule.smul_le theorem mul_le_left : I * J ≤ J := Ideal.mul_le.2 fun _ _ _ => J.mul_mem_left _ theorem mul_le_right : I * J ≤ I := Ideal.mul_le.2 fun _ hr _ _ => I.mul_mem_right _ hr @[simp] theorem sup_mul_right_self : I ⊔ I * J = I := sup_eq_left.2 Ideal.mul_le_right @[simp] theorem sup_mul_left_self : I ⊔ J * I = I := sup_eq_left.2 Ideal.mul_le_left @[simp] theorem mul_right_self_sup : I * J ⊔ I = I := sup_eq_right.2 Ideal.mul_le_right @[simp] theorem mul_left_self_sup : J * I ⊔ I = I := sup_eq_right.2 Ideal.mul_le_left variable (I J K) protected theorem mul_comm : I * J = J * I := le_antisymm (mul_le.2 fun _ hrI _ hsJ => mul_mem_mul_rev hsJ hrI) (mul_le.2 fun _ hrJ _ hsI => mul_mem_mul_rev hsI hrJ) protected theorem mul_assoc : I * J * K = I * (J * K) := Submodule.smul_assoc I J K theorem span_mul_span (S T : Set R) : span S * span T = span (⋃ (s ∈ S) (t ∈ T), {s * t}) := Submodule.span_smul_span S T variable {I J K} theorem span_mul_span' (S T : Set R) : span S * span T = span (S * T) := by unfold span rw [Submodule.span_mul_span] theorem span_singleton_mul_span_singleton (r s : R) : span {r} * span {s} = (span {r * s} : Ideal R) := by unfold span rw [Submodule.span_mul_span, Set.singleton_mul_singleton] theorem span_singleton_pow (s : R) (n : ℕ) : span {s} ^ n = (span {s ^ n} : Ideal R) := by induction' n with n ih; · simp [Set.singleton_one] simp only [pow_succ, ih, span_singleton_mul_span_singleton] theorem mem_mul_span_singleton {x y : R} {I : Ideal R} : x ∈ I * span {y} ↔ ∃ z ∈ I, z * y = x := Submodule.mem_smul_span_singleton theorem mem_span_singleton_mul {x y : R} {I : Ideal R} : x ∈ span {y} * I ↔ ∃ z ∈ I, y * z = x := by simp only [mul_comm, mem_mul_span_singleton] theorem le_span_singleton_mul_iff {x : R} {I J : Ideal R} : I ≤ span {x} * J ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI := show (∀ {zI} (_ : zI ∈ I), zI ∈ span {x} * J) ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI by simp only [mem_span_singleton_mul] theorem span_singleton_mul_le_iff {x : R} {I J : Ideal R} : span {x} * I ≤ J ↔ ∀ z ∈ I, x * z ∈ J := by simp only [mul_le, mem_span_singleton_mul, mem_span_singleton] constructor · intro h zI hzI exact h x (dvd_refl x) zI hzI · rintro h _ ⟨z, rfl⟩ zI hzI rw [mul_comm x z, mul_assoc] exact J.mul_mem_left _ (h zI hzI) theorem span_singleton_mul_le_span_singleton_mul {x y : R} {I J : Ideal R} : span {x} * I ≤ span {y} * J ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zI = y * zJ := by simp only [span_singleton_mul_le_iff, mem_span_singleton_mul, eq_comm] theorem span_singleton_mul_right_mono [IsDomain R] {x : R} (hx : x ≠ 0) : span {x} * I ≤ span {x} * J ↔ I ≤ J := by simp_rw [span_singleton_mul_le_span_singleton_mul, mul_right_inj' hx, exists_eq_right', SetLike.le_def] theorem span_singleton_mul_left_mono [IsDomain R] {x : R} (hx : x ≠ 0) : I * span {x} ≤ J * span {x} ↔ I ≤ J := by simpa only [mul_comm I, mul_comm J] using span_singleton_mul_right_mono hx theorem span_singleton_mul_right_inj [IsDomain R] {x : R} (hx : x ≠ 0) : span {x} * I = span {x} * J ↔ I = J := by simp only [le_antisymm_iff, span_singleton_mul_right_mono hx] theorem span_singleton_mul_left_inj [IsDomain R] {x : R} (hx : x ≠ 0) : I * span {x} = J * span {x} ↔ I = J := by simp only [le_antisymm_iff, span_singleton_mul_left_mono hx] theorem span_singleton_mul_right_injective [IsDomain R] {x : R} (hx : x ≠ 0) : Function.Injective ((span {x} : Ideal R) * ·) := fun _ _ => (span_singleton_mul_right_inj hx).mp theorem span_singleton_mul_left_injective [IsDomain R] {x : R} (hx : x ≠ 0) : Function.Injective fun I : Ideal R => I * span {x} := fun _ _ => (span_singleton_mul_left_inj hx).mp theorem eq_span_singleton_mul {x : R} (I J : Ideal R) : I = span {x} * J ↔ (∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI) ∧ ∀ z ∈ J, x * z ∈ I := by simp only [le_antisymm_iff, le_span_singleton_mul_iff, span_singleton_mul_le_iff] theorem span_singleton_mul_eq_span_singleton_mul {x y : R} (I J : Ideal R) : span {x} * I = span {y} * J ↔ (∀ zI ∈ I, ∃ zJ ∈ J, x * zI = y * zJ) ∧ ∀ zJ ∈ J, ∃ zI ∈ I, x * zI = y * zJ := by simp only [le_antisymm_iff, span_singleton_mul_le_span_singleton_mul, eq_comm] theorem prod_span {ι : Type*} (s : Finset ι) (I : ι → Set R) : (∏ i ∈ s, Ideal.span (I i)) = Ideal.span (∏ i ∈ s, I i) := Submodule.prod_span s I theorem prod_span_singleton {ι : Type*} (s : Finset ι) (I : ι → R) : (∏ i ∈ s, Ideal.span ({I i} : Set R)) = Ideal.span {∏ i ∈ s, I i} := Submodule.prod_span_singleton s I @[simp] theorem multiset_prod_span_singleton (m : Multiset R) : (m.map fun x => Ideal.span {x}).prod = Ideal.span ({Multiset.prod m} : Set R) := Multiset.induction_on m (by simp) fun a m ih => by simp only [Multiset.map_cons, Multiset.prod_cons, ih, ← Ideal.span_singleton_mul_span_singleton] theorem finset_inf_span_singleton {ι : Type*} (s : Finset ι) (I : ι → R) (hI : Set.Pairwise (↑s) (IsCoprime on I)) : (s.inf fun i => Ideal.span ({I i} : Set R)) = Ideal.span {∏ i ∈ s, I i} := by ext x simp only [Submodule.mem_finset_inf, Ideal.mem_span_singleton] exact ⟨Finset.prod_dvd_of_coprime hI, fun h i hi => (Finset.dvd_prod_of_mem _ hi).trans h⟩ theorem iInf_span_singleton {ι : Type*} [Fintype ι] {I : ι → R} (hI : ∀ (i j) (_ : i ≠ j), IsCoprime (I i) (I j)) : ⨅ i, span ({I i} : Set R) = span {∏ i, I i} := by rw [← Finset.inf_univ_eq_iInf, finset_inf_span_singleton] rwa [Finset.coe_univ, Set.pairwise_univ] theorem iInf_span_singleton_natCast {R : Type*} [CommRing R] {ι : Type*} [Fintype ι] {I : ι → ℕ} (hI : Pairwise fun i j => (I i).Coprime (I j)) : ⨅ (i : ι), span {(I i : R)} = span {((∏ i : ι, I i : ℕ) : R)} := by rw [iInf_span_singleton, Nat.cast_prod] exact fun i j h ↦ (hI h).cast theorem sup_eq_top_iff_isCoprime {R : Type*} [CommSemiring R] (x y : R) : span ({x} : Set R) ⊔ span {y} = ⊤ ↔ IsCoprime x y := by rw [eq_top_iff_one, Submodule.mem_sup] constructor · rintro ⟨u, hu, v, hv, h1⟩ rw [mem_span_singleton'] at hu hv rw [← hu.choose_spec, ← hv.choose_spec] at h1 exact ⟨_, _, h1⟩ · exact fun ⟨u, v, h1⟩ => ⟨_, mem_span_singleton'.mpr ⟨_, rfl⟩, _, mem_span_singleton'.mpr ⟨_, rfl⟩, h1⟩ theorem mul_le_inf : I * J ≤ I ⊓ J := mul_le.2 fun r hri s hsj => ⟨I.mul_mem_right s hri, J.mul_mem_left r hsj⟩ theorem multiset_prod_le_inf {s : Multiset (Ideal R)} : s.prod ≤ s.inf := by classical refine s.induction_on ?_ ?_ · rw [Multiset.inf_zero] exact le_top intro a s ih rw [Multiset.prod_cons, Multiset.inf_cons] exact le_trans mul_le_inf (inf_le_inf le_rfl ih) theorem prod_le_inf {s : Finset ι} {f : ι → Ideal R} : s.prod f ≤ s.inf f := multiset_prod_le_inf theorem mul_eq_inf_of_coprime (h : I ⊔ J = ⊤) : I * J = I ⊓ J := le_antisymm mul_le_inf fun r ⟨hri, hrj⟩ => let ⟨s, hsi, t, htj, hst⟩ := Submodule.mem_sup.1 ((eq_top_iff_one _).1 h) mul_one r ▸ hst ▸ (mul_add r s t).symm ▸ Ideal.add_mem (I * J) (mul_mem_mul_rev hsi hrj) (mul_mem_mul hri htj) theorem sup_mul_eq_of_coprime_left (h : I ⊔ J = ⊤) : I ⊔ J * K = I ⊔ K := le_antisymm (sup_le_sup_left mul_le_left _) fun i hi => by rw [eq_top_iff_one] at h; rw [Submodule.mem_sup] at h hi ⊢ obtain ⟨i1, hi1, j, hj, h⟩ := h; obtain ⟨i', hi', k, hk, hi⟩ := hi refine ⟨_, add_mem hi' (mul_mem_right k _ hi1), _, mul_mem_mul hj hk, ?_⟩ rw [add_assoc, ← add_mul, h, one_mul, hi] theorem sup_mul_eq_of_coprime_right (h : I ⊔ K = ⊤) : I ⊔ J * K = I ⊔ J := by rw [mul_comm] exact sup_mul_eq_of_coprime_left h theorem mul_sup_eq_of_coprime_left (h : I ⊔ J = ⊤) : I * K ⊔ J = K ⊔ J := by rw [sup_comm] at h rw [sup_comm, sup_mul_eq_of_coprime_left h, sup_comm] theorem mul_sup_eq_of_coprime_right (h : K ⊔ J = ⊤) : I * K ⊔ J = I ⊔ J := by rw [sup_comm] at h rw [sup_comm, sup_mul_eq_of_coprime_right h, sup_comm] theorem sup_prod_eq_top {s : Finset ι} {J : ι → Ideal R} (h : ∀ i, i ∈ s → I ⊔ J i = ⊤) : (I ⊔ ∏ i ∈ s, J i) = ⊤ := Finset.prod_induction _ (fun J => I ⊔ J = ⊤) (fun J K hJ hK => (sup_mul_eq_of_coprime_left hJ).trans hK) (by simp_rw [one_eq_top, sup_top_eq]) h theorem sup_iInf_eq_top {s : Finset ι} {J : ι → Ideal R} (h : ∀ i, i ∈ s → I ⊔ J i = ⊤) : (I ⊔ ⨅ i ∈ s, J i) = ⊤ := eq_top_iff.mpr <| le_of_eq_of_le (sup_prod_eq_top h).symm <| sup_le_sup_left (le_of_le_of_eq prod_le_inf <| Finset.inf_eq_iInf _ _) _ theorem prod_sup_eq_top {s : Finset ι} {J : ι → Ideal R} (h : ∀ i, i ∈ s → J i ⊔ I = ⊤) : (∏ i ∈ s, J i) ⊔ I = ⊤ := by rw [sup_comm, sup_prod_eq_top]; intro i hi; rw [sup_comm, h i hi] theorem iInf_sup_eq_top {s : Finset ι} {J : ι → Ideal R} (h : ∀ i, i ∈ s → J i ⊔ I = ⊤) : (⨅ i ∈ s, J i) ⊔ I = ⊤ := by rw [sup_comm, sup_iInf_eq_top]; intro i hi; rw [sup_comm, h i hi] theorem sup_pow_eq_top {n : ℕ} (h : I ⊔ J = ⊤) : I ⊔ J ^ n = ⊤ := by rw [← Finset.card_range n, ← Finset.prod_const] exact sup_prod_eq_top fun _ _ => h theorem pow_sup_eq_top {n : ℕ} (h : I ⊔ J = ⊤) : I ^ n ⊔ J = ⊤ := by rw [← Finset.card_range n, ← Finset.prod_const] exact prod_sup_eq_top fun _ _ => h theorem pow_sup_pow_eq_top {m n : ℕ} (h : I ⊔ J = ⊤) : I ^ m ⊔ J ^ n = ⊤ := sup_pow_eq_top (pow_sup_eq_top h) variable (I) -- @[simp] -- Porting note (#10618): simp can prove this theorem mul_bot : I * ⊥ = ⊥ := by simp -- @[simp] -- Porting note (#10618): simp can prove thisrove this theorem bot_mul : ⊥ * I = ⊥ := by simp @[simp] theorem mul_top : I * ⊤ = I := Ideal.mul_comm ⊤ I ▸ Submodule.top_smul I @[simp] theorem top_mul : ⊤ * I = I := Submodule.top_smul I variable {I} theorem mul_mono (hik : I ≤ K) (hjl : J ≤ L) : I * J ≤ K * L := Submodule.smul_mono hik hjl theorem mul_mono_left (h : I ≤ J) : I * K ≤ J * K := Submodule.smul_mono_left h theorem mul_mono_right (h : J ≤ K) : I * J ≤ I * K := smul_mono_right _ h variable (I J K) theorem mul_sup : I * (J ⊔ K) = I * J ⊔ I * K := Submodule.smul_sup I J K theorem sup_mul : (I ⊔ J) * K = I * K ⊔ J * K := Submodule.sup_smul I J K variable {I J K} theorem pow_le_pow_right {m n : ℕ} (h : m ≤ n) : I ^ n ≤ I ^ m := by cases' Nat.exists_eq_add_of_le h with k hk rw [hk, pow_add] exact le_trans mul_le_inf inf_le_left theorem pow_le_self {n : ℕ} (hn : n ≠ 0) : I ^ n ≤ I := calc I ^ n ≤ I ^ 1 := pow_le_pow_right (Nat.pos_of_ne_zero hn) _ = I := pow_one _ theorem pow_right_mono {I J : Ideal R} (e : I ≤ J) (n : ℕ) : I ^ n ≤ J ^ n := by induction' n with _ hn · rw [pow_zero, pow_zero] · rw [pow_succ, pow_succ] exact Ideal.mul_mono hn e @[simp] theorem mul_eq_bot {R : Type*} [CommSemiring R] [NoZeroDivisors R] {I J : Ideal R} : I * J = ⊥ ↔ I = ⊥ ∨ J = ⊥ := ⟨fun hij => or_iff_not_imp_left.mpr fun I_ne_bot => J.eq_bot_iff.mpr fun j hj => let ⟨i, hi, ne0⟩ := I.ne_bot_iff.mp I_ne_bot Or.resolve_left (mul_eq_zero.mp ((I * J).eq_bot_iff.mp hij _ (mul_mem_mul hi hj))) ne0, fun h => by cases' h with h h <;> rw [← Ideal.mul_bot, h, Ideal.mul_comm]⟩ instance {R : Type*} [CommSemiring R] [NoZeroDivisors R] : NoZeroDivisors (Ideal R) where eq_zero_or_eq_zero_of_mul_eq_zero := mul_eq_bot.1 instance {R : Type*} [CommSemiring R] {S : Type*} [CommRing S] [Algebra R S] [NoZeroSMulDivisors R S] {I : Ideal S} : NoZeroSMulDivisors R I := Submodule.noZeroSMulDivisors (Submodule.restrictScalars R I) /-- A product of ideals in an integral domain is zero if and only if one of the terms is zero. -/ @[simp] lemma multiset_prod_eq_bot {R : Type*} [CommRing R] [IsDomain R] {s : Multiset (Ideal R)} : s.prod = ⊥ ↔ ⊥ ∈ s := Multiset.prod_eq_zero_iff /-- A product of ideals in an integral domain is zero if and only if one of the terms is zero. -/ @[deprecated multiset_prod_eq_bot (since := "2023-12-26")] theorem prod_eq_bot {R : Type*} [CommRing R] [IsDomain R] {s : Multiset (Ideal R)} : s.prod = ⊥ ↔ ∃ I ∈ s, I = ⊥ := by simp theorem span_pair_mul_span_pair (w x y z : R) : (span {w, x} : Ideal R) * span {y, z} = span {w * y, w * z, x * y, x * z} := by simp_rw [span_insert, sup_mul, mul_sup, span_singleton_mul_span_singleton, sup_assoc] theorem isCoprime_iff_codisjoint : IsCoprime I J ↔ Codisjoint I J := by rw [IsCoprime, codisjoint_iff] constructor · rintro ⟨x, y, hxy⟩ rw [eq_top_iff_one] apply (show x * I + y * J ≤ I ⊔ J from sup_le (mul_le_left.trans le_sup_left) (mul_le_left.trans le_sup_right)) rw [hxy] simp only [one_eq_top, Submodule.mem_top] · intro h refine ⟨1, 1, ?_⟩ simpa only [one_eq_top, top_mul, Submodule.add_eq_sup] theorem isCoprime_iff_add : IsCoprime I J ↔ I + J = 1 := by rw [isCoprime_iff_codisjoint, codisjoint_iff, add_eq_sup, one_eq_top] theorem isCoprime_iff_exists : IsCoprime I J ↔ ∃ i ∈ I, ∃ j ∈ J, i + j = 1 := by rw [← add_eq_one_iff, isCoprime_iff_add] theorem isCoprime_iff_sup_eq : IsCoprime I J ↔ I ⊔ J = ⊤ := by rw [isCoprime_iff_codisjoint, codisjoint_iff] open List in theorem isCoprime_tfae : TFAE [IsCoprime I J, Codisjoint I J, I + J = 1, ∃ i ∈ I, ∃ j ∈ J, i + j = 1, I ⊔ J = ⊤] := by rw [← isCoprime_iff_codisjoint, ← isCoprime_iff_add, ← isCoprime_iff_exists, ← isCoprime_iff_sup_eq] simp theorem _root_.IsCoprime.codisjoint (h : IsCoprime I J) : Codisjoint I J := isCoprime_iff_codisjoint.mp h theorem _root_.IsCoprime.add_eq (h : IsCoprime I J) : I + J = 1 := isCoprime_iff_add.mp h theorem _root_.IsCoprime.exists (h : IsCoprime I J) : ∃ i ∈ I, ∃ j ∈ J, i + j = 1 := isCoprime_iff_exists.mp h theorem _root_.IsCoprime.sup_eq (h : IsCoprime I J) : I ⊔ J = ⊤ := isCoprime_iff_sup_eq.mp h theorem inf_eq_mul_of_isCoprime (coprime : IsCoprime I J) : I ⊓ J = I * J := (Ideal.mul_eq_inf_of_coprime coprime.sup_eq).symm @[deprecated (since := "2024-05-28")] alias inf_eq_mul_of_coprime := inf_eq_mul_of_isCoprime theorem isCoprime_span_singleton_iff (x y : R) : IsCoprime (span <| singleton x) (span <| singleton y) ↔ IsCoprime x y := by simp_rw [isCoprime_iff_codisjoint, codisjoint_iff, eq_top_iff_one, mem_span_singleton_sup, mem_span_singleton] constructor · rintro ⟨a, _, ⟨b, rfl⟩, e⟩; exact ⟨a, b, mul_comm b y ▸ e⟩ · rintro ⟨a, b, e⟩; exact ⟨a, _, ⟨b, rfl⟩, mul_comm y b ▸ e⟩ theorem isCoprime_biInf {J : ι → Ideal R} {s : Finset ι} (hf : ∀ j ∈ s, IsCoprime I (J j)) : IsCoprime I (⨅ j ∈ s, J j) := by classical simp_rw [isCoprime_iff_add] at * induction s using Finset.induction with | empty => simp | @insert i s _ hs => rw [Finset.iInf_insert, inf_comm, one_eq_top, eq_top_iff, ← one_eq_top] set K := ⨅ j ∈ s, J j calc 1 = I + K := (hs fun j hj ↦ hf j (Finset.mem_insert_of_mem hj)).symm _ = I + K*(I + J i) := by rw [hf i (Finset.mem_insert_self i s), mul_one] _ = (1+K)*I + K*J i := by ring _ ≤ I + K ⊓ J i := add_le_add mul_le_left mul_le_inf /-- The radical of an ideal `I` consists of the elements `r` such that `r ^ n ∈ I` for some `n`. -/ def radical (I : Ideal R) : Ideal R where carrier := { r | ∃ n : ℕ, r ^ n ∈ I } zero_mem' := ⟨1, (pow_one (0 : R)).symm ▸ I.zero_mem⟩ add_mem' := fun {_ _} ⟨m, hxmi⟩ ⟨n, hyni⟩ => ⟨m + n - 1, add_pow_add_pred_mem_of_pow_mem I hxmi hyni⟩ smul_mem' {r s} := fun ⟨n, h⟩ ↦ ⟨n, (mul_pow r s n).symm ▸ I.mul_mem_left (r ^ n) h⟩ theorem mem_radical_iff {r : R} : r ∈ I.radical ↔ ∃ n : ℕ, r ^ n ∈ I := Iff.rfl /-- An ideal is radical if it contains its radical. -/ def IsRadical (I : Ideal R) : Prop := I.radical ≤ I theorem le_radical : I ≤ radical I := fun r hri => ⟨1, (pow_one r).symm ▸ hri⟩ /-- An ideal is radical iff it is equal to its radical. -/ theorem radical_eq_iff : I.radical = I ↔ I.IsRadical := by rw [le_antisymm_iff, and_iff_left le_radical, IsRadical] alias ⟨_, IsRadical.radical⟩ := radical_eq_iff theorem isRadical_iff_pow_one_lt (k : ℕ) (hk : 1 < k) : I.IsRadical ↔ ∀ r, r ^ k ∈ I → r ∈ I := ⟨fun h _r hr ↦ h ⟨k, hr⟩, fun h x ⟨n, hx⟩ ↦ k.pow_imp_self_of_one_lt hk _ (fun _ _ ↦ .inr ∘ I.smul_mem _) h n x hx⟩ variable (R) theorem radical_top : (radical ⊤ : Ideal R) = ⊤ := (eq_top_iff_one _).2 ⟨0, Submodule.mem_top⟩ variable {R} theorem radical_mono (H : I ≤ J) : radical I ≤ radical J := fun _ ⟨n, hrni⟩ => ⟨n, H hrni⟩ variable (I) theorem radical_isRadical : (radical I).IsRadical := fun r ⟨n, k, hrnki⟩ => ⟨n * k, (pow_mul r n k).symm ▸ hrnki⟩ @[simp] theorem radical_idem : radical (radical I) = radical I := (radical_isRadical I).radical variable {I} theorem IsRadical.radical_le_iff (hJ : J.IsRadical) : I.radical ≤ J ↔ I ≤ J := ⟨le_trans le_radical, fun h => hJ.radical ▸ radical_mono h⟩ theorem radical_le_radical_iff : radical I ≤ radical J ↔ I ≤ radical J := (radical_isRadical J).radical_le_iff theorem radical_eq_top : radical I = ⊤ ↔ I = ⊤ := ⟨fun h => (eq_top_iff_one _).2 <| let ⟨n, hn⟩ := (eq_top_iff_one _).1 h @one_pow R _ n ▸ hn, fun h => h.symm ▸ radical_top R⟩ theorem IsPrime.isRadical (H : IsPrime I) : I.IsRadical := fun _ ⟨n, hrni⟩ => H.mem_of_pow_mem n hrni theorem IsPrime.radical (H : IsPrime I) : radical I = I := IsRadical.radical H.isRadical theorem mem_radical_of_pow_mem {I : Ideal R} {x : R} {m : ℕ} (hx : x ^ m ∈ radical I) : x ∈ radical I := radical_idem I ▸ ⟨m, hx⟩ theorem disjoint_powers_iff_not_mem (y : R) (hI : I.IsRadical) : Disjoint (Submonoid.powers y : Set R) ↑I ↔ y ∉ I.1 := by refine ⟨fun h => Set.disjoint_left.1 h (Submonoid.mem_powers _), fun h => disjoint_iff.mpr (eq_bot_iff.mpr ?_)⟩ rintro x ⟨⟨n, rfl⟩, hx'⟩ exact h (hI <| mem_radical_of_pow_mem <| le_radical hx') variable (I J) theorem radical_sup : radical (I ⊔ J) = radical (radical I ⊔ radical J) := le_antisymm (radical_mono <| sup_le_sup le_radical le_radical) <| radical_le_radical_iff.2 <| sup_le (radical_mono le_sup_left) (radical_mono le_sup_right) theorem radical_inf : radical (I ⊓ J) = radical I ⊓ radical J := le_antisymm (le_inf (radical_mono inf_le_left) (radical_mono inf_le_right)) fun r ⟨⟨m, hrm⟩, ⟨n, hrn⟩⟩ => ⟨m + n, (pow_add r m n).symm ▸ I.mul_mem_right _ hrm, (pow_add r m n).symm ▸ J.mul_mem_left _ hrn⟩ variable {I J} in theorem IsRadical.inf (hI : IsRadical I) (hJ : IsRadical J) : IsRadical (I ⊓ J) := by rw [IsRadical, radical_inf]; exact inf_le_inf hI hJ /-- The reverse inclusion does not hold for e.g. `I := fun n : ℕ ↦ Ideal.span {(2 ^ n : ℤ)}`. -/ theorem radical_iInf_le {ι} (I : ι → Ideal R) : radical (⨅ i, I i) ≤ ⨅ i, radical (I i) := le_iInf fun _ ↦ radical_mono (iInf_le _ _) theorem isRadical_iInf {ι} (I : ι → Ideal R) (hI : ∀ i, IsRadical (I i)) : IsRadical (⨅ i, I i) := (radical_iInf_le I).trans (iInf_mono hI) theorem radical_mul : radical (I * J) = radical I ⊓ radical J := by refine le_antisymm ?_ fun r ⟨⟨m, hrm⟩, ⟨n, hrn⟩⟩ => ⟨m + n, (pow_add r m n).symm ▸ mul_mem_mul hrm hrn⟩ have := radical_mono <| @mul_le_inf _ _ I J simp_rw [radical_inf I J] at this assumption variable {I J} theorem IsPrime.radical_le_iff (hJ : IsPrime J) : I.radical ≤ J ↔ I ≤ J := IsRadical.radical_le_iff hJ.isRadical theorem radical_eq_sInf (I : Ideal R) : radical I = sInf { J : Ideal R | I ≤ J ∧ IsPrime J } := le_antisymm (le_sInf fun J hJ ↦ hJ.2.radical_le_iff.2 hJ.1) fun r hr ↦ by_contradiction fun hri ↦ let ⟨m, (hrm : r ∉ radical m), him, hm⟩ := zorn_nonempty_partialOrder₀ { K : Ideal R | r ∉ radical K } (fun c hc hcc y hyc => ⟨sSup c, fun ⟨n, hrnc⟩ => let ⟨y, hyc, hrny⟩ := (Submodule.mem_sSup_of_directed ⟨y, hyc⟩ hcc.directedOn).1 hrnc hc hyc ⟨n, hrny⟩, fun z => le_sSup⟩) I hri have : ∀ x ∉ m, r ∈ radical (m ⊔ span {x}) := fun x hxm => by_contradiction fun hrmx => hxm <| hm (m ⊔ span {x}) hrmx le_sup_left ▸ (le_sup_right : _ ≤ m ⊔ span {x}) (subset_span <| Set.mem_singleton _) have : IsPrime m := ⟨by rintro rfl; rw [radical_top] at hrm; exact hrm trivial, fun {x y} hxym => or_iff_not_imp_left.2 fun hxm => by_contradiction fun hym => let ⟨n, hrn⟩ := this _ hxm let ⟨p, hpm, q, hq, hpqrn⟩ := Submodule.mem_sup.1 hrn let ⟨c, hcxq⟩ := mem_span_singleton'.1 hq let ⟨k, hrk⟩ := this _ hym let ⟨f, hfm, g, hg, hfgrk⟩ := Submodule.mem_sup.1 hrk let ⟨d, hdyg⟩ := mem_span_singleton'.1 hg hrm ⟨n + k, by rw [pow_add, ← hpqrn, ← hcxq, ← hfgrk, ← hdyg, add_mul, mul_add (c * x), mul_assoc c x (d * y), mul_left_comm x, ← mul_assoc] refine m.add_mem (m.mul_mem_right _ hpm) (m.add_mem (m.mul_mem_left _ hfm) (m.mul_mem_left _ hxym))⟩⟩ hrm <| this.radical.symm ▸ (sInf_le ⟨him, this⟩ : sInf { J : Ideal R | I ≤ J ∧ IsPrime J } ≤ m) hr theorem isRadical_bot_of_noZeroDivisors {R} [CommSemiring R] [NoZeroDivisors R] : (⊥ : Ideal R).IsRadical := fun _ hx => hx.recOn fun _ hn => pow_eq_zero hn @[simp] theorem radical_bot_of_noZeroDivisors {R : Type u} [CommSemiring R] [NoZeroDivisors R] : radical (⊥ : Ideal R) = ⊥ := eq_bot_iff.2 isRadical_bot_of_noZeroDivisors instance : IdemCommSemiring (Ideal R) := inferInstance variable (R) theorem top_pow (n : ℕ) : (⊤ ^ n : Ideal R) = ⊤ := Nat.recOn n one_eq_top fun n ih => by rw [pow_succ, ih, top_mul] variable {R} variable (I) lemma radical_pow : ∀ {n}, n ≠ 0 → radical (I ^ n) = radical I | 1, _ => by simp | n + 2, _ => by rw [pow_succ, radical_mul, radical_pow n.succ_ne_zero, inf_idem] theorem IsPrime.mul_le {I J P : Ideal R} (hp : IsPrime P) : I * J ≤ P ↔ I ≤ P ∨ J ≤ P := by rw [or_comm, Ideal.mul_le] simp_rw [hp.mul_mem_iff_mem_or_mem, SetLike.le_def, ← forall_or_left, or_comm, forall_or_left] theorem IsPrime.inf_le {I J P : Ideal R} (hp : IsPrime P) : I ⊓ J ≤ P ↔ I ≤ P ∨ J ≤ P := ⟨fun h ↦ hp.mul_le.1 <| mul_le_inf.trans h, fun h ↦ h.elim inf_le_left.trans inf_le_right.trans⟩ theorem IsPrime.multiset_prod_le {s : Multiset (Ideal R)} {P : Ideal R} (hp : IsPrime P) : s.prod ≤ P ↔ ∃ I ∈ s, I ≤ P := s.induction_on (by simp [hp.ne_top]) fun I s ih ↦ by simp [hp.mul_le, ih] theorem IsPrime.multiset_prod_map_le {s : Multiset ι} (f : ι → Ideal R) {P : Ideal R} (hp : IsPrime P) : (s.map f).prod ≤ P ↔ ∃ i ∈ s, f i ≤ P := by simp_rw [hp.multiset_prod_le, Multiset.mem_map, exists_exists_and_eq_and] theorem IsPrime.multiset_prod_mem_iff_exists_mem {I : Ideal R} (hI : I.IsPrime) (s : Multiset R) : s.prod ∈ I ↔ ∃ p ∈ s, p ∈ I := by simpa [span_singleton_le_iff_mem] using (hI.multiset_prod_map_le (span {·})) theorem IsPrime.prod_le {s : Finset ι} {f : ι → Ideal R} {P : Ideal R} (hp : IsPrime P) : s.prod f ≤ P ↔ ∃ i ∈ s, f i ≤ P := hp.multiset_prod_map_le f theorem IsPrime.prod_mem_iff_exists_mem {I : Ideal R} (hI : I.IsPrime) (s : Finset R) : s.prod (fun x ↦ x) ∈ I ↔ ∃ p ∈ s, p ∈ I := by rw [Finset.prod_eq_multiset_prod, Multiset.map_id'] exact hI.multiset_prod_mem_iff_exists_mem s.val theorem IsPrime.inf_le' {s : Finset ι} {f : ι → Ideal R} {P : Ideal R} (hp : IsPrime P) : s.inf f ≤ P ↔ ∃ i ∈ s, f i ≤ P := ⟨fun h ↦ hp.prod_le.1 <| prod_le_inf.trans h, fun ⟨_, his, hip⟩ ↦ (Finset.inf_le his).trans hip⟩ -- Porting note: needed to add explicit coercions (· : Set R). theorem subset_union {R : Type u} [Ring R] {I J K : Ideal R} : (I : Set R) ⊆ J ∪ K ↔ I ≤ J ∨ I ≤ K := AddSubgroupClass.subset_union theorem subset_union_prime' {R : Type u} [CommRing R] {s : Finset ι} {f : ι → Ideal R} {a b : ι} (hp : ∀ i ∈ s, IsPrime (f i)) {I : Ideal R} : ((I : Set R) ⊆ f a ∪ f b ∪ ⋃ i ∈ (↑s : Set ι), f i) ↔ I ≤ f a ∨ I ≤ f b ∨ ∃ i ∈ s, I ≤ f i := by suffices ((I : Set R) ⊆ f a ∪ f b ∪ ⋃ i ∈ (↑s : Set ι), f i) → I ≤ f a ∨ I ≤ f b ∨ ∃ i ∈ s, I ≤ f i from ⟨this, fun h => Or.casesOn h (fun h => Set.Subset.trans h <| Set.Subset.trans Set.subset_union_left Set.subset_union_left) fun h => Or.casesOn h (fun h => Set.Subset.trans h <| Set.Subset.trans Set.subset_union_right Set.subset_union_left) fun ⟨i, his, hi⟩ => by refine Set.Subset.trans hi <| Set.Subset.trans ?_ Set.subset_union_right exact Set.subset_biUnion_of_mem (u := fun x ↦ (f x : Set R)) (Finset.mem_coe.2 his)⟩ generalize hn : s.card = n; intro h induction' n with n ih generalizing a b s · clear hp rw [Finset.card_eq_zero] at hn subst hn rw [Finset.coe_empty, Set.biUnion_empty, Set.union_empty, subset_union] at h simpa only [exists_prop, Finset.not_mem_empty, false_and_iff, exists_false, or_false_iff] classical replace hn : ∃ (i : ι) (t : Finset ι), i ∉ t ∧ insert i t = s ∧ t.card = n := Finset.card_eq_succ.1 hn rcases hn with ⟨i, t, hit, rfl, hn⟩ replace hp : IsPrime (f i) ∧ ∀ x ∈ t, IsPrime (f x) := (t.forall_mem_insert _ _).1 hp by_cases Ht : ∃ j ∈ t, f j ≤ f i · obtain ⟨j, hjt, hfji⟩ : ∃ j ∈ t, f j ≤ f i := Ht obtain ⟨u, hju, rfl⟩ : ∃ u, j ∉ u ∧ insert j u = t := ⟨t.erase j, t.not_mem_erase j, Finset.insert_erase hjt⟩ have hp' : ∀ k ∈ insert i u, IsPrime (f k) := by rw [Finset.forall_mem_insert] at hp ⊢ exact ⟨hp.1, hp.2.2⟩ have hiu : i ∉ u := mt Finset.mem_insert_of_mem hit have hn' : (insert i u).card = n := by rwa [Finset.card_insert_of_not_mem] at hn ⊢ exacts [hiu, hju] have h' : (I : Set R) ⊆ f a ∪ f b ∪ ⋃ k ∈ (↑(insert i u) : Set ι), f k := by rw [Finset.coe_insert] at h ⊢ rw [Finset.coe_insert] at h simp only [Set.biUnion_insert] at h ⊢ rw [← Set.union_assoc (f i : Set R)] at h erw [Set.union_eq_self_of_subset_right hfji] at h exact h specialize ih hp' hn' h' refine ih.imp id (Or.imp id (Exists.imp fun k => ?_)) exact And.imp (fun hk => Finset.insert_subset_insert i (Finset.subset_insert j u) hk) id by_cases Ha : f a ≤ f i · have h' : (I : Set R) ⊆ f i ∪ f b ∪ ⋃ j ∈ (↑t : Set ι), f j := by rw [Finset.coe_insert, Set.biUnion_insert, ← Set.union_assoc, Set.union_right_comm (f a : Set R)] at h erw [Set.union_eq_self_of_subset_left Ha] at h exact h specialize ih hp.2 hn h' right rcases ih with (ih | ih | ⟨k, hkt, ih⟩) · exact Or.inr ⟨i, Finset.mem_insert_self i t, ih⟩ · exact Or.inl ih · exact Or.inr ⟨k, Finset.mem_insert_of_mem hkt, ih⟩ by_cases Hb : f b ≤ f i · have h' : (I : Set R) ⊆ f a ∪ f i ∪ ⋃ j ∈ (↑t : Set ι), f j := by rw [Finset.coe_insert, Set.biUnion_insert, ← Set.union_assoc, Set.union_assoc (f a : Set R)] at h erw [Set.union_eq_self_of_subset_left Hb] at h exact h specialize ih hp.2 hn h' rcases ih with (ih | ih | ⟨k, hkt, ih⟩) · exact Or.inl ih · exact Or.inr (Or.inr ⟨i, Finset.mem_insert_self i t, ih⟩) · exact Or.inr (Or.inr ⟨k, Finset.mem_insert_of_mem hkt, ih⟩) by_cases Hi : I ≤ f i · exact Or.inr (Or.inr ⟨i, Finset.mem_insert_self i t, Hi⟩) have : ¬I ⊓ f a ⊓ f b ⊓ t.inf f ≤ f i := by simp only [hp.1.inf_le, hp.1.inf_le', not_or] exact ⟨⟨⟨Hi, Ha⟩, Hb⟩, Ht⟩ rcases Set.not_subset.1 this with ⟨r, ⟨⟨⟨hrI, hra⟩, hrb⟩, hr⟩, hri⟩ by_cases HI : (I : Set R) ⊆ f a ∪ f b ∪ ⋃ j ∈ (↑t : Set ι), f j · specialize ih hp.2 hn HI rcases ih with (ih | ih | ⟨k, hkt, ih⟩) · left exact ih · right left exact ih · right right exact ⟨k, Finset.mem_insert_of_mem hkt, ih⟩ exfalso rcases Set.not_subset.1 HI with ⟨s, hsI, hs⟩ rw [Finset.coe_insert, Set.biUnion_insert] at h have hsi : s ∈ f i := ((h hsI).resolve_left (mt Or.inl hs)).resolve_right (mt Or.inr hs) rcases h (I.add_mem hrI hsI) with (⟨ha | hb⟩ | hi | ht) · exact hs (Or.inl <| Or.inl <| add_sub_cancel_left r s ▸ (f a).sub_mem ha hra) · exact hs (Or.inl <| Or.inr <| add_sub_cancel_left r s ▸ (f b).sub_mem hb hrb) · exact hri (add_sub_cancel_right r s ▸ (f i).sub_mem hi hsi) · rw [Set.mem_iUnion₂] at ht rcases ht with ⟨j, hjt, hj⟩ simp only [Finset.inf_eq_iInf, SetLike.mem_coe, Submodule.mem_iInf] at hr exact hs $ Or.inr $ Set.mem_biUnion hjt <| add_sub_cancel_left r s ▸ (f j).sub_mem hj <| hr j hjt /-- Prime avoidance. Atiyah-Macdonald 1.11, Eisenbud 3.3, Stacks 00DS, Matsumura Ex.1.6. -/ theorem subset_union_prime {R : Type u} [CommRing R] {s : Finset ι} {f : ι → Ideal R} (a b : ι) (hp : ∀ i ∈ s, i ≠ a → i ≠ b → IsPrime (f i)) {I : Ideal R} : ((I : Set R) ⊆ ⋃ i ∈ (↑s : Set ι), f i) ↔ ∃ i ∈ s, I ≤ f i := suffices ((I : Set R) ⊆ ⋃ i ∈ (↑s : Set ι), f i) → ∃ i, i ∈ s ∧ I ≤ f i by have aux := fun h => (bex_def.2 <| this h) simp_rw [exists_prop] at aux refine ⟨aux, fun ⟨i, his, hi⟩ ↦ Set.Subset.trans hi ?_⟩ apply Set.subset_biUnion_of_mem (show i ∈ (↑s : Set ι) from his) fun h : (I : Set R) ⊆ ⋃ i ∈ (↑s : Set ι), f i => by classical by_cases has : a ∈ s · obtain ⟨t, hat, rfl⟩ : ∃ t, a ∉ t ∧ insert a t = s := ⟨s.erase a, Finset.not_mem_erase a s, Finset.insert_erase has⟩ by_cases hbt : b ∈ t · obtain ⟨u, hbu, rfl⟩ : ∃ u, b ∉ u ∧ insert b u = t := ⟨t.erase b, Finset.not_mem_erase b t, Finset.insert_erase hbt⟩ have hp' : ∀ i ∈ u, IsPrime (f i) := by intro i hiu refine hp i (Finset.mem_insert_of_mem (Finset.mem_insert_of_mem hiu)) ?_ ?_ <;> rintro rfl <;> solve_by_elim only [Finset.mem_insert_of_mem, *] rw [Finset.coe_insert, Finset.coe_insert, Set.biUnion_insert, Set.biUnion_insert, ← Set.union_assoc, subset_union_prime' hp'] at h rwa [Finset.exists_mem_insert, Finset.exists_mem_insert] · have hp' : ∀ j ∈ t, IsPrime (f j) := by intro j hj refine hp j (Finset.mem_insert_of_mem hj) ?_ ?_ <;> rintro rfl <;> solve_by_elim only [Finset.mem_insert_of_mem, *] rw [Finset.coe_insert, Set.biUnion_insert, ← Set.union_self (f a : Set R), subset_union_prime' hp', ← or_assoc, or_self_iff] at h rwa [Finset.exists_mem_insert] · by_cases hbs : b ∈ s · obtain ⟨t, hbt, rfl⟩ : ∃ t, b ∉ t ∧ insert b t = s := ⟨s.erase b, Finset.not_mem_erase b s, Finset.insert_erase hbs⟩ have hp' : ∀ j ∈ t, IsPrime (f j) := by intro j hj refine hp j (Finset.mem_insert_of_mem hj) ?_ ?_ <;> rintro rfl <;> solve_by_elim only [Finset.mem_insert_of_mem, *] rw [Finset.coe_insert, Set.biUnion_insert, ← Set.union_self (f b : Set R), subset_union_prime' hp', ← or_assoc, or_self_iff] at h rwa [Finset.exists_mem_insert] rcases s.eq_empty_or_nonempty with hse | hsne · subst hse rw [Finset.coe_empty, Set.biUnion_empty, Set.subset_empty_iff] at h have : (I : Set R) ≠ ∅ := Set.Nonempty.ne_empty (Set.nonempty_of_mem I.zero_mem) exact absurd h this · cases' hsne with i his obtain ⟨t, _, rfl⟩ : ∃ t, i ∉ t ∧ insert i t = s := ⟨s.erase i, Finset.not_mem_erase i s, Finset.insert_erase his⟩ have hp' : ∀ j ∈ t, IsPrime (f j) := by intro j hj refine hp j (Finset.mem_insert_of_mem hj) ?_ ?_ <;> rintro rfl <;> solve_by_elim only [Finset.mem_insert_of_mem, *] rw [Finset.coe_insert, Set.biUnion_insert, ← Set.union_self (f i : Set R), subset_union_prime' hp', ← or_assoc, or_self_iff] at h rwa [Finset.exists_mem_insert] section Dvd /-- If `I` divides `J`, then `I` contains `J`. In a Dedekind domain, to divide and contain are equivalent, see `Ideal.dvd_iff_le`. -/ theorem le_of_dvd {I J : Ideal R} : I ∣ J → J ≤ I | ⟨_, h⟩ => h.symm ▸ le_trans mul_le_inf inf_le_left @[simp] theorem isUnit_iff {I : Ideal R} : IsUnit I ↔ I = ⊤ := isUnit_iff_dvd_one.trans ((@one_eq_top R _).symm ▸ ⟨fun h => eq_top_iff.mpr (Ideal.le_of_dvd h), fun h => ⟨⊤, by rw [mul_top, h]⟩⟩) instance uniqueUnits : Unique (Ideal R)ˣ where default := 1 uniq u := Units.ext (show (u : Ideal R) = 1 by rw [isUnit_iff.mp u.isUnit, one_eq_top]) end Dvd end MulAndRadical section Total variable (ι : Type*) variable (M : Type*) [AddCommGroup M] {R : Type*} [CommRing R] [Module R M] (I : Ideal R) variable (v : ι → M) (hv : Submodule.span R (Set.range v) = ⊤) /-- A variant of `Finsupp.total` that takes in vectors valued in `I`. -/ noncomputable def finsuppTotal : (ι →₀ I) →ₗ[R] M := (Finsupp.total ι M R v).comp (Finsupp.mapRange.linearMap I.subtype) variable {ι M v} theorem finsuppTotal_apply (f : ι →₀ I) : finsuppTotal ι M I v f = f.sum fun i x => (x : R) • v i := by dsimp [finsuppTotal] rw [Finsupp.total_apply, Finsupp.sum_mapRange_index] exact fun _ => zero_smul _ _ theorem finsuppTotal_apply_eq_of_fintype [Fintype ι] (f : ι →₀ I) : finsuppTotal ι M I v f = ∑ i, (f i : R) • v i := by rw [finsuppTotal_apply, Finsupp.sum_fintype] exact fun _ => zero_smul _ _ theorem range_finsuppTotal : LinearMap.range (finsuppTotal ι M I v) = I • Submodule.span R (Set.range v) := by ext rw [Submodule.mem_ideal_smul_span_iff_exists_sum] refine ⟨fun ⟨f, h⟩ => ⟨Finsupp.mapRange.linearMap I.subtype f, fun i => (f i).2, h⟩, ?_⟩ rintro ⟨a, ha, rfl⟩ classical refine ⟨a.mapRange (fun r => if h : r ∈ I then ⟨r, h⟩ else 0) (by simp), ?_⟩ rw [finsuppTotal_apply, Finsupp.sum_mapRange_index] · apply Finsupp.sum_congr intro i _ rw [dif_pos (ha i)] · exact fun _ => zero_smul _ _ end Total end Ideal section span_range variable {α R : Type*} [Semiring R] theorem Finsupp.mem_ideal_span_range_iff_exists_finsupp {x : R} {v : α → R} : x ∈ Ideal.span (Set.range v) ↔ ∃ c : α →₀ R, (c.sum fun i a => a * v i) = x := Finsupp.mem_span_range_iff_exists_finsupp /-- An element `x` lies in the span of `v` iff it can be written as sum `∑ cᵢ • vᵢ = x`. -/ theorem mem_ideal_span_range_iff_exists_fun [Fintype α] {x : R} {v : α → R} : x ∈ Ideal.span (Set.range v) ↔ ∃ c : α → R, ∑ i, c i * v i = x := mem_span_range_iff_exists_fun _ end span_range theorem Associates.mk_ne_zero' {R : Type*} [CommSemiring R] {r : R} : Associates.mk (Ideal.span {r} : Ideal R) ≠ 0 ↔ r ≠ 0 := by rw [Associates.mk_ne_zero, Ideal.zero_eq_bot, Ne, Ideal.span_singleton_eq_bot] open scoped nonZeroDivisors in theorem Ideal.span_singleton_nonZeroDivisors {R : Type*} [CommSemiring R] [NoZeroDivisors R] {r : R} : span {r} ∈ (Ideal R)⁰ ↔ r ∈ R⁰ := by cases subsingleton_or_nontrivial R · exact ⟨fun _ _ _ ↦ Subsingleton.eq_zero _, fun _ _ _ ↦ Subsingleton.eq_zero _⟩ · rw [mem_nonZeroDivisors_iff_ne_zero, mem_nonZeroDivisors_iff_ne_zero, ne_eq, zero_eq_bot, span_singleton_eq_bot] namespace Submodule variable {R : Type u} {M : Type v} variable [CommSemiring R] [AddCommMonoid M] [Module R M] -- TODO: show `[Algebra R A] : Algebra (Ideal R) A` too instance moduleSubmodule : Module (Ideal R) (Submodule R M) where smul_add := smul_sup add_smul := sup_smul mul_smul := Submodule.smul_assoc one_smul := by simp zero_smul := bot_smul smul_zero := smul_bot lemma span_smul_eq (s : Set R) (N : Submodule R M) : Ideal.span s • N = s • N := by rw [← coe_set_smul, coe_span_smul] @[simp] theorem set_smul_top_eq_span (s : Set R) : s • ⊤ = Ideal.span s := Eq.trans (span_smul_eq s ⊤).symm <| Eq.trans (smul_eq_mul (Ideal R)) (Ideal.mul_top (.span s)) end Submodule
RingTheory\Ideal\Over.lean
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.RingTheory.Algebraic import Mathlib.RingTheory.Localization.AtPrime import Mathlib.RingTheory.Localization.Integral /-! # Ideals over/under ideals This file concerns ideals lying over other ideals. Let `f : R →+* S` be a ring homomorphism (typically a ring extension), `I` an ideal of `R` and `J` an ideal of `S`. We say `J` lies over `I` (and `I` under `J`) if `I` is the `f`-preimage of `J`. This is expressed here by writing `I = J.comap f`. ## Implementation notes The proofs of the `comap_ne_bot` and `comap_lt_comap` families use an approach specific for their situation: we construct an element in `I.comap f` from the coefficients of a minimal polynomial. Once mathlib has more material on the localization at a prime ideal, the results can be proven using more general going-up/going-down theory. -/ variable {R : Type*} [CommRing R] namespace Ideal open Polynomial open Polynomial open Submodule section CommRing variable {S : Type*} [CommRing S] {f : R →+* S} {I J : Ideal S} theorem coeff_zero_mem_comap_of_root_mem_of_eval_mem {r : S} (hr : r ∈ I) {p : R[X]} (hp : p.eval₂ f r ∈ I) : p.coeff 0 ∈ I.comap f := by rw [← p.divX_mul_X_add, eval₂_add, eval₂_C, eval₂_mul, eval₂_X] at hp refine mem_comap.mpr ((I.add_mem_iff_right ?_).mp hp) exact I.mul_mem_left _ hr theorem coeff_zero_mem_comap_of_root_mem {r : S} (hr : r ∈ I) {p : R[X]} (hp : p.eval₂ f r = 0) : p.coeff 0 ∈ I.comap f := coeff_zero_mem_comap_of_root_mem_of_eval_mem hr (hp.symm ▸ I.zero_mem) theorem exists_coeff_ne_zero_mem_comap_of_non_zero_divisor_root_mem {r : S} (r_non_zero_divisor : ∀ {x}, x * r = 0 → x = 0) (hr : r ∈ I) {p : R[X]} : p ≠ 0 → p.eval₂ f r = 0 → ∃ i, p.coeff i ≠ 0 ∧ p.coeff i ∈ I.comap f := by refine p.recOnHorner ?_ ?_ ?_ · intro h contradiction · intro p a coeff_eq_zero a_ne_zero _ _ hp refine ⟨0, ?_, coeff_zero_mem_comap_of_root_mem hr hp⟩ simp [coeff_eq_zero, a_ne_zero] · intro p p_nonzero ih _ hp rw [eval₂_mul, eval₂_X] at hp obtain ⟨i, hi, mem⟩ := ih p_nonzero (r_non_zero_divisor hp) refine ⟨i + 1, ?_, ?_⟩ · simp [hi, mem] · simpa [hi] using mem /-- Let `P` be an ideal in `R[x]`. The map `R[x]/P → (R / (P ∩ R))[x] / (P / (P ∩ R))` is injective. -/ theorem injective_quotient_le_comap_map (P : Ideal R[X]) : Function.Injective <| Ideal.quotientMap (Ideal.map (Polynomial.mapRingHom (Quotient.mk (P.comap (C : R →+* R[X])))) P) (Polynomial.mapRingHom (Ideal.Quotient.mk (P.comap (C : R →+* R[X])))) le_comap_map := by refine quotientMap_injective' (le_of_eq ?_) rw [comap_map_of_surjective (mapRingHom (Ideal.Quotient.mk (P.comap (C : R →+* R[X])))) (map_surjective (Ideal.Quotient.mk (P.comap (C : R →+* R[X]))) Ideal.Quotient.mk_surjective)] refine le_antisymm (sup_le le_rfl ?_) (le_sup_of_le_left le_rfl) refine fun p hp => polynomial_mem_ideal_of_coeff_mem_ideal P p fun n => Ideal.Quotient.eq_zero_iff_mem.mp ?_ simpa only [coeff_map, coe_mapRingHom] using ext_iff.mp (Ideal.mem_bot.mp (mem_comap.mp hp)) n /-- The identity in this lemma asserts that the "obvious" square ``` R → (R / (P ∩ R)) ↓ ↓ R[x] / P → (R / (P ∩ R))[x] / (P / (P ∩ R)) ``` commutes. It is used, for instance, in the proof of `quotient_mk_comp_C_is_integral_of_jacobson`, in the file `RingTheory.Jacobson`. -/ theorem quotient_mk_maps_eq (P : Ideal R[X]) : ((Quotient.mk (map (mapRingHom (Quotient.mk (P.comap (C : R →+* R[X])))) P)).comp C).comp (Quotient.mk (P.comap (C : R →+* R[X]))) = (Ideal.quotientMap (map (mapRingHom (Quotient.mk (P.comap (C : R →+* R[X])))) P) (mapRingHom (Quotient.mk (P.comap (C : R →+* R[X])))) le_comap_map).comp ((Quotient.mk P).comp C) := by refine RingHom.ext fun x => ?_ repeat' rw [RingHom.coe_comp, Function.comp_apply] rw [quotientMap_mk, coe_mapRingHom, map_C] /-- This technical lemma asserts the existence of a polynomial `p` in an ideal `P ⊂ R[x]` that is non-zero in the quotient `R / (P ∩ R) [x]`. The assumptions are equivalent to `P ≠ 0` and `P ∩ R = (0)`. -/ theorem exists_nonzero_mem_of_ne_bot {P : Ideal R[X]} (Pb : P ≠ ⊥) (hP : ∀ x : R, C x ∈ P → x = 0) : ∃ p : R[X], p ∈ P ∧ Polynomial.map (Quotient.mk (P.comap (C : R →+* R[X]))) p ≠ 0 := by obtain ⟨m, hm⟩ := Submodule.nonzero_mem_of_bot_lt (bot_lt_iff_ne_bot.mpr Pb) refine ⟨m, Submodule.coe_mem m, fun pp0 => hm (Submodule.coe_eq_zero.mp ?_)⟩ refine (injective_iff_map_eq_zero (Polynomial.mapRingHom (Ideal.Quotient.mk (P.comap (C : R →+* R[X]))))).mp ?_ _ pp0 refine map_injective _ ((Ideal.Quotient.mk (P.comap C)).injective_iff_ker_eq_bot.mpr ?_) rw [mk_ker] exact (Submodule.eq_bot_iff _).mpr fun x hx => hP x (mem_comap.mp hx) variable {p : Ideal R} {P : Ideal S} /-- If there is an injective map `R/p → S/P` such that following diagram commutes: ``` R → S ↓ ↓ R/p → S/P ``` then `P` lies over `p`. -/ theorem comap_eq_of_scalar_tower_quotient [Algebra R S] [Algebra (R ⧸ p) (S ⧸ P)] [IsScalarTower R (R ⧸ p) (S ⧸ P)] (h : Function.Injective (algebraMap (R ⧸ p) (S ⧸ P))) : comap (algebraMap R S) P = p := by ext x rw [mem_comap, ← Quotient.eq_zero_iff_mem, ← Quotient.eq_zero_iff_mem, Quotient.mk_algebraMap, IsScalarTower.algebraMap_apply R (R ⧸ p) (S ⧸ P), Quotient.algebraMap_eq] constructor · intro hx exact (injective_iff_map_eq_zero (algebraMap (R ⧸ p) (S ⧸ P))).mp h _ hx · intro hx rw [hx, RingHom.map_zero] /-- If `P` lies over `p`, then `R / p` has a canonical map to `S / P`. -/ def Quotient.algebraQuotientOfLEComap (h : p ≤ comap f P) : Algebra (R ⧸ p) (S ⧸ P) := RingHom.toAlgebra <| quotientMap _ f h /-- `R / p` has a canonical map to `S / pS`. -/ instance Quotient.algebraQuotientMapQuotient : Algebra (R ⧸ p) (S ⧸ map f p) := Ideal.Quotient.algebraQuotientOfLEComap le_comap_map @[simp] theorem Quotient.algebraMap_quotient_map_quotient (x : R) : algebraMap (R ⧸ p) (S ⧸ map f p) (Ideal.Quotient.mk p x) = Ideal.Quotient.mk (map f p) (f x) := rfl @[simp] theorem Quotient.mk_smul_mk_quotient_map_quotient (x : R) (y : S) : Quotient.mk p x • Quotient.mk (map f p) y = Quotient.mk (map f p) (f x * y) := rfl instance Quotient.tower_quotient_map_quotient [Algebra R S] : IsScalarTower R (R ⧸ p) (S ⧸ map (algebraMap R S) p) := IsScalarTower.of_algebraMap_eq fun x => by rw [Quotient.algebraMap_eq, Quotient.algebraMap_quotient_map_quotient, Quotient.mk_algebraMap] instance QuotientMapQuotient.isNoetherian [Algebra R S] [IsNoetherian R S] (I : Ideal R) : IsNoetherian (R ⧸ I) (S ⧸ Ideal.map (algebraMap R S) I) := isNoetherian_of_tower R <| isNoetherian_of_surjective S (Ideal.Quotient.mkₐ R _).toLinearMap <| LinearMap.range_eq_top.mpr Ideal.Quotient.mk_surjective end CommRing section IsDomain variable {S : Type*} [CommRing S] {f : R →+* S} {I J : Ideal S} theorem exists_coeff_ne_zero_mem_comap_of_root_mem [IsDomain S] {r : S} (r_ne_zero : r ≠ 0) (hr : r ∈ I) {p : R[X]} : p ≠ 0 → p.eval₂ f r = 0 → ∃ i, p.coeff i ≠ 0 ∧ p.coeff i ∈ I.comap f := exists_coeff_ne_zero_mem_comap_of_non_zero_divisor_root_mem (fun {_} h => Or.resolve_right (mul_eq_zero.mp h) r_ne_zero) hr theorem exists_coeff_mem_comap_sdiff_comap_of_root_mem_sdiff [IsPrime I] (hIJ : I ≤ J) {r : S} (hr : r ∈ (J : Set S) \ I) {p : R[X]} (p_ne_zero : p.map (Quotient.mk (I.comap f)) ≠ 0) (hpI : p.eval₂ f r ∈ I) : ∃ i, p.coeff i ∈ (J.comap f : Set R) \ I.comap f := by obtain ⟨hrJ, hrI⟩ := hr have rbar_ne_zero : Ideal.Quotient.mk I r ≠ 0 := mt (Quotient.mk_eq_zero I).mp hrI have rbar_mem_J : Ideal.Quotient.mk I r ∈ J.map (Ideal.Quotient.mk I) := mem_map_of_mem _ hrJ have quotient_f : ∀ x ∈ I.comap f, (Ideal.Quotient.mk I).comp f x = 0 := by simp [Quotient.eq_zero_iff_mem] have rbar_root : (p.map (Ideal.Quotient.mk (I.comap f))).eval₂ (Quotient.lift (I.comap f) _ quotient_f) (Ideal.Quotient.mk I r) = 0 := by convert Quotient.eq_zero_iff_mem.mpr hpI exact _root_.trans (eval₂_map _ _ _) (hom_eval₂ p f (Ideal.Quotient.mk I) r).symm obtain ⟨i, ne_zero, mem⟩ := exists_coeff_ne_zero_mem_comap_of_root_mem rbar_ne_zero rbar_mem_J p_ne_zero rbar_root rw [coeff_map] at ne_zero mem refine ⟨i, (mem_quotient_iff_mem hIJ).mp ?_, mt ?_ ne_zero⟩ · simpa using mem simp [Quotient.eq_zero_iff_mem] theorem comap_lt_comap_of_root_mem_sdiff [I.IsPrime] (hIJ : I ≤ J) {r : S} (hr : r ∈ (J : Set S) \ I) {p : R[X]} (p_ne_zero : p.map (Quotient.mk (I.comap f)) ≠ 0) (hp : p.eval₂ f r ∈ I) : I.comap f < J.comap f := let ⟨i, hJ, hI⟩ := exists_coeff_mem_comap_sdiff_comap_of_root_mem_sdiff hIJ hr p_ne_zero hp SetLike.lt_iff_le_and_exists.mpr ⟨comap_mono hIJ, p.coeff i, hJ, hI⟩ theorem mem_of_one_mem (h : (1 : S) ∈ I) (x) : x ∈ I := (I.eq_top_iff_one.mpr h).symm ▸ mem_top theorem comap_lt_comap_of_integral_mem_sdiff [Algebra R S] [hI : I.IsPrime] (hIJ : I ≤ J) {x : S} (mem : x ∈ (J : Set S) \ I) (integral : IsIntegral R x) : I.comap (algebraMap R S) < J.comap (algebraMap R S) := by obtain ⟨p, p_monic, hpx⟩ := integral refine comap_lt_comap_of_root_mem_sdiff hIJ mem (map_monic_ne_zero p_monic) ?_ convert I.zero_mem theorem comap_ne_bot_of_root_mem [IsDomain S] {r : S} (r_ne_zero : r ≠ 0) (hr : r ∈ I) {p : R[X]} (p_ne_zero : p ≠ 0) (hp : p.eval₂ f r = 0) : I.comap f ≠ ⊥ := fun h => let ⟨_, hi, mem⟩ := exists_coeff_ne_zero_mem_comap_of_root_mem r_ne_zero hr p_ne_zero hp absurd (mem_bot.mp (eq_bot_iff.mp h mem)) hi theorem isMaximal_of_isIntegral_of_isMaximal_comap [Algebra R S] [Algebra.IsIntegral R S] (I : Ideal S) [I.IsPrime] (hI : IsMaximal (I.comap (algebraMap R S))) : IsMaximal I := ⟨⟨mt comap_eq_top_iff.mpr hI.1.1, fun _ I_lt_J => let ⟨I_le_J, x, hxJ, hxI⟩ := SetLike.lt_iff_le_and_exists.mp I_lt_J comap_eq_top_iff.1 <| hI.1.2 _ (comap_lt_comap_of_integral_mem_sdiff I_le_J ⟨hxJ, hxI⟩ (Algebra.IsIntegral.isIntegral x))⟩⟩ theorem isMaximal_of_isIntegral_of_isMaximal_comap' (f : R →+* S) (hf : f.IsIntegral) (I : Ideal S) [I.IsPrime] (hI : IsMaximal (I.comap f)) : IsMaximal I := let _ : Algebra R S := f.toAlgebra have : Algebra.IsIntegral R S := ⟨hf⟩ isMaximal_of_isIntegral_of_isMaximal_comap (R := R) (S := S) I hI variable [Algebra R S] theorem comap_ne_bot_of_algebraic_mem [IsDomain S] {x : S} (x_ne_zero : x ≠ 0) (x_mem : x ∈ I) (hx : IsAlgebraic R x) : I.comap (algebraMap R S) ≠ ⊥ := let ⟨_, p_ne_zero, hp⟩ := hx comap_ne_bot_of_root_mem x_ne_zero x_mem p_ne_zero hp theorem comap_ne_bot_of_integral_mem [Nontrivial R] [IsDomain S] {x : S} (x_ne_zero : x ≠ 0) (x_mem : x ∈ I) (hx : IsIntegral R x) : I.comap (algebraMap R S) ≠ ⊥ := comap_ne_bot_of_algebraic_mem x_ne_zero x_mem hx.isAlgebraic theorem eq_bot_of_comap_eq_bot [Nontrivial R] [IsDomain S] [Algebra.IsIntegral R S] (hI : I.comap (algebraMap R S) = ⊥) : I = ⊥ := by refine eq_bot_iff.2 fun x hx => ?_ by_cases hx0 : x = 0 · exact hx0.symm ▸ Ideal.zero_mem ⊥ · exact absurd hI (comap_ne_bot_of_integral_mem hx0 hx (Algebra.IsIntegral.isIntegral x)) theorem isMaximal_comap_of_isIntegral_of_isMaximal [Algebra.IsIntegral R S] (I : Ideal S) [hI : I.IsMaximal] : IsMaximal (I.comap (algebraMap R S)) := by refine Ideal.Quotient.maximal_of_isField _ ?_ haveI : IsPrime (I.comap (algebraMap R S)) := comap_isPrime _ _ exact isField_of_isIntegral_of_isField algebraMap_quotient_injective (by rwa [← Quotient.maximal_ideal_iff_isField_quotient]) theorem isMaximal_comap_of_isIntegral_of_isMaximal' {R S : Type*} [CommRing R] [CommRing S] (f : R →+* S) (hf : f.IsIntegral) (I : Ideal S) [I.IsMaximal] : IsMaximal (I.comap f) := let _ : Algebra R S := f.toAlgebra have : Algebra.IsIntegral R S := ⟨hf⟩ isMaximal_comap_of_isIntegral_of_isMaximal (R := R) (S := S) I section IsIntegralClosure variable (S) {A : Type*} [CommRing A] variable [Algebra R A] [Algebra A S] [IsScalarTower R A S] [IsIntegralClosure A R S] theorem IsIntegralClosure.comap_lt_comap {I J : Ideal A} [I.IsPrime] (I_lt_J : I < J) : I.comap (algebraMap R A) < J.comap (algebraMap R A) := let ⟨I_le_J, x, hxJ, hxI⟩ := SetLike.lt_iff_le_and_exists.mp I_lt_J comap_lt_comap_of_integral_mem_sdiff I_le_J ⟨hxJ, hxI⟩ (IsIntegralClosure.isIntegral R S x) theorem IsIntegralClosure.isMaximal_of_isMaximal_comap (I : Ideal A) [I.IsPrime] (hI : IsMaximal (I.comap (algebraMap R A))) : IsMaximal I := have : Algebra.IsIntegral R A := IsIntegralClosure.isIntegral_algebra R S isMaximal_of_isIntegral_of_isMaximal_comap I hI variable [IsDomain A] theorem IsIntegralClosure.comap_ne_bot [Nontrivial R] {I : Ideal A} (I_ne_bot : I ≠ ⊥) : I.comap (algebraMap R A) ≠ ⊥ := let ⟨x, x_mem, x_ne_zero⟩ := I.ne_bot_iff.mp I_ne_bot comap_ne_bot_of_integral_mem x_ne_zero x_mem (IsIntegralClosure.isIntegral R S x) theorem IsIntegralClosure.eq_bot_of_comap_eq_bot [Nontrivial R] {I : Ideal A} : I.comap (algebraMap R A) = ⊥ → I = ⊥ := by -- Porting note: `imp_of_not_imp_not` seems not existing contrapose; exact (IsIntegralClosure.comap_ne_bot S) end IsIntegralClosure theorem IntegralClosure.comap_lt_comap {I J : Ideal (integralClosure R S)} [I.IsPrime] (I_lt_J : I < J) : I.comap (algebraMap R (integralClosure R S)) < J.comap (algebraMap R (integralClosure R S)) := IsIntegralClosure.comap_lt_comap S I_lt_J theorem IntegralClosure.isMaximal_of_isMaximal_comap (I : Ideal (integralClosure R S)) [I.IsPrime] (hI : IsMaximal (I.comap (algebraMap R (integralClosure R S)))) : IsMaximal I := IsIntegralClosure.isMaximal_of_isMaximal_comap S I hI section variable [IsDomain S] theorem IntegralClosure.comap_ne_bot [Nontrivial R] {I : Ideal (integralClosure R S)} (I_ne_bot : I ≠ ⊥) : I.comap (algebraMap R (integralClosure R S)) ≠ ⊥ := IsIntegralClosure.comap_ne_bot S I_ne_bot theorem IntegralClosure.eq_bot_of_comap_eq_bot [Nontrivial R] {I : Ideal (integralClosure R S)} : I.comap (algebraMap R (integralClosure R S)) = ⊥ → I = ⊥ := IsIntegralClosure.eq_bot_of_comap_eq_bot S /-- `comap (algebraMap R S)` is a surjection from the prime spec of `R` to prime spec of `S`. `hP : (algebraMap R S).ker ≤ P` is a slight generalization of the extension being injective -/ theorem exists_ideal_over_prime_of_isIntegral_of_isDomain [Algebra.IsIntegral R S] (P : Ideal R) [IsPrime P] (hP : RingHom.ker (algebraMap R S) ≤ P) : ∃ Q : Ideal S, IsPrime Q ∧ Q.comap (algebraMap R S) = P := by have hP0 : (0 : S) ∉ Algebra.algebraMapSubmonoid S P.primeCompl := by rintro ⟨x, ⟨hx, x0⟩⟩ exact absurd (hP x0) hx let Rₚ := Localization P.primeCompl let Sₚ := Localization (Algebra.algebraMapSubmonoid S P.primeCompl) letI : IsDomain (Localization (Algebra.algebraMapSubmonoid S P.primeCompl)) := IsLocalization.isDomain_localization (le_nonZeroDivisors_of_noZeroDivisors hP0) obtain ⟨Qₚ : Ideal Sₚ, Qₚ_maximal⟩ := exists_maximal Sₚ let _ : Algebra Rₚ Sₚ := localizationAlgebra P.primeCompl S have : Algebra.IsIntegral Rₚ Sₚ := ⟨isIntegral_localization⟩ have Qₚ_max : IsMaximal (comap _ Qₚ) := isMaximal_comap_of_isIntegral_of_isMaximal (R := Rₚ) (S := Sₚ) Qₚ refine ⟨comap (algebraMap S Sₚ) Qₚ, ⟨comap_isPrime _ Qₚ, ?_⟩⟩ convert Localization.AtPrime.comap_maximalIdeal (I := P) rw [comap_comap, ← LocalRing.eq_maximalIdeal Qₚ_max, ← @IsLocalization.map_comp (P := S) (Q := Sₚ) (g := algebraMap R S) (M := P.primeCompl) (T := Algebra.algebraMapSubmonoid S P.primeCompl) (S := Rₚ) _ _ _ _ _ _ (fun p hp => Algebra.mem_algebraMapSubmonoid_of_mem ⟨p, hp⟩) _ _] rfl end /-- More general going-up theorem than `exists_ideal_over_prime_of_isIntegral_of_isDomain`. TODO: Version of going-up theorem with arbitrary length chains (by induction on this)? Not sure how best to write an ascending chain in Lean -/ theorem exists_ideal_over_prime_of_isIntegral_of_isPrime [Algebra.IsIntegral R S] (P : Ideal R) [IsPrime P] (I : Ideal S) [IsPrime I] (hIP : I.comap (algebraMap R S) ≤ P) : ∃ Q ≥ I, IsPrime Q ∧ Q.comap (algebraMap R S) = P := by obtain ⟨Q' : Ideal (S ⧸ I), ⟨Q'_prime, hQ'⟩⟩ := @exists_ideal_over_prime_of_isIntegral_of_isDomain (R ⧸ I.comap (algebraMap R S)) _ (S ⧸ I) _ Ideal.quotientAlgebra _ _ (map (Ideal.Quotient.mk (I.comap (algebraMap R S))) P) (map_isPrime_of_surjective Quotient.mk_surjective (by simp [hIP])) (le_trans (le_of_eq ((RingHom.injective_iff_ker_eq_bot _).1 algebraMap_quotient_injective)) bot_le) refine ⟨Q'.comap _, le_trans (le_of_eq mk_ker.symm) (ker_le_comap _), ⟨comap_isPrime _ Q', ?_⟩⟩ rw [comap_comap] refine _root_.trans ?_ (_root_.trans (congr_arg (comap (Ideal.Quotient.mk (comap (algebraMap R S) I))) hQ') ?_) · rw [comap_comap] exact congr_arg (comap · Q') (RingHom.ext fun r => rfl) · refine _root_.trans (comap_map_of_surjective _ Quotient.mk_surjective _) (sup_eq_left.2 ?_) simpa [← RingHom.ker_eq_comap_bot] using hIP lemma exists_ideal_comap_le_prime (P : Ideal R) [P.IsPrime] (I : Ideal S) (hI : I.comap (algebraMap R S) ≤ P) : ∃ Q ≥ I, Q.IsPrime ∧ Q.comap (algebraMap R S) ≤ P := by let Sₚ := Localization (Algebra.algebraMapSubmonoid S P.primeCompl) let Iₚ := I.map (algebraMap S Sₚ) have hI' : Disjoint (Algebra.algebraMapSubmonoid S P.primeCompl : Set S) I := by rw [Set.disjoint_iff] rintro _ ⟨⟨x, hx : x ∉ P, rfl⟩, hx'⟩ exact (hx (hI hx')).elim have : Iₚ ≠ ⊤ := by rw [Ne, Ideal.eq_top_iff_one, IsLocalization.mem_map_algebraMap_iff (Algebra.algebraMapSubmonoid S P.primeCompl) Sₚ, not_exists] simp only [one_mul, IsLocalization.eq_iff_exists (Algebra.algebraMapSubmonoid S P.primeCompl), not_exists] exact fun x c ↦ hI'.ne_of_mem (mul_mem c.2 x.2.2) (I.mul_mem_left c x.1.2) obtain ⟨M, hM, hM'⟩ := Ideal.exists_le_maximal _ this refine ⟨_, Ideal.map_le_iff_le_comap.mp hM', hM.isPrime.comap _, ?_⟩ intro x hx by_contra hx' exact Set.disjoint_left.mp ((IsLocalization.isPrime_iff_isPrime_disjoint (Algebra.algebraMapSubmonoid S P.primeCompl) Sₚ M).mp hM.isPrime).2 ⟨_, hx', rfl⟩ hx theorem exists_ideal_over_prime_of_isIntegral [Algebra.IsIntegral R S] (P : Ideal R) [IsPrime P] (I : Ideal S) (hIP : I.comap (algebraMap R S) ≤ P) : ∃ Q ≥ I, IsPrime Q ∧ Q.comap (algebraMap R S) = P := by have ⟨P', hP, hP', hP''⟩ := exists_ideal_comap_le_prime P I hIP obtain ⟨Q, hQ, hQ', hQ''⟩ := exists_ideal_over_prime_of_isIntegral_of_isPrime P P' hP'' exact ⟨Q, hP.trans hQ, hQ', hQ''⟩ /-- `comap (algebraMap R S)` is a surjection from the max spec of `S` to max spec of `R`. `hP : (algebraMap R S).ker ≤ P` is a slight generalization of the extension being injective -/ theorem exists_ideal_over_maximal_of_isIntegral [Algebra.IsIntegral R S] (P : Ideal R) [P_max : IsMaximal P] (hP : RingHom.ker (algebraMap R S) ≤ P) : ∃ Q : Ideal S, IsMaximal Q ∧ Q.comap (algebraMap R S) = P := by obtain ⟨Q, -, Q_prime, hQ⟩ := exists_ideal_over_prime_of_isIntegral P ⊥ hP exact ⟨Q, isMaximal_of_isIntegral_of_isMaximal_comap _ (hQ.symm ▸ P_max), hQ⟩ lemma map_eq_top_iff_of_ker_le (f : R →+* S) {I : Ideal R} (hf₁ : RingHom.ker f ≤ I) (hf₂ : f.IsIntegral) : I.map f = ⊤ ↔ I = ⊤ := by constructor; swap · rintro rfl; exact Ideal.map_top _ contrapose intro h obtain ⟨m, _, hm⟩ := Ideal.exists_le_maximal I h let _ := f.toAlgebra have : Algebra.IsIntegral _ _ := ⟨hf₂⟩ obtain ⟨m', _, rfl⟩ := exists_ideal_over_maximal_of_isIntegral m (hf₁.trans hm) rw [← map_le_iff_le_comap] at hm exact (hm.trans_lt (lt_top_iff_ne_top.mpr (IsMaximal.ne_top ‹_›))).ne lemma map_eq_top_iff (f : R →+* S) {I : Ideal R} (hf₁ : Function.Injective f) (hf₂ : f.IsIntegral) : I.map f = ⊤ ↔ I = ⊤ := map_eq_top_iff_of_ker_le f (by simp [f.injective_iff_ker_eq_bot.mp hf₁]) hf₂ end IsDomain end Ideal
RingTheory\Ideal\Pointwise.lean
/- Copyright (c) 2024 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.RingTheory.Ideal.Maps /-! # Pointwise instances on `Ideal`s This file provides the action `Ideal.pointwiseMulAction` which morally matches the action of `mulActionSet` (though here an extra `Ideal.span` is inserted). This actions is available in the `Pointwise` locale. ## Implementation notes This file is similar (but not identical) to `Mathlib/Algebra/Ring/Subsemiring/Pointwise.lean`. Where possible, try to keep them in sync. -/ open Set variable {M R : Type*} namespace Ideal section Monoid variable [Monoid M] [CommRing R] [MulSemiringAction M R] /-- The action on an ideal corresponding to applying the action to every element. This is available as an instance in the `Pointwise` locale. -/ protected def pointwiseMulSemiringAction : MulSemiringAction M (Ideal R) where smul a := Ideal.map (MulSemiringAction.toRingHom _ _ a) one_smul I := congr_arg (I.map ·) (RingHom.ext <| one_smul M) |>.trans I.map_id mul_smul a₁ a₂ I := congr_arg (I.map ·) (RingHom.ext <| mul_smul _ _) |>.trans (I.map_map _ _).symm smul_one a := by simp only [Ideal.one_eq_top]; exact Ideal.map_top _ smul_mul a I J := Ideal.map_mul (MulSemiringAction.toRingHom _ _ a) I J smul_add a I J := Ideal.map_sup _ I J smul_zero a := Ideal.map_bot scoped[Pointwise] attribute [instance] Ideal.pointwiseMulSemiringAction open Pointwise theorem pointwise_smul_def {a : M} (S : Ideal R) : a • S = S.map (MulSemiringAction.toRingHom _ _ a) := rfl -- note: unlike with `Subring`, `pointwise_smul_toAddSubgroup` wouldn't be true theorem smul_mem_pointwise_smul (m : M) (r : R) (S : Ideal R) : r ∈ S → m • r ∈ m • S := fun h => subset_span <| Set.smul_mem_smul_set h instance : CovariantClass M (Ideal R) HSMul.hSMul LE.le := ⟨fun _ _ => map_mono⟩ -- note: unlike with `Subring`, `mem_smul_pointwise_iff_exists` wouldn't be true @[simp] theorem smul_bot (a : M) : a • (⊥ : Ideal R) = ⊥ := map_bot theorem smul_sup (a : M) (S T : Ideal R) : a • (S ⊔ T) = a • S ⊔ a • T := map_sup _ _ _ theorem smul_closure (a : M) (s : Set R) : a • span s = span (a • s) := Ideal.map_span _ _ instance pointwise_central_scalar [MulSemiringAction Mᵐᵒᵖ R] [IsCentralScalar M R] : IsCentralScalar M (Ideal R) := ⟨fun _ S => (congr_arg fun f => S.map f) <| RingHom.ext <| op_smul_eq_smul _⟩ end Monoid section Group variable [Group M] [CommRing R] [MulSemiringAction M R] open Pointwise theorem pointwise_smul_eq_comap {a : M} (S : Ideal R) : a • S = S.comap (MulSemiringAction.toRingAut _ _ a).symm := by ext simp [pointwise_smul_def] rfl @[simp] theorem smul_mem_pointwise_smul_iff {a : M} {S : Ideal R} {x : R} : a • x ∈ a • S ↔ x ∈ S := ⟨fun h => by simpa using smul_mem_pointwise_smul a⁻¹ _ _ h, smul_mem_pointwise_smul _ _ _⟩ theorem mem_pointwise_smul_iff_inv_smul_mem {a : M} {S : Ideal R} {x : R} : x ∈ a • S ↔ a⁻¹ • x ∈ S := ⟨fun h => by simpa using smul_mem_pointwise_smul a⁻¹ _ _ h, fun h => by simpa using smul_mem_pointwise_smul a _ _ h⟩ @[simp] theorem pointwise_smul_toAddSubmonoid (a : M) (S : Ideal R) (ha : Function.Surjective fun r : R => a • r) : (a • S).toAddSubmonoid = a • S.toAddSubmonoid := by ext exact Ideal.mem_map_iff_of_surjective _ <| by exact ha @[simp] theorem pointwise_smul_toAddSubGroup (a : M) (S : Ideal R) (ha : Function.Surjective fun r : R => a • r) : (a • S).toAddSubgroup = a • S.toAddSubgroup := by ext exact Ideal.mem_map_iff_of_surjective _ <| by exact ha theorem mem_inv_pointwise_smul_iff {a : M} {S : Ideal R} {x : R} : x ∈ a⁻¹ • S ↔ a • x ∈ S := by rw [mem_pointwise_smul_iff_inv_smul_mem, inv_inv] @[simp] theorem pointwise_smul_le_pointwise_smul_iff {a : M} {S T : Ideal R} : a • S ≤ a • T ↔ S ≤ T := ⟨fun h => by simpa using smul_mono_right a⁻¹ h, fun h => smul_mono_right a h⟩ theorem pointwise_smul_subset_iff {a : M} {S T : Ideal R} : a • S ≤ T ↔ S ≤ a⁻¹ • T := by rw [← pointwise_smul_le_pointwise_smul_iff (a := a⁻¹), inv_smul_smul] theorem subset_pointwise_smul_iff {a : M} {S T : Ideal R} : S ≤ a • T ↔ a⁻¹ • S ≤ T := by rw [← pointwise_smul_le_pointwise_smul_iff (a := a⁻¹), inv_smul_smul] /-! TODO: add `equivSMul` like we have for subgroup. -/ end Group end Ideal
RingTheory\Ideal\Prod.lean
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.RingTheory.Ideal.Maps /-! # Ideals in product rings For commutative rings `R` and `S` and ideals `I ≤ R`, `J ≤ S`, we define `Ideal.prod I J` as the product `I × J`, viewed as an ideal of `R × S`. In `ideal_prod_eq` we show that every ideal of `R × S` is of this form. Furthermore, we show that every prime ideal of `R × S` is of the form `p × S` or `R × p`, where `p` is a prime ideal. -/ universe u v variable {R : Type u} {S : Type v} [Semiring R] [Semiring S] (I I' : Ideal R) (J J' : Ideal S) namespace Ideal /-- `I × J` as an ideal of `R × S`. -/ def prod : Ideal (R × S) where carrier := { x | x.fst ∈ I ∧ x.snd ∈ J } zero_mem' := by simp add_mem' := by rintro ⟨a₁, a₂⟩ ⟨b₁, b₂⟩ ⟨ha₁, ha₂⟩ ⟨hb₁, hb₂⟩ exact ⟨I.add_mem ha₁ hb₁, J.add_mem ha₂ hb₂⟩ smul_mem' := by rintro ⟨a₁, a₂⟩ ⟨b₁, b₂⟩ ⟨hb₁, hb₂⟩ exact ⟨I.mul_mem_left _ hb₁, J.mul_mem_left _ hb₂⟩ @[simp] theorem mem_prod {r : R} {s : S} : (⟨r, s⟩ : R × S) ∈ prod I J ↔ r ∈ I ∧ s ∈ J := Iff.rfl @[simp] theorem prod_top_top : prod (⊤ : Ideal R) (⊤ : Ideal S) = ⊤ := Ideal.ext <| by simp /-- Every ideal of the product ring is of the form `I × J`, where `I` and `J` can be explicitly given as the image under the projection maps. -/ theorem ideal_prod_eq (I : Ideal (R × S)) : I = Ideal.prod (map (RingHom.fst R S) I : Ideal R) (map (RingHom.snd R S) I) := by apply Ideal.ext rintro ⟨r, s⟩ rw [mem_prod, mem_map_iff_of_surjective (RingHom.fst R S) Prod.fst_surjective, mem_map_iff_of_surjective (RingHom.snd R S) Prod.snd_surjective] refine ⟨fun h => ⟨⟨_, ⟨h, rfl⟩⟩, ⟨_, ⟨h, rfl⟩⟩⟩, ?_⟩ rintro ⟨⟨⟨r, s'⟩, ⟨h₁, rfl⟩⟩, ⟨⟨r', s⟩, ⟨h₂, rfl⟩⟩⟩ simpa using I.add_mem (I.mul_mem_left (1, 0) h₁) (I.mul_mem_left (0, 1) h₂) @[simp] theorem map_fst_prod (I : Ideal R) (J : Ideal S) : map (RingHom.fst R S) (prod I J) = I := by ext x rw [mem_map_iff_of_surjective (RingHom.fst R S) Prod.fst_surjective] exact ⟨by rintro ⟨x, ⟨h, rfl⟩⟩ exact h.1, fun h => ⟨⟨x, 0⟩, ⟨⟨h, Ideal.zero_mem _⟩, rfl⟩⟩⟩ @[simp] theorem map_snd_prod (I : Ideal R) (J : Ideal S) : map (RingHom.snd R S) (prod I J) = J := by ext x rw [mem_map_iff_of_surjective (RingHom.snd R S) Prod.snd_surjective] exact ⟨by rintro ⟨x, ⟨h, rfl⟩⟩ exact h.2, fun h => ⟨⟨0, x⟩, ⟨⟨Ideal.zero_mem _, h⟩, rfl⟩⟩⟩ @[simp] theorem map_prodComm_prod : map ((RingEquiv.prodComm : R × S ≃+* S × R) : R × S →+* S × R) (prod I J) = prod J I := by refine Trans.trans (ideal_prod_eq _) ?_ simp [map_map] /-- Ideals of `R × S` are in one-to-one correspondence with pairs of ideals of `R` and ideals of `S`. -/ def idealProdEquiv : Ideal (R × S) ≃ Ideal R × Ideal S where toFun I := ⟨map (RingHom.fst R S) I, map (RingHom.snd R S) I⟩ invFun I := prod I.1 I.2 left_inv I := (ideal_prod_eq I).symm right_inv := fun ⟨I, J⟩ => by simp @[simp] theorem idealProdEquiv_symm_apply (I : Ideal R) (J : Ideal S) : idealProdEquiv.symm ⟨I, J⟩ = prod I J := rfl theorem prod.ext_iff {I I' : Ideal R} {J J' : Ideal S} : prod I J = prod I' J' ↔ I = I' ∧ J = J' := by simp only [← idealProdEquiv_symm_apply, idealProdEquiv.symm.injective.eq_iff, Prod.mk.inj_iff] theorem isPrime_of_isPrime_prod_top {I : Ideal R} (h : (Ideal.prod I (⊤ : Ideal S)).IsPrime) : I.IsPrime := by constructor · contrapose! h rw [h, prod_top_top, isPrime_iff] simp [isPrime_iff, h] · intro x y hxy have : (⟨x, 1⟩ : R × S) * ⟨y, 1⟩ ∈ prod I ⊤ := by rw [Prod.mk_mul_mk, mul_one, mem_prod] exact ⟨hxy, trivial⟩ simpa using h.mem_or_mem this theorem isPrime_of_isPrime_prod_top' {I : Ideal S} (h : (Ideal.prod (⊤ : Ideal R) I).IsPrime) : I.IsPrime := by apply isPrime_of_isPrime_prod_top (S := R) rw [← map_prodComm_prod] -- Note: couldn't synthesize the right instances without the `R` and `S` hints exact map_isPrime_of_equiv (RingEquiv.prodComm (R := R) (S := S)) theorem isPrime_ideal_prod_top {I : Ideal R} [h : I.IsPrime] : (prod I (⊤ : Ideal S)).IsPrime := by constructor · rcases h with ⟨h, -⟩ contrapose! h rw [← prod_top_top, prod.ext_iff] at h exact h.1 rintro ⟨r₁, s₁⟩ ⟨r₂, s₂⟩ ⟨h₁, _⟩ cases' h.mem_or_mem h₁ with h h · exact Or.inl ⟨h, trivial⟩ · exact Or.inr ⟨h, trivial⟩ theorem isPrime_ideal_prod_top' {I : Ideal S} [h : I.IsPrime] : (prod (⊤ : Ideal R) I).IsPrime := by letI : IsPrime (prod I (⊤ : Ideal R)) := isPrime_ideal_prod_top rw [← map_prodComm_prod] -- Note: couldn't synthesize the right instances without the `R` and `S` hints exact map_isPrime_of_equiv (RingEquiv.prodComm (R := S) (S := R)) theorem ideal_prod_prime_aux {I : Ideal R} {J : Ideal S} : (Ideal.prod I J).IsPrime → I = ⊤ ∨ J = ⊤ := by contrapose! simp only [ne_top_iff_one, isPrime_iff, not_and, not_forall, not_or] exact fun ⟨hI, hJ⟩ _ => ⟨⟨0, 1⟩, ⟨1, 0⟩, by simp, by simp [hJ], by simp [hI]⟩ /-- Classification of prime ideals in product rings: the prime ideals of `R × S` are precisely the ideals of the form `p × S` or `R × p`, where `p` is a prime ideal of `R` or `S`. -/ theorem ideal_prod_prime (I : Ideal (R × S)) : I.IsPrime ↔ (∃ p : Ideal R, p.IsPrime ∧ I = Ideal.prod p ⊤) ∨ ∃ p : Ideal S, p.IsPrime ∧ I = Ideal.prod ⊤ p := by constructor · rw [ideal_prod_eq I] intro hI rcases ideal_prod_prime_aux hI with (h | h) · right rw [h] at hI ⊢ exact ⟨_, ⟨isPrime_of_isPrime_prod_top' hI, rfl⟩⟩ · left rw [h] at hI ⊢ exact ⟨_, ⟨isPrime_of_isPrime_prod_top hI, rfl⟩⟩ · rintro (⟨p, ⟨h, rfl⟩⟩ | ⟨p, ⟨h, rfl⟩⟩) · exact isPrime_ideal_prod_top · exact isPrime_ideal_prod_top' end Ideal
RingTheory\Ideal\Quotient.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Chris Hughes, Mario Carneiro, Anne Baanen -/ import Mathlib.LinearAlgebra.Quotient import Mathlib.RingTheory.Congruence.Basic import Mathlib.RingTheory.Ideal.Basic import Mathlib.Tactic.FinCases /-! # Ideal quotients This file defines ideal quotients as a special case of submodule quotients and proves some basic results about these quotients. See `Algebra.RingQuot` for quotients of non-commutative rings. ## Main definitions - `Ideal.Quotient`: the quotient of a commutative ring `R` by an ideal `I : Ideal R` -/ universe u v w namespace Ideal open Set variable {R : Type u} [CommRing R] (I : Ideal R) {a b : R} variable {S : Type v} -- Note that at present `Ideal` means a left-ideal, -- so this quotient is only useful in a commutative ring. -- We should develop quotients by two-sided ideals as well. /-- The quotient `R/I` of a ring `R` by an ideal `I`. The ideal quotient of `I` is defined to equal the quotient of `I` as an `R`-submodule of `R`. This definition uses `abbrev` so that typeclass instances can be shared between `Ideal.Quotient I` and `Submodule.Quotient I`. -/ @[instance] abbrev instHasQuotient : HasQuotient R (Ideal R) := Submodule.hasQuotient namespace Quotient variable {I} {x y : R} instance one (I : Ideal R) : One (R ⧸ I) := ⟨Submodule.Quotient.mk 1⟩ /-- On `Ideal`s, `Submodule.quotientRel` is a ring congruence. -/ protected def ringCon (I : Ideal R) : RingCon R := { QuotientAddGroup.con I.toAddSubgroup with mul' := fun {a₁ b₁ a₂ b₂} h₁ h₂ => by rw [Submodule.quotientRel_r_def] at h₁ h₂ ⊢ have F := I.add_mem (I.mul_mem_left a₂ h₁) (I.mul_mem_right b₁ h₂) have : a₁ * a₂ - b₁ * b₂ = a₂ * (a₁ - b₁) + (a₂ - b₂) * b₁ := by rw [mul_sub, sub_mul, sub_add_sub_cancel, mul_comm, mul_comm b₁] rwa [← this] at F } instance commRing (I : Ideal R) : CommRing (R ⧸ I) := inferInstanceAs (CommRing (Quotient.ringCon I).Quotient) -- Sanity test to make sure no diamonds have emerged in `commRing` example : (commRing I).toAddCommGroup = Submodule.Quotient.addCommGroup I := rfl -- this instance is harder to find than the one via `Algebra α (R ⧸ I)`, so use a lower priority instance (priority := 100) isScalarTower_right {α} [SMul α R] [IsScalarTower α R R] : IsScalarTower α (R ⧸ I) (R ⧸ I) := (Quotient.ringCon I).isScalarTower_right instance smulCommClass {α} [SMul α R] [IsScalarTower α R R] [SMulCommClass α R R] : SMulCommClass α (R ⧸ I) (R ⧸ I) := (Quotient.ringCon I).smulCommClass instance smulCommClass' {α} [SMul α R] [IsScalarTower α R R] [SMulCommClass R α R] : SMulCommClass (R ⧸ I) α (R ⧸ I) := (Quotient.ringCon I).smulCommClass' /-- The ring homomorphism from a ring `R` to a quotient ring `R/I`. -/ def mk (I : Ideal R) : R →+* R ⧸ I where toFun a := Submodule.Quotient.mk a map_zero' := rfl map_one' := rfl map_mul' _ _ := rfl map_add' _ _ := rfl instance {I : Ideal R} : Coe R (R ⧸ I) := ⟨Ideal.Quotient.mk I⟩ /-- Two `RingHom`s from the quotient by an ideal are equal if their compositions with `Ideal.Quotient.mk'` are equal. See note [partially-applied ext lemmas]. -/ @[ext 1100] theorem ringHom_ext [NonAssocSemiring S] ⦃f g : R ⧸ I →+* S⦄ (h : f.comp (mk I) = g.comp (mk I)) : f = g := RingHom.ext fun x => Quotient.inductionOn' x <| (RingHom.congr_fun h : _) instance inhabited : Inhabited (R ⧸ I) := ⟨mk I 37⟩ protected theorem eq : mk I x = mk I y ↔ x - y ∈ I := Submodule.Quotient.eq I @[simp] theorem mk_eq_mk (x : R) : (Submodule.Quotient.mk x : R ⧸ I) = mk I x := rfl theorem eq_zero_iff_mem {I : Ideal R} : mk I a = 0 ↔ a ∈ I := Submodule.Quotient.mk_eq_zero _ theorem eq_zero_iff_dvd (x y : R) : Ideal.Quotient.mk (Ideal.span ({x} : Set R)) y = 0 ↔ x ∣ y := by rw [Ideal.Quotient.eq_zero_iff_mem, Ideal.mem_span_singleton] @[simp] lemma mk_singleton_self (x : R) : mk (Ideal.span {x}) x = 0 := by rw [eq_zero_iff_dvd] theorem mk_eq_mk_iff_sub_mem (x y : R) : mk I x = mk I y ↔ x - y ∈ I := by rw [← eq_zero_iff_mem, map_sub, sub_eq_zero] theorem zero_eq_one_iff {I : Ideal R} : (0 : R ⧸ I) = 1 ↔ I = ⊤ := eq_comm.trans <| eq_zero_iff_mem.trans (eq_top_iff_one _).symm theorem zero_ne_one_iff {I : Ideal R} : (0 : R ⧸ I) ≠ 1 ↔ I ≠ ⊤ := not_congr zero_eq_one_iff protected theorem nontrivial {I : Ideal R} (hI : I ≠ ⊤) : Nontrivial (R ⧸ I) := ⟨⟨0, 1, zero_ne_one_iff.2 hI⟩⟩ theorem subsingleton_iff {I : Ideal R} : Subsingleton (R ⧸ I) ↔ I = ⊤ := by rw [eq_top_iff_one, ← subsingleton_iff_zero_eq_one, eq_comm, ← (mk I).map_one, Quotient.eq_zero_iff_mem] instance : Unique (R ⧸ (⊤ : Ideal R)) := ⟨⟨0⟩, by rintro ⟨x⟩; exact Quotient.eq_zero_iff_mem.mpr Submodule.mem_top⟩ theorem mk_surjective : Function.Surjective (mk I) := fun y => Quotient.inductionOn' y fun x => Exists.intro x rfl instance : RingHomSurjective (mk I) := ⟨mk_surjective⟩ /-- If `I` is an ideal of a commutative ring `R`, if `q : R → R/I` is the quotient map, and if `s ⊆ R` is a subset, then `q⁻¹(q(s)) = ⋃ᵢ(i + s)`, the union running over all `i ∈ I`. -/ theorem quotient_ring_saturate (I : Ideal R) (s : Set R) : mk I ⁻¹' (mk I '' s) = ⋃ x : I, (fun y => x.1 + y) '' s := by ext x simp only [mem_preimage, mem_image, mem_iUnion, Ideal.Quotient.eq] exact ⟨fun ⟨a, a_in, h⟩ => ⟨⟨_, I.neg_mem h⟩, a, a_in, by simp⟩, fun ⟨⟨i, hi⟩, a, ha, Eq⟩ => ⟨a, ha, by rw [← Eq, sub_add_eq_sub_sub_swap, sub_self, zero_sub]; exact I.neg_mem hi⟩⟩ instance noZeroDivisors (I : Ideal R) [hI : I.IsPrime] : NoZeroDivisors (R ⧸ I) where eq_zero_or_eq_zero_of_mul_eq_zero {a b} := Quotient.inductionOn₂' a b fun {_ _} hab => (hI.mem_or_mem (eq_zero_iff_mem.1 hab)).elim (Or.inl ∘ eq_zero_iff_mem.2) (Or.inr ∘ eq_zero_iff_mem.2) instance isDomain (I : Ideal R) [hI : I.IsPrime] : IsDomain (R ⧸ I) := let _ := Quotient.nontrivial hI.1 NoZeroDivisors.to_isDomain _ theorem isDomain_iff_prime (I : Ideal R) : IsDomain (R ⧸ I) ↔ I.IsPrime := by refine ⟨fun H => ⟨zero_ne_one_iff.1 ?_, fun {x y} h => ?_⟩, fun h => inferInstance⟩ · haveI : Nontrivial (R ⧸ I) := ⟨H.2.1⟩ exact zero_ne_one · simp only [← eq_zero_iff_mem, (mk I).map_mul] at h ⊢ haveI := @IsDomain.to_noZeroDivisors (R ⧸ I) _ H exact eq_zero_or_eq_zero_of_mul_eq_zero h theorem exists_inv {I : Ideal R} [hI : I.IsMaximal] : ∀ {a : R ⧸ I}, a ≠ 0 → ∃ b : R ⧸ I, a * b = 1 := by rintro ⟨a⟩ h rcases hI.exists_inv (mt eq_zero_iff_mem.2 h) with ⟨b, c, hc, abc⟩ rw [mul_comm] at abc refine ⟨mk _ b, Quot.sound ?_⟩ simp only [Submodule.quotientRel_r_def] rw [← eq_sub_iff_add_eq'] at abc rwa [abc, ← neg_mem_iff (G := R) (H := I), neg_sub] at hc open Classical in /-- The quotient by a maximal ideal is a group with zero. This is a `def` rather than `instance`, since users will have computable inverses in some applications. See note [reducible non-instances]. -/ protected noncomputable abbrev groupWithZero (I : Ideal R) [hI : I.IsMaximal] : GroupWithZero (R ⧸ I) := { inv := fun a => if ha : a = 0 then 0 else Classical.choose (exists_inv ha) mul_inv_cancel := fun a (ha : a ≠ 0) => show a * dite _ _ _ = _ by rw [dif_neg ha]; exact Classical.choose_spec (exists_inv ha) inv_zero := dif_pos rfl } /-- The quotient by a maximal ideal is a field. This is a `def` rather than `instance`, since users will have computable inverses (and `qsmul`, `ratCast`) in some applications. See note [reducible non-instances]. -/ protected noncomputable abbrev field (I : Ideal R) [hI : I.IsMaximal] : Field (R ⧸ I) where __ := commRing _ __ := Quotient.groupWithZero _ nnqsmul := _ nnqsmul_def := fun q a => rfl qsmul := _ qsmul_def := fun q x => rfl /-- If the quotient by an ideal is a field, then the ideal is maximal. -/ theorem maximal_of_isField (I : Ideal R) (hqf : IsField (R ⧸ I)) : I.IsMaximal := by apply Ideal.isMaximal_iff.2 constructor · intro h rcases hqf.exists_pair_ne with ⟨⟨x⟩, ⟨y⟩, hxy⟩ exact hxy (Ideal.Quotient.eq.2 (mul_one (x - y) ▸ I.mul_mem_left _ h)) · intro J x hIJ hxnI hxJ rcases hqf.mul_inv_cancel (mt Ideal.Quotient.eq_zero_iff_mem.1 hxnI) with ⟨⟨y⟩, hy⟩ rw [← zero_add (1 : R), ← sub_self (x * y), sub_add] exact J.sub_mem (J.mul_mem_right _ hxJ) (hIJ (Ideal.Quotient.eq.1 hy)) /-- The quotient of a ring by an ideal is a field iff the ideal is maximal. -/ theorem maximal_ideal_iff_isField_quotient (I : Ideal R) : I.IsMaximal ↔ IsField (R ⧸ I) := ⟨fun h => let _i := @Quotient.field _ _ I h Field.toIsField _, maximal_of_isField _⟩ variable [Semiring S] /-- Given a ring homomorphism `f : R →+* S` sending all elements of an ideal to zero, lift it to the quotient by this ideal. -/ def lift (I : Ideal R) (f : R →+* S) (H : ∀ a : R, a ∈ I → f a = 0) : R ⧸ I →+* S := { QuotientAddGroup.lift I.toAddSubgroup f.toAddMonoidHom H with map_one' := f.map_one map_mul' := fun a₁ a₂ => Quotient.inductionOn₂' a₁ a₂ f.map_mul } @[simp] theorem lift_mk (I : Ideal R) (f : R →+* S) (H : ∀ a : R, a ∈ I → f a = 0) : lift I f H (mk I a) = f a := rfl theorem lift_surjective_of_surjective (I : Ideal R) {f : R →+* S} (H : ∀ a : R, a ∈ I → f a = 0) (hf : Function.Surjective f) : Function.Surjective (Ideal.Quotient.lift I f H) := by intro y obtain ⟨x, rfl⟩ := hf y use Ideal.Quotient.mk I x simp only [Ideal.Quotient.lift_mk] /-- The ring homomorphism from the quotient by a smaller ideal to the quotient by a larger ideal. This is the `Ideal.Quotient` version of `Quot.Factor` -/ def factor (S T : Ideal R) (H : S ≤ T) : R ⧸ S →+* R ⧸ T := Ideal.Quotient.lift S (mk T) fun _ hx => eq_zero_iff_mem.2 (H hx) @[simp] theorem factor_mk (S T : Ideal R) (H : S ≤ T) (x : R) : factor S T H (mk S x) = mk T x := rfl @[simp] theorem factor_comp_mk (S T : Ideal R) (H : S ≤ T) : (factor S T H).comp (mk S) = mk T := by ext x rw [RingHom.comp_apply, factor_mk] end Quotient /-- Quotienting by equal ideals gives equivalent rings. See also `Submodule.quotEquivOfEq` and `Ideal.quotientEquivAlgOfEq`. -/ def quotEquivOfEq {R : Type*} [CommRing R] {I J : Ideal R} (h : I = J) : R ⧸ I ≃+* R ⧸ J := { Submodule.quotEquivOfEq I J h with map_mul' := by rintro ⟨x⟩ ⟨y⟩ rfl } @[simp] theorem quotEquivOfEq_mk {R : Type*} [CommRing R] {I J : Ideal R} (h : I = J) (x : R) : quotEquivOfEq h (Ideal.Quotient.mk I x) = Ideal.Quotient.mk J x := rfl @[simp] theorem quotEquivOfEq_symm {R : Type*} [CommRing R] {I J : Ideal R} (h : I = J) : (Ideal.quotEquivOfEq h).symm = Ideal.quotEquivOfEq h.symm := by ext; rfl section Pi variable (ι : Type v) /-- `R^n/I^n` is a `R/I`-module. -/ instance modulePi : Module (R ⧸ I) ((ι → R) ⧸ I.pi ι) where smul c m := Quotient.liftOn₂' c m (fun r m => Submodule.Quotient.mk <| r • m) <| by intro c₁ m₁ c₂ m₂ hc hm apply Ideal.Quotient.eq.2 rw [Submodule.quotientRel_r_def] at hc hm intro i exact I.mul_sub_mul_mem hc (hm i) one_smul := by rintro ⟨a⟩ convert_to Ideal.Quotient.mk (I.pi ι) _ = Ideal.Quotient.mk (I.pi ι) _ congr with i; exact one_mul (a i) mul_smul := by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ convert_to Ideal.Quotient.mk (I.pi ι) _ = Ideal.Quotient.mk (I.pi ι) _ congr 1; funext i; exact mul_assoc a b (c i) smul_add := by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ convert_to Ideal.Quotient.mk (I.pi ι) _ = Ideal.Quotient.mk (I.pi ι) _ congr with i; exact mul_add a (b i) (c i) smul_zero := by rintro ⟨a⟩ convert_to Ideal.Quotient.mk (I.pi ι) _ = Ideal.Quotient.mk (I.pi ι) _ congr with _; exact mul_zero a add_smul := by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ convert_to Ideal.Quotient.mk (I.pi ι) _ = Ideal.Quotient.mk (I.pi ι) _ congr with i; exact add_mul a b (c i) zero_smul := by rintro ⟨a⟩ convert_to Ideal.Quotient.mk (I.pi ι) _ = Ideal.Quotient.mk (I.pi ι) _ congr with i; exact zero_mul (a i) /-- `R^n/I^n` is isomorphic to `(R/I)^n` as an `R/I`-module. -/ noncomputable def piQuotEquiv : ((ι → R) ⧸ I.pi ι) ≃ₗ[R ⧸ I] ι → (R ⧸ I) where toFun := fun x ↦ Quotient.liftOn' x (fun f i => Ideal.Quotient.mk I (f i)) fun a b hab => funext fun i => (Submodule.Quotient.eq' _).2 (QuotientAddGroup.leftRel_apply.mp hab i) map_add' := by rintro ⟨_⟩ ⟨_⟩; rfl map_smul' := by rintro ⟨_⟩ ⟨_⟩; rfl invFun := fun x ↦ Ideal.Quotient.mk (I.pi ι) fun i ↦ Quotient.out' (x i) left_inv := by rintro ⟨x⟩ exact Ideal.Quotient.eq.2 fun i => Ideal.Quotient.eq.1 (Quotient.out_eq' _) right_inv := by intro x ext i obtain ⟨_, _⟩ := @Quot.exists_rep _ _ (x i) convert Quotient.out_eq' (x i) /-- If `f : R^n → R^m` is an `R`-linear map and `I ⊆ R` is an ideal, then the image of `I^n` is contained in `I^m`. -/ theorem map_pi {ι : Type*} [Finite ι] {ι' : Type w} (x : ι → R) (hi : ∀ i, x i ∈ I) (f : (ι → R) →ₗ[R] ι' → R) (i : ι') : f x i ∈ I := by classical cases nonempty_fintype ι rw [pi_eq_sum_univ x] simp only [Finset.sum_apply, smul_eq_mul, map_sum, Pi.smul_apply, map_smul] exact I.sum_mem fun j _ => I.mul_mem_right _ (hi j) end Pi end Ideal
RingTheory\Ideal\QuotientOperations.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Patrick Massot -/ import Mathlib.Algebra.Algebra.Subalgebra.Operations import Mathlib.Algebra.Ring.Fin import Mathlib.RingTheory.Ideal.Quotient /-! # More operations on modules and ideals related to quotients ## Main results: - `RingHom.quotientKerEquivRange` : the **first isomorphism theorem** for commutative rings. - `RingHom.quotientKerEquivRangeS` : the **first isomorphism theorem** for a morphism from a commutative ring to a semiring. - `AlgHom.quotientKerEquivRange` : the **first isomorphism theorem** for a morphism of algebras (over a commutative semiring) - `RingHom.quotientKerEquivRangeS` : the **first isomorphism theorem** for a morphism from a commutative ring to a semiring. - `Ideal.quotientInfRingEquivPiQuotient`: the **Chinese Remainder Theorem**, version for coprime ideals (see also `ZMod.prodEquivPi` in `Data.ZMod.Quotient` for elementary versions about `ZMod`). -/ universe u v w namespace RingHom variable {R : Type u} {S : Type v} [CommRing R] [Semiring S] (f : R →+* S) /-- The induced map from the quotient by the kernel to the codomain. This is an isomorphism if `f` has a right inverse (`quotientKerEquivOfRightInverse`) / is surjective (`quotientKerEquivOfSurjective`). -/ def kerLift : R ⧸ ker f →+* S := Ideal.Quotient.lift _ f fun _ => f.mem_ker.mp @[simp] theorem kerLift_mk (r : R) : kerLift f (Ideal.Quotient.mk (ker f) r) = f r := Ideal.Quotient.lift_mk _ _ _ theorem lift_injective_of_ker_le_ideal (I : Ideal R) {f : R →+* S} (H : ∀ a : R, a ∈ I → f a = 0) (hI : ker f ≤ I) : Function.Injective (Ideal.Quotient.lift I f H) := by rw [RingHom.injective_iff_ker_eq_bot, RingHom.ker_eq_bot_iff_eq_zero] intro u hu obtain ⟨v, rfl⟩ := Ideal.Quotient.mk_surjective u rw [Ideal.Quotient.lift_mk] at hu rw [Ideal.Quotient.eq_zero_iff_mem] exact hI ((RingHom.mem_ker f).mpr hu) /-- The induced map from the quotient by the kernel is injective. -/ theorem kerLift_injective : Function.Injective (kerLift f) := lift_injective_of_ker_le_ideal (ker f) (fun a => by simp only [mem_ker, imp_self]) le_rfl variable {f} /-- The **first isomorphism theorem for commutative rings**, computable version. -/ def quotientKerEquivOfRightInverse {g : S → R} (hf : Function.RightInverse g f) : R ⧸ ker f ≃+* S := { kerLift f with toFun := kerLift f invFun := Ideal.Quotient.mk (ker f) ∘ g left_inv := by rintro ⟨x⟩ apply kerLift_injective simp only [Submodule.Quotient.quot_mk_eq_mk, Ideal.Quotient.mk_eq_mk, kerLift_mk, Function.comp_apply, hf (f x)] right_inv := hf } @[simp] theorem quotientKerEquivOfRightInverse.apply {g : S → R} (hf : Function.RightInverse g f) (x : R ⧸ ker f) : quotientKerEquivOfRightInverse hf x = kerLift f x := rfl @[simp] theorem quotientKerEquivOfRightInverse.Symm.apply {g : S → R} (hf : Function.RightInverse g f) (x : S) : (quotientKerEquivOfRightInverse hf).symm x = Ideal.Quotient.mk (ker f) (g x) := rfl variable (R) in /-- The quotient of a ring by he zero ideal is isomorphic to the ring itself. -/ def _root_.RingEquiv.quotientBot : R ⧸ (⊥ : Ideal R) ≃+* R := (Ideal.quotEquivOfEq (RingHom.ker_coe_equiv <| .refl _).symm).trans <| quotientKerEquivOfRightInverse (f := .id R) (g := _root_.id) fun _ ↦ rfl /-- The **first isomorphism theorem** for commutative rings, surjective case. -/ noncomputable def quotientKerEquivOfSurjective (hf : Function.Surjective f) : R ⧸ (ker f) ≃+* S := quotientKerEquivOfRightInverse (Classical.choose_spec hf.hasRightInverse) /-- The **first isomorphism theorem** for commutative rings (`RingHom.rangeS` version). -/ noncomputable def quotientKerEquivRangeS (f : R →+* S) : R ⧸ ker f ≃+* f.rangeS := (Ideal.quotEquivOfEq f.ker_rangeSRestrict.symm).trans <| quotientKerEquivOfSurjective f.rangeSRestrict_surjective variable {S : Type v} [Ring S] (f : R →+* S) /-- The **first isomorphism theorem** for commutative rings (`RingHom.range` version). -/ noncomputable def quotientKerEquivRange (f : R →+* S) : R ⧸ ker f ≃+* f.range := (Ideal.quotEquivOfEq f.ker_rangeRestrict.symm).trans <| quotientKerEquivOfSurjective f.rangeRestrict_surjective end RingHom namespace Ideal open Function RingHom variable {R : Type u} {S : Type v} {F : Type w} [CommRing R] [Semiring S] @[simp] theorem map_quotient_self (I : Ideal R) : map (Quotient.mk I) I = ⊥ := eq_bot_iff.2 <| Ideal.map_le_iff_le_comap.2 fun _ hx => (Submodule.mem_bot (R ⧸ I)).2 <| Ideal.Quotient.eq_zero_iff_mem.2 hx @[simp] theorem mk_ker {I : Ideal R} : ker (Quotient.mk I) = I := by ext rw [ker, mem_comap, Submodule.mem_bot, Quotient.eq_zero_iff_mem] theorem map_mk_eq_bot_of_le {I J : Ideal R} (h : I ≤ J) : I.map (Quotient.mk J) = ⊥ := by rw [map_eq_bot_iff_le_ker, mk_ker] exact h theorem ker_quotient_lift {I : Ideal R} (f : R →+* S) (H : I ≤ ker f) : ker (Ideal.Quotient.lift I f H) = f.ker.map (Quotient.mk I) := by apply Ideal.ext intro x constructor · intro hx obtain ⟨y, hy⟩ := Quotient.mk_surjective x rw [mem_ker, ← hy, Ideal.Quotient.lift_mk, ← mem_ker] at hx rw [← hy, mem_map_iff_of_surjective (Quotient.mk I) Quotient.mk_surjective] exact ⟨y, hx, rfl⟩ · intro hx rw [mem_map_iff_of_surjective (Quotient.mk I) Quotient.mk_surjective] at hx obtain ⟨y, hy⟩ := hx rw [mem_ker, ← hy.right, Ideal.Quotient.lift_mk] exact hy.left lemma injective_lift_iff {I : Ideal R} {f : R →+* S} (H : ∀ (a : R), a ∈ I → f a = 0) : Injective (Quotient.lift I f H) ↔ ker f = I := by rw [injective_iff_ker_eq_bot, ker_quotient_lift, map_eq_bot_iff_le_ker, mk_ker] constructor · exact fun h ↦ le_antisymm h H · rintro rfl; rfl lemma ker_Pi_Quotient_mk {ι : Type*} (I : ι → Ideal R) : ker (Pi.ringHom fun i : ι ↦ Quotient.mk (I i)) = ⨅ i, I i := by simp [Pi.ker_ringHom, mk_ker] @[simp] theorem bot_quotient_isMaximal_iff (I : Ideal R) : (⊥ : Ideal (R ⧸ I)).IsMaximal ↔ I.IsMaximal := ⟨fun hI => mk_ker (I := I) ▸ comap_isMaximal_of_surjective (Quotient.mk I) Quotient.mk_surjective (K := ⊥) (H := hI), fun hI => by letI := Quotient.field I exact bot_isMaximal⟩ /-- See also `Ideal.mem_quotient_iff_mem` in case `I ≤ J`. -/ @[simp] theorem mem_quotient_iff_mem_sup {I J : Ideal R} {x : R} : Quotient.mk I x ∈ J.map (Quotient.mk I) ↔ x ∈ J ⊔ I := by rw [← mem_comap, comap_map_of_surjective (Quotient.mk I) Quotient.mk_surjective, ← ker_eq_comap_bot, mk_ker] /-- See also `Ideal.mem_quotient_iff_mem_sup` if the assumption `I ≤ J` is not available. -/ theorem mem_quotient_iff_mem {I J : Ideal R} (hIJ : I ≤ J) {x : R} : Quotient.mk I x ∈ J.map (Quotient.mk I) ↔ x ∈ J := by rw [mem_quotient_iff_mem_sup, sup_eq_left.mpr hIJ] section ChineseRemainder open Function Quotient Finset variable {ι : Type*} /-- The homomorphism from `R/(⋂ i, f i)` to `∏ i, (R / f i)` featured in the Chinese Remainder Theorem. It is bijective if the ideals `f i` are coprime. -/ def quotientInfToPiQuotient (I : ι → Ideal R) : (R ⧸ ⨅ i, I i) →+* ∀ i, R ⧸ I i := Quotient.lift (⨅ i, I i) (Pi.ringHom fun i : ι ↦ Quotient.mk (I i)) (by simp [← RingHom.mem_ker, ker_Pi_Quotient_mk]) lemma quotientInfToPiQuotient_mk (I : ι → Ideal R) (x : R) : quotientInfToPiQuotient I (Quotient.mk _ x) = fun i : ι ↦ Quotient.mk (I i) x := rfl lemma quotientInfToPiQuotient_mk' (I : ι → Ideal R) (x : R) (i : ι) : quotientInfToPiQuotient I (Quotient.mk _ x) i = Quotient.mk (I i) x := rfl lemma quotientInfToPiQuotient_inj (I : ι → Ideal R) : Injective (quotientInfToPiQuotient I) := by rw [quotientInfToPiQuotient, injective_lift_iff, ker_Pi_Quotient_mk] lemma quotientInfToPiQuotient_surj [Finite ι] {I : ι → Ideal R} (hI : Pairwise fun i j => IsCoprime (I i) (I j)) : Surjective (quotientInfToPiQuotient I) := by classical cases nonempty_fintype ι intro g choose f hf using fun i ↦ mk_surjective (g i) have key : ∀ i, ∃ e : R, mk (I i) e = 1 ∧ ∀ j, j ≠ i → mk (I j) e = 0 := by intro i have hI' : ∀ j ∈ ({i} : Finset ι)ᶜ, IsCoprime (I i) (I j) := by intros j hj exact hI (by simpa [ne_comm, isCoprime_iff_add] using hj) rcases isCoprime_iff_exists.mp (isCoprime_biInf hI') with ⟨u, hu, e, he, hue⟩ replace he : ∀ j, j ≠ i → e ∈ I j := by simpa using he refine ⟨e, ?_, ?_⟩ · simp [eq_sub_of_add_eq' hue, map_sub, eq_zero_iff_mem.mpr hu] · exact fun j hj ↦ eq_zero_iff_mem.mpr (he j hj) choose e he using key use mk _ (∑ i, f i*e i) ext i rw [quotientInfToPiQuotient_mk', map_sum, Fintype.sum_eq_single i] · simp [(he i).1, hf] · intros j hj simp [(he j).2 i hj.symm] /-- **Chinese Remainder Theorem**. Eisenbud Ex.2.6. Similar to Atiyah-Macdonald 1.10 and Stacks 00DT -/ noncomputable def quotientInfRingEquivPiQuotient [Finite ι] (f : ι → Ideal R) (hf : Pairwise fun i j => IsCoprime (f i) (f j)) : (R ⧸ ⨅ i, f i) ≃+* ∀ i, R ⧸ f i := { Equiv.ofBijective _ ⟨quotientInfToPiQuotient_inj f, quotientInfToPiQuotient_surj hf⟩, quotientInfToPiQuotient f with } /-- Corollary of Chinese Remainder Theorem: if `Iᵢ` are pairwise coprime ideals in a commutative ring then the canonical map `R → ∏ (R ⧸ Iᵢ)` is surjective. -/ lemma pi_quotient_surjective {R : Type*} [CommRing R] {ι : Type*} [Finite ι] {I : ι → Ideal R} (hf : Pairwise fun i j ↦ IsCoprime (I i) (I j)) (x : (i : ι) → R ⧸ I i) : ∃ r : R, ∀ i, r = x i := by obtain ⟨y, rfl⟩ := Ideal.quotientInfToPiQuotient_surj hf x obtain ⟨r, rfl⟩ := Ideal.Quotient.mk_surjective y exact ⟨r, fun i ↦ rfl⟩ -- variant of `IsDedekindDomain.exists_forall_sub_mem_ideal` which doesn't assume Dedekind domain! /-- Corollary of Chinese Remainder Theorem: if `Iᵢ` are pairwise coprime ideals in a commutative ring then given elements `xᵢ` you can find `r` with `r - xᵢ ∈ Iᵢ` for all `i`. -/ lemma exists_forall_sub_mem_ideal {R : Type*} [CommRing R] {ι : Type*} [Finite ι] {I : ι → Ideal R} (hI : Pairwise fun i j ↦ IsCoprime (I i) (I j)) (x : ι → R) : ∃ r : R, ∀ i, r - x i ∈ I i := by obtain ⟨y, hy⟩ := Ideal.pi_quotient_surjective hI (fun i ↦ x i) exact ⟨y, fun i ↦ (Submodule.Quotient.eq (I i)).mp <| hy i⟩ /-- **Chinese remainder theorem**, specialized to two ideals. -/ noncomputable def quotientInfEquivQuotientProd (I J : Ideal R) (coprime : IsCoprime I J) : R ⧸ I ⊓ J ≃+* (R ⧸ I) × R ⧸ J := let f : Fin 2 → Ideal R := ![I, J] have hf : Pairwise fun i j => IsCoprime (f i) (f j) := by intro i j h fin_cases i <;> fin_cases j <;> try contradiction · assumption · exact coprime.symm (Ideal.quotEquivOfEq (by simp [f, iInf, inf_comm])).trans <| (Ideal.quotientInfRingEquivPiQuotient f hf).trans <| RingEquiv.piFinTwo fun i => R ⧸ f i @[simp] theorem quotientInfEquivQuotientProd_fst (I J : Ideal R) (coprime : IsCoprime I J) (x : R ⧸ I ⊓ J) : (quotientInfEquivQuotientProd I J coprime x).fst = Ideal.Quotient.factor (I ⊓ J) I inf_le_left x := Quot.inductionOn x fun _ => rfl @[simp] theorem quotientInfEquivQuotientProd_snd (I J : Ideal R) (coprime : IsCoprime I J) (x : R ⧸ I ⊓ J) : (quotientInfEquivQuotientProd I J coprime x).snd = Ideal.Quotient.factor (I ⊓ J) J inf_le_right x := Quot.inductionOn x fun _ => rfl @[simp] theorem fst_comp_quotientInfEquivQuotientProd (I J : Ideal R) (coprime : IsCoprime I J) : (RingHom.fst _ _).comp (quotientInfEquivQuotientProd I J coprime : R ⧸ I ⊓ J →+* (R ⧸ I) × R ⧸ J) = Ideal.Quotient.factor (I ⊓ J) I inf_le_left := by apply Quotient.ringHom_ext; ext; rfl @[simp] theorem snd_comp_quotientInfEquivQuotientProd (I J : Ideal R) (coprime : IsCoprime I J) : (RingHom.snd _ _).comp (quotientInfEquivQuotientProd I J coprime : R ⧸ I ⊓ J →+* (R ⧸ I) × R ⧸ J) = Ideal.Quotient.factor (I ⊓ J) J inf_le_right := by apply Quotient.ringHom_ext; ext; rfl /-- **Chinese remainder theorem**, specialized to two ideals. -/ noncomputable def quotientMulEquivQuotientProd (I J : Ideal R) (coprime : IsCoprime I J) : R ⧸ I * J ≃+* (R ⧸ I) × R ⧸ J := Ideal.quotEquivOfEq (inf_eq_mul_of_isCoprime coprime).symm |>.trans <| Ideal.quotientInfEquivQuotientProd I J coprime @[simp] theorem quotientMulEquivQuotientProd_fst (I J : Ideal R) (coprime : IsCoprime I J) (x : R ⧸ I * J) : (quotientMulEquivQuotientProd I J coprime x).fst = Ideal.Quotient.factor (I * J) I mul_le_right x := Quot.inductionOn x fun _ => rfl @[simp] theorem quotientMulEquivQuotientProd_snd (I J : Ideal R) (coprime : IsCoprime I J) (x : R ⧸ I * J) : (quotientMulEquivQuotientProd I J coprime x).snd = Ideal.Quotient.factor (I * J) J mul_le_left x := Quot.inductionOn x fun _ => rfl @[simp] theorem fst_comp_quotientMulEquivQuotientProd (I J : Ideal R) (coprime : IsCoprime I J) : (RingHom.fst _ _).comp (quotientMulEquivQuotientProd I J coprime : R ⧸ I * J →+* (R ⧸ I) × R ⧸ J) = Ideal.Quotient.factor (I * J) I mul_le_right := by apply Quotient.ringHom_ext; ext; rfl @[simp] theorem snd_comp_quotientMulEquivQuotientProd (I J : Ideal R) (coprime : IsCoprime I J) : (RingHom.snd _ _).comp (quotientMulEquivQuotientProd I J coprime : R ⧸ I * J →+* (R ⧸ I) × R ⧸ J) = Ideal.Quotient.factor (I * J) J mul_le_left := by apply Quotient.ringHom_ext; ext; rfl end ChineseRemainder section QuotientAlgebra variable (R₁ R₂ : Type*) {A B : Type*} variable [CommSemiring R₁] [CommSemiring R₂] [CommRing A] variable [Algebra R₁ A] [Algebra R₂ A] /-- The `R₁`-algebra structure on `A/I` for an `R₁`-algebra `A` -/ instance Quotient.algebra {I : Ideal A} : Algebra R₁ (A ⧸ I) := { toRingHom := (Ideal.Quotient.mk I).comp (algebraMap R₁ A) smul_def' := fun _ x => Quotient.inductionOn' x fun _ => ((Quotient.mk I).congr_arg <| Algebra.smul_def _ _).trans (RingHom.map_mul _ _ _) commutes' := fun _ _ => mul_comm _ _ } -- Lean can struggle to find this instance later if we don't provide this shortcut -- Porting note: this can probably now be deleted -- update: maybe not - removal causes timeouts instance Quotient.isScalarTower [SMul R₁ R₂] [IsScalarTower R₁ R₂ A] (I : Ideal A) : IsScalarTower R₁ R₂ (A ⧸ I) := by infer_instance /-- The canonical morphism `A →ₐ[R₁] A ⧸ I` as morphism of `R₁`-algebras, for `I` an ideal of `A`, where `A` is an `R₁`-algebra. -/ def Quotient.mkₐ (I : Ideal A) : A →ₐ[R₁] A ⧸ I := ⟨⟨⟨⟨fun a => Submodule.Quotient.mk a, rfl⟩, fun _ _ => rfl⟩, rfl, fun _ _ => rfl⟩, fun _ => rfl⟩ theorem Quotient.algHom_ext {I : Ideal A} {S} [Semiring S] [Algebra R₁ S] ⦃f g : A ⧸ I →ₐ[R₁] S⦄ (h : f.comp (Quotient.mkₐ R₁ I) = g.comp (Quotient.mkₐ R₁ I)) : f = g := AlgHom.ext fun x => Quotient.inductionOn' x <| AlgHom.congr_fun h theorem Quotient.alg_map_eq (I : Ideal A) : algebraMap R₁ (A ⧸ I) = (algebraMap A (A ⧸ I)).comp (algebraMap R₁ A) := rfl theorem Quotient.mkₐ_toRingHom (I : Ideal A) : (Quotient.mkₐ R₁ I).toRingHom = Ideal.Quotient.mk I := rfl @[simp] theorem Quotient.mkₐ_eq_mk (I : Ideal A) : ⇑(Quotient.mkₐ R₁ I) = Quotient.mk I := rfl @[simp] theorem Quotient.algebraMap_eq (I : Ideal R) : algebraMap R (R ⧸ I) = Quotient.mk I := rfl @[simp] theorem Quotient.mk_comp_algebraMap (I : Ideal A) : (Quotient.mk I).comp (algebraMap R₁ A) = algebraMap R₁ (A ⧸ I) := rfl @[simp] theorem Quotient.mk_algebraMap (I : Ideal A) (x : R₁) : Quotient.mk I (algebraMap R₁ A x) = algebraMap R₁ (A ⧸ I) x := rfl /-- The canonical morphism `A →ₐ[R₁] I.quotient` is surjective. -/ theorem Quotient.mkₐ_surjective (I : Ideal A) : Function.Surjective (Quotient.mkₐ R₁ I) := surjective_quot_mk _ /-- The kernel of `A →ₐ[R₁] I.quotient` is `I`. -/ @[simp] theorem Quotient.mkₐ_ker (I : Ideal A) : RingHom.ker (Quotient.mkₐ R₁ I : A →+* A ⧸ I) = I := Ideal.mk_ker variable {R₁} section variable [Semiring B] [Algebra R₁ B] /-- `Ideal.quotient.lift` as an `AlgHom`. -/ def Quotient.liftₐ (I : Ideal A) (f : A →ₐ[R₁] B) (hI : ∀ a : A, a ∈ I → f a = 0) : A ⧸ I →ₐ[R₁] B := {-- this is IsScalarTower.algebraMap_apply R₁ A (A ⧸ I) but the file `Algebra.Algebra.Tower` -- imports this file. Ideal.Quotient.lift I (f : A →+* B) hI with commutes' := fun r => by have : algebraMap R₁ (A ⧸ I) r = algebraMap A (A ⧸ I) (algebraMap R₁ A r) := by simp_rw [Algebra.algebraMap_eq_smul_one, smul_assoc, one_smul] rw [this, Ideal.Quotient.algebraMap_eq, RingHom.toFun_eq_coe, Ideal.Quotient.lift_mk, AlgHom.coe_toRingHom, Algebra.algebraMap_eq_smul_one, Algebra.algebraMap_eq_smul_one, map_smul, map_one] } @[simp] theorem Quotient.liftₐ_apply (I : Ideal A) (f : A →ₐ[R₁] B) (hI : ∀ a : A, a ∈ I → f a = 0) (x) : Ideal.Quotient.liftₐ I f hI x = Ideal.Quotient.lift I (f : A →+* B) hI x := rfl theorem Quotient.liftₐ_comp (I : Ideal A) (f : A →ₐ[R₁] B) (hI : ∀ a : A, a ∈ I → f a = 0) : (Ideal.Quotient.liftₐ I f hI).comp (Ideal.Quotient.mkₐ R₁ I) = f := AlgHom.ext fun _ => (Ideal.Quotient.lift_mk I (f : A →+* B) hI : _) theorem KerLift.map_smul (f : A →ₐ[R₁] B) (r : R₁) (x : A ⧸ (RingHom.ker f)) : f.kerLift (r • x) = r • f.kerLift x := by obtain ⟨a, rfl⟩ := Quotient.mkₐ_surjective R₁ _ x exact _root_.map_smul f _ _ /-- The induced algebras morphism from the quotient by the kernel to the codomain. This is an isomorphism if `f` has a right inverse (`quotientKerAlgEquivOfRightInverse`) / is surjective (`quotientKerAlgEquivOfSurjective`). -/ def kerLiftAlg (f : A →ₐ[R₁] B) : A ⧸ (RingHom.ker f) →ₐ[R₁] B := AlgHom.mk' (RingHom.kerLift (f : A →+* B)) fun _ _ => KerLift.map_smul f _ _ @[simp] theorem kerLiftAlg_mk (f : A →ₐ[R₁] B) (a : A) : kerLiftAlg f (Quotient.mk (RingHom.ker f) a) = f a := by rfl @[simp] theorem kerLiftAlg_toRingHom (f : A →ₐ[R₁] B) : (kerLiftAlg f : A ⧸ ker f →+* B) = RingHom.kerLift (f : A →+* B) := rfl /-- The induced algebra morphism from the quotient by the kernel is injective. -/ theorem kerLiftAlg_injective (f : A →ₐ[R₁] B) : Function.Injective (kerLiftAlg f) := RingHom.kerLift_injective (R := A) (S := B) f /-- The **first isomorphism** theorem for algebras, computable version. -/ @[simps!] def quotientKerAlgEquivOfRightInverse {f : A →ₐ[R₁] B} {g : B → A} (hf : Function.RightInverse g f) : (A ⧸ RingHom.ker f) ≃ₐ[R₁] B := { RingHom.quotientKerEquivOfRightInverse hf, kerLiftAlg f with } @[deprecated (since := "2024-02-27")] alias quotientKerAlgEquivOfRightInverse.apply := quotientKerAlgEquivOfRightInverse_apply @[deprecated (since := "2024-02-27")] alias QuotientKerAlgEquivOfRightInverseSymm.apply := quotientKerAlgEquivOfRightInverse_symm_apply /-- The **first isomorphism theorem** for algebras. -/ @[simps!] noncomputable def quotientKerAlgEquivOfSurjective {f : A →ₐ[R₁] B} (hf : Function.Surjective f) : (A ⧸ (RingHom.ker f)) ≃ₐ[R₁] B := quotientKerAlgEquivOfRightInverse (Classical.choose_spec hf.hasRightInverse) end section CommRing_CommRing variable {S : Type v} [CommRing S] /-- The ring hom `R/I →+* S/J` induced by a ring hom `f : R →+* S` with `I ≤ f⁻¹(J)` -/ def quotientMap {I : Ideal R} (J : Ideal S) (f : R →+* S) (hIJ : I ≤ J.comap f) : R ⧸ I →+* S ⧸ J := Quotient.lift I ((Quotient.mk J).comp f) fun _ ha => by simpa [Function.comp_apply, RingHom.coe_comp, Quotient.eq_zero_iff_mem] using hIJ ha @[simp] theorem quotientMap_mk {J : Ideal R} {I : Ideal S} {f : R →+* S} {H : J ≤ I.comap f} {x : R} : quotientMap I f H (Quotient.mk J x) = Quotient.mk I (f x) := Quotient.lift_mk J _ _ @[simp] theorem quotientMap_algebraMap {J : Ideal A} {I : Ideal S} {f : A →+* S} {H : J ≤ I.comap f} {x : R₁} : quotientMap I f H (algebraMap R₁ (A ⧸ J) x) = Quotient.mk I (f (algebraMap _ _ x)) := Quotient.lift_mk J _ _ theorem quotientMap_comp_mk {J : Ideal R} {I : Ideal S} {f : R →+* S} (H : J ≤ I.comap f) : (quotientMap I f H).comp (Quotient.mk J) = (Quotient.mk I).comp f := RingHom.ext fun x => by simp only [Function.comp_apply, RingHom.coe_comp, Ideal.quotientMap_mk] /-- The ring equiv `R/I ≃+* S/J` induced by a ring equiv `f : R ≃+* S`, where `J = f(I)`. -/ @[simps] def quotientEquiv (I : Ideal R) (J : Ideal S) (f : R ≃+* S) (hIJ : J = I.map (f : R →+* S)) : R ⧸ I ≃+* S ⧸ J := { quotientMap J (↑f) (by rw [hIJ] exact le_comap_map) with invFun := quotientMap I (↑f.symm) (by rw [hIJ] exact le_of_eq (map_comap_of_equiv I f)) left_inv := by rintro ⟨r⟩ simp only [Submodule.Quotient.quot_mk_eq_mk, Quotient.mk_eq_mk, RingHom.toFun_eq_coe, quotientMap_mk, RingEquiv.coe_toRingHom, RingEquiv.symm_apply_apply] right_inv := by rintro ⟨s⟩ simp only [Submodule.Quotient.quot_mk_eq_mk, Quotient.mk_eq_mk, RingHom.toFun_eq_coe, quotientMap_mk, RingEquiv.coe_toRingHom, RingEquiv.apply_symm_apply] } /- Porting note: removed simp. LHS simplified. Slightly different version of the simplified form closed this and was itself closed by simp -/ theorem quotientEquiv_mk (I : Ideal R) (J : Ideal S) (f : R ≃+* S) (hIJ : J = I.map (f : R →+* S)) (x : R) : quotientEquiv I J f hIJ (Ideal.Quotient.mk I x) = Ideal.Quotient.mk J (f x) := rfl @[simp] theorem quotientEquiv_symm_mk (I : Ideal R) (J : Ideal S) (f : R ≃+* S) (hIJ : J = I.map (f : R →+* S)) (x : S) : (quotientEquiv I J f hIJ).symm (Ideal.Quotient.mk J x) = Ideal.Quotient.mk I (f.symm x) := rfl /-- `H` and `h` are kept as separate hypothesis since H is used in constructing the quotient map. -/ theorem quotientMap_injective' {J : Ideal R} {I : Ideal S} {f : R →+* S} {H : J ≤ I.comap f} (h : I.comap f ≤ J) : Function.Injective (quotientMap I f H) := by refine (injective_iff_map_eq_zero (quotientMap I f H)).2 fun a ha => ?_ obtain ⟨r, rfl⟩ := Quotient.mk_surjective a rw [quotientMap_mk, Quotient.eq_zero_iff_mem] at ha exact Quotient.eq_zero_iff_mem.mpr (h ha) /-- If we take `J = I.comap f` then `QuotientMap` is injective automatically. -/ theorem quotientMap_injective {I : Ideal S} {f : R →+* S} : Function.Injective (quotientMap I f le_rfl) := quotientMap_injective' le_rfl theorem quotientMap_surjective {J : Ideal R} {I : Ideal S} {f : R →+* S} {H : J ≤ I.comap f} (hf : Function.Surjective f) : Function.Surjective (quotientMap I f H) := fun x => let ⟨x, hx⟩ := Quotient.mk_surjective x let ⟨y, hy⟩ := hf x ⟨(Quotient.mk J) y, by simp [hx, hy]⟩ /-- Commutativity of a square is preserved when taking quotients by an ideal. -/ theorem comp_quotientMap_eq_of_comp_eq {R' S' : Type*} [CommRing R'] [CommRing S'] {f : R →+* S} {f' : R' →+* S'} {g : R →+* R'} {g' : S →+* S'} (hfg : f'.comp g = g'.comp f) (I : Ideal S') : -- Porting note: was losing track of I let leq := le_of_eq (_root_.trans (comap_comap (I := I) f g') (hfg ▸ comap_comap (I := I) g f')) (quotientMap I g' le_rfl).comp (quotientMap (I.comap g') f le_rfl) = (quotientMap I f' le_rfl).comp (quotientMap (I.comap f') g leq) := by refine RingHom.ext fun a => ?_ obtain ⟨r, rfl⟩ := Quotient.mk_surjective a simp only [RingHom.comp_apply, quotientMap_mk] exact (Ideal.Quotient.mk I).congr_arg (_root_.trans (g'.comp_apply f r).symm (hfg ▸ f'.comp_apply g r)) end CommRing_CommRing section variable [CommRing B] [Algebra R₁ B] /-- The algebra hom `A/I →+* B/J` induced by an algebra hom `f : A →ₐ[R₁] B` with `I ≤ f⁻¹(J)`. -/ def quotientMapₐ {I : Ideal A} (J : Ideal B) (f : A →ₐ[R₁] B) (hIJ : I ≤ J.comap f) : A ⧸ I →ₐ[R₁] B ⧸ J := { quotientMap J (f : A →+* B) hIJ with commutes' := fun r => by simp only [RingHom.toFun_eq_coe, quotientMap_algebraMap, AlgHom.coe_toRingHom, AlgHom.commutes, Quotient.mk_algebraMap] } @[simp] theorem quotient_map_mkₐ {I : Ideal A} (J : Ideal B) (f : A →ₐ[R₁] B) (H : I ≤ J.comap f) {x : A} : quotientMapₐ J f H (Quotient.mk I x) = Quotient.mkₐ R₁ J (f x) := rfl theorem quotient_map_comp_mkₐ {I : Ideal A} (J : Ideal B) (f : A →ₐ[R₁] B) (H : I ≤ J.comap f) : (quotientMapₐ J f H).comp (Quotient.mkₐ R₁ I) = (Quotient.mkₐ R₁ J).comp f := AlgHom.ext fun x => by simp only [quotient_map_mkₐ, Quotient.mkₐ_eq_mk, AlgHom.comp_apply] /-- The algebra equiv `A/I ≃ₐ[R] B/J` induced by an algebra equiv `f : A ≃ₐ[R] B`, where`J = f(I)`. -/ def quotientEquivAlg (I : Ideal A) (J : Ideal B) (f : A ≃ₐ[R₁] B) (hIJ : J = I.map (f : A →+* B)) : (A ⧸ I) ≃ₐ[R₁] B ⧸ J := { quotientEquiv I J (f : A ≃+* B) hIJ with commutes' := fun r => by -- Porting note: Needed to add the below lemma because Equivs coerce weird have : ∀ (e : RingEquiv (A ⧸ I) (B ⧸ J)), Equiv.toFun e.toEquiv = DFunLike.coe e := fun _ ↦ rfl rw [this] simp only [quotientEquiv_apply, RingHom.toFun_eq_coe, quotientMap_algebraMap, RingEquiv.coe_toRingHom, AlgEquiv.coe_ringEquiv, AlgEquiv.commutes, Quotient.mk_algebraMap]} end instance (priority := 100) quotientAlgebra {I : Ideal A} [Algebra R A] : Algebra (R ⧸ I.comap (algebraMap R A)) (A ⧸ I) := (quotientMap I (algebraMap R A) (le_of_eq rfl)).toAlgebra theorem algebraMap_quotient_injective {I : Ideal A} [Algebra R A] : Function.Injective (algebraMap (R ⧸ I.comap (algebraMap R A)) (A ⧸ I)) := by rintro ⟨a⟩ ⟨b⟩ hab replace hab := Quotient.eq.mp hab rw [← RingHom.map_sub] at hab exact Quotient.eq.mpr hab variable (R₁) /-- Quotienting by equal ideals gives equivalent algebras. -/ def quotientEquivAlgOfEq {I J : Ideal A} (h : I = J) : (A ⧸ I) ≃ₐ[R₁] A ⧸ J := quotientEquivAlg I J AlgEquiv.refl <| h ▸ (map_id I).symm @[simp] theorem quotientEquivAlgOfEq_mk {I J : Ideal A} (h : I = J) (x : A) : quotientEquivAlgOfEq R₁ h (Ideal.Quotient.mk I x) = Ideal.Quotient.mk J x := rfl @[simp] theorem quotientEquivAlgOfEq_symm {I J : Ideal A} (h : I = J) : (quotientEquivAlgOfEq R₁ h).symm = quotientEquivAlgOfEq R₁ h.symm := by ext rfl lemma comap_map_mk {I J : Ideal R} (h : I ≤ J) : Ideal.comap (Ideal.Quotient.mk I) (Ideal.map (Ideal.Quotient.mk I) J) = J := by ext; rw [← Ideal.mem_quotient_iff_mem h, Ideal.mem_comap] /-- The **first isomorphism theorem** for commutative algebras (`AlgHom.range` version). -/ noncomputable def quotientKerEquivRange {A B : Type*} [CommRing A] [Algebra R A] [Semiring B] [Algebra R B] (f : A →ₐ[R] B) : (A ⧸ RingHom.ker f) ≃ₐ[R] f.range := (Ideal.quotientEquivAlgOfEq R (AlgHom.ker_rangeRestrict f).symm).trans <| Ideal.quotientKerAlgEquivOfSurjective f.rangeRestrict_surjective end QuotientAlgebra end Ideal namespace DoubleQuot open Ideal variable {R : Type u} section variable [CommRing R] (I J : Ideal R) /-- The obvious ring hom `R/I → R/(I ⊔ J)` -/ def quotLeftToQuotSup : R ⧸ I →+* R ⧸ I ⊔ J := Ideal.Quotient.factor I (I ⊔ J) le_sup_left /-- The kernel of `quotLeftToQuotSup` -/ theorem ker_quotLeftToQuotSup : RingHom.ker (quotLeftToQuotSup I J) = J.map (Ideal.Quotient.mk I) := by simp only [mk_ker, sup_idem, sup_comm, quotLeftToQuotSup, Quotient.factor, ker_quotient_lift, map_eq_iff_sup_ker_eq_of_surjective (Ideal.Quotient.mk I) Quotient.mk_surjective, ← sup_assoc] /-- The ring homomorphism `(R/I)/J' -> R/(I ⊔ J)` induced by `quotLeftToQuotSup` where `J'` is the image of `J` in `R/I`-/ def quotQuotToQuotSup : (R ⧸ I) ⧸ J.map (Ideal.Quotient.mk I) →+* R ⧸ I ⊔ J := Ideal.Quotient.lift (J.map (Ideal.Quotient.mk I)) (quotLeftToQuotSup I J) (ker_quotLeftToQuotSup I J).symm.le /-- The composite of the maps `R → (R/I)` and `(R/I) → (R/I)/J'` -/ def quotQuotMk : R →+* (R ⧸ I) ⧸ J.map (Ideal.Quotient.mk I) := (Ideal.Quotient.mk (J.map (Ideal.Quotient.mk I))).comp (Ideal.Quotient.mk I) -- Porting note: mismatched instances /-- The kernel of `quotQuotMk` -/ theorem ker_quotQuotMk : RingHom.ker (quotQuotMk I J) = I ⊔ J := by rw [RingHom.ker_eq_comap_bot, quotQuotMk, ← comap_comap, ← RingHom.ker, mk_ker, comap_map_of_surjective (Ideal.Quotient.mk I) Quotient.mk_surjective, ← RingHom.ker, mk_ker, sup_comm] /-- The ring homomorphism `R/(I ⊔ J) → (R/I)/J' `induced by `quotQuotMk` -/ def liftSupQuotQuotMk (I J : Ideal R) : R ⧸ I ⊔ J →+* (R ⧸ I) ⧸ J.map (Ideal.Quotient.mk I) := Ideal.Quotient.lift (I ⊔ J) (quotQuotMk I J) (ker_quotQuotMk I J).symm.le /-- `quotQuotToQuotSup` and `liftSupQuotQuotMk` are inverse isomorphisms. In the case where `I ≤ J`, this is the Third Isomorphism Theorem (see `quotQuotEquivQuotOfLe`)-/ def quotQuotEquivQuotSup : (R ⧸ I) ⧸ J.map (Ideal.Quotient.mk I) ≃+* R ⧸ I ⊔ J := RingEquiv.ofHomInv (quotQuotToQuotSup I J) (liftSupQuotQuotMk I J) (by repeat apply Ideal.Quotient.ringHom_ext rfl) (by repeat apply Ideal.Quotient.ringHom_ext rfl) @[simp] theorem quotQuotEquivQuotSup_quotQuotMk (x : R) : quotQuotEquivQuotSup I J (quotQuotMk I J x) = Ideal.Quotient.mk (I ⊔ J) x := rfl @[simp] theorem quotQuotEquivQuotSup_symm_quotQuotMk (x : R) : (quotQuotEquivQuotSup I J).symm (Ideal.Quotient.mk (I ⊔ J) x) = quotQuotMk I J x := rfl /-- The obvious isomorphism `(R/I)/J' → (R/J)/I'` -/ def quotQuotEquivComm : (R ⧸ I) ⧸ J.map (Ideal.Quotient.mk I) ≃+* (R ⧸ J) ⧸ I.map (Ideal.Quotient.mk J) := ((quotQuotEquivQuotSup I J).trans (quotEquivOfEq (sup_comm ..))).trans (quotQuotEquivQuotSup J I).symm -- Porting note: mismatched instances @[simp] theorem quotQuotEquivComm_quotQuotMk (x : R) : quotQuotEquivComm I J (quotQuotMk I J x) = quotQuotMk J I x := rfl -- Porting note: mismatched instances @[simp] theorem quotQuotEquivComm_comp_quotQuotMk : RingHom.comp (↑(quotQuotEquivComm I J)) (quotQuotMk I J) = quotQuotMk J I := RingHom.ext <| quotQuotEquivComm_quotQuotMk I J @[simp] theorem quotQuotEquivComm_symm : (quotQuotEquivComm I J).symm = quotQuotEquivComm J I := by /- Porting note: this proof used to just be rfl but currently rfl opens up a bottomless pit of processor cycles. Synthesizing instances does not seem to be an issue. -/ change (((quotQuotEquivQuotSup I J).trans (quotEquivOfEq (sup_comm ..))).trans (quotQuotEquivQuotSup J I).symm).symm = ((quotQuotEquivQuotSup J I).trans (quotEquivOfEq (sup_comm ..))).trans (quotQuotEquivQuotSup I J).symm ext r dsimp rfl variable {I J} /-- **The Third Isomorphism theorem** for rings. See `quotQuotEquivQuotSup` for a version that does not assume an inclusion of ideals. -/ def quotQuotEquivQuotOfLE (h : I ≤ J) : (R ⧸ I) ⧸ J.map (Ideal.Quotient.mk I) ≃+* R ⧸ J := (quotQuotEquivQuotSup I J).trans (Ideal.quotEquivOfEq <| sup_eq_right.mpr h) @[simp] theorem quotQuotEquivQuotOfLE_quotQuotMk (x : R) (h : I ≤ J) : quotQuotEquivQuotOfLE h (quotQuotMk I J x) = (Ideal.Quotient.mk J) x := rfl @[simp] theorem quotQuotEquivQuotOfLE_symm_mk (x : R) (h : I ≤ J) : (quotQuotEquivQuotOfLE h).symm ((Ideal.Quotient.mk J) x) = quotQuotMk I J x := rfl theorem quotQuotEquivQuotOfLE_comp_quotQuotMk (h : I ≤ J) : RingHom.comp (↑(quotQuotEquivQuotOfLE h)) (quotQuotMk I J) = (Ideal.Quotient.mk J) := by ext rfl theorem quotQuotEquivQuotOfLE_symm_comp_mk (h : I ≤ J) : RingHom.comp (↑(quotQuotEquivQuotOfLE h).symm) (Ideal.Quotient.mk J) = quotQuotMk I J := by ext rfl end section Algebra @[simp] theorem quotQuotEquivComm_mk_mk [CommRing R] (I J : Ideal R) (x : R) : quotQuotEquivComm I J (Ideal.Quotient.mk _ (Ideal.Quotient.mk _ x)) = algebraMap R _ x := rfl variable [CommSemiring R] {A : Type v} [CommRing A] [Algebra R A] (I J : Ideal A) @[simp] theorem quotQuotEquivQuotSup_quot_quot_algebraMap (x : R) : DoubleQuot.quotQuotEquivQuotSup I J (algebraMap R _ x) = algebraMap _ _ x := rfl @[simp] theorem quotQuotEquivComm_algebraMap (x : R) : quotQuotEquivComm I J (algebraMap R _ x) = algebraMap _ _ x := rfl end Algebra section AlgebraQuotient variable (R) {A : Type*} [CommSemiring R] [CommRing A] [Algebra R A] (I J : Ideal A) /-- The natural algebra homomorphism `A / I → A / (I ⊔ J)`. -/ def quotLeftToQuotSupₐ : A ⧸ I →ₐ[R] A ⧸ I ⊔ J := AlgHom.mk (quotLeftToQuotSup I J) fun _ => rfl @[simp] theorem quotLeftToQuotSupₐ_toRingHom : (quotLeftToQuotSupₐ R I J : _ →+* _) = quotLeftToQuotSup I J := rfl @[simp] theorem coe_quotLeftToQuotSupₐ : ⇑(quotLeftToQuotSupₐ R I J) = quotLeftToQuotSup I J := rfl /-- The algebra homomorphism `(A / I) / J' -> A / (I ⊔ J)` induced by `quotQuotToQuotSup`, where `J'` is the projection of `J` in `A / I`. -/ def quotQuotToQuotSupₐ : (A ⧸ I) ⧸ J.map (Quotient.mkₐ R I) →ₐ[R] A ⧸ I ⊔ J := AlgHom.mk (quotQuotToQuotSup I J) fun _ => rfl @[simp] theorem quotQuotToQuotSupₐ_toRingHom : ((quotQuotToQuotSupₐ R I J) : _ ⧸ map (Ideal.Quotient.mkₐ R I) J →+* _) = quotQuotToQuotSup I J := rfl @[simp] theorem coe_quotQuotToQuotSupₐ : ⇑(quotQuotToQuotSupₐ R I J) = quotQuotToQuotSup I J := rfl /-- The composition of the algebra homomorphisms `A → (A / I)` and `(A / I) → (A / I) / J'`, where `J'` is the projection `J` in `A / I`. -/ def quotQuotMkₐ : A →ₐ[R] (A ⧸ I) ⧸ J.map (Quotient.mkₐ R I) := AlgHom.mk (quotQuotMk I J) fun _ => rfl @[simp] theorem quotQuotMkₐ_toRingHom : (quotQuotMkₐ R I J : _ →+* _ ⧸ J.map (Quotient.mkₐ R I)) = quotQuotMk I J := rfl @[simp] theorem coe_quotQuotMkₐ : ⇑(quotQuotMkₐ R I J) = quotQuotMk I J := rfl /-- The injective algebra homomorphism `A / (I ⊔ J) → (A / I) / J'`induced by `quot_quot_mk`, where `J'` is the projection `J` in `A / I`. -/ def liftSupQuotQuotMkₐ (I J : Ideal A) : A ⧸ I ⊔ J →ₐ[R] (A ⧸ I) ⧸ J.map (Quotient.mkₐ R I) := AlgHom.mk (liftSupQuotQuotMk I J) fun _ => rfl @[simp] theorem liftSupQuotQuotMkₐ_toRingHom : (liftSupQuotQuotMkₐ R I J : _ →+* _ ⧸ J.map (Quotient.mkₐ R I)) = liftSupQuotQuotMk I J := rfl @[simp] theorem coe_liftSupQuotQuotMkₐ : ⇑(liftSupQuotQuotMkₐ R I J) = liftSupQuotQuotMk I J := rfl /-- `quotQuotToQuotSup` and `liftSupQuotQuotMk` are inverse isomorphisms. In the case where `I ≤ J`, this is the Third Isomorphism Theorem (see `DoubleQuot.quotQuotEquivQuotOfLE`). -/ def quotQuotEquivQuotSupₐ : ((A ⧸ I) ⧸ J.map (Quotient.mkₐ R I)) ≃ₐ[R] A ⧸ I ⊔ J := AlgEquiv.ofRingEquiv (f := quotQuotEquivQuotSup I J) fun _ => rfl @[simp] theorem quotQuotEquivQuotSupₐ_toRingEquiv : (quotQuotEquivQuotSupₐ R I J : _ ⧸ J.map (Quotient.mkₐ R I) ≃+* _) = quotQuotEquivQuotSup I J := rfl @[simp] -- Porting note: had to add an extra coercion arrow on the right hand side. theorem coe_quotQuotEquivQuotSupₐ : ⇑(quotQuotEquivQuotSupₐ R I J) = ⇑(quotQuotEquivQuotSup I J) := rfl @[simp] theorem quotQuotEquivQuotSupₐ_symm_toRingEquiv : ((quotQuotEquivQuotSupₐ R I J).symm : _ ≃+* _ ⧸ J.map (Quotient.mkₐ R I)) = (quotQuotEquivQuotSup I J).symm := rfl @[simp] -- Porting note: had to add an extra coercion arrow on the right hand side. theorem coe_quotQuotEquivQuotSupₐ_symm : ⇑(quotQuotEquivQuotSupₐ R I J).symm = ⇑(quotQuotEquivQuotSup I J).symm := rfl /-- The natural algebra isomorphism `(A / I) / J' → (A / J) / I'`, where `J'` (resp. `I'`) is the projection of `J` in `A / I` (resp. `I` in `A / J`). -/ def quotQuotEquivCommₐ : ((A ⧸ I) ⧸ J.map (Quotient.mkₐ R I)) ≃ₐ[R] (A ⧸ J) ⧸ I.map (Quotient.mkₐ R J) := AlgEquiv.ofRingEquiv (f := quotQuotEquivComm I J) fun _ => rfl @[simp] theorem quotQuotEquivCommₐ_toRingEquiv : (quotQuotEquivCommₐ R I J : _ ⧸ J.map (Quotient.mkₐ R I) ≃+* _ ⧸ I.map (Quotient.mkₐ R J)) = quotQuotEquivComm I J := -- Porting note: should just be `rfl` but `AlgEquiv.toRingEquiv` and `AlgEquiv.ofRingEquiv` -- involve repacking everything in the structure, so Lean ends up unfolding `quotQuotEquivComm` -- and timing out. RingEquiv.ext fun _ => rfl @[simp] theorem coe_quotQuotEquivCommₐ : ⇑(quotQuotEquivCommₐ R I J) = ⇑(quotQuotEquivComm I J) := rfl @[simp] theorem quotQuotEquivComm_symmₐ : (quotQuotEquivCommₐ R I J).symm = quotQuotEquivCommₐ R J I := by -- Porting note: should just be `rfl` but `AlgEquiv.toRingEquiv` and `AlgEquiv.ofRingEquiv` -- involve repacking everything in the structure, so Lean ends up unfolding `quotQuotEquivComm` -- and timing out. ext unfold quotQuotEquivCommₐ congr @[simp] theorem quotQuotEquivComm_comp_quotQuotMkₐ : AlgHom.comp (↑(quotQuotEquivCommₐ R I J)) (quotQuotMkₐ R I J) = quotQuotMkₐ R J I := AlgHom.ext <| quotQuotEquivComm_quotQuotMk I J variable {I J} /-- The **third isomorphism theorem** for algebras. See `quotQuotEquivQuotSupₐ` for version that does not assume an inclusion of ideals. -/ def quotQuotEquivQuotOfLEₐ (h : I ≤ J) : ((A ⧸ I) ⧸ J.map (Quotient.mkₐ R I)) ≃ₐ[R] A ⧸ J := AlgEquiv.ofRingEquiv (f := quotQuotEquivQuotOfLE h) fun _ => rfl @[simp] theorem quotQuotEquivQuotOfLEₐ_toRingEquiv (h : I ≤ J) : (quotQuotEquivQuotOfLEₐ R h : _ ⧸ J.map (Quotient.mkₐ R I) ≃+* _) = quotQuotEquivQuotOfLE h := rfl @[simp] -- Porting note: had to add an extra coercion arrow on the right hand side. theorem coe_quotQuotEquivQuotOfLEₐ (h : I ≤ J) : ⇑(quotQuotEquivQuotOfLEₐ R h) = ⇑(quotQuotEquivQuotOfLE h) := rfl @[simp] theorem quotQuotEquivQuotOfLEₐ_symm_toRingEquiv (h : I ≤ J) : ((quotQuotEquivQuotOfLEₐ R h).symm : _ ≃+* _ ⧸ J.map (Quotient.mkₐ R I)) = (quotQuotEquivQuotOfLE h).symm := rfl @[simp] -- Porting note: had to add an extra coercion arrow on the right hand side. theorem coe_quotQuotEquivQuotOfLEₐ_symm (h : I ≤ J) : ⇑(quotQuotEquivQuotOfLEₐ R h).symm = ⇑(quotQuotEquivQuotOfLE h).symm := rfl @[simp] theorem quotQuotEquivQuotOfLE_comp_quotQuotMkₐ (h : I ≤ J) : AlgHom.comp (↑(quotQuotEquivQuotOfLEₐ R h)) (quotQuotMkₐ R I J) = Quotient.mkₐ R J := rfl @[simp] theorem quotQuotEquivQuotOfLE_symm_comp_mkₐ (h : I ≤ J) : AlgHom.comp (↑(quotQuotEquivQuotOfLEₐ R h).symm) (Quotient.mkₐ R J) = quotQuotMkₐ R I J := rfl end AlgebraQuotient end DoubleQuot
RingTheory\Int\Basic.lean
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Jens Wagemaker, Aaron Anderson -/ import Mathlib.Algebra.EuclideanDomain.Basic import Mathlib.Algebra.EuclideanDomain.Int import Mathlib.RingTheory.PrincipalIdealDomain import Mathlib.Algebra.GCDMonoid.Nat import Mathlib.Data.Nat.Prime.Basic /-! # Divisibility over ℕ and ℤ This file collects results for the integers and natural numbers that use ring theory in their proofs or cases of ℕ and ℤ being examples of structures in ring theory. ## Main statements * `Nat.factors_eq`: the multiset of elements of `Nat.factors` is equal to the factors given by the `UniqueFactorizationMonoid` instance ## Tags prime, irreducible, natural numbers, integers, normalization monoid, gcd monoid, greatest common divisor, prime factorization, prime factors, unique factorization, unique factors -/ namespace Int theorem gcd_eq_one_iff_coprime {a b : ℤ} : Int.gcd a b = 1 ↔ IsCoprime a b := by constructor · intro hg obtain ⟨ua, -, ha⟩ := exists_unit_of_abs a obtain ⟨ub, -, hb⟩ := exists_unit_of_abs b use Nat.gcdA (Int.natAbs a) (Int.natAbs b) * ua, Nat.gcdB (Int.natAbs a) (Int.natAbs b) * ub rw [mul_assoc, ← ha, mul_assoc, ← hb, mul_comm, mul_comm _ (Int.natAbs b : ℤ), ← Nat.gcd_eq_gcd_ab, ← gcd_eq_natAbs, hg, Int.ofNat_one] · rintro ⟨r, s, h⟩ by_contra hg obtain ⟨p, ⟨hp, ha, hb⟩⟩ := Nat.Prime.not_coprime_iff_dvd.mp hg apply Nat.Prime.not_dvd_one hp rw [← natCast_dvd_natCast, Int.ofNat_one, ← h] exact dvd_add ((natCast_dvd.mpr ha).mul_left _) ((natCast_dvd.mpr hb).mul_left _) theorem coprime_iff_nat_coprime {a b : ℤ} : IsCoprime a b ↔ Nat.Coprime a.natAbs b.natAbs := by rw [← gcd_eq_one_iff_coprime, Nat.coprime_iff_gcd_eq_one, gcd_eq_natAbs] /-- If `gcd a (m * n) ≠ 1`, then `gcd a m ≠ 1` or `gcd a n ≠ 1`. -/ theorem gcd_ne_one_iff_gcd_mul_right_ne_one {a : ℤ} {m n : ℕ} : a.gcd (m * n) ≠ 1 ↔ a.gcd m ≠ 1 ∨ a.gcd n ≠ 1 := by simp only [gcd_eq_one_iff_coprime, ← not_and_or, not_iff_not, IsCoprime.mul_right_iff] theorem sq_of_gcd_eq_one {a b c : ℤ} (h : Int.gcd a b = 1) (heq : a * b = c ^ 2) : ∃ a0 : ℤ, a = a0 ^ 2 ∨ a = -a0 ^ 2 := by have h' : IsUnit (GCDMonoid.gcd a b) := by rw [← coe_gcd, h, Int.ofNat_one] exact isUnit_one obtain ⟨d, ⟨u, hu⟩⟩ := exists_associated_pow_of_mul_eq_pow h' heq use d rw [← hu] cases' Int.units_eq_one_or u with hu' hu' <;> · rw [hu'] simp theorem sq_of_coprime {a b c : ℤ} (h : IsCoprime a b) (heq : a * b = c ^ 2) : ∃ a0 : ℤ, a = a0 ^ 2 ∨ a = -a0 ^ 2 := sq_of_gcd_eq_one (gcd_eq_one_iff_coprime.mpr h) heq theorem natAbs_euclideanDomain_gcd (a b : ℤ) : Int.natAbs (EuclideanDomain.gcd a b) = Int.gcd a b := by apply Nat.dvd_antisymm <;> rw [← Int.natCast_dvd_natCast] · rw [Int.natAbs_dvd] exact Int.dvd_gcd (EuclideanDomain.gcd_dvd_left _ _) (EuclideanDomain.gcd_dvd_right _ _) · rw [Int.dvd_natAbs] exact EuclideanDomain.dvd_gcd Int.gcd_dvd_left Int.gcd_dvd_right end Int theorem Int.Prime.dvd_mul {m n : ℤ} {p : ℕ} (hp : Nat.Prime p) (h : (p : ℤ) ∣ m * n) : p ∣ m.natAbs ∨ p ∣ n.natAbs := by rwa [← hp.dvd_mul, ← Int.natAbs_mul, ← Int.natCast_dvd] theorem Int.Prime.dvd_mul' {m n : ℤ} {p : ℕ} (hp : Nat.Prime p) (h : (p : ℤ) ∣ m * n) : (p : ℤ) ∣ m ∨ (p : ℤ) ∣ n := by rw [Int.natCast_dvd, Int.natCast_dvd] exact Int.Prime.dvd_mul hp h theorem Int.Prime.dvd_pow {n : ℤ} {k p : ℕ} (hp : Nat.Prime p) (h : (p : ℤ) ∣ n ^ k) : p ∣ n.natAbs := by rw [Int.natCast_dvd, Int.natAbs_pow] at h exact hp.dvd_of_dvd_pow h theorem Int.Prime.dvd_pow' {n : ℤ} {k p : ℕ} (hp : Nat.Prime p) (h : (p : ℤ) ∣ n ^ k) : (p : ℤ) ∣ n := by rw [Int.natCast_dvd] exact Int.Prime.dvd_pow hp h theorem prime_two_or_dvd_of_dvd_two_mul_pow_self_two {m : ℤ} {p : ℕ} (hp : Nat.Prime p) (h : (p : ℤ) ∣ 2 * m ^ 2) : p = 2 ∨ p ∣ Int.natAbs m := by cases' Int.Prime.dvd_mul hp h with hp2 hpp · apply Or.intro_left exact le_antisymm (Nat.le_of_dvd zero_lt_two hp2) (Nat.Prime.two_le hp) · apply Or.intro_right rw [sq, Int.natAbs_mul] at hpp exact or_self_iff.mp ((Nat.Prime.dvd_mul hp).mp hpp) theorem Int.exists_prime_and_dvd {n : ℤ} (hn : n.natAbs ≠ 1) : ∃ p, Prime p ∧ p ∣ n := by obtain ⟨p, pp, pd⟩ := Nat.exists_prime_and_dvd hn exact ⟨p, Nat.prime_iff_prime_int.mp pp, Int.natCast_dvd.mpr pd⟩ theorem Int.prime_iff_natAbs_prime {k : ℤ} : Prime k ↔ Nat.Prime k.natAbs := (Int.associated_natAbs k).prime_iff.trans Nat.prime_iff_prime_int.symm namespace Int theorem zmultiples_natAbs (a : ℤ) : AddSubgroup.zmultiples (a.natAbs : ℤ) = AddSubgroup.zmultiples a := le_antisymm (AddSubgroup.zmultiples_le_of_mem (mem_zmultiples_iff.mpr (dvd_natAbs.mpr dvd_rfl))) (AddSubgroup.zmultiples_le_of_mem (mem_zmultiples_iff.mpr (natAbs_dvd.mpr dvd_rfl))) theorem span_natAbs (a : ℤ) : Ideal.span ({(a.natAbs : ℤ)} : Set ℤ) = Ideal.span {a} := by rw [Ideal.span_singleton_eq_span_singleton] exact (associated_natAbs _).symm theorem eq_pow_of_mul_eq_pow_odd_left {a b c : ℤ} (hab : IsCoprime a b) {k : ℕ} (hk : Odd k) (h : a * b = c ^ k) : ∃ d, a = d ^ k := by obtain ⟨d, hd⟩ := exists_associated_pow_of_mul_eq_pow' hab h replace hd := hd.symm rw [associated_iff_natAbs, natAbs_eq_natAbs_iff, ← hk.neg_pow] at hd obtain rfl | rfl := hd <;> exact ⟨_, rfl⟩ @[deprecated (since := "2024-07-12")] alias eq_pow_of_mul_eq_pow_bit1_left := eq_pow_of_mul_eq_pow_odd_left theorem eq_pow_of_mul_eq_pow_odd_right {a b c : ℤ} (hab : IsCoprime a b) {k : ℕ} (hk : Odd k) (h : a * b = c ^ k) : ∃ d, b = d ^ k := eq_pow_of_mul_eq_pow_odd_left hab.symm hk (by rwa [mul_comm] at h) @[deprecated (since := "2024-07-12")] alias eq_pow_of_mul_eq_pow_bit1_right := eq_pow_of_mul_eq_pow_odd_right theorem eq_pow_of_mul_eq_pow_odd {a b c : ℤ} (hab : IsCoprime a b) {k : ℕ} (hk : Odd k) (h : a * b = c ^ k) : (∃ d, a = d ^ k) ∧ ∃ e, b = e ^ k := ⟨eq_pow_of_mul_eq_pow_odd_left hab hk h, eq_pow_of_mul_eq_pow_odd_right hab hk h⟩ @[deprecated (since := "2024-07-12")] alias eq_pow_of_mul_eq_pow_bit1 := eq_pow_of_mul_eq_pow_odd end Int
RingTheory\IntegralClosure\IntegrallyClosed.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.RingTheory.IntegralClosure.Algebra.Basic import Mathlib.RingTheory.Localization.Integral /-! # Integrally closed rings An integrally closed ring `R` contains all the elements of `Frac(R)` that are integral over `R`. A special case of integrally closed rings are the Dedekind domains. ## Main definitions * `IsIntegrallyClosedIn R A` states `R` contains all integral elements of `A` * `IsIntegrallyClosed R` states `R` contains all integral elements of `Frac(R)` ## Main results * `isIntegrallyClosed_iff K`, where `K` is a fraction field of `R`, states `R` is integrally closed iff it is the integral closure of `R` in `K` ## TODO Related notions The following definitions are closely related, especially in their applications in Mathlib. A *normal domain* is a domain that is integrally closed in its field of fractions. [Stacks: normal domain](https://stacks.math.columbia.edu/tag/037B#0309) Normal domains are the major use case of `IsIntegrallyClosed` at the time of writing, and we have quite a few results that can be moved wholesale to a new `NormalDomain` definition. In fact, before PR #6126 `IsIntegrallyClosed` was exactly defined to be a normal domain. (So you might want to copy some of its API when you define normal domains.) A normal ring means that localizations at all prime ideals are normal domains. [Stacks: normal ring](https://stacks.math.columbia.edu/tag/037B#00GV) This implies `IsIntegrallyClosed`, [Stacks: Tag 034M](https://stacks.math.columbia.edu/tag/037B#034M) but is equivalent to it only under some conditions (reduced + finitely many minimal primes), [Stacks: Tag 030C](https://stacks.math.columbia.edu/tag/037B#030C) in which case it's also equivalent to being a finite product of normal domains. We'd need to add these conditions if we want exactly the products of Dedekind domains. In fact noetherianity is sufficient to guarantee finitely many minimal primes, so `IsDedekindRing` could be defined as `IsReduced`, `IsNoetherian`, `Ring.DimensionLEOne`, and either `IsIntegrallyClosed` or `NormalDomain`. If we use `NormalDomain` then `IsReduced` is automatic, but we could also consider a version of `NormalDomain` that only requires the localizations are `IsIntegrallyClosed` but may not be domains, and that may not equivalent to the ring itself being `IsIntegallyClosed` (even for noetherian rings?). -/ open scoped nonZeroDivisors Polynomial open Polynomial /-- `R` is integrally closed in `A` if all integral elements of `A` are also elements of `R`. -/ abbrev IsIntegrallyClosedIn (R A : Type*) [CommRing R] [CommRing A] [Algebra R A] := IsIntegralClosure R R A /-- `R` is integrally closed if all integral elements of `Frac(R)` are also elements of `R`. This definition uses `FractionRing R` to denote `Frac(R)`. See `isIntegrallyClosed_iff` if you want to choose another field of fractions for `R`. -/ abbrev IsIntegrallyClosed (R : Type*) [CommRing R] := IsIntegrallyClosedIn R (FractionRing R) section Iff variable {R : Type*} [CommRing R] variable {A B : Type*} [CommRing A] [CommRing B] [Algebra R A] [Algebra R B] /-- Being integrally closed is preserved under injective algebra homomorphisms. -/ theorem AlgHom.isIntegrallyClosedIn (f : A →ₐ[R] B) (hf : Function.Injective f) : IsIntegrallyClosedIn R B → IsIntegrallyClosedIn R A := by rintro ⟨inj, cl⟩ refine ⟨Function.Injective.of_comp (f := f) ?_, fun hx => ?_, ?_⟩ · convert inj aesop · obtain ⟨y, fx_eq⟩ := cl.mp ((isIntegral_algHom_iff f hf).mpr hx) aesop · rintro ⟨y, rfl⟩ apply (isIntegral_algHom_iff f hf).mp aesop /-- Being integrally closed is preserved under algebra isomorphisms. -/ theorem AlgEquiv.isIntegrallyClosedIn (e : A ≃ₐ[R] B) : IsIntegrallyClosedIn R A ↔ IsIntegrallyClosedIn R B := ⟨AlgHom.isIntegrallyClosedIn e.symm e.symm.injective, AlgHom.isIntegrallyClosedIn e e.injective⟩ variable (K : Type*) [CommRing K] [Algebra R K] [IsFractionRing R K] /-- `R` is integrally closed iff it is the integral closure of itself in its field of fractions. -/ theorem isIntegrallyClosed_iff_isIntegrallyClosedIn : IsIntegrallyClosed R ↔ IsIntegrallyClosedIn R K := (IsLocalization.algEquiv R⁰ _ _).isIntegrallyClosedIn /-- `R` is integrally closed iff it is the integral closure of itself in its field of fractions. -/ theorem isIntegrallyClosed_iff_isIntegralClosure : IsIntegrallyClosed R ↔ IsIntegralClosure R R K := isIntegrallyClosed_iff_isIntegrallyClosedIn K /-- `R` is integrally closed in `A` iff all integral elements of `A` are also elements of `R`. -/ theorem isIntegrallyClosedIn_iff {R A : Type*} [CommRing R] [CommRing A] [Algebra R A] : IsIntegrallyClosedIn R A ↔ Function.Injective (algebraMap R A) ∧ ∀ {x : A}, IsIntegral R x → ∃ y, algebraMap R A y = x := by constructor · rintro ⟨_, cl⟩ aesop · rintro ⟨inj, cl⟩ refine ⟨inj, by aesop, ?_⟩ rintro ⟨y, rfl⟩ apply isIntegral_algebraMap /-- `R` is integrally closed iff all integral elements of its fraction field `K` are also elements of `R`. -/ theorem isIntegrallyClosed_iff : IsIntegrallyClosed R ↔ ∀ {x : K}, IsIntegral R x → ∃ y, algebraMap R K y = x := by simp [isIntegrallyClosed_iff_isIntegrallyClosedIn K, isIntegrallyClosedIn_iff, IsFractionRing.injective R K] end Iff namespace IsIntegrallyClosedIn variable {R A : Type*} [CommRing R] [CommRing A] [Algebra R A] [iic : IsIntegrallyClosedIn R A] theorem algebraMap_eq_of_integral {x : A} : IsIntegral R x → ∃ y : R, algebraMap R A y = x := IsIntegralClosure.isIntegral_iff.mp theorem isIntegral_iff {x : A} : IsIntegral R x ↔ ∃ y : R, algebraMap R A y = x := IsIntegralClosure.isIntegral_iff theorem exists_algebraMap_eq_of_isIntegral_pow {x : A} {n : ℕ} (hn : 0 < n) (hx : IsIntegral R <| x ^ n) : ∃ y : R, algebraMap R A y = x := isIntegral_iff.mp <| hx.of_pow hn theorem exists_algebraMap_eq_of_pow_mem_subalgebra {A : Type*} [CommRing A] [Algebra R A] {S : Subalgebra R A} [IsIntegrallyClosedIn S A] {x : A} {n : ℕ} (hn : 0 < n) (hx : x ^ n ∈ S) : ∃ y : S, algebraMap S A y = x := exists_algebraMap_eq_of_isIntegral_pow hn <| isIntegral_iff.mpr ⟨⟨x ^ n, hx⟩, rfl⟩ variable (A) theorem integralClosure_eq_bot_iff (hRA : Function.Injective (algebraMap R A)) : integralClosure R A = ⊥ ↔ IsIntegrallyClosedIn R A := by refine eq_bot_iff.trans ?_ constructor · intro h refine ⟨ hRA, fun hx => Set.mem_range.mp (Algebra.mem_bot.mp (h hx)), ?_⟩ rintro ⟨y, rfl⟩ apply isIntegral_algebraMap · intro h x hx rw [Algebra.mem_bot, Set.mem_range] exact isIntegral_iff.mp hx variable (R) @[simp] theorem integralClosure_eq_bot [NoZeroSMulDivisors R A] [Nontrivial A] : integralClosure R A = ⊥ := (integralClosure_eq_bot_iff A (NoZeroSMulDivisors.algebraMap_injective _ _)).mpr ‹_› variable {A} {B : Type*} [CommRing B] /-- If `R` is the integral closure of `S` in `A`, then it is integrally closed in `A`. -/ lemma of_isIntegralClosure [Algebra R B] [Algebra A B] [IsScalarTower R A B] [IsIntegralClosure A R B] : IsIntegrallyClosedIn A B := have : Algebra.IsIntegral R A := IsIntegralClosure.isIntegral_algebra R B IsIntegralClosure.tower_top (R := R) variable {R} lemma _root_.IsIntegralClosure.of_isIntegrallyClosedIn [Algebra R B] [Algebra A B] [IsScalarTower R A B] [IsIntegrallyClosedIn A B] [Algebra.IsIntegral R A] : IsIntegralClosure A R B := by refine ⟨IsIntegralClosure.algebraMap_injective _ A _, fun {x} ↦ ⟨fun hx ↦ IsIntegralClosure.isIntegral_iff.mp (IsIntegral.tower_top (A := A) hx), ?_⟩⟩ rintro ⟨y, rfl⟩ exact IsIntegral.map (IsScalarTower.toAlgHom A A B) (Algebra.IsIntegral.isIntegral y) end IsIntegrallyClosedIn namespace IsIntegrallyClosed variable {R S : Type*} [CommRing R] [CommRing S] [id : IsDomain R] [iic : IsIntegrallyClosed R] variable {K : Type*} [CommRing K] [Algebra R K] [ifr : IsFractionRing R K] /-- Note that this is not a duplicate instance, since `IsIntegrallyClosed R` is instead defined as `IsIntegrallyClosed R R (FractionRing R)`. -/ instance : IsIntegralClosure R R K := (isIntegrallyClosed_iff_isIntegralClosure K).mp iic theorem algebraMap_eq_of_integral {x : K} : IsIntegral R x → ∃ y : R, algebraMap R K y = x := IsIntegralClosure.isIntegral_iff.mp theorem isIntegral_iff {x : K} : IsIntegral R x ↔ ∃ y : R, algebraMap R K y = x := IsIntegrallyClosedIn.isIntegral_iff theorem exists_algebraMap_eq_of_isIntegral_pow {x : K} {n : ℕ} (hn : 0 < n) (hx : IsIntegral R <| x ^ n) : ∃ y : R, algebraMap R K y = x := IsIntegrallyClosedIn.exists_algebraMap_eq_of_isIntegral_pow hn hx theorem exists_algebraMap_eq_of_pow_mem_subalgebra {K : Type*} [CommRing K] [Algebra R K] {S : Subalgebra R K} [IsIntegrallyClosed S] [IsFractionRing S K] {x : K} {n : ℕ} (hn : 0 < n) (hx : x ^ n ∈ S) : ∃ y : S, algebraMap S K y = x := IsIntegrallyClosedIn.exists_algebraMap_eq_of_pow_mem_subalgebra hn hx variable (R S K) instance _root_.IsIntegralClosure.of_isIntegrallyClosed [Algebra S R] [Algebra S K] [IsScalarTower S R K] [Algebra.IsIntegral S R] : IsIntegralClosure R S K := IsIntegralClosure.of_isIntegrallyClosedIn variable {R} theorem integralClosure_eq_bot_iff : integralClosure R K = ⊥ ↔ IsIntegrallyClosed R := (IsIntegrallyClosedIn.integralClosure_eq_bot_iff _ (IsFractionRing.injective _ _)).trans (isIntegrallyClosed_iff_isIntegrallyClosedIn _).symm @[simp] theorem pow_dvd_pow_iff {n : ℕ} (hn : n ≠ 0) {a b : R} : a ^ n ∣ b ^ n ↔ a ∣ b := by refine ⟨fun ⟨x, hx⟩ ↦ ?_, fun h ↦ pow_dvd_pow_of_dvd h n⟩ by_cases ha : a = 0 · simpa [ha, hn] using hx let K := FractionRing R replace ha : algebraMap R K a ≠ 0 := fun h ↦ ha <| (injective_iff_map_eq_zero _).1 (IsFractionRing.injective R K) _ h let y := (algebraMap R K b) / (algebraMap R K a) have hy : IsIntegral R y := by refine ⟨X ^ n - C x, monic_X_pow_sub_C _ hn, ?_⟩ simp only [y, map_pow, eval₂_sub, eval₂_X_pow, div_pow, eval₂_pow', eval₂_C] replace hx := congr_arg (algebraMap R K) hx rw [map_pow] at hx field_simp [hx, ha] obtain ⟨k, hk⟩ := algebraMap_eq_of_integral hy refine ⟨k, IsFractionRing.injective R K ?_⟩ rw [map_mul, hk, mul_div_cancel₀ _ ha] variable (R) /-- This is almost a duplicate of `IsIntegrallyClosedIn.integralClosure_eq_bot`, except the `NoZeroSMulDivisors` hypothesis isn't inferred automatically from `IsFractionRing`. -/ @[simp] theorem integralClosure_eq_bot : integralClosure R K = ⊥ := (integralClosure_eq_bot_iff K).mpr ‹_› end IsIntegrallyClosed namespace integralClosure open IsIntegrallyClosed variable {R : Type*} [CommRing R] variable (K : Type*) [Field K] [Algebra R K] variable [IsFractionRing R K] variable {L : Type*} [Field L] [Algebra K L] [Algebra R L] [IsScalarTower R K L] -- Can't be an instance because you need to supply `K`. theorem isIntegrallyClosedOfFiniteExtension [IsDomain R] [FiniteDimensional K L] : IsIntegrallyClosed (integralClosure R L) := letI : IsFractionRing (integralClosure R L) L := isFractionRing_of_finite_extension K L (integralClosure_eq_bot_iff L).mp integralClosure_idem end integralClosure
RingTheory\IntegralClosure\IntegralRestrict.lean
/- Copyright (c) 2023 Andrew Yang, Patrick Lutz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.RingTheory.IntegralClosure.IntegrallyClosed import Mathlib.RingTheory.LocalProperties import Mathlib.RingTheory.Localization.NormTrace import Mathlib.RingTheory.Localization.LocalizationLocalization import Mathlib.RingTheory.DedekindDomain.IntegralClosure /-! # Restriction of various maps between fields to integrally closed subrings. In this file, we assume `A` is an integrally closed domain; `K` is the fraction ring of `A`; `L` is a finite (separable) extension of `K`; `B` is the integral closure of `A` in `L`. We call this the AKLB setup. ## Main definition - `galRestrict`: The restriction `Aut(L/K) → Aut(B/A)` as an `MulEquiv` in an AKLB setup. - `Algebra.intTrace`: The trace map of a finite extension of integrally closed domains `B/A` is defined to be the restriction of the trace map of `Frac(B)/Frac(A)`. - `Algebra.intNorm`: The norm map of a finite extension of integrally closed domains `B/A` is defined to be the restriction of the norm map of `Frac(B)/Frac(A)`. -/ open nonZeroDivisors variable (A K L B : Type*) [CommRing A] [CommRing B] [Algebra A B] [Field K] [Field L] [Algebra A K] [IsFractionRing A K] [Algebra B L] [Algebra K L] [Algebra A L] [IsScalarTower A B L] [IsScalarTower A K L] [IsIntegralClosure B A L] [FiniteDimensional K L] section galois /-- The lift `End(B/A) → End(L/K)` in an ALKB setup. This is inverse to the restriction. See `galRestrictHom`. -/ noncomputable def galLift (σ : B →ₐ[A] B) : L →ₐ[K] L := haveI := (IsFractionRing.injective A K).isDomain haveI := NoZeroSMulDivisors.trans A K L haveI := IsIntegralClosure.isLocalization A K L B haveI H : ∀ (y : Algebra.algebraMapSubmonoid B A⁰), IsUnit (((algebraMap B L).comp σ) (y : B)) := by rintro ⟨_, x, hx, rfl⟩ simpa only [RingHom.coe_comp, RingHom.coe_coe, Function.comp_apply, AlgHom.commutes, isUnit_iff_ne_zero, ne_eq, map_eq_zero_iff _ (NoZeroSMulDivisors.algebraMap_injective _ _), ← IsScalarTower.algebraMap_apply] using nonZeroDivisors.ne_zero hx haveI H_eq : (IsLocalization.lift (S := L) H).comp (algebraMap K L) = (algebraMap K L) := by apply IsLocalization.ringHom_ext A⁰ ext simp only [RingHom.coe_comp, Function.comp_apply, ← IsScalarTower.algebraMap_apply A K L, IsScalarTower.algebraMap_apply A B L, IsLocalization.lift_eq, RingHom.coe_coe, AlgHom.commutes] { IsLocalization.lift (S := L) H with commutes' := DFunLike.congr_fun H_eq } /-- The restriction `End(L/K) → End(B/A)` in an AKLB setup. Also see `galRestrict` for the `AlgEquiv` version. -/ noncomputable def galRestrictHom : (L →ₐ[K] L) ≃* (B →ₐ[A] B) where toFun := fun f ↦ (IsIntegralClosure.equiv A (integralClosure A L) L B).toAlgHom.comp (((f.restrictScalars A).comp (IsScalarTower.toAlgHom A B L)).codRestrict (integralClosure A L) (fun x ↦ IsIntegral.map _ (IsIntegralClosure.isIntegral A L x))) map_mul' := by intros σ₁ σ₂ ext x apply (IsIntegralClosure.equiv A (integralClosure A L) L B).symm.injective ext dsimp simp only [AlgEquiv.symm_apply_apply, AlgHom.coe_codRestrict, AlgHom.coe_comp, AlgHom.coe_restrictScalars', IsScalarTower.coe_toAlgHom', Function.comp_apply, AlgHom.mul_apply, IsIntegralClosure.algebraMap_equiv, Subalgebra.algebraMap_eq] rfl invFun := galLift A K L B left_inv σ := have := (IsFractionRing.injective A K).isDomain have := IsIntegralClosure.isLocalization A K L B AlgHom.coe_ringHom_injective <| IsLocalization.ringHom_ext (Algebra.algebraMapSubmonoid B A⁰) <| RingHom.ext fun x ↦ by simp [Subalgebra.algebraMap_eq, galLift] right_inv σ := have := (IsFractionRing.injective A K).isDomain have := IsIntegralClosure.isLocalization A K L B AlgHom.ext fun x ↦ IsIntegralClosure.algebraMap_injective B A L (by simp [Subalgebra.algebraMap_eq, galLift]) @[simp] lemma algebraMap_galRestrictHom_apply (σ : L →ₐ[K] L) (x : B) : algebraMap B L (galRestrictHom A K L B σ x) = σ (algebraMap B L x) := by simp [galRestrictHom, Subalgebra.algebraMap_eq] @[simp, nolint unusedHavesSuffices] -- false positive from unfolding galRestrictHom lemma galRestrictHom_symm_algebraMap_apply (σ : B →ₐ[A] B) (x : B) : (galRestrictHom A K L B).symm σ (algebraMap B L x) = algebraMap B L (σ x) := by have := (IsFractionRing.injective A K).isDomain have := IsIntegralClosure.isLocalization A K L B simp [galRestrictHom, galLift, Subalgebra.algebraMap_eq] /-- The restriction `Aut(L/K) → Aut(B/A)` in an AKLB setup. -/ noncomputable def galRestrict : (L ≃ₐ[K] L) ≃* (B ≃ₐ[A] B) := (AlgEquiv.algHomUnitsEquiv K L).symm.trans ((Units.mapEquiv <| galRestrictHom A K L B).trans (AlgEquiv.algHomUnitsEquiv A B)) variable {K L} lemma coe_galRestrict_apply (σ : L ≃ₐ[K] L) : (galRestrict A K L B σ : B →ₐ[A] B) = galRestrictHom A K L B σ := rfl variable {B} lemma galRestrict_apply (σ : L ≃ₐ[K] L) (x : B) : galRestrict A K L B σ x = galRestrictHom A K L B σ x := rfl lemma algebraMap_galRestrict_apply (σ : L ≃ₐ[K] L) (x : B) : algebraMap B L (galRestrict A K L B σ x) = σ (algebraMap B L x) := algebraMap_galRestrictHom_apply A K L B σ.toAlgHom x variable (K L B) lemma prod_galRestrict_eq_norm [IsGalois K L] [IsIntegrallyClosed A] (x : B) : (∏ σ : L ≃ₐ[K] L, galRestrict A K L B σ x) = algebraMap A B (IsIntegralClosure.mk' (R := A) A (Algebra.norm K <| algebraMap B L x) (Algebra.isIntegral_norm K (IsIntegralClosure.isIntegral A L x).algebraMap)) := by apply IsIntegralClosure.algebraMap_injective B A L rw [← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_eq A K L] simp only [map_prod, algebraMap_galRestrict_apply, IsIntegralClosure.algebraMap_mk', Algebra.norm_eq_prod_automorphisms, AlgHom.coe_coe, RingHom.coe_comp, Function.comp_apply] end galois attribute [local instance] FractionRing.liftAlgebra FractionRing.isScalarTower_liftAlgebra noncomputable instance (priority := 900) [IsDomain A] [IsDomain B] [IsIntegrallyClosed B] [Module.Finite A B] [NoZeroSMulDivisors A B] : Fintype (B ≃ₐ[A] B) := haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (Algebra.algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := Module.Finite_of_isLocalization A B _ _ A⁰ Fintype.ofEquiv _ (galRestrict A (FractionRing A) (FractionRing B) B).toEquiv variable {Aₘ Bₘ} [CommRing Aₘ] [CommRing Bₘ] [Algebra Aₘ Bₘ] [Algebra A Aₘ] [Algebra B Bₘ] variable [Algebra A Bₘ] [IsScalarTower A Aₘ Bₘ] [IsScalarTower A B Bₘ] variable (M : Submonoid A) [IsLocalization M Aₘ] variable [IsLocalization (Algebra.algebraMapSubmonoid B M) Bₘ] section trace /-- The restriction of the trace on `L/K` restricted onto `B/A` in an AKLB setup. See `Algebra.intTrace` instead. -/ noncomputable def Algebra.intTraceAux [IsIntegrallyClosed A] : B →ₗ[A] A := (IsIntegralClosure.equiv A (integralClosure A K) K A).toLinearMap.comp ((((Algebra.trace K L).restrictScalars A).comp (IsScalarTower.toAlgHom A B L).toLinearMap).codRestrict (Subalgebra.toSubmodule <| integralClosure A K) (fun x ↦ isIntegral_trace (IsIntegral.algebraMap (IsIntegralClosure.isIntegral A L x)))) variable {A K L B} lemma Algebra.map_intTraceAux [IsIntegrallyClosed A] (x : B) : algebraMap A K (Algebra.intTraceAux A K L B x) = Algebra.trace K L (algebraMap B L x) := IsIntegralClosure.algebraMap_equiv A (integralClosure A K) K A _ variable (A B) variable [IsDomain A] [IsIntegrallyClosed A] [IsDomain B] [IsIntegrallyClosed B] variable [Module.Finite A B] [NoZeroSMulDivisors A B] /-- The trace of a finite extension of integrally closed domains `B/A` is the restriction of the trace on `Frac(B)/Frac(A)` onto `B/A`. See `Algebra.algebraMap_intTrace`. -/ noncomputable def Algebra.intTrace : B →ₗ[A] A := haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := Module.Finite_of_isLocalization A B _ _ A⁰ Algebra.intTraceAux A (FractionRing A) (FractionRing B) B variable {A B} lemma Algebra.algebraMap_intTrace (x : B) : algebraMap A K (Algebra.intTrace A B x) = Algebra.trace K L (algebraMap B L x) := by haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := Module.Finite_of_isLocalization A B _ _ A⁰ haveI := IsIntegralClosure.isFractionRing_of_finite_extension A K L B apply (FractionRing.algEquiv A K).symm.injective rw [AlgEquiv.commutes, Algebra.intTrace, Algebra.map_intTraceAux, ← AlgEquiv.commutes (FractionRing.algEquiv B L)] apply Algebra.trace_eq_of_equiv_equiv (FractionRing.algEquiv A K).toRingEquiv (FractionRing.algEquiv B L).toRingEquiv apply IsLocalization.ringHom_ext A⁰ simp only [AlgEquiv.toRingEquiv_eq_coe, ← AlgEquiv.coe_ringHom_commutes, RingHom.comp_assoc, AlgHom.comp_algebraMap_of_tower, ← IsScalarTower.algebraMap_eq, RingHom.comp_assoc] lemma Algebra.algebraMap_intTrace_fractionRing (x : B) : algebraMap A (FractionRing A) (Algebra.intTrace A B x) = Algebra.trace (FractionRing A) (FractionRing B) (algebraMap B _ x) := by haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := Module.Finite_of_isLocalization A B _ _ A⁰ exact Algebra.map_intTraceAux x variable (A B) lemma Algebra.intTrace_eq_trace [Module.Free A B] : Algebra.intTrace A B = Algebra.trace A B := by ext x haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ apply IsFractionRing.injective A (FractionRing A) rw [Algebra.algebraMap_intTrace_fractionRing, Algebra.trace_localization A A⁰] open nonZeroDivisors variable [IsDomain Aₘ] [IsIntegrallyClosed Aₘ] [IsDomain Bₘ] [IsIntegrallyClosed Bₘ] variable [NoZeroSMulDivisors Aₘ Bₘ] [Module.Finite Aₘ Bₘ] lemma Algebra.intTrace_eq_of_isLocalization (x : B) : algebraMap A Aₘ (Algebra.intTrace A B x) = Algebra.intTrace Aₘ Bₘ (algebraMap B Bₘ x) := by by_cases hM : 0 ∈ M · subsingleton [IsLocalization.uniqueOfZeroMem (S := Aₘ) hM] replace hM : M ≤ A⁰ := fun x hx ↦ mem_nonZeroDivisors_iff_ne_zero.mpr (fun e ↦ hM (e ▸ hx)) let K := FractionRing A let L := FractionRing B have : IsIntegralClosure B A L := IsIntegralClosure.of_isIntegrallyClosed _ _ _ have : IsLocalization (algebraMapSubmonoid B A⁰) L := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ let f : Aₘ →+* K := IsLocalization.map _ (T := A⁰) (RingHom.id A) hM letI := f.toAlgebra have : IsScalarTower A Aₘ K := IsScalarTower.of_algebraMap_eq' (by rw [RingHom.algebraMap_toAlgebra, IsLocalization.map_comp, RingHomCompTriple.comp_eq]) letI := IsFractionRing.isFractionRing_of_isDomain_of_isLocalization M Aₘ K let g : Bₘ →+* L := IsLocalization.map _ (M := algebraMapSubmonoid B M) (T := algebraMapSubmonoid B A⁰) (RingHom.id B) (Submonoid.monotone_map hM) letI := g.toAlgebra have : IsScalarTower B Bₘ L := IsScalarTower.of_algebraMap_eq' (by rw [RingHom.algebraMap_toAlgebra, IsLocalization.map_comp, RingHomCompTriple.comp_eq]) letI := ((algebraMap K L).comp f).toAlgebra have : IsScalarTower Aₘ K L := IsScalarTower.of_algebraMap_eq' rfl have : IsScalarTower Aₘ Bₘ L := by apply IsScalarTower.of_algebraMap_eq' apply IsLocalization.ringHom_ext M rw [RingHom.algebraMap_toAlgebra, RingHom.algebraMap_toAlgebra (R := Bₘ), RingHom.comp_assoc, RingHom.comp_assoc, ← IsScalarTower.algebraMap_eq, IsScalarTower.algebraMap_eq A B Bₘ, IsLocalization.map_comp, RingHom.comp_id, ← RingHom.comp_assoc, IsLocalization.map_comp, RingHom.comp_id, ← IsScalarTower.algebraMap_eq, ← IsScalarTower.algebraMap_eq] letI := IsFractionRing.isFractionRing_of_isDomain_of_isLocalization (algebraMapSubmonoid B M) Bₘ L have : FiniteDimensional K L := Module.Finite_of_isLocalization A B _ _ A⁰ have : IsIntegralClosure Bₘ Aₘ L := IsIntegralClosure.of_isIntegrallyClosed _ _ _ apply IsFractionRing.injective Aₘ K rw [← IsScalarTower.algebraMap_apply, Algebra.algebraMap_intTrace_fractionRing, Algebra.algebraMap_intTrace (L := L), ← IsScalarTower.algebraMap_apply] end trace section norm variable [IsIntegrallyClosed A] /-- The restriction of the norm on `L/K` restricted onto `B/A` in an AKLB setup. See `Algebra.intNorm` instead. -/ noncomputable def Algebra.intNormAux [Algebra.IsSeparable K L] : B →* A where toFun := fun s ↦ IsIntegralClosure.mk' (R := A) A (Algebra.norm K (algebraMap B L s)) (isIntegral_norm K <| IsIntegral.map (IsScalarTower.toAlgHom A B L) (IsIntegralClosure.isIntegral A L s)) map_one' := by simp map_mul' := fun x y ↦ by simpa using IsIntegralClosure.mk'_mul _ _ _ _ _ variable {A K L B} lemma Algebra.map_intNormAux [Algebra.IsSeparable K L] (x : B) : algebraMap A K (Algebra.intNormAux A K L B x) = Algebra.norm K (algebraMap B L x) := by dsimp [Algebra.intNormAux] exact IsIntegralClosure.algebraMap_mk' _ _ _ variable (A B) variable [IsDomain A] [IsDomain B] [IsIntegrallyClosed B] variable [Module.Finite A B] [NoZeroSMulDivisors A B] variable [Algebra.IsSeparable (FractionRing A) (FractionRing B)] -- TODO: remove this /-- The norm of a finite extension of integrally closed domains `B/A` is the restriction of the norm on `Frac(B)/Frac(A)` onto `B/A`. See `Algebra.algebraMap_intNorm`. -/ noncomputable def Algebra.intNorm : B →* A := haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := Module.Finite_of_isLocalization A B _ _ A⁰ Algebra.intNormAux A (FractionRing A) (FractionRing B) B variable {A B} lemma Algebra.algebraMap_intNorm (x : B) : algebraMap A K (Algebra.intNorm A B x) = Algebra.norm K (algebraMap B L x) := by haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := Module.Finite_of_isLocalization A B _ _ A⁰ haveI := IsIntegralClosure.isFractionRing_of_finite_extension A K L B apply (FractionRing.algEquiv A K).symm.injective rw [AlgEquiv.commutes, Algebra.intNorm, Algebra.map_intNormAux, ← AlgEquiv.commutes (FractionRing.algEquiv B L)] apply Algebra.norm_eq_of_equiv_equiv (FractionRing.algEquiv A K).toRingEquiv (FractionRing.algEquiv B L).toRingEquiv apply IsLocalization.ringHom_ext A⁰ simp only [AlgEquiv.toRingEquiv_eq_coe, ← AlgEquiv.coe_ringHom_commutes, RingHom.comp_assoc, AlgHom.comp_algebraMap_of_tower, ← IsScalarTower.algebraMap_eq, RingHom.comp_assoc] @[simp] lemma Algebra.algebraMap_intNorm_fractionRing (x : B) : algebraMap A (FractionRing A) (Algebra.intNorm A B x) = Algebra.norm (FractionRing A) (algebraMap B (FractionRing B) x) := by haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := Module.Finite_of_isLocalization A B _ _ A⁰ exact Algebra.map_intNormAux x variable (A B) lemma Algebra.intNorm_eq_norm [Module.Free A B] : Algebra.intNorm A B = Algebra.norm A := by ext x haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ apply IsFractionRing.injective A (FractionRing A) rw [Algebra.algebraMap_intNorm_fractionRing, Algebra.norm_localization A A⁰] @[simp] lemma Algebra.intNorm_zero : Algebra.intNorm A B 0 = 0 := by haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := Module.Finite_of_isLocalization A B _ _ A⁰ apply IsFractionRing.injective A (FractionRing A) simp only [algebraMap_intNorm_fractionRing, map_zero, norm_zero] variable {A B} @[simp] lemma Algebra.intNorm_eq_zero {x : B} : Algebra.intNorm A B x = 0 ↔ x = 0 := by haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := Module.Finite_of_isLocalization A B _ _ A⁰ rw [← (IsFractionRing.injective A (FractionRing A)).eq_iff, ← (IsFractionRing.injective B (FractionRing B)).eq_iff] simp only [algebraMap_intNorm_fractionRing, map_zero, norm_eq_zero_iff] lemma Algebra.intNorm_ne_zero {x : B} : Algebra.intNorm A B x ≠ 0 ↔ x ≠ 0 := by simp variable [IsDomain Aₘ] [IsIntegrallyClosed Aₘ] [IsDomain Bₘ] [IsIntegrallyClosed Bₘ] variable [NoZeroSMulDivisors Aₘ Bₘ] [Module.Finite Aₘ Bₘ] variable [Algebra.IsSeparable (FractionRing Aₘ) (FractionRing Bₘ)] lemma Algebra.intNorm_eq_of_isLocalization (x : B) : algebraMap A Aₘ (Algebra.intNorm A B x) = Algebra.intNorm Aₘ Bₘ (algebraMap B Bₘ x) := by by_cases hM : 0 ∈ M · subsingleton [IsLocalization.uniqueOfZeroMem (S := Aₘ) hM] replace hM : M ≤ A⁰ := fun x hx ↦ mem_nonZeroDivisors_iff_ne_zero.mpr (fun e ↦ hM (e ▸ hx)) let K := FractionRing A let L := FractionRing B have : IsIntegralClosure B A L := IsIntegralClosure.of_isIntegrallyClosed _ _ _ have : IsLocalization (algebraMapSubmonoid B A⁰) L := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ let f : Aₘ →+* K := IsLocalization.map _ (T := A⁰) (RingHom.id A) hM letI := f.toAlgebra have : IsScalarTower A Aₘ K := IsScalarTower.of_algebraMap_eq' (by rw [RingHom.algebraMap_toAlgebra, IsLocalization.map_comp, RingHomCompTriple.comp_eq]) letI := IsFractionRing.isFractionRing_of_isDomain_of_isLocalization M Aₘ K let g : Bₘ →+* L := IsLocalization.map _ (M := algebraMapSubmonoid B M) (T := algebraMapSubmonoid B A⁰) (RingHom.id B) (Submonoid.monotone_map hM) letI := g.toAlgebra have : IsScalarTower B Bₘ L := IsScalarTower.of_algebraMap_eq' (by rw [RingHom.algebraMap_toAlgebra, IsLocalization.map_comp, RingHomCompTriple.comp_eq]) letI := ((algebraMap K L).comp f).toAlgebra have : IsScalarTower Aₘ K L := IsScalarTower.of_algebraMap_eq' rfl have : IsScalarTower Aₘ Bₘ L := by apply IsScalarTower.of_algebraMap_eq' apply IsLocalization.ringHom_ext M rw [RingHom.algebraMap_toAlgebra, RingHom.algebraMap_toAlgebra (R := Bₘ), RingHom.comp_assoc, RingHom.comp_assoc, ← IsScalarTower.algebraMap_eq, IsScalarTower.algebraMap_eq A B Bₘ, IsLocalization.map_comp, RingHom.comp_id, ← RingHom.comp_assoc, IsLocalization.map_comp, RingHom.comp_id, ← IsScalarTower.algebraMap_eq, ← IsScalarTower.algebraMap_eq] letI := IsFractionRing.isFractionRing_of_isDomain_of_isLocalization (algebraMapSubmonoid B M) Bₘ L have : FiniteDimensional K L := Module.Finite_of_isLocalization A B _ _ A⁰ have : IsIntegralClosure Bₘ Aₘ L := IsIntegralClosure.of_isIntegrallyClosed _ _ _ apply IsFractionRing.injective Aₘ K rw [← IsScalarTower.algebraMap_apply, Algebra.algebraMap_intNorm_fractionRing, Algebra.algebraMap_intNorm (L := L), ← IsScalarTower.algebraMap_apply] end norm lemma Algebra.algebraMap_intNorm_of_isGalois [IsDomain A] [IsIntegrallyClosed A] [IsDomain B] [IsIntegrallyClosed B] [Module.Finite A B] [NoZeroSMulDivisors A B] [IsGalois (FractionRing A) (FractionRing B)] {x : B} : algebraMap A B (Algebra.intNorm A B x) = ∏ σ : B ≃ₐ[A] B, σ x := by haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (Algebra.algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := Module.Finite_of_isLocalization A B _ _ A⁰ rw [← (galRestrict A (FractionRing A) (FractionRing B) B).toEquiv.prod_comp] simp only [MulEquiv.toEquiv_eq_coe, EquivLike.coe_coe] convert (prod_galRestrict_eq_norm A (FractionRing A) (FractionRing B) B x).symm
RingTheory\IntegralClosure\Algebra\Basic.lean
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.RingTheory.IntegralClosure.Algebra.Defs import Mathlib.RingTheory.IntegralClosure.IsIntegral.Basic import Mathlib.LinearAlgebra.Matrix.Charpoly.LinearMap /-! # Integral closure of a subring. Let `A` be an `R`-algebra. We prove that integral elements form a sub-`R`-algebra of `A`. ## Main definitions Let `R` be a `CommRing` and let `A` be an R-algebra. * `integralClosure R A` : the integral closure of `R` in an `R`-algebra `A`. -/ open Polynomial Submodule section variable {R A B S : Type*} variable [CommRing R] [CommRing A] [Ring B] [CommRing S] variable [Algebra R A] [Algebra R B] (f : R →+* S) section variable {A B : Type*} [Ring A] [Ring B] [Algebra R A] [Algebra R B] variable (f : A →ₐ[R] B) (hf : Function.Injective f) end instance Module.End.isIntegral {M : Type*} [AddCommGroup M] [Module R M] [Module.Finite R M] : Algebra.IsIntegral R (Module.End R M) := ⟨LinearMap.exists_monic_and_aeval_eq_zero R⟩ variable (R) theorem IsIntegral.of_finite [Module.Finite R B] (x : B) : IsIntegral R x := (isIntegral_algHom_iff (Algebra.lmul R B) Algebra.lmul_injective).mp (Algebra.IsIntegral.isIntegral _) variable (B) instance Algebra.IsIntegral.of_finite [Module.Finite R B] : Algebra.IsIntegral R B := ⟨.of_finite R⟩ variable {R B} /-- If `S` is a sub-`R`-algebra of `A` and `S` is finitely-generated as an `R`-module, then all elements of `S` are integral over `R`. -/ theorem IsIntegral.of_mem_of_fg {A} [Ring A] [Algebra R A] (S : Subalgebra R A) (HS : S.toSubmodule.FG) (x : A) (hx : x ∈ S) : IsIntegral R x := have : Module.Finite R S := ⟨(fg_top _).mpr HS⟩ (isIntegral_algHom_iff S.val Subtype.val_injective).mpr (.of_finite R (⟨x, hx⟩ : S)) theorem RingHom.IsIntegralElem.of_mem_closure {x y z : S} (hx : f.IsIntegralElem x) (hy : f.IsIntegralElem y) (hz : z ∈ Subring.closure ({x, y} : Set S)) : f.IsIntegralElem z := by letI : Algebra R S := f.toAlgebra have := (IsIntegral.fg_adjoin_singleton hx).mul (IsIntegral.fg_adjoin_singleton hy) rw [← Algebra.adjoin_union_coe_submodule, Set.singleton_union] at this exact IsIntegral.of_mem_of_fg (Algebra.adjoin R {x, y}) this z (Algebra.mem_adjoin_iff.2 <| Subring.closure_mono Set.subset_union_right hz) nonrec theorem IsIntegral.of_mem_closure {x y z : A} (hx : IsIntegral R x) (hy : IsIntegral R y) (hz : z ∈ Subring.closure ({x, y} : Set A)) : IsIntegral R z := hx.of_mem_closure (algebraMap R A) hy hz variable (f : R →+* B) theorem RingHom.IsIntegralElem.add (f : R →+* S) {x y : S} (hx : f.IsIntegralElem x) (hy : f.IsIntegralElem y) : f.IsIntegralElem (x + y) := hx.of_mem_closure f hy <| Subring.add_mem _ (Subring.subset_closure (Or.inl rfl)) (Subring.subset_closure (Or.inr rfl)) nonrec theorem IsIntegral.add {x y : A} (hx : IsIntegral R x) (hy : IsIntegral R y) : IsIntegral R (x + y) := hx.add (algebraMap R A) hy variable (f : R →+* S) -- can be generalized to noncommutative S. theorem RingHom.IsIntegralElem.neg {x : S} (hx : f.IsIntegralElem x) : f.IsIntegralElem (-x) := hx.of_mem_closure f hx (Subring.neg_mem _ (Subring.subset_closure (Or.inl rfl))) theorem IsIntegral.neg {x : B} (hx : IsIntegral R x) : IsIntegral R (-x) := .of_mem_of_fg _ hx.fg_adjoin_singleton _ (Subalgebra.neg_mem _ <| Algebra.subset_adjoin rfl) theorem RingHom.IsIntegralElem.sub {x y : S} (hx : f.IsIntegralElem x) (hy : f.IsIntegralElem y) : f.IsIntegralElem (x - y) := by simpa only [sub_eq_add_neg] using hx.add f (hy.neg f) nonrec theorem IsIntegral.sub {x y : A} (hx : IsIntegral R x) (hy : IsIntegral R y) : IsIntegral R (x - y) := hx.sub (algebraMap R A) hy theorem RingHom.IsIntegralElem.mul {x y : S} (hx : f.IsIntegralElem x) (hy : f.IsIntegralElem y) : f.IsIntegralElem (x * y) := hx.of_mem_closure f hy (Subring.mul_mem _ (Subring.subset_closure (Or.inl rfl)) (Subring.subset_closure (Or.inr rfl))) nonrec theorem IsIntegral.mul {x y : A} (hx : IsIntegral R x) (hy : IsIntegral R y) : IsIntegral R (x * y) := hx.mul (algebraMap R A) hy theorem IsIntegral.smul {R} [CommSemiring R] [CommRing S] [Algebra R B] [Algebra S B] [Algebra R S] [IsScalarTower R S B] {x : B} (r : R)(hx : IsIntegral S x) : IsIntegral S (r • x) := .of_mem_of_fg _ hx.fg_adjoin_singleton _ <| by rw [← algebraMap_smul S]; apply Subalgebra.smul_mem; exact Algebra.subset_adjoin rfl variable (R A) /-- The integral closure of `R` in an `R`-algebra `A`. -/ def integralClosure : Subalgebra R A where carrier := { r | IsIntegral R r } zero_mem' := isIntegral_zero one_mem' := isIntegral_one add_mem' := IsIntegral.add mul_mem' := IsIntegral.mul algebraMap_mem' _ := isIntegral_algebraMap end
RingTheory\IntegralClosure\Algebra\Defs.lean
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.RingTheory.IntegralClosure.IsIntegral.Defs /-! # Integral algebras ## Main definitions Let `R` be a `CommRing` and let `A` be an R-algebra. * `Algebra.IsIntegral R A` : An algebra is integral if every element of the extension is integral over the base ring. -/ open Polynomial Submodule section Ring variable {R S A : Type*} variable [CommRing R] [Ring A] [Ring S] (f : R →+* S) variable [Algebra R A] (R) variable (A) /-- An algebra is integral if every element of the extension is integral over the base ring. -/ protected class Algebra.IsIntegral : Prop := isIntegral : ∀ x : A, IsIntegral R x variable {R A} lemma Algebra.isIntegral_def : Algebra.IsIntegral R A ↔ ∀ x : A, IsIntegral R x := ⟨fun ⟨h⟩ ↦ h, fun h ↦ ⟨h⟩⟩ end Ring
RingTheory\IntegralClosure\IsIntegral\Basic.lean
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.RingTheory.IntegralClosure.IsIntegral.Defs import Mathlib.Algebra.Polynomial.Expand import Mathlib.RingTheory.Polynomial.Tower /-! # Properties of integral elements. We prove basic properties of integral elements in a ring extension. -/ open Polynomial Submodule section Ring variable {R S A : Type*} variable [CommRing R] [Ring A] [Ring S] (f : R →+* S) variable [Algebra R A] theorem RingHom.isIntegralElem_map {x : R} : f.IsIntegralElem (f x) := ⟨X - C x, monic_X_sub_C _, by simp⟩ theorem isIntegral_algebraMap {x : R} : IsIntegral R (algebraMap R A x) := (algebraMap R A).isIntegralElem_map end Ring section variable {R A B S : Type*} variable [CommRing R] [CommRing A] [Ring B] [CommRing S] variable [Algebra R A] (f : R →+* S) theorem IsIntegral.map {B C F : Type*} [Ring B] [Ring C] [Algebra R B] [Algebra A B] [Algebra R C] [IsScalarTower R A B] [Algebra A C] [IsScalarTower R A C] {b : B} [FunLike F B C] [AlgHomClass F A B C] (f : F) (hb : IsIntegral R b) : IsIntegral R (f b) := by obtain ⟨P, hP⟩ := hb refine ⟨P, hP.1, ?_⟩ rw [← aeval_def, ← aeval_map_algebraMap A, aeval_algHom_apply, aeval_map_algebraMap, aeval_def, hP.2, _root_.map_zero] section variable {A B : Type*} [Ring A] [Ring B] [Algebra R A] [Algebra R B] theorem isIntegral_algHom_iff (f : A →ₐ[R] B) (hf : Function.Injective f) {x : A} : IsIntegral R (f x) ↔ IsIntegral R x := by refine ⟨fun ⟨p, hp, hx⟩ ↦ ⟨p, hp, ?_⟩, IsIntegral.map f⟩ rwa [← f.comp_algebraMap, ← AlgHom.coe_toRingHom, ← hom_eval₂, AlgHom.coe_toRingHom, map_eq_zero_iff f hf] at hx end open Classical in theorem Submodule.span_range_natDegree_eq_adjoin {R A} [CommRing R] [Semiring A] [Algebra R A] {x : A} {f : R[X]} (hf : f.Monic) (hfx : aeval x f = 0) : span R (Finset.image (x ^ ·) (Finset.range (natDegree f))) = Subalgebra.toSubmodule (Algebra.adjoin R {x}) := by nontriviality A have hf1 : f ≠ 1 := by rintro rfl; simp [one_ne_zero' A] at hfx refine (span_le.mpr fun s hs ↦ ?_).antisymm fun r hr ↦ ?_ · rcases Finset.mem_image.1 hs with ⟨k, -, rfl⟩ exact (Algebra.adjoin R {x}).pow_mem (Algebra.subset_adjoin rfl) k rw [Subalgebra.mem_toSubmodule, Algebra.adjoin_singleton_eq_range_aeval] at hr rcases (aeval x).mem_range.mp hr with ⟨p, rfl⟩ rw [← modByMonic_add_div p hf, map_add, map_mul, hfx, zero_mul, add_zero, ← sum_C_mul_X_pow_eq (p %ₘ f), aeval_def, eval₂_sum, sum_def] refine sum_mem fun k hkq ↦ ?_ rw [C_mul_X_pow_eq_monomial, eval₂_monomial, ← Algebra.smul_def] exact smul_mem _ _ (subset_span <| Finset.mem_image_of_mem _ <| Finset.mem_range.mpr <| (le_natDegree_of_mem_supp _ hkq).trans_lt <| natDegree_modByMonic_lt p hf hf1) theorem IsIntegral.fg_adjoin_singleton [Algebra R B] {x : B} (hx : IsIntegral R x) : (Algebra.adjoin R {x}).toSubmodule.FG := by classical rcases hx with ⟨f, hfm, hfx⟩ use (Finset.range <| f.natDegree).image (x ^ ·) exact span_range_natDegree_eq_adjoin hfm (by rwa [aeval_def]) variable (f : R →+* B) theorem RingHom.isIntegralElem_zero : f.IsIntegralElem 0 := f.map_zero ▸ f.isIntegralElem_map theorem isIntegral_zero [Algebra R B] : IsIntegral R (0 : B) := (algebraMap R B).isIntegralElem_zero theorem RingHom.isIntegralElem_one : f.IsIntegralElem 1 := f.map_one ▸ f.isIntegralElem_map theorem isIntegral_one [Algebra R B] : IsIntegral R (1 : B) := (algebraMap R B).isIntegralElem_one variable (f : R →+* S) theorem IsIntegral.of_pow [Algebra R B] {x : B} {n : ℕ} (hn : 0 < n) (hx : IsIntegral R <| x ^ n) : IsIntegral R x := by rcases hx with ⟨p, hmonic, heval⟩ exact ⟨expand R n p, hmonic.expand hn, by rwa [← aeval_def, expand_aeval]⟩ end
RingTheory\IntegralClosure\IsIntegral\Defs.lean
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.Polynomial.Eval /-! # Integral closure of a subring. If A is an R-algebra then `a : A` is integral over R if it is a root of a monic polynomial with coefficients in R. ## Main definitions Let `R` be a `CommRing` and let `A` be an R-algebra. * `RingHom.IsIntegralElem (f : R →+* A) (x : A)` : `x` is integral with respect to the map `f`, * `IsIntegral (x : A)` : `x` is integral over `R`, i.e., is a root of a monic polynomial with coefficients in `R`. -/ open Polynomial section Ring variable {R S A : Type*} variable [CommRing R] [Ring A] [Ring S] (f : R →+* S) /-- An element `x` of `A` is said to be integral over `R` with respect to `f` if it is a root of a monic polynomial `p : R[X]` evaluated under `f` -/ def RingHom.IsIntegralElem (f : R →+* A) (x : A) := ∃ p : R[X], Monic p ∧ eval₂ f x p = 0 /-- A ring homomorphism `f : R →+* A` is said to be integral if every element `A` is integral with respect to the map `f` -/ def RingHom.IsIntegral (f : R →+* A) := ∀ x : A, f.IsIntegralElem x variable [Algebra R A] (R) /-- An element `x` of an algebra `A` over a commutative ring `R` is said to be *integral*, if it is a root of some monic polynomial `p : R[X]`. Equivalently, the element is integral over `R` with respect to the induced `algebraMap` -/ def IsIntegral (x : A) : Prop := (algebraMap R A).IsIntegralElem x end Ring
RingTheory\IntegralClosure\IsIntegralClosure\Basic.lean
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.RingTheory.IntegralClosure.IsIntegralClosure.Defs import Mathlib.RingTheory.IntegralClosure.Algebra.Basic import Mathlib.RingTheory.FiniteType import Mathlib.RingTheory.Polynomial.ScaleRoots /-! # # Integral closure as a characteristic predicate We prove basic properties of `IsIntegralClosure`. -/ open scoped Classical open Polynomial Submodule section variable {R A B S : Type*} variable [CommRing R] [CommRing A] [Ring B] [CommRing S] variable [Algebra R A] [Algebra R B] (f : R →+* S) theorem IsIntegral.map_of_comp_eq {R S T U : Type*} [CommRing R] [Ring S] [CommRing T] [Ring U] [Algebra R S] [Algebra T U] (φ : R →+* T) (ψ : S →+* U) (h : (algebraMap T U).comp φ = ψ.comp (algebraMap R S)) {a : S} (ha : IsIntegral R a) : IsIntegral T (ψ a) := let ⟨p, hp⟩ := ha ⟨p.map φ, hp.1.map _, by rw [← eval_map, map_map, h, ← map_map, eval_map, eval₂_at_apply, eval_map, hp.2, ψ.map_zero]⟩ section variable {A B : Type*} [Ring A] [Ring B] [Algebra R A] [Algebra R B] variable (f : A →ₐ[R] B) theorem Algebra.IsIntegral.of_injective (hf : Function.Injective f) [Algebra.IsIntegral R B] : Algebra.IsIntegral R A := ⟨fun _ ↦ (isIntegral_algHom_iff f hf).mp (isIntegral _)⟩ end @[simp] theorem isIntegral_algEquiv {A B : Type*} [Ring A] [Ring B] [Algebra R A] [Algebra R B] (f : A ≃ₐ[R] B) {x : A} : IsIntegral R (f x) ↔ IsIntegral R x := ⟨fun h ↦ by simpa using h.map f.symm, IsIntegral.map f⟩ /-- If `R → A → B` is an algebra tower, then if the entire tower is an integral extension so is `A → B`. -/ theorem IsIntegral.tower_top [Algebra A B] [IsScalarTower R A B] {x : B} (hx : IsIntegral R x) : IsIntegral A x := let ⟨p, hp, hpx⟩ := hx ⟨p.map <| algebraMap R A, hp.map _, by rw [← aeval_def, aeval_map_algebraMap, aeval_def, hpx]⟩ theorem map_isIntegral_int {B C F : Type*} [Ring B] [Ring C] {b : B} [FunLike F B C] [RingHomClass F B C] (f : F) (hb : IsIntegral ℤ b) : IsIntegral ℤ (f b) := hb.map (f : B →+* C).toIntAlgHom theorem IsIntegral.of_subring {x : B} (T : Subring R) (hx : IsIntegral T x) : IsIntegral R x := hx.tower_top protected theorem IsIntegral.algebraMap [Algebra A B] [IsScalarTower R A B] {x : A} (h : IsIntegral R x) : IsIntegral R (algebraMap A B x) := by rcases h with ⟨f, hf, hx⟩ use f, hf rw [IsScalarTower.algebraMap_eq R A B, ← hom_eval₂, hx, RingHom.map_zero] theorem isIntegral_algebraMap_iff [Algebra A B] [IsScalarTower R A B] {x : A} (hAB : Function.Injective (algebraMap A B)) : IsIntegral R (algebraMap A B x) ↔ IsIntegral R x := isIntegral_algHom_iff (IsScalarTower.toAlgHom R A B) hAB theorem isIntegral_iff_isIntegral_closure_finite {r : B} : IsIntegral R r ↔ ∃ s : Set R, s.Finite ∧ IsIntegral (Subring.closure s) r := by constructor <;> intro hr · rcases hr with ⟨p, hmp, hpr⟩ refine ⟨_, Finset.finite_toSet _, p.restriction, monic_restriction.2 hmp, ?_⟩ rw [← aeval_def, ← aeval_map_algebraMap R r p.restriction, map_restriction, aeval_def, hpr] rcases hr with ⟨s, _, hsr⟩ exact hsr.of_subring _ theorem fg_adjoin_of_finite {s : Set A} (hfs : s.Finite) (his : ∀ x ∈ s, IsIntegral R x) : (Algebra.adjoin R s).toSubmodule.FG := Set.Finite.induction_on hfs (fun _ => ⟨{1}, Submodule.ext fun x => by rw [Algebra.adjoin_empty, Finset.coe_singleton, ← one_eq_span, Algebra.toSubmodule_bot]⟩) (fun {a s} _ _ ih his => by rw [← Set.union_singleton, Algebra.adjoin_union_coe_submodule] exact FG.mul (ih fun i hi => his i <| Set.mem_insert_of_mem a hi) (his a <| Set.mem_insert a s).fg_adjoin_singleton) his theorem isNoetherian_adjoin_finset [IsNoetherianRing R] (s : Finset A) (hs : ∀ x ∈ s, IsIntegral R x) : IsNoetherian R (Algebra.adjoin R (s : Set A)) := isNoetherian_of_fg_of_noetherian _ (fg_adjoin_of_finite s.finite_toSet hs) theorem isIntegral_of_noetherian (_ : IsNoetherian R B) (x : B) : IsIntegral R x := .of_finite R x theorem isIntegral_of_submodule_noetherian (S : Subalgebra R B) (H : IsNoetherian R (Subalgebra.toSubmodule S)) (x : B) (hx : x ∈ S) : IsIntegral R x := .of_mem_of_fg _ ((fg_top _).mp <| H.noetherian _) _ hx /-- Suppose `A` is an `R`-algebra, `M` is an `A`-module such that `a • m ≠ 0` for all non-zero `a` and `m`. If `x : A` fixes a nontrivial f.g. `R`-submodule `N` of `M`, then `x` is `R`-integral. -/ theorem isIntegral_of_smul_mem_submodule {M : Type*} [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors A M] (N : Submodule R M) (hN : N ≠ ⊥) (hN' : N.FG) (x : A) (hx : ∀ n ∈ N, x • n ∈ N) : IsIntegral R x := by let A' : Subalgebra R A := { carrier := { x | ∀ n ∈ N, x • n ∈ N } mul_mem' := fun {a b} ha hb n hn => smul_smul a b n ▸ ha _ (hb _ hn) one_mem' := fun n hn => (one_smul A n).symm ▸ hn add_mem' := fun {a b} ha hb n hn => (add_smul a b n).symm ▸ N.add_mem (ha _ hn) (hb _ hn) zero_mem' := fun n _hn => (zero_smul A n).symm ▸ N.zero_mem algebraMap_mem' := fun r n hn => (algebraMap_smul A r n).symm ▸ N.smul_mem r hn } let f : A' →ₐ[R] Module.End R N := AlgHom.ofLinearMap { toFun := fun x => (DistribMulAction.toLinearMap R M x).restrict x.prop -- Porting note: was -- `fun x y => LinearMap.ext fun n => Subtype.ext <| add_smul x y n` map_add' := by intros x y; ext; exact add_smul _ _ _ -- Porting note: was -- `fun r s => LinearMap.ext fun n => Subtype.ext <| smul_assoc r s n` map_smul' := by intros r s; ext; apply smul_assoc } -- Porting note: the next two lines were --`(LinearMap.ext fun n => Subtype.ext <| one_smul _ _) fun x y =>` --`LinearMap.ext fun n => Subtype.ext <| mul_smul x y n` (by ext; apply one_smul) (by intros x y; ext; apply mul_smul) obtain ⟨a, ha₁, ha₂⟩ : ∃ a ∈ N, a ≠ (0 : M) := by by_contra! h' apply hN rwa [eq_bot_iff] have : Function.Injective f := by show Function.Injective f.toLinearMap rw [← LinearMap.ker_eq_bot, eq_bot_iff] intro s hs have : s.1 • a = 0 := congr_arg Subtype.val (LinearMap.congr_fun hs ⟨a, ha₁⟩) exact Subtype.ext ((eq_zero_or_eq_zero_of_smul_eq_zero this).resolve_right ha₂) show IsIntegral R (A'.val ⟨x, hx⟩) rw [isIntegral_algHom_iff A'.val Subtype.val_injective, ← isIntegral_algHom_iff f this] haveI : Module.Finite R N := by rwa [Module.finite_def, Submodule.fg_top] apply Algebra.IsIntegral.isIntegral variable {f} theorem RingHom.Finite.to_isIntegral (h : f.Finite) : f.IsIntegral := letI := f.toAlgebra fun _ ↦ IsIntegral.of_mem_of_fg ⊤ h.1 _ trivial alias RingHom.IsIntegral.of_finite := RingHom.Finite.to_isIntegral /-- The [Kurosh problem](https://en.wikipedia.org/wiki/Kurosh_problem) asks to show that this is still true when `A` is not necessarily commutative and `R` is a field, but it has been solved in the negative. See https://arxiv.org/pdf/1706.02383.pdf for criteria for a finitely generated algebraic (= integral) algebra over a field to be finite dimensional. This could be an `instance`, but we tend to go from `Module.Finite` to `IsIntegral`/`IsAlgebraic`, and making it an instance will cause the search to be complicated a lot. -/ theorem Algebra.IsIntegral.finite [Algebra.IsIntegral R A] [h' : Algebra.FiniteType R A] : Module.Finite R A := have ⟨s, hs⟩ := h' ⟨by apply hs ▸ fg_adjoin_of_finite s.finite_toSet fun x _ ↦ Algebra.IsIntegral.isIntegral x⟩ /-- finite = integral + finite type -/ theorem Algebra.finite_iff_isIntegral_and_finiteType : Module.Finite R A ↔ Algebra.IsIntegral R A ∧ Algebra.FiniteType R A := ⟨fun _ ↦ ⟨⟨.of_finite R⟩, inferInstance⟩, fun ⟨h, _⟩ ↦ h.finite⟩ theorem RingHom.IsIntegral.to_finite (h : f.IsIntegral) (h' : f.FiniteType) : f.Finite := let _ := f.toAlgebra let _ : Algebra.IsIntegral R S := ⟨h⟩ Algebra.IsIntegral.finite (h' := h') alias RingHom.Finite.of_isIntegral_of_finiteType := RingHom.IsIntegral.to_finite /-- finite = integral + finite type -/ theorem RingHom.finite_iff_isIntegral_and_finiteType : f.Finite ↔ f.IsIntegral ∧ f.FiniteType := ⟨fun h ↦ ⟨h.to_isIntegral, h.to_finiteType⟩, fun ⟨h, h'⟩ ↦ h.to_finite h'⟩ variable (f : R →+* S) (R A) theorem mem_integralClosure_iff_mem_fg {r : A} : r ∈ integralClosure R A ↔ ∃ M : Subalgebra R A, M.toSubmodule.FG ∧ r ∈ M := ⟨fun hr => ⟨Algebra.adjoin R {r}, hr.fg_adjoin_singleton, Algebra.subset_adjoin rfl⟩, fun ⟨M, Hf, hrM⟩ => .of_mem_of_fg M Hf _ hrM⟩ variable {R A} theorem adjoin_le_integralClosure {x : A} (hx : IsIntegral R x) : Algebra.adjoin R {x} ≤ integralClosure R A := by rw [Algebra.adjoin_le_iff] simp only [SetLike.mem_coe, Set.singleton_subset_iff] exact hx theorem le_integralClosure_iff_isIntegral {S : Subalgebra R A} : S ≤ integralClosure R A ↔ Algebra.IsIntegral R S := SetLike.forall.symm.trans <| (forall_congr' fun x => show IsIntegral R (algebraMap S A x) ↔ IsIntegral R x from isIntegral_algebraMap_iff Subtype.coe_injective).trans Algebra.isIntegral_def.symm theorem Algebra.isIntegral_sup {S T : Subalgebra R A} : Algebra.IsIntegral R (S ⊔ T : Subalgebra R A) ↔ Algebra.IsIntegral R S ∧ Algebra.IsIntegral R T := by simp only [← le_integralClosure_iff_isIntegral, sup_le_iff] /-- Mapping an integral closure along an `AlgEquiv` gives the integral closure. -/ theorem integralClosure_map_algEquiv [Algebra R S] (f : A ≃ₐ[R] S) : (integralClosure R A).map (f : A →ₐ[R] S) = integralClosure R S := by ext y rw [Subalgebra.mem_map] constructor · rintro ⟨x, hx, rfl⟩ exact hx.map f · intro hy use f.symm y, hy.map (f.symm : S →ₐ[R] A) simp /-- An `AlgHom` between two rings restrict to an `AlgHom` between the integral closures inside them. -/ def AlgHom.mapIntegralClosure [Algebra R S] (f : A →ₐ[R] S) : integralClosure R A →ₐ[R] integralClosure R S := (f.restrictDomain (integralClosure R A)).codRestrict (integralClosure R S) (fun ⟨_, h⟩ => h.map f) @[simp] theorem AlgHom.coe_mapIntegralClosure [Algebra R S] (f : A →ₐ[R] S) (x : integralClosure R A) : (f.mapIntegralClosure x : S) = f (x : A) := rfl /-- An `AlgEquiv` between two rings restrict to an `AlgEquiv` between the integral closures inside them. -/ def AlgEquiv.mapIntegralClosure [Algebra R S] (f : A ≃ₐ[R] S) : integralClosure R A ≃ₐ[R] integralClosure R S := AlgEquiv.ofAlgHom (f : A →ₐ[R] S).mapIntegralClosure (f.symm : S →ₐ[R] A).mapIntegralClosure (AlgHom.ext fun _ ↦ Subtype.ext (f.right_inv _)) (AlgHom.ext fun _ ↦ Subtype.ext (f.left_inv _)) @[simp] theorem AlgEquiv.coe_mapIntegralClosure [Algebra R S] (f : A ≃ₐ[R] S) (x : integralClosure R A) : (f.mapIntegralClosure x : S) = f (x : A) := rfl theorem integralClosure.isIntegral (x : integralClosure R A) : IsIntegral R x := let ⟨p, hpm, hpx⟩ := x.2 ⟨p, hpm, Subtype.eq <| by rwa [← aeval_def, ← Subalgebra.val_apply, aeval_algHom_apply] at hpx⟩ instance integralClosure.AlgebraIsIntegral : Algebra.IsIntegral R (integralClosure R A) := ⟨integralClosure.isIntegral⟩ theorem IsIntegral.of_mul_unit {x y : B} {r : R} (hr : algebraMap R B r * y = 1) (hx : IsIntegral R (x * y)) : IsIntegral R x := by obtain ⟨p, p_monic, hp⟩ := hx refine ⟨scaleRoots p r, (monic_scaleRoots_iff r).2 p_monic, ?_⟩ convert scaleRoots_aeval_eq_zero hp rw [Algebra.commutes] at hr ⊢ rw [mul_assoc, hr, mul_one]; rfl theorem RingHom.IsIntegralElem.of_mul_unit (x y : S) (r : R) (hr : f r * y = 1) (hx : f.IsIntegralElem (x * y)) : f.IsIntegralElem x := letI : Algebra R S := f.toAlgebra IsIntegral.of_mul_unit hr hx /-- Generalization of `IsIntegral.of_mem_closure` bootstrapped up from that lemma -/ theorem IsIntegral.of_mem_closure' (G : Set A) (hG : ∀ x ∈ G, IsIntegral R x) : ∀ x ∈ Subring.closure G, IsIntegral R x := fun _ hx ↦ Subring.closure_induction hx hG isIntegral_zero isIntegral_one (fun _ _ ↦ IsIntegral.add) (fun _ ↦ IsIntegral.neg) fun _ _ ↦ IsIntegral.mul theorem IsIntegral.of_mem_closure'' {S : Type*} [CommRing S] {f : R →+* S} (G : Set S) (hG : ∀ x ∈ G, f.IsIntegralElem x) : ∀ x ∈ Subring.closure G, f.IsIntegralElem x := fun x hx => @IsIntegral.of_mem_closure' R S _ _ f.toAlgebra G hG x hx theorem IsIntegral.pow {x : B} (h : IsIntegral R x) (n : ℕ) : IsIntegral R (x ^ n) := .of_mem_of_fg _ h.fg_adjoin_singleton _ <| Subalgebra.pow_mem _ (by exact Algebra.subset_adjoin rfl) _ theorem IsIntegral.nsmul {x : B} (h : IsIntegral R x) (n : ℕ) : IsIntegral R (n • x) := h.smul n theorem IsIntegral.zsmul {x : B} (h : IsIntegral R x) (n : ℤ) : IsIntegral R (n • x) := h.smul n theorem IsIntegral.multiset_prod {s : Multiset A} (h : ∀ x ∈ s, IsIntegral R x) : IsIntegral R s.prod := (integralClosure R A).multiset_prod_mem h theorem IsIntegral.multiset_sum {s : Multiset A} (h : ∀ x ∈ s, IsIntegral R x) : IsIntegral R s.sum := (integralClosure R A).multiset_sum_mem h theorem IsIntegral.prod {α : Type*} {s : Finset α} (f : α → A) (h : ∀ x ∈ s, IsIntegral R (f x)) : IsIntegral R (∏ x ∈ s, f x) := (integralClosure R A).prod_mem h theorem IsIntegral.sum {α : Type*} {s : Finset α} (f : α → A) (h : ∀ x ∈ s, IsIntegral R (f x)) : IsIntegral R (∑ x ∈ s, f x) := (integralClosure R A).sum_mem h theorem IsIntegral.det {n : Type*} [Fintype n] [DecidableEq n] {M : Matrix n n A} (h : ∀ i j, IsIntegral R (M i j)) : IsIntegral R M.det := by rw [Matrix.det_apply] exact IsIntegral.sum _ fun σ _hσ ↦ (IsIntegral.prod _ fun i _hi => h _ _).zsmul _ @[simp] theorem IsIntegral.pow_iff {x : A} {n : ℕ} (hn : 0 < n) : IsIntegral R (x ^ n) ↔ IsIntegral R x := ⟨IsIntegral.of_pow hn, fun hx ↦ hx.pow n⟩ open TensorProduct theorem IsIntegral.tmul (x : A) {y : B} (h : IsIntegral R y) : IsIntegral A (x ⊗ₜ[R] y) := by rw [← mul_one x, ← smul_eq_mul, ← smul_tmul'] exact smul _ (h.map_of_comp_eq (algebraMap R A) (Algebra.TensorProduct.includeRight (R := R) (A := A) (B := B)).toRingHom Algebra.TensorProduct.includeLeftRingHom_comp_algebraMap) section variable (p : R[X]) (x : S) /-- The monic polynomial whose roots are `p.leadingCoeff * x` for roots `x` of `p`. -/ noncomputable def normalizeScaleRoots (p : R[X]) : R[X] := ∑ i ∈ p.support, monomial i (if i = p.natDegree then 1 else p.coeff i * p.leadingCoeff ^ (p.natDegree - 1 - i)) theorem normalizeScaleRoots_coeff_mul_leadingCoeff_pow (i : ℕ) (hp : 1 ≤ natDegree p) : (normalizeScaleRoots p).coeff i * p.leadingCoeff ^ i = p.coeff i * p.leadingCoeff ^ (p.natDegree - 1) := by simp only [normalizeScaleRoots, finset_sum_coeff, coeff_monomial, Finset.sum_ite_eq', one_mul, zero_mul, mem_support_iff, ite_mul, Ne, ite_not] split_ifs with h₁ h₂ · simp [h₁] · rw [h₂, leadingCoeff, ← pow_succ', tsub_add_cancel_of_le hp] · rw [mul_assoc, ← pow_add, tsub_add_cancel_of_le] apply Nat.le_sub_one_of_lt rw [lt_iff_le_and_ne] exact ⟨le_natDegree_of_ne_zero h₁, h₂⟩ theorem leadingCoeff_smul_normalizeScaleRoots (p : R[X]) : p.leadingCoeff • normalizeScaleRoots p = scaleRoots p p.leadingCoeff := by ext simp only [coeff_scaleRoots, normalizeScaleRoots, coeff_monomial, coeff_smul, Finset.smul_sum, Ne, Finset.sum_ite_eq', finset_sum_coeff, smul_ite, smul_zero, mem_support_iff] -- Porting note: added the following `simp only` simp only [tsub_le_iff_right, smul_eq_mul, mul_ite, mul_one, mul_zero, Finset.sum_ite_eq', mem_support_iff, ne_eq, ite_not] split_ifs with h₁ h₂ · simp [*] · simp [*] · rw [mul_comm, mul_assoc, ← pow_succ, tsub_right_comm, tsub_add_cancel_of_le] rw [Nat.succ_le_iff] exact tsub_pos_of_lt (lt_of_le_of_ne (le_natDegree_of_ne_zero h₁) h₂) theorem normalizeScaleRoots_support : (normalizeScaleRoots p).support ≤ p.support := by intro x contrapose simp only [not_mem_support_iff, normalizeScaleRoots, finset_sum_coeff, coeff_monomial, Finset.sum_ite_eq', mem_support_iff, Ne, Classical.not_not, ite_eq_right_iff] intro h₁ h₂ exact (h₂ h₁).elim theorem normalizeScaleRoots_degree : (normalizeScaleRoots p).degree = p.degree := by apply le_antisymm · exact Finset.sup_mono (normalizeScaleRoots_support p) · rw [← degree_scaleRoots, ← leadingCoeff_smul_normalizeScaleRoots] exact degree_smul_le _ _ theorem normalizeScaleRoots_eval₂_leadingCoeff_mul (h : 1 ≤ p.natDegree) (f : R →+* S) (x : S) : (normalizeScaleRoots p).eval₂ f (f p.leadingCoeff * x) = f p.leadingCoeff ^ (p.natDegree - 1) * p.eval₂ f x := by rw [eval₂_eq_sum_range, eval₂_eq_sum_range, Finset.mul_sum] apply Finset.sum_congr · rw [natDegree_eq_of_degree_eq (normalizeScaleRoots_degree p)] intro n _hn rw [mul_pow, ← mul_assoc, ← f.map_pow, ← f.map_mul, normalizeScaleRoots_coeff_mul_leadingCoeff_pow _ _ h, f.map_mul, f.map_pow] ring theorem normalizeScaleRoots_monic (h : p ≠ 0) : (normalizeScaleRoots p).Monic := by delta Monic leadingCoeff rw [natDegree_eq_of_degree_eq (normalizeScaleRoots_degree p)] suffices p = 0 → (0 : R) = 1 by simpa [normalizeScaleRoots, coeff_monomial] exact fun h' => (h h').elim /-- Given a `p : R[X]` and a `x : S` such that `p.eval₂ f x = 0`, `f p.leadingCoeff * x` is integral. -/ theorem RingHom.isIntegralElem_leadingCoeff_mul (h : p.eval₂ f x = 0) : f.IsIntegralElem (f p.leadingCoeff * x) := by by_cases h' : 1 ≤ p.natDegree · use normalizeScaleRoots p have : p ≠ 0 := fun h'' => by rw [h'', natDegree_zero] at h' exact Nat.not_succ_le_zero 0 h' use normalizeScaleRoots_monic p this rw [normalizeScaleRoots_eval₂_leadingCoeff_mul p h' f x, h, mul_zero] · by_cases hp : p.map f = 0 · apply_fun fun q => coeff q p.natDegree at hp rw [coeff_map, coeff_zero, coeff_natDegree] at hp rw [hp, zero_mul] exact f.isIntegralElem_zero · rw [Nat.one_le_iff_ne_zero, Classical.not_not] at h' rw [eq_C_of_natDegree_eq_zero h', eval₂_C] at h suffices p.map f = 0 by exact (hp this).elim rw [eq_C_of_natDegree_eq_zero h', map_C, h, C_eq_zero] /-- Given a `p : R[X]` and a root `x : S`, then `p.leadingCoeff • x : S` is integral over `R`. -/ theorem isIntegral_leadingCoeff_smul [Algebra R S] (h : aeval x p = 0) : IsIntegral R (p.leadingCoeff • x) := by rw [aeval_def] at h rw [Algebra.smul_def] exact (algebraMap R S).isIntegralElem_leadingCoeff_mul p x h end end section IsIntegralClosure instance integralClosure.isIntegralClosure (R A : Type*) [CommRing R] [CommRing A] [Algebra R A] : IsIntegralClosure (integralClosure R A) R A where algebraMap_injective' := Subtype.coe_injective isIntegral_iff {x} := ⟨fun h => ⟨⟨x, h⟩, rfl⟩, by rintro ⟨⟨_, h⟩, rfl⟩; exact h⟩ namespace IsIntegralClosure -- Porting note: added to work around missing infer kind support theorem algebraMap_injective (A R B : Type*) [CommRing R] [CommSemiring A] [CommRing B] [Algebra R B] [Algebra A B] [IsIntegralClosure A R B] : Function.Injective (algebraMap A B) := algebraMap_injective' R variable {R A B : Type*} [CommRing R] [CommRing A] [CommRing B] variable [Algebra R B] [Algebra A B] [IsIntegralClosure A R B] variable (R B) protected theorem isIntegral [Algebra R A] [IsScalarTower R A B] (x : A) : IsIntegral R x := (isIntegral_algebraMap_iff (algebraMap_injective A R B)).mp <| show IsIntegral R (algebraMap A B x) from isIntegral_iff.mpr ⟨x, rfl⟩ theorem isIntegral_algebra [Algebra R A] [IsScalarTower R A B] : Algebra.IsIntegral R A := ⟨fun x => IsIntegralClosure.isIntegral R B x⟩ theorem noZeroSMulDivisors [Algebra R A] [IsScalarTower R A B] [NoZeroSMulDivisors R B] : NoZeroSMulDivisors R A := by refine Function.Injective.noZeroSMulDivisors _ (IsIntegralClosure.algebraMap_injective A R B) (map_zero _) fun _ _ => ?_ simp only [Algebra.algebraMap_eq_smul_one, IsScalarTower.smul_assoc] variable {R} (A) {B} /-- If `x : B` is integral over `R`, then it is an element of the integral closure of `R` in `B`. -/ noncomputable def mk' (x : B) (hx : IsIntegral R x) : A := Classical.choose (isIntegral_iff.mp hx) @[simp] theorem algebraMap_mk' (x : B) (hx : IsIntegral R x) : algebraMap A B (mk' A x hx) = x := Classical.choose_spec (isIntegral_iff.mp hx) @[simp] theorem mk'_one (h : IsIntegral R (1 : B) := isIntegral_one) : mk' A 1 h = 1 := algebraMap_injective A R B <| by rw [algebraMap_mk', RingHom.map_one] @[simp] theorem mk'_zero (h : IsIntegral R (0 : B) := isIntegral_zero) : mk' A 0 h = 0 := algebraMap_injective A R B <| by rw [algebraMap_mk', RingHom.map_zero] -- Porting note: Left-hand side does not simplify @[simp] theorem mk'_add (x y : B) (hx : IsIntegral R x) (hy : IsIntegral R y) : mk' A (x + y) (hx.add hy) = mk' A x hx + mk' A y hy := algebraMap_injective A R B <| by simp only [algebraMap_mk', RingHom.map_add] -- Porting note: Left-hand side does not simplify @[simp] theorem mk'_mul (x y : B) (hx : IsIntegral R x) (hy : IsIntegral R y) : mk' A (x * y) (hx.mul hy) = mk' A x hx * mk' A y hy := algebraMap_injective A R B <| by simp only [algebraMap_mk', RingHom.map_mul] @[simp] theorem mk'_algebraMap [Algebra R A] [IsScalarTower R A B] (x : R) (h : IsIntegral R (algebraMap R B x) := isIntegral_algebraMap) : IsIntegralClosure.mk' A (algebraMap R B x) h = algebraMap R A x := algebraMap_injective A R B <| by rw [algebraMap_mk', ← IsScalarTower.algebraMap_apply] section lift variable (B) {S : Type*} [CommRing S] [Algebra R S] -- split from above, since otherwise it does not synthesize `Semiring S` variable [Algebra S B] [IsScalarTower R S B] variable [Algebra R A] [IsScalarTower R A B] [isIntegral : Algebra.IsIntegral R S] variable (R) /-- If `B / S / R` is a tower of ring extensions where `S` is integral over `R`, then `S` maps (uniquely) into an integral closure `B / A / R`. -/ noncomputable def lift : S →ₐ[R] A where toFun x := mk' A (algebraMap S B x) (IsIntegral.algebraMap (Algebra.IsIntegral.isIntegral (R := R) x)) map_one' := by simp only [RingHom.map_one, mk'_one] map_zero' := by simp only [RingHom.map_zero, mk'_zero] map_add' x y := by simp_rw [← mk'_add, map_add] map_mul' x y := by simp_rw [← mk'_mul, RingHom.map_mul] commutes' x := by simp_rw [← IsScalarTower.algebraMap_apply, mk'_algebraMap] @[simp] theorem algebraMap_lift (x : S) : algebraMap A B (lift R A B x) = algebraMap S B x := algebraMap_mk' A (algebraMap S B x) (IsIntegral.algebraMap (Algebra.IsIntegral.isIntegral (R := R) x)) end lift section Equiv variable (R B) (A' : Type*) [CommRing A'] variable [Algebra A' B] [IsIntegralClosure A' R B] variable [Algebra R A] [Algebra R A'] [IsScalarTower R A B] [IsScalarTower R A' B] /-- Integral closures are all isomorphic to each other. -/ noncomputable def equiv : A ≃ₐ[R] A' := AlgEquiv.ofAlgHom (lift _ B (isIntegral := isIntegral_algebra R B)) (lift _ B (isIntegral := isIntegral_algebra R B)) (by ext x; apply algebraMap_injective A' R B; simp) (by ext x; apply algebraMap_injective A R B; simp) @[simp] theorem algebraMap_equiv (x : A) : algebraMap A' B (equiv R A B A' x) = algebraMap A B x := algebraMap_lift A' B (isIntegral := isIntegral_algebra R B) x end Equiv end IsIntegralClosure end IsIntegralClosure section Algebra open Algebra variable {R A B S T : Type*} variable [CommRing R] [CommRing A] [Ring B] [CommRing S] [CommRing T] variable [Algebra A B] [Algebra R B] (f : R →+* S) (g : S →+* T) variable [Algebra R A] [IsScalarTower R A B] /-- If A is an R-algebra all of whose elements are integral over R, and x is an element of an A-algebra that is integral over A, then x is integral over R. -/ theorem isIntegral_trans [Algebra.IsIntegral R A] (x : B) (hx : IsIntegral A x) : IsIntegral R x := by rcases hx with ⟨p, pmonic, hp⟩ let S := adjoin R (p.coeffs : Set A) have : Module.Finite R S := ⟨(Subalgebra.toSubmodule S).fg_top.mpr <| fg_adjoin_of_finite p.coeffs.finite_toSet fun a _ ↦ Algebra.IsIntegral.isIntegral a⟩ let p' : S[X] := p.toSubring S.toSubring subset_adjoin have hSx : IsIntegral S x := ⟨p', (p.monic_toSubring _ _).mpr pmonic, by rw [IsScalarTower.algebraMap_eq S A B, ← eval₂_map] convert hp; apply p.map_toSubring S.toSubring⟩ let Sx := Subalgebra.toSubmodule (adjoin S {x}) let MSx : Module S Sx := SMulMemClass.toModule _ -- the next line times out without this have : Module.Finite S Sx := ⟨(Submodule.fg_top _).mpr hSx.fg_adjoin_singleton⟩ refine .of_mem_of_fg ((adjoin S {x}).restrictScalars R) ?_ _ ((Subalgebra.mem_restrictScalars R).mpr <| subset_adjoin rfl) rw [← Submodule.fg_top, ← Module.finite_def] letI : SMul S Sx := { MSx with } -- need this even though MSx is there have : IsScalarTower R S Sx := Submodule.isScalarTower Sx -- Lean looks for `Module A Sx` without this exact Module.Finite.trans S Sx variable (A) in /-- If A is an R-algebra all of whose elements are integral over R, and B is an A-algebra all of whose elements are integral over A, then all elements of B are integral over R. -/ protected theorem Algebra.IsIntegral.trans [Algebra.IsIntegral R A] [Algebra.IsIntegral A B] : Algebra.IsIntegral R B := ⟨fun x ↦ isIntegral_trans x (Algebra.IsIntegral.isIntegral (R := A) x)⟩ protected theorem RingHom.IsIntegral.trans (hf : f.IsIntegral) (hg : g.IsIntegral) : (g.comp f).IsIntegral := let _ := f.toAlgebra; let _ := g.toAlgebra; let _ := (g.comp f).toAlgebra have : IsScalarTower R S T := IsScalarTower.of_algebraMap_eq fun _ ↦ rfl have : Algebra.IsIntegral R S := ⟨hf⟩ have : Algebra.IsIntegral S T := ⟨hg⟩ have : Algebra.IsIntegral R T := Algebra.IsIntegral.trans S Algebra.IsIntegral.isIntegral /-- If `R → A → B` is an algebra tower, `C` is the integral closure of `R` in `B` and `A` is integral over `R`, then `C` is the integral closure of `A` in `B`. -/ lemma IsIntegralClosure.tower_top {B C : Type*} [CommRing C] [CommRing B] [Algebra R B] [Algebra A B] [Algebra C B] [IsScalarTower R A B] [IsIntegralClosure C R B] [Algebra.IsIntegral R A] : IsIntegralClosure C A B := ⟨IsIntegralClosure.algebraMap_injective _ R _, fun hx => (IsIntegralClosure.isIntegral_iff).mp (isIntegral_trans (R := R) _ hx), fun hx => ((IsIntegralClosure.isIntegral_iff (R := R)).mpr hx).tower_top⟩ theorem RingHom.isIntegral_of_surjective (hf : Function.Surjective f) : f.IsIntegral := fun x ↦ (hf x).recOn fun _y hy ↦ hy ▸ f.isIntegralElem_map theorem Algebra.isIntegral_of_surjective (h : Function.Surjective (algebraMap R A)) : Algebra.IsIntegral R A := ⟨(algebraMap R A).isIntegral_of_surjective h⟩ /-- If `R → A → B` is an algebra tower with `A → B` injective, then if the entire tower is an integral extension so is `R → A` -/ theorem IsIntegral.tower_bot (H : Function.Injective (algebraMap A B)) {x : A} (h : IsIntegral R (algebraMap A B x)) : IsIntegral R x := (isIntegral_algHom_iff (IsScalarTower.toAlgHom R A B) H).mp h nonrec theorem RingHom.IsIntegral.tower_bot (hg : Function.Injective g) (hfg : (g.comp f).IsIntegral) : f.IsIntegral := letI := f.toAlgebra; letI := g.toAlgebra; letI := (g.comp f).toAlgebra haveI : IsScalarTower R S T := IsScalarTower.of_algebraMap_eq fun _ ↦ rfl fun x ↦ IsIntegral.tower_bot hg (hfg (g x)) theorem IsIntegral.tower_bot_of_field {R A B : Type*} [CommRing R] [Field A] [CommRing B] [Nontrivial B] [Algebra R A] [Algebra A B] [Algebra R B] [IsScalarTower R A B] {x : A} (h : IsIntegral R (algebraMap A B x)) : IsIntegral R x := h.tower_bot (algebraMap A B).injective theorem RingHom.isIntegralElem.of_comp {x : T} (h : (g.comp f).IsIntegralElem x) : g.IsIntegralElem x := let ⟨p, hp, hp'⟩ := h ⟨p.map f, hp.map f, by rwa [← eval₂_map] at hp'⟩ theorem RingHom.IsIntegral.tower_top (h : (g.comp f).IsIntegral) : g.IsIntegral := fun x ↦ RingHom.isIntegralElem.of_comp f g (h x) theorem RingHom.IsIntegral.quotient {I : Ideal S} (hf : f.IsIntegral) : (Ideal.quotientMap I f le_rfl).IsIntegral := by rintro ⟨x⟩ obtain ⟨p, p_monic, hpx⟩ := hf x refine ⟨p.map (Ideal.Quotient.mk _), p_monic.map _, ?_⟩ simpa only [hom_eval₂, eval₂_map] using congr_arg (Ideal.Quotient.mk I) hpx instance Algebra.IsIntegral.quotient {I : Ideal A} [Algebra.IsIntegral R A] : Algebra.IsIntegral (R ⧸ I.comap (algebraMap R A)) (A ⧸ I) := ⟨RingHom.IsIntegral.quotient (algebraMap R A) Algebra.IsIntegral.isIntegral⟩ theorem isIntegral_quotientMap_iff {I : Ideal S} : (Ideal.quotientMap I f le_rfl).IsIntegral ↔ ((Ideal.Quotient.mk I).comp f : R →+* S ⧸ I).IsIntegral := by let g := Ideal.Quotient.mk (I.comap f) -- Porting note: added type ascription have : (Ideal.quotientMap I f le_rfl).comp g = (Ideal.Quotient.mk I).comp f := Ideal.quotientMap_comp_mk le_rfl refine ⟨fun h => ?_, fun h => RingHom.IsIntegral.tower_top g _ (this ▸ h)⟩ refine this ▸ RingHom.IsIntegral.trans g (Ideal.quotientMap I f le_rfl) ?_ h exact g.isIntegral_of_surjective Ideal.Quotient.mk_surjective /-- If the integral extension `R → S` is injective, and `S` is a field, then `R` is also a field. -/ theorem isField_of_isIntegral_of_isField {R S : Type*} [CommRing R] [CommRing S] [Algebra R S] [Algebra.IsIntegral R S] (hRS : Function.Injective (algebraMap R S)) (hS : IsField S) : IsField R := by have := hS.nontrivial; have := Module.nontrivial R S refine ⟨⟨0, 1, zero_ne_one⟩, mul_comm, fun {a} ha ↦ ?_⟩ -- Let `a_inv` be the inverse of `algebraMap R S a`, -- then we need to show that `a_inv` is of the form `algebraMap R S b`. obtain ⟨a_inv, ha_inv⟩ := hS.mul_inv_cancel fun h ↦ ha (hRS (h.trans (RingHom.map_zero _).symm)) letI : Invertible a_inv := (Units.mkOfMulEqOne a_inv _ <| mul_comm _ a_inv ▸ ha_inv).invertible -- Let `p : R[X]` be monic with root `a_inv`, obtain ⟨p, p_monic, hp⟩ := Algebra.IsIntegral.isIntegral (R := R) a_inv -- and `q` be `p` with coefficients reversed (so `q(a) = q'(a) * a + 1`). -- We have `q(a) = 0`, so `-q'(a)` is the inverse of `a`. use -p.reverse.divX.eval a -- -q'(a) nth_rewrite 1 [mul_neg, ← eval_X (x := a), ← eval_mul, ← p_monic, ← coeff_zero_reverse, ← add_eq_zero_iff_neg_eq, ← eval_C (a := p.reverse.coeff 0), ← eval_add, X_mul_divX_add, ← (injective_iff_map_eq_zero' _).mp hRS, ← aeval_algebraMap_apply_eq_algebraMap_eval] rwa [← eval₂_reverse_eq_zero_iff] at hp theorem isField_of_isIntegral_of_isField' {R S : Type*} [CommRing R] [CommRing S] [IsDomain S] [Algebra R S] [Algebra.IsIntegral R S] (hR : IsField R) : IsField S := by refine ⟨⟨0, 1, zero_ne_one⟩, mul_comm, fun {x} hx ↦ ?_⟩ have : Module.Finite R (adjoin R {x}) := ⟨(Submodule.fg_top _).mpr (Algebra.IsIntegral.isIntegral x).fg_adjoin_singleton⟩ letI := hR.toField obtain ⟨y, hy⟩ := FiniteDimensional.exists_mul_eq_one R (K := adjoin R {x}) (x := ⟨x, subset_adjoin rfl⟩) (mt Subtype.ext_iff.mp hx) exact ⟨y, Subtype.ext_iff.mp hy⟩ theorem Algebra.IsIntegral.isField_iff_isField {R S : Type*} [CommRing R] [CommRing S] [IsDomain S] [Algebra R S] [Algebra.IsIntegral R S] (hRS : Function.Injective (algebraMap R S)) : IsField R ↔ IsField S := ⟨isField_of_isIntegral_of_isField', isField_of_isIntegral_of_isField hRS⟩ end Algebra theorem integralClosure_idem {R A : Type*} [CommRing R] [CommRing A] [Algebra R A] : integralClosure (integralClosure R A : Set A) A = ⊥ := letI := (integralClosure R A).algebra eq_bot_iff.2 fun x hx ↦ Algebra.mem_bot.2 ⟨⟨x, isIntegral_trans (A := integralClosure R A) x hx⟩, rfl⟩ section IsDomain variable {R S : Type*} [CommRing R] [CommRing S] [IsDomain S] [Algebra R S] instance : IsDomain (integralClosure R S) := inferInstance theorem roots_mem_integralClosure {f : R[X]} (hf : f.Monic) {a : S} (ha : a ∈ f.aroots S) : a ∈ integralClosure R S := ⟨f, hf, (eval₂_eq_eval_map _).trans <| (mem_roots <| (hf.map _).ne_zero).1 ha⟩ end IsDomain
RingTheory\IntegralClosure\IsIntegralClosure\Defs.lean
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.RingTheory.IntegralClosure.IsIntegral.Defs /-! # Integral closure as a characteristic predicate ## Main definitions Let `R` be a `CommRing` and let `A` be an R-algebra. * `IsIntegralClosure R A` : the characteristic predicate stating `A` is the integral closure of `R` in `B`, i.e. that an element of `B` is integral over `R` iff it is an element of (the image of) `A`. -/ open Polynomial section IsIntegralClosure /-- `IsIntegralClosure A R B` is the characteristic predicate stating `A` is the integral closure of `R` in `B`, i.e. that an element of `B` is integral over `R` iff it is an element of (the image of) `A`. -/ class IsIntegralClosure (A R B : Type*) [CommRing R] [CommSemiring A] [CommRing B] [Algebra R B] [Algebra A B] : Prop where algebraMap_injective' : Function.Injective (algebraMap A B) isIntegral_iff : ∀ {x : B}, IsIntegral R x ↔ ∃ y, algebraMap A B y = x end IsIntegralClosure
RingTheory\Kaehler\Basic.lean
/- Copyright (c) 2020 Nicolò Cavalleri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nicolò Cavalleri, Andrew Yang -/ import Mathlib.RingTheory.Derivation.ToSquareZero import Mathlib.RingTheory.Ideal.Cotangent import Mathlib.RingTheory.IsTensorProduct import Mathlib.RingTheory.EssentialFiniteness import Mathlib.Algebra.Exact import Mathlib.LinearAlgebra.TensorProduct.RightExactness /-! # The module of kaehler differentials ## Main results - `KaehlerDifferential`: The module of kaehler differentials. For an `R`-algebra `S`, we provide the notation `Ω[S⁄R]` for `KaehlerDifferential R S`. Note that the slash is `\textfractionsolidus`. - `KaehlerDifferential.D`: The derivation into the module of kaehler differentials. - `KaehlerDifferential.span_range_derivation`: The image of `D` spans `Ω[S⁄R]` as an `S`-module. - `KaehlerDifferential.linearMapEquivDerivation`: The isomorphism `Hom_R(Ω[S⁄R], M) ≃ₗ[S] Der_R(S, M)`. - `KaehlerDifferential.quotKerTotalEquiv`: An alternative description of `Ω[S⁄R]` as `S` copies of `S` with kernel (`KaehlerDifferential.kerTotal`) generated by the relations: 1. `dx + dy = d(x + y)` 2. `x dy + y dx = d(x * y)` 3. `dr = 0` for `r ∈ R` - `KaehlerDifferential.map`: Given a map between the arrows `R →+* A` and `S →+* B`, we have an `A`-linear map `Ω[A⁄R] → Ω[B⁄S]`. - `KaehlerDifferential.map_surjective`: The sequence `Ω[B⁄R] → Ω[B⁄A] → 0` is exact. - `KaehlerDifferential.exact_mapBaseChange_map`: The sequence `B ⊗[A] Ω[A⁄R] → Ω[B⁄R] → Ω[B⁄A]` is exact. - `KaehlerDifferential.exact_kerCotangentToTensor_mapBaseChange`: If `A → B` is surjective with kernel `I`, then the sequence `I/I² → B ⊗[A] Ω[A⁄R] → Ω[B⁄R]` is exact. - `KaehlerDifferential.mapBaseChange_surjective`: If `A → B` is surjective, then the sequence `B ⊗[A] Ω[A⁄R] → Ω[B⁄R] → 0` is exact. ## Future project - Define the `IsKaehlerDifferential` predicate. -/ suppress_compilation section KaehlerDifferential open scoped TensorProduct open Algebra universe u v variable (R : Type u) (S : Type v) [CommRing R] [CommRing S] [Algebra R S] /-- The kernel of the multiplication map `S ⊗[R] S →ₐ[R] S`. -/ abbrev KaehlerDifferential.ideal : Ideal (S ⊗[R] S) := RingHom.ker (TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S) variable {S} theorem KaehlerDifferential.one_smul_sub_smul_one_mem_ideal (a : S) : (1 : S) ⊗ₜ[R] a - a ⊗ₜ[R] (1 : S) ∈ KaehlerDifferential.ideal R S := by simp [RingHom.mem_ker] variable {R} variable {M : Type*} [AddCommGroup M] [Module R M] [Module S M] [IsScalarTower R S M] /-- For a `R`-derivation `S → M`, this is the map `S ⊗[R] S →ₗ[S] M` sending `s ⊗ₜ t ↦ s • D t`. -/ def Derivation.tensorProductTo (D : Derivation R S M) : S ⊗[R] S →ₗ[S] M := TensorProduct.AlgebraTensorModule.lift ((LinearMap.lsmul S (S →ₗ[R] M)).flip D.toLinearMap) theorem Derivation.tensorProductTo_tmul (D : Derivation R S M) (s t : S) : D.tensorProductTo (s ⊗ₜ t) = s • D t := rfl theorem Derivation.tensorProductTo_mul (D : Derivation R S M) (x y : S ⊗[R] S) : D.tensorProductTo (x * y) = TensorProduct.lmul' (S := S) R x • D.tensorProductTo y + TensorProduct.lmul' (S := S) R y • D.tensorProductTo x := by refine TensorProduct.induction_on x ?_ ?_ ?_ · rw [zero_mul, map_zero, map_zero, zero_smul, smul_zero, add_zero] swap · intro x₁ y₁ h₁ h₂ rw [add_mul, map_add, map_add, map_add, add_smul, smul_add, h₁, h₂, add_add_add_comm] intro x₁ x₂ refine TensorProduct.induction_on y ?_ ?_ ?_ · rw [mul_zero, map_zero, map_zero, zero_smul, smul_zero, add_zero] swap · intro x₁ y₁ h₁ h₂ rw [mul_add, map_add, map_add, map_add, add_smul, smul_add, h₁, h₂, add_add_add_comm] intro x y simp only [TensorProduct.tmul_mul_tmul, Derivation.tensorProductTo, TensorProduct.AlgebraTensorModule.lift_apply, TensorProduct.lift.tmul', TensorProduct.lmul'_apply_tmul] dsimp rw [D.leibniz] simp only [smul_smul, smul_add, mul_comm (x * y) x₁, mul_right_comm x₁ x₂, ← mul_assoc] variable (R S) /-- The kernel of `S ⊗[R] S →ₐ[R] S` is generated by `1 ⊗ s - s ⊗ 1` as a `S`-module. -/ theorem KaehlerDifferential.submodule_span_range_eq_ideal : Submodule.span S (Set.range fun s : S => (1 : S) ⊗ₜ[R] s - s ⊗ₜ[R] (1 : S)) = (KaehlerDifferential.ideal R S).restrictScalars S := by apply le_antisymm · rw [Submodule.span_le] rintro _ ⟨s, rfl⟩ exact KaehlerDifferential.one_smul_sub_smul_one_mem_ideal _ _ · rintro x (hx : _ = _) have : x - TensorProduct.lmul' (S := S) R x ⊗ₜ[R] (1 : S) = x := by rw [hx, TensorProduct.zero_tmul, sub_zero] rw [← this] clear this hx refine TensorProduct.induction_on x ?_ ?_ ?_ · rw [map_zero, TensorProduct.zero_tmul, sub_zero]; exact zero_mem _ · intro x y have : x ⊗ₜ[R] y - (x * y) ⊗ₜ[R] (1 : S) = x • ((1 : S) ⊗ₜ y - y ⊗ₜ (1 : S)) := by simp_rw [smul_sub, TensorProduct.smul_tmul', smul_eq_mul, mul_one] rw [TensorProduct.lmul'_apply_tmul, this] refine Submodule.smul_mem _ x ?_ apply Submodule.subset_span exact Set.mem_range_self y · intro x y hx hy rw [map_add, TensorProduct.add_tmul, ← sub_add_sub_comm] exact add_mem hx hy theorem KaehlerDifferential.span_range_eq_ideal : Ideal.span (Set.range fun s : S => (1 : S) ⊗ₜ[R] s - s ⊗ₜ[R] (1 : S)) = KaehlerDifferential.ideal R S := by apply le_antisymm · rw [Ideal.span_le] rintro _ ⟨s, rfl⟩ exact KaehlerDifferential.one_smul_sub_smul_one_mem_ideal _ _ · change (KaehlerDifferential.ideal R S).restrictScalars S ≤ (Ideal.span _).restrictScalars S rw [← KaehlerDifferential.submodule_span_range_eq_ideal, Ideal.span] conv_rhs => rw [← Submodule.span_span_of_tower S] exact Submodule.subset_span /-- The module of Kähler differentials (Kahler differentials, Kaehler differentials). This is implemented as `I / I ^ 2` with `I` the kernel of the multiplication map `S ⊗[R] S →ₐ[R] S`. To view elements as a linear combination of the form `s • D s'`, use `KaehlerDifferential.tensorProductTo_surjective` and `Derivation.tensorProductTo_tmul`. We also provide the notation `Ω[S⁄R]` for `KaehlerDifferential R S`. Note that the slash is `\textfractionsolidus`. -/ def KaehlerDifferential : Type v := (KaehlerDifferential.ideal R S).Cotangent instance : AddCommGroup (KaehlerDifferential R S) := inferInstanceAs <| AddCommGroup (KaehlerDifferential.ideal R S).Cotangent instance KaehlerDifferential.module : Module (S ⊗[R] S) (KaehlerDifferential R S) := Ideal.Cotangent.moduleOfTower _ @[inherit_doc KaehlerDifferential] notation:100 "Ω[" S "⁄" R "]" => KaehlerDifferential R S instance : Nonempty (Ω[S⁄R]) := ⟨0⟩ instance KaehlerDifferential.module' {R' : Type*} [CommRing R'] [Algebra R' S] [SMulCommClass R R' S] : Module R' (Ω[S⁄R]) := Submodule.Quotient.module' _ instance : IsScalarTower S (S ⊗[R] S) (Ω[S⁄R]) := Ideal.Cotangent.isScalarTower _ instance KaehlerDifferential.isScalarTower_of_tower {R₁ R₂ : Type*} [CommRing R₁] [CommRing R₂] [Algebra R₁ S] [Algebra R₂ S] [SMul R₁ R₂] [SMulCommClass R R₁ S] [SMulCommClass R R₂ S] [IsScalarTower R₁ R₂ S] : IsScalarTower R₁ R₂ (Ω[S⁄R]) := Submodule.Quotient.isScalarTower _ _ instance KaehlerDifferential.isScalarTower' : IsScalarTower R (S ⊗[R] S) (Ω[S⁄R]) := Submodule.Quotient.isScalarTower _ _ /-- The quotient map `I → Ω[S⁄R]` with `I` being the kernel of `S ⊗[R] S → S`. -/ def KaehlerDifferential.fromIdeal : KaehlerDifferential.ideal R S →ₗ[S ⊗[R] S] Ω[S⁄R] := (KaehlerDifferential.ideal R S).toCotangent /-- (Implementation) The underlying linear map of the derivation into `Ω[S⁄R]`. -/ def KaehlerDifferential.DLinearMap : S →ₗ[R] Ω[S⁄R] := ((KaehlerDifferential.fromIdeal R S).restrictScalars R).comp ((TensorProduct.includeRight.toLinearMap - TensorProduct.includeLeft.toLinearMap : S →ₗ[R] S ⊗[R] S).codRestrict ((KaehlerDifferential.ideal R S).restrictScalars R) (KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R) : _ →ₗ[R] _) theorem KaehlerDifferential.DLinearMap_apply (s : S) : KaehlerDifferential.DLinearMap R S s = (KaehlerDifferential.ideal R S).toCotangent ⟨1 ⊗ₜ s - s ⊗ₜ 1, KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R s⟩ := rfl /-- The universal derivation into `Ω[S⁄R]`. -/ def KaehlerDifferential.D : Derivation R S (Ω[S⁄R]) := { toLinearMap := KaehlerDifferential.DLinearMap R S map_one_eq_zero' := by dsimp [KaehlerDifferential.DLinearMap_apply, Ideal.toCotangent_apply] congr rw [sub_self] leibniz' := fun a b => by have : LinearMap.CompatibleSMul { x // x ∈ ideal R S } (Ω[S⁄R]) S (S ⊗[R] S) := inferInstance dsimp [KaehlerDifferential.DLinearMap_apply] -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [← LinearMap.map_smul_of_tower (M₂ := Ω[S⁄R]), ← LinearMap.map_smul_of_tower (M₂ := Ω[S⁄R]), ← map_add, Ideal.toCotangent_eq, pow_two] convert Submodule.mul_mem_mul (KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R a : _) (KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R b : _) using 1 simp only [AddSubgroupClass.coe_sub, Submodule.coe_add, Submodule.coe_mk, TensorProduct.tmul_mul_tmul, mul_sub, sub_mul, mul_comm b, Submodule.coe_smul_of_tower, smul_sub, TensorProduct.smul_tmul', smul_eq_mul, mul_one] ring_nf } theorem KaehlerDifferential.D_apply (s : S) : KaehlerDifferential.D R S s = (KaehlerDifferential.ideal R S).toCotangent ⟨1 ⊗ₜ s - s ⊗ₜ 1, KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R s⟩ := rfl theorem KaehlerDifferential.span_range_derivation : Submodule.span S (Set.range <| KaehlerDifferential.D R S) = ⊤ := by rw [_root_.eq_top_iff] rintro x - obtain ⟨⟨x, hx⟩, rfl⟩ := Ideal.toCotangent_surjective _ x have : x ∈ (KaehlerDifferential.ideal R S).restrictScalars S := hx rw [← KaehlerDifferential.submodule_span_range_eq_ideal] at this suffices ∃ hx, (KaehlerDifferential.ideal R S).toCotangent ⟨x, hx⟩ ∈ Submodule.span S (Set.range <| KaehlerDifferential.D R S) by exact this.choose_spec refine Submodule.span_induction this ?_ ?_ ?_ ?_ · rintro _ ⟨x, rfl⟩ refine ⟨KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R x, ?_⟩ apply Submodule.subset_span exact ⟨x, KaehlerDifferential.DLinearMap_apply R S x⟩ · exact ⟨zero_mem _, Submodule.zero_mem _⟩ · rintro x y ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩; exact ⟨add_mem hx₁ hy₁, Submodule.add_mem _ hx₂ hy₂⟩ · rintro r x ⟨hx₁, hx₂⟩ exact ⟨((KaehlerDifferential.ideal R S).restrictScalars S).smul_mem r hx₁, Submodule.smul_mem _ r hx₂⟩ /-- `Ω[S⁄R]` is trivial if `R → S` is surjective. Also see `Algebra.FormallyUnramified.iff_subsingleton_kaehlerDifferential`. -/ lemma KaehlerDifferential.subsingleton_of_surjective (h : Function.Surjective (algebraMap R S)) : Subsingleton (Ω[S⁄R]) := by suffices (⊤ : Submodule S (Ω[S⁄R])) ≤ ⊥ from (subsingleton_iff_forall_eq 0).mpr fun y ↦ this trivial rw [← KaehlerDifferential.span_range_derivation, Submodule.span_le] rintro _ ⟨x, rfl⟩; obtain ⟨x, rfl⟩ := h x; simp variable {R S} /-- The linear map from `Ω[S⁄R]`, associated with a derivation. -/ def Derivation.liftKaehlerDifferential (D : Derivation R S M) : Ω[S⁄R] →ₗ[S] M := by refine LinearMap.comp ((((KaehlerDifferential.ideal R S) • (⊤ : Submodule (S ⊗[R] S) (KaehlerDifferential.ideal R S))).restrictScalars S).liftQ ?_ ?_) (Submodule.Quotient.restrictScalarsEquiv S _).symm.toLinearMap · exact D.tensorProductTo.comp ((KaehlerDifferential.ideal R S).subtype.restrictScalars S) · intro x hx rw [LinearMap.mem_ker] refine Submodule.smul_induction_on hx ?_ ?_ · rintro x hx y - rw [RingHom.mem_ker] at hx dsimp rw [Derivation.tensorProductTo_mul, hx, y.prop, zero_smul, zero_smul, zero_add] · intro x y ex ey; rw [map_add, ex, ey, zero_add] theorem Derivation.liftKaehlerDifferential_apply (D : Derivation R S M) (x) : D.liftKaehlerDifferential ((KaehlerDifferential.ideal R S).toCotangent x) = D.tensorProductTo x := rfl theorem Derivation.liftKaehlerDifferential_comp (D : Derivation R S M) : D.liftKaehlerDifferential.compDer (KaehlerDifferential.D R S) = D := by ext a dsimp [KaehlerDifferential.D_apply] refine (D.liftKaehlerDifferential_apply _).trans ?_ rw [Subtype.coe_mk, map_sub, Derivation.tensorProductTo_tmul, Derivation.tensorProductTo_tmul, one_smul, D.map_one_eq_zero, smul_zero, sub_zero] @[simp] theorem Derivation.liftKaehlerDifferential_comp_D (D' : Derivation R S M) (x : S) : D'.liftKaehlerDifferential (KaehlerDifferential.D R S x) = D' x := Derivation.congr_fun D'.liftKaehlerDifferential_comp x @[ext] theorem Derivation.liftKaehlerDifferential_unique (f f' : Ω[S⁄R] →ₗ[S] M) (hf : f.compDer (KaehlerDifferential.D R S) = f'.compDer (KaehlerDifferential.D R S)) : f = f' := by apply LinearMap.ext intro x have : x ∈ Submodule.span S (Set.range <| KaehlerDifferential.D R S) := by rw [KaehlerDifferential.span_range_derivation]; trivial refine Submodule.span_induction this ?_ ?_ ?_ ?_ · rintro _ ⟨x, rfl⟩; exact congr_arg (fun D : Derivation R S M => D x) hf · rw [map_zero, map_zero] · intro x y hx hy; rw [map_add, map_add, hx, hy] · intro a x e; simp [e] variable (R S) theorem Derivation.liftKaehlerDifferential_D : (KaehlerDifferential.D R S).liftKaehlerDifferential = LinearMap.id := Derivation.liftKaehlerDifferential_unique _ _ (KaehlerDifferential.D R S).liftKaehlerDifferential_comp variable {R S} theorem KaehlerDifferential.D_tensorProductTo (x : KaehlerDifferential.ideal R S) : (KaehlerDifferential.D R S).tensorProductTo x = (KaehlerDifferential.ideal R S).toCotangent x := by rw [← Derivation.liftKaehlerDifferential_apply, Derivation.liftKaehlerDifferential_D] rfl variable (R S) theorem KaehlerDifferential.tensorProductTo_surjective : Function.Surjective (KaehlerDifferential.D R S).tensorProductTo := by intro x; obtain ⟨x, rfl⟩ := (KaehlerDifferential.ideal R S).toCotangent_surjective x exact ⟨x, KaehlerDifferential.D_tensorProductTo x⟩ /-- The `S`-linear maps from `Ω[S⁄R]` to `M` are (`S`-linearly) equivalent to `R`-derivations from `S` to `M`. -/ @[simps! symm_apply apply_apply] def KaehlerDifferential.linearMapEquivDerivation : (Ω[S⁄R] →ₗ[S] M) ≃ₗ[S] Derivation R S M := { Derivation.llcomp.flip <| KaehlerDifferential.D R S with invFun := Derivation.liftKaehlerDifferential left_inv := fun _ => Derivation.liftKaehlerDifferential_unique _ _ (Derivation.liftKaehlerDifferential_comp _) right_inv := Derivation.liftKaehlerDifferential_comp } /-- The quotient ring of `S ⊗ S ⧸ J ^ 2` by `Ω[S⁄R]` is isomorphic to `S`. -/ def KaehlerDifferential.quotientCotangentIdealRingEquiv : (S ⊗ S ⧸ KaehlerDifferential.ideal R S ^ 2) ⧸ (KaehlerDifferential.ideal R S).cotangentIdeal ≃+* S := by have : Function.RightInverse (TensorProduct.includeLeft (R := R) (S := R) (A := S) (B := S)) (↑(TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S) : S ⊗[R] S →+* S) := by intro x; rw [AlgHom.coe_toRingHom, ← AlgHom.comp_apply, TensorProduct.lmul'_comp_includeLeft] rfl refine (Ideal.quotCotangent _).trans ?_ refine (Ideal.quotEquivOfEq ?_).trans (RingHom.quotientKerEquivOfRightInverse this) ext; rfl /-- The quotient ring of `S ⊗ S ⧸ J ^ 2` by `Ω[S⁄R]` is isomorphic to `S` as an `S`-algebra. -/ def KaehlerDifferential.quotientCotangentIdeal : ((S ⊗ S ⧸ KaehlerDifferential.ideal R S ^ 2) ⧸ (KaehlerDifferential.ideal R S).cotangentIdeal) ≃ₐ[S] S := { KaehlerDifferential.quotientCotangentIdealRingEquiv R S with commutes' := (KaehlerDifferential.quotientCotangentIdealRingEquiv R S).apply_symm_apply } theorem KaehlerDifferential.End_equiv_aux (f : S →ₐ[R] S ⊗ S ⧸ KaehlerDifferential.ideal R S ^ 2) : (Ideal.Quotient.mkₐ R (KaehlerDifferential.ideal R S).cotangentIdeal).comp f = IsScalarTower.toAlgHom R S _ ↔ (TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S).kerSquareLift.comp f = AlgHom.id R S := by rw [AlgHom.ext_iff, AlgHom.ext_iff] apply forall_congr' intro x have e₁ : (TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S).kerSquareLift (f x) = KaehlerDifferential.quotientCotangentIdealRingEquiv R S (Ideal.Quotient.mk (KaehlerDifferential.ideal R S).cotangentIdeal <| f x) := by generalize f x = y; obtain ⟨y, rfl⟩ := Ideal.Quotient.mk_surjective y; rfl have e₂ : x = KaehlerDifferential.quotientCotangentIdealRingEquiv R S (IsScalarTower.toAlgHom R S _ x) := (mul_one x).symm constructor · intro e exact (e₁.trans (@RingEquiv.congr_arg _ _ _ _ _ _ (KaehlerDifferential.quotientCotangentIdealRingEquiv R S) _ _ e)).trans e₂.symm · intro e; apply (KaehlerDifferential.quotientCotangentIdealRingEquiv R S).injective exact e₁.symm.trans (e.trans e₂) /- Note: Lean is slow to synthesize theses instances (times out). Without them the endEquivDerivation' and endEquivAuxEquiv both have significant timeouts. In Mathlib 3, it was slow but not this slow. -/ /-- A shortcut instance to prevent timing out. Hopefully to be removed in the future. -/ local instance smul_SSmod_SSmod : SMul (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) := Mul.toSMul _ /-- A shortcut instance to prevent timing out. Hopefully to be removed in the future. -/ @[nolint defLemma] local instance isScalarTower_S_right : IsScalarTower S (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) := Ideal.Quotient.isScalarTower_right /-- A shortcut instance to prevent timing out. Hopefully to be removed in the future. -/ @[nolint defLemma] local instance isScalarTower_R_right : IsScalarTower R (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) := Ideal.Quotient.isScalarTower_right /-- A shortcut instance to prevent timing out. Hopefully to be removed in the future. -/ @[nolint defLemma] local instance isScalarTower_SS_right : IsScalarTower (S ⊗[R] S) (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) := Ideal.Quotient.isScalarTower_right /-- A shortcut instance to prevent timing out. Hopefully to be removed in the future. -/ local instance instS : Module S (KaehlerDifferential.ideal R S).cotangentIdeal := Submodule.module' _ /-- A shortcut instance to prevent timing out. Hopefully to be removed in the future. -/ local instance instR : Module R (KaehlerDifferential.ideal R S).cotangentIdeal := Submodule.module' _ /-- A shortcut instance to prevent timing out. Hopefully to be removed in the future. -/ local instance instSS : Module (S ⊗[R] S) (KaehlerDifferential.ideal R S).cotangentIdeal := Submodule.module' _ /-- Derivations into `Ω[S⁄R]` is equivalent to derivations into `(KaehlerDifferential.ideal R S).cotangentIdeal`. -/ noncomputable def KaehlerDifferential.endEquivDerivation' : Derivation R S (Ω[S⁄R]) ≃ₗ[R] Derivation R S (ideal R S).cotangentIdeal := LinearEquiv.compDer ((KaehlerDifferential.ideal R S).cotangentEquivIdeal.restrictScalars S) /-- (Implementation) An `Equiv` version of `KaehlerDifferential.End_equiv_aux`. Used in `KaehlerDifferential.endEquiv`. -/ def KaehlerDifferential.endEquivAuxEquiv : { f // (Ideal.Quotient.mkₐ R (KaehlerDifferential.ideal R S).cotangentIdeal).comp f = IsScalarTower.toAlgHom R S _ } ≃ { f // (TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S).kerSquareLift.comp f = AlgHom.id R S } := (Equiv.refl _).subtypeEquiv (KaehlerDifferential.End_equiv_aux R S) /-- The endomorphisms of `Ω[S⁄R]` corresponds to sections of the surjection `S ⊗[R] S ⧸ J ^ 2 →ₐ[R] S`, with `J` being the kernel of the multiplication map `S ⊗[R] S →ₐ[R] S`. -/ noncomputable def KaehlerDifferential.endEquiv : Module.End S (Ω[S⁄R]) ≃ { f // (TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S).kerSquareLift.comp f = AlgHom.id R S } := (KaehlerDifferential.linearMapEquivDerivation R S).toEquiv.trans <| (KaehlerDifferential.endEquivDerivation' R S).toEquiv.trans <| (derivationToSquareZeroEquivLift (KaehlerDifferential.ideal R S).cotangentIdeal (KaehlerDifferential.ideal R S).cotangentIdeal_square).trans <| KaehlerDifferential.endEquivAuxEquiv R S section Finiteness theorem KaehlerDifferential.ideal_fg [EssFiniteType R S] : (KaehlerDifferential.ideal R S).FG := by classical use (EssFiniteType.finset R S).image (fun s ↦ (1 : S) ⊗ₜ[R] s - s ⊗ₜ[R] (1 : S)) apply le_antisymm · rw [Finset.coe_image, Ideal.span_le] rintro _ ⟨x, _, rfl⟩ exact KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R x · rw [← KaehlerDifferential.span_range_eq_ideal, Ideal.span_le] rintro _ ⟨x, rfl⟩ let I : Ideal (S ⊗[R] S) := Ideal.span ((EssFiniteType.finset R S).image (fun s ↦ (1 : S) ⊗ₜ[R] s - s ⊗ₜ[R] (1 : S))) show _ - _ ∈ I have : (IsScalarTower.toAlgHom R (S ⊗[R] S) (S ⊗[R] S ⧸ I)).comp TensorProduct.includeRight = (IsScalarTower.toAlgHom R (S ⊗[R] S) (S ⊗[R] S ⧸ I)).comp TensorProduct.includeLeft := by apply EssFiniteType.algHom_ext intro a ha simp only [AlgHom.coe_comp, IsScalarTower.coe_toAlgHom', Ideal.Quotient.algebraMap_eq, Function.comp_apply, TensorProduct.includeLeft_apply, TensorProduct.includeRight_apply, Ideal.Quotient.mk_eq_mk_iff_sub_mem] refine Ideal.subset_span ?_ simp only [Finset.coe_image, Set.mem_image, Finset.mem_coe] exact ⟨a, ha, rfl⟩ simpa [Ideal.Quotient.mk_eq_mk_iff_sub_mem] using AlgHom.congr_fun this x instance KaehlerDifferential.finite [EssFiniteType R S] : Module.Finite S (Ω[S⁄R]) := by classical let s := (EssFiniteType.finset R S).image (fun s ↦ D R S s) refine ⟨⟨s, top_le_iff.mp ?_⟩⟩ rw [← span_range_derivation, Submodule.span_le] rintro _ ⟨x, rfl⟩ have : ∀ x ∈ adjoin R (EssFiniteType.finset R S).toSet, .D _ _ x ∈ Submodule.span S s.toSet := by intro x hx refine adjoin_induction hx ?_ ?_ ?_ ?_ · exact fun x hx ↦ Submodule.subset_span (Finset.mem_image_of_mem _ hx) · simp · exact fun x y hx hy ↦ (D R S).map_add x y ▸ add_mem hx hy · intro x y hx hy simp only [Derivation.leibniz] exact add_mem (Submodule.smul_mem _ _ hy) (Submodule.smul_mem _ _ hx) obtain ⟨t, ht, ht', hxt⟩ := (essFiniteType_cond_iff R S (EssFiniteType.finset R S)).mp EssFiniteType.cond.choose_spec x rw [show D R S x = ht'.unit⁻¹ • (D R S (x * t) - x • D R S t) by simp [smul_smul, Units.smul_def]] exact Submodule.smul_mem _ _ (sub_mem (this _ hxt) (Submodule.smul_mem _ _ (this _ ht))) end Finiteness section Presentation open KaehlerDifferential (D) open Finsupp (single) /-- The `S`-submodule of `S →₀ S` (the direct sum of copies of `S` indexed by `S`) generated by the relations: 1. `dx + dy = d(x + y)` 2. `x dy + y dx = d(x * y)` 3. `dr = 0` for `r ∈ R` where `db` is the unit in the copy of `S` with index `b`. This is the kernel of the surjection `Finsupp.total S Ω[S⁄R] S (KaehlerDifferential.D R S)`. See `KaehlerDifferential.kerTotal_eq` and `KaehlerDifferential.total_surjective`. -/ noncomputable def KaehlerDifferential.kerTotal : Submodule S (S →₀ S) := Submodule.span S (((Set.range fun x : S × S => single x.1 1 + single x.2 1 - single (x.1 + x.2) 1) ∪ Set.range fun x : S × S => single x.2 x.1 + single x.1 x.2 - single (x.1 * x.2) 1) ∪ Set.range fun x : R => single (algebraMap R S x) 1) unsuppress_compilation in -- Porting note: was `local notation x "𝖣" y => (KaehlerDifferential.kerTotal R S).mkQ (single y x)` -- but not having `DFunLike.coe` leads to `kerTotal_mkQ_single_smul` failing. local notation3 x "𝖣" y => DFunLike.coe (KaehlerDifferential.kerTotal R S).mkQ (single y x) theorem KaehlerDifferential.kerTotal_mkQ_single_add (x y z) : (z𝖣x + y) = (z𝖣x) + z𝖣y := by rw [← map_add, eq_comm, ← sub_eq_zero, ← map_sub (Submodule.mkQ (kerTotal R S)), Submodule.mkQ_apply, Submodule.Quotient.mk_eq_zero] simp_rw [← Finsupp.smul_single_one _ z, ← smul_add, ← smul_sub] exact Submodule.smul_mem _ _ (Submodule.subset_span (Or.inl <| Or.inl <| ⟨⟨_, _⟩, rfl⟩)) theorem KaehlerDifferential.kerTotal_mkQ_single_mul (x y z) : (z𝖣x * y) = ((z * x)𝖣y) + (z * y)𝖣x := by rw [← map_add, eq_comm, ← sub_eq_zero, ← map_sub (Submodule.mkQ (kerTotal R S)), Submodule.mkQ_apply, Submodule.Quotient.mk_eq_zero] simp_rw [← Finsupp.smul_single_one _ z, ← @smul_eq_mul _ _ z, ← Finsupp.smul_single, ← smul_add, ← smul_sub] exact Submodule.smul_mem _ _ (Submodule.subset_span (Or.inl <| Or.inr <| ⟨⟨_, _⟩, rfl⟩)) theorem KaehlerDifferential.kerTotal_mkQ_single_algebraMap (x y) : (y𝖣algebraMap R S x) = 0 := by rw [Submodule.mkQ_apply, Submodule.Quotient.mk_eq_zero, ← Finsupp.smul_single_one _ y] exact Submodule.smul_mem _ _ (Submodule.subset_span (Or.inr <| ⟨_, rfl⟩)) theorem KaehlerDifferential.kerTotal_mkQ_single_algebraMap_one (x) : (x𝖣1) = 0 := by rw [← (algebraMap R S).map_one, KaehlerDifferential.kerTotal_mkQ_single_algebraMap] theorem KaehlerDifferential.kerTotal_mkQ_single_smul (r : R) (x y) : (y𝖣r • x) = r • y𝖣x := by letI : SMulZeroClass R S := inferInstance rw [Algebra.smul_def, KaehlerDifferential.kerTotal_mkQ_single_mul, KaehlerDifferential.kerTotal_mkQ_single_algebraMap, add_zero, ← LinearMap.map_smul_of_tower, Finsupp.smul_single, mul_comm, Algebra.smul_def] /-- The (universal) derivation into `(S →₀ S) ⧸ KaehlerDifferential.kerTotal R S`. -/ noncomputable def KaehlerDifferential.derivationQuotKerTotal : Derivation R S ((S →₀ S) ⧸ KaehlerDifferential.kerTotal R S) where toFun x := 1𝖣x map_add' x y := KaehlerDifferential.kerTotal_mkQ_single_add _ _ _ _ _ map_smul' r s := KaehlerDifferential.kerTotal_mkQ_single_smul _ _ _ _ _ map_one_eq_zero' := KaehlerDifferential.kerTotal_mkQ_single_algebraMap_one _ _ _ leibniz' a b := (KaehlerDifferential.kerTotal_mkQ_single_mul _ _ _ _ _).trans (by simp_rw [← Finsupp.smul_single_one _ (1 * _ : S)]; dsimp; simp) theorem KaehlerDifferential.derivationQuotKerTotal_apply (x) : KaehlerDifferential.derivationQuotKerTotal R S x = 1𝖣x := rfl theorem KaehlerDifferential.derivationQuotKerTotal_lift_comp_total : (KaehlerDifferential.derivationQuotKerTotal R S).liftKaehlerDifferential.comp (Finsupp.total S (Ω[S⁄R]) S (KaehlerDifferential.D R S)) = Submodule.mkQ _ := by apply Finsupp.lhom_ext intro a b conv_rhs => rw [← Finsupp.smul_single_one a b, LinearMap.map_smul] simp [KaehlerDifferential.derivationQuotKerTotal_apply] theorem KaehlerDifferential.kerTotal_eq : LinearMap.ker (Finsupp.total S (Ω[S⁄R]) S (KaehlerDifferential.D R S)) = KaehlerDifferential.kerTotal R S := by apply le_antisymm · conv_rhs => rw [← (KaehlerDifferential.kerTotal R S).ker_mkQ] rw [← KaehlerDifferential.derivationQuotKerTotal_lift_comp_total] exact LinearMap.ker_le_ker_comp _ _ · rw [KaehlerDifferential.kerTotal, Submodule.span_le] rintro _ ((⟨⟨x, y⟩, rfl⟩ | ⟨⟨x, y⟩, rfl⟩) | ⟨x, rfl⟩) <;> dsimp <;> simp [LinearMap.mem_ker] theorem KaehlerDifferential.total_surjective : Function.Surjective (Finsupp.total S (Ω[S⁄R]) S (KaehlerDifferential.D R S)) := by rw [← LinearMap.range_eq_top, Finsupp.range_total, KaehlerDifferential.span_range_derivation] /-- `Ω[S⁄R]` is isomorphic to `S` copies of `S` with kernel `KaehlerDifferential.kerTotal`. -/ @[simps!] noncomputable def KaehlerDifferential.quotKerTotalEquiv : ((S →₀ S) ⧸ KaehlerDifferential.kerTotal R S) ≃ₗ[S] Ω[S⁄R] := { (KaehlerDifferential.kerTotal R S).liftQ (Finsupp.total S (Ω[S⁄R]) S (KaehlerDifferential.D R S)) (KaehlerDifferential.kerTotal_eq R S).ge with invFun := (KaehlerDifferential.derivationQuotKerTotal R S).liftKaehlerDifferential left_inv := by intro x obtain ⟨x, rfl⟩ := Submodule.mkQ_surjective _ x exact LinearMap.congr_fun (KaehlerDifferential.derivationQuotKerTotal_lift_comp_total R S : _) x right_inv := by intro x obtain ⟨x, rfl⟩ := KaehlerDifferential.total_surjective R S x have := LinearMap.congr_fun (KaehlerDifferential.derivationQuotKerTotal_lift_comp_total R S) x rw [LinearMap.comp_apply] at this rw [this] rfl } theorem KaehlerDifferential.quotKerTotalEquiv_symm_comp_D : (KaehlerDifferential.quotKerTotalEquiv R S).symm.toLinearMap.compDer (KaehlerDifferential.D R S) = KaehlerDifferential.derivationQuotKerTotal R S := by convert (KaehlerDifferential.derivationQuotKerTotal R S).liftKaehlerDifferential_comp end Presentation section ExactSequence /- We have the commutative diagram ``` A --→ B ↑ ↑ | | R --→ S ``` -/ variable (A B : Type*) [CommRing A] [CommRing B] [Algebra R A] variable [Algebra A B] [Algebra S B] unsuppress_compilation in -- The map `(A →₀ A) →ₗ[A] (B →₀ B)` local macro "finsupp_map" : term => `((Finsupp.mapRange.linearMap (Algebra.linearMap A B)).comp (Finsupp.lmapDomain A A (algebraMap A B))) /-- Given the commutative diagram ``` A --→ B ↑ ↑ | | R --→ S ``` The kernel of the presentation `⊕ₓ B dx ↠ Ω_{B/S}` is spanned by the image of the kernel of `⊕ₓ A dx ↠ Ω_{A/R}` and all `ds` with `s : S`. See `kerTotal_map'` for the special case where `R = S`. -/ theorem KaehlerDifferential.kerTotal_map [Algebra R B] [IsScalarTower R A B] [IsScalarTower R S B] (h : Function.Surjective (algebraMap A B)) : (KaehlerDifferential.kerTotal R A).map finsupp_map ⊔ Submodule.span A (Set.range fun x : S => .single (algebraMap S B x) (1 : B)) = (KaehlerDifferential.kerTotal S B).restrictScalars _ := by rw [KaehlerDifferential.kerTotal, Submodule.map_span, KaehlerDifferential.kerTotal, Submodule.restrictScalars_span _ _ h] simp_rw [Set.image_union, Submodule.span_union, ← Set.image_univ, Set.image_image, Set.image_univ, map_sub, map_add] simp only [LinearMap.comp_apply, Finsupp.lmapDomain_apply, Finsupp.mapDomain_single, Finsupp.mapRange.linearMap_apply, Finsupp.mapRange_single, Algebra.linearMap_apply, map_one, map_add, map_mul] simp_rw [sup_assoc, ← (h.prodMap h).range_comp] congr! -- Porting note: new simp_rw [← IsScalarTower.algebraMap_apply R A B] rw [sup_eq_right] apply Submodule.span_mono simp_rw [IsScalarTower.algebraMap_apply R S B] exact Set.range_comp_subset_range (algebraMap R S) fun x => Finsupp.single (algebraMap S B x) (1 : B) /-- This is a special case of `kerTotal_map` where `R = S`. The kernel of the presentation `⊕ₓ B dx ↠ Ω_{B/R}` is spanned by the image of the kernel of `⊕ₓ A dx ↠ Ω_{A/R}` and all `da` with `a : A`. -/ theorem KaehlerDifferential.kerTotal_map' [Algebra R B] [IsScalarTower R A B] (h : Function.Surjective (algebraMap A B)) : (KaehlerDifferential.kerTotal R A ⊔ Submodule.span A (Set.range fun x ↦ .single (algebraMap R A x) 1)).map finsupp_map = (KaehlerDifferential.kerTotal R B).restrictScalars _ := by rw [Submodule.map_sup, ← kerTotal_map R R A B h, Submodule.map_span, ← Set.range_comp] congr refine congr_arg Set.range ?_ ext; simp [IsScalarTower.algebraMap_eq R A B] variable [Algebra R B] [IsScalarTower R A B] [IsScalarTower R S B] [SMulCommClass S A B] /-- The map `Ω[A⁄R] →ₗ[A] Ω[B⁄S]` given a square ``` A --→ B ↑ ↑ | | R --→ S ``` -/ def KaehlerDifferential.map : Ω[A⁄R] →ₗ[A] Ω[B⁄S] := Derivation.liftKaehlerDifferential (((KaehlerDifferential.D S B).restrictScalars R).compAlgebraMap A) theorem KaehlerDifferential.map_compDer : (KaehlerDifferential.map R S A B).compDer (KaehlerDifferential.D R A) = ((KaehlerDifferential.D S B).restrictScalars R).compAlgebraMap A := Derivation.liftKaehlerDifferential_comp _ @[simp] theorem KaehlerDifferential.map_D (x : A) : KaehlerDifferential.map R S A B (KaehlerDifferential.D R A x) = KaehlerDifferential.D S B (algebraMap A B x) := Derivation.congr_fun (KaehlerDifferential.map_compDer R S A B) x theorem KaehlerDifferential.ker_map : LinearMap.ker (KaehlerDifferential.map R S A B) = (((kerTotal S B).restrictScalars A).comap finsupp_map).map (Finsupp.total A (Ω[A⁄R]) A (D R A)) := by rw [← Submodule.map_comap_eq_of_surjective (total_surjective R A) (LinearMap.ker _)] congr 1 ext x simp only [Submodule.mem_comap, LinearMap.mem_ker, Finsupp.apply_total, ← kerTotal_eq, Submodule.restrictScalars_mem] simp only [Finsupp.total_apply, Function.comp_apply, LinearMap.coe_comp, Finsupp.lmapDomain_apply, Finsupp.mapRange.linearMap_apply] rw [Finsupp.sum_mapRange_index, Finsupp.sum_mapDomain_index] · simp [ofId] · simp · simp [add_smul] · simp lemma KaehlerDifferential.ker_map_of_surjective (h : Function.Surjective (algebraMap A B)) : LinearMap.ker (map R R A B) = (LinearMap.ker finsupp_map).map (Finsupp.total A _ A (D R A)) := by rw [ker_map, ← kerTotal_map' R A B h, Submodule.comap_map_eq, Submodule.map_sup, Submodule.map_sup, ← kerTotal_eq, ← Submodule.comap_bot, Submodule.map_comap_eq_of_surjective (total_surjective _ _), bot_sup_eq, Submodule.map_span, ← Set.range_comp] convert bot_sup_eq _ rw [Submodule.span_eq_bot]; simp open IsScalarTower (toAlgHom) theorem KaehlerDifferential.map_surjective_of_surjective (h : Function.Surjective (algebraMap A B)) : Function.Surjective (KaehlerDifferential.map R S A B) := by rw [← LinearMap.range_eq_top, _root_.eq_top_iff, ← @Submodule.restrictScalars_top A B, ← KaehlerDifferential.span_range_derivation, Submodule.restrictScalars_span _ _ h, Submodule.span_le] rintro _ ⟨x, rfl⟩ obtain ⟨y, rfl⟩ := h x rw [← KaehlerDifferential.map_D R S A B] exact ⟨_, rfl⟩ theorem KaehlerDifferential.map_surjective : Function.Surjective (KaehlerDifferential.map R S B B) := map_surjective_of_surjective R S B B Function.surjective_id /-- The lift of the map `Ω[A⁄R] →ₗ[A] Ω[B⁄R]` to the base change along `A → B`. This is the first map in the exact sequence `B ⊗[A] Ω[A⁄R] → Ω[B⁄R] → Ω[B⁄A] → 0`. -/ noncomputable def KaehlerDifferential.mapBaseChange : B ⊗[A] Ω[A⁄R] →ₗ[B] Ω[B⁄R] := (TensorProduct.isBaseChange A (Ω[A⁄R]) B).lift (KaehlerDifferential.map R R A B) @[simp] theorem KaehlerDifferential.mapBaseChange_tmul (x : B) (y : Ω[A⁄R]) : KaehlerDifferential.mapBaseChange R A B (x ⊗ₜ y) = x • KaehlerDifferential.map R R A B y := by conv_lhs => rw [← mul_one x, ← smul_eq_mul, ← TensorProduct.smul_tmul', LinearMap.map_smul] congr 1 exact IsBaseChange.lift_eq _ _ _ lemma KaehlerDifferential.range_mapBaseChange : LinearMap.range (mapBaseChange R A B) = LinearMap.ker (map R A B B) := by apply le_antisymm · rintro _ ⟨x, rfl⟩ induction' x with r s · simp · obtain ⟨x, rfl⟩ := total_surjective _ _ s simp only [mapBaseChange_tmul, LinearMap.mem_ker, map_smul] induction x using Finsupp.induction_linear · simp · simp [smul_add, *] · simp · rw [map_add]; exact add_mem ‹_› ‹_› · convert_to (kerTotal A B).map (Finsupp.total B (Ω[B⁄R]) B (D R B)) ≤ _ · rw [KaehlerDifferential.ker_map] congr 1 convert Submodule.comap_id _ · ext; simp rw [Submodule.map_le_iff_le_comap, kerTotal, Submodule.span_le] rintro f ((⟨⟨x, y⟩, rfl⟩|⟨⟨x, y⟩, rfl⟩)|⟨x, rfl⟩) · use 0; simp · use 0; simp · use 1 ⊗ₜ D _ _ x; simp /-- The sequence `B ⊗[A] Ω[A⁄R] → Ω[B⁄R] → Ω[B⁄A] → 0` is exact. Also see `KaehlerDifferential.map_surjective`. -/ lemma KaehlerDifferential.exact_mapBaseChange_map : Function.Exact (mapBaseChange R A B) (map R A B B) := SetLike.ext_iff.mp (range_mapBaseChange R A B).symm /-- The map `I → B ⊗[A] B ⊗[A] Ω[A⁄R]` where `I = ker(A → B)`. -/ @[simps] noncomputable def KaehlerDifferential.kerToTensor : RingHom.ker (algebraMap A B) →ₗ[A] B ⊗[A] Ω[A⁄R] where toFun x := 1 ⊗ₜ D R A x map_add' x y := by simp only [AddSubmonoid.coe_add, Submodule.coe_toAddSubmonoid, map_add, TensorProduct.tmul_add] map_smul' r x := by simp only [SetLike.val_smul, Derivation.leibniz, RingHom.id_apply, TensorProduct.tmul_smul, TensorProduct.smul_tmul', add_zero, ← Algebra.algebraMap_eq_smul_one, TensorProduct.zero_tmul, smul_eq_mul, TensorProduct.tmul_add, (RingHom.mem_ker _).mp x.prop] /-- The map `I/I² → B ⊗[A] B ⊗[A] Ω[A⁄R]` where `I = ker(A → B)`. -/ noncomputable def KaehlerDifferential.kerCotangentToTensor : (RingHom.ker (algebraMap A B)).Cotangent →ₗ[A] B ⊗[A] Ω[A⁄R] := Submodule.liftQ _ (kerToTensor R A B) (iSup_le_iff.mpr (by simp only [Submodule.map_le_iff_le_comap, Subtype.forall] rintro x hx y - simp only [Submodule.mem_comap, LinearMap.lsmul_apply, LinearMap.mem_ker, map_smul, kerToTensor_apply, TensorProduct.smul_tmul', ← algebraMap_eq_smul_one, (RingHom.mem_ker _).mp hx, TensorProduct.zero_tmul])) @[simp] lemma KaehlerDifferential.kerCotangentToTensor_toCotangent (x) : kerCotangentToTensor R A B (Ideal.toCotangent _ x) = 1 ⊗ₜ D _ _ x.1 := rfl theorem KaehlerDifferential.range_kerCotangentToTensor (h : Function.Surjective (algebraMap A B)) : LinearMap.range (kerCotangentToTensor R A B) = (LinearMap.ker (KaehlerDifferential.mapBaseChange R A B)).restrictScalars A := by classical ext x constructor · rintro ⟨x, rfl⟩ obtain ⟨x, rfl⟩ := Ideal.toCotangent_surjective _ x simp [kerCotangentToTensor_toCotangent, (RingHom.mem_ker _).mp x.2] · intro hx obtain ⟨x, rfl⟩ := LinearMap.rTensor_surjective (Ω[A⁄R]) (g := Algebra.linearMap A B) h x obtain ⟨x, rfl⟩ := (TensorProduct.lid _ _).symm.surjective x replace hx : x ∈ LinearMap.ker (KaehlerDifferential.map R R A B) := by simpa using hx rw [KaehlerDifferential.ker_map_of_surjective R A B h] at hx obtain ⟨x, hx, rfl⟩ := hx simp only [TensorProduct.lid_symm_apply, LinearMap.rTensor_tmul, Algebra.linearMap_apply, _root_.map_one] rw [← Finsupp.sum_single x, Finsupp.sum, ← Finset.sum_fiberwise_of_maps_to (fun _ ↦ Finset.mem_image_of_mem (algebraMap A B))] simp only [Function.comp_apply, map_sum (s := x.support.image (algebraMap A B)), TensorProduct.tmul_sum] apply sum_mem intro c _ simp only [Finset.filter_congr_decidable, TensorProduct.lid_symm_apply, LinearMap.rTensor_tmul, AlgHom.toLinearMap_apply, _root_.map_one, LinearMap.mem_range] simp only [map_sum, Finsupp.total_single] have : (x.support.filter (algebraMap A B · = c)).sum x ∈ RingHom.ker (algebraMap A B) := by simpa [Finsupp.mapDomain, Finsupp.sum, Finsupp.finset_sum_apply, RingHom.mem_ker, Finsupp.single_apply, ← Finset.sum_filter] using DFunLike.congr_fun hx c obtain ⟨a, ha⟩ := h c use (x.support.filter (algebraMap A B · = c)).attach.sum fun i ↦ x i • Ideal.toCotangent _ ⟨i - a, ?_⟩; swap · have : x i ≠ 0 ∧ algebraMap A B i = c := by simpa using i.prop simp [RingHom.mem_ker, ha, this.2] · simp only [map_sum, LinearMapClass.map_smul, kerCotangentToTensor_toCotangent, map_sub] simp_rw [← TensorProduct.tmul_smul] simp only [smul_sub, TensorProduct.tmul_sub, Finset.sum_sub_distrib, ← TensorProduct.tmul_sum, ← Finset.sum_smul, Finset.sum_attach, sub_eq_self, Finset.sum_attach (f := fun i ↦ x i • KaehlerDifferential.D R A i)] rw [← TensorProduct.smul_tmul, ← Algebra.algebraMap_eq_smul_one, (RingHom.mem_ker _).mp this, TensorProduct.zero_tmul] theorem KaehlerDifferential.exact_kerCotangentToTensor_mapBaseChange (h : Function.Surjective (algebraMap A B)) : Function.Exact (kerCotangentToTensor R A B) (KaehlerDifferential.mapBaseChange R A B) := SetLike.ext_iff.mp (range_kerCotangentToTensor R A B h).symm lemma KaehlerDifferential.mapBaseChange_surjective (h : Function.Surjective (algebraMap A B)) : Function.Surjective (KaehlerDifferential.mapBaseChange R A B) := by have := subsingleton_of_surjective A B h rw [← LinearMap.range_eq_top, KaehlerDifferential.range_mapBaseChange, ← top_le_iff] exact fun x _ ↦ Subsingleton.elim _ _ end ExactSequence end KaehlerDifferential
RingTheory\Kaehler\CotangentComplex.lean
/- Copyright (c) 2024 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.RingTheory.Kaehler.Polynomial import Mathlib.RingTheory.Generators /-! # Naive cotangent complex associated to a presentation. Given a presentation `0 → I → R[x₁,...,xₙ] → S → 0` (or equivalently a closed embedding `S ↪ Aⁿ` defined by `I`), we may define the (naive) cotangent complex `I/I² → ⨁ᵢ S dxᵢ → Ω[S/R] → 0`. ## Main results - `Algebra.Generators.Cotangent`: The conormal space `I/I²`. (Defined in `Generators/Basic`) - `Algebra.Generators.CotangentSpace`: The cotangent space `⨁ᵢ S dxᵢ`. - `Algebra.Generators.CotangentComplex`: The map `I/I² → ⨁ᵢ S dxᵢ`. - `Algebra.Generators.toKaehler`: The projection `⨁ᵢ S dxᵢ → Ω[S/R]`. - `Algebra.Generators.toKaehler_surjective`: The map `⨁ᵢ S dxᵢ → Ω[S/R]` is surjective. - `Algebra.Generators.exact_cotangentComplex_toKaehler`: `I/I² → ⨁ᵢ S dxᵢ → Ω[S/R]` is exact. - `Algebra.Generators.Hom.Sub`: If `f` and `g` are two maps between presentations, `f - g` induces a map `⨁ᵢ S dxᵢ → I/I²` that makes `f` and `g` homotopic. -/ open KaehlerDifferential TensorProduct MvPolynomial namespace Algebra universe w u v variable {R : Type u} {S : Type v} [CommRing R] [CommRing S] [Algebra R S] namespace Generators variable (P : Generators.{w} R S) /-- The cotangent space on `P = R[X]`. This is isomorphic to `Sⁿ` with `n` being the number of variables of `P`. -/ abbrev CotangentSpace : Type _ := S ⊗[P.Ring] Ω[P.Ring⁄R] /-- The canonical basis on the `CotangentSpace`. -/ noncomputable def cotangentSpaceBasis : Basis P.vars S P.CotangentSpace := (mvPolynomialBasis _ _).baseChange _ @[simp] lemma cotangentSpaceBasis_repr_tmul (r x i) : P.cotangentSpaceBasis.repr (r ⊗ₜ .D _ _ x) i = r * aeval P.val (pderiv i x) := by classical simp only [cotangentSpaceBasis, Basis.baseChange_repr_tmul, mvPolynomialBasis_repr_apply, Algebra.smul_def, mul_comm r, algebraMap_apply] lemma cotangentSpaceBasis_repr_one_tmul (x i) : P.cotangentSpaceBasis.repr (1 ⊗ₜ .D _ _ x) i = aeval P.val (pderiv i x) := by rw [cotangentSpaceBasis_repr_tmul, one_mul] lemma cotangentSpaceBasis_apply i : P.cotangentSpaceBasis i = 1 ⊗ₜ .D _ _ (.X i) := by simp [cotangentSpaceBasis] /-- The cotangent complex given by a presentation `R[X] → S` (i.e. a closed embedding `S ↪ Aⁿ`). -/ noncomputable def cotangentComplex : P.Cotangent →ₗ[S] P.CotangentSpace := letI f : P.Cotangent ≃ₗ[P.Ring] P.ker.Cotangent := { __ := AddEquiv.refl _, map_smul' := Cotangent.val_smul' } (kerCotangentToTensor R P.Ring S ∘ₗ f).extendScalarsOfSurjective P.algebraMap_surjective @[simp] lemma cotangentComplex_mk (x) : P.cotangentComplex (.mk x) = 1 ⊗ₜ .D _ _ x := kerCotangentToTensor_toCotangent _ _ _ _ universe w' u' v' variable {R' : Type u'} {S' : Type v'} [CommRing R'] [CommRing S'] [Algebra R' S'] variable (P' : Generators.{w'} R' S') variable [Algebra R R'] [Algebra S S'] [Algebra R S'] [IsScalarTower R R' S'] [IsScalarTower R S S'] attribute [local instance] SMulCommClass.of_commMonoid variable {P P'} namespace CotangentSpace /-- This is the map on the cotangent space associated to a map of presentation. The matrix associated to this map is the Jacobian matrix. See `CotangentSpace.repr_map`. -/ protected noncomputable def map (f : Hom P P') : P.CotangentSpace →ₗ[S] P'.CotangentSpace := by letI := ((algebraMap S S').comp (algebraMap P.Ring S)).toAlgebra haveI : IsScalarTower P.Ring S S' := IsScalarTower.of_algebraMap_eq' rfl letI := f.toAlgHom.toAlgebra haveI : IsScalarTower P.Ring P'.Ring S' := IsScalarTower.of_algebraMap_eq (fun x ↦ (f.algebraMap_toAlgHom x).symm) apply LinearMap.liftBaseChange refine (TensorProduct.mk _ _ _ 1).restrictScalars _ ∘ₗ KaehlerDifferential.map R R' P.Ring P'.Ring @[simp] lemma map_tmul (f : Hom P P') (x y) : CotangentSpace.map f (x ⊗ₜ .D _ _ y) = (algebraMap _ _ x) ⊗ₜ .D _ _ (f.toAlgHom y) := by simp only [CotangentSpace.map, AlgHom.toRingHom_eq_coe, LinearMap.liftBaseChange_tmul, LinearMap.coe_comp, LinearMap.coe_restrictScalars, Function.comp_apply, map_D, mk_apply] rw [smul_tmul', ← Algebra.algebraMap_eq_smul_one] rfl @[simp] lemma repr_map (f : Hom P P') (i j) : P'.cotangentSpaceBasis.repr (CotangentSpace.map f (P.cotangentSpaceBasis i)) j = aeval P'.val (pderiv j (f.val i)) := by simp only [cotangentSpaceBasis_apply, map_tmul, _root_.map_one, Hom.toAlgHom_X, cotangentSpaceBasis_repr_one_tmul] universe w'' u'' v'' variable {R'' : Type u''} {S'' : Type v''} [CommRing R''] [CommRing S''] [Algebra R'' S''] variable {P'' : Generators.{w''} R'' S''} variable [Algebra R R''] [Algebra S S''] [Algebra R S''] [IsScalarTower R R'' S''] [IsScalarTower R S S''] variable [Algebra R' R''] [Algebra S' S''] [Algebra R' S''] [IsScalarTower R' R'' S''] [IsScalarTower R' S' S''] variable [IsScalarTower R R' R''] [IsScalarTower S S' S''] @[simp] lemma map_id : CotangentSpace.map (.id P) = LinearMap.id := by apply P.cotangentSpaceBasis.ext intro i simp only [cotangentSpaceBasis_apply, map_tmul, _root_.map_one, Hom.toAlgHom_X, Hom.id_val, LinearMap.id_coe, id_eq] lemma map_comp (f : Hom P P') (g : Hom P' P'') : CotangentSpace.map (g.comp f) = (CotangentSpace.map g).restrictScalars S ∘ₗ CotangentSpace.map f := by apply P.cotangentSpaceBasis.ext intro i simp only [cotangentSpaceBasis_apply, map_tmul, _root_.map_one, Hom.toAlgHom_X, Hom.comp_val, LinearMap.coe_comp, LinearMap.coe_restrictScalars, Function.comp_apply] rfl lemma map_comp_apply (f : Hom P P') (g : Hom P' P'') (x) : CotangentSpace.map (g.comp f) x = .map g (.map f x) := DFunLike.congr_fun (map_comp f g) x lemma map_cotangentComplex (f : Hom P P') (x) : CotangentSpace.map f (P.cotangentComplex x) = P'.cotangentComplex (.map f x) := by obtain ⟨x, rfl⟩ := Cotangent.mk_surjective x rw [cotangentComplex_mk, map_tmul, _root_.map_one, Cotangent.map_mk, cotangentComplex_mk] lemma map_comp_cotangentComplex (f : Hom P P') : CotangentSpace.map f ∘ₗ P.cotangentComplex = P'.cotangentComplex.restrictScalars S ∘ₗ Cotangent.map f := by ext x; exact map_cotangentComplex f x end CotangentSpace universe uT variable {T : Type uT} [CommRing T] [Algebra R T] [Algebra S T] [IsScalarTower R S T] lemma Hom.sub_aux (f g : Hom P P') (x y) : letI := ((algebraMap S S').comp (algebraMap P.Ring S)).toAlgebra f.toAlgHom (x * y) - g.toAlgHom (x * y) - (P'.σ ((algebraMap P.Ring S') x) * (f.toAlgHom y - g.toAlgHom y) + P'.σ ((algebraMap P.Ring S') y) * (f.toAlgHom x - g.toAlgHom x)) ∈ P'.ker ^ 2 := by letI := ((algebraMap S S').comp (algebraMap P.Ring S)).toAlgebra have : (f.toAlgHom x - P'.σ (algebraMap P.Ring S' x)) * (f.toAlgHom y - g.toAlgHom y) + (g.toAlgHom y - P'.σ (algebraMap P.Ring S' y)) * (f.toAlgHom x - g.toAlgHom x) ∈ P'.ker ^ 2 := by rw [pow_two] refine Ideal.add_mem _ (Ideal.mul_mem_mul ?_ ?_) (Ideal.mul_mem_mul ?_ ?_) <;> simp only [RingHom.algebraMap_toAlgebra, AlgHom.toRingHom_eq_coe, RingHom.coe_comp, RingHom.coe_coe, Function.comp_apply, map_aeval, ← IsScalarTower.algebraMap_eq, coe_eval₂Hom, ← aeval_def, ker, RingHom.mem_ker, map_sub, algebraMap_toAlgHom, aeval_val_σ, sub_self] convert this using 1 simp only [_root_.map_mul] ring /-- If `f` and `g` are two maps `P → P'` between presentations, then the image of `f - g` is in the kernel of `P' → S`. -/ @[simps! apply_coe] noncomputable def Hom.subToKer (f g : Hom P P') : P.Ring →ₗ[R] P'.ker := by refine ((f.toAlgHom.toLinearMap - g.toAlgHom.toLinearMap).codRestrict (P'.ker.restrictScalars R) ?_) intro x simp only [LinearMap.sub_apply, AlgHom.toLinearMap_apply, ker, algebraMap_eq, Submodule.restrictScalars_mem, RingHom.mem_ker, map_sub, RingHom.coe_coe, algebraMap_toAlgHom, map_aeval, coe_eval₂Hom, sub_self] /-- If `f` and `g` are two maps `P → P'` between presentations, their difference induces a map `P.CotangentSpace →ₗ[S] P'.Cotangent` that makes two maps between the cotangent complexes homotopic. -/ noncomputable def Hom.sub (f g : Hom P P') : P.CotangentSpace →ₗ[S] P'.Cotangent := by letI := ((algebraMap S S').comp (algebraMap P.Ring S)).toAlgebra haveI : IsScalarTower P.Ring S S' := IsScalarTower.of_algebraMap_eq' rfl letI := f.toAlgHom.toAlgebra haveI : IsScalarTower P.Ring P'.Ring S' := IsScalarTower.of_algebraMap_eq fun x ↦ (f.algebraMap_toAlgHom x).symm haveI : IsScalarTower R P.Ring S' := IsScalarTower.of_algebraMap_eq fun x ↦ show algebraMap R S' x = algebraMap S S' (algebraMap P.Ring S (algebraMap R P.Ring x)) by rw [← IsScalarTower.algebraMap_apply R P.Ring S, ← IsScalarTower.algebraMap_apply] refine (Derivation.liftKaehlerDifferential ?_).liftBaseChange S refine { __ := Cotangent.mk.restrictScalars R ∘ₗ f.subToKer g map_one_eq_zero' := ?_ leibniz' := ?_ } · ext simp only [LinearMap.coe_comp, LinearMap.coe_restrictScalars, Function.comp_apply, Cotangent.val_mk, Cotangent.val_zero, Ideal.toCotangent_eq_zero] erw [LinearMap.codRestrict_apply] simp only [LinearMap.sub_apply, AlgHom.toLinearMap_apply, _root_.map_one, sub_self, Submodule.zero_mem] · intro x y ext simp only [LinearMap.coe_comp, LinearMap.coe_restrictScalars, Function.comp_apply, Cotangent.val_mk, Cotangent.val_add, Cotangent.val_smul''', ← map_smul, ← map_add, Ideal.toCotangent_eq, AddSubmonoid.coe_add, Submodule.coe_toAddSubmonoid, SetLike.val_smul, smul_eq_mul] exact Hom.sub_aux f g x y lemma Hom.sub_one_tmul (f g : Hom P P') (x) : f.sub g (1 ⊗ₜ .D _ _ x) = Cotangent.mk (f.subToKer g x) := by simp only [sub, LinearMap.liftBaseChange_tmul, Derivation.liftKaehlerDifferential_comp_D, Derivation.mk_coe, LinearMap.coe_comp, LinearMap.coe_restrictScalars, Function.comp_apply, one_smul] @[simp] lemma Hom.sub_tmul (f g : Hom P P') (r x) : f.sub g (r ⊗ₜ .D _ _ x) = r • Cotangent.mk (f.subToKer g x) := by simp only [sub, LinearMap.liftBaseChange_tmul, Derivation.liftKaehlerDifferential_comp_D, Derivation.mk_coe, LinearMap.coe_comp, LinearMap.coe_restrictScalars, Function.comp_apply] lemma CotangentSpace.map_sub_map (f g : Hom P P') : CotangentSpace.map f - CotangentSpace.map g = P'.cotangentComplex.restrictScalars S ∘ₗ (f.sub g) := by apply P.cotangentSpaceBasis.ext intro i simp only [cotangentSpaceBasis_apply, LinearMap.sub_apply, map_tmul, _root_.map_one, Hom.toAlgHom_X, LinearMap.coe_comp, LinearMap.coe_restrictScalars, Function.comp_apply, Hom.sub_one_tmul, cotangentComplex_mk, Hom.subToKer_apply_coe, map_sub, tmul_sub] lemma Cotangent.map_sub_map (f g : Hom P P') : map f - map g = (f.sub g) ∘ₗ P.cotangentComplex := by ext x obtain ⟨x, rfl⟩ := mk_surjective x simp only [LinearMap.sub_apply, map_mk, LinearMap.coe_comp, Function.comp_apply, cotangentComplex_mk, Hom.sub_tmul, one_smul, val_mk] apply (Ideal.cotangentEquivIdeal _).injective ext simp only [val_sub, val_mk, map_sub, AddSubgroupClass.coe_sub, Ideal.cotangentEquivIdeal_apply, Ideal.toCotangent_to_quotient_square, Submodule.mkQ_apply, Ideal.Quotient.mk_eq_mk, Hom.subToKer_apply_coe] variable (P) in /-- The projection map from the relative cotangent space to the module of differentials. -/ noncomputable abbrev toKaehler : P.CotangentSpace →ₗ[S] Ω[S⁄R] := mapBaseChange _ _ _ @[simp] lemma toKaehler_cotangentSpaceBasis (i) : P.toKaehler (P.cotangentSpaceBasis i) = D R S (P.val i) := by simp [cotangentSpaceBasis_apply] lemma toKaehler_surjective : Function.Surjective P.toKaehler := mapBaseChange_surjective _ _ _ P.algebraMap_surjective lemma exact_cotangentComplex_toKaehler : Function.Exact P.cotangentComplex P.toKaehler := exact_kerCotangentToTensor_mapBaseChange _ _ _ P.algebraMap_surjective end Generators end Algebra
RingTheory\Kaehler\Polynomial.lean
/- Copyright (c) 2024 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.RingTheory.Kaehler.Basic import Mathlib.Algebra.MvPolynomial.PDeriv import Mathlib.Algebra.Polynomial.Derivation /-! # The Kaehler differential module of polynomial algebras -/ open scoped TensorProduct open Algebra universe u v variable (R : Type u) (S : Type v) [CommRing R] [CommRing S] [Algebra R S] suppress_compilation section MvPolynomial /-- The relative differential module of a polynomial algebra `R[σ]` is the free module generated by `{ dx | x ∈ σ }`. Also see `KaehlerDifferential.mvPolynomialBasis`. -/ def KaehlerDifferential.mvPolynomialEquiv (σ : Type*) : Ω[MvPolynomial σ R⁄R] ≃ₗ[MvPolynomial σ R] σ →₀ MvPolynomial σ R where __ := (MvPolynomial.mkDerivation _ (Finsupp.single · 1)).liftKaehlerDifferential invFun := Finsupp.total σ _ _ (fun x ↦ D _ _ (MvPolynomial.X x)) right_inv := by intro x induction' x using Finsupp.induction_linear with _ _ _ _ a b · simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom]; rw [map_zero, map_zero] · simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, map_add] at *; simp only [*] · simp [LinearMap.map_smul, -map_smul] left_inv := by intro x obtain ⟨x, rfl⟩ := total_surjective _ _ x induction' x using Finsupp.induction_linear with _ _ _ _ a b · simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom]; rw [map_zero, map_zero, map_zero] · simp only [map_add, AddHom.toFun_eq_coe, LinearMap.coe_toAddHom] at *; simp only [*] · simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, Finsupp.total_single, LinearMap.map_smul, Derivation.liftKaehlerDifferential_comp_D] congr 1 induction a using MvPolynomial.induction_on · simp only [MvPolynomial.derivation_C, map_zero] · simp only [map_add, *] · simp [*] /-- `{ dx | x ∈ σ }` forms a basis of the relative differential module of a polynomial algebra `R[σ]`. -/ def KaehlerDifferential.mvPolynomialBasis (σ) : Basis σ (MvPolynomial σ R) (Ω[MvPolynomial σ R⁄R]) := ⟨mvPolynomialEquiv R σ⟩ lemma KaehlerDifferential.mvPolynomialBasis_repr_comp_D (σ) : (mvPolynomialBasis R σ).repr.toLinearMap.compDer (D _ _) = MvPolynomial.mkDerivation _ (Finsupp.single · 1) := Derivation.liftKaehlerDifferential_comp _ lemma KaehlerDifferential.mvPolynomialBasis_repr_D (σ) (x) : (mvPolynomialBasis R σ).repr (D _ _ x) = MvPolynomial.mkDerivation R (Finsupp.single · (1 : MvPolynomial σ R)) x := Derivation.congr_fun (mvPolynomialBasis_repr_comp_D R σ) x @[simp] lemma KaehlerDifferential.mvPolynomialBasis_repr_D_X (σ) (i) : (mvPolynomialBasis R σ).repr (D _ _ (.X i)) = Finsupp.single i 1 := by simp [mvPolynomialBasis_repr_D] @[simp] lemma KaehlerDifferential.mvPolynomialBasis_repr_apply (σ) (x) (i) : (mvPolynomialBasis R σ).repr (D _ _ x) i = MvPolynomial.pderiv i x := by classical suffices ((Finsupp.lapply i).comp (mvPolynomialBasis R σ).repr.toLinearMap).compDer (D _ _) = MvPolynomial.pderiv i by rw [← this]; rfl apply MvPolynomial.derivation_ext intro j simp [Finsupp.single_apply, Pi.single_apply] lemma KaehlerDifferential.mvPolynomialBasis_repr_symm_single (σ) (i) (x) : (mvPolynomialBasis R σ).repr.symm (Finsupp.single i x) = x • D R (MvPolynomial σ R) (.X i) := by apply (mvPolynomialBasis R σ).repr.injective; simp [LinearEquiv.map_smul, -map_smul] @[simp] lemma KaehlerDifferential.mvPolynomialBasis_apply (σ) (i) : mvPolynomialBasis R σ i = D R (MvPolynomial σ R) (.X i) := (mvPolynomialBasis_repr_symm_single R σ i 1).trans (one_smul _ _) instance (σ) : Module.Free (MvPolynomial σ R) (Ω[MvPolynomial σ R⁄R]) := .of_basis (KaehlerDifferential.mvPolynomialBasis R σ) end MvPolynomial section Polynomial open Polynomial lemma KaehlerDifferential.polynomial_D_apply (P : R[X]) : D R R[X] P = derivative P • D R R[X] X := by rw [← aeval_X_left_apply P, (D R R[X]).map_aeval, aeval_X_left_apply, aeval_X_left_apply] /-- The relative differential module of the univariate polynomial algebra `R[X]` is isomorphic to `R[X]` as an `R[X]`-module. -/ def KaehlerDifferential.polynomialEquiv : Ω[R[X]⁄R] ≃ₗ[R[X]] R[X] where __ := derivative'.liftKaehlerDifferential invFun := (Algebra.lsmul R R _).toLinearMap.flip (D R R[X] X) left_inv := by intro x obtain ⟨x, rfl⟩ := total_surjective _ _ x induction' x using Finsupp.induction_linear with x y hx hy x y · simp · simp only [map_add, AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, LinearMap.flip_apply, AlgHom.toLinearMap_apply, lsmul_coe] at *; simp only [*] · simp [polynomial_D_apply _ x] right_inv x := by simp lemma KaehlerDifferential.polynomialEquiv_comp_D : (polynomialEquiv R).compDer (D R R[X]) = derivative' := Derivation.liftKaehlerDifferential_comp _ @[simp] lemma KaehlerDifferential.polynomialEquiv_D (P) : polynomialEquiv R (D R R[X] P) = derivative P := Derivation.congr_fun (polynomialEquiv_comp_D R) P @[simp] lemma KaehlerDifferential.polynomialEquiv_symm (P) : (polynomialEquiv R).symm P = P • D R R[X] X := rfl end Polynomial
RingTheory\Localization\Algebra.lean
/- Copyright (c) 2024 Christian Merten. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christian Merten -/ import Mathlib.Algebra.Module.LocalizedModule import Mathlib.RingTheory.Ideal.Maps import Mathlib.RingTheory.Localization.Basic import Mathlib.RingTheory.Localization.Ideal /-! # Localization of algebra maps In this file we provide constructors to localize algebra maps. Also we show that localization commutes with taking kernels for ring homomorphisms. ## Implementation detail The proof that localization commutes with taking kernels does not use the result for linear maps, as the translation is currently tedious and can be unified easily after the localization refactor. -/ universe u u' v v' w w' variable {R S P : Type*} (Q : Type*) [CommSemiring R] [CommSemiring S] [CommSemiring P] [CommSemiring Q] {M : Submonoid R} {T : Submonoid P} [Algebra R S] [Algebra P Q] [IsLocalization M S] [IsLocalization T Q] (g : R →+* P) open IsLocalization in variable (M S) in /-- The span of `I` in a localization of `R` at `M` is the localization of `I` at `M`. -/ instance Algebra.idealMap_isLocalizedModule (I : Ideal R) : IsLocalizedModule M (Algebra.idealMap I (S := S)) where map_units x := (Module.End_isUnit_iff _).mpr ⟨fun a b e ↦ Subtype.ext ((map_units S x).mul_right_injective (by simpa [Algebra.smul_def] using congr(($e).1))), fun a ↦ ⟨⟨_, Ideal.mul_mem_left _ (map_units S x).unit⁻¹.1 a.2⟩, Subtype.ext (by simp [Algebra.smul_def, ← mul_assoc])⟩⟩ surj' y := have ⟨x, hx⟩ := (mem_map_algebraMap_iff M S).mp y.property ⟨x, Subtype.ext (by simp [Submonoid.smul_def, Algebra.smul_def, mul_comm, hx])⟩ exists_of_eq h := ⟨_, Subtype.ext (exists_of_eq congr(($h).1)).choose_spec⟩ lemma IsLocalization.ker_map (hT : Submonoid.map g M = T) : RingHom.ker (IsLocalization.map Q g (hT.symm ▸ M.le_comap_map) : S →+* Q) = (RingHom.ker g).map (algebraMap R S) := by ext x obtain ⟨x, s, rfl⟩ := IsLocalization.mk'_surjective M x simp [RingHom.mem_ker, IsLocalization.map_mk', IsLocalization.mk'_eq_zero_iff, IsLocalization.mk'_mem_map_algebraMap_iff, ← hT] variable (S) in /-- The canonical linear map from the kernel of `g` to the kernel of its localization. -/ def RingHom.toKerIsLocalization (hy : M ≤ Submonoid.comap g T) : RingHom.ker g →ₗ[R] RingHom.ker (IsLocalization.map Q g hy : S →+* Q) where toFun x := ⟨algebraMap R S x, by simp [RingHom.mem_ker, (RingHom.mem_ker g).mp x.property]⟩ map_add' x y := by simp only [AddSubmonoid.coe_add, Submodule.coe_toAddSubmonoid, map_add, AddSubmonoid.mk_add_mk] map_smul' a x := by simp only [SetLike.val_smul, smul_eq_mul, map_mul, RingHom.id_apply, SetLike.mk_smul_of_tower_mk, Algebra.smul_def] @[simp] lemma RingHom.toKerIsLocalization_apply (hy : M ≤ Submonoid.comap g T) (r : RingHom.ker g) : (RingHom.toKerIsLocalization S Q g hy r).val = algebraMap R S r := rfl /-- The canonical linear map from the kernel of `g` to the kernel of its localization is localizing. In other words, localization commutes with taking kernels. -/ lemma RingHom.toKerIsLocalization_isLocalizedModule (hT : Submonoid.map g M = T) : IsLocalizedModule M (toKerIsLocalization S Q g (hT.symm ▸ Submonoid.le_comap_map M)) := by let e := LinearEquiv.ofEq _ _ (IsLocalization.ker_map (S := S) Q g hT).symm convert_to IsLocalizedModule M ((e.restrictScalars R).toLinearMap ∘ₗ Algebra.idealMap S (RingHom.ker g)) apply IsLocalizedModule.of_linearEquiv section Algebra open Algebra variable {R : Type u} [CommRing R] (M : Submonoid R) variable {A : Type v} [CommRing A] [Algebra R A] variable {B : Type w} [CommRing B] [Algebra R B] variable (Rₚ : Type u') [CommRing Rₚ] [Algebra R Rₚ] [IsLocalization M Rₚ] variable (Aₚ : Type v') [CommRing Aₚ] [Algebra R Aₚ] [Algebra A Aₚ] [IsScalarTower R A Aₚ] [IsLocalization (Algebra.algebraMapSubmonoid A M) Aₚ] variable (Bₚ : Type v') [CommRing Bₚ] [Algebra R Bₚ] [Algebra B Bₚ] [IsScalarTower R B Bₚ] [IsLocalization (Algebra.algebraMapSubmonoid B M) Bₚ] variable [Algebra Rₚ Aₚ] [Algebra Rₚ Bₚ] [IsScalarTower R Rₚ Aₚ] [IsScalarTower R Rₚ Bₚ] namespace IsLocalization instance isLocalization_algebraMapSubmonoid_map_algHom (f : A →ₐ[R] B) : IsLocalization ((algebraMapSubmonoid A M).map f.toRingHom) Bₚ := by erw [algebraMapSubmonoid_map_eq M f] infer_instance /-- An algebra map `A →ₐ[R] B` induces an algebra map on localizations `Aₚ →ₐ[Rₚ] Bₚ`. -/ noncomputable def mapₐ (f : A →ₐ[R] B) : Aₚ →ₐ[Rₚ] Bₚ := ⟨IsLocalization.map Bₚ f.toRingHom (Algebra.algebraMapSubmonoid_le_comap M f), fun r ↦ by obtain ⟨a, m, rfl⟩ := IsLocalization.mk'_surjective M r simp [algebraMap_mk' (S := A), algebraMap_mk' (S := B), map_mk']⟩ @[simp] lemma mapₐ_coe (f : A →ₐ[R] B) : (mapₐ M Rₚ Aₚ Bₚ f : Aₚ → Bₚ) = map Bₚ f.toRingHom (algebraMapSubmonoid_le_comap M f) := rfl lemma mapₐ_injective_of_injective (f : A →ₐ[R] B) (hf : Function.Injective f) : Function.Injective (mapₐ M Rₚ Aₚ Bₚ f) := IsLocalization.map_injective_of_injective _ _ _ hf lemma mapₐ_surjective_of_surjective (f : A →ₐ[R] B) (hf : Function.Surjective f) : Function.Surjective (mapₐ M Rₚ Aₚ Bₚ f) := IsLocalization.map_surjective_of_surjective _ _ _ hf end IsLocalization open IsLocalization /-- The canonical linear map from the kernel of an algebra homomorphism to its localization. -/ def AlgHom.toKerIsLocalization (f : A →ₐ[R] B) : RingHom.ker f →ₗ[A] RingHom.ker (mapₐ M Rₚ Aₚ Bₚ f) := RingHom.toKerIsLocalization Aₚ Bₚ f.toRingHom (algebraMapSubmonoid_le_comap M f) @[simp] lemma AlgHom.toKerIsLocalization_apply (f : A →ₐ[R] B) (x : RingHom.ker f) : AlgHom.toKerIsLocalization M Rₚ Aₚ Bₚ f x = RingHom.toKerIsLocalization Aₚ Bₚ f.toRingHom (algebraMapSubmonoid_le_comap M f) x := rfl /-- The canonical linear map from the kernel of an algebra homomorphism to its localization is localizing. -/ lemma AlgHom.toKerIsLocalization_isLocalizedModule (f : A →ₐ[R] B) : IsLocalizedModule (Algebra.algebraMapSubmonoid A M) (AlgHom.toKerIsLocalization M Rₚ Aₚ Bₚ f) := RingHom.toKerIsLocalization_isLocalizedModule Bₚ f.toRingHom (algebraMapSubmonoid_map_eq M f) end Algebra
RingTheory\Localization\AsSubring.lean
/- Copyright (c) 2022 Adam Topaz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz, Junyan Xu -/ import Mathlib.RingTheory.Localization.LocalizationLocalization /-! # Localizations of domains as subalgebras of the fraction field. Given a domain `A` with fraction field `K`, and a submonoid `S` of `A` which does not contain zero, this file constructs the localization of `A` at `S` as a subalgebra of the field `K` over `A`. -/ namespace Localization open nonZeroDivisors variable {A : Type*} (K : Type*) [CommRing A] (S : Submonoid A) (hS : S ≤ A⁰) section CommRing variable [CommRing K] [Algebra A K] [IsFractionRing A K] theorem map_isUnit_of_le (hS : S ≤ A⁰) (s : S) : IsUnit (algebraMap A K s) := by apply IsLocalization.map_units K (⟨s.1, hS s.2⟩ : A⁰) /-- The canonical map from a localization of `A` at `S` to the fraction ring of `A`, given that `S ≤ A⁰`. -/ noncomputable def mapToFractionRing (B : Type*) [CommRing B] [Algebra A B] [IsLocalization S B] (hS : S ≤ A⁰) : B →ₐ[A] K := { IsLocalization.lift (map_isUnit_of_le K S hS) with commutes' := fun a => by simp } @[simp] theorem mapToFractionRing_apply {B : Type*} [CommRing B] [Algebra A B] [IsLocalization S B] (hS : S ≤ A⁰) (b : B) : mapToFractionRing K S B hS b = IsLocalization.lift (map_isUnit_of_le K S hS) b := rfl theorem mem_range_mapToFractionRing_iff (B : Type*) [CommRing B] [Algebra A B] [IsLocalization S B] (hS : S ≤ A⁰) (x : K) : x ∈ (mapToFractionRing K S B hS).range ↔ ∃ (a s : A) (hs : s ∈ S), x = IsLocalization.mk' K a ⟨s, hS hs⟩ := ⟨by rintro ⟨x, rfl⟩ obtain ⟨a, s, rfl⟩ := IsLocalization.mk'_surjective S x use a, s, s.2 apply IsLocalization.lift_mk', by rintro ⟨a, s, hs, rfl⟩ use IsLocalization.mk' _ a ⟨s, hs⟩ apply IsLocalization.lift_mk'⟩ instance isLocalization_range_mapToFractionRing (B : Type*) [CommRing B] [Algebra A B] [IsLocalization S B] (hS : S ≤ A⁰) : IsLocalization S (mapToFractionRing K S B hS).range := IsLocalization.isLocalization_of_algEquiv S <| show B ≃ₐ[A] _ from AlgEquiv.ofBijective (mapToFractionRing K S B hS).rangeRestrict (by refine ⟨fun a b h => ?_, Set.surjective_onto_range⟩ refine (IsLocalization.lift_injective_iff _).2 (fun a b => ?_) (Subtype.ext_iff.1 h) exact ⟨fun h => congr_arg _ (IsLocalization.injective _ hS h), fun h => congr_arg _ (IsFractionRing.injective A K h)⟩) instance isFractionRing_range_mapToFractionRing (B : Type*) [CommRing B] [Algebra A B] [IsLocalization S B] (hS : S ≤ A⁰) : IsFractionRing (mapToFractionRing K S B hS).range K := IsFractionRing.isFractionRing_of_isLocalization S _ _ hS /-- Given a commutative ring `A` with fraction ring `K`, and a submonoid `S` of `A` which contains no zero divisor, this is the localization of `A` at `S`, considered as a subalgebra of `K` over `A`. The carrier of this subalgebra is defined as the set of all `x : K` of the form `IsLocalization.mk' K a ⟨s, _⟩`, where `s ∈ S`. -/ noncomputable def subalgebra (hS : S ≤ A⁰) : Subalgebra A K := (mapToFractionRing K S (Localization S) hS).range.copy { x | ∃ (a s : A) (hs : s ∈ S), x = IsLocalization.mk' K a ⟨s, hS hs⟩ } <| by ext symm apply mem_range_mapToFractionRing_iff namespace subalgebra instance isLocalization_subalgebra : IsLocalization S (subalgebra K S hS) := by dsimp only [Localization.subalgebra] rw [Subalgebra.copy_eq] infer_instance instance isFractionRing : IsFractionRing (subalgebra K S hS) K := IsFractionRing.isFractionRing_of_isLocalization S _ _ hS end subalgebra end CommRing section Field variable [Field K] [Algebra A K] [IsFractionRing A K] namespace subalgebra theorem mem_range_mapToFractionRing_iff_ofField (B : Type*) [CommRing B] [Algebra A B] [IsLocalization S B] (x : K) : x ∈ (mapToFractionRing K S B hS).range ↔ ∃ (a s : A) (_ : s ∈ S), x = algebraMap A K a * (algebraMap A K s)⁻¹ := by rw [mem_range_mapToFractionRing_iff] convert Iff.rfl congr rw [Units.val_inv_eq_inv_val] rfl /-- Given a domain `A` with fraction field `K`, and a submonoid `S` of `A` which contains no zero divisor, this is the localization of `A` at `S`, considered as a subalgebra of `K` over `A`. The carrier of this subalgebra is defined as the set of all `x : K` of the form `algebraMap A K a * (algebraMap A K s)⁻¹` where `a s : A` and `s ∈ S`. -/ noncomputable def ofField : Subalgebra A K := (mapToFractionRing K S (Localization S) hS).range.copy { x | ∃ (a s : A) (_ : s ∈ S), x = algebraMap A K a * (algebraMap A K s)⁻¹ } <| by ext symm apply mem_range_mapToFractionRing_iff_ofField instance isLocalization_ofField : IsLocalization S (subalgebra.ofField K S hS) := by dsimp only [Localization.subalgebra.ofField] rw [Subalgebra.copy_eq] infer_instance instance isFractionRing_ofField : IsFractionRing (subalgebra.ofField K S hS) K := IsFractionRing.isFractionRing_of_isLocalization S _ _ hS end subalgebra end Field end Localization
RingTheory\Localization\AtPrime.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen -/ import Mathlib.RingTheory.Localization.Ideal import Mathlib.RingTheory.LocalRing.MaximalIdeal.Basic import Mathlib.RingTheory.LocalRing.RingHom.Defs /-! # Localizations of commutative rings at the complement of a prime ideal ## Main definitions * `IsLocalization.AtPrime (P : Ideal R) [IsPrime P] (S : Type*)` expresses that `S` is a localization at (the complement of) a prime ideal `P`, as an abbreviation of `IsLocalization P.prime_compl S` ## Main results * `IsLocalization.AtPrime.localRing`: a theorem (not an instance) stating a localization at the complement of a prime ideal is a local ring ## Implementation notes See `RingTheory.Localization.Basic` for a design overview. ## Tags localization, ring localization, commutative ring localization, characteristic predicate, commutative ring, field of fractions -/ variable {R : Type*} [CommSemiring R] (M : Submonoid R) (S : Type*) [CommSemiring S] variable [Algebra R S] {P : Type*} [CommSemiring P] section AtPrime variable (P : Ideal R) [hp : P.IsPrime] namespace Ideal /-- The complement of a prime ideal `P ⊆ R` is a submonoid of `R`. -/ def primeCompl : Submonoid R where carrier := (Pᶜ : Set R) one_mem' := by convert P.ne_top_iff_one.1 hp.1 mul_mem' {x y} hnx hny hxy := Or.casesOn (hp.mem_or_mem hxy) hnx hny theorem primeCompl_le_nonZeroDivisors [NoZeroDivisors R] : P.primeCompl ≤ nonZeroDivisors R := le_nonZeroDivisors_of_noZeroDivisors <| not_not_intro P.zero_mem end Ideal /-- Given a prime ideal `P`, the typeclass `IsLocalization.AtPrime S P` states that `S` is isomorphic to the localization of `R` at the complement of `P`. -/ protected abbrev IsLocalization.AtPrime := IsLocalization P.primeCompl S /-- Given a prime ideal `P`, `Localization.AtPrime P` is a localization of `R` at the complement of `P`, as a quotient type. -/ protected abbrev Localization.AtPrime := Localization P.primeCompl namespace IsLocalization theorem AtPrime.Nontrivial [IsLocalization.AtPrime S P] : Nontrivial S := nontrivial_of_ne (0 : S) 1 fun hze => by rw [← (algebraMap R S).map_one, ← (algebraMap R S).map_zero] at hze obtain ⟨t, ht⟩ := (eq_iff_exists P.primeCompl S).1 hze have htz : (t : R) = 0 := by simpa using ht.symm exact t.2 (htz.symm ▸ P.zero_mem : ↑t ∈ P) theorem AtPrime.localRing [IsLocalization.AtPrime S P] : LocalRing S := -- Porting note: since I couldn't get local instance running, I just specify it manually letI := AtPrime.Nontrivial S P LocalRing.of_nonunits_add (by intro x y hx hy hu cases' isUnit_iff_exists_inv.1 hu with z hxyz have : ∀ {r : R} {s : P.primeCompl}, mk' S r s ∈ nonunits S → r ∈ P := fun {r s} => not_imp_comm.1 fun nr => isUnit_iff_exists_inv.2 ⟨mk' S ↑s (⟨r, nr⟩ : P.primeCompl), mk'_mul_mk'_eq_one' _ _ <| show r ∈ P.primeCompl from nr⟩ rcases mk'_surjective P.primeCompl x with ⟨rx, sx, hrx⟩ rcases mk'_surjective P.primeCompl y with ⟨ry, sy, hry⟩ rcases mk'_surjective P.primeCompl z with ⟨rz, sz, hrz⟩ rw [← hrx, ← hry, ← hrz, ← mk'_add, ← mk'_mul, ← mk'_self S P.primeCompl.one_mem] at hxyz rw [← hrx] at hx rw [← hry] at hy obtain ⟨t, ht⟩ := IsLocalization.eq.1 hxyz simp only [mul_one, one_mul, Submonoid.coe_mul, Subtype.coe_mk] at ht suffices (t : R) * (sx * sy * sz) ∈ P from not_or_of_not (mt hp.mem_or_mem <| not_or_of_not sx.2 sy.2) sz.2 (hp.mem_or_mem <| (hp.mem_or_mem this).resolve_left t.2) rw [← ht] exact P.mul_mem_left _ <| P.mul_mem_right _ <| P.add_mem (P.mul_mem_right _ <| this hx) <| P.mul_mem_right _ <| this hy) end IsLocalization namespace Localization /-- The localization of `R` at the complement of a prime ideal is a local ring. -/ instance AtPrime.localRing : LocalRing (Localization P.primeCompl) := IsLocalization.AtPrime.localRing (Localization P.primeCompl) P end Localization end AtPrime namespace IsLocalization variable {A : Type*} [CommRing A] [IsDomain A] /-- The localization of an integral domain at the complement of a prime ideal is an integral domain. -/ instance isDomain_of_local_atPrime {P : Ideal A} (_ : P.IsPrime) : IsDomain (Localization.AtPrime P) := isDomain_localization P.primeCompl_le_nonZeroDivisors namespace AtPrime variable (I : Ideal R) [hI : I.IsPrime] [IsLocalization.AtPrime S I] /-- The prime ideals in the localization of a commutative ring at a prime ideal I are in order-preserving bijection with the prime ideals contained in I. -/ def orderIsoOfPrime : { p : Ideal S // p.IsPrime } ≃o { p : Ideal R // p.IsPrime ∧ p ≤ I } := (IsLocalization.orderIsoOfPrime I.primeCompl S).trans <| .setCongr _ _ <| show setOf _ = setOf _ by ext; simp [Ideal.primeCompl, ← le_compl_iff_disjoint_left] theorem isUnit_to_map_iff (x : R) : IsUnit ((algebraMap R S) x) ↔ x ∈ I.primeCompl := ⟨fun h hx => (isPrime_of_isPrime_disjoint I.primeCompl S I hI disjoint_compl_left).ne_top <| (Ideal.map (algebraMap R S) I).eq_top_of_isUnit_mem (Ideal.mem_map_of_mem _ hx) h, fun h => map_units S ⟨x, h⟩⟩ -- Can't use typeclasses to infer the `LocalRing` instance, so use an `optParam` instead -- (since `LocalRing` is a `Prop`, there should be no unification issues.) theorem to_map_mem_maximal_iff (x : R) (h : LocalRing S := localRing S I) : algebraMap R S x ∈ LocalRing.maximalIdeal S ↔ x ∈ I := not_iff_not.mp <| by simpa only [LocalRing.mem_maximalIdeal, mem_nonunits_iff, Classical.not_not] using isUnit_to_map_iff S I x theorem comap_maximalIdeal (h : LocalRing S := localRing S I) : (LocalRing.maximalIdeal S).comap (algebraMap R S) = I := Ideal.ext fun x => by simpa only [Ideal.mem_comap] using to_map_mem_maximal_iff _ I x theorem isUnit_mk'_iff (x : R) (y : I.primeCompl) : IsUnit (mk' S x y) ↔ x ∈ I.primeCompl := ⟨fun h hx => mk'_mem_iff.mpr ((to_map_mem_maximal_iff S I x).mpr hx) h, fun h => isUnit_iff_exists_inv.mpr ⟨mk' S ↑y ⟨x, h⟩, mk'_mul_mk'_eq_one ⟨x, h⟩ y⟩⟩ theorem mk'_mem_maximal_iff (x : R) (y : I.primeCompl) (h : LocalRing S := localRing S I) : mk' S x y ∈ LocalRing.maximalIdeal S ↔ x ∈ I := not_iff_not.mp <| by simpa only [LocalRing.mem_maximalIdeal, mem_nonunits_iff, Classical.not_not] using isUnit_mk'_iff S I x y end AtPrime end IsLocalization namespace Localization open IsLocalization attribute [local instance] Classical.propDecidable variable (I : Ideal R) [hI : I.IsPrime] variable {I} /-- The unique maximal ideal of the localization at `I.primeCompl` lies over the ideal `I`. -/ theorem AtPrime.comap_maximalIdeal : Ideal.comap (algebraMap R (Localization.AtPrime I)) (LocalRing.maximalIdeal (Localization I.primeCompl)) = I := -- Porting note: need to provide full name IsLocalization.AtPrime.comap_maximalIdeal _ _ /-- The image of `I` in the localization at `I.primeCompl` is a maximal ideal, and in particular it is the unique maximal ideal given by the local ring structure `AtPrime.localRing` -/ theorem AtPrime.map_eq_maximalIdeal : Ideal.map (algebraMap R (Localization.AtPrime I)) I = LocalRing.maximalIdeal (Localization I.primeCompl) := by convert congr_arg (Ideal.map (algebraMap R (Localization.AtPrime I))) -- Porting note: `algebraMap R ...` can not be solve by unification (AtPrime.comap_maximalIdeal (hI := hI)).symm -- Porting note: can not find `hI` rw [map_comap I.primeCompl] theorem le_comap_primeCompl_iff {J : Ideal P} [hJ : J.IsPrime] {f : R →+* P} : I.primeCompl ≤ J.primeCompl.comap f ↔ J.comap f ≤ I := ⟨fun h x hx => by contrapose! hx exact h hx, fun h x hx hfxJ => hx (h hfxJ)⟩ variable (I) /-- For a ring hom `f : R →+* S` and a prime ideal `J` in `S`, the induced ring hom from the localization of `R` at `J.comap f` to the localization of `S` at `J`. To make this definition more flexible, we allow any ideal `I` of `R` as input, together with a proof that `I = J.comap f`. This can be useful when `I` is not definitionally equal to `J.comap f`. -/ noncomputable def localRingHom (J : Ideal P) [J.IsPrime] (f : R →+* P) (hIJ : I = J.comap f) : Localization.AtPrime I →+* Localization.AtPrime J := IsLocalization.map (Localization.AtPrime J) f (le_comap_primeCompl_iff.mpr (ge_of_eq hIJ)) theorem localRingHom_to_map (J : Ideal P) [J.IsPrime] (f : R →+* P) (hIJ : I = J.comap f) (x : R) : localRingHom I J f hIJ (algebraMap _ _ x) = algebraMap _ _ (f x) := map_eq _ _ theorem localRingHom_mk' (J : Ideal P) [J.IsPrime] (f : R →+* P) (hIJ : I = J.comap f) (x : R) (y : I.primeCompl) : localRingHom I J f hIJ (IsLocalization.mk' _ x y) = IsLocalization.mk' (Localization.AtPrime J) (f x) (⟨f y, le_comap_primeCompl_iff.mpr (ge_of_eq hIJ) y.2⟩ : J.primeCompl) := map_mk' _ _ _ instance isLocalRingHom_localRingHom (J : Ideal P) [hJ : J.IsPrime] (f : R →+* P) (hIJ : I = J.comap f) : IsLocalRingHom (localRingHom I J f hIJ) := IsLocalRingHom.mk fun x hx => by rcases IsLocalization.mk'_surjective I.primeCompl x with ⟨r, s, rfl⟩ rw [localRingHom_mk'] at hx rw [AtPrime.isUnit_mk'_iff] at hx ⊢ exact fun hr => hx ((SetLike.ext_iff.mp hIJ r).mp hr) theorem localRingHom_unique (J : Ideal P) [J.IsPrime] (f : R →+* P) (hIJ : I = J.comap f) {j : Localization.AtPrime I →+* Localization.AtPrime J} (hj : ∀ x : R, j (algebraMap _ _ x) = algebraMap _ _ (f x)) : localRingHom I J f hIJ = j := map_unique _ _ hj @[simp] theorem localRingHom_id : localRingHom I I (RingHom.id R) (Ideal.comap_id I).symm = RingHom.id _ := localRingHom_unique _ _ _ _ fun _ => rfl -- Porting note: simplifier won't pick up this lemma, so deleted @[simp] theorem localRingHom_comp {S : Type*} [CommSemiring S] (J : Ideal S) [hJ : J.IsPrime] (K : Ideal P) [hK : K.IsPrime] (f : R →+* S) (hIJ : I = J.comap f) (g : S →+* P) (hJK : J = K.comap g) : localRingHom I K (g.comp f) (by rw [hIJ, hJK, Ideal.comap_comap f g]) = (localRingHom J K g hJK).comp (localRingHom I J f hIJ) := localRingHom_unique _ _ _ _ fun r => by simp only [Function.comp_apply, RingHom.coe_comp, localRingHom_to_map] end Localization
RingTheory\Localization\BaseChange.lean
/- Copyright (c) 2022 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang, Jujian Zhang -/ import Mathlib.RingTheory.IsTensorProduct import Mathlib.RingTheory.Localization.Module /-! # Localized Module Given a commutative semiring `R`, a multiplicative subset `S ⊆ R` and an `R`-module `M`, we can localize `M` by `S`. This gives us a `Localization S`-module. ## Main definition * `isLocalizedModule_iff_isBaseChange` : A localization of modules corresponds to a base change. -/ variable {R : Type*} [CommSemiring R] (S : Submonoid R) (A : Type*) [CommRing A] [Algebra R A] [IsLocalization S A] {M : Type*} [AddCommMonoid M] [Module R M] [Module A M] [IsScalarTower R A M] {M' : Type*} [AddCommMonoid M'] [Module R M'] [Module A M'] [IsScalarTower R A M'] (f : M →ₗ[R] M') /-- The forward direction of `isLocalizedModule_iff_isBaseChange`. It is also used to prove the other direction. -/ theorem IsLocalizedModule.isBaseChange [IsLocalizedModule S f] : IsBaseChange A f := .of_lift_unique _ fun Q _ _ _ _ g ↦ by obtain ⟨ℓ, rfl, h₂⟩ := IsLocalizedModule.is_universal S f g fun s ↦ by rw [← (Algebra.lsmul R (A := A) R Q).commutes]; exact (IsLocalization.map_units A s).map _ refine ⟨ℓ.extendScalarsOfIsLocalization S A, by simp, fun g'' h ↦ ?_⟩ cases h₂ (LinearMap.restrictScalars R g'') h; rfl /-- The map `(f : M →ₗ[R] M')` is a localization of modules iff the map `(Localization S) × M → N, (s, m) ↦ s • f m` is the tensor product (insomuch as it is the universal bilinear map). In particular, there is an isomorphism between `LocalizedModule S M` and `(Localization S) ⊗[R] M` given by `m/s ↦ (1/s) ⊗ₜ m`. -/ theorem isLocalizedModule_iff_isBaseChange : IsLocalizedModule S f ↔ IsBaseChange A f := by refine ⟨fun _ ↦ IsLocalizedModule.isBaseChange S A f, fun h ↦ ?_⟩ have : IsBaseChange A (LocalizedModule.mkLinearMap S M) := IsLocalizedModule.isBaseChange S A _ let e := (this.equiv.symm.trans h.equiv).restrictScalars R convert IsLocalizedModule.of_linearEquiv S (LocalizedModule.mkLinearMap S M) e ext rw [LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, LinearEquiv.restrictScalars_apply, LinearEquiv.trans_apply, IsBaseChange.equiv_symm_apply, IsBaseChange.equiv_tmul, one_smul]
RingTheory\Localization\Basic.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen -/ import Mathlib.Algebra.Algebra.Tower import Mathlib.Algebra.GroupWithZero.NonZeroDivisors import Mathlib.GroupTheory.MonoidLocalization.MonoidWithZero import Mathlib.RingTheory.OreLocalization.Ring import Mathlib.RingTheory.Ideal.Basic /-! # Localizations of commutative rings We characterize the localization of a commutative ring `R` at a submonoid `M` up to isomorphism; that is, a commutative ring `S` is the localization of `R` at `M` iff we can find a ring homomorphism `f : R →+* S` satisfying 3 properties: 1. For all `y ∈ M`, `f y` is a unit; 2. For all `z : S`, there exists `(x, y) : R × M` such that `z * f y = f x`; 3. For all `x, y : R` such that `f x = f y`, there exists `c ∈ M` such that `x * c = y * c`. (The converse is a consequence of 1.) In the following, let `R, P` be commutative rings, `S, Q` be `R`- and `P`-algebras and `M, T` be submonoids of `R` and `P` respectively, e.g.: ``` variable (R S P Q : Type*) [CommRing R] [CommRing S] [CommRing P] [CommRing Q] variable [Algebra R S] [Algebra P Q] (M : Submonoid R) (T : Submonoid P) ``` ## Main definitions * `IsLocalization (M : Submonoid R) (S : Type*)` is a typeclass expressing that `S` is a localization of `R` at `M`, i.e. the canonical map `algebraMap R S : R →+* S` is a localization map (satisfying the above properties). * `IsLocalization.mk' S` is a surjection sending `(x, y) : R × M` to `f x * (f y)⁻¹` * `IsLocalization.lift` is the ring homomorphism from `S` induced by a homomorphism from `R` which maps elements of `M` to invertible elements of the codomain. * `IsLocalization.map S Q` is the ring homomorphism from `S` to `Q` which maps elements of `M` to elements of `T` * `IsLocalization.ringEquivOfRingEquiv`: if `R` and `P` are isomorphic by an isomorphism sending `M` to `T`, then `S` and `Q` are isomorphic * `IsLocalization.algEquiv`: if `Q` is another localization of `R` at `M`, then `S` and `Q` are isomorphic as `R`-algebras ## Main results * `Localization M S`, a construction of the localization as a quotient type, defined in `GroupTheory.MonoidLocalization`, has `CommRing`, `Algebra R` and `IsLocalization M` instances if `R` is a ring. `Localization.Away`, `Localization.AtPrime` and `FractionRing` are abbreviations for `Localization`s and have their corresponding `IsLocalization` instances ## Implementation notes In maths it is natural to reason up to isomorphism, but in Lean we cannot naturally `rewrite` one structure with an isomorphic one; one way around this is to isolate a predicate characterizing a structure up to isomorphism, and reason about things that satisfy the predicate. A previous version of this file used a fully bundled type of ring localization maps, then used a type synonym `f.codomain` for `f : LocalizationMap M S` to instantiate the `R`-algebra structure on `S`. This results in defining ad-hoc copies for everything already defined on `S`. By making `IsLocalization` a predicate on the `algebraMap R S`, we can ensure the localization map commutes nicely with other `algebraMap`s. To prove most lemmas about a localization map `algebraMap R S` in this file we invoke the corresponding proof for the underlying `CommMonoid` localization map `IsLocalization.toLocalizationMap M S`, which can be found in `GroupTheory.MonoidLocalization` and the namespace `Submonoid.LocalizationMap`. To reason about the localization as a quotient type, use `mk_eq_of_mk'` and associated lemmas. These show the quotient map `mk : R → M → Localization M` equals the surjection `LocalizationMap.mk'` induced by the map `algebraMap : R →+* Localization M`. The lemma `mk_eq_of_mk'` hence gives you access to the results in the rest of the file, which are about the `LocalizationMap.mk'` induced by any localization map. The proof that "a `CommRing` `K` which is the localization of an integral domain `R` at `R \ {0}` is a field" is a `def` rather than an `instance`, so if you want to reason about a field of fractions `K`, assume `[Field K]` instead of just `[CommRing K]`. ## Tags localization, ring localization, commutative ring localization, characteristic predicate, commutative ring, field of fractions -/ open Function section CommSemiring variable {R : Type*} [CommSemiring R] (M : Submonoid R) (S : Type*) [CommSemiring S] variable [Algebra R S] {P : Type*} [CommSemiring P] /-- The typeclass `IsLocalization (M : Submonoid R) S` where `S` is an `R`-algebra expresses that `S` is isomorphic to the localization of `R` at `M`. -/ @[mk_iff] class IsLocalization : Prop where -- Porting note: add ' to fields, and made new versions of these with either `S` or `M` explicit. /-- Everything in the image of `algebraMap` is a unit -/ map_units' : ∀ y : M, IsUnit (algebraMap R S y) /-- The `algebraMap` is surjective -/ surj' : ∀ z : S, ∃ x : R × M, z * algebraMap R S x.2 = algebraMap R S x.1 /-- The kernel of `algebraMap` is contained in the annihilator of `M`; it is then equal to the annihilator by `map_units'` -/ exists_of_eq : ∀ {x y}, algebraMap R S x = algebraMap R S y → ∃ c : M, ↑c * x = ↑c * y variable {M} namespace IsLocalization section IsLocalization variable [IsLocalization M S] section @[inherit_doc IsLocalization.map_units'] theorem map_units : ∀ y : M, IsUnit (algebraMap R S y) := IsLocalization.map_units' variable (M) {S} @[inherit_doc IsLocalization.surj'] theorem surj : ∀ z : S, ∃ x : R × M, z * algebraMap R S x.2 = algebraMap R S x.1 := IsLocalization.surj' variable (S) @[inherit_doc IsLocalization.exists_of_eq] theorem eq_iff_exists {x y} : algebraMap R S x = algebraMap R S y ↔ ∃ c : M, ↑c * x = ↑c * y := Iff.intro IsLocalization.exists_of_eq fun ⟨c, h⟩ ↦ by apply_fun algebraMap R S at h rw [map_mul, map_mul] at h exact (IsLocalization.map_units S c).mul_right_inj.mp h variable {S} theorem of_le (N : Submonoid R) (h₁ : M ≤ N) (h₂ : ∀ r ∈ N, IsUnit (algebraMap R S r)) : IsLocalization N S where map_units' r := h₂ r r.2 surj' s := have ⟨⟨x, y, hy⟩, H⟩ := IsLocalization.surj M s ⟨⟨x, y, h₁ hy⟩, H⟩ exists_of_eq {x y} := by rw [IsLocalization.eq_iff_exists M] rintro ⟨c, hc⟩ exact ⟨⟨c, h₁ c.2⟩, hc⟩ variable (S) /-- `IsLocalization.toLocalizationWithZeroMap M S` shows `S` is the monoid localization of `R` at `M`. -/ @[simps] def toLocalizationWithZeroMap : Submonoid.LocalizationWithZeroMap M S where __ := algebraMap R S toFun := algebraMap R S map_units' := IsLocalization.map_units _ surj' := IsLocalization.surj _ exists_of_eq _ _ := IsLocalization.exists_of_eq /-- `IsLocalization.toLocalizationMap M S` shows `S` is the monoid localization of `R` at `M`. -/ abbrev toLocalizationMap : Submonoid.LocalizationMap M S := (toLocalizationWithZeroMap M S).toLocalizationMap @[simp] theorem toLocalizationMap_toMap : (toLocalizationMap M S).toMap = (algebraMap R S : R →*₀ S) := rfl theorem toLocalizationMap_toMap_apply (x) : (toLocalizationMap M S).toMap x = algebraMap R S x := rfl theorem surj₂ : ∀ z w : S, ∃ z' w' : R, ∃ d : M, (z * algebraMap R S d = algebraMap R S z') ∧ (w * algebraMap R S d = algebraMap R S w') := (toLocalizationMap M S).surj₂ end variable (M) {S} /-- Given a localization map `f : M →* N`, a section function sending `z : N` to some `(x, y) : M × S` such that `f x * (f y)⁻¹ = z`. -/ noncomputable def sec (z : S) : R × M := Classical.choose <| IsLocalization.surj _ z @[simp] theorem toLocalizationMap_sec : (toLocalizationMap M S).sec = sec M := rfl /-- Given `z : S`, `IsLocalization.sec M z` is defined to be a pair `(x, y) : R × M` such that `z * f y = f x` (so this lemma is true by definition). -/ theorem sec_spec (z : S) : z * algebraMap R S (IsLocalization.sec M z).2 = algebraMap R S (IsLocalization.sec M z).1 := Classical.choose_spec <| IsLocalization.surj _ z /-- Given `z : S`, `IsLocalization.sec M z` is defined to be a pair `(x, y) : R × M` such that `z * f y = f x`, so this lemma is just an application of `S`'s commutativity. -/ theorem sec_spec' (z : S) : algebraMap R S (IsLocalization.sec M z).1 = algebraMap R S (IsLocalization.sec M z).2 * z := by rw [mul_comm, sec_spec] variable {M} /-- If `M` contains `0` then the localization at `M` is trivial. -/ theorem subsingleton (h : 0 ∈ M) : Subsingleton S := (toLocalizationMap M S).subsingleton h theorem map_right_cancel {x y} {c : M} (h : algebraMap R S (c * x) = algebraMap R S (c * y)) : algebraMap R S x = algebraMap R S y := (toLocalizationMap M S).map_right_cancel h theorem map_left_cancel {x y} {c : M} (h : algebraMap R S (x * c) = algebraMap R S (y * c)) : algebraMap R S x = algebraMap R S y := (toLocalizationMap M S).map_left_cancel h theorem eq_zero_of_fst_eq_zero {z x} {y : M} (h : z * algebraMap R S y = algebraMap R S x) (hx : x = 0) : z = 0 := by rw [hx, (algebraMap R S).map_zero] at h exact (IsUnit.mul_left_eq_zero (IsLocalization.map_units S y)).1 h variable (M S) theorem map_eq_zero_iff (r : R) : algebraMap R S r = 0 ↔ ∃ m : M, ↑m * r = 0 := by constructor · intro h obtain ⟨m, hm⟩ := (IsLocalization.eq_iff_exists M S).mp ((algebraMap R S).map_zero.trans h.symm) exact ⟨m, by simpa using hm.symm⟩ · rintro ⟨m, hm⟩ rw [← (IsLocalization.map_units S m).mul_right_inj, mul_zero, ← RingHom.map_mul, hm, RingHom.map_zero] variable {M} /-- `IsLocalization.mk' S` is the surjection sending `(x, y) : R × M` to `f x * (f y)⁻¹`. -/ noncomputable def mk' (x : R) (y : M) : S := (toLocalizationMap M S).mk' x y @[simp] theorem mk'_sec (z : S) : mk' S (IsLocalization.sec M z).1 (IsLocalization.sec M z).2 = z := (toLocalizationMap M S).mk'_sec _ theorem mk'_mul (x₁ x₂ : R) (y₁ y₂ : M) : mk' S (x₁ * x₂) (y₁ * y₂) = mk' S x₁ y₁ * mk' S x₂ y₂ := (toLocalizationMap M S).mk'_mul _ _ _ _ theorem mk'_one (x) : mk' S x (1 : M) = algebraMap R S x := (toLocalizationMap M S).mk'_one _ @[simp] theorem mk'_spec (x) (y : M) : mk' S x y * algebraMap R S y = algebraMap R S x := (toLocalizationMap M S).mk'_spec _ _ @[simp] theorem mk'_spec' (x) (y : M) : algebraMap R S y * mk' S x y = algebraMap R S x := (toLocalizationMap M S).mk'_spec' _ _ @[simp] theorem mk'_spec_mk (x) (y : R) (hy : y ∈ M) : mk' S x ⟨y, hy⟩ * algebraMap R S y = algebraMap R S x := mk'_spec S x ⟨y, hy⟩ @[simp] theorem mk'_spec'_mk (x) (y : R) (hy : y ∈ M) : algebraMap R S y * mk' S x ⟨y, hy⟩ = algebraMap R S x := mk'_spec' S x ⟨y, hy⟩ variable {S} theorem eq_mk'_iff_mul_eq {x} {y : M} {z} : z = mk' S x y ↔ z * algebraMap R S y = algebraMap R S x := (toLocalizationMap M S).eq_mk'_iff_mul_eq theorem mk'_eq_iff_eq_mul {x} {y : M} {z} : mk' S x y = z ↔ algebraMap R S x = z * algebraMap R S y := (toLocalizationMap M S).mk'_eq_iff_eq_mul theorem mk'_add_eq_iff_add_mul_eq_mul {x} {y : M} {z₁ z₂} : mk' S x y + z₁ = z₂ ↔ algebraMap R S x + z₁ * algebraMap R S y = z₂ * algebraMap R S y := by rw [← mk'_spec S x y, ← IsUnit.mul_left_inj (IsLocalization.map_units S y), right_distrib] theorem mk'_pow (x : R) (y : M) (n : ℕ) : mk' S (x ^ n) (y ^ n) = mk' S x y ^ n := by simp_rw [IsLocalization.mk'_eq_iff_eq_mul, SubmonoidClass.coe_pow, map_pow, ← mul_pow] simp variable (M) theorem mk'_surjective (z : S) : ∃ (x : _) (y : M), mk' S x y = z := let ⟨r, hr⟩ := IsLocalization.surj _ z ⟨r.1, r.2, (eq_mk'_iff_mul_eq.2 hr).symm⟩ variable (S) /-- The localization of a `Fintype` is a `Fintype`. Cannot be an instance. -/ noncomputable def fintype' [Fintype R] : Fintype S := have := Classical.propDecidable Fintype.ofSurjective (Function.uncurry <| IsLocalization.mk' S) fun a => Prod.exists'.mpr <| IsLocalization.mk'_surjective M a variable {M S} /-- Localizing at a submonoid with 0 inside it leads to the trivial ring. -/ def uniqueOfZeroMem (h : (0 : R) ∈ M) : Unique S := uniqueOfZeroEqOne <| by simpa using IsLocalization.map_units S ⟨0, h⟩ theorem mk'_eq_iff_eq {x₁ x₂} {y₁ y₂ : M} : mk' S x₁ y₁ = mk' S x₂ y₂ ↔ algebraMap R S (y₂ * x₁) = algebraMap R S (y₁ * x₂) := (toLocalizationMap M S).mk'_eq_iff_eq theorem mk'_eq_iff_eq' {x₁ x₂} {y₁ y₂ : M} : mk' S x₁ y₁ = mk' S x₂ y₂ ↔ algebraMap R S (x₁ * y₂) = algebraMap R S (x₂ * y₁) := (toLocalizationMap M S).mk'_eq_iff_eq' theorem mk'_mem_iff {x} {y : M} {I : Ideal S} : mk' S x y ∈ I ↔ algebraMap R S x ∈ I := by constructor <;> intro h · rw [← mk'_spec S x y, mul_comm] exact I.mul_mem_left ((algebraMap R S) y) h · rw [← mk'_spec S x y] at h obtain ⟨b, hb⟩ := isUnit_iff_exists_inv.1 (map_units S y) have := I.mul_mem_left b h rwa [mul_comm, mul_assoc, hb, mul_one] at this protected theorem eq {a₁ b₁} {a₂ b₂ : M} : mk' S a₁ a₂ = mk' S b₁ b₂ ↔ ∃ c : M, ↑c * (↑b₂ * a₁) = c * (a₂ * b₁) := (toLocalizationMap M S).eq theorem mk'_eq_zero_iff (x : R) (s : M) : mk' S x s = 0 ↔ ∃ m : M, ↑m * x = 0 := by rw [← (map_units S s).mul_left_inj, mk'_spec, zero_mul, map_eq_zero_iff M] @[simp] theorem mk'_zero (s : M) : IsLocalization.mk' S 0 s = 0 := by rw [eq_comm, IsLocalization.eq_mk'_iff_mul_eq, zero_mul, map_zero] theorem ne_zero_of_mk'_ne_zero {x : R} {y : M} (hxy : IsLocalization.mk' S x y ≠ 0) : x ≠ 0 := by rintro rfl exact hxy (IsLocalization.mk'_zero _) section Ext variable [Algebra R P] [IsLocalization M P] theorem eq_iff_eq {x y} : algebraMap R S x = algebraMap R S y ↔ algebraMap R P x = algebraMap R P y := (toLocalizationMap M S).eq_iff_eq (toLocalizationMap M P) theorem mk'_eq_iff_mk'_eq {x₁ x₂} {y₁ y₂ : M} : mk' S x₁ y₁ = mk' S x₂ y₂ ↔ mk' P x₁ y₁ = mk' P x₂ y₂ := (toLocalizationMap M S).mk'_eq_iff_mk'_eq (toLocalizationMap M P) theorem mk'_eq_of_eq {a₁ b₁ : R} {a₂ b₂ : M} (H : ↑a₂ * b₁ = ↑b₂ * a₁) : mk' S a₁ a₂ = mk' S b₁ b₂ := (toLocalizationMap M S).mk'_eq_of_eq H theorem mk'_eq_of_eq' {a₁ b₁ : R} {a₂ b₂ : M} (H : b₁ * ↑a₂ = a₁ * ↑b₂) : mk' S a₁ a₂ = mk' S b₁ b₂ := (toLocalizationMap M S).mk'_eq_of_eq' H theorem mk'_cancel (a : R) (b c : M) : mk' S (a * c) (b * c) = mk' S a b := (toLocalizationMap M S).mk'_cancel _ _ _ variable (S) @[simp] theorem mk'_self {x : R} (hx : x ∈ M) : mk' S x ⟨x, hx⟩ = 1 := (toLocalizationMap M S).mk'_self _ hx @[simp] theorem mk'_self' {x : M} : mk' S (x : R) x = 1 := (toLocalizationMap M S).mk'_self' _ theorem mk'_self'' {x : M} : mk' S x.1 x = 1 := mk'_self' _ end Ext theorem mul_mk'_eq_mk'_of_mul (x y : R) (z : M) : (algebraMap R S) x * mk' S y z = mk' S (x * y) z := (toLocalizationMap M S).mul_mk'_eq_mk'_of_mul _ _ _ theorem mk'_eq_mul_mk'_one (x : R) (y : M) : mk' S x y = (algebraMap R S) x * mk' S 1 y := ((toLocalizationMap M S).mul_mk'_one_eq_mk' _ _).symm @[simp] theorem mk'_mul_cancel_left (x : R) (y : M) : mk' S (y * x : R) y = (algebraMap R S) x := (toLocalizationMap M S).mk'_mul_cancel_left _ _ theorem mk'_mul_cancel_right (x : R) (y : M) : mk' S (x * y) y = (algebraMap R S) x := (toLocalizationMap M S).mk'_mul_cancel_right _ _ @[simp] theorem mk'_mul_mk'_eq_one (x y : M) : mk' S (x : R) y * mk' S (y : R) x = 1 := by rw [← mk'_mul, mul_comm]; exact mk'_self _ _ theorem mk'_mul_mk'_eq_one' (x : R) (y : M) (h : x ∈ M) : mk' S x y * mk' S (y : R) ⟨x, h⟩ = 1 := mk'_mul_mk'_eq_one ⟨x, h⟩ _ theorem smul_mk' (x y : R) (m : M) : x • mk' S y m = mk' S (x * y) m := by nth_rw 2 [← one_mul m] rw [mk'_mul, mk'_one, Algebra.smul_def] @[simp] theorem smul_mk'_one (x : R) (m : M) : x • mk' S 1 m = mk' S x m := by rw [smul_mk', mul_one] @[simp] lemma smul_mk'_self {m : M} {r : R} : (m : R) • mk' S r m = algebraMap R S r := by rw [smul_mk', mk'_mul_cancel_left] @[simps] instance invertible_mk'_one (s : M) : Invertible (IsLocalization.mk' S (1 : R) s) where invOf := algebraMap R S s invOf_mul_self := by simp mul_invOf_self := by simp section variable (M) theorem isUnit_comp (j : S →+* P) (y : M) : IsUnit (j.comp (algebraMap R S) y) := (toLocalizationMap M S).isUnit_comp j.toMonoidHom _ end /-- Given a localization map `f : R →+* S` for a submonoid `M ⊆ R` and a map of `CommSemiring`s `g : R →+* P` such that `g(M) ⊆ Units P`, `f x = f y → g x = g y` for all `x y : R`. -/ theorem eq_of_eq {g : R →+* P} (hg : ∀ y : M, IsUnit (g y)) {x y} (h : (algebraMap R S) x = (algebraMap R S) y) : g x = g y := Submonoid.LocalizationMap.eq_of_eq (toLocalizationMap M S) (g := g.toMonoidHom) hg h theorem mk'_add (x₁ x₂ : R) (y₁ y₂ : M) : mk' S (x₁ * y₂ + x₂ * y₁) (y₁ * y₂) = mk' S x₁ y₁ + mk' S x₂ y₂ := mk'_eq_iff_eq_mul.2 <| Eq.symm (by rw [mul_comm (_ + _), mul_add, mul_mk'_eq_mk'_of_mul, mk'_add_eq_iff_add_mul_eq_mul, mul_comm (_ * _), ← mul_assoc, add_comm, ← map_mul, mul_mk'_eq_mk'_of_mul, mk'_add_eq_iff_add_mul_eq_mul] simp only [map_add, Submonoid.coe_mul, map_mul] ring) theorem mul_add_inv_left {g : R →+* P} (h : ∀ y : M, IsUnit (g y)) (y : M) (w z₁ z₂ : P) : w * ↑(IsUnit.liftRight (g.toMonoidHom.restrict M) h y)⁻¹ + z₁ = z₂ ↔ w + g y * z₁ = g y * z₂ := by rw [mul_comm, ← one_mul z₁, ← Units.inv_mul (IsUnit.liftRight (g.toMonoidHom.restrict M) h y), mul_assoc, ← mul_add, Units.inv_mul_eq_iff_eq_mul, Units.inv_mul_cancel_left, IsUnit.coe_liftRight] simp [RingHom.toMonoidHom_eq_coe, MonoidHom.restrict_apply] theorem lift_spec_mul_add {g : R →+* P} (hg : ∀ y : M, IsUnit (g y)) (z w w' v) : ((toLocalizationWithZeroMap M S).lift g.toMonoidWithZeroHom hg) z * w + w' = v ↔ g ((toLocalizationMap M S).sec z).1 * w + g ((toLocalizationMap M S).sec z).2 * w' = g ((toLocalizationMap M S).sec z).2 * v := by erw [mul_comm, ← mul_assoc, mul_add_inv_left hg, mul_comm] rfl /-- Given a localization map `f : R →+* S` for a submonoid `M ⊆ R` and a map of `CommSemiring`s `g : R →+* P` such that `g y` is invertible for all `y : M`, the homomorphism induced from `S` to `P` sending `z : S` to `g x * (g y)⁻¹`, where `(x, y) : R × M` are such that `z = f x * (f y)⁻¹`. -/ noncomputable def lift {g : R →+* P} (hg : ∀ y : M, IsUnit (g y)) : S →+* P := { Submonoid.LocalizationWithZeroMap.lift (toLocalizationWithZeroMap M S) g.toMonoidWithZeroHom hg with map_add' := by intro x y erw [(toLocalizationMap M S).lift_spec, mul_add, mul_comm, eq_comm, lift_spec_mul_add, add_comm, mul_comm, mul_assoc, mul_comm, mul_assoc, lift_spec_mul_add] simp_rw [← mul_assoc] show g _ * g _ * g _ + g _ * g _ * g _ = g _ * g _ * g _ simp_rw [← map_mul g, ← map_add g] apply eq_of_eq (S := S) hg simp only [sec_spec', toLocalizationMap_sec, map_add, map_mul] ring } variable {g : R →+* P} (hg : ∀ y : M, IsUnit (g y)) /-- Given a localization map `f : R →+* S` for a submonoid `M ⊆ R` and a map of `CommSemiring`s `g : R →* P` such that `g y` is invertible for all `y : M`, the homomorphism induced from `S` to `P` maps `f x * (f y)⁻¹` to `g x * (g y)⁻¹` for all `x : R, y ∈ M`. -/ theorem lift_mk' (x y) : lift hg (mk' S x y) = g x * ↑(IsUnit.liftRight (g.toMonoidHom.restrict M) hg y)⁻¹ := (toLocalizationMap M S).lift_mk' _ _ _ theorem lift_mk'_spec (x v) (y : M) : lift hg (mk' S x y) = v ↔ g x = g y * v := (toLocalizationMap M S).lift_mk'_spec _ _ _ _ @[simp] theorem lift_eq (x : R) : lift hg ((algebraMap R S) x) = g x := (toLocalizationMap M S).lift_eq _ _ theorem lift_eq_iff {x y : R × M} : lift hg (mk' S x.1 x.2) = lift hg (mk' S y.1 y.2) ↔ g (x.1 * y.2) = g (y.1 * x.2) := (toLocalizationMap M S).lift_eq_iff _ @[simp] theorem lift_comp : (lift hg).comp (algebraMap R S) = g := RingHom.ext <| (DFunLike.ext_iff (F := MonoidHom _ _)).1 <| (toLocalizationMap M S).lift_comp _ @[simp] theorem lift_of_comp (j : S →+* P) : lift (isUnit_comp M j) = j := RingHom.ext <| (DFunLike.ext_iff (F := MonoidHom _ _)).1 <| (toLocalizationMap M S).lift_of_comp j.toMonoidHom variable (M) /-- See note [partially-applied ext lemmas] -/ theorem monoidHom_ext ⦃j k : S →* P⦄ (h : j.comp (algebraMap R S : R →* S) = k.comp (algebraMap R S)) : j = k := Submonoid.LocalizationMap.epic_of_localizationMap (toLocalizationMap M S) <| DFunLike.congr_fun h /-- See note [partially-applied ext lemmas] -/ theorem ringHom_ext ⦃j k : S →+* P⦄ (h : j.comp (algebraMap R S) = k.comp (algebraMap R S)) : j = k := RingHom.coe_monoidHom_injective <| monoidHom_ext M <| MonoidHom.ext <| RingHom.congr_fun h /- This is not an instance because the submonoid `M` would become a metavariable in typeclass search. -/ theorem algHom_subsingleton [Algebra R P] : Subsingleton (S →ₐ[R] P) := ⟨fun f g => AlgHom.coe_ringHom_injective <| IsLocalization.ringHom_ext M <| by rw [f.comp_algebraMap, g.comp_algebraMap]⟩ /-- To show `j` and `k` agree on the whole localization, it suffices to show they agree on the image of the base ring, if they preserve `1` and `*`. -/ protected theorem ext (j k : S → P) (hj1 : j 1 = 1) (hk1 : k 1 = 1) (hjm : ∀ a b, j (a * b) = j a * j b) (hkm : ∀ a b, k (a * b) = k a * k b) (h : ∀ a, j (algebraMap R S a) = k (algebraMap R S a)) : j = k := let j' : MonoidHom S P := { toFun := j, map_one' := hj1, map_mul' := hjm } let k' : MonoidHom S P := { toFun := k, map_one' := hk1, map_mul' := hkm } have : j' = k' := monoidHom_ext M (MonoidHom.ext h) show j'.toFun = k'.toFun by rw [this] variable {M} theorem lift_unique {j : S →+* P} (hj : ∀ x, j ((algebraMap R S) x) = g x) : lift hg = j := RingHom.ext <| (DFunLike.ext_iff (F := MonoidHom _ _)).1 <| Submonoid.LocalizationMap.lift_unique (toLocalizationMap M S) (g := g.toMonoidHom) hg (j := j.toMonoidHom) hj @[simp] theorem lift_id (x) : lift (map_units S : ∀ _ : M, IsUnit _) x = x := (toLocalizationMap M S).lift_id _ theorem lift_surjective_iff : Surjective (lift hg : S → P) ↔ ∀ v : P, ∃ x : R × M, v * g x.2 = g x.1 := (toLocalizationMap M S).lift_surjective_iff hg theorem lift_injective_iff : Injective (lift hg : S → P) ↔ ∀ x y, algebraMap R S x = algebraMap R S y ↔ g x = g y := (toLocalizationMap M S).lift_injective_iff hg section Map variable {T : Submonoid P} {Q : Type*} [CommSemiring Q] (hy : M ≤ T.comap g) variable [Algebra P Q] [IsLocalization T Q] section variable (Q) /-- Map a homomorphism `g : R →+* P` to `S →+* Q`, where `S` and `Q` are localizations of `R` and `P` at `M` and `T` respectively, such that `g(M) ⊆ T`. We send `z : S` to `algebraMap P Q (g x) * (algebraMap P Q (g y))⁻¹`, where `(x, y) : R × M` are such that `z = f x * (f y)⁻¹`. -/ noncomputable def map (g : R →+* P) (hy : M ≤ T.comap g) : S →+* Q := lift (M := M) (g := (algebraMap P Q).comp g) fun y => map_units _ ⟨g y, hy y.2⟩ end -- Porting note: added `simp` attribute, since it proves very similar lemmas marked `simp` @[simp] theorem map_eq (x) : map Q g hy ((algebraMap R S) x) = algebraMap P Q (g x) := lift_eq (fun y => map_units _ ⟨g y, hy y.2⟩) x @[simp] theorem map_comp : (map Q g hy).comp (algebraMap R S) = (algebraMap P Q).comp g := lift_comp fun y => map_units _ ⟨g y, hy y.2⟩ theorem map_mk' (x) (y : M) : map Q g hy (mk' S x y) = mk' Q (g x) ⟨g y, hy y.2⟩ := Submonoid.LocalizationMap.map_mk' (toLocalizationMap M S) (g := g.toMonoidHom) (fun y => hy y.2) (k := toLocalizationMap T Q) .. @[simp] theorem map_id_mk' {Q : Type*} [CommSemiring Q] [Algebra R Q] [IsLocalization M Q] (x) (y : M) : map Q (RingHom.id R) (le_refl M) (mk' S x y) = mk' Q x y := map_mk' .. @[simp] theorem map_id (z : S) (h : M ≤ M.comap (RingHom.id R) := le_refl M) : map S (RingHom.id _) h z = z := lift_id _ theorem map_unique (j : S →+* Q) (hj : ∀ x : R, j (algebraMap R S x) = algebraMap P Q (g x)) : map Q g hy = j := lift_unique (fun y => map_units _ ⟨g y, hy y.2⟩) hj /-- If `CommSemiring` homs `g : R →+* P, l : P →+* A` induce maps of localizations, the composition of the induced maps equals the map of localizations induced by `l ∘ g`. -/ theorem map_comp_map {A : Type*} [CommSemiring A] {U : Submonoid A} {W} [CommSemiring W] [Algebra A W] [IsLocalization U W] {l : P →+* A} (hl : T ≤ U.comap l) : (map W l hl).comp (map Q g hy : S →+* _) = map W (l.comp g) fun _ hx => hl (hy hx) := RingHom.ext fun x => Submonoid.LocalizationMap.map_map (P := P) (toLocalizationMap M S) (fun y => hy y.2) (toLocalizationMap U W) (fun w => hl w.2) x /-- If `CommSemiring` homs `g : R →+* P, l : P →+* A` induce maps of localizations, the composition of the induced maps equals the map of localizations induced by `l ∘ g`. -/ theorem map_map {A : Type*} [CommSemiring A] {U : Submonoid A} {W} [CommSemiring W] [Algebra A W] [IsLocalization U W] {l : P →+* A} (hl : T ≤ U.comap l) (x : S) : map W l hl (map Q g hy x) = map W (l.comp g) (fun x hx => hl (hy hx)) x := by rw [← map_comp_map (Q := Q) hy hl]; rfl theorem map_smul (x : S) (z : R) : map Q g hy (z • x : S) = g z • map Q g hy x := by rw [Algebra.smul_def, Algebra.smul_def, RingHom.map_mul, map_eq] section variable (S Q) /-- If `S`, `Q` are localizations of `R` and `P` at submonoids `M, T` respectively, an isomorphism `j : R ≃+* P` such that `j(M) = T` induces an isomorphism of localizations `S ≃+* Q`. -/ @[simps] noncomputable def ringEquivOfRingEquiv (h : R ≃+* P) (H : M.map h.toMonoidHom = T) : S ≃+* Q := have H' : T.map h.symm.toMonoidHom = M := by rw [← M.map_id, ← H, Submonoid.map_map] congr ext apply h.symm_apply_apply { map Q (h : R →+* P) (M.le_comap_of_map_le (le_of_eq H)) with toFun := map Q (h : R →+* P) (M.le_comap_of_map_le (le_of_eq H)) invFun := map S (h.symm : P →+* R) (T.le_comap_of_map_le (le_of_eq H')) left_inv := fun x => by rw [map_map, map_unique _ (RingHom.id _), RingHom.id_apply] simp right_inv := fun x => by rw [map_map, map_unique _ (RingHom.id _), RingHom.id_apply] simp } end theorem ringEquivOfRingEquiv_eq_map {j : R ≃+* P} (H : M.map j.toMonoidHom = T) : (ringEquivOfRingEquiv S Q j H : S →+* Q) = map Q (j : R →+* P) (M.le_comap_of_map_le (le_of_eq H)) := rfl -- Porting note (#10618): removed `simp`, `simp` can prove it theorem ringEquivOfRingEquiv_eq {j : R ≃+* P} (H : M.map j.toMonoidHom = T) (x) : ringEquivOfRingEquiv S Q j H ((algebraMap R S) x) = algebraMap P Q (j x) := by simp theorem ringEquivOfRingEquiv_mk' {j : R ≃+* P} (H : M.map j.toMonoidHom = T) (x : R) (y : M) : ringEquivOfRingEquiv S Q j H (mk' S x y) = mk' Q (j x) ⟨j y, show j y ∈ T from H ▸ Set.mem_image_of_mem j y.2⟩ := by simp [map_mk'] end Map section AlgEquiv variable {Q : Type*} [CommSemiring Q] [Algebra R Q] [IsLocalization M Q] section variable (M S Q) /-- If `S`, `Q` are localizations of `R` at the submonoid `M` respectively, there is an isomorphism of localizations `S ≃ₐ[R] Q`. -/ @[simps!] noncomputable def algEquiv : S ≃ₐ[R] Q := { ringEquivOfRingEquiv S Q (RingEquiv.refl R) M.map_id with commutes' := ringEquivOfRingEquiv_eq _ } end -- Porting note (#10618): removed `simp`, `simp` can prove it theorem algEquiv_mk' (x : R) (y : M) : algEquiv M S Q (mk' S x y) = mk' Q x y := by simp -- Porting note (#10618): removed `simp`, `simp` can prove it theorem algEquiv_symm_mk' (x : R) (y : M) : (algEquiv M S Q).symm (mk' Q x y) = mk' S x y := by simp variable (M) in protected lemma bijective (f : S →+* Q) (hf : f.comp (algebraMap R S) = algebraMap R Q) : Function.Bijective f := (show f = IsLocalization.algEquiv M S Q by apply IsLocalization.ringHom_ext M; rw [hf]; ext; simp) ▸ (IsLocalization.algEquiv M S Q).toEquiv.bijective end AlgEquiv section at_units lemma at_units {R : Type*} [CommSemiring R] (S : Submonoid R) (hS : S ≤ IsUnit.submonoid R) : IsLocalization S R where map_units' y := hS y.prop surj' := fun s ↦ ⟨⟨s, 1⟩, by simp⟩ exists_of_eq := fun {x y} (e : x = y) ↦ ⟨1, e ▸ rfl⟩ variable (R M) /-- The localization at a module of units is isomorphic to the ring. -/ noncomputable def atUnits (H : M ≤ IsUnit.submonoid R) : R ≃ₐ[R] S := by refine AlgEquiv.ofBijective (Algebra.ofId R S) ⟨?_, ?_⟩ · intro x y hxy obtain ⟨c, eq⟩ := (IsLocalization.eq_iff_exists M S).mp hxy obtain ⟨u, hu⟩ := H c.prop rwa [← hu, Units.mul_right_inj] at eq · intro y obtain ⟨⟨x, s⟩, eq⟩ := IsLocalization.surj M y obtain ⟨u, hu⟩ := H s.prop use x * u.inv dsimp [Algebra.ofId, RingHom.toFun_eq_coe, AlgHom.coe_mks] rw [RingHom.map_mul, ← eq, ← hu, mul_assoc, ← RingHom.map_mul] simp end at_units section variable (M S) (Q : Type*) [CommSemiring Q] [Algebra P Q] /-- Injectivity of a map descends to the map induced on localizations. -/ theorem map_injective_of_injective (h : Function.Injective g) [IsLocalization (M.map g) Q] : Function.Injective (map Q g M.le_comap_map : S → Q) := (toLocalizationMap M S).map_injective_of_injective h (toLocalizationMap (M.map g) Q) /-- Surjectivity of a map descends to the map induced on localizations. -/ theorem map_surjective_of_surjective (h : Function.Surjective g) [IsLocalization (M.map g) Q] : Function.Surjective (map Q g M.le_comap_map : S → Q) := (toLocalizationMap M S).map_surjective_of_surjective h (toLocalizationMap (M.map g) Q) end end IsLocalization section variable (M) {S} theorem isLocalization_of_algEquiv [Algebra R P] [IsLocalization M S] (h : S ≃ₐ[R] P) : IsLocalization M P := by constructor · intro y convert (IsLocalization.map_units S y).map h.toAlgHom.toRingHom.toMonoidHom exact (h.commutes y).symm · intro y obtain ⟨⟨x, s⟩, e⟩ := IsLocalization.surj M (h.symm y) apply_fun (show S → P from h) at e simp only [map_mul, h.apply_symm_apply, h.commutes] at e exact ⟨⟨x, s⟩, e⟩ · intro x y rw [← h.symm.toEquiv.injective.eq_iff, ← IsLocalization.eq_iff_exists M S, ← h.symm.commutes, ← h.symm.commutes] exact id theorem isLocalization_iff_of_algEquiv [Algebra R P] (h : S ≃ₐ[R] P) : IsLocalization M S ↔ IsLocalization M P := ⟨fun _ => isLocalization_of_algEquiv M h, fun _ => isLocalization_of_algEquiv M h.symm⟩ theorem isLocalization_iff_of_ringEquiv (h : S ≃+* P) : IsLocalization M S ↔ haveI := (h.toRingHom.comp <| algebraMap R S).toAlgebra; IsLocalization M P := letI := (h.toRingHom.comp <| algebraMap R S).toAlgebra isLocalization_iff_of_algEquiv M { h with commutes' := fun _ => rfl } variable (S) theorem isLocalization_of_base_ringEquiv [IsLocalization M S] (h : R ≃+* P) : haveI := ((algebraMap R S).comp h.symm.toRingHom).toAlgebra IsLocalization (M.map h.toMonoidHom) S := by letI : Algebra P S := ((algebraMap R S).comp h.symm.toRingHom).toAlgebra constructor · rintro ⟨_, ⟨y, hy, rfl⟩⟩ convert IsLocalization.map_units S ⟨y, hy⟩ dsimp only [RingHom.algebraMap_toAlgebra, RingHom.comp_apply] exact congr_arg _ (h.symm_apply_apply _) · intro y obtain ⟨⟨x, s⟩, e⟩ := IsLocalization.surj M y refine ⟨⟨h x, _, _, s.prop, rfl⟩, ?_⟩ dsimp only [RingHom.algebraMap_toAlgebra, RingHom.comp_apply] at e ⊢ convert e <;> exact h.symm_apply_apply _ · intro x y rw [RingHom.algebraMap_toAlgebra, RingHom.comp_apply, RingHom.comp_apply, IsLocalization.eq_iff_exists M S] simp_rw [← h.toEquiv.apply_eq_iff_eq] change (∃ c : M, h (c * h.symm x) = h (c * h.symm y)) → _ simp only [RingEquiv.apply_symm_apply, RingEquiv.map_mul] exact fun ⟨c, e⟩ ↦ ⟨⟨_, _, c.prop, rfl⟩, e⟩ theorem isLocalization_iff_of_base_ringEquiv (h : R ≃+* P) : IsLocalization M S ↔ haveI := ((algebraMap R S).comp h.symm.toRingHom).toAlgebra IsLocalization (M.map h.toMonoidHom) S := by letI : Algebra P S := ((algebraMap R S).comp h.symm.toRingHom).toAlgebra refine ⟨fun _ => isLocalization_of_base_ringEquiv M S h, ?_⟩ intro H convert isLocalization_of_base_ringEquiv (Submonoid.map (RingEquiv.toMonoidHom h) M) S h.symm · erw [Submonoid.map_equiv_eq_comap_symm, Submonoid.comap_map_eq_of_injective] exact h.toEquiv.injective rw [RingHom.algebraMap_toAlgebra, RingHom.comp_assoc] simp only [RingHom.comp_id, RingEquiv.symm_symm, RingEquiv.symm_toRingHom_comp_toRingHom] apply Algebra.algebra_ext intro r rw [RingHom.algebraMap_toAlgebra] end variable (M) theorem nonZeroDivisors_le_comap [IsLocalization M S] : nonZeroDivisors R ≤ (nonZeroDivisors S).comap (algebraMap R S) := by rintro a ha b (e : b * algebraMap R S a = 0) obtain ⟨x, s, rfl⟩ := mk'_surjective M b rw [← @mk'_one R _ M, ← mk'_mul, ← (algebraMap R S).map_zero, ← @mk'_one R _ M, IsLocalization.eq] at e obtain ⟨c, e⟩ := e rw [mul_zero, mul_zero, Submonoid.coe_one, one_mul, ← mul_assoc] at e rw [mk'_eq_zero_iff] exact ⟨c, ha _ e⟩ theorem map_nonZeroDivisors_le [IsLocalization M S] : (nonZeroDivisors R).map (algebraMap R S) ≤ nonZeroDivisors S := Submonoid.map_le_iff_le_comap.mpr (nonZeroDivisors_le_comap M S) end IsLocalization namespace Localization open IsLocalization /-! ### Constructing a localization at a given submonoid -/ section instance instUniqueLocalization [Subsingleton R] : Unique (Localization M) where uniq a := by with_unfolding_all show a = mk 1 1 exact Localization.induction_on a fun _ => by congr <;> apply Subsingleton.elim theorem add_mk (a b c d) : (mk a b : Localization M) + mk c d = mk ((b : R) * c + (d : R) * a) (b * d) := by rw [add_comm (b * c) (d * a), mul_comm b d] exact OreLocalization.oreDiv_add_oreDiv theorem add_mk_self (a b c) : (mk a b : Localization M) + mk c b = mk (a + c) b := by rw [add_mk, mk_eq_mk_iff, r_eq_r'] refine (r' M).symm ⟨1, ?_⟩ simp only [Submonoid.coe_one, Submonoid.coe_mul] ring /-- For any given denominator `b : M`, the map `a ↦ a / b` is an `AddMonoidHom` from `R` to `Localization M`-/ @[simps] def mkAddMonoidHom (b : M) : R →+ Localization M where toFun a := mk a b map_zero' := mk_zero _ map_add' _ _ := (add_mk_self _ _ _).symm theorem mk_sum {ι : Type*} (f : ι → R) (s : Finset ι) (b : M) : mk (∑ i ∈ s, f i) b = ∑ i ∈ s, mk (f i) b := map_sum (mkAddMonoidHom b) f s theorem mk_list_sum (l : List R) (b : M) : mk l.sum b = (l.map fun a => mk a b).sum := map_list_sum (mkAddMonoidHom b) l theorem mk_multiset_sum (l : Multiset R) (b : M) : mk l.sum b = (l.map fun a => mk a b).sum := (mkAddMonoidHom b).map_multiset_sum l instance isLocalization : IsLocalization M (Localization M) where map_units' := (Localization.monoidOf M).map_units surj' := (Localization.monoidOf M).surj exists_of_eq := (Localization.monoidOf M).eq_iff_exists.mp end @[simp] theorem toLocalizationMap_eq_monoidOf : toLocalizationMap M (Localization M) = monoidOf M := rfl theorem monoidOf_eq_algebraMap (x) : (monoidOf M).toMap x = algebraMap R (Localization M) x := rfl theorem mk_one_eq_algebraMap (x) : mk x 1 = algebraMap R (Localization M) x := rfl theorem mk_eq_mk'_apply (x y) : mk x y = IsLocalization.mk' (Localization M) x y := by rw [mk_eq_monoidOf_mk'_apply, mk', toLocalizationMap_eq_monoidOf] -- Porting note: removed `simp`. Left hand side can be simplified; not clear what normal form should --be. theorem mk_eq_mk' : (mk : R → M → Localization M) = IsLocalization.mk' (Localization M) := mk_eq_monoidOf_mk' theorem mk_algebraMap {A : Type*} [CommSemiring A] [Algebra A R] (m : A) : mk (algebraMap A R m) 1 = algebraMap A (Localization M) m := by rw [mk_eq_mk', mk'_eq_iff_eq_mul, Submonoid.coe_one, map_one, mul_one]; rfl theorem mk_natCast (m : ℕ) : (mk m 1 : Localization M) = m := by simpa using mk_algebraMap (R := R) (A := ℕ) _ @[deprecated (since := "2024-04-17")] alias mk_nat_cast := mk_natCast variable [IsLocalization M S] section variable (M) /-- The localization of `R` at `M` as a quotient type is isomorphic to any other localization. -/ @[simps!] noncomputable def algEquiv : Localization M ≃ₐ[R] S := IsLocalization.algEquiv M _ _ /-- The localization of a singleton is a singleton. Cannot be an instance due to metavariables. -/ noncomputable def _root_.IsLocalization.unique (R Rₘ) [CommSemiring R] [CommSemiring Rₘ] (M : Submonoid R) [Subsingleton R] [Algebra R Rₘ] [IsLocalization M Rₘ] : Unique Rₘ := have : Inhabited Rₘ := ⟨1⟩ (algEquiv M Rₘ).symm.injective.unique end -- Porting note (#10618): removed `simp`, `simp` can prove it nonrec theorem algEquiv_mk' (x : R) (y : M) : algEquiv M S (mk' (Localization M) x y) = mk' S x y := algEquiv_mk' _ _ -- Porting note (#10618): removed `simp`, `simp` can prove it nonrec theorem algEquiv_symm_mk' (x : R) (y : M) : (algEquiv M S).symm (mk' S x y) = mk' (Localization M) x y := algEquiv_symm_mk' _ _ theorem algEquiv_mk (x y) : algEquiv M S (mk x y) = mk' S x y := by rw [mk_eq_mk', algEquiv_mk'] theorem algEquiv_symm_mk (x : R) (y : M) : (algEquiv M S).symm (mk' S x y) = mk x y := by rw [mk_eq_mk', algEquiv_symm_mk'] lemma coe_algEquiv : (Localization.algEquiv M S : Localization M →+* S) = IsLocalization.map (M := M) (T := M) _ (RingHom.id R) le_rfl := rfl lemma coe_algEquiv_symm : ((Localization.algEquiv M S).symm : S →+* Localization M) = IsLocalization.map (M := M) (T := M) _ (RingHom.id R) le_rfl := rfl end Localization end CommSemiring section CommRing variable {R : Type*} [CommRing R] {M : Submonoid R} (S : Type*) [CommRing S] variable [Algebra R S] {P : Type*} [CommRing P] namespace Localization theorem neg_mk (a b) : -(mk a b : Localization M) = mk (-a) b := OreLocalization.neg_def _ _ theorem sub_mk (a c) (b d) : (mk a b : Localization M) - mk c d = mk ((d : R) * a - b * c) (b * d) := by rw [sub_eq_add_neg, neg_mk, add_mk, add_comm, mul_neg, ← sub_eq_add_neg] theorem mk_intCast (m : ℤ) : (mk m 1 : Localization M) = m := by simpa using mk_algebraMap (R := R) (A := ℤ) _ @[deprecated (since := "2024-04-17")] alias mk_int_cast := mk_intCast end Localization namespace IsLocalization variable {K : Type*} [IsLocalization M S] theorem to_map_eq_zero_iff {x : R} (hM : M ≤ nonZeroDivisors R) : algebraMap R S x = 0 ↔ x = 0 := by rw [← (algebraMap R S).map_zero] constructor <;> intro h · cases' (eq_iff_exists M S).mp h with c hc rw [mul_zero, mul_comm] at hc exact hM c.2 x hc · rw [h] protected theorem injective (hM : M ≤ nonZeroDivisors R) : Injective (algebraMap R S) := by rw [injective_iff_map_eq_zero (algebraMap R S)] intro a ha rwa [to_map_eq_zero_iff S hM] at ha protected theorem to_map_ne_zero_of_mem_nonZeroDivisors [Nontrivial R] (hM : M ≤ nonZeroDivisors R) {x : R} (hx : x ∈ nonZeroDivisors R) : algebraMap R S x ≠ 0 := show (algebraMap R S).toMonoidWithZeroHom x ≠ 0 from map_ne_zero_of_mem_nonZeroDivisors (algebraMap R S) (IsLocalization.injective S hM) hx variable {S} theorem sec_snd_ne_zero [Nontrivial R] (hM : M ≤ nonZeroDivisors R) (x : S) : ((sec M x).snd : R) ≠ 0 := nonZeroDivisors.coe_ne_zero ⟨(sec M x).snd.val, hM (sec M x).snd.property⟩ theorem sec_fst_ne_zero [Nontrivial R] [NoZeroDivisors S] (hM : M ≤ nonZeroDivisors R) {x : S} (hx : x ≠ 0) : (sec M x).fst ≠ 0 := by have hsec := sec_spec M x intro hfst rw [hfst, map_zero, mul_eq_zero, _root_.map_eq_zero_iff] at hsec · exact Or.elim hsec hx (sec_snd_ne_zero hM x) · exact IsLocalization.injective S hM variable {Q : Type*} [CommRing Q] {g : R →+* P} [Algebra P Q] variable (A : Type*) [CommRing A] [IsDomain A] /-- A `CommRing` `S` which is the localization of a ring `R` without zero divisors at a subset of non-zero elements does not have zero divisors. -/ theorem noZeroDivisors_of_le_nonZeroDivisors [Algebra A S] {M : Submonoid A} [IsLocalization M S] (hM : M ≤ nonZeroDivisors A) : NoZeroDivisors S := { eq_zero_or_eq_zero_of_mul_eq_zero := by intro z w h cases' surj M z with x hx cases' surj M w with y hy have : z * w * algebraMap A S y.2 * algebraMap A S x.2 = algebraMap A S x.1 * algebraMap A S y.1 := by rw [mul_assoc z, hy, ← hx]; ring rw [h, zero_mul, zero_mul, ← (algebraMap A S).map_mul] at this cases' eq_zero_or_eq_zero_of_mul_eq_zero ((to_map_eq_zero_iff S hM).mp this.symm) with H H · exact Or.inl (eq_zero_of_fst_eq_zero hx H) · exact Or.inr (eq_zero_of_fst_eq_zero hy H) } /-- A `CommRing` `S` which is the localization of an integral domain `R` at a subset of non-zero elements is an integral domain. -/ theorem isDomain_of_le_nonZeroDivisors [Algebra A S] {M : Submonoid A} [IsLocalization M S] (hM : M ≤ nonZeroDivisors A) : IsDomain S := by apply @NoZeroDivisors.to_isDomain _ _ (id _) (id _) · exact ⟨⟨(algebraMap A S) 0, (algebraMap A S) 1, fun h => zero_ne_one (IsLocalization.injective S hM h)⟩⟩ · exact noZeroDivisors_of_le_nonZeroDivisors _ hM variable {A} /-- The localization of an integral domain to a set of non-zero elements is an integral domain. -/ theorem isDomain_localization {M : Submonoid A} (hM : M ≤ nonZeroDivisors A) : IsDomain (Localization M) := isDomain_of_le_nonZeroDivisors _ hM end IsLocalization open IsLocalization /-- If `R` is a field, then localizing at a submonoid not containing `0` adds no new elements. -/ theorem IsField.localization_map_bijective {R Rₘ : Type*} [CommRing R] [CommRing Rₘ] {M : Submonoid R} (hM : (0 : R) ∉ M) (hR : IsField R) [Algebra R Rₘ] [IsLocalization M Rₘ] : Function.Bijective (algebraMap R Rₘ) := by letI := hR.toField replace hM := le_nonZeroDivisors_of_noZeroDivisors hM refine ⟨IsLocalization.injective _ hM, fun x => ?_⟩ obtain ⟨r, ⟨m, hm⟩, rfl⟩ := mk'_surjective M x obtain ⟨n, hn⟩ := hR.mul_inv_cancel (nonZeroDivisors.ne_zero <| hM hm) exact ⟨r * n, by erw [eq_mk'_iff_mul_eq, ← map_mul, mul_assoc, _root_.mul_comm n, hn, mul_one]⟩ /-- If `R` is a field, then localizing at a submonoid not containing `0` adds no new elements. -/ theorem Field.localization_map_bijective {K Kₘ : Type*} [Field K] [CommRing Kₘ] {M : Submonoid K} (hM : (0 : K) ∉ M) [Algebra K Kₘ] [IsLocalization M Kₘ] : Function.Bijective (algebraMap K Kₘ) := (Field.toIsField K).localization_map_bijective hM -- this looks weird due to the `letI` inside the above lemma, but trying to do it the other -- way round causes issues with defeq of instances, so this is actually easier. section Algebra variable {S} {Rₘ Sₘ : Type*} [CommRing Rₘ] [CommRing Sₘ] variable [Algebra R Rₘ] [IsLocalization M Rₘ] variable [Algebra S Sₘ] [i : IsLocalization (Algebra.algebraMapSubmonoid S M) Sₘ] section variable (S M) /-- Definition of the natural algebra induced by the localization of an algebra. Given an algebra `R → S`, a submonoid `R` of `M`, and a localization `Rₘ` for `M`, let `Sₘ` be the localization of `S` to the image of `M` under `algebraMap R S`. Then this is the natural algebra structure on `Rₘ → Sₘ`, such that the entire square commutes, where `localization_map.map_comp` gives the commutativity of the underlying maps. This instance can be helpful if you define `Sₘ := Localization (Algebra.algebraMapSubmonoid S M)`, however we will instead use the hypotheses `[Algebra Rₘ Sₘ] [IsScalarTower R Rₘ Sₘ]` in lemmas since the algebra structure may arise in different ways. -/ noncomputable def localizationAlgebra : Algebra Rₘ Sₘ := (map Sₘ (algebraMap R S) (show _ ≤ (Algebra.algebraMapSubmonoid S M).comap _ from M.le_comap_map) : Rₘ →+* Sₘ).toAlgebra end section variable [Algebra Rₘ Sₘ] [Algebra R Sₘ] [IsScalarTower R Rₘ Sₘ] [IsScalarTower R S Sₘ] variable (S Rₘ Sₘ) theorem IsLocalization.map_units_map_submonoid [IsLocalization (Algebra.algebraMapSubmonoid S M) Sₘ] (y : M) : IsUnit (algebraMap R Sₘ y) := by rw [IsScalarTower.algebraMap_apply _ S] exact IsLocalization.map_units Sₘ ⟨algebraMap R S y, Algebra.mem_algebraMapSubmonoid_of_mem y⟩ -- can't be simp, as `S` only appears on the RHS theorem IsLocalization.algebraMap_mk' (x : R) (y : M) : algebraMap Rₘ Sₘ (IsLocalization.mk' Rₘ x y) = IsLocalization.mk' Sₘ (algebraMap R S x) ⟨algebraMap R S y, Algebra.mem_algebraMapSubmonoid_of_mem y⟩ := by rw [IsLocalization.eq_mk'_iff_mul_eq, Subtype.coe_mk, ← IsScalarTower.algebraMap_apply, ← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R Rₘ Sₘ, IsScalarTower.algebraMap_apply R Rₘ Sₘ, ← _root_.map_mul, mul_comm, IsLocalization.mul_mk'_eq_mk'_of_mul] exact congr_arg (algebraMap Rₘ Sₘ) (IsLocalization.mk'_mul_cancel_left x y) variable (M) /-- If the square below commutes, the bottom map is uniquely specified: ``` R → S ↓ ↓ Rₘ → Sₘ ``` -/ theorem IsLocalization.algebraMap_eq_map_map_submonoid : algebraMap Rₘ Sₘ = map Sₘ (algebraMap R S) (show _ ≤ (Algebra.algebraMapSubmonoid S M).comap _ from M.le_comap_map) := Eq.symm <| IsLocalization.map_unique _ (algebraMap Rₘ Sₘ) fun x => by rw [← IsScalarTower.algebraMap_apply R S Sₘ, ← IsScalarTower.algebraMap_apply R Rₘ Sₘ] /-- If the square below commutes, the bottom map is uniquely specified: ``` R → S ↓ ↓ Rₘ → Sₘ ``` -/ theorem IsLocalization.algebraMap_apply_eq_map_map_submonoid (x) : algebraMap Rₘ Sₘ x = map Sₘ (algebraMap R S) (show _ ≤ (Algebra.algebraMapSubmonoid S M).comap _ from M.le_comap_map) x := DFunLike.congr_fun (IsLocalization.algebraMap_eq_map_map_submonoid _ _ _ _) x theorem IsLocalization.lift_algebraMap_eq_algebraMap : IsLocalization.lift (M := M) (IsLocalization.map_units_map_submonoid S Sₘ) = algebraMap Rₘ Sₘ := IsLocalization.lift_unique _ fun _ => (IsScalarTower.algebraMap_apply _ _ _ _).symm end variable (Rₘ Sₘ) /-- Injectivity of the underlying `algebraMap` descends to the algebra induced by localization. -/ theorem localizationAlgebra_injective (hRS : Function.Injective (algebraMap R S)) : Function.Injective (@algebraMap Rₘ Sₘ _ _ (localizationAlgebra M S)) := have : IsLocalization (M.map (algebraMap R S)) Sₘ := i IsLocalization.map_injective_of_injective _ _ _ hRS end Algebra end CommRing
RingTheory\Localization\Cardinality.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.SetTheory.Cardinal.Ordinal import Mathlib.RingTheory.Artinian /-! # Cardinality of localizations In this file, we establish the cardinality of localizations. In most cases, a localization has cardinality equal to the base ring. If there are zero-divisors, however, this is no longer true - for example, `ZMod 6` localized at `{2, 4}` is equal to `ZMod 3`, and if you have zero in your submonoid, then your localization is trivial (see `IsLocalization.uniqueOfZeroMem`). ## Main statements * `IsLocalization.card_le`: A localization has cardinality no larger than the base ring. * `IsLocalization.card`: If you don't localize at zero-divisors, the localization of a ring has cardinality equal to its base ring, -/ open Cardinal nonZeroDivisors universe u v namespace IsLocalization variable {R : Type u} [CommRing R] {L : Type u} [CommRing L] [Algebra R L] /-- A localization always has cardinality less than or equal to the base ring. -/ theorem card_le (S : Submonoid R) [IsLocalization S L] : #L ≤ #R := by classical cases fintypeOrInfinite R · exact Cardinal.mk_le_of_surjective (IsArtinianRing.localization_surjective S _) erw [← Cardinal.mul_eq_self <| Cardinal.aleph0_le_mk R] set f : R × R → L := fun aa => IsLocalization.mk' _ aa.1 (if h : aa.2 ∈ S then ⟨aa.2, h⟩ else 1) refine @Cardinal.mk_le_of_surjective _ _ f fun a => ?_ obtain ⟨x, y, h⟩ := IsLocalization.mk'_surjective S a use (x, y) dsimp [f] rwa [dif_pos <| show ↑y ∈ S from y.2, SetLike.eta] variable (L) /-- If you do not localize at any zero-divisors, localization preserves cardinality. -/ theorem card (S : Submonoid R) [IsLocalization S L] (hS : S ≤ R⁰) : #R = #L := (Cardinal.mk_le_of_injective (IsLocalization.injective L hS)).antisymm (card_le S) end IsLocalization
RingTheory\Localization\Finiteness.lean
/- Copyright (c) 2024 Christian Merten. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christian Merten -/ import Mathlib.Algebra.Module.LocalizedModuleIntegers import Mathlib.RingTheory.Localization.Algebra import Mathlib.RingTheory.LocalProperties /-! # Finiteness properties under localization In this file we establish behaviour of `Module.Finite` under localizations. ## Main results - `Module.Finite.of_isLocalizedModule`: If `M` is a finite `R`-module, `S` is a submonoid of `R`, `Rₚ` is the localization of `R` at `S` and `Mₚ` is the localization of `M` at `S`, then `Mₚ` is a finite `Rₚ`-module. - `Module.Finite.of_localizationSpan_finite`: If `M` is an `R`-module and `{ r }` is a finite set generating the unit ideal such that `Mᵣ` is a finite `Rᵣ`-module for each `r`, then `M` is a finite `R`-module. -/ universe u v w t namespace Module.Finite section variable {R : Type u} [CommSemiring R] (S : Submonoid R) variable {Rₚ : Type v} [CommSemiring Rₚ] [Algebra R Rₚ] [IsLocalization S Rₚ] variable {M : Type w} [AddCommMonoid M] [Module R M] variable {Mₚ : Type t} [AddCommMonoid Mₚ] [Module R Mₚ] [Module Rₚ Mₚ] [IsScalarTower R Rₚ Mₚ] variable (f : M →ₗ[R] Mₚ) [IsLocalizedModule S f] lemma of_isLocalizedModule [Module.Finite R M] : Module.Finite Rₚ Mₚ := by classical obtain ⟨T, hT⟩ := ‹Module.Finite R M› use T.image f rw [eq_top_iff] rintro x - obtain ⟨⟨y, m⟩, (hyx : IsLocalizedModule.mk' f y m = x)⟩ := IsLocalizedModule.mk'_surjective S f x have hy : y ∈ Submodule.span R T := by rw [hT]; trivial have : f y ∈ Submodule.map f (Submodule.span R T) := Submodule.mem_map_of_mem hy rw [Submodule.map_span] at this have H : Submodule.span R (f '' T) ≤ (Submodule.span Rₚ (f '' T)).restrictScalars R := by rw [Submodule.span_le]; exact Submodule.subset_span convert (Submodule.span Rₚ (f '' T)).smul_mem (IsLocalization.mk' Rₚ (1 : R) m) (H this) using 1 · rw [← hyx, ← IsLocalizedModule.mk'_one S, IsLocalizedModule.mk'_smul_mk'] simp · simp end variable {R : Type u} [CommRing R] (S : Submonoid R) {M : Type w} [AddCommMonoid M] [Module R M] /-- If there exists a finite set `{ r }` of `R` such that `Mᵣ` is `Rᵣ`-finite for each `r`, then `M` is a finite `R`-module. General version for any modules `Mᵣ` and rings `Rᵣ` satisfying the correct universal properties. See `Module.Finite.of_localizationSpan_finite` for the specialized version. See `of_localizationSpan'` for a version without the finite set assumption. -/ theorem of_localizationSpan_finite' (t : Finset R) (ht : Ideal.span (t : Set R) = ⊤) {Mₚ : ∀ (_ : t), Type*} [∀ (g : t), AddCommMonoid (Mₚ g)] [∀ (g : t), Module R (Mₚ g)] {Rₚ : ∀ (_ : t), Type u} [∀ (g : t), CommRing (Rₚ g)] [∀ (g : t), Algebra R (Rₚ g)] [∀ (g : t), IsLocalization.Away g.val (Rₚ g)] [∀ (g : t), Module (Rₚ g) (Mₚ g)] [∀ (g : t), IsScalarTower R (Rₚ g) (Mₚ g)] (f : ∀ (g : t), M →ₗ[R] Mₚ g) [∀ (g : t), IsLocalizedModule (Submonoid.powers g.val) (f g)] (H : ∀ (g : t), Module.Finite (Rₚ g) (Mₚ g)) : Module.Finite R M := by classical constructor choose s₁ s₂ using (fun g ↦ (H g).1) let sf := fun x : t ↦ IsLocalizedModule.finsetIntegerMultiple (Submonoid.powers x.val) (f x) (s₁ x) use t.attach.biUnion sf rw [Submodule.span_attach_biUnion, eq_top_iff] rintro x - refine Submodule.mem_of_span_eq_top_of_smul_pow_mem _ (t : Set R) ht _ (fun r ↦ ?_) set S : Submonoid R := Submonoid.powers r.val obtain ⟨⟨_, n₁, rfl⟩, hn₁⟩ := multiple_mem_span_of_mem_localization_span S (Rₚ r) (s₁ r : Set (Mₚ r)) (IsLocalizedModule.mk' (f r) x (1 : S)) (by rw [s₂ r]; trivial) rw [Submonoid.smul_def, ← IsLocalizedModule.mk'_smul, IsLocalizedModule.mk'_one] at hn₁ obtain ⟨⟨_, n₂, rfl⟩, hn₂⟩ := IsLocalizedModule.smul_mem_finsetIntegerMultiple_span S (f r) _ (s₁ r) hn₁ rw [Submonoid.smul_def] at hn₂ use n₂ + n₁ apply le_iSup (fun x : t ↦ Submodule.span R (sf x : Set M)) r rw [pow_add, mul_smul] exact hn₂ /-- If there exists a set `{ r }` of `R` such that `Mᵣ` is `Rᵣ`-finite for each `r`, then `M` is a finite `R`-module. General version for any modules `Mᵣ` and rings `Rᵣ` satisfying the correct universal properties. See `Module.Finite.of_localizationSpan_finite` for the specialized version. -/ theorem of_localizationSpan' (t : Set R) (ht : Ideal.span t = ⊤) {Mₚ : ∀ (_ : t), Type*} [∀ (g : t), AddCommMonoid (Mₚ g)] [∀ (g : t), Module R (Mₚ g)] {Rₚ : ∀ (_ : t), Type u} [∀ (g : t), CommRing (Rₚ g)] [∀ (g : t), Algebra R (Rₚ g)] [h₁ : ∀ (g : t), IsLocalization.Away g.val (Rₚ g)] [∀ (g : t), Module (Rₚ g) (Mₚ g)] [∀ (g : t), IsScalarTower R (Rₚ g) (Mₚ g)] (f : ∀ (g : t), M →ₗ[R] Mₚ g) [h₂ : ∀ (g : t), IsLocalizedModule (Submonoid.powers g.val) (f g)] (H : ∀ (g : t), Module.Finite (Rₚ g) (Mₚ g)) : Module.Finite R M := by rw [Ideal.span_eq_top_iff_finite] at ht obtain ⟨t', hc, ht'⟩ := ht have (g : t') : IsLocalization.Away g.val (Rₚ ⟨g.val, hc g.property⟩) := h₁ ⟨g.val, hc g.property⟩ have (g : t') : IsLocalizedModule (Submonoid.powers g.val) ((fun g ↦ f ⟨g.val, hc g.property⟩) g) := h₂ ⟨g.val, hc g.property⟩ apply of_localizationSpan_finite' t' ht' (fun g ↦ f ⟨g.val, hc g.property⟩) (fun g ↦ H ⟨g.val, hc g.property⟩) /-- If there exists a finite set `{ r }` of `R` such that `Mᵣ` is `Rᵣ`-finite for each `r`, then `M` is a finite `R`-module. See `of_localizationSpan` for a version without the finite set assumption. -/ theorem of_localizationSpan_finite (t : Finset R) (ht : Ideal.span (t : Set R) = ⊤) (H : ∀ (g : t), Module.Finite (Localization.Away g.val) (LocalizedModule (Submonoid.powers g.val) M)) : Module.Finite R M := let f (g : t) : M →ₗ[R] LocalizedModule (Submonoid.powers g.val) M := LocalizedModule.mkLinearMap (Submonoid.powers g.val) M of_localizationSpan_finite' t ht f H /-- If there exists a set `{ r }` of `R` such that `Mᵣ` is `Rᵣ`-finite for each `r`, then `M` is a finite `R`-module. -/ theorem of_localizationSpan (t : Set R) (ht : Ideal.span t = ⊤) (H : ∀ (g : t), Module.Finite (Localization.Away g.val) (LocalizedModule (Submonoid.powers g.val) M)) : Module.Finite R M := let f (g : t) : M →ₗ[R] LocalizedModule (Submonoid.powers g.val) M := LocalizedModule.mkLinearMap (Submonoid.powers g.val) M of_localizationSpan' t ht f H end Finite end Module namespace Ideal variable {R : Type u} [CommRing R] /-- If `I` is an ideal such that there exists a set `{ r }` of `R` such that the image of `I` in `Rᵣ` is finitely generated for each `r`, then `I` is finitely generated. -/ lemma fg_of_localizationSpan {I : Ideal R} (t : Set R) (ht : Ideal.span t = ⊤) (H : ∀ (g : t), (I.map (algebraMap R (Localization.Away g.val))).FG) : I.FG := by apply Module.Finite.iff_fg.mp let k (g : t) : I →ₗ[R] (I.map (algebraMap R (Localization.Away g.val))) := Algebra.idealMap I (S := Localization.Away g.val) exact Module.Finite.of_localizationSpan' t ht k (fun g ↦ Module.Finite.iff_fg.mpr (H g)) end Ideal variable {R : Type u} [CommRing R] {S : Type v} [CommRing S] {f : R →+* S} /-- To check that the kernel of a ring homomorphism is finitely generated, it suffices to check this after localizing at a spanning set of the source. -/ lemma RingHom.ker_fg_of_localizationSpan (t : Set R) (ht : Ideal.span t = ⊤) (H : ∀ g : t, (RingHom.ker (Localization.awayMap f g.val)).FG) : (RingHom.ker f).FG := by apply Ideal.fg_of_localizationSpan t ht intro g rw [← IsLocalization.ker_map (Localization.Away (f g.val)) f (Submonoid.map_powers f g.val)] exact H g
RingTheory\Localization\FractionRing.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen -/ import Mathlib.Algebra.Algebra.Tower import Mathlib.RingTheory.Localization.Basic import Mathlib.Algebra.Field.Equiv /-! # Fraction ring / fraction field Frac(R) as localization ## Main definitions * `IsFractionRing R K` expresses that `K` is a field of fractions of `R`, as an abbreviation of `IsLocalization (NonZeroDivisors R) K` ## Main results * `IsFractionRing.field`: a definition (not an instance) stating the localization of an integral domain `R` at `R \ {0}` is a field * `Rat.isFractionRing` is an instance stating `ℚ` is the field of fractions of `ℤ` ## Implementation notes See `RingTheory/Localization/Basic.lean` for a design overview. ## Tags localization, ring localization, commutative ring localization, characteristic predicate, commutative ring, field of fractions -/ variable (R : Type*) [CommRing R] {M : Submonoid R} (S : Type*) [CommRing S] variable [Algebra R S] {P : Type*} [CommRing P] variable {A : Type*} [CommRing A] [IsDomain A] (K : Type*) -- TODO: should this extend `Algebra` instead of assuming it? /-- `IsFractionRing R K` states `K` is the field of fractions of an integral domain `R`. -/ abbrev IsFractionRing [CommRing K] [Algebra R K] := IsLocalization (nonZeroDivisors R) K instance {R : Type*} [Field R] : IsFractionRing R R := IsLocalization.at_units _ (fun _ ↦ isUnit_of_mem_nonZeroDivisors) /-- The cast from `Int` to `Rat` as a `FractionRing`. -/ instance Rat.isFractionRing : IsFractionRing ℤ ℚ where map_units' := by rintro ⟨x, hx⟩ rw [mem_nonZeroDivisors_iff_ne_zero] at hx simpa only [eq_intCast, isUnit_iff_ne_zero, Int.cast_eq_zero, Ne, Subtype.coe_mk] using hx surj' := by rintro ⟨n, d, hd, h⟩ refine ⟨⟨n, ⟨d, ?_⟩⟩, Rat.mul_den_eq_num _⟩ rw [mem_nonZeroDivisors_iff_ne_zero, Int.natCast_ne_zero_iff_pos] exact Nat.zero_lt_of_ne_zero hd exists_of_eq {x y} := by rw [eq_intCast, eq_intCast, Int.cast_inj] rintro rfl use 1 namespace IsFractionRing open IsLocalization variable {R K} section CommRing variable [CommRing K] [Algebra R K] [IsFractionRing R K] [Algebra A K] [IsFractionRing A K] theorem to_map_eq_zero_iff {x : R} : algebraMap R K x = 0 ↔ x = 0 := IsLocalization.to_map_eq_zero_iff _ le_rfl variable (R K) protected theorem injective : Function.Injective (algebraMap R K) := IsLocalization.injective _ (le_of_eq rfl) variable {R K} @[norm_cast, simp] -- Porting note: using `↑` didn't work, so I needed to explicitly put in the cast myself theorem coe_inj {a b : R} : (Algebra.cast a : K) = Algebra.cast b ↔ a = b := (IsFractionRing.injective R K).eq_iff instance (priority := 100) [NoZeroDivisors K] : NoZeroSMulDivisors R K := NoZeroSMulDivisors.of_algebraMap_injective <| IsFractionRing.injective R K protected theorem to_map_ne_zero_of_mem_nonZeroDivisors [Nontrivial R] {x : R} (hx : x ∈ nonZeroDivisors R) : algebraMap R K x ≠ 0 := IsLocalization.to_map_ne_zero_of_mem_nonZeroDivisors _ le_rfl hx variable (A) /-- A `CommRing` `K` which is the localization of an integral domain `R` at `R - {0}` is an integral domain. -/ protected theorem isDomain : IsDomain K := isDomain_of_le_nonZeroDivisors _ (le_refl (nonZeroDivisors A)) /-- The inverse of an element in the field of fractions of an integral domain. -/ protected noncomputable irreducible_def inv (z : K) : K := open scoped Classical in if h : z = 0 then 0 else mk' K ↑(sec (nonZeroDivisors A) z).2 ⟨(sec _ z).1, mem_nonZeroDivisors_iff_ne_zero.2 fun h0 => h <| eq_zero_of_fst_eq_zero (sec_spec (nonZeroDivisors A) z) h0⟩ protected theorem mul_inv_cancel (x : K) (hx : x ≠ 0) : x * IsFractionRing.inv A x = 1 := by rw [IsFractionRing.inv, dif_neg hx, ← IsUnit.mul_left_inj (map_units K ⟨(sec _ x).1, mem_nonZeroDivisors_iff_ne_zero.2 fun h0 => hx <| eq_zero_of_fst_eq_zero (sec_spec (nonZeroDivisors A) x) h0⟩), one_mul, mul_assoc] rw [mk'_spec, ← eq_mk'_iff_mul_eq] exact (mk'_sec _ x).symm /-- A `CommRing` `K` which is the localization of an integral domain `R` at `R - {0}` is a field. See note [reducible non-instances]. -/ noncomputable abbrev toField : Field K where __ := IsFractionRing.isDomain A mul_inv_cancel := IsFractionRing.mul_inv_cancel A inv_zero := show IsFractionRing.inv A (0 : K) = 0 by rw [IsFractionRing.inv]; exact dif_pos rfl nnqsmul := _ nnqsmul_def := fun q a => rfl qsmul := _ qsmul_def := fun a x => rfl lemma surjective_iff_isField [IsDomain R] : Function.Surjective (algebraMap R K) ↔ IsField R where mp h := (RingEquiv.ofBijective (algebraMap R K) ⟨IsFractionRing.injective R K, h⟩).toMulEquiv.isField (IsFractionRing.toField R).toIsField mpr h := letI := h.toField (IsLocalization.atUnits R _ (S := K) (fun _ hx ↦ Ne.isUnit (mem_nonZeroDivisors_iff_ne_zero.mp hx))).surjective end CommRing variable {B : Type*} [CommRing B] [IsDomain B] [Field K] {L : Type*} [Field L] [Algebra A K] [IsFractionRing A K] {g : A →+* L} theorem mk'_mk_eq_div {r s} (hs : s ∈ nonZeroDivisors A) : mk' K r ⟨s, hs⟩ = algebraMap A K r / algebraMap A K s := mk'_eq_iff_eq_mul.2 <| (div_mul_cancel₀ (algebraMap A K r) (IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors hs)).symm @[simp] theorem mk'_eq_div {r} (s : nonZeroDivisors A) : mk' K r s = algebraMap A K r / algebraMap A K s := mk'_mk_eq_div s.2 theorem div_surjective (z : K) : ∃ x y : A, y ∈ nonZeroDivisors A ∧ algebraMap _ _ x / algebraMap _ _ y = z := let ⟨x, ⟨y, hy⟩, h⟩ := mk'_surjective (nonZeroDivisors A) z ⟨x, y, hy, by rwa [mk'_eq_div] at h⟩ theorem isUnit_map_of_injective (hg : Function.Injective g) (y : nonZeroDivisors A) : IsUnit (g y) := IsUnit.mk0 (g y) <| show g.toMonoidWithZeroHom y ≠ 0 from map_ne_zero_of_mem_nonZeroDivisors g hg y.2 @[simp] theorem mk'_eq_zero_iff_eq_zero [Algebra R K] [IsFractionRing R K] {x : R} {y : nonZeroDivisors R} : mk' K x y = 0 ↔ x = 0 := by refine ⟨fun hxy => ?_, fun h => by rw [h, mk'_zero]⟩ simp_rw [mk'_eq_zero_iff, mul_left_coe_nonZeroDivisors_eq_zero_iff] at hxy exact (exists_const _).mp hxy theorem mk'_eq_one_iff_eq {x : A} {y : nonZeroDivisors A} : mk' K x y = 1 ↔ x = y := by refine ⟨?_, fun hxy => by rw [hxy, mk'_self']⟩ intro hxy have hy : (algebraMap A K) ↑y ≠ (0 : K) := IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors y.property rw [IsFractionRing.mk'_eq_div, div_eq_one_iff_eq hy] at hxy exact IsFractionRing.injective A K hxy open Function /-- Given an integral domain `A` with field of fractions `K`, and an injective ring hom `g : A →+* L` where `L` is a field, we get a field hom sending `z : K` to `g x * (g y)⁻¹`, where `(x, y) : A × (NonZeroDivisors A)` are such that `z = f x * (f y)⁻¹`. -/ noncomputable def lift (hg : Injective g) : K →+* L := IsLocalization.lift fun y : nonZeroDivisors A => isUnit_map_of_injective hg y /-- Given an integral domain `A` with field of fractions `K`, and an injective ring hom `g : A →+* L` where `L` is a field, the field hom induced from `K` to `L` maps `x` to `g x` for all `x : A`. -/ @[simp] theorem lift_algebraMap (hg : Injective g) (x) : lift hg (algebraMap A K x) = g x := lift_eq _ _ /-- Given an integral domain `A` with field of fractions `K`, and an injective ring hom `g : A →+* L` where `L` is a field, field hom induced from `K` to `L` maps `f x / f y` to `g x / g y` for all `x : A, y ∈ NonZeroDivisors A`. -/ theorem lift_mk' (hg : Injective g) (x) (y : nonZeroDivisors A) : lift hg (mk' K x y) = g x / g y := by simp only [mk'_eq_div, map_div₀, lift_algebraMap] /-- Given integral domains `A, B` with fields of fractions `K`, `L` and an injective ring hom `j : A →+* B`, we get a field hom sending `z : K` to `g (j x) * (g (j y))⁻¹`, where `(x, y) : A × (NonZeroDivisors A)` are such that `z = f x * (f y)⁻¹`. -/ noncomputable def map {A B K L : Type*} [CommRing A] [CommRing B] [IsDomain B] [CommRing K] [Algebra A K] [IsFractionRing A K] [CommRing L] [Algebra B L] [IsFractionRing B L] {j : A →+* B} (hj : Injective j) : K →+* L := IsLocalization.map L j (show nonZeroDivisors A ≤ (nonZeroDivisors B).comap j from nonZeroDivisors_le_comap_nonZeroDivisors_of_injective j hj) /-- Given integral domains `A, B` and localization maps to their fields of fractions `f : A →+* K, g : B →+* L`, an isomorphism `j : A ≃+* B` induces an isomorphism of fields of fractions `K ≃+* L`. -/ noncomputable def fieldEquivOfRingEquiv [Algebra B L] [IsFractionRing B L] (h : A ≃+* B) : K ≃+* L := ringEquivOfRingEquiv (M := nonZeroDivisors A) K (T := nonZeroDivisors B) L h (by ext b show b ∈ h.toEquiv '' _ ↔ _ erw [h.toEquiv.image_eq_preimage, Set.preimage, Set.mem_setOf_eq, mem_nonZeroDivisors_iff_ne_zero, mem_nonZeroDivisors_iff_ne_zero] exact h.symm.map_ne_zero_iff) theorem isFractionRing_iff_of_base_ringEquiv (h : R ≃+* P) : IsFractionRing R S ↔ @IsFractionRing P _ S _ ((algebraMap R S).comp h.symm.toRingHom).toAlgebra := by delta IsFractionRing convert isLocalization_iff_of_base_ringEquiv (nonZeroDivisors R) S h ext x erw [Submonoid.map_equiv_eq_comap_symm] simp only [MulEquiv.coe_toMonoidHom, RingEquiv.toMulEquiv_eq_coe, Submonoid.mem_comap] constructor · rintro hx z (hz : z * h.symm x = 0) rw [← h.map_eq_zero_iff] apply hx simpa only [h.map_zero, h.apply_symm_apply, h.map_mul] using congr_arg h hz · rintro (hx : h.symm x ∈ _) z hz rw [← h.symm.map_eq_zero_iff] apply hx rw [← h.symm.map_mul, hz, h.symm.map_zero] protected theorem nontrivial (R S : Type*) [CommRing R] [Nontrivial R] [CommRing S] [Algebra R S] [IsFractionRing R S] : Nontrivial S := by apply nontrivial_of_ne · intro h apply @zero_ne_one R exact IsLocalization.injective S (le_of_eq rfl) (((algebraMap R S).map_zero.trans h).trans (algebraMap R S).map_one.symm) end IsFractionRing variable (A) /-- The fraction ring of a commutative ring `R` as a quotient type. We instantiate this definition as generally as possible, and assume that the commutative ring `R` is an integral domain only when this is needed for proving. In this generality, this construction is also known as the *total fraction ring* of `R`. -/ abbrev FractionRing := Localization (nonZeroDivisors R) namespace FractionRing instance unique [Subsingleton R] : Unique (FractionRing R) := inferInstance instance [Nontrivial R] : Nontrivial (FractionRing R) := inferInstance /-- Porting note: if the fields of this instance are explicitly defined as they were in mathlib3, the last instance in this file suffers a TC timeout -/ noncomputable instance field : Field (FractionRing A) := inferInstance @[simp] theorem mk_eq_div {r s} : (Localization.mk r s : FractionRing A) = (algebraMap _ _ r / algebraMap A _ s : FractionRing A) := by rw [Localization.mk_eq_mk', IsFractionRing.mk'_eq_div] /-- This is not an instance because it creates a diamond when `K = FractionRing R`. Should usually be introduced locally along with `isScalarTower_liftAlgebra` See note [reducible non-instances]. -/ noncomputable abbrev liftAlgebra [IsDomain R] [Field K] [Algebra R K] [NoZeroSMulDivisors R K] : Algebra (FractionRing R) K := RingHom.toAlgebra (IsFractionRing.lift (NoZeroSMulDivisors.algebraMap_injective R _)) -- Porting note: had to fill in the `_` by hand for this instance instance isScalarTower_liftAlgebra [IsDomain R] [Field K] [Algebra R K] [NoZeroSMulDivisors R K] : by letI := liftAlgebra R K; exact IsScalarTower R (FractionRing R) K := by letI := liftAlgebra R K exact IsScalarTower.of_algebraMap_eq fun x => (IsFractionRing.lift_algebraMap (NoZeroSMulDivisors.algebraMap_injective R K) x).symm /-- Given an integral domain `A` and a localization map to a field of fractions `f : A →+* K`, we get an `A`-isomorphism between the field of fractions of `A` as a quotient type and `K`. -/ noncomputable def algEquiv (K : Type*) [Field K] [Algebra A K] [IsFractionRing A K] : FractionRing A ≃ₐ[A] K := Localization.algEquiv (nonZeroDivisors A) K instance [Algebra R A] [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R (FractionRing A) := by apply NoZeroSMulDivisors.of_algebraMap_injective rw [IsScalarTower.algebraMap_eq R A] apply Function.Injective.comp (NoZeroSMulDivisors.algebraMap_injective A (FractionRing A)) (NoZeroSMulDivisors.algebraMap_injective R A) end FractionRing
RingTheory\Localization\Ideal.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen -/ import Mathlib.RingTheory.Ideal.QuotientOperations import Mathlib.RingTheory.Localization.Basic /-! # Ideals in localizations of commutative rings ## Implementation notes See `Mathlib/RingTheory/Localization/Basic.lean` for a design overview. ## Tags localization, ring localization, commutative ring localization, characteristic predicate, commutative ring, field of fractions -/ namespace IsLocalization section CommSemiring variable {R : Type*} [CommSemiring R] (M : Submonoid R) (S : Type*) [CommSemiring S] variable [Algebra R S] [IsLocalization M S] /-- Explicit characterization of the ideal given by `Ideal.map (algebraMap R S) I`. In practice, this ideal differs only in that the carrier set is defined explicitly. This definition is only meant to be used in proving `mem_map_algebraMap_iff`, and any proof that needs to refer to the explicit carrier set should use that theorem. -/ private def map_ideal (I : Ideal R) : Ideal S where carrier := { z : S | ∃ x : I × M, z * algebraMap R S x.2 = algebraMap R S x.1 } zero_mem' := ⟨⟨0, 1⟩, by simp⟩ add_mem' := by rintro a b ⟨a', ha⟩ ⟨b', hb⟩ let Z : { x // x ∈ I } := ⟨(a'.2 : R) * (b'.1 : R) + (b'.2 : R) * (a'.1 : R), I.add_mem (I.mul_mem_left _ b'.1.2) (I.mul_mem_left _ a'.1.2)⟩ use ⟨Z, a'.2 * b'.2⟩ simp only [RingHom.map_add, Submodule.coe_mk, Submonoid.coe_mul, RingHom.map_mul] rw [add_mul, ← mul_assoc a, ha, mul_comm (algebraMap R S a'.2) (algebraMap R S b'.2), ← mul_assoc b, hb] ring smul_mem' := by rintro c x ⟨x', hx⟩ obtain ⟨c', hc⟩ := IsLocalization.surj M c let Z : { x // x ∈ I } := ⟨c'.1 * x'.1, I.mul_mem_left c'.1 x'.1.2⟩ use ⟨Z, c'.2 * x'.2⟩ simp only [← hx, ← hc, smul_eq_mul, Submodule.coe_mk, Submonoid.coe_mul, RingHom.map_mul] ring theorem mem_map_algebraMap_iff {I : Ideal R} {z} : z ∈ Ideal.map (algebraMap R S) I ↔ ∃ x : I × M, z * algebraMap R S x.2 = algebraMap R S x.1 := by constructor · change _ → z ∈ map_ideal M S I refine fun h => Ideal.mem_sInf.1 h fun z hz => ?_ obtain ⟨y, hy⟩ := hz let Z : { x // x ∈ I } := ⟨y, hy.left⟩ use ⟨Z, 1⟩ simp [hy.right] · rintro ⟨⟨a, s⟩, h⟩ rw [← Ideal.unit_mul_mem_iff_mem _ (map_units S s), mul_comm] exact h.symm ▸ Ideal.mem_map_of_mem _ a.2 lemma mk'_mem_map_algebraMap_iff (I : Ideal R) (x : R) (s : M) : IsLocalization.mk' S x s ∈ I.map (algebraMap R S) ↔ ∃ s ∈ M, s * x ∈ I := by rw [← Ideal.unit_mul_mem_iff_mem _ (IsLocalization.map_units S s), IsLocalization.mk'_spec', IsLocalization.mem_map_algebraMap_iff M] simp_rw [← map_mul, IsLocalization.eq_iff_exists M, mul_comm x, ← mul_assoc, ← Submonoid.coe_mul] exact ⟨fun ⟨⟨y, t⟩, c, h⟩ ↦ ⟨_, (c * t).2, h ▸ I.mul_mem_left c.1 y.2⟩, fun ⟨s, hs, h⟩ ↦ ⟨⟨⟨_, h⟩, ⟨s, hs⟩⟩, 1, by simp⟩⟩ theorem map_comap [IsLocalization M S] (J : Ideal S) : Ideal.map (algebraMap R S) (Ideal.comap (algebraMap R S) J) = J := le_antisymm (Ideal.map_le_iff_le_comap.2 le_rfl) fun x hJ => by obtain ⟨r, s, hx⟩ := mk'_surjective M x rw [← hx] at hJ ⊢ exact Ideal.mul_mem_right _ _ (Ideal.mem_map_of_mem _ (show (algebraMap R S) r ∈ J from mk'_spec S r s ▸ J.mul_mem_right ((algebraMap R S) s) hJ)) theorem comap_map_of_isPrime_disjoint (I : Ideal R) (hI : I.IsPrime) (hM : Disjoint (M : Set R) I) : Ideal.comap (algebraMap R S) (Ideal.map (algebraMap R S) I) = I := by refine le_antisymm ?_ Ideal.le_comap_map refine (fun a ha => ?_) obtain ⟨⟨b, s⟩, h⟩ := (mem_map_algebraMap_iff M S).1 (Ideal.mem_comap.1 ha) replace h : algebraMap R S (s * a) = algebraMap R S b := by simpa only [← map_mul, mul_comm] using h obtain ⟨c, hc⟩ := (eq_iff_exists M S).1 h have : ↑c * ↑s * a ∈ I := by rw [mul_assoc, hc] exact I.mul_mem_left c b.2 exact (hI.mem_or_mem this).resolve_left fun hsc => hM.le_bot ⟨(c * s).2, hsc⟩ /-- If `S` is the localization of `R` at a submonoid, the ordering of ideals of `S` is embedded in the ordering of ideals of `R`. -/ def orderEmbedding : Ideal S ↪o Ideal R where toFun J := Ideal.comap (algebraMap R S) J inj' := Function.LeftInverse.injective (map_comap M S) map_rel_iff' := by rintro J₁ J₂ constructor · exact fun hJ => (map_comap M S) J₁ ▸ (map_comap M S) J₂ ▸ Ideal.map_mono hJ · exact fun hJ => Ideal.comap_mono hJ /-- If `R` is a ring, then prime ideals in the localization at `M` correspond to prime ideals in the original ring `R` that are disjoint from `M`. This lemma gives the particular case for an ideal and its comap, see `le_rel_iso_of_prime` for the more general relation isomorphism -/ theorem isPrime_iff_isPrime_disjoint (J : Ideal S) : J.IsPrime ↔ (Ideal.comap (algebraMap R S) J).IsPrime ∧ Disjoint (M : Set R) ↑(Ideal.comap (algebraMap R S) J) := by constructor · refine fun h => ⟨⟨?_, ?_⟩, Set.disjoint_left.mpr fun m hm1 hm2 => h.ne_top (Ideal.eq_top_of_isUnit_mem _ hm2 (map_units S ⟨m, hm1⟩))⟩ · refine fun hJ => h.ne_top ?_ rw [eq_top_iff, ← (orderEmbedding M S).le_iff_le] exact le_of_eq hJ.symm · intro x y hxy rw [Ideal.mem_comap, RingHom.map_mul] at hxy exact h.mem_or_mem hxy · refine fun h => ⟨fun hJ => h.left.ne_top (eq_top_iff.2 ?_), ?_⟩ · rwa [eq_top_iff, ← (orderEmbedding M S).le_iff_le] at hJ · intro x y hxy obtain ⟨a, s, ha⟩ := mk'_surjective M x obtain ⟨b, t, hb⟩ := mk'_surjective M y have : mk' S (a * b) (s * t) ∈ J := by rwa [mk'_mul, ha, hb] rw [mk'_mem_iff, ← Ideal.mem_comap] at this have this₂ := (h.1).mul_mem_iff_mem_or_mem.1 this rw [Ideal.mem_comap, Ideal.mem_comap] at this₂ rwa [← ha, ← hb, mk'_mem_iff, mk'_mem_iff] /-- If `R` is a ring, then prime ideals in the localization at `M` correspond to prime ideals in the original ring `R` that are disjoint from `M`. This lemma gives the particular case for an ideal and its map, see `le_rel_iso_of_prime` for the more general relation isomorphism, and the reverse implication -/ theorem isPrime_of_isPrime_disjoint (I : Ideal R) (hp : I.IsPrime) (hd : Disjoint (M : Set R) ↑I) : (Ideal.map (algebraMap R S) I).IsPrime := by rw [isPrime_iff_isPrime_disjoint M S, comap_map_of_isPrime_disjoint M S I hp hd] exact ⟨hp, hd⟩ /-- If `R` is a ring, then prime ideals in the localization at `M` correspond to prime ideals in the original ring `R` that are disjoint from `M` -/ def orderIsoOfPrime : { p : Ideal S // p.IsPrime } ≃o { p : Ideal R // p.IsPrime ∧ Disjoint (M : Set R) ↑p } where toFun p := ⟨Ideal.comap (algebraMap R S) p.1, (isPrime_iff_isPrime_disjoint M S p.1).1 p.2⟩ invFun p := ⟨Ideal.map (algebraMap R S) p.1, isPrime_of_isPrime_disjoint M S p.1 p.2.1 p.2.2⟩ left_inv J := Subtype.eq (map_comap M S J) right_inv I := Subtype.eq (comap_map_of_isPrime_disjoint M S I.1 I.2.1 I.2.2) map_rel_iff' := by rintro I I' constructor · exact (fun h => show I.val ≤ I'.val from map_comap M S I.val ▸ map_comap M S I'.val ▸ Ideal.map_mono h) exact fun h x hx => h hx end CommSemiring section CommRing variable {R : Type*} [CommRing R] (M : Submonoid R) (S : Type*) [CommRing S] variable [Algebra R S] [IsLocalization M S] /-- `quotientMap` applied to maximal ideals of a localization is `surjective`. The quotient by a maximal ideal is a field, so inverses to elements already exist, and the localization necessarily maps the equivalence class of the inverse in the localization -/ theorem surjective_quotientMap_of_maximal_of_localization {I : Ideal S} [I.IsPrime] {J : Ideal R} {H : J ≤ I.comap (algebraMap R S)} (hI : (I.comap (algebraMap R S)).IsMaximal) : Function.Surjective (Ideal.quotientMap I (algebraMap R S) H) := by intro s obtain ⟨s, rfl⟩ := Ideal.Quotient.mk_surjective s obtain ⟨r, ⟨m, hm⟩, rfl⟩ := mk'_surjective M s by_cases hM : (Ideal.Quotient.mk (I.comap (algebraMap R S))) m = 0 · have : I = ⊤ := by rw [Ideal.eq_top_iff_one] rw [Ideal.Quotient.eq_zero_iff_mem, Ideal.mem_comap] at hM convert I.mul_mem_right (mk' S (1 : R) ⟨m, hm⟩) hM rw [← mk'_eq_mul_mk'_one, mk'_self] exact ⟨0, eq_comm.1 (by simp [Ideal.Quotient.eq_zero_iff_mem, this])⟩ · rw [Ideal.Quotient.maximal_ideal_iff_isField_quotient] at hI obtain ⟨n, hn⟩ := hI.3 hM obtain ⟨rn, rfl⟩ := Ideal.Quotient.mk_surjective n refine ⟨(Ideal.Quotient.mk J) (r * rn), ?_⟩ -- The rest of the proof is essentially just algebraic manipulations to prove the equality replace hn := congr_arg (Ideal.quotientMap I (algebraMap R S) le_rfl) hn rw [RingHom.map_one, RingHom.map_mul] at hn rw [Ideal.quotientMap_mk, ← sub_eq_zero, ← RingHom.map_sub, Ideal.Quotient.eq_zero_iff_mem, ← Ideal.Quotient.eq_zero_iff_mem, RingHom.map_sub, sub_eq_zero, mk'_eq_mul_mk'_one] simp only [mul_eq_mul_left_iff, RingHom.map_mul] refine Or.inl (mul_left_cancel₀ (M₀ := S ⧸ I) (fun hn => hM (Ideal.Quotient.eq_zero_iff_mem.2 (Ideal.mem_comap.2 (Ideal.Quotient.eq_zero_iff_mem.1 hn)))) (_root_.trans hn ?_)) -- Porting note (#10691): was `rw`, but this took extremely long. refine Eq.trans ?_ (RingHom.map_mul (Ideal.Quotient.mk I) (algebraMap R S m) (mk' S 1 ⟨m, hm⟩)) rw [← mk'_eq_mul_mk'_one, mk'_self, RingHom.map_one] open nonZeroDivisors theorem bot_lt_comap_prime [IsDomain R] (hM : M ≤ R⁰) (p : Ideal S) [hpp : p.IsPrime] (hp0 : p ≠ ⊥) : ⊥ < Ideal.comap (algebraMap R S) p := by haveI : IsDomain S := isDomain_of_le_nonZeroDivisors _ hM rw [← Ideal.comap_bot_of_injective (algebraMap R S) (IsLocalization.injective _ hM)] convert (orderIsoOfPrime M S).lt_iff_lt.mpr (show (⟨⊥, Ideal.bot_prime⟩ : { p : Ideal S // p.IsPrime }) < ⟨p, hpp⟩ from hp0.bot_lt) theorem ideal_eq_iInf_comap_map_away {S : Finset R} (hS : Ideal.span (α := R) S = ⊤) (I : Ideal R) : I = ⨅ f ∈ S, (I.map (algebraMap R (Localization.Away f))).comap (algebraMap R (Localization.Away f)) := by apply le_antisymm · simp only [le_iInf₂_iff, ← Ideal.map_le_iff_le_comap, le_refl, implies_true] · intro x hx apply Submodule.mem_of_span_eq_top_of_smul_pow_mem _ _ hS rintro ⟨s, hs⟩ simp only [Ideal.mem_iInf, Ideal.mem_comap] at hx obtain ⟨⟨y, ⟨_, n, rfl⟩⟩, e⟩ := (IsLocalization.mem_map_algebraMap_iff (.powers s) _).mp (hx s hs) dsimp only at e rw [← map_mul, IsLocalization.eq_iff_exists (.powers s)] at e obtain ⟨⟨_, m, rfl⟩, e⟩ := e use m + n dsimp at e ⊢ rw [pow_add, mul_assoc, ← mul_comm x, e] exact I.mul_mem_left _ y.2 end CommRing end IsLocalization
RingTheory\Localization\Integer.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen -/ import Mathlib.RingTheory.Localization.Basic /-! # Integer elements of a localization ## Main definitions * `IsLocalization.IsInteger` is a predicate stating that `x : S` is in the image of `R` ## Implementation notes See `RingTheory/Localization/Basic.lean` for a design overview. ## Tags localization, ring localization, commutative ring localization, characteristic predicate, commutative ring, field of fractions -/ variable {R : Type*} [CommSemiring R] {M : Submonoid R} {S : Type*} [CommSemiring S] variable [Algebra R S] {P : Type*} [CommSemiring P] open Function namespace IsLocalization section variable (R) -- TODO: define a subalgebra of `IsInteger`s /-- Given `a : S`, `S` a localization of `R`, `IsInteger R a` iff `a` is in the image of the localization map from `R` to `S`. -/ def IsInteger (a : S) : Prop := a ∈ (algebraMap R S).rangeS end theorem isInteger_zero : IsInteger R (0 : S) := Subsemiring.zero_mem _ theorem isInteger_one : IsInteger R (1 : S) := Subsemiring.one_mem _ theorem isInteger_add {a b : S} (ha : IsInteger R a) (hb : IsInteger R b) : IsInteger R (a + b) := Subsemiring.add_mem _ ha hb theorem isInteger_mul {a b : S} (ha : IsInteger R a) (hb : IsInteger R b) : IsInteger R (a * b) := Subsemiring.mul_mem _ ha hb theorem isInteger_smul {a : R} {b : S} (hb : IsInteger R b) : IsInteger R (a • b) := by rcases hb with ⟨b', hb⟩ use a * b' rw [← hb, (algebraMap R S).map_mul, Algebra.smul_def] variable (M) variable [IsLocalization M S] /-- Each element `a : S` has an `M`-multiple which is an integer. This version multiplies `a` on the right, matching the argument order in `LocalizationMap.surj`. -/ theorem exists_integer_multiple' (a : S) : ∃ b : M, IsInteger R (a * algebraMap R S b) := let ⟨⟨Num, denom⟩, h⟩ := IsLocalization.surj _ a ⟨denom, Set.mem_range.mpr ⟨Num, h.symm⟩⟩ /-- Each element `a : S` has an `M`-multiple which is an integer. This version multiplies `a` on the left, matching the argument order in the `SMul` instance. -/ theorem exists_integer_multiple (a : S) : ∃ b : M, IsInteger R ((b : R) • a) := by simp_rw [Algebra.smul_def, mul_comm _ a] apply exists_integer_multiple' /-- We can clear the denominators of a `Finset`-indexed family of fractions. -/ theorem exist_integer_multiples {ι : Type*} (s : Finset ι) (f : ι → S) : ∃ b : M, ∀ i ∈ s, IsLocalization.IsInteger R ((b : R) • f i) := by haveI := Classical.propDecidable refine ⟨∏ i ∈ s, (sec M (f i)).2, fun i hi => ⟨?_, ?_⟩⟩ · exact (∏ j ∈ s.erase i, (sec M (f j)).2) * (sec M (f i)).1 rw [RingHom.map_mul, sec_spec', ← mul_assoc, ← (algebraMap R S).map_mul, ← Algebra.smul_def] congr 2 refine _root_.trans ?_ (map_prod (Submonoid.subtype M) _ _).symm rw [mul_comm,Submonoid.coe_finset_prod, -- Porting note: explicitly supplied `f` ← Finset.prod_insert (f := fun i => ((sec M (f i)).snd : R)) (s.not_mem_erase i), Finset.insert_erase hi] rfl /-- We can clear the denominators of a finite indexed family of fractions. -/ theorem exist_integer_multiples_of_finite {ι : Type*} [Finite ι] (f : ι → S) : ∃ b : M, ∀ i, IsLocalization.IsInteger R ((b : R) • f i) := by cases nonempty_fintype ι obtain ⟨b, hb⟩ := exist_integer_multiples M Finset.univ f exact ⟨b, fun i => hb i (Finset.mem_univ _)⟩ /-- We can clear the denominators of a finite set of fractions. -/ theorem exist_integer_multiples_of_finset (s : Finset S) : ∃ b : M, ∀ a ∈ s, IsInteger R ((b : R) • a) := exist_integer_multiples M s id /-- A choice of a common multiple of the denominators of a `Finset`-indexed family of fractions. -/ noncomputable def commonDenom {ι : Type*} (s : Finset ι) (f : ι → S) : M := (exist_integer_multiples M s f).choose /-- The numerator of a fraction after clearing the denominators of a `Finset`-indexed family of fractions. -/ noncomputable def integerMultiple {ι : Type*} (s : Finset ι) (f : ι → S) (i : s) : R := ((exist_integer_multiples M s f).choose_spec i i.prop).choose @[simp] theorem map_integerMultiple {ι : Type*} (s : Finset ι) (f : ι → S) (i : s) : algebraMap R S (integerMultiple M s f i) = commonDenom M s f • f i := ((exist_integer_multiples M s f).choose_spec _ i.prop).choose_spec /-- A choice of a common multiple of the denominators of a finite set of fractions. -/ noncomputable def commonDenomOfFinset (s : Finset S) : M := commonDenom M s id /-- The finset of numerators after clearing the denominators of a finite set of fractions. -/ noncomputable def finsetIntegerMultiple [DecidableEq R] (s : Finset S) : Finset R := s.attach.image fun t => integerMultiple M s id t open Pointwise theorem finsetIntegerMultiple_image [DecidableEq R] (s : Finset S) : algebraMap R S '' finsetIntegerMultiple M s = commonDenomOfFinset M s • (s : Set S) := by delta finsetIntegerMultiple commonDenom rw [Finset.coe_image] ext constructor · rintro ⟨_, ⟨x, -, rfl⟩, rfl⟩ rw [map_integerMultiple] exact Set.mem_image_of_mem _ x.prop · rintro ⟨x, hx, rfl⟩ exact ⟨_, ⟨⟨x, hx⟩, s.mem_attach _, rfl⟩, map_integerMultiple M s id _⟩ end IsLocalization
RingTheory\Localization\Integral.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen -/ import Mathlib.Algebra.GroupWithZero.NonZeroDivisors import Mathlib.Algebra.Polynomial.Lifts import Mathlib.GroupTheory.MonoidLocalization.Basic import Mathlib.RingTheory.Algebraic import Mathlib.RingTheory.IntegralClosure.Algebra.Basic import Mathlib.RingTheory.Localization.FractionRing import Mathlib.RingTheory.Localization.Integer /-! # Integral and algebraic elements of a fraction field ## Implementation notes See `RingTheory/Localization/Basic.lean` for a design overview. ## Tags localization, ring localization, commutative ring localization, characteristic predicate, commutative ring, field of fractions -/ variable {R : Type*} [CommRing R] (M : Submonoid R) {S : Type*} [CommRing S] variable [Algebra R S] {P : Type*} [CommRing P] open Polynomial namespace IsLocalization section IntegerNormalization open Polynomial variable [IsLocalization M S] open scoped Classical /-- `coeffIntegerNormalization p` gives the coefficients of the polynomial `integerNormalization p` -/ noncomputable def coeffIntegerNormalization (p : S[X]) (i : ℕ) : R := if hi : i ∈ p.support then Classical.choose (Classical.choose_spec (exist_integer_multiples_of_finset M (p.support.image p.coeff)) (p.coeff i) (Finset.mem_image.mpr ⟨i, hi, rfl⟩)) else 0 theorem coeffIntegerNormalization_of_not_mem_support (p : S[X]) (i : ℕ) (h : coeff p i = 0) : coeffIntegerNormalization M p i = 0 := by simp only [coeffIntegerNormalization, h, mem_support_iff, eq_self_iff_true, not_true, Ne, dif_neg, not_false_iff] theorem coeffIntegerNormalization_mem_support (p : S[X]) (i : ℕ) (h : coeffIntegerNormalization M p i ≠ 0) : i ∈ p.support := by contrapose h rw [Ne, Classical.not_not, coeffIntegerNormalization, dif_neg h] /-- `integerNormalization g` normalizes `g` to have integer coefficients by clearing the denominators -/ noncomputable def integerNormalization (p : S[X]) : R[X] := ∑ i ∈ p.support, monomial i (coeffIntegerNormalization M p i) @[simp] theorem integerNormalization_coeff (p : S[X]) (i : ℕ) : (integerNormalization M p).coeff i = coeffIntegerNormalization M p i := by simp (config := { contextual := true }) [integerNormalization, coeff_monomial, coeffIntegerNormalization_of_not_mem_support] theorem integerNormalization_spec (p : S[X]) : ∃ b : M, ∀ i, algebraMap R S ((integerNormalization M p).coeff i) = (b : R) • p.coeff i := by use Classical.choose (exist_integer_multiples_of_finset M (p.support.image p.coeff)) intro i rw [integerNormalization_coeff, coeffIntegerNormalization] split_ifs with hi · exact Classical.choose_spec (Classical.choose_spec (exist_integer_multiples_of_finset M (p.support.image p.coeff)) (p.coeff i) (Finset.mem_image.mpr ⟨i, hi, rfl⟩)) · rw [RingHom.map_zero, not_mem_support_iff.mp hi, smul_zero] -- Porting note: was `convert (smul_zero _).symm, ...` theorem integerNormalization_map_to_map (p : S[X]) : ∃ b : M, (integerNormalization M p).map (algebraMap R S) = (b : R) • p := let ⟨b, hb⟩ := integerNormalization_spec M p ⟨b, Polynomial.ext fun i => by rw [coeff_map, coeff_smul] exact hb i⟩ variable {R' : Type*} [CommRing R'] theorem integerNormalization_eval₂_eq_zero (g : S →+* R') (p : S[X]) {x : R'} (hx : eval₂ g x p = 0) : eval₂ (g.comp (algebraMap R S)) x (integerNormalization M p) = 0 := let ⟨b, hb⟩ := integerNormalization_map_to_map M p _root_.trans (eval₂_map (algebraMap R S) g x).symm (by rw [hb, ← IsScalarTower.algebraMap_smul S (b : R) p, eval₂_smul, hx, mul_zero]) theorem integerNormalization_aeval_eq_zero [Algebra R R'] [Algebra S R'] [IsScalarTower R S R'] (p : S[X]) {x : R'} (hx : aeval x p = 0) : aeval x (integerNormalization M p) = 0 := by rw [aeval_def, IsScalarTower.algebraMap_eq R S R', integerNormalization_eval₂_eq_zero _ (algebraMap _ _) _ hx] end IntegerNormalization end IsLocalization namespace IsFractionRing open IsLocalization variable {A K C : Type*} [CommRing A] [IsDomain A] [Field K] [Algebra A K] [IsFractionRing A K] variable [CommRing C] theorem integerNormalization_eq_zero_iff {p : K[X]} : integerNormalization (nonZeroDivisors A) p = 0 ↔ p = 0 := by refine Polynomial.ext_iff.trans (Polynomial.ext_iff.trans ?_).symm obtain ⟨⟨b, nonzero⟩, hb⟩ := integerNormalization_spec (nonZeroDivisors A) p constructor <;> intro h i · -- Porting note: avoided some defeq abuse rw [coeff_zero, ← to_map_eq_zero_iff (K := K), hb i, h i, coeff_zero, smul_zero] · have hi := h i rw [Polynomial.coeff_zero, ← @to_map_eq_zero_iff A _ K, hb i, Algebra.smul_def] at hi apply Or.resolve_left (eq_zero_or_eq_zero_of_mul_eq_zero hi) intro h apply mem_nonZeroDivisors_iff_ne_zero.mp nonzero exact to_map_eq_zero_iff.mp h variable (A K C) /-- An element of a ring is algebraic over the ring `A` iff it is algebraic over the field of fractions of `A`. -/ theorem isAlgebraic_iff [Algebra A C] [Algebra K C] [IsScalarTower A K C] {x : C} : IsAlgebraic A x ↔ IsAlgebraic K x := by constructor <;> rintro ⟨p, hp, px⟩ · refine ⟨p.map (algebraMap A K), fun h => hp (Polynomial.ext fun i => ?_), ?_⟩ · have : algebraMap A K (p.coeff i) = 0 := _root_.trans (Polynomial.coeff_map _ _).symm (by simp [h]) exact to_map_eq_zero_iff.mp this · exact (Polynomial.aeval_map_algebraMap K _ _).trans px · exact ⟨integerNormalization _ p, mt integerNormalization_eq_zero_iff.mp hp, integerNormalization_aeval_eq_zero _ p px⟩ variable {A K C} /-- A ring is algebraic over the ring `A` iff it is algebraic over the field of fractions of `A`. -/ theorem comap_isAlgebraic_iff [Algebra A C] [Algebra K C] [IsScalarTower A K C] : Algebra.IsAlgebraic A C ↔ Algebra.IsAlgebraic K C := ⟨fun h => ⟨fun x => (isAlgebraic_iff A K C).mp (h.isAlgebraic x)⟩, fun h => ⟨fun x => (isAlgebraic_iff A K C).mpr (h.isAlgebraic x)⟩⟩ end IsFractionRing open IsLocalization section IsIntegral variable {Rₘ Sₘ : Type*} [CommRing Rₘ] [CommRing Sₘ] variable [Algebra R Rₘ] [IsLocalization M Rₘ] variable [Algebra S Sₘ] [IsLocalization (Algebra.algebraMapSubmonoid S M) Sₘ] variable {M} open Polynomial theorem RingHom.isIntegralElem_localization_at_leadingCoeff {R S : Type*} [CommRing R] [CommRing S] (f : R →+* S) (x : S) (p : R[X]) (hf : p.eval₂ f x = 0) (M : Submonoid R) (hM : p.leadingCoeff ∈ M) {Rₘ Sₘ : Type*} [CommRing Rₘ] [CommRing Sₘ] [Algebra R Rₘ] [IsLocalization M Rₘ] [Algebra S Sₘ] [IsLocalization (M.map f : Submonoid S) Sₘ] : (map Sₘ f M.le_comap_map : Rₘ →+* _).IsIntegralElem (algebraMap S Sₘ x) := by by_cases triv : (1 : Rₘ) = 0 · exact ⟨0, ⟨_root_.trans leadingCoeff_zero triv.symm, eval₂_zero _ _⟩⟩ haveI : Nontrivial Rₘ := nontrivial_of_ne 1 0 triv obtain ⟨b, hb⟩ := isUnit_iff_exists_inv.mp (map_units Rₘ ⟨p.leadingCoeff, hM⟩) refine ⟨p.map (algebraMap R Rₘ) * C b, ⟨?_, ?_⟩⟩ · refine monic_mul_C_of_leadingCoeff_mul_eq_one ?_ rwa [leadingCoeff_map_of_leadingCoeff_ne_zero (algebraMap R Rₘ)] refine fun hfp => zero_ne_one (_root_.trans (zero_mul b).symm (hfp ▸ hb) : (0 : Rₘ) = 1) · refine eval₂_mul_eq_zero_of_left _ _ _ ?_ erw [eval₂_map, IsLocalization.map_comp, ← hom_eval₂ _ f (algebraMap S Sₘ) x] exact _root_.trans (congr_arg (algebraMap S Sₘ) hf) (RingHom.map_zero _) /-- Given a particular witness to an element being algebraic over an algebra `R → S`, We can localize to a submonoid containing the leading coefficient to make it integral. Explicitly, the map between the localizations will be an integral ring morphism -/ theorem is_integral_localization_at_leadingCoeff {x : S} (p : R[X]) (hp : aeval x p = 0) (hM : p.leadingCoeff ∈ M) : (map Sₘ (algebraMap R S) (show _ ≤ (Algebra.algebraMapSubmonoid S M).comap _ from M.le_comap_map) : Rₘ →+* _).IsIntegralElem (algebraMap S Sₘ x) := -- Porting note: added `haveI` haveI : IsLocalization (Submonoid.map (algebraMap R S) M) Sₘ := inferInstanceAs (IsLocalization (Algebra.algebraMapSubmonoid S M) Sₘ) (algebraMap R S).isIntegralElem_localization_at_leadingCoeff x p hp M hM /-- If `R → S` is an integral extension, `M` is a submonoid of `R`, `Rₘ` is the localization of `R` at `M`, and `Sₘ` is the localization of `S` at the image of `M` under the extension map, then the induced map `Rₘ → Sₘ` is also an integral extension -/ theorem isIntegral_localization [Algebra.IsIntegral R S] : (map Sₘ (algebraMap R S) (show _ ≤ (Algebra.algebraMapSubmonoid S M).comap _ from M.le_comap_map) : Rₘ →+* _).IsIntegral := by intro x obtain ⟨⟨s, ⟨u, hu⟩⟩, hx⟩ := surj (Algebra.algebraMapSubmonoid S M) x obtain ⟨v, hv⟩ := hu obtain ⟨v', hv'⟩ := isUnit_iff_exists_inv'.1 (map_units Rₘ ⟨v, hv.1⟩) refine @IsIntegral.of_mul_unit Rₘ _ _ _ (localizationAlgebra M S) x (algebraMap S Sₘ u) v' ?_ ?_ · replace hv' := congr_arg (@algebraMap Rₘ Sₘ _ _ (localizationAlgebra M S)) hv' rw [RingHom.map_mul, RingHom.map_one, ← RingHom.comp_apply _ (algebraMap R Rₘ)] at hv' -- Porting note: added argument erw [IsLocalization.map_comp (show _ ≤ (Algebra.algebraMapSubmonoid S M).comap _ from M.le_comap_map)] at hv' exact hv.2 ▸ hv' · obtain ⟨p, hp⟩ := Algebra.IsIntegral.isIntegral (R := R) s exact hx.symm ▸ is_integral_localization_at_leadingCoeff p hp.2 (hp.1.symm ▸ M.one_mem) @[nolint unusedHavesSuffices] -- It claims the `have : IsLocalization` line is unnecessary, -- but remove it and the proof won't work. theorem isIntegral_localization' {R S : Type*} [CommRing R] [CommRing S] {f : R →+* S} (hf : f.IsIntegral) (M : Submonoid R) : (map (Localization (M.map (f : R →* S))) f (M.le_comap_map : _ ≤ Submonoid.comap (f : R →* S) _) : Localization M →+* _).IsIntegral := -- Porting note: added let _ := f.toAlgebra have : Algebra.IsIntegral R S := ⟨hf⟩ have : IsLocalization (Algebra.algebraMapSubmonoid S M) (Localization (Submonoid.map (f : R →* S) M)) := Localization.isLocalization isIntegral_localization variable (M) theorem IsLocalization.scaleRoots_commonDenom_mem_lifts (p : Rₘ[X]) (hp : p.leadingCoeff ∈ (algebraMap R Rₘ).range) : p.scaleRoots (algebraMap R Rₘ <| IsLocalization.commonDenom M p.support p.coeff) ∈ Polynomial.lifts (algebraMap R Rₘ) := by rw [Polynomial.lifts_iff_coeff_lifts] intro n rw [Polynomial.coeff_scaleRoots] by_cases h₁ : n ∈ p.support on_goal 1 => by_cases h₂ : n = p.natDegree · rwa [h₂, Polynomial.coeff_natDegree, tsub_self, pow_zero, _root_.mul_one] · have : n + 1 ≤ p.natDegree := lt_of_le_of_ne (Polynomial.le_natDegree_of_mem_supp _ h₁) h₂ rw [← tsub_add_cancel_of_le (le_tsub_of_add_le_left this), pow_add, pow_one, mul_comm, _root_.mul_assoc, ← map_pow] change _ ∈ (algebraMap R Rₘ).range apply mul_mem · exact RingHom.mem_range_self _ _ · rw [← Algebra.smul_def] exact ⟨_, IsLocalization.map_integerMultiple M p.support p.coeff ⟨n, h₁⟩⟩ · rw [Polynomial.not_mem_support_iff] at h₁ rw [h₁, zero_mul] exact zero_mem (algebraMap R Rₘ).range theorem IsIntegral.exists_multiple_integral_of_isLocalization [Algebra Rₘ S] [IsScalarTower R Rₘ S] (x : S) (hx : IsIntegral Rₘ x) : ∃ m : M, IsIntegral R (m • x) := by cases' subsingleton_or_nontrivial Rₘ with _ nontriv · haveI := (_root_.algebraMap Rₘ S).codomain_trivial exact ⟨1, Polynomial.X, Polynomial.monic_X, Subsingleton.elim _ _⟩ obtain ⟨p, hp₁, hp₂⟩ := hx -- Porting note: obtain doesn't support side goals have := lifts_and_natDegree_eq_and_monic (IsLocalization.scaleRoots_commonDenom_mem_lifts M p ?_) ?_ · obtain ⟨p', hp'₁, -, hp'₂⟩ := this refine ⟨IsLocalization.commonDenom M p.support p.coeff, p', hp'₂, ?_⟩ rw [IsScalarTower.algebraMap_eq R Rₘ S, ← Polynomial.eval₂_map, hp'₁, Submonoid.smul_def, Algebra.smul_def, IsScalarTower.algebraMap_apply R Rₘ S] exact Polynomial.scaleRoots_eval₂_eq_zero _ hp₂ · rw [hp₁.leadingCoeff] exact one_mem _ · rwa [Polynomial.monic_scaleRoots_iff] end IsIntegral variable {A K : Type*} [CommRing A] [IsDomain A] namespace IsIntegralClosure variable (A) variable {L : Type*} [Field K] [Field L] [Algebra A K] [Algebra A L] [IsFractionRing A K] variable (C : Type*) [CommRing C] [IsDomain C] [Algebra C L] [IsIntegralClosure C A L] variable [Algebra A C] [IsScalarTower A C L] open Algebra /-- If the field `L` is an algebraic extension of the integral domain `A`, the integral closure `C` of `A` in `L` has fraction field `L`. -/ theorem isFractionRing_of_algebraic [Algebra.IsAlgebraic A L] (inj : ∀ x, algebraMap A L x = 0 → x = 0) : IsFractionRing C L := { map_units' := fun ⟨y, hy⟩ => IsUnit.mk0 _ (show algebraMap C L y ≠ 0 from fun h => mem_nonZeroDivisors_iff_ne_zero.mp hy ((injective_iff_map_eq_zero (algebraMap C L)).mp (algebraMap_injective C A L) _ h)) surj' := fun z => let ⟨x, y, hy, hxy⟩ := exists_integral_multiple (Algebra.IsAlgebraic.isAlgebraic z) inj ⟨⟨mk' C (x : L) x.2, algebraMap _ _ y, mem_nonZeroDivisors_iff_ne_zero.mpr fun h => hy (inj _ (by rw [IsScalarTower.algebraMap_apply A C L, h, RingHom.map_zero]))⟩, by simp only rw [algebraMap_mk', ← IsScalarTower.algebraMap_apply A C L, hxy]⟩ exists_of_eq := fun {x y} h => ⟨1, by simpa using algebraMap_injective C A L h⟩ } variable (K L) /-- If the field `L` is a finite extension of the fraction field of the integral domain `A`, the integral closure `C` of `A` in `L` has fraction field `L`. -/ theorem isFractionRing_of_finite_extension [Algebra K L] [IsScalarTower A K L] [FiniteDimensional K L] : IsFractionRing C L := have : Algebra.IsAlgebraic A L := IsFractionRing.comap_isAlgebraic_iff.mpr (inferInstanceAs (Algebra.IsAlgebraic K L)) isFractionRing_of_algebraic A C fun _ hx => IsFractionRing.to_map_eq_zero_iff.mp ((_root_.map_eq_zero <| algebraMap K L).mp <| (IsScalarTower.algebraMap_apply _ _ _ _).symm.trans hx) end IsIntegralClosure namespace integralClosure variable {L : Type*} [Field K] [Field L] [Algebra A K] [IsFractionRing A K] open Algebra /-- If the field `L` is an algebraic extension of the integral domain `A`, the integral closure of `A` in `L` has fraction field `L`. -/ theorem isFractionRing_of_algebraic [Algebra A L] [Algebra.IsAlgebraic A L] (inj : ∀ x, algebraMap A L x = 0 → x = 0) : IsFractionRing (integralClosure A L) L := IsIntegralClosure.isFractionRing_of_algebraic A (integralClosure A L) inj variable (K L) /-- If the field `L` is a finite extension of the fraction field of the integral domain `A`, the integral closure of `A` in `L` has fraction field `L`. -/ theorem isFractionRing_of_finite_extension [Algebra A L] [Algebra K L] [IsScalarTower A K L] [FiniteDimensional K L] : IsFractionRing (integralClosure A L) L := IsIntegralClosure.isFractionRing_of_finite_extension A K L (integralClosure A L) end integralClosure namespace IsFractionRing variable (R S K) /-- `S` is algebraic over `R` iff a fraction ring of `S` is algebraic over `R` -/ theorem isAlgebraic_iff' [Field K] [IsDomain R] [IsDomain S] [Algebra R K] [Algebra S K] [NoZeroSMulDivisors R K] [IsFractionRing S K] [IsScalarTower R S K] : Algebra.IsAlgebraic R S ↔ Algebra.IsAlgebraic R K := by simp only [Algebra.isAlgebraic_def] constructor · intro h x letI := FractionRing.liftAlgebra R K have := FractionRing.isScalarTower_liftAlgebra R K rw [IsFractionRing.isAlgebraic_iff R (FractionRing R) K, isAlgebraic_iff_isIntegral] obtain ⟨a : S, b, ha, rfl⟩ := @div_surjective S _ _ _ _ _ _ x obtain ⟨f, hf₁, hf₂⟩ := h b rw [div_eq_mul_inv] refine IsIntegral.mul ?_ ?_ · rw [← isAlgebraic_iff_isIntegral] refine .tower_top_of_injective (NoZeroSMulDivisors.algebraMap_injective R (FractionRing R)) ?_ exact .algebraMap (h a) · rw [← isAlgebraic_iff_isIntegral] use (f.map (algebraMap R (FractionRing R))).reverse constructor · rwa [Ne, Polynomial.reverse_eq_zero, ← Polynomial.degree_eq_bot, Polynomial.degree_map_eq_of_injective (NoZeroSMulDivisors.algebraMap_injective R (FractionRing R)), Polynomial.degree_eq_bot] · have : Invertible (algebraMap S K b) := IsUnit.invertible (isUnit_of_mem_nonZeroDivisors (mem_nonZeroDivisors_iff_ne_zero.2 fun h => nonZeroDivisors.ne_zero ha ((injective_iff_map_eq_zero (algebraMap S K)).1 (NoZeroSMulDivisors.algebraMap_injective _ _) b h))) rw [Polynomial.aeval_def, ← invOf_eq_inv, Polynomial.eval₂_reverse_eq_zero_iff, Polynomial.eval₂_map, ← IsScalarTower.algebraMap_eq, ← Polynomial.aeval_def, Polynomial.aeval_algebraMap_apply, hf₂, RingHom.map_zero] · intro h x obtain ⟨f, hf₁, hf₂⟩ := h (algebraMap S K x) use f, hf₁ rw [Polynomial.aeval_algebraMap_apply] at hf₂ exact (injective_iff_map_eq_zero (algebraMap S K)).1 (NoZeroSMulDivisors.algebraMap_injective _ _) _ hf₂ open nonZeroDivisors variable {S K} /-- If the `S`-multiples of `a` are contained in some `R`-span, then `Frac(S)`-multiples of `a` are contained in the equivalent `Frac(R)`-span. -/ theorem ideal_span_singleton_map_subset {L : Type*} [IsDomain R] [IsDomain S] [Field K] [Field L] [Algebra R K] [Algebra R L] [Algebra S L] [IsIntegralClosure S R L] [IsFractionRing S L] [Algebra K L] [IsScalarTower R S L] [IsScalarTower R K L] {a : S} {b : Set S} [Algebra.IsAlgebraic R L] (inj : Function.Injective (algebraMap R L)) (h : (Ideal.span ({a} : Set S) : Set S) ⊆ Submodule.span R b) : (Ideal.span ({algebraMap S L a} : Set L) : Set L) ⊆ Submodule.span K (algebraMap S L '' b) := by intro x hx obtain ⟨x', rfl⟩ := Ideal.mem_span_singleton.mp hx obtain ⟨y', z', rfl⟩ := IsLocalization.mk'_surjective S⁰ x' obtain ⟨y, z, hz0, yz_eq⟩ := IsIntegralClosure.exists_smul_eq_mul inj y' (nonZeroDivisors.coe_ne_zero z') have injRS : Function.Injective (algebraMap R S) := by refine Function.Injective.of_comp (show Function.Injective (algebraMap S L ∘ algebraMap R S) from ?_) rwa [← RingHom.coe_comp, ← IsScalarTower.algebraMap_eq] have hz0' : algebraMap R S z ∈ S⁰ := map_mem_nonZeroDivisors (algebraMap R S) injRS (mem_nonZeroDivisors_of_ne_zero hz0) have mk_yz_eq : IsLocalization.mk' L y' z' = IsLocalization.mk' L y ⟨_, hz0'⟩ := by rw [Algebra.smul_def, mul_comm _ y, mul_comm _ y'] at yz_eq exact IsLocalization.mk'_eq_of_eq (by rw [mul_comm _ y, mul_comm _ y', yz_eq]) suffices hy : algebraMap S L (a * y) ∈ Submodule.span K ((algebraMap S L) '' b) by rw [mk_yz_eq, IsFractionRing.mk'_eq_div, ← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R K L, div_eq_mul_inv, ← mul_assoc, mul_comm, ← map_inv₀, ← Algebra.smul_def, ← _root_.map_mul] exact (Submodule.span K _).smul_mem _ hy refine Submodule.span_subset_span R K _ ?_ rw [Submodule.span_algebraMap_image_of_tower] -- Note: #8386 had to specify the value of `f` here: exact Submodule.mem_map_of_mem (f := LinearMap.restrictScalars _ _) (h (Ideal.mem_span_singleton.mpr ⟨y, rfl⟩)) end IsFractionRing lemma isAlgebraic_of_isLocalization {R} [CommRing R] (M : Submonoid R) (S) [CommRing S] [Nontrivial R] [Algebra R S] [IsLocalization M S] : Algebra.IsAlgebraic R S := by constructor intro x obtain ⟨x, s, rfl⟩ := IsLocalization.mk'_surjective M x by_cases hs : (s : R) = 0 · have := IsLocalization.mk'_spec S x s rw [hs, map_zero, mul_zero] at this exact ⟨X, X_ne_zero, by simp [IsLocalization.mk'_eq_mul_mk'_one x, ← this]⟩ refine ⟨s • X - C x, ?_, ?_⟩ · intro e; apply hs simpa only [coeff_sub, coeff_smul, coeff_X_one, coeff_C_succ, sub_zero, coeff_zero, ← Algebra.algebraMap_eq_smul_one, Submonoid.smul_def, Algebra.id.map_eq_id, RingHom.id_apply] using congr_arg (Polynomial.coeff · 1) e · simp only [map_sub, Algebra.smul_def, Submonoid.smul_def, map_mul, AlgHom.commutes, aeval_X, IsLocalization.mk'_spec', aeval_C, sub_self] open nonZeroDivisors in lemma isAlgebraic_of_isFractionRing {R S} (K L) [CommRing R] [CommRing S] [Field K] [CommRing L] [Algebra R S] [Algebra R K] [Algebra R L] [Algebra S L] [Algebra K L] [IsScalarTower R S L] [IsScalarTower R K L] [IsFractionRing S L] [Algebra.IsIntegral R S] : Algebra.IsAlgebraic K L := by constructor intro x obtain ⟨x, s, rfl⟩ := IsLocalization.mk'_surjective S⁰ x apply IsIntegral.isAlgebraic rw [IsLocalization.mk'_eq_mul_mk'_one] apply RingHom.IsIntegralElem.mul · apply IsIntegral.tower_top (R := R) apply IsIntegral.map (IsScalarTower.toAlgHom R S L) exact Algebra.IsIntegral.isIntegral x · show IsIntegral _ _ rw [← isAlgebraic_iff_isIntegral, ← IsAlgebraic.invOf_iff, isAlgebraic_iff_isIntegral] apply IsIntegral.tower_top (R := R) apply IsIntegral.map (IsScalarTower.toAlgHom R S L) exact Algebra.IsIntegral.isIntegral (s : S)
RingTheory\Localization\InvSubmonoid.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen -/ import Mathlib.GroupTheory.Submonoid.Inverses import Mathlib.RingTheory.FiniteType import Mathlib.RingTheory.Localization.Basic /-! # Submonoid of inverses ## Main definitions * `IsLocalization.invSubmonoid M S` is the submonoid of `S = M⁻¹R` consisting of inverses of each element `x ∈ M` ## Implementation notes See `Mathlib/RingTheory/Localization/Basic.lean` for a design overview. ## Tags localization, ring localization, commutative ring localization, characteristic predicate, commutative ring, field of fractions -/ variable {R : Type*} [CommRing R] (M : Submonoid R) (S : Type*) [CommRing S] variable [Algebra R S] {P : Type*} [CommRing P] open Function namespace IsLocalization section InvSubmonoid /-- The submonoid of `S = M⁻¹R` consisting of `{ 1 / x | x ∈ M }`. -/ def invSubmonoid : Submonoid S := (M.map (algebraMap R S)).leftInv variable [IsLocalization M S] theorem submonoid_map_le_is_unit : M.map (algebraMap R S) ≤ IsUnit.submonoid S := by rintro _ ⟨a, ha, rfl⟩ exact IsLocalization.map_units S ⟨_, ha⟩ /-- There is an equivalence of monoids between the image of `M` and `invSubmonoid`. -/ noncomputable abbrev equivInvSubmonoid : M.map (algebraMap R S) ≃* invSubmonoid M S := ((M.map (algebraMap R S)).leftInvEquiv (submonoid_map_le_is_unit M S)).symm /-- There is a canonical map from `M` to `invSubmonoid` sending `x` to `1 / x`. -/ noncomputable def toInvSubmonoid : M →* invSubmonoid M S := (equivInvSubmonoid M S).toMonoidHom.comp ((algebraMap R S : R →* S).submonoidMap M) theorem toInvSubmonoid_surjective : Function.Surjective (toInvSubmonoid M S) := Function.Surjective.comp (β := M.map (algebraMap R S)) (Equiv.surjective (equivInvSubmonoid _ _).toEquiv) (MonoidHom.submonoidMap_surjective _ _) @[simp] theorem toInvSubmonoid_mul (m : M) : (toInvSubmonoid M S m : S) * algebraMap R S m = 1 := Submonoid.leftInvEquiv_symm_mul _ (submonoid_map_le_is_unit _ _) _ @[simp] theorem mul_toInvSubmonoid (m : M) : algebraMap R S m * (toInvSubmonoid M S m : S) = 1 := Submonoid.mul_leftInvEquiv_symm _ (submonoid_map_le_is_unit _ _) ⟨_, _⟩ @[simp] theorem smul_toInvSubmonoid (m : M) : m • (toInvSubmonoid M S m : S) = 1 := by convert mul_toInvSubmonoid M S m ext rw [← Algebra.smul_def] rfl variable {S} -- Porting note: `surj'` was taken, so use `surj''` instead theorem surj'' (z : S) : ∃ (r : R) (m : M), z = r • (toInvSubmonoid M S m : S) := by rcases IsLocalization.surj M z with ⟨⟨r, m⟩, e : z * _ = algebraMap R S r⟩ refine ⟨r, m, ?_⟩ rw [Algebra.smul_def, ← e, mul_assoc] simp theorem toInvSubmonoid_eq_mk' (x : M) : (toInvSubmonoid M S x : S) = mk' S 1 x := by rw [← (IsLocalization.map_units S x).mul_left_inj] simp theorem mem_invSubmonoid_iff_exists_mk' (x : S) : x ∈ invSubmonoid M S ↔ ∃ m : M, mk' S 1 m = x := by simp_rw [← toInvSubmonoid_eq_mk'] exact ⟨fun h => ⟨_, congr_arg Subtype.val (toInvSubmonoid_surjective M S ⟨x, h⟩).choose_spec⟩, fun h => h.choose_spec ▸ (toInvSubmonoid M S h.choose).prop⟩ variable (S) theorem span_invSubmonoid : Submodule.span R (invSubmonoid M S : Set S) = ⊤ := by rw [eq_top_iff] rintro x - rcases IsLocalization.surj'' M x with ⟨r, m, rfl⟩ exact Submodule.smul_mem _ _ (Submodule.subset_span (toInvSubmonoid M S m).prop) theorem finiteType_of_monoid_fg [Monoid.FG M] : Algebra.FiniteType R S := by have := Monoid.fg_of_surjective _ (toInvSubmonoid_surjective M S) rw [Monoid.fg_iff_submonoid_fg] at this rcases this with ⟨s, hs⟩ refine ⟨⟨s, ?_⟩⟩ rw [eq_top_iff] rintro x - change x ∈ (Subalgebra.toSubmodule (Algebra.adjoin R _ : Subalgebra R S) : Set S) rw [Algebra.adjoin_eq_span, hs, span_invSubmonoid] trivial end InvSubmonoid end IsLocalization
RingTheory\Localization\LocalizationLocalization.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen -/ import Mathlib.RingTheory.Localization.AtPrime import Mathlib.RingTheory.Localization.Basic import Mathlib.RingTheory.Localization.FractionRing /-! # Localizations of localizations ## Implementation notes See `Mathlib/RingTheory/Localization/Basic.lean` for a design overview. ## Tags localization, ring localization, commutative ring localization, characteristic predicate, commutative ring, field of fractions -/ open Function namespace IsLocalization section LocalizationLocalization variable {R : Type*} [CommSemiring R] (M : Submonoid R) {S : Type*} [CommSemiring S] variable [Algebra R S] {P : Type*} [CommSemiring P] variable (N : Submonoid S) (T : Type*) [CommSemiring T] [Algebra R T] section variable [Algebra S T] [IsScalarTower R S T] -- This should only be defined when `S` is the localization `M⁻¹R`, hence the nolint. /-- Localizing wrt `M ⊆ R` and then wrt `N ⊆ S = M⁻¹R` is equal to the localization of `R` wrt this module. See `localization_localization_isLocalization`. -/ @[nolint unusedArguments] def localizationLocalizationSubmodule : Submonoid R := (N ⊔ M.map (algebraMap R S)).comap (algebraMap R S) variable {M N} @[simp] theorem mem_localizationLocalizationSubmodule {x : R} : x ∈ localizationLocalizationSubmodule M N ↔ ∃ (y : N) (z : M), algebraMap R S x = y * algebraMap R S z := by rw [localizationLocalizationSubmodule, Submonoid.mem_comap, Submonoid.mem_sup] constructor · rintro ⟨y, hy, _, ⟨z, hz, rfl⟩, e⟩ exact ⟨⟨y, hy⟩, ⟨z, hz⟩, e.symm⟩ · rintro ⟨y, z, e⟩ exact ⟨y, y.prop, _, ⟨z, z.prop, rfl⟩, e.symm⟩ variable (M N) variable [IsLocalization M S] theorem localization_localization_map_units [IsLocalization N T] (y : localizationLocalizationSubmodule M N) : IsUnit (algebraMap R T y) := by obtain ⟨y', z, eq⟩ := mem_localizationLocalizationSubmodule.mp y.prop rw [IsScalarTower.algebraMap_apply R S T, eq, RingHom.map_mul, IsUnit.mul_iff] exact ⟨IsLocalization.map_units T y', (IsLocalization.map_units _ z).map (algebraMap S T)⟩ theorem localization_localization_surj [IsLocalization N T] (x : T) : ∃ y : R × localizationLocalizationSubmodule M N, x * algebraMap R T y.2 = algebraMap R T y.1 := by rcases IsLocalization.surj N x with ⟨⟨y, s⟩, eq₁⟩ -- x = y / s rcases IsLocalization.surj M y with ⟨⟨z, t⟩, eq₂⟩ -- y = z / t rcases IsLocalization.surj M (s : S) with ⟨⟨z', t'⟩, eq₃⟩ -- s = z' / t' dsimp only at eq₁ eq₂ eq₃ refine ⟨⟨z * t', z' * t, ?_⟩, ?_⟩ -- x = y / s = (z * t') / (z' * t) · rw [mem_localizationLocalizationSubmodule] refine ⟨s, t * t', ?_⟩ rw [RingHom.map_mul, ← eq₃, mul_assoc, ← RingHom.map_mul, mul_comm t, Submonoid.coe_mul] · simp only [Subtype.coe_mk, RingHom.map_mul, IsScalarTower.algebraMap_apply R S T, ← eq₃, ← eq₂, ← eq₁] ring theorem localization_localization_exists_of_eq [IsLocalization N T] (x y : R) : algebraMap R T x = algebraMap R T y → ∃ c : localizationLocalizationSubmodule M N, ↑c * x = ↑c * y := by rw [IsScalarTower.algebraMap_apply R S T, IsScalarTower.algebraMap_apply R S T, IsLocalization.eq_iff_exists N T] rintro ⟨z, eq₁⟩ rcases IsLocalization.surj M (z : S) with ⟨⟨z', s⟩, eq₂⟩ dsimp only at eq₂ suffices (algebraMap R S) (x * z' : R) = (algebraMap R S) (y * z') by obtain ⟨c, eq₃ : ↑c * (x * z') = ↑c * (y * z')⟩ := (IsLocalization.eq_iff_exists M S).mp this refine ⟨⟨c * z', ?_⟩, ?_⟩ · rw [mem_localizationLocalizationSubmodule] refine ⟨z, c * s, ?_⟩ rw [map_mul, ← eq₂, Submonoid.coe_mul, map_mul, mul_left_comm] · rwa [mul_comm _ z', mul_comm _ z', ← mul_assoc, ← mul_assoc] at eq₃ rw [map_mul, map_mul, ← eq₂, ← mul_assoc, ← mul_assoc, mul_comm _ (z : S), eq₁, mul_comm _ (z : S)] /-- Given submodules `M ⊆ R` and `N ⊆ S = M⁻¹R`, with `f : R →+* S` the localization map, we have `N ⁻¹ S = T = (f⁻¹ (N • f(M))) ⁻¹ R`. I.e., the localization of a localization is a localization. -/ theorem localization_localization_isLocalization [IsLocalization N T] : IsLocalization (localizationLocalizationSubmodule M N) T := { map_units' := localization_localization_map_units M N T surj' := localization_localization_surj M N T exists_of_eq := localization_localization_exists_of_eq M N T _ _ } /-- Given submodules `M ⊆ R` and `N ⊆ S = M⁻¹R`, with `f : R →+* S` the localization map, if `N` contains all the units of `S`, then `N ⁻¹ S = T = (f⁻¹ N) ⁻¹ R`. I.e., the localization of a localization is a localization. -/ theorem localization_localization_isLocalization_of_has_all_units [IsLocalization N T] (H : ∀ x : S, IsUnit x → x ∈ N) : IsLocalization (N.comap (algebraMap R S)) T := by convert localization_localization_isLocalization M N T using 1 dsimp [localizationLocalizationSubmodule] congr symm rw [sup_eq_left] rintro _ ⟨x, hx, rfl⟩ exact H _ (IsLocalization.map_units _ ⟨x, hx⟩) /-- Given a submodule `M ⊆ R` and a prime ideal `p` of `S = M⁻¹R`, with `f : R →+* S` the localization map, then `T = Sₚ` is the localization of `R` at `f⁻¹(p)`. -/ theorem isLocalization_isLocalization_atPrime_isLocalization (p : Ideal S) [Hp : p.IsPrime] [IsLocalization.AtPrime T p] : IsLocalization.AtPrime T (p.comap (algebraMap R S)) := by apply localization_localization_isLocalization_of_has_all_units M p.primeCompl T intro x hx hx' exact (Hp.1 : ¬_) (p.eq_top_of_isUnit_mem hx' hx) instance (p : Ideal (Localization M)) [p.IsPrime] : Algebra R (Localization.AtPrime p) := inferInstance instance (p : Ideal (Localization M)) [p.IsPrime] : IsScalarTower R (Localization M) (Localization.AtPrime p) := IsScalarTower.of_algebraMap_eq' rfl instance localization_localization_atPrime_is_localization (p : Ideal (Localization M)) [p.IsPrime] : IsLocalization.AtPrime (Localization.AtPrime p) (p.comap (algebraMap R _)) := isLocalization_isLocalization_atPrime_isLocalization M _ _ /-- Given a submodule `M ⊆ R` and a prime ideal `p` of `M⁻¹R`, with `f : R →+* S` the localization map, then `(M⁻¹R)ₚ` is isomorphic (as an `R`-algebra) to the localization of `R` at `f⁻¹(p)`. -/ noncomputable def localizationLocalizationAtPrimeIsoLocalization (p : Ideal (Localization M)) [p.IsPrime] : Localization.AtPrime (p.comap (algebraMap R (Localization M))) ≃ₐ[R] Localization.AtPrime p := IsLocalization.algEquiv (p.comap (algebraMap R (Localization M))).primeCompl _ _ end variable (S) /-- Given submonoids `M ≤ N` of `R`, this is the canonical algebra structure of `M⁻¹S` acting on `N⁻¹S`. -/ noncomputable def localizationAlgebraOfSubmonoidLe (M N : Submonoid R) (h : M ≤ N) [IsLocalization M S] [IsLocalization N T] : Algebra S T := (@IsLocalization.lift R _ M S _ _ T _ _ (algebraMap R T) (fun y => map_units T ⟨↑y, h y.prop⟩)).toAlgebra /-- If `M ≤ N` are submonoids of `R`, then the natural map `M⁻¹S →+* N⁻¹S` commutes with the localization maps -/ theorem localization_isScalarTower_of_submonoid_le (M N : Submonoid R) (h : M ≤ N) [IsLocalization M S] [IsLocalization N T] : @IsScalarTower R S T _ (localizationAlgebraOfSubmonoidLe S T M N h).toSMul _ := letI := localizationAlgebraOfSubmonoidLe S T M N h IsScalarTower.of_algebraMap_eq' (IsLocalization.lift_comp _).symm noncomputable instance (x : Ideal R) [H : x.IsPrime] [IsDomain R] : Algebra (Localization.AtPrime x) (Localization (nonZeroDivisors R)) := localizationAlgebraOfSubmonoidLe _ _ x.primeCompl (nonZeroDivisors R) (by intro a ha rw [mem_nonZeroDivisors_iff_ne_zero] exact fun h => ha (h.symm ▸ x.zero_mem)) /-- If `M ≤ N` are submonoids of `R`, then `N⁻¹S` is also the localization of `M⁻¹S` at `N`. -/ theorem isLocalization_of_submonoid_le (M N : Submonoid R) (h : M ≤ N) [IsLocalization M S] [IsLocalization N T] [Algebra S T] [IsScalarTower R S T] : IsLocalization (N.map (algebraMap R S)) T := { map_units' := by rintro ⟨_, ⟨y, hy, rfl⟩⟩ convert IsLocalization.map_units T ⟨y, hy⟩ exact (IsScalarTower.algebraMap_apply _ _ _ _).symm surj' := fun y => by obtain ⟨⟨x, s⟩, e⟩ := IsLocalization.surj N y refine ⟨⟨algebraMap R S x, _, _, s.prop, rfl⟩, ?_⟩ simpa [← IsScalarTower.algebraMap_apply] using e exists_of_eq := fun {x₁ x₂} => by obtain ⟨⟨y₁, s₁⟩, e₁⟩ := IsLocalization.surj M x₁ obtain ⟨⟨y₂, s₂⟩, e₂⟩ := IsLocalization.surj M x₂ refine (Set.exists_image_iff (algebraMap R S) N fun c => c * x₁ = c * x₂).mpr.comp ?_ dsimp only at e₁ e₂ ⊢ suffices algebraMap R T (y₁ * s₂) = algebraMap R T (y₂ * s₁) → ∃ a : N, algebraMap R S (a * (y₁ * s₂)) = algebraMap R S (a * (y₂ * s₁)) by have h₁ := @IsUnit.mul_left_inj T _ _ (algebraMap S T x₁) (algebraMap S T x₂) (IsLocalization.map_units T ⟨(s₁ : R), h s₁.prop⟩) have h₂ := @IsUnit.mul_left_inj T _ _ ((algebraMap S T x₁) * (algebraMap R T s₁)) ((algebraMap S T x₂) * (algebraMap R T s₁)) (IsLocalization.map_units T ⟨(s₂ : R), h s₂.prop⟩) simp only [IsScalarTower.algebraMap_apply R S T, Subtype.coe_mk] at h₁ h₂ simp only [IsScalarTower.algebraMap_apply R S T, map_mul, ← e₁, ← e₂, ← mul_assoc, mul_right_comm _ (algebraMap R S s₂), mul_right_comm _ (algebraMap S T (algebraMap R S s₂)), (IsLocalization.map_units S s₁).mul_left_inj, (IsLocalization.map_units S s₂).mul_left_inj] at this rw [h₂, h₁] at this simpa only [mul_comm] using this simp_rw [IsLocalization.eq_iff_exists N T, IsLocalization.eq_iff_exists M S] intro ⟨a, e⟩ exact ⟨a, 1, by convert e using 1 <;> simp⟩ } /-- If `M ≤ N` are submonoids of `R` such that `∀ x : N, ∃ m : R, m * x ∈ M`, then the localization at `N` is equal to the localizaton of `M`. -/ theorem isLocalization_of_is_exists_mul_mem (M N : Submonoid R) [IsLocalization M S] (h : M ≤ N) (h' : ∀ x : N, ∃ m : R, m * x ∈ M) : IsLocalization N S := { map_units' := fun y => by obtain ⟨m, hm⟩ := h' y have := IsLocalization.map_units S ⟨_, hm⟩ erw [map_mul] at this exact (IsUnit.mul_iff.mp this).2 surj' := fun z => by obtain ⟨⟨y, s⟩, e⟩ := IsLocalization.surj M z exact ⟨⟨y, _, h s.prop⟩, e⟩ exists_of_eq := fun {_ _} => by rw [IsLocalization.eq_iff_exists M] exact fun ⟨x, hx⟩ => ⟨⟨_, h x.prop⟩, hx⟩ } end LocalizationLocalization end IsLocalization namespace IsFractionRing variable {R : Type*} [CommRing R] (M : Submonoid R) {S : Type*} [CommRing S] open IsLocalization theorem isFractionRing_of_isLocalization (S T : Type*) [CommRing S] [CommRing T] [Algebra R S] [Algebra R T] [Algebra S T] [IsScalarTower R S T] [IsLocalization M S] [IsFractionRing R T] (hM : M ≤ nonZeroDivisors R) : IsFractionRing S T := by have := isLocalization_of_submonoid_le S T M (nonZeroDivisors R) hM refine @isLocalization_of_is_exists_mul_mem _ _ _ _ _ _ _ this ?_ ?_ · exact map_nonZeroDivisors_le M S · rintro ⟨x, hx⟩ obtain ⟨⟨y, s⟩, e⟩ := IsLocalization.surj M x use algebraMap R S s rw [mul_comm, Subtype.coe_mk, e] refine Set.mem_image_of_mem (algebraMap R S) ?_ intro z hz apply IsLocalization.injective S hM rw [map_zero] apply hx rw [← (map_units S s).mul_left_inj, mul_assoc, e, ← map_mul, hz, map_zero, zero_mul] theorem isFractionRing_of_isDomain_of_isLocalization [IsDomain R] (S T : Type*) [CommRing S] [CommRing T] [Algebra R S] [Algebra R T] [Algebra S T] [IsScalarTower R S T] [IsLocalization M S] [IsFractionRing R T] : IsFractionRing S T := by haveI := IsFractionRing.nontrivial R T haveI := (algebraMap S T).domain_nontrivial apply isFractionRing_of_isLocalization M S T intro x hx rw [mem_nonZeroDivisors_iff_ne_zero] intro hx' apply @zero_ne_one S rw [← (algebraMap R S).map_one, ← @mk'_one R _ M, @comm _ Eq, mk'_eq_zero_iff] exact ⟨⟨x, hx⟩, by simp [hx']⟩ end IsFractionRing
RingTheory\Localization\Module.lean
/- Copyright (c) 2022 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu, Anne Baanen -/ import Mathlib.LinearAlgebra.Basis import Mathlib.Algebra.Module.LocalizedModule import Mathlib.RingTheory.Localization.FractionRing import Mathlib.RingTheory.Localization.Integer /-! # Modules / vector spaces over localizations / fraction fields This file contains some results about vector spaces over the field of fractions of a ring. ## Main results * `LinearIndependent.localization`: `b` is linear independent over a localization of `R` if it is linear independent over `R` itself * `Basis.ofIsLocalizedModule` / `Basis.localizationLocalization`: promote an `R`-basis `b` of `A` to an `Rₛ`-basis of `Aₛ`, where `Rₛ` and `Aₛ` are localizations of `R` and `A` at `s` respectively * `LinearIndependent.iff_fractionRing`: `b` is linear independent over `R` iff it is linear independent over `Frac(R)` -/ open nonZeroDivisors section Localization variable {R : Type*} (Rₛ : Type*) [CommSemiring R] (S : Submonoid R) section IsLocalizedModule section AddCommMonoid open Submodule variable [CommSemiring Rₛ] [Algebra R Rₛ] [hT : IsLocalization S Rₛ] variable {M M' : Type*} [AddCommMonoid M] [Module R M] [Module Rₛ M] [IsScalarTower R Rₛ M] [AddCommMonoid M'] [Module R M'] [Module Rₛ M'] [IsScalarTower R Rₛ M'] (f : M →ₗ[R] M') [IsLocalizedModule S f] theorem span_eq_top_of_isLocalizedModule {v : Set M} (hv : span R v = ⊤) : span Rₛ (f '' v) = ⊤ := top_unique fun x _ ↦ by obtain ⟨⟨m, s⟩, h⟩ := IsLocalizedModule.surj S f x rw [Submonoid.smul_def, ← algebraMap_smul Rₛ, ← Units.smul_isUnit (IsLocalization.map_units Rₛ s), eq_comm, ← inv_smul_eq_iff] at h refine h ▸ smul_mem _ _ (span_subset_span R Rₛ _ ?_) rw [← LinearMap.coe_restrictScalars R, ← LinearMap.map_span, hv] exact mem_map_of_mem mem_top theorem LinearIndependent.of_isLocalizedModule {ι : Type*} {v : ι → M} (hv : LinearIndependent R v) : LinearIndependent Rₛ (f ∘ v) := by rw [linearIndependent_iff'] at hv ⊢ intro t g hg i hi choose! a g' hg' using IsLocalization.exist_integer_multiples S t g have h0 : f (∑ i ∈ t, g' i • v i) = 0 := by apply_fun ((a : R) • ·) at hg rw [smul_zero, Finset.smul_sum] at hg rw [map_sum, ← hg] refine Finset.sum_congr rfl fun i hi => ?_ rw [← smul_assoc, ← hg' i hi, map_smul, Function.comp_apply, algebraMap_smul] obtain ⟨s, hs⟩ := (IsLocalizedModule.eq_zero_iff S f).mp h0 simp_rw [Finset.smul_sum, Submonoid.smul_def, smul_smul] at hs specialize hv t _ hs i hi rw [← (IsLocalization.map_units Rₛ a).mul_right_eq_zero, ← Algebra.smul_def, ← hg' i hi] exact (IsLocalization.map_eq_zero_iff S _ _).2 ⟨s, hv⟩ theorem LinearIndependent.localization {ι : Type*} {b : ι → M} (hli : LinearIndependent R b) : LinearIndependent Rₛ b := by have := isLocalizedModule_id S M Rₛ exact hli.of_isLocalizedModule Rₛ S .id end AddCommMonoid section Basis variable [CommRing Rₛ] [Algebra R Rₛ] [hT : IsLocalization S Rₛ] open Submodule variable {M Mₛ : Type*} [AddCommGroup M] [AddCommGroup Mₛ] [Module R M] [Module R Mₛ] [Module R Mₛ] [Module Rₛ Mₛ] (f : M →ₗ[R] Mₛ) [IsLocalizedModule S f] [IsScalarTower R Rₛ Mₛ] {ι : Type*} (b : Basis ι R M) /-- If `M` has an `R`-basis, then localizing `M` at `S` has a basis over `R` localized at `S`. -/ noncomputable def Basis.ofIsLocalizedModule : Basis ι Rₛ Mₛ := .mk (b.linearIndependent.of_isLocalizedModule Rₛ S f) <| by rw [Set.range_comp, span_eq_top_of_isLocalizedModule Rₛ S _ b.span_eq] @[simp] theorem Basis.ofIsLocalizedModule_apply (i : ι) : b.ofIsLocalizedModule Rₛ S f i = f (b i) := by rw [ofIsLocalizedModule, coe_mk, Function.comp_apply] @[simp] theorem Basis.ofIsLocalizedModule_repr_apply (m : M) (i : ι) : ((b.ofIsLocalizedModule Rₛ S f).repr (f m)) i = algebraMap R Rₛ (b.repr m i) := by suffices ((b.ofIsLocalizedModule Rₛ S f).repr.toLinearMap.restrictScalars R) ∘ₗ f = Finsupp.mapRange.linearMap (Algebra.linearMap R Rₛ) ∘ₗ b.repr.toLinearMap by exact DFunLike.congr_fun (LinearMap.congr_fun this m) i refine Basis.ext b fun i ↦ ?_ rw [LinearMap.coe_comp, Function.comp_apply, LinearMap.coe_restrictScalars, LinearEquiv.coe_coe, ← b.ofIsLocalizedModule_apply Rₛ S f, repr_self, LinearMap.coe_comp, Function.comp_apply, LinearEquiv.coe_coe, repr_self, Finsupp.mapRange.linearMap_apply, Finsupp.mapRange_single, Algebra.linearMap_apply, map_one] theorem Basis.ofIsLocalizedModule_span : span R (Set.range (b.ofIsLocalizedModule Rₛ S f)) = LinearMap.range f := by calc span R (Set.range (b.ofIsLocalizedModule Rₛ S f)) _ = span R (f '' (Set.range b)) := by congr; ext; simp _ = map f (span R (Set.range b)) := by rw [Submodule.map_span] _ = LinearMap.range f := by rw [b.span_eq, Submodule.map_top] end Basis end IsLocalizedModule section LocalizationLocalization variable {R : Type*} (Rₛ : Type*) [CommSemiring R] [CommRing Rₛ] [Algebra R Rₛ] variable (S : Submonoid R) [hT : IsLocalization S Rₛ] variable {A : Type*} [CommRing A] [Algebra R A] variable (Aₛ : Type*) [CommRing Aₛ] [Algebra A Aₛ] variable [Algebra Rₛ Aₛ] [Algebra R Aₛ] [IsScalarTower R Rₛ Aₛ] [IsScalarTower R A Aₛ] variable [hA : IsLocalization (Algebra.algebraMapSubmonoid A S) Aₛ] open Submodule theorem LinearIndependent.localization_localization {ι : Type*} {v : ι → A} (hv : LinearIndependent R v) : LinearIndependent Rₛ ((algebraMap A Aₛ) ∘ v) := hv.of_isLocalizedModule Rₛ S (IsScalarTower.toAlgHom R A Aₛ).toLinearMap theorem span_eq_top_localization_localization {v : Set A} (hv : span R v = ⊤) : span Rₛ (algebraMap A Aₛ '' v) = ⊤ := span_eq_top_of_isLocalizedModule Rₛ S (IsScalarTower.toAlgHom R A Aₛ).toLinearMap hv /-- If `A` has an `R`-basis, then localizing `A` at `S` has a basis over `R` localized at `S`. A suitable instance for `[Algebra A Aₛ]` is `localizationAlgebra`. -/ noncomputable def Basis.localizationLocalization {ι : Type*} (b : Basis ι R A) : Basis ι Rₛ Aₛ := b.ofIsLocalizedModule Rₛ S (IsScalarTower.toAlgHom R A Aₛ).toLinearMap @[simp] theorem Basis.localizationLocalization_apply {ι : Type*} (b : Basis ι R A) (i) : b.localizationLocalization Rₛ S Aₛ i = algebraMap A Aₛ (b i) := b.ofIsLocalizedModule_apply Rₛ S _ i @[simp] theorem Basis.localizationLocalization_repr_algebraMap {ι : Type*} (b : Basis ι R A) (x i) : (b.localizationLocalization Rₛ S Aₛ).repr (algebraMap A Aₛ x) i = algebraMap R Rₛ (b.repr x i) := b.ofIsLocalizedModule_repr_apply Rₛ S _ _ i theorem Basis.localizationLocalization_span {ι : Type*} (b : Basis ι R A) : Submodule.span R (Set.range (b.localizationLocalization Rₛ S Aₛ)) = LinearMap.range (IsScalarTower.toAlgHom R A Aₛ) := b.ofIsLocalizedModule_span Rₛ S _ end LocalizationLocalization section FractionRing variable (R K : Type*) [CommRing R] [Field K] [Algebra R K] [IsFractionRing R K] variable {V : Type*} [AddCommGroup V] [Module R V] [Module K V] [IsScalarTower R K V] theorem LinearIndependent.iff_fractionRing {ι : Type*} {b : ι → V} : LinearIndependent R b ↔ LinearIndependent K b := ⟨LinearIndependent.localization K R⁰, LinearIndependent.restrict_scalars (smul_left_injective R one_ne_zero)⟩ end FractionRing section variable {R : Type*} [CommSemiring R] (S : Submonoid R) variable (A : Type*) [CommSemiring A] [Algebra R A] [IsLocalization S A] variable {M N : Type*} [AddCommMonoid M] [Module R M] [Module A M] [IsScalarTower R A M] [AddCommMonoid N] [Module R N] [Module A N] [IsScalarTower R A N] open IsLocalization /-- An `R`-linear map between two `S⁻¹R`-modules is actually `S⁻¹R`-linear. -/ def LinearMap.extendScalarsOfIsLocalization (f : M →ₗ[R] N) : M →ₗ[A] N where toFun := f map_add' := f.map_add map_smul' := by intro r m simp only [RingHom.id_apply] rcases mk'_surjective S r with ⟨r, s, rfl⟩ calc f (mk' A r s • m) = ((s : R) • mk' A 1 s) • f (mk' A r s • m) := by simp _ = (mk' A 1 s) • (s : R) • f (mk' A r s • m) := by rw [smul_comm, smul_assoc] _ = (mk' A 1 s) • f ((s : R) • mk' A r s • m) := by simp _ = (mk' A 1 s) • f (r • m) := by rw [← smul_assoc, smul_mk'_self, algebraMap_smul] _ = (mk' A 1 s) • r • f m := by simp _ = mk' A r s • f m := by rw [smul_comm, ← smul_assoc, smul_mk'_one] @[simp] lemma LinearMap.restrictScalars_extendScalarsOfIsLocalization (f : M →ₗ[R] N) : (f.extendScalarsOfIsLocalization S A).restrictScalars R = f := rfl @[simp] lemma LinearMap.extendScalarsOfIsLocalization_apply (f : M →ₗ[A] N) : f.extendScalarsOfIsLocalization S A = f := rfl @[simp] lemma LinearMap.extendScalarsOfIsLocalization_apply' (f : M →ₗ[R] N) (x : M) : (f.extendScalarsOfIsLocalization S A) x = f x := rfl end end Localization
RingTheory\Localization\NormTrace.lean
/- Copyright (c) 2023 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.RingTheory.Localization.Module import Mathlib.RingTheory.Norm.Basic import Mathlib.RingTheory.Discriminant /-! # Field/algebra norm / trace and localization This file contains results on the combination of `IsLocalization` and `Algebra.norm`, `Algebra.trace` and `Algebra.discr`. ## Main results * `Algebra.norm_localization`: let `S` be an extension of `R` and `Rₘ Sₘ` be localizations at `M` of `R S` respectively. Then the norm of `a : Sₘ` over `Rₘ` is the norm of `a : S` over `R` if `S` is free as `R`-module. * `Algebra.trace_localization`: let `S` be an extension of `R` and `Rₘ Sₘ` be localizations at `M` of `R S` respectively. Then the trace of `a : Sₘ` over `Rₘ` is the trace of `a : S` over `R` if `S` is free as `R`-module. * `Algebra.discr_localizationLocalization`: let `S` be an extension of `R` and `Rₘ Sₘ` be localizations at `M` of `R S` respectively. Let `b` be a `R`-basis of `S`. Then discriminant of the `Rₘ`-basis of `Sₘ` induced by `b` is the discriminant of `b`. ## Tags field norm, algebra norm, localization -/ open scoped nonZeroDivisors variable (R : Type*) {S : Type*} [CommRing R] [CommRing S] [Algebra R S] variable {Rₘ Sₘ : Type*} [CommRing Rₘ] [Algebra R Rₘ] [CommRing Sₘ] [Algebra S Sₘ] variable (M : Submonoid R) variable [IsLocalization M Rₘ] [IsLocalization (Algebra.algebraMapSubmonoid S M) Sₘ] variable [Algebra Rₘ Sₘ] [Algebra R Sₘ] [IsScalarTower R Rₘ Sₘ] [IsScalarTower R S Sₘ] open Algebra theorem Algebra.map_leftMulMatrix_localization {ι : Type*} [Fintype ι] [DecidableEq ι] (b : Basis ι R S) (a : S) : (algebraMap R Rₘ).mapMatrix (leftMulMatrix b a) = leftMulMatrix (b.localizationLocalization Rₘ M Sₘ) (algebraMap S Sₘ a) := by ext i j simp only [Matrix.map_apply, RingHom.mapMatrix_apply, leftMulMatrix_eq_repr_mul, ← map_mul, Basis.localizationLocalization_apply, Basis.localizationLocalization_repr_algebraMap] /-- Let `S` be an extension of `R` and `Rₘ Sₘ` be localizations at `M` of `R S` respectively. Then the norm of `a : Sₘ` over `Rₘ` is the norm of `a : S` over `R` if `S` is free as `R`-module. -/ theorem Algebra.norm_localization [Module.Free R S] [Module.Finite R S] (a : S) : Algebra.norm Rₘ (algebraMap S Sₘ a) = algebraMap R Rₘ (Algebra.norm R a) := by cases subsingleton_or_nontrivial R · haveI : Subsingleton Rₘ := Module.subsingleton R Rₘ simp [eq_iff_true_of_subsingleton] let b := Module.Free.chooseBasis R S letI := Classical.decEq (Module.Free.ChooseBasisIndex R S) rw [Algebra.norm_eq_matrix_det (b.localizationLocalization Rₘ M Sₘ), Algebra.norm_eq_matrix_det b, RingHom.map_det, ← Algebra.map_leftMulMatrix_localization] variable {M} in /-- The norm of `a : S` in `R` can be computed in `Sₘ`. -/ lemma Algebra.norm_eq_iff [Module.Free R S] [Module.Finite R S] {a : S} {b : R} (hM : M ≤ nonZeroDivisors R) : Algebra.norm R a = b ↔ (Algebra.norm Rₘ) ((algebraMap S Sₘ) a) = algebraMap R Rₘ b := ⟨fun h ↦ h.symm ▸ Algebra.norm_localization _ M _, fun h ↦ IsLocalization.injective Rₘ hM <| h.symm ▸ (Algebra.norm_localization R M a).symm⟩ /-- Let `S` be an extension of `R` and `Rₘ Sₘ` be localizations at `M` of `R S` respectively. Then the trace of `a : Sₘ` over `Rₘ` is the trace of `a : S` over `R` if `S` is free as `R`-module. -/ theorem Algebra.trace_localization [Module.Free R S] [Module.Finite R S] (a : S) : Algebra.trace Rₘ Sₘ (algebraMap S Sₘ a) = algebraMap R Rₘ (Algebra.trace R S a) := by cases subsingleton_or_nontrivial R · haveI : Subsingleton Rₘ := Module.subsingleton R Rₘ simp [eq_iff_true_of_subsingleton] let b := Module.Free.chooseBasis R S letI := Classical.decEq (Module.Free.ChooseBasisIndex R S) rw [Algebra.trace_eq_matrix_trace (b.localizationLocalization Rₘ M Sₘ), Algebra.trace_eq_matrix_trace b, ← Algebra.map_leftMulMatrix_localization] exact (AddMonoidHom.map_trace (algebraMap R Rₘ).toAddMonoidHom _).symm section LocalizationLocalization variable (Sₘ : Type*) [CommRing Sₘ] [Algebra S Sₘ] [Algebra Rₘ Sₘ] [Algebra R Sₘ] variable [IsScalarTower R Rₘ Sₘ] [IsScalarTower R S Sₘ] variable [IsLocalization (Algebra.algebraMapSubmonoid S M) Sₘ] variable {ι : Type*} [Fintype ι] [DecidableEq ι] theorem Algebra.traceMatrix_localizationLocalization (b : Basis ι R S) : Algebra.traceMatrix Rₘ (b.localizationLocalization Rₘ M Sₘ) = (algebraMap R Rₘ).mapMatrix (Algebra.traceMatrix R b) := by have : Module.Finite R S := Module.Finite.of_basis b have : Module.Free R S := Module.Free.of_basis b ext i j : 2 simp_rw [RingHom.mapMatrix_apply, Matrix.map_apply, traceMatrix_apply, traceForm_apply, Basis.localizationLocalization_apply, ← map_mul] exact Algebra.trace_localization R M _ /-- Let `S` be an extension of `R` and `Rₘ Sₘ` be localizations at `M` of `R S` respectively. Let `b` be a `R`-basis of `S`. Then discriminant of the `Rₘ`-basis of `Sₘ` induced by `b` is the discriminant of `b`. -/ theorem Algebra.discr_localizationLocalization (b : Basis ι R S) : Algebra.discr Rₘ (b.localizationLocalization Rₘ M Sₘ) = algebraMap R Rₘ (Algebra.discr R b) := by rw [Algebra.discr_def, Algebra.discr_def, RingHom.map_det, Algebra.traceMatrix_localizationLocalization] end LocalizationLocalization
RingTheory\Localization\NumDen.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen -/ import Mathlib.RingTheory.Localization.FractionRing import Mathlib.RingTheory.Localization.Integer import Mathlib.RingTheory.UniqueFactorizationDomain /-! # Numerator and denominator in a localization ## Implementation notes See `Mathlib/RingTheory/Localization/Basic.lean` for a design overview. ## Tags localization, ring localization, commutative ring localization, characteristic predicate, commutative ring, field of fractions -/ variable {R : Type*} [CommRing R] (M : Submonoid R) {S : Type*} [CommRing S] variable [Algebra R S] {P : Type*} [CommRing P] namespace IsFractionRing open IsLocalization section NumDen variable (A : Type*) [CommRing A] [IsDomain A] [UniqueFactorizationMonoid A] variable {K : Type*} [Field K] [Algebra A K] [IsFractionRing A K] theorem exists_reduced_fraction (x : K) : ∃ (a : A) (b : nonZeroDivisors A), IsRelPrime a b ∧ mk' K a b = x := by obtain ⟨⟨b, b_nonzero⟩, a, hab⟩ := exists_integer_multiple (nonZeroDivisors A) x obtain ⟨a', b', c', no_factor, rfl, rfl⟩ := UniqueFactorizationMonoid.exists_reduced_factors' a b (mem_nonZeroDivisors_iff_ne_zero.mp b_nonzero) obtain ⟨_, b'_nonzero⟩ := mul_mem_nonZeroDivisors.mp b_nonzero refine ⟨a', ⟨b', b'_nonzero⟩, no_factor, ?_⟩ refine mul_left_cancel₀ (IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors b_nonzero) ?_ simp only [Subtype.coe_mk, RingHom.map_mul, Algebra.smul_def] at * erw [← hab, mul_assoc, mk'_spec' _ a' ⟨b', b'_nonzero⟩] /-- `f.num x` is the numerator of `x : f.codomain` as a reduced fraction. -/ noncomputable def num (x : K) : A := Classical.choose (exists_reduced_fraction A x) /-- `f.den x` is the denominator of `x : f.codomain` as a reduced fraction. -/ noncomputable def den (x : K) : nonZeroDivisors A := Classical.choose (Classical.choose_spec (exists_reduced_fraction A x)) theorem num_den_reduced (x : K) : IsRelPrime (num A x) (den A x) := (Classical.choose_spec (Classical.choose_spec (exists_reduced_fraction A x))).1 -- @[simp] -- Porting note: LHS reduces to give the simp lemma below theorem mk'_num_den (x : K) : mk' K (num A x) (den A x) = x := (Classical.choose_spec (Classical.choose_spec (exists_reduced_fraction A x))).2 @[simp] theorem mk'_num_den' (x : K) : algebraMap A K (num A x) / algebraMap A K (den A x) = x := by rw [← mk'_eq_div] apply mk'_num_den variable {A} theorem num_mul_den_eq_num_iff_eq {x y : K} : x * algebraMap A K (den A y) = algebraMap A K (num A y) ↔ x = y := ⟨fun h => by simpa only [mk'_num_den] using eq_mk'_iff_mul_eq.mpr h, fun h ↦ eq_mk'_iff_mul_eq.mp (by rw [h, mk'_num_den])⟩ theorem num_mul_den_eq_num_iff_eq' {x y : K} : y * algebraMap A K (den A x) = algebraMap A K (num A x) ↔ x = y := ⟨fun h ↦ by simpa only [eq_comm, mk'_num_den] using eq_mk'_iff_mul_eq.mpr h, fun h ↦ eq_mk'_iff_mul_eq.mp (by rw [h, mk'_num_den])⟩ theorem num_mul_den_eq_num_mul_den_iff_eq {x y : K} : num A y * den A x = num A x * den A y ↔ x = y := ⟨fun h ↦ by simpa only [mk'_num_den] using mk'_eq_of_eq' (S := K) h, fun h ↦ by rw [h]⟩ theorem eq_zero_of_num_eq_zero {x : K} (h : num A x = 0) : x = 0 := num_mul_den_eq_num_iff_eq'.mp (by rw [zero_mul, h, RingHom.map_zero]) @[simp] lemma num_zero : IsFractionRing.num A (0 : K) = 0 := by have := mk'_num_den' A (0 : K) simp only [div_eq_zero_iff] at this rcases this with h | h · exact NoZeroSMulDivisors.algebraMap_injective A K (by convert h; simp) · replace h : algebraMap A K (den A (0 : K)) = algebraMap A K 0 := by convert h; simp absurd NoZeroSMulDivisors.algebraMap_injective A K h apply nonZeroDivisors.coe_ne_zero @[simp] lemma num_eq_zero (x : K) : IsFractionRing.num A x = 0 ↔ x = 0 := ⟨eq_zero_of_num_eq_zero, fun h ↦ h ▸ num_zero⟩ theorem isInteger_of_isUnit_den {x : K} (h : IsUnit (den A x : A)) : IsInteger A x := by cases' h with d hd have d_ne_zero : algebraMap A K (den A x) ≠ 0 := IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors (den A x).2 use ↑d⁻¹ * num A x refine _root_.trans ?_ (mk'_num_den A x) rw [map_mul, map_units_inv, hd] apply mul_left_cancel₀ d_ne_zero rw [← mul_assoc, mul_inv_cancel d_ne_zero, one_mul, mk'_spec'] theorem isUnit_den_iff (x : K) : IsUnit (den A x : A) ↔ IsLocalization.IsInteger A x where mp h := by obtain ⟨den, hd⟩ := IsUnit.exists_right_inv h use (num A x) * den conv => rhs; rw [← mk'_num_den' A x] rw [map_mul, div_eq_mul_inv] congr 1 apply eq_inv_of_mul_eq_one_right rw [← map_mul] norm_cast simp only [hd, OneMemClass.coe_one, map_one] mpr h := by have ⟨v, h⟩ := h apply IsRelPrime.isUnit_of_dvd (num_den_reduced A x).symm use v apply_fun algebraMap A K · simp only [map_mul, h] rw [mul_comm, ← div_eq_iff] · simp only [mk'_num_den'] intro h replace h : algebraMap A K (den A x : A) = algebraMap A K 0 := by convert h; simp exact nonZeroDivisors.coe_ne_zero _ <| NoZeroSMulDivisors.algebraMap_injective A K h exact NoZeroSMulDivisors.algebraMap_injective A K theorem isUnit_den_zero : IsUnit (den A (0 : K) : A) := by simp [isUnit_den_iff, IsLocalization.isInteger_zero] @[deprecated isUnit_den_zero (since := "2024-07-11")] theorem isUnit_den_of_num_eq_zero {x : K} (h : num A x = 0) : IsUnit (den A x : A) := eq_zero_of_num_eq_zero h ▸ isUnit_den_zero lemma associated_den_num_inv (x : K) (hx : x ≠ 0) : Associated (den A x : A) (num A x⁻¹) := associated_of_dvd_dvd (IsRelPrime.dvd_of_dvd_mul_right (IsFractionRing.num_den_reduced A x).symm <| dvd_of_mul_left_dvd (a := (den A x⁻¹ : A)) <| dvd_of_eq <| NoZeroSMulDivisors.algebraMap_injective A K <| Eq.symm <| eq_of_div_eq_one (by simp [mul_div_mul_comm, hx])) (IsRelPrime.dvd_of_dvd_mul_right (IsFractionRing.num_den_reduced A x⁻¹) <| dvd_of_mul_left_dvd (a := (num A x : A)) <| dvd_of_eq <| NoZeroSMulDivisors.algebraMap_injective A K <| eq_of_div_eq_one (by simp [mul_div_mul_comm, hx])) lemma associated_num_den_inv (x : K) (hx : x ≠ 0) : Associated (num A x : A) (den A x⁻¹) := by have : Associated (num A x⁻¹⁻¹ : A) (den A x⁻¹) := (associated_den_num_inv x⁻¹ (inv_ne_zero hx)).symm rw [inv_inv] at this exact this end NumDen variable (S) end IsFractionRing
RingTheory\Localization\Submodule.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen -/ import Mathlib.RingTheory.Localization.FractionRing import Mathlib.RingTheory.Localization.Ideal import Mathlib.RingTheory.Noetherian /-! # Submodules in localizations of commutative rings ## Implementation notes See `RingTheory/Localization/Basic.lean` for a design overview. ## Tags localization, ring localization, commutative ring localization, characteristic predicate, commutative ring, field of fractions -/ variable {R : Type*} [CommRing R] (M : Submonoid R) (S : Type*) [CommRing S] variable [Algebra R S] {P : Type*} [CommRing P] namespace IsLocalization -- This was previously a `hasCoe` instance, but if `S = R` then this will loop. -- It could be a `hasCoeT` instance, but we keep it explicit here to avoid slowing down -- the rest of the library. /-- Map from ideals of `R` to submodules of `S` induced by `f`. -/ def coeSubmodule (I : Ideal R) : Submodule R S := Submodule.map (Algebra.linearMap R S) I theorem mem_coeSubmodule (I : Ideal R) {x : S} : x ∈ coeSubmodule S I ↔ ∃ y : R, y ∈ I ∧ algebraMap R S y = x := Iff.rfl theorem coeSubmodule_mono {I J : Ideal R} (h : I ≤ J) : coeSubmodule S I ≤ coeSubmodule S J := Submodule.map_mono h @[simp] theorem coeSubmodule_bot : coeSubmodule S (⊥ : Ideal R) = ⊥ := by rw [coeSubmodule, Submodule.map_bot] @[simp] theorem coeSubmodule_top : coeSubmodule S (⊤ : Ideal R) = 1 := by rw [coeSubmodule, Submodule.map_top, Submodule.one_eq_range] @[simp] theorem coeSubmodule_sup (I J : Ideal R) : coeSubmodule S (I ⊔ J) = coeSubmodule S I ⊔ coeSubmodule S J := Submodule.map_sup _ _ _ @[simp] theorem coeSubmodule_mul (I J : Ideal R) : coeSubmodule S (I * J) = coeSubmodule S I * coeSubmodule S J := Submodule.map_mul _ _ (Algebra.ofId R S) theorem coeSubmodule_fg (hS : Function.Injective (algebraMap R S)) (I : Ideal R) : Submodule.FG (coeSubmodule S I) ↔ Submodule.FG I := ⟨Submodule.fg_of_fg_map _ (LinearMap.ker_eq_bot.mpr hS), Submodule.FG.map _⟩ @[simp] theorem coeSubmodule_span (s : Set R) : coeSubmodule S (Ideal.span s) = Submodule.span R (algebraMap R S '' s) := by rw [IsLocalization.coeSubmodule, Ideal.span, Submodule.map_span] rfl -- @[simp] -- Porting note (#10618): simp can prove this theorem coeSubmodule_span_singleton (x : R) : coeSubmodule S (Ideal.span {x}) = Submodule.span R {(algebraMap R S) x} := by rw [coeSubmodule_span, Set.image_singleton] variable {g : R →+* P} variable {T : Submonoid P} (hy : M ≤ T.comap g) {Q : Type*} [CommRing Q] variable [Algebra P Q] [IsLocalization T Q] variable [IsLocalization M S] section theorem isNoetherianRing (h : IsNoetherianRing R) : IsNoetherianRing S := by rw [isNoetherianRing_iff, isNoetherian_iff_wellFounded] at h ⊢ exact OrderEmbedding.wellFounded (IsLocalization.orderEmbedding M S).dual h end variable {S M} @[mono] theorem coeSubmodule_le_coeSubmodule (h : M ≤ nonZeroDivisors R) {I J : Ideal R} : coeSubmodule S I ≤ coeSubmodule S J ↔ I ≤ J := -- Note: #8386 had to specify the value of `f` here: Submodule.map_le_map_iff_of_injective (f := Algebra.linearMap R S) (IsLocalization.injective _ h) _ _ @[mono] theorem coeSubmodule_strictMono (h : M ≤ nonZeroDivisors R) : StrictMono (coeSubmodule S : Ideal R → Submodule R S) := strictMono_of_le_iff_le fun _ _ => (coeSubmodule_le_coeSubmodule h).symm variable (S) theorem coeSubmodule_injective (h : M ≤ nonZeroDivisors R) : Function.Injective (coeSubmodule S : Ideal R → Submodule R S) := injective_of_le_imp_le _ fun hl => (coeSubmodule_le_coeSubmodule h).mp hl theorem coeSubmodule_isPrincipal {I : Ideal R} (h : M ≤ nonZeroDivisors R) : (coeSubmodule S I).IsPrincipal ↔ I.IsPrincipal := by constructor <;> rintro ⟨⟨x, hx⟩⟩ · have x_mem : x ∈ coeSubmodule S I := hx.symm ▸ Submodule.mem_span_singleton_self x obtain ⟨x, _, rfl⟩ := (mem_coeSubmodule _ _).mp x_mem refine ⟨⟨x, coeSubmodule_injective S h ?_⟩⟩ rw [Ideal.submodule_span_eq, hx, coeSubmodule_span_singleton] · refine ⟨⟨algebraMap R S x, ?_⟩⟩ rw [hx, Ideal.submodule_span_eq, coeSubmodule_span_singleton] variable {S} (M) theorem mem_span_iff {N : Type*} [AddCommGroup N] [Module R N] [Module S N] [IsScalarTower R S N] {x : N} {a : Set N} : x ∈ Submodule.span S a ↔ ∃ y ∈ Submodule.span R a, ∃ z : M, x = mk' S 1 z • y := by constructor · intro h refine Submodule.span_induction h ?_ ?_ ?_ ?_ · rintro x hx exact ⟨x, Submodule.subset_span hx, 1, by rw [mk'_one, _root_.map_one, one_smul]⟩ · exact ⟨0, Submodule.zero_mem _, 1, by rw [mk'_one, _root_.map_one, one_smul]⟩ · rintro _ _ ⟨y, hy, z, rfl⟩ ⟨y', hy', z', rfl⟩ refine ⟨(z' : R) • y + (z : R) • y', Submodule.add_mem _ (Submodule.smul_mem _ _ hy) (Submodule.smul_mem _ _ hy'), z * z', ?_⟩ rw [smul_add, ← IsScalarTower.algebraMap_smul S (z : R), ← IsScalarTower.algebraMap_smul S (z' : R), smul_smul, smul_smul] congr 1 · rw [← mul_one (1 : R), mk'_mul, mul_assoc, mk'_spec, _root_.map_one, mul_one, mul_one] · rw [← mul_one (1 : R), mk'_mul, mul_right_comm, mk'_spec, _root_.map_one, mul_one, one_mul] · rintro a _ ⟨y, hy, z, rfl⟩ obtain ⟨y', z', rfl⟩ := mk'_surjective M a refine ⟨y' • y, Submodule.smul_mem _ _ hy, z' * z, ?_⟩ rw [← IsScalarTower.algebraMap_smul S y', smul_smul, ← mk'_mul, smul_smul, mul_comm (mk' S _ _), mul_mk'_eq_mk'_of_mul] · rintro ⟨y, hy, z, rfl⟩ exact Submodule.smul_mem _ _ (Submodule.span_subset_span R S _ hy) theorem mem_span_map {x : S} {a : Set R} : x ∈ Ideal.span (algebraMap R S '' a) ↔ ∃ y ∈ Ideal.span a, ∃ z : M, x = mk' S y z := by refine (mem_span_iff M).trans ?_ constructor · rw [← coeSubmodule_span] rintro ⟨_, ⟨y, hy, rfl⟩, z, hz⟩ refine ⟨y, hy, z, ?_⟩ rw [hz, Algebra.linearMap_apply, smul_eq_mul, mul_comm, mul_mk'_eq_mk'_of_mul, mul_one] · rintro ⟨y, hy, z, hz⟩ refine ⟨algebraMap R S y, Submodule.map_mem_span_algebraMap_image _ _ hy, z, ?_⟩ rw [hz, smul_eq_mul, mul_comm, mul_mk'_eq_mk'_of_mul, mul_one] end IsLocalization namespace IsFractionRing open IsLocalization variable {A K : Type*} [CommRing A] section CommRing variable [CommRing K] [Algebra R K] [IsFractionRing R K] [Algebra A K] [IsFractionRing A K] @[simp, mono] theorem coeSubmodule_le_coeSubmodule {I J : Ideal R} : coeSubmodule K I ≤ coeSubmodule K J ↔ I ≤ J := IsLocalization.coeSubmodule_le_coeSubmodule le_rfl @[mono] theorem coeSubmodule_strictMono : StrictMono (coeSubmodule K : Ideal R → Submodule R K) := strictMono_of_le_iff_le fun _ _ => coeSubmodule_le_coeSubmodule.symm variable (R K) theorem coeSubmodule_injective : Function.Injective (coeSubmodule K : Ideal R → Submodule R K) := injective_of_le_imp_le _ fun hl => coeSubmodule_le_coeSubmodule.mp hl @[simp] theorem coeSubmodule_isPrincipal {I : Ideal R} : (coeSubmodule K I).IsPrincipal ↔ I.IsPrincipal := IsLocalization.coeSubmodule_isPrincipal _ le_rfl end CommRing end IsFractionRing
RingTheory\Localization\Away\AdjoinRoot.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen -/ import Mathlib.RingTheory.AdjoinRoot import Mathlib.RingTheory.Localization.Away.Basic /-! The `R`-`AlgEquiv` between the localization of `R` away from `r` and `R` with an inverse of `r` adjoined. -/ open Polynomial AdjoinRoot Localization variable {R : Type*} [CommRing R] -- Porting note: removed `IsLocalization.algHom_subsingleton` due to -- `cannot find synthesization order for instance` attribute [local instance] AdjoinRoot.algHom_subsingleton /-- The `R`-`AlgEquiv` between the localization of `R` away from `r` and `R` with an inverse of `r` adjoined. -/ noncomputable def Localization.awayEquivAdjoin (r : R) : Away r ≃ₐ[R] AdjoinRoot (C r * X - 1) := AlgEquiv.ofAlgHom { awayLift _ r -- Porting note: This argument used to be found automatically, i.e. `_` (isUnit_of_mul_eq_one ((algebraMap R (AdjoinRoot (C r * X - 1))) r) (root (C r * X - 1)) (root_isInv r)) with commutes' := IsLocalization.Away.AwayMap.lift_eq r (isUnit_of_mul_eq_one _ _ <| root_isInv r) } (liftHom _ (IsLocalization.Away.invSelf r) <| by simp only [map_sub, map_mul, aeval_C, aeval_X, IsLocalization.Away.mul_invSelf, aeval_one, sub_self]) (Subsingleton.elim _ _) -- Porting note: fix since `IsLocalization.algHom_subsingleton` is no local instance anymore (Subsingleton.elim (h := IsLocalization.algHom_subsingleton (Submonoid.powers r)) _ _) theorem IsLocalization.adjoin_inv (r : R) : IsLocalization.Away r (AdjoinRoot <| C r * X - 1) := IsLocalization.isLocalization_of_algEquiv _ (Localization.awayEquivAdjoin r) theorem IsLocalization.Away.finitePresentation (r : R) {S} [CommRing S] [Algebra R S] [IsLocalization.Away r S] : Algebra.FinitePresentation R S := (AdjoinRoot.finitePresentation _).equiv <| (Localization.awayEquivAdjoin r).symm.trans <| IsLocalization.algEquiv (Submonoid.powers r) _ _
RingTheory\Localization\Away\Basic.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen -/ import Mathlib.RingTheory.UniqueFactorizationDomain import Mathlib.RingTheory.Localization.Basic /-! # Localizations away from an element ## Main definitions * `IsLocalization.Away (x : R) S` expresses that `S` is a localization away from `x`, as an abbreviation of `IsLocalization (Submonoid.powers x) S`. * `exists_reduced_fraction' (hb : b ≠ 0)` produces a reduced fraction of the form `b = a * x^n` for some `n : ℤ` and some `a : R` that is not divisible by `x`. ## Implementation notes See `Mathlib/RingTheory/Localization/Basic.lean` for a design overview. ## Tags localization, ring localization, commutative ring localization, characteristic predicate, commutative ring, field of fractions -/ section CommSemiring variable {R : Type*} [CommSemiring R] (M : Submonoid R) {S : Type*} [CommSemiring S] variable [Algebra R S] {P : Type*} [CommSemiring P] namespace IsLocalization section Away variable (x : R) /-- Given `x : R`, the typeclass `IsLocalization.Away x S` states that `S` is isomorphic to the localization of `R` at the submonoid generated by `x`. -/ abbrev Away (S : Type*) [CommSemiring S] [Algebra R S] := IsLocalization (Submonoid.powers x) S namespace Away variable [IsLocalization.Away x S] /-- Given `x : R` and a localization map `F : R →+* S` away from `x`, `invSelf` is `(F x)⁻¹`. -/ noncomputable def invSelf : S := mk' S (1 : R) ⟨x, Submonoid.mem_powers _⟩ @[simp] theorem mul_invSelf : algebraMap R S x * invSelf x = 1 := by convert IsLocalization.mk'_mul_mk'_eq_one (M := Submonoid.powers x) (S := S) _ 1 symm apply IsLocalization.mk'_one /-- For `s : S` with `S` being the localization of `R` away from `x`, this is a choice of `(r, n) : R × ℕ` such that `s * algebraMap R S (x ^ n) = algebraMap R S r`. -/ noncomputable def sec (s : S) : R × ℕ := ⟨(IsLocalization.sec (Submonoid.powers x) s).1, (IsLocalization.sec (Submonoid.powers x) s).2.property.choose⟩ lemma sec_spec (s : S) : s * (algebraMap R S) (x ^ (IsLocalization.Away.sec x s).2) = algebraMap R S (IsLocalization.Away.sec x s).1 := by simp only [IsLocalization.Away.sec, ← IsLocalization.sec_spec] congr exact (IsLocalization.sec (Submonoid.powers x) s).2.property.choose_spec variable {g : R →+* P} /-- Given `x : R`, a localization map `F : R →+* S` away from `x`, and a map of `CommSemiring`s `g : R →+* P` such that `g x` is invertible, the homomorphism induced from `S` to `P` sending `z : S` to `g y * (g x)⁻ⁿ`, where `y : R, n : ℕ` are such that `z = F y * (F x)⁻ⁿ`. -/ noncomputable def lift (hg : IsUnit (g x)) : S →+* P := IsLocalization.lift fun y : Submonoid.powers x => show IsUnit (g y.1) by obtain ⟨n, hn⟩ := y.2 rw [← hn, g.map_pow] exact IsUnit.map (powMonoidHom n : P →* P) hg @[simp] theorem AwayMap.lift_eq (hg : IsUnit (g x)) (a : R) : lift x hg ((algebraMap R S) a) = g a := IsLocalization.lift_eq _ _ @[simp] theorem AwayMap.lift_comp (hg : IsUnit (g x)) : (lift x hg).comp (algebraMap R S) = g := IsLocalization.lift_comp _ /-- Given `x y : R` and localizations `S`, `P` away from `x` and `x * y` respectively, the homomorphism induced from `S` to `P`. -/ noncomputable def awayToAwayRight (y : R) [Algebra R P] [IsLocalization.Away (x * y) P] : S →+* P := lift x <| show IsUnit ((algebraMap R P) x) from isUnit_of_mul_eq_one ((algebraMap R P) x) (mk' P y ⟨x * y, Submonoid.mem_powers _⟩) <| by rw [mul_mk'_eq_mk'_of_mul, mk'_self] variable (S) (Q : Type*) [CommSemiring Q] [Algebra P Q] /-- Given a map `f : R →+* S` and an element `r : R`, we may construct a map `Rᵣ →+* Sᵣ`. -/ noncomputable def map (f : R →+* P) (r : R) [IsLocalization.Away r S] [IsLocalization.Away (f r) Q] : S →+* Q := IsLocalization.map Q f (show Submonoid.powers r ≤ (Submonoid.powers (f r)).comap f by rintro x ⟨n, rfl⟩ use n simp) section Algebra variable {A : Type*} [CommRing A] [Algebra R A] variable {B : Type*} [CommRing B] [Algebra R B] variable (Aₚ : Type*) [CommRing Aₚ] [Algebra A Aₚ] [Algebra R Aₚ] [IsScalarTower R A Aₚ] variable (Bₚ : Type*) [CommRing Bₚ] [Algebra B Bₚ] [Algebra R Bₚ] [IsScalarTower R B Bₚ] instance {f : A →+* B} (a : A) [Away (f a) Bₚ] : IsLocalization (.map f (.powers a)) Bₚ := by simpa /-- Given a algebra map `f : A →ₐ[R] B` and an element `a : A`, we may construct a map `Aₐ →ₐ[R] Bₐ`. -/ noncomputable def mapₐ (f : A →ₐ[R] B) (a : A) [Away a Aₚ] [Away (f a) Bₚ] : Aₚ →ₐ[R] Bₚ := ⟨map Aₚ Bₚ f.toRingHom a, fun r ↦ by dsimp only [AlgHom.toRingHom_eq_coe, map, RingHom.coe_coe, OneHom.toFun_eq_coe] rw [IsScalarTower.algebraMap_apply R A Aₚ, IsScalarTower.algebraMap_eq R B Bₚ] erw [IsLocalization.map_eq] simp⟩ @[simp] lemma mapₐ_apply (f : A →ₐ[R] B) (a : A) [Away a Aₚ] [Away (f a) Bₚ] (x : Aₚ) : mapₐ Aₚ Bₚ f a x = map Aₚ Bₚ f.toRingHom a x := rfl variable {Aₚ} {Bₚ} lemma mapₐ_injective_of_injective {f : A →ₐ[R] B} (a : A) [Away a Aₚ] [Away (f a) Bₚ] (hf : Function.Injective f) : Function.Injective (mapₐ Aₚ Bₚ f a) := IsLocalization.map_injective_of_injective _ _ _ hf lemma mapₐ_surjective_of_surjective {f : A →ₐ[R] B} (a : A) [Away a Aₚ] [Away (f a) Bₚ] (hf : Function.Surjective f) : Function.Surjective (mapₐ Aₚ Bₚ f a) := have : IsLocalization (Submonoid.map f.toRingHom (Submonoid.powers a)) Bₚ := by simp only [AlgHom.toRingHom_eq_coe, Submonoid.map_powers, RingHom.coe_coe] infer_instance IsLocalization.map_surjective_of_surjective _ _ _ hf end Algebra end Away end Away variable [IsLocalization M S] section AtUnits variable (R) (S) /-- The localization away from a unit is isomorphic to the ring. -/ noncomputable def atUnit (x : R) (e : IsUnit x) [IsLocalization.Away x S] : R ≃ₐ[R] S := atUnits R (Submonoid.powers x) (by rwa [Submonoid.powers_eq_closure, Submonoid.closure_le, Set.singleton_subset_iff]) /-- The localization at one is isomorphic to the ring. -/ noncomputable def atOne [IsLocalization.Away (1 : R) S] : R ≃ₐ[R] S := @atUnit R _ S _ _ (1 : R) isUnit_one _ theorem away_of_isUnit_of_bijective {R : Type*} (S : Type*) [CommRing R] [CommRing S] [Algebra R S] {r : R} (hr : IsUnit r) (H : Function.Bijective (algebraMap R S)) : IsLocalization.Away r S := { map_units' := by rintro ⟨_, n, rfl⟩ exact (algebraMap R S).isUnit_map (hr.pow _) surj' := fun z => by obtain ⟨z', rfl⟩ := H.2 z exact ⟨⟨z', 1⟩, by simp⟩ exists_of_eq := fun {x y} => by erw [H.1.eq_iff] rintro rfl exact ⟨1, rfl⟩ } end AtUnits section Prod lemma away_of_isIdempotentElem {R S} [CommRing R] [CommRing S] [Algebra R S] {e : R} (he : IsIdempotentElem e) (H : RingHom.ker (algebraMap R S) = Ideal.span {1 - e}) (H' : Function.Surjective (algebraMap R S)) : IsLocalization.Away e S where map_units' r := by have : algebraMap R S e = 1 := by rw [← (algebraMap R S).map_one, eq_comm, ← sub_eq_zero, ← map_sub, ← RingHom.mem_ker, H, Ideal.mem_span_singleton] obtain ⟨r, n, rfl⟩ := r simp [this] surj' z := by obtain ⟨z, rfl⟩ := H' z exact ⟨⟨z, 1⟩, by simp⟩ exists_of_eq {x y} h := by rw [← sub_eq_zero, ← map_sub, ← RingHom.mem_ker, H, Ideal.mem_span_singleton] at h obtain ⟨k, hk⟩ := h refine ⟨⟨e, Submonoid.mem_powers e⟩, ?_⟩ rw [← sub_eq_zero, ← mul_sub, hk, ← mul_assoc, mul_sub, mul_one, he.eq, sub_self, zero_mul] instance away_fst {R S} [CommRing R] [CommRing S] : letI := (RingHom.fst R S).toAlgebra IsLocalization.Away (R := R × S) (1, 0) R := by letI := (RingHom.fst R S).toAlgebra apply away_of_isIdempotentElem · ext <;> simp · ext x simp only [RingHom.algebraMap_toAlgebra, RingHom.mem_ker, RingHom.coe_fst, Ideal.mem_span_singleton, Prod.one_eq_mk, Prod.mk_sub_mk, sub_self, sub_zero] constructor · intro e; use x; ext <;> simp [e] · rintro ⟨⟨i, j⟩, rfl⟩; simp · exact Prod.fst_surjective instance away_snd {R S} [CommRing R] [CommRing S] : letI := (RingHom.snd R S).toAlgebra IsLocalization.Away (R := R × S) (0, 1) S := by letI := (RingHom.snd R S).toAlgebra apply away_of_isIdempotentElem · ext <;> simp · ext x simp only [RingHom.algebraMap_toAlgebra, RingHom.mem_ker, RingHom.coe_snd, Ideal.mem_span_singleton, Prod.one_eq_mk, Prod.mk_sub_mk, sub_self, sub_zero] constructor · intro e; use x; ext <;> simp [e] · rintro ⟨⟨i, j⟩, rfl⟩; simp · exact Prod.snd_surjective end Prod end IsLocalization namespace Localization open IsLocalization variable {M} /-- Given a map `f : R →+* S` and an element `r : R`, such that `f r` is invertible, we may construct a map `Rᵣ →+* S`. -/ noncomputable abbrev awayLift (f : R →+* P) (r : R) (hr : IsUnit (f r)) : Localization.Away r →+* P := IsLocalization.Away.lift r hr /-- Given a map `f : R →+* S` and an element `r : R`, we may construct a map `Rᵣ →+* Sᵣ`. -/ noncomputable abbrev awayMap (f : R →+* P) (r : R) : Localization.Away r →+* Localization.Away (f r) := IsLocalization.Away.map _ _ f r variable {A : Type*} [CommRing A] [Algebra R A] variable {B : Type*} [CommRing B] [Algebra R B] /-- Given a map `f : A →ₐ[R] B` and an element `a : A`, we may construct a map `Aₐ →ₐ[R] Bₐ`. -/ noncomputable abbrev awayMapₐ (f : A →ₐ[R] B) (a : A) : Localization.Away a →ₐ[R] Localization.Away (f a) := IsLocalization.Away.mapₐ _ _ f a end Localization end CommSemiring open Localization variable {R : Type*} [CommRing R] section NumDen open IsLocalization variable (x : R) variable (B : Type*) [CommRing B] [Algebra R B] [IsLocalization.Away x B] /-- `selfZPow x (m : ℤ)` is `x ^ m` as an element of the localization away from `x`. -/ noncomputable def selfZPow (m : ℤ) : B := if _ : 0 ≤ m then algebraMap _ _ x ^ m.natAbs else mk' _ (1 : R) (Submonoid.pow x m.natAbs) theorem selfZPow_of_nonneg {n : ℤ} (hn : 0 ≤ n) : selfZPow x B n = algebraMap R B x ^ n.natAbs := dif_pos hn @[simp] theorem selfZPow_natCast (d : ℕ) : selfZPow x B d = algebraMap R B x ^ d := selfZPow_of_nonneg _ _ (Int.natCast_nonneg d) @[simp] theorem selfZPow_zero : selfZPow x B 0 = 1 := by simp [selfZPow_of_nonneg _ _ le_rfl] theorem selfZPow_of_neg {n : ℤ} (hn : n < 0) : selfZPow x B n = mk' _ (1 : R) (Submonoid.pow x n.natAbs) := dif_neg hn.not_le theorem selfZPow_of_nonpos {n : ℤ} (hn : n ≤ 0) : selfZPow x B n = mk' _ (1 : R) (Submonoid.pow x n.natAbs) := by by_cases hn0 : n = 0 · simp [hn0, selfZPow_zero, Submonoid.pow_apply] · simp [selfZPow_of_neg _ _ (lt_of_le_of_ne hn hn0)] @[simp] theorem selfZPow_neg_natCast (d : ℕ) : selfZPow x B (-d) = mk' _ (1 : R) (Submonoid.pow x d) := by simp [selfZPow_of_nonpos _ _ (neg_nonpos.mpr (Int.natCast_nonneg d))] @[simp] theorem selfZPow_sub_natCast {n m : ℕ} : selfZPow x B (n - m) = mk' _ (x ^ n) (Submonoid.pow x m) := by by_cases h : m ≤ n · rw [IsLocalization.eq_mk'_iff_mul_eq, Submonoid.pow_apply, Subtype.coe_mk, ← Int.ofNat_sub h, selfZPow_natCast, ← map_pow, ← map_mul, ← pow_add, Nat.sub_add_cancel h] · rw [← neg_sub, ← Int.ofNat_sub (le_of_not_le h), selfZPow_neg_natCast, IsLocalization.mk'_eq_iff_eq] simp [Submonoid.pow_apply, ← pow_add, Nat.sub_add_cancel (le_of_not_le h)] @[deprecated (since := "2024-04-05")] alias selfZPow_coe_nat := selfZPow_natCast @[deprecated (since := "2024-04-05")] alias selfZPow_neg_coe_nat := selfZPow_neg_natCast @[deprecated (since := "2024-04-05")] alias selfZPow_sub_cast_nat := selfZPow_sub_natCast @[simp] theorem selfZPow_add {n m : ℤ} : selfZPow x B (n + m) = selfZPow x B n * selfZPow x B m := by rcases le_or_lt 0 n with hn | hn <;> rcases le_or_lt 0 m with hm | hm · rw [selfZPow_of_nonneg _ _ hn, selfZPow_of_nonneg _ _ hm, selfZPow_of_nonneg _ _ (add_nonneg hn hm), Int.natAbs_add_of_nonneg hn hm, pow_add] · have : n + m = n.natAbs - m.natAbs := by rw [Int.natAbs_of_nonneg hn, Int.ofNat_natAbs_of_nonpos hm.le, sub_neg_eq_add] rw [selfZPow_of_nonneg _ _ hn, selfZPow_of_neg _ _ hm, this, selfZPow_sub_natCast, IsLocalization.mk'_eq_mul_mk'_one, map_pow] · have : n + m = m.natAbs - n.natAbs := by rw [Int.natAbs_of_nonneg hm, Int.ofNat_natAbs_of_nonpos hn.le, sub_neg_eq_add, add_comm] rw [selfZPow_of_nonneg _ _ hm, selfZPow_of_neg _ _ hn, this, selfZPow_sub_natCast, IsLocalization.mk'_eq_mul_mk'_one, map_pow, mul_comm] · rw [selfZPow_of_neg _ _ hn, selfZPow_of_neg _ _ hm, selfZPow_of_neg _ _ (add_neg hn hm), Int.natAbs_add_of_nonpos hn.le hm.le, ← mk'_mul, one_mul] congr ext simp [pow_add] theorem selfZPow_mul_neg (d : ℤ) : selfZPow x B d * selfZPow x B (-d) = 1 := by by_cases hd : d ≤ 0 · erw [selfZPow_of_nonpos x B hd, selfZPow_of_nonneg, ← map_pow, Int.natAbs_neg, IsLocalization.mk'_spec, map_one] apply nonneg_of_neg_nonpos rwa [neg_neg] · erw [selfZPow_of_nonneg x B (le_of_not_le hd), selfZPow_of_nonpos, ← map_pow, Int.natAbs_neg, @IsLocalization.mk'_spec' R _ (Submonoid.powers x) B _ _ _ 1 (Submonoid.pow x d.natAbs), map_one] refine nonpos_of_neg_nonneg (le_of_lt ?_) rwa [neg_neg, ← not_le] theorem selfZPow_neg_mul (d : ℤ) : selfZPow x B (-d) * selfZPow x B d = 1 := by rw [mul_comm, selfZPow_mul_neg x B d] theorem selfZPow_pow_sub (a : R) (b : B) (m d : ℤ) : selfZPow x B (m - d) * mk' B a (1 : Submonoid.powers x) = b ↔ selfZPow x B m * mk' B a (1 : Submonoid.powers x) = selfZPow x B d * b := by rw [sub_eq_add_neg, selfZPow_add, mul_assoc, mul_comm _ (mk' B a 1), ← mul_assoc] constructor · intro h have := congr_arg (fun s : B => s * selfZPow x B d) h simp only at this rwa [mul_assoc, mul_assoc, selfZPow_neg_mul, mul_one, mul_comm b _] at this · intro h have := congr_arg (fun s : B => s * selfZPow x B (-d)) h simp only at this rwa [mul_comm _ b, mul_assoc b _ _, selfZPow_mul_neg, mul_one] at this variable [IsDomain R] [WfDvdMonoid R] theorem exists_reduced_fraction' {b : B} (hb : b ≠ 0) (hx : Irreducible x) : ∃ (a : R) (n : ℤ), ¬x ∣ a ∧ selfZPow x B n * algebraMap R B a = b := by obtain ⟨⟨a₀, y⟩, H⟩ := surj (Submonoid.powers x) b obtain ⟨d, hy⟩ := (Submonoid.mem_powers_iff y.1 x).mp y.2 have ha₀ : a₀ ≠ 0 := by haveI := @isDomain_of_le_nonZeroDivisors B _ R _ _ _ (Submonoid.powers x) _ (powers_le_nonZeroDivisors_of_noZeroDivisors hx.ne_zero) simp only [map_zero, ← hy, map_pow] at H apply ((injective_iff_map_eq_zero' (algebraMap R B)).mp _ a₀).mpr.mt · rw [← H] apply mul_ne_zero hb (pow_ne_zero _ _) exact IsLocalization.to_map_ne_zero_of_mem_nonZeroDivisors B (powers_le_nonZeroDivisors_of_noZeroDivisors hx.ne_zero) (mem_nonZeroDivisors_iff_ne_zero.mpr hx.ne_zero) · exact IsLocalization.injective B (powers_le_nonZeroDivisors_of_noZeroDivisors hx.ne_zero) simp only [← hy] at H obtain ⟨m, a, hyp1, hyp2⟩ := WfDvdMonoid.max_power_factor ha₀ hx refine ⟨a, m - d, ?_⟩ rw [← mk'_one (M := Submonoid.powers x) B, selfZPow_pow_sub, selfZPow_natCast, selfZPow_natCast, ← map_pow _ _ d, mul_comm _ b, H, hyp2, map_mul, map_pow _ _ m] exact ⟨hyp1, congr_arg _ (IsLocalization.mk'_one _ _)⟩ end NumDen
RingTheory\LocalRing\Basic.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Chris Hughes, Mario Carneiro -/ import Mathlib.RingTheory.LocalRing.Defs import Mathlib.RingTheory.Ideal.Basic /-! # Local rings We prove basic properties of local rings. -/ variable {R S : Type*} section CommSemiring variable [CommSemiring R] namespace LocalRing theorem of_isUnit_or_isUnit_of_isUnit_add [Nontrivial R] (h : ∀ a b : R, IsUnit (a + b) → IsUnit a ∨ IsUnit b) : LocalRing R := ⟨fun {a b} hab => h a b <| hab.symm ▸ isUnit_one⟩ /-- A semiring is local if it is nontrivial and the set of nonunits is closed under the addition. -/ theorem of_nonunits_add [Nontrivial R] (h : ∀ a b : R, a ∈ nonunits R → b ∈ nonunits R → a + b ∈ nonunits R) : LocalRing R := ⟨fun {a b} hab => or_iff_not_and_not.2 fun H => h a b H.1 H.2 <| hab.symm ▸ isUnit_one⟩ /-- A semiring is local if it has a unique maximal ideal. -/ theorem of_unique_max_ideal (h : ∃! I : Ideal R, I.IsMaximal) : LocalRing R := @of_nonunits_add _ _ (nontrivial_of_ne (0 : R) 1 <| let ⟨I, Imax, _⟩ := h fun H : 0 = 1 => Imax.1.1 <| I.eq_top_iff_one.2 <| H ▸ I.zero_mem) fun x y hx hy H => let ⟨I, Imax, Iuniq⟩ := h let ⟨Ix, Ixmax, Hx⟩ := exists_max_ideal_of_mem_nonunits hx let ⟨Iy, Iymax, Hy⟩ := exists_max_ideal_of_mem_nonunits hy have xmemI : x ∈ I := Iuniq Ix Ixmax ▸ Hx have ymemI : y ∈ I := Iuniq Iy Iymax ▸ Hy Imax.1.1 <| I.eq_top_of_isUnit_mem (I.add_mem xmemI ymemI) H theorem of_unique_nonzero_prime (h : ∃! P : Ideal R, P ≠ ⊥ ∧ Ideal.IsPrime P) : LocalRing R := of_unique_max_ideal (by rcases h with ⟨P, ⟨hPnonzero, hPnot_top, _⟩, hPunique⟩ refine ⟨P, ⟨⟨hPnot_top, ?_⟩⟩, fun M hM => hPunique _ ⟨?_, Ideal.IsMaximal.isPrime hM⟩⟩ · refine Ideal.maximal_of_no_maximal fun M hPM hM => ne_of_lt hPM ?_ exact (hPunique _ ⟨ne_bot_of_gt hPM, Ideal.IsMaximal.isPrime hM⟩).symm · rintro rfl exact hPnot_top (hM.1.2 P (bot_lt_iff_ne_bot.2 hPnonzero))) variable [LocalRing R] theorem isUnit_or_isUnit_of_isUnit_add {a b : R} (h : IsUnit (a + b)) : IsUnit a ∨ IsUnit b := by rcases h with ⟨u, hu⟩ rw [← Units.inv_mul_eq_one, mul_add] at hu apply Or.imp _ _ (isUnit_or_isUnit_of_add_one hu) <;> exact isUnit_of_mul_isUnit_right theorem nonunits_add {a b : R} (ha : a ∈ nonunits R) (hb : b ∈ nonunits R) : a + b ∈ nonunits R := fun H => not_or_of_not ha hb (isUnit_or_isUnit_of_isUnit_add H) end LocalRing end CommSemiring namespace LocalRing variable [CommRing R] theorem of_isUnit_or_isUnit_one_sub_self [Nontrivial R] (h : ∀ a : R, IsUnit a ∨ IsUnit (1 - a)) : LocalRing R := ⟨fun {a b} hab => add_sub_cancel_left a b ▸ hab.symm ▸ h a⟩ variable [LocalRing R] theorem isUnit_or_isUnit_one_sub_self (a : R) : IsUnit a ∨ IsUnit (1 - a) := isUnit_or_isUnit_of_isUnit_add <| (add_sub_cancel a 1).symm ▸ isUnit_one theorem isUnit_of_mem_nonunits_one_sub_self (a : R) (h : 1 - a ∈ nonunits R) : IsUnit a := or_iff_not_imp_right.1 (isUnit_or_isUnit_one_sub_self a) h theorem isUnit_one_sub_self_of_mem_nonunits (a : R) (h : a ∈ nonunits R) : IsUnit (1 - a) := or_iff_not_imp_left.1 (isUnit_or_isUnit_one_sub_self a) h theorem of_surjective' [CommRing S] [Nontrivial S] (f : R →+* S) (hf : Function.Surjective f) : LocalRing S := of_isUnit_or_isUnit_one_sub_self (by intro b obtain ⟨a, rfl⟩ := hf b apply (isUnit_or_isUnit_one_sub_self a).imp <| RingHom.isUnit_map _ rw [← f.map_one, ← f.map_sub] apply f.isUnit_map) end LocalRing namespace Field variable (K : Type*) [Field K] -- see Note [lower instance priority] instance (priority := 100) : LocalRing K := by classical exact LocalRing.of_isUnit_or_isUnit_one_sub_self fun a => if h : a = 0 then Or.inr (by rw [h, sub_zero]; exact isUnit_one) else Or.inl <| IsUnit.mk0 a h end Field
RingTheory\LocalRing\Defs.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Chris Hughes, Mario Carneiro -/ import Mathlib.Algebra.Group.Units import Mathlib.Algebra.Ring.Defs /-! # Local rings Define local rings as commutative rings having a unique maximal ideal. ## Main definitions * `LocalRing`: A predicate on semirings, stating that for any pair of elements that adds up to `1`, one of them is a unit. In the commutative case this is shown to be equivalent to the condition that there exists a unique maximal ideal, see `LocalRing.of_unique_max_ideal` and `LocalRing.maximal_ideal_unique`. -/ /-- A semiring is local if it is nontrivial and `a` or `b` is a unit whenever `a + b = 1`. Note that `LocalRing` is a predicate. -/ class LocalRing (R : Type*) [Semiring R] extends Nontrivial R : Prop where of_is_unit_or_is_unit_of_add_one :: /-- in a local ring `R`, if `a + b = 1`, then either `a` is a unit or `b` is a unit. In another word, for every `a : R`, either `a` is a unit or `1 - a` is a unit. -/ isUnit_or_isUnit_of_add_one {a b : R} (h : a + b = 1) : IsUnit a ∨ IsUnit b
RingTheory\LocalRing\Module.lean
/- Copyright (c) 2024 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.RingTheory.FiniteType import Mathlib.RingTheory.Nakayama import Mathlib.Algebra.Module.FinitePresentation import Mathlib.LinearAlgebra.FiniteDimensional import Mathlib.LinearAlgebra.TensorProduct.RightExactness import Mathlib.RingTheory.Flat.Basic import Mathlib.RingTheory.LocalRing.ResidueField.Basic /-! # Finite modules over local rings This file gathers various results about finite modules over a local ring `(R, 𝔪, k)`. ## Main results - `LocalRing.subsingleton_tensorProduct`: If `M` is finitely generated, `k ⊗ M = 0 ↔ M = 0`. - `Module.free_of_maximalIdeal_rTensor_injective`: If `M` is a finitely presented module such that `m ⊗ M → M` is injective (for example when `M` is flat), then `M` is free. - `Module.free_of_lTensor_residueField_injective`: If `N → M → P → 0` is a presentation of `P` with `N` finite and `M` finite free, then injectivity of `k ⊗ N → k ⊗ M` implies that `P` is free. - `LocalRing.split_injective_iff_lTensor_residueField_injective`: Given an `R`-linear map `l : M → N` with `M` finite and `N` finite free, `l` is a split injection if and only if `k ⊗ l` is a (split) injection. -/ variable {R S} [CommRing R] [CommRing S] [Algebra R S] section variable {M N} [AddCommGroup M] [AddCommGroup N] [Module R M] [Module R N] open Function (Injective Surjective Exact) open LocalRing TensorProduct local notation "k" => ResidueField R local notation "𝔪" => maximalIdeal R variable {P} [AddCommGroup P] [Module R P] (f : M →ₗ[R] N) (g : N →ₗ[R] P) namespace LocalRing variable [LocalRing R] theorem map_mkQ_eq {N₁ N₂ : Submodule R M} (h : N₁ ≤ N₂) (h' : N₂.FG) : N₁.map (Submodule.mkQ (𝔪 • N₂)) = N₂.map (Submodule.mkQ (𝔪 • N₂)) ↔ N₁ = N₂ := by constructor · intro hN have : N₂ ≤ 𝔪 • N₂ ⊔ N₁ := by simpa using Submodule.comap_mono (f := Submodule.mkQ (𝔪 • N₂)) hN.ge rw [sup_comm] at this exact h.antisymm (Submodule.le_of_le_smul_of_le_jacobson_bot h' (by rw [jacobson_eq_maximalIdeal]; exact bot_ne_top) this) · rintro rfl; simp theorem map_mkQ_eq_top {N : Submodule R M} [Module.Finite R M] : N.map (Submodule.mkQ (𝔪 • ⊤)) = ⊤ ↔ N = ⊤ := by rw [← map_mkQ_eq (N₁ := N) le_top Module.Finite.out, Submodule.map_top, Submodule.range_mkQ] theorem map_tensorProduct_mk_eq_top {N : Submodule R M} [Module.Finite R M] : N.map (TensorProduct.mk R k M 1) = ⊤ ↔ N = ⊤ := by constructor · intro hN letI : Module k (M ⧸ (𝔪 • ⊤ : Submodule R M)) := inferInstanceAs (Module (R ⧸ 𝔪) (M ⧸ 𝔪 • (⊤ : Submodule R M))) letI : IsScalarTower R k (M ⧸ (𝔪 • ⊤ : Submodule R M)) := inferInstanceAs (IsScalarTower R (R ⧸ 𝔪) (M ⧸ 𝔪 • (⊤ : Submodule R M))) let f := AlgebraTensorModule.lift (((LinearMap.ringLmapEquivSelf k k _).symm (Submodule.mkQ (𝔪 • ⊤ : Submodule R M))).restrictScalars R) have : f.comp (TensorProduct.mk R k M 1) = Submodule.mkQ (𝔪 • ⊤) := by ext; simp [f] have hf : Function.Surjective f := by intro x; obtain ⟨x, rfl⟩ := Submodule.mkQ_surjective _ x rw [← this, LinearMap.comp_apply]; exact ⟨_, rfl⟩ apply_fun Submodule.map f at hN rwa [← Submodule.map_comp, this, Submodule.map_top, LinearMap.range_eq_top.mpr hf, map_mkQ_eq_top] at hN · rintro rfl; rw [Submodule.map_top, LinearMap.range_eq_top] exact TensorProduct.mk_surjective R M k Ideal.Quotient.mk_surjective theorem subsingleton_tensorProduct [Module.Finite R M] : Subsingleton (k ⊗[R] M) ↔ Subsingleton M := by rw [← Submodule.subsingleton_iff R, ← subsingleton_iff_bot_eq_top, ← Submodule.subsingleton_iff R, ← subsingleton_iff_bot_eq_top, ← map_tensorProduct_mk_eq_top (M := M), Submodule.map_bot] theorem span_eq_top_of_tmul_eq_basis [Module.Finite R M] {ι} (f : ι → M) (b : Basis ι k (k ⊗[R] M)) (hb : ∀ i, 1 ⊗ₜ f i = b i) : Submodule.span R (Set.range f) = ⊤ := by rw [← map_tensorProduct_mk_eq_top, Submodule.map_span, ← Submodule.restrictScalars_span R k Ideal.Quotient.mk_surjective, Submodule.restrictScalars_eq_top_iff, ← b.span_eq, ← Set.range_comp] simp only [Function.comp, mk_apply, hb, Basis.span_eq] end LocalRing open Function in /-- Given `M₁ → M₂ → M₃ → 0` and `N₁ → N₂ → N₃ → 0`, if `M₁ ⊗ N₃ → M₂ ⊗ N₃` and `M₂ ⊗ N₁ → M₂ ⊗ N₂` are both injective, then `M₃ ⊗ N₁ → M₃ ⊗ N₂` is also injective. -/ theorem lTensor_injective_of_exact_of_exact_of_rTensor_injective {M₁ M₂ M₃ N₁ N₂ N₃} [AddCommGroup M₁] [Module R M₁] [AddCommGroup M₂] [Module R M₂] [AddCommGroup M₃] [Module R M₃] [AddCommGroup N₁] [Module R N₁] [AddCommGroup N₂] [Module R N₂] [AddCommGroup N₃] [Module R N₃] {f₁ : M₁ →ₗ[R] M₂} {f₂ : M₂ →ₗ[R] M₃} {g₁ : N₁ →ₗ[R] N₂} {g₂ : N₂ →ₗ[R] N₃} (hfexact : Exact f₁ f₂) (hfsurj : Surjective f₂) (hgexact : Exact g₁ g₂) (hgsurj : Surjective g₂) (hfinj : Injective (f₁.rTensor N₃)) (hginj : Injective (g₁.lTensor M₂)) : Injective (g₁.lTensor M₃) := by rw [injective_iff_map_eq_zero] intro x hx obtain ⟨x, rfl⟩ := f₂.rTensor_surjective N₁ hfsurj x have : f₂.rTensor N₂ (g₁.lTensor M₂ x) = 0 := by rw [← hx, ← LinearMap.comp_apply, ← LinearMap.comp_apply, LinearMap.rTensor_comp_lTensor, LinearMap.lTensor_comp_rTensor] obtain ⟨y, hy⟩ := (rTensor_exact N₂ hfexact hfsurj _).mp this have : g₂.lTensor M₁ y = 0 := by apply hfinj trans g₂.lTensor M₂ (g₁.lTensor M₂ x) · rw [← hy, ← LinearMap.comp_apply, ← LinearMap.comp_apply, LinearMap.rTensor_comp_lTensor, LinearMap.lTensor_comp_rTensor] rw [← LinearMap.comp_apply, ← LinearMap.lTensor_comp, hgexact.linearMap_comp_eq_zero] simp obtain ⟨z, rfl⟩ := (lTensor_exact _ hgexact hgsurj _).mp this obtain rfl : f₁.rTensor N₁ z = x := by apply hginj simp only [← hy, ← LinearMap.comp_apply, ← LinearMap.comp_apply, LinearMap.lTensor_comp_rTensor, LinearMap.rTensor_comp_lTensor] rw [← LinearMap.comp_apply, ← LinearMap.rTensor_comp, hfexact.linearMap_comp_eq_zero] simp namespace Module variable [LocalRing R] /-- If `M` is a finitely presented module over a local ring `(R, 𝔪)` such that `m ⊗ M → M` is injective, then `M` is free. -/ theorem free_of_maximalIdeal_rTensor_injective [Module.FinitePresentation R M] (H : Function.Injective ((𝔪).subtype.rTensor M)) : Module.Free R M := by let I := Module.Free.ChooseBasisIndex k (k ⊗[R] M) -- Let `b : I → k ⊗ M` be a `k`-basis. let b : Basis I k _ := Module.Free.chooseBasis k (k ⊗[R] M) letI : IsNoetherian k (k ⊗[R] (I →₀ R)) := isNoetherian_of_isNoetherianRing_of_finite k (k ⊗[R] (I →₀ R)) choose f hf using TensorProduct.mk_surjective R M k Ideal.Quotient.mk_surjective -- By choosing an abitrary lift of `b` to `I → M`, we get a surjection `i : Rᴵ → M`. let i := Finsupp.total I M R (f ∘ b) have hi : Surjective i := by rw [← LinearMap.range_eq_top, Finsupp.range_total] exact LocalRing.span_eq_top_of_tmul_eq_basis (R := R) (f := f ∘ b) b (fun _ ↦ hf _) have : Module.Finite R (LinearMap.ker i) := by constructor exact (Submodule.fg_top _).mpr (Module.FinitePresentation.fg_ker i hi) -- We claim that `i` is actually a bijection, -- hence an isomorphism exhibing `M` as the free module `Rᴵ` refine Module.Free.of_equiv (LinearEquiv.ofBijective i ⟨?_, hi⟩) -- By Nakayama's lemma, it suffices to show that `k ⊗ ker(i) = 0`. rw [← LinearMap.ker_eq_bot, ← Submodule.subsingleton_iff_eq_bot, ← LocalRing.subsingleton_tensorProduct (R := R), subsingleton_iff_forall_eq 0] have : Function.Surjective (i.baseChange k) := i.lTensor_surjective _ hi -- By construction, `k ⊗ i : kᴵ → k ⊗ M` is bijective. have hi' : Function.Bijective (i.baseChange k) := by refine ⟨?_, this⟩ rw [← LinearMap.ker_eq_bot (M := k ⊗[R] (I →₀ R)) (f := i.baseChange k), ← Submodule.finrank_eq_zero (R := k) (M := k ⊗[R] (I →₀ R)), ← Nat.add_right_inj (n := FiniteDimensional.finrank k (LinearMap.range <| i.baseChange k)), LinearMap.finrank_range_add_finrank_ker (V := k ⊗[R] (I →₀ R)), LinearMap.range_eq_top.mpr this, finrank_top] simp only [FiniteDimensional.finrank_tensorProduct, FiniteDimensional.finrank_self, FiniteDimensional.finrank_finsupp_self, one_mul, add_zero] rw [FiniteDimensional.finrank_eq_card_chooseBasisIndex] -- On the other hand, `m ⊗ M → M` injective => `Tor₁(k, M) = 0` => `k ⊗ ker(i) → kᴵ` injective. have := @lTensor_injective_of_exact_of_exact_of_rTensor_injective (N₁ := LinearMap.ker i) (N₂ := I →₀ R) (N₃ := M) (f₁ := (𝔪).subtype) (f₂ := Submodule.mkQ 𝔪) inferInstance inferInstance inferInstance inferInstance inferInstance inferInstance intro x apply @this (LinearMap.ker i).subtype i (LinearMap.exact_subtype_mkQ 𝔪) (Submodule.mkQ_surjective _) (LinearMap.exact_subtype_ker_map i) hi H (Module.Flat.lTensor_preserves_injective_linearMap _ Subtype.val_injective) apply hi'.injective rw [LinearMap.baseChange_eq_ltensor] erw [← LinearMap.comp_apply (i.lTensor k), ← LinearMap.lTensor_comp] rw [(LinearMap.exact_subtype_ker_map i).linearMap_comp_eq_zero] simp only [LinearMap.lTensor_zero, LinearMap.zero_apply, map_zero] -- TODO: Generalise this to finite free modules. theorem free_of_flat_of_localRing [Module.FinitePresentation R P] [Module.Flat R P] : Module.Free R P := free_of_maximalIdeal_rTensor_injective (Module.Flat.rTensor_preserves_injective_linearMap _ Subtype.val_injective) /-- If `M → N → P → 0` is a presentation of `P` over a local ring `(R, 𝔪, k)` with `M` finite and `N` finite free, then injectivity of `k ⊗ M → k ⊗ N` implies that `P` is free. -/ theorem free_of_lTensor_residueField_injective (hg : Surjective g) (h : Exact f g) [Module.Finite R M] [Module.Finite R N] [Module.Free R N] (hf : Function.Injective (f.lTensor k)) : Module.Free R P := by have := Module.finitePresentation_of_free_of_surjective g hg (by rw [h.linearMap_ker_eq, LinearMap.range_eq_map]; exact (Module.Finite.out).map f) apply free_of_maximalIdeal_rTensor_injective rw [← LinearMap.lTensor_inj_iff_rTensor_inj] apply lTensor_injective_of_exact_of_exact_of_rTensor_injective h hg (LinearMap.exact_subtype_mkQ 𝔪) (Submodule.mkQ_surjective _) ((LinearMap.lTensor_inj_iff_rTensor_inj _ _).mp hf) (Module.Flat.lTensor_preserves_injective_linearMap _ Subtype.val_injective) end Module /-- Given a linear map `l : M → N` over a local ring `(R, 𝔪, k)` with `M` finite and `N` finite free, `l` is a split injection if and only if `k ⊗ l` is a (split) injection. -/ theorem LocalRing.split_injective_iff_lTensor_residueField_injective [LocalRing R] [Module.Finite R M] [Module.Finite R N] [Module.Free R N] (l : M →ₗ[R] N) : (∃ l', l' ∘ₗ l = LinearMap.id) ↔ Function.Injective (l.lTensor (ResidueField R)) := by constructor · intro ⟨l', hl⟩ have : l'.lTensor (ResidueField R) ∘ₗ l.lTensor (ResidueField R) = .id := by rw [← LinearMap.lTensor_comp, hl, LinearMap.lTensor_id] exact Function.HasLeftInverse.injective ⟨_, LinearMap.congr_fun this⟩ · intro h -- By `Module.free_of_lTensor_residueField_injective`, `k ⊗ l` injective => `N ⧸ l(M)` free. have := Module.free_of_lTensor_residueField_injective l (LinearMap.range l).mkQ (Submodule.mkQ_surjective _) l.exact_map_mkQ_range h -- Hence `l(M)` is projective because `0 → l(M) → N → N ⧸ l(M) → 0` splits. have : Module.Projective R (LinearMap.range l) := by have := (Exact.split_tfae (LinearMap.exact_subtype_mkQ (LinearMap.range l)) Subtype.val_injective (Submodule.mkQ_surjective _)).out 0 1 obtain ⟨l', hl'⟩ := this.mp (Module.projective_lifting_property _ _ (Submodule.mkQ_surjective _)) exact Module.Projective.of_split _ _ hl' -- Then `0 → ker l → M → l(M) → 0` splits. obtain ⟨l', hl'⟩ : ∃ l', l' ∘ₗ (LinearMap.ker l).subtype = LinearMap.id := by have : Function.Exact (LinearMap.ker l).subtype (l.codRestrict (LinearMap.range l) (LinearMap.mem_range_self l)) := by rw [LinearMap.exact_iff, LinearMap.ker_rangeRestrict, Submodule.range_subtype] have := (Exact.split_tfae this Subtype.val_injective (fun ⟨x, y, e⟩ ↦ ⟨y, Subtype.ext e⟩)).out 0 1 exact this.mp (Module.projective_lifting_property _ _ (fun ⟨x, y, e⟩ ↦ ⟨y, Subtype.ext e⟩)) have : Module.Finite R (LinearMap.ker l) := by refine Module.Finite.of_surjective l' ?_ exact Function.HasRightInverse.surjective ⟨_, DFunLike.congr_fun hl'⟩ -- And tensoring with `k` preserves the injectivity of the first arrow. -- That is, `k ⊗ ker l → k ⊗ M` is also injective. have H : Function.Injective ((LinearMap.ker l).subtype.lTensor k) := by apply_fun (LinearMap.lTensor k) at hl' rw [LinearMap.lTensor_comp, LinearMap.lTensor_id] at hl' exact Function.HasLeftInverse.injective ⟨l'.lTensor k, DFunLike.congr_fun hl'⟩ -- But by assumption `k ⊗ M → k ⊗ l(M)` is already injective, so `k ⊗ ker l = 0`. have : Subsingleton (k ⊗[R] LinearMap.ker l) := by refine (subsingleton_iff_forall_eq 0).mpr fun y ↦ H (h ?_) rw [map_zero, map_zero, ← LinearMap.comp_apply, ← LinearMap.lTensor_comp, l.exact_subtype_ker_map.linearMap_comp_eq_zero, LinearMap.lTensor_zero, LinearMap.zero_apply] -- By Nakayama's lemma, `l` is injective. have : Function.Injective l := by rwa [← LinearMap.ker_eq_bot, ← Submodule.subsingleton_iff_eq_bot, ← LocalRing.subsingleton_tensorProduct (R := R)] -- Whence `M ≃ l(M)` is projective and the result follows. have := (Exact.split_tfae l.exact_map_mkQ_range this (Submodule.mkQ_surjective _)).out 0 1 rw [← this] exact Module.projective_lifting_property _ _ (Submodule.mkQ_surjective _) end
RingTheory\LocalRing\MaximalIdeal\Basic.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Chris Hughes, Mario Carneiro -/ import Mathlib.RingTheory.LocalRing.MaximalIdeal.Defs import Mathlib.RingTheory.JacobsonIdeal /-! # Maximal ideal of local rings We prove basic properties of the maximal ideal of a local ring. -/ variable {R S K : Type*} section CommSemiring variable [CommSemiring R] namespace LocalRing variable [LocalRing R] variable (R) instance maximalIdeal.isMaximal : (maximalIdeal R).IsMaximal := by rw [Ideal.isMaximal_iff] constructor · intro h apply h exact isUnit_one · intro I x _ hx H erw [Classical.not_not] at hx rcases hx with ⟨u, rfl⟩ simpa using I.mul_mem_left (↑u⁻¹) H theorem maximal_ideal_unique : ∃! I : Ideal R, I.IsMaximal := ⟨maximalIdeal R, maximalIdeal.isMaximal R, fun I hI => hI.eq_of_le (maximalIdeal.isMaximal R).1.1 fun _ hx => hI.1.1 ∘ I.eq_top_of_isUnit_mem hx⟩ variable {R} theorem eq_maximalIdeal {I : Ideal R} (hI : I.IsMaximal) : I = maximalIdeal R := ExistsUnique.unique (maximal_ideal_unique R) hI <| maximalIdeal.isMaximal R theorem le_maximalIdeal {J : Ideal R} (hJ : J ≠ ⊤) : J ≤ maximalIdeal R := by rcases Ideal.exists_le_maximal J hJ with ⟨M, hM1, hM2⟩ rwa [← eq_maximalIdeal hM1] @[simp] theorem mem_maximalIdeal (x) : x ∈ maximalIdeal R ↔ x ∈ nonunits R := Iff.rfl theorem isField_iff_maximalIdeal_eq : IsField R ↔ maximalIdeal R = ⊥ := not_iff_not.mp ⟨Ring.ne_bot_of_isMaximal_of_not_isField inferInstance, fun h => Ring.not_isField_iff_exists_prime.mpr ⟨_, h, Ideal.IsMaximal.isPrime' _⟩⟩ end LocalRing end CommSemiring section CommRing variable [CommRing R] namespace LocalRing variable [LocalRing R] theorem maximalIdeal_le_jacobson (I : Ideal R) : LocalRing.maximalIdeal R ≤ I.jacobson := le_sInf fun _ ⟨_, h⟩ => le_of_eq (LocalRing.eq_maximalIdeal h).symm theorem jacobson_eq_maximalIdeal (I : Ideal R) (h : I ≠ ⊤) : I.jacobson = LocalRing.maximalIdeal R := le_antisymm (sInf_le ⟨le_maximalIdeal h, maximalIdeal.isMaximal R⟩) (maximalIdeal_le_jacobson I) end LocalRing end CommRing namespace LocalRing section variable [CommRing R] [LocalRing R] [CommRing S] [LocalRing S] theorem ker_eq_maximalIdeal [Field K] (φ : R →+* K) (hφ : Function.Surjective φ) : RingHom.ker φ = maximalIdeal R := LocalRing.eq_maximalIdeal <| (RingHom.ker_isMaximal_of_surjective φ) hφ end end LocalRing theorem LocalRing.maximalIdeal_eq_bot {R : Type*} [Field R] : LocalRing.maximalIdeal R = ⊥ := LocalRing.isField_iff_maximalIdeal_eq.mp (Field.toIsField R)
RingTheory\LocalRing\MaximalIdeal\Defs.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Chris Hughes, Mario Carneiro -/ import Mathlib.RingTheory.LocalRing.Basic /-! # Maximal ideal of local rings We define the maximal ideal of a local ring as the ideal of all non units. ## Main definitions * `LocalRing.maximalIdeal`: The unique maximal ideal for a local rings. Its carrier set is the set of non units. -/ namespace LocalRing variable (R : Type*) [CommSemiring R] [LocalRing R] /-- The ideal of elements that are not units. -/ def maximalIdeal : Ideal R where carrier := nonunits R zero_mem' := zero_mem_nonunits.2 <| zero_ne_one add_mem' {_ _} hx hy := nonunits_add hx hy smul_mem' _ _ := mul_mem_nonunits_right end LocalRing
RingTheory\LocalRing\ResidueField\Basic.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Chris Hughes, Mario Carneiro -/ import Mathlib.RingTheory.LocalRing.ResidueField.Defs import Mathlib.RingTheory.LocalRing.RingHom.Basic import Mathlib.RingTheory.LocalRing.MaximalIdeal.Basic /-! # Residue Field of local rings We prove basic properties of the residue field of a local ring. -/ variable {R S T : Type*} namespace LocalRing section variable [CommRing R] [LocalRing R] [CommRing S] [LocalRing S] [CommRing T] [LocalRing T] lemma ker_residue : RingHom.ker (residue R) = maximalIdeal R := Ideal.mk_ker @[simp] lemma residue_eq_zero_iff (x : R) : residue R x = 0 ↔ x ∈ maximalIdeal R := by rw [← RingHom.mem_ker, ker_residue] lemma residue_ne_zero_iff_isUnit (x : R) : residue R x ≠ 0 ↔ IsUnit x := by simp variable (R) instance ResidueField.algebra : Algebra R (ResidueField R) := Ideal.Quotient.algebra _ theorem ResidueField.algebraMap_eq : algebraMap R (ResidueField R) = residue R := rfl instance : IsLocalRingHom (LocalRing.residue R) := ⟨fun _ ha => Classical.not_not.mp (Ideal.Quotient.eq_zero_iff_mem.not.mp (isUnit_iff_ne_zero.mp ha))⟩ variable {R} namespace ResidueField /-- A local ring homomorphism into a field can be descended onto the residue field. -/ def lift {R S : Type*} [CommRing R] [LocalRing R] [Field S] (f : R →+* S) [IsLocalRingHom f] : LocalRing.ResidueField R →+* S := Ideal.Quotient.lift _ f fun a ha => by_contradiction fun h => ha (isUnit_of_map_unit f a (isUnit_iff_ne_zero.mpr h)) theorem lift_comp_residue {R S : Type*} [CommRing R] [LocalRing R] [Field S] (f : R →+* S) [IsLocalRingHom f] : (lift f).comp (residue R) = f := RingHom.ext fun _ => rfl @[simp] theorem lift_residue_apply {R S : Type*} [CommRing R] [LocalRing R] [Field S] (f : R →+* S) [IsLocalRingHom f] (x) : lift f (residue R x) = f x := rfl /-- The map on residue fields induced by a local homomorphism between local rings -/ def map (f : R →+* S) [IsLocalRingHom f] : ResidueField R →+* ResidueField S := Ideal.Quotient.lift (maximalIdeal R) ((Ideal.Quotient.mk _).comp f) fun a ha => by erw [Ideal.Quotient.eq_zero_iff_mem] exact map_nonunit f a ha /-- Applying `LocalRing.ResidueField.map` to the identity ring homomorphism gives the identity ring homomorphism. -/ @[simp] theorem map_id : LocalRing.ResidueField.map (RingHom.id R) = RingHom.id (LocalRing.ResidueField R) := Ideal.Quotient.ringHom_ext <| RingHom.ext fun _ => rfl /-- The composite of two `LocalRing.ResidueField.map`s is the `LocalRing.ResidueField.map` of the composite. -/ theorem map_comp (f : T →+* R) (g : R →+* S) [IsLocalRingHom f] [IsLocalRingHom g] : LocalRing.ResidueField.map (g.comp f) = (LocalRing.ResidueField.map g).comp (LocalRing.ResidueField.map f) := Ideal.Quotient.ringHom_ext <| RingHom.ext fun _ => rfl theorem map_comp_residue (f : R →+* S) [IsLocalRingHom f] : (ResidueField.map f).comp (residue R) = (residue S).comp f := rfl theorem map_residue (f : R →+* S) [IsLocalRingHom f] (r : R) : ResidueField.map f (residue R r) = residue S (f r) := rfl theorem map_id_apply (x : ResidueField R) : map (RingHom.id R) x = x := DFunLike.congr_fun map_id x @[simp] theorem map_map (f : R →+* S) (g : S →+* T) (x : ResidueField R) [IsLocalRingHom f] [IsLocalRingHom g] : map g (map f x) = map (g.comp f) x := DFunLike.congr_fun (map_comp f g).symm x /-- A ring isomorphism defines an isomorphism of residue fields. -/ @[simps apply] def mapEquiv (f : R ≃+* S) : LocalRing.ResidueField R ≃+* LocalRing.ResidueField S where toFun := map (f : R →+* S) invFun := map (f.symm : S →+* R) left_inv x := by simp only [map_map, RingEquiv.symm_comp, map_id, RingHom.id_apply] right_inv x := by simp only [map_map, RingEquiv.comp_symm, map_id, RingHom.id_apply] map_mul' := RingHom.map_mul _ map_add' := RingHom.map_add _ @[simp] theorem mapEquiv.symm (f : R ≃+* S) : (mapEquiv f).symm = mapEquiv f.symm := rfl @[simp] theorem mapEquiv_trans (e₁ : R ≃+* S) (e₂ : S ≃+* T) : mapEquiv (e₁.trans e₂) = (mapEquiv e₁).trans (mapEquiv e₂) := RingEquiv.toRingHom_injective <| map_comp (e₁ : R →+* S) (e₂ : S →+* T) @[simp] theorem mapEquiv_refl : mapEquiv (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.toRingHom_injective map_id /-- The group homomorphism from `RingAut R` to `RingAut k` where `k` is the residue field of `R`. -/ @[simps] def mapAut : RingAut R →* RingAut (LocalRing.ResidueField R) where toFun := mapEquiv map_mul' e₁ e₂ := mapEquiv_trans e₂ e₁ map_one' := mapEquiv_refl section MulSemiringAction variable (G : Type*) [Group G] [MulSemiringAction G R] /-- If `G` acts on `R` as a `MulSemiringAction`, then it also acts on `LocalRing.ResidueField R`. -/ instance : MulSemiringAction G (LocalRing.ResidueField R) := MulSemiringAction.compHom _ <| mapAut.comp (MulSemiringAction.toRingAut G R) @[simp] theorem residue_smul (g : G) (r : R) : residue R (g • r) = g • residue R r := rfl end MulSemiringAction end ResidueField theorem isLocalRingHom_residue : IsLocalRingHom (LocalRing.residue R) := by constructor intro a ha by_contra h erw [Ideal.Quotient.eq_zero_iff_mem.mpr ((LocalRing.mem_maximalIdeal _).mpr h)] at ha exact ha.ne_zero rfl end end LocalRing
RingTheory\LocalRing\ResidueField\Defs.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Chris Hughes, Mario Carneiro -/ import Mathlib.RingTheory.LocalRing.MaximalIdeal.Basic import Mathlib.RingTheory.Ideal.Quotient /-! # Residue Field of local rings ## Main definitions * `LocalRing.ResidueField`: The quotient of a local ring by its maximal ideal. * `LocalRing.residue`: The quotient map from a local ring to its residue field. -/ namespace LocalRing variable (R : Type*) [CommRing R] [LocalRing R] /-- The residue field of a local ring is the quotient of the ring by its maximal ideal. -/ def ResidueField := R ⧸ maximalIdeal R -- Porting note: failed at `deriving` instances automatically instance ResidueFieldCommRing : CommRing (ResidueField R) := show CommRing (R ⧸ maximalIdeal R) from inferInstance instance ResidueFieldInhabited : Inhabited (ResidueField R) := show Inhabited (R ⧸ maximalIdeal R) from inferInstance noncomputable instance ResidueField.field : Field (ResidueField R) := Ideal.Quotient.field (maximalIdeal R) /-- The quotient map from a local ring to its residue field. -/ def residue : R →+* ResidueField R := Ideal.Quotient.mk _ end LocalRing
RingTheory\LocalRing\RingHom\Basic.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Chris Hughes, Mario Carneiro -/ import Mathlib.RingTheory.LocalRing.RingHom.Defs import Mathlib.RingTheory.LocalRing.MaximalIdeal.Defs import Mathlib.RingTheory.Ideal.Maps import Mathlib.Logic.Equiv.TransferInstance /-! # Local rings homomorphisms We prove basic properties of local rings homomorphisms. -/ variable {R S T : Type*} section variable [Semiring R] [Semiring S] [Semiring T] instance isLocalRingHom_id (R : Type*) [Semiring R] : IsLocalRingHom (RingHom.id R) where map_nonunit _ := id @[simp] theorem isUnit_map_iff (f : R →+* S) [IsLocalRingHom f] (a) : IsUnit (f a) ↔ IsUnit a := ⟨IsLocalRingHom.map_nonunit a, f.isUnit_map⟩ -- Porting note: as this can be proved by other `simp` lemmas, this is marked as high priority. @[simp (high)] theorem map_mem_nonunits_iff (f : R →+* S) [IsLocalRingHom f] (a) : f a ∈ nonunits S ↔ a ∈ nonunits R := ⟨fun h ha => h <| (isUnit_map_iff f a).mpr ha, fun h ha => h <| (isUnit_map_iff f a).mp ha⟩ instance isLocalRingHom_comp (g : S →+* T) (f : R →+* S) [IsLocalRingHom g] [IsLocalRingHom f] : IsLocalRingHom (g.comp f) where map_nonunit a := IsLocalRingHom.map_nonunit a ∘ IsLocalRingHom.map_nonunit (f a) instance isLocalRingHom_equiv (f : R ≃+* S) : IsLocalRingHom (f : R →+* S) where map_nonunit a ha := by convert RingHom.isUnit_map (f.symm : S →+* R) ha exact (RingEquiv.symm_apply_apply f a).symm @[simp] theorem isUnit_of_map_unit (f : R →+* S) [IsLocalRingHom f] (a) (h : IsUnit (f a)) : IsUnit a := IsLocalRingHom.map_nonunit a h theorem of_irreducible_map (f : R →+* S) [h : IsLocalRingHom f] {x} (hfx : Irreducible (f x)) : Irreducible x := ⟨fun h => hfx.not_unit <| IsUnit.map f h, fun p q hx => let ⟨H⟩ := h Or.imp (H p) (H q) <| hfx.isUnit_or_isUnit <| f.map_mul p q ▸ congr_arg f hx⟩ theorem isLocalRingHom_of_comp (f : R →+* S) (g : S →+* T) [IsLocalRingHom (g.comp f)] : IsLocalRingHom f := ⟨fun _ ha => (isUnit_map_iff (g.comp f) _).mp (g.isUnit_map ha)⟩ /-- If `f : R →+* S` is a local ring hom, then `R` is a local ring if `S` is. -/ theorem RingHom.domain_localRing {R S : Type*} [CommSemiring R] [CommSemiring S] [H : LocalRing S] (f : R →+* S) [IsLocalRingHom f] : LocalRing R := by haveI : Nontrivial R := pullback_nonzero f f.map_zero f.map_one apply LocalRing.of_nonunits_add intro a b simp_rw [← map_mem_nonunits_iff f, f.map_add] exact LocalRing.nonunits_add end section open LocalRing variable [CommSemiring R] [LocalRing R] [CommSemiring S] [LocalRing S] /-- The image of the maximal ideal of the source is contained within the maximal ideal of the target. -/ theorem map_nonunit (f : R →+* S) [IsLocalRingHom f] (a : R) (h : a ∈ maximalIdeal R) : f a ∈ maximalIdeal S := fun H => h <| isUnit_of_map_unit f a H end namespace LocalRing section variable [CommSemiring R] [LocalRing R] [CommSemiring S] [LocalRing S] /-- A ring homomorphism between local rings is a local ring hom iff it reflects units, i.e. any preimage of a unit is still a unit. https://stacks.math.columbia.edu/tag/07BJ -/ theorem local_hom_TFAE (f : R →+* S) : List.TFAE [IsLocalRingHom f, f '' (maximalIdeal R).1 ⊆ maximalIdeal S, (maximalIdeal R).map f ≤ maximalIdeal S, maximalIdeal R ≤ (maximalIdeal S).comap f, (maximalIdeal S).comap f = maximalIdeal R] := by tfae_have 1 → 2 · rintro _ _ ⟨a, ha, rfl⟩ exact map_nonunit f a ha tfae_have 2 → 4 · exact Set.image_subset_iff.1 tfae_have 3 ↔ 4 · exact Ideal.map_le_iff_le_comap tfae_have 4 → 1 · intro h constructor exact fun x => not_imp_not.1 (@h x) tfae_have 1 → 5 · intro ext exact not_iff_not.2 (isUnit_map_iff f _) tfae_have 5 → 4 · exact fun h => le_of_eq h.symm tfae_finish end theorem of_surjective [CommSemiring R] [LocalRing R] [CommSemiring S] [Nontrivial S] (f : R →+* S) [IsLocalRingHom f] (hf : Function.Surjective f) : LocalRing S := of_isUnit_or_isUnit_of_isUnit_add (by intro a b hab obtain ⟨a, rfl⟩ := hf a obtain ⟨b, rfl⟩ := hf b rw [← map_add] at hab exact (isUnit_or_isUnit_of_isUnit_add <| IsLocalRingHom.map_nonunit _ hab).imp f.isUnit_map f.isUnit_map) /-- If `f : R →+* S` is a surjective local ring hom, then the induced units map is surjective. -/ theorem surjective_units_map_of_local_ringHom [CommRing R] [CommRing S] (f : R →+* S) (hf : Function.Surjective f) (h : IsLocalRingHom f) : Function.Surjective (Units.map <| f.toMonoidHom) := by intro a obtain ⟨b, hb⟩ := hf (a : S) use (isUnit_of_map_unit f b (by rw [hb]; exact Units.isUnit _)).unit ext exact hb -- see Note [lower instance priority] /-- Every ring hom `f : K →+* R` from a division ring `K` to a nontrivial ring `R` is a local ring hom. -/ instance (priority := 100) {K R} [DivisionRing K] [CommRing R] [Nontrivial R] (f : K →+* R) : IsLocalRingHom f where map_nonunit r hr := by simpa only [isUnit_iff_ne_zero, ne_eq, map_eq_zero] using hr.ne_zero end LocalRing namespace RingEquiv protected theorem localRing {A B : Type*} [CommSemiring A] [LocalRing A] [CommSemiring B] (e : A ≃+* B) : LocalRing B := haveI := e.symm.toEquiv.nontrivial LocalRing.of_surjective (e : A →+* B) e.surjective end RingEquiv
RingTheory\LocalRing\RingHom\Defs.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Chris Hughes, Mario Carneiro -/ import Mathlib.Algebra.Group.Units import Mathlib.Algebra.Ring.Hom.Defs /-! # Local rings homomorphisms We Define local ring homomorhpisms. ## Main definitions * `IsLocalRingHom`: A predicate on semiring homomorphisms, requiring that it maps nonunits to nonunits. For local rings, this means that the image of the unique maximal ideal is again contained in the unique maximal ideal. -/ /-- A local ring homomorphism is a homomorphism `f` between local rings such that `a` in the domain is a unit if `f a` is a unit for any `a`. See `LocalRing.local_hom_TFAE` for other equivalent definitions. -/ class IsLocalRingHom {R S : Type*} [Semiring R] [Semiring S] (f : R →+* S) : Prop where /-- A local ring homomorphism `f : R ⟶ S` will send nonunits of `R` to nonunits of `S`. -/ map_nonunit : ∀ a, IsUnit (f a) → IsUnit a
RingTheory\MvPolynomial\Basic.lean
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.Algebra.CharP.Defs import Mathlib.Algebra.MvPolynomial.Degrees import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.LinearAlgebra.FinsuppVectorSpace import Mathlib.LinearAlgebra.FreeModule.Finite.Basic /-! # Multivariate polynomials over commutative rings This file contains basic facts about multivariate polynomials over commutative rings, for example that the monomials form a basis. ## Main definitions * `restrictTotalDegree σ R m`: the subspace of multivariate polynomials indexed by `σ` over the commutative ring `R` of total degree at most `m`. * `restrictDegree σ R m`: the subspace of multivariate polynomials indexed by `σ` over the commutative ring `R` such that the degree in each individual variable is at most `m`. ## Main statements * The multivariate polynomial ring over a commutative semiring of characteristic `p` has characteristic `p`, and similarly for `CharZero`. * `basisMonomials`: shows that the monomials form a basis of the vector space of multivariate polynomials. ## TODO Generalise to noncommutative (semi)rings -/ noncomputable section open Set LinearMap Submodule open Polynomial universe u v variable (σ : Type u) (R : Type v) [CommSemiring R] (p m : ℕ) namespace MvPolynomial section CharP instance [CharP R p] : CharP (MvPolynomial σ R) p where cast_eq_zero_iff' n := by rw [← C_eq_coe_nat, ← C_0, C_inj, CharP.cast_eq_zero_iff R p] end CharP section CharZero instance [CharZero R] : CharZero (MvPolynomial σ R) where cast_injective x y hxy := by rwa [← C_eq_coe_nat, ← C_eq_coe_nat, C_inj, Nat.cast_inj] at hxy end CharZero section Homomorphism theorem mapRange_eq_map {R S : Type*} [CommSemiring R] [CommSemiring S] (p : MvPolynomial σ R) (f : R →+* S) : Finsupp.mapRange f f.map_zero p = map f p := by rw [p.as_sum, Finsupp.mapRange_finset_sum, map_sum (map f)] refine Finset.sum_congr rfl fun n _ => ?_ rw [map_monomial, ← single_eq_monomial, Finsupp.mapRange_single, single_eq_monomial] end Homomorphism section Degree variable {σ} /-- The submodule of polynomials that are sum of monomials in the set `s`. -/ def restrictSupport (s : Set (σ →₀ ℕ)) : Submodule R (MvPolynomial σ R) := Finsupp.supported _ _ s /-- `restrictSupport R s` has a canonical `R`-basis indexed by `s`. -/ def basisRestrictSupport (s : Set (σ →₀ ℕ)) : Basis s R (restrictSupport R s) where repr := Finsupp.supportedEquivFinsupp s theorem restrictSupport_mono {s t : Set (σ →₀ ℕ)} (h : s ⊆ t) : restrictSupport R s ≤ restrictSupport R t := Finsupp.supported_mono h variable (σ) /-- The submodule of polynomials of total degree less than or equal to `m`. -/ def restrictTotalDegree (m : ℕ) : Submodule R (MvPolynomial σ R) := restrictSupport R { n | (n.sum fun _ e => e) ≤ m } /-- The submodule of polynomials such that the degree with respect to each individual variable is less than or equal to `m`. -/ def restrictDegree (m : ℕ) : Submodule R (MvPolynomial σ R) := restrictSupport R { n | ∀ i, n i ≤ m } variable {R} theorem mem_restrictTotalDegree (p : MvPolynomial σ R) : p ∈ restrictTotalDegree σ R m ↔ p.totalDegree ≤ m := by rw [totalDegree, Finset.sup_le_iff] rfl theorem mem_restrictDegree (p : MvPolynomial σ R) (n : ℕ) : p ∈ restrictDegree σ R n ↔ ∀ s ∈ p.support, ∀ i, (s : σ →₀ ℕ) i ≤ n := by rw [restrictDegree, restrictSupport, Finsupp.mem_supported] rfl theorem mem_restrictDegree_iff_sup [DecidableEq σ] (p : MvPolynomial σ R) (n : ℕ) : p ∈ restrictDegree σ R n ↔ ∀ i, p.degrees.count i ≤ n := by simp only [mem_restrictDegree, degrees_def, Multiset.count_finset_sup, Finsupp.count_toMultiset, Finset.sup_le_iff] exact ⟨fun h n s hs => h s hs n, fun h s hs n => h n s hs⟩ variable (R) theorem restrictTotalDegree_le_restrictDegree (m : ℕ) : restrictTotalDegree σ R m ≤ restrictDegree σ R m := fun p hp ↦ (mem_restrictDegree _ _ _).mpr fun s hs i ↦ (degreeOf_le_iff.mp (degreeOf_le_totalDegree p i) s hs).trans ((mem_restrictTotalDegree _ _ _).mp hp) /-- The monomials form a basis on `MvPolynomial σ R`. -/ def basisMonomials : Basis (σ →₀ ℕ) R (MvPolynomial σ R) := Finsupp.basisSingleOne @[simp] theorem coe_basisMonomials : (basisMonomials σ R : (σ →₀ ℕ) → MvPolynomial σ R) = fun s => monomial s 1 := rfl /-- The `R`-module `MvPolynomial σ R` is free. -/ instance : Module.Free R (MvPolynomial σ R) := Module.Free.of_basis (MvPolynomial.basisMonomials σ R) theorem linearIndependent_X : LinearIndependent R (X : σ → MvPolynomial σ R) := (basisMonomials σ R).linearIndependent.comp (fun s : σ => Finsupp.single s 1) (Finsupp.single_left_injective one_ne_zero) private lemma finite_setOf_bounded (α) [Finite α] (n : ℕ) : Finite {f : α →₀ ℕ | ∀ a, f a ≤ n} := ((Set.Finite.pi' fun _ ↦ Set.finite_le_nat _).preimage DFunLike.coe_injective.injOn).to_subtype instance [Finite σ] (N : ℕ) : Module.Finite R (restrictDegree σ R N) := have := finite_setOf_bounded σ N Module.Finite.of_basis (basisRestrictSupport R _) instance [Finite σ] (N : ℕ) : Module.Finite R (restrictTotalDegree σ R N) := have := finite_setOf_bounded σ N have : Finite {s : σ →₀ ℕ | s.sum (fun _ e ↦ e) ≤ N} := by rw [Set.finite_coe_iff] at this ⊢ exact this.subset fun n hn i ↦ (eq_or_ne (n i) 0).elim (fun h ↦ h.trans_le N.zero_le) fun h ↦ (Finset.single_le_sum (fun _ _ ↦ Nat.zero_le _) <| Finsupp.mem_support_iff.mpr h).trans hn Module.Finite.of_basis (basisRestrictSupport R _) end Degree section Algebra variable {R S σ : Type*} [CommSemiring R] [CommSemiring S] [Algebra R S] /-- If `S` is an `R`-algebra, then `MvPolynomial σ S` is a `MvPolynomial σ R` algebra. Warning: This produces a diamond for `Algebra (MvPolynomial σ R) (MvPolynomial σ (MvPolynomial σ S))`. That's why it is not a global instance. -/ noncomputable def algebraMvPolynomial : Algebra (MvPolynomial σ R) (MvPolynomial σ S) := (MvPolynomial.map (algebraMap R S)).toAlgebra attribute [local instance] algebraMvPolynomial @[simp] lemma algebraMap_def : algebraMap (MvPolynomial σ R) (MvPolynomial σ S) = MvPolynomial.map (algebraMap R S) := rfl instance : IsScalarTower R (MvPolynomial σ R) (MvPolynomial σ S) := IsScalarTower.of_algebraMap_eq' (by ext; simp) end Algebra end MvPolynomial -- this is here to avoid import cycle issues namespace Polynomial /-- The monomials form a basis on `R[X]`. -/ noncomputable def basisMonomials : Basis ℕ R R[X] := Basis.ofRepr (toFinsuppIsoAlg R).toLinearEquiv @[simp] theorem coe_basisMonomials : (basisMonomials R : ℕ → R[X]) = fun s => monomial s 1 := funext fun _ => ofFinsupp_single _ _ end Polynomial
RingTheory\MvPolynomial\Homogeneous.lean
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Eric Wieser -/ import Mathlib.Algebra.DirectSum.Internal import Mathlib.Algebra.GradedMonoid import Mathlib.Algebra.MvPolynomial.CommRing import Mathlib.Algebra.MvPolynomial.Equiv import Mathlib.Algebra.MvPolynomial.Variables import Mathlib.RingTheory.MvPolynomial.WeightedHomogeneous import Mathlib.Algebra.Polynomial.Roots /-! # Homogeneous polynomials A multivariate polynomial `φ` is homogeneous of degree `n` if all monomials occurring in `φ` have degree `n`. ## Main definitions/lemmas * `IsHomogeneous φ n`: a predicate that asserts that `φ` is homogeneous of degree `n`. * `homogeneousSubmodule σ R n`: the submodule of homogeneous polynomials of degree `n`. * `homogeneousComponent n`: the additive morphism that projects polynomials onto their summand that is homogeneous of degree `n`. * `sum_homogeneousComponent`: every polynomial is the sum of its homogeneous components. -/ namespace MvPolynomial variable {σ : Type*} {τ : Type*} {R : Type*} {S : Type*} /- TODO * show that `MvPolynomial σ R ≃ₐ[R] ⨁ i, homogeneousSubmodule σ R i` -/ open Finsupp /-- A multivariate polynomial `φ` is homogeneous of degree `n` if all monomials occurring in `φ` have degree `n`. -/ def IsHomogeneous [CommSemiring R] (φ : MvPolynomial σ R) (n : ℕ) := IsWeightedHomogeneous 1 φ n variable [CommSemiring R] theorem weightedTotalDegree_one (φ : MvPolynomial σ R) : weightedTotalDegree (1 : σ → ℕ) φ = φ.totalDegree := by simp only [totalDegree, weightedTotalDegree, weight, LinearMap.toAddMonoidHom_coe, Finsupp.total, Pi.one_apply, Finsupp.coe_lsum, LinearMap.coe_smulRight, LinearMap.id_coe, id, Algebra.id.smul_eq_mul, mul_one] variable (σ R) /-- The submodule of homogeneous `MvPolynomial`s of degree `n`. -/ def homogeneousSubmodule (n : ℕ) : Submodule R (MvPolynomial σ R) where carrier := { x | x.IsHomogeneous n } smul_mem' r a ha c hc := by rw [coeff_smul] at hc apply ha intro h apply hc rw [h] exact smul_zero r zero_mem' d hd := False.elim (hd <| coeff_zero _) add_mem' {a b} ha hb c hc := by rw [coeff_add] at hc obtain h | h : coeff c a ≠ 0 ∨ coeff c b ≠ 0 := by contrapose! hc simp only [hc, add_zero] · exact ha h · exact hb h @[simp] lemma weightedHomogeneousSubmodule_one (n : ℕ) : weightedHomogeneousSubmodule R 1 n = homogeneousSubmodule σ R n := rfl variable {σ R} @[simp] theorem mem_homogeneousSubmodule (n : ℕ) (p : MvPolynomial σ R) : p ∈ homogeneousSubmodule σ R n ↔ p.IsHomogeneous n := Iff.rfl variable (σ R) /-- While equal, the former has a convenient definitional reduction. -/ theorem homogeneousSubmodule_eq_finsupp_supported (n : ℕ) : homogeneousSubmodule σ R n = Finsupp.supported _ R { d | d.degree = n } := by simp_rw [degree_eq_weight_one] exact weightedHomogeneousSubmodule_eq_finsupp_supported R 1 n variable {σ R} theorem homogeneousSubmodule_mul (m n : ℕ) : homogeneousSubmodule σ R m * homogeneousSubmodule σ R n ≤ homogeneousSubmodule σ R (m + n) := weightedHomogeneousSubmodule_mul 1 m n section theorem isHomogeneous_monomial {d : σ →₀ ℕ} (r : R) {n : ℕ} (hn : d.degree = n) : IsHomogeneous (monomial d r) n := by rw [degree_eq_weight_one] at hn exact isWeightedHomogeneous_monomial 1 d r hn variable (σ) theorem totalDegree_eq_zero_iff (p : MvPolynomial σ R) : p.totalDegree = 0 ↔ ∀ (m : σ →₀ ℕ) (_ : m ∈ p.support) (x : σ), m x = 0 := by rw [← weightedTotalDegree_one, weightedTotalDegree_eq_zero_iff _ p] exact nonTorsionWeight_of (Function.const σ one_ne_zero) theorem totalDegree_zero_iff_isHomogeneous {p : MvPolynomial σ R} : p.totalDegree = 0 ↔ IsHomogeneous p 0 := by rw [← weightedTotalDegree_one, ← isWeightedHomogeneous_zero_iff_weightedTotalDegree_eq_zero, IsHomogeneous] alias ⟨isHomogeneous_of_totalDegree_zero, _⟩ := totalDegree_zero_iff_isHomogeneous theorem isHomogeneous_C (r : R) : IsHomogeneous (C r : MvPolynomial σ R) 0 := by apply isHomogeneous_monomial simp only [Finsupp.degree, Finsupp.zero_apply, Finset.sum_const_zero] variable (R) theorem isHomogeneous_zero (n : ℕ) : IsHomogeneous (0 : MvPolynomial σ R) n := (homogeneousSubmodule σ R n).zero_mem theorem isHomogeneous_one : IsHomogeneous (1 : MvPolynomial σ R) 0 := isHomogeneous_C _ _ variable {σ} theorem isHomogeneous_X (i : σ) : IsHomogeneous (X i : MvPolynomial σ R) 1 := by apply isHomogeneous_monomial rw [Finsupp.degree, Finsupp.support_single_ne_zero _ one_ne_zero, Finset.sum_singleton] exact Finsupp.single_eq_same end namespace IsHomogeneous variable [CommSemiring S] {φ ψ : MvPolynomial σ R} {m n : ℕ} theorem coeff_eq_zero (hφ : IsHomogeneous φ n) {d : σ →₀ ℕ} (hd : d.degree ≠ n) : coeff d φ = 0 := by rw [degree_eq_weight_one] at hd exact IsWeightedHomogeneous.coeff_eq_zero hφ d hd theorem inj_right (hm : IsHomogeneous φ m) (hn : IsHomogeneous φ n) (hφ : φ ≠ 0) : m = n := by obtain ⟨d, hd⟩ : ∃ d, coeff d φ ≠ 0 := exists_coeff_ne_zero hφ rw [← hm hd, ← hn hd] theorem add (hφ : IsHomogeneous φ n) (hψ : IsHomogeneous ψ n) : IsHomogeneous (φ + ψ) n := (homogeneousSubmodule σ R n).add_mem hφ hψ theorem sum {ι : Type*} (s : Finset ι) (φ : ι → MvPolynomial σ R) (n : ℕ) (h : ∀ i ∈ s, IsHomogeneous (φ i) n) : IsHomogeneous (∑ i ∈ s, φ i) n := (homogeneousSubmodule σ R n).sum_mem h theorem mul (hφ : IsHomogeneous φ m) (hψ : IsHomogeneous ψ n) : IsHomogeneous (φ * ψ) (m + n) := homogeneousSubmodule_mul m n <| Submodule.mul_mem_mul hφ hψ theorem prod {ι : Type*} (s : Finset ι) (φ : ι → MvPolynomial σ R) (n : ι → ℕ) (h : ∀ i ∈ s, IsHomogeneous (φ i) (n i)) : IsHomogeneous (∏ i ∈ s, φ i) (∑ i ∈ s, n i) := by classical revert h refine Finset.induction_on s ?_ ?_ · intro simp only [isHomogeneous_one, Finset.sum_empty, Finset.prod_empty] · intro i s his IH h simp only [his, Finset.prod_insert, Finset.sum_insert, not_false_iff] apply (h i (Finset.mem_insert_self _ _)).mul (IH _) intro j hjs exact h j (Finset.mem_insert_of_mem hjs) lemma C_mul (hφ : φ.IsHomogeneous m) (r : R) : (C r * φ).IsHomogeneous m := by simpa only [zero_add] using (isHomogeneous_C _ _).mul hφ lemma _root_.MvPolynomial.isHomogeneous_C_mul_X (r : R) (i : σ) : (C r * X i).IsHomogeneous 1 := (isHomogeneous_X _ _).C_mul _ @[deprecated (since := "2024-03-21")] alias _root_.MvPolynomial.C_mul_X := _root_.MvPolynomial.isHomogeneous_C_mul_X lemma pow (hφ : φ.IsHomogeneous m) (n : ℕ) : (φ ^ n).IsHomogeneous (m * n) := by rw [show φ ^ n = ∏ _i ∈ Finset.range n, φ by simp] rw [show m * n = ∑ _i ∈ Finset.range n, m by simp [mul_comm]] apply IsHomogeneous.prod _ _ _ (fun _ _ ↦ hφ) lemma _root_.MvPolynomial.isHomogeneous_X_pow (i : σ) (n : ℕ) : (X (R := R) i ^ n).IsHomogeneous n := by simpa only [one_mul] using (isHomogeneous_X _ _).pow n lemma _root_.MvPolynomial.isHomogeneous_C_mul_X_pow (r : R) (i : σ) (n : ℕ) : (C r * X i ^ n).IsHomogeneous n := (isHomogeneous_X_pow _ _).C_mul _ lemma eval₂ (hφ : φ.IsHomogeneous m) (f : R →+* MvPolynomial τ S) (g : σ → MvPolynomial τ S) (hf : ∀ r, (f r).IsHomogeneous 0) (hg : ∀ i, (g i).IsHomogeneous n) : (eval₂ f g φ).IsHomogeneous (n * m) := by apply IsHomogeneous.sum intro i hi rw [← zero_add (n * m)] apply IsHomogeneous.mul (hf _) _ convert IsHomogeneous.prod _ _ (fun k ↦ n * i k) _ · rw [Finsupp.mem_support_iff] at hi rw [← Finset.mul_sum, ← hφ hi, weight_apply] simp_rw [smul_eq_mul, Finsupp.sum, Pi.one_apply, mul_one] · rintro k - apply (hg k).pow lemma map (hφ : φ.IsHomogeneous n) (f : R →+* S) : (map f φ).IsHomogeneous n := by simpa only [one_mul] using hφ.eval₂ _ _ (fun r ↦ isHomogeneous_C _ (f r)) (isHomogeneous_X _) lemma aeval [Algebra R S] (hφ : φ.IsHomogeneous m) (g : σ → MvPolynomial τ S) (hg : ∀ i, (g i).IsHomogeneous n) : (aeval g φ).IsHomogeneous (n * m) := hφ.eval₂ _ _ (fun _ ↦ isHomogeneous_C _ _) hg section CommRing -- In this section we shadow the semiring `R` with a ring `R`. variable {R σ : Type*} [CommRing R] {φ ψ : MvPolynomial σ R} {n : ℕ} theorem neg (hφ : IsHomogeneous φ n) : IsHomogeneous (-φ) n := (homogeneousSubmodule σ R n).neg_mem hφ theorem sub (hφ : IsHomogeneous φ n) (hψ : IsHomogeneous ψ n) : IsHomogeneous (φ - ψ) n := (homogeneousSubmodule σ R n).sub_mem hφ hψ end CommRing /-- The homogeneous degree bounds the total degree. See also `MvPolynomial.IsHomogeneous.totalDegree` when `φ` is non-zero. -/ lemma totalDegree_le (hφ : IsHomogeneous φ n) : φ.totalDegree ≤ n := by apply Finset.sup_le intro d hd rw [mem_support_iff] at hd simp_rw [Finsupp.sum, ← hφ hd, weight_apply, Pi.one_apply, smul_eq_mul, mul_one, Finsupp.sum, le_rfl] theorem totalDegree (hφ : IsHomogeneous φ n) (h : φ ≠ 0) : totalDegree φ = n := by apply le_antisymm hφ.totalDegree_le obtain ⟨d, hd⟩ : ∃ d, coeff d φ ≠ 0 := exists_coeff_ne_zero h simp only [← hφ hd, MvPolynomial.totalDegree, Finsupp.sum] replace hd := Finsupp.mem_support_iff.mpr hd simp only [weight_apply, Pi.one_apply, smul_eq_mul, mul_one] -- Porting note: Original proof did not define `f` exact Finset.le_sup (f := fun s ↦ ∑ x ∈ s.support, s x) hd theorem rename_isHomogeneous {f : σ → τ} (h : φ.IsHomogeneous n) : (rename f φ).IsHomogeneous n := by rw [← φ.support_sum_monomial_coeff, map_sum]; simp_rw [rename_monomial] apply IsHomogeneous.sum _ _ _ fun d hd ↦ isHomogeneous_monomial _ _ intro d hd apply (Finsupp.sum_mapDomain_index_addMonoidHom fun _ ↦ .id ℕ).trans convert h (mem_support_iff.mp hd) simp only [weight_apply, AddMonoidHom.id_apply, Pi.one_apply, smul_eq_mul, mul_one] theorem rename_isHomogeneous_iff {f : σ → τ} (hf : f.Injective) : (rename f φ).IsHomogeneous n ↔ φ.IsHomogeneous n := by refine ⟨fun h d hd ↦ ?_, rename_isHomogeneous⟩ convert ← @h (d.mapDomain f) _ · simp only [weight_apply, Pi.one_apply, smul_eq_mul, mul_one] exact Finsupp.sum_mapDomain_index_inj (h := fun _ ↦ id) hf · rwa [coeff_rename_mapDomain f hf] lemma finSuccEquiv_coeff_isHomogeneous {N : ℕ} {φ : MvPolynomial (Fin (N+1)) R} {n : ℕ} (hφ : φ.IsHomogeneous n) (i j : ℕ) (h : i + j = n) : ((finSuccEquiv _ _ φ).coeff i).IsHomogeneous j := by intro d hd rw [finSuccEquiv_coeff_coeff] at hd have h' : (weight 1) (Finsupp.cons i d) = i + j := by simpa [Finset.sum_subset_zero_on_sdiff (g := d.cons i) (d.cons_support (y := i)) (by simp) (fun _ _ ↦ rfl), ← h] using hφ hd simp only [weight_apply, Pi.one_apply, smul_eq_mul, mul_one, Finsupp.sum_cons, add_right_inj] at h' ⊢ exact h' -- TODO: develop API for `optionEquivLeft` and get rid of the `[Fintype σ]` assumption lemma coeff_isHomogeneous_of_optionEquivLeft_symm [hσ : Finite σ] {p : Polynomial (MvPolynomial σ R)} (hp : ((optionEquivLeft R σ).symm p).IsHomogeneous n) (i j : ℕ) (h : i + j = n) : (p.coeff i).IsHomogeneous j := by obtain ⟨k, ⟨e⟩⟩ := Finite.exists_equiv_fin σ let e' := e.optionCongr.trans (_root_.finSuccEquiv _).symm let F := renameEquiv R e let F' := renameEquiv R e' let φ := F' ((optionEquivLeft R σ).symm p) have hφ : φ.IsHomogeneous n := hp.rename_isHomogeneous suffices IsHomogeneous (F (p.coeff i)) j by rwa [← (IsHomogeneous.rename_isHomogeneous_iff e.injective)] convert hφ.finSuccEquiv_coeff_isHomogeneous i j h using 1 dsimp only [φ, F', F, renameEquiv_apply] rw [finSuccEquiv_rename_finSuccEquiv, AlgEquiv.apply_symm_apply] simp open Polynomial in private lemma exists_eval_ne_zero_of_coeff_finSuccEquiv_ne_zero_aux {N : ℕ} {F : MvPolynomial (Fin (Nat.succ N)) R} {n : ℕ} (hF : IsHomogeneous F n) (hFn : ((finSuccEquiv R N) F).coeff n ≠ 0) : ∃ r, eval r F ≠ 0 := by have hF₀ : F ≠ 0 := by contrapose! hFn; simp [hFn] have hdeg : natDegree (finSuccEquiv R N F) < n + 1 := by linarith [natDegree_finSuccEquiv F, degreeOf_le_totalDegree F 0, hF.totalDegree hF₀] use Fin.cons 1 0 have aux : ∀ i ∈ Finset.range n, constantCoeff ((finSuccEquiv R N F).coeff i) = 0 := by intro i hi rw [Finset.mem_range] at hi apply (hF.finSuccEquiv_coeff_isHomogeneous i (n-i) (by omega)).coeff_eq_zero simp only [Finsupp.degree_zero] rw [← Nat.sub_ne_zero_iff_lt] at hi exact hi.symm simp_rw [eval_eq_eval_mv_eval', eval_one_map, Polynomial.eval_eq_sum_range' hdeg, eval_zero, one_pow, mul_one, map_sum, Finset.sum_range_succ, Finset.sum_eq_zero aux, zero_add] contrapose! hFn ext d rw [coeff_zero] obtain rfl | hd := eq_or_ne d 0 · apply hFn · contrapose! hd ext i rw [Finsupp.coe_zero, Pi.zero_apply] by_cases hi : i ∈ d.support · have := hF.finSuccEquiv_coeff_isHomogeneous n 0 (add_zero _) hd simp only [weight_apply, Pi.one_apply, smul_eq_mul, mul_one, Finsupp.sum] at this rw [Finset.sum_eq_zero_iff_of_nonneg (fun _ _ ↦ zero_le')] at this exact this i hi · simpa using hi section IsDomain -- In this section we shadow the semiring `R` with a domain `R`. variable {R σ : Type*} [CommRing R] [IsDomain R] {F G : MvPolynomial σ R} {n : ℕ} open Cardinal Polynomial private lemma exists_eval_ne_zero_of_totalDegree_le_card_aux {N : ℕ} {F : MvPolynomial (Fin N) R} {n : ℕ} (hF : F.IsHomogeneous n) (hF₀ : F ≠ 0) (hnR : n ≤ #R) : ∃ r, eval r F ≠ 0 := by induction N generalizing n with | zero => use 0 contrapose! hF₀ ext d simpa only [Subsingleton.elim d 0, eval_zero, coeff_zero] using hF₀ | succ N IH => have hdeg : natDegree (finSuccEquiv R N F) < n + 1 := by linarith [natDegree_finSuccEquiv F, degreeOf_le_totalDegree F 0, hF.totalDegree hF₀] obtain ⟨i, hi⟩ : ∃ i : ℕ, (finSuccEquiv R N F).coeff i ≠ 0 := by contrapose! hF₀ exact (finSuccEquiv _ _).injective <| Polynomial.ext <| by simpa using hF₀ have hin : i ≤ n := by contrapose! hi exact coeff_eq_zero_of_natDegree_lt <| (Nat.le_of_lt_succ hdeg).trans_lt hi obtain hFn | hFn := ne_or_eq ((finSuccEquiv R N F).coeff n) 0 · exact hF.exists_eval_ne_zero_of_coeff_finSuccEquiv_ne_zero_aux hFn have hin : i < n := hin.lt_or_eq.elim id <| by aesop obtain ⟨j, hj⟩ : ∃ j, i + (j + 1) = n := (Nat.exists_eq_add_of_lt hin).imp <| by intros; omega obtain ⟨r, hr⟩ : ∃ r, (eval r) (Polynomial.coeff ((finSuccEquiv R N) F) i) ≠ 0 := IH (hF.finSuccEquiv_coeff_isHomogeneous _ _ hj) hi (.trans (by norm_cast; omega) hnR) set φ : R[X] := Polynomial.map (eval r) (finSuccEquiv _ _ F) with hφ have hφ₀ : φ ≠ 0 := fun hφ₀ ↦ hr <| by rw [← coeff_eval_eq_eval_coeff, ← hφ, hφ₀, Polynomial.coeff_zero] have hφR : φ.natDegree < #R := by refine lt_of_lt_of_le ?_ hnR norm_cast refine lt_of_le_of_lt (natDegree_map_le _ _) ?_ suffices (finSuccEquiv _ _ F).natDegree ≠ n by omega rintro rfl refine leadingCoeff_ne_zero.mpr ?_ hFn simpa using (finSuccEquiv R N).injective.ne hF₀ obtain ⟨r₀, hr₀⟩ : ∃ r₀, Polynomial.eval r₀ φ ≠ 0 := φ.exists_eval_ne_zero_of_natDegree_lt_card hφ₀ hφR use Fin.cons r₀ r rwa [eval_eq_eval_mv_eval'] /-- See `MvPolynomial.IsHomogeneous.eq_zero_of_forall_eval_eq_zero` for a version that assumes `Infinite R`. -/ lemma eq_zero_of_forall_eval_eq_zero_of_le_card (hF : F.IsHomogeneous n) (h : ∀ r : σ → R, eval r F = 0) (hnR : n ≤ #R) : F = 0 := by contrapose! h -- reduce to the case where σ is finite obtain ⟨k, f, hf, F, rfl⟩ := exists_fin_rename F have hF₀ : F ≠ 0 := by rintro rfl; simp at h have hF : F.IsHomogeneous n := by rwa [rename_isHomogeneous_iff hf] at hF obtain ⟨r, hr⟩ := exists_eval_ne_zero_of_totalDegree_le_card_aux hF hF₀ hnR obtain ⟨r, rfl⟩ := (Function.factorsThrough_iff _).mp <| (hf.factorsThrough r) use r rwa [eval_rename] /-- See `MvPolynomial.IsHomogeneous.funext` for a version that assumes `Infinite R`. -/ lemma funext_of_le_card (hF : F.IsHomogeneous n) (hG : G.IsHomogeneous n) (h : ∀ r : σ → R, eval r F = eval r G) (hnR : n ≤ #R) : F = G := by rw [← sub_eq_zero] apply eq_zero_of_forall_eval_eq_zero_of_le_card (hF.sub hG) _ hnR simpa [sub_eq_zero] using h /-- See `MvPolynomial.IsHomogeneous.eq_zero_of_forall_eval_eq_zero_of_le_card` for a version that assumes `n ≤ #R`. -/ lemma eq_zero_of_forall_eval_eq_zero [Infinite R] {F : MvPolynomial σ R} {n : ℕ} (hF : F.IsHomogeneous n) (h : ∀ r : σ → R, eval r F = 0) : F = 0 := by apply eq_zero_of_forall_eval_eq_zero_of_le_card hF h exact (Cardinal.nat_lt_aleph0 _).le.trans <| Cardinal.infinite_iff.mp ‹Infinite R› /-- See `MvPolynomial.IsHomogeneous.funext_of_le_card` for a version that assumes `n ≤ #R`. -/ lemma funext [Infinite R] {F G : MvPolynomial σ R} {n : ℕ} (hF : F.IsHomogeneous n) (hG : G.IsHomogeneous n) (h : ∀ r : σ → R, eval r F = eval r G) : F = G := by apply funext_of_le_card hF hG h exact (Cardinal.nat_lt_aleph0 _).le.trans <| Cardinal.infinite_iff.mp ‹Infinite R› end IsDomain /-- The homogeneous submodules form a graded ring. This instance is used by `DirectSum.commSemiring` and `DirectSum.algebra`. -/ instance HomogeneousSubmodule.gcommSemiring : SetLike.GradedMonoid (homogeneousSubmodule σ R) where one_mem := isHomogeneous_one σ R mul_mem _ _ _ _ := IsHomogeneous.mul end IsHomogeneous noncomputable section open Finset /-- `homogeneousComponent n φ` is the part of `φ` that is homogeneous of degree `n`. See `sum_homogeneousComponent` for the statement that `φ` is equal to the sum of all its homogeneous components. -/ def homogeneousComponent [CommSemiring R] (n : ℕ) : MvPolynomial σ R →ₗ[R] MvPolynomial σ R := weightedHomogeneousComponent 1 n section HomogeneousComponent open Finset Finsupp variable (n : ℕ) (φ ψ : MvPolynomial σ R) theorem homogeneousComponent_mem : homogeneousComponent n φ ∈ homogeneousSubmodule σ R n := weightedHomogeneousComponent_mem _ φ n theorem coeff_homogeneousComponent (d : σ →₀ ℕ) : coeff d (homogeneousComponent n φ) = if d.degree = n then coeff d φ else 0 := by rw [degree_eq_weight_one] convert coeff_weightedHomogeneousComponent n φ d theorem homogeneousComponent_apply : homogeneousComponent n φ = ∑ d ∈ φ.support.filter fun d => d.degree = n, monomial d (coeff d φ) := by simp_rw [degree_eq_weight_one] convert weightedHomogeneousComponent_apply n φ theorem homogeneousComponent_isHomogeneous : (homogeneousComponent n φ).IsHomogeneous n := weightedHomogeneousComponent_isWeightedHomogeneous n φ @[simp] theorem homogeneousComponent_zero : homogeneousComponent 0 φ = C (coeff 0 φ) := weightedHomogeneousComponent_zero φ (fun _ => Nat.succ_ne_zero Nat.zero) @[simp] theorem homogeneousComponent_C_mul (n : ℕ) (r : R) : homogeneousComponent n (C r * φ) = C r * homogeneousComponent n φ := weightedHomogeneousComponent_C_mul φ n r theorem homogeneousComponent_eq_zero' (h : ∀ d : σ →₀ ℕ, d ∈ φ.support → d.degree ≠ n) : homogeneousComponent n φ = 0 := by simp_rw [degree_eq_weight_one] at h exact weightedHomogeneousComponent_eq_zero' n φ h theorem homogeneousComponent_eq_zero (h : φ.totalDegree < n) : homogeneousComponent n φ = 0 := by apply homogeneousComponent_eq_zero' rw [totalDegree, Finset.sup_lt_iff (lt_of_le_of_lt (Nat.zero_le _) h)] at h intro d hd; exact ne_of_lt (h d hd) theorem sum_homogeneousComponent : (∑ i ∈ range (φ.totalDegree + 1), homogeneousComponent i φ) = φ := by ext1 d suffices φ.totalDegree < d.support.sum d → 0 = coeff d φ by simpa [coeff_sum, coeff_homogeneousComponent] exact fun h => (coeff_eq_zero_of_totalDegree_lt h).symm theorem homogeneousComponent_of_mem {m n : ℕ} {p : MvPolynomial σ R} (h : p ∈ homogeneousSubmodule σ R n) : homogeneousComponent m p = if m = n then p else 0 := weightedHomogeneousComponent_of_mem h end HomogeneousComponent end noncomputable section GradedAlgebra /-- The homogeneous submodules form a graded ring. This instance is used by `DirectSum.commSemiring` and `DirectSum.algebra`. -/ lemma HomogeneousSubmodule.gradedMonoid : SetLike.GradedMonoid (homogeneousSubmodule σ R) := WeightedHomogeneousSubmodule.gradedMonoid /-- The decomposition of `MvPolynomial σ R` into homogeneous submodules. -/ abbrev decomposition : DirectSum.Decomposition (homogeneousSubmodule σ R) := weightedDecomposition R (1 : σ → ℕ) /-- `MvPolynomial σ R` as a graded algebra, graded by the degree. We do not make this a global instance because one may want to consider a different graded algebra structure on `MvPolynomial σ R`, induced by another weight function. To make it a local instance, you may use `attribute [local instance] MvPolynomial.gradedAlgebra`. -/ abbrev gradedAlgebra : GradedAlgebra (homogeneousSubmodule σ R) := weightedGradedAlgebra R (1 : σ → ℕ) theorem decomposition.decompose'_apply (φ : MvPolynomial σ R) (i : ℕ) : (decomposition.decompose' φ i : MvPolynomial σ R) = homogeneousComponent i φ := weightedDecomposition.decompose'_apply R _ φ i theorem decomposition.decompose'_eq : decomposition.decompose' = fun φ : MvPolynomial σ R => DirectSum.mk (fun i : ℕ => ↥(homogeneousSubmodule σ R i)) (φ.support.image Finsupp.degree) fun m => ⟨homogeneousComponent m φ, homogeneousComponent_mem m φ⟩ := by rw [degree_eq_weight_one] rfl end GradedAlgebra end MvPolynomial
RingTheory\MvPolynomial\Ideal.lean
/- Copyright (c) 2023 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.MonoidAlgebra.Ideal import Mathlib.Algebra.MvPolynomial.Division /-! # Lemmas about ideals of `MvPolynomial` Notably this contains results about monomial ideals. ## Main results * `MvPolynomial.mem_ideal_span_monomial_image` * `MvPolynomial.mem_ideal_span_X_image` -/ variable {σ R : Type*} namespace MvPolynomial variable [CommSemiring R] /-- `x` is in a monomial ideal generated by `s` iff every element of its support dominates one of the generators. Note that `si ≤ xi` is analogous to saying that the monomial corresponding to `si` divides the monomial corresponding to `xi`. -/ theorem mem_ideal_span_monomial_image {x : MvPolynomial σ R} {s : Set (σ →₀ ℕ)} : x ∈ Ideal.span ((fun s => monomial s (1 : R)) '' s) ↔ ∀ xi ∈ x.support, ∃ si ∈ s, si ≤ xi := by refine AddMonoidAlgebra.mem_ideal_span_of'_image.trans ?_ simp_rw [le_iff_exists_add, add_comm] rfl theorem mem_ideal_span_monomial_image_iff_dvd {x : MvPolynomial σ R} {s : Set (σ →₀ ℕ)} : x ∈ Ideal.span ((fun s => monomial s (1 : R)) '' s) ↔ ∀ xi ∈ x.support, ∃ si ∈ s, monomial si 1 ∣ monomial xi (x.coeff xi) := by refine mem_ideal_span_monomial_image.trans (forall₂_congr fun xi hxi => ?_) simp_rw [monomial_dvd_monomial, one_dvd, and_true_iff, mem_support_iff.mp hxi, false_or_iff] /-- `x` is in a monomial ideal generated by variables `X` iff every element of its support has a component in `s`. -/ theorem mem_ideal_span_X_image {x : MvPolynomial σ R} {s : Set σ} : x ∈ Ideal.span (MvPolynomial.X '' s : Set (MvPolynomial σ R)) ↔ ∀ m ∈ x.support, ∃ i ∈ s, (m : σ →₀ ℕ) i ≠ 0 := by have := @mem_ideal_span_monomial_image σ R _ x ((fun i => Finsupp.single i 1) '' s) rw [Set.image_image] at this refine this.trans ?_ simp [Nat.one_le_iff_ne_zero] end MvPolynomial
RingTheory\MvPolynomial\Localization.lean
/- Copyright (c) 2024 Christian Merten. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christian Merten -/ import Mathlib.Algebra.MvPolynomial.CommRing import Mathlib.RingTheory.Ideal.QuotientOperations import Mathlib.RingTheory.Localization.Away.Basic import Mathlib.RingTheory.Localization.Basic import Mathlib.RingTheory.MvPolynomial.Basic /-! # Localization and multivariate polynomial rings In this file we show some results connecting multivariate polynomial rings and localization. ## Main results - `MvPolynomial.isLocalization`: If `S` is the localization of `R` at a submonoid `M`, then `MvPolynomial σ S` is the localization of `MvPolynomial σ R` at the image of `M` in `MvPolynomial σ R`. -/ variable {σ R : Type*} [CommRing R] (M : Submonoid R) variable (S : Type*) [CommRing S] [Algebra R S] namespace MvPolynomial variable [IsLocalization M S] attribute [local instance] algebraMvPolynomial /-- If `S` is the localization of `R` at a submonoid `M`, then `MvPolynomial σ S` is the localization of `MvPolynomial σ R` at `M.map MvPolynomial.C`. -/ instance isLocalization : IsLocalization (M.map <| C (σ := σ)) (MvPolynomial σ S) where map_units' := by rintro ⟨p, q, hq, rfl⟩ simp only [algebraMap_def, map_C] exact IsUnit.map _ (IsLocalization.map_units _ ⟨q, hq⟩) surj' p := by simp only [algebraMap_def, Prod.exists, Subtype.exists, Submonoid.mem_map, exists_prop, exists_exists_and_eq_and, map_C] refine induction_on' p ?_ ?_ · intro u s obtain ⟨⟨r, m⟩, hr⟩ := IsLocalization.surj M s use monomial u r, m, m.property simp only [map_monomial] rw [← hr, mul_comm, C_mul_monomial, mul_comm] · intro p p' ⟨x, m, hm, hxm⟩ ⟨x', m', hm', hxm'⟩ use x * (C m') + x' * (C m), m * m', Submonoid.mul_mem _ hm hm' simp only [map_mul, map_add, map_C] rw [add_mul, ← mul_assoc, hxm, ← mul_assoc, ← hxm, ← hxm'] ring exists_of_eq {p q} := by intro h simp_rw [algebraMap_def, MvPolynomial.ext_iff, coeff_map] at h choose c hc using (fun m ↦ IsLocalization.exists_of_eq (M := M) (h m)) simp only [Subtype.exists, Submonoid.mem_map, exists_prop, exists_exists_and_eq_and] classical refine ⟨Finset.prod (p.support ∪ q.support) (fun m ↦ c m), ?_, ?_⟩ · exact M.prod_mem (fun m _ ↦ (c m).property) · ext m simp only [coeff_C_mul] by_cases h : m ∈ p.support ∪ q.support · exact Finset.prod_mul_eq_prod_mul_of_exists m h (hc m) · simp only [Finset.mem_union, mem_support_iff, ne_eq, not_or, Decidable.not_not] at h rw [h.left, h.right] lemma isLocalization_C_mk' (a : R) (m : M) : C (IsLocalization.mk' S a m) = IsLocalization.mk' (MvPolynomial σ S) (C (σ := σ) a) ⟨C m, Submonoid.mem_map_of_mem C m.property⟩ := by simp_rw [IsLocalization.eq_mk'_iff_mul_eq, algebraMap_def, map_C, ← map_mul, IsLocalization.mk'_spec] end MvPolynomial namespace IsLocalization.Away open MvPolynomial variable (r : R) [IsLocalization.Away r S] /-- The canonical algebra map from `MvPolynomial Unit R` quotiented by `C r * X () - 1` to the localization of `R` away from `r`. -/ private noncomputable def auxHom : (MvPolynomial Unit R) ⧸ (Ideal.span { C r * X () - 1 }) →ₐ[R] S := Ideal.Quotient.liftₐ (Ideal.span { C r * X () - 1}) (aeval (fun _ ↦ invSelf r)) <| by intro p hp refine Submodule.span_induction hp ?_ ?_ ?_ ?_ · rintro p ⟨q, rfl⟩ simp · simp · intro p q hp hq simp [hp, hq] · intro a x hx simp [hx] @[simp] private lemma auxHom_mk (p : MvPolynomial Unit R) : auxHom S r p = aeval (S₁ := S) (fun _ ↦ invSelf r) p := rfl private noncomputable def auxInv : S →+* (MvPolynomial Unit R) ⧸ Ideal.span { C r * X () - 1 } := letI g : R →+* MvPolynomial Unit R ⧸ (Ideal.span { C r * X () - 1 }) := (Ideal.Quotient.mk _).comp C IsLocalization.Away.lift (S := S) (g := g) r <| by simp only [RingHom.coe_comp, Function.comp_apply, g] rw [isUnit_iff_exists_inv] use (Ideal.Quotient.mk _ <| X ()) rw [← _root_.map_mul, ← map_one (Ideal.Quotient.mk _), Ideal.Quotient.mk_eq_mk_iff_sub_mem] exact Ideal.mem_span_singleton_self (C r * X () - 1) private lemma auxHom_auxInv : (auxHom S r).toRingHom.comp (auxInv S r) = RingHom.id S := by apply IsLocalization.ringHom_ext (Submonoid.powers r) ext x simp [auxInv] private lemma auxInv_auxHom : (auxInv S r).comp (auxHom (S := S) r).toRingHom = RingHom.id _ := by rw [← RingHom.cancel_right (Ideal.Quotient.mk_surjective)] ext x · simp [auxInv] · simp only [auxInv, AlgHom.toRingHom_eq_coe, RingHom.coe_comp, RingHom.coe_coe, Function.comp_apply, auxHom_mk, aeval_X, RingHomCompTriple.comp_eq] erw [IsLocalization.lift_mk'_spec] simp only [map_one, RingHom.coe_comp, Function.comp_apply] rw [← _root_.map_one (Ideal.Quotient.mk _)] rw [← _root_.map_mul, Ideal.Quotient.mk_eq_mk_iff_sub_mem, ← Ideal.neg_mem_iff, neg_sub] exact Ideal.mem_span_singleton_self (C r * X x - 1) /-- The canonical algebra isomorphism from `MvPolynomial Unit R` quotiented by `C r * X () - 1` to the localization of `R` away from `r`. -/ noncomputable def mvPolynomialQuotientEquiv : ((MvPolynomial Unit R) ⧸ Ideal.span { C r * X () - 1 }) ≃ₐ[R] S where toFun := auxHom S r invFun := auxInv S r left_inv x := by simpa using congrFun (congrArg DFunLike.coe <| auxInv_auxHom S r) x right_inv s := by simpa using congrFun (congrArg DFunLike.coe <| auxHom_auxInv S r) s map_mul' := by simp map_add' := by simp commutes' := by simp @[simp] lemma mvPolynomialQuotientEquiv_apply (p : MvPolynomial Unit R) : mvPolynomialQuotientEquiv S r (Ideal.Quotient.mk _ p) = aeval (S₁ := S) (fun _ ↦ invSelf r) p := rfl end IsLocalization.Away
RingTheory\MvPolynomial\NewtonIdentities.lean
/- Copyright (c) 2023 Michael Lee. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Lee -/ import Mathlib.Algebra.Algebra.Subalgebra.Basic import Mathlib.Algebra.MvPolynomial.CommRing import Mathlib.Algebra.MvPolynomial.Rename import Mathlib.Data.Finset.Card import Mathlib.Data.Fintype.Basic import Mathlib.RingTheory.MvPolynomial.Symmetric /-! # Newton's Identities This file defines `MvPolynomial` power sums as a means of implementing Newton's identities. The combinatorial proof, due to Zeilberger, defines for `k : ℕ` a subset `pairs` of `(range k).powerset × range k` and a map `pairMap` such that `pairMap` is an involution on `pairs`, and a map `weight` which identifies elements of `pairs` with the terms of the summation in Newton's identities and which satisfies `weight ∘ pairMap = -weight`. The result therefore follows neatly from an identity implemented in mathlib as `Finset.sum_involution`. Namely, we use `Finset.sum_involution` to show that `∑ t ∈ pairs σ k, weight σ R k t = 0`. We then identify `(-1) ^ k * k * esymm σ R k` with the terms of the weight sum for which `t.fst` has cardinality `k`, and `(-1) ^ i * esymm σ R i * psum σ R (k - i)` with the terms of the weight sum for which `t.fst` has cardinality `i` for `i < k` , and we thereby derive the main result `(-1) ^ k * k * esymm σ R k + ∑ i ∈ range k, (-1) ^ i * esymm σ R i * psum σ R (k - i) = 0` (or rather, two equivalent forms which provide direct definitions for `esymm` and `psum` in lower-degree terms). ## Main declarations * `MvPolynomial.mul_esymm_eq_sum`: a recurrence relation for the `k`th elementary symmetric polynomial in terms of lower-degree elementary symmetric polynomials and power sums. * `MvPolynomial.psum_eq_mul_esymm_sub_sum`: a recurrence relation for the degree-`k` power sum in terms of lower-degree elementary symmetric polynomials and power sums. ## References See [zeilberger1984] for the combinatorial proof of Newton's identities. -/ open Equiv (Perm) open MvPolynomial noncomputable section namespace MvPolynomial open Finset Nat namespace NewtonIdentities variable (σ : Type*) (R : Type*) [CommRing R] section DecidableEq variable [DecidableEq σ] private def pairMap (t : Finset σ × σ) : Finset σ × σ := if h : t.snd ∈ t.fst then (t.fst.erase t.snd, t.snd) else (t.fst.cons t.snd h, t.snd) private lemma pairMap_ne_self (t : Finset σ × σ) : pairMap σ t ≠ t := by rw [pairMap] split_ifs with h1 all_goals by_contra ht; rw [← ht] at h1; simp_all private lemma pairMap_of_snd_mem_fst {t : Finset σ × σ} (h : t.snd ∈ t.fst) : pairMap σ t = (t.fst.erase t.snd, t.snd) := by simp [pairMap, h] private lemma pairMap_of_snd_nmem_fst {t : Finset σ × σ} (h : t.snd ∉ t.fst) : pairMap σ t = (t.fst.cons t.snd h, t.snd) := by simp [pairMap, h] @[simp] private theorem pairMap_involutive : (pairMap σ).Involutive := by intro t rw [pairMap, pairMap] split_ifs with h1 h2 h3 · simp at h2 · simp [insert_erase h1] · simp_all · simp at h3 variable [Fintype σ] private def pairs (k : ℕ) : Finset (Finset σ × σ) := univ.filter (fun t ↦ card t.fst ≤ k ∧ (card t.fst = k → t.snd ∈ t.fst)) @[simp] private lemma mem_pairs (k : ℕ) (t : Finset σ × σ) : t ∈ pairs σ k ↔ card t.fst ≤ k ∧ (card t.fst = k → t.snd ∈ t.fst) := by simp [pairs] private def weight (k : ℕ) (t : Finset σ × σ) : MvPolynomial σ R := (-1) ^ card t.fst * ((∏ a ∈ t.fst, X a) * X t.snd ^ (k - card t.fst)) private theorem pairMap_mem_pairs {k : ℕ} (t : Finset σ × σ) (h : t ∈ pairs σ k) : pairMap σ t ∈ pairs σ k := by rw [mem_pairs] at h ⊢ rcases (em (t.snd ∈ t.fst)) with h1 | h1 · rw [pairMap_of_snd_mem_fst σ h1] simp only [h1, implies_true, and_true] at h simp only [card_erase_of_mem h1, tsub_le_iff_right, mem_erase, ne_eq, h1] refine ⟨le_step h, ?_⟩ by_contra h2 simp only [not_true_eq_false, and_true, not_forall, not_false_eq_true, exists_prop] at h2 rw [← h2] at h exact not_le_of_lt (sub_lt (card_pos.mpr ⟨t.snd, h1⟩) zero_lt_one) h · rw [pairMap_of_snd_nmem_fst σ h1] simp only [h1] at h simp only [card_cons, mem_cons, true_or, implies_true, and_true] exact (le_iff_eq_or_lt.mp h.left).resolve_left h.right private theorem weight_add_weight_pairMap {k : ℕ} (t : Finset σ × σ) (h : t ∈ pairs σ k) : weight σ R k t + weight σ R k (pairMap σ t) = 0 := by rw [weight, weight] rw [mem_pairs] at h have h2 (n : ℕ) : -(-1 : MvPolynomial σ R) ^ n = (-1) ^ (n + 1) := by rw [← neg_one_mul ((-1 : MvPolynomial σ R) ^ n), pow_add, pow_one, mul_comm] rcases (em (t.snd ∈ t.fst)) with h1 | h1 · rw [pairMap_of_snd_mem_fst σ h1] simp only [← prod_erase_mul t.fst (fun j ↦ (X j : MvPolynomial σ R)) h1, mul_assoc (∏ a ∈ erase t.fst t.snd, X a), card_erase_of_mem h1] nth_rewrite 1 [← pow_one (X t.snd)] simp only [← pow_add, add_comm] have h3 : 1 ≤ card t.fst := lt_iff_add_one_le.mp (card_pos.mpr ⟨t.snd, h1⟩) rw [← tsub_tsub_assoc h.left h3, ← neg_neg ((-1 : MvPolynomial σ R) ^ (card t.fst - 1)), h2 (card t.fst - 1), Nat.sub_add_cancel h3] simp · rw [pairMap_of_snd_nmem_fst σ h1] simp only [mul_comm, mul_assoc (∏ a ∈ t.fst, X a), card_cons, prod_cons] nth_rewrite 2 [← pow_one (X t.snd)] simp only [← pow_add, ← Nat.add_sub_assoc (Nat.lt_of_le_of_ne h.left (mt h.right h1)), add_comm, Nat.succ_eq_add_one, Nat.add_sub_add_right] rw [← neg_neg ((-1 : MvPolynomial σ R) ^ card t.fst), h2] simp private theorem weight_sum (k : ℕ) : ∑ t ∈ pairs σ k, weight σ R k t = 0 := sum_involution (fun t _ ↦ pairMap σ t) (weight_add_weight_pairMap σ R) (fun t _ ↦ (fun _ ↦ pairMap_ne_self σ t)) (pairMap_mem_pairs σ) (fun t _ ↦ pairMap_involutive σ t) private theorem sum_filter_pairs_eq_sum_powersetCard_sum (k : ℕ) (f : Finset σ × σ → MvPolynomial σ R) : (∑ t ∈ filter (fun t ↦ card t.fst = k) (pairs σ k), f t) = ∑ A ∈ powersetCard k univ, (∑ j ∈ A, f (A, j)) := by apply sum_finset_product aesop private theorem sum_filter_pairs_eq_sum_powersetCard_mem_filter_antidiagonal_sum (k : ℕ) (a : ℕ × ℕ) (ha : a ∈ (antidiagonal k).filter (fun a ↦ a.fst < k)) (f : Finset σ × σ → MvPolynomial σ R) : (∑ t ∈ filter (fun t ↦ card t.fst = a.fst) (pairs σ k), f t) = ∑ A ∈ powersetCard a.fst univ, (∑ j, f (A, j)) := by apply sum_finset_product simp only [mem_filter, mem_powersetCard_univ, mem_univ, and_true, and_iff_right_iff_imp] rintro p hp have : card p.fst ≤ k := by apply le_of_lt; aesop aesop private lemma filter_pairs_lt (k : ℕ) : (pairs σ k).filter (fun (s, _) ↦ s.card < k) = (range k).disjiUnion (powersetCard · univ) ((pairwise_disjoint_powersetCard _).set_pairwise _) ×ˢ univ := by ext; aesop (add unsafe le_of_lt) private theorem sum_filter_pairs_eq_sum_filter_antidiagonal_powersetCard_sum (k : ℕ) (f : Finset σ × σ → MvPolynomial σ R) : ∑ t ∈ (pairs σ k).filter fun t ↦ card t.fst < k, f t = ∑ a ∈ (antidiagonal k).filter fun a ↦ a.fst < k, ∑ A ∈ powersetCard a.fst univ, ∑ j, f (A, j) := by rw [filter_pairs_lt, sum_product, sum_disjiUnion] refine sum_nbij' (fun n ↦ (n, k - n)) Prod.fst ?_ ?_ ?_ ?_ ?_ <;> simp (config := { contextual := true }) [@eq_comm _ _ k, Nat.add_sub_cancel', le_of_lt] private theorem disjoint_filter_pairs_lt_filter_pairs_eq (k : ℕ) : Disjoint (filter (fun t ↦ card t.fst < k) (pairs σ k)) (filter (fun t ↦ card t.fst = k) (pairs σ k)) := by rw [disjoint_filter] exact fun _ _ h1 h2 ↦ lt_irrefl _ (h2.symm.subst h1) private theorem disjUnion_filter_pairs_eq_pairs (k : ℕ) : disjUnion (filter (fun t ↦ card t.fst < k) (pairs σ k)) (filter (fun t ↦ card t.fst = k) (pairs σ k)) (disjoint_filter_pairs_lt_filter_pairs_eq σ k) = pairs σ k := by simp only [disjUnion_eq_union, Finset.ext_iff, pairs, filter_filter, mem_filter] intro a rw [← filter_or, mem_filter] refine ⟨fun ha ↦ by tauto, fun ha ↦ ?_⟩ have hacard := le_iff_lt_or_eq.mp ha.2.1 tauto end DecidableEq variable [Fintype σ] private theorem esymm_summand_to_weight (k : ℕ) (A : Finset σ) (h : A ∈ powersetCard k univ) : ∑ j ∈ A, weight σ R k (A, j) = k * (-1) ^ k * (∏ i ∈ A, X i : MvPolynomial σ R) := by simp [weight, mem_powersetCard_univ.mp h, mul_assoc] private theorem esymm_to_weight [DecidableEq σ] (k : ℕ) : k * esymm σ R k = (-1) ^ k * ∑ t ∈ filter (fun t ↦ card t.fst = k) (pairs σ k), weight σ R k t := by rw [esymm, sum_filter_pairs_eq_sum_powersetCard_sum σ R k (fun t ↦ weight σ R k t), sum_congr rfl (esymm_summand_to_weight σ R k), mul_comm (k : MvPolynomial σ R) ((-1) ^ k), ← mul_sum, ← mul_assoc, ← mul_assoc, ← pow_add, Even.neg_one_pow ⟨k, rfl⟩, one_mul] private theorem esymm_mul_psum_summand_to_weight (k : ℕ) (a : ℕ × ℕ) (ha : a ∈ antidiagonal k) : ∑ A ∈ powersetCard a.fst univ, ∑ j, weight σ R k (A, j) = (-1) ^ a.fst * esymm σ R a.fst * psum σ R a.snd := by simp only [esymm, psum, weight, ← mul_assoc, mul_sum] rw [sum_comm] refine sum_congr rfl fun x _ ↦ ?_ rw [sum_mul] refine sum_congr rfl fun s hs ↦ ?_ rw [mem_powersetCard_univ.mp hs, ← mem_antidiagonal.mp ha, add_sub_self_left] private theorem esymm_mul_psum_to_weight [DecidableEq σ] (k : ℕ) : ∑ a ∈ (antidiagonal k).filter (fun a ↦ a.fst < k), (-1) ^ a.fst * esymm σ R a.fst * psum σ R a.snd = ∑ t ∈ filter (fun t ↦ card t.fst < k) (pairs σ k), weight σ R k t := by rw [← sum_congr rfl (fun a ha ↦ esymm_mul_psum_summand_to_weight σ R k a (mem_filter.mp ha).left), sum_filter_pairs_eq_sum_filter_antidiagonal_powersetCard_sum σ R k] end NewtonIdentities variable (σ : Type*) [Fintype σ] (R : Type*) [CommRing R] /-- **Newton's identities** give a recurrence relation for the kth elementary symmetric polynomial in terms of lower degree elementary symmetric polynomials and power sums. -/ theorem mul_esymm_eq_sum (k : ℕ) : k * esymm σ R k = (-1) ^ (k + 1) * ∑ a ∈ (antidiagonal k).filter (fun a ↦ a.fst < k), (-1) ^ a.fst * esymm σ R a.fst * psum σ R a.snd := by classical rw [NewtonIdentities.esymm_to_weight σ R k, NewtonIdentities.esymm_mul_psum_to_weight σ R k, eq_comm, ← sub_eq_zero, sub_eq_add_neg, neg_mul_eq_neg_mul, neg_eq_neg_one_mul ((-1 : MvPolynomial σ R) ^ k)] nth_rw 2 [← pow_one (-1 : MvPolynomial σ R)] rw [← pow_add, add_comm 1 k, ← left_distrib, ← sum_disjUnion (NewtonIdentities.disjoint_filter_pairs_lt_filter_pairs_eq σ k), NewtonIdentities.disjUnion_filter_pairs_eq_pairs σ k, NewtonIdentities.weight_sum σ R k, neg_one_pow_mul_eq_zero_iff.mpr rfl] theorem sum_antidiagonal_card_esymm_psum_eq_zero : ∑ a ∈ antidiagonal (Fintype.card σ), (-1) ^ a.fst * esymm σ R a.fst * psum σ R a.snd = 0 := by let k := Fintype.card σ suffices (-1 : MvPolynomial σ R) ^ (k + 1) * ∑ a ∈ antidiagonal k, (-1) ^ a.fst * esymm σ R a.fst * psum σ R a.snd = 0 by simpa using this simp [← sum_filter_add_sum_filter_not (antidiagonal k) (fun a ↦ a.fst < k), ← mul_esymm_eq_sum, mul_add, ← mul_assoc, ← pow_add, mul_comm ↑k (esymm σ R k)] /-- A version of Newton's identities which may be more useful in the case that we know the values of the elementary symmetric polynomials and would like to calculate the values of the power sums. -/ theorem psum_eq_mul_esymm_sub_sum (k : ℕ) (h : 0 < k) : psum σ R k = (-1) ^ (k + 1) * k * esymm σ R k - ∑ a ∈ (antidiagonal k).filter (fun a ↦ a.fst ∈ Set.Ioo 0 k), (-1) ^ a.fst * esymm σ R a.fst * psum σ R a.snd := by simp only [Set.Ioo, Set.mem_setOf_eq, and_comm] have hesymm := mul_esymm_eq_sum σ R k rw [← (sum_filter_add_sum_filter_not ((antidiagonal k).filter (fun a ↦ a.fst < k)) (fun a ↦ 0 < a.fst) (fun a ↦ (-1) ^ a.fst * esymm σ R a.fst * psum σ R a.snd))] at hesymm have sub_both_sides := congrArg (· - (-1 : MvPolynomial σ R) ^ (k + 1) * ∑ a ∈ ((antidiagonal k).filter (fun a ↦ a.fst < k)).filter (fun a ↦ 0 < a.fst), (-1) ^ a.fst * esymm σ R a.fst * psum σ R a.snd) hesymm simp only [left_distrib, add_sub_cancel_left] at sub_both_sides have sub_both_sides := congrArg ((-1 : MvPolynomial σ R) ^ (k + 1) * ·) sub_both_sides simp only [mul_sub_left_distrib, ← mul_assoc, ← pow_add, Even.neg_one_pow ⟨k + 1, rfl⟩, one_mul, not_le, lt_one_iff, filter_filter (fun a : ℕ × ℕ ↦ a.fst < k) (fun a ↦ ¬0 < a.fst)] at sub_both_sides have : filter (fun a ↦ a.fst < k ∧ ¬0 < a.fst) (antidiagonal k) = {(0, k)} := by ext a rw [mem_filter, mem_antidiagonal, mem_singleton] refine ⟨?_, by rintro rfl; omega⟩ rintro ⟨ha, ⟨_, ha0⟩⟩ rw [← ha, Nat.eq_zero_of_not_pos ha0, zero_add, ← Nat.eq_zero_of_not_pos ha0] rw [this, sum_singleton] at sub_both_sides simp only [_root_.pow_zero, esymm_zero, mul_one, one_mul, filter_filter] at sub_both_sides exact sub_both_sides.symm end MvPolynomial
RingTheory\MvPolynomial\Symmetric.lean
/- Copyright (c) 2020 Hanting Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Hanting Zhang, Johan Commelin -/ import Mathlib.Algebra.Algebra.Subalgebra.Basic import Mathlib.Algebra.MvPolynomial.CommRing import Mathlib.Combinatorics.Enumerative.Partition /-! # Symmetric Polynomials and Elementary Symmetric Polynomials This file defines symmetric `MvPolynomial`s and the bases of elementary, complete homogeneous, power sum, and monomial symmetric `MvPolynomial`s. We also prove some basic facts about them. ## Main declarations * `MvPolynomial.IsSymmetric` * `MvPolynomial.symmetricSubalgebra` * `MvPolynomial.esymm` * `MvPolynomial.hsymm` * `MvPolynomial.psum` * `MvPolynomial.msymm` ## Notation + `esymm σ R n` is the `n`th elementary symmetric polynomial in `MvPolynomial σ R`. + `hsymm σ R n` is the `n`th complete homogeneous symmetric polynomial in `MvPolynomial σ R`. + `psum σ R n` is the degree-`n` power sum in `MvPolynomial σ R`, i.e. the sum of monomials `(X i)^n` over `i ∈ σ`. + `msymm σ R μ` is the monomial symmetric polynomial whose exponents set are the parts of `μ ⊢ n` in `MvPolynomial σ R`. As in other polynomial files, we typically use the notation: + `σ τ : Type*` (indexing the variables) + `R S : Type*` `[CommSemiring R]` `[CommSemiring S]` (the coefficients) + `r : R` elements of the coefficient ring + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `φ ψ : MvPolynomial σ R` -/ open Equiv (Perm) noncomputable section namespace Multiset variable {R : Type*} [CommSemiring R] /-- The `n`th elementary symmetric function evaluated at the elements of `s` -/ def esymm (s : Multiset R) (n : ℕ) : R := ((s.powersetCard n).map Multiset.prod).sum theorem _root_.Finset.esymm_map_val {σ} (f : σ → R) (s : Finset σ) (n : ℕ) : (s.val.map f).esymm n = (s.powersetCard n).sum fun t => t.prod f := by simp only [esymm, powersetCard_map, ← Finset.map_val_val_powersetCard, map_map] rfl end Multiset namespace MvPolynomial variable {σ τ : Type*} {R S : Type*} /-- A `MvPolynomial φ` is symmetric if it is invariant under permutations of its variables by the `rename` operation -/ def IsSymmetric [CommSemiring R] (φ : MvPolynomial σ R) : Prop := ∀ e : Perm σ, rename e φ = φ /-- The subalgebra of symmetric `MvPolynomial`s. -/ def symmetricSubalgebra (σ R : Type*) [CommSemiring R] : Subalgebra R (MvPolynomial σ R) where carrier := setOf IsSymmetric algebraMap_mem' r e := rename_C e r mul_mem' ha hb e := by rw [map_mul, ha, hb] add_mem' ha hb e := by rw [map_add, ha, hb] @[simp] theorem mem_symmetricSubalgebra [CommSemiring R] (p : MvPolynomial σ R) : p ∈ symmetricSubalgebra σ R ↔ p.IsSymmetric := Iff.rfl namespace IsSymmetric section CommSemiring variable [CommSemiring R] [CommSemiring S] {φ ψ : MvPolynomial σ R} @[simp] theorem C (r : R) : IsSymmetric (C r : MvPolynomial σ R) := (symmetricSubalgebra σ R).algebraMap_mem r @[simp] theorem zero : IsSymmetric (0 : MvPolynomial σ R) := (symmetricSubalgebra σ R).zero_mem @[simp] theorem one : IsSymmetric (1 : MvPolynomial σ R) := (symmetricSubalgebra σ R).one_mem theorem add (hφ : IsSymmetric φ) (hψ : IsSymmetric ψ) : IsSymmetric (φ + ψ) := (symmetricSubalgebra σ R).add_mem hφ hψ theorem mul (hφ : IsSymmetric φ) (hψ : IsSymmetric ψ) : IsSymmetric (φ * ψ) := (symmetricSubalgebra σ R).mul_mem hφ hψ theorem smul (r : R) (hφ : IsSymmetric φ) : IsSymmetric (r • φ) := (symmetricSubalgebra σ R).smul_mem hφ r @[simp] theorem map (hφ : IsSymmetric φ) (f : R →+* S) : IsSymmetric (map f φ) := fun e => by rw [← map_rename, hφ] protected theorem rename (hφ : φ.IsSymmetric) (e : σ ≃ τ) : (rename e φ).IsSymmetric := fun _ => by apply rename_injective _ e.symm.injective simp_rw [rename_rename, ← Equiv.coe_trans, Equiv.self_trans_symm, Equiv.coe_refl, rename_id] rw [hφ] @[simp] theorem _root_.MvPolynomial.isSymmetric_rename {e : σ ≃ τ} : (MvPolynomial.rename e φ).IsSymmetric ↔ φ.IsSymmetric := ⟨fun h => by simpa using (IsSymmetric.rename (R := R) h e.symm), (IsSymmetric.rename · e)⟩ end CommSemiring section CommRing variable [CommRing R] {φ ψ : MvPolynomial σ R} theorem neg (hφ : IsSymmetric φ) : IsSymmetric (-φ) := (symmetricSubalgebra σ R).neg_mem hφ theorem sub (hφ : IsSymmetric φ) (hψ : IsSymmetric ψ) : IsSymmetric (φ - ψ) := (symmetricSubalgebra σ R).sub_mem hφ hψ end CommRing end IsSymmetric /-- `MvPolynomial.rename` induces an isomorphism between the symmetric subalgebras. -/ @[simps!] def renameSymmetricSubalgebra [CommSemiring R] (e : σ ≃ τ) : symmetricSubalgebra σ R ≃ₐ[R] symmetricSubalgebra τ R := AlgEquiv.ofAlgHom (((rename e).comp (symmetricSubalgebra σ R).val).codRestrict _ <| fun x => x.2.rename e) (((rename e.symm).comp <| Subalgebra.val _).codRestrict _ <| fun x => x.2.rename e.symm) (AlgHom.ext <| fun p => Subtype.ext <| by simp) (AlgHom.ext <| fun p => Subtype.ext <| by simp) variable (σ R : Type*) [CommSemiring R] [CommSemiring S] [Fintype σ] [Fintype τ] section ElementarySymmetric open Finset /-- The `n`th elementary symmetric `MvPolynomial σ R`. It is the sum over all the degree n squarefree monomials in `MvPolynomial σ R`. -/ def esymm (n : ℕ) : MvPolynomial σ R := ∑ t ∈ powersetCard n univ, ∏ i ∈ t, X i /-- `esymmPart` is the product of the symmetric polynomials `esymm μᵢ`, where `μ = (μ₁, μ₂, ...)` is a partition. -/ def esymmPart {n : ℕ} (μ : n.Partition) : MvPolynomial σ R := (μ.parts.map (esymm σ R)).prod /-- The `n`th elementary symmetric `MvPolynomial σ R` is obtained by evaluating the `n`th elementary symmetric at the `Multiset` of the monomials -/ theorem esymm_eq_multiset_esymm : esymm σ R = (univ.val.map X).esymm := by exact funext fun n => (esymm_map_val X _ n).symm theorem aeval_esymm_eq_multiset_esymm [Algebra R S] (n : ℕ) (f : σ → S) : aeval f (esymm σ R n) = (univ.val.map f).esymm n := by simp_rw [esymm, aeval_sum, aeval_prod, aeval_X, esymm_map_val] /-- We can define `esymm σ R n` by summing over a subtype instead of over `powerset_len`. -/ theorem esymm_eq_sum_subtype (n : ℕ) : esymm σ R n = ∑ t : { s : Finset σ // s.card = n }, ∏ i ∈ (t : Finset σ), X i := sum_subtype _ (fun _ => mem_powersetCard_univ) _ /-- We can define `esymm σ R n` as a sum over explicit monomials -/ theorem esymm_eq_sum_monomial (n : ℕ) : esymm σ R n = ∑ t ∈ powersetCard n univ, monomial (∑ i ∈ t, Finsupp.single i 1) 1 := by simp_rw [monomial_sum_one] rfl @[simp] theorem esymm_zero : esymm σ R 0 = 1 := by simp only [esymm, powersetCard_zero, sum_singleton, prod_empty] @[simp] theorem esymm_one : esymm σ R 1 = ∑ i, X i := by simp [esymm, powersetCard_one] theorem esymmPart_zero : esymmPart σ R (.indiscrete 0) = 1 := by simp [esymmPart] @[simp] theorem esymmPart_indiscrete (n : ℕ) : esymmPart σ R (.indiscrete n) = esymm σ R n := by cases n <;> simp [esymmPart] theorem map_esymm (n : ℕ) (f : R →+* S) : map f (esymm σ R n) = esymm σ S n := by simp_rw [esymm, map_sum, map_prod, map_X] theorem rename_esymm (n : ℕ) (e : σ ≃ τ) : rename e (esymm σ R n) = esymm τ R n := calc rename e (esymm σ R n) = ∑ x ∈ powersetCard n univ, ∏ i ∈ x, X (e i) := by simp_rw [esymm, map_sum, map_prod, rename_X] _ = ∑ t ∈ powersetCard n (univ.map e.toEmbedding), ∏ i ∈ t, X i := by simp [powersetCard_map, -map_univ_equiv] -- Porting note: Why did `mapEmbedding_apply` not work? dsimp [mapEmbedding, OrderEmbedding.ofMapLEIff] simp _ = ∑ t ∈ powersetCard n univ, ∏ i ∈ t, X i := by rw [map_univ_equiv] theorem esymm_isSymmetric (n : ℕ) : IsSymmetric (esymm σ R n) := by intro rw [rename_esymm] theorem support_esymm'' [DecidableEq σ] [Nontrivial R] (n : ℕ) : (esymm σ R n).support = (powersetCard n (univ : Finset σ)).biUnion fun t => (Finsupp.single (∑ i ∈ t, Finsupp.single i 1) (1 : R)).support := by rw [esymm_eq_sum_monomial] simp only [← single_eq_monomial] refine Finsupp.support_sum_eq_biUnion (powersetCard n (univ : Finset σ)) ?_ intro s t hst rw [disjoint_left, Finsupp.support_single_ne_zero _ one_ne_zero] rw [Finsupp.support_single_ne_zero _ one_ne_zero] simp only [one_ne_zero, mem_singleton, Finsupp.mem_support_iff] rintro a h rfl have := congr_arg Finsupp.support h rw [Finsupp.support_sum_eq_biUnion, Finsupp.support_sum_eq_biUnion] at this · have hsingle : ∀ s : Finset σ, ∀ x : σ, x ∈ s → (Finsupp.single x 1).support = {x} := by intros _ x _ rw [Finsupp.support_single_ne_zero x one_ne_zero] have hs := biUnion_congr (of_eq_true (eq_self s)) (hsingle s) have ht := biUnion_congr (of_eq_true (eq_self t)) (hsingle t) rw [hs, ht] at this · simp only [biUnion_singleton_eq_self] at this exact absurd this hst.symm all_goals intro x y; simp [Finsupp.support_single_disjoint] theorem support_esymm' [DecidableEq σ] [Nontrivial R] (n : ℕ) : (esymm σ R n).support = (powersetCard n (univ : Finset σ)).biUnion fun t => {∑ i ∈ t, Finsupp.single i 1} := by rw [support_esymm''] congr funext exact Finsupp.support_single_ne_zero _ one_ne_zero theorem support_esymm [DecidableEq σ] [Nontrivial R] (n : ℕ) : (esymm σ R n).support = (powersetCard n (univ : Finset σ)).image fun t => ∑ i ∈ t, Finsupp.single i 1 := by rw [support_esymm'] exact biUnion_singleton theorem degrees_esymm [Nontrivial R] {n : ℕ} (hpos : 0 < n) (hn : n ≤ Fintype.card σ) : (esymm σ R n).degrees = (univ : Finset σ).val := by classical have : (Finsupp.toMultiset ∘ fun t : Finset σ => ∑ i ∈ t, Finsupp.single i 1) = val := by funext simp [Finsupp.toMultiset_sum_single] rw [degrees_def, support_esymm, sup_image, this] have : ((powersetCard n univ).sup (fun (x : Finset σ) => x)).val = sup (powersetCard n univ) val := by refine comp_sup_eq_sup_comp _ ?_ ?_ · intros simp only [union_val, sup_eq_union] congr · rfl rw [← this] obtain ⟨k, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hpos.ne' simpa using powersetCard_sup _ _ (Nat.lt_of_succ_le hn) end ElementarySymmetric section CompleteHomogeneousSymmetric open Finset Multiset Sym variable [DecidableEq σ] [DecidableEq τ] /-- The `n`th complete homogeneous symmetric `MvPolynomial σ R`. It is the sum over all the degree n monomials in `MvPolynomial σ R`. -/ def hsymm (n : ℕ) : MvPolynomial σ R := ∑ s : Sym σ n, (s.1.map X).prod /-- `hsymmPart` is the product of the symmetric polynomials `hsymm μᵢ`, where `μ = (μ₁, μ₂, ...)` is a partition. -/ def hsymmPart {n : ℕ} (μ : n.Partition) : MvPolynomial σ R := (μ.parts.map (hsymm σ R)).prod @[simp] theorem hsymm_zero : hsymm σ R 0 = 1 := by simp [hsymm, eq_nil_of_card_zero] @[simp] theorem hsymm_one : hsymm σ R 1 = ∑ i, X i := by symm apply Fintype.sum_equiv oneEquiv simp only [oneEquiv_apply, Multiset.map_singleton, Multiset.prod_singleton, implies_true] theorem hsymmPart_zero : hsymmPart σ R (.indiscrete 0) = 1 := by simp [hsymmPart] @[simp] theorem hsymmPart_indiscrete (n : ℕ) : hsymmPart σ R (.indiscrete n) = hsymm σ R n := by cases n <;> simp [hsymmPart] theorem map_hsymm (n : ℕ) (f : R →+* S) : map f (hsymm σ R n) = hsymm σ S n := by simp [hsymm, ← Multiset.prod_hom'] theorem rename_hsymm (n : ℕ) (e : σ ≃ τ) : rename e (hsymm σ R n) = hsymm τ R n := by simp_rw [hsymm, map_sum, ← prod_hom', rename_X] apply Fintype.sum_equiv (equivCongr e) simp theorem hsymm_isSymmetric (n : ℕ) : IsSymmetric (hsymm σ R n) := rename_hsymm _ _ n end CompleteHomogeneousSymmetric section PowerSum open Finset /-- The degree-`n` power sum symmetric `MvPolynomial σ R`. It is the sum over all the `n`-th powers of the variables. -/ def psum (n : ℕ) : MvPolynomial σ R := ∑ i, X i ^ n /-- `psumPart` is the product of the symmetric polynomials `psum μᵢ`, where `μ = (μ₁, μ₂, ...)` is a partition. -/ def psumPart {n : ℕ} (μ : n.Partition) : MvPolynomial σ R := (μ.parts.map (psum σ R)).prod @[simp] theorem psum_zero : psum σ R 0 = Fintype.card σ := by simp [psum] @[simp] theorem psum_one : psum σ R 1 = ∑ i, X i := by simp [psum] @[simp] theorem psumPart_zero : psumPart σ R (.indiscrete 0) = 1 := by simp [psumPart] @[simp] theorem psumPart_indiscrete {n : ℕ} (npos : n ≠ 0) : psumPart σ R (.indiscrete n) = psum σ R n := by simp [psumPart, npos] @[simp] theorem rename_psum (n : ℕ) (e : σ ≃ τ) : rename e (psum σ R n) = psum τ R n := by simp_rw [psum, map_sum, map_pow, rename_X, e.sum_comp (X · ^ n)] theorem psum_isSymmetric (n : ℕ) : IsSymmetric (psum σ R n) := rename_psum _ _ n end PowerSum section MonomialSymmetric variable [DecidableEq σ] [DecidableEq τ] {n : ℕ} /-- The monomial symmetric `MvPolynomial σ R` with exponent set μ. It is the sum over all the monomials in `MvPolynomial σ R` such that the multiset of exponents is equal to the multiset of parts of μ. -/ def msymm (μ : n.Partition) : MvPolynomial σ R := ∑ s : {a : Sym σ n // .ofSym a = μ}, (s.1.1.map X).prod @[simp] theorem msymm_zero : msymm σ R (.indiscrete 0) = 1 := by rw [msymm, Fintype.sum_subsingleton _ ⟨(Sym.nil : Sym σ 0), by rfl⟩] simp @[simp] theorem msymm_one : msymm σ R (.indiscrete 1) = ∑ i, X i := by have : (fun (x : Sym σ 1) ↦ x ∈ Set.univ) = (fun x ↦ Nat.Partition.ofSym x = Nat.Partition.indiscrete 1) := by simp_rw [Set.mem_univ, Nat.Partition.ofSym_one] symm rw [Fintype.sum_equiv (Equiv.trans Sym.oneEquiv (Equiv.Set.univ (Sym σ 1)).symm) _ (fun s ↦ (s.1.1.map X).prod)] · apply Fintype.sum_equiv (Equiv.subtypeEquivProp this) intro x congr · intro x rw [← Multiset.prod_singleton (X x), ← Multiset.map_singleton] congr @[simp] theorem rename_msymm (μ : n.Partition) (e : σ ≃ τ) : rename e (msymm σ R μ) = msymm τ R μ := by rw [msymm, map_sum] apply Fintype.sum_equiv (Nat.Partition.ofSymShapeEquiv μ e) intro rw [← Multiset.prod_hom, Multiset.map_map, Nat.Partition.ofSymShapeEquiv] simp theorem msymm_isSymmetric (μ : n.Partition) : IsSymmetric (msymm σ R μ) := rename_msymm _ _ μ end MonomialSymmetric end MvPolynomial
RingTheory\MvPolynomial\Tower.lean
/- Copyright (c) 2022 Yuyang Zhao. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yuyang Zhao -/ import Mathlib.Algebra.Algebra.Tower import Mathlib.Algebra.MvPolynomial.Basic /-! # Algebra towers for multivariate polynomial This file proves some basic results about the algebra tower structure for the type `MvPolynomial σ R`. This structure itself is provided elsewhere as `MvPolynomial.isScalarTower` When you update this file, you can also try to make a corresponding update in `RingTheory.Polynomial.Tower`. -/ variable (R A B : Type*) {σ : Type*} namespace MvPolynomial section Semiring variable [CommSemiring R] [CommSemiring A] [CommSemiring B] variable [Algebra R A] [Algebra A B] [Algebra R B] variable [IsScalarTower R A B] variable {R B} theorem aeval_map_algebraMap (x : σ → B) (p : MvPolynomial σ R) : aeval x (map (algebraMap R A) p) = aeval x p := by rw [aeval_def, aeval_def, eval₂_map, IsScalarTower.algebraMap_eq R A B] end Semiring section CommSemiring variable [CommSemiring R] [CommSemiring A] [CommSemiring B] variable [Algebra R A] [Algebra A B] [Algebra R B] [IsScalarTower R A B] variable {R A} theorem aeval_algebraMap_apply (x : σ → A) (p : MvPolynomial σ R) : aeval (algebraMap A B ∘ x) p = algebraMap A B (MvPolynomial.aeval x p) := by rw [aeval_def, aeval_def, ← coe_eval₂Hom, ← coe_eval₂Hom, map_eval₂Hom, ← IsScalarTower.algebraMap_eq] -- Porting note: added simp only [Function.comp] theorem aeval_algebraMap_eq_zero_iff [NoZeroSMulDivisors A B] [Nontrivial B] (x : σ → A) (p : MvPolynomial σ R) : aeval (algebraMap A B ∘ x) p = 0 ↔ aeval x p = 0 := by rw [aeval_algebraMap_apply, Algebra.algebraMap_eq_smul_one, smul_eq_zero, iff_false_intro (one_ne_zero' B), or_false_iff] theorem aeval_algebraMap_eq_zero_iff_of_injective {x : σ → A} {p : MvPolynomial σ R} (h : Function.Injective (algebraMap A B)) : aeval (algebraMap A B ∘ x) p = 0 ↔ aeval x p = 0 := by rw [aeval_algebraMap_apply, ← (algebraMap A B).map_zero, h.eq_iff] end CommSemiring end MvPolynomial namespace Subalgebra open MvPolynomial section CommSemiring variable {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] @[simp] theorem mvPolynomial_aeval_coe (S : Subalgebra R A) (x : σ → S) (p : MvPolynomial σ R) : aeval (fun i => (x i : A)) p = aeval x p := by convert aeval_algebraMap_apply A x p end CommSemiring end Subalgebra
RingTheory\MvPolynomial\WeightedHomogeneous.lean
/- Copyright (c) 2022 María Inés de Frutos-Fernández. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Antoine Chambert-Loir, María Inés de Frutos-Fernández -/ import Mathlib.Algebra.DirectSum.Decomposition import Mathlib.Algebra.GradedMonoid import Mathlib.Algebra.MvPolynomial.Basic import Mathlib.Algebra.Order.Monoid.Canonical.Defs import Mathlib.Data.Finsupp.Weight import Mathlib.RingTheory.GradedAlgebra.Basic /-! # Weighted homogeneous polynomials It is possible to assign weights (in a commutative additive monoid `M`) to the variables of a multivariate polynomial ring, so that monomials of the ring then have a weighted degree with respect to the weights of the variables. The weights are represented by a function `w : σ → M`, where `σ` are the indeterminates. A multivariate polynomial `φ` is weighted homogeneous of weighted degree `m : M` if all monomials occurring in `φ` have the same weighted degree `m`. ## Main definitions/lemmas * `weightedTotalDegree' w φ` : the weighted total degree of a multivariate polynomial with respect to the weights `w`, taking values in `WithBot M`. * `weightedTotalDegree w φ` : When `M` has a `⊥` element, we can define the weighted total degree of a multivariate polynomial as a function taking values in `M`. * `IsWeightedHomogeneous w φ m`: a predicate that asserts that `φ` is weighted homogeneous of weighted degree `m` with respect to the weights `w`. * `weightedHomogeneousSubmodule R w m`: the submodule of homogeneous polynomials of weighted degree `m`. * `weightedHomogeneousComponent w m`: the additive morphism that projects polynomials onto their summand that is weighted homogeneous of degree `n` with respect to `w`. * `sum_weightedHomogeneousComponent`: every polynomial is the sum of its weighted homogeneous components. -/ noncomputable section open Set Function Finset Finsupp AddMonoidAlgebra variable {R M : Type*} [CommSemiring R] namespace MvPolynomial variable {σ : Type*} section AddCommMonoid variable [AddCommMonoid M] /-! ### `weight` -/ section SemilatticeSup variable [SemilatticeSup M] /-- The weighted total degree of a multivariate polynomial, taking values in `WithBot M`. -/ def weightedTotalDegree' (w : σ → M) (p : MvPolynomial σ R) : WithBot M := p.support.sup fun s => weight w s /-- The `weightedTotalDegree'` of a polynomial `p` is `⊥` if and only if `p = 0`. -/ theorem weightedTotalDegree'_eq_bot_iff (w : σ → M) (p : MvPolynomial σ R) : weightedTotalDegree' w p = ⊥ ↔ p = 0 := by simp only [weightedTotalDegree', Finset.sup_eq_bot_iff, mem_support_iff, WithBot.coe_ne_bot, MvPolynomial.eq_zero_iff] exact forall_congr' fun _ => Classical.not_not /-- The `weightedTotalDegree'` of the zero polynomial is `⊥`. -/ theorem weightedTotalDegree'_zero (w : σ → M) : weightedTotalDegree' w (0 : MvPolynomial σ R) = ⊥ := by simp only [weightedTotalDegree', support_zero, Finset.sup_empty] section OrderBot variable [OrderBot M] /-- When `M` has a `⊥` element, we can define the weighted total degree of a multivariate polynomial as a function taking values in `M`. -/ def weightedTotalDegree (w : σ → M) (p : MvPolynomial σ R) : M := p.support.sup fun s => weight w s /-- This lemma relates `weightedTotalDegree` and `weightedTotalDegree'`. -/ theorem weightedTotalDegree_coe (w : σ → M) (p : MvPolynomial σ R) (hp : p ≠ 0) : weightedTotalDegree' w p = ↑(weightedTotalDegree w p) := by rw [Ne, ← weightedTotalDegree'_eq_bot_iff w p, ← Ne, WithBot.ne_bot_iff_exists] at hp obtain ⟨m, hm⟩ := hp apply le_antisymm · simp only [weightedTotalDegree, weightedTotalDegree', Finset.sup_le_iff, WithBot.coe_le_coe] intro b exact Finset.le_sup · simp only [weightedTotalDegree] have hm' : weightedTotalDegree' w p ≤ m := le_of_eq hm.symm rw [← hm] simpa [weightedTotalDegree'] using hm' /-- The `weightedTotalDegree` of the zero polynomial is `⊥`. -/ theorem weightedTotalDegree_zero (w : σ → M) : weightedTotalDegree w (0 : MvPolynomial σ R) = ⊥ := by simp only [weightedTotalDegree, support_zero, Finset.sup_empty] theorem le_weightedTotalDegree (w : σ → M) {φ : MvPolynomial σ R} {d : σ →₀ ℕ} (hd : d ∈ φ.support) : weight w d ≤ φ.weightedTotalDegree w := le_sup hd end OrderBot end SemilatticeSup /-- A multivariate polynomial `φ` is weighted homogeneous of weighted degree `m` if all monomials occurring in `φ` have weighted degree `m`. -/ def IsWeightedHomogeneous (w : σ → M) (φ : MvPolynomial σ R) (m : M) : Prop := ∀ ⦃d⦄, coeff d φ ≠ 0 → weight w d = m variable (R) /-- The submodule of homogeneous `MvPolynomial`s of degree `n`. -/ def weightedHomogeneousSubmodule (w : σ → M) (m : M) : Submodule R (MvPolynomial σ R) where carrier := { x | x.IsWeightedHomogeneous w m } smul_mem' r a ha c hc := by rw [coeff_smul] at hc exact ha (right_ne_zero_of_mul hc) zero_mem' d hd := False.elim (hd <| coeff_zero _) add_mem' {a} {b} ha hb c hc := by rw [coeff_add] at hc obtain h | h : coeff c a ≠ 0 ∨ coeff c b ≠ 0 := by contrapose! hc simp only [hc, add_zero] · exact ha h · exact hb h @[simp] theorem mem_weightedHomogeneousSubmodule (w : σ → M) (m : M) (p : MvPolynomial σ R) : p ∈ weightedHomogeneousSubmodule R w m ↔ p.IsWeightedHomogeneous w m := Iff.rfl /-- The submodule `weightedHomogeneousSubmodule R w m` of homogeneous `MvPolynomial`s of degree `n` is equal to the `R`-submodule of all `p : (σ →₀ ℕ) →₀ R` such that `p.support ⊆ {d | weight w d = m}`. While equal, the former has a convenient definitional reduction. -/ theorem weightedHomogeneousSubmodule_eq_finsupp_supported (w : σ → M) (m : M) : weightedHomogeneousSubmodule R w m = Finsupp.supported R R { d | weight w d = m } := by ext x rw [mem_supported, Set.subset_def] simp only [Finsupp.mem_support_iff, mem_coe] rfl variable {R} /-- The submodule generated by products `Pm * Pn` of weighted homogeneous polynomials of degrees `m` and `n` is contained in the submodule of weighted homogeneous polynomials of degree `m + n`. -/ theorem weightedHomogeneousSubmodule_mul (w : σ → M) (m n : M) : weightedHomogeneousSubmodule R w m * weightedHomogeneousSubmodule R w n ≤ weightedHomogeneousSubmodule R w (m + n) := by classical rw [Submodule.mul_le] intro φ hφ ψ hψ c hc rw [coeff_mul] at hc obtain ⟨⟨d, e⟩, hde, H⟩ := Finset.exists_ne_zero_of_sum_ne_zero hc have aux : coeff d φ ≠ 0 ∧ coeff e ψ ≠ 0 := by contrapose! H by_cases h : coeff d φ = 0 <;> simp_all only [Ne, not_false_iff, zero_mul, mul_zero] rw [← mem_antidiagonal.mp hde, ← hφ aux.1, ← hψ aux.2, map_add] /-- Monomials are weighted homogeneous. -/ theorem isWeightedHomogeneous_monomial (w : σ → M) (d : σ →₀ ℕ) (r : R) {m : M} (hm : weight w d = m) : IsWeightedHomogeneous w (monomial d r) m := by classical intro c hc rw [coeff_monomial] at hc split_ifs at hc with h · subst c exact hm · contradiction /-- A polynomial of weightedTotalDegree `⊥` is weighted_homogeneous of degree `⊥`. -/ theorem isWeightedHomogeneous_of_total_degree_zero [SemilatticeSup M] [OrderBot M] (w : σ → M) {p : MvPolynomial σ R} (hp : weightedTotalDegree w p = (⊥ : M)) : IsWeightedHomogeneous w p (⊥ : M) := by intro d hd have h := weightedTotalDegree_coe w p (MvPolynomial.ne_zero_iff.mpr ⟨d, hd⟩) simp only [weightedTotalDegree', hp] at h rw [eq_bot_iff, ← WithBot.coe_le_coe, ← h] apply Finset.le_sup (mem_support_iff.mpr hd) /-- Constant polynomials are weighted homogeneous of degree 0. -/ theorem isWeightedHomogeneous_C (w : σ → M) (r : R) : IsWeightedHomogeneous w (C r : MvPolynomial σ R) 0 := isWeightedHomogeneous_monomial _ _ _ (map_zero _) variable (R) /-- 0 is weighted homogeneous of any degree. -/ theorem isWeightedHomogeneous_zero (w : σ → M) (m : M) : IsWeightedHomogeneous w (0 : MvPolynomial σ R) m := (weightedHomogeneousSubmodule R w m).zero_mem /-- 1 is weighted homogeneous of degree 0. -/ theorem isWeightedHomogeneous_one (w : σ → M) : IsWeightedHomogeneous w (1 : MvPolynomial σ R) 0 := isWeightedHomogeneous_C _ _ /-- An indeterminate `i : σ` is weighted homogeneous of degree `w i`. -/ theorem isWeightedHomogeneous_X (w : σ → M) (i : σ) : IsWeightedHomogeneous w (X i : MvPolynomial σ R) (w i) := by apply isWeightedHomogeneous_monomial simp only [weight, LinearMap.toAddMonoidHom_coe, total_single, one_nsmul] namespace IsWeightedHomogeneous variable {R} variable {φ ψ : MvPolynomial σ R} {m n : M} /-- The weighted degree of a weighted homogeneous polynomial controls its support. -/ theorem coeff_eq_zero {w : σ → M} (hφ : IsWeightedHomogeneous w φ n) (d : σ →₀ ℕ) (hd : weight w d ≠ n) : coeff d φ = 0 := by have aux := mt (@hφ d) hd rwa [Classical.not_not] at aux /-- The weighted degree of a nonzero weighted homogeneous polynomial is well-defined. -/ theorem inj_right {w : σ → M} (hφ : φ ≠ 0) (hm : IsWeightedHomogeneous w φ m) (hn : IsWeightedHomogeneous w φ n) : m = n := by obtain ⟨d, hd⟩ : ∃ d, coeff d φ ≠ 0 := exists_coeff_ne_zero hφ rw [← hm hd, ← hn hd] /-- The sum of two weighted homogeneous polynomials of degree `n` is weighted homogeneous of weighted degree `n`. -/ theorem add {w : σ → M} (hφ : IsWeightedHomogeneous w φ n) (hψ : IsWeightedHomogeneous w ψ n) : IsWeightedHomogeneous w (φ + ψ) n := (weightedHomogeneousSubmodule R w n).add_mem hφ hψ /-- The sum of weighted homogeneous polynomials of degree `n` is weighted homogeneous of weighted degree `n`. -/ theorem sum {ι : Type*} (s : Finset ι) (φ : ι → MvPolynomial σ R) (n : M) {w : σ → M} (h : ∀ i ∈ s, IsWeightedHomogeneous w (φ i) n) : IsWeightedHomogeneous w (∑ i ∈ s, φ i) n := (weightedHomogeneousSubmodule R w n).sum_mem h /-- The product of weighted homogeneous polynomials of weighted degrees `m` and `n` is weighted homogeneous of weighted degree `m + n`. -/ theorem mul {w : σ → M} (hφ : IsWeightedHomogeneous w φ m) (hψ : IsWeightedHomogeneous w ψ n) : IsWeightedHomogeneous w (φ * ψ) (m + n) := weightedHomogeneousSubmodule_mul w m n <| Submodule.mul_mem_mul hφ hψ /-- A product of weighted homogeneous polynomials is weighted homogeneous, with weighted degree equal to the sum of the weighted degrees. -/ theorem prod {ι : Type*} (s : Finset ι) (φ : ι → MvPolynomial σ R) (n : ι → M) {w : σ → M} : (∀ i ∈ s, IsWeightedHomogeneous w (φ i) (n i)) → IsWeightedHomogeneous w (∏ i ∈ s, φ i) (∑ i ∈ s, n i) := by classical refine Finset.induction_on s ?_ ?_ · intro simp only [isWeightedHomogeneous_one, Finset.sum_empty, Finset.prod_empty] · intro i s his IH h simp only [his, Finset.prod_insert, Finset.sum_insert, not_false_iff] apply (h i (Finset.mem_insert_self _ _)).mul (IH _) intro j hjs exact h j (Finset.mem_insert_of_mem hjs) /-- A non zero weighted homogeneous polynomial of weighted degree `n` has weighted total degree `n`. -/ theorem weighted_total_degree [SemilatticeSup M] {w : σ → M} (hφ : IsWeightedHomogeneous w φ n) (h : φ ≠ 0) : weightedTotalDegree' w φ = n := by simp only [weightedTotalDegree'] apply le_antisymm · simp only [Finset.sup_le_iff, mem_support_iff, WithBot.coe_le_coe] exact fun d hd => le_of_eq (hφ hd) · obtain ⟨d, hd⟩ : ∃ d, coeff d φ ≠ 0 := exists_coeff_ne_zero h simp only [← hφ hd, Finsupp.sum] replace hd := Finsupp.mem_support_iff.mpr hd apply Finset.le_sup hd end IsWeightedHomogeneous variable {R} /-- The weighted homogeneous submodules form a graded monoid. -/ lemma WeightedHomogeneousSubmodule.gradedMonoid {w : σ → M} : SetLike.GradedMonoid (weightedHomogeneousSubmodule R w) where one_mem := isWeightedHomogeneous_one R w mul_mem _ _ _ _ := IsWeightedHomogeneous.mul /-- `weightedHomogeneousComponent w n φ` is the part of `φ` that is weighted homogeneous of weighted degree `n`, with respect to the weights `w`. See `sum_weightedHomogeneousComponent` for the statement that `φ` is equal to the sum of all its weighted homogeneous components. -/ def weightedHomogeneousComponent (w : σ → M) (n : M) : MvPolynomial σ R →ₗ[R] MvPolynomial σ R := letI := Classical.decEq M (Submodule.subtype _).comp <| Finsupp.restrictDom _ _ { d | weight w d = n } section WeightedHomogeneousComponent variable {w : σ → M} (n : M) (φ ψ : MvPolynomial σ R) theorem coeff_weightedHomogeneousComponent [DecidableEq M] (d : σ →₀ ℕ) : coeff d (weightedHomogeneousComponent w n φ) = if weight w d = n then coeff d φ else 0 := letI := Classical.decEq M Finsupp.filter_apply (fun d : σ →₀ ℕ => weight w d = n) φ d |>.trans <| by convert rfl theorem weightedHomogeneousComponent_apply [DecidableEq M] : weightedHomogeneousComponent w n φ = ∑ d ∈ φ.support.filter fun d => weight w d = n, monomial d (coeff d φ) := letI := Classical.decEq M Finsupp.filter_eq_sum (fun d : σ →₀ ℕ => weight w d = n) φ |>.trans <| by convert rfl /-- The `n` weighted homogeneous component of a polynomial is weighted homogeneous of weighted degree `n`. -/ theorem weightedHomogeneousComponent_isWeightedHomogeneous : (weightedHomogeneousComponent w n φ).IsWeightedHomogeneous w n := by classical intro d hd contrapose! hd rw [coeff_weightedHomogeneousComponent, if_neg hd] theorem weightedHomogeneousComponent_mem (w : σ → M) (φ : MvPolynomial σ R) (m : M) : weightedHomogeneousComponent w m φ ∈ weightedHomogeneousSubmodule R w m := by rw [mem_weightedHomogeneousSubmodule] exact weightedHomogeneousComponent_isWeightedHomogeneous m φ @[simp] theorem weightedHomogeneousComponent_C_mul (n : M) (r : R) : weightedHomogeneousComponent w n (C r * φ) = C r * weightedHomogeneousComponent w n φ := by simp only [C_mul', LinearMap.map_smul] theorem weightedHomogeneousComponent_eq_zero' (h : ∀ d : σ →₀ ℕ, d ∈ φ.support → weight w d ≠ n) : weightedHomogeneousComponent w n φ = 0 := by classical rw [weightedHomogeneousComponent_apply, sum_eq_zero] intro d hd; rw [mem_filter] at hd exfalso; exact h _ hd.1 hd.2 theorem weightedHomogeneousComponent_eq_zero [SemilatticeSup M] [OrderBot M] (h : weightedTotalDegree w φ < n) : weightedHomogeneousComponent w n φ = 0 := by classical rw [weightedHomogeneousComponent_apply, sum_eq_zero] intro d hd rw [Finset.mem_filter] at hd exfalso apply lt_irrefl n nth_rw 1 [← hd.2] exact lt_of_le_of_lt (le_weightedTotalDegree w hd.1) h theorem weightedHomogeneousComponent_finsupp : (Function.support fun m => weightedHomogeneousComponent w m φ).Finite := by suffices (Function.support fun m => weightedHomogeneousComponent w m φ) ⊆ (fun d => weight w d) '' φ.support by exact Finite.subset ((fun d : σ →₀ ℕ => (weight w) d) '' ↑(support φ)).toFinite this intro m hm by_contra hm' apply hm simp only [mem_support, Ne] at hm simp only [Set.mem_image, not_exists, not_and] at hm' exact weightedHomogeneousComponent_eq_zero' m φ hm' variable (w) /-- Every polynomial is the sum of its weighted homogeneous components. -/ theorem sum_weightedHomogeneousComponent : (finsum fun m => weightedHomogeneousComponent w m φ) = φ := by classical rw [finsum_eq_sum _ (weightedHomogeneousComponent_finsupp φ)] ext1 d simp only [coeff_sum, coeff_weightedHomogeneousComponent] rw [Finset.sum_eq_single (weight w d)] · rw [if_pos rfl] · intro m _ hm' rw [if_neg hm'.symm] · intro hm rw [if_pos rfl] simp only [Finite.mem_toFinset, mem_support, Ne, Classical.not_not] at hm have := coeff_weightedHomogeneousComponent (w := w) (weight w d) φ d rw [hm, if_pos rfl, coeff_zero] at this exact this.symm theorem finsum_weightedHomogeneousComponent : (finsum fun m => weightedHomogeneousComponent w m φ) = φ := by rw [sum_weightedHomogeneousComponent] variable {w} theorem IsWeightedHomogeneous.weightedHomogeneousComponent_same {m : M} {p : MvPolynomial σ R} (hp : IsWeightedHomogeneous w p m) : weightedHomogeneousComponent w m p = p := by classical ext x rw [coeff_weightedHomogeneousComponent] by_cases zero_coeff : coeff x p = 0 · split_ifs · rfl rw [zero_coeff] · rw [hp zero_coeff, if_pos rfl] theorem IsWeightedHomogeneous.weightedHomogeneousComponent_ne {m : M} (n : M) {p : MvPolynomial σ R} (hp : IsWeightedHomogeneous w p m) : n ≠ m → weightedHomogeneousComponent w n p = 0 := by classical intro hn ext x rw [coeff_weightedHomogeneousComponent] by_cases zero_coeff : coeff x p = 0 · simp [zero_coeff] · rw [if_neg] · rw [coeff_zero] · rw [hp zero_coeff]; exact Ne.symm hn /-- The weighted homogeneous components of a weighted homogeneous polynomial. -/ theorem weightedHomogeneousComponent_of_mem [DecidableEq M] {m n : M} {p : MvPolynomial σ R} (h : p ∈ weightedHomogeneousSubmodule R w n) : weightedHomogeneousComponent w m p = if m = n then p else 0 := by simp only [mem_weightedHomogeneousSubmodule] at h ext x rw [coeff_weightedHomogeneousComponent] by_cases zero_coeff : coeff x p = 0 · split_ifs <;> simp only [zero_coeff, coeff_zero] · rw [h zero_coeff] simp only [show n = m ↔ m = n from eq_comm] split_ifs with h1 · rfl · simp only [coeff_zero] theorem weightedHomogeneousComponent_of_isWeightedHomogeneous_same {m : M} {p : MvPolynomial σ R} (hp : IsWeightedHomogeneous w p m) : weightedHomogeneousComponent w m p = p := by classical ext x rw [coeff_weightedHomogeneousComponent] by_cases zero_coeff : coeff x p = 0 · simp [zero_coeff] · rw [hp zero_coeff, if_pos rfl] theorem weightedHomogeneousComponent_of_isWeightedHomogeneous_ne {m n : M} {p : MvPolynomial σ R} (hp : IsWeightedHomogeneous w p m) (hn : n ≠ m) : weightedHomogeneousComponent w n p = 0 := by classical ext x rw [coeff_weightedHomogeneousComponent] by_cases zero_coeff : coeff x p = 0 · simp [zero_coeff] · rw [if_neg (by simp only [hp zero_coeff, hn.symm, not_false_eq_true]), coeff_zero] variable (R w) open DirectSum theorem DirectSum.coeLinearMap_eq_dfinsupp_sum [DecidableEq σ] [DecidableEq R] [DecidableEq M] (x : DirectSum M fun i : M => ↥(weightedHomogeneousSubmodule R w i)) : (coeLinearMap fun i : M => weightedHomogeneousSubmodule R w i) x = DFinsupp.sum x (fun _ x => ↑x) := by rw [_root_.DirectSum.coeLinearMap_eq_dfinsupp_sum] theorem DirectSum.coeAddMonoidHom_eq_support_sum [DecidableEq σ] [DecidableEq R] [DecidableEq M] (x : DirectSum M fun i : M => ↥(weightedHomogeneousSubmodule R w i)) : (DirectSum.coeAddMonoidHom fun i : M => weightedHomogeneousSubmodule R w i) x = DFinsupp.sum x (fun _ x => ↑x) := DirectSum.coeLinearMap_eq_dfinsupp_sum R w x theorem DirectSum.coeLinearMap_eq_finsum [DecidableEq M] (x : DirectSum M fun i : M => ↥(weightedHomogeneousSubmodule R w i)) : (DirectSum.coeLinearMap fun i : M => weightedHomogeneousSubmodule R w i) x = finsum fun m => x m := by classical rw [DirectSum.coeLinearMap_eq_dfinsupp_sum, DFinsupp.sum, finsum_eq_sum_of_support_subset] apply DirectSum.support_subset theorem weightedHomogeneousComponent_directSum [DecidableEq M] (x : DirectSum M fun i : M => ↥(weightedHomogeneousSubmodule R w i)) (m : M) : (weightedHomogeneousComponent w m) ((DirectSum.coeLinearMap fun i : M => weightedHomogeneousSubmodule R w i) x) = x m := by classical rw [DirectSum.coeLinearMap_eq_dfinsupp_sum, DFinsupp.sum, map_sum] convert @Finset.sum_eq_single M (MvPolynomial σ R) _ (DFinsupp.support x) _ m _ _ · rw [weightedHomogeneousComponent_of_isWeightedHomogeneous_same (x m).prop] · intro n _ hmn rw [weightedHomogeneousComponent_of_isWeightedHomogeneous_ne (x n).prop hmn.symm] · rw [DFinsupp.not_mem_support_iff] intro hm; rw [hm, Submodule.coe_zero, map_zero] end WeightedHomogeneousComponent end AddCommMonoid section CanonicallyOrderedAddCommMonoid variable [CanonicallyOrderedAddCommMonoid M] {w : σ → M} (φ : MvPolynomial σ R) /-- If `M` is a `CanonicallyOrderedAddCommMonoid`, then the `weightedHomogeneousComponent` of weighted degree `0` of a polynomial is its constant coefficient. -/ @[simp] theorem weightedHomogeneousComponent_zero [NoZeroSMulDivisors ℕ M] (hw : ∀ i : σ, w i ≠ 0) : weightedHomogeneousComponent w 0 φ = C (coeff 0 φ) := by classical ext1 d rcases Classical.em (d = 0) with (rfl | hd) · simp only [coeff_weightedHomogeneousComponent, if_pos, map_zero, coeff_zero_C] · rw [coeff_weightedHomogeneousComponent, if_neg, coeff_C, if_neg (Ne.symm hd)] simp only [weight, LinearMap.toAddMonoidHom_coe, Finsupp.total_apply, Finsupp.sum, sum_eq_zero_iff, Finsupp.mem_support_iff, Ne, smul_eq_zero, not_forall, not_or, and_self_left, exists_prop] simp only [DFunLike.ext_iff, Finsupp.coe_zero, Pi.zero_apply, not_forall] at hd obtain ⟨i, hi⟩ := hd exact ⟨i, hi, hw i⟩ /-- A weight function is nontorsion if its values are not torsion. -/ def NonTorsionWeight (w : σ → M) := ∀ n x, n • w x = (0 : M) → n = 0 theorem nonTorsionWeight_of [NoZeroSMulDivisors ℕ M] (hw : ∀ i : σ, w i ≠ 0) : NonTorsionWeight w := fun _ x hnx => (smul_eq_zero_iff_left (hw x)).mp hnx end CanonicallyOrderedAddCommMonoid section CanonicallyLinearOrderedMonoid variable [CanonicallyLinearOrderedAddCommMonoid M] {w : σ → M} (φ : MvPolynomial σ R) /-- If `w` is a nontorsion weight function, then the finitely supported function `m : σ →₀ ℕ` has weighted degree zero if and only if `∀ x : σ, m x = 0`. -/ theorem weightedDegree_eq_zero_iff (hw : NonTorsionWeight w) {m : σ →₀ ℕ} : weight w m = 0 ↔ ∀ x : σ, m x = 0 := by simp only [weight, Finsupp.total, LinearMap.toAddMonoidHom_coe, coe_lsum, LinearMap.coe_smulRight, LinearMap.id_coe, id_eq] rw [Finsupp.sum, Finset.sum_eq_zero_iff] apply forall_congr' intro x rw [Finsupp.mem_support_iff] constructor · intro hx by_contra hx' exact absurd (hw _ _ (hx hx')) hx' · intro hax _ simp only [hax, zero_smul] /-- A multivatiate polynomial is weighted homogeneous of weighted degree zero if and only if its weighted total degree is equal to zero. -/ theorem isWeightedHomogeneous_zero_iff_weightedTotalDegree_eq_zero {p : MvPolynomial σ R} : IsWeightedHomogeneous w p 0 ↔ p.weightedTotalDegree w = 0 := by rw [weightedTotalDegree, ← bot_eq_zero, Finset.sup_eq_bot_iff, bot_eq_zero, IsWeightedHomogeneous] apply forall_congr' intro m rw [mem_support_iff] /-- If `w` is a nontorsion weight function, then a multivariate polynomial has weighted total degree zero if and only if for every `m ∈ p.support` and `x : σ`, `m x = 0`. -/ theorem weightedTotalDegree_eq_zero_iff (hw : NonTorsionWeight w) (p : MvPolynomial σ R) : p.weightedTotalDegree w = 0 ↔ ∀ (m : σ →₀ ℕ) (_ : m ∈ p.support) (x : σ), m x = 0 := by rw [← isWeightedHomogeneous_zero_iff_weightedTotalDegree_eq_zero, IsWeightedHomogeneous] apply forall_congr' intro m rw [mem_support_iff] apply forall_congr' intro _ exact weightedDegree_eq_zero_iff hw end CanonicallyLinearOrderedMonoid section GradedAlgebra /- Here, given a weight `w : σ → M`, where `M` is an additive and commutative monoid, we endow the ring of multivariate polynomials `MvPolynomial σ R` with the structure of a graded algebra -/ variable (w : σ → M) [AddCommMonoid M] theorem weightedHomogeneousComponent_eq_zero_of_not_mem [DecidableEq M] (φ : MvPolynomial σ R) (i : M) (hi : i ∉ Finset.image (weight w) φ.support) : weightedHomogeneousComponent w i φ = 0 := by apply weightedHomogeneousComponent_eq_zero' simp only [Finset.mem_image, mem_support_iff, ne_eq, exists_prop, not_exists, not_and] at hi exact fun m hm ↦ hi m (mem_support_iff.mp hm) variable (R) /-- The `decompose'` argument of `weightedDecomposition`. -/ def decompose' [DecidableEq M] := fun φ : MvPolynomial σ R => DirectSum.mk (fun i : M => ↥(weightedHomogeneousSubmodule R w i)) (Finset.image (weight w) φ.support) fun m => ⟨weightedHomogeneousComponent w m φ, weightedHomogeneousComponent_mem w φ m⟩ theorem decompose'_apply [DecidableEq M] (φ : MvPolynomial σ R) (m : M) : (decompose' R w φ m : MvPolynomial σ R) = weightedHomogeneousComponent w m φ := by rw [decompose'] by_cases hm : m ∈ Finset.image (weight w) φ.support · simp only [DirectSum.mk_apply_of_mem hm, Subtype.coe_mk] · rw [DirectSum.mk_apply_of_not_mem hm, Submodule.coe_zero, weightedHomogeneousComponent_eq_zero_of_not_mem w φ m hm] /-- Given a weight `w`, the decomposition of `MvPolynomial σ R` into weighted homogeneous submodules -/ def weightedDecomposition [DecidableEq M] : DirectSum.Decomposition (weightedHomogeneousSubmodule R w) where decompose' := decompose' R w left_inv φ := by classical conv_rhs => rw [← sum_weightedHomogeneousComponent w φ] rw [← DirectSum.sum_support_of (decompose' R w φ)] simp only [DirectSum.coeAddMonoidHom_of, MvPolynomial.coeff_sum, map_sum, finsum_eq_sum _ (weightedHomogeneousComponent_finsupp φ)] apply Finset.sum_congr _ (fun m _ ↦ by rw [decompose'_apply]) ext m simp only [DFinsupp.mem_support_toFun, ne_eq, Set.Finite.mem_toFinset, Function.mem_support, not_iff_not] conv_lhs => rw [← Subtype.coe_inj] rw [decompose'_apply, Submodule.coe_zero] right_inv x := by classical apply DFinsupp.ext intro m rw [← Subtype.coe_inj, decompose'_apply] exact weightedHomogeneousComponent_directSum R w x m /-- Given a weight, `MvPolynomial` as a graded algebra -/ def weightedGradedAlgebra [DecidableEq M] : GradedAlgebra (weightedHomogeneousSubmodule R w) where toDecomposition := weightedDecomposition R w toGradedMonoid := WeightedHomogeneousSubmodule.gradedMonoid theorem weightedDecomposition.decompose'_eq [DecidableEq M] : (weightedDecomposition R w).decompose' = fun φ : MvPolynomial σ R => DirectSum.mk (fun i : M => ↥(weightedHomogeneousSubmodule R w i)) (Finset.image (weight w) φ.support) fun m => ⟨weightedHomogeneousComponent w m φ, weightedHomogeneousComponent_mem w φ m⟩ := rfl theorem weightedDecomposition.decompose'_apply [DecidableEq M] (φ : MvPolynomial σ R) (m : M) : ((weightedDecomposition R w).decompose' φ m : MvPolynomial σ R) = weightedHomogeneousComponent w m φ := MvPolynomial.decompose'_apply R w φ m end GradedAlgebra end MvPolynomial
RingTheory\MvPowerSeries\Basic.lean
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Kenny Lau -/ import Mathlib.Algebra.MvPolynomial.Basic import Mathlib.Algebra.Order.Antidiag.Finsupp import Mathlib.Data.Finsupp.Antidiagonal import Mathlib.Data.Finsupp.Weight import Mathlib.LinearAlgebra.StdBasis import Mathlib.Tactic.Linarith /-! # Formal (multivariate) power series This file defines multivariate formal power series and develops the basic properties of these objects. A formal power series is to a polynomial like an infinite sum is to a finite sum. We provide the natural inclusion from multivariate polynomials to multivariate formal power series. ## Main definitions - `MvPowerSeries.C`: constant power series - `MvPowerSeries.X`: the indeterminates - `MvPowerSeries.coeff`, `MvPowerSeries.constantCoeff`: the coefficients of a `MvPowerSeries`, its constant coefficient - `MvPowerSeries.monomial`: the monomials - `MvPowerSeries.coeff_mul`: computes the coefficients of the product of two `MvPowerSeries` - `MvPowerSeries.coeff_prod` : computes the coefficients of products of `MvPowerSeries` - `MvPowerSeries.coeff_pow` : computes the coefficients of powers of a `MvPowerSeries` - `MvPowerSeries.coeff_eq_zero_of_constantCoeff_nilpotent`: if the constant coefficient of a `MvPowerSeries` is nilpotent, then some coefficients of its powers are automatically zero - `MvPowerSeries.map`: apply a `RingHom` to the coefficients of a `MvPowerSeries` (as a `RingHom) - `MvPowerSeries.X_pow_dvd_iff`, `MvPowerSeries.X_dvd_iff`: equivalent conditions for (a power of) an indeterminate to divide a `MvPowerSeries` - `MvPolynomial.toMvPowerSeries`: the canonical coercion from `MvPolynomial` to `MvPowerSeries` ## Note This file sets up the (semi)ring structure on multivariate power series: additional results are in: * `Mathlib.RingTheory.MvPowerSeries.Inverse` : invertibility, formal power series over a local ring form a local ring; * `Mathlib.RingTheory.MvPowerSeries.Trunc`: truncation of power series. In `Mathlib.RingTheory.PowerSeries.Basic`, formal power series in one variable will be obtained as a particular case, defined by `PowerSeries R := MvPowerSeries Unit R`. See that file for a specific description. ## Implementation notes In this file we define multivariate formal power series with variables indexed by `σ` and coefficients in `R` as `MvPowerSeries σ R := (σ →₀ ℕ) → R`. Unfortunately there is not yet enough API to show that they are the completion of the ring of multivariate polynomials. However, we provide most of the infrastructure that is needed to do this. Once I-adic completion (topological or algebraic) is available it should not be hard to fill in the details. -/ noncomputable section open Finset (antidiagonal mem_antidiagonal) /-- Multivariate formal power series, where `σ` is the index set of the variables and `R` is the coefficient ring. -/ def MvPowerSeries (σ : Type*) (R : Type*) := (σ →₀ ℕ) → R namespace MvPowerSeries open Finsupp variable {σ R : Type*} instance [Inhabited R] : Inhabited (MvPowerSeries σ R) := ⟨fun _ => default⟩ instance [Zero R] : Zero (MvPowerSeries σ R) := Pi.instZero instance [AddMonoid R] : AddMonoid (MvPowerSeries σ R) := Pi.addMonoid instance [AddGroup R] : AddGroup (MvPowerSeries σ R) := Pi.addGroup instance [AddCommMonoid R] : AddCommMonoid (MvPowerSeries σ R) := Pi.addCommMonoid instance [AddCommGroup R] : AddCommGroup (MvPowerSeries σ R) := Pi.addCommGroup instance [Nontrivial R] : Nontrivial (MvPowerSeries σ R) := Function.nontrivial instance {A} [Semiring R] [AddCommMonoid A] [Module R A] : Module R (MvPowerSeries σ A) := Pi.module _ _ _ instance {A S} [Semiring R] [Semiring S] [AddCommMonoid A] [Module R A] [Module S A] [SMul R S] [IsScalarTower R S A] : IsScalarTower R S (MvPowerSeries σ A) := Pi.isScalarTower section Semiring variable (R) [Semiring R] /-- The `n`th monomial as multivariate formal power series: it is defined as the `R`-linear map from `R` to the semi-ring of multivariate formal power series associating to each `a` the map sending `n : σ →₀ ℕ` to the value `a` and sending all other `x : σ →₀ ℕ` different from `n` to `0`. -/ def monomial (n : σ →₀ ℕ) : R →ₗ[R] MvPowerSeries σ R := letI := Classical.decEq σ LinearMap.stdBasis R (fun _ ↦ R) n /-- The `n`th coefficient of a multivariate formal power series. -/ def coeff (n : σ →₀ ℕ) : MvPowerSeries σ R →ₗ[R] R := LinearMap.proj n variable {R} /-- Two multivariate formal power series are equal if all their coefficients are equal. -/ @[ext] theorem ext {φ ψ} (h : ∀ n : σ →₀ ℕ, coeff R n φ = coeff R n ψ) : φ = ψ := funext h /-- Two multivariate formal power series are equal if and only if all their coefficients are equal. -/ add_decl_doc MvPowerSeries.ext_iff theorem monomial_def [DecidableEq σ] (n : σ →₀ ℕ) : (monomial R n) = LinearMap.stdBasis R (fun _ ↦ R) n := by rw [monomial] -- unify the `Decidable` arguments convert rfl theorem coeff_monomial [DecidableEq σ] (m n : σ →₀ ℕ) (a : R) : coeff R m (monomial R n a) = if m = n then a else 0 := by -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [coeff, monomial_def, LinearMap.proj_apply (i := m)] -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [LinearMap.stdBasis_apply, Function.update_apply, Pi.zero_apply] @[simp] theorem coeff_monomial_same (n : σ →₀ ℕ) (a : R) : coeff R n (monomial R n a) = a := by classical rw [monomial_def] exact LinearMap.stdBasis_same R (fun _ ↦ R) n a theorem coeff_monomial_ne {m n : σ →₀ ℕ} (h : m ≠ n) (a : R) : coeff R m (monomial R n a) = 0 := by classical rw [monomial_def] exact LinearMap.stdBasis_ne R (fun _ ↦ R) _ _ h a theorem eq_of_coeff_monomial_ne_zero {m n : σ →₀ ℕ} {a : R} (h : coeff R m (monomial R n a) ≠ 0) : m = n := by_contra fun h' => h <| coeff_monomial_ne h' a @[simp] theorem coeff_comp_monomial (n : σ →₀ ℕ) : (coeff R n).comp (monomial R n) = LinearMap.id := LinearMap.ext <| coeff_monomial_same n -- Porting note (#10618): simp can prove this. -- @[simp] theorem coeff_zero (n : σ →₀ ℕ) : coeff R n (0 : MvPowerSeries σ R) = 0 := rfl variable (m n : σ →₀ ℕ) (φ ψ : MvPowerSeries σ R) instance : One (MvPowerSeries σ R) := ⟨monomial R (0 : σ →₀ ℕ) 1⟩ theorem coeff_one [DecidableEq σ] : coeff R n (1 : MvPowerSeries σ R) = if n = 0 then 1 else 0 := coeff_monomial _ _ _ theorem coeff_zero_one : coeff R (0 : σ →₀ ℕ) 1 = 1 := coeff_monomial_same 0 1 theorem monomial_zero_one : monomial R (0 : σ →₀ ℕ) 1 = 1 := rfl instance : AddMonoidWithOne (MvPowerSeries σ R) := { show AddMonoid (MvPowerSeries σ R) by infer_instance with natCast := fun n => monomial R 0 n natCast_zero := by simp [Nat.cast] natCast_succ := by simp [Nat.cast, monomial_zero_one] one := 1 } instance : Mul (MvPowerSeries σ R) := letI := Classical.decEq σ ⟨fun φ ψ n => ∑ p ∈ antidiagonal n, coeff R p.1 φ * coeff R p.2 ψ⟩ theorem coeff_mul [DecidableEq σ] : coeff R n (φ * ψ) = ∑ p ∈ antidiagonal n, coeff R p.1 φ * coeff R p.2 ψ := by refine Finset.sum_congr ?_ fun _ _ => rfl rw [Subsingleton.elim (Classical.decEq σ) ‹DecidableEq σ›] protected theorem zero_mul : (0 : MvPowerSeries σ R) * φ = 0 := ext fun n => by classical simp [coeff_mul] protected theorem mul_zero : φ * 0 = 0 := ext fun n => by classical simp [coeff_mul] theorem coeff_monomial_mul (a : R) : coeff R m (monomial R n a * φ) = if n ≤ m then a * coeff R (m - n) φ else 0 := by classical have : ∀ p ∈ antidiagonal m, coeff R (p : (σ →₀ ℕ) × (σ →₀ ℕ)).1 (monomial R n a) * coeff R p.2 φ ≠ 0 → p.1 = n := fun p _ hp => eq_of_coeff_monomial_ne_zero (left_ne_zero_of_mul hp) rw [coeff_mul, ← Finset.sum_filter_of_ne this, Finset.filter_fst_eq_antidiagonal _ n, Finset.sum_ite_index] simp only [Finset.sum_singleton, coeff_monomial_same, Finset.sum_empty] theorem coeff_mul_monomial (a : R) : coeff R m (φ * monomial R n a) = if n ≤ m then coeff R (m - n) φ * a else 0 := by classical have : ∀ p ∈ antidiagonal m, coeff R (p : (σ →₀ ℕ) × (σ →₀ ℕ)).1 φ * coeff R p.2 (monomial R n a) ≠ 0 → p.2 = n := fun p _ hp => eq_of_coeff_monomial_ne_zero (right_ne_zero_of_mul hp) rw [coeff_mul, ← Finset.sum_filter_of_ne this, Finset.filter_snd_eq_antidiagonal _ n, Finset.sum_ite_index] simp only [Finset.sum_singleton, coeff_monomial_same, Finset.sum_empty] theorem coeff_add_monomial_mul (a : R) : coeff R (m + n) (monomial R m a * φ) = a * coeff R n φ := by rw [coeff_monomial_mul, if_pos, add_tsub_cancel_left] exact le_add_right le_rfl theorem coeff_add_mul_monomial (a : R) : coeff R (m + n) (φ * monomial R n a) = coeff R m φ * a := by rw [coeff_mul_monomial, if_pos, add_tsub_cancel_right] exact le_add_left le_rfl @[simp] theorem commute_monomial {a : R} {n} : Commute φ (monomial R n a) ↔ ∀ m, Commute (coeff R m φ) a := by rw [commute_iff_eq, MvPowerSeries.ext_iff] refine ⟨fun h m => ?_, fun h m => ?_⟩ · have := h (m + n) rwa [coeff_add_mul_monomial, add_comm, coeff_add_monomial_mul] at this · rw [coeff_mul_monomial, coeff_monomial_mul] split_ifs <;> [apply h; rfl] protected theorem one_mul : (1 : MvPowerSeries σ R) * φ = φ := ext fun n => by simpa using coeff_add_monomial_mul 0 n φ 1 protected theorem mul_one : φ * 1 = φ := ext fun n => by simpa using coeff_add_mul_monomial n 0 φ 1 protected theorem mul_add (φ₁ φ₂ φ₃ : MvPowerSeries σ R) : φ₁ * (φ₂ + φ₃) = φ₁ * φ₂ + φ₁ * φ₃ := ext fun n => by classical simp only [coeff_mul, mul_add, Finset.sum_add_distrib, LinearMap.map_add] protected theorem add_mul (φ₁ φ₂ φ₃ : MvPowerSeries σ R) : (φ₁ + φ₂) * φ₃ = φ₁ * φ₃ + φ₂ * φ₃ := ext fun n => by classical simp only [coeff_mul, add_mul, Finset.sum_add_distrib, LinearMap.map_add] protected theorem mul_assoc (φ₁ φ₂ φ₃ : MvPowerSeries σ R) : φ₁ * φ₂ * φ₃ = φ₁ * (φ₂ * φ₃) := by ext1 n classical simp only [coeff_mul, Finset.sum_mul, Finset.mul_sum, Finset.sum_sigma'] apply Finset.sum_nbij' (fun ⟨⟨_i, j⟩, ⟨k, l⟩⟩ ↦ ⟨(k, l + j), (l, j)⟩) (fun ⟨⟨i, _j⟩, ⟨k, l⟩⟩ ↦ ⟨(i + k, l), (i, k)⟩) <;> aesop (add simp [add_assoc, mul_assoc]) instance : Semiring (MvPowerSeries σ R) := { inferInstanceAs (AddMonoidWithOne (MvPowerSeries σ R)), inferInstanceAs (Mul (MvPowerSeries σ R)), inferInstanceAs (AddCommMonoid (MvPowerSeries σ R)) with mul_one := MvPowerSeries.mul_one one_mul := MvPowerSeries.one_mul mul_assoc := MvPowerSeries.mul_assoc mul_zero := MvPowerSeries.mul_zero zero_mul := MvPowerSeries.zero_mul left_distrib := MvPowerSeries.mul_add right_distrib := MvPowerSeries.add_mul } end Semiring instance [CommSemiring R] : CommSemiring (MvPowerSeries σ R) := { show Semiring (MvPowerSeries σ R) by infer_instance with mul_comm := fun φ ψ => ext fun n => by classical simpa only [coeff_mul, mul_comm] using sum_antidiagonal_swap n fun a b => coeff R a φ * coeff R b ψ } instance [Ring R] : Ring (MvPowerSeries σ R) := { inferInstanceAs (Semiring (MvPowerSeries σ R)), inferInstanceAs (AddCommGroup (MvPowerSeries σ R)) with } instance [CommRing R] : CommRing (MvPowerSeries σ R) := { inferInstanceAs (CommSemiring (MvPowerSeries σ R)), inferInstanceAs (AddCommGroup (MvPowerSeries σ R)) with } section Semiring variable [Semiring R] theorem monomial_mul_monomial (m n : σ →₀ ℕ) (a b : R) : monomial R m a * monomial R n b = monomial R (m + n) (a * b) := by classical ext k simp only [coeff_mul_monomial, coeff_monomial] split_ifs with h₁ h₂ h₃ h₃ h₂ <;> try rfl · rw [← h₂, tsub_add_cancel_of_le h₁] at h₃ exact (h₃ rfl).elim · rw [h₃, add_tsub_cancel_right] at h₂ exact (h₂ rfl).elim · exact zero_mul b · rw [h₂] at h₁ exact (h₁ <| le_add_left le_rfl).elim variable (σ) (R) /-- The constant multivariate formal power series. -/ def C : R →+* MvPowerSeries σ R := { monomial R (0 : σ →₀ ℕ) with map_one' := rfl map_mul' := fun a b => (monomial_mul_monomial 0 0 a b).symm map_zero' := (monomial R (0 : _)).map_zero } variable {σ} {R} @[simp] theorem monomial_zero_eq_C : ⇑(monomial R (0 : σ →₀ ℕ)) = C σ R := rfl theorem monomial_zero_eq_C_apply (a : R) : monomial R (0 : σ →₀ ℕ) a = C σ R a := rfl theorem coeff_C [DecidableEq σ] (n : σ →₀ ℕ) (a : R) : coeff R n (C σ R a) = if n = 0 then a else 0 := coeff_monomial _ _ _ theorem coeff_zero_C (a : R) : coeff R (0 : σ →₀ ℕ) (C σ R a) = a := coeff_monomial_same 0 a /-- The variables of the multivariate formal power series ring. -/ def X (s : σ) : MvPowerSeries σ R := monomial R (single s 1) 1 theorem coeff_X [DecidableEq σ] (n : σ →₀ ℕ) (s : σ) : coeff R n (X s : MvPowerSeries σ R) = if n = single s 1 then 1 else 0 := coeff_monomial _ _ _ theorem coeff_index_single_X [DecidableEq σ] (s t : σ) : coeff R (single t 1) (X s : MvPowerSeries σ R) = if t = s then 1 else 0 := by simp only [coeff_X, single_left_inj (one_ne_zero : (1 : ℕ) ≠ 0)] @[simp] theorem coeff_index_single_self_X (s : σ) : coeff R (single s 1) (X s : MvPowerSeries σ R) = 1 := coeff_monomial_same _ _ theorem coeff_zero_X (s : σ) : coeff R (0 : σ →₀ ℕ) (X s : MvPowerSeries σ R) = 0 := by classical rw [coeff_X, if_neg] intro h exact one_ne_zero (single_eq_zero.mp h.symm) theorem commute_X (φ : MvPowerSeries σ R) (s : σ) : Commute φ (X s) := φ.commute_monomial.mpr fun _m => Commute.one_right _ theorem X_def (s : σ) : X s = monomial R (single s 1) 1 := rfl theorem X_pow_eq (s : σ) (n : ℕ) : (X s : MvPowerSeries σ R) ^ n = monomial R (single s n) 1 := by induction' n with n ih · simp · rw [pow_succ, ih, Finsupp.single_add, X, monomial_mul_monomial, one_mul] theorem coeff_X_pow [DecidableEq σ] (m : σ →₀ ℕ) (s : σ) (n : ℕ) : coeff R m ((X s : MvPowerSeries σ R) ^ n) = if m = single s n then 1 else 0 := by rw [X_pow_eq s n, coeff_monomial] @[simp] theorem coeff_mul_C (n : σ →₀ ℕ) (φ : MvPowerSeries σ R) (a : R) : coeff R n (φ * C σ R a) = coeff R n φ * a := by simpa using coeff_add_mul_monomial n 0 φ a @[simp] theorem coeff_C_mul (n : σ →₀ ℕ) (φ : MvPowerSeries σ R) (a : R) : coeff R n (C σ R a * φ) = a * coeff R n φ := by simpa using coeff_add_monomial_mul 0 n φ a theorem coeff_zero_mul_X (φ : MvPowerSeries σ R) (s : σ) : coeff R (0 : σ →₀ ℕ) (φ * X s) = 0 := by have : ¬single s 1 ≤ 0 := fun h => by simpa using h s simp only [X, coeff_mul_monomial, if_neg this] theorem coeff_zero_X_mul (φ : MvPowerSeries σ R) (s : σ) : coeff R (0 : σ →₀ ℕ) (X s * φ) = 0 := by rw [← (φ.commute_X s).eq, coeff_zero_mul_X] variable (σ) (R) /-- The constant coefficient of a formal power series. -/ def constantCoeff : MvPowerSeries σ R →+* R := { coeff R (0 : σ →₀ ℕ) with toFun := coeff R (0 : σ →₀ ℕ) map_one' := coeff_zero_one map_mul' := fun φ ψ => by classical simp [coeff_mul, support_single_ne_zero] map_zero' := LinearMap.map_zero _ } variable {σ} {R} @[simp] theorem coeff_zero_eq_constantCoeff : ⇑(coeff R (0 : σ →₀ ℕ)) = constantCoeff σ R := rfl theorem coeff_zero_eq_constantCoeff_apply (φ : MvPowerSeries σ R) : coeff R (0 : σ →₀ ℕ) φ = constantCoeff σ R φ := rfl @[simp] theorem constantCoeff_C (a : R) : constantCoeff σ R (C σ R a) = a := rfl @[simp] theorem constantCoeff_comp_C : (constantCoeff σ R).comp (C σ R) = RingHom.id R := rfl -- Porting note (#10618): simp can prove this. -- @[simp] theorem constantCoeff_zero : constantCoeff σ R 0 = 0 := rfl -- Porting note (#10618): simp can prove this. -- @[simp] theorem constantCoeff_one : constantCoeff σ R 1 = 1 := rfl @[simp] theorem constantCoeff_X (s : σ) : constantCoeff σ R (X s) = 0 := coeff_zero_X s /-- If a multivariate formal power series is invertible, then so is its constant coefficient. -/ theorem isUnit_constantCoeff (φ : MvPowerSeries σ R) (h : IsUnit φ) : IsUnit (constantCoeff σ R φ) := h.map _ -- Porting note (#10618): simp can prove this. -- @[simp] theorem coeff_smul (f : MvPowerSeries σ R) (n) (a : R) : coeff _ n (a • f) = a * coeff _ n f := rfl theorem smul_eq_C_mul (f : MvPowerSeries σ R) (a : R) : a • f = C σ R a * f := by ext simp theorem X_inj [Nontrivial R] {s t : σ} : (X s : MvPowerSeries σ R) = X t ↔ s = t := ⟨by classical intro h replace h := congr_arg (coeff R (single s 1)) h rw [coeff_X, if_pos rfl, coeff_X] at h split_ifs at h with H · rw [Finsupp.single_eq_single_iff] at H cases' H with H H · exact H.1 · exfalso exact one_ne_zero H.1 · exfalso exact one_ne_zero h, congr_arg X⟩ end Semiring section Map variable {S T : Type*} [Semiring R] [Semiring S] [Semiring T] variable (f : R →+* S) (g : S →+* T) variable (σ) /-- The map between multivariate formal power series induced by a map on the coefficients. -/ def map : MvPowerSeries σ R →+* MvPowerSeries σ S where toFun φ n := f <| coeff R n φ map_zero' := ext fun _n => f.map_zero map_one' := ext fun n => show f ((coeff R n) 1) = (coeff S n) 1 by classical rw [coeff_one, coeff_one] split_ifs with h · simp only [RingHom.map_ite_one_zero, ite_true, map_one, h] · simp only [RingHom.map_ite_one_zero, ite_false, map_zero, h] map_add' φ ψ := ext fun n => show f ((coeff R n) (φ + ψ)) = f ((coeff R n) φ) + f ((coeff R n) ψ) by simp map_mul' φ ψ := ext fun n => show f _ = _ by classical rw [coeff_mul, map_sum, coeff_mul] apply Finset.sum_congr rfl rintro ⟨i, j⟩ _; rw [f.map_mul]; rfl variable {σ} @[simp] theorem map_id : map σ (RingHom.id R) = RingHom.id _ := rfl theorem map_comp : map σ (g.comp f) = (map σ g).comp (map σ f) := rfl @[simp] theorem coeff_map (n : σ →₀ ℕ) (φ : MvPowerSeries σ R) : coeff S n (map σ f φ) = f (coeff R n φ) := rfl @[simp] theorem constantCoeff_map (φ : MvPowerSeries σ R) : constantCoeff σ S (map σ f φ) = f (constantCoeff σ R φ) := rfl @[simp] theorem map_monomial (n : σ →₀ ℕ) (a : R) : map σ f (monomial R n a) = monomial S n (f a) := by classical ext m simp [coeff_monomial, apply_ite f] @[simp] theorem map_C (a : R) : map σ f (C σ R a) = C σ S (f a) := map_monomial _ _ _ @[simp] theorem map_X (s : σ) : map σ f (X s) = X s := by simp [MvPowerSeries.X] end Map section Semiring variable [Semiring R] theorem X_pow_dvd_iff {s : σ} {n : ℕ} {φ : MvPowerSeries σ R} : (X s : MvPowerSeries σ R) ^ n ∣ φ ↔ ∀ m : σ →₀ ℕ, m s < n → coeff R m φ = 0 := by classical constructor · rintro ⟨φ, rfl⟩ m h rw [coeff_mul, Finset.sum_eq_zero] rintro ⟨i, j⟩ hij rw [coeff_X_pow, if_neg, zero_mul] contrapose! h dsimp at h subst i rw [mem_antidiagonal] at hij rw [← hij, Finsupp.add_apply, Finsupp.single_eq_same] exact Nat.le_add_right n _ · intro h refine ⟨fun m => coeff R (m + single s n) φ, ?_⟩ ext m by_cases H : m - single s n + single s n = m · rw [coeff_mul, Finset.sum_eq_single (single s n, m - single s n)] · rw [coeff_X_pow, if_pos rfl, one_mul] simpa using congr_arg (fun m : σ →₀ ℕ => coeff R m φ) H.symm · rintro ⟨i, j⟩ hij hne rw [mem_antidiagonal] at hij rw [coeff_X_pow] split_ifs with hi · exfalso apply hne rw [← hij, ← hi, Prod.mk.inj_iff] refine ⟨rfl, ?_⟩ ext t simp only [add_tsub_cancel_left, Finsupp.add_apply, Finsupp.tsub_apply] · exact zero_mul _ · intro hni exfalso apply hni rwa [mem_antidiagonal, add_comm] · rw [h, coeff_mul, Finset.sum_eq_zero] · rintro ⟨i, j⟩ hij rw [mem_antidiagonal] at hij rw [coeff_X_pow] split_ifs with hi · exfalso apply H rw [← hij, hi] ext rw [coe_add, coe_add, Pi.add_apply, Pi.add_apply, add_tsub_cancel_left, add_comm] · exact zero_mul _ · contrapose! H ext t by_cases hst : s = t · subst t simpa using tsub_add_cancel_of_le H · simp [Finsupp.single_apply, hst] theorem X_dvd_iff {s : σ} {φ : MvPowerSeries σ R} : (X s : MvPowerSeries σ R) ∣ φ ↔ ∀ m : σ →₀ ℕ, m s = 0 → coeff R m φ = 0 := by rw [← pow_one (X s : MvPowerSeries σ R), X_pow_dvd_iff] constructor <;> intro h m hm · exact h m (hm.symm ▸ zero_lt_one) · exact h m (Nat.eq_zero_of_le_zero <| Nat.le_of_succ_le_succ hm) end Semiring section CommSemiring open Finset.HasAntidiagonal Finset variable {R : Type*} [CommSemiring R] {ι : Type*} [DecidableEq ι] /-- Coefficients of a product of power series -/ theorem coeff_prod [DecidableEq σ] (f : ι → MvPowerSeries σ R) (d : σ →₀ ℕ) (s : Finset ι) : coeff R d (∏ j ∈ s, f j) = ∑ l ∈ finsuppAntidiag s d, ∏ i ∈ s, coeff R (l i) (f i) := by induction s using Finset.induction_on generalizing d with | empty => simp only [prod_empty, sum_const, nsmul_eq_mul, mul_one, coeff_one, finsuppAntidiag_empty] split_ifs · simp only [card_singleton, Nat.cast_one] · simp only [card_empty, Nat.cast_zero] | @insert a s ha ih => rw [finsuppAntidiag_insert ha, prod_insert ha, coeff_mul, sum_biUnion] · apply Finset.sum_congr rfl simp only [mem_antidiagonal, sum_map, Function.Embedding.coeFn_mk, coe_update, Prod.forall] rintro u v rfl rw [ih, Finset.mul_sum, ← Finset.sum_attach] apply Finset.sum_congr rfl simp only [mem_attach, Finset.prod_insert ha, Function.update_same, forall_true_left, Subtype.forall] rintro x - rw [Finset.prod_congr rfl] intro i hi rw [Function.update_noteq] exact ne_of_mem_of_not_mem hi ha · simp only [Set.PairwiseDisjoint, Set.Pairwise, mem_coe, mem_antidiagonal, ne_eq, disjoint_left, mem_map, mem_attach, Function.Embedding.coeFn_mk, true_and, Subtype.exists, exists_prop, not_exists, not_and, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂, Prod.forall, Prod.mk.injEq] rintro u v rfl u' v' huv h k - l - hkl obtain rfl : u' = u := by simpa only [Finsupp.coe_update, Function.update_same] using DFunLike.congr_fun hkl a simp only [add_right_inj] at huv exact h rfl huv.symm /-- The `d`th coefficient of a power of a multivariate power series is the sum, indexed by `finsuppAntidiag (Finset.range n) d`, of products of coefficients -/ theorem coeff_pow [DecidableEq σ] (f : MvPowerSeries σ R) {n : ℕ} (d : σ →₀ ℕ) : coeff R d (f ^ n) = ∑ l in finsuppAntidiag (Finset.range n) d, ∏ i in Finset.range n, coeff R (l i) f := by suffices f ^ n = (Finset.range n).prod fun _ ↦ f by rw [this, coeff_prod] rw [Finset.prod_const, card_range] /-- Vanishing of coefficients of powers of multivariate power series when the constant coefficient is nilpotent [N. Bourbaki, *Algebra {II}*, Chapter 4, §4, n°2, proposition 3][bourbaki1981] -/ theorem coeff_eq_zero_of_constantCoeff_nilpotent {f : MvPowerSeries σ R} {m : ℕ} (hf : constantCoeff σ R f ^ m = 0) {d : σ →₀ ℕ} {n : ℕ} (hn : m + degree d ≤ n) : coeff R d (f ^ n) = 0 := by classical rw [coeff_pow] apply sum_eq_zero intro k hk rw [mem_finsuppAntidiag] at hk set s := (range n).filter fun i ↦ k i = 0 with hs_def have hs : s ⊆ range n := filter_subset _ _ have hs' (i : ℕ) (hi : i ∈ s) : coeff R (k i) f = constantCoeff σ R f := by simp only [hs_def, mem_filter] at hi rw [hi.2, coeff_zero_eq_constantCoeff] have hs'' (i : ℕ) (hi : i ∈ s) : k i = 0 := by simp only [hs_def, mem_filter] at hi rw [hi.2] rw [← prod_sdiff (s₁ := s) (filter_subset _ _)] apply mul_eq_zero_of_right rw [prod_congr rfl hs', prod_const] suffices m ≤ s.card by obtain ⟨m', hm'⟩ := Nat.exists_eq_add_of_le this rw [hm', pow_add, hf, MulZeroClass.zero_mul] rw [← Nat.add_le_add_iff_right, add_comm s.card, Finset.card_sdiff_add_card_eq_card (filter_subset _ _), card_range] apply le_trans _ hn simp only [add_comm m, Nat.add_le_add_iff_right, ← hk.1, ← sum_sdiff (hs), sum_eq_zero (s := s) hs'', add_zero] rw [← hs_def] convert Finset.card_nsmul_le_sum (range n \ s) (fun x ↦ degree (k x)) 1 _ · simp only [Algebra.id.smul_eq_mul, mul_one] · simp only [degree_eq_weight_one, map_sum] · simp only [hs_def, mem_filter, mem_sdiff, mem_range, not_and, and_imp] intro i hi hi' rw [← not_lt, Nat.lt_one_iff, degree_eq_zero_iff] exact hi' hi end CommSemiring section Algebra variable {A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] instance : Algebra R (MvPowerSeries σ A) := { show Module R (MvPowerSeries σ A) by infer_instance with commutes' := fun a φ => by ext n simp [Algebra.commutes] smul_def' := fun a σ => by ext n simp [(coeff A n).map_smul_of_tower a, Algebra.smul_def] toRingHom := (MvPowerSeries.map σ (algebraMap R A)).comp (C σ R) } theorem c_eq_algebraMap : C σ R = algebraMap R (MvPowerSeries σ R) := rfl theorem algebraMap_apply {r : R} : algebraMap R (MvPowerSeries σ A) r = C σ A (algebraMap R A r) := by change (MvPowerSeries.map σ (algebraMap R A)).comp (C σ R) r = _ simp instance [Nonempty σ] [Nontrivial R] : Nontrivial (Subalgebra R (MvPowerSeries σ R)) := ⟨⟨⊥, ⊤, by classical rw [Ne, SetLike.ext_iff, not_forall] inhabit σ refine ⟨X default, ?_⟩ simp only [Algebra.mem_bot, not_exists, Set.mem_range, iff_true_iff, Algebra.mem_top] intro x rw [MvPowerSeries.ext_iff, not_forall] refine ⟨Finsupp.single default 1, ?_⟩ simp [algebraMap_apply, coeff_C]⟩⟩ end Algebra end MvPowerSeries namespace MvPolynomial open Finsupp variable {σ : Type*} {R : Type*} [CommSemiring R] (φ ψ : MvPolynomial σ R) -- Porting note: added so we can add the `@[coe]` attribute /-- The natural inclusion from multivariate polynomials into multivariate formal power series. -/ @[coe] def toMvPowerSeries : MvPolynomial σ R → MvPowerSeries σ R := fun φ n => coeff n φ /-- The natural inclusion from multivariate polynomials into multivariate formal power series. -/ instance coeToMvPowerSeries : Coe (MvPolynomial σ R) (MvPowerSeries σ R) := ⟨toMvPowerSeries⟩ theorem coe_def : (φ : MvPowerSeries σ R) = fun n => coeff n φ := rfl @[simp, norm_cast] theorem coeff_coe (n : σ →₀ ℕ) : MvPowerSeries.coeff R n ↑φ = coeff n φ := rfl @[simp, norm_cast] theorem coe_monomial (n : σ →₀ ℕ) (a : R) : (monomial n a : MvPowerSeries σ R) = MvPowerSeries.monomial R n a := MvPowerSeries.ext fun m => by classical rw [coeff_coe, coeff_monomial, MvPowerSeries.coeff_monomial] split_ifs with h₁ h₂ <;> first |rfl|subst m; contradiction @[simp, norm_cast] theorem coe_zero : ((0 : MvPolynomial σ R) : MvPowerSeries σ R) = 0 := rfl @[simp, norm_cast] theorem coe_one : ((1 : MvPolynomial σ R) : MvPowerSeries σ R) = 1 := coe_monomial _ _ @[simp, norm_cast] theorem coe_add : ((φ + ψ : MvPolynomial σ R) : MvPowerSeries σ R) = φ + ψ := rfl @[simp, norm_cast] theorem coe_mul : ((φ * ψ : MvPolynomial σ R) : MvPowerSeries σ R) = φ * ψ := MvPowerSeries.ext fun n => by classical simp only [coeff_coe, MvPowerSeries.coeff_mul, coeff_mul] @[simp, norm_cast] theorem coe_C (a : R) : ((C a : MvPolynomial σ R) : MvPowerSeries σ R) = MvPowerSeries.C σ R a := coe_monomial _ _ @[simp, norm_cast] theorem coe_X (s : σ) : ((X s : MvPolynomial σ R) : MvPowerSeries σ R) = MvPowerSeries.X s := coe_monomial _ _ variable (σ R) theorem coe_injective : Function.Injective (Coe.coe : MvPolynomial σ R → MvPowerSeries σ R) := fun x y h => by ext simp_rw [← coeff_coe] congr variable {σ R φ ψ} @[simp, norm_cast] theorem coe_inj : (φ : MvPowerSeries σ R) = ψ ↔ φ = ψ := (coe_injective σ R).eq_iff @[simp] theorem coe_eq_zero_iff : (φ : MvPowerSeries σ R) = 0 ↔ φ = 0 := by rw [← coe_zero, coe_inj] @[simp] theorem coe_eq_one_iff : (φ : MvPowerSeries σ R) = 1 ↔ φ = 1 := by rw [← coe_one, coe_inj] /-- The coercion from multivariate polynomials to multivariate power series as a ring homomorphism. -/ def coeToMvPowerSeries.ringHom : MvPolynomial σ R →+* MvPowerSeries σ R where toFun := (Coe.coe : MvPolynomial σ R → MvPowerSeries σ R) map_zero' := coe_zero map_one' := coe_one map_add' := coe_add map_mul' := coe_mul @[simp, norm_cast] theorem coe_pow (n : ℕ) : ((φ ^ n : MvPolynomial σ R) : MvPowerSeries σ R) = (φ : MvPowerSeries σ R) ^ n := coeToMvPowerSeries.ringHom.map_pow _ _ variable (φ ψ) @[simp] theorem coeToMvPowerSeries.ringHom_apply : coeToMvPowerSeries.ringHom φ = φ := rfl section Algebra variable (A : Type*) [CommSemiring A] [Algebra R A] /-- The coercion from multivariate polynomials to multivariate power series as an algebra homomorphism. -/ def coeToMvPowerSeries.algHom : MvPolynomial σ R →ₐ[R] MvPowerSeries σ A := { (MvPowerSeries.map σ (algebraMap R A)).comp coeToMvPowerSeries.ringHom with commutes' := fun r => by simp [algebraMap_apply, MvPowerSeries.algebraMap_apply] } @[simp] theorem coeToMvPowerSeries.algHom_apply : coeToMvPowerSeries.algHom A φ = MvPowerSeries.map σ (algebraMap R A) ↑φ := rfl end Algebra end MvPolynomial namespace MvPowerSeries variable {σ R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A] (f : MvPowerSeries σ R) instance algebraMvPolynomial : Algebra (MvPolynomial σ R) (MvPowerSeries σ A) := RingHom.toAlgebra (MvPolynomial.coeToMvPowerSeries.algHom A).toRingHom instance algebraMvPowerSeries : Algebra (MvPowerSeries σ R) (MvPowerSeries σ A) := (map σ (algebraMap R A)).toAlgebra variable (A) theorem algebraMap_apply' (p : MvPolynomial σ R) : algebraMap (MvPolynomial σ R) (MvPowerSeries σ A) p = map σ (algebraMap R A) p := rfl theorem algebraMap_apply'' : algebraMap (MvPowerSeries σ R) (MvPowerSeries σ A) f = map σ (algebraMap R A) f := rfl end MvPowerSeries end
RingTheory\MvPowerSeries\Inverse.lean
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Kenny Lau -/ import Mathlib.Algebra.Group.Units import Mathlib.RingTheory.MvPowerSeries.Basic import Mathlib.RingTheory.MvPowerSeries.NoZeroDivisors import Mathlib.RingTheory.LocalRing.RingHom.Basic /-! # Formal (multivariate) power series - Inverses This file defines multivariate formal power series and develops the basic properties of these objects, when it comes about multiplicative inverses. For `φ : MvPowerSeries σ R` and `u : Rˣ` is the constant coefficient of `φ`, `MvPowerSeries.invOfUnit φ u` is a formal power series such, and `MvPowerSeries.mul_invOfUnit` proves that `φ * invOfUnit φ u = 1`. The construction of the power series `invOfUnit` is done by writing that relation and solving and for its coefficients by induction. Over a field, all power series `φ` have an “inverse” `MvPowerSeries.inv φ`, which is `0` if and only if the constant coefficient of `φ` is zero (by `MvPowerSeries.inv_eq_zero`), and `MvPowerSeries.mul_inv_cancel` asserts the equality `φ * φ⁻¹ = 1` when the constant coefficient of `φ` is nonzero. Instances are defined: * Formal power series over a local ring form a local ring. * The morphism `MvPowerSeries.map σ f : MvPowerSeries σ A →* MvPowerSeries σ B` induced by a local morphism `f : A →+* B` (`IsLocalRingHom f`) of commutative rings is a *local* morphism. -/ noncomputable section open Finset (antidiagonal mem_antidiagonal) namespace MvPowerSeries open Finsupp variable {σ R : Type*} section Ring variable [Ring R] /- The inverse of a multivariate formal power series is defined by well-founded recursion on the coefficients of the inverse. -/ /-- Auxiliary definition that unifies the totalised inverse formal power series `(_)⁻¹` and the inverse formal power series that depends on an inverse of the constant coefficient `invOfUnit`. -/ protected noncomputable def inv.aux (a : R) (φ : MvPowerSeries σ R) : MvPowerSeries σ R | n => letI := Classical.decEq σ if n = 0 then a else -a * ∑ x ∈ antidiagonal n, if _ : x.2 < n then coeff R x.1 φ * inv.aux a φ x.2 else 0 termination_by n => n theorem coeff_inv_aux [DecidableEq σ] (n : σ →₀ ℕ) (a : R) (φ : MvPowerSeries σ R) : coeff R n (inv.aux a φ) = if n = 0 then a else -a * ∑ x ∈ antidiagonal n, if x.2 < n then coeff R x.1 φ * coeff R x.2 (inv.aux a φ) else 0 := show inv.aux a φ n = _ by cases Subsingleton.elim ‹DecidableEq σ› (Classical.decEq σ) rw [inv.aux] rfl /-- A multivariate formal power series is invertible if the constant coefficient is invertible. -/ def invOfUnit (φ : MvPowerSeries σ R) (u : Rˣ) : MvPowerSeries σ R := inv.aux (↑u⁻¹) φ theorem coeff_invOfUnit [DecidableEq σ] (n : σ →₀ ℕ) (φ : MvPowerSeries σ R) (u : Rˣ) : coeff R n (invOfUnit φ u) = if n = 0 then ↑u⁻¹ else -↑u⁻¹ * ∑ x ∈ antidiagonal n, if x.2 < n then coeff R x.1 φ * coeff R x.2 (invOfUnit φ u) else 0 := by convert coeff_inv_aux n (↑u⁻¹) φ @[simp] theorem constantCoeff_invOfUnit (φ : MvPowerSeries σ R) (u : Rˣ) : constantCoeff σ R (invOfUnit φ u) = ↑u⁻¹ := by classical rw [← coeff_zero_eq_constantCoeff_apply, coeff_invOfUnit, if_pos rfl] @[simp] theorem mul_invOfUnit (φ : MvPowerSeries σ R) (u : Rˣ) (h : constantCoeff σ R φ = u) : φ * invOfUnit φ u = 1 := ext fun n => letI := Classical.decEq (σ →₀ ℕ) if H : n = 0 then by rw [H] simp [coeff_mul, support_single_ne_zero, h] else by classical have : ((0 : σ →₀ ℕ), n) ∈ antidiagonal n := by rw [mem_antidiagonal, zero_add] rw [coeff_one, if_neg H, coeff_mul, ← Finset.insert_erase this, Finset.sum_insert (Finset.not_mem_erase _ _), coeff_zero_eq_constantCoeff_apply, h, coeff_invOfUnit, if_neg H, neg_mul, mul_neg, Units.mul_inv_cancel_left, ← Finset.insert_erase this, Finset.sum_insert (Finset.not_mem_erase _ _), Finset.insert_erase this, if_neg (not_lt_of_ge <| le_rfl), zero_add, add_comm, ← sub_eq_add_neg, sub_eq_zero, Finset.sum_congr rfl] rintro ⟨i, j⟩ hij rw [Finset.mem_erase, mem_antidiagonal] at hij cases' hij with h₁ h₂ subst n rw [if_pos] suffices (0 : _) + j < i + j by simpa apply add_lt_add_right constructor · intro s exact Nat.zero_le _ · intro H apply h₁ suffices i = 0 by simp [this] ext1 s exact Nat.eq_zero_of_le_zero (H s) -- TODO : can one prove equivalence? @[simp] theorem invOfUnit_mul (φ : MvPowerSeries σ R) (u : Rˣ) (h : constantCoeff σ R φ = u) : invOfUnit φ u * φ = 1 := by rw [← mul_cancel_right_mem_nonZeroDivisors (r := φ.invOfUnit u), mul_assoc, one_mul, mul_invOfUnit _ _ h, mul_one] apply mem_nonZeroDivisors_of_constantCoeff simp only [constantCoeff_invOfUnit, IsUnit.mem_nonZeroDivisors (Units.isUnit u⁻¹)] theorem isUnit_iff_constantCoeff {φ : MvPowerSeries σ R} : IsUnit φ ↔ IsUnit (constantCoeff σ R φ) := by constructor · exact IsUnit.map _ · intro ⟨u, hu⟩ exact ⟨⟨_, φ.invOfUnit u, mul_invOfUnit φ u hu.symm, invOfUnit_mul φ u hu.symm⟩, rfl⟩ end Ring section CommRing variable [CommRing R] /-- Multivariate formal power series over a local ring form a local ring. -/ instance [LocalRing R] : LocalRing (MvPowerSeries σ R) := LocalRing.of_isUnit_or_isUnit_one_sub_self <| by intro φ rcases LocalRing.isUnit_or_isUnit_one_sub_self (constantCoeff σ R φ) with (⟨u, h⟩ | ⟨u, h⟩) <;> [left; right] <;> · refine isUnit_of_mul_eq_one _ _ (mul_invOfUnit _ u ?_) simpa using h.symm -- TODO(jmc): once adic topology lands, show that this is complete end CommRing section LocalRing variable {S : Type*} [CommRing R] [CommRing S] (f : R →+* S) [IsLocalRingHom f] -- Thanks to the linter for informing us that this instance does -- not actually need R and S to be local rings! /-- The map between multivariate formal power series over the same indexing set induced by a local ring hom `A → B` is local -/ instance map.isLocalRingHom : IsLocalRingHom (map σ f) := ⟨by rintro φ ⟨ψ, h⟩ replace h := congr_arg (constantCoeff σ S) h rw [constantCoeff_map] at h have : IsUnit (constantCoeff σ S ↑ψ) := isUnit_constantCoeff (↑ψ) ψ.isUnit rw [h] at this rcases isUnit_of_map_unit f _ this with ⟨c, hc⟩ exact isUnit_of_mul_eq_one φ (invOfUnit φ c) (mul_invOfUnit φ c hc.symm)⟩ end LocalRing section Field open MvPowerSeries variable {k : Type*} [Field k] /-- The inverse `1/f` of a multivariable power series `f` over a field -/ protected def inv (φ : MvPowerSeries σ k) : MvPowerSeries σ k := inv.aux (constantCoeff σ k φ)⁻¹ φ instance : Inv (MvPowerSeries σ k) := ⟨MvPowerSeries.inv⟩ theorem coeff_inv [DecidableEq σ] (n : σ →₀ ℕ) (φ : MvPowerSeries σ k) : coeff k n φ⁻¹ = if n = 0 then (constantCoeff σ k φ)⁻¹ else -(constantCoeff σ k φ)⁻¹ * ∑ x ∈ antidiagonal n, if x.2 < n then coeff k x.1 φ * coeff k x.2 φ⁻¹ else 0 := coeff_inv_aux n _ φ @[simp] theorem constantCoeff_inv (φ : MvPowerSeries σ k) : constantCoeff σ k φ⁻¹ = (constantCoeff σ k φ)⁻¹ := by classical rw [← coeff_zero_eq_constantCoeff_apply, coeff_inv, if_pos rfl] theorem inv_eq_zero {φ : MvPowerSeries σ k} : φ⁻¹ = 0 ↔ constantCoeff σ k φ = 0 := ⟨fun h => by simpa using congr_arg (constantCoeff σ k) h, fun h => ext fun n => by classical rw [coeff_inv] split_ifs <;> simp only [h, map_zero, zero_mul, inv_zero, neg_zero]⟩ @[simp] theorem zero_inv : (0 : MvPowerSeries σ k)⁻¹ = 0 := by rw [inv_eq_zero, constantCoeff_zero] -- Porting note (#10618): simp can prove this. -- @[simp] theorem invOfUnit_eq (φ : MvPowerSeries σ k) (h : constantCoeff σ k φ ≠ 0) : invOfUnit φ (Units.mk0 _ h) = φ⁻¹ := rfl @[simp] theorem invOfUnit_eq' (φ : MvPowerSeries σ k) (u : Units k) (h : constantCoeff σ k φ = u) : invOfUnit φ u = φ⁻¹ := by rw [← invOfUnit_eq φ (h.symm ▸ u.ne_zero)] apply congrArg (invOfUnit φ) rw [Units.ext_iff] exact h.symm @[simp] protected theorem mul_inv_cancel (φ : MvPowerSeries σ k) (h : constantCoeff σ k φ ≠ 0) : φ * φ⁻¹ = 1 := by rw [← invOfUnit_eq φ h, mul_invOfUnit φ (Units.mk0 _ h) rfl] @[simp] protected theorem inv_mul_cancel (φ : MvPowerSeries σ k) (h : constantCoeff σ k φ ≠ 0) : φ⁻¹ * φ = 1 := by rw [mul_comm, φ.mul_inv_cancel h] protected theorem eq_mul_inv_iff_mul_eq {φ₁ φ₂ φ₃ : MvPowerSeries σ k} (h : constantCoeff σ k φ₃ ≠ 0) : φ₁ = φ₂ * φ₃⁻¹ ↔ φ₁ * φ₃ = φ₂ := ⟨fun k => by simp [k, mul_assoc, MvPowerSeries.inv_mul_cancel _ h], fun k => by simp [← k, mul_assoc, MvPowerSeries.mul_inv_cancel _ h]⟩ protected theorem eq_inv_iff_mul_eq_one {φ ψ : MvPowerSeries σ k} (h : constantCoeff σ k ψ ≠ 0) : φ = ψ⁻¹ ↔ φ * ψ = 1 := by rw [← MvPowerSeries.eq_mul_inv_iff_mul_eq h, one_mul] protected theorem inv_eq_iff_mul_eq_one {φ ψ : MvPowerSeries σ k} (h : constantCoeff σ k ψ ≠ 0) : ψ⁻¹ = φ ↔ φ * ψ = 1 := by rw [eq_comm, MvPowerSeries.eq_inv_iff_mul_eq_one h] @[simp] protected theorem mul_inv_rev (φ ψ : MvPowerSeries σ k) : (φ * ψ)⁻¹ = ψ⁻¹ * φ⁻¹ := by by_cases h : constantCoeff σ k (φ * ψ) = 0 · rw [inv_eq_zero.mpr h] simp only [map_mul, mul_eq_zero] at h -- we don't have `NoZeroDivisors (MvPowerSeries σ k)` yet, cases' h with h h <;> simp [inv_eq_zero.mpr h] · rw [MvPowerSeries.inv_eq_iff_mul_eq_one h] simp only [not_or, map_mul, mul_eq_zero] at h rw [← mul_assoc, mul_assoc _⁻¹, MvPowerSeries.inv_mul_cancel _ h.left, mul_one, MvPowerSeries.inv_mul_cancel _ h.right] instance : InvOneClass (MvPowerSeries σ k) := { inferInstanceAs (One (MvPowerSeries σ k)), inferInstanceAs (Inv (MvPowerSeries σ k)) with inv_one := by rw [MvPowerSeries.inv_eq_iff_mul_eq_one, mul_one] simp } @[simp] theorem C_inv (r : k) : (C σ k r)⁻¹ = C σ k r⁻¹ := by rcases eq_or_ne r 0 with (rfl | hr) · simp rw [MvPowerSeries.inv_eq_iff_mul_eq_one, ← map_mul, inv_mul_cancel hr, map_one] simpa using hr @[simp] theorem X_inv (s : σ) : (X s : MvPowerSeries σ k)⁻¹ = 0 := by rw [inv_eq_zero, constantCoeff_X] @[simp] theorem smul_inv (r : k) (φ : MvPowerSeries σ k) : (r • φ)⁻¹ = r⁻¹ • φ⁻¹ := by simp [smul_eq_C_mul, mul_comm] end Field end MvPowerSeries end
RingTheory\MvPowerSeries\NoZeroDivisors.lean
/- Copyright (c) 2024 Antoine Chambert-Loir. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Antoine Chambert-Loir -/ import Mathlib.RingTheory.MvPowerSeries.Basic import Mathlib.Data.Finsupp.WellFounded /-! # ZeroDivisors in a MvPowerSeries ring - `mem_nonZeroDivisors_of_constantCoeff` proves that a multivariate power series whose constant coefficient is not a zero divisor is itself not a zero divisor ## TODO * A subsequent PR #14571 proves that if `R` has no zero divisors, then so does `MvPowerSeries σ R`. * Transfer/adapt these results to `HahnSeries`. ## Remark The analogue of `Polynomial.nmem_nonZeroDivisors_iff` (McCoy theorem) holds for power series over a noetherian ring, but not in general. See [Fields1971] -/ noncomputable section open Finset (antidiagonal mem_antidiagonal) namespace MvPowerSeries open Finsupp variable {σ R : Type*} section Semiring variable [Semiring R] /-- A multivariate power series is not a zero divisor when its constant coefficient is not a zero divisor -/ theorem mem_nonZeroDivisors_of_constantCoeff {φ : MvPowerSeries σ R} (hφ : constantCoeff σ R φ ∈ nonZeroDivisors R) : φ ∈ nonZeroDivisors (MvPowerSeries σ R) := by classical intro x hx ext d apply WellFoundedLT.induction d intro e he rw [map_zero, ← mul_right_mem_nonZeroDivisors_eq_zero_iff hφ, ← map_zero (f := coeff R e), ← hx] convert (coeff_mul e x φ).symm rw [Finset.sum_eq_single (e,0), coeff_zero_eq_constantCoeff] · rintro ⟨u, _⟩ huv _ suffices u < e by simp only [he u this, zero_mul, map_zero] apply lt_of_le_of_ne · simp only [← mem_antidiagonal.mp huv, le_add_iff_nonneg_right, zero_le] · rintro rfl simp_all · simp only [mem_antidiagonal, add_zero, not_true_eq_false, coeff_zero_eq_constantCoeff, false_implies] end Semiring end MvPowerSeries end
RingTheory\MvPowerSeries\Trunc.lean
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Kenny Lau -/ import Mathlib.RingTheory.MvPowerSeries.Basic import Mathlib.Data.Finsupp.Interval /-! # Formal (multivariate) power series - Truncation `MvPowerSeries.trunc n φ` truncates a formal multivariate power series to the multivariate polynomial that has the same coefficients as `φ`, for all `m < n`, and `0` otherwise. Note that here, `m` and `n` have types `σ →₀ ℕ`, so that `m < n` means that `m ≠ n` and `m s ≤ n s` for all `s : σ`. -/ noncomputable section open Finset (antidiagonal mem_antidiagonal) namespace MvPowerSeries open Finsupp variable {σ R : Type*} section Trunc variable [CommSemiring R] (n : σ →₀ ℕ) /-- Auxiliary definition for the truncation function. -/ def truncFun (φ : MvPowerSeries σ R) : MvPolynomial σ R := ∑ m ∈ Finset.Iio n, MvPolynomial.monomial m (coeff R m φ) theorem coeff_truncFun (m : σ →₀ ℕ) (φ : MvPowerSeries σ R) : (truncFun n φ).coeff m = if m < n then coeff R m φ else 0 := by classical simp [truncFun, MvPolynomial.coeff_sum] variable (R) /-- The `n`th truncation of a multivariate formal power series to a multivariate polynomial -/ def trunc : MvPowerSeries σ R →+ MvPolynomial σ R where toFun := truncFun n map_zero' := by classical ext simp [coeff_truncFun] map_add' := by classical intros x y ext m simp only [coeff_truncFun, MvPolynomial.coeff_add] split_ifs · rw [map_add] · rw [zero_add] variable {R} theorem coeff_trunc (m : σ →₀ ℕ) (φ : MvPowerSeries σ R) : (trunc R n φ).coeff m = if m < n then coeff R m φ else 0 := by classical simp [trunc, coeff_truncFun] @[simp] theorem trunc_one (n : σ →₀ ℕ) (hnn : n ≠ 0) : trunc R n 1 = 1 := MvPolynomial.ext _ _ fun m => by classical rw [coeff_trunc, coeff_one] split_ifs with H H' · subst m simp · symm rw [MvPolynomial.coeff_one] exact if_neg (Ne.symm H') · symm rw [MvPolynomial.coeff_one] refine if_neg ?_ rintro rfl apply H exact Ne.bot_lt hnn @[simp] theorem trunc_c (n : σ →₀ ℕ) (hnn : n ≠ 0) (a : R) : trunc R n (C σ R a) = MvPolynomial.C a := MvPolynomial.ext _ _ fun m => by classical rw [coeff_trunc, coeff_C, MvPolynomial.coeff_C] split_ifs with H <;> first |rfl|try simp_all exfalso; apply H; subst m; exact Ne.bot_lt hnn end Trunc end MvPowerSeries end
RingTheory\Nilpotent\Basic.lean
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Associated.Basic import Mathlib.Algebra.GeomSum import Mathlib.Algebra.GroupWithZero.NonZeroDivisors import Mathlib.Algebra.Module.Defs import Mathlib.Algebra.SMulWithZero import Mathlib.Data.Nat.Choose.Sum import Mathlib.Data.Nat.Lattice import Mathlib.RingTheory.Nilpotent.Defs /-! # Nilpotent elements This file develops the basic theory of nilpotent elements. In particular it shows that the nilpotent elements are closed under many operations. For the definition of `nilradical`, see `Mathlib.RingTheory.Nilpotent.Lemmas`. ## Main definitions * `isNilpotent_neg_iff` * `Commute.isNilpotent_add` * `Commute.isNilpotent_sub` -/ universe u v open Function Set variable {R S : Type*} {x y : R} theorem IsNilpotent.neg [Ring R] (h : IsNilpotent x) : IsNilpotent (-x) := by obtain ⟨n, hn⟩ := h use n rw [neg_pow, hn, mul_zero] @[simp] theorem isNilpotent_neg_iff [Ring R] : IsNilpotent (-x) ↔ IsNilpotent x := ⟨fun h => neg_neg x ▸ h.neg, fun h => h.neg⟩ lemma IsNilpotent.smul [MonoidWithZero R] [MonoidWithZero S] [MulActionWithZero R S] [SMulCommClass R S S] [IsScalarTower R S S] {a : S} (ha : IsNilpotent a) (t : R) : IsNilpotent (t • a) := by obtain ⟨k, ha⟩ := ha use k rw [smul_pow, ha, smul_zero] theorem IsNilpotent.isUnit_sub_one [Ring R] {r : R} (hnil : IsNilpotent r) : IsUnit (r - 1) := by obtain ⟨n, hn⟩ := hnil refine ⟨⟨r - 1, -∑ i ∈ Finset.range n, r ^ i, ?_, ?_⟩, rfl⟩ · simp [mul_geom_sum, hn] · simp [geom_sum_mul, hn] theorem IsNilpotent.isUnit_one_sub [Ring R] {r : R} (hnil : IsNilpotent r) : IsUnit (1 - r) := by rw [← IsUnit.neg_iff, neg_sub] exact isUnit_sub_one hnil theorem IsNilpotent.isUnit_add_one [Ring R] {r : R} (hnil : IsNilpotent r) : IsUnit (r + 1) := by rw [← IsUnit.neg_iff, neg_add'] exact isUnit_sub_one hnil.neg theorem IsNilpotent.isUnit_one_add [Ring R] {r : R} (hnil : IsNilpotent r) : IsUnit (1 + r) := add_comm r 1 ▸ isUnit_add_one hnil theorem IsNilpotent.isUnit_add_left_of_commute [Ring R] {r u : R} (hnil : IsNilpotent r) (hu : IsUnit u) (h_comm : Commute r u) : IsUnit (u + r) := by rw [← Units.isUnit_mul_units _ hu.unit⁻¹, add_mul, IsUnit.mul_val_inv] replace h_comm : Commute r (↑hu.unit⁻¹) := Commute.units_inv_right h_comm refine IsNilpotent.isUnit_one_add ?_ exact (hu.unit⁻¹.isUnit.isNilpotent_mul_unit_of_commute_iff h_comm).mpr hnil theorem IsNilpotent.isUnit_add_right_of_commute [Ring R] {r u : R} (hnil : IsNilpotent r) (hu : IsUnit u) (h_comm : Commute r u) : IsUnit (r + u) := add_comm r u ▸ hnil.isUnit_add_left_of_commute hu h_comm instance [Zero R] [Pow R ℕ] [Zero S] [Pow S ℕ] [IsReduced R] [IsReduced S] : IsReduced (R × S) where eq_zero _ := fun ⟨n, hn⟩ ↦ have hn := Prod.ext_iff.1 hn Prod.ext (IsReduced.eq_zero _ ⟨n, hn.1⟩) (IsReduced.eq_zero _ ⟨n, hn.2⟩) theorem Prime.isRadical [CommMonoidWithZero R] {y : R} (hy : Prime y) : IsRadical y := fun _ _ ↦ hy.dvd_of_dvd_pow theorem zero_isRadical_iff [MonoidWithZero R] : IsRadical (0 : R) ↔ IsReduced R := by simp_rw [isReduced_iff, IsNilpotent, exists_imp, ← zero_dvd_iff] exact forall_swap theorem isReduced_iff_pow_one_lt [MonoidWithZero R] (k : ℕ) (hk : 1 < k) : IsReduced R ↔ ∀ x : R, x ^ k = 0 → x = 0 := by simp_rw [← zero_isRadical_iff, isRadical_iff_pow_one_lt k hk, zero_dvd_iff] theorem IsRadical.of_dvd [CancelCommMonoidWithZero R] {x y : R} (hy : IsRadical y) (h0 : y ≠ 0) (hxy : x ∣ y) : IsRadical x := (isRadical_iff_pow_one_lt 2 one_lt_two).2 <| by obtain ⟨z, rfl⟩ := hxy refine fun w dvd ↦ ((mul_dvd_mul_iff_right <| right_ne_zero_of_mul h0).mp <| hy 2 _ ?_) rw [mul_pow, sq z]; exact mul_dvd_mul dvd (dvd_mul_left z z) namespace Commute section Semiring variable [Semiring R] theorem add_pow_eq_zero_of_add_le_succ_of_pow_eq_zero (h_comm : Commute x y) {m n k : ℕ} (hx : x ^ m = 0) (hy : y ^ n = 0) (h : m + n ≤ k + 1) : (x + y) ^ k = 0 := by rw [h_comm.add_pow'] apply Finset.sum_eq_zero rintro ⟨i, j⟩ hij suffices x ^ i * y ^ j = 0 by simp only [this, nsmul_eq_mul, mul_zero] by_cases hi : m ≤ i · rw [pow_eq_zero_of_le hi hx, zero_mul] rw [pow_eq_zero_of_le ?_ hy, mul_zero] linarith [Finset.mem_antidiagonal.mp hij] theorem add_pow_add_eq_zero_of_pow_eq_zero (h_comm : Commute x y) {m n : ℕ} (hx : x ^ m = 0) (hy : y ^ n = 0) : (x + y) ^ (m + n - 1) = 0 := h_comm.add_pow_eq_zero_of_add_le_succ_of_pow_eq_zero hx hy <| by rw [← Nat.sub_le_iff_le_add] theorem isNilpotent_add (h_comm : Commute x y) (hx : IsNilpotent x) (hy : IsNilpotent y) : IsNilpotent (x + y) := by obtain ⟨n, hn⟩ := hx obtain ⟨m, hm⟩ := hy exact ⟨_, add_pow_add_eq_zero_of_pow_eq_zero h_comm hn hm⟩ protected lemma isNilpotent_sum {ι : Type*} {s : Finset ι} {f : ι → R} (hnp : ∀ i ∈ s, IsNilpotent (f i)) (h_comm : ∀ i j, i ∈ s → j ∈ s → Commute (f i) (f j)) : IsNilpotent (∑ i ∈ s, f i) := by classical induction s using Finset.induction with | empty => simp | @insert j s hj ih => ?_ rw [Finset.sum_insert hj] apply Commute.isNilpotent_add · exact Commute.sum_right _ _ _ (fun i hi ↦ h_comm _ _ (by simp) (by simp [hi])) · apply hnp; simp · exact ih (fun i hi ↦ hnp i (by simp [hi])) (fun i j hi hj ↦ h_comm i j (by simp [hi]) (by simp [hj])) protected lemma isNilpotent_mul_left_iff (h_comm : Commute x y) (hy : y ∈ nonZeroDivisorsLeft R) : IsNilpotent (x * y) ↔ IsNilpotent x := by refine ⟨?_, h_comm.isNilpotent_mul_left⟩ rintro ⟨k, hk⟩ rw [mul_pow h_comm] at hk exact ⟨k, (nonZeroDivisorsLeft R).pow_mem hy k _ hk⟩ protected lemma isNilpotent_mul_right_iff (h_comm : Commute x y) (hx : x ∈ nonZeroDivisorsRight R) : IsNilpotent (x * y) ↔ IsNilpotent y := by refine ⟨?_, h_comm.isNilpotent_mul_right⟩ rintro ⟨k, hk⟩ rw [mul_pow h_comm] at hk exact ⟨k, (nonZeroDivisorsRight R).pow_mem hx k _ hk⟩ end Semiring section Ring variable [Ring R] theorem isNilpotent_sub (h_comm : Commute x y) (hx : IsNilpotent x) (hy : IsNilpotent y) : IsNilpotent (x - y) := by rw [← neg_right_iff] at h_comm rw [← isNilpotent_neg_iff] at hy rw [sub_eq_add_neg] exact h_comm.isNilpotent_add hx hy end Ring end Commute section CommSemiring variable [CommSemiring R] {x y : R} lemma isNilpotent_sum {ι : Type*} {s : Finset ι} {f : ι → R} (hnp : ∀ i ∈ s, IsNilpotent (f i)) : IsNilpotent (∑ i ∈ s, f i) := Commute.isNilpotent_sum hnp fun _ _ _ _ ↦ Commute.all _ _ end CommSemiring lemma NoZeroSMulDivisors.isReduced (R M : Type*) [MonoidWithZero R] [Zero M] [MulActionWithZero R M] [Nontrivial M] [NoZeroSMulDivisors R M] : IsReduced R := by refine ⟨fun x ⟨k, hk⟩ ↦ ?_⟩ induction' k with k ih · rw [pow_zero] at hk exact eq_zero_of_zero_eq_one hk.symm x · obtain ⟨m : M, hm : m ≠ 0⟩ := exists_ne (0 : M) have : x ^ (k + 1) • m = 0 := by simp only [hk, zero_smul] rw [pow_succ', mul_smul] at this rcases eq_zero_or_eq_zero_of_smul_eq_zero this with rfl | hx · rfl · exact ih <| (eq_zero_or_eq_zero_of_smul_eq_zero hx).resolve_right hm
RingTheory\Nilpotent\Defs.lean
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.GroupWithZero.Hom import Mathlib.Algebra.GroupWithZero.Units.Basic import Mathlib.Algebra.Ring.Defs import Mathlib.Data.Nat.Lattice /-! # Definition of nilpotent elements This file defines the notion of a nilpotent element and proves the immediate consequences. For results that require further theory, see `Mathlib.RingTheory.Nilpotent.Basic` and `Mathlib.RingTheory.Nilpotent.Lemmas`. ## Main definitions * `IsNilpotent` * `Commute.isNilpotent_mul_left` * `Commute.isNilpotent_mul_right` * `nilpotencyClass` -/ universe u v open Function Set variable {R S : Type*} {x y : R} /-- An element is said to be nilpotent if some natural-number-power of it equals zero. Note that we require only the bare minimum assumptions for the definition to make sense. Even `MonoidWithZero` is too strong since nilpotency is important in the study of rings that are only power-associative. -/ def IsNilpotent [Zero R] [Pow R ℕ] (x : R) : Prop := ∃ n : ℕ, x ^ n = 0 theorem IsNilpotent.mk [Zero R] [Pow R ℕ] (x : R) (n : ℕ) (e : x ^ n = 0) : IsNilpotent x := ⟨n, e⟩ @[simp] lemma isNilpotent_of_subsingleton [Zero R] [Pow R ℕ] [Subsingleton R] : IsNilpotent x := ⟨0, Subsingleton.elim _ _⟩ @[simp] theorem IsNilpotent.zero [MonoidWithZero R] : IsNilpotent (0 : R) := ⟨1, pow_one 0⟩ theorem not_isNilpotent_one [MonoidWithZero R] [Nontrivial R] : ¬ IsNilpotent (1 : R) := fun ⟨_, H⟩ ↦ zero_ne_one (H.symm.trans (one_pow _)) lemma IsNilpotent.pow_succ (n : ℕ) {S : Type*} [MonoidWithZero S] {x : S} (hx : IsNilpotent x) : IsNilpotent (x ^ n.succ) := by obtain ⟨N,hN⟩ := hx use N rw [← pow_mul, Nat.succ_mul, pow_add, hN, mul_zero] theorem IsNilpotent.of_pow [MonoidWithZero R] {x : R} {m : ℕ} (h : IsNilpotent (x ^ m)) : IsNilpotent x := by obtain ⟨n, h⟩ := h use m*n rw [← h, pow_mul x m n] lemma IsNilpotent.pow_of_pos {n} {S : Type*} [MonoidWithZero S] {x : S} (hx : IsNilpotent x) (hn : n ≠ 0) : IsNilpotent (x ^ n) := by cases n with | zero => contradiction | succ => exact IsNilpotent.pow_succ _ hx @[simp] lemma IsNilpotent.pow_iff_pos {n} {S : Type*} [MonoidWithZero S] {x : S} (hn : n ≠ 0) : IsNilpotent (x ^ n) ↔ IsNilpotent x := ⟨fun h => of_pow h, fun h => pow_of_pos h hn⟩ theorem IsNilpotent.map [MonoidWithZero R] [MonoidWithZero S] {r : R} {F : Type*} [FunLike F R S] [MonoidWithZeroHomClass F R S] (hr : IsNilpotent r) (f : F) : IsNilpotent (f r) := by use hr.choose rw [← map_pow, hr.choose_spec, map_zero] lemma IsNilpotent.map_iff [MonoidWithZero R] [MonoidWithZero S] {r : R} {F : Type*} [FunLike F R S] [MonoidWithZeroHomClass F R S] {f : F} (hf : Function.Injective f) : IsNilpotent (f r) ↔ IsNilpotent r := ⟨fun ⟨k, hk⟩ ↦ ⟨k, (map_eq_zero_iff f hf).mp <| by rwa [map_pow]⟩, fun h ↦ h.map f⟩ theorem IsUnit.isNilpotent_mul_unit_of_commute_iff [MonoidWithZero R] {r u : R} (hu : IsUnit u) (h_comm : Commute r u) : IsNilpotent (r * u) ↔ IsNilpotent r := exists_congr fun n ↦ by rw [h_comm.mul_pow, (hu.pow n).mul_left_eq_zero] theorem IsUnit.isNilpotent_unit_mul_of_commute_iff [MonoidWithZero R] {r u : R} (hu : IsUnit u) (h_comm : Commute r u) : IsNilpotent (u * r) ↔ IsNilpotent r := h_comm ▸ hu.isNilpotent_mul_unit_of_commute_iff h_comm section NilpotencyClass section ZeroPow variable [Zero R] [Pow R ℕ] variable (x) in /-- If `x` is nilpotent, the nilpotency class is the smallest natural number `k` such that `x ^ k = 0`. If `x` is not nilpotent, the nilpotency class takes the junk value `0`. -/ noncomputable def nilpotencyClass : ℕ := sInf {k | x ^ k = 0} @[simp] lemma nilpotencyClass_eq_zero_of_subsingleton [Subsingleton R] : nilpotencyClass x = 0 := by let s : Set ℕ := {k | x ^ k = 0} suffices s = univ by change sInf _ = 0; simp [s] at this; simp [this] exact eq_univ_iff_forall.mpr fun k ↦ Subsingleton.elim _ _ lemma isNilpotent_of_pos_nilpotencyClass (hx : 0 < nilpotencyClass x) : IsNilpotent x := by let s : Set ℕ := {k | x ^ k = 0} change s.Nonempty change 0 < sInf s at hx by_contra contra simp [not_nonempty_iff_eq_empty.mp contra] at hx lemma pow_nilpotencyClass (hx : IsNilpotent x) : x ^ (nilpotencyClass x) = 0 := Nat.sInf_mem hx end ZeroPow section MonoidWithZero variable [MonoidWithZero R] lemma nilpotencyClass_eq_succ_iff {k : ℕ} : nilpotencyClass x = k + 1 ↔ x ^ (k + 1) = 0 ∧ x ^ k ≠ 0 := by let s : Set ℕ := {k | x ^ k = 0} have : ∀ k₁ k₂ : ℕ, k₁ ≤ k₂ → k₁ ∈ s → k₂ ∈ s := fun k₁ k₂ h_le hk₁ ↦ pow_eq_zero_of_le h_le hk₁ simp [s, nilpotencyClass, Nat.sInf_upward_closed_eq_succ_iff this] @[simp] lemma nilpotencyClass_zero [Nontrivial R] : nilpotencyClass (0 : R) = 1 := nilpotencyClass_eq_succ_iff.mpr <| by constructor <;> simp @[simp] lemma pos_nilpotencyClass_iff [Nontrivial R] : 0 < nilpotencyClass x ↔ IsNilpotent x := by refine ⟨isNilpotent_of_pos_nilpotencyClass, fun hx ↦ Nat.pos_of_ne_zero fun hx' ↦ ?_⟩ replace hx := pow_nilpotencyClass hx rw [hx', pow_zero] at hx exact one_ne_zero hx lemma pow_pred_nilpotencyClass [Nontrivial R] (hx : IsNilpotent x) : x ^ (nilpotencyClass x - 1) ≠ 0 := (nilpotencyClass_eq_succ_iff.mp <| Nat.eq_add_of_sub_eq (pos_nilpotencyClass_iff.mpr hx) rfl).2 lemma eq_zero_of_nilpotencyClass_eq_one (hx : nilpotencyClass x = 1) : x = 0 := by have : IsNilpotent x := isNilpotent_of_pos_nilpotencyClass (hx ▸ Nat.one_pos) rw [← pow_nilpotencyClass this, hx, pow_one] @[simp] lemma nilpotencyClass_eq_one [Nontrivial R] : nilpotencyClass x = 1 ↔ x = 0 := ⟨eq_zero_of_nilpotencyClass_eq_one, fun hx ↦ hx ▸ nilpotencyClass_zero⟩ end MonoidWithZero end NilpotencyClass /-- A structure that has zero and pow is reduced if it has no nonzero nilpotent elements. -/ @[mk_iff] class IsReduced (R : Type*) [Zero R] [Pow R ℕ] : Prop where /-- A reduced structure has no nonzero nilpotent elements. -/ eq_zero : ∀ x : R, IsNilpotent x → x = 0 instance (priority := 900) isReduced_of_noZeroDivisors [MonoidWithZero R] [NoZeroDivisors R] : IsReduced R := ⟨fun _ ⟨_, hn⟩ => pow_eq_zero hn⟩ instance (priority := 900) isReduced_of_subsingleton [Zero R] [Pow R ℕ] [Subsingleton R] : IsReduced R := ⟨fun _ _ => Subsingleton.elim _ _⟩ theorem IsNilpotent.eq_zero [Zero R] [Pow R ℕ] [IsReduced R] (h : IsNilpotent x) : x = 0 := IsReduced.eq_zero x h @[simp] theorem isNilpotent_iff_eq_zero [MonoidWithZero R] [IsReduced R] : IsNilpotent x ↔ x = 0 := ⟨fun h => h.eq_zero, fun h => h.symm ▸ IsNilpotent.zero⟩ theorem isReduced_of_injective [MonoidWithZero R] [MonoidWithZero S] {F : Type*} [FunLike F R S] [MonoidWithZeroHomClass F R S] (f : F) (hf : Function.Injective f) [IsReduced S] : IsReduced R := by constructor intro x hx apply hf rw [map_zero] exact (hx.map f).eq_zero instance (ι) (R : ι → Type*) [∀ i, Zero (R i)] [∀ i, Pow (R i) ℕ] [∀ i, IsReduced (R i)] : IsReduced (∀ i, R i) where eq_zero _ := fun ⟨n, hn⟩ ↦ funext fun i ↦ IsReduced.eq_zero _ ⟨n, congr_fun hn i⟩ /-- An element `y` in a monoid is radical if for any element `x`, `y` divides `x` whenever it divides a power of `x`. -/ def IsRadical [Dvd R] [Pow R ℕ] (y : R) : Prop := ∀ (n : ℕ) (x), y ∣ x ^ n → y ∣ x theorem isRadical_iff_pow_one_lt [MonoidWithZero R] (k : ℕ) (hk : 1 < k) : IsRadical y ↔ ∀ x, y ∣ x ^ k → y ∣ x := ⟨(· k), k.pow_imp_self_of_one_lt hk _ fun _ _ h ↦ .inl (dvd_mul_of_dvd_left h _)⟩ namespace Commute section Semiring variable [Semiring R] theorem isNilpotent_mul_left (h_comm : Commute x y) (h : IsNilpotent x) : IsNilpotent (x * y) := by obtain ⟨n, hn⟩ := h use n rw [h_comm.mul_pow, hn, zero_mul] theorem isNilpotent_mul_right (h_comm : Commute x y) (h : IsNilpotent y) : IsNilpotent (x * y) := by rw [h_comm.eq] exact h_comm.symm.isNilpotent_mul_left h end Semiring end Commute
RingTheory\Nilpotent\Lemmas.lean
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.LinearAlgebra.Matrix.ToLin import Mathlib.LinearAlgebra.Quotient import Mathlib.RingTheory.Ideal.Maps import Mathlib.RingTheory.Nilpotent.Defs /-! # Nilpotent elements This file contains results about nilpotent elements that involve ring theory. -/ universe u v open Function Set variable {R S : Type*} {x y : R} theorem RingHom.ker_isRadical_iff_reduced_of_surjective {S F} [CommSemiring R] [CommRing S] [FunLike F R S] [RingHomClass F R S] {f : F} (hf : Function.Surjective f) : (RingHom.ker f).IsRadical ↔ IsReduced S := by simp_rw [isReduced_iff, hf.forall, IsNilpotent, ← map_pow, ← RingHom.mem_ker] rfl theorem isRadical_iff_span_singleton [CommSemiring R] : IsRadical y ↔ (Ideal.span ({y} : Set R)).IsRadical := by simp_rw [IsRadical, ← Ideal.mem_span_singleton] exact forall_swap.trans (forall_congr' fun r => exists_imp.symm) namespace Commute section Semiring variable [Semiring R] (h_comm : Commute x y) end Semiring end Commute section CommSemiring variable [CommSemiring R] {x y : R} /-- The nilradical of a commutative semiring is the ideal of nilpotent elements. -/ def nilradical (R : Type*) [CommSemiring R] : Ideal R := (0 : Ideal R).radical theorem mem_nilradical : x ∈ nilradical R ↔ IsNilpotent x := Iff.rfl theorem nilradical_eq_sInf (R : Type*) [CommSemiring R] : nilradical R = sInf { J : Ideal R | J.IsPrime } := (Ideal.radical_eq_sInf ⊥).trans <| by simp_rw [and_iff_right bot_le] theorem nilpotent_iff_mem_prime : IsNilpotent x ↔ ∀ J : Ideal R, J.IsPrime → x ∈ J := by rw [← mem_nilradical, nilradical_eq_sInf, Submodule.mem_sInf] rfl theorem nilradical_le_prime (J : Ideal R) [H : J.IsPrime] : nilradical R ≤ J := (nilradical_eq_sInf R).symm ▸ sInf_le H @[simp] theorem nilradical_eq_zero (R : Type*) [CommSemiring R] [IsReduced R] : nilradical R = 0 := Ideal.ext fun _ => isNilpotent_iff_eq_zero end CommSemiring namespace LinearMap variable (R) {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A] @[simp] theorem isNilpotent_mulLeft_iff (a : A) : IsNilpotent (mulLeft R a) ↔ IsNilpotent a := by constructor <;> rintro ⟨n, hn⟩ <;> use n <;> simp only [mulLeft_eq_zero_iff, pow_mulLeft] at hn ⊢ <;> exact hn @[simp] theorem isNilpotent_mulRight_iff (a : A) : IsNilpotent (mulRight R a) ↔ IsNilpotent a := by constructor <;> rintro ⟨n, hn⟩ <;> use n <;> simp only [mulRight_eq_zero_iff, pow_mulRight] at hn ⊢ <;> exact hn variable {R} variable {ι M : Type*} [Fintype ι] [DecidableEq ι] [AddCommMonoid M] [Module R M] @[simp] lemma isNilpotent_toMatrix_iff (b : Basis ι R M) (f : M →ₗ[R] M) : IsNilpotent (toMatrix b b f) ↔ IsNilpotent f := by refine exists_congr fun k ↦ ?_ rw [toMatrix_pow] exact (toMatrix b b).map_eq_zero_iff end LinearMap namespace Module.End lemma isNilpotent.restrict {R M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] {f : M →ₗ[R] M} {p : Submodule R M} (hf : MapsTo f p p) (hnil : IsNilpotent f) : IsNilpotent (f.restrict hf) := by obtain ⟨n, hn⟩ := hnil exact ⟨n, LinearMap.ext fun m ↦ by simp [LinearMap.pow_restrict n, LinearMap.restrict_apply, hn]⟩ variable {M : Type v} [Ring R] [AddCommGroup M] [Module R M] variable {f : Module.End R M} {p : Submodule R M} (hp : p ≤ p.comap f) theorem IsNilpotent.mapQ (hnp : IsNilpotent f) : IsNilpotent (p.mapQ p f hp) := by obtain ⟨k, hk⟩ := hnp use k simp [← p.mapQ_pow, hk] end Module.End
RingTheory\NonUnitalSubring\Basic.lean
/- Copyright (c) 2023 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Algebra.Group.Subgroup.Basic import Mathlib.GroupTheory.Subsemigroup.Center import Mathlib.RingTheory.NonUnitalSubsemiring.Basic /-! # `NonUnitalSubring`s Let `R` be a non-unital ring. This file defines the "bundled" non-unital subring type `NonUnitalSubring R`, a type whose terms correspond to non-unital subrings of `R`. This is the preferred way to talk about non-unital subrings in mathlib. We prove that non-unital subrings are a complete lattice, and that you can `map` (pushforward) and `comap` (pull back) them along ring homomorphisms. We define the `closure` construction from `Set R` to `NonUnitalSubring R`, sending a subset of `R` to the non-unital subring it generates, and prove that it is a Galois insertion. ## Main definitions Notation used here: `(R : Type u) [NonUnitalRing R] (S : Type u) [NonUnitalRing S] (f g : R →ₙ+* S)` `(A : NonUnitalSubring R) (B : NonUnitalSubring S) (s : Set R)` * `NonUnitalSubring R` : the type of non-unital subrings of a ring `R`. * `instance : CompleteLattice (NonUnitalSubring R)` : the complete lattice structure on the non-unital subrings. * `NonUnitalSubring.center` : the center of a non-unital ring `R`. * `NonUnitalSubring.closure` : non-unital subring closure of a set, i.e., the smallest non-unital subring that includes the set. * `NonUnitalSubring.gi` : `closure : Set M → NonUnitalSubring M` and coercion `coe : NonUnitalSubring M → Set M` form a `GaloisInsertion`. * `comap f B : NonUnitalSubring A` : the preimage of a non-unital subring `B` along the non-unital ring homomorphism `f` * `map f A : NonUnitalSubring B` : the image of a non-unital subring `A` along the non-unital ring homomorphism `f`. * `Prod A B : NonUnitalSubring (R × S)` : the product of non-unital subrings * `f.range : NonUnitalSubring B` : the range of the non-unital ring homomorphism `f`. * `eq_locus f g : NonUnitalSubring R` : given non-unital ring homomorphisms `f g : R →ₙ+* S`, the non-unital subring of `R` where `f x = g x` ## Implementation notes A non-unital subring is implemented as a `NonUnitalSubsemiring` which is also an additive subgroup. Lattice inclusion (e.g. `≤` and `⊓`) is used rather than set notation (`⊆` and `∩`), although `∈` is defined as membership of a non-unital subring's underlying set. ## Tags non-unital subring -/ universe u v w section Basic variable {R : Type u} {S : Type v} {T : Type w} [NonUnitalNonAssocRing R] section NonUnitalSubringClass /-- `NonUnitalSubringClass S R` states that `S` is a type of subsets `s ⊆ R` that are both a multiplicative submonoid and an additive subgroup. -/ class NonUnitalSubringClass (S : Type*) (R : Type u) [NonUnitalNonAssocRing R] [SetLike S R] extends NonUnitalSubsemiringClass S R, NegMemClass S R : Prop where -- See note [lower instance priority] instance (priority := 100) NonUnitalSubringClass.addSubgroupClass (S : Type*) (R : Type u) [SetLike S R] [NonUnitalNonAssocRing R] [h : NonUnitalSubringClass S R] : AddSubgroupClass S R := { h with } variable [SetLike S R] [hSR : NonUnitalSubringClass S R] (s : S) namespace NonUnitalSubringClass -- Prefer subclasses of `NonUnitalRing` over subclasses of `NonUnitalSubringClass`. /-- A non-unital subring of a non-unital ring inherits a non-unital ring structure -/ instance (priority := 75) toNonUnitalNonAssocRing : NonUnitalNonAssocRing s := Subtype.val_injective.nonUnitalNonAssocRing _ rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl -- Prefer subclasses of `NonUnitalRing` over subclasses of `NonUnitalSubringClass`. /-- A non-unital subring of a non-unital ring inherits a non-unital ring structure -/ instance (priority := 75) toNonUnitalRing {R : Type*} [NonUnitalRing R] [SetLike S R] [NonUnitalSubringClass S R] (s : S) : NonUnitalRing s := Subtype.val_injective.nonUnitalRing _ rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl -- Prefer subclasses of `NonUnitalRing` over subclasses of `NonUnitalSubringClass`. /-- A non-unital subring of a `NonUnitalCommRing` is a `NonUnitalCommRing`. -/ instance (priority := 75) toNonUnitalCommRing {R} [NonUnitalCommRing R] [SetLike S R] [NonUnitalSubringClass S R] : NonUnitalCommRing s := Subtype.val_injective.nonUnitalCommRing _ rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl /-- The natural non-unital ring hom from a non-unital subring of a non-unital ring `R` to `R`. -/ def subtype (s : S) : s →ₙ+* R := { NonUnitalSubsemiringClass.subtype s, AddSubgroupClass.subtype s with toFun := Subtype.val } @[simp] theorem coe_subtype : (subtype s : s → R) = Subtype.val := rfl end NonUnitalSubringClass end NonUnitalSubringClass variable [NonUnitalNonAssocRing S] [NonUnitalNonAssocRing T] /-- `NonUnitalSubring R` is the type of non-unital subrings of `R`. A non-unital subring of `R` is a subset `s` that is a multiplicative subsemigroup and an additive subgroup. Note in particular that it shares the same 0 as R. -/ structure NonUnitalSubring (R : Type u) [NonUnitalNonAssocRing R] extends NonUnitalSubsemiring R, AddSubgroup R /-- Reinterpret a `NonUnitalSubring` as a `NonUnitalSubsemiring`. -/ add_decl_doc NonUnitalSubring.toNonUnitalSubsemiring /-- Reinterpret a `NonUnitalSubring` as an `AddSubgroup`. -/ add_decl_doc NonUnitalSubring.toAddSubgroup namespace NonUnitalSubring /-- The underlying submonoid of a `NonUnitalSubring`. -/ def toSubsemigroup (s : NonUnitalSubring R) : Subsemigroup R := { s.toNonUnitalSubsemiring.toSubsemigroup with carrier := s.carrier } instance : SetLike (NonUnitalSubring R) R where coe s := s.carrier coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective h instance : NonUnitalSubringClass (NonUnitalSubring R) R where zero_mem s := s.zero_mem' add_mem {s} := s.add_mem' mul_mem {s} := s.mul_mem' neg_mem {s} := s.neg_mem' theorem mem_carrier {s : NonUnitalSubring R} {x : R} : x ∈ s.toNonUnitalSubsemiring ↔ x ∈ s := Iff.rfl @[simp] theorem mem_mk {S : NonUnitalSubsemiring R} {x : R} (h) : x ∈ (⟨S, h⟩ : NonUnitalSubring R) ↔ x ∈ S := Iff.rfl @[simp] theorem coe_set_mk (S : NonUnitalSubsemiring R) (h) : ((⟨S, h⟩ : NonUnitalSubring R) : Set R) = S := rfl @[simp] theorem mk_le_mk {S S' : NonUnitalSubsemiring R} (h h') : (⟨S, h⟩ : NonUnitalSubring R) ≤ (⟨S', h'⟩ : NonUnitalSubring R) ↔ S ≤ S' := Iff.rfl /-- Two non-unital subrings are equal if they have the same elements. -/ @[ext] theorem ext {S T : NonUnitalSubring R} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h /-- Copy of a non-unital subring with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (S : NonUnitalSubring R) (s : Set R) (hs : s = ↑S) : NonUnitalSubring R := { S.toNonUnitalSubsemiring.copy s hs with carrier := s neg_mem' := hs.symm ▸ S.neg_mem' } @[simp] theorem coe_copy (S : NonUnitalSubring R) (s : Set R) (hs : s = ↑S) : (S.copy s hs : Set R) = s := rfl theorem copy_eq (S : NonUnitalSubring R) (s : Set R) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs theorem toNonUnitalSubsemiring_injective : Function.Injective (toNonUnitalSubsemiring : NonUnitalSubring R → NonUnitalSubsemiring R) | _r, _s, h => ext (SetLike.ext_iff.mp h : _) @[mono] theorem toNonUnitalSubsemiring_strictMono : StrictMono (toNonUnitalSubsemiring : NonUnitalSubring R → NonUnitalSubsemiring R) := fun _ _ => id @[mono] theorem toNonUnitalSubsemiring_mono : Monotone (toNonUnitalSubsemiring : NonUnitalSubring R → NonUnitalSubsemiring R) := toNonUnitalSubsemiring_strictMono.monotone theorem toAddSubgroup_injective : Function.Injective (toAddSubgroup : NonUnitalSubring R → AddSubgroup R) | _r, _s, h => ext (SetLike.ext_iff.mp h : _) @[mono] theorem toAddSubgroup_strictMono : StrictMono (toAddSubgroup : NonUnitalSubring R → AddSubgroup R) := fun _ _ => id @[mono] theorem toAddSubgroup_mono : Monotone (toAddSubgroup : NonUnitalSubring R → AddSubgroup R) := toAddSubgroup_strictMono.monotone theorem toSubsemigroup_injective : Function.Injective (toSubsemigroup : NonUnitalSubring R → Subsemigroup R) | _r, _s, h => ext (SetLike.ext_iff.mp h : _) @[mono] theorem toSubsemigroup_strictMono : StrictMono (toSubsemigroup : NonUnitalSubring R → Subsemigroup R) := fun _ _ => id @[mono] theorem toSubsemigroup_mono : Monotone (toSubsemigroup : NonUnitalSubring R → Subsemigroup R) := toSubsemigroup_strictMono.monotone /-- Construct a `NonUnitalSubring R` from a set `s`, a subsemigroup `sm`, and an additive subgroup `sa` such that `x ∈ s ↔ x ∈ sm ↔ x ∈ sa`. -/ protected def mk' (s : Set R) (sm : Subsemigroup R) (sa : AddSubgroup R) (hm : ↑sm = s) (ha : ↑sa = s) : NonUnitalSubring R := { sm.copy s hm.symm, sa.copy s ha.symm with } @[simp] theorem coe_mk' {s : Set R} {sm : Subsemigroup R} (hm : ↑sm = s) {sa : AddSubgroup R} (ha : ↑sa = s) : (NonUnitalSubring.mk' s sm sa hm ha : Set R) = s := rfl @[simp] theorem mem_mk' {s : Set R} {sm : Subsemigroup R} (hm : ↑sm = s) {sa : AddSubgroup R} (ha : ↑sa = s) {x : R} : x ∈ NonUnitalSubring.mk' s sm sa hm ha ↔ x ∈ s := Iff.rfl @[simp] theorem mk'_toSubsemigroup {s : Set R} {sm : Subsemigroup R} (hm : ↑sm = s) {sa : AddSubgroup R} (ha : ↑sa = s) : (NonUnitalSubring.mk' s sm sa hm ha).toSubsemigroup = sm := SetLike.coe_injective hm.symm @[simp] theorem mk'_toAddSubgroup {s : Set R} {sm : Subsemigroup R} (hm : ↑sm = s) {sa : AddSubgroup R} (ha : ↑sa = s) : (NonUnitalSubring.mk' s sm sa hm ha).toAddSubgroup = sa := SetLike.coe_injective ha.symm end NonUnitalSubring namespace NonUnitalSubring variable (s : NonUnitalSubring R) /-- A non-unital subring contains the ring's 0. -/ protected theorem zero_mem : (0 : R) ∈ s := zero_mem _ /-- A non-unital subring is closed under multiplication. -/ protected theorem mul_mem {x y : R} : x ∈ s → y ∈ s → x * y ∈ s := mul_mem /-- A non-unital subring is closed under addition. -/ protected theorem add_mem {x y : R} : x ∈ s → y ∈ s → x + y ∈ s := add_mem /-- A non-unital subring is closed under negation. -/ protected theorem neg_mem {x : R} : x ∈ s → -x ∈ s := neg_mem /-- A non-unital subring is closed under subtraction -/ protected theorem sub_mem {x y : R} (hx : x ∈ s) (hy : y ∈ s) : x - y ∈ s := sub_mem hx hy /-- Sum of a list of elements in a non-unital subring is in the non-unital subring. -/ protected theorem list_sum_mem {l : List R} : (∀ x ∈ l, x ∈ s) → l.sum ∈ s := list_sum_mem /-- Sum of a multiset of elements in a `NonUnitalSubring` of a `NonUnitalRing` is in the `NonUnitalSubring`. -/ protected theorem multiset_sum_mem {R} [NonUnitalNonAssocRing R] (s : NonUnitalSubring R) (m : Multiset R) : (∀ a ∈ m, a ∈ s) → m.sum ∈ s := multiset_sum_mem _ /-- Sum of elements in a `NonUnitalSubring` of a `NonUnitalRing` indexed by a `Finset` is in the `NonUnitalSubring`. -/ protected theorem sum_mem {R : Type*} [NonUnitalNonAssocRing R] (s : NonUnitalSubring R) {ι : Type*} {t : Finset ι} {f : ι → R} (h : ∀ c ∈ t, f c ∈ s) : (∑ i ∈ t, f i) ∈ s := sum_mem h /-- A non-unital subring of a non-unital ring inherits a non-unital ring structure -/ instance toNonUnitalRing {R : Type*} [NonUnitalRing R] (s : NonUnitalSubring R) : NonUnitalRing s := Subtype.coe_injective.nonUnitalRing _ rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl protected theorem zsmul_mem {x : R} (hx : x ∈ s) (n : ℤ) : n • x ∈ s := zsmul_mem hx n @[simp, norm_cast] theorem val_add (x y : s) : (↑(x + y) : R) = ↑x + ↑y := rfl @[simp, norm_cast] theorem val_neg (x : s) : (↑(-x) : R) = -↑x := rfl @[simp, norm_cast] theorem val_mul (x y : s) : (↑(x * y) : R) = ↑x * ↑y := rfl @[simp, norm_cast] theorem val_zero : ((0 : s) : R) = 0 := rfl theorem coe_eq_zero_iff {x : s} : (x : R) = 0 ↔ x = 0 := by simp /-- A non-unital subring of a `NonUnitalCommRing` is a `NonUnitalCommRing`. -/ instance toNonUnitalCommRing {R} [NonUnitalCommRing R] (s : NonUnitalSubring R) : NonUnitalCommRing s := Subtype.coe_injective.nonUnitalCommRing _ rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl /-! ## Partial order -/ @[simp] theorem mem_toSubsemigroup {s : NonUnitalSubring R} {x : R} : x ∈ s.toSubsemigroup ↔ x ∈ s := Iff.rfl @[simp] theorem coe_toSubsemigroup (s : NonUnitalSubring R) : (s.toSubsemigroup : Set R) = s := rfl @[simp] theorem mem_toAddSubgroup {s : NonUnitalSubring R} {x : R} : x ∈ s.toAddSubgroup ↔ x ∈ s := Iff.rfl @[simp] theorem coe_toAddSubgroup (s : NonUnitalSubring R) : (s.toAddSubgroup : Set R) = s := rfl @[simp] theorem mem_toNonUnitalSubsemiring {s : NonUnitalSubring R} {x : R} : x ∈ s.toNonUnitalSubsemiring ↔ x ∈ s := Iff.rfl @[simp] theorem coe_toNonUnitalSubsemiring (s : NonUnitalSubring R) : (s.toNonUnitalSubsemiring : Set R) = s := rfl /-! ## top -/ /-- The non-unital subring `R` of the ring `R`. -/ instance : Top (NonUnitalSubring R) := ⟨{ (⊤ : Subsemigroup R), (⊤ : AddSubgroup R) with }⟩ @[simp] theorem mem_top (x : R) : x ∈ (⊤ : NonUnitalSubring R) := Set.mem_univ x @[simp] theorem coe_top : ((⊤ : NonUnitalSubring R) : Set R) = Set.univ := rfl /-- The ring equiv between the top element of `NonUnitalSubring R` and `R`. -/ @[simps!] def topEquiv : (⊤ : NonUnitalSubring R) ≃+* R := NonUnitalSubsemiring.topEquiv end NonUnitalSubring end Basic section Hom namespace NonUnitalSubring variable {F : Type w} {R : Type u} {S : Type v} {T : Type*} {SR : Type*} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [NonUnitalNonAssocRing T] [FunLike F R S] [NonUnitalRingHomClass F R S] (s : NonUnitalSubring R) /-! ## comap -/ /-- The preimage of a `NonUnitalSubring` along a ring homomorphism is a `NonUnitalSubring`. -/ def comap {F : Type w} {R : Type u} {S : Type v} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [FunLike F R S] [NonUnitalRingHomClass F R S] (f : F) (s : NonUnitalSubring S) : NonUnitalSubring R := { s.toSubsemigroup.comap (f : R →ₙ* S), s.toAddSubgroup.comap (f : R →+ S) with carrier := f ⁻¹' s.carrier } @[simp] theorem coe_comap (s : NonUnitalSubring S) (f : F) : (s.comap f : Set R) = f ⁻¹' s := rfl @[simp] theorem mem_comap {s : NonUnitalSubring S} {f : F} {x : R} : x ∈ s.comap f ↔ f x ∈ s := Iff.rfl theorem comap_comap (s : NonUnitalSubring T) (g : S →ₙ+* T) (f : R →ₙ+* S) : (s.comap g).comap f = s.comap (g.comp f) := rfl /-! ## map -/ /-- The image of a `NonUnitalSubring` along a ring homomorphism is a `NonUnitalSubring`. -/ def map {F : Type w} {R : Type u} {S : Type v} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [FunLike F R S] [NonUnitalRingHomClass F R S] (f : F) (s : NonUnitalSubring R) : NonUnitalSubring S := { s.toSubsemigroup.map (f : R →ₙ* S), s.toAddSubgroup.map (f : R →+ S) with carrier := f '' s.carrier } @[simp] theorem coe_map (f : F) (s : NonUnitalSubring R) : (s.map f : Set S) = f '' s := rfl @[simp] theorem mem_map {f : F} {s : NonUnitalSubring R} {y : S} : y ∈ s.map f ↔ ∃ x ∈ s, f x = y := Set.mem_image _ _ _ @[simp] theorem map_id : s.map (NonUnitalRingHom.id R) = s := SetLike.coe_injective <| Set.image_id _ theorem map_map (g : S →ₙ+* T) (f : R →ₙ+* S) : (s.map f).map g = s.map (g.comp f) := SetLike.coe_injective <| Set.image_image _ _ _ theorem map_le_iff_le_comap {f : F} {s : NonUnitalSubring R} {t : NonUnitalSubring S} : s.map f ≤ t ↔ s ≤ t.comap f := Set.image_subset_iff theorem gc_map_comap (f : F) : GaloisConnection (map f : NonUnitalSubring R → NonUnitalSubring S) (comap f) := fun _S _T => map_le_iff_le_comap /-- A `NonUnitalSubring` is isomorphic to its image under an injective function -/ noncomputable def equivMapOfInjective (f : F) (hf : Function.Injective (f : R → S)) : s ≃+* s.map f := { Equiv.Set.image f s hf with map_mul' := fun _ _ => Subtype.ext (map_mul f _ _) map_add' := fun _ _ => Subtype.ext (map_add f _ _) } @[simp] theorem coe_equivMapOfInjective_apply (f : F) (hf : Function.Injective f) (x : s) : (equivMapOfInjective s f hf x : S) = f x := rfl end NonUnitalSubring namespace NonUnitalRingHom variable {R : Type u} {S : Type v} {T : Type*} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [NonUnitalNonAssocRing T] (g : S →ₙ+* T) (f : R →ₙ+* S) /-! ## range -/ /-- The range of a ring homomorphism, as a `NonUnitalSubring` of the target. See Note [range copy pattern]. -/ def range {R : Type u} {S : Type v} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] (f : R →ₙ+* S) : NonUnitalSubring S := ((⊤ : NonUnitalSubring R).map f).copy (Set.range f) Set.image_univ.symm @[simp] theorem coe_range : (f.range : Set S) = Set.range f := rfl @[simp] theorem mem_range {f : R →ₙ+* S} {y : S} : y ∈ f.range ↔ ∃ x, f x = y := Iff.rfl theorem range_eq_map (f : R →ₙ+* S) : f.range = NonUnitalSubring.map f ⊤ := by ext; simp theorem mem_range_self (f : R →ₙ+* S) (x : R) : f x ∈ f.range := mem_range.mpr ⟨x, rfl⟩ theorem map_range : f.range.map g = (g.comp f).range := by simpa only [range_eq_map] using (⊤ : NonUnitalSubring R).map_map g f /-- The range of a ring homomorphism is a fintype, if the domain is a fintype. Note: this instance can form a diamond with `Subtype.fintype` in the presence of `Fintype S`. -/ instance fintypeRange [Fintype R] [DecidableEq S] (f : R →ₙ+* S) : Fintype (range f) := Set.fintypeRange f end NonUnitalRingHom namespace NonUnitalSubring section Order variable {F : Type w} {R : Type u} {S : Type v} {T : Type*} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [NonUnitalNonAssocRing T] [FunLike F R S] [NonUnitalRingHomClass F R S] (g : S →ₙ+* T) (f : R →ₙ+* S) /-! ## bot -/ instance : Bot (NonUnitalSubring R) := ⟨(0 : R →ₙ+* R).range⟩ instance : Inhabited (NonUnitalSubring R) := ⟨⊥⟩ theorem coe_bot : ((⊥ : NonUnitalSubring R) : Set R) = {0} := (NonUnitalRingHom.coe_range (0 : R →ₙ+* R)).trans (@Set.range_const R R _ 0) theorem mem_bot {x : R} : x ∈ (⊥ : NonUnitalSubring R) ↔ x = 0 := show x ∈ ((⊥ : NonUnitalSubring R) : Set R) ↔ x = 0 by rw [coe_bot, Set.mem_singleton_iff] /-! ## inf -/ /-- The inf of two `NonUnitalSubring`s is their intersection. -/ instance : Inf (NonUnitalSubring R) := ⟨fun s t => { s.toSubsemigroup ⊓ t.toSubsemigroup, s.toAddSubgroup ⊓ t.toAddSubgroup with carrier := s ∩ t }⟩ @[simp] theorem coe_inf (p p' : NonUnitalSubring R) : ((p ⊓ p' : NonUnitalSubring R) : Set R) = (p : Set R) ∩ p' := rfl @[simp] theorem mem_inf {p p' : NonUnitalSubring R} {x : R} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := Iff.rfl instance : InfSet (NonUnitalSubring R) := ⟨fun s => NonUnitalSubring.mk' (⋂ t ∈ s, ↑t) (⨅ t ∈ s, NonUnitalSubring.toSubsemigroup t) (⨅ t ∈ s, NonUnitalSubring.toAddSubgroup t) (by simp) (by simp)⟩ @[simp, norm_cast] theorem coe_sInf (S : Set (NonUnitalSubring R)) : ((sInf S : NonUnitalSubring R) : Set R) = ⋂ s ∈ S, ↑s := rfl theorem mem_sInf {S : Set (NonUnitalSubring R)} {x : R} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := Set.mem_iInter₂ @[simp, norm_cast] theorem coe_iInf {ι : Sort*} {S : ι → NonUnitalSubring R} : (↑(⨅ i, S i) : Set R) = ⋂ i, S i := by simp only [iInf, coe_sInf, Set.biInter_range] theorem mem_iInf {ι : Sort*} {S : ι → NonUnitalSubring R} {x : R} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by simp only [iInf, mem_sInf, Set.forall_mem_range] @[simp] theorem sInf_toSubsemigroup (s : Set (NonUnitalSubring R)) : (sInf s).toSubsemigroup = ⨅ t ∈ s, NonUnitalSubring.toSubsemigroup t := mk'_toSubsemigroup _ _ @[simp] theorem sInf_toAddSubgroup (s : Set (NonUnitalSubring R)) : (sInf s).toAddSubgroup = ⨅ t ∈ s, NonUnitalSubring.toAddSubgroup t := mk'_toAddSubgroup _ _ /-- `NonUnitalSubring`s of a ring form a complete lattice. -/ instance : CompleteLattice (NonUnitalSubring R) := { completeLatticeOfInf (NonUnitalSubring R) fun _s => IsGLB.of_image (@fun _ _ : NonUnitalSubring R => SetLike.coe_subset_coe) isGLB_biInf with bot := ⊥ bot_le := fun s _x hx => (mem_bot.mp hx).symm ▸ zero_mem s top := ⊤ le_top := fun _ _ _ => trivial inf := (· ⊓ ·) inf_le_left := fun _ _ _ => And.left inf_le_right := fun _ _ _ => And.right le_inf := fun _s _t₁ _t₂ h₁ h₂ _x hx => ⟨h₁ hx, h₂ hx⟩ } theorem eq_top_iff' (A : NonUnitalSubring R) : A = ⊤ ↔ ∀ x : R, x ∈ A := eq_top_iff.trans ⟨fun h m => h <| mem_top m, fun h m _ => h m⟩ end Order /-! ## Center of a ring -/ section Center variable {R : Type u} section NonUnitalNonAssocRing variable (R) [NonUnitalNonAssocRing R] /-- The center of a ring `R` is the set of elements that commute with everything in `R` -/ def center : NonUnitalSubring R := { NonUnitalSubsemiring.center R with neg_mem' := Set.neg_mem_center } theorem coe_center : ↑(center R) = Set.center R := rfl @[simp] theorem center_toNonUnitalSubsemiring : (center R).toNonUnitalSubsemiring = NonUnitalSubsemiring.center R := rfl /-- The center is commutative and associative. -/ instance center.instNonUnitalCommRing : NonUnitalCommRing (center R) := { NonUnitalSubsemiring.center.instNonUnitalCommSemiring R, inferInstanceAs <| NonUnitalNonAssocRing (center R) with } end NonUnitalNonAssocRing section NonUnitalRing variable [NonUnitalRing R] -- no instance diamond, unlike the unital version example : (center.instNonUnitalCommRing _).toNonUnitalRing = NonUnitalSubringClass.toNonUnitalRing (center R) := by with_reducible_and_instances rfl theorem mem_center_iff {z : R} : z ∈ center R ↔ ∀ g, g * z = z * g := Subsemigroup.mem_center_iff instance decidableMemCenter [DecidableEq R] [Fintype R] : DecidablePred (· ∈ center R) := fun _ => decidable_of_iff' _ mem_center_iff @[simp] theorem center_eq_top (R) [NonUnitalCommRing R] : center R = ⊤ := SetLike.coe_injective (Set.center_eq_univ R) end NonUnitalRing end Center /-! ## `NonUnitalSubring` closure of a subset -/ variable {F : Type w} {R : Type u} {S : Type v} {T : Type*} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [NonUnitalNonAssocRing T] [FunLike F R S] [NonUnitalRingHomClass F R S] (g : S →ₙ+* T) (f : R →ₙ+* S) /-- The `NonUnitalSubring` generated by a set. -/ def closure (s : Set R) : NonUnitalSubring R := sInf {S | s ⊆ S} theorem mem_closure {x : R} {s : Set R} : x ∈ closure s ↔ ∀ S : NonUnitalSubring R, s ⊆ S → x ∈ S := mem_sInf /-- The `NonUnitalSubring` generated by a set includes the set. -/ @[simp, aesop safe 20 apply (rule_sets := [SetLike])] theorem subset_closure {s : Set R} : s ⊆ closure s := fun _x hx => mem_closure.2 fun _S hS => hS hx theorem not_mem_of_not_mem_closure {s : Set R} {P : R} (hP : P ∉ closure s) : P ∉ s := fun h => hP (subset_closure h) /-- A `NonUnitalSubring` `t` includes `closure s` if and only if it includes `s`. -/ @[simp] theorem closure_le {s : Set R} {t : NonUnitalSubring R} : closure s ≤ t ↔ s ⊆ t := ⟨Set.Subset.trans subset_closure, fun h => sInf_le h⟩ /-- `NonUnitalSubring` closure of a set is monotone in its argument: if `s ⊆ t`, then `closure s ≤ closure t`. -/ theorem closure_mono ⦃s t : Set R⦄ (h : s ⊆ t) : closure s ≤ closure t := closure_le.2 <| Set.Subset.trans h subset_closure theorem closure_eq_of_le {s : Set R} {t : NonUnitalSubring R} (h₁ : s ⊆ t) (h₂ : t ≤ closure s) : closure s = t := le_antisymm (closure_le.2 h₁) h₂ /-- An induction principle for closure membership. If `p` holds for `0`, `1`, and all elements of `s`, and is preserved under addition, negation, and multiplication, then `p` holds for all elements of the closure of `s`. -/ @[elab_as_elim] theorem closure_induction {s : Set R} {p : R → Prop} {x} (h : x ∈ closure s) (mem : ∀ x ∈ s, p x) (zero : p 0) (add : ∀ x y, p x → p y → p (x + y)) (neg : ∀ x : R, p x → p (-x)) (mul : ∀ x y, p x → p y → p (x * y)) : p x := (@closure_le _ _ _ ⟨⟨⟨⟨p, add _ _⟩, zero⟩, mul _ _⟩, neg _⟩).2 mem h /-- The difference with `NonUnitalSubring.closure_induction` is that this acts on the subtype. -/ @[elab_as_elim] theorem closure_induction' {s : Set R} {p : closure s → Prop} (a : closure s) (mem : ∀ (x) (hx : x ∈ s), p ⟨x, subset_closure hx⟩) (zero : p 0) (add : ∀ x y, p x → p y → p (x + y)) (neg : ∀ x, p x → p (-x)) (mul : ∀ x y, p x → p y → p (x * y)) : p a := Subtype.recOn a fun b hb => by refine Exists.elim ?_ fun (hb : b ∈ closure s) (hc : p ⟨b, hb⟩) => hc refine closure_induction hb (fun x hx => ⟨subset_closure hx, mem x hx⟩) ⟨zero_mem (closure s), zero⟩ ?_ ?_ ?_ · rintro x y ⟨hx, hpx⟩ ⟨hy, hpy⟩ exact ⟨add_mem hx hy, add _ _ hpx hpy⟩ · rintro x ⟨hx, hpx⟩ exact ⟨neg_mem hx, neg _ hpx⟩ · rintro x y ⟨hx, hpx⟩ ⟨hy, hpy⟩ exact ⟨mul_mem hx hy, mul _ _ hpx hpy⟩ /-- An induction principle for closure membership, for predicates with two arguments. -/ @[elab_as_elim] theorem closure_induction₂ {s : Set R} {p : R → R → Prop} {a b : R} (ha : a ∈ closure s) (hb : b ∈ closure s) (Hs : ∀ x ∈ s, ∀ y ∈ s, p x y) (H0_left : ∀ x, p 0 x) (H0_right : ∀ x, p x 0) (Hneg_left : ∀ x y, p x y → p (-x) y) (Hneg_right : ∀ x y, p x y → p x (-y)) (Hadd_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ + x₂) y) (Hadd_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ + y₂)) (Hmul_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ * x₂) y) (Hmul_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ * y₂)) : p a b := by refine closure_induction hb ?_ (H0_right _) (Hadd_right a) (Hneg_right a) (Hmul_right a) refine closure_induction ha Hs (fun x _ => H0_left x) ?_ ?_ ?_ · exact fun x y H₁ H₂ z zs => Hadd_left x y z (H₁ z zs) (H₂ z zs) · exact fun x hx z zs => Hneg_left x z (hx z zs) · exact fun x y H₁ H₂ z zs => Hmul_left x y z (H₁ z zs) (H₂ z zs) theorem mem_closure_iff {s : Set R} {x} : x ∈ closure s ↔ x ∈ AddSubgroup.closure (Subsemigroup.closure s : Set R) := ⟨fun h => closure_induction h (fun x hx => AddSubgroup.subset_closure <| Subsemigroup.subset_closure hx) (AddSubgroup.zero_mem _) (fun x y hx hy => AddSubgroup.add_mem _ hx hy) (fun x hx => AddSubgroup.neg_mem _ hx) fun x y hx hy => AddSubgroup.closure_induction hy (fun q hq => AddSubgroup.closure_induction hx (fun p hp => AddSubgroup.subset_closure ((Subsemigroup.closure s).mul_mem hp hq)) (by rw [zero_mul q]; apply AddSubgroup.zero_mem _) (fun p₁ p₂ ihp₁ ihp₂ => by rw [add_mul p₁ p₂ q]; apply AddSubgroup.add_mem _ ihp₁ ihp₂) fun x hx => by have f : -x * q = -(x * q) := by simp rw [f]; apply AddSubgroup.neg_mem _ hx) (by rw [mul_zero x]; apply AddSubgroup.zero_mem _) (fun q₁ q₂ ihq₁ ihq₂ => by rw [mul_add x q₁ q₂]; apply AddSubgroup.add_mem _ ihq₁ ihq₂) fun z hz => by have f : x * -z = -(x * z) := by simp rw [f]; apply AddSubgroup.neg_mem _ hz, fun h => AddSubgroup.closure_induction h (fun x hx => Subsemigroup.closure_induction hx (fun x hx => subset_closure hx) fun x y hx hy => mul_mem hx hy) (zero_mem _) (fun x y hx hy => add_mem hx hy) fun x hx => neg_mem hx⟩ /-- If all elements of `s : Set A` commute pairwise, then `closure s` is a commutative ring. -/ def closureNonUnitalCommRingOfComm {R : Type u} [NonUnitalRing R] {s : Set R} (hcomm : ∀ a ∈ s, ∀ b ∈ s, a * b = b * a) : NonUnitalCommRing (closure s) := { (closure s).toNonUnitalRing with mul_comm := fun x y => by ext simp only [NonUnitalSubring.val_mul] refine closure_induction₂ x.prop y.prop hcomm (fun x => by simp only [mul_zero, zero_mul]) (fun x => by simp only [mul_zero, zero_mul]) (fun x y hxy => by simp only [mul_neg, neg_mul, hxy]) (fun x y hxy => by simp only [mul_neg, neg_mul, hxy]) (fun x₁ x₂ y h₁ h₂ => by simp only [add_mul, mul_add, h₁, h₂]) (fun x₁ x₂ y h₁ h₂ => by simp only [add_mul, mul_add, h₁, h₂]) (fun x₁ x₂ y h₁ h₂ => by rw [← mul_assoc, ← h₁, mul_assoc x₁ y x₂, ← h₂, mul_assoc]) fun x₁ x₂ y h₁ h₂ => by rw [← mul_assoc, h₁, mul_assoc, h₂, ← mul_assoc] } variable (R) /-- `closure` forms a Galois insertion with the coercion to set. -/ protected def gi : GaloisInsertion (@closure R _) SetLike.coe where choice s _ := closure s gc _s _t := closure_le le_l_u _s := subset_closure choice_eq _s _h := rfl variable {R} /-- Closure of a `NonUnitalSubring` `S` equals `S`. -/ theorem closure_eq (s : NonUnitalSubring R) : closure (s : Set R) = s := (NonUnitalSubring.gi R).l_u_eq s @[simp] theorem closure_empty : closure (∅ : Set R) = ⊥ := (NonUnitalSubring.gi R).gc.l_bot @[simp] theorem closure_univ : closure (Set.univ : Set R) = ⊤ := @coe_top R _ ▸ closure_eq ⊤ theorem closure_union (s t : Set R) : closure (s ∪ t) = closure s ⊔ closure t := (NonUnitalSubring.gi R).gc.l_sup theorem closure_iUnion {ι} (s : ι → Set R) : closure (⋃ i, s i) = ⨆ i, closure (s i) := (NonUnitalSubring.gi R).gc.l_iSup theorem closure_sUnion (s : Set (Set R)) : closure (⋃₀ s) = ⨆ t ∈ s, closure t := (NonUnitalSubring.gi R).gc.l_sSup theorem map_sup (s t : NonUnitalSubring R) (f : F) : (s ⊔ t).map f = s.map f ⊔ t.map f := (gc_map_comap f).l_sup theorem map_iSup {ι : Sort*} (f : F) (s : ι → NonUnitalSubring R) : (iSup s).map f = ⨆ i, (s i).map f := (gc_map_comap f).l_iSup theorem comap_inf (s t : NonUnitalSubring S) (f : F) : (s ⊓ t).comap f = s.comap f ⊓ t.comap f := (gc_map_comap f).u_inf theorem comap_iInf {ι : Sort*} (f : F) (s : ι → NonUnitalSubring S) : (iInf s).comap f = ⨅ i, (s i).comap f := (gc_map_comap f).u_iInf @[simp] theorem map_bot (f : R →ₙ+* S) : (⊥ : NonUnitalSubring R).map f = ⊥ := (gc_map_comap f).l_bot @[simp] theorem comap_top (f : R →ₙ+* S) : (⊤ : NonUnitalSubring S).comap f = ⊤ := (gc_map_comap f).u_top /-- Given `NonUnitalSubring`s `s`, `t` of rings `R`, `S` respectively, `s.prod t` is `s ×ˢ t` as a `NonUnitalSubring` of `R × S`. -/ def prod (s : NonUnitalSubring R) (t : NonUnitalSubring S) : NonUnitalSubring (R × S) := { s.toSubsemigroup.prod t.toSubsemigroup, s.toAddSubgroup.prod t.toAddSubgroup with carrier := s ×ˢ t } @[norm_cast] theorem coe_prod (s : NonUnitalSubring R) (t : NonUnitalSubring S) : (s.prod t : Set (R × S)) = (s : Set R) ×ˢ t := rfl theorem mem_prod {s : NonUnitalSubring R} {t : NonUnitalSubring S} {p : R × S} : p ∈ s.prod t ↔ p.1 ∈ s ∧ p.2 ∈ t := Iff.rfl @[mono] theorem prod_mono ⦃s₁ s₂ : NonUnitalSubring R⦄ (hs : s₁ ≤ s₂) ⦃t₁ t₂ : NonUnitalSubring S⦄ (ht : t₁ ≤ t₂) : s₁.prod t₁ ≤ s₂.prod t₂ := Set.prod_mono hs ht theorem prod_mono_right (s : NonUnitalSubring R) : Monotone fun t : NonUnitalSubring S => s.prod t := prod_mono (le_refl s) theorem prod_mono_left (t : NonUnitalSubring S) : Monotone fun s : NonUnitalSubring R => s.prod t := fun _s₁ _s₂ hs => prod_mono hs (le_refl t) theorem prod_top (s : NonUnitalSubring R) : s.prod (⊤ : NonUnitalSubring S) = s.comap (NonUnitalRingHom.fst R S) := ext fun x => by simp [mem_prod, MonoidHom.coe_fst] theorem top_prod (s : NonUnitalSubring S) : (⊤ : NonUnitalSubring R).prod s = s.comap (NonUnitalRingHom.snd R S) := ext fun x => by simp [mem_prod, MonoidHom.coe_snd] @[simp] theorem top_prod_top : (⊤ : NonUnitalSubring R).prod (⊤ : NonUnitalSubring S) = ⊤ := (top_prod _).trans <| comap_top _ /-- Product of `NonUnitalSubring`s is isomorphic to their product as rings. -/ def prodEquiv (s : NonUnitalSubring R) (t : NonUnitalSubring S) : s.prod t ≃+* s × t := { Equiv.Set.prod (s : Set R) (t : Set S) with map_mul' := fun _ _ => rfl map_add' := fun _ _ => rfl } /-- The underlying set of a non-empty directed Sup of `NonUnitalSubring`s is just a union of the `NonUnitalSubring`s. Note that this fails without the directedness assumption (the union of two `NonUnitalSubring`s is typically not a `NonUnitalSubring`) -/ theorem mem_iSup_of_directed {ι} [hι : Nonempty ι] {S : ι → NonUnitalSubring R} (hS : Directed (· ≤ ·) S) {x : R} : (x ∈ ⨆ i, S i) ↔ ∃ i, x ∈ S i := by refine ⟨?_, fun ⟨i, hi⟩ ↦ le_iSup S i hi⟩ let U : NonUnitalSubring R := NonUnitalSubring.mk' (⋃ i, (S i : Set R)) (⨆ i, (S i).toSubsemigroup) (⨆ i, (S i).toAddSubgroup) (Subsemigroup.coe_iSup_of_directed hS) (AddSubgroup.coe_iSup_of_directed hS) suffices ⨆ i, S i ≤ U by simpa [U] using @this x exact iSup_le fun i x hx ↦ Set.mem_iUnion.2 ⟨i, hx⟩ theorem coe_iSup_of_directed {ι} [Nonempty ι] {S : ι → NonUnitalSubring R} (hS : Directed (· ≤ ·) S) : ((⨆ i, S i : NonUnitalSubring R) : Set R) = ⋃ i, S i := Set.ext fun x ↦ by simp [mem_iSup_of_directed hS] theorem mem_sSup_of_directedOn {S : Set (NonUnitalSubring R)} (Sne : S.Nonempty) (hS : DirectedOn (· ≤ ·) S) {x : R} : x ∈ sSup S ↔ ∃ s ∈ S, x ∈ s := by haveI : Nonempty S := Sne.to_subtype simp only [sSup_eq_iSup', mem_iSup_of_directed hS.directed_val, SetCoe.exists, Subtype.coe_mk, exists_prop] theorem coe_sSup_of_directedOn {S : Set (NonUnitalSubring R)} (Sne : S.Nonempty) (hS : DirectedOn (· ≤ ·) S) : (↑(sSup S) : Set R) = ⋃ s ∈ S, ↑s := Set.ext fun x => by simp [mem_sSup_of_directedOn Sne hS] theorem mem_map_equiv {f : R ≃+* S} {K : NonUnitalSubring R} {x : S} : x ∈ K.map (f : R →ₙ+* S) ↔ f.symm x ∈ K := @Set.mem_image_equiv _ _ (K : Set R) f.toEquiv x theorem map_equiv_eq_comap_symm (f : R ≃+* S) (K : NonUnitalSubring R) : K.map (f : R →ₙ+* S) = K.comap f.symm := SetLike.coe_injective (f.toEquiv.image_eq_preimage K) theorem comap_equiv_eq_map_symm (f : R ≃+* S) (K : NonUnitalSubring S) : K.comap (f : R →ₙ+* S) = K.map f.symm := (map_equiv_eq_comap_symm f.symm K).symm end NonUnitalSubring namespace NonUnitalRingHom variable {F : Type w} {R : Type u} {S : Type v} {T : Type*} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [NonUnitalNonAssocRing T] [FunLike F R S] [NonUnitalRingHomClass F R S] (g : S →ₙ+* T) (f : R →ₙ+* S) {s : NonUnitalSubring R} open NonUnitalSubring /-- Restriction of a ring homomorphism to its range interpreted as a `NonUnitalSubring`. This is the bundled version of `Set.rangeFactorization`. -/ def rangeRestrict (f : R →ₙ+* S) : R →ₙ+* f.range := NonUnitalRingHom.codRestrict f f.range fun x => ⟨x, rfl⟩ @[simp] theorem coe_rangeRestrict (f : R →ₙ+* S) (x : R) : (f.rangeRestrict x : S) = f x := rfl theorem rangeRestrict_surjective (f : R →ₙ+* S) : Function.Surjective f.rangeRestrict := fun ⟨_y, hy⟩ => let ⟨x, hx⟩ := mem_range.mp hy ⟨x, Subtype.ext hx⟩ theorem range_top_iff_surjective {f : R →ₙ+* S} : f.range = (⊤ : NonUnitalSubring S) ↔ Function.Surjective f := SetLike.ext'_iff.trans <| Iff.trans (by rw [coe_range, coe_top]) Set.range_iff_surjective /-- The range of a surjective ring homomorphism is the whole of the codomain. -/ @[simp] theorem range_top_of_surjective (f : R →ₙ+* S) (hf : Function.Surjective f) : f.range = (⊤ : NonUnitalSubring S) := range_top_iff_surjective.2 hf /-- The `NonUnitalSubring` of elements `x : R` such that `f x = g x`, i.e., the equalizer of f and g as a `NonUnitalSubring` of R -/ def eqLocus (f g : R →ₙ+* S) : NonUnitalSubring R := { (f : R →ₙ* S).eqLocus g, (f : R →+ S).eqLocus g with carrier := {x | f x = g x} } @[simp] theorem eqLocus_same (f : R →ₙ+* S) : f.eqLocus f = ⊤ := SetLike.ext fun _ => eq_self_iff_true _ /-- If two ring homomorphisms are equal on a set, then they are equal on its `NonUnitalSubring` closure. -/ theorem eqOn_set_closure {f g : R →ₙ+* S} {s : Set R} (h : Set.EqOn f g s) : Set.EqOn f g (closure s) := show closure s ≤ f.eqLocus g from closure_le.2 h theorem eq_of_eqOn_set_top {f g : R →ₙ+* S} (h : Set.EqOn f g (⊤ : NonUnitalSubring R)) : f = g := ext fun _x => h trivial theorem eq_of_eqOn_set_dense {s : Set R} (hs : closure s = ⊤) {f g : R →ₙ+* S} (h : s.EqOn f g) : f = g := eq_of_eqOn_set_top <| hs ▸ eqOn_set_closure h theorem closure_preimage_le (f : R →ₙ+* S) (s : Set S) : closure (f ⁻¹' s) ≤ (closure s).comap f := closure_le.2 fun _x hx => SetLike.mem_coe.2 <| mem_comap.2 <| subset_closure hx /-- The image under a ring homomorphism of the `NonUnitalSubring` generated by a set equals the `NonUnitalSubring` generated by the image of the set. -/ theorem map_closure (f : R →ₙ+* S) (s : Set R) : (closure s).map f = closure (f '' s) := le_antisymm (map_le_iff_le_comap.2 <| le_trans (closure_mono <| Set.subset_preimage_image _ _) (closure_preimage_le _ _)) (closure_le.2 <| Set.image_subset _ subset_closure) end NonUnitalRingHom namespace NonUnitalSubring variable {F : Type w} {R : Type u} {S : Type v} {T : Type*} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [NonUnitalNonAssocRing T] [FunLike F R S] [NonUnitalRingHomClass F R S] (g : S →ₙ+* T) (f : R →ₙ+* S) {s : NonUnitalSubring R} open NonUnitalRingHom /-- The ring homomorphism associated to an inclusion of `NonUnitalSubring`s. -/ def inclusion {S T : NonUnitalSubring R} (h : S ≤ T) : S →ₙ+* T := NonUnitalRingHom.codRestrict (NonUnitalSubringClass.subtype S) _ fun x => h x.2 @[simp] theorem range_subtype (s : NonUnitalSubring R) : (NonUnitalSubringClass.subtype s).range = s := SetLike.coe_injective <| (coe_srange _).trans Subtype.range_coe theorem range_fst : NonUnitalRingHom.srange (fst R S) = ⊤ := NonUnitalSubsemiring.range_fst theorem range_snd : NonUnitalRingHom.srange (snd R S) = ⊤ := NonUnitalSubsemiring.range_snd end NonUnitalSubring namespace RingEquiv variable {F : Type w} {R : Type u} {S : Type v} {T : Type*} [NonUnitalRing R] [NonUnitalRing S] [NonUnitalRing T] [FunLike F R S] [NonUnitalRingHomClass F R S] (g : S →ₙ+* T) (f : R →ₙ+* S) {s t : NonUnitalSubring R} /-- Makes the identity isomorphism from a proof two `NonUnitalSubring`s of a multiplicative monoid are equal. -/ def nonUnitalSubringCongr (h : s = t) : s ≃+* t := { Equiv.setCongr <| congr_arg _ h with map_mul' := fun _ _ => rfl map_add' := fun _ _ => rfl } /-- Restrict a ring homomorphism with a left inverse to a ring isomorphism to its `RingHom.range`. -/ def ofLeftInverse' {g : S → R} {f : R →ₙ+* S} (h : Function.LeftInverse g f) : R ≃+* f.range := { f.rangeRestrict with toFun := fun x => f.rangeRestrict x invFun := fun x => (g ∘ NonUnitalSubringClass.subtype f.range) x left_inv := h right_inv := fun x => Subtype.ext <| let ⟨x', hx'⟩ := NonUnitalRingHom.mem_range.mp x.prop show f (g x) = x by rw [← hx', h x'] } @[simp] theorem ofLeftInverse'_apply {g : S → R} {f : R →ₙ+* S} (h : Function.LeftInverse g f) (x : R) : ↑(ofLeftInverse' h x) = f x := rfl @[simp] theorem ofLeftInverse'_symm_apply {g : S → R} {f : R →ₙ+* S} (h : Function.LeftInverse g f) (x : f.range) : (ofLeftInverse' h).symm x = g x := rfl end RingEquiv namespace NonUnitalSubring variable {F : Type w} {R : Type u} {S : Type v} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [FunLike F R S] [NonUnitalRingHomClass F R S] theorem closure_preimage_le (f : F) (s : Set S) : closure ((f : R → S) ⁻¹' s) ≤ (closure s).comap f := closure_le.2 fun _x hx => SetLike.mem_coe.2 <| mem_comap.2 <| subset_closure hx end NonUnitalSubring end Hom
RingTheory\NonUnitalSubsemiring\Basic.lean
/- Copyright (c) 2022 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.Algebra.Group.Subsemigroup.Membership import Mathlib.Algebra.GroupWithZero.Center import Mathlib.Algebra.Ring.Center import Mathlib.Algebra.Ring.Centralizer import Mathlib.Algebra.Ring.Equiv import Mathlib.Algebra.Ring.Prod import Mathlib.Algebra.Group.Hom.End import Mathlib.Data.Set.Finite import Mathlib.GroupTheory.Subsemigroup.Centralizer /-! # Bundled non-unital subsemirings We define bundled non-unital subsemirings and some standard constructions: `CompleteLattice` structure, `subtype` and `inclusion` ring homomorphisms, non-unital subsemiring `map`, `comap` and range (`srange`) of a `NonUnitalRingHom` etc. -/ universe u v w variable {R : Type u} {S : Type v} {T : Type w} [NonUnitalNonAssocSemiring R] (M : Subsemigroup R) /-- `NonUnitalSubsemiringClass S R` states that `S` is a type of subsets `s ⊆ R` that are both an additive submonoid and also a multiplicative subsemigroup. -/ class NonUnitalSubsemiringClass (S : Type*) (R : Type u) [NonUnitalNonAssocSemiring R] [SetLike S R] extends AddSubmonoidClass S R : Prop where mul_mem : ∀ {s : S} {a b : R}, a ∈ s → b ∈ s → a * b ∈ s -- See note [lower instance priority] instance (priority := 100) NonUnitalSubsemiringClass.mulMemClass (S : Type*) (R : Type u) [NonUnitalNonAssocSemiring R] [SetLike S R] [h : NonUnitalSubsemiringClass S R] : MulMemClass S R := { h with } namespace NonUnitalSubsemiringClass variable [SetLike S R] [NonUnitalSubsemiringClass S R] (s : S) open AddSubmonoidClass /- Prefer subclasses of `NonUnitalNonAssocSemiring` over subclasses of `NonUnitalSubsemiringClass`. -/ /-- A non-unital subsemiring of a `NonUnitalNonAssocSemiring` inherits a `NonUnitalNonAssocSemiring` structure -/ instance (priority := 75) toNonUnitalNonAssocSemiring : NonUnitalNonAssocSemiring s := Subtype.coe_injective.nonUnitalNonAssocSemiring (↑) rfl (by simp) (fun _ _ => rfl) fun _ _ => rfl instance noZeroDivisors [NoZeroDivisors R] : NoZeroDivisors s := Subtype.coe_injective.noZeroDivisors (↑) rfl fun _ _ => rfl /-- The natural non-unital ring hom from a non-unital subsemiring of a non-unital semiring `R` to `R`. -/ def subtype : s →ₙ+* R := { AddSubmonoidClass.subtype s, MulMemClass.subtype s with toFun := (↑) } @[simp] theorem coeSubtype : (subtype s : s → R) = ((↑) : s → R) := rfl /-- A non-unital subsemiring of a `NonUnitalSemiring` is a `NonUnitalSemiring`. -/ instance toNonUnitalSemiring {R} [NonUnitalSemiring R] [SetLike S R] [NonUnitalSubsemiringClass S R] : NonUnitalSemiring s := Subtype.coe_injective.nonUnitalSemiring (↑) rfl (by simp) (fun _ _ => rfl) fun _ _ => rfl /-- A non-unital subsemiring of a `NonUnitalCommSemiring` is a `NonUnitalCommSemiring`. -/ instance toNonUnitalCommSemiring {R} [NonUnitalCommSemiring R] [SetLike S R] [NonUnitalSubsemiringClass S R] : NonUnitalCommSemiring s := Subtype.coe_injective.nonUnitalCommSemiring (↑) rfl (by simp) (fun _ _ => rfl) fun _ _ => rfl /-! Note: currently, there are no ordered versions of non-unital rings. -/ end NonUnitalSubsemiringClass /-- A non-unital subsemiring of a non-unital semiring `R` is a subset `s` that is both an additive submonoid and a semigroup. -/ structure NonUnitalSubsemiring (R : Type u) [NonUnitalNonAssocSemiring R] extends AddSubmonoid R, Subsemigroup R /-- Reinterpret a `NonUnitalSubsemiring` as a `Subsemigroup`. -/ add_decl_doc NonUnitalSubsemiring.toSubsemigroup /-- Reinterpret a `NonUnitalSubsemiring` as an `AddSubmonoid`. -/ add_decl_doc NonUnitalSubsemiring.toAddSubmonoid namespace NonUnitalSubsemiring instance : SetLike (NonUnitalSubsemiring R) R where coe s := s.carrier coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h instance : NonUnitalSubsemiringClass (NonUnitalSubsemiring R) R where zero_mem {s} := AddSubmonoid.zero_mem' s.toAddSubmonoid add_mem {s} := AddSubsemigroup.add_mem' s.toAddSubmonoid.toAddSubsemigroup mul_mem {s} := mul_mem' s theorem mem_carrier {s : NonUnitalSubsemiring R} {x : R} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl /-- Two non-unital subsemirings are equal if they have the same elements. -/ @[ext] theorem ext {S T : NonUnitalSubsemiring R} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h /-- Copy of a non-unital subsemiring with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (S : NonUnitalSubsemiring R) (s : Set R) (hs : s = ↑S) : NonUnitalSubsemiring R := { S.toAddSubmonoid.copy s hs, S.toSubsemigroup.copy s hs with carrier := s } @[simp] theorem coe_copy (S : NonUnitalSubsemiring R) (s : Set R) (hs : s = ↑S) : (S.copy s hs : Set R) = s := rfl theorem copy_eq (S : NonUnitalSubsemiring R) (s : Set R) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs theorem toSubsemigroup_injective : Function.Injective (toSubsemigroup : NonUnitalSubsemiring R → Subsemigroup R) | _, _, h => ext (SetLike.ext_iff.mp h : _) @[mono] theorem toSubsemigroup_strictMono : StrictMono (toSubsemigroup : NonUnitalSubsemiring R → Subsemigroup R) := fun _ _ => id @[mono] theorem toSubsemigroup_mono : Monotone (toSubsemigroup : NonUnitalSubsemiring R → Subsemigroup R) := toSubsemigroup_strictMono.monotone theorem toAddSubmonoid_injective : Function.Injective (toAddSubmonoid : NonUnitalSubsemiring R → AddSubmonoid R) | _, _, h => ext (SetLike.ext_iff.mp h : _) @[mono] theorem toAddSubmonoid_strictMono : StrictMono (toAddSubmonoid : NonUnitalSubsemiring R → AddSubmonoid R) := fun _ _ => id @[mono] theorem toAddSubmonoid_mono : Monotone (toAddSubmonoid : NonUnitalSubsemiring R → AddSubmonoid R) := toAddSubmonoid_strictMono.monotone /-- Construct a `NonUnitalSubsemiring R` from a set `s`, a subsemigroup `sg`, and an additive submonoid `sa` such that `x ∈ s ↔ x ∈ sg ↔ x ∈ sa`. -/ protected def mk' (s : Set R) (sg : Subsemigroup R) (hg : ↑sg = s) (sa : AddSubmonoid R) (ha : ↑sa = s) : NonUnitalSubsemiring R where carrier := s zero_mem' := by subst ha; exact sa.zero_mem add_mem' := by subst ha; exact sa.add_mem mul_mem' := by subst hg; exact sg.mul_mem @[simp] theorem coe_mk' {s : Set R} {sg : Subsemigroup R} (hg : ↑sg = s) {sa : AddSubmonoid R} (ha : ↑sa = s) : (NonUnitalSubsemiring.mk' s sg hg sa ha : Set R) = s := rfl @[simp] theorem mem_mk' {s : Set R} {sg : Subsemigroup R} (hg : ↑sg = s) {sa : AddSubmonoid R} (ha : ↑sa = s) {x : R} : x ∈ NonUnitalSubsemiring.mk' s sg hg sa ha ↔ x ∈ s := Iff.rfl @[simp] theorem mk'_toSubsemigroup {s : Set R} {sg : Subsemigroup R} (hg : ↑sg = s) {sa : AddSubmonoid R} (ha : ↑sa = s) : (NonUnitalSubsemiring.mk' s sg hg sa ha).toSubsemigroup = sg := SetLike.coe_injective hg.symm @[simp] theorem mk'_toAddSubmonoid {s : Set R} {sg : Subsemigroup R} (hg : ↑sg = s) {sa : AddSubmonoid R} (ha : ↑sa = s) : (NonUnitalSubsemiring.mk' s sg hg sa ha).toAddSubmonoid = sa := SetLike.coe_injective ha.symm end NonUnitalSubsemiring namespace NonUnitalSubsemiring variable [NonUnitalNonAssocSemiring S] [NonUnitalNonAssocSemiring T] variable {F G : Type*} [FunLike F R S] [NonUnitalRingHomClass F R S] [FunLike G S T] [NonUnitalRingHomClass G S T] (s : NonUnitalSubsemiring R) @[simp, norm_cast] theorem coe_zero : ((0 : s) : R) = (0 : R) := rfl @[simp, norm_cast] theorem coe_add (x y : s) : ((x + y : s) : R) = (x + y : R) := rfl @[simp, norm_cast] theorem coe_mul (x y : s) : ((x * y : s) : R) = (x * y : R) := rfl /-! Note: currently, there are no ordered versions of non-unital rings. -/ @[simp high] theorem mem_toSubsemigroup {s : NonUnitalSubsemiring R} {x : R} : x ∈ s.toSubsemigroup ↔ x ∈ s := Iff.rfl @[simp high] theorem coe_toSubsemigroup (s : NonUnitalSubsemiring R) : (s.toSubsemigroup : Set R) = s := rfl @[simp] theorem mem_toAddSubmonoid {s : NonUnitalSubsemiring R} {x : R} : x ∈ s.toAddSubmonoid ↔ x ∈ s := Iff.rfl @[simp] theorem coe_toAddSubmonoid (s : NonUnitalSubsemiring R) : (s.toAddSubmonoid : Set R) = s := rfl /-- The non-unital subsemiring `R` of the non-unital semiring `R`. -/ instance : Top (NonUnitalSubsemiring R) := ⟨{ (⊤ : Subsemigroup R), (⊤ : AddSubmonoid R) with }⟩ @[simp] theorem mem_top (x : R) : x ∈ (⊤ : NonUnitalSubsemiring R) := Set.mem_univ x @[simp] theorem coe_top : ((⊤ : NonUnitalSubsemiring R) : Set R) = Set.univ := rfl /-- The ring equiv between the top element of `NonUnitalSubsemiring R` and `R`. -/ @[simps!] def topEquiv : (⊤ : NonUnitalSubsemiring R) ≃+* R := { Subsemigroup.topEquiv, AddSubmonoid.topEquiv with } /-- The preimage of a non-unital subsemiring along a non-unital ring homomorphism is a non-unital subsemiring. -/ def comap (f : F) (s : NonUnitalSubsemiring S) : NonUnitalSubsemiring R := { s.toSubsemigroup.comap (f : MulHom R S), s.toAddSubmonoid.comap (f : R →+ S) with carrier := f ⁻¹' s } @[simp] theorem coe_comap (s : NonUnitalSubsemiring S) (f : F) : (s.comap f : Set R) = f ⁻¹' s := rfl @[simp] theorem mem_comap {s : NonUnitalSubsemiring S} {f : F} {x : R} : x ∈ s.comap f ↔ f x ∈ s := Iff.rfl -- this has some nasty coercions, how to deal with it? theorem comap_comap (s : NonUnitalSubsemiring T) (g : G) (f : F) : ((s.comap g : NonUnitalSubsemiring S).comap f : NonUnitalSubsemiring R) = s.comap ((g : S →ₙ+* T).comp (f : R →ₙ+* S)) := rfl /-- The image of a non-unital subsemiring along a ring homomorphism is a non-unital subsemiring. -/ def map (f : F) (s : NonUnitalSubsemiring R) : NonUnitalSubsemiring S := { s.toSubsemigroup.map (f : R →ₙ* S), s.toAddSubmonoid.map (f : R →+ S) with carrier := f '' s } @[simp] theorem coe_map (f : F) (s : NonUnitalSubsemiring R) : (s.map f : Set S) = f '' s := rfl @[simp] theorem mem_map {f : F} {s : NonUnitalSubsemiring R} {y : S} : y ∈ s.map f ↔ ∃ x ∈ s, f x = y := Iff.rfl @[simp] theorem map_id : s.map (NonUnitalRingHom.id R) = s := SetLike.coe_injective <| Set.image_id _ -- unavoidable coercions? theorem map_map (g : G) (f : F) : (s.map (f : R →ₙ+* S)).map (g : S →ₙ+* T) = s.map ((g : S →ₙ+* T).comp (f : R →ₙ+* S)) := SetLike.coe_injective <| Set.image_image _ _ _ theorem map_le_iff_le_comap {f : F} {s : NonUnitalSubsemiring R} {t : NonUnitalSubsemiring S} : s.map f ≤ t ↔ s ≤ t.comap f := Set.image_subset_iff theorem gc_map_comap (f : F) : @GaloisConnection (NonUnitalSubsemiring R) (NonUnitalSubsemiring S) _ _ (map f) (comap f) := fun _ _ => map_le_iff_le_comap /-- A non-unital subsemiring is isomorphic to its image under an injective function -/ noncomputable def equivMapOfInjective (f : F) (hf : Function.Injective (f : R → S)) : s ≃+* s.map f := { Equiv.Set.image f s hf with map_mul' := fun _ _ => Subtype.ext (map_mul f _ _) map_add' := fun _ _ => Subtype.ext (map_add f _ _) } @[simp] theorem coe_equivMapOfInjective_apply (f : F) (hf : Function.Injective f) (x : s) : (equivMapOfInjective s f hf x : S) = f x := rfl end NonUnitalSubsemiring namespace NonUnitalRingHom open NonUnitalSubsemiring variable [NonUnitalNonAssocSemiring S] [NonUnitalNonAssocSemiring T] variable {F G : Type*} [FunLike F R S] [NonUnitalRingHomClass F R S] variable [FunLike G S T] [NonUnitalRingHomClass G S T] (f : F) (g : G) /-- The range of a non-unital ring homomorphism is a non-unital subsemiring. See note [range copy pattern]. -/ def srange : NonUnitalSubsemiring S := ((⊤ : NonUnitalSubsemiring R).map (f : R →ₙ+* S)).copy (Set.range f) Set.image_univ.symm @[simp] theorem coe_srange : (srange f : Set S) = Set.range f := rfl @[simp] theorem mem_srange {f : F} {y : S} : y ∈ srange f ↔ ∃ x, f x = y := Iff.rfl theorem srange_eq_map : srange f = (⊤ : NonUnitalSubsemiring R).map f := by ext simp theorem mem_srange_self (f : F) (x : R) : f x ∈ srange f := mem_srange.mpr ⟨x, rfl⟩ theorem map_srange (g : S →ₙ+* T) (f : R →ₙ+* S) : map g (srange f) = srange (g.comp f) := by simpa only [srange_eq_map] using (⊤ : NonUnitalSubsemiring R).map_map g f /-- The range of a morphism of non-unital semirings is finite if the domain is a finite. -/ instance finite_srange [Finite R] (f : F) : Finite (srange f : NonUnitalSubsemiring S) := (Set.finite_range f).to_subtype end NonUnitalRingHom namespace NonUnitalSubsemiring -- should we define this as the range of the zero homomorphism? instance : Bot (NonUnitalSubsemiring R) := ⟨{ carrier := {0} add_mem' := fun _ _ => by simp_all zero_mem' := Set.mem_singleton 0 mul_mem' := fun _ _ => by simp_all }⟩ instance : Inhabited (NonUnitalSubsemiring R) := ⟨⊥⟩ theorem coe_bot : ((⊥ : NonUnitalSubsemiring R) : Set R) = {0} := rfl theorem mem_bot {x : R} : x ∈ (⊥ : NonUnitalSubsemiring R) ↔ x = 0 := Set.mem_singleton_iff /-- The inf of two non-unital subsemirings is their intersection. -/ instance : Inf (NonUnitalSubsemiring R) := ⟨fun s t => { s.toSubsemigroup ⊓ t.toSubsemigroup, s.toAddSubmonoid ⊓ t.toAddSubmonoid with carrier := s ∩ t }⟩ @[simp] theorem coe_inf (p p' : NonUnitalSubsemiring R) : ((p ⊓ p' : NonUnitalSubsemiring R) : Set R) = (p : Set R) ∩ p' := rfl @[simp] theorem mem_inf {p p' : NonUnitalSubsemiring R} {x : R} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := Iff.rfl instance : InfSet (NonUnitalSubsemiring R) := ⟨fun s => NonUnitalSubsemiring.mk' (⋂ t ∈ s, ↑t) (⨅ t ∈ s, NonUnitalSubsemiring.toSubsemigroup t) (by simp) (⨅ t ∈ s, NonUnitalSubsemiring.toAddSubmonoid t) (by simp)⟩ @[simp, norm_cast] theorem coe_sInf (S : Set (NonUnitalSubsemiring R)) : ((sInf S : NonUnitalSubsemiring R) : Set R) = ⋂ s ∈ S, ↑s := rfl theorem mem_sInf {S : Set (NonUnitalSubsemiring R)} {x : R} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := Set.mem_iInter₂ @[simp] theorem sInf_toSubsemigroup (s : Set (NonUnitalSubsemiring R)) : (sInf s).toSubsemigroup = ⨅ t ∈ s, NonUnitalSubsemiring.toSubsemigroup t := mk'_toSubsemigroup _ _ @[simp] theorem sInf_toAddSubmonoid (s : Set (NonUnitalSubsemiring R)) : (sInf s).toAddSubmonoid = ⨅ t ∈ s, NonUnitalSubsemiring.toAddSubmonoid t := mk'_toAddSubmonoid _ _ /-- Non-unital subsemirings of a non-unital semiring form a complete lattice. -/ instance : CompleteLattice (NonUnitalSubsemiring R) := { completeLatticeOfInf (NonUnitalSubsemiring R) fun _ => IsGLB.of_image SetLike.coe_subset_coe isGLB_biInf with bot := ⊥ bot_le := fun s _ hx => (mem_bot.mp hx).symm ▸ zero_mem s top := ⊤ le_top := fun _ _ _ => trivial inf := (· ⊓ ·) inf_le_left := fun _ _ _ => And.left inf_le_right := fun _ _ _ => And.right le_inf := fun _ _ _ h₁ h₂ _ hx => ⟨h₁ hx, h₂ hx⟩ } theorem eq_top_iff' (A : NonUnitalSubsemiring R) : A = ⊤ ↔ ∀ x : R, x ∈ A := eq_top_iff.trans ⟨fun h m => h <| mem_top m, fun h m _ => h m⟩ section NonUnitalNonAssocSemiring variable (R) /-- The center of a semiring `R` is the set of elements that commute and associate with everything in `R` -/ def center : NonUnitalSubsemiring R := { Subsemigroup.center R with zero_mem' := Set.zero_mem_center add_mem' := Set.add_mem_center } theorem coe_center : ↑(center R) = Set.center R := rfl @[simp] theorem center_toSubsemigroup : (center R).toSubsemigroup = Subsemigroup.center R := rfl /-- The center is commutative and associative. -/ instance center.instNonUnitalCommSemiring : NonUnitalCommSemiring (center R) := { Subsemigroup.center.commSemigroup, NonUnitalSubsemiringClass.toNonUnitalNonAssocSemiring (center R) with } /-- A point-free means of proving membership in the center, for a non-associative ring. This can be helpful when working with types that have ext lemmas for `R →+ R`. -/ lemma _root_.Set.mem_center_iff_addMonoidHom (a : R) : a ∈ Set.center R ↔ AddMonoidHom.mulLeft a = .mulRight a ∧ AddMonoidHom.compr₂ .mul (.mulLeft a) = .comp .mul (.mulLeft a) ∧ AddMonoidHom.comp .mul (.mulRight a) = .compl₂ .mul (.mulLeft a) ∧ AddMonoidHom.compr₂ .mul (.mulRight a) = .compl₂ .mul (.mulRight a) := by rw [Set.mem_center_iff, isMulCentral_iff] simp [DFunLike.ext_iff] end NonUnitalNonAssocSemiring section NonUnitalSemiring -- no instance diamond, unlike the unital version example {R} [NonUnitalSemiring R] : (center.instNonUnitalCommSemiring _).toNonUnitalSemiring = NonUnitalSubsemiringClass.toNonUnitalSemiring (center R) := by with_reducible_and_instances rfl theorem mem_center_iff {R} [NonUnitalSemiring R] {z : R} : z ∈ center R ↔ ∀ g, g * z = z * g := by rw [← Semigroup.mem_center_iff] exact Iff.rfl instance decidableMemCenter {R} [NonUnitalSemiring R] [DecidableEq R] [Fintype R] : DecidablePred (· ∈ center R) := fun _ => decidable_of_iff' _ mem_center_iff @[simp] theorem center_eq_top (R) [NonUnitalCommSemiring R] : center R = ⊤ := SetLike.coe_injective (Set.center_eq_univ R) end NonUnitalSemiring section Centralizer /-- The centralizer of a set as non-unital subsemiring. -/ def centralizer {R} [NonUnitalSemiring R] (s : Set R) : NonUnitalSubsemiring R := { Subsemigroup.centralizer s with carrier := s.centralizer zero_mem' := Set.zero_mem_centralizer add_mem' := Set.add_mem_centralizer } @[simp, norm_cast] theorem coe_centralizer {R} [NonUnitalSemiring R] (s : Set R) : (centralizer s : Set R) = s.centralizer := rfl theorem centralizer_toSubsemigroup {R} [NonUnitalSemiring R] (s : Set R) : (centralizer s).toSubsemigroup = Subsemigroup.centralizer s := rfl theorem mem_centralizer_iff {R} [NonUnitalSemiring R] {s : Set R} {z : R} : z ∈ centralizer s ↔ ∀ g ∈ s, g * z = z * g := Iff.rfl theorem center_le_centralizer {R} [NonUnitalSemiring R] (s) : center R ≤ centralizer s := s.center_subset_centralizer theorem centralizer_le {R} [NonUnitalSemiring R] (s t : Set R) (h : s ⊆ t) : centralizer t ≤ centralizer s := Set.centralizer_subset h @[simp] theorem centralizer_eq_top_iff_subset {R} [NonUnitalSemiring R] {s : Set R} : centralizer s = ⊤ ↔ s ⊆ center R := SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset @[simp] theorem centralizer_univ {R} [NonUnitalSemiring R] : centralizer Set.univ = center R := SetLike.ext' (Set.centralizer_univ R) end Centralizer /-- The `NonUnitalSubsemiring` generated by a set. -/ def closure (s : Set R) : NonUnitalSubsemiring R := sInf { S | s ⊆ S } theorem mem_closure {x : R} {s : Set R} : x ∈ closure s ↔ ∀ S : NonUnitalSubsemiring R, s ⊆ S → x ∈ S := mem_sInf /-- The non-unital subsemiring generated by a set includes the set. -/ @[simp, aesop safe 20 apply (rule_sets := [SetLike])] theorem subset_closure {s : Set R} : s ⊆ closure s := fun _ hx => mem_closure.2 fun _ hS => hS hx theorem not_mem_of_not_mem_closure {s : Set R} {P : R} (hP : P ∉ closure s) : P ∉ s := fun h => hP (subset_closure h) /-- A non-unital subsemiring `S` includes `closure s` if and only if it includes `s`. -/ @[simp] theorem closure_le {s : Set R} {t : NonUnitalSubsemiring R} : closure s ≤ t ↔ s ⊆ t := ⟨Set.Subset.trans subset_closure, fun h => sInf_le h⟩ /-- Subsemiring closure of a set is monotone in its argument: if `s ⊆ t`, then `closure s ≤ closure t`. -/ theorem closure_mono ⦃s t : Set R⦄ (h : s ⊆ t) : closure s ≤ closure t := closure_le.2 <| Set.Subset.trans h subset_closure theorem closure_eq_of_le {s : Set R} {t : NonUnitalSubsemiring R} (h₁ : s ⊆ t) (h₂ : t ≤ closure s) : closure s = t := le_antisymm (closure_le.2 h₁) h₂ variable [NonUnitalNonAssocSemiring S] theorem mem_map_equiv {f : R ≃+* S} {K : NonUnitalSubsemiring R} {x : S} : x ∈ K.map (f : R →ₙ+* S) ↔ f.symm x ∈ K := by convert @Set.mem_image_equiv _ _ (↑K) f.toEquiv x theorem map_equiv_eq_comap_symm (f : R ≃+* S) (K : NonUnitalSubsemiring R) : K.map (f : R →ₙ+* S) = K.comap f.symm := SetLike.coe_injective (f.toEquiv.image_eq_preimage K) theorem comap_equiv_eq_map_symm (f : R ≃+* S) (K : NonUnitalSubsemiring S) : K.comap (f : R →ₙ+* S) = K.map f.symm := (map_equiv_eq_comap_symm f.symm K).symm end NonUnitalSubsemiring namespace Subsemigroup /-- The additive closure of a non-unital subsemigroup is a non-unital subsemiring. -/ def nonUnitalSubsemiringClosure (M : Subsemigroup R) : NonUnitalSubsemiring R := { AddSubmonoid.closure (M : Set R) with mul_mem' := MulMemClass.mul_mem_add_closure } theorem nonUnitalSubsemiringClosure_coe : (M.nonUnitalSubsemiringClosure : Set R) = AddSubmonoid.closure (M : Set R) := rfl theorem nonUnitalSubsemiringClosure_toAddSubmonoid : M.nonUnitalSubsemiringClosure.toAddSubmonoid = AddSubmonoid.closure (M : Set R) := rfl /-- The `NonUnitalSubsemiring` generated by a multiplicative subsemigroup coincides with the `NonUnitalSubsemiring.closure` of the subsemigroup itself . -/ theorem nonUnitalSubsemiringClosure_eq_closure : M.nonUnitalSubsemiringClosure = NonUnitalSubsemiring.closure (M : Set R) := by ext refine ⟨fun hx => ?_, fun hx => (NonUnitalSubsemiring.mem_closure.mp hx) M.nonUnitalSubsemiringClosure fun s sM => ?_⟩ <;> rintro - ⟨H1, rfl⟩ <;> rintro - ⟨H2, rfl⟩ · exact AddSubmonoid.mem_closure.mp hx H1.toAddSubmonoid H2 · exact H2 sM end Subsemigroup namespace NonUnitalSubsemiring @[simp] theorem closure_subsemigroup_closure (s : Set R) : closure ↑(Subsemigroup.closure s) = closure s := le_antisymm (closure_le.mpr fun _ hy => (Subsemigroup.mem_closure.mp hy) (closure s).toSubsemigroup subset_closure) (closure_mono Subsemigroup.subset_closure) /-- The elements of the non-unital subsemiring closure of `M` are exactly the elements of the additive closure of a multiplicative subsemigroup `M`. -/ theorem coe_closure_eq (s : Set R) : (closure s : Set R) = AddSubmonoid.closure (Subsemigroup.closure s : Set R) := by simp [← Subsemigroup.nonUnitalSubsemiringClosure_toAddSubmonoid, Subsemigroup.nonUnitalSubsemiringClosure_eq_closure] theorem mem_closure_iff {s : Set R} {x} : x ∈ closure s ↔ x ∈ AddSubmonoid.closure (Subsemigroup.closure s : Set R) := Set.ext_iff.mp (coe_closure_eq s) x @[simp] theorem closure_addSubmonoid_closure {s : Set R} : closure ↑(AddSubmonoid.closure s) = closure s := by ext x refine ⟨fun hx => ?_, fun hx => closure_mono AddSubmonoid.subset_closure hx⟩ rintro - ⟨H, rfl⟩ rintro - ⟨J, rfl⟩ refine (AddSubmonoid.mem_closure.mp (mem_closure_iff.mp hx)) H.toAddSubmonoid fun y hy => ?_ refine (Subsemigroup.mem_closure.mp hy) H.toSubsemigroup fun z hz => ?_ exact (AddSubmonoid.mem_closure.mp hz) H.toAddSubmonoid fun w hw => J hw /-- An induction principle for closure membership. If `p` holds for `0`, `1`, and all elements of `s`, and is preserved under addition and multiplication, then `p` holds for all elements of the closure of `s`. -/ @[elab_as_elim] theorem closure_induction {s : Set R} {p : R → Prop} {x} (h : x ∈ closure s) (mem : ∀ x ∈ s, p x) (zero : p 0) (add : ∀ x y, p x → p y → p (x + y)) (mul : ∀ x y, p x → p y → p (x * y)) : p x := (@closure_le _ _ _ ⟨⟨⟨p, fun {a b} => add a b⟩, zero⟩, fun {a b} => mul a b⟩).2 mem h /-- An induction principle for closure membership for predicates with two arguments. -/ @[elab_as_elim] theorem closure_induction₂ {s : Set R} {p : R → R → Prop} {x} {y : R} (hx : x ∈ closure s) (hy : y ∈ closure s) (Hs : ∀ x ∈ s, ∀ y ∈ s, p x y) (H0_left : ∀ x, p 0 x) (H0_right : ∀ x, p x 0) (Hadd_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ + x₂) y) (Hadd_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ + y₂)) (Hmul_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ * x₂) y) (Hmul_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ * y₂)) : p x y := closure_induction hx (fun x₁ x₁s => closure_induction hy (Hs x₁ x₁s) (H0_right x₁) (Hadd_right x₁) (Hmul_right x₁)) (H0_left y) (fun z z' => Hadd_left z z' y) fun z z' => Hmul_left z z' y variable (R) /-- `closure` forms a Galois insertion with the coercion to set. -/ protected def gi : GaloisInsertion (@closure R _) (↑) where choice s _ := closure s gc _ _ := closure_le le_l_u _ := subset_closure choice_eq _ _ := rfl variable {R} variable [NonUnitalNonAssocSemiring S] variable {F : Type*} [FunLike F R S] [NonUnitalRingHomClass F R S] /-- Closure of a non-unital subsemiring `S` equals `S`. -/ theorem closure_eq (s : NonUnitalSubsemiring R) : closure (s : Set R) = s := (NonUnitalSubsemiring.gi R).l_u_eq s @[simp] theorem closure_empty : closure (∅ : Set R) = ⊥ := (NonUnitalSubsemiring.gi R).gc.l_bot @[simp] theorem closure_univ : closure (Set.univ : Set R) = ⊤ := @coe_top R _ ▸ closure_eq ⊤ theorem closure_union (s t : Set R) : closure (s ∪ t) = closure s ⊔ closure t := (NonUnitalSubsemiring.gi R).gc.l_sup theorem closure_iUnion {ι} (s : ι → Set R) : closure (⋃ i, s i) = ⨆ i, closure (s i) := (NonUnitalSubsemiring.gi R).gc.l_iSup theorem closure_sUnion (s : Set (Set R)) : closure (⋃₀ s) = ⨆ t ∈ s, closure t := (NonUnitalSubsemiring.gi R).gc.l_sSup theorem map_sup (s t : NonUnitalSubsemiring R) (f : F) : (map f (s ⊔ t) : NonUnitalSubsemiring S) = map f s ⊔ map f t := @GaloisConnection.l_sup _ _ s t _ _ _ _ (gc_map_comap f) theorem map_iSup {ι : Sort*} (f : F) (s : ι → NonUnitalSubsemiring R) : (map f (iSup s) : NonUnitalSubsemiring S) = ⨆ i, map f (s i) := @GaloisConnection.l_iSup _ _ _ _ _ _ _ (gc_map_comap f) s theorem comap_inf (s t : NonUnitalSubsemiring S) (f : F) : (comap f (s ⊓ t) : NonUnitalSubsemiring R) = comap f s ⊓ comap f t := @GaloisConnection.u_inf _ _ s t _ _ _ _ (gc_map_comap f) theorem comap_iInf {ι : Sort*} (f : F) (s : ι → NonUnitalSubsemiring S) : (comap f (iInf s) : NonUnitalSubsemiring R) = ⨅ i, comap f (s i) := @GaloisConnection.u_iInf _ _ _ _ _ _ _ (gc_map_comap f) s @[simp] theorem map_bot (f : F) : map f (⊥ : NonUnitalSubsemiring R) = (⊥ : NonUnitalSubsemiring S) := (gc_map_comap f).l_bot @[simp] theorem comap_top (f : F) : comap f (⊤ : NonUnitalSubsemiring S) = (⊤ : NonUnitalSubsemiring R) := (gc_map_comap f).u_top /-- Given `NonUnitalSubsemiring`s `s`, `t` of semirings `R`, `S` respectively, `s.prod t` is `s × t` as a non-unital subsemiring of `R × S`. -/ def prod (s : NonUnitalSubsemiring R) (t : NonUnitalSubsemiring S) : NonUnitalSubsemiring (R × S) := { s.toSubsemigroup.prod t.toSubsemigroup, s.toAddSubmonoid.prod t.toAddSubmonoid with carrier := (s : Set R) ×ˢ (t : Set S) } @[norm_cast] theorem coe_prod (s : NonUnitalSubsemiring R) (t : NonUnitalSubsemiring S) : (s.prod t : Set (R × S)) = (s : Set R) ×ˢ (t : Set S) := rfl theorem mem_prod {s : NonUnitalSubsemiring R} {t : NonUnitalSubsemiring S} {p : R × S} : p ∈ s.prod t ↔ p.1 ∈ s ∧ p.2 ∈ t := Iff.rfl @[mono] theorem prod_mono ⦃s₁ s₂ : NonUnitalSubsemiring R⦄ (hs : s₁ ≤ s₂) ⦃t₁ t₂ : NonUnitalSubsemiring S⦄ (ht : t₁ ≤ t₂) : s₁.prod t₁ ≤ s₂.prod t₂ := Set.prod_mono hs ht theorem prod_mono_right (s : NonUnitalSubsemiring R) : Monotone fun t : NonUnitalSubsemiring S => s.prod t := prod_mono (le_refl s) theorem prod_mono_left (t : NonUnitalSubsemiring S) : Monotone fun s : NonUnitalSubsemiring R => s.prod t := fun _ _ hs => prod_mono hs (le_refl t) theorem prod_top (s : NonUnitalSubsemiring R) : s.prod (⊤ : NonUnitalSubsemiring S) = s.comap (NonUnitalRingHom.fst R S) := ext fun x => by simp [mem_prod, MonoidHom.coe_fst] theorem top_prod (s : NonUnitalSubsemiring S) : (⊤ : NonUnitalSubsemiring R).prod s = s.comap (NonUnitalRingHom.snd R S) := ext fun x => by simp [mem_prod, MonoidHom.coe_snd] @[simp] theorem top_prod_top : (⊤ : NonUnitalSubsemiring R).prod (⊤ : NonUnitalSubsemiring S) = ⊤ := (top_prod _).trans <| comap_top _ /-- Product of non-unital subsemirings is isomorphic to their product as semigroups. -/ def prodEquiv (s : NonUnitalSubsemiring R) (t : NonUnitalSubsemiring S) : s.prod t ≃+* s × t := { Equiv.Set.prod (s : Set R) (t : Set S) with map_mul' := fun _ _ => rfl map_add' := fun _ _ => rfl } theorem mem_iSup_of_directed {ι} [hι : Nonempty ι] {S : ι → NonUnitalSubsemiring R} (hS : Directed (· ≤ ·) S) {x : R} : (x ∈ ⨆ i, S i) ↔ ∃ i, x ∈ S i := by refine ⟨?_, fun ⟨i, hi⟩ ↦ le_iSup S i hi⟩ let U : NonUnitalSubsemiring R := NonUnitalSubsemiring.mk' (⋃ i, (S i : Set R)) (⨆ i, (S i).toSubsemigroup) (Subsemigroup.coe_iSup_of_directed hS) (⨆ i, (S i).toAddSubmonoid) (AddSubmonoid.coe_iSup_of_directed hS) -- Porting note `@this` doesn't work suffices H : ⨆ i, S i ≤ U by simpa [U] using @H x exact iSup_le fun i x hx => Set.mem_iUnion.2 ⟨i, hx⟩ theorem coe_iSup_of_directed {ι} [hι : Nonempty ι] {S : ι → NonUnitalSubsemiring R} (hS : Directed (· ≤ ·) S) : ((⨆ i, S i : NonUnitalSubsemiring R) : Set R) = ⋃ i, S i := Set.ext fun x ↦ by simp [mem_iSup_of_directed hS] theorem mem_sSup_of_directedOn {S : Set (NonUnitalSubsemiring R)} (Sne : S.Nonempty) (hS : DirectedOn (· ≤ ·) S) {x : R} : x ∈ sSup S ↔ ∃ s ∈ S, x ∈ s := by haveI : Nonempty S := Sne.to_subtype simp only [sSup_eq_iSup', mem_iSup_of_directed hS.directed_val, Subtype.exists, exists_prop] theorem coe_sSup_of_directedOn {S : Set (NonUnitalSubsemiring R)} (Sne : S.Nonempty) (hS : DirectedOn (· ≤ ·) S) : (↑(sSup S) : Set R) = ⋃ s ∈ S, ↑s := Set.ext fun x => by simp [mem_sSup_of_directedOn Sne hS] end NonUnitalSubsemiring namespace NonUnitalRingHom variable {F : Type*} [FunLike F R S] theorem eq_of_eqOn_stop {f g : F} (h : Set.EqOn (f : R → S) (g : R → S) (⊤ : NonUnitalSubsemiring R)) : f = g := DFunLike.ext _ _ fun _ => h trivial variable [NonUnitalNonAssocSemiring S] [NonUnitalNonAssocSemiring T] [NonUnitalRingHomClass F R S] {S' : Type*} [SetLike S' S] [NonUnitalSubsemiringClass S' S] {s : NonUnitalSubsemiring R} open NonUnitalSubsemiringClass NonUnitalSubsemiring /-- Restriction of a non-unital ring homomorphism to a non-unital subsemiring of the codomain. -/ def codRestrict (f : F) (s : S') (h : ∀ x, f x ∈ s) : R →ₙ+* s where toFun n := ⟨f n, h n⟩ map_mul' x y := Subtype.eq (map_mul f x y) map_add' x y := Subtype.eq (map_add f x y) map_zero' := Subtype.eq (map_zero f) /-- Restriction of a non-unital ring homomorphism to its range interpreted as a non-unital subsemiring. This is the bundled version of `Set.rangeFactorization`. -/ def srangeRestrict (f : F) : R →ₙ+* (srange f : NonUnitalSubsemiring S) := codRestrict f (srange f) (mem_srange_self f) @[simp] theorem coe_srangeRestrict (f : F) (x : R) : (srangeRestrict f x : S) = f x := rfl theorem srangeRestrict_surjective (f : F) : Function.Surjective (srangeRestrict f : R → (srange f : NonUnitalSubsemiring S)) := fun ⟨_, hy⟩ => let ⟨x, hx⟩ := mem_srange.mp hy ⟨x, Subtype.ext hx⟩ theorem srange_top_iff_surjective {f : F} : srange f = (⊤ : NonUnitalSubsemiring S) ↔ Function.Surjective (f : R → S) := SetLike.ext'_iff.trans <| Iff.trans (by rw [coe_srange, coe_top]) Set.range_iff_surjective /-- The range of a surjective non-unital ring homomorphism is the whole of the codomain. -/ @[simp] theorem srange_top_of_surjective (f : F) (hf : Function.Surjective (f : R → S)) : srange f = (⊤ : NonUnitalSubsemiring S) := srange_top_iff_surjective.2 hf /-- The non-unital subsemiring of elements `x : R` such that `f x = g x` -/ def eqSlocus (f g : F) : NonUnitalSubsemiring R := { (f : R →ₙ* S).eqLocus (g : R →ₙ* S), (f : R →+ S).eqLocusM g with carrier := { x | f x = g x } } /-- If two non-unital ring homomorphisms are equal on a set, then they are equal on its non-unital subsemiring closure. -/ theorem eqOn_sclosure {f g : F} {s : Set R} (h : Set.EqOn (f : R → S) (g : R → S) s) : Set.EqOn f g (closure s) := show closure s ≤ eqSlocus f g from closure_le.2 h theorem eq_of_eqOn_sdense {s : Set R} (hs : closure s = ⊤) {f g : F} (h : s.EqOn (f : R → S) (g : R → S)) : f = g := eq_of_eqOn_stop <| hs ▸ eqOn_sclosure h theorem sclosure_preimage_le (f : F) (s : Set S) : closure ((f : R → S) ⁻¹' s) ≤ (closure s).comap f := closure_le.2 fun _ hx => SetLike.mem_coe.2 <| mem_comap.2 <| subset_closure hx /-- The image under a ring homomorphism of the subsemiring generated by a set equals the subsemiring generated by the image of the set. -/ theorem map_sclosure (f : F) (s : Set R) : (closure s).map f = closure ((f : R → S) '' s) := le_antisymm (map_le_iff_le_comap.2 <| le_trans (closure_mono <| Set.subset_preimage_image _ _) (sclosure_preimage_le _ _)) (closure_le.2 <| Set.image_subset _ subset_closure) end NonUnitalRingHom namespace NonUnitalSubsemiring open NonUnitalRingHom NonUnitalSubsemiringClass /-- The non-unital ring homomorphism associated to an inclusion of non-unital subsemirings. -/ def inclusion {S T : NonUnitalSubsemiring R} (h : S ≤ T) : S →ₙ+* T := codRestrict (subtype S) _ fun x => h x.2 @[simp] theorem srange_subtype (s : NonUnitalSubsemiring R) : NonUnitalRingHom.srange (subtype s) = s := SetLike.coe_injective <| (coe_srange _).trans Subtype.range_coe variable [NonUnitalNonAssocSemiring S] @[simp] theorem range_fst : NonUnitalRingHom.srange (fst R S) = ⊤ := NonUnitalRingHom.srange_top_of_surjective (fst R S) Prod.fst_surjective @[simp] theorem range_snd : NonUnitalRingHom.srange (snd R S) = ⊤ := NonUnitalRingHom.srange_top_of_surjective (snd R S) <| Prod.snd_surjective end NonUnitalSubsemiring namespace RingEquiv open NonUnitalRingHom NonUnitalSubsemiringClass variable {s t : NonUnitalSubsemiring R} variable [NonUnitalNonAssocSemiring S] {F : Type*} [FunLike F R S] [NonUnitalRingHomClass F R S] /-- Makes the identity isomorphism from a proof two non-unital subsemirings of a multiplicative monoid are equal. -/ def nonUnitalSubsemiringCongr (h : s = t) : s ≃+* t := { Equiv.setCongr <| congr_arg _ h with map_mul' := fun _ _ => rfl map_add' := fun _ _ => rfl } /-- Restrict a non-unital ring homomorphism with a left inverse to a ring isomorphism to its `NonUnitalRingHom.srange`. -/ def sofLeftInverse' {g : S → R} {f : F} (h : Function.LeftInverse g f) : R ≃+* srange f := { srangeRestrict f with toFun := srangeRestrict f invFun := fun x => g (subtype (srange f) x) left_inv := h right_inv := fun x => Subtype.ext <| let ⟨x', hx'⟩ := NonUnitalRingHom.mem_srange.mp x.prop show f (g x) = x by rw [← hx', h x'] } @[simp] theorem sofLeftInverse'_apply {g : S → R} {f : F} (h : Function.LeftInverse g f) (x : R) : ↑(sofLeftInverse' h x) = f x := rfl @[simp] theorem sofLeftInverse'_symm_apply {g : S → R} {f : F} (h : Function.LeftInverse g f) (x : srange f) : (sofLeftInverse' h).symm x = g x := rfl /-- Given an equivalence `e : R ≃+* S` of non-unital semirings and a non-unital subsemiring `s` of `R`, `non_unital_subsemiring_map e s` is the induced equivalence between `s` and `s.map e` -/ @[simps!] def nonUnitalSubsemiringMap (e : R ≃+* S) (s : NonUnitalSubsemiring R) : s ≃+* NonUnitalSubsemiring.map e.toNonUnitalRingHom s := { e.toAddEquiv.addSubmonoidMap s.toAddSubmonoid, e.toMulEquiv.subsemigroupMap s.toSubsemigroup with } end RingEquiv
RingTheory\Norm\Basic.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.RingTheory.Norm.Defs import Mathlib.FieldTheory.PrimitiveElement import Mathlib.LinearAlgebra.Matrix.Charpoly.Minpoly import Mathlib.LinearAlgebra.Matrix.ToLinearEquiv import Mathlib.FieldTheory.IsAlgClosed.AlgebraicClosure import Mathlib.FieldTheory.Galois /-! # Norm for (finite) ring extensions Suppose we have an `R`-algebra `S` with a finite basis. For each `s : S`, the determinant of the linear map given by multiplying by `s` gives information about the roots of the minimal polynomial of `s` over `R`. ## Implementation notes Typically, the norm is defined specifically for finite field extensions. The current definition is as general as possible and the assumption that we have fields or that the extension is finite is added to the lemmas as needed. We only define the norm for left multiplication (`Algebra.leftMulMatrix`, i.e. `LinearMap.mulLeft`). For now, the definitions assume `S` is commutative, so the choice doesn't matter anyway. See also `Algebra.trace`, which is defined similarly as the trace of `Algebra.leftMulMatrix`. ## References * https://en.wikipedia.org/wiki/Field_norm -/ universe u v w variable {R S T : Type*} [CommRing R] [Ring S] variable [Algebra R S] variable {K L F : Type*} [Field K] [Field L] [Field F] variable [Algebra K L] [Algebra K F] variable {ι : Type w} open FiniteDimensional open LinearMap open Matrix Polynomial open scoped Matrix namespace Algebra section EqProdRoots /-- Given `pb : PowerBasis K S`, then the norm of `pb.gen` is `(-1) ^ pb.dim * coeff (minpoly K pb.gen) 0`. -/ theorem PowerBasis.norm_gen_eq_coeff_zero_minpoly (pb : PowerBasis R S) : norm R pb.gen = (-1) ^ pb.dim * coeff (minpoly R pb.gen) 0 := by rw [norm_eq_matrix_det pb.basis, det_eq_sign_charpoly_coeff, charpoly_leftMulMatrix, Fintype.card_fin] /-- Given `pb : PowerBasis R S`, then the norm of `pb.gen` is `((minpoly R pb.gen).aroots F).prod`. -/ theorem PowerBasis.norm_gen_eq_prod_roots [Algebra R F] (pb : PowerBasis R S) (hf : (minpoly R pb.gen).Splits (algebraMap R F)) : algebraMap R F (norm R pb.gen) = ((minpoly R pb.gen).aroots F).prod := by haveI := Module.nontrivial R F have := minpoly.monic pb.isIntegral_gen rw [PowerBasis.norm_gen_eq_coeff_zero_minpoly, ← pb.natDegree_minpoly, RingHom.map_mul, ← coeff_map, prod_roots_eq_coeff_zero_of_monic_of_split (this.map _) ((splits_id_iff_splits _).2 hf), this.natDegree_map, map_pow, ← mul_assoc, ← mul_pow] simp only [map_neg, _root_.map_one, neg_mul, neg_neg, one_pow, one_mul] end EqProdRoots section EqZeroIff variable [Finite ι] @[simp] theorem norm_zero [Nontrivial S] [Module.Free R S] [Module.Finite R S] : norm R (0 : S) = 0 := by nontriviality rw [norm_apply, coe_lmul_eq_mul, map_zero, LinearMap.det_zero' (Module.Free.chooseBasis R S)] @[simp] theorem norm_eq_zero_iff [IsDomain R] [IsDomain S] [Module.Free R S] [Module.Finite R S] {x : S} : norm R x = 0 ↔ x = 0 := by constructor on_goal 1 => let b := Module.Free.chooseBasis R S swap · rintro rfl; exact norm_zero · letI := Classical.decEq (Module.Free.ChooseBasisIndex R S) rw [norm_eq_matrix_det b, ← Matrix.exists_mulVec_eq_zero_iff] rintro ⟨v, v_ne, hv⟩ rw [← b.equivFun.apply_symm_apply v, b.equivFun_symm_apply, b.equivFun_apply, leftMulMatrix_mulVec_repr] at hv refine (mul_eq_zero.mp (b.ext_elem fun i => ?_)).resolve_right (show ∑ i, v i • b i ≠ 0 from ?_) · simpa only [LinearEquiv.map_zero, Pi.zero_apply] using congr_fun hv i · contrapose! v_ne with sum_eq apply b.equivFun.symm.injective rw [b.equivFun_symm_apply, sum_eq, LinearEquiv.map_zero] theorem norm_ne_zero_iff [IsDomain R] [IsDomain S] [Module.Free R S] [Module.Finite R S] {x : S} : norm R x ≠ 0 ↔ x ≠ 0 := not_iff_not.mpr norm_eq_zero_iff /-- This is `Algebra.norm_eq_zero_iff` composed with `Algebra.norm_apply`. -/ @[simp] theorem norm_eq_zero_iff' [IsDomain R] [IsDomain S] [Module.Free R S] [Module.Finite R S] {x : S} : LinearMap.det (LinearMap.mul R S x) = 0 ↔ x = 0 := norm_eq_zero_iff theorem norm_eq_zero_iff_of_basis [IsDomain R] [IsDomain S] (b : Basis ι R S) {x : S} : Algebra.norm R x = 0 ↔ x = 0 := by haveI : Module.Free R S := Module.Free.of_basis b haveI : Module.Finite R S := Module.Finite.of_basis b exact norm_eq_zero_iff theorem norm_ne_zero_iff_of_basis [IsDomain R] [IsDomain S] (b : Basis ι R S) {x : S} : Algebra.norm R x ≠ 0 ↔ x ≠ 0 := not_iff_not.mpr (norm_eq_zero_iff_of_basis b) end EqZeroIff open IntermediateField variable (K) theorem norm_eq_norm_adjoin [FiniteDimensional K L] [Algebra.IsSeparable K L] (x : L) : norm K x = norm K (AdjoinSimple.gen K x) ^ finrank K⟮x⟯ L := by letI := Algebra.isSeparable_tower_top_of_isSeparable K K⟮x⟯ L let pbL := Field.powerBasisOfFiniteOfSeparable K⟮x⟯ L let pbx := IntermediateField.adjoin.powerBasis (Algebra.IsSeparable.isIntegral K x) -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [← AdjoinSimple.algebraMap_gen K x, norm_eq_matrix_det (pbx.basis.smulTower pbL.basis) _, smulTower_leftMulMatrix_algebraMap, det_blockDiagonal, norm_eq_matrix_det pbx.basis] simp only [Finset.card_fin, Finset.prod_const] congr rw [← PowerBasis.finrank, AdjoinSimple.algebraMap_gen K x] variable {K} section IntermediateField theorem _root_.IntermediateField.AdjoinSimple.norm_gen_eq_one {x : L} (hx : ¬IsIntegral K x) : norm K (AdjoinSimple.gen K x) = 1 := by rw [norm_eq_one_of_not_exists_basis] contrapose! hx obtain ⟨s, ⟨b⟩⟩ := hx refine .of_mem_of_fg K⟮x⟯.toSubalgebra ?_ x ?_ · exact (Submodule.fg_iff_finiteDimensional _).mpr (of_fintype_basis b) · exact IntermediateField.subset_adjoin K _ (Set.mem_singleton x) theorem _root_.IntermediateField.AdjoinSimple.norm_gen_eq_prod_roots (x : L) (hf : (minpoly K x).Splits (algebraMap K F)) : (algebraMap K F) (norm K (AdjoinSimple.gen K x)) = ((minpoly K x).aroots F).prod := by have injKxL := (algebraMap K⟮x⟯ L).injective by_cases hx : IsIntegral K x; swap · simp [minpoly.eq_zero hx, IntermediateField.AdjoinSimple.norm_gen_eq_one hx, aroots_def] rw [← adjoin.powerBasis_gen hx, PowerBasis.norm_gen_eq_prod_roots] <;> rw [adjoin.powerBasis_gen hx, ← minpoly.algebraMap_eq injKxL] <;> try simp only [AdjoinSimple.algebraMap_gen _ _] exact hf end IntermediateField section EqProdEmbeddings open IntermediateField IntermediateField.AdjoinSimple Polynomial variable (F) (E : Type*) [Field E] [Algebra K E] theorem norm_eq_prod_embeddings_gen [Algebra R F] (pb : PowerBasis R S) (hE : (minpoly R pb.gen).Splits (algebraMap R F)) (hfx : IsSeparable R pb.gen) : algebraMap R F (norm R pb.gen) = (@Finset.univ _ (PowerBasis.AlgHom.fintype pb)).prod fun σ => σ pb.gen := by letI := Classical.decEq F rw [PowerBasis.norm_gen_eq_prod_roots pb hE] rw [@Fintype.prod_equiv (S →ₐ[R] F) _ _ (PowerBasis.AlgHom.fintype pb) _ _ pb.liftEquiv' (fun σ => σ pb.gen) (fun x => x) ?_] · rw [Finset.prod_mem_multiset, Finset.prod_eq_multiset_prod, Multiset.toFinset_val, Multiset.dedup_eq_self.mpr, Multiset.map_id] · exact nodup_roots hfx.map · intro x; rfl · intro σ; simp only [PowerBasis.liftEquiv'_apply_coe] theorem norm_eq_prod_roots [Algebra.IsSeparable K L] [FiniteDimensional K L] {x : L} (hF : (minpoly K x).Splits (algebraMap K F)) : algebraMap K F (norm K x) = ((minpoly K x).aroots F).prod ^ finrank K⟮x⟯ L := by rw [norm_eq_norm_adjoin K x, map_pow, IntermediateField.AdjoinSimple.norm_gen_eq_prod_roots _ hF] theorem prod_embeddings_eq_finrank_pow [Algebra L F] [IsScalarTower K L F] [IsAlgClosed E] [Algebra.IsSeparable K F] [FiniteDimensional K F] (pb : PowerBasis K L) : ∏ σ : F →ₐ[K] E, σ (algebraMap L F pb.gen) = ((@Finset.univ _ (PowerBasis.AlgHom.fintype pb)).prod fun σ : L →ₐ[K] E => σ pb.gen) ^ finrank L F := by haveI : FiniteDimensional L F := FiniteDimensional.right K L F haveI : Algebra.IsSeparable L F := Algebra.isSeparable_tower_top_of_isSeparable K L F letI : Fintype (L →ₐ[K] E) := PowerBasis.AlgHom.fintype pb rw [Fintype.prod_equiv algHomEquivSigma (fun σ : F →ₐ[K] E => _) fun σ => σ.1 pb.gen, ← Finset.univ_sigma_univ, Finset.prod_sigma, ← Finset.prod_pow] · refine Finset.prod_congr rfl fun σ _ => ?_ letI : Algebra L E := σ.toRingHom.toAlgebra simp_rw [Finset.prod_const] congr exact AlgHom.card L F E · intro σ simp only [algHomEquivSigma, Equiv.coe_fn_mk, AlgHom.restrictDomain, AlgHom.comp_apply, IsScalarTower.coe_toAlgHom'] variable (K) /-- For `L/K` a finite separable extension of fields and `E` an algebraically closed extension of `K`, the norm (down to `K`) of an element `x` of `L` is equal to the product of the images of `x` over all the `K`-embeddings `σ` of `L` into `E`. -/ theorem norm_eq_prod_embeddings [FiniteDimensional K L] [Algebra.IsSeparable K L] [IsAlgClosed E] (x : L) : algebraMap K E (norm K x) = ∏ σ : L →ₐ[K] E, σ x := by have hx := Algebra.IsSeparable.isIntegral K x rw [norm_eq_norm_adjoin K x, RingHom.map_pow, ← adjoin.powerBasis_gen hx, norm_eq_prod_embeddings_gen E (adjoin.powerBasis hx) (IsAlgClosed.splits_codomain _)] · exact (prod_embeddings_eq_finrank_pow L (L := K⟮x⟯) E (adjoin.powerBasis hx)).symm · haveI := Algebra.isSeparable_tower_bot_of_isSeparable K K⟮x⟯ L exact Algebra.IsSeparable.isSeparable K _ theorem norm_eq_prod_automorphisms [FiniteDimensional K L] [IsGalois K L] (x : L) : algebraMap K L (norm K x) = ∏ σ : L ≃ₐ[K] L, σ x := by apply NoZeroSMulDivisors.algebraMap_injective L (AlgebraicClosure L) rw [map_prod (algebraMap L (AlgebraicClosure L))] rw [← Fintype.prod_equiv (Normal.algHomEquivAut K (AlgebraicClosure L) L)] · rw [← norm_eq_prod_embeddings _ _ x, ← IsScalarTower.algebraMap_apply] · intro σ simp only [Normal.algHomEquivAut, AlgHom.restrictNormal', Equiv.coe_fn_mk, AlgEquiv.coe_ofBijective, AlgHom.restrictNormal_commutes, id.map_eq_id, RingHom.id_apply] theorem isIntegral_norm [Algebra R L] [Algebra R K] [IsScalarTower R K L] [Algebra.IsSeparable K L] [FiniteDimensional K L] {x : L} (hx : IsIntegral R x) : IsIntegral R (norm K x) := by have hx' : IsIntegral K x := hx.tower_top rw [← isIntegral_algebraMap_iff (algebraMap K (AlgebraicClosure L)).injective, norm_eq_prod_roots] · refine (IsIntegral.multiset_prod fun y hy => ?_).pow _ rw [mem_roots_map (minpoly.ne_zero hx')] at hy use minpoly R x, minpoly.monic hx rw [← aeval_def] at hy ⊢ exact minpoly.aeval_of_isScalarTower R x y hy · apply IsAlgClosed.splits_codomain lemma norm_eq_of_algEquiv [Ring T] [Algebra R T] (e : S ≃ₐ[R] T) (x) : Algebra.norm R (e x) = Algebra.norm R x := by simp_rw [Algebra.norm_apply, ← LinearMap.det_conj _ e.toLinearEquiv]; congr; ext; simp lemma norm_eq_of_ringEquiv {A B C : Type*} [CommRing A] [CommRing B] [Ring C] [Algebra A C] [Algebra B C] (e : A ≃+* B) (he : (algebraMap B C).comp e = algebraMap A C) (x : C) : e (Algebra.norm A x) = Algebra.norm B x := by classical by_cases h : ∃ s : Finset C, Nonempty (Basis s B C) · obtain ⟨s, ⟨b⟩⟩ := h letI : Algebra A B := RingHom.toAlgebra e letI : IsScalarTower A B C := IsScalarTower.of_algebraMap_eq' he.symm rw [Algebra.norm_eq_matrix_det b, Algebra.norm_eq_matrix_det (b.mapCoeffs e.symm (by simp [Algebra.smul_def, ← he])), e.map_det] congr ext i j simp [leftMulMatrix_apply, LinearMap.toMatrix_apply] rw [norm_eq_one_of_not_exists_basis _ h, norm_eq_one_of_not_exists_basis, _root_.map_one] intro ⟨s, ⟨b⟩⟩ exact h ⟨s, ⟨b.mapCoeffs e (by simp [Algebra.smul_def, ← he])⟩⟩ lemma norm_eq_of_equiv_equiv {A₁ B₁ A₂ B₂ : Type*} [CommRing A₁] [Ring B₁] [CommRing A₂] [Ring B₂] [Algebra A₁ B₁] [Algebra A₂ B₂] (e₁ : A₁ ≃+* A₂) (e₂ : B₁ ≃+* B₂) (he : RingHom.comp (algebraMap A₂ B₂) ↑e₁ = RingHom.comp ↑e₂ (algebraMap A₁ B₁)) (x) : Algebra.norm A₁ x = e₁.symm (Algebra.norm A₂ (e₂ x)) := by letI := (RingHom.comp (e₂ : B₁ →+* B₂) (algebraMap A₁ B₁)).toAlgebra' ?_ · let e' : B₁ ≃ₐ[A₁] B₂ := { e₂ with commutes' := fun _ ↦ rfl } rw [← Algebra.norm_eq_of_ringEquiv e₁ he, ← Algebra.norm_eq_of_algEquiv e'] simp [e'] intros c x apply e₂.symm.injective simp only [RingHom.coe_comp, RingHom.coe_coe, Function.comp_apply, _root_.map_mul, RingEquiv.symm_apply_apply, commutes] variable {F} (L) -- TODO. Generalize this proof to rings theorem norm_norm [Algebra L F] [IsScalarTower K L F] [Algebra.IsSeparable K F] (x : F) : norm K (norm L x) = norm K x := by by_cases hKF : FiniteDimensional K F · let A := AlgebraicClosure K apply (algebraMap K A).injective haveI : FiniteDimensional L F := FiniteDimensional.right K L F haveI : FiniteDimensional K L := FiniteDimensional.left K L F haveI : Algebra.IsSeparable K L := Algebra.isSeparable_tower_bot_of_isSeparable K L F haveI : Algebra.IsSeparable L F := Algebra.isSeparable_tower_top_of_isSeparable K L F letI : ∀ σ : L →ₐ[K] A, haveI := σ.toRingHom.toAlgebra Fintype (F →ₐ[L] A) := fun _ => inferInstance rw [norm_eq_prod_embeddings K A (_ : F), Fintype.prod_equiv algHomEquivSigma (fun σ : F →ₐ[K] A => σ x) (fun π : Σ f : L →ₐ[K] A, _ => (π.2 : F → A) x) fun _ => rfl] suffices ∀ σ : L →ₐ[K] A, haveI := σ.toRingHom.toAlgebra ∏ π : F →ₐ[L] A, π x = σ (norm L x) by simp_rw [← Finset.univ_sigma_univ, Finset.prod_sigma, this, norm_eq_prod_embeddings] intro σ letI : Algebra L A := σ.toRingHom.toAlgebra rw [← norm_eq_prod_embeddings L A (_ : F)] simp [RingHom.algebraMap_toAlgebra] · rw [norm_eq_one_of_not_module_finite hKF] by_cases hKL : FiniteDimensional K L · have hLF : ¬FiniteDimensional L F := by refine (mt ?_) hKF intro hKF exact FiniteDimensional.trans K L F rw [norm_eq_one_of_not_module_finite hLF, _root_.map_one] · rw [norm_eq_one_of_not_module_finite hKL] end EqProdEmbeddings end Algebra
RingTheory\Norm\Defs.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.LinearAlgebra.Determinant /-! # Norm for (finite) ring extensions Suppose we have an `R`-algebra `S` with a finite basis. For each `s : S`, the determinant of the linear map given by multiplying by `s` gives information about the roots of the minimal polynomial of `s` over `R`. ## Implementation notes Typically, the norm is defined specifically for finite field extensions. The current definition is as general as possible and the assumption that we have fields or that the extension is finite is added to the lemmas as needed. We only define the norm for left multiplication (`Algebra.leftMulMatrix`, i.e. `LinearMap.mulLeft`). For now, the definitions assume `S` is commutative, so the choice doesn't matter anyway. See also `Algebra.trace`, which is defined similarly as the trace of `Algebra.leftMulMatrix`. ## References * https://en.wikipedia.org/wiki/Field_norm -/ universe u v w variable {R S T : Type*} [CommRing R] [Ring S] variable [Algebra R S] variable {K L F : Type*} [Field K] [Field L] [Field F] variable [Algebra K L] [Algebra K F] variable {ι : Type w} open FiniteDimensional open LinearMap open Matrix Polynomial open scoped Matrix namespace Algebra variable (R) /-- The norm of an element `s` of an `R`-algebra is the determinant of `(*) s`. -/ noncomputable def norm : S →* R := LinearMap.det.comp (lmul R S).toRingHom.toMonoidHom theorem norm_apply (x : S) : norm R x = LinearMap.det (lmul R S x) := rfl theorem norm_eq_one_of_not_exists_basis (h : ¬∃ s : Finset S, Nonempty (Basis s R S)) (x : S) : norm R x = 1 := by rw [norm_apply, LinearMap.det]; split_ifs <;> trivial variable {R} theorem norm_eq_one_of_not_module_finite (h : ¬Module.Finite R S) (x : S) : norm R x = 1 := by refine norm_eq_one_of_not_exists_basis _ (mt ?_ h) _ rintro ⟨s, ⟨b⟩⟩ exact Module.Finite.of_basis b -- Can't be a `simp` lemma because it depends on a choice of basis theorem norm_eq_matrix_det [Fintype ι] [DecidableEq ι] (b : Basis ι R S) (s : S) : norm R s = Matrix.det (Algebra.leftMulMatrix b s) := by rw [norm_apply, ← LinearMap.det_toMatrix b, ← toMatrix_lmul_eq]; rfl /-- If `x` is in the base ring `K`, then the norm is `x ^ [L : K]`. -/ theorem norm_algebraMap_of_basis [Fintype ι] (b : Basis ι R S) (x : R) : norm R (algebraMap R S x) = x ^ Fintype.card ι := by haveI := Classical.decEq ι rw [norm_apply, ← det_toMatrix b, lmul_algebraMap] convert @det_diagonal _ _ _ _ _ fun _ : ι => x · ext (i j); rw [toMatrix_lsmul] · rw [Finset.prod_const, Finset.card_univ] /-- If `x` is in the base field `K`, then the norm is `x ^ [L : K]`. (If `L` is not finite-dimensional over `K`, then `norm = 1 = x ^ 0 = x ^ (finrank L K)`.) -/ @[simp] protected theorem norm_algebraMap {L : Type*} [Ring L] [Algebra K L] (x : K) : norm K (algebraMap K L x) = x ^ finrank K L := by by_cases H : ∃ s : Finset L, Nonempty (Basis s K L) · rw [norm_algebraMap_of_basis H.choose_spec.some, finrank_eq_card_basis H.choose_spec.some] · rw [norm_eq_one_of_not_exists_basis K H, finrank_eq_zero_of_not_exists_basis, pow_zero] rintro ⟨s, ⟨b⟩⟩ exact H ⟨s, ⟨b⟩⟩ end Algebra
RingTheory\OreLocalization\Basic.lean
/- Copyright (c) 2022 Jakob von Raumer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jakob von Raumer, Kevin Klinge, Andrew Yang -/ import Mathlib.Algebra.Group.Submonoid.DistribMulAction import Mathlib.RingTheory.OreLocalization.OreSet /-! # Localization over left Ore sets. This file defines the localization of a monoid over a left Ore set and proves its universal mapping property. ## Notations Introduces the notation `R[S⁻¹]` for the Ore localization of a monoid `R` at a right Ore subset `S`. Also defines a new heterogeneous division notation `r /ₒ s` for a numerator `r : R` and a denominator `s : S`. ## References * <https://ncatlab.org/nlab/show/Ore+localization> * [Zoran Škoda, *Noncommutative localization in noncommutative geometry*][skoda2006] ## Tags localization, Ore, non-commutative -/ universe u open OreLocalization namespace OreLocalization variable {R : Type*} [Monoid R] (S : Submonoid R) [OreSet S] (X) [MulAction R X] /-- The setoid on `R × S` used for the Ore localization. -/ @[to_additive AddOreLocalization.oreEqv "The setoid on `R × S` used for the Ore localization."] def oreEqv : Setoid (X × S) where r rs rs' := ∃ (u : S) (v : R), u • rs'.1 = v • rs.1 ∧ u * rs'.2 = v * rs.2 iseqv := by refine ⟨fun _ => ⟨1, 1, by simp⟩, ?_, ?_⟩ · rintro ⟨r, s⟩ ⟨r', s'⟩ ⟨u, v, hru, hsu⟩; dsimp only at * rcases oreCondition (s : R) s' with ⟨r₂, s₂, h₁⟩ rcases oreCondition r₂ u with ⟨r₃, s₃, h₂⟩ have : r₃ * v * s = s₃ * s₂ * s := by -- Porting note: the proof used `assoc_rw` rw [mul_assoc _ (s₂ : R), h₁, ← mul_assoc, h₂, mul_assoc, ← hsu, ← mul_assoc] rcases ore_right_cancel (r₃ * v) (s₃ * s₂) s this with ⟨w, hw⟩ refine ⟨w * (s₃ * s₂), w * (r₃ * u), ?_, ?_⟩ <;> simp only [Submonoid.coe_mul, Submonoid.smul_def, ← hw] · simp only [mul_smul, hru, ← Submonoid.smul_def] · simp only [mul_assoc, hsu] · rintro ⟨r₁, s₁⟩ ⟨r₂, s₂⟩ ⟨r₃, s₃⟩ ⟨u, v, hur₁, hs₁u⟩ ⟨u', v', hur₂, hs₂u⟩ rcases oreCondition v' u with ⟨r', s', h⟩; dsimp only at * refine ⟨s' * u', r' * v, ?_, ?_⟩ <;> simp only [Submonoid.smul_def, Submonoid.coe_mul, mul_smul, mul_assoc] at * · rw [hur₂, smul_smul, h, mul_smul, hur₁] · rw [hs₂u, ← mul_assoc, h, mul_assoc, hs₁u] end OreLocalization /-- The Ore localization of a monoid and a submonoid fulfilling the Ore condition. -/ @[to_additive AddOreLocalization "The Ore localization of an additive monoid and a submonoid fulfilling the Ore condition."] def OreLocalization {R : Type*} [Monoid R] (S : Submonoid R) [OreSet S] (X : Type*) [MulAction R X] := Quotient (OreLocalization.oreEqv S X) namespace OreLocalization section Monoid variable (R : Type*) [Monoid R] (S : Submonoid R) [OreSet S] @[inherit_doc OreLocalization] scoped syntax:1075 term noWs atomic("[" term "⁻¹" noWs "]") : term macro_rules | `($R[$S⁻¹]) => ``(OreLocalization $S $R) attribute [local instance] oreEqv variable {R S} variable {X} [MulAction R X] /-- The division in the Ore localization `X[S⁻¹]`, as a fraction of an element of `X` and `S`. -/ @[to_additive "The subtraction in the Ore localization, as a difference of an element of `X` and `S`."] def oreDiv (r : X) (s : S) : X[S⁻¹] := Quotient.mk' (r, s) @[inherit_doc] infixl:70 " /ₒ " => oreDiv @[inherit_doc] infixl:65 " -ₒ " => _root_.AddOreLocalization.oreSub @[to_additive (attr := elab_as_elim, cases_eliminator, induction_eliminator)] protected theorem ind {β : X[S⁻¹] → Prop} (c : ∀ (r : X) (s : S), β (r /ₒ s)) : ∀ q, β q := by apply Quotient.ind rintro ⟨r, s⟩ exact c r s @[to_additive] theorem oreDiv_eq_iff {r₁ r₂ : X} {s₁ s₂ : S} : r₁ /ₒ s₁ = r₂ /ₒ s₂ ↔ ∃ (u : S) (v : R), u • r₂ = v • r₁ ∧ u * s₂ = v * s₁ := Quotient.eq'' /-- A fraction `r /ₒ s` is equal to its expansion by an arbitrary factor `t` if `t * s ∈ S`. -/ @[to_additive "A difference `r -ₒ s` is equal to its expansion by an arbitrary translation `t` if `t + s ∈ S`."] protected theorem expand (r : X) (s : S) (t : R) (hst : t * (s : R) ∈ S) : r /ₒ s = t • r /ₒ ⟨t * s, hst⟩ := by apply Quotient.sound exact ⟨s, s * t, by rw [mul_smul, Submonoid.smul_def], by rw [← mul_assoc]⟩ /-- A fraction is equal to its expansion by a factor from `S`. -/ @[to_additive "A difference is equal to its expansion by a summand from `S`."] protected theorem expand' (r : X) (s s' : S) : r /ₒ s = s' • r /ₒ (s' * s) := OreLocalization.expand r s s' (by norm_cast; apply SetLike.coe_mem) /-- Fractions which differ by a factor of the numerator can be proven equal if those factors expand to equal elements of `R`. -/ @[to_additive "Differences whose minuends differ by a common summand can be proven equal if those summands expand to equal elements of `R`."] protected theorem eq_of_num_factor_eq {r r' r₁ r₂ : R} {s t : S} (h : t * r = t * r') : r₁ * r * r₂ /ₒ s = r₁ * r' * r₂ /ₒ s := by rcases oreCondition r₁ t with ⟨r₁', t', hr₁⟩ rw [OreLocalization.expand' _ s t', OreLocalization.expand' _ s t'] congr 1 -- Porting note (#11215): TODO: use `assoc_rw`? calc (t' : R) * (r₁ * r * r₂) = t' * r₁ * r * r₂ := by simp [← mul_assoc] _ = r₁' * t * r * r₂ := by rw [hr₁] _ = r₁' * (t * r) * r₂ := by simp [← mul_assoc] _ = r₁' * (t * r') * r₂ := by rw [h] _ = r₁' * t * r' * r₂ := by simp [← mul_assoc] _ = t' * r₁ * r' * r₂ := by rw [hr₁] _ = t' * (r₁ * r' * r₂) := by simp [← mul_assoc] /-- A function or predicate over `X` and `S` can be lifted to `X[S⁻¹]` if it is invariant under expansion on the left. -/ @[to_additive "A function or predicate over `X` and `S` can be lifted to the localizaton if it is invariant under expansion on the left."] def liftExpand {C : Sort*} (P : X → S → C) (hP : ∀ (r : X) (t : R) (s : S) (ht : t * s ∈ S), P r s = P (t • r) ⟨t * s, ht⟩) : X[S⁻¹] → C := Quotient.lift (fun p : X × S => P p.1 p.2) fun (r₁, s₁) (r₂, s₂) ⟨u, v, hr₂, hs₂⟩ => by dsimp at * have s₁vS : v * s₁ ∈ S := by rw [← hs₂, ← S.coe_mul] exact SetLike.coe_mem (u * s₂) replace hs₂ : u * s₂ = ⟨_, s₁vS⟩ := by ext; simp [hs₂] rw [hP r₁ v s₁ s₁vS, hP r₂ u s₂ (by norm_cast; rwa [hs₂]), ← hr₂] simp only [← hs₂]; rfl @[to_additive (attr := simp)] theorem liftExpand_of {C : Sort*} {P : X → S → C} {hP : ∀ (r : X) (t : R) (s : S) (ht : t * s ∈ S), P r s = P (t • r) ⟨t * s, ht⟩} (r : X) (s : S) : liftExpand P hP (r /ₒ s) = P r s := rfl /-- A version of `liftExpand` used to simultaneously lift functions with two arguments in `X[S⁻¹]`. -/ @[to_additive "A version of `liftExpand` used to simultaneously lift functions with two arguments"] def lift₂Expand {C : Sort*} (P : X → S → X → S → C) (hP : ∀ (r₁ : X) (t₁ : R) (s₁ : S) (ht₁ : t₁ * s₁ ∈ S) (r₂ : X) (t₂ : R) (s₂ : S) (ht₂ : t₂ * s₂ ∈ S), P r₁ s₁ r₂ s₂ = P (t₁ • r₁) ⟨t₁ * s₁, ht₁⟩ (t₂ • r₂) ⟨t₂ * s₂, ht₂⟩) : X[S⁻¹] → X[S⁻¹] → C := liftExpand (fun r₁ s₁ => liftExpand (P r₁ s₁) fun r₂ t₂ s₂ ht₂ => by have := hP r₁ 1 s₁ (by simp) r₂ t₂ s₂ ht₂ simp [this]) fun r₁ t₁ s₁ ht₁ => by ext x; induction' x with r₂ s₂ dsimp only rw [liftExpand_of, liftExpand_of, hP r₁ t₁ s₁ ht₁ r₂ 1 s₂ (by simp)]; simp @[to_additive (attr := simp)] theorem lift₂Expand_of {C : Sort*} {P : X → S → X → S → C} {hP : ∀ (r₁ : X) (t₁ : R) (s₁ : S) (ht₁ : t₁ * s₁ ∈ S) (r₂ : X) (t₂ : R) (s₂ : S) (ht₂ : t₂ * s₂ ∈ S), P r₁ s₁ r₂ s₂ = P (t₁ • r₁) ⟨t₁ * s₁, ht₁⟩ (t₂ • r₂) ⟨t₂ * s₂, ht₂⟩} (r₁ : X) (s₁ : S) (r₂ : X) (s₂ : S) : lift₂Expand P hP (r₁ /ₒ s₁) (r₂ /ₒ s₂) = P r₁ s₁ r₂ s₂ := rfl @[to_additive] private def smul' (r₁ : R) (s₁ : S) (r₂ : X) (s₂ : S) : X[S⁻¹] := oreNum r₁ s₂ • r₂ /ₒ (oreDenom r₁ s₂ * s₁) @[to_additive] private theorem smul'_char (r₁ : R) (r₂ : X) (s₁ s₂ : S) (u : S) (v : R) (huv : u * r₁ = v * s₂) : OreLocalization.smul' r₁ s₁ r₂ s₂ = v • r₂ /ₒ (u * s₁) := by -- Porting note: `assoc_rw` was not ported yet simp only [smul'] have h₀ := ore_eq r₁ s₂; set v₀ := oreNum r₁ s₂; set u₀ := oreDenom r₁ s₂ rcases oreCondition (u₀ : R) u with ⟨r₃, s₃, h₃⟩ have := calc r₃ * v * s₂ = r₃ * (u * r₁) := by rw [mul_assoc, ← huv] _ = s₃ * (u₀ * r₁) := by rw [← mul_assoc, ← mul_assoc, h₃] _ = s₃ * v₀ * s₂ := by rw [mul_assoc, h₀] rcases ore_right_cancel _ _ _ this with ⟨s₄, hs₄⟩ symm; rw [oreDiv_eq_iff] use s₄ * s₃ use s₄ * r₃ simp only [Submonoid.coe_mul, Submonoid.smul_def, smul_eq_mul] constructor · rw [smul_smul, mul_assoc (c := v₀), ← hs₄] simp only [smul_smul, mul_assoc] · rw [← mul_assoc (b := (u₀ : R)), mul_assoc (c := (u₀ : R)), h₃] simp only [mul_assoc] /-- The multiplication on the Ore localization of monoids. -/ @[to_additive] private def smul'' (r : R) (s : S) : X[S⁻¹] → X[S⁻¹] := liftExpand (smul' r s) fun r₁ r₂ s' hs => by rcases oreCondition r s' with ⟨r₁', s₁', h₁⟩ rw [smul'_char _ _ _ _ _ _ h₁] rcases oreCondition r ⟨_, hs⟩ with ⟨r₂', s₂', h₂⟩ rw [smul'_char _ _ _ _ _ _ h₂] rcases oreCondition (s₁' : R) (s₂') with ⟨r₃', s₃', h₃⟩ have : s₃' * r₁' * s' = (r₃' * r₂' * r₂) * s' := by rw [mul_assoc, ← h₁, ← mul_assoc, h₃, mul_assoc, h₂] simp [mul_assoc] rcases ore_right_cancel _ _ _ this with ⟨s₄', h₄⟩ have : (s₄' * r₃') * (s₂' * s) ∈ S := by rw [mul_assoc, ← mul_assoc r₃', ← h₃] exact (s₄' * (s₃' * s₁' * s)).2 rw [OreLocalization.expand' _ _ (s₄' * s₃'), OreLocalization.expand _ (s₂' * s) _ this] simp only [Submonoid.smul_def, Submonoid.coe_mul, smul_smul, mul_assoc, h₄] congr 1 ext; simp only [Submonoid.coe_mul, ← mul_assoc] rw [mul_assoc (s₄' : R), h₃, ← mul_assoc] /-- The scalar multiplication on the Ore localization of monoids. -/ @[to_additive (attr := irreducible) "the vector addition on the Ore localization of additive monoids."] protected def smul : R[S⁻¹] → X[S⁻¹] → X[S⁻¹] := liftExpand smul'' fun r₁ r₂ s hs => by ext x induction' x with x s₂ show OreLocalization.smul' r₁ s x s₂ = OreLocalization.smul' (r₂ * r₁) ⟨_, hs⟩ x s₂ rcases oreCondition r₁ s₂ with ⟨r₁', s₁', h₁⟩ rw [smul'_char _ _ _ _ _ _ h₁] rcases oreCondition (r₂ * r₁) s₂ with ⟨r₂', s₂', h₂⟩ rw [smul'_char _ _ _ _ _ _ h₂] rcases oreCondition (s₂' * r₂) (s₁') with ⟨r₃', s₃', h₃⟩ have : s₃' * r₂' * s₂ = r₃' * r₁' * s₂ := by rw [mul_assoc, ← h₂, ← mul_assoc _ r₂, ← mul_assoc, h₃, mul_assoc, h₁, mul_assoc] rcases ore_right_cancel _ _ _ this with ⟨s₄', h₄⟩ have : (s₄' * r₃') * (s₁' * s) ∈ S := by rw [← mul_assoc, mul_assoc _ r₃', ← h₃, ← mul_assoc, ← mul_assoc, mul_assoc] exact mul_mem (s₄' * s₃' * s₂').2 hs rw [OreLocalization.expand' (r₂' • x) _ (s₄' * s₃'), OreLocalization.expand _ _ _ this] simp only [Submonoid.smul_def, Submonoid.coe_mul, smul_smul, mul_assoc, h₄] congr 1 ext; simp only [Submonoid.coe_mul, ← mul_assoc] rw [mul_assoc _ r₃', ← h₃, ← mul_assoc, ← mul_assoc] @[to_additive] instance : SMul R[S⁻¹] X[S⁻¹] := ⟨OreLocalization.smul⟩ @[to_additive] instance : Mul R[S⁻¹] := ⟨OreLocalization.smul⟩ @[to_additive] theorem oreDiv_smul_oreDiv {r₁ : R} {r₂ : X} {s₁ s₂ : S} : (r₁ /ₒ s₁) • (r₂ /ₒ s₂) = oreNum r₁ s₂ • r₂ /ₒ (oreDenom r₁ s₂ * s₁) := by with_unfolding_all rfl @[to_additive] theorem oreDiv_mul_oreDiv {r₁ : R} {r₂ : R} {s₁ s₂ : S} : (r₁ /ₒ s₁) * (r₂ /ₒ s₂) = oreNum r₁ s₂ * r₂ /ₒ (oreDenom r₁ s₂ * s₁) := by with_unfolding_all rfl /-- A characterization lemma for the scalar multiplication on the Ore localization, allowing for a choice of Ore numerator and Ore denominator. -/ @[to_additive "A characterization lemma for the vector addition on the Ore localization, allowing for a choice of Ore minuend and Ore subtrahend."] theorem oreDiv_smul_char (r₁ : R) (r₂ : X) (s₁ s₂ : S) (r' : R) (s' : S) (huv : s' * r₁ = r' * s₂) : (r₁ /ₒ s₁) • (r₂ /ₒ s₂) = r' • r₂ /ₒ (s' * s₁) := by with_unfolding_all exact smul'_char r₁ r₂ s₁ s₂ s' r' huv /-- A characterization lemma for the multiplication on the Ore localization, allowing for a choice of Ore numerator and Ore denominator. -/ @[to_additive "A characterization lemma for the addition on the Ore localization, allowing for a choice of Ore minuend and Ore subtrahend."] theorem oreDiv_mul_char (r₁ r₂ : R) (s₁ s₂ : S) (r' : R) (s' : S) (huv : s' * r₁ = r' * s₂) : r₁ /ₒ s₁ * (r₂ /ₒ s₂) = r' * r₂ /ₒ (s' * s₁) := by with_unfolding_all exact smul'_char r₁ r₂ s₁ s₂ s' r' huv /-- Another characterization lemma for the scalar multiplication on the Ore localizaion delivering Ore witnesses and conditions bundled in a sigma type. -/ @[to_additive "Another characterization lemma for the vector addition on the Ore localizaion delivering Ore witnesses and conditions bundled in a sigma type."] def oreDivSMulChar' (r₁ : R) (r₂ : X) (s₁ s₂ : S) : Σ'r' : R, Σ's' : S, s' * r₁ = r' * s₂ ∧ (r₁ /ₒ s₁) • (r₂ /ₒ s₂) = r' • r₂ /ₒ (s' * s₁) := ⟨oreNum r₁ s₂, oreDenom r₁ s₂, ore_eq r₁ s₂, oreDiv_smul_oreDiv⟩ /-- Another characterization lemma for the multiplication on the Ore localizaion delivering Ore witnesses and conditions bundled in a sigma type. -/ @[to_additive "Another characterization lemma for the addition on the Ore localizaion delivering Ore witnesses and conditions bundled in a sigma type."] def oreDivMulChar' (r₁ r₂ : R) (s₁ s₂ : S) : Σ'r' : R, Σ's' : S, s' * r₁ = r' * s₂ ∧ r₁ /ₒ s₁ * (r₂ /ₒ s₂) = r' * r₂ /ₒ (s' * s₁) := ⟨oreNum r₁ s₂, oreDenom r₁ s₂, ore_eq r₁ s₂, oreDiv_mul_oreDiv⟩ /-- `1` in the localization, defined as `1 /ₒ 1`. -/ @[to_additive (attr := irreducible) "`0` in the additive localization, defined as `0 -ₒ 0`."] protected def one : R[S⁻¹] := 1 /ₒ 1 @[to_additive] instance : One R[S⁻¹] := ⟨OreLocalization.one⟩ @[to_additive] protected theorem one_def : (1 : R[S⁻¹]) = 1 /ₒ 1 := by with_unfolding_all rfl @[to_additive] instance : Inhabited R[S⁻¹] := ⟨1⟩ @[to_additive (attr := simp)] protected theorem div_eq_one' {r : R} (hr : r ∈ S) : r /ₒ ⟨r, hr⟩ = 1 := by rw [OreLocalization.one_def, oreDiv_eq_iff] exact ⟨⟨r, hr⟩, 1, by simp, by simp⟩ @[to_additive (attr := simp)] protected theorem div_eq_one {s : S} : (s : R) /ₒ s = 1 := OreLocalization.div_eq_one' _ @[to_additive] protected theorem one_smul (x : X[S⁻¹]) : (1 : R[S⁻¹]) • x = x := by induction' x with r s simp [OreLocalization.one_def, oreDiv_smul_char 1 r 1 s 1 s (by simp)] @[to_additive] protected theorem one_mul (x : R[S⁻¹]) : 1 * x = x := OreLocalization.one_smul x @[to_additive] protected theorem mul_one (x : R[S⁻¹]) : x * 1 = x := by induction' x with r s simp [OreLocalization.one_def, oreDiv_mul_char r (1 : R) s (1 : S) r 1 (by simp)] @[to_additive] protected theorem mul_smul (x y : R[S⁻¹]) (z : X[S⁻¹]) : (x * y) • z = x • y • z := by -- Porting note: `assoc_rw` was not ported yet induction' x with r₁ s₁ induction' y with r₂ s₂ induction' z with r₃ s₃ rcases oreDivMulChar' r₁ r₂ s₁ s₂ with ⟨ra, sa, ha, ha'⟩; rw [ha']; clear ha' rcases oreDivSMulChar' r₂ r₃ s₂ s₃ with ⟨rb, sb, hb, hb'⟩; rw [hb']; clear hb' rcases oreCondition ra sb with ⟨rc, sc, hc⟩ rw [oreDiv_smul_char (ra * r₂) r₃ (sa * s₁) s₃ (rc * rb) sc]; swap · rw [← mul_assoc _ ra, hc, mul_assoc, hb, ← mul_assoc] rw [← mul_assoc, mul_smul] symm; apply oreDiv_smul_char rw [Submonoid.coe_mul, Submonoid.coe_mul, ← mul_assoc, ← hc, mul_assoc _ ra, ← ha, mul_assoc] @[to_additive] protected theorem mul_assoc (x y z : R[S⁻¹]) : x * y * z = x * (y * z) := OreLocalization.mul_smul x y z /-- `npow` of `OreLocalization` -/ @[to_additive (attr := irreducible) "`nsmul` of `AddOreLocalization`"] protected def npow : ℕ → R[S⁻¹] → R[S⁻¹] := npowRec unseal OreLocalization.npow in @[to_additive] instance : Monoid R[S⁻¹] where one_mul := OreLocalization.one_mul mul_one := OreLocalization.mul_one mul_assoc := OreLocalization.mul_assoc npow := OreLocalization.npow @[to_additive] instance instMulActionOreLocalization : MulAction R[S⁻¹] X[S⁻¹] where one_smul := OreLocalization.one_smul mul_smul := OreLocalization.mul_smul @[to_additive] protected theorem mul_inv (s s' : S) : ((s : R) /ₒ s') * ((s' : R) /ₒ s) = 1 := by simp [oreDiv_mul_char (s : R) s' s' s 1 1 (by simp)] @[to_additive (attr := simp)] protected theorem one_div_smul {r : X} {s t : S} : ((1 : R) /ₒ t) • (r /ₒ s) = r /ₒ (s * t) := by simp [oreDiv_smul_char 1 r t s 1 s (by simp)] @[to_additive (attr := simp)] protected theorem one_div_mul {r : R} {s t : S} : (1 /ₒ t) * (r /ₒ s) = r /ₒ (s * t) := by simp [oreDiv_mul_char 1 r t s 1 s (by simp)] @[to_additive (attr := simp)] protected theorem smul_cancel {r : X} {s t : S} : ((s : R) /ₒ t) • (r /ₒ s) = r /ₒ t := by simp [oreDiv_smul_char s.1 r t s 1 1 (by simp)] @[to_additive (attr := simp)] protected theorem mul_cancel {r : R} {s t : S} : ((s : R) /ₒ t) * (r /ₒ s) = r /ₒ t := by simp [oreDiv_mul_char s.1 r t s 1 1 (by simp)] @[to_additive (attr := simp)] protected theorem smul_cancel' {r₁ : R} {r₂ : X} {s t : S} : ((r₁ * s) /ₒ t) • (r₂ /ₒ s) = (r₁ • r₂) /ₒ t := by simp [oreDiv_smul_char (r₁ * s) r₂ t s r₁ 1 (by simp)] @[to_additive (attr := simp)] protected theorem mul_cancel' {r₁ r₂ : R} {s t : S} : ((r₁ * s) /ₒ t) * (r₂ /ₒ s) = (r₁ * r₂) /ₒ t := by simp [oreDiv_mul_char (r₁ * s) r₂ t s r₁ 1 (by simp)] @[to_additive (attr := simp)] theorem smul_div_one {p : R} {r : X} {s : S} : (p /ₒ s) • (r /ₒ 1) = (p • r) /ₒ s := by simp [oreDiv_smul_char p r s 1 p 1 (by simp)] @[to_additive (attr := simp)] theorem mul_div_one {p r : R} {s : S} : (p /ₒ s) * (r /ₒ 1) = (p * r) /ₒ s := by --TODO use coercion r ↦ r /ₒ 1 simp [oreDiv_mul_char p r s 1 p 1 (by simp)] /-- The fraction `s /ₒ 1` as a unit in `R[S⁻¹]`, where `s : S`. -/ @[to_additive "The difference `s -ₒ 0` as a an additive unit."] def numeratorUnit (s : S) : Units R[S⁻¹] where val := (s : R) /ₒ 1 inv := (1 : R) /ₒ s val_inv := OreLocalization.mul_inv s 1 inv_val := OreLocalization.mul_inv 1 s /-- The multiplicative homomorphism from `R` to `R[S⁻¹]`, mapping `r : R` to the fraction `r /ₒ 1`. -/ @[to_additive "The additive homomorphism from `R` to `AddOreLocalization R S`, mapping `r : R` to the difference `r -ₒ 0`."] def numeratorHom : R →* R[S⁻¹] where toFun r := r /ₒ 1 map_one' := by with_unfolding_all rfl map_mul' _ _ := mul_div_one.symm @[to_additive] theorem numeratorHom_apply {r : R} : numeratorHom r = r /ₒ (1 : S) := rfl @[to_additive] theorem numerator_isUnit (s : S) : IsUnit (numeratorHom (s : R) : R[S⁻¹]) := ⟨numeratorUnit s, rfl⟩ section UMP variable {T : Type*} [Monoid T] variable (f : R →* T) (fS : S →* Units T) /-- The universal lift from a morphism `R →* T`, which maps elements of `S` to units of `T`, to a morphism `R[S⁻¹] →* T`. -/ @[to_additive "The universal lift from a morphism `R →+ T`, which maps elements of `S` to additive-units of `T`, to a morphism `AddOreLocalization R S →+ T`."] def universalMulHom (hf : ∀ s : S, f s = fS s) : R[S⁻¹] →* T where -- Porting note(#12129): additional beta reduction needed toFun x := x.liftExpand (fun r s => ((fS s)⁻¹ : Units T) * f r) fun r t s ht => by simp only [smul_eq_mul] have : (fS ⟨t * s, ht⟩ : T) = f t * fS s := by simp only [← hf, MonoidHom.map_mul] conv_rhs => rw [MonoidHom.map_mul, ← one_mul (f r), ← Units.val_one, ← mul_right_inv (fS s)] rw [Units.val_mul, mul_assoc, ← mul_assoc _ (fS s : T), ← this, ← mul_assoc] simp only [one_mul, Units.inv_mul] map_one' := by beta_reduce; rw [OreLocalization.one_def, liftExpand_of]; simp map_mul' x y := by -- Porting note: `simp only []` required, not just for beta reductions beta_reduce simp only [] -- TODO more! induction' x with r₁ s₁ induction' y with r₂ s₂ rcases oreDivMulChar' r₁ r₂ s₁ s₂ with ⟨ra, sa, ha, ha'⟩; rw [ha']; clear ha' rw [liftExpand_of, liftExpand_of, liftExpand_of, Units.inv_mul_eq_iff_eq_mul, map_mul, map_mul, Units.val_mul, mul_assoc, ← mul_assoc (fS s₁ : T), ← mul_assoc (fS s₁ : T), Units.mul_inv, one_mul, ← hf, ← mul_assoc, ← map_mul _ _ r₁, ha, map_mul, hf s₂, mul_assoc, ← mul_assoc (fS s₂ : T), (fS s₂).mul_inv, one_mul] variable (hf : ∀ s : S, f s = fS s) @[to_additive] theorem universalMulHom_apply {r : R} {s : S} : universalMulHom f fS hf (r /ₒ s) = ((fS s)⁻¹ : Units T) * f r := rfl @[to_additive] theorem universalMulHom_commutes {r : R} : universalMulHom f fS hf (numeratorHom r) = f r := by simp [numeratorHom_apply, universalMulHom_apply] /-- The universal morphism `universalMulHom` is unique. -/ @[to_additive "The universal morphism `universalAddHom` is unique."] theorem universalMulHom_unique (φ : R[S⁻¹] →* T) (huniv : ∀ r : R, φ (numeratorHom r) = f r) : φ = universalMulHom f fS hf := by ext x; induction' x with r s rw [universalMulHom_apply, ← huniv r, numeratorHom_apply, ← one_mul (φ (r /ₒ s)), ← Units.val_one, ← mul_left_inv (fS s), Units.val_mul, mul_assoc, ← hf, ← huniv, ← φ.map_mul, numeratorHom_apply, OreLocalization.mul_cancel] end UMP end Monoid section SMul variable {R R' M X : Type*} [Monoid M] {S : Submonoid M} [OreSet S] [MulAction M X] variable [SMul R X] [SMul R M] [IsScalarTower R M M] [IsScalarTower R M X] variable [SMul R' X] [SMul R' M] [IsScalarTower R' M M] [IsScalarTower R' M X] variable [SMul R R'] [IsScalarTower R R' M] /-- Scalar multiplication in a monoid localization. -/ @[to_additive (attr := irreducible) "Vector addition in an additive monoid localization."] protected def hsmul (c : R) : X[S⁻¹] → X[S⁻¹] := liftExpand (fun m s ↦ oreNum (c • 1) s • m /ₒ oreDenom (c • 1) s) (fun r t s ht ↦ by dsimp only rw [← mul_one (oreDenom (c • 1) s), ← oreDiv_smul_oreDiv, ← mul_one (oreDenom (c • 1) _), ← oreDiv_smul_oreDiv, ← OreLocalization.expand]) /- Warning: This gives an diamond on `SMul R[S⁻¹] M[S⁻¹][S⁻¹]`, but we will almost never localize at the same monoid twice. -/ /- Although the definition does not require `IsScalarTower R M X`, it does not make sense without it. -/ @[to_additive (attr := nolint unusedArguments)] instance [SMul R X] [SMul R M] [IsScalarTower R M X] [IsScalarTower R M M] : SMul R (X[S⁻¹]) where smul := OreLocalization.hsmul @[to_additive] theorem smul_oreDiv (r : R) (x : X) (s : S) : r • (x /ₒ s) = oreNum (r • 1) s • x /ₒ oreDenom (r • 1) s := by with_unfolding_all rfl @[to_additive (attr := simp)] theorem oreDiv_one_smul (r : M) (x : X[S⁻¹]) : (r /ₒ (1 : S)) • x = r • x := by induction' x using OreLocalization.ind with r' s rw [smul_oreDiv, oreDiv_smul_oreDiv, mul_one, smul_eq_mul, mul_one] @[to_additive] theorem smul_one_smul (r : R) (x : X[S⁻¹]) : (r • 1 : M) • x = r • x := by induction' x using OreLocalization.ind with r' s simp only [smul_oreDiv, smul_eq_mul, mul_one] @[to_additive] theorem smul_one_oreDiv_one_smul (r : R) (x : X[S⁻¹]) : ((r • 1 : M) /ₒ (1 : S)) • x = r • x := by rw [oreDiv_one_smul, smul_one_smul] @[to_additive] instance : IsScalarTower R R' X[S⁻¹] where smul_assoc r m x := by rw [← smul_one_oreDiv_one_smul, ← smul_one_oreDiv_one_smul, ← smul_one_oreDiv_one_smul, ← mul_smul, mul_div_one] simp only [smul_eq_mul, mul_one, smul_mul_assoc, smul_assoc, one_mul] @[to_additive] instance [SMulCommClass R R' M] : SMulCommClass R R' X[S⁻¹] where smul_comm r m x := by rw [← smul_one_smul m, ← smul_assoc, smul_comm, smul_assoc, smul_one_smul] @[to_additive] instance : IsScalarTower R M[S⁻¹] X[S⁻¹] where smul_assoc r m x := by rw [← smul_one_oreDiv_one_smul, ← smul_one_oreDiv_one_smul, ← mul_smul, smul_eq_mul] @[to_additive] instance [SMulCommClass R M M] : SMulCommClass R M[S⁻¹] X[S⁻¹] where smul_comm r x y := by induction' x using OreLocalization.ind with r₁ s₁ induction' y using OreLocalization.ind with r₂ s₂ rw [← smul_one_oreDiv_one_smul, ← smul_one_oreDiv_one_smul, smul_smul, smul_smul, mul_div_one, oreDiv_mul_char _ _ _ _ (r • 1) s₁ (by simp), mul_one] simp @[to_additive] instance [SMul Rᵐᵒᵖ M] [SMul Rᵐᵒᵖ X] [IsScalarTower Rᵐᵒᵖ M M] [IsScalarTower Rᵐᵒᵖ M X] [IsCentralScalar R M] : IsCentralScalar R X[S⁻¹] where op_smul_eq_smul r x := by rw [← smul_one_oreDiv_one_smul, ← smul_one_oreDiv_one_smul, op_smul_eq_smul] @[to_additive] instance {R} [Monoid R] [MulAction R M] [IsScalarTower R M M] [MulAction R X] [IsScalarTower R M X] : MulAction R X[S⁻¹] where one_smul := OreLocalization.ind fun x s ↦ by rw [← smul_one_oreDiv_one_smul, one_smul, ← OreLocalization.one_def, one_smul] mul_smul s₁ s₂ x := by rw [← smul_eq_mul, smul_assoc] @[to_additive] theorem smul_oreDiv_one (r : R) (x : X) : r • (x /ₒ (1 : S)) = (r • x) /ₒ (1 : S) := by rw [← smul_one_oreDiv_one_smul, smul_div_one, smul_assoc, one_smul] end SMul section CommMonoid variable {R : Type*} [CommMonoid R] {S : Submonoid R} [OreSet S] @[to_additive] theorem oreDiv_mul_oreDiv_comm {r₁ r₂ : R} {s₁ s₂ : S} : r₁ /ₒ s₁ * (r₂ /ₒ s₂) = r₁ * r₂ /ₒ (s₁ * s₂) := by rw [oreDiv_mul_char r₁ r₂ s₁ s₂ r₁ s₂ (by simp [mul_comm]), mul_comm s₂] @[to_additive] instance : CommMonoid R[S⁻¹] where mul_comm := fun x y => by induction' x with r₁ s₁ induction' y with r₂ s₂ rw [oreDiv_mul_oreDiv_comm, oreDiv_mul_oreDiv_comm, mul_comm r₁, mul_comm s₁] end CommMonoid section Zero variable {R : Type*} [Monoid R] {S : Submonoid R} [OreSet S] {X : Type*} [Zero X] variable [MulAction R X] /-- `0` in the localization, defined as `0 /ₒ 1`. -/ @[irreducible] protected def zero : X[S⁻¹] := 0 /ₒ 1 instance : Zero X[S⁻¹] := ⟨OreLocalization.zero⟩ protected theorem zero_def : (0 : X[S⁻¹]) = 0 /ₒ 1 := by with_unfolding_all rfl end Zero section MonoidWithZero variable {R : Type*} [MonoidWithZero R] {S : Submonoid R} [OreSet S] @[simp] theorem zero_oreDiv' (s : S) : (0 : R) /ₒ s = 0 := by rw [OreLocalization.zero_def, oreDiv_eq_iff] exact ⟨s, 1, by simp [Submonoid.smul_def]⟩ instance : MonoidWithZero R[S⁻¹] where zero_mul x := by induction' x using OreLocalization.ind with r s rw [OreLocalization.zero_def, oreDiv_mul_char 0 r 1 s 0 1 (by simp), zero_mul, one_mul] mul_zero x := by induction' x using OreLocalization.ind with r s rw [OreLocalization.zero_def, mul_div_one, mul_zero, zero_oreDiv', zero_oreDiv'] end MonoidWithZero section CommMonoidWithZero variable {R : Type*} [CommMonoidWithZero R] {S : Submonoid R} [OreSet S] instance : CommMonoidWithZero R[S⁻¹] where __ := inferInstanceAs (MonoidWithZero R[S⁻¹]) __ := inferInstanceAs (CommMonoid R[S⁻¹]) end CommMonoidWithZero section DistribMulAction variable {R : Type*} [Monoid R] {S : Submonoid R} [OreSet S] {X : Type*} [AddMonoid X] variable [DistribMulAction R X] private def add'' (r₁ : X) (s₁ : S) (r₂ : X) (s₂ : S) : X[S⁻¹] := (oreDenom (s₁ : R) s₂ • r₁ + oreNum (s₁ : R) s₂ • r₂) /ₒ (oreDenom (s₁ : R) s₂ * s₁) private theorem add''_char (r₁ : X) (s₁ : S) (r₂ : X) (s₂ : S) (rb : R) (sb : R) (hb : sb * s₁ = rb * s₂) (h : sb * s₁ ∈ S) : add'' r₁ s₁ r₂ s₂ = (sb • r₁ + rb • r₂) /ₒ ⟨sb * s₁, h⟩ := by simp only [add''] have ha := ore_eq (s₁ : R) s₂ generalize oreNum (s₁ : R) s₂ = ra at * generalize oreDenom (s₁ : R) s₂ = sa at * rw [oreDiv_eq_iff] rcases oreCondition sb sa with ⟨rc, sc, hc⟩ have : sc * rb * s₂ = rc * ra * s₂ := by rw [mul_assoc rc, ← ha, ← mul_assoc, ← hc, mul_assoc, mul_assoc, hb] rcases ore_right_cancel _ _ s₂ this with ⟨sd, hd⟩ use sd * sc use sd * rc simp only [smul_add, smul_smul, Submonoid.smul_def, Submonoid.coe_mul] constructor · rw [mul_assoc _ _ rb, hd, mul_assoc, hc, mul_assoc, mul_assoc] · rw [mul_assoc, ← mul_assoc (sc : R), hc, mul_assoc, mul_assoc] attribute [local instance] OreLocalization.oreEqv private def add' (r₂ : X) (s₂ : S) : X[S⁻¹] → X[S⁻¹] := (--plus tilde Quotient.lift fun r₁s₁ : X × S => add'' r₁s₁.1 r₁s₁.2 r₂ s₂) <| by -- Porting note: `assoc_rw` & `noncomm_ring` were not ported yet rintro ⟨r₁', s₁'⟩ ⟨r₁, s₁⟩ ⟨sb, rb, hb, hb'⟩ -- s*, r* rcases oreCondition (s₁' : R) s₂ with ⟨rc, sc, hc⟩ --s~~, r~~ rcases oreCondition rb sc with ⟨rd, sd, hd⟩ -- s#, r# dsimp at * rw [add''_char _ _ _ _ rc sc hc (sc * s₁').2] have : sd * sb * s₁ = rd * rc * s₂ := by rw [mul_assoc, hb', ← mul_assoc, hd, mul_assoc, hc, ← mul_assoc] rw [add''_char _ _ _ _ (rd * rc : R) (sd * sb) this (sd * sb * s₁).2] rw [mul_smul, ← Submonoid.smul_def sb, hb, smul_smul, hd, oreDiv_eq_iff] use 1 use rd simp only [mul_smul, smul_add, one_smul, OneMemClass.coe_one, one_mul, true_and] rw [this, hc, mul_assoc] /-- The addition on the Ore localization. -/ @[irreducible] private def add : X[S⁻¹] → X[S⁻¹] → X[S⁻¹] := fun x => Quotient.lift (fun rs : X × S => add' rs.1 rs.2 x) (by rintro ⟨r₁, s₁⟩ ⟨r₂, s₂⟩ ⟨sb, rb, hb, hb'⟩ induction' x with r₃ s₃ show add'' _ _ _ _ = add'' _ _ _ _ dsimp only at * rcases oreCondition (s₃ : R) s₂ with ⟨rc, sc, hc⟩ rcases oreCondition rc sb with ⟨rd, sd, hd⟩ have : rd * rb * s₁ = sd * sc * s₃ := by rw [mul_assoc, ← hb', ← mul_assoc, ← hd, mul_assoc, ← hc, mul_assoc] rw [add''_char _ _ _ _ rc sc hc (sc * s₃).2] rw [add''_char _ _ _ _ _ _ this.symm (sd * sc * s₃).2] refine oreDiv_eq_iff.mpr ?_ simp only [Submonoid.mk_smul, smul_add] use sd, 1 simp only [one_smul, one_mul, mul_smul, ← hb, Submonoid.smul_def, ← mul_assoc, and_true] simp only [smul_smul, hd]) instance : Add X[S⁻¹] := ⟨add⟩ theorem oreDiv_add_oreDiv {r r' : X} {s s' : S} : r /ₒ s + r' /ₒ s' = (oreDenom (s : R) s' • r + oreNum (s : R) s' • r') /ₒ (oreDenom (s : R) s' * s) := by with_unfolding_all rfl theorem oreDiv_add_char' {r r' : X} (s s' : S) (rb : R) (sb : R) (h : sb * s = rb * s') (h' : sb * s ∈ S) : r /ₒ s + r' /ₒ s' = (sb • r + rb • r') /ₒ ⟨sb * s, h'⟩ := by with_unfolding_all exact add''_char r s r' s' rb sb h h' /-- A characterization of the addition on the Ore localizaion, allowing for arbitrary Ore numerator and Ore denominator. -/ theorem oreDiv_add_char {r r' : X} (s s' : S) (rb : R) (sb : S) (h : sb * s = rb * s') : r /ₒ s + r' /ₒ s' = (sb • r + rb • r') /ₒ (sb * s) := oreDiv_add_char' s s' rb sb h (sb * s).2 /-- Another characterization of the addition on the Ore localization, bundling up all witnesses and conditions into a sigma type. -/ def oreDivAddChar' (r r' : X) (s s' : S) : Σ'r'' : R, Σ's'' : S, s'' * s = r'' * s' ∧ r /ₒ s + r' /ₒ s' = (s'' • r + r'' • r') /ₒ (s'' * s) := ⟨oreNum (s : R) s', oreDenom (s : R) s', ore_eq (s : R) s', oreDiv_add_oreDiv⟩ @[simp] theorem add_oreDiv {r r' : X} {s : S} : r /ₒ s + r' /ₒ s = (r + r') /ₒ s := by simp [oreDiv_add_char s s 1 1 (by simp)] protected theorem add_assoc (x y z : X[S⁻¹]) : x + y + z = x + (y + z) := by induction' x with r₁ s₁ induction' y with r₂ s₂ induction' z with r₃ s₃ rcases oreDivAddChar' r₁ r₂ s₁ s₂ with ⟨ra, sa, ha, ha'⟩; rw [ha']; clear ha' rcases oreDivAddChar' (sa • r₁ + ra • r₂) r₃ (sa * s₁) s₃ with ⟨rc, sc, hc, q⟩; rw [q]; clear q simp only [smul_add, mul_assoc, add_assoc] simp_rw [← add_oreDiv, ← OreLocalization.expand'] congr 2 · rw [OreLocalization.expand r₂ s₂ ra (ha.symm ▸ (sa * s₁).2)]; congr; ext; exact ha · rw [OreLocalization.expand r₃ s₃ rc (hc.symm ▸ (sc * (sa * s₁)).2)]; congr; ext; exact hc @[simp] theorem zero_oreDiv (s : S) : (0 : X) /ₒ s = 0 := by rw [OreLocalization.zero_def, oreDiv_eq_iff] exact ⟨s, 1, by simp⟩ protected theorem zero_add (x : X[S⁻¹]) : 0 + x = x := by induction x rw [← zero_oreDiv, add_oreDiv]; simp protected theorem add_zero (x : X[S⁻¹]) : x + 0 = x := by induction x rw [← zero_oreDiv, add_oreDiv]; simp @[irreducible] private def nsmul : ℕ → X[S⁻¹] → X[S⁻¹] := nsmulRec instance : AddMonoid X[S⁻¹] where add_assoc := OreLocalization.add_assoc zero_add := OreLocalization.zero_add add_zero := OreLocalization.add_zero nsmul := nsmul nsmul_zero _ := by with_unfolding_all rfl nsmul_succ _ _ := by with_unfolding_all rfl protected theorem smul_zero (x : R[S⁻¹]) : x • (0 : X[S⁻¹]) = 0 := by induction' x with r s rw [OreLocalization.zero_def, smul_div_one, smul_zero, zero_oreDiv, zero_oreDiv] protected theorem smul_add (z : R[S⁻¹]) (x y : X[S⁻¹]) : z • (x + y) = z • x + z • y := by induction' x with r₁ s₁ induction' y with r₂ s₂ induction' z with r₃ s₃ rcases oreDivAddChar' r₁ r₂ s₁ s₂ with ⟨ra, sa, ha, ha'⟩; rw [ha']; clear ha'; norm_cast at ha rw [OreLocalization.expand' r₁ s₁ sa] rw [OreLocalization.expand r₂ s₂ ra (by rw [← ha]; apply SetLike.coe_mem)] rw [← Subtype.coe_eq_of_eq_mk ha] repeat rw [oreDiv_smul_oreDiv] simp only [smul_add, add_oreDiv] instance : DistribMulAction R[S⁻¹] X[S⁻¹] where smul_zero := OreLocalization.smul_zero smul_add := OreLocalization.smul_add instance {R₀} [Monoid R₀] [MulAction R₀ X] [MulAction R₀ R] [IsScalarTower R₀ R X] [IsScalarTower R₀ R R] : DistribMulAction R₀ X[S⁻¹] where smul_zero _ := by rw [← smul_one_oreDiv_one_smul, smul_zero] smul_add _ _ _ := by simp only [← smul_one_oreDiv_one_smul, smul_add] end DistribMulAction section AddCommMonoid variable {R : Type*} [Monoid R] {S : Submonoid R} [OreSet S] variable {X : Type*} [AddCommMonoid X] [DistribMulAction R X] protected theorem add_comm (x y : X[S⁻¹]) : x + y = y + x := by induction' x with r s induction' y with r' s' rcases oreDivAddChar' r r' s s' with ⟨ra, sa, ha, ha'⟩ rw [ha', oreDiv_add_char' s' s _ _ ha.symm (ha ▸ (sa * s).2), add_comm] congr; ext; exact ha instance instAddCommMonoidOreLocalization : AddCommMonoid X[S⁻¹] where add_comm := OreLocalization.add_comm end AddCommMonoid section AddGroup variable {R : Type*} [Monoid R] {S : Submonoid R} [OreSet S] variable {X : Type*} [AddGroup X] [DistribMulAction R X] /-- Negation on the Ore localization is defined via negation on the numerator. -/ @[irreducible] protected def neg : X[S⁻¹] → X[S⁻¹] := liftExpand (fun (r : X) (s : S) => -r /ₒ s) fun r t s ht => by -- Porting note(#12129): additional beta reduction needed beta_reduce rw [← smul_neg, ← OreLocalization.expand] instance instNegOreLocalization : Neg X[S⁻¹] := ⟨OreLocalization.neg⟩ @[simp] protected theorem neg_def (r : X) (s : S) : -(r /ₒ s) = -r /ₒ s := by with_unfolding_all rfl protected theorem add_left_neg (x : X[S⁻¹]) : -x + x = 0 := by induction' x with r s; simp /-- `zsmul` of `OreLocalization` -/ @[irreducible] protected def zsmul : ℤ → X[S⁻¹] → X[S⁻¹] := zsmulRec unseal OreLocalization.zsmul in instance instAddGroupOreLocalization : AddGroup X[S⁻¹] where add_left_neg := OreLocalization.add_left_neg zsmul := OreLocalization.zsmul end AddGroup section AddCommGroup variable {R : Type*} [Monoid R] {S : Submonoid R} [OreSet S] variable {X : Type*} [AddCommGroup X] [DistribMulAction R X] instance : AddCommGroup X[S⁻¹] where __ := inferInstanceAs (AddGroup X[S⁻¹]) __ := inferInstanceAs (AddCommMonoid X[S⁻¹]) end AddCommGroup end OreLocalization
RingTheory\OreLocalization\OreSet.lean
/- Copyright (c) 2022 Jakob von Raumer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jakob von Raumer, Kevin Klinge -/ import Mathlib.Algebra.Group.Submonoid.Basic import Mathlib.Algebra.GroupWithZero.Basic import Mathlib.Algebra.Ring.Regular /-! # (Left) Ore sets This defines left Ore sets on arbitrary monoids. ## References * https://ncatlab.org/nlab/show/Ore+set -/ namespace AddOreLocalization /-- A submonoid `S` of an additive monoid `R` is (left) Ore if common summands on the right can be turned into common summands on the left, and if each pair of `r : R` and `s : S` admits an Ore minuend `v : R` and an Ore subtrahend `u : S` such that `u + r = v + s`. -/ class AddOreSet {R : Type*} [AddMonoid R] (S : AddSubmonoid R) where /-- Common summands on the right can be turned into common summands on the left, a weak form of cancellability. -/ ore_right_cancel : ∀ (r₁ r₂ : R) (s : S), r₁ + s = r₂ + s → ∃ s' : S, s' + r₁ = s' + r₂ /-- The Ore minuend of a difference. -/ oreMin : R → S → R /-- The Ore subtrahend of a difference. -/ oreSubtra : R → S → S /-- The Ore condition of a difference, expressed in terms of `oreMin` and `oreSubtra`. -/ ore_eq : ∀ (r : R) (s : S), oreSubtra r s + r = oreMin r s + s end AddOreLocalization namespace OreLocalization section Monoid /-- A submonoid `S` of a monoid `R` is (left) Ore if common factors on the right can be turned into common factors on the left, and if each pair of `r : R` and `s : S` admits an Ore numerator `v : R` and an Ore denominator `u : S` such that `u * r = v * s`. -/ @[to_additive AddOreLocalization.AddOreSet] class OreSet {R : Type*} [Monoid R] (S : Submonoid R) where /-- Common factors on the right can be turned into common factors on the left, a weak form of cancellability. -/ ore_right_cancel : ∀ (r₁ r₂ : R) (s : S), r₁ * s = r₂ * s → ∃ s' : S, s' * r₁ = s' * r₂ /-- The Ore numerator of a fraction. -/ oreNum : R → S → R /-- The Ore denominator of a fraction. -/ oreDenom : R → S → S /-- The Ore condition of a fraction, expressed in terms of `oreNum` and `oreDenom`. -/ ore_eq : ∀ (r : R) (s : S), oreDenom r s * r = oreNum r s * s -- TODO: use this once it's available. -- run_cmd to_additive.map_namespace `OreLocalization `AddOreLocalization variable {R : Type*} [Monoid R] {S : Submonoid R} [OreSet S] /-- Common factors on the right can be turned into common factors on the left, a weak form of cancellability. -/ @[to_additive AddOreLocalization.ore_right_cancel] theorem ore_right_cancel (r₁ r₂ : R) (s : S) (h : r₁ * s = r₂ * s) : ∃ s' : S, s' * r₁ = s' * r₂ := OreSet.ore_right_cancel r₁ r₂ s h /-- The Ore numerator of a fraction. -/ @[to_additive AddOreLocalization.oreMin "The Ore minuend of a difference."] def oreNum (r : R) (s : S) : R := OreSet.oreNum r s /-- The Ore denominator of a fraction. -/ @[to_additive AddOreLocalization.oreSubtra "The Ore subtrahend of a difference."] def oreDenom (r : R) (s : S) : S := OreSet.oreDenom r s /-- The Ore condition of a fraction, expressed in terms of `oreNum` and `oreDenom`. -/ @[to_additive AddOreLocalization.add_ore_eq "The Ore condition of a difference, expressed in terms of `oreMin` and `oreSubtra`."] theorem ore_eq (r : R) (s : S) : oreDenom r s * r = oreNum r s * s := OreSet.ore_eq r s /-- The Ore condition bundled in a sigma type. This is useful in situations where we want to obtain both witnesses and the condition for a given fraction. -/ @[to_additive AddOreLocalization.addOreCondition "The Ore condition bundled in a sigma type. This is useful in situations where we want to obtain both witnesses and the condition for a given difference."] def oreCondition (r : R) (s : S) : Σ'r' : R, Σ's' : S, s' * r = r' * s := ⟨oreNum r s, oreDenom r s, ore_eq r s⟩ /-- The trivial submonoid is an Ore set. -/ @[to_additive AddOreLocalization.addOreSetBot] instance oreSetBot : OreSet (⊥ : Submonoid R) where ore_right_cancel _ _ s h := ⟨s, by rcases s with ⟨s, hs⟩ rw [Submonoid.mem_bot] at hs subst hs rw [mul_one, mul_one] at h subst h rfl⟩ oreNum r _ := r oreDenom _ s := s ore_eq _ s := by rcases s with ⟨s, hs⟩ rw [Submonoid.mem_bot] at hs simp [hs] /-- Every submonoid of a commutative monoid is an Ore set. -/ @[to_additive AddOreLocalization.addOreSetComm] instance (priority := 100) oreSetComm {R} [CommMonoid R] (S : Submonoid R) : OreSet S where ore_right_cancel m n s h := ⟨s, by rw [mul_comm (s : R) n, mul_comm (s : R) m, h]⟩ oreNum r _ := r oreDenom _ s := s ore_eq r s := by rw [mul_comm] end Monoid /-- Cancellability in monoids with zeros can act as a replacement for the `ore_right_cancel` condition of an ore set. -/ def oreSetOfCancelMonoidWithZero {R : Type*} [CancelMonoidWithZero R] {S : Submonoid R} (oreNum : R → S → R) (oreDenom : R → S → S) (ore_eq : ∀ (r : R) (s : S), oreDenom r s * r = oreNum r s * s) : OreSet S := { ore_right_cancel := fun _ _ s h => ⟨s, mul_eq_mul_left_iff.mpr (mul_eq_mul_right_iff.mp h)⟩ oreNum oreDenom ore_eq } /-- In rings without zero divisors, the first (cancellability) condition is always fulfilled, it suffices to give a proof for the Ore condition itself. -/ def oreSetOfNoZeroDivisors {R : Type*} [Ring R] [NoZeroDivisors R] {S : Submonoid R} (oreNum : R → S → R) (oreDenom : R → S → S) (ore_eq : ∀ (r : R) (s : S), oreDenom r s * r = oreNum r s * s) : OreSet S := letI : CancelMonoidWithZero R := NoZeroDivisors.toCancelMonoidWithZero oreSetOfCancelMonoidWithZero oreNum oreDenom ore_eq lemma nonempty_oreSet_iff {R : Type*} [Ring R] {S : Submonoid R} : Nonempty (OreSet S) ↔ (∀ (r₁ r₂ : R) (s : S), r₁ * s = r₂ * s → ∃ s' : S, s' * r₁ = s' * r₂) ∧ (∀ (r : R) (s : S), ∃ (r' : R) (s' : S), s' * r = r' * s) := by constructor · exact fun ⟨_⟩ ↦ ⟨ore_right_cancel, fun r s ↦ ⟨oreNum r s, oreDenom r s, ore_eq r s⟩⟩ · intro ⟨H, H'⟩ choose r' s' h using H' exact ⟨H, r', s', h⟩ lemma nonempty_oreSet_iff_of_noZeroDivisors {R : Type*} [Ring R] [NoZeroDivisors R] {S : Submonoid R} : Nonempty (OreSet S) ↔ ∀ (r : R) (s : S), ∃ (r' : R) (s' : S), s' * r = r' * s := by constructor · exact fun ⟨_⟩ ↦ fun r s ↦ ⟨oreNum r s, oreDenom r s, ore_eq r s⟩ · intro H choose r' s' h using H exact ⟨oreSetOfNoZeroDivisors r' s' h⟩ end OreLocalization
RingTheory\OreLocalization\Ring.lean
/- Copyright (c) 2022 Jakob von Raumer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jakob von Raumer, Kevin Klinge, Andrew Yang -/ import Mathlib.Algebra.GroupWithZero.NonZeroDivisors import Mathlib.Algebra.Algebra.Defs import Mathlib.Algebra.Field.Defs import Mathlib.RingTheory.OreLocalization.Basic /-! # Module and Ring instances of Ore Localizations The `Monoid` and `DistribMulAction` instances and additive versions are provided in `Mathlib/RingTheory/OreLocalization/Basic.lean`. -/ universe u namespace OreLocalization section Module variable {R : Type*} [Semiring R] {S : Submonoid R} [OreSet S] variable {X : Type*} [AddCommMonoid X] [Module R X] protected theorem zero_smul (x : X[S⁻¹]) : (0 : R[S⁻¹]) • x = 0 := by induction' x with r s rw [OreLocalization.zero_def, oreDiv_smul_char 0 r 1 s 0 1 (by simp)]; simp protected theorem add_smul (y z : R[S⁻¹]) (x : X[S⁻¹]) : (y + z) • x = y • x + z • x := by induction' x with r₁ s₁ induction' y with r₂ s₂ induction' z with r₃ s₃ rcases oreDivAddChar' r₂ r₃ s₂ s₃ with ⟨ra, sa, ha, q⟩ rw [q] clear q rw [OreLocalization.expand' r₂ s₂ sa] rcases oreDivSMulChar' (sa • r₂) r₁ (sa * s₂) s₁ with ⟨rb, sb, hb, q⟩ rw [q] clear q have hs₃rasb : sb * ra * s₃ ∈ S := by rw [mul_assoc, ← ha] norm_cast apply SetLike.coe_mem rw [OreLocalization.expand _ _ _ hs₃rasb] have ha' : ↑((sb * sa) * s₂) = sb * ra * s₃ := by simp [ha, mul_assoc] rw [← Subtype.coe_eq_of_eq_mk ha'] rcases oreDivSMulChar' ((sb * ra) • r₃) r₁ (sb * sa * s₂) s₁ with ⟨rc, sc, hc, hc'⟩ rw [hc'] rw [oreDiv_add_char _ _ 1 sc (by simp [mul_assoc])] rw [OreLocalization.expand' (sa • r₂ + ra • r₃) (sa * s₂) (sc * sb)] simp only [smul_eq_mul, one_smul, Submonoid.smul_def, mul_add, Submonoid.coe_mul] at hb hc ⊢ rw [mul_assoc, hb, mul_assoc, ← mul_assoc _ ra, hc, ← mul_assoc, ← add_mul] rw [OreLocalization.smul_cancel'] simp only [add_smul, ← mul_assoc, smul_smul] end Module section Semiring variable {R : Type*} [Semiring R] {S : Submonoid R} [OreSet S] attribute [local instance] OreLocalization.oreEqv protected theorem zero_mul (x : R[S⁻¹]) : 0 * x = 0 := OreLocalization.zero_smul x protected theorem mul_zero (x : R[S⁻¹]) : x * 0 = 0 := OreLocalization.smul_zero x protected theorem left_distrib (x y z : R[S⁻¹]) : x * (y + z) = x * y + x * z := OreLocalization.smul_add _ _ _ theorem right_distrib (x y z : R[S⁻¹]) : (x + y) * z = x * z + y * z := OreLocalization.add_smul _ _ _ instance : Semiring R[S⁻¹] where __ := inferInstanceAs (MonoidWithZero (R[S⁻¹])) __ := inferInstanceAs (AddCommMonoid (R[S⁻¹])) left_distrib := OreLocalization.left_distrib right_distrib := right_distrib variable {X : Type*} [AddCommMonoid X] [Module R X] instance : Module R[S⁻¹] X[S⁻¹] where add_smul := OreLocalization.add_smul zero_smul := OreLocalization.zero_smul instance {R₀} [Semiring R₀] [Module R₀ X] [Module R₀ R] [IsScalarTower R₀ R X] [IsScalarTower R₀ R R] : Module R₀ X[S⁻¹] where add_smul r s x := by simp only [← smul_one_oreDiv_one_smul, add_smul, ← add_oreDiv] zero_smul x := by rw [← smul_one_oreDiv_one_smul, zero_smul, zero_oreDiv, zero_smul] @[simp] lemma nsmul_eq_nsmul (n : ℕ) (x : X[S⁻¹]) : letI inst := OreLocalization.instModuleOfIsScalarTower (R₀ := ℕ) (R := R) (X := X) (S := S) HSMul.hSMul (self := @instHSMul _ _ inst.toSMul) n x = n • x := by letI inst := OreLocalization.instModuleOfIsScalarTower (R₀ := ℕ) (R := R) (X := X) (S := S) exact congr($(AddCommMonoid.uniqueNatModule.2 inst).smul n x) /-- The ring homomorphism from `R` to `R[S⁻¹]`, mapping `r : R` to the fraction `r /ₒ 1`. -/ @[simps!] def numeratorRingHom : R →+* R[S⁻¹] where __ := numeratorHom map_zero' := by with_unfolding_all exact OreLocalization.zero_def map_add' _ _ := add_oreDiv.symm instance {R₀} [CommSemiring R₀] [Algebra R₀ R] : Algebra R₀ R[S⁻¹] where __ := inferInstanceAs (Module R₀ R[S⁻¹]) __ := numeratorRingHom.comp (algebraMap R₀ R) commutes' r x := by induction' x using OreLocalization.ind with r₁ s₁ dsimp rw [mul_div_one, oreDiv_mul_char _ _ _ _ (algebraMap R₀ R r) s₁ (Algebra.commutes _ _).symm, Algebra.commutes, mul_one] smul_def' r x := by dsimp rw [Algebra.algebraMap_eq_smul_one, ← smul_eq_mul, smul_one_oreDiv_one_smul] section UMP variable {T : Type*} [Semiring T] variable (f : R →+* T) (fS : S →* Units T) variable (hf : ∀ s : S, f s = fS s) /-- The universal lift from a ring homomorphism `f : R →+* T`, which maps elements in `S` to units of `T`, to a ring homomorphism `R[S⁻¹] →+* T`. This extends the construction on monoids. -/ def universalHom : R[S⁻¹] →+* T := { universalMulHom f.toMonoidHom fS hf with map_zero' := by simp only [RingHom.toMonoidHom_eq_coe, OneHom.toFun_eq_coe, MonoidHom.toOneHom_coe] rw [OreLocalization.zero_def, universalMulHom_apply] simp map_add' := fun x y => by simp only [RingHom.toMonoidHom_eq_coe, OneHom.toFun_eq_coe, MonoidHom.toOneHom_coe] induction' x with r₁ s₁ induction' y with r₂ s₂ rcases oreDivAddChar' r₁ r₂ s₁ s₂ with ⟨r₃, s₃, h₃, h₃'⟩ rw [h₃'] clear h₃' simp only [RingHom.toMonoidHom_eq_coe, smul_eq_mul, universalMulHom_apply, MonoidHom.coe_coe, Submonoid.smul_def] simp only [mul_inv_rev, MonoidHom.map_mul, RingHom.map_add, RingHom.map_mul, Units.val_mul] rw [mul_add, mul_assoc, ← mul_assoc _ (f s₃), hf, ← Units.val_mul] simp only [one_mul, mul_left_inv, Units.val_one] congr 1 rw [← mul_assoc] congr 1 norm_cast at h₃ have h₃' := Subtype.coe_eq_of_eq_mk h₃ rw [← Units.val_mul, ← mul_inv_rev, ← fS.map_mul, h₃'] rw [Units.inv_mul_eq_iff_eq_mul, Units.eq_mul_inv_iff_mul_eq, ← hf, ← hf] simp only [map_mul] } theorem universalHom_apply {r : R} {s : S} : universalHom f fS hf (r /ₒ s) = ((fS s)⁻¹ : Units T) * f r := rfl theorem universalHom_commutes {r : R} : universalHom f fS hf (numeratorHom r) = f r := by simp [numeratorHom_apply, universalHom_apply] theorem universalHom_unique (φ : R[S⁻¹] →+* T) (huniv : ∀ r : R, φ (numeratorHom r) = f r) : φ = universalHom f fS hf := RingHom.coe_monoidHom_injective <| universalMulHom_unique (RingHom.toMonoidHom f) fS hf (↑φ) huniv end UMP end Semiring section Ring variable {R : Type*} [Ring R] {S : Submonoid R} [OreSet S] variable {X : Type*} [AddCommGroup X] [Module R X] instance : Ring R[S⁻¹] where __ := inferInstanceAs (Semiring R[S⁻¹]) __ := inferInstanceAs (AddGroup R[S⁻¹]) @[simp] lemma zsmul_eq_zsmul (n : ℤ) (x : X[S⁻¹]) : letI inst := OreLocalization.instModuleOfIsScalarTower (R₀ := ℤ) (R := R) (X := X) (S := S) HSMul.hSMul (self := @instHSMul _ _ inst.toSMul) n x = n • x := by letI inst := OreLocalization.instModuleOfIsScalarTower (R₀ := ℤ) (R := R) (X := X) (S := S) exact congr($(AddCommGroup.uniqueIntModule.2 inst).smul n x) open nonZeroDivisors theorem numeratorHom_inj (hS : S ≤ nonZeroDivisorsRight R) : Function.Injective (numeratorHom : R → R[S⁻¹]) := fun r₁ r₂ h => by rw [numeratorHom_apply, numeratorHom_apply, oreDiv_eq_iff] at h rcases h with ⟨u, v, h₁, h₂⟩ simp only [S.coe_one, mul_one, Submonoid.smul_def, smul_eq_mul] at h₁ h₂ rw [← h₂, ← sub_eq_zero, ← mul_sub] at h₁ exact (sub_eq_zero.mp (hS u.2 _ h₁)).symm theorem subsingleton_iff : Subsingleton R[S⁻¹] ↔ 0 ∈ S := by rw [← subsingleton_iff_zero_eq_one, OreLocalization.one_def, OreLocalization.zero_def, oreDiv_eq_iff] simp theorem nontrivial_iff : Nontrivial R[S⁻¹] ↔ 0 ∉ S := by rw [← not_subsingleton_iff_nontrivial, subsingleton_iff] theorem nontrivial_of_nonZeroDivisors [Nontrivial R] (hS : S ≤ R⁰) : Nontrivial R[S⁻¹] := nontrivial_iff.mpr (fun e ↦ one_ne_zero <| hS e 1 (mul_zero _)) end Ring noncomputable section DivisionRing open nonZeroDivisors variable {R : Type*} [Ring R] [Nontrivial R] [OreSet R⁰] instance nontrivial : Nontrivial R[R⁰⁻¹] := nontrivial_of_nonZeroDivisors (refl R⁰) variable [NoZeroDivisors R] open Classical in /-- The inversion of Ore fractions for a ring without zero divisors, satisying `0⁻¹ = 0` and `(r /ₒ r')⁻¹ = r' /ₒ r` for `r ≠ 0`. -/ @[irreducible] protected def inv : R[R⁰⁻¹] → R[R⁰⁻¹] := liftExpand (fun r s => if hr : r = (0 : R) then (0 : R[R⁰⁻¹]) else s /ₒ ⟨r, fun _ => eq_zero_of_ne_zero_of_mul_right_eq_zero hr⟩) (by intro r t s hst by_cases hr : r = 0 · simp [hr] · by_cases ht : t = 0 · exfalso apply nonZeroDivisors.coe_ne_zero ⟨_, hst⟩ simp [ht, mul_zero] · simp only [hr, ht, dif_neg, not_false_iff, or_self_iff, mul_eq_zero, smul_eq_mul] apply OreLocalization.expand) instance inv' : Inv R[R⁰⁻¹] := ⟨OreLocalization.inv⟩ open Classical in protected theorem inv_def {r : R} {s : R⁰} : (r /ₒ s)⁻¹ = if hr : r = (0 : R) then (0 : R[R⁰⁻¹]) else s /ₒ ⟨r, fun _ => eq_zero_of_ne_zero_of_mul_right_eq_zero hr⟩ := by with_unfolding_all rfl protected theorem mul_inv_cancel (x : R[R⁰⁻¹]) (h : x ≠ 0) : x * x⁻¹ = 1 := by induction' x with r s rw [OreLocalization.inv_def, OreLocalization.one_def] have hr : r ≠ 0 := by rintro rfl simp at h simp only [hr] with_unfolding_all apply OreLocalization.mul_inv ⟨r, _⟩ protected theorem inv_zero : (0 : R[R⁰⁻¹])⁻¹ = 0 := by rw [OreLocalization.zero_def, OreLocalization.inv_def] simp instance : DivisionRing R[R⁰⁻¹] where mul_inv_cancel := OreLocalization.mul_inv_cancel inv_zero := OreLocalization.inv_zero nnqsmul := _ nnqsmul_def := fun q a => rfl qsmul := _ qsmul_def := fun q a => rfl end DivisionRing section CommSemiring variable {R : Type*} [CommSemiring R] {S : Submonoid R} [OreSet S] instance : CommSemiring R[S⁻¹] where __ := inferInstanceAs (Semiring R[S⁻¹]) __ := inferInstanceAs (CommMonoid R[S⁻¹]) end CommSemiring section CommRing variable {R : Type*} [CommRing R] {S : Submonoid R} [OreSet S] instance : CommRing R[S⁻¹] where __ := inferInstanceAs (Ring R[S⁻¹]) __ := inferInstanceAs (CommMonoid R[S⁻¹]) end CommRing section Field open nonZeroDivisors variable {R : Type*} [CommRing R] [Nontrivial R] [NoZeroDivisors R] [OreSet R⁰] noncomputable instance : Field R[R⁰⁻¹] where __ := inferInstanceAs (DivisionRing R[R⁰⁻¹]) __ := inferInstanceAs (CommMonoid R[R⁰⁻¹]) end Field end OreLocalization
RingTheory\Polynomial\Basic.lean
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.CharP.ExpChar import Mathlib.Algebra.MvPolynomial.CommRing import Mathlib.Algebra.MvPolynomial.Equiv import Mathlib.RingTheory.Polynomial.Content /-! # Ring-theoretic supplement of Algebra.Polynomial. ## Main results * `MvPolynomial.isDomain`: If a ring is an integral domain, then so is its polynomial ring over finitely many variables. * `Polynomial.isNoetherianRing`: Hilbert basis theorem, that if a ring is noetherian then so is its polynomial ring. * `Polynomial.wfDvdMonoid`: If an integral domain is a `WFDvdMonoid`, then so is its polynomial ring. * `Polynomial.uniqueFactorizationMonoid`, `MvPolynomial.uniqueFactorizationMonoid`: If an integral domain is a `UniqueFactorizationMonoid`, then so is its polynomial ring (of any number of variables). -/ noncomputable section open Polynomial open Finset universe u v w variable {R : Type u} {S : Type*} namespace Polynomial section Semiring variable [Semiring R] instance instCharP (p : ℕ) [h : CharP R p] : CharP R[X] p := let ⟨h⟩ := h ⟨fun n => by rw [← map_natCast C, ← C_0, C_inj, h]⟩ instance instExpChar (p : ℕ) [h : ExpChar R p] : ExpChar R[X] p := by cases h; exacts [ExpChar.zero, ExpChar.prime ‹_›] variable (R) /-- The `R`-submodule of `R[X]` consisting of polynomials of degree ≤ `n`. -/ def degreeLE (n : WithBot ℕ) : Submodule R R[X] := ⨅ k : ℕ, ⨅ _ : ↑k > n, LinearMap.ker (lcoeff R k) /-- The `R`-submodule of `R[X]` consisting of polynomials of degree < `n`. -/ def degreeLT (n : ℕ) : Submodule R R[X] := ⨅ k : ℕ, ⨅ (_ : k ≥ n), LinearMap.ker (lcoeff R k) variable {R} theorem mem_degreeLE {n : WithBot ℕ} {f : R[X]} : f ∈ degreeLE R n ↔ degree f ≤ n := by simp only [degreeLE, Submodule.mem_iInf, degree_le_iff_coeff_zero, LinearMap.mem_ker]; rfl @[mono] theorem degreeLE_mono {m n : WithBot ℕ} (H : m ≤ n) : degreeLE R m ≤ degreeLE R n := fun _ hf => mem_degreeLE.2 (le_trans (mem_degreeLE.1 hf) H) theorem degreeLE_eq_span_X_pow [DecidableEq R] {n : ℕ} : degreeLE R n = Submodule.span R ↑((Finset.range (n + 1)).image fun n => (X : R[X]) ^ n) := by apply le_antisymm · intro p hp replace hp := mem_degreeLE.1 hp rw [← Polynomial.sum_monomial_eq p, Polynomial.sum] refine Submodule.sum_mem _ fun k hk => ?_ have := WithBot.coe_le_coe.1 (Finset.sup_le_iff.1 hp k hk) rw [← C_mul_X_pow_eq_monomial, C_mul'] refine Submodule.smul_mem _ _ (Submodule.subset_span <| Finset.mem_coe.2 <| Finset.mem_image.2 ⟨_, Finset.mem_range.2 (Nat.lt_succ_of_le this), rfl⟩) rw [Submodule.span_le, Finset.coe_image, Set.image_subset_iff] intro k hk apply mem_degreeLE.2 exact (degree_X_pow_le _).trans (WithBot.coe_le_coe.2 <| Nat.le_of_lt_succ <| Finset.mem_range.1 hk) theorem mem_degreeLT {n : ℕ} {f : R[X]} : f ∈ degreeLT R n ↔ degree f < n := by rw [degreeLT, Submodule.mem_iInf] conv_lhs => intro i; rw [Submodule.mem_iInf] rw [degree, Finset.max_eq_sup_coe] rw [Finset.sup_lt_iff ?_] rotate_left · apply WithBot.bot_lt_coe conv_rhs => simp only [mem_support_iff] intro b rw [Nat.cast_withBot, WithBot.coe_lt_coe, lt_iff_not_le, Ne, not_imp_not] rfl @[mono] theorem degreeLT_mono {m n : ℕ} (H : m ≤ n) : degreeLT R m ≤ degreeLT R n := fun _ hf => mem_degreeLT.2 (lt_of_lt_of_le (mem_degreeLT.1 hf) <| WithBot.coe_le_coe.2 H) theorem degreeLT_eq_span_X_pow [DecidableEq R] {n : ℕ} : degreeLT R n = Submodule.span R ↑((Finset.range n).image fun n => X ^ n : Finset R[X]) := by apply le_antisymm · intro p hp replace hp := mem_degreeLT.1 hp rw [← Polynomial.sum_monomial_eq p, Polynomial.sum] refine Submodule.sum_mem _ fun k hk => ?_ have := WithBot.coe_lt_coe.1 ((Finset.sup_lt_iff <| WithBot.bot_lt_coe n).1 hp k hk) rw [← C_mul_X_pow_eq_monomial, C_mul'] refine Submodule.smul_mem _ _ (Submodule.subset_span <| Finset.mem_coe.2 <| Finset.mem_image.2 ⟨_, Finset.mem_range.2 this, rfl⟩) rw [Submodule.span_le, Finset.coe_image, Set.image_subset_iff] intro k hk apply mem_degreeLT.2 exact lt_of_le_of_lt (degree_X_pow_le _) (WithBot.coe_lt_coe.2 <| Finset.mem_range.1 hk) /-- The first `n` coefficients on `degreeLT n` form a linear equivalence with `Fin n → R`. -/ def degreeLTEquiv (R) [Semiring R] (n : ℕ) : degreeLT R n ≃ₗ[R] Fin n → R where toFun p n := (↑p : R[X]).coeff n invFun f := ⟨∑ i : Fin n, monomial i (f i), (degreeLT R n).sum_mem fun i _ => mem_degreeLT.mpr (lt_of_le_of_lt (degree_monomial_le i (f i)) (WithBot.coe_lt_coe.mpr i.is_lt))⟩ map_add' p q := by ext dsimp rw [coeff_add] map_smul' x p := by ext dsimp rw [coeff_smul] rfl left_inv := by rintro ⟨p, hp⟩ ext1 simp only [Submodule.coe_mk] by_cases hp0 : p = 0 · subst hp0 simp only [coeff_zero, LinearMap.map_zero, Finset.sum_const_zero] rw [mem_degreeLT, degree_eq_natDegree hp0, Nat.cast_lt] at hp conv_rhs => rw [p.as_sum_range' n hp, ← Fin.sum_univ_eq_sum_range] right_inv f := by ext i simp only [finset_sum_coeff, Submodule.coe_mk] rw [Finset.sum_eq_single i, coeff_monomial, if_pos rfl] · rintro j - hji rw [coeff_monomial, if_neg] rwa [← Fin.ext_iff] · intro h exact (h (Finset.mem_univ _)).elim -- Porting note: removed @[simp] as simp can prove this theorem degreeLTEquiv_eq_zero_iff_eq_zero {n : ℕ} {p : R[X]} (hp : p ∈ degreeLT R n) : degreeLTEquiv _ _ ⟨p, hp⟩ = 0 ↔ p = 0 := by rw [LinearEquiv.map_eq_zero_iff, Submodule.mk_eq_zero] theorem eval_eq_sum_degreeLTEquiv {n : ℕ} {p : R[X]} (hp : p ∈ degreeLT R n) (x : R) : p.eval x = ∑ i, degreeLTEquiv _ _ ⟨p, hp⟩ i * x ^ (i : ℕ) := by simp_rw [eval_eq_sum] exact (sum_fin _ (by simp_rw [zero_mul, forall_const]) (mem_degreeLT.mp hp)).symm theorem degreeLT_succ_eq_degreeLE {n : ℕ} : degreeLT R (n + 1) = degreeLE R n := by ext x by_cases x_zero : x = 0 · simp_rw [x_zero, Submodule.zero_mem] · rw [mem_degreeLT, mem_degreeLE, ← natDegree_lt_iff_degree_lt (by rwa [ne_eq]), ← natDegree_le_iff_degree_le, Nat.lt_succ] /-- For every polynomial `p` in the span of a set `s : Set R[X]`, there exists a polynomial of `p' ∈ s` with higher degree. See also `Polynomial.exists_degree_le_of_mem_span_of_finite`. -/ theorem exists_degree_le_of_mem_span {s : Set R[X]} {p : R[X]} (hs : s.Nonempty) (hp : p ∈ Submodule.span R s) : ∃ p' ∈ s, degree p ≤ degree p' := by by_contra! h by_cases hp_zero : p = 0 · rw [hp_zero, degree_zero] at h rcases hs with ⟨x, hx⟩ exact not_lt_bot (h x hx) · have : p ∈ degreeLT R (natDegree p) := by refine (Submodule.span_le.mpr fun p' p'_mem => ?_) hp rw [SetLike.mem_coe, mem_degreeLT, Nat.cast_withBot] exact lt_of_lt_of_le (h p' p'_mem) degree_le_natDegree rwa [mem_degreeLT, Nat.cast_withBot, degree_eq_natDegree hp_zero, Nat.cast_withBot, lt_self_iff_false] at this /-- A stronger version of `Polynomial.exists_degree_le_of_mem_span` under the assumption that the set `s : R[X]` is finite. There exists a polynomial `p' ∈ s` whose degree dominates the degree of every element of `p ∈ span R s`-/ theorem exists_degree_le_of_mem_span_of_finite {s : Set R[X]} (s_fin : s.Finite) (hs : s.Nonempty) : ∃ p' ∈ s, ∀ (p : R[X]), p ∈ Submodule.span R s → degree p ≤ degree p' := by rcases Set.Finite.exists_maximal_wrt degree s s_fin hs with ⟨a, has, hmax⟩ refine ⟨a, has, fun p hp => ?_⟩ rcases exists_degree_le_of_mem_span hs hp with ⟨p', hp'⟩ by_cases h : degree a ≤ degree p' · rw [← hmax p' hp'.left h] at hp'; exact hp'.right · exact le_trans hp'.right (not_le.mp h).le /-- The span of every finite set of polynomials is contained in a `degreeLE n` for some `n`. -/ theorem span_le_degreeLE_of_finite {s : Set R[X]} (s_fin : s.Finite) : ∃ n : ℕ, Submodule.span R s ≤ degreeLE R n := by by_cases s_emp : s.Nonempty · rcases exists_degree_le_of_mem_span_of_finite s_fin s_emp with ⟨p', _, hp'max⟩ exact ⟨natDegree p', fun p hp => mem_degreeLE.mpr ((hp'max _ hp).trans degree_le_natDegree)⟩ · rw [Set.not_nonempty_iff_eq_empty] at s_emp rw [s_emp, Submodule.span_empty] exact ⟨0, bot_le⟩ /-- The span of every finite set of polynomials is contained in a `degreeLT n` for some `n`. -/ theorem span_of_finite_le_degreeLT {s : Set R[X]} (s_fin : s.Finite) : ∃ n : ℕ, Submodule.span R s ≤ degreeLT R n := by rcases span_le_degreeLE_of_finite s_fin with ⟨n, _⟩ exact ⟨n + 1, by rwa [degreeLT_succ_eq_degreeLE]⟩ /-- If `R` is a nontrivial ring, the polynomials `R[X]` are not finite as an `R`-module. When `R` is a field, this is equivalent to `R[X]` being an infinite-dimensional vector space over `R`. -/ theorem not_finite [Nontrivial R] : ¬ Module.Finite R R[X] := by rw [Module.finite_def, Submodule.fg_def] push_neg intro s hs contra rcases span_le_degreeLE_of_finite hs with ⟨n,hn⟩ have : ((X : R[X]) ^ (n + 1)) ∈ Polynomial.degreeLE R ↑n := by rw [contra] at hn exact hn Submodule.mem_top rw [mem_degreeLE, degree_X_pow, Nat.cast_le, add_le_iff_nonpos_right, nonpos_iff_eq_zero] at this exact one_ne_zero this /-- The finset of nonzero coefficients of a polynomial. -/ def coeffs (p : R[X]) : Finset R := letI := Classical.decEq R Finset.image (fun n => p.coeff n) p.support @[deprecated (since := "2024-05-17")] noncomputable alias frange := coeffs theorem coeffs_zero : coeffs (0 : R[X]) = ∅ := rfl @[deprecated (since := "2024-05-17")] alias frange_zero := coeffs_zero theorem mem_coeffs_iff {p : R[X]} {c : R} : c ∈ p.coeffs ↔ ∃ n ∈ p.support, c = p.coeff n := by simp [coeffs, eq_comm, (Finset.mem_image)] @[deprecated (since := "2024-05-17")] alias mem_frange_iff := mem_coeffs_iff theorem coeffs_one : coeffs (1 : R[X]) ⊆ {1} := by classical simp_rw [coeffs, Finset.image_subset_iff] simp_all [coeff_one] @[deprecated (since := "2024-05-17")] alias frange_one := coeffs_one theorem coeff_mem_coeffs (p : R[X]) (n : ℕ) (h : p.coeff n ≠ 0) : p.coeff n ∈ p.coeffs := by classical simp only [coeffs, exists_prop, mem_support_iff, Finset.mem_image, Ne] exact ⟨n, h, rfl⟩ @[deprecated (since := "2024-05-17")] alias coeff_mem_frange := coeff_mem_coeffs theorem geom_sum_X_comp_X_add_one_eq_sum (n : ℕ) : (∑ i ∈ range n, (X : R[X]) ^ i).comp (X + 1) = (Finset.range n).sum fun i : ℕ => (n.choose (i + 1) : R[X]) * X ^ i := by ext i trans (n.choose (i + 1) : R); swap · simp only [finset_sum_coeff, ← C_eq_natCast, coeff_C_mul_X_pow] rw [Finset.sum_eq_single i, if_pos rfl] · simp (config := { contextual := true }) only [@eq_comm _ i, if_false, eq_self_iff_true, imp_true_iff] · simp (config := { contextual := true }) only [Nat.lt_add_one_iff, Nat.choose_eq_zero_of_lt, Nat.cast_zero, Finset.mem_range, not_lt, eq_self_iff_true, if_true, imp_true_iff] induction' n with n ih generalizing i · dsimp; simp only [zero_comp, coeff_zero, Nat.cast_zero] · simp only [geom_sum_succ', ih, add_comp, X_pow_comp, coeff_add, Nat.choose_succ_succ, Nat.cast_add, coeff_X_add_one_pow] theorem Monic.geom_sum {P : R[X]} (hP : P.Monic) (hdeg : 0 < P.natDegree) {n : ℕ} (hn : n ≠ 0) : (∑ i ∈ range n, P ^ i).Monic := by nontriviality R obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hn rw [geom_sum_succ'] refine (hP.pow _).add_of_left ?_ refine lt_of_le_of_lt (degree_sum_le _ _) ?_ rw [Finset.sup_lt_iff] · simp only [Finset.mem_range, degree_eq_natDegree (hP.pow _).ne_zero] simp only [Nat.cast_lt, hP.natDegree_pow] intro k exact nsmul_lt_nsmul_left hdeg · rw [bot_lt_iff_ne_bot, Ne, degree_eq_bot] exact (hP.pow _).ne_zero theorem Monic.geom_sum' {P : R[X]} (hP : P.Monic) (hdeg : 0 < P.degree) {n : ℕ} (hn : n ≠ 0) : (∑ i ∈ range n, P ^ i).Monic := hP.geom_sum (natDegree_pos_iff_degree_pos.2 hdeg) hn theorem monic_geom_sum_X {n : ℕ} (hn : n ≠ 0) : (∑ i ∈ range n, (X : R[X]) ^ i).Monic := by nontriviality R apply monic_X.geom_sum _ hn simp only [natDegree_X, zero_lt_one] end Semiring section Ring variable [Ring R] /-- Given a polynomial, return the polynomial whose coefficients are in the ring closure of the original coefficients. -/ def restriction (p : R[X]) : Polynomial (Subring.closure (↑p.coeffs : Set R)) := ∑ i ∈ p.support, monomial i (⟨p.coeff i, letI := Classical.decEq R if H : p.coeff i = 0 then H.symm ▸ (Subring.closure _).zero_mem else Subring.subset_closure (p.coeff_mem_coeffs _ H)⟩ : Subring.closure (↑p.coeffs : Set R)) @[simp] theorem coeff_restriction {p : R[X]} {n : ℕ} : ↑(coeff (restriction p) n) = coeff p n := by classical simp only [restriction, coeff_monomial, finset_sum_coeff, mem_support_iff, Finset.sum_ite_eq', Ne, ite_not] split_ifs with h · rw [h] rfl · rfl -- Porting note: removed @[simp] as simp can prove this theorem coeff_restriction' {p : R[X]} {n : ℕ} : (coeff (restriction p) n).1 = coeff p n := coeff_restriction @[simp] theorem support_restriction (p : R[X]) : support (restriction p) = support p := by ext i simp only [mem_support_iff, not_iff_not, Ne] conv_rhs => rw [← coeff_restriction] exact ⟨fun H => by rw [H, ZeroMemClass.coe_zero], fun H => Subtype.coe_injective H⟩ @[simp] theorem map_restriction {R : Type u} [CommRing R] (p : R[X]) : p.restriction.map (algebraMap _ _) = p := ext fun n => by rw [coeff_map, Algebra.algebraMap_ofSubring_apply, coeff_restriction] @[simp] theorem degree_restriction {p : R[X]} : (restriction p).degree = p.degree := by simp [degree] @[simp] theorem natDegree_restriction {p : R[X]} : (restriction p).natDegree = p.natDegree := by simp [natDegree] @[simp] theorem monic_restriction {p : R[X]} : Monic (restriction p) ↔ Monic p := by simp only [Monic, leadingCoeff, natDegree_restriction] rw [← @coeff_restriction _ _ p] exact ⟨fun H => by rw [H, OneMemClass.coe_one], fun H => Subtype.coe_injective H⟩ @[simp] theorem restriction_zero : restriction (0 : R[X]) = 0 := by simp only [restriction, Finset.sum_empty, support_zero] @[simp] theorem restriction_one : restriction (1 : R[X]) = 1 := ext fun i => Subtype.eq <| by rw [coeff_restriction', coeff_one, coeff_one]; split_ifs <;> rfl variable [Semiring S] {f : R →+* S} {x : S} theorem eval₂_restriction {p : R[X]} : eval₂ f x p = eval₂ (f.comp (Subring.subtype (Subring.closure (p.coeffs : Set R)))) x p.restriction := by simp only [eval₂_eq_sum, sum, support_restriction, ← @coeff_restriction _ _ p, RingHom.comp_apply, Subring.coeSubtype] section ToSubring variable (p : R[X]) (T : Subring R) /-- Given a polynomial `p` and a subring `T` that contains the coefficients of `p`, return the corresponding polynomial whose coefficients are in `T`. -/ def toSubring (hp : (↑p.coeffs : Set R) ⊆ T) : T[X] := ∑ i ∈ p.support, monomial i (⟨p.coeff i, letI := Classical.decEq R if H : p.coeff i = 0 then H.symm ▸ T.zero_mem else hp (p.coeff_mem_coeffs _ H)⟩ : T) variable (hp : (↑p.coeffs : Set R) ⊆ T) @[simp] theorem coeff_toSubring {n : ℕ} : ↑(coeff (toSubring p T hp) n) = coeff p n := by classical simp only [toSubring, coeff_monomial, finset_sum_coeff, mem_support_iff, Finset.sum_ite_eq', Ne, ite_not] split_ifs with h · rw [h] rfl · rfl -- Porting note: removed @[simp] as simp can prove this theorem coeff_toSubring' {n : ℕ} : (coeff (toSubring p T hp) n).1 = coeff p n := coeff_toSubring _ _ hp @[simp] theorem support_toSubring : support (toSubring p T hp) = support p := by ext i simp only [mem_support_iff, not_iff_not, Ne] conv_rhs => rw [← coeff_toSubring p T hp] exact ⟨fun H => by rw [H, ZeroMemClass.coe_zero], fun H => Subtype.coe_injective H⟩ @[simp] theorem degree_toSubring : (toSubring p T hp).degree = p.degree := by simp [degree] @[simp] theorem natDegree_toSubring : (toSubring p T hp).natDegree = p.natDegree := by simp [natDegree] @[simp] theorem monic_toSubring : Monic (toSubring p T hp) ↔ Monic p := by simp_rw [Monic, leadingCoeff, natDegree_toSubring, ← coeff_toSubring p T hp] exact ⟨fun H => by rw [H, OneMemClass.coe_one], fun H => Subtype.coe_injective H⟩ @[simp] theorem toSubring_zero : toSubring (0 : R[X]) T (by simp [coeffs]) = 0 := by ext i simp @[simp] theorem toSubring_one : toSubring (1 : R[X]) T (Set.Subset.trans coeffs_one <| Finset.singleton_subset_set_iff.2 T.one_mem) = 1 := ext fun i => Subtype.eq <| by rw [coeff_toSubring', coeff_one, coeff_one, apply_ite Subtype.val, ZeroMemClass.coe_zero, OneMemClass.coe_one] @[simp] theorem map_toSubring : (p.toSubring T hp).map (Subring.subtype T) = p := by ext n simp [coeff_map] end ToSubring variable (T : Subring R) /-- Given a polynomial whose coefficients are in some subring, return the corresponding polynomial whose coefficients are in the ambient ring. -/ def ofSubring (p : T[X]) : R[X] := ∑ i ∈ p.support, monomial i (p.coeff i : R) theorem coeff_ofSubring (p : T[X]) (n : ℕ) : coeff (ofSubring T p) n = (coeff p n : T) := by simp only [ofSubring, coeff_monomial, finset_sum_coeff, mem_support_iff, Finset.sum_ite_eq', ite_eq_right_iff, Ne, ite_not, Classical.not_not, ite_eq_left_iff] intro h rw [h, ZeroMemClass.coe_zero] @[simp] theorem coeffs_ofSubring {p : T[X]} : (↑(p.ofSubring T).coeffs : Set R) ⊆ T := by classical intro i hi simp only [coeffs, Set.mem_image, mem_support_iff, Ne, Finset.mem_coe, (Finset.coe_image)] at hi rcases hi with ⟨n, _, h'n⟩ rw [← h'n, coeff_ofSubring] exact Subtype.mem (coeff p n : T) @[deprecated (since := "2024-05-17")] alias frange_ofSubring := coeffs_ofSubring end Ring section CommRing variable [CommRing R] section ModByMonic variable {q : R[X]} theorem mem_ker_modByMonic (hq : q.Monic) {p : R[X]} : p ∈ LinearMap.ker (modByMonicHom q) ↔ q ∣ p := LinearMap.mem_ker.trans (modByMonic_eq_zero_iff_dvd hq) @[simp] theorem ker_modByMonicHom (hq : q.Monic) : LinearMap.ker (Polynomial.modByMonicHom q) = (Ideal.span {q}).restrictScalars R := Submodule.ext fun _ => (mem_ker_modByMonic hq).trans Ideal.mem_span_singleton.symm end ModByMonic end CommRing end Polynomial namespace Ideal open Polynomial section Semiring variable [Semiring R] /-- Transport an ideal of `R[X]` to an `R`-submodule of `R[X]`. -/ def ofPolynomial (I : Ideal R[X]) : Submodule R R[X] where carrier := I.carrier zero_mem' := I.zero_mem add_mem' := I.add_mem smul_mem' c x H := by rw [← C_mul'] exact I.mul_mem_left _ H variable {I : Ideal R[X]} theorem mem_ofPolynomial (x) : x ∈ I.ofPolynomial ↔ x ∈ I := Iff.rfl variable (I) /-- Given an ideal `I` of `R[X]`, make the `R`-submodule of `I` consisting of polynomials of degree ≤ `n`. -/ def degreeLE (n : WithBot ℕ) : Submodule R R[X] := Polynomial.degreeLE R n ⊓ I.ofPolynomial /-- Given an ideal `I` of `R[X]`, make the ideal in `R` of leading coefficients of polynomials in `I` with degree ≤ `n`. -/ def leadingCoeffNth (n : ℕ) : Ideal R := (I.degreeLE n).map <| lcoeff R n /-- Given an ideal `I` in `R[X]`, make the ideal in `R` of the leading coefficients in `I`. -/ def leadingCoeff : Ideal R := ⨆ n : ℕ, I.leadingCoeffNth n end Semiring section CommSemiring variable [CommSemiring R] [Semiring S] /-- If every coefficient of a polynomial is in an ideal `I`, then so is the polynomial itself -/ theorem polynomial_mem_ideal_of_coeff_mem_ideal (I : Ideal R[X]) (p : R[X]) (hp : ∀ n : ℕ, p.coeff n ∈ I.comap (C : R →+* R[X])) : p ∈ I := sum_C_mul_X_pow_eq p ▸ Submodule.sum_mem I fun n _ => I.mul_mem_right _ (hp n) /-- The push-forward of an ideal `I` of `R` to `R[X]` via inclusion is exactly the set of polynomials whose coefficients are in `I` -/ theorem mem_map_C_iff {I : Ideal R} {f : R[X]} : f ∈ (Ideal.map (C : R →+* R[X]) I : Ideal R[X]) ↔ ∀ n : ℕ, f.coeff n ∈ I := by constructor · intro hf apply @Submodule.span_induction _ _ _ _ _ f _ _ hf · intro f hf n cases' (Set.mem_image _ _ _).mp hf with x hx rw [← hx.right, coeff_C] by_cases h : n = 0 · simpa [h] using hx.left · simp [h] · simp · exact fun f g hf hg n => by simp [I.add_mem (hf n) (hg n)] · refine fun f g hg n => ?_ rw [smul_eq_mul, coeff_mul] exact I.sum_mem fun c _ => I.mul_mem_left (f.coeff c.fst) (hg c.snd) · intro hf rw [← sum_monomial_eq f] refine (I.map C : Ideal R[X]).sum_mem fun n _ => ?_ simp only [← C_mul_X_pow_eq_monomial, ne_eq] rw [mul_comm] exact (I.map C : Ideal R[X]).mul_mem_left _ (mem_map_of_mem _ (hf n)) theorem _root_.Polynomial.ker_mapRingHom (f : R →+* S) : LinearMap.ker (Polynomial.mapRingHom f).toSemilinearMap = f.ker.map (C : R →+* R[X]) := by ext simp only [LinearMap.mem_ker, RingHom.toSemilinearMap_apply, coe_mapRingHom] rw [mem_map_C_iff, Polynomial.ext_iff] simp_rw [RingHom.mem_ker f] simp variable (I : Ideal R[X]) theorem mem_leadingCoeffNth (n : ℕ) (x) : x ∈ I.leadingCoeffNth n ↔ ∃ p ∈ I, degree p ≤ n ∧ p.leadingCoeff = x := by simp only [leadingCoeffNth, degreeLE, Submodule.mem_map, lcoeff_apply, Submodule.mem_inf, mem_degreeLE] constructor · rintro ⟨p, ⟨hpdeg, hpI⟩, rfl⟩ rcases lt_or_eq_of_le hpdeg with hpdeg | hpdeg · refine ⟨0, I.zero_mem, bot_le, ?_⟩ rw [leadingCoeff_zero, eq_comm] exact coeff_eq_zero_of_degree_lt hpdeg · refine ⟨p, hpI, le_of_eq hpdeg, ?_⟩ rw [Polynomial.leadingCoeff, natDegree, hpdeg, Nat.cast_withBot, WithBot.unbot'_coe] · rintro ⟨p, hpI, hpdeg, rfl⟩ have : natDegree p + (n - natDegree p) = n := add_tsub_cancel_of_le (natDegree_le_of_degree_le hpdeg) refine ⟨p * X ^ (n - natDegree p), ⟨?_, I.mul_mem_right _ hpI⟩, ?_⟩ · apply le_trans (degree_mul_le _ _) _ apply le_trans (add_le_add degree_le_natDegree (degree_X_pow_le _)) _ rw [← Nat.cast_add, this] · rw [Polynomial.leadingCoeff, ← coeff_mul_X_pow p (n - natDegree p), this] theorem mem_leadingCoeffNth_zero (x) : x ∈ I.leadingCoeffNth 0 ↔ C x ∈ I := (mem_leadingCoeffNth _ _ _).trans ⟨fun ⟨p, hpI, hpdeg, hpx⟩ => by rwa [← hpx, Polynomial.leadingCoeff, Nat.eq_zero_of_le_zero (natDegree_le_of_degree_le hpdeg), ← eq_C_of_degree_le_zero hpdeg], fun hx => ⟨C x, hx, degree_C_le, leadingCoeff_C x⟩⟩ theorem leadingCoeffNth_mono {m n : ℕ} (H : m ≤ n) : I.leadingCoeffNth m ≤ I.leadingCoeffNth n := by intro r hr simp only [SetLike.mem_coe, mem_leadingCoeffNth] at hr ⊢ rcases hr with ⟨p, hpI, hpdeg, rfl⟩ refine ⟨p * X ^ (n - m), I.mul_mem_right _ hpI, ?_, leadingCoeff_mul_X_pow⟩ refine le_trans (degree_mul_le _ _) ?_ refine le_trans (add_le_add hpdeg (degree_X_pow_le _)) ?_ rw [← Nat.cast_add, add_tsub_cancel_of_le H] theorem mem_leadingCoeff (x) : x ∈ I.leadingCoeff ↔ ∃ p ∈ I, Polynomial.leadingCoeff p = x := by rw [leadingCoeff, Submodule.mem_iSup_of_directed] · simp only [mem_leadingCoeffNth] constructor · rintro ⟨i, p, hpI, _, rfl⟩ exact ⟨p, hpI, rfl⟩ rintro ⟨p, hpI, rfl⟩ exact ⟨natDegree p, p, hpI, degree_le_natDegree, rfl⟩ intro i j exact ⟨i + j, I.leadingCoeffNth_mono (Nat.le_add_right _ _), I.leadingCoeffNth_mono (Nat.le_add_left _ _)⟩ /-- If `I` is an ideal, and `pᵢ` is a finite family of polynomials each satisfying `∀ k, (pᵢ)ₖ ∈ Iⁿⁱ⁻ᵏ` for some `nᵢ`, then `p = ∏ pᵢ` also satisfies `∀ k, pₖ ∈ Iⁿ⁻ᵏ` with `n = ∑ nᵢ`. -/ theorem _root_.Polynomial.coeff_prod_mem_ideal_pow_tsub {ι : Type*} (s : Finset ι) (f : ι → R[X]) (I : Ideal R) (n : ι → ℕ) (h : ∀ i ∈ s, ∀ (k), (f i).coeff k ∈ I ^ (n i - k)) (k : ℕ) : (s.prod f).coeff k ∈ I ^ (s.sum n - k) := by classical induction' s using Finset.induction with a s ha hs generalizing k · rw [sum_empty, prod_empty, coeff_one, zero_tsub, pow_zero, Ideal.one_eq_top] exact Submodule.mem_top · rw [sum_insert ha, prod_insert ha, coeff_mul] apply sum_mem rintro ⟨i, j⟩ e obtain rfl : i + j = k := mem_antidiagonal.mp e apply Ideal.pow_le_pow_right add_tsub_add_le_tsub_add_tsub rw [pow_add] exact Ideal.mul_mem_mul (h _ (Finset.mem_insert.mpr <| Or.inl rfl) _) (hs (fun i hi k => h _ (Finset.mem_insert.mpr <| Or.inr hi) _) j) end CommSemiring section Ring variable [Ring R] /-- `R[X]` is never a field for any ring `R`. -/ theorem polynomial_not_isField : ¬IsField R[X] := by nontriviality R intro hR obtain ⟨p, hp⟩ := hR.mul_inv_cancel X_ne_zero have hp0 : p ≠ 0 := right_ne_zero_of_mul_eq_one hp have := degree_lt_degree_mul_X hp0 rw [← X_mul, congr_arg degree hp, degree_one, Nat.WithBot.lt_zero_iff, degree_eq_bot] at this exact hp0 this /-- The only constant in a maximal ideal over a field is `0`. -/ theorem eq_zero_of_constant_mem_of_maximal (hR : IsField R) (I : Ideal R[X]) [hI : I.IsMaximal] (x : R) (hx : C x ∈ I) : x = 0 := by refine Classical.by_contradiction fun hx0 => hI.ne_top ((eq_top_iff_one I).2 ?_) obtain ⟨y, hy⟩ := hR.mul_inv_cancel hx0 convert I.mul_mem_left (C y) hx rw [← C.map_mul, hR.mul_comm y x, hy, RingHom.map_one] end Ring section CommRing variable [CommRing R] /-- If `P` is a prime ideal of `R`, then `P.R[x]` is a prime ideal of `R[x]`. -/ theorem isPrime_map_C_iff_isPrime (P : Ideal R) : IsPrime (map (C : R →+* R[X]) P : Ideal R[X]) ↔ IsPrime P := by -- Note: the following proof avoids quotient rings -- It can be golfed substantially by using something like -- `(Quotient.isDomain_iff_prime (map C P : Ideal R[X]))` constructor · intro H have := comap_isPrime C (map C P) convert this using 1 ext x simp only [mem_comap, mem_map_C_iff] constructor · rintro h (- | n) · rwa [coeff_C_zero] · simp only [coeff_C_ne_zero (Nat.succ_ne_zero _), Submodule.zero_mem] · intro h simpa only [coeff_C_zero] using h 0 · intro h constructor · rw [Ne, eq_top_iff_one, mem_map_C_iff, not_forall] use 0 rw [coeff_one_zero, ← eq_top_iff_one] exact h.1 · intro f g simp only [mem_map_C_iff] contrapose! rintro ⟨hf, hg⟩ classical let m := Nat.find hf let n := Nat.find hg refine ⟨m + n, ?_⟩ rw [coeff_mul, ← Finset.insert_erase ((Finset.mem_antidiagonal (a := (m,n))).mpr rfl), Finset.sum_insert (Finset.not_mem_erase _ _), (P.add_mem_iff_left _).not] · apply mt h.2 rw [not_or] exact ⟨Nat.find_spec hf, Nat.find_spec hg⟩ apply P.sum_mem rintro ⟨i, j⟩ hij rw [Finset.mem_erase, Finset.mem_antidiagonal] at hij simp only [Ne, Prod.mk.inj_iff, not_and_or] at hij obtain hi | hj : i < m ∨ j < n := by rw [or_iff_not_imp_left, not_lt, le_iff_lt_or_eq] rintro (hmi | rfl) · rw [← not_le] intro hnj exact (add_lt_add_of_lt_of_le hmi hnj).ne hij.2.symm · simp only [eq_self_iff_true, not_true, false_or_iff, add_right_inj, not_and_self_iff] at hij · rw [mul_comm] apply P.mul_mem_left exact Classical.not_not.1 (Nat.find_min hf hi) · apply P.mul_mem_left exact Classical.not_not.1 (Nat.find_min hg hj) /-- If `P` is a prime ideal of `R`, then `P.R[x]` is a prime ideal of `R[x]`. -/ theorem isPrime_map_C_of_isPrime {P : Ideal R} (H : IsPrime P) : IsPrime (map (C : R →+* R[X]) P : Ideal R[X]) := (isPrime_map_C_iff_isPrime P).mpr H theorem is_fg_degreeLE [IsNoetherianRing R] (I : Ideal R[X]) (n : ℕ) : Submodule.FG (I.degreeLE n) := letI := Classical.decEq R isNoetherian_submodule_left.1 (isNoetherian_of_fg_of_noetherian _ ⟨_, degreeLE_eq_span_X_pow.symm⟩) _ end CommRing end Ideal variable {σ : Type v} {M : Type w} variable [CommRing R] [CommRing S] [AddCommGroup M] [Module R M] section Prime variable (σ) {r : R} namespace Polynomial theorem prime_C_iff : Prime (C r) ↔ Prime r := ⟨comap_prime C (evalRingHom (0 : R)) fun r => eval_C, fun hr => by have := hr.1 rw [← Ideal.span_singleton_prime] at hr ⊢ · rw [← Set.image_singleton, ← Ideal.map_span] apply Ideal.isPrime_map_C_of_isPrime hr · intro h; apply (this (C_eq_zero.mp h)) · assumption⟩ end Polynomial namespace MvPolynomial private theorem prime_C_iff_of_fintype {R : Type u} (σ : Type v) {r : R} [CommRing R] [Fintype σ] : Prime (C r : MvPolynomial σ R) ↔ Prime r := by rw [(renameEquiv R (Fintype.equivFin σ)).toMulEquiv.prime_iff] convert_to Prime (C r) ↔ _ · congr! apply rename_C · symm induction' Fintype.card σ with d hd · exact (isEmptyAlgEquiv R (Fin 0)).toMulEquiv.symm.prime_iff · rw [hd, ← Polynomial.prime_C_iff] convert (finSuccEquiv R d).toMulEquiv.symm.prime_iff (p := Polynomial.C (C r)) rw [← finSuccEquiv_comp_C_eq_C] simp_rw [RingHom.coe_comp, RingHom.coe_coe, Function.comp_apply, MulEquiv.symm_mk, AlgEquiv.toEquiv_eq_coe, AlgEquiv.symm_toEquiv_eq_symm, MulEquiv.coe_mk, EquivLike.coe_coe] theorem prime_C_iff : Prime (C r : MvPolynomial σ R) ↔ Prime r := ⟨comap_prime C constantCoeff (constantCoeff_C _), fun hr => ⟨fun h => hr.1 <| by rw [← C_inj, h] simp, fun h => hr.2.1 <| by rw [← constantCoeff_C _ r] exact h.map _, fun a b hd => by obtain ⟨s, a', b', rfl, rfl⟩ := exists_finset_rename₂ a b rw [← algebraMap_eq] at hd have : algebraMap R _ r ∣ a' * b' := by convert killCompl Subtype.coe_injective |>.toRingHom.map_dvd hd <;> simp rw [← rename_C ((↑) : s → σ)] let f := (rename (R := R) ((↑) : s → σ)).toRingHom exact (((prime_C_iff_of_fintype s).2 hr).2.2 a' b' this).imp f.map_dvd f.map_dvd⟩⟩ variable {σ} theorem prime_rename_iff (s : Set σ) {p : MvPolynomial s R} : Prime (rename ((↑) : s → σ) p) ↔ Prime (p : MvPolynomial s R) := by classical symm let eqv := (sumAlgEquiv R (↥sᶜ) s).symm.trans (renameEquiv R <| (Equiv.sumComm (↥sᶜ) s).trans <| Equiv.Set.sumCompl s) have : (rename (↑)).toRingHom = eqv.toAlgHom.toRingHom.comp C := by apply ringHom_ext · intro simp only [eqv, AlgHom.toRingHom_eq_coe, RingHom.coe_coe, rename_C, AlgEquiv.toAlgHom_eq_coe, AlgEquiv.toAlgHom_toRingHom, RingHom.coe_comp, AlgEquiv.coe_trans, Function.comp_apply, MvPolynomial.sumAlgEquiv_symm_apply, iterToSum_C_C, renameEquiv_apply, Equiv.coe_trans, Equiv.sumComm_apply] · intro simp only [eqv, AlgHom.toRingHom_eq_coe, RingHom.coe_coe, rename_X, AlgEquiv.toAlgHom_eq_coe, AlgEquiv.toAlgHom_toRingHom, RingHom.coe_comp, AlgEquiv.coe_trans, Function.comp_apply, MvPolynomial.sumAlgEquiv_symm_apply, iterToSum_C_X, renameEquiv_apply, Equiv.coe_trans, Equiv.sumComm_apply, Sum.swap_inr, Equiv.Set.sumCompl_apply_inl] apply_fun (· p) at this simp_rw [AlgHom.toRingHom_eq_coe, RingHom.coe_coe] at this rw [← prime_C_iff, eqv.toMulEquiv.prime_iff, this] simp only [MulEquiv.coe_mk, AlgEquiv.toEquiv_eq_coe, EquivLike.coe_coe, AlgEquiv.trans_apply, MvPolynomial.sumAlgEquiv_symm_apply, renameEquiv_apply, Equiv.coe_trans, Equiv.sumComm_apply, AlgEquiv.toAlgHom_eq_coe, AlgEquiv.toAlgHom_toRingHom, RingHom.coe_comp, RingHom.coe_coe, AlgEquiv.coe_trans, Function.comp_apply] end MvPolynomial end Prime namespace Polynomial instance (priority := 100) wfDvdMonoid {R : Type*} [CommRing R] [IsDomain R] [WfDvdMonoid R] : WfDvdMonoid R[X] where wellFounded_dvdNotUnit := by classical refine RelHomClass.wellFounded (⟨fun p : R[X] => ((if p = 0 then ⊤ else ↑p.degree : WithTop (WithBot ℕ)), p.leadingCoeff), ?_⟩ : DvdNotUnit →r Prod.Lex (· < ·) DvdNotUnit) (wellFounded_lt.prod_lex ‹WfDvdMonoid R›.wellFounded_dvdNotUnit) rintro a b ⟨ane0, ⟨c, ⟨not_unit_c, rfl⟩⟩⟩ dsimp rw [Polynomial.degree_mul, if_neg ane0] split_ifs with hac · rw [hac, Polynomial.leadingCoeff_zero] apply Prod.Lex.left exact WithTop.coe_lt_top _ have cne0 : c ≠ 0 := right_ne_zero_of_mul hac simp only [cne0, ane0, Polynomial.leadingCoeff_mul] by_cases hdeg : c.degree = (0 : ℕ) · simp only [hdeg, Nat.cast_zero, add_zero] refine Prod.Lex.right _ ⟨?_, ⟨c.leadingCoeff, fun unit_c => not_unit_c ?_, rfl⟩⟩ · rwa [Ne, Polynomial.leadingCoeff_eq_zero] rw [Polynomial.isUnit_iff, Polynomial.eq_C_of_degree_eq_zero hdeg] use c.leadingCoeff, unit_c rw [Polynomial.leadingCoeff, Polynomial.natDegree_eq_of_degree_eq_some hdeg] · apply Prod.Lex.left rw [Polynomial.degree_eq_natDegree cne0] at * simp only [Nat.cast_inj] at hdeg rw [WithTop.coe_lt_coe, Polynomial.degree_eq_natDegree ane0, ← Nat.cast_add, Nat.cast_lt] exact lt_add_of_pos_right _ (Nat.pos_of_ne_zero hdeg) end Polynomial /-- Hilbert basis theorem: a polynomial ring over a noetherian ring is a noetherian ring. -/ protected theorem Polynomial.isNoetherianRing [inst : IsNoetherianRing R] : IsNoetherianRing R[X] := isNoetherianRing_iff.2 ⟨fun I : Ideal R[X] => let M := WellFounded.min (isNoetherian_iff_wellFounded.1 (by infer_instance)) (Set.range I.leadingCoeffNth) ⟨_, ⟨0, rfl⟩⟩ have hm : M ∈ Set.range I.leadingCoeffNth := WellFounded.min_mem _ _ _ let ⟨N, HN⟩ := hm let ⟨s, hs⟩ := I.is_fg_degreeLE N have hm2 : ∀ k, I.leadingCoeffNth k ≤ M := fun k => Or.casesOn (le_or_lt k N) (fun h => HN ▸ I.leadingCoeffNth_mono h) fun h x hx => Classical.by_contradiction fun hxm => haveI : IsNoetherian R R := inst have : ¬M < I.leadingCoeffNth k := by refine WellFounded.not_lt_min (wellFounded_submodule_gt R R) _ _ ?_; exact ⟨k, rfl⟩ this ⟨HN ▸ I.leadingCoeffNth_mono (le_of_lt h), fun H => hxm (H hx)⟩ have hs2 : ∀ {x}, x ∈ I.degreeLE N → x ∈ Ideal.span (↑s : Set R[X]) := hs ▸ fun hx => Submodule.span_induction hx (fun _ hx => Ideal.subset_span hx) (Ideal.zero_mem _) (fun _ _ => Ideal.add_mem _) fun c f hf => f.C_mul' c ▸ Ideal.mul_mem_left _ _ hf ⟨s, le_antisymm (Ideal.span_le.2 fun x hx => have : x ∈ I.degreeLE N := hs ▸ Submodule.subset_span hx this.2) <| by have : Submodule.span R[X] ↑s = Ideal.span ↑s := rfl rw [this] intro p hp generalize hn : p.natDegree = k induction' k using Nat.strong_induction_on with k ih generalizing p rcases le_or_lt k N with h | h · subst k refine hs2 ⟨Polynomial.mem_degreeLE.2 (le_trans Polynomial.degree_le_natDegree <| WithBot.coe_le_coe.2 h), hp⟩ · have hp0 : p ≠ 0 := by rintro rfl cases hn exact Nat.not_lt_zero _ h have : (0 : R) ≠ 1 := by intro h apply hp0 ext i refine (mul_one _).symm.trans ?_ rw [← h, mul_zero] rfl haveI : Nontrivial R := ⟨⟨0, 1, this⟩⟩ have : p.leadingCoeff ∈ I.leadingCoeffNth N := by rw [HN] exact hm2 k ((I.mem_leadingCoeffNth _ _).2 ⟨_, hp, hn ▸ Polynomial.degree_le_natDegree, rfl⟩) rw [I.mem_leadingCoeffNth] at this rcases this with ⟨q, hq, hdq, hlqp⟩ have hq0 : q ≠ 0 := by intro H rw [← Polynomial.leadingCoeff_eq_zero] at H rw [hlqp, Polynomial.leadingCoeff_eq_zero] at H exact hp0 H have h1 : p.degree = (q * Polynomial.X ^ (k - q.natDegree)).degree := by rw [Polynomial.degree_mul', Polynomial.degree_X_pow] · rw [Polynomial.degree_eq_natDegree hp0, Polynomial.degree_eq_natDegree hq0] rw [← Nat.cast_add, add_tsub_cancel_of_le, hn] · refine le_trans (Polynomial.natDegree_le_of_degree_le hdq) (le_of_lt h) rw [Polynomial.leadingCoeff_X_pow, mul_one] exact mt Polynomial.leadingCoeff_eq_zero.1 hq0 have h2 : p.leadingCoeff = (q * Polynomial.X ^ (k - q.natDegree)).leadingCoeff := by rw [← hlqp, Polynomial.leadingCoeff_mul_X_pow] have := Polynomial.degree_sub_lt h1 hp0 h2 rw [Polynomial.degree_eq_natDegree hp0] at this rw [← sub_add_cancel p (q * Polynomial.X ^ (k - q.natDegree))] convert (Ideal.span ↑s).add_mem _ ((Ideal.span (s : Set R[X])).mul_mem_right _ _) · by_cases hpq : p - q * Polynomial.X ^ (k - q.natDegree) = 0 · rw [hpq] exact Ideal.zero_mem _ refine ih _ ?_ (I.sub_mem hp (I.mul_mem_right _ hq)) rfl rwa [Polynomial.degree_eq_natDegree hpq, Nat.cast_lt, hn] at this exact hs2 ⟨Polynomial.mem_degreeLE.2 hdq, hq⟩⟩⟩ attribute [instance] Polynomial.isNoetherianRing namespace Polynomial theorem exists_irreducible_of_degree_pos {R : Type u} [CommRing R] [IsDomain R] [WfDvdMonoid R] {f : R[X]} (hf : 0 < f.degree) : ∃ g, Irreducible g ∧ g ∣ f := WfDvdMonoid.exists_irreducible_factor (fun huf => ne_of_gt hf <| degree_eq_zero_of_isUnit huf) fun hf0 => not_lt_of_lt hf <| hf0.symm ▸ (@degree_zero R _).symm ▸ WithBot.bot_lt_coe _ theorem exists_irreducible_of_natDegree_pos {R : Type u} [CommRing R] [IsDomain R] [WfDvdMonoid R] {f : R[X]} (hf : 0 < f.natDegree) : ∃ g, Irreducible g ∧ g ∣ f := exists_irreducible_of_degree_pos <| by contrapose! hf exact natDegree_le_of_degree_le hf theorem exists_irreducible_of_natDegree_ne_zero {R : Type u} [CommRing R] [IsDomain R] [WfDvdMonoid R] {f : R[X]} (hf : f.natDegree ≠ 0) : ∃ g, Irreducible g ∧ g ∣ f := exists_irreducible_of_natDegree_pos <| Nat.pos_of_ne_zero hf theorem linearIndependent_powers_iff_aeval (f : M →ₗ[R] M) (v : M) : (LinearIndependent R fun n : ℕ => (f ^ n) v) ↔ ∀ p : R[X], aeval f p v = 0 → p = 0 := by rw [linearIndependent_iff] simp only [Finsupp.total_apply, aeval_endomorphism, forall_iff_forall_finsupp, Sum, support, coeff, ofFinsupp_eq_zero] exact Iff.rfl attribute [-instance] Ring.toNonAssocRing theorem disjoint_ker_aeval_of_coprime (f : M →ₗ[R] M) {p q : R[X]} (hpq : IsCoprime p q) : Disjoint (LinearMap.ker (aeval f p)) (LinearMap.ker (aeval f q)) := by rw [disjoint_iff_inf_le] intro v hv rcases hpq with ⟨p', q', hpq'⟩ simpa [LinearMap.mem_ker.1 (Submodule.mem_inf.1 hv).1, LinearMap.mem_ker.1 (Submodule.mem_inf.1 hv).2] using congr_arg (fun p : R[X] => aeval f p v) hpq'.symm theorem sup_aeval_range_eq_top_of_coprime (f : M →ₗ[R] M) {p q : R[X]} (hpq : IsCoprime p q) : LinearMap.range (aeval f p) ⊔ LinearMap.range (aeval f q) = ⊤ := by rw [eq_top_iff] intro v _ rw [Submodule.mem_sup] rcases hpq with ⟨p', q', hpq'⟩ use aeval f (p * p') v use LinearMap.mem_range.2 ⟨aeval f p' v, by simp only [LinearMap.mul_apply, aeval_mul]⟩ use aeval f (q * q') v use LinearMap.mem_range.2 ⟨aeval f q' v, by simp only [LinearMap.mul_apply, aeval_mul]⟩ simpa only [mul_comm p p', mul_comm q q', aeval_one, aeval_add] using congr_arg (fun p : R[X] => aeval f p v) hpq' theorem sup_ker_aeval_le_ker_aeval_mul {f : M →ₗ[R] M} {p q : R[X]} : LinearMap.ker (aeval f p) ⊔ LinearMap.ker (aeval f q) ≤ LinearMap.ker (aeval f (p * q)) := by intro v hv rcases Submodule.mem_sup.1 hv with ⟨x, hx, y, hy, hxy⟩ have h_eval_x : aeval f (p * q) x = 0 := by rw [mul_comm, aeval_mul, LinearMap.mul_apply, LinearMap.mem_ker.1 hx, LinearMap.map_zero] have h_eval_y : aeval f (p * q) y = 0 := by rw [aeval_mul, LinearMap.mul_apply, LinearMap.mem_ker.1 hy, LinearMap.map_zero] rw [LinearMap.mem_ker, ← hxy, LinearMap.map_add, h_eval_x, h_eval_y, add_zero] theorem sup_ker_aeval_eq_ker_aeval_mul_of_coprime (f : M →ₗ[R] M) {p q : R[X]} (hpq : IsCoprime p q) : LinearMap.ker (aeval f p) ⊔ LinearMap.ker (aeval f q) = LinearMap.ker (aeval f (p * q)) := by apply le_antisymm sup_ker_aeval_le_ker_aeval_mul intro v hv rw [Submodule.mem_sup] rcases hpq with ⟨p', q', hpq'⟩ have h_eval₂_qpp' := calc aeval f (q * (p * p')) v = aeval f (p' * (p * q)) v := by rw [mul_comm, mul_assoc, mul_comm, mul_assoc, mul_comm q p] _ = 0 := by rw [aeval_mul, LinearMap.mul_apply, LinearMap.mem_ker.1 hv, LinearMap.map_zero] have h_eval₂_pqq' := calc aeval f (p * (q * q')) v = aeval f (q' * (p * q)) v := by rw [← mul_assoc, mul_comm] _ = 0 := by rw [aeval_mul, LinearMap.mul_apply, LinearMap.mem_ker.1 hv, LinearMap.map_zero] rw [aeval_mul] at h_eval₂_qpp' h_eval₂_pqq' refine ⟨aeval f (q * q') v, LinearMap.mem_ker.1 h_eval₂_pqq', aeval f (p * p') v, LinearMap.mem_ker.1 h_eval₂_qpp', ?_⟩ rw [add_comm, mul_comm p p', mul_comm q q'] simpa only [map_add, map_mul, aeval_one] using congr_arg (fun p : R[X] => aeval f p v) hpq' end Polynomial namespace MvPolynomial lemma aeval_natDegree_le {R : Type*} [CommSemiring R] {m n : ℕ} (F : MvPolynomial σ R) (hF : F.totalDegree ≤ m) (f : σ → Polynomial R) (hf : ∀ i, (f i).natDegree ≤ n) : (MvPolynomial.aeval f F).natDegree ≤ m * n := by rw [MvPolynomial.aeval_def, MvPolynomial.eval₂] apply (Polynomial.natDegree_sum_le _ _).trans apply Finset.sup_le intro d hd simp_rw [Function.comp_apply, ← C_eq_algebraMap] apply (Polynomial.natDegree_C_mul_le _ _).trans apply (Polynomial.natDegree_prod_le _ _).trans have : ∑ i ∈ d.support, (d i) * n ≤ m * n := by rw [← Finset.sum_mul] apply mul_le_mul' (.trans _ hF) le_rfl rw [MvPolynomial.totalDegree] exact Finset.le_sup_of_le hd le_rfl apply (Finset.sum_le_sum _).trans this rintro i - apply Polynomial.natDegree_pow_le.trans exact mul_le_mul' le_rfl (hf i) theorem isNoetherianRing_fin_0 [IsNoetherianRing R] : IsNoetherianRing (MvPolynomial (Fin 0) R) := by apply isNoetherianRing_of_ringEquiv R symm; apply MvPolynomial.isEmptyRingEquiv R (Fin 0) theorem isNoetherianRing_fin [IsNoetherianRing R] : ∀ {n : ℕ}, IsNoetherianRing (MvPolynomial (Fin n) R) | 0 => isNoetherianRing_fin_0 | n + 1 => @isNoetherianRing_of_ringEquiv (Polynomial (MvPolynomial (Fin n) R)) _ _ _ (MvPolynomial.finSuccEquiv _ n).toRingEquiv.symm (@Polynomial.isNoetherianRing (MvPolynomial (Fin n) R) _ isNoetherianRing_fin) /-- The multivariate polynomial ring in finitely many variables over a noetherian ring is itself a noetherian ring. -/ instance isNoetherianRing [Finite σ] [IsNoetherianRing R] : IsNoetherianRing (MvPolynomial σ R) := by cases nonempty_fintype σ exact @isNoetherianRing_of_ringEquiv (MvPolynomial (Fin (Fintype.card σ)) R) _ _ _ (renameEquiv R (Fintype.equivFin σ).symm).toRingEquiv isNoetherianRing_fin /-- Auxiliary lemma: Multivariate polynomials over an integral domain with variables indexed by `Fin n` form an integral domain. This fact is proven inductively, and then used to prove the general case without any finiteness hypotheses. See `MvPolynomial.noZeroDivisors` for the general case. -/ theorem noZeroDivisors_fin (R : Type u) [CommSemiring R] [NoZeroDivisors R] : ∀ n : ℕ, NoZeroDivisors (MvPolynomial (Fin n) R) | 0 => (MvPolynomial.isEmptyAlgEquiv R _).injective.noZeroDivisors _ (map_zero _) (map_mul _) | n + 1 => haveI := noZeroDivisors_fin R n (MvPolynomial.finSuccEquiv R n).injective.noZeroDivisors _ (map_zero _) (map_mul _) /-- Auxiliary definition: Multivariate polynomials in finitely many variables over an integral domain form an integral domain. This fact is proven by transport of structure from the `MvPolynomial.noZeroDivisors_fin`, and then used to prove the general case without finiteness hypotheses. See `MvPolynomial.noZeroDivisors` for the general case. -/ theorem noZeroDivisors_of_finite (R : Type u) (σ : Type v) [CommSemiring R] [Finite σ] [NoZeroDivisors R] : NoZeroDivisors (MvPolynomial σ R) := by cases nonempty_fintype σ haveI := noZeroDivisors_fin R (Fintype.card σ) exact (renameEquiv R (Fintype.equivFin σ)).injective.noZeroDivisors _ (map_zero _) (map_mul _) instance {R : Type u} [CommSemiring R] [NoZeroDivisors R] {σ : Type v} : NoZeroDivisors (MvPolynomial σ R) where eq_zero_or_eq_zero_of_mul_eq_zero {p q} h := by obtain ⟨s, p, q, rfl, rfl⟩ := exists_finset_rename₂ p q let _nzd := MvPolynomial.noZeroDivisors_of_finite R s have : p * q = 0 := by apply rename_injective _ Subtype.val_injective simpa using h rw [mul_eq_zero] at this apply this.imp <;> rintro rfl <;> simp /-- The multivariate polynomial ring over an integral domain is an integral domain. -/ instance isDomain {R : Type u} {σ : Type v} [CommRing R] [IsDomain R] : IsDomain (MvPolynomial σ R) := by apply @NoZeroDivisors.to_isDomain (MvPolynomial σ R) _ ?_ _ apply AddMonoidAlgebra.nontrivial -- instance {R : Type u} {σ : Type v} [CommRing R] [IsDomain R] : -- IsDomain (MvPolynomial σ R)[X] := inferInstance theorem map_mvPolynomial_eq_eval₂ {S : Type*} [CommRing S] [Finite σ] (ϕ : MvPolynomial σ R →+* S) (p : MvPolynomial σ R) : ϕ p = MvPolynomial.eval₂ (ϕ.comp MvPolynomial.C) (fun s => ϕ (MvPolynomial.X s)) p := by cases nonempty_fintype σ refine Trans.trans (congr_arg ϕ (MvPolynomial.as_sum p)) ?_ rw [MvPolynomial.eval₂_eq', map_sum ϕ] congr ext simp only [monomial_eq, ϕ.map_pow, map_prod ϕ, ϕ.comp_apply, ϕ.map_mul, Finsupp.prod_pow] /-- If every coefficient of a polynomial is in an ideal `I`, then so is the polynomial itself, multivariate version. -/ theorem mem_ideal_of_coeff_mem_ideal (I : Ideal (MvPolynomial σ R)) (p : MvPolynomial σ R) (hcoe : ∀ m : σ →₀ ℕ, p.coeff m ∈ I.comap (C : R →+* MvPolynomial σ R)) : p ∈ I := by rw [as_sum p] suffices ∀ m ∈ p.support, monomial m (MvPolynomial.coeff m p) ∈ I by exact Submodule.sum_mem I this intro m _ rw [← mul_one (coeff m p), ← C_mul_monomial] suffices C (coeff m p) ∈ I by exact I.mul_mem_right (monomial m 1) this simpa [Ideal.mem_comap] using hcoe m /-- The push-forward of an ideal `I` of `R` to `MvPolynomial σ R` via inclusion is exactly the set of polynomials whose coefficients are in `I` -/ theorem mem_map_C_iff {I : Ideal R} {f : MvPolynomial σ R} : f ∈ (Ideal.map (C : R →+* MvPolynomial σ R) I : Ideal (MvPolynomial σ R)) ↔ ∀ m : σ →₀ ℕ, f.coeff m ∈ I := by classical constructor · intro hf apply @Submodule.span_induction _ _ _ _ Semiring.toModule f _ _ hf · intro f hf n cases' (Set.mem_image _ _ _).mp hf with x hx rw [← hx.right, coeff_C] by_cases h : n = 0 · simpa [h] using hx.left · simp [Ne.symm h] · simp · exact fun f g hf hg n => by simp [I.add_mem (hf n) (hg n)] · refine fun f g hg n => ?_ rw [smul_eq_mul, coeff_mul] exact I.sum_mem fun c _ => I.mul_mem_left (f.coeff c.fst) (hg c.snd) · intro hf rw [as_sum f] suffices ∀ m ∈ f.support, monomial m (coeff m f) ∈ (Ideal.map C I : Ideal (MvPolynomial σ R)) by exact Submodule.sum_mem _ this intro m _ rw [← mul_one (coeff m f), ← C_mul_monomial] suffices C (coeff m f) ∈ (Ideal.map C I : Ideal (MvPolynomial σ R)) by exact Ideal.mul_mem_right _ _ this apply Ideal.mem_map_of_mem _ exact hf m attribute [-instance] Ring.toNonAssocRing in theorem ker_map (f : R →+* S) : RingHom.ker (map f : MvPolynomial σ R →+* MvPolynomial σ S) = Ideal.map (C : R →+* MvPolynomial σ R) (RingHom.ker f) := by ext rw [MvPolynomial.mem_map_C_iff, RingHom.mem_ker, MvPolynomial.ext_iff] simp_rw [coeff_map, coeff_zero, RingHom.mem_ker] end MvPolynomial section UniqueFactorizationDomain variable {D : Type u} [CommRing D] [IsDomain D] [UniqueFactorizationMonoid D] (σ) open UniqueFactorizationMonoid namespace Polynomial instance (priority := 100) uniqueFactorizationMonoid : UniqueFactorizationMonoid D[X] := by letI := Classical.arbitrary (NormalizedGCDMonoid D) exact ufm_of_decomposition_of_wfDvdMonoid /-- If `D` is a unique factorization domain, `f` is a non-zero polynomial in `D[X]`, then `f` has only finitely many monic factors. (Note that its factors up to unit may be more than monic factors.) See also `UniqueFactorizationMonoid.fintypeSubtypeDvd`. -/ noncomputable def fintypeSubtypeMonicDvd (f : D[X]) (hf : f ≠ 0) : Fintype { g : D[X] // g.Monic ∧ g ∣ f } := by set G := { g : D[X] // g.Monic ∧ g ∣ f } let y : Associates D[X] := Associates.mk f have hy : y ≠ 0 := Associates.mk_ne_zero.mpr hf let H := { x : Associates D[X] // x ∣ y } let hfin : Fintype H := UniqueFactorizationMonoid.fintypeSubtypeDvd y hy let i : G → H := fun x ↦ ⟨Associates.mk x.1, Associates.mk_dvd_mk.2 x.2.2⟩ refine Fintype.ofInjective i fun x y heq ↦ ?_ rw [Subtype.mk.injEq] at heq ⊢ exact eq_of_monic_of_associated x.2.1 y.2.1 (Associates.mk_eq_mk_iff_associated.mp heq) end Polynomial namespace MvPolynomial variable (d : ℕ) private theorem uniqueFactorizationMonoid_of_fintype [Fintype σ] : UniqueFactorizationMonoid (MvPolynomial σ D) := (renameEquiv D (Fintype.equivFin σ)).toMulEquiv.symm.uniqueFactorizationMonoid <| by induction' Fintype.card σ with d hd · apply (isEmptyAlgEquiv D (Fin 0)).toMulEquiv.symm.uniqueFactorizationMonoid infer_instance · apply (finSuccEquiv D d).toMulEquiv.symm.uniqueFactorizationMonoid exact Polynomial.uniqueFactorizationMonoid instance (priority := 100) uniqueFactorizationMonoid : UniqueFactorizationMonoid (MvPolynomial σ D) := by rw [iff_exists_prime_factors] intro a ha; obtain ⟨s, a', rfl⟩ := exists_finset_rename a obtain ⟨w, h, u, hw⟩ := iff_exists_prime_factors.1 (uniqueFactorizationMonoid_of_fintype s) a' fun h => ha <| by simp [h] exact ⟨w.map (rename (↑)), fun b hb => let ⟨b', hb', he⟩ := Multiset.mem_map.1 hb he ▸ (prime_rename_iff ↑s).2 (h b' hb'), Units.map (@rename s σ D _ (↑)).toRingHom.toMonoidHom u, by erw [Multiset.prod_hom, ← map_mul, hw]⟩ end MvPolynomial end UniqueFactorizationDomain /-- A polynomial over a field which is not a unit must have a monic irreducible factor. See also `WfDvdMonoid.exists_irreducible_factor`. -/ theorem Polynomial.exists_monic_irreducible_factor {F : Type*} [Field F] (f : F[X]) (hu : ¬IsUnit f) : ∃ g : F[X], g.Monic ∧ Irreducible g ∧ g ∣ f := by by_cases hf : f = 0 · exact ⟨X, monic_X, irreducible_X, hf ▸ dvd_zero X⟩ obtain ⟨g, hi, hf⟩ := WfDvdMonoid.exists_irreducible_factor hu hf have ha : Associated g (g * C g.leadingCoeff⁻¹) := associated_mul_unit_right _ _ <| isUnit_C.2 (leadingCoeff_ne_zero.2 hi.ne_zero).isUnit.inv exact ⟨_, monic_mul_leadingCoeff_inv hi.ne_zero, ha.irreducible hi, ha.dvd_iff_dvd_left.1 hf⟩
RingTheory\Polynomial\Bernstein.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.MvPolynomial.PDeriv import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.Derivative import Mathlib.Data.Nat.Choose.Sum import Mathlib.LinearAlgebra.LinearIndependent import Mathlib.RingTheory.Polynomial.Pochhammer /-! # Bernstein polynomials The definition of the Bernstein polynomials ``` bernsteinPolynomial (R : Type*) [CommRing R] (n ν : ℕ) : R[X] := (choose n ν) * X^ν * (1 - X)^(n - ν) ``` and the fact that for `ν : Fin (n+1)` these are linearly independent over `ℚ`. We prove the basic identities * `(Finset.range (n + 1)).sum (fun ν ↦ bernsteinPolynomial R n ν) = 1` * `(Finset.range (n + 1)).sum (fun ν ↦ ν • bernsteinPolynomial R n ν) = n • X` * `(Finset.range (n + 1)).sum (fun ν ↦ (ν * (ν-1)) • bernsteinPolynomial R n ν) = (n * (n-1)) • X^2` ## Notes See also `Mathlib.Analysis.SpecialFunctions.Bernstein`, which defines the Bernstein approximations of a continuous function `f : C([0,1], ℝ)`, and shows that these converge uniformly to `f`. -/ noncomputable section open Nat (choose) open Polynomial (X) open scoped Polynomial variable (R : Type*) [CommRing R] /-- `bernsteinPolynomial R n ν` is `(choose n ν) * X^ν * (1 - X)^(n - ν)`. Although the coefficients are integers, it is convenient to work over an arbitrary commutative ring. -/ def bernsteinPolynomial (n ν : ℕ) : R[X] := (choose n ν : R[X]) * X ^ ν * (1 - X) ^ (n - ν) example : bernsteinPolynomial ℤ 3 2 = 3 * X ^ 2 - 3 * X ^ 3 := by norm_num [bernsteinPolynomial, choose] ring namespace bernsteinPolynomial theorem eq_zero_of_lt {n ν : ℕ} (h : n < ν) : bernsteinPolynomial R n ν = 0 := by simp [bernsteinPolynomial, Nat.choose_eq_zero_of_lt h] section variable {R} {S : Type*} [CommRing S] @[simp] theorem map (f : R →+* S) (n ν : ℕ) : (bernsteinPolynomial R n ν).map f = bernsteinPolynomial S n ν := by simp [bernsteinPolynomial] end theorem flip (n ν : ℕ) (h : ν ≤ n) : (bernsteinPolynomial R n ν).comp (1 - X) = bernsteinPolynomial R n (n - ν) := by simp [bernsteinPolynomial, h, tsub_tsub_assoc, mul_right_comm] theorem flip' (n ν : ℕ) (h : ν ≤ n) : bernsteinPolynomial R n ν = (bernsteinPolynomial R n (n - ν)).comp (1 - X) := by simp [← flip _ _ _ h, Polynomial.comp_assoc] theorem eval_at_0 (n ν : ℕ) : (bernsteinPolynomial R n ν).eval 0 = if ν = 0 then 1 else 0 := by rw [bernsteinPolynomial] split_ifs with h · subst h; simp · simp [zero_pow h] theorem eval_at_1 (n ν : ℕ) : (bernsteinPolynomial R n ν).eval 1 = if ν = n then 1 else 0 := by rw [bernsteinPolynomial] split_ifs with h · subst h; simp · obtain hνn | hnν := Ne.lt_or_lt h · simp [zero_pow $ Nat.sub_ne_zero_of_lt hνn] · simp [Nat.choose_eq_zero_of_lt hnν] theorem derivative_succ_aux (n ν : ℕ) : Polynomial.derivative (bernsteinPolynomial R (n + 1) (ν + 1)) = (n + 1) * (bernsteinPolynomial R n ν - bernsteinPolynomial R n (ν + 1)) := by rw [bernsteinPolynomial] suffices ((n + 1).choose (ν + 1) : R[X]) * ((↑(ν + 1 : ℕ) : R[X]) * X ^ ν) * (1 - X) ^ (n - ν) - ((n + 1).choose (ν + 1) : R[X]) * X ^ (ν + 1) * ((↑(n - ν) : R[X]) * (1 - X) ^ (n - ν - 1)) = (↑(n + 1) : R[X]) * ((n.choose ν : R[X]) * X ^ ν * (1 - X) ^ (n - ν) - (n.choose (ν + 1) : R[X]) * X ^ (ν + 1) * (1 - X) ^ (n - (ν + 1))) by simpa [Polynomial.derivative_pow, ← sub_eq_add_neg, Nat.succ_sub_succ_eq_sub, Polynomial.derivative_mul, Polynomial.derivative_natCast, zero_mul, Nat.cast_add, algebraMap.coe_one, Polynomial.derivative_X, mul_one, zero_add, Polynomial.derivative_sub, Polynomial.derivative_one, zero_sub, mul_neg, Nat.sub_zero, bernsteinPolynomial, map_add, map_natCast, Nat.cast_one] conv_rhs => rw [mul_sub] -- We'll prove the two terms match up separately. refine congr (congr_arg Sub.sub ?_) ?_ · simp only [← mul_assoc] apply congr (congr_arg (· * ·) (congr (congr_arg (· * ·) _) rfl)) rfl -- Now it's just about binomial coefficients exact mod_cast congr_arg (fun m : ℕ => (m : R[X])) (Nat.succ_mul_choose_eq n ν).symm · rw [← tsub_add_eq_tsub_tsub, ← mul_assoc, ← mul_assoc]; congr 1 rw [mul_comm, ← mul_assoc, ← mul_assoc]; congr 1 norm_cast congr 1 convert (Nat.choose_mul_succ_eq n (ν + 1)).symm using 1 · -- Porting note: was -- convert mul_comm _ _ using 2 -- simp rw [mul_comm, Nat.succ_sub_succ_eq_sub] · apply mul_comm theorem derivative_succ (n ν : ℕ) : Polynomial.derivative (bernsteinPolynomial R n (ν + 1)) = n * (bernsteinPolynomial R (n - 1) ν - bernsteinPolynomial R (n - 1) (ν + 1)) := by cases n · simp [bernsteinPolynomial] · rw [Nat.cast_succ]; apply derivative_succ_aux theorem derivative_zero (n : ℕ) : Polynomial.derivative (bernsteinPolynomial R n 0) = -n * bernsteinPolynomial R (n - 1) 0 := by simp [bernsteinPolynomial, Polynomial.derivative_pow] theorem iterate_derivative_at_0_eq_zero_of_lt (n : ℕ) {ν k : ℕ} : k < ν → (Polynomial.derivative^[k] (bernsteinPolynomial R n ν)).eval 0 = 0 := by cases' ν with ν · rintro ⟨⟩ · rw [Nat.lt_succ_iff] induction' k with k ih generalizing n ν · simp [eval_at_0] · simp only [derivative_succ, Int.natCast_eq_zero, mul_eq_zero, Function.comp_apply, Function.iterate_succ, Polynomial.iterate_derivative_sub, Polynomial.iterate_derivative_natCast_mul, Polynomial.eval_mul, Polynomial.eval_natCast, Polynomial.eval_sub] intro h apply mul_eq_zero_of_right rw [ih _ _ (Nat.le_of_succ_le h), sub_zero] convert ih _ _ (Nat.pred_le_pred h) exact (Nat.succ_pred_eq_of_pos (k.succ_pos.trans_le h)).symm @[simp] theorem iterate_derivative_succ_at_0_eq_zero (n ν : ℕ) : (Polynomial.derivative^[ν] (bernsteinPolynomial R n (ν + 1))).eval 0 = 0 := iterate_derivative_at_0_eq_zero_of_lt R n (lt_add_one ν) open Polynomial @[simp] theorem iterate_derivative_at_0 (n ν : ℕ) : (Polynomial.derivative^[ν] (bernsteinPolynomial R n ν)).eval 0 = (ascPochhammer R ν).eval ((n - (ν - 1) : ℕ) : R) := by by_cases h : ν ≤ n · induction' ν with ν ih generalizing n · simp [eval_at_0] · have h' : ν ≤ n - 1 := le_tsub_of_add_le_right h simp only [derivative_succ, ih (n - 1) h', iterate_derivative_succ_at_0_eq_zero, Nat.succ_sub_succ_eq_sub, tsub_zero, sub_zero, iterate_derivative_sub, iterate_derivative_natCast_mul, eval_one, eval_mul, eval_add, eval_sub, eval_X, eval_comp, eval_natCast, Function.comp_apply, Function.iterate_succ, ascPochhammer_succ_left] obtain rfl | h'' := ν.eq_zero_or_pos · simp · have : n - 1 - (ν - 1) = n - ν := by rw [gt_iff_lt, ← Nat.succ_le_iff] at h'' rw [← tsub_add_eq_tsub_tsub, add_comm, tsub_add_cancel_of_le h''] rw [this, ascPochhammer_eval_succ] rw_mod_cast [tsub_add_cancel_of_le (h'.trans n.pred_le)] · simp only [not_le] at h rw [tsub_eq_zero_iff_le.mpr (Nat.le_sub_one_of_lt h), eq_zero_of_lt R h] simp [pos_iff_ne_zero.mp (pos_of_gt h)] theorem iterate_derivative_at_0_ne_zero [CharZero R] (n ν : ℕ) (h : ν ≤ n) : (Polynomial.derivative^[ν] (bernsteinPolynomial R n ν)).eval 0 ≠ 0 := by simp only [Int.natCast_eq_zero, bernsteinPolynomial.iterate_derivative_at_0, Ne, Nat.cast_eq_zero] simp only [← ascPochhammer_eval_cast] norm_cast apply ne_of_gt obtain rfl | h' := Nat.eq_zero_or_pos ν · simp · rw [← Nat.succ_pred_eq_of_pos h'] at h exact ascPochhammer_pos _ _ (tsub_pos_of_lt (Nat.lt_of_succ_le h)) /-! Rather than redoing the work of evaluating the derivatives at 1, we use the symmetry of the Bernstein polynomials. -/ theorem iterate_derivative_at_1_eq_zero_of_lt (n : ℕ) {ν k : ℕ} : k < n - ν → (Polynomial.derivative^[k] (bernsteinPolynomial R n ν)).eval 1 = 0 := by intro w rw [flip' _ _ _ (tsub_pos_iff_lt.mp (pos_of_gt w)).le] simp [Polynomial.eval_comp, iterate_derivative_at_0_eq_zero_of_lt R n w] @[simp] theorem iterate_derivative_at_1 (n ν : ℕ) (h : ν ≤ n) : (Polynomial.derivative^[n - ν] (bernsteinPolynomial R n ν)).eval 1 = (-1) ^ (n - ν) * (ascPochhammer R (n - ν)).eval (ν + 1 : R) := by rw [flip' _ _ _ h] simp [Polynomial.eval_comp, h] obtain rfl | h' := h.eq_or_lt · simp · norm_cast congr omega theorem iterate_derivative_at_1_ne_zero [CharZero R] (n ν : ℕ) (h : ν ≤ n) : (Polynomial.derivative^[n - ν] (bernsteinPolynomial R n ν)).eval 1 ≠ 0 := by rw [bernsteinPolynomial.iterate_derivative_at_1 _ _ _ h, Ne, neg_one_pow_mul_eq_zero_iff, ← Nat.cast_succ, ← ascPochhammer_eval_cast, ← Nat.cast_zero, Nat.cast_inj] exact (ascPochhammer_pos _ _ (Nat.succ_pos ν)).ne' open Submodule theorem linearIndependent_aux (n k : ℕ) (h : k ≤ n + 1) : LinearIndependent ℚ fun ν : Fin k => bernsteinPolynomial ℚ n ν := by induction' k with k ih · apply linearIndependent_empty_type · apply linearIndependent_fin_succ'.mpr fconstructor · exact ih (le_of_lt h) · -- The actual work! -- We show that the (n-k)-th derivative at 1 doesn't vanish, -- but vanishes for everything in the span. clear ih simp only [Nat.succ_eq_add_one, add_le_add_iff_right] at h simp only [Fin.val_last, Fin.init_def] dsimp apply not_mem_span_of_apply_not_mem_span_image (@Polynomial.derivative ℚ _ ^ (n - k)) -- Note: #8386 had to change `span_image` into `span_image _` simp only [not_exists, not_and, Submodule.mem_map, Submodule.span_image _] intro p m apply_fun Polynomial.eval (1 : ℚ) simp only [LinearMap.pow_apply] -- The right hand side is nonzero, -- so it will suffice to show the left hand side is always zero. suffices (Polynomial.derivative^[n - k] p).eval 1 = 0 by rw [this] exact (iterate_derivative_at_1_ne_zero ℚ n k h).symm refine span_induction m ?_ ?_ ?_ ?_ · simp only [Set.mem_range, forall_exists_index, forall_apply_eq_imp_iff] rintro ⟨a, w⟩; simp only [Fin.val_mk] rw [iterate_derivative_at_1_eq_zero_of_lt ℚ n ((tsub_lt_tsub_iff_left_of_le h).mpr w)] · simp · intro x y hx hy; simp [hx, hy] · intro a x h; simp [h] /-- The Bernstein polynomials are linearly independent. We prove by induction that the collection of `bernsteinPolynomial n ν` for `ν = 0, ..., k` are linearly independent. The inductive step relies on the observation that the `(n-k)`-th derivative, evaluated at 1, annihilates `bernsteinPolynomial n ν` for `ν < k`, but has a nonzero value at `ν = k`. -/ theorem linearIndependent (n : ℕ) : LinearIndependent ℚ fun ν : Fin (n + 1) => bernsteinPolynomial ℚ n ν := linearIndependent_aux n (n + 1) le_rfl theorem sum (n : ℕ) : (∑ ν ∈ Finset.range (n + 1), bernsteinPolynomial R n ν) = 1 := calc (∑ ν ∈ Finset.range (n + 1), bernsteinPolynomial R n ν) = (X + (1 - X)) ^ n := by rw [add_pow] simp only [bernsteinPolynomial, mul_comm, mul_assoc, mul_left_comm] _ = 1 := by simp open Polynomial open MvPolynomial hiding X theorem sum_smul (n : ℕ) : (∑ ν ∈ Finset.range (n + 1), ν • bernsteinPolynomial R n ν) = n • X := by -- We calculate the `x`-derivative of `(x+y)^n`, evaluated at `y=(1-x)`, -- either directly or by using the binomial theorem. -- We'll work in `MvPolynomial Bool R`. let x : MvPolynomial Bool R := MvPolynomial.X true let y : MvPolynomial Bool R := MvPolynomial.X false have pderiv_true_x : pderiv true x = 1 := by rw [pderiv_X]; rfl have pderiv_true_y : pderiv true y = 0 := by rw [pderiv_X]; rfl let e : Bool → R[X] := fun i => cond i X (1 - X) -- Start with `(x+y)^n = (x+y)^n`, -- take the `x`-derivative, evaluate at `x=X, y=1-X`, and multiply by `X`: trans MvPolynomial.aeval e (pderiv true ((x + y) ^ n)) * X -- On the left hand side we'll use the binomial theorem, then simplify. · -- We first prepare a tedious rewrite: have w : ∀ k : ℕ, k • bernsteinPolynomial R n k = (k : R[X]) * Polynomial.X ^ (k - 1) * (1 - Polynomial.X) ^ (n - k) * (n.choose k : R[X]) * Polynomial.X := by rintro (_ | k) · simp · rw [bernsteinPolynomial] simp only [← natCast_mul, Nat.succ_eq_add_one, Nat.add_succ_sub_one, add_zero, pow_succ] push_cast ring rw [add_pow, map_sum (pderiv true), map_sum (MvPolynomial.aeval e), Finset.sum_mul] -- Step inside the sum: refine Finset.sum_congr rfl fun k _ => (w k).trans ?_ simp only [x, y, e, pderiv_true_x, pderiv_true_y, Algebra.id.smul_eq_mul, nsmul_eq_mul, Bool.cond_true, Bool.cond_false, add_zero, mul_one, mul_zero, smul_zero, MvPolynomial.aeval_X, MvPolynomial.pderiv_mul, Derivation.leibniz_pow, Derivation.map_natCast, map_natCast, map_pow, map_mul] · rw [(pderiv true).leibniz_pow, (pderiv true).map_add, pderiv_true_x, pderiv_true_y] simp only [x, y, e, Algebra.id.smul_eq_mul, nsmul_eq_mul, map_natCast, map_pow, map_add, map_mul, Bool.cond_true, Bool.cond_false, MvPolynomial.aeval_X, add_sub_cancel, one_pow, add_zero, mul_one] theorem sum_mul_smul (n : ℕ) : (∑ ν ∈ Finset.range (n + 1), (ν * (ν - 1)) • bernsteinPolynomial R n ν) = (n * (n - 1)) • X ^ 2 := by -- We calculate the second `x`-derivative of `(x+y)^n`, evaluated at `y=(1-x)`, -- either directly or by using the binomial theorem. -- We'll work in `MvPolynomial Bool R`. let x : MvPolynomial Bool R := MvPolynomial.X true let y : MvPolynomial Bool R := MvPolynomial.X false have pderiv_true_x : pderiv true x = 1 := by rw [pderiv_X]; rfl have pderiv_true_y : pderiv true y = 0 := by rw [pderiv_X]; rfl let e : Bool → R[X] := fun i => cond i X (1 - X) -- Start with `(x+y)^n = (x+y)^n`, -- take the second `x`-derivative, evaluate at `x=X, y=1-X`, and multiply by `X`: trans MvPolynomial.aeval e (pderiv true (pderiv true ((x + y) ^ n))) * X ^ 2 -- On the left hand side we'll use the binomial theorem, then simplify. · -- We first prepare a tedious rewrite: have w : ∀ k : ℕ, (k * (k - 1)) • bernsteinPolynomial R n k = (n.choose k : R[X]) * ((1 - Polynomial.X) ^ (n - k) * ((k : R[X]) * ((↑(k - 1) : R[X]) * Polynomial.X ^ (k - 1 - 1)))) * Polynomial.X ^ 2 := by rintro (_ | _ | k) · simp · simp · rw [bernsteinPolynomial] simp only [← natCast_mul, Nat.succ_eq_add_one, Nat.add_succ_sub_one, add_zero, pow_succ] push_cast ring rw [add_pow, map_sum (pderiv true), map_sum (pderiv true), map_sum (MvPolynomial.aeval e), Finset.sum_mul] -- Step inside the sum: refine Finset.sum_congr rfl fun k _ => (w k).trans ?_ simp only [x, y, e, pderiv_true_x, pderiv_true_y, Algebra.id.smul_eq_mul, nsmul_eq_mul, Bool.cond_true, Bool.cond_false, add_zero, zero_add, mul_zero, smul_zero, mul_one, MvPolynomial.aeval_X, MvPolynomial.pderiv_X_self, MvPolynomial.pderiv_X_of_ne, Derivation.leibniz_pow, Derivation.leibniz, Derivation.map_natCast, map_natCast, map_pow, map_mul, map_add] -- On the right hand side, we'll just simplify. · simp only [x, y, e, pderiv_one, pderiv_mul, (pderiv _).leibniz_pow, (pderiv _).map_natCast, (pderiv true).map_add, pderiv_true_x, pderiv_true_y, Algebra.id.smul_eq_mul, add_zero, mul_one, Derivation.map_smul_of_tower, map_nsmul, map_pow, map_add, Bool.cond_true, Bool.cond_false, MvPolynomial.aeval_X, add_sub_cancel, one_pow, smul_smul, smul_one_mul] /-- A certain linear combination of the previous three identities, which we'll want later. -/ theorem variance (n : ℕ) : (∑ ν ∈ Finset.range (n + 1), (n • Polynomial.X - (ν : R[X])) ^ 2 * bernsteinPolynomial R n ν) = n • Polynomial.X * ((1 : R[X]) - Polynomial.X) := by have p : ((((Finset.range (n + 1)).sum fun ν => (ν * (ν - 1)) • bernsteinPolynomial R n ν) + (1 - (2 * n) • Polynomial.X) * (Finset.range (n + 1)).sum fun ν => ν • bernsteinPolynomial R n ν) + n ^ 2 • X ^ 2 * (Finset.range (n + 1)).sum fun ν => bernsteinPolynomial R n ν) = _ := rfl conv at p => lhs rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib, ← Finset.sum_add_distrib] simp only [← natCast_mul] simp only [← mul_assoc] simp only [← add_mul] conv at p => rhs rw [sum, sum_smul, sum_mul_smul, ← natCast_mul] calc _ = _ := Finset.sum_congr rfl fun k m => ?_ _ = _ := p _ = _ := ?_ · congr 1; simp only [← natCast_mul, push_cast] cases k <;> · simp; ring · simp only [← natCast_mul, push_cast] cases n · simp · simp; ring end bernsteinPolynomial
RingTheory\Polynomial\Chebyshev.lean
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Julian Kuelshammer, Heather Macbeth, Mitchell Lee -/ import Mathlib.Algebra.Polynomial.Derivative import Mathlib.Tactic.LinearCombination /-! # Chebyshev polynomials The Chebyshev polynomials are families of polynomials indexed by `ℤ`, with integral coefficients. ## Main definitions * `Polynomial.Chebyshev.T`: the Chebyshev polynomials of the first kind. * `Polynomial.Chebyshev.U`: the Chebyshev polynomials of the second kind. ## Main statements * The formal derivative of the Chebyshev polynomials of the first kind is a scalar multiple of the Chebyshev polynomials of the second kind. * `Polynomial.Chebyshev.mul_T`, twice the product of the `m`-th and `k`-th Chebyshev polynomials of the first kind is the sum of the `m + k`-th and `m - k`-th Chebyshev polynomials of the first kind. * `Polynomial.Chebyshev.T_mul`, the `(m * n)`-th Chebyshev polynomial of the first kind is the composition of the `m`-th and `n`-th Chebyshev polynomials of the first kind. ## Implementation details Since Chebyshev polynomials have interesting behaviour over the complex numbers and modulo `p`, we define them to have coefficients in an arbitrary commutative ring, even though technically `ℤ` would suffice. The benefit of allowing arbitrary coefficient rings, is that the statements afterwards are clean, and do not have `map (Int.castRingHom R)` interfering all the time. ## References [Lionel Ponton, _Roots of the Chebyshev polynomials: A purely algebraic approach_] [ponton2020chebyshev] ## TODO * Redefine and/or relate the definition of Chebyshev polynomials to `LinearRecurrence`. * Add explicit formula involving square roots for Chebyshev polynomials * Compute zeroes and extrema of Chebyshev polynomials. * Prove that the roots of the Chebyshev polynomials (except 0) are irrational. * Prove minimax properties of Chebyshev polynomials. -/ namespace Polynomial.Chebyshev open Polynomial variable (R S : Type*) [CommRing R] [CommRing S] /-- `T n` is the `n`-th Chebyshev polynomial of the first kind. -/ -- Well-founded definitions are now irreducible by default; -- as this was implemented before this change, -- we just set it back to semireducible to avoid needing to change any proofs. @[semireducible] noncomputable def T : ℤ → R[X] | 0 => 1 | 1 => X | (n : ℕ) + 2 => 2 * X * T (n + 1) - T n | -((n : ℕ) + 1) => 2 * X * T (-n) - T (-n + 1) termination_by n => Int.natAbs n + Int.natAbs (n - 1) /-- Induction principle used for proving facts about Chebyshev polynomials. -/ @[elab_as_elim] protected theorem induct (motive : ℤ → Prop) (zero : motive 0) (one : motive 1) (add_two : ∀ (n : ℕ), motive (↑n + 1) → motive ↑n → motive (↑n + 2)) (neg_add_one : ∀ (n : ℕ), motive (-↑n) → motive (-↑n + 1) → motive (-↑n - 1)) : ∀ (a : ℤ), motive a := T.induct Unit motive zero one add_two fun n hn hnm => by simpa only [Int.negSucc_eq, neg_add] using neg_add_one n hn hnm @[simp] theorem T_add_two : ∀ n, T R (n + 2) = 2 * X * T R (n + 1) - T R n | (k : ℕ) => T.eq_3 R k | -(k + 1 : ℕ) => by linear_combination (norm := (simp [Int.negSucc_eq]; ring_nf)) T.eq_4 R k theorem T_add_one (n : ℤ) : T R (n + 1) = 2 * X * T R n - T R (n - 1) := by linear_combination (norm := ring_nf) T_add_two R (n - 1) theorem T_sub_two (n : ℤ) : T R (n - 2) = 2 * X * T R (n - 1) - T R n := by linear_combination (norm := ring_nf) T_add_two R (n - 2) theorem T_sub_one (n : ℤ) : T R (n - 1) = 2 * X * T R n - T R (n + 1) := by linear_combination (norm := ring_nf) T_add_two R (n - 1) theorem T_eq (n : ℤ) : T R n = 2 * X * T R (n - 1) - T R (n - 2) := by linear_combination (norm := ring_nf) T_add_two R (n - 2) @[simp] theorem T_zero : T R 0 = 1 := rfl @[simp] theorem T_one : T R 1 = X := rfl theorem T_neg_one : T R (-1) = X := (by ring : 2 * X * 1 - X = X) theorem T_two : T R 2 = 2 * X ^ 2 - 1 := by simpa [pow_two, mul_assoc] using T_add_two R 0 @[simp] theorem T_neg (n : ℤ) : T R (-n) = T R n := by induction n using Polynomial.Chebyshev.induct with | zero => rfl | one => show 2 * X * 1 - X = X; ring | add_two n ih1 ih2 => have h₁ := T_add_two R n have h₂ := T_sub_two R (-n) linear_combination (norm := ring_nf) (2 * (X : R[X])) * ih1 - ih2 - h₁ + h₂ | neg_add_one n ih1 ih2 => have h₁ := T_add_one R n have h₂ := T_sub_one R (-n) linear_combination (norm := ring_nf) (2 * (X : R[X])) * ih1 - ih2 + h₁ - h₂ theorem T_natAbs (n : ℤ) : T R n.natAbs = T R n := by obtain h | h := Int.natAbs_eq n <;> nth_rw 2 [h]; simp theorem T_neg_two : T R (-2) = 2 * X ^ 2 - 1 := by simp [T_two] /-- `U n` is the `n`-th Chebyshev polynomial of the second kind. -/ -- Well-founded definitions are now irreducible by default; -- as this was implemented before this change, -- we just set it back to semireducible to avoid needing to change any proofs. @[semireducible] noncomputable def U : ℤ → R[X] | 0 => 1 | 1 => 2 * X | (n : ℕ) + 2 => 2 * X * U (n + 1) - U n | -((n : ℕ) + 1) => 2 * X * U (-n) - U (-n + 1) termination_by n => Int.natAbs n + Int.natAbs (n - 1) @[simp] theorem U_add_two : ∀ n, U R (n + 2) = 2 * X * U R (n + 1) - U R n | (k : ℕ) => U.eq_3 R k | -(k + 1 : ℕ) => by linear_combination (norm := (simp [Int.negSucc_eq]; ring_nf)) U.eq_4 R k theorem U_add_one (n : ℤ) : U R (n + 1) = 2 * X * U R n - U R (n - 1) := by linear_combination (norm := ring_nf) U_add_two R (n - 1) theorem U_sub_two (n : ℤ) : U R (n - 2) = 2 * X * U R (n - 1) - U R n := by linear_combination (norm := ring_nf) U_add_two R (n - 2) theorem U_sub_one (n : ℤ) : U R (n - 1) = 2 * X * U R n - U R (n + 1) := by linear_combination (norm := ring_nf) U_add_two R (n - 1) theorem U_eq (n : ℤ) : U R n = 2 * X * U R (n - 1) - U R (n - 2) := by linear_combination (norm := ring_nf) U_add_two R (n - 2) @[simp] theorem U_zero : U R 0 = 1 := rfl @[simp] theorem U_one : U R 1 = 2 * X := rfl @[simp] theorem U_neg_one : U R (-1) = 0 := by simpa using U_sub_one R 0 theorem U_two : U R 2 = 4 * X ^ 2 - 1 := by have := U_add_two R 0 simp only [zero_add, U_one, U_zero] at this linear_combination this @[simp] theorem U_neg_two : U R (-2) = -1 := by simpa [zero_sub, Int.reduceNeg, U_neg_one, mul_zero, U_zero] using U_sub_two R 0 theorem U_neg_sub_one (n : ℤ) : U R (-n - 1) = -U R (n - 1) := by induction n using Polynomial.Chebyshev.induct with | zero => simp | one => simp | add_two n ih1 ih2 => have h₁ := U_add_one R n have h₂ := U_sub_two R (-n - 1) linear_combination (norm := ring_nf) 2 * (X : R[X]) * ih1 - ih2 + h₁ + h₂ | neg_add_one n ih1 ih2 => have h₁ := U_eq R n have h₂ := U_sub_two R (-n) linear_combination (norm := ring_nf) 2 * (X : R[X]) * ih1 - ih2 + h₁ + h₂ theorem U_neg (n : ℤ) : U R (-n) = -U R (n - 2) := by simpa [sub_sub] using U_neg_sub_one R (n - 1) @[simp] theorem U_neg_sub_two (n : ℤ) : U R (-n - 2) = -U R n := by simpa [sub_eq_add_neg, add_comm] using U_neg R (n + 2) theorem U_eq_X_mul_U_add_T (n : ℤ) : U R (n + 1) = X * U R n + T R (n + 1) := by induction n using Polynomial.Chebyshev.induct with | zero => simp [two_mul] | one => simp [U_two, T_two]; ring | add_two n ih1 ih2 => have h₁ := U_add_two R (n + 1) have h₂ := U_add_two R n have h₃ := T_add_two R (n + 1) linear_combination (norm := ring_nf) -h₃ - (X : R[X]) * h₂ + h₁ + 2 * (X : R[X]) * ih1 - ih2 | neg_add_one n ih1 ih2 => have h₁ := U_add_two R (-n - 1) have h₂ := U_add_two R (-n) have h₃ := T_add_two R (-n) linear_combination (norm := ring_nf) -h₃ + h₂ - (X : R[X]) * h₁ - ih2 + 2 * (X : R[X]) * ih1 theorem T_eq_U_sub_X_mul_U (n : ℤ) : T R n = U R n - X * U R (n - 1) := by linear_combination (norm := ring_nf) - U_eq_X_mul_U_add_T R (n - 1) theorem T_eq_X_mul_T_sub_pol_U (n : ℤ) : T R (n + 2) = X * T R (n + 1) - (1 - X ^ 2) * U R n := by have h₁ := U_eq_X_mul_U_add_T R n have h₂ := U_eq_X_mul_U_add_T R (n + 1) have h₃ := U_add_two R n linear_combination (norm := ring_nf) h₃ - h₂ + (X : R[X]) * h₁ theorem one_sub_X_sq_mul_U_eq_pol_in_T (n : ℤ) : (1 - X ^ 2) * U R n = X * T R (n + 1) - T R (n + 2) := by linear_combination T_eq_X_mul_T_sub_pol_U R n variable {R S} @[simp] theorem map_T (f : R →+* S) (n : ℤ) : map f (T R n) = T S n := by induction n using Polynomial.Chebyshev.induct with | zero => simp | one => simp | add_two n ih1 ih2 => simp_rw [T_add_two, Polynomial.map_sub, Polynomial.map_mul, Polynomial.map_ofNat, map_X, ih1, ih2] | neg_add_one n ih1 ih2 => simp_rw [T_sub_one, Polynomial.map_sub, Polynomial.map_mul, Polynomial.map_ofNat, map_X, ih1, ih2] @[simp] theorem map_U (f : R →+* S) (n : ℤ) : map f (U R n) = U S n := by induction n using Polynomial.Chebyshev.induct with | zero => simp | one => simp | add_two n ih1 ih2 => simp_rw [U_add_two, Polynomial.map_sub, Polynomial.map_mul, Polynomial.map_ofNat, map_X, ih1, ih2] | neg_add_one n ih1 ih2 => simp_rw [U_sub_one, Polynomial.map_sub, Polynomial.map_mul, Polynomial.map_ofNat, map_X, ih1, ih2] theorem T_derivative_eq_U (n : ℤ) : derivative (T R n) = n * U R (n - 1) := by induction n using Polynomial.Chebyshev.induct with | zero => simp | one => simp [T_two, U_one, derivative_sub, derivative_one, derivative_mul, derivative_X_pow, add_mul] | add_two n ih1 ih2 => have h₁ := congr_arg derivative (T_add_two R n) have h₂ := U_sub_one R n have h₃ := T_eq_U_sub_X_mul_U R (n + 1) simp only [derivative_sub, derivative_mul, derivative_ofNat, derivative_X] at h₁ linear_combination (norm := (push_cast; ring_nf)) h₁ - ih2 + 2 * (X : R[X]) * ih1 + 2 * h₃ - n * h₂ | neg_add_one n ih1 ih2 => have h₁ := congr_arg derivative (T_sub_one R (-n)) have h₂ := U_sub_two R (-n) have h₃ := T_eq_U_sub_X_mul_U R (-n) simp only [derivative_sub, derivative_mul, derivative_ofNat, derivative_X] at h₁ linear_combination (norm := (push_cast; ring_nf)) -ih2 + 2 * (X : R[X]) * ih1 + h₁ + 2 * h₃ + (n + 1) * h₂ theorem one_sub_X_sq_mul_derivative_T_eq_poly_in_T (n : ℤ) : (1 - X ^ 2) * derivative (T R (n + 1)) = (n + 1 : R[X]) * (T R n - X * T R (n + 1)) := by have H₁ := one_sub_X_sq_mul_U_eq_pol_in_T R n have H₂ := T_derivative_eq_U (R := R) (n + 1) have h₁ := T_add_two R n linear_combination (norm := (push_cast; ring_nf)) (-n - 1) * h₁ + (-(X : R[X]) ^ 2 + 1) * H₂ + (n + 1) * H₁ theorem add_one_mul_T_eq_poly_in_U (n : ℤ) : ((n : R[X]) + 1) * T R (n + 1) = X * U R n - (1 - X ^ 2) * derivative (U R n) := by have h₁ := congr_arg derivative <| T_eq_X_mul_T_sub_pol_U R n simp only [derivative_sub, derivative_mul, derivative_X, derivative_one, derivative_X_pow, T_derivative_eq_U, C_eq_natCast] at h₁ have h₂ := T_eq_U_sub_X_mul_U R (n + 1) linear_combination (norm := (push_cast; ring_nf)) h₁ + (n + 2) * h₂ variable (R) /-- Twice the product of two Chebyshev `T` polynomials is the sum of two other Chebyshev `T` polynomials. -/ theorem mul_T (m k : ℤ) : 2 * T R m * T R k = T R (m + k) + T R (m - k) := by induction k using Polynomial.Chebyshev.induct with | zero => simp [two_mul] | one => rw [T_add_one, T_one]; ring | add_two k ih1 ih2 => have h₁ := T_add_two R (m + k) have h₂ := T_sub_two R (m - k) have h₃ := T_add_two R k linear_combination (norm := ring_nf) 2 * T R m * h₃ - h₂ - h₁ - ih2 + 2 * (X : R[X]) * ih1 | neg_add_one k ih1 ih2 => have h₁ := T_add_two R (m + (-k - 1)) have h₂ := T_sub_two R (m - (-k - 1)) have h₃ := T_add_two R (-k - 1) linear_combination (norm := ring_nf) 2 * T R m * h₃ - h₂ - h₁ - ih2 + 2 * (X : R[X]) * ih1 /-- The `(m * n)`-th Chebyshev `T` polynomial is the composition of the `m`-th and `n`-th. -/ theorem T_mul (m n : ℤ) : T R (m * n) = (T R m).comp (T R n) := by induction m using Polynomial.Chebyshev.induct with | zero => simp | one => simp | add_two m ih1 ih2 => have h₁ := mul_T R ((m + 1) * n) n have h₂ := congr_arg (comp · (T R n)) <| T_add_two R m simp only [sub_comp, mul_comp, ofNat_comp, X_comp] at h₂ linear_combination (norm := ring_nf) -ih2 - h₂ - h₁ + 2 * T R n * ih1 | neg_add_one m ih1 ih2 => have h₁ := mul_T R ((-m) * n) n have h₂ := congr_arg (comp · (T R n)) <| T_add_two R (-m - 1) simp only [sub_comp, mul_comp, ofNat_comp, X_comp] at h₂ linear_combination (norm := ring_nf) -ih2 - h₂ - h₁ + 2 * T R n * ih1 end Polynomial.Chebyshev
RingTheory\Polynomial\Content.lean
/- Copyright (c) 2020 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.Algebra.GCDMonoid.Finset import Mathlib.Algebra.Polynomial.CancelLeads import Mathlib.Algebra.Polynomial.EraseLead import Mathlib.Algebra.Polynomial.FieldDivision /-! # GCD structures on polynomials Definitions and basic results about polynomials over GCD domains, particularly their contents and primitive polynomials. ## Main Definitions Let `p : R[X]`. - `p.content` is the `gcd` of the coefficients of `p`. - `p.IsPrimitive` indicates that `p.content = 1`. ## Main Results - `Polynomial.content_mul`: If `p q : R[X]`, then `(p * q).content = p.content * q.content`. - `Polynomial.NormalizedGcdMonoid`: The polynomial ring of a GCD domain is itself a GCD domain. -/ namespace Polynomial open Polynomial section Primitive variable {R : Type*} [CommSemiring R] /-- A polynomial is primitive when the only constant polynomials dividing it are units -/ def IsPrimitive (p : R[X]) : Prop := ∀ r : R, C r ∣ p → IsUnit r theorem isPrimitive_iff_isUnit_of_C_dvd {p : R[X]} : p.IsPrimitive ↔ ∀ r : R, C r ∣ p → IsUnit r := Iff.rfl @[simp] theorem isPrimitive_one : IsPrimitive (1 : R[X]) := fun _ h => isUnit_C.mp (isUnit_of_dvd_one h) theorem Monic.isPrimitive {p : R[X]} (hp : p.Monic) : p.IsPrimitive := by rintro r ⟨q, h⟩ exact isUnit_of_mul_eq_one r (q.coeff p.natDegree) (by rwa [← coeff_C_mul, ← h]) theorem IsPrimitive.ne_zero [Nontrivial R] {p : R[X]} (hp : p.IsPrimitive) : p ≠ 0 := by rintro rfl exact (hp 0 (dvd_zero (C 0))).ne_zero rfl theorem isPrimitive_of_dvd {p q : R[X]} (hp : IsPrimitive p) (hq : q ∣ p) : IsPrimitive q := fun a ha => isPrimitive_iff_isUnit_of_C_dvd.mp hp a (dvd_trans ha hq) end Primitive variable {R : Type*} [CommRing R] [IsDomain R] section NormalizedGCDMonoid variable [NormalizedGCDMonoid R] /-- `p.content` is the `gcd` of the coefficients of `p`. -/ def content (p : R[X]) : R := p.support.gcd p.coeff theorem content_dvd_coeff {p : R[X]} (n : ℕ) : p.content ∣ p.coeff n := by by_cases h : n ∈ p.support · apply Finset.gcd_dvd h rw [mem_support_iff, Classical.not_not] at h rw [h] apply dvd_zero @[simp] theorem content_C {r : R} : (C r).content = normalize r := by rw [content] by_cases h0 : r = 0 · simp [h0] have h : (C r).support = {0} := support_monomial _ h0 simp [h] @[simp] theorem content_zero : content (0 : R[X]) = 0 := by rw [← C_0, content_C, normalize_zero] @[simp] theorem content_one : content (1 : R[X]) = 1 := by rw [← C_1, content_C, normalize_one] theorem content_X_mul {p : R[X]} : content (X * p) = content p := by rw [content, content, Finset.gcd_def, Finset.gcd_def] refine congr rfl ?_ have h : (X * p).support = p.support.map ⟨Nat.succ, Nat.succ_injective⟩ := by ext a simp only [exists_prop, Finset.mem_map, Function.Embedding.coeFn_mk, Ne, mem_support_iff] cases' a with a · simp [coeff_X_mul_zero, Nat.succ_ne_zero] rw [mul_comm, coeff_mul_X] constructor · intro h use a · rintro ⟨b, ⟨h1, h2⟩⟩ rw [← Nat.succ_injective h2] apply h1 rw [h] simp only [Finset.map_val, Function.comp_apply, Function.Embedding.coeFn_mk, Multiset.map_map] refine congr (congr rfl ?_) rfl ext a rw [mul_comm] simp [coeff_mul_X] @[simp] theorem content_X_pow {k : ℕ} : content ((X : R[X]) ^ k) = 1 := by induction' k with k hi · simp rw [pow_succ', content_X_mul, hi] @[simp] theorem content_X : content (X : R[X]) = 1 := by rw [← mul_one X, content_X_mul, content_one] theorem content_C_mul (r : R) (p : R[X]) : (C r * p).content = normalize r * p.content := by by_cases h0 : r = 0; · simp [h0] rw [content]; rw [content]; rw [← Finset.gcd_mul_left] refine congr (congr rfl ?_) ?_ <;> ext <;> simp [h0, mem_support_iff] @[simp] theorem content_monomial {r : R} {k : ℕ} : content (monomial k r) = normalize r := by rw [← C_mul_X_pow_eq_monomial, content_C_mul, content_X_pow, mul_one] theorem content_eq_zero_iff {p : R[X]} : content p = 0 ↔ p = 0 := by rw [content, Finset.gcd_eq_zero_iff] constructor <;> intro h · ext n by_cases h0 : n ∈ p.support · rw [h n h0, coeff_zero] · rw [mem_support_iff] at h0 push_neg at h0 simp [h0] · intro x simp [h] -- Porting note: this reduced with simp so created `normUnit_content` and put simp on it theorem normalize_content {p : R[X]} : normalize p.content = p.content := Finset.normalize_gcd @[simp] theorem normUnit_content {p : R[X]} : normUnit (content p) = 1 := by by_cases hp0 : p.content = 0 · simp [hp0] · ext apply mul_left_cancel₀ hp0 erw [← normalize_apply, normalize_content, mul_one] theorem content_eq_gcd_range_of_lt (p : R[X]) (n : ℕ) (h : p.natDegree < n) : p.content = (Finset.range n).gcd p.coeff := by apply dvd_antisymm_of_normalize_eq normalize_content Finset.normalize_gcd · rw [Finset.dvd_gcd_iff] intro i _ apply content_dvd_coeff _ · apply Finset.gcd_mono intro i simp only [Nat.lt_succ_iff, mem_support_iff, Ne, Finset.mem_range] contrapose! intro h1 apply coeff_eq_zero_of_natDegree_lt (lt_of_lt_of_le h h1) theorem content_eq_gcd_range_succ (p : R[X]) : p.content = (Finset.range p.natDegree.succ).gcd p.coeff := content_eq_gcd_range_of_lt _ _ (Nat.lt_succ_self _) theorem content_eq_gcd_leadingCoeff_content_eraseLead (p : R[X]) : p.content = GCDMonoid.gcd p.leadingCoeff (eraseLead p).content := by by_cases h : p = 0 · simp [h] rw [← leadingCoeff_eq_zero, leadingCoeff, ← Ne, ← mem_support_iff] at h rw [content, ← Finset.insert_erase h, Finset.gcd_insert, leadingCoeff, content, eraseLead_support] refine congr rfl (Finset.gcd_congr rfl fun i hi => ?_) rw [Finset.mem_erase] at hi rw [eraseLead_coeff, if_neg hi.1] theorem dvd_content_iff_C_dvd {p : R[X]} {r : R} : r ∣ p.content ↔ C r ∣ p := by rw [C_dvd_iff_dvd_coeff] constructor · intro h i apply h.trans (content_dvd_coeff _) · intro h rw [content, Finset.dvd_gcd_iff] intro i _ apply h i theorem C_content_dvd (p : R[X]) : C p.content ∣ p := dvd_content_iff_C_dvd.1 dvd_rfl theorem isPrimitive_iff_content_eq_one {p : R[X]} : p.IsPrimitive ↔ p.content = 1 := by rw [← normalize_content, normalize_eq_one, IsPrimitive] simp_rw [← dvd_content_iff_C_dvd] exact ⟨fun h => h p.content (dvd_refl p.content), fun h r hdvd => isUnit_of_dvd_unit hdvd h⟩ theorem IsPrimitive.content_eq_one {p : R[X]} (hp : p.IsPrimitive) : p.content = 1 := isPrimitive_iff_content_eq_one.mp hp section PrimPart /-- The primitive part of a polynomial `p` is the primitive polynomial gained by dividing `p` by `p.content`. If `p = 0`, then `p.primPart = 1`. -/ noncomputable def primPart (p : R[X]) : R[X] := letI := Classical.decEq R if p = 0 then 1 else Classical.choose (C_content_dvd p) theorem eq_C_content_mul_primPart (p : R[X]) : p = C p.content * p.primPart := by by_cases h : p = 0; · simp [h] rw [primPart, if_neg h, ← Classical.choose_spec (C_content_dvd p)] @[simp] theorem primPart_zero : primPart (0 : R[X]) = 1 := if_pos rfl theorem isPrimitive_primPart (p : R[X]) : p.primPart.IsPrimitive := by by_cases h : p = 0; · simp [h] rw [← content_eq_zero_iff] at h rw [isPrimitive_iff_content_eq_one] apply mul_left_cancel₀ h conv_rhs => rw [p.eq_C_content_mul_primPart, mul_one, content_C_mul, normalize_content] theorem content_primPart (p : R[X]) : p.primPart.content = 1 := p.isPrimitive_primPart.content_eq_one theorem primPart_ne_zero (p : R[X]) : p.primPart ≠ 0 := p.isPrimitive_primPart.ne_zero theorem natDegree_primPart (p : R[X]) : p.primPart.natDegree = p.natDegree := by by_cases h : C p.content = 0 · rw [C_eq_zero, content_eq_zero_iff] at h simp [h] conv_rhs => rw [p.eq_C_content_mul_primPart, natDegree_mul h p.primPart_ne_zero, natDegree_C, zero_add] @[simp] theorem IsPrimitive.primPart_eq {p : R[X]} (hp : p.IsPrimitive) : p.primPart = p := by rw [← one_mul p.primPart, ← C_1, ← hp.content_eq_one, ← p.eq_C_content_mul_primPart] theorem isUnit_primPart_C (r : R) : IsUnit (C r).primPart := by by_cases h0 : r = 0 · simp [h0] unfold IsUnit refine ⟨⟨C ↑(normUnit r)⁻¹, C ↑(normUnit r), by rw [← RingHom.map_mul, Units.inv_mul, C_1], by rw [← RingHom.map_mul, Units.mul_inv, C_1]⟩, ?_⟩ rw [← normalize_eq_zero, ← C_eq_zero] at h0 apply mul_left_cancel₀ h0 conv_rhs => rw [← content_C, ← (C r).eq_C_content_mul_primPart] simp only [Units.val_mk, normalize_apply, RingHom.map_mul] rw [mul_assoc, ← RingHom.map_mul, Units.mul_inv, C_1, mul_one] theorem primPart_dvd (p : R[X]) : p.primPart ∣ p := Dvd.intro_left (C p.content) p.eq_C_content_mul_primPart.symm theorem aeval_primPart_eq_zero {S : Type*} [Ring S] [IsDomain S] [Algebra R S] [NoZeroSMulDivisors R S] {p : R[X]} {s : S} (hpzero : p ≠ 0) (hp : aeval s p = 0) : aeval s p.primPart = 0 := by rw [eq_C_content_mul_primPart p, map_mul, aeval_C] at hp have hcont : p.content ≠ 0 := fun h => hpzero (content_eq_zero_iff.1 h) replace hcont := Function.Injective.ne (NoZeroSMulDivisors.algebraMap_injective R S) hcont rw [map_zero] at hcont exact eq_zero_of_ne_zero_of_mul_left_eq_zero hcont hp theorem eval₂_primPart_eq_zero {S : Type*} [CommRing S] [IsDomain S] {f : R →+* S} (hinj : Function.Injective f) {p : R[X]} {s : S} (hpzero : p ≠ 0) (hp : eval₂ f s p = 0) : eval₂ f s p.primPart = 0 := by rw [eq_C_content_mul_primPart p, eval₂_mul, eval₂_C] at hp have hcont : p.content ≠ 0 := fun h => hpzero (content_eq_zero_iff.1 h) replace hcont := Function.Injective.ne hinj hcont rw [map_zero] at hcont exact eq_zero_of_ne_zero_of_mul_left_eq_zero hcont hp end PrimPart theorem gcd_content_eq_of_dvd_sub {a : R} {p q : R[X]} (h : C a ∣ p - q) : GCDMonoid.gcd a p.content = GCDMonoid.gcd a q.content := by rw [content_eq_gcd_range_of_lt p (max p.natDegree q.natDegree).succ (lt_of_le_of_lt (le_max_left _ _) (Nat.lt_succ_self _))] rw [content_eq_gcd_range_of_lt q (max p.natDegree q.natDegree).succ (lt_of_le_of_lt (le_max_right _ _) (Nat.lt_succ_self _))] apply Finset.gcd_eq_of_dvd_sub intro x _ cases' h with w hw use w.coeff x rw [← coeff_sub, hw, coeff_C_mul] theorem content_mul_aux {p q : R[X]} : GCDMonoid.gcd (p * q).eraseLead.content p.leadingCoeff = GCDMonoid.gcd (p.eraseLead * q).content p.leadingCoeff := by rw [gcd_comm (content _) _, gcd_comm (content _) _] apply gcd_content_eq_of_dvd_sub rw [← self_sub_C_mul_X_pow, ← self_sub_C_mul_X_pow, sub_mul, sub_sub, add_comm, sub_add, sub_sub_cancel, leadingCoeff_mul, RingHom.map_mul, mul_assoc, mul_assoc] apply dvd_sub (Dvd.intro _ rfl) (Dvd.intro _ rfl) @[simp] theorem content_mul {p q : R[X]} : (p * q).content = p.content * q.content := by classical suffices h : ∀ (n : ℕ) (p q : R[X]), (p * q).degree < n → (p * q).content = p.content * q.content by apply h apply lt_of_le_of_lt degree_le_natDegree (WithBot.coe_lt_coe.2 (Nat.lt_succ_self _)) intro n induction' n with n ih · intro p q hpq rw [Nat.cast_zero, Nat.WithBot.lt_zero_iff, degree_eq_bot, mul_eq_zero] at hpq rcases hpq with (rfl | rfl) <;> simp intro p q hpq by_cases p0 : p = 0 · simp [p0] by_cases q0 : q = 0 · simp [q0] rw [degree_eq_natDegree (mul_ne_zero p0 q0), Nat.cast_lt, Nat.lt_succ_iff_lt_or_eq, ← Nat.cast_lt (α := WithBot ℕ), ← degree_eq_natDegree (mul_ne_zero p0 q0), natDegree_mul p0 q0] at hpq rcases hpq with (hlt | heq) · apply ih _ _ hlt rw [← p.natDegree_primPart, ← q.natDegree_primPart, ← Nat.cast_inj (R := WithBot ℕ), Nat.cast_add, ← degree_eq_natDegree p.primPart_ne_zero, ← degree_eq_natDegree q.primPart_ne_zero] at heq rw [p.eq_C_content_mul_primPart, q.eq_C_content_mul_primPart] suffices h : (q.primPart * p.primPart).content = 1 by rw [mul_assoc, content_C_mul, content_C_mul, mul_comm p.primPart, mul_assoc, content_C_mul, content_C_mul, h, mul_one, content_primPart, content_primPart, mul_one, mul_one] rw [← normalize_content, normalize_eq_one, isUnit_iff_dvd_one, content_eq_gcd_leadingCoeff_content_eraseLead, leadingCoeff_mul, gcd_comm] apply (gcd_mul_dvd_mul_gcd _ _ _).trans rw [content_mul_aux, ih, content_primPart, mul_one, gcd_comm, ← content_eq_gcd_leadingCoeff_content_eraseLead, content_primPart, one_mul, mul_comm q.primPart, content_mul_aux, ih, content_primPart, mul_one, gcd_comm, ← content_eq_gcd_leadingCoeff_content_eraseLead, content_primPart] · rw [← heq, degree_mul, WithBot.add_lt_add_iff_right] · apply degree_erase_lt p.primPart_ne_zero · rw [Ne, degree_eq_bot] apply q.primPart_ne_zero · rw [mul_comm, ← heq, degree_mul, WithBot.add_lt_add_iff_left] · apply degree_erase_lt q.primPart_ne_zero · rw [Ne, degree_eq_bot] apply p.primPart_ne_zero theorem IsPrimitive.mul {p q : R[X]} (hp : p.IsPrimitive) (hq : q.IsPrimitive) : (p * q).IsPrimitive := by rw [isPrimitive_iff_content_eq_one, content_mul, hp.content_eq_one, hq.content_eq_one, mul_one] @[simp] theorem primPart_mul {p q : R[X]} (h0 : p * q ≠ 0) : (p * q).primPart = p.primPart * q.primPart := by rw [Ne, ← content_eq_zero_iff, ← C_eq_zero] at h0 apply mul_left_cancel₀ h0 conv_lhs => rw [← (p * q).eq_C_content_mul_primPart, p.eq_C_content_mul_primPart, q.eq_C_content_mul_primPart] rw [content_mul, RingHom.map_mul] ring theorem IsPrimitive.dvd_primPart_iff_dvd {p q : R[X]} (hp : p.IsPrimitive) (hq : q ≠ 0) : p ∣ q.primPart ↔ p ∣ q := by refine ⟨fun h => h.trans (Dvd.intro_left _ q.eq_C_content_mul_primPart.symm), fun h => ?_⟩ rcases h with ⟨r, rfl⟩ apply Dvd.intro _ rw [primPart_mul hq, hp.primPart_eq] theorem exists_primitive_lcm_of_isPrimitive {p q : R[X]} (hp : p.IsPrimitive) (hq : q.IsPrimitive) : ∃ r : R[X], r.IsPrimitive ∧ ∀ s : R[X], p ∣ s ∧ q ∣ s ↔ r ∣ s := by classical have h : ∃ (n : ℕ) (r : R[X]), r.natDegree = n ∧ r.IsPrimitive ∧ p ∣ r ∧ q ∣ r := ⟨(p * q).natDegree, p * q, rfl, hp.mul hq, dvd_mul_right _ _, dvd_mul_left _ _⟩ rcases Nat.find_spec h with ⟨r, rdeg, rprim, pr, qr⟩ refine ⟨r, rprim, fun s => ⟨?_, fun rs => ⟨pr.trans rs, qr.trans rs⟩⟩⟩ suffices hs : ∀ (n : ℕ) (s : R[X]), s.natDegree = n → p ∣ s ∧ q ∣ s → r ∣ s from hs s.natDegree s rfl clear s by_contra! con rcases Nat.find_spec con with ⟨s, sdeg, ⟨ps, qs⟩, rs⟩ have s0 : s ≠ 0 := by contrapose! rs simp [rs] have hs := Nat.find_min' h ⟨_, s.natDegree_primPart, s.isPrimitive_primPart, (hp.dvd_primPart_iff_dvd s0).2 ps, (hq.dvd_primPart_iff_dvd s0).2 qs⟩ rw [← rdeg] at hs by_cases sC : s.natDegree ≤ 0 · rw [eq_C_of_natDegree_le_zero (le_trans hs sC), isPrimitive_iff_content_eq_one, content_C, normalize_eq_one] at rprim rw [eq_C_of_natDegree_le_zero (le_trans hs sC), ← dvd_content_iff_C_dvd] at rs apply rs rprim.dvd have hcancel := natDegree_cancelLeads_lt_of_natDegree_le_natDegree hs (lt_of_not_ge sC) rw [sdeg] at hcancel apply Nat.find_min con hcancel refine ⟨_, rfl, ⟨dvd_cancelLeads_of_dvd_of_dvd pr ps, dvd_cancelLeads_of_dvd_of_dvd qr qs⟩, fun rcs => rs ?_⟩ rw [← rprim.dvd_primPart_iff_dvd s0] rw [cancelLeads, tsub_eq_zero_iff_le.mpr hs, pow_zero, mul_one] at rcs have h := dvd_add rcs (Dvd.intro_left (C (leadingCoeff s) * X ^ (natDegree s - natDegree r)) rfl) have hC0 := rprim.ne_zero rw [Ne, ← leadingCoeff_eq_zero, ← C_eq_zero] at hC0 rw [sub_add_cancel, ← rprim.dvd_primPart_iff_dvd (mul_ne_zero hC0 s0)] at h rcases isUnit_primPart_C r.leadingCoeff with ⟨u, hu⟩ apply h.trans (Associated.symm ⟨u, _⟩).dvd rw [primPart_mul (mul_ne_zero hC0 s0), hu, mul_comm] theorem dvd_iff_content_dvd_content_and_primPart_dvd_primPart {p q : R[X]} (hq : q ≠ 0) : p ∣ q ↔ p.content ∣ q.content ∧ p.primPart ∣ q.primPart := by constructor <;> intro h · rcases h with ⟨r, rfl⟩ rw [content_mul, p.isPrimitive_primPart.dvd_primPart_iff_dvd hq] exact ⟨Dvd.intro _ rfl, p.primPart_dvd.trans (Dvd.intro _ rfl)⟩ · rw [p.eq_C_content_mul_primPart, q.eq_C_content_mul_primPart] exact mul_dvd_mul (RingHom.map_dvd C h.1) h.2 noncomputable instance (priority := 100) normalizedGcdMonoid : NormalizedGCDMonoid R[X] := letI := Classical.decEq R normalizedGCDMonoidOfExistsLCM fun p q => by rcases exists_primitive_lcm_of_isPrimitive p.isPrimitive_primPart q.isPrimitive_primPart with ⟨r, rprim, hr⟩ refine ⟨C (lcm p.content q.content) * r, fun s => ?_⟩ by_cases hs : s = 0 · simp [hs] by_cases hpq : C (lcm p.content q.content) = 0 · rw [C_eq_zero, lcm_eq_zero_iff, content_eq_zero_iff, content_eq_zero_iff] at hpq rcases hpq with (hpq | hpq) <;> simp [hpq, hs] iterate 3 rw [dvd_iff_content_dvd_content_and_primPart_dvd_primPart hs] rw [content_mul, rprim.content_eq_one, mul_one, content_C, normalize_lcm, lcm_dvd_iff, primPart_mul (mul_ne_zero hpq rprim.ne_zero), rprim.primPart_eq, (isUnit_primPart_C (lcm p.content q.content)).mul_left_dvd, ← hr s.primPart] tauto theorem degree_gcd_le_left {p : R[X]} (hp : p ≠ 0) (q) : (gcd p q).degree ≤ p.degree := by have := natDegree_le_iff_degree_le.mp (natDegree_le_of_dvd (gcd_dvd_left p q) hp) rwa [degree_eq_natDegree hp] theorem degree_gcd_le_right (p) {q : R[X]} (hq : q ≠ 0) : (gcd p q).degree ≤ q.degree := by rw [gcd_comm] exact degree_gcd_le_left hq p end NormalizedGCDMonoid end Polynomial
RingTheory\Polynomial\Dickson.lean
/- Copyright (c) 2021 Julian Kuelshammer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Julian Kuelshammer -/ import Mathlib.Algebra.CharP.Invertible import Mathlib.Data.ZMod.Basic import Mathlib.RingTheory.Localization.FractionRing import Mathlib.RingTheory.Polynomial.Chebyshev import Mathlib.Algebra.CharP.Basic import Mathlib.Algebra.EuclideanDomain.Field import Mathlib.Algebra.Polynomial.Roots /-! # Dickson polynomials The (generalised) Dickson polynomials are a family of polynomials indexed by `ℕ × ℕ`, with coefficients in a commutative ring `R` depending on an element `a∈R`. More precisely, the they satisfy the recursion `dickson k a (n + 2) = X * (dickson k a n + 1) - a * (dickson k a n)` with starting values `dickson k a 0 = 3 - k` and `dickson k a 1 = X`. In the literature, `dickson k a n` is called the `n`-th Dickson polynomial of the `k`-th kind associated to the parameter `a : R`. They are closely related to the Chebyshev polynomials in the case that `a=1`. When `a=0` they are just the family of monomials `X ^ n`. ## Main definition * `Polynomial.dickson`: the generalised Dickson polynomials. ## Main statements * `Polynomial.dickson_one_one_mul`, the `(m * n)`-th Dickson polynomial of the first kind for parameter `1 : R` is the composition of the `m`-th and `n`-th Dickson polynomials of the first kind for `1 : R`. * `Polynomial.dickson_one_one_charP`, for a prime number `p`, the `p`-th Dickson polynomial of the first kind associated to parameter `1 : R` is congruent to `X ^ p` modulo `p`. ## References * [R. Lidl, G. L. Mullen and G. Turnwald, _Dickson polynomials_][MR1237403] ## TODO * Redefine `dickson` in terms of `LinearRecurrence`. * Show that `dickson 2 1` is equal to the characteristic polynomial of the adjacency matrix of a type A Dynkin diagram. * Prove that the adjacency matrices of simply laced Dynkin diagrams are precisely the adjacency matrices of simple connected graphs which annihilate `dickson 2 1`. -/ noncomputable section namespace Polynomial open Polynomial variable {R S : Type*} [CommRing R] [CommRing S] (k : ℕ) (a : R) /-- `dickson` is the `n`-th (generalised) Dickson polynomial of the `k`-th kind associated to the element `a ∈ R`. -/ noncomputable def dickson : ℕ → R[X] | 0 => 3 - k | 1 => X | n + 2 => X * dickson (n + 1) - C a * dickson n @[simp] theorem dickson_zero : dickson k a 0 = 3 - k := rfl @[simp] theorem dickson_one : dickson k a 1 = X := rfl theorem dickson_two : dickson k a 2 = X ^ 2 - C a * (3 - k : R[X]) := by simp only [dickson, sq] @[simp] theorem dickson_add_two (n : ℕ) : dickson k a (n + 2) = X * dickson k a (n + 1) - C a * dickson k a n := by rw [dickson] theorem dickson_of_two_le {n : ℕ} (h : 2 ≤ n) : dickson k a n = X * dickson k a (n - 1) - C a * dickson k a (n - 2) := by obtain ⟨n, rfl⟩ := Nat.exists_eq_add_of_le h rw [add_comm] exact dickson_add_two k a n variable {k a} theorem map_dickson (f : R →+* S) : ∀ n : ℕ, map f (dickson k a n) = dickson k (f a) n | 0 => by simp_rw [dickson_zero, Polynomial.map_sub, Polynomial.map_natCast, Polynomial.map_ofNat] | 1 => by simp only [dickson_one, map_X] | n + 2 => by simp only [dickson_add_two, Polynomial.map_sub, Polynomial.map_mul, map_X, map_C] rw [map_dickson f n, map_dickson f (n + 1)] @[simp] theorem dickson_two_zero : ∀ n : ℕ, dickson 2 (0 : R) n = X ^ n | 0 => by simp only [dickson_zero, pow_zero] norm_num | 1 => by simp only [dickson_one, pow_one] | n + 2 => by simp only [dickson_add_two, C_0, zero_mul, sub_zero] rw [dickson_two_zero (n + 1), pow_add X (n + 1) 1, mul_comm, pow_one] section Dickson /-! ### A Lambda structure on `ℤ[X]` Mathlib doesn't currently know what a Lambda ring is. But once it does, we can endow `ℤ[X]` with a Lambda structure in terms of the `dickson 1 1` polynomials defined below. There is exactly one other Lambda structure on `ℤ[X]` in terms of binomial polynomials. -/ theorem dickson_one_one_eval_add_inv (x y : R) (h : x * y = 1) : ∀ n, (dickson 1 (1 : R) n).eval (x + y) = x ^ n + y ^ n | 0 => by simp only [eval_one, eval_add, pow_zero, dickson_zero]; norm_num | 1 => by simp only [eval_X, dickson_one, pow_one] | n + 2 => by simp only [eval_sub, eval_mul, dickson_one_one_eval_add_inv x y h _, eval_X, dickson_add_two, C_1, eval_one] conv_lhs => simp only [pow_succ', add_mul, mul_add, h, ← mul_assoc, mul_comm y x, one_mul] ring variable (R) -- Porting note: Added 2 new theorems for convenience private theorem two_mul_C_half_eq_one [Invertible (2 : R)] : 2 * C (⅟ 2 : R) = 1 := by rw [two_mul, ← C_add, invOf_two_add_invOf_two, C_1] private theorem C_half_mul_two_eq_one [Invertible (2 : R)] : C (⅟ 2 : R) * 2 = 1 := by rw [mul_comm, two_mul_C_half_eq_one] theorem dickson_one_one_eq_chebyshev_T [Invertible (2 : R)] : ∀ n, dickson 1 (1 : R) n = 2 * (Chebyshev.T R n).comp (C (⅟ 2) * X) | 0 => by simp only [Chebyshev.T_zero, mul_one, one_comp, dickson_zero] norm_num | 1 => by rw [dickson_one, Nat.cast_one, Chebyshev.T_one, X_comp, ← mul_assoc, two_mul_C_half_eq_one, one_mul] | n + 2 => by rw [dickson_add_two, C_1, Nat.cast_add, Nat.cast_two, Chebyshev.T_add_two, dickson_one_one_eq_chebyshev_T (n + 1), dickson_one_one_eq_chebyshev_T n, sub_comp, mul_comp, mul_comp, X_comp, ofNat_comp] simp_rw [← mul_assoc, Nat.cast_ofNat, two_mul_C_half_eq_one, Nat.cast_add, Nat.cast_one] ring theorem chebyshev_T_eq_dickson_one_one [Invertible (2 : R)] (n : ℕ) : Chebyshev.T R n = C (⅟ 2) * (dickson 1 1 n).comp (2 * X) := by rw [dickson_one_one_eq_chebyshev_T, mul_comp, ofNat_comp, comp_assoc, mul_comp, C_comp, X_comp] simp_rw [← mul_assoc, Nat.cast_ofNat, C_half_mul_two_eq_one, one_mul, comp_X] /-- The `(m * n)`-th Dickson polynomial of the first kind is the composition of the `m`-th and `n`-th. -/ theorem dickson_one_one_mul (m n : ℕ) : dickson 1 (1 : R) (m * n) = (dickson 1 1 m).comp (dickson 1 1 n) := by have h : (1 : R) = Int.castRingHom R 1 := by simp only [eq_intCast, Int.cast_one] rw [h] simp only [← map_dickson (Int.castRingHom R), ← map_comp] congr 1 apply map_injective (Int.castRingHom ℚ) Int.cast_injective simp only [map_dickson, map_comp, eq_intCast, Int.cast_one, dickson_one_one_eq_chebyshev_T, Nat.cast_mul, Chebyshev.T_mul, two_mul, ← add_comp] simp only [← two_mul, ← comp_assoc] apply eval₂_congr rfl rfl rw [comp_assoc] apply eval₂_congr rfl _ rfl rw [mul_comp, C_comp, X_comp, ← mul_assoc, C_half_mul_two_eq_one, one_mul] theorem dickson_one_one_comp_comm (m n : ℕ) : (dickson 1 (1 : R) m).comp (dickson 1 1 n) = (dickson 1 1 n).comp (dickson 1 1 m) := by rw [← dickson_one_one_mul, mul_comm, dickson_one_one_mul] theorem dickson_one_one_zmod_p (p : ℕ) [Fact p.Prime] : dickson 1 (1 : ZMod p) p = X ^ p := by -- Recall that `dickson_one_one_eval_add_inv` characterises `dickson 1 1 p` -- as a polynomial that maps `x + x⁻¹` to `x ^ p + (x⁻¹) ^ p`. -- Since `X ^ p` also satisfies this property in characteristic `p`, -- we can use a variant on `Polynomial.funext` to conclude that these polynomials are equal. -- For this argument, we need an arbitrary infinite field of characteristic `p`. obtain ⟨K, _, _, H⟩ : ∃ (K : Type) (_ : Field K), ∃ _ : CharP K p, Infinite K := by let K := FractionRing (Polynomial (ZMod p)) let f : ZMod p →+* K := (algebraMap _ (FractionRing _)).comp C have : CharP K p := by rw [← f.charP_iff_charP] infer_instance haveI : Infinite K := Infinite.of_injective (algebraMap (Polynomial (ZMod p)) (FractionRing (Polynomial (ZMod p)))) (IsFractionRing.injective _ _) refine ⟨K, ?_, ?_, ?_⟩ <;> infer_instance apply map_injective (ZMod.castHom (dvd_refl p) K) (RingHom.injective _) rw [map_dickson, Polynomial.map_pow, map_X] apply eq_of_infinite_eval_eq -- The two polynomials agree on all `x` of the form `x = y + y⁻¹`. apply @Set.Infinite.mono _ { x : K | ∃ y, x = y + y⁻¹ ∧ y ≠ 0 } · rintro _ ⟨x, rfl, hx⟩ simp only [eval_X, eval_pow, Set.mem_setOf_eq, @add_pow_char K _ p, dickson_one_one_eval_add_inv _ _ (mul_inv_cancel hx), inv_pow, ZMod.castHom_apply, ZMod.cast_one'] -- Now we need to show that the set of such `x` is infinite. -- If the set is finite, then we will show that `K` is also finite. · intro h rw [← Set.infinite_univ_iff] at H apply H -- To each `x` of the form `x = y + y⁻¹` -- we `bind` the set of `y` that solve the equation `x = y + y⁻¹`. -- For every `x`, that set is finite (since it is governed by a quadratic equation). -- For the moment, we claim that all these sets together cover `K`. suffices (Set.univ : Set K) = ⋃ x ∈ { x : K | ∃ y : K, x = y + y⁻¹ ∧ y ≠ 0 }, { y | x = y + y⁻¹ ∨ y = 0 } by rw [this] clear this refine h.biUnion fun x _ => ?_ -- The following quadratic polynomial has as solutions the `y` for which `x = y + y⁻¹`. let φ : K[X] := X ^ 2 - C x * X + 1 have hφ : φ ≠ 0 := by intro H have : φ.eval 0 = 0 := by rw [H, eval_zero] simpa [φ, eval_X, eval_one, eval_pow, eval_sub, sub_zero, eval_add, eval_mul, mul_zero, sq, zero_add, one_ne_zero] classical convert (φ.roots ∪ {0}).toFinset.finite_toSet using 1 ext1 y simp only [φ, Multiset.mem_toFinset, Set.mem_setOf_eq, Finset.mem_coe, Multiset.mem_union, mem_roots hφ, IsRoot, eval_add, eval_sub, eval_pow, eval_mul, eval_X, eval_C, eval_one, Multiset.mem_singleton] by_cases hy : y = 0 · simp only [hy, eq_self_iff_true, or_true_iff] apply or_congr _ Iff.rfl rw [← mul_left_inj' hy, eq_comm, ← sub_eq_zero, add_mul, inv_mul_cancel hy] apply eq_iff_eq_cancel_right.mpr ring -- Finally, we prove the claim that our finite union of finite sets covers all of `K`. apply (Set.eq_univ_of_forall _).symm intro x simp only [exists_prop, Set.mem_iUnion, Set.bind_def, Ne, Set.mem_setOf_eq] by_cases hx : x = 0 · simp only [hx, and_true_iff, eq_self_iff_true, inv_zero, or_true_iff] exact ⟨_, 1, rfl, one_ne_zero⟩ · simp only [hx, or_false_iff, exists_eq_right] exact ⟨_, rfl, hx⟩ theorem dickson_one_one_charP (p : ℕ) [Fact p.Prime] [CharP R p] : dickson 1 (1 : R) p = X ^ p := by have h : (1 : R) = ZMod.castHom (dvd_refl p) R 1 := by simp only [ZMod.castHom_apply, ZMod.cast_one'] rw [h, ← map_dickson (ZMod.castHom (dvd_refl p) R), dickson_one_one_zmod_p, Polynomial.map_pow, map_X] end Dickson end Polynomial
RingTheory\Polynomial\GaussLemma.lean
/- Copyright (c) 2020 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.FieldTheory.SplittingField.Construction import Mathlib.RingTheory.Int.Basic import Mathlib.RingTheory.Localization.Integral import Mathlib.RingTheory.IntegralClosure.IntegrallyClosed /-! # Gauss's Lemma Gauss's Lemma is one of a few results pertaining to irreducibility of primitive polynomials. ## Main Results - `IsIntegrallyClosed.eq_map_mul_C_of_dvd`: if `R` is integrally closed, `K = Frac(R)` and `g : K[X]` divides a monic polynomial with coefficients in `R`, then `g * (C g.leadingCoeff⁻¹)` has coefficients in `R` - `Polynomial.Monic.irreducible_iff_irreducible_map_fraction_map`: A monic polynomial over an integrally closed domain is irreducible iff it is irreducible in a fraction field - `isIntegrallyClosed_iff'`: Integrally closed domains are precisely the domains for in which Gauss's lemma holds for monic polynomials - `Polynomial.IsPrimitive.irreducible_iff_irreducible_map_fraction_map`: A primitive polynomial over a GCD domain is irreducible iff it is irreducible in a fraction field - `Polynomial.IsPrimitive.Int.irreducible_iff_irreducible_map_cast`: A primitive polynomial over `ℤ` is irreducible iff it is irreducible over `ℚ`. - `Polynomial.IsPrimitive.dvd_iff_fraction_map_dvd_fraction_map`: Two primitive polynomials over a GCD domain divide each other iff they do in a fraction field. - `Polynomial.IsPrimitive.Int.dvd_iff_map_cast_dvd_map_cast`: Two primitive polynomials over `ℤ` divide each other if they do in `ℚ`. -/ open scoped nonZeroDivisors Polynomial variable {R : Type*} [CommRing R] section IsIntegrallyClosed open Polynomial open integralClosure open IsIntegrallyClosed variable (K : Type*) [Field K] [Algebra R K] theorem integralClosure.mem_lifts_of_monic_of_dvd_map {f : R[X]} (hf : f.Monic) {g : K[X]} (hg : g.Monic) (hd : g ∣ f.map (algebraMap R K)) : g ∈ lifts (algebraMap (integralClosure R K) K) := by have := mem_lift_of_splits_of_roots_mem_range (integralClosure R g.SplittingField) ((splits_id_iff_splits _).2 <| SplittingField.splits g) (hg.map _) fun a ha => (SetLike.ext_iff.mp (integralClosure R g.SplittingField).range_algebraMap _).mpr <| roots_mem_integralClosure hf ?_ · rw [lifts_iff_coeff_lifts, ← RingHom.coe_range, Subalgebra.range_algebraMap] at this refine (lifts_iff_coeff_lifts _).2 fun n => ?_ rw [← RingHom.coe_range, Subalgebra.range_algebraMap] obtain ⟨p, hp, he⟩ := SetLike.mem_coe.mp (this n); use p, hp rw [IsScalarTower.algebraMap_eq R K, coeff_map, ← eval₂_map, eval₂_at_apply] at he rw [eval₂_eq_eval_map]; apply (injective_iff_map_eq_zero _).1 _ _ he apply RingHom.injective rw [aroots_def, IsScalarTower.algebraMap_eq R K _, ← map_map] refine Multiset.mem_of_le (roots.le_of_dvd ((hf.map _).map _).ne_zero ?_) ha exact map_dvd (algebraMap K g.SplittingField) hd variable [IsDomain R] [IsFractionRing R K] /-- If `K = Frac(R)` and `g : K[X]` divides a monic polynomial with coefficients in `R`, then `g * (C g.leadingCoeff⁻¹)` has coefficients in `R` -/ theorem IsIntegrallyClosed.eq_map_mul_C_of_dvd [IsIntegrallyClosed R] {f : R[X]} (hf : f.Monic) {g : K[X]} (hg : g ∣ f.map (algebraMap R K)) : ∃ g' : R[X], g'.map (algebraMap R K) * (C <| leadingCoeff g) = g := by have g_ne_0 : g ≠ 0 := ne_zero_of_dvd_ne_zero (Monic.ne_zero <| hf.map (algebraMap R K)) hg suffices lem : ∃ g' : R[X], g'.map (algebraMap R K) = g * C g.leadingCoeff⁻¹ by obtain ⟨g', hg'⟩ := lem use g' rw [hg', mul_assoc, ← C_mul, inv_mul_cancel (leadingCoeff_ne_zero.mpr g_ne_0), C_1, mul_one] have g_mul_dvd : g * C g.leadingCoeff⁻¹ ∣ f.map (algebraMap R K) := by rwa [Associated.dvd_iff_dvd_left (show Associated (g * C g.leadingCoeff⁻¹) g from _)] rw [associated_mul_isUnit_left_iff] exact isUnit_C.mpr (inv_ne_zero <| leadingCoeff_ne_zero.mpr g_ne_0).isUnit let algeq := (Subalgebra.equivOfEq _ _ <| integralClosure_eq_bot R _).trans (Algebra.botEquivOfInjective <| IsFractionRing.injective R <| K) have : (algebraMap R _).comp algeq.toAlgHom.toRingHom = (integralClosure R _).toSubring.subtype := by ext x; (conv_rhs => rw [← algeq.symm_apply_apply x]); rfl have H := (mem_lifts _).1 (integralClosure.mem_lifts_of_monic_of_dvd_map K hf (monic_mul_leadingCoeff_inv g_ne_0) g_mul_dvd) refine ⟨map algeq.toAlgHom.toRingHom ?_, ?_⟩ · use! Classical.choose H · rw [map_map, this] exact Classical.choose_spec H end IsIntegrallyClosed namespace Polynomial section variable {S : Type*} [CommRing S] [IsDomain S] variable {φ : R →+* S} (hinj : Function.Injective φ) {f : R[X]} (hf : f.IsPrimitive) theorem IsPrimitive.isUnit_iff_isUnit_map_of_injective : IsUnit f ↔ IsUnit (map φ f) := by refine ⟨(mapRingHom φ).isUnit_map, fun h => ?_⟩ rcases isUnit_iff.1 h with ⟨_, ⟨u, rfl⟩, hu⟩ have hdeg := degree_C u.ne_zero rw [hu, degree_map_eq_of_injective hinj] at hdeg rw [eq_C_of_degree_eq_zero hdeg] at hf ⊢ exact isUnit_C.mpr (isPrimitive_iff_isUnit_of_C_dvd.mp hf (f.coeff 0) dvd_rfl) theorem IsPrimitive.irreducible_of_irreducible_map_of_injective (h_irr : Irreducible (map φ f)) : Irreducible f := by refine ⟨fun h => h_irr.not_unit (IsUnit.map (mapRingHom φ) h), fun a b h => (h_irr.isUnit_or_isUnit <| by rw [h, Polynomial.map_mul]).imp ?_ ?_⟩ all_goals apply ((isPrimitive_of_dvd hf _).isUnit_iff_isUnit_map_of_injective hinj).mpr exacts [Dvd.intro _ h.symm, Dvd.intro_left _ h.symm] end section FractionMap variable {K : Type*} [Field K] [Algebra R K] [IsFractionRing R K] theorem IsPrimitive.isUnit_iff_isUnit_map {p : R[X]} (hp : p.IsPrimitive) : IsUnit p ↔ IsUnit (p.map (algebraMap R K)) := hp.isUnit_iff_isUnit_map_of_injective (IsFractionRing.injective _ _) variable [IsDomain R] section IsIntegrallyClosed open IsIntegrallyClosed /-- **Gauss's Lemma** for integrally closed domains states that a monic polynomial is irreducible iff it is irreducible in the fraction field. -/ theorem Monic.irreducible_iff_irreducible_map_fraction_map [IsIntegrallyClosed R] {p : R[X]} (h : p.Monic) : Irreducible p ↔ Irreducible (p.map <| algebraMap R K) := by /- The ← direction follows from `IsPrimitive.irreducible_of_irreducible_map_of_injective`. For the → direction, it is enought to show that if `(p.map <| algebraMap R K) = a * b` and `a` is not a unit then `b` is a unit -/ refine ⟨fun hp => irreducible_iff.mpr ⟨hp.not_unit.imp h.isPrimitive.isUnit_iff_isUnit_map.mpr, fun a b H => or_iff_not_imp_left.mpr fun hₐ => ?_⟩, fun hp => h.isPrimitive.irreducible_of_irreducible_map_of_injective (IsFractionRing.injective R K) hp⟩ obtain ⟨a', ha⟩ := eq_map_mul_C_of_dvd K h (dvd_of_mul_right_eq b H.symm) obtain ⟨b', hb⟩ := eq_map_mul_C_of_dvd K h (dvd_of_mul_left_eq a H.symm) have : a.leadingCoeff * b.leadingCoeff = 1 := by rw [← leadingCoeff_mul, ← H, Monic.leadingCoeff (h.map <| algebraMap R K)] rw [← ha, ← hb, mul_comm _ (C b.leadingCoeff), mul_assoc, ← mul_assoc (C a.leadingCoeff), ← C_mul, this, C_1, one_mul, ← Polynomial.map_mul] at H rw [← hb, ← Polynomial.coe_mapRingHom] refine IsUnit.mul (IsUnit.map _ (Or.resolve_left (hp.isUnit_or_isUnit ?_) (show ¬IsUnit a' from ?_))) (isUnit_iff_exists_inv'.mpr -- Porting note(https://github.com/leanprover-community/mathlib4/issues/5073): was `rwa` (Exists.intro (C a.leadingCoeff) <| by rw [← C_mul, this, C_1])) · exact Polynomial.map_injective _ (IsFractionRing.injective R K) H · by_contra h_contra refine hₐ ?_ rw [← ha, ← Polynomial.coe_mapRingHom] exact IsUnit.mul (IsUnit.map _ h_contra) (isUnit_iff_exists_inv.mpr -- Porting note(https://github.com/leanprover-community/mathlib4/issues/5073): was `rwa` (Exists.intro (C b.leadingCoeff) <| by rw [← C_mul, this, C_1])) /-- Integrally closed domains are precisely the domains for in which Gauss's lemma holds for monic polynomials -/ theorem isIntegrallyClosed_iff' : IsIntegrallyClosed R ↔ ∀ p : R[X], p.Monic → (Irreducible p ↔ Irreducible (p.map <| algebraMap R K)) := by constructor · intro hR p hp; exact Monic.irreducible_iff_irreducible_map_fraction_map hp · intro H refine (isIntegrallyClosed_iff K).mpr fun {x} hx => RingHom.mem_range.mp <| minpoly.mem_range_of_degree_eq_one R x ?_ rw [← Monic.degree_map (minpoly.monic hx) (algebraMap R K)] apply degree_eq_one_of_irreducible_of_root ((H _ <| minpoly.monic hx).mp (minpoly.irreducible hx)) rw [IsRoot, eval_map, ← aeval_def, minpoly.aeval R x] theorem Monic.dvd_of_fraction_map_dvd_fraction_map [IsIntegrallyClosed R] {p q : R[X]} (hp : p.Monic) (hq : q.Monic) (h : q.map (algebraMap R K) ∣ p.map (algebraMap R K)) : q ∣ p := by obtain ⟨r, hr⟩ := h obtain ⟨d', hr'⟩ := IsIntegrallyClosed.eq_map_mul_C_of_dvd K hp (dvd_of_mul_left_eq _ hr.symm) rw [Monic.leadingCoeff, C_1, mul_one] at hr' · rw [← hr', ← Polynomial.map_mul] at hr exact dvd_of_mul_right_eq _ (Polynomial.map_injective _ (IsFractionRing.injective R K) hr.symm) · exact Monic.of_mul_monic_left (hq.map (algebraMap R K)) (by simpa [← hr] using hp.map _) theorem Monic.dvd_iff_fraction_map_dvd_fraction_map [IsIntegrallyClosed R] {p q : R[X]} (hp : p.Monic) (hq : q.Monic) : q.map (algebraMap R K) ∣ p.map (algebraMap R K) ↔ q ∣ p := ⟨fun h => hp.dvd_of_fraction_map_dvd_fraction_map hq h, fun ⟨a, b⟩ => ⟨a.map (algebraMap R K), b.symm ▸ Polynomial.map_mul (algebraMap R K)⟩⟩ end IsIntegrallyClosed open IsLocalization section NormalizedGCDMonoid variable [NormalizedGCDMonoid R] theorem isUnit_or_eq_zero_of_isUnit_integerNormalization_primPart {p : K[X]} (h0 : p ≠ 0) (h : IsUnit (integerNormalization R⁰ p).primPart) : IsUnit p := by rcases isUnit_iff.1 h with ⟨_, ⟨u, rfl⟩, hu⟩ obtain ⟨⟨c, c0⟩, hc⟩ := integerNormalization_map_to_map R⁰ p rw [Subtype.coe_mk, Algebra.smul_def, algebraMap_apply] at hc apply isUnit_of_mul_isUnit_right rw [← hc, (integerNormalization R⁰ p).eq_C_content_mul_primPart, ← hu, ← RingHom.map_mul, isUnit_iff] refine ⟨algebraMap R K ((integerNormalization R⁰ p).content * ↑u), isUnit_iff_ne_zero.2 fun con => ?_, by simp⟩ replace con := (injective_iff_map_eq_zero (algebraMap R K)).1 (IsFractionRing.injective _ _) _ con rw [mul_eq_zero, content_eq_zero_iff, IsFractionRing.integerNormalization_eq_zero_iff] at con rcases con with (con | con) · apply h0 con · apply Units.ne_zero _ con /-- **Gauss's Lemma** for GCD domains states that a primitive polynomial is irreducible iff it is irreducible in the fraction field. -/ theorem IsPrimitive.irreducible_iff_irreducible_map_fraction_map {p : R[X]} (hp : p.IsPrimitive) : Irreducible p ↔ Irreducible (p.map (algebraMap R K)) := by -- Porting note: was `(IsFractionRing.injective _ _)` refine ⟨fun hi => ⟨fun h => hi.not_unit (hp.isUnit_iff_isUnit_map.2 h), fun a b hab => ?_⟩, hp.irreducible_of_irreducible_map_of_injective (IsFractionRing.injective R K)⟩ obtain ⟨⟨c, c0⟩, hc⟩ := integerNormalization_map_to_map R⁰ a obtain ⟨⟨d, d0⟩, hd⟩ := integerNormalization_map_to_map R⁰ b rw [Algebra.smul_def, algebraMap_apply, Subtype.coe_mk] at hc hd rw [mem_nonZeroDivisors_iff_ne_zero] at c0 d0 have hcd0 : c * d ≠ 0 := mul_ne_zero c0 d0 rw [Ne, ← C_eq_zero] at hcd0 have h1 : C c * C d * p = integerNormalization R⁰ a * integerNormalization R⁰ b := by apply map_injective (algebraMap R K) (IsFractionRing.injective _ _) _ rw [Polynomial.map_mul, Polynomial.map_mul, Polynomial.map_mul, hc, hd, map_C, map_C, hab] ring obtain ⟨u, hu⟩ : Associated (c * d) (content (integerNormalization R⁰ a) * content (integerNormalization R⁰ b)) := by rw [← dvd_dvd_iff_associated, ← normalize_eq_normalize_iff, normalize.map_mul, normalize.map_mul, normalize_content, normalize_content, ← mul_one (normalize c * normalize d), ← hp.content_eq_one, ← content_C, ← content_C, ← content_mul, ← content_mul, ← content_mul, h1] rw [← RingHom.map_mul, eq_comm, (integerNormalization R⁰ a).eq_C_content_mul_primPart, (integerNormalization R⁰ b).eq_C_content_mul_primPart, mul_assoc, mul_comm _ (C _ * _), ← mul_assoc, ← mul_assoc, ← RingHom.map_mul, ← hu, RingHom.map_mul, mul_assoc, mul_assoc, ← mul_assoc (C (u : R))] at h1 have h0 : a ≠ 0 ∧ b ≠ 0 := by classical rw [Ne, Ne, ← not_or, ← mul_eq_zero, ← hab] intro con apply hp.ne_zero (map_injective (algebraMap R K) (IsFractionRing.injective _ _) _) simp [con] rcases hi.isUnit_or_isUnit (mul_left_cancel₀ hcd0 h1).symm with (h | h) · right apply isUnit_or_eq_zero_of_isUnit_integerNormalization_primPart h0.2 (isUnit_of_mul_isUnit_right h) · left apply isUnit_or_eq_zero_of_isUnit_integerNormalization_primPart h0.1 h theorem IsPrimitive.dvd_of_fraction_map_dvd_fraction_map {p q : R[X]} (hp : p.IsPrimitive) (hq : q.IsPrimitive) (h_dvd : p.map (algebraMap R K) ∣ q.map (algebraMap R K)) : p ∣ q := by rcases h_dvd with ⟨r, hr⟩ obtain ⟨⟨s, s0⟩, hs⟩ := integerNormalization_map_to_map R⁰ r rw [Subtype.coe_mk, Algebra.smul_def, algebraMap_apply] at hs have h : p ∣ q * C s := by use integerNormalization R⁰ r apply map_injective (algebraMap R K) (IsFractionRing.injective _ _) rw [Polynomial.map_mul, Polynomial.map_mul, hs, hr, mul_assoc, mul_comm r] simp rw [← hp.dvd_primPart_iff_dvd, primPart_mul, hq.primPart_eq, Associated.dvd_iff_dvd_right] at h · exact h · symm rcases isUnit_primPart_C s with ⟨u, hu⟩ use u rw [hu] iterate 2 apply mul_ne_zero hq.ne_zero rw [Ne, C_eq_zero] contrapose! s0 simp [s0, mem_nonZeroDivisors_iff_ne_zero] variable (K) theorem IsPrimitive.dvd_iff_fraction_map_dvd_fraction_map {p q : R[X]} (hp : p.IsPrimitive) (hq : q.IsPrimitive) : p ∣ q ↔ p.map (algebraMap R K) ∣ q.map (algebraMap R K) := ⟨fun ⟨a, b⟩ => ⟨a.map (algebraMap R K), b.symm ▸ Polynomial.map_mul (algebraMap R K)⟩, fun h => hp.dvd_of_fraction_map_dvd_fraction_map hq h⟩ end NormalizedGCDMonoid end FractionMap /-- **Gauss's Lemma** for `ℤ` states that a primitive integer polynomial is irreducible iff it is irreducible over `ℚ`. -/ theorem IsPrimitive.Int.irreducible_iff_irreducible_map_cast {p : ℤ[X]} (hp : p.IsPrimitive) : Irreducible p ↔ Irreducible (p.map (Int.castRingHom ℚ)) := hp.irreducible_iff_irreducible_map_fraction_map theorem IsPrimitive.Int.dvd_iff_map_cast_dvd_map_cast (p q : ℤ[X]) (hp : p.IsPrimitive) (hq : q.IsPrimitive) : p ∣ q ↔ p.map (Int.castRingHom ℚ) ∣ q.map (Int.castRingHom ℚ) := hp.dvd_iff_fraction_map_dvd_fraction_map ℚ hq end Polynomial
RingTheory\Polynomial\IntegralNormalization.lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.Degree.Lemmas import Mathlib.Algebra.Polynomial.Monic /-! # Theory of monic polynomials We define `integralNormalization`, which relate arbitrary polynomials to monic ones. -/ open Polynomial namespace Polynomial universe u v y variable {R : Type u} {S : Type v} {a b : R} {m n : ℕ} {ι : Type y} section IntegralNormalization section Semiring variable [Semiring R] /-- If `f : R[X]` is a nonzero polynomial with root `z`, `integralNormalization f` is a monic polynomial with root `leadingCoeff f * z`. Moreover, `integralNormalization 0 = 0`. -/ noncomputable def integralNormalization (f : R[X]) : R[X] := ∑ i ∈ f.support, monomial i (if f.degree = i then 1 else coeff f i * f.leadingCoeff ^ (f.natDegree - 1 - i)) @[simp] theorem integralNormalization_zero : integralNormalization (0 : R[X]) = 0 := by simp [integralNormalization] theorem integralNormalization_coeff {f : R[X]} {i : ℕ} : (integralNormalization f).coeff i = if f.degree = i then 1 else coeff f i * f.leadingCoeff ^ (f.natDegree - 1 - i) := by have : f.coeff i = 0 → f.degree ≠ i := fun hc hd => coeff_ne_zero_of_eq_degree hd hc simp (config := { contextual := true }) [integralNormalization, coeff_monomial, this, mem_support_iff] theorem integralNormalization_support {f : R[X]} : (integralNormalization f).support ⊆ f.support := by intro simp (config := { contextual := true }) [integralNormalization, coeff_monomial, mem_support_iff] theorem integralNormalization_coeff_degree {f : R[X]} {i : ℕ} (hi : f.degree = i) : (integralNormalization f).coeff i = 1 := by rw [integralNormalization_coeff, if_pos hi] theorem integralNormalization_coeff_natDegree {f : R[X]} (hf : f ≠ 0) : (integralNormalization f).coeff (natDegree f) = 1 := integralNormalization_coeff_degree (degree_eq_natDegree hf) theorem integralNormalization_coeff_ne_degree {f : R[X]} {i : ℕ} (hi : f.degree ≠ i) : coeff (integralNormalization f) i = coeff f i * f.leadingCoeff ^ (f.natDegree - 1 - i) := by rw [integralNormalization_coeff, if_neg hi] theorem integralNormalization_coeff_ne_natDegree {f : R[X]} {i : ℕ} (hi : i ≠ natDegree f) : coeff (integralNormalization f) i = coeff f i * f.leadingCoeff ^ (f.natDegree - 1 - i) := integralNormalization_coeff_ne_degree (degree_ne_of_natDegree_ne hi.symm) theorem monic_integralNormalization {f : R[X]} (hf : f ≠ 0) : Monic (integralNormalization f) := monic_of_degree_le f.natDegree (Finset.sup_le fun i h => WithBot.coe_le_coe.2 <| le_natDegree_of_mem_supp i <| integralNormalization_support h) (integralNormalization_coeff_natDegree hf) end Semiring section IsDomain variable [Ring R] [IsDomain R] @[simp] theorem support_integralNormalization {f : R[X]} : (integralNormalization f).support = f.support := by by_cases hf : f = 0; · simp [hf] ext i refine ⟨fun h => integralNormalization_support h, ?_⟩ simp only [integralNormalization_coeff, mem_support_iff] intro hfi split_ifs with hi <;> simp [hf, hfi, hi] end IsDomain section IsDomain variable [CommRing R] [IsDomain R] variable [CommSemiring S] theorem integralNormalization_eval₂_eq_zero {p : R[X]} (f : R →+* S) {z : S} (hz : eval₂ f z p = 0) (inj : ∀ x : R, f x = 0 → x = 0) : eval₂ f (z * f p.leadingCoeff) (integralNormalization p) = 0 := calc eval₂ f (z * f p.leadingCoeff) (integralNormalization p) = p.support.attach.sum fun i => f (coeff (integralNormalization p) i.1 * p.leadingCoeff ^ i.1) * z ^ i.1 := by rw [eval₂_eq_sum, sum_def, support_integralNormalization] simp only [mul_comm z, mul_pow, mul_assoc, RingHom.map_pow, RingHom.map_mul] rw [← Finset.sum_attach] _ = p.support.attach.sum fun i => f (coeff p i.1 * p.leadingCoeff ^ (natDegree p - 1)) * z ^ i.1 := by by_cases hp : p = 0; · simp [hp] have one_le_deg : 1 ≤ natDegree p := Nat.succ_le_of_lt (natDegree_pos_of_eval₂_root hp f hz inj) congr with i congr 2 by_cases hi : i.1 = natDegree p · rw [hi, integralNormalization_coeff_degree, one_mul, leadingCoeff, ← pow_succ', tsub_add_cancel_of_le one_le_deg] exact degree_eq_natDegree hp · have : i.1 ≤ p.natDegree - 1 := Nat.le_sub_one_of_lt (lt_of_le_of_ne (le_natDegree_of_ne_zero (mem_support_iff.mp i.2)) hi) rw [integralNormalization_coeff_ne_natDegree hi, mul_assoc, ← pow_add, tsub_add_cancel_of_le this] _ = f p.leadingCoeff ^ (natDegree p - 1) * eval₂ f z p := by simp_rw [eval₂_eq_sum, sum_def, fun i => mul_comm (coeff p i), RingHom.map_mul, RingHom.map_pow, mul_assoc, ← Finset.mul_sum] congr 1 exact p.support.sum_attach fun i ↦ f (p.coeff i) * z ^ i _ = 0 := by rw [hz, mul_zero] theorem integralNormalization_aeval_eq_zero [Algebra R S] {f : R[X]} {z : S} (hz : aeval z f = 0) (inj : ∀ x : R, algebraMap R S x = 0 → x = 0) : aeval (z * algebraMap R S f.leadingCoeff) (integralNormalization f) = 0 := integralNormalization_eval₂_eq_zero (algebraMap R S) hz inj end IsDomain end IntegralNormalization end Polynomial
RingTheory\Polynomial\IrreducibleRing.lean
/- Copyright (c) 2024 Jz Pan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jz Pan -/ import Mathlib.Algebra.Polynomial.RingDivision import Mathlib.RingTheory.Polynomial.Nilpotent /-! # Polynomials over an irreducible ring This file contains results about the polynomials over an irreducible ring (i.e. a ring with only one minimal prime ideal, equivalently, whose spectrum is an irreducible topological space). ## Main results - `Polynomial.Monic.irreducible_of_irreducible_map_of_isPrime_nilradical`: a monic polynomial over an irreducible ring is irreducible if it is irreducible after mapping into an integral domain. A generalization to `Polynomial.Monic.irreducible_of_irreducible_map`. ## Tags polynomial, irreducible ring, nilradical, prime ideal -/ open scoped Classical Polynomial open Polynomial noncomputable section /-- A polynomial over an irreducible ring `R` is irreducible if it is monic and irreducible after mapping into an integral domain `S` (https://math.stackexchange.com/a/4843432/235999). A generalization to `Polynomial.Monic.irreducible_of_irreducible_map`. -/ theorem Polynomial.Monic.irreducible_of_irreducible_map_of_isPrime_nilradical {R S : Type*} [CommRing R] [(nilradical R).IsPrime] [CommRing S] [IsDomain S] (φ : R →+* S) (f : R[X]) (hm : f.Monic) (hi : Irreducible (f.map φ)) : Irreducible f := by let R' := R ⧸ nilradical R let ψ : R' →+* S := Ideal.Quotient.lift (nilradical R) φ (haveI := RingHom.ker_isPrime φ; nilradical_le_prime (RingHom.ker φ)) let ι := algebraMap R R' rw [show φ = ψ.comp ι from rfl, ← map_map] at hi replace hi := hm.map ι |>.irreducible_of_irreducible_map _ _ hi refine ⟨fun h ↦ hi.1 <| (mapRingHom ι).isUnit_map h, fun a b h ↦ ?_⟩ wlog hb : IsUnit (b.map ι) generalizing a b · exact (this b a (mul_comm a b ▸ h) (hi.2 _ _ (by rw [h, Polynomial.map_mul]) |>.resolve_right hb)).symm have hn (i : ℕ) (hi : i ≠ 0) : IsNilpotent (b.coeff i) := by obtain ⟨_, _, h⟩ := Polynomial.isUnit_iff.1 hb simpa only [coeff_map, coeff_C, hi, ite_false, ← RingHom.mem_ker, show RingHom.ker ι = nilradical R from Ideal.mk_ker] using congr(coeff $(h.symm) i) refine .inr <| isUnit_of_coeff_isUnit_isNilpotent (isUnit_of_mul_isUnit_right (x := a.coeff f.natDegree) <| (IsUnit.neg_iff _).1 ?_) hn have hc : f.leadingCoeff = _ := congr(coeff $h f.natDegree) rw [hm, coeff_mul, Finset.Nat.sum_antidiagonal_eq_sum_range_succ fun i j ↦ a.coeff i * b.coeff j, Finset.sum_range_succ, ← sub_eq_iff_eq_add, Nat.sub_self] at hc rw [← add_sub_cancel_left 1 (-(_ * _)), ← sub_eq_add_neg, hc] exact IsNilpotent.isUnit_sub_one <| show _ ∈ nilradical R from sum_mem fun i hi ↦ Ideal.mul_mem_left _ _ <| hn _ <| Nat.sub_ne_zero_of_lt (List.mem_range.1 hi)
RingTheory\Polynomial\Nilpotent.lean
/- Copyright (c) 2023 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Emilie Uthaiwat, Oliver Nash -/ import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.Div import Mathlib.Algebra.Polynomial.Identities import Mathlib.RingTheory.Ideal.QuotientOperations import Mathlib.RingTheory.Nilpotent.Lemmas import Mathlib.RingTheory.Polynomial.Tower import Mathlib.RingTheory.Nilpotent.Basic /-! # Nilpotency in polynomial rings. This file is a place for results related to nilpotency in (single-variable) polynomial rings. ## Main results: * `Polynomial.isNilpotent_iff` * `Polynomial.isUnit_iff_coeff_isUnit_isNilpotent` -/ namespace Polynomial variable {R : Type*} {r : R} section Semiring variable [Semiring R] {P : R[X]} lemma isNilpotent_C_mul_pow_X_of_isNilpotent (n : ℕ) (hnil : IsNilpotent r) : IsNilpotent ((C r) * X ^ n) := by refine Commute.isNilpotent_mul_left (commute_X_pow _ _).symm ?_ obtain ⟨m, hm⟩ := hnil refine ⟨m, ?_⟩ rw [← C_pow, hm, C_0] lemma isNilpotent_pow_X_mul_C_of_isNilpotent (n : ℕ) (hnil : IsNilpotent r) : IsNilpotent (X ^ n * (C r)) := by rw [commute_X_pow] exact isNilpotent_C_mul_pow_X_of_isNilpotent n hnil @[simp] lemma isNilpotent_monomial_iff {n : ℕ} : IsNilpotent (monomial (R := R) n r) ↔ IsNilpotent r := exists_congr fun k ↦ by simp @[simp] lemma isNilpotent_C_iff : IsNilpotent (C r) ↔ IsNilpotent r := exists_congr fun k ↦ by simpa only [← C_pow] using C_eq_zero @[simp] lemma isNilpotent_X_mul_iff : IsNilpotent (X * P) ↔ IsNilpotent P := by refine ⟨fun h ↦ ?_, ?_⟩ · rwa [Commute.isNilpotent_mul_right_iff (commute_X P) (by simp)] at h · rintro ⟨k, hk⟩ exact ⟨k, by simp [(commute_X P).mul_pow, hk]⟩ @[simp] lemma isNilpotent_mul_X_iff : IsNilpotent (P * X) ↔ IsNilpotent P := by rw [← commute_X P] exact isNilpotent_X_mul_iff end Semiring section CommRing variable [CommRing R] {P : R[X]} protected lemma isNilpotent_iff : IsNilpotent P ↔ ∀ i, IsNilpotent (coeff P i) := by refine ⟨P.recOnHorner (by simp) (fun p r hp₀ _ hp hpr i ↦ ?_) (fun p _ hnp hpX i ↦ ?_), fun h ↦ ?_⟩ · rw [← sum_monomial_eq P] exact isNilpotent_sum (fun i _ ↦ by simpa only [isNilpotent_monomial_iff] using h i) · have hr : IsNilpotent (C r) := by obtain ⟨k, hk⟩ := hpr replace hp : eval 0 p = 0 := by rwa [coeff_zero_eq_aeval_zero] at hp₀ refine isNilpotent_C_iff.mpr ⟨k, ?_⟩ simpa [coeff_zero_eq_aeval_zero, hp] using congr_arg (fun q ↦ coeff q 0) hk cases' i with i · simpa [hp₀] using hr simp only [coeff_add, coeff_C_succ, add_zero] apply hp simpa using Commute.isNilpotent_sub (Commute.all _ _) hpr hr · cases' i with i · simp simpa using hnp (isNilpotent_mul_X_iff.mp hpX) i @[simp] lemma isNilpotent_reflect_iff {P : R[X]} {N : ℕ} (hN : P.natDegree ≤ N) : IsNilpotent (reflect N P) ↔ IsNilpotent P := by simp only [Polynomial.isNilpotent_iff, coeff_reverse] refine ⟨fun h i ↦ ?_, fun h i ↦ ?_⟩ <;> rcases le_or_lt i N with hi | hi · simpa [tsub_tsub_cancel_of_le hi] using h (N - i) · simp [coeff_eq_zero_of_natDegree_lt <| lt_of_le_of_lt hN hi] · simpa [hi, revAt_le] using h (N - i) · simpa [revAt_eq_self_of_lt hi] using h i @[simp] lemma isNilpotent_reverse_iff : IsNilpotent P.reverse ↔ IsNilpotent P := isNilpotent_reflect_iff (le_refl _) /-- Let `P` be a polynomial over `R`. If its constant term is a unit and its other coefficients are nilpotent, then `P` is a unit. See also `Polynomial.isUnit_iff_coeff_isUnit_isNilpotent`. -/ theorem isUnit_of_coeff_isUnit_isNilpotent (hunit : IsUnit (P.coeff 0)) (hnil : ∀ i, i ≠ 0 → IsNilpotent (P.coeff i)) : IsUnit P := by induction' h : P.natDegree using Nat.strong_induction_on with k hind generalizing P by_cases hdeg : P.natDegree = 0 { rw [eq_C_of_natDegree_eq_zero hdeg] exact hunit.map C } set P₁ := P.eraseLead with hP₁ suffices IsUnit P₁ by rw [← eraseLead_add_monomial_natDegree_leadingCoeff P, ← C_mul_X_pow_eq_monomial, ← hP₁] refine IsNilpotent.isUnit_add_left_of_commute ?_ this (Commute.all _ _) exact isNilpotent_C_mul_pow_X_of_isNilpotent _ (hnil _ hdeg) have hdeg₂ := lt_of_le_of_lt P.eraseLead_natDegree_le (Nat.sub_lt (Nat.pos_of_ne_zero hdeg) zero_lt_one) refine hind P₁.natDegree ?_ ?_ (fun i hi => ?_) rfl · simp_rw [← h, hdeg₂] · simp_rw [eraseLead_coeff_of_ne _ (Ne.symm hdeg), hunit] · by_cases H : i ≤ P₁.natDegree · simp_rw [eraseLead_coeff_of_ne _ (ne_of_lt (lt_of_le_of_lt H hdeg₂)), hnil i hi] · simp_rw [coeff_eq_zero_of_natDegree_lt (lt_of_not_ge H), IsNilpotent.zero] /-- Let `P` be a polynomial over `R`. If `P` is a unit, then all its coefficients are nilpotent, except its constant term which is a unit. See also `Polynomial.isUnit_iff_coeff_isUnit_isNilpotent`. -/ theorem coeff_isUnit_isNilpotent_of_isUnit (hunit : IsUnit P) : IsUnit (P.coeff 0) ∧ (∀ i, i ≠ 0 → IsNilpotent (P.coeff i)) := by obtain ⟨Q, hQ⟩ := IsUnit.exists_right_inv hunit constructor · refine isUnit_of_mul_eq_one _ (Q.coeff 0) ?_ have h := (mul_coeff_zero P Q).symm rwa [hQ, coeff_one_zero] at h · intros n hn rw [nilpotent_iff_mem_prime] intros I hI let f := mapRingHom (Ideal.Quotient.mk I) have hPQ : degree (f P) = 0 ∧ degree (f Q) = 0 := by rw [← Nat.WithBot.add_eq_zero_iff, ← degree_mul, ← _root_.map_mul, hQ, map_one, degree_one] have hcoeff : (f P).coeff n = 0 := by refine coeff_eq_zero_of_degree_lt ?_ rw [hPQ.1] exact WithBot.coe_pos.2 hn.bot_lt rw [coe_mapRingHom, coeff_map, ← RingHom.mem_ker, Ideal.mk_ker] at hcoeff exact hcoeff /-- Let `P` be a polynomial over `R`. `P` is a unit if and only if all its coefficients are nilpotent, except its constant term which is a unit. See also `Polynomial.isUnit_iff'`. -/ theorem isUnit_iff_coeff_isUnit_isNilpotent : IsUnit P ↔ IsUnit (P.coeff 0) ∧ (∀ i, i ≠ 0 → IsNilpotent (P.coeff i)) := ⟨coeff_isUnit_isNilpotent_of_isUnit, fun H => isUnit_of_coeff_isUnit_isNilpotent H.1 H.2⟩ @[simp] lemma isUnit_C_add_X_mul_iff : IsUnit (C r + X * P) ↔ IsUnit r ∧ IsNilpotent P := by have : ∀ i, coeff (C r + X * P) (i + 1) = coeff P i := by simp simp_rw [isUnit_iff_coeff_isUnit_isNilpotent, Nat.forall_ne_zero_iff, this] simp only [coeff_add, coeff_C_zero, mul_coeff_zero, coeff_X_zero, zero_mul, add_zero, and_congr_right_iff, ← Polynomial.isNilpotent_iff] lemma isUnit_iff' : IsUnit P ↔ IsUnit (eval 0 P) ∧ IsNilpotent (P /ₘ X) := by suffices P = C (eval 0 P) + X * (P /ₘ X) by conv_lhs => rw [this]; simp conv_lhs => rw [← modByMonic_add_div P monic_X] simp [modByMonic_X] theorem not_isUnit_of_natDegree_pos_of_isReduced [IsReduced R] (p : R[X]) (hpl : 0 < p.natDegree) : ¬ IsUnit p := by simp only [ne_eq, isNilpotent_iff_eq_zero, not_and, not_forall, exists_prop, Polynomial.isUnit_iff_coeff_isUnit_isNilpotent] intro _ refine ⟨p.natDegree, hpl.ne', ?_⟩ contrapose! hpl simp only [coeff_natDegree, leadingCoeff_eq_zero] at hpl simp [hpl] theorem not_isUnit_of_degree_pos_of_isReduced [IsReduced R] (p : R[X]) (hpl : 0 < p.degree) : ¬ IsUnit p := not_isUnit_of_natDegree_pos_of_isReduced _ (natDegree_pos_iff_degree_pos.mpr hpl) end CommRing section CommAlgebra variable {R S : Type*} [CommRing R] [CommRing S] [Algebra R S] (P : R[X]) {a b : S} lemma isNilpotent_aeval_sub_of_isNilpotent_sub (h : IsNilpotent (a - b)) : IsNilpotent (aeval a P - aeval b P) := by simp only [← eval_map_algebraMap] have ⟨c, hc⟩ := evalSubFactor (map (algebraMap R S) P) a b exact hc ▸ (Commute.all _ _).isNilpotent_mul_right h variable {P} lemma isUnit_aeval_of_isUnit_aeval_of_isNilpotent_sub (hb : IsUnit (aeval b P)) (hab : IsNilpotent (a - b)) : IsUnit (aeval a P) := by rw [← add_sub_cancel (aeval b P) (aeval a P)] refine IsNilpotent.isUnit_add_left_of_commute ?_ hb (Commute.all _ _) exact isNilpotent_aeval_sub_of_isNilpotent_sub P hab end CommAlgebra end Polynomial
RingTheory\Polynomial\Opposites.lean
/- Copyright (c) 2022 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Mathlib.Algebra.Polynomial.Degree.Definitions /-! # Interactions between `R[X]` and `Rᵐᵒᵖ[X]` This file contains the basic API for "pushing through" the isomorphism `opRingEquiv : R[X]ᵐᵒᵖ ≃+* Rᵐᵒᵖ[X]`. It allows going back and forth between a polynomial ring over a semiring and the polynomial ring over the opposite semiring. -/ open Polynomial open Polynomial MulOpposite variable {R : Type*} [Semiring R] noncomputable section namespace Polynomial /-- Ring isomorphism between `R[X]ᵐᵒᵖ` and `Rᵐᵒᵖ[X]` sending each coefficient of a polynomial to the corresponding element of the opposite ring. -/ def opRingEquiv (R : Type*) [Semiring R] : R[X]ᵐᵒᵖ ≃+* Rᵐᵒᵖ[X] := ((toFinsuppIso R).op.trans AddMonoidAlgebra.opRingEquiv).trans (toFinsuppIso _).symm /-! Lemmas to get started, using `opRingEquiv R` on the various expressions of `Finsupp.single`: `monomial`, `C a`, `X`, `C a * X ^ n`. -/ @[simp] theorem opRingEquiv_op_monomial (n : ℕ) (r : R) : opRingEquiv R (op (monomial n r : R[X])) = monomial n (op r) := by simp only [opRingEquiv, RingEquiv.coe_trans, Function.comp_apply, AddMonoidAlgebra.opRingEquiv_apply, RingEquiv.op_apply_apply, toFinsuppIso_apply, unop_op, toFinsupp_monomial, Finsupp.mapRange_single, toFinsuppIso_symm_apply, ofFinsupp_single] @[simp] theorem opRingEquiv_op_C (a : R) : opRingEquiv R (op (C a)) = C (op a) := opRingEquiv_op_monomial 0 a @[simp] theorem opRingEquiv_op_X : opRingEquiv R (op (X : R[X])) = X := opRingEquiv_op_monomial 1 1 theorem opRingEquiv_op_C_mul_X_pow (r : R) (n : ℕ) : opRingEquiv R (op (C r * X ^ n : R[X])) = C (op r) * X ^ n := by simp only [X_pow_mul, op_mul, op_pow, map_mul, map_pow, opRingEquiv_op_X, opRingEquiv_op_C] /-! Lemmas to get started, using `(opRingEquiv R).symm` on the various expressions of `Finsupp.single`: `monomial`, `C a`, `X`, `C a * X ^ n`. -/ @[simp] theorem opRingEquiv_symm_monomial (n : ℕ) (r : Rᵐᵒᵖ) : (opRingEquiv R).symm (monomial n r) = op (monomial n (unop r)) := (opRingEquiv R).injective (by simp) @[simp] theorem opRingEquiv_symm_C (a : Rᵐᵒᵖ) : (opRingEquiv R).symm (C a) = op (C (unop a)) := opRingEquiv_symm_monomial 0 a @[simp] theorem opRingEquiv_symm_X : (opRingEquiv R).symm (X : Rᵐᵒᵖ[X]) = op X := opRingEquiv_symm_monomial 1 1 theorem opRingEquiv_symm_C_mul_X_pow (r : Rᵐᵒᵖ) (n : ℕ) : (opRingEquiv R).symm (C r * X ^ n : Rᵐᵒᵖ[X]) = op (C (unop r) * X ^ n) := by rw [C_mul_X_pow_eq_monomial, opRingEquiv_symm_monomial, C_mul_X_pow_eq_monomial] /-! Lemmas about more global properties of polynomials and opposites. -/ @[simp] theorem coeff_opRingEquiv (p : R[X]ᵐᵒᵖ) (n : ℕ) : (opRingEquiv R p).coeff n = op ((unop p).coeff n) := by induction' p with p cases p rfl @[simp] theorem support_opRingEquiv (p : R[X]ᵐᵒᵖ) : (opRingEquiv R p).support = (unop p).support := by induction' p with p cases p exact Finsupp.support_mapRange_of_injective (map_zero _) _ op_injective @[simp] theorem natDegree_opRingEquiv (p : R[X]ᵐᵒᵖ) : (opRingEquiv R p).natDegree = (unop p).natDegree := by by_cases p0 : p = 0 · simp only [p0, _root_.map_zero, natDegree_zero, unop_zero] · simp only [p0, natDegree_eq_support_max', Ne, AddEquivClass.map_eq_zero_iff, not_false_iff, support_opRingEquiv, unop_eq_zero_iff] @[simp] theorem leadingCoeff_opRingEquiv (p : R[X]ᵐᵒᵖ) : (opRingEquiv R p).leadingCoeff = op (unop p).leadingCoeff := by rw [leadingCoeff, coeff_opRingEquiv, natDegree_opRingEquiv, leadingCoeff] end Polynomial
RingTheory\Polynomial\Pochhammer.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Polynomial.Degree.Definitions import Mathlib.Algebra.Polynomial.Eval import Mathlib.Algebra.Polynomial.Monic import Mathlib.Algebra.Polynomial.RingDivision import Mathlib.Tactic.Abel /-! # The Pochhammer polynomials We define and prove some basic relations about `ascPochhammer S n : S[X] := X * (X + 1) * ... * (X + n - 1)` which is also known as the rising factorial and about `descPochhammer R n : R[X] := X * (X - 1) * ... * (X - n + 1)` which is also known as the falling factorial. Versions of this definition that are focused on `Nat` can be found in `Data.Nat.Factorial` as `Nat.ascFactorial` and `Nat.descFactorial`. ## Implementation As with many other families of polynomials, even though the coefficients are always in `ℕ` or `ℤ` , we define the polynomial with coefficients in any `[Semiring S]` or `[Ring R]`. ## TODO There is lots more in this direction: * q-factorials, q-binomials, q-Pochhammer. -/ universe u v open Polynomial open Polynomial section Semiring variable (S : Type u) [Semiring S] /-- `ascPochhammer S n` is the polynomial `X * (X + 1) * ... * (X + n - 1)`, with coefficients in the semiring `S`. -/ noncomputable def ascPochhammer : ℕ → S[X] | 0 => 1 | n + 1 => X * (ascPochhammer n).comp (X + 1) @[simp] theorem ascPochhammer_zero : ascPochhammer S 0 = 1 := rfl @[simp] theorem ascPochhammer_one : ascPochhammer S 1 = X := by simp [ascPochhammer] theorem ascPochhammer_succ_left (n : ℕ) : ascPochhammer S (n + 1) = X * (ascPochhammer S n).comp (X + 1) := by rw [ascPochhammer] theorem monic_ascPochhammer (n : ℕ) [Nontrivial S] [NoZeroDivisors S] : Monic <| ascPochhammer S n := by induction' n with n hn · simp · have : leadingCoeff (X + 1 : S[X]) = 1 := leadingCoeff_X_add_C 1 rw [ascPochhammer_succ_left, Monic.def, leadingCoeff_mul, leadingCoeff_comp (ne_zero_of_eq_one <| natDegree_X_add_C 1 : natDegree (X + 1) ≠ 0), hn, monic_X, one_mul, one_mul, this, one_pow] section variable {S} {T : Type v} [Semiring T] @[simp] theorem ascPochhammer_map (f : S →+* T) (n : ℕ) : (ascPochhammer S n).map f = ascPochhammer T n := by induction' n with n ih · simp · simp [ih, ascPochhammer_succ_left, map_comp] theorem ascPochhammer_eval₂ (f : S →+* T) (n : ℕ) (t : T) : (ascPochhammer T n).eval t = (ascPochhammer S n).eval₂ f t := by rw [← ascPochhammer_map f] exact eval_map f t theorem ascPochhammer_eval_comp {R : Type*} [CommSemiring R] (n : ℕ) (p : R[X]) [Algebra R S] (x : S) : ((ascPochhammer S n).comp (p.map (algebraMap R S))).eval x = (ascPochhammer S n).eval (p.eval₂ (algebraMap R S) x) := by rw [ascPochhammer_eval₂ (algebraMap R S), ← eval₂_comp', ← ascPochhammer_map (algebraMap R S), ← map_comp, eval_map] end @[simp, norm_cast] theorem ascPochhammer_eval_cast (n k : ℕ) : (((ascPochhammer ℕ n).eval k : ℕ) : S) = ((ascPochhammer S n).eval k : S) := by rw [← ascPochhammer_map (algebraMap ℕ S), eval_map, ← eq_natCast (algebraMap ℕ S), eval₂_at_natCast,Nat.cast_id] theorem ascPochhammer_eval_zero {n : ℕ} : (ascPochhammer S n).eval 0 = if n = 0 then 1 else 0 := by cases n · simp · simp [X_mul, Nat.succ_ne_zero, ascPochhammer_succ_left] theorem ascPochhammer_zero_eval_zero : (ascPochhammer S 0).eval 0 = 1 := by simp @[simp] theorem ascPochhammer_ne_zero_eval_zero {n : ℕ} (h : n ≠ 0) : (ascPochhammer S n).eval 0 = 0 := by simp [ascPochhammer_eval_zero, h] theorem ascPochhammer_succ_right (n : ℕ) : ascPochhammer S (n + 1) = ascPochhammer S n * (X + (n : S[X])) := by suffices h : ascPochhammer ℕ (n + 1) = ascPochhammer ℕ n * (X + (n : ℕ[X])) by apply_fun Polynomial.map (algebraMap ℕ S) at h simpa only [ascPochhammer_map, Polynomial.map_mul, Polynomial.map_add, map_X, Polynomial.map_natCast] using h induction' n with n ih · simp · conv_lhs => rw [ascPochhammer_succ_left, ih, mul_comp, ← mul_assoc, ← ascPochhammer_succ_left, add_comp, X_comp, natCast_comp, add_assoc, add_comm (1 : ℕ[X]), ← Nat.cast_succ] theorem ascPochhammer_succ_eval {S : Type*} [Semiring S] (n : ℕ) (k : S) : (ascPochhammer S (n + 1)).eval k = (ascPochhammer S n).eval k * (k + n) := by rw [ascPochhammer_succ_right, mul_add, eval_add, eval_mul_X, ← Nat.cast_comm, ← C_eq_natCast, eval_C_mul, Nat.cast_comm, ← mul_add] theorem ascPochhammer_succ_comp_X_add_one (n : ℕ) : (ascPochhammer S (n + 1)).comp (X + 1) = ascPochhammer S (n + 1) + (n + 1) • (ascPochhammer S n).comp (X + 1) := by suffices (ascPochhammer ℕ (n + 1)).comp (X + 1) = ascPochhammer ℕ (n + 1) + (n + 1) * (ascPochhammer ℕ n).comp (X + 1) by simpa [map_comp] using congr_arg (Polynomial.map (Nat.castRingHom S)) this nth_rw 2 [ascPochhammer_succ_left] rw [← add_mul, ascPochhammer_succ_right ℕ n, mul_comp, mul_comm, add_comp, X_comp, natCast_comp, add_comm, ← add_assoc] ring theorem ascPochhammer_mul (n m : ℕ) : ascPochhammer S n * (ascPochhammer S m).comp (X + (n : S[X])) = ascPochhammer S (n + m) := by induction' m with m ih · simp · rw [ascPochhammer_succ_right, Polynomial.mul_X_add_natCast_comp, ← mul_assoc, ih, ← add_assoc, ascPochhammer_succ_right, Nat.cast_add, add_assoc] theorem ascPochhammer_nat_eq_ascFactorial (n : ℕ) : ∀ k, (ascPochhammer ℕ k).eval n = n.ascFactorial k | 0 => by rw [ascPochhammer_zero, eval_one, Nat.ascFactorial_zero] | t + 1 => by rw [ascPochhammer_succ_right, eval_mul, ascPochhammer_nat_eq_ascFactorial n t, eval_add, eval_X, eval_natCast, Nat.cast_id, Nat.ascFactorial_succ, mul_comm] theorem ascPochhammer_nat_eq_descFactorial (a b : ℕ) : (ascPochhammer ℕ b).eval a = (a + b - 1).descFactorial b := by rw [ascPochhammer_nat_eq_ascFactorial, Nat.add_descFactorial_eq_ascFactorial'] @[simp] theorem ascPochhammer_natDegree (n : ℕ) [NoZeroDivisors S] [Nontrivial S] : (ascPochhammer S n).natDegree = n := by induction' n with n hn · simp · have : natDegree (X + (n : S[X])) = 1 := natDegree_X_add_C (n : S) rw [ascPochhammer_succ_right, natDegree_mul _ (ne_zero_of_natDegree_gt <| this.symm ▸ Nat.zero_lt_one), hn, this] cases n · simp · refine ne_zero_of_natDegree_gt <| hn.symm ▸ Nat.add_one_pos _ end Semiring section StrictOrderedSemiring variable {S : Type*} [StrictOrderedSemiring S] theorem ascPochhammer_pos (n : ℕ) (s : S) (h : 0 < s) : 0 < (ascPochhammer S n).eval s := by induction' n with n ih · simp only [Nat.zero_eq, ascPochhammer_zero, eval_one] exact zero_lt_one · rw [ascPochhammer_succ_right, mul_add, eval_add, ← Nat.cast_comm, eval_natCast_mul, eval_mul_X, Nat.cast_comm, ← mul_add] exact mul_pos ih (lt_of_lt_of_le h (le_add_of_nonneg_right (Nat.cast_nonneg n))) end StrictOrderedSemiring section Factorial open Nat variable (S : Type*) [Semiring S] (r n : ℕ) @[simp] theorem ascPochhammer_eval_one (S : Type*) [Semiring S] (n : ℕ) : (ascPochhammer S n).eval (1 : S) = (n ! : S) := by rw_mod_cast [ascPochhammer_nat_eq_ascFactorial, Nat.one_ascFactorial] theorem factorial_mul_ascPochhammer (S : Type*) [Semiring S] (r n : ℕ) : (r ! : S) * (ascPochhammer S n).eval (r + 1 : S) = (r + n)! := by rw_mod_cast [ascPochhammer_nat_eq_ascFactorial, Nat.factorial_mul_ascFactorial] theorem ascPochhammer_nat_eval_succ (r : ℕ) : ∀ n : ℕ, n * (ascPochhammer ℕ r).eval (n + 1) = (n + r) * (ascPochhammer ℕ r).eval n | 0 => by by_cases h : r = 0 · simp only [h, zero_mul, zero_add] · simp only [ascPochhammer_eval_zero, zero_mul, if_neg h, mul_zero] | k + 1 => by simp only [ascPochhammer_nat_eq_ascFactorial, Nat.succ_ascFactorial, add_right_comm] theorem ascPochhammer_eval_succ (r n : ℕ) : (n : S) * (ascPochhammer S r).eval (n + 1 : S) = (n + r) * (ascPochhammer S r).eval (n : S) := mod_cast congr_arg Nat.cast (ascPochhammer_nat_eval_succ r n) end Factorial section Ring variable (R : Type u) [Ring R] /-- `descPochhammer R n` is the polynomial `X * (X - 1) * ... * (X - n + 1)`, with coefficients in the ring `R`. -/ noncomputable def descPochhammer : ℕ → R[X] | 0 => 1 | n + 1 => X * (descPochhammer n).comp (X - 1) @[simp] theorem descPochhammer_zero : descPochhammer R 0 = 1 := rfl @[simp] theorem descPochhammer_one : descPochhammer R 1 = X := by simp [descPochhammer] theorem descPochhammer_succ_left (n : ℕ) : descPochhammer R (n + 1) = X * (descPochhammer R n).comp (X - 1) := by rw [descPochhammer] theorem monic_descPochhammer (n : ℕ) [Nontrivial R] [NoZeroDivisors R] : Monic <| descPochhammer R n := by induction' n with n hn · simp · have h : leadingCoeff (X - 1 : R[X]) = 1 := leadingCoeff_X_sub_C 1 have : natDegree (X - (1 : R[X])) ≠ 0 := ne_zero_of_eq_one <| natDegree_X_sub_C (1 : R) rw [descPochhammer_succ_left, Monic.def, leadingCoeff_mul, leadingCoeff_comp this, hn, monic_X, one_mul, one_mul, h, one_pow] section variable {R} {T : Type v} [Ring T] @[simp] theorem descPochhammer_map (f : R →+* T) (n : ℕ) : (descPochhammer R n).map f = descPochhammer T n := by induction' n with n ih · simp · simp [ih, descPochhammer_succ_left, map_comp] end @[simp, norm_cast] theorem descPochhammer_eval_cast (n : ℕ) (k : ℤ) : (((descPochhammer ℤ n).eval k : ℤ) : R) = ((descPochhammer R n).eval k : R) := by rw [← descPochhammer_map (algebraMap ℤ R), eval_map, ← eq_intCast (algebraMap ℤ R)] simp only [algebraMap_int_eq, eq_intCast, eval₂_at_intCast, Nat.cast_id, eq_natCast, Int.cast_id] theorem descPochhammer_eval_zero {n : ℕ} : (descPochhammer R n).eval 0 = if n = 0 then 1 else 0 := by cases n · simp · simp [X_mul, Nat.succ_ne_zero, descPochhammer_succ_left] theorem descPochhammer_zero_eval_zero : (descPochhammer R 0).eval 0 = 1 := by simp @[simp] theorem descPochhammer_ne_zero_eval_zero {n : ℕ} (h : n ≠ 0) : (descPochhammer R n).eval 0 = 0 := by simp [descPochhammer_eval_zero, h] theorem descPochhammer_succ_right (n : ℕ) : descPochhammer R (n + 1) = descPochhammer R n * (X - (n : R[X])) := by suffices h : descPochhammer ℤ (n + 1) = descPochhammer ℤ n * (X - (n : ℤ[X])) by apply_fun Polynomial.map (algebraMap ℤ R) at h simpa [descPochhammer_map, Polynomial.map_mul, Polynomial.map_add, map_X, Polynomial.map_intCast] using h induction' n with n ih · simp [descPochhammer] · conv_lhs => rw [descPochhammer_succ_left, ih, mul_comp, ← mul_assoc, ← descPochhammer_succ_left, sub_comp, X_comp, natCast_comp] rw [Nat.cast_add, Nat.cast_one, sub_add_eq_sub_sub_swap] @[simp] theorem descPochhammer_natDegree (n : ℕ) [NoZeroDivisors R] [Nontrivial R] : (descPochhammer R n).natDegree = n := by induction' n with n hn · simp · have : natDegree (X - (n : R[X])) = 1 := natDegree_X_sub_C (n : R) rw [descPochhammer_succ_right, natDegree_mul _ (ne_zero_of_natDegree_gt <| this.symm ▸ Nat.zero_lt_one), hn, this] cases n · simp · refine ne_zero_of_natDegree_gt <| hn.symm ▸ Nat.add_one_pos _ theorem descPochhammer_succ_eval {S : Type*} [Ring S] (n : ℕ) (k : S) : (descPochhammer S (n + 1)).eval k = (descPochhammer S n).eval k * (k - n) := by rw [descPochhammer_succ_right, mul_sub, eval_sub, eval_mul_X, ← Nat.cast_comm, ← C_eq_natCast, eval_C_mul, Nat.cast_comm, ← mul_sub] theorem descPochhammer_succ_comp_X_sub_one (n : ℕ) : (descPochhammer R (n + 1)).comp (X - 1) = descPochhammer R (n + 1) - (n + (1 : R[X])) • (descPochhammer R n).comp (X - 1) := by suffices (descPochhammer ℤ (n + 1)).comp (X - 1) = descPochhammer ℤ (n + 1) - (n + 1) * (descPochhammer ℤ n).comp (X - 1) by simpa [map_comp] using congr_arg (Polynomial.map (Int.castRingHom R)) this nth_rw 2 [descPochhammer_succ_left] rw [← sub_mul, descPochhammer_succ_right ℤ n, mul_comp, mul_comm, sub_comp, X_comp, natCast_comp] ring theorem descPochhammer_eq_ascPochhammer (n : ℕ) : descPochhammer ℤ n = (ascPochhammer ℤ n).comp ((X : ℤ[X]) - n + 1) := by induction n with | zero => rw [descPochhammer_zero, ascPochhammer_zero, one_comp] | succ n ih => rw [Nat.cast_succ, sub_add, add_sub_cancel_right, descPochhammer_succ_right, ascPochhammer_succ_left, ih, X_mul, mul_X_comp, comp_assoc, add_comp, X_comp, one_comp] theorem descPochhammer_eval_eq_ascPochhammer (r : R) (n : ℕ) : (descPochhammer R n).eval r = (ascPochhammer R n).eval (r - n + 1) := by induction n with | zero => rw [descPochhammer_zero, eval_one, ascPochhammer_zero, eval_one] | succ n ih => rw [Nat.cast_succ, sub_add, add_sub_cancel_right, descPochhammer_succ_eval, ih, ascPochhammer_succ_left, X_mul, eval_mul_X, show (X + 1 : R[X]) = (X + 1 : ℕ[X]).map (algebraMap ℕ R) by simp only [Polynomial.map_add, map_X, Polynomial.map_one], ascPochhammer_eval_comp, eval₂_add, eval₂_X, eval₂_one] theorem descPochhammer_mul (n m : ℕ) : descPochhammer R n * (descPochhammer R m).comp (X - (n : R[X])) = descPochhammer R (n + m) := by induction' m with m ih · simp · rw [descPochhammer_succ_right, Polynomial.mul_X_sub_intCast_comp, ← mul_assoc, ih, ← add_assoc, descPochhammer_succ_right, Nat.cast_add, sub_add_eq_sub_sub] theorem ascPochhammer_eval_neg_eq_descPochhammer (r : R) : ∀ (k : ℕ), (ascPochhammer R k).eval (-r) = (-1)^k * (descPochhammer R k).eval r | 0 => by rw [ascPochhammer_zero, descPochhammer_zero] simp only [eval_one, pow_zero, mul_one] | (k+1) => by rw [ascPochhammer_succ_right, mul_add, eval_add, eval_mul_X, ← Nat.cast_comm, eval_natCast_mul, Nat.cast_comm, ← mul_add, ascPochhammer_eval_neg_eq_descPochhammer r k, mul_assoc, descPochhammer_succ_right, mul_sub, eval_sub, eval_mul_X, ← Nat.cast_comm, eval_natCast_mul, pow_add, pow_one, mul_assoc ((-1)^k) (-1), mul_sub, neg_one_mul, neg_mul_eq_mul_neg, Nat.cast_comm, sub_eq_add_neg, neg_one_mul, neg_neg, ← mul_add] theorem descPochhammer_eval_eq_descFactorial (n k : ℕ) : (descPochhammer R k).eval (n : R) = n.descFactorial k := by induction k with | zero => rw [descPochhammer_zero, eval_one, Nat.descFactorial_zero, Nat.cast_one] | succ k ih => rw [descPochhammer_succ_right, Nat.descFactorial_succ, mul_sub, eval_sub, eval_mul_X, ← Nat.cast_comm k, eval_natCast_mul, ← Nat.cast_comm n, ← sub_mul, ih] by_cases h : n < k · rw [Nat.descFactorial_eq_zero_iff_lt.mpr h, Nat.cast_zero, mul_zero, mul_zero, Nat.cast_zero] · rw [Nat.cast_mul, Nat.cast_sub <| not_lt.mp h] theorem descPochhammer_int_eq_ascFactorial (a b : ℕ) : (descPochhammer ℤ b).eval (a + b : ℤ) = (a + 1).ascFactorial b := by rw [← Nat.cast_add, descPochhammer_eval_eq_descFactorial ℤ (a + b) b, Nat.add_descFactorial_eq_ascFactorial] end Ring
RingTheory\Polynomial\Quotient.lean
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, David Kurniadi Angdinata, Devon Tuma, Riccardo Brasca -/ import Mathlib.Algebra.Polynomial.Div import Mathlib.RingTheory.Polynomial.Basic import Mathlib.RingTheory.Ideal.QuotientOperations /-! # Quotients of polynomial rings -/ open Polynomial namespace Polynomial variable {R : Type*} [CommRing R] noncomputable def quotientSpanXSubCAlgEquivAux2 (x : R) : (R[X] ⧸ (RingHom.ker (aeval x).toRingHom : Ideal R[X])) ≃ₐ[R] R := let e := RingHom.quotientKerEquivOfRightInverse (fun x => by exact eval_C : Function.RightInverse (fun a : R => (C a : R[X])) (@aeval R R _ _ _ x)) { e with commutes' := fun r => e.apply_symm_apply r } noncomputable def quotientSpanXSubCAlgEquivAux1 (x : R) : (R[X] ⧸ Ideal.span {X - C x}) ≃ₐ[R] (R[X] ⧸ (RingHom.ker (aeval x).toRingHom : Ideal R[X])) := @Ideal.quotientEquivAlgOfEq R R[X] _ _ _ _ _ (ker_evalRingHom x).symm -- Porting note: need to split this definition into two sub-definitions to prevent time out /-- For a commutative ring $R$, evaluating a polynomial at an element $x \in R$ induces an isomorphism of $R$-algebras $R[X] / \langle X - x \rangle \cong R$. -/ noncomputable def quotientSpanXSubCAlgEquiv (x : R) : (R[X] ⧸ Ideal.span ({X - C x} : Set R[X])) ≃ₐ[R] R := (quotientSpanXSubCAlgEquivAux1 x).trans (quotientSpanXSubCAlgEquivAux2 x) @[simp] theorem quotientSpanXSubCAlgEquiv_mk (x : R) (p : R[X]) : quotientSpanXSubCAlgEquiv x (Ideal.Quotient.mk _ p) = p.eval x := rfl @[simp] theorem quotientSpanXSubCAlgEquiv_symm_apply (x : R) (y : R) : (quotientSpanXSubCAlgEquiv x).symm y = algebraMap R _ y := rfl /-- For a commutative ring $R$, evaluating a polynomial at an element $y \in R$ induces an isomorphism of $R$-algebras $R[X] / \langle x, X - y \rangle \cong R / \langle x \rangle$. -/ noncomputable def quotientSpanCXSubCAlgEquiv (x y : R) : (R[X] ⧸ (Ideal.span {C x, X - C y} : Ideal R[X])) ≃ₐ[R] R ⧸ (Ideal.span {x} : Ideal R) := (Ideal.quotientEquivAlgOfEq R <| by rw [Ideal.span_insert, sup_comm]).trans <| (DoubleQuot.quotQuotEquivQuotSupₐ R _ _).symm.trans <| (Ideal.quotientEquivAlg _ _ (quotientSpanXSubCAlgEquiv y) rfl).trans <| Ideal.quotientEquivAlgOfEq R <| by simp only [Ideal.map_span, Set.image_singleton]; congr 2; exact eval_C /-- For a commutative ring $R$, evaluating a polynomial at elements $y(X) \in R[X]$ and $x \in R$ induces an isomorphism of $R$-algebras $R[X, Y] / \langle X - x, Y - y(X) \rangle \cong R$. -/ noncomputable def quotientSpanCXSubCXSubCAlgEquiv {x : R} {y : R[X]} : @AlgEquiv R (R[X][X] ⧸ (Ideal.span {C (X - C x), X - C y} : Ideal <| R[X][X])) R _ _ _ (Ideal.Quotient.algebra R) _ := ((quotientSpanCXSubCAlgEquiv (X - C x) y).restrictScalars R).trans <| quotientSpanXSubCAlgEquiv x lemma modByMonic_eq_zero_iff_quotient_eq_zero (p q : R[X]) (hq : q.Monic) : p %ₘ q = 0 ↔ (p : R[X] ⧸ Ideal.span {q}) = 0 := by rw [modByMonic_eq_zero_iff_dvd hq, Ideal.Quotient.eq_zero_iff_dvd] end Polynomial namespace Ideal noncomputable section open Polynomial variable {R : Type*} [CommRing R] theorem quotient_map_C_eq_zero {I : Ideal R} : ∀ a ∈ I, ((Quotient.mk (map (C : R →+* R[X]) I : Ideal R[X])).comp C) a = 0 := by intro a ha rw [RingHom.comp_apply, Quotient.eq_zero_iff_mem] exact mem_map_of_mem _ ha theorem eval₂_C_mk_eq_zero {I : Ideal R} : ∀ f ∈ (map (C : R →+* R[X]) I : Ideal R[X]), eval₂RingHom (C.comp (Quotient.mk I)) X f = 0 := by intro a ha rw [← sum_monomial_eq a] dsimp rw [eval₂_sum] refine Finset.sum_eq_zero fun n _ => ?_ dsimp rw [eval₂_monomial (C.comp (Quotient.mk I)) X] refine mul_eq_zero_of_left (Polynomial.ext fun m => ?_) (X ^ n) erw [coeff_C] by_cases h : m = 0 · simpa [h] using Quotient.eq_zero_iff_mem.2 ((mem_map_C_iff.1 ha) n) · simp [h] /-- If `I` is an ideal of `R`, then the ring polynomials over the quotient ring `I.quotient` is isomorphic to the quotient of `R[X]` by the ideal `map C I`, where `map C I` contains exactly the polynomials whose coefficients all lie in `I`. -/ def polynomialQuotientEquivQuotientPolynomial (I : Ideal R) : (R ⧸ I)[X] ≃+* R[X] ⧸ (map C I : Ideal R[X]) where toFun := eval₂RingHom (Quotient.lift I ((Quotient.mk (map C I : Ideal R[X])).comp C) quotient_map_C_eq_zero) (Quotient.mk (map C I : Ideal R[X]) X) invFun := Quotient.lift (map C I : Ideal R[X]) (eval₂RingHom (C.comp (Quotient.mk I)) X) eval₂_C_mk_eq_zero map_mul' f g := by simp only [coe_eval₂RingHom, eval₂_mul] map_add' f g := by simp only [eval₂_add, coe_eval₂RingHom] left_inv := by intro f refine Polynomial.induction_on' f ?_ ?_ · intro p q hp hq simp only [coe_eval₂RingHom] at hp hq simp only [coe_eval₂RingHom, hp, hq, RingHom.map_add] · rintro n ⟨x⟩ simp only [← smul_X_eq_monomial, C_mul', Quotient.lift_mk, Submodule.Quotient.quot_mk_eq_mk, Quotient.mk_eq_mk, eval₂_X_pow, eval₂_smul, coe_eval₂RingHom, RingHom.map_pow, eval₂_C, RingHom.coe_comp, RingHom.map_mul, eval₂_X, Function.comp_apply] right_inv := by rintro ⟨f⟩ refine Polynomial.induction_on' f ?_ ?_ · -- Porting note: was `simp_intro p q hp hq` intros p q hp hq simp only [Submodule.Quotient.quot_mk_eq_mk, Quotient.mk_eq_mk, map_add, Quotient.lift_mk, coe_eval₂RingHom] at hp hq ⊢ rw [hp, hq] · intro n a simp only [← smul_X_eq_monomial, ← C_mul' a (X ^ n), Quotient.lift_mk, Submodule.Quotient.quot_mk_eq_mk, Quotient.mk_eq_mk, eval₂_X_pow, eval₂_smul, coe_eval₂RingHom, RingHom.map_pow, eval₂_C, RingHom.coe_comp, RingHom.map_mul, eval₂_X, Function.comp_apply] @[simp] theorem polynomialQuotientEquivQuotientPolynomial_symm_mk (I : Ideal R) (f : R[X]) : I.polynomialQuotientEquivQuotientPolynomial.symm (Quotient.mk _ f) = f.map (Quotient.mk I) := by rw [polynomialQuotientEquivQuotientPolynomial, RingEquiv.symm_mk, RingEquiv.coe_mk, Equiv.coe_fn_mk, Quotient.lift_mk, coe_eval₂RingHom, eval₂_eq_eval_map, ← Polynomial.map_map, ← eval₂_eq_eval_map, Polynomial.eval₂_C_X] @[simp] theorem polynomialQuotientEquivQuotientPolynomial_map_mk (I : Ideal R) (f : R[X]) : I.polynomialQuotientEquivQuotientPolynomial (f.map <| Quotient.mk I) = Quotient.mk (map C I : Ideal R[X]) f := by apply (polynomialQuotientEquivQuotientPolynomial I).symm.injective rw [RingEquiv.symm_apply_apply, polynomialQuotientEquivQuotientPolynomial_symm_mk] /-- If `P` is a prime ideal of `R`, then `R[x]/(P)` is an integral domain. -/ theorem isDomain_map_C_quotient {P : Ideal R} (_ : IsPrime P) : IsDomain (R[X] ⧸ (map (C : R →+* R[X]) P : Ideal R[X])) := MulEquiv.isDomain (Polynomial (R ⧸ P)) (polynomialQuotientEquivQuotientPolynomial P).symm /-- Given any ring `R` and an ideal `I` of `R[X]`, we get a map `R → R[x] → R[x]/I`. If we let `R` be the image of `R` in `R[x]/I` then we also have a map `R[x] → R'[x]`. In particular we can map `I` across this map, to get `I'` and a new map `R' → R'[x] → R'[x]/I`. This theorem shows `I'` will not contain any non-zero constant polynomials. -/ theorem eq_zero_of_polynomial_mem_map_range (I : Ideal R[X]) (x : ((Quotient.mk I).comp C).range) (hx : C x ∈ I.map (Polynomial.mapRingHom ((Quotient.mk I).comp C).rangeRestrict)) : x = 0 := by let i := ((Quotient.mk I).comp C).rangeRestrict have hi' : RingHom.ker (Polynomial.mapRingHom i) ≤ I := by refine fun f hf => polynomial_mem_ideal_of_coeff_mem_ideal I f fun n => ?_ rw [mem_comap, ← Quotient.eq_zero_iff_mem, ← RingHom.comp_apply] rw [RingHom.mem_ker, coe_mapRingHom] at hf replace hf := congr_arg (fun f : Polynomial _ => f.coeff n) hf simp only [coeff_map, coeff_zero] at hf rwa [Subtype.ext_iff, RingHom.coe_rangeRestrict] at hf obtain ⟨x, hx'⟩ := x obtain ⟨y, rfl⟩ := RingHom.mem_range.1 hx' refine Subtype.eq ?_ simp only [RingHom.comp_apply, Quotient.eq_zero_iff_mem, ZeroMemClass.coe_zero] suffices C (i y) ∈ I.map (Polynomial.mapRingHom i) by obtain ⟨f, hf⟩ := mem_image_of_mem_map_of_surjective (Polynomial.mapRingHom i) (Polynomial.map_surjective _ (RingHom.rangeRestrict_surjective ((Quotient.mk I).comp C))) this refine sub_add_cancel (C y) f ▸ I.add_mem (hi' ?_ : C y - f ∈ I) hf.1 rw [RingHom.mem_ker, RingHom.map_sub, hf.2, sub_eq_zero, coe_mapRingHom, map_C] exact hx end end Ideal namespace MvPolynomial variable {R : Type*} {σ : Type*} [CommRing R] {r : R} theorem quotient_map_C_eq_zero {I : Ideal R} {i : R} (hi : i ∈ I) : (Ideal.Quotient.mk (Ideal.map (C : R →+* MvPolynomial σ R) I : Ideal (MvPolynomial σ R))).comp C i = 0 := by simp only [Function.comp_apply, RingHom.coe_comp, Ideal.Quotient.eq_zero_iff_mem] exact Ideal.mem_map_of_mem _ hi theorem eval₂_C_mk_eq_zero {I : Ideal R} {a : MvPolynomial σ R} (ha : a ∈ (Ideal.map (C : R →+* MvPolynomial σ R) I : Ideal (MvPolynomial σ R))) : eval₂Hom (C.comp (Ideal.Quotient.mk I)) X a = 0 := by rw [as_sum a] rw [coe_eval₂Hom, eval₂_sum] refine Finset.sum_eq_zero fun n _ => ?_ simp only [eval₂_monomial, Function.comp_apply, RingHom.coe_comp] refine mul_eq_zero_of_left ?_ _ suffices coeff n a ∈ I by rw [← @Ideal.mk_ker R _ I, RingHom.mem_ker] at this simp only [this, C_0] exact mem_map_C_iff.1 ha n lemma quotientEquivQuotientMvPolynomial_rightInverse (I : Ideal R) : Function.RightInverse (eval₂ (Ideal.Quotient.lift I ((Ideal.Quotient.mk (Ideal.map C I : Ideal (MvPolynomial σ R))).comp C) fun i hi => quotient_map_C_eq_zero hi) fun i => Ideal.Quotient.mk (Ideal.map C I : Ideal (MvPolynomial σ R)) (X i)) (Ideal.Quotient.lift (Ideal.map C I : Ideal (MvPolynomial σ R)) (eval₂Hom (C.comp (Ideal.Quotient.mk I)) X) fun a ha => eval₂_C_mk_eq_zero ha) := by intro f apply induction_on f · intro r obtain ⟨r, rfl⟩ := Ideal.Quotient.mk_surjective r rw [eval₂_C, Ideal.Quotient.lift_mk, RingHom.comp_apply, Ideal.Quotient.lift_mk, eval₂Hom_C, RingHom.comp_apply] · intros p q hp hq simp only [RingHom.map_add, MvPolynomial.coe_eval₂Hom, coe_eval₂Hom, MvPolynomial.eval₂_add] at hp hq ⊢ rw [hp, hq] · intros p i hp simp only [coe_eval₂Hom] at hp simp only [hp, coe_eval₂Hom, Ideal.Quotient.lift_mk, eval₂_mul, RingHom.map_mul, eval₂_X] lemma quotientEquivQuotientMvPolynomial_leftInverse (I : Ideal R) : Function.LeftInverse (eval₂ (Ideal.Quotient.lift I ((Ideal.Quotient.mk (Ideal.map C I : Ideal (MvPolynomial σ R))).comp C) fun i hi => quotient_map_C_eq_zero hi) fun i => Ideal.Quotient.mk (Ideal.map C I : Ideal (MvPolynomial σ R)) (X i)) (Ideal.Quotient.lift (Ideal.map C I : Ideal (MvPolynomial σ R)) (eval₂Hom (C.comp (Ideal.Quotient.mk I)) X) fun a ha => eval₂_C_mk_eq_zero ha) := by intro f obtain ⟨f, rfl⟩ := Ideal.Quotient.mk_surjective f apply induction_on f · intro r rw [Ideal.Quotient.lift_mk, eval₂Hom_C, RingHom.comp_apply, eval₂_C, Ideal.Quotient.lift_mk, RingHom.comp_apply] · intros p q hp hq erw [Ideal.Quotient.lift_mk] at hp hq ⊢ simp only [Submodule.Quotient.quot_mk_eq_mk, eval₂_add, RingHom.map_add, coe_eval₂Hom, Ideal.Quotient.lift_mk, Ideal.Quotient.mk_eq_mk] at hp hq ⊢ rw [hp, hq] · intros p i hp simp only [Submodule.Quotient.quot_mk_eq_mk, coe_eval₂Hom, Ideal.Quotient.lift_mk, Ideal.Quotient.mk_eq_mk, eval₂_mul, RingHom.map_mul, eval₂_X] at hp ⊢ simp only [hp] -- Porting note: this definition was split to avoid timeouts. /-- If `I` is an ideal of `R`, then the ring `MvPolynomial σ I.quotient` is isomorphic as an `R`-algebra to the quotient of `MvPolynomial σ R` by the ideal generated by `I`. -/ noncomputable def quotientEquivQuotientMvPolynomial (I : Ideal R) : MvPolynomial σ (R ⧸ I) ≃ₐ[R] MvPolynomial σ R ⧸ (Ideal.map C I : Ideal (MvPolynomial σ R)) := let e : MvPolynomial σ (R ⧸ I) →ₐ[R] MvPolynomial σ R ⧸ (Ideal.map C I : Ideal (MvPolynomial σ R)) := { eval₂Hom (Ideal.Quotient.lift I ((Ideal.Quotient.mk (Ideal.map C I : Ideal (MvPolynomial σ R))).comp C) fun _ hi => quotient_map_C_eq_zero hi) fun i => Ideal.Quotient.mk (Ideal.map C I : Ideal (MvPolynomial σ R)) (X i) with commutes' := fun r => eval₂Hom_C _ _ (Ideal.Quotient.mk I r) } { e with invFun := Ideal.Quotient.lift (Ideal.map C I : Ideal (MvPolynomial σ R)) (eval₂Hom (C.comp (Ideal.Quotient.mk I)) X) fun _ ha => eval₂_C_mk_eq_zero ha left_inv := quotientEquivQuotientMvPolynomial_rightInverse I right_inv := quotientEquivQuotientMvPolynomial_leftInverse I } end MvPolynomial
RingTheory\Polynomial\RationalRoot.lean
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.RingTheory.IntegralClosure.IntegrallyClosed import Mathlib.RingTheory.Localization.NumDen import Mathlib.RingTheory.Polynomial.ScaleRoots /-! # Rational root theorem and integral root theorem This file contains the rational root theorem and integral root theorem. The rational root theorem for a unique factorization domain `A` with localization `S`, states that the roots of `p : A[X]` in `A`'s field of fractions are of the form `x / y` with `x y : A`, `x ∣ p.coeff 0` and `y ∣ p.leadingCoeff`. The corollary is the integral root theorem `isInteger_of_is_root_of_monic`: if `p` is monic, its roots must be integers. Finally, we use this to show unique factorization domains are integrally closed. ## References * https://en.wikipedia.org/wiki/Rational_root_theorem -/ open scoped Polynomial section ScaleRoots variable {A K R S : Type*} [CommRing A] [Field K] [CommRing R] [CommRing S] variable {M : Submonoid A} [Algebra A S] [IsLocalization M S] [Algebra A K] [IsFractionRing A K] open Finsupp IsFractionRing IsLocalization Polynomial theorem scaleRoots_aeval_eq_zero_of_aeval_mk'_eq_zero {p : A[X]} {r : A} {s : M} (hr : aeval (mk' S r s) p = 0) : aeval (algebraMap A S r) (scaleRoots p s) = 0 := by convert scaleRoots_eval₂_eq_zero (algebraMap A S) hr -- Porting note: added funext rw [aeval_def, mk'_spec' _ r s] variable [IsDomain A] theorem num_isRoot_scaleRoots_of_aeval_eq_zero [UniqueFactorizationMonoid A] {p : A[X]} {x : K} (hr : aeval x p = 0) : IsRoot (scaleRoots p (den A x)) (num A x) := by apply isRoot_of_eval₂_map_eq_zero (IsFractionRing.injective A K) refine scaleRoots_aeval_eq_zero_of_aeval_mk'_eq_zero ?_ rw [mk'_num_den] exact hr end ScaleRoots section RationalRootTheorem variable {A K : Type*} [CommRing A] [IsDomain A] [UniqueFactorizationMonoid A] [Field K] variable [Algebra A K] [IsFractionRing A K] open IsFractionRing IsLocalization Polynomial UniqueFactorizationMonoid /-- **Rational root theorem** part 1: if `r : f.codomain` is a root of a polynomial over the ufd `A`, then the numerator of `r` divides the constant coefficient -/ theorem num_dvd_of_is_root {p : A[X]} {r : K} (hr : aeval r p = 0) : num A r ∣ p.coeff 0 := by suffices num A r ∣ (scaleRoots p (den A r)).coeff 0 by simp only [coeff_scaleRoots, tsub_zero] at this haveI inst := Classical.propDecidable by_cases hr : num A r = 0 · simp_all [nonZeroDivisors.coe_ne_zero] · refine dvd_of_dvd_mul_left_of_no_prime_factors hr ?_ this intro q dvd_num dvd_denom_pow hq apply hq.not_unit exact num_den_reduced A r dvd_num (hq.dvd_of_dvd_pow dvd_denom_pow) convert dvd_term_of_isRoot_of_dvd_terms 0 (num_isRoot_scaleRoots_of_aeval_eq_zero hr) _ · rw [pow_zero, mul_one] intro j hj apply dvd_mul_of_dvd_right convert pow_dvd_pow (num A r) (Nat.succ_le_of_lt (bot_lt_iff_ne_bot.mpr hj)) exact (pow_one _).symm /-- Rational root theorem part 2: if `r : f.codomain` is a root of a polynomial over the ufd `A`, then the denominator of `r` divides the leading coefficient -/ theorem den_dvd_of_is_root {p : A[X]} {r : K} (hr : aeval r p = 0) : (den A r : A) ∣ p.leadingCoeff := by suffices (den A r : A) ∣ p.leadingCoeff * num A r ^ p.natDegree by refine dvd_of_dvd_mul_left_of_no_prime_factors (mem_nonZeroDivisors_iff_ne_zero.mp (den A r).2) ?_ this intro q dvd_den dvd_num_pow hq apply hq.not_unit exact num_den_reduced A r (hq.dvd_of_dvd_pow dvd_num_pow) dvd_den rw [← coeff_scaleRoots_natDegree] apply dvd_term_of_isRoot_of_dvd_terms _ (num_isRoot_scaleRoots_of_aeval_eq_zero hr) intro j hj by_cases h : j < p.natDegree · rw [coeff_scaleRoots] refine (dvd_mul_of_dvd_right ?_ _).mul_right _ convert pow_dvd_pow (den A r : A) (Nat.succ_le_iff.mpr (lt_tsub_iff_left.mpr _)) · exact (pow_one _).symm simpa using h rw [← natDegree_scaleRoots p (den A r)] at * rw [coeff_eq_zero_of_natDegree_lt (lt_of_le_of_ne (le_of_not_gt h) hj.symm), zero_mul] exact dvd_zero _ /-- **Integral root theorem**: if `r : f.codomain` is a root of a monic polynomial over the ufd `A`, then `r` is an integer -/ theorem isInteger_of_is_root_of_monic {p : A[X]} (hp : Monic p) {r : K} (hr : aeval r p = 0) : IsInteger A r := isInteger_of_isUnit_den (isUnit_of_dvd_one (hp ▸ den_dvd_of_is_root hr)) theorem exists_integer_of_is_root_of_monic {p : A[X]} (hp : Monic p) {r : K} (hr : aeval r p = 0) : ∃ r' : A, r = algebraMap A K r' ∧ r' ∣ p.coeff 0 := by /- I tried deducing this from above by unwrapping IsInteger, but the divisibility condition is annoying -/ obtain ⟨inv, h_inv⟩ := hp ▸ den_dvd_of_is_root hr use num A r * inv, ?_ · have h : inv ∣ 1 := ⟨den A r, by simpa [mul_comm] using h_inv⟩ simpa using mul_dvd_mul (num_dvd_of_is_root hr) h · have d_ne_zero : algebraMap A K (den A r) ≠ 0 := IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors (den A r).prop nth_rw 1 [← mk'_num_den' A r] rw [div_eq_iff d_ne_zero, map_mul, mul_assoc, mul_comm ((algebraMap A K) inv), ← map_mul, ← h_inv, map_one, mul_one] namespace UniqueFactorizationMonoid theorem integer_of_integral {x : K} : IsIntegral A x → IsInteger A x := fun ⟨_, hp, hx⟩ => isInteger_of_is_root_of_monic hp hx -- See library note [lower instance priority] instance (priority := 100) instIsIntegrallyClosed : IsIntegrallyClosed A := (isIntegrallyClosed_iff (FractionRing A)).mpr fun {_} => integer_of_integral end UniqueFactorizationMonoid end RationalRootTheorem
RingTheory\Polynomial\ScaleRoots.lean
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Devon Tuma -/ import Mathlib.Algebra.GroupWithZero.NonZeroDivisors import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.RingTheory.Coprime.Basic import Mathlib.Tactic.AdaptationNote /-! # Scaling the roots of a polynomial This file defines `scaleRoots p s` for a polynomial `p` in one variable and a ring element `s` to be the polynomial with root `r * s` for each root `r` of `p` and proves some basic results about it. -/ variable {R S A K : Type*} namespace Polynomial open Polynomial section Semiring variable [Semiring R] [Semiring S] /-- `scaleRoots p s` is a polynomial with root `r * s` for each root `r` of `p`. -/ noncomputable def scaleRoots (p : R[X]) (s : R) : R[X] := ∑ i ∈ p.support, monomial i (p.coeff i * s ^ (p.natDegree - i)) @[simp] theorem coeff_scaleRoots (p : R[X]) (s : R) (i : ℕ) : (scaleRoots p s).coeff i = coeff p i * s ^ (p.natDegree - i) := by simp (config := { contextual := true }) [scaleRoots, coeff_monomial] theorem coeff_scaleRoots_natDegree (p : R[X]) (s : R) : (scaleRoots p s).coeff p.natDegree = p.leadingCoeff := by rw [leadingCoeff, coeff_scaleRoots, tsub_self, pow_zero, mul_one] @[simp] theorem zero_scaleRoots (s : R) : scaleRoots 0 s = 0 := by ext simp theorem scaleRoots_ne_zero {p : R[X]} (hp : p ≠ 0) (s : R) : scaleRoots p s ≠ 0 := by intro h have : p.coeff p.natDegree ≠ 0 := mt leadingCoeff_eq_zero.mp hp have : (scaleRoots p s).coeff p.natDegree = 0 := congr_fun (congr_arg (coeff : R[X] → ℕ → R) h) p.natDegree rw [coeff_scaleRoots_natDegree] at this contradiction theorem support_scaleRoots_le (p : R[X]) (s : R) : (scaleRoots p s).support ≤ p.support := by intro simpa using left_ne_zero_of_mul theorem support_scaleRoots_eq (p : R[X]) {s : R} (hs : s ∈ nonZeroDivisors R) : (scaleRoots p s).support = p.support := le_antisymm (support_scaleRoots_le p s) (by intro i simp only [coeff_scaleRoots, Polynomial.mem_support_iff] intro p_ne_zero ps_zero have := pow_mem hs (p.natDegree - i) _ ps_zero contradiction) @[simp] theorem degree_scaleRoots (p : R[X]) {s : R} : degree (scaleRoots p s) = degree p := by haveI := Classical.propDecidable by_cases hp : p = 0 · rw [hp, zero_scaleRoots] refine le_antisymm (Finset.sup_mono (support_scaleRoots_le p s)) (degree_le_degree ?_) rw [coeff_scaleRoots_natDegree] intro h have := leadingCoeff_eq_zero.mp h contradiction @[simp] theorem natDegree_scaleRoots (p : R[X]) (s : R) : natDegree (scaleRoots p s) = natDegree p := by simp only [natDegree, degree_scaleRoots] theorem monic_scaleRoots_iff {p : R[X]} (s : R) : Monic (scaleRoots p s) ↔ Monic p := by simp only [Monic, leadingCoeff, natDegree_scaleRoots, coeff_scaleRoots_natDegree] theorem map_scaleRoots (p : R[X]) (x : R) (f : R →+* S) (h : f p.leadingCoeff ≠ 0) : (p.scaleRoots x).map f = (p.map f).scaleRoots (f x) := by ext simp [Polynomial.natDegree_map_of_leadingCoeff_ne_zero _ h] @[simp] lemma scaleRoots_C (r c : R) : (C c).scaleRoots r = C c := by ext; simp @[simp] lemma scaleRoots_one (p : R[X]) : p.scaleRoots 1 = p := by ext; simp @[simp] lemma scaleRoots_zero (p : R[X]) : p.scaleRoots 0 = p.leadingCoeff • X ^ p.natDegree := by ext n simp only [coeff_scaleRoots, ne_eq, tsub_eq_zero_iff_le, not_le, zero_pow_eq, mul_ite, mul_one, mul_zero, coeff_smul, coeff_X_pow, smul_eq_mul] split_ifs with h₁ h₂ h₂ · subst h₂; rfl · exact coeff_eq_zero_of_natDegree_lt (lt_of_le_of_ne h₁ (Ne.symm h₂)) · exact (h₁ h₂.ge).elim · rfl @[simp] lemma one_scaleRoots (r : R) : (1 : R[X]).scaleRoots r = 1 := by ext; simp end Semiring section CommSemiring variable [Semiring S] [CommSemiring R] [Semiring A] [Field K] theorem scaleRoots_eval₂_mul_of_commute {p : S[X]} (f : S →+* A) (a : A) (s : S) (hsa : Commute (f s) a) (hf : ∀ s₁ s₂, Commute (f s₁) (f s₂)) : eval₂ f (f s * a) (scaleRoots p s) = f s ^ p.natDegree * eval₂ f a p := by calc _ = (scaleRoots p s).support.sum fun i => f (coeff p i * s ^ (p.natDegree - i)) * (f s * a) ^ i := by simp [eval₂_eq_sum, sum_def] _ = p.support.sum fun i => f (coeff p i * s ^ (p.natDegree - i)) * (f s * a) ^ i := (Finset.sum_subset (support_scaleRoots_le p s) fun i _hi hi' => by let this : coeff p i * s ^ (p.natDegree - i) = 0 := by simpa using hi' simp [this]) _ = p.support.sum fun i : ℕ => f (p.coeff i) * f s ^ (p.natDegree - i + i) * a ^ i := (Finset.sum_congr rfl fun i _hi => by simp_rw [f.map_mul, f.map_pow, pow_add, hsa.mul_pow, mul_assoc]) _ = p.support.sum fun i : ℕ => f s ^ p.natDegree * (f (p.coeff i) * a ^ i) := Finset.sum_congr rfl fun i hi => by rw [mul_assoc, ← map_pow, (hf _ _).left_comm, map_pow, tsub_add_cancel_of_le] exact le_natDegree_of_ne_zero (Polynomial.mem_support_iff.mp hi) _ = f s ^ p.natDegree * eval₂ f a p := by simp [← Finset.mul_sum, eval₂_eq_sum, sum_def] theorem scaleRoots_eval₂_mul {p : S[X]} (f : S →+* R) (r : R) (s : S) : eval₂ f (f s * r) (scaleRoots p s) = f s ^ p.natDegree * eval₂ f r p := scaleRoots_eval₂_mul_of_commute f r s (mul_comm _ _) fun _ _ ↦ mul_comm _ _ theorem scaleRoots_eval₂_eq_zero {p : S[X]} (f : S →+* R) {r : R} {s : S} (hr : eval₂ f r p = 0) : eval₂ f (f s * r) (scaleRoots p s) = 0 := by rw [scaleRoots_eval₂_mul, hr, mul_zero] theorem scaleRoots_aeval_eq_zero [Algebra R A] {p : R[X]} {a : A} {r : R} (ha : aeval a p = 0) : aeval (algebraMap R A r * a) (scaleRoots p r) = 0 := by rw [aeval_def, scaleRoots_eval₂_mul_of_commute, ← aeval_def, ha, mul_zero] · apply Algebra.commutes · intros; rw [Commute, SemiconjBy, ← map_mul, ← map_mul, mul_comm] theorem scaleRoots_eval₂_eq_zero_of_eval₂_div_eq_zero {p : S[X]} {f : S →+* K} (hf : Function.Injective f) {r s : S} (hr : eval₂ f (f r / f s) p = 0) (hs : s ∈ nonZeroDivisors S) : eval₂ f (f r) (scaleRoots p s) = 0 := by -- The proof works without this option, but *much* slower. set_option tactic.skipAssignedInstances false in nontriviality S using Subsingleton.eq_zero convert @scaleRoots_eval₂_eq_zero _ _ _ _ p f _ s hr rw [← mul_div_assoc, mul_comm, mul_div_cancel_right₀] exact map_ne_zero_of_mem_nonZeroDivisors _ hf hs theorem scaleRoots_aeval_eq_zero_of_aeval_div_eq_zero [Algebra R K] (inj : Function.Injective (algebraMap R K)) {p : R[X]} {r s : R} (hr : aeval (algebraMap R K r / algebraMap R K s) p = 0) (hs : s ∈ nonZeroDivisors R) : aeval (algebraMap R K r) (scaleRoots p s) = 0 := scaleRoots_eval₂_eq_zero_of_eval₂_div_eq_zero inj hr hs @[simp] lemma scaleRoots_mul (p : R[X]) (r s) : p.scaleRoots (r * s) = (p.scaleRoots r).scaleRoots s := by ext; simp [mul_pow, mul_assoc] /-- Multiplication and `scaleRoots` commute up to a power of `r`. The factor disappears if we assume that the product of the leading coeffs does not vanish. See `Polynomial.mul_scaleRoots'`. -/ lemma mul_scaleRoots (p q : R[X]) (r : R) : r ^ (natDegree p + natDegree q - natDegree (p * q)) • (p * q).scaleRoots r = p.scaleRoots r * q.scaleRoots r := by ext n; simp only [coeff_scaleRoots, coeff_smul, smul_eq_mul] trans (∑ x ∈ Finset.antidiagonal n, coeff p x.1 * coeff q x.2) * r ^ (natDegree p + natDegree q - n) · rw [← coeff_mul] cases lt_or_le (natDegree (p * q)) n with | inl h => simp only [coeff_eq_zero_of_natDegree_lt h, zero_mul, mul_zero] | inr h => rw [mul_comm, mul_assoc, ← pow_add, add_comm, tsub_add_tsub_cancel natDegree_mul_le h] · rw [coeff_mul, Finset.sum_mul] apply Finset.sum_congr rfl simp only [Finset.mem_antidiagonal, coeff_scaleRoots, Prod.forall] intros a b e cases lt_or_le (natDegree p) a with | inl h => simp only [coeff_eq_zero_of_natDegree_lt h, zero_mul, mul_zero] | inr ha => cases lt_or_le (natDegree q) b with | inl h => simp only [coeff_eq_zero_of_natDegree_lt h, zero_mul, mul_zero] | inr hb => simp only [← e, mul_assoc, mul_comm (r ^ (_ - a)), ← pow_add] rw [add_comm (_ - _), tsub_add_tsub_comm ha hb] lemma mul_scaleRoots' (p q : R[X]) (r : R) (h : leadingCoeff p * leadingCoeff q ≠ 0) : (p * q).scaleRoots r = p.scaleRoots r * q.scaleRoots r := by rw [← mul_scaleRoots, natDegree_mul' h, tsub_self, pow_zero, one_smul] lemma mul_scaleRoots_of_noZeroDivisors (p q : R[X]) (r : R) [NoZeroDivisors R] : (p * q).scaleRoots r = p.scaleRoots r * q.scaleRoots r := by by_cases hp : p = 0; · simp [hp] by_cases hq : q = 0; · simp [hq] apply mul_scaleRoots' simp only [ne_eq, mul_eq_zero, leadingCoeff_eq_zero, hp, hq, or_self, not_false_eq_true] lemma add_scaleRoots_of_natDegree_eq (p q : R[X]) (r : R) (h : natDegree p = natDegree q) : r ^ (natDegree p - natDegree (p + q)) • (p + q).scaleRoots r = p.scaleRoots r + q.scaleRoots r := by ext n; simp only [coeff_smul, coeff_scaleRoots, coeff_add, smul_eq_mul, mul_comm (r ^ _), ← pow_add, ← h, ← add_mul, add_comm (_ - n)] #adaptation_note /-- v4.7.0-rc1 Previously `mul_assoc` was part of the `simp only` above, and this `rw` was not needed. but this now causes a max rec depth error. -/ rw [mul_assoc, ← pow_add] cases lt_or_le (natDegree (p + q)) n with | inl hn => simp only [← coeff_add, coeff_eq_zero_of_natDegree_lt hn, zero_mul] | inr hn => rw [add_comm (_ - n), tsub_add_tsub_cancel (natDegree_add_le_of_degree_le le_rfl h.ge) hn] lemma scaleRoots_dvd' (p q : R[X]) {r : R} (hr : IsUnit r) (hpq : p ∣ q) : p.scaleRoots r ∣ q.scaleRoots r := by obtain ⟨a, rfl⟩ := hpq rw [← ((hr.pow (natDegree p + natDegree a - natDegree (p * a))).map (algebraMap R R[X])).dvd_mul_left, ← Algebra.smul_def, mul_scaleRoots] exact dvd_mul_right (scaleRoots p r) (scaleRoots a r) lemma scaleRoots_dvd (p q : R[X]) {r : R} [NoZeroDivisors R] (hpq : p ∣ q) : p.scaleRoots r ∣ q.scaleRoots r := by obtain ⟨a, rfl⟩ := hpq rw [mul_scaleRoots_of_noZeroDivisors] exact dvd_mul_right (scaleRoots p r) (scaleRoots a r) alias _root_.Dvd.dvd.scaleRoots := scaleRoots_dvd lemma scaleRoots_dvd_iff (p q : R[X]) {r : R} (hr : IsUnit r) : p.scaleRoots r ∣ q.scaleRoots r ↔ p ∣ q := by refine ⟨?_ ∘ scaleRoots_dvd' _ _ (hr.unit⁻¹).isUnit, scaleRoots_dvd' p q hr⟩ simp [← scaleRoots_mul, scaleRoots_one] alias _root_.IsUnit.scaleRoots_dvd_iff := scaleRoots_dvd_iff lemma isCoprime_scaleRoots (p q : R[X]) (r : R) (hr : IsUnit r) (h : IsCoprime p q) : IsCoprime (p.scaleRoots r) (q.scaleRoots r) := by obtain ⟨a, b, e⟩ := h let s : R := ↑hr.unit⁻¹ have : natDegree (a * p) = natDegree (b * q) := by apply natDegree_eq_of_natDegree_add_eq_zero rw [e, natDegree_one] use s ^ natDegree (a * p) • s ^ (natDegree a + natDegree p - natDegree (a * p)) • a.scaleRoots r use s ^ natDegree (a * p) • s ^ (natDegree b + natDegree q - natDegree (b * q)) • b.scaleRoots r simp only [s, smul_mul_assoc, ← mul_scaleRoots, smul_smul, Units.smul_def, mul_assoc, ← mul_pow, IsUnit.val_inv_mul, one_pow, mul_one, ← smul_add, one_smul, e, natDegree_one, one_scaleRoots, ← add_scaleRoots_of_natDegree_eq _ _ _ this, tsub_zero] alias _root_.IsCoprime.scaleRoots := isCoprime_scaleRoots end CommSemiring end Polynomial
RingTheory\Polynomial\Selmer.lean
/- Copyright (c) 2022 Thomas Browning. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning -/ import Mathlib.Analysis.Complex.Polynomial.UnitTrinomial import Mathlib.RingTheory.Polynomial.GaussLemma import Mathlib.Tactic.LinearCombination /-! # Irreducibility of Selmer Polynomials This file proves irreducibility of the Selmer polynomials `X ^ n - X - 1`. ## Main results - `X_pow_sub_X_sub_one_irreducible`: The Selmer polynomials `X ^ n - X - 1` are irreducible. TODO: Show that the Selmer polynomials have full Galois group. -/ namespace Polynomial open scoped Polynomial variable {n : ℕ} theorem X_pow_sub_X_sub_one_irreducible_aux (z : ℂ) : ¬(z ^ n = z + 1 ∧ z ^ n + z ^ 2 = 0) := by rintro ⟨h1, h2⟩ replace h3 : z ^ 3 = 1 := by linear_combination (1 - z - z ^ 2 - z ^ n) * h1 + (z ^ n - 2) * h2 have key : z ^ n = 1 ∨ z ^ n = z ∨ z ^ n = z ^ 2 := by rw [← Nat.mod_add_div n 3, pow_add, pow_mul, h3, one_pow, mul_one] have : n % 3 < 3 := Nat.mod_lt n zero_lt_three interval_cases n % 3 <;> simp only [this, pow_zero, pow_one, eq_self_iff_true, or_true_iff, true_or_iff] have z_ne_zero : z ≠ 0 := fun h => zero_ne_one ((zero_pow three_ne_zero).symm.trans (show (0 : ℂ) ^ 3 = 1 from h ▸ h3)) rcases key with (key | key | key) · exact z_ne_zero (by rwa [key, self_eq_add_left] at h1) · exact one_ne_zero (by rwa [key, self_eq_add_right] at h1) · exact z_ne_zero (pow_eq_zero (by rwa [key, add_self_eq_zero] at h2)) theorem X_pow_sub_X_sub_one_irreducible (hn1 : n ≠ 1) : Irreducible (X ^ n - X - 1 : ℤ[X]) := by by_cases hn0 : n = 0 · rw [hn0, pow_zero, sub_sub, add_comm, ← sub_sub, sub_self, zero_sub] exact Associated.irreducible ⟨-1, mul_neg_one X⟩ irreducible_X have hn : 1 < n := Nat.one_lt_iff_ne_zero_and_ne_one.mpr ⟨hn0, hn1⟩ have hp : (X ^ n - X - 1 : ℤ[X]) = trinomial 0 1 n (-1) (-1) 1 := by simp only [trinomial, C_neg, C_1]; ring rw [hp] apply IsUnitTrinomial.irreducible_of_coprime' ⟨0, 1, n, zero_lt_one, hn, -1, -1, 1, rfl⟩ rintro z ⟨h1, h2⟩ apply X_pow_sub_X_sub_one_irreducible_aux (n := n) z rw [trinomial_mirror zero_lt_one hn (-1 : ℤˣ).ne_zero (1 : ℤˣ).ne_zero] at h2 simp_rw [trinomial, aeval_add, aeval_mul, aeval_X_pow, aeval_C, Units.val_neg, Units.val_one, map_neg, map_one] at h1 h2 replace h1 : z ^ n = z + 1 := by linear_combination h1 replace h2 := mul_eq_zero_of_left h2 z rw [add_mul, add_mul, add_zero, mul_assoc (-1 : ℂ), ← pow_succ, Nat.sub_add_cancel hn.le] at h2 rw [h1] at h2 ⊢ exact ⟨rfl, by linear_combination -h2⟩ theorem X_pow_sub_X_sub_one_irreducible_rat (hn1 : n ≠ 1) : Irreducible (X ^ n - X - 1 : ℚ[X]) := by by_cases hn0 : n = 0 · rw [hn0, pow_zero, sub_sub, add_comm, ← sub_sub, sub_self, zero_sub] exact Associated.irreducible ⟨-1, mul_neg_one X⟩ irreducible_X have hp : (X ^ n - X - 1 : ℤ[X]) = trinomial 0 1 n (-1) (-1) 1 := by simp only [trinomial, C_neg, C_1]; ring have hn : 1 < n := Nat.one_lt_iff_ne_zero_and_ne_one.mpr ⟨hn0, hn1⟩ have h := (IsPrimitive.Int.irreducible_iff_irreducible_map_cast ?_).mp (X_pow_sub_X_sub_one_irreducible hn1) · rwa [Polynomial.map_sub, Polynomial.map_sub, Polynomial.map_pow, Polynomial.map_one, Polynomial.map_X] at h · exact hp.symm ▸ (trinomial_monic zero_lt_one hn).isPrimitive end Polynomial
RingTheory\Polynomial\SeparableDegree.lean
/- Copyright (c) 2021 Jakob Scholbach. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jakob Scholbach -/ import Mathlib.Algebra.Algebra.Defs import Mathlib.Algebra.CharP.ExpChar import Mathlib.FieldTheory.Separable /-! # Separable degree This file contains basics about the separable degree of a polynomial. ## Main results - `IsSeparableContraction`: is the condition that, for `g` a separable polynomial, we have that `g(x^(q^m)) = f(x)` for some `m : ℕ`. - `HasSeparableContraction`: the condition of having a separable contraction - `HasSeparableContraction.degree`: the separable degree, defined as the degree of some separable contraction - `Irreducible.hasSeparableContraction`: any irreducible polynomial can be contracted to a separable polynomial - `HasSeparableContraction.dvd_degree'`: the degree of a separable contraction divides the degree, in function of the exponential characteristic of the field - `HasSeparableContraction.dvd_degree` and `HasSeparableContraction.eq_degree` specialize the statement of `separable_degree_dvd_degree` - `IsSeparableContraction.degree_eq`: the separable degree is well-defined, implemented as the statement that the degree of any separable contraction equals `HasSeparableContraction.degree` ## Tags separable degree, degree, polynomial -/ noncomputable section namespace Polynomial open scoped Classical open Polynomial section CommSemiring variable {F : Type*} [CommSemiring F] (q : ℕ) /-- A separable contraction of a polynomial `f` is a separable polynomial `g` such that `g(x^(q^m)) = f(x)` for some `m : ℕ`. -/ def IsSeparableContraction (f : F[X]) (g : F[X]) : Prop := g.Separable ∧ ∃ m : ℕ, expand F (q ^ m) g = f /-- The condition of having a separable contraction. -/ def HasSeparableContraction (f : F[X]) : Prop := ∃ g : F[X], IsSeparableContraction q f g variable {q} {f : F[X]} (hf : HasSeparableContraction q f) /-- A choice of a separable contraction. -/ def HasSeparableContraction.contraction : F[X] := Classical.choose hf /-- The separable degree of a polynomial is the degree of a given separable contraction. -/ def HasSeparableContraction.degree : ℕ := hf.contraction.natDegree /-- The `HasSeparableContraction.contraction` is indeed a separable contraction. -/ theorem HasSeparableContraction.isSeparableContraction : IsSeparableContraction q f hf.contraction := Classical.choose_spec hf /-- The separable degree divides the degree, in function of the exponential characteristic of F. -/ theorem IsSeparableContraction.dvd_degree' {g} (hf : IsSeparableContraction q f g) : ∃ m : ℕ, g.natDegree * q ^ m = f.natDegree := by obtain ⟨m, rfl⟩ := hf.2 use m rw [natDegree_expand] theorem HasSeparableContraction.dvd_degree' : ∃ m : ℕ, hf.degree * q ^ m = f.natDegree := (Classical.choose_spec hf).dvd_degree' hf /-- The separable degree divides the degree. -/ theorem HasSeparableContraction.dvd_degree : hf.degree ∣ f.natDegree := let ⟨a, ha⟩ := hf.dvd_degree' Dvd.intro (q ^ a) ha /-- In exponential characteristic one, the separable degree equals the degree. -/ theorem HasSeparableContraction.eq_degree {f : F[X]} (hf : HasSeparableContraction 1 f) : hf.degree = f.natDegree := by let ⟨a, ha⟩ := hf.dvd_degree' rw [← ha, one_pow a, mul_one] end CommSemiring section Field variable {F : Type*} [Field F] variable (q : ℕ) {f : F[X]} (hf : HasSeparableContraction q f) /-- Every irreducible polynomial can be contracted to a separable polynomial. https://stacks.math.columbia.edu/tag/09H0 -/ theorem _root_.Irreducible.hasSeparableContraction (q : ℕ) [hF : ExpChar F q] {f : F[X]} (irred : Irreducible f) : HasSeparableContraction q f := by cases hF · exact ⟨f, irred.separable, ⟨0, by rw [pow_zero, expand_one]⟩⟩ · rcases exists_separable_of_irreducible q irred ‹q.Prime›.ne_zero with ⟨n, g, hgs, hge⟩ exact ⟨g, hgs, n, hge⟩ /-- If two expansions (along the positive characteristic) of two separable polynomials `g` and `g'` agree, then they have the same degree. -/ theorem contraction_degree_eq_or_insep [hq : NeZero q] [CharP F q] (g g' : F[X]) (m m' : ℕ) (h_expand : expand F (q ^ m) g = expand F (q ^ m') g') (hg : g.Separable) (hg' : g'.Separable) : g.natDegree = g'.natDegree := by wlog hm : m ≤ m' · exact (this q hf g' g m' m h_expand.symm hg' hg (le_of_not_le hm)).symm obtain ⟨s, rfl⟩ := exists_add_of_le hm rw [pow_add, expand_mul, expand_inj (pow_pos (NeZero.pos q) m)] at h_expand subst h_expand rcases isUnit_or_eq_zero_of_separable_expand q s (NeZero.pos q) hg with (h | rfl) · rw [natDegree_expand, natDegree_eq_zero_of_isUnit h, zero_mul] · rw [natDegree_expand, pow_zero, mul_one] /-- The separable degree equals the degree of any separable contraction, i.e., it is unique. -/ theorem IsSeparableContraction.degree_eq [hF : ExpChar F q] (g : F[X]) (hg : IsSeparableContraction q f g) : g.natDegree = hf.degree := by cases hF · rcases hg with ⟨_, m, hm⟩ rw [one_pow, expand_one] at hm rw [hf.eq_degree, hm] · rcases hg with ⟨hg, m, hm⟩ let g' := Classical.choose hf obtain ⟨hg', m', hm'⟩ := Classical.choose_spec hf haveI : Fact q.Prime := ⟨by assumption⟩ refine contraction_degree_eq_or_insep q g g' m m' ?_ hg hg' rw [hm, hm'] end Field end Polynomial
RingTheory\Polynomial\Tower.lean
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Yuyang Zhao -/ import Mathlib.Algebra.Algebra.Tower import Mathlib.Algebra.Polynomial.AlgebraMap /-! # Algebra towers for polynomial This file proves some basic results about the algebra tower structure for the type `R[X]`. This structure itself is provided elsewhere as `Polynomial.isScalarTower` When you update this file, you can also try to make a corresponding update in `RingTheory.MvPolynomial.Tower`. -/ open Polynomial variable (R A B : Type*) namespace Polynomial section Semiring variable [CommSemiring R] [CommSemiring A] [Semiring B] variable [Algebra R A] [Algebra A B] [Algebra R B] variable [IsScalarTower R A B] variable {R B} @[simp] theorem aeval_map_algebraMap (x : B) (p : R[X]) : aeval x (map (algebraMap R A) p) = aeval x p := by rw [aeval_def, aeval_def, eval₂_map, IsScalarTower.algebraMap_eq R A B] @[simp] lemma eval_map_algebraMap (P : R[X]) (a : A) : (map (algebraMap R A) P).eval a = aeval a P := by rw [← aeval_map_algebraMap (A := A), coe_aeval_eq_eval] end Semiring section CommSemiring variable [CommSemiring R] [CommSemiring A] [Semiring B] variable [Algebra R A] [Algebra A B] [Algebra R B] [IsScalarTower R A B] variable {R A} theorem aeval_algebraMap_apply (x : A) (p : R[X]) : aeval (algebraMap A B x) p = algebraMap A B (aeval x p) := by rw [aeval_def, aeval_def, hom_eval₂, ← IsScalarTower.algebraMap_eq] @[simp] theorem aeval_algebraMap_eq_zero_iff [NoZeroSMulDivisors A B] [Nontrivial B] (x : A) (p : R[X]) : aeval (algebraMap A B x) p = 0 ↔ aeval x p = 0 := by rw [aeval_algebraMap_apply, Algebra.algebraMap_eq_smul_one, smul_eq_zero, iff_false_intro (one_ne_zero' B), or_false_iff] variable {B} theorem aeval_algebraMap_eq_zero_iff_of_injective {x : A} {p : R[X]} (h : Function.Injective (algebraMap A B)) : aeval (algebraMap A B x) p = 0 ↔ aeval x p = 0 := by rw [aeval_algebraMap_apply, ← (algebraMap A B).map_zero, h.eq_iff] end CommSemiring end Polynomial namespace Subalgebra open Polynomial section CommSemiring variable {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] @[simp] theorem aeval_coe (S : Subalgebra R A) (x : S) (p : R[X]) : aeval (x : A) p = aeval x p := aeval_algebraMap_apply A x p end CommSemiring end Subalgebra
RingTheory\Polynomial\Vieta.lean
/- Copyright (c) 2020 Hanting Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Hanting Zhang -/ import Mathlib.Algebra.Polynomial.Splits import Mathlib.RingTheory.MvPolynomial.Symmetric /-! # Vieta's Formula The main result is `Multiset.prod_X_add_C_eq_sum_esymm`, which shows that the product of linear terms `X + λ` with `λ` in a `Multiset s` is equal to a linear combination of the symmetric functions `esymm s`. From this, we deduce `MvPolynomial.prod_X_add_C_eq_sum_esymm` which is the equivalent formula for the product of linear terms `X + X i` with `i` in a `Fintype σ` as a linear combination of the symmetric polynomials `esymm σ R j`. For `R` be an integral domain (so that `p.roots` is defined for any `p : R[X]` as a multiset), we derive `Polynomial.coeff_eq_esymm_roots_of_card`, the relationship between the coefficients and the roots of `p` for a polynomial `p` that splits (i.e. having as many roots as its degree). -/ open Polynomial namespace Multiset open Polynomial section Semiring variable {R : Type*} [CommSemiring R] /-- A sum version of **Vieta's formula** for `Multiset`: the product of the linear terms `X + λ` where `λ` runs through a multiset `s` is equal to a linear combination of the symmetric functions `esymm s` of the `λ`'s . -/ theorem prod_X_add_C_eq_sum_esymm (s : Multiset R) : (s.map fun r => X + C r).prod = ∑ j ∈ Finset.range (Multiset.card s + 1), (C (s.esymm j) * X ^ (Multiset.card s - j)) := by classical rw [prod_map_add, antidiagonal_eq_map_powerset, map_map, ← bind_powerset_len, map_bind, sum_bind, Finset.sum_eq_multiset_sum, Finset.range_val, map_congr (Eq.refl _)] intro _ _ rw [esymm, ← sum_hom', ← sum_map_mul_right, map_congr (Eq.refl _)] intro s ht rw [mem_powersetCard] at ht dsimp rw [prod_hom' s (Polynomial.C : R →+* R[X])] simp [ht, map_const, prod_replicate, prod_hom', map_id', card_sub] /-- Vieta's formula for the coefficients of the product of linear terms `X + λ` where `λ` runs through a multiset `s` : the `k`th coefficient is the symmetric function `esymm (card s - k) s`. -/ theorem prod_X_add_C_coeff (s : Multiset R) {k : ℕ} (h : k ≤ Multiset.card s) : (s.map fun r => X + C r).prod.coeff k = s.esymm (Multiset.card s - k) := by convert Polynomial.ext_iff.mp (prod_X_add_C_eq_sum_esymm s) k using 1 simp_rw [finset_sum_coeff, coeff_C_mul_X_pow] rw [Finset.sum_eq_single_of_mem (Multiset.card s - k) _] · rw [if_pos (Nat.sub_sub_self h).symm] · intro j hj1 hj2 suffices k ≠ card s - j by rw [if_neg this] intro hn rw [hn, Nat.sub_sub_self (Nat.lt_succ_iff.mp (Finset.mem_range.mp hj1))] at hj2 exact Ne.irrefl hj2 · rw [Finset.mem_range] exact Nat.lt_succ_of_le (Nat.sub_le (Multiset.card s) k) theorem prod_X_add_C_coeff' {σ} (s : Multiset σ) (r : σ → R) {k : ℕ} (h : k ≤ Multiset.card s) : (s.map fun i => X + C (r i)).prod.coeff k = (s.map r).esymm (Multiset.card s - k) := by erw [← map_map (fun r => X + C r) r, prod_X_add_C_coeff] <;> rw [s.card_map r]; assumption theorem _root_.Finset.prod_X_add_C_coeff {σ} (s : Finset σ) (r : σ → R) {k : ℕ} (h : k ≤ s.card) : (∏ i ∈ s, (X + C (r i))).coeff k = ∑ t ∈ s.powersetCard (s.card - k), ∏ i ∈ t, r i := by rw [Finset.prod, prod_X_add_C_coeff' _ r h, Finset.esymm_map_val] rfl end Semiring section Ring variable {R : Type*} [CommRing R] theorem esymm_neg (s : Multiset R) (k : ℕ) : (map Neg.neg s).esymm k = (-1) ^ k * esymm s k := by rw [esymm, esymm, ← Multiset.sum_map_mul_left, Multiset.powersetCard_map, Multiset.map_map, map_congr rfl] intro x hx rw [(mem_powersetCard.mp hx).right.symm, ← prod_replicate, ← Multiset.map_const] nth_rw 3 [← map_id' x] rw [← prod_map_mul, map_congr rfl, Function.comp_apply] exact fun z _ => neg_one_mul z theorem prod_X_sub_X_eq_sum_esymm (s : Multiset R) : (s.map fun t => X - C t).prod = ∑ j ∈ Finset.range (Multiset.card s + 1), (-1) ^ j * (C (s.esymm j) * X ^ (Multiset.card s - j)) := by conv_lhs => congr congr ext x rw [sub_eq_add_neg] rw [← map_neg C x] convert prod_X_add_C_eq_sum_esymm (map (fun t => -t) s) using 1 · rw [map_map]; rfl · simp only [esymm_neg, card_map, mul_assoc, map_mul, map_pow, map_neg, map_one] theorem prod_X_sub_C_coeff (s : Multiset R) {k : ℕ} (h : k ≤ Multiset.card s) : (s.map fun t => X - C t).prod.coeff k = (-1) ^ (Multiset.card s - k) * s.esymm (Multiset.card s - k) := by conv_lhs => congr congr congr ext x rw [sub_eq_add_neg] rw [← map_neg C x] convert prod_X_add_C_coeff (map (fun t => -t) s) _ using 1 · rw [map_map]; rfl · rw [esymm_neg, card_map] · rwa [card_map] /-- Vieta's formula for the coefficients and the roots of a polynomial over an integral domain with as many roots as its degree. -/ theorem _root_.Polynomial.coeff_eq_esymm_roots_of_card [IsDomain R] {p : R[X]} (hroots : Multiset.card p.roots = p.natDegree) {k : ℕ} (h : k ≤ p.natDegree) : p.coeff k = p.leadingCoeff * (-1) ^ (p.natDegree - k) * p.roots.esymm (p.natDegree - k) := by conv_lhs => rw [← C_leadingCoeff_mul_prod_multiset_X_sub_C hroots] rw [coeff_C_mul, mul_assoc]; congr have : k ≤ card (roots p) := by rw [hroots]; exact h convert p.roots.prod_X_sub_C_coeff this using 3 <;> rw [hroots] /-- Vieta's formula for split polynomials over a field. -/ theorem _root_.Polynomial.coeff_eq_esymm_roots_of_splits {F} [Field F] {p : F[X]} (hsplit : p.Splits (RingHom.id F)) {k : ℕ} (h : k ≤ p.natDegree) : p.coeff k = p.leadingCoeff * (-1) ^ (p.natDegree - k) * p.roots.esymm (p.natDegree - k) := Polynomial.coeff_eq_esymm_roots_of_card (splits_iff_card_roots.1 hsplit) h end Ring end Multiset section MvPolynomial open Finset Polynomial Fintype variable (R σ : Type*) [CommSemiring R] [Fintype σ] /-- A sum version of Vieta's formula for `MvPolynomial`: viewing `X i` as variables, the product of linear terms `λ + X i` is equal to a linear combination of the symmetric polynomials `esymm σ R j`. -/ theorem MvPolynomial.prod_C_add_X_eq_sum_esymm : (∏ i : σ, (Polynomial.X + Polynomial.C (MvPolynomial.X i))) = ∑ j ∈ range (card σ + 1), Polynomial.C (MvPolynomial.esymm σ R j) * Polynomial.X ^ (card σ - j) := by let s := Finset.univ.val.map fun i : σ => (MvPolynomial.X i : MvPolynomial σ R) have : Fintype.card σ = Multiset.card s := by rw [Multiset.card_map, ← Finset.card_univ, Finset.card_def] simp_rw [this, MvPolynomial.esymm_eq_multiset_esymm σ R, Finset.prod_eq_multiset_prod] convert Multiset.prod_X_add_C_eq_sum_esymm s simp_rw [s, Multiset.map_map, Function.comp_apply] theorem MvPolynomial.prod_X_add_C_coeff (k : ℕ) (h : k ≤ card σ) : (∏ i : σ, (Polynomial.X + Polynomial.C (MvPolynomial.X i)) : Polynomial _).coeff k = MvPolynomial.esymm σ R (card σ - k) := by let s := Finset.univ.val.map fun i => (MvPolynomial.X i : MvPolynomial σ R) have : Fintype.card σ = Multiset.card s := by rw [Multiset.card_map, ← Finset.card_univ, Finset.card_def] rw [this] at h ⊢ rw [MvPolynomial.esymm_eq_multiset_esymm σ R, Finset.prod_eq_multiset_prod] convert Multiset.prod_X_add_C_coeff s h dsimp simp_rw [s, Multiset.map_map, Function.comp_apply] end MvPolynomial
RingTheory\Polynomial\Wronskian.lean
/- Copyright (c) 2024 Jineon Back and Seewoo Lee. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jineon Baek, Seewoo Lee -/ import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.Derivative import Mathlib.LinearAlgebra.SesquilinearForm /-! # Wronskian of a pair of polynomial This file defines Wronskian of a pair of polynomials, which is `W(a, b) = ab' - a'b`. We also prove basic properties of it. ## Main declarations - `Polynomial.wronskian_eq_of_sum_zero`: We have `W(a, b) = W(b, c)` when `a + b + c = 0`. - `Polynomial.degree_wronskian_lt_add`: Degree of Wronskian `W(a, b)` is strictly smaller than the sum of degrees of `a` and `b` - `Polynomial.natDegree_wronskian_lt_add`: `natDegree` version of the above theorem. We need to assume that the Wronskian is nonzero. (Otherwise, `a = b = 1` gives a counterexample.) ## TODO - Define Wronskian for n-tuple of polynomials, not necessarily two. -/ noncomputable section open scoped Polynomial namespace Polynomial variable {R : Type*} [CommRing R] /-- Wronskian of a pair of polynomials, `W(a, b) = ab' - a'b`. -/ def wronskian (a b : R[X]) : R[X] := a * (derivative b) - (derivative a) * b variable (R) in /-- `Polynomial.wronskian` as a bilinear map. -/ def wronskianBilin : R[X] →ₗ[R] R[X] →ₗ[R] R[X] := (LinearMap.mul R R[X]).compl₂ derivative - (LinearMap.mul R R[X]).comp derivative @[simp] theorem wronskianBilin_apply (a b : R[X]) : wronskianBilin R a b = wronskian a b := rfl @[simp] theorem wronskian_zero_left (a : R[X]) : wronskian 0 a = 0 := by rw [← wronskianBilin_apply 0 a, map_zero]; rfl @[simp] theorem wronskian_zero_right (a : R[X]) : wronskian a 0 = 0 := (wronskianBilin R a).map_zero theorem wronskian_neg_left (a b : R[X]) : wronskian (-a) b = -wronskian a b := LinearMap.map_neg₂ (wronskianBilin R) a b theorem wronskian_neg_right (a b : R[X]) : wronskian a (-b) = -wronskian a b := (wronskianBilin R a).map_neg b theorem wronskian_add_right (a b c : R[X]) : wronskian a (b + c) = wronskian a b + wronskian a c := (wronskianBilin R a).map_add b c theorem wronskian_add_left (a b c : R[X]) : wronskian (a + b) c = wronskian a c + wronskian b c := (wronskianBilin R).map_add₂ a b c theorem wronskian_self_eq_zero (a : R[X]) : wronskian a a = 0 := by rw [wronskian, mul_comm, sub_self] theorem isAlt_wronskianBilin : (wronskianBilin R).IsAlt := wronskian_self_eq_zero theorem wronskian_neg_eq (a b : R[X]) : -wronskian a b = wronskian b a := LinearMap.IsAlt.neg isAlt_wronskianBilin a b theorem wronskian_eq_of_sum_zero {a b c : R[X]} (hAdd : a + b + c = 0) : wronskian a b = wronskian b c := isAlt_wronskianBilin.eq_of_add_add_eq_zero hAdd /-- Degree of `W(a,b)` is strictly less than the sum of degrees of `a` and `b` (both nonzero). -/ theorem degree_wronskian_lt_add {a b : R[X]} (ha : a ≠ 0) (hb : b ≠ 0) : (wronskian a b).degree < a.degree + b.degree := by calc (wronskian a b).degree ≤ max (a * derivative b).degree (derivative a * b).degree := Polynomial.degree_sub_le _ _ _ < a.degree + b.degree := by rw [max_lt_iff] constructor case left => apply lt_of_le_of_lt · exact degree_mul_le a (derivative b) · rw [← Polynomial.degree_ne_bot] at ha rw [WithBot.add_lt_add_iff_left ha] exact Polynomial.degree_derivative_lt hb case right => apply lt_of_le_of_lt · exact degree_mul_le (derivative a) b · rw [← Polynomial.degree_ne_bot] at hb rw [WithBot.add_lt_add_iff_right hb] exact Polynomial.degree_derivative_lt ha /-- `natDegree` version of the above theorem. Note this would be false with just `(ha : a ≠ 0) (hb : b ≠ 0), as when `a = b = 1` we have `(wronskian a b).natDegree = a.natDegree = b.natDegree = 0`. -/ theorem natDegree_wronskian_lt_add {a b : R[X]} (hw : wronskian a b ≠ 0) : (wronskian a b).natDegree < a.natDegree + b.natDegree := by have ha : a ≠ 0 := by intro h; subst h; rw [wronskian_zero_left] at hw; exact hw rfl have hb : b ≠ 0 := by intro h; subst h; rw [wronskian_zero_right] at hw; exact hw rfl rw [← WithBot.coe_lt_coe, WithBot.coe_add] convert ← degree_wronskian_lt_add ha hb · exact Polynomial.degree_eq_natDegree hw · exact Polynomial.degree_eq_natDegree ha · exact Polynomial.degree_eq_natDegree hb end Polynomial
RingTheory\Polynomial\Cyclotomic\Basic.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.Algebra.NeZero import Mathlib.Algebra.Polynomial.BigOperators import Mathlib.Algebra.Polynomial.Lifts import Mathlib.Algebra.Polynomial.Splits import Mathlib.RingTheory.RootsOfUnity.Complex import Mathlib.NumberTheory.ArithmeticFunction import Mathlib.RingTheory.RootsOfUnity.Basic import Mathlib.FieldTheory.RatFunc.AsPolynomial /-! # Cyclotomic polynomials. For `n : ℕ` and an integral domain `R`, we define a modified version of the `n`-th cyclotomic polynomial with coefficients in `R`, denoted `cyclotomic' n R`, as `∏ (X - μ)`, where `μ` varies over the primitive `n`th roots of unity. If there is a primitive `n`th root of unity in `R` then this the standard definition. We then define the standard cyclotomic polynomial `cyclotomic n R` with coefficients in any ring `R`. ## Main definition * `cyclotomic n R` : the `n`-th cyclotomic polynomial with coefficients in `R`. ## Main results * `Polynomial.degree_cyclotomic` : The degree of `cyclotomic n` is `totient n`. * `Polynomial.prod_cyclotomic_eq_X_pow_sub_one` : `X ^ n - 1 = ∏ (cyclotomic i)`, where `i` divides `n`. * `Polynomial.cyclotomic_eq_prod_X_pow_sub_one_pow_moebius` : The Möbius inversion formula for `cyclotomic n R` over an abstract fraction field for `R[X]`. ## Implementation details Our definition of `cyclotomic' n R` makes sense in any integral domain `R`, but the interesting results hold if there is a primitive `n`-th root of unity in `R`. In particular, our definition is not the standard one unless there is a primitive `n`th root of unity in `R`. For example, `cyclotomic' 3 ℤ = 1`, since there are no primitive cube roots of unity in `ℤ`. The main example is `R = ℂ`, we decided to work in general since the difficulties are essentially the same. To get the standard cyclotomic polynomials, we use `unique_int_coeff_of_cycl`, with `R = ℂ`, to get a polynomial with integer coefficients and then we map it to `R[X]`, for any ring `R`. -/ open scoped Polynomial noncomputable section universe u namespace Polynomial section Cyclotomic' section IsDomain variable {R : Type*} [CommRing R] [IsDomain R] /-- The modified `n`-th cyclotomic polynomial with coefficients in `R`, it is the usual cyclotomic polynomial if there is a primitive `n`-th root of unity in `R`. -/ def cyclotomic' (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] : R[X] := ∏ μ ∈ primitiveRoots n R, (X - C μ) /-- The zeroth modified cyclotomic polyomial is `1`. -/ @[simp] theorem cyclotomic'_zero (R : Type*) [CommRing R] [IsDomain R] : cyclotomic' 0 R = 1 := by simp only [cyclotomic', Finset.prod_empty, primitiveRoots_zero] /-- The first modified cyclotomic polyomial is `X - 1`. -/ @[simp] theorem cyclotomic'_one (R : Type*) [CommRing R] [IsDomain R] : cyclotomic' 1 R = X - 1 := by simp only [cyclotomic', Finset.prod_singleton, RingHom.map_one, IsPrimitiveRoot.primitiveRoots_one] /-- The second modified cyclotomic polyomial is `X + 1` if the characteristic of `R` is not `2`. -/ @[simp] theorem cyclotomic'_two (R : Type*) [CommRing R] [IsDomain R] (p : ℕ) [CharP R p] (hp : p ≠ 2) : cyclotomic' 2 R = X + 1 := by rw [cyclotomic'] have prim_root_two : primitiveRoots 2 R = {(-1 : R)} := by simp only [Finset.eq_singleton_iff_unique_mem, mem_primitiveRoots two_pos] exact ⟨IsPrimitiveRoot.neg_one p hp, fun x => IsPrimitiveRoot.eq_neg_one_of_two_right⟩ simp only [prim_root_two, Finset.prod_singleton, RingHom.map_neg, RingHom.map_one, sub_neg_eq_add] /-- `cyclotomic' n R` is monic. -/ theorem cyclotomic'.monic (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] : (cyclotomic' n R).Monic := monic_prod_of_monic _ _ fun _ _ => monic_X_sub_C _ /-- `cyclotomic' n R` is different from `0`. -/ theorem cyclotomic'_ne_zero (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] : cyclotomic' n R ≠ 0 := (cyclotomic'.monic n R).ne_zero /-- The natural degree of `cyclotomic' n R` is `totient n` if there is a primitive root of unity in `R`. -/ theorem natDegree_cyclotomic' {ζ : R} {n : ℕ} (h : IsPrimitiveRoot ζ n) : (cyclotomic' n R).natDegree = Nat.totient n := by rw [cyclotomic'] rw [natDegree_prod (primitiveRoots n R) fun z : R => X - C z] · simp only [IsPrimitiveRoot.card_primitiveRoots h, mul_one, natDegree_X_sub_C, Nat.cast_id, Finset.sum_const, nsmul_eq_mul] intro z _ exact X_sub_C_ne_zero z /-- The degree of `cyclotomic' n R` is `totient n` if there is a primitive root of unity in `R`. -/ theorem degree_cyclotomic' {ζ : R} {n : ℕ} (h : IsPrimitiveRoot ζ n) : (cyclotomic' n R).degree = Nat.totient n := by simp only [degree_eq_natDegree (cyclotomic'_ne_zero n R), natDegree_cyclotomic' h] /-- The roots of `cyclotomic' n R` are the primitive `n`-th roots of unity. -/ theorem roots_of_cyclotomic (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] : (cyclotomic' n R).roots = (primitiveRoots n R).val := by rw [cyclotomic']; exact roots_prod_X_sub_C (primitiveRoots n R) /-- If there is a primitive `n`th root of unity in `K`, then `X ^ n - 1 = ∏ (X - μ)`, where `μ` varies over the `n`-th roots of unity. -/ theorem X_pow_sub_one_eq_prod {ζ : R} {n : ℕ} (hpos : 0 < n) (h : IsPrimitiveRoot ζ n) : X ^ n - 1 = ∏ ζ ∈ nthRootsFinset n R, (X - C ζ) := by classical rw [nthRootsFinset, ← Multiset.toFinset_eq (IsPrimitiveRoot.nthRoots_one_nodup h)] simp only [Finset.prod_mk, RingHom.map_one] rw [nthRoots] have hmonic : (X ^ n - C (1 : R)).Monic := monic_X_pow_sub_C (1 : R) (ne_of_lt hpos).symm symm apply prod_multiset_X_sub_C_of_monic_of_roots_card_eq hmonic rw [@natDegree_X_pow_sub_C R _ _ n 1, ← nthRoots] exact IsPrimitiveRoot.card_nthRoots_one h end IsDomain section Field variable {K : Type*} [Field K] /-- `cyclotomic' n K` splits. -/ theorem cyclotomic'_splits (n : ℕ) : Splits (RingHom.id K) (cyclotomic' n K) := by apply splits_prod (RingHom.id K) intro z _ simp only [splits_X_sub_C (RingHom.id K)] /-- If there is a primitive `n`-th root of unity in `K`, then `X ^ n - 1` splits. -/ theorem X_pow_sub_one_splits {ζ : K} {n : ℕ} (h : IsPrimitiveRoot ζ n) : Splits (RingHom.id K) (X ^ n - C (1 : K)) := by rw [splits_iff_card_roots, ← nthRoots, IsPrimitiveRoot.card_nthRoots_one h, natDegree_X_pow_sub_C] /-- If there is a primitive `n`-th root of unity in `K`, then `∏ i ∈ Nat.divisors n, cyclotomic' i K = X ^ n - 1`. -/ theorem prod_cyclotomic'_eq_X_pow_sub_one {K : Type*} [CommRing K] [IsDomain K] {ζ : K} {n : ℕ} (hpos : 0 < n) (h : IsPrimitiveRoot ζ n) : ∏ i ∈ Nat.divisors n, cyclotomic' i K = X ^ n - 1 := by classical have hd : (n.divisors : Set ℕ).PairwiseDisjoint fun k => primitiveRoots k K := fun x _ y _ hne => IsPrimitiveRoot.disjoint hne simp only [X_pow_sub_one_eq_prod hpos h, cyclotomic', ← Finset.prod_biUnion hd, h.nthRoots_one_eq_biUnion_primitiveRoots] /-- If there is a primitive `n`-th root of unity in `K`, then `cyclotomic' n K = (X ^ k - 1) /ₘ (∏ i ∈ Nat.properDivisors k, cyclotomic' i K)`. -/ theorem cyclotomic'_eq_X_pow_sub_one_div {K : Type*} [CommRing K] [IsDomain K] {ζ : K} {n : ℕ} (hpos : 0 < n) (h : IsPrimitiveRoot ζ n) : cyclotomic' n K = (X ^ n - 1) /ₘ ∏ i ∈ Nat.properDivisors n, cyclotomic' i K := by rw [← prod_cyclotomic'_eq_X_pow_sub_one hpos h, ← Nat.cons_self_properDivisors hpos.ne', Finset.prod_cons] have prod_monic : (∏ i ∈ Nat.properDivisors n, cyclotomic' i K).Monic := by apply monic_prod_of_monic intro i _ exact cyclotomic'.monic i K rw [(div_modByMonic_unique (cyclotomic' n K) 0 prod_monic _).1] simp only [degree_zero, zero_add] refine ⟨by rw [mul_comm], ?_⟩ rw [bot_lt_iff_ne_bot] intro h exact Monic.ne_zero prod_monic (degree_eq_bot.1 h) /-- If there is a primitive `n`-th root of unity in `K`, then `cyclotomic' n K` comes from a monic polynomial with integer coefficients. -/ theorem int_coeff_of_cyclotomic' {K : Type*} [CommRing K] [IsDomain K] {ζ : K} {n : ℕ} (h : IsPrimitiveRoot ζ n) : ∃ P : ℤ[X], map (Int.castRingHom K) P = cyclotomic' n K ∧ P.degree = (cyclotomic' n K).degree ∧ P.Monic := by refine lifts_and_degree_eq_and_monic ?_ (cyclotomic'.monic n K) induction' n using Nat.strong_induction_on with k ihk generalizing ζ rcases k.eq_zero_or_pos with (rfl | hpos) · use 1 simp only [cyclotomic'_zero, coe_mapRingHom, Polynomial.map_one] let B : K[X] := ∏ i ∈ Nat.properDivisors k, cyclotomic' i K have Bmo : B.Monic := by apply monic_prod_of_monic intro i _ exact cyclotomic'.monic i K have Bint : B ∈ lifts (Int.castRingHom K) := by refine Subsemiring.prod_mem (lifts (Int.castRingHom K)) ?_ intro x hx have xsmall := (Nat.mem_properDivisors.1 hx).2 obtain ⟨d, hd⟩ := (Nat.mem_properDivisors.1 hx).1 rw [mul_comm] at hd exact ihk x xsmall (h.pow hpos hd) replace Bint := lifts_and_degree_eq_and_monic Bint Bmo obtain ⟨B₁, hB₁, _, hB₁mo⟩ := Bint let Q₁ : ℤ[X] := (X ^ k - 1) /ₘ B₁ have huniq : 0 + B * cyclotomic' k K = X ^ k - 1 ∧ (0 : K[X]).degree < B.degree := by constructor · rw [zero_add, mul_comm, ← prod_cyclotomic'_eq_X_pow_sub_one hpos h, ← Nat.cons_self_properDivisors hpos.ne', Finset.prod_cons] · simpa only [degree_zero, bot_lt_iff_ne_bot, Ne, degree_eq_bot] using Bmo.ne_zero replace huniq := div_modByMonic_unique (cyclotomic' k K) (0 : K[X]) Bmo huniq simp only [lifts, RingHom.mem_rangeS] use Q₁ rw [coe_mapRingHom, map_divByMonic (Int.castRingHom K) hB₁mo, hB₁, ← huniq.1] simp /-- If `K` is of characteristic `0` and there is a primitive `n`-th root of unity in `K`, then `cyclotomic n K` comes from a unique polynomial with integer coefficients. -/ theorem unique_int_coeff_of_cycl {K : Type*} [CommRing K] [IsDomain K] [CharZero K] {ζ : K} {n : ℕ+} (h : IsPrimitiveRoot ζ n) : ∃! P : ℤ[X], map (Int.castRingHom K) P = cyclotomic' n K := by obtain ⟨P, hP⟩ := int_coeff_of_cyclotomic' h refine ⟨P, hP.1, fun Q hQ => ?_⟩ apply map_injective (Int.castRingHom K) Int.cast_injective rw [hP.1, hQ] end Field end Cyclotomic' section Cyclotomic /-- The `n`-th cyclotomic polynomial with coefficients in `R`. -/ def cyclotomic (n : ℕ) (R : Type*) [Ring R] : R[X] := if h : n = 0 then 1 else map (Int.castRingHom R) (int_coeff_of_cyclotomic' (Complex.isPrimitiveRoot_exp n h)).choose theorem int_cyclotomic_rw {n : ℕ} (h : n ≠ 0) : cyclotomic n ℤ = (int_coeff_of_cyclotomic' (Complex.isPrimitiveRoot_exp n h)).choose := by simp only [cyclotomic, h, dif_neg, not_false_iff] ext i simp only [coeff_map, Int.cast_id, eq_intCast] /-- `cyclotomic n R` comes from `cyclotomic n ℤ`. -/ theorem map_cyclotomic_int (n : ℕ) (R : Type*) [Ring R] : map (Int.castRingHom R) (cyclotomic n ℤ) = cyclotomic n R := by by_cases hzero : n = 0 · simp only [hzero, cyclotomic, dif_pos, Polynomial.map_one] simp [cyclotomic, hzero] theorem int_cyclotomic_spec (n : ℕ) : map (Int.castRingHom ℂ) (cyclotomic n ℤ) = cyclotomic' n ℂ ∧ (cyclotomic n ℤ).degree = (cyclotomic' n ℂ).degree ∧ (cyclotomic n ℤ).Monic := by by_cases hzero : n = 0 · simp only [hzero, cyclotomic, degree_one, monic_one, cyclotomic'_zero, dif_pos, eq_self_iff_true, Polynomial.map_one, and_self_iff] rw [int_cyclotomic_rw hzero] exact (int_coeff_of_cyclotomic' (Complex.isPrimitiveRoot_exp n hzero)).choose_spec theorem int_cyclotomic_unique {n : ℕ} {P : ℤ[X]} (h : map (Int.castRingHom ℂ) P = cyclotomic' n ℂ) : P = cyclotomic n ℤ := by apply map_injective (Int.castRingHom ℂ) Int.cast_injective rw [h, (int_cyclotomic_spec n).1] /-- The definition of `cyclotomic n R` commutes with any ring homomorphism. -/ @[simp] theorem map_cyclotomic (n : ℕ) {R S : Type*} [Ring R] [Ring S] (f : R →+* S) : map f (cyclotomic n R) = cyclotomic n S := by rw [← map_cyclotomic_int n R, ← map_cyclotomic_int n S, map_map] have : Subsingleton (ℤ →+* S) := inferInstance congr! theorem cyclotomic.eval_apply {R S : Type*} (q : R) (n : ℕ) [Ring R] [Ring S] (f : R →+* S) : eval (f q) (cyclotomic n S) = f (eval q (cyclotomic n R)) := by rw [← map_cyclotomic n f, eval_map, eval₂_at_apply] /-- The zeroth cyclotomic polyomial is `1`. -/ @[simp] theorem cyclotomic_zero (R : Type*) [Ring R] : cyclotomic 0 R = 1 := by simp only [cyclotomic, dif_pos] /-- The first cyclotomic polyomial is `X - 1`. -/ @[simp] theorem cyclotomic_one (R : Type*) [Ring R] : cyclotomic 1 R = X - 1 := by have hspec : map (Int.castRingHom ℂ) (X - 1) = cyclotomic' 1 ℂ := by simp only [cyclotomic'_one, PNat.one_coe, map_X, Polynomial.map_one, Polynomial.map_sub] symm rw [← map_cyclotomic_int, ← int_cyclotomic_unique hspec] simp only [map_X, Polynomial.map_one, Polynomial.map_sub] /-- `cyclotomic n` is monic. -/ theorem cyclotomic.monic (n : ℕ) (R : Type*) [Ring R] : (cyclotomic n R).Monic := by rw [← map_cyclotomic_int] exact (int_cyclotomic_spec n).2.2.map _ /-- `cyclotomic n` is primitive. -/ theorem cyclotomic.isPrimitive (n : ℕ) (R : Type*) [CommRing R] : (cyclotomic n R).IsPrimitive := (cyclotomic.monic n R).isPrimitive /-- `cyclotomic n R` is different from `0`. -/ theorem cyclotomic_ne_zero (n : ℕ) (R : Type*) [Ring R] [Nontrivial R] : cyclotomic n R ≠ 0 := (cyclotomic.monic n R).ne_zero /-- The degree of `cyclotomic n` is `totient n`. -/ theorem degree_cyclotomic (n : ℕ) (R : Type*) [Ring R] [Nontrivial R] : (cyclotomic n R).degree = Nat.totient n := by rw [← map_cyclotomic_int] rw [degree_map_eq_of_leadingCoeff_ne_zero (Int.castRingHom R) _] · cases' n with k · simp only [cyclotomic, degree_one, dif_pos, Nat.totient_zero, CharP.cast_eq_zero] rw [← degree_cyclotomic' (Complex.isPrimitiveRoot_exp k.succ (Nat.succ_ne_zero k))] exact (int_cyclotomic_spec k.succ).2.1 simp only [(int_cyclotomic_spec n).right.right, eq_intCast, Monic.leadingCoeff, Int.cast_one, Ne, not_false_iff, one_ne_zero] /-- The natural degree of `cyclotomic n` is `totient n`. -/ theorem natDegree_cyclotomic (n : ℕ) (R : Type*) [Ring R] [Nontrivial R] : (cyclotomic n R).natDegree = Nat.totient n := by rw [natDegree, degree_cyclotomic]; norm_cast /-- The degree of `cyclotomic n R` is positive. -/ theorem degree_cyclotomic_pos (n : ℕ) (R : Type*) (hpos : 0 < n) [Ring R] [Nontrivial R] : 0 < (cyclotomic n R).degree := by rwa [degree_cyclotomic n R, Nat.cast_pos, Nat.totient_pos] open Finset /-- `∏ i ∈ Nat.divisors n, cyclotomic i R = X ^ n - 1`. -/ theorem prod_cyclotomic_eq_X_pow_sub_one {n : ℕ} (hpos : 0 < n) (R : Type*) [CommRing R] : ∏ i ∈ Nat.divisors n, cyclotomic i R = X ^ n - 1 := by have integer : ∏ i ∈ Nat.divisors n, cyclotomic i ℤ = X ^ n - 1 := by apply map_injective (Int.castRingHom ℂ) Int.cast_injective simp only [Polynomial.map_prod, int_cyclotomic_spec, Polynomial.map_pow, map_X, Polynomial.map_one, Polynomial.map_sub] exact prod_cyclotomic'_eq_X_pow_sub_one hpos (Complex.isPrimitiveRoot_exp n hpos.ne') simpa only [Polynomial.map_prod, map_cyclotomic_int, Polynomial.map_sub, Polynomial.map_one, Polynomial.map_pow, Polynomial.map_X] using congr_arg (map (Int.castRingHom R)) integer theorem cyclotomic.dvd_X_pow_sub_one (n : ℕ) (R : Type*) [Ring R] : cyclotomic n R ∣ X ^ n - 1 := by suffices cyclotomic n ℤ ∣ X ^ n - 1 by simpa only [map_cyclotomic_int, Polynomial.map_sub, Polynomial.map_one, Polynomial.map_pow, Polynomial.map_X] using map_dvd (Int.castRingHom R) this rcases n.eq_zero_or_pos with (rfl | hn) · simp rw [← prod_cyclotomic_eq_X_pow_sub_one hn] exact Finset.dvd_prod_of_mem _ (n.mem_divisors_self hn.ne') theorem prod_cyclotomic_eq_geom_sum {n : ℕ} (h : 0 < n) (R) [CommRing R] : ∏ i ∈ n.divisors.erase 1, cyclotomic i R = ∑ i ∈ Finset.range n, X ^ i := by suffices (∏ i ∈ n.divisors.erase 1, cyclotomic i ℤ) = ∑ i ∈ Finset.range n, X ^ i by simpa only [Polynomial.map_prod, map_cyclotomic_int, Polynomial.map_sum, Polynomial.map_pow, Polynomial.map_X] using congr_arg (map (Int.castRingHom R)) this rw [← mul_left_inj' (cyclotomic_ne_zero 1 ℤ), prod_erase_mul _ _ (Nat.one_mem_divisors.2 h.ne'), cyclotomic_one, geom_sum_mul, prod_cyclotomic_eq_X_pow_sub_one h] /-- If `p` is prime, then `cyclotomic p R = ∑ i ∈ range p, X ^ i`. -/ theorem cyclotomic_prime (R : Type*) [Ring R] (p : ℕ) [hp : Fact p.Prime] : cyclotomic p R = ∑ i ∈ Finset.range p, X ^ i := by suffices cyclotomic p ℤ = ∑ i ∈ range p, X ^ i by simpa only [map_cyclotomic_int, Polynomial.map_sum, Polynomial.map_pow, Polynomial.map_X] using congr_arg (map (Int.castRingHom R)) this rw [← prod_cyclotomic_eq_geom_sum hp.out.pos, hp.out.divisors, erase_insert (mem_singleton.not.2 hp.out.ne_one.symm), prod_singleton] theorem cyclotomic_prime_mul_X_sub_one (R : Type*) [Ring R] (p : ℕ) [hn : Fact (Nat.Prime p)] : cyclotomic p R * (X - 1) = X ^ p - 1 := by rw [cyclotomic_prime, geom_sum_mul] @[simp] theorem cyclotomic_two (R : Type*) [Ring R] : cyclotomic 2 R = X + 1 := by simp [cyclotomic_prime] @[simp] theorem cyclotomic_three (R : Type*) [Ring R] : cyclotomic 3 R = X ^ 2 + X + 1 := by simp [cyclotomic_prime, sum_range_succ'] theorem cyclotomic_dvd_geom_sum_of_dvd (R) [Ring R] {d n : ℕ} (hdn : d ∣ n) (hd : d ≠ 1) : cyclotomic d R ∣ ∑ i ∈ Finset.range n, X ^ i := by suffices cyclotomic d ℤ ∣ ∑ i ∈ Finset.range n, X ^ i by simpa only [map_cyclotomic_int, Polynomial.map_sum, Polynomial.map_pow, Polynomial.map_X] using map_dvd (Int.castRingHom R) this rcases n.eq_zero_or_pos with (rfl | hn) · simp rw [← prod_cyclotomic_eq_geom_sum hn] apply Finset.dvd_prod_of_mem simp [hd, hdn, hn.ne'] theorem X_pow_sub_one_mul_prod_cyclotomic_eq_X_pow_sub_one_of_dvd (R) [CommRing R] {d n : ℕ} (h : d ∈ n.properDivisors) : ((X ^ d - 1) * ∏ x ∈ n.divisors \ d.divisors, cyclotomic x R) = X ^ n - 1 := by obtain ⟨hd, hdn⟩ := Nat.mem_properDivisors.mp h have h0n : 0 < n := pos_of_gt hdn have h0d : 0 < d := Nat.pos_of_dvd_of_pos hd h0n rw [← prod_cyclotomic_eq_X_pow_sub_one h0d, ← prod_cyclotomic_eq_X_pow_sub_one h0n, mul_comm, Finset.prod_sdiff (Nat.divisors_subset_of_dvd h0n.ne' hd)] theorem X_pow_sub_one_mul_cyclotomic_dvd_X_pow_sub_one_of_dvd (R) [CommRing R] {d n : ℕ} (h : d ∈ n.properDivisors) : (X ^ d - 1) * cyclotomic n R ∣ X ^ n - 1 := by have hdn := (Nat.mem_properDivisors.mp h).2 use ∏ x ∈ n.properDivisors \ d.divisors, cyclotomic x R symm convert X_pow_sub_one_mul_prod_cyclotomic_eq_X_pow_sub_one_of_dvd R h using 1 rw [mul_assoc] congr 1 rw [← Nat.insert_self_properDivisors hdn.ne_bot, insert_sdiff_of_not_mem, prod_insert] · exact Finset.not_mem_sdiff_of_not_mem_left Nat.properDivisors.not_self_mem · exact fun hk => hdn.not_le <| Nat.divisor_le hk section ArithmeticFunction open ArithmeticFunction open scoped ArithmeticFunction /-- `cyclotomic n R` can be expressed as a product in a fraction field of `R[X]` using Möbius inversion. -/ theorem cyclotomic_eq_prod_X_pow_sub_one_pow_moebius {n : ℕ} (R : Type*) [CommRing R] [IsDomain R] : algebraMap _ (RatFunc R) (cyclotomic n R) = ∏ i ∈ n.divisorsAntidiagonal, algebraMap R[X] _ (X ^ i.snd - 1) ^ μ i.fst := by rcases n.eq_zero_or_pos with (rfl | hpos) · simp have h : ∀ n : ℕ, 0 < n → (∏ i ∈ Nat.divisors n, algebraMap _ (RatFunc R) (cyclotomic i R)) = algebraMap _ _ (X ^ n - 1 : R[X]) := by intro n hn rw [← prod_cyclotomic_eq_X_pow_sub_one hn R, map_prod] rw [(prod_eq_iff_prod_pow_moebius_eq_of_nonzero (fun n hn => _) fun n hn => _).1 h n hpos] <;> simp_rw [Ne, IsFractionRing.to_map_eq_zero_iff] · simp [cyclotomic_ne_zero] · intro n hn apply Monic.ne_zero apply monic_X_pow_sub_C _ (ne_of_gt hn) end ArithmeticFunction /-- We have `cyclotomic n R = (X ^ k - 1) /ₘ (∏ i ∈ Nat.properDivisors k, cyclotomic i K)`. -/ theorem cyclotomic_eq_X_pow_sub_one_div {R : Type*} [CommRing R] {n : ℕ} (hpos : 0 < n) : cyclotomic n R = (X ^ n - 1) /ₘ ∏ i ∈ Nat.properDivisors n, cyclotomic i R := by nontriviality R rw [← prod_cyclotomic_eq_X_pow_sub_one hpos, ← Nat.cons_self_properDivisors hpos.ne', Finset.prod_cons] have prod_monic : (∏ i ∈ Nat.properDivisors n, cyclotomic i R).Monic := by apply monic_prod_of_monic intro i _ exact cyclotomic.monic i R rw [(div_modByMonic_unique (cyclotomic n R) 0 prod_monic _).1] simp only [degree_zero, zero_add] constructor · rw [mul_comm] rw [bot_lt_iff_ne_bot] intro h exact Monic.ne_zero prod_monic (degree_eq_bot.1 h) /-- If `m` is a proper divisor of `n`, then `X ^ m - 1` divides `∏ i ∈ Nat.properDivisors n, cyclotomic i R`. -/ theorem X_pow_sub_one_dvd_prod_cyclotomic (R : Type*) [CommRing R] {n m : ℕ} (hpos : 0 < n) (hm : m ∣ n) (hdiff : m ≠ n) : X ^ m - 1 ∣ ∏ i ∈ Nat.properDivisors n, cyclotomic i R := by replace hm := Nat.mem_properDivisors.2 ⟨hm, lt_of_le_of_ne (Nat.divisor_le (Nat.mem_divisors.2 ⟨hm, hpos.ne'⟩)) hdiff⟩ rw [← Finset.sdiff_union_of_subset (Nat.divisors_subset_properDivisors (ne_of_lt hpos).symm (Nat.mem_properDivisors.1 hm).1 (ne_of_lt (Nat.mem_properDivisors.1 hm).2)), Finset.prod_union Finset.sdiff_disjoint, prod_cyclotomic_eq_X_pow_sub_one (Nat.pos_of_mem_properDivisors hm)] exact ⟨∏ x ∈ n.properDivisors \ m.divisors, cyclotomic x R, by rw [mul_comm]⟩ /-- If there is a primitive `n`-th root of unity in `K`, then `cyclotomic n K = ∏ μ ∈ primitiveRoots n K, (X - C μ)`. ∈ particular, `cyclotomic n K = cyclotomic' n K` -/ theorem cyclotomic_eq_prod_X_sub_primitiveRoots {K : Type*} [CommRing K] [IsDomain K] {ζ : K} {n : ℕ} (hz : IsPrimitiveRoot ζ n) : cyclotomic n K = ∏ μ ∈ primitiveRoots n K, (X - C μ) := by rw [← cyclotomic'] induction' n using Nat.strong_induction_on with k hk generalizing ζ obtain hzero | hpos := k.eq_zero_or_pos · simp only [hzero, cyclotomic'_zero, cyclotomic_zero] have h : ∀ i ∈ k.properDivisors, cyclotomic i K = cyclotomic' i K := by intro i hi obtain ⟨d, hd⟩ := (Nat.mem_properDivisors.1 hi).1 rw [mul_comm] at hd exact hk i (Nat.mem_properDivisors.1 hi).2 (IsPrimitiveRoot.pow hpos hz hd) rw [@cyclotomic_eq_X_pow_sub_one_div _ _ _ hpos, cyclotomic'_eq_X_pow_sub_one_div hpos hz, Finset.prod_congr (refl k.properDivisors) h] theorem eq_cyclotomic_iff {R : Type*} [CommRing R] {n : ℕ} (hpos : 0 < n) (P : R[X]) : P = cyclotomic n R ↔ (P * ∏ i ∈ Nat.properDivisors n, Polynomial.cyclotomic i R) = X ^ n - 1 := by nontriviality R refine ⟨fun hcycl => ?_, fun hP => ?_⟩ · rw [hcycl, ← prod_cyclotomic_eq_X_pow_sub_one hpos R, ← Nat.cons_self_properDivisors hpos.ne', Finset.prod_cons] · have prod_monic : (∏ i ∈ Nat.properDivisors n, cyclotomic i R).Monic := by apply monic_prod_of_monic intro i _ exact cyclotomic.monic i R rw [@cyclotomic_eq_X_pow_sub_one_div R _ _ hpos, (div_modByMonic_unique P 0 prod_monic _).1] refine ⟨by rwa [zero_add, mul_comm], ?_⟩ rw [degree_zero, bot_lt_iff_ne_bot] intro h exact Monic.ne_zero prod_monic (degree_eq_bot.1 h) /-- If `p ^ k` is a prime power, then `cyclotomic (p ^ (n + 1)) R = ∑ i ∈ range p, (X ^ (p ^ n)) ^ i`. -/ theorem cyclotomic_prime_pow_eq_geom_sum {R : Type*} [CommRing R] {p n : ℕ} (hp : p.Prime) : cyclotomic (p ^ (n + 1)) R = ∑ i ∈ Finset.range p, (X ^ p ^ n) ^ i := by have : ∀ m, (cyclotomic (p ^ (m + 1)) R = ∑ i ∈ Finset.range p, (X ^ p ^ m) ^ i) ↔ ((∑ i ∈ Finset.range p, (X ^ p ^ m) ^ i) * ∏ x ∈ Finset.range (m + 1), cyclotomic (p ^ x) R) = X ^ p ^ (m + 1) - 1 := by intro m have := eq_cyclotomic_iff (R := R) (P := ∑ i ∈ range p, (X ^ p ^ m) ^ i) (pow_pos hp.pos (m + 1)) rw [eq_comm] at this rw [this, Nat.prod_properDivisors_prime_pow hp] induction' n with n_n n_ih · haveI := Fact.mk hp; simp [cyclotomic_prime] rw [((eq_cyclotomic_iff (pow_pos hp.pos (n_n + 1 + 1)) _).mpr _).symm] rw [Nat.prod_properDivisors_prime_pow hp, Finset.prod_range_succ, n_ih] rw [this] at n_ih rw [mul_comm _ (∑ i ∈ _, _), n_ih, geom_sum_mul, sub_left_inj, ← pow_mul] simp only [pow_add, pow_one] theorem cyclotomic_prime_pow_mul_X_pow_sub_one (R : Type*) [CommRing R] (p k : ℕ) [hn : Fact (Nat.Prime p)] : cyclotomic (p ^ (k + 1)) R * (X ^ p ^ k - 1) = X ^ p ^ (k + 1) - 1 := by rw [cyclotomic_prime_pow_eq_geom_sum hn.out, geom_sum_mul, ← pow_mul, pow_succ, mul_comm] /-- The constant term of `cyclotomic n R` is `1` if `2 ≤ n`. -/ theorem cyclotomic_coeff_zero (R : Type*) [CommRing R] {n : ℕ} (hn : 1 < n) : (cyclotomic n R).coeff 0 = 1 := by induction' n using Nat.strong_induction_on with n hi have hprod : (∏ i ∈ Nat.properDivisors n, (Polynomial.cyclotomic i R).coeff 0) = -1 := by rw [← Finset.insert_erase (Nat.one_mem_properDivisors_iff_one_lt.2 (lt_of_lt_of_le one_lt_two hn)), Finset.prod_insert (Finset.not_mem_erase 1 _), cyclotomic_one R] have hleq : ∀ j ∈ n.properDivisors.erase 1, 2 ≤ j := by intro j hj apply Nat.succ_le_of_lt exact (Ne.le_iff_lt (Finset.mem_erase.1 hj).1.symm).mp (Nat.succ_le_of_lt (Nat.pos_of_mem_properDivisors (Finset.mem_erase.1 hj).2)) have hcongr : ∀ j ∈ n.properDivisors.erase 1, (cyclotomic j R).coeff 0 = 1 := by intro j hj exact hi j (Nat.mem_properDivisors.1 (Finset.mem_erase.1 hj).2).2 (hleq j hj) have hrw : (∏ x ∈ n.properDivisors.erase 1, (cyclotomic x R).coeff 0) = 1 := by rw [Finset.prod_congr (refl (n.properDivisors.erase 1)) hcongr] simp only [Finset.prod_const_one] simp only [hrw, mul_one, zero_sub, coeff_one_zero, coeff_X_zero, coeff_sub] have heq : (X ^ n - 1 : R[X]).coeff 0 = -(cyclotomic n R).coeff 0 := by rw [← prod_cyclotomic_eq_X_pow_sub_one (zero_le_one.trans_lt hn), ← Nat.cons_self_properDivisors hn.ne_bot, Finset.prod_cons, mul_coeff_zero, coeff_zero_prod, hprod, mul_neg, mul_one] have hzero : (X ^ n - 1 : R[X]).coeff 0 = (-1 : R) := by rw [coeff_zero_eq_eval_zero _] simp only [zero_pow (by positivity : n ≠ 0), eval_X, eval_one, zero_sub, eval_pow, eval_sub] rw [hzero] at heq exact neg_inj.mp (Eq.symm heq) /-- If `(a : ℕ)` is a root of `cyclotomic n (ZMod p)`, where `p` is a prime, then `a` and `p` are coprime. -/ theorem coprime_of_root_cyclotomic {n : ℕ} (hpos : 0 < n) {p : ℕ} [hprime : Fact p.Prime] {a : ℕ} (hroot : IsRoot (cyclotomic n (ZMod p)) (Nat.castRingHom (ZMod p) a)) : a.Coprime p := by apply Nat.Coprime.symm rw [hprime.1.coprime_iff_not_dvd] intro h replace h := (ZMod.natCast_zmod_eq_zero_iff_dvd a p).2 h rw [IsRoot.def, eq_natCast, h, ← coeff_zero_eq_eval_zero] at hroot by_cases hone : n = 1 · simp only [hone, cyclotomic_one, zero_sub, coeff_one_zero, coeff_X_zero, neg_eq_zero, one_ne_zero, coeff_sub] at hroot rw [cyclotomic_coeff_zero (ZMod p) (Nat.succ_le_of_lt (lt_of_le_of_ne (Nat.succ_le_of_lt hpos) (Ne.symm hone)))] at hroot exact one_ne_zero hroot end Cyclotomic section Order /-- If `(a : ℕ)` is a root of `cyclotomic n (ZMod p)`, then the multiplicative order of `a` modulo `p` divides `n`. -/ theorem orderOf_root_cyclotomic_dvd {n : ℕ} (hpos : 0 < n) {p : ℕ} [Fact p.Prime] {a : ℕ} (hroot : IsRoot (cyclotomic n (ZMod p)) (Nat.castRingHom (ZMod p) a)) : orderOf (ZMod.unitOfCoprime a (coprime_of_root_cyclotomic hpos hroot)) ∣ n := by apply orderOf_dvd_of_pow_eq_one suffices hpow : eval (Nat.castRingHom (ZMod p) a) (X ^ n - 1 : (ZMod p)[X]) = 0 by simp only [eval_X, eval_one, eval_pow, eval_sub, eq_natCast] at hpow apply Units.val_eq_one.1 simp only [sub_eq_zero.mp hpow, ZMod.coe_unitOfCoprime, Units.val_pow_eq_pow_val] rw [IsRoot.def] at hroot rw [← prod_cyclotomic_eq_X_pow_sub_one hpos (ZMod p), ← Nat.cons_self_properDivisors hpos.ne', Finset.prod_cons, eval_mul, hroot, zero_mul] end Order end Polynomial
RingTheory\Polynomial\Cyclotomic\Eval.lean
/- Copyright (c) 2021 Eric Rodriguez. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Rodriguez -/ import Mathlib.RingTheory.Polynomial.Cyclotomic.Roots import Mathlib.Tactic.ByContra import Mathlib.Topology.Algebra.Polynomial import Mathlib.NumberTheory.Padics.PadicVal import Mathlib.Analysis.Complex.Arg /-! # Evaluating cyclotomic polynomials This file states some results about evaluating cyclotomic polynomials in various different ways. ## Main definitions * `Polynomial.eval(₂)_one_cyclotomic_prime(_pow)`: `eval 1 (cyclotomic p^k R) = p`. * `Polynomial.eval_one_cyclotomic_not_prime_pow`: Otherwise, `eval 1 (cyclotomic n R) = 1`. * `Polynomial.cyclotomic_pos` : `∀ x, 0 < eval x (cyclotomic n R)` if `2 < n`. -/ namespace Polynomial open Finset Nat @[simp] theorem eval_one_cyclotomic_prime {R : Type*} [CommRing R] {p : ℕ} [hn : Fact p.Prime] : eval 1 (cyclotomic p R) = p := by simp only [cyclotomic_prime, eval_X, one_pow, Finset.sum_const, eval_pow, eval_finset_sum, Finset.card_range, smul_one_eq_cast] -- @[simp] -- Porting note (#10618): simp already proves this theorem eval₂_one_cyclotomic_prime {R S : Type*} [CommRing R] [Semiring S] (f : R →+* S) {p : ℕ} [Fact p.Prime] : eval₂ f 1 (cyclotomic p R) = p := by simp @[simp] theorem eval_one_cyclotomic_prime_pow {R : Type*} [CommRing R] {p : ℕ} (k : ℕ) [hn : Fact p.Prime] : eval 1 (cyclotomic (p ^ (k + 1)) R) = p := by simp only [cyclotomic_prime_pow_eq_geom_sum hn.out, eval_X, one_pow, Finset.sum_const, eval_pow, eval_finset_sum, Finset.card_range, smul_one_eq_cast] -- @[simp] -- Porting note (#10618): simp already proves this theorem eval₂_one_cyclotomic_prime_pow {R S : Type*} [CommRing R] [Semiring S] (f : R →+* S) {p : ℕ} (k : ℕ) [Fact p.Prime] : eval₂ f 1 (cyclotomic (p ^ (k + 1)) R) = p := by simp private theorem cyclotomic_neg_one_pos {n : ℕ} (hn : 2 < n) {R} [LinearOrderedCommRing R] : 0 < eval (-1 : R) (cyclotomic n R) := by haveI := NeZero.of_gt hn rw [← map_cyclotomic_int, ← Int.cast_one, ← Int.cast_neg, eval_intCast_map, Int.coe_castRingHom, Int.cast_pos] suffices 0 < eval (↑(-1 : ℤ)) (cyclotomic n ℝ) by rw [← map_cyclotomic_int n ℝ, eval_intCast_map, Int.coe_castRingHom] at this simpa only [Int.cast_pos] using this simp only [Int.cast_one, Int.cast_neg] have h0 := cyclotomic_coeff_zero ℝ hn.le rw [coeff_zero_eq_eval_zero] at h0 by_contra! hx have := intermediate_value_univ (-1) 0 (cyclotomic n ℝ).continuous obtain ⟨y, hy : IsRoot _ y⟩ := this (show (0 : ℝ) ∈ Set.Icc _ _ by simpa [h0] using hx) rw [@isRoot_cyclotomic_iff] at hy rw [hy.eq_orderOf] at hn exact hn.not_le LinearOrderedRing.orderOf_le_two theorem cyclotomic_pos {n : ℕ} (hn : 2 < n) {R} [LinearOrderedCommRing R] (x : R) : 0 < eval x (cyclotomic n R) := by induction' n using Nat.strong_induction_on with n ih have hn' : 0 < n := pos_of_gt hn have hn'' : 1 < n := one_lt_two.trans hn have := prod_cyclotomic_eq_geom_sum hn' R apply_fun eval x at this rw [← cons_self_properDivisors hn'.ne', Finset.erase_cons_of_ne _ hn''.ne', Finset.prod_cons, eval_mul, eval_geom_sum] at this rcases lt_trichotomy 0 (∑ i ∈ Finset.range n, x ^ i) with (h | h | h) · apply pos_of_mul_pos_left · rwa [this] rw [eval_prod] refine Finset.prod_nonneg fun i hi => ?_ simp only [Finset.mem_erase, mem_properDivisors] at hi rw [geom_sum_pos_iff hn'.ne'] at h cases' h with hk hx · refine (ih _ hi.2.2 (Nat.two_lt_of_ne ?_ hi.1 ?_)).le <;> rintro rfl · exact hn'.ne' (zero_dvd_iff.mp hi.2.1) · exact even_iff_not_odd.mp (even_iff_two_dvd.mpr hi.2.1) hk · rcases eq_or_ne i 2 with (rfl | hk) · simpa only [eval_X, eval_one, cyclotomic_two, eval_add] using hx.le refine (ih _ hi.2.2 (Nat.two_lt_of_ne ?_ hi.1 hk)).le rintro rfl exact hn'.ne' <| zero_dvd_iff.mp hi.2.1 · rw [eq_comm, geom_sum_eq_zero_iff_neg_one hn'.ne'] at h exact h.1.symm ▸ cyclotomic_neg_one_pos hn · apply pos_of_mul_neg_left · rwa [this] rw [geom_sum_neg_iff hn'.ne'] at h have h2 : 2 ∈ n.properDivisors.erase 1 := by rw [Finset.mem_erase, mem_properDivisors] exact ⟨by decide, even_iff_two_dvd.mp h.1, hn⟩ rw [eval_prod, ← Finset.prod_erase_mul _ _ h2] apply mul_nonpos_of_nonneg_of_nonpos · refine Finset.prod_nonneg fun i hi => le_of_lt ?_ simp only [Finset.mem_erase, mem_properDivisors] at hi refine ih _ hi.2.2.2 (Nat.two_lt_of_ne ?_ hi.2.1 hi.1) rintro rfl rw [zero_dvd_iff] at hi exact hn'.ne' hi.2.2.1 · simpa only [eval_X, eval_one, cyclotomic_two, eval_add] using h.right.le theorem cyclotomic_pos_and_nonneg (n : ℕ) {R} [LinearOrderedCommRing R] (x : R) : (1 < x → 0 < eval x (cyclotomic n R)) ∧ (1 ≤ x → 0 ≤ eval x (cyclotomic n R)) := by rcases n with (_ | _ | _ | n) · simp only [cyclotomic_zero, eval_one, zero_lt_one, implies_true, zero_le_one, and_self] · simp only [zero_add, cyclotomic_one, eval_sub, eval_X, eval_one, sub_pos, imp_self, sub_nonneg, and_self] · simp only [zero_add, reduceAdd, cyclotomic_two, eval_add, eval_X, eval_one] constructor <;> intro <;> linarith · constructor <;> intro <;> [skip; apply le_of_lt] <;> apply cyclotomic_pos (by omega) /-- Cyclotomic polynomials are always positive on inputs larger than one. Similar to `cyclotomic_pos` but with the condition on the input rather than index of the cyclotomic polynomial. -/ theorem cyclotomic_pos' (n : ℕ) {R} [LinearOrderedCommRing R] {x : R} (hx : 1 < x) : 0 < eval x (cyclotomic n R) := (cyclotomic_pos_and_nonneg n x).1 hx /-- Cyclotomic polynomials are always nonnegative on inputs one or more. -/ theorem cyclotomic_nonneg (n : ℕ) {R} [LinearOrderedCommRing R] {x : R} (hx : 1 ≤ x) : 0 ≤ eval x (cyclotomic n R) := (cyclotomic_pos_and_nonneg n x).2 hx theorem eval_one_cyclotomic_not_prime_pow {R : Type*} [Ring R] {n : ℕ} (h : ∀ {p : ℕ}, p.Prime → ∀ k : ℕ, p ^ k ≠ n) : eval 1 (cyclotomic n R) = 1 := by rcases n.eq_zero_or_pos with (rfl | hn') · simp have hn : 1 < n := one_lt_iff_ne_zero_and_ne_one.mpr ⟨hn'.ne', (h Nat.prime_two 0).symm⟩ rsuffices h | h : eval 1 (cyclotomic n ℤ) = 1 ∨ eval 1 (cyclotomic n ℤ) = -1 · have := eval_intCast_map (Int.castRingHom R) (cyclotomic n ℤ) 1 simpa only [map_cyclotomic, Int.cast_one, h, eq_intCast] using this · exfalso linarith [cyclotomic_nonneg n (le_refl (1 : ℤ))] rw [← Int.natAbs_eq_natAbs_iff, Int.natAbs_one, Nat.eq_one_iff_not_exists_prime_dvd] intro p hp hpe haveI := Fact.mk hp have := prod_cyclotomic_eq_geom_sum hn' ℤ apply_fun eval 1 at this rw [eval_geom_sum, one_geom_sum, eval_prod, eq_comm, ← Finset.prod_sdiff <| @range_pow_padicValNat_subset_divisors' p _ _, Finset.prod_image] at this · simp_rw [eval_one_cyclotomic_prime_pow, Finset.prod_const, Finset.card_range, mul_comm] at this rw [← Finset.prod_sdiff <| show {n} ⊆ _ from _] at this swap · simp only [singleton_subset_iff, mem_sdiff, mem_erase, Ne, mem_divisors, dvd_refl, true_and_iff, mem_image, mem_range, exists_prop, not_exists, not_and] exact ⟨⟨hn.ne', hn'.ne'⟩, fun t _ => h hp _⟩ rw [← Int.natAbs_ofNat p, Int.natAbs_dvd_natAbs] at hpe obtain ⟨t, ht⟩ := hpe rw [Finset.prod_singleton, ht, mul_left_comm, mul_comm, ← mul_assoc, mul_assoc] at this have : (p : ℤ) ^ padicValNat p n * p ∣ n := ⟨_, this⟩ simp only [← _root_.pow_succ, ← Int.natAbs_dvd_natAbs, Int.natAbs_ofNat, Int.natAbs_pow] at this exact pow_succ_padicValNat_not_dvd hn'.ne' this · rintro x - y - hxy apply Nat.succ_injective exact Nat.pow_right_injective hp.two_le hxy theorem sub_one_pow_totient_lt_cyclotomic_eval {n : ℕ} {q : ℝ} (hn' : 2 ≤ n) (hq' : 1 < q) : (q - 1) ^ totient n < (cyclotomic n ℝ).eval q := by have hn : 0 < n := pos_of_gt hn' have hq := zero_lt_one.trans hq' have hfor : ∀ ζ' ∈ primitiveRoots n ℂ, q - 1 ≤ ‖↑q - ζ'‖ := by intro ζ' hζ' rw [mem_primitiveRoots hn] at hζ' convert norm_sub_norm_le (↑q) ζ' · rw [Complex.norm_real, Real.norm_of_nonneg hq.le] · rw [hζ'.norm'_eq_one hn.ne'] let ζ := Complex.exp (2 * ↑Real.pi * Complex.I / ↑n) have hζ : IsPrimitiveRoot ζ n := Complex.isPrimitiveRoot_exp n hn.ne' have hex : ∃ ζ' ∈ primitiveRoots n ℂ, q - 1 < ‖↑q - ζ'‖ := by refine ⟨ζ, (mem_primitiveRoots hn).mpr hζ, ?_⟩ suffices ¬SameRay ℝ (q : ℂ) ζ by convert lt_norm_sub_of_not_sameRay this <;> simp only [hζ.norm'_eq_one hn.ne', Real.norm_of_nonneg hq.le, Complex.norm_real] rw [Complex.sameRay_iff] push_neg refine ⟨mod_cast hq.ne', hζ.ne_zero hn.ne', ?_⟩ rw [Complex.arg_ofReal_of_nonneg hq.le, Ne, eq_comm, hζ.arg_eq_zero_iff hn.ne'] clear_value ζ rintro rfl linarith [hζ.unique IsPrimitiveRoot.one] have : ¬eval (↑q) (cyclotomic n ℂ) = 0 := by erw [cyclotomic.eval_apply q n (algebraMap ℝ ℂ)] simpa only [Complex.coe_algebraMap, Complex.ofReal_eq_zero] using (cyclotomic_pos' n hq').ne' suffices Units.mk0 (Real.toNNReal (q - 1)) (by simp [hq']) ^ totient n < Units.mk0 ‖(cyclotomic n ℂ).eval ↑q‖₊ (by simp [this]) by simp only [← Units.val_lt_val, Units.val_pow_eq_pow_val, Units.val_mk0, ← NNReal.coe_lt_coe, hq'.le, Real.toNNReal_lt_toNNReal_iff_of_nonneg, coe_nnnorm, Complex.norm_eq_abs, NNReal.coe_pow, Real.coe_toNNReal', max_eq_left, sub_nonneg] at this convert this erw [cyclotomic.eval_apply q n (algebraMap ℝ ℂ), eq_comm] simp only [cyclotomic_nonneg n hq'.le, Complex.coe_algebraMap, Complex.abs_ofReal, abs_eq_self] simp only [cyclotomic_eq_prod_X_sub_primitiveRoots hζ, eval_prod, eval_C, eval_X, eval_sub, nnnorm_prod, Units.mk0_prod] convert Finset.prod_lt_prod' (M := NNRealˣ) _ _ swap; · exact fun _ => Units.mk0 (Real.toNNReal (q - 1)) (by simp [hq']) · simp only [Complex.card_primitiveRoots, prod_const, card_attach] · simp only [Subtype.coe_mk, Finset.mem_attach, forall_true_left, Subtype.forall, ← Units.val_le_val, ← NNReal.coe_le_coe, Complex.abs.nonneg, hq'.le, Units.val_mk0, Real.coe_toNNReal', coe_nnnorm, Complex.norm_eq_abs, max_le_iff, tsub_le_iff_right] intro x hx simpa only [and_true_iff, tsub_le_iff_right] using hfor x hx · simp only [Subtype.coe_mk, Finset.mem_attach, exists_true_left, Subtype.exists, ← NNReal.coe_lt_coe, ← Units.val_lt_val, Units.val_mk0 _, coe_nnnorm] simpa [hq'.le, Real.coe_toNNReal', max_eq_left, sub_nonneg] using hex theorem sub_one_pow_totient_le_cyclotomic_eval {q : ℝ} (hq' : 1 < q) : ∀ n, (q - 1) ^ totient n ≤ (cyclotomic n ℝ).eval q | 0 => by simp only [totient_zero, _root_.pow_zero, cyclotomic_zero, eval_one, le_refl] | 1 => by simp only [totient_one, pow_one, cyclotomic_one, eval_sub, eval_X, eval_one, le_refl] | n + 2 => (sub_one_pow_totient_lt_cyclotomic_eval le_add_self hq').le theorem cyclotomic_eval_lt_add_one_pow_totient {n : ℕ} {q : ℝ} (hn' : 3 ≤ n) (hq' : 1 < q) : (cyclotomic n ℝ).eval q < (q + 1) ^ totient n := by have hn : 0 < n := pos_of_gt hn' have hq := zero_lt_one.trans hq' have hfor : ∀ ζ' ∈ primitiveRoots n ℂ, ‖↑q - ζ'‖ ≤ q + 1 := by intro ζ' hζ' rw [mem_primitiveRoots hn] at hζ' convert norm_sub_le (↑q) ζ' · rw [Complex.norm_real, Real.norm_of_nonneg (zero_le_one.trans_lt hq').le] · rw [hζ'.norm'_eq_one hn.ne'] let ζ := Complex.exp (2 * ↑Real.pi * Complex.I / ↑n) have hζ : IsPrimitiveRoot ζ n := Complex.isPrimitiveRoot_exp n hn.ne' have hex : ∃ ζ' ∈ primitiveRoots n ℂ, ‖↑q - ζ'‖ < q + 1 := by refine ⟨ζ, (mem_primitiveRoots hn).mpr hζ, ?_⟩ suffices ¬SameRay ℝ (q : ℂ) (-ζ) by convert norm_add_lt_of_not_sameRay this using 2 · rw [Complex.norm_eq_abs, Complex.abs_ofReal] symm exact abs_eq_self.mpr hq.le · simp [abs_of_pos hq, hζ.norm'_eq_one hn.ne', -Complex.norm_eq_abs] rw [Complex.sameRay_iff] push_neg refine ⟨mod_cast hq.ne', neg_ne_zero.mpr <| hζ.ne_zero hn.ne', ?_⟩ rw [Complex.arg_ofReal_of_nonneg hq.le, Ne, eq_comm] intro h rw [Complex.arg_eq_zero_iff, Complex.neg_re, neg_nonneg, Complex.neg_im, neg_eq_zero] at h have hζ₀ : ζ ≠ 0 := by clear_value ζ rintro rfl exact hn.ne' (hζ.unique IsPrimitiveRoot.zero) have : ζ.re < 0 ∧ ζ.im = 0 := ⟨h.1.lt_of_ne ?_, h.2⟩ · rw [← Complex.arg_eq_pi_iff, hζ.arg_eq_pi_iff hn.ne'] at this rw [this] at hζ linarith [hζ.unique <| IsPrimitiveRoot.neg_one 0 two_ne_zero.symm] · contrapose! hζ₀ apply Complex.ext <;> simp [hζ₀, h.2] have : ¬eval (↑q) (cyclotomic n ℂ) = 0 := by erw [cyclotomic.eval_apply q n (algebraMap ℝ ℂ)] simp only [Complex.coe_algebraMap, Complex.ofReal_eq_zero] exact (cyclotomic_pos' n hq').ne.symm suffices Units.mk0 ‖(cyclotomic n ℂ).eval ↑q‖₊ (by simp [this]) < Units.mk0 (Real.toNNReal (q + 1)) (by simp; linarith) ^ totient n by simp only [← Units.val_lt_val, Units.val_pow_eq_pow_val, Units.val_mk0, ← NNReal.coe_lt_coe, hq'.le, Real.toNNReal_lt_toNNReal_iff_of_nonneg, coe_nnnorm, Complex.norm_eq_abs, NNReal.coe_pow, Real.coe_toNNReal', max_eq_left, sub_nonneg] at this convert this using 2 · erw [cyclotomic.eval_apply q n (algebraMap ℝ ℂ), eq_comm] simp [cyclotomic_nonneg n hq'.le] rw [eq_comm, max_eq_left_iff] linarith simp only [cyclotomic_eq_prod_X_sub_primitiveRoots hζ, eval_prod, eval_C, eval_X, eval_sub, nnnorm_prod, Units.mk0_prod] convert Finset.prod_lt_prod' (M := NNRealˣ) _ _ swap; · exact fun _ => Units.mk0 (Real.toNNReal (q + 1)) (by simp; linarith only [hq']) · simp [Complex.card_primitiveRoots] · simp only [Subtype.coe_mk, Finset.mem_attach, forall_true_left, Subtype.forall, ← Units.val_le_val, ← NNReal.coe_le_coe, Complex.abs.nonneg, hq'.le, Units.val_mk0, Real.coe_toNNReal, coe_nnnorm, Complex.norm_eq_abs, max_le_iff] intro x hx have : Complex.abs _ ≤ _ := hfor x hx simp [this] · simp only [Subtype.coe_mk, Finset.mem_attach, exists_true_left, Subtype.exists, ← NNReal.coe_lt_coe, ← Units.val_lt_val, Units.val_mk0 _, coe_nnnorm] obtain ⟨ζ, hζ, hhζ : Complex.abs _ < _⟩ := hex exact ⟨ζ, hζ, by simp [hhζ]⟩ theorem cyclotomic_eval_le_add_one_pow_totient {q : ℝ} (hq' : 1 < q) : ∀ n, (cyclotomic n ℝ).eval q ≤ (q + 1) ^ totient n | 0 => by simp | 1 => by simp [add_assoc, add_nonneg, zero_le_one] | 2 => by simp | n + 3 => (cyclotomic_eval_lt_add_one_pow_totient le_add_self hq').le theorem sub_one_pow_totient_lt_natAbs_cyclotomic_eval {n : ℕ} {q : ℕ} (hn' : 1 < n) (hq : q ≠ 1) : (q - 1) ^ totient n < ((cyclotomic n ℤ).eval ↑q).natAbs := by rcases hq.lt_or_lt.imp_left Nat.lt_one_iff.mp with (rfl | hq') · rw [zero_tsub, zero_pow (Nat.totient_pos.2 (pos_of_gt hn')).ne', pos_iff_ne_zero, Int.natAbs_ne_zero, Nat.cast_zero, ← coeff_zero_eq_eval_zero, cyclotomic_coeff_zero _ hn'] exact one_ne_zero rw [← @Nat.cast_lt ℝ, Nat.cast_pow, Nat.cast_sub hq'.le, Nat.cast_one, Int.cast_natAbs] refine (sub_one_pow_totient_lt_cyclotomic_eval hn' (Nat.one_lt_cast.2 hq')).trans_le ?_ convert (cyclotomic.eval_apply (q : ℤ) n (algebraMap ℤ ℝ)).trans_le (le_abs_self _) simp theorem sub_one_lt_natAbs_cyclotomic_eval {n : ℕ} {q : ℕ} (hn' : 1 < n) (hq : q ≠ 1) : q - 1 < ((cyclotomic n ℤ).eval ↑q).natAbs := calc q - 1 ≤ (q - 1) ^ totient n := Nat.le_self_pow (Nat.totient_pos.2 <| pos_of_gt hn').ne' _ _ < ((cyclotomic n ℤ).eval ↑q).natAbs := sub_one_pow_totient_lt_natAbs_cyclotomic_eval hn' hq end Polynomial
RingTheory\Polynomial\Cyclotomic\Expand.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.Roots import Mathlib.Data.ZMod.Algebra /-! # Cyclotomic polynomials and `expand`. We gather results relating cyclotomic polynomials and `expand`. ## Main results * `Polynomial.cyclotomic_expand_eq_cyclotomic_mul` : If `p` is a prime such that `¬ p ∣ n`, then `expand R p (cyclotomic n R) = (cyclotomic (n * p) R) * (cyclotomic n R)`. * `Polynomial.cyclotomic_expand_eq_cyclotomic` : If `p` is a prime such that `p ∣ n`, then `expand R p (cyclotomic n R) = cyclotomic (p * n) R`. * `Polynomial.cyclotomic_mul_prime_eq_pow_of_not_dvd` : If `R` is of characteristic `p` and `¬p ∣ n`, then `cyclotomic (n * p) R = (cyclotomic n R) ^ (p - 1)`. * `Polynomial.cyclotomic_mul_prime_dvd_eq_pow` : If `R` is of characteristic `p` and `p ∣ n`, then `cyclotomic (n * p) R = (cyclotomic n R) ^ p`. * `Polynomial.cyclotomic_mul_prime_pow_eq` : If `R` is of characteristic `p` and `¬p ∣ m`, then `cyclotomic (p ^ k * m) R = (cyclotomic m R) ^ (p ^ k - p ^ (k - 1))`. -/ namespace Polynomial /-- If `p` is a prime such that `¬ p ∣ n`, then `expand R p (cyclotomic n R) = (cyclotomic (n * p) R) * (cyclotomic n R)`. -/ @[simp] theorem cyclotomic_expand_eq_cyclotomic_mul {p n : ℕ} (hp : Nat.Prime p) (hdiv : ¬p ∣ n) (R : Type*) [CommRing R] : expand R p (cyclotomic n R) = cyclotomic (n * p) R * cyclotomic n R := by rcases Nat.eq_zero_or_pos n with (rfl | hnpos) · simp haveI := NeZero.of_pos hnpos suffices expand ℤ p (cyclotomic n ℤ) = cyclotomic (n * p) ℤ * cyclotomic n ℤ by rw [← map_cyclotomic_int, ← map_expand, this, Polynomial.map_mul, map_cyclotomic_int, map_cyclotomic] refine eq_of_monic_of_dvd_of_natDegree_le ((cyclotomic.monic _ ℤ).mul (cyclotomic.monic _ ℤ)) ((cyclotomic.monic n ℤ).expand hp.pos) ?_ ?_ · refine (IsPrimitive.Int.dvd_iff_map_cast_dvd_map_cast _ _ (IsPrimitive.mul (cyclotomic.isPrimitive (n * p) ℤ) (cyclotomic.isPrimitive n ℤ)) ((cyclotomic.monic n ℤ).expand hp.pos).isPrimitive).2 ?_ rw [Polynomial.map_mul, map_cyclotomic_int, map_cyclotomic_int, map_expand, map_cyclotomic_int] refine IsCoprime.mul_dvd (cyclotomic.isCoprime_rat fun h => ?_) ?_ ?_ · replace h : n * p = n * 1 := by simp [h] exact Nat.Prime.ne_one hp (mul_left_cancel₀ hnpos.ne' h) · have hpos : 0 < n * p := mul_pos hnpos hp.pos have hprim := Complex.isPrimitiveRoot_exp _ hpos.ne' rw [cyclotomic_eq_minpoly_rat hprim hpos] refine minpoly.dvd ℚ _ ?_ rw [aeval_def, ← eval_map, map_expand, map_cyclotomic, expand_eval, ← IsRoot.def, @isRoot_cyclotomic_iff] convert IsPrimitiveRoot.pow_of_dvd hprim hp.ne_zero (dvd_mul_left p n) rw [Nat.mul_div_cancel _ (Nat.Prime.pos hp)] · have hprim := Complex.isPrimitiveRoot_exp _ hnpos.ne.symm rw [cyclotomic_eq_minpoly_rat hprim hnpos] refine minpoly.dvd ℚ _ ?_ rw [aeval_def, ← eval_map, map_expand, expand_eval, ← IsRoot.def, ← cyclotomic_eq_minpoly_rat hprim hnpos, map_cyclotomic, @isRoot_cyclotomic_iff] exact IsPrimitiveRoot.pow_of_prime hprim hp hdiv · rw [natDegree_expand, natDegree_cyclotomic, natDegree_mul (cyclotomic_ne_zero _ ℤ) (cyclotomic_ne_zero _ ℤ), natDegree_cyclotomic, natDegree_cyclotomic, mul_comm n, Nat.totient_mul ((Nat.Prime.coprime_iff_not_dvd hp).2 hdiv), Nat.totient_prime hp, mul_comm (p - 1), ← Nat.mul_succ, Nat.sub_one, Nat.succ_pred_eq_of_pos hp.pos] /-- If `p` is a prime such that `p ∣ n`, then `expand R p (cyclotomic n R) = cyclotomic (p * n) R`. -/ @[simp] theorem cyclotomic_expand_eq_cyclotomic {p n : ℕ} (hp : Nat.Prime p) (hdiv : p ∣ n) (R : Type*) [CommRing R] : expand R p (cyclotomic n R) = cyclotomic (n * p) R := by rcases n.eq_zero_or_pos with (rfl | hzero) · simp haveI := NeZero.of_pos hzero suffices expand ℤ p (cyclotomic n ℤ) = cyclotomic (n * p) ℤ by rw [← map_cyclotomic_int, ← map_expand, this, map_cyclotomic_int] refine eq_of_monic_of_dvd_of_natDegree_le (cyclotomic.monic _ ℤ) ((cyclotomic.monic n ℤ).expand hp.pos) ?_ ?_ · have hpos := Nat.mul_pos hzero hp.pos have hprim := Complex.isPrimitiveRoot_exp _ hpos.ne.symm rw [cyclotomic_eq_minpoly hprim hpos] refine minpoly.isIntegrallyClosed_dvd (hprim.isIntegral hpos) ?_ rw [aeval_def, ← eval_map, map_expand, map_cyclotomic, expand_eval, ← IsRoot.def, @isRoot_cyclotomic_iff] convert IsPrimitiveRoot.pow_of_dvd hprim hp.ne_zero (dvd_mul_left p n) rw [Nat.mul_div_cancel _ hp.pos] · rw [natDegree_expand, natDegree_cyclotomic, natDegree_cyclotomic, mul_comm n, Nat.totient_mul_of_prime_of_dvd hp hdiv, mul_comm] /-- If the `p ^ n`th cyclotomic polynomial is irreducible, so is the `p ^ m`th, for `m ≤ n`. -/ theorem cyclotomic_irreducible_pow_of_irreducible_pow {p : ℕ} (hp : Nat.Prime p) {R} [CommRing R] [IsDomain R] {n m : ℕ} (hmn : m ≤ n) (h : Irreducible (cyclotomic (p ^ n) R)) : Irreducible (cyclotomic (p ^ m) R) := by rcases m.eq_zero_or_pos with (rfl | hm) · simpa using irreducible_X_sub_C (1 : R) obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le hmn induction' k with k hk · simpa using h have : m + k ≠ 0 := (add_pos_of_pos_of_nonneg hm k.zero_le).ne' rw [Nat.add_succ, pow_succ, ← cyclotomic_expand_eq_cyclotomic hp <| dvd_pow_self p this] at h exact hk (by omega) (of_irreducible_expand hp.ne_zero h) /-- If `Irreducible (cyclotomic (p ^ n) R)` then `Irreducible (cyclotomic p R).` -/ theorem cyclotomic_irreducible_of_irreducible_pow {p : ℕ} (hp : Nat.Prime p) {R} [CommRing R] [IsDomain R] {n : ℕ} (hn : n ≠ 0) (h : Irreducible (cyclotomic (p ^ n) R)) : Irreducible (cyclotomic p R) := pow_one p ▸ cyclotomic_irreducible_pow_of_irreducible_pow hp hn.bot_lt h section CharP /-- If `R` is of characteristic `p` and `¬p ∣ n`, then `cyclotomic (n * p) R = (cyclotomic n R) ^ (p - 1)`. -/ theorem cyclotomic_mul_prime_eq_pow_of_not_dvd (R : Type*) {p n : ℕ} [hp : Fact (Nat.Prime p)] [Ring R] [CharP R p] (hn : ¬p ∣ n) : cyclotomic (n * p) R = cyclotomic n R ^ (p - 1) := by letI : Algebra (ZMod p) R := ZMod.algebra _ _ suffices cyclotomic (n * p) (ZMod p) = cyclotomic n (ZMod p) ^ (p - 1) by rw [← map_cyclotomic _ (algebraMap (ZMod p) R), ← map_cyclotomic _ (algebraMap (ZMod p) R), this, Polynomial.map_pow] apply mul_right_injective₀ (cyclotomic_ne_zero n <| ZMod p); dsimp rw [← pow_succ', tsub_add_cancel_of_le hp.out.one_lt.le, mul_comm, ← ZMod.expand_card] conv_rhs => rw [← map_cyclotomic_int] rw [← map_expand, cyclotomic_expand_eq_cyclotomic_mul hp.out hn, Polynomial.map_mul, map_cyclotomic, map_cyclotomic] /-- If `R` is of characteristic `p` and `p ∣ n`, then `cyclotomic (n * p) R = (cyclotomic n R) ^ p`. -/ theorem cyclotomic_mul_prime_dvd_eq_pow (R : Type*) {p n : ℕ} [hp : Fact (Nat.Prime p)] [Ring R] [CharP R p] (hn : p ∣ n) : cyclotomic (n * p) R = cyclotomic n R ^ p := by letI : Algebra (ZMod p) R := ZMod.algebra _ _ suffices cyclotomic (n * p) (ZMod p) = cyclotomic n (ZMod p) ^ p by rw [← map_cyclotomic _ (algebraMap (ZMod p) R), ← map_cyclotomic _ (algebraMap (ZMod p) R), this, Polynomial.map_pow] rw [← ZMod.expand_card, ← map_cyclotomic_int n, ← map_expand, cyclotomic_expand_eq_cyclotomic hp.out hn, map_cyclotomic] /-- If `R` is of characteristic `p` and `¬p ∣ m`, then `cyclotomic (p ^ k * m) R = (cyclotomic m R) ^ (p ^ k - p ^ (k - 1))`. -/ theorem cyclotomic_mul_prime_pow_eq (R : Type*) {p m : ℕ} [Fact (Nat.Prime p)] [Ring R] [CharP R p] (hm : ¬p ∣ m) : ∀ {k}, 0 < k → cyclotomic (p ^ k * m) R = cyclotomic m R ^ (p ^ k - p ^ (k - 1)) | 1, _ => by rw [pow_one, Nat.sub_self, pow_zero, mul_comm, cyclotomic_mul_prime_eq_pow_of_not_dvd R hm] | a + 2, _ => by have hdiv : p ∣ p ^ a.succ * m := ⟨p ^ a * m, by rw [← mul_assoc, pow_succ']⟩ rw [pow_succ', mul_assoc, mul_comm, cyclotomic_mul_prime_dvd_eq_pow R hdiv, cyclotomic_mul_prime_pow_eq _ _ a.succ_pos, ← pow_mul] · simp only [tsub_zero, Nat.succ_sub_succ_eq_sub] rw [Nat.mul_sub_right_distrib, mul_comm, pow_succ] · assumption /-- If `R` is of characteristic `p` and `¬p ∣ m`, then `ζ` is a root of `cyclotomic (p ^ k * m) R` if and only if it is a primitive `m`-th root of unity. -/ theorem isRoot_cyclotomic_prime_pow_mul_iff_of_charP {m k p : ℕ} {R : Type*} [CommRing R] [IsDomain R] [hp : Fact (Nat.Prime p)] [hchar : CharP R p] {μ : R} [NeZero (m : R)] : (Polynomial.cyclotomic (p ^ k * m) R).IsRoot μ ↔ IsPrimitiveRoot μ m := by rcases k.eq_zero_or_pos with (rfl | hk) · rw [pow_zero, one_mul, isRoot_cyclotomic_iff] refine ⟨fun h => ?_, fun h => ?_⟩ · rw [IsRoot.def, cyclotomic_mul_prime_pow_eq R (NeZero.not_char_dvd R p m) hk, eval_pow] at h replace h := pow_eq_zero h rwa [← IsRoot.def, isRoot_cyclotomic_iff] at h · rw [← isRoot_cyclotomic_iff, IsRoot.def] at h rw [cyclotomic_mul_prime_pow_eq R (NeZero.not_char_dvd R p m) hk, IsRoot.def, eval_pow, h, zero_pow] exact Nat.sub_ne_zero_of_lt $ pow_right_strictMono hp.out.one_lt $ Nat.pred_lt hk.ne' end CharP end Polynomial
RingTheory\Polynomial\Cyclotomic\Roots.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.Basic import Mathlib.RingTheory.RootsOfUnity.Minpoly /-! # Roots of cyclotomic polynomials. We gather results about roots of cyclotomic polynomials. In particular we show in `Polynomial.cyclotomic_eq_minpoly` that `cyclotomic n R` is the minimal polynomial of a primitive root of unity. ## Main results * `IsPrimitiveRoot.isRoot_cyclotomic` : Any `n`-th primitive root of unity is a root of `cyclotomic n R`. * `isRoot_cyclotomic_iff` : if `NeZero (n : R)`, then `μ` is a root of `cyclotomic n R` if and only if `μ` is a primitive root of unity. * `Polynomial.cyclotomic_eq_minpoly` : `cyclotomic n ℤ` is the minimal polynomial of a primitive `n`-th root of unity `μ`. * `Polynomial.cyclotomic.irreducible` : `cyclotomic n ℤ` is irreducible. ## Implementation details To prove `Polynomial.cyclotomic.irreducible`, the irreducibility of `cyclotomic n ℤ`, we show in `Polynomial.cyclotomic_eq_minpoly` that `cyclotomic n ℤ` is the minimal polynomial of any `n`-th primitive root of unity `μ : K`, where `K` is a field of characteristic `0`. -/ namespace Polynomial variable {R : Type*} [CommRing R] {n : ℕ} theorem isRoot_of_unity_of_root_cyclotomic {ζ : R} {i : ℕ} (hi : i ∈ n.divisors) (h : (cyclotomic i R).IsRoot ζ) : ζ ^ n = 1 := by rcases n.eq_zero_or_pos with (rfl | hn) · exact pow_zero _ have := congr_arg (eval ζ) (prod_cyclotomic_eq_X_pow_sub_one hn R).symm rw [eval_sub, eval_pow, eval_X, eval_one] at this convert eq_add_of_sub_eq' this convert (add_zero (M := R) _).symm apply eval_eq_zero_of_dvd_of_eval_eq_zero _ h exact Finset.dvd_prod_of_mem _ hi section IsDomain variable [IsDomain R] theorem _root_.isRoot_of_unity_iff (h : 0 < n) (R : Type*) [CommRing R] [IsDomain R] {ζ : R} : ζ ^ n = 1 ↔ ∃ i ∈ n.divisors, (cyclotomic i R).IsRoot ζ := by rw [← mem_nthRoots h, nthRoots, mem_roots <| X_pow_sub_C_ne_zero h _, C_1, ← prod_cyclotomic_eq_X_pow_sub_one h, isRoot_prod] /-- Any `n`-th primitive root of unity is a root of `cyclotomic n R`. -/ theorem _root_.IsPrimitiveRoot.isRoot_cyclotomic (hpos : 0 < n) {μ : R} (h : IsPrimitiveRoot μ n) : IsRoot (cyclotomic n R) μ := by rw [← mem_roots (cyclotomic_ne_zero n R), cyclotomic_eq_prod_X_sub_primitiveRoots h, roots_prod_X_sub_C, ← Finset.mem_def] rwa [← mem_primitiveRoots hpos] at h private theorem isRoot_cyclotomic_iff' {n : ℕ} {K : Type*} [Field K] {μ : K} [NeZero (n : K)] : IsRoot (cyclotomic n K) μ ↔ IsPrimitiveRoot μ n := by -- in this proof, `o` stands for `orderOf μ` have hnpos : 0 < n := (NeZero.of_neZero_natCast K).out.bot_lt refine ⟨fun hμ => ?_, IsPrimitiveRoot.isRoot_cyclotomic hnpos⟩ have hμn : μ ^ n = 1 := by rw [isRoot_of_unity_iff hnpos _] exact ⟨n, n.mem_divisors_self hnpos.ne', hμ⟩ by_contra hnμ have ho : 0 < orderOf μ := (isOfFinOrder_iff_pow_eq_one.2 <| ⟨n, hnpos, hμn⟩).orderOf_pos have := pow_orderOf_eq_one μ rw [isRoot_of_unity_iff ho] at this obtain ⟨i, hio, hiμ⟩ := this replace hio := Nat.dvd_of_mem_divisors hio rw [IsPrimitiveRoot.not_iff] at hnμ rw [← orderOf_dvd_iff_pow_eq_one] at hμn have key : i < n := (Nat.le_of_dvd ho hio).trans_lt ((Nat.le_of_dvd hnpos hμn).lt_of_ne hnμ) have key' : i ∣ n := hio.trans hμn rw [← Polynomial.dvd_iff_isRoot] at hμ hiμ have hni : {i, n} ⊆ n.divisors := by simpa [Finset.insert_subset_iff, key'] using hnpos.ne' obtain ⟨k, hk⟩ := hiμ obtain ⟨j, hj⟩ := hμ have := prod_cyclotomic_eq_X_pow_sub_one hnpos K rw [← Finset.prod_sdiff hni, Finset.prod_pair key.ne, hk, hj] at this have hn := (X_pow_sub_one_separable_iff.mpr <| NeZero.natCast_ne n K).squarefree rw [← this, Squarefree] at hn specialize hn (X - C μ) ⟨(∏ x ∈ n.divisors \ {i, n}, cyclotomic x K) * k * j, by ring⟩ simp [Polynomial.isUnit_iff_degree_eq_zero] at hn theorem isRoot_cyclotomic_iff [NeZero (n : R)] {μ : R} : IsRoot (cyclotomic n R) μ ↔ IsPrimitiveRoot μ n := by have hf : Function.Injective _ := IsFractionRing.injective R (FractionRing R) haveI : NeZero (n : FractionRing R) := NeZero.nat_of_injective hf rw [← isRoot_map_iff hf, ← IsPrimitiveRoot.map_iff_of_injective hf, map_cyclotomic, ← isRoot_cyclotomic_iff'] theorem roots_cyclotomic_nodup [NeZero (n : R)] : (cyclotomic n R).roots.Nodup := by obtain h | ⟨ζ, hζ⟩ := (cyclotomic n R).roots.empty_or_exists_mem · exact h.symm ▸ Multiset.nodup_zero rw [mem_roots <| cyclotomic_ne_zero n R, isRoot_cyclotomic_iff] at hζ refine Multiset.nodup_of_le (roots.le_of_dvd (X_pow_sub_C_ne_zero (NeZero.pos_of_neZero_natCast R) 1) <| cyclotomic.dvd_X_pow_sub_one n R) hζ.nthRoots_one_nodup theorem cyclotomic.roots_to_finset_eq_primitiveRoots [NeZero (n : R)] : (⟨(cyclotomic n R).roots, roots_cyclotomic_nodup⟩ : Finset _) = primitiveRoots n R := by ext a -- Porting note: was -- `simp [cyclotomic_ne_zero n R, isRoot_cyclotomic_iff, mem_primitiveRoots,` -- ` NeZero.pos_of_neZero_natCast R]` simp only [mem_primitiveRoots, NeZero.pos_of_neZero_natCast R] convert isRoot_cyclotomic_iff (n := n) (μ := a) simp [cyclotomic_ne_zero n R] theorem cyclotomic.roots_eq_primitiveRoots_val [NeZero (n : R)] : (cyclotomic n R).roots = (primitiveRoots n R).val := by rw [← cyclotomic.roots_to_finset_eq_primitiveRoots] /-- If `R` is of characteristic zero, then `ζ` is a root of `cyclotomic n R` if and only if it is a primitive `n`-th root of unity. -/ theorem isRoot_cyclotomic_iff_charZero {n : ℕ} {R : Type*} [CommRing R] [IsDomain R] [CharZero R] {μ : R} (hn : 0 < n) : (Polynomial.cyclotomic n R).IsRoot μ ↔ IsPrimitiveRoot μ n := letI := NeZero.of_gt hn isRoot_cyclotomic_iff end IsDomain /-- Over a ring `R` of characteristic zero, `fun n => cyclotomic n R` is injective. -/ theorem cyclotomic_injective [CharZero R] : Function.Injective fun n => cyclotomic n R := by intro n m hnm simp only at hnm rcases eq_or_ne n 0 with (rfl | hzero) · rw [cyclotomic_zero] at hnm replace hnm := congr_arg natDegree hnm rwa [natDegree_one, natDegree_cyclotomic, eq_comm, Nat.totient_eq_zero, eq_comm] at hnm · haveI := NeZero.mk hzero rw [← map_cyclotomic_int _ R, ← map_cyclotomic_int _ R] at hnm replace hnm := map_injective (Int.castRingHom R) Int.cast_injective hnm replace hnm := congr_arg (map (Int.castRingHom ℂ)) hnm rw [map_cyclotomic_int, map_cyclotomic_int] at hnm have hprim := Complex.isPrimitiveRoot_exp _ hzero have hroot := isRoot_cyclotomic_iff (R := ℂ).2 hprim rw [hnm] at hroot haveI hmzero : NeZero m := ⟨fun h => by simp [h] at hroot⟩ rw [isRoot_cyclotomic_iff (R := ℂ)] at hroot replace hprim := hprim.eq_orderOf rwa [← IsPrimitiveRoot.eq_orderOf hroot] at hprim /-- The minimal polynomial of a primitive `n`-th root of unity `μ` divides `cyclotomic n ℤ`. -/ theorem _root_.IsPrimitiveRoot.minpoly_dvd_cyclotomic {n : ℕ} {K : Type*} [Field K] {μ : K} (h : IsPrimitiveRoot μ n) (hpos : 0 < n) [CharZero K] : minpoly ℤ μ ∣ cyclotomic n ℤ := by apply minpoly.isIntegrallyClosed_dvd (h.isIntegral hpos) simpa [aeval_def, eval₂_eq_eval_map, IsRoot.def] using h.isRoot_cyclotomic hpos section minpoly open IsPrimitiveRoot Complex theorem _root_.IsPrimitiveRoot.minpoly_eq_cyclotomic_of_irreducible {K : Type*} [Field K] {R : Type*} [CommRing R] [IsDomain R] {μ : R} {n : ℕ} [Algebra K R] (hμ : IsPrimitiveRoot μ n) (h : Irreducible <| cyclotomic n K) [NeZero (n : K)] : cyclotomic n K = minpoly K μ := by haveI := NeZero.of_noZeroSMulDivisors K R n refine minpoly.eq_of_irreducible_of_monic h ?_ (cyclotomic.monic n K) rwa [aeval_def, eval₂_eq_eval_map, map_cyclotomic, ← IsRoot.def, isRoot_cyclotomic_iff] /-- `cyclotomic n ℤ` is the minimal polynomial of a primitive `n`-th root of unity `μ`. -/ theorem cyclotomic_eq_minpoly {n : ℕ} {K : Type*} [Field K] {μ : K} (h : IsPrimitiveRoot μ n) (hpos : 0 < n) [CharZero K] : cyclotomic n ℤ = minpoly ℤ μ := by refine eq_of_monic_of_dvd_of_natDegree_le (minpoly.monic (IsPrimitiveRoot.isIntegral h hpos)) (cyclotomic.monic n ℤ) (h.minpoly_dvd_cyclotomic hpos) ?_ simpa [natDegree_cyclotomic n ℤ] using totient_le_degree_minpoly h /-- `cyclotomic n ℚ` is the minimal polynomial of a primitive `n`-th root of unity `μ`. -/ theorem cyclotomic_eq_minpoly_rat {n : ℕ} {K : Type*} [Field K] {μ : K} (h : IsPrimitiveRoot μ n) (hpos : 0 < n) [CharZero K] : cyclotomic n ℚ = minpoly ℚ μ := by rw [← map_cyclotomic_int, cyclotomic_eq_minpoly h hpos] exact (minpoly.isIntegrallyClosed_eq_field_fractions' _ (IsPrimitiveRoot.isIntegral h hpos)).symm /-- `cyclotomic n ℤ` is irreducible. -/ theorem cyclotomic.irreducible {n : ℕ} (hpos : 0 < n) : Irreducible (cyclotomic n ℤ) := by rw [cyclotomic_eq_minpoly (isPrimitiveRoot_exp n hpos.ne') hpos] apply minpoly.irreducible exact (isPrimitiveRoot_exp n hpos.ne').isIntegral hpos /-- `cyclotomic n ℚ` is irreducible. -/ theorem cyclotomic.irreducible_rat {n : ℕ} (hpos : 0 < n) : Irreducible (cyclotomic n ℚ) := by rw [← map_cyclotomic_int] exact (IsPrimitive.irreducible_iff_irreducible_map_fraction_map (cyclotomic.isPrimitive n ℤ)).1 (cyclotomic.irreducible hpos) /-- If `n ≠ m`, then `(cyclotomic n ℚ)` and `(cyclotomic m ℚ)` are coprime. -/ theorem cyclotomic.isCoprime_rat {n m : ℕ} (h : n ≠ m) : IsCoprime (cyclotomic n ℚ) (cyclotomic m ℚ) := by rcases n.eq_zero_or_pos with (rfl | hnzero) · exact isCoprime_one_left rcases m.eq_zero_or_pos with (rfl | hmzero) · exact isCoprime_one_right rw [Irreducible.coprime_iff_not_dvd <| cyclotomic.irreducible_rat <| hnzero] exact fun hdiv => h <| cyclotomic_injective <| eq_of_monic_of_associated (cyclotomic.monic n ℚ) (cyclotomic.monic m ℚ) <| Irreducible.associated_of_dvd (cyclotomic.irreducible_rat hnzero) (cyclotomic.irreducible_rat hmzero) hdiv end minpoly end Polynomial