source
stringlengths
17
118
lean4
stringlengths
0
335k
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/AssociatedPrime/Basic.lean
import Mathlib.Algebra.Exact import Mathlib.LinearAlgebra.Span.Basic import Mathlib.RingTheory.Ideal.IsPrimary import Mathlib.RingTheory.Ideal.Quotient.Operations import Mathlib.RingTheory.Noetherian.Defs /-! # Associated primes of a module We provide the definition and related lemmas about associated primes of modules. ## Main definition - `IsAssociatedPrime`: `IsAssociatedPrime I M` if the prime ideal `I` is the annihilator of some `x : M`. - `associatedPrimes`: The set of associated primes of a module. ## Main results - `exists_le_isAssociatedPrime_of_isNoetherianRing`: In a Noetherian ring, any `ann(x)` is contained in an associated prime for `x ≠ 0`. - `associatedPrimes.eq_singleton_of_isPrimary`: In a Noetherian ring, `I.radical` is the only associated prime of `R ⧸ I` when `I` is primary. ## TODO Generalize this to a non-commutative setting once there are annihilator for non-commutative rings. -/ variable {R : Type*} [CommRing R] (I J : Ideal R) (M : Type*) [AddCommGroup M] [Module R M] open LinearMap /-- `IsAssociatedPrime I M` if the prime ideal `I` is the annihilator of some `x : M`. -/ def IsAssociatedPrime : Prop := I.IsPrime ∧ ∃ x : M, I = ker (toSpanSingleton R M x) theorem isAssociatedPrime_iff_exists_injective_linearMap : IsAssociatedPrime I M ↔ I.IsPrime ∧ ∃ (f : R ⧸ I →ₗ[R] M), Function.Injective f := by rw [IsAssociatedPrime] congr! 1 refine ⟨fun ⟨_, h⟩ ↦ ⟨Submodule.liftQ _ _ h.le, ker_eq_bot.1 (Submodule.ker_liftQ_eq_bot' _ _ h)⟩, fun ⟨f, h⟩ ↦ ⟨(f ∘ₗ Submodule.mkQ I) 1, ?_⟩⟩ have := I.ker_mkQ ▸ ker_comp_of_ker_eq_bot (Submodule.mkQ I) (ker_eq_bot_of_injective h) convert this.symm using 2 ext; simp variable (R) /-- The set of associated primes of a module. -/ def associatedPrimes : Set (Ideal R) := { I | IsAssociatedPrime I M } variable {I J M R} variable {M' : Type*} [AddCommGroup M'] [Module R M'] (f : M →ₗ[R] M') theorem AssociatePrimes.mem_iff : I ∈ associatedPrimes R M ↔ IsAssociatedPrime I M := Iff.rfl theorem IsAssociatedPrime.isPrime (h : IsAssociatedPrime I M) : I.IsPrime := h.1 theorem IsAssociatedPrime.map_of_injective (h : IsAssociatedPrime I M) (hf : Function.Injective f) : IsAssociatedPrime I M' := by obtain ⟨x, rfl⟩ := h.2 refine ⟨h.1, ⟨f x, ?_⟩⟩ ext r simp_rw [mem_ker, toSpanSingleton_apply, ← map_smul, ← f.map_zero, hf.eq_iff] theorem LinearEquiv.isAssociatedPrime_iff (l : M ≃ₗ[R] M') : IsAssociatedPrime I M ↔ IsAssociatedPrime I M' := ⟨fun h => h.map_of_injective l l.injective, fun h => h.map_of_injective l.symm l.symm.injective⟩ theorem not_isAssociatedPrime_of_subsingleton [Subsingleton M] : ¬IsAssociatedPrime I M := by rintro ⟨hI, x, hx⟩ apply hI.ne_top simpa [Subsingleton.elim x 0] using hx variable (R) in theorem exists_le_isAssociatedPrime_of_isNoetherianRing [H : IsNoetherianRing R] (x : M) (hx : x ≠ 0) : ∃ P : Ideal R, IsAssociatedPrime P M ∧ ker (toSpanSingleton R M x) ≤ P := by have : ker (toSpanSingleton R M x) ≠ ⊤ := by rwa [Ne, Ideal.eq_top_iff_one, mem_ker, toSpanSingleton_apply, one_smul] obtain ⟨P, ⟨l, h₁, y, rfl⟩, h₃⟩ := set_has_maximal_iff_noetherian.mpr H { P | ker (toSpanSingleton R M x) ≤ P ∧ P ≠ ⊤ ∧ ∃ y : M, P = ker (toSpanSingleton R M y) } ⟨_, rfl.le, this, x, rfl⟩ refine ⟨_, ⟨⟨h₁, ?_⟩, y, rfl⟩, l⟩ intro a b hab rw [or_iff_not_imp_left] intro ha rw [mem_ker, toSpanSingleton_apply] at ha hab have H₁ : ker (toSpanSingleton R M y) ≤ ker (toSpanSingleton R M (a • y)) := by intro c hc rw [mem_ker, toSpanSingleton_apply] at hc ⊢ rw [smul_comm, hc, smul_zero] have H₂ : ker (toSpanSingleton R M (a • y)) ≠ ⊤ := by rwa [Ne, ker_eq_top, toSpanSingleton_eq_zero_iff] rwa [H₁.eq_of_not_lt (h₃ _ ⟨l.trans H₁, H₂, _, rfl⟩), mem_ker, toSpanSingleton_apply, smul_comm, smul_smul] namespace associatedPrimes variable {f} {M'' : Type*} [AddCommGroup M''] [Module R M''] {g : M' →ₗ[R] M''} /-- If `M → M'` is injective, then the set of associated primes of `M` is contained in that of `M'`. -/ @[stacks 02M3 "first part"] theorem subset_of_injective (hf : Function.Injective f) : associatedPrimes R M ⊆ associatedPrimes R M' := fun _I h => h.map_of_injective f hf /-- If `0 → M → M' → M''` is an exact sequence, then the set of associated primes of `M'` is contained in the union of those of `M` and `M''`. -/ @[stacks 02M3 "second part"] theorem subset_union_of_exact (hf : Function.Injective f) (hfg : Function.Exact f g) : associatedPrimes R M' ⊆ associatedPrimes R M ∪ associatedPrimes R M'' := by rintro p ⟨_, x, hx⟩ by_cases! h : ∃ a ∈ p.primeCompl, ∃ y : M, f y = a • x · obtain ⟨a, ha, y, h⟩ := h left refine ⟨‹_›, y, le_antisymm (fun b hb ↦ ?_) (fun b hb ↦ ?_)⟩ · rw [hx] at hb rw [LinearMap.mem_ker, LinearMap.toSpanSingleton_apply] at hb ⊢ apply_fun _ using hf rw [map_smul, map_zero, h, smul_comm, hb, smul_zero] · rw [LinearMap.mem_ker, LinearMap.toSpanSingleton_apply] at hb apply_fun f at hb rw [map_smul, map_zero, h, ← mul_smul, ← LinearMap.toSpanSingleton_apply, ← LinearMap.mem_ker, ← hx] at hb contrapose! hb exact p.primeCompl.mul_mem hb ha · right refine ⟨‹_›, g x, le_antisymm (fun b hb ↦ ?_) (fun b hb ↦ ?_)⟩ · rw [hx] at hb rw [LinearMap.mem_ker, LinearMap.toSpanSingleton_apply] at hb ⊢ rw [← map_smul, hb, map_zero] · rw [LinearMap.mem_ker, LinearMap.toSpanSingleton_apply, ← map_smul, ← LinearMap.mem_ker, hfg.linearMap_ker_eq] at hb obtain ⟨y, hy⟩ := hb by_contra! H exact h b H y hy variable (R M M') in /-- The set of associated primes of the product of two modules is equal to the union of those of the two modules. -/ @[stacks 02M3 "third part"] theorem prod : associatedPrimes R (M × M') = associatedPrimes R M ∪ associatedPrimes R M' := (subset_union_of_exact LinearMap.inl_injective .inl_snd).antisymm (Set.union_subset_iff.2 ⟨subset_of_injective LinearMap.inl_injective, subset_of_injective LinearMap.inr_injective⟩) end associatedPrimes theorem LinearEquiv.AssociatedPrimes.eq (l : M ≃ₗ[R] M') : associatedPrimes R M = associatedPrimes R M' := le_antisymm (associatedPrimes.subset_of_injective l.injective) (associatedPrimes.subset_of_injective l.symm.injective) theorem associatedPrimes.eq_empty_of_subsingleton [Subsingleton M] : associatedPrimes R M = ∅ := by ext; simp only [Set.mem_empty_iff_false, iff_false] apply not_isAssociatedPrime_of_subsingleton variable (R M) theorem associatedPrimes.nonempty [IsNoetherianRing R] [Nontrivial M] : (associatedPrimes R M).Nonempty := by obtain ⟨x, hx⟩ := exists_ne (0 : M) obtain ⟨P, hP, _⟩ := exists_le_isAssociatedPrime_of_isNoetherianRing R x hx exact ⟨P, hP⟩ theorem biUnion_associatedPrimes_eq_zero_divisors [IsNoetherianRing R] : ⋃ p ∈ associatedPrimes R M, p = { r : R | ∃ x : M, x ≠ 0 ∧ r • x = 0 } := by refine subset_antisymm (Set.iUnion₂_subset ?_) ?_ · rintro _ ⟨h, x, ⟨⟩⟩ r h' refine ⟨x, ne_of_eq_of_ne (one_smul R x).symm ?_, h'⟩ exact (Ideal.ne_top_iff_one _).mp h.ne_top · intro r ⟨x, h, h'⟩ obtain ⟨P, hP, hx⟩ := exists_le_isAssociatedPrime_of_isNoetherianRing R x h exact Set.mem_biUnion hP (hx h') theorem biUnion_associatedPrimes_eq_compl_nonZeroDivisors [IsNoetherianRing R] : ⋃ p ∈ associatedPrimes R R, p = (nonZeroDivisors R : Set R)ᶜ := (biUnion_associatedPrimes_eq_zero_divisors R R).trans <| by ext; simp [← nonZeroDivisorsLeft_eq_nonZeroDivisors, and_comm] variable {R M} theorem IsAssociatedPrime.annihilator_le (h : IsAssociatedPrime I M) : (⊤ : Submodule R M).annihilator ≤ I := by obtain ⟨hI, x, rfl⟩ := h rw [← Submodule.annihilator_span_singleton] exact Submodule.annihilator_mono le_top theorem IsAssociatedPrime.eq_radical (hI : I.IsPrimary) (h : IsAssociatedPrime J (R ⧸ I)) : J = I.radical := by obtain ⟨hJ, x, e⟩ := h have : x ≠ 0 := by rintro rfl apply hJ.1 rwa [toSpanSingleton_zero, ker_zero] at e obtain ⟨x, rfl⟩ := Ideal.Quotient.mkₐ_surjective R _ x replace e : ∀ {y}, y ∈ J ↔ x * y ∈ I := by intro y rw [e, mem_ker, toSpanSingleton_apply, ← map_smul, smul_eq_mul, mul_comm, Ideal.Quotient.mkₐ_eq_mk, ← Ideal.Quotient.mk_eq_mk, Submodule.Quotient.mk_eq_zero] apply le_antisymm · intro y hy exact ((Ideal.isPrimary_iff.1 hI).2 <| e.mp hy).resolve_left ((Submodule.Quotient.mk_eq_zero I).not.mp this) · rw [hJ.radical_le_iff] intro y hy exact e.mpr (I.mul_mem_left x hy) theorem associatedPrimes.eq_singleton_of_isPrimary [IsNoetherianRing R] (hI : I.IsPrimary) : associatedPrimes R (R ⧸ I) = {I.radical} := by ext J rw [Set.mem_singleton_iff] refine ⟨IsAssociatedPrime.eq_radical hI, ?_⟩ rintro rfl haveI : Nontrivial (R ⧸ I) := by refine ⟨(Ideal.Quotient.mk I :) 1, (Ideal.Quotient.mk I :) 0, ?_⟩ rw [Ne, Ideal.Quotient.eq, sub_zero, ← Ideal.eq_top_iff_one] exact hI.1 obtain ⟨a, ha⟩ := associatedPrimes.nonempty R (R ⧸ I) exact ha.eq_radical hI ▸ ha
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/AssociatedPrime/Localization.lean
import Mathlib.Algebra.Module.LocalizedModule.Basic import Mathlib.RingTheory.Ideal.AssociatedPrime.Basic import Mathlib.RingTheory.Localization.AtPrime.Basic /-! # Associated primes of localized module This file mainly proves the relation between `Ass(S⁻¹M)` and `Ass(M)` ## Main Results * `associatedPrimes.mem_associatePrimes_of_comap_mem_associatePrimes_isLocalizedModule` : for an `R` module `M`, if `p` is a prime ideal of `S⁻¹R` and `p ∩ R ∈ Ass(M)` then `p ∈ Ass (S⁻¹M)`. TODO: prove the reverse when `p` is finitely generated and get `Ass (S⁻¹M) = Ass(M) ∩ Spec(S⁻¹R)` when `R` Noetherian. TODO: deduce from the above that every minimal element in support is in `Ass(M)`. -/ variable {R : Type*} [CommRing R] (S : Submonoid R) (R' : Type*) [CommRing R'] [Algebra R R'] [IsLocalization S R'] variable {M M' : Type*} [AddCommGroup M] [Module R M] [AddCommGroup M'] [Module R M'] (f : M →ₗ[R] M') [IsLocalizedModule S f] [Module R' M'] [IsScalarTower R R' M'] open IsLocalRing LinearMap namespace Module.associatedPrimes include S f in lemma mem_associatePrimes_of_comap_mem_associatePrimes_isLocalizedModule (p : Ideal R') [p.IsPrime] (ass : p.comap (algebraMap R R') ∈ associatedPrimes R M) : p ∈ associatedPrimes R' M' := by rcases ass with ⟨hp, x, hx⟩ constructor · /- use the following to remove `p.IsPrime` exact (IsLocalization.isPrime_iff_isPrime_disjoint S _ _).mpr ⟨hp, (IsLocalization.disjoint_comap_iff S R' p).mpr (p ≠ ⊤)⟩ -/ assumption · use f x ext t rcases IsLocalization.exists_mk'_eq S t with ⟨r, s, hrs⟩ rw [← IsLocalizedModule.mk'_one S, ← hrs, mem_ker, toSpanSingleton_apply, IsLocalizedModule.mk'_smul_mk', mul_one, IsLocalizedModule.mk'_eq_zero'] refine ⟨fun h ↦ ?_, fun ⟨t, ht⟩ ↦ ?_⟩ · use 1 simp only [← toSpanSingleton_apply, one_smul, ← mem_ker, ← hx, Ideal.mem_comap] have : (algebraMap R R') r = IsLocalization.mk' R' r s * IsLocalization.mk' R' s.1 (1 : S) := by rw [← IsLocalization.mk'_one (M := S) R', ← sub_eq_zero, ← IsLocalization.mk'_mul, ← IsLocalization.mk'_sub] simp rw [this] exact Ideal.IsTwoSided.mul_mem_of_left _ h · have : t • r • x = (t.1 * r) • x := smul_smul t.1 r x rw [this, ← LinearMap.toSpanSingleton_apply, ← LinearMap.mem_ker, ← hx, Ideal.mem_comap, ← IsLocalization.mk'_one (M := S) R'] at ht have : IsLocalization.mk' R' r s = IsLocalization.mk' (M := S) R' (t.1 * r) 1 * IsLocalization.mk' R' 1 (t * s) := by rw [← IsLocalization.mk'_mul, mul_one, one_mul, ← sub_eq_zero, ← IsLocalization.mk'_sub, Submonoid.coe_mul] simp [← mul_assoc, mul_comm r t.1, IsLocalization.mk'_zero] simpa [this] using Ideal.IsTwoSided.mul_mem_of_left _ ht lemma mem_associatePrimes_localizedModule_atPrime_of_mem_associated_primes {p : Ideal R} [p.IsPrime] (ass : p ∈ associatedPrimes R M) : maximalIdeal (Localization.AtPrime p) ∈ associatedPrimes (Localization.AtPrime p) (LocalizedModule p.primeCompl M) := by apply mem_associatePrimes_of_comap_mem_associatePrimes_isLocalizedModule p.primeCompl (Localization.AtPrime p) (LocalizedModule.mkLinearMap p.primeCompl M) simpa [Localization.AtPrime.comap_maximalIdeal] using ass end Module.associatedPrimes
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/AssociatedPrime/Finiteness.lean
import Mathlib.Order.RelSeries import Mathlib.RingTheory.Ideal.AssociatedPrime.Basic import Mathlib.RingTheory.Localization.FractionRing import Mathlib.RingTheory.Noetherian.Basic import Mathlib.RingTheory.Spectrum.Prime.Defs import Mathlib.RingTheory.Spectrum.Maximal.Basic /-! # Finitely generated module over Noetherian ring have finitely many associated primes. In this file we proved that any finitely generated module over a Noetherian ring have finitely many associated primes. ## Main results * `IsNoetherianRing.exists_relSeries_isQuotientEquivQuotientPrime`: If `A` is a Noetherian ring and `M` is a finitely generated `A`-module, then there exists a chain of submodules `0 = M₀ ≤ M₁ ≤ M₂ ≤ ... ≤ Mₙ = M` of `M`, such that for each `0 ≤ i < n`, `Mᵢ₊₁ / Mᵢ` is isomorphic to `A / pᵢ` for some prime ideal `pᵢ` of `A`. * `IsNoetherianRing.induction_on_isQuotientEquivQuotientPrime`: If a property on finitely generated modules over a Noetherian ring satisfies that: - it holds for zero module, - it holds for any module isomorphic to some `A ⧸ p` where `p` is a prime ideal of `A`, - it is stable by short exact sequences, then the property holds for every finitely generated modules. * `associatedPrimes.finite`: There are only finitely many associated primes of a finitely generated module over a Noetherian ring. -/ universe u v variable {A : Type u} [CommRing A] {M : Type v} [AddCommGroup M] [Module A M] /-- A `Prop` asserting that two submodules `N₁, N₂` satisfy `N₁ ≤ N₂` and `N₂ / N₁` is isomorphic to `A / p` for some prime ideal `p` of `A`. -/ def Submodule.IsQuotientEquivQuotientPrime (N₁ N₂ : Submodule A M) := N₁ ≤ N₂ ∧ ∃ (p : PrimeSpectrum A), Nonempty ((↥N₂ ⧸ N₁.submoduleOf N₂) ≃ₗ[A] A ⧸ p.1) open LinearMap in theorem Submodule.isQuotientEquivQuotientPrime_iff {N₁ N₂ : Submodule A M} : N₁.IsQuotientEquivQuotientPrime N₂ ↔ ∃ x, Ideal.IsPrime (ker (toSpanSingleton A _ (N₁.mkQ x))) ∧ N₂ = N₁ ⊔ span A {x} := by let f := mapQ (N₁.submoduleOf N₂) N₁ N₂.subtype le_rfl have hf₁ : ker f = ⊥ := ker_liftQ_eq_bot _ _ _ (by simp [ker_comp, submoduleOf]) have hf₂ : range f = N₂.map N₁.mkQ := by simp [f, mapQ, range_liftQ, range_comp] refine ⟨fun ⟨h, p, ⟨e⟩⟩ ↦ ?_, fun ⟨x, hx, hx'⟩ ↦ ⟨le_sup_left.trans_eq hx'.symm, ⟨_, hx⟩, ?_⟩⟩ · obtain ⟨⟨x, hx⟩, hx'⟩ := Submodule.mkQ_surjective _ (e.symm 1) have hx'' : N₁.mkQ x = f (e.symm 1) := by simp [f, ← hx'] refine ⟨x, ?_, ?_⟩ · convert p.2 ext r simp [hx'', ← map_smul, Algebra.smul_def, show f _ = 0 ↔ _ from congr(_ ∈ $hf₁), Ideal.Quotient.eq_zero_iff_mem] · refine le_antisymm ?_ (sup_le h ((span_singleton_le_iff_mem _ _).mpr hx)) have : (span A {x}).map N₁.mkQ = ((span A {1}).map e.symm).map f := by simp only [map_span, Set.image_singleton, hx''] rw [← N₁.ker_mkQ, sup_comm, ← comap_map_eq, ← map_le_iff_le_comap, this] simp [hf₂, Ideal.Quotient.span_singleton_one] · have hxN₂ : x ∈ N₂ := (le_sup_right.trans_eq hx'.symm) (mem_span_singleton_self x) refine ⟨.symm (.ofBijective (Submodule.mapQ _ _ (toSpanSingleton A _ ⟨x, hxN₂⟩) ?_) ⟨?_, ?_⟩)⟩ · simp [SetLike.le_def, ← Quotient.mk_smul, submoduleOf] · refine ker_eq_bot.mp (ker_liftQ_eq_bot _ _ _ ?_) simp [← Quotient.mk_smul, SetLike.le_def, submoduleOf] · rw [mapQ, ← range_eq_top, range_liftQ, range_comp] have := congr($(hx').submoduleOf N₂) rw [submoduleOf_self, submoduleOf_sup_of_le (by simp_all) (by simp_all), submoduleOf_span_singleton_of_mem _ hxN₂] at this simpa [← span_singleton_eq_range, LinearMap.range_toSpanSingleton] using this.symm variable (A M) [IsNoetherianRing A] [Module.Finite A M] /-- If `A` is a Noetherian ring and `M` is a finitely generated `A`-module, then there exists a chain of submodules `0 = M₀ ≤ M₁ ≤ M₂ ≤ ... ≤ Mₙ = M` of `M`, such that for each `0 ≤ i < n`, `Mᵢ₊₁ / Mᵢ` is isomorphic to `A / pᵢ` for some prime ideal `pᵢ` of `A`. -/ @[stacks 00L0] theorem IsNoetherianRing.exists_relSeries_isQuotientEquivQuotientPrime : ∃ s : RelSeries {(N₁, N₂) | Submodule.IsQuotientEquivQuotientPrime (A := A) (M := M) N₁ N₂}, s.head = ⊥ ∧ s.last = ⊤ := by refine WellFoundedGT.induction_top ⟨⊥, .singleton _ ⊥, rfl, rfl⟩ ?_ rintro N hN ⟨s, hs₁, hs₂⟩ have := Submodule.Quotient.nontrivial_of_lt_top _ hN.lt_top obtain ⟨p, hp, x, rfl⟩ := associatedPrimes.nonempty A (M ⧸ N) obtain ⟨x, rfl⟩ := Submodule.mkQ_surjective _ x have hxN : x ∉ N := fun h ↦ hp.ne_top (by rw [show N.mkQ x = 0 by simpa]; simp) have := Submodule.isQuotientEquivQuotientPrime_iff.mpr ⟨x, hp, rfl⟩ refine ⟨_, by simpa [hs₂], s.snoc _ (hs₂ ▸ this), by simpa, rfl⟩ /-- If a property on finitely generated modules over a Noetherian ring satisfies that: - it holds for zero module (it's formalized as it holds for any module which is subsingleton), - it holds for `A ⧸ p` for every prime ideal `p` of `A` (to avoid universe problem, it's formalized as it holds for any module isomorphic to `A ⧸ p`), - it is stable by short exact sequences, then the property holds for every finitely generated modules. NOTE: This should be the induction principle for `M`, but due to the bug https://github.com/leanprover/lean4/issues/4246 currently it is induction for `Module.Finite A M`. -/ @[elab_as_elim] theorem IsNoetherianRing.induction_on_isQuotientEquivQuotientPrime ⦃M : Type v⦄ [AddCommGroup M] [Module A M] (_ : Module.Finite A M) {motive : (N : Type v) → [AddCommGroup N] → [Module A N] → [Module.Finite A N] → Prop} (subsingleton : (N : Type v) → [AddCommGroup N] → [Module A N] → [Module.Finite A N] → [Subsingleton N] → motive N) (quotient : (N : Type v) → [AddCommGroup N] → [Module A N] → [Module.Finite A N] → (p : PrimeSpectrum A) → (N ≃ₗ[A] A ⧸ p.1) → motive N) (exact : (N₁ : Type v) → [AddCommGroup N₁] → [Module A N₁] → [Module.Finite A N₁] → (N₂ : Type v) → [AddCommGroup N₂] → [Module A N₂] → [Module.Finite A N₂] → (N₃ : Type v) → [AddCommGroup N₃] → [Module A N₃] → [Module.Finite A N₃] → (f : N₁ →ₗ[A] N₂) → (g : N₂ →ₗ[A] N₃) → Function.Injective f → Function.Surjective g → Function.Exact f g → motive N₁ → motive N₃ → motive N₂) : motive M := by have equiv (N₁ : Type v) [AddCommGroup N₁] [Module A N₁] [Module.Finite A N₁] (N₂ : Type v) [AddCommGroup N₂] [Module A N₂] [Module.Finite A N₂] (f : N₁ ≃ₗ[A] N₂) (h : motive N₁) : motive N₂ := exact N₁ N₂ PUnit.{v + 1} f 0 f.injective (Function.surjective_to_subsingleton _) ((f.exact_zero_iff_surjective _).2 f.surjective) h (subsingleton _) obtain ⟨s, hs1, hs2⟩ := IsNoetherianRing.exists_relSeries_isQuotientEquivQuotientPrime A M suffices H : ∀ n, (h : n < s.length + 1) → motive (s ⟨n, h⟩) by replace H : motive s.last := H s.length s.length.lt_add_one rw [hs2] at H exact equiv _ _ Submodule.topEquiv H intro n h induction n with | zero => change motive s.head rw [hs1] exact subsingleton _ | succ n ih => specialize ih (n.lt_add_one.trans h) obtain ⟨hle, p, ⟨f⟩⟩ := s.step ⟨n, (add_lt_add_iff_right _).1 h⟩ replace ih := equiv _ _ (Submodule.submoduleOfEquivOfLe hle).symm ih exact exact _ _ _ _ _ (Submodule.injective_subtype _) (Submodule.mkQ_surjective _) (LinearMap.exact_subtype_mkQ _) ih (quotient _ p f) /-- There are only finitely many associated primes of a finitely generated module over a Noetherian ring. -/ @[stacks 00LC] theorem associatedPrimes.finite : (associatedPrimes A M).Finite := by induction ‹Module.Finite A M› using IsNoetherianRing.induction_on_isQuotientEquivQuotientPrime A with | subsingleton N => simp [associatedPrimes.eq_empty_of_subsingleton] | quotient N p f => have := associatedPrimes.eq_singleton_of_isPrimary p.2.isPrimary simp [LinearEquiv.AssociatedPrimes.eq f, this] | exact N₁ N₂ N₃ f g hf _ hfg h₁ h₃ => exact (h₁.union h₃).subset (associatedPrimes.subset_union_of_exact hf hfg) /-- Every maximal ideal of a commutative Noetherian total ring of fractions `A` is an associated prime of the `A`-module `A`. -/ theorem Ideal.IsMaximal.mem_associatedPrimes_of_isFractionRing [IsFractionRing A A] (I : Ideal A) [hI : I.IsMaximal] : I ∈ associatedPrimes A A := have fin := associatedPrimes.finite A A have ⟨P, hP⟩ := (I.subset_union_prime_finite fin (f := id) 0 0 fun _ h _ _ ↦ h.isPrime).1 <| by simp_rw [id, biUnion_associatedPrimes_eq_compl_nonZeroDivisors] exact fun x hx h ↦ hI.ne_top <| I.eq_top_of_isUnit_mem hx (IsFractionRing.self_iff_nonZeroDivisors_le_isUnit.mp ‹_› h) hI.eq_of_le hP.1.isPrime.ne_top hP.2 ▸ hP.1 /-- A commutative Noetherian total ring of fractions is semilocal. -/ instance [IsFractionRing A A] : Finite (MaximalSpectrum A) := (MaximalSpectrum.equivSubtype A).finite_iff.mpr <| Set.finite_coe_iff.mpr <| (associatedPrimes.finite A A).subset fun _ ↦ (·.mem_associatedPrimes_of_isFractionRing)
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/Norm/RelNorm.lean
import Mathlib.Algebra.GroupWithZero.Torsion import Mathlib.NumberTheory.RamificationInertia.Galois import Mathlib.RingTheory.DedekindDomain.Factorization import Mathlib.RingTheory.DedekindDomain.Instances import Mathlib.RingTheory.Ideal.Int import Mathlib.RingTheory.NormalClosure /-! # Ideal norms This file defines 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 * `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.relNorm`: multiplicativity of the relative ideal norm * `relNorm_relNorm`: transitivity of the relative ideal norm -/ open scoped nonZeroDivisors section SpanNorm namespace Ideal open Submodule variable (R S : Type*) [CommRing R] [IsDomain R] {S : Type*} [CommRing S] [IsDomain S] variable [IsIntegrallyClosed R] [IsIntegrallyClosed S] [Algebra R S] [Module.Finite R S] variable [NoZeroSMulDivisors R S] attribute [local instance] FractionRing.liftAlgebra /-- `Ideal.spanNorm R (I : Ideal S)` is the ideal generated by mapping `Algebra.intNorm R S` over `I`. See also `Ideal.relNorm`. -/ noncomputable def spanNorm (I : Ideal S) : Ideal R := Ideal.map (Algebra.intNorm R S) I @[simp] theorem spanNorm_bot : spanNorm R (⊥ : Ideal S) = ⊥ := span_eq_bot.mpr fun x hx => by simpa using hx variable {R} in @[simp] theorem spanNorm_eq_bot_iff {I : Ideal S} : spanNorm R I = ⊥ ↔ I = ⊥ := by simp only [spanNorm, span_eq_bot, Set.mem_image, SetLike.mem_coe, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂, Algebra.intNorm_eq_zero, @eq_bot_iff _ _ _ I, SetLike.le_def, map, mem_bot] theorem intNorm_mem_spanNorm {I : Ideal S} {x : S} (hx : x ∈ I) : Algebra.intNorm R S x ∈ I.spanNorm R := subset_span (Set.mem_image_of_mem _ hx) theorem norm_mem_spanNorm [Module.Free R S] {I : Ideal S} (x : S) (hx : x ∈ I) : Algebra.norm R x ∈ I.spanNorm R := by refine subset_span ⟨x, hx, ?_⟩ rw [Algebra.intNorm_eq_norm] @[simp] theorem spanNorm_singleton {r : S} : spanNorm R (span ({r} : Set S)) = span {Algebra.intNorm R S 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 (intNorm_mem_spanNorm _ (mem_span_singleton_self _))) @[simp] theorem spanNorm_top : spanNorm R (⊤ : Ideal S) = ⊤ := by simp [← Ideal.span_singleton_one] theorem map_spanIntNorm (I : Ideal S) {T : Type*} [Semiring T] (f : R →+* T) : map f (spanNorm R I) = span (f ∘ Algebra.intNorm R S '' (I : Set S)) := by rw [spanNorm] nth_rw 2 [map] simp [map_span, Set.image_image] @[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 spanIntNorm_localization (I : Ideal S) (M : Submonoid R) (hM : M ≤ 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ₘ] [IsIntegrallyClosed Rₘ] [IsDomain Rₘ] [IsDomain Sₘ] [NoZeroSMulDivisors Rₘ Sₘ] [Module.Finite Rₘ Sₘ] [IsIntegrallyClosed Sₘ] : spanNorm Rₘ (I.map (algebraMap S Sₘ)) = (spanNorm R I).map (algebraMap R Rₘ) := by let K := FractionRing R let f : Rₘ →+* K := IsLocalization.map _ (T := R⁰) (RingHom.id R) hM let L := FractionRing S let g : Sₘ →+* L := IsLocalization.map _ (M := Algebra.algebraMapSubmonoid S M) (T := S⁰) (RingHom.id S) (Submonoid.map_le_of_le_comap _ <| hM.trans (nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ (FaithfulSMul.algebraMap_injective _ _))) algebraize [f, g, (algebraMap K L).comp f] have : IsScalarTower R Rₘ K := IsScalarTower.of_algebraMap_eq' (by rw [RingHom.algebraMap_toAlgebra, IsLocalization.map_comp, RingHomCompTriple.comp_eq]) let _ := IsFractionRing.isFractionRing_of_isDomain_of_isLocalization M Rₘ K have : IsScalarTower S Sₘ L := IsScalarTower.of_algebraMap_eq' (by rw [RingHom.algebraMap_toAlgebra, IsLocalization.map_comp, RingHomCompTriple.comp_eq]) have : IsScalarTower Rₘ Sₘ L := by apply IsScalarTower.of_algebraMap_eq' apply IsLocalization.ringHom_ext M rw [RingHom.algebraMap_toAlgebra, RingHom.algebraMap_toAlgebra (R := Sₘ), RingHom.comp_assoc, RingHom.comp_assoc, ← IsScalarTower.algebraMap_eq, IsScalarTower.algebraMap_eq R S Sₘ, IsLocalization.map_comp, RingHom.comp_id, ← RingHom.comp_assoc, IsLocalization.map_comp, RingHom.comp_id, ← IsScalarTower.algebraMap_eq, ← IsScalarTower.algebraMap_eq] let _ := IsFractionRing.isFractionRing_of_isDomain_of_isLocalization (Algebra.algebraMapSubmonoid S M) Sₘ L rw [map_spanIntNorm] refine span_eq_span (Set.image_subset_iff.mpr ?_) (Set.image_subset_iff.mpr ?_) · intro a' ha' simp only [Set.mem_preimage, submodule_span_eq, ← map_spanIntNorm, 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.intNorm R S a, intNorm_mem_spanNorm _ ha⟩, ⟨s ^ Module.finrank K L, pow_mem hs _⟩, ?_⟩ simp only [map_pow] at has ⊢ apply_fun algebraMap _ L at has apply_fun Algebra.norm K at has simp only [map_mul] at has rw [← IsScalarTower.algebraMap_apply, ← IsScalarTower.algebraMap_apply, ← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R K L, Algebra.norm_algebraMap] at has apply IsFractionRing.injective Rₘ K simp only [map_mul, map_pow] rwa [Algebra.algebraMap_intNorm (L := L), ← IsScalarTower.algebraMap_apply, ← IsScalarTower.algebraMap_apply, Algebra.algebraMap_intNorm (L := L)] · intro a ha rw [Set.mem_preimage, Function.comp_apply, Algebra.intNorm_eq_of_isLocalization M (Bₘ := Sₘ)] 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] nth_rw 1 [map]; nth_rw 1 [map] rw [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 (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 _ _) rcases 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] rcases 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 theorem spanNorm_le_comap (I : Ideal S) : spanNorm R I ≤ comap (algebraMap R S) I := by rw [spanNorm, Ideal.map, Ideal.span_le, ← Submodule.span_le] intro x hx induction hx using Submodule.span_induction with | mem _ h => obtain ⟨x, hx, rfl⟩ := h exact mem_comap.mpr <| mem_of_dvd _ (Algebra.dvd_algebraMap_intNorm_self _ _ x) hx | zero => simp | add _ _ _ _ hx hy => exact Submodule.add_mem _ hx hy | smul _ _ _ hx => exact Submodule.smul_mem _ _ hx /-- Multiplicativity of `Ideal.spanNorm`. simp-normal form is `map_mul (Ideal.relNorm R)`. -/ theorem spanNorm_mul [IsDedekindDomain R] [IsDedekindDomain S] (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] refine eq_of_localization_maximal (fun P hP ↦ ?_) by_cases hP0 : P = ⊥ · subst hP0 rw [spanNorm_mul_of_bot_or_top] intro I exact or_iff_not_imp_right.mpr fun hI ↦ (hP.eq_of_le hI bot_le).symm have : NeZero P := ⟨hP0⟩ let P' := Algebra.algebraMapSubmonoid S P.primeCompl simp only [Ideal.map_mul, ← spanIntNorm_localization (R := R) (Sₘ := Localization P') _ _ P.primeCompl_le_nonZeroDivisors] rw [← (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, map_mul] section spanNorm_spanNorm variable (T : Type*) [CommRing T] [IsDomain T] [IsIntegrallyClosed T] [Algebra R T] [Algebra T S] [Module.Finite R T] [Module.Finite T S] [NoZeroSMulDivisors R T] [NoZeroSMulDivisors T S] [IsScalarTower R T S] open _root_.Algebra theorem le_spanNorm_spanNorm (I : Ideal S) : spanNorm R I ≤ spanNorm R (spanNorm T I) := by simp_rw [spanNorm, map] refine span_mono ?_ rintro _ ⟨x, hx, rfl⟩ exact ⟨intNorm T S x, subset_span <| Set.mem_image_of_mem _ hx, by rw [intNorm_intNorm]⟩ /-- This condition `eq_bot_or_top` is equivalent to being a field. However, `Ideal.spanNorm_spanNorm_of_field` would be harder to apply since we'd need to upgrade a `CommRing R` instance to a `Field R` instance. -/ theorem spanNorm_spanNorm_of_bot_or_top (eq_bot_or_top : ∀ I : Ideal R, I = ⊥ ∨ I = ⊤) (I : Ideal S) : spanNorm R (spanNorm T I) = spanNorm R I := by obtain h | h := eq_bot_or_top (spanNorm R I) · rw [h, spanNorm_eq_bot_iff, spanNorm_eq_bot_iff, spanNorm_eq_bot_iff.mp h] · exact h ▸ (eq_top_iff_one _).mpr <| le_spanNorm_spanNorm R T I <| (eq_top_iff_one _).mp h attribute [local instance] Localization.AtPrime.algebra_localization_localization theorem spanNorm_spanNorm [IsDedekindDomain R] [IsDedekindDomain T] [IsDedekindDomain S] (I : Ideal S) : spanNorm R (spanNorm T I) = spanNorm R I := by refine eq_of_localization_maximal fun P hP ↦ ?_ by_cases hP : P = ⊥ · subst hP rw [spanNorm_spanNorm_of_bot_or_top] exact fun I ↦ or_iff_not_imp_right.mpr fun hI ↦ (hP.eq_of_le hI bot_le).symm let Rₚ := Localization.AtPrime P let Tₚ := Localization (algebraMapSubmonoid T P.primeCompl) let Sₚ := Localization (algebraMapSubmonoid S P.primeCompl) have : NeZero P := ⟨hP⟩ have h : algebraMapSubmonoid T P.primeCompl ≤ T⁰ := algebraMapSubmonoid_le_nonZeroDivisors_of_faithfulSMul _ (primeCompl_le_nonZeroDivisors P) rw [← spanIntNorm_localization R (spanNorm T I) _ (primeCompl_le_nonZeroDivisors P) Tₚ, ← spanIntNorm_localization T (Rₘ := Tₚ) I _ h Sₚ, ← spanIntNorm_localization R (Rₘ := Rₚ) I _ (primeCompl_le_nonZeroDivisors P) Sₚ, ← (I.map _).span_singleton_generator, spanNorm_singleton, spanNorm_singleton, intNorm_intNorm, spanNorm_singleton] end spanNorm_spanNorm variable [IsDedekindDomain R] [IsDedekindDomain S] /-- 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. -/ noncomputable def relNorm : Ideal S →*₀ Ideal R where toFun := spanNorm R map_zero' := spanNorm_bot R map_one' := by 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.intNorm R S '' (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 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} in @[simp] theorem relNorm_eq_bot_iff {I : Ideal S} : relNorm R I = ⊥ ↔ I = ⊥ := spanNorm_eq_bot_iff theorem norm_mem_relNorm [Module.Free R S] (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.intNorm R S r} := spanNorm_singleton R theorem map_relNorm (I : Ideal S) {T : Type*} [Semiring T] (f : R →+* T) : map f (relNorm R I) = span (f ∘ Algebra.intNorm R S '' (I : Set S)) := map_spanIntNorm R I f @[mono] theorem relNorm_mono {I J : Ideal S} (h : I ≤ J) : relNorm R I ≤ relNorm R J := spanNorm_mono R h variable {R} private theorem relNorm_map_algEquiv_aux {T : Type*} [CommRing T] [IsDedekindDomain T] [IsIntegrallyClosed T] [Algebra R T] [Module.Finite R T] [NoZeroSMulDivisors R T] (σ : S ≃ₐ[R] T) (I : Ideal S) : relNorm R (I.map σ) ≤ relNorm R I := span_mono fun _ ⟨x, hx₁, hx₂⟩ ↦ ⟨σ.toRingEquiv.symm x, by rwa [SetLike.mem_coe, Ideal.symm_apply_mem_of_equiv_iff], hx₂ ▸ Algebra.intNorm_map_algEquiv _ x σ.symm⟩ @[simp] theorem relNorm_map_algEquiv {T : Type*} [CommRing T] [IsDedekindDomain T] [IsIntegrallyClosed T] [Algebra R T] [Module.Finite R T] [NoZeroSMulDivisors R T] (σ : S ≃ₐ[R] T) (I : Ideal S) : relNorm R (I.map σ) = relNorm R I := by refine le_antisymm (relNorm_map_algEquiv_aux σ I) ?_ convert relNorm_map_algEquiv_aux σ.symm (I.map σ) change I = map σ.symm.toAlgHom (map σ.toAlgHom I) simp [map_mapₐ] @[simp] theorem relNorm_comap_algEquiv {T : Type*} [CommRing T] [IsDedekindDomain T] [IsIntegrallyClosed T] [Algebra R T] [Module.Finite R T] [NoZeroSMulDivisors R T] (σ : S ≃ₐ[R] T) (I : Ideal T) : relNorm R (I.comap σ) = relNorm R I := map_symm σ.toRingEquiv ▸ relNorm_map_algEquiv σ.symm I variable (R) open MulSemiringAction Pointwise in @[simp] theorem relNorm_smul {G : Type*} [Group G] [MulSemiringAction G S] [SMulCommClass G R S] (g : G) (I : Ideal S) : relNorm R (g • I) = relNorm R I := relNorm_map_algEquiv (toAlgEquiv R S g) I theorem relNorm_le_comap (I : Ideal S) : relNorm R I ≤ comap (algebraMap R S) I := spanNorm_le_comap R I theorem relNorm_relNorm (T : Type*) [CommRing T] [IsDedekindDomain T] [IsIntegrallyClosed T] [Algebra R T] [Algebra T S] [IsScalarTower R T S] [Module.Finite R T] [Module.Finite T S] [NoZeroSMulDivisors R T] [NoZeroSMulDivisors T S] (I : Ideal S) : relNorm R (relNorm T I) = relNorm R I := spanNorm_spanNorm _ _ _ variable {R} (S) attribute [local instance] Localization.AtPrime.liftAlgebra in theorem relNorm_algebraMap (I : Ideal R) : relNorm R (I.map (algebraMap R S)) = I ^ Module.finrank (FractionRing R) (FractionRing S) := by rw [← spanNorm_eq] refine eq_of_localization_maximal (fun P hPd ↦ ?_) let P' := Algebra.algebraMapSubmonoid S P.primeCompl let Rₚ := Localization.AtPrime P let K := FractionRing R rw [← spanIntNorm_localization R _ _ P.primeCompl_le_nonZeroDivisors (Localization P'), Ideal.map_pow, I.map_map, ← IsScalarTower.algebraMap_eq, IsScalarTower.algebraMap_eq R Rₚ, ← I.map_map, ← (I.map _).span_singleton_generator, Ideal.map_span, Set.image_singleton, spanNorm_singleton, Ideal.span_singleton_pow] congr 2 apply IsFractionRing.injective Rₚ K rw [Algebra.algebraMap_intNorm (L := FractionRing S), ← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply Rₚ K, Algebra.norm_algebraMap, map_pow] variable (R) /-- A version of `relNorm_algebraMap` involving a tower of algebras `S/R/R'`. -/ theorem relNorm_algebraMap' {R'} [CommRing R'] (I : Ideal R') [Algebra R' R] [Algebra R' S] [IsScalarTower R' R S] : relNorm R (I.map (algebraMap R' S)) = I.map (algebraMap R' R) ^ Module.finrank (FractionRing R) (FractionRing S) := by rw [← relNorm_algebraMap, Ideal.map_map, IsScalarTower.algebraMap_eq R' R S] section relNorm_prime variable {R} {S} (P : Ideal S) (p : Ideal R) [hPp : P.LiesOver p] /-- See `Ideal.relNorm_eq_pow_of_isMaximal` for a more precise statement when `p` is a maximal ideal. -/ theorem exists_relNorm_eq_pow_of_isPrime [p.IsPrime] : ∃ s, relNorm R P = p ^ s := by by_cases hp : p = ⊥ · refine ⟨1, ?_⟩ have : P.LiesOver ⊥ := hp ▸ hPp rw [hp, eq_bot_of_liesOver_bot R P, relNorm_bot, bot_pow (one_ne_zero)] have h : relNorm R (map (algebraMap R S) p) ≤ relNorm R P := relNorm_mono _ <| map_le_iff_le_comap.mpr <| le_of_eq <| (liesOver_iff _ _).mp hPp rw [relNorm_algebraMap S, ← dvd_iff_le, dvd_prime_pow (prime_of_isPrime hp inferInstance)] at h obtain ⟨s, _, hs⟩ := h exact ⟨s, by rwa [associated_iff_eq] at hs⟩ /-- See `Ideal.relNorm_eq_pow_of_isMaximal` for a statement that does not require the extension to be Galois. -/ theorem relNorm_eq_pow_of_isPrime_isGalois [p.IsMaximal] [P.IsPrime] [IsGalois (FractionRing R) (FractionRing S)] : relNorm R P = p ^ p.inertiaDeg P := by let G := Gal(FractionRing S/FractionRing R) let := IsIntegralClosure.MulSemiringAction R (FractionRing R) (FractionRing S) S have := IsGaloisGroup.of_isFractionRing G R S (FractionRing R) (FractionRing S) by_cases hp : p = ⊥ · have h : p.inertiaDeg P ≠ 0 := Nat.ne_zero_iff_zero_lt.mpr <| inertiaDeg_pos p P have hP : P = ⊥ := by rw [hp] at hPp exact eq_bot_of_liesOver_bot R P rw [hp, hP, relNorm_bot, bot_pow] rwa [hp, hP] at h obtain ⟨s, hs⟩ := exists_relNorm_eq_pow_of_isPrime P p suffices s = p.inertiaDeg P by rwa [this] at hs have h₀ : ∀ Q ∈ (p.primesOver S).toFinset, relNorm R Q ^ ramificationIdx (algebraMap R S) p Q = p ^ ((p.ramificationIdxIn S) * s) := by intro Q hQ rw [Set.mem_toFinset] at hQ have : Q.IsPrime := hQ.1 have : Q.LiesOver p := hQ.2 rw [← ramificationIdxIn_eq_ramificationIdx p Q G] obtain ⟨σ, rfl⟩ := Ideal.exists_smul_eq_of_isGaloisGroup p P Q G rw [relNorm_smul, hs, ← pow_mul, mul_comm] have h := (congr_arg (relNorm R ·) <| map_algebraMap_eq_finset_prod_pow hp).symm.trans <| relNorm_algebraMap S p simp +contextual only [map_prod, map_pow, h₀, Finset.prod_const, ← pow_mul] at h rwa [← IsGaloisGroup.card_eq_finrank G (FractionRing R) (FractionRing S), ← Ideal.ncard_primesOver_mul_ramificationIdxIn_mul_inertiaDegIn hp S G, mul_comm, ← Set.ncard_eq_toFinset_card', ((IsLeftCancelMulZero.mul_left_cancel_of_ne_zero hp).pow_injective _).eq_iff, mul_right_inj' (primesOver_ncard_ne_zero p S), mul_right_inj' (ramificationIdxIn_ne_zero G hp), inertiaDegIn_eq_inertiaDeg p P G] at h rw [one_eq_top] exact IsMaximal.ne_top inferInstance theorem relNorm_eq_pow_of_isMaximal [PerfectField (FractionRing R)] [P.IsMaximal] [p.IsMaximal] : relNorm R P = p ^ p.inertiaDeg P := by let T := Ring.NormalClosure R S obtain ⟨Q, hQ₁, hQ₂⟩ : ∃ Q : Ideal T, Q.IsMaximal ∧ Q.LiesOver P := exists_maximal_ideal_liesOver_of_isIntegral P have : Q.LiesOver p := LiesOver.trans Q P p have h := relNorm_eq_pow_of_isPrime_isGalois Q p have : IsGalois (FractionRing S) (FractionRing T) := IsGalois.tower_top_of_isGalois (FractionRing R) (FractionRing S) (FractionRing T) rwa [← relNorm_relNorm R S, relNorm_eq_pow_of_isPrime_isGalois Q P, map_pow, inertiaDeg_algebra_tower p P Q, pow_mul, pow_left_inj] at h exact Nat.ne_zero_iff_zero_lt.mpr <| inertiaDeg_pos P Q end relNorm_prime section absNorm variable [Module.Free ℤ R] [Module.Free ℤ S] [Module.Finite ℤ S] open UniqueFactorizationMonoid in theorem absNorm_relNorm [PerfectField (FractionRing R)] (I : Ideal S) : absNorm (relNorm R I) = absNorm I := by have : Module.Finite ℤ R := Module.Finite.left ℤ R S by_cases hI : I = ⊥ · simp [hI] rw [← prod_normalizedFactors_eq_self hI] refine Multiset.prod_induction (fun I ↦ absNorm (relNorm R I) = absNorm I) _ ?_ ?_ ?_ · intro _ _ hx hy rw [map_mul, map_mul, map_mul, hx, hy] · simp · intro Q hQ have hQ' : Q ≠ ⊥ := ne_zero_of_mem_normalizedFactors hQ rw [Ideal.mem_normalizedFactors_iff hI] at hQ have : Q.IsMaximal := Ring.DimensionLEOne.maximalOfPrime hQ' hQ.1 let P := under R Q let p := absNorm (under ℤ P) have : NeZero P := ⟨under_ne_bot R hQ'⟩ have : Q.LiesOver P := by simp [liesOver_iff, P] have : Q.LiesOver (span {(p : ℤ)}) := LiesOver.trans Q P _ have : Fact (p.Prime) := ⟨Nat.absNorm_under_prime _⟩ have hp : Prime (p : ℤ) := Nat.prime_iff_prime_int.mp <| Nat.absNorm_under_prime _ rw [relNorm_eq_pow_of_isMaximal Q P, map_pow, absNorm_eq_pow_inertiaDeg Q hp, absNorm_eq_pow_inertiaDeg P hp, inertiaDeg_algebra_tower (span {(p : ℤ)}) P Q, pow_mul] theorem relNorm_int (I : Ideal S) : relNorm ℤ I = Ideal.span {(absNorm I : ℤ)} := by rw [← Int.ideal_span_absNorm_eq_self (relNorm ℤ I), absNorm_relNorm] theorem absNorm_algebraMap (I : Ideal R) [Module.Finite ℤ R] : absNorm (I.map (algebraMap R S)) = (absNorm I) ^ Module.finrank (FractionRing R) (FractionRing S) := by rw [← absNorm_relNorm ℤ, ← relNorm_relNorm ℤ R, relNorm_algebraMap, absNorm_relNorm, map_pow] end absNorm end Ideal end SpanNorm
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/Norm/AbsNorm.lean
import Mathlib.Algebra.CharP.Quotient import Mathlib.LinearAlgebra.FreeModule.Determinant import Mathlib.LinearAlgebra.FreeModule.Finite.CardQuotient import Mathlib.LinearAlgebra.FreeModule.IdealQuotient import Mathlib.RingTheory.DedekindDomain.Dvr import Mathlib.RingTheory.DedekindDomain.Ideal.Lemmas import Mathlib.RingTheory.Ideal.Basis import Mathlib.RingTheory.Norm.Basic import Mathlib.RingTheory.UniqueFactorizationDomain.Multiplicative /-! # 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). ## 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. ## 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 -/ open Module 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_notMem : 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_notMem 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_notMem : 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_notMem ab_mem ⊢ exact (prime_pow_succ_dvd_mul (Ideal.prime_of_isPrime hP P_prime) ab_mem).resolve_left a_notMem /-- 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_notMem : 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_notMem 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 | zero => simp | succ i ih => ?_ 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_notMem 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_notMem 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] refine Ideal.mul_add_mem_pow_succ_unique hP a _ _ _ _ a_notMem (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 rw [cardQuot_mul] map_one' := by 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, map_zero] @[simp] theorem absNorm_top : absNorm (⊤ : Ideal S) = 1 := by rw [← Ideal.one_eq_top, 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).index_ne_zero⟩ 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_isUnit (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 (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 exact Submodule.natAbs_det_equiv (I.restrictScalars ℤ) e /-- 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 := Submodule.natAbs_det_basis_change b (I.restrictScalars ℤ) bI @[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, Ideal.absNorm_bot, LinearMap.det_zero'', Set.singleton_zero, map_zero, Int.natAbs_zero] letI := Ideal.finiteQuotientOfFreeOfNeBot (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] intro 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_iff_mem_nonZeroDivisors {I : Ideal S} : absNorm I ≠ 0 ↔ I ∈ (Ideal S)⁰ := by simp_rw [ne_eq, Ideal.absNorm_eq_zero_iff, mem_nonZeroDivisors_iff_ne_zero, Submodule.zero_eq_bot] theorem absNorm_pos_iff_mem_nonZeroDivisors {I : Ideal S} : 0 < absNorm I ↔ I ∈ (Ideal S)⁰ := by rw [← absNorm_ne_zero_iff_mem_nonZeroDivisors, Nat.pos_iff_ne_zero] theorem absNorm_ne_zero_of_nonZeroDivisors (I : (Ideal S)⁰) : absNorm (I : Ideal S) ≠ 0 := absNorm_ne_zero_iff_mem_nonZeroDivisors.mpr (SetLike.coe_mem I) theorem absNorm_pos_of_nonZeroDivisors (I : (Ideal S)⁰) : 0 < absNorm (I : Ideal S) := absNorm_pos_iff_mem_nonZeroDivisors.mpr (SetLike.coe_mem I) theorem finite_setOf_absNorm_eq [CharZero S] (n : ℕ) : {I : Ideal S | Ideal.absNorm I = n}.Finite := by obtain hn | hn := Nat.eq_zero_or_pos n · simp only [hn, absNorm_eq_zero_iff, Set.setOf_eq_eq_singleton, Set.finite_singleton] · let f := fun I : Ideal S => Ideal.map (Ideal.Quotient.mk (@Ideal.span S _ {↑n})) I refine Set.Finite.of_finite_image (f := 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 (f := g) ?_ SetLike.coe_injective.injOn exact Set.Finite.subset Set.finite_univ (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 finite_setOf_absNorm_le [CharZero S] (n : ℕ) : {I : Ideal S | Ideal.absNorm I ≤ n}.Finite := by rw [show {I : Ideal S | Ideal.absNorm I ≤ n} = (⋃ i ∈ Set.Icc 0 n, {I : Ideal S | Ideal.absNorm I = i}) by ext; simp] refine Set.Finite.biUnion (Set.finite_Icc 0 n) (fun i _ => Ideal.finite_setOf_absNorm_eq i) theorem finite_setOf_absNorm_le₀ [CharZero S] (n : ℕ) : {I : (Ideal S)⁰ | Ideal.absNorm (I : Ideal S) ≤ n}.Finite := by have : Finite {I : Ideal S // I ∈ (Ideal S)⁰ ∧ absNorm I ≤ n} := (finite_setOf_absNorm_le n).subset fun _ ⟨_, h⟩ ↦ h exact Finite.of_equiv _ (Equiv.subtypeSubtypeEquivSubtypeInter _ (fun I ↦ absNorm I ≤ n)).symm theorem card_norm_le_eq_card_norm_le_add_one (n : ℕ) [CharZero S] : Nat.card {I : Ideal S // absNorm I ≤ n} = Nat.card {I : (Ideal S)⁰ // absNorm (I : Ideal S) ≤ n} + 1 := by classical have : Finite {I : Ideal S // I ∈ (Ideal S)⁰ ∧ absNorm I ≤ n} := (finite_setOf_absNorm_le n).subset fun _ ⟨_, h⟩ ↦ h have : Finite {I : Ideal S // I ∉ (Ideal S)⁰ ∧ absNorm I ≤ n} := (finite_setOf_absNorm_le n).subset fun _ ⟨_, h⟩ ↦ h rw [Nat.card_congr (Equiv.subtypeSubtypeEquivSubtypeInter (fun I ↦ I ∈ (Ideal S)⁰) (fun I ↦ absNorm I ≤ n))] let e : {I : Ideal S // absNorm I ≤ n} ≃ {I : Ideal S // I ∈ (Ideal S)⁰ ∧ absNorm I ≤ n} ⊕ {I : Ideal S // I ∉ (Ideal S)⁰ ∧ absNorm I ≤ n} := by refine (Equiv.subtypeEquivRight ?_).trans (subtypeOrEquiv _ _ ?_) · intro _ simp_rw [← or_and_right, em, true_and] · exact Pi.disjoint_iff.mpr fun I ↦ Prop.disjoint_iff.mpr (by tauto) simp_rw [Nat.card_congr e, Nat.card_sum, add_right_inj] conv_lhs => enter [1, 1, I] rw [← absNorm_ne_zero_iff_mem_nonZeroDivisors, ne_eq, not_not, and_iff_left_iff_imp.mpr (fun h ↦ by rw [h]; exact Nat.zero_le n), absNorm_eq_zero_iff] rw [Nat.card_unique] 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 section Int open Ideal @[simp] theorem Int.ideal_span_absNorm_eq_self (J : Ideal ℤ) : span {(absNorm J : ℤ)} = J := by obtain ⟨g, rfl⟩ := IsPrincipalIdealRing.principal J simp end Int end abs_norm
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/Quotient/Nilpotent.lean
import Mathlib.RingTheory.Ideal.Quotient.Operations import Mathlib.RingTheory.Nilpotent.Lemmas /-! # Nilpotent elements in quotient rings -/ theorem Ideal.isRadical_iff_quotient_reduced {R : Type*} [CommRing R] (I : Ideal R) : I.IsRadical ↔ IsReduced (R ⧸ I) := by conv_lhs => rw [← @Ideal.mk_ker R _ I] exact RingHom.ker_isRadical_iff_reduced_of_surjective Quotient.mk_surjective variable {S : Type*} [CommRing S] (I : Ideal S) /-- Let `P` be a property on ideals. If `P` holds for square-zero ideals, and if `P I → P (J ⧸ I) → P J`, then `P` holds for all nilpotent ideals. -/ theorem Ideal.IsNilpotent.induction_on (hI : IsNilpotent I) {P : ∀ ⦃S : Type _⦄ [CommRing S], Ideal S → Prop} (h₁ : ∀ ⦃S : Type _⦄ [CommRing S], ∀ I : Ideal S, I ^ 2 = ⊥ → P I) (h₂ : ∀ ⦃S : Type _⦄ [CommRing S], ∀ I J : Ideal S, I ≤ J → P I → P (J.map (Ideal.Quotient.mk I)) → P J) : P I := by obtain ⟨n, hI : I ^ n = ⊥⟩ := hI induction n using Nat.strong_induction_on generalizing S with | _ n H by_cases hI' : I = ⊥ · subst hI' apply h₁ rw [← Ideal.zero_eq_bot, zero_pow two_ne_zero] rcases n with - | n · rw [pow_zero, Ideal.one_eq_top] at hI haveI := subsingleton_of_bot_eq_top hI.symm exact (hI' (Subsingleton.elim _ _)).elim rcases n with - | n · rw [pow_one] at hI exact (hI' hI).elim apply h₂ (I ^ 2) _ (Ideal.pow_le_self two_ne_zero) · apply H n.succ _ (I ^ 2) · rw [← pow_mul, eq_bot_iff, ← hI, Nat.succ_eq_add_one] apply Ideal.pow_le_pow_right (by cutsat) · exact n.succ.lt_succ_self · apply h₁ rw [← Ideal.map_pow, Ideal.map_quotient_self] theorem IsNilpotent.isUnit_quotient_mk_iff {R : Type*} [CommRing R] {I : Ideal R} (hI : IsNilpotent I) {x : R} : IsUnit (Ideal.Quotient.mk I x) ↔ IsUnit x := by refine ⟨?_, fun h => h.map <| Ideal.Quotient.mk I⟩ revert x apply Ideal.IsNilpotent.induction_on (S := R) I hI <;> clear hI I swap · introv e h₁ h₂ h₃ apply h₁ apply h₂ exact h₃.map ((DoubleQuot.quotQuotEquivQuotSup I J).trans (Ideal.quotEquivOfEq (sup_eq_right.mpr e))).symm.toRingHom · introv e H obtain ⟨y, hy⟩ := Ideal.Quotient.mk_surjective (↑H.unit⁻¹ : S ⧸ I) have : Ideal.Quotient.mk I (x * y) = Ideal.Quotient.mk I 1 := by rw [map_one, map_mul, hy, IsUnit.mul_val_inv] rw [Ideal.Quotient.eq] at this have : (x * y - 1) ^ 2 = 0 := by rw [← Ideal.mem_bot, ← e] exact Ideal.pow_mem_pow this _ have : x * (y * (2 - x * y)) = 1 := by rw [eq_comm, ← sub_eq_zero, ← this] ring exact .of_mul_eq_one _ this
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/Quotient/PowTransition.lean
import Mathlib.LinearAlgebra.Quotient.Basic import Mathlib.RingTheory.Ideal.Quotient.Defs import Mathlib.Algebra.Algebra.Operations import Mathlib.RingTheory.Ideal.Operations import Mathlib.RingTheory.Ideal.Maps /-! # The quotient map from `R ⧸ I ^ m` to `R ⧸ I ^ n` where `m ≥ n` In this file we define the canonical quotient linear map from `M ⧸ I ^ m • ⊤` to `M ⧸ I ^ n • ⊤` and canonical quotient ring map from `R ⧸ I ^ m` to `R ⧸ I ^ n`. These definitions will be used in theorems related to `IsAdicComplete` to find a lift element from compatible sequences in the quotients. We also include results about the relation between quotients of submodules and quotients of ideals here. ## Main definitions - `Submodule.factorPow`: the linear map from `M ⧸ I ^ m • ⊤` to `M ⧸ I ^ n • ⊤` induced by the natural inclusion `I ^ n • ⊤ → I ^ m • ⊤`. - `Ideal.Quotient.factorPow`: the ring homomorphism from `R ⧸ I ^ m` to `R ⧸ I ^ n` induced by the natural inclusion `I ^ n → I ^ m`. ## Main results -/ /- Since `Mathlib/LinearAlgebra/Quotient/Basic.lean` and `Mathlib/RingTheory/Ideal/Quotient/Defs.lean` do not import each other, and the first file that imports both of them is `Mathlib/RingTheory/Ideal/Quotient/Operations.lean`, which has already established the first isomorphism theorem and Chinese remainder theorem, we put these pure technical lemmas that involves both `Submodule.mapQ` and `Ideal.Quotient.factor` in this file. -/ open Ideal Quotient variable {R : Type*} [Ring R] {I J K : Ideal R} {M : Type*} [AddCommGroup M] [Module R M] lemma Ideal.Quotient.factor_ker (H : I ≤ J) [I.IsTwoSided] [J.IsTwoSided] : RingHom.ker (factor H) = J.map (Ideal.Quotient.mk I) := by ext x refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rcases Ideal.Quotient.mk_surjective x with ⟨r, hr⟩ rw [← hr] at h ⊢ simp only [factor, RingHom.mem_ker, lift_mk, eq_zero_iff_mem] at h exact Ideal.mem_map_of_mem _ h · rcases mem_image_of_mem_map_of_surjective _ Ideal.Quotient.mk_surjective h with ⟨r, hr, eq⟩ simpa [← eq, Ideal.Quotient.eq_zero_iff_mem] using hr lemma Submodule.eq_factor_of_eq_factor_succ {p : ℕ → Submodule R M} (hp : Antitone p) (x : (n : ℕ) → M ⧸ (p n)) (h : ∀ m, x m = factor (hp m.le_succ) (x (m + 1))) {m n : ℕ} (g : m ≤ n) : x m = factor (hp g) (x n) := by have : n = m + (n - m) := (Nat.add_sub_of_le g).symm induction hmn : n - m generalizing m n with | zero => rw [hmn, Nat.add_zero] at this subst this simp | succ k ih => rw [hmn, ← add_assoc] at this subst this rw [ih (m.le_add_right k) (by simp), h] · simp · cutsat lemma Ideal.Quotient.eq_factor_of_eq_factor_succ {I : ℕ → Ideal R} [∀ n, (I n).IsTwoSided] (hI : Antitone I) (x : (n : ℕ) → R ⧸ (I n)) (h : ∀ m, x m = factor (hI m.le_succ) (x (m + 1))) {m n : ℕ} (g : m ≤ n) : x m = factor (hI g) (x n) := Submodule.eq_factor_of_eq_factor_succ hI x h g lemma Ideal.map_mk_comap_factor [J.IsTwoSided] [K.IsTwoSided] (hIJ : J ≤ I) (hJK : K ≤ J) : (I.map (mk J)).comap (factor hJK) = I.map (mk K) := by ext x refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rcases mem_image_of_mem_map_of_surjective (mk J) Quotient.mk_surjective h with ⟨r, hr, eq⟩ have : x - ((mk K) r) ∈ J.map (mk K) := by simp [← factor_ker hJK, ← eq] rcases mem_image_of_mem_map_of_surjective (mk K) Quotient.mk_surjective this with ⟨s, hs, eq'⟩ rw [← add_sub_cancel ((mk K) r) x, ← eq', ← map_add] exact mem_map_of_mem (mk K) (Submodule.add_mem _ hr (hIJ hs)) · rcases mem_image_of_mem_map_of_surjective (mk K) Quotient.mk_surjective h with ⟨r, hr, eq⟩ simpa only [← eq] using mem_map_of_mem (mk J) hr namespace Submodule open Submodule section @[simp] theorem mapQ_eq_factor (h : I ≤ J) (x : R ⧸ I) : mapQ I J LinearMap.id h x = factor h x := rfl @[simp] theorem factor_eq_factor [I.IsTwoSided] [J.IsTwoSided] (h : I ≤ J) (x : R ⧸ I) : Submodule.factor h x = Ideal.Quotient.factor h x := rfl end variable (I M) lemma pow_smul_top_le {m n : ℕ} (h : m ≤ n) : (I ^ n • ⊤ : Submodule R M) ≤ I ^ m • ⊤ := smul_mono_left (Ideal.pow_le_pow_right h) /-- The linear map from `M ⧸ I ^ m • ⊤` to `M ⧸ I ^ n • ⊤` induced by the natural inclusion `I ^ n • ⊤ → I ^ m • ⊤`. To future contributors: Before adding lemmas related to `Submodule.factorPow`, please check whether it can be generalized to `Submodule.factor` and whether the corresponding (more general) lemma for `Submodule.factor` already exists. -/ abbrev factorPow {m n : ℕ} (le : m ≤ n) : M ⧸ (I ^ n • ⊤ : Submodule R M) →ₗ[R] M ⧸ (I ^ m • ⊤ : Submodule R M) := factor (smul_mono_left (Ideal.pow_le_pow_right le)) /-- `factorPow` for `n = m + 1` -/ abbrev factorPowSucc (m : ℕ) : M ⧸ (I ^ (m + 1) • ⊤ : Submodule R M) →ₗ[R] M ⧸ (I ^ m • ⊤ : Submodule R M) := factorPow I M (Nat.le_succ m) end Submodule namespace Ideal namespace Quotient variable [I.IsTwoSided] variable (I) /-- The ring homomorphism from `R ⧸ I ^ m` to `R ⧸ I ^ n` induced by the natural inclusion `I ^ n → I ^ m`. To future contributors: Before adding lemmas related to `Ideal.factorPow`, please check whether it can be generalized to `Ideal.factor` and whether the corresponding (more general) lemma for `Ideal.factor` already exists. -/ abbrev factorPow {m n : ℕ} (le : n ≤ m) : R ⧸ I ^ m →+* R ⧸ I ^ n := factor (pow_le_pow_right le) /-- `factorPow` for `m = n + 1` -/ abbrev factorPowSucc (n : ℕ) : R ⧸ I ^ (n + 1) →+* R ⧸ I ^ n := factorPow I (Nat.le_succ n) end Quotient end Ideal variable {R : Type*} [CommRing R] (I : Ideal R) lemma Ideal.map_mk_comap_factorPow {a b : ℕ} (apos : 0 < a) (le : a ≤ b) : (I.map (mk (I ^ a))).comap (factorPow I le) = I.map (mk (I ^ b)) := by apply Ideal.map_mk_comap_factor exact pow_le_self (Nat.ne_zero_of_lt apos) variable {I} in lemma factorPowSucc.isUnit_of_isUnit_image {n : ℕ} (npos : n > 0) {a : R ⧸ I ^ (n + 1)} (h : IsUnit (factorPow I n.le_succ a)) : IsUnit a := by rcases isUnit_iff_exists.mp h with ⟨b, hb, _⟩ rcases factor_surjective (pow_le_pow_right n.le_succ) b with ⟨b', hb'⟩ rw [← hb', ← map_one (factorPow I n.le_succ), ← map_mul] at hb apply (RingHom.sub_mem_ker_iff (factorPow I n.le_succ)).mpr at hb rw [factor_ker (pow_le_pow_right n.le_succ)] at hb rcases Ideal.mem_image_of_mem_map_of_surjective (Ideal.Quotient.mk (I ^ (n + 1))) Ideal.Quotient.mk_surjective hb with ⟨c, hc, eq⟩ refine .of_mul_eq_one (b' * (1 - Ideal.Quotient.mk (I ^ (n + 1)) c)) ?_ calc _ = (a * b' - 1) * (1 - Ideal.Quotient.mk (I ^ (n + 1)) c) + (1 - Ideal.Quotient.mk (I ^ (n + 1)) c) := by ring _ = 1 := by rw [← eq, mul_sub, mul_one, sub_add_sub_cancel', sub_eq_self, ← map_mul, Ideal.Quotient.eq_zero_iff_mem, pow_add] apply Ideal.mul_mem_mul hc (Ideal.mul_le_left (I := I ^ (n - 1)) _) simpa only [← pow_add, Nat.sub_add_cancel npos] using hc
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/Quotient/Index.lean
import Mathlib.Algebra.Ring.GeomSum import Mathlib.Data.Finsupp.Fintype import Mathlib.GroupTheory.Index import Mathlib.LinearAlgebra.DirectSum.Finsupp import Mathlib.LinearAlgebra.TensorProduct.Quotient import Mathlib.LinearAlgebra.TensorProduct.RightExactness import Mathlib.RingTheory.Finiteness.Cardinality import Mathlib.RingTheory.Ideal.Quotient.Operations import Mathlib.RingTheory.TensorProduct.Finite /-! # Indices of ideals ## Main result - `Submodule.finite_quotient_smul`: Let `N` be a finite index f.g. `R`-submodule, and `I` be a finite index ideal. Then `I • N` also has finite index. - `Ideal.index_quotient_pow_le`: If `I` is generated by `k` elements, the index of `I ^ n` is bounded by `#(R ⧸ I) ^ (k⁰ + k¹ + ⋯ + kⁿ⁻¹)`. -/ variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] variable (I : Ideal R) {N : Submodule R M} open TensorProduct in /-- Let `N` be a finite index f.g. `R`-submodule, and `I` be a finite index ideal. Then `I • N` also has finite index. -/ lemma Submodule.finite_quotient_smul [Finite (R ⧸ I)] [Finite (M ⧸ N)] (hN : N.FG) : Finite (M ⧸ I • N) := by suffices (I • N).toAddSubgroup.FiniteIndex by exact (I • N).toAddSubgroup.finite_quotient_of_finiteIndex suffices Nat.card (N ⧸ (I • N).comap N.subtype) ≠ 0 by constructor rw [← AddSubgroup.relIndex_mul_index (H := (I • N).toAddSubgroup) (K := N.toAddSubgroup) Submodule.smul_le_right] have inst : Finite (M ⧸ N.toAddSubgroup) := ‹_› exact mul_ne_zero this AddSubgroup.index_ne_zero_of_finite let e : (N ⧸ (I • N).comap N.subtype) ≃ₗ[R] (R ⧸ I) ⊗[R] N := Submodule.quotEquivOfEq _ (I • (⊤ : Submodule R N)) (Submodule.map_injective_of_injective N.injective_subtype (by simp [Submodule.smul_le_right])) ≪≫ₗ (quotTensorEquivQuotSMul N I).symm rw [Nat.card_congr e.toEquiv] have : Module.Finite R N := Module.Finite.iff_fg.mpr hN have : Finite ((R ⧸ I) ⊗[R] N) := Module.finite_of_finite (R ⧸ I) exact Nat.card_pos.ne' -- We have `hs` and `N` instead of using `span R s` in the goal to make it easier to use. -- Usually we would like to bound the index of some abstract `I • N`, and we may construct `s` while -- applying this lemma instead of having to provide it beforehand. open TensorProduct in lemma Submodule.index_smul_le [Finite (R ⧸ I)] (s : Finset M) (hs : Submodule.span R s = N) : (I • N).toAddSubgroup.index ≤ I.toAddSubgroup.index ^ s.card * N.toAddSubgroup.index := by classical cases nonempty_fintype (R ⧸ I) rw [← AddSubgroup.relIndex_mul_index (H := (I • N).toAddSubgroup) (K := N.toAddSubgroup) Submodule.smul_le_right] gcongr change (Nat.card (N ⧸ (I • N).comap N.subtype)) ≤ Nat.card (R ⧸ I) ^ s.card let e : (N ⧸ (I • N).comap N.subtype) ≃ₗ[R] (R ⧸ I) ⊗[R] N := Submodule.quotEquivOfEq _ (I • (⊤ : Submodule R N)) (Submodule.map_injective_of_injective N.injective_subtype (by simp [Submodule.smul_le_right])) ≪≫ₗ (quotTensorEquivQuotSMul N I).symm rw [Nat.card_congr e.toEquiv] have H : LinearMap.range (Finsupp.linearCombination R (α := s) (↑)) = N := by rw [Finsupp.range_linearCombination, ← hs, Subtype.range_val] let f : (s →₀ R) →ₗ[R] N := (Finsupp.linearCombination R (↑)).codRestrict _ (fun c => by rw [← H, LinearMap.mem_range]; exact exists_apply_eq_apply _ _) have hf : Function.Surjective f := fun x ↦ by obtain ⟨y, hy⟩ := H.ge x.2; exact ⟨y, Subtype.ext hy⟩ have : Function.Surjective (f.lTensor (R ⧸ I) ∘ₗ (finsuppScalarRight R (R ⧸ I) s).symm.toLinearMap) := (LinearMap.lTensor_surjective (R ⧸ I) hf).comp (LinearEquiv.surjective _) refine (Nat.card_le_card_of_surjective _ this).trans ?_ simp only [Nat.card_eq_fintype_card, Fintype.card_finsupp, Fintype.card_coe, le_rfl] variable {I} lemma Ideal.finite_quotient_prod {ι : Type*} (I : ι → Ideal R) (s : Finset ι) (hI : ∀ i ∈ s, (I i).FG) (hI' : ∀ i ∈ s, Finite (R ⧸ I i)) : Finite (R ⧸ (∏ i ∈ s, I i)) := by classical induction s using Finset.induction_on with | empty => simp only [Finset.prod_empty, one_eq_top]; infer_instance | insert a s has IH => rw [Finset.prod_insert has, mul_comm] have := hI' a (by simp) have := IH (fun i hi ↦ hI _ (by simp [hi])) (fun i hi ↦ hI' _ (by simp [hi])) exact Submodule.finite_quotient_smul _ (hI a (by simp)) lemma Ideal.finite_quotient_pow (hI : I.FG) [Finite (R ⧸ I)] (n) : Finite (R ⧸ I ^ n) := by induction n with | zero => simp only [pow_zero, Ideal.one_eq_top] infer_instance | succ n _ => exact Submodule.finite_quotient_smul (I ^ n) hI lemma Ideal.index_pow_le (s : Finset R) (hs : Ideal.span s = I) [Finite (R ⧸ I)] (n) : (I ^ n).toAddSubgroup.index ≤ I.toAddSubgroup.index ^ ∑ i ∈ Finset.range n, s.card ^ i := by have := Ideal.finite_quotient_pow ⟨s, hs⟩ induction n with | zero => simp | succ n IH => refine (Submodule.index_smul_le (I ^ n) s hs).trans ?_ refine (Nat.mul_le_mul (Nat.pow_le_pow_left IH _) le_rfl).trans ?_ rw [← pow_mul, ← pow_succ, geom_sum_succ, mul_comm]
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/Quotient/Basic.lean
import Mathlib.GroupTheory.QuotientGroup.Finite import Mathlib.LinearAlgebra.Quotient.Defs import Mathlib.RingTheory.Congruence.Basic import Mathlib.RingTheory.Ideal.Basic import Mathlib.RingTheory.Ideal.Quotient.Defs 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 semirings. ## Main definitions - `Ideal.Quotient.Ring`: the quotient of a ring `R` by a two-sided ideal `I : Ideal R` -/ open Set variable {ι ι' R S : Type*} [Ring R] (I J : Ideal R) {a b : R} namespace Ideal.Quotient @[simp] lemma mk_span_range (f : ι → R) [(span (range f)).IsTwoSided] (i : ι) : mk (span (.range f)) (f i) = 0 := by rw [Ideal.Quotient.eq_zero_iff_mem] exact Ideal.subset_span ⟨i, rfl⟩ variable {I} {x y : R} theorem zero_eq_one_iff : (0 : R ⧸ I) = 1 ↔ I = ⊤ := eq_comm.trans <| (Submodule.Quotient.mk_eq_zero _).trans (eq_top_iff_one _).symm theorem zero_ne_one_iff : (0 : R ⧸ I) ≠ 1 ↔ I ≠ ⊤ := not_congr zero_eq_one_iff protected theorem nontrivial (hI : I ≠ ⊤) : Nontrivial (R ⧸ I) := ⟨⟨0, 1, zero_ne_one_iff.2 hI⟩⟩ theorem subsingleton_iff : Subsingleton (R ⧸ I) ↔ I = ⊤ := by rw [Submodule.Quotient.subsingleton_iff, eq_top_iff, SetLike.le_def] simp_rw [Submodule.mem_top, true_implies] instance : Unique (R ⧸ (⊤ : Ideal R)) := ⟨⟨0⟩, by rintro ⟨x⟩; exact Quotient.eq_zero_iff_mem.mpr Submodule.mem_top⟩ variable [I.IsTwoSided] -- 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' theorem eq_zero_iff_dvd {R} [CommRing R] (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) [(Ideal.span {x}).IsTwoSided] : mk (Ideal.span {x}) x = 0 := (Submodule.Quotient.mk_eq_zero _).mpr (mem_span_singleton_self _) variable (I) instance noZeroDivisors [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 [hI : I.IsPrime] : IsDomain (R ⧸ I) := let _ := Quotient.nontrivial hI.1 NoZeroDivisors.to_isDomain _ theorem isDomain_iff_prime : 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 variable {I} in theorem exists_inv [hI : I.IsMaximal] : ∀ {a : R ⧸ I}, a ≠ 0 → ∃ b : R ⧸ I, a * b = 1 := by apply exists_right_inv_of_exists_left_inv rintro ⟨a⟩ h rcases hI.exists_inv (mt eq_zero_iff_mem.2 h) with ⟨b, c, hc, abc⟩ refine ⟨mk _ b, Quot.sound ?_⟩ simp only [Submodule.quotientRel_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 [hI : I.IsMaximal] : GroupWithZero (R ⧸ I) := fast_instance% { 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 __ := Quotient.nontrivial hI.out.1 } /-- The quotient by a two-sided ideal that is maximal as a left ideal is a division ring. 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 divisionRing [I.IsMaximal] : DivisionRing (R ⧸ I) := fast_instance% { __ := ring _ __ := Quotient.groupWithZero _ nnqsmul := _ nnqsmul_def _ _ := rfl qsmul := _ qsmul_def _ _ := rfl } /-- The quotient of a commutative ring 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 {R} [CommRing R] (I : Ideal R) [I.IsMaximal] : Field (R ⧸ I) := fast_instance% { __ := commRing _ __ := Quotient.divisionRing I } /-- If the quotient by an ideal is a field, then the ideal is maximal. -/ theorem maximal_of_isField {R} [CommRing R] (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 {R} [CommRing R] (I : Ideal R) : I.IsMaximal ↔ IsField (R ⧸ I) := ⟨fun h => let _i := @Quotient.field _ _ I h Field.toIsField _, maximal_of_isField _⟩ end Quotient section Pi /-- `R^n/I^n` is a `R/I`-module. -/ instance modulePi [I.IsTwoSided] : Module (R ⧸ I) ((ι → R) ⧸ pi fun _ ↦ I) 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_def] at hc hm intro i exact I.mul_sub_mul_mem hc (hm i) one_smul := by rintro ⟨a⟩; exact congr_arg _ (one_smul _ _) mul_smul := by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩; exact congr_arg _ (mul_smul _ _ _) smul_add := by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩; exact congr_arg _ (smul_add _ _ _) smul_zero := by rintro ⟨a⟩; exact congr_arg _ (smul_zero _) add_smul := by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩; exact congr_arg _ (add_smul _ _ _) zero_smul := by rintro ⟨a⟩; exact congr_arg _ (zero_smul _ _) variable (ι) in /-- `R^n/I^n` is isomorphic to `(R/I)^n` as an `R/I`-module. -/ noncomputable def piQuotEquiv [I.IsTwoSided] : ((ι → R) ⧸ pi fun _ ↦ I) ≃ₗ[R ⧸ I] ι → (R ⧸ I) where toFun x := Quotient.liftOn' x (fun f i ↦ Ideal.Quotient.mk I (f i)) fun _ _ 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 x := Ideal.Quotient.mk _ (Quotient.out <| x ·) left_inv := by rintro ⟨x⟩ exact Ideal.Quotient.eq.2 fun i ↦ Ideal.Quotient.eq.1 (Quotient.out_eq' _) right_inv x := funext fun i ↦ 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 [I.IsTwoSided] [Finite ι] (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 open scoped Pointwise in /-- A ring is made up of a disjoint union of cosets of an ideal. -/ lemma univ_eq_iUnion_image_add : (Set.univ (α := R)) = ⋃ x : R ⧸ I, x.out +ᵥ (I : Set R) := QuotientAddGroup.univ_eq_iUnion_vadd I.toAddSubgroup end Ideal lemma finite_iff_ideal_quotient (I : Ideal R) : Finite R ↔ Finite I ∧ Finite (R ⧸ I) := finite_iff_addSubgroup_quotient I.toAddSubgroup lemma Finite.of_ideal_quotient (I : Ideal R) [Finite I] [Finite (R ⧸ I)] : Finite R := by rw [finite_iff_ideal_quotient]; constructor <;> assumption @[deprecated (since := "2025-11-11")] alias Finite.of_finite_quot_finite_ideal := Finite.of_ideal_quotient
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/Quotient/Operations.lean
import Mathlib.Algebra.Algebra.Subalgebra.Operations import Mathlib.Algebra.Ring.Fin import Mathlib.LinearAlgebra.Quotient.Basic import Mathlib.RingTheory.Ideal.Quotient.Basic /-! # 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} [Ring 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 _ => 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) [I.IsTwoSided] {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.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 /-- 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) @[simp] lemma quotientKerEquivOfSurjective_apply_mk {f : R →+* S} (hf : Function.Surjective f) (x : R) : f.quotientKerEquivOfSurjective hf (Ideal.Quotient.mk _ x) = f x := rfl /-- 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} [Ring R] [Semiring S] @[simp] theorem map_quotient_self (I : Ideal R) [I.IsTwoSided] : 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} [I.IsTwoSided] : 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} [J.IsTwoSided] (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} [I.IsTwoSided] (f : R →+* S) (H : I ≤ ker f) : ker (Ideal.Quotient.lift I f H) = (RingHom.ker f).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} [I.IsTwoSided] {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) [∀ i, (I i).IsTwoSided] : 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) [I.IsTwoSided] : (⊥ : 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.divisionRing 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} [I.IsTwoSided] {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} [I.IsTwoSided] (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) [∀ i, (I i).IsTwoSided] : (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) [∀ i, (I i).IsTwoSided] (x : R) : quotientInfToPiQuotient I (Quotient.mk _ x) = fun i : ι ↦ Quotient.mk (I i) x := rfl lemma quotientInfToPiQuotient_mk' (I : ι → Ideal R) [∀ i, (I i).IsTwoSided] (x : R) (i : ι) : quotientInfToPiQuotient I (Quotient.mk _ x) i = Quotient.mk (I i) x := rfl lemma quotientInfToPiQuotient_inj (I : ι → Ideal R) [∀ i, (I i).IsTwoSided] : Injective (quotientInfToPiQuotient I) := by rw [quotientInfToPiQuotient, injective_lift_iff, ker_Pi_Quotient_mk] variable {R : Type*} [CommRing R] {ι : Type*} [Finite ι] lemma quotientInfToPiQuotient_surj {I : ι → Ideal R} (hI : Pairwise (IsCoprime on I)) : 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 intro 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] · intro 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 (f : ι → Ideal R) (hf : Pairwise (IsCoprime on f)) : (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 {I : ι → Ideal R} (hf : Pairwise (IsCoprime on I)) (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⟩ lemma pi_mkQ_surjective {I : ι → Ideal R} (hI : Pairwise (IsCoprime on I)) : Surjective (LinearMap.pi fun i ↦ (I i).mkQ) := fun x ↦ have ⟨r, eq⟩ := pi_quotient_surjective hI x; ⟨r, funext eq⟩ -- 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 {I : ι → Ideal R} (hI : Pairwise (IsCoprime on I)) (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 (IsCoprime on f) := 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 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 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 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 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 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 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 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 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₂] [Ring 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} [I.IsTwoSided] : Algebra R₁ (A ⧸ I) where algebraMap := (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' := by rintro r ⟨x⟩; exact congr_arg (⟦·⟧) (Algebra.commutes r x) instance {A} [CommRing A] [Algebra R₁ A] (I : Ideal A) : Algebra R₁ (A ⧸ I) := inferInstance -- This instance can be inferred, but is kept around as a useful shortcut. instance Quotient.isScalarTower [SMul R₁ R₂] [IsScalarTower R₁ R₂ A] (I : Ideal A) : IsScalarTower R₁ R₂ (A ⧸ I) := inferInstance /-- 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) [I.IsTwoSided] : 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} [I.IsTwoSided] {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 {A} [CommRing A] [Algebra R₁ A] (I : Ideal A) : algebraMap R₁ (A ⧸ I) = (algebraMap A (A ⧸ I)).comp (algebraMap R₁ A) := rfl theorem Quotient.mkₐ_toRingHom (I : Ideal A) [I.IsTwoSided] : (Quotient.mkₐ R₁ I).toRingHom = Ideal.Quotient.mk I := rfl @[simp] theorem Quotient.mkₐ_eq_mk (I : Ideal A) [I.IsTwoSided] : ⇑(Quotient.mkₐ R₁ I) = Quotient.mk I := rfl @[simp] theorem Quotient.algebraMap_eq {R} [CommRing R] (I : Ideal R) : algebraMap R (R ⧸ I) = Quotient.mk I := rfl @[simp] theorem Quotient.mk_comp_algebraMap (I : Ideal A) [I.IsTwoSided] : (Quotient.mk I).comp (algebraMap R₁ A) = algebraMap R₁ (A ⧸ I) := rfl @[simp] theorem Quotient.mk_algebraMap (I : Ideal A) [I.IsTwoSided] (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) [I.IsTwoSided] : Function.Surjective (Quotient.mkₐ R₁ I) := Quot.mk_surjective /-- The kernel of `A →ₐ[R₁] I.quotient` is `I`. -/ @[simp] theorem Quotient.mkₐ_ker (I : Ideal A) [I.IsTwoSided] : RingHom.ker (Quotient.mkₐ R₁ I : A →+* A ⧸ I) = I := Ideal.mk_ker lemma Quotient.mk_bijective_iff_eq_bot (I : Ideal A) [I.IsTwoSided] : Function.Bijective (mk I) ↔ I = ⊥ := by constructor · intro h rw [← map_eq_bot_iff_of_injective h.1] exact (map_eq_bot_iff_le_ker _).mpr <| le_of_eq mk_ker.symm · exact fun h => ⟨(injective_iff_ker_eq_bot _).mpr <| by rw [mk_ker, h], mk_surjective⟩ section /-- `AlgHom` version of `Ideal.Quotient.factor`. -/ def Quotient.factorₐ {I J : Ideal A} [I.IsTwoSided] [J.IsTwoSided] (hIJ : I ≤ J) : A ⧸ I →ₐ[R₁] A ⧸ J where __ := Ideal.Quotient.factor hIJ commutes' _ := rfl variable {I J : Ideal A} [I.IsTwoSided] [J.IsTwoSided] (hIJ : I ≤ J) @[simp] lemma Quotient.coe_factorₐ : (Ideal.Quotient.factorₐ R₁ hIJ : A ⧸ I →+* A ⧸ J) = Ideal.Quotient.factor hIJ := rfl @[simp] lemma Quotient.factorₐ_apply_mk (x : A) : Ideal.Quotient.factorₐ R₁ hIJ x = x := rfl @[simp] lemma Quotient.factorₐ_comp_mk : (Ideal.Quotient.factorₐ R₁ hIJ).comp (Ideal.Quotient.mkₐ R₁ I) = Ideal.Quotient.mkₐ R₁ J := rfl @[simp] lemma Quotient.factorₐ_comp {K : Ideal A} [K.IsTwoSided] (hJK : J ≤ K) : (Ideal.Quotient.factorₐ R₁ hJK).comp (Ideal.Quotient.factorₐ R₁ hIJ) = Ideal.Quotient.factorₐ R₁ (hIJ.trans hJK) := Ideal.Quotient.algHom_ext _ (by ext; simp) end variable {R₁} section variable [Semiring B] [Algebra R₁ B] /-- `Ideal.quotient.lift` as an `AlgHom`. -/ def Quotient.liftₐ (I : Ideal A) [I.IsTwoSided] (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 = Ideal.Quotient.mk I (algebraMap R₁ A r) := rfl rw [this, 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) [I.IsTwoSided] (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) [I.IsTwoSided] (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 Quotient.span_singleton_one (I : Ideal A) [I.IsTwoSided] : Submodule.span A {(1 : A ⧸ I)} = ⊤ := by rw [← map_one (mk _), ← Submodule.range_mkQ I, ← Submodule.map_top, ← Ideal.span_singleton_one, Ideal.span, Submodule.map_span, Set.image_singleton, Submodule.mkQ_apply, Quotient.mk_eq_mk] open Pointwise in lemma Quotient.smul_top {R : Type*} [CommRing R] (a : R) (I : Ideal R) : (a • ⊤ : Submodule R (R ⧸ I)) = Submodule.span R {Submodule.Quotient.mk a} := by simp [← Ideal.Quotient.span_singleton_one, Algebra.smul_def, Submodule.smul_span] 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 } /-- 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 Ring_Ring variable {S : Type v} [Ring 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) [I.IsTwoSided] [J.IsTwoSided] (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} [I.IsTwoSided] [J.IsTwoSided] {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} [I.IsTwoSided] [J.IsTwoSided] {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} [I.IsTwoSided] [J.IsTwoSided] {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] lemma ker_quotientMap_mk {I J : Ideal R} [I.IsTwoSided] [J.IsTwoSided] : RingHom.ker (quotientMap (J.map _) (Quotient.mk I) le_comap_map) = I.map (Quotient.mk J) := by rw [Ideal.quotientMap, Ideal.ker_quotient_lift, ← RingHom.comap_ker, Ideal.mk_ker, Ideal.comap_map_of_surjective _ Ideal.Quotient.mk_surjective, ← RingHom.ker_eq_comap_bot, Ideal.mk_ker, Ideal.map_sup, Ideal.map_quotient_self, bot_sup_eq] section quotientEquiv variable (I : Ideal R) (J : Ideal S) [I.IsTwoSided] [J.IsTwoSided] (f : R ≃+* S) (hIJ : J = I.map (f : R →+* S)) /-- The ring equiv `R/I ≃+* S/J` induced by a ring equiv `f : R ≃+* S`, where `J = f(I)`. -/ @[simps] def quotientEquiv : R ⧸ I ≃+* S ⧸ J where __ := quotientMap J f (hIJ ▸ le_comap_map) invFun := quotientMap I f.symm (hIJ ▸ (map_comap_of_equiv f).le) 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] -- Not `@[simp]` since `simp` proves it. theorem quotientEquiv_mk (x : R) : quotientEquiv I J f hIJ (Ideal.Quotient.mk I x) = Ideal.Quotient.mk J (f x) := rfl -- Not `@[simp]` since `simp` proves it. theorem quotientEquiv_symm_mk (x : S) : (quotientEquiv I J f hIJ).symm (Ideal.Quotient.mk J x) = Ideal.Quotient.mk I (f.symm x) := rfl end quotientEquiv /-- `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} [I.IsTwoSided] [J.IsTwoSided] {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} [I.IsTwoSided] : Function.Injective (quotientMap I f le_rfl) := quotientMap_injective' le_rfl theorem quotientMap_surjective {J : Ideal R} {I : Ideal S} [I.IsTwoSided] [J.IsTwoSided] {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*} [Ring R'] [Ring S'] {f : R →+* S} {f' : R' →+* S'} {g : R →+* R'} {g' : S →+* S'} (hfg : f'.comp g = g'.comp f) (I : Ideal S') [I.IsTwoSided] : let leq := le_of_eq (_root_.trans (comap_comap f g') (hfg ▸ comap_comap 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 Ring_Ring section variable [Ring B] [Algebra R₁ B] {I : Ideal A} (J : Ideal B) [I.IsTwoSided] [J.IsTwoSided] /-- The algebra hom `A/I →+* B/J` induced by an algebra hom `f : A →ₐ[R₁] B` with `I ≤ f⁻¹(J)`. -/ def quotientMapₐ (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ₐ (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ₐ (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] variable (I) in /-- The algebra equiv `A/I ≃ₐ[R] B/J` induced by an algebra equiv `f : A ≃ₐ[R] B`, where`J = f(I)`. -/ def quotientEquivAlg (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' r := by simp } end /-- If `P` lies over `p`, then `R / p` has a canonical map to `A / P`. -/ abbrev Quotient.algebraQuotientOfLEComap {R} [CommRing R] [Algebra R A] {p : Ideal R} {P : Ideal A} [P.IsTwoSided] (h : p ≤ comap (algebraMap R A) P) : Algebra (R ⧸ p) (A ⧸ P) where algebraMap := quotientMap P (algebraMap R A) h smul := Quotient.lift₂ (⟦· • ·⟧) fun r₁ a₁ r₂ a₂ hr ha ↦ Quotient.sound <| by have := h (p.quotientRel_def.mp hr) rw [mem_comap, map_sub] at this simpa only [Algebra.smul_def] using P.quotientRel_def.mpr (P.mul_sub_mul_mem this <| P.quotientRel_def.mp ha) smul_def' := by rintro ⟨_⟩ ⟨_⟩; exact congr_arg (⟦·⟧) (Algebra.smul_def _ _) commutes' := by rintro ⟨_⟩ ⟨_⟩; exact congr_arg (⟦·⟧) (Algebra.commutes _ _) instance (priority := 100) quotientAlgebra {R} [CommRing R] {I : Ideal A} [I.IsTwoSided] [Algebra R A] : Algebra (R ⧸ I.comap (algebraMap R A)) (A ⧸ I) := Quotient.algebraQuotientOfLEComap le_rfl instance (R) {A} [CommRing R] [CommRing A] (I : Ideal A) [Algebra R A] : Algebra (R ⧸ I.comap (algebraMap R A)) (A ⧸ I) := inferInstance theorem algebraMap_quotient_injective {R} [CommRing R] {I : Ideal A} [I.IsTwoSided] [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} [I.IsTwoSided] [J.IsTwoSided] (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} [I.IsTwoSided] [J.IsTwoSided] (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} [I.IsTwoSided] [J.IsTwoSided] (h : I = J) : (quotientEquivAlgOfEq R₁ h).symm = quotientEquivAlgOfEq R₁ h.symm := by ext rfl lemma comap_map_mk {I J : Ideal R} [I.IsTwoSided] (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 {R A B : Type*} [CommSemiring R] [Ring 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 section quotientBot variable {R S : Type*} variable (R) in /-- The quotient of a ring by he zero ideal is isomorphic to the ring itself. -/ def RingEquiv.quotientBot [Ring R] : R ⧸ (⊥ : Ideal R) ≃+* R := (Ideal.quotEquivOfEq (RingHom.ker_coe_equiv <| .refl _).symm).trans <| RingHom.quotientKerEquivOfRightInverse (f := .id R) (g := _root_.id) fun _ ↦ rfl @[simp] lemma RingEquiv.quotientBot_mk [Ring R] (r : R) : RingEquiv.quotientBot R (Ideal.Quotient.mk ⊥ r) = r := rfl @[simp] lemma RingEquiv.quotientBot_symm_mk [Ring R] (r : R) : (RingEquiv.quotientBot R).symm r = r := rfl variable (R S) in /-- `RingEquiv.quotientBot` as an algebra isomorphism. -/ def AlgEquiv.quotientBot [CommSemiring R] [Ring S] [Algebra R S] : (S ⧸ (⊥ : Ideal S)) ≃ₐ[R] S where __ := RingEquiv.quotientBot S commutes' x := by simp [← Ideal.Quotient.mk_algebraMap] @[simp] lemma AlgEquiv.quotientBot_mk [CommSemiring R] [CommRing S] [Algebra R S] (s : S) : AlgEquiv.quotientBot R S (Ideal.Quotient.mk ⊥ s) = s := rfl @[simp] lemma AlgEquiv.quotientBot_symm_mk [CommSemiring R] [CommRing S] [Algebra R S] (s : S) : (AlgEquiv.quotientBot R S).symm s = s := rfl end quotientBot 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 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) /-- 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) Ideal.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 @[simp] theorem quotQuotEquivComm_quotQuotMk (x : R) : quotQuotEquivComm I J (quotQuotMk I J x) = quotQuotMk J I x := rfl @[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 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] 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] 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 := 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 rfl @[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] 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] 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 namespace Ideal section PowQuot variable {R : Type*} [CommRing R] (I : Ideal R) (n : ℕ) /-- `I ^ n ⧸ I ^ (n + 1)` can be viewed as a quotient module and as ideal of `R ⧸ I ^ (n + 1)`. This definition gives the `R`-linear equivalence between the two. -/ noncomputable def powQuotPowSuccLinearEquivMapMkPowSuccPow : ((I ^ n : Ideal R) ⧸ (I • ⊤ : Submodule R (I ^ n : Ideal R))) ≃ₗ[R] Ideal.map (Ideal.Quotient.mk (I ^ (n + 1))) (I ^ n) := by refine { LinearMap.codRestrict (Submodule.restrictScalars _ (Ideal.map (Ideal.Quotient.mk (I ^ (n + 1))) (I ^ n))) (Submodule.mapQ (I • ⊤) (I ^ (n + 1)) (Submodule.subtype (I ^ n)) ?_) ?_, Equiv.ofBijective _ ⟨?_, ?_⟩ with } · intro simp [Submodule.mem_smul_top_iff, pow_succ'] · intro x obtain ⟨⟨y, hy⟩, rfl⟩ := Submodule.Quotient.mk_surjective _ x simp [Ideal.mem_sup_left hy] · intro a b obtain ⟨⟨x, hx⟩, rfl⟩ := Submodule.Quotient.mk_surjective _ a obtain ⟨⟨y, hy⟩, rfl⟩ := Submodule.Quotient.mk_surjective _ b simp [Ideal.Quotient.eq, Submodule.Quotient.eq, Submodule.mem_smul_top_iff, pow_succ'] · intro ⟨x, hx⟩ rw [Ideal.mem_map_iff_of_surjective _ Ideal.Quotient.mk_surjective] at hx obtain ⟨y, hy, rfl⟩ := hx refine ⟨Submodule.Quotient.mk ⟨y, hy⟩, ?_⟩ simp /-- `I ^ n ⧸ I ^ (n + 1)` can be viewed as a quotient module and as ideal of `R ⧸ I ^ (n + 1)`. This definition gives the equivalence between the two, instead of the `R`-linear equivalence, to bypass typeclass synthesis issues on complex `Module` goals. -/ noncomputable def powQuotPowSuccEquivMapMkPowSuccPow : ((I ^ n : Ideal R) ⧸ (I • ⊤ : Submodule R (I ^ n : Ideal R))) ≃ Ideal.map (Ideal.Quotient.mk (I ^ (n + 1))) (I ^ n) := powQuotPowSuccLinearEquivMapMkPowSuccPow I n end PowQuot end Ideal
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/Quotient/Defs.lean
import Mathlib.LinearAlgebra.Quotient.Defs import Mathlib.RingTheory.Congruence.Defs import Mathlib.RingTheory.Ideal.Defs /-! # 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.instHasQuotient`: the quotient of a commutative ring `R` by an ideal `I : Ideal R` - `Ideal.Quotient.commRing`: the ring structure of the ideal quotient - `Ideal.Quotient.mk`: map an element of `R` to the quotient `R ⧸ I` - `Ideal.Quotient.lift`: turn a map `R → S` into a map `R ⧸ I → S` - `Ideal.quotEquivOfEq`: quotienting by equal ideals gives isomorphic rings -/ universe u v w namespace Ideal open Set variable {R : Type u} [Ring R] (I J : Ideal R) {a b : R} variable {S : Type v} /-- The quotient `R/I` of a ring `R` by an ideal `I`, defined to equal the quotient of `I` as an `R`-submodule of `R`. -/ instance instHasQuotient : HasQuotient R (Ideal R) := Submodule.hasQuotient /-- Shortcut instance for commutative rings. -/ instance {R} [CommRing R] : HasQuotient R (Ideal R) := inferInstance 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) [I.IsTwoSided] : RingCon R where __ := QuotientAddGroup.con I.toAddSubgroup mul' {a₁ b₁ a₂ b₂} h₁ h₂ := by rw [Submodule.quotientRel_def] at h₁ h₂ ⊢ exact mul_sub_mul_mem I h₁ h₂ instance ring (I : Ideal R) [I.IsTwoSided] : Ring (R ⧸ I) := fast_instance% { __ : AddCommGroup (R ⧸ I) := inferInstance __ : Ring (Quotient.ringCon I).Quotient := inferInstance } instance commRing {R} [CommRing R] (I : Ideal R) : CommRing (R ⧸ I) := fast_instance% { mul_comm := by rintro ⟨a⟩ ⟨b⟩; exact congr_arg _ (mul_comm a b) } instance {R} [CommRing R] (I : Ideal R) : Ring (R ⧸ I) := fast_instance% inferInstance instance commSemiring {R} [CommRing R] (I : Ideal R) : CommSemiring (R ⧸ I) := fast_instance% inferInstance instance semiring {R} [CommRing R] (I : Ideal R) : Semiring (R ⧸ I) := fast_instance% inferInstance variable [I.IsTwoSided] -- Sanity test to make sure no diamonds have emerged in `commRing` example : (ring I).toAddCommGroup = Submodule.Quotient.addCommGroup I := rfl variable (I) in /-- The ring homomorphism from a ring `R` to a quotient ring `R/I`. -/ def mk : R →+* R ⧸ I where toFun a := Submodule.Quotient.mk a map_zero' := rfl map_one' := rfl map_mul' _ _ := rfl map_add' _ _ := rfl instance : 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 : Nonempty (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 : mk I a = 0 ↔ a ∈ I := Submodule.Quotient.mk_eq_zero _ 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] @[simp] theorem mk_out (x : R ⧸ I) : Ideal.Quotient.mk I (Quotient.out x) = x := Quotient.out_eq x 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 (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⟩⟩ variable [Semiring S] (I) /-- 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 (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 (f : R →+* S) (H : ∀ a : R, a ∈ I → f a = 0) : lift I f H (mk I a) = f a := rfl lemma lift_comp_mk (f : R →+* S) (H : ∀ a : R, a ∈ I → f a = 0) : (lift I f H).comp (mk I) = f := rfl theorem lift_surjective_of_surjective {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] variable {S T U : Ideal R} [S.IsTwoSided] [T.IsTwoSided] [U.IsTwoSided] /-- 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` When the two ideals are of the form `I^m` and `I^n` and `n ≤ m`, please refer to the dedicated version `Ideal.Quotient.factorPow`. -/ def factor (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 (H : S ≤ T) (x : R) : factor H (mk S x) = mk T x := rfl @[simp] theorem factor_eq : factor (le_refl S) = RingHom.id _ := by ext simp @[simp] theorem factor_comp_mk (H : S ≤ T) : (factor H).comp (mk S) = mk T := by ext x rw [RingHom.comp_apply, factor_mk] @[simp] theorem factor_comp (H1 : S ≤ T) (H2 : T ≤ U) : (factor H2).comp (factor H1) = factor (H1.trans H2) := by ext simp @[simp] theorem factor_comp_apply (H1 : S ≤ T) (H2 : T ≤ U) (x : R ⧸ S) : factor H2 (factor H1 x) = factor (H1.trans H2) x := by rw [← RingHom.comp_apply] simp lemma factor_surjective (H : S ≤ T) : Function.Surjective (factor H) := Ideal.Quotient.lift_surjective_of_surjective _ _ Ideal.Quotient.mk_surjective end Quotient variable {I J} [I.IsTwoSided] [J.IsTwoSided] /-- Quotienting by equal ideals gives equivalent rings. See also `Submodule.quotEquivOfEq` and `Ideal.quotientEquivAlgOfEq`. -/ def quotEquivOfEq (h : I = J) : R ⧸ I ≃+* R ⧸ J := { Submodule.quotEquivOfEq I J h with map_mul' := by rintro ⟨x⟩ ⟨y⟩ rfl } @[simp] theorem quotEquivOfEq_mk (h : I = J) (x : R) : quotEquivOfEq h (Ideal.Quotient.mk I x) = Ideal.Quotient.mk J x := rfl @[simp] theorem quotEquivOfEq_symm (h : I = J) : (Ideal.quotEquivOfEq h).symm = Ideal.quotEquivOfEq h.symm := by ext; rfl end Ideal
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/Quotient/ChineseRemainder.lean
import Mathlib.LinearAlgebra.TensorProduct.Pi import Mathlib.LinearAlgebra.TensorProduct.RightExactness import Mathlib.RingTheory.Ideal.Quotient.Operations /-! # Module version of Chinese remainder theorem -/ open Function variable {R : Type*} [CommRing R] {ι : Type*} variable (M : Type*) [AddCommGroup M] [Module R M] variable (I : ι → Ideal R) (hI : Pairwise (IsCoprime on I)) namespace Ideal open TensorProduct LinearMap lemma pi_mkQ_rTensor [Fintype ι] [DecidableEq ι] : (LinearMap.pi fun i ↦ (I i).mkQ).rTensor M = (piLeft ..).symm.toLinearMap ∘ₗ .pi (fun i ↦ TensorProduct.mk R (R ⧸ I i) M 1) ∘ₗ TensorProduct.lid R M := by ext; simp [LinearMap.pi, LinearEquiv.piCongrRight] variable [Finite ι] include hI attribute [local instance] Fintype.ofFinite /-- A form of Chinese remainder theorem for modules, part I: if ideals `Iᵢ` of `R` are pairwise coprime, then for any `R`-module `M`, the natural map `M → Πᵢ (R ⧸ Iᵢ) ⊗[R] M` is surjective. -/ theorem pi_tensorProductMk_quotient_surjective : Surjective (LinearMap.pi fun i ↦ TensorProduct.mk R (R ⧸ I i) M 1) := by have := rTensor_surjective M (pi_mkQ_surjective hI) classical rw [pi_mkQ_rTensor] at this simpa using this /-- A form of Chinese remainder theorem for modules, part II: if ideals `Iᵢ` of `R` are pairwise coprime, then for any `R`-module `M`, the kernel of `M → Πᵢ (R ⧸ Iᵢ) ⊗[R] M` equals `(⋂ᵢ Iᵢ) • M`. -/ theorem ker_tensorProductMk_quotient : ker (LinearMap.pi fun i ↦ TensorProduct.mk R (R ⧸ I i) M 1) = (⨅ i, I i) • (⊤ : Submodule R M) := by have := rTensor_exact M (exact_subtype_ker_map _) (pi_mkQ_surjective hI) rw [← (TensorProduct.lid R M).conj_exact_iff_exact, exact_iff] at this convert this · classical simp [pi_mkQ_rTensor, LinearMap.comp_assoc] refine le_antisymm (Submodule.smul_le.mpr fun r hr m _ ↦ ⟨⟨r, ?_⟩ ⊗ₜ m, rfl⟩) ?_ · simpa only [ker_pi, Submodule.ker_mkQ] rintro _ ⟨x, rfl⟩ refine x.induction_on (by simp) (fun r m ↦ Submodule.smul_mem_smul ?_ ⟨⟩) fun _ _ ↦ ?_ · simpa only [← (I _).ker_mkQ, ← ker_pi] using Subtype.mem _ · simpa using add_mem end Ideal
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/Quotient/Noetherian.lean
import Mathlib.RingTheory.Ideal.Quotient.Operations import Mathlib.RingTheory.Noetherian.Basic /-! # Noetherian quotient rings and quotient modules -/ instance Ideal.Quotient.isNoetherianRing {R : Type*} [CommRing R] [IsNoetherianRing R] (I : Ideal R) : IsNoetherianRing (R ⧸ I) := isNoetherianRing_iff.mpr <| isNoetherian_of_tower R <| inferInstance
.lake/packages/mathlib/Mathlib/RingTheory/Artinian/Instances.lean
import Mathlib.Algebra.Divisibility.Prod import Mathlib.Algebra.Polynomial.FieldDivision import Mathlib.RingTheory.Artinian.Module /-! # Instances related to Artinian rings We show that every reduced Artinian ring and the polynomial ring over it are decomposition monoids, and every reduced Artinian ring is semisimple. -/ namespace IsArtinianRing variable (R : Type*) [CommRing R] [IsArtinianRing R] [IsReduced R] attribute [local instance] fieldOfSubtypeIsMaximal instance : DecompositionMonoid R := MulEquiv.decompositionMonoid (equivPi R) instance : DecompositionMonoid (Polynomial R) := MulEquiv.decompositionMonoid <| (Polynomial.mapEquiv <| equivPi R).trans (Polynomial.piEquiv _) end IsArtinianRing
.lake/packages/mathlib/Mathlib/RingTheory/Artinian/Module.lean
import Mathlib.Algebra.Group.Units.Opposite import Mathlib.Algebra.Regular.Opposite import Mathlib.Data.SetLike.Fintype import Mathlib.LinearAlgebra.FreeModule.Finite.Basic import Mathlib.Order.Filter.EventuallyConst import Mathlib.RingTheory.Ideal.Prod import Mathlib.RingTheory.Ideal.Quotient.Operations import Mathlib.RingTheory.Jacobson.Semiprimary import Mathlib.RingTheory.Nilpotent.Lemmas import Mathlib.RingTheory.Noetherian.Defs import Mathlib.RingTheory.Spectrum.Maximal.Basic import Mathlib.RingTheory.Spectrum.Prime.Basic /-! # Artinian rings and modules A module satisfying these equivalent conditions is said to be an *Artinian* R-module if every decreasing chain of submodules is eventually constant, or equivalently, if the relation `<` on submodules is well founded. A ring is said to be left (or right) Artinian if it is Artinian as a left (or right) module over itself, or simply Artinian if it is both left and right Artinian. ## Main definitions Let `R` be a ring and let `M` and `P` be `R`-modules. Let `N` be an `R`-submodule of `M`. * `IsArtinian R M` is the proposition that `M` is an Artinian `R`-module. It is a class, implemented as the predicate that the `<` relation on submodules is well founded. * `IsArtinianRing R` is the proposition that `R` is a left Artinian ring. ## Main results * `IsArtinianRing.primeSpectrum_finite`, `IsArtinianRing.isMaximal_of_isPrime`: there are only finitely prime ideals in a commutative Artinian ring, and each of them is maximal. * `IsArtinianRing.equivPi`: a reduced commutative Artinian ring `R` is isomorphic to a finite product of fields (and therefore is a semisimple ring and a decomposition monoid; moreover `R[X]` is also a decomposition monoid). * `IsArtinian.isSemisimpleModule_iff_jacobson`: an Artinian module is semisimple iff its Jacobson radical is zero. * `instIsSemiprimaryRingOfIsArtinianRing`: an Artinian ring `R` is semiprimary, in particular the Jacobson radical of `R` is a nilpotent ideal (`IsArtinianRing.isNilpotent_jacobson_bot`). ## References * [M. F. Atiyah and I. G. Macdonald, *Introduction to commutative algebra*][atiyah-macdonald] * [P. Samuel, *Algebraic Theory of Numbers*][samuel1967] ## Tags Artinian, artinian, Artinian ring, Artinian module, artinian ring, artinian module -/ open Set Filter Pointwise /-- `IsArtinian R M` is the proposition that `M` is an Artinian `R`-module, implemented as the well-foundedness of submodule inclusion. -/ abbrev IsArtinian (R M) [Semiring R] [AddCommMonoid M] [Module R M] : Prop := WellFoundedLT (Submodule R M) theorem isArtinian_iff (R M) [Semiring R] [AddCommMonoid M] [Module R M] : IsArtinian R M ↔ WellFounded (· < · : Submodule R M → Submodule R M → Prop) := isWellFounded_iff _ _ section Semiring variable {R M P N : Type*} variable [Semiring R] [AddCommMonoid M] [AddCommMonoid P] [AddCommMonoid N] variable [Module R M] [Module R P] [Module R N] theorem LinearMap.isArtinian_iff_of_bijective {S P} [Semiring S] [AddCommMonoid P] [Module S P] {σ : R →+* S} [RingHomSurjective σ] (l : M →ₛₗ[σ] P) (hl : Function.Bijective l) : IsArtinian R M ↔ IsArtinian S P := let e := Submodule.orderIsoMapComapOfBijective l hl ⟨fun _ ↦ e.symm.strictMono.wellFoundedLT, fun _ ↦ e.strictMono.wellFoundedLT⟩ theorem isArtinian_of_injective (f : M →ₗ[R] P) (h : Function.Injective f) [IsArtinian R P] : IsArtinian R M := ⟨Subrelation.wf (fun {A B} hAB => show A.map f < B.map f from Submodule.map_strictMono_of_injective h hAB) (InvImage.wf (Submodule.map f) IsWellFounded.wf)⟩ instance isArtinian_submodule' [IsArtinian R M] (N : Submodule R M) : IsArtinian R N := isArtinian_of_injective N.subtype Subtype.val_injective theorem isArtinian_of_le {s t : Submodule R M} [IsArtinian R t] (h : s ≤ t) : IsArtinian R s := isArtinian_of_injective (Submodule.inclusion h) (Submodule.inclusion_injective h) variable (M) in theorem isArtinian_of_surjective (f : M →ₗ[R] P) (hf : Function.Surjective f) [IsArtinian R M] : IsArtinian R P := ⟨Subrelation.wf (fun {A B} hAB => show A.comap f < B.comap f from Submodule.comap_strictMono_of_surjective hf hAB) (InvImage.wf (Submodule.comap f) IsWellFounded.wf)⟩ /-- If `M` is an Artinian `R` module, and `S` is an `R`-algebra with a surjective algebra map, then `M` is an Artinian `S` module. -/ theorem isArtinian_of_surjective_algebraMap {S : Type*} [CommSemiring S] [Algebra S R] [Module S M] [IsArtinian R M] [IsScalarTower S R M] (H : Function.Surjective (algebraMap S R)) : IsArtinian S M := by apply (OrderEmbedding.wellFoundedLT (β := Submodule R M)) refine ⟨⟨?_, ?_⟩, ?_⟩ · intro N refine {toAddSubmonoid := N.toAddSubmonoid, smul_mem' := ?_} intro c x hx obtain ⟨r, rfl⟩ := H c suffices r • x ∈ N by simpa [Algebra.algebraMap_eq_smul_one, smul_assoc] apply N.smul_mem _ hx · intro N1 N2 h rwa [Submodule.ext_iff] at h ⊢ · intro N1 N2 rfl instance isArtinian_range (f : M →ₗ[R] P) [IsArtinian R M] : IsArtinian R (LinearMap.range f) := isArtinian_of_surjective _ _ f.surjective_rangeRestrict theorem isArtinian_of_linearEquiv (f : M ≃ₗ[R] P) [IsArtinian R M] : IsArtinian R P := isArtinian_of_surjective _ f.toLinearMap f.toEquiv.surjective theorem LinearEquiv.isArtinian_iff (f : M ≃ₗ[R] P) : IsArtinian R M ↔ IsArtinian R P := ⟨fun _ ↦ isArtinian_of_linearEquiv f, fun _ ↦ isArtinian_of_linearEquiv f.symm⟩ -- This was previously a global instance, -- but it doesn't appear to be used and has been implicated in slow typeclass resolutions. lemma isArtinian_of_finite [Finite M] : IsArtinian R M := ⟨Finite.wellFounded_of_trans_of_irrefl _⟩ open Submodule theorem IsArtinian.finite_of_linearIndependent [Nontrivial R] [h : IsArtinian R M] {s : Set M} (hs : LinearIndependent R ((↑) : s → M)) : s.Finite := by refine by_contradiction fun hf ↦ (RelEmbedding.wellFounded_iff_isEmpty.1 h.wf).elim' ?_ have f : ℕ ↪ s := Set.Infinite.natEmbedding s hf have : ∀ n, (↑) ∘ f '' { m | n ≤ m } ⊆ s := by rintro n x ⟨y, _, rfl⟩ exact (f y).2 have : ∀ a b : ℕ, a ≤ b ↔ span R (Subtype.val ∘ f '' { m | b ≤ m }) ≤ span R (Subtype.val ∘ f '' { m | a ≤ m }) := by intro a b rw [span_le_span_iff hs (this b) (this a), Set.image_subset_image_iff (Subtype.coe_injective.comp f.injective), Set.subset_def] simp only [Set.mem_setOf_eq] exact ⟨fun hab x ↦ hab.trans, (· _ le_rfl)⟩ exact ⟨⟨fun n ↦ span R (Subtype.val ∘ f '' { m | n ≤ m }), fun x y ↦ by rw [le_antisymm_iff, ← this y x, ← this x y] exact fun ⟨h₁, h₂⟩ ↦ le_antisymm_iff.2 ⟨h₂, h₁⟩⟩, by intro a b conv_rhs => rw [GT.gt, lt_iff_le_not_ge, this, this, ← lt_iff_le_not_ge] rfl⟩ /-- A module is Artinian iff every nonempty set of submodules has a minimal submodule among them. -/ theorem set_has_minimal_iff_artinian : (∀ a : Set <| Submodule R M, a.Nonempty → ∃ M' ∈ a, ∀ I ∈ a, ¬I < M') ↔ IsArtinian R M := by rw [isArtinian_iff, WellFounded.wellFounded_iff_has_min] theorem IsArtinian.set_has_minimal [IsArtinian R M] (a : Set <| Submodule R M) (ha : a.Nonempty) : ∃ M' ∈ a, ∀ I ∈ a, ¬I < M' := set_has_minimal_iff_artinian.mpr ‹_› a ha /-- A module is Artinian iff every decreasing chain of submodules stabilizes. -/ theorem monotone_stabilizes_iff_artinian : (∀ f : ℕ →o (Submodule R M)ᵒᵈ, ∃ n, ∀ m, n ≤ m → f n = f m) ↔ IsArtinian R M := wellFoundedGT_iff_monotone_chain_condition.symm namespace IsArtinian variable [IsArtinian R M] theorem monotone_stabilizes (f : ℕ →o (Submodule R M)ᵒᵈ) : ∃ n, ∀ m, n ≤ m → f n = f m := monotone_stabilizes_iff_artinian.mpr ‹_› f theorem eventuallyConst_of_isArtinian (f : ℕ →o (Submodule R M)ᵒᵈ) : atTop.EventuallyConst f := by simp_rw [eventuallyConst_atTop, eq_comm] exact monotone_stabilizes f /-- If `∀ I > J, P I` implies `P J`, then `P` holds for all submodules. -/ theorem induction {P : Submodule R M → Prop} (hgt : ∀ I, (∀ J < I, P J) → P I) (I : Submodule R M) : P I := WellFoundedLT.induction I hgt open Function /-- Any injective endomorphism of an Artinian module is surjective. -/ theorem surjective_of_injective_endomorphism (f : M →ₗ[R] M) (s : Injective f) : Surjective f := by have h := ‹IsArtinian R M›; contrapose! h rw [IsArtinian, WellFoundedLT, isWellFounded_iff] refine (RelEmbedding.natGT (LinearMap.range <| f ^ ·) ?_).not_wellFounded intro n simp_rw [pow_succ, Module.End.mul_eq_comp, LinearMap.range_comp, ← Submodule.map_top (f ^ n)] refine Submodule.map_strictMono_of_injective (Module.End.iterate_injective s n) (Ne.lt_top ?_) rwa [Ne, LinearMap.range_eq_top] /-- Any injective endomorphism of an Artinian module is bijective. -/ theorem bijective_of_injective_endomorphism (f : M →ₗ[R] M) (s : Injective f) : Bijective f := ⟨s, surjective_of_injective_endomorphism f s⟩ /-- A sequence `f` of submodules of an Artinian module, with the supremum `f (n+1)` and the infimum of `f 0`, ..., `f n` being ⊤, is eventually ⊤. -/ theorem disjoint_partial_infs_eventually_top (f : ℕ → Submodule R M) (h : ∀ n, Disjoint (partialSups (OrderDual.toDual ∘ f) n) (OrderDual.toDual (f (n + 1)))) : ∃ n : ℕ, ∀ m, n ≤ m → f m = ⊤ := by -- A little off-by-one cleanup first: rsuffices ⟨n, w⟩ : ∃ n : ℕ, ∀ m, n ≤ m → OrderDual.toDual f (m + 1) = ⊤ · use n + 1 rintro (_ | m) p · cases p · apply w exact Nat.succ_le_succ_iff.mp p obtain ⟨n, w⟩ := monotone_stabilizes (partialSups (OrderDual.toDual ∘ f)) refine ⟨n, fun m p ↦ (h m).eq_bot_of_ge <| sup_eq_left.mp ?_⟩ simpa only [partialSups_add_one] using (w (m + 1) <| le_add_right p).symm.trans <| w m p end IsArtinian namespace LinearMap variable [IsArtinian R M] lemma eventually_iInf_range_pow_eq (f : Module.End R M) : ∀ᶠ n in atTop, ⨅ m, LinearMap.range (f ^ m) = LinearMap.range (f ^ n) := by obtain ⟨n, hn : ∀ m, n ≤ m → LinearMap.range (f ^ n) = LinearMap.range (f ^ m)⟩ := IsArtinian.monotone_stabilizes f.iterateRange refine eventually_atTop.mpr ⟨n, fun l hl ↦ le_antisymm (iInf_le _ _) (le_iInf fun m ↦ ?_)⟩ rcases le_or_gt l m with h | h · rw [← hn _ (hl.trans h), hn _ hl] · exact f.iterateRange.monotone h.le end LinearMap end Semiring section Ring variable {R M P N : Type*} variable [Ring R] [AddCommGroup M] [AddCommGroup P] [AddCommGroup N] variable [Module R M] [Module R P] [Module R N] instance isArtinian_of_quotient_of_artinian (N : Submodule R M) [IsArtinian R M] : IsArtinian R (M ⧸ N) := isArtinian_of_surjective M (Submodule.mkQ N) (Submodule.Quotient.mk_surjective N) theorem isArtinian_of_range_eq_ker [IsArtinian R M] [IsArtinian R P] (f : M →ₗ[R] N) (g : N →ₗ[R] P) (h : LinearMap.range f = LinearMap.ker g) : IsArtinian R N := wellFounded_lt_exact_sequence (LinearMap.range f) (Submodule.map ((LinearMap.ker f).liftQ f le_rfl)) (Submodule.comap ((LinearMap.ker f).liftQ f le_rfl)) (Submodule.comap g.rangeRestrict) (Submodule.map g.rangeRestrict) (Submodule.gciMapComap <| LinearMap.ker_eq_bot.mp <| Submodule.ker_liftQ_eq_bot _ _ _ le_rfl) (Submodule.giMapComap g.surjective_rangeRestrict) (by simp [Submodule.map_comap_eq, inf_comm, Submodule.range_liftQ]) (by simp [Submodule.comap_map_eq, h]) theorem isArtinian_iff_submodule_quotient (S : Submodule R P) : IsArtinian R P ↔ IsArtinian R S ∧ IsArtinian R (P ⧸ S) := by refine ⟨fun h ↦ ⟨inferInstance, inferInstance⟩, fun ⟨_, _⟩ ↦ ?_⟩ apply isArtinian_of_range_eq_ker S.subtype S.mkQ rw [Submodule.ker_mkQ, Submodule.range_subtype] instance isArtinian_prod [IsArtinian R M] [IsArtinian R P] : IsArtinian R (M × P) := isArtinian_of_range_eq_ker (LinearMap.inl R M P) (LinearMap.snd R M P) (LinearMap.range_inl R M P) instance isArtinian_sup (M₁ M₂ : Submodule R P) [IsArtinian R M₁] [IsArtinian R M₂] : IsArtinian R ↥(M₁ ⊔ M₂) := by have := isArtinian_range (M₁.subtype.coprod M₂.subtype) rwa [LinearMap.range_coprod, Submodule.range_subtype, Submodule.range_subtype] at this variable {ι : Type*} [Finite ι] instance isArtinian_pi : ∀ {M : ι → Type*} [Π i, AddCommGroup (M i)] [Π i, Module R (M i)] [∀ i, IsArtinian R (M i)], IsArtinian R (Π i, M i) := by apply Finite.induction_empty_option _ _ _ ι · exact fun e h ↦ isArtinian_of_linearEquiv (LinearEquiv.piCongrLeft R _ e) · infer_instance · exact fun ih ↦ isArtinian_of_linearEquiv (LinearEquiv.piOptionEquivProd R).symm /-- A version of `isArtinian_pi` for non-dependent functions. We need this instance because sometimes Lean fails to apply the dependent version in non-dependent settings (e.g., it fails to prove that `ι → ℝ` is finite dimensional over `ℝ`). -/ instance isArtinian_pi' [IsArtinian R M] : IsArtinian R (ι → M) := isArtinian_pi instance isArtinian_finsupp [IsArtinian R M] : IsArtinian R (ι →₀ M) := isArtinian_of_linearEquiv (Finsupp.linearEquivFunOnFinite _ _ _).symm instance isArtinian_iSup : ∀ {M : ι → Submodule R P} [∀ i, IsArtinian R (M i)], IsArtinian R ↥(⨆ i, M i) := by apply Finite.induction_empty_option _ _ _ ι · intro _ _ e h _ _; rw [← e.iSup_comp]; apply h · intros; rw [iSup_of_empty]; infer_instance · intro _ _ ih _ _; rw [iSup_option]; infer_instance variable (R M) in theorem IsArtinian.isSemisimpleModule_iff_jacobson [IsArtinian R M] : IsSemisimpleModule R M ↔ Module.jacobson R M = ⊥ := ⟨fun _ ↦ IsSemisimpleModule.jacobson_eq_bot R M, fun h ↦ have ⟨s, hs⟩ := Finset.exists_inf_le (Subtype.val (p := fun m : Submodule R M ↦ IsCoatom m)) have _ (m : s) : IsSimpleModule R (M ⧸ m.1.1) := isSimpleModule_iff_isCoatom.mpr m.1.2 let f : M →ₗ[R] ∀ m : s, M ⧸ m.1.1 := LinearMap.pi fun m ↦ m.1.1.mkQ .of_injective f <| LinearMap.ker_eq_bot.mp <| le_bot_iff.mp fun x hx ↦ by rw [← h, Module.jacobson, Submodule.mem_sInf] exact fun m hm ↦ hs ⟨m, hm⟩ <| Submodule.mem_finsetInf.mpr fun i hi ↦ (Submodule.Quotient.mk_eq_zero i.1).mp <| congr_fun hx ⟨i, hi⟩⟩ open Submodule Function namespace LinearMap variable [IsArtinian R M] /-- For any endomorphism of an Artinian module, any sufficiently high iterate has codisjoint kernel and range. -/ theorem eventually_codisjoint_ker_pow_range_pow (f : Module.End R M) : ∀ᶠ n in atTop, Codisjoint (LinearMap.ker (f ^ n)) (LinearMap.range (f ^ n)) := by obtain ⟨n, hn : ∀ m, n ≤ m → LinearMap.range (f ^ n) = LinearMap.range (f ^ m)⟩ := IsArtinian.monotone_stabilizes f.iterateRange refine eventually_atTop.mpr ⟨n, fun m hm ↦ codisjoint_iff.mpr ?_⟩ simp_rw [← hn _ hm, Submodule.eq_top_iff', Submodule.mem_sup] intro x rsuffices ⟨y, hy⟩ : ∃ y, (f ^ m) ((f ^ n) y) = (f ^ m) x · exact ⟨x - (f ^ n) y, by simp [hy], (f ^ n) y, by simp⟩ -- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to change `mem_range` into `mem_range (f := _)` simp_rw [f.pow_apply n, f.pow_apply m, ← iterate_add_apply, ← f.pow_apply (m + n), ← f.pow_apply m, ← mem_range (f := _), ← hn _ (n.le_add_left m), hn _ hm] exact LinearMap.mem_range_self (f ^ m) x /-- This is the Fitting decomposition of the module `M` with respect to the endomorphism `f`. See also `LinearMap.isCompl_iSup_ker_pow_iInf_range_pow` for an alternative spelling. -/ theorem eventually_isCompl_ker_pow_range_pow [IsNoetherian R M] (f : Module.End R M) : ∀ᶠ n in atTop, IsCompl (LinearMap.ker (f ^ n)) (LinearMap.range (f ^ n)) := by filter_upwards [f.eventually_disjoint_ker_pow_range_pow.and f.eventually_codisjoint_ker_pow_range_pow] with n hn simpa only [isCompl_iff] /-- This is the Fitting decomposition of the module `M` with respect to the endomorphism `f`. See also `LinearMap.eventually_isCompl_ker_pow_range_pow` for an alternative spelling. -/ theorem isCompl_iSup_ker_pow_iInf_range_pow [IsNoetherian R M] (f : M →ₗ[R] M) : IsCompl (⨆ n, LinearMap.ker (f ^ n)) (⨅ n, LinearMap.range (f ^ n)) := by obtain ⟨k, hk⟩ := eventually_atTop.mp <| f.eventually_isCompl_ker_pow_range_pow.and <| f.eventually_iInf_range_pow_eq.and f.eventually_iSup_ker_pow_eq obtain ⟨h₁, h₂, h₃⟩ := hk k (le_refl k) rwa [h₂, h₃] end LinearMap end Ring section CommSemiring variable {R : Type*} (M : Type*) [CommSemiring R] [AddCommMonoid M] [Module R M] [IsArtinian R M] namespace IsArtinian theorem range_smul_pow_stabilizes (r : R) : ∃ n : ℕ, ∀ m, n ≤ m → LinearMap.range (r ^ n • LinearMap.id : M →ₗ[R] M) = LinearMap.range (r ^ m • LinearMap.id : M →ₗ[R] M) := monotone_stabilizes ⟨fun n => LinearMap.range (r ^ n • LinearMap.id : M →ₗ[R] M), fun n m h x ⟨y, hy⟩ => ⟨r ^ (m - n) • y, by dsimp at hy ⊢ rw [← smul_assoc, smul_eq_mul, ← pow_add, ← hy, add_tsub_cancel_of_le h]⟩⟩ variable {M} theorem exists_pow_succ_smul_dvd (r : R) (x : M) : ∃ (n : ℕ) (y : M), r ^ n.succ • y = r ^ n • x := by obtain ⟨n, hn⟩ := IsArtinian.range_smul_pow_stabilizes M r simp_rw [SetLike.ext_iff] at hn exact ⟨n, by simpa using hn n.succ n.le_succ (r ^ n • x)⟩ end IsArtinian end CommSemiring theorem isArtinian_of_submodule_of_artinian (R M) [Semiring R] [AddCommMonoid M] [Module R M] (N : Submodule R M) (_ : IsArtinian R M) : IsArtinian R N := inferInstance /-- If `M / S / R` is a scalar tower, and `M / R` is Artinian, then `M / S` is also Artinian. -/ theorem isArtinian_of_tower (R) {S M} [Semiring R] [Semiring S] [AddCommMonoid M] [SMul R S] [Module S M] [Module R M] [IsScalarTower R S M] (h : IsArtinian R M) : IsArtinian S M := ⟨(Submodule.restrictScalarsEmbedding R S M).wellFounded h.wf⟩ -- See `Mathlib/RingTheory/Artinian/Ring.lean` assert_not_exists IsLocalization IsLocalRing /-- A ring is Artinian if it is Artinian as a module over itself. Strictly speaking, this should be called `IsLeftArtinianRing` but we omit the `Left` for convenience in the commutative case. For a right Artinian ring, use `IsArtinian Rᵐᵒᵖ R`. For equivalent definitions, see `Mathlib/RingTheory/Artinian/Ring.lean`. -/ @[stacks 00J5] abbrev IsArtinianRing (R) [Semiring R] := IsArtinian R R theorem isArtinianRing_iff {R} [Semiring R] : IsArtinianRing R ↔ IsArtinian R R := Iff.rfl instance DivisionSemiring.instIsArtinianRing {K : Type*} [DivisionSemiring K] : IsArtinianRing K := ⟨Finite.wellFounded_of_trans_of_irrefl _⟩ instance DivisionRing.instIsArtinianRing {K : Type*} [DivisionRing K] : IsArtinianRing K := inferInstance theorem Ring.isArtinian_of_zero_eq_one {R} [Semiring R] (h01 : (0 : R) = 1) : IsArtinianRing R := have := subsingleton_of_zero_eq_one h01 inferInstance instance (R) [Ring R] [IsArtinianRing R] (I : Ideal R) [I.IsTwoSided] : IsArtinianRing (R ⧸ I) := isArtinian_of_tower R inferInstance open Submodule Function instance isArtinian_of_fg_of_artinian' {R M} [Ring R] [AddCommGroup M] [Module R M] [IsArtinianRing R] [Module.Finite R M] : IsArtinian R M := have ⟨_, _, h⟩ := Module.Finite.exists_fin' R M isArtinian_of_surjective _ _ h theorem isArtinian_of_fg_of_artinian {R M} [Ring R] [AddCommGroup M] [Module R M] (N : Submodule R M) [IsArtinianRing R] (hN : N.FG) : IsArtinian R N := by rw [← Module.Finite.iff_fg] at hN; infer_instance theorem IsArtinianRing.of_finite (R S) [Ring R] [Ring S] [Module R S] [IsScalarTower R S S] [IsArtinianRing R] [Module.Finite R S] : IsArtinianRing S := isArtinian_of_tower R isArtinian_of_fg_of_artinian' instance (n R) [Fintype n] [DecidableEq n] [Ring R] [IsNoetherianRing R] : IsNoetherianRing (Matrix n n R) := .of_finite R _ instance (n R) [Fintype n] [DecidableEq n] [Ring R] [IsArtinianRing R] : IsArtinianRing (Matrix n n R) := .of_finite R _ /-- In a module over an Artinian ring, the submodule generated by finitely many vectors is Artinian. -/ theorem isArtinian_span_of_finite (R) {M} [Ring R] [AddCommGroup M] [Module R M] [IsArtinianRing R] {A : Set M} (hA : A.Finite) : IsArtinian R (Submodule.span R A) := isArtinian_of_fg_of_artinian _ (Submodule.fg_def.mpr ⟨A, hA, rfl⟩) theorem Function.Surjective.isArtinianRing {R} [Semiring R] {S} [Semiring S] {F} [FunLike F R S] [RingHomClass F R S] {f : F} (hf : Function.Surjective f) [H : IsArtinianRing R] : IsArtinianRing S := by rw [isArtinianRing_iff] at H ⊢ exact ⟨(Ideal.orderEmbeddingOfSurjective f hf).wellFounded H.wf⟩ instance isArtinianRing_rangeS {R} [Semiring R] {S} [Semiring S] (f : R →+* S) [IsArtinianRing R] : IsArtinianRing f.rangeS := f.rangeSRestrict_surjective.isArtinianRing instance isArtinianRing_range {R} [Ring R] {S} [Ring S] (f : R →+* S) [IsArtinianRing R] : IsArtinianRing f.range := isArtinianRing_rangeS f theorem RingEquiv.isArtinianRing {R S} [Semiring R] [Semiring S] (f : R ≃+* S) [IsArtinianRing R] : IsArtinianRing S := f.surjective.isArtinianRing instance {R S} [Semiring R] [Semiring S] [IsArtinianRing R] [IsArtinianRing S] : IsArtinianRing (R × S) := Ideal.idealProdEquiv.toOrderEmbedding.wellFoundedLT instance {ι} [Finite ι] : ∀ {R : ι → Type*} [Π i, Semiring (R i)] [∀ i, IsArtinianRing (R i)], IsArtinianRing (Π i, R i) := by apply Finite.induction_empty_option _ _ _ ι · exact fun e h ↦ RingEquiv.isArtinianRing (.piCongrLeft _ e) · infer_instance · exact fun ih ↦ RingEquiv.isArtinianRing (.symm .piOptionEquivProd) namespace IsArtinianRing section Semiring variable {R : Type*} [Semiring R] theorem isUnit_iff_isRightRegular [IsArtinianRing R] {x : R} : IsUnit x ↔ IsRightRegular x := by rw [IsRightRegular, IsUnit.isUnit_iff_mulRight_bijective, Bijective, and_iff_left_of_imp] exact IsArtinian.surjective_of_injective_endomorphism (.toSpanSingleton R R x) theorem isUnit_iff_isRegular [IsArtinianRing R] {x : R} : IsUnit x ↔ IsRegular x := by rw [isRegular_iff, ← isUnit_iff_isRightRegular, and_iff_right_of_imp (·.isRegular.1)] theorem isUnit_iff_isLeftRegular [IsArtinianRing Rᵐᵒᵖ] {x : R} : IsUnit x ↔ IsLeftRegular x := by rw [← isRightRegular_op, ← isUnit_op, isUnit_iff_isRightRegular] theorem isUnit_iff_isRegular_of_mulOpposite [IsArtinianRing Rᵐᵒᵖ] {x : R} : IsUnit x ↔ IsRegular x := by rw [isRegular_iff, ← isUnit_iff_isLeftRegular, and_iff_left_of_imp (·.isRegular.2)] end Semiring section Ring variable {R : Type*} [Ring R] open nonZeroDivisors /-- If an element of an Artinian ring is not a zero divisor then it is a unit. -/ theorem isUnit_of_mem_nonZeroDivisors [IsArtinianRing R] {a : R} (ha : a ∈ R⁰) : IsUnit a := by rwa [isUnit_iff_isRegular, isRegular_iff_mem_nonZeroDivisors] theorem isUnit_of_mem_nonZeroDivisors_of_mulOpposite [IsArtinianRing Rᵐᵒᵖ] {a : R} (ha : a ∈ R⁰) : IsUnit a := by rwa [isUnit_iff_isRegular_of_mulOpposite, isRegular_iff_mem_nonZeroDivisors] /-- In an Artinian ring, an element is a unit iff it is a non-zero-divisor. See also `isUnit_iff_mem_nonZeroDivisors_of_finite`. -/ theorem isUnit_iff_mem_nonZeroDivisors [IsArtinianRing R] {a : R} : IsUnit a ↔ a ∈ R⁰ := by rw [isUnit_iff_isRegular, isRegular_iff_mem_nonZeroDivisors] theorem isUnit_iff_mem_nonZeroDivisors_of_mulOpposite [IsArtinianRing Rᵐᵒᵖ] {a : R} : IsUnit a ↔ a ∈ R⁰ := by rw [isUnit_iff_isRegular_of_mulOpposite, isRegular_iff_mem_nonZeroDivisors] variable (R) theorem isUnitSubmonoid_eq [IsArtinianRing R] : IsUnit.submonoid R = R⁰ := by ext; simp [IsUnit.mem_submonoid_iff, isUnit_iff_mem_nonZeroDivisors] @[deprecated (since := "2025-08-26")] alias isUnit_submonoid_eq := isUnitSubmonoid_eq theorem isUnitSubmonoid_eq_of_mulOpposite [IsArtinianRing Rᵐᵒᵖ] : IsUnit.submonoid R = R⁰ := by ext; simp [IsUnit.mem_submonoid_iff, isUnit_iff_mem_nonZeroDivisors_of_mulOpposite] theorem isUnitSubmonoid_eq_nonZeroDivisorsRight [IsArtinianRing R] : IsUnit.submonoid R = nonZeroDivisorsRight R := by ext; rw [← isRightRegular_iff_mem_nonZeroDivisorsRight]; exact isUnit_iff_isRightRegular theorem nonZeroDivisorsLeft_eq_isUnitSubmonoid [IsArtinianRing Rᵐᵒᵖ] : IsUnit.submonoid R = nonZeroDivisorsLeft R := by ext; rw [← isLeftRegular_iff_mem_nonZeroDivisorsLeft]; exact isUnit_iff_isLeftRegular end Ring section CommSemiring variable (R : Type*) [CommSemiring R] [IsArtinianRing R] @[stacks 00J7] lemma setOf_isMaximal_finite : {I : Ideal R | I.IsMaximal}.Finite := by have ⟨s, H⟩ := Finset.exists_inf_le (Subtype.val (p := fun I : Ideal R ↦ I.IsMaximal)) refine Set.finite_def.2 ⟨s, fun p ↦ ?_⟩ have ⟨q, hq1, hq2⟩ := p.2.isPrime.inf_le'.mp (H p) rwa [← Subtype.ext <| q.2.eq_of_le p.2.ne_top hq2] instance : Finite (MaximalSpectrum R) := haveI : Finite {I : Ideal R // I.IsMaximal} := (setOf_isMaximal_finite R).to_subtype .of_equiv _ (MaximalSpectrum.equivSubtype _).symm end CommSemiring section CommRing variable {R : Type*} [CommRing R] [IsArtinianRing R] variable (R) in lemma isField_of_isDomain [IsDomain R] : IsField R := by refine ⟨Nontrivial.exists_pair_ne, mul_comm, fun {x} hx ↦ ?_⟩ obtain ⟨n, y, hy⟩ := IsArtinian.exists_pow_succ_smul_dvd x (1 : R) replace hy : x ^ n * (x * y - 1) = 0 := by rw [mul_sub, sub_eq_zero] convert hy using 1 simp [Nat.succ_eq_add_one, pow_add, mul_assoc] rw [mul_eq_zero, sub_eq_zero] at hy exact ⟨_, hy.resolve_left <| pow_ne_zero _ hx⟩ /- Does not hold in a commutative semiring: consider {0, 0.5, 1} with ⊔ as + and ⊓ as *, then both {0} and {0, 0.5} are prime ideals. -/ -- Note: type class synthesis should try to synthesize `p.IsPrime` before `IsArtinianRing R`, -- hence the argument order. instance isMaximal_of_isPrime {R : Type*} [CommRing R] (p : Ideal R) [p.IsPrime] [IsArtinianRing R] : p.IsMaximal := Ideal.Quotient.maximal_of_isField _ (isField_of_isDomain _) lemma isPrime_iff_isMaximal (p : Ideal R) : p.IsPrime ↔ p.IsMaximal := ⟨fun _ ↦ isMaximal_of_isPrime p, fun h ↦ h.isPrime⟩ /-- The prime spectrum is in bijection with the maximal spectrum. -/ @[simps] def primeSpectrumEquivMaximalSpectrum : PrimeSpectrum R ≃ MaximalSpectrum R where toFun I := ⟨I.asIdeal, isPrime_iff_isMaximal I.asIdeal |>.mp I.isPrime⟩ invFun I := ⟨I.asIdeal, isPrime_iff_isMaximal I.asIdeal |>.mpr I.isMaximal⟩ lemma primeSpectrumEquivMaximalSpectrum_comp_asIdeal : MaximalSpectrum.asIdeal ∘ primeSpectrumEquivMaximalSpectrum = PrimeSpectrum.asIdeal (R := R) := rfl lemma primeSpectrumEquivMaximalSpectrum_symm_comp_asIdeal : PrimeSpectrum.asIdeal ∘ primeSpectrumEquivMaximalSpectrum.symm = MaximalSpectrum.asIdeal (R := R) := rfl lemma primeSpectrum_asIdeal_range_eq : range PrimeSpectrum.asIdeal = (range <| MaximalSpectrum.asIdeal (R := R)) := by simp only [PrimeSpectrum.range_asIdeal, MaximalSpectrum.range_asIdeal, isPrime_iff_isMaximal] variable (R) lemma setOf_isPrime_finite : {I : Ideal R | I.IsPrime}.Finite := by simpa only [isPrime_iff_isMaximal] using setOf_isMaximal_finite R instance : Finite (PrimeSpectrum R) := haveI : Finite {I : Ideal R // I.IsPrime} := (setOf_isPrime_finite R).to_subtype .of_equiv _ (PrimeSpectrum.equivSubtype _).symm.toEquiv /-- A temporary field instance on the quotients by maximal ideals. -/ @[local instance] noncomputable def fieldOfSubtypeIsMaximal (I : MaximalSpectrum R) : Field (R ⧸ I.asIdeal) := Ideal.Quotient.field I.asIdeal /-- The quotient of a commutative Artinian ring by its nilradical is isomorphic to a finite product of fields, namely the quotients by the maximal ideals. -/ noncomputable def quotNilradicalEquivPi : R ⧸ nilradical R ≃+* ∀ I : MaximalSpectrum R, R ⧸ I.asIdeal := let f := MaximalSpectrum.asIdeal (R := R) .trans (Ideal.quotEquivOfEq <| ext fun x ↦ by rw [PrimeSpectrum.nilradical_eq_iInf, iInf, primeSpectrum_asIdeal_range_eq]; rfl) (Ideal.quotientInfRingEquivPiQuotient f <| fun I J h ↦ Ideal.isCoprime_iff_sup_eq.mpr <| I.2.coprime_of_ne J.2 <| fun hIJ ↦ h <| MaximalSpectrum.ext hIJ) /-- A reduced commutative Artinian ring is isomorphic to a finite product of fields, namely the quotients by the maximal ideals. -/ noncomputable def equivPi [IsReduced R] : R ≃+* ∀ I : MaximalSpectrum R, R ⧸ I.asIdeal := .trans (.symm <| .quotientBot R) <| .trans (Ideal.quotEquivOfEq (nilradical_eq_zero R).symm) (quotNilradicalEquivPi R) theorem isSemisimpleRing_of_isReduced [IsReduced R] : IsSemisimpleRing R := (equivPi R).symm.isSemisimpleRing end CommRing section Ring variable {R : Type*} [Ring R] [IsArtinianRing R] theorem isSemisimpleRing_iff_jacobson : IsSemisimpleRing R ↔ Ring.jacobson R = ⊥ := IsArtinian.isSemisimpleModule_iff_jacobson R R instance : IsSemiprimaryRing R where isSemisimpleRing := IsArtinianRing.isSemisimpleRing_iff_jacobson.mpr (Ring.jacobson_quotient_jacobson R) isNilpotent := by let Jac := Ring.jacobson R have ⟨n, hn⟩ := IsArtinian.monotone_stabilizes ⟨(Jac ^ ·), @Ideal.pow_le_pow_right _ _ _⟩ have hn : Jac * Jac ^ n = Jac ^ n := by rw [← Ideal.IsTwoSided.pow_succ]; exact (hn _ n.le_succ).symm use n; by_contra ne have ⟨N, ⟨eq, ne⟩, min⟩ := wellFounded_lt.has_min {N | Jac * N = N ∧ N ≠ ⊥} ⟨_, hn, ne⟩ have : Jac ^ n * N = N := n.rec (by rw [Jac.pow_zero, N.one_mul]) fun n hn ↦ by rwa [Jac.pow_succ, mul_assoc, eq] let I x := Submodule.map (LinearMap.toSpanSingleton R R x) (Jac ^ n) have hI x : I x ≤ Ideal.span {x} := by rw [Ideal.span, LinearMap.span_singleton_eq_range]; exact LinearMap.map_le_range have ⟨x, hx⟩ : ∃ x ∈ N, I x ≠ ⊥ := by contrapose! ne rw [← this, ← le_bot_iff, Ideal.mul_le] refine fun ri hi rn hn ↦ ?_ rw [← ne rn hn] exact ⟨ri, hi, rfl⟩ rw [← Ideal.span_singleton_le_iff_mem] at hx have : I x = N := by refine ((hI x).trans hx.1).eq_of_not_lt (min _ ⟨?_, hx.2⟩) rw [← smul_eq_mul, ← Submodule.map_smul'', smul_eq_mul, hn] have : Ideal.span {x} = N := le_antisymm hx.1 (this.symm.trans_le <| hI x) refine (this ▸ ne) ((Submodule.fg_span <| Set.finite_singleton x).eq_bot_of_le_jacobson_smul ?_) rw [← Ideal.span, this, smul_eq_mul, eq] end Ring end IsArtinianRing
.lake/packages/mathlib/Mathlib/RingTheory/Artinian/Ring.lean
import Mathlib.Algebra.Field.Equiv import Mathlib.RingTheory.Artinian.Module import Mathlib.RingTheory.Localization.Defs import Mathlib.RingTheory.LocalRing.MaximalIdeal.Basic /-! # Artinian rings A ring is said to be left (or right) Artinian if it is Artinian as a left (or right) module over itself, or simply Artinian if it is both left and right Artinian. ## Main definitions * `IsArtinianRing R` is the proposition that `R` is a left Artinian ring. ## Main results * `IsArtinianRing.localization_surjective`: the canonical homomorphism from a commutative Artinian ring to any localization of itself is surjective. * `IsArtinianRing.isNilpotent_jacobson_bot`: the Jacobson radical of a commutative Artinian ring is a nilpotent ideal. ## Implementation Details The predicate `IsArtinianRing` is defined in `Mathlib/RingTheory/Artinian/Ring.lean` instead, so that we can apply basic API on Artinian modules to division rings without a heavy import. ## References * [M. F. Atiyah and I. G. Macdonald, *Introduction to commutative algebra*][atiyah-macdonald] * [P. Samuel, *Algebraic Theory of Numbers*][samuel1967] ## Tags Artinian, artinian, Artinian ring, artinian ring -/ open Set Submodule IsArtinian namespace IsArtinianRing @[stacks 00J8] theorem isNilpotent_jacobson_bot {R} [Ring R] [IsArtinianRing R] : IsNilpotent (Ideal.jacobson (⊥ : Ideal R)) := Ideal.jacobson_bot (R := R) ▸ IsSemiprimaryRing.isNilpotent variable {R : Type*} [CommRing R] [IsArtinianRing R] lemma jacobson_eq_radical (I : Ideal R) : I.jacobson = I.radical := by simp_rw [Ideal.jacobson, Ideal.radical_eq_sInf, IsArtinianRing.isPrime_iff_isMaximal] theorem isNilpotent_nilradical : IsNilpotent (nilradical R) := by rw [nilradical, ← jacobson_eq_radical] exact isNilpotent_jacobson_bot variable (R) in /-- Commutative Artinian reduced local ring is a field. -/ theorem isField_of_isReduced_of_isLocalRing [IsReduced R] [IsLocalRing R] : IsField R := (IsArtinianRing.equivPi R).trans (RingEquiv.piUnique _) |>.toMulEquiv.isField (Ideal.Quotient.field _).toIsField section Localization variable (S : Submonoid R) (L : Type*) [CommSemiring L] [Algebra R L] [IsLocalization S L] include S /-- Localizing an Artinian ring can only reduce the amount of elements. -/ theorem localization_surjective : Function.Surjective (algebraMap R L) := by intro r' obtain ⟨r₁, s, rfl⟩ := IsLocalization.exists_mk'_eq S r' rsuffices ⟨r₂, h⟩ : ∃ r : R, IsLocalization.mk' L 1 s = algebraMap R L r · exact ⟨r₁ * r₂, by rw [IsLocalization.mk'_eq_mul_mk'_one, map_mul, h]⟩ obtain ⟨n, r, hr⟩ := IsArtinian.exists_pow_succ_smul_dvd (s : R) (1 : R) use r rw [smul_eq_mul, smul_eq_mul, pow_succ, mul_assoc] at hr apply_fun algebraMap R L at hr simp only [map_mul] at hr rw [← IsLocalization.mk'_one (M := S) L, IsLocalization.mk'_eq_iff_eq, mul_one, Submonoid.coe_one, ← (IsLocalization.map_units L (s ^ n)).mul_left_cancel hr, map_mul] theorem localization_artinian : IsArtinianRing L := (localization_surjective S L).isArtinianRing /-- `IsArtinianRing.localization_artinian` can't be made an instance, as it would make `S` + `R` into metavariables. However, this is safe. -/ instance : IsArtinianRing (Localization S) := localization_artinian S _ end Localization end IsArtinianRing
.lake/packages/mathlib/Mathlib/RingTheory/Artinian/Algebra.lean
import Mathlib.RingTheory.Artinian.Module import Mathlib.RingTheory.IntegralClosure.Algebra.Defs import Mathlib.RingTheory.IntegralClosure.IsIntegral.Basic /-! # Algebras over Artinian rings In this file we collect results about algebras over Artinian rings. -/ namespace IsArtinianRing variable {R A : Type*} variable [CommRing R] [IsArtinianRing R] [Ring A] [Algebra R A] open nonZeroDivisors /-- In an `R`-algebra over an Artinian ring `R`, if an element is integral and is not a zero divisor, then it is a unit. -/ theorem isUnit_of_isIntegral_of_nonZeroDivisor {a : A} (hi : IsIntegral R a) (ha : a ∈ A⁰) : IsUnit a := let B := Algebra.adjoin R {a} let b : B := ⟨a, Algebra.self_mem_adjoin_singleton R a⟩ haveI : Module.Finite R B := Algebra.finite_adjoin_simple_of_isIntegral hi haveI : IsArtinianRing B := isArtinian_of_tower R inferInstance have hinj : Function.Injective B.subtype := Subtype.val_injective have hb : b ∈ B⁰ := comap_nonZeroDivisors_le_of_injective hinj ha (isUnit_of_mem_nonZeroDivisors hb).map B.subtype /-- Integral element of an algebra over Artinian ring `R` is either a zero divisor or a unit. -/ theorem isUnit_iff_nonZeroDivisor_of_isIntegral {a : A} (hi : IsIntegral R a) : IsUnit a ↔ a ∈ A⁰ := ⟨IsUnit.mem_nonZeroDivisors, isUnit_of_isIntegral_of_nonZeroDivisor hi⟩ /-- In an `R`-algebra over an Artinian ring `R`, if an element is integral and is not a zero divisor, then it is a unit. -/ theorem isUnit_of_nonZeroDivisor_of_isIntegral' [Algebra.IsIntegral R A] {a : A} (ha : a ∈ A⁰) : IsUnit a := isUnit_of_isIntegral_of_nonZeroDivisor (R := R) (Algebra.IsIntegral.isIntegral a) ha /-- Integral element of an algebra over Artinian ring `R` is either a zero divisor or a unit. -/ theorem isUnit_iff_nonZeroDivisor_of_isIntegral' [Algebra.IsIntegral R A] {a : A} : IsUnit a ↔ a ∈ A⁰ := isUnit_iff_nonZeroDivisor_of_isIntegral (R := R) (Algebra.IsIntegral.isIntegral a) theorem isUnit_submonoid_eq_of_isIntegral [Algebra.IsIntegral R A] : IsUnit.submonoid A = A⁰ := by ext; simpa [IsUnit.mem_submonoid_iff] using isUnit_iff_nonZeroDivisor_of_isIntegral' (R := R) end IsArtinianRing
.lake/packages/mathlib/Mathlib/RingTheory/TensorProduct/Finite.lean
import Mathlib.LinearAlgebra.Isomorphisms import Mathlib.RingTheory.Finiteness.Basic import Mathlib.RingTheory.Finiteness.Bilinear import Mathlib.RingTheory.Ideal.Quotient.Basic import Mathlib.RingTheory.TensorProduct.Maps /-! # Finiteness of the tensor product of (sub)modules In this file we show that the supremum of two subalgebras that are finitely generated as modules, is again finitely generated. -/ open Function (Surjective) open Finsupp namespace Submodule variable {R M N : Type*} [CommSemiring R] [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N] {I : Submodule R N} open TensorProduct LinearMap /-- Every `x : N ⊗ M` is the image of some `y : J ⊗ M`, where `J` is a finitely generated submodule of `N`, under the tensor product of the inclusion `J → N` and the identity `M → M`. -/ theorem exists_fg_le_eq_rTensor_subtype (x : N ⊗ M) : ∃ (J : Submodule R N) (_ : J.FG) (y : J ⊗ M), x = rTensor M J.subtype y := by induction x with | zero => exact ⟨⊥, fg_bot, 0, rfl⟩ | tmul i m => exact ⟨R ∙ i, fg_span_singleton i, ⟨i, mem_span_singleton_self _⟩ ⊗ₜ[R] m, rfl⟩ | add x₁ x₂ ihx₁ ihx₂ => obtain ⟨J₁, fg₁, y₁, rfl⟩ := ihx₁ obtain ⟨J₂, fg₂, y₂, rfl⟩ := ihx₂ refine ⟨J₁ ⊔ J₂, fg₁.sup fg₂, rTensor M (J₁.inclusion le_sup_left) y₁ + rTensor M (J₂.inclusion le_sup_right) y₂, ?_⟩ rw [map_add, ← rTensor_comp_apply, ← rTensor_comp_apply] rfl theorem exists_fg_le_subset_range_rTensor_subtype (s : Set (N ⊗[R] M)) (hs : s.Finite) : ∃ (J : Submodule R N) (_ : J.FG), s ⊆ LinearMap.range (rTensor M J.subtype) := by choose J fg y eq using exists_fg_le_eq_rTensor_subtype (R := R) (M := M) (N := N) rw [← Set.finite_coe_iff] at hs refine ⟨⨆ x : s, J x, fg_iSup _ fun _ ↦ fg _, fun x hx ↦ ⟨rTensor M (inclusion <| le_iSup _ ⟨x, hx⟩) (y x), .trans ?_ (eq x).symm⟩⟩ rw [← comp_apply, ← rTensor_comp]; rfl open TensorProduct LinearMap /-- Every `x : I ⊗ M` is the image of some `y : J ⊗ M`, where `J ≤ I` is finitely generated, under the tensor product of `J.inclusion ‹J ≤ I› : J → I` and the identity `M → M`. -/ theorem exists_fg_le_eq_rTensor_inclusion (x : I ⊗ M) : ∃ (J : Submodule R N) (_ : J.FG) (hle : J ≤ I) (y : J ⊗ M), x = rTensor M (J.inclusion hle) y := by obtain ⟨J, fg, y, rfl⟩ := exists_fg_le_eq_rTensor_subtype x refine ⟨J.map I.subtype, fg.map _, I.map_subtype_le J, rTensor M (I.subtype.submoduleMap J) y, ?_⟩ rw [← LinearMap.rTensor_comp_apply]; rfl theorem exists_fg_le_subset_range_rTensor_inclusion (s : Set (I ⊗[R] M)) (hs : s.Finite) : ∃ (J : Submodule R N) (_ : J.FG) (hle : J ≤ I), s ⊆ LinearMap.range (rTensor M (J.inclusion hle)) := by choose J fg hle y eq using exists_fg_le_eq_rTensor_inclusion (M := M) (I := I) rw [← Set.finite_coe_iff] at hs refine ⟨⨆ x : s, J x, fg_iSup _ fun _ ↦ fg _, iSup_le fun _ ↦ hle _, fun x hx ↦ ⟨rTensor M (inclusion <| le_iSup _ ⟨x, hx⟩) (y x), .trans ?_ (eq x).symm⟩⟩ rw [← comp_apply, ← rTensor_comp]; rfl end Submodule section ModuleAndAlgebra variable (R A B M N : Type*) instance Module.Finite.base_change [CommSemiring R] [Semiring A] [Algebra R A] [AddCommMonoid M] [Module R M] [h : Module.Finite R M] : Module.Finite A (TensorProduct R A M) := by classical obtain ⟨s, hs⟩ := h.fg_top refine ⟨⟨s.image (TensorProduct.mk R A M 1), eq_top_iff.mpr ?_⟩⟩ rintro x - induction x with | zero => exact zero_mem _ | tmul x y => rw [Finset.coe_image, ← Submodule.span_span_of_tower R, Submodule.span_image, hs, Submodule.map_top, LinearMap.coe_range, ← mul_one x, ← smul_eq_mul, ← TensorProduct.smul_tmul'] exact Submodule.smul_mem _ x (Submodule.subset_span <| Set.mem_range_self y) | add x y hx hy => exact Submodule.add_mem _ hx hy instance Module.Finite.tensorProduct [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] [hM : Module.Finite R M] [hN : Module.Finite R N] : Module.Finite R (TensorProduct R M N) where fg_top := (TensorProduct.map₂_mk_top_top_eq_top R M N).subst (hM.fg_top.map₂ _ hN.fg_top) end ModuleAndAlgebra section NontrivialTensorProduct variable (R M : Type*) [CommRing R] [AddCommGroup M] [Module R M] [Module.Finite R M] [Nontrivial M] lemma Module.exists_isPrincipal_quotient_of_finite : ∃ N : Submodule R M, N ≠ ⊤ ∧ Submodule.IsPrincipal (⊤ : Submodule R (M ⧸ N)) := by obtain ⟨n, f, hf⟩ := @Module.Finite.exists_fin R M _ _ _ _ let s := { m : ℕ | Submodule.span R (f '' (Fin.val ⁻¹' (Set.Iio m))) ≠ ⊤ } have hns : ∀ x ∈ s, x < n := by refine fun x hx ↦ lt_iff_not_ge.mpr fun e ↦ ?_ have : (Fin.val ⁻¹' Set.Iio x : Set (Fin n)) = Set.univ := by ext y; simpa using y.2.trans_le e simp [s, this, hf] at hx have hs₁ : s.Nonempty := ⟨0, by simp [s]⟩ have hs₂ : BddAbove s := ⟨n, fun x hx ↦ (hns x hx).le⟩ have hs := Nat.sSup_mem hs₁ hs₂ refine ⟨_, hs, ⟨⟨Submodule.mkQ _ (f ⟨_, hns _ hs⟩), ?_⟩⟩⟩ have := not_not.mp (notMem_of_csSup_lt (Order.lt_succ _) hs₂) rw [← Set.image_singleton, ← Submodule.map_span, ← (Submodule.comap_injective_of_surjective (Submodule.mkQ_surjective _)).eq_iff, Submodule.comap_map_eq, Submodule.ker_mkQ, Submodule.comap_top, ← this, ← Submodule.span_union, Order.Iio_succ_eq_insert (sSup s), ← Set.union_singleton, Set.preimage_union, Set.image_union, ← @Set.image_singleton _ _ f, Set.union_comm] congr! ext simp [Fin.ext_iff] lemma Module.exists_surjective_quotient_of_finite : ∃ (I : Ideal R) (f : M →ₗ[R] R ⧸ I), I ≠ ⊤ ∧ Function.Surjective f := by obtain ⟨N, hN, ⟨x, hx⟩⟩ := Module.exists_isPrincipal_quotient_of_finite R M let f := (LinearMap.toSpanSingleton R _ x).quotKerEquivOfSurjective (by rw [← LinearMap.range_eq_top, ← LinearMap.span_singleton_eq_range, hx]) refine ⟨_, f.symm.toLinearMap.comp N.mkQ, fun e ↦ ?_, f.symm.surjective.comp N.mkQ_surjective⟩ obtain rfl : x = 0 := by simpa using LinearMap.congr_fun (LinearMap.ker_eq_top.mp e) 1 rw [ne_eq, ← Submodule.subsingleton_quotient_iff_eq_top, ← not_nontrivial_iff_subsingleton, not_not] at hN simp at hx open TensorProduct instance : Nontrivial (M ⊗[R] M) := by obtain ⟨I, ϕ, hI, hϕ⟩ := Module.exists_surjective_quotient_of_finite R M let ψ : M ⊗[R] M →ₗ[R] R ⧸ I := (LinearMap.mul' R (R ⧸ I)).comp (TensorProduct.map ϕ ϕ) have : Nontrivial (R ⧸ I) := by rwa [← not_subsingleton_iff_nontrivial, Submodule.subsingleton_quotient_iff_eq_top] have : Function.Surjective ψ := by intro x; obtain ⟨x, rfl⟩ := hϕ x; obtain ⟨y, hy⟩ := hϕ 1; exact ⟨x ⊗ₜ y, by simp [ψ, hy]⟩ exact this.nontrivial end NontrivialTensorProduct theorem Subalgebra.finite_sup {K L : Type*} [CommSemiring K] [CommSemiring L] [Algebra K L] (E1 E2 : Subalgebra K L) [Module.Finite K E1] [Module.Finite K E2] : Module.Finite K ↥(E1 ⊔ E2) := by rw [← E1.range_val, ← E2.range_val, ← Algebra.TensorProduct.productMap_range] exact Module.Finite.range (Algebra.TensorProduct.productMap E1.val E2.val).toLinearMap open TensorProduct in lemma RingHom.surjective_of_tmul_eq_tmul_of_finite {R S} [CommRing R] [Ring S] [Algebra R S] [Module.Finite R S] (h₁ : ∀ s : S, s ⊗ₜ[R] 1 = 1 ⊗ₜ s) : Function.Surjective (algebraMap R S) := by let R' := LinearMap.range (Algebra.ofId R S).toLinearMap rcases subsingleton_or_nontrivial (S ⧸ R') with h | _ · rwa [Submodule.subsingleton_quotient_iff_eq_top, LinearMap.range_eq_top] at h have : Subsingleton ((S ⧸ R') ⊗[R] (S ⧸ R')) := by refine subsingleton_of_forall_eq 0 fun y ↦ ?_ induction y with | zero => rfl | add a b e₁ e₂ => rwa [e₁, zero_add] | tmul x y => obtain ⟨x, rfl⟩ := R'.mkQ_surjective x obtain ⟨y, rfl⟩ := R'.mkQ_surjective y obtain ⟨s, hs⟩ : ∃ s, 1 ⊗ₜ[R] s = x ⊗ₜ[R] y := by use x * y trans x ⊗ₜ 1 * 1 ⊗ₜ y · simp [h₁] · simp have : R'.mkQ 1 = 0 := (Submodule.Quotient.mk_eq_zero R').mpr ⟨1, map_one (algebraMap R S)⟩ rw [← map_tmul R'.mkQ R'.mkQ, ← hs, map_tmul, this, zero_tmul] cases false_of_nontrivial_of_subsingleton ((S ⧸ R') ⊗[R] (S ⧸ R'))
.lake/packages/mathlib/Mathlib/RingTheory/TensorProduct/DirectLimitFG.lean
import Mathlib.LinearAlgebra.TensorProduct.DirectLimit import Mathlib.LinearAlgebra.TensorProduct.Tower import Mathlib.RingTheory.Adjoin.FG /-! # Tensor products and finitely generated submodules Various results about how tensor products of arbitrary modules are direct limits of tensor products of finitely-generated modules. ## Main definitions * `Submodule.FG.directedSystem`, the directed system of finitely generated submodules of a module. * `Submodule.FG.directLimit` proves that a module is the direct limit of its finitely generated submodules, with respect to the inclusion maps * `DirectedSystem.rTensor`, the directed system deduced from a directed system of modules by applying `rTensor`. * `Submodule.FG.rTensor.directSystem`, the directed system of modules `P ⊗[R] N`, for all finitely generated submodules `P`, with respect to the maps deduced from the inclusions * `Submodule.FG.rTensor.directLimit` : a tensor product `M ⊗[R] N` is the direct limit of the modules `P ⊗[R] N`, where `P` ranges over all finitely generated submodules of `M`, as a linear equivalence. * `DirectedSystem.lTensor`, the directed system deduced from a directed system of modules by applying `lTensor`. * `Submodule.FG.lTensor.directSystem`, the directed system of modules `M ⊗[R] Q`, for all finitely generated submodules `Q`, with respect to the maps deduced from the inclusions * `Submodule.FG.lTensor.directLimit` : a tensor product `M ⊗[R] N` is the direct limit of the modules `M ⊗[R] Q`, where `Q` ranges over all finitely generated submodules of `N`, as a linear equivalence. -/ open Submodule LinearMap section Semiring universe u v variable {R : Type u} [Semiring R] {M : Type*} [AddCommMonoid M] [Module R M] /-- The directed system of finitely generated submodules of `M` -/ instance Submodule.FG.directedSystem : DirectedSystem (ι := {P : Submodule R M // P.FG}) (F := fun P ↦ P.val) (f := fun ⦃P Q⦄ (h : P ≤ Q) ↦ Submodule.inclusion h) where map_self := fun _ _ ↦ rfl map_map := fun _ _ _ _ _ _ ↦ rfl variable (R M) in /-- Any module is the direct limit of its finitely generated submodules -/ noncomputable def Submodule.FG.directLimit [DecidableEq {P : Submodule R M // P.FG}] : Module.DirectLimit (ι := {P : Submodule R M // P.FG}) (G := fun P ↦ P.val) (fun ⦃P Q⦄ (h : P ≤ Q) ↦ Submodule.inclusion h) ≃ₗ[R] M := LinearEquiv.ofBijective (Module.DirectLimit.lift _ _ _ _ (fun P ↦ P.val.subtype) (fun _ _ _ _ ↦ rfl)) ⟨Module.DirectLimit.lift_injective _ _ (fun P ↦ Submodule.injective_subtype P.val), fun x ↦ ⟨Module.DirectLimit.of _ {P : Submodule R M // P.FG} _ _ ⟨Submodule.span R {x}, Submodule.fg_span_singleton x⟩ ⟨x, Submodule.mem_span_singleton_self x⟩, by simp⟩⟩ end Semiring section TensorProducts open TensorProduct universe u v variable (R : Type u) (M N : Type*) [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] /-- Given a directed system of `R`-modules, tensoring it on the right gives a directed system -/ theorem DirectedSystem.rTensor {ι : Type*} [Preorder ι] {F : ι → Type*} [∀ i, AddCommMonoid (F i)] [∀ i, Module R (F i)] {f : ⦃i j : ι⦄ → i ≤ j → F i →ₗ[R] F j} (D : DirectedSystem F (fun _ _ h ↦ f h)) : DirectedSystem (fun i ↦ (F i) ⊗[R] N) (fun _ _ h ↦ rTensor N (f h)) where map_self i t := by rw [← id_apply (R := R) t] apply DFunLike.congr_fun ext m n simp [D.map_self] map_map {i j k} h h' t := by rw [← comp_apply, ← rTensor_comp] apply DFunLike.congr_fun ext p n simp [D.map_map] /-- When `P` ranges over finitely generated submodules of `M`, the modules of the form `P ⊗[R] N` form a directed system. -/ theorem Submodule.FG.rTensor.directedSystem : DirectedSystem (ι := {P : Submodule R M // P.FG}) (fun P ↦ P.val ⊗[R] N) (fun ⦃_ _⦄ h ↦ rTensor N (Submodule.inclusion h)) := Submodule.FG.directedSystem.rTensor R N /-- A tensor product `M ⊗[R] N` is the direct limit of the modules `P ⊗[R] N`, where `P` ranges over all finitely generated submodules of `M`, as a linear equivalence. -/ noncomputable def Submodule.FG.rTensor.directLimit [DecidableEq {P : Submodule R M // P.FG}] : Module.DirectLimit (R := R) (ι := {P : Submodule R M // P.FG}) (fun P ↦ P.val ⊗[R] N) (fun ⦃P Q⦄ (h : P ≤ Q) ↦ (Submodule.inclusion h).rTensor N) ≃ₗ[R] M ⊗[R] N := (TensorProduct.directLimitLeft _ N).symm.trans ((Submodule.FG.directLimit R M).rTensor N) theorem Submodule.FG.rTensor.directLimit_apply [DecidableEq {P : Submodule R M // P.FG}] {P : {P : Submodule R M // P.FG}} (u : P ⊗[R] N) : (Submodule.FG.rTensor.directLimit R M N) ((Module.DirectLimit.of R {P : Submodule R M // P.FG} (fun P ↦ P.val ⊗[R] N) (fun ⦃_ _⦄ h ↦ (Submodule.inclusion h).rTensor N) P) u) = (rTensor N (Submodule.subtype P)) u := by suffices (Submodule.FG.rTensor.directLimit R M N).toLinearMap.comp (Module.DirectLimit.of R {P : Submodule R M // P.FG} (fun P ↦ P.val ⊗[R] N) (fun _ _ hPQ ↦ rTensor N (Submodule.inclusion hPQ)) P) = rTensor N (Submodule.subtype P.val) by exact DFunLike.congr_fun this u ext p n simp [Submodule.FG.rTensor.directLimit, Submodule.FG.directLimit] /-- An alternative version to `Submodule.FG.rTensor.directLimit_apply`. -/ theorem Submodule.FG.rTensor.directLimit_apply' [DecidableEq {P : Submodule R M // P.FG}] {P : Submodule R M} (hP : Submodule.FG P) (u : P ⊗[R] N) : (Submodule.FG.rTensor.directLimit R M N) ((Module.DirectLimit.of R {P : Submodule R M // P.FG} (fun P ↦ P.val ⊗[R] N) (fun ⦃_ _⦄ h ↦ rTensor N (Submodule.inclusion h)) ⟨P, hP⟩) u) = (rTensor N (Submodule.subtype P)) u := by apply Submodule.FG.rTensor.directLimit_apply /-- Given a directed system of `R`-modules, tensoring it on the left gives a directed system -/ theorem DirectedSystem.lTensor {ι : Type*} [Preorder ι] {F : ι → Type*} [∀ i, AddCommMonoid (F i)] [∀ i, Module R (F i)] {f : ⦃i j : ι⦄ → i ≤ j → F i →ₗ[R] F j} (D : DirectedSystem F (fun _ _ h ↦ f h)) : DirectedSystem (fun i ↦ M ⊗[R] (F i)) (fun _ _ h ↦ lTensor M (f h)) where map_self i t := by rw [← id_apply (R := R) t] apply DFunLike.congr_fun ext m n simp [D.map_self] map_map {i j k} h h' t := by rw [← comp_apply, ← lTensor_comp] apply DFunLike.congr_fun ext p n simp [D.map_map] /-- When `Q` ranges over finitely generated submodules of `N`, the modules of the form `M ⊗[R] Q` form a directed system. -/ theorem Submodule.FG.lTensor.directedSystem : DirectedSystem (ι := {Q : Submodule R N // Q.FG}) (fun Q ↦ M ⊗[R] Q.val) (fun _ _ hPQ ↦ lTensor M (Submodule.inclusion hPQ)) := Submodule.FG.directedSystem.lTensor R M /-- A tensor product `M ⊗[R] N` is the direct limit of the modules `M ⊗[R] Q`, where `Q` ranges over all finitely generated submodules of `N`, as a linear equivalence. -/ noncomputable def Submodule.FG.lTensor.directLimit [DecidableEq {Q : Submodule R N // Q.FG}] : Module.DirectLimit (R := R) (ι := {Q : Submodule R N // Q.FG}) (fun Q ↦ M ⊗[R] Q.val) (fun _ _ hPQ ↦ (inclusion hPQ).lTensor M) ≃ₗ[R] M ⊗[R] N := (TensorProduct.directLimitRight _ M).symm.trans ((Submodule.FG.directLimit R N).lTensor M) theorem Submodule.FG.lTensor.directLimit_apply [DecidableEq {P : Submodule R N // P.FG}] (Q : {Q : Submodule R N // Q.FG}) (u : M ⊗[R] Q.val) : (Submodule.FG.lTensor.directLimit R M N) ((Module.DirectLimit.of R {Q : Submodule R N // Q.FG} (fun Q ↦ M ⊗[R] Q.val) (fun _ _ hPQ ↦ (inclusion hPQ).lTensor M) Q) u) = (lTensor M (Submodule.subtype Q.val)) u := by suffices (Submodule.FG.lTensor.directLimit R M N).toLinearMap.comp (Module.DirectLimit.of R {Q : Submodule R N // Q.FG} (fun Q ↦ M ⊗[R] Q.val) (fun _ _ hPQ ↦ lTensor M (inclusion hPQ)) Q) = lTensor M (Submodule.subtype Q.val) by exact DFunLike.congr_fun this u ext p n simp [Submodule.FG.lTensor.directLimit, Submodule.FG.directLimit] theorem Submodule.FG.lTensor.directLimit_apply' [DecidableEq {Q : Submodule R N // Q.FG}] (Q : Submodule R N) (hQ : Q.FG) (u : M ⊗[R] Q) : (Submodule.FG.lTensor.directLimit R M N) ((Module.DirectLimit.of R {Q : Submodule R N // Q.FG} (fun Q ↦ M ⊗[R] Q.val) (fun _ _ hPQ ↦ lTensor M (inclusion hPQ)) ⟨Q, hQ⟩) u) = (lTensor M (Submodule.subtype Q)) u := Submodule.FG.lTensor.directLimit_apply R M N ⟨Q, hQ⟩ u variable {R M N} (u : M ⊗[R] N) {P : Submodule R M} (hP : Submodule.FG P) {t : P ⊗[R] N} {P' : Submodule R M} (hP' : Submodule.FG P') {t' : P' ⊗[R] N} theorem TensorProduct.exists_of_fg : ∃ (P : Submodule R M), P.FG ∧ u ∈ range (rTensor N P.subtype) := by classical let ⟨P, t, ht⟩ := Module.DirectLimit.exists_of ((Submodule.FG.rTensor.directLimit R M N).symm u) use P.val, P.property, t rw [← Submodule.FG.rTensor.directLimit_apply, ht, LinearEquiv.apply_symm_apply] include hP in theorem TensorProduct.eq_of_fg_of_subtype_eq {t' : P ⊗[R] N} (h : rTensor N P.subtype t = rTensor N P.subtype t') : ∃ (Q : Submodule R M) (hPQ : P ≤ Q), Q.FG ∧ rTensor N (inclusion hPQ) t = rTensor N (inclusion hPQ) t' := by classical simp only [← Submodule.FG.rTensor.directLimit_apply' R M N hP, EmbeddingLike.apply_eq_iff_eq] at h obtain ⟨Q, hPQ, h⟩ := Module.DirectLimit.exists_eq_of_of_eq h use Q.val, Subtype.coe_le_coe.mpr hPQ, Q.property include hP in theorem TensorProduct.eq_zero_of_fg_of_subtype_eq_zero (h : rTensor N P.subtype t = 0) : ∃ (Q : Submodule R M) (hPQ : P ≤ Q), Q.FG ∧ rTensor N (inclusion hPQ) t = 0 := by rw [← (rTensor N P.subtype).map_zero] at h simpa only [map_zero] using TensorProduct.eq_of_fg_of_subtype_eq hP h include hP hP' in theorem TensorProduct.eq_of_fg_of_subtype_eq' (h : rTensor N P.subtype t = rTensor N P'.subtype t') : ∃ (Q : Submodule R M) (hPQ : P ≤ Q) (hP'Q : P' ≤ Q), Q.FG ∧ rTensor N (inclusion hPQ) t = rTensor N (inclusion hP'Q) t' := by simp only [← subtype_comp_inclusion _ _ (le_sup_left : _ ≤ P ⊔ P'), ← subtype_comp_inclusion _ _ (le_sup_right : _ ≤ P ⊔ P'), rTensor_comp, coe_comp, Function.comp_apply] at h let ⟨Q, hQ_le, hQ, h⟩ := TensorProduct.eq_of_fg_of_subtype_eq (hP.sup hP') h use Q, le_trans le_sup_left hQ_le, le_trans le_sup_right hQ_le, hQ simpa [← comp_apply, ← rTensor_comp] using h end TensorProducts section Algebra open TensorProduct variable {R S M N : Type*} [CommSemiring R] [Semiring S] [Algebra R S] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] (u : S ⊗[R] N) {A : Subalgebra R S} (hA : A.FG) {t t' : A ⊗[R] N} {A' : Subalgebra R S} (hA' : A'.FG) theorem TensorProduct.Algebra.exists_of_fg : ∃ (A : Subalgebra R S), Subalgebra.FG A ∧ u ∈ range (rTensor N A.val.toLinearMap) := by obtain ⟨P, ⟨s, hs⟩, hu⟩ := TensorProduct.exists_of_fg u use Algebra.adjoin R s, Subalgebra.fg_adjoin_finset _ have : P ≤ (Algebra.adjoin R (s : Set S)).toSubmodule := by simp only [← hs, span_le, Subalgebra.coe_toSubmodule] exact Algebra.subset_adjoin rw [← subtype_comp_inclusion P _ this, rTensor_comp] at hu exact range_comp_le_range _ _ hu include hA in theorem TensorProduct.Algebra.eq_of_fg_of_subtype_eq (h : rTensor N A.val.toLinearMap t = rTensor N A.val.toLinearMap t') : ∃ (B : Subalgebra R S) (hAB : A ≤ B), Subalgebra.FG B ∧ rTensor N (Subalgebra.inclusion hAB).toLinearMap t = LinearMap.rTensor N (Subalgebra.inclusion hAB).toLinearMap t' := by classical let ⟨P, hP, u, hu⟩ := TensorProduct.exists_of_fg t let ⟨P', hP', u', hu'⟩ := TensorProduct.exists_of_fg t' let P₁ := Submodule.map A.toSubmodule.subtype (P ⊔ P') have hP₁ : Submodule.FG P₁ := Submodule.FG.map _ (Submodule.FG.sup hP hP') -- the embeddings from P and P' to P₁ let j : P →ₗ[R] P₁ := (Subalgebra.toSubmodule A).subtype.restrict (fun p hp ↦ by simp only [coe_subtype, Submodule.map_sup, P₁] exact Submodule.mem_sup_left ⟨p, hp, rfl⟩) let j' : P' →ₗ[R] P₁ := (Subalgebra.toSubmodule A).subtype.restrict (fun p hp ↦ by simp only [coe_subtype, Submodule.map_sup, P₁] exact Submodule.mem_sup_right ⟨p, hp, rfl⟩) -- we map u and u' to P₁ ⊗[R] N, getting u₁ and u'₁ set u₁ := rTensor N j u with hu₁ set u'₁ := rTensor N j' u' with hu'₁ -- u₁ and u'₁ are equal in S ⊗[R] N have : rTensor N P₁.subtype u₁ = rTensor N P₁.subtype u'₁ := by rw [hu₁, hu'₁] simp only [← comp_apply, ← rTensor_comp] have hj₁ : P₁.subtype ∘ₗ j = A.val.toLinearMap ∘ₗ P.subtype := rfl have hj'₁ : P₁.subtype ∘ₗ j' = A.val.toLinearMap ∘ₗ P'.subtype := rfl rw [hj₁, hj'₁] simp only [rTensor_comp, comp_apply] rw [hu, hu', h] let ⟨P'₁, hP₁_le, hP'₁, h⟩ := TensorProduct.eq_of_fg_of_subtype_eq hP₁ this let ⟨s, hs⟩ := hP'₁ let ⟨w, hw⟩ := hA let B := Algebra.adjoin R ((s ∪ w : Finset S) : Set S) have hBA : A ≤ B := by simp only [B, ← hw] apply Algebra.adjoin_mono simp only [Finset.coe_union, Set.subset_union_right] use B, hBA, Subalgebra.fg_adjoin_finset _ rw [← hu, ← hu'] simp only [← comp_apply, ← rTensor_comp] have hP'₁_le : P'₁ ≤ B.toSubmodule := by simp only [← hs, Finset.coe_union, Submodule.span_le, Subalgebra.coe_toSubmodule, B] exact subset_trans Set.subset_union_left Algebra.subset_adjoin have k : (Subalgebra.inclusion hBA).toLinearMap ∘ₗ P.subtype = inclusion hP'₁_le ∘ₗ inclusion hP₁_le ∘ₗ j := by ext; rfl have k' : (Subalgebra.inclusion hBA).toLinearMap ∘ₗ P'.subtype = inclusion hP'₁_le ∘ₗ inclusion hP₁_le ∘ₗ j' := by ext; rfl rw [k, k'] simp only [rTensor_comp, comp_apply] rw [← hu₁, ← hu'₁, h] include hA hA' in theorem TensorProduct.Algebra.eq_of_fg_of_subtype_eq' {t' : A' ⊗[R] N} (h : rTensor N A.val.toLinearMap t = rTensor N A'.val.toLinearMap t') : ∃ (B : Subalgebra R S) (hAB : A ≤ B) (hA'B : A' ≤ B), Subalgebra.FG B ∧ rTensor N (Subalgebra.inclusion hAB).toLinearMap t = rTensor N (Subalgebra.inclusion hA'B).toLinearMap t' := by have hj : (A ⊔ A').val.comp (Subalgebra.inclusion le_sup_left) = A.val := by ext; rfl have hj' : (A ⊔ A').val.comp (Subalgebra.inclusion le_sup_right) = A'.val := by ext; rfl simp only [← hj, ← hj', AlgHom.comp_toLinearMap, rTensor_comp, comp_apply] at h let ⟨B, hB_le, hB, h⟩ := TensorProduct.Algebra.eq_of_fg_of_subtype_eq (Subalgebra.FG.sup hA hA') h use B, le_trans le_sup_left hB_le, le_trans le_sup_right hB_le, hB simpa only [← rTensor_comp, ← comp_apply] using h /-- Lift an element that maps to 0 -/ theorem Submodule.exists_fg_of_baseChange_eq_zero (f : M →ₗ[R] N) {t : S ⊗[R] M} (ht : f.baseChange S t = 0) : ∃ (A : Subalgebra R S) (_ : A.FG) (u : A ⊗[R] M), f.baseChange A u = 0 ∧ A.val.toLinearMap.rTensor M u = t := by classical obtain ⟨A, hA, ht_memA⟩ := TensorProduct.Algebra.exists_of_fg t obtain ⟨u, hu⟩ := _root_.id ht_memA have := TensorProduct.Algebra.eq_of_fg_of_subtype_eq hA (t := f.baseChange _ u) (t' := 0) simp only [map_zero, exists_and_left] at this have hu' : (A.val.toLinearMap.rTensor N) (f.baseChange (↥A) u) = 0 := by rw [← ht, ← hu, rTensor_baseChange] obtain ⟨B, hB, hAB, hu'⟩ := this hu' use B, hB, rTensor M (Subalgebra.inclusion hAB).toLinearMap u constructor · rw [← rTensor_baseChange, hu'] · rw [← comp_apply, ← rTensor_comp, ← hu] congr end Algebra
.lake/packages/mathlib/Mathlib/RingTheory/TensorProduct/Maps.lean
import Mathlib.Algebra.Algebra.RestrictScalars import Mathlib.Algebra.Algebra.Subalgebra.Lattice import Mathlib.Algebra.Module.Rat import Mathlib.RingTheory.TensorProduct.Basic /-! # Maps between tensor products of R-algebras This file provides results about maps between tensor products of `R`-algebras. ## Main declarations - the structure isomorphisms * `Algebra.TensorProduct.lid : R ⊗[R] A ≃ₐ[R] A` * `Algebra.TensorProduct.rid : A ⊗[R] R ≃ₐ[S] A` (usually used with `S = R` or `S = A`) * `Algebra.TensorProduct.comm : A ⊗[R] B ≃ₐ[R] B ⊗[R] A` * `Algebra.TensorProduct.assoc : ((A ⊗[R] B) ⊗[R] C) ≃ₐ[R] (A ⊗[R] (B ⊗[R] C))` - `Algebra.TensorProduct.liftEquiv`: a universal property for the tensor product of algebras. ## References * [C. Kassel, *Quantum Groups* (§II.4)][Kassel1995] -/ assert_not_exists Equiv.Perm.cycleType open scoped TensorProduct open TensorProduct namespace Module.End open LinearMap variable (R M N : Type*) [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] /-- The map `LinearMap.lTensorHom` which sends `f ↦ 1 ⊗ f` as a morphism of algebras. -/ @[simps!] def lTensorAlgHom : Module.End R M →ₐ[R] Module.End R (N ⊗[R] M) := .ofLinearMap (lTensorHom (M := N)) (lTensor_id N M) (lTensor_mul N) /-- The map `LinearMap.rTensorHom` which sends `f ↦ f ⊗ 1` as a morphism of algebras. -/ @[simps!] def rTensorAlgHom : Module.End R M →ₐ[R] Module.End R (M ⊗[R] N) := .ofLinearMap (rTensorHom (M := N)) (rTensor_id N M) (rTensor_mul N) end Module.End namespace Algebra namespace TensorProduct universe uR uS uA uB uC uD uE uF variable {R : Type uR} {R' : Type*} {S : Type uS} {T : Type*} variable {A : Type uA} {B : Type uB} {C : Type uC} {D : Type uD} {E : Type uE} {F : Type uF} /-! We build the structure maps for the symmetric monoidal category of `R`-algebras. -/ section Monoidal section variable [CommSemiring R] [CommSemiring S] [Algebra R S] variable [Semiring A] [Algebra R A] [Algebra S A] [IsScalarTower R S A] variable [Semiring B] [Algebra R B] variable [Semiring C] [Algebra S C] variable [Semiring D] [Algebra R D] /-- To check a linear map preserves multiplication, it suffices to check it on pure tensors. See `algHomOfLinearMapTensorProduct` for a bundled version. -/ lemma _root_.LinearMap.map_mul_of_map_mul_tmul {f : A ⊗[R] B →ₗ[S] C} (hf : ∀ (a₁ a₂ : A) (b₁ b₂ : B), f ((a₁ * a₂) ⊗ₜ (b₁ * b₂)) = f (a₁ ⊗ₜ b₁) * f (a₂ ⊗ₜ b₂)) (x y : A ⊗[R] B) : f (x * y) = f x * f y := f.map_mul_iff.2 (by -- these instances are needed by the statement of `ext`, but not by the current definition. letI : Algebra R C := RestrictScalars.algebra R S C letI : IsScalarTower R S C := RestrictScalars.isScalarTower R S C ext dsimp exact hf _ _ _ _) x y /-- Build an algebra morphism from a linear map out of a tensor product, and evidence that on pure tensors, it preserves multiplication and the identity. Note that we state `h_one` using `1 ⊗ₜ[R] 1` instead of `1` so that lemmas about `f` applied to pure tensors can be directly applied by the caller (without needing `TensorProduct.one_def`). -/ def algHomOfLinearMapTensorProduct (f : A ⊗[R] B →ₗ[S] C) (h_mul : ∀ (a₁ a₂ : A) (b₁ b₂ : B), f ((a₁ * a₂) ⊗ₜ (b₁ * b₂)) = f (a₁ ⊗ₜ b₁) * f (a₂ ⊗ₜ b₂)) (h_one : f (1 ⊗ₜ[R] 1) = 1) : A ⊗[R] B →ₐ[S] C := AlgHom.ofLinearMap f h_one (f.map_mul_of_map_mul_tmul h_mul) @[simp] theorem algHomOfLinearMapTensorProduct_apply (f h_mul h_one x) : (algHomOfLinearMapTensorProduct f h_mul h_one : A ⊗[R] B →ₐ[S] C) x = f x := rfl /-- Build an algebra equivalence from a linear equivalence out of a tensor product, and evidence that on pure tensors, it preserves multiplication and the identity. Note that we state `h_one` using `1 ⊗ₜ[R] 1` instead of `1` so that lemmas about `f` applied to pure tensors can be directly applied by the caller (without needing `TensorProduct.one_def`). -/ def algEquivOfLinearEquivTensorProduct (f : A ⊗[R] B ≃ₗ[S] C) (h_mul : ∀ (a₁ a₂ : A) (b₁ b₂ : B), f ((a₁ * a₂) ⊗ₜ (b₁ * b₂)) = f (a₁ ⊗ₜ b₁) * f (a₂ ⊗ₜ b₂)) (h_one : f (1 ⊗ₜ[R] 1) = 1) : A ⊗[R] B ≃ₐ[S] C := { algHomOfLinearMapTensorProduct (f : A ⊗[R] B →ₗ[S] C) h_mul h_one, f with } @[simp] theorem algEquivOfLinearEquivTensorProduct_apply (f h_mul h_one x) : (algEquivOfLinearEquivTensorProduct f h_mul h_one : A ⊗[R] B ≃ₐ[S] C) x = f x := rfl variable [Algebra R C] /-- Build an algebra equivalence from a linear equivalence out of a triple tensor product, and evidence of multiplicativity on pure tensors. -/ def algEquivOfLinearEquivTripleTensorProduct (f : A ⊗[R] B ⊗[R] C ≃ₗ[R] D) (h_mul : ∀ (a₁ a₂ : A) (b₁ b₂ : B) (c₁ c₂ : C), f ((a₁ * a₂) ⊗ₜ (b₁ * b₂) ⊗ₜ (c₁ * c₂)) = f (a₁ ⊗ₜ b₁ ⊗ₜ c₁) * f (a₂ ⊗ₜ b₂ ⊗ₜ c₂)) (h_one : f (((1 : A) ⊗ₜ[R] (1 : B)) ⊗ₜ[R] (1 : C)) = 1) : A ⊗[R] B ⊗[R] C ≃ₐ[R] D := AlgEquiv.ofLinearEquiv f h_one <| f.map_mul_iff.2 <| by ext dsimp exact h_mul _ _ _ _ _ _ @[simp] theorem algEquivOfLinearEquivTripleTensorProduct_apply (f h_mul h_one x) : (algEquivOfLinearEquivTripleTensorProduct f h_mul h_one : A ⊗[R] B ⊗[R] C ≃ₐ[R] D) x = f x := rfl section lift variable [IsScalarTower R S C] /-- The forward direction of the universal property of tensor products of algebras; any algebra morphism from the tensor product can be factored as the product of two algebra morphisms that commute. See `Algebra.TensorProduct.liftEquiv` for the fact that every morphism factors this way. -/ def lift (f : A →ₐ[S] C) (g : B →ₐ[R] C) (hfg : ∀ x y, Commute (f x) (g y)) : (A ⊗[R] B) →ₐ[S] C := algHomOfLinearMapTensorProduct (AlgebraTensorModule.lift <| letI restr : (C →ₗ[S] C) →ₗ[S] _ := { toFun := (·.restrictScalars R) map_add' := fun _ _ => LinearMap.ext fun _ => rfl map_smul' := fun _ _ => LinearMap.ext fun _ => rfl } LinearMap.flip <| (restr ∘ₗ LinearMap.mul S C ∘ₗ f.toLinearMap).flip ∘ₗ g) (fun a₁ a₂ b₁ b₂ => show f (a₁ * a₂) * g (b₁ * b₂) = f a₁ * g b₁ * (f a₂ * g b₂) by rw [map_mul, map_mul, (hfg a₂ b₁).mul_mul_mul_comm]) (show f 1 * g 1 = 1 by rw [map_one, map_one, one_mul]) @[simp] theorem lift_tmul (f : A →ₐ[S] C) (g : B →ₐ[R] C) (hfg : ∀ x y, Commute (f x) (g y)) (a : A) (b : B) : lift f g hfg (a ⊗ₜ b) = f a * g b := rfl @[simp] theorem lift_includeLeft_includeRight : lift includeLeft includeRight (fun _ _ => (Commute.one_right _).tmul (Commute.one_left _)) = .id S (A ⊗[R] B) := by ext <;> simp @[simp] theorem lift_comp_includeLeft (f : A →ₐ[S] C) (g : B →ₐ[R] C) (hfg : ∀ x y, Commute (f x) (g y)) : (lift f g hfg).comp includeLeft = f := AlgHom.ext <| by simp @[simp] theorem lift_comp_includeRight (f : A →ₐ[S] C) (g : B →ₐ[R] C) (hfg : ∀ x y, Commute (f x) (g y)) : ((lift f g hfg).restrictScalars R).comp includeRight = g := AlgHom.ext <| by simp /-- The universal property of the tensor product of algebras. Pairs of algebra morphisms that commute are equivalent to algebra morphisms from the tensor product. This is `Algebra.TensorProduct.lift` as an equivalence. See also `GradedTensorProduct.liftEquiv` for an alternative commutativity requirement for graded algebra. -/ @[simps] def liftEquiv : {fg : (A →ₐ[S] C) × (B →ₐ[R] C) // ∀ x y, Commute (fg.1 x) (fg.2 y)} ≃ ((A ⊗[R] B) →ₐ[S] C) where toFun fg := lift fg.val.1 fg.val.2 fg.prop invFun f' := ⟨(f'.comp includeLeft, (f'.restrictScalars R).comp includeRight), fun _ _ => ((Commute.one_right _).tmul (Commute.one_left _)).map f'⟩ left_inv fg := by ext <;> simp right_inv f' := by ext <;> simp end lift end variable [CommSemiring R] [CommSemiring S] [Algebra R S] variable [Semiring A] [Algebra R A] [Algebra S A] [IsScalarTower R S A] variable [Semiring B] [Algebra R B] variable [Semiring C] [Algebra R C] [Algebra S C] [IsScalarTower R S C] variable [Semiring D] [Algebra R D] variable [Semiring E] [Algebra R E] [Algebra S E] [IsScalarTower R S E] variable [Semiring F] [Algebra R F] section variable (R A) /-- The base ring is a left identity for the tensor product of algebra, up to algebra isomorphism. -/ protected nonrec def lid : R ⊗[R] A ≃ₐ[R] A := algEquivOfLinearEquivTensorProduct (TensorProduct.lid R A) (by simp only [mul_smul, lid_tmul, Algebra.smul_mul_assoc, Algebra.mul_smul_comm] simp_rw [← mul_smul, mul_comm] simp) (by simp [Algebra.smul_def]) @[simp] theorem lid_toLinearEquiv : (TensorProduct.lid R A).toLinearEquiv = _root_.TensorProduct.lid R A := rfl variable {R} {A} in @[simp] theorem lid_tmul (r : R) (a : A) : TensorProduct.lid R A (r ⊗ₜ a) = r • a := rfl variable {A} in @[simp] theorem lid_symm_apply (a : A) : (TensorProduct.lid R A).symm a = 1 ⊗ₜ a := rfl variable (S) /-- The base ring is a right identity for the tensor product of algebra, up to algebra isomorphism. Note that if `A` is commutative this can be instantiated with `S = A`. -/ protected nonrec def rid : A ⊗[R] R ≃ₐ[S] A := algEquivOfLinearEquivTensorProduct (AlgebraTensorModule.rid R S A) (fun a₁ a₂ r₁ r₂ => smul_mul_smul_comm r₁ a₁ r₂ a₂ |>.symm) (one_smul R _) @[simp] theorem rid_toLinearEquiv : (TensorProduct.rid R S A).toLinearEquiv = AlgebraTensorModule.rid R S A := rfl variable {R A} in @[simp] theorem rid_tmul (r : R) (a : A) : TensorProduct.rid R S A (a ⊗ₜ r) = r • a := rfl variable {A} in @[simp] theorem rid_symm_apply (a : A) : (TensorProduct.rid R S A).symm a = a ⊗ₜ 1 := rfl section CompatibleSMul variable (R S A B : Type*) [CommSemiring R] [CommSemiring S] [Semiring A] [Semiring B] variable [Algebra R A] [Algebra R B] [Algebra S A] [Algebra S B] variable [SMulCommClass R S A] [CompatibleSMul R S A B] /-- If A and B are both R- and S-algebras and their actions on them commute, and if the S-action on `A ⊗[R] B` can switch between the two factors, then there is a canonical S-algebra homomorphism from `A ⊗[S] B` to `A ⊗[R] B`. -/ def mapOfCompatibleSMul : A ⊗[S] B →ₐ[S] A ⊗[R] B := .ofLinearMap (_root_.TensorProduct.mapOfCompatibleSMul R S A B) rfl fun x ↦ x.induction_on (by simp) (fun _ _ y ↦ y.induction_on (by simp) (by simp) fun _ _ h h' ↦ by simp only [mul_add, map_add, h, h']) fun _ _ h h' _ ↦ by simp only [add_mul, map_add, h, h'] @[simp] theorem mapOfCompatibleSMul_tmul (m n) : mapOfCompatibleSMul R S A B (m ⊗ₜ n) = m ⊗ₜ n := rfl theorem mapOfCompatibleSMul_surjective : Function.Surjective (mapOfCompatibleSMul R S A B) := _root_.TensorProduct.mapOfCompatibleSMul_surjective R S A B attribute [local instance] SMulCommClass.symm /-- `mapOfCompatibleSMul R S A B` is also A-linear. -/ def mapOfCompatibleSMul' : A ⊗[S] B →ₐ[R] A ⊗[R] B := .ofLinearMap (_root_.TensorProduct.mapOfCompatibleSMul' R S A B) rfl (map_mul <| mapOfCompatibleSMul R S A B) /-- If the R- and S-actions on A and B satisfy `CompatibleSMul` both ways, then `A ⊗[S] B` is canonically isomorphic to `A ⊗[R] B`. -/ def equivOfCompatibleSMul [CompatibleSMul S R A B] : A ⊗[S] B ≃ₐ[S] A ⊗[R] B where __ := mapOfCompatibleSMul R S A B invFun := mapOfCompatibleSMul S R A B __ := _root_.TensorProduct.equivOfCompatibleSMul R S A B variable [Algebra R S] [CompatibleSMul R S S A] [CompatibleSMul S R S A] omit [SMulCommClass R S A] /-- If the R- and S- action on S and A satisfy `CompatibleSMul` both ways, then `S ⊗[R] A` is canonically isomorphic to `A`. -/ def lidOfCompatibleSMul : S ⊗[R] A ≃ₐ[S] A := (equivOfCompatibleSMul R S S A).symm.trans (TensorProduct.lid _ _) theorem lidOfCompatibleSMul_tmul (s a) : lidOfCompatibleSMul R S A (s ⊗ₜ[R] a) = s • a := rfl instance {R M N : Type*} [CommSemiring R] [AddCommGroup M] [AddCommGroup N] [Module R M] [Module R N] [Module ℚ M] [Module ℚ N] : CompatibleSMul R ℚ M N where smul_tmul q m n := by have : IsAddTorsionFree (M ⊗[R] N) := .of_module_rat _ suffices q.den • ((q • m) ⊗ₜ[R] n) = q.den • (m ⊗ₜ[R] (q • n)) from smul_right_injective (M ⊗[R] N) q.den_nz <| by norm_cast rw [smul_tmul', ← tmul_smul, ← smul_assoc, ← smul_assoc, nsmul_eq_mul, Rat.den_mul_eq_num] norm_cast rw [smul_tmul] end CompatibleSMul section variable (B) unseal mul in /-- The tensor product of R-algebras is commutative, up to algebra isomorphism. -/ protected def comm : A ⊗[R] B ≃ₐ[R] B ⊗[R] A := algEquivOfLinearEquivTensorProduct (_root_.TensorProduct.comm R A B) (fun _ _ _ _ => rfl) rfl @[simp] theorem comm_toLinearEquiv : (Algebra.TensorProduct.comm R A B).toLinearEquiv = _root_.TensorProduct.comm R A B := rfl variable {A B} in @[simp] theorem comm_tmul (a : A) (b : B) : TensorProduct.comm R A B (a ⊗ₜ b) = b ⊗ₜ a := rfl variable {A B} in @[simp] theorem comm_symm_tmul (a : A) (b : B) : (TensorProduct.comm R A B).symm (b ⊗ₜ a) = a ⊗ₜ b := rfl theorem comm_symm : (TensorProduct.comm R A B).symm = TensorProduct.comm R B A := by ext; rfl @[simp] lemma comm_comp_includeLeft : (TensorProduct.comm R A B : A ⊗[R] B →ₐ[R] B ⊗[R] A).comp includeLeft = includeRight := rfl @[simp] lemma comm_comp_includeRight : (TensorProduct.comm R A B : A ⊗[R] B →ₐ[R] B ⊗[R] A).comp includeRight = includeLeft := rfl theorem adjoin_tmul_eq_top : adjoin R { t : A ⊗[R] B | ∃ a b, a ⊗ₜ[R] b = t } = ⊤ := top_le_iff.mp <| (top_le_iff.mpr <| span_tmul_eq_top R A B).trans (span_le_adjoin R _) end section variable {R A} unseal mul in theorem assoc_aux_1 (a₁ a₂ : A) (b₁ b₂ : B) (c₁ c₂ : C) : (TensorProduct.assoc R A B C) ((a₁ * a₂) ⊗ₜ[R] (b₁ * b₂) ⊗ₜ[R] (c₁ * c₂)) = (TensorProduct.assoc R A B C) (a₁ ⊗ₜ[R] b₁ ⊗ₜ[R] c₁) * (TensorProduct.assoc R A B C) (a₂ ⊗ₜ[R] b₂ ⊗ₜ[R] c₂) := rfl theorem assoc_aux_2 : (TensorProduct.assoc R A B C) (1 ⊗ₜ[R] 1 ⊗ₜ[R] 1) = 1 := rfl variable (R A C D) /-- The associator for tensor product of R-algebras, as an algebra isomorphism. -/ protected def assoc : A ⊗[S] C ⊗[R] D ≃ₐ[S] A ⊗[S] (C ⊗[R] D) := AlgEquiv.ofLinearEquiv (AlgebraTensorModule.assoc R S S A C D) (by simp [Algebra.TensorProduct.one_def]) ((LinearMap.map_mul_iff _).mpr <| by ext; simp) @[simp] theorem assoc_toLinearEquiv : (TensorProduct.assoc R S A C D).toLinearEquiv = AlgebraTensorModule.assoc R S S A C D := rfl variable {A C D} @[simp] theorem assoc_tmul (a : A) (b : C) (c : D) : TensorProduct.assoc R S A C D ((a ⊗ₜ b) ⊗ₜ c) = a ⊗ₜ (b ⊗ₜ c) := rfl @[simp] theorem assoc_symm_tmul (a : A) (b : C) (c : D) : (TensorProduct.assoc R S A C D).symm (a ⊗ₜ (b ⊗ₜ c)) = (a ⊗ₜ b) ⊗ₜ c := rfl end section variable (T A B : Type*) [CommSemiring T] [CommSemiring A] [CommSemiring B] [Algebra R T] [Algebra R A] [Algebra R B] [Algebra T A] [IsScalarTower R T A] [Algebra S A] [IsScalarTower R S A] [Algebra S T] [IsScalarTower S T A] /-- The natural isomorphism `A ⊗[S] (S ⊗[R] B) ≃ₐ[T] A ⊗[R] B`. -/ def cancelBaseChange : A ⊗[S] (S ⊗[R] B) ≃ₐ[T] A ⊗[R] B := AlgEquiv.symm <| AlgEquiv.ofLinearEquiv (TensorProduct.AlgebraTensorModule.cancelBaseChange R S T A B).symm (by simp [Algebra.TensorProduct.one_def]) <| LinearMap.map_mul_of_map_mul_tmul (fun _ _ _ _ ↦ by simp) @[simp] lemma cancelBaseChange_tmul (a : A) (s : S) (b : B) : Algebra.TensorProduct.cancelBaseChange R S T A B (a ⊗ₜ (s ⊗ₜ b)) = (s • a) ⊗ₜ b := TensorProduct.AlgebraTensorModule.cancelBaseChange_tmul R S T a b s @[simp] lemma cancelBaseChange_symm_tmul (a : A) (b : B) : (Algebra.TensorProduct.cancelBaseChange R S T A B).symm (a ⊗ₜ b) = a ⊗ₜ (1 ⊗ₜ b) := TensorProduct.AlgebraTensorModule.cancelBaseChange_symm_tmul R S T a b end variable {R S A} /-- The tensor product of a pair of algebra morphisms. -/ def map (f : A →ₐ[S] C) (g : B →ₐ[R] D) : A ⊗[R] B →ₐ[S] C ⊗[R] D := algHomOfLinearMapTensorProduct (AlgebraTensorModule.map f.toLinearMap g.toLinearMap) (by simp) (by simp [one_def]) @[simp] lemma toLinearMap_map (f : A →ₐ[S] C) (g : B →ₐ[R] D) : (map f g).toLinearMap = TensorProduct.AlgebraTensorModule.map f.toLinearMap g.toLinearMap := rfl @[simp] theorem map_tmul (f : A →ₐ[S] C) (g : B →ₐ[R] D) (a : A) (b : B) : map f g (a ⊗ₜ b) = f a ⊗ₜ g b := rfl @[simp] theorem map_id : map (.id S A) (.id R B) = .id S _ := ext (AlgHom.ext fun _ => rfl) (AlgHom.ext fun _ => rfl) theorem map_comp (f₂ : C →ₐ[S] E) (f₁ : A →ₐ[S] C) (g₂ : D →ₐ[R] F) (g₁ : B →ₐ[R] D) : map (f₂.comp f₁) (g₂.comp g₁) = (map f₂ g₂).comp (map f₁ g₁) := ext (AlgHom.ext fun _ => rfl) (AlgHom.ext fun _ => rfl) lemma map_id_comp (g₂ : D →ₐ[R] F) (g₁ : B →ₐ[R] D) : map (AlgHom.id S A) (g₂.comp g₁) = (map (AlgHom.id S A) g₂).comp (map (AlgHom.id S A) g₁) := ext (AlgHom.ext fun _ => rfl) (AlgHom.ext fun _ => rfl) lemma map_comp_id (f₂ : C →ₐ[S] E) (f₁ : A →ₐ[S] C) : map (f₂.comp f₁) (AlgHom.id R E) = (map f₂ (AlgHom.id R E)).comp (map f₁ (AlgHom.id R E)) := ext (AlgHom.ext fun _ => rfl) (AlgHom.ext fun _ => rfl) @[simp] theorem map_comp_includeLeft (f : A →ₐ[S] C) (g : B →ₐ[R] D) : (map f g).comp includeLeft = includeLeft.comp f := AlgHom.ext <| by simp @[simp] theorem map_restrictScalars_comp_includeRight (f : A →ₐ[S] C) (g : B →ₐ[R] D) : ((map f g).restrictScalars R).comp includeRight = includeRight.comp g := AlgHom.ext <| by simp @[simp] theorem map_comp_includeRight (f : A →ₐ[R] C) (g : B →ₐ[R] D) : (map f g).comp includeRight = includeRight.comp g := map_restrictScalars_comp_includeRight f g theorem map_range (f : A →ₐ[R] C) (g : B →ₐ[R] D) : (map f g).range = (includeLeft.comp f).range ⊔ (includeRight.comp g).range := by apply le_antisymm · rw [← map_top, ← adjoin_tmul_eq_top, ← adjoin_image, adjoin_le_iff] rintro _ ⟨_, ⟨a, b, rfl⟩, rfl⟩ rw [map_tmul, ← mul_one (f a), ← one_mul (g b), ← tmul_mul_tmul] exact mul_mem_sup (AlgHom.mem_range_self _ a) (AlgHom.mem_range_self _ b) · rw [← map_comp_includeLeft f g, ← map_comp_includeRight f g] exact sup_le (AlgHom.range_comp_le_range _ _) (AlgHom.range_comp_le_range _ _) lemma comm_comp_map (f : A →ₐ[R] C) (g : B →ₐ[R] D) : (TensorProduct.comm R C D : C ⊗[R] D →ₐ[R] D ⊗[R] C).comp (Algebra.TensorProduct.map f g) = (Algebra.TensorProduct.map g f).comp (TensorProduct.comm R A B).toAlgHom := by ext <;> rfl lemma comm_comp_map_apply (f : A →ₐ[R] C) (g : B →ₐ[R] D) (x) : TensorProduct.comm R C D (Algebra.TensorProduct.map f g x) = (Algebra.TensorProduct.map g f) (TensorProduct.comm R A B x) := congr($(comm_comp_map f g) x) variable (A) in /-- `lTensor A g : A ⊗ B →ₐ A ⊗ D` is the natural algebra morphism induced by `g : B →ₐ D`. -/ noncomputable abbrev lTensor (g : B →ₐ[R] D) : (A ⊗[R] B) →ₐ[S] (A ⊗[R] D) := map (.id S A) g variable (B) in /-- `rTensor B f : A ⊗ B →ₐ C ⊗ B` is the natural algebra morphism induced by `f : A →ₐ C`. -/ noncomputable abbrev rTensor (f : A →ₐ[S] C) : A ⊗[R] B →ₐ[S] C ⊗[R] B := map f (.id R B) /-- Construct an isomorphism between tensor products of an S-algebra with an R-algebra from S- and R- isomorphisms between the tensor factors. -/ def congr (f : A ≃ₐ[S] C) (g : B ≃ₐ[R] D) : A ⊗[R] B ≃ₐ[S] C ⊗[R] D := AlgEquiv.ofAlgHom (map f g) (map f.symm g.symm) (ext' fun b d => by simp) (ext' fun a c => by simp) @[simp] theorem congr_toLinearEquiv (f : A ≃ₐ[S] C) (g : B ≃ₐ[R] D) : (Algebra.TensorProduct.congr f g).toLinearEquiv = TensorProduct.AlgebraTensorModule.congr f.toLinearEquiv g.toLinearEquiv := rfl @[simp] theorem congr_apply (f : A ≃ₐ[S] C) (g : B ≃ₐ[R] D) (x) : congr f g x = (map (f : A →ₐ[S] C) (g : B →ₐ[R] D)) x := rfl @[simp] theorem congr_symm_apply (f : A ≃ₐ[S] C) (g : B ≃ₐ[R] D) (x) : (congr f g).symm x = (map (f.symm : C →ₐ[S] A) (g.symm : D →ₐ[R] B)) x := rfl @[simp] theorem congr_refl : congr (.refl : A ≃ₐ[S] A) (.refl : B ≃ₐ[R] B) = .refl := AlgEquiv.coe_algHom_injective <| map_id theorem congr_trans (f₁ : A ≃ₐ[S] C) (f₂ : C ≃ₐ[S] E) (g₁ : B ≃ₐ[R] D) (g₂ : D ≃ₐ[R] F) : congr (f₁.trans f₂) (g₁.trans g₂) = (congr f₁ g₁).trans (congr f₂ g₂) := AlgEquiv.coe_algHom_injective <| map_comp f₂.toAlgHom f₁.toAlgHom g₂.toAlgHom g₁.toAlgHom theorem congr_symm (f : A ≃ₐ[S] C) (g : B ≃ₐ[R] D) : congr f.symm g.symm = (congr f g).symm := rfl variable (R A B C) in /-- Tensor product of algebras analogue of `mul_left_comm`. This is the algebra version of `TensorProduct.leftComm`. -/ def leftComm : A ⊗[R] (B ⊗[R] C) ≃ₐ[R] B ⊗[R] (A ⊗[R] C) := (Algebra.TensorProduct.assoc R R A B C).symm.trans <| (congr (Algebra.TensorProduct.comm R A B) .refl).trans <| TensorProduct.assoc R R B A C @[simp] theorem leftComm_tmul (m : A) (n : B) (p : C) : leftComm R A B C (m ⊗ₜ (n ⊗ₜ p)) = n ⊗ₜ (m ⊗ₜ p) := rfl @[simp] theorem leftComm_symm_tmul (m : A) (n : B) (p : C) : (leftComm R A B C).symm (n ⊗ₜ (m ⊗ₜ p)) = m ⊗ₜ (n ⊗ₜ p) := rfl @[simp] theorem leftComm_toLinearEquiv : ↑(leftComm R A B C) = _root_.TensorProduct.leftComm R A B C := LinearEquiv.toLinearMap_injective (by ext; rfl) variable [CommSemiring T] [Algebra R T] [Algebra T A] [IsScalarTower R T A] [SMulCommClass S T A] [Algebra S T] [IsScalarTower S T A] [CommSemiring R'] [Algebra R R'] [Algebra R' T] [Algebra R' A] [Algebra R' B] [IsScalarTower R R' A] [SMulCommClass S R' A] [SMulCommClass R' S A] [IsScalarTower R' T A] [IsScalarTower R R' B] variable (R R' S T A B C D) in /-- Tensor product of algebras analogue of `mul_mul_mul_comm`. This is the algebra version of `TensorProduct.AlgebraTensorModule.tensorTensorTensorComm`. -/ def tensorTensorTensorComm : A ⊗[R'] B ⊗[S] (C ⊗[R] D) ≃ₐ[T] A ⊗[S] C ⊗[R'] (B ⊗[R] D) := AlgEquiv.ofLinearEquiv (TensorProduct.AlgebraTensorModule.tensorTensorTensorComm R R' S T A B C D) rfl (LinearMap.map_mul_iff _ |>.mpr <| by ext; simp) @[simp] theorem tensorTensorTensorComm_tmul (m : A) (n : B) (p : C) (q : D) : tensorTensorTensorComm R R' S T A B C D (m ⊗ₜ n ⊗ₜ (p ⊗ₜ q)) = m ⊗ₜ p ⊗ₜ (n ⊗ₜ q) := rfl @[simp] theorem tensorTensorTensorComm_symm_tmul (m : A) (n : C) (p : B) (q : D) : (tensorTensorTensorComm R R' S T A B C D).symm (m ⊗ₜ n ⊗ₜ (p ⊗ₜ q)) = m ⊗ₜ p ⊗ₜ (n ⊗ₜ q) := rfl theorem tensorTensorTensorComm_symm : (tensorTensorTensorComm R R' S T A B C D).symm = tensorTensorTensorComm R S R' T A C B D := rfl theorem tensorTensorTensorComm_toLinearEquiv : (tensorTensorTensorComm R R' S T A B C D).toLinearEquiv = TensorProduct.AlgebraTensorModule.tensorTensorTensorComm R R' S T A B C D := rfl @[simp] theorem toLinearEquiv_tensorTensorTensorComm : (tensorTensorTensorComm R R R R A B C D).toLinearEquiv = _root_.TensorProduct.tensorTensorTensorComm R A B C D := rfl lemma map_bijective {f : A →ₐ[R] B} {g : C →ₐ[R] D} (hf : Function.Bijective f) (hg : Function.Bijective g) : Function.Bijective (map f g) := _root_.TensorProduct.map_bijective hf hg lemma includeLeft_bijective (h : Function.Bijective (algebraMap R B)) : Function.Bijective (includeLeft : A →ₐ[S] A ⊗[R] B) := by have : (includeLeft : A →ₐ[S] A ⊗[R] B).comp (TensorProduct.rid R S A).toAlgHom = map (.id S A) (Algebra.ofId R B) := by ext; simp rw [← Function.Bijective.of_comp_iff _ (TensorProduct.rid R S A).bijective] convert_to Function.Bijective (map (.id R A) (Algebra.ofId R B)) · exact DFunLike.coe_fn_eq.mpr this · exact Algebra.TensorProduct.map_bijective Function.bijective_id h lemma includeRight_bijective (h : Function.Bijective (algebraMap R A)) : Function.Bijective (includeRight : B →ₐ[R] A ⊗[R] B) := by rw [← Function.Bijective.of_comp_iff' (TensorProduct.comm R A B).bijective] exact Algebra.TensorProduct.includeLeft_bijective (S := R) h end end Monoidal section variable [CommSemiring R] [CommSemiring S] [Algebra R S] variable [Semiring A] [Algebra R A] [Algebra S A] [IsScalarTower R S A] variable [Semiring B] [Algebra R B] variable [CommSemiring C] [Algebra R C] [Algebra S C] [IsScalarTower R S C] /-- If `A`, `B`, `C` are `R`-algebras, `A` and `C` are also `S`-algebras (forming a tower as `·/S/R`), then the product map of `f : A →ₐ[S] C` and `g : B →ₐ[R] C` is an `S`-algebra homomorphism. This is just a special case of `Algebra.TensorProduct.lift` for when `C` is commutative. -/ abbrev productLeftAlgHom (f : A →ₐ[S] C) (g : B →ₐ[R] C) : A ⊗[R] B →ₐ[S] C := lift f g (fun _ _ => Commute.all _ _) lemma tmul_one_eq_one_tmul (r : R) : algebraMap R A r ⊗ₜ[R] 1 = 1 ⊗ₜ algebraMap R B r := by rw [Algebra.algebraMap_eq_smul_one, Algebra.algebraMap_eq_smul_one, smul_tmul] end section variable [CommSemiring R] [Semiring A] [Semiring B] [CommSemiring S] variable [Algebra R A] [Algebra R B] [Algebra R S] variable (f : A →ₐ[R] S) (g : B →ₐ[R] S) variable (R) /-- `LinearMap.mul'` as an `AlgHom` over the algebra. -/ def lmul'' : S ⊗[R] S →ₐ[S] S := algHomOfLinearMapTensorProduct { __ := LinearMap.mul' R S map_smul' := fun s x ↦ x.induction_on (by simp) (fun _ _ ↦ by simp [TensorProduct.smul_tmul', mul_assoc]) fun x y hx hy ↦ by simp_all [mul_add] } (fun a₁ a₂ b₁ b₂ => by simp [mul_mul_mul_comm]) <| by simp theorem lmul''_eq_lid_comp_mapOfCompatibleSMul : lmul'' R = (TensorProduct.lid S S).toAlgHom.comp (mapOfCompatibleSMul' _ _ _ _) := by ext; rfl /-- `LinearMap.mul'` as an `AlgHom` over the base ring. -/ def lmul' : S ⊗[R] S →ₐ[R] S := (lmul'' R).restrictScalars R variable {R} theorem lmul'_toLinearMap : (lmul' R : _ →ₐ[R] S).toLinearMap = LinearMap.mul' R S := rfl @[simp] theorem lmul'_apply_tmul (a b : S) : lmul' (S := S) R (a ⊗ₜ[R] b) = a * b := rfl @[simp] theorem lmul'_comp_includeLeft : (lmul' R : _ →ₐ[R] S).comp includeLeft = AlgHom.id R S := AlgHom.ext <| mul_one @[simp] theorem lmul'_comp_includeRight : (lmul' R : _ →ₐ[R] S).comp includeRight = AlgHom.id R S := AlgHom.ext <| one_mul lemma lmul'_comp_map (f : A →ₐ[R] S) (g : B →ₐ[R] S) : (lmul' R).comp (map f g) = lift f g (fun _ _ ↦ .all _ _) := by ext <;> rfl variable (R S) in /-- If multiplication by elements of S can switch between the two factors of `S ⊗[R] S`, then `lmul''` is an isomorphism. -/ def lmulEquiv [CompatibleSMul R S S S] : S ⊗[R] S ≃ₐ[S] S := .ofAlgHom (lmul'' R) includeLeft lmul'_comp_includeLeft <| AlgHom.ext fun x ↦ x.induction_on (by simp) (fun x y ↦ show (x * y) ⊗ₜ[R] 1 = x ⊗ₜ[R] y by rw [mul_comm, ← smul_eq_mul, smul_tmul, smul_eq_mul, mul_one]) fun _ _ hx hy ↦ by simp_all [add_tmul] theorem lmulEquiv_eq_lidOfCompatibleSMul [CompatibleSMul R S S S] : lmulEquiv R S = lidOfCompatibleSMul R S S := AlgEquiv.coe_algHom_injective <| by ext; rfl /-- If `S` is commutative, for a pair of morphisms `f : A →ₐ[R] S`, `g : B →ₐ[R] S`, We obtain a map `A ⊗[R] B →ₐ[R] S` that commutes with `f`, `g` via `a ⊗ b ↦ f(a) * g(b)`. This is a special case of `Algebra.TensorProduct.productLeftAlgHom` for when the two base rings are the same. -/ def productMap : A ⊗[R] B →ₐ[R] S := productLeftAlgHom f g theorem productMap_eq_comp_map : productMap f g = (lmul' R).comp (TensorProduct.map f g) := by ext <;> rfl @[simp] theorem productMap_apply_tmul (a : A) (b : B) : productMap f g (a ⊗ₜ b) = f a * g b := rfl theorem productMap_left_apply (a : A) : productMap f g (a ⊗ₜ 1) = f a := by simp @[simp] theorem productMap_left : (productMap f g).comp includeLeft = f := lift_comp_includeLeft _ _ (fun _ _ => Commute.all _ _) theorem productMap_right_apply (b : B) : productMap f g (1 ⊗ₜ b) = g b := by simp @[simp] theorem productMap_right : (productMap f g).comp includeRight = g := lift_comp_includeRight _ _ (fun _ _ => Commute.all _ _) theorem productMap_range : (productMap f g).range = f.range ⊔ g.range := by rw [productMap_eq_comp_map, AlgHom.range_comp, map_range, map_sup, ← AlgHom.range_comp, ← AlgHom.range_comp, ← AlgHom.comp_assoc, ← AlgHom.comp_assoc, lmul'_comp_includeLeft, lmul'_comp_includeRight, AlgHom.id_comp, AlgHom.id_comp] end end TensorProduct end Algebra namespace LinearMap variable (R A M N : Type*) [CommSemiring R] [CommSemiring A] [Algebra R A] variable [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] open Module open scoped TensorProduct /-- The natural linear map $A ⊗ \text{Hom}_R(M, N) → \text{Hom}_A (M_A, N_A)$, where $M_A$ and $N_A$ are the respective modules over $A$ obtained by extension of scalars. See `LinearMap.tensorProductEnd` for this map specialized to endomorphisms, and bundled as `A`-algebra homomorphism. -/ @[simps!] def tensorProduct : A ⊗[R] (M →ₗ[R] N) →ₗ[A] (A ⊗[R] M) →ₗ[A] (A ⊗[R] N) := TensorProduct.AlgebraTensorModule.lift <| { toFun := fun a ↦ a • baseChangeHom R A M N map_add' := by simp only [add_smul, forall_true_iff] map_smul' := by simp only [smul_assoc, RingHom.id_apply, forall_true_iff] } /-- The natural `A`-algebra homomorphism $A ⊗ (\text{End}_R M) → \text{End}_A (A ⊗ M)$, where `M` is an `R`-module, and `A` an `R`-algebra. -/ @[simps!] def tensorProductEnd : A ⊗[R] (End R M) →ₐ[A] End A (A ⊗[R] M) := Algebra.TensorProduct.algHomOfLinearMapTensorProduct (LinearMap.tensorProduct R A M M) (fun a b f g ↦ by apply LinearMap.ext intro x simp only [tensorProduct, mul_comm a b, Module.End.mul_eq_comp, TensorProduct.AlgebraTensorModule.lift_apply, TensorProduct.lift.tmul, coe_restrictScalars, coe_mk, AddHom.coe_mk, mul_smul, smul_apply, baseChangeHom_apply, baseChange_comp, comp_apply, Algebra.mul_smul_comm, Algebra.smul_mul_assoc]) (by apply LinearMap.ext intro x simp only [tensorProduct, TensorProduct.AlgebraTensorModule.lift_apply, TensorProduct.lift.tmul, coe_restrictScalars, coe_mk, AddHom.coe_mk, one_smul, baseChangeHom_apply, baseChange_eq_ltensor, Module.End.one_eq_id, lTensor_id, LinearMap.id_apply]) end LinearMap namespace Module variable {R S A M N : Type*} [CommSemiring R] [CommSemiring S] [Semiring A] variable [AddCommMonoid M] [AddCommMonoid N] variable [Algebra R S] [Algebra S A] [Algebra R A] variable [Module R M] [Module S M] [Module A M] [Module R N] variable [IsScalarTower R A M] [IsScalarTower S A M] [IsScalarTower R S M] /-- The algebra homomorphism from `End M ⊗ End N` to `End (M ⊗ N)` sending `f ⊗ₜ g` to the `TensorProduct.map f g`, the tensor product of the two maps. This is an `AlgHom` version of `TensorProduct.AlgebraTensorModule.homTensorHomMap`. Like that definition, this is generalized across many different rings; namely a tower of algebras `A/S/R`. -/ def endTensorEndAlgHom : End A M ⊗[R] End R N →ₐ[S] End A (M ⊗[R] N) := Algebra.TensorProduct.algHomOfLinearMapTensorProduct (AlgebraTensorModule.homTensorHomMap R A S M N M N) (fun _f₁ _f₂ _g₁ _g₂ => AlgebraTensorModule.ext fun _m _n => rfl) (AlgebraTensorModule.ext fun _m _n => rfl) theorem endTensorEndAlgHom_apply (f : End A M) (g : End R N) : endTensorEndAlgHom (R := R) (S := S) (A := A) (M := M) (N := N) (f ⊗ₜ[R] g) = AlgebraTensorModule.map f g := rfl end Module /-- Given a subalgebra `C` of an `R`-algebra `A`, and an `R`-algebra `B`, the base change of `C` to a subalgebra of `B ⊗[R] A` -/ def Subalgebra.baseChange {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] (B : Type*) [CommSemiring B] [Algebra R B] (C : Subalgebra R A) : Subalgebra B (B ⊗[R] A) := AlgHom.range (Algebra.TensorProduct.map (AlgHom.id B B) C.val) variable {R A B : Type*} [CommSemiring R] [Semiring A] [CommSemiring B] [Algebra R A] [Algebra R B] variable {C : Subalgebra R A} lemma Subalgebra.tmul_mem_baseChange {x : A} (hx : x ∈ C) (b : B) : b ⊗ₜ[R] x ∈ C.baseChange B := ⟨(b ⊗ₜ[R] ⟨x, hx⟩), rfl⟩
.lake/packages/mathlib/Mathlib/RingTheory/TensorProduct/Pi.lean
import Mathlib.Algebra.Algebra.Pi import Mathlib.LinearAlgebra.TensorProduct.Pi import Mathlib.LinearAlgebra.TensorProduct.Prod import Mathlib.RingTheory.TensorProduct.Maps /-! # Tensor product and products of algebras In this file we examine the behaviour of the tensor product with (finite) products. This is a direct application of `Mathlib/LinearAlgebra/TensorProduct/Pi.lean` to the algebra case. -/ open TensorProduct namespace Algebra.TensorProduct variable (R S A : Type*) [CommSemiring R] [CommSemiring S] [Algebra R S] [Semiring A] [Algebra R A] [Algebra S A] [IsScalarTower R S A] variable {ι : Type*} (B : ι → Type*) [∀ i, Semiring (B i)] [∀ i, Algebra R (B i)] @[simp] lemma piRightHom_one : piRightHom R S A B 1 = 1 := rfl variable {R S A B} in @[simp] lemma piRightHom_mul (x y : A ⊗[R] ∀ i, B i) : piRightHom R S A B (x * y) = piRightHom R S A B x * piRightHom R S A B y := by induction x · simp · induction y · simp · ext j simp · simp_all [mul_add] · simp_all [add_mul] /-- The canonical map `A ⊗[R] (∀ i, B i) →ₐ[S] ∀ i, A ⊗[R] B i`. This is an isomorphism if `ι` is finite (see `Algebra.TensorProduct.piRight`). -/ def piRightHom : A ⊗[R] (∀ i, B i) →ₐ[S] ∀ i, A ⊗[R] B i := AlgHom.ofLinearMap (_root_.TensorProduct.piRightHom R S A B) (by simp) (by simp) variable [Fintype ι] [DecidableEq ι] /-- Tensor product of rings commutes with finite products on the right. -/ def piRight : A ⊗[R] (∀ i, B i) ≃ₐ[S] ∀ i, A ⊗[R] B i := AlgEquiv.ofLinearEquiv (_root_.TensorProduct.piRight R S A B) (by simp) (by simp) @[simp] lemma piRight_tmul (x : A) (f : ∀ i, B i) : piRight R S A B (x ⊗ₜ f) = (fun j ↦ x ⊗ₜ f j) := rfl variable (ι) in /-- Variant of `Algebra.TensorProduct.piRight` with constant factors. -/ def piScalarRight : A ⊗[R] (ι → R) ≃ₐ[S] ι → A := (piRight R S A (fun _ : ι ↦ R)).trans <| AlgEquiv.piCongrRight (fun _ ↦ Algebra.TensorProduct.rid R S A) lemma piScalarRight_tmul (x : A) (y : ι → R) : piScalarRight R S A ι (x ⊗ₜ y) = fun i ↦ y i • x := rfl @[simp] lemma piScalarRight_tmul_apply (x : A) (y : ι → R) (i : ι) : piScalarRight R S A ι (x ⊗ₜ y) i = y i • x := rfl section variable (B C : Type*) [Semiring B] [Semiring C] [Algebra R B] [Algebra R C] /-- Tensor product of rings commutes with binary products on the right. -/ nonrec def prodRight : A ⊗[R] (B × C) ≃ₐ[S] A ⊗[R] B × A ⊗[R] C := AlgEquiv.ofLinearEquiv (TensorProduct.prodRight R S A B C) (by simp [Algebra.TensorProduct.one_def]) (LinearMap.map_mul_of_map_mul_tmul (fun _ _ _ _ ↦ by simp)) lemma prodRight_tmul (a : A) (x : B × C) : prodRight R S A B C (a ⊗ₜ x) = (a ⊗ₜ x.1, a ⊗ₜ x.2) := rfl @[simp] lemma prodRight_tmul_fst (a : A) (x : B × C) : (prodRight R S A B C (a ⊗ₜ x)).fst = a ⊗ₜ x.1 := rfl @[simp] lemma prodRight_tmul_snd (a : A) (x : B × C) : (prodRight R S A B C (a ⊗ₜ x)).snd = a ⊗ₜ x.2 := rfl @[simp] lemma prodRight_symm_tmul (a : A) (b : B) (c : C) : (prodRight R S A B C).symm (a ⊗ₜ b, a ⊗ₜ c) = a ⊗ₜ (b, c) := by apply (prodRight R S A B C).injective simp [prodRight_tmul] end end Algebra.TensorProduct theorem TensorProduct.piScalarRight_symm_algebraMap (R : Type*) [CommSemiring R] (S : Type*) [CommSemiring S] [Algebra R S] (ι : Type*) [Fintype ι] [DecidableEq ι] {N : Type*} [Semiring N] [Algebra R N] [Module S N] [IsScalarTower R S N] (x : ι → R) : (TensorProduct.piScalarRight R S N ι).symm (algebraMap _ _ x) = 1 ⊗ₜ[R] x := by simp [Algebra.algebraMap_eq_smul_one, Pi.smul_def', LinearEquiv.symm_apply_eq, piScalarRight_apply, piScalarRightHom_tmul]
.lake/packages/mathlib/Mathlib/RingTheory/TensorProduct/Basic.lean
import Mathlib.Algebra.Algebra.Operations import Mathlib.Algebra.Star.TensorProduct import Mathlib.LinearAlgebra.TensorProduct.Tower /-! # The tensor product of R-algebras This file provides results about the multiplicative structure on `A ⊗[R] B` when `R` is a commutative (semi)ring and `A` and `B` are both `R`-algebras. On these tensor products, multiplication is characterized by `(a₁ ⊗ₜ b₁) * (a₂ ⊗ₜ b₂) = (a₁ * a₂) ⊗ₜ (b₁ * b₂)`. ## Main declarations - `Algebra.TensorProduct.semiring`: the ring structure on `A ⊗[R] B` for two `R`-algebras `A`, `B`. - `Algebra.TensorProduct.leftAlgebra`: the `S`-algebra structure on `A ⊗[R] B`, for when `A` is additionally an `S` algebra. ## References * [C. Kassel, *Quantum Groups* (§II.4)][Kassel1995] -/ assert_not_exists Equiv.Perm.cycleType open scoped TensorProduct open TensorProduct namespace LinearMap section liftBaseChange variable {R M N} (A) [CommSemiring R] [CommSemiring A] [Algebra R A] [AddCommMonoid M] variable [AddCommMonoid N] [Module R M] [Module R N] [Module A N] [IsScalarTower R A N] /-- If `M` is an `R`-module and `N` is an `A`-module, then `A`-linear maps `A ⊗[R] M →ₗ[A] N` correspond to `R` linear maps `M →ₗ[R] N` by composing with `M → A ⊗ M`, `x ↦ 1 ⊗ x`. -/ def liftBaseChangeEquiv : (M →ₗ[R] N) ≃ₗ[A] (A ⊗[R] M →ₗ[A] N) := (LinearMap.ringLmapEquivSelf _ _ _).symm.trans (AlgebraTensorModule.lift.equiv _ _ _ _ _ _) /-- If `N` is an `A` module, we may lift a linear map `M →ₗ[R] N` to `A ⊗[R] M →ₗ[A] N` -/ abbrev liftBaseChange (l : M →ₗ[R] N) : A ⊗[R] M →ₗ[A] N := LinearMap.liftBaseChangeEquiv A l @[simp] lemma liftBaseChange_tmul (l : M →ₗ[R] N) (x y) : l.liftBaseChange A (x ⊗ₜ y) = x • l y := rfl lemma liftBaseChange_one_tmul (l : M →ₗ[R] N) (y) : l.liftBaseChange A (1 ⊗ₜ y) = l y := by simp @[simp] lemma liftBaseChangeEquiv_symm_apply (l : A ⊗[R] M →ₗ[A] N) (x) : (liftBaseChangeEquiv A).symm l x = l (1 ⊗ₜ x) := rfl lemma liftBaseChange_comp {P} [AddCommMonoid P] [Module A P] [Module R P] [IsScalarTower R A P] (l : M →ₗ[R] N) (l' : N →ₗ[A] P) : l' ∘ₗ l.liftBaseChange A = (l'.restrictScalars R ∘ₗ l).liftBaseChange A := by ext simp @[simp] lemma range_liftBaseChange (l : M →ₗ[R] N) : LinearMap.range (l.liftBaseChange A) = Submodule.span A (LinearMap.range l) := by apply le_antisymm · rintro _ ⟨x, rfl⟩ induction x using TensorProduct.induction_on · simp · rw [LinearMap.liftBaseChange_tmul] exact Submodule.smul_mem _ _ (Submodule.subset_span ⟨_, rfl⟩) · rw [map_add] exact add_mem ‹_› ‹_› · rw [Submodule.span_le] rintro _ ⟨x, rfl⟩ exact ⟨1 ⊗ₜ x, by simp⟩ end liftBaseChange end LinearMap namespace Algebra namespace TensorProduct universe uR uS uA uB uC uD uE uF variable {R : Type uR} {R' : Type*} {S : Type uS} {T : Type*} variable {A : Type uA} {B : Type uB} {C : Type uC} {D : Type uD} {E : Type uE} {F : Type uF} /-! ### The `R`-algebra structure on `A ⊗[R] B` -/ section AddCommMonoidWithOne variable [CommSemiring R] variable [AddCommMonoidWithOne A] [Module R A] variable [AddCommMonoidWithOne B] [Module R B] instance : One (A ⊗[R] B) where one := 1 ⊗ₜ 1 theorem one_def : (1 : A ⊗[R] B) = (1 : A) ⊗ₜ (1 : B) := rfl instance instAddCommMonoidWithOne : AddCommMonoidWithOne (A ⊗[R] B) where natCast n := n ⊗ₜ 1 natCast_zero := by simp natCast_succ n := by simp [add_tmul, one_def] add_comm := add_comm theorem natCast_def (n : ℕ) : (n : A ⊗[R] B) = (n : A) ⊗ₜ (1 : B) := rfl theorem natCast_def' (n : ℕ) : (n : A ⊗[R] B) = (1 : A) ⊗ₜ (n : B) := by rw [natCast_def, ← nsmul_one, smul_tmul, nsmul_one] end AddCommMonoidWithOne section NonUnitalNonAssocSemiring variable [CommSemiring R] variable [NonUnitalNonAssocSemiring A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] variable [NonUnitalNonAssocSemiring B] [Module R B] [SMulCommClass R B B] [IsScalarTower R B B] /-- (Implementation detail) The multiplication map on `A ⊗[R] B`, as an `R`-bilinear map. -/ @[irreducible] def mul : A ⊗[R] B →ₗ[R] A ⊗[R] B →ₗ[R] A ⊗[R] B := TensorProduct.map₂ (LinearMap.mul R A) (LinearMap.mul R B) unseal mul in @[simp] theorem mul_apply (a₁ a₂ : A) (b₁ b₂ : B) : mul (a₁ ⊗ₜ[R] b₁) (a₂ ⊗ₜ[R] b₂) = (a₁ * a₂) ⊗ₜ[R] (b₁ * b₂) := rfl -- providing this instance separately makes some downstream code substantially faster instance instMul : Mul (A ⊗[R] B) where mul a b := mul a b unseal mul in @[simp] theorem tmul_mul_tmul (a₁ a₂ : A) (b₁ b₂ : B) : a₁ ⊗ₜ[R] b₁ * a₂ ⊗ₜ[R] b₂ = (a₁ * a₂) ⊗ₜ[R] (b₁ * b₂) := rfl unseal mul in theorem _root_.SemiconjBy.tmul {a₁ a₂ a₃ : A} {b₁ b₂ b₃ : B} (ha : SemiconjBy a₁ a₂ a₃) (hb : SemiconjBy b₁ b₂ b₃) : SemiconjBy (a₁ ⊗ₜ[R] b₁) (a₂ ⊗ₜ[R] b₂) (a₃ ⊗ₜ[R] b₃) := congr_arg₂ (· ⊗ₜ[R] ·) ha.eq hb.eq nonrec theorem _root_.Commute.tmul {a₁ a₂ : A} {b₁ b₂ : B} (ha : Commute a₁ a₂) (hb : Commute b₁ b₂) : Commute (a₁ ⊗ₜ[R] b₁) (a₂ ⊗ₜ[R] b₂) := ha.tmul hb instance instNonUnitalNonAssocSemiring : NonUnitalNonAssocSemiring (A ⊗[R] B) where left_distrib a b c := by simp [HMul.hMul, Mul.mul] right_distrib a b c := by simp [HMul.hMul, Mul.mul] zero_mul a := by simp [HMul.hMul, Mul.mul] mul_zero a := by simp [HMul.hMul, Mul.mul] -- we want `isScalarTower_right` to take priority since it's better for unification elsewhere instance (priority := 100) isScalarTower_right [Monoid S] [DistribMulAction S A] [IsScalarTower S A A] [SMulCommClass R S A] : IsScalarTower S (A ⊗[R] B) (A ⊗[R] B) where smul_assoc r x y := by change r • x * y = r • (x * y) induction y with | zero => simp [smul_zero] | tmul a b => induction x with | zero => simp [smul_zero] | tmul a' b' => dsimp rw [TensorProduct.smul_tmul', TensorProduct.smul_tmul', tmul_mul_tmul, smul_mul_assoc] | add x y hx hy => simp [smul_add, add_mul _, *] | add x y hx hy => simp [smul_add, mul_add _, *] -- we want `Algebra.to_smulCommClass` to take priority since it's better for unification elsewhere instance (priority := 100) sMulCommClass_right [Monoid S] [DistribMulAction S A] [SMulCommClass S A A] [SMulCommClass R S A] : SMulCommClass S (A ⊗[R] B) (A ⊗[R] B) where smul_comm r x y := by change r • (x * y) = x * r • y induction y with | zero => simp [smul_zero] | tmul a b => induction x with | zero => simp [smul_zero] | tmul a' b' => dsimp rw [TensorProduct.smul_tmul', TensorProduct.smul_tmul', tmul_mul_tmul, mul_smul_comm] | add x y hx hy => simp [smul_add, add_mul _, *] | add x y hx hy => simp [smul_add, mul_add _, *] end NonUnitalNonAssocSemiring section NonAssocSemiring variable [CommSemiring R] variable [NonAssocSemiring A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] variable [NonAssocSemiring B] [Module R B] [SMulCommClass R B B] [IsScalarTower R B B] protected theorem one_mul (x : A ⊗[R] B) : mul (1 ⊗ₜ 1) x = x := by refine TensorProduct.induction_on x ?_ ?_ ?_ <;> simp +contextual protected theorem mul_one (x : A ⊗[R] B) : mul x (1 ⊗ₜ 1) = x := by refine TensorProduct.induction_on x ?_ ?_ ?_ <;> simp +contextual instance instNonAssocSemiring : NonAssocSemiring (A ⊗[R] B) where one_mul := Algebra.TensorProduct.one_mul mul_one := Algebra.TensorProduct.mul_one toNonUnitalNonAssocSemiring := instNonUnitalNonAssocSemiring __ := instAddCommMonoidWithOne end NonAssocSemiring section NonUnitalSemiring variable [CommSemiring R] variable [NonUnitalSemiring A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] variable [NonUnitalSemiring B] [Module R B] [SMulCommClass R B B] [IsScalarTower R B B] unseal mul in protected theorem mul_assoc (x y z : A ⊗[R] B) : mul (mul x y) z = mul x (mul y z) := by -- restate as an equality of morphisms so that we can use `ext` suffices LinearMap.llcomp R _ _ _ mul ∘ₗ mul = (LinearMap.llcomp R _ _ _ LinearMap.lflip.toLinearMap <| LinearMap.llcomp R _ _ _ mul.flip ∘ₗ mul).flip by exact DFunLike.congr_fun (DFunLike.congr_fun (DFunLike.congr_fun this x) y) z ext xa xb ya yb za zb exact congr_arg₂ (· ⊗ₜ ·) (mul_assoc xa ya za) (mul_assoc xb yb zb) instance instNonUnitalSemiring : NonUnitalSemiring (A ⊗[R] B) where mul_assoc := Algebra.TensorProduct.mul_assoc end NonUnitalSemiring section Semiring variable [CommSemiring R] variable [Semiring A] [Algebra R A] variable [Semiring B] [Algebra R B] variable [Semiring C] [Algebra R C] instance instSemiring : Semiring (A ⊗[R] B) where left_distrib a b c := by simp [HMul.hMul, Mul.mul] right_distrib a b c := by simp [HMul.hMul, Mul.mul] zero_mul a := by simp [HMul.hMul, Mul.mul] mul_zero a := by simp [HMul.hMul, Mul.mul] mul_assoc := Algebra.TensorProduct.mul_assoc one_mul := Algebra.TensorProduct.one_mul mul_one := Algebra.TensorProduct.mul_one natCast_zero := AddMonoidWithOne.natCast_zero natCast_succ := AddMonoidWithOne.natCast_succ @[simp] theorem tmul_pow (a : A) (b : B) (k : ℕ) : a ⊗ₜ[R] b ^ k = (a ^ k) ⊗ₜ[R] (b ^ k) := by induction k with | zero => simp [one_def] | succ k ih => simp [pow_succ, ih] /-- The ring morphism `A →+* A ⊗[R] B` sending `a` to `a ⊗ₜ 1`. -/ @[simps] def includeLeftRingHom : A →+* A ⊗[R] B where toFun a := a ⊗ₜ 1 map_zero' := by simp map_add' := by simp [add_tmul] map_one' := rfl map_mul' := by simp variable [CommSemiring S] [Algebra S A] instance leftAlgebra [SMulCommClass R S A] : Algebra S (A ⊗[R] B) := { commutes' := fun r x => by dsimp only [RingHom.toFun_eq_coe, RingHom.comp_apply, includeLeftRingHom_apply] rw [algebraMap_eq_smul_one, ← smul_tmul', ← one_def, mul_smul_comm, smul_mul_assoc, mul_one, one_mul] smul_def' := fun r x => by dsimp only [RingHom.toFun_eq_coe, RingHom.comp_apply, includeLeftRingHom_apply] rw [algebraMap_eq_smul_one, ← smul_tmul', smul_mul_assoc, ← one_def, one_mul] algebraMap := TensorProduct.includeLeftRingHom.comp (algebraMap S A) } lemma algebraMap_def [SMulCommClass R S A] : algebraMap S (A ⊗[R] B) = includeLeftRingHom.comp (algebraMap S A) := rfl example : (Semiring.toNatAlgebra : Algebra ℕ (ℕ ⊗[ℕ] B)) = leftAlgebra := rfl -- This is for the `undergrad.yaml` list. /-- The tensor product of two `R`-algebras is an `R`-algebra. -/ instance instAlgebra : Algebra R (A ⊗[R] B) := inferInstance @[simp] theorem algebraMap_apply [SMulCommClass R S A] (r : S) : algebraMap S (A ⊗[R] B) r = (algebraMap S A) r ⊗ₜ 1 := rfl theorem algebraMap_apply' (r : R) : algebraMap R (A ⊗[R] B) r = 1 ⊗ₜ algebraMap R B r := by rw [algebraMap_apply, Algebra.algebraMap_eq_smul_one, Algebra.algebraMap_eq_smul_one, smul_tmul] /-- The `R`-algebra morphism `A →ₐ[R] A ⊗[R] B` sending `a` to `a ⊗ₜ 1`. -/ def includeLeft [SMulCommClass R S A] : A →ₐ[S] A ⊗[R] B := { includeLeftRingHom with commutes' := by simp } @[simp] theorem includeLeft_apply [SMulCommClass R S A] (a : A) : (includeLeft : A →ₐ[S] A ⊗[R] B) a = a ⊗ₜ 1 := rfl /-- The algebra morphism `B →ₐ[R] A ⊗[R] B` sending `b` to `1 ⊗ₜ b`. -/ def includeRight : B →ₐ[R] A ⊗[R] B where toFun b := 1 ⊗ₜ b map_zero' := by simp map_add' := by simp [tmul_add] map_one' := rfl map_mul' := by simp commutes' r := by simp only [algebraMap_apply'] @[simp] theorem includeRight_apply (b : B) : (includeRight : B →ₐ[R] A ⊗[R] B) b = 1 ⊗ₜ b := rfl theorem includeLeftRingHom_comp_algebraMap : (includeLeftRingHom.comp (algebraMap R A) : R →+* A ⊗[R] B) = includeRight.toRingHom.comp (algebraMap R B) := by ext simp section ext variable [Algebra R S] [Algebra S C] [IsScalarTower R S A] [IsScalarTower R S C] /-- A version of `TensorProduct.ext` for `AlgHom`. Using this as the `@[ext]` lemma instead of `Algebra.TensorProduct.ext'` allows `ext` to apply lemmas specific to `A →ₐ[S] _` and `B →ₐ[R] _`; notably this allows recursion into nested tensor products of algebras. See note [partially-applied ext lemmas]. -/ @[ext high] theorem ext ⦃f g : (A ⊗[R] B) →ₐ[S] C⦄ (ha : f.comp includeLeft = g.comp includeLeft) (hb : (f.restrictScalars R).comp includeRight = (g.restrictScalars R).comp includeRight) : f = g := by apply AlgHom.toLinearMap_injective ext a b have := congr_arg₂ HMul.hMul (AlgHom.congr_fun ha a) (AlgHom.congr_fun hb b) dsimp at * rwa [← map_mul, ← map_mul, tmul_mul_tmul, one_mul, mul_one] at this theorem ext' {g h : A ⊗[R] B →ₐ[S] C} (H : ∀ a b, g (a ⊗ₜ b) = h (a ⊗ₜ b)) : g = h := ext (AlgHom.ext fun _ => H _ _) (AlgHom.ext fun _ => H _ _) end ext end Semiring section AddCommGroupWithOne variable [CommSemiring R] variable [AddCommGroupWithOne A] [Module R A] variable [AddCommMonoidWithOne B] [Module R B] instance instAddCommGroupWithOne : AddCommGroupWithOne (A ⊗[R] B) where toAddCommGroup := TensorProduct.addCommGroup __ := instAddCommMonoidWithOne intCast z := z ⊗ₜ (1 : B) intCast_ofNat n := by simp [natCast_def] intCast_negSucc n := by simp [natCast_def, add_tmul, neg_tmul, one_def] theorem intCast_def (z : ℤ) : (z : A ⊗[R] B) = (z : A) ⊗ₜ (1 : B) := rfl end AddCommGroupWithOne section NonUnitalNonAssocRing variable [CommSemiring R] variable [NonUnitalNonAssocRing A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] variable [NonUnitalNonAssocSemiring B] [Module R B] [SMulCommClass R B B] [IsScalarTower R B B] instance instNonUnitalNonAssocRing : NonUnitalNonAssocRing (A ⊗[R] B) where toAddCommGroup := TensorProduct.addCommGroup __ := instNonUnitalNonAssocSemiring end NonUnitalNonAssocRing section NonAssocRing variable [CommSemiring R] variable [NonAssocRing A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] variable [NonAssocSemiring B] [Module R B] [SMulCommClass R B B] [IsScalarTower R B B] instance instNonAssocRing : NonAssocRing (A ⊗[R] B) where toAddCommGroup := TensorProduct.addCommGroup __ := instNonAssocSemiring __ := instAddCommGroupWithOne end NonAssocRing section NonUnitalRing variable [CommSemiring R] variable [NonUnitalRing A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] variable [NonUnitalSemiring B] [Module R B] [SMulCommClass R B B] [IsScalarTower R B B] instance instNonUnitalRing : NonUnitalRing (A ⊗[R] B) where toAddCommGroup := TensorProduct.addCommGroup __ := instNonUnitalSemiring end NonUnitalRing section CommSemiring variable [CommSemiring R] variable [CommSemiring A] [Algebra R A] variable [CommSemiring B] [Algebra R B] instance instCommSemiring : CommSemiring (A ⊗[R] B) where toSemiring := inferInstance mul_comm x y := by refine TensorProduct.induction_on x ?_ ?_ ?_ · simp · intro a₁ b₁ refine TensorProduct.induction_on y ?_ ?_ ?_ · simp · intro a₂ b₂ simp [mul_comm] · intro a₂ b₂ ha hb simp [mul_add, add_mul, ha, hb] · intro x₁ x₂ h₁ h₂ simp [mul_add, add_mul, h₁, h₂] end CommSemiring section Ring variable [CommSemiring R] variable [Ring A] [Algebra R A] variable [Semiring B] [Algebra R B] instance instRing : Ring (A ⊗[R] B) where toSemiring := instSemiring __ := TensorProduct.addCommGroup __ := instNonAssocRing theorem intCast_def' {B} [Ring B] [Algebra R B] (z : ℤ) : (z : A ⊗[R] B) = (1 : A) ⊗ₜ (z : B) := by rw [intCast_def, ← zsmul_one, smul_tmul, zsmul_one] -- verify there are no diamonds example : (instRing : Ring (A ⊗[R] B)).toAddCommGroup = addCommGroup := by with_reducible_and_instances rfl -- fails at `with_reducible_and_instances rfl` https://github.com/leanprover-community/mathlib4/issues/10906 example : (Ring.toIntAlgebra _ : Algebra ℤ (ℤ ⊗[ℤ] A)) = leftAlgebra := rfl end Ring section CommRing variable [CommSemiring R] variable [CommRing A] [Algebra R A] variable [CommSemiring B] [Algebra R B] instance instCommRing : CommRing (A ⊗[R] B) := { toRing := inferInstance mul_comm := mul_comm } end CommRing section RightAlgebra variable [CommSemiring R] variable [Semiring A] [Algebra R A] variable [CommSemiring B] [Algebra R B] /-- `S ⊗[R] T` has a `T`-algebra structure. This is not a global instance or else the action of `S` on `S ⊗[R] S` would be ambiguous. -/ abbrev rightAlgebra : Algebra B (A ⊗[R] B) := includeRight.toRingHom.toAlgebra' fun b x => by suffices LinearMap.mulLeft R (includeRight b) = LinearMap.mulRight R (includeRight b) from congr($this x) ext xa xb simp [mul_comm] attribute [local instance] TensorProduct.rightAlgebra lemma algebraMap_eq_includeRight : letI := rightAlgebra (R := R) (A := A) (B := B) algebraMap B (A ⊗[R] B) = includeRight (R := R) (A := A) (B := B) := rfl instance right_isScalarTower : IsScalarTower R B (A ⊗[R] B) := IsScalarTower.of_algebraMap_eq fun r => (Algebra.TensorProduct.includeRight.commutes r).symm lemma right_algebraMap_apply (b : B) : algebraMap B (A ⊗[R] B) b = 1 ⊗ₜ b := rfl instance : SMulCommClass A B (A ⊗[R] B) where smul_comm a b x := x.induction_on (by simp) (fun _ _ ↦ by simp [Algebra.smul_def, right_algebraMap_apply, smul_tmul']) fun _ _ h₁ h₂ ↦ by simpa using congr($h₁ + $h₂) instance : SMulCommClass B A (A ⊗[R] B) := .symm .. end RightAlgebra /-- Verify that typeclass search finds the ring structure on `A ⊗[ℤ] B` when `A` and `B` are merely rings, by treating both as `ℤ`-algebras. -/ example [Ring A] [Ring B] : Ring (A ⊗[ℤ] B) := by infer_instance /-- Verify that typeclass search finds the CommRing structure on `A ⊗[ℤ] B` when `A` and `B` are merely `CommRing`s, by treating both as `ℤ`-algebras. -/ example [CommRing A] [CommRing B] : CommRing (A ⊗[ℤ] B) := by infer_instance variable (R A B) in lemma closure_range_union_range_eq_top [CommRing R] [Ring A] [Ring B] [Algebra R A] [Algebra R B] : Subring.closure (Set.range (Algebra.TensorProduct.includeLeft : A →ₐ[R] A ⊗[R] B) ∪ Set.range Algebra.TensorProduct.includeRight) = ⊤ := by rw [← top_le_iff] rintro x - induction x with | zero => exact zero_mem _ | tmul x y => convert_to (Algebra.TensorProduct.includeLeftRingHom (R := R) x) * (Algebra.TensorProduct.includeRight y) ∈ _ · simp · exact mul_mem (Subring.subset_closure (.inl ⟨x, rfl⟩)) (Subring.subset_closure (.inr ⟨_, rfl⟩)) | add x y _ _ => exact add_mem ‹_› ‹_› variable [CommSemiring R] [CommSemiring S] [Algebra R S] /-- If `M` is a `B`-module that is also an `A`-module, the canonical map `M →ₗ[A] B ⊗[A] M` is injective. -/ lemma mk_one_injective_of_isScalarTower (M : Type*) [AddCommMonoid M] [Module R M] [Module S M] [IsScalarTower R S M] : Function.Injective (TensorProduct.mk R S M 1) := by apply Function.RightInverse.injective (g := LinearMap.liftBaseChange S LinearMap.id) intro m simp end TensorProduct end Algebra lemma Algebra.baseChange_lmul {R B : Type*} [CommSemiring R] [Semiring B] [Algebra R B] {A : Type*} [CommSemiring A] [Algebra R A] (f : B) : (Algebra.lmul R B f).baseChange A = Algebra.lmul A (A ⊗[R] B) (1 ⊗ₜ f) := by ext i simp namespace TensorProduct.Algebra variable {R A B M : Type*} variable [CommSemiring R] [AddCommMonoid M] [Module R M] variable [Semiring A] [Semiring B] [Module A M] [Module B M] variable [Algebra R A] [Algebra R B] variable [IsScalarTower R A M] [IsScalarTower R B M] /-- An auxiliary definition, used for constructing the `Module (A ⊗[R] B) M` in `TensorProduct.Algebra.module` below. -/ def moduleAux : A ⊗[R] B →ₗ[R] M →ₗ[R] M := TensorProduct.lift { toFun := fun a => a • (Algebra.lsmul R R M : B →ₐ[R] Module.End R M).toLinearMap map_add' := fun r t => by ext simp only [add_smul, LinearMap.add_apply] map_smul' := fun n r => by ext simp only [RingHom.id_apply, LinearMap.smul_apply, smul_assoc] } theorem moduleAux_apply (a : A) (b : B) (m : M) : moduleAux (a ⊗ₜ[R] b) m = a • b • m := rfl variable [SMulCommClass A B M] /-- If `M` is a representation of two different `R`-algebras `A` and `B` whose actions commute, then it is a representation the `R`-algebra `A ⊗[R] B`. An important example arises from a semiring `S`; allowing `S` to act on itself via left and right multiplication, the roles of `R`, `A`, `B`, `M` are played by `ℕ`, `S`, `Sᵐᵒᵖ`, `S`. This example is important because a submodule of `S` as a `Module` over `S ⊗[ℕ] Sᵐᵒᵖ` is a two-sided ideal. NB: This is not an instance because in the case `B = A` and `M = A ⊗[R] A` we would have a diamond of `smul` actions. Furthermore, this would not be a mere definitional diamond but a true mathematical diamond in which `A ⊗[R] A` had two distinct scalar actions on itself: one from its multiplication, and one from this would-be instance. Arguably we could live with this but in any case the real fix is to address the ambiguity in notation, probably along the lines outlined here: https://leanprover.zulipchat.com/#narrow/stream/144837-PR-reviews/topic/.234773.20base.20change/near/240929258 -/ protected def module : Module (A ⊗[R] B) M where smul x m := moduleAux x m zero_smul m := by simp only [(· • ·), map_zero, LinearMap.zero_apply] smul_zero x := by simp only [(· • ·), map_zero] smul_add x m₁ m₂ := by simp only [(· • ·), map_add] add_smul x y m := by simp only [(· • ·), map_add, LinearMap.add_apply] one_smul m := by -- Porting note: was one `simp only`, not two simp only [(· • ·), Algebra.TensorProduct.one_def] simp only [moduleAux_apply, one_smul] mul_smul x y m := by refine TensorProduct.induction_on x ?_ ?_ ?_ <;> refine TensorProduct.induction_on y ?_ ?_ ?_ · simp only [(· • ·), mul_zero, map_zero, LinearMap.zero_apply] · intro a b simp only [(· • ·), zero_mul, map_zero, LinearMap.zero_apply] · intro z w _ _ simp only [(· • ·), zero_mul, map_zero, LinearMap.zero_apply] · intro a b simp only [(· • ·), mul_zero, map_zero, LinearMap.zero_apply] · intro a₁ b₁ a₂ b₂ -- Porting note: was one `simp only`, not two simp only [(· • ·), Algebra.TensorProduct.tmul_mul_tmul] simp only [moduleAux_apply, mul_smul, smul_comm a₁ b₂] · intro z w hz hw a b -- Porting note: was one `simp only`, but random stuff doesn't work simp only [(· • ·)] at hz hw ⊢ simp only [moduleAux_apply, mul_add, LinearMap.map_add, LinearMap.add_apply, moduleAux_apply, hz, hw] · intro z w _ _ simp only [(· • ·), mul_zero, map_zero, LinearMap.zero_apply] · intro a b z w hz hw simp only [(· • ·)] at hz hw ⊢ simp only [LinearMap.map_add, add_mul, LinearMap.add_apply, hz, hw] · intro u v _ _ z w hz hw simp only [(· • ·)] at hz hw ⊢ simp only [add_mul, LinearMap.map_add, LinearMap.add_apply, hz, hw, add_add_add_comm] attribute [local instance] TensorProduct.Algebra.module theorem smul_def (a : A) (b : B) (m : M) : a ⊗ₜ[R] b • m = a • b • m := rfl section Lemmas theorem linearMap_comp_mul' : Algebra.linearMap R (A ⊗[R] B) ∘ₗ LinearMap.mul' R R = map (Algebra.linearMap R A) (Algebra.linearMap R B) := by ext simp only [AlgebraTensorModule.curry_apply, curry_apply, LinearMap.coe_restrictScalars, map_tmul, Algebra.linearMap_apply, map_one, LinearMap.coe_comp, Function.comp_apply, LinearMap.mul'_apply, mul_one, Algebra.TensorProduct.one_def] end Lemmas end TensorProduct.Algebra open LinearMap in lemma Submodule.map_range_rTensor_subtype_lid {R Q} [CommSemiring R] [AddCommMonoid Q] [Module R Q] {I : Submodule R R} : (range <| rTensor Q I.subtype).map (TensorProduct.lid R Q) = I • ⊤ := by rw [← map_top, ← map_coe_toLinearMap, ← Submodule.map_comp, map_top] refine le_antisymm ?_ fun q h ↦ Submodule.smul_induction_on h (fun r hr q _ ↦ ⟨⟨r, hr⟩ ⊗ₜ q, by simp⟩) (by simp +contextual [add_mem]) rintro _ ⟨t, rfl⟩ exact t.induction_on (by simp) (by simp +contextual [Submodule.smul_mem_smul]) (by simp +contextual [add_mem]) section variable {R M S T : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] [Semiring S] [Algebra R S] [Ring T] [Algebra R T] variable (R S M) in theorem TensorProduct.mk_surjective (h : Function.Surjective (algebraMap R S)) : Function.Surjective (TensorProduct.mk R S M 1) := by rw [← LinearMap.range_eq_top, ← top_le_iff, ← span_tmul_eq_top, Submodule.span_le] rintro _ ⟨x, y, rfl⟩ obtain ⟨x, rfl⟩ := h x rw [Algebra.algebraMap_eq_smul_one, smul_tmul] exact ⟨x • y, rfl⟩ variable (S) in lemma TensorProduct.flip_mk_surjective (h : Function.Surjective (algebraMap R T)) : Function.Surjective ((TensorProduct.mk R S T).flip 1) := by rw [← LinearMap.range_eq_top, ← top_le_iff, ← span_tmul_eq_top, Submodule.span_le] rintro _ ⟨s, t, rfl⟩ obtain ⟨r, rfl⟩ := h t rw [Algebra.algebraMap_eq_smul_one, ← smul_tmul] exact ⟨r • s, rfl⟩ variable (T) in lemma Algebra.TensorProduct.includeRight_surjective (h : Function.Surjective (algebraMap R S)) : Function.Surjective (includeRight : T →ₐ[R] S ⊗[R] T) := TensorProduct.mk_surjective _ _ _ h lemma Algebra.TensorProduct.includeLeft_surjective (S A : Type*) [CommSemiring S] [Semiring A] [Algebra S A] [Algebra R A] [SMulCommClass R S A] (h : Function.Surjective (algebraMap R T)) : Function.Surjective (includeLeft : A →ₐ[S] A ⊗[R] T) := TensorProduct.flip_mk_surjective _ h end variable {R A B : Type*} [CommSemiring R] [NonUnitalNonAssocSemiring A] [NonUnitalNonAssocSemiring B] [Module R A] [Module R B] [SMulCommClass R A A] [SMulCommClass R B B] [IsScalarTower R A A] [IsScalarTower R B B] @[simp] theorem TensorProduct.Algebra.mul'_comp_tensorTensorTensorComm : LinearMap.mul' R (A ⊗[R] B) ∘ₗ tensorTensorTensorComm R A A B B = map (LinearMap.mul' R A) (LinearMap.mul' R B) := by ext simp lemma LinearMap.mul'_tensor : mul' R (A ⊗[R] B) = map (mul' R A) (mul' R B) ∘ₗ tensorTensorTensorComm R A B A B := ext_fourfold' <| by simp lemma LinearMap.mulLeft_tmul (a : A) (b : B) : mulLeft R (a ⊗ₜ[R] b) = map (mulLeft R a) (mulLeft R b) := by ext; simp lemma LinearMap.mulRight_tmul (a : A) (b : B) : mulRight R (a ⊗ₜ[R] b) = map (mulRight R a) (mulRight R b) := by ext; simp namespace TensorProduct variable [StarRing R] [StarRing A] [StarRing B] [StarModule R A] [StarModule R B] noncomputable instance : StarMul (A ⊗[R] B) where star_mul x y := x.induction_on (by simp) (fun _ _ ↦ y.induction_on (by simp) fun _ _ ↦ by simp fun _ _ h₁ h₂ ↦ by simp [add_mul, mul_add, h₁, h₂]) fun _ _ h₁ h₂ ↦ by simp [add_mul, mul_add, h₁, h₂] noncomputable instance : StarRing (A ⊗[R] B) where star_add := by simp end TensorProduct
.lake/packages/mathlib/Mathlib/RingTheory/TensorProduct/Quotient.lean
import Mathlib.LinearAlgebra.TensorProduct.Quotient import Mathlib.RingTheory.Ideal.Quotient.Operations import Mathlib.RingTheory.TensorProduct.Basic /-! # Interaction between quotients and tensor products for algebras This file proves algebra analogs of the isomorphisms in `Mathlib/LinearAlgebra/TensorProduct/Quotient.lean`. ## Main results - `Algebra.TensorProduct.quotIdealMapEquivTensorQuot`: `B ⧸ (I.map <| algebraMap A B) ≃ₐ[B] B ⊗[A] (A ⧸ I)` -/ open TensorProduct namespace Algebra.TensorProduct variable {A : Type*} (B : Type*) [CommRing A] [CommRing B] [Algebra A B] (I : Ideal A) private noncomputable def quotIdealMapEquivTensorQuotAux : (B ⧸ (I.map <| algebraMap A B)) ≃ₗ[B] B ⊗[A] (A ⧸ I) := AddEquiv.toLinearEquiv (TensorProduct.tensorQuotEquivQuotSMul B I ≪≫ₗ Submodule.quotEquivOfEq _ _ (Ideal.smul_top_eq_map I) ≪≫ₗ Submodule.Quotient.restrictScalarsEquiv A (I.map <| algebraMap A B)).symm <| by intro c x obtain ⟨u, rfl⟩ := Ideal.Quotient.mk_surjective x rfl private lemma quotIdealMapEquivTensorQuotAux_mk (b : B) : (quotIdealMapEquivTensorQuotAux B I) b = b ⊗ₜ[A] 1 := rfl /-- `B ⊗[A] (A ⧸ I)` is isomorphic as an `A`-algebra to `B ⧸ I B`. -/ noncomputable def quotIdealMapEquivTensorQuot : (B ⧸ (I.map <| algebraMap A B)) ≃ₐ[B] B ⊗[A] (A ⧸ I) := AlgEquiv.ofLinearEquiv (quotIdealMapEquivTensorQuotAux B I) rfl (fun x y ↦ by obtain ⟨u, rfl⟩ := Ideal.Quotient.mk_surjective x obtain ⟨v, rfl⟩ := Ideal.Quotient.mk_surjective y simp_rw [← map_mul, quotIdealMapEquivTensorQuotAux_mk] simp) @[simp] lemma quotIdealMapEquivTensorQuot_mk (b : B) : quotIdealMapEquivTensorQuot B I b = b ⊗ₜ[A] 1 := rfl @[simp] lemma quotIdealMapEquivTensorQuot_symm_tmul (b : B) (a : A) : (quotIdealMapEquivTensorQuot B I).symm (b ⊗ₜ[A] a) = Submodule.Quotient.mk (a • b) := rfl end Algebra.TensorProduct
.lake/packages/mathlib/Mathlib/RingTheory/TensorProduct/MonoidAlgebra.lean
import Mathlib.Algebra.MonoidAlgebra.Basic import Mathlib.RingTheory.IsTensorProduct /-! # Monoid algebras commute with base change In this file we show that monoid algebras are stable under pushout. ## TODO Additivise -/ noncomputable section open TensorProduct namespace MonoidAlgebra variable {R M S A B : Type*} [CommSemiring R] [CommSemiring S] [Algebra R S] [CommMonoid M] variable [CommSemiring A] [Algebra R A] [CommSemiring B] [Algebra R B] variable (R A B) in /-- The base change of `MonoidAlgebra B M` to an `R`-algebra `A` is isomorphic to `MonoidAlgebra (A ⊗[R] B) M` as an `A`-algebra. -/ noncomputable def tensorEquiv : A ⊗[R] MonoidAlgebra B M ≃ₐ[A] MonoidAlgebra (A ⊗[R] B) M := by refine .ofAlgHom (Algebra.TensorProduct.lift ((IsScalarTower.toAlgHom A (A ⊗[R] B) _).comp Algebra.TensorProduct.includeLeft) (mapRangeAlgHom _ Algebra.TensorProduct.includeRight) fun p n ↦ .all ..) (MonoidAlgebra.liftNCAlgHom (Algebra.TensorProduct.map (.id _ _) singleOneAlgHom) (Algebra.TensorProduct.includeRight.toMonoidHom.comp (of B M)) fun _ _ ↦ .all ..) ?_ ?_ · apply AlgHom.toLinearMap_injective ext simp · ext : 1 · ext apply AlgHom.toLinearMap_injective ext simp @[simp] lemma tensorEquiv_tmul (a : A) (p : MonoidAlgebra B M) : tensorEquiv R A B (a ⊗ₜ p) = a • mapRangeAlgHom M Algebra.TensorProduct.includeRight p := by simp [tensorEquiv, Algebra.smul_def] @[simp] lemma tensorEquiv_symm_single (m : M) (a : A) (b : B) : (tensorEquiv R A B).symm (single m (a ⊗ₜ b)) = a ⊗ₜ single m b := by simp [tensorEquiv] variable (R A) in /-- The base change of `MonoidAlgebra R M` to an `R`-algebra `A` is isomorphic to `MonoidAlgebra A M` as an `A`-algebra. -/ noncomputable def scalarTensorEquiv : A ⊗[R] MonoidAlgebra R M ≃ₐ[A] MonoidAlgebra A M := (tensorEquiv ..).trans <| mapRangeAlgEquiv A M <| Algebra.TensorProduct.rid R A A @[simp] lemma scalarTensorEquiv_tmul (a : A) (p : MonoidAlgebra R M) : scalarTensorEquiv R A (a ⊗ₜ p) = a • mapRangeAlgHom M (Algebra.ofId ..) p := by ext; simp [scalarTensorEquiv]; simp [Algebra.smul_def, Algebra.commutes] @[simp] lemma scalarTensorEquiv_symm_single (m : M) (a : A) : (scalarTensorEquiv R A).symm (single m a) = a ⊗ₜ single m 1 := by simp [scalarTensorEquiv] attribute [local instance] algebraMonoidAlgebra in instance [Algebra S B] [Algebra A B] [Algebra R B] [IsScalarTower R A B] [IsScalarTower R S B] [Algebra.IsPushout R S A B] : Algebra.IsPushout R S (MonoidAlgebra A M) (MonoidAlgebra B M) where out := .of_equiv ((tensorEquiv (M := M) R S A).trans <| mapRangeAlgEquiv S M <| Algebra.IsPushout.equiv R S A B).toLinearEquiv fun x ↦ by induction x using Finsupp.induction_linear <;> simp_all [Algebra.IsPushout.equiv_tmul] attribute [local instance] algebraMonoidAlgebra in instance [Algebra S B] [Algebra A B] [Algebra R B] [IsScalarTower R A B] [IsScalarTower R S B] [Algebra.IsPushout R A S B] : Algebra.IsPushout R (MonoidAlgebra A M) S (MonoidAlgebra B M) := have : Algebra.IsPushout R S A B := .symm ‹_› .symm inferInstance end MonoidAlgebra end
.lake/packages/mathlib/Mathlib/RingTheory/TensorProduct/MvPolynomial.lean
import Mathlib.LinearAlgebra.DirectSum.Finsupp import Mathlib.Algebra.MvPolynomial.Eval import Mathlib.RingTheory.TensorProduct.Basic import Mathlib.Algebra.MvPolynomial.Equiv import Mathlib.RingTheory.IsTensorProduct /-! # Tensor Product of (multivariate) polynomial rings Let `Semiring R`, `Algebra R S` and `Module R N`. * `MvPolynomial.rTensor` gives the linear equivalence `MvPolynomial σ S ⊗[R] N ≃ₗ[R] (σ →₀ ℕ) →₀ (S ⊗[R] N)` characterized, for `p : MvPolynomial σ S`, `n : N` and `d : σ →₀ ℕ`, by `rTensor (p ⊗ₜ[R] n) d = (coeff d p) ⊗ₜ[R] n` * `MvPolynomial.scalarRTensor` gives the linear equivalence `MvPolynomial σ R ⊗[R] N ≃ₗ[R] (σ →₀ ℕ) →₀ N` such that `MvPolynomial.scalarRTensor (p ⊗ₜ[R] n) d = coeff d p • n` for `p : MvPolynomial σ R`, `n : N` and `d : σ →₀ ℕ`, by * `MvPolynomial.rTensorAlgHom`, the algebra morphism from the tensor product of a polynomial algebra by an algebra to a polynomial algebra * `MvPolynomial.rTensorAlgEquiv`, `MvPolynomial.scalarRTensorAlgEquiv`, the tensor product of a polynomial algebra by an algebra is algebraically equivalent to a polynomial algebra ## TODO : * `MvPolynomial.rTensor` could be phrased in terms of `AddMonoidAlgebra`, and `MvPolynomial.rTensor` then has `smul` by the polynomial algebra. * `MvPolynomial.rTensorAlgHom` and `MvPolynomial.scalarRTensorAlgEquiv` are morphisms for the algebra structure by `MvPolynomial σ R`. -/ universe u v noncomputable section namespace MvPolynomial open DirectSum TensorProduct open Set LinearMap Submodule variable {R : Type u} {N : Type v} [CommSemiring R] variable {σ ι : Type*} variable {S : Type*} [CommSemiring S] [Algebra R S] section Module variable [DecidableEq σ] variable [AddCommMonoid N] [Module R N] /-- The tensor product of a polynomial ring by a module is linearly equivalent to a Finsupp of a tensor product -/ noncomputable def rTensor : MvPolynomial σ S ⊗[R] N ≃ₗ[S] (σ →₀ ℕ) →₀ (S ⊗[R] N) := TensorProduct.finsuppLeft' _ _ _ _ _ lemma rTensor_apply_tmul (p : MvPolynomial σ S) (n : N) : rTensor (p ⊗ₜ[R] n) = p.sum (fun i m ↦ Finsupp.single i (m ⊗ₜ[R] n)) := TensorProduct.finsuppLeft_apply_tmul p n lemma rTensor_apply_tmul_apply (p : MvPolynomial σ S) (n : N) (d : σ →₀ ℕ) : rTensor (p ⊗ₜ[R] n) d = (coeff d p) ⊗ₜ[R] n := TensorProduct.finsuppLeft_apply_tmul_apply p n d lemma rTensor_apply_monomial_tmul (e : σ →₀ ℕ) (s : S) (n : N) (d : σ →₀ ℕ) : rTensor (monomial e s ⊗ₜ[R] n) d = if e = d then s ⊗ₜ[R] n else 0 := by simp only [rTensor_apply_tmul_apply, coeff_monomial, ite_tmul] lemma rTensor_apply_X_tmul (s : σ) (n : N) (d : σ →₀ ℕ) : rTensor (X s ⊗ₜ[R] n) d = if Finsupp.single s 1 = d then (1 : S) ⊗ₜ[R] n else 0 := by rw [rTensor_apply_tmul_apply, coeff_X', ite_tmul] lemma rTensor_apply (t : MvPolynomial σ S ⊗[R] N) (d : σ →₀ ℕ) : rTensor t d = ((lcoeff S d).restrictScalars R).rTensor N t := TensorProduct.finsuppLeft_apply t d @[simp] lemma rTensor_symm_apply_single (d : σ →₀ ℕ) (s : S) (n : N) : rTensor.symm (Finsupp.single d (s ⊗ₜ n)) = (monomial d s) ⊗ₜ[R] n := TensorProduct.finsuppLeft_symm_apply_single (R := R) d s n /-- The tensor product of the polynomial algebra by a module is linearly equivalent to a Finsupp of that module -/ noncomputable def scalarRTensor : MvPolynomial σ R ⊗[R] N ≃ₗ[R] (σ →₀ ℕ) →₀ N := TensorProduct.finsuppScalarLeft _ _ _ lemma scalarRTensor_apply_tmul (p : MvPolynomial σ R) (n : N) : scalarRTensor (p ⊗ₜ[R] n) = p.sum (fun i m ↦ Finsupp.single i (m • n)) := TensorProduct.finsuppScalarLeft_apply_tmul p n lemma scalarRTensor_apply_tmul_apply (p : MvPolynomial σ R) (n : N) (d : σ →₀ ℕ) : scalarRTensor (p ⊗ₜ[R] n) d = coeff d p • n := TensorProduct.finsuppScalarLeft_apply_tmul_apply p n d lemma scalarRTensor_apply_monomial_tmul (e : σ →₀ ℕ) (r : R) (n : N) (d : σ →₀ ℕ) : scalarRTensor (monomial e r ⊗ₜ[R] n) d = if e = d then r • n else 0 := by rw [scalarRTensor_apply_tmul_apply, coeff_monomial, ite_smul, zero_smul] lemma scalarRTensor_apply_X_tmul_apply (s : σ) (n : N) (d : σ →₀ ℕ) : scalarRTensor (X s ⊗ₜ[R] n) d = if Finsupp.single s 1 = d then n else 0 := by rw [scalarRTensor_apply_tmul_apply, coeff_X', ite_smul, one_smul, zero_smul] lemma scalarRTensor_symm_apply_single (d : σ →₀ ℕ) (n : N) : scalarRTensor.symm (Finsupp.single d n) = (monomial d 1) ⊗ₜ[R] n := TensorProduct.finsuppScalarLeft_symm_apply_single d n end Module section Algebra variable [CommSemiring N] [Algebra R N] /-- The algebra morphism from a tensor product of a polynomial algebra by an algebra to a polynomial algebra -/ noncomputable def rTensorAlgHom : (MvPolynomial σ S) ⊗[R] N →ₐ[S] MvPolynomial σ (S ⊗[R] N) := Algebra.TensorProduct.lift (mapAlgHom Algebra.TensorProduct.includeLeft) ((IsScalarTower.toAlgHom R (S ⊗[R] N) _).comp Algebra.TensorProduct.includeRight) (fun p n => by simp [commute_iff_eq, algebraMap_eq, mul_comm]) @[simp] lemma coeff_rTensorAlgHom_tmul (p : MvPolynomial σ S) (n : N) (d : σ →₀ ℕ) : coeff d (rTensorAlgHom (p ⊗ₜ[R] n)) = (coeff d p) ⊗ₜ[R] n := by rw [rTensorAlgHom, Algebra.TensorProduct.lift_tmul] rw [AlgHom.coe_comp, IsScalarTower.coe_toAlgHom', Function.comp_apply, Algebra.TensorProduct.includeRight_apply] rw [algebraMap_eq, mul_comm, coeff_C_mul] simp [mapAlgHom, coeff_map] section DecidableEq variable [DecidableEq σ] lemma coeff_rTensorAlgHom_monomial_tmul (e : σ →₀ ℕ) (s : S) (n : N) (d : σ →₀ ℕ) : coeff d (rTensorAlgHom (monomial e s ⊗ₜ[R] n)) = if e = d then s ⊗ₜ[R] n else 0 := by simp [ite_tmul] lemma rTensorAlgHom_toLinearMap : (rTensorAlgHom : MvPolynomial σ S ⊗[R] N →ₐ[S] MvPolynomial σ (S ⊗[R] N)).toLinearMap = rTensor.toLinearMap := by ext d n e dsimp only [AlgebraTensorModule.curry_apply, TensorProduct.curry_apply, LinearMap.coe_restrictScalars, AlgHom.toLinearMap_apply] simp only [coe_comp, Function.comp_apply, AlgebraTensorModule.curry_apply, curry_apply, LinearMap.coe_restrictScalars, AlgHom.toLinearMap_apply] rw [coeff_rTensorAlgHom_tmul] simp only [coeff] exact (finsuppLeft_apply_tmul_apply _ _ _).symm lemma rTensorAlgHom_apply_eq (p : MvPolynomial σ S ⊗[R] N) : rTensorAlgHom (S := S) p = rTensor p := by rw [← AlgHom.toLinearMap_apply, rTensorAlgHom_toLinearMap] rfl /-- The tensor product of a polynomial algebra by an algebra is algebraically equivalent to a polynomial algebra -/ noncomputable def rTensorAlgEquiv : (MvPolynomial σ S) ⊗[R] N ≃ₐ[S] MvPolynomial σ (S ⊗[R] N) := by apply AlgEquiv.ofLinearEquiv rTensor · simp only [Algebra.TensorProduct.one_def] apply symm rw [← LinearEquiv.symm_apply_eq] exact finsuppLeft_symm_apply_single (R := R) (0 : σ →₀ ℕ) (1 : S) (1 : N) · intro x y erw [← rTensorAlgHom_apply_eq (S := S)] simp only [map_mul, rTensorAlgHom_apply_eq] rfl @[simp] lemma rTensorAlgEquiv_apply (x : (MvPolynomial σ S) ⊗[R] N) : rTensorAlgEquiv x = rTensorAlgHom x := by rw [← AlgHom.coe_coe, ← AlgEquiv.toAlgHom_eq_coe] congr 1 ext _ d <;> simpa [rTensorAlgEquiv] using rTensor_apply_tmul_apply _ _ d /-- The tensor product of the polynomial algebra by an algebra is algebraically equivalent to a polynomial algebra with coefficients in that algebra -/ noncomputable def scalarRTensorAlgEquiv : MvPolynomial σ R ⊗[R] N ≃ₐ[R] MvPolynomial σ N := rTensorAlgEquiv.trans (mapAlgEquiv σ (Algebra.TensorProduct.lid R N)) end DecidableEq variable (R) variable (A : Type*) [CommSemiring A] [Algebra R A] /-- Tensoring `MvPolynomial σ R` on the left by an `R`-algebra `A` is algebraically equivalent to `MvPolynomial σ A`. -/ noncomputable def algebraTensorAlgEquiv : A ⊗[R] MvPolynomial σ R ≃ₐ[A] MvPolynomial σ A := AlgEquiv.ofAlgHom (Algebra.TensorProduct.lift (Algebra.ofId A (MvPolynomial σ A)) (MvPolynomial.mapAlgHom <| Algebra.ofId R A) (fun _ _ ↦ Commute.all _ _)) (aeval (fun s ↦ 1 ⊗ₜ X s)) (by ext s; simp) (by ext s; simp) @[simp] lemma algebraTensorAlgEquiv_tmul (a : A) (p : MvPolynomial σ R) : algebraTensorAlgEquiv R A (a ⊗ₜ p) = a • MvPolynomial.map (algebraMap R A) p := by simp [algebraTensorAlgEquiv, Algebra.smul_def] rfl @[simp] lemma algebraTensorAlgEquiv_symm_X (s : σ) : (algebraTensorAlgEquiv R A).symm (X s) = 1 ⊗ₜ X s := by simp [algebraTensorAlgEquiv] @[simp] lemma algebraTensorAlgEquiv_symm_monomial (m : σ →₀ ℕ) (a : A) : (algebraTensorAlgEquiv R A).symm (monomial m a) = a ⊗ₜ monomial m 1 := by apply @Finsupp.induction σ ℕ _ _ m · simp [algebraTensorAlgEquiv] · intro i n f _ _ hfa simp only [algebraTensorAlgEquiv, AlgEquiv.ofAlgHom_symm_apply] at hfa ⊢ simp only [add_comm, monomial_add_single, map_mul, map_pow, aeval_X, Algebra.TensorProduct.tmul_pow, one_pow, hfa] nth_rw 2 [← mul_one a] rw [Algebra.TensorProduct.tmul_mul_tmul] @[simp] lemma algebraTensorAlgEquiv_symm_comp_aeval : (((algebraTensorAlgEquiv (σ := σ) R A).symm.restrictScalars R) : MvPolynomial σ A →ₐ[R] A ⊗[R] MvPolynomial σ R).comp (MvPolynomial.mapAlgHom (R := R) (S₁ := R) (S₂ := A) (Algebra.ofId R A)) = Algebra.TensorProduct.includeRight := by ext simp @[simp] lemma algebraTensorAlgEquiv_symm_map (x : MvPolynomial σ R) : (algebraTensorAlgEquiv R A).symm (map (algebraMap R A) x) = 1 ⊗ₜ x := DFunLike.congr_fun (algebraTensorAlgEquiv_symm_comp_aeval R A) x lemma aeval_one_tmul (f : σ → S) (p : MvPolynomial σ R) : (aeval fun x ↦ (1 ⊗ₜ[R] f x : N ⊗[R] S)) p = 1 ⊗ₜ[R] (aeval f) p := by induction p using MvPolynomial.induction_on with | C a => simp only [algHom_C, Algebra.TensorProduct.algebraMap_apply] rw [← mul_one ((algebraMap R N) a), ← Algebra.smul_def, smul_tmul, Algebra.smul_def, mul_one] | add p q hp hq => simp [hp, hq, tmul_add] | mul_X p i h => simp [h] variable (S σ ι) in /-- `S[X] ⊗[R] R[Y] ≃ S[X, Y]` -/ def tensorEquivSum : MvPolynomial σ S ⊗[R] MvPolynomial ι R ≃ₐ[S] MvPolynomial (σ ⊕ ι) S := ((algebraTensorAlgEquiv _ _).restrictScalars _).trans ((sumAlgEquiv _ _ _).symm.trans (renameEquiv _ (.sumComm ι σ))) variable {R} attribute [local simp] Algebra.smul_def @[simp] lemma tensorEquivSum_X_tmul_one (i) : tensorEquivSum R σ ι S (.X i ⊗ₜ 1) = .X (.inl i) := by simp [tensorEquivSum] @[simp] lemma tensorEquivSum_C_tmul_one (r) : tensorEquivSum R σ ι S (.C r ⊗ₜ 1) = .C r := by simp [tensorEquivSum] @[simp] lemma tensorEquivSum_one_tmul_X (i) : tensorEquivSum R σ ι S (1 ⊗ₜ .X i) = .X (.inr i) := by simp [tensorEquivSum] @[simp] lemma tensorEquivSum_one_tmul_C (r) : tensorEquivSum R σ ι S (1 ⊗ₜ .C r) = .C (algebraMap R S r) := by simp [tensorEquivSum] @[simp] lemma tensorEquivSum_C_tmul_C (r : R) (s : S) : tensorEquivSum R σ ι S (.C s ⊗ₜ .C r) = .C (r • s) := by simp [tensorEquivSum, mul_comm (C s)] @[simp] lemma tensorEquivSum_X_tmul_X (i j) : tensorEquivSum R σ ι S (.X i ⊗ₜ .X j) = .X (.inl i) * .X (.inr j) := by simp [tensorEquivSum] section Pushout attribute [local instance] algebraMvPolynomial instance : Algebra.IsPushout R S (MvPolynomial σ R) (MvPolynomial σ S) where out := .of_equiv (algebraTensorAlgEquiv R S).toLinearEquiv fun _ ↦ by simp instance : Algebra.IsPushout R (MvPolynomial σ R) S (MvPolynomial σ S) := .symm inferInstance end Pushout end Algebra end MvPolynomial end
.lake/packages/mathlib/Mathlib/RingTheory/TensorProduct/Nontrivial.lean
import Mathlib.LinearAlgebra.Basis.VectorSpace import Mathlib.RingTheory.Flat.FaithfullyFlat.Basic import Mathlib.RingTheory.Localization.FractionRing /-! # Nontriviality of tensor product of algebras This file contains some more results on nontriviality of tensor product of algebras. -/ open TensorProduct namespace Algebra.TensorProduct /-- If `A`, `B` are `R`-algebras, `R` injects into `A` and `B`, and `A` and `B` are domains (which implies `R` is also a domain), then `A ⊗[R] B` is nontrivial. -/ theorem nontrivial_of_algebraMap_injective_of_isDomain (R A B : Type*) [CommRing R] [CommRing A] [CommRing B] [Algebra R A] [Algebra R B] (ha : Function.Injective (algebraMap R A)) (hb : Function.Injective (algebraMap R B)) [IsDomain A] [IsDomain B] : Nontrivial (A ⊗[R] B) := by haveI := ha.isDomain _ let FR := FractionRing R let FA := FractionRing A let FB := FractionRing B let fa : FR →ₐ[R] FA := IsFractionRing.liftAlgHom (g := Algebra.ofId R FA) ((IsFractionRing.injective A FA).comp ha) let fb : FR →ₐ[R] FB := IsFractionRing.liftAlgHom (g := Algebra.ofId R FB) ((IsFractionRing.injective B FB).comp hb) algebraize_only [fa.toRingHom, fb.toRingHom] exact Algebra.TensorProduct.mapOfCompatibleSMul FR R FA FB |>.comp (Algebra.TensorProduct.map (IsScalarTower.toAlgHom R A FA) (IsScalarTower.toAlgHom R B FB)) |>.toRingHom.domain_nontrivial end Algebra.TensorProduct
.lake/packages/mathlib/Mathlib/RingTheory/TensorProduct/IsBaseChangePi.lean
import Mathlib.LinearAlgebra.TensorProduct.Pi import Mathlib.LinearAlgebra.TensorProduct.Prod import Mathlib.RingTheory.Localization.BaseChange /-! # Base change commutes with finite products In particular, localization of modules commutes with finite products. We also show the binary product versions. -/ variable {R S : Type*} [CommSemiring R] [CommSemiring S] [Algebra R S] namespace IsBaseChange /-- Base change commutes with binary products. -/ lemma prodMap {M N M' N' : Type*} [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N] [AddCommMonoid M'] [AddCommMonoid N'] [Module R M'] [Module R N'] [Module S M'] [Module S N'] [IsScalarTower R S M'] [IsScalarTower R S N'] (f : M →ₗ[R] M') (g : N →ₗ[R] N') (hf : IsBaseChange S f) (hg : IsBaseChange S g) : IsBaseChange S (f.prodMap g) := by apply of_equiv (TensorProduct.prodRight R _ S M N ≪≫ₗ hf.equiv.prodCongr hg.equiv) intro p simp [equiv_tmul] /-- Base change commutes with finite products. -/ lemma pi {ι : Type*} [Finite ι] {M M' : ι → Type*} [∀ i, AddCommMonoid (M i)] [∀ i, AddCommMonoid (M' i)] [∀ i, Module R (M i)] [∀ i, Module R (M' i)] [∀ i, Module S (M' i)] [∀ i, IsScalarTower R S (M' i)] (f : ∀ i, M i →ₗ[R] M' i) (hf : ∀ i, IsBaseChange S (f i)) : IsBaseChange S (.pi fun i ↦ f i ∘ₗ .proj i) := by classical cases nonempty_fintype ι apply of_equiv <| TensorProduct.piRight R S _ M ≪≫ₗ .piCongrRight fun i ↦ (hf i).equiv intro x ext i simp [equiv_tmul] end IsBaseChange namespace IsLocalizedModule variable (S : Submonoid R) attribute [local instance] IsLocalizedModule.isScalarTower_module /-- Localization of modules commutes with binary products. -/ instance prodMap {M N M' N' : Type*} [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N] [AddCommMonoid M'] [AddCommMonoid N'] [Module R M'] [Module R N'] (f : M →ₗ[R] M') (g : N →ₗ[R] N') [IsLocalizedModule S f] [IsLocalizedModule S g] : IsLocalizedModule S (f.prodMap g) := by letI : Module (Localization S) M' := IsLocalizedModule.module S f letI : Module (Localization S) N' := IsLocalizedModule.module S g rw [isLocalizedModule_iff_isBaseChange S (Localization S)] apply IsBaseChange.prodMap · rw [← isLocalizedModule_iff_isBaseChange S] infer_instance · rw [← isLocalizedModule_iff_isBaseChange S] infer_instance /-- Localization of modules commutes with finite products. -/ instance pi {ι : Type*} [Finite ι] {M M' : ι → Type*} [∀ i, AddCommMonoid (M i)] [∀ i, AddCommMonoid (M' i)] [∀ i, Module R (M i)] [∀ i, Module R (M' i)] (f : ∀ i, M i →ₗ[R] M' i) [∀ i, IsLocalizedModule S (f i)] : IsLocalizedModule S (.pi fun i ↦ f i ∘ₗ .proj i) := by letI (i : ι) : Module (Localization S) (M' i) := IsLocalizedModule.module S (f i) rw [isLocalizedModule_iff_isBaseChange S (Localization S)] apply IsBaseChange.pi intro i rw [← isLocalizedModule_iff_isBaseChange S] infer_instance end IsLocalizedModule
.lake/packages/mathlib/Mathlib/RingTheory/TensorProduct/Free.lean
import Mathlib.LinearAlgebra.DirectSum.Finsupp import Mathlib.LinearAlgebra.Finsupp.Pi import Mathlib.LinearAlgebra.FreeModule.Basic import Mathlib.LinearAlgebra.Matrix.ToLin /-! # Results on bases of tensor products In the file we construct a basis for the base change of a module to an algebra, and deduce that `Module.Free` is stable under base change. ## Main declarations - `Algebra.TensorProduct.basis`: given a basis of a module `M` over a commutative semiring `R`, and an `R`-algebra `A`, this provides a basis for `A ⊗[R] M` over `A`. - `Algebra.TensorProduct.instFree`: if `M` is free, then so is `A ⊗[R] M`. -/ assert_not_exists Cardinal open Module open scoped TensorProduct namespace Algebra namespace TensorProduct variable {R A : Type*} section Basis universe uM uι variable {M : Type uM} {ι : Type uι} variable [CommSemiring R] [Semiring A] [Algebra R A] variable [AddCommMonoid M] [Module R M] (b : Basis ι R M) variable (A) in /-- Given an `R`-algebra `A` and an `R`-basis of `M`, this is an `R`-linear isomorphism `A ⊗[R] M ≃ (ι →₀ A)` (which is in fact `A`-linear). -/ noncomputable def basisAux : A ⊗[R] M ≃ₗ[R] ι →₀ A := _root_.TensorProduct.congr (Finsupp.LinearEquiv.finsuppUnique R A PUnit.{uι+1}).symm b.repr ≪≫ₗ (finsuppTensorFinsupp R R A R PUnit ι).trans (Finsupp.lcongr (Equiv.uniqueProd ι PUnit) (_root_.TensorProduct.rid R A)) theorem basisAux_tmul (a : A) (m : M) : basisAux A b (a ⊗ₜ m) = a • Finsupp.mapRange (algebraMap R A) (map_zero _) (b.repr m) := by ext simp [basisAux, ← Algebra.commutes, Algebra.smul_def] theorem basisAux_map_smul (a : A) (x : A ⊗[R] M) : basisAux A b (a • x) = a • basisAux A b x := TensorProduct.induction_on x (by simp) (fun x y => by simp only [TensorProduct.smul_tmul', basisAux_tmul, smul_assoc]) fun x y hx hy => by simp [hx, hy] variable (A) in /-- Given a `R`-algebra `A`, this is the `A`-basis of `A ⊗[R] M` induced by a `R`-basis of `M`. -/ noncomputable def basis : Basis ι A (A ⊗[R] M) where repr := { basisAux A b with map_smul' := basisAux_map_smul b } @[simp] theorem basis_repr_tmul (a : A) (m : M) : (basis A b).repr (a ⊗ₜ m) = a • Finsupp.mapRange (algebraMap R A) (map_zero _) (b.repr m) := basisAux_tmul b _ _ theorem basis_repr_symm_apply (a : A) (i : ι) : (basis A b).repr.symm (Finsupp.single i a) = a ⊗ₜ b.repr.symm (Finsupp.single i 1) := by simp [basis, LinearEquiv.coe_symm_mk', Equiv.uniqueProd_symm_apply, basisAux] @[simp] theorem basis_apply (i : ι) : basis A b i = 1 ⊗ₜ b i := basis_repr_symm_apply b 1 i theorem basis_repr_symm_apply' (a : A) (i : ι) : a • basis A b i = a ⊗ₜ b i := by simpa using basis_repr_symm_apply b a i section baseChange open LinearMap variable [Fintype ι] variable {ι' N : Type*} [Fintype ι'] [DecidableEq ι'] [AddCommMonoid N] [Module R N] variable (A : Type*) [CommSemiring A] [Algebra R A] lemma _root_.Module.Basis.baseChange_linearMap (b : Basis ι R M) (b' : Basis ι' R N) (ij : ι × ι') : baseChange A (b'.linearMap b ij) = (basis A b').linearMap (basis A b) ij := by apply (basis A b').ext intro k conv_lhs => simp only [basis_apply, baseChange_tmul] simp_rw [Basis.linearMap_apply_apply, basis_apply] split <;> simp only [TensorProduct.tmul_zero] variable [DecidableEq ι] lemma _root_.Module.Basis.baseChange_end (b : Basis ι R M) (ij : ι × ι) : baseChange A (b.end ij) = (basis A b).end ij := b.baseChange_linearMap A b ij end baseChange end Basis instance instFree (R A M : Type*) [CommSemiring R] [AddCommMonoid M] [Module R M] [Module.Free R M] [CommSemiring A] [Algebra R A] : Module.Free A (A ⊗[R] M) := Module.Free.of_basis <| Algebra.TensorProduct.basis A (Module.Free.chooseBasis R M) end TensorProduct end Algebra namespace LinearMap open Algebra.TensorProduct variable {R M₁ M₂ ι ι₂ : Type*} (A : Type*) [Fintype ι] [Finite ι₂] [DecidableEq ι] [CommSemiring R] [CommSemiring A] [Algebra R A] [AddCommMonoid M₁] [Module R M₁] [AddCommMonoid M₂] [Module R M₂] @[simp] lemma toMatrix_baseChange (f : M₁ →ₗ[R] M₂) (b₁ : Basis ι R M₁) (b₂ : Basis ι₂ R M₂) : toMatrix (basis A b₁) (basis A b₂) (f.baseChange A) = (toMatrix b₁ b₂ f).map (algebraMap R A) := by ext; simp [toMatrix_apply] end LinearMap
.lake/packages/mathlib/Mathlib/RingTheory/Nilpotent/Exp.lean
import Mathlib.Algebra.Algebra.Basic import Mathlib.Algebra.Algebra.Bilinear import Mathlib.Algebra.BigOperators.GroupWithZero.Action import Mathlib.Algebra.Module.BigOperators import Mathlib.Algebra.Module.Rat import Mathlib.Data.Nat.Cast.Field import Mathlib.LinearAlgebra.TensorProduct.Tower import Mathlib.RingTheory.Nilpotent.Basic import Mathlib.RingTheory.TensorProduct.Maps import Mathlib.Tactic.FieldSimp /-! # Exponential map on algebras This file defines the exponential map `IsNilpotent.exp` on `ℚ`-algebras. The definition of `IsNilpotent.exp a` applies to any element `a` in an algebra over `ℚ`, though it yields meaningful (non-junk) values only when `a` is nilpotent. The main result is `IsNilpotent.exp_add_of_commute`, which establishes the expected connection between the additive and multiplicative structures of `A` for commuting nilpotent elements. Additionally, `IsNilpotent.isUnit_exp` shows that if `a` is nilpotent in `A`, then `IsNilpotent.exp a` is a unit in `A`. Note: Although the definition works with `ℚ`-algebras, the results can be applied to any algebra over a characteristic zero field. ## Main definitions * `IsNilpotent.exp` ## Tags algebra, exponential map, nilpotent -/ namespace IsNilpotent variable {A : Type*} [Ring A] [Module ℚ A] open Finset open scoped Nat /-- The exponential map on algebras, defined in analogy with the usual exponential series. It provides meaningful (non-junk) values for nilpotent elements. -/ noncomputable def exp (a : A) : A := ∑ i ∈ range (nilpotencyClass a), (i.factorial : ℚ)⁻¹ • (a ^ i) theorem exp_eq_sum {a : A} {k : ℕ} (h : a ^ k = 0) : exp a = ∑ i ∈ range k, (i.factorial : ℚ)⁻¹ • (a ^ i) := by have h₁ : ∑ i ∈ range k, (i.factorial : ℚ)⁻¹ • (a ^ i) = ∑ i ∈ range (nilpotencyClass a), (i.factorial : ℚ)⁻¹ • (a ^ i) + ∑ i ∈ Ico (nilpotencyClass a) k, (i.factorial : ℚ)⁻¹ • (a ^ i) := (sum_range_add_sum_Ico _ (csInf_le' h)).symm suffices ∑ i ∈ Ico (nilpotencyClass a) k, (i.factorial : ℚ)⁻¹ • (a ^ i) = 0 by dsimp [exp] rw [h₁, this, add_zero] exact sum_eq_zero fun _ h₂ => by rw [pow_eq_zero_of_le (mem_Ico.1 h₂).1 (pow_nilpotencyClass ⟨k, h⟩), smul_zero] theorem exp_smul_eq_sum {M : Type*} [AddCommGroup M] [Module A M] [Module ℚ M] {a : A} {m : M} {k : ℕ} (h : (a ^ k) • m = 0) (hn : IsNilpotent a) : exp a • m = ∑ i ∈ range k, (i.factorial : ℚ)⁻¹ • (a ^ i) • m := by rcases le_or_gt (nilpotencyClass a) k with h₀ | h₀ · simp_rw [exp_eq_sum (pow_eq_zero_of_le h₀ (pow_nilpotencyClass hn)), sum_smul, smul_assoc] rw [exp, sum_smul, ← sum_range_add_sum_Ico _ (Nat.le_of_succ_le h₀)] suffices ∑ i ∈ Ico k (nilpotencyClass a), ((i.factorial : ℚ)⁻¹ • (a ^ i)) • m = 0 by simp_rw [this, add_zero, smul_assoc] refine sum_eq_zero fun r h₂ ↦ ?_ rw [smul_assoc, ← pow_sub_mul_pow a (mem_Ico.1 h₂).1, mul_smul, h, smul_zero, smul_zero] theorem exp_add_of_commute {a b : A} (h₁ : Commute a b) (h₂ : IsNilpotent a) (h₃ : IsNilpotent b) : exp (a + b) = exp a * exp b := by obtain ⟨n₁, hn₁⟩ := h₂ obtain ⟨n₂, hn₂⟩ := h₃ let N := n₁ ⊔ n₂ have h₄ : a ^ (N + 1) = 0 := pow_eq_zero_of_le (by omega) hn₁ have h₅ : b ^ (N + 1) = 0 := pow_eq_zero_of_le (by omega) hn₂ rw [exp_eq_sum (k := 2 * N + 1) (Commute.add_pow_eq_zero_of_add_le_succ_of_pow_eq_zero h₁ h₄ h₅ (by cutsat)), exp_eq_sum h₄, exp_eq_sum h₅] set R2N := range (2 * N + 1) with hR2N set RN := range (N + 1) with hRN have s₁ := by calc ∑ i ∈ R2N, (i ! : ℚ)⁻¹ • (a + b) ^ i = ∑ i ∈ R2N, (i ! : ℚ)⁻¹ • ∑ j ∈ range (i + 1), a ^ j * b ^ (i - j) * i.choose j := ?_ _ = ∑ i ∈ R2N, (∑ j ∈ range (i + 1), ((j ! : ℚ)⁻¹ * ((i - j) ! : ℚ)⁻¹) • (a ^ j * b ^ (i - j))) := ?_ _ = ∑ ij ∈ R2N ×ˢ R2N with ij.1 + ij.2 ≤ 2 * N, ((ij.1 ! : ℚ)⁻¹ * (ij.2 ! : ℚ)⁻¹) • (a ^ ij.1 * b ^ ij.2) := ?_ · refine sum_congr rfl fun i _ ↦ ?_ rw [Commute.add_pow h₁ i] · simp_rw [smul_sum] refine sum_congr rfl fun i hi ↦ sum_congr rfl fun j hj ↦ ?_ simp only [mem_range] at hi hj replace hj := Nat.le_of_lt_succ hj suffices (i ! : ℚ)⁻¹ * (i.choose j) = ((j ! : ℚ)⁻¹ * ((i - j)! : ℚ)⁻¹) by rw [← Nat.cast_commute (i.choose j), ← this, ← mul_smul_comm, ← nsmul_eq_mul, mul_smul, ← smul_assoc, smul_comm, smul_assoc] norm_cast rw [Nat.choose_eq_factorial_div_factorial hj, Nat.cast_div (Nat.factorial_mul_factorial_dvd_factorial hj) (by positivity)] simp [field] · rw [hR2N, sum_sigma'] apply sum_bij (fun ⟨i, j⟩ _ ↦ (j, i - j)) · simp only [mem_sigma, mem_range, mem_filter, mem_product, and_imp] cutsat · simp only [mem_sigma, mem_range, Prod.mk.injEq, and_imp] rintro ⟨x₁, y₁⟩ - h₁ ⟨x₂, y₂⟩ - h₂ h₃ h₄ simp_all cutsat · simp only [mem_filter, mem_product, mem_range, mem_sigma, exists_prop, Sigma.exists, and_imp, Prod.forall, Prod.mk.injEq] exact fun x y _ _ _ ↦ ⟨x + y, x, by cutsat⟩ · simp only [mem_sigma, mem_range, implies_true] have z₁ : ∑ ij ∈ R2N ×ˢ R2N with ¬ ij.1 + ij.2 ≤ 2 * N, ((ij.1 ! : ℚ)⁻¹ * (ij.2 ! : ℚ)⁻¹) • (a ^ ij.1 * b ^ ij.2) = 0 := sum_eq_zero fun i hi ↦ by rw [mem_filter] at hi cases le_or_gt (N + 1) i.1 with | inl h => rw [pow_eq_zero_of_le h h₄, zero_mul, smul_zero] | inr _ => rw [pow_eq_zero_of_le (by linarith) h₅, mul_zero, smul_zero] have split₁ := sum_filter_add_sum_filter_not (R2N ×ˢ R2N) (fun ij ↦ ij.1 + ij.2 ≤ 2 * N) (fun ij ↦ ((ij.1 ! : ℚ)⁻¹ * (ij.2 ! : ℚ)⁻¹) • (a ^ ij.1 * b ^ ij.2)) rw [z₁, add_zero] at split₁ rw [split₁] at s₁ have z₂ : ∑ ij ∈ R2N ×ˢ R2N with ¬ (ij.1 ≤ N ∧ ij.2 ≤ N), ((ij.1 ! : ℚ)⁻¹ * (ij.2 ! : ℚ)⁻¹) • (a ^ ij.1 * b ^ ij.2) = 0 := sum_eq_zero fun i hi ↦ by simp only [not_and, not_le, mem_filter] at hi cases le_or_gt (N + 1) i.1 with | inl h => rw [pow_eq_zero_of_le h h₄, zero_mul, smul_zero] | inr h => rw [pow_eq_zero_of_le (hi.2 (Nat.le_of_lt_succ h)) h₅, mul_zero, smul_zero] have split₂ := sum_filter_add_sum_filter_not (R2N ×ˢ R2N) (fun ij ↦ ij.1 ≤ N ∧ ij.2 ≤ N) (fun ij ↦ ((ij.1 ! : ℚ)⁻¹ * (ij.2 ! : ℚ)⁻¹) • (a ^ ij.1 * b ^ ij.2)) rw [z₂, add_zero] at split₂ rw [← split₂] at s₁ have restrict : ∑ ij ∈ R2N ×ˢ R2N with ij.1 ≤ N ∧ ij.2 ≤ N, ((ij.1 ! : ℚ)⁻¹ * (ij.2 ! : ℚ)⁻¹) • (a ^ ij.1 * b ^ ij.2) = ∑ ij ∈ RN ×ˢ RN, ((ij.1 ! : ℚ)⁻¹ * (ij.2 ! : ℚ)⁻¹) • (a ^ ij.1 * b ^ ij.2) := by apply sum_congr · ext x simp only [mem_filter, mem_product, mem_range, hR2N, hRN] cutsat · tauto rw [restrict] at s₁ have s₂ := by calc (∑ i ∈ RN, (i ! : ℚ)⁻¹ • a ^ i) * ∑ i ∈ RN, (i ! : ℚ)⁻¹ • b ^ i = ∑ i ∈ RN, ∑ j ∈ RN, ((i ! : ℚ)⁻¹ * (j ! : ℚ)⁻¹) • (a ^ i * b ^ j) := ?_ _ = ∑ ij ∈ RN ×ˢ RN, ((ij.1 ! : ℚ)⁻¹ * (ij.2 ! : ℚ)⁻¹) • (a ^ ij.1 * b ^ ij.2) := ?_ · rw [sum_mul_sum] refine sum_congr rfl fun _ _ ↦ sum_congr rfl fun _ _ ↦ ?_ rw [smul_mul_assoc, mul_smul_comm, smul_smul] · rw [sum_sigma'] apply sum_bijective (fun ⟨i, j⟩ ↦ (i, j)) · exact ⟨fun ⟨i, j⟩ ⟨i', j'⟩ h ↦ by cases h; rfl, fun ⟨i, j⟩ ↦ ⟨⟨i, j⟩, rfl⟩⟩ · simp only [mem_sigma, mem_product, implies_true] · simp only [implies_true] rwa [s₂.symm] at s₁ @[simp] theorem exp_zero : exp (0 : A) = 1 := by simp [exp_eq_sum (pow_one 0)] theorem exp_mul_exp_neg_self {a : A} (h : IsNilpotent a) : exp a * exp (-a) = 1 := by simp [← exp_add_of_commute (Commute.neg_right rfl) h h.neg] theorem exp_neg_mul_exp_self {a : A} (h : IsNilpotent a) : exp (-a) * exp a = 1 := by simp [← exp_add_of_commute (Commute.neg_left rfl) h.neg h] theorem isUnit_exp {a : A} (h : IsNilpotent a) : IsUnit (exp a) := by apply isUnit_iff_exists.2 use exp (-a) exact ⟨exp_mul_exp_neg_self h, exp_neg_mul_exp_self h⟩ theorem map_exp {B F : Type*} [Ring B] [FunLike F A B] [RingHomClass F A B] [Module ℚ B] {a : A} (ha : IsNilpotent a) (f : F) : f (exp a) = exp (f a) := by obtain ⟨k, hk⟩ := ha have hk' : (f a) ^ k = 0 := by simp [← map_pow, hk] simp [exp_eq_sum hk, exp_eq_sum hk', map_rat_smul] theorem exp_smul {G : Type*} [Monoid G] [MulSemiringAction G A] (g : G) {a : A} (ha : IsNilpotent a) : exp (g • a) = g • exp a := (map_exp ha (MulSemiringAction.toRingHom G A g)).symm end IsNilpotent namespace Module.End variable {R M N : Type*} [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] [Module ℚ M] [Module ℚ N] open IsNilpotent TensorProduct theorem commute_exp_left_of_commute {fM : Module.End R M} {fN : Module.End R N} {g : M →ₗ[R] N} (hfM : IsNilpotent fM) (hfN : IsNilpotent fN) (h : fN ∘ₗ g = g ∘ₗ fM) : exp fN ∘ₗ g = g ∘ₗ exp fM := by ext m obtain ⟨k, hfM⟩ := hfM obtain ⟨l, hfN⟩ := hfN let kl := max k l replace hfM : fM ^ kl = 0 := pow_eq_zero_of_le (by omega) hfM replace hfN : fN ^ kl = 0 := pow_eq_zero_of_le (by omega) hfN have (i : ℕ) : (fN ^ i) (g m) = g ((fM ^ i) m) := by simpa using LinearMap.congr_fun (Module.End.commute_pow_left_of_commute h i) m simp [exp_eq_sum hfM, exp_eq_sum hfN, this, map_rat_smul] theorem exp_mul_of_derivation (R B : Type*) [CommRing R] [NonUnitalNonAssocRing B] [Module R B] [SMulCommClass R B B] [IsScalarTower R B B] [Module ℚ B] (D : B →ₗ[R] B) (h_der : ∀ x y, D (x * y) = x * D y + (D x) * y) (h_nil : IsNilpotent D) (x y : B) : exp D (x * y) = (exp D x) * (exp D y) := by let DL : Module.End R (B ⊗[R] B) := D.lTensor B let DR : Module.End R (B ⊗[R] B) := D.rTensor B have h_nilL : IsNilpotent DL := h_nil.map <| lTensorAlgHom R B B have h_nilR : IsNilpotent DR := h_nil.map <| rTensorAlgHom R B B have h_comm : Commute DL DR := by ext; simp [DL, DR] set m : B ⊗[R] B →ₗ[R] B := LinearMap.mul' R B with hm have h₁ : exp D (x * y) = m (exp (DL + DR) (x ⊗ₜ[R] y)) := by suffices exp D ∘ₗ m = m ∘ₗ exp (DL + DR) by simpa using LinearMap.congr_fun this (x ⊗ₜ[R] y) apply commute_exp_left_of_commute (h_comm.isNilpotent_add h_nilL h_nilR) h_nil ext simp [DL, DR, hm, h_der] have h₂ : exp DL = (exp D).lTensor B := (h_nil.map_exp (lTensorAlgHom R B B)).symm have h₃ : exp DR = (exp D).rTensor B := (h_nil.map_exp (rTensorAlgHom R B B)).symm simp [h₁, exp_add_of_commute h_comm h_nilL h_nilR, h₂, h₃, hm] end Module.End
.lake/packages/mathlib/Mathlib/RingTheory/Nilpotent/Lemmas.lean
import Mathlib.LinearAlgebra.Matrix.ToLin import Mathlib.LinearAlgebra.Quotient.Basic import Mathlib.RingTheory.Ideal.Maps import Mathlib.RingTheory.Nilpotent.Defs /-! # Nilpotent elements This file contains results about nilpotent elements that involve ring theory. -/ assert_not_exists Cardinal universe u v open Function Module Set variable {R S : Type*} {x y : R} theorem RingHom.ker_isRadical_iff_reduced_of_surjective {S F} [CommSemiring R] [Semiring 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) theorem isNilpotent_iff_zero_mem_powers [Monoid R] [Zero R] {x : R} : IsNilpotent x ↔ 0 ∈ Submonoid.powers x := Iff.rfl 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 theorem nilradical_eq_bot_iff {R : Type*} [CommSemiring R] : nilradical R = ⊥ ↔ IsReduced R := by simp_rw [eq_bot_iff, SetLike.le_def, Submodule.mem_bot, mem_nilradical, isReduced_iff] 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 @[simp] lemma Matrix.isNilpotent_toLin'_iff {ι : Type*} [DecidableEq ι] [Fintype ι] [CommSemiring R] (A : Matrix ι ι R) : IsNilpotent A.toLin' ↔ IsNilpotent A := by have : A.toLin'.toMatrix (Pi.basisFun R ι) (Pi.basisFun R ι) = A := LinearMap.toMatrix'_toLin' A conv_rhs => rw [← this] rw [LinearMap.isNilpotent_toMatrix_iff] namespace Module.End section variable {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] lemma isNilpotent_restrict_of_le {f : End R M} {p q : Submodule R M} {hp : MapsTo f p p} {hq : MapsTo f q q} (h : p ≤ q) (hf : IsNilpotent (f.restrict hq)) : IsNilpotent (f.restrict hp) := by obtain ⟨n, hn⟩ := hf use n ext ⟨x, hx⟩ replace hn := DFunLike.congr_fun hn ⟨x, h hx⟩ simp_rw [LinearMap.zero_apply, ZeroMemClass.coe_zero, ZeroMemClass.coe_eq_zero] at hn ⊢ rw [Module.End.pow_restrict, LinearMap.restrict_apply] at hn ⊢ ext exact (congr_arg Subtype.val hn :) lemma isNilpotent.restrict {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 only [Module.End.pow_restrict n, hn, LinearMap.restrict_apply, LinearMap.zero_apply]; rfl⟩ end 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
.lake/packages/mathlib/Mathlib/RingTheory/Nilpotent/GeometricallyReduced.lean
import Mathlib.FieldTheory.IsAlgClosed.AlgebraicClosure import Mathlib.RingTheory.Flat.Basic /-! # Geometrically reduced algebras In this file we introduce geometrically reduced algebras. For a field `k`, we say that a `k`-algebra `A` is geometrically reduced (`IsGeometricallyReduced`) if the tensor product `AlgebraicClosure k ⊗[k] A` is reduced. ## Main results - `IsGeometricallyReduced.of_forall_fg`: for a field `k` and a commutative `k`-algebra `A`, if all finitely generated subalgebras `B` of `A` are geometrically reduced, then `A` is geometrically reduced. ## References - See [https://stacks.math.columbia.edu/tag/05DS] for some theory of geometrically reduced algebras. Note that their definition differs from the one here, we still need a proof that these are equivalent (see TODO). ## TODO - Prove that if `A` is a geometrically reduced `k`-algebra, then for every field extension `K` of `k` the `K`-algebra `K ⊗[k] A` is reduced. -/ open TensorProduct noncomputable section namespace Algebra variable {k A : Type*} [Field k] [Ring A] [Algebra k A] /-- The `k`-algebra `A` is geometrically reduced iff its base change to `AlgebraicClosure k` is reduced. -/ @[mk_iff] class IsGeometricallyReduced (k A : Type*) [Field k] [Ring A] [Algebra k A] : Prop where isReduced_algebraicClosure_tensorProduct : IsReduced (AlgebraicClosure k ⊗[k] A) attribute [instance] IsGeometricallyReduced.isReduced_algebraicClosure_tensorProduct instance (k A K : Type*) [Field k] [Ring A] [Algebra k A] [Field K] [Algebra k K] [Algebra.IsAlgebraic k K] [IsGeometricallyReduced k A] : IsReduced (K ⊗[k] A) := isReduced_of_injective (Algebra.TensorProduct.map ((IsAlgClosed.lift : K →ₐ[k] AlgebraicClosure k)) 1) (Module.Flat.rTensor_preserves_injective_linearMap _ (RingHom.injective _)) lemma IsGeometricallyReduced.of_injective {B : Type*} [Ring B] [Algebra k B] (f : A →ₐ[k] B) (hf : Function.Injective f) [IsGeometricallyReduced k B] : IsGeometricallyReduced k A := ⟨isReduced_of_injective (Algebra.TensorProduct.map 1 f) (Module.Flat.lTensor_preserves_injective_linearMap _ hf)⟩ variable (k) in theorem isReduced_of_isGeometricallyReduced [IsGeometricallyReduced k A] : IsReduced A := isReduced_of_injective (Algebra.TensorProduct.includeRight : A →ₐ[k] (AlgebraicClosure k) ⊗[k] A) (Algebra.TensorProduct.includeRight_injective <| FaithfulSMul.algebraMap_injective _ _) /-- If all finitely generated subalgebras of `A` are geometrically reduced, then `A` is geometrically reduced. -/ @[stacks 030T] theorem IsGeometricallyReduced.of_forall_fg (h : ∀ B : Subalgebra k A, B.FG → IsGeometricallyReduced k B) : IsGeometricallyReduced k A := by simp_rw [isGeometricallyReduced_iff] at h exact ⟨IsReduced.tensorProduct_of_flat_of_forall_fg h⟩ end Algebra
.lake/packages/mathlib/Mathlib/RingTheory/Nilpotent/Basic.lean
import Mathlib.Algebra.BigOperators.Finprod import Mathlib.Algebra.GroupWithZero.Action.Defs import Mathlib.Algebra.GroupWithZero.NonZeroDivisors import Mathlib.Algebra.NoZeroSMulDivisors.Defs import Mathlib.Algebra.Ring.GeomSum 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.lean`. ## 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 lemma IsUnit.not_isNilpotent [Ring R] [Nontrivial R] {x : R} (hx : IsUnit x) : ¬ IsNilpotent x := by intro H simpa using H.isUnit_add_right_of_commute hx.neg (by simp) lemma IsNilpotent.not_isUnit [Ring R] [Nontrivial R] {x : R} (hx : IsNilpotent x) : ¬ IsUnit x := mt IsUnit.not_isNilpotent (by simpa only [not_not] using hx) lemma IsIdempotentElem.eq_zero_of_isNilpotent [MonoidWithZero R] {e : R} (idem : IsIdempotentElem e) (nilp : IsNilpotent e) : e = 0 := by obtain ⟨rfl | n, hn⟩ := nilp · rw [pow_zero] at hn; rw [← one_mul e, hn, zero_mul] · rw [← hn, idem.pow_succ_eq] alias IsNilpotent.eq_zero_of_isIdempotentElem := IsIdempotentElem.eq_zero_of_isNilpotent 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] gcongr exact dvd_pow_self _ two_ne_zero 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])) theorem isNilpotent_finsum {ι : Type*} {f : ι → R} (hf : ∀ b, IsNilpotent (f b)) (h_comm : ∀ i j, Commute (f i) (f j)) : IsNilpotent (finsum f) := by classical by_cases h : Set.Finite f.support · rw [finsum_def, dif_pos h] exact Commute.isNilpotent_sum (fun b _ ↦ hf b) (fun _ _ _ _ ↦ h_comm _ _) · simp only [finsum_def, dif_neg h, IsNilpotent.zero] protected lemma isNilpotent_mul_right_iff (h_comm : Commute x y) (hy : y ∈ nonZeroDivisorsRight R) : IsNilpotent (x * y) ↔ IsNilpotent x := by refine ⟨?_, h_comm.isNilpotent_mul_right⟩ rintro ⟨k, hk⟩ rw [mul_pow h_comm] at hk exact ⟨k, (nonZeroDivisorsRight R).pow_mem hy k _ hk⟩ protected lemma isNilpotent_mul_left_iff (h_comm : Commute x y) (hx : x ∈ nonZeroDivisorsLeft R) : IsNilpotent (x * y) ↔ IsNilpotent y := by refine ⟨?_, h_comm.isNilpotent_mul_left⟩ rintro ⟨k, hk⟩ rw [mul_pow h_comm] at hk exact ⟨k, (nonZeroDivisorsLeft 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 _ _ theorem isNilpotent_finsum {ι : Type*} {f : ι → R} (hf : ∀ b, IsNilpotent (f b)) : IsNilpotent (finsum f) := Commute.isNilpotent_finsum hf 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 | zero => rw [pow_zero] at hk exact eq_zero_of_zero_eq_one hk.symm x | succ k ih => 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
.lake/packages/mathlib/Mathlib/RingTheory/Nilpotent/Defs.lean
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.lean` and `Mathlib/RingTheory/Nilpotent/Lemmas.lean`. ## 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 := ⟨of_pow, (pow_of_pos · 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 namespace IsReduced theorem pow_eq_zero [Zero R] [Pow R ℕ] [IsReduced R] {n : ℕ} (h : x ^ n = 0) : x = 0 := IsReduced.eq_zero x ⟨n, h⟩ @[simp] theorem pow_eq_zero_iff [MonoidWithZero R] [IsReduced R] {n : ℕ} (hn : n ≠ 0) : x ^ n = 0 ↔ x = 0 := ⟨pow_eq_zero, fun h ↦ h.symm ▸ zero_pow hn⟩ theorem pow_ne_zero_iff [MonoidWithZero R] [IsReduced R] {n : ℕ} (hn : n ≠ 0) : x ^ n ≠ 0 ↔ x ≠ 0 := not_congr (pow_eq_zero_iff hn) theorem pow_ne_zero [Zero R] [Pow R ℕ] [IsReduced R] (n : ℕ) (h : x ≠ 0) : x ^ n ≠ 0 := fun H ↦ h (pow_eq_zero H) /-- A variant of `IsReduced.pow_eq_zero_iff` assuming `R` is not trivial. -/ @[simp] theorem pow_eq_zero_iff' [MonoidWithZero R] [IsReduced R] [Nontrivial R] {n : ℕ} : x ^ n = 0 ↔ x = 0 ∧ n ≠ 0 := by cases n <;> simp end IsReduced instance (priority := 900) isReduced_of_noZeroDivisors [MonoidWithZero R] [NoZeroDivisors R] : IsReduced R := ⟨fun _ ⟨_, hn⟩ => eq_zero_of_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 lemma exists_isNilpotent_of_not_isReduced {R : Type*} [Zero R] [Pow R ℕ] (h : ¬IsReduced R) : ∃ x : R, x ≠ 0 ∧ IsNilpotent x := by rw [isReduced_iff, not_forall] at h; tauto 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 [Monoid 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_right (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_left (h_comm : Commute x y) (h : IsNilpotent y) : IsNilpotent (x * y) := by rw [h_comm.eq] exact h_comm.symm.isNilpotent_mul_right h end Semiring end Commute
.lake/packages/mathlib/Mathlib/RingTheory/Noetherian/Nilpotent.lean
import Mathlib.RingTheory.Finiteness.Ideal import Mathlib.RingTheory.Nilpotent.Lemmas import Mathlib.RingTheory.Noetherian.Defs /-! # Nilpotent ideals in Noetherian rings ## Main results * `IsNoetherianRing.isNilpotent_nilradical` -/ open IsNoetherian theorem IsNoetherianRing.isNilpotent_nilradical (R : Type*) [CommSemiring R] [IsNoetherianRing R] : IsNilpotent (nilradical R) := by obtain ⟨n, hn⟩ := Ideal.exists_radical_pow_le_of_fg (⊥ : Ideal R) (IsNoetherian.noetherian _) exact ⟨n, eq_bot_iff.mpr hn⟩ lemma Ideal.FG.isNilpotent_iff_le_nilradical {R : Type*} [CommSemiring R] {I : Ideal R} (hI : I.FG) : IsNilpotent I ↔ I ≤ nilradical R := ⟨fun ⟨n, hn⟩ _ hx ↦ ⟨n, hn ▸ Ideal.pow_mem_pow hx n⟩, fun h ↦ let ⟨n, hn⟩ := exists_pow_le_of_le_radical_of_fg h hI; ⟨n, le_bot_iff.mp hn⟩⟩
.lake/packages/mathlib/Mathlib/RingTheory/Noetherian/Basic.lean
import Mathlib.Algebra.Order.SuccPred.PartialSups import Mathlib.LinearAlgebra.Quotient.Basic import Mathlib.RingTheory.Noetherian.Defs import Mathlib.RingTheory.Finiteness.Cardinality import Mathlib.RingTheory.Finiteness.Finsupp import Mathlib.RingTheory.Ideal.Prod /-! # Noetherian rings and modules The following are equivalent for a module M over a ring R: 1. Every increasing chain of submodules M₁ ⊆ M₂ ⊆ M₃ ⊆ ⋯ eventually stabilises. 2. Every submodule is finitely generated. A module satisfying these equivalent conditions is said to be a *Noetherian* R-module. A ring is a *Noetherian ring* if it is Noetherian as a module over itself. (Note that we do not assume yet that our rings are commutative, so perhaps this should be called "left-Noetherian". To avoid cumbersome names once we specialize to the commutative case, we don't make this explicit in the declaration names.) ## Main definitions Let `R` be a ring and let `M` and `P` be `R`-modules. Let `N` be an `R`-submodule of `M`. * `IsNoetherian R M` is the proposition that `M` is a Noetherian `R`-module. It is a class, implemented as the predicate that all `R`-submodules of `M` are finitely generated. ## Main statements * `isNoetherian_iff` is the theorem that an R-module M is Noetherian iff `>` is well-founded on `Submodule R M`. Note that the Hilbert basis theorem, that if a commutative ring R is Noetherian then so is R[X], is proved in `RingTheory.Polynomial`. ## References * [M. F. Atiyah and I. G. Macdonald, *Introduction to commutative algebra*][atiyah-macdonald] * [P. Samuel, *Algebraic Theory of Numbers*][samuel1967] ## Tags Noetherian, noetherian, Noetherian ring, Noetherian module, noetherian ring, noetherian module -/ assert_not_exists Matrix open Set Pointwise section variable {R M P : Type*} variable [Semiring R] [AddCommMonoid M] [AddCommMonoid P] variable [Module R M] [Module R P] open IsNoetherian variable (M) in theorem isNoetherian_of_surjective (f : M →ₗ[R] P) (hf : LinearMap.range f = ⊤) [IsNoetherian R M] : IsNoetherian R P := ⟨fun s => have : (s.comap f).map f = s := Submodule.map_comap_eq_self <| hf.symm ▸ le_top this ▸ (noetherian _).map _⟩ instance isNoetherian_range (f : M →ₗ[R] P) [IsNoetherian R M] : IsNoetherian R (LinearMap.range f) := isNoetherian_of_surjective _ _ f.range_rangeRestrict instance isNoetherian_quotient {A M : Type*} [Ring A] [AddCommGroup M] [SMul R A] [Module R M] [Module A M] [IsScalarTower R A M] (N : Submodule A M) [IsNoetherian R M] : IsNoetherian R (M ⧸ N) := isNoetherian_of_surjective M ((Submodule.mkQ N).restrictScalars R) <| LinearMap.range_eq_top.mpr N.mkQ_surjective theorem isNoetherian_of_linearEquiv (f : M ≃ₗ[R] P) [IsNoetherian R M] : IsNoetherian R P := isNoetherian_of_surjective _ f.toLinearMap f.range theorem LinearEquiv.isNoetherian_iff (f : M ≃ₗ[R] P) : IsNoetherian R M ↔ IsNoetherian R P := ⟨fun _ ↦ isNoetherian_of_linearEquiv f, fun _ ↦ isNoetherian_of_linearEquiv f.symm⟩ theorem isNoetherian_top_iff : IsNoetherian R (⊤ : Submodule R M) ↔ IsNoetherian R M := Submodule.topEquiv.isNoetherian_iff theorem isNoetherian_of_injective [IsNoetherian R P] (f : M →ₗ[R] P) (hf : Function.Injective f) : IsNoetherian R M := isNoetherian_of_linearEquiv (LinearEquiv.ofInjective f hf).symm theorem fg_of_injective [IsNoetherian R P] {N : Submodule R M} (f : M →ₗ[R] P) (hf : Function.Injective f) : N.FG := haveI := isNoetherian_of_injective f hf IsNoetherian.noetherian N end namespace Module variable {R M N : Type*} variable [Semiring R] [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N] variable (R M) -- see Note [lower instance priority] instance (priority := 80) _root_.isNoetherian_of_finite [Finite M] : IsNoetherian R M := ⟨fun s => ⟨(s : Set M).toFinite.toFinset, by rw [Set.Finite.coe_toFinset, Submodule.span_eq]⟩⟩ -- see Note [lower instance priority] instance (priority := 100) IsNoetherian.finite [IsNoetherian R M] : Module.Finite R M := ⟨IsNoetherian.noetherian ⊤⟩ instance {R₁ S : Type*} [CommSemiring R₁] [Semiring S] [Algebra R₁ S] [IsNoetherian R₁ S] (I : Ideal S) : Module.Finite R₁ I := IsNoetherian.finite R₁ ((I : Submodule S S).restrictScalars R₁) variable {R M} theorem Finite.of_injective [IsNoetherian R N] (f : M →ₗ[R] N) (hf : Function.Injective f) : Module.Finite R M := ⟨fg_of_injective f hf⟩ end Module section variable {R M N P : Type*} variable [Ring R] [AddCommGroup M] [AddCommGroup N] [AddCommGroup P] variable [Module R M] [Module R N] [Module R P] open IsNoetherian theorem isNoetherian_of_ker_bot [IsNoetherian R P] (f : M →ₗ[R] P) (hf : LinearMap.ker f = ⊥) : IsNoetherian R M := isNoetherian_of_linearEquiv (LinearEquiv.ofInjective f <| LinearMap.ker_eq_bot.mp hf).symm theorem fg_of_ker_bot [IsNoetherian R P] {N : Submodule R M} (f : M →ₗ[R] P) (hf : LinearMap.ker f = ⊥) : N.FG := haveI := isNoetherian_of_ker_bot f hf IsNoetherian.noetherian N -- False over a semiring: ℕ is a Noetherian ℕ-module but ℕ × ℕ is not. instance isNoetherian_prod [IsNoetherian R M] [IsNoetherian R P] : IsNoetherian R (M × P) := ⟨fun s => Submodule.fg_of_fg_map_of_fg_inf_ker (LinearMap.snd R M P) (noetherian _) <| have : s ⊓ LinearMap.ker (LinearMap.snd R M P) ≤ LinearMap.range (LinearMap.inl R M P) := fun x ⟨_, hx2⟩ => ⟨x.1, Prod.ext rfl <| Eq.symm <| LinearMap.mem_ker.1 hx2⟩ Submodule.map_comap_eq_self this ▸ (noetherian _).map _⟩ instance isNoetherian_sup (M₁ M₂ : Submodule R P) [IsNoetherian R M₁] [IsNoetherian R M₂] : IsNoetherian R ↥(M₁ ⊔ M₂) := by have := isNoetherian_range (M₁.subtype.coprod M₂.subtype) rwa [LinearMap.range_coprod, Submodule.range_subtype, Submodule.range_subtype] at this variable {ι : Type*} [Finite ι] instance isNoetherian_pi : ∀ {M : ι → Type*} [∀ i, AddCommGroup (M i)] [∀ i, Module R (M i)] [∀ i, IsNoetherian R (M i)], IsNoetherian R (Π i, M i) := by apply Finite.induction_empty_option _ _ _ ι · exact fun e h ↦ isNoetherian_of_linearEquiv (LinearEquiv.piCongrLeft R _ e) · infer_instance · exact fun ih ↦ isNoetherian_of_linearEquiv (LinearEquiv.piOptionEquivProd R).symm /-- A version of `isNoetherian_pi` for non-dependent functions. We need this instance because sometimes Lean fails to apply the dependent version in non-dependent settings (e.g., it fails to prove that `ι → ℝ` is finite dimensional over `ℝ`). -/ instance isNoetherian_pi' [IsNoetherian R M] : IsNoetherian R (ι → M) := isNoetherian_pi instance isNoetherian_iSup : ∀ {M : ι → Submodule R P} [∀ i, IsNoetherian R (M i)], IsNoetherian R ↥(⨆ i, M i) := by apply Finite.induction_empty_option _ _ _ ι · intro _ _ e h _ _; rw [← e.iSup_comp]; apply h · intros; rw [iSup_of_empty]; infer_instance · intro _ _ ih _ _; rw [iSup_option]; infer_instance /-- If the first and final modules in an exact sequence are Noetherian, then the middle module is also Noetherian. -/ theorem isNoetherian_of_range_eq_ker [IsNoetherian R M] [IsNoetherian R P] (f : M →ₗ[R] N) (g : N →ₗ[R] P) (h : LinearMap.range f = LinearMap.ker g) : IsNoetherian R N := isNoetherian_mk <| wellFounded_gt_exact_sequence (LinearMap.range f) (Submodule.map ((LinearMap.ker f).liftQ f le_rfl)) (Submodule.comap ((LinearMap.ker f).liftQ f le_rfl)) (Submodule.comap g.rangeRestrict) (Submodule.map g.rangeRestrict) (Submodule.gciMapComap <| LinearMap.ker_eq_bot.mp <| Submodule.ker_liftQ_eq_bot _ _ _ le_rfl) (Submodule.giMapComap g.surjective_rangeRestrict) (by simp [Submodule.map_comap_eq, inf_comm, Submodule.range_liftQ]) (by simp [Submodule.comap_map_eq, h]) theorem isNoetherian_iff_submodule_quotient (S : Submodule R P) : IsNoetherian R P ↔ IsNoetherian R S ∧ IsNoetherian R (P ⧸ S) := by refine ⟨fun _ ↦ ⟨inferInstance, inferInstance⟩, fun ⟨_, _⟩ ↦ ?_⟩ apply isNoetherian_of_range_eq_ker S.subtype S.mkQ rw [Submodule.ker_mkQ, Submodule.range_subtype] end section CommRing variable (R M N : Type*) [CommRing R] [AddCommGroup M] [AddCommGroup N] [Module R M] [Module R N] [IsNoetherian R M] [Module.Finite R N] instance isNoetherian_linearMap_pi {ι : Type*} [Finite ι] : IsNoetherian R ((ι → R) →ₗ[R] M) := let _i : Fintype ι := Fintype.ofFinite ι; isNoetherian_of_linearEquiv (Module.piEquiv ι R M) instance isNoetherian_linearMap : IsNoetherian R (N →ₗ[R] M) := by obtain ⟨n, f, hf⟩ := Module.Finite.exists_fin' R N let g : (N →ₗ[R] M) →ₗ[R] (Fin n → R) →ₗ[R] M := (LinearMap.llcomp R (Fin n → R) N M).flip f exact isNoetherian_of_injective g hf.injective_linearMapComp_right end CommRing open IsNoetherian Submodule Function section variable {R M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] /-- If `∀ I > J, P I` implies `P J`, then `P` holds for all submodules. -/ theorem IsNoetherian.induction [IsNoetherian R M] {P : Submodule R M → Prop} (hgt : ∀ I, (∀ J > I, P J) → P I) (I : Submodule R M) : P I := IsWellFounded.induction _ I hgt theorem LinearMap.isNoetherian_iff_of_bijective {S P} [Semiring S] [AddCommMonoid P] [Module S P] {σ : R →+* S} [RingHomSurjective σ] (l : M →ₛₗ[σ] P) (hl : Function.Bijective l) : IsNoetherian R M ↔ IsNoetherian S P := by simp_rw [isNoetherian_iff'] let e := Submodule.orderIsoMapComapOfBijective l hl exact ⟨fun _ ↦ e.symm.strictMono.wellFoundedGT, fun _ ↦ e.strictMono.wellFoundedGT⟩ end section variable {R M N P : Type*} [Semiring R] [AddCommMonoid M] [Module R M] [IsNoetherian R M] lemma Submodule.finite_ne_bot_of_iSupIndep {ι : Type*} {N : ι → Submodule R M} (h : iSupIndep N) : Set.Finite {i | N i ≠ ⊥} := WellFoundedGT.finite_ne_bot_of_iSupIndep h /-- A linearly-independent family of vectors in a module over a non-trivial ring must be finite if the module is Noetherian. -/ theorem LinearIndependent.finite_of_isNoetherian [Nontrivial R] {ι} {v : ι → M} (hv : LinearIndependent R v) : Finite ι := by refine WellFoundedGT.finite_of_iSupIndep hv.iSupIndep_span_singleton fun i contra => ?_ apply hv.ne_zero i have : v i ∈ R ∙ v i := Submodule.mem_span_singleton_self (v i) rwa [contra, Submodule.mem_bot] at this theorem LinearIndependent.set_finite_of_isNoetherian [Nontrivial R] {s : Set M} (hi : LinearIndependent R ((↑) : s → M)) : s.Finite := @Set.toFinite _ _ hi.finite_of_isNoetherian /-- A sequence `f` of submodules of a Noetherian module, with `f (n+1)` disjoint from the supremum of `f 0`, ..., `f n`, is eventually zero. -/ theorem IsNoetherian.disjoint_partialSups_eventually_bot (f : ℕ → Submodule R M) (h : ∀ n, Disjoint (partialSups f n) (f (n + 1))) : ∃ n : ℕ, ∀ m, n ≤ m → f m = ⊥ := by -- A little off-by-one cleanup first: suffices t : ∃ n : ℕ, ∀ m, n ≤ m → f (m + 1) = ⊥ by obtain ⟨n, w⟩ := t use n + 1 rintro (_ | m) p · cases p · apply w exact Nat.succ_le_succ_iff.mp p obtain ⟨n, w⟩ := monotone_stabilizes_iff_noetherian.mpr inferInstance (partialSups f) refine ⟨n, fun m p ↦ (h m).eq_bot_of_ge <| sup_eq_left.mp ?_⟩ simpa only [partialSups_add_one] using (w (m + 1) <| le_add_right p).symm.trans <| w m p end -- see Note [lower instance priority] /-- Modules over the trivial ring are Noetherian. -/ instance (priority := 100) isNoetherian_of_subsingleton (R M) [Subsingleton R] [Semiring R] [AddCommMonoid M] [Module R M] : IsNoetherian R M := haveI := Module.subsingleton R M isNoetherian_of_finite R M theorem isNoetherian_of_submodule_of_noetherian (R M) [Semiring R] [AddCommMonoid M] [Module R M] (N : Submodule R M) (h : IsNoetherian R M) : IsNoetherian R N := isNoetherian_mk ⟨OrderEmbedding.wellFounded (Submodule.MapSubtype.orderEmbedding N).dual h.wf⟩ /-- If `M / S / R` is a scalar tower, and `M / R` is Noetherian, then `M / S` is also Noetherian. -/ theorem isNoetherian_of_tower (R) {S M} [Semiring R] [Semiring S] [AddCommMonoid M] [SMul R S] [Module S M] [Module R M] [IsScalarTower R S M] (h : IsNoetherian R M) : IsNoetherian S M := isNoetherian_mk ⟨(Submodule.restrictScalarsEmbedding R S M).dual.wellFounded h.wf⟩ instance isNoetherian_of_isNoetherianRing_of_finite (R M : Type*) [Ring R] [AddCommGroup M] [Module R M] [IsNoetherianRing R] [Module.Finite R M] : IsNoetherian R M := have ⟨_, _, h⟩ := Module.Finite.exists_fin' R M isNoetherian_of_surjective _ _ (LinearMap.range_eq_top.mpr h) theorem isNoetherian_of_fg_of_noetherian {R M} [Ring R] [AddCommGroup M] [Module R M] (N : Submodule R M) [I : IsNoetherianRing R] (hN : N.FG) : IsNoetherian R N := by rw [← Module.Finite.iff_fg] at hN; infer_instance /-- In a module over a Noetherian ring, the submodule generated by finitely many vectors is Noetherian. -/ theorem isNoetherian_span_of_finite (R) {M} [Ring R] [AddCommGroup M] [Module R M] [IsNoetherianRing R] {A : Set M} (hA : A.Finite) : IsNoetherian R (Submodule.span R A) := isNoetherian_of_fg_of_noetherian _ (Submodule.fg_def.mpr ⟨A, hA, rfl⟩) theorem IsNoetherianRing.of_finite (R S) [Ring R] [Ring S] [Module R S] [IsScalarTower R S S] [IsNoetherianRing R] [Module.Finite R S] : IsNoetherianRing S := isNoetherian_of_tower R inferInstance theorem isNoetherianRing_of_surjective (R) [Semiring R] (S) [Semiring S] (f : R →+* S) (hf : Function.Surjective f) [H : IsNoetherianRing R] : IsNoetherianRing S := isNoetherian_mk ⟨OrderEmbedding.wellFounded (Ideal.orderEmbeddingOfSurjective f hf).dual H.wf⟩ instance isNoetherianRing_rangeS {R} [Semiring R] {S} [Semiring S] (f : R →+* S) [IsNoetherianRing R] : IsNoetherianRing f.rangeS := isNoetherianRing_of_surjective R f.rangeS f.rangeSRestrict f.rangeSRestrict_surjective instance isNoetherianRing_range {R} [Ring R] {S} [Ring S] (f : R →+* S) [IsNoetherianRing R] : IsNoetherianRing f.range := isNoetherianRing_rangeS f theorem isNoetherianRing_of_ringEquiv (R) [Semiring R] {S} [Semiring S] (f : R ≃+* S) [IsNoetherianRing R] : IsNoetherianRing S := isNoetherianRing_of_surjective R S f.toRingHom f.toEquiv.surjective instance {R S} [Semiring R] [Semiring S] [IsNoetherianRing R] [IsNoetherianRing S] : IsNoetherianRing (R × S) := by rw [IsNoetherianRing, isNoetherian_iff'] at * exact Ideal.idealProdEquiv.toOrderEmbedding.wellFoundedGT instance {ι} [Finite ι] : ∀ {R : ι → Type*} [Π i, Semiring (R i)] [∀ i, IsNoetherianRing (R i)], IsNoetherianRing (Π i, R i) := by apply Finite.induction_empty_option _ _ _ ι · exact fun e h ↦ isNoetherianRing_of_ringEquiv _ (.piCongrLeft _ e) · infer_instance · exact fun ih ↦ isNoetherianRing_of_ringEquiv _ (.symm .piOptionEquivProd)
.lake/packages/mathlib/Mathlib/RingTheory/Noetherian/Filter.lean
import Mathlib.Order.Filter.EventuallyConst import Mathlib.RingTheory.Noetherian.Defs /-! # Noetherian modules and finiteness of chains ## Main results Let `R` be a ring and let `M` be an `R`-module. * `eventuallyConst_of_isNoetherian`: an ascending chain of submodules in a Noetherian module is eventually constant ## References * [M. F. Atiyah and I. G. Macdonald, *Introduction to commutative algebra*][atiyah-macdonald] * [P. Samuel, *Algebraic Theory of Numbers*][samuel1967] ## Tags Noetherian, noetherian, Noetherian ring, Noetherian module, noetherian ring, noetherian module -/ open Set Filter Pointwise open IsNoetherian Submodule Function section Semiring variable {R M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] theorem eventuallyConst_of_isNoetherian [IsNoetherian R M] (f : ℕ →o Submodule R M) : atTop.EventuallyConst f := by simp_rw [eventuallyConst_atTop, eq_comm] exact (monotone_stabilizes_iff_noetherian.mpr inferInstance) f end Semiring
.lake/packages/mathlib/Mathlib/RingTheory/Noetherian/Defs.lean
import Mathlib.Order.Filter.AtTopBot.Basic import Mathlib.RingTheory.Finiteness.Basic /-! # Noetherian rings and modules The following are equivalent for a module M over a ring R: 1. Every increasing chain of submodules M₁ ⊆ M₂ ⊆ M₃ ⊆ ⋯ eventually stabilises. 2. Every submodule is finitely generated. A module satisfying these equivalent conditions is said to be a *Noetherian* R-module. A ring is a *Noetherian ring* if it is Noetherian as a module over itself. (Note that we do not assume yet that our rings are commutative, so perhaps this should be called "left-Noetherian". To avoid cumbersome names once we specialize to the commutative case, we don't make this explicit in the declaration names.) ## Main definitions Let `R` be a ring and let `M` and `P` be `R`-modules. Let `N` be an `R`-submodule of `M`. * `IsNoetherian R M` is the proposition that `M` is a Noetherian `R`-module. It is a class, implemented as the predicate that all `R`-submodules of `M` are finitely generated. ## Main statements * `isNoetherian_iff` is the theorem that an R-module M is Noetherian iff `>` is well-founded on `Submodule R M`. Note that the Hilbert basis theorem, that if a commutative ring R is Noetherian then so is R[X], is proved in `RingTheory.Polynomial`. ## References * [M. F. Atiyah and I. G. Macdonald, *Introduction to commutative algebra*][atiyah-macdonald] * [P. Samuel, *Algebraic Theory of Numbers*][samuel1967] ## Tags Noetherian, noetherian, Noetherian ring, Noetherian module, noetherian ring, noetherian module -/ assert_not_exists Finsupp.linearCombination Matrix Pi.basis open Set Pointwise /-- `IsNoetherian R M` is the proposition that `M` is a Noetherian `R`-module, implemented as the predicate that all `R`-submodules of `M` are finitely generated. -/ -- TODO: should this be renamed to `Noetherian`? class IsNoetherian (R M) [Semiring R] [AddCommMonoid M] [Module R M] : Prop where noetherian : ∀ s : Submodule R M, s.FG attribute [inherit_doc IsNoetherian] IsNoetherian.noetherian section variable {R : Type*} {M : Type*} {P : Type*} variable [Semiring R] [AddCommMonoid M] [AddCommMonoid P] variable [Module R M] [Module R P] open IsNoetherian /-- An R-module is Noetherian iff all its submodules are finitely-generated. -/ theorem isNoetherian_def : IsNoetherian R M ↔ ∀ s : Submodule R M, s.FG := ⟨fun h => h.noetherian, IsNoetherian.mk⟩ theorem isNoetherian_submodule {N : Submodule R M} : IsNoetherian R N ↔ ∀ s : Submodule R M, s ≤ N → s.FG := by refine ⟨fun ⟨hn⟩ => fun s hs => have : s ≤ LinearMap.range N.subtype := N.range_subtype.symm ▸ hs Submodule.map_comap_eq_self this ▸ (hn _).map _, fun h => ⟨fun s => ?_⟩⟩ have f := (Submodule.equivMapOfInjective N.subtype Subtype.val_injective s).symm have h₁ := h (s.map N.subtype) (Submodule.map_subtype_le N s) have h₂ : (⊤ : Submodule R (s.map N.subtype)).map f = ⊤ := by simp have h₃ := ((Submodule.fg_top _).2 h₁).map (↑f : _ →ₗ[R] s) exact (Submodule.fg_top _).1 (h₂ ▸ h₃) theorem isNoetherian_submodule_left {N : Submodule R M} : IsNoetherian R N ↔ ∀ s : Submodule R M, (N ⊓ s).FG := isNoetherian_submodule.trans ⟨fun H _ => H _ inf_le_left, fun H _ hs => inf_of_le_right hs ▸ H _⟩ theorem isNoetherian_submodule_right {N : Submodule R M} : IsNoetherian R N ↔ ∀ s : Submodule R M, (s ⊓ N).FG := isNoetherian_submodule.trans ⟨fun H _ => H _ inf_le_right, fun H _ hs => inf_of_le_left hs ▸ H _⟩ instance isNoetherian_submodule' [IsNoetherian R M] (N : Submodule R M) : IsNoetherian R N := isNoetherian_submodule.2 fun _ _ => IsNoetherian.noetherian _ theorem isNoetherian_of_le {s t : Submodule R M} [ht : IsNoetherian R t] (h : s ≤ t) : IsNoetherian R s := isNoetherian_submodule.mpr fun _ hs' => isNoetherian_submodule.mp ht _ (le_trans hs' h) end open IsNoetherian Submodule Function section universe w variable {R M P : Type*} {N : Type w} [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] [AddCommMonoid P] [Module R P] theorem isNoetherian_iff' : IsNoetherian R M ↔ WellFoundedGT (Submodule R M) := by refine .trans ?_ ((CompleteLattice.wellFoundedGT_characterisations <| Submodule R M).out 0 3).symm exact ⟨fun ⟨h⟩ => fun k => (fg_iff_compact k).mp (h k), fun h => ⟨fun k => (fg_iff_compact k).mpr (h k)⟩⟩ theorem isNoetherian_iff : IsNoetherian R M ↔ WellFounded ((· > ·) : Submodule R M → Submodule R M → Prop) := by rw [isNoetherian_iff', ← isWellFounded_iff] alias ⟨IsNoetherian.wf, _⟩ := isNoetherian_iff alias ⟨IsNoetherian.wellFoundedGT, isNoetherian_mk⟩ := isNoetherian_iff' instance wellFoundedGT [h : IsNoetherian R M] : WellFoundedGT (Submodule R M) := h.wellFoundedGT theorem isNoetherian_iff_fg_wellFounded : IsNoetherian R M ↔ WellFoundedGT { N : Submodule R M // N.FG } := by let α := { N : Submodule R M // N.FG } constructor · intro H let f : α ↪o Submodule R M := OrderEmbedding.subtype _ exact OrderEmbedding.wellFoundedLT f.dual · intro H constructor intro N obtain ⟨⟨N₀, h₁⟩, e : N₀ ≤ N, h₂⟩ := WellFounded.has_min H.wf { N' : α | N'.1 ≤ N } ⟨⟨⊥, Submodule.fg_bot⟩, @bot_le _ _ _ N⟩ convert h₁ refine (e.antisymm ?_).symm by_contra h₃ obtain ⟨x, hx₁ : x ∈ N, hx₂ : x ∉ N₀⟩ := Set.not_subset.mp h₃ apply hx₂ rw [eq_of_le_of_not_lt (le_sup_right : N₀ ≤ _) (h₂ ⟨_, Submodule.FG.sup ⟨{x}, by rw [Finset.coe_singleton]⟩ h₁⟩ <| sup_le ((Submodule.span_singleton_le_iff_mem _ _).mpr hx₁) e)] exact (le_sup_left : (R ∙ x) ≤ _) (Submodule.mem_span_singleton_self _) /-- A module is Noetherian iff every nonempty set of submodules has a maximal submodule among them. -/ theorem set_has_maximal_iff_noetherian : (∀ a : Set <| Submodule R M, a.Nonempty → ∃ M' ∈ a, ∀ I ∈ a, ¬M' < I) ↔ IsNoetherian R M := by rw [isNoetherian_iff, WellFounded.wellFounded_iff_has_min] /-- A module is Noetherian iff every increasing chain of submodules stabilizes. -/ theorem monotone_stabilizes_iff_noetherian : (∀ f : ℕ →o Submodule R M, ∃ n, ∀ m, n ≤ m → f n = f m) ↔ IsNoetherian R M := by rw [isNoetherian_iff', wellFoundedGT_iff_monotone_chain_condition] variable [IsNoetherian R M] open Filter /-- For an endomorphism of a Noetherian module, any sufficiently large iterate has disjoint kernel and range. -/ theorem Module.End.eventually_disjoint_ker_pow_range_pow (f : End R M) : ∀ᶠ n in atTop, Disjoint (LinearMap.ker (f ^ n)) (LinearMap.range (f ^ n)) := by obtain ⟨n, hn : ∀ m, n ≤ m → LinearMap.ker (f ^ n) = LinearMap.ker (f ^ m)⟩ := monotone_stabilizes_iff_noetherian.mpr inferInstance f.iterateKer refine eventually_atTop.mpr ⟨n, fun m hm ↦ disjoint_iff.mpr ?_⟩ rw [← hn _ hm, Submodule.eq_bot_iff] rintro - ⟨hx, ⟨x, rfl⟩⟩ apply pow_map_zero_of_le hm replace hx : x ∈ LinearMap.ker (f ^ (n + m)) := by simpa [f.pow_apply n, f.pow_apply m, ← f.pow_apply (n + m), ← iterate_add_apply] using hx rwa [← hn _ (n.le_add_right m)] at hx lemma LinearMap.eventually_iSup_ker_pow_eq (f : M →ₗ[R] M) : ∀ᶠ n in atTop, ⨆ m, LinearMap.ker (f ^ m) = LinearMap.ker (f ^ n) := by obtain ⟨n, hn : ∀ m, n ≤ m → ker (f ^ n) = ker (f ^ m)⟩ := monotone_stabilizes_iff_noetherian.mpr inferInstance f.iterateKer refine eventually_atTop.mpr ⟨n, fun m hm ↦ ?_⟩ refine le_antisymm (iSup_le fun l ↦ ?_) (le_iSup (fun i ↦ LinearMap.ker (f ^ i)) m) rcases le_or_gt m l with h | h · rw [← hn _ (hm.trans h), hn _ hm] · exact f.iterateKer.monotone h.le end /-- A (semi)ring is Noetherian if it is Noetherian as a module over itself, i.e. all its ideals are finitely generated. -/ abbrev IsNoetherianRing (R) [Semiring R] := IsNoetherian R R theorem isNoetherianRing_iff {R} [Semiring R] : IsNoetherianRing R ↔ IsNoetherian R R := Iff.rfl /-- A ring is Noetherian if and only if all its ideals are finitely-generated. -/ theorem isNoetherianRing_iff_ideal_fg (R : Type*) [Semiring R] : IsNoetherianRing R ↔ ∀ I : Ideal R, I.FG := isNoetherianRing_iff.trans isNoetherian_def
.lake/packages/mathlib/Mathlib/RingTheory/Noetherian/UniqueFactorizationDomain.lean
import Mathlib.RingTheory.Noetherian.Defs import Mathlib.RingTheory.UniqueFactorizationDomain.Ideal /-! # Noetherian domains have unique factorization ## Main results - IsNoetherianRing.wfDvdMonoid -/ variable {R : Type*} [CommSemiring R] [IsDomain R] -- see Note [lower instance priority] instance (priority := 100) IsNoetherianRing.wfDvdMonoid [h : IsNoetherianRing R] : WfDvdMonoid R := WfDvdMonoid.of_setOf_isPrincipal_wellFoundedOn_gt h.wf.wellFoundedOn
.lake/packages/mathlib/Mathlib/RingTheory/Noetherian/Orzech.lean
import Mathlib.Algebra.Module.Submodule.IterateMapComap import Mathlib.Order.PartialSups import Mathlib.RingTheory.Noetherian.Basic import Mathlib.RingTheory.OrzechProperty /-! # Noetherian rings have the Orzech property ## Main results * `IsNoetherian.injective_of_surjective_of_injective`: if `M` and `N` are `R`-modules for a ring `R` (not necessarily commutative), `M` is Noetherian, `i : N →ₗ[R] M` is injective, `f : N →ₗ[R] M` is surjective, then `f` is also injective. * `IsNoetherianRing.orzechProperty`: Any Noetherian ring satisfies the Orzech property. -/ open Set Filter Pointwise open IsNoetherian Submodule Function section universe w variable {R M P : Type*} {N : Type w} [Ring R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] [AddCommGroup P] [Module R P] [IsNoetherian R M] /-- **Orzech's theorem** for Noetherian modules: if `R` is a ring (not necessarily commutative), `M` and `N` are `R`-modules, `M` is Noetherian, `i : N →ₗ[R] M` is injective, `f : N →ₗ[R] M` is surjective, then `f` is also injective. The proof here is adapted from Djoković's paper *Epimorphisms of modules which must be isomorphisms* [djokovic1973], utilizing `LinearMap.iterateMapComap`. See also Orzech's original paper: *Onto endomorphisms are isomorphisms* [orzech1971]. -/ theorem IsNoetherian.injective_of_surjective_of_injective (i f : N →ₗ[R] M) (hi : Injective i) (hf : Surjective f) : Injective f := by haveI := isNoetherian_of_injective i hi obtain ⟨n, H⟩ := monotone_stabilizes_iff_noetherian.2 ‹_› ⟨_, monotone_nat_of_le_succ <| f.iterateMapComap_le_succ i ⊥ (by simp)⟩ exact LinearMap.ker_eq_bot.1 <| bot_unique <| f.ker_le_of_iterateMapComap_eq_succ i ⊥ n (H _ (Nat.le_succ _)) hf hi /-- **Orzech's theorem** for Noetherian modules: if `R` is a ring (not necessarily commutative), `M` is a Noetherian `R`-module, `N` is a submodule, `f : N →ₗ[R] M` is surjective, then `f` is also injective. -/ theorem IsNoetherian.injective_of_surjective_of_submodule {N : Submodule R M} (f : N →ₗ[R] M) (hf : Surjective f) : Injective f := IsNoetherian.injective_of_surjective_of_injective N.subtype f N.injective_subtype hf /-- Any surjective endomorphism of a Noetherian module is injective. -/ theorem IsNoetherian.injective_of_surjective_endomorphism (f : M →ₗ[R] M) (s : Surjective f) : Injective f := IsNoetherian.injective_of_surjective_of_injective _ f (LinearEquiv.refl _ _).injective s /-- Any surjective endomorphism of a Noetherian module is bijective. -/ theorem IsNoetherian.bijective_of_surjective_endomorphism (f : M →ₗ[R] M) (s : Surjective f) : Bijective f := ⟨IsNoetherian.injective_of_surjective_endomorphism f s, s⟩ /-- If `M ⊕ N` embeds into `M`, for `M` Noetherian over `R`, then `N` is trivial. -/ theorem IsNoetherian.subsingleton_of_prod_injective (f : M × N →ₗ[R] M) (i : Injective f) : Subsingleton N := .intro fun x y ↦ by have h := IsNoetherian.injective_of_surjective_of_injective f _ i LinearMap.fst_surjective simpa using h (show LinearMap.fst R M N (0, x) = LinearMap.fst R M N (0, y) from rfl) /-- If `M ⊕ N` embeds into `M`, for `M` Noetherian over `R`, then `N` is trivial. -/ @[simps!] def IsNoetherian.equivPUnitOfProdInjective (f : M × N →ₗ[R] M) (i : Injective f) : N ≃ₗ[R] PUnit.{w + 1} := haveI := IsNoetherian.subsingleton_of_prod_injective f i .ofSubsingleton _ _ end /-- Any Noetherian ring satisfies Orzech property. See also `IsNoetherian.injective_of_surjective_of_submodule` and `IsNoetherian.injective_of_surjective_of_injective`. -/ instance (priority := 100) IsNoetherianRing.orzechProperty (R) [Ring R] [IsNoetherianRing R] : OrzechProperty R where injective_of_surjective_of_submodule' {M} := letI := Module.addCommMonoidToAddCommGroup R (M := M) IsNoetherian.injective_of_surjective_of_submodule
.lake/packages/mathlib/Mathlib/RingTheory/Noetherian/OfPrime.lean
import Mathlib.RingTheory.Ideal.Oka import Mathlib.RingTheory.Noetherian.Defs import Mathlib.RingTheory.Ideal.BigOperators /-! # Noetherian rings and prime ideals ## Main results - `IsNoetherianRing.of_prime`: a ring where all prime ideals are finitely generated is a noetherian ring ## References - [cohen1950]: *Commutative rings with restricted minimum condition*, I. S. Cohen, Theorem 2 -/ variable {R : Type*} [CommRing R] namespace Ideal open Set Finset /-- `Ideal.FG` is an Oka predicate. -/ theorem isOka_fg : IsOka (FG (R := R)) where top := ⟨{1}, by simp⟩ oka {I a} hsup hcolon := by classical obtain ⟨_, f, hf⟩ := Submodule.fg_iff_exists_fin_generating_family.1 hsup obtain ⟨_, i, hi⟩ := Submodule.fg_iff_exists_fin_generating_family.1 hcolon rw [submodule_span_eq] at hf have H k : ∃ r : R, ∃ p ∈ I, r * a + p = f k := by apply mem_span_singleton_sup.1 rw [sup_comm, ← hf] exact mem_span_range_self choose! r p p_mem_I Hf using H refine ⟨image p univ ∪ image (a • i) univ, le_antisymm ?_ (fun y hy ↦ ?_)⟩ <;> simp only [coe_union, coe_image, coe_univ, image_univ, Pi.smul_apply, span_union] · simp only [sup_le_iff, span_le, range_subset_iff, smul_eq_mul] exact ⟨p_mem_I, fun _ ↦ mul_comm a _ ▸ mem_colon_singleton.1 (hi ▸ mem_span_range_self)⟩ · rw [Submodule.mem_sup] obtain ⟨s, H⟩ := mem_span_range_iff_exists_fun.1 (hf ▸ Ideal.mem_sup_left hy) simp_rw [← Hf] at H ring_nf at H rw [sum_add_distrib, ← sum_mul, add_comm] at H refine ⟨(∑ k, s k * p k), sum_mem _ (fun _ _ ↦ mul_mem_left _ _ mem_span_range_self), (∑ k, s k * r k) * a, ?_, H⟩ rw [mul_comm, ← smul_eq_mul, range_smul, ← submodule_span_eq, Submodule.span_smul, hi] exact smul_mem_smul_set <| mem_colon_singleton.2 <| (I.add_mem_iff_right <| I.sum_mem (fun _ _ ↦ mul_mem_left _ _ <| p_mem_I _)).1 (H ▸ hy) end Ideal open Ideal /-- If all prime ideals in a commutative ring are finitely generated, so are all other ideals. -/ theorem IsNoetherianRing.of_prime (H : ∀ I : Ideal R, I.IsPrime → I.FG) : IsNoetherianRing R := by refine ⟨isOka_fg.forall_of_forall_prime' (fun C hC₁ hC₂ I hI h ↦ ⟨sSup C, ?_, h⟩) H⟩ obtain ⟨G, hG⟩ := h obtain ⟨J, J_mem_C, G_subset_J⟩ : ∃ J ∈ C, (G : Set R) ⊆ J := by refine hC₂.directedOn.exists_mem_subset_of_finset_subset_biUnion ⟨I, hI⟩ (fun _ hx ↦ ?_) simp only [Set.mem_iUnion, SetLike.mem_coe, exists_prop] exact (Submodule.mem_sSup_of_directed ⟨I, hI⟩ hC₂.directedOn).1 <| hG ▸ subset_span hx suffices J_eq_sSup : J = sSup C from J_eq_sSup ▸ J_mem_C exact le_antisymm (le_sSup J_mem_C) (hG ▸ Ideal.span_le.2 G_subset_J) /-- If all non-zero prime ideals in a commutative ring are finitely generated, so are all other ideals. -/ theorem IsNoetherianRing.of_prime_ne_bot (H : ∀ I : Ideal R, I.IsPrime → I ≠ ⊥ → I.FG) : IsNoetherianRing R := .of_prime fun I hi ↦ (eq_or_ne I ⊥).elim (· ▸ Submodule.fg_bot) <| H _ hi
.lake/packages/mathlib/Mathlib/RingTheory/Coprime/Lemmas.lean
import Mathlib.Algebra.BigOperators.Ring.Finset import Mathlib.Data.Fintype.Basic import Mathlib.Data.Int.GCD import Mathlib.RingTheory.Coprime.Basic /-! # Additional lemmas about elements of a ring satisfying `IsCoprime` and elements of a monoid satisfying `IsRelPrime` These lemmas are in a separate file to the definition of `IsCoprime` or `IsRelPrime` as they require more imports. Notably, this includes lemmas about `Finset.prod` as this requires importing BigOperators, and lemmas about `Pow` since these are easiest to prove via `Finset.prod`. -/ universe u v open scoped Function -- required for scoped `on` notation section IsCoprime variable {R : Type u} {I : Type v} [CommSemiring R] {x y z : R} {s : I → R} {t : Finset I} section theorem Int.isCoprime_iff_gcd_eq_one {m n : ℤ} : IsCoprime m n ↔ Int.gcd m n = 1 := by constructor · rintro ⟨a, b, h⟩ refine Nat.dvd_one.mp (Int.gcd_dvd_iff.mpr ⟨a, b, ?_⟩) rwa [mul_comm m, mul_comm n, eq_comm] · rw [← Int.ofNat_inj, IsCoprime, Int.gcd_eq_gcd_ab, mul_comm m, mul_comm n, Nat.cast_one] intro h exact ⟨_, _, h⟩ instance : DecidableRel (IsCoprime : ℤ → ℤ → Prop) := fun m n => decidable_of_iff (Int.gcd m n = 1) Int.isCoprime_iff_gcd_eq_one.symm @[simp, norm_cast] theorem Nat.isCoprime_iff_coprime {m n : ℕ} : IsCoprime (m : ℤ) n ↔ Nat.Coprime m n := by rw [Int.isCoprime_iff_gcd_eq_one, Int.gcd_natCast_natCast] alias ⟨IsCoprime.natCoprime, Nat.Coprime.isCoprime⟩ := Nat.isCoprime_iff_coprime @[deprecated (since := "2025-08-25")] alias IsCoprime.nat_coprime := IsCoprime.natCoprime theorem Nat.Coprime.cast {R : Type*} [CommRing R] {a b : ℕ} (h : Nat.Coprime a b) : IsCoprime (a : R) (b : R) := mod_cast h.isCoprime.intCast theorem ne_zero_or_ne_zero_of_nat_coprime {A : Type u} [CommRing A] [Nontrivial A] {a b : ℕ} (h : Nat.Coprime a b) : (a : A) ≠ 0 ∨ (b : A) ≠ 0 := IsCoprime.ne_zero_or_ne_zero (R := A) <| by simpa only [map_natCast] using IsCoprime.map (Nat.Coprime.isCoprime h) (Int.castRingHom A) theorem IsCoprime.prod_left (h : ∀ i ∈ t, IsCoprime (s i) x) : IsCoprime (∏ i ∈ t, s i) x := by induction t using Finset.cons_induction with | empty => apply isCoprime_one_left | cons b t hbt ih => rw [Finset.prod_cons] rw [Finset.forall_mem_cons] at h exact h.1.mul_left (ih h.2) theorem IsCoprime.prod_right : (∀ i ∈ t, IsCoprime x (s i)) → IsCoprime x (∏ i ∈ t, s i) := by simpa only [isCoprime_comm] using IsCoprime.prod_left (R := R) theorem IsCoprime.prod_left_iff : IsCoprime (∏ i ∈ t, s i) x ↔ ∀ i ∈ t, IsCoprime (s i) x := by classical refine Finset.induction_on t (iff_of_true isCoprime_one_left fun _ ↦ by simp) fun b t hbt ih ↦ ?_ rw [Finset.prod_insert hbt, IsCoprime.mul_left_iff, ih, Finset.forall_mem_insert] theorem IsCoprime.prod_right_iff : IsCoprime x (∏ i ∈ t, s i) ↔ ∀ i ∈ t, IsCoprime x (s i) := by simpa only [isCoprime_comm] using IsCoprime.prod_left_iff (R := R) theorem IsCoprime.of_prod_left (H1 : IsCoprime (∏ i ∈ t, s i) x) (i : I) (hit : i ∈ t) : IsCoprime (s i) x := IsCoprime.prod_left_iff.1 H1 i hit theorem IsCoprime.of_prod_right (H1 : IsCoprime x (∏ i ∈ t, s i)) (i : I) (hit : i ∈ t) : IsCoprime x (s i) := IsCoprime.prod_right_iff.1 H1 i hit theorem Finset.prod_dvd_of_coprime (Hs : (t : Set I).Pairwise (IsCoprime on s)) (Hs1 : (∀ i ∈ t, s i ∣ z)) : (∏ x ∈ t, s x) ∣ z := by classical induction t using Finset.induction_on with | empty => simp | insert a r har ih => rw [Finset.prod_insert har] refine IsCoprime.mul_dvd ?_ ?_ ?_ · refine IsCoprime.prod_right fun i hir ↦ ?_ exact Hs (by simp) (by simp [hir]) (ne_of_mem_of_not_mem hir har).symm · exact Hs1 a (Finset.mem_insert_self a r) · refine ih (Hs.mono ?_) fun i hi ↦ Hs1 i <| Finset.mem_insert_of_mem hi simp only [Finset.coe_insert, Set.subset_insert] theorem Fintype.prod_dvd_of_coprime [Fintype I] (Hs : Pairwise (IsCoprime on s)) (Hs1 : ∀ i, s i ∣ z) : (∏ x, s x) ∣ z := Finset.prod_dvd_of_coprime (Hs.set_pairwise _) fun i _ ↦ Hs1 i end open Finset theorem exists_sum_eq_one_iff_pairwise_coprime [DecidableEq I] (h : t.Nonempty) : (∃ μ : I → R, (∑ i ∈ t, μ i * ∏ j ∈ t \ {i}, s j) = 1) ↔ Pairwise (IsCoprime on fun i : t ↦ s i) := by induction h using Finset.Nonempty.cons_induction with | singleton => simp [exists_apply_eq, Pairwise, Function.onFun] | cons a t hat h ih => rw [pairwise_cons'] have mem : ∀ x ∈ t, a ∈ insert a t \ {x} := fun x hx ↦ by rw [mem_sdiff, mem_singleton] exact ⟨mem_insert_self _ _, fun ha ↦ hat (ha ▸ hx)⟩ constructor · rintro ⟨μ, hμ⟩ rw [sum_cons, cons_eq_insert, sdiff_singleton_eq_erase, erase_insert hat] at hμ refine ⟨ih.mp ⟨Pi.single h.choose (μ a * s h.choose) + μ * fun _ ↦ s a, ?_⟩, fun b hb ↦ ?_⟩ · rw [prod_eq_mul_prod_diff_singleton h.choose_spec, ← mul_assoc, ← @if_pos _ _ h.choose_spec R (_ * _) 0, ← sum_pi_single', ← sum_add_distrib] at hμ rw [← hμ, sum_congr rfl] intro x hx convert add_mul (R := R) _ _ _ using 2 · by_cases hx : x = h.choose · rw [hx, Pi.single_eq_same, Pi.single_eq_same] · rw [Pi.single_eq_of_ne hx, Pi.single_eq_of_ne hx, zero_mul] · convert (mul_assoc _ _ _).symm rw [prod_eq_prod_diff_singleton_mul (mem x hx), mul_comm, sdiff_sdiff_comm, sdiff_singleton_eq_erase a, erase_insert hat] · have : IsCoprime (s b) (s a) := ⟨μ a * ∏ i ∈ t \ {b}, s i, ∑ i ∈ t, μ i * ∏ j ∈ t \ {i}, s j, ?_⟩ · exact ⟨this.symm, this⟩ rw [mul_assoc, ← prod_eq_prod_diff_singleton_mul hb, sum_mul, ← hμ, sum_congr rfl] intro x hx rw [mul_assoc] congr rw [prod_eq_prod_diff_singleton_mul (mem x hx) _] congr 2 rw [sdiff_sdiff_comm, sdiff_singleton_eq_erase a, erase_insert hat] · rintro ⟨hs, Hb⟩ obtain ⟨μ, hμ⟩ := ih.mpr hs obtain ⟨u, v, huv⟩ := IsCoprime.prod_left fun b hb ↦ (Hb b hb).right use fun i ↦ if i = a then u else v * μ i have hμ' : (∑ i ∈ t, v * ((μ i * ∏ j ∈ t \ {i}, s j) * s a)) = v * s a := by rw [← mul_sum, ← sum_mul, hμ, one_mul] rw [sum_cons, cons_eq_insert, sdiff_singleton_eq_erase, erase_insert hat] simp only [↓reduceIte, ite_mul] rw [← huv, ← hμ', sum_congr rfl] intro x hx rw [mul_assoc, if_neg fun ha : x = a ↦ hat (ha.casesOn hx)] rw [mul_assoc] congr rw [prod_eq_prod_diff_singleton_mul (mem x hx) _] congr 2 rw [sdiff_sdiff_comm, sdiff_singleton_eq_erase a, erase_insert hat] theorem exists_sum_eq_one_iff_pairwise_coprime' [Fintype I] [Nonempty I] [DecidableEq I] : (∃ μ : I → R, (∑ i : I, μ i * ∏ j ∈ {i}ᶜ, s j) = 1) ↔ Pairwise (IsCoprime on s) := by convert exists_sum_eq_one_iff_pairwise_coprime Finset.univ_nonempty (s := s) using 1 simp only [pairwise_subtype_iff_pairwise_finset', coe_univ, Set.pairwise_univ] theorem pairwise_coprime_iff_coprime_prod [DecidableEq I] : Pairwise (IsCoprime on fun i : t ↦ s i) ↔ ∀ i ∈ t, IsCoprime (s i) (∏ j ∈ t \ {i}, s j) := by rw [Finset.pairwise_subtype_iff_pairwise_finset'] refine ⟨fun hp i hi ↦ IsCoprime.prod_right_iff.mpr fun j hj ↦ ?_, fun hp ↦ ?_⟩ · rw [Finset.mem_sdiff, Finset.mem_singleton] at hj exact (hp hj.1 hi hj.2).symm · rintro i hi j hj h apply IsCoprime.prod_right_iff.mp (hp i hi) exact Finset.mem_sdiff.mpr ⟨hj, fun f ↦ h (Finset.mem_singleton.mp f).symm⟩ variable {m n : ℕ} theorem IsCoprime.pow_left (H : IsCoprime x y) : IsCoprime (x ^ m) y := by rw [← Finset.card_range m, ← Finset.prod_const] exact IsCoprime.prod_left fun _ _ ↦ H theorem IsCoprime.pow_right (H : IsCoprime x y) : IsCoprime x (y ^ n) := by rw [← Finset.card_range n, ← Finset.prod_const] exact IsCoprime.prod_right fun _ _ ↦ H theorem IsCoprime.pow (H : IsCoprime x y) : IsCoprime (x ^ m) (y ^ n) := H.pow_left.pow_right theorem IsCoprime.pow_left_iff (hm : 0 < m) : IsCoprime (x ^ m) y ↔ IsCoprime x y := by refine ⟨fun h ↦ ?_, IsCoprime.pow_left⟩ rw [← Finset.card_range m, ← Finset.prod_const] at h exact h.of_prod_left 0 (Finset.mem_range.mpr hm) theorem IsCoprime.pow_right_iff (hm : 0 < m) : IsCoprime x (y ^ m) ↔ IsCoprime x y := isCoprime_comm.trans <| (IsCoprime.pow_left_iff hm).trans <| isCoprime_comm theorem IsCoprime.pow_iff (hm : 0 < m) (hn : 0 < n) : IsCoprime (x ^ m) (y ^ n) ↔ IsCoprime x y := (IsCoprime.pow_left_iff hm).trans <| IsCoprime.pow_right_iff hn end IsCoprime section RelPrime variable {α I} [CommMonoid α] [DecompositionMonoid α] {x y z : α} {s : I → α} {t : Finset I} theorem IsRelPrime.prod_left : (∀ i ∈ t, IsRelPrime (s i) x) → IsRelPrime (∏ i ∈ t, s i) x := by classical refine Finset.induction_on t (fun _ ↦ isRelPrime_one_left) fun b t hbt ih H ↦ ?_ rw [Finset.prod_insert hbt] rw [Finset.forall_mem_insert] at H exact H.1.mul_left (ih H.2) theorem IsRelPrime.prod_right : (∀ i ∈ t, IsRelPrime x (s i)) → IsRelPrime x (∏ i ∈ t, s i) := by simpa only [isRelPrime_comm] using IsRelPrime.prod_left (α := α) theorem IsRelPrime.prod_left_iff : IsRelPrime (∏ i ∈ t, s i) x ↔ ∀ i ∈ t, IsRelPrime (s i) x := by classical refine Finset.induction_on t (iff_of_true isRelPrime_one_left fun _ ↦ by simp) fun b t hbt ih ↦ ?_ rw [Finset.prod_insert hbt, IsRelPrime.mul_left_iff, ih, Finset.forall_mem_insert] theorem IsRelPrime.prod_right_iff : IsRelPrime x (∏ i ∈ t, s i) ↔ ∀ i ∈ t, IsRelPrime x (s i) := by simpa only [isRelPrime_comm] using IsRelPrime.prod_left_iff (α := α) theorem IsRelPrime.of_prod_left (H1 : IsRelPrime (∏ i ∈ t, s i) x) (i : I) (hit : i ∈ t) : IsRelPrime (s i) x := IsRelPrime.prod_left_iff.1 H1 i hit theorem IsRelPrime.of_prod_right (H1 : IsRelPrime x (∏ i ∈ t, s i)) (i : I) (hit : i ∈ t) : IsRelPrime x (s i) := IsRelPrime.prod_right_iff.1 H1 i hit theorem Finset.prod_dvd_of_isRelPrime : (t : Set I).Pairwise (IsRelPrime on s) → (∀ i ∈ t, s i ∣ z) → (∏ x ∈ t, s x) ∣ z := by classical exact Finset.induction_on t (fun _ _ ↦ one_dvd z) (by intro a r har ih Hs Hs1 rw [Finset.prod_insert har] have aux1 : a ∈ (↑(insert a r) : Set I) := Finset.mem_insert_self a r refine (IsRelPrime.prod_right fun i hir ↦ Hs aux1 (Finset.mem_insert_of_mem hir) <| by rintro rfl exact har hir).mul_dvd (Hs1 a aux1) (ih (Hs.mono ?_) fun i hi ↦ Hs1 i <| Finset.mem_insert_of_mem hi) simp only [Finset.coe_insert, Set.subset_insert]) theorem Fintype.prod_dvd_of_isRelPrime [Fintype I] (Hs : Pairwise (IsRelPrime on s)) (Hs1 : ∀ i, s i ∣ z) : (∏ x, s x) ∣ z := Finset.prod_dvd_of_isRelPrime (Hs.set_pairwise _) fun i _ ↦ Hs1 i theorem pairwise_isRelPrime_iff_isRelPrime_prod [DecidableEq I] : Pairwise (IsRelPrime on fun i : t ↦ s i) ↔ ∀ i ∈ t, IsRelPrime (s i) (∏ j ∈ t \ {i}, s j) := by refine ⟨fun hp i hi ↦ IsRelPrime.prod_right_iff.mpr fun j hj ↦ ?_, fun hp ↦ ?_⟩ · rw [Finset.mem_sdiff, Finset.mem_singleton] at hj obtain ⟨hj, ji⟩ := hj exact @hp ⟨i, hi⟩ ⟨j, hj⟩ fun h ↦ ji (congrArg Subtype.val h).symm · rintro ⟨i, hi⟩ ⟨j, hj⟩ h apply IsRelPrime.prod_right_iff.mp (hp i hi) grind namespace IsRelPrime variable {m n : ℕ} theorem pow_left (H : IsRelPrime x y) : IsRelPrime (x ^ m) y := by rw [← Finset.card_range m, ← Finset.prod_const] exact IsRelPrime.prod_left fun _ _ ↦ H theorem pow_right (H : IsRelPrime x y) : IsRelPrime x (y ^ n) := by rw [← Finset.card_range n, ← Finset.prod_const] exact IsRelPrime.prod_right fun _ _ ↦ H theorem pow (H : IsRelPrime x y) : IsRelPrime (x ^ m) (y ^ n) := H.pow_left.pow_right theorem pow_left_iff (hm : 0 < m) : IsRelPrime (x ^ m) y ↔ IsRelPrime x y := by refine ⟨fun h ↦ ?_, IsRelPrime.pow_left⟩ rw [← Finset.card_range m, ← Finset.prod_const] at h exact h.of_prod_left 0 (Finset.mem_range.mpr hm) theorem pow_right_iff (hm : 0 < m) : IsRelPrime x (y ^ m) ↔ IsRelPrime x y := isRelPrime_comm.trans <| (IsRelPrime.pow_left_iff hm).trans <| isRelPrime_comm theorem pow_iff (hm : 0 < m) (hn : 0 < n) : IsRelPrime (x ^ m) (y ^ n) ↔ IsRelPrime x y := (IsRelPrime.pow_left_iff hm).trans (IsRelPrime.pow_right_iff hn) end IsRelPrime end RelPrime
.lake/packages/mathlib/Mathlib/RingTheory/Coprime/Basic.lean
import Mathlib.Algebra.Group.Action.Units import Mathlib.Algebra.Group.Nat.Units import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.Ring.Divisibility.Basic import Mathlib.Algebra.Ring.Hom.Defs import Mathlib.Logic.Basic import Mathlib.Tactic.Ring /-! # Coprime elements of a ring or monoid ## Main definition * `IsCoprime x y`: that `x` and `y` are coprime, defined to be the existence of `a` and `b` such that `a * x + b * y = 1`. Note that elements with no common divisors (`IsRelPrime`) are not necessarily coprime, e.g., the multivariate polynomials `x₁` and `x₂` are not coprime. The two notions are equivalent in Bézout rings, see `isRelPrime_iff_isCoprime`. This file also contains lemmas about `IsRelPrime` parallel to `IsCoprime`. See also `RingTheory.Coprime.Lemmas` for further development of coprime elements. -/ universe u v section CommSemiring variable {R : Type u} [CommSemiring R] (x y z w : R) /-- The proposition that `x` and `y` are coprime, defined to be the existence of `a` and `b` such that `a * x + b * y = 1`. Note that elements with no common divisors are not necessarily coprime, e.g., the multivariate polynomials `x₁` and `x₂` are not coprime. -/ def IsCoprime : Prop := ∃ a b, a * x + b * y = 1 variable {x y z w} @[symm] theorem IsCoprime.symm (H : IsCoprime x y) : IsCoprime y x := let ⟨a, b, H⟩ := H ⟨b, a, by rw [add_comm, H]⟩ theorem isCoprime_comm : IsCoprime x y ↔ IsCoprime y x := ⟨IsCoprime.symm, IsCoprime.symm⟩ theorem isCoprime_self : IsCoprime x x ↔ IsUnit x := ⟨fun ⟨a, b, h⟩ => .of_mul_eq_one (a + b) <| by rwa [mul_comm, add_mul], fun h => let ⟨b, hb⟩ := isUnit_iff_exists_inv'.1 h ⟨b, 0, by rwa [zero_mul, add_zero]⟩⟩ theorem isCoprime_zero_left : IsCoprime 0 x ↔ IsUnit x := ⟨fun ⟨a, b, H⟩ => .of_mul_eq_one b <| by rwa [mul_zero, zero_add, mul_comm] at H, fun H => let ⟨b, hb⟩ := isUnit_iff_exists_inv'.1 H ⟨1, b, by rwa [one_mul, zero_add]⟩⟩ theorem isCoprime_zero_right : IsCoprime x 0 ↔ IsUnit x := isCoprime_comm.trans isCoprime_zero_left theorem not_isCoprime_zero_zero [Nontrivial R] : ¬IsCoprime (0 : R) 0 := mt isCoprime_zero_right.mp not_isUnit_zero lemma IsCoprime.intCast {R : Type*} [CommRing R] {a b : ℤ} (h : IsCoprime a b) : IsCoprime (a : R) (b : R) := by rcases h with ⟨u, v, H⟩ use u, v rw_mod_cast [H] exact Int.cast_one /-- If a 2-vector `p` satisfies `IsCoprime (p 0) (p 1)`, then `p ≠ 0`. -/ theorem IsCoprime.ne_zero [Nontrivial R] {p : Fin 2 → R} (h : IsCoprime (p 0) (p 1)) : p ≠ 0 := by rintro rfl exact not_isCoprime_zero_zero h theorem IsCoprime.ne_zero_or_ne_zero [Nontrivial R] (h : IsCoprime x y) : x ≠ 0 ∨ y ≠ 0 := by apply not_or_of_imp rintro rfl rfl exact not_isCoprime_zero_zero h theorem isCoprime_one_left : IsCoprime 1 x := ⟨1, 0, by rw [one_mul, zero_mul, add_zero]⟩ theorem isCoprime_one_right : IsCoprime x 1 := ⟨0, 1, by rw [one_mul, zero_mul, zero_add]⟩ theorem IsCoprime.dvd_of_dvd_mul_right (H1 : IsCoprime x z) (H2 : x ∣ y * z) : x ∣ y := by let ⟨a, b, H⟩ := H1 rw [← mul_one y, ← H, mul_add, ← mul_assoc, mul_left_comm] exact dvd_add (dvd_mul_left _ _) (H2.mul_left _) theorem IsCoprime.dvd_of_dvd_mul_left (H1 : IsCoprime x y) (H2 : x ∣ y * z) : x ∣ z := by let ⟨a, b, H⟩ := H1 rw [← one_mul z, ← H, add_mul, mul_right_comm, mul_assoc b] exact dvd_add (dvd_mul_left _ _) (H2.mul_left _) theorem IsCoprime.mul_left (H1 : IsCoprime x z) (H2 : IsCoprime y z) : IsCoprime (x * y) z := let ⟨a, b, h1⟩ := H1 let ⟨c, d, h2⟩ := H2 ⟨a * c, a * x * d + b * c * y + b * d * z, calc a * c * (x * y) + (a * x * d + b * c * y + b * d * z) * z _ = (a * x + b * z) * (c * y + d * z) := by ring _ = 1 := by rw [h1, h2, mul_one] ⟩ theorem IsCoprime.mul_right (H1 : IsCoprime x y) (H2 : IsCoprime x z) : IsCoprime x (y * z) := by rw [isCoprime_comm] at H1 H2 ⊢ exact H1.mul_left H2 theorem IsCoprime.mul_dvd (H : IsCoprime x y) (H1 : x ∣ z) (H2 : y ∣ z) : x * y ∣ z := by obtain ⟨a, b, h⟩ := H rw [← mul_one z, ← h, mul_add] apply dvd_add · rw [mul_comm z, mul_assoc] exact (mul_dvd_mul_left _ H2).mul_left _ · rw [mul_comm b, ← mul_assoc] exact (mul_dvd_mul_right H1 _).mul_right _ theorem IsCoprime.of_mul_left_left (H : IsCoprime (x * y) z) : IsCoprime x z := let ⟨a, b, h⟩ := H ⟨a * y, b, by rwa [mul_right_comm, mul_assoc]⟩ theorem IsCoprime.of_mul_left_right (H : IsCoprime (x * y) z) : IsCoprime y z := by rw [mul_comm] at H exact H.of_mul_left_left theorem IsCoprime.of_mul_right_left (H : IsCoprime x (y * z)) : IsCoprime x y := by rw [isCoprime_comm] at H ⊢ exact H.of_mul_left_left theorem IsCoprime.of_mul_right_right (H : IsCoprime x (y * z)) : IsCoprime x z := by rw [mul_comm] at H exact H.of_mul_right_left theorem IsCoprime.mul_left_iff : IsCoprime (x * y) z ↔ IsCoprime x z ∧ IsCoprime y z := ⟨fun H => ⟨H.of_mul_left_left, H.of_mul_left_right⟩, fun ⟨H1, H2⟩ => H1.mul_left H2⟩ theorem IsCoprime.mul_right_iff : IsCoprime x (y * z) ↔ IsCoprime x y ∧ IsCoprime x z := by rw [isCoprime_comm, IsCoprime.mul_left_iff, isCoprime_comm, @isCoprime_comm _ _ z] theorem IsCoprime.of_isCoprime_of_dvd_left (h : IsCoprime y z) (hdvd : x ∣ y) : IsCoprime x z := by obtain ⟨d, rfl⟩ := hdvd exact IsCoprime.of_mul_left_left h theorem IsCoprime.of_isCoprime_of_dvd_right (h : IsCoprime z y) (hdvd : x ∣ y) : IsCoprime z x := (h.symm.of_isCoprime_of_dvd_left hdvd).symm @[gcongr] theorem IsCoprime.mono (h₁ : x ∣ y) (h₂ : z ∣ w) (h : IsCoprime y w) : IsCoprime x z := h.of_isCoprime_of_dvd_left h₁ |>.of_isCoprime_of_dvd_right h₂ theorem IsCoprime.isUnit_of_dvd (H : IsCoprime x y) (d : x ∣ y) : IsUnit x := let ⟨k, hk⟩ := d isCoprime_self.1 <| IsCoprime.of_mul_right_left <| show IsCoprime x (x * k) from hk ▸ H theorem IsCoprime.isUnit_of_dvd' {a b x : R} (h : IsCoprime a b) (ha : x ∣ a) (hb : x ∣ b) : IsUnit x := (h.of_isCoprime_of_dvd_left ha).isUnit_of_dvd hb theorem IsCoprime.isRelPrime {a b : R} (h : IsCoprime a b) : IsRelPrime a b := fun _ ↦ h.isUnit_of_dvd' theorem IsCoprime.map (H : IsCoprime x y) {S : Type v} [CommSemiring S] (f : R →+* S) : IsCoprime (f x) (f y) := let ⟨a, b, h⟩ := H ⟨f a, f b, by rw [← f.map_mul, ← f.map_mul, ← f.map_add, h, f.map_one]⟩ theorem IsCoprime.of_add_mul_left_left (h : IsCoprime (x + y * z) y) : IsCoprime x y := let ⟨a, b, H⟩ := h ⟨a, a * z + b, by simpa only [add_mul, mul_add, add_assoc, add_comm, add_left_comm, mul_assoc, mul_comm, mul_left_comm] using H⟩ theorem IsCoprime.of_add_mul_right_left (h : IsCoprime (x + z * y) y) : IsCoprime x y := by rw [mul_comm] at h exact h.of_add_mul_left_left theorem IsCoprime.of_add_mul_left_right (h : IsCoprime x (y + x * z)) : IsCoprime x y := by rw [isCoprime_comm] at h ⊢ exact h.of_add_mul_left_left theorem IsCoprime.of_add_mul_right_right (h : IsCoprime x (y + z * x)) : IsCoprime x y := by rw [mul_comm] at h exact h.of_add_mul_left_right theorem IsCoprime.of_mul_add_left_left (h : IsCoprime (y * z + x) y) : IsCoprime x y := by rw [add_comm] at h exact h.of_add_mul_left_left theorem IsCoprime.of_mul_add_right_left (h : IsCoprime (z * y + x) y) : IsCoprime x y := by rw [add_comm] at h exact h.of_add_mul_right_left theorem IsCoprime.of_mul_add_left_right (h : IsCoprime x (x * z + y)) : IsCoprime x y := by rw [add_comm] at h exact h.of_add_mul_left_right theorem IsCoprime.of_mul_add_right_right (h : IsCoprime x (z * x + y)) : IsCoprime x y := by rw [add_comm] at h exact h.of_add_mul_right_right theorem IsRelPrime.of_add_mul_left_left (h : IsRelPrime (x + y * z) y) : IsRelPrime x y := fun _ hx hy ↦ h (dvd_add hx <| dvd_mul_of_dvd_left hy z) hy theorem IsRelPrime.of_add_mul_right_left (h : IsRelPrime (x + z * y) y) : IsRelPrime x y := (mul_comm z y ▸ h).of_add_mul_left_left theorem IsRelPrime.of_add_mul_left_right (h : IsRelPrime x (y + x * z)) : IsRelPrime x y := by rw [isRelPrime_comm] at h ⊢ exact h.of_add_mul_left_left theorem IsRelPrime.of_add_mul_right_right (h : IsRelPrime x (y + z * x)) : IsRelPrime x y := (mul_comm z x ▸ h).of_add_mul_left_right theorem IsRelPrime.of_mul_add_left_left (h : IsRelPrime (y * z + x) y) : IsRelPrime x y := (add_comm _ x ▸ h).of_add_mul_left_left theorem IsRelPrime.of_mul_add_right_left (h : IsRelPrime (z * y + x) y) : IsRelPrime x y := (add_comm _ x ▸ h).of_add_mul_right_left theorem IsRelPrime.of_mul_add_left_right (h : IsRelPrime x (x * z + y)) : IsRelPrime x y := (add_comm _ y ▸ h).of_add_mul_left_right theorem IsRelPrime.of_mul_add_right_right (h : IsRelPrime x (z * x + y)) : IsRelPrime x y := (add_comm _ y ▸ h).of_add_mul_right_right end CommSemiring section ScalarTower variable {R G : Type*} [CommSemiring R] [Group G] [MulAction G R] [SMulCommClass G R R] [IsScalarTower G R R] (x : G) (y z : R) theorem isCoprime_group_smul_left : IsCoprime (x • y) z ↔ IsCoprime y z := ⟨fun ⟨a, b, h⟩ => ⟨x • a, b, by rwa [smul_mul_assoc, ← mul_smul_comm]⟩, fun ⟨a, b, h⟩ => ⟨x⁻¹ • a, b, by rwa [smul_mul_smul_comm, inv_mul_cancel, one_smul]⟩⟩ theorem isCoprime_group_smul_right : IsCoprime y (x • z) ↔ IsCoprime y z := isCoprime_comm.trans <| (isCoprime_group_smul_left x z y).trans isCoprime_comm theorem isCoprime_group_smul : IsCoprime (x • y) (x • z) ↔ IsCoprime y z := (isCoprime_group_smul_left x y (x • z)).trans (isCoprime_group_smul_right x y z) end ScalarTower section CommSemiringUnit variable {R : Type*} [CommSemiring R] {x u v : R} theorem isCoprime_mul_unit_left_left (hu : IsUnit x) (y z : R) : IsCoprime (x * y) z ↔ IsCoprime y z := let ⟨u, hu⟩ := hu hu ▸ isCoprime_group_smul_left u y z theorem isCoprime_mul_unit_left_right (hu : IsUnit x) (y z : R) : IsCoprime y (x * z) ↔ IsCoprime y z := let ⟨u, hu⟩ := hu hu ▸ isCoprime_group_smul_right u y z theorem isCoprime_mul_unit_right_left (hu : IsUnit x) (y z : R) : IsCoprime (y * x) z ↔ IsCoprime y z := mul_comm x y ▸ isCoprime_mul_unit_left_left hu y z theorem isCoprime_mul_unit_right_right (hu : IsUnit x) (y z : R) : IsCoprime y (z * x) ↔ IsCoprime y z := mul_comm x z ▸ isCoprime_mul_unit_left_right hu y z theorem isCoprime_mul_units_left (hu : IsUnit u) (hv : IsUnit v) (y z : R) : IsCoprime (u * y) (v * z) ↔ IsCoprime y z := Iff.trans (isCoprime_mul_unit_left_left hu _ _) (isCoprime_mul_unit_left_right hv _ _) theorem isCoprime_mul_units_right (hu : IsUnit u) (hv : IsUnit v) (y z : R) : IsCoprime (y * u) (z * v) ↔ IsCoprime y z := Iff.trans (isCoprime_mul_unit_right_left hu _ _) (isCoprime_mul_unit_right_right hv _ _) theorem isCoprime_mul_unit_left (hu : IsUnit x) (y z : R) : IsCoprime (x * y) (x * z) ↔ IsCoprime y z := isCoprime_mul_units_left hu hu _ _ theorem isCoprime_mul_unit_right (hu : IsUnit x) (y z : R) : IsCoprime (y * x) (z * x) ↔ IsCoprime y z := isCoprime_mul_units_right hu hu _ _ end CommSemiringUnit namespace IsCoprime section CommRing variable {R : Type u} [CommRing R] theorem add_mul_left_left {x y : R} (h : IsCoprime x y) (z : R) : IsCoprime (x + y * z) y := @of_add_mul_left_left R _ _ _ (-z) <| by simpa only [mul_neg, add_neg_cancel_right] using h theorem add_mul_right_left {x y : R} (h : IsCoprime x y) (z : R) : IsCoprime (x + z * y) y := by rw [mul_comm] exact h.add_mul_left_left z theorem add_mul_left_right {x y : R} (h : IsCoprime x y) (z : R) : IsCoprime x (y + x * z) := by rw [isCoprime_comm] exact h.symm.add_mul_left_left z theorem add_mul_right_right {x y : R} (h : IsCoprime x y) (z : R) : IsCoprime x (y + z * x) := by rw [isCoprime_comm] exact h.symm.add_mul_right_left z theorem mul_add_left_left {x y : R} (h : IsCoprime x y) (z : R) : IsCoprime (y * z + x) y := by rw [add_comm] exact h.add_mul_left_left z theorem mul_add_right_left {x y : R} (h : IsCoprime x y) (z : R) : IsCoprime (z * y + x) y := by rw [add_comm] exact h.add_mul_right_left z theorem mul_add_left_right {x y : R} (h : IsCoprime x y) (z : R) : IsCoprime x (x * z + y) := by rw [add_comm] exact h.add_mul_left_right z theorem mul_add_right_right {x y : R} (h : IsCoprime x y) (z : R) : IsCoprime x (z * x + y) := by rw [add_comm] exact h.add_mul_right_right z theorem add_mul_left_left_iff {x y z : R} : IsCoprime (x + y * z) y ↔ IsCoprime x y := ⟨of_add_mul_left_left, fun h => h.add_mul_left_left z⟩ theorem add_mul_right_left_iff {x y z : R} : IsCoprime (x + z * y) y ↔ IsCoprime x y := ⟨of_add_mul_right_left, fun h => h.add_mul_right_left z⟩ theorem add_mul_left_right_iff {x y z : R} : IsCoprime x (y + x * z) ↔ IsCoprime x y := ⟨of_add_mul_left_right, fun h => h.add_mul_left_right z⟩ theorem add_mul_right_right_iff {x y z : R} : IsCoprime x (y + z * x) ↔ IsCoprime x y := ⟨of_add_mul_right_right, fun h => h.add_mul_right_right z⟩ theorem mul_add_left_left_iff {x y z : R} : IsCoprime (y * z + x) y ↔ IsCoprime x y := ⟨of_mul_add_left_left, fun h => h.mul_add_left_left z⟩ theorem mul_add_right_left_iff {x y z : R} : IsCoprime (z * y + x) y ↔ IsCoprime x y := ⟨of_mul_add_right_left, fun h => h.mul_add_right_left z⟩ theorem mul_add_left_right_iff {x y z : R} : IsCoprime x (x * z + y) ↔ IsCoprime x y := ⟨of_mul_add_left_right, fun h => h.mul_add_left_right z⟩ theorem mul_add_right_right_iff {x y z : R} : IsCoprime x (z * x + y) ↔ IsCoprime x y := ⟨of_mul_add_right_right, fun h => h.mul_add_right_right z⟩ theorem neg_left {x y : R} (h : IsCoprime x y) : IsCoprime (-x) y := by obtain ⟨a, b, h⟩ := h use -a, b rwa [neg_mul_neg] theorem neg_left_iff (x y : R) : IsCoprime (-x) y ↔ IsCoprime x y := ⟨fun h => neg_neg x ▸ h.neg_left, neg_left⟩ theorem neg_right {x y : R} (h : IsCoprime x y) : IsCoprime x (-y) := h.symm.neg_left.symm theorem neg_right_iff (x y : R) : IsCoprime x (-y) ↔ IsCoprime x y := ⟨fun h => neg_neg y ▸ h.neg_right, neg_right⟩ theorem neg_neg {x y : R} (h : IsCoprime x y) : IsCoprime (-x) (-y) := h.neg_left.neg_right theorem neg_neg_iff (x y : R) : IsCoprime (-x) (-y) ↔ IsCoprime x y := (neg_left_iff _ _).trans (neg_right_iff _ _) section abs variable [LinearOrder R] [AddLeftMono R] lemma abs_left_iff (x y : R) : IsCoprime |x| y ↔ IsCoprime x y := by cases le_or_gt 0 x with | inl h => rw [abs_of_nonneg h] | inr h => rw [abs_of_neg h, IsCoprime.neg_left_iff] lemma abs_left {x y : R} (h : IsCoprime x y) : IsCoprime |x| y := abs_left_iff _ _ |>.2 h lemma abs_right_iff (x y : R) : IsCoprime x |y| ↔ IsCoprime x y := by rw [isCoprime_comm, IsCoprime.abs_left_iff, isCoprime_comm] lemma abs_right {x y : R} (h : IsCoprime x y) : IsCoprime x |y| := abs_right_iff _ _ |>.2 h theorem abs_abs_iff (x y : R) : IsCoprime |x| |y| ↔ IsCoprime x y := (abs_left_iff _ _).trans (abs_right_iff _ _) theorem abs_abs {x y : R} (h : IsCoprime x y) : IsCoprime |x| |y| := h.abs_left.abs_right end abs end CommRing theorem sq_add_sq_ne_zero {R : Type*} [CommRing R] [LinearOrder R] [IsStrictOrderedRing R] {a b : R} (h : IsCoprime a b) : a ^ 2 + b ^ 2 ≠ 0 := by intro h' obtain ⟨ha, hb⟩ := (add_eq_zero_iff_of_nonneg (sq_nonneg _) (sq_nonneg _)).mp h' obtain rfl := eq_zero_of_pow_eq_zero ha obtain rfl := eq_zero_of_pow_eq_zero hb exact not_isCoprime_zero_zero h end IsCoprime /-- `IsCoprime` is not a useful definition for `Nat`; consider using `Nat.Coprime` instead. -/ @[simp] lemma Nat.isCoprime_iff {m n : ℕ} : IsCoprime m n ↔ m = 1 ∨ n = 1 := by refine ⟨fun ⟨a, b, H⟩ => ?_, fun h => ?_⟩ · simp_rw [Nat.add_eq_one_iff, mul_eq_one, mul_eq_zero] at H exact H.symm.imp (·.1.2) (·.2.2) · obtain rfl | rfl := h · exact isCoprime_one_left · exact isCoprime_one_right /-- `IsCoprime` is not a useful definition for `PNat`; consider using `Nat.Coprime` instead. -/ lemma PNat.isCoprime_iff {m n : ℕ+} : IsCoprime (m : ℕ) n ↔ m = 1 ∨ n = 1 := by simp /-- `IsCoprime` is not a useful definition if an inverse is available. -/ @[simp] lemma Semifield.isCoprime_iff {R : Type*} [Semifield R] {m n : R} : IsCoprime m n ↔ m ≠ 0 ∨ n ≠ 0 := by obtain rfl | hn := eq_or_ne n 0 · simp [isCoprime_zero_right] suffices IsCoprime m n by simpa [hn] refine ⟨0, n⁻¹, ?_⟩ simp [inv_mul_cancel₀ hn] namespace IsRelPrime variable {R} [CommRing R] {x y : R} theorem add_mul_left_left (h : IsRelPrime x y) (z : R) : IsRelPrime (x + y * z) y := @of_add_mul_left_left R _ _ _ (-z) <| by simpa only [mul_neg, add_neg_cancel_right] using h theorem add_mul_right_left (h : IsRelPrime x y) (z : R) : IsRelPrime (x + z * y) y := mul_comm z y ▸ h.add_mul_left_left z theorem add_mul_left_right (h : IsRelPrime x y) (z : R) : IsRelPrime x (y + x * z) := (h.symm.add_mul_left_left z).symm theorem add_mul_right_right (h : IsRelPrime x y) (z : R) : IsRelPrime x (y + z * x) := (h.symm.add_mul_right_left z).symm theorem mul_add_left_left (h : IsRelPrime x y) (z : R) : IsRelPrime (y * z + x) y := add_comm x _ ▸ h.add_mul_left_left z theorem mul_add_right_left (h : IsRelPrime x y) (z : R) : IsRelPrime (z * y + x) y := add_comm x _ ▸ h.add_mul_right_left z theorem mul_add_left_right (h : IsRelPrime x y) (z : R) : IsRelPrime x (x * z + y) := add_comm y _ ▸ h.add_mul_left_right z theorem mul_add_right_right (h : IsRelPrime x y) (z : R) : IsRelPrime x (z * x + y) := add_comm y _ ▸ h.add_mul_right_right z variable {z} theorem add_mul_left_left_iff : IsRelPrime (x + y * z) y ↔ IsRelPrime x y := ⟨of_add_mul_left_left, fun h ↦ h.add_mul_left_left z⟩ theorem add_mul_right_left_iff : IsRelPrime (x + z * y) y ↔ IsRelPrime x y := ⟨of_add_mul_right_left, fun h ↦ h.add_mul_right_left z⟩ theorem add_mul_left_right_iff : IsRelPrime x (y + x * z) ↔ IsRelPrime x y := ⟨of_add_mul_left_right, fun h ↦ h.add_mul_left_right z⟩ theorem add_mul_right_right_iff : IsRelPrime x (y + z * x) ↔ IsRelPrime x y := ⟨of_add_mul_right_right, fun h ↦ h.add_mul_right_right z⟩ theorem mul_add_left_left_iff {x y z : R} : IsRelPrime (y * z + x) y ↔ IsRelPrime x y := ⟨of_mul_add_left_left, fun h ↦ h.mul_add_left_left z⟩ theorem mul_add_right_left_iff {x y z : R} : IsRelPrime (z * y + x) y ↔ IsRelPrime x y := ⟨of_mul_add_right_left, fun h ↦ h.mul_add_right_left z⟩ theorem mul_add_left_right_iff {x y z : R} : IsRelPrime x (x * z + y) ↔ IsRelPrime x y := ⟨of_mul_add_left_right, fun h ↦ h.mul_add_left_right z⟩ theorem mul_add_right_right_iff {x y z : R} : IsRelPrime x (z * x + y) ↔ IsRelPrime x y := ⟨of_mul_add_right_right, fun h ↦ h.mul_add_right_right z⟩ theorem neg_left (h : IsRelPrime x y) : IsRelPrime (-x) y := fun _ ↦ (h <| dvd_neg.mp ·) theorem neg_right (h : IsRelPrime x y) : IsRelPrime x (-y) := h.symm.neg_left.symm protected theorem neg_neg (h : IsRelPrime x y) : IsRelPrime (-x) (-y) := h.neg_left.neg_right theorem neg_left_iff (x y : R) : IsRelPrime (-x) y ↔ IsRelPrime x y := ⟨fun h ↦ neg_neg x ▸ h.neg_left, neg_left⟩ theorem neg_right_iff (x y : R) : IsRelPrime x (-y) ↔ IsRelPrime x y := ⟨fun h ↦ neg_neg y ▸ h.neg_right, neg_right⟩ theorem neg_neg_iff (x y : R) : IsRelPrime (-x) (-y) ↔ IsRelPrime x y := (neg_left_iff _ _).trans (neg_right_iff _ _) end IsRelPrime
.lake/packages/mathlib/Mathlib/RingTheory/Coprime/Ideal.lean
import Mathlib.LinearAlgebra.DFinsupp import Mathlib.RingTheory.Ideal.BigOperators import Mathlib.RingTheory.Ideal.Operations /-! # An additional lemma about coprime ideals This lemma generalises `exists_sum_eq_one_iff_pairwise_coprime` to the case of non-principal ideals. It is on a separate file due to import requirements. -/ namespace Ideal variable {ι R : Type*} [CommSemiring R] /-- A finite family of ideals is pairwise coprime (that is, any two of them generate the whole ring) iff when taking all the possible intersections of all but one of these ideals, the resulting family of ideals still generate the whole ring. For example with three ideals : `I ⊔ J = I ⊔ K = J ⊔ K = ⊤ ↔ (I ⊓ J) ⊔ (I ⊓ K) ⊔ (J ⊓ K) = ⊤`. When ideals are all of the form `I i = R ∙ s i`, this is equivalent to the `exists_sum_eq_one_iff_pairwise_coprime` lemma. -/ theorem iSup_iInf_eq_top_iff_pairwise {t : Finset ι} (h : t.Nonempty) (I : ι → Ideal R) : (⨆ i ∈ t, ⨅ (j) (_ : j ∈ t) (_ : j ≠ i), I j) = ⊤ ↔ (t : Set ι).Pairwise fun i j => I i ⊔ I j = ⊤ := by haveI : DecidableEq ι := Classical.decEq ι rw [eq_top_iff_one, Submodule.mem_iSup_finset_iff_exists_sum] refine h.cons_induction ?_ ?_ <;> clear t h · simp only [Finset.sum_singleton, Finset.coe_singleton, Set.pairwise_singleton, iff_true] refine fun a => ⟨fun i => if h : i = a then ⟨1, ?_⟩ else 0, ?_⟩ · simp [h] · simp only [dif_pos, Submodule.coe_mk] intro a t hat h ih rw [Finset.coe_cons, Set.pairwise_insert_of_symmetric fun i j (h : I i ⊔ I j = ⊤) ↦ (sup_comm _ _).trans h] constructor · rintro ⟨μ, hμ⟩ rw [Finset.sum_cons] at hμ refine ⟨ih.mp ⟨Pi.single h.choose ⟨μ a, ?a1⟩ + fun i => ⟨μ i, ?a2⟩, ?a3⟩, fun b hb ab => ?a4⟩ case a1 => have := Submodule.coe_mem (μ a) rw [mem_iInf] at this ⊢ --for some reason `simp only [mem_iInf]` times out intro i specialize this i rw [mem_iInf, mem_iInf] at this ⊢ intro hi _ apply this (Finset.subset_cons _ hi) rintro rfl exact hat hi case a2 => have := Submodule.coe_mem (μ i) simp only [mem_iInf] at this ⊢ intro j hj ij exact this _ (Finset.subset_cons _ hj) ij case a3 => rw [← @if_pos _ _ h.choose_spec R (μ a) 0, ← Finset.sum_pi_single', ← Finset.sum_add_distrib] at hμ convert hμ rename_i i _ rw [Pi.add_apply, Submodule.coe_add, Submodule.coe_mk] by_cases hi : i = h.choose · rw [hi, Pi.single_eq_same, Pi.single_eq_same, Submodule.coe_mk] · rw [Pi.single_eq_of_ne hi, Pi.single_eq_of_ne hi, Submodule.coe_zero] case a4 => rw [eq_top_iff_one, Submodule.mem_sup] rw [add_comm] at hμ refine ⟨_, ?_, _, ?_, hμ⟩ · refine sum_mem _ fun x hx => ?_ have := Submodule.coe_mem (μ x) simp only [mem_iInf] at this apply this _ (Finset.mem_cons_self _ _) rintro rfl exact hat hx · have := Submodule.coe_mem (μ a) simp only [mem_iInf] at this exact this _ (Finset.subset_cons _ hb) ab.symm · rintro ⟨hs, Hb⟩ obtain ⟨μ, hμ⟩ := ih.mpr hs have := sup_iInf_eq_top fun b hb => Hb b hb (ne_of_mem_of_not_mem hb hat).symm rw [eq_top_iff_one, Submodule.mem_sup] at this obtain ⟨u, hu, v, hv, huv⟩ := this refine ⟨fun i => if hi : i = a then ⟨v, ?_⟩ else ⟨u * μ i, ?_⟩, ?_⟩ · simp only [mem_iInf] at hv ⊢ intro j hj ij rw [Finset.mem_cons, ← hi] at hj exact hv _ (hj.resolve_left ij) · have := Submodule.coe_mem (μ i) simp only [mem_iInf] at this ⊢ intro j hj ij rcases Finset.mem_cons.mp hj with (rfl | hj) · exact mul_mem_right _ _ hu · exact mul_mem_left _ _ (this _ hj ij) · dsimp only rw [Finset.sum_cons, dif_pos rfl, add_comm] rw [← mul_one u] at huv rw [← huv, ← hμ, Finset.mul_sum] congr 1 apply Finset.sum_congr rfl intro j hj rw [dif_neg] rintro rfl exact hat hj end Ideal
.lake/packages/mathlib/Mathlib/RingTheory/DiscreteValuationRing/TFAE.lean
import Mathlib.RingTheory.DedekindDomain.Basic import Mathlib.RingTheory.DiscreteValuationRing.Basic import Mathlib.RingTheory.Finiteness.Ideal import Mathlib.RingTheory.Ideal.Cotangent /-! # Equivalent conditions for DVR In `IsDiscreteValuationRing.TFAE`, we show that the following are equivalent for a Noetherian local domain that is not a field `(R, m, k)`: - `R` is a discrete valuation ring - `R` is a valuation ring - `R` is a Dedekind domain - `R` is integrally closed with a unique prime ideal - `m` is principal - `dimₖ m/m² = 1` - Every nonzero ideal is a power of `m`. Also see `tfae_of_isNoetherianRing_of_isLocalRing_of_isDomain` for a version without `¬ IsField R`. -/ variable (R : Type*) [CommRing R] open scoped Multiplicative open IsLocalRing Module theorem exists_maximalIdeal_pow_eq_of_principal [IsNoetherianRing R] [IsLocalRing R] [IsDomain R] (h' : (maximalIdeal R).IsPrincipal) (I : Ideal R) (hI : I ≠ ⊥) : ∃ n : ℕ, I = maximalIdeal R ^ n := by by_cases h : IsField R · let _ := h.toField exact ⟨0, by simp [(eq_bot_or_eq_top I).resolve_left hI]⟩ classical obtain ⟨x, hx : _ = Ideal.span _⟩ := h' by_cases hI' : I = ⊤ · use 0; rw [pow_zero, hI', Ideal.one_eq_top] have H : ∀ r : R, ¬IsUnit r ↔ x ∣ r := fun r => (SetLike.ext_iff.mp hx r).trans Ideal.mem_span_singleton have : x ≠ 0 := by rintro rfl apply Ring.ne_bot_of_isMaximal_of_not_isField (maximalIdeal.isMaximal R) h simp [hx] have hx' := IsDiscreteValuationRing.irreducible_of_span_eq_maximalIdeal x this hx have H' : ∀ r : R, r ≠ 0 → r ∈ nonunits R → ∃ n : ℕ, Associated (x ^ n) r := by intro r hr₁ hr₂ obtain ⟨f, hf₁, rfl, hf₂⟩ := (WfDvdMonoid.not_unit_iff_exists_factors_eq r hr₁).mp hr₂ have : ∀ b ∈ f, Associated x b := by intro b hb exact Irreducible.associated_of_dvd hx' (hf₁ b hb) ((H b).mp (hf₁ b hb).1) clear hr₁ hr₂ hf₁ induction f using Multiset.induction with | empty => exact (hf₂ rfl).elim | cons fa fs fh => ?_ rcases eq_or_ne fs ∅ with (rfl | hf') · use 1 rw [pow_one, Multiset.prod_cons, Multiset.empty_eq_zero, Multiset.prod_zero, mul_one] exact this _ (Multiset.mem_cons_self _ _) · obtain ⟨n, hn⟩ := fh hf' fun b hb => this _ (Multiset.mem_cons_of_mem hb) use n + 1 rw [pow_add, Multiset.prod_cons, mul_comm, pow_one] exact Associated.mul_mul (this _ (Multiset.mem_cons_self _ _)) hn have : ∃ n : ℕ, x ^ n ∈ I := by obtain ⟨r, hr₁, hr₂⟩ : ∃ r : R, r ∈ I ∧ r ≠ 0 := by by_contra! h; apply hI; rw [eq_bot_iff]; exact h obtain ⟨n, u, rfl⟩ := H' r hr₂ (le_maximalIdeal hI' hr₁) use n rwa [← I.unit_mul_mem_iff_mem u.isUnit, mul_comm] use Nat.find this apply le_antisymm · change ∀ s ∈ I, s ∈ _ by_contra! hI'' obtain ⟨s, hs₁, hs₂⟩ := hI'' apply hs₂ by_cases hs₃ : s = 0; · rw [hs₃]; exact zero_mem _ obtain ⟨n, u, rfl⟩ := H' s hs₃ (le_maximalIdeal hI' hs₁) rw [mul_comm, Ideal.unit_mul_mem_iff_mem _ u.isUnit] at hs₁ ⊢ apply Ideal.pow_le_pow_right (Nat.find_min' this hs₁) apply Ideal.pow_mem_pow exact (H _).mpr (dvd_refl _) · rw [hx, Ideal.span_singleton_pow, Ideal.span_le, Set.singleton_subset_iff] exact Nat.find_spec this theorem maximalIdeal_isPrincipal_of_isDedekindDomain [IsLocalRing R] [IsDomain R] [IsDedekindDomain R] : (maximalIdeal R).IsPrincipal := by classical by_cases ne_bot : maximalIdeal R = ⊥ · rw [ne_bot]; infer_instance obtain ⟨a, ha₁, ha₂⟩ : ∃ a ∈ maximalIdeal R, a ≠ (0 : R) := by by_contra! h'; apply ne_bot; rwa [eq_bot_iff] have hle : Ideal.span {a} ≤ maximalIdeal R := by rwa [Ideal.span_le, Set.singleton_subset_iff] have : (Ideal.span {a}).radical = maximalIdeal R := by rw [Ideal.radical_eq_sInf] apply le_antisymm · exact sInf_le ⟨hle, inferInstance⟩ · refine le_sInf fun I hI => (eq_maximalIdeal <| hI.2.isMaximal (fun e => ha₂ ?_)).ge rw [← Ideal.span_singleton_eq_bot, eq_bot_iff, ← e]; exact hI.1 have : ∃ n, maximalIdeal R ^ n ≤ Ideal.span {a} := by rw [← this]; apply Ideal.exists_radical_pow_le_of_fg; exact IsNoetherian.noetherian _ rcases hn : Nat.find this with - | n · have := Nat.find_spec this rw [hn, pow_zero, Ideal.one_eq_top] at this exact (Ideal.IsMaximal.ne_top inferInstance (eq_top_iff.mpr <| this.trans hle)).elim obtain ⟨b, hb₁, hb₂⟩ : ∃ b ∈ maximalIdeal R ^ n, b ∉ Ideal.span {a} := by by_contra! h'; rw [Nat.find_eq_iff] at hn; exact hn.2 n n.lt_succ_self fun x hx => h' x hx have hb₃ : ∀ m ∈ maximalIdeal R, ∃ k : R, k * a = b * m := by intro m hm; rw [← Ideal.mem_span_singleton']; apply Nat.find_spec this rw [hn, pow_succ]; exact Ideal.mul_mem_mul hb₁ hm have hb₄ : b ≠ 0 := by rintro rfl; apply hb₂; exact zero_mem _ let K := FractionRing R let x : K := algebraMap R K b / algebraMap R K a let M := Submodule.map (Algebra.linearMap R K) (maximalIdeal R) have ha₃ : algebraMap R K a ≠ 0 := IsFractionRing.to_map_eq_zero_iff.not.mpr ha₂ by_cases hx : ∀ y ∈ M, x * y ∈ M · have := isIntegral_of_smul_mem_submodule M ?_ ?_ x hx · obtain ⟨y, e⟩ := IsIntegrallyClosed.algebraMap_eq_of_integral this refine (hb₂ (Ideal.mem_span_singleton'.mpr ⟨y, ?_⟩)).elim apply IsFractionRing.injective R K rw [map_mul, e, div_mul_cancel₀ _ ha₃] · rw [Submodule.ne_bot_iff]; refine ⟨_, ⟨a, ha₁, rfl⟩, ?_⟩ exact (IsFractionRing.to_map_eq_zero_iff (K := K)).not.mpr ha₂ · apply Submodule.FG.map; exact IsNoetherian.noetherian _ · have : (M.map (DistribMulAction.toLinearMap R K x)).comap (Algebra.linearMap R K) = ⊤ := by contrapose! hx with h rintro m' ⟨m, hm, rfl : algebraMap R K m = m'⟩ obtain ⟨k, hk⟩ := hb₃ m hm have hk' : x * algebraMap R K m = algebraMap R K k := by rw [← mul_div_right_comm, ← map_mul, ← hk, map_mul, mul_div_cancel_right₀ _ ha₃] exact ⟨k, le_maximalIdeal h ⟨_, ⟨_, hm, rfl⟩, hk'⟩, hk'.symm⟩ obtain ⟨y, hy₁, hy₂⟩ : ∃ y ∈ maximalIdeal R, b * y = a := by rw [Ideal.eq_top_iff_one, Submodule.mem_comap] at this obtain ⟨_, ⟨y, hy, rfl⟩, hy' : x * algebraMap R K y = algebraMap R K 1⟩ := this rw [map_one, ← mul_div_right_comm, div_eq_one_iff_eq ha₃, ← map_mul] at hy' exact ⟨y, hy, IsFractionRing.injective R K hy'⟩ refine ⟨⟨y, ?_⟩⟩ apply le_antisymm · intro m hm; obtain ⟨k, hk⟩ := hb₃ m hm; rw [← hy₂, mul_comm, mul_assoc] at hk rw [← mul_left_cancel₀ hb₄ hk, mul_comm]; exact Ideal.mem_span_singleton'.mpr ⟨_, rfl⟩ · rwa [Submodule.span_le, Set.singleton_subset_iff] /-- Let `(R, m, k)` be a Noetherian local domain (possibly a field). The following are equivalent: 0. `R` is a PID 1. `R` is a valuation ring 2. `R` is a Dedekind domain 3. `R` is integrally closed with at most one non-zero prime ideal 4. `m` is principal 5. `dimₖ m/m² ≤ 1` 6. Every nonzero ideal is a power of `m`. Also see `IsDiscreteValuationRing.TFAE` for a version assuming `¬ IsField R`. -/ theorem tfae_of_isNoetherianRing_of_isLocalRing_of_isDomain [IsNoetherianRing R] [IsLocalRing R] [IsDomain R] : List.TFAE [IsPrincipalIdealRing R, ValuationRing R, IsDedekindDomain R, IsIntegrallyClosed R ∧ ∀ P : Ideal R, P ≠ ⊥ → P.IsPrime → P = maximalIdeal R, (maximalIdeal R).IsPrincipal, finrank (ResidueField R) (CotangentSpace R) ≤ 1, ∀ I ≠ ⊥, ∃ n : ℕ, I = maximalIdeal R ^ n] := by tfae_have 1 → 2 := fun _ ↦ inferInstance tfae_have 2 → 1 := fun _ ↦ ((IsBezout.TFAE (R := R)).out 0 1).mp ‹_› tfae_have 1 → 4 | H => ⟨inferInstance, fun P hP hP' ↦ eq_maximalIdeal (hP'.isMaximal hP)⟩ tfae_have 4 → 3 := fun ⟨h₁, h₂⟩ ↦ { h₁ with maximalOfPrime := (h₂ _ · · ▸ maximalIdeal.isMaximal R) } tfae_have 3 → 5 := fun h ↦ maximalIdeal_isPrincipal_of_isDedekindDomain R tfae_have 6 ↔ 5 := finrank_cotangentSpace_le_one_iff tfae_have 5 → 7 := exists_maximalIdeal_pow_eq_of_principal R tfae_have 7 → 2 := by rw [ValuationRing.iff_ideal_total] intro H constructor intro I J by_cases hI : I = ⊥; · order by_cases hJ : J = ⊥; · order obtain ⟨n, rfl⟩ := H I hI obtain ⟨m, rfl⟩ := H J hJ exact (le_total m n).imp Ideal.pow_le_pow_right Ideal.pow_le_pow_right tfae_finish /-- The following are equivalent for a Noetherian local domain that is not a field `(R, m, k)`: 0. `R` is a discrete valuation ring 1. `R` is a valuation ring 2. `R` is a Dedekind domain 3. `R` is integrally closed with a unique non-zero prime ideal 4. `m` is principal 5. `dimₖ m/m² = 1` 6. Every nonzero ideal is a power of `m`. Also see `tfae_of_isNoetherianRing_of_isLocalRing_of_isDomain` for a version without `¬ IsField R`. -/ theorem IsDiscreteValuationRing.TFAE [IsNoetherianRing R] [IsLocalRing R] [IsDomain R] (h : ¬IsField R) : List.TFAE [IsDiscreteValuationRing R, ValuationRing R, IsDedekindDomain R, IsIntegrallyClosed R ∧ ∃! P : Ideal R, P ≠ ⊥ ∧ P.IsPrime, (maximalIdeal R).IsPrincipal, finrank (ResidueField R) (CotangentSpace R) = 1, ∀ (I) (_ : I ≠ ⊥), ∃ n : ℕ, I = maximalIdeal R ^ n] := by have : finrank (ResidueField R) (CotangentSpace R) = 1 ↔ finrank (ResidueField R) (CotangentSpace R) ≤ 1 := by simp [Nat.le_one_iff_eq_zero_or_eq_one, finrank_cotangentSpace_eq_zero_iff, h] rw [this] have : maximalIdeal R ≠ ⊥ := isField_iff_maximalIdeal_eq.not.mp h convert tfae_of_isNoetherianRing_of_isLocalRing_of_isDomain R · exact ⟨fun _ ↦ inferInstance, fun h ↦ { h with not_a_field' := this }⟩ · exact ⟨fun h P h₁ h₂ ↦ h.unique ⟨h₁, h₂⟩ ⟨this, inferInstance⟩, fun H ↦ ⟨_, ⟨this, inferInstance⟩, fun P hP ↦ H P hP.1 hP.2⟩⟩ variable {R} lemma IsLocalRing.finrank_CotangentSpace_eq_one_iff [IsNoetherianRing R] [IsLocalRing R] [IsDomain R] : finrank (ResidueField R) (CotangentSpace R) = 1 ↔ IsDiscreteValuationRing R := by by_cases hR : IsField R · letI := hR.toField simp only [finrank_cotangentSpace_eq_zero, zero_ne_one, false_iff] exact fun h ↦ h.3 maximalIdeal_eq_bot · exact (IsDiscreteValuationRing.TFAE R hR).out 5 0 variable (R) lemma IsLocalRing.finrank_CotangentSpace_eq_one [IsDomain R] [IsDiscreteValuationRing R] : finrank (ResidueField R) (CotangentSpace R) = 1 := finrank_CotangentSpace_eq_one_iff.mpr ‹_› instance (priority := 100) IsDedekindDomain.isPrincipalIdealRing [IsLocalRing R] [IsDedekindDomain R] : IsPrincipalIdealRing R := ((tfae_of_isNoetherianRing_of_isLocalRing_of_isDomain R).out 2 0).mp ‹_›
.lake/packages/mathlib/Mathlib/RingTheory/DiscreteValuationRing/Basic.lean
import Mathlib.RingTheory.AdicCompletion.Basic import Mathlib.RingTheory.LocalRing.MaximalIdeal.Basic import Mathlib.RingTheory.LocalRing.RingHom.Basic import Mathlib.RingTheory.UniqueFactorizationDomain.Basic import Mathlib.RingTheory.Valuation.PrimeMultiplicity import Mathlib.RingTheory.Valuation.ValuationRing /-! # Discrete valuation rings This file defines discrete valuation rings (DVRs) and develops a basic interface for them. ## Important definitions There are various definitions of a DVR in the literature; we define a DVR to be a local PID which is not a field (the first definition in Wikipedia) and prove that this is equivalent to being a PID with a unique non-zero prime ideal (the definition in Serre's book "Local Fields"). Let R be an integral domain, assumed to be a principal ideal ring and a local ring. * `IsDiscreteValuationRing R` : a predicate expressing that R is a DVR. ### Definitions * `addVal R : AddValuation R ℕ∞` : the additive valuation on a DVR. * `toEuclideanDomain R : EuclideanDomain R` : a non-canonical structure of Euclidean domain on a DVR, where `x % y = 0` if `y ∣ x` and `x % y = x` otherwise. The GCD algorithm terminates in two steps. ## Implementation notes It's a theorem that an element of a DVR is a uniformizer if and only if it's irreducible. We do not hence define `Uniformizer` at all, because we can use `Irreducible` instead. ## Tags discrete valuation ring -/ universe u open Ideal IsLocalRing /-- An integral domain is a *discrete valuation ring* (DVR) if it's a local PID which is not a field. -/ class IsDiscreteValuationRing (R : Type u) [CommRing R] [IsDomain R] : Prop extends IsPrincipalIdealRing R, IsLocalRing R where not_a_field' : maximalIdeal R ≠ ⊥ namespace IsDiscreteValuationRing variable (R : Type u) [CommRing R] [IsDomain R] [IsDiscreteValuationRing R] theorem not_a_field : maximalIdeal R ≠ ⊥ := not_a_field' /-- A discrete valuation ring `R` is not a field. -/ theorem not_isField : ¬IsField R := IsLocalRing.isField_iff_maximalIdeal_eq.not.mpr (not_a_field R) variable {R} open PrincipalIdealRing theorem irreducible_of_span_eq_maximalIdeal {R : Type*} [CommSemiring R] [IsLocalRing R] [IsDomain R] (ϖ : R) (hϖ : ϖ ≠ 0) (h : maximalIdeal R = Ideal.span {ϖ}) : Irreducible ϖ := by have h2 : ¬IsUnit ϖ := show ϖ ∈ maximalIdeal R from h.symm ▸ Submodule.mem_span_singleton_self ϖ refine ⟨h2, ?_⟩ intro a b hab by_contra! h obtain ⟨ha : a ∈ maximalIdeal R, hb : b ∈ maximalIdeal R⟩ := h rw [h, mem_span_singleton'] at ha hb rcases ha with ⟨a, rfl⟩ rcases hb with ⟨b, rfl⟩ rw [show a * ϖ * (b * ϖ) = ϖ * (ϖ * (a * b)) by ring] at hab apply hϖ apply eq_zero_of_mul_eq_self_right _ hab.symm exact fun hh => h2 (isUnit_of_dvd_one ⟨_, hh.symm⟩) /-- An element of a DVR is irreducible iff it is a uniformizer, that is, generates the maximal ideal of `R`. -/ theorem irreducible_iff_uniformizer (ϖ : R) : Irreducible ϖ ↔ maximalIdeal R = Ideal.span {ϖ} := ⟨fun hϖ => (eq_maximalIdeal (isMaximal_of_irreducible hϖ)).symm, fun h => irreducible_of_span_eq_maximalIdeal ϖ (fun e => not_a_field R <| by rwa [h, span_singleton_eq_bot]) h⟩ theorem _root_.Irreducible.maximalIdeal_eq {ϖ : R} (h : Irreducible ϖ) : maximalIdeal R = Ideal.span {ϖ} := (irreducible_iff_uniformizer _).mp h variable (R) /-- Uniformizers exist in a DVR. -/ theorem exists_irreducible : ∃ ϖ : R, Irreducible ϖ := by simp_rw [irreducible_iff_uniformizer] exact (IsPrincipalIdealRing.principal <| maximalIdeal R).principal /-- Uniformizers exist in a DVR. -/ theorem exists_prime : ∃ ϖ : R, Prime ϖ := (exists_irreducible R).imp fun _ => irreducible_iff_prime.1 /-- An integral domain is a DVR iff it's a PID with a unique non-zero prime ideal. -/ theorem iff_pid_with_one_nonzero_prime (R : Type u) [CommRing R] [IsDomain R] : IsDiscreteValuationRing R ↔ IsPrincipalIdealRing R ∧ ∃! P : Ideal R, P ≠ ⊥ ∧ IsPrime P := by constructor · intro RDVR rcases id RDVR with ⟨Rlocal⟩ constructor · assumption use IsLocalRing.maximalIdeal R constructor · exact ⟨Rlocal, inferInstance⟩ · rintro Q ⟨hQ1, hQ2⟩ obtain ⟨q, rfl⟩ := (IsPrincipalIdealRing.principal Q).1 have hq : q ≠ 0 := by rintro rfl apply hQ1 simp rw [submodule_span_eq, span_singleton_prime hq] at hQ2 replace hQ2 := hQ2.irreducible rw [irreducible_iff_uniformizer] at hQ2 exact hQ2.symm · rintro ⟨RPID, Punique⟩ haveI : IsLocalRing R := IsLocalRing.of_unique_nonzero_prime Punique refine { not_a_field' := ?_ } rcases Punique with ⟨P, ⟨hP1, hP2⟩, _⟩ have hPM : P ≤ maximalIdeal R := le_maximalIdeal hP2.1 order theorem associated_of_irreducible {a b : R} (ha : Irreducible a) (hb : Irreducible b) : Associated a b := by rw [irreducible_iff_uniformizer] at ha hb rw [← span_singleton_eq_span_singleton, ← ha, hb] variable (R : Type*) /-- Alternative characterisation of discrete valuation rings. -/ def HasUnitMulPowIrreducibleFactorization [CommRing R] : Prop := ∃ p : R, Irreducible p ∧ ∀ {x : R}, x ≠ 0 → ∃ n : ℕ, Associated (p ^ n) x namespace HasUnitMulPowIrreducibleFactorization variable {R} [CommRing R] theorem unique_irreducible (hR : HasUnitMulPowIrreducibleFactorization R) ⦃p q : R⦄ (hp : Irreducible p) (hq : Irreducible q) : Associated p q := by rcases hR with ⟨ϖ, hϖ, hR⟩ suffices ∀ {p : R} (_ : Irreducible p), Associated p ϖ by apply Associated.trans (this hp) (this hq).symm clear hp hq p q intro p hp obtain ⟨n, hn⟩ := hR hp.ne_zero have : Irreducible (ϖ ^ n) := hn.symm.irreducible hp rcases lt_trichotomy n 1 with (H | rfl | H) · obtain rfl : n = 0 := by clear hn this revert H n decide simp [not_irreducible_one, pow_zero] at this · simpa only [pow_one] using hn.symm · obtain ⟨n, rfl⟩ : ∃ k, n = 1 + k + 1 := Nat.exists_eq_add_of_lt H rw [pow_succ'] at this rcases this.isUnit_or_isUnit rfl with (H0 | H0) · exact (hϖ.not_isUnit H0).elim · rw [add_comm, pow_succ'] at H0 exact (hϖ.not_isUnit (isUnit_of_mul_isUnit_left H0)).elim variable [IsDomain R] /-- An integral domain in which there is an irreducible element `p` such that every nonzero element is associated to a power of `p` is a unique factorization domain. See `IsDiscreteValuationRing.ofHasUnitMulPowIrreducibleFactorization`. -/ theorem toUniqueFactorizationMonoid (hR : HasUnitMulPowIrreducibleFactorization R) : UniqueFactorizationMonoid R := let p := Classical.choose hR let spec := Classical.choose_spec hR UniqueFactorizationMonoid.of_exists_prime_factors fun x hx => by use Multiset.replicate (Classical.choose (spec.2 hx)) p constructor · intro q hq have hpq := Multiset.eq_of_mem_replicate hq rw [hpq] refine ⟨spec.1.ne_zero, spec.1.not_isUnit, ?_⟩ intro a b h by_cases ha : a = 0 · rw [ha] simp only [true_or, dvd_zero] obtain ⟨m, u, rfl⟩ := spec.2 ha rw [mul_assoc, mul_left_comm, Units.dvd_mul_left] at h rw [Units.dvd_mul_right] by_cases hm : m = 0 · simp only [hm, one_mul, pow_zero] at h ⊢ right exact h left obtain ⟨m, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hm rw [pow_succ'] apply dvd_mul_of_dvd_left dvd_rfl _ · rw [Multiset.prod_replicate] exact Classical.choose_spec (spec.2 hx) theorem of_ufd_of_unique_irreducible [UniqueFactorizationMonoid R] (h₁ : ∃ p : R, Irreducible p) (h₂ : ∀ ⦃p q : R⦄, Irreducible p → Irreducible q → Associated p q) : HasUnitMulPowIrreducibleFactorization R := by obtain ⟨p, hp⟩ := h₁ refine ⟨p, hp, ?_⟩ intro x hx obtain ⟨fx, hfx⟩ := WfDvdMonoid.exists_factors x hx refine ⟨Multiset.card fx, ?_⟩ have H := hfx.2 rw [← Associates.mk_eq_mk_iff_associated] at H ⊢ rw [← H, ← Associates.prod_mk, Associates.mk_pow, ← Multiset.prod_replicate] congr 1 symm rw [Multiset.eq_replicate] simp only [true_and, and_imp, Multiset.card_map, Multiset.mem_map, exists_imp] rintro _ q hq rfl rw [Associates.mk_eq_mk_iff_associated] apply h₂ (hfx.1 _ hq) hp end HasUnitMulPowIrreducibleFactorization theorem aux_pid_of_ufd_of_unique_irreducible (R : Type u) [CommRing R] [IsDomain R] [UniqueFactorizationMonoid R] (h₁ : ∃ p : R, Irreducible p) (h₂ : ∀ ⦃p q : R⦄, Irreducible p → Irreducible q → Associated p q) : IsPrincipalIdealRing R := by classical constructor intro I by_cases I0 : I = ⊥ · rw [I0] use 0 simp only [Set.singleton_zero, Submodule.span_zero] obtain ⟨x, hxI, hx0⟩ : ∃ x ∈ I, x ≠ (0 : R) := I.ne_bot_iff.mp I0 obtain ⟨p, _, H⟩ := HasUnitMulPowIrreducibleFactorization.of_ufd_of_unique_irreducible h₁ h₂ have ex : ∃ n : ℕ, p ^ n ∈ I := by obtain ⟨n, u, rfl⟩ := H hx0 refine ⟨n, ?_⟩ simpa only [Units.mul_inv_cancel_right] using I.mul_mem_right (↑u⁻¹) hxI constructor use p ^ Nat.find ex change I = Ideal.span _ apply le_antisymm · intro r hr by_cases hr0 : r = 0 · simp only [hr0, Submodule.zero_mem] obtain ⟨n, u, rfl⟩ := H hr0 simp only [mem_span_singleton, Units.isUnit, IsUnit.dvd_mul_right] apply pow_dvd_pow apply Nat.find_min' simpa only [Units.mul_inv_cancel_right] using I.mul_mem_right (↑u⁻¹) hr · rw [span_singleton_le_iff_mem] exact Nat.find_spec ex /-- A unique factorization domain with at least one irreducible element in which all irreducible elements are associated is a discrete valuation ring. -/ theorem of_ufd_of_unique_irreducible {R : Type u} [CommRing R] [IsDomain R] [UniqueFactorizationMonoid R] (h₁ : ∃ p : R, Irreducible p) (h₂ : ∀ ⦃p q : R⦄, Irreducible p → Irreducible q → Associated p q) : IsDiscreteValuationRing R := by rw [iff_pid_with_one_nonzero_prime] haveI PID : IsPrincipalIdealRing R := aux_pid_of_ufd_of_unique_irreducible R h₁ h₂ obtain ⟨p, hp⟩ := h₁ refine ⟨PID, ⟨Ideal.span {p}, ⟨?_, ?_⟩, ?_⟩⟩ · rw [Submodule.ne_bot_iff] exact ⟨p, Ideal.mem_span_singleton.mpr (dvd_refl p), hp.ne_zero⟩ · rwa [Ideal.span_singleton_prime hp.ne_zero, ← UniqueFactorizationMonoid.irreducible_iff_prime] · intro I rw [← Submodule.IsPrincipal.span_singleton_generator I] rintro ⟨I0, hI⟩ apply span_singleton_eq_span_singleton.mpr apply h₂ _ hp rw [Ne, Submodule.span_singleton_eq_bot] at I0 rwa [UniqueFactorizationMonoid.irreducible_iff_prime, ← Ideal.span_singleton_prime I0] /-- An integral domain in which there is an irreducible element `p` such that every nonzero element is associated to a power of `p` is a discrete valuation ring. -/ theorem ofHasUnitMulPowIrreducibleFactorization {R : Type u} [CommRing R] [IsDomain R] (hR : HasUnitMulPowIrreducibleFactorization R) : IsDiscreteValuationRing R := by letI : UniqueFactorizationMonoid R := hR.toUniqueFactorizationMonoid apply of_ufd_of_unique_irreducible _ hR.unique_irreducible obtain ⟨p, hp, H⟩ := hR exact ⟨p, hp⟩ /- If a ring is equivalent to a DVR, it is itself a DVR. -/ theorem RingEquivClass.isDiscreteValuationRing {A B E : Type*} [CommRing A] [IsDomain A] [CommRing B] [IsDomain B] [IsDiscreteValuationRing A] [EquivLike E A B] [RingEquivClass E A B] (e : E) : IsDiscreteValuationRing B where principal := (isPrincipalIdealRing_iff _).1 <| IsPrincipalIdealRing.of_surjective _ (e : A ≃+* B).surjective __ : IsLocalRing B := (e : A ≃+* B).isLocalRing not_a_field' := by obtain ⟨a, ha⟩ := Submodule.nonzero_mem_of_bot_lt (bot_lt_iff_ne_bot.mpr <| IsDiscreteValuationRing.not_a_field A) rw [Submodule.ne_bot_iff] refine ⟨e a, ⟨?_, by simp only [ne_eq, EmbeddingLike.map_eq_zero_iff, ZeroMemClass.coe_eq_zero, ha, not_false_eq_true]⟩⟩ rw [IsLocalRing.mem_maximalIdeal, map_mem_nonunits_iff e, ← IsLocalRing.mem_maximalIdeal] exact a.2 section variable [CommRing R] [IsDomain R] [IsDiscreteValuationRing R] variable {R} theorem associated_pow_irreducible {x : R} (hx : x ≠ 0) {ϖ : R} (hirr : Irreducible ϖ) : ∃ n : ℕ, Associated x (ϖ ^ n) := by have : WfDvdMonoid R := IsNoetherianRing.wfDvdMonoid obtain ⟨fx, hfx⟩ := WfDvdMonoid.exists_factors x hx use Multiset.card fx have H := hfx.2 rw [← Associates.mk_eq_mk_iff_associated] at H ⊢ rw [← H, ← Associates.prod_mk, Associates.mk_pow, ← Multiset.prod_replicate] congr 1 rw [Multiset.eq_replicate] simp only [true_and, and_imp, Multiset.card_map, Multiset.mem_map, exists_imp] rintro _ _ _ rfl rw [Associates.mk_eq_mk_iff_associated] refine associated_of_irreducible _ ?_ hirr apply hfx.1 assumption theorem eq_unit_mul_pow_irreducible {x : R} (hx : x ≠ 0) {ϖ : R} (hirr : Irreducible ϖ) : ∃ (n : ℕ) (u : Rˣ), x = u * ϖ ^ n := by obtain ⟨n, hn⟩ := associated_pow_irreducible hx hirr obtain ⟨u, rfl⟩ := hn.symm use n, u apply mul_comm open Submodule.IsPrincipal theorem ideal_eq_span_pow_irreducible {s : Ideal R} (hs : s ≠ ⊥) {ϖ : R} (hirr : Irreducible ϖ) : ∃ n : ℕ, s = Ideal.span {ϖ ^ n} := by have gen_ne_zero : generator s ≠ 0 := by rw [Ne, ← eq_bot_iff_generator_eq_zero] assumption rcases associated_pow_irreducible gen_ne_zero hirr with ⟨n, u, hnu⟩ use n have : span _ = _ := Ideal.span_singleton_generator s rw [← this, ← hnu, span_singleton_eq_span_singleton] use u theorem unit_mul_pow_congr_pow {p q : R} (hp : Irreducible p) (hq : Irreducible q) (u v : Rˣ) (m n : ℕ) (h : ↑u * p ^ m = v * q ^ n) : m = n := by have key : Associated (Multiset.replicate m p).prod (Multiset.replicate n q).prod := by rw [Multiset.prod_replicate, Multiset.prod_replicate, Associated] refine ⟨u * v⁻¹, ?_⟩ simp only [Units.val_mul] rw [mul_left_comm, ← mul_assoc, h, mul_right_comm, Units.mul_inv, one_mul] have := by refine Multiset.card_eq_card_of_rel (UniqueFactorizationMonoid.factors_unique ?_ ?_ key) all_goals intro x hx obtain rfl := Multiset.eq_of_mem_replicate hx assumption simpa only [Multiset.card_replicate] theorem unit_mul_pow_congr_unit {ϖ : R} (hirr : Irreducible ϖ) (u v : Rˣ) (m n : ℕ) (h : ↑u * ϖ ^ m = v * ϖ ^ n) : u = v := by obtain rfl : m = n := unit_mul_pow_congr_pow hirr hirr u v m n h rw [← sub_eq_zero] at h rw [← sub_mul, mul_eq_zero] at h rcases h with h | h · rw [sub_eq_zero] at h exact mod_cast h · apply (hirr.ne_zero (eq_zero_of_pow_eq_zero h)).elim /-! ## The additive valuation on a DVR -/ open Classical in /-- The `ℕ∞`-valued additive valuation on a DVR. -/ noncomputable def addVal (R : Type u) [CommRing R] [IsDomain R] [IsDiscreteValuationRing R] : AddValuation R ℕ∞ := multiplicity_addValuation (Classical.choose_spec (exists_prime R)) theorem addVal_def (r : R) (u : Rˣ) {ϖ : R} (hϖ : Irreducible ϖ) (n : ℕ) (hr : r = u * ϖ ^ n) : addVal R r = n := by classical rw [addVal, multiplicity_addValuation_apply, hr, emultiplicity_eq_of_associated_left (associated_of_irreducible R hϖ (Classical.choose_spec (exists_prime R)).irreducible), emultiplicity_eq_of_associated_right (Associated.symm ⟨u, mul_comm _ _⟩), emultiplicity_pow_self_of_prime (irreducible_iff_prime.1 hϖ)] /-- An alternative definition of the additive valuation, taking units into account -/ theorem addVal_def' (u : Rˣ) {ϖ : R} (hϖ : Irreducible ϖ) (n : ℕ) : addVal R ((u : R) * ϖ ^ n) = n := addVal_def _ u hϖ n rfl theorem addVal_zero : addVal R 0 = ⊤ := (addVal R).map_zero theorem addVal_one : addVal R 1 = 0 := (addVal R).map_one @[simp] theorem addVal_uniformizer {ϖ : R} (hϖ : Irreducible ϖ) : addVal R ϖ = 1 := by simpa only [one_mul, eq_self_iff_true, Units.val_one, pow_one, forall_true_left, Nat.cast_one] using addVal_def ϖ 1 hϖ 1 theorem addVal_mul {a b : R} : addVal R (a * b) = addVal R a + addVal R b := (addVal R).map_mul _ _ theorem addVal_pow (a : R) (n : ℕ) : addVal R (a ^ n) = n • addVal R a := (addVal R).map_pow _ _ nonrec theorem _root_.Irreducible.addVal_pow {ϖ : R} (h : Irreducible ϖ) (n : ℕ) : addVal R (ϖ ^ n) = n := by rw [addVal_pow, addVal_uniformizer h, nsmul_one] theorem addVal_eq_top_iff {a : R} : addVal R a = ⊤ ↔ a = 0 := by have hi := (Classical.choose_spec (exists_prime R)).irreducible constructor · contrapose intro h obtain ⟨n, ha⟩ := associated_pow_irreducible h hi obtain ⟨u, rfl⟩ := ha.symm rw [mul_comm, addVal_def' u hi n] nofun · rintro rfl exact addVal_zero theorem addVal_le_iff_dvd {a b : R} : addVal R a ≤ addVal R b ↔ a ∣ b := by classical have hp := Classical.choose_spec (exists_prime R) constructor <;> intro h · by_cases ha0 : a = 0 · rw [ha0, addVal_zero, top_le_iff, addVal_eq_top_iff] at h rw [h] apply dvd_zero obtain ⟨n, ha⟩ := associated_pow_irreducible ha0 hp.irreducible rw [addVal, multiplicity_addValuation_apply, multiplicity_addValuation_apply, emultiplicity_le_emultiplicity_iff] at h exact ha.dvd.trans (h n ha.symm.dvd) · rw [addVal, multiplicity_addValuation_apply, multiplicity_addValuation_apply] exact emultiplicity_le_emultiplicity_of_dvd_right h theorem addVal_add {a b : R} : min (addVal R a) (addVal R b) ≤ addVal R (a + b) := (addVal R).map_add _ _ @[simp] lemma addVal_eq_zero_of_unit (u : Rˣ) : addVal R u = 0 := by obtain ⟨ϖ, hϖ⟩ := exists_irreducible R rw [addVal_def (u : R) u hϖ 0] <;> simp lemma addVal_eq_zero_iff {x : R} : addVal R x = 0 ↔ IsUnit x := by rcases eq_or_ne x 0 with rfl | hx · simp obtain ⟨ϖ, hϖ⟩ := exists_irreducible R obtain ⟨n, u, rfl⟩ := eq_unit_mul_pow_irreducible hx hϖ simp [isUnit_pow_iff_of_not_isUnit hϖ.not_isUnit, hϖ] end instance (R : Type*) [CommRing R] [IsDomain R] [IsDiscreteValuationRing R] : IsHausdorff (maximalIdeal R) R where haus' x hx := by obtain ⟨ϖ, hϖ⟩ := exists_irreducible R simp only [← Ideal.one_eq_top, smul_eq_mul, mul_one, SModEq.zero, hϖ.maximalIdeal_eq, Ideal.span_singleton_pow, Ideal.mem_span_singleton, ← addVal_le_iff_dvd, hϖ.addVal_pow] at hx rwa [← addVal_eq_top_iff, WithTop.eq_top_iff_forall_ge] noncomputable section toEuclideanDomain variable {R : Type*} [CommRing R] [IsDomain R] [IsDiscreteValuationRing R] /-- A noncomputable quotient to define the Euclidean domain structure. The GCD algorithm only takes two steps to terminate. Given `GCD(x,y)`, if `x ∣ y` then `y%x = 0` so we're done in one step; otherwise `y%x = y` and then `GCD(x,y) = GCD(y,x)` which brings us back to the first case. -/ def quotient (x y : R) : R := open Classical in if y = 0 then 0 else if h : y ∣ x then h.choose else 0 /-- A noncomputable remainder to define the Euclidean domain structure. The GCD algorithm only takes two steps to terminate. Given `GCD(x,y)`, if `x ∣ y` then `y%x = 0` so we're done in one step; otherwise `y%x = y` and then `GCD(x,y) = GCD(y,x)` which brings us back to the first case. -/ def remainder (x y : R) : R := open Classical in if y ∣ x then 0 else x /-- A modification of the valuation, sending `0` to `⊥` instead of `⊤`. -/ def toWithBotNat (x : R) : WithBot ℕ := addVal R x @[simp] lemma toWithBotNat_zero : toWithBotNat (R := R) 0 = ⊥ := addVal_zero @[simp] lemma toWithBotNat_eq_bot_iff (x : R) : toWithBotNat x = ⊥ ↔ x = 0 := addVal_eq_top_iff @[simp] lemma bot_lt_toWithBotNat_iff (x : R) : ⊥ < toWithBotNat x ↔ x ≠ 0 := by rw [bot_lt_iff_ne_bot]; simp lemma toWithBotNat_le_toWithBotNat_iff {x y : R} (hx : x ≠ 0) (hy : y ≠ 0) : toWithBotNat x ≤ toWithBotNat y ↔ x ∣ y := by unfold toWithBotNat generalize hvx : addVal R x = vx generalize hvy : addVal R y = vy cases vx with | top => rw [addVal_eq_top_iff] at hvx; tauto | coe vx => cases vy with | top => rw [addVal_eq_top_iff] at hvy; tauto | coe vy => rw [← addVal_le_iff_dvd, hvx, hvy] exact WithBot.coe_le_coe.trans WithTop.coe_le_coe.symm lemma dvd_of_toWithBotNat_le_toWithBotNat (x y : R) (hx : x ≠ 0) (hle : toWithBotNat x ≤ toWithBotNat y) : x ∣ y := by by_cases hy : y = 0 · simp [hy, hx] at hle exact (toWithBotNat_le_toWithBotNat_iff hx hy).mp hle variable (R) in /-- A noncomputable Euclidean domain structure on a discrete valuation ring, where the GCD algorithm only takes two steps to terminate. Given `GCD(x,y)`, if `x ∣ y` then `y%x = 0` so we're done in one step; otherwise `y%x = y` and then `GCD(x,y) = GCD(y,x)` which brings us back to the first case. See `EuclideanDomain.to_principal_ideal_domain` for EuclideanDomain ⇒ PID. -/ def toEuclideanDomain : EuclideanDomain R where quotient := quotient quotient_zero x := by simp [quotient] remainder := remainder quotient_mul_add_remainder_eq x y := by rw [remainder, quotient] split_ifs with h₁ h₂ h₂ · rw [h₁, zero_dvd_iff] at h₂; rw [h₁, h₂]; ring · rw [h₁]; ring · rw [← h₂.choose_spec]; ring · ring r x y := toWithBotNat x < toWithBotNat y r_wellFounded := WellFounded.onFun wellFounded_lt remainder_lt x y hy := by rw [remainder] split_ifs with hyx · rwa [toWithBotNat_zero, bot_lt_toWithBotNat_iff] · exact lt_iff_not_ge.mpr (mt (dvd_of_toWithBotNat_le_toWithBotNat _ _ hy) hyx) mul_left_not_lt x y hy := by by_cases hx : x = 0 · simp [hx] rw [not_lt, toWithBotNat_le_toWithBotNat_iff hx (mul_ne_zero hx hy)] exact dvd_mul_right _ _ end toEuclideanDomain end IsDiscreteValuationRing section variable (A : Type u) [CommRing A] [IsDomain A] [IsDiscreteValuationRing A] /-- A DVR is a valuation ring. -/ instance (priority := 100) of_isDiscreteValuationRing : ValuationRing A := inferInstance end namespace Valuation.Integers variable {K Γ₀ O : Type*} [Field K] [LinearOrderedCommGroupWithZero Γ₀] [CommRing O] [Algebra O K] {v : Valuation K Γ₀} (hv : v.Integers O) include hv lemma maximalIdeal_eq_setOf_le_v_algebraMap : letI : IsDomain O := hv.hom_inj.isDomain ∀ [IsDiscreteValuationRing O] {ϖ : O} (_h : Irreducible ϖ), (IsLocalRing.maximalIdeal O : Set O) = {y : O | v (algebraMap O K y) ≤ v (algebraMap O K ϖ)} := by letI : IsDomain O := hv.hom_inj.isDomain intro _ _ h rw [← hv.coe_span_singleton_eq_setOf_le_v_algebraMap, ← h.maximalIdeal_eq] lemma maximalIdeal_pow_eq_setOf_le_v_algebraMap_pow : letI : IsDomain O := hv.hom_inj.isDomain ∀ [IsDiscreteValuationRing O] {ϖ : O} (_h : Irreducible ϖ) (n : ℕ), ((IsLocalRing.maximalIdeal O ^ n : Ideal O) : Set O) = {y : O | v (algebraMap O K y) ≤ v (algebraMap O K ϖ) ^ n} := by letI : IsDomain O := hv.hom_inj.isDomain intro _ ϖ h n have : (v (algebraMap O K ϖ)) ^ n = v (algebraMap O K (ϖ ^ n)) := by simp rw [this, ← hv.coe_span_singleton_eq_setOf_le_v_algebraMap, ← Ideal.span_singleton_pow, ← h.maximalIdeal_eq] end Valuation.Integers section Valuation.integer variable {K Γ₀ : Type*} [Field K] [LinearOrderedCommGroupWithZero Γ₀] (v : Valuation K Γ₀) lemma _root_.Irreducible.maximalIdeal_eq_setOf_le_v_coe [IsDiscreteValuationRing v.integer] {ϖ : v.integer} (h : Irreducible ϖ) : (IsLocalRing.maximalIdeal v.integer : Set v.integer) = {y : v.integer | v y ≤ v ϖ} := (Valuation.integer.integers v).maximalIdeal_eq_setOf_le_v_algebraMap h lemma _root_.Irreducible.maximalIdeal_pow_eq_setOf_le_v_coe_pow [IsDiscreteValuationRing v.integer] {ϖ : v.integer} (h : Irreducible ϖ) (n : ℕ) : ((IsLocalRing.maximalIdeal v.integer ^ n : Ideal v.integer) : Set v.integer) = {y : v.integer | v y ≤ v (ϖ : K) ^ n} := (Valuation.integer.integers v).maximalIdeal_pow_eq_setOf_le_v_algebraMap_pow h _ end Valuation.integer
.lake/packages/mathlib/Mathlib/RingTheory/FractionalIdeal/Inverse.lean
import Mathlib.RingTheory.FractionalIdeal.Operations /-! # Inverse operator for fractional ideals This file defines the notation `I⁻¹` where `I` is a not necessarily invertible fractional ideal. Note that this is somewhat misleading notation in case `I` is not invertible. The theorem that all nonzero fractional ideals are invertible in a Dedekind domain can be found in `Mathlib/DedekindDomain/Ideal/Basic.lean`. ## Main definitions - `FractionalIdeal.instInv` defines `I⁻¹ := 1 / I`. ## References * [D. Marcus, *Number Fields*][marcus1977number] * [J.W.S. Cassels, A. Fröhlich, *Algebraic Number Theory*][cassels1967algebraic] * [J. Neukirch, *Algebraic Number Theory*][Neukirch1992] ## Tags fractional ideal, invertible ideal -/ assert_not_exists IsDedekindDomain variable (R A K : Type*) [CommRing R] [CommRing A] [Field K] open scoped nonZeroDivisors Polynomial namespace FractionalIdeal variable {R₁ : Type*} [CommRing R₁] [IsDomain R₁] [Algebra R₁ K] [IsFractionRing R₁ K] variable {I J : FractionalIdeal R₁⁰ K} noncomputable instance : Inv (FractionalIdeal R₁⁰ K) := ⟨fun I => 1 / I⟩ theorem inv_eq : I⁻¹ = 1 / I := rfl theorem inv_zero' : (0 : FractionalIdeal R₁⁰ K)⁻¹ = 0 := div_zero theorem inv_of_ne_zero {J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) : J⁻¹ = ⟨(1 : FractionalIdeal R₁⁰ K) / J, isFractional_div_of_ne_zero h⟩ := div_of_ne_zero h theorem coe_inv_of_ne_zero {J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) : (↑J⁻¹ : Submodule R₁ K) = IsLocalization.coeSubmodule K ⊤ / (J : Submodule R₁ K) := by simp_rw [inv_of_ne_zero _ h, coe_one, coe_mk, IsLocalization.coeSubmodule_top] @[deprecated (since := "2025-09-14")] alias inv_nonzero := inv_of_ne_zero @[deprecated (since := "2025-09-14")] alias coe_inv_of_nonzero := coe_inv_of_ne_zero variable {K} theorem mem_inv_iff (hI : I ≠ 0) {x : K} : x ∈ I⁻¹ ↔ ∀ y ∈ I, x * y ∈ (1 : FractionalIdeal R₁⁰ K) := mem_div_iff_of_ne_zero hI theorem inv_anti_mono (hI : I ≠ 0) (hJ : J ≠ 0) (hIJ : I ≤ J) : J⁻¹ ≤ I⁻¹ := by -- Porting note: in Lean3, introducing `x` would just give `x ∈ J⁻¹ → x ∈ I⁻¹`, but -- in Lean4, it goes all the way down to the subtypes intro x simp only [val_eq_coe, mem_coe, mem_inv_iff hJ, mem_inv_iff hI] exact fun h y hy => h y (hIJ hy) theorem le_self_mul_inv {I : FractionalIdeal R₁⁰ K} (hI : I ≤ (1 : FractionalIdeal R₁⁰ K)) : I ≤ I * I⁻¹ := le_self_mul_one_div hI variable (K) theorem coe_ideal_le_self_mul_inv (I : Ideal R₁) : (I : FractionalIdeal R₁⁰ K) ≤ I * (I : FractionalIdeal R₁⁰ K)⁻¹ := le_self_mul_inv coeIdeal_le_one /-- `I⁻¹` is the inverse of `I` if `I` has an inverse. -/ theorem right_inverse_eq (I J : FractionalIdeal R₁⁰ K) (h : I * J = 1) : J = I⁻¹ := eq_one_div_of_mul_eq_one_right _ _ h theorem mul_inv_cancel_iff {I : FractionalIdeal R₁⁰ K} : I * I⁻¹ = 1 ↔ ∃ J, I * J = 1 := ⟨fun h => ⟨I⁻¹, h⟩, fun ⟨J, hJ⟩ => by rwa [← right_inverse_eq K I J hJ]⟩ theorem mul_inv_cancel_iff_isUnit {I : FractionalIdeal R₁⁰ K} : I * I⁻¹ = 1 ↔ IsUnit I := (mul_inv_cancel_iff K).trans isUnit_iff_exists_inv.symm variable {K' : Type*} [Field K'] [Algebra R₁ K'] [IsFractionRing R₁ K'] @[simp] protected theorem map_inv (I : FractionalIdeal R₁⁰ K) (h : K ≃ₐ[R₁] K') : I⁻¹.map (h : K →ₐ[R₁] K') = (I.map h)⁻¹ := by rw [inv_eq, FractionalIdeal.map_div, FractionalIdeal.map_one, inv_eq] open Submodule Submodule.IsPrincipal @[simp] theorem spanSingleton_inv (x : K) : (spanSingleton R₁⁰ x)⁻¹ = spanSingleton _ x⁻¹ := one_div_spanSingleton x theorem spanSingleton_div_spanSingleton (x y : K) : spanSingleton R₁⁰ x / spanSingleton R₁⁰ y = spanSingleton R₁⁰ (x / y) := by rw [div_spanSingleton, mul_comm, spanSingleton_mul_spanSingleton, div_eq_mul_inv] theorem spanSingleton_div_self {x : K} (hx : x ≠ 0) : spanSingleton R₁⁰ x / spanSingleton R₁⁰ x = 1 := by rw [spanSingleton_div_spanSingleton, div_self hx, spanSingleton_one] theorem coe_ideal_span_singleton_div_self {x : R₁} (hx : x ≠ 0) : (Ideal.span ({x} : Set R₁) : FractionalIdeal R₁⁰ K) / Ideal.span ({x} : Set R₁) = 1 := by rw [coeIdeal_span_singleton, spanSingleton_div_self K <| (map_ne_zero_iff _ <| FaithfulSMul.algebraMap_injective R₁ K).mpr hx] theorem spanSingleton_mul_inv {x : K} (hx : x ≠ 0) : spanSingleton R₁⁰ x * (spanSingleton R₁⁰ x)⁻¹ = 1 := by rw [spanSingleton_inv, spanSingleton_mul_spanSingleton, mul_inv_cancel₀ hx, spanSingleton_one] theorem coe_ideal_span_singleton_mul_inv {x : R₁} (hx : x ≠ 0) : (Ideal.span ({x} : Set R₁) : FractionalIdeal R₁⁰ K) * (Ideal.span ({x} : Set R₁) : FractionalIdeal R₁⁰ K)⁻¹ = 1 := by rw [coeIdeal_span_singleton, spanSingleton_mul_inv K <| (map_ne_zero_iff _ <| FaithfulSMul.algebraMap_injective R₁ K).mpr hx] theorem spanSingleton_inv_mul {x : K} (hx : x ≠ 0) : (spanSingleton R₁⁰ x)⁻¹ * spanSingleton R₁⁰ x = 1 := by rw [mul_comm, spanSingleton_mul_inv K hx] theorem coe_ideal_span_singleton_inv_mul {x : R₁} (hx : x ≠ 0) : (Ideal.span ({x} : Set R₁) : FractionalIdeal R₁⁰ K)⁻¹ * Ideal.span ({x} : Set R₁) = 1 := by rw [mul_comm, coe_ideal_span_singleton_mul_inv K hx] theorem mul_generator_self_inv {R₁ : Type*} [CommRing R₁] [Algebra R₁ K] [IsLocalization R₁⁰ K] (I : FractionalIdeal R₁⁰ K) [Submodule.IsPrincipal (I : Submodule R₁ K)] (h : I ≠ 0) : I * spanSingleton _ (generator (I : Submodule R₁ K))⁻¹ = 1 := by -- Rewrite only the `I` that appears alone. conv_lhs => congr; rw [eq_spanSingleton_of_principal I] rw [spanSingleton_mul_spanSingleton, mul_inv_cancel₀, spanSingleton_one] intro generator_I_eq_zero apply h rw [eq_spanSingleton_of_principal I, generator_I_eq_zero, spanSingleton_zero] theorem invertible_of_principal (I : FractionalIdeal R₁⁰ K) [Submodule.IsPrincipal (I : Submodule R₁ K)] (h : I ≠ 0) : I * I⁻¹ = 1 := mul_div_self_cancel_iff.mpr ⟨spanSingleton _ (generator (I : Submodule R₁ K))⁻¹, mul_generator_self_inv _ I h⟩ theorem invertible_iff_generator_nonzero (I : FractionalIdeal R₁⁰ K) [Submodule.IsPrincipal (I : Submodule R₁ K)] : I * I⁻¹ = 1 ↔ generator (I : Submodule R₁ K) ≠ 0 := by constructor · intro hI hg apply ne_zero_of_mul_eq_one _ _ hI rw [eq_spanSingleton_of_principal I, hg, spanSingleton_zero] · intro hg apply invertible_of_principal rw [eq_spanSingleton_of_principal I] intro hI have := mem_spanSingleton_self R₁⁰ (generator (I : Submodule R₁ K)) rw [hI, mem_zero_iff] at this contradiction theorem isPrincipal_inv (I : FractionalIdeal R₁⁰ K) [Submodule.IsPrincipal (I : Submodule R₁ K)] (h : I ≠ 0) : Submodule.IsPrincipal I⁻¹.1 := by rw [val_eq_coe, isPrincipal_iff] use (generator (I : Submodule R₁ K))⁻¹ have hI : I * spanSingleton _ (generator (I : Submodule R₁ K))⁻¹ = 1 := mul_generator_self_inv _ I h exact (right_inverse_eq _ I (spanSingleton _ (generator (I : Submodule R₁ K))⁻¹) hI).symm variable {K} lemma den_mem_inv {I : FractionalIdeal R₁⁰ K} (hI : I ≠ ⊥) : algebraMap R₁ K (I.den : R₁) ∈ I⁻¹ := by rw [mem_inv_iff hI] intro i hi rw [← Algebra.smul_def (I.den : R₁) i, ← mem_coe, coe_one] suffices Submodule.map (Algebra.linearMap R₁ K) I.num ≤ 1 from this <| (den_mul_self_eq_num I).symm ▸ smul_mem_pointwise_smul i I.den I.coeToSubmodule hi apply le_trans <| map_mono (show I.num ≤ 1 by simp only [Ideal.one_eq_top, le_top]) rw [Ideal.one_eq_top, Submodule.map_top, one_eq_range] lemma num_le_mul_inv (I : FractionalIdeal R₁⁰ K) : I.num ≤ I * I⁻¹ := by by_cases hI : I = 0 · rw [hI, num_zero_eq <| FaithfulSMul.algebraMap_injective R₁ K, zero_mul, zero_eq_bot, coeIdeal_bot] · rw [mul_comm, ← den_mul_self_eq_num'] gcongr exact spanSingleton_le_iff_mem.2 (den_mem_inv hI) lemma bot_lt_mul_inv {I : FractionalIdeal R₁⁰ K} (hI : I ≠ ⊥) : ⊥ < I * I⁻¹ := lt_of_lt_of_le (coeIdeal_ne_zero.2 (hI ∘ num_eq_zero_iff.1)).bot_lt I.num_le_mul_inv noncomputable instance : InvOneClass (FractionalIdeal R₁⁰ K) := { inv_one := div_one } end FractionalIdeal
.lake/packages/mathlib/Mathlib/RingTheory/FractionalIdeal/Norm.lean
import Mathlib.RingTheory.FractionalIdeal.Basic import Mathlib.RingTheory.Ideal.Norm.AbsNorm import Mathlib.RingTheory.Localization.NormTrace /-! # Fractional ideal norms This file defines the absolute ideal norm of a fractional ideal `I : FractionalIdeal R⁰ K` where `K` is a fraction field of `R`. The norm is defined by `FractionalIdeal.absNorm I = Ideal.absNorm I.num / |Algebra.norm ℤ I.den|` where `I.num` is an ideal of `R` and `I.den` an element of `R⁰` such that `I.den • I = I.num`. ## Main definitions and results * `FractionalIdeal.absNorm`: the norm as a zero-preserving morphism with values in `ℚ`. * `FractionalIdeal.absNorm_eq'`: the value of the norm does not depend on the choice of `I.num` and `I.den`. * `FractionalIdeal.abs_det_basis_change`: the norm is given by the determinant of the basis change matrix. * `FractionalIdeal.absNorm_span_singleton`: the norm of a principal fractional ideal is the norm of its generator -/ open Module open scoped Pointwise nonZeroDivisors namespace FractionalIdeal variable {R : Type*} [CommRing R] [IsDedekindDomain R] [Module.Free ℤ R] [Module.Finite ℤ R] variable {K : Type*} [CommRing K] [Algebra R K] [IsFractionRing R K] theorem absNorm_div_norm_eq_absNorm_div_norm {I : FractionalIdeal R⁰ K} (a : R⁰) (I₀ : Ideal R) (h : a • (I : Submodule R K) = Submodule.map (Algebra.linearMap R K) I₀) : (Ideal.absNorm I.num : ℚ) / |Algebra.norm ℤ (I.den : R)| = (Ideal.absNorm I₀ : ℚ) / |Algebra.norm ℤ (a : R)| := by rw [div_eq_div_iff] · replace h := congr_arg (I.den • ·) h have h' := congr_arg (a • ·) (den_mul_self_eq_num I) dsimp only at h h' rw [smul_comm] at h rw [h, Submonoid.smul_def, Submonoid.smul_def, ← Submodule.ideal_span_singleton_smul, ← Submodule.ideal_span_singleton_smul, ← Submodule.map_smul'', ← Submodule.map_smul'', (LinearMap.map_injective ?_).eq_iff, smul_eq_mul, smul_eq_mul] at h' · simp_rw [← Nat.cast_natAbs, ← Nat.cast_mul, ← Ideal.absNorm_span_singleton] rw [← map_mul, ← map_mul, mul_comm, ← h', mul_comm] · exact LinearMap.ker_eq_bot.mpr (IsFractionRing.injective R K) all_goals simp [Algebra.norm_eq_zero_iff] /-- The absolute norm of the fractional ideal `I` extending by multiplicativity the absolute norm on (integral) ideals. -/ noncomputable def absNorm : FractionalIdeal R⁰ K →*₀ ℚ where toFun I := (Ideal.absNorm I.num : ℚ) / |Algebra.norm ℤ (I.den : R)| map_zero' := by rw [num_zero_eq, Submodule.zero_eq_bot, Ideal.absNorm_bot, Nat.cast_zero, zero_div] exact IsFractionRing.injective R K map_one' := by rw [absNorm_div_norm_eq_absNorm_div_norm 1 ⊤ (by simp [Submodule.one_eq_range]), Ideal.absNorm_top, Nat.cast_one, OneMemClass.coe_one, map_one, abs_one, Int.cast_one, one_div_one] map_mul' I J := by rw [absNorm_div_norm_eq_absNorm_div_norm (I.den * J.den) (I.num * J.num) (by have : Algebra.linearMap R K = (IsScalarTower.toAlgHom R R K).toLinearMap := rfl rw [coe_mul, this, Submodule.map_mul, ← this, ← den_mul_self_eq_num, ← den_mul_self_eq_num] exact Submodule.mul_smul_mul_eq_smul_mul_smul _ _ _ _), Submonoid.coe_mul, map_mul, map_mul, Nat.cast_mul, div_mul_div_comm, Int.cast_abs, Int.cast_abs, Int.cast_abs, ← abs_mul, Int.cast_mul] theorem absNorm_eq (I : FractionalIdeal R⁰ K) : absNorm I = (Ideal.absNorm I.num : ℚ) / |Algebra.norm ℤ (I.den : R)| := rfl theorem absNorm_eq' {I : FractionalIdeal R⁰ K} (a : R⁰) (I₀ : Ideal R) (h : a • (I : Submodule R K) = Submodule.map (Algebra.linearMap R K) I₀) : absNorm I = (Ideal.absNorm I₀ : ℚ) / |Algebra.norm ℤ (a : R)| := by rw [absNorm, ← absNorm_div_norm_eq_absNorm_div_norm a I₀ h, MonoidWithZeroHom.coe_mk, ZeroHom.coe_mk] theorem absNorm_nonneg (I : FractionalIdeal R⁰ K) : 0 ≤ absNorm I := by dsimp [absNorm]; positivity theorem absNorm_bot : absNorm (⊥ : FractionalIdeal R⁰ K) = 0 := absNorm.map_zero' theorem absNorm_one : absNorm (1 : FractionalIdeal R⁰ K) = 1 := by convert absNorm.map_one' theorem absNorm_eq_zero_iff [NoZeroDivisors K] {I : FractionalIdeal R⁰ K} : absNorm I = 0 ↔ I = 0 := by refine ⟨fun h ↦ zero_of_num_eq_bot zero_notMem_nonZeroDivisors ?_, fun h ↦ h ▸ absNorm_bot⟩ rw [absNorm_eq, div_eq_zero_iff] at h refine Ideal.absNorm_eq_zero_iff.mp <| Nat.cast_eq_zero.mp <| h.resolve_right ?_ simp [Algebra.norm_eq_zero_iff] theorem coeIdeal_absNorm (I₀ : Ideal R) : absNorm (I₀ : FractionalIdeal R⁰ K) = Ideal.absNorm I₀ := by rw [absNorm_eq' 1 I₀ (by rw [one_smul]; rfl), OneMemClass.coe_one, map_one, abs_one, Int.cast_one, _root_.div_one] section IsLocalization variable [IsLocalization (Algebra.algebraMapSubmonoid R ℤ⁰) K] [Algebra ℚ K] theorem abs_det_basis_change [NoZeroDivisors K] {ι : Type*} [Fintype ι] [DecidableEq ι] (b : Basis ι ℤ R) (I : FractionalIdeal R⁰ K) (bI : Basis ι ℤ I) : |(b.localizationLocalization ℚ ℤ⁰ K).det ((↑) ∘ bI)| = absNorm I := by have := IsFractionRing.nontrivial R K let b₀ : Basis ι ℚ K := b.localizationLocalization ℚ ℤ⁰ K let bI.num : Basis ι ℤ I.num := bI.map ((equivNum (nonZeroDivisors.coe_ne_zero _)).restrictScalars ℤ) rw [absNorm_eq, ← Ideal.natAbs_det_basis_change b I.num bI.num, Nat.cast_natAbs, Int.cast_abs, Int.cast_abs, Basis.det_apply, Basis.det_apply] change _ = |algebraMap ℤ ℚ _| / _ rw [RingHom.map_det, show RingHom.mapMatrix (algebraMap ℤ ℚ) (b.toMatrix ((↑) ∘ bI.num)) = b₀.toMatrix ((algebraMap R K (den I : R)) • ((↑) ∘ bI)) by ext : 2 simp_rw [bI.num, RingHom.mapMatrix_apply, Matrix.map_apply, Basis.toMatrix_apply, ← Basis.localizationLocalization_repr_algebraMap ℚ ℤ⁰ K, Function.comp_apply, Basis.map_apply, LinearEquiv.restrictScalars_apply, equivNum_apply, Submonoid.smul_def, Algebra.smul_def] rfl] rw [Basis.toMatrix_smul, Matrix.det_mul, abs_mul, ← Algebra.norm_eq_matrix_det, Algebra.norm_localization ℤ ℤ⁰, show (Algebra.norm ℤ (den I : R) : ℚ) = algebraMap ℤ ℚ (Algebra.norm ℤ (den I : R)) by rfl, mul_div_assoc, mul_div_cancel₀ _ (by rw [ne_eq, abs_eq_zero, IsFractionRing.to_map_eq_zero_iff, Algebra.norm_eq_zero_iff_of_basis b] exact nonZeroDivisors.coe_ne_zero _)] variable (R) in @[simp] theorem absNorm_span_singleton [Module.Finite ℚ K] (x : K) : absNorm (spanSingleton R⁰ x) = |(Algebra.norm ℚ x)| := by have : IsDomain K := IsFractionRing.isDomain R obtain ⟨d, ⟨r, hr⟩⟩ := IsLocalization.exists_integer_multiple R⁰ x rw [absNorm_eq' d (Ideal.span {r})] · rw [Ideal.absNorm_span_singleton] simp_rw [Nat.cast_natAbs, Int.cast_abs, show ((Algebra.norm ℤ _) : ℚ) = algebraMap ℤ ℚ (Algebra.norm ℤ _) by rfl, ← Algebra.norm_localization ℤ ℤ⁰ (Sₘ := K) _] rw [hr, Algebra.smul_def, map_mul, abs_mul, mul_div_assoc, mul_div_cancel₀ _ (by rw [ne_eq, abs_eq_zero, Algebra.norm_eq_zero_iff, IsFractionRing.to_map_eq_zero_iff] exact nonZeroDivisors.coe_ne_zero _)] · ext simp_rw [Submodule.mem_smul_pointwise_iff_exists, mem_coe, mem_spanSingleton, Submodule.mem_map, Algebra.linearMap_apply, Submonoid.smul_def, Ideal.mem_span_singleton', exists_exists_eq_and, map_mul, hr, ← Algebra.smul_def, smul_comm (d : R)] end IsLocalization end FractionalIdeal
.lake/packages/mathlib/Mathlib/RingTheory/FractionalIdeal/Basic.lean
import Mathlib.RingTheory.Localization.Integer import Mathlib.RingTheory.Localization.Submodule /-! # Fractional ideals This file defines fractional ideals of an integral domain and proves basic facts about them. ## Main definitions Let `S` be a submonoid of an integral domain `R` and `P` the localization of `R` at `S`. * `IsFractional` defines which `R`-submodules of `P` are fractional ideals * `FractionalIdeal S P` is the type of fractional ideals in `P` * a coercion `coeIdeal : Ideal R → FractionalIdeal S P` * `CommSemiring (FractionalIdeal S P)` instance: the typical ideal operations generalized to fractional ideals * `Lattice (FractionalIdeal S P)` instance ## Main statements * the `MulLeftMono` and `MulRightMono` instances state that ideal multiplication is monotone * `mul_div_self_cancel_iff` states that `1 / I` is the inverse of `I` if one exists ## Implementation notes Fractional ideals are considered equal when they contain the same elements, independent of the denominator `a : R` such that `a I ⊆ R`. Thus, we define `FractionalIdeal` to be the subtype of the predicate `IsFractional`, instead of having `FractionalIdeal` be a structure of which `a` is a field. Most definitions in this file specialize operations from submodules to fractional ideals, proving that the result of this operation is fractional if the input is fractional. Exceptions to this rule are defining `(+) := (⊔)` and `⊥ := 0`, in order to reuse their respective proof terms. We can still use `simp` to show `↑I + ↑J = ↑(I + J)` and `↑⊥ = ↑0`. Many results in fact do not need that `P` is a localization, only that `P` is an `R`-algebra. We omit the `IsLocalization` parameter whenever this is practical. Similarly, we don't assume that the localization is a field until we need it to define ideal quotients. When this assumption is needed, we replace `S` with `R⁰`, making the localization a field. ## References * https://en.wikipedia.org/wiki/Fractional_ideal ## Tags fractional ideal, fractional ideals, invertible ideal -/ open IsLocalization Pointwise nonZeroDivisors section Defs variable {R : Type*} [CommRing R] {S : Submonoid R} {P : Type*} [CommRing P] variable [Algebra R P] variable (S) /-- A submodule `I` is a fractional ideal if `a I ⊆ R` for some `a ≠ 0`. -/ def IsFractional (I : Submodule R P) := ∃ a ∈ S, ∀ b ∈ I, IsInteger R (a • b) variable (P) /-- The fractional ideals of a domain `R` are ideals of `R` divided by some `a ∈ R`. More precisely, let `P` be a localization of `R` at some submonoid `S`, then a fractional ideal `I ⊆ P` is an `R`-submodule of `P`, such that there is a nonzero `a : R` with `a I ⊆ R`. -/ def FractionalIdeal := { I : Submodule R P // IsFractional S I } end Defs namespace FractionalIdeal open Set Submodule variable {R : Type*} [CommRing R] {S : Submonoid R} {P : Type*} [CommRing P] variable [Algebra R P] /-- Map a fractional ideal `I` to a submodule by forgetting that `∃ a, a I ⊆ R`. This implements the coercion `FractionalIdeal S P → Submodule R P`. -/ @[coe] def coeToSubmodule (I : FractionalIdeal S P) : Submodule R P := I.val /-- Map a fractional ideal `I` to a submodule by forgetting that `∃ a, a I ⊆ R`. This coercion is typically called `coeToSubmodule` in lemma names (or `coe` when the coercion is clear from the context), not to be confused with `IsLocalization.coeSubmodule : Ideal R → Submodule R P` (which we use to define `coe : Ideal R → FractionalIdeal S P`). -/ instance : CoeOut (FractionalIdeal S P) (Submodule R P) := ⟨coeToSubmodule⟩ protected theorem isFractional (I : FractionalIdeal S P) : IsFractional S (I : Submodule R P) := I.prop /-- An element of `S` such that `I.den • I = I.num`, see `FractionalIdeal.num` and `FractionalIdeal.den_mul_self_eq_num`. -/ noncomputable def den (I : FractionalIdeal S P) : S := ⟨I.2.choose, I.2.choose_spec.1⟩ /-- An ideal of `R` such that `I.den • I = I.num`, see `FractionalIdeal.den` and `FractionalIdeal.den_mul_self_eq_num`. -/ noncomputable def num (I : FractionalIdeal S P) : Ideal R := (I.den • (I : Submodule R P)).comap (Algebra.linearMap R P) theorem den_mul_self_eq_num (I : FractionalIdeal S P) : I.den • (I : Submodule R P) = Submodule.map (Algebra.linearMap R P) I.num := by rw [den, num, Submodule.map_comap_eq] refine (inf_of_le_right ?_).symm rintro _ ⟨a, ha, rfl⟩ exact I.2.choose_spec.2 a ha /-- The linear equivalence between the fractional ideal `I` and the integral ideal `I.num` defined by mapping `x` to `den I • x`. -/ noncomputable def equivNum [Nontrivial P] [NoZeroSMulDivisors R P] {I : FractionalIdeal S P} (h_nz : (I.den : R) ≠ 0) : I ≃ₗ[R] I.num := by refine LinearEquiv.trans (LinearEquiv.ofBijective ((DistribMulAction.toLinearMap R P I.den).restrict fun _ hx ↦ ?_) ⟨fun _ _ hxy ↦ ?_, fun ⟨y, hy⟩ ↦ ?_⟩) (Submodule.equivMapOfInjective (Algebra.linearMap R P) (FaithfulSMul.algebraMap_injective R P) (num I)).symm · rw [← den_mul_self_eq_num] exact Submodule.smul_mem_pointwise_smul _ _ _ hx · simp_rw [LinearMap.restrict_apply, DistribMulAction.toLinearMap_apply, Subtype.mk.injEq] at hxy rwa [Submonoid.smul_def, Submonoid.smul_def, smul_right_inj h_nz, SetCoe.ext_iff] at hxy · rw [← den_mul_self_eq_num] at hy obtain ⟨x, hx, hxy⟩ := hy exact ⟨⟨x, hx⟩, by simp_rw [LinearMap.restrict_apply, Subtype.ext_iff, ← hxy]; rfl⟩ section SetLike instance : SetLike (FractionalIdeal S P) P where coe I := ↑(I : Submodule R P) coe_injective' := SetLike.coe_injective.comp Subtype.coe_injective @[simp] theorem mem_coe {I : FractionalIdeal S P} {x : P} : x ∈ (I : Submodule R P) ↔ x ∈ I := Iff.rfl /-- Partially-applied version of `FractionalIdeal.ext`. -/ theorem coe_ext {I J : FractionalIdeal S P} : (I : Submodule R P) = (J : Submodule R P) → I = J := Subtype.ext /-- Partially-applied version of `FractionalIdeal.ext_iff`. -/ theorem coe_ext_iff {I J : FractionalIdeal S P} : I = J ↔ (I : Submodule R P) = (J : Submodule R P) := Subtype.ext_iff @[ext] theorem ext {I J : FractionalIdeal S P} : (∀ x, x ∈ I ↔ x ∈ J) → I = J := SetLike.ext @[simp] theorem equivNum_apply [Nontrivial P] [NoZeroSMulDivisors R P] {I : FractionalIdeal S P} (h_nz : (I.den : R) ≠ 0) (x : I) : algebraMap R P (equivNum h_nz x) = I.den • x := by change Algebra.linearMap R P _ = _ rw [equivNum, LinearEquiv.trans_apply, LinearEquiv.ofBijective_apply, LinearMap.restrict_apply, Submodule.map_equivMapOfInjective_symm_apply, Subtype.coe_mk, DistribMulAction.toLinearMap_apply] /-- Copy of a `FractionalIdeal` with a new underlying set equal to the old one. Useful to fix definitional equalities. -/ protected def copy (p : FractionalIdeal S P) (s : Set P) (hs : s = ↑p) : FractionalIdeal S P := ⟨Submodule.copy p s hs, by convert p.isFractional ext simp only [hs] rfl⟩ @[simp] theorem coe_copy (p : FractionalIdeal S P) (s : Set P) (hs : s = ↑p) : ↑(p.copy s hs) = s := rfl theorem coe_eq (p : FractionalIdeal S P) (s : Set P) (hs : s = ↑p) : p.copy s hs = p := SetLike.coe_injective hs end SetLike lemma zero_mem (I : FractionalIdeal S P) : 0 ∈ I := I.coeToSubmodule.zero_mem @[simp] theorem val_eq_coe (I : FractionalIdeal S P) : I.val = I := rfl @[simp, norm_cast] theorem coe_mk (I : Submodule R P) (hI : IsFractional S I) : coeToSubmodule ⟨I, hI⟩ = I := rfl theorem coeToSet_coeToSubmodule (I : FractionalIdeal S P) : ((I : Submodule R P) : Set P) = I := rfl /-! Transfer instances from `Submodule R P` to `FractionalIdeal S P`. -/ instance (I : FractionalIdeal S P) : Module R I := Submodule.module (I : Submodule R P) theorem coeToSubmodule_injective : Function.Injective (fun (I : FractionalIdeal S P) ↦ (I : Submodule R P)) := Subtype.coe_injective theorem coeToSubmodule_inj {I J : FractionalIdeal S P} : (I : Submodule R P) = J ↔ I = J := coeToSubmodule_injective.eq_iff theorem isFractional_of_le_one (I : Submodule R P) (h : I ≤ 1) : IsFractional S I := by use 1, S.one_mem intro b hb rw [one_smul] obtain ⟨b', b'_mem, rfl⟩ := mem_one.mp (h hb) exact Set.mem_range_self b' theorem isFractional_of_le {I : Submodule R P} {J : FractionalIdeal S P} (hIJ : I ≤ J) : IsFractional S I := by obtain ⟨a, a_mem, ha⟩ := J.isFractional use a, a_mem intro b b_mem exact ha b (hIJ b_mem) /-- Map an ideal `I` to a fractional ideal by forgetting `I` is integral. This is the function that implements the coercion `Ideal R → FractionalIdeal S P`. -/ @[coe] def coeIdeal (I : Ideal R) : FractionalIdeal S P := ⟨coeSubmodule P I, isFractional_of_le_one _ <| by simpa using coeSubmodule_mono P (le_top : I ≤ ⊤)⟩ -- Is a `CoeTC` rather than `Coe` to speed up failing inference, see library note [use has_coe_t] /-- Map an ideal `I` to a fractional ideal by forgetting `I` is integral. This is a bundled version of `IsLocalization.coeSubmodule : Ideal R → Submodule R P`, which is not to be confused with the `coe : FractionalIdeal S P → Submodule R P`, also called `coeToSubmodule` in theorem names. This map is available as a ring hom, called `FractionalIdeal.coeIdealHom`. -/ instance : CoeTC (Ideal R) (FractionalIdeal S P) := ⟨fun I => coeIdeal I⟩ @[simp, norm_cast] theorem coe_coeIdeal (I : Ideal R) : ((I : FractionalIdeal S P) : Submodule R P) = coeSubmodule P I := rfl variable (S) @[simp] theorem mem_coeIdeal {x : P} {I : Ideal R} : x ∈ (I : FractionalIdeal S P) ↔ ∃ x', x' ∈ I ∧ algebraMap R P x' = x := mem_coeSubmodule _ _ @[simp] -- Ensure `simp` is confluent for `x ∈ ((I : Ideal R) : FractionalIdeal S P)`. theorem mem_coeSubmodule {x : P} {I : Ideal R} : x ∈ coeSubmodule P I ↔ ∃ x', x' ∈ I ∧ algebraMap R P x' = x := Iff.rfl theorem mem_coeIdeal_of_mem {x : R} {I : Ideal R} (hx : x ∈ I) : algebraMap R P x ∈ (I : FractionalIdeal S P) := (mem_coeIdeal S).mpr ⟨x, hx, rfl⟩ theorem coeIdeal_le_coeIdeal' [IsLocalization S P] (h : S ≤ nonZeroDivisors R) {I J : Ideal R} : (I : FractionalIdeal S P) ≤ J ↔ I ≤ J := coeSubmodule_le_coeSubmodule h @[simp] theorem coeIdeal_le_coeIdeal (K : Type*) [CommRing K] [Algebra R K] [IsFractionRing R K] {I J : Ideal R} : (I : FractionalIdeal R⁰ K) ≤ J ↔ I ≤ J := IsFractionRing.coeSubmodule_le_coeSubmodule @[gcongr] protected alias ⟨_, GCongr.coeIdeal_le_coeIdeal⟩ := coeIdeal_le_coeIdeal instance : Zero (FractionalIdeal S P) := ⟨(0 : Ideal R)⟩ @[simp] theorem mem_zero_iff {x : P} : x ∈ (0 : FractionalIdeal S P) ↔ x = 0 := ⟨fun ⟨x', x'_mem_zero, x'_eq_x⟩ => by have x'_eq_zero : x' = 0 := x'_mem_zero simp [x'_eq_x.symm, x'_eq_zero], fun hx => ⟨0, rfl, by simp [hx]⟩⟩ variable {S} @[simp, norm_cast] theorem coe_zero : ↑(0 : FractionalIdeal S P) = (⊥ : Submodule R P) := Submodule.ext fun _ => mem_zero_iff S @[simp, norm_cast] theorem coeIdeal_bot : ((⊥ : Ideal R) : FractionalIdeal S P) = 0 := rfl section variable [loc : IsLocalization S P] variable (P) in -- Cannot be @[simp] because `S` cannot be inferred by `simp`. theorem exists_mem_algebraMap_eq {x : R} {I : Ideal R} (h : S ≤ nonZeroDivisors R) : (∃ x', x' ∈ I ∧ algebraMap R P x' = algebraMap R P x) ↔ x ∈ I := ⟨fun ⟨_, hx', Eq⟩ => IsLocalization.injective _ h Eq ▸ hx', fun h => ⟨x, h, rfl⟩⟩ theorem coeIdeal_injective' (h : S ≤ nonZeroDivisors R) : Function.Injective (fun (I : Ideal R) ↦ (I : FractionalIdeal S P)) := fun _ _ h' => ((coeIdeal_le_coeIdeal' S h).mp h'.le).antisymm ((coeIdeal_le_coeIdeal' S h).mp h'.ge) theorem coeIdeal_inj' (h : S ≤ nonZeroDivisors R) {I J : Ideal R} : (I : FractionalIdeal S P) = J ↔ I = J := (coeIdeal_injective' h).eq_iff -- Not `@[simp]` because `coeIdeal_eq_zero` (in `Operations.lean`) will prove this. theorem coeIdeal_eq_zero' {I : Ideal R} (h : S ≤ nonZeroDivisors R) : (I : FractionalIdeal S P) = 0 ↔ I = (⊥ : Ideal R) := coeIdeal_inj' h theorem coeIdeal_ne_zero' {I : Ideal R} (h : S ≤ nonZeroDivisors R) : (I : FractionalIdeal S P) ≠ 0 ↔ I ≠ (⊥ : Ideal R) := not_iff_not.mpr <| coeIdeal_eq_zero' h end theorem coeToSubmodule_eq_bot {I : FractionalIdeal S P} : (I : Submodule R P) = ⊥ ↔ I = 0 := ⟨fun h => coeToSubmodule_injective (by simp [h]), fun h => by simp [h]⟩ theorem coeToSubmodule_ne_bot {I : FractionalIdeal S P} : ↑I ≠ (⊥ : Submodule R P) ↔ I ≠ 0 := not_iff_not.mpr coeToSubmodule_eq_bot instance : Inhabited (FractionalIdeal S P) := ⟨0⟩ instance : One (FractionalIdeal S P) := ⟨(⊤ : Ideal R)⟩ theorem zero_of_num_eq_bot [NoZeroSMulDivisors R P] (hS : 0 ∉ S) {I : FractionalIdeal S P} (hI : I.num = ⊥) : I = 0 := by rw [← coeToSubmodule_eq_bot, eq_bot_iff] intro x hx suffices (den I : R) • x = 0 from (smul_eq_zero.mp this).resolve_left (ne_of_mem_of_not_mem (SetLike.coe_mem _) hS) have h_eq : I.den • (I : Submodule R P) = ⊥ := by rw [den_mul_self_eq_num, hI, Submodule.map_bot] exact (Submodule.eq_bot_iff _).mp h_eq (den I • x) ⟨x, hx, rfl⟩ theorem num_zero_eq (h_inj : Function.Injective (algebraMap R P)) : num (0 : FractionalIdeal S P) = 0 := by simpa [num, LinearMap.ker_eq_bot] using h_inj variable (S) @[simp, norm_cast] theorem coeIdeal_top : ((⊤ : Ideal R) : FractionalIdeal S P) = 1 := rfl theorem mem_one_iff {x : P} : x ∈ (1 : FractionalIdeal S P) ↔ ∃ x' : R, algebraMap R P x' = x := Iff.intro (fun ⟨x', _, h⟩ => ⟨x', h⟩) fun ⟨x', h⟩ => ⟨x', ⟨⟩, h⟩ theorem coe_mem_one (x : R) : algebraMap R P x ∈ (1 : FractionalIdeal S P) := (mem_one_iff S).mpr ⟨x, rfl⟩ theorem one_mem_one : (1 : P) ∈ (1 : FractionalIdeal S P) := (mem_one_iff S).mpr ⟨1, RingHom.map_one _⟩ variable {S} /-- `(1 : FractionalIdeal S P)` is defined as the R-submodule `f(R) ≤ P`. However, this is not definitionally equal to `1 : Submodule R P`, which is proved in the actual `simp` lemma `coe_one`. -/ theorem coe_one_eq_coeSubmodule_top : ↑(1 : FractionalIdeal S P) = coeSubmodule P (⊤ : Ideal R) := rfl @[simp, norm_cast] theorem coe_one : (↑(1 : FractionalIdeal S P) : Submodule R P) = 1 := by rw [coe_one_eq_coeSubmodule_top, coeSubmodule_top] section Lattice /-! ### `Lattice` section Defines the order on fractional ideals as inclusion of their underlying sets, and ports the lattice structure on submodules to fractional ideals. -/ @[simp] theorem coe_le_coe {I J : FractionalIdeal S P} : (I : Submodule R P) ≤ (J : Submodule R P) ↔ I ≤ J := Iff.rfl theorem zero_le (I : FractionalIdeal S P) : 0 ≤ I := by intro x hx convert zero_mem I rw [(mem_zero_iff _).mp hx] instance orderBot : OrderBot (FractionalIdeal S P) where bot := 0 bot_le := zero_le @[simp] theorem bot_eq_zero : (⊥ : FractionalIdeal S P) = 0 := rfl theorem le_zero_iff {I : FractionalIdeal S P} : I ≤ 0 ↔ I = 0 := le_bot_iff theorem eq_zero_iff {I : FractionalIdeal S P} : I = 0 ↔ ∀ x ∈ I, x = (0 : P) := ⟨fun h x hx => by simpa [h, mem_zero_iff] using hx, fun h => le_bot_iff.mp fun x hx => (mem_zero_iff S).mpr (h x hx)⟩ theorem _root_.IsFractional.sup {I J : Submodule R P} : IsFractional S I → IsFractional S J → IsFractional S (I ⊔ J) | ⟨aI, haI, hI⟩, ⟨aJ, haJ, hJ⟩ => ⟨aI * aJ, S.mul_mem haI haJ, fun b hb => by rcases mem_sup.mp hb with ⟨bI, hbI, bJ, hbJ, rfl⟩ rw [smul_add] apply isInteger_add · rw [mul_smul, smul_comm] exact isInteger_smul (hI bI hbI) · rw [mul_smul] exact isInteger_smul (hJ bJ hbJ)⟩ theorem _root_.IsFractional.inf_right {I : Submodule R P} : IsFractional S I → ∀ J, IsFractional S (I ⊓ J) | ⟨aI, haI, hI⟩, J => ⟨aI, haI, fun b hb => by rcases mem_inf.mp hb with ⟨hbI, _⟩ exact hI b hbI⟩ instance : Min (FractionalIdeal S P) := ⟨fun I J => ⟨I ⊓ J, I.isFractional.inf_right J⟩⟩ @[simp, norm_cast] theorem coe_inf (I J : FractionalIdeal S P) : ↑(I ⊓ J) = (I ⊓ J : Submodule R P) := rfl instance : Max (FractionalIdeal S P) := ⟨fun I J => ⟨I ⊔ J, I.isFractional.sup J.isFractional⟩⟩ @[norm_cast] theorem coe_sup (I J : FractionalIdeal S P) : ↑(I ⊔ J) = (I ⊔ J : Submodule R P) := rfl instance lattice : Lattice (FractionalIdeal S P) := Function.Injective.lattice _ Subtype.coe_injective coe_sup coe_inf instance : SemilatticeSup (FractionalIdeal S P) := { FractionalIdeal.lattice with } end Lattice section Semiring instance : Add (FractionalIdeal S P) := ⟨(· ⊔ ·)⟩ @[simp] theorem sup_eq_add (I J : FractionalIdeal S P) : I ⊔ J = I + J := rfl @[simp, norm_cast] theorem coe_add (I J : FractionalIdeal S P) : (↑(I + J) : Submodule R P) = I + J := rfl theorem mem_add (I J : FractionalIdeal S P) (x : P) : x ∈ I + J ↔ ∃ i ∈ I, ∃ j ∈ J, i + j = x := by rw [← mem_coe, coe_add, Submodule.add_eq_sup]; exact Submodule.mem_sup @[simp, norm_cast] lemma coeIdeal_inf [FaithfulSMul R P] (I J : Ideal R) : (↑(I ⊓ J) : FractionalIdeal S P) = ↑I ⊓ ↑J := by apply coeToSubmodule_injective exact Submodule.map_inf (Algebra.linearMap R P) (FaithfulSMul.algebraMap_injective R P) @[simp, norm_cast] theorem coeIdeal_sup (I J : Ideal R) : ↑(I ⊔ J) = (I + J : FractionalIdeal S P) := coeToSubmodule_injective <| coeSubmodule_sup _ _ _ theorem _root_.IsFractional.nsmul {I : Submodule R P} : ∀ n : ℕ, IsFractional S I → IsFractional S (n • I : Submodule R P) | 0, _ => by rw [zero_smul] convert ((0 : Ideal R) : FractionalIdeal S P).isFractional simp | n + 1, h => by rw [succ_nsmul] exact (IsFractional.nsmul n h).sup h instance : SMul ℕ (FractionalIdeal S P) where smul n I := ⟨n • ↑I, I.isFractional.nsmul n⟩ @[norm_cast] theorem coe_nsmul (n : ℕ) (I : FractionalIdeal S P) : (↑(n • I) : Submodule R P) = n • (I : Submodule R P) := rfl theorem _root_.IsFractional.mul {I J : Submodule R P} : IsFractional S I → IsFractional S J → IsFractional S (I * J : Submodule R P) | ⟨aI, haI, hI⟩, ⟨aJ, haJ, hJ⟩ => ⟨aI * aJ, S.mul_mem haI haJ, fun b hb => by refine Submodule.mul_induction_on hb ?_ ?_ · intro m hm n hn obtain ⟨n', hn'⟩ := hJ n hn rw [mul_smul, mul_comm m, ← smul_mul_assoc, ← hn', ← Algebra.smul_def] apply hI exact Submodule.smul_mem _ _ hm · intro x y hx hy rw [smul_add] apply isInteger_add hx hy⟩ theorem _root_.IsFractional.pow {I : Submodule R P} (h : IsFractional S I) : ∀ n : ℕ, IsFractional S (I ^ n : Submodule R P) | 0 => isFractional_of_le_one _ (pow_zero _).le | n + 1 => (pow_succ I n).symm ▸ (IsFractional.pow h n).mul h /-- `FractionalIdeal.mul` is the product of two fractional ideals, used to define the `Mul` instance. This is only an auxiliary definition: the preferred way of writing `I.mul J` is `I * J`. Elaborated terms involving `FractionalIdeal` tend to grow quite large, so by making definitions irreducible, we hope to avoid deep unfolds. -/ irreducible_def mul (lemma := mul_def') (I J : FractionalIdeal S P) : FractionalIdeal S P := ⟨I * J, I.isFractional.mul J.isFractional⟩ -- local attribute [semireducible] mul instance : Mul (FractionalIdeal S P) := ⟨fun I J => mul I J⟩ @[simp] theorem mul_eq_mul (I J : FractionalIdeal S P) : mul I J = I * J := rfl theorem mul_def (I J : FractionalIdeal S P) : I * J = ⟨I * J, I.isFractional.mul J.isFractional⟩ := by simp only [← mul_eq_mul, mul_def'] @[simp, norm_cast] theorem coe_mul (I J : FractionalIdeal S P) : (↑(I * J) : Submodule R P) = I * J := by simp only [mul_def, coe_mk] @[simp, norm_cast] theorem coeIdeal_mul (I J : Ideal R) : (↑(I * J) : FractionalIdeal S P) = I * J := by simp only [mul_def] exact coeToSubmodule_injective (coeSubmodule_mul _ _ _) instance : MulLeftMono (FractionalIdeal S P) where elim I J J' h := by simpa only [mul_def] using mul_le.mpr fun x hx y hy => mul_mem_mul hx (h hy) instance : MulRightMono (FractionalIdeal S P) where elim I J J' h := by simpa only [mul_def] using mul_le.mpr fun x hx y hy => mul_mem_mul (h hx) hy @[deprecated _root_.mul_right_mono (since := "2025-09-09")] protected theorem mul_left_mono (I : FractionalIdeal S P) : Monotone (I * ·) := mul_right_mono @[deprecated _root_.mul_left_mono (since := "2025-09-09")] protected lemma mul_right_mono (I : FractionalIdeal S P) : Monotone fun J => J * I := mul_left_mono theorem mul_mem_mul {I J : FractionalIdeal S P} {i j : P} (hi : i ∈ I) (hj : j ∈ J) : i * j ∈ I * J := by simp only [mul_def] exact Submodule.mul_mem_mul hi hj theorem mul_le {I J K : FractionalIdeal S P} : I * J ≤ K ↔ ∀ i ∈ I, ∀ j ∈ J, i * j ∈ K := by simp only [mul_def] exact Submodule.mul_le instance : Pow (FractionalIdeal S P) ℕ := ⟨fun I n => ⟨(I : Submodule R P) ^ n, I.isFractional.pow n⟩⟩ @[simp, norm_cast] theorem coe_pow (I : FractionalIdeal S P) (n : ℕ) : ↑(I ^ n) = (I : Submodule R P) ^ n := rfl @[elab_as_elim] protected theorem mul_induction_on {I J : FractionalIdeal S P} {C : P → Prop} {r : P} (hr : r ∈ I * J) (hm : ∀ i ∈ I, ∀ j ∈ J, C (i * j)) (ha : ∀ x y, C x → C y → C (x + y)) : C r := by simp only [mul_def] at hr exact Submodule.mul_induction_on hr hm ha instance : NatCast (FractionalIdeal S P) := ⟨Nat.unaryCast⟩ theorem coe_natCast (n : ℕ) : ((n : FractionalIdeal S P) : Submodule R P) = n := show ((n.unaryCast : FractionalIdeal S P) : Submodule R P) = n by induction n <;> simp [*, Nat.unaryCast] instance commSemiring : CommSemiring (FractionalIdeal S P) := Function.Injective.commSemiring _ Subtype.coe_injective coe_zero coe_one coe_add coe_mul (fun _ _ => coe_nsmul _ _) coe_pow coe_natCast instance : CanonicallyOrderedAdd (FractionalIdeal S P) where exists_add_of_le h := ⟨_, (sup_eq_right.mpr h).symm⟩ le_add_self _ _ := le_sup_right le_self_add _ _ := le_sup_left instance : IsOrderedRing (FractionalIdeal S P) := CanonicallyOrderedAdd.toIsOrderedRing end Semiring variable (S P) /-- `FractionalIdeal.coeToSubmodule` as a bundled `RingHom`. -/ @[simps] def coeSubmoduleHom : FractionalIdeal S P →+* Submodule R P where toFun := coeToSubmodule map_one' := coe_one map_mul' := coe_mul map_zero' := coe_zero (S := S) map_add' := coe_add variable {S P} section Order @[deprecated _root_.add_le_add_left (since := "2025-09-14")] theorem add_le_add_left {I J : FractionalIdeal S P} (hIJ : I ≤ J) (J' : FractionalIdeal S P) : J' + I ≤ J' + J := _root_.add_le_add_left hIJ _ @[deprecated mul_le_mul_left' (since := "2025-09-14")] theorem mul_le_mul_left {I J : FractionalIdeal S P} (hIJ : I ≤ J) (J' : FractionalIdeal S P) : J' * I ≤ J' * J := mul_le_mul_left' hIJ _ @[deprecated le_mul_of_one_le_left' (since := "2025-09-14")] theorem le_self_mul_self {I : FractionalIdeal S P} (hI : 1 ≤ I) : I ≤ I * I := le_mul_of_one_le_left' hI @[deprecated mul_le_of_le_one_left' (since := "2025-09-14")] theorem mul_self_le_self {I : FractionalIdeal S P} (hI : I ≤ 1) : I * I ≤ I := mul_le_of_le_one_left' hI theorem coeIdeal_le_one {I : Ideal R} : (I : FractionalIdeal S P) ≤ 1 := fun _ hx => let ⟨y, _, hy⟩ := (mem_coeIdeal S).mp hx (mem_one_iff S).mpr ⟨y, hy⟩ theorem le_one_iff_exists_coeIdeal {J : FractionalIdeal S P} : J ≤ (1 : FractionalIdeal S P) ↔ ∃ I : Ideal R, ↑I = J := by constructor · intro hJ refine ⟨⟨⟨⟨{ x : R | algebraMap R P x ∈ J }, ?_⟩, ?_⟩, ?_⟩, ?_⟩ · intro a b ha hb rw [mem_setOf, RingHom.map_add] exact J.val.add_mem ha hb · rw [mem_setOf, RingHom.map_zero] exact J.zero_mem · intro c x hx rw [smul_eq_mul, mem_setOf, RingHom.map_mul, ← Algebra.smul_def] exact J.val.smul_mem c hx · ext x constructor · rintro ⟨y, hy, eq_y⟩ rwa [← eq_y] · intro hx obtain ⟨y, rfl⟩ := (mem_one_iff S).mp (hJ hx) exact mem_setOf.mpr ⟨y, hx, rfl⟩ · rintro ⟨I, hI⟩ rw [← hI] apply coeIdeal_le_one @[simp] theorem one_le {I : FractionalIdeal S P} : 1 ≤ I ↔ (1 : P) ∈ I := by rw [← coe_le_coe, coe_one, Submodule.one_le, mem_coe] variable (S P) /-- `coeIdealHom (S : Submonoid R) P` is `(↑) : Ideal R → FractionalIdeal S P` as a ring hom -/ @[simps] def coeIdealHom : Ideal R →+* FractionalIdeal S P where toFun := coeIdeal map_add' := coeIdeal_sup map_mul' := coeIdeal_mul map_one' := by rw [Ideal.one_eq_top, coeIdeal_top] map_zero' := coeIdeal_bot theorem coeIdeal_pow (I : Ideal R) (n : ℕ) : ↑(I ^ n) = (I : FractionalIdeal S P) ^ n := (coeIdealHom S P).map_pow _ n theorem coeIdeal_finprod [IsLocalization S P] {α : Sort*} {f : α → Ideal R} (hS : S ≤ nonZeroDivisors R) : ((∏ᶠ a : α, f a : Ideal R) : FractionalIdeal S P) = ∏ᶠ a : α, (f a : FractionalIdeal S P) := MonoidHom.map_finprod_of_injective (coeIdealHom S P).toMonoidHom (coeIdeal_injective' hS) f end Order section FG variable {R : Type*} [CommRing R] [Nontrivial R] {S : Submonoid R} variable {P : Type*} [Nontrivial P] [CommRing P] [Algebra R P] [NoZeroSMulDivisors R P] /-- The fractional ideals of a Noetherian ring are finitely generated. -/ lemma fg_of_isNoetherianRing [hR : IsNoetherianRing R] (hS : S ≤ R⁰) (I : FractionalIdeal S P) : FG I.coeToSubmodule := by have := hR.noetherian I.num rw [← fg_top] at this ⊢ exact fg_of_linearEquiv (I.equivNum <| coe_ne_zero ⟨(I.den : R), hS (SetLike.coe_mem I.den)⟩) this end FG end FractionalIdeal
.lake/packages/mathlib/Mathlib/RingTheory/FractionalIdeal/Operations.lean
import Mathlib.Algebra.EuclideanDomain.Basic import Mathlib.RingTheory.FractionalIdeal.Basic import Mathlib.RingTheory.IntegralClosure.IsIntegral.Basic import Mathlib.RingTheory.LocalRing.Basic import Mathlib.RingTheory.PrincipalIdealDomain import Mathlib.Tactic.Field /-! # More operations on fractional ideals ## Main definitions * `map` is the pushforward of a fractional ideal along an algebra morphism Let `K` be the localization of `R` at `R⁰ = R \ {0}` (i.e. the field of fractions). * `FractionalIdeal R⁰ K` is the type of fractional ideals in the field of fractions * `Div (FractionalIdeal R⁰ K)` instance: the ideal quotient `I / J` (typically written $I : J$, but a `:` operator cannot be defined) ## Main statement * `isNoetherian` states that every fractional ideal of a Noetherian integral domain is Noetherian ## References * https://en.wikipedia.org/wiki/Fractional_ideal ## Tags fractional ideal, fractional ideals, invertible ideal -/ open IsLocalization Pointwise nonZeroDivisors namespace FractionalIdeal open Set Submodule variable {R : Type*} [CommRing R] {S : Submonoid R} {P : Type*} [CommRing P] variable [Algebra R P] section variable {P' : Type*} [CommRing P'] [Algebra R P'] variable {P'' : Type*} [CommRing P''] [Algebra R P''] theorem _root_.IsFractional.map (g : P →ₐ[R] P') {I : Submodule R P} : IsFractional S I → IsFractional S (Submodule.map g.toLinearMap I) | ⟨a, a_nonzero, hI⟩ => ⟨a, a_nonzero, fun b hb => by obtain ⟨b', b'_mem, hb'⟩ := Submodule.mem_map.mp hb rw [AlgHom.toLinearMap_apply] at hb' obtain ⟨x, hx⟩ := hI b' b'_mem use x rw [← g.commutes, hx, map_smul, hb']⟩ /-- `I.map g` is the pushforward of the fractional ideal `I` along the algebra morphism `g` -/ def map (g : P →ₐ[R] P') : FractionalIdeal S P → FractionalIdeal S P' := fun I => ⟨Submodule.map g.toLinearMap I, I.isFractional.map g⟩ @[simp, norm_cast] theorem coe_map (g : P →ₐ[R] P') (I : FractionalIdeal S P) : ↑(map g I) = Submodule.map g.toLinearMap I := rfl @[simp] theorem mem_map {I : FractionalIdeal S P} {g : P →ₐ[R] P'} {y : P'} : y ∈ I.map g ↔ ∃ x, x ∈ I ∧ g x = y := Submodule.mem_map variable (I J : FractionalIdeal S P) (g : P →ₐ[R] P') @[simp] theorem map_id : I.map (AlgHom.id _ _) = I := coeToSubmodule_injective (Submodule.map_id (I : Submodule R P)) @[simp] theorem map_comp (g' : P' →ₐ[R] P'') : I.map (g'.comp g) = (I.map g).map g' := coeToSubmodule_injective (Submodule.map_comp g.toLinearMap g'.toLinearMap I) @[simp, norm_cast] theorem map_coeIdeal (I : Ideal R) : (I : FractionalIdeal S P).map g = I := by ext x simp @[simp] protected theorem map_one : (1 : FractionalIdeal S P).map g = 1 := map_coeIdeal g ⊤ @[simp] protected theorem map_zero : (0 : FractionalIdeal S P).map g = 0 := map_coeIdeal g 0 @[simp] protected theorem map_add : (I + J).map g = I.map g + J.map g := coeToSubmodule_injective (Submodule.map_sup _ _ _) @[simp] protected theorem map_mul : (I * J).map g = I.map g * J.map g := by simp only [mul_def] exact coeToSubmodule_injective (Submodule.map_mul _ _ _) @[simp] theorem map_map_symm (g : P ≃ₐ[R] P') : (I.map (g : P →ₐ[R] P')).map (g.symm : P' →ₐ[R] P) = I := by rw [← map_comp, g.symm_comp, map_id] @[simp] theorem map_symm_map (I : FractionalIdeal S P') (g : P ≃ₐ[R] P') : (I.map (g.symm : P' →ₐ[R] P)).map (g : P →ₐ[R] P') = I := by rw [← map_comp, g.comp_symm, map_id] theorem map_mem_map {f : P →ₐ[R] P'} (h : Function.Injective f) {x : P} {I : FractionalIdeal S P} : f x ∈ map f I ↔ x ∈ I := mem_map.trans ⟨fun ⟨_, hx', x'_eq⟩ => h x'_eq ▸ hx', fun h => ⟨x, h, rfl⟩⟩ theorem map_injective (f : P →ₐ[R] P') (h : Function.Injective f) : Function.Injective (map f : FractionalIdeal S P → FractionalIdeal S P') := fun _ _ hIJ => ext fun _ => (map_mem_map h).symm.trans (hIJ.symm ▸ map_mem_map h) /-- If `g` is an equivalence, `map g` is an isomorphism -/ def mapEquiv (g : P ≃ₐ[R] P') : FractionalIdeal S P ≃+* FractionalIdeal S P' where toFun := map g invFun := map g.symm map_add' I J := FractionalIdeal.map_add I J _ map_mul' I J := FractionalIdeal.map_mul I J _ left_inv I := by rw [← map_comp, AlgEquiv.symm_comp, map_id] right_inv I := by rw [← map_comp, AlgEquiv.comp_symm, map_id] @[simp] theorem coeFun_mapEquiv (g : P ≃ₐ[R] P') : (mapEquiv g : FractionalIdeal S P → FractionalIdeal S P') = map g := rfl @[simp] theorem mapEquiv_apply (g : P ≃ₐ[R] P') (I : FractionalIdeal S P) : mapEquiv g I = map (↑g) I := rfl @[simp] theorem mapEquiv_symm (g : P ≃ₐ[R] P') : ((mapEquiv g).symm : FractionalIdeal S P' ≃+* _) = mapEquiv g.symm := rfl @[simp] theorem mapEquiv_refl : mapEquiv AlgEquiv.refl = RingEquiv.refl (FractionalIdeal S P) := RingEquiv.ext fun x => by simp theorem isFractional_span_iff {s : Set P} : IsFractional S (span R s) ↔ ∃ a ∈ S, ∀ b : P, b ∈ s → IsInteger R (a • b) := ⟨fun ⟨a, a_mem, h⟩ => ⟨a, a_mem, fun b hb => h b (subset_span hb)⟩, fun ⟨a, a_mem, h⟩ => ⟨a, a_mem, fun _ hb => span_induction (hx := hb) h (by rw [smul_zero] exact isInteger_zero) (fun x y _ _ hx hy => by rw [smul_add] exact isInteger_add hx hy) fun s x _ hx => by rw [smul_comm] exact isInteger_smul hx⟩⟩ theorem isFractional_of_fg [IsLocalization S P] {I : Submodule R P} (hI : I.FG) : IsFractional S I := by rcases hI with ⟨I, rfl⟩ rcases exist_integer_multiples_of_finset S I with ⟨⟨s, hs1⟩, hs⟩ rw [isFractional_span_iff] exact ⟨s, hs1, hs⟩ theorem mem_span_mul_finite_of_mem_mul {I J : FractionalIdeal S P} {x : P} (hx : x ∈ I * J) : ∃ T T' : Finset P, (T : Set P) ⊆ I ∧ (T' : Set P) ⊆ J ∧ x ∈ span R (T * T' : Set P) := Submodule.mem_span_mul_finite_of_mem_mul (by simpa using mem_coe.mpr hx) variable (S) in theorem coeIdeal_fg (inj : Function.Injective (algebraMap R P)) (I : Ideal R) : FG ((I : FractionalIdeal S P) : Submodule R P) ↔ I.FG := coeSubmodule_fg _ inj _ theorem fg_unit (I : (FractionalIdeal S P)ˣ) : FG (I : Submodule R P) := Submodule.fg_unit <| Units.map (coeSubmoduleHom S P).toMonoidHom I theorem fg_of_isUnit (I : FractionalIdeal S P) (h : IsUnit I) : FG (I : Submodule R P) := fg_unit h.unit theorem _root_.Ideal.fg_of_isUnit (inj : Function.Injective (algebraMap R P)) (I : Ideal R) (h : IsUnit (I : FractionalIdeal S P)) : I.FG := by rw [← coeIdeal_fg S inj I] exact FractionalIdeal.fg_of_isUnit (R := R) I h variable (S P P') variable [IsLocalization S P] [IsLocalization S P'] /-- `canonicalEquiv f f'` is the canonical equivalence between the fractional ideals in `P` and in `P'`, which are both localizations of `R` at `S`. -/ noncomputable irreducible_def canonicalEquiv : FractionalIdeal S P ≃+* FractionalIdeal S P' := mapEquiv { ringEquivOfRingEquiv P P' (RingEquiv.refl R) (show S.map _ = S by rw [RingEquiv.toMonoidHom_refl, Submonoid.map_id]) with commutes' := fun _ => ringEquivOfRingEquiv_eq _ _ } @[simp] theorem mem_canonicalEquiv_apply {I : FractionalIdeal S P} {x : P'} : x ∈ canonicalEquiv S P P' I ↔ ∃ y ∈ I, IsLocalization.map P' (RingHom.id R) (fun y (hy : y ∈ S) => show RingHom.id R y ∈ S from hy) (y : P) = x := by rw [canonicalEquiv, mapEquiv_apply, mem_map] exact ⟨fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩, fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩⟩ @[simp] theorem canonicalEquiv_symm : (canonicalEquiv S P P').symm = canonicalEquiv S P' P := RingEquiv.ext fun I => SetLike.ext_iff.mpr fun x => by rw [mem_canonicalEquiv_apply, canonicalEquiv, mapEquiv_symm, mapEquiv_apply, mem_map] exact ⟨fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩, fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩⟩ theorem canonicalEquiv_flip (I) : canonicalEquiv S P P' (canonicalEquiv S P' P I) = I := by rw [← canonicalEquiv_symm, RingEquiv.symm_apply_apply] @[simp] theorem canonicalEquiv_canonicalEquiv (P'' : Type*) [CommRing P''] [Algebra R P''] [IsLocalization S P''] (I : FractionalIdeal S P) : canonicalEquiv S P' P'' (canonicalEquiv S P P' I) = canonicalEquiv S P P'' I := by ext simp [IsLocalization.map_map] theorem canonicalEquiv_trans_canonicalEquiv (P'' : Type*) [CommRing P''] [Algebra R P''] [IsLocalization S P''] : (canonicalEquiv S P P').trans (canonicalEquiv S P' P'') = canonicalEquiv S P P'' := RingEquiv.ext (canonicalEquiv_canonicalEquiv S P P' P'') @[simp] theorem canonicalEquiv_coeIdeal (I : Ideal R) : canonicalEquiv S P P' I = I := by ext simp [IsLocalization.map_eq] @[simp] theorem canonicalEquiv_self : canonicalEquiv S P P = RingEquiv.refl _ := by rw [← canonicalEquiv_trans_canonicalEquiv S P P] convert (canonicalEquiv S P P).symm_trans_self exact (canonicalEquiv_symm S P P).symm end section IsFractionRing /-! ### `IsFractionRing` section This section concerns fractional ideals in the field of fractions, i.e. the type `FractionalIdeal R⁰ K` where `IsFractionRing R K`. -/ variable {K K' : Type*} [Field K] [Field K'] variable [Algebra R K] [IsFractionRing R K] [Algebra R K'] [IsFractionRing R K'] variable {I J : FractionalIdeal R⁰ K} (h : K →ₐ[R] K') /-- Nonzero fractional ideals contain a nonzero integer. -/ theorem exists_ne_zero_mem_isInteger [Nontrivial R] (hI : I ≠ 0) : ∃ x, x ≠ 0 ∧ algebraMap R K x ∈ I := by obtain ⟨y : K, y_mem, y_notMem⟩ := SetLike.exists_of_lt (by simpa only using bot_lt_iff_ne_bot.mpr hI) have y_ne_zero : y ≠ 0 := by simpa using y_notMem obtain ⟨z, ⟨x, hx⟩⟩ := exists_integer_multiple R⁰ y refine ⟨x, ?_, ?_⟩ · rw [Ne, ← @IsFractionRing.to_map_eq_zero_iff R _ K, hx, Algebra.smul_def] exact mul_ne_zero (IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors z.2) y_ne_zero · rw [hx] exact smul_mem _ _ y_mem theorem map_ne_zero [Nontrivial R] (hI : I ≠ 0) : I.map h ≠ 0 := by obtain ⟨x, x_ne_zero, hx⟩ := exists_ne_zero_mem_isInteger hI contrapose! x_ne_zero with map_eq_zero refine IsFractionRing.to_map_eq_zero_iff.mp (eq_zero_iff.mp map_eq_zero _ (mem_map.mpr ?_)) exact ⟨algebraMap R K x, hx, h.commutes x⟩ @[simp] theorem map_eq_zero_iff [Nontrivial R] : I.map h = 0 ↔ I = 0 := ⟨not_imp_not.mp (map_ne_zero _), fun hI => hI.symm ▸ FractionalIdeal.map_zero h⟩ theorem coeIdeal_injective : Function.Injective (fun (I : Ideal R) ↦ (I : FractionalIdeal R⁰ K)) := coeIdeal_injective' le_rfl theorem coeIdeal_inj {I J : Ideal R} : (I : FractionalIdeal R⁰ K) = (J : FractionalIdeal R⁰ K) ↔ I = J := coeIdeal_inj' le_rfl @[simp] theorem coeIdeal_eq_zero {I : Ideal R} : (I : FractionalIdeal R⁰ K) = 0 ↔ I = ⊥ := coeIdeal_eq_zero' le_rfl theorem coeIdeal_ne_zero {I : Ideal R} : (I : FractionalIdeal R⁰ K) ≠ 0 ↔ I ≠ ⊥ := coeIdeal_ne_zero' le_rfl @[simp] theorem coeIdeal_eq_one {I : Ideal R} : (I : FractionalIdeal R⁰ K) = 1 ↔ I = 1 := by simpa only [Ideal.one_eq_top] using coeIdeal_inj theorem coeIdeal_ne_one {I : Ideal R} : (I : FractionalIdeal R⁰ K) ≠ 1 ↔ I ≠ 1 := not_iff_not.mpr coeIdeal_eq_one theorem num_eq_zero_iff [Nontrivial R] {I : FractionalIdeal R⁰ K} : I.num = 0 ↔ I = 0 where mp h := zero_of_num_eq_bot zero_notMem_nonZeroDivisors h mpr h := h ▸ num_zero_eq (IsFractionRing.injective R K) end IsFractionRing section Quotient /-! ### `quotient` section This section defines the ideal quotient of fractional ideals. In this section we need that each non-zero `y : R` has an inverse in the localization, i.e. that the localization is a field. We satisfy this assumption by taking `S = nonZeroDivisors R`, `R`'s localization at which is a field because `R` is a domain. -/ variable {R₁ : Type*} [CommRing R₁] {K : Type*} [Field K] variable [Algebra R₁ K] instance : Nontrivial (FractionalIdeal R₁⁰ K) := ⟨⟨0, 1, fun h => have this : (1 : K) ∈ (0 : FractionalIdeal R₁⁰ K) := by rw [← (algebraMap R₁ K).map_one] simpa only [h] using coe_mem_one R₁⁰ 1 one_ne_zero ((mem_zero_iff _).mp this)⟩⟩ theorem ne_zero_of_mul_eq_one (I J : FractionalIdeal R₁⁰ K) (h : I * J = 1) : I ≠ 0 := fun hI => zero_ne_one' (FractionalIdeal R₁⁰ K) (by convert h simp [hI]) variable [IsFractionRing R₁ K] [IsDomain R₁] theorem _root_.IsFractional.div_of_nonzero {I J : Submodule R₁ K} : IsFractional R₁⁰ I → IsFractional R₁⁰ J → J ≠ 0 → IsFractional R₁⁰ (I / J) | ⟨aI, haI, hI⟩, ⟨aJ, haJ, hJ⟩, h => by obtain ⟨y, mem_J, notMem_zero⟩ := SetLike.exists_of_lt (show 0 < J by simpa only using bot_lt_iff_ne_bot.mpr h) obtain ⟨y', hy'⟩ := hJ y mem_J use aI * y' constructor · apply (nonZeroDivisors R₁).mul_mem haI (mem_nonZeroDivisors_iff_ne_zero.mpr _) intro y'_eq_zero have : algebraMap R₁ K aJ * y = 0 := by rw [← Algebra.smul_def, ← hy', y'_eq_zero, RingHom.map_zero] have y_zero := (mul_eq_zero.mp this).resolve_left (mt ((injective_iff_map_eq_zero (algebraMap R₁ K)).1 (IsFractionRing.injective _ _) _) (mem_nonZeroDivisors_iff_ne_zero.mp haJ)) apply notMem_zero simpa intro b hb convert hI _ (hb _ (Submodule.smul_mem _ aJ mem_J)) using 1 rw [← hy', mul_comm b, ← Algebra.smul_def, mul_smul] theorem isFractional_div_of_ne_zero {I J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) : IsFractional R₁⁰ (I / J : Submodule R₁ K) := I.isFractional.div_of_nonzero J.isFractional fun H => h <| coeToSubmodule_injective <| H.trans coe_zero.symm @[deprecated (since := "2025-09-14")] alias fractional_div_of_nonzero := isFractional_div_of_ne_zero open Classical in noncomputable instance : Div (FractionalIdeal R₁⁰ K) := ⟨fun I J => if h : J = 0 then 0 else ⟨I / J, isFractional_div_of_ne_zero h⟩⟩ variable {I J : FractionalIdeal R₁⁰ K} @[simp] theorem div_zero {I : FractionalIdeal R₁⁰ K} : I / 0 = 0 := dif_pos rfl theorem div_of_ne_zero {I J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) : I / J = ⟨I / J, isFractional_div_of_ne_zero h⟩ := dif_neg h @[deprecated (since := "2025-09-14")] alias div_nonzero := div_of_ne_zero @[simp] theorem coe_div {I J : FractionalIdeal R₁⁰ K} (hJ : J ≠ 0) : (↑(I / J) : Submodule R₁ K) = ↑I / (↑J : Submodule R₁ K) := congr_arg _ (dif_neg hJ) theorem mem_div_iff_of_ne_zero {I J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) {x} : x ∈ I / J ↔ ∀ y ∈ J, x * y ∈ I := by rw [div_of_ne_zero h] exact Submodule.mem_div_iff_forall_mul_mem @[deprecated (since := "2025-09-14")] alias mem_div_iff_of_nonzero := mem_div_iff_of_ne_zero theorem mul_one_div_le_one {I : FractionalIdeal R₁⁰ K} : I * (1 / I) ≤ 1 := by by_cases hI : I = 0 · rw [hI, div_zero, mul_zero] exact zero_le 1 · rw [← coe_le_coe, coe_mul, coe_div hI, coe_one] apply Submodule.mul_one_div_le_one theorem le_self_mul_one_div {I : FractionalIdeal R₁⁰ K} (hI : I ≤ (1 : FractionalIdeal R₁⁰ K)) : I ≤ I * (1 / I) := by by_cases hI_nz : I = 0 · rw [hI_nz, div_zero, mul_zero] · rw [← coe_le_coe, coe_mul, coe_div hI_nz, coe_one] rw [← coe_le_coe, coe_one] at hI exact Submodule.le_self_mul_one_div hI theorem le_div_iff_of_ne_zero {I J J' : FractionalIdeal R₁⁰ K} (hJ' : J' ≠ 0) : I ≤ J / J' ↔ ∀ x ∈ I, ∀ y ∈ J', x * y ∈ J := ⟨fun h _ hx => (mem_div_iff_of_ne_zero hJ').mp (h hx), fun h x hx => (mem_div_iff_of_ne_zero hJ').mpr (h x hx)⟩ @[deprecated (since := "2025-09-14")] alias le_div_iff_of_nonzero := le_div_iff_of_ne_zero theorem le_div_iff_mul_le {I J J' : FractionalIdeal R₁⁰ K} (hJ' : J' ≠ 0) : I ≤ J / J' ↔ I * J' ≤ J := by rw [div_of_ne_zero hJ', ← coe_le_coe (I := I * J') (J := J), coe_mul] exact Submodule.le_div_iff_mul_le @[simp] theorem div_one {I : FractionalIdeal R₁⁰ K} : I / 1 = I := by rw [div_of_ne_zero (one_ne_zero' (FractionalIdeal R₁⁰ K))] ext constructor <;> intro h · simpa using mem_div_iff_forall_mul_mem.mp h 1 ((algebraMap R₁ K).map_one ▸ coe_mem_one R₁⁰ 1) · apply mem_div_iff_forall_mul_mem.mpr rintro y ⟨y', _, rfl⟩ convert Submodule.smul_mem _ y' h using 1 rw [mul_comm, Algebra.linearMap_apply, ← Algebra.smul_def] theorem eq_one_div_of_mul_eq_one_right (I J : FractionalIdeal R₁⁰ K) (h : I * J = 1) : J = 1 / I := by have hI : I ≠ 0 := ne_zero_of_mul_eq_one I J h suffices h' : I * (1 / I) = 1 from congr_arg Units.inv <| @Units.ext _ _ (Units.mkOfMulEqOne _ _ h) (Units.mkOfMulEqOne _ _ h') rfl apply le_antisymm · apply mul_le.mpr _ intro x hx y hy rw [mul_comm] exact (mem_div_iff_of_ne_zero hI).mp hy x hx rw [← h] gcongr apply (le_div_iff_of_ne_zero hI).mpr _ intro y hy x hx rw [mul_comm] exact mul_mem_mul hy hx theorem mul_div_self_cancel_iff {I : FractionalIdeal R₁⁰ K} : I * (1 / I) = 1 ↔ ∃ J, I * J = 1 := ⟨fun h => ⟨1 / I, h⟩, fun ⟨J, hJ⟩ => by rwa [← eq_one_div_of_mul_eq_one_right I J hJ]⟩ variable {K' : Type*} [Field K'] [Algebra R₁ K'] [IsFractionRing R₁ K'] @[simp] protected theorem map_div (I J : FractionalIdeal R₁⁰ K) (h : K ≃ₐ[R₁] K') : (I / J).map (h : K →ₐ[R₁] K') = I.map h / J.map h := by by_cases H : J = 0 · rw [H, div_zero, FractionalIdeal.map_zero, div_zero] · simp [← coeToSubmodule_inj, div_of_ne_zero H, div_of_ne_zero (map_ne_zero _ H)] theorem map_one_div (I : FractionalIdeal R₁⁰ K) (h : K ≃ₐ[R₁] K') : (1 / I).map (h : K →ₐ[R₁] K') = 1 / I.map h := by rw [FractionalIdeal.map_div, FractionalIdeal.map_one] end Quotient section Field variable {R₁ K L : Type*} [CommRing R₁] [Field K] [Field L] variable [Algebra R₁ K] [IsFractionRing R₁ K] [Algebra K L] [IsFractionRing K L] theorem eq_zero_or_one (I : FractionalIdeal K⁰ L) : I = 0 ∨ I = 1 := by rw [or_iff_not_imp_left] intro hI simp_rw [@SetLike.ext_iff _ _ _ I 1, mem_one_iff] intro x constructor · intro x_mem obtain ⟨n, d, rfl⟩ := IsLocalization.exists_mk'_eq K⁰ x refine ⟨n / d, ?_⟩ rw [map_div₀, IsFractionRing.mk'_eq_div] · rintro ⟨x, rfl⟩ obtain ⟨y, y_ne, y_mem⟩ := exists_ne_zero_mem_isInteger hI rw [← div_mul_cancel₀ x y_ne, RingHom.map_mul, ← Algebra.smul_def] exact smul_mem (M := L) I (x / y) y_mem theorem eq_zero_or_one_of_isField (hF : IsField R₁) (I : FractionalIdeal R₁⁰ K) : I = 0 ∨ I = 1 := letI : Field R₁ := hF.toField eq_zero_or_one I end Field section PrincipalIdeal variable {R₁ : Type*} [CommRing R₁] {K : Type*} [Field K] variable [Algebra R₁ K] [IsFractionRing R₁ K] variable (R₁) /-- `FractionalIdeal.span_finset R₁ s f` is the fractional ideal of `R₁` generated by `f '' s`. -/ -- Porting note: `@[simps]` generated a `Subtype.val` coercion instead of a -- `FractionalIdeal.coeToSubmodule` coercion def spanFinset {ι : Type*} (s : Finset ι) (f : ι → K) : FractionalIdeal R₁⁰ K := ⟨Submodule.span R₁ (f '' s), by obtain ⟨a', ha'⟩ := IsLocalization.exist_integer_multiples R₁⁰ s f refine ⟨a', a'.2, fun x hx => Submodule.span_induction ?_ ?_ ?_ ?_ hx⟩ · rintro _ ⟨i, hi, rfl⟩ exact ha' i hi · rw [smul_zero] exact IsLocalization.isInteger_zero · intro x y _ _ hx hy rw [smul_add] exact IsLocalization.isInteger_add hx hy · intro c x _ hx rw [smul_comm] exact IsLocalization.isInteger_smul hx⟩ @[simp] lemma spanFinset_coe {ι : Type*} (s : Finset ι) (f : ι → K) : (spanFinset R₁ s f : Submodule R₁ K) = Submodule.span R₁ (f '' s) := rfl variable {R₁} @[simp] theorem spanFinset_eq_zero {ι : Type*} {s : Finset ι} {f : ι → K} : spanFinset R₁ s f = 0 ↔ ∀ j ∈ s, f j = 0 := by simp only [← coeToSubmodule_inj, spanFinset_coe, coe_zero, Submodule.span_eq_bot, Set.mem_image, Finset.mem_coe, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] theorem spanFinset_ne_zero {ι : Type*} {s : Finset ι} {f : ι → K} : spanFinset R₁ s f ≠ 0 ↔ ∃ j ∈ s, f j ≠ 0 := by simp open Submodule.IsPrincipal variable [IsLocalization S P] theorem isFractional_span_singleton (x : P) : IsFractional S (span R {x} : Submodule R P) := let ⟨a, ha⟩ := exists_integer_multiple S x isFractional_span_iff.mpr ⟨a, a.2, fun _ hx' => (Set.mem_singleton_iff.mp hx').symm ▸ ha⟩ variable (S) /-- `spanSingleton x` is the fractional ideal generated by `x` if `0 ∉ S` -/ irreducible_def spanSingleton (x : P) : FractionalIdeal S P := ⟨span R {x}, isFractional_span_singleton x⟩ -- local attribute [semireducible] span_singleton @[simp] theorem coe_spanSingleton (x : P) : (spanSingleton S x : Submodule R P) = span R {x} := by rw [spanSingleton] rfl @[simp] theorem mem_spanSingleton {x y : P} : x ∈ spanSingleton S y ↔ ∃ z : R, z • y = x := by rw [spanSingleton] exact Submodule.mem_span_singleton theorem mem_spanSingleton_self (x : P) : x ∈ spanSingleton S x := (mem_spanSingleton S).mpr ⟨1, one_smul _ _⟩ variable (P) in /-- A version of `FractionalIdeal.den_mul_self_eq_num` in terms of fractional ideals. -/ theorem den_mul_self_eq_num' (I : FractionalIdeal S P) : spanSingleton S (algebraMap R P I.den) * I = I.num := by apply coeToSubmodule_injective dsimp only rw [coe_mul, ← smul_eq_mul, coe_spanSingleton, smul_eq_mul, Submodule.span_singleton_mul] convert I.den_mul_self_eq_num using 1 ext rw [mem_smul_pointwise_iff_exists, mem_smul_pointwise_iff_exists] simp [smul_eq_mul, Algebra.smul_def, Submonoid.smul_def] variable {S} @[simp] theorem spanSingleton_le_iff_mem {x : P} {I : FractionalIdeal S P} : spanSingleton S x ≤ I ↔ x ∈ I := by rw [← coe_le_coe, coe_spanSingleton, Submodule.span_singleton_le_iff_mem, mem_coe] theorem spanSingleton_eq_spanSingleton [NoZeroSMulDivisors R P] {x y : P} : spanSingleton S x = spanSingleton S y ↔ ∃ z : Rˣ, z • x = y := by rw [← Submodule.span_singleton_eq_span_singleton, spanSingleton, spanSingleton] exact Subtype.mk_eq_mk theorem eq_spanSingleton_of_principal (I : FractionalIdeal S P) [IsPrincipal (I : Submodule R P)] : I = spanSingleton S (generator (I : Submodule R P)) := by -- Porting note: this used to be `coeToSubmodule_injective (span_singleton_generator ↑I).symm` -- but Lean 4 struggled to unify everything. Turned it into an explicit `rw`. rw [spanSingleton, ← coeToSubmodule_inj, coe_mk, span_singleton_generator] theorem isPrincipal_iff (I : FractionalIdeal S P) : IsPrincipal (I : Submodule R P) ↔ ∃ x, I = spanSingleton S x := ⟨fun _ => ⟨generator (I : Submodule R P), eq_spanSingleton_of_principal I⟩, fun ⟨x, hx⟩ => { principal := ⟨x, Eq.trans (congr_arg _ hx) (coe_spanSingleton _ x)⟩ }⟩ @[simp] theorem spanSingleton_zero : spanSingleton S (0 : P) = 0 := by ext simp [eq_comm] theorem spanSingleton_eq_zero_iff {y : P} : spanSingleton S y = 0 ↔ y = 0 := ⟨fun h => span_eq_bot.mp (by simpa using congr_arg Subtype.val h : span R {y} = ⊥) y (mem_singleton y), fun h => by simp [h]⟩ theorem spanSingleton_ne_zero_iff {y : P} : spanSingleton S y ≠ 0 ↔ y ≠ 0 := not_congr spanSingleton_eq_zero_iff @[simp] theorem spanSingleton_one : spanSingleton S (1 : P) = 1 := by ext refine (mem_spanSingleton S).trans ((exists_congr ?_).trans (mem_one_iff S).symm) intro x' rw [Algebra.smul_def, mul_one] @[simp] theorem spanSingleton_mul_spanSingleton (x y : P) : spanSingleton S x * spanSingleton S y = spanSingleton S (x * y) := by apply coeToSubmodule_injective simp only [coe_mul, coe_spanSingleton, span_mul_span, singleton_mul_singleton] @[simp] theorem spanSingleton_pow (x : P) (n : ℕ) : spanSingleton S x ^ n = spanSingleton S (x ^ n) := by induction n with | zero => rw [pow_zero, pow_zero, spanSingleton_one] | succ n hn => rw [pow_succ, hn, spanSingleton_mul_spanSingleton, pow_succ] @[simp] theorem coeIdeal_span_singleton (x : R) : (↑(Ideal.span {x} : Ideal R) : FractionalIdeal S P) = spanSingleton S (algebraMap R P x) := by ext y refine (mem_coeIdeal S).trans (Iff.trans ?_ (mem_spanSingleton S).symm) constructor · rintro ⟨y', hy', rfl⟩ obtain ⟨x', rfl⟩ := Submodule.mem_span_singleton.mp hy' use x' rw [smul_eq_mul, RingHom.map_mul, Algebra.smul_def] · rintro ⟨y', rfl⟩ refine ⟨y' * x, Submodule.mem_span_singleton.mpr ⟨y', rfl⟩, ?_⟩ rw [RingHom.map_mul, Algebra.smul_def] @[simp] theorem canonicalEquiv_spanSingleton {P'} [CommRing P'] [Algebra R P'] [IsLocalization S P'] (x : P) : canonicalEquiv S P P' (spanSingleton S x) = spanSingleton S (IsLocalization.map P' (RingHom.id R) (fun y (hy : y ∈ S) => show RingHom.id R y ∈ S from hy) x) := by apply SetLike.ext_iff.mpr intro y constructor <;> intro h · rw [mem_spanSingleton] obtain ⟨x', hx', rfl⟩ := (mem_canonicalEquiv_apply _ _ _).mp h obtain ⟨z, rfl⟩ := (mem_spanSingleton _).mp hx' use z rw [IsLocalization.map_smul, RingHom.id_apply] · rw [mem_canonicalEquiv_apply] obtain ⟨z, rfl⟩ := (mem_spanSingleton _).mp h use z • x use (mem_spanSingleton _).mpr ⟨z, rfl⟩ simp [IsLocalization.map_smul] theorem mem_singleton_mul {x y : P} {I : FractionalIdeal S P} : y ∈ spanSingleton S x * I ↔ ∃ y' ∈ I, y = x * y' := by constructor · intro h refine FractionalIdeal.mul_induction_on h ?_ ?_ · intro x' hx' y' hy' obtain ⟨a, ha⟩ := (mem_spanSingleton S).mp hx' use a • y', Submodule.smul_mem (I : Submodule R P) a hy' rw [← ha, Algebra.mul_smul_comm, Algebra.smul_mul_assoc] · rintro _ _ ⟨y, hy, rfl⟩ ⟨y', hy', rfl⟩ exact ⟨y + y', Submodule.add_mem (I : Submodule R P) hy hy', (mul_add _ _ _).symm⟩ · rintro ⟨y', hy', rfl⟩ exact mul_mem_mul ((mem_spanSingleton S).mpr ⟨1, one_smul _ _⟩) hy' variable (K) in theorem mk'_mul_coeIdeal_eq_coeIdeal {I J : Ideal R₁} {x y : R₁} (hy : y ∈ R₁⁰) : spanSingleton R₁⁰ (IsLocalization.mk' K x ⟨y, hy⟩) * I = (J : FractionalIdeal R₁⁰ K) ↔ Ideal.span {x} * I = Ideal.span {y} * J := by have : spanSingleton R₁⁰ (IsLocalization.mk' _ (1 : R₁) ⟨y, hy⟩) * spanSingleton R₁⁰ (algebraMap R₁ K y) = 1 := by rw [spanSingleton_mul_spanSingleton, mul_comm, ← IsLocalization.mk'_eq_mul_mk'_one, IsLocalization.mk'_self, spanSingleton_one] let y' : (FractionalIdeal R₁⁰ K)ˣ := Units.mkOfMulEqOne _ _ this have coe_y' : ↑y' = spanSingleton R₁⁰ (IsLocalization.mk' K (1 : R₁) ⟨y, hy⟩) := rfl refine Iff.trans ?_ (y'.mul_right_inj.trans coeIdeal_inj) rw [coe_y', coeIdeal_mul, coeIdeal_span_singleton, coeIdeal_mul, coeIdeal_span_singleton, ← mul_assoc, spanSingleton_mul_spanSingleton, ← mul_assoc, spanSingleton_mul_spanSingleton, mul_comm (mk' _ _ _), ← IsLocalization.mk'_eq_mul_mk'_one, mul_comm (mk' _ _ _), ← IsLocalization.mk'_eq_mul_mk'_one, IsLocalization.mk'_self, spanSingleton_one, one_mul] theorem spanSingleton_mul_coeIdeal_eq_coeIdeal {I J : Ideal R₁} {z : K} : spanSingleton R₁⁰ z * (I : FractionalIdeal R₁⁰ K) = J ↔ Ideal.span {((IsLocalization.sec R₁⁰ z).1 : R₁)} * I = Ideal.span {((IsLocalization.sec R₁⁰ z).2 : R₁)} * J := by rw [← mk'_mul_coeIdeal_eq_coeIdeal K (IsLocalization.sec R₁⁰ z).2.prop, IsLocalization.mk'_sec K z] variable [IsDomain R₁] theorem one_div_spanSingleton (x : K) : 1 / spanSingleton R₁⁰ x = spanSingleton R₁⁰ x⁻¹ := by classical exact if h : x = 0 then by simp [h] else (eq_one_div_of_mul_eq_one_right _ _ (by simp [h])).symm @[simp] theorem div_spanSingleton (J : FractionalIdeal R₁⁰ K) (d : K) : J / spanSingleton R₁⁰ d = spanSingleton R₁⁰ d⁻¹ * J := by rw [← one_div_spanSingleton] by_cases hd : d = 0 · simp only [hd, spanSingleton_zero, div_zero, zero_mul] have h_spand : spanSingleton R₁⁰ d ≠ 0 := mt spanSingleton_eq_zero_iff.mp hd apply le_antisymm · intro x hx dsimp only [val_eq_coe] at hx ⊢ -- Porting note: get rid of the partially applied `coe`s rw [coe_div h_spand, Submodule.mem_div_iff_forall_mul_mem] at hx specialize hx d (mem_spanSingleton_self R₁⁰ d) have h_xd : x = d⁻¹ * (x * d) := by field rw [coe_mul, one_div_spanSingleton, h_xd] exact Submodule.mul_mem_mul (mem_spanSingleton_self R₁⁰ _) hx · rw [le_div_iff_mul_le h_spand, mul_assoc, mul_left_comm, one_div_spanSingleton, spanSingleton_mul_spanSingleton, inv_mul_cancel₀ hd, spanSingleton_one, mul_one] theorem exists_eq_spanSingleton_mul (I : FractionalIdeal R₁⁰ K) : ∃ (a : R₁) (aI : Ideal R₁), a ≠ 0 ∧ I = spanSingleton R₁⁰ (algebraMap R₁ K a)⁻¹ * aI := by obtain ⟨a_inv, nonzero, ha⟩ := I.isFractional have nonzero := mem_nonZeroDivisors_iff_ne_zero.mp nonzero have map_a_nonzero : algebraMap R₁ K a_inv ≠ 0 := mt IsFractionRing.to_map_eq_zero_iff.mp nonzero refine ⟨a_inv, Submodule.comap (Algebra.linearMap R₁ K) ↑(spanSingleton R₁⁰ (algebraMap R₁ K a_inv) * I), nonzero, ext fun x => Iff.trans ⟨?_, ?_⟩ mem_singleton_mul.symm⟩ · intro hx obtain ⟨x', hx'⟩ := ha x hx rw [Algebra.smul_def] at hx' refine ⟨algebraMap R₁ K x', (mem_coeIdeal _).mpr ⟨x', mem_singleton_mul.mpr ?_, rfl⟩, ?_⟩ · exact ⟨x, hx, hx'⟩ · rw [hx', ← mul_assoc, inv_mul_cancel₀ map_a_nonzero, one_mul] · rintro ⟨y, hy, rfl⟩ obtain ⟨x', hx', rfl⟩ := (mem_coeIdeal _).mp hy obtain ⟨y', hy', hx'⟩ := mem_singleton_mul.mp hx' rw [Algebra.linearMap_apply] at hx' rwa [hx', ← mul_assoc, inv_mul_cancel₀ map_a_nonzero, one_mul] /-- If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of `R` such that `I = a⁻¹J`, then `J` is nonzero. -/ theorem ideal_factor_ne_zero {R} [CommRing R] {K : Type*} [Field K] [Algebra R K] [IsFractionRing R K] {I : FractionalIdeal R⁰ K} (hI : I ≠ 0) {a : R} {J : Ideal R} (haJ : I = spanSingleton R⁰ ((algebraMap R K) a)⁻¹ * ↑J) : J ≠ 0 := fun h ↦ by rw [h, Ideal.zero_eq_bot, coeIdeal_bot, mul_zero] at haJ exact hI haJ /-- If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of `R` such that `I = a⁻¹J`, then `a` is nonzero. -/ theorem constant_factor_ne_zero {R} [CommRing R] {K : Type*} [Field K] [Algebra R K] [IsFractionRing R K] {I : FractionalIdeal R⁰ K} (hI : I ≠ 0) {a : R} {J : Ideal R} (haJ : I = spanSingleton R⁰ ((algebraMap R K) a)⁻¹ * ↑J) : (Ideal.span {a} : Ideal R) ≠ 0 := fun h ↦ by rw [Ideal.zero_eq_bot, Ideal.span_singleton_eq_bot] at h rw [h, RingHom.map_zero, inv_zero, spanSingleton_zero, zero_mul] at haJ exact hI haJ instance isPrincipal {R} [CommRing R] [IsDomain R] [IsPrincipalIdealRing R] [Algebra R K] [IsFractionRing R K] (I : FractionalIdeal R⁰ K) : (I : Submodule R K).IsPrincipal := by obtain ⟨a, aI, -, ha⟩ := exists_eq_spanSingleton_mul I use (algebraMap R K a)⁻¹ * algebraMap R K (generator aI) suffices I = spanSingleton R⁰ ((algebraMap R K a)⁻¹ * algebraMap R K (generator aI)) by rw [spanSingleton] at this exact congr_arg Subtype.val this conv_lhs => rw [ha, ← span_singleton_generator aI] rw [Ideal.submodule_span_eq, coeIdeal_span_singleton (generator aI), spanSingleton_mul_spanSingleton] theorem le_spanSingleton_mul_iff {x : P} {I J : FractionalIdeal S P} : I ≤ spanSingleton S x * J ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI := show (∀ {zI} (_ : zI ∈ I), zI ∈ spanSingleton _ x * J) ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI by simp only [mem_singleton_mul, eq_comm] theorem spanSingleton_mul_le_iff {x : P} {I J : FractionalIdeal S P} : spanSingleton _ x * I ≤ J ↔ ∀ z ∈ I, x * z ∈ J := by simp only [mul_le, mem_spanSingleton] constructor · intro h zI hzI exact h x ⟨1, one_smul _ _⟩ zI hzI · rintro h _ ⟨z, rfl⟩ zI hzI rw [Algebra.smul_mul_assoc] exact Submodule.smul_mem J.1 _ (h zI hzI) theorem eq_spanSingleton_mul {x : P} {I J : FractionalIdeal S P} : I = spanSingleton _ x * J ↔ (∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI) ∧ ∀ z ∈ J, x * z ∈ I := by simp only [le_antisymm_iff, le_spanSingleton_mul_iff, spanSingleton_mul_le_iff] theorem num_le (I : FractionalIdeal S P) : (I.num : FractionalIdeal S P) ≤ I := by rw [← I.den_mul_self_eq_num', spanSingleton_mul_le_iff] intro _ h rw [← Algebra.smul_def] exact Submodule.smul_mem _ _ h end PrincipalIdeal variable {R₁ : Type*} [CommRing R₁] variable {K : Type*} [Field K] [Algebra R₁ K] theorem isNoetherian_zero : IsNoetherian R₁ (0 : FractionalIdeal R₁⁰ K) := isNoetherian_submodule.mpr fun I (hI : I ≤ (0 : FractionalIdeal R₁⁰ K)) => by rw [coe_zero, le_bot_iff] at hI rw [hI] exact fg_bot theorem isNoetherian_iff {I : FractionalIdeal R₁⁰ K} : IsNoetherian R₁ I ↔ ∀ J ≤ I, (J : Submodule R₁ K).FG := isNoetherian_submodule.trans ⟨fun h _ hJ => h _ hJ, fun h J hJ => h ⟨J, isFractional_of_le hJ⟩ hJ⟩ theorem isNoetherian_coeIdeal [IsNoetherianRing R₁] (I : Ideal R₁) : IsNoetherian R₁ (I : FractionalIdeal R₁⁰ K) := by rw [isNoetherian_iff] intro J hJ obtain ⟨J, rfl⟩ := le_one_iff_exists_coeIdeal.mp (le_trans hJ coeIdeal_le_one) exact (IsNoetherian.noetherian J).map _ variable [IsFractionRing R₁ K] [IsDomain R₁] theorem isNoetherian_spanSingleton_inv_to_map_mul (x : R₁) {I : FractionalIdeal R₁⁰ K} (hI : IsNoetherian R₁ I) : IsNoetherian R₁ (spanSingleton R₁⁰ (algebraMap R₁ K x)⁻¹ * I : FractionalIdeal R₁⁰ K) := by classical by_cases hx : x = 0 · rw [hx, RingHom.map_zero, inv_zero, spanSingleton_zero, zero_mul] exact isNoetherian_zero have h_gx : algebraMap R₁ K x ≠ 0 := mt ((injective_iff_map_eq_zero (algebraMap R₁ K)).mp (IsFractionRing.injective _ _) x) hx have h_spanx : spanSingleton R₁⁰ (algebraMap R₁ K x) ≠ 0 := spanSingleton_ne_zero_iff.mpr h_gx rw [isNoetherian_iff] at hI ⊢ intro J hJ rw [← div_spanSingleton, le_div_iff_mul_le h_spanx] at hJ obtain ⟨s, hs⟩ := hI _ hJ use s * {(algebraMap R₁ K x)⁻¹} rw [Finset.coe_mul, Finset.coe_singleton, ← span_mul_span, hs, ← coe_spanSingleton R₁⁰, ← coe_mul, mul_assoc, spanSingleton_mul_spanSingleton, mul_inv_cancel₀ h_gx, spanSingleton_one, mul_one] /-- Every fractional ideal of a Noetherian integral domain is Noetherian. -/ theorem isNoetherian [IsNoetherianRing R₁] (I : FractionalIdeal R₁⁰ K) : IsNoetherian R₁ I := by obtain ⟨d, J, _, rfl⟩ := exists_eq_spanSingleton_mul I apply isNoetherian_spanSingleton_inv_to_map_mul apply isNoetherian_coeIdeal section Adjoin variable (S) variable [IsLocalization S P] (x : P) /-- `A[x]` is a fractional ideal for every integral `x`. -/ theorem isFractional_adjoin_integral (hx : IsIntegral R x) : IsFractional S (Subalgebra.toSubmodule (Algebra.adjoin R ({x} : Set P))) := isFractional_of_fg hx.fg_adjoin_singleton /-- `FractionalIdeal.adjoinIntegral (S : Submonoid R) x hx` is `R[x]` as a fractional ideal, where `hx` is a proof that `x : P` is integral over `R`. -/ -- Porting note: `@[simps]` generated a `Subtype.val` coercion instead of a -- `FractionalIdeal.coeToSubmodule` coercion def adjoinIntegral (hx : IsIntegral R x) : FractionalIdeal S P := ⟨_, isFractional_adjoin_integral S x hx⟩ @[simp] theorem adjoinIntegral_coe (hx : IsIntegral R x) : (adjoinIntegral S x hx : Submodule R P) = (Subalgebra.toSubmodule (Algebra.adjoin R ({x} : Set P))) := rfl theorem mem_adjoinIntegral_self (hx : IsIntegral R x) : x ∈ adjoinIntegral S x hx := Algebra.subset_adjoin (Set.mem_singleton x) end Adjoin end FractionalIdeal
.lake/packages/mathlib/Mathlib/RingTheory/FractionalIdeal/Extended.lean
import Mathlib.RingTheory.DedekindDomain.Ideal.Lemmas /-! # Extension of fractional ideals This file defines the extension of a fractional ideal along a ring homomorphism. ## Main definitions * `FractionalIdeal.extended`: Let `A` and `B` be commutative rings with respective localizations `IsLocalization M K` and `IsLocalization N L`. Let `f : A →+* B` be a ring homomorphism with `hf : M ≤ Submonoid.comap f N`. If `I : FractionalIdeal M K`, then the extension of `I` along `f` is `extended L hf I : FractionalIdeal N L`. * `FractionalIdeal.extendedHom`: The ring homomorphism version of `FractionalIdeal.extended`. * `FractionalIdeal.extendedHomₐ`: For `A ⊆ B` an extension of domains, the ring homomorphism that sends a fractional ideal of `A` to a fractional ideal of `B`. ## Main results * `FractionalIdeal.extendedHomₐ_injective`: the map `FractionalIdeal.extendedHomₐ` is injective. * `Ideal.map_algebraMap_injective`: For `A ⊆ B` an extension of Dedekind domains, the map that sends an ideal `I` of `A` to `I·B` is injective. ## Tags fractional ideal, fractional ideals, extended, extension -/ open IsLocalization FractionalIdeal Submodule namespace FractionalIdeal section RingHom variable {A : Type*} [CommRing A] {B : Type*} [CommRing B] {f : A →+* B} variable {K : Type*} {M : Submonoid A} [CommRing K] [Algebra A K] [IsLocalization M K] variable (L : Type*) {N : Submonoid B} [CommRing L] [Algebra B L] [IsLocalization N L] variable (hf : M ≤ Submonoid.comap f N) variable (I : FractionalIdeal M K) (J : FractionalIdeal M K) /-- Given commutative rings `A` and `B` with respective localizations `IsLocalization M K` and `IsLocalization N L`, and a ring homomorphism `f : A →+* B` satisfying `M ≤ Submonoid.comap f N`, a fractional ideal `I` of `A` can be extended along `f` to a fractional ideal of `B`. -/ def extended (I : FractionalIdeal M K) : FractionalIdeal N L where val := span B <| (IsLocalization.map (S := K) L f hf) '' I property := by have ⟨a, ha, frac⟩ := I.isFractional refine ⟨f a, hf ha, fun b hb ↦ ?_⟩ refine span_induction (fun x hx ↦ ?_) ⟨0, by simp⟩ (fun x y _ _ hx hy ↦ smul_add (f a) x y ▸ isInteger_add hx hy) (fun b c _ hc ↦ ?_) hb · rcases hx with ⟨k, kI, rfl⟩ obtain ⟨c, hc⟩ := frac k kI exact ⟨f c, by simp [← IsLocalization.map_smul, ← hc]⟩ · rw [← smul_assoc, smul_eq_mul, mul_comm (f a), ← smul_eq_mul, smul_assoc] exact isInteger_smul hc local notation "map_f" => (IsLocalization.map (S := K) L f hf) lemma mem_extended_iff (x : L) : x ∈ I.extended L hf ↔ x ∈ span B (map_f '' I) := by constructor <;> { intro hx; simpa } @[simp] lemma coe_extended_eq_span : I.extended L hf = span B (map_f '' I) := by ext; simp [mem_coe, mem_extended_iff] @[simp] theorem extended_zero : extended L hf (0 : FractionalIdeal M K) = 0 := have : ((0 : FractionalIdeal M K) : Set K) = {0} := by ext; simp coeToSubmodule_injective (by simp [this]) variable {I} theorem extended_ne_zero [IsDomain B] (hf' : Function.Injective f) (hI : I ≠ 0) (hN : 0 ∉ N) : extended L hf I ≠ 0 := by simp only [ne_eq, ← coeToSubmodule_inj, coe_extended_eq_span, coe_zero, Submodule.span_eq_bot, Set.mem_image, SetLike.mem_coe, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂, not_forall] obtain ⟨x, hx₁, hx₂⟩ : ∃ x ∈ I, x ≠ 0 := by simpa [ne_eq, eq_zero_iff] using hI refine ⟨x, hx₁, ?_⟩ exact (map_ne_zero_iff _ (IsLocalization.map_injective_of_injective' _ _ _ _ hN hf')).mpr hx₂ @[simp] theorem extended_eq_zero_iff [IsDomain B] (hf' : Function.Injective f) (hN : 0 ∉ N) : extended L hf I = 0 ↔ I = 0 := by refine ⟨?_, fun h ↦ h ▸ extended_zero _ _⟩ contrapose! exact fun h ↦ extended_ne_zero L hf hf' h hN variable (I) @[simp] theorem extended_one : extended L hf (1 : FractionalIdeal M K) = 1 := by refine coeToSubmodule_injective <| Submodule.ext fun x ↦ ⟨fun hx ↦ span_induction ?_ (zero_mem _) (fun y z _ _ hy hz ↦ add_mem hy hz) (fun b y _ hy ↦ smul_mem _ b hy) hx, ?_⟩ · rintro ⟨b, _, rfl⟩ rw [Algebra.linearMap_apply, Algebra.algebraMap_eq_smul_one] exact smul_mem _ _ <| subset_span ⟨1, by simp [one_mem_one]⟩ · rintro _ ⟨_, ⟨a, ha, rfl⟩, rfl⟩ exact ⟨f a, ha, by rw [Algebra.linearMap_apply, Algebra.linearMap_apply, map_eq]⟩ theorem extended_le_one_of_le_one (hI : I ≤ 1) : extended L hf I ≤ 1 := by obtain ⟨J, rfl⟩ := le_one_iff_exists_coeIdeal.mp hI intro x hx simp only [val_eq_coe, mem_coe, mem_extended_iff, mem_span_image_iff_exists_fun, Finset.univ_eq_attach, coe_one] at hx ⊢ obtain ⟨s, hs, c, rfl⟩ := hx refine Submodule.sum_smul_mem _ _ fun x h ↦ mem_one.mpr ?_ obtain ⟨a, ha⟩ : ∃ a, (algebraMap A K) a = ↑x := by simpa [val_eq_coe, coe_one, mem_one] using hI <| hs x.prop exact ⟨f a, by rw [← ha, map_eq]⟩ theorem one_le_extended_of_one_le (hI : 1 ≤ I) : 1 ≤ extended L hf I := by rw [one_le] at hI ⊢ exact (mem_extended_iff _ _ _ _).mpr <| subset_span ⟨1, hI, by rw [map_one]⟩ theorem extended_add : (I + J).extended L hf = (I.extended L hf) + (J.extended L hf) := by apply coeToSubmodule_injective simp only [coe_extended_eq_span, coe_add, Submodule.add_eq_sup, ← span_union, ← Set.image_union] apply Submodule.span_eq_span · rintro _ ⟨y, hy, rfl⟩ obtain ⟨i, hi, j, hj, rfl⟩ := (mem_add I J y).mp <| SetLike.mem_coe.mp hy rw [RingHom.map_add] exact add_mem (Submodule.subset_span ⟨i, Set.mem_union_left _ hi, by simp⟩) (Submodule.subset_span ⟨j, Set.mem_union_right _ hj, by simp⟩) · rintro _ ⟨y, hy, rfl⟩ suffices y ∈ I + J from SetLike.mem_coe.mpr <| Submodule.subset_span ⟨y, by simp [this]⟩ exact hy.elim (fun h ↦ (mem_add I J y).mpr ⟨y, h, 0, zero_mem J, add_zero y⟩) (fun h ↦ (mem_add I J y).mpr ⟨0, zero_mem I, y, h, zero_add y⟩) theorem extended_mul : (I * J).extended L hf = (I.extended L hf) * (J.extended L hf) := by apply coeToSubmodule_injective simp only [coe_extended_eq_span, coe_mul, span_mul_span] refine Submodule.span_eq_span (fun _ h ↦ ?_) (fun _ h ↦ ?_) · rcases h with ⟨x, hx, rfl⟩ replace hx : x ∈ (I : Submodule A K) * (J : Submodule A K) := coe_mul I J ▸ hx rw [Submodule.mul_eq_span_mul_set] at hx refine span_induction (fun y hy ↦ ?_) (by simp) (fun y z _ _ hy hz ↦ ?_) (fun a y _ hy ↦ ?_) hx · rcases Set.mem_mul.mp hy with ⟨i, hi, j, hj, rfl⟩ exact subset_span <| Set.mem_mul.mpr ⟨map_f i, ⟨i, hi, by simp⟩, map_f j, ⟨j, hj, by simp⟩, by simp⟩ · exact map_add map_f y z ▸ Submodule.add_mem _ hy hz · rw [Algebra.smul_def, map_mul, map_eq, ← Algebra.smul_def] exact smul_mem _ (f a) hy · rcases Set.mem_mul.mp h with ⟨y, ⟨i, hi, rfl⟩, z, ⟨j, hj, rfl⟩, rfl⟩ exact Submodule.subset_span ⟨i * j, mul_mem_mul hi hj, by simp⟩ @[simp] theorem extended_coeIdeal_eq_map (I₀ : Ideal A) : (I₀ : FractionalIdeal M K).extended L hf = (I₀.map f : FractionalIdeal N L) := by rw [Ideal.map, Ideal.span, ← coeToSubmodule_inj, Ideal.submodule_span_eq, coe_coeIdeal, IsLocalization.coeSubmodule_span, coe_extended_eq_span] refine Submodule.span_eq_span ?_ ?_ · rintro _ ⟨_, ⟨a, ha, rfl⟩, rfl⟩ exact Submodule.subset_span ⟨f a, Set.mem_image_of_mem f ha, by rw [Algebra.linearMap_apply, IsLocalization.map_eq hf a]⟩ · rintro _ ⟨_ , ⟨a, ha, rfl⟩, rfl⟩ exact Submodule.subset_span ⟨algebraMap A K a, mem_coeIdeal_of_mem M ha, IsLocalization.map_eq hf a⟩ /-- The ring homomorphism version of `FractionalIdeal.extended`. -/ @[simps] def extendedHom : FractionalIdeal M K →+* FractionalIdeal N L where toFun := extended L hf map_one' := extended_one L hf map_zero' := extended_zero L hf map_mul' := extended_mul L hf map_add' := extended_add L hf end RingHom section Algebra open scoped nonZeroDivisors variable {A K : Type*} (L B : Type*) [CommRing A] [CommRing B] [IsDomain B] [Algebra A B] [NoZeroSMulDivisors A B] [Field K] [Field L] [Algebra A K] [Algebra B L] [IsFractionRing A K] [IsFractionRing B L] {I : FractionalIdeal A⁰ K} /-- The ring homomorphisme that extends a fractional ideal of `A` to a fractional ideal of `B` for `A ⊆ B` an extension of domains. -/ abbrev extendedHomₐ : FractionalIdeal A⁰ K →+* FractionalIdeal B⁰ L := extendedHom L <| nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ (FaithfulSMul.algebraMap_injective _ _) theorem extendedHomₐ_eq_zero_iff {I : FractionalIdeal A⁰ K} : extendedHomₐ L B I = 0 ↔ I = 0 := extended_eq_zero_iff _ _ (FaithfulSMul.algebraMap_injective _ _) zero_notMem_nonZeroDivisors theorem extendedHomₐ_coeIdeal_eq_map (I : Ideal A) : (I : FractionalIdeal A⁰ K).extendedHomₐ L B = (I.map (algebraMap A B) : FractionalIdeal B⁰ L) := extended_coeIdeal_eq_map L _ I variable [Algebra K L] [Algebra A L] [IsScalarTower A B L] [IsScalarTower A K L] [IsDomain A] [Algebra.IsIntegral A B] theorem coe_extendedHomₐ_eq_span (I : FractionalIdeal A⁰ K) : extendedHomₐ L B I = span B (algebraMap K L '' I) := by rw [extendedHom_apply, coe_extended_eq_span, IsLocalization.algebraMap_eq_map_map_submonoid A⁰ B K L] rfl theorem le_one_of_extendedHomₐ_le_one [IsIntegrallyClosed A] [IsIntegrallyClosed B] (hI : extendedHomₐ L B I ≤ 1) : I ≤ 1 := by contrapose! hI rw [SetLike.not_le_iff_exists] at hI ⊢ obtain ⟨x, hx₁, hx₂⟩ := hI refine ⟨algebraMap K L x, ?_, ?_⟩ · simpa [← FractionalIdeal.mem_coe, IsLocalization.algebraMap_eq_map_map_submonoid A⁰ B K L] using subset_span <| Set.mem_image_of_mem _ hx₁ · contrapose! hx₂ rw [mem_one_iff, ← IsIntegrallyClosed.isIntegral_iff] at hx₂ ⊢ exact IsIntegral.tower_bot_of_field <| isIntegral_trans _ hx₂ theorem extendedHomₐ_le_one_iff [IsIntegrallyClosed A] [IsIntegrallyClosed B] : extendedHomₐ L B I ≤ 1 ↔ I ≤ 1 := ⟨fun h ↦ le_one_of_extendedHomₐ_le_one L B h, fun a ↦ extended_le_one_of_le_one L _ I a⟩ section IsDedekindDomain variable [IsDedekindDomain A] [IsDedekindDomain B] theorem one_le_extendedHomₐ_iff (hI : I ≠ 0) : 1 ≤ extendedHomₐ L B I ↔ 1 ≤ I := by rw [← inv_le_inv_iff ((extendedHomₐ_eq_zero_iff _ _).not.mpr hI) (by simp), inv_one, ← map_inv₀, extendedHomₐ_le_one_iff, inv_le_comm hI (by simp), inv_one] theorem extendedHomₐ_eq_one_iff (hI : I ≠ 0) : extendedHomₐ L B I = 1 ↔ I = 1 := by rw [le_antisymm_iff, extendedHomₐ_le_one_iff, one_le_extendedHomₐ_iff _ _ hI, ← le_antisymm_iff] variable (A K) in theorem extendedHomₐ_injective : Function.Injective (fun I : FractionalIdeal A⁰ K ↦ extendedHomₐ L B I) := by intro I J h dsimp only at h by_cases hI : I = 0 · rwa [hI, map_zero, eq_comm, extendedHomₐ_eq_zero_iff L B, eq_comm, ← hI] at h by_cases hJ : J = 0 · rwa [hJ, map_zero, extendedHomₐ_eq_zero_iff L B, ← hJ] at h rwa [← mul_inv_eq_one₀ ((extendedHomₐ_eq_zero_iff _ _).not.mpr hJ), ← map_inv₀, ← map_mul, extendedHomₐ_eq_one_iff _ _ (mul_ne_zero hI (inv_ne_zero hJ)), mul_inv_eq_one₀ hJ] at h end IsDedekindDomain end Algebra end FractionalIdeal
.lake/packages/mathlib/Mathlib/RingTheory/PowerSeries/Substitution.lean
import Mathlib.RingTheory.MvPowerSeries.Substitution import Mathlib.RingTheory.PowerSeries.Evaluation /-! # Substitutions in power series A (possibly multivariate) power series can be substituted into a (univariate) power series if and only if its constant coefficient is nilpotent. This is a particularization of the substitution of multivariate power series to the case of univariate power series. Because of the special API for `PowerSeries`, some results for `MvPowerSeries` do not immediately apply and a “primed” version is provided here. -/ namespace PowerSeries variable {A : Type*} [CommRing A] {R : Type*} [CommRing R] [Algebra A R] {τ : Type*} {S : Type*} [CommRing S] open MvPowerSeries.WithPiTopology /-- (Possibly multivariate) power series which can be substituted in a `PowerSeries`. -/ abbrev HasSubst (a : MvPowerSeries τ S) : Prop := IsNilpotent (MvPowerSeries.constantCoeff a) theorem hasSubst_iff {a : MvPowerSeries τ S} : HasSubst a ↔ MvPowerSeries.HasSubst (Function.const Unit a) := ⟨fun ha ↦ MvPowerSeries.hasSubst_of_constantCoeff_nilpotent (Function.const Unit ha), fun ha ↦ (ha.const_coeff ())⟩ theorem HasSubst.const {a : MvPowerSeries τ S} (ha : HasSubst a) : MvPowerSeries.HasSubst (fun () ↦ a) := hasSubst_iff.mp ha theorem hasSubst_iff_hasEval_of_discreteTopology [TopologicalSpace S] [DiscreteTopology S] {a : MvPowerSeries τ S} : HasSubst a ↔ PowerSeries.HasEval a := by rw [hasSubst_iff, MvPowerSeries.hasSubst_iff_hasEval_of_discreteTopology, hasEval_iff, Function.const_def] theorem HasSubst.hasEval [TopologicalSpace S] {a : MvPowerSeries τ S} (ha : HasSubst a) : HasEval a := isTopologicallyNilpotent_of_constantCoeff_isNilpotent ha theorem HasSubst.of_constantCoeff_zero {a : MvPowerSeries τ S} (ha : MvPowerSeries.constantCoeff a = 0) : HasSubst a := by simp [HasSubst, ha] /-- A variant of `HasSubst.of_constantCoeff_zero` for `PowerSeries` to avoid the expansion of `Unit`. -/ theorem HasSubst.of_constantCoeff_zero' {a : PowerSeries S} (ha : PowerSeries.constantCoeff a = 0) : HasSubst a := HasSubst.of_constantCoeff_zero ha protected theorem HasSubst.X (t : τ) : HasSubst (MvPowerSeries.X t : MvPowerSeries τ S) := by simp [HasSubst] /-- The univariate `X : R⟦X⟧` can be substituted in power series This lemma is added because `simp` doesn't find it from `HasSubst.X`. -/ protected theorem HasSubst.X' : HasSubst (X : R⟦X⟧) := HasSubst.X _ protected theorem HasSubst.X_pow {n : ℕ} (hn : n ≠ 0) : HasSubst (X ^ n : R⟦X⟧) := HasSubst.of_constantCoeff_zero' (by simp [hn]) protected theorem HasSubst.monomial {n : τ →₀ ℕ} (hn : n ≠ 0) (s : S) : HasSubst (MvPowerSeries.monomial n s) := by classical apply HasSubst.of_constantCoeff_zero rw [← MvPowerSeries.coeff_zero_eq_constantCoeff, MvPowerSeries.coeff_monomial, if_neg hn.symm] /-- A variant of `HasSubst.monomial` to avoid the expansion of `Unit`. -/ protected theorem HasSubst.monomial' {n : ℕ} (hn : n ≠ 0) (s : S) : HasSubst (monomial n s) := HasSubst.monomial (Finsupp.single_ne_zero.mpr hn) s theorem HasSubst.zero : HasSubst (0 : MvPowerSeries τ R) := by rw [hasSubst_iff] exact MvPowerSeries.HasSubst.zero /-- A variant of `HasSubst.zero` to avoid the expansion of `Unit`. -/ theorem HasSubst.zero' : HasSubst (0 : PowerSeries R) := PowerSeries.HasSubst.zero variable {f g : MvPowerSeries τ R} theorem HasSubst.add (hf : HasSubst f) (hg : HasSubst g) : HasSubst (f + g) := (Commute.all _ _).isNilpotent_add hf hg theorem HasSubst.mul_left (hf : HasSubst f) : HasSubst (f * g) := by simp only [HasSubst, map_mul] exact (Commute.all _ _).isNilpotent_mul_right hf theorem HasSubst.mul_right (hf : HasSubst f) : HasSubst (g * f) := by simp only [HasSubst, map_mul] exact (Commute.all _ _).isNilpotent_mul_left hf theorem HasSubst.smul (r : MvPowerSeries τ S) {a : MvPowerSeries τ S} (ha : HasSubst a) : HasSubst (r • a) := ha.mul_right /-- Families of `PowerSeries` that can be substituted, as an `Ideal`. -/ noncomputable def HasSubst.ideal : Ideal (MvPowerSeries τ S) where carrier := setOf HasSubst add_mem' := HasSubst.add zero_mem' := HasSubst.zero smul_mem' := HasSubst.smul /-- A more general version of `HasSubst.smul`. -/ theorem HasSubst.smul' (a : A) (hf : HasSubst f) : HasSubst (a • f) := by simp only [HasSubst, MvPowerSeries.constantCoeff_smul] exact IsNilpotent.smul hf _ theorem HasSubst.smul_X (a : A) (t : τ) : HasSubst (a • (MvPowerSeries.X t) : MvPowerSeries τ R) := (HasSubst.X t).smul' _ theorem HasSubst.smul_X' (a : A) : HasSubst (a • X : R⟦X⟧) := HasSubst.X'.smul' _ variable {υ : Type*} {T : Type*} [CommRing T] [Algebra R S] [Algebra R T] [Algebra S T] /-- Substitution of power series into a power series. -/ noncomputable def subst (a : MvPowerSeries τ S) (f : PowerSeries R) : MvPowerSeries τ S := MvPowerSeries.subst (fun _ ↦ a) f variable {a : MvPowerSeries τ S} {b : S⟦X⟧} /-- Substitution of power series into a power series, as an `AlgHom`. -/ noncomputable def substAlgHom (ha : HasSubst a) : PowerSeries R →ₐ[R] MvPowerSeries τ S := MvPowerSeries.substAlgHom ha.const theorem coe_substAlgHom (ha : HasSubst a) : ⇑(substAlgHom ha) = subst (R := R) a := MvPowerSeries.coe_substAlgHom ha.const attribute [local instance] DiscreteTopology.instContinuousSMul in /-- Rewrite `PowerSeries.substAlgHom` as `PowerSeries.aeval`. Its use is discouraged because it introduces a topology and might lead into awkward comparisons. -/ theorem substAlgHom_eq_aeval [UniformSpace R] [DiscreteUniformity R] [UniformSpace S] [DiscreteUniformity S] (ha : HasSubst a) : (substAlgHom ha : R⟦X⟧ →ₐ[R] MvPowerSeries τ S) = PowerSeries.aeval ha.hasEval := by ext1 f simpa [substAlgHom] using congr_fun (MvPowerSeries.substAlgHom_eq_aeval ha.const) f theorem subst_add (ha : HasSubst a) (f g : PowerSeries R) : subst a (f + g) = subst a f + subst a g := by rw [← coe_substAlgHom ha, map_add] theorem subst_pow (ha : HasSubst a) (f : PowerSeries R) (n : ℕ) : subst a (f ^ n) = (subst a f) ^ n := by rw [← coe_substAlgHom ha, map_pow] theorem subst_mul (ha : HasSubst a) (f g : PowerSeries R) : subst a (f * g) = subst a f * subst a g := by rw [← coe_substAlgHom ha, map_mul] theorem subst_smul [Algebra A S] [IsScalarTower A R S] (ha : HasSubst a) (r : A) (f : PowerSeries R) : subst a (r • f) = r • (subst a f) := by rw [← coe_substAlgHom ha, AlgHom.map_smul_of_tower] theorem coeff_subst_finite (ha : HasSubst a) (f : PowerSeries R) (e : τ →₀ ℕ) : Set.Finite (fun (d : ℕ) ↦ coeff d f • MvPowerSeries.coeff e (a ^ d)).support := by convert (MvPowerSeries.coeff_subst_finite ha.const f e).image (Finsupp.LinearEquiv.finsuppUnique ℕ ℕ Unit).toEquiv rw [← Equiv.preimage_eq_iff_eq_image, ← Function.support_comp_eq_preimage] apply congr_arg rw [← Equiv.eq_comp_symm] ext simp [coeff] theorem coeff_subst_finite' (hb : HasSubst b) (f : PowerSeries R) (e : ℕ) : Set.Finite (fun (d : ℕ) ↦ coeff d f • (PowerSeries.coeff e (b ^ d))).support := coeff_subst_finite hb f _ theorem coeff_subst (ha : HasSubst a) (f : PowerSeries R) (e : τ →₀ ℕ) : MvPowerSeries.coeff e (subst a f) = finsum (fun (d : ℕ) ↦ coeff d f • (MvPowerSeries.coeff e (a ^ d))) := by rw [subst, MvPowerSeries.coeff_subst ha.const f e, ← finsum_comp_equiv (Finsupp.LinearEquiv.finsuppUnique ℕ ℕ Unit).toEquiv.symm] apply finsum_congr intro congr <;> simp theorem coeff_subst' {b : S⟦X⟧} (hb : HasSubst b) (f : R⟦X⟧) (e : ℕ) : coeff e (f.subst b) = finsum (fun (d : ℕ) ↦ coeff d f • PowerSeries.coeff e (b ^ d)) := by simp [PowerSeries.coeff, coeff_subst hb] theorem constantCoeff_subst (ha : HasSubst a) (f : PowerSeries R) : MvPowerSeries.constantCoeff (subst a f) = finsum (fun d ↦ coeff d f • MvPowerSeries.constantCoeff (a ^ d)) := by simp only [← MvPowerSeries.coeff_zero_eq_constantCoeff_apply, coeff_subst ha f 0] theorem map_algebraMap_eq_subst_X (f : R⟦X⟧) : map (algebraMap R S) f = subst X f := MvPowerSeries.map_algebraMap_eq_subst_X f theorem _root_.Polynomial.toPowerSeries_toMvPowerSeries (p : Polynomial R) : (p : PowerSeries R) = ((Polynomial.aeval (MvPolynomial.X ()) p : MvPolynomial Unit R) : MvPowerSeries Unit R) := by suffices (Polynomial.coeToPowerSeries.algHom R) p = (MvPolynomial.coeToMvPowerSeries.algHom R) (Polynomial.aeval (MvPolynomial.X () : MvPolynomial Unit R) p) by simpa rw [← AlgHom.comp_apply] apply AlgHom.congr_fun apply Polynomial.algHom_ext simp [X] theorem substAlgHom_coe (ha : HasSubst a) (p : Polynomial R) : substAlgHom ha (p : PowerSeries R) = ↑(Polynomial.aeval a p) := by rw [p.toPowerSeries_toMvPowerSeries, substAlgHom, MvPowerSeries.coe_substAlgHom, MvPowerSeries.subst_coe, ← AlgHom.comp_apply] apply AlgHom.congr_fun apply Polynomial.algHom_ext simp theorem substAlgHom_X (ha : HasSubst a) : substAlgHom ha (X : R⟦X⟧) = a := by rw [← Polynomial.coe_X, substAlgHom_coe, Polynomial.aeval_X] theorem subst_coe (ha : HasSubst a) (p : Polynomial R) : subst a (p : PowerSeries R) = (Polynomial.aeval a p) := by rw [← coe_substAlgHom ha, substAlgHom_coe] theorem subst_X (ha : HasSubst a) : subst a (X : R⟦X⟧) = a := by rw [← coe_substAlgHom ha, substAlgHom_X] theorem HasSubst.comp {a : PowerSeries S} (ha : HasSubst a) {b : MvPowerSeries υ T} (hb : HasSubst b) : HasSubst (substAlgHom hb a) := MvPowerSeries.IsNilpotent_subst hb.const ha variable {a : PowerSeries S} {b : MvPowerSeries υ T} {a' : MvPowerSeries τ S} {b' : τ → MvPowerSeries υ T} [IsScalarTower R S T] theorem substAlgHom_comp_substAlgHom (ha : HasSubst a) (hb : HasSubst b) : ((substAlgHom hb).restrictScalars R).comp (substAlgHom ha) = substAlgHom (ha.comp hb) := MvPowerSeries.substAlgHom_comp_substAlgHom _ _ theorem substAlgHom_comp_substAlgHom_apply (ha : HasSubst a) (hb : HasSubst b) (f : PowerSeries R) : (substAlgHom hb) (substAlgHom ha f) = substAlgHom (ha.comp hb) f := DFunLike.congr_fun (substAlgHom_comp_substAlgHom ha hb) f theorem subst_comp_subst (ha : HasSubst a) (hb : HasSubst b) : (subst b) ∘ (subst a) = subst (R := R) (subst b a) := by simpa [funext_iff, DFunLike.ext_iff, coe_substAlgHom] using substAlgHom_comp_substAlgHom ha hb theorem subst_comp_subst_apply (ha : HasSubst a) (hb : HasSubst b) (f : PowerSeries R) : subst b (subst a f) = subst (subst b a) f := congr_fun (subst_comp_subst ha hb) f theorem _root_.MvPowerSeries.rescaleUnit (a : R) (f : R⟦X⟧) : MvPowerSeries.rescale (Function.const _ a) f = rescale a f := by ext d rw [coeff_rescale, coeff, MvPowerSeries.coeff_rescale] simp end PowerSeries
.lake/packages/mathlib/Mathlib/RingTheory/PowerSeries/Inverse.lean
import Mathlib.Algebra.Polynomial.FieldDivision import Mathlib.RingTheory.DiscreteValuationRing.Basic import Mathlib.RingTheory.MvPowerSeries.Inverse import Mathlib.RingTheory.PowerSeries.NoZeroDivisors import Mathlib.RingTheory.LocalRing.ResidueField.Defs import Mathlib.RingTheory.UniqueFactorizationDomain.Multiplicity import Mathlib.Data.ENat.Lattice /-! # Formal power series - Inverses If the constant coefficient of a formal (univariate) power series is invertible, then this formal power series is invertible. (See the discussion in `Mathlib/RingTheory/MvPowerSeries/Inverse.lean` for the construction.) Formal (univariate) power series over a local ring form a local ring. Formal (univariate) power series over a field form a discrete valuation ring, and a normalization monoid. The definition `residueFieldOfPowerSeries` provides the isomorphism between the residue field of `k⟦X⟧` and `k`, when `k` is a field. -/ noncomputable section open Polynomial open Finset (antidiagonal mem_antidiagonal) namespace PowerSeries open Finsupp (single) variable {R : Type*} section Ring variable [Ring R] /-- Auxiliary function used for computing inverse of a power series -/ protected def inv.aux : R → R⟦X⟧ → R⟦X⟧ := MvPowerSeries.inv.aux theorem coeff_inv_aux (n : ℕ) (a : R) (φ : R⟦X⟧) : coeff n (inv.aux a φ) = if n = 0 then a else -a * ∑ x ∈ antidiagonal n, if x.2 < n then coeff x.1 φ * coeff x.2 (inv.aux a φ) else 0 := by rw [coeff, inv.aux, MvPowerSeries.coeff_inv_aux] simp only [Finsupp.single_eq_zero] split_ifs; · rfl congr 1 symm apply Finset.sum_nbij' (fun (a, b) ↦ (single () a, single () b)) fun (f, g) ↦ (f (), g ()) · aesop · aesop · aesop · aesop · rintro ⟨i, j⟩ _hij obtain H | H := le_or_gt n j · aesop rw [if_pos H, if_pos] · rfl refine ⟨?_, fun hh ↦ H.not_ge ?_⟩ · rintro ⟨⟩ simpa [Finsupp.single_eq_same] using le_of_lt H · simpa [Finsupp.single_eq_same] using hh () /-- A formal power series is invertible if the constant coefficient is invertible. -/ def invOfUnit (φ : R⟦X⟧) (u : Rˣ) : R⟦X⟧ := MvPowerSeries.invOfUnit φ u theorem coeff_invOfUnit (n : ℕ) (φ : R⟦X⟧) (u : Rˣ) : coeff n (invOfUnit φ u) = if n = 0 then ↑u⁻¹ else -↑u⁻¹ * ∑ x ∈ antidiagonal n, if x.2 < n then coeff x.1 φ * coeff x.2 (invOfUnit φ u) else 0 := coeff_inv_aux n (↑u⁻¹ : R) φ @[simp] theorem constantCoeff_invOfUnit (φ : R⟦X⟧) (u : Rˣ) : constantCoeff (invOfUnit φ u) = ↑u⁻¹ := by rw [← coeff_zero_eq_constantCoeff_apply, coeff_invOfUnit, if_pos rfl] @[simp] theorem mul_invOfUnit (φ : R⟦X⟧) (u : Rˣ) (h : constantCoeff φ = u) : φ * invOfUnit φ u = 1 := MvPowerSeries.mul_invOfUnit φ u <| h @[simp] theorem invOfUnit_mul (φ : R⟦X⟧) (u : Rˣ) (h : constantCoeff φ = u) : invOfUnit φ u * φ = 1 := MvPowerSeries.invOfUnit_mul φ u h theorem isUnit_iff_constantCoeff {φ : R⟦X⟧} : IsUnit φ ↔ IsUnit (constantCoeff φ) := MvPowerSeries.isUnit_iff_constantCoeff /-- Two ways of removing the constant coefficient of a power series are the same. -/ theorem sub_const_eq_shift_mul_X (φ : R⟦X⟧) : φ - C (constantCoeff φ) = (mk fun p ↦ coeff (p + 1) φ) * X := sub_eq_iff_eq_add.mpr (eq_shift_mul_X_add_const φ) theorem sub_const_eq_X_mul_shift (φ : R⟦X⟧) : φ - C (constantCoeff φ) = X * mk fun p ↦ coeff (p + 1) φ := sub_eq_iff_eq_add.mpr (eq_X_mul_shift_add_const φ) end Ring section Field variable {k : Type*} [Field k] /-- The inverse 1/f of a power series f defined over a field -/ protected def inv : k⟦X⟧ → k⟦X⟧ := MvPowerSeries.inv instance : Inv k⟦X⟧ := ⟨PowerSeries.inv⟩ theorem inv_eq_inv_aux (φ : k⟦X⟧) : φ⁻¹ = inv.aux (constantCoeff φ)⁻¹ φ := rfl theorem coeff_inv (n) (φ : k⟦X⟧) : coeff n φ⁻¹ = if n = 0 then (constantCoeff φ)⁻¹ else -(constantCoeff φ)⁻¹ * ∑ x ∈ antidiagonal n, if x.2 < n then coeff x.1 φ * coeff x.2 φ⁻¹ else 0 := by rw [inv_eq_inv_aux, coeff_inv_aux n (constantCoeff φ)⁻¹ φ] @[simp] theorem constantCoeff_inv (φ : k⟦X⟧) : constantCoeff φ⁻¹ = (constantCoeff φ)⁻¹ := MvPowerSeries.constantCoeff_inv φ theorem inv_eq_zero {φ : k⟦X⟧} : φ⁻¹ = 0 ↔ constantCoeff φ = 0 := MvPowerSeries.inv_eq_zero theorem zero_inv : (0 : k⟦X⟧)⁻¹ = 0 := MvPowerSeries.zero_inv @[simp] theorem invOfUnit_eq (φ : k⟦X⟧) (h : constantCoeff φ ≠ 0) : invOfUnit φ (Units.mk0 _ h) = φ⁻¹ := rfl @[simp] theorem invOfUnit_eq' (φ : k⟦X⟧) (u : Units k) (h : constantCoeff φ = u) : invOfUnit φ u = φ⁻¹ := MvPowerSeries.invOfUnit_eq' φ _ h @[simp] protected theorem mul_inv_cancel (φ : k⟦X⟧) (h : constantCoeff φ ≠ 0) : φ * φ⁻¹ = 1 := MvPowerSeries.mul_inv_cancel φ h @[simp] protected theorem inv_mul_cancel (φ : k⟦X⟧) (h : constantCoeff φ ≠ 0) : φ⁻¹ * φ = 1 := MvPowerSeries.inv_mul_cancel φ h theorem eq_mul_inv_iff_mul_eq {φ₁ φ₂ φ₃ : k⟦X⟧} (h : constantCoeff φ₃ ≠ 0) : φ₁ = φ₂ * φ₃⁻¹ ↔ φ₁ * φ₃ = φ₂ := MvPowerSeries.eq_mul_inv_iff_mul_eq h theorem eq_inv_iff_mul_eq_one {φ ψ : k⟦X⟧} (h : constantCoeff ψ ≠ 0) : φ = ψ⁻¹ ↔ φ * ψ = 1 := MvPowerSeries.eq_inv_iff_mul_eq_one h theorem inv_eq_iff_mul_eq_one {φ ψ : k⟦X⟧} (h : constantCoeff ψ ≠ 0) : ψ⁻¹ = φ ↔ φ * ψ = 1 := MvPowerSeries.inv_eq_iff_mul_eq_one h protected theorem mul_inv_rev (φ ψ : k⟦X⟧) : (φ * ψ)⁻¹ = ψ⁻¹ * φ⁻¹ := MvPowerSeries.mul_inv_rev _ _ instance : InvOneClass k⟦X⟧ := { inferInstanceAs <| InvOneClass <| MvPowerSeries Unit k with } @[simp] theorem C_inv (r : k) : (C r)⁻¹ = C r⁻¹ := MvPowerSeries.C_inv _ @[simp] theorem X_inv : (X : k⟦X⟧)⁻¹ = 0 := MvPowerSeries.X_inv _ theorem smul_inv (r : k) (φ : k⟦X⟧) : (r • φ)⁻¹ = r⁻¹ • φ⁻¹ := MvPowerSeries.smul_inv _ _ /-- `firstUnitCoeff` is the non-zero coefficient whose index is `f.order`, seen as a unit of the field. It is obtained using `divided_by_X_pow_order`, defined in `PowerSeries.Order`. -/ def firstUnitCoeff {f : k⟦X⟧} (hf : f ≠ 0) : kˣ := have : Invertible (constantCoeff (divXPowOrder f)) := by apply invertibleOfNonzero simpa [constantCoeff_divXPowOrder_eq_zero_iff.not] unitOfInvertible (constantCoeff (divXPowOrder f)) /-- `Inv_divided_by_X_pow_order` is the inverse of the element obtained by diving a non-zero power series by the largest power of `X` dividing it. Useful to create a term of type `Units`, done in `Unit_divided_by_X_pow_order` -/ def Inv_divided_by_X_pow_order {f : k⟦X⟧} (hf : f ≠ 0) : k⟦X⟧ := invOfUnit (divXPowOrder f) (firstUnitCoeff hf) @[simp] theorem Inv_divided_by_X_pow_order_rightInv {f : k⟦X⟧} (hf : f ≠ 0) : divXPowOrder f * Inv_divided_by_X_pow_order hf = 1 := mul_invOfUnit (divXPowOrder f) (firstUnitCoeff hf) rfl @[simp] theorem Inv_divided_by_X_pow_order_leftInv {f : k⟦X⟧} (hf : f ≠ 0) : Inv_divided_by_X_pow_order hf * divXPowOrder f = 1 := by rw [mul_comm] exact mul_invOfUnit (divXPowOrder f) (firstUnitCoeff hf) rfl open scoped Classical in /-- `Unit_of_divided_by_X_pow_order` is the unit power series obtained by dividing a non-zero power series by the largest power of `X` that divides it. -/ def Unit_of_divided_by_X_pow_order (f : k⟦X⟧) : k⟦X⟧ˣ := if hf : f = 0 then 1 else { val := divXPowOrder f inv := Inv_divided_by_X_pow_order hf val_inv := Inv_divided_by_X_pow_order_rightInv hf inv_val := Inv_divided_by_X_pow_order_leftInv hf } theorem isUnit_divided_by_X_pow_order {f : k⟦X⟧} (hf : f ≠ 0) : IsUnit (divXPowOrder f) := ⟨Unit_of_divided_by_X_pow_order f, by simp only [Unit_of_divided_by_X_pow_order, dif_neg hf, Units.val_mk]⟩ theorem Unit_of_divided_by_X_pow_order_nonzero {f : k⟦X⟧} (hf : f ≠ 0) : ↑(Unit_of_divided_by_X_pow_order f) = divXPowOrder f := by simp only [Unit_of_divided_by_X_pow_order, dif_neg hf, Units.val_mk] @[simp] theorem Unit_of_divided_by_X_pow_order_zero : Unit_of_divided_by_X_pow_order (0 : k⟦X⟧) = 1 := by simp only [Unit_of_divided_by_X_pow_order, dif_pos] theorem eq_divided_by_X_pow_order_Iff_Unit {f : k⟦X⟧} (hf : f ≠ 0) : f = divXPowOrder f ↔ IsUnit f := ⟨fun h ↦ by rw [h]; exact isUnit_divided_by_X_pow_order hf, fun h ↦ by have : f.order = 0 := by simp [order_zero_of_unit h] conv_lhs => rw [← X_pow_order_mul_divXPowOrder (f := f), this, ENat.toNat_zero, pow_zero, one_mul]⟩ end Field section IsLocalRing variable {S : Type*} [CommRing R] [CommRing S] (f : R →+* S) [IsLocalHom f] @[instance] theorem map.isLocalHom : IsLocalHom (map f) := MvPowerSeries.map.isLocalHom f variable [IsLocalRing R] instance : IsLocalRing R⟦X⟧ := { inferInstanceAs <| IsLocalRing <| MvPowerSeries Unit R with } end IsLocalRing section IsDiscreteValuationRing variable {k : Type*} [Field k] open IsDiscreteValuationRing theorem hasUnitMulPowIrreducibleFactorization : HasUnitMulPowIrreducibleFactorization k⟦X⟧ := ⟨X, And.intro X_irreducible (by intro f hf use f.order.toNat use Unit_of_divided_by_X_pow_order f simp only [Unit_of_divided_by_X_pow_order_nonzero hf] exact X_pow_order_mul_divXPowOrder)⟩ instance : UniqueFactorizationMonoid k⟦X⟧ := hasUnitMulPowIrreducibleFactorization.toUniqueFactorizationMonoid instance : IsDiscreteValuationRing k⟦X⟧ := ofHasUnitMulPowIrreducibleFactorization hasUnitMulPowIrreducibleFactorization instance isNoetherianRing : IsNoetherianRing k⟦X⟧ := PrincipalIdealRing.isNoetherianRing /-- The maximal ideal of `k⟦X⟧` is generated by `X`. -/ theorem maximalIdeal_eq_span_X : IsLocalRing.maximalIdeal (k⟦X⟧) = Ideal.span {X} := by have hX : (Ideal.span {(X : k⟦X⟧)}).IsMaximal := by rw [Ideal.isMaximal_iff] constructor · rw [Ideal.mem_span_singleton] exact Prime.not_dvd_one X_prime · intro I f hI hfX hfI rw [Ideal.mem_span_singleton, X_dvd_iff] at hfX have hfI0 : C (f 0) ∈ I := by have : C (f 0) = f - (f - C (f 0)) := by rw [sub_sub_cancel] rw [this] apply Ideal.sub_mem I hfI apply hI rw [Ideal.mem_span_singleton, X_dvd_iff, map_sub, constantCoeff_C, ← coeff_zero_eq_constantCoeff_apply, sub_eq_zero, coeff_zero_eq_constantCoeff] rfl rw [← Ideal.eq_top_iff_one] apply Ideal.eq_top_of_isUnit_mem I hfI0 (IsUnit.map C (Ne.isUnit hfX)) rw [IsLocalRing.eq_maximalIdeal hX] instance : NormalizationMonoid k⟦X⟧ where normUnit f := (Unit_of_divided_by_X_pow_order f)⁻¹ normUnit_zero := by simp only [Unit_of_divided_by_X_pow_order_zero, inv_one] normUnit_mul := fun hf hg ↦ by simp only [← mul_inv, inv_inj] simp only [Unit_of_divided_by_X_pow_order_nonzero (mul_ne_zero hf hg), Unit_of_divided_by_X_pow_order_nonzero hf, Unit_of_divided_by_X_pow_order_nonzero hg, Units.ext_iff, Units.val_mul, ← divXPowOrder_mul] normUnit_coe_units := by intro u set u₀ := u.1 with hu have h₀ : IsUnit u₀ := ⟨u, hu.symm⟩ rw [inv_inj, Units.ext_iff, ← hu, Unit_of_divided_by_X_pow_order_nonzero h₀.ne_zero] exact ((eq_divided_by_X_pow_order_Iff_Unit h₀.ne_zero).mpr h₀).symm theorem normUnit_X : normUnit (X : k⟦X⟧) = 1 := by simp [normUnit, ← Units.val_eq_one, Unit_of_divided_by_X_pow_order_nonzero] theorem X_eq_normalizeX : (X : k⟦X⟧) = normalize X := by simp only [normalize_apply, normUnit_X, Units.val_one, mul_one] open UniqueFactorizationMonoid open scoped Classical in theorem normalized_count_X_eq_of_coe {P : k[X]} (hP : P ≠ 0) : Multiset.count PowerSeries.X (normalizedFactors (P : k⟦X⟧)) = Multiset.count Polynomial.X (normalizedFactors P) := by apply eq_of_forall_le_iff simp only [← Nat.cast_le (α := ℕ∞)] rw [X_eq_normalize, PowerSeries.X_eq_normalizeX, ← emultiplicity_eq_count_normalizedFactors irreducible_X hP, ← emultiplicity_eq_count_normalizedFactors X_irreducible] <;> simp only [← pow_dvd_iff_le_emultiplicity, Polynomial.X_pow_dvd_iff, PowerSeries.X_pow_dvd_iff, Polynomial.coeff_coe P, implies_true, ne_eq, coe_eq_zero_iff, hP, not_false_eq_true] open IsLocalRing theorem ker_coeff_eq_max_ideal : RingHom.ker (constantCoeff (R := k)) = maximalIdeal _ := Ideal.ext fun _ ↦ by rw [RingHom.mem_ker, maximalIdeal_eq_span_X, Ideal.mem_span_singleton, X_dvd_iff] /-- The ring isomorphism between the residue field of the ring of power series valued in a field `K` and `K` itself. -/ def residueFieldOfPowerSeries : ResidueField k⟦X⟧ ≃+* k := (Ideal.quotEquivOfEq (ker_coeff_eq_max_ideal).symm).trans (RingHom.quotientKerEquivOfSurjective constantCoeff_surj) end IsDiscreteValuationRing end PowerSeries end
.lake/packages/mathlib/Mathlib/RingTheory/PowerSeries/PiTopology.lean
import Mathlib.RingTheory.MvPowerSeries.PiTopology import Mathlib.RingTheory.PowerSeries.Basic import Mathlib.RingTheory.PowerSeries.Order import Mathlib.RingTheory.PowerSeries.Trunc import Mathlib.LinearAlgebra.Finsupp.Pi import Mathlib.Topology.Algebra.InfiniteSum.Ring /-! # Product topology on power series Let `R` be with `Semiring R` and `TopologicalSpace R` In this file we define the topology on `PowerSeries σ R` that corresponds to the simple convergence on its coefficients. It is the coarsest topology for which all coefficients maps are continuous. When `R` has `UniformSpace R`, we define the corresponding uniform structure. This topology can be included by writing `open scoped PowerSeries.WithPiTopology`. When the type of coefficients has the discrete topology, it corresponds to the topology defined by [N. Bourbaki, *Algebra {II}*, Chapter 4, §4, n°2][bourbaki1981]. It corresponds with the adic topology but this is not proved here. - `PowerSeries.WithPiTopology.isTopologicallyNilpotent_of_constantCoeff_isNilpotent`, `PowerSeries.WithPiTopology.isTopologicallyNilpotent_of_constantCoeff_zero`: if the constant coefficient of `f` is nilpotent, or vanishes, then `f` is topologically nilpotent. - `PowerSeries.WithPiTopology.isTopologicallyNilpotent_iff_constantCoeff_isNilpotent` : assuming the base ring has the discrete topology, `f` is topologically nilpotent iff the constant coefficient of `f` is nilpotent. - `PowerSeries.WithPiTopology.hasSum_of_monomials_self` : viewed as an infinite sum, a power series converges to itself. TODO: add the similar result for the series of homogeneous components. ## Instances - If `R` is a topological (semi)ring, then so is `PowerSeries σ R`. - If the topology of `R` is T0 or T2, then so is that of `PowerSeries σ R`. - If `R` is a `IsUniformAddGroup`, then so is `PowerSeries σ R`. - If `R` is complete, then so is `PowerSeries σ R`. -/ namespace PowerSeries open Filter Function variable (R : Type*) section Topological variable [TopologicalSpace R] namespace WithPiTopology open scoped Topology /-- The pointwise topology on `PowerSeries` -/ scoped instance : TopologicalSpace (PowerSeries R) := Pi.topologicalSpace /-- Separation of the topology on `PowerSeries` -/ @[scoped instance] theorem instT0Space [T0Space R] : T0Space (PowerSeries R) := MvPowerSeries.WithPiTopology.instT0Space /-- `PowerSeries` on a `T2Space` form a `T2Space` -/ @[scoped instance] theorem instT2Space [T2Space R] : T2Space (PowerSeries R) := MvPowerSeries.WithPiTopology.instT2Space /-- Coefficients are continuous -/ theorem continuous_coeff [Semiring R] (d : ℕ) : Continuous (PowerSeries.coeff (R := R) d) := continuous_pi_iff.mp continuous_id (Finsupp.single () d) /-- The constant coefficient is continuous -/ theorem continuous_constantCoeff [Semiring R] : Continuous (constantCoeff (R := R)) := coeff_zero_eq_constantCoeff (R := R) ▸ continuous_coeff R 0 /-- A family of power series converges iff it converges coefficientwise -/ theorem tendsto_iff_coeff_tendsto [Semiring R] {ι : Type*} (f : ι → PowerSeries R) (u : Filter ι) (g : PowerSeries R) : Tendsto f u (nhds g) ↔ ∀ d : ℕ, Tendsto (fun i => coeff d (f i)) u (nhds (coeff d g)) := by rw [MvPowerSeries.WithPiTopology.tendsto_iff_coeff_tendsto] apply (Finsupp.LinearEquiv.finsuppUnique ℕ ℕ Unit).toEquiv.forall_congr intro d simp only [LinearEquiv.coe_toEquiv, Finsupp.LinearEquiv.finsuppUnique_apply, PUnit.default_eq_unit, coeff] apply iff_of_eq congr · ext _; congr; ext; simp · ext; simp theorem tendsto_trunc_atTop [CommSemiring R] (f : R⟦X⟧) : Tendsto (fun d ↦ (trunc d f : R⟦X⟧)) atTop (𝓝 f) := by rw [tendsto_iff_coeff_tendsto] intro d exact tendsto_atTop_of_eventually_const fun n (hdn : d < n) ↦ (by simp [coeff_trunc, hdn]) /-- The inclusion of polynomials into power series has dense image -/ theorem denseRange_toPowerSeries [CommSemiring R] : DenseRange (Polynomial.toPowerSeries (R := R)) := fun f => mem_closure_of_tendsto (tendsto_trunc_atTop R f) <| .of_forall fun _ ↦ Set.mem_range_self _ /-- The semiring topology on `PowerSeries` of a topological semiring -/ @[scoped instance] theorem instIsTopologicalSemiring [Semiring R] [IsTopologicalSemiring R] : IsTopologicalSemiring (PowerSeries R) := MvPowerSeries.WithPiTopology.instIsTopologicalSemiring Unit R /-- The ring topology on `PowerSeries` of a topological ring -/ @[scoped instance] theorem instIsTopologicalRing [Ring R] [IsTopologicalRing R] : IsTopologicalRing (PowerSeries R) := MvPowerSeries.WithPiTopology.instIsTopologicalRing Unit R section Sum variable [Semiring R] {ι : Type*} {f : ι → R⟦X⟧} theorem hasSum_iff_hasSum_coeff {g : R⟦X⟧} : HasSum f g ↔ ∀ d, HasSum (fun i ↦ coeff d (f i)) (coeff d g) := by simp_rw [HasSum, ← map_sum] apply tendsto_iff_coeff_tendsto theorem summable_iff_summable_coeff : Summable f ↔ ∀ d : ℕ, Summable (fun i ↦ coeff d (f i)) := by simp_rw [Summable, hasSum_iff_hasSum_coeff] constructor · rintro ⟨a, h⟩ n exact ⟨coeff n a, h n⟩ · intro h choose a h using h exact ⟨mk a, by simpa using h⟩ /-- A family of `PowerSeries` is summable if their order tends to infinity. -/ theorem summable_of_tendsto_order_atTop_nhds_top [LinearOrder ι] [LocallyFiniteOrderBot ι] (h : Tendsto (fun i ↦ (f i).order) atTop (𝓝 ⊤)) : Summable f := by rcases isEmpty_or_nonempty ι with hempty | hempty · apply summable_empty rw [summable_iff_summable_coeff] intro n simp_rw [ENat.tendsto_nhds_top_iff_natCast_lt, Filter.eventually_atTop] at h obtain ⟨i, hi⟩ := h n refine summable_of_finite_support <| (Set.finite_Iic i).subset ?_ simp_rw [Function.support_subset_iff, Set.mem_Iic] intro k hk contrapose! hk exact coeff_of_lt_order _ <| by simpa using (hi k hk.le) variable {R} in /-- The geometric series converges if the constant term is zero. -/ theorem summable_pow_of_constantCoeff_eq_zero {f : PowerSeries R} (h : f.constantCoeff = 0) : Summable (f ^ ·) := MvPowerSeries.WithPiTopology.summable_pow_of_constantCoeff_eq_zero h section GeomSeries variable {R : Type*} [TopologicalSpace R] [Ring R] [IsTopologicalRing R] [T2Space R] variable {f : PowerSeries R} /-- Formula for geometric series. -/ theorem tsum_pow_mul_one_sub_of_constantCoeff_eq_zero (h : f.constantCoeff = 0) : (∑' (i : ℕ), f ^ i) * (1 - f) = 1 := (summable_pow_of_constantCoeff_eq_zero h).tsum_pow_mul_one_sub /-- Formula for geometric series. -/ theorem one_sub_mul_tsum_pow_of_constantCoeff_eq_zero (h : f.constantCoeff = 0) : (1 - f) * ∑' (i : ℕ), f ^ i = 1 := (summable_pow_of_constantCoeff_eq_zero h).one_sub_mul_tsum_pow end GeomSeries end Sum section Prod variable [CommSemiring R] {ι : Type*} [LinearOrder ι] [LocallyFiniteOrderBot ι] {f : ι → R⟦X⟧} /-- If the order of a family of `PowerSeries` tends to infinity, the collection of all possible products over `Finset` is summable. -/ theorem summable_prod_of_tendsto_order_atTop_nhds_top (h : Tendsto (fun i ↦ (f i).order) atTop (𝓝 ⊤)) : Summable (∏ i ∈ ·, f i) := by rcases isEmpty_or_nonempty ι with hempty | hempty · apply Summable.of_finite refine (summable_iff_summable_coeff _).mpr fun n ↦ summable_of_finite_support ?_ simp_rw [ENat.tendsto_nhds_top_iff_natCast_lt, eventually_atTop] at h obtain ⟨i, hi⟩ := h n apply (Finset.Iio i).powerset.finite_toSet.subset suffices ∀ s : Finset ι, coeff n (∏ i ∈ s, f i) ≠ 0 → ↑s ⊆ Set.Iio i by simpa intro s hs contrapose! hs obtain ⟨x, hxs, hxi⟩ := Set.not_subset.mp hs rw [Set.mem_Iio, not_lt] at hxi refine coeff_of_lt_order _ <| (hi x hxi).trans_le <| le_trans ?_ (le_order_prod _ _) apply Finset.single_le_sum (by simp) hxs /-- A family of `PowerSeries` in the form `1 + f i` is multipliable if the order of `f i` tends to infinity. -/ theorem multipliable_one_add_of_tendsto_order_atTop_nhds_top (h : Tendsto (fun i ↦ (f i).order) atTop (nhds ⊤)) : Multipliable (1 + f ·) := multipliable_one_add_of_summable_prod <| summable_prod_of_tendsto_order_atTop_nhds_top _ h end Prod end WithPiTopology end Topological section Uniform namespace WithPiTopology variable [UniformSpace R] /-- The product uniformity on `PowerSeries` -/ scoped instance : UniformSpace (PowerSeries R) := MvPowerSeries.WithPiTopology.instUniformSpace /-- Coefficients are uniformly continuous -/ theorem uniformContinuous_coeff [Semiring R] (d : ℕ) : UniformContinuous fun f : PowerSeries R ↦ coeff d f := uniformContinuous_pi.mp uniformContinuous_id (Finsupp.single () d) /-- Completeness of the uniform structure on `PowerSeries` -/ @[scoped instance] theorem instCompleteSpace [CompleteSpace R] : CompleteSpace (PowerSeries R) := MvPowerSeries.WithPiTopology.instCompleteSpace /-- The `IsUniformAddGroup` structure on `PowerSeries` of a `IsUniformAddGroup` -/ @[scoped instance] theorem instIsUniformAddGroup [AddGroup R] [IsUniformAddGroup R] : IsUniformAddGroup (PowerSeries R) := MvPowerSeries.WithPiTopology.instIsUniformAddGroup end WithPiTopology end Uniform section variable {R} variable [TopologicalSpace R] namespace WithPiTopology open MvPowerSeries.WithPiTopology theorem continuous_C [Semiring R] : Continuous (C (R := R)) := MvPowerSeries.WithPiTopology.continuous_C theorem isTopologicallyNilpotent_of_constantCoeff_isNilpotent [CommSemiring R] {f : PowerSeries R} (hf : IsNilpotent (constantCoeff (R := R) f)) : Tendsto (fun n : ℕ => f ^ n) atTop (nhds 0) := MvPowerSeries.WithPiTopology.isTopologicallyNilpotent_of_constantCoeff_isNilpotent hf theorem isTopologicallyNilpotent_of_constantCoeff_zero [CommSemiring R] {f : PowerSeries R} (hf : constantCoeff (R := R) f = 0) : Tendsto (fun n : ℕ => f ^ n) atTop (nhds 0) := MvPowerSeries.WithPiTopology.isTopologicallyNilpotent_of_constantCoeff_zero hf /-- Assuming the base ring has a discrete topology, the powers of a `PowerSeries` converge to 0 iff its constant coefficient is nilpotent. [N. Bourbaki, *Algebra {II}*, Chapter 4, §4, n°2, corollary of prop. 3][bourbaki1981] -/ theorem isTopologicallyNilpotent_iff_constantCoeff_isNilpotent [CommRing R] [DiscreteTopology R] (f : PowerSeries R) : Tendsto (fun n : ℕ => f ^ n) atTop (nhds 0) ↔ IsNilpotent (constantCoeff f) := MvPowerSeries.WithPiTopology.isTopologicallyNilpotent_iff_constantCoeff_isNilpotent f end WithPiTopology end section Summable variable [Semiring R] [TopologicalSpace R] open WithPiTopology MvPowerSeries.WithPiTopology variable {R} -- NOTE : one needs an API to apply `Finsupp.LinearEquiv.finsuppUnique` /-- A power series is the sum (in the sense of summable families) of its monomials -/ theorem hasSum_of_monomials_self (f : PowerSeries R) : HasSum (fun d : ℕ => monomial d (coeff d f)) f := by rw [← (Finsupp.LinearEquiv.finsuppUnique ℕ ℕ Unit).toEquiv.hasSum_iff] convert MvPowerSeries.WithPiTopology.hasSum_of_monomials_self f simp only [LinearEquiv.coe_toEquiv, comp_apply, monomial, coeff, Finsupp.LinearEquiv.finsuppUnique_apply, PUnit.default_eq_unit] congr all_goals { ext; simp } /-- If the coefficient space is T2, then the power series is `tsum` of its monomials -/ theorem as_tsum [T2Space R] (f : PowerSeries R) : f = tsum fun d : ℕ => monomial d (coeff d f) := (HasSum.tsum_eq (hasSum_of_monomials_self f)).symm end Summable end PowerSeries
.lake/packages/mathlib/Mathlib/RingTheory/PowerSeries/WellKnown.lean
import Mathlib.Algebra.Algebra.Rat import Mathlib.Data.Nat.Cast.Field import Mathlib.RingTheory.PowerSeries.Basic /-! # Definition of well-known power series In this file we define the following power series: * `PowerSeries.invUnitsSub`: given `u : Rˣ`, this is the series for `1 / (u - x)`. It is given by `∑ n, x ^ n /ₚ u ^ (n + 1)`. * `PowerSeries.invOneSubPow`: given a commutative ring `S` and a number `d : ℕ`, `PowerSeries.invOneSubPow S d` is the multiplicative inverse of `(1 - X) ^ d` in `S⟦X⟧ˣ`. When `d` is `0`, `PowerSeries.invOneSubPow S d` will just be `1`. When `d` is positive, `PowerSeries.invOneSubPow S d` will be `∑ n, Nat.choose (d - 1 + n) (d - 1)`. * `PowerSeries.sin`, `PowerSeries.cos`, `PowerSeries.exp` : power series for sin, cosine, and exponential functions. -/ namespace PowerSeries section Ring variable {R S : Type*} [Ring R] [Ring S] /-- The power series for `1 / (u - x)`. -/ def invUnitsSub (u : Rˣ) : PowerSeries R := mk fun n => 1 /ₚ u ^ (n + 1) @[simp] theorem coeff_invUnitsSub (u : Rˣ) (n : ℕ) : coeff n (invUnitsSub u) = 1 /ₚ u ^ (n + 1) := coeff_mk _ _ @[simp] theorem constantCoeff_invUnitsSub (u : Rˣ) : constantCoeff (invUnitsSub u) = 1 /ₚ u := by rw [← coeff_zero_eq_constantCoeff_apply, coeff_invUnitsSub, zero_add, pow_one] @[simp] theorem invUnitsSub_mul_X (u : Rˣ) : invUnitsSub u * X = invUnitsSub u * C (u : R) - 1 := by ext (_ | n) · simp · simp [pow_succ'] @[simp] theorem invUnitsSub_mul_sub (u : Rˣ) : invUnitsSub u * (C (u : R) - X) = 1 := by simp [mul_sub, sub_sub_cancel] theorem map_invUnitsSub (f : R →+* S) (u : Rˣ) : map f (invUnitsSub u) = invUnitsSub (Units.map (f : R →* S) u) := by ext simp only [← map_pow, coeff_map, coeff_invUnitsSub, one_divp] rfl end Ring section invOneSubPow variable (S : Type*) [CommRing S] (d : ℕ) /-- (1 + X + X^2 + ...) * (1 - X) = 1. Note that the power series `1 + X + X^2 + ...` is written as `mk 1` where `1` is the constant function so that `mk 1` is the power series with all coefficients equal to one. -/ theorem mk_one_mul_one_sub_eq_one : (mk 1 : S⟦X⟧) * (1 - X) = 1 := by rw [mul_comm, PowerSeries.ext_iff] intro n cases n with | zero => simp | succ n => simp [sub_mul] /-- Note that `mk 1` is the constant function `1` so the power series `1 + X + X^2 + ...`. This theorem states that for any `d : ℕ`, `(1 + X + X^2 + ... : S⟦X⟧) ^ (d + 1)` is equal to the power series `mk fun n => Nat.choose (d + n) d : S⟦X⟧`. -/ theorem mk_one_pow_eq_mk_choose_add : (mk 1 : S⟦X⟧) ^ (d + 1) = (mk fun n => Nat.choose (d + n) d : S⟦X⟧) := by induction d with | zero => ext; simp | succ d hd => ext n rw [pow_add, hd, pow_one, mul_comm, coeff_mul] simp_rw [coeff_mk, Pi.one_apply, one_mul] norm_cast rw [Finset.sum_antidiagonal_choose_add, add_right_comm] /-- Given a natural number `d : ℕ` and a commutative ring `S`, `PowerSeries.invOneSubPow S d` is the multiplicative inverse of `(1 - X) ^ d` in `S⟦X⟧ˣ`. When `d` is `0`, `PowerSeries.invOneSubPow S d` will just be `1`. When `d` is positive, `PowerSeries.invOneSubPow S d` will be the power series `mk fun n => Nat.choose (d - 1 + n) (d - 1)`. -/ noncomputable def invOneSubPow : ℕ → S⟦X⟧ˣ | 0 => 1 | d + 1 => { val := mk fun n => Nat.choose (d + n) d inv := (1 - X) ^ (d + 1) val_inv := by rw [← mk_one_pow_eq_mk_choose_add, ← mul_pow, mk_one_mul_one_sub_eq_one, one_pow] inv_val := by rw [← mk_one_pow_eq_mk_choose_add, ← mul_pow, mul_comm, mk_one_mul_one_sub_eq_one, one_pow] } theorem invOneSubPow_zero : invOneSubPow S 0 = 1 := by delta invOneSubPow simp only theorem invOneSubPow_val_eq_mk_sub_one_add_choose_of_pos (h : 0 < d) : (invOneSubPow S d).val = (mk fun n => Nat.choose (d - 1 + n) (d - 1) : S⟦X⟧) := by rw [← Nat.sub_one_add_one_eq_of_pos h, invOneSubPow, add_tsub_cancel_right] theorem invOneSubPow_val_succ_eq_mk_add_choose : (invOneSubPow S (d + 1)).val = (mk fun n => Nat.choose (d + n) d : S⟦X⟧) := rfl theorem invOneSubPow_val_one_eq_invUnitSub_one : (invOneSubPow S 1).val = invUnitsSub (1 : Sˣ) := by simp [invOneSubPow, invUnitsSub] /-- The theorem `PowerSeries.mk_one_mul_one_sub_eq_one` implies that `1 - X` is a unit in `S⟦X⟧` whose inverse is the power series `1 + X + X^2 + ...`. This theorem states that for any `d : ℕ`, `PowerSeries.invOneSubPow S d` is equal to `(1 - X)⁻¹ ^ d`. -/ theorem invOneSubPow_eq_inv_one_sub_pow : invOneSubPow S d = (Units.mkOfMulEqOne (1 - X) (mk 1 : S⟦X⟧) <| Eq.trans (mul_comm _ _) (mk_one_mul_one_sub_eq_one S))⁻¹ ^ d := by induction d with | zero => exact Eq.symm <| pow_zero _ | succ d _ => rw [inv_pow] exact (DivisionMonoid.inv_eq_of_mul _ (invOneSubPow S (d + 1)) <| by rw [← Units.val_eq_one, Units.val_mul, Units.val_pow_eq_pow_val] exact (invOneSubPow S (d + 1)).inv_val).symm theorem invOneSubPow_inv_eq_one_sub_pow : (invOneSubPow S d).inv = (1 - X : S⟦X⟧) ^ d := by induction d with | zero => exact Eq.symm <| pow_zero _ | succ d => rfl theorem invOneSubPow_inv_zero_eq_one : (invOneSubPow S 0).inv = 1 := by delta invOneSubPow simp only [Units.inv_eq_val_inv, inv_one, Units.val_one] theorem mk_add_choose_mul_one_sub_pow_eq_one : (mk fun n ↦ Nat.choose (d + n) d : S⟦X⟧) * ((1 - X) ^ (d + 1)) = 1 := (invOneSubPow S (d + 1)).val_inv theorem invOneSubPow_add (e : ℕ) : invOneSubPow S (d + e) = invOneSubPow S d * invOneSubPow S e := by simp_rw [invOneSubPow_eq_inv_one_sub_pow, pow_add] theorem one_sub_pow_mul_invOneSubPow_val_add_eq_invOneSubPow_val (e : ℕ) : (1 - X) ^ e * (invOneSubPow S (d + e)).val = (invOneSubPow S d).val := by simp [invOneSubPow_add, Units.val_mul, mul_comm, mul_assoc, ← invOneSubPow_inv_eq_one_sub_pow] theorem one_sub_pow_add_mul_invOneSubPow_val_eq_one_sub_pow (e : ℕ) : (1 - X) ^ (d + e) * (invOneSubPow S e).val = (1 - X) ^ d := by simp [pow_add, mul_assoc, ← invOneSubPow_inv_eq_one_sub_pow S e] end invOneSubPow section Field variable (A A' : Type*) [Ring A] [Ring A'] [Algebra ℚ A] [Algebra ℚ A'] open Nat /-- Power series for the exponential function at zero. -/ def exp : PowerSeries A := mk fun n => algebraMap ℚ A (1 / n !) /-- Power series for the sine function at zero. -/ def sin : PowerSeries A := mk fun n => if Even n then 0 else algebraMap ℚ A ((-1) ^ (n / 2) / n !) /-- Power series for the cosine function at zero. -/ def cos : PowerSeries A := mk fun n => if Even n then algebraMap ℚ A ((-1) ^ (n / 2) / n !) else 0 variable {A A'} (n : ℕ) @[simp] theorem coeff_exp : coeff n (exp A) = algebraMap ℚ A (1 / n !) := coeff_mk _ _ @[simp] theorem constantCoeff_exp : constantCoeff (exp A) = 1 := by rw [← coeff_zero_eq_constantCoeff_apply, coeff_exp] simp variable (f : A →+* A') @[simp] theorem map_exp : map (f : A →+* A') (exp A) = exp A' := by ext simp @[simp] theorem map_sin : map f (sin A) = sin A' := by ext simp [sin, apply_ite f] @[simp] theorem map_cos : map f (cos A) = cos A' := by ext simp [cos, apply_ite f] end Field open RingHom open Finset Nat variable {A : Type*} [CommRing A] /-- Shows that $e^{aX} * e^{bX} = e^{(a + b)X}$ -/ theorem exp_mul_exp_eq_exp_add [Algebra ℚ A] (a b : A) : rescale a (exp A) * rescale b (exp A) = rescale (a + b) (exp A) := by ext n simp only [coeff_mul, exp, rescale, coeff_mk, MonoidHom.coe_mk, OneHom.coe_mk, coe_mk, Nat.sum_antidiagonal_eq_sum_range_succ_mk, add_pow, sum_mul] apply sum_congr rfl rintro x hx suffices a ^ x * b ^ (n - x) * (algebraMap ℚ A (1 / ↑x.factorial) * algebraMap ℚ A (1 / ↑(n - x).factorial)) = a ^ x * b ^ (n - x) * (↑(n.choose x) * (algebraMap ℚ A) (1 / ↑n.factorial)) by convert this using 1 <;> ring congr 1 rw [← map_natCast (algebraMap ℚ A) (n.choose x), ← map_mul, ← map_mul] refine RingHom.congr_arg _ ?_ rw [mul_one_div (↑(n.choose x) : ℚ), one_div_mul_one_div] symm rw [div_eq_iff, div_mul_eq_mul_div, one_mul, choose_eq_factorial_div_factorial] · norm_cast rw [cast_div_charZero] apply factorial_mul_factorial_dvd_factorial (mem_range_succ_iff.1 hx) · apply mem_range_succ_iff.1 hx · rintro h apply factorial_ne_zero n rw [cast_eq_zero.1 h] /-- Shows that $e^{x} * e^{-x} = 1$ -/ theorem exp_mul_exp_neg_eq_one [Algebra ℚ A] : exp A * evalNegHom (exp A) = 1 := by convert exp_mul_exp_eq_exp_add (1 : A) (-1) <;> simp /-- Shows that $(e^{X})^k = e^{kX}$. -/ theorem exp_pow_eq_rescale_exp [Algebra ℚ A] (k : ℕ) : exp A ^ k = rescale (k : A) (exp A) := by induction k with | zero => simp only [rescale_zero, constantCoeff_exp, Function.comp_apply, map_one, cast_zero, pow_zero (exp A), coe_comp] | succ k h => simpa only [succ_eq_add_one, cast_add, ← exp_mul_exp_eq_exp_add (k : A), ← h, cast_one, id_apply, rescale_one] using pow_succ (exp A) k /-- Shows that $\sum_{k = 0}^{n - 1} (e^{X})^k = \sum_{p = 0}^{\infty} \sum_{k = 0}^{n - 1} \frac{k^p}{p!}X^p$. -/ theorem exp_pow_sum [Algebra ℚ A] (n : ℕ) : ((Finset.range n).sum fun k => exp A ^ k) = PowerSeries.mk fun p => (Finset.range n).sum fun k => (k ^ p : A) * algebraMap ℚ A p.factorial⁻¹ := by simp only [exp_pow_eq_rescale_exp, rescale] ext simp only [one_div, coeff_mk, coe_mk, MonoidHom.coe_mk, OneHom.coe_mk, coeff_exp, map_sum] end PowerSeries
.lake/packages/mathlib/Mathlib/RingTheory/PowerSeries/Order.lean
import Mathlib.Algebra.CharP.Defs import Mathlib.RingTheory.Multiplicity import Mathlib.RingTheory.PowerSeries.Basic /-! # Formal power series (in one variable) - Order The `PowerSeries.order` of a formal power series `φ` is the multiplicity of the variable `X` in `φ`. If the coefficients form an integral domain, then `PowerSeries.order` is an additive valuation (`PowerSeries.order_mul`, `PowerSeries.min_order_le_order_add`). We prove that if the commutative ring `R` of coefficients is an integral domain, then the ring `R⟦X⟧` of formal power series in one variable over `R` is an integral domain. Given a non-zero power series `f`, `divided_by_X_pow_order f` is the power series obtained by dividing out the largest power of X that divides `f`, that is its order. This is useful when proving that `R⟦X⟧` is a normalization monoid, which is done in `PowerSeries.Inverse`. -/ noncomputable section open Polynomial open Finset (antidiagonal mem_antidiagonal) namespace PowerSeries open Finsupp (single) variable {R : Type*} section OrderBasic variable [Semiring R] {φ : R⟦X⟧} theorem exists_coeff_ne_zero_iff_ne_zero : (∃ n : ℕ, coeff n φ ≠ 0) ↔ φ ≠ 0 := by refine not_iff_not.mp ?_ push_neg simp /-- The order of a formal power series `φ` is the greatest `n : ℕ∞` such that `X^n` divides `φ`. The order is `⊤` if and only if `φ = 0`. -/ def order (φ : R⟦X⟧) : ℕ∞ := letI := Classical.decEq R letI := Classical.decEq R⟦X⟧ if h : φ = 0 then ⊤ else Nat.find (exists_coeff_ne_zero_iff_ne_zero.mpr h) /-- The order of the `0` power series is infinite. -/ @[simp] theorem order_zero : order (0 : R⟦X⟧) = ⊤ := dif_pos rfl theorem order_finite_iff_ne_zero : (order φ < ⊤) ↔ φ ≠ 0 := by simp only [order] split_ifs with h <;> simpa /-- The `0` power series is the unique power series with infinite order. -/ @[simp] theorem order_eq_top {φ : R⟦X⟧} : φ.order = ⊤ ↔ φ = 0 := by simpa using order_finite_iff_ne_zero.not_left theorem coe_toNat_order {φ : R⟦X⟧} (hf : φ ≠ 0) : φ.order.toNat = φ.order := by rw [ENat.coe_toNat_eq_self.mpr (order_eq_top.not.mpr hf)] /-- If the order of a formal power series is finite, then the coefficient indexed by the order is nonzero. -/ theorem coeff_order (h : φ ≠ 0) : coeff φ.order.toNat φ ≠ 0 := by classical simp only [order, h, not_false_iff, dif_neg] generalize_proofs h exact Nat.find_spec h /-- If the `n`th coefficient of a formal power series is nonzero, then the order of the power series is less than or equal to `n`. -/ theorem order_le (n : ℕ) (h : coeff n φ ≠ 0) : order φ ≤ n := by classical rw [order, dif_neg] · simpa using ⟨n, le_rfl, h⟩ · exact exists_coeff_ne_zero_iff_ne_zero.mp ⟨n, h⟩ /-- The `n`th coefficient of a formal power series is `0` if `n` is strictly smaller than the order of the power series. -/ theorem coeff_of_lt_order (n : ℕ) (h : ↑n < order φ) : coeff n φ = 0 := by contrapose! h exact order_le _ h theorem coeff_of_lt_order_toNat (n : ℕ) (h : n < φ.order.toNat) : coeff n φ = 0 := by by_cases h' : φ = 0 · simp [h'] · refine coeff_of_lt_order _ ?_ rwa [← coe_toNat_order h', ENat.coe_lt_coe] /-- The order of a formal power series is at least `n` if the `i`th coefficient is `0` for all `i < n`. -/ theorem nat_le_order (φ : R⟦X⟧) (n : ℕ) (h : ∀ i < n, coeff i φ = 0) : ↑n ≤ order φ := by classical simp only [order] split_ifs · simp · simpa [Nat.le_find_iff] /-- The order of a formal power series is at least `n` if the `i`th coefficient is `0` for all `i < n`. -/ theorem le_order (φ : R⟦X⟧) (n : ℕ∞) (h : ∀ i : ℕ, ↑i < n → coeff i φ = 0) : n ≤ order φ := by cases n with | top => simpa using ext (by simpa using h) | coe n => convert nat_le_order φ n _ simpa using h /-- The order of a formal power series is exactly `n` if the `n`th coefficient is nonzero, and the `i`th coefficient is `0` for all `i < n`. -/ theorem order_eq_nat {φ : R⟦X⟧} {n : ℕ} : order φ = n ↔ coeff n φ ≠ 0 ∧ ∀ i, i < n → coeff i φ = 0 := by classical rcases eq_or_ne φ 0 with (rfl | hφ) · simp simp [order, dif_neg hφ, Nat.find_eq_iff] /-- The order of a formal power series is exactly `n` if the `n`th coefficient is nonzero, and the `i`th coefficient is `0` for all `i < n`. -/ theorem order_eq {φ : R⟦X⟧} {n : ℕ∞} : order φ = n ↔ (∀ i : ℕ, ↑i = n → coeff i φ ≠ 0) ∧ ∀ i : ℕ, ↑i < n → coeff i φ = 0 := by cases n with | top => simp | coe n => simp [order_eq_nat] /-- The order of the sum of two formal power series is at least the minimum of their orders. -/ theorem min_order_le_order_add (φ ψ : R⟦X⟧) : min (order φ) (order ψ) ≤ order (φ + ψ) := by refine le_order _ _ ?_ simp +contextual [coeff_of_lt_order] private theorem order_add_of_order_ne.aux (φ ψ : R⟦X⟧) (H : order φ < order ψ) : order (φ + ψ) ≤ order φ ⊓ order ψ := by suffices order (φ + ψ) = order φ by rw [le_inf_iff, this] exact ⟨le_rfl, le_of_lt H⟩ rw [order_eq] constructor · intro i hi rw [← hi] at H rw [(coeff _).map_add, coeff_of_lt_order i H, add_zero] exact (order_eq_nat.1 hi.symm).1 · intro i hi rw [(coeff _).map_add, coeff_of_lt_order i hi, coeff_of_lt_order i (lt_trans hi H), zero_add] /-- The order of the sum of two formal power series is the minimum of their orders if their orders differ. -/ theorem order_add_of_order_ne (φ ψ : R⟦X⟧) (h : order φ ≠ order ψ) : order (φ + ψ) = order φ ⊓ order ψ := by refine le_antisymm ?_ (min_order_le_order_add _ _) rcases h.lt_or_gt with (φ_lt_ψ | ψ_lt_φ) · apply order_add_of_order_ne.aux _ _ φ_lt_ψ · simpa only [add_comm, inf_comm] using order_add_of_order_ne.aux _ _ ψ_lt_φ @[deprecated (since := "2025-09-17")] alias order_add_of_order_eq := order_add_of_order_ne /-- The order of the product of two formal power series is at least the sum of their orders. -/ theorem le_order_mul (φ ψ : R⟦X⟧) : order φ + order ψ ≤ order (φ * ψ) := by apply le_order intro n hn; rw [coeff_mul, Finset.sum_eq_zero] rintro ⟨i, j⟩ hij by_cases! hi : ↑i < order φ · rw [coeff_of_lt_order i hi, zero_mul] by_cases! hj : ↑j < order ψ · rw [coeff_of_lt_order j hj, mul_zero] rw [mem_antidiagonal] at hij exfalso apply ne_of_lt (lt_of_lt_of_le hn <| add_le_add hi hj) rw [← Nat.cast_add, hij] theorem le_order_pow (φ : R⟦X⟧) (n : ℕ) : n • order φ ≤ order (φ ^ n) := by induction n with | zero => simp | succ n ih => grw [add_smul, one_smul, pow_succ, ih, le_order_mul] theorem le_order_prod {R : Type*} [CommSemiring R] {ι : Type*} (φ : ι → R⟦X⟧) (s : Finset ι) : ∑ i ∈ s, (φ i).order ≤ (∏ i ∈ s, φ i).order := by induction s using Finset.cons_induction with | empty => simp | cons a s ha ih => grw [Finset.sum_cons ha, Finset.prod_cons ha, ih, le_order_mul] alias order_mul_ge := le_order_mul theorem order_ne_zero_iff_constCoeff_eq_zero {φ : R⟦X⟧} : φ.order ≠ 0 ↔ φ.constantCoeff = 0 := by constructor · intro h rw [← PowerSeries.coeff_zero_eq_constantCoeff] apply coeff_of_lt_order simpa using pos_of_ne_zero h · intro h refine ENat.one_le_iff_ne_zero.mp <| PowerSeries.le_order _ _ fun d hd ↦ ?_ rw [Nat.cast_lt_one] at hd simp [hd, h] /-- The order of the monomial `a*X^n` is infinite if `a = 0` and `n` otherwise. -/ theorem order_monomial (n : ℕ) (a : R) [Decidable (a = 0)] : order (monomial n a) = if a = 0 then (⊤ : ℕ∞) else n := by split_ifs with h · rw [h, order_eq_top, LinearMap.map_zero] · rw [order_eq] constructor <;> intro i hi · simp only [Nat.cast_inj] at hi rwa [hi, coeff_monomial_same] · simp only [Nat.cast_lt] at hi rw [coeff_monomial, if_neg] exact ne_of_lt hi /-- The order of the monomial `a*X^n` is `n` if `a ≠ 0`. -/ theorem order_monomial_of_ne_zero (n : ℕ) (a : R) (h : a ≠ 0) : order (monomial n a) = n := by classical rw [order_monomial, if_neg h] /-- If `n` is strictly smaller than the order of `ψ`, then the `n`th coefficient of its product with any other power series is `0`. -/ theorem coeff_mul_of_lt_order {φ ψ : R⟦X⟧} {n : ℕ} (h : ↑n < ψ.order) : coeff n (φ * ψ) = 0 := by suffices coeff n (φ * ψ) = ∑ p ∈ antidiagonal n, 0 by rw [this, Finset.sum_const_zero] rw [coeff_mul] apply Finset.sum_congr rfl intro x hx refine mul_eq_zero_of_right (coeff x.fst φ) (coeff_of_lt_order x.snd (lt_of_le_of_lt ?_ h)) rw [mem_antidiagonal] at hx norm_cast cutsat theorem coeff_mul_one_sub_of_lt_order {R : Type*} [Ring R] {φ ψ : R⟦X⟧} (n : ℕ) (h : ↑n < ψ.order) : coeff n (φ * (1 - ψ)) = coeff n φ := by simp [coeff_mul_of_lt_order h, mul_sub] theorem coeff_mul_prod_one_sub_of_lt_order {R ι : Type*} [CommRing R] (k : ℕ) (s : Finset ι) (φ : R⟦X⟧) (f : ι → R⟦X⟧) : (∀ i ∈ s, ↑k < (f i).order) → coeff k (φ * ∏ i ∈ s, (1 - f i)) = coeff k φ := by classical induction s using Finset.induction_on with | empty => simp | insert a s ha ih => intro t simp only [Finset.mem_insert, forall_eq_or_imp] at t rw [Finset.prod_insert ha, ← mul_assoc, mul_right_comm, coeff_mul_one_sub_of_lt_order _ t.1] exact ih t.2 @[simp] theorem order_neg {R : Type*} [Ring R] (φ : PowerSeries R) : (-φ).order = φ.order := by by_contra! h have : φ = 0 := by simpa using (order_add_of_order_ne _ _ h).symm simp [this] at h /-- Given a non-zero power series `f`, `divXPowOrder f` is the power series obtained by dividing out the largest power of X that divides `f`, that is its order -/ def divXPowOrder (f : R⟦X⟧) : R⟦X⟧ := .mk fun n ↦ coeff (n + f.order.toNat) f @[simp] lemma coeff_divXPowOrder {f : R⟦X⟧} {n : ℕ} : coeff n (divXPowOrder f) = coeff (n + f.order.toNat) f := coeff_mk _ _ @[simp] lemma divXPowOrder_zero : divXPowOrder (0 : R⟦X⟧) = 0 := by ext simp lemma constantCoeff_divXPowOrder {f : R⟦X⟧} : constantCoeff (divXPowOrder f) = coeff f.order.toNat f := by simp [← coeff_zero_eq_constantCoeff] lemma constantCoeff_divXPowOrder_eq_zero_iff {f : R⟦X⟧} : constantCoeff (divXPowOrder f) = 0 ↔ f = 0 := by by_cases h : f = 0 · simp [h] · simp [constantCoeff_divXPowOrder, coeff_order h, h] theorem X_pow_order_mul_divXPowOrder {f : R⟦X⟧} : X ^ f.order.toNat * divXPowOrder f = f := by ext n rw [coeff_X_pow_mul'] split_ifs with h · simp [h] · push_neg at h rw [coeff_of_lt_order_toNat _ h] theorem X_pow_order_dvd : X ^ φ.order.toNat ∣ φ := by simpa only [X_pow_dvd_iff] using coeff_of_lt_order_toNat theorem order_eq_emultiplicity_X {R : Type*} [Semiring R] (φ : R⟦X⟧) : order φ = emultiplicity X φ := by classical rcases eq_or_ne φ 0 with (rfl | hφ) · simp cases ho : order φ with | top => simp [hφ] at ho | coe n => have hn : φ.order.toNat = n := by simp [ho] rw [← hn, eq_comm] apply le_antisymm _ · apply le_emultiplicity_of_pow_dvd apply X_pow_order_dvd · apply Order.le_of_lt_add_one rw [← not_le, ← Nat.cast_one, ← Nat.cast_add, ← pow_dvd_iff_le_emultiplicity] rintro ⟨ψ, H⟩ have := congr_arg (coeff n) H rw [X_pow_mul, coeff_mul_of_lt_order, ← hn] at this · exact coeff_order hφ this · rw [X_pow_eq, order_monomial] split_ifs · simp · rw [← hn, ENat.coe_lt_coe] simp end OrderBasic section OrderZeroNeOne variable [Semiring R] [Nontrivial R] /-- The order of the formal power series `1` is `0`. -/ @[simp] theorem order_one : order (1 : R⟦X⟧) = 0 := by simpa using order_monomial_of_ne_zero 0 (1 : R) one_ne_zero /-- The order of an invertible power series is `0`. -/ theorem order_zero_of_unit {f : R⟦X⟧} : IsUnit f → f.order = 0 := by rintro ⟨⟨u, v, hu, hv⟩, hf⟩ apply And.left rw [← add_eq_zero, ← hf, ← nonpos_iff_eq_zero, ← @order_one R _ _, ← hu] exact order_mul_ge _ _ /-- The order of the formal power series `X` is `1`. -/ @[simp] theorem order_X : order (X : R⟦X⟧) = 1 := by simpa only [Nat.cast_one] using order_monomial_of_ne_zero 1 (1 : R) one_ne_zero /-- The order of the formal power series `X^n` is `n`. -/ @[simp] theorem order_X_pow (n : ℕ) : order ((X : R⟦X⟧) ^ n) = n := by rw [X_pow_eq, order_monomial_of_ne_zero] exact one_ne_zero /-- Dividing `X` by the maximal power of `X` dividing it leaves `1`. -/ @[simp] theorem divXPowOrder_X : divXPowOrder X = (1 : R⟦X⟧) := by ext n simp [coeff_X] theorem divXPowOrder_one : divXPowOrder 1 = (1 : R⟦X⟧) := by ext k simp end OrderZeroNeOne section NoZeroDivisors variable [Semiring R] [NoZeroDivisors R] /-- The order of the product of two formal power series over an integral domain is the sum of their orders. -/ theorem order_mul (φ ψ : R⟦X⟧) : order (φ * ψ) = order φ + order ψ := by apply le_antisymm _ (le_order_mul _ _) by_cases! h : φ = 0 ∨ ψ = 0 · rcases h with h | h <;> simp [h] · rw [← coe_toNat_order h.1, ← coe_toNat_order h.2, ← ENat.coe_add] apply order_le rw [coeff_mul, Finset.sum_eq_single_of_mem ⟨φ.order.toNat, ψ.order.toNat⟩ (by simp)] · exact mul_ne_zero (coeff_order h.1) (coeff_order h.2) · intro ij hij h rcases trichotomy_of_add_eq_add (mem_antidiagonal.mp hij) with h' | h' | h' · exact False.elim (h (by simp [Prod.ext_iff, h'.1, h'.2])) · rw [coeff_of_lt_order_toNat ij.1 h', zero_mul] · rw [coeff_of_lt_order_toNat ij.2 h', mul_zero] /-- The operation of dividing a power series by the largest possible power of `X` preserves multiplication. -/ theorem divXPowOrder_mul {f g : R⟦X⟧} : divXPowOrder (f * g) = divXPowOrder f * divXPowOrder g := by by_cases! h : f = 0 ∨ g = 0 · rcases h with (h | h) <;> simp [h] apply X_pow_mul_cancel (k := f.order.toNat + g.order.toNat) calc _ = X ^ ((f * g).order.toNat) * (f * g).divXPowOrder := by rw [order_mul, ENat.toNat_add (order_eq_top.not.mpr h.1) (order_eq_top.not.mpr h.2)] _ = f * g := by simp [X_pow_order_mul_divXPowOrder] _ = (X ^ f.order.toNat * f.divXPowOrder) * (X ^ g.order.toNat * g.divXPowOrder) := by simp [X_pow_order_mul_divXPowOrder] _ = f.divXPowOrder * g.divXPowOrder * X ^ (g.order.toNat + f.order.toNat) := by rw [mul_assoc, X_pow_mul, X_pow_mul, ← mul_assoc, mul_assoc, ← pow_add] _ = X ^ (f.order.toNat + g.order.toNat) * (f.divXPowOrder * g.divXPowOrder) := by rw [X_pow_mul, add_comm] @[deprecated divXPowOrder_mul "use `divXPowOrder_mul.symm` instead" (since := "2025-11-06")] theorem divXPowOrder_mul_divXPowOrder {f g : R⟦X⟧} : divXPowOrder f * divXPowOrder g = divXPowOrder (f * g) := divXPowOrder_mul.symm variable [Nontrivial R] /-- `PowerSeries.order` as a `MonoidHom`. -/ def orderHom : R⟦X⟧ →* Multiplicative ℕ∞ where toFun g := .ofAdd g.order map_one' := order_one map_mul' := order_mul @[simp, norm_cast] lemma coe_orderHom : (orderHom : R⟦X⟧ → ℕ∞) = order := rfl theorem order_pow (φ : R⟦X⟧) (n : ℕ) : order (φ ^ n) = n • order φ := map_pow orderHom φ n theorem order_prod {R : Type*} [CommSemiring R] [NoZeroDivisors R] [Nontrivial R] {ι : Type*} (φ : ι → R⟦X⟧) (s : Finset ι) : (∏ i ∈ s, φ i).order = ∑ i ∈ s, (φ i).order := map_prod orderHom φ s /-- `PowerSeries.divXPowOrder` as a `MonoidHom`. -/ def divXPowOrderHom : R⟦X⟧ →* R⟦X⟧ where toFun g := g.divXPowOrder map_one' := divXPowOrder_one map_mul' f g := divXPowOrder_mul (f := f) (g := g) @[simp, norm_cast] lemma coe_divXPowOrderHom : (divXPowOrderHom : R⟦X⟧ → R⟦X⟧) = divXPowOrder := rfl theorem divXPowOrder_pow (φ : R⟦X⟧) (n : ℕ) : divXPowOrder (φ ^ n) = (divXPowOrder φ) ^ n := map_pow divXPowOrderHom φ n theorem divXPowOrder_prod {R : Type*} [CommSemiring R] [NoZeroDivisors R] [Nontrivial R] {ι : Type*} (φ : ι → R⟦X⟧) (s : Finset ι) : (∏ i ∈ s, φ i).divXPowOrder = ∏ i ∈ s, (φ i).divXPowOrder := map_prod divXPowOrderHom φ s end NoZeroDivisors end PowerSeries end
.lake/packages/mathlib/Mathlib/RingTheory/PowerSeries/Evaluation.lean
import Mathlib.RingTheory.MvPowerSeries.Evaluation import Mathlib.RingTheory.PowerSeries.PiTopology import Mathlib.Algebra.MvPolynomial.Equiv /-! # Evaluation of power series Power series in one indeterminate are the particular case of multivariate power series, for the `Unit` type of indeterminates. This file provides a simpler syntax. Let `R`, `S` be types, with `CommRing R`, `CommRing S`. One assumes that `IsTopologicalRing R` and `IsUniformAddGroup R`, and that `S` is a complete and separated topological `R`-algebra, with `IsLinearTopology S S`, which means there is a basis of neighborhoods of 0 consisting of ideals. Given `φ : R →+* S`, `a : S`, and `f : MvPowerSeries σ R`, `PowerSeries.eval₂ f φ a` is the evaluation of the power series `f` at `a`. It `f` is (the coercion of) a polynomial, it coincides with the evaluation of that polynomial. Otherwise, it is defined by density from polynomials; its values are irrelevant unless `φ` is continuous and `a` is topologically nilpotent (`a ^ n` tends to 0 when `n` tends to infinity). For consistency with the case of multivariate power series, we define `PowerSeries.HasEval` as an abbrev to `IsTopologicallyNilpotent`. Under `Continuous φ` and `HasEval a`, the following lemmas furnish the properties of evaluation: * `PowerSeries.eval₂Hom`: the evaluation of multivariate power series, as a ring morphism, * `PowerSeries.aeval`: the evaluation map as an algebra morphism * `PowerSeries.uniformContinuous_eval₂`: uniform continuity of the evaluation * `PowerSeries.continuous_eval₂`: continuity of the evaluation * `PowerSeries.eval₂_eq_tsum`: the evaluation is given by the sum of its monomials, evaluated. We refer to the documentation of `MvPowerSeries.eval₂` for more details. -/ namespace PowerSeries open WithPiTopology variable {R : Type*} [CommRing R] variable {S : Type*} [CommRing S] variable {φ : R →+* S} section variable [TopologicalSpace R] [TopologicalSpace S] /-- Points at which evaluation of power series is well behaved -/ abbrev HasEval (a : S) := IsTopologicallyNilpotent a theorem hasEval_def (a : S) : HasEval a ↔ IsTopologicallyNilpotent a := .rfl theorem hasEval_iff {a : S} : HasEval a ↔ MvPowerSeries.HasEval (fun (_ : Unit) ↦ a) := ⟨fun ha ↦ ⟨fun _ ↦ ha, by simp⟩, fun ha ↦ ha.hpow default⟩ theorem hasEval {a : S} (ha : HasEval a) : MvPowerSeries.HasEval (fun (_ : Unit) ↦ a) := hasEval_iff.mp ha theorem HasEval.mono {S : Type*} [CommRing S] {a : S} {t u : TopologicalSpace S} (h : t ≤ u) (ha : @HasEval _ _ t a) : @HasEval _ _ u a := by simp only [hasEval_iff] at ha ⊢ exact ha.mono h theorem HasEval.zero : HasEval (0 : S) := by rw [hasEval_iff]; exact MvPowerSeries.HasEval.zero theorem HasEval.add [ContinuousAdd S] [IsLinearTopology S S] {a b : S} (ha : HasEval a) (hb : HasEval b) : HasEval (a + b) := by simp only [hasEval_iff] at ha hb ⊢ exact ha.add hb theorem HasEval.mul_left [IsLinearTopology S S] (c : S) {x : S} (hx : HasEval x) : HasEval (c * x) := by simp only [hasEval_iff] at hx ⊢ exact hx.mul_left _ theorem HasEval.mul_right [IsLinearTopology S S] (c : S) {x : S} (hx : HasEval x) : HasEval (x * c) := by simp only [hasEval_iff] at hx ⊢ exact hx.mul_right _ /-- [Bourbaki, *Algebra*, chap. 4, §4, n°3, Prop. 4 (i) (a & b)][bourbaki1981]. -/ theorem HasEval.map (hφ : Continuous φ) {a : R} (ha : HasEval a) : HasEval (φ a) := by simp only [hasEval_iff] at ha ⊢ exact ha.map hφ protected theorem HasEval.X : HasEval (X : R⟦X⟧) := by rw [hasEval_iff] exact MvPowerSeries.HasEval.X variable [IsTopologicalRing S] [IsLinearTopology S S] /-- The domain of evaluation of `MvPowerSeries`, as an ideal -/ @[simps] def hasEvalIdeal : Ideal S where carrier := {a | HasEval a} add_mem' := HasEval.add zero_mem' := HasEval.zero smul_mem' := HasEval.mul_left theorem mem_hasEvalIdeal_iff {a : S} : a ∈ hasEvalIdeal ↔ HasEval a := by simp [hasEvalIdeal] end variable (φ : R →+* S) (a : S) variable [UniformSpace R] [UniformSpace S] /-- Evaluation of a power series `f` at a point `a`. It coincides with the evaluation of `f` as a polynomial if `f` is the coercion of a polynomial. Otherwise, it is only relevant if `φ` is continuous and `a` is topologically nilpotent. -/ noncomputable def eval₂ : PowerSeries R → S := MvPowerSeries.eval₂ φ (fun _ ↦ a) @[simp] theorem eval₂_coe (f : Polynomial R) : eval₂ φ a f = f.eval₂ φ a := by let g : MvPolynomial Unit R := (MvPolynomial.pUnitAlgEquiv R).symm f have : f = MvPolynomial.pUnitAlgEquiv R g := by simp only [g, ← AlgEquiv.symm_apply_eq] simp only [this, PowerSeries.eval₂, MvPolynomial.eval₂_const_pUnitAlgEquiv] rw [← MvPolynomial.toMvPowerSeries_pUnitAlgEquiv, MvPowerSeries.eval₂_coe] @[simp] theorem eval₂_C (r : R) : eval₂ φ a (C r) = φ r := by rw [← Polynomial.coe_C, eval₂_coe, Polynomial.eval₂_C] @[simp] theorem eval₂_X : eval₂ φ a X = a := by rw [← Polynomial.coe_X, eval₂_coe, Polynomial.eval₂_X] variable {φ a} variable [IsUniformAddGroup R] [IsTopologicalSemiring R] [IsUniformAddGroup S] [T2Space S] [CompleteSpace S] [IsTopologicalRing S] [IsLinearTopology S S] /-- The evaluation homomorphism at `a` on `PowerSeries`, as a `RingHom`. -/ noncomputable def eval₂Hom (hφ : Continuous φ) (ha : HasEval a) : PowerSeries R →+* S := MvPowerSeries.eval₂Hom hφ (hasEval ha) theorem coe_eval₂Hom (hφ : Continuous φ) (ha : HasEval a) : ⇑(eval₂Hom hφ ha) = eval₂ φ a := MvPowerSeries.coe_eval₂Hom hφ (hasEval ha) -- Note: this is still true without the `T2Space` hypothesis, by arguing that the case -- disjunction in the definition of `eval₂` only replaces some values by topologically -- inseparable ones. theorem uniformContinuous_eval₂ (hφ : Continuous φ) (ha : HasEval a) : UniformContinuous (eval₂ φ a) := MvPowerSeries.uniformContinuous_eval₂ hφ (hasEval ha) theorem continuous_eval₂ (hφ : Continuous φ) (ha : HasEval a) : Continuous (eval₂ φ a : PowerSeries R → S) := (uniformContinuous_eval₂ hφ ha).continuous theorem hasSum_eval₂ (hφ : Continuous φ) (ha : HasEval a) (f : PowerSeries R) : HasSum (fun (d : ℕ) ↦ φ (coeff d f) * a ^ d) (f.eval₂ φ a) := by have := MvPowerSeries.hasSum_eval₂ hφ (hasEval ha) f simp only [PowerSeries.eval₂] rw [← (Finsupp.single_injective ()).hasSum_iff] at this · convert this; simp; congr · intro d hd exact False.elim (hd ⟨d (), by ext; simp⟩) theorem eval₂_eq_tsum (hφ : Continuous φ) (ha : HasEval a) (f : PowerSeries R) : PowerSeries.eval₂ φ a f = ∑' d : ℕ, φ (coeff d f) * a ^ d := (hasSum_eval₂ hφ ha f).tsum_eq.symm theorem eval₂_unique (hφ : Continuous φ) (ha : HasEval a) {ε : PowerSeries R → S} (hε : Continuous ε) (h : ∀ p : Polynomial R, ε p = Polynomial.eval₂ φ a p) : ε = eval₂ φ a := by apply MvPowerSeries.eval₂_unique hφ (hasEval ha) hε intro p rw [MvPolynomial.toMvPowerSeries_pUnitAlgEquiv, h, ← MvPolynomial.eval₂_pUnitAlgEquiv] theorem comp_eval₂ (hφ : Continuous φ) (ha : HasEval a) {T : Type*} [UniformSpace T] [CompleteSpace T] [T2Space T] [CommRing T] [IsTopologicalRing T] [IsLinearTopology T T] [IsUniformAddGroup T] {ε : S →+* T} (hε : Continuous ε) : ε ∘ eval₂ φ a = eval₂ (ε.comp φ) (ε a) := by apply eval₂_unique _ (ha.map hε) · exact Continuous.comp hε (continuous_eval₂ hφ ha) · intro p simp only [Function.comp_apply, eval₂_coe] exact Polynomial.hom_eval₂ p φ ε a · simp only [RingHom.coe_comp, Continuous.comp hε hφ] variable [Algebra R S] [ContinuousSMul R S] /-- For `HasEval a`, the evaluation homomorphism at `a` on `PowerSeries`, as an `AlgHom`. -/ noncomputable def aeval (ha : HasEval a) : PowerSeries R →ₐ[R] S := MvPowerSeries.aeval (hasEval ha) theorem coe_aeval (ha : HasEval a) : ↑(aeval ha) = eval₂ (algebraMap R S) a := MvPowerSeries.coe_aeval (hasEval ha) theorem continuous_aeval (ha : HasEval a) : Continuous (aeval ha : PowerSeries R → S) := MvPowerSeries.continuous_aeval (hasEval ha) @[simp] theorem aeval_coe (ha : HasEval a) (p : Polynomial R) : aeval ha (p : PowerSeries R) = Polynomial.aeval a p := by rw [coe_aeval, Polynomial.aeval_def, eval₂_coe] theorem aeval_unique {ε : PowerSeries R →ₐ[R] S} (hε : Continuous ε) : aeval (HasEval.X.map hε) = ε := MvPowerSeries.aeval_unique hε theorem hasSum_aeval (ha : HasEval a) (f : PowerSeries R) : HasSum (fun d ↦ coeff d f • a ^ d) (f.aeval ha) := by simp_rw [coe_aeval, ← algebraMap_smul (R := R) S, smul_eq_mul] exact hasSum_eval₂ (continuous_algebraMap R S) ha f theorem aeval_eq_sum (ha : HasEval a) (f : PowerSeries R) : aeval ha f = tsum fun d ↦ coeff d f • a ^ d := (hasSum_aeval ha f).tsum_eq.symm theorem comp_aeval (ha : HasEval a) {T : Type*} [CommRing T] [UniformSpace T] [IsUniformAddGroup T] [IsTopologicalRing T] [IsLinearTopology T T] [T2Space T] [Algebra R T] [ContinuousSMul R T] [CompleteSpace T] {ε : S →ₐ[R] T} (hε : Continuous ε) : ε.comp (aeval ha) = aeval (ha.map hε) := MvPowerSeries.comp_aeval (hasEval ha) hε end PowerSeries
.lake/packages/mathlib/Mathlib/RingTheory/PowerSeries/Trunc.lean
import Mathlib.Algebra.Polynomial.Coeff import Mathlib.Algebra.Polynomial.Degree.Lemmas import Mathlib.RingTheory.PowerSeries.Basic /-! # Formal power series in one variable - Truncation `PowerSeries.trunc n φ` truncates a (univariate) formal power series to the polynomial that has the same coefficients as `φ`, for all `m < n`, and `0` otherwise. -/ noncomputable section open Polynomial open Finset (antidiagonal mem_antidiagonal) namespace PowerSeries open Finsupp (single) variable {R : Type*} section Trunc variable [Semiring R] open Finset Nat /-- The `n`th truncation of a formal power series to a polynomial -/ def trunc (n : ℕ) (φ : R⟦X⟧) : R[X] := ∑ m ∈ Ico 0 n, Polynomial.monomial m (coeff m φ) theorem coeff_trunc (m) (n) (φ : R⟦X⟧) : (trunc n φ).coeff m = if m < n then coeff m φ else 0 := by simp [trunc, Polynomial.coeff_monomial] @[simp] theorem trunc_zero (n) : trunc n (0 : R⟦X⟧) = 0 := Polynomial.ext fun m => by rw [coeff_trunc, LinearMap.map_zero, Polynomial.coeff_zero] split_ifs <;> rfl @[simp] theorem trunc_one (n) : trunc (n + 1) (1 : R⟦X⟧) = 1 := Polynomial.ext fun m => by grind [PowerSeries.coeff_trunc, PowerSeries.coeff_one, Polynomial.coeff_one] @[simp] theorem trunc_C (n) (a : R) : trunc (n + 1) (C a) = Polynomial.C a := Polynomial.ext fun m => by rw [coeff_trunc, coeff_C, Polynomial.coeff_C] split_ifs with H <;> first | rfl | try simp_all @[simp] theorem trunc_add (n) (φ ψ : R⟦X⟧) : trunc n (φ + ψ) = trunc n φ + trunc n ψ := Polynomial.ext fun m => by simp only [coeff_trunc, Polynomial.coeff_add] split_ifs with H · rfl · rw [zero_add] theorem trunc_succ (f : R⟦X⟧) (n : ℕ) : trunc n.succ f = trunc n f + Polynomial.monomial n (coeff n f) := by rw [trunc, Ico_zero_eq_range, sum_range_succ, trunc, Ico_zero_eq_range] theorem natDegree_trunc_lt (f : R⟦X⟧) (n) : (trunc (n + 1) f).natDegree < n + 1 := by rw [Nat.lt_succ_iff, natDegree_le_iff_coeff_eq_zero] intros rw [coeff_trunc] split_ifs with h · rw [lt_succ, ← not_lt] at h contradiction · rfl @[simp] lemma trunc_zero' {f : R⟦X⟧} : trunc 0 f = 0 := rfl theorem degree_trunc_lt (f : R⟦X⟧) (n) : (trunc n f).degree < n := by rw [degree_lt_iff_coeff_zero] intros rw [coeff_trunc] split_ifs with h · rw [← not_le] at h contradiction · rfl theorem eval₂_trunc_eq_sum_range {S : Type*} [Semiring S] (s : S) (G : R →+* S) (n) (f : R⟦X⟧) : (trunc n f).eval₂ G s = ∑ i ∈ range n, G (coeff i f) * s ^ i := by cases n with | zero => rw [trunc_zero', range_zero, sum_empty, eval₂_zero] | succ n => have := natDegree_trunc_lt f n rw [eval₂_eq_sum_range' (hn := this)] apply sum_congr rfl intro _ h rw [mem_range] at h congr rw [coeff_trunc, if_pos h] @[simp] theorem trunc_X (n) : trunc (n + 2) X = (Polynomial.X : R[X]) := by ext d rw [coeff_trunc, coeff_X] split_ifs with h₁ h₂ · rw [h₂, coeff_X_one] · rw [coeff_X_of_ne_one h₂] · rw [coeff_X_of_ne_one] intro hd apply h₁ rw [hd] exact n.one_lt_succ_succ lemma trunc_X_of {n : ℕ} (hn : 2 ≤ n) : trunc n X = (Polynomial.X : R[X]) := by cases n with | zero => contradiction | succ n => cases n with | zero => contradiction | succ n => exact trunc_X n @[simp] lemma trunc_one_left (p : R⟦X⟧) : trunc (R := R) 1 p = .C (coeff 0 p) := by ext i; simp +contextual [coeff_trunc, Polynomial.coeff_C] lemma trunc_one_X : trunc (R := R) 1 X = 0 := by simp @[simp] lemma trunc_C_mul (n : ℕ) (r : R) (f : R⟦X⟧) : trunc n (C r * f) = .C r * trunc n f := by ext i; simp [coeff_trunc] @[simp] lemma trunc_mul_C (n : ℕ) (f : R⟦X⟧) (r : R) : trunc n (f * C r) = trunc n f * .C r := by ext i; simp [coeff_trunc] /-- Split off the first `n` coefficients. -/ lemma eq_shift_mul_X_pow_add_trunc (n : ℕ) (f : R⟦X⟧) : f = (mk fun i ↦ coeff (i + n) f) * X ^ n + (f.trunc n : R⟦X⟧) := by ext j rw [map_add, Polynomial.coeff_coe, coeff_mul_X_pow', coeff_trunc] simp_rw [← not_le] split_ifs with h <;> simp [h] /-- Split off the first `n` coefficients. -/ lemma eq_X_pow_mul_shift_add_trunc (n : ℕ) (f : R⟦X⟧) : f = X ^ n * (mk fun i ↦ coeff (i + n) f) + (f.trunc n : R⟦X⟧) := by rw [← (commute_X_pow _ n).eq, ← eq_shift_mul_X_pow_add_trunc] end Trunc section Trunc /- Lemmas in this section involve the coercion `R[X] → R⟦X⟧`, so they may only be stated in the case `R` is commutative. This is because the coercion is an `R`-algebra map. -/ variable {R : Type*} [CommSemiring R] open Nat hiding pow_succ pow_zero open Finset Finset.Nat theorem trunc_trunc_of_le {n m} (f : R⟦X⟧) (hnm : n ≤ m := by rfl) : trunc n ↑(trunc m f) = trunc n f := by ext d rw [coeff_trunc, coeff_trunc, coeff_coe] split_ifs with h · rw [coeff_trunc, if_pos <| lt_of_lt_of_le h hnm] · rfl @[simp] theorem trunc_trunc {n} (f : R⟦X⟧) : trunc n ↑(trunc n f) = trunc n f := trunc_trunc_of_le f @[simp] theorem trunc_trunc_mul {n} (f g : R⟦X⟧) : trunc n ((trunc n f) * g : R⟦X⟧) = trunc n (f * g) := by ext m rw [coeff_trunc, coeff_trunc] split_ifs with h · rw [coeff_mul, coeff_mul, sum_congr rfl] intro _ hab have ha := lt_of_le_of_lt (antidiagonal.fst_le hab) h rw [coeff_coe, coeff_trunc, if_pos ha] · rfl @[simp] theorem trunc_mul_trunc {n} (f g : R⟦X⟧) : trunc n (f * (trunc n g) : R⟦X⟧) = trunc n (f * g) := by rw [mul_comm, trunc_trunc_mul, mul_comm] theorem trunc_trunc_mul_trunc {n} (f g : R⟦X⟧) : trunc n (trunc n f * trunc n g : R⟦X⟧) = trunc n (f * g) := by rw [trunc_trunc_mul, trunc_mul_trunc] @[simp] theorem trunc_trunc_pow (f : R⟦X⟧) (n a : ℕ) : trunc n ((trunc n f : R⟦X⟧) ^ a) = trunc n (f ^ a) := by induction a with | zero => rw [pow_zero, pow_zero] | succ a ih => rw [_root_.pow_succ', _root_.pow_succ', trunc_trunc_mul, ← trunc_trunc_mul_trunc, ih, trunc_trunc_mul_trunc] theorem trunc_coe_eq_self {n} {f : R[X]} (hn : natDegree f < n) : trunc n (f : R⟦X⟧) = f := by rw [← Polynomial.coe_inj] ext m rw [coeff_coe, coeff_trunc] split case isTrue h => rfl case isFalse h => rw [not_lt] at h rw [coeff_coe]; symm exact coeff_eq_zero_of_natDegree_lt <| lt_of_lt_of_le hn h /-- The function `coeff n : R⟦X⟧ → R` is continuous. I.e. `coeff n f` depends only on a sufficiently long truncation of the power series `f`. -/ theorem coeff_coe_trunc_of_lt {n m} {f : R⟦X⟧} (h : n < m) : coeff n (trunc m f) = coeff n f := by rwa [coeff_coe, coeff_trunc, if_pos] /-- The `n`-th coefficient of `f*g` may be calculated from the truncations of `f` and `g`. -/ theorem coeff_mul_eq_coeff_trunc_mul_trunc₂ {n a b} (f g : R⟦X⟧) (ha : n < a) (hb : n < b) : coeff n (f * g) = coeff n ((trunc a f : R⟦X⟧) * (trunc b g : R⟦X⟧)) := by symm rw [← coeff_coe_trunc_of_lt n.lt_succ_self, ← trunc_trunc_mul_trunc, trunc_trunc_of_le f ha, trunc_trunc_of_le g hb, trunc_trunc_mul_trunc, coeff_coe_trunc_of_lt n.lt_succ_self] theorem coeff_mul_eq_coeff_trunc_mul_trunc {d n} (f g) (h : d < n) : coeff d (f * g) = coeff d ((trunc n f : R⟦X⟧) * (trunc n g : R⟦X⟧)) := coeff_mul_eq_coeff_trunc_mul_trunc₂ f g h h end Trunc section Map variable {S : Type*} [Semiring R] [Semiring S] (f : R →+* S) lemma trunc_map (p : R⟦X⟧) (n : ℕ) : (p.map f).trunc n = (p.trunc n).map f := by ext m; simp [coeff_trunc, apply_ite f] end Map end PowerSeries end
.lake/packages/mathlib/Mathlib/RingTheory/PowerSeries/Restricted.lean
import Mathlib.Analysis.Normed.Group.Ultra import Mathlib.Analysis.RCLike.Basic import Mathlib.RingTheory.PowerSeries.Basic import Mathlib.Tactic.Bound /-! # Restricted power series `IsRestricted` : We say a power series over a normed ring `R` is restricted for a parameter `c` if `‖coeff R i f‖ * c ^ i → 0`. -/ namespace PowerSeries variable {R : Type*} [NormedRing R] (c : ℝ) open PowerSeries Filter open scoped Topology /-- A power series over `R` is restricted of parameter `c` if we have `‖coeff R i f‖ * c ^ i → 0`. -/ def IsRestricted (f : PowerSeries R) := Tendsto (fun (i : ℕ) ↦ (norm (coeff i f)) * c ^ i) atTop (𝓝 0) namespace IsRestricted lemma isRestricted_iff {f : PowerSeries R} : IsRestricted c f ↔ ∀ ε, 0 < ε → ∃ N, ∀ n, N ≤ n → ‖‖(coeff n) f‖ * c ^ n‖ < ε := by simp [IsRestricted, NormedAddCommGroup.tendsto_atTop] lemma isRestricted_iff_abs (f : PowerSeries R) : IsRestricted c f ↔ IsRestricted |c| f := by simp [isRestricted_iff] lemma zero : IsRestricted c (0 : PowerSeries R) := by simp [IsRestricted] lemma one : IsRestricted c (1 : PowerSeries R) := by simp only [isRestricted_iff, coeff_one, norm_mul, norm_pow, Real.norm_eq_abs] refine fun _ _ ↦ ⟨1, fun n hn ↦ ?_ ⟩ split · omega · simpa lemma monomial (n : ℕ) (a : R) : IsRestricted c (monomial n a) := by simp only [monomial_eq_mk, isRestricted_iff, coeff_mk, norm_mul, norm_pow, Real.norm_eq_abs, abs_norm] refine fun _ _ ↦ ⟨n + 1, fun _ _ ↦ ?_⟩ split · omega · simpa lemma C (a : R) : IsRestricted c (C a) := by simpa [monomial_zero_eq_C_apply] using monomial c 0 a lemma add {f g : PowerSeries R} (hf : IsRestricted c f) (hg : IsRestricted c g) : IsRestricted c (f + g) := by simp only [isRestricted_iff, map_add, norm_mul, norm_pow, Real.norm_eq_abs] at ⊢ hf hg intro ε hε obtain ⟨fN, hfN⟩ := hf (ε / 2) (by positivity) obtain ⟨gN, hgN⟩ := hg (ε / 2) (by positivity) simp only [abs_norm] at hfN hgN ⊢ refine ⟨max fN gN, fun n hn ↦ ?_ ⟩ calc _ ≤ ‖(coeff n) f‖ * |c| ^ n + ‖(coeff n) g‖ * |c| ^ n := by grw [norm_add_le, add_mul] _ < ε / 2 + ε / 2 := by gcongr <;> grind _ = ε := by ring lemma neg {f : PowerSeries R} (hf : IsRestricted c f) : IsRestricted c (-f) := by simpa [isRestricted_iff] using hf lemma smul {f : PowerSeries R} (hf : IsRestricted c f) (r : R) : IsRestricted c (r • f) := by if h : r = 0 then simpa [h] using zero c else simp_rw [isRestricted_iff, norm_mul, norm_pow, Real.norm_eq_abs, abs_norm] at ⊢ hf intro ε _ obtain ⟨n, hn⟩ := hf (ε / ‖r‖) (by positivity) refine ⟨n, fun N hN ↦ ?_⟩ calc _ ≤ ‖r‖ * ‖(coeff N) f‖ * |c| ^ N := mul_le_mul_of_nonneg (norm_mul_le _ _) (by simp) (by simp) (by simp) _ < ‖r‖ * (ε / ‖r‖) := by rw [mul_assoc]; aesop _ = ε := mul_div_cancel₀ _ (by aesop) /-- The set of `‖coeff R i f‖ * c ^ i` for a given power series `f` and parameter `c`. -/ def convergenceSet (f : PowerSeries R) : Set ℝ := {‖coeff i f‖ * c^i | i : ℕ} open Finset in lemma convergenceSet_BddAbove {f : PowerSeries R} (hf : IsRestricted c f) : BddAbove (convergenceSet c f) := by simp_rw [isRestricted_iff] at hf obtain ⟨N, hf⟩ := by simpa using (hf 1) rw [bddAbove_def, convergenceSet] use max 1 (max' (image (fun i ↦ ‖coeff i f‖ * c ^ i) (range (N + 1))) (by simp)) simp only [Set.mem_setOf_eq, le_sup_iff, forall_exists_index, forall_apply_eq_imp_iff] intro i rcases le_total i N with h | h · right apply le_max' simp only [mem_image, mem_range] exact ⟨i, by omega, rfl⟩ · left calc _ ≤ ‖(coeff i) f‖ * |c ^ i| := by bound _ ≤ 1 := by simpa using (hf i h).le variable [IsUltrametricDist R] open IsUltrametricDist lemma mul {f g : PowerSeries R} (hf : IsRestricted c f) (hg : IsRestricted c g) : IsRestricted c (f * g) := by obtain ⟨a, ha, fBound1⟩ := (bddAbove_iff_exists_ge 1).mp (convergenceSet_BddAbove _ ((isRestricted_iff_abs c f).mp hf)) obtain ⟨b, hb, gBound1⟩ := (bddAbove_iff_exists_ge 1).mp (convergenceSet_BddAbove _ ((isRestricted_iff_abs c g).mp hg)) simp only [convergenceSet, Set.mem_setOf_eq, forall_exists_index, forall_apply_eq_imp_iff] at fBound1 gBound1 simp only [isRestricted_iff, norm_mul, norm_pow, Real.norm_eq_abs, abs_norm, PowerSeries.coeff_mul] at ⊢ hf hg intro ε hε obtain ⟨Nf, fBound2⟩ := (hf (ε / (max a b))) (by positivity) obtain ⟨Ng, gBound2⟩ := (hg (ε / (max a b))) (by positivity) refine ⟨2 * max Nf Ng, fun n hn ↦ ?_⟩ obtain ⟨⟨fst, snd⟩, hi, ultrametric⟩ := exists_norm_finset_sum_le (Finset.antidiagonal n) (fun a ↦ (coeff a.1) f * (coeff a.2) g) obtain ⟨rfl⟩ := by simpa using hi (⟨(0, n), by simp⟩) calc _ ≤ ‖(coeff fst) f * (coeff snd) g‖ * |c| ^ (fst + snd) := by bound _ ≤ ‖(coeff fst) f‖ * |c| ^ fst * (‖(coeff snd) g‖ * |c| ^ snd) := by grw [norm_mul_le]; grind have : max Nf Ng ≤ fst ∨ max Nf Ng ≤ snd := by omega rcases this with this | this · calc _ < ε / max a b * b := by grw [gBound1 snd] gcongr exact fBound2 fst (by omega) _ ≤ ε := by rw [div_mul_comm, mul_le_iff_le_one_left ‹_›] bound · calc _ < a * (ε / max a b) := by grw [fBound1 fst] gcongr exact gBound2 snd (by omega) _ ≤ ε := by rw [mul_div_left_comm, mul_le_iff_le_one_right ‹_›] bound end IsRestricted end PowerSeries
.lake/packages/mathlib/Mathlib/RingTheory/PowerSeries/NoZeroDivisors.lean
import Mathlib.RingTheory.PowerSeries.Order import Mathlib.RingTheory.Ideal.Maps /-! # Power series over rings with no zero divisors This file proves, using the properties of orders of power series, that `R⟦X⟧` is an integral domain when `R` is. We then state various results about `R⟦X⟧` with `R` an integral domain. ## Instance If `R` has `NoZeroDivisors`, then so does `R⟦X⟧`. -/ variable {R : Type*} namespace PowerSeries section NoZeroDivisors variable [Semiring R] instance [NoZeroDivisors R] : NoZeroDivisors R⟦X⟧ where eq_zero_or_eq_zero_of_mul_eq_zero {φ ψ} h := by simp_rw [← order_eq_top, order_mul] at h ⊢ exact WithTop.add_eq_top.mp h end NoZeroDivisors section IsDomain instance [Ring R] [IsDomain R] : IsDomain R⟦X⟧ := NoZeroDivisors.to_isDomain _ variable [CommRing R] [IsDomain R] /-- The ideal spanned by the variable in the power series ring over an integral domain is a prime ideal. -/ theorem span_X_isPrime : (Ideal.span ({X} : Set R⟦X⟧)).IsPrime := by suffices Ideal.span ({X} : Set R⟦X⟧) = RingHom.ker constantCoeff by rw [this] exact RingHom.ker_isPrime _ apply Ideal.ext intro φ rw [RingHom.mem_ker, Ideal.mem_span_singleton, X_dvd_iff] /-- The variable of the power series ring over an integral domain is prime. -/ theorem X_prime : Prime (X : R⟦X⟧) := by rw [← Ideal.span_singleton_prime] · exact span_X_isPrime · intro h simpa [map_zero (coeff 1)] using congr_arg (coeff 1) h /-- The variable of the power series ring over an integral domain is irreducible. -/ theorem X_irreducible : Irreducible (X : R⟦X⟧) := X_prime.irreducible theorem rescale_injective {a : R} (ha : a ≠ 0) : Function.Injective (rescale a) := by intro p q h rw [PowerSeries.ext_iff] at * intro n specialize h n rwa [coeff_rescale, coeff_rescale, mul_right_inj' <| pow_ne_zero _ ha] at h end IsDomain end PowerSeries
.lake/packages/mathlib/Mathlib/RingTheory/PowerSeries/Basic.lean
import Mathlib.Algebra.CharP.Defs import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.Basic import Mathlib.RingTheory.MvPowerSeries.Basic import Mathlib.Tactic.MoveAdd import Mathlib.Algebra.MvPolynomial.Equiv import Mathlib.RingTheory.Ideal.Basic /-! # Formal power series (in one variable) This file defines (univariate) 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. Formal power series in one variable are defined from multivariate power series as `PowerSeries R := MvPowerSeries Unit R`. The file sets up the (semi)ring structure on univariate power series. We provide the natural inclusion from polynomials to formal power series. Additional results can be found in: * `Mathlib/RingTheory/PowerSeries/Trunc.lean`, truncation of power series; * `Mathlib/RingTheory/PowerSeries/Inverse.lean`, about inverses of power series, and the fact that power series over a local ring form a local ring; * `Mathlib/RingTheory/PowerSeries/Order.lean`, the order of a power series at 0, and application to the fact that power series over an integral domain form an integral domain. ## Implementation notes Because of its definition, `PowerSeries R := MvPowerSeries Unit R`. a lot of proofs and properties from the multivariate case can be ported to the single variable case. However, it means that formal power series are indexed by `Unit →₀ ℕ`, which is of course canonically isomorphic to `ℕ`. We then build some glue to treat formal power series as if they were indexed by `ℕ`. Occasionally this leads to proofs that are uglier than expected. -/ noncomputable section open Finset (antidiagonal mem_antidiagonal) /-- Formal power series over a coefficient type `R` -/ abbrev PowerSeries (R : Type*) := MvPowerSeries Unit R namespace PowerSeries open Finsupp (single) variable {R : Type*} section /-- `R⟦X⟧` is notation for `PowerSeries R`, the semiring of formal power series in one variable over a semiring `R`. -/ scoped notation:9000 R "⟦X⟧" => PowerSeries R instance [Inhabited R] : Inhabited R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [Zero R] : Zero R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [AddMonoid R] : AddMonoid R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [AddGroup R] : AddGroup R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [AddCommMonoid R] : AddCommMonoid R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [AddCommGroup R] : AddCommGroup R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [Semiring R] : Semiring R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [CommSemiring R] : CommSemiring R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [Ring R] : Ring R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [CommRing R] : CommRing R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [Nontrivial R] : Nontrivial R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance {A} [Semiring R] [AddCommMonoid A] [Module R A] : Module R A⟦X⟧ := by dsimp only [PowerSeries] infer_instance 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 A⟦X⟧ := Pi.isScalarTower instance {A} [Semiring A] [CommSemiring R] [Algebra R A] : Algebra R A⟦X⟧ := by dsimp only [PowerSeries] infer_instance end section Semiring variable [Semiring R] /-- The `n`th coefficient of a formal power series. -/ def coeff (n : ℕ) : R⟦X⟧ →ₗ[R] R := MvPowerSeries.coeff (single () n) /-- The `n`th monomial with coefficient `a` as formal power series. -/ def monomial (n : ℕ) : R →ₗ[R] R⟦X⟧ := MvPowerSeries.monomial (single () n) theorem coeff_def {s : Unit →₀ ℕ} {n : ℕ} (h : s () = n) : coeff (R := R) n = MvPowerSeries.coeff s := by rw [coeff, ← h, ← Finsupp.unique_single s] /-- Two formal power series are equal if all their coefficients are equal. -/ @[ext] theorem ext {φ ψ : R⟦X⟧} (h : ∀ n, coeff n φ = coeff n ψ) : φ = ψ := MvPowerSeries.ext fun n => by rw [← coeff_def] · apply h rfl @[simp] theorem forall_coeff_eq_zero (φ : R⟦X⟧) : (∀ n, coeff n φ = 0) ↔ φ = 0 := ⟨fun h => ext h, fun h => by simp [h]⟩ /-- Two formal power series are equal if all their coefficients are equal. -/ add_decl_doc PowerSeries.ext_iff instance [Subsingleton R] : Subsingleton R⟦X⟧ := by simp only [subsingleton_iff, PowerSeries.ext_iff] subsingleton /-- Constructor for formal power series. -/ def mk {R} (f : ℕ → R) : R⟦X⟧ := fun s => f (s ()) @[simp] theorem coeff_mk (n : ℕ) (f : ℕ → R) : coeff n (mk f) = f n := congr_arg f Finsupp.single_eq_same theorem coeff_monomial (m n : ℕ) (a : R) : coeff m (monomial n a) = if m = n then a else 0 := calc coeff m (monomial n a) = _ := MvPowerSeries.coeff_monomial _ _ _ _ = if m = n then a else 0 := by simp only [Finsupp.unique_single_eq_iff] theorem monomial_eq_mk (n : ℕ) (a : R) : monomial n a = mk fun m => if m = n then a else 0 := ext fun m => by rw [coeff_monomial, coeff_mk] @[simp] theorem coeff_monomial_same (n : ℕ) (a : R) : coeff n (monomial n a) = a := MvPowerSeries.coeff_monomial_same _ _ @[simp] theorem coeff_comp_monomial (n : ℕ) : (coeff (R := R) n).comp (monomial n) = LinearMap.id := LinearMap.ext <| coeff_monomial_same n theorem monomial_mul_monomial (m n : ℕ) (a b : R) : monomial m a * monomial n b = monomial (m + n) (a * b) := by simpa [monomial] using MvPowerSeries.monomial_mul_monomial (Finsupp.single () m) (Finsupp.single () n) a b /-- The constant coefficient of a formal power series. -/ def constantCoeff : R⟦X⟧ →+* R := MvPowerSeries.constantCoeff /-- The constant formal power series. -/ def C : R →+* R⟦X⟧ := MvPowerSeries.C @[simp] lemma algebraMap_eq {R : Type*} [CommSemiring R] : algebraMap R R⟦X⟧ = C := rfl /-- The variable of the formal power series ring. -/ def X : R⟦X⟧ := MvPowerSeries.X () theorem commute_X (φ : R⟦X⟧) : Commute φ X := MvPowerSeries.commute_X _ _ theorem X_mul {φ : R⟦X⟧} : X * φ = φ * X := MvPowerSeries.X_mul theorem commute_X_pow (φ : R⟦X⟧) (n : ℕ) : Commute φ (X ^ n) := MvPowerSeries.commute_X_pow _ _ _ theorem X_pow_mul {φ : R⟦X⟧} {n : ℕ} : X ^ n * φ = φ * X ^ n := MvPowerSeries.X_pow_mul @[simp] theorem coeff_zero_eq_constantCoeff : ⇑(coeff (R := R) 0) = constantCoeff := by rw [coeff, Finsupp.single_zero] rfl theorem coeff_zero_eq_constantCoeff_apply (φ : R⟦X⟧) : coeff 0 φ = constantCoeff φ := by rw [coeff_zero_eq_constantCoeff] @[simp] theorem monomial_zero_eq_C : ⇑(monomial (R := R) 0) = C := by -- This used to be `rw`, but we need `rw; rfl` after https://github.com/leanprover/lean4/pull/2644 rw [monomial, Finsupp.single_zero, MvPowerSeries.monomial_zero_eq_C] rfl theorem monomial_zero_eq_C_apply (a : R) : monomial 0 a = C a := by simp theorem coeff_C (n : ℕ) (a : R) : coeff n (C a : R⟦X⟧) = if n = 0 then a else 0 := by rw [← monomial_zero_eq_C_apply, coeff_monomial] @[simp] theorem coeff_zero_C (a : R) : coeff 0 (C a) = a := by rw [coeff_C, if_pos rfl] theorem coeff_ne_zero_C {a : R} {n : ℕ} (h : n ≠ 0) : coeff n (C a) = 0 := by rw [coeff_C, if_neg h] @[simp] theorem coeff_succ_C {a : R} {n : ℕ} : coeff (n + 1) (C a) = 0 := coeff_ne_zero_C n.succ_ne_zero theorem C_injective : Function.Injective (C (R := R)) := by intro a b H simp_rw [PowerSeries.ext_iff] at H simpa only [coeff_zero_C] using H 0 protected theorem subsingleton_iff : Subsingleton R⟦X⟧ ↔ Subsingleton R := by refine ⟨fun h ↦ ?_, fun _ ↦ inferInstance⟩ rw [subsingleton_iff] at h ⊢ exact fun a b ↦ C_injective (h (C a) (C b)) theorem X_eq : (X : R⟦X⟧) = monomial 1 1 := rfl theorem coeff_X (n : ℕ) : coeff n (X : R⟦X⟧) = if n = 1 then 1 else 0 := by rw [X_eq, coeff_monomial] @[simp] theorem coeff_zero_X : coeff 0 (X : R⟦X⟧) = 0 := by rw [coeff, Finsupp.single_zero, X, MvPowerSeries.coeff_zero_X] @[simp] theorem coeff_one_X : coeff 1 (X : R⟦X⟧) = 1 := by rw [coeff_X, if_pos rfl] @[simp] theorem X_ne_zero [Nontrivial R] : (X : R⟦X⟧) ≠ 0 := fun H => by simpa only [coeff_one_X, one_ne_zero, map_zero] using congr_arg (coeff 1) H theorem X_pow_eq (n : ℕ) : (X : R⟦X⟧) ^ n = monomial n 1 := MvPowerSeries.X_pow_eq _ n theorem coeff_X_pow (m n : ℕ) : coeff m ((X : R⟦X⟧) ^ n) = if m = n then 1 else 0 := by rw [X_pow_eq, coeff_monomial] @[simp] theorem coeff_X_pow_self (n : ℕ) : coeff n ((X : R⟦X⟧) ^ n) = 1 := by rw [coeff_X_pow, if_pos rfl] @[simp] theorem coeff_one (n : ℕ) : coeff n (1 : R⟦X⟧) = if n = 0 then 1 else 0 := coeff_C n 1 theorem coeff_zero_one : coeff 0 (1 : R⟦X⟧) = 1 := coeff_zero_C 1 theorem coeff_mul (n : ℕ) (φ ψ : R⟦X⟧) : coeff n (φ * ψ) = ∑ p ∈ antidiagonal n, coeff p.1 φ * coeff p.2 ψ := by -- `rw` can't see that `PowerSeries = MvPowerSeries Unit`, so use `.trans` refine (MvPowerSeries.coeff_mul _ φ ψ).trans ?_ rw [Finsupp.antidiagonal_single, Finset.sum_map] rfl @[simp] theorem coeff_mul_C (n : ℕ) (φ : R⟦X⟧) (a : R) : coeff n (φ * C a) = coeff n φ * a := MvPowerSeries.coeff_mul_C _ φ a @[simp] theorem coeff_C_mul (n : ℕ) (φ : R⟦X⟧) (a : R) : coeff n (C a * φ) = a * coeff n φ := MvPowerSeries.coeff_C_mul _ φ a @[simp] theorem coeff_smul {S : Type*} [Semiring S] [Module R S] (n : ℕ) (φ : PowerSeries S) (a : R) : coeff n (a • φ) = a • coeff n φ := rfl @[simp] theorem constantCoeff_smul {S : Type*} [Semiring S] [Module R S] (φ : PowerSeries S) (a : R) : constantCoeff (a • φ) = a • constantCoeff φ := rfl theorem smul_eq_C_mul (f : R⟦X⟧) (a : R) : a • f = C a * f := by ext simp @[simp] theorem coeff_succ_mul_X (n : ℕ) (φ : R⟦X⟧) : coeff (n + 1) (φ * X) = coeff n φ := by simp only [coeff, Finsupp.single_add] convert φ.coeff_add_mul_monomial (single () n) (single () 1) _ rw [mul_one] @[simp] theorem coeff_succ_X_mul (n : ℕ) (φ : R⟦X⟧) : coeff (n + 1) (X * φ) = coeff n φ := by simp only [coeff, Finsupp.single_add, add_comm n 1] convert φ.coeff_add_monomial_mul (single () 1) (single () n) _ rw [one_mul] theorem mul_X_cancel {φ ψ : R⟦X⟧} (h : φ * X = ψ * X) : φ = ψ := by rw [PowerSeries.ext_iff] at h ⊢ intro n simpa using h (n + 1) theorem mul_X_injective : Function.Injective (· * X : R⟦X⟧ → R⟦X⟧) := fun _ _ ↦ mul_X_cancel theorem mul_X_inj {φ ψ : R⟦X⟧} : φ * X = ψ * X ↔ φ = ψ := mul_X_injective.eq_iff theorem X_mul_cancel {φ ψ : R⟦X⟧} (h : X * φ = X * ψ) : φ = ψ := by rw [PowerSeries.ext_iff] at h ⊢ intro n simpa using h (n + 1) theorem X_mul_injective : Function.Injective (X * · : R⟦X⟧ → R⟦X⟧) := fun _ _ ↦ X_mul_cancel theorem X_mul_inj {φ ψ : R⟦X⟧} : X * φ = X * ψ ↔ φ = ψ := X_mul_injective.eq_iff @[simp] theorem constantCoeff_C (a : R) : constantCoeff (C a) = a := rfl @[simp] theorem constantCoeff_comp_C : constantCoeff.comp C = RingHom.id R := rfl @[simp] theorem constantCoeff_zero : constantCoeff (R := R) 0 = 0 := rfl @[simp] theorem constantCoeff_one : constantCoeff (R := R) 1 = 1 := rfl @[simp] theorem constantCoeff_X : constantCoeff (R := R) X = 0 := MvPowerSeries.coeff_zero_X _ @[simp] theorem constantCoeff_mk {f : ℕ → R} : constantCoeff (mk f) = f 0 := rfl theorem coeff_zero_mul_X (φ : R⟦X⟧) : coeff 0 (φ * X) = 0 := by simp theorem coeff_zero_X_mul (φ : R⟦X⟧) : coeff 0 (X * φ) = 0 := by simp theorem constantCoeff_surj : Function.Surjective (constantCoeff (R := R)) := fun r => ⟨C r, constantCoeff_C r⟩ -- The following section duplicates the API of `Mathlib.Data.Polynomial.Coeff` and should attempt -- to keep up to date with that section theorem coeff_C_mul_X_pow (x : R) (k n : ℕ) : coeff n (C x * X ^ k : R⟦X⟧) = if n = k then x else 0 := by simp [X_pow_eq, coeff_monomial] @[simp] theorem coeff_mul_X_pow (p : R⟦X⟧) (n d : ℕ) : coeff (d + n) (p * X ^ n) = coeff d p := by rw [coeff_mul, Finset.sum_eq_single (d, n), coeff_X_pow, if_pos rfl, mul_one] · rintro ⟨i, j⟩ h1 h2 rw [coeff_X_pow, if_neg, mul_zero] rintro rfl apply h2 rw [mem_antidiagonal, add_right_cancel_iff] at h1 subst h1 rfl · exact fun h1 => (h1 (mem_antidiagonal.2 rfl)).elim @[simp] theorem coeff_X_pow_mul (p : R⟦X⟧) (n d : ℕ) : coeff (d + n) (X ^ n * p) = coeff d p := by rw [coeff_mul, Finset.sum_eq_single (n, d), coeff_X_pow, if_pos rfl, one_mul] · rintro ⟨i, j⟩ h1 h2 rw [coeff_X_pow, if_neg, zero_mul] rintro rfl apply h2 rw [mem_antidiagonal, add_comm, add_right_cancel_iff] at h1 subst h1 rfl · rw [add_comm] exact fun h1 => (h1 (mem_antidiagonal.2 rfl)).elim theorem mul_X_pow_cancel {k : ℕ} {φ ψ : R⟦X⟧} (h : φ * X ^ k = ψ * X ^ k) : φ = ψ := by rw [PowerSeries.ext_iff] at h ⊢ intro n simpa using h (n + k) theorem mul_X_pow_injective {k : ℕ} : Function.Injective (· * X ^ k : R⟦X⟧ → R⟦X⟧) := fun _ _ ↦ mul_X_pow_cancel theorem mul_X_pow_inj {k : ℕ} {φ ψ : R⟦X⟧} : φ * X ^ k = ψ * X ^ k ↔ φ = ψ := mul_X_pow_injective.eq_iff theorem X_pow_mul_cancel {k : ℕ} {φ ψ : R⟦X⟧} (h : X ^ k * φ = X ^ k * ψ) : φ = ψ := by rw [PowerSeries.ext_iff] at h ⊢ intro n simpa using h (n + k) theorem X_pow_mul_injective {k : ℕ} : Function.Injective (X ^ k * · : R⟦X⟧ → R⟦X⟧) := fun _ _ ↦ X_pow_mul_cancel theorem X_pow_mul_inj {k : ℕ} {φ ψ : R⟦X⟧} : X ^ k * φ = X ^ k * ψ ↔ φ = ψ := X_pow_mul_injective.eq_iff theorem coeff_mul_X_pow' (p : R⟦X⟧) (n d : ℕ) : coeff d (p * X ^ n) = ite (n ≤ d) (coeff (d - n) p) 0 := by split_ifs with h · rw [← tsub_add_cancel_of_le h, coeff_mul_X_pow, add_tsub_cancel_right] · refine (coeff_mul _ _ _).trans (Finset.sum_eq_zero fun x hx => ?_) rw [coeff_X_pow, if_neg, mul_zero] exact ((le_of_add_le_right (mem_antidiagonal.mp hx).le).trans_lt <| not_le.mp h).ne theorem coeff_X_pow_mul' (p : R⟦X⟧) (n d : ℕ) : coeff d (X ^ n * p) = ite (n ≤ d) (coeff (d - n) p) 0 := by split_ifs with h · rw [← tsub_add_cancel_of_le h, coeff_X_pow_mul] simp · refine (coeff_mul _ _ _).trans (Finset.sum_eq_zero fun x hx => ?_) rw [coeff_X_pow, if_neg, zero_mul] have := mem_antidiagonal.mp hx rw [add_comm] at this exact ((le_of_add_le_right this.le).trans_lt <| not_le.mp h).ne end /-- If a formal power series is invertible, then so is its constant coefficient. -/ theorem isUnit_constantCoeff (φ : R⟦X⟧) (h : IsUnit φ) : IsUnit (constantCoeff φ) := MvPowerSeries.isUnit_constantCoeff φ h /-- Split off the constant coefficient. -/ theorem eq_shift_mul_X_add_const (φ : R⟦X⟧) : φ = (mk fun p => coeff (p + 1) φ) * X + C (constantCoeff φ) := by ext (_ | n) · simp only [coeff_zero_eq_constantCoeff, map_add, map_mul, constantCoeff_X, mul_zero, coeff_zero_C, zero_add] · simp only [coeff_succ_mul_X, coeff_mk, LinearMap.map_add, coeff_C, n.succ_ne_zero, if_false, add_zero] /-- Split off the constant coefficient. -/ theorem eq_X_mul_shift_add_const (φ : R⟦X⟧) : φ = (X * mk fun p => coeff (p + 1) φ) + C (constantCoeff φ) := by ext (_ | n) · simp only [coeff_zero_eq_constantCoeff, map_add, map_mul, constantCoeff_X, zero_mul, coeff_zero_C, zero_add] · simp only [coeff_succ_X_mul, coeff_mk, LinearMap.map_add, coeff_C, n.succ_ne_zero, if_false, add_zero] section Map variable {S : Type*} {T : Type*} [Semiring S] [Semiring T] variable (f : R →+* S) (g : S →+* T) /-- The map between formal power series induced by a map on the coefficients. -/ def map : R⟦X⟧ →+* S⟦X⟧ := MvPowerSeries.map f @[simp] theorem map_id : (map (RingHom.id R) : R⟦X⟧ → R⟦X⟧) = id := rfl theorem map_comp : map (g.comp f) = (map g).comp (map f) := rfl @[simp] theorem coeff_map (n : ℕ) (φ : R⟦X⟧) : coeff n (map f φ) = f (coeff n φ) := rfl @[simp] theorem map_C (r : R) : map f (C r) = C (f r) := by ext simp [coeff_C, apply_ite f] @[simp] theorem map_X : map f X = X := by ext simp [coeff_X, apply_ite f] theorem map_surjective (f : S →+* T) (hf : Function.Surjective f) : Function.Surjective (PowerSeries.map f) := by intro g use PowerSeries.mk fun k ↦ Function.surjInv hf (PowerSeries.coeff k g) ext k simp only [Function.surjInv, coeff_map, coeff_mk] exact Classical.choose_spec (hf (coeff k g)) theorem map_injective (f : S →+* T) (hf : Function.Injective ⇑f) : Function.Injective (PowerSeries.map f) := by intro u v huv ext k apply hf rw [← PowerSeries.coeff_map, ← PowerSeries.coeff_map, huv] end Map @[simp] theorem map_eq_zero {R S : Type*} [DivisionSemiring R] [Semiring S] [Nontrivial S] (φ : R⟦X⟧) (f : R →+* S) : φ.map f = 0 ↔ φ = 0 := MvPowerSeries.map_eq_zero _ _ theorem X_pow_dvd_iff {n : ℕ} {φ : R⟦X⟧} : (X : R⟦X⟧) ^ n ∣ φ ↔ ∀ m, m < n → coeff m φ = 0 := by convert @MvPowerSeries.X_pow_dvd_iff Unit R _ () n φ constructor <;> intro h m hm · rw [Finsupp.unique_single m] convert h _ hm · apply h simpa only [Finsupp.single_eq_same] using hm theorem X_dvd_iff {φ : R⟦X⟧} : (X : R⟦X⟧) ∣ φ ↔ constantCoeff φ = 0 := by rw [← pow_one (X : R⟦X⟧), X_pow_dvd_iff, ← coeff_zero_eq_constantCoeff_apply] constructor <;> intro h · exact h 0 zero_lt_one · intro m hm rwa [Nat.eq_zero_of_le_zero (Nat.le_of_succ_le_succ hm)] end Semiring section CommSemiring variable [CommSemiring R] open Finset Nat /-- The ring homomorphism taking a power series `f(X)` to `f(aX)`. -/ noncomputable def rescale (a : R) : R⟦X⟧ →+* R⟦X⟧ where toFun f := PowerSeries.mk fun n => a ^ n * PowerSeries.coeff n f map_zero' := by ext simp only [LinearMap.map_zero, PowerSeries.coeff_mk, mul_zero] map_one' := by ext1 simp only [mul_boole, PowerSeries.coeff_mk, PowerSeries.coeff_one] split_ifs with h · rw [h, pow_zero a] rfl map_add' := by intros ext dsimp only exact mul_add _ _ _ map_mul' f g := by ext rw [PowerSeries.coeff_mul, PowerSeries.coeff_mk, PowerSeries.coeff_mul, Finset.mul_sum] apply sum_congr rfl simp only [coeff_mk, Prod.forall, mem_antidiagonal] intro b c H rw [← H, pow_add, mul_mul_mul_comm] @[simp] theorem coeff_rescale (f : R⟦X⟧) (a : R) (n : ℕ) : coeff n (rescale a f) = a ^ n * coeff n f := coeff_mk n (fun n ↦ a ^ n * coeff n f) @[simp] theorem rescale_zero : rescale 0 = (C (R := R)).comp constantCoeff := by ext x n simp only [Function.comp_apply, RingHom.coe_comp, rescale, RingHom.coe_mk, coeff_C] split_ifs with h <;> simp [h] theorem rescale_zero_apply (f : R⟦X⟧) : rescale 0 f = C (constantCoeff f) := by simp @[simp] theorem rescale_one : rescale 1 = RingHom.id R⟦X⟧ := by ext simp [coeff_rescale] theorem rescale_mk (f : ℕ → R) (a : R) : rescale a (mk f) = mk fun n : ℕ => a ^ n * f n := by ext rw [coeff_rescale, coeff_mk, coeff_mk] theorem rescale_rescale (f : R⟦X⟧) (a b : R) : rescale b (rescale a f) = rescale (a * b) f := by ext n simp_rw [coeff_rescale] rw [mul_pow, mul_comm _ (b ^ n), mul_assoc] theorem rescale_mul (a b : R) : rescale (a * b) = (rescale b).comp (rescale a) := by ext simp [← rescale_rescale] end CommSemiring section CommSemiring open Finset.HasAntidiagonal Finset variable {R : Type*} [CommSemiring R] {ι : Type*} /-- Coefficients of a product of power series -/ theorem coeff_prod [DecidableEq ι] (f : ι → PowerSeries R) (d : ℕ) (s : Finset ι) : coeff d (∏ j ∈ s, f j) = ∑ l ∈ finsuppAntidiag s d, ∏ i ∈ s, coeff (l i) (f i) := by simp only [coeff] rw [MvPowerSeries.coeff_prod, ← AddEquiv.finsuppUnique_symm d, ← mapRange_finsuppAntidiag_eq, sum_map, sum_congr rfl] intro x _ apply prod_congr rfl intro i _ congr 2 simp only [AddEquiv.toEquiv_eq_coe, Finsupp.mapRange.addEquiv_toEquiv, AddEquiv.toEquiv_symm, Equiv.coe_toEmbedding, Finsupp.mapRange.equiv_apply, AddEquiv.coe_toEquiv_symm, Finsupp.mapRange_apply, AddEquiv.finsuppUnique_symm] theorem prod_monomial (f : ι → ℕ) (g : ι → R) (s : Finset ι) : ∏ i ∈ s, monomial (f i) (g i) = monomial (∑ i ∈ s, f i) (∏ i ∈ s, g i) := by simpa [monomial, Finsupp.single_finset_sum] using MvPowerSeries.prod_monomial (fun i ↦ Finsupp.single () (f i)) g s theorem monomial_pow (m : ℕ) (a : R) (n : ℕ) : (monomial m a) ^ n = monomial (n * m) (a ^ n) := by simpa [monomial] using MvPowerSeries.monomial_pow (Finsupp.single () m) a n /-- The `n`-th coefficient of the `k`-th power of a power series. -/ lemma coeff_pow (k n : ℕ) (φ : R⟦X⟧) : coeff n (φ ^ k) = ∑ l ∈ finsuppAntidiag (range k) n, ∏ i ∈ range k, coeff (l i) φ := by have h₁ (i : ℕ) : Function.const ℕ φ i = φ := rfl have h₂ (i : ℕ) : ∏ j ∈ range i, Function.const ℕ φ j = φ ^ i := by apply prod_range_induction (fun _ => φ) (fun i => φ ^ i) rfl i (fun _ => congrFun rfl) rw [← h₂, ← h₁ k] apply coeff_prod (f := Function.const ℕ φ) (d := n) (s := range k) /-- First coefficient of the product of two power series. -/ lemma coeff_one_mul (φ ψ : R⟦X⟧) : coeff 1 (φ * ψ) = coeff 1 φ * constantCoeff ψ + coeff 1 ψ * constantCoeff φ := by have : Finset.antidiagonal 1 = {(0, 1), (1, 0)} := by exact rfl rw [coeff_mul, this, Finset.sum_insert, Finset.sum_singleton, coeff_zero_eq_constantCoeff, mul_comm, add_comm] simp /-- First coefficient of the `n`-th power of a power series. -/ lemma coeff_one_pow (n : ℕ) (φ : R⟦X⟧) : coeff 1 (φ ^ n) = n * coeff 1 φ * (constantCoeff φ) ^ (n - 1) := by rcases Nat.eq_zero_or_pos n with (rfl | hn) · simp induction n with | zero => cutsat | succ n' ih => have h₁ (m : ℕ) : φ ^ (m + 1) = φ ^ m * φ := by exact rfl have h₂ : Finset.antidiagonal 1 = {(0, 1), (1, 0)} := by exact rfl rw [h₁, coeff_mul, h₂, Finset.sum_insert, Finset.sum_singleton] · simp only [coeff_zero_eq_constantCoeff, map_pow, Nat.cast_add, Nat.cast_one, add_tsub_cancel_right] have h₀ : n' = 0 ∨ 1 ≤ n' := by omega rcases h₀ with h' | h' · by_contra h'' rw [h'] at h'' simp only [pow_zero, one_mul, coeff_one, one_ne_zero, ↓reduceIte, zero_mul, add_zero, mul_one] at h'' norm_num at h'' · rw [ih] · conv => lhs; arg 2; rw [mul_comm, ← mul_assoc] move_mul [← constantCoeff φ ^ (n' - 1)] conv => enter [1, 2, 1, 1, 2]; rw [← pow_one (a := constantCoeff φ)] rw [← pow_add (a := constantCoeff φ)] conv => enter [1, 2, 1, 1]; rw [Nat.sub_add_cancel h'] ring exact h' · decide end CommSemiring section CommRing variable {A : Type*} [CommRing A] theorem not_isField : ¬IsField A⟦X⟧ := by by_cases hA : Subsingleton A · exact not_isField_of_subsingleton _ · nontriviality A rw [Ring.not_isField_iff_exists_ideal_bot_lt_and_lt_top] use Ideal.span {X} constructor · rw [bot_lt_iff_ne_bot, Ne, Ideal.span_singleton_eq_bot] exact X_ne_zero · rw [lt_top_iff_ne_top, Ne, Ideal.eq_top_iff_one, Ideal.mem_span_singleton, X_dvd_iff, constantCoeff_one] exact one_ne_zero @[simp] theorem rescale_X (a : A) : rescale a X = C a * X := by ext simp only [coeff_rescale, coeff_C_mul, coeff_X] split_ifs with h <;> simp [h] theorem rescale_neg_one_X : rescale (-1 : A) X = -X := by rw [rescale_X, map_neg, map_one, neg_one_mul] /-- The ring homomorphism taking a power series `f(X)` to `f(-X)`. -/ noncomputable def evalNegHom : A⟦X⟧ →+* A⟦X⟧ := rescale (-1 : A) @[simp] theorem evalNegHom_X : evalNegHom (X : A⟦X⟧) = -X := rescale_neg_one_X end CommRing section Algebra variable {A B : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] theorem C_eq_algebraMap {r : R} : C r = (algebraMap R R⟦X⟧) r := rfl theorem algebraMap_apply {r : R} : algebraMap R A⟦X⟧ r = C (algebraMap R A r) := MvPowerSeries.algebraMap_apply instance [Nontrivial R] : Nontrivial (Subalgebra R R⟦X⟧) := { inferInstanceAs <| Nontrivial <| Subalgebra R <| MvPowerSeries Unit R with } /-- Change of coefficients in power series, as an `AlgHom` -/ def mapAlgHom (φ : A →ₐ[R] B) : PowerSeries A →ₐ[R] PowerSeries B := MvPowerSeries.mapAlgHom φ theorem mapAlgHom_apply (φ : A →ₐ[R] B) (f : A⟦X⟧) : mapAlgHom φ f = f.map φ := MvPowerSeries.mapAlgHom_apply φ f end Algebra end PowerSeries namespace Polynomial open Finsupp Polynomial section Semiring variable {R : Type*} [Semiring R] (φ ψ : R[X]) /-- The natural inclusion from polynomials into formal power series. -/ @[coe] def toPowerSeries : R[X] → PowerSeries R := fun φ => PowerSeries.mk fun n => coeff φ n /-- The natural inclusion from polynomials into formal power series. -/ instance coeToPowerSeries : Coe R[X] (PowerSeries R) := ⟨toPowerSeries⟩ theorem coe_def : (φ : PowerSeries R) = PowerSeries.mk (coeff φ) := rfl @[simp, norm_cast] theorem coeff_coe (n) : PowerSeries.coeff n φ = coeff φ n := congr_arg (coeff φ) Finsupp.single_eq_same @[simp, norm_cast] theorem coe_monomial (n : ℕ) (a : R) : (monomial n a : PowerSeries R) = PowerSeries.monomial n a := by ext simp [coeff_coe, PowerSeries.coeff_monomial, Polynomial.coeff_monomial, eq_comm] @[simp, norm_cast] theorem coe_zero : ((0 : R[X]) : PowerSeries R) = 0 := rfl @[simp, norm_cast] theorem coe_one : ((1 : R[X]) : PowerSeries R) = 1 := by have := coe_monomial 0 (1 : R) rwa [PowerSeries.monomial_zero_eq_C_apply] at this @[simp, norm_cast] theorem coe_add : ((φ + ψ : R[X]) : PowerSeries R) = φ + ψ := by ext simp @[simp, norm_cast] theorem coe_mul : ((φ * ψ : R[X]) : PowerSeries R) = φ * ψ := PowerSeries.ext fun n => by simp only [coeff_coe, PowerSeries.coeff_mul, coeff_mul] @[simp, norm_cast] lemma coe_smul (φ : R[X]) (r : R) : (r • φ : Polynomial R) = r • (φ : PowerSeries R) := rfl @[simp, norm_cast] theorem coe_C (a : R) : ((C a : R[X]) : PowerSeries R) = PowerSeries.C a := by have := coe_monomial 0 a rwa [PowerSeries.monomial_zero_eq_C_apply] at this @[simp, norm_cast] theorem coe_X : ((X : R[X]) : PowerSeries R) = PowerSeries.X := coe_monomial _ _ @[simp] lemma polynomial_map_coe {U V : Type*} [CommSemiring U] [CommSemiring V] {φ : U →+* V} {f : Polynomial U} : Polynomial.map φ f = PowerSeries.map φ f := by ext simp @[simp] theorem constantCoeff_coe : PowerSeries.constantCoeff φ = φ.coeff 0 := rfl variable (R) theorem coe_injective : Function.Injective ((↑) : R[X] → PowerSeries R) := fun x y h => by ext simp_rw [← coeff_coe, h] variable {R φ ψ} @[simp, norm_cast] theorem coe_inj : (φ : PowerSeries R) = ψ ↔ φ = ψ := (coe_injective R).eq_iff @[simp] theorem coe_eq_zero_iff : (φ : PowerSeries R) = 0 ↔ φ = 0 := by rw [← coe_zero, coe_inj] @[simp] theorem coe_eq_one_iff : (φ : PowerSeries R) = 1 ↔ φ = 1 := by rw [← coe_one, coe_inj] /-- The coercion from polynomials to power series as a ring homomorphism. -/ def coeToPowerSeries.ringHom : R[X] →+* PowerSeries R where toFun := (↑) map_zero' := coe_zero map_one' := coe_one map_add' := coe_add map_mul' := coe_mul @[simp] theorem coeToPowerSeries.ringHom_apply : coeToPowerSeries.ringHom φ = φ := rfl @[simp, norm_cast] theorem coe_pow (n : ℕ) : ((φ ^ n : R[X]) : PowerSeries R) = (φ : PowerSeries R) ^ n := coeToPowerSeries.ringHom.map_pow _ _ theorem eval₂_C_X_eq_coe : φ.eval₂ PowerSeries.C PowerSeries.X = ↑φ := by nth_rw 2 [← eval₂_C_X (p := φ)] rw [← coeToPowerSeries.ringHom_apply, eval₂_eq_sum_range, eval₂_eq_sum_range, map_sum] apply Finset.sum_congr rfl intros rw [map_mul, map_pow, coeToPowerSeries.ringHom_apply, coeToPowerSeries.ringHom_apply, coe_C, coe_X] end Semiring section CommSemiring variable {R : Type*} [CommSemiring R] (φ ψ : R[X]) theorem _root_.MvPolynomial.toMvPowerSeries_pUnitAlgEquiv {f : MvPolynomial PUnit R} : (f.toMvPowerSeries : PowerSeries R) = (f.pUnitAlgEquiv R).toPowerSeries := by induction f using MvPolynomial.induction_on' with | monomial d r => --Note: this `have` should be a generic `simp` lemma for a `Unique` type with `()` replaced --by any element. have : single () (d ()) = d := by ext; simp simp only [MvPolynomial.coe_monomial, MvPolynomial.pUnitAlgEquiv_monomial, Polynomial.coe_monomial, PowerSeries.monomial, this] | add f g hf hg => simp [hf, hg] theorem pUnitAlgEquiv_symm_toPowerSeries {f : Polynomial R} : ((f.toPowerSeries) : MvPowerSeries PUnit R) = ((MvPolynomial.pUnitAlgEquiv R).symm f).toMvPowerSeries := by set g := (MvPolynomial.pUnitAlgEquiv R).symm f have : f = MvPolynomial.pUnitAlgEquiv R g := by simp only [g, AlgEquiv.apply_symm_apply] rw [this, MvPolynomial.toMvPowerSeries_pUnitAlgEquiv] variable (A : Type*) [Semiring A] [Algebra R A] /-- The coercion from polynomials to power series as an algebra homomorphism. -/ def coeToPowerSeries.algHom : R[X] →ₐ[R] PowerSeries A := { (PowerSeries.map (algebraMap R A)).comp coeToPowerSeries.ringHom with commutes' := fun r => by simp [PowerSeries.algebraMap_apply] } @[simp] theorem coeToPowerSeries.algHom_apply : coeToPowerSeries.algHom A φ = PowerSeries.map (algebraMap R A) ↑φ := rfl end CommSemiring section CommRing variable {R : Type*} [CommRing R] @[simp, norm_cast] lemma coe_neg (p : R[X]) : ((-p : R[X]) : PowerSeries R) = -p := coeToPowerSeries.ringHom.map_neg p @[simp, norm_cast] lemma coe_sub (p q : R[X]) : ((p - q : R[X]) : PowerSeries R) = p - q := coeToPowerSeries.ringHom.map_sub p q end CommRing end Polynomial namespace PowerSeries section Algebra open Polynomial variable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A] (f : R⟦X⟧) instance algebraPolynomial : Algebra R[X] A⟦X⟧ := RingHom.toAlgebra (Polynomial.coeToPowerSeries.algHom A).toRingHom instance algebraPowerSeries : Algebra R⟦X⟧ A⟦X⟧ := (map (algebraMap R A)).toAlgebra -- see Note [lower instance priority] instance (priority := 100) algebraPolynomial' {A : Type*} [CommSemiring A] [Algebra R A[X]] : Algebra R A⟦X⟧ := RingHom.toAlgebra <| Polynomial.coeToPowerSeries.ringHom.comp (algebraMap R A[X]) variable (A) theorem algebraMap_apply' (p : R[X]) : algebraMap R[X] A⟦X⟧ p = map (algebraMap R A) p := rfl theorem algebraMap_apply'' : algebraMap R⟦X⟧ A⟦X⟧ f = map (algebraMap R A) f := rfl end Algebra end PowerSeries end
.lake/packages/mathlib/Mathlib/RingTheory/PowerSeries/WeierstrassPreparation.lean
import Mathlib.RingTheory.LocalRing.ResidueField.Basic import Mathlib.RingTheory.Polynomial.Eisenstein.Distinguished import Mathlib.RingTheory.PowerSeries.CoeffMulMem import Mathlib.RingTheory.PowerSeries.Inverse import Mathlib.RingTheory.PowerSeries.Trunc /-! # Weierstrass preparation theorem for power series over a complete local ring In this file we define Weierstrass division, Weierstrass factorization, and prove Weierstrass preparation theorem. We assume that a ring is adic complete with respect to some ideal. If such ideal is a maximal ideal, then by `isLocalRing_of_isAdicComplete_maximal`, such ring has only one maximal ideal, and hence it is a complete local ring. ## Main definitions - `PowerSeries.IsWeierstrassDivisionAt f g q r I`: let `f` and `g` be power series over `A`, `I` be an ideal of `A`, this is a `Prop` which asserts that a power series `q` and a polynomial `r` of degree `< n` satisfy `f = g * q + r`, where `n` is the order of the image of `g` in `(A / I)⟦X⟧` (defined to be zero if such image is zero, in which case it's mathematically not considered). - `PowerSeries.IsWeierstrassDivision`: version of `PowerSeries.IsWeierstrassDivisionAt` for local rings with respect to its maximal ideal. - `PowerSeries.IsWeierstrassDivisorAt g I`: let `g` be a power series over `A`, `I` be an ideal of `A`, this is a `Prop` which asserts that the `n`-th coefficient of `g` is a unit, where `n` is the order of the image of `g` in `(A / I)⟦X⟧` (defined to be zero if such image is zero, in which case it's mathematically not considered). This property guarantees that if the `A` is `I`-adic complete, then `g` can be used as a divisor in Weierstrass division (`PowerSeries.IsWeierstrassDivisorAt.isWeierstrassDivisionAt_div_mod`). - `PowerSeries.IsWeierstrassDivisor`: version of `PowerSeries.IsWeierstrassDivisorAt` for local rings with respect to its maximal ideal. - `PowerSeries.IsWeierstrassFactorizationAt g f h I`: for a power series `g` over `A` and an ideal `I` of `A`, this is a `Prop` which asserts that `f` is a distinguished polynomial at `I`, `h` is a formal power series over `A` that is a unit and such that `g = f * h`. - `PowerSeries.IsWeierstrassFactorization`: version of `PowerSeries.IsWeierstrassFactorizationAt` for local rings with respect to its maximal ideal. ## Main results - `PowerSeries.exists_isWeierstrassDivision`: **Weierstrass division** ([washington_cyclotomic], Proposition 7.2): let `f`, `g` be power series over a complete local ring, such that the image of `g` in the residue field is not zero. Let `n` be the order of the image of `g` in the residue field. Then there exists a power series `q` and a polynomial `r` of degree `< n`, such that `f = g * q + r`. - `PowerSeries.IsWeierstrassDivision.elim`, `PowerSeries.IsWeierstrassDivision.unique`: `q` and `r` in the Weierstrass division are unique. - `PowerSeries.exists_isWeierstrassFactorization`: **Weierstrass preparation theorem** ([washington_cyclotomic], Theorem 7.3): let `g` be a power series over a complete local ring, such that its image in the residue field is not zero. Then there exists a distinguished polynomial `f` and a power series `h` which is a unit, such that `g = f * h`. - `PowerSeries.IsWeierstrassFactorization.elim`, `PowerSeries.IsWeierstrassFactorization.unique`: `f` and `h` in Weierstrass preparation theorem are unique. - `Polynomial.IsDistinguishedAt.algEquivQuotient`: a distinguished polynomial `g` induces a natural isomorphism `A[X] / (g) ≃ₐ[A] A⟦X⟧ / (g)`. - `PowerSeries.IsWeierstrassFactorizationAt.algEquivQuotient`: a Weierstrass factorization `g = f * h` induces a natural isomorphism `A[X] / (f) ≃ₐ[A] A⟦X⟧ / (g)`. - `PowerSeries.algEquivQuotientWeierstrassDistinguished`: if `g` is a power series over a complete local ring, such that its image in the residue field is not zero, then there is a natural isomorphism `A[X] / (f) ≃ₐ[A] A⟦X⟧ / (g)` where `f` is `PowerSeries.weierstrassDistinguished g`. ## References - [Washington, Lawrence C. *Introduction to cyclotomic fields.*][washington_cyclotomic] -/ open scoped Polynomial namespace PowerSeries variable {A : Type*} [CommRing A] /-! ## Weierstrass division -/ section IsWeierstrassDivisionAt variable (f g q : A⟦X⟧) (r : A[X]) (I : Ideal A) /-- Let `f`, `g` be power series over `A`, `I` be an ideal of `A`, `PowerSeries.IsWeierstrassDivisionAt f g q r I` is a `Prop` which asserts that a power series `q` and a polynomial `r` of degree `< n` satisfy `f = g * q + r`, where `n` is the order of the image of `g` in `(A / I)⟦X⟧` (defined to be zero if such image is zero, in which case it's mathematically not considered). -/ @[mk_iff] structure IsWeierstrassDivisionAt : Prop where degree_lt : r.degree < (g.map (Ideal.Quotient.mk I)).order.toNat eq_mul_add : f = g * q + r /-- Version of `PowerSeries.IsWeierstrassDivisionAt` for local rings with respect to its maximal ideal. -/ abbrev IsWeierstrassDivision [IsLocalRing A] : Prop := f.IsWeierstrassDivisionAt g q r (IsLocalRing.maximalIdeal A) theorem isWeierstrassDivisionAt_zero : IsWeierstrassDivisionAt 0 g 0 0 I := by constructor · rw [Polynomial.degree_zero] exact WithBot.bot_lt_coe _ · simp variable {f g q r I} namespace IsWeierstrassDivisionAt theorem coeff_f_sub_r_mem (H : f.IsWeierstrassDivisionAt g q r I) {i : ℕ} (hi : i < (g.map (Ideal.Quotient.mk I)).order.toNat) : coeff i (f - r : A⟦X⟧) ∈ I := by replace H := H.2 rw [← sub_eq_iff_eq_add] at H rw [H] refine coeff_mul_mem_ideal_of_coeff_left_mem_ideal i (fun j hj ↦ ?_) i le_rfl have := coeff_of_lt_order_toNat _ (lt_of_le_of_lt hj hi) rwa [coeff_map, ← RingHom.mem_ker, Ideal.mk_ker] at this theorem add {f' q' r'} (H : f.IsWeierstrassDivisionAt g q r I) (H' : f'.IsWeierstrassDivisionAt g q' r' I) : (f + f').IsWeierstrassDivisionAt g (q + q') (r + r') I := ⟨(Polynomial.degree_add_le _ _).trans_lt (sup_lt_iff.2 ⟨H.degree_lt, H'.degree_lt⟩), by rw [H.eq_mul_add, H'.eq_mul_add, Polynomial.coe_add]; ring⟩ theorem smul (H : f.IsWeierstrassDivisionAt g q r I) (a : A) : (a • f).IsWeierstrassDivisionAt g (a • q) (a • r) I := ⟨(Polynomial.degree_smul_le a _).trans_lt H.degree_lt, by simp [H.eq_mul_add, Algebra.smul_def, mul_add, mul_left_comm]⟩ end IsWeierstrassDivisionAt end IsWeierstrassDivisionAt section IsWeierstrassDivisorAt variable (g : A⟦X⟧) (I : Ideal A) /-- `PowerSeries.IsWeierstrassDivisorAt g I` is a `Prop` which asserts that the `n`-th coefficient of `g` is a unit, where `n` is the order of the image of `g` in `(A / I)⟦X⟧` (defined to be zero if such image is zero, in which case it's mathematically not considered). This property guarantees that if the ring is `I`-adic complete, then `g` can be used as a divisor in Weierstrass division (`PowerSeries.IsWeierstrassDivisorAt.isWeierstrassDivisionAt_div_mod`). -/ def IsWeierstrassDivisorAt : Prop := IsUnit (coeff (g.map (Ideal.Quotient.mk I)).order.toNat g) /-- Version of `PowerSeries.IsWeierstrassDivisorAt` for local rings with respect to its maximal ideal. -/ abbrev IsWeierstrassDivisor [IsLocalRing A] : Prop := g.IsWeierstrassDivisorAt (IsLocalRing.maximalIdeal A) variable {g} in /-- If `g` is a power series over a local ring such that its image in the residue field is not zero, then `g` can be used as a Weierstrass divisor. -/ theorem IsWeierstrassDivisor.of_map_ne_zero [IsLocalRing A] (hg : g.map (IsLocalRing.residue A) ≠ 0) : g.IsWeierstrassDivisor := by rw [IsWeierstrassDivisor, IsWeierstrassDivisorAt, ← IsLocalRing.notMem_maximalIdeal] have h := coeff_order hg contrapose! h rwa [coeff_map, IsLocalRing.residue_eq_zero_iff] theorem _root_.Polynomial.IsDistinguishedAt.isWeierstrassDivisorAt {g : A[X]} {I : Ideal A} (H : g.IsDistinguishedAt I) (hI : I ≠ ⊤) : IsWeierstrassDivisorAt g I := by have : g.natDegree = _ := congr(ENat.toNat $(H.coe_natDegree_eq_order_map g 1 (by rwa [constantCoeff_one, ← Ideal.ne_top_iff_one]) (by simp))) simp [IsWeierstrassDivisorAt, ← this, H.monic.leadingCoeff] theorem _root_.Polynomial.IsDistinguishedAt.isWeierstrassDivisorAt' {g : A[X]} {I : Ideal A} (H : g.IsDistinguishedAt I) [IsHausdorff I A] : IsWeierstrassDivisorAt g I := by rcases eq_or_ne I ⊤ with rfl | hI · have := ‹IsHausdorff ⊤ A›.subsingleton exact isUnit_of_subsingleton _ exact H.isWeierstrassDivisorAt hI private theorem coeff_trunc_order_mem (i : ℕ) : (g.trunc (g.map (Ideal.Quotient.mk I)).order.toNat).coeff i ∈ I := by rw [coeff_trunc] split_ifs with h · simpa [← RingHom.mem_ker] using coeff_of_lt_order_toNat _ h · exact zero_mem _ namespace IsWeierstrassDivisorAt variable {g I} (H : g.IsWeierstrassDivisorAt I) include H theorem isUnit_shift : IsUnit <| mk fun i ↦ coeff (i + (g.map (Ideal.Quotient.mk I)).order.toNat) g := by simpa [isUnit_iff_constantCoeff] /-- The inductively constructed sequence `qₖ` in the proof of Weierstrass division. -/ noncomputable def seq (H : g.IsWeierstrassDivisorAt I) (f : A⟦X⟧) : ℕ → A⟦X⟧ | 0 => 0 | k + 1 => H.seq f k + (mk fun i ↦ coeff (i + (g.map (Ideal.Quotient.mk I)).order.toNat) (f - g * H.seq f k)) * H.isUnit_shift.unit⁻¹ variable (a : A) (f f' : A⟦X⟧) theorem coeff_seq_mem (k : ℕ) {i : ℕ} (hi : i ≥ (g.map (Ideal.Quotient.mk I)).order.toNat) : coeff i (f - g * H.seq f k) ∈ I ^ k := by induction k generalizing hi i with | zero => simp | succ k hq => rw [seq] set q := H.seq f k set s := f - g * q set n := (g.map (Ideal.Quotient.mk I)).order.toNat have hs := s.eq_X_pow_mul_shift_add_trunc n set s₀ := s.trunc n set s₁ := PowerSeries.mk fun i ↦ coeff (i + n) s set q' := q + s₁ * H.isUnit_shift.unit⁻¹ have key : f - g * q' = (s₀ : A⟦X⟧) - (g.trunc n : A⟦X⟧) * s₁ * H.isUnit_shift.unit⁻¹ := by trans s + g * (q - q') · simp_rw [s]; ring simp_rw [q'] rw [sub_add_cancel_left, mul_neg, ← mul_assoc, mul_right_comm] nth_rw 1 [g.eq_X_pow_mul_shift_add_trunc n] rw [add_mul, mul_assoc, IsUnit.mul_val_inv, hs] ring rw [key, map_sub, Polynomial.coeff_coe, coeff_trunc, if_neg hi.not_gt, zero_sub, neg_mem_iff, pow_succ'] refine coeff_mul_mem_ideal_of_coeff_left_mem_ideal' (fun i ↦ ?_) i refine coeff_mul_mem_ideal_mul_ideal_of_coeff_mem_ideal' (by simp [n, g.coeff_trunc_order_mem]) (fun i ↦ ?_) i rw [coeff_mk] exact hq (by simp) theorem coeff_seq_succ_sub_seq_mem (k i : ℕ) : coeff i (H.seq f (k + 1) - H.seq f k) ∈ I ^ k := by rw [seq, add_sub_cancel_left] refine coeff_mul_mem_ideal_of_coeff_left_mem_ideal' (fun i ↦ ?_) i rw [coeff_mk] exact H.coeff_seq_mem f k (by simp) @[simp] theorem seq_zero : H.seq f 0 = 0 := rfl theorem seq_one : H.seq f 1 = (PowerSeries.mk fun i ↦ coeff (i + (g.map (Ideal.Quotient.mk I)).order.toNat) f) * H.isUnit_shift.unit⁻¹ := by simp_rw [seq, mul_zero, zero_add, sub_zero] /-- The (bundled version of) coefficient of the limit `q` of the inductively constructed sequence `qₖ` in the proof of Weierstrass division. -/ noncomputable def divCoeff [IsPrecomplete I A] (i : ℕ) := Classical.indefiniteDescription _ <| IsPrecomplete.prec' (I := I) (fun k ↦ coeff i (H.seq f k)) fun {m} {n} hn ↦ by induction n, hn using Nat.le_induction with | base => rw [SModEq.def] | succ n hn ih => refine ih.trans (SModEq.symm ?_) rw [SModEq.sub_mem, smul_eq_mul, Ideal.mul_top, ← map_sub] exact Ideal.pow_le_pow_right hn (H.coeff_seq_succ_sub_seq_mem f n i) /-- The limit `q` of the inductively constructed sequence `qₖ` in the proof of Weierstrass division. -/ noncomputable def div [IsPrecomplete I A] : A⟦X⟧ := PowerSeries.mk fun i ↦ (H.divCoeff f i).1 theorem coeff_div [IsPrecomplete I A] (i : ℕ) : coeff i (H.div f) = (H.divCoeff f i).1 := by simp [div] theorem coeff_div_sub_seq_mem [IsPrecomplete I A] (k i : ℕ) : coeff i (H.div f - (H.seq f k)) ∈ I ^ k := by simpa [coeff_div, SModEq.sub_mem] using ((H.divCoeff f i).2 k).symm /-- The remainder `r` in the proof of Weierstrass division. -/ noncomputable def mod [IsPrecomplete I A] : A[X] := (f - g * H.div f).trunc (g.map (Ideal.Quotient.mk I)).order.toNat /-- If the ring is `I`-adic complete, then `g` can be used as a divisor in Weierstrass division. -/ theorem isWeierstrassDivisionAt_div_mod [IsAdicComplete I A] : f.IsWeierstrassDivisionAt g (H.div f) (H.mod f) I := by rcases eq_or_ne I ⊤ with rfl | hI · have := ‹IsAdicComplete ⊤ A›.toIsHausdorff.subsingleton rw [Subsingleton.elim f 0, Subsingleton.elim (H.div 0) 0, Subsingleton.elim (H.mod 0) 0] exact g.isWeierstrassDivisionAt_zero _ constructor · exact degree_trunc_lt _ _ · rw [mod, add_comm, ← sub_eq_iff_eq_add] ext i rw [Polynomial.coeff_coe, coeff_trunc] split_ifs with hi · rfl refine IsHausdorff.haus' (I := I) _ fun k ↦ ?_ rw [SModEq.zero, smul_eq_mul, Ideal.mul_top, show f - g * H.div f = f - g * (H.seq f k) - g * (H.div f - (H.seq f k)) by ring, map_sub] exact Ideal.sub_mem _ (H.coeff_seq_mem f k (not_lt.1 hi)) <| coeff_mul_mem_ideal_of_coeff_right_mem_ideal' (H.coeff_div_sub_seq_mem f k) i /-- If `g * q = r` for some power series `q` and some polynomial `r` whose degree is `< n`, then `q` and `r` are all zero. This implies the uniqueness of Weierstrass division. -/ theorem eq_zero_of_mul_eq [IsHausdorff I A] {q : A⟦X⟧} {r : A[X]} (hdeg : r.degree < (g.map (Ideal.Quotient.mk I)).order.toNat) (heq : g * q = r) : q = 0 ∧ r = 0 := by suffices ∀ k i, coeff i q ∈ I ^ k by have hq : q = 0 := by ext i refine IsHausdorff.haus' (I := I) _ fun k ↦ ?_ rw [SModEq.zero, smul_eq_mul, Ideal.mul_top] exact this _ _ rw [hq, mul_zero, Eq.comm, Polynomial.coe_eq_zero_iff] at heq exact ⟨hq, heq⟩ intro k induction k with | zero => simp | succ k ih => rw [g.eq_X_pow_mul_shift_add_trunc (g.map (Ideal.Quotient.mk I)).order.toNat] at heq have h1 : ∀ i, coeff i r ∈ I ^ (k + 1) := fun i ↦ by rcases lt_or_ge i (g.map (Ideal.Quotient.mk I)).order.toNat with hi | hi · rw [← heq, pow_succ'] refine coeff_mul_mem_ideal_mul_ideal_of_coeff_mem_ideal i (fun j hj ↦ ?_) (fun j _ ↦ ih j) i le_rfl rw [map_add, Polynomial.coeff_coe] refine Ideal.add_mem _ ?_ (g.coeff_trunc_order_mem I j) simp_rw [coeff_X_pow_mul', if_neg (lt_of_le_of_lt hj hi).not_ge, zero_mem] simp_rw [Polynomial.coeff_coe, Polynomial.coeff_eq_zero_of_degree_lt (lt_of_lt_of_le hdeg (by simpa)), zero_mem] rw [add_mul, mul_comm (X ^ _), ← eq_sub_iff_add_eq] at heq replace heq := congr(H.isUnit_shift.unit⁻¹ * $heq) rw [← mul_assoc, ← mul_assoc, IsUnit.val_inv_mul, one_mul] at heq intro i rw [← coeff_X_pow_mul _ (g.map (Ideal.Quotient.mk I)).order.toNat i, heq] refine coeff_mul_mem_ideal_of_coeff_right_mem_ideal' (fun i ↦ ?_) _ rw [map_sub] refine Ideal.sub_mem _ (h1 _) ?_ rw [pow_succ'] refine coeff_mul_mem_ideal_mul_ideal_of_coeff_mem_ideal' (fun i ↦ ?_) ih _ simp_rw [Polynomial.coeff_coe, g.coeff_trunc_order_mem] /-- If `g * q + r = g * q' + r'` for some power series `q`, `q'` and some polynomials `r`, `r'` whose degrees are `< n`, then `q = q'` and `r = r'` are all zero. This implies the uniqueness of Weierstrass division. -/ theorem eq_of_mul_add_eq_mul_add [IsHausdorff I A] {q q' : A⟦X⟧} {r r' : A[X]} (hr : r.degree < (g.map (Ideal.Quotient.mk I)).order.toNat) (hr' : r'.degree < (g.map (Ideal.Quotient.mk I)).order.toNat) (heq : g * q + r = g * q' + r') : q = q' ∧ r = r' := by replace heq : g * (q - q') = ↑(r' - r) := by rw [← eq_sub_iff_add_eq] at heq rw [Polynomial.coe_sub, mul_sub, heq] ring have h := H.eq_zero_of_mul_eq (lt_of_le_of_lt (r'.degree_sub_le r) (max_lt hr' hr)) heq simp_rw [sub_eq_zero] at h exact ⟨h.1, h.2.symm⟩ @[simp] theorem div_add [IsAdicComplete I A] : H.div (f + f') = H.div f + H.div f' := by have H1 := (H.isWeierstrassDivisionAt_div_mod f).add (H.isWeierstrassDivisionAt_div_mod f') have H2 := H.isWeierstrassDivisionAt_div_mod (f + f') exact (H.eq_of_mul_add_eq_mul_add H2.degree_lt H1.degree_lt (H2.eq_mul_add.symm.trans H1.eq_mul_add)).1 @[simp] theorem div_smul [IsAdicComplete I A] : H.div (a • f) = a • H.div f := by have H1 := (H.isWeierstrassDivisionAt_div_mod f).smul a have H2 := H.isWeierstrassDivisionAt_div_mod (a • f) exact (H.eq_of_mul_add_eq_mul_add H2.degree_lt H1.degree_lt (H2.eq_mul_add.symm.trans H1.eq_mul_add)).1 @[simp] theorem div_zero [IsAdicComplete I A] : H.div 0 = 0 := by simpa using H.div_smul 0 0 @[simp] theorem mod_add [IsAdicComplete I A] : H.mod (f + f') = H.mod f + H.mod f' := by have H1 := (H.isWeierstrassDivisionAt_div_mod f).add (H.isWeierstrassDivisionAt_div_mod f') have H2 := H.isWeierstrassDivisionAt_div_mod (f + f') exact (H.eq_of_mul_add_eq_mul_add H2.degree_lt H1.degree_lt (H2.eq_mul_add.symm.trans H1.eq_mul_add)).2 @[simp] theorem mod_smul [IsAdicComplete I A] : H.mod (a • f) = a • H.mod f := by have H1 := (H.isWeierstrassDivisionAt_div_mod f).smul a have H2 := H.isWeierstrassDivisionAt_div_mod (a • f) exact (H.eq_of_mul_add_eq_mul_add H2.degree_lt H1.degree_lt (H2.eq_mul_add.symm.trans H1.eq_mul_add)).2 @[simp] theorem mod_zero [IsAdicComplete I A] : H.mod 0 = 0 := by simpa using H.mod_smul 0 0 /-- The remainder map `PowerSeries.IsWeierstrassDivisorAt.mod` induces a linear map `A⟦X⟧ / (g) →ₗ[A] A[X]`. -/ noncomputable def mod' [IsAdicComplete I A] : A⟦X⟧ ⧸ Ideal.span {g} →ₗ[A] A[X] where toFun := Quotient.lift (fun f ↦ H.mod f) fun f f' hf ↦ by simp_rw [HasEquiv.Equiv, Submodule.quotientRel_def, Ideal.mem_span_singleton'] at hf obtain ⟨a, ha⟩ := hf obtain ⟨hf1, hf2⟩ := H.isWeierstrassDivisionAt_div_mod f obtain ⟨hf'1, hf'2⟩ := H.isWeierstrassDivisionAt_div_mod f' rw [eq_sub_iff_add_eq, hf2, hf'2, ← add_assoc, mul_comm, ← mul_add] at ha exact (H.eq_of_mul_add_eq_mul_add hf'1 hf1 ha).2.symm map_add' f f' := by obtain ⟨f, rfl⟩ := Ideal.Quotient.mk_surjective f obtain ⟨f', rfl⟩ := Ideal.Quotient.mk_surjective f' exact H.mod_add f f' map_smul' a f := by obtain ⟨f, rfl⟩ := Ideal.Quotient.mk_surjective f exact H.mod_smul a f @[simp] theorem mod'_mk_eq_mod [IsAdicComplete I A] {f : A⟦X⟧} : H.mod' (Ideal.Quotient.mk _ f) = H.mod f := rfl theorem div_coe_eq_zero [IsAdicComplete I A] {r : A[X]} (hr : r.degree < (g.map (Ideal.Quotient.mk I)).order.toNat) : H.div r = 0 := by obtain ⟨h1, h2⟩ := H.isWeierstrassDivisionAt_div_mod r exact (H.eq_of_mul_add_eq_mul_add (q := H.div r) (q' := 0) h1 hr (by simpa using h2.symm)).1 theorem mod_coe_eq_self [IsAdicComplete I A] {r : A[X]} (hr : r.degree < (g.map (Ideal.Quotient.mk I)).order.toNat) : H.mod r = r := by obtain ⟨h1, h2⟩ := H.isWeierstrassDivisionAt_div_mod r exact (H.eq_of_mul_add_eq_mul_add (q := H.div r) (q' := 0) h1 hr (by simpa using h2.symm)).2 @[simp] theorem mk_mod'_eq_self [IsAdicComplete I A] {f : A⟦X⟧ ⧸ Ideal.span {g}} : Ideal.Quotient.mk _ (H.mod' f : A⟦X⟧) = f := by obtain ⟨f, rfl⟩ := Ideal.Quotient.mk_surjective f rw [mod'_mk_eq_mod, Eq.comm, Ideal.Quotient.mk_eq_mk_iff_sub_mem, Ideal.mem_span_singleton'] use H.div f rw [eq_sub_iff_add_eq, mul_comm, (H.isWeierstrassDivisionAt_div_mod f).2.symm] end IsWeierstrassDivisorAt section Equiv variable {g : A[X]} {I : Ideal A} (H : g.IsDistinguishedAt I) [IsAdicComplete I A] include H /-- A distinguished polynomial `g` induces a natural isomorphism `A[X] / (g) ≃ₐ[A] A⟦X⟧ / (g)`. -/ @[simps! apply symm_apply] noncomputable def _root_.Polynomial.IsDistinguishedAt.algEquivQuotient : (A[X] ⧸ Ideal.span {g}) ≃ₐ[A] A⟦X⟧ ⧸ Ideal.span {(g : A⟦X⟧)} where __ := Ideal.quotientMapₐ _ (Polynomial.coeToPowerSeries.algHom A) fun a ha ↦ by obtain ⟨b, hb⟩ := Ideal.mem_span_singleton'.1 ha simp only [Ideal.mem_comap, Polynomial.coeToPowerSeries.algHom_apply, Algebra.algebraMap_self, map_id, id_eq, Ideal.mem_span_singleton'] exact ⟨b, by simp [← hb]⟩ invFun := Ideal.Quotient.mk _ ∘ H.isWeierstrassDivisorAt'.mod' left_inv f := by rcases subsingleton_or_nontrivial A with _ | _ · have : Subsingleton A[X] := inferInstance have : Subsingleton (A[X] ⧸ Ideal.span {g}) := Quot.Subsingleton exact Subsingleton.elim _ _ have hI : I ≠ ⊤ := by rintro rfl exact not_subsingleton _ ‹IsAdicComplete ⊤ A›.toIsHausdorff.subsingleton have := Ideal.Quotient.nontrivial hI obtain ⟨f, hfdeg, rfl⟩ : ∃ r : A[X], r.degree < g.degree ∧ Ideal.Quotient.mk _ r = f := by obtain ⟨f, rfl⟩ := Ideal.Quotient.mk_surjective f refine ⟨f %ₘ g, Polynomial.degree_modByMonic_lt f H.monic, ?_⟩ rw [Eq.comm, Ideal.Quotient.mk_eq_mk_iff_sub_mem, Ideal.mem_span_singleton'] exact ⟨f /ₘ g, by rw [Polynomial.modByMonic_eq_sub_mul_div _ H.monic]; ring⟩ have h1 : g.degree = ((g : A⟦X⟧).map (Ideal.Quotient.mk I)).order.toNat := by convert H.degree_eq_coe_lift_order_map g 1 (by rwa [constantCoeff_one, ← Ideal.ne_top_iff_one]) (by simp) exact (ENat.lift_eq_toNat_of_lt_top _).symm dsimp rw [Ideal.Quotient.mk_eq_mk_iff_sub_mem, Ideal.mem_span_singleton'] exact ⟨0, by simp [H.isWeierstrassDivisorAt'.mod_coe_eq_self (hfdeg.trans_eq h1)]⟩ right_inv f := by exact H.isWeierstrassDivisorAt'.mk_mod'_eq_self end Equiv end IsWeierstrassDivisorAt section IsLocalRing variable [IsLocalRing A] (a : A) (f f' g : A⟦X⟧) variable {g} in /-- **Weierstrass division** ([washington_cyclotomic], Proposition 7.2): let `f`, `g` be power series over a complete local ring, such that the image of `g` in the residue field is not zero. Let `n` be the order of the image of `g` in the residue field. Then there exists a power series `q` and a polynomial `r` of degree `< n`, such that `f = g * q + r`. -/ theorem exists_isWeierstrassDivision [IsAdicComplete (IsLocalRing.maximalIdeal A) A] (hg : g.map (IsLocalRing.residue A) ≠ 0) : ∃ q r, f.IsWeierstrassDivision g q r := ⟨_, _, (IsWeierstrassDivisor.of_map_ne_zero hg).isWeierstrassDivisionAt_div_mod f⟩ -- Unfortunately there is no Unicode subscript `w`. /-- The quotient `q` in Weierstrass division, denoted by `f /ʷ g`. Note that when the image of `g` in the residue field is zero, this is defined to be zero. -/ noncomputable def weierstrassDiv [IsPrecomplete (IsLocalRing.maximalIdeal A) A] : A⟦X⟧ := open scoped Classical in if hg : g.map (IsLocalRing.residue A) ≠ 0 then (IsWeierstrassDivisor.of_map_ne_zero hg).div f else 0 /-- The remainder `r` in Weierstrass division, denoted by `f %ʷ g`. Note that when the image of `g` in the residue field is zero, this is defined to be zero. -/ noncomputable def weierstrassMod [IsPrecomplete (IsLocalRing.maximalIdeal A) A] : A[X] := open scoped Classical in if hg : g.map (IsLocalRing.residue A) ≠ 0 then (IsWeierstrassDivisor.of_map_ne_zero hg).mod f else 0 @[inherit_doc] infixl:70 " /ʷ " => weierstrassDiv @[inherit_doc] infixl:70 " %ʷ " => weierstrassMod @[simp] theorem weierstrassDiv_zero_right [IsPrecomplete (IsLocalRing.maximalIdeal A) A] : f /ʷ 0 = 0 := by rw [weierstrassDiv, dif_neg (by simp)] alias weierstrassDiv_zero := weierstrassDiv_zero_right @[simp] theorem weierstrassMod_zero_right [IsPrecomplete (IsLocalRing.maximalIdeal A) A] : f %ʷ 0 = 0 := by rw [weierstrassMod, dif_neg (by simp)] alias weierstrassMod_zero := weierstrassMod_zero_right theorem degree_weierstrassMod_lt [IsPrecomplete (IsLocalRing.maximalIdeal A) A] : (f %ʷ g).degree < (g.map (IsLocalRing.residue A)).order.toNat := by rw [weierstrassMod] split_ifs with hg · exact degree_trunc_lt _ _ · nontriviality A rw [Polynomial.degree_zero] exact WithBot.bot_lt_coe _ section variable {g} (hg : g.map (IsLocalRing.residue A) ≠ 0) include hg theorem isWeierstrassDivision_weierstrassDiv_weierstrassMod [IsAdicComplete (IsLocalRing.maximalIdeal A) A] : f.IsWeierstrassDivision g (f /ʷ g) (f %ʷ g) := by simp_rw [weierstrassDiv, weierstrassMod, dif_pos hg] exact (IsWeierstrassDivisor.of_map_ne_zero hg).isWeierstrassDivisionAt_div_mod f theorem eq_mul_weierstrassDiv_add_weierstrassMod [IsAdicComplete (IsLocalRing.maximalIdeal A) A] : f = g * (f /ʷ g) + (f %ʷ g) := by simp_rw [weierstrassDiv, weierstrassMod, dif_pos hg] exact ((IsWeierstrassDivisor.of_map_ne_zero hg).isWeierstrassDivisionAt_div_mod f).2 variable {f} in /-- The quotient `q` and the remainder `r` in the Weierstrass division are unique. This result is stated using two `PowerSeries.IsWeierstrassDivision` assertions, and only requires the ring being Hausdorff with respect to the maximal ideal. If you want `q` and `r` equal to `f /ʷ g` and `f %ʷ g`, use `PowerSeries.IsWeierstrassDivision.unique` instead, which requires the ring being complete with respect to the maximal ideal. -/ theorem IsWeierstrassDivision.elim [IsHausdorff (IsLocalRing.maximalIdeal A) A] {q q' : A⟦X⟧} {r r' : A[X]} (H : f.IsWeierstrassDivision g q r) (H2 : f.IsWeierstrassDivision g q' r') : q = q' ∧ r = r' := (IsWeierstrassDivisor.of_map_ne_zero hg).eq_of_mul_add_eq_mul_add H.1 H2.1 (H.2.symm.trans H2.2) /-- If `q` and `r` are quotient and remainder in the Weierstrass division `0 / g`, then they are equal to `0`. -/ theorem IsWeierstrassDivision.eq_zero [IsHausdorff (IsLocalRing.maximalIdeal A) A] {q : A⟦X⟧} {r : A[X]} (H : IsWeierstrassDivision 0 g q r) : q = 0 ∧ r = 0 := H.elim hg (g.isWeierstrassDivisionAt_zero _) variable {f} in /-- If `q` and `r` are quotient and remainder in the Weierstrass division `f / g`, then they are equal to `f /ʷ g` and `f %ʷ g`. -/ theorem IsWeierstrassDivision.unique [IsAdicComplete (IsLocalRing.maximalIdeal A) A] {q : A⟦X⟧} {r : A[X]} (H : f.IsWeierstrassDivision g q r) : q = f /ʷ g ∧ r = f %ʷ g := H.elim hg (f.isWeierstrassDivision_weierstrassDiv_weierstrassMod hg) end @[simp] theorem add_weierstrassDiv [IsAdicComplete (IsLocalRing.maximalIdeal A) A] : (f + f') /ʷ g = f /ʷ g + f' /ʷ g := by simp_rw [weierstrassDiv] split_ifs <;> simp @[simp] theorem smul_weierstrassDiv [IsAdicComplete (IsLocalRing.maximalIdeal A) A] : (a • f) /ʷ g = a • (f /ʷ g) := by simp_rw [weierstrassDiv] split_ifs <;> simp @[simp] theorem weierstrassDiv_zero_left [IsAdicComplete (IsLocalRing.maximalIdeal A) A] : 0 /ʷ g = 0 := by simp_rw [weierstrassDiv] split_ifs <;> simp alias zero_weierstrassDiv := weierstrassDiv_zero_left @[simp] theorem add_weierstrassMod [IsAdicComplete (IsLocalRing.maximalIdeal A) A] : (f + f') %ʷ g = f %ʷ g + f' %ʷ g := by simp_rw [weierstrassMod] split_ifs <;> simp @[simp] theorem smul_weierstrassMod [IsAdicComplete (IsLocalRing.maximalIdeal A) A] : (a • f) %ʷ g = a • (f %ʷ g) := by simp_rw [weierstrassMod] split_ifs <;> simp @[simp] theorem weierstrassMod_zero_left [IsAdicComplete (IsLocalRing.maximalIdeal A) A] : 0 %ʷ g = 0 := by simp_rw [weierstrassMod] split_ifs <;> simp alias zero_weierstrassMod := weierstrassMod_zero_left end IsLocalRing /-! ## Weierstrass preparation theorem -/ /-- If `f` is a polynomial over `A`, `g` and `h` are power series over `A`, then `PowerSeries.IsWeierstrassFactorizationAt g f h I` is a `Prop` which asserts that `f` is distinguished at `I`, `h` is a unit, such that `g = f * h`. -/ @[mk_iff] structure IsWeierstrassFactorizationAt (g : A⟦X⟧) (f : A[X]) (h : A⟦X⟧) (I : Ideal A) : Prop where isDistinguishedAt : f.IsDistinguishedAt I isUnit : IsUnit h eq_mul : g = f * h /-- Version of `PowerSeries.IsWeierstrassFactorizationAt` for local rings with respect to its maximal ideal. -/ abbrev IsWeierstrassFactorization (g : A⟦X⟧) (f : A[X]) (h : A⟦X⟧) [IsLocalRing A] : Prop := g.IsWeierstrassFactorizationAt f h (IsLocalRing.maximalIdeal A) namespace IsWeierstrassFactorizationAt variable {g : A⟦X⟧} {f : A[X]} {h : A⟦X⟧} {I : Ideal A} (H : g.IsWeierstrassFactorizationAt f h I) include H theorem map_ne_zero_of_ne_top (hI : I ≠ ⊤) : g.map (Ideal.Quotient.mk I) ≠ 0 := by have := Ideal.Quotient.nontrivial hI rw [congr(map (Ideal.Quotient.mk I) $(H.eq_mul)), map_mul, ← Polynomial.polynomial_map_coe, ne_eq, (H.isUnit.map _).mul_left_eq_zero] exact_mod_cast f.map_monic_ne_zero (f := Ideal.Quotient.mk I) H.isDistinguishedAt.monic theorem degree_eq_coe_lift_order_map_of_ne_top (hI : I ≠ ⊤) : f.degree = (g.map (Ideal.Quotient.mk I)).order.lift (order_finite_iff_ne_zero.2 (H.map_ne_zero_of_ne_top hI)) := by refine H.isDistinguishedAt.degree_eq_coe_lift_order_map g h ?_ H.eq_mul contrapose! hI exact Ideal.eq_top_of_isUnit_mem _ hI (isUnit_iff_constantCoeff.1 H.isUnit) theorem natDegree_eq_toNat_order_map_of_ne_top (hI : I ≠ ⊤) : f.natDegree = (g.map (Ideal.Quotient.mk I)).order.toNat := by rw [Polynomial.natDegree, H.degree_eq_coe_lift_order_map_of_ne_top hI, ENat.lift_eq_toNat_of_lt_top] exact WithBot.unbotD_coe _ _ /-- If `g = f * h` is a Weierstrass factorization, then there is a natural isomorphism `A[X] / (f) ≃ₐ[A] A⟦X⟧ / (g)`. -/ @[simps! apply] noncomputable def algEquivQuotient [IsAdicComplete I A] : (A[X] ⧸ Ideal.span {f}) ≃ₐ[A] A⟦X⟧ ⧸ Ideal.span {g} := H.isDistinguishedAt.algEquivQuotient.trans <| Ideal.quotientEquivAlgOfEq A <| by rw [H.eq_mul, Ideal.span_singleton_mul_right_unit H.isUnit] @[simp] theorem algEquivQuotient_symm_apply [IsAdicComplete I A] (x : A⟦X⟧ ⧸ Ideal.span {g}) : H.algEquivQuotient.symm x = Ideal.Quotient.mk _ (H.isDistinguishedAt.isWeierstrassDivisorAt'.mod' <| Ideal.quotientEquivAlgOfEq A (by rw [H.eq_mul, Ideal.span_singleton_mul_right_unit H.isUnit]) x) := by simp [algEquivQuotient] theorem mul {g' : A⟦X⟧} {f' : A[X]} {h' : A⟦X⟧} (H' : g'.IsWeierstrassFactorizationAt f' h' I) : (g * g').IsWeierstrassFactorizationAt (f * f') (h * h') I := ⟨H.isDistinguishedAt.mul H'.isDistinguishedAt, H.isUnit.mul H'.isUnit, by rw [H.eq_mul, H'.eq_mul, Polynomial.coe_mul]; ring⟩ theorem smul {a : A} (ha : IsUnit a) : (a • g).IsWeierstrassFactorizationAt f (a • h) I := by refine ⟨H.isDistinguishedAt, ?_, ?_⟩ · rw [Algebra.smul_def] exact (ha.map _).mul H.isUnit · simp [H.eq_mul] end IsWeierstrassFactorizationAt variable [IsLocalRing A] namespace IsWeierstrassFactorization variable {g : A⟦X⟧} {f : A[X]} {h : A⟦X⟧} (H : g.IsWeierstrassFactorization f h) include H theorem map_ne_zero : g.map (IsLocalRing.residue A) ≠ 0 := H.map_ne_zero_of_ne_top (Ideal.IsMaximal.ne_top inferInstance) theorem degree_eq_coe_lift_order_map : f.degree = (g.map (IsLocalRing.residue A)).order.lift (order_finite_iff_ne_zero.2 H.map_ne_zero) := H.degree_eq_coe_lift_order_map_of_ne_top (Ideal.IsMaximal.ne_top inferInstance) theorem natDegree_eq_toNat_order_map : f.natDegree = (g.map (IsLocalRing.residue A)).order.toNat := H.natDegree_eq_toNat_order_map_of_ne_top (Ideal.IsMaximal.ne_top inferInstance) end IsWeierstrassFactorization theorem IsWeierstrassDivision.isUnit_of_map_ne_zero {g q : A⟦X⟧} {r : A[X]} (hg : g.map (IsLocalRing.residue A) ≠ 0) (H : (X ^ (g.map (IsLocalRing.residue A)).order.toNat).IsWeierstrassDivision g q r) : IsUnit q := by obtain ⟨H1 : r.degree < (g.map (IsLocalRing.residue A)).order.toNat, H2⟩ := H set n := (g.map (IsLocalRing.residue A)).order.toNat replace H2 := congr(coeff n (($H2).map (IsLocalRing.residue A))) simp_rw [map_pow, map_X, coeff_X_pow_self, map_add, map_mul, coeff_map, Polynomial.coeff_coe, Polynomial.coeff_eq_zero_of_degree_lt H1, map_zero, add_zero] at H2 rw [isUnit_iff_constantCoeff, ← isUnit_map_iff (IsLocalRing.residue A)] rw [coeff_mul, ← Finset.sum_subset (s₁ := {(n, 0)}) (by simp) (fun p hp hnotMem ↦ ?_), Finset.sum_singleton, coeff_map, coeff_map, coeff_zero_eq_constantCoeff, mul_comm] at H2 · exact .of_mul_eq_one _ H2.symm · rw [coeff_of_lt_order p.1 ?_] · rw [zero_mul] · rw [← ENat.lt_lift_iff (h := order_finite_iff_ne_zero.2 hg), ENat.lift_eq_toNat_of_lt_top] refine (Finset.antidiagonal.fst_le hp).lt_of_ne ?_ contrapose! hnotMem rwa [Finset.mem_singleton, Finset.antidiagonal_congr hp (by simp)] theorem IsWeierstrassDivision.isWeierstrassFactorization {g q : A⟦X⟧} {r : A[X]} (hg : g.map (IsLocalRing.residue A) ≠ 0) (H : (X ^ (g.map (IsLocalRing.residue A)).order.toNat).IsWeierstrassDivision g q r) : g.IsWeierstrassFactorization (Polynomial.X ^ (g.map (IsLocalRing.residue A)).order.toNat - r) ↑(H.isUnit_of_map_ne_zero hg).unit⁻¹ := by have H1 : r.degree < (g.map (IsLocalRing.residue A)).order.toNat := H.1 set n := (g.map (IsLocalRing.residue A)).order.toNat set f := Polynomial.X ^ n - r replace H1 : r.degree < (Polynomial.X (R := A) ^ n).degree := by rwa [Polynomial.degree_X_pow] have hfdeg : f.natDegree = n := by suffices f.degree = n by rw [Polynomial.natDegree, this]; rfl rw [Polynomial.degree_sub_eq_left_of_degree_lt H1, Polynomial.degree_X_pow] refine ⟨⟨⟨fun {i} hi ↦ ?_⟩, .sub_of_left (Polynomial.monic_X_pow _) H1⟩, Units.isUnit _, ?_⟩ · rw [hfdeg] at hi simp_rw [f, Polynomial.coeff_sub, Polynomial.coeff_X_pow, if_neg hi.ne, zero_sub, neg_mem_iff] have := H.coeff_f_sub_r_mem hi rwa [map_sub, coeff_X_pow, if_neg hi.ne, zero_sub, neg_mem_iff, Polynomial.coeff_coe] at this · have := congr($(H.2) * ↑(H.isUnit_of_map_ne_zero hg).unit⁻¹) rw [add_mul, mul_assoc, IsUnit.mul_val_inv, mul_one, ← sub_eq_iff_eq_add] at this simp_rw [← this, f, Polynomial.coe_sub, Polynomial.coe_pow, Polynomial.coe_X, sub_mul] theorem IsWeierstrassFactorization.isWeierstrassDivision {g : A⟦X⟧} {f : A[X]} {h : A⟦X⟧} (H : g.IsWeierstrassFactorization f h) : (X ^ (g.map (IsLocalRing.residue A)).order.toNat).IsWeierstrassDivision g ↑H.isUnit.unit⁻¹ (Polynomial.X ^ (g.map (IsLocalRing.residue A)).order.toNat - f) := by set n := (g.map (IsLocalRing.residue A)).order.toNat with hn constructor · refine (Polynomial.degree_sub_lt ?_ (Polynomial.monic_X_pow n).ne_zero ?_).trans_eq (by simpa) · simp_rw [H.degree_eq_coe_lift_order_map, Polynomial.degree_X_pow, n, ENat.lift_eq_toNat_of_lt_top] · rw [(Polynomial.monic_X_pow n).leadingCoeff, H.isDistinguishedAt.monic.leadingCoeff] · simp_rw [H.eq_mul, mul_assoc, IsUnit.mul_val_inv, mul_one, Polynomial.coe_sub, Polynomial.coe_pow, Polynomial.coe_X, add_sub_cancel] /-- The `f` and `h` in the Weierstrass preparation theorem are unique. This result is stated using two `PowerSeries.IsWeierstrassFactorization` assertions, and only requires the ring being Hausdorff with respect to the maximal ideal. If you want `f` and `h` equal to `PowerSeries.weierstrassDistinguished` and `PowerSeries.weierstrassUnit`, use `PowerSeries.IsWeierstrassFactorization.unique` instead, which requires the ring being complete with respect to the maximal ideal. -/ theorem IsWeierstrassFactorization.elim [IsHausdorff (IsLocalRing.maximalIdeal A) A] {g : A⟦X⟧} {f f' : A[X]} {h h' : A⟦X⟧} (H : g.IsWeierstrassFactorization f h) (H2 : g.IsWeierstrassFactorization f' h') : f = f' ∧ h = h' := by obtain ⟨h1, h2⟩ := H.isWeierstrassDivision.elim H.map_ne_zero H2.isWeierstrassDivision rw [← Units.ext_iff, inv_inj, Units.ext_iff] at h1 exact ⟨by simpa using h2, h1⟩ section IsAdicComplete variable [IsAdicComplete (IsLocalRing.maximalIdeal A) A] {a : A} {g g' : A⟦X⟧} {f : A[X]} {h : A⟦X⟧} /-- **Weierstrass preparation theorem** ([washington_cyclotomic], Theorem 7.3): let `g` be a power series over a complete local ring, such that its image in the residue field is not zero. Then there exists a distinguished polynomial `f` and a power series `h` which is a unit, such that `g = f * h`. -/ theorem exists_isWeierstrassFactorization (hg : g.map (IsLocalRing.residue A) ≠ 0) : ∃ f h, g.IsWeierstrassFactorization f h := by obtain ⟨q, r, H⟩ := (X ^ (g.map (IsLocalRing.residue A)).order.toNat).exists_isWeierstrassDivision hg exact ⟨_, _, H.isWeierstrassFactorization hg⟩ variable (g) in /-- The `f` in the Weierstrass preparation theorem. -/ noncomputable def weierstrassDistinguished (hg : g.map (IsLocalRing.residue A) ≠ 0) : A[X] := (g.exists_isWeierstrassFactorization hg).choose variable (g) in /-- The `h` in the Weierstrass preparation theorem. -/ noncomputable def weierstrassUnit (hg : g.map (IsLocalRing.residue A) ≠ 0) : A⟦X⟧ := (g.exists_isWeierstrassFactorization hg).choose_spec.choose theorem isWeierstrassFactorization_weierstrassDistinguished_weierstrassUnit (hg : g.map (IsLocalRing.residue A) ≠ 0) : g.IsWeierstrassFactorization (g.weierstrassDistinguished hg) (g.weierstrassUnit hg) := (g.exists_isWeierstrassFactorization hg).choose_spec.choose_spec /-- If `g` is a power series over a complete local ring, such that its image in the residue field is not zero, then there is a natural isomorphism `A[X] / (f) ≃ₐ[A] A⟦X⟧ / (g)` where `f` is `PowerSeries.weierstrassDistinguished g`. -/ noncomputable abbrev algEquivQuotientWeierstrassDistinguished (hg : g.map (IsLocalRing.residue A) ≠ 0) := (g.isWeierstrassFactorization_weierstrassDistinguished_weierstrassUnit hg).algEquivQuotient theorem isDistinguishedAt_weierstrassDistinguished (hg : g.map (IsLocalRing.residue A) ≠ 0) : (g.weierstrassDistinguished hg).IsDistinguishedAt (IsLocalRing.maximalIdeal A) := (g.exists_isWeierstrassFactorization hg).choose_spec.choose_spec.isDistinguishedAt theorem isUnit_weierstrassUnit (hg : g.map (IsLocalRing.residue A) ≠ 0) : IsUnit (g.weierstrassUnit hg) := (g.exists_isWeierstrassFactorization hg).choose_spec.choose_spec.isUnit theorem eq_weierstrassDistinguished_mul_weierstrassUnit (hg : g.map (IsLocalRing.residue A) ≠ 0) : g = g.weierstrassDistinguished hg * g.weierstrassUnit hg := (g.exists_isWeierstrassFactorization hg).choose_spec.choose_spec.eq_mul /-- The `f` and `h` in Weierstrass preparation theorem are equal to `PowerSeries.weierstrassDistinguished` and `PowerSeries.weierstrassUnit`. -/ theorem IsWeierstrassFactorization.unique (H : g.IsWeierstrassFactorization f h) (hg : g.map (IsLocalRing.residue A) ≠ 0) : f = g.weierstrassDistinguished hg ∧ h = g.weierstrassUnit hg := H.elim (g.isWeierstrassFactorization_weierstrassDistinguished_weierstrassUnit hg) @[simp] theorem weierstrassDistinguished_mul (hg : (g * g').map (IsLocalRing.residue A) ≠ 0) : (g * g').weierstrassDistinguished hg = g.weierstrassDistinguished (fun h ↦ hg (by simp [h])) * g'.weierstrassDistinguished (fun h ↦ hg (by simp [h])) := by have H := g.isWeierstrassFactorization_weierstrassDistinguished_weierstrassUnit (fun h ↦ hg (by simp [h])) have H' := g'.isWeierstrassFactorization_weierstrassDistinguished_weierstrassUnit (fun h ↦ hg (by simp [h])) have H'' := (g * g').isWeierstrassFactorization_weierstrassDistinguished_weierstrassUnit hg exact (H''.elim (H.mul H')).1 @[simp] theorem weierstrassUnit_mul (hg : (g * g').map (IsLocalRing.residue A) ≠ 0) : (g * g').weierstrassUnit hg = g.weierstrassUnit (fun h ↦ hg (by simp [h])) * g'.weierstrassUnit (fun h ↦ hg (by simp [h])) := by have H := g.isWeierstrassFactorization_weierstrassDistinguished_weierstrassUnit (fun h ↦ hg (by simp [h])) have H' := g'.isWeierstrassFactorization_weierstrassDistinguished_weierstrassUnit (fun h ↦ hg (by simp [h])) have H'' := (g * g').isWeierstrassFactorization_weierstrassDistinguished_weierstrassUnit hg exact (H''.elim (H.mul H')).2 @[simp] theorem weierstrassDistinguished_smul (hg : (a • g).map (IsLocalRing.residue A) ≠ 0) : (a • g).weierstrassDistinguished hg = g.weierstrassDistinguished (fun h ↦ hg (by simp [Algebra.smul_def, h])) := by have H := g.isWeierstrassFactorization_weierstrassDistinguished_weierstrassUnit (fun h ↦ hg (by simp [Algebra.smul_def, h])) have H' := (a • g).isWeierstrassFactorization_weierstrassDistinguished_weierstrassUnit hg have ha : IsLocalRing.residue A a ≠ 0 := fun h ↦ hg (by simp [Algebra.smul_def, h]) exact (H'.elim (H.smul (by simpa using ha))).1 @[simp] theorem weierstrassUnit_smul (hg : (a • g).map (IsLocalRing.residue A) ≠ 0) : (a • g).weierstrassUnit hg = a • g.weierstrassUnit (fun h ↦ hg (by simp [Algebra.smul_def, h])) := by have H := g.isWeierstrassFactorization_weierstrassDistinguished_weierstrassUnit (fun h ↦ hg (by simp [Algebra.smul_def, h])) have H' := (a • g).isWeierstrassFactorization_weierstrassDistinguished_weierstrassUnit hg have ha : IsLocalRing.residue A a ≠ 0 := fun h ↦ hg (by simp [Algebra.smul_def, h]) exact (H'.elim (H.smul (by simpa using ha))).2 end IsAdicComplete end PowerSeries
.lake/packages/mathlib/Mathlib/RingTheory/PowerSeries/Derivative.lean
import Mathlib.RingTheory.PowerSeries.Trunc import Mathlib.RingTheory.PowerSeries.Inverse import Mathlib.RingTheory.Derivation.Basic /-! # Definitions In this file we define an operation `derivative` (formal differentiation) on the ring of formal power series in one variable (over an arbitrary commutative semiring). Under suitable assumptions, we prove that two power series are equal if their derivatives are equal and their constant terms are equal. This will give us a simple tool for proving power series identities. For example, one can easily prove the power series identity $\exp ( \log (1+X)) = 1+X$ by differentiating twice. ## Main Definition - `PowerSeries.derivative R : Derivation R R⟦X⟧ R⟦X⟧` the formal derivative operation. This is abbreviated `d⁄dX R`. -/ namespace PowerSeries open Polynomial Derivation Nat section CommutativeSemiring variable {R} [CommSemiring R] /-- The formal derivative of a power series in one variable. This is defined here as a function, but will be packaged as a derivation `derivative` on `R⟦X⟧`. -/ noncomputable def derivativeFun (f : R⟦X⟧) : R⟦X⟧ := mk fun n ↦ coeff (n + 1) f * (n + 1) theorem coeff_derivativeFun (f : R⟦X⟧) (n : ℕ) : coeff n f.derivativeFun = coeff (n + 1) f * (n + 1) := by rw [derivativeFun, coeff_mk] theorem derivativeFun_coe (f : R[X]) : (f : R⟦X⟧).derivativeFun = derivative f := by ext rw [coeff_derivativeFun, coeff_coe, coeff_coe, coeff_derivative] theorem derivativeFun_add (f g : R⟦X⟧) : derivativeFun (f + g) = derivativeFun f + derivativeFun g := by ext rw [coeff_derivativeFun, map_add, map_add, coeff_derivativeFun, coeff_derivativeFun, add_mul] theorem derivativeFun_C (r : R) : derivativeFun (C r) = 0 := by ext n -- Note that `map_zero` didn't get picked up, apparently due to a missing `FunLike.coe` rw [coeff_derivativeFun, coeff_succ_C, zero_mul, (coeff n).map_zero] theorem trunc_derivativeFun (f : R⟦X⟧) (n : ℕ) : trunc n f.derivativeFun = derivative (trunc (n + 1) f) := by ext d rw [coeff_trunc] split_ifs with h · have : d + 1 < n + 1 := succ_lt_succ_iff.2 h rw [coeff_derivativeFun, coeff_derivative, coeff_trunc, if_pos this] · have : ¬d + 1 < n + 1 := by rwa [succ_lt_succ_iff] rw [coeff_derivative, coeff_trunc, if_neg this, zero_mul] --A special case of `derivativeFun_mul`, used in its proof. private theorem derivativeFun_coe_mul_coe (f g : R[X]) : derivativeFun (f * g : R⟦X⟧) = f * derivative g + g * derivative f := by rw [← coe_mul, derivativeFun_coe, derivative_mul, add_comm, mul_comm _ g, ← coe_mul, ← coe_mul, Polynomial.coe_add] /-- **Leibniz rule for formal power series**. -/ theorem derivativeFun_mul (f g : R⟦X⟧) : derivativeFun (f * g) = f • g.derivativeFun + g • f.derivativeFun := by ext n have h₁ : n < n + 1 := lt_succ_self n have h₂ : n < n + 1 + 1 := Nat.lt_add_right _ h₁ rw [coeff_derivativeFun, map_add, coeff_mul_eq_coeff_trunc_mul_trunc _ _ (lt_succ_self _), smul_eq_mul, smul_eq_mul, coeff_mul_eq_coeff_trunc_mul_trunc₂ g f.derivativeFun h₂ h₁, coeff_mul_eq_coeff_trunc_mul_trunc₂ f g.derivativeFun h₂ h₁, trunc_derivativeFun, trunc_derivativeFun, ← map_add, ← derivativeFun_coe_mul_coe, coeff_derivativeFun] theorem derivativeFun_one : derivativeFun (1 : R⟦X⟧) = 0 := by rw [← map_one C, derivativeFun_C (1 : R)] theorem derivativeFun_smul (r : R) (f : R⟦X⟧) : derivativeFun (r • f) = r • derivativeFun f := by rw [smul_eq_C_mul, smul_eq_C_mul, derivativeFun_mul, derivativeFun_C, smul_zero, add_zero, smul_eq_mul] variable (R) /-- The formal derivative of a formal power series -/ noncomputable def derivative : Derivation R R⟦X⟧ R⟦X⟧ where toFun := derivativeFun map_add' := derivativeFun_add map_smul' := derivativeFun_smul map_one_eq_zero' := derivativeFun_one leibniz' := derivativeFun_mul /-- Abbreviation of `PowerSeries.derivative`, the formal derivative on `R⟦X⟧` -/ scoped notation "d⁄dX" => derivative variable {R} @[simp] theorem derivative_C (r : R) : d⁄dX R (C r) = 0 := derivativeFun_C r theorem coeff_derivative (f : R⟦X⟧) (n : ℕ) : coeff n (d⁄dX R f) = coeff (n + 1) f * (n + 1) := coeff_derivativeFun f n theorem derivative_coe (f : R[X]) : d⁄dX R f = Polynomial.derivative f := derivativeFun_coe f @[simp] theorem derivative_X : d⁄dX R (X : R⟦X⟧) = 1 := by ext rw [coeff_derivative, coeff_one, coeff_X, boole_mul] simp_rw [add_eq_right] split_ifs with h · rw [h, cast_zero, zero_add] · rfl theorem trunc_derivative (f : R⟦X⟧) (n : ℕ) : trunc n (d⁄dX R f) = Polynomial.derivative (trunc (n + 1) f) := trunc_derivativeFun .. theorem trunc_derivative' (f : R⟦X⟧) (n : ℕ) : trunc (n - 1) (d⁄dX R f) = Polynomial.derivative (trunc n f) := by cases n with | zero => simp | succ n => rw [succ_sub_one, trunc_derivative] end CommutativeSemiring /- In the next lemma, we use `smul_right_inj`, which requires not only `IsAddTorsionFree R`, but also cancellation of addition in `R`. For this reason, the next lemma is stated in the case that `R` is a `CommRing`. -/ /-- If `f` and `g` have the same constant term and derivative, then they are equal. -/ theorem derivative.ext {R} [CommRing R] [IsAddTorsionFree R] {f g} (hD : d⁄dX R f = d⁄dX R g) (hc : constantCoeff f = constantCoeff g) : f = g := by ext n cases n with | zero => rw [coeff_zero_eq_constantCoeff, hc] | succ n => have equ : coeff n (d⁄dX R f) = coeff n (d⁄dX R g) := by rw [hD] rwa [coeff_derivative, coeff_derivative, ← cast_succ, mul_comm, ← nsmul_eq_mul, mul_comm, ← nsmul_eq_mul, smul_right_inj n.succ_ne_zero] at equ @[simp] theorem derivative_inv {R} [CommRing R] (f : R⟦X⟧ˣ) : d⁄dX R ↑f⁻¹ = -(↑f⁻¹ : R⟦X⟧) ^ 2 * d⁄dX R f := by apply Derivation.leibniz_of_mul_eq_one simp @[simp] theorem derivative_invOf {R} [CommRing R] (f : R⟦X⟧) [Invertible f] : d⁄dX R ⅟f = -⅟f ^ 2 * d⁄dX R f := by rw [Derivation.leibniz_invOf, smul_eq_mul] /- The following theorem is stated only in the case that `R` is a field. This is because there is currently no instance of `Inv R⟦X⟧` for more general base rings `R`. -/ @[simp] theorem derivative_inv' {R} [Field R] (f : R⟦X⟧) : d⁄dX R f⁻¹ = -f⁻¹ ^ 2 * d⁄dX R f := by by_cases h : constantCoeff f = 0 · suffices f⁻¹ = 0 by rw [this, pow_two, zero_mul, neg_zero, zero_mul, map_zero] rwa [MvPowerSeries.inv_eq_zero] apply Derivation.leibniz_of_mul_eq_one exact PowerSeries.inv_mul_cancel (h := h) end PowerSeries
.lake/packages/mathlib/Mathlib/RingTheory/PowerSeries/CoeffMulMem.lean
import Mathlib.RingTheory.Ideal.Operations import Mathlib.RingTheory.Ideal.BigOperators import Mathlib.RingTheory.PowerSeries.Basic /-! # Some results on the coefficients of multiplication of two power series ## Main results - `PowerSeries.coeff_mul_mem_ideal_mul_ideal_of_coeff_mem_ideal`, `PowerSeries.coeff_mul_mem_ideal_mul_ideal_of_coeff_mem_ideal'`: if for all `i ≤ n` (resp. for all `i`), the `i`-th coefficients of power series `f` and `g` are in ideals `I` and `J`, respectively, then for all `i ≤ n` (resp. for all `i`), the `i`-th coefficients of `f * g` are in `I * J`. - `PowerSeries.coeff_mul_mem_ideal_of_coeff_right_mem_ideal`, `PowerSeries.coeff_mul_mem_ideal_of_coeff_right_mem_ideal'`: if for all `i ≤ n` (resp. for all `i`), the `i`-th coefficients of power series `g` are in ideal `I`, then for all `i ≤ n` (resp. for all `i`), the `i`-th coefficients of `f * g` are in `I`. - `PowerSeries.coeff_mul_mem_ideal_of_coeff_left_mem_ideal`, `PowerSeries.coeff_mul_mem_ideal_of_coeff_left_mem_ideal'`: if for all `i ≤ n` (resp. for all `i`), the `i`-th coefficients of power series `f` are in ideal `I`, then for all `i ≤ n` (resp. for all `i`), the `i`-th coefficients of `f * g` are in `I`. -/ namespace PowerSeries variable {A : Type*} [Semiring A] {I J : Ideal A} {f g : A⟦X⟧} (n : ℕ) theorem coeff_mul_mem_ideal_mul_ideal_of_coeff_mem_ideal (hf : ∀ i ≤ n, coeff i f ∈ I) (hg : ∀ i ≤ n, coeff i g ∈ J) : ∀ i ≤ n, coeff i (f * g) ∈ I * J := fun i hi ↦ by rw [coeff_mul] exact Ideal.sum_mem _ fun p hp ↦ Ideal.mul_mem_mul (hf _ ((Finset.antidiagonal.fst_le hp).trans hi)) (hg _ ((Finset.antidiagonal.snd_le hp).trans hi)) theorem coeff_mul_mem_ideal_mul_ideal_of_coeff_mem_ideal' (hf : ∀ i, coeff i f ∈ I) (hg : ∀ i, coeff i g ∈ J) : ∀ i, coeff i (f * g) ∈ I * J := fun i ↦ coeff_mul_mem_ideal_mul_ideal_of_coeff_mem_ideal i (fun i _ ↦ hf i) (fun i _ ↦ hg i) i le_rfl theorem coeff_mul_mem_ideal_of_coeff_right_mem_ideal (hg : ∀ i ≤ n, coeff i g ∈ I) : ∀ i ≤ n, coeff i (f * g) ∈ I := by simpa using coeff_mul_mem_ideal_mul_ideal_of_coeff_mem_ideal (I := ⊤) (f := f) n (by simp) hg theorem coeff_mul_mem_ideal_of_coeff_right_mem_ideal' (hg : ∀ i, coeff i g ∈ I) : ∀ i, coeff i (f * g) ∈ I := by simpa using coeff_mul_mem_ideal_mul_ideal_of_coeff_mem_ideal' (I := ⊤) (f := f) (by simp) hg variable [I.IsTwoSided] theorem coeff_mul_mem_ideal_of_coeff_left_mem_ideal (hf : ∀ i ≤ n, coeff i f ∈ I) : ∀ i ≤ n, coeff i (f * g) ∈ I := by simpa only [Ideal.IsTwoSided.mul_one] using coeff_mul_mem_ideal_mul_ideal_of_coeff_mem_ideal (J := 1) (g := g) n hf (by simp) theorem coeff_mul_mem_ideal_of_coeff_left_mem_ideal' (hf : ∀ i, coeff i f ∈ I) : ∀ i, coeff i (f * g) ∈ I := by simpa only [Ideal.IsTwoSided.mul_one] using coeff_mul_mem_ideal_mul_ideal_of_coeff_mem_ideal' (J := 1) (g := g) hf (by simp) end PowerSeries
.lake/packages/mathlib/Mathlib/RingTheory/PowerSeries/GaussNorm.lean
import Mathlib.Data.Real.Archimedean import Mathlib.RingTheory.PowerSeries.Order /-! # Gauss norm for power series This file defines the Gauss norm for power series. Given a power series `f` in `R⟦X⟧`, a function `v : R → ℝ` and a real number `c`, the Gauss norm is defined as the supremum of the set of all values of `v (f.coeff i) * c ^ i` for all `i : ℕ`. In case `f` is a polynomial, `v` is a non-negative function with `v 0 = 0` and `c ≥ 0`, `f.gaussNorm v c` reduces to the Gauss norm defined in `Mathlib/RingTheory/Polynomial/GaussNorm.lean`, see `Polynomial.gaussNorm_coe_powerSeries`. ## Main Definitions and Results * `PowerSeries.gaussNorm` is the supremum of the set of all values of `v (f.coeff i) * c ^ i` for all `i : ℕ`, where `f` is a power series in `R⟦X⟧`, `v : R → ℝ` is a function and `c` is a real number. * `PowerSeries.gaussNorm_nonneg`: if `v` is a non-negative function, then the Gauss norm is non-negative. * `PowerSeries.gaussNorm_eq_zero_iff`: if `v` is a non-negative function and `v x = 0 ↔ x = 0` for all `x : R` and `c` is positive, then the Gauss norm is zero if and only if the power series is zero. -/ namespace PowerSeries variable {R F : Type*} [Semiring R] [FunLike F R ℝ] (v : F) (c : ℝ) (f : R⟦X⟧) /-- Given a power series `f` in `R⟦X⟧`, a function `v : R → ℝ` and a real number `c`, the Gauss norm is defined as the supremum of the set of all values of `v (f.coeff i) * c ^ i` for all `i : ℕ`. -/ noncomputable def gaussNorm : ℝ := ⨆ i : ℕ, v (f.coeff i) * c ^ i lemma le_gaussNorm (hbd : BddAbove {x | ∃ i, v (f.coeff i) * c ^ i = x}) (i : ℕ) : v (f.coeff i) * c ^ i ≤ f.gaussNorm v c := le_ciSup hbd i @[simp] theorem gaussNorm_zero [ZeroHomClass F R ℝ] : gaussNorm v c 0 = 0 := by simp [gaussNorm] theorem gaussNorm_nonneg [NonnegHomClass F R ℝ] : 0 ≤ f.gaussNorm v c := by by_cases h : BddAbove (Set.range fun i ↦ v (f.coeff i) * c ^ i) · calc 0 ≤ v (f.coeff 0) * c ^ 0 := mul_nonneg (apply_nonneg v (f.coeff 0)) <| pow_nonneg (le_of_lt (zero_lt_one)) 0 _ ≤ f.gaussNorm v c := le_ciSup h 0 · simp [gaussNorm, h] @[simp] theorem gaussNorm_eq_zero_iff [ZeroHomClass F R ℝ] [NonnegHomClass F R ℝ] {v : F} (h_eq_zero : ∀ x : R, v x = 0 → x = 0) {f : R⟦X⟧} {c : ℝ} (hc : 0 < c) (hbd : BddAbove (Set.range fun i ↦ v (f.coeff i) * c ^ i)) : f.gaussNorm v c = 0 ↔ f = 0 := by refine ⟨?_, fun hf ↦ by simp [hf]⟩ contrapose! intro hf apply ne_of_gt obtain ⟨n, hn⟩ := exists_coeff_ne_zero_iff_ne_zero.mpr hf calc 0 < v (f.coeff n) * c ^ n := by have := fun h ↦ hn (h_eq_zero (coeff n f) h) positivity _ ≤ gaussNorm v c f := le_ciSup hbd n end PowerSeries
.lake/packages/mathlib/Mathlib/RingTheory/PowerSeries/Binomial.lean
import Mathlib.RingTheory.Binomial import Mathlib.RingTheory.PowerSeries.WellKnown /-! # Binomial Power Series We introduce formal power series of the form `(1 + X) ^ r`, where `r` is an element of a commutative binomial ring `R`. ## Main Definitions * `PowerSeries.binomialSeries`: A power series expansion of `(1 + X) ^ r`, where `r` is an element of a commutative binomial ring `R`. ## Main Results * `PowerSeries.binomial_add`: Adding exponents yields multiplication of series. * `PowerSeries.binomialSeries_nat`: when `r` is a natural number, we get `(1 + X) ^ r`. * `PowerSeries.rescale_neg_one_invOneSubPow`: The image of `(1 - X) ^ (-d)` under the map `X ↦ (-X)` is `(1 + X) ^ (-d)` ## TODO * When `A` is a commutative `R`-algebra, the exponentiation action makes the multiplicative group `1 + XA[[X]]` into an `R`-module. -/ open Finset BigOperators suppress_compilation variable {R A : Type*} namespace PowerSeries variable [CommRing R] [BinomialRing R] /-- The power series for `(1 + X) ^ r`. -/ def binomialSeries (A) [One A] [SMul R A] (r : R) : PowerSeries A := mk fun n => Ring.choose r n • 1 @[simp] lemma binomialSeries_coeff [Semiring A] [SMul R A] (r : R) (n : ℕ) : coeff n (binomialSeries A r) = Ring.choose r n • 1 := coeff_mk n fun n ↦ Ring.choose r n • 1 @[simp] lemma binomialSeries_constantCoeff [Ring A] [Algebra R A] (r : R) : constantCoeff (binomialSeries A r) = 1 := by simp [← coeff_zero_eq_constantCoeff_apply] @[simp] lemma binomialSeries_add [Ring A] [Algebra R A] (r s : R) : binomialSeries A (r + s) = binomialSeries A r * binomialSeries A s := by ext n simp only [binomialSeries_coeff, Ring.add_choose_eq n (Commute.all r s), coeff_mul, Algebra.mul_smul_comm, mul_one, sum_smul] refine sum_congr rfl fun ab hab => ?_ rw [mul_comm, mul_smul] @[simp] lemma binomialSeries_nat [Ring A] [Algebra R A] (d : ℕ) : binomialSeries A (d : R) = (1 + X) ^ d := by ext n have hright : (1 + X) ^ d = (((1 : Polynomial A) + (Polynomial.X)) ^ d).toPowerSeries := by simp rw [hright, Polynomial.coeff_coe, binomialSeries_coeff, Polynomial.coeff_one_add_X_pow] simp [Ring.choose_natCast, Nat.cast_smul_eq_nsmul] @[simp] lemma binomialSeries_zero [Ring A] [Algebra R A] : binomialSeries A (0 : R) = (1 : A⟦X⟧) := by simpa using binomialSeries_nat 0 lemma rescale_neg_one_invOneSubPow [CommRing A] (d : ℕ) : rescale (-1 : A) (invOneSubPow A d) = binomialSeries A (-d : ℤ) := by ext n rw [coeff_rescale, binomialSeries_coeff, ← Int.cast_negOnePow_natCast, ← zsmul_eq_mul] cases d with | zero => by_cases hn : n = 0 <;> simp [invOneSubPow, Ring.choose_zero_ite, hn] | succ d => simp only [invOneSubPow, coeff_mk, Nat.cast_add, Nat.cast_one, neg_add_rev, Int.reduceNeg, zsmul_eq_mul, mul_one] rw [show (-1 : ℤ) + -d = -(d + 1) by abel, Ring.choose_neg, Nat.choose_symm_add, Units.smul_def, show (d : ℤ) + 1 + n - 1 = d + n by cutsat, ← Nat.cast_add, Ring.choose_natCast] norm_cast end PowerSeries
.lake/packages/mathlib/Mathlib/RingTheory/Adjoin/FG.lean
import Mathlib.Algebra.EuclideanDomain.Int import Mathlib.Algebra.MvPolynomial.Eval import Mathlib.RingTheory.Adjoin.Basic import Mathlib.RingTheory.Polynomial.Basic import Mathlib.RingTheory.PrincipalIdealDomain /-! # Adjoining elements to form subalgebras This file develops the basic theory of finitely-generated subalgebras. ## Definitions * `FG (S : Subalgebra R A)` : A predicate saying that the subalgebra is finitely-generated as an A-algebra ## Tags adjoin, algebra, finitely-generated algebra -/ universe u v w open Subsemiring Ring Submodule open Pointwise namespace Algebra variable {R : Type u} {A : Type v} {B : Type w} [CommSemiring R] [CommSemiring A] [Algebra R A] {s t : Set A} theorem fg_trans (h1 : (adjoin R s).toSubmodule.FG) (h2 : (adjoin (adjoin R s) t).toSubmodule.FG) : (adjoin R (s ∪ t)).toSubmodule.FG := by rcases fg_def.1 h1 with ⟨p, hp, hp'⟩ rcases fg_def.1 h2 with ⟨q, hq, hq'⟩ refine fg_def.2 ⟨p * q, hp.mul hq, le_antisymm ?_ ?_⟩ · rw [span_le, Set.mul_subset_iff] intro x hx y hy change x * y ∈ adjoin R (s ∪ t) refine Subalgebra.mul_mem _ ?_ ?_ · have : x ∈ Subalgebra.toSubmodule (adjoin R s) := by rw [← hp'] exact subset_span hx exact adjoin_mono Set.subset_union_left this have : y ∈ Subalgebra.toSubmodule (adjoin (adjoin R s) t) := by rw [← hq'] exact subset_span hy change y ∈ adjoin R (s ∪ t) rwa [adjoin_union_eq_adjoin_adjoin] · intro r hr change r ∈ adjoin R (s ∪ t) at hr rw [adjoin_union_eq_adjoin_adjoin] at hr change r ∈ Subalgebra.toSubmodule (adjoin (adjoin R s) t) at hr rw [← hq', ← Set.image_id q, Finsupp.mem_span_image_iff_linearCombination (adjoin R s)] at hr rcases hr with ⟨l, hlq, rfl⟩ have := @Finsupp.linearCombination_apply A A (adjoin R s) rw [this, Finsupp.sum] refine sum_mem ?_ intro z hz change (l z).1 * _ ∈ _ have : (l z).1 ∈ Subalgebra.toSubmodule (adjoin R s) := (l z).2 rw [← hp', ← Set.image_id p, Finsupp.mem_span_image_iff_linearCombination R] at this rcases this with ⟨l2, hlp, hl⟩ have := @Finsupp.linearCombination_apply A A R rw [this] at hl rw [← hl, Finsupp.sum_mul] refine sum_mem ?_ intro t ht change _ * _ ∈ _ rw [smul_mul_assoc] refine smul_mem _ _ ?_ exact subset_span ⟨t, hlp ht, z, hlq hz, rfl⟩ end Algebra namespace Subalgebra variable {R : Type u} {A : Type v} {B : Type w} variable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] /-- A subalgebra `S` is finitely generated if there exists `t : Finset A` such that `Algebra.adjoin R t = S`. -/ def FG (S : Subalgebra R A) : Prop := ∃ t : Finset A, Algebra.adjoin R ↑t = S theorem fg_adjoin_finset (s : Finset A) : (Algebra.adjoin R (↑s : Set A)).FG := ⟨s, rfl⟩ theorem fg_def {S : Subalgebra R A} : S.FG ↔ ∃ t : Set A, Set.Finite t ∧ Algebra.adjoin R t = S := Iff.symm Set.exists_finite_iff_finset theorem fg_bot : (⊥ : Subalgebra R A).FG := ⟨∅, Finset.coe_empty ▸ Algebra.adjoin_empty R A⟩ theorem fg_of_fg_toSubmodule {S : Subalgebra R A} : S.toSubmodule.FG → S.FG := fun ⟨t, ht⟩ ↦ ⟨t, le_antisymm (Algebra.adjoin_le fun x hx ↦ show x ∈ Subalgebra.toSubmodule S from ht ▸ subset_span hx) <| show Subalgebra.toSubmodule S ≤ Subalgebra.toSubmodule (Algebra.adjoin R ↑t) from fun x hx ↦ span_le.mpr (fun _ hx ↦ Algebra.subset_adjoin hx) (show x ∈ span R ↑t by rw [ht] exact hx)⟩ theorem fg_of_noetherian [IsNoetherian R A] (S : Subalgebra R A) : S.FG := fg_of_fg_toSubmodule (IsNoetherian.noetherian (Subalgebra.toSubmodule S)) theorem fg_of_submodule_fg (h : (⊤ : Submodule R A).FG) : (⊤ : Subalgebra R A).FG := let ⟨s, hs⟩ := h ⟨s, toSubmodule.injective <| by rw [Algebra.top_toSubmodule, eq_top_iff, ← hs, span_le] exact Algebra.subset_adjoin⟩ theorem FG.prod {S : Subalgebra R A} {T : Subalgebra R B} (hS : S.FG) (hT : T.FG) : (S.prod T).FG := by obtain ⟨s, hs⟩ := fg_def.1 hS obtain ⟨t, ht⟩ := fg_def.1 hT rw [← hs.2, ← ht.2] exact fg_def.2 ⟨LinearMap.inl R A B '' (s ∪ {1}) ∪ LinearMap.inr R A B '' (t ∪ {1}), Set.Finite.union (Set.Finite.image _ (Set.Finite.union hs.1 (Set.finite_singleton _))) (Set.Finite.image _ (Set.Finite.union ht.1 (Set.finite_singleton _))), Algebra.adjoin_inl_union_inr_eq_prod R s t⟩ section theorem FG.map {S : Subalgebra R A} (f : A →ₐ[R] B) (hs : S.FG) : (S.map f).FG := by let ⟨s, hs⟩ := hs classical exact ⟨s.image f, by rw [Finset.coe_image, Algebra.adjoin_image, hs]⟩ end theorem fg_of_fg_map (S : Subalgebra R A) (f : A →ₐ[R] B) (hf : Function.Injective f) (hs : (S.map f).FG) : S.FG := let ⟨s, hs⟩ := hs ⟨s.preimage f fun _ _ _ _ h ↦ hf h, map_injective hf <| by rw [← Algebra.adjoin_image, Finset.coe_preimage, Set.image_preimage_eq_of_subset, hs] rw [← AlgHom.coe_range, ← Algebra.adjoin_le_iff, hs, ← Algebra.map_top] exact map_mono le_top⟩ theorem fg_top (S : Subalgebra R A) : (⊤ : Subalgebra R S).FG ↔ S.FG := ⟨fun h ↦ by rw [← S.range_val, ← Algebra.map_top] exact FG.map _ h, fun h ↦ fg_of_fg_map _ S.val Subtype.val_injective <| by rw [Algebra.map_top, range_val] exact h⟩ theorem induction_on_adjoin [IsNoetherian R A] (P : Subalgebra R A → Prop) (base : P ⊥) (ih : ∀ (S : Subalgebra R A) (x : A), P S → P (Algebra.adjoin R (insert x S))) (S : Subalgebra R A) : P S := by classical obtain ⟨t, rfl⟩ := S.fg_of_noetherian refine Finset.induction_on t ?_ ?_ · simpa using base intro x t _ h rw [Finset.coe_insert] simpa only [Algebra.adjoin_insert_adjoin] using ih _ x h theorem FG.sup {S S' : Subalgebra R A} (hS : Subalgebra.FG S) (hS' : Subalgebra.FG S') : Subalgebra.FG (S ⊔ S') := let ⟨s, hs⟩ := Subalgebra.fg_def.1 hS let ⟨s', hs'⟩ := Subalgebra.fg_def.1 hS' fg_def.mpr ⟨s ∪ s', Set.Finite.union hs.1 hs'.1, (by rw [Algebra.adjoin_union, hs.2, hs'.2])⟩ end Subalgebra section Semiring variable {R : Type u} {A : Type v} {B : Type w} variable [CommSemiring R] [CommRing A] [CommRing B] [Algebra R A] [Algebra R B] /-- The image of a Noetherian R-algebra under an R-algebra map is a Noetherian ring. -/ instance AlgHom.isNoetherianRing_range (f : A →ₐ[R] B) [IsNoetherianRing A] : IsNoetherianRing f.range := _root_.isNoetherianRing_range f.toRingHom end Semiring section Ring variable {R : Type u} {A : Type v} {B : Type w} variable [CommRing R] [CommRing A] [CommRing B] [Algebra R A] [Algebra R B] theorem isNoetherianRing_of_fg {S : Subalgebra R A} (HS : S.FG) [IsNoetherianRing R] : IsNoetherianRing S := let ⟨t, ht⟩ := HS ht ▸ (Algebra.adjoin_eq_range R (↑t : Set A)).symm ▸ AlgHom.isNoetherianRing_range _ theorem is_noetherian_subring_closure (s : Set R) (hs : s.Finite) : IsNoetherianRing (Subring.closure s) := show IsNoetherianRing (subalgebraOfSubring (Subring.closure s)) from Algebra.adjoin_int s ▸ isNoetherianRing_of_fg (Subalgebra.fg_def.2 ⟨s, hs, rfl⟩) end Ring
.lake/packages/mathlib/Mathlib/RingTheory/Adjoin/Tower.lean
import Mathlib.RingTheory.Adjoin.FG /-! # Adjoining elements and being finitely generated in an algebra tower ## Main results * `Algebra.fg_trans'`: if `S` is finitely generated as `R`-algebra and `A` as `S`-algebra, then `A` is finitely generated as `R`-algebra * `fg_of_fg_of_fg`: **Artin--Tate lemma**: if C/B/A is a tower of rings, and A is Noetherian, and C is algebra-finite over A, and C is module-finite over B, then B is algebra-finite over A. -/ open Pointwise universe u v w u₁ variable (R : Type u) (S : Type v) (A : Type w) (B : Type u₁) namespace Algebra theorem adjoin_restrictScalars (C D E : Type*) [CommSemiring C] [CommSemiring D] [CommSemiring E] [Algebra C D] [Algebra C E] [Algebra D E] [IsScalarTower C D E] (S : Set E) : (Algebra.adjoin D S).restrictScalars C = (Algebra.adjoin ((⊤ : Subalgebra C D).map (IsScalarTower.toAlgHom C D E)) S).restrictScalars C := by suffices Set.range (algebraMap D E) = Set.range (algebraMap ((⊤ : Subalgebra C D).map (IsScalarTower.toAlgHom C D E)) E) by ext x change x ∈ Subsemiring.closure (_ ∪ S) ↔ x ∈ Subsemiring.closure (_ ∪ S) rw [this] ext x constructor · rintro ⟨y, hy⟩ exact ⟨⟨algebraMap D E y, ⟨y, ⟨Algebra.mem_top, rfl⟩⟩⟩, hy⟩ · rintro ⟨⟨y, ⟨z, ⟨h0, h1⟩⟩⟩, h2⟩ exact ⟨z, Eq.trans h1 h2⟩ theorem adjoin_res_eq_adjoin_res (C D E F : Type*) [CommSemiring C] [CommSemiring D] [CommSemiring E] [CommSemiring F] [Algebra C D] [Algebra C E] [Algebra C F] [Algebra D F] [Algebra E F] [IsScalarTower C D F] [IsScalarTower C E F] {S : Set D} {T : Set E} (hS : Algebra.adjoin C S = ⊤) (hT : Algebra.adjoin C T = ⊤) : (Algebra.adjoin E (algebraMap D F '' S)).restrictScalars C = (Algebra.adjoin D (algebraMap E F '' T)).restrictScalars C := by rw [adjoin_restrictScalars C E, adjoin_restrictScalars C D, ← hS, ← hT, ← Algebra.adjoin_image, ← Algebra.adjoin_image, ← AlgHom.coe_toRingHom, ← AlgHom.coe_toRingHom, IsScalarTower.coe_toAlgHom, IsScalarTower.coe_toAlgHom, ← adjoin_union_eq_adjoin_adjoin, ← adjoin_union_eq_adjoin_adjoin, Set.union_comm] end Algebra section theorem Algebra.fg_trans' {R S A : Type*} [CommSemiring R] [CommSemiring S] [Semiring A] [Algebra R S] [Algebra S A] [Algebra R A] [IsScalarTower R S A] (hRS : (⊤ : Subalgebra R S).FG) (hSA : (⊤ : Subalgebra S A).FG) : (⊤ : Subalgebra R A).FG := by classical rcases hRS with ⟨s, hs⟩ rcases hSA with ⟨t, ht⟩ exact ⟨s.image (algebraMap S A) ∪ t, by rw [Finset.coe_union, Finset.coe_image, Algebra.adjoin_algebraMap_image_union_eq_adjoin_adjoin, hs, Algebra.adjoin_top, ht, Subalgebra.restrictScalars_top, Subalgebra.restrictScalars_top ] ⟩ end section ArtinTate variable (C : Type*) section Semiring variable [CommSemiring A] [CommSemiring B] [Semiring C] variable [Algebra A B] [Algebra B C] [Algebra A C] [IsScalarTower A B C] open Finset Submodule theorem exists_subalgebra_of_fg (hAC : (⊤ : Subalgebra A C).FG) (hBC : (⊤ : Submodule B C).FG) : ∃ B₀ : Subalgebra A B, B₀.FG ∧ (⊤ : Submodule B₀ C).FG := by obtain ⟨x, hx⟩ := hAC obtain ⟨y, hy⟩ := hBC have := hy simp_rw [eq_top_iff', mem_span_finset] at this choose f _ hf using this classical let s : Finset B := Finset.image₂ f (x ∪ y * y) y have hxy : ∀ xi ∈ x, xi ∈ span (Algebra.adjoin A (↑s : Set B)) (↑(insert 1 y : Finset C) : Set C) := fun xi hxi => hf xi ▸ sum_mem fun yj hyj => smul_mem (span (Algebra.adjoin A (↑s : Set B)) (↑(insert 1 y : Finset C) : Set C)) ⟨f xi yj, Algebra.subset_adjoin <| mem_image₂_of_mem (mem_union_left _ hxi) hyj⟩ (subset_span <| mem_insert_of_mem hyj) have hyy : span (Algebra.adjoin A (↑s : Set B)) (↑(insert 1 y : Finset C) : Set C) * span (Algebra.adjoin A (↑s : Set B)) (↑(insert 1 y : Finset C) : Set C) ≤ span (Algebra.adjoin A (↑s : Set B)) (↑(insert 1 y : Finset C) : Set C) := by rw [span_mul_span, span_le, coe_insert] rintro _ ⟨yi, rfl | hyi, yj, rfl | hyj, rfl⟩ <;> dsimp · rw [mul_one] exact subset_span (Set.mem_insert _ _) · rw [one_mul] exact subset_span (Set.mem_insert_of_mem _ hyj) · rw [mul_one] exact subset_span (Set.mem_insert_of_mem _ hyi) · rw [← hf (yi * yj)] exact SetLike.mem_coe.2 (sum_mem fun yk hyk => smul_mem (span (Algebra.adjoin A (↑s : Set B)) (insert 1 ↑y : Set C)) ⟨f (yi * yj) yk, Algebra.subset_adjoin <| mem_image₂_of_mem (mem_union_right _ <| mul_mem_mul hyi hyj) hyk⟩ (subset_span <| Set.mem_insert_of_mem _ hyk : yk ∈ _)) refine ⟨Algebra.adjoin A (↑s : Set B), Subalgebra.fg_adjoin_finset _, insert 1 y, ?_⟩ convert restrictScalars_injective A (Algebra.adjoin A (s : Set B)) C _ rw [restrictScalars_top, eq_top_iff, ← Algebra.top_toSubmodule, ← hx, Algebra.adjoin_eq_span, span_le] refine fun r hr => Submonoid.closure_induction (fun c hc => hxy c hc) (subset_span <| mem_insert_self _ _) (fun p q _ _ hp hq => hyy <| Submodule.mul_mem_mul hp hq) hr end Semiring section Ring variable [CommRing A] [CommRing B] [CommRing C] variable [Algebra A B] [Algebra B C] [Algebra A C] [IsScalarTower A B C] /-- **Artin--Tate lemma**: if A ⊆ B ⊆ C is a chain of subrings of commutative rings, and A is Noetherian, and C is algebra-finite over A, and C is module-finite over B, then B is algebra-finite over A. References: Atiyah--Macdonald Proposition 7.8; Altman--Kleiman 16.17. -/ @[stacks 00IS] theorem fg_of_fg_of_fg [IsNoetherianRing A] (hAC : (⊤ : Subalgebra A C).FG) (hBC : (⊤ : Submodule B C).FG) (hBCi : Function.Injective (algebraMap B C)) : (⊤ : Subalgebra A B).FG := let ⟨B₀, hAB₀, hB₀C⟩ := exists_subalgebra_of_fg A B C hAC hBC Algebra.fg_trans' (B₀.fg_top.2 hAB₀) <| Subalgebra.fg_of_submodule_fg <| have : IsNoetherianRing B₀ := isNoetherianRing_of_fg hAB₀ have : Module.Finite B₀ C := ⟨hB₀C⟩ fg_of_injective (IsScalarTower.toAlgHom B₀ B C).toLinearMap hBCi end Ring end ArtinTate
.lake/packages/mathlib/Mathlib/RingTheory/Adjoin/Basic.lean
import Mathlib.Algebra.Algebra.Subalgebra.Prod import Mathlib.Algebra.Algebra.Subalgebra.Tower import Mathlib.LinearAlgebra.Basis.Basic import Mathlib.LinearAlgebra.Prod /-! # Adjoining elements to form subalgebras This file contains basic results on `Algebra.adjoin`. ## Tags adjoin, algebra -/ assert_not_exists Polynomial universe uR uS uA uB open Module Submodule Subsemiring open scoped Pointwise variable {R : Type uR} {S : Type uS} {A : Type uA} {B : Type uB} namespace Algebra section Semiring variable [CommSemiring R] [CommSemiring S] [Semiring A] [Semiring B] variable [Algebra R S] [Algebra R A] [Algebra S A] [Algebra R B] [IsScalarTower R S A] variable {s t : Set A} variable (R A) variable {A} (s) theorem adjoin_prod_le (s : Set A) (t : Set B) : adjoin R (s ×ˢ t) ≤ (adjoin R s).prod (adjoin R t) := adjoin_le <| Set.prod_mono subset_adjoin subset_adjoin theorem adjoin_inl_union_inr_eq_prod (s) (t) : adjoin R (LinearMap.inl R A B '' (s ∪ {1}) ∪ LinearMap.inr R A B '' (t ∪ {1})) = (adjoin R s).prod (adjoin R t) := by apply le_antisymm · simp only [adjoin_le_iff, Set.insert_subset_iff, Subalgebra.zero_mem, Subalgebra.one_mem, subset_adjoin,-- the rest comes from `squeeze_simp` Set.union_subset_iff, LinearMap.coe_inl, Set.mk_preimage_prod_right, Set.image_subset_iff, SetLike.mem_coe, Set.mk_preimage_prod_left, LinearMap.coe_inr, and_self_iff, Set.union_singleton, Subalgebra.coe_prod] · rintro ⟨a, b⟩ ⟨ha, hb⟩ let P := adjoin R (LinearMap.inl R A B '' (s ∪ {1}) ∪ LinearMap.inr R A B '' (t ∪ {1})) have Ha : (a, (0 : B)) ∈ adjoin R (LinearMap.inl R A B '' (s ∪ {1})) := mem_adjoin_of_map_mul R LinearMap.inl_map_mul ha have Hb : ((0 : A), b) ∈ adjoin R (LinearMap.inr R A B '' (t ∪ {1})) := mem_adjoin_of_map_mul R LinearMap.inr_map_mul hb replace Ha : (a, (0 : B)) ∈ P := adjoin_mono Set.subset_union_left Ha replace Hb : ((0 : A), b) ∈ P := adjoin_mono Set.subset_union_right Hb simpa [P] using Subalgebra.add_mem _ Ha Hb variable (A) in theorem adjoin_algebraMap (s : Set S) : adjoin R (algebraMap S A '' s) = (adjoin R s).map (IsScalarTower.toAlgHom R S A) := adjoin_image R (IsScalarTower.toAlgHom R S A) s theorem adjoin_algebraMap_image_union_eq_adjoin_adjoin (s : Set S) (t : Set A) : adjoin R (algebraMap S A '' s ∪ t) = (adjoin (adjoin R s) t).restrictScalars R := le_antisymm (closure_mono <| Set.union_subset (Set.range_subset_iff.2 fun r => Or.inl ⟨algebraMap R (adjoin R s) r, (IsScalarTower.algebraMap_apply _ _ _ _).symm⟩) (Set.union_subset_union_left _ fun _ ⟨_x, hx, hxs⟩ => hxs ▸ ⟨⟨_, subset_adjoin hx⟩, rfl⟩)) (closure_le.2 <| Set.union_subset (Set.range_subset_iff.2 fun x => adjoin_mono Set.subset_union_left <| Algebra.adjoin_algebraMap R A s ▸ ⟨x, x.prop, rfl⟩) (Set.Subset.trans Set.subset_union_right subset_adjoin)) theorem adjoin_adjoin_of_tower (s : Set A) : adjoin S (adjoin R s : Set A) = adjoin S s := by apply le_antisymm (adjoin_le _) · exact adjoin_mono subset_adjoin · rw [← Subalgebra.coe_restrictScalars R (S := S), SetLike.coe_subset_coe] exact adjoin_le subset_adjoin theorem Subalgebra.restrictScalars_adjoin {s : Set A} : (adjoin S s).restrictScalars R = (IsScalarTower.toAlgHom R S A).range ⊔ adjoin R s := by refine le_antisymm (fun _ hx ↦ adjoin_induction (fun x hx ↦ le_sup_right (α := Subalgebra R A) (subset_adjoin hx)) (fun x ↦ le_sup_left (α := Subalgebra R A) ⟨x, rfl⟩) (fun _ _ _ _ ↦ add_mem) (fun _ _ _ _ ↦ mul_mem) <| (Subalgebra.mem_restrictScalars _).mp hx) (sup_le ?_ <| adjoin_le subset_adjoin) rintro _ ⟨x, rfl⟩; exact algebraMap_mem (adjoin S s) x @[simp] theorem adjoin_top {A} [Semiring A] [Algebra S A] (t : Set A) : adjoin (⊤ : Subalgebra R S) t = (adjoin S t).restrictScalars (⊤ : Subalgebra R S) := let equivTop : Subalgebra (⊤ : Subalgebra R S) A ≃o Subalgebra S A := { toFun := fun s => { s with algebraMap_mem' := fun r => s.algebraMap_mem ⟨r, trivial⟩ } invFun := fun s => s.restrictScalars _ left_inv := fun _ => SetLike.coe_injective rfl right_inv := fun _ => SetLike.coe_injective rfl map_rel_iff' := @fun _ _ => Iff.rfl } le_antisymm (adjoin_le <| show t ⊆ adjoin S t from subset_adjoin) (equivTop.symm_apply_le.mpr <| adjoin_le <| show t ⊆ adjoin (⊤ : Subalgebra R S) t from subset_adjoin) end Semiring section CommSemiring variable [CommSemiring R] [CommSemiring A] variable [Algebra R A] {s t : Set A} variable (R s t) theorem adjoin_union_eq_adjoin_adjoin : adjoin R (s ∪ t) = (adjoin (adjoin R s) t).restrictScalars R := by simpa using adjoin_algebraMap_image_union_eq_adjoin_adjoin R s t /-- If `A` is spanned over `R` by `s`, then the algebra spanned over `A` by `t` is the equal to the algebra spanned over `R` by `s ∪ t`. -/ theorem adjoin_eq_adjoin_union [CommSemiring B] [Algebra R B] [Algebra A B] [IsScalarTower R A B] (s : Set A) (t : Set B) (hS : adjoin R s = ⊤) : (adjoin A t).restrictScalars R = adjoin R ((algebraMap A B '' s) ∪ t) := by have := congr_arg (Subalgebra.map (IsScalarTower.toAlgHom R A B)) hS rw [Algebra.map_top, AlgHom.map_adjoin, IsScalarTower.coe_toAlgHom'] at this rw [adjoin_union_eq_adjoin_adjoin, this, ← IsScalarTower.adjoin_range_toAlgHom] variable {R} theorem pow_smul_mem_of_smul_subset_of_mem_adjoin [CommSemiring B] [Algebra R B] [Algebra A B] [IsScalarTower R A B] (r : A) (s : Set B) (B' : Subalgebra R B) (hs : r • s ⊆ B') {x : B} (hx : x ∈ adjoin R s) (hr : algebraMap A B r ∈ B') : ∃ n₀ : ℕ, ∀ n ≥ n₀, r ^ n • x ∈ B' := by change x ∈ Subalgebra.toSubmodule (adjoin R s) at hx rw [adjoin_eq_span, Finsupp.mem_span_iff_linearCombination] at hx rcases hx with ⟨l, rfl : (l.sum fun (i : Submonoid.closure s) (c : R) => c • (i : B)) = x⟩ choose n₁ n₂ using fun x : Submonoid.closure s => Submonoid.pow_smul_mem_closure_smul r s x.prop use l.support.sup n₁ intro n hn rw [Finsupp.smul_sum] refine B'.toSubmodule.sum_mem ?_ intro a ha have : n ≥ n₁ a := le_trans (Finset.le_sup ha) hn dsimp only rw [← tsub_add_cancel_of_le this, pow_add, ← smul_smul, ← IsScalarTower.algebraMap_smul A (l a) (a : B), smul_smul (r ^ n₁ a), mul_comm, ← smul_smul, smul_def, map_pow, IsScalarTower.algebraMap_smul] apply Subalgebra.mul_mem _ (Subalgebra.pow_mem _ hr _) _ refine Subalgebra.smul_mem _ ?_ _ change _ ∈ B'.toSubmonoid rw [← Submonoid.closure_eq B'.toSubmonoid] apply Submonoid.closure_mono hs (n₂ a) theorem pow_smul_mem_adjoin_smul (r : R) (s : Set A) {x : A} (hx : x ∈ adjoin R s) : ∃ n₀ : ℕ, ∀ n ≥ n₀, r ^ n • x ∈ adjoin R (r • s) := pow_smul_mem_of_smul_subset_of_mem_adjoin r s _ subset_adjoin hx (Subalgebra.algebraMap_mem _ _) lemma adjoin_nonUnitalSubalgebra_eq_span (s : NonUnitalSubalgebra R A) : Subalgebra.toSubmodule (adjoin R (s : Set A)) = span R {1} ⊔ s.toSubmodule := by rw [adjoin_eq_span, Submonoid.closure_eq_one_union, span_union, ← NonUnitalAlgebra.adjoin_eq_span, NonUnitalAlgebra.adjoin_eq] end CommSemiring end Algebra open Algebra Subalgebra section variable (F E : Type*) {K : Type*} [CommSemiring E] [Semiring K] [SMul F E] [Algebra E K] variable [CommSemiring F] [Algebra F K] [IsScalarTower F E K] (L : Subalgebra F K) {F} /-- If `K / E / F` is a ring extension tower, `L` is a subalgebra of `K / F`, then `E[L]` is generated by any basis of `L / F` as an `E`-module. -/ theorem Subalgebra.adjoin_eq_span_basis {ι : Type*} (bL : Basis ι F L) : toSubmodule (adjoin E (L : Set K)) = span E (Set.range fun i : ι ↦ (bL i).1) := L.adjoin_eq_span_of_eq_span E <| by simpa only [← L.range_val, Submodule.map_span, Submodule.map_top, ← Set.range_comp] using congr_arg (Submodule.map L.val) bL.span_eq.symm theorem Algebra.restrictScalars_adjoin (F : Type*) [CommSemiring F] {E : Type*} [CommSemiring E] [Algebra F E] (K : Subalgebra F E) (S : Set E) : (Algebra.adjoin K S).restrictScalars F = Algebra.adjoin F (K ∪ S) := by conv_lhs => rw [← Algebra.adjoin_eq K, ← Algebra.adjoin_union_eq_adjoin_adjoin] /-- If `E / L / F` and `E / L' / F` are two ring extension towers, `L ≃ₐ[F] L'` is an isomorphism compatible with `E / L` and `E / L'`, then for any subset `S` of `E`, `L[S]` and `L'[S]` are equal as subalgebras of `E / F`. -/ theorem Algebra.restrictScalars_adjoin_of_algEquiv {F E L L' : Type*} [CommSemiring F] [CommSemiring L] [CommSemiring L'] [Semiring E] [Algebra F L] [Algebra L E] [Algebra F L'] [Algebra L' E] [Algebra F E] [IsScalarTower F L E] [IsScalarTower F L' E] (i : L ≃ₐ[F] L') (hi : algebraMap L E = (algebraMap L' E) ∘ i) (S : Set E) : (Algebra.adjoin L S).restrictScalars F = (Algebra.adjoin L' S).restrictScalars F := by apply_fun Subalgebra.toSubsemiring using fun K K' h ↦ by rwa [SetLike.ext'_iff] at h ⊢ change Subsemiring.closure _ = Subsemiring.closure _ rw [hi, Set.range_comp, EquivLike.range_eq_univ, Set.image_univ] end
.lake/packages/mathlib/Mathlib/RingTheory/Adjoin/PowerBasis.lean
import Mathlib.RingTheory.Adjoin.Basic import Mathlib.RingTheory.PowerBasis import Mathlib.LinearAlgebra.Matrix.Basis /-! # Power basis for `Algebra.adjoin R {x}` This file defines the canonical power basis on `Algebra.adjoin R {x}`, where `x` is an integral element over `R`. -/ open Module Polynomial PowerBasis variable {K S : Type*} [Field K] [CommRing S] [Algebra K S] namespace Algebra /-- The elements `1, x, ..., x ^ (d - 1)` for a basis for the `K`-module `K[x]`, where `d` is the degree of the minimal polynomial of `x`. -/ noncomputable def adjoin.powerBasisAux {x : S} (hx : IsIntegral K x) : Basis (Fin (minpoly K x).natDegree) K (adjoin K ({x} : Set S)) := by have hST : Function.Injective (algebraMap (adjoin K ({x} : Set S)) S) := Subtype.coe_injective have hx' : IsIntegral K (⟨x, subset_adjoin (Set.mem_singleton x)⟩ : adjoin K ({x} : Set S)) := by apply (isIntegral_algebraMap_iff hST).mp convert hx apply Basis.mk (v := fun i : Fin _ ↦ ⟨x, subset_adjoin (Set.mem_singleton x)⟩ ^ (i : ℕ)) · have : LinearIndependent K _ := linearIndependent_pow (⟨x, self_mem_adjoin_singleton _ _⟩ : adjoin K {x}) rwa [← minpoly.algebraMap_eq hST] at this · rintro ⟨y, hy⟩ _ have := hx'.mem_span_pow (y := ⟨y, hy⟩) rw [← minpoly.algebraMap_eq hST] at this apply this rw [adjoin_singleton_eq_range_aeval] at hy obtain ⟨f, rfl⟩ := (aeval x).mem_range.mp hy use f ext exact aeval_algebraMap_apply S (⟨x, _⟩ : adjoin K {x}) _ /-- The power basis `1, x, ..., x ^ (d - 1)` for `K[x]`, where `d` is the degree of the minimal polynomial of `x`. See `Algebra.adjoin.powerBasis'` for a version over a more general base ring. -/ @[simps gen dim] noncomputable def adjoin.powerBasis {x : S} (hx : IsIntegral K x) : PowerBasis K (adjoin K ({x} : Set S)) where gen := ⟨x, subset_adjoin (Set.mem_singleton x)⟩ dim := (minpoly K x).natDegree basis := adjoin.powerBasisAux hx basis_eq_pow i := by rw [adjoin.powerBasisAux, Basis.mk_apply] /-- If `x` generates `S` over `K` and is integral over `K`, then it defines a power basis. See `PowerBasis.ofAdjoinEqTop'` for a version over a more general base ring. -/ noncomputable def _root_.PowerBasis.ofAdjoinEqTop {x : S} (hx : IsIntegral K x) (hx' : adjoin K {x} = ⊤) : PowerBasis K S := (adjoin.powerBasis hx).map ((Subalgebra.equivOfEq _ _ hx').trans Subalgebra.topEquiv) @[simp] theorem _root_.PowerBasis.ofAdjoinEqTop_gen {x : S} (hx : IsIntegral K x) (hx' : adjoin K {x} = ⊤) : (PowerBasis.ofAdjoinEqTop hx hx').gen = x := rfl @[simp] theorem _root_.PowerBasis.ofAdjoinEqTop_dim {x : S} (hx : IsIntegral K x) (hx' : adjoin K {x} = ⊤) : (PowerBasis.ofAdjoinEqTop hx hx').dim = (minpoly K x).natDegree := rfl @[deprecated "Use in combination with `PowerBasis.adjoin_eq_top_of_gen_mem_adjoin` to recover the \ deprecated definition" (since := "2025-09-29")] alias PowerBasis.ofGenMemAdjoin := PowerBasis.ofAdjoinEqTop end Algebra open Algebra section IsIntegral namespace PowerBasis open Polynomial variable {R : Type*} [CommRing R] [Algebra R S] [Algebra R K] [IsScalarTower R K S] variable {A : Type*} [CommRing A] [Algebra R A] [Algebra S A] variable [IsScalarTower R S A] {B : PowerBasis S A} /-- If `B : PowerBasis S A` is such that `IsIntegral R B.gen`, then `IsIntegral R (B.basis.repr (B.gen ^ n) i)` for all `i` if `minpoly S B.gen = (minpoly R B.gen).map (algebraMap R S)`. This is the case if `R` is a GCD domain and `S` is its fraction ring. -/ theorem repr_gen_pow_isIntegral (hB : IsIntegral R B.gen) (hmin : minpoly S B.gen = (minpoly R B.gen).map (algebraMap R S)) (n : ℕ) : ∀ i, IsIntegral R (B.basis.repr (B.gen ^ n) i) := by intro i nontriviality S let Q := X ^ n %ₘ minpoly R B.gen have : B.gen ^ n = aeval B.gen Q := by rw [← @aeval_X_pow R _ _ _ _ B.gen, ← modByMonic_add_div (X ^ n) (minpoly.monic hB)] simp [Q] by_cases hQ : Q = 0 · simp [this, hQ, isIntegral_zero] have hlt : Q.natDegree < B.dim := by rw [← B.natDegree_minpoly, hmin, (minpoly.monic hB).natDegree_map, natDegree_lt_natDegree_iff hQ] letI : Nontrivial R := Nontrivial.of_polynomial_ne hQ exact degree_modByMonic_lt _ (minpoly.monic hB) rw [this, aeval_eq_sum_range' hlt] simp only [map_sum, Finset.sum_apply'] refine IsIntegral.sum _ fun j hj => ?_ replace hj := Finset.mem_range.1 hj rw [← Fin.val_mk hj, ← B.basis_eq_pow, Algebra.smul_def, IsScalarTower.algebraMap_apply R S A, ← Algebra.smul_def, LinearEquiv.map_smul] simp only [algebraMap_smul, Finsupp.coe_smul, Pi.smul_apply, B.basis.repr_self_apply] by_cases hij : (⟨j, hj⟩ : Fin _) = i · simp only [hij, if_true] rw [Algebra.smul_def, mul_one] exact isIntegral_algebraMap · simp [hij, isIntegral_zero] /-- Let `B : PowerBasis S A` be such that `IsIntegral R B.gen`, and let `x y : A` be elements with integral coordinates in the base `B.basis`. Then `IsIntegral R ((B.basis.repr (x * y) i)` for all `i` if `minpoly S B.gen = (minpoly R B.gen).map (algebraMap R S)`. This is the case if `R` is a GCD domain and `S` is its fraction ring. -/ theorem repr_mul_isIntegral (hB : IsIntegral R B.gen) {x y : A} (hx : ∀ i, IsIntegral R (B.basis.repr x i)) (hy : ∀ i, IsIntegral R (B.basis.repr y i)) (hmin : minpoly S B.gen = (minpoly R B.gen).map (algebraMap R S)) : ∀ i, IsIntegral R (B.basis.repr (x * y) i) := by intro i rw [← B.basis.sum_repr x, ← B.basis.sum_repr y, Finset.sum_mul_sum, ← Finset.sum_product', map_sum, Finset.sum_apply'] refine IsIntegral.sum _ fun I _ => ?_ simp only [Algebra.smul_mul_assoc, Algebra.mul_smul_comm, LinearEquiv.map_smulₛₗ, RingHom.id_apply, Finsupp.coe_smul, Pi.smul_apply, id.smul_eq_mul] refine (hy _).mul ((hx _).mul ?_) simp only [coe_basis, ← pow_add] exact repr_gen_pow_isIntegral hB hmin _ _ /-- Let `B : PowerBasis S A` be such that `IsIntegral R B.gen`, and let `x : A` be an element with integral coordinates in the base `B.basis`. Then `IsIntegral R ((B.basis.repr (x ^ n) i)` for all `i` and all `n` if `minpoly S B.gen = (minpoly R B.gen).map (algebraMap R S)`. This is the case if `R` is a GCD domain and `S` is its fraction ring. -/ theorem repr_pow_isIntegral (hB : IsIntegral R B.gen) {x : A} (hx : ∀ i, IsIntegral R (B.basis.repr x i)) (hmin : minpoly S B.gen = (minpoly R B.gen).map (algebraMap R S)) (n : ℕ) : ∀ i, IsIntegral R (B.basis.repr (x ^ n) i) := by nontriviality A using Subsingleton.elim (x ^ n) 0, isIntegral_zero revert hx refine Nat.case_strong_induction_on -- Porting note: had to hint what to induct on (p := fun n ↦ _ → ∀ (i : Fin B.dim), IsIntegral R (B.basis.repr (x ^ n) i)) n ?_ fun n hn => ?_ · intro _ i rw [pow_zero, ← pow_zero B.gen, ← Fin.val_mk B.dim_pos, ← B.basis_eq_pow, B.basis.repr_self_apply] split_ifs · exact isIntegral_one · exact isIntegral_zero · intro hx rw [pow_succ] exact repr_mul_isIntegral hB (fun _ => hn _ le_rfl (fun _ => hx _) _) hx hmin /-- Let `B B' : PowerBasis K S` be such that `IsIntegral R B.gen`, and let `P : R[X]` be such that `aeval B.gen P = B'.gen`. Then `IsIntegral R (B.basis.to_matrix B'.basis i j)` for all `i` and `j` if `minpoly K B.gen = (minpoly R B.gen).map (algebraMap R L)`. This is the case if `R` is a GCD domain and `K` is its fraction ring. -/ theorem toMatrix_isIntegral {B B' : PowerBasis K S} {P : R[X]} (h : aeval B.gen P = B'.gen) (hB : IsIntegral R B.gen) (hmin : minpoly K B.gen = (minpoly R B.gen).map (algebraMap R K)) : ∀ i j, IsIntegral R (B.basis.toMatrix B'.basis i j) := by intro i j rw [B.basis.toMatrix_apply, B'.coe_basis] refine repr_pow_isIntegral hB (fun i => ?_) hmin _ _ rw [← h, aeval_eq_sum_range, map_sum, Finset.sum_apply'] refine IsIntegral.sum _ fun n _ => ?_ rw [Algebra.smul_def, IsScalarTower.algebraMap_apply R K S, ← Algebra.smul_def, LinearEquiv.map_smul, algebraMap_smul] exact (repr_gen_pow_isIntegral hB hmin _ _).smul _ end PowerBasis end IsIntegral
.lake/packages/mathlib/Mathlib/RingTheory/Adjoin/FGBaseChange.lean
import Mathlib.LinearAlgebra.TensorProduct.Finiteness import Mathlib.RingTheory.TensorProduct.Maps import Mathlib.RingTheory.Adjoin.FG /-! # Finitely generated subalgebras of a base change obtained from an element ## Main results - `exists_fg_and_mem_baseChange`: given an element `x` of a tensor product `A ⊗[R] B` of two `R`-algebras `A` and `B`, there exists a finitely generated subalgebra `C` of `B` such that `x` is contained in `C ⊗[R] B`. -/ open TensorProduct lemma exists_fg_and_mem_baseChange {R A B : Type*} [CommSemiring R] [CommSemiring A] [Semiring B] [Algebra R A] [Algebra R B] (x : A ⊗[R] B) : ∃ C : Subalgebra R B, C.FG ∧ x ∈ C.baseChange A := by obtain ⟨S, hS⟩ := TensorProduct.exists_finset x classical refine ⟨Algebra.adjoin R (S.image fun j ↦ j.2), ?_, ?_⟩ · exact Subalgebra.fg_adjoin_finset _ · exact hS ▸ Subalgebra.sum_mem _ fun s hs ↦ (Subalgebra.tmul_mem_baseChange (Algebra.subset_adjoin (Finset.mem_image_of_mem _ hs)) s.1)
.lake/packages/mathlib/Mathlib/RingTheory/Adjoin/Field.lean
import Mathlib.Algebra.Polynomial.Splits import Mathlib.RingTheory.Adjoin.Basic import Mathlib.RingTheory.AdjoinRoot /-! # Adjoining elements to a field Some lemmas on the ring generated by adjoining an element to a field. ## Main statements * `Polynomial.lift_of_splits`: If `K` and `L` are field extensions of `F` and we have `s : Finset K` such that the minimal polynomial of each `x ∈ s` splits in `L` then `Algebra.adjoin F s` embeds in `L`. -/ noncomputable section open Polynomial section Embeddings variable (F : Type*) [Field F] open AdjoinRoot in /-- If `p` is the minimal polynomial of `a` over `F` then `F[a] ≃ₐ[F] F[x]/(p)` -/ def AlgEquiv.adjoinSingletonEquivAdjoinRootMinpoly {R : Type*} [CommRing R] [Algebra F R] (x : R) : Algebra.adjoin F ({x} : Set R) ≃ₐ[F] AdjoinRoot (minpoly F x) := AlgEquiv.symm <| AlgEquiv.ofBijective (Minpoly.toAdjoin F x) <| by refine ⟨(injective_iff_map_eq_zero _).2 fun P₁ hP₁ ↦ ?_, Minpoly.toAdjoin.surjective F x⟩ obtain ⟨P, rfl⟩ := mk_surjective P₁ refine AdjoinRoot.mk_eq_zero.mpr (minpoly.dvd F x ?_) simpa [← Subalgebra.coe_eq_zero, ← aeval_def] using hP₁ @[simp] theorem AlgEquiv.adjoinSingletonEquivAdjoinRootMinpoly_symm_toAlgHom {R : Type*} [CommRing R] [Algebra F R] (x : R) : (adjoinSingletonEquivAdjoinRootMinpoly F x).symm = AdjoinRoot.Minpoly.toAdjoin F x := rfl @[simp] theorem AlgEquiv.coe_adjoinSingletonEquivAdjoinRootMinpoly_symm {R : Type*} [CommRing R] [Algebra F R] (x : R) : ⇑(adjoinSingletonEquivAdjoinRootMinpoly F x).symm = AdjoinRoot.Minpoly.toAdjoin F x := rfl /-- Produce an algebra homomorphism `Adjoin R {x} →ₐ[R] T` sending `x` to a root of `x`'s minimal polynomial in `T`. -/ noncomputable def Algebra.adjoin.liftSingleton {S T : Type*} [CommRing S] [CommRing T] [Algebra F S] [Algebra F T] (x : S) (y : T) (h : aeval y (minpoly F x) = 0) : Algebra.adjoin F {x} →ₐ[F] T := (AdjoinRoot.liftAlgHom _ _ y h).comp (AlgEquiv.adjoinSingletonEquivAdjoinRootMinpoly F x).toAlgHom open Finset /-- If `K` and `L` are field extensions of `F` and we have `s : Finset K` such that the minimal polynomial of each `x ∈ s` splits in `L` then `Algebra.adjoin F s` embeds in `L`. -/ theorem Polynomial.lift_of_splits {F K L : Type*} [Field F] [Field K] [Field L] [Algebra F K] [Algebra F L] (s : Finset K) : (∀ x ∈ s, IsIntegral F x ∧ Splits (algebraMap F L) (minpoly F x)) → Nonempty (Algebra.adjoin F (s : Set K) →ₐ[F] L) := by classical refine Finset.induction_on s (fun _ ↦ ?_) fun a s _ ih H ↦ ?_ · rw [coe_empty, Algebra.adjoin_empty] exact ⟨(Algebra.ofId F L).comp (Algebra.botEquiv F K)⟩ rw [forall_mem_insert] at H rcases H with ⟨⟨H1, H2⟩, H3⟩ obtain ⟨f⟩ := ih H3 choose H3 _ using H3 rw [coe_insert, Set.insert_eq, Set.union_comm, Algebra.adjoin_union_eq_adjoin_adjoin] set Ks := Algebra.adjoin F (s : Set K) haveI : FiniteDimensional F Ks := ((Submodule.fg_iff_finiteDimensional _).1 (fg_adjoin_of_finite s.finite_toSet H3)).of_subalgebra_toSubmodule letI := fieldOfFiniteDimensional F Ks letI := (f : Ks →+* L).toAlgebra have H5 : IsIntegral Ks a := H1.tower_top have H6 : (minpoly Ks a).Splits (algebraMap Ks L) := by refine splits_of_splits_of_dvd _ ((minpoly.monic H1).map (algebraMap F Ks)).ne_zero ((splits_map_iff _ _).2 ?_) (minpoly.dvd _ _ ?_) · rw [← IsScalarTower.algebraMap_eq] exact H2 · rw [Polynomial.aeval_map_algebraMap, minpoly.aeval] obtain ⟨y, hy⟩ := Polynomial.exists_root_of_splits _ H6 (minpoly.degree_pos H5).ne' exact ⟨Subalgebra.ofRestrictScalars F _ <| Algebra.adjoin.liftSingleton Ks a y hy⟩ end Embeddings variable {R K L M : Type*} [CommRing R] [Field K] [Field L] [CommRing M] [Algebra R K] [Algebra R M] {x : L} section variable [Algebra R L] theorem IsIntegral.mem_range_algHom_of_minpoly_splits (int : IsIntegral R x) (h : Splits (algebraMap R K) (minpoly R x)) (f : K →ₐ[R] L) : x ∈ f.range := show x ∈ Set.range f from Set.image_subset_range _ ((minpoly R x).rootSet K) <| by rw [image_rootSet h f, mem_rootSet'] exact ⟨((minpoly.monic int).map _).ne_zero, minpoly.aeval R x⟩ theorem IsIntegral.mem_range_algebraMap_of_minpoly_splits [Algebra K L] [IsScalarTower R K L] (int : IsIntegral R x) (h : Splits (algebraMap R K) (minpoly R x)) : x ∈ (algebraMap K L).range := int.mem_range_algHom_of_minpoly_splits h (IsScalarTower.toAlgHom R K L) theorem minpoly_neg_splits [Algebra K L] {x : L} (g : (minpoly K x).Splits (algebraMap K L)) : (minpoly K (-x)).Splits (algebraMap K L) := by rw [minpoly.neg] apply splits_mul _ _ g.comp_neg_X simpa only [map_pow, map_neg, map_one] using splits_C (algebraMap K L) ((-1) ^ (minpoly K x).natDegree) theorem minpoly_add_algebraMap_splits [Algebra K L] {x : L} (r : K) (g : (minpoly K x).Splits (algebraMap K L)) : (minpoly K (x + algebraMap K L r)).Splits (algebraMap K L) := by simpa [minpoly.add_algebraMap] using g.comp_X_sub_C r theorem minpoly_sub_algebraMap_splits [Algebra K L] {x : L} (r : K) (g : (minpoly K x).Splits (algebraMap K L)) : (minpoly K (x - algebraMap K L r)).Splits (algebraMap K L) := by simpa only [sub_eq_add_neg, map_neg] using minpoly_add_algebraMap_splits (-r) g theorem minpoly_algebraMap_add_splits [Algebra K L] {x : L} (r : K) (g : (minpoly K x).Splits (algebraMap K L)) : (minpoly K (algebraMap K L r + x)).Splits (algebraMap K L) := by simpa only [add_comm] using minpoly_add_algebraMap_splits r g theorem minpoly_algebraMap_sub_splits [Algebra K L] {x : L} (r : K) (g : (minpoly K x).Splits (algebraMap K L)) : (minpoly K (algebraMap K L r - x)).Splits (algebraMap K L) := by simpa only [neg_sub] using minpoly_neg_splits (minpoly_sub_algebraMap_splits r g) end variable [Algebra K M] [IsScalarTower R K M] {x : M} /-- The `RingHom` version of `IsIntegral.minpoly_splits_tower_top`. -/ theorem IsIntegral.minpoly_splits_tower_top' (int : IsIntegral R x) {f : K →+* L} (h : Splits (f.comp <| algebraMap R K) (minpoly R x)) : Splits f (minpoly K x) := splits_of_splits_of_dvd _ ((minpoly.monic int).map _).ne_zero ((splits_map_iff _ _).mpr h) (minpoly.dvd_map_of_isScalarTower R _ x) theorem IsIntegral.minpoly_splits_tower_top [Algebra K L] [Algebra R L] [IsScalarTower R K L] (int : IsIntegral R x) (h : Splits (algebraMap R L) (minpoly R x)) : Splits (algebraMap K L) (minpoly K x) := by rw [IsScalarTower.algebraMap_eq R K L] at h exact int.minpoly_splits_tower_top' h /-- If `K / E / F` is a ring extension tower, `L` is a subalgebra of `K / F`, then `[E[L] : E] ≤ [L : F]`. -/ lemma Subalgebra.adjoin_rank_le {F : Type*} (E : Type*) {K : Type*} [CommSemiring F] [StrongRankCondition F] [CommSemiring E] [StrongRankCondition E] [Semiring K] [SMul F E] [Algebra E K] [Algebra F K] [IsScalarTower F E K] (L : Subalgebra F K) [Module.Free F L] : Module.rank E (Algebra.adjoin E (L : Set K)) ≤ Module.rank F L := by rw [← rank_toSubmodule, Module.Free.rank_eq_card_chooseBasisIndex F L, L.adjoin_eq_span_basis E (Module.Free.chooseBasis F L)] exact rank_span_le _ |>.trans Cardinal.mk_range_le
.lake/packages/mathlib/Mathlib/RingTheory/Adjoin/Polynomial.lean
import Mathlib.Algebra.Polynomial.AlgebraMap /-! # Polynomials and adjoining roots ## Main results * `Polynomial.instCommSemiringAdjoinSingleton, instCommRingAdjoinSingleton`: adjoining an element to a commutative (semi)ring gives a commutative (semi)ring -/ noncomputable section open Finset open Polynomial namespace Polynomial universe u v w z variable {R : Type u} {S : Type v} {T : Type w} {A : Type z} {A' B : Type*} {a b : R} {n : ℕ} section aeval open Algebra variable [CommSemiring R] [Semiring A] [CommSemiring A'] [Semiring B] variable [Algebra R A] [Algebra R B] variable {p q : R[X]} (x : A) @[simp] theorem adjoin_X : adjoin R ({X} : Set R[X]) = ⊤ := by refine top_unique fun p _hp => ?_ set S := adjoin R ({X} : Set R[X]) rw [← sum_monomial_eq p]; simp only [← smul_X_eq_monomial] exact S.sum_mem fun n _hn => S.smul_mem (S.pow_mem (subset_adjoin rfl) _) _ variable (R) theorem _root_.Algebra.adjoin_singleton_eq_range_aeval (x : A) : adjoin R {x} = (aeval x).range := by rw [← Algebra.map_top, ← adjoin_X, AlgHom.map_adjoin, Set.image_singleton, aeval_X] @[simp] theorem aeval_mem_adjoin_singleton : aeval x p ∈ adjoin R {x} := by simp [adjoin_singleton_eq_range_aeval] theorem _root_.Algebra.adjoin_mem_exists_aeval {a : A} (h : a ∈ Algebra.adjoin R {x}) : ∃ p : R[X], aeval x p = a := by rw [Algebra.adjoin_singleton_eq_range_aeval] at h simp_all theorem _root_.Algebra.adjoin_eq_exists_aeval (a : Algebra.adjoin R {x}) : ∃ p : R[X], aeval x p = a := by have : (a : A) ∈ Algebra.adjoin R {x} := by simp set y := (a : A) with h rw [Algebra.adjoin_singleton_eq_range_aeval] at this simp_all @[elab_as_elim] theorem _root_.Algebra.adjoin_singleton_induction {M : (adjoin R {x}) → Prop} (a : adjoin R {x}) (f : ∀ (p : Polynomial R), M (⟨aeval x p, aeval_mem_adjoin_singleton R x⟩ : adjoin R {x})) : M a := by obtain ⟨p, hp⟩ := Algebra.adjoin_eq_exists_aeval _ x a aesop instance instCommSemiringAdjoinSingleton : CommSemiring <| adjoin R {x} := { mul_comm := fun ⟨p, hp⟩ ⟨q, hq⟩ ↦ by obtain ⟨p', rfl⟩ := Algebra.adjoin_singleton_eq_range_aeval R x ▸ hp obtain ⟨q', rfl⟩ := Algebra.adjoin_singleton_eq_range_aeval R x ▸ hq simp only [AlgHom.toRingHom_eq_coe, RingHom.coe_coe, MulMemClass.mk_mul_mk, ← map_mul, mul_comm p' q'] } instance instCommRingAdjoinSingleton {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (x : A) : CommRing <| Algebra.adjoin R {x} := { mul_comm := mul_comm } end aeval end Polynomial
.lake/packages/mathlib/Mathlib/RingTheory/Adjoin/Dimension.lean
import Mathlib.Algebra.Group.Pointwise.Set.Card import Mathlib.LinearAlgebra.Dimension.Constructions import Mathlib.RingTheory.Adjoin.Basic /-! # Some results on dimensions of algebra adjoin This file contains some results on dimensions of `Algebra.adjoin`. -/ open Module universe u v namespace Subalgebra variable {R : Type u} {S : Type v} [CommRing R] [StrongRankCondition R] [CommRing S] [Algebra R S] (A B : Subalgebra R S) [Free R A] [Free R B] /-- If `A` and `B` are subalgebras of a commutative `R`-algebra `S`, both of them are free `R`-algebras, then the rank of the rank of the subalgebra generated by `A` and `B` over `R` is less than or equal to the product of that of `A` and `B`. -/ theorem rank_sup_le_of_free : Module.rank R ↥(A ⊔ B) ≤ Module.rank R A * Module.rank R B := by obtain ⟨ιA, bA⟩ := Free.exists_basis (R := R) (M := A) obtain ⟨ιB, bB⟩ := Free.exists_basis (R := R) (M := B) have h := Algebra.adjoin_union_coe_submodule R (A : Set S) (B : Set S) rw [A.adjoin_eq_span_basis R bA, B.adjoin_eq_span_basis R bB, ← Algebra.sup_def, Submodule.span_mul_span] at h change Module.rank R ↥(toSubmodule (A ⊔ B)) ≤ _ rw [h, ← bA.mk_eq_rank'', ← bB.mk_eq_rank''] refine (rank_span_le _).trans Cardinal.mk_mul_le |>.trans ?_ gcongr <;> exact Cardinal.mk_range_le /-- If `A` and `B` are subalgebras of a commutative `R`-algebra `S`, both of them are free `R`-algebras, then the `Module.finrank` of the rank of the subalgebra generated by `A` and `B` over `R` is less than or equal to the product of that of `A` and `B`. -/ theorem finrank_sup_le_of_free : finrank R ↥(A ⊔ B) ≤ finrank R A * finrank R B := by by_cases h : Module.Finite R A ∧ Module.Finite R B · obtain ⟨_, _⟩ := h simpa only [map_mul] using Cardinal.toNat_le_toNat (A.rank_sup_le_of_free B) (Cardinal.mul_lt_aleph0 (rank_lt_aleph0 R A) (rank_lt_aleph0 R B)) wlog hA : ¬ Module.Finite R A generalizing A B · have := this B A (fun h' ↦ h h'.symm) (not_and.1 h (of_not_not hA)) rwa [sup_comm, mul_comm] at this rw [← rank_lt_aleph0_iff, not_lt] at hA have := LinearMap.rank_le_of_injective _ <| Submodule.inclusion_injective <| show toSubmodule A ≤ toSubmodule (A ⊔ B) by simp rw [show finrank R A = 0 from Cardinal.toNat_apply_of_aleph0_le hA, show finrank R ↥(A ⊔ B) = 0 from Cardinal.toNat_apply_of_aleph0_le (hA.trans this), zero_mul] end Subalgebra
.lake/packages/mathlib/Mathlib/RingTheory/Algebraic/Integral.lean
import Mathlib.LinearAlgebra.Dimension.Localization import Mathlib.RingTheory.Algebraic.Basic import Mathlib.RingTheory.IntegralClosure.IsIntegralClosure.Basic import Mathlib.RingTheory.Localization.BaseChange /-! # Algebraic elements and integral elements This file relates algebraic and integral elements of an algebra, by proving every integral element is algebraic and that every algebraic element over a field is integral. ## Main results * `IsIntegral.isAlgebraic`, `Algebra.IsIntegral.isAlgebraic`: integral implies algebraic. * `isAlgebraic_iff_isIntegral`, `Algebra.isAlgebraic_iff_isIntegral`: integral iff algebraic over a field. * `IsAlgebraic.of_finite`, `Algebra.IsAlgebraic.of_finite`: finite-dimensional (as module) implies algebraic. * `IsAlgebraic.exists_integral_multiple`: an algebraic element has a multiple which is integral * `IsAlgebraic.iff_exists_smul_integral`: If `R` is reduced and `S` is an `R`-algebra with injective `algebraMap`, then an element of `S` is algebraic over `R` iff some `R`-multiple is integral over `R`. * `Algebra.IsAlgebraic.trans`: If `A/S/R` is a tower of algebras and both `A/S` and `S/R` are algebraic, then `A/R` is also algebraic, provided that `S` has no zero divisors. * `Subalgebra.algebraicClosure`: If `R` is a domain and `S` is an arbitrary `R`-algebra, then the elements of `S` that are algebraic over `R` form a subalgebra. * `Transcendental.extendScalars`: an element of an `R`-algebra that is transcendental over `R` remains transcendental over any algebraic `R`-subalgebra that has no zero divisors. -/ assert_not_exists IsLocalRing universe u v w open Polynomial section zero_ne_one variable {R : Type u} {S : Type*} {A : Type v} [CommRing R] variable [CommRing S] [Ring A] [Algebra R A] [Algebra R S] [Algebra S A] variable [IsScalarTower R S A] /-- An integral element of an algebra is algebraic. -/ theorem IsIntegral.isAlgebraic [Nontrivial R] {x : A} : IsIntegral R x → IsAlgebraic R x := fun ⟨p, hp, hpx⟩ => ⟨p, hp.ne_zero, hpx⟩ instance Algebra.IsIntegral.isAlgebraic [Nontrivial R] [Algebra.IsIntegral R A] : Algebra.IsAlgebraic R A := ⟨fun a ↦ (Algebra.IsIntegral.isIntegral a).isAlgebraic⟩ end zero_ne_one section Field variable {K : Type u} {A : Type v} [Field K] [Ring A] [Algebra K A] /-- An element of an algebra over a field is algebraic if and only if it is integral. -/ theorem isAlgebraic_iff_isIntegral {x : A} : IsAlgebraic K x ↔ IsIntegral K x := by refine ⟨?_, IsIntegral.isAlgebraic⟩ rintro ⟨p, hp, hpx⟩ refine ⟨_, monic_mul_leadingCoeff_inv hp, ?_⟩ rw [← aeval_def, map_mul, hpx, zero_mul] protected theorem Algebra.isAlgebraic_iff_isIntegral : Algebra.IsAlgebraic K A ↔ Algebra.IsIntegral K A := by rw [Algebra.isAlgebraic_def, Algebra.isIntegral_def, forall_congr' fun _ ↦ isAlgebraic_iff_isIntegral] alias ⟨IsAlgebraic.isIntegral, _⟩ := isAlgebraic_iff_isIntegral /-- This used to be an `alias` of `Algebra.isAlgebraic_iff_isIntegral` but that would make `Algebra.IsAlgebraic K A` an explicit parameter instead of instance implicit. -/ protected instance Algebra.IsAlgebraic.isIntegral [Algebra.IsAlgebraic K A] : Algebra.IsIntegral K A := Algebra.isAlgebraic_iff_isIntegral.mp ‹_› theorem Algebra.IsAlgebraic.of_isIntegralClosure (R B C : Type*) [CommRing R] [Nontrivial R] [CommRing B] [CommRing C] [Algebra R B] [Algebra R C] [Algebra B C] [IsScalarTower R B C] [IsIntegralClosure B R C] : Algebra.IsAlgebraic R B := have := IsIntegralClosure.isIntegral_algebra R (A := B) C inferInstance end Field section variable (K L R : Type*) {A : Type*} section Ring variable [CommRing R] [Nontrivial R] [Ring A] [Algebra R A] theorem IsAlgebraic.of_finite (e : A) [Module.Finite R A] : IsAlgebraic R e := (IsIntegral.of_finite R e).isAlgebraic variable (A) /-- A field extension is algebraic if it is finite. -/ @[stacks 09GG "first part"] instance Algebra.IsAlgebraic.of_finite [Module.Finite R A] : Algebra.IsAlgebraic R A := (IsIntegral.of_finite R A).isAlgebraic end Ring section Field variable {K L} [Field K] [Ring A] [Algebra K A] /-- If `K` is a field, `r : A` and `f : K[X]`, then `Polynomial.aeval r f` is transcendental over `K` if and only if `r` and `f` are both transcendental over `K`. See also `Transcendental.aeval_of_transcendental` and `Transcendental.of_aeval`. -/ @[simp] theorem transcendental_aeval_iff {r : A} {f : K[X]} : Transcendental K (Polynomial.aeval r f) ↔ Transcendental K r ∧ Transcendental K f := by refine ⟨fun h ↦ ⟨?_, h.of_aeval⟩, fun ⟨h1, h2⟩ ↦ h1.aeval_of_transcendental h2⟩ rw [Transcendental] at h ⊢ contrapose! h rw [isAlgebraic_iff_isIntegral] at h ⊢ exact .of_mem_of_fg _ h.fg_adjoin_singleton _ (aeval_mem_adjoin_singleton _ _) variable [Field L] [Algebra K L] theorem AlgHom.bijective [FiniteDimensional K L] (ϕ : L →ₐ[K] L) : Function.Bijective ϕ := (Algebra.IsAlgebraic.of_finite K L).algHom_bijective ϕ variable (K L) in /-- Bijection between algebra equivalences and algebra homomorphisms -/ noncomputable abbrev algEquivEquivAlgHom [FiniteDimensional K L] : (L ≃ₐ[K] L) ≃* (L →ₐ[K] L) := Algebra.IsAlgebraic.algEquivEquivAlgHom K L end Field end variable {R S A : Type*} [CommRing R] [CommRing S] [Ring A] variable [Algebra R S] [Algebra R A] [Algebra S A] [IsScalarTower R S A] variable {z : A} {z' : S} namespace IsAlgebraic theorem exists_integral_multiple (hz : IsAlgebraic R z) : ∃ y ≠ (0 : R), IsIntegral R (y • z) := by by_cases inj : Function.Injective (algebraMap R A); swap · rw [injective_iff_map_eq_zero] at inj; push_neg at inj have ⟨r, eq, ne⟩ := inj exact ⟨r, ne, by simpa [← algebraMap_smul A, eq, zero_smul] using isIntegral_zero⟩ have ⟨p, p_ne_zero, px⟩ := hz set a := p.leadingCoeff have a_ne_zero : a ≠ 0 := mt Polynomial.leadingCoeff_eq_zero.mp p_ne_zero have x_integral : IsIntegral R (algebraMap R A a * z) := ⟨p.integralNormalization, monic_integralNormalization p_ne_zero, integralNormalization_aeval_eq_zero px fun _ ↦ (map_eq_zero_iff _ inj).mp⟩ exact ⟨_, a_ne_zero, Algebra.smul_def a z ▸ x_integral⟩ variable (R) in theorem _root_.Algebra.IsAlgebraic.exists_integral_multiples [NoZeroDivisors R] [alg : Algebra.IsAlgebraic R A] (s : Finset A) : ∃ y ≠ (0 : R), ∀ z ∈ s, IsIntegral R (y • z) := by have := Algebra.IsAlgebraic.nontrivial R A choose r hr int using fun x ↦ (alg.1 x).exists_integral_multiple refine ⟨∏ x ∈ s, r x, Finset.prod_ne_zero_iff.mpr fun _ _ ↦ hr _, fun _ h ↦ ?_⟩ classical rw [← Finset.prod_erase_mul _ _ h, mul_smul] exact (int _).smul _ theorem of_smul_isIntegral {y : R} (hy : ¬ IsNilpotent y) (h : IsIntegral R (y • z)) : IsAlgebraic R z := by have ⟨p, monic, eval0⟩ := h refine ⟨p.comp (C y * X), fun h ↦ ?_, by simpa [aeval_comp, Algebra.smul_def] using eval0⟩ apply_fun (coeff · p.natDegree) at h have hy0 : y ≠ 0 := by rintro rfl; exact hy .zero rw [coeff_zero, ← mul_one p.natDegree, ← natDegree_C_mul_X y hy0, coeff_comp_degree_mul_degree, monic, one_mul, leadingCoeff_C_mul_X] at h · exact hy ⟨_, h⟩ · rw [natDegree_C_mul_X _ hy0]; rintro ⟨⟩ theorem of_smul {y : R} (hy : y ∈ nonZeroDivisors R) (h : IsAlgebraic R (y • z)) : IsAlgebraic R z := have ⟨p, hp, eval0⟩ := h ⟨_, mt (comp_C_mul_X_eq_zero_iff hy).mp hp, by simpa [aeval_comp, Algebra.smul_def] using eval0⟩ theorem iff_exists_smul_integral [IsReduced R] : IsAlgebraic R z ↔ ∃ y ≠ (0 : R), IsIntegral R (y • z) := ⟨(exists_integral_multiple ·), fun ⟨_, hy, int⟩ ↦ of_smul_isIntegral (by rwa [isNilpotent_iff_eq_zero]) int⟩ section restrictScalars variable (R) [NoZeroDivisors S] /-! The next theorem may fail if only `R` is assumed to be a domain but `S` is not: for example, let `S = R[X] ⧸ (X² - X)` and let `A` be the subalgebra of `S[Y]` generated by `XY`. `A` is algebraic over `S` because any element `∑ᵢ sᵢ(XY)ⁱ` is a root of the polynomial `(X - 1)(Z - s₀)` in `S[Z]`, because `X(X - 1) = X² - X = 0` in `S`. However, `XY` is a transcendental element in `A` over `R`, because `∑ᵢ rᵢ(XY)ⁱ = 0` in `S[Y]` implies all `rᵢXⁱ = 0` (i.e., `r₀ = 0` and `rᵢX = 0` for `i > 0`) in `S`, which implies `rᵢ = 0` in `R`. This example is inspired by the comment https://mathoverflow.net/questions/482944/when-do-algebraic-elements-form-a-subalgebra#comment1257632_482944. -/ theorem restrictScalars_of_isIntegral [int : Algebra.IsIntegral R S] {a : A} (h : IsAlgebraic S a) : IsAlgebraic R a := by by_cases hRS : Function.Injective (algebraMap R S) on_goal 2 => exact (Algebra.isAlgebraic_of_not_injective fun h ↦ hRS <| .of_comp (IsScalarTower.algebraMap_eq R S A ▸ h)).1 _ have := hRS.noZeroDivisors _ (map_zero _) (map_mul _) have ⟨s, hs, int_s⟩ := h.exists_integral_multiple cases subsingleton_or_nontrivial R · have := Module.subsingleton R S exact (is_transcendental_of_subsingleton _ _ h).elim have ⟨r, hr, _, e⟩ := (int.1 s).isAlgebraic.exists_nonzero_dvd (mem_nonZeroDivisors_of_ne_zero hs) refine .of_smul_isIntegral (y := r) (by rwa [isNilpotent_iff_eq_zero]) ?_ rw [Algebra.smul_def, IsScalarTower.algebraMap_apply R S, e, ← Algebra.smul_def, mul_comm, mul_smul] exact isIntegral_trans _ (int_s.smul _) theorem restrictScalars [Algebra.IsAlgebraic R S] {a : A} (h : IsAlgebraic S a) : IsAlgebraic R a := by have ⟨p, hp, eval0⟩ := h by_cases hRS : Function.Injective (algebraMap R S) on_goal 2 => exact (Algebra.isAlgebraic_of_not_injective fun h ↦ hRS <| .of_comp (IsScalarTower.algebraMap_eq R S A ▸ h)).1 _ have := hRS.noZeroDivisors _ (map_zero _) (map_mul _) classical have ⟨r, hr, int⟩ := Algebra.IsAlgebraic.exists_integral_multiples R (p.support.image (coeff p)) let p := (r • p).toSubring (integralClosure R S).toSubring fun s hs ↦ by obtain ⟨n, hn, rfl⟩ := mem_coeffs_iff.mp hs exact int _ (Finset.mem_image_of_mem _ <| support_smul _ _ hn) have : IsAlgebraic (integralClosure R S) a := by refine ⟨p, ?_, ?_⟩ · have : FaithfulSMul R S := (faithfulSMul_iff_algebraMap_injective R S).mpr hRS simpa only [← Polynomial.map_ne_zero_iff (f := Subring.subtype _) Subtype.val_injective, p, map_toSubring, smul_ne_zero_iff] using And.intro hr hp rw [← eval_map_algebraMap, Subalgebra.algebraMap_eq, ← map_map, ← Subalgebra.toSubring_subtype, map_toSubring, eval_map_algebraMap, ← AlgHom.restrictScalars_apply R, map_smul, AlgHom.restrictScalars_apply, eval0, smul_zero] exact restrictScalars_of_isIntegral _ this theorem _root_.IsIntegral.trans_isAlgebraic [alg : Algebra.IsAlgebraic R S] {a : A} (h : IsIntegral S a) : IsAlgebraic R a := by cases subsingleton_or_nontrivial A · have := Algebra.IsAlgebraic.nontrivial R S exact Subsingleton.elim a 0 ▸ isAlgebraic_zero · have := Module.nontrivial S A exact h.isAlgebraic.restrictScalars _ end restrictScalars section Ring variable (s : S) {a : A} (ha : IsAlgebraic R a) include ha protected lemma neg : IsAlgebraic R (-a) := have ⟨p, h, eval0⟩ := ha ⟨algEquivAevalNegX p, EmbeddingLike.map_ne_zero_iff.mpr h, by simpa [← comp_eq_aeval, aeval_comp]⟩ protected lemma smul (r : R) : IsAlgebraic R (r • a) := have ⟨_, hp, eval0⟩ := ha ⟨_, scaleRoots_ne_zero hp r, Algebra.smul_def r a ▸ scaleRoots_aeval_eq_zero eval0⟩ protected lemma nsmul (n : ℕ) : IsAlgebraic R (n • a) := Nat.cast_smul_eq_nsmul R n a ▸ ha.smul _ protected lemma zsmul (n : ℤ) : IsAlgebraic R (n • a) := Int.cast_smul_eq_zsmul R n a ▸ ha.smul _ omit [Algebra S A] [IsScalarTower R S A] in lemma tmul [FaithfulSMul R S] : IsAlgebraic S (s ⊗ₜ[R] a) := by rw [← mul_one s, ← smul_eq_mul, ← TensorProduct.smul_tmul'] have ⟨p, h, eval0⟩ := ha refine .smul ⟨p.map (algebraMap R S), (Polynomial.map_ne_zero_iff <| FaithfulSMul.algebraMap_injective ..).mpr h, ?_⟩ _ rw [← Algebra.TensorProduct.includeRight_apply, ← AlgHom.coe_toRingHom (A := A), ← map_aeval_eq_aeval_map (by ext; simp), eval0, map_zero] end Ring section CommRing variable [NoZeroDivisors R] {a b : S} (ha : IsAlgebraic R a) (hb : IsAlgebraic R b) include ha hb protected lemma mul : IsAlgebraic R (a * b) := by have ⟨ra, a0, int_a⟩ := ha.exists_integral_multiple have ⟨rb, b0, int_b⟩ := hb.exists_integral_multiple refine IsAlgebraic.iff_exists_smul_integral.mpr ⟨_, mul_ne_zero a0 b0, ?_⟩ simp_rw [Algebra.smul_def, map_mul, mul_mul_mul_comm, ← Algebra.smul_def] exact int_a.mul int_b protected lemma add : IsAlgebraic R (a + b) := by have ⟨ra, a0, int_a⟩ := ha.exists_integral_multiple have ⟨rb, b0, int_b⟩ := hb.exists_integral_multiple refine IsAlgebraic.iff_exists_smul_integral.mpr ⟨_, mul_ne_zero b0 a0, ?_⟩ rw [smul_add, mul_smul, mul_comm, mul_smul] exact (int_a.smul _).add (int_b.smul _) protected lemma sub : IsAlgebraic R (a - b) := sub_eq_add_neg a b ▸ ha.add hb.neg omit hb protected lemma pow (n : ℕ) : IsAlgebraic R (a ^ n) := have := ha.nontrivial n.rec (pow_zero a ▸ isAlgebraic_one) fun _ h ↦ pow_succ a _ ▸ h.mul ha end CommRing end IsAlgebraic namespace Algebra variable (R S A) [NoZeroDivisors S] /-- Transitivity of algebraicity for algebras over domains. -/ @[stacks 09GJ] theorem IsAlgebraic.trans [Algebra.IsAlgebraic R S] [alg : Algebra.IsAlgebraic S A] : Algebra.IsAlgebraic R A := ⟨fun _ ↦ (alg.1 _).restrictScalars _⟩ theorem IsIntegral.trans_isAlgebraic [Algebra.IsIntegral R S] [alg : Algebra.IsAlgebraic S A] : Algebra.IsAlgebraic R A := ⟨fun _ ↦ (alg.1 _).restrictScalars_of_isIntegral _⟩ theorem IsAlgebraic.trans_isIntegral [Algebra.IsAlgebraic R S] [int : Algebra.IsIntegral S A] : Algebra.IsAlgebraic R A := ⟨fun _ ↦ (int.1 _).trans_isAlgebraic _⟩ variable {A} protected theorem IsIntegral.isAlgebraic_iff [Algebra.IsIntegral R S] [FaithfulSMul R S] {a : A} : IsAlgebraic R a ↔ IsAlgebraic S a := ⟨.extendScalars (FaithfulSMul.algebraMap_injective ..), .restrictScalars_of_isIntegral _⟩ theorem IsIntegral.isAlgebraic_iff_top [Algebra.IsIntegral R S] [FaithfulSMul R S] : Algebra.IsAlgebraic R A ↔ Algebra.IsAlgebraic S A := by simp_rw [Algebra.isAlgebraic_def, Algebra.IsIntegral.isAlgebraic_iff R S] protected theorem IsAlgebraic.isAlgebraic_iff [Algebra.IsAlgebraic R S] [FaithfulSMul R S] {a : A} : IsAlgebraic R a ↔ IsAlgebraic S a := ⟨.extendScalars (FaithfulSMul.algebraMap_injective ..), .restrictScalars _⟩ theorem IsAlgebraic.isAlgebraic_iff_top [Algebra.IsAlgebraic R S] [FaithfulSMul R S] : Algebra.IsAlgebraic R A ↔ Algebra.IsAlgebraic S A := by simp_rw [Algebra.isAlgebraic_def, Algebra.IsAlgebraic.isAlgebraic_iff R S] theorem IsAlgebraic.isAlgebraic_iff_bot [Algebra.IsAlgebraic S A] [FaithfulSMul S A] : Algebra.IsAlgebraic R A ↔ Algebra.IsAlgebraic R S := ⟨fun _ ↦ .tower_bot_of_injective (FaithfulSMul.algebraMap_injective S A), fun _ ↦ .trans R S A⟩ end Algebra variable (R S) /-- If `R` is a domain and `S` is an arbitrary `R`-algebra, then the elements of `S` that are algebraic over `R` form a subalgebra. -/ def Subalgebra.algebraicClosure [IsDomain R] : Subalgebra R S where carrier := {s | IsAlgebraic R s} mul_mem' ha hb := ha.mul hb add_mem' ha hb := ha.add hb algebraMap_mem' := isAlgebraic_algebraMap theorem Subalgebra.mem_algebraicClosure [IsDomain R] {x : S} : x ∈ algebraicClosure R S ↔ IsAlgebraic R x := Iff.rfl theorem integralClosure_le_algebraicClosure [IsDomain R] : integralClosure R S ≤ Subalgebra.algebraicClosure R S := fun _ ↦ IsIntegral.isAlgebraic theorem Subalgebra.algebraicClosure_eq_integralClosure {K} [Field K] [Algebra K S] : algebraicClosure K S = integralClosure K S := SetLike.ext fun _ ↦ isAlgebraic_iff_isIntegral instance [IsDomain R] : Algebra.IsAlgebraic R (Subalgebra.algebraicClosure R S) := (Subalgebra.isAlgebraic_iff _).mp fun _ ↦ id variable {R S} theorem Algebra.isAlgebraic_adjoin_iff [IsDomain R] {s : Set S} : (adjoin R s).IsAlgebraic ↔ ∀ x ∈ s, IsAlgebraic R x := Algebra.adjoin_le_iff (S := Subalgebra.algebraicClosure R S) theorem Algebra.isAlgebraic_adjoin_of_nonempty [NoZeroDivisors R] {s : Set S} (hs : s.Nonempty) : (adjoin R s).IsAlgebraic ↔ ∀ x ∈ s, IsAlgebraic R x := ⟨fun h x hx ↦ h _ (subset_adjoin hx), fun h ↦ have ⟨x, hx⟩ := hs have := (isDomain_iff_noZeroDivisors_and_nontrivial _).mpr ⟨‹_›, (h x hx).nontrivial⟩ isAlgebraic_adjoin_iff.mpr h⟩ /-- In an algebra generated by a single algebraic element over a domain `R`, every element is algebraic. This may fail when `R` is not a domain: see https://mathoverflow.net/a/132192/ for an example. -/ theorem Algebra.isAlgebraic_adjoin_singleton_iff [NoZeroDivisors R] {s : S} : (adjoin R {s}).IsAlgebraic ↔ IsAlgebraic R s := (isAlgebraic_adjoin_of_nonempty <| Set.singleton_nonempty s).trans forall_eq theorem IsAlgebraic.of_mul [NoZeroDivisors R] {y z : S} (hy : y ∈ nonZeroDivisors S) (alg_y : IsAlgebraic R y) (alg_yz : IsAlgebraic R (y * z)) : IsAlgebraic R z := by have ⟨t, ht, r, hr, eq⟩ := alg_y.exists_nonzero_eq_adjoin_mul hy have := alg_yz.mul (Algebra.isAlgebraic_adjoin_singleton_iff.mpr alg_y _ ht) rw [mul_right_comm, eq, ← Algebra.smul_def] at this exact this.of_smul (mem_nonZeroDivisors_of_ne_zero hr) open Algebra in omit [Algebra R A] [IsScalarTower R S A] in theorem IsAlgebraic.adjoin_of_forall_isAlgebraic [NoZeroDivisors S] {s t : Set S} (alg : ∀ x ∈ s \ t, IsAlgebraic (adjoin R t) x) {a : A} (ha : IsAlgebraic (adjoin R s) a) : IsAlgebraic (adjoin R t) a := by set Rs := adjoin R s set Rt := adjoin R t let Rts := adjoin Rt s let _ : Algebra Rs Rts := (Subalgebra.inclusion (T := Rts.restrictScalars R) <| adjoin_le <| by apply subset_adjoin).toAlgebra have : IsScalarTower Rs Rts A := .of_algebraMap_eq fun ⟨a, _⟩ ↦ rfl have : Algebra.IsAlgebraic Rt Rts := by have := ha.nontrivial have := Subtype.val_injective (p := (· ∈ Rs)).nontrivial have := (isDomain_iff_noZeroDivisors_and_nontrivial Rt).mpr ⟨inferInstance, inferInstance⟩ rw [← Subalgebra.isAlgebraic_iff, isAlgebraic_adjoin_iff] intro x hs by_cases ht : x ∈ t · exact isAlgebraic_algebraMap (⟨x, subset_adjoin ht⟩ : Rt) exact alg _ ⟨hs, ht⟩ have : IsAlgebraic Rts a := ha.extendScalars (by apply Subalgebra.inclusion_injective) exact this.restrictScalars Rt namespace Transcendental section variable (S) [NoZeroDivisors S] {a : A} (ha : Transcendental R a) include ha lemma extendScalars_of_isIntegral [Algebra.IsIntegral R S] : Transcendental S a := by contrapose ha rw [Transcendental, not_not] at ha ⊢ exact ha.restrictScalars_of_isIntegral _ lemma extendScalars [Algebra.IsAlgebraic R S] : Transcendental S a := by contrapose ha rw [Transcendental, not_not] at ha ⊢ exact ha.restrictScalars _ end variable [NoZeroDivisors S] {a : S} (ha : Transcendental R a) include ha protected lemma integralClosure : Transcendental (integralClosure R S) a := ha.extendScalars_of_isIntegral _ lemma subalgebraAlgebraicClosure [IsDomain R] : Transcendental (Subalgebra.algebraicClosure R S) a := ha.extendScalars _ end Transcendental namespace Algebra variable (R S) [NoZeroDivisors S] [FaithfulSMul R S] {a : A} protected theorem IsIntegral.transcendental_iff [Algebra.IsIntegral R S] : Transcendental R a ↔ Transcendental S a := ⟨(·.extendScalars_of_isIntegral _), (·.restrictScalars (FaithfulSMul.algebraMap_injective R S))⟩ protected theorem IsAlgebraic.transcendental_iff [Algebra.IsAlgebraic R S] : Transcendental R a ↔ Transcendental S a := ⟨(·.extendScalars _), (·.restrictScalars (FaithfulSMul.algebraMap_injective R S))⟩ end Algebra open scoped nonZeroDivisors namespace Algebra.IsAlgebraic section IsFractionRing variable (R S) (R' S' : Type*) [CommRing S'] [FaithfulSMul R S] [alg : Algebra.IsAlgebraic R S] [NoZeroDivisors S] [Algebra S S'] [IsFractionRing S S'] instance : IsLocalization (algebraMapSubmonoid S R⁰) S' := have := (FaithfulSMul.algebraMap_injective R S).noZeroDivisors _ (map_zero _) (map_mul _) (IsLocalization.iff_of_le_of_exists_dvd _ S⁰ (map_le_nonZeroDivisors_of_injective _ (FaithfulSMul.algebraMap_injective ..) le_rfl) fun s hs ↦ have ⟨r, ne, eq⟩ := (alg.1 s).exists_nonzero_dvd hs ⟨_, ⟨r, mem_nonZeroDivisors_of_ne_zero ne, rfl⟩, eq⟩).mpr inferInstance variable [Algebra R S'] [IsScalarTower R S S'] instance : IsLocalizedModule R⁰ (IsScalarTower.toAlgHom R S S').toLinearMap := isLocalizedModule_iff_isLocalization.mpr inferInstance variable [CommRing R'] [Algebra R R'] [IsFractionRing R R'] theorem isBaseChange_of_isFractionRing [Module R' S'] [IsScalarTower R R' S'] : IsBaseChange R' (IsScalarTower.toAlgHom R S S').toLinearMap := (isLocalizedModule_iff_isBaseChange R⁰ ..).mp inferInstance variable [Algebra R' S'] [IsScalarTower R R' S'] instance : IsPushout R R' S S' := (isPushout_iff ..).mpr <| isBaseChange_of_isFractionRing .. instance : IsPushout R S R' S' := .symm inferInstance end IsFractionRing variable (R) (R' : Type*) (S : Type u) [CommRing R'] [CommRing S] [Algebra R S] [Algebra R R'] [IsFractionRing R R'] [FaithfulSMul R S] [Algebra.IsAlgebraic R S] section variable [NoZeroDivisors S] (S' : Type v) [CommRing S'] [Algebra R S'] [Algebra S S'] [Module R' S'] [IsScalarTower R R' S'] [IsScalarTower R S S'] [IsFractionRing S S'] theorem lift_rank_of_isFractionRing : Cardinal.lift.{u} (Module.rank R' S') = Cardinal.lift.{v} (Module.rank R S) := by rw [IsLocalization.rank_eq R' R⁰ le_rfl, IsLocalizedModule.lift_rank_eq R⁰ (IsScalarTower.toAlgHom R S S').toLinearMap le_rfl] theorem finrank_of_isFractionRing : Module.finrank R' S' = Module.finrank R S := by simpa using congr_arg Cardinal.toNat (lift_rank_of_isFractionRing ..) theorem rank_of_isFractionRing (S' : Type u) [CommRing S'] [Algebra R S'] [Algebra S S'] [Module R' S'] [IsScalarTower R R' S'] [IsScalarTower R S S'] [IsFractionRing S S'] : Module.rank R' S' = Module.rank R S := by simpa using lift_rank_of_isFractionRing R R' S S' end attribute [local instance] FractionRing.liftAlgebra in theorem rank_fractionRing [IsDomain S] : Module.rank (FractionRing R) (FractionRing S) = Module.rank R S := rank_of_isFractionRing .. end Algebra.IsAlgebraic section Polynomial attribute [local instance] Polynomial.algebra MvPolynomial.algebraMvPolynomial section variable (R S) [NoZeroDivisors R] -- TODO: `PolynomialModule` version theorem rank_polynomial_polynomial : Module.rank R[X] S[X] = Module.rank R S := ((Algebra.isPushout_iff ..).mp inferInstance).rank_eq theorem rank_mvPolynomial_mvPolynomial (σ : Type u) : Module.rank (MvPolynomial σ R) (MvPolynomial σ S) = Cardinal.lift.{u} (Module.rank R S) := by have := Algebra.isPushout_iff R (MvPolynomial σ R) S (MvPolynomial σ S) |>.mp inferInstance |>.lift_rank_eq rwa [Cardinal.lift_id', Cardinal.lift_umax] at this end variable [alg : Algebra.IsAlgebraic R S] section Pushout variable (R S) (R' : Type*) [CommRing R'] [Algebra R R'] [NoZeroDivisors R'] [FaithfulSMul R R'] open TensorProduct in instance Algebra.IsAlgebraic.tensorProduct : Algebra.IsAlgebraic R' (R' ⊗[R] S) where isAlgebraic p := have := IsAlgebraic.nontrivial R S have := (FaithfulSMul.algebraMap_injective R R').nontrivial p.induction_on isAlgebraic_zero (fun _ s ↦ .tmul _ <| alg.1 s) (fun _ _ ↦ .add) variable (S' : Type*) [CommRing S'] [Algebra R S'] [Algebra S S'] [Algebra R' S'] [IsScalarTower R R' S'] [IsScalarTower R S S'] theorem Algebra.IsPushout.isAlgebraic' [IsPushout R R' S S'] : Algebra.IsAlgebraic R' S' := (equiv R R' S S').isAlgebraic theorem Algebra.IsPushout.isAlgebraic [h : IsPushout R S R' S'] : Algebra.IsAlgebraic R' S' := have := h.symm; (equiv R R' S S').isAlgebraic end Pushout instance [NoZeroDivisors R] : Algebra.IsAlgebraic R[X] S[X] := Algebra.IsPushout.isAlgebraic R S .. instance [NoZeroDivisors S] : Algebra.IsAlgebraic R[X] S[X] := by by_cases h : Function.Injective (algebraMap R S) · have := h.noZeroDivisors _ (map_zero _) (map_mul _); infer_instance rw [← Polynomial.map_injective_iff] at h exact Algebra.isAlgebraic_of_not_injective h theorem Polynomial.exists_dvd_map_of_isAlgebraic [NoZeroDivisors S] {f : S[X]} (hf : f ≠ 0) : ∃ g : R[X], g ≠ 0 ∧ f ∣ g.map (algebraMap R S) := (Algebra.IsAlgebraic.isAlgebraic f).exists_nonzero_dvd (mem_nonZeroDivisors_of_ne_zero hf) instance {σ} [NoZeroDivisors R] : Algebra.IsAlgebraic (MvPolynomial σ R) (MvPolynomial σ S) := Algebra.IsPushout.isAlgebraic R S .. instance {σ} [NoZeroDivisors S] : Algebra.IsAlgebraic (MvPolynomial σ R) (MvPolynomial σ S) := by by_cases h : Function.Injective (algebraMap R S) · have := h.noZeroDivisors _ (map_zero _) (map_mul _); infer_instance rw [← MvPolynomial.map_injective_iff] at h exact Algebra.isAlgebraic_of_not_injective h theorem MvPolynomial.exists_dvd_map_of_isAlgebraic {σ} [NoZeroDivisors S] {f : MvPolynomial σ S} (hf : f ≠ 0) : ∃ g : MvPolynomial σ R, g ≠ 0 ∧ f ∣ g.map (algebraMap R S) := (Algebra.IsAlgebraic.isAlgebraic f).exists_nonzero_dvd (mem_nonZeroDivisors_of_ne_zero hf) variable [IsDomain S] [FaithfulSMul R S] attribute [local instance] FractionRing.liftAlgebra instance : Algebra.IsPushout R (FractionRing R[X]) S (FractionRing S[X]) := (Algebra.IsPushout.comp_iff _ R[X] _ S[X]).mpr inferInstance instance : Algebra.IsPushout R S (FractionRing R[X]) (FractionRing S[X]) := .symm inferInstance instance {σ : Type*} : Algebra.IsPushout R (FractionRing (MvPolynomial σ R)) S (FractionRing (MvPolynomial σ S)) := (Algebra.IsPushout.comp_iff _ (MvPolynomial σ R) _ (MvPolynomial σ S)).mpr inferInstance instance {σ : Type*} : Algebra.IsPushout R S (FractionRing (MvPolynomial σ R)) (FractionRing (MvPolynomial σ S)) := .symm inferInstance namespace Algebra.IsAlgebraic @[stacks 0G1M] theorem rank_fractionRing_polynomial : Module.rank (FractionRing R[X]) (FractionRing S[X]) = Module.rank R S := by have := (FaithfulSMul.algebraMap_injective R S).isDomain rw [rank_fractionRing, rank_polynomial_polynomial] open Cardinal in @[stacks 0G1M] theorem rank_fractionRing_mvPolynomial (σ : Type u) : Module.rank (FractionRing (MvPolynomial σ R)) (FractionRing (MvPolynomial σ S)) = lift.{u} (Module.rank R S) := by have := (FaithfulSMul.algebraMap_injective R S).isDomain rw [rank_fractionRing, rank_mvPolynomial_mvPolynomial] end Algebra.IsAlgebraic end Polynomial section FractionRing open Algebra Module open scoped nonZeroDivisors attribute [local instance] FractionRing.liftAlgebra instance [IsDomain R] [IsDomain S] [NoZeroSMulDivisors R S] [Module.Finite R S] : FiniteDimensional (FractionRing R) (FractionRing S) := by obtain ⟨_, s, hs⟩ := Module.Finite.exists_fin (R := R) (M := S) exact Module.finite_def.mpr <| (span_eq_top_localization_localization (FractionRing R) R⁰ (FractionRing S) hs) ▸ Submodule.fg_span (Set.toFinite _) end FractionRing
.lake/packages/mathlib/Mathlib/RingTheory/Algebraic/Pi.lean
import Mathlib.Algebra.Polynomial.AlgebraMap /-! # Algebraic functions This file defines algebraic functions as the image of the `algebraMap R[X] (R → S)`. -/ assert_not_exists IsIntegralClosure LinearIndependent IsLocalRing MvPolynomial open Polynomial section Pi variable (R S T : Type*) /-- This is not an instance as it forms a diamond with `Pi.instSMul`. See the `instance_diamonds` test for details. -/ def Polynomial.hasSMulPi [Semiring R] [SMul R S] : SMul R[X] (R → S) := ⟨fun p f x => eval x p • f x⟩ /-- This is not an instance as it forms a diamond with `Pi.instSMul`. See the `instance_diamonds` test for details. -/ noncomputable def Polynomial.hasSMulPi' [CommSemiring R] [Semiring S] [Algebra R S] [SMul S T] : SMul R[X] (S → T) := ⟨fun p f x => aeval x p • f x⟩ attribute [local instance] Polynomial.hasSMulPi Polynomial.hasSMulPi' @[simp] theorem polynomial_smul_apply [Semiring R] [SMul R S] (p : R[X]) (f : R → S) (x : R) : (p • f) x = eval x p • f x := rfl @[simp] theorem polynomial_smul_apply' [CommSemiring R] [Semiring S] [Algebra R S] [SMul S T] (p : R[X]) (f : S → T) (x : S) : (p • f) x = aeval x p • f x := rfl variable [CommSemiring R] [CommSemiring S] [CommSemiring T] [Algebra R S] [Algebra S T] /-- This is not an instance for the same reasons as `Polynomial.hasSMulPi'`. -/ noncomputable def Polynomial.algebraPi : Algebra R[X] (S → T) where __ := Polynomial.hasSMulPi' R S T algebraMap := { toFun p z := algebraMap S T (aeval z p) map_one' := funext fun z => by simp only [Pi.one_apply, map_one] map_mul' _ _ := funext fun z => by simp only [Pi.mul_apply, map_mul] map_zero' := funext fun z => by simp only [Pi.zero_apply, map_zero] map_add' _ _ := funext fun z => by simp only [Pi.add_apply, map_add] } commutes' _ _ := funext fun z => by exact mul_comm _ _ smul_def' _ _ := funext fun z => by simp only [polynomial_smul_apply', Algebra.algebraMap_eq_smul_one, RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk, Pi.mul_apply, Algebra.smul_mul_assoc, one_mul] attribute [local instance] Polynomial.algebraPi @[simp] theorem Polynomial.algebraMap_pi_eq_aeval : (algebraMap R[X] (S → T) : R[X] → S → T) = fun p z => algebraMap _ _ (aeval z p) := rfl @[simp] theorem Polynomial.algebraMap_pi_self_eq_eval : (algebraMap R[X] (R → R) : R[X] → R → R) = fun p z => eval z p := rfl end Pi
.lake/packages/mathlib/Mathlib/RingTheory/Algebraic/Basic.lean
import Mathlib.Algebra.Polynomial.Expand import Mathlib.Algebra.Polynomial.Roots import Mathlib.RingTheory.Adjoin.Polynomial import Mathlib.RingTheory.Algebraic.Defs import Mathlib.RingTheory.Polynomial.Tower /-! # Algebraic elements and algebraic extensions An element of an R-algebra is algebraic over R if it is the root of a nonzero polynomial. An R-algebra is algebraic over R if and only if all its elements are algebraic over R. The main result in this file proves transitivity of algebraicity: a tower of algebraic field extensions is algebraic. -/ universe u v w open Polynomial nonZeroDivisors section variable (R : Type u) {A : Type v} [CommRing R] [Ring A] [Algebra R A] @[nontriviality] theorem is_transcendental_of_subsingleton [Subsingleton R] (x : A) : Transcendental R x := fun ⟨p, h, _⟩ => h <| Subsingleton.elim p 0 variable {R} theorem IsAlgebraic.nontrivial {a : A} (h : IsAlgebraic R a) : Nontrivial R := by contrapose! h apply is_transcendental_of_subsingleton variable (R A) theorem Algebra.IsAlgebraic.nontrivial [alg : Algebra.IsAlgebraic R A] : Nontrivial R := (alg.1 0).nontrivial instance (priority := low) Algebra.transcendental_of_subsingleton [Subsingleton R] : Algebra.Transcendental R A := ⟨⟨0, is_transcendental_of_subsingleton R 0⟩⟩ theorem Polynomial.transcendental_X : Transcendental R (X (R := R)) := by simp [transcendental_iff] variable {R A} theorem IsAlgebraic.of_aeval {r : A} (f : R[X]) (hf : f.natDegree ≠ 0) (hf' : f.leadingCoeff ∈ R⁰) (H : IsAlgebraic R (aeval r f)) : IsAlgebraic R r := by obtain ⟨p, h1, h2⟩ := H have : (p.comp f).coeff (p.natDegree * f.natDegree) ≠ 0 := fun h ↦ h1 <| by rwa [coeff_comp_degree_mul_degree hf, mul_right_mem_nonZeroDivisors_eq_zero_iff (pow_mem hf' _), leadingCoeff_eq_zero] at h exact ⟨p.comp f, fun h ↦ this (by simp [h]), by rwa [aeval_comp]⟩ theorem Transcendental.aeval {r : A} (H : Transcendental R r) (f : R[X]) (hf : f.natDegree ≠ 0) (hf' : f.leadingCoeff ∈ R⁰) : Transcendental R (aeval r f) := fun h ↦ H (h.of_aeval f hf hf') /-- If `r : A` and `f : R[X]` are transcendental over `R`, then `Polynomial.aeval r f` is also transcendental over `R`. For the converse, see `Transcendental.of_aeval` and `transcendental_aeval_iff`. -/ theorem Transcendental.aeval_of_transcendental {r : A} (H : Transcendental R r) {f : R[X]} (hf : Transcendental R f) : Transcendental R (Polynomial.aeval r f) := by rw [transcendental_iff] at H hf ⊢ intro p hp exact hf _ (H _ (by rwa [← aeval_comp, comp_eq_aeval] at hp)) /-- If `Polynomial.aeval r f` is transcendental over `R`, then `f : R[X]` is also transcendental over `R`. In fact, the `r` is also transcendental over `R` provided that `R` is a field (see `transcendental_aeval_iff`). -/ theorem Transcendental.of_aeval {r : A} {f : R[X]} (H : Transcendental R (Polynomial.aeval r f)) : Transcendental R f := by rw [transcendental_iff] at H ⊢ intro p hp exact H p (by rw [← aeval_comp, comp_eq_aeval, hp, map_zero]) theorem IsAlgebraic.of_aeval_of_transcendental {r : A} {f : R[X]} (H : IsAlgebraic R (aeval r f)) (hf : Transcendental R f) : IsAlgebraic R r := by contrapose H exact Transcendental.aeval_of_transcendental H hf theorem Polynomial.transcendental (f : R[X]) (hf : f.natDegree ≠ 0) (hf' : f.leadingCoeff ∈ R⁰) : Transcendental R f := by simpa using (transcendental_X R).aeval f hf hf' theorem isAlgebraic_iff_not_injective {x : A} : IsAlgebraic R x ↔ ¬Function.Injective (Polynomial.aeval x : R[X] →ₐ[R] A) := by simp only [IsAlgebraic, injective_iff_map_eq_zero, not_forall, and_comm, exists_prop] /-- An element `x` is transcendental over `R` if and only if the map `Polynomial.aeval x` is injective. This is similar to `algebraicIndependent_iff_injective_aeval`. -/ theorem transcendental_iff_injective {x : A} : Transcendental R x ↔ Function.Injective (Polynomial.aeval x : R[X] →ₐ[R] A) := isAlgebraic_iff_not_injective.not_left /-- An element `x` is transcendental over `R` if and only if the kernel of the ring homomorphism `Polynomial.aeval x` is the zero ideal. This is similar to `algebraicIndependent_iff_ker_eq_bot`. -/ theorem transcendental_iff_ker_eq_bot {x : A} : Transcendental R x ↔ RingHom.ker (aeval (R := R) x) = ⊥ := by rw [transcendental_iff_injective, RingHom.injective_iff_ker_eq_bot] theorem Algebra.isAlgebraic_of_not_injective (h : ¬ Function.Injective (algebraMap R A)) : Algebra.IsAlgebraic R A where isAlgebraic a := isAlgebraic_iff_not_injective.mpr fun inj ↦ h <| by convert inj.comp C_injective; ext; simp theorem Algebra.injective_of_transcendental [h : Algebra.Transcendental R A] : Function.Injective (algebraMap R A) := by rw [transcendental_iff_not_isAlgebraic] at h contrapose! h exact isAlgebraic_of_not_injective h end section zero_ne_one variable {R : Type u} {S : Type*} {A : Type v} [CommRing R] variable [CommRing S] [Ring A] [Algebra R A] [Algebra R S] [Algebra S A] variable [IsScalarTower R S A] theorem isAlgebraic_zero [Nontrivial R] : IsAlgebraic R (0 : A) := ⟨_, X_ne_zero, aeval_X 0⟩ /-- An element of `R` is algebraic, when viewed as an element of the `R`-algebra `A`. -/ theorem isAlgebraic_algebraMap [Nontrivial R] (x : R) : IsAlgebraic R (algebraMap R A x) := ⟨_, X_sub_C_ne_zero x, by rw [map_sub, aeval_X, aeval_C, sub_self]⟩ theorem isAlgebraic_one [Nontrivial R] : IsAlgebraic R (1 : A) := by rw [← map_one (algebraMap R A)] exact isAlgebraic_algebraMap 1 theorem isAlgebraic_nat [Nontrivial R] (n : ℕ) : IsAlgebraic R (n : A) := by rw [← map_natCast (_ : R →+* A) n] exact isAlgebraic_algebraMap (Nat.cast n) theorem isAlgebraic_int [Nontrivial R] (n : ℤ) : IsAlgebraic R (n : A) := by rw [← map_intCast (algebraMap R A)] exact isAlgebraic_algebraMap (Int.cast n) theorem isAlgebraic_rat (R : Type u) {A : Type v} [DivisionRing A] [Field R] [Algebra R A] (n : ℚ) : IsAlgebraic R (n : A) := by rw [← map_ratCast (algebraMap R A)] exact isAlgebraic_algebraMap (Rat.cast n) theorem isAlgebraic_of_mem_rootSet {R : Type u} {A : Type v} [CommRing R] [Field A] [Algebra R A] {p : R[X]} {x : A} (hx : x ∈ p.rootSet A) : IsAlgebraic R x := ⟨p, ne_zero_of_mem_rootSet hx, aeval_eq_zero_of_mem_rootSet hx⟩ variable (S) in theorem IsLocalization.isAlgebraic [Nontrivial R] (M : Submonoid R) [IsLocalization M S] : Algebra.IsAlgebraic R S where isAlgebraic x := by obtain rfl | hx := eq_or_ne x 0 · exact isAlgebraic_zero have ⟨⟨r, m⟩, h⟩ := surj M x refine ⟨C m.1 * X - C r, fun eq ↦ hx ?_, by simpa [sub_eq_zero, mul_comm x] using h⟩ rwa [← eq_mk'_iff_mul_eq, show r = 0 by simpa using congr(coeff $eq 0), mk'_zero] at h open IsScalarTower protected theorem IsAlgebraic.algebraMap {a : S} : IsAlgebraic R a → IsAlgebraic R (algebraMap S A a) := fun ⟨f, hf₁, hf₂⟩ => ⟨f, hf₁, by rw [aeval_algebraMap_apply, hf₂, map_zero]⟩ section variable {B : Type*} [Ring B] [Algebra R B] /-- This is slightly more general than `IsAlgebraic.algebraMap` in that it allows noncommutative intermediate rings `A`. -/ protected theorem IsAlgebraic.algHom (f : A →ₐ[R] B) {a : A} (h : IsAlgebraic R a) : IsAlgebraic R (f a) := let ⟨p, hp, ha⟩ := h ⟨p, hp, by rw [aeval_algHom, f.comp_apply, ha, map_zero]⟩ theorem isAlgebraic_algHom_iff (f : A →ₐ[R] B) (hf : Function.Injective f) {a : A} : IsAlgebraic R (f a) ↔ IsAlgebraic R a := ⟨fun ⟨p, hp0, hp⟩ ↦ ⟨p, hp0, hf <| by rwa [map_zero, ← f.comp_apply, ← aeval_algHom]⟩, IsAlgebraic.algHom f⟩ section RingHom omit [Algebra R S] [Algebra S A] [IsScalarTower R S A] [Algebra R B] variable [Algebra S B] {FRS FAB : Type*} section variable [FunLike FRS R S] [RingHomClass FRS R S] [FunLike FAB A B] [RingHomClass FAB A B] (f : FRS) (g : FAB) {a : A} theorem IsAlgebraic.ringHom_of_comp_eq (halg : IsAlgebraic R a) (hf : Function.Injective f) (h : RingHom.comp (algebraMap S B) f = RingHom.comp g (algebraMap R A)) : IsAlgebraic S (g a) := by obtain ⟨p, h1, h2⟩ := halg refine ⟨p.map f, (Polynomial.map_ne_zero_iff hf).2 h1, ?_⟩ change aeval ((g : A →+* B) a) _ = 0 rw [← map_aeval_eq_aeval_map h, h2, map_zero] theorem Transcendental.of_ringHom_of_comp_eq (H : Transcendental S (g a)) (hf : Function.Injective f) (h : RingHom.comp (algebraMap S B) f = RingHom.comp g (algebraMap R A)) : Transcendental R a := fun halg ↦ H (halg.ringHom_of_comp_eq f g hf h) theorem Algebra.IsAlgebraic.ringHom_of_comp_eq [Algebra.IsAlgebraic R A] (hf : Function.Injective f) (hg : Function.Surjective g) (h : RingHom.comp (algebraMap S B) f = RingHom.comp g (algebraMap R A)) : Algebra.IsAlgebraic S B := by refine ⟨fun b ↦ ?_⟩ obtain ⟨a, rfl⟩ := hg b exact (Algebra.IsAlgebraic.isAlgebraic a).ringHom_of_comp_eq f g hf h theorem Algebra.Transcendental.of_ringHom_of_comp_eq [H : Algebra.Transcendental S B] (hf : Function.Injective f) (hg : Function.Surjective g) (h : RingHom.comp (algebraMap S B) f = RingHom.comp g (algebraMap R A)) : Algebra.Transcendental R A := by rw [Algebra.transcendental_iff_not_isAlgebraic] at H ⊢ exact fun halg ↦ H (halg.ringHom_of_comp_eq f g hf hg h) theorem IsAlgebraic.of_ringHom_of_comp_eq (halg : IsAlgebraic S (g a)) (hf : Function.Surjective f) (hg : Function.Injective g) (h : RingHom.comp (algebraMap S B) f = RingHom.comp g (algebraMap R A)) : IsAlgebraic R a := by obtain ⟨p, h1, h2⟩ := halg obtain ⟨q, rfl⟩ := map_surjective (f : R →+* S) hf p refine ⟨q, fun h' ↦ by simp [h'] at h1, hg ?_⟩ change aeval ((g : A →+* B) a) _ = 0 at h2 change (g : A →+* B) _ = _ rw [map_zero, map_aeval_eq_aeval_map h, h2] theorem Transcendental.ringHom_of_comp_eq (H : Transcendental R a) (hf : Function.Surjective f) (hg : Function.Injective g) (h : RingHom.comp (algebraMap S B) f = RingHom.comp g (algebraMap R A)) : Transcendental S (g a) := fun halg ↦ H (halg.of_ringHom_of_comp_eq f g hf hg h) theorem Algebra.IsAlgebraic.of_ringHom_of_comp_eq [Algebra.IsAlgebraic S B] (hf : Function.Surjective f) (hg : Function.Injective g) (h : RingHom.comp (algebraMap S B) f = RingHom.comp g (algebraMap R A)) : Algebra.IsAlgebraic R A := ⟨fun a ↦ (Algebra.IsAlgebraic.isAlgebraic (g a)).of_ringHom_of_comp_eq f g hf hg h⟩ theorem Algebra.Transcendental.ringHom_of_comp_eq [H : Algebra.Transcendental R A] (hf : Function.Surjective f) (hg : Function.Injective g) (h : RingHom.comp (algebraMap S B) f = RingHom.comp g (algebraMap R A)) : Algebra.Transcendental S B := by rw [Algebra.transcendental_iff_not_isAlgebraic] at H ⊢ exact fun halg ↦ H (halg.of_ringHom_of_comp_eq f g hf hg h) end section variable [EquivLike FRS R S] [RingEquivClass FRS R S] [FunLike FAB A B] [RingHomClass FAB A B] (f : FRS) (g : FAB) theorem isAlgebraic_ringHom_iff_of_comp_eq (hg : Function.Injective g) (h : RingHom.comp (algebraMap S B) f = RingHom.comp g (algebraMap R A)) {a : A} : IsAlgebraic S (g a) ↔ IsAlgebraic R a := ⟨fun H ↦ H.of_ringHom_of_comp_eq f g (EquivLike.surjective f) hg h, fun H ↦ H.ringHom_of_comp_eq f g (EquivLike.injective f) h⟩ theorem transcendental_ringHom_iff_of_comp_eq (hg : Function.Injective g) (h : RingHom.comp (algebraMap S B) f = RingHom.comp g (algebraMap R A)) {a : A} : Transcendental S (g a) ↔ Transcendental R a := not_congr (isAlgebraic_ringHom_iff_of_comp_eq f g hg h) end section variable [EquivLike FRS R S] [RingEquivClass FRS R S] [EquivLike FAB A B] [RingEquivClass FAB A B] (f : FRS) (g : FAB) theorem Algebra.isAlgebraic_ringHom_iff_of_comp_eq (h : RingHom.comp (algebraMap S B) f = RingHom.comp g (algebraMap R A)) : Algebra.IsAlgebraic S B ↔ Algebra.IsAlgebraic R A := ⟨fun H ↦ H.of_ringHom_of_comp_eq f g (EquivLike.surjective f) (EquivLike.injective g) h, fun H ↦ H.ringHom_of_comp_eq f g (EquivLike.injective f) (EquivLike.surjective g) h⟩ theorem Algebra.transcendental_ringHom_iff_of_comp_eq (h : RingHom.comp (algebraMap S B) f = RingHom.comp g (algebraMap R A)) : Algebra.Transcendental S B ↔ Algebra.Transcendental R A := by simp_rw [Algebra.transcendental_iff_not_isAlgebraic, Algebra.isAlgebraic_ringHom_iff_of_comp_eq f g h] end end RingHom theorem Algebra.IsAlgebraic.of_injective (f : A →ₐ[R] B) (hf : Function.Injective f) [Algebra.IsAlgebraic R B] : Algebra.IsAlgebraic R A := ⟨fun _ ↦ (isAlgebraic_algHom_iff f hf).mp (Algebra.IsAlgebraic.isAlgebraic _)⟩ /-- Transfer `Algebra.IsAlgebraic` across an `AlgEquiv`. -/ theorem AlgEquiv.isAlgebraic (e : A ≃ₐ[R] B) [Algebra.IsAlgebraic R A] : Algebra.IsAlgebraic R B := Algebra.IsAlgebraic.of_injective e.symm.toAlgHom e.symm.injective theorem AlgEquiv.isAlgebraic_iff (e : A ≃ₐ[R] B) : Algebra.IsAlgebraic R A ↔ Algebra.IsAlgebraic R B := ⟨fun _ ↦ e.isAlgebraic, fun _ ↦ e.symm.isAlgebraic⟩ end theorem isAlgebraic_algebraMap_iff {a : S} (h : Function.Injective (algebraMap S A)) : IsAlgebraic R (algebraMap S A a) ↔ IsAlgebraic R a := isAlgebraic_algHom_iff (IsScalarTower.toAlgHom R S A) h theorem transcendental_algebraMap_iff {a : S} (h : Function.Injective (algebraMap S A)) : Transcendental R (algebraMap S A a) ↔ Transcendental R a := by simp_rw [Transcendental, isAlgebraic_algebraMap_iff h] namespace Subalgebra theorem isAlgebraic_iff_isAlgebraic_val {S : Subalgebra R A} {x : S} : IsAlgebraic R x ↔ IsAlgebraic R x.1 := (isAlgebraic_algHom_iff S.val Subtype.val_injective).symm theorem isAlgebraic_of_isAlgebraic_bot {x : S} (halg : IsAlgebraic (⊥ : Subalgebra R S) x) : IsAlgebraic R x := halg.of_ringHom_of_comp_eq (algebraMap R (⊥ : Subalgebra R S)) (RingHom.id S) (by rintro ⟨_, r, rfl⟩; exact ⟨r, rfl⟩) Function.injective_id rfl theorem isAlgebraic_bot_iff (h : Function.Injective (algebraMap R S)) {x : S} : IsAlgebraic (⊥ : Subalgebra R S) x ↔ IsAlgebraic R x := isAlgebraic_ringHom_iff_of_comp_eq (Algebra.botEquivOfInjective h).symm (RingHom.id S) Function.injective_id (by rfl) variable (R S) in theorem algebra_isAlgebraic_of_algebra_isAlgebraic_bot_left [Algebra.IsAlgebraic (⊥ : Subalgebra R S) S] : Algebra.IsAlgebraic R S := Algebra.IsAlgebraic.of_ringHom_of_comp_eq (algebraMap R (⊥ : Subalgebra R S)) (RingHom.id S) (by rintro ⟨_, r, rfl⟩; exact ⟨r, rfl⟩) Function.injective_id (by ext; rfl) theorem algebra_isAlgebraic_bot_left_iff (h : Function.Injective (algebraMap R S)) : Algebra.IsAlgebraic (⊥ : Subalgebra R S) S ↔ Algebra.IsAlgebraic R S := by simp_rw [Algebra.isAlgebraic_def, isAlgebraic_bot_iff h] instance algebra_isAlgebraic_bot_right [Nontrivial R] : Algebra.IsAlgebraic R (⊥ : Subalgebra R S) := ⟨by rintro ⟨_, x, rfl⟩; exact isAlgebraic_algebraMap _⟩ end Subalgebra theorem IsAlgebraic.of_pow {r : A} {n : ℕ} (hn : 0 < n) (ht : IsAlgebraic R (r ^ n)) : IsAlgebraic R r := have ⟨p, p_nonzero, hp⟩ := ht ⟨_, by rwa [expand_ne_zero hn], by rwa [expand_aeval n p r]⟩ theorem Transcendental.pow {r : A} (ht : Transcendental R r) {n : ℕ} (hn : 0 < n) : Transcendental R (r ^ n) := fun ht' ↦ ht <| ht'.of_pow hn lemma IsAlgebraic.invOf {x : S} [Invertible x] (h : IsAlgebraic R x) : IsAlgebraic R (⅟x) := by obtain ⟨p, hp, hp'⟩ := h refine ⟨p.reverse, by simpa using hp, ?_⟩ rwa [Polynomial.aeval_def, Polynomial.eval₂_reverse_eq_zero_iff, ← Polynomial.aeval_def] lemma IsAlgebraic.invOf_iff {x : S} [Invertible x] : IsAlgebraic R (⅟x) ↔ IsAlgebraic R x := ⟨IsAlgebraic.invOf, IsAlgebraic.invOf⟩ lemma IsAlgebraic.inv_iff {K} [Field K] [Algebra R K] {x : K} : IsAlgebraic R (x⁻¹) ↔ IsAlgebraic R x := by by_cases hx : x = 0 · simp [hx] letI := invertibleOfNonzero hx exact IsAlgebraic.invOf_iff (R := R) (x := x) alias ⟨_, IsAlgebraic.inv⟩ := IsAlgebraic.inv_iff end zero_ne_one section variable {K L R S A : Type*} section Ring section CommRing variable [CommRing R] [CommRing S] [Ring A] variable [Algebra R S] [Algebra S A] [Algebra R A] [IsScalarTower R S A] /-- If `x` is algebraic over `R`, then `x` is algebraic over `S` when `S` is an extension of `R`, and the map from `R` to `S` is injective. -/ theorem IsAlgebraic.extendScalars (hinj : Function.Injective (algebraMap R S)) {x : A} (A_alg : IsAlgebraic R x) : IsAlgebraic S x := let ⟨p, hp₁, hp₂⟩ := A_alg ⟨p.map (algebraMap _ _), by rwa [Ne, ← degree_eq_bot, degree_map_eq_of_injective hinj, degree_eq_bot], by simpa⟩ /-- A special case of `IsAlgebraic.extendScalars`. This is extracted as a theorem because in some cases `IsAlgebraic.extendScalars` will just runs out of memory. -/ theorem IsAlgebraic.tower_top_of_subalgebra_le {A B : Subalgebra R S} (hle : A ≤ B) {x : S} (h : IsAlgebraic A x) : IsAlgebraic B x := by letI : Algebra A B := (Subalgebra.inclusion hle).toAlgebra haveI : IsScalarTower A B S := .of_algebraMap_eq fun _ ↦ rfl exact h.extendScalars (Subalgebra.inclusion_injective hle) /-- If `x` is transcendental over `S`, then `x` is transcendental over `R` when `S` is an extension of `R`, and the map from `R` to `S` is injective. -/ theorem Transcendental.restrictScalars (hinj : Function.Injective (algebraMap R S)) {x : A} (h : Transcendental S x) : Transcendental R x := fun H ↦ h (H.extendScalars hinj) /-- A special case of `Transcendental.restrictScalars`. This is extracted as a theorem because in some cases `Transcendental.restrictScalars` will just runs out of memory. -/ theorem Transcendental.of_tower_top_of_subalgebra_le {A B : Subalgebra R S} (hle : A ≤ B) {x : S} (h : Transcendental B x) : Transcendental A x := fun H ↦ h (H.tower_top_of_subalgebra_le hle) /-- If A is an algebraic algebra over R, then A is algebraic over S when S is an extension of R, and the map from `R` to `S` is injective. -/ theorem Algebra.IsAlgebraic.extendScalars (hinj : Function.Injective (algebraMap R S)) [Algebra.IsAlgebraic R A] : Algebra.IsAlgebraic S A := ⟨fun _ ↦ (Algebra.IsAlgebraic.isAlgebraic _).extendScalars hinj⟩ theorem Algebra.IsAlgebraic.tower_bot_of_injective [Algebra.IsAlgebraic R A] (hinj : Function.Injective (algebraMap S A)) : Algebra.IsAlgebraic R S where isAlgebraic x := by simpa [isAlgebraic_algebraMap_iff hinj] using isAlgebraic (R := R) (A := A) (algebraMap _ _ x) end CommRing section Field variable [Field K] [Field L] [Ring A] variable [Algebra K L] [Algebra L A] [Algebra K A] [IsScalarTower K L A] variable (L) /-- If `x` is algebraic over `K`, then `x` is algebraic over `L` when `L` is an extension of `K` -/ @[stacks 09GF "part one"] theorem IsAlgebraic.tower_top {x : A} (A_alg : IsAlgebraic K x) : IsAlgebraic L x := A_alg.extendScalars (algebraMap K L).injective variable {L} (K) in /-- If `x` is transcendental over `L`, then `x` is transcendental over `K` when `L` is an extension of `K` -/ theorem Transcendental.of_tower_top {x : A} (h : Transcendental L x) : Transcendental K x := fun H ↦ h (H.tower_top L) /-- If A is an algebraic algebra over K, then A is algebraic over L when L is an extension of K -/ @[stacks 09GF "part two"] theorem Algebra.IsAlgebraic.tower_top [Algebra.IsAlgebraic K A] : Algebra.IsAlgebraic L A := Algebra.IsAlgebraic.extendScalars (algebraMap K L).injective variable (K) (A) theorem Algebra.IsAlgebraic.tower_bot (K L A : Type*) [CommRing K] [Field L] [Ring A] [Algebra K L] [Algebra L A] [Algebra K A] [IsScalarTower K L A] [Nontrivial A] [Algebra.IsAlgebraic K A] : Algebra.IsAlgebraic K L := tower_bot_of_injective (algebraMap L A).injective end Field end Ring section NoZeroSMulDivisors namespace Algebra.IsAlgebraic variable [CommRing K] [Field L] [Algebra K L] theorem algHom_bijective [NoZeroSMulDivisors K L] [Algebra.IsAlgebraic K L] (f : L →ₐ[K] L) : Function.Bijective f := by refine ⟨f.injective, fun b ↦ ?_⟩ obtain ⟨p, hp, he⟩ := Algebra.IsAlgebraic.isAlgebraic (R := K) b let f' : p.rootSet L → p.rootSet L := (rootSet_maps_to' (fun x ↦ x) f).restrict f _ _ have : f'.Surjective := Finite.injective_iff_surjective.1 fun _ _ h ↦ Subtype.eq <| f.injective <| Subtype.ext_iff.1 h obtain ⟨a, ha⟩ := this ⟨b, mem_rootSet.2 ⟨hp, he⟩⟩ exact ⟨a, Subtype.ext_iff.1 ha⟩ theorem algHom_bijective₂ [NoZeroSMulDivisors K L] [DivisionRing R] [Algebra K R] [Algebra.IsAlgebraic K L] (f : L →ₐ[K] R) (g : R →ₐ[K] L) : Function.Bijective f ∧ Function.Bijective g := (g.injective.bijective₂_of_surjective f.injective (algHom_bijective <| g.comp f).2).symm theorem bijective_of_isScalarTower [NoZeroSMulDivisors K L] [Algebra.IsAlgebraic K L] [DivisionRing R] [Algebra K R] [Algebra L R] [IsScalarTower K L R] (f : R →ₐ[K] L) : Function.Bijective f := (algHom_bijective₂ (IsScalarTower.toAlgHom K L R) f).2 theorem bijective_of_isScalarTower' [Field R] [Algebra K R] [NoZeroSMulDivisors K R] [Algebra.IsAlgebraic K R] [Algebra L R] [IsScalarTower K L R] (f : R →ₐ[K] L) : Function.Bijective f := (algHom_bijective₂ f (IsScalarTower.toAlgHom K L R)).1 variable (K L) /-- Bijection between algebra equivalences and algebra homomorphisms -/ @[simps] noncomputable def algEquivEquivAlgHom [NoZeroSMulDivisors K L] [Algebra.IsAlgebraic K L] : (L ≃ₐ[K] L) ≃* (L →ₐ[K] L) where toFun ϕ := ϕ.toAlgHom invFun ϕ := AlgEquiv.ofBijective ϕ (algHom_bijective ϕ) map_mul' _ _ := rfl end Algebra.IsAlgebraic end NoZeroSMulDivisors end section variable {R S : Type*} [CommRing R] section variable [Ring S] [Algebra R S] theorem IsAlgebraic.exists_nonzero_coeff_and_aeval_eq_zero {s : S} (hRs : IsAlgebraic R s) (hs : s ∈ S⁰) : ∃ q : R[X], q.coeff 0 ≠ 0 ∧ aeval s q = 0 := by obtain ⟨p, hp0, hp⟩ := hRs obtain ⟨q, hpq, hq⟩ := exists_eq_pow_rootMultiplicity_mul_and_not_dvd p hp0 0 simp only [C_0, sub_zero, X_pow_mul, X_dvd_iff] at hpq hq rw [hpq, map_mul, aeval_X_pow] at hp exact ⟨q, hq, (S⁰.pow_mem hs (rootMultiplicity 0 p)).2 (aeval s q) hp⟩ theorem IsAlgebraic.exists_nonzero_eq_adjoin_mul {s : S} (hRs : IsAlgebraic R s) (hs : s ∈ S⁰) : ∃ᵉ (t ∈ Algebra.adjoin R {s}) (r ≠ (0 : R)), s * t = algebraMap R S r := by have ⟨q, hq0, hq⟩ := hRs.exists_nonzero_coeff_and_aeval_eq_zero hs have ⟨p, hp⟩ := X_dvd_sub_C (p := q) refine ⟨aeval s p, aeval_mem_adjoin_singleton _ _, _, neg_ne_zero.mpr hq0, ?_⟩ apply_fun aeval s at hp rwa [map_sub, hq, zero_sub, map_mul, aeval_X, aeval_C, ← map_neg, eq_comm] at hp theorem IsAlgebraic.exists_nonzero_dvd {s : S} (hRs : IsAlgebraic R s) (hs : s ∈ S⁰) : ∃ r : R, r ≠ 0 ∧ s ∣ algebraMap R S r := by obtain ⟨q, hq0, hq⟩ := hRs.exists_nonzero_coeff_and_aeval_eq_zero hs have key := map_dvd (aeval s) (X_dvd_sub_C (p := q)) rw [map_sub, hq, zero_sub, dvd_neg, aeval_X, aeval_C] at key exact ⟨q.coeff 0, hq0, key⟩ /-- A fraction `(a : S) / (b : S)` can be reduced to `(c : S) / (d : R)`, if `b` is algebraic over `R`. -/ theorem IsAlgebraic.exists_smul_eq_mul (a : S) {b : S} (hRb : IsAlgebraic R b) (hb : b ∈ S⁰) : ∃ᵉ (c : S) (d ≠ (0 : R)), d • a = b * c := have ⟨r, hr, s, h⟩ := hRb.exists_nonzero_dvd hb ⟨s * a, r, hr, by rw [Algebra.smul_def, h, mul_assoc]⟩ variable (R) /-- A fraction `(a : S) / (b : S)` can be reduced to `(c : S) / (d : R)`, if `b` is algebraic over `R`. -/ theorem Algebra.IsAlgebraic.exists_smul_eq_mul [NoZeroDivisors S] [Algebra.IsAlgebraic R S] (a : S) {b : S} (hb : b ≠ 0) : ∃ᵉ (c : S) (d ≠ (0 : R)), d • a = b * c := (isAlgebraic b).exists_smul_eq_mul a (mem_nonZeroDivisors_of_ne_zero hb) end namespace Algebra.IsAlgebraic variable (S) {A : Type*} [CommRing S] [NoZeroDivisors S] [Algebra R S] [alg : Algebra.IsAlgebraic R S] [Ring A] [Algebra R A] [Algebra S A] [IsScalarTower R S A] open Function (Injective) in theorem injective_tower_top (inj : Injective (algebraMap R A)) : Injective (algebraMap S A) := by refine (injective_iff_map_eq_zero _).mpr fun s eq ↦ of_not_not fun ne ↦ ?_ have ⟨r, ne, dvd⟩ := (alg.1 s).exists_nonzero_dvd (mem_nonZeroDivisors_of_ne_zero ne) refine ne (inj <| map_zero (algebraMap R A) ▸ zero_dvd_iff.mp ?_) simp_rw [← eq, IsScalarTower.algebraMap_apply R S A, map_dvd (algebraMap S A) dvd] variable (R A) theorem faithfulSMul_tower_top [FaithfulSMul R A] : FaithfulSMul S A := by rw [faithfulSMul_iff_algebraMap_injective] at * exact injective_tower_top S ‹_› end Algebra.IsAlgebraic end section Field variable {K L : Type*} [Field K] [Field L] [Algebra K L] (A : Subalgebra K L) theorem inv_eq_of_aeval_divX_ne_zero {x : L} {p : K[X]} (aeval_ne : aeval x (divX p) ≠ 0) : x⁻¹ = aeval x (divX p) / (aeval x p - algebraMap _ _ (p.coeff 0)) := by rw [inv_eq_iff_eq_inv, inv_div, eq_comm, div_eq_iff, sub_eq_iff_eq_add, mul_comm] conv_lhs => rw [← divX_mul_X_add p] · rw [map_add, map_mul, aeval_X, aeval_C] · exact aeval_ne theorem inv_eq_of_root_of_coeff_zero_ne_zero {x : L} {p : K[X]} (aeval_eq : aeval x p = 0) (coeff_zero_ne : p.coeff 0 ≠ 0) : x⁻¹ = -(aeval x (divX p) / algebraMap _ _ (p.coeff 0)) := by convert inv_eq_of_aeval_divX_ne_zero (p := p) (L := L) (mt (fun h => (algebraMap K L).injective ?_) coeff_zero_ne) using 1 · rw [aeval_eq, zero_sub, div_neg] rw [RingHom.map_zero] convert aeval_eq conv_rhs => rw [← divX_mul_X_add p] rw [map_add, map_mul, h, zero_mul, zero_add, aeval_C] theorem Subalgebra.inv_mem_of_root_of_coeff_zero_ne_zero {x : A} {p : K[X]} (aeval_eq : aeval x p = 0) (coeff_zero_ne : p.coeff 0 ≠ 0) : (x⁻¹ : L) ∈ A := by suffices (x⁻¹ : L) = (-p.coeff 0)⁻¹ • aeval x (divX p) by rw [this] exact A.smul_mem (aeval x _).2 _ have : aeval (x : L) p = 0 := by rw [Subalgebra.aeval_coe, aeval_eq, Subalgebra.coe_zero] rw [inv_eq_of_root_of_coeff_zero_ne_zero this coeff_zero_ne, div_eq_inv_mul, Algebra.smul_def, aeval_coe, map_inv₀, map_neg, inv_neg, neg_mul] theorem Subalgebra.inv_mem_of_algebraic {x : A} (hx : IsAlgebraic K (x : L)) : (x⁻¹ : L) ∈ A := by obtain ⟨p, ne_zero, aeval_eq⟩ := hx rw [Subalgebra.aeval_coe, Subalgebra.coe_eq_zero] at aeval_eq revert ne_zero aeval_eq refine p.recOnHorner ?_ ?_ ?_ · intro h contradiction · intro p a hp ha _ih _ne_zero aeval_eq refine A.inv_mem_of_root_of_coeff_zero_ne_zero aeval_eq ?_ rwa [coeff_add, hp, zero_add, coeff_C, if_pos rfl] · intro p hp ih _ne_zero aeval_eq rw [map_mul, aeval_X, mul_eq_zero] at aeval_eq rcases aeval_eq with aeval_eq | x_eq · exact ih hp aeval_eq · rw [x_eq, Subalgebra.coe_zero, inv_zero] exact A.zero_mem /-- In an algebraic extension L/K, an intermediate subalgebra is a field. -/ @[stacks 0BID] theorem Subalgebra.isField_of_algebraic [Algebra.IsAlgebraic K L] : IsField A := { show Nontrivial A by infer_instance, Subalgebra.toCommRing A with mul_inv_cancel := fun {a} ha => ⟨⟨a⁻¹, A.inv_mem_of_algebraic (Algebra.IsAlgebraic.isAlgebraic (a : L))⟩, Subtype.ext (mul_inv_cancel₀ (mt (Subalgebra.coe_eq_zero _).mp ha))⟩ } end Field section Infinite variable {R A : Type*} [CommRing R] [Ring A] [Algebra R A] [Nontrivial R] theorem Transcendental.infinite {x : A} (hx : Transcendental R x) : Infinite A := .of_injective _ (transcendental_iff_injective.mp hx) variable (R A) in theorem Algebra.Transcendental.infinite [Algebra.Transcendental R A] : Infinite A := have ⟨x, hx⟩ := ‹Algebra.Transcendental R A› hx.infinite end Infinite
.lake/packages/mathlib/Mathlib/RingTheory/Algebraic/Cardinality.lean
import Mathlib.Algebra.Polynomial.Cardinal import Mathlib.Algebra.Polynomial.Roots import Mathlib.RingTheory.Algebraic.Defs /-! # Cardinality of algebraic extensions This file contains results on cardinality of algebraic extensions. -/ universe u v open scoped Cardinal Polynomial open Cardinal namespace Algebra.IsAlgebraic variable (R : Type u) [CommRing R] (L : Type v) [CommRing L] [IsDomain L] [Algebra R L] variable [NoZeroSMulDivisors R L] [Algebra.IsAlgebraic R L] theorem lift_cardinalMk_le_sigma_polynomial : lift.{u} #L ≤ #(Σ p : R[X], { x : L // x ∈ p.aroots L }) := by have := @lift_mk_le_lift_mk_of_injective L (Σ p : R[X], {x : L | x ∈ p.aroots L}) (fun x : L => let p := Classical.indefiniteDescription _ (Algebra.IsAlgebraic.isAlgebraic x) ⟨p.1, x, by dsimp have := (Polynomial.map_ne_zero_iff (FaithfulSMul.algebraMap_injective R L)).2 p.2.1 rw [Polynomial.mem_roots this, Polynomial.IsRoot, Polynomial.eval_map, ← Polynomial.aeval_def, p.2.2]⟩) fun x y => by intro h simp only [Set.coe_setOf, ne_eq, Set.mem_setOf_eq, Sigma.mk.inj_iff] at h refine (Subtype.heq_iff_coe_eq ?_).1 h.2 simp only [h.1, forall_true_iff] rwa [lift_umax, lift_id'.{v}] at this theorem lift_cardinalMk_le_max : lift.{u} #L ≤ lift.{v} #R ⊔ ℵ₀ := calc lift.{u} #L ≤ #(Σ p : R[X], { x : L // x ∈ p.aroots L }) := lift_cardinalMk_le_sigma_polynomial R L _ = Cardinal.sum fun p : R[X] => #{x : L | x ∈ p.aroots L} := by rw [← mk_sigma]; rfl _ ≤ Cardinal.sum.{u, v} fun _ : R[X] => ℵ₀ := (sum_le_sum _ _ fun _ => (Multiset.finite_toSet _).lt_aleph0.le) _ = lift.{v} #(R[X]) * ℵ₀ := by rw [sum_const, lift_aleph0] _ ≤ lift.{v} (#R ⊔ ℵ₀) ⊔ ℵ₀ ⊔ ℵ₀ := (mul_le_max _ _).trans <| by gcongr; simp only [lift_le, Polynomial.cardinalMk_le_max] _ = _ := by simp variable (L : Type u) [CommRing L] [IsDomain L] [Algebra R L] variable [NoZeroSMulDivisors R L] [Algebra.IsAlgebraic R L] theorem cardinalMk_le_sigma_polynomial : #L ≤ #(Σ p : R[X], { x : L // x ∈ p.aroots L }) := by simpa only [lift_id] using lift_cardinalMk_le_sigma_polynomial R L /-- The cardinality of an algebraic extension is at most the maximum of the cardinality of the base ring or `ℵ₀`. -/ @[stacks 09GK] theorem cardinalMk_le_max : #L ≤ max #R ℵ₀ := by simpa only [lift_id] using lift_cardinalMk_le_max R L end Algebra.IsAlgebraic
.lake/packages/mathlib/Mathlib/RingTheory/Algebraic/Defs.lean
import Mathlib.Algebra.Polynomial.AlgebraMap /-! # Algebraic elements and algebraic extensions An element of an R-algebra is algebraic over R if it is the root of a nonzero polynomial. An R-algebra is algebraic over R if and only if all its elements are algebraic over R. ## Main definitions * `IsAlgebraic`: algebraic elements of an algebra. * `Transcendental`: transcendental elements of an algebra are those that are not algebraic. * `Subalgebra.IsAlgebraic`: a subalgebra is algebraic if all its elements are algebraic. * `Algebra.IsAlgebraic`: an algebra is algebraic if all its elements are algebraic. * `Algebra.Transcendental`: an algebra is transcendental if some element is transcendental. ## Main results * `transcendental_iff`: an element `x : A` is transcendental over `R` iff out of `R[X]` only the zero polynomial evaluates to 0 at `x`. * `Subalgebra.isAlgebraic_iff`: a subalgebra is algebraic iff it is algebraic as an algebra. -/ assert_not_exists IsIntegralClosure LinearIndependent IsLocalRing MvPolynomial universe u v w open Polynomial section variable (R : Type u) {A : Type v} [CommRing R] [Ring A] [Algebra R A] /-- An element of an R-algebra is algebraic over R if it is a root of a nonzero polynomial with coefficients in R. -/ @[stacks 09GC "Algebraic elements"] def IsAlgebraic (x : A) : Prop := ∃ p : R[X], p ≠ 0 ∧ aeval x p = 0 /-- An element of an R-algebra is transcendental over R if it is not algebraic over R. -/ def Transcendental (x : A) : Prop := ¬IsAlgebraic R x variable {R} /-- An element `x` is transcendental over `R` if and only if for any polynomial `p`, `Polynomial.aeval x p = 0` implies `p = 0`. This is similar to `algebraicIndependent_iff`. -/ theorem transcendental_iff {x : A} : Transcendental R x ↔ ∀ p : R[X], aeval x p = 0 → p = 0 := by rw [Transcendental, IsAlgebraic, not_exists] congr! 1; tauto /-- A subalgebra is algebraic if all its elements are algebraic. -/ protected def Subalgebra.IsAlgebraic (S : Subalgebra R A) : Prop := ∀ x ∈ S, IsAlgebraic R x variable (R A) /-- An algebra is algebraic if all its elements are algebraic. -/ @[stacks 09GC "Algebraic extensions"] protected class Algebra.IsAlgebraic : Prop where isAlgebraic : ∀ x : A, IsAlgebraic R x /-- An algebra is transcendental if some element is transcendental. -/ protected class Algebra.Transcendental : Prop where transcendental : ∃ x : A, Transcendental R x variable {R A} lemma Algebra.isAlgebraic_def : Algebra.IsAlgebraic R A ↔ ∀ x : A, IsAlgebraic R x := ⟨fun ⟨h⟩ ↦ h, fun h ↦ ⟨h⟩⟩ lemma Algebra.transcendental_def : Algebra.Transcendental R A ↔ ∃ x : A, Transcendental R x := ⟨fun ⟨h⟩ ↦ h, fun h ↦ ⟨h⟩⟩ theorem Algebra.transcendental_iff_not_isAlgebraic : Algebra.Transcendental R A ↔ ¬ Algebra.IsAlgebraic R A := by simp [isAlgebraic_def, transcendental_def, Transcendental] /-- A subalgebra is algebraic if and only if it is algebraic as an algebra. -/ theorem Subalgebra.isAlgebraic_iff (S : Subalgebra R A) : S.IsAlgebraic ↔ Algebra.IsAlgebraic R S := by delta Subalgebra.IsAlgebraic rw [Subtype.forall', Algebra.isAlgebraic_def] refine forall_congr' fun x => exists_congr fun p => and_congr Iff.rfl ?_ have h : Function.Injective S.val := Subtype.val_injective conv_rhs => rw [← h.eq_iff, map_zero] rw [← aeval_algHom_apply, S.val_apply] /-- An algebra is algebraic if and only if it is algebraic as a subalgebra. -/ theorem Algebra.isAlgebraic_iff : Algebra.IsAlgebraic R A ↔ (⊤ : Subalgebra R A).IsAlgebraic := by delta Subalgebra.IsAlgebraic simp only [Algebra.isAlgebraic_def, Algebra.mem_top, forall_prop_of_true] end
.lake/packages/mathlib/Mathlib/RingTheory/Algebraic/MvPolynomial.lean
import Mathlib.Algebra.MvPolynomial.Supported import Mathlib.RingTheory.Adjoin.Polynomial import Mathlib.RingTheory.Algebraic.Basic /-! # Transcendental elements in `MvPolynomial` This file lists some results on some elements in `MvPolynomial σ R` being transcendental over the base ring `R` and subrings `MvPolynomial.supported` of `MvPolynomial σ R`. -/ universe u v w open Polynomial namespace MvPolynomial variable {σ : Type*} (R : Type*) [CommRing R] theorem transcendental_supported_polynomial_aeval_X {i : σ} {s : Set σ} (h : i ∉ s) {f : R[X]} (hf : Transcendental R f) : Transcendental (supported R s) (Polynomial.aeval (X i : MvPolynomial σ R) f) := by classical rw [transcendental_iff_injective] at hf ⊢ let g := MvPolynomial.mapAlgHom (R := R) (σ := s) (Polynomial.aeval (R := R) f) replace hf : Function.Injective g := MvPolynomial.map_injective _ hf let u := (Subalgebra.val _).comp ((optionEquivRight R s).symm |>.trans (renameEquiv R (Set.subtypeInsertEquivOption h).symm) |>.trans (supportedEquivMvPolynomial _).symm).toAlgHom |>.comp g |>.comp ((optionEquivLeft R s).symm.trans (optionEquivRight R s)).toAlgHom let v := ((Polynomial.aeval (R := supported R s) (Polynomial.aeval (X i : MvPolynomial σ R) f)).restrictScalars R).comp (Polynomial.mapAlgEquiv (supportedEquivMvPolynomial s).symm).toAlgHom replace hf : Function.Injective u := by simp only [AlgEquiv.toAlgHom_eq_coe, AlgHom.coe_comp, Subalgebra.coe_val, AlgHom.coe_coe, AlgEquiv.coe_trans, Function.comp_assoc, u] apply Subtype.val_injective.comp simp only [EquivLike.comp_injective] apply hf.comp simp only [EquivLike.comp_injective, EquivLike.injective] have h1 : Polynomial.aeval (X i : MvPolynomial σ R) = ((Subalgebra.val _).comp (supportedEquivMvPolynomial _).symm.toAlgHom |>.comp (Polynomial.aeval (X ⟨i, s.mem_insert i⟩ : MvPolynomial ↑(insert i s) R))) := by ext1; simp have h2 : u = v := by simp only [u, v, g] ext1 · ext1 simp [Set.subtypeInsertEquivOption, Subalgebra.algebraMap_eq, optionEquivLeft_symm_apply] · simp [Set.subtypeInsertEquivOption, h1, optionEquivLeft_symm_apply] simpa only [h2, v, AlgEquiv.toAlgHom_eq_coe, AlgHom.coe_comp, AlgHom.coe_coe, EquivLike.injective_comp, AlgHom.coe_restrictScalars'] using hf theorem transcendental_polynomial_aeval_X (i : σ) {f : R[X]} (hf : Transcendental R f) : Transcendental R (Polynomial.aeval (X i : MvPolynomial σ R) f) := by have := transcendental_supported_polynomial_aeval_X R (Set.notMem_empty i) hf let g := (Algebra.botEquivOfInjective (MvPolynomial.C_injective σ R)).symm.trans (Subalgebra.equivOfEq _ _ supported_empty).symm rwa [Transcendental, ← isAlgebraic_ringHom_iff_of_comp_eq g (RingHom.id (MvPolynomial σ R)) Function.injective_id (by ext1; rfl), RingHom.id_apply, ← Transcendental] theorem transcendental_polynomial_aeval_X_iff (i : σ) {f : R[X]} : Transcendental R (Polynomial.aeval (X i : MvPolynomial σ R) f) ↔ Transcendental R f := by refine ⟨?_, transcendental_polynomial_aeval_X R i⟩ simp_rw [Transcendental, not_imp_not] exact fun h ↦ h.algHom _ theorem transcendental_supported_polynomial_aeval_X_iff [Nontrivial R] {i : σ} {s : Set σ} {f : R[X]} : Transcendental (supported R s) (Polynomial.aeval (X i : MvPolynomial σ R) f) ↔ i ∉ s ∧ Transcendental R f := by refine ⟨fun h ↦ ⟨?_, ?_⟩, fun ⟨h, hf⟩ ↦ transcendental_supported_polynomial_aeval_X R h hf⟩ · rw [Transcendental] at h contrapose! h refine isAlgebraic_algebraMap (⟨Polynomial.aeval (X i) f, ?_⟩ : supported R s) exact Algebra.adjoin_mono (Set.singleton_subset_iff.2 (Set.mem_image_of_mem _ h)) (Polynomial.aeval_mem_adjoin_singleton _ _) · rw [← transcendental_polynomial_aeval_X_iff R i] refine h.restrictScalars fun _ _ heq ↦ MvPolynomial.C_injective σ R ?_ simp_rw [← MvPolynomial.algebraMap_eq] exact congr($(heq).1) theorem transcendental_supported_X {i : σ} {s : Set σ} (h : i ∉ s) : Transcendental (supported R s) (X i : MvPolynomial σ R) := by simpa using transcendental_supported_polynomial_aeval_X R h (Polynomial.transcendental_X R) theorem transcendental_X (i : σ) : Transcendental R (X i : MvPolynomial σ R) := by simpa using transcendental_polynomial_aeval_X R i (Polynomial.transcendental_X R) theorem transcendental_supported_X_iff [Nontrivial R] {i : σ} {s : Set σ} : Transcendental (supported R s) (X i : MvPolynomial σ R) ↔ i ∉ s := by simpa [Polynomial.transcendental_X] using transcendental_supported_polynomial_aeval_X_iff R (i := i) (s := s) (f := Polynomial.X) end MvPolynomial
.lake/packages/mathlib/Mathlib/RingTheory/Algebraic/LinearIndependent.lean
import Mathlib.LinearAlgebra.LinearIndependent.Defs import Mathlib.RingTheory.Algebraic.Defs /-! # Linear independence of transcendental elements ## Main result * `Transcendental.linearIndependent_sub_inv`: let `x : E` transcendental over `F`, then `{(x - a)⁻¹ | a : F}` is linearly independent over `F`. -/ open Polynomial section /-- If `E / F` is a field extension, `x` is an element of `E` transcendental over `F`, then `{(x - a)⁻¹ | a : F}` is linearly independent over `F`. -/ theorem Transcendental.linearIndependent_sub_inv {F E : Type*} [Field F] [Field E] [Algebra F E] {x : E} (H : Transcendental F x) : LinearIndependent F fun a ↦ (x - algebraMap F E a)⁻¹ := by classical rw [transcendental_iff] at H refine linearIndependent_iff'.2 fun s m hm i hi ↦ ?_ have hnz (a : F) : x - algebraMap F E a ≠ 0 := fun h ↦ X_sub_C_ne_zero a <| H (.X - .C a) (by simp [h]) let b := s.prod fun j ↦ x - algebraMap F E j have h1 : ∀ i ∈ s, m i • (b * (x - algebraMap F E i)⁻¹) = m i • (s.erase i).prod fun j ↦ x - algebraMap F E j := fun i hi ↦ by simp_rw [b, ← s.prod_erase_mul _ hi, mul_inv_cancel_right₀ (hnz i)] replace hm := congr(b * $(hm)) simp_rw [mul_zero, Finset.mul_sum, mul_smul_comm, Finset.sum_congr rfl h1] at hm let p : Polynomial F := s.sum fun i ↦ .C (m i) * (s.erase i).prod fun j ↦ .X - .C j replace hm := congr(Polynomial.aeval i $(H p (by simp_rw [← hm, p, map_sum, map_mul, map_prod, map_sub, aeval_X, aeval_C, Algebra.smul_def]))) have h2 : ∀ j ∈ s.erase i, m j * ((s.erase j).prod fun x ↦ i - x) = 0 := fun j hj ↦ by have := Finset.mem_erase_of_ne_of_mem (Finset.ne_of_mem_erase hj).symm hi simp_rw [← (s.erase j).prod_erase_mul _ this, sub_self, mul_zero] simp_rw [map_zero, p, map_sum, map_mul, map_prod, map_sub, aeval_X, aeval_C, Algebra.algebraMap_self_apply, ← s.sum_erase_add _ hi, Finset.sum_eq_zero h2, zero_add] at hm exact eq_zero_of_ne_zero_of_mul_right_eq_zero (Finset.prod_ne_zero_iff.2 fun j hj ↦ sub_ne_zero.2 (Finset.ne_of_mem_erase hj).symm) hm end
.lake/packages/mathlib/Mathlib/RingTheory/Morita/Basic.lean
import Mathlib.Algebra.Category.ModuleCat.ChangeOfRings import Mathlib.CategoryTheory.Linear.LinearFunctor import Mathlib.Algebra.Category.ModuleCat.Basic import Mathlib.CategoryTheory.Adjunction.Limits /-! # Morita equivalence Two `R`-algebras `A` and `B` are Morita equivalent if the categories of modules over `A` and `B` are `R`-linearly equivalent. In this file, we prove that Morita equivalence is an equivalence relation and that isomorphic algebras are Morita equivalent. ## Main definitions - `MoritaEquivalence R A B`: a structure containing an `R`-linear equivalence of categories between the module categories of `A` and `B`. - `IsMoritaEquivalent R A B`: a predicate asserting that `R`-algebras `A` and `B` are Morita equivalent. ## TODO - For any ring `R`, `R` and `Matₙ(R)` are Morita equivalent. - Morita equivalence in terms of projective generators. - Morita equivalence in terms of full idempotents. - Morita equivalence in terms of existence of an invertible bimodule. - If `R ≈ S`, then `R` is simple iff `S` is simple. ## References * [Nathan Jacobson, *Basic Algebra II*][jacobson1989] ## Tags Morita Equivalence, Category Theory, Noncommutative Ring, Module Theory -/ universe u₀ u₁ u₂ u₃ open CategoryTheory variable (R : Type u₀) [CommSemiring R] open scoped ModuleCat.Algebra /-- Let `A` and `B` be `R`-algebras. A Morita equivalence between `A` and `B` is an `R`-linear equivalence between the categories of `A`-modules and `B`-modules. -/ structure MoritaEquivalence (A : Type u₁) [Ring A] [Algebra R A] (B : Type u₂) [Ring B] [Algebra R B] where /-- The underlying equivalence of categories -/ eqv : ModuleCat.{max u₁ u₂} A ≌ ModuleCat.{max u₁ u₂} B linear : eqv.functor.Linear R := by infer_instance namespace MoritaEquivalence attribute [instance] MoritaEquivalence.linear instance {A : Type u₁} [Ring A] [Algebra R A] {B : Type u₂} [Ring B] [Algebra R B] (e : MoritaEquivalence R A B) : e.eqv.functor.Additive := e.eqv.functor.additive_of_preserves_binary_products /-- For any `R`-algebra `A`, `A` is Morita equivalent to itself. -/ def refl (A : Type u₁) [Ring A] [Algebra R A] : MoritaEquivalence R A A where eqv := CategoryTheory.Equivalence.refl linear := Functor.instLinearId /-- For any `R`-algebras `A` and `B`, if `A` is Morita equivalent to `B`, then `B` is Morita equivalent to `A`. -/ def symm {A : Type u₁} [Ring A] [Algebra R A] {B : Type u₂} [Ring B] [Algebra R B] (e : MoritaEquivalence R A B) : MoritaEquivalence R B A where eqv := e.eqv.symm linear := e.eqv.inverseLinear R -- TODO: We have restricted all the rings to the same universe here because of the complication -- `max u₁ u₂`, `max u₂ u₃` vs `max u₁ u₃`. But once we proved the definition of Morita -- equivalence is equivalent to the existence of a full idempotent element, we can remove this -- restriction in the universe. -- Or alternatively, @alreadydone has sketched an argument on how the universe restriction can be -- removed via a categorical argument, -- see [here](https://github.com/leanprover-community/mathlib4/pull/20640#discussion_r1912189931) /-- For any `R`-algebras `A`, `B`, and `C`, if `A` is Morita equivalent to `B` and `B` is Morita equivalent to `C`, then `A` is Morita equivalent to `C`. -/ def trans {A B C : Type u₁} [Ring A] [Algebra R A] [Ring B] [Algebra R B] [Ring C] [Algebra R C] (e : MoritaEquivalence R A B) (e' : MoritaEquivalence R B C) : MoritaEquivalence R A C where eqv := e.eqv.trans e'.eqv linear := e.eqv.functor.instLinearComp e'.eqv.functor variable {R} in /-- Isomorphic `R`-algebras are Morita equivalent. -/ noncomputable def ofAlgEquiv {A : Type u₁} {B : Type u₂} [Ring A] [Algebra R A] [Ring B] [Algebra R B] (f : A ≃ₐ[R] B) : MoritaEquivalence R A B where eqv := ModuleCat.restrictScalarsEquivalenceOfRingEquiv f.symm.toRingEquiv linear := ModuleCat.Algebra.restrictScalarsEquivalenceOfRingEquiv_linear f.symm end MoritaEquivalence /-- Let `A` and `B` be `R`-algebras. We say that `A` and `B` are Morita equivalent if the categories of `A`-modules and `B`-modules are equivalent as `R`-linear categories. -/ structure IsMoritaEquivalent (A : Type u₁) [Ring A] [Algebra R A] (B : Type u₂) [Ring B] [Algebra R B] : Prop where cond : Nonempty <| MoritaEquivalence R A B namespace IsMoritaEquivalent lemma refl (A : Type u₁) [Ring A] [Algebra R A] : IsMoritaEquivalent R A A where cond := ⟨.refl R A⟩ lemma symm {A : Type u₁} [Ring A] [Algebra R A] {B : Type u₂} [Ring B] [Algebra R B] (h : IsMoritaEquivalent R A B) : IsMoritaEquivalent R B A where cond := h.cond.map <| .symm R lemma trans {A B C : Type u₁} [Ring A] [Ring B] [Ring C] [Algebra R A] [Algebra R B] [Algebra R C] (h : IsMoritaEquivalent R A B) (h' : IsMoritaEquivalent R B C) : IsMoritaEquivalent R A C where cond := Nonempty.map2 (.trans R) h.cond h'.cond lemma of_algEquiv {A : Type u₁} [Ring A] [Algebra R A] {B : Type u₂} [Ring B] [Algebra R B] (f : A ≃ₐ[R] B) : IsMoritaEquivalent R A B where cond := ⟨.ofAlgEquiv f⟩ end IsMoritaEquivalent
.lake/packages/mathlib/Mathlib/RingTheory/Coalgebra/GroupLike.lean
import Mathlib.RingTheory.Coalgebra.Equiv import Mathlib.RingTheory.Flat.Domain /-! # Group-like elements in a coalgebra This file defines group-like elements in a coalgebra, i.e. elements `a` such that `ε a = 1` and `Δ a = a ⊗ₜ a`. ## Main declarations * `IsGroupLikeElem`: Predicate for an element in a coalgebra to be group-like. * `linearIndepOn_isGroupLikeElem`: Group-like elements over a domain are linearly independent. -/ open Coalgebra Function TensorProduct variable {F R A B : Type*} section CommSemiring variable [CommSemiring R] [AddCommMonoid A] [AddCommMonoid B] [Module R A] [Coalgebra R A] [Module R B] [Coalgebra R B] {a b : A} variable (R) in /-- A group-like element in a coalgebra is an element `a` such that `ε(a) = 1` and `Δ(a) = a ⊗ₜ a`, where `ε` and `Δ` are the counit and comultiplication respectively. -/ @[mk_iff] structure IsGroupLikeElem (a : A) : Prop where /-- A group-like element `a` satisfies `ε(a) = 1`. -/ counit_eq_one : counit (R := R) a = 1 /-- A group-like element `a` satisfies `Δ(a) = a ⊗ₜ a`. -/ comul_eq_tmul_self : comul a = a ⊗ₜ[R] a attribute [simp] IsGroupLikeElem.counit_eq_one IsGroupLikeElem.comul_eq_tmul_self @[simp] lemma isGroupLikeElem_self {r : R} : IsGroupLikeElem R r ↔ r = 1 := by simp +contextual [isGroupLikeElem_iff] lemma IsGroupLikeElem.ne_zero [Nontrivial R] (ha : IsGroupLikeElem R a) : a ≠ 0 := by rintro rfl; simpa using ha.counit_eq_one /-- A coalgebra homomorphism sends group-like elements to group-like elements. -/ lemma IsGroupLikeElem.map [FunLike F A B] [CoalgHomClass F R A B] (f : F) (ha : IsGroupLikeElem R a) : IsGroupLikeElem R (f a) where counit_eq_one := by rw [CoalgHomClass.counit_comp_apply, ha.counit_eq_one] comul_eq_tmul_self := by rw [← CoalgHomClass.map_comp_comul_apply, ha.comul_eq_tmul_self]; simp /-- A coalgebra isomorphism preserves group-like elements. -/ @[simp] lemma isGroupLikeElem_map_equiv [EquivLike F A B] [CoalgEquivClass F R A B] (f : F) : IsGroupLikeElem R (f a) ↔ IsGroupLikeElem R a where mp ha := (CoalgEquivClass.toCoalgEquiv f).symm_apply_apply a ▸ ha.map _ mpr := .map f variable (R A) in /-- The type of group-like elements in a coalgebra. -/ @[ext] structure GroupLike where /-- The underlying element of a group-like element. -/ val : A isGroupLikeElem_val : IsGroupLikeElem R val namespace GroupLike attribute [simp] isGroupLikeElem_val attribute [coe] val instance instCoeOut : CoeOut (GroupLike R A) A where coe := val lemma val_injective : Injective (val : GroupLike R A → A) := by rintro ⟨a, ha⟩; congr! @[simp, norm_cast] lemma val_inj {a b : GroupLike R A} : a.val = b.val ↔ a = b := val_injective.eq_iff /-- Identity equivalence between `GroupLike R A` and `{a : A // IsGroupLikeElem R a}`. -/ def valEquiv : GroupLike R A ≃ Subtype (IsGroupLikeElem R : A → Prop) where toFun a := ⟨a.1, a.2⟩ invFun a := ⟨a.1, a.2⟩ left_inv _ := rfl right_inv _ := rfl end GroupLike end CommSemiring section CommRing variable [CommRing R] [IsDomain R] [AddCommGroup A] [Module R A] [Coalgebra R A] [NoZeroSMulDivisors R A] open Submodule in /-- Group-like elements over a domain are linearly independent. -/ lemma linearIndepOn_isGroupLikeElem : LinearIndepOn R id {a : A | IsGroupLikeElem R a} := by classical -- We show that any finset `s` of group-like elements is linearly independent. rw [linearIndepOn_iff_linearIndepOn_finset] rintro s hs -- For this, we do induction on `s`. induction s using Finset.cons_induction with -- The case `s = ∅` is trivial. | empty => simp -- Let's deal with the `s ∪ {a}` case. | cons a s has ih => simp only [Finset.cons_eq_insert, Finset.coe_insert, Set.subset_def, Set.mem_insert_iff, Finset.mem_coe, Set.mem_setOf_eq, forall_eq_or_imp] at hs obtain ⟨ha, hs⟩ := hs specialize ih hs -- Assume that there is some `c : A → R` and `d : R` such that `∑ x ∈ s, c x • x = d • a`. -- We want to prove `d = 0` and `∀ x ∈ s, c x = 0`. rw [Finset.coe_cons] refine ih.id_insert' ?_ simp only [mem_span_finset, forall_exists_index, and_imp] rintro d c - hc -- `x ⊗ y` over `x, y ∈ s` are linearly independent since `s` is linearly independent and -- `R` is a domain. replace ih := ih.tmul_of_isDomain ih simp_rw [← Finset.coe_product, linearIndepOn_finset_iffₛ, id] at ih -- Tensoring the equality `∑ x ∈ s, c x • x = d • a` with itself, we get by linear independence -- that `c x ^ 2 = d * c x` and `c x * c y = 0` for `x ≠ y`. have key := calc ∑ x ∈ s, ∑ y ∈ s, (if x = y then d * c x else 0) • x ⊗ₜ[R] y _ = d • ∑ x ∈ s, c x • x ⊗ₜ[R] x := by simp [Finset.smul_sum, mul_smul] _ = d • comul (d • a) := by rw [← hc]; simp +contextual [(hs _ _).comul_eq_tmul_self] _ = (d • a) ⊗ₜ (d • a) := by simp [ha.comul_eq_tmul_self, smul_tmul, tmul_smul, -neg_smul] _ = ∑ x ∈ s, ∑ y ∈ s, (c x * c y) • x ⊗ₜ[R] y := by simp_rw [← hc, sum_tmul, smul_tmul, Finset.smul_sum, tmul_sum, tmul_smul, mul_smul] simp_rw [← Finset.sum_product'] at key apply ih at key -- Therefore, `c x = 0` for all `x ∈ s`. replace key x (hx : x ∈ s) : c x = 0 := by -- Otherwise, we deduce from `key` that `c y = 0` for any `y ≠ x` with `y ∈ s`. by_contra! hcx have hcy (y) (hys : y ∈ s) (hyx : y ≠ x) : c y = 0 := by simpa [*] using (key (y, x) (by simp [*])).symm -- Then substitute this into `hc` to get `c x • x = d • a`. rw [Finset.sum_eq_single x (by simp +contextual [hcy]) (by simp [hx])] at hc -- But `key` also says that `c x = d`. have hcxa : d = c x := mul_left_injective₀ hcx (by simpa using (key (x, x) (by simp [*]))) -- So `x = a`... obtain rfl : x = a := by rwa [hcxa, smul_right_inj hcx] at hc -- ... which contradicts `x ∈ s` and `a ∉ s`. contradiction -- We are now done, since `d • a = ∑ x ∈ s, c x • x = 0` simp_all [ha.ne_zero, eq_comm] /-- Group-like elements over a domain are linearly independent. -/ lemma linearIndep_groupLikeVal : LinearIndependent R (GroupLike.val (R := R) (A := A)) := by simpa using (linearIndependent_equiv GroupLike.valEquiv).2 linearIndepOn_isGroupLikeElem end CommRing
.lake/packages/mathlib/Mathlib/RingTheory/Coalgebra/Convolution.lean
import Mathlib.Algebra.Algebra.Bilinear import Mathlib.LinearAlgebra.TensorProduct.Tower import Mathlib.RingTheory.Coalgebra.Hom import Mathlib.RingTheory.Coalgebra.TensorProduct import Mathlib.RingTheory.TensorProduct.Basic /-! # Convolution product on linear maps from a coalgebra to an algebra This file constructs the ring structure on linear maps `C → A` where `C` is a coalgebra and `A` an algebra, where multiplication is given by `(f * g)(x) = ∑ f x₍₁₎ * g x₍₂₎` in Sweedler notation or ``` | μ | | / \ f * g = f g | | \ / δ | ``` diagrammatically, where `μ` stands for multiplication and `δ` for comultiplication. ## Implementation notes Note that in the case `C = A` this convolution product conflicts with the (unfortunately global!) group instance on `Module.End R A` with multiplication defined as composition. As a result, the convolution product is scoped to `ConvolutionProduct`. -/ suppress_compilation open Coalgebra TensorProduct open scoped RingTheory.LinearMap variable {R A B C : Type*} [CommSemiring R] namespace LinearMap section NonUnitalNonAssocSemiring variable [NonUnitalNonAssocSemiring A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] [AddCommMonoid C] [Module R C] [CoalgebraStruct R C] /-- Convolution product on linear maps from a coalgebra to an algebra. -/ abbrev convMul : Mul (C →ₗ[R] A) where mul f g := mul' R A ∘ₗ TensorProduct.map f g ∘ₗ comul scoped[ConvolutionProduct] attribute [instance] LinearMap.convMul open scoped ConvolutionProduct lemma convMul_def (f g : C →ₗ[R] A) : f * g = mul' R A ∘ₗ TensorProduct.map f g ∘ₗ comul := rfl @[simp] lemma convMul_apply (f g : C →ₗ[R] A) (c : C) : (f * g) c = mul' R A (.map f g (comul c)) := rfl lemma _root_.Coalgebra.Repr.convMul_apply {a : C} (𝓡 : Coalgebra.Repr R a) (f g : C →ₗ[R] A) : (f * g) a = ∑ i ∈ 𝓡.index, f (𝓡.left i) * g (𝓡.right i) := by simp [convMul_def, ← 𝓡.eq] /-- Non-unital and non-associative convolution semiring structure on linear maps from a coalgebra to a non-unital non-associative algebra. -/ abbrev convNonUnitalNonAssocSemiring : NonUnitalNonAssocSemiring (C →ₗ[R] A) where left_distrib f g h := by ext; simp [map_add_right] right_distrib f g h := by ext; simp [map_add_left] zero_mul f := by ext; simp mul_zero f := by ext; simp scoped[ConvolutionProduct] attribute [instance] LinearMap.convNonUnitalNonAssocSemiring @[simp] lemma toSpanSingleton_convMul_toSpanSingleton (x y : A) : toSpanSingleton R A x * toSpanSingleton R A y = toSpanSingleton R A (x * y) := by ext; simp theorem _root_.TensorProduct.map_convMul_map {D : Type*} [AddCommMonoid B] [Module R B] [CoalgebraStruct R B] [NonUnitalNonAssocSemiring D] [Module R D] [SMulCommClass R D D] [IsScalarTower R D D] {f h : C →ₗ[R] A} {g k : B →ₗ[R] D} : (f ⊗ₘ g) * (h ⊗ₘ k) = (f * h) ⊗ₘ (g * k) := by simp_rw [convMul_def, comul_def, mul'_tensor, comp_assoc, AlgebraTensorModule.map_eq, ← comp_assoc _ _ (tensorTensorTensorComm R _ _ _ _).toLinearMap] nth_rw 2 [← comp_assoc, comp_assoc] simp [AlgebraTensorModule.tensorTensorTensorComm_eq, ← tensorTensorTensorComm_comp_map, ← comp_assoc, map_comp] end NonUnitalNonAssocSemiring open scoped ConvolutionProduct section NonUnitalNonAssocRing variable [NonUnitalNonAssocRing A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] [AddCommMonoid C] [Module R C] [CoalgebraStruct R C] /-- Non-unital and non-associative convolution ring structure on linear maps from a coalgebra to a non-unital and non-associative algebra. -/ abbrev convNonUnitalNonAssocRing : NonUnitalNonAssocRing (C →ₗ[R] A) where scoped[ConvolutionProduct] attribute [instance] LinearMap.convNonUnitalNonAssocRing end NonUnitalNonAssocRing section NonUnitalSemiring variable [NonUnitalSemiring A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] [AddCommMonoid C] [Module R C] [Coalgebra R C] lemma nonUnitalAlgHom_comp_convMul_distrib [NonUnitalNonAssocSemiring B] [Module R B] [SMulCommClass R B B] [IsScalarTower R B B] (h : A →ₙₐ[R] B) (f g : C →ₗ[R] A) : (h : A →ₗ[R] B).comp (f * g) = .comp h f * .comp h g := by simp [convMul_def, map_comp, ← comp_assoc, NonUnitalAlgHom.comp_mul'] lemma convMul_comp_coalgHom_distrib [AddCommMonoid B] [Module R B] [CoalgebraStruct R B] (f g : C →ₗ[R] A) (h : B →ₗc[R] C) : (f * g).comp h.toLinearMap = f.comp h.toLinearMap * g.comp h.toLinearMap := by simp [convMul_def, map_comp, comp_assoc] /-- Non-unital convolution semiring structure on linear maps from a coalgebra to a non-unital algebra. -/ abbrev convNonUnitalSemiring : NonUnitalSemiring (C →ₗ[R] A) where mul_assoc f g h := calc μ ∘ₗ (μ ∘ₗ (f ⊗ₘ g) ∘ₗ δ ⊗ₘ h) ∘ₗ δ _ = (μ ∘ₗ .rTensor _ μ) ∘ₗ ((f ⊗ₘ g) ⊗ₘ h) ∘ₗ (.rTensor _ δ ∘ₗ δ) := by ext; simp _ = (μ ∘ₗ rTensor _ μ) ∘ₗ (((f ⊗ₘ g) ⊗ₘ h) ∘ₗ (TensorProduct.assoc R C C C).symm) ∘ₗ lTensor C δ ∘ₗ δ := by simp only [comp_assoc, coassoc_symm] _ = (μ ∘ₗ rTensor A μ ∘ₗ ↑(TensorProduct.assoc R A A A).symm) ∘ₗ (f ⊗ₘ (g ⊗ₘ h)) ∘ₗ lTensor C δ ∘ₗ δ := by simp only [map_map_comp_assoc_symm_eq, comp_assoc] _ = (μ ∘ₗ .lTensor _ μ) ∘ₗ (f ⊗ₘ (g ⊗ₘ h)) ∘ₗ (lTensor C δ ∘ₗ δ) := by congr 1 ext simp [mul_assoc] _ = μ ∘ₗ (f ⊗ₘ μ ∘ₗ (g ⊗ₘ h) ∘ₗ δ) ∘ₗ δ := by ext; simp scoped[ConvolutionProduct] attribute [instance] LinearMap.convNonUnitalSemiring end NonUnitalSemiring section NonUnitalRing variable [NonUnitalRing A] [AddCommMonoid C] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] [Module R C] [Coalgebra R C] /-- Non-unital convolution ring structure on linear maps from a coalgebra to a non-unital algebra. -/ abbrev convNonUnitalRing : NonUnitalRing (C →ₗ[R] A) where scoped[ConvolutionProduct] attribute [instance] LinearMap.convNonUnitalRing end NonUnitalRing section Semiring variable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [AddCommMonoid C] [Module R C] section CoalgebraStruct variable [CoalgebraStruct R C] lemma algHom_comp_convMul_distrib (h : A →ₐ B) (f g : C →ₗ[R] A) : h.toLinearMap.comp (f * g) = h.toLinearMap.comp f * h.toLinearMap.comp g := by simp [convMul_def, map_comp, ← comp_assoc, AlgHom.comp_mul'] end CoalgebraStruct variable [Coalgebra R C] /-- Convolution unit on linear maps from a coalgebra to an algebra. -/ abbrev convOne : One (C →ₗ[R] A) where one := Algebra.linearMap R A ∘ₗ counit scoped[ConvolutionProduct] attribute [instance] LinearMap.convOne lemma convOne_def : (1 : C →ₗ[R] A) = Algebra.linearMap R A ∘ₗ counit := rfl @[simp] lemma convOne_apply (c : C) : (1 : C →ₗ[R] A) c = algebraMap R A (counit (R := R) c) := rfl /-- Convolution semiring structure on linear maps from a coalgebra to an algebra. -/ abbrev convSemiring : Semiring (C →ₗ[R] A) where one_mul f := by ext; simp [convOne_def, ← map_comp_rTensor] mul_one f := by ext; simp [convOne_def, ← map_comp_lTensor] scoped[ConvolutionProduct] attribute [instance] LinearMap.convSemiring end Semiring section CommSemiring variable [CommSemiring A] [AddCommMonoid C] [Algebra R A] [Module R C] [Coalgebra R C] [IsCocomm R C] /-- Commutative convolution semiring structure on linear maps from a cocommutative coalgebra to an algebra. -/ abbrev convCommSemiring : CommSemiring (C →ₗ[R] A) where mul_comm f g := by ext x; rw [convMul_apply, ← comm_comul R x, map_comm, mul'_comm, convMul_apply] scoped[ConvolutionProduct] attribute [instance] LinearMap.convCommSemiring end CommSemiring section Ring variable [Ring A] [AddCommMonoid C] [Algebra R A] [Module R C] [Coalgebra R C] /-- Convolution ring structure on linear maps from a coalgebra to an algebra. -/ abbrev convRing : Ring (C →ₗ[R] A) where scoped[ConvolutionProduct] attribute [instance] LinearMap.convRing end Ring section CommRing variable [CommRing A] [AddCommMonoid C] [Algebra R A] [Module R C] [Coalgebra R C] [IsCocomm R C] /-- Commutative convolution ring structure on linear maps from a cocommutative coalgebra to an algebra. -/ abbrev convCommRing : CommRing (C →ₗ[R] A) where scoped[ConvolutionProduct] attribute [instance] LinearMap.convCommRing end CommRing end LinearMap
.lake/packages/mathlib/Mathlib/RingTheory/Coalgebra/TensorProduct.lean
import Mathlib.LinearAlgebra.TensorProduct.Tower import Mathlib.RingTheory.Coalgebra.Equiv /-! # Tensor products of coalgebras Suppose `S` is an `R`-algebra. Given an `S`-coalgebra `A` and `R`-coalgebra `B`, we can define a natural comultiplication map `Δ : A ⊗[R] B → (A ⊗[R] B) ⊗[S] (A ⊗[R] B)` and counit map `ε : A ⊗[R] B → S` induced by the comultiplication and counit maps of `A` and `B`. In this file we show that `Δ, ε` satisfy the axioms of a coalgebra, and also define other data in the monoidal structure on `R`-coalgebras, like the tensor product of two coalgebra morphisms as a coalgebra morphism. In particular, when `R = S` we get tensor products of coalgebras, and when `A = S` we get the base change `S ⊗[R] B` as an `S`-coalgebra. -/ open TensorProduct variable {R S A B : Type*} [CommSemiring R] [CommSemiring S] [AddCommMonoid A] [AddCommMonoid B] [Algebra R S] [Module R A] [Module S A] [Module R B] [IsScalarTower R S A] namespace TensorProduct open Coalgebra section CoalgebraStruct variable [CoalgebraStruct R B] [CoalgebraStruct S A] noncomputable instance instCoalgebraStruct : CoalgebraStruct S (A ⊗[R] B) where comul := AlgebraTensorModule.tensorTensorTensorComm R S R S A A B B ∘ₗ AlgebraTensorModule.map comul comul counit := AlgebraTensorModule.rid R S S ∘ₗ AlgebraTensorModule.map counit counit lemma comul_def : Coalgebra.comul (R := S) (A := A ⊗[R] B) = AlgebraTensorModule.tensorTensorTensorComm R S R S A A B B ∘ₗ AlgebraTensorModule.map Coalgebra.comul Coalgebra.comul := rfl lemma counit_def : Coalgebra.counit (R := S) (A := A ⊗[R] B) = AlgebraTensorModule.rid R S S ∘ₗ AlgebraTensorModule.map counit counit := rfl @[simp] lemma comul_tmul (x : A) (y : B) : comul (x ⊗ₜ y) = AlgebraTensorModule.tensorTensorTensorComm R S R S A A B B (comul x ⊗ₜ comul y) := rfl @[simp] lemma counit_tmul (x : A) (y : B) : counit (R := S) (x ⊗ₜ[R] y) = counit (R := R) y • counit (R := S) x := rfl end CoalgebraStruct variable [Coalgebra R B] [Coalgebra S A] open Lean.Parser.Tactic in /-- `hopf_tensor_induction x with x₁ x₂` attempts to replace `x` by `x₁ ⊗ₜ x₂` via linearity. This is an implementation detail that is used to set up tensor products of coalgebras, bialgebras, and hopf algebras, and shouldn't be relied on downstream. -/ scoped macro "hopf_tensor_induction " var:elimTarget "with " var₁:ident var₂:ident : tactic => `(tactic| (induction $var with | zero => simp only [tmul_zero, LinearEquiv.map_zero, LinearMap.map_zero, zero_tmul, zero_mul, mul_zero] | add _ _ h₁ h₂ => -- avoid the more general `map_add` for performance reasons simp only [LinearEquiv.map_add, LinearMap.map_add, tmul_add, add_tmul, add_mul, mul_add, h₁, h₂] | tmul $var₁ $var₂ => ?_)) private lemma coassoc : TensorProduct.assoc S (A ⊗[R] B) (A ⊗[R] B) (A ⊗[R] B) ∘ₗ (comul (R := S) (A := (A ⊗[R] B))).rTensor (A ⊗[R] B) ∘ₗ (comul (R := S) (A := (A ⊗[R] B))) = (comul (R := S) (A := (A ⊗[R] B))).lTensor (A ⊗[R] B) ∘ₗ (comul (R := S) (A := (A ⊗[R] B))) := by ext x y let F : A ⊗[S] (A ⊗[S] A) ⊗[R] (B ⊗[R] (B ⊗[R] B)) ≃ₗ[S] A ⊗[R] B ⊗[S] (A ⊗[R] B ⊗[S] (A ⊗[R] B)) := AlgebraTensorModule.tensorTensorTensorComm _ _ _ _ _ _ _ _ ≪≫ₗ AlgebraTensorModule.congr (.refl _ _) (AlgebraTensorModule.tensorTensorTensorComm _ _ _ _ _ _ _ _) let F' : A ⊗[S] (A ⊗[S] A) ⊗[R] (B ⊗[R] (B ⊗[R] B)) →ₗ[S] A ⊗[R] B ⊗[S] (A ⊗[R] B ⊗[S] (A ⊗[R] B)) := TensorProduct.mapOfCompatibleSMul _ _ _ _ ∘ₗ TensorProduct.map .id (TensorProduct.mapOfCompatibleSMul _ _ _ _) ∘ₗ F.toLinearMap convert congr(F ($(Coalgebra.coassoc_apply x) ⊗ₜ[R] $(Coalgebra.coassoc_apply y))) using 1 · dsimp hopf_tensor_induction comul (R := S) x with x₁ x₂ hopf_tensor_induction comul (R := R) y with y₁ y₂ dsimp hopf_tensor_induction comul (R := S) x₁ with x₁₁ x₁₂ hopf_tensor_induction comul (R := R) y₁ with y₁₁ y₁₂ rfl · dsimp hopf_tensor_induction comul (R := S) x with x₁ x₂ hopf_tensor_induction comul (R := R) y with y₁ y₂ dsimp hopf_tensor_induction comul (R := S) x₂ with x₂₁ x₂₂ hopf_tensor_induction comul (R := R) y₂ with y₂₁ y₂₂ rfl noncomputable instance instCoalgebra : Coalgebra S (A ⊗[R] B) where coassoc := coassoc (R := R) rTensor_counit_comp_comul := by ext x y convert congr((TensorProduct.lid S _).symm (TensorProduct.lid _ _ $(rTensor_counit_comul (R := S) x) ⊗ₜ[R] TensorProduct.lid _ _ $(rTensor_counit_comul (R := R) y))) · dsimp hopf_tensor_induction comul (R := S) x with x₁ x₂ hopf_tensor_induction comul (R := R) y with y₁ y₂ apply (TensorProduct.lid S _).injective dsimp rw [tmul_smul, smul_assoc, one_smul, smul_tmul'] · dsimp simp only [one_smul] lTensor_counit_comp_comul := by ext x y convert congr((TensorProduct.rid S _).symm (TensorProduct.rid _ _ $(lTensor_counit_comul (R := S) x) ⊗ₜ[R] TensorProduct.rid _ _ $(lTensor_counit_comul (R := R) y))) · dsimp hopf_tensor_induction comul (R := S) x with x₁ x₂ hopf_tensor_induction comul (R := R) y with y₁ y₂ apply (TensorProduct.rid S _).injective dsimp rw [tmul_smul, smul_assoc, one_smul, smul_tmul'] · dsimp simp only [one_smul] instance [IsCocomm S A] [IsCocomm R B] : IsCocomm S (A ⊗[R] B) where comm_comp_comul := by ext x y dsimp conv_rhs => rw [← comm_comul _ x, ← comm_comul _ y] hopf_tensor_induction comul (R := S) x with x₁ x₂ hopf_tensor_induction comul (R := R) y with y₁ y₂ simp end TensorProduct namespace Coalgebra namespace TensorProduct variable {R S M N P Q : Type*} [CommSemiring R] [CommSemiring S] [Algebra R S] [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] [AddCommMonoid Q] [Module R M] [Module R N] [Module R P] [Module R Q] [Module S M] [IsScalarTower R S M] [Coalgebra S M] [Module S N] [IsScalarTower R S N] [Coalgebra S N] [Coalgebra R P] [Coalgebra R Q] section /-- The tensor product of two coalgebra morphisms as a coalgebra morphism. -/ noncomputable def map (f : M →ₗc[S] N) (g : P →ₗc[R] Q) : M ⊗[R] P →ₗc[S] N ⊗[R] Q where toLinearMap := AlgebraTensorModule.map f.toLinearMap g.toLinearMap counit_comp := by ext; simp map_comp_comul := by ext x y dsimp simp only [← CoalgHomClass.map_comp_comul_apply] hopf_tensor_induction comul (R := S) x with x₁ x₂ hopf_tensor_induction comul (R := R) y with y₁ y₂ simp @[simp] theorem map_tmul (f : M →ₗc[S] N) (g : P →ₗc[R] Q) (x : M) (y : P) : map f g (x ⊗ₜ y) = f x ⊗ₜ g y := rfl @[simp] theorem map_toLinearMap (f : M →ₗc[S] N) (g : P →ₗc[R] Q) : map f g = AlgebraTensorModule.map (f : M →ₗ[S] N) (g : P →ₗ[R] Q) := rfl variable (R S M N P) /-- The associator for tensor products of R-coalgebras, as a coalgebra equivalence. -/ protected noncomputable def assoc : (M ⊗[S] N) ⊗[R] P ≃ₗc[S] M ⊗[S] (N ⊗[R] P) := { AlgebraTensorModule.assoc R S S M N P with counit_comp := by ext; simp map_comp_comul := by ext x y z dsimp hopf_tensor_induction comul (R := S) x with x₁ x₂ hopf_tensor_induction comul (R := S) y with y₁ y₂ hopf_tensor_induction comul (R := R) z with z₁ z₂ simp } variable {R S M N P} @[simp] theorem assoc_tmul (x : M) (y : N) (z : P) : Coalgebra.TensorProduct.assoc R S M N P ((x ⊗ₜ y) ⊗ₜ z) = x ⊗ₜ (y ⊗ₜ z) := rfl @[simp] theorem assoc_symm_tmul (x : M) (y : N) (z : P) : (Coalgebra.TensorProduct.assoc R S M N P).symm (x ⊗ₜ (y ⊗ₜ z)) = (x ⊗ₜ y) ⊗ₜ z := rfl @[simp] theorem assoc_toLinearEquiv : Coalgebra.TensorProduct.assoc R S M N P = AlgebraTensorModule.assoc R S S M N P := rfl variable (R P) /-- The base ring is a left identity for the tensor product of coalgebras, up to coalgebra equivalence. -/ protected noncomputable def lid : R ⊗[R] P ≃ₗc[R] P := { _root_.TensorProduct.lid R P with counit_comp := by ext; simp map_comp_comul := by ext x dsimp simp only [one_smul] hopf_tensor_induction comul (R := R) x with x₁ x₂ simp } variable {R P} @[simp] theorem lid_toLinearEquiv : (Coalgebra.TensorProduct.lid R P) = _root_.TensorProduct.lid R P := rfl @[simp] theorem lid_tmul (r : R) (a : P) : Coalgebra.TensorProduct.lid R P (r ⊗ₜ a) = r • a := rfl @[simp] theorem lid_symm_apply (a : P) : (Coalgebra.TensorProduct.lid R P).symm a = 1 ⊗ₜ a := rfl variable (R S M) in /-- The base ring is a right identity for the tensor product of coalgebras, up to coalgebra equivalence. -/ protected noncomputable def rid : M ⊗[R] R ≃ₗc[S] M := { AlgebraTensorModule.rid R S M with counit_comp := by ext; simp map_comp_comul := by ext x dsimp simp only [one_smul] hopf_tensor_induction comul (R := S) x with x₁ x₂ simp } @[simp] theorem rid_toLinearEquiv : (Coalgebra.TensorProduct.rid R S M) = AlgebraTensorModule.rid R S M := rfl @[simp] theorem rid_tmul (r : R) (a : M) : Coalgebra.TensorProduct.rid R S M (a ⊗ₜ r) = r • a := rfl @[simp] theorem rid_symm_apply (a : M) : (Coalgebra.TensorProduct.rid R S M).symm a = a ⊗ₜ 1 := rfl end end TensorProduct end Coalgebra namespace CoalgHom variable {R M N P : Type*} [CommRing R] [AddCommGroup M] [AddCommGroup N] [AddCommGroup P] [Module R M] [Module R N] [Module R P] [Coalgebra R M] [Coalgebra R N] [Coalgebra R P] variable (M) /-- `lTensor M f : M ⊗ N →ₗc M ⊗ P` is the natural coalgebra morphism induced by `f : N →ₗc P`. -/ noncomputable abbrev lTensor (f : N →ₗc[R] P) : M ⊗[R] N →ₗc[R] M ⊗[R] P := Coalgebra.TensorProduct.map (CoalgHom.id R M) f /-- `rTensor M f : N ⊗ M →ₗc P ⊗ M` is the natural coalgebra morphism induced by `f : N →ₗc P`. -/ noncomputable abbrev rTensor (f : N →ₗc[R] P) : N ⊗[R] M →ₗc[R] P ⊗[R] M := Coalgebra.TensorProduct.map f (CoalgHom.id R M) end CoalgHom
.lake/packages/mathlib/Mathlib/RingTheory/Coalgebra/MulOpposite.lean
import Mathlib.RingTheory.Coalgebra.Basic /-! # MulOpposite of coalgebras Suppose `R` is a commutative semiring, and `A` is an `R`-coalgebra, then `Aᵐᵒᵖ` is an `R`-coalgebra, where we define the comultiplication and counit maps naturally. -/ namespace MulOpposite open scoped TensorProduct open TensorProduct Coalgebra LinearMap variable {R A : Type*} [CommSemiring R] [AddCommMonoid A] [Module R A] noncomputable instance [CoalgebraStruct R A] : CoalgebraStruct R Aᵐᵒᵖ where comul := map (opLinearEquiv R).toLinearMap (opLinearEquiv R).toLinearMap ∘ₗ comul ∘ₗ (opLinearEquiv R).symm.toLinearMap counit := counit ∘ₗ (opLinearEquiv R).symm.toLinearMap lemma comul_def [CoalgebraStruct R A] : comul (R := R) (A := Aᵐᵒᵖ) = map (opLinearEquiv R).toLinearMap (opLinearEquiv R).toLinearMap ∘ₗ comul ∘ₗ (opLinearEquiv R).symm.toLinearMap := rfl lemma counit_def [CoalgebraStruct R A] : counit (R := R) (A := Aᵐᵒᵖ) = counit ∘ₗ (opLinearEquiv R).symm.toLinearMap := rfl noncomputable instance [Coalgebra R A] : Coalgebra R Aᵐᵒᵖ where coassoc := ext fun _ => by rw [comul_def, rTensor_comp, rTensor_comp] simp only [coe_comp, LinearEquiv.coe_coe, Function.comp_apply, lTensor_map, rTensor_def] simp_rw [← map_map_assoc, map_map, comp_assoc, ← lTensor_comp_rTensor] simp [lTensor_tensor, comp_assoc] rTensor_counit_comp_comul := ext fun _ => by simp only [counit_def, comul_def, coe_comp, Function.comp_apply, rTensor_map, comp_assoc] simp [← lTensor_comp_rTensor] lTensor_counit_comp_comul := ext fun _ => by simp only [counit_def, comul_def, coe_comp, Function.comp_apply, lTensor_map, comp_assoc] simp [← rTensor_comp_lTensor] end MulOpposite
.lake/packages/mathlib/Mathlib/RingTheory/Coalgebra/Basic.lean
import Mathlib.LinearAlgebra.TensorProduct.Finiteness import Mathlib.LinearAlgebra.TensorProduct.Associator /-! # Coalgebras In this file we define `Coalgebra`, and provide instances for: * Commutative semirings: `CommSemiring.toCoalgebra` * Binary products: `Prod.instCoalgebra` * Finitely supported functions: `DFinsupp.instCoalgebra`, `Finsupp.instCoalgebra` ## References * <https://en.wikipedia.org/wiki/Coalgebra> -/ universe u v w open scoped TensorProduct /-- Data fields for `Coalgebra`, to allow API to be constructed before proving `Coalgebra.coassoc`. See `Coalgebra` for documentation. -/ class CoalgebraStruct (R : Type u) (A : Type v) [CommSemiring R] [AddCommMonoid A] [Module R A] where /-- The comultiplication of the coalgebra -/ comul : A →ₗ[R] A ⊗[R] A /-- The counit of the coalgebra -/ counit : A →ₗ[R] R @[inherit_doc] scoped[RingTheory.LinearMap] notation "ε" => CoalgebraStruct.counit @[inherit_doc] scoped[RingTheory.LinearMap] notation "δ" => CoalgebraStruct.comul /-- A representation of an element `a` of a coalgebra `A` is a finite sum of pure tensors `∑ xᵢ ⊗ yᵢ` that is equal to `comul a`. -/ structure Coalgebra.Repr (R : Type u) {A : Type v} [CommSemiring R] [AddCommMonoid A] [Module R A] [CoalgebraStruct R A] (a : A) where /-- the indexing type of a representation of `comul a` -/ {ι : Type*} /-- the finite indexing set of a representation of `comul a` -/ (index : Finset ι) /-- the first coordinate of a representation of `comul a` -/ (left : ι → A) /-- the second coordinate of a representation of `comul a` -/ (right : ι → A) /-- `comul a` is equal to a finite sum of some pure tensors -/ (eq : ∑ i ∈ index, left i ⊗ₜ[R] right i = CoalgebraStruct.comul a) /-- An arbitrarily chosen representation. -/ noncomputable def Coalgebra.Repr.arbitrary (R : Type u) {A : Type v} [CommSemiring R] [AddCommMonoid A] [Module R A] [CoalgebraStruct R A] (a : A) : Coalgebra.Repr R a where left := Prod.fst right := Prod.snd index := TensorProduct.exists_finset (R := R) (CoalgebraStruct.comul a) |>.choose eq := TensorProduct.exists_finset (R := R) (CoalgebraStruct.comul a) |>.choose_spec.symm @[inherit_doc Coalgebra.Repr.arbitrary] scoped[Coalgebra] notation "ℛ" => Coalgebra.Repr.arbitrary namespace Coalgebra export CoalgebraStruct (comul counit) end Coalgebra /-- A coalgebra over a commutative (semi)ring `R` is an `R`-module equipped with a coassociative comultiplication `Δ` and a counit `ε` obeying the left and right counitality laws. -/ class Coalgebra (R : Type u) (A : Type v) [CommSemiring R] [AddCommMonoid A] [Module R A] extends CoalgebraStruct R A where /-- The comultiplication is coassociative -/ coassoc : TensorProduct.assoc R A A A ∘ₗ comul.rTensor A ∘ₗ comul = comul.lTensor A ∘ₗ comul /-- The counit satisfies the left counitality law -/ rTensor_counit_comp_comul : counit.rTensor A ∘ₗ comul = TensorProduct.mk R _ _ 1 /-- The counit satisfies the right counitality law -/ lTensor_counit_comp_comul : counit.lTensor A ∘ₗ comul = (TensorProduct.mk R _ _).flip 1 namespace Coalgebra variable {R : Type u} {A : Type v} variable [CommSemiring R] [AddCommMonoid A] [Module R A] [Coalgebra R A] {a : A} @[simp] theorem coassoc_apply (a : A) : TensorProduct.assoc R A A A (comul.rTensor A (comul a)) = comul.lTensor A (comul a) := LinearMap.congr_fun coassoc a @[simp] theorem coassoc_symm_apply (a : A) : (TensorProduct.assoc R A A A).symm (comul.lTensor A (comul a)) = comul.rTensor A (comul a) := by rw [(TensorProduct.assoc R A A A).symm_apply_eq, coassoc_apply a] @[simp] theorem coassoc_symm : (TensorProduct.assoc R A A A).symm ∘ₗ comul.lTensor A ∘ₗ comul = comul.rTensor A ∘ₗ (comul (R := R)) := LinearMap.ext coassoc_symm_apply @[simp] theorem rTensor_counit_comul (a : A) : counit.rTensor A (comul a) = 1 ⊗ₜ[R] a := LinearMap.congr_fun rTensor_counit_comp_comul a @[simp] theorem lTensor_counit_comul (a : A) : counit.lTensor A (comul a) = a ⊗ₜ[R] 1 := LinearMap.congr_fun lTensor_counit_comp_comul a @[simp] lemma sum_counit_tmul_eq {a : A} (repr : Coalgebra.Repr R a) : ∑ i ∈ repr.index, counit (R := R) (repr.left i) ⊗ₜ (repr.right i) = 1 ⊗ₜ[R] a := by simpa [← repr.eq, map_sum] using congr($(rTensor_counit_comp_comul (R := R) (A := A)) a) @[simp] lemma sum_tmul_counit_eq {a : A} (repr : Coalgebra.Repr R a) : ∑ i ∈ repr.index, (repr.left i) ⊗ₜ counit (R := R) (repr.right i) = a ⊗ₜ[R] 1 := by simpa [← repr.eq, map_sum] using congr($(lTensor_counit_comp_comul (R := R) (A := A)) a) -- Cannot be @[simp] because `a₂` cannot be inferred by `simp`. lemma sum_tmul_tmul_eq {a : A} (repr : Repr R a) (a₁ : (i : repr.ι) → Repr R (repr.left i)) (a₂ : (i : repr.ι) → Repr R (repr.right i)) : ∑ i ∈ repr.index, ∑ j ∈ (a₁ i).index, (a₁ i).left j ⊗ₜ[R] ((a₁ i).right j ⊗ₜ[R] repr.right i) = ∑ i ∈ repr.index, ∑ j ∈ (a₂ i).index, repr.left i ⊗ₜ[R] ((a₂ i).left j ⊗ₜ[R] (a₂ i).right j) := by simpa [(a₂ _).eq, ← (a₁ _).eq, ← TensorProduct.tmul_sum, TensorProduct.sum_tmul, ← repr.eq] using congr($(coassoc (R := R)) a) @[simp] theorem sum_counit_tmul_map_eq {B : Type*} [AddCommMonoid B] [Module R B] {F : Type*} [FunLike F A B] [LinearMapClass F R A B] (f : F) (a : A) {repr : Repr R a} : ∑ i ∈ repr.index, counit (R := R) (repr.left i) ⊗ₜ f (repr.right i) = 1 ⊗ₜ[R] f a := by have := sum_counit_tmul_eq repr apply_fun LinearMap.lTensor R (f : A →ₗ[R] B) at this simp_all only [map_sum, LinearMap.lTensor_tmul, LinearMap.coe_coe] @[simp] theorem sum_map_tmul_counit_eq {B : Type*} [AddCommMonoid B] [Module R B] {F : Type*} [FunLike F A B] [LinearMapClass F R A B] (f : F) (a : A) {repr : Repr R a} : ∑ i ∈ repr.index, f (repr.left i) ⊗ₜ counit (R := R) (repr.right i) = f a ⊗ₜ[R] 1 := by have := sum_tmul_counit_eq repr apply_fun LinearMap.rTensor R (f : A →ₗ[R] B) at this simp_all only [map_sum, LinearMap.rTensor_tmul, LinearMap.coe_coe] -- Cannot be @[simp] because `a₁` cannot be inferred by `simp`. theorem sum_map_tmul_tmul_eq {B : Type*} [AddCommMonoid B] [Module R B] {F : Type*} [FunLike F A B] [LinearMapClass F R A B] (f g h : F) (a : A) {repr : Repr R a} {a₁ : (i : repr.ι) → Repr R (repr.left i)} {a₂ : (i : repr.ι) → Repr R (repr.right i)} : ∑ i ∈ repr.index, ∑ j ∈ (a₂ i).index, f (repr.left i) ⊗ₜ (g ((a₂ i).left j) ⊗ₜ h ((a₂ i).right j)) = ∑ i ∈ repr.index, ∑ j ∈ (a₁ i).index, f ((a₁ i).left j) ⊗ₜ[R] (g ((a₁ i).right j) ⊗ₜ[R] h (repr.right i)) := by have := sum_tmul_tmul_eq repr a₁ a₂ apply_fun TensorProduct.map (f : A →ₗ[R] B) (TensorProduct.map (g : A →ₗ[R] B) (h : A →ₗ[R] B)) at this simp_all only [map_sum, TensorProduct.map_tmul, LinearMap.coe_coe] lemma sum_counit_smul (𝓡 : Repr R a) : ∑ x ∈ 𝓡.index, counit (R := R) (𝓡.left x) • 𝓡.right x = a := by simpa only [map_sum, TensorProduct.lift.tmul, LinearMap.lsmul_apply, one_smul] using congr(TensorProduct.lift (LinearMap.lsmul R A) $(sum_counit_tmul_eq (R := R) 𝓡)) lemma lift_lsmul_comp_counit_comp_comul : TensorProduct.lift (.lsmul R A ∘ₗ counit) ∘ₗ comul = .id := by have := rTensor_counit_comp_comul (R := R) (A := A) apply_fun (TensorProduct.lift (LinearMap.lsmul R A) ∘ₗ ·) at this rw [LinearMap.rTensor, ← LinearMap.comp_assoc, TensorProduct.lift_comp_map, LinearMap.compl₂_id] at this ext simp [this] variable (R A) in /-- A coalgebra `A` is cocommutative if its comultiplication `δ : A → A ⊗ A` commutes with the swapping `β : A ⊗ A ≃ A ⊗ A` of the factors in the tensor product. -/ class IsCocomm where protected comm_comp_comul : (TensorProduct.comm R A A).comp comul = comul variable [IsCocomm R A] variable (R A) in @[simp] lemma comm_comp_comul : (TensorProduct.comm R A A).comp comul = comul := IsCocomm.comm_comp_comul variable (R) in @[simp] lemma comm_comul (a : A) : TensorProduct.comm R A A (comul a) = comul a := congr($(comm_comp_comul R A) a) end Coalgebra open Coalgebra namespace CommSemiring variable (R : Type u) [CommSemiring R] /-- Every commutative (semi)ring is a coalgebra over itself, with `Δ r = 1 ⊗ₜ r`. -/ instance toCoalgebra : Coalgebra R R where comul := (TensorProduct.mk R R R) 1 counit := .id coassoc := rfl rTensor_counit_comp_comul := by ext; rfl lTensor_counit_comp_comul := by ext; rfl @[simp] theorem comul_apply (r : R) : comul r = 1 ⊗ₜ[R] r := rfl @[simp] theorem counit_apply (r : R) : counit r = r := rfl instance : IsCocomm R R where comm_comp_comul := by ext; simp end CommSemiring namespace Prod variable (R : Type u) (A : Type v) (B : Type w) variable [CommSemiring R] [AddCommMonoid A] [AddCommMonoid B] [Module R A] [Module R B] variable [Coalgebra R A] [Coalgebra R B] open LinearMap instance instCoalgebraStruct : CoalgebraStruct R (A × B) where comul := .coprod (TensorProduct.map (.inl R A B) (.inl R A B) ∘ₗ comul) (TensorProduct.map (.inr R A B) (.inr R A B) ∘ₗ comul) counit := .coprod counit counit @[simp] theorem comul_apply (r : A × B) : comul r = TensorProduct.map (.inl R A B) (.inl R A B) (comul r.1) + TensorProduct.map (.inr R A B) (.inr R A B) (comul r.2) := rfl @[simp] theorem counit_apply (r : A × B) : (counit r : R) = counit r.1 + counit r.2 := rfl theorem comul_comp_inl : comul ∘ₗ inl R A B = TensorProduct.map (.inl R A B) (.inl R A B) ∘ₗ comul := by ext; simp theorem comul_comp_inr : comul ∘ₗ inr R A B = TensorProduct.map (.inr R A B) (.inr R A B) ∘ₗ comul := by ext; simp theorem comul_comp_fst : comul ∘ₗ .fst R A B = TensorProduct.map (.fst R A B) (.fst R A B) ∘ₗ comul := by ext : 1 · rw [comp_assoc, fst_comp_inl, comp_id, comp_assoc, comul_comp_inl, ← comp_assoc, ← TensorProduct.map_comp, fst_comp_inl, TensorProduct.map_id, id_comp] · rw [comp_assoc, fst_comp_inr, comp_zero, comp_assoc, comul_comp_inr, ← comp_assoc, ← TensorProduct.map_comp, fst_comp_inr, TensorProduct.map_zero_left, zero_comp] theorem comul_comp_snd : comul ∘ₗ .snd R A B = TensorProduct.map (.snd R A B) (.snd R A B) ∘ₗ comul := by ext : 1 · rw [comp_assoc, snd_comp_inl, comp_zero, comp_assoc, comul_comp_inl, ← comp_assoc, ← TensorProduct.map_comp, snd_comp_inl, TensorProduct.map_zero_left, zero_comp] · rw [comp_assoc, snd_comp_inr, comp_id, comp_assoc, comul_comp_inr, ← comp_assoc, ← TensorProduct.map_comp, snd_comp_inr, TensorProduct.map_id, id_comp] @[simp] theorem counit_comp_inr : counit ∘ₗ inr R A B = counit := by ext; simp @[simp] theorem counit_comp_inl : counit ∘ₗ inl R A B = counit := by ext; simp instance instCoalgebra : Coalgebra R (A × B) where rTensor_counit_comp_comul := by ext : 1 · rw [comp_assoc, comul_comp_inl, ← comp_assoc, rTensor_comp_map, counit_comp_inl, ← lTensor_comp_rTensor, comp_assoc, rTensor_counit_comp_comul, lTensor_comp_mk] · rw [comp_assoc, comul_comp_inr, ← comp_assoc, rTensor_comp_map, counit_comp_inr, ← lTensor_comp_rTensor, comp_assoc, rTensor_counit_comp_comul, lTensor_comp_mk] lTensor_counit_comp_comul := by ext : 1 · rw [comp_assoc, comul_comp_inl, ← comp_assoc, lTensor_comp_map, counit_comp_inl, ← rTensor_comp_lTensor, comp_assoc, lTensor_counit_comp_comul, rTensor_comp_flip_mk] · rw [comp_assoc, comul_comp_inr, ← comp_assoc, lTensor_comp_map, counit_comp_inr, ← rTensor_comp_lTensor, comp_assoc, lTensor_counit_comp_comul, rTensor_comp_flip_mk] coassoc := by dsimp only [instCoalgebraStruct] ext x : 2 <;> dsimp only [comp_apply, LinearEquiv.coe_coe, coe_inl, coe_inr, coprod_apply] · simp only [map_zero, add_zero] simp_rw [← comp_apply, ← comp_assoc, rTensor_comp_map, lTensor_comp_map, coprod_inl, ← map_comp_rTensor, ← map_comp_lTensor, comp_assoc, ← coassoc, ← comp_assoc, TensorProduct.map_map_comp_assoc_eq, comp_apply, LinearEquiv.coe_coe] · simp only [map_zero, zero_add] simp_rw [← comp_apply, ← comp_assoc, rTensor_comp_map, lTensor_comp_map, coprod_inr, ← map_comp_rTensor, ← map_comp_lTensor, comp_assoc, ← coassoc, ← comp_assoc, TensorProduct.map_map_comp_assoc_eq, comp_apply, LinearEquiv.coe_coe] instance [IsCocomm R A] [IsCocomm R B] : IsCocomm R (A × B) where comm_comp_comul := by ext <;> simp [← TensorProduct.map_comm] end Prod namespace DFinsupp variable (R : Type u) (ι : Type v) (A : ι → Type w) variable [DecidableEq ι] variable [CommSemiring R] [∀ i, AddCommMonoid (A i)] [∀ i, Module R (A i)] [∀ i, Coalgebra R (A i)] open LinearMap instance instCoalgebraStruct : CoalgebraStruct R (Π₀ i, A i) where comul := DFinsupp.lsum R fun i => TensorProduct.map (DFinsupp.lsingle i) (DFinsupp.lsingle i) ∘ₗ comul counit := DFinsupp.lsum R fun _ => counit @[simp] theorem comul_single (i : ι) (a : A i) : comul (R := R) (DFinsupp.single i a) = (TensorProduct.map (DFinsupp.lsingle i) (DFinsupp.lsingle i) : _ →ₗ[R] _) (comul a) := lsum_single _ _ _ _ @[simp] theorem counit_single (i : ι) (a : A i) : counit (DFinsupp.single i a) = counit (R := R) a := lsum_single _ _ _ _ theorem comul_comp_lsingle (i : ι) : comul ∘ₗ (lsingle i : A i →ₗ[R] _) = TensorProduct.map (lsingle i) (lsingle i) ∘ₗ comul := by ext; simp theorem comul_comp_lapply (i : ι) : comul ∘ₗ (lapply i : _ →ₗ[R] A i) = TensorProduct.map (lapply i) (lapply i) ∘ₗ comul := by ext j : 1 conv_rhs => rw [comp_assoc, comul_comp_lsingle, ← comp_assoc, ← TensorProduct.map_comp] obtain rfl | hij := eq_or_ne i j · rw [comp_assoc, lapply_comp_lsingle_same, comp_id, TensorProduct.map_id, id_comp] · rw [comp_assoc, lapply_comp_lsingle_of_ne _ _ hij, comp_zero, TensorProduct.map_zero_left, zero_comp] @[simp] theorem counit_comp_lsingle (i : ι) : counit ∘ₗ (lsingle i : A i →ₗ[R] _) = counit := by ext; simp /-- The `R`-module whose elements are dependent functions `(i : ι) → A i` which are zero on all but finitely many elements of `ι` has a coalgebra structure. The coproduct `Δ` is given by `Δ(fᵢ a) = fᵢ a₁ ⊗ fᵢ a₂` where `Δ(a) = a₁ ⊗ a₂` and the counit `ε` by `ε(fᵢ a) = ε(a)`, where `fᵢ a` is the function sending `i` to `a` and all other elements of `ι` to zero. -/ instance instCoalgebra : Coalgebra R (Π₀ i, A i) where rTensor_counit_comp_comul := by ext : 1 rw [comp_assoc, comul_comp_lsingle, ← comp_assoc, rTensor_comp_map, counit_comp_lsingle, ← lTensor_comp_rTensor, comp_assoc, rTensor_counit_comp_comul, lTensor_comp_mk] lTensor_counit_comp_comul := by ext : 1 rw [comp_assoc, comul_comp_lsingle, ← comp_assoc, lTensor_comp_map, counit_comp_lsingle, ← rTensor_comp_lTensor, comp_assoc, lTensor_counit_comp_comul, rTensor_comp_flip_mk] coassoc := by ext i : 1 simp_rw [comp_assoc, comul_comp_lsingle, ← comp_assoc, lTensor_comp_map, comul_comp_lsingle, comp_assoc, ← comp_assoc comul, rTensor_comp_map, comul_comp_lsingle, ← map_comp_rTensor, ← map_comp_lTensor, comp_assoc, ← coassoc, ← comp_assoc comul, ← comp_assoc, TensorProduct.map_map_comp_assoc_eq] instance instIsCocomm [∀ i, IsCocomm R (A i)] : IsCocomm R (Π₀ i, A i) where comm_comp_comul := by ext i : 1 -- TODO: Add `reassoc` for `LinearMap`. Then we wouldn't need to reassociate back and forth. simp only [comp_assoc, comul_comp_lsingle] simp only [← comp_assoc, ← TensorProduct.map_comp_comm_eq] simp [LinearMap.comp_assoc] end DFinsupp namespace Finsupp variable (R : Type u) (ι : Type v) (A : Type w) variable [CommSemiring R] [AddCommMonoid A] [Module R A] [Coalgebra R A] open LinearMap noncomputable instance instCoalgebraStruct : CoalgebraStruct R (ι →₀ A) where comul := Finsupp.lsum R fun i => TensorProduct.map (Finsupp.lsingle i) (Finsupp.lsingle i) ∘ₗ comul counit := Finsupp.lsum R fun _ => counit @[simp] theorem comul_single (i : ι) (a : A) : comul (R := R) (Finsupp.single i a) = (TensorProduct.map (Finsupp.lsingle i) (Finsupp.lsingle i) : _ →ₗ[R] _) (comul a) := lsum_single _ _ _ _ @[simp] theorem counit_single (i : ι) (a : A) : counit (Finsupp.single i a) = counit (R := R) a := lsum_single _ _ _ _ theorem comul_comp_lsingle (i : ι) : comul ∘ₗ (lsingle i : A →ₗ[R] _) = TensorProduct.map (lsingle i) (lsingle i) ∘ₗ comul := by ext; simp theorem comul_comp_lapply (i : ι) : comul ∘ₗ (lapply i : _ →ₗ[R] A) = TensorProduct.map (lapply i) (lapply i) ∘ₗ comul := by ext j : 1 conv_rhs => rw [comp_assoc, comul_comp_lsingle, ← comp_assoc, ← TensorProduct.map_comp] obtain rfl | hij := eq_or_ne i j · rw [comp_assoc, lapply_comp_lsingle_same, comp_id, TensorProduct.map_id, id_comp] · rw [comp_assoc, lapply_comp_lsingle_of_ne _ _ hij, comp_zero, TensorProduct.map_zero_left, zero_comp] @[simp] theorem counit_comp_lsingle (i : ι) : counit ∘ₗ (lsingle i : A →ₗ[R] _) = counit := by ext; simp /-- The `R`-module whose elements are functions `ι → A` which are zero on all but finitely many elements of `ι` has a coalgebra structure. The coproduct `Δ` is given by `Δ(fᵢ a) = fᵢ a₁ ⊗ fᵢ a₂` where `Δ(a) = a₁ ⊗ a₂` and the counit `ε` by `ε(fᵢ a) = ε(a)`, where `fᵢ a` is the function sending `i` to `a` and all other elements of `ι` to zero. -/ noncomputable instance instCoalgebra : Coalgebra R (ι →₀ A) where rTensor_counit_comp_comul := by ext : 1 rw [comp_assoc, comul_comp_lsingle, ← comp_assoc, rTensor_comp_map, counit_comp_lsingle, ← lTensor_comp_rTensor, comp_assoc, rTensor_counit_comp_comul, lTensor_comp_mk] lTensor_counit_comp_comul := by ext : 1 rw [comp_assoc, comul_comp_lsingle, ← comp_assoc, lTensor_comp_map, counit_comp_lsingle, ← rTensor_comp_lTensor, comp_assoc, lTensor_counit_comp_comul, rTensor_comp_flip_mk] coassoc := by ext i : 1 simp_rw [comp_assoc, comul_comp_lsingle, ← comp_assoc, lTensor_comp_map, comul_comp_lsingle, comp_assoc, ← comp_assoc comul, rTensor_comp_map, comul_comp_lsingle, ← map_comp_rTensor, ← map_comp_lTensor, comp_assoc, ← coassoc, ← comp_assoc comul, ← comp_assoc, TensorProduct.map_map_comp_assoc_eq] instance instIsCocomm [IsCocomm R A] : IsCocomm R (ι →₀ A) where comm_comp_comul := by ext i : 1 -- TODO: Add `reassoc` for `LinearMap`. Then we wouldn't need to reassociate back and forth. simp only [comp_assoc, comul_comp_lsingle] simp only [← comp_assoc, ← TensorProduct.map_comp_comm_eq] simp [LinearMap.comp_assoc] end Finsupp
.lake/packages/mathlib/Mathlib/RingTheory/Coalgebra/MonoidAlgebra.lean
import Mathlib.Algebra.Polynomial.Laurent import Mathlib.RingTheory.Coalgebra.Basic /-! # The coalgebra structure on monoid algebras Given a type `X`, a commutative semiring `R` and a semiring `A` which is also an `R`-coalgebra, this file collects results about the `R`-coalgebra instance on `A[X]` inherited from the corresponding structure on its coefficients, defined in `Mathlib/RingTheory/Coalgebra/Basic.lean`. ## Main definitions * `(Add)MonoidAlgebra.instCoalgebra`: the `R`-coalgebra structure on `A[X]` when `A` is an `R`-coalgebra. * `LaurentPolynomial.instCoalgebra`: the `R`-coalgebra structure on the Laurent polynomials `A[T;T⁻¹]` when `A` is an `R`-coalgebra. -/ noncomputable section open Coalgebra namespace MonoidAlgebra variable {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] {X : Type*} [Module R A] [Coalgebra R A] variable (R A X) in instance instCoalgebra : Coalgebra R (MonoidAlgebra A X) := Finsupp.instCoalgebra R X A instance instIsCocomm [IsCocomm R A] : IsCocomm R (MonoidAlgebra A X) := Finsupp.instIsCocomm R X A @[simp] lemma counit_single (x : X) (a : A) : Coalgebra.counit (single x a) = Coalgebra.counit (R := R) a := Finsupp.counit_single _ _ _ _ _ @[simp] lemma comul_single (x : X) (a : A) : Coalgebra.comul (R := R) (single x a) = TensorProduct.map (lsingle x) (lsingle x) (Coalgebra.comul a) := Finsupp.comul_single _ _ _ _ _ end MonoidAlgebra namespace AddMonoidAlgebra variable {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] {X : Type*} [Module R A] [Coalgebra R A] variable (R A X) in instance instCoalgebra : Coalgebra R A[X] := Finsupp.instCoalgebra R X A instance instIsCocomm [IsCocomm R A] : IsCocomm R A[X] := Finsupp.instIsCocomm R X A @[simp] lemma counit_single (x : X) (a : A) : Coalgebra.counit (single x a) = Coalgebra.counit (R := R) a := Finsupp.counit_single _ _ _ _ _ @[simp] lemma comul_single (x : X) (a : A) : Coalgebra.comul (R := R) (single x a) = TensorProduct.map (lsingle x) (lsingle x) (Coalgebra.comul a) := Finsupp.comul_single _ _ _ _ _ end AddMonoidAlgebra namespace LaurentPolynomial open AddMonoidAlgebra variable (R A : Type*) [CommSemiring R] [Semiring A] [Module R A] [Coalgebra R A] instance instCoalgebra : Coalgebra R A[T;T⁻¹] := inferInstanceAs <| Coalgebra R A[ℤ] instance instIsCocomm [IsCocomm R A] : IsCocomm R A[T;T⁻¹] := inferInstanceAs <| IsCocomm R A[ℤ] variable {R A} @[simp] theorem comul_C (a : A) : Coalgebra.comul (R := R) (C a) = TensorProduct.map (lsingle 0) (lsingle 0) (Coalgebra.comul (R := R) a) := comul_single _ _ @[simp] theorem comul_C_mul_T (a : A) (n : ℤ) : Coalgebra.comul (R := R) (C a * T n) = TensorProduct.map (lsingle n) (lsingle n) (Coalgebra.comul (R := R) a) := by simp [← single_eq_C_mul_T] theorem comul_C_mul_T_self (a : R) (n : ℤ) : Coalgebra.comul (C a * T n) = T n ⊗ₜ[R] (C a * T n) := by simp @[simp] theorem counit_C (a : A) : Coalgebra.counit (R := R) (C a) = Coalgebra.counit (R := R) a := counit_single _ _ @[simp] theorem counit_C_mul_T (a : A) (n : ℤ) : Coalgebra.counit (R := R) (C a * T n) = Coalgebra.counit (R := R) a := by simp [← single_eq_C_mul_T] end LaurentPolynomial
.lake/packages/mathlib/Mathlib/RingTheory/Coalgebra/Equiv.lean
import Mathlib.RingTheory.Coalgebra.Hom /-! # Isomorphisms of `R`-coalgebras This file defines bundled isomorphisms of `R`-coalgebras. We simply mimic the early parts of `Mathlib/Algebra/Module/Equiv.lean`. ## Main definitions * `CoalgEquiv R A B`: the type of `R`-coalgebra isomorphisms between `A` and `B`. ## Notation * `A ≃ₗc[R] B` : `R`-coalgebra equivalence from `A` to `B`. -/ universe u v w variable {R A B C : Type*} open Coalgebra /-- An equivalence of coalgebras is an invertible coalgebra homomorphism. -/ structure CoalgEquiv (R : Type*) [CommSemiring R] (A B : Type*) [AddCommMonoid A] [AddCommMonoid B] [Module R A] [Module R B] [CoalgebraStruct R A] [CoalgebraStruct R B] extends A →ₗc[R] B, A ≃ₗ[R] B where attribute [nolint docBlame] CoalgEquiv.toCoalgHom attribute [nolint docBlame] CoalgEquiv.toLinearEquiv @[inherit_doc CoalgEquiv] notation:50 A " ≃ₗc[" R "] " B => CoalgEquiv R A B /-- `CoalgEquivClass F R A B` asserts `F` is a type of bundled coalgebra equivalences from `A` to `B`. -/ class CoalgEquivClass (F : Type*) (R A B : outParam Type*) [CommSemiring R] [AddCommMonoid A] [AddCommMonoid B] [Module R A] [Module R B] [CoalgebraStruct R A] [CoalgebraStruct R B] [EquivLike F A B] : Prop extends CoalgHomClass F R A B, SemilinearEquivClass F (RingHom.id R) A B namespace CoalgEquivClass variable {F R A B : Type*} [CommSemiring R] [AddCommMonoid A] [AddCommMonoid B] [Module R A] [Module R B] [CoalgebraStruct R A] [CoalgebraStruct R B] /-- Reinterpret an element of a type of coalgebra equivalences as a coalgebra equivalence. -/ @[coe] def toCoalgEquiv [EquivLike F A B] [CoalgEquivClass F R A B] (f : F) : A ≃ₗc[R] B := { (f : A →ₗc[R] B), (f : A ≃ₗ[R] B) with } /-- Reinterpret an element of a type of coalgebra equivalences as a coalgebra equivalence. -/ instance instCoeToCoalgEquiv [EquivLike F A B] [CoalgEquivClass F R A B] : CoeHead F (A ≃ₗc[R] B) where coe f := toCoalgEquiv f end CoalgEquivClass namespace CoalgEquiv variable [CommSemiring R] section variable [AddCommMonoid A] [AddCommMonoid B] [Module R A] [Module R B] [CoalgebraStruct R A] [CoalgebraStruct R B] /-- The equivalence of types underlying a coalgebra equivalence. -/ def toEquiv : (A ≃ₗc[R] B) → A ≃ B := fun f => f.toLinearEquiv.toEquiv theorem toEquiv_injective : Function.Injective (toEquiv : (A ≃ₗc[R] B) → A ≃ B) := fun ⟨_, _, _, _⟩ ⟨_, _, _, _⟩ h => (CoalgEquiv.mk.injEq _ _ _ _ _ _ _ _).mpr ⟨CoalgHom.ext (congr_fun (Equiv.mk.inj h).1), (Equiv.mk.inj h).2⟩ @[simp] theorem toEquiv_inj {e₁ e₂ : A ≃ₗc[R] B} : e₁.toEquiv = e₂.toEquiv ↔ e₁ = e₂ := toEquiv_injective.eq_iff theorem toCoalgHom_injective : Function.Injective (toCoalgHom : (A ≃ₗc[R] B) → A →ₗc[R] B) := fun _ _ H => toEquiv_injective <| Equiv.ext <| CoalgHom.congr_fun H instance : EquivLike (A ≃ₗc[R] B) A B where coe e := e.toFun inv := CoalgEquiv.invFun coe_injective' _ _ h _ := toCoalgHom_injective (DFunLike.coe_injective h) left_inv := CoalgEquiv.left_inv right_inv := CoalgEquiv.right_inv instance : FunLike (A ≃ₗc[R] B) A B where coe := DFunLike.coe coe_injective' := DFunLike.coe_injective instance : CoalgEquivClass (A ≃ₗc[R] B) R A B where map_add := (·.map_add') map_smulₛₗ := (·.map_smul') counit_comp := (·.counit_comp) map_comp_comul := (·.map_comp_comul) @[simp, norm_cast] theorem toCoalgHom_inj {e₁ e₂ : A ≃ₗc[R] B} : (↑e₁ : A →ₗc[R] B) = e₂ ↔ e₁ = e₂ := toCoalgHom_injective.eq_iff @[simp] theorem coe_mk {f h h₀ h₁ h₂ h₃ h₄ h₅} : (⟨⟨⟨⟨f, h⟩, h₀⟩, h₁, h₂⟩, h₃, h₄, h₅⟩ : A ≃ₗc[R] B) = f := rfl end section variable [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C] [Module R A] [Module R B] [Module R C] [CoalgebraStruct R A] [CoalgebraStruct R B] [CoalgebraStruct R C] variable (e e' : A ≃ₗc[R] B) @[simp, norm_cast] theorem coe_coe : ⇑(e : A →ₗc[R] B) = e := rfl @[simp] theorem toLinearEquiv_eq_coe (f : A ≃ₗc[R] B) : f.toLinearEquiv = f := rfl @[simp] theorem toCoalgHom_eq_coe (f : A ≃ₗc[R] B) : f.toCoalgHom = f := rfl @[simp] theorem coe_toLinearEquiv : ⇑(e : A ≃ₗ[R] B) = e := rfl @[simp] theorem coe_toCoalgHom : ⇑(e : A →ₗc[R] B) = e := rfl theorem toLinearEquiv_toLinearMap : ((e : A ≃ₗ[R] B) : A →ₗ[R] B) = (e : A →ₗc[R] B) := rfl section variable {e e'} @[ext] theorem ext (h : ∀ x, e x = e' x) : e = e' := DFunLike.ext _ _ h protected theorem congr_arg {x x'} : x = x' → e x = e x' := DFunLike.congr_arg e protected theorem congr_fun (h : e = e') (x : A) : e x = e' x := DFunLike.congr_fun h x end /-- Coalgebra equivalences are symmetric. -/ @[symm] def symm (e : A ≃ₗc[R] B) : B ≃ₗc[R] A := { (e : A ≃ₗ[R] B).symm with counit_comp := (LinearEquiv.comp_toLinearMap_symm_eq _ _).2 e.counit_comp.symm map_comp_comul := by change (TensorProduct.congr (e : A ≃ₗ[R] B) (e : A ≃ₗ[R] B)).symm.toLinearMap ∘ₗ comul = comul ∘ₗ (e : A ≃ₗ[R] B).symm rw [LinearEquiv.toLinearMap_symm_comp_eq] simp only [TensorProduct.congr, toLinearEquiv_toLinearMap, LinearEquiv.ofLinear_toLinearMap, ← LinearMap.comp_assoc, CoalgHomClass.map_comp_comul, LinearEquiv.eq_comp_toLinearMap_symm] } /-- See Note [custom simps projection] -/ def Simps.apply {R : Type*} [CommSemiring R] {α β : Type*} [AddCommMonoid α] [AddCommMonoid β] [Module R α] [Module R β] [CoalgebraStruct R α] [CoalgebraStruct R β] (f : α ≃ₗc[R] β) : α → β := f /-- See Note [custom simps projection] -/ def Simps.symm_apply {R : Type*} [CommSemiring R] {A : Type*} {B : Type*} [AddCommMonoid A] [AddCommMonoid B] [Module R A] [Module R B] [CoalgebraStruct R A] [CoalgebraStruct R B] (e : A ≃ₗc[R] B) : B → A := e.symm initialize_simps_projections CoalgEquiv (toFun → apply, invFun → symm_apply) variable (A R) in /-- The identity map is a coalgebra equivalence. -/ @[refl, simps!] def refl : A ≃ₗc[R] A := { CoalgHom.id R A, LinearEquiv.refl R A with } @[simp] theorem refl_toLinearEquiv : refl R A = LinearEquiv.refl R A := rfl @[simp] theorem refl_toCoalgHom : refl R A = CoalgHom.id R A := rfl @[simp] theorem symm_toLinearEquiv (e : A ≃ₗc[R] B) : e.symm = (e : A ≃ₗ[R] B).symm := rfl theorem coe_symm_toLinearEquiv (e : A ≃ₗc[R] B) : ⇑(e : A ≃ₗ[R] B).symm = e.symm := rfl @[simp] theorem symm_toCoalgHom (e : A ≃ₗc[R] B) : ((e.symm : B →ₗc[R] A) : B →ₗ[R] A) = (e : A ≃ₗ[R] B).symm := rfl @[simp] theorem symm_apply_apply (e : A ≃ₗc[R] B) (x) : e.symm (e x) = x := LinearEquiv.symm_apply_apply (e : A ≃ₗ[R] B) x @[simp] theorem apply_symm_apply (e : A ≃ₗc[R] B) (x) : e (e.symm x) = x := LinearEquiv.apply_symm_apply (e : A ≃ₗ[R] B) x @[simp] theorem invFun_eq_symm : e.invFun = e.symm := rfl theorem coe_toEquiv_symm : e.toEquiv.symm = e.symm := rfl @[simp] theorem toEquiv_symm : e.symm.toEquiv = e.toEquiv.symm := rfl @[simp] theorem coe_toEquiv : ⇑e.toEquiv = e := rfl @[simp] theorem coe_symm_toEquiv : ⇑e.toEquiv.symm = e.symm := rfl variable {e₁₂ : A ≃ₗc[R] B} {e₂₃ : B ≃ₗc[R] C} /-- Coalgebra equivalences are transitive. -/ @[trans, simps!] def trans (e₁₂ : A ≃ₗc[R] B) (e₂₃ : B ≃ₗc[R] C) : A ≃ₗc[R] C := { (e₂₃ : B →ₗc[R] C).comp (e₁₂ : A →ₗc[R] B), e₁₂.toLinearEquiv ≪≫ₗ e₂₃.toLinearEquiv with } theorem trans_toLinearEquiv : (e₁₂.trans e₂₃ : A ≃ₗ[R] C) = (e₁₂ : A ≃ₗ[R] B) ≪≫ₗ e₂₃ := rfl @[simp] theorem trans_toCoalgHom : (e₁₂.trans e₂₃ : A →ₗc[R] C) = e₂₃.comp e₁₂ := rfl @[simp] theorem coe_toEquiv_trans : (e₁₂ : A ≃ B).trans e₂₃ = (e₁₂.trans e₂₃ : A ≃ C) := rfl /-- If an coalgebra morphism has an inverse, it is an coalgebra isomorphism. -/ def ofCoalgHom (f : A →ₗc[R] B) (g : B →ₗc[R] A) (h₁ : f.comp g = CoalgHom.id R B) (h₂ : g.comp f = CoalgHom.id R A) : A ≃ₗc[R] B where __ := f toFun := f invFun := g left_inv := CoalgHom.ext_iff.1 h₂ right_inv := CoalgHom.ext_iff.1 h₁ @[simp] theorem coe_ofCoalgHom (f : A →ₗc[R] B) (g : B →ₗc[R] A) (h₁ h₂) : ofCoalgHom f g h₁ h₂ = f := rfl theorem ofCoalgHom_symm (f : A →ₗc[R] B) (g : B →ₗc[R] A) (h₁ h₂) : (ofCoalgHom f g h₁ h₂).symm = ofCoalgHom g f h₂ h₁ := rfl variable {f : A →ₗc[R] B} (hf : Function.Bijective f) /-- Promotes a bijective coalgebra homomorphism to a coalgebra equivalence. -/ @[simps apply] noncomputable def ofBijective : A ≃ₗc[R] B where toFun := f __ := f __ := LinearEquiv.ofBijective (f : A →ₗ[R] B) hf @[simp] theorem coe_ofBijective : (CoalgEquiv.ofBijective hf : A → B) = f := rfl end variable [CommSemiring R] [AddCommMonoid A] [Module R A] [Coalgebra R A] [AddCommMonoid B] [Module R B] [CoalgebraStruct R B] /-- Let `A` be an `R`-coalgebra and let `B` be an `R`-module with a `CoalgebraStruct`. A linear equivalence `A ≃ₗ[R] B` that respects the `CoalgebraStruct`s defines an `R`-coalgebra structure on `B`. -/ @[reducible] def toCoalgebra (f : A ≃ₗc[R] B) : Coalgebra R B where coassoc := by simp only [← ((f : A ≃ₗ[R] B).comp_toLinearMap_symm_eq _ _).2 f.map_comp_comul, ← LinearMap.comp_assoc] congr 1 ext x simpa only [toCoalgHom_eq_coe, CoalgHom.toLinearMap_eq_coe, LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, ← (ℛ R _).eq, map_sum, TensorProduct.map_tmul, LinearMap.coe_coe, CoalgHom.coe_coe, LinearMap.rTensor_tmul, coe_symm_toLinearEquiv, symm_apply_apply, LinearMap.lTensor_comp_map, TensorProduct.sum_tmul, TensorProduct.assoc_tmul, TensorProduct.tmul_sum] using (sum_map_tmul_tmul_eq f f f x).symm rTensor_counit_comp_comul := by simp_rw [(f.toLinearEquiv.eq_comp_toLinearMap_symm _ _).2 f.counit_comp, ← (f.toLinearEquiv.comp_toLinearMap_symm_eq _ _).2 f.map_comp_comul, ← LinearMap.comp_assoc, f.toLinearEquiv.comp_toLinearMap_symm_eq] ext x simp [← (ℛ R _).eq, coe_symm_toLinearEquiv] lTensor_counit_comp_comul := by simp_rw [(f.toLinearEquiv.eq_comp_toLinearMap_symm _ _).2 f.counit_comp, ← (f.toLinearEquiv.comp_toLinearMap_symm_eq _ _).2 f.map_comp_comul, ← LinearMap.comp_assoc, f.toLinearEquiv.comp_toLinearMap_symm_eq] ext x simp [← (ℛ R _).eq, coe_symm_toLinearEquiv] end CoalgEquiv
.lake/packages/mathlib/Mathlib/RingTheory/Coalgebra/Hom.lean
import Mathlib.RingTheory.Coalgebra.Basic /-! # Homomorphisms of `R`-coalgebras This file defines bundled homomorphisms of `R`-coalgebras. We largely mimic `Mathlib/Algebra/Algebra/Hom.lean`. ## Main definitions * `CoalgHom R A B`: the type of `R`-coalgebra morphisms from `A` to `B`. * `Coalgebra.counitCoalgHom R A : A →ₗc[R] R`: the counit of a coalgebra as a coalgebra homomorphism. ## Notation * `A →ₗc[R] B` : `R`-coalgebra homomorphism from `A` to `B`. -/ open TensorProduct Coalgebra universe u v w /-- Given `R`-modules `A, B` with comultiplication maps `Δ_A, Δ_B` and counit maps `ε_A, ε_B`, an `R`-coalgebra homomorphism `A →ₗc[R] B` is an `R`-linear map `f` such that `ε_B ∘ f = ε_A` and `(f ⊗ f) ∘ Δ_A = Δ_B ∘ f`. -/ structure CoalgHom (R A B : Type*) [CommSemiring R] [AddCommMonoid A] [Module R A] [AddCommMonoid B] [Module R B] [CoalgebraStruct R A] [CoalgebraStruct R B] extends A →ₗ[R] B where counit_comp : counit ∘ₗ toLinearMap = counit map_comp_comul : TensorProduct.map toLinearMap toLinearMap ∘ₗ comul = comul ∘ₗ toLinearMap @[inherit_doc CoalgHom] infixr:25 " →ₗc " => CoalgHom _ @[inherit_doc] notation:25 A " →ₗc[" R "] " B => CoalgHom R A B /-- `CoalgHomClass F R A B` asserts `F` is a type of bundled coalgebra homomorphisms from `A` to `B`. -/ class CoalgHomClass (F : Type*) (R A B : outParam Type*) [CommSemiring R] [AddCommMonoid A] [Module R A] [AddCommMonoid B] [Module R B] [CoalgebraStruct R A] [CoalgebraStruct R B] [FunLike F A B] : Prop extends SemilinearMapClass F (RingHom.id R) A B where counit_comp : ∀ f : F, counit ∘ₗ (f : A →ₗ[R] B) = counit map_comp_comul : ∀ f : F, TensorProduct.map (f : A →ₗ[R] B) (f : A →ₗ[R] B) ∘ₗ comul = comul ∘ₗ (f : A →ₗ[R] B) attribute [simp] CoalgHomClass.counit_comp CoalgHomClass.map_comp_comul namespace CoalgHomClass variable {R A B F : Type*} [CommSemiring R] [AddCommMonoid A] [Module R A] [AddCommMonoid B] [Module R B] [CoalgebraStruct R A] [CoalgebraStruct R B] [FunLike F A B] [CoalgHomClass F R A B] /-- Turn an element of a type `F` satisfying `CoalgHomClass F R A B` into an actual `CoalgHom`. This is declared as the default coercion from `F` to `A →ₗc[R] B`. -/ @[coe] def toCoalgHom (f : F) : A →ₗc[R] B := { (f : A →ₗ[R] B) with toFun := f counit_comp := CoalgHomClass.counit_comp f map_comp_comul := CoalgHomClass.map_comp_comul f } instance instCoeToCoalgHom : CoeHead F (A →ₗc[R] B) := ⟨CoalgHomClass.toCoalgHom⟩ @[simp] theorem counit_comp_apply (f : F) (x : A) : counit (f x) = counit (R := R) x := LinearMap.congr_fun (counit_comp f) _ @[simp] theorem map_comp_comul_apply (f : F) (x : A) : TensorProduct.map f f (σ₁₂ := .id _) (comul x) = comul (R := R) (f x) := LinearMap.congr_fun (map_comp_comul f) _ end CoalgHomClass namespace CoalgHom variable {R A B C D : Type*} section variable [CommSemiring R] [AddCommMonoid A] [Module R A] [AddCommMonoid B] [Module R B] [AddCommMonoid C] [Module R C] [AddCommMonoid D] [Module R D] [CoalgebraStruct R A] [CoalgebraStruct R B] [CoalgebraStruct R C] [CoalgebraStruct R D] instance funLike : FunLike (A →ₗc[R] B) A B where coe f := f.toFun coe_injective' f g h := by rcases f with ⟨⟨⟨_, _⟩, _⟩, _, _⟩ rcases g with ⟨⟨⟨_, _⟩, _⟩, _, _⟩ congr instance coalgHomClass : CoalgHomClass (A →ₗc[R] B) R A B where map_add := fun f => f.map_add' map_smulₛₗ := fun f => f.map_smul' counit_comp := fun f => f.counit_comp map_comp_comul := fun f => f.map_comp_comul /-- See Note [custom simps projection] -/ def Simps.apply {R α β : Type*} [CommSemiring R] [AddCommMonoid α] [Module R α] [AddCommMonoid β] [Module R β] [CoalgebraStruct R α] [CoalgebraStruct R β] (f : α →ₗc[R] β) : α → β := f initialize_simps_projections CoalgHom (toFun → apply) @[simp] protected theorem coe_coe {F : Type*} [FunLike F A B] [CoalgHomClass F R A B] (f : F) : ⇑(f : A →ₗc[R] B) = f := rfl @[simp] theorem coe_mk {f : A →ₗ[R] B} (h h₁) : ((⟨f, h, h₁⟩ : A →ₗc[R] B) : A → B) = f := rfl @[norm_cast] theorem coe_mks {f : A → B} (h₁ h₂ h₃ h₄) : ⇑(⟨⟨⟨f, h₁⟩, h₂⟩, h₃, h₄⟩ : A →ₗc[R] B) = f := rfl @[simp, norm_cast] theorem coe_linearMap_mk {f : A →ₗ[R] B} (h h₁) : ((⟨f, h, h₁⟩ : A →ₗc[R] B) : A →ₗ[R] B) = f := rfl @[simp] theorem toLinearMap_eq_coe (f : A →ₗc[R] B) : f.toLinearMap = f := rfl @[simp, norm_cast] theorem coe_toLinearMap (f : A →ₗc[R] B) : ⇑(f : A →ₗ[R] B) = f := rfl @[norm_cast] theorem coe_toAddMonoidHom (f : A →ₗc[R] B) : ⇑(f : A →+ B) = f := rfl theorem coe_fn_injective : @Function.Injective (A →ₗc[R] B) (A → B) (↑) := DFunLike.coe_injective theorem coe_fn_inj {φ₁ φ₂ : A →ₗc[R] B} : (φ₁ : A → B) = φ₂ ↔ φ₁ = φ₂ := DFunLike.coe_fn_eq theorem coe_linearMap_injective : Function.Injective ((↑) : (A →ₗc[R] B) → A →ₗ[R] B) := fun φ₁ φ₂ H => coe_fn_injective <| show ((φ₁ : A →ₗ[R] B) : A → B) = ((φ₂ : A →ₗ[R] B) : A → B) from congr_arg _ H theorem coe_addMonoidHom_injective : Function.Injective ((↑) : (A →ₗc[R] B) → A →+ B) := LinearMap.toAddMonoidHom_injective.comp coe_linearMap_injective protected theorem congr_fun {φ₁ φ₂ : A →ₗc[R] B} (H : φ₁ = φ₂) (x : A) : φ₁ x = φ₂ x := DFunLike.congr_fun H x protected theorem congr_arg (φ : A →ₗc[R] B) {x y : A} (h : x = y) : φ x = φ y := DFunLike.congr_arg φ h @[ext] theorem ext {φ₁ φ₂ : A →ₗc[R] B} (H : ∀ x, φ₁ x = φ₂ x) : φ₁ = φ₂ := DFunLike.ext _ _ H @[ext high] theorem ext_of_ring {f g : R →ₗc[R] A} (h : f 1 = g 1) : f = g := coe_linearMap_injective (by ext; assumption) @[simp] theorem mk_coe {f : A →ₗc[R] B} (h₁ h₂ h₃ h₄) : (⟨⟨⟨f, h₁⟩, h₂⟩, h₃, h₄⟩ : A →ₗc[R] B) = f := ext fun _ => rfl /-- Copy of a `CoalgHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : A →ₗc[R] B) (f' : A → B) (h : f' = ⇑f) : A →ₗc[R] B := { toLinearMap := (f : A →ₗ[R] B).copy f' h counit_comp := by ext; simp_all map_comp_comul := by simp only [(f : A →ₗ[R] B).copy_eq f' h, CoalgHomClass.map_comp_comul] } @[simp] theorem coe_copy (f : A →ₗc[R] B) (f' : A → B) (h : f' = ⇑f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : A →ₗc[R] B) (f' : A → B) (h : f' = ⇑f) : f.copy f' h = f := DFunLike.ext' h variable (R A) /-- Identity map as a `CoalgHom`. -/ @[simps!] protected def id : A →ₗc[R] A := { LinearMap.id with counit_comp := by ext; rfl map_comp_comul := by simp only [map_id, LinearMap.id_comp, LinearMap.comp_id] } variable {R A} @[simp, norm_cast] theorem coe_id : ⇑(CoalgHom.id R A) = id := rfl @[simp] theorem id_toLinearMap : (CoalgHom.id R A : A →ₗ[R] A) = LinearMap.id := rfl /-- Composition of coalgebra homomorphisms. -/ @[simps!] def comp (φ₁ : B →ₗc[R] C) (φ₂ : A →ₗc[R] B) : A →ₗc[R] C := { (φ₁ : B →ₗ[R] C) ∘ₗ (φ₂ : A →ₗ[R] B) with counit_comp := by ext; simp map_comp_comul := by ext; simp [map_comp] } @[simp] theorem coe_comp (φ₁ : B →ₗc[R] C) (φ₂ : A →ₗc[R] B) : ⇑(φ₁.comp φ₂) = φ₁ ∘ φ₂ := rfl @[simp] theorem comp_toLinearMap (φ₁ : B →ₗc[R] C) (φ₂ : A →ₗc[R] B) : φ₁.comp φ₂ = (φ₁ : B →ₗ[R] C) ∘ₗ (φ₂ : A →ₗ[R] B) := rfl variable (φ : A →ₗc[R] B) @[simp] theorem comp_id : φ.comp (CoalgHom.id R A) = φ := ext fun _x => rfl @[simp] theorem id_comp : (CoalgHom.id R B).comp φ = φ := ext fun _x => rfl theorem comp_assoc (φ₁ : C →ₗc[R] D) (φ₂ : B →ₗc[R] C) (φ₃ : A →ₗc[R] B) : (φ₁.comp φ₂).comp φ₃ = φ₁.comp (φ₂.comp φ₃) := ext fun _x => rfl theorem map_smul_of_tower {R'} [SMul R' A] [SMul R' B] [LinearMap.CompatibleSMul A B R' R] (r : R') (x : A) : φ (r • x) = r • φ x := φ.toLinearMap.map_smul_of_tower r x @[simps -isSimp toSemigroup_toMul_mul toOne_one] instance End : Monoid (A →ₗc[R] A) where mul := comp mul_assoc _ _ _ := rfl one := CoalgHom.id R A one_mul _ := ext fun _ => rfl mul_one _ := ext fun _ => rfl @[simp] theorem one_apply (x : A) : (1 : A →ₗc[R] A) x = x := rfl @[simp] theorem mul_apply (φ ψ : A →ₗc[R] A) (x : A) : (φ * ψ) x = φ (ψ x) := rfl end end CoalgHom namespace Coalgebra variable (R : Type u) (A : Type v) (B : Type w) variable [CommSemiring R] [AddCommMonoid A] [AddCommMonoid B] [Module R A] [Module R B] variable [Coalgebra R A] [Coalgebra R B] /-- The counit of a coalgebra as a `CoalgHom`. -/ noncomputable def counitCoalgHom : A →ₗc[R] R := { counit with counit_comp := by ext; simp map_comp_comul := by ext simp only [LinearMap.coe_comp, Function.comp_apply, CommSemiring.comul_apply, ← LinearMap.lTensor_comp_rTensor, rTensor_counit_comul, LinearMap.lTensor_tmul] } @[simp] theorem counitCoalgHom_apply (x : A) : counitCoalgHom R A x = counit x := rfl @[simp] theorem counitCoalgHom_toLinearMap : counitCoalgHom R A = counit (R := R) (A := A) := rfl variable {R} instance subsingleton_to_ring : Subsingleton (A →ₗc[R] R) := ⟨fun f g => CoalgHom.ext fun x => by have hf := CoalgHomClass.counit_comp_apply f x have hg := CoalgHomClass.counit_comp_apply g x simp_all only [CommSemiring.counit_apply]⟩ @[ext high] theorem ext_to_ring (f g : A →ₗc[R] R) : f = g := Subsingleton.elim _ _ variable {A B} /-- If `φ : A → B` is a coalgebra map and `a = ∑ xᵢ ⊗ yᵢ`, then `φ a = ∑ φ xᵢ ⊗ φ yᵢ` -/ @[simps] def Repr.induced {a : A} (repr : Repr R a) {F : Type*} [FunLike F A B] [CoalgHomClass F R A B] (φ : F) : Repr R (φ a) where index := repr.index left := φ ∘ repr.left right := φ ∘ repr.right eq := (congr($((CoalgHomClass.map_comp_comul φ).symm) a).trans <| by rw [LinearMap.comp_apply, ← repr.eq, map_sum]; rfl).symm end Coalgebra
.lake/packages/mathlib/Mathlib/RingTheory/SimpleModule/Rank.lean
import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas import Mathlib.RingTheory.SimpleModule.Basic /-! # A module over a division ring is simple iff it has rank one -/ theorem isSimpleModule_iff_finrank_eq_one {R M} [DivisionRing R] [AddCommGroup M] [Module R M] : IsSimpleModule R M ↔ Module.finrank R M = 1 := ⟨fun h ↦ have := h.nontrivial; have ⟨v, hv⟩ := exists_ne (0 : M) (finrank_eq_one_iff_of_nonzero' v hv).mpr (IsSimpleModule.toSpanSingleton_surjective R hv), (isSimpleModule_iff ..).mpr ∘ is_simple_module_of_finrank_eq_one⟩
.lake/packages/mathlib/Mathlib/RingTheory/SimpleModule/IsAlgClosed.lean
import Mathlib.FieldTheory.IsAlgClosed.Basic import Mathlib.RingTheory.SimpleModule.WedderburnArtin /-! # Wedderburn–Artin Theorem over an algebraically closed field -/ variable (F R : Type*) [Field F] [IsAlgClosed F] [Ring R] [Algebra F R] /-- The **Wedderburn–Artin Theorem** over algebraically closed fields: a finite-dimensional simple algebra over an algebraically closed field is isomorphic to a matrix algebra over the field. -/ theorem IsSimpleRing.exists_algEquiv_matrix_of_isAlgClosed [IsSimpleRing R] [FiniteDimensional F R] : ∃ (n : ℕ) (_ : NeZero n), Nonempty (R ≃ₐ[F] Matrix (Fin n) (Fin n) F) := have := IsArtinianRing.of_finite F R have ⟨n, hn, D, _, _, _, ⟨e⟩⟩ := exists_algEquiv_matrix_divisionRing_finite F R ⟨n, hn, ⟨e.trans <| .mapMatrix <| .symm <| .ofBijective (Algebra.ofId F D) IsAlgClosed.algebraMap_bijective_of_isIntegral⟩⟩ /-- The **Wedderburn–Artin Theorem** over algebraically closed fields: a finite-dimensional semisimple algebra over an algebraically closed field is isomorphic to a product of matrix algebras over the field. -/ theorem IsSemisimpleRing.exists_algEquiv_pi_matrix_of_isAlgClosed [IsSemisimpleRing R] [FiniteDimensional F R] : ∃ (n : ℕ) (d : Fin n → ℕ), (∀ i, NeZero (d i)) ∧ Nonempty (R ≃ₐ[F] Π i, Matrix (Fin (d i)) (Fin (d i)) F) := have ⟨n, D, d, _, _, _, hd, ⟨e⟩⟩ := exists_algEquiv_pi_matrix_divisionRing_finite F R ⟨n, d, hd, ⟨e.trans <| .piCongrRight fun i ↦ .mapMatrix <| .symm <| .ofBijective (Algebra.ofId F (D i)) IsAlgClosed.algebraMap_bijective_of_isIntegral⟩⟩
.lake/packages/mathlib/Mathlib/RingTheory/SimpleModule/Basic.lean
import Mathlib.Algebra.DirectSum.Module import Mathlib.Data.Finite.Card import Mathlib.Data.Matrix.Mul import Mathlib.LinearAlgebra.DFinsupp import Mathlib.LinearAlgebra.Finsupp.Span import Mathlib.LinearAlgebra.Isomorphisms import Mathlib.LinearAlgebra.Projection import Mathlib.Order.Atoms.Finite import Mathlib.Order.CompactlyGenerated.Intervals import Mathlib.Order.JordanHolder import Mathlib.RingTheory.Ideal.Colon import Mathlib.RingTheory.Noetherian.Defs /-! # Simple Modules ## Main Definitions * `IsSimpleModule` indicates that a module has no proper submodules (the only submodules are `⊥` and `⊤`). * `IsSemisimpleModule` indicates that every submodule has a complement, or equivalently, the module is a direct sum of simple modules. * A `DivisionRing` structure on the endomorphism ring of a simple module. ## Main Results * Schur's Lemma: `bijective_or_eq_zero` shows that a linear map between simple modules is either bijective or 0, leading to a `DivisionRing` structure on the endomorphism ring. * `isSimpleModule_iff_quot_maximal`: a module is simple iff it's isomorphic to the quotient of the ring by a maximal left ideal. * `sSup_simples_eq_top_iff_isSemisimpleModule`: a module is semisimple iff it is generated by its simple submodules. * `IsSemisimpleModule.annihilator_isRadical`: the annihilator of a semisimple module over a commutative ring is a radical ideal. * `IsSemisimpleModule.submodule`, `IsSemisimpleModule.quotient`: any submodule or quotient module of a semisimple module is semisimple. * `isSemisimpleModule_of_isSemisimpleModule_submodule`: a module generated by semisimple submodules is itself semisimple. * `IsSemisimpleRing.isSemisimpleModule`: every module over a semisimple ring is semisimple. * `instIsSemisimpleRingForAllRing`: a finite product of semisimple rings is semisimple. * `RingHom.isSemisimpleRing_of_surjective`: any quotient of a semisimple ring is semisimple. ## TODO * Artin-Wedderburn Theory (uniqueness) * Unify with the work on Schur's Lemma in a category theory context -/ variable {ι : Type*} (R S : Type*) [Ring R] [Ring S] (M : Type*) [AddCommGroup M] [Module R M] /-- A module is simple when it has only two submodules, `⊥` and `⊤`. -/ @[mk_iff] class IsSimpleModule extends IsSimpleOrder (Submodule R M) /-- A module is semisimple when every submodule has a complement, or equivalently, the module is a direct sum of simple modules. -/ @[mk_iff] class IsSemisimpleModule extends ComplementedLattice (Submodule R M) instance [IsSimpleModule R M] : IsSemisimpleModule R M where instance (R) [DivisionRing R] : IsSimpleModule R R where /-- A ring is semisimple if it is semisimple as a module over itself. -/ abbrev IsSemisimpleRing := IsSemisimpleModule R R instance (priority := low) [Subsingleton R] : IsSemisimpleRing R := (isSemisimpleModule_iff R R).mpr Subsingleton.instComplementedLattice variable {R S} in theorem RingEquiv.isSemisimpleRing (e : R ≃+* S) [IsSemisimpleRing R] : IsSemisimpleRing S where __ := (Submodule.orderIsoMapComap e.toSemilinearEquiv).complementedLattice variable {R S} in theorem RingEquiv.isSemisimpleRing_iff (e : R ≃+* S) : IsSemisimpleRing R ↔ IsSemisimpleRing S := ⟨fun _ ↦ e.isSemisimpleRing, fun _ ↦ e.symm.isSemisimpleRing⟩ theorem IsSimpleModule.nontrivial [IsSimpleModule R M] : Nontrivial M := ⟨⟨0, by have h : (⊥ : Submodule R M) ≠ ⊤ := bot_ne_top contrapose! h ext x simp [Submodule.mem_bot, Submodule.mem_top, h x]⟩⟩ variable {m : Submodule R M} {N : Type*} [AddCommGroup N] {R S M} theorem LinearMap.isSimpleModule_iff_of_bijective [Module S N] {σ : R →+* S} [RingHomSurjective σ] (l : M →ₛₗ[σ] N) (hl : Function.Bijective l) : IsSimpleModule R M ↔ IsSimpleModule S N := by simp_rw [isSimpleModule_iff, (Submodule.orderIsoMapComapOfBijective l hl).isSimpleOrder_iff] variable [Module R N] theorem IsSimpleModule.congr (e : M ≃ₗ[R] N) [IsSimpleModule R N] : IsSimpleModule R M where __ := (Submodule.orderIsoMapComap e).isSimpleOrder theorem LinearEquiv.isSimpleModule_iff (e : M ≃ₗ[R] N) : IsSimpleModule R M ↔ IsSimpleModule R N := ⟨(·.congr e.symm), (·.congr e)⟩ theorem isSimpleModule_iff_isAtom : IsSimpleModule R m ↔ IsAtom m := by rw [← Set.isSimpleOrder_Iic_iff_isAtom, isSimpleModule_iff] exact m.mapIic.isSimpleOrder_iff theorem isSimpleModule_iff_isCoatom : IsSimpleModule R (M ⧸ m) ↔ IsCoatom m := by rw [← Set.isSimpleOrder_Ici_iff_isCoatom, isSimpleModule_iff] exact (Submodule.comapMkQRelIso m).isSimpleOrder_iff theorem covBy_iff_quot_is_simple {A B : Submodule R M} (hAB : A ≤ B) : A ⋖ B ↔ IsSimpleModule R (B ⧸ Submodule.comap B.subtype A) := by set f : Submodule R B ≃o Set.Iic B := B.mapIic with hf rw [covBy_iff_coatom_Iic hAB, isSimpleModule_iff_isCoatom, ← OrderIso.isCoatom_iff f, hf] simp [-OrderIso.isCoatom_iff, Submodule.map_comap_subtype, inf_eq_right.2 hAB] namespace IsSimpleModule @[simp] theorem isAtom [IsSimpleModule R m] : IsAtom m := isSimpleModule_iff_isAtom.1 ‹_› variable [IsSimpleModule R M] (R) open LinearMap theorem span_singleton_eq_top {m : M} (hm : m ≠ 0) : Submodule.span R {m} = ⊤ := (eq_bot_or_eq_top _).resolve_left fun h ↦ hm (h.le <| Submodule.mem_span_singleton_self m) instance (S : Submodule R M) : S.IsPrincipal where principal := by obtain rfl | rfl := eq_bot_or_eq_top S · exact ⟨0, Submodule.span_zero.symm⟩ have := IsSimpleModule.nontrivial R M have ⟨m, hm⟩ := exists_ne (0 : M) exact ⟨m, (span_singleton_eq_top R hm).symm⟩ theorem toSpanSingleton_surjective {m : M} (hm : m ≠ 0) : Function.Surjective (toSpanSingleton R M m) := by rw [← range_eq_top, ← span_singleton_eq_range, span_singleton_eq_top R hm] theorem ker_toSpanSingleton_isMaximal {m : M} (hm : m ≠ 0) : Ideal.IsMaximal (ker (toSpanSingleton R M m)) := by rw [Ideal.isMaximal_def, ← isSimpleModule_iff_isCoatom] exact congr (quotKerEquivOfSurjective _ <| toSpanSingleton_surjective R hm) open scoped IsSimpleOrder in instance : IsNoetherian R M := isNoetherian_iff'.mpr inferInstance end IsSimpleModule open IsSimpleModule in /-- A module is simple iff it's isomorphic to the quotient of the ring by a maximal left ideal (not necessarily unique if the ring is not commutative). -/ theorem isSimpleModule_iff_quot_maximal : IsSimpleModule R M ↔ ∃ I : Ideal R, I.IsMaximal ∧ Nonempty (M ≃ₗ[R] R ⧸ I) := by refine ⟨fun h ↦ ?_, fun ⟨I, ⟨coatom⟩, ⟨equiv⟩⟩ ↦ ?_⟩ · have := IsSimpleModule.nontrivial R M have ⟨m, hm⟩ := exists_ne (0 : M) exact ⟨_, ker_toSpanSingleton_isMaximal R hm, ⟨(LinearMap.quotKerEquivOfSurjective _ <| toSpanSingleton_surjective R hm).symm⟩⟩ · convert congr equiv; rwa [isSimpleModule_iff_isCoatom] /-- In general, the annihilator of a simple module is called a primitive ideal, and it is always a two-sided prime ideal, but mathlib's `Ideal.IsPrime` is not the correct definition for noncommutative rings. -/ theorem IsSimpleModule.annihilator_isMaximal {R} [CommRing R] [Module R M] [simple : IsSimpleModule R M] : (Module.annihilator R M).IsMaximal := by have ⟨I, max, ⟨e⟩⟩ := isSimpleModule_iff_quot_maximal.mp simple rwa [e.annihilator_eq, I.annihilator_quotient] theorem isSimpleModule_iff_toSpanSingleton_surjective : IsSimpleModule R M ↔ Nontrivial M ∧ ∀ x : M, x ≠ 0 → Function.Surjective (LinearMap.toSpanSingleton R M x) where mp h := ⟨h.nontrivial, fun _ ↦ h.toSpanSingleton_surjective⟩ mpr := fun ⟨_, h⟩ ↦ (isSimpleModule_iff R M).mpr ⟨fun m ↦ or_iff_not_imp_left.mpr fun ne_bot ↦ have ⟨x, hxm, hx0⟩ := m.ne_bot_iff.mp ne_bot top_unique <| fun z _ ↦ by obtain ⟨y, rfl⟩ := h x hx0 z; exact m.smul_mem _ hxm⟩ /-- A ring is a simple module over itself iff it is a division ring. -/ theorem isSimpleModule_self_iff_isUnit : IsSimpleModule R R ↔ Nontrivial R ∧ ∀ x : R, x ≠ 0 → IsUnit x := isSimpleModule_iff_toSpanSingleton_surjective.trans <| and_congr_right fun _ ↦ by refine ⟨fun h x hx ↦ ?_, fun h x hx ↦ (h x hx).unit.mulRight_bijective.surjective⟩ obtain ⟨y, hyx : y * x = 1⟩ := h x hx 1 have hy : y ≠ 0 := left_ne_zero_of_mul (hyx.symm ▸ one_ne_zero) obtain ⟨z, hzy : z * y = 1⟩ := h y hy 1 exact ⟨⟨x, y, left_inv_eq_right_inv hzy hyx ▸ hzy, hyx⟩, rfl⟩ theorem IsSemisimpleModule.of_sSup_simples_eq_top (h : sSup { m : Submodule R M | IsSimpleModule R m } = ⊤) : IsSemisimpleModule R M where __ := complementedLattice_of_sSup_atoms_eq_top (by simp_rw [← h, isSimpleModule_iff_isAtom]) namespace Module.Finite variable (R₀ P : Type*) [Semiring R₀] [AddCommMonoid P] [Module R P] section variable [Module R₀ P] [SMulCommClass R R₀ P] [Module.Finite R₀ (M →ₗ[R] P)] theorem of_isComplemented_domain (h : IsComplemented m) : Module.Finite R₀ (m →ₗ[R] P) := .of_surjective (.lcomp R₀ P ..) (LinearMap.surjective_comp_subtype_of_isComplemented h) instance [IsSemisimpleModule R M] : Module.Finite R₀ (m →ₗ[R] P) := .of_isComplemented_domain _ _ (exists_isCompl m) end section variable [Module R₀ M] [SMulCommClass R R₀ M] [SMul R₀ R] [IsScalarTower R₀ R M] [Module.Finite R₀ (P →ₗ[R] M)] theorem of_isComplemented_codomain (h : IsComplemented m) : Module.Finite R₀ (P →ₗ[R] m) := .of_surjective (.compRight ..) (LinearMap.surjective_comp_linearProjOfIsCompl h.choose_spec) instance [IsSemisimpleModule R M] : Module.Finite R₀ (P →ₗ[R] m) := .of_isComplemented_codomain _ _ (exists_isCompl m) end end Module.Finite namespace IsSemisimpleModule theorem eq_bot_or_exists_simple_le (N : Submodule R M) [IsSemisimpleModule R N] : N = ⊥ ∨ ∃ m ≤ N, IsSimpleModule R m := by rw [← N.subsingleton_iff_eq_bot, ← Submodule.subsingleton_iff R, ← subsingleton_iff_bot_eq_top] refine (eq_bot_or_exists_atom_le _).imp .symm fun ⟨m, h, _⟩ ↦ ⟨_, N.map_subtype_le m, ?_⟩ rw [← isSimpleModule_iff_isAtom] at h exact .congr (m.equivMapOfInjective _ N.subtype_injective).symm variable [IsSemisimpleModule R M] theorem exists_submodule_linearEquiv_quotient (N : Submodule R M) : ∃ (P : Submodule R M), Nonempty (P ≃ₗ[R] M ⧸ N) := have ⟨P, compl⟩ := exists_isCompl N; ⟨P, ⟨(N.quotientEquivOfIsCompl P compl).symm⟩⟩ theorem exists_quotient_linearEquiv_submodule (N : Submodule R M) : ∃ (P : Submodule R M), Nonempty (N ≃ₗ[R] M ⧸ P) := have ⟨P, compl⟩ := exists_isCompl N; ⟨P, ⟨(P.quotientEquivOfIsCompl N compl.symm).symm⟩⟩ theorem extension_property {P} [AddCommGroup P] [Module R P] (f : N →ₗ[R] M) (hf : Function.Injective f) (g : N →ₗ[R] P) : ∃ h : M →ₗ[R] P, h ∘ₗ f = g := have ⟨m, compl⟩ := exists_isCompl (LinearMap.range f) ⟨g ∘ₗ f.linearProjOfIsCompl _ hf compl, by ext; simp⟩ theorem lifting_property {P} [AddCommGroup P] [Module R P] (f : M →ₗ[R] N) (hf : Function.Surjective f) (g : P →ₗ[R] N) : ∃ h : P →ₗ[R] M, f ∘ₗ h = g := by have ⟨m, compl⟩ := exists_isCompl (LinearMap.ker f) let e := (Submodule.quotientEquivOfIsCompl _ m compl).symm ≪≫ₗ f.quotKerEquivOfSurjective hf refine ⟨Submodule.subtype _ ∘ₗ e.symm.toLinearMap ∘ₗ g, LinearMap.ext fun x ↦ ?_⟩ obtain ⟨z, eq⟩ := e.surjective (g x) simp only [LinearMap.comp_apply, ← eq, LinearEquiv.coe_coe, e.symm_apply_apply] simp [e] theorem sSup_simples_le (N : Submodule R M) : sSup { m : Submodule R M | IsSimpleModule R m ∧ m ≤ N } = N := by simpa only [isSimpleModule_iff_isAtom] using sSup_atoms_le_eq _ variable (R M) theorem exists_simple_submodule [Nontrivial M] : ∃ m : Submodule R M, IsSimpleModule R m := by simpa only [isSimpleModule_iff_isAtom] using IsAtomic.exists_atom _ theorem sSup_simples_eq_top : sSup { m : Submodule R M | IsSimpleModule R m } = ⊤ := by simpa only [isSimpleModule_iff_isAtom] using sSup_atoms_eq_top theorem exists_sSupIndep_sSup_simples_eq_top : ∃ s : Set (Submodule R M), sSupIndep s ∧ sSup s = ⊤ ∧ ∀ m ∈ s, IsSimpleModule R m := by have := sSup_simples_eq_top R M simp_rw [isSimpleModule_iff_isAtom] at this ⊢ exact exists_sSupIndep_of_sSup_atoms_eq_top this /-- The annihilator of a semisimple module over a commutative ring is a radical ideal. -/ theorem annihilator_isRadical (R) [CommRing R] [Module R M] [IsSemisimpleModule R M] : (Module.annihilator R M).IsRadical := by rw [← Submodule.annihilator_top, ← sSup_simples_eq_top, sSup_eq_iSup', Submodule.annihilator_iSup] exact Ideal.isRadical_iInf _ fun i ↦ (i.2.annihilator_isMaximal).isPrime.isRadical instance submodule {m : Submodule R M} : IsSemisimpleModule R m where __ := m.mapIic.complementedLattice_iff.2 IsModularLattice.complementedLattice_Iic variable {R M} open LinearMap theorem congr (e : N ≃ₗ[R] M) : IsSemisimpleModule R N where __ := (Submodule.orderIsoMapComap e.symm).complementedLattice theorem of_injective (f : N →ₗ[R] M) (hf : Function.Injective f) : IsSemisimpleModule R N := congr (Submodule.topEquiv.symm.trans <| Submodule.equivMapOfInjective f hf _) instance quotient : IsSemisimpleModule R (M ⧸ m) := have ⟨_, ⟨e⟩⟩ := exists_submodule_linearEquiv_quotient m .congr e.symm instance (priority := low) [Module.Finite R M] : IsNoetherian R M where noetherian m := have ⟨_, ⟨e⟩⟩ := exists_quotient_linearEquiv_submodule m Module.Finite.iff_fg.mp (Module.Finite.equiv e.symm) -- does not work as an instance, not sure why protected theorem range (f : M →ₗ[R] N) : IsSemisimpleModule R (range f) := congr (quotKerEquivRange _).symm theorem of_surjective (f : M →ₗ[R] N) (hf : Function.Surjective f) : IsSemisimpleModule R N := congr (f.quotKerEquivOfSurjective hf).symm section variable {M' : Type*} [AddCommGroup M'] [Module R M'] {N'} [AddCommGroup N'] [Module S N'] {σ : R →+* S} (l : M' →ₛₗ[σ] N') theorem _root_.LinearMap.isSemisimpleModule_iff_of_bijective [RingHomSurjective σ] (hl : Function.Bijective l) : IsSemisimpleModule R M' ↔ IsSemisimpleModule S N' := by simp_rw [isSemisimpleModule_iff, (Submodule.orderIsoMapComapOfBijective l hl).complementedLattice_iff] -- TODO: generalize Submodule.equivMapOfInjective from InvPair to RingHomSurjective proof_wanted _root_.LinearMap.isSemisimpleModule_of_injective (_ : Function.Injective l) [IsSemisimpleModule S N'] : IsSemisimpleModule R M' --TODO: generalize LinearMap.quotKerEquivOfSurjective to SemilinearMaps + RingHomSurjective proof_wanted _root_.LinearMap.isSemisimpleModule_of_surjective (_ : Function.Surjective l) [IsSemisimpleModule R M'] : IsSemisimpleModule S N' end end IsSemisimpleModule theorem LinearEquiv.isSemisimpleModule_iff (e : M ≃ₗ[R] N) : IsSemisimpleModule R M ↔ IsSemisimpleModule R N := ⟨(·.congr e.symm), (·.congr e)⟩ /-- A module is semisimple iff it is generated by its simple submodules. -/ theorem sSup_simples_eq_top_iff_isSemisimpleModule : sSup { m : Submodule R M | IsSimpleModule R m } = ⊤ ↔ IsSemisimpleModule R M := ⟨.of_sSup_simples_eq_top, fun _ ↦ IsSemisimpleModule.sSup_simples_eq_top _ _⟩ /-- A module generated by semisimple submodules is itself semisimple. -/ lemma isSemisimpleModule_of_isSemisimpleModule_submodule {s : Set ι} {p : ι → Submodule R M} (hp : ∀ i ∈ s, IsSemisimpleModule R (p i)) (hp' : ⨆ i ∈ s, p i = ⊤) : IsSemisimpleModule R M := by simp_rw [isSemisimpleModule_iff] at hp ⊢ refine complementedLattice_of_complementedLattice_Iic (fun i hi ↦ ?_) hp' simpa only [← (p i).mapIic.complementedLattice_iff] using hp i hi open Submodule in lemma isSemisimpleModule_biSup_of_isSemisimpleModule_submodule {s : Set ι} {p : ι → Submodule R M} (hp : ∀ i ∈ s, IsSemisimpleModule R (p i)) : IsSemisimpleModule R ↥(⨆ i ∈ s, p i) := by refine isSemisimpleModule_of_isSemisimpleModule_submodule ((comap_equiv_self_of_inj_of_le (injective_subtype _) ?_).isSemisimpleModule_iff.mpr <| hp · ·) (biSup_comap_subtype_eq_top ..) simp_rw [range_subtype, le_biSup p ‹_›] lemma isSemisimpleModule_of_isSemisimpleModule_submodule' {p : ι → Submodule R M} (hp : ∀ i, IsSemisimpleModule R (p i)) (hp' : ⨆ i, p i = ⊤) : IsSemisimpleModule R M := isSemisimpleModule_of_isSemisimpleModule_submodule (s := Set.univ) (fun i _ ↦ hp i) (by simpa) instance {ι} (M : ι → Type*) [∀ i, AddCommGroup (M i)] [∀ i, Module R (M i)] [∀ i, IsSemisimpleModule R (M i)] : IsSemisimpleModule R (Π₀ i, M i) := by classical exact isSemisimpleModule_of_isSemisimpleModule_submodule' (fun _ ↦ .range _) DFinsupp.iSup_range_lsingle variable (R M) in theorem IsSemisimpleModule.exists_linearEquiv_dfinsupp [IsSemisimpleModule R M] : ∃ (s : Set (Submodule R M)) (_ : M ≃ₗ[R] Π₀ m : s, m.1), sSupIndep s ∧ ∀ m : s, IsSimpleModule R m.1 := by have ⟨s, ind, sSup, simple⟩ := IsSemisimpleModule.exists_sSupIndep_sSup_simples_eq_top R M refine ⟨s, ?_, ind, SetCoe.forall.mpr simple⟩ rw [sSupIndep_iff] at ind classical exact .symm <| .trans (.ofInjective _ ind.dfinsupp_lsum_injective) <| .trans (.ofEq _ ⊤ <| by rw [← Submodule.iSup_eq_range_dfinsupp_lsum, ← sSup, sSup_eq_iSup']) Submodule.topEquiv theorem isSemisimpleModule_iff_exists_linearEquiv_dfinsupp : IsSemisimpleModule R M ↔ ∃ (s : Set (Submodule R M)) (_ : M ≃ₗ[R] Π₀ m : s, m.1), ∀ m : s, IsSimpleModule R m.1 := by refine ⟨fun _ ↦ ?_, fun ⟨s, e, h⟩ ↦ .congr e⟩ have ⟨s, e, h⟩ := IsSemisimpleModule.exists_linearEquiv_dfinsupp R M exact ⟨s, e, h.2⟩ variable (R M) in theorem IsSemisimpleModule.exists_linearEquiv_fin_dfinsupp [IsSemisimpleModule R M] [Module.Finite R M] : ∃ (n : ℕ) (S : Fin n → Submodule R M) (_ : M ≃ₗ[R] Π₀ i : Fin n, S i), ∀ i, IsSimpleModule R (S i) := have ⟨s, e, h, simple⟩ := IsSemisimpleModule.exists_linearEquiv_dfinsupp R M have := WellFoundedGT.finite_of_iSupIndep ((sSupIndep_iff _).mp h) fun S ↦ (S.1.nontrivial_iff_ne_bot).mp <| IsSimpleModule.nontrivial R S ⟨_, _, e.trans <| DirectSum.lequivCongrLeft R (Finite.equivFin s), fun _ ↦ simple _⟩ open LinearMap in instance {ι} [Finite ι] (M : ι → Type*) [∀ i, AddCommGroup (M i)] [∀ i, Module R (M i)] [∀ i, IsSemisimpleModule R (M i)] : IsSemisimpleModule R (Π i, M i) := by classical exact isSemisimpleModule_of_isSemisimpleModule_submodule' (p := (range <| single _ _ ·)) (fun i ↦ .range _) (by simp_rw [range_eq_map, Submodule.iSup_map_single, Submodule.pi_top]) theorem IsSemisimpleModule.sup {p q : Submodule R M} (_ : IsSemisimpleModule R p) (_ : IsSemisimpleModule R q) : IsSemisimpleModule R ↥(p ⊔ q) := by let f : Bool → Submodule R M := Bool.rec q p rw [show p ⊔ q = ⨆ i ∈ Set.univ, f i by rw [iSup_univ, iSup_bool_eq]] exact isSemisimpleModule_biSup_of_isSemisimpleModule_submodule (by rintro (_ | _) _ <;> assumption) variable (R M) in theorem IsSemisimpleRing.exists_linearEquiv_ideal_of_isSimpleModule [IsSemisimpleRing R] [h : IsSimpleModule R M] : ∃ I : Ideal R, Nonempty (M ≃ₗ[R] I) := have ⟨J, _, ⟨e⟩⟩ := isSimpleModule_iff_quot_maximal.mp h have ⟨I, ⟨e'⟩⟩ := IsSemisimpleModule.exists_submodule_linearEquiv_quotient J ⟨I, ⟨e.trans e'.symm⟩⟩ instance IsSemisimpleRing.isSemisimpleModule [IsSemisimpleRing R] : IsSemisimpleModule R M := have : IsSemisimpleModule R (M →₀ R) := isSemisimpleModule_of_isSemisimpleModule_submodule' (fun _ ↦ .congr (LinearMap.quotKerEquivRange _).symm) Finsupp.iSup_lsingle_range .congr (LinearMap.quotKerEquivOfSurjective _ <| Finsupp.linearCombination_id_surjective R M).symm instance IsSemisimpleModule.isCoatomic_submodule [IsSemisimpleModule R M] : IsCoatomic (Submodule R M) := isCoatomic_of_isAtomic_of_complementedLattice_of_isModular open LinearMap in /-- A finite product of semisimple rings is semisimple. -/ instance {ι} [Finite ι] (R : ι → Type*) [Π i, Ring (R i)] [∀ i, IsSemisimpleRing (R i)] : IsSemisimpleRing (Π i, R i) := by letI _ (i) : Module (Π i, R i) (R i) := Module.compHom _ (Pi.evalRingHom R i) let e (i) : R i →ₛₗ[Pi.evalRingHom R i] R i := { AddMonoidHom.id (R i) with map_smul' := fun _ _ ↦ rfl } have (i : _) : IsSemisimpleModule (Π i, R i) (R i) := ((e i).isSemisimpleModule_iff_of_bijective Function.bijective_id).mpr inferInstance infer_instance /-- A binary product of semisimple rings is semisimple. -/ instance [hR : IsSemisimpleRing R] [hS : IsSemisimpleRing S] : IsSemisimpleRing (R × S) := by letI : Module (R × S) R := Module.compHom _ (.fst R S) letI : Module (R × S) S := Module.compHom _ (.snd R S) -- e₁, e₂ got falsely flagged by the unused argument linter let _e₁ : R →ₛₗ[.fst R S] R := { AddMonoidHom.id R with map_smul' := fun _ _ ↦ rfl } let _e₂ : S →ₛₗ[.snd R S] S := { AddMonoidHom.id S with map_smul' := fun _ _ ↦ rfl } rw [IsSemisimpleRing, ← _e₁.isSemisimpleModule_iff_of_bijective Function.bijective_id] at hR rw [IsSemisimpleRing, ← _e₂.isSemisimpleModule_iff_of_bijective Function.bijective_id] at hS rw [IsSemisimpleRing, ← Submodule.topEquiv.isSemisimpleModule_iff_of_bijective (LinearEquiv.bijective _), ← LinearMap.sup_range_inl_inr] exact .sup (.range _) (.range _) theorem RingHom.isSemisimpleRing_of_surjective (f : R →+* S) (hf : Function.Surjective f) [IsSemisimpleRing R] : IsSemisimpleRing S := by letI : Module R S := Module.compHom _ f haveI : RingHomSurjective f := ⟨hf⟩ let e : S →ₛₗ[f] S := { AddMonoidHom.id S with map_smul' := fun _ _ ↦ rfl } rw [IsSemisimpleRing, ← e.isSemisimpleModule_iff_of_bijective Function.bijective_id] infer_instance theorem IsSemisimpleRing.ideal_eq_span_idempotent [IsSemisimpleRing R] (I : Ideal R) : ∃ e : R, IsIdempotentElem e ∧ I = .span {e} := by obtain ⟨J, h⟩ := exists_isCompl I obtain ⟨f, idem, rfl⟩ := I.isIdempotentElemEquiv.symm (I.isComplEquivProj ⟨J, h⟩) exact ⟨f 1, LinearMap.isIdempotentElem_apply_one_iff.mpr idem, by rw [LinearMap.range_eq_map, ← Ideal.span_one, ← Ideal.submodule_span_eq, LinearMap.map_span, Set.image_one, Ideal.submodule_span_eq]⟩ instance [IsSemisimpleRing R] : IsPrincipalIdealRing R where principal I := have ⟨e, _, he⟩ := IsSemisimpleRing.ideal_eq_span_idempotent I; ⟨e, he⟩ namespace LinearMap theorem injective_or_eq_zero [IsSimpleModule R M] (f : M →ₗ[R] N) : Function.Injective f ∨ f = 0 := by rw [← ker_eq_bot, ← ker_eq_top] apply eq_bot_or_eq_top theorem injective_of_ne_zero [IsSimpleModule R M] {f : M →ₗ[R] N} (h : f ≠ 0) : Function.Injective f := f.injective_or_eq_zero.resolve_right h theorem surjective_or_eq_zero [IsSimpleModule R N] (f : M →ₗ[R] N) : Function.Surjective f ∨ f = 0 := by rw [← range_eq_top, ← range_eq_bot, or_comm] apply eq_bot_or_eq_top theorem surjective_of_ne_zero [IsSimpleModule R N] {f : M →ₗ[R] N} (h : f ≠ 0) : Function.Surjective f := f.surjective_or_eq_zero.resolve_right h /-- **Schur's Lemma** for linear maps between (possibly distinct) simple modules -/ theorem bijective_or_eq_zero [IsSimpleModule R M] [IsSimpleModule R N] (f : M →ₗ[R] N) : Function.Bijective f ∨ f = 0 := or_iff_not_imp_right.mpr fun h ↦ ⟨injective_of_ne_zero h, surjective_of_ne_zero h⟩ theorem bijective_of_ne_zero [IsSimpleModule R M] [IsSimpleModule R N] {f : M →ₗ[R] N} (h : f ≠ 0) : Function.Bijective f := f.bijective_or_eq_zero.resolve_right h theorem isCoatom_ker_of_surjective [IsSimpleModule R N] {f : M →ₗ[R] N} (hf : Function.Surjective f) : IsCoatom (LinearMap.ker f) := by rw [← isSimpleModule_iff_isCoatom] exact IsSimpleModule.congr (f.quotKerEquivOfSurjective hf) theorem linearEquiv_of_ne_zero [IsSemisimpleModule R M] [IsSimpleModule R N] {f : M →ₗ[R] N} (h : f ≠ 0) : ∃ S : Submodule R M, Nonempty (N ≃ₗ[R] S) := have ⟨m, (_ : IsSimpleModule R m), ne⟩ := exists_ne_zero_of_sSup_eq_top h _ (IsSemisimpleModule.sSup_simples_eq_top ..) ⟨m, ⟨.symm <| .ofBijective _ ((bijective_or_eq_zero _).resolve_right ne)⟩⟩ /-- Schur's Lemma makes the endomorphism ring of a simple module a division ring. -/ noncomputable instance _root_.Module.End.instDivisionRing [DecidableEq (Module.End R M)] [IsSimpleModule R M] : DivisionRing (Module.End R M) where inv f := if h : f = 0 then 0 else (LinearEquiv.ofBijective _ <| bijective_of_ne_zero h).symm exists_pair_ne := ⟨0, 1, have := IsSimpleModule.nontrivial R M; zero_ne_one⟩ mul_inv_cancel a a0 := by simp_rw [dif_neg a0]; ext exact (LinearEquiv.ofBijective _ <| bijective_of_ne_zero a0).right_inv _ inv_zero := dif_pos rfl nnqsmul := _ nnqsmul_def := fun _ _ => rfl qsmul := _ qsmul_def := fun _ _ => rfl instance (R) [DivisionRing R] [Module R M] [Nontrivial M] : IsSimpleModule (Module.End R M) M := isSimpleModule_iff_toSpanSingleton_surjective.mpr <| .intro ‹_› fun v hv w ↦ have ⟨f, eq⟩ := IsSemisimpleModule.extension_property _ (ker_eq_bot.mp (ker_toSpanSingleton R M hv)) (toSpanSingleton R M w) ⟨f, by simpa using congr($eq 1)⟩ end LinearMap namespace JordanHolderModule instance instJordanHolderLattice : JordanHolderLattice (Submodule R M) where IsMaximal := (· ⋖ ·) lt_of_isMaximal := CovBy.lt sup_eq_of_isMaximal hxz hyz := WCovBy.sup_eq hxz.wcovBy hyz.wcovBy isMaximal_inf_left_of_isMaximal_sup := inf_covBy_of_covBy_sup_of_covBy_sup_left Iso X Y := Nonempty <| (X.2 ⧸ X.1.comap X.2.subtype) ≃ₗ[R] Y.2 ⧸ Y.1.comap Y.2.subtype iso_symm := fun ⟨f⟩ => ⟨f.symm⟩ iso_trans := fun ⟨f⟩ ⟨g⟩ => ⟨f.trans g⟩ second_iso {X} {Y} _ := by constructor rw [sup_comm, inf_comm] dsimp exact (LinearMap.quotientInfEquivSupQuotient Y X).symm end JordanHolderModule
.lake/packages/mathlib/Mathlib/RingTheory/SimpleModule/Isotypic.lean
import Mathlib.Algebra.Algebra.Pi import Mathlib.Order.CompleteSublattice import Mathlib.RingTheory.SimpleModule.Basic /-! # Isotypic modules and isotypic components ## Main definitions * `IsIsotypicOfType R M S` means that all simple submodules of the `R`-module `M` are isomorphic to `S`. Such a module `M` is isomorphic to a finsupp over `S`, see `IsIsotypicOfType.linearEquiv_finsupp`. * `IsIsotypic R M` means that all simple submodules of the `R`-module `M` are isomorphic to each other. * `isotypicComponent R M S` is the sum of all submodules of `M` isomorphic to `S`. * `isotypicComponents R M` is the set of all nontrivial isotypic components of `M` (where `S` is taken to be simple submodules). * `Submodule.IsFullyInvariant N` means that the submodule `N` of an `R`-module `M` is mapped into itself by all endomorphisms of `M`. The `fullyInvariantSubmodule`s of `M` form a complete lattice, which is atomic if `M` is semisimple, in which case the atoms are the isotypic components of `M`. A fully invariant submodule of a semiring as a module over itself is simply a two-sided ideal, see `isFullyInvariant_iff_isTwoSided`. * `iSupIndep.ringEquiv`, `iSupIndep.algEquiv`: if `M` is the direct sum of fully invariant submodules `Nᵢ`, then `End R M` is isomorphic to `Πᵢ End R Nᵢ`. This can be applied to the isotypic components of a semisimple module `M`, yielding `IsSemisimpleModule.endAlgEquiv`. ## Keywords isotypic component, fully invariant submodule -/ universe u variable (R₀ R : Type*) (M : Type u) (N S : Type*) [CommSemiring R₀] [Ring R] [Algebra R₀ R] [AddCommGroup M] [AddCommGroup N] [AddCommGroup S] [Module R M] [Module R N] [Module R S] /-- An `R`-module `M` is isotypic of type `S` if all simple submodules of `M` are isomorphic to `S`. If `M` is semisimple, it is equivalent to requiring that all simple quotients of `M` are isomorphic to `S`. -/ def IsIsotypicOfType : Prop := ∀ (m : Submodule R M) [IsSimpleModule R m], Nonempty (m ≃ₗ[R] S) /-- An `R`-module `M` is isotypic if all its simple submodules are isomorphic. -/ def IsIsotypic : Prop := ∀ (m : Submodule R M) [IsSimpleModule R m], IsIsotypicOfType R M m variable {R M S} in theorem IsIsotypicOfType.isIsotypic (h : IsIsotypicOfType R M S) : IsIsotypic R M := fun m _ m' _ ↦ ⟨(h m').some.trans (h m).some.symm⟩ @[nontriviality] theorem IsIsotypicOfType.of_subsingleton [Subsingleton M] : IsIsotypicOfType R M S := fun S ↦ have := IsSimpleModule.nontrivial R S (not_subsingleton _ S.subtype_injective.subsingleton).elim @[nontriviality] theorem IsIsotypic.of_subsingleton [Subsingleton M] : IsIsotypic R M := fun S ↦ (IsIsotypicOfType.of_subsingleton R M S).isIsotypic S theorem IsIsotypicOfType.of_isSimpleModule [IsSimpleModule R M] : IsIsotypicOfType R M M := fun S hS ↦ by rw [isSimpleModule_iff_isAtom, isAtom_iff_eq_top] at hS exact ⟨.trans (.ofEq _ _ hS) Submodule.topEquiv⟩ variable {R} theorem IsIsotypic.of_self [IsSemisimpleRing R] (h : IsIsotypic R R) : IsIsotypic R M := fun m _ m' _ ↦ have ⟨_, ⟨e⟩⟩ := IsSemisimpleRing.exists_linearEquiv_ideal_of_isSimpleModule R m have ⟨_, ⟨e'⟩⟩ := IsSemisimpleRing.exists_linearEquiv_ideal_of_isSimpleModule R m' have := IsSimpleModule.congr e.symm have := IsSimpleModule.congr e'.symm ⟨e'.trans <| (h _ _).some.trans e.symm⟩ variable {M N S} theorem IsIsotypicOfType.of_linearEquiv_type (h : IsIsotypicOfType R M S) (e : S ≃ₗ[R] N) : IsIsotypicOfType R M N := fun m _ ↦ ⟨(h m).some.trans e⟩ theorem IsIsotypicOfType.of_injective (h : IsIsotypicOfType R N S) (f : M →ₗ[R] N) (inj : Function.Injective f) : IsIsotypicOfType R M S := fun m ↦ have em := m.equivMapOfInjective f inj have := IsSimpleModule.congr em.symm ⟨em.trans (h (m.map f)).some⟩ theorem IsIsotypic.of_injective (h : IsIsotypic R N) (f : M →ₗ[R] N) (inj : Function.Injective f) : IsIsotypic R M := fun m _ ↦ have em := (m.equivMapOfInjective f inj).symm have := IsSimpleModule.congr em ((h (m.map f)).of_injective f inj).of_linearEquiv_type em theorem LinearEquiv.isIsotypicOfType_iff (e : M ≃ₗ[R] N) : IsIsotypicOfType R M S ↔ IsIsotypicOfType R N S := ⟨(·.of_injective _ e.symm.injective), (·.of_injective _ e.injective)⟩ theorem LinearEquiv.isIsotypicOfType_iff_type (e : N ≃ₗ[R] S) : IsIsotypicOfType R M N ↔ IsIsotypicOfType R M S := ⟨(·.of_linearEquiv_type e), (·.of_linearEquiv_type e.symm)⟩ theorem LinearEquiv.isIsotypic_iff (e : M ≃ₗ[R] N) : IsIsotypic R M ↔ IsIsotypic R N := ⟨(·.of_injective _ e.symm.injective), (·.of_injective _ e.injective)⟩ theorem isIsotypicOfType_submodule_iff {N : Submodule R M} : IsIsotypicOfType R N S ↔ ∀ m ≤ N, [IsSimpleModule R m] → Nonempty (m ≃ₗ[R] S) := by rw [Subtype.forall', ← (Submodule.MapSubtype.orderIso N).forall_congr_right] have e := Submodule.equivMapOfInjective _ N.subtype_injective simp_rw [Submodule.MapSubtype.orderIso, Equiv.coe_fn_mk, ← (e _).isSimpleModule_iff] exact forall₂_congr fun m _ ↦ ⟨fun ⟨e'⟩ ↦ ⟨(e m).symm.trans e'⟩, fun ⟨e'⟩ ↦ ⟨(e m).trans e'⟩⟩ theorem isIsotypic_submodule_iff {N : Submodule R M} : IsIsotypic R N ↔ ∀ m ≤ N, [IsSimpleModule R m] → IsIsotypicOfType R N m := by rw [Subtype.forall', ← (Submodule.MapSubtype.orderIso N).forall_congr_right] have e := Submodule.equivMapOfInjective _ N.subtype_injective simp_rw [Submodule.MapSubtype.orderIso, Equiv.coe_fn_mk, ← (e _).isSimpleModule_iff, ← (e _).isIsotypicOfType_iff_type, IsIsotypic] section Finsupp variable [IsSemisimpleModule R M] theorem IsIsotypicOfType.linearEquiv_finsupp (h : IsIsotypicOfType R M S) : ∃ ι : Type u, Nonempty (M ≃ₗ[R] ι →₀ S) := by have ⟨s, e, _, hs⟩ := IsSemisimpleModule.exists_linearEquiv_dfinsupp R M classical exact ⟨s, ⟨e.trans (DFinsupp.mapRange.linearEquiv fun m : s ↦ (h m.1).some) |>.trans (finsuppLequivDFinsupp R).symm⟩⟩ theorem IsIsotypic.linearEquiv_finsupp [Nontrivial M] (h : IsIsotypic R M) : ∃ (ι : Type u) (_ : Nonempty ι) (S : Submodule R M), IsSimpleModule R S ∧ Nonempty (M ≃ₗ[R] ι →₀ S) := by have ⟨S, hS⟩ := IsAtomic.exists_atom (Submodule R M) rw [← isSimpleModule_iff_isAtom] at hS have ⟨ι, e⟩ := (h S).linearEquiv_finsupp exact ⟨ι, (isEmpty_or_nonempty ι).resolve_left fun _ ↦ not_subsingleton _ (e.some.subsingleton), S, hS, e⟩ theorem IsIsotypicOfType.linearEquiv_fun [Module.Finite R M] (h : IsIsotypicOfType R M S) : ∃ n : ℕ, Nonempty (M ≃ₗ[R] Fin n → S) := by have ⟨n, S, e, hs⟩ := IsSemisimpleModule.exists_linearEquiv_fin_dfinsupp R M classical exact ⟨n, ⟨e.trans (DFinsupp.mapRange.linearEquiv fun i ↦ (h (S i)).some) |>.trans (finsuppLequivDFinsupp R).symm |>.trans (Finsupp.linearEquivFunOnFinite ..)⟩⟩ theorem IsIsotypic.linearEquiv_fun [Module.Finite R M] [Nontrivial M] (h : IsIsotypic R M) : ∃ (n : ℕ) (_ : NeZero n) (S : Submodule R M), IsSimpleModule R S ∧ Nonempty (M ≃ₗ[R] Fin n → S) := by have ⟨S, hS⟩ := IsAtomic.exists_atom (Submodule R M) rw [← isSimpleModule_iff_isAtom] at hS have ⟨n, e⟩ := (h S).linearEquiv_fun exact ⟨n, neZero_iff.2 <| by rintro rfl; exact not_subsingleton _ (e.some.subsingleton), S, hS, e⟩ theorem IsIsotypic.submodule_linearEquiv_fun {m : Submodule R M} [Module.Finite R m] [Nontrivial m] (h : IsIsotypic R m) : ∃ (n : ℕ) (_ : NeZero n) (S : Submodule R M), S ≤ m ∧ IsSimpleModule R S ∧ Nonempty (m ≃ₗ[R] Fin n → S) := have ⟨n, hn, S, _, ⟨e⟩⟩ := h.linearEquiv_fun let e' := S.equivMapOfInjective _ m.subtype_injective ⟨n, hn, _, m.map_subtype_le S, .congr e'.symm, ⟨e.trans <| .piCongrRight fun _ ↦ e'⟩⟩ end Finsupp variable (R M S) /-- If `S` is a simple `R`-module, the `S`-isotypic component in an `R`-module `M` is the sum of all submodules of `M` isomorphic to `S`. -/ def isotypicComponent : Submodule R M := sSup {m | Nonempty (m ≃ₗ[R] S)} /-- The set of all (nontrivial) isotypic components of a module. -/ def isotypicComponents : Set (Submodule R M) := { m | ∃ S : Submodule R M, IsSimpleModule R S ∧ m = isotypicComponent R M S } variable {R M} theorem Submodule.le_isotypicComponent (m : Submodule R M) : m ≤ isotypicComponent R M m := le_sSup ⟨.refl ..⟩ theorem bot_lt_isotypicComponent (S : Submodule R M) [IsSimpleModule R S] : ⊥ < isotypicComponent R M S := (bot_lt_iff_ne_bot.mpr <| (S.nontrivial_iff_ne_bot).mp <| IsSimpleModule.nontrivial R S).trans_le S.le_isotypicComponent theorem bot_lt_isotypicComponents {m : Submodule R M} (h : m ∈ isotypicComponents R M) : ⊥ < m := by obtain ⟨_, _, rfl⟩ := h; exact bot_lt_isotypicComponent .. instance (c : isotypicComponents R M) : Nontrivial c := Submodule.nontrivial_iff_ne_bot.mpr (bot_lt_isotypicComponents c.2).ne' instance [IsSemisimpleModule R S] : IsSemisimpleModule R (isotypicComponent R M S) := by rw [isotypicComponent, sSup_eq_iSup] refine isSemisimpleModule_biSup_of_isSemisimpleModule_submodule fun m ⟨e⟩ ↦ ?_ have := IsSemisimpleModule.congr e infer_instance instance (c : isotypicComponents R M) : IsSemisimpleModule R c := by obtain ⟨c, S, _, rfl⟩ := c; infer_instance variable {S} in theorem LinearEquiv.isotypicComponent_eq (e : N ≃ₗ[R] S) : isotypicComponent R M N = isotypicComponent R M S := congr_arg sSup <| Set.ext fun _ ↦ Nonempty.congr (·.trans e) (·.trans e.symm) section SimpleSubmodule variable (N : Submodule R M) [IsSimpleModule R N] (s : Set (Submodule R M)) open LinearMap in theorem Submodule.le_linearEquiv_of_sSup_eq_top [IsSemisimpleModule R M] (hs : sSup s = ⊤) : ∃ m ∈ s, ∃ S ≤ m, Nonempty (N ≃ₗ[R] S) := by have := IsSimpleModule.nontrivial R N have ⟨_, compl⟩ := exists_isCompl N have ⟨m, hm, ne⟩ := exists_ne_zero_of_sSup_eq_top (ne_zero_of_surjective (N.linearProjOfIsCompl_surjective compl)) _ hs have ⟨S, ⟨e⟩⟩ := linearEquiv_of_ne_zero ne exact ⟨m, hm, _, m.map_subtype_le S, ⟨e.trans (S.equivMapOfInjective _ m.subtype_injective)⟩⟩ theorem Submodule.linearEquiv_of_sSup_eq_top [h : ∀ m : s, IsSimpleModule R m] (hs : sSup s = ⊤) : ∃ S ∈ s, Nonempty (N ≃ₗ[R] S) := have := isSemisimpleModule_of_isSemisimpleModule_submodule' (fun _ ↦ inferInstance) (sSup_eq_iSup' s ▸ hs) have ⟨m, hm, _S, le, ⟨e⟩⟩ := N.le_linearEquiv_of_sSup_eq_top _ hs have := isSimpleModule_iff_isAtom.mp (IsSimpleModule.congr e.symm) have := ((isSimpleModule_iff_isAtom.mp <| h ⟨m, hm⟩).le_iff_eq this.1).mp le ⟨m, hm, ⟨e.trans (.ofEq _ _ this)⟩⟩ /-- If a simple module is contained in a sum of semisimple modules, it must be isomorphic to a submodule of one of the summands. -/ theorem Submodule.le_linearEquiv_of_le_sSup [hs : ∀ m : s, IsSemisimpleModule R m] (hN : N ≤ sSup s) : ∃ m ∈ s, ∃ S ≤ m, Nonempty (N ≃ₗ[R] S) := by rw [sSup_eq_iSup] at hN have e := LinearEquiv.ofInjective _ (inclusion_injective hN) have := IsSimpleModule.congr e.symm have := isSemisimpleModule_biSup_of_isSemisimpleModule_submodule fun m hm ↦ hs ⟨m, hm⟩ obtain ⟨_, ⟨m, hm, rfl⟩, S, le, ⟨e'⟩⟩ := LinearMap.range (inclusion hN) |>.le_linearEquiv_of_sSup_eq_top (comap (⨆ i ∈ s, i).subtype '' s) <| by rw [sSup_image, biSup_comap_subtype_eq_top] exact ⟨m, hm, _, map_le_iff_le_comap.mpr le, ⟨(e.trans e').trans (equivMapOfInjective _ (subtype_injective _) _)⟩⟩ theorem Submodule.linearEquiv_of_le_sSup [simple : ∀ m : s, IsSimpleModule R m] (hs : N ≤ sSup s) : ∃ S ∈ s, Nonempty (N ≃ₗ[R] S) := have ⟨m, hm, _S, le, ⟨e⟩⟩ := N.le_linearEquiv_of_le_sSup _ hs have := isSimpleModule_iff_isAtom.mp (.congr e.symm) have := ((isSimpleModule_iff_isAtom.mp <| simple ⟨m, hm⟩).le_iff_eq this.1).mp le ⟨m, hm, ⟨e.trans (.ofEq _ _ this)⟩⟩ end SimpleSubmodule section IsSimpleModule variable (R M) [IsSimpleModule R S] local instance (m : {m : Submodule R M | Nonempty (m ≃ₗ[R] S)}) : IsSimpleModule R m := .congr m.2.some protected theorem IsIsotypicOfType.isotypicComponent : IsIsotypicOfType R (isotypicComponent R M S) S := isIsotypicOfType_submodule_iff.mpr fun m h _ ↦ have ⟨_, ⟨e⟩, ⟨e'⟩⟩ := m.linearEquiv_of_le_sSup _ h ⟨e'.trans e⟩ protected theorem IsIsotypic.isotypicComponent : IsIsotypic R (isotypicComponent R M S) := (IsIsotypicOfType.isotypicComponent R M S).isIsotypic variable {R M} in protected theorem IsIsotypic.isotypicComponents {m : Submodule R M} (h : m ∈ isotypicComponents R M) : IsIsotypic R m := by obtain ⟨_, _, rfl⟩ := h; exact .isotypicComponent R M _ variable {R M} in theorem eq_isotypicComponent_of_le {S c : Submodule R M} (hc : c ∈ isotypicComponents R M) [IsSimpleModule R S] (le : S ≤ c) : c = isotypicComponent R M S := by obtain ⟨S', _, rfl⟩ := hc have ⟨e⟩ := isIsotypicOfType_submodule_iff.mp (.isotypicComponent R M S') _ le exact e.symm.isotypicComponent_eq theorem sSupIndep_isotypicComponents : sSupIndep (isotypicComponents R M) := fun c hc ↦ disjoint_iff.mpr <| of_not_not fun ne ↦ by set s := isotypicComponents R M \ {c} have : IsSemisimpleModule R c := by obtain ⟨S, _, rfl⟩ := hc; infer_instance have := IsSemisimpleModule.of_injective _ (Submodule.inclusion_injective (inf_le_left : c ⊓ sSup s ≤ c)) have (c : s) : IsSemisimpleModule R c := by obtain ⟨_, ⟨_, _, rfl⟩, _⟩ := c; infer_instance have ⟨S, le, _⟩ := (IsSemisimpleModule.eq_bot_or_exists_simple_le _).resolve_left ne have ⟨c', hc', S', le', ⟨e⟩⟩ := S.le_linearEquiv_of_le_sSup _ (le.trans inf_le_right) have := IsSimpleModule.congr e.symm refine hc'.2 ?_ rw [eq_isotypicComponent_of_le hc (le.trans inf_le_left), eq_isotypicComponent_of_le hc'.1 le'] exact e.symm.isotypicComponent_eq instance [IsNoetherian R M] : Finite (isotypicComponents R M) := Set.finite_coe_iff.mpr <| WellFoundedGT.finite_of_sSupIndep (sSupIndep_isotypicComponents R M) variable {R M S} theorem IsIsotypicOfType.of_isotypicComponent_eq_top (h : isotypicComponent R M S = ⊤) : IsIsotypicOfType R M S := fun m _ ↦ have ⟨_, ⟨e⟩, ⟨e'⟩⟩ := m.linearEquiv_of_sSup_eq_top _ h; ⟨e'.trans e⟩ theorem Submodule.map_le_isotypicComponent (S : Submodule R M) [IsSimpleModule R S] (f : M →ₗ[R] N) : S.map f ≤ isotypicComponent R N S := by conv_lhs => rw [← S.range_subtype, ← LinearMap.range_comp] obtain inj | eq := (f ∘ₗ S.subtype).injective_or_eq_zero · exact le_sSup ⟨.symm <| .ofInjective _ inj⟩ · simp_rw [eq, LinearMap.range_zero, bot_le] variable (S) in theorem LinearMap.le_comap_isotypicComponent (f : M →ₗ[R] N) : isotypicComponent R M S ≤ (isotypicComponent R N S).comap f := sSup_le fun m ⟨e⟩ ↦ Submodule.map_le_iff_le_comap.mp <| have := IsSimpleModule.congr e (m.map_le_isotypicComponent f).trans_eq e.isotypicComponent_eq section IsFullyInvariant variable {R M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] /-- A submodule `N` an `R`-module `M` is fully invariant if `N` is mapped into itself by all `R`-linear endomorphisms of `M`. If `M` is semisimple, this is equivalent to `N` being a sum of isotypic components of `M`: see `isFullyInvariant_iff_sSup_isotypicComponents`. -/ def Submodule.IsFullyInvariant (N : Submodule R M) : Prop := ∀ f : Module.End R M, N ≤ N.comap f theorem isFullyInvariant_iff_isTwoSided {I : Ideal R} : I.IsFullyInvariant ↔ I.IsTwoSided := by simpa only [Submodule.IsFullyInvariant, ← MulOpposite.opEquiv.trans (RingEquiv.moduleEndSelf R |>.toEquiv) |>.forall_congr_right, SetLike.le_def, I.isTwoSided_iff] using forall_comm variable (R M) in /-- The fully invariant submodules of a module form a complete sublattice in the lattice of submodules. -/ def fullyInvariantSubmodule : CompleteSublattice (Submodule R M) := .mk' { N : Submodule R M | N.IsFullyInvariant } (fun _s hs f ↦ sSup_le fun _N hN ↦ (hs hN f).trans <| Submodule.comap_mono <| le_sSup hN) fun _s hs f ↦ Submodule.map_le_iff_le_comap.mp <| le_sInf fun _N hN ↦ Submodule.map_le_iff_le_comap.mpr <| (sInf_le hN).trans (hs hN f) theorem mem_fullyInvariantSubmodule_iff {m : Submodule R M} : m ∈ fullyInvariantSubmodule R M ↔ m.IsFullyInvariant := Iff.rfl end IsFullyInvariant section Equiv variable {ι : Type*} [DecidableEq ι] {N : ι → Submodule R M} (ind : iSupIndep N) (iSup_top : ⨆ i, N i = ⊤) (invar : ∀ i, (N i).IsFullyInvariant) /-- If an `R`-module `M` is the direct sum of fully invariant submodules `Nᵢ`, then `End R M` is isomorphic to `Πᵢ End R Nᵢ` as a ring. -/ noncomputable def iSupIndep.ringEquiv : Module.End R M ≃+* Π i, Module.End R (N i) where toFun f i := f.restrict (invar i f) invFun f := letI e := ind.linearEquiv iSup_top; e ∘ₗ DFinsupp.mapRange.linearMap f ∘ₗ e.symm left_inv f := LinearMap.ext fun x ↦ by exact Submodule.iSup_induction _ (motive := (_ = f ·)) (iSup_top ▸ Submodule.mem_top (x := x)) (fun i x h ↦ by simp [ind.linearEquiv_symm_apply _ h]) (by simp) fun _ _ h₁ h₂ ↦ by simpa only [map_add] using congr($h₁ + $h₂) right_inv f := by ext i x; simp [ind.linearEquiv_symm_apply _ x.2] map_add' _ _ := rfl map_mul' _ _ := rfl /-- If an `R`-module `M` is the direct sum of fully invariant submodules `Nᵢ`, then `End R M` is isomorphic to `Πᵢ End R Nᵢ` as an algebra. -/ noncomputable def iSupIndep.algEquiv [Module R₀ M] [IsScalarTower R₀ R M] : Module.End R M ≃ₐ[R₀] Π i, Module.End R (N i) where __ := ind.ringEquiv iSup_top invar commutes' _ := rfl end Equiv variable (R M S) in protected theorem Submodule.IsFullyInvariant.isotypicComponent : (isotypicComponent R M S).IsFullyInvariant := LinearMap.le_comap_isotypicComponent S theorem Submodule.IsFullyInvariant.of_mem_isotypicComponents {m : Submodule R M} (h : m ∈ isotypicComponents R M) : m.IsFullyInvariant := by obtain ⟨_, _, rfl⟩ := h; exact .isotypicComponent R M _ variable (R M) in /-- The Galois coinsertion from sets of isotypic components to fully invariant submodules. -/ def GaloisCoinsertion.setIsotypicComponents : GaloisCoinsertion (α := Set (isotypicComponents R M)) (β := fullyInvariantSubmodule R M) (fun s ↦ ⨆ c ∈ s, ⟨c, .of_mem_isotypicComponents c.2⟩) fun m ↦ {c | c.1 ≤ m} := GaloisConnection.toGaloisCoinsertion (fun _ _ ↦ iSup₂_le_iff) fun s c hc ↦ of_not_not fun hcs ↦ (bot_lt_isotypicComponents c.2).ne' <| (sSupIndep_isotypicComponents R M c.2).eq_bot_of_le <| hc.trans <| by simp_rw [CompleteSublattice.coe_iSup, iSup₂_le_iff] exact fun c hc ↦ le_sSup ⟨c.2, Subtype.coe_ne_coe.mpr (ne_of_mem_of_not_mem hc hcs)⟩ theorem le_isotypicComponent_iff [IsSemisimpleModule R M] {m : Submodule R M} : m ≤ isotypicComponent R M S ↔ IsIsotypicOfType R m S where mp h := .of_injective (.isotypicComponent R M S) _ (Submodule.inclusion_injective h) mpr h := (IsSemisimpleModule.sSup_simples_le m).ge.trans (sSup_le_sSup fun S ⟨_, le⟩ ↦ isIsotypicOfType_submodule_iff.mp h S le) theorem isotypicComponent_eq_top_iff [IsSemisimpleModule R M] : isotypicComponent R M S = ⊤ ↔ IsIsotypicOfType R M S := by rw [← top_le_iff, le_isotypicComponent_iff, Submodule.topEquiv.isIsotypicOfType_iff] open IsSemisimpleModule in theorem isFullyInvariant_iff_le_imp_isotypicComponent_le [IsSemisimpleModule R M] {m : Submodule R M} : m.IsFullyInvariant ↔ ∀ S ≤ m, [IsSimpleModule R S] → isotypicComponent R M S ≤ m where mp h S le _ := sSup_le fun S' ⟨e⟩ ↦ by have ⟨p, eq⟩ := extension_property _ S.subtype_injective (S'.subtype ∘ₗ e.symm) refine le_trans ?_ (Submodule.map_le_iff_le_comap.mpr (le.trans (h p))) rw [← S.range_subtype, ← LinearMap.range_comp, eq, e.symm.range_comp, S'.range_subtype] mpr h f := (sSup_simples_le m).ge.trans <| sSup_le fun S ⟨_, le⟩ ↦ Submodule.map_le_iff_le_comap.mp ((S.map_le_isotypicComponent f).trans (h S le)) theorem eq_isotypicComponent_iff [IsSemisimpleModule R M] {m : Submodule R M} (ne : m ≠ ⊥) : m = isotypicComponent R M S ↔ IsIsotypicOfType R m S ∧ m.IsFullyInvariant where mp := by rintro rfl; exact ⟨.isotypicComponent R M S, .isotypicComponent R M S⟩ mpr := fun ⟨iso, invar⟩ ↦ (le_isotypicComponent_iff.mpr iso).antisymm <| have ⟨S', le, _⟩ := (IsSemisimpleModule.eq_bot_or_exists_simple_le m).resolve_left ne (isIsotypicOfType_submodule_iff.mp iso S' le).some.symm.isotypicComponent_eq.trans_le (isFullyInvariant_iff_le_imp_isotypicComponent_le.mp invar _ le) end IsSimpleModule variable [IsSemisimpleModule R M] open IsSemisimpleModule theorem isIsotypic_iff_isFullyInvariant_imp_bot_or_top : IsIsotypic R M ↔ ∀ N : Submodule R M, N.IsFullyInvariant → N = ⊥ ∨ N = ⊤ where mp h N hN := (eq_bot_or_exists_simple_le N).imp_right fun ⟨S, le, _⟩ ↦ top_unique <| (isotypicComponent_eq_top_iff.mpr (h S)).ge.trans ((isFullyInvariant_iff_le_imp_isotypicComponent_le.mp hN) _ le) mpr h S _ := isotypicComponent_eq_top_iff.mp <| (h _ (.isotypicComponent R M S)).resolve_left (bot_lt_isotypicComponent S).ne' theorem mem_isotypicComponents_iff {m : Submodule R M} : m ∈ isotypicComponents R M ↔ IsIsotypic R m ∧ m.IsFullyInvariant ∧ m ≠ ⊥ where mp := by rintro ⟨S, _, rfl⟩; exact ⟨.isotypicComponent R M S, .isotypicComponent R M S, (bot_lt_isotypicComponent S).ne'⟩ mpr := fun ⟨iso, invar, ne⟩ ↦ have ⟨S, le, simple⟩ := (eq_bot_or_exists_simple_le m).resolve_left ne ⟨S, simple, (eq_isotypicComponent_iff ne).mpr ⟨isIsotypic_submodule_iff.mp iso S le, invar⟩⟩ /-- Sets of isotypic components in a semisimple module are in order-preserving 1-1 correspondence with fully invariant submodules. Consequently, the fully invariant submodules form a complete atomic Boolean algebra. -/ @[simps] def OrderIso.setIsotypicComponents : Set (isotypicComponents R M) ≃o fullyInvariantSubmodule R M where toFun s := ⨆ c ∈ s, ⟨c, .of_mem_isotypicComponents c.2⟩ invFun m := { c | c.1 ≤ m } left_inv := (GaloisCoinsertion.setIsotypicComponents R M).u_l_eq right_inv m := (iSup₂_le fun _ ↦ by exact id).antisymm <| (sSup_simples_le m.1).ge.trans <| sSup_le fun S ⟨simple, le⟩ ↦ S.le_isotypicComponent.trans <| by let c : isotypicComponents R M := ⟨_, S, simple, rfl⟩ simp_rw [← show c.1 = isotypicComponent R M S from rfl, CompleteSublattice.coe_iSup] exact le_biSup _ (isFullyInvariant_iff_le_imp_isotypicComponent_le.mp m.2 _ le) map_rel_iff' := (GaloisCoinsertion.setIsotypicComponents R M).l_le_l_iff theorem isFullyInvariant_iff_sSup_isotypicComponents {m : Submodule R M} : m.IsFullyInvariant ↔ ∃ s ⊆ isotypicComponents R M, m = sSup s := by refine ⟨fun h ↦ ⟨OrderIso.setIsotypicComponents.symm ⟨m, h⟩, ⟨?_, ?_⟩⟩, ?_⟩ · rintro _ ⟨c, _, rfl⟩; exact c.2 · convert Subtype.ext_iff.mp (OrderIso.setIsotypicComponents.right_inv ⟨m, h⟩).symm simp [sSup_image, OrderIso.setIsotypicComponents, OrderIso.symm] · rintro ⟨_, hs, rfl⟩ exact (fullyInvariantSubmodule R M).sSupClosed fun _ h ↦ .of_mem_isotypicComponents (hs h) variable (R M) in theorem sSup_isotypicComponents : sSup (isotypicComponents R M) = ⊤ := have ⟨_, h, eq⟩ := isFullyInvariant_iff_sSup_isotypicComponents.mp (fullyInvariantSubmodule R M).top_mem top_unique <| eq.le.trans (sSup_le_sSup h) namespace IsSemisimpleModule variable (R M) [Module R₀ M] [IsScalarTower R₀ R M] [DecidableEq (isotypicComponents R M)] /-- The endomorphism algebra of a semisimple module is the direct product of the endomorphism algebras of its isotypic components. -/ noncomputable def endAlgEquiv : Module.End R M ≃ₐ[R₀] Π c : isotypicComponents R M, Module.End R c.1 := ((sSupIndep_iff _).mp <| sSupIndep_isotypicComponents R M).algEquiv R₀ ((sSup_eq_iSup' _).symm.trans <| sSup_isotypicComponents R M) (.of_mem_isotypicComponents ·.2) /-- The endomorphism ring of a semisimple module is the direct product of the endomorphism rings of its isotypic components. -/ noncomputable def endRingEquiv : Module.End R M ≃+* Π c : isotypicComponents R M, Module.End R c.1 := (endAlgEquiv ℕ R M).toRingEquiv end IsSemisimpleModule
.lake/packages/mathlib/Mathlib/RingTheory/SimpleModule/WedderburnArtin.lean
import Mathlib.LinearAlgebra.FreeModule.Finite.Basic import Mathlib.RingTheory.FiniteLength import Mathlib.RingTheory.SimpleModule.Isotypic import Mathlib.RingTheory.SimpleRing.Congr import Mathlib.RingTheory.SimpleRing.Matrix /-! # Wedderburn–Artin Theorem ## Main results * `IsSimpleRing.tfae`: a simple ring is semisimple iff it is Artinian, iff it has a minimal left ideal. * `isSimpleRing_isArtinianRing_iff`: a ring is simple Artinian iff it is semisimple, isotypic, and nontrivial. * `IsSimpleRing.exists_algEquiv_matrix_end_mulOpposite`: a simple Artinian algebra is isomorphic to a (finite-dimensional) matrix algebra over a division algebra. The division algebra is the opposite of the endomorphism algebra of a simple (i.e., minimal) left ideal. * `IsSemisimpleRing.exists_algEquiv_pi_matrix_end_mulOpposite`: a semisimple algebra is isomorphic to a finite direct product of matrix algebras over division algebras. The division algebras are the opposites of the endomorphism algebras of the simple (i.e., minimal) left ideals. * `IsSimpleRing.exists_algEquiv_matrix_divisionRing_finite`, `IsSemisimpleRing.exists_algEquiv_pi_matrix_divisionRing_finite`: if the simple Artinian / semisimple algebra is finite as a module over a base ring, then the division algebra(s) are also finite over the same ring. If the base ring is an algebraically closed field, the only finite-dimensional division algebra over it is itself, and we obtain `IsSimpleRing.exists_algEquiv_matrix_of_isAlgClosed` and `IsSemisimpleRing.exists_algEquiv_pi_matrix_of_isAlgClosed` (in a later file). -/ universe u variable (R₀ : Type*) {R : Type u} [CommSemiring R₀] [Ring R] [Algebra R₀ R] /-- A simple ring is semisimple iff it is Artinian, iff it has a minimal left ideal. -/ theorem IsSimpleRing.tfae [IsSimpleRing R] : List.TFAE [IsSemisimpleRing R, IsArtinianRing R, ∃ I : Ideal R, IsAtom I] := by tfae_have 1 → 2 := fun _ ↦ inferInstance tfae_have 2 → 3 := fun _ ↦ IsAtomic.exists_atom _ tfae_have 3 → 1 := fun ⟨I, hI⟩ ↦ by have ⟨_, h⟩ := isSimpleRing_iff_isTwoSided_imp.mp ‹IsSimpleRing R› simp_rw [← isFullyInvariant_iff_isTwoSided] at h have := isSimpleModule_iff_isAtom.mpr hI obtain eq | eq := h _ (.isotypicComponent R R I) · exact (hI.bot_lt.not_ge <| (le_sSup <| by exact ⟨.refl ..⟩).trans_eq eq).elim exact .congr (.symm <| .trans (.ofEq _ _ eq) Submodule.topEquiv) tfae_finish theorem IsSimpleRing.isSemisimpleRing_iff_isArtinianRing [IsSimpleRing R] : IsSemisimpleRing R ↔ IsArtinianRing R := tfae.out 0 1 theorem isSimpleRing_isArtinianRing_iff : IsSimpleRing R ∧ IsArtinianRing R ↔ IsSemisimpleRing R ∧ IsIsotypic R R ∧ Nontrivial R := by refine ⟨fun ⟨_, _⟩ ↦ ?_, fun ⟨_, _, _⟩ ↦ ?_⟩ on_goal 1 => have := IsSimpleRing.isSemisimpleRing_iff_isArtinianRing.mpr ‹_› all_goals simp_rw [isIsotypic_iff_isFullyInvariant_imp_bot_or_top, isFullyInvariant_iff_isTwoSided, isSimpleRing_iff_isTwoSided_imp] at * · exact ⟨this, by rwa [and_comm]⟩ · exact ⟨⟨‹_›, ‹_›⟩, inferInstance⟩ namespace IsSimpleRing variable (R) [IsSimpleRing R] [IsArtinianRing R] instance (priority := low) : IsSemisimpleRing R := (isSimpleRing_isArtinianRing_iff.mp ⟨‹_›, ‹_›⟩).1 theorem isIsotypic (M) [AddCommGroup M] [Module R M] : IsIsotypic R M := (isSimpleRing_isArtinianRing_iff.mp ⟨‹_›, ‹_›⟩).2.1.of_self M /-- The **Wedderburn–Artin Theorem**: an Artinian simple ring is isomorphic to a matrix ring over the opposite of the endomorphism ring of its simple module. -/ theorem exists_ringEquiv_matrix_end_mulOpposite : ∃ (n : ℕ) (_ : NeZero n) (I : Ideal R) (_ : IsSimpleModule R I), Nonempty (R ≃+* Matrix (Fin n) (Fin n) (Module.End R I)ᵐᵒᵖ) := by have ⟨n, hn, S, hS, ⟨e⟩⟩ := (isIsotypic R R).linearEquiv_fun refine ⟨n, hn, S, hS, ⟨.trans (.opOp R) <| .trans (.op ?_) (.symm .mopMatrix)⟩⟩ exact .trans (.moduleEndSelf R) <| .trans e.conjRingEquiv (endVecRingEquivMatrixEnd ..) /-- The **Wedderburn–Artin Theorem**: an Artinian simple ring is isomorphic to a matrix ring over a division ring. -/ theorem exists_ringEquiv_matrix_divisionRing : ∃ (n : ℕ) (_ : NeZero n) (D : Type u) (_ : DivisionRing D), Nonempty (R ≃+* Matrix (Fin n) (Fin n) D) := by have ⟨n, hn, I, _, ⟨e⟩⟩ := exists_ringEquiv_matrix_end_mulOpposite R classical exact ⟨n, hn, _, _, ⟨e⟩⟩ /-- The **Wedderburn–Artin Theorem**, algebra form: an Artinian simple algebra is isomorphic to a matrix algebra over the opposite of the endomorphism algebra of its simple module. -/ theorem exists_algEquiv_matrix_end_mulOpposite : ∃ (n : ℕ) (_ : NeZero n) (I : Ideal R) (_ : IsSimpleModule R I), Nonempty (R ≃ₐ[R₀] Matrix (Fin n) (Fin n) (Module.End R I)ᵐᵒᵖ) := by have ⟨n, hn, S, hS, ⟨e⟩⟩ := (isIsotypic R R).linearEquiv_fun refine ⟨n, hn, S, hS, ⟨.trans (.opOp R₀ R) <| .trans (.op ?_) (.symm .mopMatrix)⟩⟩ exact .trans (.moduleEndSelf R₀) <| .trans (e.algConj R₀) (endVecAlgEquivMatrixEnd ..) /-- The **Wedderburn–Artin Theorem**, algebra form: an Artinian simple algebra is isomorphic to a matrix algebra over a division algebra. -/ theorem exists_algEquiv_matrix_divisionRing : ∃ (n : ℕ) (_ : NeZero n) (D : Type u) (_ : DivisionRing D) (_ : Algebra R₀ D), Nonempty (R ≃ₐ[R₀] Matrix (Fin n) (Fin n) D) := by have ⟨n, hn, I, _, ⟨e⟩⟩ := exists_algEquiv_matrix_end_mulOpposite R₀ R classical exact ⟨n, hn, _, _, _, ⟨e⟩⟩ /-- The **Wedderburn–Artin Theorem**, algebra form, finite case: a finite Artinian simple algebra is isomorphic to a matrix algebra over a finite division algebra. -/ theorem exists_algEquiv_matrix_divisionRing_finite [Module.Finite R₀ R] : ∃ (n : ℕ) (_ : NeZero n) (D : Type u) (_ : DivisionRing D) (_ : Algebra R₀ D) (_ : Module.Finite R₀ D), Nonempty (R ≃ₐ[R₀] Matrix (Fin n) (Fin n) D) := by have ⟨n, hn, I, _, ⟨e⟩⟩ := exists_algEquiv_matrix_end_mulOpposite R₀ R have := Module.Finite.equiv e.toLinearEquiv classical exact ⟨n, hn, _, _, _, .of_surjective (Matrix.entryLinearMap R₀ _ (0 : Fin n) (0 : Fin n)) fun f ↦ ⟨fun _ _ ↦ f, rfl⟩, ⟨e⟩⟩ end IsSimpleRing namespace IsSemisimpleModule open Module (End) universe v variable (R) (M : Type v) [AddCommGroup M] [Module R₀ M] [Module R M] [IsScalarTower R₀ R M] [IsSemisimpleModule R M] [Module.Finite R M] theorem exists_end_algEquiv_pi_matrix_end : ∃ (n : ℕ) (S : Fin n → Submodule R M) (d : Fin n → ℕ), (∀ i, IsSimpleModule R (S i)) ∧ (∀ i, NeZero (d i)) ∧ Nonempty (End R M ≃ₐ[R₀] Π i, Matrix (Fin (d i)) (Fin (d i)) (End R (S i))) := by choose d pos S _ simple e using fun c : isotypicComponents R M ↦ (IsIsotypic.isotypicComponents c.2).submodule_linearEquiv_fun classical exact ⟨_, _, _, fun _ ↦ simple _, fun _ ↦ pos _, ⟨.trans (endAlgEquiv R₀ R M) <| .trans (.piCongrRight fun c ↦ ((e c).some.algConj R₀).trans (endVecAlgEquivMatrixEnd ..)) <| (.piCongrLeft' R₀ _ (Finite.equivFin _))⟩⟩ theorem exists_end_ringEquiv_pi_matrix_end : ∃ (n : ℕ) (S : Fin n → Submodule R M) (d : Fin n → ℕ), (∀ i, IsSimpleModule R (S i)) ∧ (∀ i, NeZero (d i)) ∧ Nonempty (End R M ≃+* Π i, Matrix (Fin (d i)) (Fin (d i)) (End R (S i))) := have ⟨n, S, d, hS, hd, ⟨e⟩⟩ := exists_end_algEquiv_pi_matrix_end ℕ R M; ⟨n, S, d, hS, hd, ⟨e⟩⟩ @[deprecated (since := "2025-11-16")] alias exists_end_algEquiv := exists_end_algEquiv_pi_matrix_end @[deprecated (since := "2025-11-16")] alias exists_end_ringEquiv := exists_end_ringEquiv_pi_matrix_end -- TODO: can also require D be in `Type u`, since every simple module is the quotient by an ideal. theorem exists_end_algEquiv_pi_matrix_divisionRing : ∃ (n : ℕ) (D : Fin n → Type v) (d : Fin n → ℕ) (_ : ∀ i, DivisionRing (D i)) (_ : ∀ i, Algebra R₀ (D i)), (∀ i, NeZero (d i)) ∧ Nonempty (End R M ≃ₐ[R₀] Π i, Matrix (Fin (d i)) (Fin (d i)) (D i)) := by have ⟨n, S, d, _, hd, ⟨e⟩⟩ := exists_end_algEquiv_pi_matrix_end R₀ R M classical exact ⟨n, _, d, inferInstance, inferInstance, hd, ⟨e⟩⟩ theorem exists_end_ringEquiv_pi_matrix_divisionRing : ∃ (n : ℕ) (D : Fin n → Type v) (d : Fin n → ℕ) (_ : ∀ i, DivisionRing (D i)), (∀ i, NeZero (d i)) ∧ Nonempty (End R M ≃+* Π i, Matrix (Fin (d i)) (Fin (d i)) (D i)) := have ⟨n, D, d, _, _, hd, ⟨e⟩⟩ := exists_end_algEquiv_pi_matrix_divisionRing ℕ R M ⟨n, D, d, _, hd, ⟨e⟩⟩ theorem _root_.IsSemisimpleRing.moduleEnd : IsSemisimpleRing (Module.End R M) := have ⟨_, _, _, _, _, ⟨e⟩⟩ := exists_end_ringEquiv_pi_matrix_divisionRing R M e.symm.isSemisimpleRing end IsSemisimpleModule namespace IsSemisimpleRing variable (R) [IsSemisimpleRing R] /-- The **Wedderburn–Artin Theorem**, algebra form: a semisimple algebra is isomorphic to a product of matrix algebras over the opposite of the endomorphism algebras of its simple modules. -/ theorem exists_algEquiv_pi_matrix_end_mulOpposite : ∃ (n : ℕ) (S : Fin n → Ideal R) (d : Fin n → ℕ), (∀ i, IsSimpleModule R (S i)) ∧ (∀ i, NeZero (d i)) ∧ Nonempty (R ≃ₐ[R₀] Π i, Matrix (Fin (d i)) (Fin (d i)) (Module.End R (S i))ᵐᵒᵖ) := have ⟨n, S, d, hS, hd, ⟨e⟩⟩ := IsSemisimpleModule.exists_end_algEquiv_pi_matrix_end R₀ R R ⟨n, S, d, hS, hd, ⟨.trans (.opOp R₀ R) <| .trans (.op <| .trans (.moduleEndSelf R₀) e) <| .trans (.piMulOpposite _ _) (.piCongrRight fun _ ↦ .symm .mopMatrix)⟩⟩ /-- The **Wedderburn–Artin Theorem**, algebra form: a semisimple algebra is isomorphic to a product of matrix algebras over division algebras. -/ theorem exists_algEquiv_pi_matrix_divisionRing : ∃ (n : ℕ) (D : Fin n → Type u) (d : Fin n → ℕ) (_ : ∀ i, DivisionRing (D i)) (_ : ∀ i, Algebra R₀ (D i)), (∀ i, NeZero (d i)) ∧ Nonempty (R ≃ₐ[R₀] Π i, Matrix (Fin (d i)) (Fin (d i)) (D i)) := by have ⟨n, S, d, _, hd, ⟨e⟩⟩ := exists_algEquiv_pi_matrix_end_mulOpposite R₀ R classical exact ⟨n, _, d, inferInstance, inferInstance, hd, ⟨e⟩⟩ /-- The **Wedderburn–Artin Theorem**, algebra form, finite case: a finite semisimple algebra is isomorphic to a product of matrix algebras over finite division algebras. -/ theorem exists_algEquiv_pi_matrix_divisionRing_finite [Module.Finite R₀ R] : ∃ (n : ℕ) (D : Fin n → Type u) (d : Fin n → ℕ) (_ : ∀ i, DivisionRing (D i)) (_ : ∀ i, Algebra R₀ (D i)) (_ : ∀ i, Module.Finite R₀ (D i)), (∀ i, NeZero (d i)) ∧ Nonempty (R ≃ₐ[R₀] Π i, Matrix (Fin (d i)) (Fin (d i)) (D i)) := by have ⟨n, D, d, _, _, hd, ⟨e⟩⟩ := exists_algEquiv_pi_matrix_divisionRing R₀ R have := Module.Finite.equiv e.toLinearEquiv refine ⟨n, D, d, _, _, fun i ↦ ?_, hd, ⟨e⟩⟩ let l := Matrix.entryLinearMap R₀ (D i) 0 0 ∘ₗ .proj (φ := fun i ↦ Matrix (Fin (d i)) (Fin (d i)) _) i exact .of_surjective l fun x ↦ ⟨fun j _ _ ↦ Function.update (fun _ ↦ 0) i x j, by simp [l]⟩ /-- The **Wedderburn–Artin Theorem**: a semisimple ring is isomorphic to a product of matrix rings over the opposite of the endomorphism rings of its simple modules. -/ theorem exists_ringEquiv_pi_matrix_end_mulOpposite : ∃ (n : ℕ) (D : Fin n → Ideal R) (d : Fin n → ℕ), (∀ i, IsSimpleModule R (D i)) ∧ (∀ i, NeZero (d i)) ∧ Nonempty (R ≃+* Π i, Matrix (Fin (d i)) (Fin (d i)) (Module.End R (D i))ᵐᵒᵖ) := have ⟨n, S, d, hS, hd, ⟨e⟩⟩ := exists_algEquiv_pi_matrix_end_mulOpposite ℕ R ⟨n, S, d, hS, hd, ⟨e⟩⟩ /-- The **Wedderburn–Artin Theorem**: a semisimple ring is isomorphic to a product of matrix rings over division rings. -/ theorem exists_ringEquiv_pi_matrix_divisionRing : ∃ (n : ℕ) (D : Fin n → Type u) (d : Fin n → ℕ) (_ : ∀ i, DivisionRing (D i)), (∀ i, NeZero (d i)) ∧ Nonempty (R ≃+* Π i, Matrix (Fin (d i)) (Fin (d i)) (D i)) := have ⟨n, D, d, _, _, hd, ⟨e⟩⟩ := exists_algEquiv_pi_matrix_divisionRing ℕ R ⟨n, D, d, _, hd, ⟨e⟩⟩ instance (n) [Fintype n] [DecidableEq n] : IsSemisimpleRing (Matrix n n R) := (isEmpty_or_nonempty n).elim (fun _ ↦ inferInstance) fun _ ↦ have ⟨_, _, _, _, _, ⟨e⟩⟩ := exists_ringEquiv_pi_matrix_divisionRing R (e.mapMatrix (m := n).trans Matrix.piRingEquiv).symm.isSemisimpleRing instance [IsSemisimpleRing R] : IsSemisimpleRing Rᵐᵒᵖ := have ⟨_, _, _, _, _, ⟨e⟩⟩ := exists_ringEquiv_pi_matrix_divisionRing R ((e.op.trans (.piMulOpposite _)).trans (.piCongrRight fun _ ↦ .symm .mopMatrix)).symm |>.isSemisimpleRing end IsSemisimpleRing theorem isSemisimpleRing_mulOpposite_iff : IsSemisimpleRing Rᵐᵒᵖ ↔ IsSemisimpleRing R := ⟨fun _ ↦ (RingEquiv.opOp R).symm.isSemisimpleRing, fun _ ↦ inferInstance⟩ /-- The existence part of the Artin–Wedderburn theorem. -/ theorem isSemisimpleRing_iff_pi_matrix_divisionRing : IsSemisimpleRing R ↔ ∃ (n : ℕ) (D : Fin n → Type u) (d : Fin n → ℕ) (_ : Π i, DivisionRing (D i)), Nonempty (R ≃+* Π i, Matrix (Fin (d i)) (Fin (d i)) (D i)) where mp _ := have ⟨n, D, d, _, _, e⟩ := IsSemisimpleRing.exists_ringEquiv_pi_matrix_divisionRing R ⟨n, D, d, _, e⟩ mpr := fun ⟨_, _, _, _, ⟨e⟩⟩ ↦ e.symm.isSemisimpleRing -- Need left-right symmetry of Jacobson radical proof_wanted IsSemiprimaryRing.mulOpposite [IsSemiprimaryRing R] : IsSemiprimaryRing Rᵐᵒᵖ proof_wanted isSemiprimaryRing_mulOpposite_iff : IsSemiprimaryRing Rᵐᵒᵖ ↔ IsSemiprimaryRing R -- A left Artinian ring is right Noetherian iff it is right Artinian. To be left as an `example`. proof_wanted IsArtinianRing.isNoetherianRing_iff_isArtinianRing_mulOpposite [IsArtinianRing R] : IsNoetherianRing Rᵐᵒᵖ ↔ IsArtinianRing Rᵐᵒᵖ
.lake/packages/mathlib/Mathlib/RingTheory/SimpleModule/InjectiveProjective.lean
import Mathlib.RingTheory.SimpleModule.Basic import Mathlib.Algebra.Module.Injective import Mathlib.Algebra.Module.Projective /-! If `R` is a semisimple ring, then any `R`-module is both injective and projective. -/ namespace Module variable (R : Type*) [Ring R] [IsSemisimpleRing R] (M : Type*) [AddCommGroup M] [Module R M] theorem injective_of_isSemisimpleRing : Module.Injective R M where out X Y _ _ _ _ f hf g := let ⟨h, comp⟩ := IsSemisimpleModule.extension_property f hf g ⟨h, fun _ ↦ by rw [← comp, LinearMap.comp_apply]⟩ theorem projective_of_isSemisimpleRing : Module.Projective R M := .of_lifting_property'' (IsSemisimpleModule.lifting_property · · _) @[deprecated (since := "2025-09-12")] alias injective_of_semisimple_ring := injective_of_isSemisimpleRing @[deprecated (since := "2025-09-12")] alias projective_of_semisimple_ring := projective_of_isSemisimpleRing end Module
.lake/packages/mathlib/Mathlib/RingTheory/Int/Basic.lean
import Mathlib.Algebra.EuclideanDomain.Basic import Mathlib.Algebra.EuclideanDomain.Int import Mathlib.Algebra.GCDMonoid.Nat import Mathlib.Data.Nat.Prime.Int import Mathlib.RingTheory.PrincipalIdealDomain /-! # Divisibility over ℤ This file collects results for the integers that use ring theory in their proofs or cases of ℤ being examples of structures in ring theory. ## Main statements * `Int.Prime.dvd_mul'`: A prime number dividing a product in ℤ divides at least one factor. * `Int.exists_prime_and_dvd`: Every non-unit integer has a prime divisor. * `Int.prime_iff_natAbs_prime`: Primality in ℤ corresponds to primality of its absolute value in ℕ. * `Int.span_natAbs`: The principal ideal generated by `a.natAbs` is equal to that of `a`. ## Tags prime, irreducible, integers, normalization monoid, gcd monoid, greatest common divisor -/ namespace Int theorem isCoprime_iff_nat_coprime {a b : ℤ} : IsCoprime a b ↔ Nat.Coprime a.natAbs b.natAbs := by rw [isCoprime_iff_gcd_eq_one, 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 [← isCoprime_iff_gcd_eq_one, ← 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] rcases Int.units_eq_one_or u with hu' | hu' <;> · rw [hu'] simp theorem sq_of_isCoprime {a b c : ℤ} (h : IsCoprime a b) (heq : a * b = c ^ 2) : ∃ a0 : ℤ, a = a0 ^ 2 ∨ a = -a0 ^ 2 := sq_of_gcd_eq_one (isCoprime_iff_gcd_eq_one.mp 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_coe_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 rcases 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) namespace Int theorem 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 prime_iff_natAbs_prime {k : ℤ} : Prime k ↔ Nat.Prime k.natAbs := (Int.associated_natAbs k).prime_iff.trans Nat.prime_iff_prime_int.symm instance instDecidablePredPrime : DecidablePred (Prime : ℤ → Prop) := fun m ↦ decidable_of_iff (Nat.Prime m.natAbs) prime_iff_natAbs_prime.symm instance (priority := 100) : DecidablePred (Irreducible : ℤ → Prop) := fun m ↦ decidable_of_iff (Prime m) irreducible_iff_prime.symm 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⟩ 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 (c := c) hab.symm hk (by rwa [mul_comm] at h) 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⟩ end Int
.lake/packages/mathlib/Mathlib/RingTheory/Norm/Transitivity.lean
import Mathlib.LinearAlgebra.Matrix.Block import Mathlib.LinearAlgebra.Matrix.Charpoly.Coeff import Mathlib.RingTheory.Norm.Defs import Mathlib.RingTheory.PolynomialAlgebra import Mathlib.FieldTheory.IntermediateField.Adjoin.Defs import Mathlib.FieldTheory.IntermediateField.Algebraic import Mathlib.FieldTheory.IsAlgClosed.AlgebraicClosure import Mathlib.RingTheory.Norm.Basic import Mathlib.FieldTheory.Galois.Basic /-! # Transitivity of algebra norm 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`. ## References * [silvester2000] Silvester, *Determinants of Block Matrices*, The Mathematical Gazette (2000). -/ variable {R S A n m : Type*} [CommRing R] [CommRing S] variable (M : Matrix m m S) [DecidableEq m] [DecidableEq n] (k : m) open Matrix Polynomial namespace Algebra.Norm.Transitivity /-- Given a ((m-1)+1)x((m-1)+1) block matrix `M = [[A,b],[c,d]]`, `auxMat M k` is the auxiliary matrix `[[dI,0],[-c,1]]`. `k` corresponds to the last row/column of the matrix. -/ def auxMat : Matrix m m S := of fun i j ↦ if j = k then if i = k then 1 else 0 else if i = k then -M k j else if i = j then M k k else 0 /-- `aux M k` is lower triangular. -/ lemma auxMat_blockTriangular : (auxMat M k).BlockTriangular (· ≠ k) := fun i j lt ↦ by simp_rw [lt_iff_not_ge, le_Prop_eq, Classical.not_imp, not_not] at lt rw [auxMat, of_apply, if_pos lt.2, if_neg lt.1] lemma auxMat_toSquareBlock_ne : (auxMat M k).toSquareBlock (· ≠ k) True = M k k • 1 := by ext i j simp [auxMat, toSquareBlock_def, if_neg (of_eq_true i.2), if_neg (of_eq_true j.2), Matrix.one_apply, Subtype.ext_iff] lemma auxMat_toSquareBlock_eq : (auxMat M k).toSquareBlock (· ≠ k) False = 1 := by ext ⟨i, hi⟩ ⟨j, hj⟩ rw [eq_iff_iff, iff_false, not_not] at hi hj simp [auxMat, toSquareBlock_def, if_pos hi, if_pos hj, Matrix.one_apply, if_pos (hj ▸ hi)] variable [Fintype m] /-- `M * aux M k` is upper triangular. -/ lemma mul_auxMat_blockTriangular : (M * auxMat M k).BlockTriangular (· = k) := fun i j lt ↦ by simp_rw [lt_iff_not_ge, le_Prop_eq, Classical.not_imp] at lt simp_rw [Matrix.mul_apply, auxMat, of_apply, if_neg lt.2, mul_ite, mul_neg, mul_zero] rw [Finset.sum_ite, Finset.filter_eq', if_pos (Finset.mem_univ _), Finset.sum_singleton, Finset.sum_ite_eq', if_pos, lt.1, mul_comm, neg_add_cancel] exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, lt.2⟩ /-- The lower-right corner of `M * aux M k` is the same as the corner of `M`. -/ lemma mul_auxMat_corner : (M * auxMat M k) k k = M k k := by simp [Matrix.mul_apply, auxMat] lemma mul_auxMat_toSquareBlock_eq : (M * auxMat M k).toSquareBlock (· = k) True = M k k • 1 := by ext ⟨i, hi⟩ ⟨j, hj⟩ rw [eq_iff_iff, iff_true] at hi hj simp [toSquareBlock_def, hi, hj, mul_auxMat_corner] set_option quotPrecheck false in /-- The upper-left block of `M * aux M k`. -/ scoped notation "mulAuxMatBlock" => (M * auxMat M k).toSquareBlock (· = k) False lemma det_mul_corner_pow : M.det * M k k ^ (Fintype.card m - 1) = M k k * (mulAuxMatBlock).det := by trans (M * auxMat M k).det · simp [det_mul, (auxMat_blockTriangular M k).det_fintype, auxMat_toSquareBlock_ne, auxMat_toSquareBlock_eq] rw [(mul_auxMat_blockTriangular M k).det_fintype, Fintype.prod_Prop, mul_auxMat_toSquareBlock_eq] simp_rw [det_smul_of_tower, eq_iff_iff, iff_true, Fintype.card_unique, pow_one, det_one, smul_eq_mul, mul_one] -- `Decidable (P = Q)` diamond induced by `Prop.linearOrder`, which is classical, when `P` and `Q` -- are themselves decidable. convert rfl /-- A matrix with X added to the corner. -/ noncomputable def cornerAddX : Matrix m m S[X] := (diagonal fun i ↦ if i = k then X else 0) + M.map C variable [Fintype n] (f : S →+* Matrix n n R) omit [Fintype m] in lemma polyToMatrix_cornerAddX : f.polyToMatrix (cornerAddX M k k k) = (-f (M k k)).charmatrix := by simp [cornerAddX, Matrix.add_apply, charmatrix, RingHom.polyToMatrix, -AlgEquiv.symm_toRingEquiv, map_neg] lemma eval_zero_det_det : eval 0 (f.polyToMatrix (cornerAddX M k).det).det = (f M.det).det := by rw [← coe_evalRingHom, RingHom.map_det, ← RingHom.comp_apply, evalRingHom_mapMatrix_comp_polyToMatrix, f.comp_apply, RingHom.map_det] congr; ext; simp [cornerAddX, diagonal, apply_ite] lemma eval_zero_comp_det : eval 0 (comp m m n n R[X] <| (cornerAddX M k).map f.polyToMatrix).det = (comp m m n n R <| M.map f).det := by simp_rw [← coe_evalRingHom, RingHom.map_det, ← compRingEquiv_apply, ← RingEquiv.coe_toRingHom, ← RingHom.mapMatrix_apply, ← RingHom.comp_apply, ← RingHom.comp_assoc, evalRingHom_mapMatrix_comp_compRingEquiv, RingHom.comp_assoc, RingHom.mapMatrix_comp, evalRingHom_mapMatrix_comp_polyToMatrix, ← RingHom.mapMatrix_comp, RingHom.comp_apply] congr with i j simp [cornerAddX, diagonal, apply_ite] theorem comp_det_mul_pow : ((M.map f).comp m m n n R).det * (f (M k k)).det ^ (Fintype.card m - 1) = (f (M k k)).det * (((mulAuxMatBlock).map f).comp _ _ n n R).det := by trans (((M * auxMat M k).map f).comp m m n n R).det · simp_rw [← f.mapMatrix_apply, ← compRingEquiv_apply, map_mul, det_mul, f.mapMatrix_apply, compRingEquiv_apply, ((auxMat_blockTriangular M k).map f).comp.det_fintype, Fintype.prod_Prop, comp_toSquareBlock (b := (· ≠ k)), det_reindex_self, map_toSquareBlock, auxMat_toSquareBlock_eq, auxMat_toSquareBlock_ne, smul_one_eq_diagonal, ← diagonal_one, diagonal_map (map_zero _), comp_diagonal, det_reindex_self] simp · simp_rw [((mul_auxMat_blockTriangular M k).map f).comp.det_fintype, Fintype.prod_Prop, comp_toSquareBlock (b := (· = k)), det_reindex_self, map_toSquareBlock, mul_auxMat_toSquareBlock_eq, smul_one_eq_diagonal, diagonal_map (map_zero _), comp_diagonal, det_reindex_self] simp variable {M f} in lemma det_det_aux (ih : ∀ M, (f (det M)).det = ((M.map f).comp {a // (a = k) = False} _ n n R).det) : ((f M.det).det - ((M.map f).comp m m n n R).det) * (f (M k k)).det ^ (Fintype.card m - 1) = 0 := by rw [sub_mul, comp_det_mul_pow, ← det_pow, ← map_pow, ← det_mul, ← map_mul, det_mul_corner_pow, map_mul, det_mul, ih, sub_self] end Algebra.Norm.Transitivity open Algebra.Norm.Transitivity /-- The main result in Silvester's paper *Determinants of Block Matrices*: the determinant of a block matrix with commuting, equal-sized, square blocks can be computed by taking determinants twice in a row: first take the determinant over the commutative ring generated by the blocks (`S` here), then take the determinant over the base ring. -/ theorem Matrix.det_det [Fintype m] [Fintype n] (f : S →+* Matrix n n R) : (f M.det).det = ((M.map f).comp m m n n R).det := by induction l : Fintype.card m generalizing R S m with | zero => rw [Fintype.card_eq_zero_iff] at l simp_rw [Matrix.det_isEmpty, map_one, det_one] | succ l ih => have ⟨k⟩ := Fintype.card_pos_iff.mp (Nat.lt_of_sub_eq_succ l) let f' := f.polyToMatrix let M' := cornerAddX M k have : (f' M'.det).det = ((M'.map f').comp m m n n R[X]).det := by refine sub_eq_zero.mp <| mem_nonZeroDivisors_iff_right.mp (pow_mem ?_ _) _ (det_det_aux k fun M ↦ ih _ _ <| by grind [Fintype.card_subtype_compl, Fintype.card_unique]) rw [polyToMatrix_cornerAddX, ← charpoly] exact (Matrix.charpoly_monic _).mem_nonZeroDivisors rw [← eval_zero_det_det, congr_arg (eval 0) this, eval_zero_comp_det] variable [Algebra R S] [Module.Free R S] theorem LinearMap.det_restrictScalars [AddCommGroup A] [Module R A] [Module S A] [IsScalarTower R S A] [Module.Free S A] {f : A →ₗ[S] A} : (f.restrictScalars R).det = Algebra.norm R f.det := by classical nontriviality R nontriviality A have := Module.nontrivial S A let ⟨ιS, bS⟩ := Module.Free.exists_basis (R := R) (M := S) let ⟨ιA, bA⟩ := Module.Free.exists_basis (R := S) (M := A) have := bS.index_nonempty have := bA.index_nonempty cases fintypeOrInfinite ιS; swap · rw [Algebra.norm_eq_one_of_not_module_finite (Module.not_finite_of_infinite_basis bS), det_eq_one_of_not_module_finite (Module.not_finite_of_infinite_basis (bS.smulTower bA))] cases fintypeOrInfinite ιA; swap · rw [det_eq_one_of_not_module_finite (Module.not_finite_of_infinite_basis bA), map_one, det_eq_one_of_not_module_finite (Module.not_finite_of_infinite_basis (bS.smulTower bA))] rw [Algebra.norm_eq_matrix_det bS, ← AlgHom.coe_toRingHom, ← det_toMatrix bA, det_det, ← det_toMatrix (bS.smulTower' bA), restrictScalars_toMatrix, RingHom.coe_coe] /-- Let A/S/R be a tower of finite free tower of rings (with R and S commutative). Then $\text{Norm}_{A/R} = \text{Norm}_{A/S} \circ \text{Norm}_{S/R}$. -/ theorem Algebra.norm_norm {A} [Ring A] [Algebra R A] [Algebra S A] [IsScalarTower R S A] [Module.Free S A] {a : A} : norm R (norm S a) = norm R a := by rw [norm_apply S, norm_apply R a, ← LinearMap.det_restrictScalars]; rfl variable {L : Type*} (K : Type*) [Field K] [Field L] [Algebra K L] open Module IntermediateField AdjoinSimple namespace Algebra theorem isIntegral_norm [Algebra R L] [Algebra R K] [IsScalarTower R K L] {x : L} (hx : IsIntegral R x) : IsIntegral R (norm K x) := by by_cases h : FiniteDimensional K L swap · simpa [norm_eq_one_of_not_module_finite h] using isIntegral_one let F := K⟮x⟯ rw [← norm_norm (S := F), ← coe_gen K x, ← IntermediateField.algebraMap_apply, norm_algebraMap_of_basis (Module.Free.chooseBasis F L) (gen K x), map_pow] apply IsIntegral.pow rw [← isIntegral_algebraMap_iff (algebraMap K (AlgebraicClosure F)).injective, norm_gen_eq_prod_roots _ (IsAlgClosed.splits_codomain _)] refine IsIntegral.multiset_prod (fun y hy ↦ ⟨minpoly R x, minpoly.monic hx, ?_⟩) suffices (aeval y) ((minpoly R x).map (algebraMap R K)) = 0 by simpa obtain ⟨P, hP⟩ := minpoly.dvd K x (show aeval x ((minpoly R x).map (algebraMap R K)) = 0 by simp) simp [hP, aeval_mul, (mem_aroots'.mp hy).2] theorem norm_eq_norm_adjoin (x : L) : norm K x = norm K (AdjoinSimple.gen K x) ^ finrank K⟮x⟯ L := by by_cases h : FiniteDimensional K L swap · rw [norm_eq_one_of_not_module_finite h] by_cases hx : IsIntegral K x · have h₁ : ¬ FiniteDimensional K⟮x⟯ L := fun H ↦ h <| by have : FiniteDimensional K K⟮x⟯ := adjoin.finiteDimensional hx exact Finite.trans K⟮x⟯ L simp [finrank_of_not_finite h₁] · rw [norm_eq_one_of_not_module_finite] · simp · refine fun H ↦ hx ?_ rw [← isIntegral_gen] exact IsIntegral.isIntegral (gen K x) let F := K⟮x⟯ nth_rw 1 [← coe_gen K x] rw [← norm_norm (S := F), ← IntermediateField.algebraMap_apply, norm_algebraMap_of_basis (Module.Free.chooseBasis F L) (gen K x), map_pow, finrank_eq_card_chooseBasisIndex] variable (F E : Type*) [Field F] [Algebra K F] [Field E] [Algebra K E] variable {K} in theorem norm_eq_prod_roots {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] variable [FiniteDimensional K L] /-- 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 [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 [IsGalois K L] (x : L) : algebraMap K L (norm K x) = ∏ σ : Gal(L/K), σ x := by apply FaithfulSMul.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, algebraMap_self, RingHom.id_apply] end Algebra
.lake/packages/mathlib/Mathlib/RingTheory/Norm/Basic.lean
import Mathlib.RingTheory.Norm.Defs import Mathlib.FieldTheory.PrimitiveElement import Mathlib.LinearAlgebra.Matrix.Charpoly.Minpoly import Mathlib.LinearAlgebra.Matrix.ToLinearEquiv /-! # 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 Module 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, coeff_zero_eq_prod_roots_of_monic_of_splits (this.map _) ((splits_id_iff_splits _).2 hf), this.natDegree_map, map_pow, ← mul_assoc, ← mul_pow] simp only [map_neg, 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 swap · rintro rfl; exact norm_zero · let b := Module.Free.chooseBasis R S let decEq := 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 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 (b.finiteDimensional_of_finite) · 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] <;> simp only [AdjoinSimple.algebraMap_gen _ _, 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 (.map hfx) · intro x; rfl · intro σ; simp only [PowerBasis.liftEquiv'_apply_coe] 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'] 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, 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'] intro c x apply e₂.symm.injective simp only [RingHom.coe_comp, RingHom.coe_coe, Function.comp_apply, map_mul, RingEquiv.symm_apply_apply, commutes] end EqProdEmbeddings end Algebra
.lake/packages/mathlib/Mathlib/RingTheory/Norm/Defs.lean
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 : Type*} [CommRing R] [Ring S] variable [Algebra R S] variable {K : Type*} [Field K] variable {ι : Type w} open Module 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`. -/ @[stacks 0BIF "Norm"] 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 @[simp] theorem norm_self : Algebra.norm R = MonoidHom.id R := by ext simp [norm_apply] 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] assumption_mod_cast end Algebra
.lake/packages/mathlib/Mathlib/RingTheory/Congruence/Opposite.lean
import Mathlib.RingTheory.Congruence.Basic import Mathlib.GroupTheory.Congruence.Opposite /-! # Congruences on the opposite ring This file defines the order isomorphism between the congruences on a ring `R` and the congruences on the opposite ring `Rᵐᵒᵖ`. -/ variable {R : Type*} [Add R] [Mul R] namespace RingCon /-- If `c` is a `RingCon R`, then `(a, b) ↦ c b.unop a.unop` is a `RingCon Rᵐᵒᵖ`. -/ def op (c : RingCon R) : RingCon Rᵐᵒᵖ where __ := c.toCon.op mul' h1 h2 := c.toCon.op.mul h1 h2 add' h1 h2 := c.add h1 h2 lemma op_iff {c : RingCon R} {x y : Rᵐᵒᵖ} : c.op x y ↔ c y.unop x.unop := Iff.rfl /-- If `c` is a `RingCon Rᵐᵒᵖ`, then `(a, b) ↦ c b.op a.op` is a `RingCon R`. -/ def unop (c : RingCon Rᵐᵒᵖ) : RingCon R where __ := c.toCon.unop mul' h1 h2 := c.toCon.unop.mul h1 h2 add' h1 h2 := c.add h1 h2 lemma unop_iff {c : RingCon Rᵐᵒᵖ} {x y : R} : c.unop x y ↔ c (.op y) (.op x) := Iff.rfl /-- The congruences of a ring `R` biject to the congruences of the opposite ring `Rᵐᵒᵖ`. -/ @[simps] def opOrderIso : RingCon R ≃o RingCon Rᵐᵒᵖ where toFun := op invFun := unop map_rel_iff' {c d} := by rw [le_def, le_def]; constructor <;> intro h _ _ h' <;> exact h h' end RingCon