path
stringlengths
11
71
content
stringlengths
75
124k
RingTheory\FreeRing.lean
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Johan Commelin -/ import Mathlib.GroupTheory.FreeAbelianGroup /-! # Free rings The theory of the free ring over a type. ## Main definitions * `FreeRing α` : the free (not commutative in general) ring over a type. * `lift (f : α → R)` : the ring hom `FreeRing α →+* R` induced by `f`. * `map (f : α → β)` : the ring hom `FreeRing α →+* FreeRing β` induced by `f`. ## Implementation details `FreeRing α` is implemented as the free abelian group over the free monoid on `α`. ## Tags free ring -/ universe u v /-- The free ring over a type `α`. -/ def FreeRing (α : Type u) : Type u := FreeAbelianGroup <| FreeMonoid α instance (α : Type u) : Ring (FreeRing α) := FreeAbelianGroup.ring _ instance (α : Type u) : Inhabited (FreeRing α) := by dsimp only [FreeRing] infer_instance namespace FreeRing variable {α : Type u} /-- The canonical map from α to `FreeRing α`. -/ def of (x : α) : FreeRing α := FreeAbelianGroup.of (FreeMonoid.of x) theorem of_injective : Function.Injective (of : α → FreeRing α) := FreeAbelianGroup.of_injective.comp FreeMonoid.of_injective @[elab_as_elim, induction_eliminator] protected theorem induction_on {C : FreeRing α → Prop} (z : FreeRing α) (hn1 : C (-1)) (hb : ∀ b, C (of b)) (ha : ∀ x y, C x → C y → C (x + y)) (hm : ∀ x y, C x → C y → C (x * y)) : C z := have hn : ∀ x, C x → C (-x) := fun x ih => neg_one_mul x ▸ hm _ _ hn1 ih have h1 : C 1 := neg_neg (1 : FreeRing α) ▸ hn _ hn1 FreeAbelianGroup.induction_on z (add_left_neg (1 : FreeRing α) ▸ ha _ _ hn1 h1) (fun m => List.recOn m h1 fun a m ih => by -- Porting note: in mathlib, convert was not necessary, `exact hm _ _ (hb a) ih` worked fine convert hm _ _ (hb a) ih rw [of, ← FreeAbelianGroup.of_mul] rfl) (fun m ih => hn _ ih) ha section lift variable {R : Type v} [Ring R] (f : α → R) /-- The ring homomorphism `FreeRing α →+* R` induced from a map `α → R`. -/ def lift : (α → R) ≃ (FreeRing α →+* R) := FreeMonoid.lift.trans FreeAbelianGroup.liftMonoid @[simp] theorem lift_of (x : α) : lift f (of x) = f x := congr_fun (lift.left_inv f) x @[simp] theorem lift_comp_of (f : FreeRing α →+* R) : lift (f ∘ of) = f := lift.right_inv f @[ext] theorem hom_ext ⦃f g : FreeRing α →+* R⦄ (h : ∀ x, f (of x) = g (of x)) : f = g := lift.symm.injective (funext h) end lift variable {β : Type v} (f : α → β) /-- The canonical ring homomorphism `FreeRing α →+* FreeRing β` generated by a map `α → β`. -/ def map : FreeRing α →+* FreeRing β := lift <| of ∘ f @[simp] theorem map_of (x : α) : map f (of x) = of (f x) := lift_of _ _ end FreeRing
RingTheory\Generators.lean
/- Copyright (c) 2024 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.RingTheory.Ideal.Cotangent import Mathlib.RingTheory.Localization.Away.Basic import Mathlib.RingTheory.MvPolynomial.Tower import Mathlib.RingTheory.TensorProduct.Basic /-! # Generators of algebras ## Main definition - `Algebra.Generators`: A family of generators of a `R`-algebra `S` consists of 1. `vars`: The type of variables. 2. `val : vars → S`: The assignment of each variable to a value. 3. `σ`: A set-theoretic section of the induced `R`-algebra homomorphism `R[X] → S`, where we write `R[X]` for `R[vars]`. - `Algebra.Generators.Hom`: Given a commuting square ``` R --→ P = R[X] ---→ S | | ↓ ↓ R' -→ P' = R'[X'] → S ``` A hom between `P` and `P'` is an assignment `X → P'` such that the arrows commute. - `Algebra.Generators.Cotangent`: The cotangent space wrt `P = R[X] → S`, i.e. the space `I/I²` with `I` being the kernel of the presentation. -/ universe w u v open TensorProduct MvPolynomial variable (R : Type u) (S : Type v) [CommRing R] [CommRing S] [Algebra R S] /-- A family of generators of a `R`-algebra `S` consists of 1. `vars`: The type of variables. 2. `val : vars → S`: The assignment of each variable to a value in `S`. 3. `σ`: A section of `R[X] → S`. -/ structure Algebra.Generators where /-- The type of variables. -/ vars : Type w /-- The assignment of each variable to a value in `S`. -/ val : vars → S /-- A section of `R[X] → S`. -/ σ' : S → MvPolynomial vars R aeval_val_σ' : ∀ s, aeval val (σ' s) = s namespace Algebra.Generators variable {R S} variable (P : Generators.{w} R S) /-- The polynomial ring wrt a family of generators. -/ protected abbrev Ring : Type (max w u) := MvPolynomial P.vars R /-- The designated section of wrt a family of generators. -/ def σ : S → P.Ring := P.σ' /-- See Note [custom simps projection] -/ def Simps.σ : S → P.Ring := P.σ initialize_simps_projections Algebra.Generators (σ' → σ) @[simp] lemma aeval_val_σ (s) : aeval P.val (P.σ s) = s := P.aeval_val_σ' s instance : Algebra P.Ring S := (aeval P.val).toAlgebra noncomputable instance {R₀} [CommRing R₀] [Algebra R₀ R] [Algebra R₀ S] [IsScalarTower R₀ R S] : IsScalarTower R₀ P.Ring S := IsScalarTower.of_algebraMap_eq' ((aeval (R := R) P.val).comp_algebraMap_of_tower R₀).symm lemma algebraMap_eq : algebraMap P.Ring S = ↑(aeval (R := R) P.val) := rfl @[simp] lemma algebraMap_apply (x) : algebraMap P.Ring S x = aeval (R := R) P.val x := rfl @[simp] lemma σ_smul (x y) : P.σ x • y = x * y := by rw [Algebra.smul_def, algebraMap_apply, aeval_val_σ] lemma σ_injective : P.σ.Injective := by intro x y e rw [← P.aeval_val_σ x, ← P.aeval_val_σ y, e] lemma algebraMap_surjective : Function.Surjective (algebraMap P.Ring S) := (⟨_, P.aeval_val_σ ·⟩) section Construction /-- Construct `Generators` from an assignment `I → S` such that `R[X] → S` is surjective. -/ @[simps val, simps (config := .lemmasOnly) vars] noncomputable def ofSurjective {vars} (val : vars → S) (h : Function.Surjective (aeval (R := R) val)) : Generators R S where vars := vars val := val σ' x := (h x).choose aeval_val_σ' x := (h x).choose_spec /-- Construct `Generators` from an assignment `I → S` such that `R[X] → S` is surjective. -/ noncomputable def ofAlgHom {I} (f : MvPolynomial I R →ₐ[R] S) (h : Function.Surjective f) : Generators R S := ofSurjective (f ∘ X) (by rwa [show aeval (f ∘ X) = f by ext; simp]) /-- Construct `Generators` from a family of generators of `S`. -/ noncomputable def ofSet {s : Set S} (hs : Algebra.adjoin R s = ⊤) : Generators R S := by refine ofSurjective (Subtype.val : s → S) ?_ rwa [← Algebra.range_top_iff_surjective, ← Algebra.adjoin_range_eq_range_aeval, Subtype.range_coe_subtype, Set.setOf_mem_eq] variable (R S) in /-- The `Generators` containing the whole algebra, which induces the canonical map `R[S] → S`. -/ @[simps] noncomputable def self : Generators R S where vars := S val := _root_.id σ' := X aeval_val_σ' := aeval_X _ section Localization variable (r : R) [IsLocalization.Away r S] /-- If `S` is the localization of `R` away from `r`, we obtain a canonical generator mapping to the inverse of `r`. -/ @[simps val, simps (config := .lemmasOnly) vars σ] noncomputable def localizationAway : Generators R S where vars := Unit val _ := IsLocalization.Away.invSelf r σ' s := letI a : R := (IsLocalization.Away.sec r s).1 letI n : ℕ := (IsLocalization.Away.sec r s).2 C a * X () ^ n aeval_val_σ' s := by rw [_root_.map_mul, algHom_C, map_pow, aeval_X] simp only [← IsLocalization.Away.sec_spec, map_pow, IsLocalization.Away.invSelf] rw [← IsLocalization.mk'_pow, one_pow, ← IsLocalization.mk'_one (M := Submonoid.powers r) S r] rw [← IsLocalization.mk'_pow, one_pow, mul_assoc, ← IsLocalization.mk'_mul] rw [mul_one, one_mul, IsLocalization.mk'_pow] simp end Localization variable {T} [CommRing T] [Algebra R T] [Algebra S T] [IsScalarTower R S T] /-- Given two families of generators `S[X] → T` and `R[Y] → S`, we may constuct the family of generators `R[X, Y] → T`. -/ @[simps val, simps (config := .lemmasOnly) vars σ] noncomputable def comp (Q : Generators S T) (P : Generators R S) : Generators R T where vars := Q.vars ⊕ P.vars val := Sum.elim Q.val (algebraMap S T ∘ P.val) σ' x := (Q.σ x).sum (fun n r ↦ rename Sum.inr (P.σ r) * monomial (n.mapDomain Sum.inl) 1) aeval_val_σ' s := by have (x : P.Ring) : aeval (algebraMap S T ∘ P.val) x = algebraMap S T (aeval P.val x) := by rw [map_aeval, aeval_def, coe_eval₂Hom, ← IsScalarTower.algebraMap_eq, Function.comp] conv_rhs => rw [← Q.aeval_val_σ s, ← (Q.σ s).sum_single] simp only [map_finsupp_sum, _root_.map_mul, aeval_rename, Sum.elim_comp_inr, this, aeval_val_σ, aeval_monomial, _root_.map_one, Finsupp.prod_mapDomain_index_inj Sum.inl_injective, Sum.elim_inl, one_mul, single_eq_monomial] variable (S) in /-- If `R → S → T` is a tower of algebras, a family of generators `R[X] → T` gives a family of generators `S[X] → T`. -/ @[simps val, simps (config := .lemmasOnly) vars] noncomputable def extendScalars (P : Generators R T) : Generators S T where vars := P.vars val := P.val σ' x := map (algebraMap R S) (P.σ x) aeval_val_σ' s := by simp [@aeval_def S, ← IsScalarTower.algebraMap_eq, ← @aeval_def R] /-- If `P` is a family of generators of `S` over `R` and `T` is an `R`-algebra, we obtain a natural family of generators of `T ⊗[R] S` over `T`. -/ @[simps! val, simps! (config := .lemmasOnly) vars] noncomputable def baseChange {T} [CommRing T] [Algebra R T] (P : Generators R S) : Generators T (T ⊗[R] S) := by apply Generators.ofSurjective (fun x ↦ 1 ⊗ₜ[R] P.val x) intro x induction x using TensorProduct.induction_on with | zero => exact ⟨0, map_zero _⟩ | tmul a b => let X := P.σ b use a • MvPolynomial.map (algebraMap R T) X simp only [LinearMapClass.map_smul, X, aeval_map_algebraMap] have : ∀ y : P.Ring, aeval (fun x ↦ (1 ⊗ₜ[R] P.val x : T ⊗[R] S)) y = 1 ⊗ₜ aeval (fun x ↦ P.val x) y := by intro y induction y using MvPolynomial.induction_on with | h_C a => rw [aeval_C, aeval_C, TensorProduct.algebraMap_apply, algebraMap_eq_smul_one, smul_tmul, algebraMap_eq_smul_one] | h_add p q hp hq => simp [map_add, tmul_add, hp, hq] | h_X p i hp => simp [hp] rw [this, P.aeval_val_σ, smul_tmul', smul_eq_mul, mul_one] | add x y ex ey => obtain ⟨a, ha⟩ := ex obtain ⟨b, hb⟩ := ey use (a + b) rw [map_add, ha, hb] end Construction variable {R' S'} [CommRing R'] [CommRing S'] [Algebra R' S'] (P' : Generators R' S') variable {R'' S''} [CommRing R''] [CommRing S''] [Algebra R'' S''] (P'' : Generators R'' S'') section Hom section variable [Algebra R R'] [Algebra R' R''] [Algebra R' S''] variable [Algebra S S'] [Algebra S' S''] [Algebra S S''] /-- Given a commuting square R --→ P = R[X] ---→ S | | ↓ ↓ R' -→ P' = R'[X'] → S A hom between `P` and `P'` is an assignment `I → P'` such that the arrows commute. Also see `Algebra.Generators.Hom.equivAlgHom`. -/ @[ext] structure Hom where /-- The assignment of each variable in `I` to a value in `P' = R'[X']`. -/ val : P.vars → P'.Ring aeval_val : ∀ i, aeval P'.val (val i) = algebraMap S S' (P.val i) attribute [simp] Hom.aeval_val variable {P P'} /-- A hom between two families of generators gives an algebra homomorphism between the polynomial rings. -/ noncomputable def Hom.toAlgHom (f : Hom P P') : P.Ring →ₐ[R] P'.Ring := MvPolynomial.aeval f.val variable [Algebra R S'] [IsScalarTower R R' S'] [IsScalarTower R S S'] in @[simp] lemma Hom.algebraMap_toAlgHom (f : Hom P P') (x) : MvPolynomial.aeval P'.val (f.toAlgHom x) = algebraMap S S' (MvPolynomial.aeval P.val x) := by suffices ((MvPolynomial.aeval P'.val).restrictScalars R).comp f.toAlgHom = (IsScalarTower.toAlgHom R S S').comp (MvPolynomial.aeval P.val) from DFunLike.congr_fun this x apply MvPolynomial.algHom_ext intro i simp [Hom.toAlgHom] @[simp] lemma Hom.toAlgHom_X (f : Hom P P') (i) : f.toAlgHom (.X i) = f.val i := MvPolynomial.aeval_X f.val i lemma Hom.toAlgHom_C (f : Hom P P') (r) : f.toAlgHom (.C r) = .C (algebraMap _ _ r) := MvPolynomial.aeval_C f.val r lemma Hom.toAlgHom_monomial (f : Generators.Hom P P') (v r) : f.toAlgHom (monomial v r) = r • v.prod (f.val · ^ ·) := by rw [toAlgHom, aeval_monomial, Algebra.smul_def] variable [Algebra R S'] [IsScalarTower R R' S'] [IsScalarTower R S S'] in /-- Giving a hom between two families of generators is equivalent to giving an algebra homomorphism between the polynomial rings. -/ @[simps] noncomputable def Hom.equivAlgHom : Hom P P' ≃ { f : P.Ring →ₐ[R] P'.Ring // ∀ x, aeval P'.val (f x) = algebraMap S S' (aeval P.val x) } where toFun f := ⟨f.toAlgHom, f.algebraMap_toAlgHom⟩ invFun f := ⟨fun i ↦ f.1 (.X i), fun i ↦ by simp [f.2]⟩ left_inv f := by ext; simp right_inv f := by ext; simp variable (P P') /-- The hom from `P` to `P'` given by the designated section of `P'`. -/ @[simps] def defaultHom : Hom P P' := ⟨P'.σ ∘ algebraMap S S' ∘ P.val, fun x ↦ by simp⟩ instance : Inhabited (Hom P P') := ⟨defaultHom P P'⟩ /-- The identity hom. -/ @[simps] protected noncomputable def Hom.id : Hom P P := ⟨X, by simp⟩ @[simp] lemma Hom.toAlgHom_id : Hom.toAlgHom (.id P) = AlgHom.id _ _ := by ext1; simp variable {P P' P''} /-- The composition of two homs. -/ @[simps] noncomputable def Hom.comp [IsScalarTower R' R'' S''] [IsScalarTower R' S' S''] [IsScalarTower S S' S''] (f : Hom P' P'') (g : Hom P P') : Hom P P'' where val x := aeval f.val (g.val x) aeval_val x := by simp only rw [IsScalarTower.algebraMap_apply S S' S'', ← g.aeval_val] induction g.val x using MvPolynomial.induction_on with | h_C r => simp [← IsScalarTower.algebraMap_apply] | h_add x y hx hy => simp only [map_add, hx, hy] | h_X p i hp => simp only [_root_.map_mul, hp, aeval_X, aeval_val] @[simp] lemma Hom.comp_id [Algebra R S'] [IsScalarTower R R' S'] [IsScalarTower R S S'] (f : Hom P P') : f.comp (Hom.id P) = f := by ext; simp end @[simp] lemma Hom.id_comp [Algebra S S'] (f : Hom P P') : (Hom.id P').comp f = f := by ext; simp [Hom.id, aeval_X_left] variable [Algebra R R'] [Algebra R' R''] [Algebra R' S''] variable [Algebra S S'] [Algebra S' S''] [Algebra S S''] @[simp] lemma Hom.toAlgHom_comp_apply [Algebra R R''] [IsScalarTower R R' R''] [IsScalarTower R' R'' S''] [IsScalarTower R' S' S''] [IsScalarTower S S' S''] (f : Hom P P') (g : Hom P' P'') (x) : (g.comp f).toAlgHom x = g.toAlgHom (f.toAlgHom x) := by induction x using MvPolynomial.induction_on with | h_C r => simp only [← MvPolynomial.algebraMap_eq, AlgHom.map_algebraMap] | h_add x y hx hy => simp only [map_add, hx, hy] | h_X p i hp => simp only [_root_.map_mul, hp, toAlgHom_X, comp_val]; rfl variable {T} [CommRing T] [Algebra R T] [Algebra S T] [IsScalarTower R S T] /-- Given families of generators `X ⊆ T` over `S` and `Y ⊆ S` over `R`, there is a map of generators `R[Y] → R[X, Y]`. -/ @[simps] noncomputable def toComp (Q : Generators S T) (P : Generators R S) : Hom P (Q.comp P) where val i := X (.inr i) aeval_val i := by simp /-- Given families of generators `X ⊆ T` over `S` and `Y ⊆ S` over `R`, there is a map of generators `R[X, Y] → S[X]`. -/ @[simps] noncomputable def ofComp (Q : Generators S T) (P : Generators R S) : Hom (Q.comp P) Q where val i := i.elim X (C ∘ P.val) aeval_val i := by cases i <;> simp /-- Given families of generators `X ⊆ T`, there is a map `R[X] → S[X]`. -/ @[simps] noncomputable def toExtendScalars (P : Generators R T) : Hom P (P.extendScalars S) where val := X aeval_val i := by simp end Hom section Cotangent /-- The kernel of a presentation. -/ abbrev ker : Ideal P.Ring := RingHom.ker (algebraMap P.Ring S) lemma ker_eq_ker_aeval_val : P.ker = RingHom.ker (aeval P.val) := rfl /-- The cotangent space of a presentation. This is a type synonym so that `P = R[X]` can act on it through the action of `S` without creating a diamond. -/ def Cotangent : Type _ := P.ker.Cotangent noncomputable instance : AddCommGroup P.Cotangent := inferInstanceAs (AddCommGroup P.ker.Cotangent) variable {P} /-- The identity map `P.ker.Cotangent → P.Cotangent` into the type synonym. -/ def Cotangent.of (x : P.ker.Cotangent) : P.Cotangent := x /-- The identity map `P.Cotangent → P.ker.Cotangent` from the type synonym. -/ def Cotangent.val (x : P.Cotangent) : P.ker.Cotangent := x @[ext] lemma Cotangent.ext {x y : P.Cotangent} (e : x.val = y.val) : x = y := e namespace Cotangent variable (x y : P.Cotangent) (w z : P.ker.Cotangent) @[simp] lemma val_add : (x + y).val = x.val + y.val := rfl @[simp] lemma val_zero : (0 : P.Cotangent).val = 0 := rfl @[simp] lemma of_add : of (w + z) = of w + of z := rfl @[simp] lemma of_zero : (of 0 : P.Cotangent) = 0 := rfl @[simp] lemma of_val : of x.val = x := rfl @[simp] lemma val_of : (of w).val = w := rfl @[simp] lemma val_sub : (x - y).val = x.val - y.val := rfl end Cotangent lemma Cotangent.smul_eq_zero_of_mem (p : P.Ring) (hp : p ∈ P.ker) (m : P.ker.Cotangent) : p • m = 0 := by obtain ⟨x, rfl⟩ := Ideal.toCotangent_surjective _ m rw [← map_smul, Ideal.toCotangent_eq_zero, Submodule.coe_smul, smul_eq_mul, pow_two] exact Ideal.mul_mem_mul hp x.2 attribute [local simp] RingHom.mem_ker noncomputable instance Cotangent.module : Module S P.Cotangent where smul := fun r s ↦ .of (P.σ r • s.val) smul_zero := fun r ↦ ext (smul_zero (P.σ r)) smul_add := fun r x y ↦ ext (smul_add (P.σ r) x.val y.val) add_smul := fun r s x ↦ by have := smul_eq_zero_of_mem (P.σ (r + s) - (P.σ r + P.σ s) : P.Ring) (by simp ) x simpa only [sub_smul, add_smul, sub_eq_zero] zero_smul := fun x ↦ smul_eq_zero_of_mem (P.σ 0 : P.Ring) (by simp) x one_smul := fun x ↦ by have := smul_eq_zero_of_mem (P.σ 1 - 1 : P.Ring) (by simp) x simpa [sub_eq_zero, sub_smul] mul_smul := fun r s x ↦ by have := smul_eq_zero_of_mem (P.σ (r * s) - (P.σ r * P.σ s) : P.Ring) (by simp) x simpa only [sub_smul, mul_smul, sub_eq_zero] using this noncomputable instance Cotangent.module' {R₀} [CommRing R₀] [Algebra R₀ S] : Module R₀ P.Cotangent := Module.compHom P.Cotangent (algebraMap R₀ S) instance {R₁ R₂} [CommRing R₁] [CommRing R₂] [Algebra R₁ S] [Algebra R₂ S] [Algebra R₁ R₂] [IsScalarTower R₁ R₂ S] : IsScalarTower R₁ R₂ P.Cotangent := by constructor intros r s m show algebraMap R₂ S (r • s) • m = (algebraMap _ S r) • (algebraMap _ S s) • m rw [Algebra.smul_def, _root_.map_mul, mul_smul, ← IsScalarTower.algebraMap_apply] lemma Cotangent.val_smul''' {R₀} [CommRing R₀] [Algebra R₀ S] (r : R₀) (x : P.Cotangent) : (r • x).val = P.σ (algebraMap R₀ S r) • x.val := rfl @[simp] lemma Cotangent.val_smul (r : S) (x : P.Cotangent) : (r • x).val = P.σ r • x.val := rfl @[simp] lemma Cotangent.val_smul' (r : P.Ring) (x : P.Cotangent) : (r • x).val = r • x.val := by rw [val_smul''', ← sub_eq_zero, ← sub_smul] exact Cotangent.smul_eq_zero_of_mem _ (by simp) _ @[simp] lemma Cotangent.val_smul'' (r : R) (x : P.Cotangent) : (r • x).val = r • x.val := by rw [← algebraMap_smul P.Ring, val_smul', algebraMap_smul] /-- The quotient map from the kernel of `P = R[X] → S` onto the cotangent space. -/ def Cotangent.mk : P.ker →ₗ[P.Ring] P.Cotangent where toFun x := .of (Ideal.toCotangent _ x) map_add' x y := by simp map_smul' x y := ext <| by simp @[simp] lemma Cotangent.val_mk (x : P.ker) : (mk x).val = Ideal.toCotangent _ x := rfl lemma Cotangent.mk_surjective : Function.Surjective (mk (P := P)) := fun x ↦ Ideal.toCotangent_surjective P.ker x.val variable {P'} variable [Algebra R R'] [Algebra R' R''] [Algebra R' S''] variable [Algebra S S'] [Algebra S' S''] [Algebra S S''] variable [Algebra R S'] [IsScalarTower R R' S'] [IsScalarTower R S S'] /-- A hom between families of generators induce a map between cotangent spaces. -/ noncomputable def Cotangent.map (f : Hom P P') : P.Cotangent →ₗ[S] P'.Cotangent where toFun x := .of (Ideal.mapCotangent (R := R) _ _ f.toAlgHom (fun x hx ↦ by simpa using RingHom.congr_arg (algebraMap S S') hx) x.val) map_add' x y := ext (map_add _ x.val y.val) map_smul' r x := by ext obtain ⟨x, rfl⟩ := Cotangent.mk_surjective x obtain ⟨r, rfl⟩ := P.algebraMap_surjective r simp only [algebraMap_smul, val_smul', val_mk, val_of, Ideal.mapCotangent_toCotangent, RingHomCompTriple.comp_apply, ← (Ideal.toCotangent _).map_smul] conv_rhs => rw [algebraMap_apply, ← algebraMap_smul S', ← f.algebraMap_toAlgHom, ← algebraMap_apply, algebraMap_smul, val_smul', val_of, ← (Ideal.toCotangent _).map_smul] congr 1 ext1 simp only [SetLike.val_smul, smul_eq_mul, _root_.map_mul] @[simp] lemma Cotangent.map_mk (f : Hom P P') (x) : Cotangent.map f (.mk x) = .mk ⟨f.toAlgHom x, by simpa [-map_aeval] using RingHom.congr_arg (algebraMap S S') x.2⟩ := rfl @[simp] lemma Cotangent.map_id : Cotangent.map (.id P) = LinearMap.id := by ext x obtain ⟨x, rfl⟩ := Cotangent.mk_surjective x simp only [map_mk, Hom.toAlgHom_id, AlgHom.coe_id, id_eq, Subtype.coe_eta, val_mk, LinearMap.id_coe] variable [Algebra R R''] [IsScalarTower R R' R''] [IsScalarTower R' R'' S''] [IsScalarTower R' S' S''] [IsScalarTower S S' S''] [Algebra R S''] [IsScalarTower R R'' S''] [IsScalarTower R S S''] lemma Cotangent.map_comp (f : Hom P P') (g : Hom P' P'') : Cotangent.map (g.comp f) = (map g).restrictScalars S ∘ₗ map f := by ext x obtain ⟨x, rfl⟩ := Cotangent.mk_surjective x simp only [map_mk, val_mk, LinearMap.coe_comp, LinearMap.coe_restrictScalars, Function.comp_apply, Hom.toAlgHom_comp_apply] end Cotangent end Algebra.Generators
RingTheory\Henselian.lean
/- Copyright (c) 2021 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.Polynomial.Taylor import Mathlib.RingTheory.LocalRing.ResidueField.Basic import Mathlib.RingTheory.AdicCompletion.Basic /-! # Henselian rings In this file we set up the basic theory of Henselian (local) rings. A ring `R` is *Henselian* at an ideal `I` if the following conditions hold: * `I` is contained in the Jacobson radical of `R` * for every polynomial `f` over `R`, with a *simple* root `a₀` over the quotient ring `R/I`, there exists a lift `a : R` of `a₀` that is a root of `f`. (Here, saying that a root `b` of a polynomial `g` is *simple* means that `g.derivative.eval b` is a unit. Warning: if `R/I` is not a field then it is not enough to assume that `g` has a factorization into monic linear factors in which `X - b` shows up only once; for example `1` is not a simple root of `X^2-1` over `ℤ/4ℤ`.) A local ring `R` is *Henselian* if it is Henselian at its maximal ideal. In this case the first condition is automatic, and in the second condition we may ask for `f.derivative.eval a ≠ 0`, since the quotient ring `R/I` is a field in this case. ## Main declarations * `HenselianRing`: a typeclass on commutative rings, asserting that the ring is Henselian at the ideal `I`. * `HenselianLocalRing`: a typeclass on commutative rings, asserting that the ring is local Henselian. * `Field.henselian`: fields are Henselian local rings * `Henselian.TFAE`: equivalent ways of expressing the Henselian property for local rings * `IsAdicComplete.henselianRing`: a ring `R` with ideal `I` that is `I`-adically complete is Henselian at `I` ## References https://stacks.math.columbia.edu/tag/04GE ## TODO After a good API for etale ring homomorphisms has been developed, we can give more equivalent characterization of Henselian rings. In particular, this can give a proof that factorizations into coprime polynomials can be lifted from the residue field to the Henselian ring. The following gist contains some code sketches in that direction. https://gist.github.com/jcommelin/47d94e4af092641017a97f7f02bf9598 -/ noncomputable section universe u v open Polynomial LocalRing Polynomial Function List theorem isLocalRingHom_of_le_jacobson_bot {R : Type*} [CommRing R] (I : Ideal R) (h : I ≤ Ideal.jacobson ⊥) : IsLocalRingHom (Ideal.Quotient.mk I) := by constructor intro a h have : IsUnit (Ideal.Quotient.mk (Ideal.jacobson ⊥) a) := by rw [isUnit_iff_exists_inv] at * obtain ⟨b, hb⟩ := h obtain ⟨b, rfl⟩ := Ideal.Quotient.mk_surjective b use Ideal.Quotient.mk _ b rw [← (Ideal.Quotient.mk _).map_one, ← (Ideal.Quotient.mk _).map_mul, Ideal.Quotient.eq] at hb ⊢ exact h hb obtain ⟨⟨x, y, h1, h2⟩, rfl : x = _⟩ := this obtain ⟨y, rfl⟩ := Ideal.Quotient.mk_surjective y rw [← (Ideal.Quotient.mk _).map_mul, ← (Ideal.Quotient.mk _).map_one, Ideal.Quotient.eq, Ideal.mem_jacobson_bot] at h1 h2 specialize h1 1 simp? at h1 says simp only [mul_one, sub_add_cancel, IsUnit.mul_iff] at h1 exact h1.1 /-- A ring `R` is *Henselian* at an ideal `I` if the following condition holds: for every polynomial `f` over `R`, with a *simple* root `a₀` over the quotient ring `R/I`, there exists a lift `a : R` of `a₀` that is a root of `f`. (Here, saying that a root `b` of a polynomial `g` is *simple* means that `g.derivative.eval b` is a unit. Warning: if `R/I` is not a field then it is not enough to assume that `g` has a factorization into monic linear factors in which `X - b` shows up only once; for example `1` is not a simple root of `X^2-1` over `ℤ/4ℤ`.) -/ class HenselianRing (R : Type*) [CommRing R] (I : Ideal R) : Prop where jac : I ≤ Ideal.jacobson ⊥ is_henselian : ∀ (f : R[X]) (_ : f.Monic) (a₀ : R) (_ : f.eval a₀ ∈ I) (_ : IsUnit (Ideal.Quotient.mk I (f.derivative.eval a₀))), ∃ a : R, f.IsRoot a ∧ a - a₀ ∈ I /-- A local ring `R` is *Henselian* if the following condition holds: for every polynomial `f` over `R`, with a *simple* root `a₀` over the residue field, there exists a lift `a : R` of `a₀` that is a root of `f`. (Recall that a root `b` of a polynomial `g` is *simple* if it is not a double root, so if `g.derivative.eval b ≠ 0`.) In other words, `R` is local Henselian if it is Henselian at the ideal `I`, in the sense of `HenselianRing`. -/ class HenselianLocalRing (R : Type*) [CommRing R] extends LocalRing R : Prop where is_henselian : ∀ (f : R[X]) (_ : f.Monic) (a₀ : R) (_ : f.eval a₀ ∈ maximalIdeal R) (_ : IsUnit (f.derivative.eval a₀)), ∃ a : R, f.IsRoot a ∧ a - a₀ ∈ maximalIdeal R -- see Note [lower instance priority] instance (priority := 100) Field.henselian (K : Type*) [Field K] : HenselianLocalRing K where is_henselian f _ a₀ h₁ _ := by simp only [(maximalIdeal K).eq_bot_of_prime, Ideal.mem_bot] at h₁ ⊢ exact ⟨a₀, h₁, sub_self _⟩ theorem HenselianLocalRing.TFAE (R : Type u) [CommRing R] [LocalRing R] : TFAE [HenselianLocalRing R, ∀ f : R[X], f.Monic → ∀ a₀ : ResidueField R, aeval a₀ f = 0 → aeval a₀ (derivative f) ≠ 0 → ∃ a : R, f.IsRoot a ∧ residue R a = a₀, ∀ {K : Type u} [Field K], ∀ (φ : R →+* K), Surjective φ → ∀ f : R[X], f.Monic → ∀ a₀ : K, f.eval₂ φ a₀ = 0 → f.derivative.eval₂ φ a₀ ≠ 0 → ∃ a : R, f.IsRoot a ∧ φ a = a₀] := by tfae_have 3 → 2 · intro H exact H (residue R) Ideal.Quotient.mk_surjective tfae_have 2 → 1 · intro H constructor intro f hf a₀ h₁ h₂ specialize H f hf (residue R a₀) have aux := flip mem_nonunits_iff.mp h₂ simp only [aeval_def, ResidueField.algebraMap_eq, eval₂_at_apply, ← Ideal.Quotient.eq_zero_iff_mem, ← LocalRing.mem_maximalIdeal] at H h₁ aux obtain ⟨a, ha₁, ha₂⟩ := H h₁ aux refine ⟨a, ha₁, ?_⟩ rw [← Ideal.Quotient.eq_zero_iff_mem] rwa [← sub_eq_zero, ← RingHom.map_sub] at ha₂ tfae_have 1 → 3 · intro hR K _K φ hφ f hf a₀ h₁ h₂ obtain ⟨a₀, rfl⟩ := hφ a₀ have H := HenselianLocalRing.is_henselian f hf a₀ simp only [← ker_eq_maximalIdeal φ hφ, eval₂_at_apply, RingHom.mem_ker φ] at H h₁ h₂ obtain ⟨a, ha₁, ha₂⟩ := H h₁ (by contrapose! h₂ rwa [← mem_nonunits_iff, ← LocalRing.mem_maximalIdeal, ← LocalRing.ker_eq_maximalIdeal φ hφ, RingHom.mem_ker] at h₂) refine ⟨a, ha₁, ?_⟩ rwa [φ.map_sub, sub_eq_zero] at ha₂ tfae_finish instance (R : Type*) [CommRing R] [hR : HenselianLocalRing R] : HenselianRing R (maximalIdeal R) where jac := by rw [Ideal.jacobson, le_sInf_iff] rintro I ⟨-, hI⟩ exact (eq_maximalIdeal hI).ge is_henselian := by intro f hf a₀ h₁ h₂ refine HenselianLocalRing.is_henselian f hf a₀ h₁ ?_ contrapose! h₂ rw [← mem_nonunits_iff, ← LocalRing.mem_maximalIdeal, ← Ideal.Quotient.eq_zero_iff_mem] at h₂ rw [h₂] exact not_isUnit_zero -- see Note [lower instance priority] /-- A ring `R` that is `I`-adically complete is Henselian at `I`. -/ instance (priority := 100) IsAdicComplete.henselianRing (R : Type*) [CommRing R] (I : Ideal R) [IsAdicComplete I R] : HenselianRing R I where jac := IsAdicComplete.le_jacobson_bot _ is_henselian := by intro f _ a₀ h₁ h₂ classical let f' := derivative f -- we define a sequence `c n` by starting at `a₀` and then continually -- applying the function sending `b` to `b - f(b)/f'(b)` (Newton's method). -- Note that `f'.eval b` is a unit, because `b` has the same residue as `a₀` modulo `I`. let c : ℕ → R := fun n => Nat.recOn n a₀ fun _ b => b - f.eval b * Ring.inverse (f'.eval b) have hc : ∀ n, c (n + 1) = c n - f.eval (c n) * Ring.inverse (f'.eval (c n)) := by intro n simp only [c, Nat.rec_add_one] -- we now spend some time determining properties of the sequence `c : ℕ → R` -- `hc_mod`: for every `n`, we have `c n ≡ a₀ [SMOD I]` -- `hf'c` : for every `n`, `f'.eval (c n)` is a unit -- `hfcI` : for every `n`, `f.eval (c n)` is contained in `I ^ (n+1)` have hc_mod : ∀ n, c n ≡ a₀ [SMOD I] := by intro n induction' n with n ih · rfl rw [hc, sub_eq_add_neg, ← add_zero a₀] refine ih.add ?_ rw [SModEq.zero, Ideal.neg_mem_iff] refine I.mul_mem_right _ ?_ rw [← SModEq.zero] at h₁ ⊢ exact (ih.eval f).trans h₁ have hf'c : ∀ n, IsUnit (f'.eval (c n)) := by intro n haveI := isLocalRingHom_of_le_jacobson_bot I (IsAdicComplete.le_jacobson_bot I) apply isUnit_of_map_unit (Ideal.Quotient.mk I) convert h₂ using 1 exact SModEq.def.mp ((hc_mod n).eval _) have hfcI : ∀ n, f.eval (c n) ∈ I ^ (n + 1) := by intro n induction' n with n ih · simpa only [Nat.zero_eq, Nat.rec_zero, zero_add, pow_one] using h₁ rw [← taylor_eval_sub (c n), hc, sub_eq_add_neg, sub_eq_add_neg, add_neg_cancel_comm] rw [eval_eq_sum, sum_over_range' _ _ _ (lt_add_of_pos_right _ zero_lt_two), ← Finset.sum_range_add_sum_Ico _ (Nat.le_add_left _ _)] swap · intro i rw [zero_mul] refine Ideal.add_mem _ ?_ ?_ · erw [Finset.sum_range_succ] rw [Finset.range_one, Finset.sum_singleton, taylor_coeff_zero, taylor_coeff_one, pow_zero, pow_one, mul_one, mul_neg, mul_left_comm, Ring.mul_inverse_cancel _ (hf'c n), mul_one, add_neg_self] exact Ideal.zero_mem _ · refine Submodule.sum_mem _ ?_ simp only [Finset.mem_Ico] rintro i ⟨h2i, _⟩ have aux : n + 2 ≤ i * (n + 1) := by trans 2 * (n + 1) <;> nlinarith only [h2i] refine Ideal.mul_mem_left _ _ (Ideal.pow_le_pow_right aux ?_) rw [pow_mul'] exact Ideal.pow_mem_pow ((Ideal.neg_mem_iff _).2 <| Ideal.mul_mem_right _ _ ih) _ -- we are now in the position to show that `c : ℕ → R` is a Cauchy sequence have aux : ∀ m n, m ≤ n → c m ≡ c n [SMOD (I ^ m • ⊤ : Ideal R)] := by intro m n hmn rw [← Ideal.one_eq_top, Ideal.smul_eq_mul, mul_one] obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le hmn clear hmn induction' k with k ih · rw [add_zero] rw [← add_assoc] #adaptation_note /-- nightly-2024-03-11 I'm not sure why the `erw` is now needed here. It looks like it should work. It looks like a diamond between `instHAdd` on `Nat` and `AddSemigroup.toAdd` which is used by `instHAdd` -/ erw [hc] rw [← add_zero (c m), sub_eq_add_neg] refine ih.add ?_ symm rw [SModEq.zero, Ideal.neg_mem_iff] refine Ideal.mul_mem_right _ _ (Ideal.pow_le_pow_right ?_ (hfcI _)) rw [add_assoc] exact le_self_add -- hence the sequence converges to some limit point `a`, which is the `a` we are looking for obtain ⟨a, ha⟩ := IsPrecomplete.prec' c (aux _ _) refine ⟨a, ?_, ?_⟩ · show f.IsRoot a suffices ∀ n, f.eval a ≡ 0 [SMOD (I ^ n • ⊤ : Ideal R)] by exact IsHausdorff.haus' _ this intro n specialize ha n rw [← Ideal.one_eq_top, Ideal.smul_eq_mul, mul_one] at ha ⊢ refine (ha.symm.eval f).trans ?_ rw [SModEq.zero] exact Ideal.pow_le_pow_right le_self_add (hfcI _) · show a - a₀ ∈ I specialize ha (0 + 1) rw [hc, pow_one, ← Ideal.one_eq_top, Ideal.smul_eq_mul, mul_one, sub_eq_add_neg] at ha rw [← SModEq.sub_mem, ← add_zero a₀] refine ha.symm.trans (SModEq.rfl.add ?_) rw [SModEq.zero, Ideal.neg_mem_iff] exact Ideal.mul_mem_right _ _ h₁
RingTheory\HopfAlgebra.lean
/- Copyright (c) 2024 Ali Ramsey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ali Ramsey -/ import Mathlib.RingTheory.Bialgebra.Basic /-! # Hopf algebras In this file we define `HopfAlgebra`, and provide instances for: * Commutative semirings: `CommSemiring.toHopfAlgebra` # Main definitions * `HopfAlgebra R A` : the Hopf algebra structure on an `R`-bialgebra `A`. * `HopfAlgebra.antipode` : The `R`-linear map `A →ₗ[R] A`. ## TODO * Uniqueness of Hopf algebra structure on a bialgebra (i.e. if the algebra and coalgebra structures agree then the antipodes must also agree). * `antipode 1 = 1` and `antipode (a * b) = antipode b * antipode a`, so in particular if `A` is commutative then `antipode` is an algebra homomorphism. * If `A` is commutative then `antipode` is necessarily a bijection and its square is the identity. ## References * <https://en.wikipedia.org/wiki/Hopf_algebra> * [C. Kassel, *Quantum Groups* (§III.3)][Kassel1995] -/ suppress_compilation universe u v /-- A Hopf algebra over a commutative (semi)ring `R` is a bialgebra over `R` equipped with an `R`-linear endomorphism `antipode` satisfying the antipode axioms. -/ class HopfAlgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends Bialgebra R A where /-- The antipode of the Hopf algebra. -/ antipode : A →ₗ[R] A /-- One of the antipode axioms for a Hopf algebra. -/ mul_antipode_rTensor_comul : LinearMap.mul' R A ∘ₗ antipode.rTensor A ∘ₗ comul = (Algebra.linearMap R A) ∘ₗ counit /-- One of the antipode axioms for a Hopf algebra. -/ mul_antipode_lTensor_comul : LinearMap.mul' R A ∘ₗ antipode.lTensor A ∘ₗ comul = (Algebra.linearMap R A) ∘ₗ counit namespace HopfAlgebra variable {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [HopfAlgebra R A] @[simp] theorem mul_antipode_rTensor_comul_apply (a : A) : LinearMap.mul' R A (antipode.rTensor A (Coalgebra.comul a)) = algebraMap R A (Coalgebra.counit a) := LinearMap.congr_fun mul_antipode_rTensor_comul a @[simp] theorem mul_antipode_lTensor_comul_apply (a : A) : LinearMap.mul' R A (antipode.lTensor A (Coalgebra.comul a)) = algebraMap R A (Coalgebra.counit a) := LinearMap.congr_fun mul_antipode_lTensor_comul a open Coalgebra @[simp] lemma sum_antipode_mul_eq {a : A} (repr : Repr R a) : ∑ i ∈ repr.index, antipode (R := R) (repr.left i) * repr.right i = algebraMap R A (counit a) := by simpa [← repr.eq, map_sum] using congr($(mul_antipode_rTensor_comul (R := R)) a) @[simp] lemma sum_mul_antipode_eq {a : A} (repr : Repr R a) : ∑ i ∈ repr.index, repr.left i * antipode (R := R) (repr.right i) = algebraMap R A (counit a) := by simpa [← repr.eq, map_sum] using congr($(mul_antipode_lTensor_comul (R := R)) a) lemma sum_antipode_mul_eq_smul {a : A} (repr : Repr R a) : ∑ i ∈ repr.index, antipode (R := R) (repr.left i) * repr.right i = counit (R := R) a • 1 := by rw [sum_antipode_mul_eq, Algebra.smul_def, mul_one] lemma sum_mul_antipode_eq_smul {a : A} (repr : Repr R a) : ∑ i ∈ repr.index, repr.left i * antipode (R := R) (repr.right i) = counit (R := R) a • 1 := by rw [sum_mul_antipode_eq, Algebra.smul_def, mul_one] end HopfAlgebra namespace CommSemiring variable (R : Type u) [CommSemiring R] open HopfAlgebra /-- Every commutative (semi)ring is a Hopf algebra over itself -/ instance toHopfAlgebra : HopfAlgebra R R where antipode := .id mul_antipode_rTensor_comul := by ext; simp mul_antipode_lTensor_comul := by ext; simp @[simp] theorem antipode_eq_id : antipode (R := R) (A := R) = .id := rfl end CommSemiring
RingTheory\Idempotents.lean
/- Copyright (c) 2024 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.Algebra.GeomSum import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.RingTheory.Ideal.QuotientOperations import Mathlib.RingTheory.Nilpotent.Defs /-! ## Idempotents in rings The predicate `IsIdempotentElem` is defined for general monoids in `Algebra/Ring/Idempotents.lean`. In this file we provide various results regarding idempotent elements in rings. ## Main definitions - `OrthogonalIdempotents`: A family `{ eᵢ }` of idempotent elements is orthogonal if `eᵢ * eⱼ = 0` for all `i ≠ j`. - `CompleteOrthogonalIdempotents`: A family `{ eᵢ }` of orthogonal idempotent elements is complete if `∑ eᵢ = 1`. ## Main results - `CompleteOrthogonalIdempotents.lift_of_isNilpotent_ker`: If the kernel of `f : R →+* S` consists of nilpotent elements, and `{ eᵢ }` is a family of complete orthogonal idempotents in the range of `f`, then `{ eᵢ }` is the image of some complete orthogonal idempotents in `R`. - `existsUnique_isIdempotentElem_eq_of_ker_isNilpotent`: If `R` is commutative and the kernel of `f : R →+* S` consists of nilpotent elements, then every idempotent in the range of `f` lifts to a unique idempotent in `R`. - `CompleteOrthogonalIdempotents.bijective_pi`: If `R` is commutative, then a family `{ eᵢ }` of complete orthogonal idempotent elements induces a ring isomorphism `R ≃ ∏ R ⧸ ⟨1 - eᵢ⟩`. -/ section Ring variable {R S : Type*} [Ring R] [Ring S] (f : R →+* S) theorem isIdempotentElem_one_sub_one_sub_pow_pow (x : R) (n : ℕ) (hx : (x - x ^ 2) ^ n = 0) : IsIdempotentElem (1 - (1 - x ^ n) ^ n) := by let P : Polynomial ℤ := 1 - (1 - .X ^ n) ^ n have : (.X - .X ^ 2) ^ n ∣ P - P ^ 2 := by have H₁ : .X ^ n ∣ P := by have := sub_dvd_pow_sub_pow 1 ((1 : Polynomial ℤ) - Polynomial.X ^ n) n rwa [sub_sub_cancel, one_pow] at this have H₂ : (1 - .X) ^ n ∣ 1 - P := by simp only [sub_sub_cancel, P] simpa using pow_dvd_pow_of_dvd (sub_dvd_pow_sub_pow (α := Polynomial ℤ) 1 Polynomial.X n) n have := mul_dvd_mul H₁ H₂ simpa only [← mul_pow, mul_sub, mul_one, ← pow_two] using this have := map_dvd (Polynomial.aeval x) this simp only [map_pow, map_sub, Polynomial.aeval_X, hx, map_one, zero_dvd_iff, P] at this rwa [sub_eq_zero, eq_comm, pow_two] at this theorem exists_isIdempotentElem_mul_eq_zero_of_ker_isNilpotent_aux (h : ∀ x ∈ RingHom.ker f, IsNilpotent x) (e₁ : S) (he : e₁ ∈ f.range) (he₁ : IsIdempotentElem e₁) (e₂ : R) (he₂ : IsIdempotentElem e₂) (he₁e₂ : e₁ * f e₂ = 0) : ∃ e' : R, IsIdempotentElem e' ∧ f e' = e₁ ∧ e' * e₂ = 0 := by obtain ⟨e₁, rfl⟩ := he cases subsingleton_or_nontrivial R · exact ⟨_, Subsingleton.elim _ _, rfl, Subsingleton.elim _ _⟩ let a := e₁ - e₁ * e₂ have ha : f a = f e₁ := by rw [map_sub, map_mul, he₁e₂, sub_zero] have ha' : a * e₂ = 0 := by rw [sub_mul, mul_assoc, he₂.eq, sub_self] have hx' : a - a ^ 2 ∈ RingHom.ker f := by simp [RingHom.mem_ker, mul_sub, pow_two, ha, he₁.eq] obtain ⟨n, hn⟩ := h _ hx' refine ⟨_, isIdempotentElem_one_sub_one_sub_pow_pow _ _ hn, ?_, ?_⟩ · cases' n with n · simp at hn simp only [map_sub, map_one, map_pow, ha, he₁.pow_succ_eq, he₁.one_sub.pow_succ_eq, sub_sub_cancel] · obtain ⟨k, hk⟩ := (Commute.one_left (MulOpposite.op <| 1 - a ^ n)).sub_dvd_pow_sub_pow n apply_fun MulOpposite.unop at hk have : 1 - (1 - a ^ n) ^ n = MulOpposite.unop k * a ^ n := by simpa using hk rw [this, mul_assoc] cases' n with n · simp at hn rw [pow_succ, mul_assoc, ha', mul_zero, mul_zero] /-- Orthogonal idempotents lift along nil ideals. -/ theorem exists_isIdempotentElem_mul_eq_zero_of_ker_isNilpotent (h : ∀ x ∈ RingHom.ker f, IsNilpotent x) (e₁ : S) (he : e₁ ∈ f.range) (he₁ : IsIdempotentElem e₁) (e₂ : R) (he₂ : IsIdempotentElem e₂) (he₁e₂ : e₁ * f e₂ = 0) (he₂e₁ : f e₂ * e₁ = 0) : ∃ e' : R, IsIdempotentElem e' ∧ f e' = e₁ ∧ e' * e₂ = 0 ∧ e₂ * e' = 0 := by obtain ⟨e', h₁, rfl, h₂⟩ := exists_isIdempotentElem_mul_eq_zero_of_ker_isNilpotent_aux f h e₁ he he₁ e₂ he₂ he₁e₂ refine ⟨(1 - e₂) * e', ?_, ?_, ?_, ?_⟩ · rw [IsIdempotentElem, mul_assoc, ← mul_assoc e', mul_sub, mul_one, h₂, sub_zero, h₁.eq] · rw [map_mul, map_sub, map_one, sub_mul, one_mul, he₂e₁, sub_zero] · rw [mul_assoc, h₂, mul_zero] · rw [← mul_assoc, mul_sub, mul_one, he₂.eq, sub_self, zero_mul] /-- Idempotents lift along nil ideals. -/ theorem exists_isIdempotentElem_eq_of_ker_isNilpotent (h : ∀ x ∈ RingHom.ker f, IsNilpotent x) (e : S) (he : e ∈ f.range) (he' : IsIdempotentElem e) : ∃ e' : R, IsIdempotentElem e' ∧ f e' = e := by simpa using exists_isIdempotentElem_mul_eq_zero_of_ker_isNilpotent f h e he he' 0 .zero (by simp) variable {I : Type*} (e : I → R) /-- A family `{ eᵢ }` of idempotent elements is orthogonal if `eᵢ * eⱼ = 0` for all `i ≠ j`. -/ @[mk_iff] structure OrthogonalIdempotents : Prop where idem : ∀ i, IsIdempotentElem (e i) ortho : ∀ i j, i ≠ j → e i * e j = 0 variable {e} lemma OrthogonalIdempotents.mul_eq [DecidableEq I] (he : OrthogonalIdempotents e) (i j) : e i * e j = if i = j then e i else 0 := by split · simp [*, (he.idem j).eq] · exact he.ortho _ _ ‹_› lemma OrthogonalIdempotents.iff_mul_eq [DecidableEq I] : OrthogonalIdempotents e ↔ ∀ i j, e i * e j = if i = j then e i else 0 := ⟨mul_eq, fun H ↦ ⟨fun i ↦ by simpa using H i i, fun i j e ↦ by simpa [e] using H i j⟩⟩ lemma OrthogonalIdempotents.isIdempotentElem_sum [Fintype I] (he : OrthogonalIdempotents e) : IsIdempotentElem (∑ i, e i) := by classical simp [IsIdempotentElem, Finset.sum_mul, Finset.mul_sum, he.mul_eq] lemma OrthogonalIdempotents.map (he : OrthogonalIdempotents e) : OrthogonalIdempotents (f ∘ e) := by classical simp [iff_mul_eq, he.mul_eq, ← map_mul f, apply_ite f] lemma OrthogonalIdempotents.map_injective_iff (hf : Function.Injective f) : OrthogonalIdempotents (f ∘ e) ↔ OrthogonalIdempotents e := by classical simp [iff_mul_eq, ← hf.eq_iff, apply_ite] lemma OrthogonalIdempotents.embedding (he : OrthogonalIdempotents e) {J} (i : J ↪ I) : OrthogonalIdempotents (e ∘ i) := by classical simp [iff_mul_eq, he.mul_eq] lemma OrthogonalIdempotents.equiv {J} (i : J ≃ I) : OrthogonalIdempotents (e ∘ i) ↔ OrthogonalIdempotents e := by classical simp [iff_mul_eq, i.forall_congr_left] lemma OrthogonalIdempotents.unique [Unique I] : OrthogonalIdempotents e ↔ IsIdempotentElem (e default) := by simp [orthogonalIdempotents_iff, Unique.forall_iff] lemma OrthogonalIdempotents.option (he : OrthogonalIdempotents e) [Fintype I] (x) (hx : IsIdempotentElem x) (hx₁ : x * ∑ i, e i = 0) (hx₂ : (∑ i, e i) * x = 0) : OrthogonalIdempotents (Option.elim · x e) where idem i := i.rec hx he.idem ortho i j ne := by classical cases' i with i <;> cases' j with j · cases ne rfl · simpa only [mul_assoc, Finset.sum_mul, he.mul_eq, Finset.sum_ite_eq', Finset.mem_univ, ↓reduceIte, zero_mul] using congr_arg (· * e j) hx₁ · simpa only [Option.elim_some, Option.elim_none, ← mul_assoc, Finset.mul_sum, he.mul_eq, Finset.sum_ite_eq, Finset.mem_univ, ↓reduceIte, mul_zero] using congr_arg (e i * ·) hx₂ · exact he.ortho i j (Option.some_inj.ne.mp ne) lemma OrthogonalIdempotents.lift_of_isNilpotent_ker_aux (h : ∀ x ∈ RingHom.ker f, IsNilpotent x) {n} {e : Fin n → S} (he : OrthogonalIdempotents e) (he' : ∀ i, e i ∈ f.range) : ∃ e' : Fin n → R, OrthogonalIdempotents e' ∧ f ∘ e' = e := by induction' n with n IH · refine ⟨0, ⟨finZeroElim, finZeroElim⟩, funext finZeroElim⟩ · obtain ⟨e', h₁, h₂⟩ := IH (he.embedding (Fin.succEmb n)) (fun i ↦ he' _) have h₂' (i) : f (e' i) = e i.succ := congr_fun h₂ i obtain ⟨e₀, h₃, h₄, h₅, h₆⟩ := exists_isIdempotentElem_mul_eq_zero_of_ker_isNilpotent f h _ (he' 0) (he.idem 0) _ h₁.isIdempotentElem_sum (by simp [Finset.mul_sum, h₂', he.mul_eq, Fin.succ_ne_zero, eq_comm]) (by simp [Finset.sum_mul, h₂', he.mul_eq, Fin.succ_ne_zero]) refine ⟨_, (h₁.option _ h₃ h₅ h₆).embedding (finSuccEquiv n).toEmbedding, funext fun i ↦ ?_⟩ obtain ⟨_ | i, rfl⟩ := (finSuccEquiv n).symm.surjective i <;> simp [*] /-- A family of orthogonal idempotents lift along nil ideals. -/ lemma OrthogonalIdempotents.lift_of_isNilpotent_ker [Finite I] (h : ∀ x ∈ RingHom.ker f, IsNilpotent x) {e : I → S} (he : OrthogonalIdempotents e) (he' : ∀ i, e i ∈ f.range) : ∃ e' : I → R, OrthogonalIdempotents e' ∧ f ∘ e' = e := by cases nonempty_fintype I obtain ⟨e', h₁, h₂⟩ := lift_of_isNilpotent_ker_aux f h (he.embedding (Fintype.equivFin I).symm.toEmbedding) (fun _ ↦ he' _) refine ⟨_, h₁.embedding (Fintype.equivFin I).toEmbedding, by ext x; simpa using congr_fun h₂ (Fintype.equivFin I x)⟩ variable [Fintype I] /-- A family `{ eᵢ }` of idempotent elements is complete orthogonal if 1. (orthogonal) `eᵢ * eⱼ = 0` for all `i ≠ j`. 2. (complete) `∑ eᵢ = 1` -/ @[mk_iff] structure CompleteOrthogonalIdempotents (e : I → R) extends OrthogonalIdempotents e : Prop where complete : ∑ i, e i = 1 variable (he : CompleteOrthogonalIdempotents e) lemma CompleteOrthogonalIdempotents.unique_iff [Unique I] : CompleteOrthogonalIdempotents e ↔ e default = 1 := by rw [completeOrthogonalIdempotents_iff, orthogonalIdempotents_iff] simp only [Unique.forall_iff, ne_eq, not_true_eq_false, false_implies, and_true, Finset.univ_unique, Finset.sum_singleton, and_iff_right_iff_imp] exact (· ▸ IsIdempotentElem.one) lemma CompleteOrthogonalIdempotents.pair_iff {x y : R} : CompleteOrthogonalIdempotents ![x, y] ↔ IsIdempotentElem x ∧ y = 1 - x := by rw [completeOrthogonalIdempotents_iff, orthogonalIdempotents_iff, and_assoc] simp only [Nat.succ_eq_add_one, Nat.reduceAdd, Fin.forall_fin_two, Fin.isValue, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.head_cons, ne_eq, not_true_eq_false, false_implies, zero_ne_one, not_false_eq_true, true_implies, true_and, one_ne_zero, and_true, and_self, Fin.sum_univ_two, eq_sub_iff_add_eq, @add_comm _ _ y] constructor · exact fun h ↦ ⟨h.1.1, h.2.2⟩ · rintro ⟨h₁, h₂⟩ obtain rfl := eq_sub_iff_add_eq'.mpr h₂ exact ⟨⟨h₁, h₁.one_sub⟩, ⟨by simp [mul_sub, h₁.eq], by simp [sub_mul, h₁.eq]⟩, h₂⟩ lemma CompleteOrthogonalIdempotents.of_isIdempotentElem {e : R} (he : IsIdempotentElem e) : CompleteOrthogonalIdempotents ![e, 1 - e] := pair_iff.mpr ⟨he, rfl⟩ lemma CompleteOrthogonalIdempotents.single {I : Type*} [Fintype I] [DecidableEq I] (R : I → Type*) [∀ i, Ring (R i)] : CompleteOrthogonalIdempotents (Pi.single (f := R) · 1) := by refine ⟨⟨by simp [IsIdempotentElem, ← Pi.single_mul], ?_⟩, Finset.univ_sum_single 1⟩ intros i j hij ext k by_cases hi : i = k · subst hi; simp [hij] · simp [hi] lemma CompleteOrthogonalIdempotents.map (he : CompleteOrthogonalIdempotents e) : CompleteOrthogonalIdempotents (f ∘ e) where __ := he.toOrthogonalIdempotents.map f complete := by simp only [Function.comp_apply, ← map_sum, he.complete, map_one] lemma CompleteOrthogonalIdempotents.map_injective_iff (hf : Function.Injective f) : CompleteOrthogonalIdempotents (f ∘ e) ↔ CompleteOrthogonalIdempotents e := by simp [completeOrthogonalIdempotents_iff, ← hf.eq_iff, apply_ite, OrthogonalIdempotents.map_injective_iff f hf] lemma CompleteOrthogonalIdempotents.equiv {J} [Fintype J] (i : J ≃ I) : CompleteOrthogonalIdempotents (e ∘ i) ↔ CompleteOrthogonalIdempotents e := by simp only [completeOrthogonalIdempotents_iff, OrthogonalIdempotents.equiv, Function.comp_apply, and_congr_right_iff, Fintype.sum_equiv i _ e (fun _ ↦ rfl)] lemma CompleteOrthogonalIdempotents.option (he : OrthogonalIdempotents e) : CompleteOrthogonalIdempotents (Option.elim · (1 - ∑ i, e i) e) where __ := he.option _ he.isIdempotentElem_sum.one_sub (by simp [sub_mul, he.isIdempotentElem_sum.eq]) (by simp [mul_sub, he.isIdempotentElem_sum.eq]) complete := by rw [Fintype.sum_option] exact sub_add_cancel _ _ @[nontriviality] lemma CompleteOrthogonalIdempotents.of_subsingleton [Subsingleton R] : CompleteOrthogonalIdempotents e := ⟨⟨fun _ ↦ Subsingleton.elim _ _, fun _ _ _ ↦ Subsingleton.elim _ _⟩, Subsingleton.elim _ _⟩ lemma CompleteOrthogonalIdempotents.lift_of_isNilpotent_ker_aux (h : ∀ x ∈ RingHom.ker f, IsNilpotent x) {n} {e : Fin n → S} (he : CompleteOrthogonalIdempotents e) (he' : ∀ i, e i ∈ f.range) : ∃ e' : Fin n → R, CompleteOrthogonalIdempotents e' ∧ f ∘ e' = e := by cases subsingleton_or_nontrivial R · choose e' he' using he' exact ⟨e', .of_subsingleton, funext he'⟩ cases subsingleton_or_nontrivial S · obtain ⟨n, hn⟩ := h 1 (Subsingleton.elim _ _) simp at hn cases' n with n · simpa using he.complete obtain ⟨e', h₁, h₂⟩ := OrthogonalIdempotents.lift_of_isNilpotent_ker f h he.1 he' refine ⟨_, (equiv (finSuccEquiv n)).mpr (CompleteOrthogonalIdempotents.option (h₁.embedding (Fin.succEmb _))), funext fun i ↦ ?_⟩ have (i) : f (e' i) = e i := congr_fun h₂ i obtain ⟨_ | i, rfl⟩ := (finSuccEquiv n).symm.surjective i · simp only [Fin.val_succEmb, Function.comp_apply, finSuccEquiv_symm_none, finSuccEquiv_zero, Option.elim_none, map_sub, map_one, map_sum, this, ← he.complete, sub_eq_iff_eq_add, Fin.sum_univ_succ] · simp [this] /-- A system of complete orthogonal idempotents lift along nil ideals. -/ lemma CompleteOrthogonalIdempotents.lift_of_isNilpotent_ker (h : ∀ x ∈ RingHom.ker f, IsNilpotent x) {e : I → S} (he : CompleteOrthogonalIdempotents e) (he' : ∀ i, e i ∈ f.range) : ∃ e' : I → R, CompleteOrthogonalIdempotents e' ∧ f ∘ e' = e := by obtain ⟨e', h₁, h₂⟩ := lift_of_isNilpotent_ker_aux f h ((equiv (Fintype.equivFin I).symm).mpr he) (fun _ ↦ he' _) refine ⟨_, ((equiv (Fintype.equivFin I)).mpr h₁), by ext x; simpa using congr_fun h₂ (Fintype.equivFin I x)⟩ theorem eq_of_isNilpotent_sub_of_isIdempotentElem_of_commute {e₁ e₂ : R} (he₁ : IsIdempotentElem e₁) (he₂ : IsIdempotentElem e₂) (H : IsNilpotent (e₁ - e₂)) (H' : Commute e₁ e₂) : e₁ = e₂ := by have : (e₁ - e₂) ^ 3 = (e₁ - e₂) := by simp only [pow_succ, pow_zero, mul_sub, one_mul, sub_mul, he₁.eq, he₂.eq, H'.eq, mul_assoc] simp only [← mul_assoc, he₁.eq, he₂.eq] abel obtain ⟨n, hn⟩ := H have : (e₁ - e₂) ^ (2 * n + 1) = (e₁ - e₂) := by clear hn; induction n <;> simp [mul_add, add_assoc, pow_add _ (2 * _) 3, this, ← pow_succ, *] rwa [pow_succ, two_mul, pow_add, hn, zero_mul, zero_mul, eq_comm, sub_eq_zero] at this theorem CompleteOrthogonalIdempotents.of_ker_isNilpotent_of_isMulCentral (h : ∀ x ∈ RingHom.ker f, IsNilpotent x) (he : ∀ i, IsIdempotentElem (e i)) (he' : ∀ i, IsMulCentral (e i)) (he'' : CompleteOrthogonalIdempotents (f ∘ e)) : CompleteOrthogonalIdempotents e := by obtain ⟨e', h₁, h₂⟩ := lift_of_isNilpotent_ker f h he'' (fun _ ↦ ⟨_, rfl⟩) obtain rfl : e = e' := by ext i refine eq_of_isNilpotent_sub_of_isIdempotentElem_of_commute (he _) (h₁.idem _) (h _ ?_) ((he' i).comm _) simpa [RingHom.mem_ker, sub_eq_zero] using congr_fun h₂.symm i exact h₁ end Ring section CommRing variable {R S : Type*} [CommRing R] [Ring S] (f : R →+* S) theorem eq_of_isNilpotent_sub_of_isIdempotentElem {e₁ e₂ : R} (he₁ : IsIdempotentElem e₁) (he₂ : IsIdempotentElem e₂) (H : IsNilpotent (e₁ - e₂)) : e₁ = e₂ := eq_of_isNilpotent_sub_of_isIdempotentElem_of_commute he₁ he₂ H (.all _ _) theorem existsUnique_isIdempotentElem_eq_of_ker_isNilpotent (h : ∀ x ∈ RingHom.ker f, IsNilpotent x) (e : S) (he : e ∈ f.range) (he' : IsIdempotentElem e) : ∃! e' : R, IsIdempotentElem e' ∧ f e' = e := by obtain ⟨e', he₂, rfl⟩ := exists_isIdempotentElem_eq_of_ker_isNilpotent f h e he he' exact ⟨e', ⟨he₂, rfl⟩, fun x ⟨hx, hx'⟩ ↦ eq_of_isNilpotent_sub_of_isIdempotentElem hx he₂ (h _ (by rw [RingHom.mem_ker, map_sub, hx', sub_self]))⟩ /-- A family of orthogonal idempotents induces an surjection `R ≃+* ∏ R ⧸ ⟨1 - eᵢ⟩` -/ lemma OrthogonalIdempotents.surjective_pi {I : Type*} [Finite I] {e : I → R} (he : OrthogonalIdempotents e) : Function.Surjective (Pi.ringHom fun i ↦ Ideal.Quotient.mk (Ideal.span {1 - e i})) := by suffices Pairwise fun i j ↦ IsCoprime (Ideal.span {1 - e i}) (Ideal.span {1 - e j}) by intro x obtain ⟨x, rfl⟩ := Ideal.quotientInfToPiQuotient_surj this x obtain ⟨x, rfl⟩ := Ideal.Quotient.mk_surjective x exact ⟨x, by ext i; simp [Ideal.quotientInfToPiQuotient]⟩ intros i j hij rw [Ideal.isCoprime_span_singleton_iff] exact ⟨1, e i, by simp [mul_sub, sub_mul, he.ortho i j hij]⟩ variable {I : Type*} [Fintype I] {e : I → R} theorem CompleteOrthogonalIdempotents.of_ker_isNilpotent (h : ∀ x ∈ RingHom.ker f, IsNilpotent x) (he : ∀ i, IsIdempotentElem (e i)) (he' : CompleteOrthogonalIdempotents (f ∘ e)) : CompleteOrthogonalIdempotents e := of_ker_isNilpotent_of_isMulCentral f h he (fun _ ↦ Semigroup.mem_center_iff.mpr (mul_comm · _)) he' lemma OrthogonalIdempotents.prod_one_sub (he : OrthogonalIdempotents e) : ∏ i, (1 - e i) = 1 - ∑ i, e i := by classical induction' (@Finset.univ I _) using Finset.induction_on with a s has ih · simp · suffices (1 - e a) * (1 - ∑ i in s, e i) = 1 - (e a + ∑ i in s, e i) by simp [*] have : e a * ∑ i in s, e i = 0 := by rw [Finset.mul_sum, ← Finset.sum_const_zero (s := s)] exact Finset.sum_congr rfl fun j hj ↦ he.ortho a j (fun e ↦ has (e ▸ hj)) rw [sub_mul, mul_sub, mul_sub, one_mul, mul_one, one_mul, this, sub_zero, sub_sub, add_comm] lemma CompleteOrthogonalIdempotents.prod_one_sub (he : CompleteOrthogonalIdempotents e) : ∏ i, (1 - e i) = 0 := by rw [he.1.prod_one_sub, he.complete, sub_self] lemma CompleteOrthogonalIdempotents.of_prod_one_sub (he : OrthogonalIdempotents e) (he' : ∏ i, (1 - e i) = 0) : CompleteOrthogonalIdempotents e where __ := he complete := by rwa [he.prod_one_sub, sub_eq_zero, eq_comm] at he' /-- A family of complete orthogonal idempotents induces an isomorphism `R ≃+* ∏ R ⧸ ⟨1 - eᵢ⟩` -/ lemma CompleteOrthogonalIdempotents.bijective_pi (he : CompleteOrthogonalIdempotents e) : Function.Bijective (Pi.ringHom fun i ↦ Ideal.Quotient.mk (Ideal.span {1 - e i})) := by classical refine ⟨?_, he.1.surjective_pi⟩ rw [injective_iff_map_eq_zero] intro x hx simp [Function.funext_iff, Ideal.Quotient.eq_zero_iff_mem, Ideal.mem_span_singleton] at hx suffices ∀ s : Finset I, (∏ i in s, (1 - e i)) * x = x by rw [← this Finset.univ, he.prod_one_sub, zero_mul] refine fun s ↦ Finset.induction_on s (by simp) ?_ intros a s has e' suffices (1 - e a) * x = x by simp [has, mul_assoc, e', this] obtain ⟨c, rfl⟩ := hx a rw [← mul_assoc, (he.idem a).one_sub.eq] lemma CompleteOrthogonalIdempotents.bijective_pi' (he : CompleteOrthogonalIdempotents (1 - e ·)) : Function.Bijective (Pi.ringHom fun i ↦ Ideal.Quotient.mk (Ideal.span {e i})) := by obtain ⟨e', rfl, h⟩ : ∃ e' : I → R, (e' = e) ∧ Function.Bijective (Pi.ringHom fun i ↦ Ideal.Quotient.mk (Ideal.span {e' i})) := ⟨_, funext (by simp), he.bijective_pi⟩ exact h lemma bijective_pi_of_isIdempotentElem (e : I → R) (he : ∀ i, IsIdempotentElem (e i)) (he₁ : ∀ i j, i ≠ j → (1 - e i) * (1 - e j) = 0) (he₂ : ∏ i, e i = 0) : Function.Bijective (Pi.ringHom fun i ↦ Ideal.Quotient.mk (Ideal.span {e i})) := (CompleteOrthogonalIdempotents.of_prod_one_sub ⟨fun i ↦ (he i).one_sub, he₁⟩ (by simpa using he₂)).bijective_pi' end CommRing
RingTheory\IntegralDomain.lean
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Chris Hughes -/ import Mathlib.Algebra.GeomSum import Mathlib.Algebra.Polynomial.Roots import Mathlib.GroupTheory.SpecificGroups.Cyclic /-! # Integral domains Assorted theorems about integral domains. ## Main theorems * `isCyclic_of_subgroup_isDomain`: A finite subgroup of the units of an integral domain is cyclic. * `Fintype.fieldOfDomain`: A finite integral domain is a field. ## Notes Wedderburn's little theorem, which shows that all finite division rings are actually fields, is in `Mathlib.RingTheory.LittleWedderburn`. ## Tags integral domain, finite integral domain, finite field -/ section open Finset Polynomial Function Nat section CancelMonoidWithZero -- There doesn't seem to be a better home for these right now variable {M : Type*} [CancelMonoidWithZero M] [Finite M] theorem mul_right_bijective_of_finite₀ {a : M} (ha : a ≠ 0) : Bijective fun b => a * b := Finite.injective_iff_bijective.1 <| mul_right_injective₀ ha theorem mul_left_bijective_of_finite₀ {a : M} (ha : a ≠ 0) : Bijective fun b => b * a := Finite.injective_iff_bijective.1 <| mul_left_injective₀ ha /-- Every finite nontrivial cancel_monoid_with_zero is a group_with_zero. -/ def Fintype.groupWithZeroOfCancel (M : Type*) [CancelMonoidWithZero M] [DecidableEq M] [Fintype M] [Nontrivial M] : GroupWithZero M := { ‹Nontrivial M›, ‹CancelMonoidWithZero M› with inv := fun a => if h : a = 0 then 0 else Fintype.bijInv (mul_right_bijective_of_finite₀ h) 1 mul_inv_cancel := fun a ha => by simp only [Inv.inv, dif_neg ha] exact Fintype.rightInverse_bijInv _ _ inv_zero := by simp [Inv.inv, dif_pos rfl] } theorem exists_eq_pow_of_mul_eq_pow_of_coprime {R : Type*} [CommSemiring R] [IsDomain R] [GCDMonoid R] [Unique Rˣ] {a b c : R} {n : ℕ} (cp : IsCoprime a b) (h : a * b = c ^ n) : ∃ d : R, a = d ^ n := by refine exists_eq_pow_of_mul_eq_pow (isUnit_of_dvd_one ?_) h obtain ⟨x, y, hxy⟩ := cp rw [← hxy] exact -- Porting note: added `GCDMonoid.` twice dvd_add (dvd_mul_of_dvd_right (GCDMonoid.gcd_dvd_left _ _) _) (dvd_mul_of_dvd_right (GCDMonoid.gcd_dvd_right _ _) _) nonrec theorem Finset.exists_eq_pow_of_mul_eq_pow_of_coprime {ι R : Type*} [CommSemiring R] [IsDomain R] [GCDMonoid R] [Unique Rˣ] {n : ℕ} {c : R} {s : Finset ι} {f : ι → R} (h : ∀ i ∈ s, ∀ j ∈ s, i ≠ j → IsCoprime (f i) (f j)) (hprod : ∏ i ∈ s, f i = c ^ n) : ∀ i ∈ s, ∃ d : R, f i = d ^ n := by classical intro i hi rw [← insert_erase hi, prod_insert (not_mem_erase i s)] at hprod refine exists_eq_pow_of_mul_eq_pow_of_coprime (IsCoprime.prod_right fun j hj => h i hi j (erase_subset i s hj) fun hij => ?_) hprod rw [hij] at hj exact (s.not_mem_erase _) hj end CancelMonoidWithZero variable {R : Type*} {G : Type*} section Ring variable [Ring R] [IsDomain R] [Fintype R] /-- Every finite domain is a division ring. More generally, they are fields; this can be found in `Mathlib.RingTheory.LittleWedderburn`. -/ def Fintype.divisionRingOfIsDomain (R : Type*) [Ring R] [IsDomain R] [DecidableEq R] [Fintype R] : DivisionRing R where __ := Fintype.groupWithZeroOfCancel R __ := ‹Ring R› nnqsmul := _ qsmul := _ /-- Every finite commutative domain is a field. More generally, commutativity is not required: this can be found in `Mathlib.RingTheory.LittleWedderburn`. -/ def Fintype.fieldOfDomain (R) [CommRing R] [IsDomain R] [DecidableEq R] [Fintype R] : Field R := { Fintype.divisionRingOfIsDomain R, ‹CommRing R› with } theorem Finite.isField_of_domain (R) [CommRing R] [IsDomain R] [Finite R] : IsField R := by cases nonempty_fintype R exact @Field.toIsField R (@Fintype.fieldOfDomain R _ _ (Classical.decEq R) _) end Ring variable [CommRing R] [IsDomain R] [Group G] -- Porting note: Finset doesn't seem to have `{g ∈ univ | g^n = g₀}` notation anymore, -- so we have to use `Finset.filter` instead theorem card_nthRoots_subgroup_units [Fintype G] [DecidableEq G] (f : G →* R) (hf : Injective f) {n : ℕ} (hn : 0 < n) (g₀ : G) : Finset.card (Finset.univ.filter (fun g ↦ g^n = g₀)) ≤ Multiset.card (nthRoots n (f g₀)) := by haveI : DecidableEq R := Classical.decEq _ calc _ ≤ (nthRoots n (f g₀)).toFinset.card := card_le_card_of_injOn f (by aesop) hf.injOn _ ≤ _ := (nthRoots n (f g₀)).toFinset_card_le /-- A finite subgroup of the unit group of an integral domain is cyclic. -/ theorem isCyclic_of_subgroup_isDomain [Finite G] (f : G →* R) (hf : Injective f) : IsCyclic G := by classical cases nonempty_fintype G apply isCyclic_of_card_pow_eq_one_le intro n hn exact le_trans (card_nthRoots_subgroup_units f hf hn 1) (card_nthRoots n (f 1)) /-- The unit group of a finite integral domain is cyclic. To support `ℤˣ` and other infinite monoids with finite groups of units, this requires only `Finite Rˣ` rather than deducing it from `Finite R`. -/ instance [Finite Rˣ] : IsCyclic Rˣ := isCyclic_of_subgroup_isDomain (Units.coeHom R) <| Units.ext section variable (S : Subgroup Rˣ) [Finite S] /-- A finite subgroup of the units of an integral domain is cyclic. -/ instance subgroup_units_cyclic : IsCyclic S := by -- Porting note: the original proof used a `coe`, but I was not able to get it to work. apply isCyclic_of_subgroup_isDomain (R := R) (G := S) _ _ · exact MonoidHom.mk (OneHom.mk (fun s => ↑s.val) rfl) (by simp) · exact Units.ext.comp Subtype.val_injective end section EuclideanDivision namespace Polynomial open Polynomial variable (K : Type) [Field K] [Algebra R[X] K] [IsFractionRing R[X] K] theorem div_eq_quo_add_rem_div (f : R[X]) {g : R[X]} (hg : g.Monic) : ∃ q r : R[X], r.degree < g.degree ∧ (algebraMap R[X] K f) / (algebraMap R[X] K g) = algebraMap R[X] K q + (algebraMap R[X] K r) / (algebraMap R[X] K g) := by refine ⟨f /ₘ g, f %ₘ g, ?_, ?_⟩ · exact degree_modByMonic_lt _ hg · have hg' : algebraMap R[X] K g ≠ 0 := -- Porting note: the proof was `by exact_mod_cast Monic.ne_zero hg` (map_ne_zero_iff _ (IsFractionRing.injective R[X] K)).mpr (Monic.ne_zero hg) field_simp [hg'] -- Porting note: `norm_cast` was here, but does nothing. rw [add_comm, mul_comm, ← map_mul, ← map_add, modByMonic_add_div f hg] end Polynomial end EuclideanDivision variable [Fintype G] @[deprecated (since := "2024-06-10")] alias card_fiber_eq_of_mem_range := MonoidHom.card_fiber_eq_of_mem_range /-- In an integral domain, a sum indexed by a nontrivial homomorphism from a finite group is zero. -/ theorem sum_hom_units_eq_zero (f : G →* R) (hf : f ≠ 1) : ∑ g : G, f g = 0 := by classical obtain ⟨x, hx⟩ : ∃ x : MonoidHom.range f.toHomUnits, ∀ y : MonoidHom.range f.toHomUnits, y ∈ Submonoid.powers x := IsCyclic.exists_monoid_generator have hx1 : x ≠ 1 := by rintro rfl apply hf ext g rw [MonoidHom.one_apply] cases' hx ⟨f.toHomUnits g, g, rfl⟩ with n hn rwa [Subtype.ext_iff, Units.ext_iff, Subtype.coe_mk, MonoidHom.coe_toHomUnits, one_pow, eq_comm] at hn replace hx1 : (x.val : R) - 1 ≠ 0 := -- Porting note: was `(x : R)` fun h => hx1 (Subtype.eq (Units.ext (sub_eq_zero.1 h))) let c := (univ.filter fun g => f.toHomUnits g = 1).card calc ∑ g : G, f g = ∑ g : G, (f.toHomUnits g : R) := rfl _ = ∑ u ∈ univ.image f.toHomUnits, (univ.filter fun g => f.toHomUnits g = u).card • (u : R) := (sum_comp ((↑) : Rˣ → R) f.toHomUnits) _ = ∑ u ∈ univ.image f.toHomUnits, c • (u : R) := (sum_congr rfl fun u hu => congr_arg₂ _ ?_ rfl) -- remaining goal 1, proven below -- Porting note: have to change `(b : R)` into `((b : Rˣ) : R)` _ = ∑ b : MonoidHom.range f.toHomUnits, c • ((b : Rˣ) : R) := (Finset.sum_subtype _ (by simp) _) _ = c • ∑ b : MonoidHom.range f.toHomUnits, ((b : Rˣ) : R) := smul_sum.symm _ = c • (0 : R) := congr_arg₂ _ rfl ?_ -- remaining goal 2, proven below _ = (0 : R) := smul_zero _ · -- remaining goal 1 show (univ.filter fun g : G => f.toHomUnits g = u).card = c apply MonoidHom.card_fiber_eq_of_mem_range f.toHomUnits · simpa only [mem_image, mem_univ, true_and, Set.mem_range] using hu · exact ⟨1, f.toHomUnits.map_one⟩ -- remaining goal 2 show (∑ b : MonoidHom.range f.toHomUnits, ((b : Rˣ) : R)) = 0 calc (∑ b : MonoidHom.range f.toHomUnits, ((b : Rˣ) : R)) = ∑ n ∈ range (orderOf x), ((x : Rˣ) : R) ^ n := Eq.symm <| sum_nbij (x ^ ·) (by simp only [mem_univ, forall_true_iff]) (by simpa using pow_injOn_Iio_orderOf) (fun b _ => let ⟨n, hn⟩ := hx b ⟨n % orderOf x, mem_range.2 (Nat.mod_lt _ (orderOf_pos _)), -- Porting note: have to use `dsimp` to apply the function by dsimp at hn ⊢; rw [pow_mod_orderOf, hn]⟩) (by simp only [imp_true_iff, eq_self_iff_true, Subgroup.coe_pow, Units.val_pow_eq_pow_val]) _ = 0 := ?_ rw [← mul_left_inj' hx1, zero_mul, geom_sum_mul] norm_cast simp [pow_orderOf_eq_one] /-- In an integral domain, a sum indexed by a homomorphism from a finite group is zero, unless the homomorphism is trivial, in which case the sum is equal to the cardinality of the group. -/ theorem sum_hom_units (f : G →* R) [Decidable (f = 1)] : ∑ g : G, f g = if f = 1 then Fintype.card G else 0 := by split_ifs with h · simp [h, card_univ] · rw [cast_zero] -- Porting note: added exact sum_hom_units_eq_zero f h end
RingTheory\IsAdjoinRoot.lean
/- Copyright (c) 2022 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.FieldTheory.Minpoly.IsIntegrallyClosed import Mathlib.RingTheory.PowerBasis /-! # A predicate on adjoining roots of polynomial This file defines a predicate `IsAdjoinRoot S f`, which states that the ring `S` can be constructed by adjoining a specified root of the polynomial `f : R[X]` to `R`. This predicate is useful when the same ring can be generated by adjoining the root of different polynomials, and you want to vary which polynomial you're considering. The results in this file are intended to mirror those in `RingTheory.AdjoinRoot`, in order to provide an easier way to translate results from one to the other. ## Motivation `AdjoinRoot` presents one construction of a ring `R[α]`. However, it is possible to obtain rings of this form in many ways, such as `NumberField.ringOfIntegers ℚ(√-5)`, or `Algebra.adjoin R {α, α^2}`, or `IntermediateField.adjoin R {α, 2 - α}`, or even if we want to view `ℂ` as adjoining a root of `X^2 + 1` to `ℝ`. ## Main definitions The two main predicates in this file are: * `IsAdjoinRoot S f`: `S` is generated by adjoining a specified root of `f : R[X]` to `R` * `IsAdjoinRootMonic S f`: `S` is generated by adjoining a root of the monic polynomial `f : R[X]` to `R` Using `IsAdjoinRoot` to map into `S`: * `IsAdjoinRoot.map`: inclusion from `R[X]` to `S` * `IsAdjoinRoot.root`: the specific root adjoined to `R` to give `S` Using `IsAdjoinRoot` to map out of `S`: * `IsAdjoinRoot.repr`: choose a non-unique representative in `R[X]` * `IsAdjoinRoot.lift`, `IsAdjoinRoot.liftHom`: lift a morphism `R →+* T` to `S →+* T` * `IsAdjoinRootMonic.modByMonicHom`: a unique representative in `R[X]` if `f` is monic ## Main results * `AdjoinRoot.isAdjoinRoot` and `AdjoinRoot.isAdjoinRootMonic`: `AdjoinRoot` satisfies the conditions on `IsAdjoinRoot`(`_monic`) * `IsAdjoinRootMonic.powerBasis`: the `root` generates a power basis on `S` over `R` * `IsAdjoinRoot.aequiv`: algebra isomorphism showing adjoining a root gives a unique ring up to isomorphism * `IsAdjoinRoot.ofEquiv`: transfer `IsAdjoinRoot` across an algebra isomorphism * `IsAdjoinRootMonic.minpoly_eq`: the minimal polynomial of the adjoined root of `f` is equal to `f`, if `f` is irreducible and monic, and `R` is a GCD domain -/ open scoped Polynomial open Polynomial noncomputable section universe u v -- Porting note: this looks like something that should not be here -- section MoveMe -- -- end MoveMe -- This class doesn't really make sense on a predicate /-- `IsAdjoinRoot S f` states that the ring `S` can be constructed by adjoining a specified root of the polynomial `f : R[X]` to `R`. Compare `PowerBasis R S`, which does not explicitly specify which polynomial we adjoin a root of (in particular `f` does not need to be the minimal polynomial of the root we adjoin), and `AdjoinRoot` which constructs a new type. This is not a typeclass because the choice of root given `S` and `f` is not unique. -/ -- Porting note(#5171): this linter isn't ported yet. -- @[nolint has_nonempty_instance] structure IsAdjoinRoot {R : Type u} (S : Type v) [CommSemiring R] [Semiring S] [Algebra R S] (f : R[X]) : Type max u v where map : R[X] →+* S map_surjective : Function.Surjective map ker_map : RingHom.ker map = Ideal.span {f} algebraMap_eq : algebraMap R S = map.comp Polynomial.C -- This class doesn't really make sense on a predicate /-- `IsAdjoinRootMonic S f` states that the ring `S` can be constructed by adjoining a specified root of the monic polynomial `f : R[X]` to `R`. As long as `f` is monic, there is a well-defined representation of elements of `S` as polynomials in `R[X]` of degree lower than `deg f` (see `modByMonicHom` and `coeff`). In particular, we have `IsAdjoinRootMonic.powerBasis`. Bundling `Monic` into this structure is very useful when working with explicit `f`s such as `X^2 - C a * X - C b` since it saves you carrying around the proofs of monicity. -/ -- @[nolint has_nonempty_instance] -- Porting note: This linter does not exist yet. structure IsAdjoinRootMonic {R : Type u} (S : Type v) [CommSemiring R] [Semiring S] [Algebra R S] (f : R[X]) extends IsAdjoinRoot S f where Monic : Monic f section Ring variable {R : Type u} {S : Type v} [CommRing R] [Ring S] {f : R[X]} [Algebra R S] namespace IsAdjoinRoot /-- `(h : IsAdjoinRoot S f).root` is the root of `f` that can be adjoined to generate `S`. -/ def root (h : IsAdjoinRoot S f) : S := h.map X theorem subsingleton (h : IsAdjoinRoot S f) [Subsingleton R] : Subsingleton S := h.map_surjective.subsingleton theorem algebraMap_apply (h : IsAdjoinRoot S f) (x : R) : algebraMap R S x = h.map (Polynomial.C x) := by rw [h.algebraMap_eq, RingHom.comp_apply] @[simp] theorem mem_ker_map (h : IsAdjoinRoot S f) {p} : p ∈ RingHom.ker h.map ↔ f ∣ p := by rw [h.ker_map, Ideal.mem_span_singleton] theorem map_eq_zero_iff (h : IsAdjoinRoot S f) {p} : h.map p = 0 ↔ f ∣ p := by rw [← h.mem_ker_map, RingHom.mem_ker] @[simp] theorem map_X (h : IsAdjoinRoot S f) : h.map X = h.root := rfl @[simp] theorem map_self (h : IsAdjoinRoot S f) : h.map f = 0 := h.map_eq_zero_iff.mpr dvd_rfl @[simp] theorem aeval_eq (h : IsAdjoinRoot S f) (p : R[X]) : aeval h.root p = h.map p := Polynomial.induction_on p (fun x => by rw [aeval_C, h.algebraMap_apply]) (fun p q ihp ihq => by rw [map_add, RingHom.map_add, ihp, ihq]) fun n x _ => by rw [map_mul, aeval_C, map_pow, aeval_X, RingHom.map_mul, ← h.algebraMap_apply, RingHom.map_pow, map_X] -- @[simp] -- Porting note (#10618): simp can prove this theorem aeval_root (h : IsAdjoinRoot S f) : aeval h.root f = 0 := by rw [aeval_eq, map_self] /-- Choose an arbitrary representative so that `h.map (h.repr x) = x`. If `f` is monic, use `IsAdjoinRootMonic.modByMonicHom` for a unique choice of representative. -/ def repr (h : IsAdjoinRoot S f) (x : S) : R[X] := (h.map_surjective x).choose theorem map_repr (h : IsAdjoinRoot S f) (x : S) : h.map (h.repr x) = x := (h.map_surjective x).choose_spec /-- `repr` preserves zero, up to multiples of `f` -/ theorem repr_zero_mem_span (h : IsAdjoinRoot S f) : h.repr 0 ∈ Ideal.span ({f} : Set R[X]) := by rw [← h.ker_map, RingHom.mem_ker, h.map_repr] /-- `repr` preserves addition, up to multiples of `f` -/ theorem repr_add_sub_repr_add_repr_mem_span (h : IsAdjoinRoot S f) (x y : S) : h.repr (x + y) - (h.repr x + h.repr y) ∈ Ideal.span ({f} : Set R[X]) := by rw [← h.ker_map, RingHom.mem_ker, map_sub, h.map_repr, map_add, h.map_repr, h.map_repr, sub_self] /-- Extensionality of the `IsAdjoinRoot` structure itself. See `IsAdjoinRootMonic.ext_elem` for extensionality of the ring elements. -/ theorem ext_map (h h' : IsAdjoinRoot S f) (eq : ∀ x, h.map x = h'.map x) : h = h' := by cases h; cases h'; congr exact RingHom.ext eq /-- Extensionality of the `IsAdjoinRoot` structure itself. See `IsAdjoinRootMonic.ext_elem` for extensionality of the ring elements. -/ @[ext] theorem ext (h h' : IsAdjoinRoot S f) (eq : h.root = h'.root) : h = h' := h.ext_map h' fun x => by rw [← h.aeval_eq, ← h'.aeval_eq, eq] section lift variable {T : Type*} [CommRing T] {i : R →+* T} {x : T} (hx : f.eval₂ i x = 0) /-- Auxiliary lemma for `IsAdjoinRoot.lift` -/ theorem eval₂_repr_eq_eval₂_of_map_eq (h : IsAdjoinRoot S f) (z : S) (w : R[X]) (hzw : h.map w = z) : (h.repr z).eval₂ i x = w.eval₂ i x := by rw [eq_comm, ← sub_eq_zero, ← h.map_repr z, ← map_sub, h.map_eq_zero_iff] at hzw obtain ⟨y, hy⟩ := hzw rw [← sub_eq_zero, ← eval₂_sub, hy, eval₂_mul, hx, zero_mul] variable (i x) -- To match `AdjoinRoot.lift` /-- Lift a ring homomorphism `R →+* T` to `S →+* T` by specifying a root `x` of `f` in `T`, where `S` is given by adjoining a root of `f` to `R`. -/ def lift (h : IsAdjoinRoot S f) : S →+* T where toFun z := (h.repr z).eval₂ i x map_zero' := by dsimp only -- Porting note (#10752): added `dsimp only` rw [h.eval₂_repr_eq_eval₂_of_map_eq hx _ _ (map_zero _), eval₂_zero] map_add' z w := by dsimp only -- Porting note (#10752): added `dsimp only` rw [h.eval₂_repr_eq_eval₂_of_map_eq hx _ (h.repr z + h.repr w), eval₂_add] rw [map_add, map_repr, map_repr] map_one' := by beta_reduce -- Porting note (#12129): additional beta reduction needed rw [h.eval₂_repr_eq_eval₂_of_map_eq hx _ _ (map_one _), eval₂_one] map_mul' z w := by dsimp only -- Porting note (#10752): added `dsimp only` rw [h.eval₂_repr_eq_eval₂_of_map_eq hx _ (h.repr z * h.repr w), eval₂_mul] rw [map_mul, map_repr, map_repr] variable {i x} @[simp] theorem lift_map (h : IsAdjoinRoot S f) (z : R[X]) : h.lift i x hx (h.map z) = z.eval₂ i x := by rw [lift, RingHom.coe_mk] dsimp -- Porting note (#11227):added a `dsimp` rw [h.eval₂_repr_eq_eval₂_of_map_eq hx _ _ rfl] @[simp] theorem lift_root (h : IsAdjoinRoot S f) : h.lift i x hx h.root = x := by rw [← h.map_X, lift_map, eval₂_X] @[simp] theorem lift_algebraMap (h : IsAdjoinRoot S f) (a : R) : h.lift i x hx (algebraMap R S a) = i a := by rw [h.algebraMap_apply, lift_map, eval₂_C] /-- Auxiliary lemma for `apply_eq_lift` -/ theorem apply_eq_lift (h : IsAdjoinRoot S f) (g : S →+* T) (hmap : ∀ a, g (algebraMap R S a) = i a) (hroot : g h.root = x) (a : S) : g a = h.lift i x hx a := by rw [← h.map_repr a, Polynomial.as_sum_range_C_mul_X_pow (h.repr a)] simp only [map_sum, map_mul, map_pow, h.map_X, hroot, ← h.algebraMap_apply, hmap, lift_root, lift_algebraMap] /-- Unicity of `lift`: a map that agrees on `R` and `h.root` agrees with `lift` everywhere. -/ theorem eq_lift (h : IsAdjoinRoot S f) (g : S →+* T) (hmap : ∀ a, g (algebraMap R S a) = i a) (hroot : g h.root = x) : g = h.lift i x hx := RingHom.ext (h.apply_eq_lift hx g hmap hroot) variable [Algebra R T] (hx' : aeval x f = 0) variable (x) -- To match `AdjoinRoot.liftHom` /-- Lift the algebra map `R → T` to `S →ₐ[R] T` by specifying a root `x` of `f` in `T`, where `S` is given by adjoining a root of `f` to `R`. -/ def liftHom (h : IsAdjoinRoot S f) : S →ₐ[R] T := { h.lift (algebraMap R T) x hx' with commutes' := fun a => h.lift_algebraMap hx' a } variable {x} @[simp] theorem coe_liftHom (h : IsAdjoinRoot S f) : (h.liftHom x hx' : S →+* T) = h.lift (algebraMap R T) x hx' := rfl theorem lift_algebraMap_apply (h : IsAdjoinRoot S f) (z : S) : h.lift (algebraMap R T) x hx' z = h.liftHom x hx' z := rfl @[simp] theorem liftHom_map (h : IsAdjoinRoot S f) (z : R[X]) : h.liftHom x hx' (h.map z) = aeval x z := by rw [← lift_algebraMap_apply, lift_map, aeval_def] @[simp] theorem liftHom_root (h : IsAdjoinRoot S f) : h.liftHom x hx' h.root = x := by rw [← lift_algebraMap_apply, lift_root] /-- Unicity of `liftHom`: a map that agrees on `h.root` agrees with `liftHom` everywhere. -/ theorem eq_liftHom (h : IsAdjoinRoot S f) (g : S →ₐ[R] T) (hroot : g h.root = x) : g = h.liftHom x hx' := AlgHom.ext (h.apply_eq_lift hx' g g.commutes hroot) end lift end IsAdjoinRoot namespace AdjoinRoot variable (f) /-- `AdjoinRoot f` is indeed given by adjoining a root of `f`. -/ protected def isAdjoinRoot : IsAdjoinRoot (AdjoinRoot f) f where map := AdjoinRoot.mk f map_surjective := Ideal.Quotient.mk_surjective ker_map := by ext rw [RingHom.mem_ker, ← @AdjoinRoot.mk_self _ _ f, AdjoinRoot.mk_eq_mk, Ideal.mem_span_singleton, ← dvd_add_left (dvd_refl f), sub_add_cancel] algebraMap_eq := AdjoinRoot.algebraMap_eq f /-- `AdjoinRoot f` is indeed given by adjoining a root of `f`. If `f` is monic this is more powerful than `AdjoinRoot.isAdjoinRoot`. -/ protected def isAdjoinRootMonic (hf : Monic f) : IsAdjoinRootMonic (AdjoinRoot f) f := { AdjoinRoot.isAdjoinRoot f with Monic := hf } @[simp] theorem isAdjoinRoot_map_eq_mk : (AdjoinRoot.isAdjoinRoot f).map = AdjoinRoot.mk f := rfl @[simp] theorem isAdjoinRootMonic_map_eq_mk (hf : f.Monic) : (AdjoinRoot.isAdjoinRootMonic f hf).map = AdjoinRoot.mk f := rfl @[simp] theorem isAdjoinRoot_root_eq_root : (AdjoinRoot.isAdjoinRoot f).root = AdjoinRoot.root f := by simp only [IsAdjoinRoot.root, AdjoinRoot.root, AdjoinRoot.isAdjoinRoot_map_eq_mk] @[simp] theorem isAdjoinRootMonic_root_eq_root (hf : Monic f) : (AdjoinRoot.isAdjoinRootMonic f hf).root = AdjoinRoot.root f := by simp only [IsAdjoinRoot.root, AdjoinRoot.root, AdjoinRoot.isAdjoinRootMonic_map_eq_mk] end AdjoinRoot namespace IsAdjoinRootMonic open IsAdjoinRoot theorem map_modByMonic (h : IsAdjoinRootMonic S f) (g : R[X]) : h.map (g %ₘ f) = h.map g := by rw [← RingHom.sub_mem_ker_iff, mem_ker_map, modByMonic_eq_sub_mul_div _ h.Monic, sub_right_comm, sub_self, zero_sub, dvd_neg] exact ⟨_, rfl⟩ theorem modByMonic_repr_map (h : IsAdjoinRootMonic S f) (g : R[X]) : h.repr (h.map g) %ₘ f = g %ₘ f := modByMonic_eq_of_dvd_sub h.Monic <| by rw [← h.mem_ker_map, RingHom.sub_mem_ker_iff, map_repr] /-- `IsAdjoinRoot.modByMonicHom` sends the equivalence class of `f` mod `g` to `f %ₘ g`. -/ def modByMonicHom (h : IsAdjoinRootMonic S f) : S →ₗ[R] R[X] where toFun x := h.repr x %ₘ f map_add' x y := by conv_lhs => rw [← h.map_repr x, ← h.map_repr y, ← map_add] beta_reduce -- Porting note (#12129): additional beta reduction needed rw [h.modByMonic_repr_map, add_modByMonic] map_smul' c x := by rw [RingHom.id_apply, ← h.map_repr x, Algebra.smul_def, h.algebraMap_apply, ← map_mul] dsimp only -- Porting note (#10752): added `dsimp only` rw [h.modByMonic_repr_map, ← smul_eq_C_mul, smul_modByMonic, h.map_repr] @[simp] theorem modByMonicHom_map (h : IsAdjoinRootMonic S f) (g : R[X]) : h.modByMonicHom (h.map g) = g %ₘ f := h.modByMonic_repr_map g @[simp] theorem map_modByMonicHom (h : IsAdjoinRootMonic S f) (x : S) : h.map (h.modByMonicHom x) = x := by rw [modByMonicHom, LinearMap.coe_mk] dsimp -- Porting note (#11227):added a `dsimp` rw [map_modByMonic, map_repr] @[simp] theorem modByMonicHom_root_pow (h : IsAdjoinRootMonic S f) {n : ℕ} (hdeg : n < natDegree f) : h.modByMonicHom (h.root ^ n) = X ^ n := by nontriviality R rw [← h.map_X, ← map_pow, modByMonicHom_map, modByMonic_eq_self_iff h.Monic, degree_X_pow] contrapose! hdeg simpa [natDegree_le_iff_degree_le] using hdeg @[simp] theorem modByMonicHom_root (h : IsAdjoinRootMonic S f) (hdeg : 1 < natDegree f) : h.modByMonicHom h.root = X := by simpa using modByMonicHom_root_pow h hdeg /-- The basis on `S` generated by powers of `h.root`. Auxiliary definition for `IsAdjoinRootMonic.powerBasis`. -/ def basis (h : IsAdjoinRootMonic S f) : Basis (Fin (natDegree f)) R S := Basis.ofRepr { toFun := fun x => (h.modByMonicHom x).toFinsupp.comapDomain _ Fin.val_injective.injOn invFun := fun g => h.map (ofFinsupp (g.mapDomain _)) left_inv := fun x => by cases subsingleton_or_nontrivial R · subsingleton [h.subsingleton] simp only rw [Finsupp.mapDomain_comapDomain, Polynomial.eta, h.map_modByMonicHom x] · exact Fin.val_injective intro i hi refine Set.mem_range.mpr ⟨⟨i, ?_⟩, rfl⟩ contrapose! hi simp only [Polynomial.toFinsupp_apply, Classical.not_not, Finsupp.mem_support_iff, Ne, modByMonicHom, LinearMap.coe_mk, Finset.mem_coe] by_cases hx : h.toIsAdjoinRoot.repr x %ₘ f = 0 · simp [hx] refine coeff_eq_zero_of_natDegree_lt (lt_of_lt_of_le ?_ hi) dsimp -- Porting note (#11227):added a `dsimp` rw [natDegree_lt_natDegree_iff hx] exact degree_modByMonic_lt _ h.Monic right_inv := fun g => by nontriviality R ext i simp only [h.modByMonicHom_map, Finsupp.comapDomain_apply, Polynomial.toFinsupp_apply] rw [(Polynomial.modByMonic_eq_self_iff h.Monic).mpr, Polynomial.coeff] · dsimp only -- Porting note (#10752): added `dsimp only` rw [Finsupp.mapDomain_apply Fin.val_injective] rw [degree_eq_natDegree h.Monic.ne_zero, degree_lt_iff_coeff_zero] intro m hm rw [Polynomial.coeff] dsimp only -- Porting note (#10752): added `dsimp only` rw [Finsupp.mapDomain_notin_range] rw [Set.mem_range, not_exists] rintro i rfl exact i.prop.not_le hm map_add' := fun x y => by beta_reduce -- Porting note (#12129): additional beta reduction needed rw [map_add, toFinsupp_add, Finsupp.comapDomain_add_of_injective Fin.val_injective] -- Porting note: the original simp proof with the same lemmas does not work -- See https://github.com/leanprover-community/mathlib4/issues/5026 -- simp only [map_add, Finsupp.comapDomain_add_of_injective Fin.val_injective, toFinsupp_add] map_smul' := fun c x => by dsimp only -- Porting note (#10752): added `dsimp only` rw [map_smul, toFinsupp_smul, Finsupp.comapDomain_smul_of_injective Fin.val_injective, RingHom.id_apply] } -- Porting note: the original simp proof with the same lemmas does not work -- See https://github.com/leanprover-community/mathlib4/issues/5026 -- simp only [map_smul, Finsupp.comapDomain_smul_of_injective Fin.val_injective, -- RingHom.id_apply, toFinsupp_smul] } @[simp] theorem basis_apply (h : IsAdjoinRootMonic S f) (i) : h.basis i = h.root ^ (i : ℕ) := Basis.apply_eq_iff.mpr <| show (h.modByMonicHom (h.toIsAdjoinRoot.root ^ (i : ℕ))).toFinsupp.comapDomain _ Fin.val_injective.injOn = Finsupp.single _ _ by ext j rw [Finsupp.comapDomain_apply, modByMonicHom_root_pow] · rw [X_pow_eq_monomial, toFinsupp_monomial, Finsupp.single_apply_left Fin.val_injective] · exact i.is_lt theorem deg_pos [Nontrivial S] (h : IsAdjoinRootMonic S f) : 0 < natDegree f := by rcases h.basis.index_nonempty with ⟨⟨i, hi⟩⟩ exact (Nat.zero_le _).trans_lt hi theorem deg_ne_zero [Nontrivial S] (h : IsAdjoinRootMonic S f) : natDegree f ≠ 0 := h.deg_pos.ne' /-- If `f` is monic, the powers of `h.root` form a basis. -/ @[simps! gen dim basis] def powerBasis (h : IsAdjoinRootMonic S f) : PowerBasis R S where gen := h.root dim := natDegree f basis := h.basis basis_eq_pow := h.basis_apply @[simp] theorem basis_repr (h : IsAdjoinRootMonic S f) (x : S) (i : Fin (natDegree f)) : h.basis.repr x i = (h.modByMonicHom x).coeff (i : ℕ) := by change (h.modByMonicHom x).toFinsupp.comapDomain _ Fin.val_injective.injOn i = _ rw [Finsupp.comapDomain_apply, Polynomial.toFinsupp_apply] theorem basis_one (h : IsAdjoinRootMonic S f) (hdeg : 1 < natDegree f) : h.basis ⟨1, hdeg⟩ = h.root := by rw [h.basis_apply, Fin.val_mk, pow_one] /-- `IsAdjoinRootMonic.liftPolyₗ` lifts a linear map on polynomials to a linear map on `S`. -/ @[simps!] def liftPolyₗ {T : Type*} [AddCommGroup T] [Module R T] (h : IsAdjoinRootMonic S f) (g : R[X] →ₗ[R] T) : S →ₗ[R] T := g.comp h.modByMonicHom /-- `IsAdjoinRootMonic.coeff h x i` is the `i`th coefficient of the representative of `x : S`. -/ def coeff (h : IsAdjoinRootMonic S f) : S →ₗ[R] ℕ → R := h.liftPolyₗ { toFun := Polynomial.coeff map_add' := fun p q => funext (Polynomial.coeff_add p q) map_smul' := fun c p => funext (Polynomial.coeff_smul c p) } theorem coeff_apply_lt (h : IsAdjoinRootMonic S f) (z : S) (i : ℕ) (hi : i < natDegree f) : h.coeff z i = h.basis.repr z ⟨i, hi⟩ := by simp only [coeff, LinearMap.comp_apply, Finsupp.lcoeFun_apply, Finsupp.lmapDomain_apply, LinearEquiv.coe_coe, liftPolyₗ_apply, LinearMap.coe_mk, h.basis_repr] rfl theorem coeff_apply_coe (h : IsAdjoinRootMonic S f) (z : S) (i : Fin (natDegree f)) : h.coeff z i = h.basis.repr z i := h.coeff_apply_lt z i i.prop theorem coeff_apply_le (h : IsAdjoinRootMonic S f) (z : S) (i : ℕ) (hi : natDegree f ≤ i) : h.coeff z i = 0 := by simp only [coeff, LinearMap.comp_apply, Finsupp.lcoeFun_apply, Finsupp.lmapDomain_apply, LinearEquiv.coe_coe, liftPolyₗ_apply, LinearMap.coe_mk, h.basis_repr] nontriviality R exact Polynomial.coeff_eq_zero_of_degree_lt ((degree_modByMonic_lt _ h.Monic).trans_le (Polynomial.degree_le_of_natDegree_le hi)) theorem coeff_apply (h : IsAdjoinRootMonic S f) (z : S) (i : ℕ) : h.coeff z i = if hi : i < natDegree f then h.basis.repr z ⟨i, hi⟩ else 0 := by split_ifs with hi · exact h.coeff_apply_lt z i hi · exact h.coeff_apply_le z i (le_of_not_lt hi) theorem coeff_root_pow (h : IsAdjoinRootMonic S f) {n} (hn : n < natDegree f) : h.coeff (h.root ^ n) = Pi.single n 1 := by ext i rw [coeff_apply] split_ifs with hi · calc h.basis.repr (h.root ^ n) ⟨i, _⟩ = h.basis.repr (h.basis ⟨n, hn⟩) ⟨i, hi⟩ := by rw [h.basis_apply, Fin.val_mk] _ = Pi.single (f := fun _ => R) ((⟨n, hn⟩ : Fin _) : ℕ) (1 : (fun _ => R) n) ↑(⟨i, _⟩ : Fin _) := by rw [h.basis.repr_self, ← Finsupp.single_eq_pi_single, Finsupp.single_apply_left Fin.val_injective] _ = Pi.single (f := fun _ => R) n 1 i := by rw [Fin.val_mk, Fin.val_mk] · refine (Pi.single_eq_of_ne (f := fun _ => R) ?_ (1 : (fun _ => R) n)).symm rintro rfl simp [hi] at hn theorem coeff_one [Nontrivial S] (h : IsAdjoinRootMonic S f) : h.coeff 1 = Pi.single 0 1 := by rw [← h.coeff_root_pow h.deg_pos, pow_zero] theorem coeff_root (h : IsAdjoinRootMonic S f) (hdeg : 1 < natDegree f) : h.coeff h.root = Pi.single 1 1 := by rw [← h.coeff_root_pow hdeg, pow_one] theorem coeff_algebraMap [Nontrivial S] (h : IsAdjoinRootMonic S f) (x : R) : h.coeff (algebraMap R S x) = Pi.single 0 x := by ext i rw [Algebra.algebraMap_eq_smul_one, map_smul, coeff_one, Pi.smul_apply, smul_eq_mul] refine (Pi.apply_single (fun _ y => x * y) ?_ 0 1 i).trans (by simp) simp theorem ext_elem (h : IsAdjoinRootMonic S f) ⦃x y : S⦄ (hxy : ∀ i < natDegree f, h.coeff x i = h.coeff y i) : x = y := EquivLike.injective h.basis.equivFun <| funext fun i => by rw [Basis.equivFun_apply, ← h.coeff_apply_coe, Basis.equivFun_apply, ← h.coeff_apply_coe, hxy i i.prop] theorem ext_elem_iff (h : IsAdjoinRootMonic S f) {x y : S} : x = y ↔ ∀ i < natDegree f, h.coeff x i = h.coeff y i := ⟨fun hxy _ _=> hxy ▸ rfl, fun hxy => h.ext_elem hxy⟩ theorem coeff_injective (h : IsAdjoinRootMonic S f) : Function.Injective h.coeff := fun _ _ hxy => h.ext_elem fun _ _ => hxy ▸ rfl theorem isIntegral_root (h : IsAdjoinRootMonic S f) : IsIntegral R h.root := ⟨f, h.Monic, h.aeval_root⟩ end IsAdjoinRootMonic end Ring section CommRing variable {R : Type u} {S : Type v} [CommRing R] [CommRing S] [Algebra R S] {f : R[X]} namespace IsAdjoinRoot section lift @[simp] theorem lift_self_apply (h : IsAdjoinRoot S f) (x : S) : h.lift (algebraMap R S) h.root h.aeval_root x = x := by rw [← h.map_repr x, lift_map, ← aeval_def, h.aeval_eq] theorem lift_self (h : IsAdjoinRoot S f) : h.lift (algebraMap R S) h.root h.aeval_root = RingHom.id S := RingHom.ext h.lift_self_apply end lift section Equiv variable {T : Type*} [CommRing T] [Algebra R T] /-- Adjoining a root gives a unique ring up to algebra isomorphism. This is the converse of `IsAdjoinRoot.ofEquiv`: this turns an `IsAdjoinRoot` into an `AlgEquiv`, and `IsAdjoinRoot.ofEquiv` turns an `AlgEquiv` into an `IsAdjoinRoot`. -/ def aequiv (h : IsAdjoinRoot S f) (h' : IsAdjoinRoot T f) : S ≃ₐ[R] T := { h.liftHom h'.root h'.aeval_root with toFun := h.liftHom h'.root h'.aeval_root invFun := h'.liftHom h.root h.aeval_root left_inv := fun x => by rw [← h.map_repr x, liftHom_map, aeval_eq, liftHom_map, aeval_eq] right_inv := fun x => by rw [← h'.map_repr x, liftHom_map, aeval_eq, liftHom_map, aeval_eq] } @[simp] theorem aequiv_map (h : IsAdjoinRoot S f) (h' : IsAdjoinRoot T f) (z : R[X]) : h.aequiv h' (h.map z) = h'.map z := by rw [aequiv, AlgEquiv.coe_mk, Equiv.coe_fn_mk, liftHom_map, aeval_eq] @[simp] theorem aequiv_root (h : IsAdjoinRoot S f) (h' : IsAdjoinRoot T f) : h.aequiv h' h.root = h'.root := by rw [aequiv, AlgEquiv.coe_mk, Equiv.coe_fn_mk, liftHom_root] @[simp] theorem aequiv_self (h : IsAdjoinRoot S f) : h.aequiv h = AlgEquiv.refl := by ext a; exact h.lift_self_apply a @[simp] theorem aequiv_symm (h : IsAdjoinRoot S f) (h' : IsAdjoinRoot T f) : (h.aequiv h').symm = h'.aequiv h := by ext; rfl @[simp] theorem lift_aequiv {U : Type*} [CommRing U] (h : IsAdjoinRoot S f) (h' : IsAdjoinRoot T f) (i : R →+* U) (x hx z) : h'.lift i x hx (h.aequiv h' z) = h.lift i x hx z := by rw [← h.map_repr z, aequiv_map, lift_map, lift_map] @[simp] theorem liftHom_aequiv {U : Type*} [CommRing U] [Algebra R U] (h : IsAdjoinRoot S f) (h' : IsAdjoinRoot T f) (x : U) (hx z) : h'.liftHom x hx (h.aequiv h' z) = h.liftHom x hx z := h.lift_aequiv h' _ _ hx _ @[simp] theorem aequiv_aequiv {U : Type*} [CommRing U] [Algebra R U] (h : IsAdjoinRoot S f) (h' : IsAdjoinRoot T f) (h'' : IsAdjoinRoot U f) (x) : (h'.aequiv h'') (h.aequiv h' x) = h.aequiv h'' x := h.liftHom_aequiv _ _ h''.aeval_root _ @[simp] theorem aequiv_trans {U : Type*} [CommRing U] [Algebra R U] (h : IsAdjoinRoot S f) (h' : IsAdjoinRoot T f) (h'' : IsAdjoinRoot U f) : (h.aequiv h').trans (h'.aequiv h'') = h.aequiv h'' := by ext z; exact h.aequiv_aequiv h' h'' z /-- Transfer `IsAdjoinRoot` across an algebra isomorphism. This is the converse of `IsAdjoinRoot.aequiv`: this turns an `AlgEquiv` into an `IsAdjoinRoot`, and `IsAdjoinRoot.aequiv` turns an `IsAdjoinRoot` into an `AlgEquiv`. -/ @[simps! map_apply] def ofEquiv (h : IsAdjoinRoot S f) (e : S ≃ₐ[R] T) : IsAdjoinRoot T f where map := ((e : S ≃+* T) : S →+* T).comp h.map map_surjective := e.surjective.comp h.map_surjective ker_map := by rw [← RingHom.comap_ker, RingHom.ker_coe_equiv, ← RingHom.ker_eq_comap_bot, h.ker_map] algebraMap_eq := by ext simp only [AlgEquiv.commutes, RingHom.comp_apply, AlgEquiv.coe_ringEquiv, RingEquiv.coe_toRingHom, ← h.algebraMap_apply] @[simp] theorem ofEquiv_root (h : IsAdjoinRoot S f) (e : S ≃ₐ[R] T) : (h.ofEquiv e).root = e h.root := rfl @[simp] theorem aequiv_ofEquiv {U : Type*} [CommRing U] [Algebra R U] (h : IsAdjoinRoot S f) (h' : IsAdjoinRoot T f) (e : T ≃ₐ[R] U) : h.aequiv (h'.ofEquiv e) = (h.aequiv h').trans e := by ext a; rw [← h.map_repr a, aequiv_map, AlgEquiv.trans_apply, aequiv_map, ofEquiv_map_apply] @[simp] theorem ofEquiv_aequiv {U : Type*} [CommRing U] [Algebra R U] (h : IsAdjoinRoot S f) (h' : IsAdjoinRoot U f) (e : S ≃ₐ[R] T) : (h.ofEquiv e).aequiv h' = e.symm.trans (h.aequiv h') := by ext a rw [← (h.ofEquiv e).map_repr a, aequiv_map, AlgEquiv.trans_apply, ofEquiv_map_apply, e.symm_apply_apply, aequiv_map] end Equiv end IsAdjoinRoot namespace IsAdjoinRootMonic theorem minpoly_eq [IsDomain R] [IsDomain S] [NoZeroSMulDivisors R S] [IsIntegrallyClosed R] (h : IsAdjoinRootMonic S f) (hirr : Irreducible f) : minpoly R h.root = f := let ⟨q, hq⟩ := minpoly.isIntegrallyClosed_dvd h.isIntegral_root h.aeval_root symm <| eq_of_monic_of_associated h.Monic (minpoly.monic h.isIntegral_root) <| by convert Associated.mul_left (minpoly R h.root) <| associated_one_iff_isUnit.2 <| (hirr.isUnit_or_isUnit hq).resolve_left <| minpoly.not_isUnit R h.root rw [mul_one] end IsAdjoinRootMonic section Algebra open AdjoinRoot IsAdjoinRoot minpoly PowerBasis IsAdjoinRootMonic Algebra theorem Algebra.adjoin.powerBasis'_minpoly_gen [IsDomain R] [IsDomain S] [NoZeroSMulDivisors R S] [IsIntegrallyClosed R] {x : S} (hx' : IsIntegral R x) : minpoly R x = minpoly R (Algebra.adjoin.powerBasis' hx').gen := by haveI := isDomain_of_prime (prime_of_isIntegrallyClosed hx') haveI := noZeroSMulDivisors_of_prime_of_degree_ne_zero (prime_of_isIntegrallyClosed hx') (ne_of_lt (degree_pos hx')).symm rw [← minpolyGen_eq, adjoin.powerBasis', minpolyGen_map, minpolyGen_eq, AdjoinRoot.powerBasis'_gen, ← isAdjoinRootMonic_root_eq_root _ (monic hx'), minpoly_eq] exact irreducible hx' end Algebra end CommRing
RingTheory\IsTensorProduct.lean
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.RingTheory.TensorProduct.Basic import Mathlib.Algebra.Module.ULift /-! # The characteristic predicate of tensor product ## Main definitions - `IsTensorProduct`: A predicate on `f : M₁ →ₗ[R] M₂ →ₗ[R] M` expressing that `f` realizes `M` as the tensor product of `M₁ ⊗[R] M₂`. This is defined by requiring the lift `M₁ ⊗[R] M₂ → M` to be bijective. - `IsBaseChange`: A predicate on an `R`-algebra `S` and a map `f : M →ₗ[R] N` with `N` being an `S`-module, expressing that `f` realizes `N` as the base change of `M` along `R → S`. - `Algebra.IsPushout`: A predicate on the following diagram of scalar towers ``` R → S ↓ ↓ R' → S' ``` asserting that is a pushout diagram (i.e. `S' = S ⊗[R] R'`) ## Main results - `TensorProduct.isBaseChange`: `S ⊗[R] M` is the base change of `M` along `R → S`. -/ universe u v₁ v₂ v₃ v₄ open TensorProduct section IsTensorProduct variable {R : Type*} [CommSemiring R] variable {M₁ M₂ M M' : Type*} variable [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M] [AddCommMonoid M'] variable [Module R M₁] [Module R M₂] [Module R M] [Module R M'] variable (f : M₁ →ₗ[R] M₂ →ₗ[R] M) variable {N₁ N₂ N : Type*} [AddCommMonoid N₁] [AddCommMonoid N₂] [AddCommMonoid N] variable [Module R N₁] [Module R N₂] [Module R N] variable {g : N₁ →ₗ[R] N₂ →ₗ[R] N} /-- Given a bilinear map `f : M₁ →ₗ[R] M₂ →ₗ[R] M`, `IsTensorProduct f` means that `M` is the tensor product of `M₁` and `M₂` via `f`. This is defined by requiring the lift `M₁ ⊗[R] M₂ → M` to be bijective. -/ def IsTensorProduct : Prop := Function.Bijective (TensorProduct.lift f) variable (R M N) {f} theorem TensorProduct.isTensorProduct : IsTensorProduct (TensorProduct.mk R M N) := by delta IsTensorProduct convert_to Function.Bijective (LinearMap.id : M ⊗[R] N →ₗ[R] M ⊗[R] N) using 2 · apply TensorProduct.ext' simp · exact Function.bijective_id variable {R M N} /-- If `M` is the tensor product of `M₁` and `M₂`, it is linearly equivalent to `M₁ ⊗[R] M₂`. -/ @[simps! apply] noncomputable def IsTensorProduct.equiv (h : IsTensorProduct f) : M₁ ⊗[R] M₂ ≃ₗ[R] M := LinearEquiv.ofBijective _ h @[simp] theorem IsTensorProduct.equiv_toLinearMap (h : IsTensorProduct f) : h.equiv.toLinearMap = TensorProduct.lift f := rfl @[simp] theorem IsTensorProduct.equiv_symm_apply (h : IsTensorProduct f) (x₁ : M₁) (x₂ : M₂) : h.equiv.symm (f x₁ x₂) = x₁ ⊗ₜ x₂ := by apply h.equiv.injective refine (h.equiv.apply_symm_apply _).trans ?_ simp /-- If `M` is the tensor product of `M₁` and `M₂`, we may lift a bilinear map `M₁ →ₗ[R] M₂ →ₗ[R] M'` to a `M →ₗ[R] M'`. -/ noncomputable def IsTensorProduct.lift (h : IsTensorProduct f) (f' : M₁ →ₗ[R] M₂ →ₗ[R] M') : M →ₗ[R] M' := (TensorProduct.lift f').comp h.equiv.symm.toLinearMap theorem IsTensorProduct.lift_eq (h : IsTensorProduct f) (f' : M₁ →ₗ[R] M₂ →ₗ[R] M') (x₁ : M₁) (x₂ : M₂) : h.lift f' (f x₁ x₂) = f' x₁ x₂ := by delta IsTensorProduct.lift simp /-- The tensor product of a pair of linear maps between modules. -/ noncomputable def IsTensorProduct.map (hf : IsTensorProduct f) (hg : IsTensorProduct g) (i₁ : M₁ →ₗ[R] N₁) (i₂ : M₂ →ₗ[R] N₂) : M →ₗ[R] N := hg.equiv.toLinearMap.comp ((TensorProduct.map i₁ i₂).comp hf.equiv.symm.toLinearMap) theorem IsTensorProduct.map_eq (hf : IsTensorProduct f) (hg : IsTensorProduct g) (i₁ : M₁ →ₗ[R] N₁) (i₂ : M₂ →ₗ[R] N₂) (x₁ : M₁) (x₂ : M₂) : hf.map hg i₁ i₂ (f x₁ x₂) = g (i₁ x₁) (i₂ x₂) := by delta IsTensorProduct.map simp theorem IsTensorProduct.inductionOn (h : IsTensorProduct f) {C : M → Prop} (m : M) (h0 : C 0) (htmul : ∀ x y, C (f x y)) (hadd : ∀ x y, C x → C y → C (x + y)) : C m := by rw [← h.equiv.right_inv m] generalize h.equiv.invFun m = y change C (TensorProduct.lift f y) induction y with | zero => rwa [map_zero] | tmul _ _ => rw [TensorProduct.lift.tmul] apply htmul | add _ _ _ _ => rw [map_add] apply hadd <;> assumption end IsTensorProduct section IsBaseChange variable {R : Type*} {M : Type v₁} {N : Type v₂} (S : Type v₃) variable [AddCommMonoid M] [AddCommMonoid N] [CommSemiring R] variable [CommSemiring S] [Algebra R S] [Module R M] [Module R N] [Module S N] [IsScalarTower R S N] variable (f : M →ₗ[R] N) /-- Given an `R`-algebra `S` and an `R`-module `M`, an `S`-module `N` together with a map `f : M →ₗ[R] N` is the base change of `M` to `S` if the map `S × M → N, (s, m) ↦ s • f m` is the tensor product. -/ def IsBaseChange : Prop := IsTensorProduct (((Algebra.linearMap S <| Module.End S (M →ₗ[R] N)).flip f).restrictScalars R) -- Porting note: split `variable` variable {S f} variable (h : IsBaseChange S f) variable {P Q : Type*} [AddCommMonoid P] [Module R P] variable [AddCommMonoid Q] [Module S Q] section variable [Module R Q] [IsScalarTower R S Q] /-- Suppose `f : M →ₗ[R] N` is the base change of `M` along `R → S`. Then any `R`-linear map from `M` to an `S`-module factors through `f`. -/ noncomputable nonrec def IsBaseChange.lift (g : M →ₗ[R] Q) : N →ₗ[S] Q := { h.lift (((Algebra.linearMap S <| Module.End S (M →ₗ[R] Q)).flip g).restrictScalars R) with map_smul' := fun r x => by let F := ((Algebra.linearMap S <| Module.End S (M →ₗ[R] Q)).flip g).restrictScalars R have hF : ∀ (s : S) (m : M), h.lift F (s • f m) = s • g m := h.lift_eq F change h.lift F (r • x) = r • h.lift F x apply h.inductionOn x · rw [smul_zero, map_zero, smul_zero] · intro s m change h.lift F (r • s • f m) = r • h.lift F (s • f m) rw [← mul_smul, hF, hF, mul_smul] · intro x₁ x₂ e₁ e₂ rw [map_add, smul_add, map_add, smul_add, e₁, e₂] } nonrec theorem IsBaseChange.lift_eq (g : M →ₗ[R] Q) (x : M) : h.lift g (f x) = g x := by have hF : ∀ (s : S) (m : M), h.lift g (s • f m) = s • g m := h.lift_eq _ convert hF 1 x <;> rw [one_smul] theorem IsBaseChange.lift_comp (g : M →ₗ[R] Q) : ((h.lift g).restrictScalars R).comp f = g := LinearMap.ext (h.lift_eq g) end @[elab_as_elim] nonrec theorem IsBaseChange.inductionOn (x : N) (P : N → Prop) (h₁ : P 0) (h₂ : ∀ m : M, P (f m)) (h₃ : ∀ (s : S) (n), P n → P (s • n)) (h₄ : ∀ n₁ n₂, P n₁ → P n₂ → P (n₁ + n₂)) : P x := h.inductionOn x h₁ (fun _ _ => h₃ _ _ (h₂ _)) h₄ theorem IsBaseChange.algHom_ext (g₁ g₂ : N →ₗ[S] Q) (e : ∀ x, g₁ (f x) = g₂ (f x)) : g₁ = g₂ := by ext x refine h.inductionOn x _ ?_ ?_ ?_ ?_ · rw [map_zero, map_zero] · assumption · intro s n e' rw [g₁.map_smul, g₂.map_smul, e'] · intro x y e₁ e₂ rw [map_add, map_add, e₁, e₂] theorem IsBaseChange.algHom_ext' [Module R Q] [IsScalarTower R S Q] (g₁ g₂ : N →ₗ[S] Q) (e : (g₁.restrictScalars R).comp f = (g₂.restrictScalars R).comp f) : g₁ = g₂ := h.algHom_ext g₁ g₂ (LinearMap.congr_fun e) variable (R M N S) theorem TensorProduct.isBaseChange : IsBaseChange S (TensorProduct.mk R S M 1) := by delta IsBaseChange convert TensorProduct.isTensorProduct R S M using 1 ext s x change s • (1 : S) ⊗ₜ[R] x = s ⊗ₜ[R] x rw [TensorProduct.smul_tmul'] congr 1 exact mul_one _ variable {R M N S} /-- The base change of `M` along `R → S` is linearly equivalent to `S ⊗[R] M`. -/ noncomputable nonrec def IsBaseChange.equiv : S ⊗[R] M ≃ₗ[S] N := { h.equiv with map_smul' := fun r x => by change h.equiv (r • x) = r • h.equiv x refine TensorProduct.induction_on x ?_ ?_ ?_ · rw [smul_zero, map_zero, smul_zero] · intro x y -- porting note (#10745): was simp [smul_tmul', Algebra.ofId_apply] simp only [Algebra.linearMap_apply, lift.tmul, smul_eq_mul, LinearMap.mul_apply, LinearMap.smul_apply, IsTensorProduct.equiv_apply, Module.algebraMap_end_apply, _root_.map_mul, smul_tmul', eq_self_iff_true, LinearMap.coe_restrictScalars, LinearMap.flip_apply] · intro x y hx hy rw [map_add, smul_add, map_add, smul_add, hx, hy] } theorem IsBaseChange.equiv_tmul (s : S) (m : M) : h.equiv (s ⊗ₜ m) = s • f m := TensorProduct.lift.tmul s m theorem IsBaseChange.equiv_symm_apply (m : M) : h.equiv.symm (f m) = 1 ⊗ₜ m := by rw [h.equiv.symm_apply_eq, h.equiv_tmul, one_smul] variable (f) theorem IsBaseChange.of_lift_unique (h : ∀ (Q : Type max v₁ v₂ v₃) [AddCommMonoid Q], ∀ [Module R Q] [Module S Q], ∀ [IsScalarTower R S Q], ∀ g : M →ₗ[R] Q, ∃! g' : N →ₗ[S] Q, (g'.restrictScalars R).comp f = g) : IsBaseChange S f := by obtain ⟨g, hg, -⟩ := h (ULift.{v₂} <| S ⊗[R] M) (ULift.moduleEquiv.symm.toLinearMap.comp <| TensorProduct.mk R S M 1) let f' : S ⊗[R] M →ₗ[R] N := TensorProduct.lift (((LinearMap.flip (AlgHom.toLinearMap (Algebra.ofId S (Module.End S (M →ₗ[R] N))))) f).restrictScalars R) change Function.Bijective f' let f'' : S ⊗[R] M →ₗ[S] N := by refine { f' with map_smul' := fun s x => TensorProduct.induction_on x ?_ (fun s' y => smul_assoc s s' _) fun x y hx hy => ?_ } · dsimp; rw [map_zero, smul_zero, map_zero, smul_zero] · dsimp at *; rw [smul_add, map_add, map_add, smul_add, hx, hy] simp_rw [DFunLike.ext_iff, LinearMap.comp_apply, LinearMap.restrictScalars_apply] at hg let fe : S ⊗[R] M ≃ₗ[S] N := LinearEquiv.ofLinear f'' (ULift.moduleEquiv.toLinearMap.comp g) ?_ ?_ · exact fe.bijective · rw [← LinearMap.cancel_left (ULift.moduleEquiv : ULift.{max v₁ v₃} N ≃ₗ[S] N).symm.injective] refine (h (ULift.{max v₁ v₃} N) <| ULift.moduleEquiv.symm.toLinearMap.comp f).unique ?_ rfl ext x simp only [LinearMap.comp_apply, LinearMap.restrictScalars_apply, hg] apply one_smul · ext x change (g <| (1 : S) • f x).down = _ rw [one_smul, hg] rfl variable {f} theorem IsBaseChange.iff_lift_unique : IsBaseChange S f ↔ ∀ (Q : Type max v₁ v₂ v₃) [AddCommMonoid Q], ∀ [Module R Q] [Module S Q], ∀ [IsScalarTower R S Q], ∀ g : M →ₗ[R] Q, ∃! g' : N →ₗ[S] Q, (g'.restrictScalars R).comp f = g := ⟨fun h => by intros Q _ _ _ _ g exact ⟨h.lift g, h.lift_comp g, fun g' e => h.algHom_ext' _ _ (e.trans (h.lift_comp g).symm)⟩, IsBaseChange.of_lift_unique f⟩ theorem IsBaseChange.ofEquiv (e : M ≃ₗ[R] N) : IsBaseChange R e.toLinearMap := by apply IsBaseChange.of_lift_unique intro Q I₁ I₂ I₃ I₄ g have : I₂ = I₃ := by ext r q show (by let _ := I₂; exact r • q) = (by let _ := I₃; exact r • q) dsimp rw [← one_smul R q, smul_smul, ← @smul_assoc _ _ _ (id _) (id _) (id _) I₄, smul_eq_mul] cases this refine ⟨g.comp e.symm.toLinearMap, by ext simp, ?_⟩ rintro y (rfl : _ = _) ext simp variable {T O : Type*} [CommSemiring T] [Algebra R T] [Algebra S T] [IsScalarTower R S T] variable [AddCommMonoid O] [Module R O] [Module S O] [Module T O] [IsScalarTower S T O] variable [IsScalarTower R S O] [IsScalarTower R T O] theorem IsBaseChange.comp {f : M →ₗ[R] N} (hf : IsBaseChange S f) {g : N →ₗ[S] O} (hg : IsBaseChange T g) : IsBaseChange T ((g.restrictScalars R).comp f) := by apply IsBaseChange.of_lift_unique intro Q _ _ _ _ i letI := Module.compHom Q (algebraMap S T) haveI : IsScalarTower S T Q := ⟨fun x y z => by rw [Algebra.smul_def, mul_smul] rfl⟩ have : IsScalarTower R S Q := by refine ⟨fun x y z => ?_⟩ change (IsScalarTower.toAlgHom R S T) (x • y) • z = x • algebraMap S T y • z rw [map_smul, smul_assoc] rfl refine ⟨hg.lift (hf.lift i), by ext simp [IsBaseChange.lift_eq], ?_⟩ rintro g' (e : _ = _) refine hg.algHom_ext' _ _ (hf.algHom_ext' _ _ ?_) rw [IsBaseChange.lift_comp, IsBaseChange.lift_comp, ← e] ext rfl variable {R' S' : Type*} [CommSemiring R'] [CommSemiring S'] variable [Algebra R R'] [Algebra S S'] [Algebra R' S'] [Algebra R S'] variable [IsScalarTower R R' S'] [IsScalarTower R S S'] open IsScalarTower (toAlgHom) variable (R S R' S') /-- A type-class stating that the following diagram of scalar towers R → S ↓ ↓ R' → S' is a pushout diagram (i.e. `S' = S ⊗[R] R'`) -/ @[mk_iff] class Algebra.IsPushout : Prop where out : IsBaseChange S (toAlgHom R R' S').toLinearMap variable {R S R' S'} @[symm] theorem Algebra.IsPushout.symm (h : Algebra.IsPushout R S R' S') : Algebra.IsPushout R R' S S' := by let _ := (Algebra.TensorProduct.includeRight : R' →ₐ[R] S ⊗ R').toRingHom.toAlgebra let e : R' ⊗[R] S ≃ₗ[R'] S' := by refine { (_root_.TensorProduct.comm R R' S).trans <| h.1.equiv.restrictScalars R with map_smul' := ?_ } intro r x change h.1.equiv (TensorProduct.comm R R' S (r • x)) = r • h.1.equiv (TensorProduct.comm R R' S x) refine TensorProduct.induction_on x ?_ ?_ ?_ · simp only [smul_zero, map_zero] · intro x y simp only [smul_tmul', smul_eq_mul, TensorProduct.comm_tmul, smul_def, TensorProduct.algebraMap_apply, id.map_eq_id, RingHom.id_apply, TensorProduct.tmul_mul_tmul, one_mul, h.1.equiv_tmul, AlgHom.toLinearMap_apply, _root_.map_mul, IsScalarTower.coe_toAlgHom'] ring · intro x y hx hy rw [map_add, map_add, smul_add, map_add, map_add, hx, hy, smul_add] have : (toAlgHom R S S').toLinearMap = (e.toLinearMap.restrictScalars R).comp (TensorProduct.mk R R' S 1) := by ext simp [h.1.equiv_tmul, Algebra.smul_def] constructor rw [this] exact (TensorProduct.isBaseChange R S R').comp (IsBaseChange.ofEquiv e) variable (R S R' S') theorem Algebra.IsPushout.comm : Algebra.IsPushout R S R' S' ↔ Algebra.IsPushout R R' S S' := ⟨Algebra.IsPushout.symm, Algebra.IsPushout.symm⟩ variable {R S R'} attribute [local instance] Algebra.TensorProduct.rightAlgebra instance TensorProduct.isPushout {R S T : Type*} [CommRing R] [CommRing S] [CommRing T] [Algebra R S] [Algebra R T] : Algebra.IsPushout R S T (TensorProduct R S T) := ⟨TensorProduct.isBaseChange R T S⟩ instance TensorProduct.isPushout' {R S T : Type*} [CommRing R] [CommRing S] [CommRing T] [Algebra R S] [Algebra R T] : Algebra.IsPushout R T S (TensorProduct R S T) := Algebra.IsPushout.symm inferInstance /-- If `S' = S ⊗[R] R'`, then any pair of `R`-algebra homomorphisms `f : S → A` and `g : R' → A` such that `f x` and `g y` commutes for all `x, y` descends to a (unique) homomorphism `S' → A`. -/ @[simps! (config := .lemmasOnly) apply] noncomputable def Algebra.pushoutDesc [H : Algebra.IsPushout R S R' S'] {A : Type*} [Semiring A] [Algebra R A] (f : S →ₐ[R] A) (g : R' →ₐ[R] A) (hf : ∀ x y, f x * g y = g y * f x) : S' →ₐ[R] A := by letI := Module.compHom A f.toRingHom haveI : IsScalarTower R S A := { smul_assoc := fun r s a => show f (r • s) * a = r • (f s * a) by rw [map_smul, smul_mul_assoc] } haveI : IsScalarTower S A A := { smul_assoc := fun r a b => mul_assoc _ _ _ } have : ∀ x, H.out.lift g.toLinearMap (algebraMap R' S' x) = g x := H.out.lift_eq _ refine AlgHom.ofLinearMap ((H.out.lift g.toLinearMap).restrictScalars R) ?_ ?_ · dsimp only [LinearMap.restrictScalars_apply] rw [← (algebraMap R' S').map_one, this, _root_.map_one] · intro x y refine H.out.inductionOn x _ ?_ ?_ ?_ ?_ · rw [zero_mul, map_zero, zero_mul] rotate_left · intro s s' e dsimp only [LinearMap.restrictScalars_apply] at e ⊢ rw [LinearMap.map_smul, smul_mul_assoc, LinearMap.map_smul, e, smul_mul_assoc] · intro s s' e₁ e₂ dsimp only [LinearMap.restrictScalars_apply] at e₁ e₂ ⊢ rw [add_mul, map_add, map_add, add_mul, e₁, e₂] intro x dsimp rw [this] refine H.out.inductionOn y _ ?_ ?_ ?_ ?_ · rw [mul_zero, map_zero, mul_zero] · intro y dsimp rw [← _root_.map_mul, this, this, _root_.map_mul] · intro s s' e rw [mul_comm, smul_mul_assoc, LinearMap.map_smul, LinearMap.map_smul, mul_comm, e] change f s * (g x * _) = g x * (f s * _) rw [← mul_assoc, ← mul_assoc, hf] · intro s s' e₁ e₂ rw [mul_add, map_add, map_add, mul_add, e₁, e₂] @[simp] theorem Algebra.pushoutDesc_left [H : Algebra.IsPushout R S R' S'] {A : Type*} [Semiring A] [Algebra R A] (f : S →ₐ[R] A) (g : R' →ₐ[R] A) (H) (x : S) : Algebra.pushoutDesc S' f g H (algebraMap S S' x) = f x := by letI := Module.compHom A f.toRingHom haveI : IsScalarTower R S A := { smul_assoc := fun r s a => show f (r • s) * a = r • (f s * a) by rw [map_smul, smul_mul_assoc] } haveI : IsScalarTower S A A := { smul_assoc := fun r a b => mul_assoc _ _ _ } rw [Algebra.algebraMap_eq_smul_one, pushoutDesc_apply, map_smul, ← Algebra.pushoutDesc_apply S' f g H, _root_.map_one] exact mul_one (f x) theorem Algebra.lift_algHom_comp_left [Algebra.IsPushout R S R' S'] {A : Type*} [Semiring A] [Algebra R A] (f : S →ₐ[R] A) (g : R' →ₐ[R] A) (H) : (Algebra.pushoutDesc S' f g H).comp (toAlgHom R S S') = f := AlgHom.ext fun x => (Algebra.pushoutDesc_left S' f g H x : _) @[simp] theorem Algebra.pushoutDesc_right [H : Algebra.IsPushout R S R' S'] {A : Type*} [Semiring A] [Algebra R A] (f : S →ₐ[R] A) (g : R' →ₐ[R] A) (H) (x : R') : Algebra.pushoutDesc S' f g H (algebraMap R' S' x) = g x := letI := Module.compHom A f.toRingHom haveI : IsScalarTower R S A := { smul_assoc := fun r s a => show f (r • s) * a = r • (f s * a) by rw [map_smul, smul_mul_assoc] } IsBaseChange.lift_eq _ _ _ theorem Algebra.lift_algHom_comp_right [Algebra.IsPushout R S R' S'] {A : Type*} [Semiring A] [Algebra R A] (f : S →ₐ[R] A) (g : R' →ₐ[R] A) (H) : (Algebra.pushoutDesc S' f g H).comp (toAlgHom R R' S') = g := AlgHom.ext fun x => (Algebra.pushoutDesc_right S' f g H x : _) @[ext (iff := false)] theorem Algebra.IsPushout.algHom_ext [H : Algebra.IsPushout R S R' S'] {A : Type*} [Semiring A] [Algebra R A] {f g : S' →ₐ[R] A} (h₁ : f.comp (toAlgHom R R' S') = g.comp (toAlgHom R R' S')) (h₂ : f.comp (toAlgHom R S S') = g.comp (toAlgHom R S S')) : f = g := by ext x refine H.1.inductionOn x _ ?_ ?_ ?_ ?_ · simp only [map_zero] · exact AlgHom.congr_fun h₁ · intro s s' e rw [Algebra.smul_def, _root_.map_mul, _root_.map_mul, e] congr 1 exact (AlgHom.congr_fun h₂ s : _) · intro s₁ s₂ e₁ e₂ rw [map_add, map_add, e₁, e₂] end IsBaseChange
RingTheory\Jacobson.lean
/- Copyright (c) 2020 Devon Tuma. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Devon Tuma -/ import Mathlib.RingTheory.Localization.Away.Basic import Mathlib.RingTheory.Ideal.Over import Mathlib.RingTheory.JacobsonIdeal /-! # Jacobson Rings The following conditions are equivalent for a ring `R`: 1. Every radical ideal `I` is equal to its Jacobson radical 2. Every radical ideal `I` can be written as an intersection of maximal ideals 3. Every prime ideal `I` is equal to its Jacobson radical Any ring satisfying any of these equivalent conditions is said to be Jacobson. Some particular examples of Jacobson rings are also proven. `isJacobson_quotient` says that the quotient of a Jacobson ring is Jacobson. `isJacobson_localization` says the localization of a Jacobson ring to a single element is Jacobson. `isJacobson_polynomial_iff_isJacobson` says polynomials over a Jacobson ring form a Jacobson ring. ## Main definitions Let `R` be a commutative ring. Jacobson rings are defined using the first of the above conditions * `IsJacobson R` is the proposition that `R` is a Jacobson ring. It is a class, implemented as the predicate that for any ideal, `I.isRadical` implies `I.jacobson = I`. ## Main statements * `isJacobson_iff_prime_eq` is the equivalence between conditions 1 and 3 above. * `isJacobson_iff_sInf_maximal` is the equivalence between conditions 1 and 2 above. * `isJacobson_of_surjective` says that if `R` is a Jacobson ring and `f : R →+* S` is surjective, then `S` is also a Jacobson ring * `MvPolynomial.isJacobson` says that multi-variate polynomials over a Jacobson ring are Jacobson. ## Tags Jacobson, Jacobson Ring -/ universe u namespace Ideal open Polynomial open Polynomial section IsJacobson variable {R S : Type*} [CommRing R] [CommRing S] {I : Ideal R} /-- A ring is a Jacobson ring if for every radical ideal `I`, the Jacobson radical of `I` is equal to `I`. See `isJacobson_iff_prime_eq` and `isJacobson_iff_sInf_maximal` for equivalent definitions. -/ class IsJacobson (R : Type*) [CommRing R] : Prop where out' : ∀ I : Ideal R, I.IsRadical → I.jacobson = I theorem isJacobson_iff {R} [CommRing R] : IsJacobson R ↔ ∀ I : Ideal R, I.IsRadical → I.jacobson = I := ⟨fun h => h.1, fun h => ⟨h⟩⟩ theorem IsJacobson.out {R} [CommRing R] : IsJacobson R → ∀ {I : Ideal R}, I.IsRadical → I.jacobson = I := isJacobson_iff.1 /-- A ring is a Jacobson ring if and only if for all prime ideals `P`, the Jacobson radical of `P` is equal to `P`. -/ theorem isJacobson_iff_prime_eq : IsJacobson R ↔ ∀ P : Ideal R, IsPrime P → P.jacobson = P := by refine isJacobson_iff.trans ⟨fun h I hI => h I hI.isRadical, ?_⟩ refine fun h I hI ↦ le_antisymm (fun x hx ↦ ?_) (fun x hx ↦ mem_sInf.mpr fun _ hJ ↦ hJ.left hx) rw [← hI.radical, radical_eq_sInf I, mem_sInf] intro P hP rw [Set.mem_setOf_eq] at hP erw [mem_sInf] at hx erw [← h P hP.right, mem_sInf] exact fun J hJ => hx ⟨le_trans hP.left hJ.left, hJ.right⟩ /-- A ring `R` is Jacobson if and only if for every prime ideal `I`, `I` can be written as the infimum of some collection of maximal ideals. Allowing ⊤ in the set `M` of maximal ideals is equivalent, but makes some proofs cleaner. -/ theorem isJacobson_iff_sInf_maximal : IsJacobson R ↔ ∀ {I : Ideal R}, I.IsPrime → ∃ M : Set (Ideal R), (∀ J ∈ M, IsMaximal J ∨ J = ⊤) ∧ I = sInf M := ⟨fun H _I h => eq_jacobson_iff_sInf_maximal.1 (H.out h.isRadical), fun H => isJacobson_iff_prime_eq.2 fun _P hP => eq_jacobson_iff_sInf_maximal.2 (H hP)⟩ theorem isJacobson_iff_sInf_maximal' : IsJacobson R ↔ ∀ {I : Ideal R}, I.IsPrime → ∃ M : Set (Ideal R), (∀ J ∈ M, ∀ (K : Ideal R), J < K → K = ⊤) ∧ I = sInf M := ⟨fun H _I h => eq_jacobson_iff_sInf_maximal'.1 (H.out h.isRadical), fun H => isJacobson_iff_prime_eq.2 fun _P hP => eq_jacobson_iff_sInf_maximal'.2 (H hP)⟩ theorem radical_eq_jacobson [H : IsJacobson R] (I : Ideal R) : I.radical = I.jacobson := le_antisymm (le_sInf fun _J ⟨hJ, hJ_max⟩ => (IsPrime.radical_le_iff hJ_max.isPrime).mpr hJ) (H.out (radical_isRadical I) ▸ jacobson_mono le_radical) /-- Fields have only two ideals, and the condition holds for both of them. -/ instance (priority := 100) isJacobson_field {K : Type*} [Field K] : IsJacobson K := ⟨fun I _ => Or.recOn (eq_bot_or_top I) (fun h => le_antisymm (sInf_le ⟨le_rfl, h.symm ▸ bot_isMaximal⟩) (h.symm ▸ bot_le)) fun h => by rw [h, jacobson_eq_top_iff]⟩ theorem isJacobson_of_surjective [H : IsJacobson R] : (∃ f : R →+* S, Function.Surjective ↑f) → IsJacobson S := by rintro ⟨f, hf⟩ rw [isJacobson_iff_sInf_maximal] intro p hp use map f '' { J : Ideal R | comap f p ≤ J ∧ J.IsMaximal } use fun j ⟨J, hJ, hmap⟩ => hmap ▸ (map_eq_top_or_isMaximal_of_surjective f hf hJ.right).symm have : p = map f (comap f p).jacobson := (IsJacobson.out' _ <| hp.isRadical.comap f).symm ▸ (map_comap_of_surjective f hf p).symm exact this.trans (map_sInf hf fun J ⟨hJ, _⟩ => le_trans (Ideal.ker_le_comap f) hJ) instance (priority := 100) isJacobson_quotient [IsJacobson R] : IsJacobson (R ⧸ I) := isJacobson_of_surjective ⟨Quotient.mk I, by rintro ⟨x⟩ use x rfl⟩ theorem isJacobson_iso (e : R ≃+* S) : IsJacobson R ↔ IsJacobson S := ⟨fun h => @isJacobson_of_surjective _ _ _ _ h ⟨(e : R →+* S), e.surjective⟩, fun h => @isJacobson_of_surjective _ _ _ _ h ⟨(e.symm : S →+* R), e.symm.surjective⟩⟩ theorem isJacobson_of_isIntegral [Algebra R S] [Algebra.IsIntegral R S] (hR : IsJacobson R) : IsJacobson S := by rw [isJacobson_iff_prime_eq] intro P hP by_cases hP_top : comap (algebraMap R S) P = ⊤ · simp [comap_eq_top_iff.1 hP_top] · haveI : Nontrivial (R ⧸ comap (algebraMap R S) P) := Quotient.nontrivial hP_top rw [jacobson_eq_iff_jacobson_quotient_eq_bot] refine eq_bot_of_comap_eq_bot (R := R ⧸ comap (algebraMap R S) P) ?_ rw [eq_bot_iff, ← jacobson_eq_iff_jacobson_quotient_eq_bot.1 ((isJacobson_iff_prime_eq.1 hR) (comap (algebraMap R S) P) (comap_isPrime _ _)), comap_jacobson] refine sInf_le_sInf fun J hJ => ?_ simp only [true_and_iff, Set.mem_image, bot_le, Set.mem_setOf_eq] have : J.IsMaximal := by simpa using hJ exact exists_ideal_over_maximal_of_isIntegral J (comap_bot_le_of_injective _ algebraMap_quotient_injective) theorem isJacobson_of_isIntegral' (f : R →+* S) (hf : f.IsIntegral) (hR : IsJacobson R) : IsJacobson S := let _ : Algebra R S := f.toAlgebra have : Algebra.IsIntegral R S := ⟨hf⟩ isJacobson_of_isIntegral hR end IsJacobson section Localization open IsLocalization Submonoid variable {R S : Type*} [CommRing R] [CommRing S] {I : Ideal R} variable (y : R) [Algebra R S] [IsLocalization.Away y S] variable (S) /-- If `R` is a Jacobson ring, then maximal ideals in the localization at `y` correspond to maximal ideals in the original ring `R` that don't contain `y`. This lemma gives the correspondence in the particular case of an ideal and its comap. See `le_relIso_of_maximal` for the more general relation isomorphism -/ theorem isMaximal_iff_isMaximal_disjoint [H : IsJacobson R] (J : Ideal S) : J.IsMaximal ↔ (comap (algebraMap R S) J).IsMaximal ∧ y ∉ Ideal.comap (algebraMap R S) J := by constructor · refine fun h => ⟨?_, fun hy => h.ne_top (Ideal.eq_top_of_isUnit_mem _ hy (map_units _ ⟨y, Submonoid.mem_powers _⟩))⟩ have hJ : J.IsPrime := IsMaximal.isPrime h rw [isPrime_iff_isPrime_disjoint (Submonoid.powers y)] at hJ have : y ∉ (comap (algebraMap R S) J).1 := Set.disjoint_left.1 hJ.right (Submonoid.mem_powers _) erw [← H.out hJ.left.isRadical, mem_sInf] at this push_neg at this rcases this with ⟨I, hI, hI'⟩ convert hI.right by_cases hJ : J = map (algebraMap R S) I · rw [hJ, comap_map_of_isPrime_disjoint (powers y) S I (IsMaximal.isPrime hI.right)] rwa [disjoint_powers_iff_not_mem y hI.right.isPrime.isRadical] · have hI_p : (map (algebraMap R S) I).IsPrime := by refine isPrime_of_isPrime_disjoint (powers y) _ I hI.right.isPrime ?_ rwa [disjoint_powers_iff_not_mem y hI.right.isPrime.isRadical] have : J ≤ map (algebraMap R S) I := map_comap (Submonoid.powers y) S J ▸ map_mono hI.left exact absurd (h.1.2 _ (lt_of_le_of_ne this hJ)) hI_p.1 · refine fun h => ⟨⟨fun hJ => h.1.ne_top (eq_top_iff.2 ?_), fun I hI => ?_⟩⟩ · rwa [eq_top_iff, ← (IsLocalization.orderEmbedding (powers y) S).le_iff_le] at hJ · have := congr_arg (map (algebraMap R S)) (h.1.1.2 _ ⟨comap_mono (le_of_lt hI), ?_⟩) · rwa [map_comap (powers y) S I, map_top] at this refine fun hI' => hI.right ?_ rw [← map_comap (powers y) S I, ← map_comap (powers y) S J] exact map_mono hI' variable {S} /-- If `R` is a Jacobson ring, then maximal ideals in the localization at `y` correspond to maximal ideals in the original ring `R` that don't contain `y`. This lemma gives the correspondence in the particular case of an ideal and its map. See `le_relIso_of_maximal` for the more general statement, and the reverse of this implication -/ theorem isMaximal_of_isMaximal_disjoint [IsJacobson R] (I : Ideal R) (hI : I.IsMaximal) (hy : y ∉ I) : (map (algebraMap R S) I).IsMaximal := by rw [isMaximal_iff_isMaximal_disjoint S y, comap_map_of_isPrime_disjoint (powers y) S I (IsMaximal.isPrime hI) ((disjoint_powers_iff_not_mem y hI.isPrime.isRadical).2 hy)] exact ⟨hI, hy⟩ /-- If `R` is a Jacobson ring, then maximal ideals in the localization at `y` correspond to maximal ideals in the original ring `R` that don't contain `y` -/ def orderIsoOfMaximal [IsJacobson R] : { p : Ideal S // p.IsMaximal } ≃o { p : Ideal R // p.IsMaximal ∧ y ∉ p } where toFun p := ⟨Ideal.comap (algebraMap R S) p.1, (isMaximal_iff_isMaximal_disjoint S y p.1).1 p.2⟩ invFun p := ⟨Ideal.map (algebraMap R S) p.1, isMaximal_of_isMaximal_disjoint y p.1 p.2.1 p.2.2⟩ left_inv J := Subtype.eq (map_comap (powers y) S J) right_inv I := Subtype.eq (comap_map_of_isPrime_disjoint _ _ I.1 (IsMaximal.isPrime I.2.1) ((disjoint_powers_iff_not_mem y I.2.1.isPrime.isRadical).2 I.2.2)) map_rel_iff' {I I'} := ⟨fun h => show I.val ≤ I'.val from map_comap (powers y) S I.val ▸ map_comap (powers y) S I'.val ▸ Ideal.map_mono h, fun h _ hx => h hx⟩ /-- If `S` is the localization of the Jacobson ring `R` at the submonoid generated by `y : R`, then `S` is Jacobson. -/ theorem isJacobson_localization [H : IsJacobson R] : IsJacobson S := by rw [isJacobson_iff_prime_eq] refine fun P' hP' => le_antisymm ?_ le_jacobson obtain ⟨hP', hPM⟩ := (IsLocalization.isPrime_iff_isPrime_disjoint (powers y) S P').mp hP' have hP := H.out hP'.isRadical refine (IsLocalization.map_comap (powers y) S P'.jacobson).ge.trans ((map_mono ?_).trans (IsLocalization.map_comap (powers y) S P').le) have : sInf { I : Ideal R | comap (algebraMap R S) P' ≤ I ∧ I.IsMaximal ∧ y ∉ I } ≤ comap (algebraMap R S) P' := by intro x hx have hxy : x * y ∈ (comap (algebraMap R S) P').jacobson := by rw [Ideal.jacobson, mem_sInf] intro J hJ by_cases h : y ∈ J · exact J.mul_mem_left x h · exact J.mul_mem_right y ((mem_sInf.1 hx) ⟨hJ.left, ⟨hJ.right, h⟩⟩) rw [hP] at hxy cases' hP'.mem_or_mem hxy with hxy hxy · exact hxy · exact (hPM.le_bot ⟨Submonoid.mem_powers _, hxy⟩).elim refine le_trans ?_ this rw [Ideal.jacobson, comap_sInf', sInf_eq_iInf] refine iInf_le_iInf_of_subset fun I hI => ⟨map (algebraMap R S) I, ⟨?_, ?_⟩⟩ · exact ⟨le_trans (le_of_eq (IsLocalization.map_comap (powers y) S P').symm) (map_mono hI.1), isMaximal_of_isMaximal_disjoint y _ hI.2.1 hI.2.2⟩ · exact IsLocalization.comap_map_of_isPrime_disjoint _ S I (IsMaximal.isPrime hI.2.1) ((disjoint_powers_iff_not_mem y hI.2.1.isPrime.isRadical).2 hI.2.2) end Localization namespace Polynomial open Polynomial section CommRing -- Porting note: move to better place -- Porting note: make `S` and `T` universe polymorphic lemma Subring.mem_closure_image_of {S T : Type*} [CommRing S] [CommRing T] (g : S →+* T) (u : Set S) (x : S) (hx : x ∈ Subring.closure u) : g x ∈ Subring.closure (g '' u) := by rw [Subring.mem_closure] at hx ⊢ intro T₁ h₁ rw [← Subring.mem_comap] apply hx simp only [Subring.coe_comap, ← Set.image_subset_iff, SetLike.mem_coe] exact h₁ -- Porting note: move to better place lemma mem_closure_X_union_C {R : Type*} [Ring R] (p : R[X]) : p ∈ Subring.closure (insert X {f | f.degree ≤ 0} : Set R[X]) := by refine Polynomial.induction_on p ?_ ?_ ?_ · intro r apply Subring.subset_closure apply Set.mem_insert_of_mem exact degree_C_le · intros p1 p2 h1 h2 exact Subring.add_mem _ h1 h2 · intros n r hr rw [pow_succ, ← mul_assoc] apply Subring.mul_mem _ hr apply Subring.subset_closure apply Set.mem_insert variable {R S : Type*} [CommRing R] [CommRing S] [IsDomain S] variable {Rₘ Sₘ : Type*} [CommRing Rₘ] [CommRing Sₘ] /-- If `I` is a prime ideal of `R[X]` and `pX ∈ I` is a non-constant polynomial, then the map `R →+* R[x]/I` descends to an integral map when localizing at `pX.leadingCoeff`. In particular `X` is integral because it satisfies `pX`, and constants are trivially integral, so integrality of the entire extension follows by closure under addition and multiplication. -/ theorem isIntegral_isLocalization_polynomial_quotient (P : Ideal R[X]) (pX : R[X]) (hpX : pX ∈ P) [Algebra (R ⧸ P.comap (C : R →+* R[X])) Rₘ] [IsLocalization.Away (pX.map (Quotient.mk (P.comap (C : R →+* R[X])))).leadingCoeff Rₘ] [Algebra (R[X] ⧸ P) Sₘ] [IsLocalization ((Submonoid.powers (pX.map (Quotient.mk (P.comap (C : R →+* R[X])))).leadingCoeff).map (quotientMap P C le_rfl) : Submonoid (R[X] ⧸ P)) Sₘ] : (IsLocalization.map Sₘ (quotientMap P C le_rfl) (Submonoid.powers (pX.map (Quotient.mk (P.comap (C : R →+* R[X])))).leadingCoeff).le_comap_map : Rₘ →+* Sₘ).IsIntegral := by let P' : Ideal R := P.comap C let M : Submonoid (R ⧸ P') := Submonoid.powers (pX.map (Quotient.mk (P.comap (C : R →+* R[X])))).leadingCoeff let M' : Submonoid (R[X] ⧸ P) := (Submonoid.powers (pX.map (Quotient.mk (P.comap (C : R →+* R[X])))).leadingCoeff).map (quotientMap P C le_rfl) let φ : R ⧸ P' →+* R[X] ⧸ P := quotientMap P C le_rfl let φ' : Rₘ →+* Sₘ := IsLocalization.map Sₘ φ M.le_comap_map have hφ' : φ.comp (Quotient.mk P') = (Quotient.mk P).comp C := rfl intro p obtain ⟨⟨p', ⟨q, hq⟩⟩, hp⟩ := IsLocalization.surj M' p suffices φ'.IsIntegralElem (algebraMap (R[X] ⧸ P) Sₘ p') by obtain ⟨q', hq', rfl⟩ := hq obtain ⟨q'', hq''⟩ := isUnit_iff_exists_inv'.1 (IsLocalization.map_units Rₘ (⟨q', hq'⟩ : M)) refine (hp.symm ▸ this).of_mul_unit φ' p (algebraMap (R[X] ⧸ P) Sₘ (φ q')) q'' ?_ rw [← φ'.map_one, ← congr_arg φ' hq'', φ'.map_mul, ← φ'.comp_apply] simp only [IsLocalization.map_comp _] rw [RingHom.comp_apply] dsimp at hp refine @IsIntegral.of_mem_closure'' Rₘ _ Sₘ _ φ' ((algebraMap (R[X] ⧸ P) Sₘ).comp (Quotient.mk P) '' insert X { p | p.degree ≤ 0 }) ?_ ((algebraMap (R[X] ⧸ P) Sₘ) p') ?_ · rintro x ⟨p, hp, rfl⟩ simp only [Set.mem_insert_iff] at hp cases' hp with hy hy · rw [hy] refine φ.isIntegralElem_localization_at_leadingCoeff ((Quotient.mk P) X) (pX.map (Quotient.mk P')) ?_ M ?_ · rwa [eval₂_map, hφ', ← hom_eval₂, Quotient.eq_zero_iff_mem, eval₂_C_X] · use 1 simp only [pow_one] · rw [Set.mem_setOf_eq, degree_le_zero_iff] at hy -- Porting note: was `refine' hy.symm ▸` -- `⟨X - C (algebraMap _ _ ((Quotient.mk P') (p.coeff 0))), monic_X_sub_C _, _⟩` rw [hy] use X - C (algebraMap (R ⧸ P') Rₘ ((Quotient.mk P') (p.coeff 0))) constructor · apply monic_X_sub_C · simp only [eval₂_sub, eval₂_X, eval₂_C] rw [sub_eq_zero, ← φ'.comp_apply] simp only [IsLocalization.map_comp _] rfl · obtain ⟨p, rfl⟩ := Quotient.mk_surjective p' rw [← RingHom.comp_apply] apply Subring.mem_closure_image_of apply Polynomial.mem_closure_X_union_C /-- If `f : R → S` descends to an integral map in the localization at `x`, and `R` is a Jacobson ring, then the intersection of all maximal ideals in `S` is trivial -/ theorem jacobson_bot_of_integral_localization {R : Type*} [CommRing R] [IsDomain R] [IsJacobson R] (Rₘ Sₘ : Type*) [CommRing Rₘ] [CommRing Sₘ] (φ : R →+* S) (hφ : Function.Injective ↑φ) (x : R) (hx : x ≠ 0) [Algebra R Rₘ] [IsLocalization.Away x Rₘ] [Algebra S Sₘ] [IsLocalization ((Submonoid.powers x).map φ : Submonoid S) Sₘ] (hφ' : RingHom.IsIntegral (IsLocalization.map Sₘ φ (Submonoid.powers x).le_comap_map : Rₘ →+* Sₘ)) : (⊥ : Ideal S).jacobson = (⊥ : Ideal S) := by have hM : ((Submonoid.powers x).map φ : Submonoid S) ≤ nonZeroDivisors S := map_le_nonZeroDivisors_of_injective φ hφ (powers_le_nonZeroDivisors_of_noZeroDivisors hx) letI : IsDomain Sₘ := IsLocalization.isDomain_of_le_nonZeroDivisors _ hM let φ' : Rₘ →+* Sₘ := IsLocalization.map _ φ (Submonoid.powers x).le_comap_map suffices ∀ I : Ideal Sₘ, I.IsMaximal → (I.comap (algebraMap S Sₘ)).IsMaximal by have hϕ' : comap (algebraMap S Sₘ) (⊥ : Ideal Sₘ) = (⊥ : Ideal S) := by rw [← RingHom.ker_eq_comap_bot, ← RingHom.injective_iff_ker_eq_bot] exact IsLocalization.injective Sₘ hM have hSₘ : IsJacobson Sₘ := isJacobson_of_isIntegral' φ' hφ' (isJacobson_localization x) refine eq_bot_iff.mpr (le_trans ?_ (le_of_eq hϕ')) rw [← hSₘ.out isRadical_bot_of_noZeroDivisors, comap_jacobson] exact sInf_le_sInf fun j hj => ⟨bot_le, let ⟨J, hJ⟩ := hj hJ.2 ▸ this J hJ.1.2⟩ intro I hI -- Remainder of the proof is pulling and pushing ideals around the square and the quotient square haveI : (I.comap (algebraMap S Sₘ)).IsPrime := comap_isPrime _ I haveI : (I.comap φ').IsPrime := comap_isPrime φ' I haveI : (⊥ : Ideal (S ⧸ I.comap (algebraMap S Sₘ))).IsPrime := bot_prime have hcomm : φ'.comp (algebraMap R Rₘ) = (algebraMap S Sₘ).comp φ := IsLocalization.map_comp _ let f := quotientMap (I.comap (algebraMap S Sₘ)) φ le_rfl let g := quotientMap I (algebraMap S Sₘ) le_rfl have := isMaximal_comap_of_isIntegral_of_isMaximal' φ' hφ' I have := ((isMaximal_iff_isMaximal_disjoint Rₘ x _).1 this).left have : ((I.comap (algebraMap S Sₘ)).comap φ).IsMaximal := by rwa [comap_comap, hcomm, ← comap_comap] at this rw [← bot_quotient_isMaximal_iff] at this ⊢ refine isMaximal_of_isIntegral_of_isMaximal_comap' f ?_ ⊥ ((eq_bot_iff.2 (comap_bot_le_of_injective f quotientMap_injective)).symm ▸ this) exact RingHom.IsIntegral.tower_bot f g quotientMap_injective ((comp_quotientMap_eq_of_comp_eq hcomm I).symm ▸ (RingHom.isIntegral_of_surjective _ (IsLocalization.surjective_quotientMap_of_maximal_of_localization (Submonoid.powers x) Rₘ (by rwa [comap_comap, hcomm, ← bot_quotient_isMaximal_iff]))).trans _ _ (hφ'.quotient _)) /-- Used to bootstrap the proof of `isJacobson_polynomial_iff_isJacobson`. That theorem is more general and should be used instead of this one. -/ private theorem isJacobson_polynomial_of_domain (R : Type*) [CommRing R] [IsDomain R] [hR : IsJacobson R] (P : Ideal R[X]) [IsPrime P] (hP : ∀ x : R, C x ∈ P → x = 0) : P.jacobson = P := by by_cases Pb : P = ⊥ · exact Pb.symm ▸ jacobson_bot_polynomial_of_jacobson_bot (hR.out isRadical_bot_of_noZeroDivisors) · rw [jacobson_eq_iff_jacobson_quotient_eq_bot] let P' := P.comap (C : R →+* R[X]) haveI : P'.IsPrime := comap_isPrime C P haveI hR' : IsJacobson (R ⧸ P') := by infer_instance obtain ⟨p, pP, p0⟩ := exists_nonzero_mem_of_ne_bot Pb hP let x := (Polynomial.map (Quotient.mk P') p).leadingCoeff have hx : x ≠ 0 := by rwa [Ne, leadingCoeff_eq_zero] let φ : R ⧸ P' →+* R[X] ⧸ P := Ideal.quotientMap P (C : R →+* R[X]) le_rfl let hφ : Function.Injective ↑φ := quotientMap_injective let Rₘ := Localization.Away x let Sₘ := (Localization ((Submonoid.powers x).map φ : Submonoid (R[X] ⧸ P))) refine jacobson_bot_of_integral_localization (S := R[X] ⧸ P) (R := R ⧸ P') Rₘ Sₘ _ hφ _ hx ?_ haveI islocSₘ : IsLocalization (Submonoid.map φ (Submonoid.powers x)) Sₘ := by infer_instance exact @isIntegral_isLocalization_polynomial_quotient R _ Rₘ Sₘ _ _ P p pP _ _ _ islocSₘ theorem isJacobson_polynomial_of_isJacobson (hR : IsJacobson R) : IsJacobson R[X] := by rw [isJacobson_iff_prime_eq] intro I hI let R' : Subring (R[X] ⧸ I) := ((Quotient.mk I).comp C).range let i : R →+* R' := ((Quotient.mk I).comp C).rangeRestrict have hi : Function.Surjective ↑i := ((Quotient.mk I).comp C).rangeRestrict_surjective have hi' : RingHom.ker (mapRingHom i) ≤ I := by intro f hf apply polynomial_mem_ideal_of_coeff_mem_ideal I f intro n replace hf := congrArg (fun g : Polynomial ((Quotient.mk I).comp C).range => g.coeff n) hf change (Polynomial.map ((Quotient.mk I).comp C).rangeRestrict f).coeff n = 0 at hf rw [coeff_map, Subtype.ext_iff] at hf rwa [mem_comap, ← Quotient.eq_zero_iff_mem, ← RingHom.comp_apply] have R'_jacob : IsJacobson R' := isJacobson_of_surjective ⟨i, hi⟩ let J := map (mapRingHom i) I -- Porting note: moved ↓ this up a few lines, so that it can be used in the `have` have h_surj : Function.Surjective (mapRingHom i) := Polynomial.map_surjective i hi have : IsPrime J := map_isPrime_of_surjective h_surj hi' suffices h : J.jacobson = J by replace h := congrArg (comap (Polynomial.mapRingHom i)) h rw [← map_jacobson_of_surjective h_surj hi', comap_map_of_surjective _ h_surj, comap_map_of_surjective _ h_surj] at h refine le_antisymm ?_ le_jacobson exact le_trans (le_sup_of_le_left le_rfl) (le_trans (le_of_eq h) (sup_le le_rfl hi')) apply isJacobson_polynomial_of_domain R' J exact eq_zero_of_polynomial_mem_map_range I theorem isJacobson_polynomial_iff_isJacobson : IsJacobson R[X] ↔ IsJacobson R := by refine ⟨?_, isJacobson_polynomial_of_isJacobson⟩ intro H exact isJacobson_of_surjective ⟨eval₂RingHom (RingHom.id _) 1, fun x => ⟨C x, by simp only [coe_eval₂RingHom, RingHom.id_apply, eval₂_C]⟩⟩ instance [IsJacobson R] : IsJacobson R[X] := isJacobson_polynomial_iff_isJacobson.mpr ‹IsJacobson R› end CommRing section variable {R : Type*} [CommRing R] [IsJacobson R] variable (P : Ideal R[X]) [hP : P.IsMaximal] theorem isMaximal_comap_C_of_isMaximal [Nontrivial R] (hP' : ∀ x : R, C x ∈ P → x = 0) : IsMaximal (comap (C : R →+* R[X]) P : Ideal R) := by let P' := comap (C : R →+* R[X]) P haveI hP'_prime : P'.IsPrime := comap_isPrime C P obtain ⟨⟨m, hmem_P⟩, hm⟩ := Submodule.nonzero_mem_of_bot_lt (bot_lt_of_maximal P polynomial_not_isField) have hm' : m ≠ 0 := by simpa [Submodule.coe_eq_zero] using hm let φ : R ⧸ P' →+* R[X] ⧸ P := quotientMap P (C : R →+* R[X]) le_rfl let a : R ⧸ P' := (m.map (Quotient.mk P')).leadingCoeff let M : Submonoid (R ⧸ P') := Submonoid.powers a rw [← bot_quotient_isMaximal_iff] have hp0 : a ≠ 0 := fun hp0' => hm' <| map_injective (Quotient.mk (P.comap (C : R →+* R[X]) : Ideal R)) ((injective_iff_map_eq_zero (Quotient.mk (P.comap (C : R →+* R[X]) : Ideal R))).2 fun x hx => by rwa [Quotient.eq_zero_iff_mem, (by rwa [eq_bot_iff] : (P.comap C : Ideal R) = ⊥)] at hx) (by simpa only [a, leadingCoeff_eq_zero, Polynomial.map_zero] using hp0') have hM : (0 : R ⧸ P') ∉ M := fun ⟨n, hn⟩ => hp0 (pow_eq_zero hn) suffices (⊥ : Ideal (Localization M)).IsMaximal by rw [← IsLocalization.comap_map_of_isPrime_disjoint M (Localization M) ⊥ bot_prime (disjoint_iff_inf_le.mpr fun x hx => hM (hx.2 ▸ hx.1))] exact ((isMaximal_iff_isMaximal_disjoint (Localization M) a _).mp (by rwa [map_bot])).1 let M' : Submonoid (R[X] ⧸ P) := M.map φ have hM' : (0 : R[X] ⧸ P) ∉ M' := fun ⟨z, hz⟩ => hM (quotientMap_injective (_root_.trans hz.2 φ.map_zero.symm) ▸ hz.1) haveI : IsDomain (Localization M') := IsLocalization.isDomain_localization (le_nonZeroDivisors_of_noZeroDivisors hM') suffices (⊥ : Ideal (Localization M')).IsMaximal by rw [le_antisymm bot_le (comap_bot_le_of_injective _ (IsLocalization.map_injective_of_injective M (Localization M) (Localization M') quotientMap_injective))] refine isMaximal_comap_of_isIntegral_of_isMaximal' _ ?_ ⊥ have isloc : IsLocalization (Submonoid.map φ M) (Localization M') := by infer_instance exact @isIntegral_isLocalization_polynomial_quotient R _ (Localization M) (Localization M') _ _ P m hmem_P _ _ _ isloc rw [(map_bot.symm : (⊥ : Ideal (Localization M')) = map (algebraMap (R[X] ⧸ P) (Localization M')) ⊥)] let bot_maximal := (bot_quotient_isMaximal_iff _).mpr hP refine map.isMaximal (algebraMap (R[X] ⧸ P) (Localization M')) ?_ bot_maximal apply IsField.localization_map_bijective hM' rwa [← Quotient.maximal_ideal_iff_isField_quotient, ← bot_quotient_isMaximal_iff] /-- Used to bootstrap the more general `quotient_mk_comp_C_isIntegral_of_jacobson` -/ private theorem quotient_mk_comp_C_isIntegral_of_jacobson' [Nontrivial R] (hR : IsJacobson R) (hP' : ∀ x : R, C x ∈ P → x = 0) : ((Quotient.mk P).comp C : R →+* R[X] ⧸ P).IsIntegral := by refine (isIntegral_quotientMap_iff _).mp ?_ let P' : Ideal R := P.comap C obtain ⟨pX, hpX, hp0⟩ := exists_nonzero_mem_of_ne_bot (ne_of_lt (bot_lt_of_maximal P polynomial_not_isField)).symm hP' let a : R ⧸ P' := (pX.map (Quotient.mk P')).leadingCoeff let M : Submonoid (R ⧸ P') := Submonoid.powers a let φ : R ⧸ P' →+* R[X] ⧸ P := quotientMap P C le_rfl haveI hP'_prime : P'.IsPrime := comap_isPrime C P have hM : (0 : R ⧸ P') ∉ M := fun ⟨n, hn⟩ => hp0 <| leadingCoeff_eq_zero.mp (pow_eq_zero hn) let M' : Submonoid (R[X] ⧸ P) := M.map φ refine RingHom.IsIntegral.tower_bot φ (algebraMap _ (Localization M')) ?_ ?_ · refine IsLocalization.injective (Localization M') (show M' ≤ _ from le_nonZeroDivisors_of_noZeroDivisors fun hM' => hM ?_) exact let ⟨z, zM, z0⟩ := hM' quotientMap_injective (_root_.trans z0 φ.map_zero.symm) ▸ zM · suffices RingHom.comp (algebraMap (R[X] ⧸ P) (Localization M')) φ = (IsLocalization.map (Localization M') φ M.le_comap_map).comp (algebraMap (R ⧸ P') (Localization M)) by rw [this] refine RingHom.IsIntegral.trans (algebraMap (R ⧸ P') (Localization M)) (IsLocalization.map (Localization M') φ M.le_comap_map) ?_ ?_ · exact (algebraMap (R ⧸ P') (Localization M)).isIntegral_of_surjective (IsField.localization_map_bijective hM ((Quotient.maximal_ideal_iff_isField_quotient _).mp (isMaximal_comap_C_of_isMaximal P hP'))).2 · -- `convert` here is faster than `exact`, and this proof is near the time limit. -- convert isIntegral_isLocalization_polynomial_quotient P pX hpX have isloc : IsLocalization M' (Localization M') := by infer_instance exact @isIntegral_isLocalization_polynomial_quotient R _ (Localization M) (Localization M') _ _ P pX hpX _ _ _ isloc rw [IsLocalization.map_comp M.le_comap_map] /-- If `R` is a Jacobson ring, and `P` is a maximal ideal of `R[X]`, then `R → R[X]/P` is an integral map. -/ theorem quotient_mk_comp_C_isIntegral_of_jacobson : ((Quotient.mk P).comp C : R →+* R[X] ⧸ P).IsIntegral := by let P' : Ideal R := P.comap C haveI : P'.IsPrime := comap_isPrime C P let f : R[X] →+* Polynomial (R ⧸ P') := Polynomial.mapRingHom (Quotient.mk P') have hf : Function.Surjective ↑f := map_surjective (Quotient.mk P') Quotient.mk_surjective have hPJ : P = (P.map f).comap f := by rw [comap_map_of_surjective _ hf] refine le_antisymm (le_sup_of_le_left le_rfl) (sup_le le_rfl ?_) refine fun p hp => polynomial_mem_ideal_of_coeff_mem_ideal P p fun n => Quotient.eq_zero_iff_mem.mp ?_ simpa only [f, coeff_map, coe_mapRingHom] using (Polynomial.ext_iff.mp hp) n refine RingHom.IsIntegral.tower_bot _ _ (injective_quotient_le_comap_map P) ?_ rw [← quotient_mk_maps_eq] refine ((Quotient.mk P').isIntegral_of_surjective Quotient.mk_surjective).trans _ _ ?_ have : IsMaximal (map (mapRingHom (Quotient.mk (comap C P))) P) := Or.recOn (map_eq_top_or_isMaximal_of_surjective f hf hP) (fun h => absurd (_root_.trans (h ▸ hPJ : P = comap f ⊤) comap_top : P = ⊤) hP.ne_top) id apply quotient_mk_comp_C_isIntegral_of_jacobson' _ ?_ (fun x hx => ?_) any_goals exact Ideal.isJacobson_quotient obtain ⟨z, rfl⟩ := Quotient.mk_surjective x rwa [Quotient.eq_zero_iff_mem, mem_comap, hPJ, mem_comap, coe_mapRingHom, map_C] theorem isMaximal_comap_C_of_isJacobson : (P.comap (C : R →+* R[X])).IsMaximal := by rw [← @mk_ker _ _ P, RingHom.ker_eq_comap_bot, comap_comap] have := (bot_quotient_isMaximal_iff _).mpr hP exact isMaximal_comap_of_isIntegral_of_isMaximal' _ (quotient_mk_comp_C_isIntegral_of_jacobson P) ⊥ lemma isMaximal_comap_C_of_isJacobson' {P : Ideal R[X]} (hP : IsMaximal P) : (P.comap (C : R →+* R[X])).IsMaximal := by haveI := hP exact isMaximal_comap_C_of_isJacobson P theorem comp_C_integral_of_surjective_of_jacobson {S : Type*} [Field S] (f : R[X] →+* S) (hf : Function.Surjective ↑f) : (f.comp C).IsIntegral := by haveI : f.ker.IsMaximal := RingHom.ker_isMaximal_of_surjective f hf let g : R[X] ⧸ (RingHom.ker f) →+* S := Ideal.Quotient.lift (RingHom.ker f) f fun _ h => h have hfg : g.comp (Quotient.mk (RingHom.ker f)) = f := ringHom_ext' rfl rfl rw [← hfg, RingHom.comp_assoc] refine (quotient_mk_comp_C_isIntegral_of_jacobson (RingHom.ker f)).trans _ g (g.isIntegral_of_surjective ?_) rw [← hfg] at hf norm_num at hf exact Function.Surjective.of_comp hf end end Polynomial open MvPolynomial RingHom namespace MvPolynomial theorem isJacobson_MvPolynomial_fin {R : Type u} [CommRing R] [H : IsJacobson R] : ∀ n : ℕ, IsJacobson (MvPolynomial (Fin n) R) | 0 => (isJacobson_iso ((renameEquiv R (Equiv.equivPEmpty (Fin 0))).toRingEquiv.trans (isEmptyRingEquiv R PEmpty.{u+1}))).mpr H | n + 1 => (isJacobson_iso (finSuccEquiv R n).toRingEquiv).2 (Polynomial.isJacobson_polynomial_iff_isJacobson.2 (isJacobson_MvPolynomial_fin n)) /-- General form of the Nullstellensatz for Jacobson rings, since in a Jacobson ring we have `Inf {P maximal | P ≥ I} = Inf {P prime | P ≥ I} = I.radical`. Fields are always Jacobson, and in that special case this is (most of) the classical Nullstellensatz, since `I(V(I))` is the intersection of maximal ideals containing `I`, which is then `I.radical` -/ instance isJacobson {R : Type*} [CommRing R] {ι : Type*} [Finite ι] [IsJacobson R] : IsJacobson (MvPolynomial ι R) := by cases nonempty_fintype ι haveI := Classical.decEq ι let e := Fintype.equivFin ι rw [isJacobson_iso (renameEquiv R e).toRingEquiv] exact isJacobson_MvPolynomial_fin _ variable {n : ℕ} universe v w /-- The constant coefficient as an R-linear morphism -/ private noncomputable def Cₐ (R : Type u) (S : Type v) [CommRing R] [CommRing S] [Algebra R S] : S →ₐ[R] S[X] := { Polynomial.C with commutes' := fun r => by rfl } private lemma aux_IH {R : Type u} {S : Type v} {T : Type w} [CommRing R] [CommRing S] [CommRing T] [IsJacobson S] [Algebra R S] [Algebra R T] (IH : ∀ (Q : Ideal S), (IsMaximal Q) → RingHom.IsIntegral (algebraMap R (S ⧸ Q))) (v : S[X] ≃ₐ[R] T) (P : Ideal T) (hP : P.IsMaximal) : RingHom.IsIntegral (algebraMap R (T ⧸ P)) := by let Q := P.comap v.toAlgHom.toRingHom have hw : Ideal.map v Q = P := map_comap_of_surjective v v.surjective P haveI hQ : IsMaximal Q := comap_isMaximal_of_surjective _ v.surjective let w : (S[X] ⧸ Q) ≃ₐ[R] (T ⧸ P) := Ideal.quotientEquivAlg Q P v hw.symm let Q' := Q.comap (Polynomial.C) let w' : (S ⧸ Q') →ₐ[R] (S[X] ⧸ Q) := Ideal.quotientMapₐ Q (Cₐ R S) le_rfl have h_eq : algebraMap R (T ⧸ P) = w.toRingEquiv.toRingHom.comp (w'.toRingHom.comp (algebraMap R (S ⧸ Q'))) := by ext r simp only [AlgEquiv.toAlgHom_eq_coe, AlgHom.toRingHom_eq_coe, AlgEquiv.toRingEquiv_eq_coe, RingEquiv.toRingHom_eq_coe, AlgHom.comp_algebraMap_of_tower, coe_comp, coe_coe, AlgEquiv.coe_ringEquiv, Function.comp_apply, AlgEquiv.commutes] rw [h_eq] apply RingHom.IsIntegral.trans · apply RingHom.IsIntegral.trans · apply IH apply Polynomial.isMaximal_comap_C_of_isJacobson' exact hQ · suffices w'.toRingHom = Ideal.quotientMap Q (Polynomial.C) le_rfl by rw [this] rw [isIntegral_quotientMap_iff _] apply Polynomial.quotient_mk_comp_C_isIntegral_of_jacobson rfl · apply RingHom.isIntegral_of_surjective exact w.surjective private theorem quotient_mk_comp_C_isIntegral_of_jacobson' {R : Type*} [CommRing R] [IsJacobson R] (P : Ideal (MvPolynomial (Fin n) R)) (hP : P.IsMaximal) : RingHom.IsIntegral (algebraMap R (MvPolynomial (Fin n) R ⧸ P)) := by induction' n with n IH · apply RingHom.isIntegral_of_surjective apply Function.Surjective.comp Quotient.mk_surjective exact C_surjective (Fin 0) · apply aux_IH IH (finSuccEquiv R n).symm P hP theorem quotient_mk_comp_C_isIntegral_of_jacobson {R : Type*} [CommRing R] [IsJacobson R] (P : Ideal (MvPolynomial (Fin n) R)) [hP : P.IsMaximal] : RingHom.IsIntegral (RingHom.comp (Quotient.mk P) (MvPolynomial.C)) := by change RingHom.IsIntegral (algebraMap R (MvPolynomial (Fin n) R ⧸ P)) apply quotient_mk_comp_C_isIntegral_of_jacobson' infer_instance theorem comp_C_integral_of_surjective_of_jacobson {R : Type*} [CommRing R] [IsJacobson R] {σ : Type*} [Finite σ] {S : Type*} [Field S] (f : MvPolynomial σ R →+* S) (hf : Function.Surjective ↑f) : (f.comp C).IsIntegral := by cases nonempty_fintype σ have e := (Fintype.equivFin σ).symm let f' : MvPolynomial (Fin _) R →+* S := f.comp (renameEquiv R e).toRingEquiv.toRingHom have hf' := Function.Surjective.comp hf (renameEquiv R e).surjective change Function.Surjective ↑f' at hf' have : (f'.comp C).IsIntegral := by haveI : f'.ker.IsMaximal := ker_isMaximal_of_surjective f' hf' let g : MvPolynomial _ R ⧸ (RingHom.ker f') →+* S := Ideal.Quotient.lift (RingHom.ker f') f' fun _ h => h have hfg : g.comp (Quotient.mk (RingHom.ker f')) = f' := ringHom_ext (fun r => rfl) fun i => rfl rw [← hfg, RingHom.comp_assoc] refine (quotient_mk_comp_C_isIntegral_of_jacobson (RingHom.ker f')).trans _ g (g.isIntegral_of_surjective ?_) rw [← hfg] at hf' norm_num at hf' exact Function.Surjective.of_comp hf' rw [RingHom.comp_assoc] at this convert this refine RingHom.ext fun x => ?_ exact ((renameEquiv R e).commutes' x).symm end MvPolynomial end Ideal
RingTheory\JacobsonIdeal.lean
/- Copyright (c) 2020 Devon Tuma. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Devon Tuma -/ import Mathlib.RingTheory.Ideal.IsPrimary import Mathlib.RingTheory.Ideal.Quotient import Mathlib.RingTheory.Polynomial.Quotient /-! # Jacobson radical The Jacobson radical of a ring `R` is defined to be the intersection of all maximal ideals of `R`. This is similar to how the nilradical is equal to the intersection of all prime ideals of `R`. We can extend the idea of the nilradical to ideals of `R`, by letting the radical of an ideal `I` be the intersection of prime ideals containing `I`. Under this extension, the original nilradical is the radical of the zero ideal `⊥`. Here we define the Jacobson radical of an ideal `I` in a similar way, as the intersection of maximal ideals containing `I`. ## Main definitions Let `R` be a commutative ring, and `I` be an ideal of `R` * `Ideal.jacobson I` is the jacobson radical, i.e. the infimum of all maximal ideals containing I. * `Ideal.IsLocal I` is the proposition that the jacobson radical of `I` is itself a maximal ideal ## Main statements * `mem_jacobson_iff` gives a characterization of members of the jacobson of I * `Ideal.isLocal_of_isMaximal_radical`: if the radical of I is maximal then so is the jacobson radical ## Tags Jacobson, Jacobson radical, Local Ideal -/ universe u v namespace Ideal variable {R : Type u} {S : Type v} open Polynomial section Jacobson section Ring variable [Ring R] [Ring S] {I : Ideal R} /-- The Jacobson radical of `I` is the infimum of all maximal (left) ideals containing `I`. -/ def jacobson (I : Ideal R) : Ideal R := sInf { J : Ideal R | I ≤ J ∧ IsMaximal J } theorem le_jacobson : I ≤ jacobson I := fun _ hx => mem_sInf.mpr fun _ hJ => hJ.left hx @[simp] theorem jacobson_idem : jacobson (jacobson I) = jacobson I := le_antisymm (sInf_le_sInf fun _ hJ => ⟨sInf_le hJ, hJ.2⟩) le_jacobson @[simp] theorem jacobson_top : jacobson (⊤ : Ideal R) = ⊤ := eq_top_iff.2 le_jacobson @[simp] theorem jacobson_eq_top_iff : jacobson I = ⊤ ↔ I = ⊤ := ⟨fun H => by_contradiction fun hi => let ⟨M, hm, him⟩ := exists_le_maximal I hi lt_top_iff_ne_top.1 (lt_of_le_of_lt (show jacobson I ≤ M from sInf_le ⟨him, hm⟩) <| lt_top_iff_ne_top.2 hm.ne_top) H, fun H => eq_top_iff.2 <| le_sInf fun _ ⟨hij, _⟩ => H ▸ hij⟩ theorem jacobson_eq_bot : jacobson I = ⊥ → I = ⊥ := fun h => eq_bot_iff.mpr (h ▸ le_jacobson) theorem jacobson_eq_self_of_isMaximal [H : IsMaximal I] : I.jacobson = I := le_antisymm (sInf_le ⟨le_of_eq rfl, H⟩) le_jacobson instance (priority := 100) jacobson.isMaximal [H : IsMaximal I] : IsMaximal (jacobson I) := ⟨⟨fun htop => H.1.1 (jacobson_eq_top_iff.1 htop), fun _ hJ => H.1.2 _ (lt_of_le_of_lt le_jacobson hJ)⟩⟩ theorem mem_jacobson_iff {x : R} : x ∈ jacobson I ↔ ∀ y, ∃ z, z * y * x + z - 1 ∈ I := ⟨fun hx y => by_cases (fun hxy : I ⊔ span {y * x + 1} = ⊤ => let ⟨p, hpi, q, hq, hpq⟩ := Submodule.mem_sup.1 ((eq_top_iff_one _).1 hxy) let ⟨r, hr⟩ := mem_span_singleton'.1 hq ⟨r, by -- Porting note: supply `mul_add_one` with explicit variables rw [mul_assoc, ← mul_add_one r (y * x), hr, ← hpq, ← neg_sub, add_sub_cancel_right] exact I.neg_mem hpi⟩) fun hxy : I ⊔ span {y * x + 1} ≠ ⊤ => let ⟨M, hm1, hm2⟩ := exists_le_maximal _ hxy suffices x ∉ M from (this <| mem_sInf.1 hx ⟨le_trans le_sup_left hm2, hm1⟩).elim fun hxm => hm1.1.1 <| (eq_top_iff_one _).2 <| add_sub_cancel_left (y * x) 1 ▸ M.sub_mem (le_sup_right.trans hm2 <| subset_span rfl) (M.mul_mem_left _ hxm), fun hx => mem_sInf.2 fun M ⟨him, hm⟩ => by_contradiction fun hxm => let ⟨y, i, hi, df⟩ := hm.exists_inv hxm let ⟨z, hz⟩ := hx (-y) hm.1.1 <| (eq_top_iff_one _).2 <| sub_sub_cancel (z * -y * x + z) 1 ▸ M.sub_mem (by -- Porting note: supply `mul_add_one` with explicit variables rw [mul_assoc, ← mul_add_one z, neg_mul, ← sub_eq_iff_eq_add.mpr df.symm, neg_sub, sub_add_cancel] exact M.mul_mem_left _ hi) <| him hz⟩ theorem exists_mul_sub_mem_of_sub_one_mem_jacobson {I : Ideal R} (r : R) (h : r - 1 ∈ jacobson I) : ∃ s, s * r - 1 ∈ I := by cases' mem_jacobson_iff.1 h 1 with s hs use s simpa [mul_sub] using hs /-- An ideal equals its Jacobson radical iff it is the intersection of a set of maximal ideals. Allowing the set to include ⊤ is equivalent, and is included only to simplify some proofs. -/ theorem eq_jacobson_iff_sInf_maximal : I.jacobson = I ↔ ∃ M : Set (Ideal R), (∀ J ∈ M, IsMaximal J ∨ J = ⊤) ∧ I = sInf M := by use fun hI => ⟨{ J : Ideal R | I ≤ J ∧ J.IsMaximal }, ⟨fun _ hJ => Or.inl hJ.right, hI.symm⟩⟩ rintro ⟨M, hM, hInf⟩ refine le_antisymm (fun x hx => ?_) le_jacobson rw [hInf, mem_sInf] intro I hI cases' hM I hI with is_max is_top · exact (mem_sInf.1 hx) ⟨le_sInf_iff.1 (le_of_eq hInf) I hI, is_max⟩ · exact is_top.symm ▸ Submodule.mem_top theorem eq_jacobson_iff_sInf_maximal' : I.jacobson = I ↔ ∃ M : Set (Ideal R), (∀ J ∈ M, ∀ (K : Ideal R), J < K → K = ⊤) ∧ I = sInf M := eq_jacobson_iff_sInf_maximal.trans ⟨fun h => let ⟨M, hM⟩ := h ⟨M, ⟨fun J hJ K hK => Or.recOn (hM.1 J hJ) (fun h => h.1.2 K hK) fun h => eq_top_iff.2 (le_of_lt (h ▸ hK)), hM.2⟩⟩, fun h => let ⟨M, hM⟩ := h ⟨M, ⟨fun J hJ => Or.recOn (Classical.em (J = ⊤)) (fun h => Or.inr h) fun h => Or.inl ⟨⟨h, hM.1 J hJ⟩⟩, hM.2⟩⟩⟩ /-- An ideal `I` equals its Jacobson radical if and only if every element outside `I` also lies outside of a maximal ideal containing `I`. -/ theorem eq_jacobson_iff_not_mem : I.jacobson = I ↔ ∀ (x) (_ : x ∉ I), ∃ M : Ideal R, (I ≤ M ∧ M.IsMaximal) ∧ x ∉ M := by constructor · intro h x hx erw [← h, mem_sInf] at hx push_neg at hx exact hx · refine fun h => le_antisymm (fun x hx => ?_) le_jacobson contrapose hx erw [mem_sInf] push_neg exact h x hx theorem map_jacobson_of_surjective {f : R →+* S} (hf : Function.Surjective f) : RingHom.ker f ≤ I → map f I.jacobson = (map f I).jacobson := by intro h unfold Ideal.jacobson -- Porting note: dot notation for `RingHom.ker` does not work have : ∀ J ∈ { J : Ideal R | I ≤ J ∧ J.IsMaximal }, RingHom.ker f ≤ J := fun J hJ => le_trans h hJ.left refine Trans.trans (map_sInf hf this) (le_antisymm ?_ ?_) · refine sInf_le_sInf fun J hJ => ⟨comap f J, ⟨⟨le_comap_of_map_le hJ.1, ?_⟩, map_comap_of_surjective f hf J⟩⟩ haveI : J.IsMaximal := hJ.right exact comap_isMaximal_of_surjective f hf · refine sInf_le_sInf_of_subset_insert_top fun j hj => hj.recOn fun J hJ => ?_ rw [← hJ.2] cases' map_eq_top_or_isMaximal_of_surjective f hf hJ.left.right with htop hmax · exact htop.symm ▸ Set.mem_insert ⊤ _ · exact Set.mem_insert_of_mem ⊤ ⟨map_mono hJ.1.1, hmax⟩ theorem map_jacobson_of_bijective {f : R →+* S} (hf : Function.Bijective f) : map f I.jacobson = (map f I).jacobson := map_jacobson_of_surjective hf.right (le_trans (le_of_eq (f.injective_iff_ker_eq_bot.1 hf.left)) bot_le) theorem comap_jacobson {f : R →+* S} {K : Ideal S} : comap f K.jacobson = sInf (comap f '' { J : Ideal S | K ≤ J ∧ J.IsMaximal }) := Trans.trans (comap_sInf' f _) sInf_eq_iInf.symm theorem comap_jacobson_of_surjective {f : R →+* S} (hf : Function.Surjective f) {K : Ideal S} : comap f K.jacobson = (comap f K).jacobson := by unfold Ideal.jacobson refine le_antisymm ?_ ?_ · rw [← top_inf_eq (sInf _), ← sInf_insert, comap_sInf', sInf_eq_iInf] refine iInf_le_iInf_of_subset fun J hJ => ?_ have : comap f (map f J) = J := Trans.trans (comap_map_of_surjective f hf J) (le_antisymm (sup_le_iff.2 ⟨le_of_eq rfl, le_trans (comap_mono bot_le) hJ.left⟩) le_sup_left) cases' map_eq_top_or_isMaximal_of_surjective _ hf hJ.right with htop hmax · exact ⟨⊤, Set.mem_insert ⊤ _, htop ▸ this⟩ · exact ⟨map f J, Set.mem_insert_of_mem _ ⟨le_map_of_comap_le_of_surjective f hf hJ.1, hmax⟩, this⟩ · simp_rw [comap_sInf, le_iInf_iff] intros J hJ haveI : J.IsMaximal := hJ.right exact sInf_le ⟨comap_mono hJ.left, comap_isMaximal_of_surjective _ hf⟩ @[mono] theorem jacobson_mono {I J : Ideal R} : I ≤ J → I.jacobson ≤ J.jacobson := by intro h x hx erw [mem_sInf] at hx ⊢ exact fun K ⟨hK, hK_max⟩ => hx ⟨Trans.trans h hK, hK_max⟩ end Ring section CommRing variable [CommRing R] [CommRing S] {I : Ideal R} theorem radical_le_jacobson : radical I ≤ jacobson I := le_sInf fun _ hJ => (radical_eq_sInf I).symm ▸ sInf_le ⟨hJ.left, IsMaximal.isPrime hJ.right⟩ theorem isRadical_of_eq_jacobson (h : jacobson I = I) : I.IsRadical := radical_le_jacobson.trans h.le theorem isUnit_of_sub_one_mem_jacobson_bot (r : R) (h : r - 1 ∈ jacobson (⊥ : Ideal R)) : IsUnit r := by cases' exists_mul_sub_mem_of_sub_one_mem_jacobson r h with s hs rw [mem_bot, sub_eq_zero, mul_comm] at hs exact isUnit_of_mul_eq_one _ _ hs theorem mem_jacobson_bot {x : R} : x ∈ jacobson (⊥ : Ideal R) ↔ ∀ y, IsUnit (x * y + 1) := ⟨fun hx y => let ⟨z, hz⟩ := (mem_jacobson_iff.1 hx) y isUnit_iff_exists_inv.2 ⟨z, by rwa [add_mul, one_mul, ← sub_eq_zero, mul_right_comm, mul_comm _ z, mul_right_comm]⟩, fun h => mem_jacobson_iff.mpr fun y => let ⟨b, hb⟩ := isUnit_iff_exists_inv.1 (h y) ⟨b, (Submodule.mem_bot R).2 (hb ▸ by ring)⟩⟩ /-- An ideal `I` of `R` is equal to its Jacobson radical if and only if the Jacobson radical of the quotient ring `R/I` is the zero ideal -/ -- Porting note: changed `Quotient.mk'` to `` theorem jacobson_eq_iff_jacobson_quotient_eq_bot : I.jacobson = I ↔ jacobson (⊥ : Ideal (R ⧸ I)) = ⊥ := by have hf : Function.Surjective (Ideal.Quotient.mk I) := Submodule.Quotient.mk_surjective I constructor · intro h replace h := congr_arg (Ideal.map (Ideal.Quotient.mk I)) h rw [map_jacobson_of_surjective hf (le_of_eq mk_ker)] at h simpa using h · intro h replace h := congr_arg (comap (Ideal.Quotient.mk I)) h rw [comap_jacobson_of_surjective hf, ← RingHom.ker_eq_comap_bot (Ideal.Quotient.mk I)] at h simpa using h /-- The standard radical and Jacobson radical of an ideal `I` of `R` are equal if and only if the nilradical and Jacobson radical of the quotient ring `R/I` coincide -/ -- Porting note: changed `Quotient.mk'` to `` theorem radical_eq_jacobson_iff_radical_quotient_eq_jacobson_bot : I.radical = I.jacobson ↔ radical (⊥ : Ideal (R ⧸ I)) = jacobson ⊥ := by have hf : Function.Surjective (Ideal.Quotient.mk I) := Submodule.Quotient.mk_surjective I constructor · intro h have := congr_arg (map (Ideal.Quotient.mk I)) h rw [map_radical_of_surjective hf (le_of_eq mk_ker), map_jacobson_of_surjective hf (le_of_eq mk_ker)] at this simpa using this · intro h have := congr_arg (comap (Ideal.Quotient.mk I)) h rw [comap_radical, comap_jacobson_of_surjective hf, ← RingHom.ker_eq_comap_bot (Ideal.Quotient.mk I)] at this simpa using this theorem jacobson_radical_eq_jacobson : I.radical.jacobson = I.jacobson := le_antisymm (le_trans (le_of_eq (congr_arg jacobson (radical_eq_sInf I))) (sInf_le_sInf fun _ hJ => ⟨sInf_le ⟨hJ.1, hJ.2.isPrime⟩, hJ.2⟩)) (jacobson_mono le_radical) end CommRing end Jacobson section Polynomial open Polynomial variable [CommRing R] theorem jacobson_bot_polynomial_le_sInf_map_maximal : jacobson (⊥ : Ideal R[X]) ≤ sInf (map (C : R →+* R[X]) '' { J : Ideal R | J.IsMaximal }) := by refine le_sInf fun J => exists_imp.2 fun j hj => ?_ haveI : j.IsMaximal := hj.1 refine Trans.trans (jacobson_mono bot_le) (le_of_eq ?_ : J.jacobson ≤ J) suffices t : (⊥ : Ideal (Polynomial (R ⧸ j))).jacobson = ⊥ by rw [← hj.2, jacobson_eq_iff_jacobson_quotient_eq_bot] replace t := congr_arg (map (polynomialQuotientEquivQuotientPolynomial j).toRingHom) t rwa [map_jacobson_of_bijective _, map_bot] at t exact RingEquiv.bijective (polynomialQuotientEquivQuotientPolynomial j) refine eq_bot_iff.2 fun f hf => ?_ have r1 : (X : (R ⧸ j)[X]) ≠ 0 := fun hX => by replace hX := congr_arg (fun f => coeff f 1) hX simp only [coeff_X_one, coeff_zero] at hX exact zero_ne_one hX.symm have r2 := eq_C_of_degree_eq_zero (degree_eq_zero_of_isUnit ((mem_jacobson_bot.1 hf) X)) simp only [coeff_add, mul_coeff_zero, coeff_X_zero, mul_zero, coeff_one_zero, zero_add] at r2 erw [add_left_eq_self] at r2 simpa using (mul_eq_zero.mp r2).resolve_right r1 -- Porting note: this is golfed to much -- simpa [(fun hX => by simpa using congr_arg (fun f => coeff f 1) hX : (X : (R ⧸ j)[X]) ≠ 0)] -- using eq_C_of_degree_eq_zero (degree_eq_zero_of_is_unit ((mem_jacobson_bot.1 hf) X)) theorem jacobson_bot_polynomial_of_jacobson_bot (h : jacobson (⊥ : Ideal R) = ⊥) : jacobson (⊥ : Ideal R[X]) = ⊥ := by refine eq_bot_iff.2 (le_trans jacobson_bot_polynomial_le_sInf_map_maximal ?_) refine fun f hf => (Submodule.mem_bot R[X]).2 <| Polynomial.ext fun n => Trans.trans (?_ : coeff f n = 0) (coeff_zero n).symm suffices f.coeff n ∈ Ideal.jacobson ⊥ by rwa [h, Submodule.mem_bot] at this exact mem_sInf.2 fun j hj => (mem_map_C_iff.1 ((mem_sInf.1 hf) ⟨j, ⟨hj.2, rfl⟩⟩)) n end Polynomial section IsLocal variable [CommRing R] /-- An ideal `I` is local iff its Jacobson radical is maximal. -/ class IsLocal (I : Ideal R) : Prop where /-- A ring `R` is local if and only if its jacobson radical is maximal -/ out : IsMaximal (jacobson I) theorem isLocal_iff {I : Ideal R} : IsLocal I ↔ IsMaximal (jacobson I) := ⟨fun h => h.1, fun h => ⟨h⟩⟩ theorem isLocal_of_isMaximal_radical {I : Ideal R} (hi : IsMaximal (radical I)) : IsLocal I := ⟨have : radical I = jacobson I := le_antisymm (le_sInf fun _ ⟨him, hm⟩ => hm.isPrime.radical_le_iff.2 him) (sInf_le ⟨le_radical, hi⟩) show IsMaximal (jacobson I) from this ▸ hi⟩ theorem IsLocal.le_jacobson {I J : Ideal R} (hi : IsLocal I) (hij : I ≤ J) (hj : J ≠ ⊤) : J ≤ jacobson I := let ⟨_, hm, hjm⟩ := exists_le_maximal J hj le_trans hjm <| le_of_eq <| Eq.symm <| hi.1.eq_of_le hm.1.1 <| sInf_le ⟨le_trans hij hjm, hm⟩ theorem IsLocal.mem_jacobson_or_exists_inv {I : Ideal R} (hi : IsLocal I) (x : R) : x ∈ jacobson I ∨ ∃ y, y * x - 1 ∈ I := by_cases (fun h : I ⊔ span {x} = ⊤ => let ⟨p, hpi, q, hq, hpq⟩ := Submodule.mem_sup.1 ((eq_top_iff_one _).1 h) let ⟨r, hr⟩ := mem_span_singleton.1 hq Or.inr ⟨r, by rw [← hpq, mul_comm, ← hr, ← neg_sub, add_sub_cancel_right]; exact I.neg_mem hpi⟩) fun h : I ⊔ span {x} ≠ ⊤ => Or.inl <| le_trans le_sup_right (hi.le_jacobson le_sup_left h) <| mem_span_singleton.2 <| dvd_refl x end IsLocal theorem isPrimary_of_isMaximal_radical [CommRing R] {I : Ideal R} (hi : IsMaximal (radical I)) : IsPrimary I := have : radical I = jacobson I := le_antisymm (le_sInf fun M ⟨him, hm⟩ => hm.isPrime.radical_le_iff.2 him) (sInf_le ⟨le_radical, hi⟩) ⟨ne_top_of_lt <| lt_of_le_of_lt le_radical (lt_top_iff_ne_top.2 hi.1.1), fun {x y} hxy => ((isLocal_of_isMaximal_radical hi).mem_jacobson_or_exists_inv y).symm.imp (fun ⟨z, hz⟩ => by rw [← mul_one x, ← sub_sub_cancel (z * y) 1, mul_sub, mul_left_comm] exact I.sub_mem (I.mul_mem_left _ hxy) (I.mul_mem_left _ hz)) (this ▸ id)⟩ end Ideal
RingTheory\LaurentSeries.lean
/- Copyright (c) 2021 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, María Inés de Frutos-Fernández, Filippo A. E. Nuccio -/ import Mathlib.Data.Int.Interval import Mathlib.RingTheory.Binomial import Mathlib.RingTheory.DedekindDomain.Basic import Mathlib.RingTheory.HahnSeries.PowerSeries import Mathlib.RingTheory.HahnSeries.Summable import Mathlib.RingTheory.PowerSeries.Inverse import Mathlib.FieldTheory.RatFunc.AsPolynomial import Mathlib.RingTheory.Localization.FractionRing /-! # Laurent Series ## Main Definitions * Defines `LaurentSeries` as an abbreviation for `HahnSeries ℤ`. * Defines `hasseDeriv` of a Laurent series with coefficients in a module over a ring. * Provides a coercion `PowerSeries R` into `LaurentSeries R` given by `HahnSeries.ofPowerSeries`. * Defines `LaurentSeries.powerSeriesPart` * Defines the localization map `LaurentSeries.of_powerSeries_localization` which evaluates to `HahnSeries.ofPowerSeries`. * Embedding of rational functions into Laurent series, provided as a coercion, utilizing the underlying `RatFunc.coeAlgHom`. * Study of the `X`-Adic valuation on the ring of Laurent series over a field ## Main Results * Basic properties of Hasse derivatives ### About the `X`-Adic valuation: * The (integral) valuation of a power series is the order of the first non-zero coefficient, see `intValuation_le_iff_coeff_lt_eq_zero`. * The valuation of a Laurent series is the order of the first non-zero coefficient, see `valuation_le_iff_coeff_lt_eq_zero`. * Every Laurent series of valuation less than `(1 : ℤₘ₀)` comes from a power series, see `val_le_one_iff_eq_coe`. ## Implementation details * Since `LaurentSeries` is just an abbreviation of `HahnSeries ℤ _`, the definition of the coefficients is given in terms of `HahnSeries.coeff` and this forces sometimes to go back-and-forth from `X : LaurentSeries _` to `single 1 1 : HahnSeries ℤ _`. -/ universe u open scoped Classical open HahnSeries Polynomial noncomputable section /-- A `LaurentSeries` is implemented as a `HahnSeries` with value group `ℤ`. -/ abbrev LaurentSeries (R : Type u) [Zero R] := HahnSeries ℤ R variable {R : Type*} namespace LaurentSeries section HasseDeriv /-- The Hasse derivative of Laurent series, as a linear map. -/ @[simps] def hasseDeriv (R : Type*) {V : Type*} [AddCommGroup V] [Semiring R] [Module R V] (k : ℕ) : LaurentSeries V →ₗ[R] LaurentSeries V where toFun f := HahnSeries.ofSuppBddBelow (fun (n : ℤ) => (Ring.choose (n + k) k) • f.coeff (n + k)) (forallLTEqZero_supp_BddBelow _ (f.order - k : ℤ) (fun _ h_lt ↦ by rw [coeff_eq_zero_of_lt_order <| lt_sub_iff_add_lt.mp h_lt, smul_zero])) map_add' f g := by ext simp only [ofSuppBddBelow, add_coeff', Pi.add_apply, smul_add] map_smul' r f := by ext simp only [ofSuppBddBelow, smul_coeff, RingHom.id_apply, smul_comm r] variable [Semiring R] {V : Type*} [AddCommGroup V] [Module R V] theorem hasseDeriv_coeff (k : ℕ) (f : LaurentSeries V) (n : ℤ) : (hasseDeriv R k f).coeff n = Ring.choose (n + k) k • f.coeff (n + k) := rfl end HasseDeriv section Semiring variable [Semiring R] instance : Coe (PowerSeries R) (LaurentSeries R) := ⟨HahnSeries.ofPowerSeries ℤ R⟩ /- Porting note: now a syntactic tautology and not needed elsewhere theorem coe_powerSeries (x : PowerSeries R) : (x : LaurentSeries R) = HahnSeries.ofPowerSeries ℤ R x := rfl -/ @[simp] theorem coeff_coe_powerSeries (x : PowerSeries R) (n : ℕ) : HahnSeries.coeff (x : LaurentSeries R) n = PowerSeries.coeff R n x := by rw [ofPowerSeries_apply_coeff] /-- This is a power series that can be multiplied by an integer power of `X` to give our Laurent series. If the Laurent series is nonzero, `powerSeriesPart` has a nonzero constant term. -/ def powerSeriesPart (x : LaurentSeries R) : PowerSeries R := PowerSeries.mk fun n => x.coeff (x.order + n) @[simp] theorem powerSeriesPart_coeff (x : LaurentSeries R) (n : ℕ) : PowerSeries.coeff R n x.powerSeriesPart = x.coeff (x.order + n) := PowerSeries.coeff_mk _ _ @[simp] theorem powerSeriesPart_zero : powerSeriesPart (0 : LaurentSeries R) = 0 := by ext simp [(PowerSeries.coeff _ _).map_zero] -- Note: this doesn't get picked up any more @[simp] theorem powerSeriesPart_eq_zero (x : LaurentSeries R) : x.powerSeriesPart = 0 ↔ x = 0 := by constructor · contrapose! simp only [ne_eq] intro h rw [PowerSeries.ext_iff, not_forall] refine ⟨0, ?_⟩ simp [coeff_order_ne_zero h] · rintro rfl simp @[simp] theorem single_order_mul_powerSeriesPart (x : LaurentSeries R) : (single x.order 1 : LaurentSeries R) * x.powerSeriesPart = x := by ext n rw [← sub_add_cancel n x.order, single_mul_coeff_add, sub_add_cancel, one_mul] by_cases h : x.order ≤ n · rw [Int.eq_natAbs_of_zero_le (sub_nonneg_of_le h), coeff_coe_powerSeries, powerSeriesPart_coeff, ← Int.eq_natAbs_of_zero_le (sub_nonneg_of_le h), add_sub_cancel] · rw [ofPowerSeries_apply, embDomain_notin_range] · contrapose! h exact order_le_of_coeff_ne_zero h.symm · contrapose! h simp only [Set.mem_range, RelEmbedding.coe_mk, Function.Embedding.coeFn_mk] at h obtain ⟨m, hm⟩ := h rw [← sub_nonneg, ← hm] simp only [Nat.cast_nonneg] theorem ofPowerSeries_powerSeriesPart (x : LaurentSeries R) : ofPowerSeries ℤ R x.powerSeriesPart = single (-x.order) 1 * x := by refine Eq.trans ?_ (congr rfl x.single_order_mul_powerSeriesPart) rw [← mul_assoc, single_mul_single, neg_add_self, mul_one, ← C_apply, C_one, one_mul] end Semiring instance [CommSemiring R] : Algebra (PowerSeries R) (LaurentSeries R) := (HahnSeries.ofPowerSeries ℤ R).toAlgebra @[simp] theorem coe_algebraMap [CommSemiring R] : ⇑(algebraMap (PowerSeries R) (LaurentSeries R)) = HahnSeries.ofPowerSeries ℤ R := rfl /-- The localization map from power series to Laurent series. -/ @[simps (config := { rhsMd := .all, simpRhs := true })] instance of_powerSeries_localization [CommRing R] : IsLocalization (Submonoid.powers (PowerSeries.X : PowerSeries R)) (LaurentSeries R) where map_units' := by rintro ⟨_, n, rfl⟩ refine ⟨⟨single (n : ℤ) 1, single (-n : ℤ) 1, ?_, ?_⟩, ?_⟩ · simp · simp · dsimp; rw [ofPowerSeries_X_pow] surj' z := by by_cases h : 0 ≤ z.order · refine ⟨⟨PowerSeries.X ^ Int.natAbs z.order * powerSeriesPart z, 1⟩, ?_⟩ simp only [RingHom.map_one, mul_one, RingHom.map_mul, coe_algebraMap, ofPowerSeries_X_pow, Submonoid.coe_one] rw [Int.natAbs_of_nonneg h, single_order_mul_powerSeriesPart] · refine ⟨⟨powerSeriesPart z, PowerSeries.X ^ Int.natAbs z.order, ⟨_, rfl⟩⟩, ?_⟩ simp only [coe_algebraMap, ofPowerSeries_powerSeriesPart] rw [mul_comm _ z] refine congr rfl ?_ rw [ofPowerSeries_X_pow, Int.ofNat_natAbs_of_nonpos] exact le_of_not_ge h exists_of_eq {x y} := by rw [coe_algebraMap, ofPowerSeries_injective.eq_iff] rintro rfl exact ⟨1, rfl⟩ instance {K : Type*} [Field K] : IsFractionRing (PowerSeries K) (LaurentSeries K) := IsLocalization.of_le (Submonoid.powers (PowerSeries.X : PowerSeries K)) _ (powers_le_nonZeroDivisors_of_noZeroDivisors PowerSeries.X_ne_zero) fun _ hf => isUnit_of_mem_nonZeroDivisors <| map_mem_nonZeroDivisors _ HahnSeries.ofPowerSeries_injective hf end LaurentSeries namespace PowerSeries open LaurentSeries variable {R' : Type*} [Semiring R] [Ring R'] (f g : PowerSeries R) (f' g' : PowerSeries R') @[norm_cast] -- Porting note (#10618): simp can prove this theorem coe_zero : ((0 : PowerSeries R) : LaurentSeries R) = 0 := (ofPowerSeries ℤ R).map_zero @[norm_cast] -- Porting note (#10618): simp can prove this theorem coe_one : ((1 : PowerSeries R) : LaurentSeries R) = 1 := (ofPowerSeries ℤ R).map_one @[norm_cast] -- Porting note (#10618): simp can prove this theorem coe_add : ((f + g : PowerSeries R) : LaurentSeries R) = f + g := (ofPowerSeries ℤ R).map_add _ _ @[norm_cast] theorem coe_sub : ((f' - g' : PowerSeries R') : LaurentSeries R') = f' - g' := (ofPowerSeries ℤ R').map_sub _ _ @[norm_cast] theorem coe_neg : ((-f' : PowerSeries R') : LaurentSeries R') = -f' := (ofPowerSeries ℤ R').map_neg _ @[norm_cast] -- Porting note (#10618): simp can prove this theorem coe_mul : ((f * g : PowerSeries R) : LaurentSeries R) = f * g := (ofPowerSeries ℤ R).map_mul _ _ theorem coeff_coe (i : ℤ) : ((f : PowerSeries R) : LaurentSeries R).coeff i = if i < 0 then 0 else PowerSeries.coeff R i.natAbs f := by cases i · rw [Int.ofNat_eq_coe, coeff_coe_powerSeries, if_neg (Int.natCast_nonneg _).not_lt, Int.natAbs_ofNat] · rw [ofPowerSeries_apply, embDomain_notin_image_support, if_pos (Int.negSucc_lt_zero _)] simp only [not_exists, RelEmbedding.coe_mk, Set.mem_image, not_and, Function.Embedding.coeFn_mk, Ne, toPowerSeries_symm_apply_coeff, mem_support, imp_true_iff, not_false_iff] -- Porting note (#10618): simp can prove this -- Porting note: removed norm_cast attribute theorem coe_C (r : R) : ((C R r : PowerSeries R) : LaurentSeries R) = HahnSeries.C r := ofPowerSeries_C _ -- @[simp] -- Porting note (#10618): simp can prove this theorem coe_X : ((X : PowerSeries R) : LaurentSeries R) = single 1 1 := ofPowerSeries_X @[simp, norm_cast] theorem coe_smul {S : Type*} [Semiring S] [Module R S] (r : R) (x : PowerSeries S) : ((r • x : PowerSeries S) : LaurentSeries S) = r • (ofPowerSeries ℤ S x) := by ext simp [coeff_coe, coeff_smul, smul_ite] -- Porting note: RingHom.map_bit0 and RingHom.map_bit1 no longer exist @[norm_cast] theorem coe_pow (n : ℕ) : ((f ^ n : PowerSeries R) : LaurentSeries R) = (ofPowerSeries ℤ R f) ^ n := (ofPowerSeries ℤ R).map_pow _ _ end PowerSeries namespace RatFunc variable {F : Type u} [Field F] (p q : F[X]) (f g : RatFunc F) /-- The coercion `RatFunc F → LaurentSeries F` as bundled alg hom. -/ def coeAlgHom (F : Type u) [Field F] : RatFunc F →ₐ[F[X]] LaurentSeries F := liftAlgHom (Algebra.ofId _ _) <| nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ <| Polynomial.algebraMap_hahnSeries_injective _ /-- The coercion `RatFunc F → LaurentSeries F` as a function. This is the implementation of `coeToLaurentSeries`. -/ @[coe] def coeToLaurentSeries_fun {F : Type u} [Field F] : RatFunc F → LaurentSeries F := coeAlgHom F instance coeToLaurentSeries : Coe (RatFunc F) (LaurentSeries F) := ⟨coeToLaurentSeries_fun⟩ theorem coe_def : (f : LaurentSeries F) = coeAlgHom F f := rfl attribute [-instance] RatFunc.instCoePolynomial in -- avoids a diamond, see https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/compiling.20behaviour.20within.20one.20file theorem coe_num_denom : (f : LaurentSeries F) = f.num / f.denom := liftAlgHom_apply _ _ f theorem coe_injective : Function.Injective ((↑) : RatFunc F → LaurentSeries F) := liftAlgHom_injective _ (Polynomial.algebraMap_hahnSeries_injective _) -- Porting note: removed the `norm_cast` tag: -- `norm_cast: badly shaped lemma, rhs can't start with coe `↑(coeAlgHom F) f` @[simp] theorem coe_apply : coeAlgHom F f = f := rfl -- avoids a diamond, see https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/compiling.20behaviour.20within.20one.20file theorem coe_coe (P : Polynomial F) : ((P : PowerSeries F) : LaurentSeries F) = (P : RatFunc F) := by simp only [coePolynomial, coe_def, AlgHom.commutes, algebraMap_hahnSeries_apply] @[simp, norm_cast] theorem coe_zero : ((0 : RatFunc F) : LaurentSeries F) = 0 := map_zero (coeAlgHom F) theorem coe_ne_zero {f : Polynomial F} (hf : f ≠ 0) : (↑f : PowerSeries F) ≠ 0 := by simp only [ne_eq, Polynomial.coe_eq_zero_iff, hf, not_false_eq_true] @[simp, norm_cast] theorem coe_one : ((1 : RatFunc F) : LaurentSeries F) = 1 := map_one (coeAlgHom F) @[simp, norm_cast] theorem coe_add : ((f + g : RatFunc F) : LaurentSeries F) = f + g := map_add (coeAlgHom F) _ _ @[simp, norm_cast] theorem coe_sub : ((f - g : RatFunc F) : LaurentSeries F) = f - g := map_sub (coeAlgHom F) _ _ @[simp, norm_cast] theorem coe_neg : ((-f : RatFunc F) : LaurentSeries F) = -f := map_neg (coeAlgHom F) _ @[simp, norm_cast] theorem coe_mul : ((f * g : RatFunc F) : LaurentSeries F) = f * g := map_mul (coeAlgHom F) _ _ @[simp, norm_cast] theorem coe_pow (n : ℕ) : ((f ^ n : RatFunc F) : LaurentSeries F) = (f : LaurentSeries F) ^ n := map_pow (coeAlgHom F) _ _ @[simp, norm_cast] theorem coe_div : ((f / g : RatFunc F) : LaurentSeries F) = (f : LaurentSeries F) / (g : LaurentSeries F) := map_div₀ (coeAlgHom F) _ _ @[simp, norm_cast] theorem coe_C (r : F) : ((RatFunc.C r : RatFunc F) : LaurentSeries F) = HahnSeries.C r := by rw [coe_num_denom, num_C, denom_C, Polynomial.coe_C, -- Porting note: removed `coe_C` Polynomial.coe_one, PowerSeries.coe_one, div_one] simp only [algebraMap_eq_C, ofPowerSeries_C, C_apply] -- Porting note: added -- TODO: generalize over other modules @[simp, norm_cast] theorem coe_smul (r : F) : ((r • f : RatFunc F) : LaurentSeries F) = r • (f : LaurentSeries F) := by rw [RatFunc.smul_eq_C_mul, ← C_mul_eq_smul, coe_mul, coe_C] -- Porting note: removed `norm_cast` because "badly shaped lemma, rhs can't start with coe" -- even though `single 1 1` is a bundled function application, not a "real" coercion @[simp] theorem coe_X : ((X : RatFunc F) : LaurentSeries F) = single 1 1 := by rw [coe_num_denom, num_X, denom_X, Polynomial.coe_X, -- Porting note: removed `coe_C` Polynomial.coe_one, PowerSeries.coe_one, div_one] simp only [ofPowerSeries_X] -- Porting note: added theorem single_one_eq_pow {R : Type _} [Ring R] (n : ℕ) : single (n : ℤ) (1 : R) = single (1 : ℤ) 1 ^ n := by induction' n with n h_ind · simp · rw [← Int.ofNat_add_one_out, pow_succ', ← h_ind, HahnSeries.single_mul_single, one_mul, add_comm] theorem single_inv (d : ℤ) {α : F} (hα : α ≠ 0) : single (-d) (α⁻¹ : F) = (single (d : ℤ) (α : F))⁻¹ := by apply eq_inv_of_mul_eq_one_right simp [hα] theorem single_zpow (n : ℤ) : single (n : ℤ) (1 : F) = single (1 : ℤ) 1 ^ n := by induction' n with n_pos n_neg · apply single_one_eq_pow · rw [Int.negSucc_coe, Int.ofNat_add, Nat.cast_one, ← inv_one, single_inv (n_neg + 1 : ℤ) one_ne_zero, zpow_neg, ← Nat.cast_one, ← Int.ofNat_add, Nat.cast_one, inv_inj, zpow_natCast, single_one_eq_pow, inv_one] instance : Algebra (RatFunc F) (LaurentSeries F) := RingHom.toAlgebra (coeAlgHom F).toRingHom theorem algebraMap_apply_div : algebraMap (RatFunc F) (LaurentSeries F) (algebraMap _ _ p / algebraMap _ _ q) = algebraMap F[X] (LaurentSeries F) p / algebraMap _ _ q := by -- Porting note: had to supply implicit arguments to `convert` convert coe_div (algebraMap F[X] (RatFunc F) p) (algebraMap F[X] (RatFunc F) q) <;> rw [← mk_one, coe_def, coeAlgHom, mk_eq_div, liftAlgHom_apply_div, map_one, div_one, Algebra.ofId_apply] instance : IsScalarTower F[X] (RatFunc F) (LaurentSeries F) := ⟨fun x y z => by ext simp⟩ end RatFunc section AdicValuation open scoped DiscreteValuation variable (K : Type*) [Field K] namespace PowerSeries /-- The prime ideal `(X)` of `PowerSeries K`, when `K` is a field, as a term of the `HeightOneSpectrum`. -/ def idealX : IsDedekindDomain.HeightOneSpectrum K⟦X⟧ where asIdeal := Ideal.span {X} isPrime := PowerSeries.span_X_isPrime ne_bot := by rw [ne_eq, Ideal.span_singleton_eq_bot]; exact X_ne_zero open RatFunc IsDedekindDomain.HeightOneSpectrum variable {K} /- The `X`-adic valuation of a polynomial equals the `X`-adic valuation of its coercion to `K⟦X⟧`-/ theorem intValuation_eq_of_coe (P : K[X]) : (Polynomial.idealX K).intValuation P = (idealX K).intValuation (P : K⟦X⟧) := by by_cases hP : P = 0 · rw [hP, Valuation.map_zero, Polynomial.coe_zero, Valuation.map_zero] simp only [intValuation_apply] rw [intValuationDef_if_neg _ hP, intValuationDef_if_neg _ <| coe_ne_zero hP] simp only [idealX_span, ofAdd_neg, inv_inj, WithZero.coe_inj, EmbeddingLike.apply_eq_iff_eq, Nat.cast_inj] have span_ne_zero : (Ideal.span {P} : Ideal K[X]) ≠ 0 ∧ (Ideal.span {Polynomial.X} : Ideal K[X]) ≠ 0 := by simp only [Ideal.zero_eq_bot, ne_eq, Ideal.span_singleton_eq_bot, hP, Polynomial.X_ne_zero, not_false_iff, and_self_iff] have span_ne_zero' : (Ideal.span {↑P} : Ideal K⟦X⟧) ≠ 0 ∧ ((idealX K).asIdeal : Ideal K⟦X⟧) ≠ 0 := by simp only [Ideal.zero_eq_bot, ne_eq, Ideal.span_singleton_eq_bot, coe_eq_zero_iff, hP, not_false_eq_true, true_and, (idealX K).3] rw [count_associates_factors_eq (Ideal.span {P}) (Ideal.span {Polynomial.X}) (span_ne_zero).1 (Ideal.span_singleton_prime Polynomial.X_ne_zero|>.mpr prime_X) (span_ne_zero).2, count_associates_factors_eq (Ideal.span {↑(P : K⟦X⟧)}) (idealX K).asIdeal] on_goal 1 => convert (normalized_count_X_eq_of_coe hP).symm exacts [count_span_normalizedFactors_eq_of_normUnit hP Polynomial.normUnit_X prime_X, count_span_normalizedFactors_eq_of_normUnit (coe_ne_zero hP) normUnit_X X_prime, span_ne_zero'.1, (idealX K).isPrime, span_ne_zero'.2] /-- The integral valuation of the power series `X : K⟦X⟧` equals `(ofAdd -1) : ℤₘ₀`-/ @[simp] theorem intValuation_X : (idealX K).intValuationDef X = ↑(Multiplicative.ofAdd (-1 : ℤ)) := by rw [← Polynomial.coe_X, ← intValuation_apply, ← intValuation_eq_of_coe] apply intValuation_singleton _ Polynomial.X_ne_zero (by rfl) end PowerSeries namespace RatFunc open IsDedekindDomain.HeightOneSpectrum PowerSeries theorem valuation_eq_LaurentSeries_valuation (P : RatFunc K) : (Polynomial.idealX K).valuation P = (PowerSeries.idealX K).valuation (P : LaurentSeries K) := by refine RatFunc.induction_on' P ?_ intro f g h rw [Polynomial.valuation_of_mk K f h, RatFunc.mk_eq_mk' f h, Eq.comm] convert @valuation_of_mk' (PowerSeries K) _ _ (LaurentSeries K) _ _ _ (PowerSeries.idealX K) f ⟨g, mem_nonZeroDivisors_iff_ne_zero.2 <| coe_ne_zero h⟩ · simp only [IsFractionRing.mk'_eq_div, coe_div, LaurentSeries.coe_algebraMap, coe_coe] rfl exacts [intValuation_eq_of_coe _, intValuation_eq_of_coe _] end RatFunc namespace LaurentSeries open IsDedekindDomain.HeightOneSpectrum PowerSeries RatFunc instance : Valued (LaurentSeries K) ℤₘ₀ := Valued.mk' (PowerSeries.idealX K).valuation theorem valuation_X_pow (s : ℕ) : Valued.v (((X : K⟦X⟧) : LaurentSeries K) ^ s) = Multiplicative.ofAdd (-(s : ℤ)) := by erw [map_pow, ← one_mul (s : ℤ), ← neg_mul (1 : ℤ) s, Int.ofAdd_mul, WithZero.coe_zpow, ofAdd_neg, WithZero.coe_inv, zpow_natCast, valuation_of_algebraMap, intValuation_toFun, intValuation_X, ofAdd_neg, WithZero.coe_inv, inv_pow] theorem valuation_single_zpow (s : ℤ) : Valued.v (HahnSeries.single s (1 : K) : LaurentSeries K) = Multiplicative.ofAdd (-(s : ℤ)) := by have : Valued.v (1 : LaurentSeries K) = (1 : ℤₘ₀) := Valued.v.map_one rw [← single_zero_one, ← add_right_neg s, ← mul_one 1, ← single_mul_single, map_mul, mul_eq_one_iff_eq_inv₀] at this · rw [this] induction' s with s s · rw [Int.ofNat_eq_coe, ← HahnSeries.ofPowerSeries_X_pow] at this rw [Int.ofNat_eq_coe, ← this, PowerSeries.coe_pow, valuation_X_pow] · simp only [Int.negSucc_coe, neg_neg, ← HahnSeries.ofPowerSeries_X_pow, PowerSeries.coe_pow, valuation_X_pow, ofAdd_neg, WithZero.coe_inv, inv_inv] · simp only [Valuation.ne_zero_iff, ne_eq, one_ne_zero, not_false_iff, HahnSeries.single_ne_zero] /- The coefficients of a power series vanish in degree strictly less than its valuation. -/ theorem coeff_zero_of_lt_intValuation {n d : ℕ} {f : K⟦X⟧} (H : Valued.v (f : LaurentSeries K) ≤ Multiplicative.ofAdd (-d : ℤ)) : n < d → coeff K n f = 0 := by intro hnd apply (PowerSeries.X_pow_dvd_iff).mp _ n hnd erw [← span_singleton_dvd_span_singleton_iff_dvd, ← Ideal.span_singleton_pow, ← (intValuation_le_pow_iff_dvd (PowerSeries.idealX K) f d), ← intValuation_apply, ← valuation_of_algebraMap (R := K⟦X⟧) (K := (LaurentSeries K))] exact H /- The valuation of a power series is the order of the first non-zero coefficient. -/ theorem intValuation_le_iff_coeff_lt_eq_zero {d : ℕ} (f : K⟦X⟧) : Valued.v (f : LaurentSeries K) ≤ Multiplicative.ofAdd (-d : ℤ) ↔ ∀ n : ℕ, n < d → coeff K n f = 0 := by have : PowerSeries.X ^ d ∣ f ↔ ∀ n : ℕ, n < d → (PowerSeries.coeff K n) f = 0 := ⟨PowerSeries.X_pow_dvd_iff.mp, PowerSeries.X_pow_dvd_iff.mpr⟩ erw [← this, valuation_of_algebraMap (PowerSeries.idealX K) f, ← span_singleton_dvd_span_singleton_iff_dvd, ← Ideal.span_singleton_pow] apply intValuation_le_pow_iff_dvd /- The coefficients of a Laurent series vanish in degree strictly less than its valuation. -/ theorem coeff_zero_of_lt_valuation {n D : ℤ} {f : LaurentSeries K} (H : Valued.v f ≤ Multiplicative.ofAdd (-D)) : n < D → f.coeff n = 0 := by intro hnd by_cases h_n_ord : n < f.order · exact coeff_eq_zero_of_lt_order h_n_ord rw [not_lt] at h_n_ord set F := powerSeriesPart f with hF by_cases ord_nonpos : f.order ≤ 0 · obtain ⟨s, hs⟩ := Int.exists_eq_neg_ofNat ord_nonpos obtain ⟨m, hm⟩ := Int.eq_ofNat_of_zero_le (neg_le_iff_add_nonneg.mp (hs ▸ h_n_ord)) obtain ⟨d, hd⟩ := Int.eq_ofNat_of_zero_le (a := D + s) (by linarith) rw [eq_add_neg_of_add_eq hm, add_comm, ← hs, ← powerSeriesPart_coeff] apply (intValuation_le_iff_coeff_lt_eq_zero K F).mp _ m (by linarith) rwa [hF, ofPowerSeries_powerSeriesPart f, hs, neg_neg, ← hd, neg_add_rev, ofAdd_add, map_mul, ← ofPowerSeries_X_pow s, PowerSeries.coe_pow, WithZero.coe_mul, valuation_X_pow K s, mul_le_mul_left₀ (by simp only [ne_eq, WithZero.coe_ne_zero, not_false_iff])] · rw [not_le] at ord_nonpos obtain ⟨s, hs⟩ := Int.exists_eq_neg_ofNat (Int.neg_nonpos_of_nonneg (le_of_lt ord_nonpos)) obtain ⟨m, hm⟩ := Int.eq_ofNat_of_zero_le (a := n - s) (by linarith) obtain ⟨d, hd⟩ := Int.eq_ofNat_of_zero_le (a := D - s) (by linarith) rw [(sub_eq_iff_eq_add).mp hm, add_comm, ← neg_neg (s : ℤ), ← hs, neg_neg, ← powerSeriesPart_coeff] apply (intValuation_le_iff_coeff_lt_eq_zero K F).mp _ m (by linarith) rwa [hF, ofPowerSeries_powerSeriesPart f, map_mul, ← hd, hs, neg_sub, sub_eq_add_neg, ofAdd_add, valuation_single_zpow, neg_neg, WithZero.coe_mul, mul_le_mul_left₀ (by simp only [ne_eq, WithZero.coe_ne_zero, not_false_iff])] /- The valuation of a Laurent series is the order of the first non-zero coefficient. -/ theorem valuation_le_iff_coeff_lt_eq_zero {D : ℤ} {f : LaurentSeries K} : Valued.v f ≤ ↑(Multiplicative.ofAdd (-D : ℤ)) ↔ ∀ n : ℤ, n < D → f.coeff n = 0 := by refine ⟨fun hnD n hn => coeff_zero_of_lt_valuation K hnD hn, fun h_val_f => ?_⟩ let F := powerSeriesPart f by_cases ord_nonpos : f.order ≤ 0 · obtain ⟨s, hs⟩ := Int.exists_eq_neg_ofNat ord_nonpos rw [← f.single_order_mul_powerSeriesPart, hs, map_mul, valuation_single_zpow, neg_neg, mul_comm, ← le_mul_inv_iff₀, ofAdd_neg, WithZero.coe_inv, ← mul_inv, ← WithZero.coe_mul, ← ofAdd_add, ← WithZero.coe_inv, ← ofAdd_neg] · by_cases hDs : D + s ≤ 0 · apply le_trans ((PowerSeries.idealX K).valuation_le_one F) rwa [← WithZero.coe_one, ← ofAdd_zero, WithZero.coe_le_coe, Multiplicative.ofAdd_le, Left.nonneg_neg_iff] · obtain ⟨d, hd⟩ := Int.eq_ofNat_of_zero_le (le_of_lt <| not_le.mp hDs) rw [hd] apply (intValuation_le_iff_coeff_lt_eq_zero K F).mpr intro n hn rw [powerSeriesPart_coeff f n, hs] apply h_val_f linarith · simp only [ne_eq, WithZero.coe_ne_zero, not_false_iff] · obtain ⟨s, hs⟩ := Int.exists_eq_neg_ofNat <| neg_nonpos_of_nonneg <| le_of_lt <| not_le.mp ord_nonpos rw [neg_inj] at hs rw [← f.single_order_mul_powerSeriesPart, hs, map_mul, valuation_single_zpow, mul_comm, ← le_mul_inv_iff₀, ofAdd_neg, WithZero.coe_inv, ← mul_inv, ← WithZero.coe_mul, ← ofAdd_add, ← WithZero.coe_inv, ← ofAdd_neg, neg_add, neg_neg] · by_cases hDs : D - s ≤ 0 · apply le_trans ((PowerSeries.idealX K).valuation_le_one F) rw [← WithZero.coe_one, ← ofAdd_zero, WithZero.coe_le_coe, Multiplicative.ofAdd_le] linarith · obtain ⟨d, hd⟩ := Int.eq_ofNat_of_zero_le (le_of_lt <| not_le.mp hDs) rw [← neg_neg (-D + ↑s), ← sub_eq_neg_add, neg_sub, hd] apply (intValuation_le_iff_coeff_lt_eq_zero K F).mpr intro n hn rw [powerSeriesPart_coeff f n, hs] apply h_val_f (s + n) linarith · simp only [ne_eq, WithZero.coe_ne_zero, not_false_iff] /- Two Laurent series whose difference has small valuation have the same coefficients for small enough indices. -/ theorem eq_coeff_of_valuation_sub_lt {d n : ℤ} {f g : LaurentSeries K} (H : Valued.v (g - f) ≤ ↑(Multiplicative.ofAdd (-d))) : n < d → g.coeff n = f.coeff n := by by_cases triv : g = f · exact fun _ => by rw [triv] · intro hn apply eq_of_sub_eq_zero erw [← HahnSeries.sub_coeff] apply coeff_zero_of_lt_valuation K H hn /- Every Laurent series of valuation less than `(1 : ℤₘ₀)` comes from a power series. -/ theorem val_le_one_iff_eq_coe (f : LaurentSeries K) : Valued.v f ≤ (1 : ℤₘ₀) ↔ ∃ F : PowerSeries K, F = f := by rw [← WithZero.coe_one, ← ofAdd_zero, ← neg_zero, valuation_le_iff_coeff_lt_eq_zero] refine ⟨fun h => ⟨PowerSeries.mk fun n => f.coeff n, ?_⟩, ?_⟩ on_goal 1 => ext (_ | n) · simp only [Int.ofNat_eq_coe, coeff_coe_powerSeries, coeff_mk] on_goal 1 => simp only [h (Int.negSucc n) (Int.negSucc_lt_zero n)] on_goal 2 => rintro ⟨F, rfl⟩ _ _ all_goals apply HahnSeries.embDomain_notin_range simp only [Nat.coe_castAddMonoidHom, RelEmbedding.coe_mk, Function.Embedding.coeFn_mk, Set.mem_range, not_exists, Int.negSucc_lt_zero,] intro · simp only [not_false_eq_true] · linarith end LaurentSeries end AdicValuation
RingTheory\LittleWedderburn.lean
/- Copyright (c) 2021 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Eric Rodriguez -/ import Mathlib.GroupTheory.ClassEquation import Mathlib.GroupTheory.GroupAction.ConjAct import Mathlib.RingTheory.Polynomial.Cyclotomic.Eval /-! # Wedderburn's Little Theorem This file proves Wedderburn's Little Theorem. ## Main Declarations * `littleWedderburn`: a finite division ring is a field. ## Future work A couple simple generalisations are possible: * A finite ring is commutative iff all its nilpotents lie in the center. [Chintala, Vineeth, *Sorry, the Nilpotents Are in the Center*][chintala2020] * A ring is commutative if all its elements have finite order. [Dolan, S. W., *A Proof of Jacobson's Theorem*][dolan1975] When alternativity is added to Mathlib, one could formalise the Artin-Zorn theorem, which states that any finite alternative division ring is in fact a field. https://en.wikipedia.org/wiki/Artin%E2%80%93Zorn_theorem If interested, generalisations to semifields could be explored. The theory of semi-vector spaces is not clear, but assuming that such a theory could be found where every module considered in the below proof is free, then the proof works nearly verbatim. -/ open scoped Polynomial open Fintype /-! Everything in this namespace is internal to the proof of Wedderburn's little theorem. -/ namespace LittleWedderburn variable (D : Type*) [DivisionRing D] private def InductionHyp : Prop := ∀ {R : Subring D}, R < ⊤ → ∀ ⦃x y⦄, x ∈ R → y ∈ R → x * y = y * x namespace InductionHyp open FiniteDimensional Polynomial variable {D} private def field (hD : InductionHyp D) {R : Subring D} (hR : R < ⊤) [Fintype D] [DecidableEq D] [DecidablePred (· ∈ R)] : Field R := { show DivisionRing R from Fintype.divisionRingOfIsDomain R with mul_comm := fun x y ↦ Subtype.ext <| hD hR x.2 y.2 } /-- We prove that if every subring of `D` is central, then so is `D`. -/ private theorem center_eq_top [Finite D] (hD : InductionHyp D) : Subring.center D = ⊤ := by classical cases nonempty_fintype D set Z := Subring.center D -- We proceed by contradiction; that is, we assume the center is strictly smaller than `D`. by_contra! hZ letI : Field Z := hD.field hZ.lt_top set q := card Z with card_Z have hq : 1 < q := by rw [card_Z]; exact one_lt_card let n := finrank Z D have card_D : card D = q ^ n := card_eq_pow_finrank have h1qn : 1 ≤ q ^ n := by rw [← card_D]; exact card_pos -- We go about this by looking at the class equation for `Dˣ`: -- `q ^ n - 1 = q - 1 + ∑ x : conjugacy classes (D ∖ Dˣ), |x|`. -- The next few lines gets the equation into basically this form over `ℤ`. have key := Group.card_center_add_sum_card_noncenter_eq_card (Dˣ) rw [card_congr (show _ ≃* Zˣ from Subgroup.centerUnitsEquivUnitsCenter D).toEquiv, card_units, ← card_Z, card_units, card_D] at key -- By properties of the cyclotomic function, we have that `Φₙ(q) ∣ q ^ n - 1`; however, when -- `n ≠ 1`, then `¬Φₙ(q) | q - 1`; so if the sum over the conjugacy classes is divisible by -- `Φₙ(q)`, then `n = 1`, and therefore the vector space is trivial, as desired. let Φₙ := cyclotomic n ℤ apply_fun (Nat.cast : ℕ → ℤ) at key rw [Nat.cast_add, Nat.cast_sub h1qn, Nat.cast_sub hq.le, Nat.cast_one, Nat.cast_pow] at key suffices Φₙ.eval ↑q ∣ ↑(∑ x ∈ (ConjClasses.noncenter Dˣ).toFinset, x.carrier.toFinset.card) by have contra : Φₙ.eval _ ∣ _ := eval_dvd (cyclotomic.dvd_X_pow_sub_one n ℤ) (x := (q : ℤ)) rw [eval_sub, eval_pow, eval_X, eval_one, ← key, Int.dvd_add_left this] at contra refine (Nat.le_of_dvd ?_ ?_).not_lt (sub_one_lt_natAbs_cyclotomic_eval (n := n) ?_ hq.ne') · exact tsub_pos_of_lt hq · convert Int.natAbs_dvd_natAbs.mpr contra clear_value q simp only [eq_comm, Int.natAbs_eq_iff, Nat.cast_sub hq.le, Nat.cast_one, neg_sub, true_or] · by_contra! h obtain ⟨x, hx⟩ := finrank_le_one_iff.mp h refine not_le_of_lt hZ.lt_top (fun y _ ↦ Subring.mem_center_iff.mpr fun z ↦ ?_) obtain ⟨r, rfl⟩ := hx y obtain ⟨s, rfl⟩ := hx z rw [smul_mul_smul, smul_mul_smul, mul_comm] rw [Nat.cast_sum] apply Finset.dvd_sum rintro ⟨x⟩ hx simp (config := {zeta := false}) only [ConjClasses.quot_mk_eq_mk, Set.mem_toFinset] at hx ⊢ set Zx := Subring.centralizer ({↑x} : Set D) -- The key thing is then to note that for all conjugacy classes `x`, `|x|` is given by -- `|Dˣ| / |Zxˣ|`, where `Zx` is the centralizer of `x`; but `Zx` is an algebra over `Z`, and -- therefore `|Zxˣ| = q ^ d - 1`, where `d` is the dimension of `D` as a vector space over `Z`. -- We therefore get that `|x| = (q ^ n - 1) / (q ^ d - 1)`, and as `d` is a strict divisor of `n`, -- we do have that `Φₙ(q) | (q ^ n - 1) / (q ^ d - 1)`; extending this over the whole sum -- gives us the desired contradiction.. rw [Set.toFinset_card, ConjClasses.card_carrier, ← card_congr (show Zxˣ ≃* _ from unitsCentralizerEquiv _ x).toEquiv, card_units, card_D] have hZx : Zx ≠ ⊤ := by by_contra! hZx refine (ConjClasses.mk_bijOn (Dˣ)).mapsTo (Set.subset_center_units ?_) hx exact Subring.centralizer_eq_top_iff_subset.mp hZx <| Set.mem_singleton _ letI : Field Zx := hD.field hZx.lt_top letI : Algebra Z Zx := (Subring.inclusion <| Subring.center_le_centralizer {(x : D)}).toAlgebra let d := finrank Z Zx have card_Zx : card Zx = q ^ d := card_eq_pow_finrank have h1qd : 1 ≤ q ^ d := by rw [← card_Zx]; exact card_pos haveI : IsScalarTower Z Zx D := ⟨fun x y z ↦ mul_assoc _ _ _⟩ rw [card_units, card_Zx, Int.natCast_div, Nat.cast_sub h1qd, Nat.cast_sub h1qn, Nat.cast_one, Nat.cast_pow, Nat.cast_pow] apply Int.dvd_div_of_mul_dvd have aux : ∀ {k : ℕ}, ((X : ℤ[X]) ^ k - 1).eval ↑q = (q : ℤ) ^ k - 1 := by simp only [eval_X, eval_one, eval_pow, eval_sub, eq_self_iff_true, forall_const] rw [← aux, ← aux, ← eval_mul] refine (evalRingHom ↑q).map_dvd (X_pow_sub_one_mul_cyclotomic_dvd_X_pow_sub_one_of_dvd ℤ ?_) refine Nat.mem_properDivisors.mpr ⟨⟨_, (finrank_mul_finrank Z Zx D).symm⟩, ?_⟩ rw [← pow_lt_pow_iff_right hq, ← card_D, ← card_Zx] obtain ⟨b, -, hb⟩ := SetLike.exists_of_lt hZx.lt_top refine card_lt_of_injective_of_not_mem _ Subtype.val_injective (?_ : b ∉ _) rintro ⟨b, rfl⟩ exact hb b.2 end InductionHyp private theorem center_eq_top [Finite D] : Subring.center D = ⊤ := by classical cases nonempty_fintype D induction' hn : Fintype.card D using Nat.strong_induction_on with n IH generalizing D apply InductionHyp.center_eq_top intro R hR x y hx hy suffices (⟨y, hy⟩ : R) ∈ Subring.center R by rw [Subring.mem_center_iff] at this simpa using this ⟨x, hx⟩ let R_dr : DivisionRing R := Fintype.divisionRingOfIsDomain R rw [IH (Fintype.card R) _ R inferInstance rfl] · trivial rw [← hn, ← Subring.card_top D] exact Set.card_lt_card hR end LittleWedderburn open LittleWedderburn /-- A finite division ring is a field. See `Finite.isDomain_to_isField` and `Fintype.divisionRingOfIsDomain` for more general statements, but these create data, and therefore may cause diamonds if used improperly. -/ instance (priority := 100) littleWedderburn (D : Type*) [DivisionRing D] [Finite D] : Field D := { ‹DivisionRing D› with mul_comm := fun x y ↦ by simp [Subring.mem_center_iff.mp ?_ x, center_eq_top D] } alias Finite.divisionRing_to_field := littleWedderburn /-- A finite domain is a field. See also `littleWedderburn` and `Fintype.divisionRingOfIsDomain`. -/ theorem Finite.isDomain_to_isField (D : Type*) [Finite D] [Ring D] [IsDomain D] : IsField D := by classical cases nonempty_fintype D let _ := Fintype.divisionRingOfIsDomain D let _ := littleWedderburn D exact Field.toIsField D
RingTheory\LocalProperties.lean
/- Copyright (c) 2021 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.RingTheory.FiniteType import Mathlib.RingTheory.Localization.AtPrime import Mathlib.RingTheory.Localization.Away.Basic import Mathlib.RingTheory.Localization.Integer import Mathlib.RingTheory.Localization.Submodule import Mathlib.RingTheory.Nilpotent.Lemmas import Mathlib.RingTheory.RingHomProperties import Mathlib.Data.Set.Subsingleton /-! # Local properties of commutative rings In this file, we provide the proofs of various local properties. ## Naming Conventions * `localization_P` : `P` holds for `S⁻¹R` if `P` holds for `R`. * `P_of_localization_maximal` : `P` holds for `R` if `P` holds for `Rₘ` for all maximal `m`. * `P_of_localization_prime` : `P` holds for `R` if `P` holds for `Rₘ` for all prime `m`. * `P_ofLocalizationSpan` : `P` holds for `R` if given a spanning set `{fᵢ}`, `P` holds for all `R_{fᵢ}`. ## Main results The following properties are covered: * The triviality of an ideal or an element: `ideal_eq_bot_of_localization`, `eq_zero_of_localization` * `IsReduced` : `localization_isReduced`, `isReduced_of_localization_maximal`. * `RingHom.finite`: `localization_finite`, `finite_ofLocalizationSpan` * `RingHom.finiteType`: `localization_finiteType`, `finiteType_ofLocalizationSpan` -/ open scoped Pointwise Classical universe u variable {R S : Type u} [CommRing R] [CommRing S] (M : Submonoid R) variable (N : Submonoid S) (R' S' : Type u) [CommRing R'] [CommRing S'] (f : R →+* S) variable [Algebra R R'] [Algebra S S'] section Properties section CommRing variable (P : ∀ (R : Type u) [CommRing R], Prop) /-- A property `P` of comm rings is said to be preserved by localization if `P` holds for `M⁻¹R` whenever `P` holds for `R`. -/ def LocalizationPreserves : Prop := ∀ {R : Type u} [hR : CommRing R] (M : Submonoid R) (S : Type u) [hS : CommRing S] [Algebra R S] [IsLocalization M S], @P R hR → @P S hS /-- A property `P` of comm rings satisfies `OfLocalizationMaximal` if `P` holds for `R` whenever `P` holds for `Rₘ` for all maximal ideal `m`. -/ def OfLocalizationMaximal : Prop := ∀ (R : Type u) [CommRing R], (∀ (J : Ideal R) (_ : J.IsMaximal), P (Localization.AtPrime J)) → P R end CommRing section RingHom variable (P : ∀ {R S : Type u} [CommRing R] [CommRing S] (_ : R →+* S), Prop) /-- A property `P` of ring homs is said to be preserved by localization if `P` holds for `M⁻¹R →+* M⁻¹S` whenever `P` holds for `R →+* S`. -/ def RingHom.LocalizationPreserves := ∀ ⦃R S : Type u⦄ [CommRing R] [CommRing S] (f : R →+* S) (M : Submonoid R) (R' S' : Type u) [CommRing R'] [CommRing S'] [Algebra R R'] [Algebra S S'] [IsLocalization M R'] [IsLocalization (M.map f) S'], P f → P (IsLocalization.map S' f (Submonoid.le_comap_map M) : R' →+* S') /-- A property `P` of ring homs satisfies `RingHom.OfLocalizationFiniteSpan` if `P` holds for `R →+* S` whenever there exists a finite set `{ r }` that spans `R` such that `P` holds for `Rᵣ →+* Sᵣ`. Note that this is equivalent to `RingHom.OfLocalizationSpan` via `RingHom.ofLocalizationSpan_iff_finite`, but this is easier to prove. -/ def RingHom.OfLocalizationFiniteSpan := ∀ ⦃R S : Type u⦄ [CommRing R] [CommRing S] (f : R →+* S) (s : Finset R) (_ : Ideal.span (s : Set R) = ⊤) (_ : ∀ r : s, P (Localization.awayMap f r)), P f /-- A property `P` of ring homs satisfies `RingHom.OfLocalizationFiniteSpan` if `P` holds for `R →+* S` whenever there exists a set `{ r }` that spans `R` such that `P` holds for `Rᵣ →+* Sᵣ`. Note that this is equivalent to `RingHom.OfLocalizationFiniteSpan` via `RingHom.ofLocalizationSpan_iff_finite`, but this has less restrictions when applying. -/ def RingHom.OfLocalizationSpan := ∀ ⦃R S : Type u⦄ [CommRing R] [CommRing S] (f : R →+* S) (s : Set R) (_ : Ideal.span s = ⊤) (_ : ∀ r : s, P (Localization.awayMap f r)), P f /-- A property `P` of ring homs satisfies `RingHom.HoldsForLocalizationAway` if `P` holds for each localization map `R →+* Rᵣ`. -/ def RingHom.HoldsForLocalizationAway : Prop := ∀ ⦃R : Type u⦄ (S : Type u) [CommRing R] [CommRing S] [Algebra R S] (r : R) [IsLocalization.Away r S], P (algebraMap R S) /-- A property `P` of ring homs satisfies `RingHom.OfLocalizationFiniteSpanTarget` if `P` holds for `R →+* S` whenever there exists a finite set `{ r }` that spans `S` such that `P` holds for `R →+* Sᵣ`. Note that this is equivalent to `RingHom.OfLocalizationSpanTarget` via `RingHom.ofLocalizationSpanTarget_iff_finite`, but this is easier to prove. -/ def RingHom.OfLocalizationFiniteSpanTarget : Prop := ∀ ⦃R S : Type u⦄ [CommRing R] [CommRing S] (f : R →+* S) (s : Finset S) (_ : Ideal.span (s : Set S) = ⊤) (_ : ∀ r : s, P ((algebraMap S (Localization.Away (r : S))).comp f)), P f /-- A property `P` of ring homs satisfies `RingHom.OfLocalizationSpanTarget` if `P` holds for `R →+* S` whenever there exists a set `{ r }` that spans `S` such that `P` holds for `R →+* Sᵣ`. Note that this is equivalent to `RingHom.OfLocalizationFiniteSpanTarget` via `RingHom.ofLocalizationSpanTarget_iff_finite`, but this has less restrictions when applying. -/ def RingHom.OfLocalizationSpanTarget : Prop := ∀ ⦃R S : Type u⦄ [CommRing R] [CommRing S] (f : R →+* S) (s : Set S) (_ : Ideal.span s = ⊤) (_ : ∀ r : s, P ((algebraMap S (Localization.Away (r : S))).comp f)), P f /-- A property `P` of ring homs satisfies `RingHom.OfLocalizationPrime` if `P` holds for `R` whenever `P` holds for `Rₘ` for all prime ideals `p`. -/ def RingHom.OfLocalizationPrime : Prop := ∀ ⦃R S : Type u⦄ [CommRing R] [CommRing S] (f : R →+* S), (∀ (J : Ideal S) (_ : J.IsPrime), P (Localization.localRingHom _ J f rfl)) → P f /-- A property of ring homs is local if it is preserved by localizations and compositions, and for each `{ r }` that spans `S`, we have `P (R →+* S) ↔ ∀ r, P (R →+* Sᵣ)`. -/ structure RingHom.PropertyIsLocal : Prop where LocalizationPreserves : RingHom.LocalizationPreserves @P OfLocalizationSpanTarget : RingHom.OfLocalizationSpanTarget @P StableUnderComposition : RingHom.StableUnderComposition @P HoldsForLocalizationAway : RingHom.HoldsForLocalizationAway @P theorem RingHom.ofLocalizationSpan_iff_finite : RingHom.OfLocalizationSpan @P ↔ RingHom.OfLocalizationFiniteSpan @P := by delta RingHom.OfLocalizationSpan RingHom.OfLocalizationFiniteSpan apply forall₅_congr -- TODO: Using `refine` here breaks `resetI`. intros constructor · intro h s; exact h s · intro h s hs hs' obtain ⟨s', h₁, h₂⟩ := (Ideal.span_eq_top_iff_finite s).mp hs exact h s' h₂ fun x => hs' ⟨_, h₁ x.prop⟩ theorem RingHom.ofLocalizationSpanTarget_iff_finite : RingHom.OfLocalizationSpanTarget @P ↔ RingHom.OfLocalizationFiniteSpanTarget @P := by delta RingHom.OfLocalizationSpanTarget RingHom.OfLocalizationFiniteSpanTarget apply forall₅_congr -- TODO: Using `refine` here breaks `resetI`. intros constructor · intro h s; exact h s · intro h s hs hs' obtain ⟨s', h₁, h₂⟩ := (Ideal.span_eq_top_iff_finite s).mp hs exact h s' h₂ fun x => hs' ⟨_, h₁ x.prop⟩ theorem RingHom.HoldsForLocalizationAway.of_bijective (H : RingHom.HoldsForLocalizationAway P) (hf : Function.Bijective f) : P f := by letI := f.toAlgebra have := IsLocalization.at_units (.powers (1 : R)) (by simp) have := IsLocalization.isLocalization_of_algEquiv (.powers (1 : R)) (AlgEquiv.ofBijective (Algebra.ofId R S) hf) exact H _ 1 variable {P f R' S'} theorem RingHom.PropertyIsLocal.respectsIso (hP : RingHom.PropertyIsLocal @P) : RingHom.RespectsIso @P := by apply hP.StableUnderComposition.respectsIso introv letI := e.toRingHom.toAlgebra -- Porting note: was `apply_with hP.holds_for_localization_away { instances := ff }` have : IsLocalization.Away (1 : R) S := by apply IsLocalization.away_of_isUnit_of_bijective _ isUnit_one e.bijective exact RingHom.PropertyIsLocal.HoldsForLocalizationAway hP S (1 : R) -- Almost all arguments are implicit since this is not intended to use mid-proof. theorem RingHom.LocalizationPreserves.away (H : RingHom.LocalizationPreserves @P) (r : R) [IsLocalization.Away r R'] [IsLocalization.Away (f r) S'] (hf : P f) : P (IsLocalization.Away.map R' S' f r) := by have : IsLocalization ((Submonoid.powers r).map f) S' := by rw [Submonoid.map_powers]; assumption exact H f (Submonoid.powers r) R' S' hf theorem RingHom.PropertyIsLocal.ofLocalizationSpan (hP : RingHom.PropertyIsLocal @P) : RingHom.OfLocalizationSpan @P := by introv R hs hs' apply_fun Ideal.map f at hs rw [Ideal.map_span, Ideal.map_top] at hs apply hP.OfLocalizationSpanTarget _ _ hs rintro ⟨_, r, hr, rfl⟩ convert hP.StableUnderComposition _ _ (hP.HoldsForLocalizationAway (Localization.Away r) r) (hs' ⟨r, hr⟩) using 1 exact (IsLocalization.map_comp _).symm lemma RingHom.OfLocalizationSpanTarget.ofIsLocalization (hP : RingHom.OfLocalizationSpanTarget P) (hP' : RingHom.RespectsIso P) {R S : Type u} [CommRing R] [CommRing S] (f : R →+* S) (s : Set S) (hs : Ideal.span s = ⊤) (hT : ∀ r : s, ∃ (T : Type u) (_ : CommRing T) (_ : Algebra S T) (_ : IsLocalization.Away (r : S) T), P ((algebraMap S T).comp f)) : P f := by apply hP _ s hs intros r obtain ⟨T, _, _, _, hT⟩ := hT r convert hP'.1 _ (Localization.algEquiv (R := S) (Submonoid.powers (r : S)) T).symm.toRingEquiv hT rw [← RingHom.comp_assoc, RingEquiv.toRingHom_eq_coe, AlgEquiv.toRingEquiv_eq_coe, AlgEquiv.toRingEquiv_toRingHom, Localization.coe_algEquiv_symm, IsLocalization.map_comp, RingHom.comp_id] end RingHom end Properties section Ideal open scoped nonZeroDivisors /-- Let `I J : Ideal R`. If the localization of `I` at each maximal ideal `P` is included in the localization of `J` at `P`, then `I ≤ J`. -/ theorem Ideal.le_of_localization_maximal {I J : Ideal R} (h : ∀ (P : Ideal R) (hP : P.IsMaximal), Ideal.map (algebraMap R (Localization.AtPrime P)) I ≤ Ideal.map (algebraMap R (Localization.AtPrime P)) J) : I ≤ J := by intro x hx suffices J.colon (Ideal.span {x}) = ⊤ by simpa using Submodule.mem_colon.mp (show (1 : R) ∈ J.colon (Ideal.span {x}) from this.symm ▸ Submodule.mem_top) x (Ideal.mem_span_singleton_self x) refine Not.imp_symm (J.colon (Ideal.span {x})).exists_le_maximal ?_ push_neg intro P hP le obtain ⟨⟨⟨a, ha⟩, ⟨s, hs⟩⟩, eq⟩ := (IsLocalization.mem_map_algebraMap_iff P.primeCompl _).mp (h P hP (Ideal.mem_map_of_mem _ hx)) rw [← _root_.map_mul, ← sub_eq_zero, ← map_sub] at eq obtain ⟨⟨m, hm⟩, eq⟩ := (IsLocalization.map_eq_zero_iff P.primeCompl _ _).mp eq refine hs ((hP.isPrime.mem_or_mem (le (Ideal.mem_colon_singleton.mpr ?_))).resolve_right hm) simp only [Subtype.coe_mk, mul_sub, sub_eq_zero, mul_comm x s, mul_left_comm] at eq simpa only [mul_assoc, eq] using J.mul_mem_left m ha /-- Let `I J : Ideal R`. If the localization of `I` at each maximal ideal `P` is equal to the localization of `J` at `P`, then `I = J`. -/ theorem Ideal.eq_of_localization_maximal {I J : Ideal R} (h : ∀ (P : Ideal R) (_ : P.IsMaximal), Ideal.map (algebraMap R (Localization.AtPrime P)) I = Ideal.map (algebraMap R (Localization.AtPrime P)) J) : I = J := le_antisymm (Ideal.le_of_localization_maximal fun P hP => (h P hP).le) (Ideal.le_of_localization_maximal fun P hP => (h P hP).ge) /-- An ideal is trivial if its localization at every maximal ideal is trivial. -/ theorem ideal_eq_bot_of_localization' (I : Ideal R) (h : ∀ (J : Ideal R) (hJ : J.IsMaximal), Ideal.map (algebraMap R (Localization.AtPrime J)) I = ⊥) : I = ⊥ := Ideal.eq_of_localization_maximal fun P hP => by simpa using h P hP -- TODO: This proof should work for all modules, once we have enough material on submodules of -- localized modules. /-- An ideal is trivial if its localization at every maximal ideal is trivial. -/ theorem ideal_eq_bot_of_localization (I : Ideal R) (h : ∀ (J : Ideal R) (hJ : J.IsMaximal), IsLocalization.coeSubmodule (Localization.AtPrime J) I = ⊥) : I = ⊥ := ideal_eq_bot_of_localization' _ fun P hP => (Ideal.map_eq_bot_iff_le_ker _).mpr fun x hx => by rw [RingHom.mem_ker, ← Submodule.mem_bot R, ← h P hP, IsLocalization.mem_coeSubmodule] exact ⟨x, hx, rfl⟩ theorem eq_zero_of_localization (r : R) (h : ∀ (J : Ideal R) (hJ : J.IsMaximal), algebraMap R (Localization.AtPrime J) r = 0) : r = 0 := by rw [← Ideal.span_singleton_eq_bot] apply ideal_eq_bot_of_localization intro J hJ delta IsLocalization.coeSubmodule erw [Submodule.map_span, Submodule.span_eq_bot] rintro _ ⟨_, h', rfl⟩ cases Set.mem_singleton_iff.mpr h' exact h J hJ end Ideal section Reduced theorem localization_isReduced : LocalizationPreserves fun R hR => IsReduced R := by introv R _ _ constructor rintro x ⟨_ | n, e⟩ · simpa using congr_arg (· * x) e obtain ⟨⟨y, m⟩, hx⟩ := IsLocalization.surj M x dsimp only at hx let hx' := congr_arg (· ^ n.succ) hx simp only [mul_pow, e, zero_mul, ← RingHom.map_pow] at hx' rw [← (algebraMap R S).map_zero] at hx' obtain ⟨m', hm'⟩ := (IsLocalization.eq_iff_exists M S).mp hx' apply_fun (· * (m' : R) ^ n) at hm' simp only [mul_assoc, zero_mul, mul_zero] at hm' rw [← mul_left_comm, ← pow_succ', ← mul_pow] at hm' replace hm' := IsNilpotent.eq_zero ⟨_, hm'.symm⟩ rw [← (IsLocalization.map_units S m).mul_left_inj, hx, zero_mul, IsLocalization.map_eq_zero_iff M] exact ⟨m', by rw [← hm', mul_comm]⟩ instance [IsReduced R] : IsReduced (Localization M) := localization_isReduced M _ inferInstance theorem isReduced_ofLocalizationMaximal : OfLocalizationMaximal fun R hR => IsReduced R := by introv R h constructor intro x hx apply eq_zero_of_localization intro J hJ specialize h J hJ exact (hx.map <| algebraMap R <| Localization.AtPrime J).eq_zero end Reduced section Surjective theorem localizationPreserves_surjective : RingHom.LocalizationPreserves fun {R S} _ _ f => Function.Surjective f := by introv R H x obtain ⟨x, ⟨_, s, hs, rfl⟩, rfl⟩ := IsLocalization.mk'_surjective (M.map f) x obtain ⟨y, rfl⟩ := H x use IsLocalization.mk' R' y ⟨s, hs⟩ rw [IsLocalization.map_mk'] theorem surjective_ofLocalizationSpan : RingHom.OfLocalizationSpan fun {R S} _ _ f => Function.Surjective f := by introv R e H rw [← Set.range_iff_surjective, Set.eq_univ_iff_forall] letI := f.toAlgebra intro x apply Submodule.mem_of_span_eq_top_of_smul_pow_mem (LinearMap.range (Algebra.linearMap R S)) s e intro r obtain ⟨a, e'⟩ := H r (algebraMap _ _ x) obtain ⟨b, ⟨_, n, rfl⟩, rfl⟩ := IsLocalization.mk'_surjective (Submonoid.powers (r : R)) a erw [IsLocalization.map_mk'] at e' rw [eq_comm, IsLocalization.eq_mk'_iff_mul_eq, Subtype.coe_mk, Subtype.coe_mk, ← map_mul] at e' obtain ⟨⟨_, n', rfl⟩, e''⟩ := (IsLocalization.eq_iff_exists (Submonoid.powers (f r)) _).mp e' dsimp only at e'' rw [mul_comm x, ← mul_assoc, ← map_pow, ← map_mul, ← map_mul, ← pow_add] at e'' exact ⟨n' + n, _, e''.symm⟩ /-- A surjective ring homomorphism `R →+* S` induces a surjective homomorphism `R_{f⁻¹(P)} →+* S_P` for every prime ideal `P` of `S`. -/ theorem surjective_localRingHom_of_surjective (h : Function.Surjective f) (P : Ideal S) [P.IsPrime] : Function.Surjective (Localization.localRingHom (P.comap f) P f rfl) := have : IsLocalization (Submonoid.map f (Ideal.comap f P).primeCompl) (Localization.AtPrime P) := (Submonoid.map_comap_eq_of_surjective h P.primeCompl).symm ▸ Localization.isLocalization localizationPreserves_surjective _ _ _ _ h lemma surjective_respectsIso : RingHom.RespectsIso (fun f ↦ Function.Surjective f) := by apply RingHom.StableUnderComposition.respectsIso · intro R S T _ _ _ f g hf hg simp only [RingHom.coe_comp] exact Function.Surjective.comp hg hf · intro R S _ _ e exact EquivLike.surjective e end Surjective section Finite lemma Module.Finite_of_isLocalization (R S Rₚ Sₚ) [CommSemiring R] [CommRing S] [CommRing Rₚ] [CommRing Sₚ] [Algebra R S] [Algebra R Rₚ] [Algebra R Sₚ] [Algebra S Sₚ] [Algebra Rₚ Sₚ] [IsScalarTower R S Sₚ] [IsScalarTower R Rₚ Sₚ] (M : Submonoid R) [IsLocalization M Rₚ] [IsLocalization (Algebra.algebraMapSubmonoid S M) Sₚ] [hRS : Module.Finite R S] : Module.Finite Rₚ Sₚ := by classical have : algebraMap Rₚ Sₚ = IsLocalization.map (T := Algebra.algebraMapSubmonoid S M) Sₚ (algebraMap R S) (Submonoid.le_comap_map M) := by apply IsLocalization.ringHom_ext M simp only [IsLocalization.map_comp, ← IsScalarTower.algebraMap_eq] -- We claim that if `S` is generated by `T` as an `R`-module, -- then `S'` is generated by `T` as an `R'`-module. obtain ⟨T, hT⟩ := hRS use T.image (algebraMap S Sₚ) rw [eq_top_iff] rintro x - -- By the hypotheses, for each `x : S'`, we have `x = y / (f r)` for some `y : S` and `r : M`. -- Since `S` is generated by `T`, the image of `y` should fall in the span of the image of `T`. obtain ⟨y, ⟨_, ⟨r, hr, rfl⟩⟩, rfl⟩ := IsLocalization.mk'_surjective (Algebra.algebraMapSubmonoid S M) x rw [IsLocalization.mk'_eq_mul_mk'_one, mul_comm, Finset.coe_image] have hy : y ∈ Submodule.span R ↑T := by rw [hT]; trivial replace hy : algebraMap S Sₚ y ∈ Submodule.map (IsScalarTower.toAlgHom R S Sₚ).toLinearMap (Submodule.span R (T : Set S)) := Submodule.mem_map_of_mem -- -- Note: #8386 had to specify the value of `f` below (f := (IsScalarTower.toAlgHom R S Sₚ).toLinearMap) hy rw [Submodule.map_span (IsScalarTower.toAlgHom R S Sₚ).toLinearMap T] at hy have H : Submodule.span R (algebraMap S Sₚ '' T) ≤ (Submodule.span Rₚ (algebraMap S Sₚ '' T)).restrictScalars R := by rw [Submodule.span_le]; exact Submodule.subset_span -- Now, since `y ∈ span T`, and `(f r)⁻¹ ∈ R'`, `x / (f r)` is in `span T` as well. convert (Submodule.span Rₚ (algebraMap S Sₚ '' T)).smul_mem (IsLocalization.mk' Rₚ (1 : R) ⟨r, hr⟩) (H hy) using 1 rw [Algebra.smul_def, this, IsLocalization.map_mk', map_one] /-- If `S` is a finite `R`-algebra, then `S' = M⁻¹S` is a finite `R' = M⁻¹R`-algebra. -/ theorem localization_finite : RingHom.LocalizationPreserves @RingHom.Finite := by introv R hf letI := f.toAlgebra letI := ((algebraMap S S').comp f).toAlgebra let f' : R' →+* S' := IsLocalization.map S' f (Submonoid.le_comap_map M) letI := f'.toAlgebra have : IsScalarTower R R' S' := IsScalarTower.of_algebraMap_eq' (IsLocalization.map_comp M.le_comap_map).symm have : IsScalarTower R S S' := IsScalarTower.of_algebraMap_eq' rfl have : IsLocalization (Algebra.algebraMapSubmonoid S M) S' := by rwa [Algebra.algebraMapSubmonoid, RingHom.algebraMap_toAlgebra] have : Module.Finite R S := hf apply Module.Finite_of_isLocalization R S R' S' M theorem localization_away_map_finite (r : R) [IsLocalization.Away r R'] [IsLocalization.Away (f r) S'] (hf : f.Finite) : (IsLocalization.Away.map R' S' f r).Finite := localization_finite.away r hf /-- Let `S` be an `R`-algebra, `M` a submonoid of `R`, and `S' = M⁻¹S`. If the image of some `x : S` falls in the span of some finite `s ⊆ S'` over `R`, then there exists some `m : M` such that `m • x` falls in the span of `IsLocalization.finsetIntegerMultiple _ s` over `R`. -/ theorem IsLocalization.smul_mem_finsetIntegerMultiple_span [Algebra R S] [Algebra R S'] [IsScalarTower R S S'] [IsLocalization (M.map (algebraMap R S)) S'] (x : S) (s : Finset S') (hx : algebraMap S S' x ∈ Submodule.span R (s : Set S')) : ∃ m : M, m • x ∈ Submodule.span R (IsLocalization.finsetIntegerMultiple (M.map (algebraMap R S)) s : Set S) := by let g : S →ₐ[R] S' := AlgHom.mk' (algebraMap S S') fun c x => by simp [Algebra.algebraMap_eq_smul_one] -- We first obtain the `y' ∈ M` such that `s' = y' • s` is falls in the image of `S` in `S'`. let y := IsLocalization.commonDenomOfFinset (M.map (algebraMap R S)) s have hx₁ : (y : S) • (s : Set S') = g '' _ := (IsLocalization.finsetIntegerMultiple_image _ s).symm obtain ⟨y', hy', e : algebraMap R S y' = y⟩ := y.prop have : algebraMap R S y' • (s : Set S') = y' • (s : Set S') := by simp_rw [Algebra.algebraMap_eq_smul_one, smul_assoc, one_smul] rw [← e, this] at hx₁ replace hx₁ := congr_arg (Submodule.span R) hx₁ rw [Submodule.span_smul] at hx₁ replace hx : _ ∈ y' • Submodule.span R (s : Set S') := Set.smul_mem_smul_set hx rw [hx₁] at hx erw [← _root_.map_smul g, ← Submodule.map_span (g : S →ₗ[R] S')] at hx -- Since `x` falls in the span of `s` in `S'`, `y' • x : S` falls in the span of `s'` in `S'`. -- That is, there exists some `x' : S` in the span of `s'` in `S` and `x' = y' • x` in `S'`. -- Thus `a • (y' • x) = a • x' ∈ span s'` in `S` for some `a ∈ M`. obtain ⟨x', hx', hx'' : algebraMap _ _ _ = _⟩ := hx obtain ⟨⟨_, a, ha₁, rfl⟩, ha₂⟩ := (IsLocalization.eq_iff_exists (M.map (algebraMap R S)) S').mp hx'' use (⟨a, ha₁⟩ : M) * (⟨y', hy'⟩ : M) convert (Submodule.span R (IsLocalization.finsetIntegerMultiple (Submonoid.map (algebraMap R S) M) s : Set S)).smul_mem a hx' using 1 convert ha₂.symm using 1 · rw [Subtype.coe_mk, Submonoid.smul_def, Submonoid.coe_mul, ← smul_smul] exact Algebra.smul_def _ _ · exact Algebra.smul_def _ _ /-- If `M` is an `R' = S⁻¹R` module, and `x ∈ span R' s`, then `t • x ∈ span R s` for some `t : S`. -/ theorem multiple_mem_span_of_mem_localization_span {N : Type*} [AddCommMonoid N] [Module R N] [Module R' N] [IsScalarTower R R' N] [IsLocalization M R'] (s : Set N) (x : N) (hx : x ∈ Submodule.span R' s) : ∃ (t : M), t • x ∈ Submodule.span R s := by classical obtain ⟨s', hss', hs'⟩ := Submodule.mem_span_finite_of_mem_span hx rsuffices ⟨t, ht⟩ : ∃ t : M, t • x ∈ Submodule.span R (s' : Set N) · exact ⟨t, Submodule.span_mono hss' ht⟩ clear hx hss' s induction s' using Finset.induction_on generalizing x · use 1; simpa using hs' rename_i a s _ hs simp only [Finset.coe_insert, Finset.image_insert, Finset.coe_image, Subtype.coe_mk, Submodule.mem_span_insert] at hs' ⊢ rcases hs' with ⟨y, z, hz, rfl⟩ rcases IsLocalization.surj M y with ⟨⟨y', s'⟩, e⟩ apply congrArg (fun x ↦ x • a) at e simp only [algebraMap_smul] at e rcases hs _ hz with ⟨t, ht⟩ refine ⟨t * s', t * y', _, (Submodule.span R (s : Set N)).smul_mem s' ht, ?_⟩ rw [smul_add, ← smul_smul, mul_comm, ← smul_smul, ← smul_smul, ← e, mul_comm, ← Algebra.smul_def] simp rfl /-- If `S` is an `R' = M⁻¹R` algebra, and `x ∈ adjoin R' s`, then `t • x ∈ adjoin R s` for some `t : M`. -/ theorem multiple_mem_adjoin_of_mem_localization_adjoin [Algebra R' S] [Algebra R S] [IsScalarTower R R' S] [IsLocalization M R'] (s : Set S) (x : S) (hx : x ∈ Algebra.adjoin R' s) : ∃ t : M, t • x ∈ Algebra.adjoin R s := by change ∃ t : M, t • x ∈ Subalgebra.toSubmodule (Algebra.adjoin R s) change x ∈ Subalgebra.toSubmodule (Algebra.adjoin R' s) at hx simp_rw [Algebra.adjoin_eq_span] at hx ⊢ exact multiple_mem_span_of_mem_localization_span M R' _ _ hx theorem finite_ofLocalizationSpan : RingHom.OfLocalizationSpan @RingHom.Finite := by rw [RingHom.ofLocalizationSpan_iff_finite] introv R hs H -- We first setup the instances letI := f.toAlgebra letI := fun r : s => (Localization.awayMap f r).toAlgebra have : ∀ r : s, IsLocalization ((Submonoid.powers (r : R)).map (algebraMap R S)) (Localization.Away (f r)) := by intro r; rw [Submonoid.map_powers]; exact Localization.isLocalization haveI : ∀ r : s, IsScalarTower R (Localization.Away (r : R)) (Localization.Away (f r)) := fun r => IsScalarTower.of_algebraMap_eq' (IsLocalization.map_comp (Submonoid.powers (r : R)).le_comap_map).symm -- By the hypothesis, we may find a finite generating set for each `Sᵣ`. This set can then be -- lifted into `R` by multiplying a sufficiently large power of `r`. I claim that the union of -- these generates `S`. constructor replace H := fun r => (H r).1 choose s₁ s₂ using H let sf := fun x : s => IsLocalization.finsetIntegerMultiple (Submonoid.powers (f x)) (s₁ x) use s.attach.biUnion sf rw [Submodule.span_attach_biUnion, eq_top_iff] -- It suffices to show that `r ^ n • x ∈ span T` for each `r : s`, since `{ r ^ n }` spans `R`. -- This then follows from the fact that each `x : R` is a linear combination of the generating set -- of `Sᵣ`. By multiplying a sufficiently large power of `r`, we can cancel out the `r`s in the -- denominators of both the generating set and the coefficients. rintro x - apply Submodule.mem_of_span_eq_top_of_smul_pow_mem _ (s : Set R) hs _ _ intro r obtain ⟨⟨_, n₁, rfl⟩, hn₁⟩ := multiple_mem_span_of_mem_localization_span (Submonoid.powers (r : R)) (Localization.Away (r : R)) (s₁ r : Set (Localization.Away (f r))) (algebraMap S _ x) (by rw [s₂ r]; trivial) dsimp only at hn₁ rw [Submonoid.smul_def, Algebra.smul_def, IsScalarTower.algebraMap_apply R S, ← map_mul] at hn₁ obtain ⟨⟨_, n₂, rfl⟩, hn₂⟩ := IsLocalization.smul_mem_finsetIntegerMultiple_span (Submonoid.powers (r : R)) (Localization.Away (f r)) _ (s₁ r) hn₁ rw [Submonoid.smul_def, ← Algebra.smul_def, smul_smul, Subtype.coe_mk, ← pow_add] at hn₂ simp_rw [Submonoid.map_powers] at hn₂ use n₂ + n₁ exact le_iSup (fun x : s => Submodule.span R (sf x : Set S)) r hn₂ end Finite section FiniteType theorem localization_finiteType : RingHom.LocalizationPreserves @RingHom.FiniteType := by introv R hf -- mirrors the proof of `localization_map_finite` letI := f.toAlgebra letI := ((algebraMap S S').comp f).toAlgebra let f' : R' →+* S' := IsLocalization.map S' f (Submonoid.le_comap_map M) letI := f'.toAlgebra haveI : IsScalarTower R R' S' := IsScalarTower.of_algebraMap_eq' (IsLocalization.map_comp M.le_comap_map).symm let fₐ : S →ₐ[R] S' := AlgHom.mk' (algebraMap S S') fun c x => RingHom.map_mul _ _ _ obtain ⟨T, hT⟩ := id hf use T.image (algebraMap S S') rw [eq_top_iff] rintro x - obtain ⟨y, ⟨_, ⟨r, hr, rfl⟩⟩, rfl⟩ := IsLocalization.mk'_surjective (M.map f) x rw [IsLocalization.mk'_eq_mul_mk'_one, mul_comm, Finset.coe_image] have hy : y ∈ Algebra.adjoin R (T : Set S) := by rw [hT]; trivial replace hy : algebraMap S S' y ∈ (Algebra.adjoin R (T : Set S)).map fₐ := Subalgebra.mem_map.mpr ⟨_, hy, rfl⟩ rw [fₐ.map_adjoin T] at hy have H : Algebra.adjoin R (algebraMap S S' '' T) ≤ (Algebra.adjoin R' (algebraMap S S' '' T)).restrictScalars R := by rw [Algebra.adjoin_le_iff]; exact Algebra.subset_adjoin convert (Algebra.adjoin R' (algebraMap S S' '' T)).smul_mem (H hy) (IsLocalization.mk' R' (1 : R) ⟨r, hr⟩) using 1 rw [Algebra.smul_def] erw [IsLocalization.map_mk' M.le_comap_map] rw [map_one] theorem localization_away_map_finiteType (r : R) [IsLocalization.Away r R'] [IsLocalization.Away (f r) S'] (hf : f.FiniteType) : (IsLocalization.Away.map R' S' f r).FiniteType := localization_finiteType.away r hf variable {S'} /-- Let `S` be an `R`-algebra, `M` a submonoid of `S`, `S' = M⁻¹S`. Suppose the image of some `x : S` falls in the adjoin of some finite `s ⊆ S'` over `R`, and `A` is an `R`-subalgebra of `S` containing both `M` and the numerators of `s`. Then, there exists some `m : M` such that `m • x` falls in `A`. -/ theorem IsLocalization.exists_smul_mem_of_mem_adjoin [Algebra R S] [Algebra R S'] [IsScalarTower R S S'] (M : Submonoid S) [IsLocalization M S'] (x : S) (s : Finset S') (A : Subalgebra R S) (hA₁ : (IsLocalization.finsetIntegerMultiple M s : Set S) ⊆ A) (hA₂ : M ≤ A.toSubmonoid) (hx : algebraMap S S' x ∈ Algebra.adjoin R (s : Set S')) : ∃ m : M, m • x ∈ A := by let g : S →ₐ[R] S' := IsScalarTower.toAlgHom R S S' let y := IsLocalization.commonDenomOfFinset M s have hx₁ : (y : S) • (s : Set S') = g '' _ := (IsLocalization.finsetIntegerMultiple_image _ s).symm obtain ⟨n, hn⟩ := Algebra.pow_smul_mem_of_smul_subset_of_mem_adjoin (y : S) (s : Set S') (A.map g) (by rw [hx₁]; exact Set.image_subset _ hA₁) hx (Set.mem_image_of_mem _ (hA₂ y.2)) obtain ⟨x', hx', hx''⟩ := hn n (le_of_eq rfl) rw [Algebra.smul_def, ← _root_.map_mul] at hx'' obtain ⟨a, ha₂⟩ := (IsLocalization.eq_iff_exists M S').mp hx'' use a * y ^ n convert A.mul_mem hx' (hA₂ a.prop) using 1 rw [Submonoid.smul_def, smul_eq_mul, Submonoid.coe_mul, SubmonoidClass.coe_pow, mul_assoc, ← ha₂, mul_comm] /-- Let `S` be an `R`-algebra, `M` a submonoid of `R`, and `S' = M⁻¹S`. If the image of some `x : S` falls in the adjoin of some finite `s ⊆ S'` over `R`, then there exists some `m : M` such that `m • x` falls in the adjoin of `IsLocalization.finsetIntegerMultiple _ s` over `R`. -/ theorem IsLocalization.lift_mem_adjoin_finsetIntegerMultiple [Algebra R S] [Algebra R S'] [IsScalarTower R S S'] [IsLocalization (M.map (algebraMap R S)) S'] (x : S) (s : Finset S') (hx : algebraMap S S' x ∈ Algebra.adjoin R (s : Set S')) : ∃ m : M, m • x ∈ Algebra.adjoin R (IsLocalization.finsetIntegerMultiple (M.map (algebraMap R S)) s : Set S) := by obtain ⟨⟨_, a, ha, rfl⟩, e⟩ := IsLocalization.exists_smul_mem_of_mem_adjoin (M.map (algebraMap R S)) x s (Algebra.adjoin R _) Algebra.subset_adjoin (by rintro _ ⟨a, _, rfl⟩; exact Subalgebra.algebraMap_mem _ a) hx refine ⟨⟨a, ha⟩, ?_⟩ simpa only [Submonoid.smul_def, algebraMap_smul] using e theorem finiteType_ofLocalizationSpan : RingHom.OfLocalizationSpan @RingHom.FiniteType := by rw [RingHom.ofLocalizationSpan_iff_finite] introv R hs H -- mirrors the proof of `finite_ofLocalizationSpan` letI := f.toAlgebra letI := fun r : s => (Localization.awayMap f r).toAlgebra have : ∀ r : s, IsLocalization ((Submonoid.powers (r : R)).map (algebraMap R S)) (Localization.Away (f r)) := by intro r; rw [Submonoid.map_powers]; exact Localization.isLocalization haveI : ∀ r : s, IsScalarTower R (Localization.Away (r : R)) (Localization.Away (f r)) := fun r => IsScalarTower.of_algebraMap_eq' (IsLocalization.map_comp (Submonoid.powers (r : R)).le_comap_map).symm constructor replace H := fun r => (H r).1 choose s₁ s₂ using H let sf := fun x : s => IsLocalization.finsetIntegerMultiple (Submonoid.powers (f x)) (s₁ x) use s.attach.biUnion sf convert (Algebra.adjoin_attach_biUnion (R := R) sf).trans _ rw [eq_top_iff] rintro x - apply (⨆ x : s, Algebra.adjoin R (sf x : Set S)).toSubmodule.mem_of_span_eq_top_of_smul_pow_mem _ hs _ _ intro r obtain ⟨⟨_, n₁, rfl⟩, hn₁⟩ := multiple_mem_adjoin_of_mem_localization_adjoin (Submonoid.powers (r : R)) (Localization.Away (r : R)) (s₁ r : Set (Localization.Away (f r))) (algebraMap S (Localization.Away (f r)) x) (by rw [s₂ r]; trivial) rw [Submonoid.smul_def, Algebra.smul_def, IsScalarTower.algebraMap_apply R S, ← map_mul] at hn₁ obtain ⟨⟨_, n₂, rfl⟩, hn₂⟩ := IsLocalization.lift_mem_adjoin_finsetIntegerMultiple (Submonoid.powers (r : R)) _ (s₁ r) hn₁ rw [Submonoid.smul_def, ← Algebra.smul_def, smul_smul, Subtype.coe_mk, ← pow_add] at hn₂ simp_rw [Submonoid.map_powers] at hn₂ use n₂ + n₁ exact le_iSup (fun x : s => Algebra.adjoin R (sf x : Set S)) r hn₂ end FiniteType
RingTheory\MatrixAlgebra.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Eric Wieser -/ import Mathlib.Data.Matrix.Basis import Mathlib.RingTheory.TensorProduct.Basic /-! We show `Matrix n n A ≃ₐ[R] (A ⊗[R] Matrix n n R)`. -/ suppress_compilation universe u v w open TensorProduct open TensorProduct open Algebra.TensorProduct open Matrix variable {R : Type u} [CommSemiring R] variable {A : Type v} [Semiring A] [Algebra R A] variable {n : Type w} variable (R A n) namespace MatrixEquivTensor /-- (Implementation detail). The function underlying `(A ⊗[R] Matrix n n R) →ₐ[R] Matrix n n A`, as an `R`-bilinear map. -/ def toFunBilinear : A →ₗ[R] Matrix n n R →ₗ[R] Matrix n n A := (Algebra.lsmul R R (Matrix n n A)).toLinearMap.compl₂ (Algebra.linearMap R A).mapMatrix @[simp] theorem toFunBilinear_apply (a : A) (m : Matrix n n R) : toFunBilinear R A n a m = a • m.map (algebraMap R A) := rfl /-- (Implementation detail). The function underlying `(A ⊗[R] Matrix n n R) →ₐ[R] Matrix n n A`, as an `R`-linear map. -/ def toFunLinear : A ⊗[R] Matrix n n R →ₗ[R] Matrix n n A := TensorProduct.lift (toFunBilinear R A n) variable [DecidableEq n] [Fintype n] /-- The function `(A ⊗[R] Matrix n n R) →ₐ[R] Matrix n n A`, as an algebra homomorphism. -/ def toFunAlgHom : A ⊗[R] Matrix n n R →ₐ[R] Matrix n n A := algHomOfLinearMapTensorProduct (toFunLinear R A n) (by intros simp_rw [toFunLinear, lift.tmul, toFunBilinear_apply, Matrix.map_mul] ext dsimp simp_rw [Matrix.mul_apply, Matrix.smul_apply, Matrix.map_apply, smul_eq_mul, Finset.mul_sum, _root_.mul_assoc, Algebra.left_comm]) (by simp_rw [toFunLinear, lift.tmul, toFunBilinear_apply, Matrix.map_one (algebraMap R A) (map_zero _) (map_one _), one_smul]) @[simp] theorem toFunAlgHom_apply (a : A) (m : Matrix n n R) : toFunAlgHom R A n (a ⊗ₜ m) = a • m.map (algebraMap R A) := rfl /-- (Implementation detail.) The bare function `Matrix n n A → A ⊗[R] Matrix n n R`. (We don't need to show that it's an algebra map, thankfully --- just that it's an inverse.) -/ def invFun (M : Matrix n n A) : A ⊗[R] Matrix n n R := ∑ p : n × n, M p.1 p.2 ⊗ₜ stdBasisMatrix p.1 p.2 1 @[simp] theorem invFun_zero : invFun R A n 0 = 0 := by simp [invFun] @[simp] theorem invFun_add (M N : Matrix n n A) : invFun R A n (M + N) = invFun R A n M + invFun R A n N := by simp [invFun, add_tmul, Finset.sum_add_distrib] @[simp] theorem invFun_smul (a : A) (M : Matrix n n A) : invFun R A n (a • M) = a ⊗ₜ 1 * invFun R A n M := by simp [invFun, Finset.mul_sum] @[simp] theorem invFun_algebraMap (M : Matrix n n R) : invFun R A n (M.map (algebraMap R A)) = 1 ⊗ₜ M := by dsimp [invFun] simp only [Algebra.algebraMap_eq_smul_one, smul_tmul, ← tmul_sum, mul_boole] congr conv_rhs => rw [matrix_eq_sum_std_basis M] convert Finset.sum_product (β := Matrix n n R); simp theorem right_inv (M : Matrix n n A) : (toFunAlgHom R A n) (invFun R A n M) = M := by simp only [invFun, map_sum, stdBasisMatrix, apply_ite ↑(algebraMap R A), smul_eq_mul, mul_boole, toFunAlgHom_apply, RingHom.map_zero, RingHom.map_one, Matrix.map_apply, Pi.smul_def] convert Finset.sum_product (β := Matrix n n A) conv_lhs => rw [matrix_eq_sum_std_basis M] refine Finset.sum_congr rfl fun i _ => Finset.sum_congr rfl fun j _ => Matrix.ext fun a b => ?_ simp only [stdBasisMatrix, smul_apply, Matrix.map_apply] split_ifs <;> aesop theorem left_inv (M : A ⊗[R] Matrix n n R) : invFun R A n (toFunAlgHom R A n M) = M := by induction M with | zero => simp | tmul a m => simp | add x y hx hy => rw [map_add] conv_rhs => rw [← hx, ← hy, ← invFun_add] /-- (Implementation detail) The equivalence, ignoring the algebra structure, `(A ⊗[R] Matrix n n R) ≃ Matrix n n A`. -/ def equiv : A ⊗[R] Matrix n n R ≃ Matrix n n A where toFun := toFunAlgHom R A n invFun := invFun R A n left_inv := left_inv R A n right_inv := right_inv R A n end MatrixEquivTensor variable [Fintype n] [DecidableEq n] /-- The `R`-algebra isomorphism `Matrix n n A ≃ₐ[R] (A ⊗[R] Matrix n n R)`. -/ def matrixEquivTensor : Matrix n n A ≃ₐ[R] A ⊗[R] Matrix n n R := AlgEquiv.symm { MatrixEquivTensor.toFunAlgHom R A n, MatrixEquivTensor.equiv R A n with } open MatrixEquivTensor @[simp] theorem matrixEquivTensor_apply (M : Matrix n n A) : matrixEquivTensor R A n M = ∑ p : n × n, M p.1 p.2 ⊗ₜ stdBasisMatrix p.1 p.2 1 := rfl -- Porting note: short circuiting simplifier from simplifying left hand side @[simp (high)] theorem matrixEquivTensor_apply_std_basis (i j : n) (x : A) : matrixEquivTensor R A n (stdBasisMatrix i j x) = x ⊗ₜ stdBasisMatrix i j 1 := by have t : ∀ p : n × n, i = p.1 ∧ j = p.2 ↔ p = (i, j) := by aesop simp [ite_tmul, t, stdBasisMatrix] @[simp] theorem matrixEquivTensor_apply_symm (a : A) (M : Matrix n n R) : (matrixEquivTensor R A n).symm (a ⊗ₜ M) = M.map fun x => a * algebraMap R A x := rfl
RingTheory\MaximalSpectrum.lean
/- Copyright (c) 2022 David Kurniadi Angdinata. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Kurniadi Angdinata -/ import Mathlib.RingTheory.PrimeSpectrum import Mathlib.RingTheory.Localization.AsSubring /-! # Maximal spectrum of a commutative ring The maximal spectrum of a commutative ring is the type of all maximal ideals. It is naturally a subset of the prime spectrum endowed with the subspace topology. ## Main definitions * `MaximalSpectrum R`: The maximal spectrum of a commutative ring `R`, i.e., the set of all maximal ideals of `R`. ## Implementation notes The Zariski topology on the maximal spectrum is defined as the subspace topology induced by the natural inclusion into the prime spectrum to avoid API duplication for zero loci. -/ noncomputable section open scoped Classical universe u v variable (R : Type u) [CommRing R] /-- The maximal spectrum of a commutative ring `R` is the type of all maximal ideals of `R`. -/ @[ext] structure MaximalSpectrum where asIdeal : Ideal R IsMaximal : asIdeal.IsMaximal attribute [instance] MaximalSpectrum.IsMaximal variable {R} namespace MaximalSpectrum instance [Nontrivial R] : Nonempty <| MaximalSpectrum R := let ⟨I, hI⟩ := Ideal.exists_maximal R ⟨⟨I, hI⟩⟩ /-- The natural inclusion from the maximal spectrum to the prime spectrum. -/ def toPrimeSpectrum (x : MaximalSpectrum R) : PrimeSpectrum R := ⟨x.asIdeal, x.IsMaximal.isPrime⟩ theorem toPrimeSpectrum_injective : (@toPrimeSpectrum R _).Injective := fun ⟨_, _⟩ ⟨_, _⟩ h => by simpa only [MaximalSpectrum.mk.injEq] using PrimeSpectrum.ext_iff.mp h open PrimeSpectrum Set variable (R) variable [IsDomain R] (K : Type v) [Field K] [Algebra R K] [IsFractionRing R K] /-- An integral domain is equal to the intersection of its localizations at all its maximal ideals viewed as subalgebras of its field of fractions. -/ theorem iInf_localization_eq_bot : (⨅ v : MaximalSpectrum R, Localization.subalgebra.ofField K _ v.asIdeal.primeCompl_le_nonZeroDivisors) = ⊥ := by ext x rw [Algebra.mem_bot, Algebra.mem_iInf] constructor · contrapose intro hrange hlocal let denom : Ideal R := (Submodule.span R {1} : Submodule R K).colon (Submodule.span R {x}) have hdenom : (1 : R) ∉ denom := by intro hdenom rcases Submodule.mem_span_singleton.mp (Submodule.mem_colon.mp hdenom x <| Submodule.mem_span_singleton_self x) with ⟨y, hy⟩ exact hrange ⟨y, by rw [← mul_one <| algebraMap R K y, ← Algebra.smul_def, hy, one_smul]⟩ rcases denom.exists_le_maximal fun h => (h ▸ hdenom) Submodule.mem_top with ⟨max, hmax, hle⟩ rcases hlocal ⟨max, hmax⟩ with ⟨n, d, hd, rfl⟩ apply hd (hle <| Submodule.mem_colon.mpr fun _ hy => _) intro _ hy rcases Submodule.mem_span_singleton.mp hy with ⟨y, rfl⟩ exact Submodule.mem_span_singleton.mpr ⟨y * n, by rw [Algebra.smul_def, mul_one, map_mul, smul_comm, Algebra.smul_def, Algebra.smul_def, mul_comm <| algebraMap R K d, inv_mul_cancel_right₀ <| (map_ne_zero_iff _ <| NoZeroSMulDivisors.algebraMap_injective R K).mpr fun h => (h ▸ hd) max.zero_mem]⟩ · rintro ⟨y, rfl⟩ ⟨v, hv⟩ exact ⟨y, 1, v.ne_top_iff_one.mp hv.ne_top, by rw [map_one, inv_one, mul_one]⟩ end MaximalSpectrum namespace PrimeSpectrum variable (R) variable [IsDomain R] (K : Type v) [Field K] [Algebra R K] [IsFractionRing R K] /-- An integral domain is equal to the intersection of its localizations at all its prime ideals viewed as subalgebras of its field of fractions. -/ theorem iInf_localization_eq_bot : ⨅ v : PrimeSpectrum R, Localization.subalgebra.ofField K _ (v.asIdeal.primeCompl_le_nonZeroDivisors) = ⊥ := by ext x rw [Algebra.mem_iInf] constructor · rw [← MaximalSpectrum.iInf_localization_eq_bot, Algebra.mem_iInf] exact fun hx ⟨v, hv⟩ => hx ⟨v, hv.isPrime⟩ · rw [Algebra.mem_bot] rintro ⟨y, rfl⟩ ⟨v, hv⟩ exact ⟨y, 1, v.ne_top_iff_one.mp hv.ne_top, by rw [map_one, inv_one, mul_one]⟩ end PrimeSpectrum
RingTheory\Multiplicity.lean
/- Copyright (c) 2018 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Chris Hughes -/ import Mathlib.Algebra.Associated.Basic import Mathlib.Algebra.BigOperators.Group.Finset import Mathlib.Algebra.SMulWithZero import Mathlib.Data.Nat.PartENat import Mathlib.Tactic.Linarith /-! # Multiplicity of a divisor For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves several basic results on it. ## Main definitions * `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers `n`. * `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite. -/ variable {α β : Type*} open Nat Part /-- `multiplicity a b` returns the largest natural number `n` such that `a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`, then it returns `⊤`-/ def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat := PartENat.find fun n => ¬a ^ (n + 1) ∣ b namespace multiplicity section Monoid variable [Monoid α] [Monoid β] /-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/ abbrev Finite (a b : α) : Prop := ∃ n : ℕ, ¬a ^ (n + 1) ∣ b theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} : Finite a b ↔ (multiplicity a b).Dom := Iff.rfl theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b := Iff.rfl theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ => hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩ @[norm_cast] theorem Int.natCast_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by apply Part.ext' · rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ] norm_cast · intro h1 h2 apply _root_.le_antisymm <;> · apply Nat.find_mono norm_cast simp @[deprecated (since := "2024-04-05")] alias Int.coe_nat_multiplicity := Int.natCast_multiplicity theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b := ⟨fun h n => Nat.casesOn n (by rw [_root_.pow_zero] exact one_dvd _) (by simpa [Finite, Classical.not_not] using h), by simp [Finite, multiplicity, Classical.not_not]; tauto⟩ theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a := let ⟨n, hn⟩ := h hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1) theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ => ⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩ variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)] theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} : (k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by rw [← PartENat.some_eq_natCast] exact Nat.casesOn k (fun _ => by rw [_root_.pow_zero] exact one_dvd _) fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b := pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get]) theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h) theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) : ¬a ^ m ∣ b := is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm) theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) : 0 < (multiplicity a b).get hfin := by refine zero_lt_iff.2 fun h => ?_ simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h) theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) : (k : PartENat) = multiplicity a b := le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by have : Finite a b := ⟨k, hsucc⟩ rw [PartENat.le_coe_iff] exact ⟨this, Nat.find_min' _ hsucc⟩ theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) : k = get (multiplicity a b) ⟨k, hsucc⟩ := by rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc] theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) : (k : PartENat) ≤ multiplicity a b := le_of_not_gt fun hk' => is_greatest hk' hk theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} : a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b := ⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩ theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} : multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le] theorem eq_coe_iff {a b : α} {n : ℕ} : multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by rw [← PartENat.some_eq_natCast] exact ⟨fun h => let ⟨h₁, h₂⟩ := eq_some_iff.1 h h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by rw [PartENat.lt_coe_iff] exact ⟨h₁, lt_succ_self _⟩)⟩, fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩ theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b := (PartENat.find_eq_top_iff _).trans <| by simp only [Classical.not_not] exact ⟨fun h n => Nat.casesOn n (by rw [_root_.pow_zero] exact one_dvd _) fun n => h _, fun h n => h _⟩ @[simp] theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ := eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _) -- @[simp] Porting note (#10618): simp can prove this theorem one_left (b : α) : multiplicity 1 b = ⊤ := isUnit_left b isUnit_one @[simp] theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero] simp [not_dvd_one_of_finite_one_right ha] -- @[simp] Porting note (#10618): simp can prove this theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ := isUnit_left a u.isUnit theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by rw [← Nat.cast_zero, eq_coe_iff] simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and] theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b := multiplicity_eq_zero.not_left theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b := Part.eq_none_iff' theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by rw [Ne, eq_top_iff_not_finite, Classical.not_not] theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by rw [lt_top_iff_ne_top, ne_top_iff_finite] theorem exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : Finite a b) : ∃ c : α, b = a ^ (multiplicity a b).get hfin * c ∧ ¬a ∣ c := by obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin refine ⟨c, hc, ?_⟩ rintro ⟨k, hk⟩ rw [hk, ← mul_assoc, ← _root_.pow_succ] at hc have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩ exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁ theorem multiplicity_le_multiplicity_iff {a b : α} {c d : β} : multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d := ⟨fun h n hab => pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h), fun h => letI := Classical.dec (Finite a b) if hab : Finite a b then by rw [← PartENat.natCast_get (finite_iff_dom.1 hab)] exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _)) else by have : ∀ n : ℕ, c ^ n ∣ d := fun n => h n (not_finite_iff_forall.1 hab _) rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩ theorem multiplicity_eq_multiplicity_iff {a b : α} {c d : β} : multiplicity a b = multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d := ⟨fun h n => ⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩, fun h => le_antisymm (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mp) (multiplicity_le_multiplicity_iff.mpr fun n => (h n).mpr)⟩ theorem le_multiplicity_map {F : Type*} [FunLike F α β] [MonoidHomClass F α β] (f : F) {a b : α} : multiplicity a b ≤ multiplicity (f a) (f b) := multiplicity_le_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd f theorem multiplicity_map_eq {F : Type*} [EquivLike F α β] [MulEquivClass F α β] (f : F) {a b : α} : multiplicity (f a) (f b) = multiplicity a b := multiplicity_eq_multiplicity_iff.mpr fun n ↦ by rw [← map_pow]; exact map_dvd_iff f theorem multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) : multiplicity a b ≤ multiplicity a c := multiplicity_le_multiplicity_iff.2 fun _ hb => hb.trans h theorem eq_of_associated_right {a b c : α} (h : Associated b c) : multiplicity a b = multiplicity a c := le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd) (multiplicity_le_multiplicity_of_dvd_right h.symm.dvd) theorem dvd_of_multiplicity_pos {a b : α} (h : (0 : PartENat) < multiplicity a b) : a ∣ b := by rw [← pow_one a] apply pow_dvd_of_le_multiplicity simpa only [Nat.cast_one, PartENat.pos_iff_one_le] using h theorem dvd_iff_multiplicity_pos {a b : α} : (0 : PartENat) < multiplicity a b ↔ a ∣ b := ⟨dvd_of_multiplicity_pos, fun hdvd => lt_of_le_of_ne (zero_le _) fun heq => is_greatest (show multiplicity a b < ↑1 by simpa only [heq, Nat.cast_zero] using PartENat.coe_lt_coe.mpr zero_lt_one) (by rwa [pow_one a])⟩ theorem finite_nat_iff {a b : ℕ} : Finite a b ↔ a ≠ 1 ∧ 0 < b := by rw [← not_iff_not, not_finite_iff_forall, not_and_or, Ne, Classical.not_not, not_lt, Nat.le_zero] exact ⟨fun h => or_iff_not_imp_right.2 fun hb => have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1 Classical.by_contradiction fun ha1 : a ≠ 1 => have ha_gt_one : 1 < a := lt_of_not_ge fun _ => match a with | 0 => ha rfl | 1 => ha1 rfl | b+2 => by omega not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b), fun h => by cases h <;> simp [*]⟩ alias ⟨_, _root_.has_dvd.dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos end Monoid section CommMonoid variable [CommMonoid α] theorem finite_of_finite_mul_left {a b c : α} : Finite a (b * c) → Finite a c := by rw [mul_comm]; exact finite_of_finite_mul_right variable [DecidableRel ((· ∣ ·) : α → α → Prop)] theorem isUnit_right {a b : α} (ha : ¬IsUnit a) (hb : IsUnit b) : multiplicity a b = 0 := eq_coe_iff.2 ⟨show a ^ 0 ∣ b by simp only [_root_.pow_zero, one_dvd], by rw [pow_one] exact fun h => mt (isUnit_of_dvd_unit h) ha hb⟩ theorem one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 := isUnit_right ha isUnit_one theorem unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 := isUnit_right ha u.isUnit open scoped Classical theorem multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) : multiplicity b c ≤ multiplicity a c := multiplicity_le_multiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h theorem eq_of_associated_left {a b c : α} (h : Associated a b) : multiplicity b c = multiplicity a c := le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd) (multiplicity_le_multiplicity_of_dvd_left h.symm.dvd) -- Porting note: this was doing nothing in mathlib3 also -- alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos end CommMonoid section MonoidWithZero variable [MonoidWithZero α] theorem ne_zero_of_finite {a b : α} (h : Finite a b) : b ≠ 0 := let ⟨n, hn⟩ := h fun hb => by simp [hb] at hn variable [DecidableRel ((· ∣ ·) : α → α → Prop)] @[simp] protected theorem zero (a : α) : multiplicity a 0 = ⊤ := Part.eq_none_iff.2 fun _ ⟨⟨_, hk⟩, _⟩ => hk (dvd_zero _) @[simp] theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 := multiplicity.multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha end MonoidWithZero section CommMonoidWithZero variable [CommMonoidWithZero α] variable [DecidableRel ((· ∣ ·) : α → α → Prop)] theorem multiplicity_mk_eq_multiplicity [DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop)] {a b : α} : multiplicity (Associates.mk a) (Associates.mk b) = multiplicity a b := by by_cases h : Finite a b · rw [← PartENat.natCast_get (finite_iff_dom.mp h)] refine (multiplicity.unique (show Associates.mk a ^ (multiplicity a b).get h ∣ Associates.mk b from ?_) ?_).symm <;> rw [← Associates.mk_pow, Associates.mk_dvd_mk] · exact pow_multiplicity_dvd h · exact is_greatest ((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _))) · suffices ¬Finite (Associates.mk a) (Associates.mk b) by rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this rw [h, this] refine not_finite_iff_forall.mpr fun n => by rw [← Associates.mk_pow, Associates.mk_dvd_mk] exact not_finite_iff_forall.mp h n end CommMonoidWithZero section Semiring variable [Semiring α] [DecidableRel ((· ∣ ·) : α → α → Prop)] theorem min_le_multiplicity_add {p a b : α} : min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) := (le_total (multiplicity p a) (multiplicity p b)).elim (fun h ↦ by rw [min_eq_left h, multiplicity_le_multiplicity_iff] exact fun n hn => dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn)) fun h ↦ by rw [min_eq_right h, multiplicity_le_multiplicity_iff] exact fun n hn => dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn end Semiring section Ring variable [Ring α] [DecidableRel ((· ∣ ·) : α → α → Prop)] @[simp] protected theorem neg (a b : α) : multiplicity a (-b) = multiplicity a b := Part.ext' (by simp only [multiplicity, PartENat.find, dvd_neg]) fun h₁ h₂ => PartENat.natCast_inj.1 (by rw [PartENat.natCast_get] exact Eq.symm (unique (pow_multiplicity_dvd _).neg_right (mt dvd_neg.1 (is_greatest' _ (lt_succ_self _))))) theorem Int.natAbs (a : ℕ) (b : ℤ) : multiplicity a b.natAbs = multiplicity (a : ℤ) b := by cases' Int.natAbs_eq b with h h <;> conv_rhs => rw [h] · rw [Int.natCast_multiplicity] · rw [multiplicity.neg, Int.natCast_multiplicity] theorem multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) : multiplicity p (a + b) = multiplicity p b := by apply le_antisymm · apply PartENat.le_of_lt_add_one cases' PartENat.ne_top_iff.mp (PartENat.ne_top_of_lt h) with k hk rw [hk] rw_mod_cast [multiplicity_lt_iff_not_dvd, dvd_add_right] · intro h_dvd apply multiplicity.is_greatest _ h_dvd rw [hk, ← Nat.succ_eq_add_one] norm_cast apply Nat.lt_succ_self k · rw [pow_dvd_iff_le_multiplicity, Nat.cast_add, ← hk, Nat.cast_one] exact PartENat.add_one_le_of_lt h · have := @min_le_multiplicity_add α _ _ p a b rwa [← min_eq_right (le_of_lt h)] theorem multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) : multiplicity p (a - b) = multiplicity p b := by rw [sub_eq_add_neg, multiplicity_add_of_gt] <;> rw [multiplicity.neg]; assumption theorem multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) : multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := by rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with (hab | hab | hab) · rw [add_comm, multiplicity_add_of_gt hab, min_eq_left] exact le_of_lt hab · contradiction · rw [multiplicity_add_of_gt hab, min_eq_right] exact le_of_lt hab end Ring section CancelCommMonoidWithZero variable [CancelCommMonoidWithZero α] /- Porting note: Pulled a b intro parameters since Lean parses that more easily -/ theorem finite_mul_aux {p : α} (hp : Prime p) {a b : α} : ∀ {n m : ℕ}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b | n, m => fun ha hb ⟨s, hs⟩ => have : p ∣ a * b := ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩ (hp.2.2 a b this).elim (fun ⟨x, hx⟩ => have hn0 : 0 < n := Nat.pos_of_ne_zero fun hn0 => by simp [hx, hn0] at ha have hpx : ¬p ^ (n - 1 + 1) ∣ x := fun ⟨y, hy⟩ => ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩) have : 1 ≤ n + m := le_trans hn0 (Nat.le_add_right n m) finite_mul_aux hp hpx hb ⟨s, mul_right_cancel₀ hp.1 (by rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this] simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩) fun ⟨x, hx⟩ => have hm0 : 0 < m := Nat.pos_of_ne_zero fun hm0 => by simp [hx, hm0] at hb have hpx : ¬p ^ (m - 1 + 1) ∣ x := fun ⟨y, hy⟩ => hb (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 <| by rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩) finite_mul_aux hp ha hpx ⟨s, mul_right_cancel₀ hp.1 (by rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)] simp_all [mul_comm, mul_assoc, mul_left_comm, pow_add])⟩ theorem finite_mul {p a b : α} (hp : Prime p) : Finite p a → Finite p b → Finite p (a * b) := fun ⟨n, hn⟩ ⟨m, hm⟩ => ⟨n + m, finite_mul_aux hp hn hm⟩ theorem finite_mul_iff {p a b : α} (hp : Prime p) : Finite p (a * b) ↔ Finite p a ∧ Finite p b := ⟨fun h => ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, fun h => finite_mul hp h.1 h.2⟩ theorem finite_pow {p a : α} (hp : Prime p) : ∀ {k : ℕ} (_ : Finite p a), Finite p (a ^ k) | 0, _ => ⟨0, by simp [mt isUnit_iff_dvd_one.2 hp.2.1]⟩ | k + 1, ha => by rw [_root_.pow_succ']; exact finite_mul hp ha (finite_pow hp ha) variable [DecidableRel ((· ∣ ·) : α → α → Prop)] @[simp] theorem multiplicity_self {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by rw [← Nat.cast_one] exact eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => ha (isUnit_iff_dvd_one.2 ⟨b, mul_left_cancel₀ ha0 <| by simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩ @[simp] theorem get_multiplicity_self {a : α} (ha : Finite a a) : get (multiplicity a a) ha = 1 := PartENat.get_eq_iff_eq_coe.2 (eq_coe_iff.2 ⟨by simp, fun ⟨b, hb⟩ => by rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc, mul_right_inj' (ne_zero_of_finite ha)] at hb exact mt isUnit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by simp_all⟩⟩) protected theorem mul' {p a b : α} (hp : Prime p) (h : (multiplicity p (a * b)).Dom) : get (multiplicity p (a * b)) h = get (multiplicity p a) ((finite_mul_iff hp).1 h).1 + get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a := pow_multiplicity_dvd _ have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b := pow_multiplicity_dvd _ have hpoweq : p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 + get (multiplicity p b) ((finite_mul_iff hp).1 h).2) = p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 * p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := by simp [pow_add] have hdiv : p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 + get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣ a * b := by rw [hpoweq]; apply mul_dvd_mul <;> assumption have hsucc : ¬p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 + get (multiplicity p b) ((finite_mul_iff hp).1 h).2 + 1) ∣ a * b := fun h => not_or_of_not (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _)) (_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h) rw [← PartENat.natCast_inj, PartENat.natCast_get, eq_coe_iff]; exact ⟨hdiv, hsucc⟩ open scoped Classical protected theorem mul {p a b : α} (hp : Prime p) : multiplicity p (a * b) = multiplicity p a + multiplicity p b := if h : Finite p a ∧ Finite p b then by rw [← PartENat.natCast_get (finite_iff_dom.1 h.1), ← PartENat.natCast_get (finite_iff_dom.1 h.2), ← PartENat.natCast_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← Nat.cast_add, PartENat.natCast_inj, multiplicity.mul' hp] else by rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)] cases' not_and_or.1 h with h h <;> simp [eq_top_iff_not_finite.2 h] theorem Finset.prod {β : Type*} {p : α} (hp : Prime p) (s : Finset β) (f : β → α) : multiplicity p (∏ x ∈ s, f x) = ∑ x ∈ s, multiplicity p (f x) := by classical induction' s using Finset.induction with a s has ih h · simp only [Finset.sum_empty, Finset.prod_empty] convert one_right hp.not_unit · simp [has, ← ih] convert multiplicity.mul hp -- Porting note: with protected could not use pow' k in the succ branch protected theorem pow' {p a : α} (hp : Prime p) (ha : Finite p a) : ∀ {k : ℕ}, get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha := by intro k induction' k with k hk · simp [one_right hp.not_unit] · have : multiplicity p (a ^ (k + 1)) = multiplicity p (a * a ^ k) := by rw [_root_.pow_succ'] rw [get_eq_get_of_eq _ _ this, multiplicity.mul' hp, hk, add_mul, one_mul, add_comm] theorem pow {p a : α} (hp : Prime p) : ∀ {k : ℕ}, multiplicity p (a ^ k) = k • multiplicity p a | 0 => by simp [one_right hp.not_unit] | succ k => by simp [_root_.pow_succ, succ_nsmul, pow hp, multiplicity.mul hp] theorem multiplicity_pow_self {p : α} (h0 : p ≠ 0) (hu : ¬IsUnit p) (n : ℕ) : multiplicity p (p ^ n) = n := by rw [eq_coe_iff] use dvd_rfl rw [pow_dvd_pow_iff h0 hu] apply Nat.not_succ_le_self theorem multiplicity_pow_self_of_prime {p : α} (hp : Prime p) (n : ℕ) : multiplicity p (p ^ n) = n := multiplicity_pow_self hp.ne_zero hp.not_unit n end CancelCommMonoidWithZero end multiplicity section Nat open multiplicity theorem multiplicity_eq_zero_of_coprime {p a b : ℕ} (hp : p ≠ 1) (hle : multiplicity p a ≤ multiplicity p b) (hab : Nat.Coprime a b) : multiplicity p a = 0 := by rw [multiplicity_le_multiplicity_iff] at hle rw [← nonpos_iff_eq_zero, ← not_lt, PartENat.pos_iff_one_le, ← Nat.cast_one, ← pow_dvd_iff_le_multiplicity] intro h have := Nat.dvd_gcd h (hle _ h) rw [Coprime.gcd_eq_one hab, Nat.dvd_one, pow_one] at this exact hp this end Nat namespace multiplicity theorem finite_int_iff_natAbs_finite {a b : ℤ} : Finite a b ↔ Finite a.natAbs b.natAbs := by simp only [finite_def, ← Int.natAbs_dvd_natAbs, Int.natAbs_pow] theorem finite_int_iff {a b : ℤ} : Finite a b ↔ a.natAbs ≠ 1 ∧ b ≠ 0 := by rw [finite_int_iff_natAbs_finite, finite_nat_iff, pos_iff_ne_zero, Int.natAbs_ne_zero] instance decidableNat : DecidableRel fun a b : ℕ => (multiplicity a b).Dom := fun _ _ => decidable_of_iff _ finite_nat_iff.symm instance decidableInt : DecidableRel fun a b : ℤ => (multiplicity a b).Dom := fun _ _ => decidable_of_iff _ finite_int_iff.symm end multiplicity
RingTheory\Nakayama.lean
/- Copyright (c) 2021 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.RingTheory.JacobsonIdeal /-! # Nakayama's lemma This file contains some alternative statements of Nakayama's Lemma as found in [Stacks: Nakayama's Lemma](https://stacks.math.columbia.edu/tag/00DV). ## Main statements * `Submodule.eq_smul_of_le_smul_of_le_jacobson` - A version of (2) in [Stacks: Nakayama's Lemma](https://stacks.math.columbia.edu/tag/00DV)., generalising to the Jacobson of any ideal. * `Submodule.eq_bot_of_le_smul_of_le_jacobson_bot` - Statement (2) in [Stacks: Nakayama's Lemma](https://stacks.math.columbia.edu/tag/00DV). * `Submodule.sup_smul_eq_sup_smul_of_le_smul_of_le_jacobson` - A version of (4) in [Stacks: Nakayama's Lemma](https://stacks.math.columbia.edu/tag/00DV)., generalising to the Jacobson of any ideal. * `Submodule.smul_le_of_le_smul_of_le_jacobson_bot` - Statement (4) in [Stacks: Nakayama's Lemma](https://stacks.math.columbia.edu/tag/00DV). Note that a version of Statement (1) in [Stacks: Nakayama's Lemma](https://stacks.math.columbia.edu/tag/00DV) can be found in `RingTheory.Finiteness` under the name `Submodule.exists_sub_one_mem_and_smul_eq_zero_of_fg_of_le_smul` ## References * [Stacks: Nakayama's Lemma](https://stacks.math.columbia.edu/tag/00DV) ## Tags Nakayama, Jacobson -/ variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] open Ideal namespace Submodule /-- **Nakayama's Lemma** - A slightly more general version of (2) in [Stacks 00DV](https://stacks.math.columbia.edu/tag/00DV). See also `eq_bot_of_le_smul_of_le_jacobson_bot` for the special case when `J = ⊥`. -/ theorem eq_smul_of_le_smul_of_le_jacobson {I J : Ideal R} {N : Submodule R M} (hN : N.FG) (hIN : N ≤ I • N) (hIjac : I ≤ jacobson J) : N = J • N := by refine le_antisymm ?_ (Submodule.smul_le.2 fun _ _ _ => Submodule.smul_mem _ _) intro n hn cases' Submodule.exists_sub_one_mem_and_smul_eq_zero_of_fg_of_le_smul I N hN hIN with r hr cases' exists_mul_sub_mem_of_sub_one_mem_jacobson r (hIjac hr.1) with s hs have : n = -(s * r - 1) • n := by rw [neg_sub, sub_smul, mul_smul, hr.2 n hn, one_smul, smul_zero, sub_zero] rw [this] exact Submodule.smul_mem_smul (Submodule.neg_mem _ hs) hn lemma eq_bot_of_eq_ideal_smul_of_le_jacobson_annihilator {I : Ideal R} {N : Submodule R M} (hN : FG N) (hIN : N = I • N) (hIjac : I ≤ N.annihilator.jacobson) : N = ⊥ := (eq_smul_of_le_smul_of_le_jacobson hN hIN.le hIjac).trans N.annihilator_smul open Pointwise in lemma eq_bot_of_eq_pointwise_smul_of_mem_jacobson_annihilator {r : R} {N : Submodule R M} (hN : FG N) (hrN : N = r • N) (hrJac : r ∈ N.annihilator.jacobson) : N = ⊥ := eq_bot_of_eq_ideal_smul_of_le_jacobson_annihilator hN (Eq.trans hrN (ideal_span_singleton_smul r N).symm) ((span_singleton_le_iff_mem r _).mpr hrJac) open Pointwise in lemma eq_bot_of_set_smul_eq_of_subset_jacobson_annihilator {s : Set R} {N : Submodule R M} (hN : FG N) (hsN : N = s • N) (hsJac : s ⊆ N.annihilator.jacobson) : N = ⊥ := eq_bot_of_eq_ideal_smul_of_le_jacobson_annihilator hN (Eq.trans hsN (span_smul_eq s N).symm) (span_le.mpr hsJac) lemma top_ne_ideal_smul_of_le_jacobson_annihilator [Nontrivial M] [Module.Finite R M] {I} (h : I ≤ (Module.annihilator R M).jacobson) : (⊤ : Submodule R M) ≠ I • ⊤ := fun H => top_ne_bot <| eq_bot_of_eq_ideal_smul_of_le_jacobson_annihilator Module.Finite.out H <| (congrArg (I ≤ Ideal.jacobson ·) annihilator_top).mpr h open Pointwise in lemma top_ne_set_smul_of_subset_jacobson_annihilator [Nontrivial M] [Module.Finite R M] {s : Set R} (h : s ⊆ (Module.annihilator R M).jacobson) : (⊤ : Submodule R M) ≠ s • ⊤ := ne_of_ne_of_eq (top_ne_ideal_smul_of_le_jacobson_annihilator (span_le.mpr h)) (span_smul_eq _ _) open Pointwise in lemma top_ne_pointwise_smul_of_mem_jacobson_annihilator [Nontrivial M] [Module.Finite R M] {r} (h : r ∈ (Module.annihilator R M).jacobson) : (⊤ : Submodule R M) ≠ r • ⊤ := ne_of_ne_of_eq (top_ne_set_smul_of_subset_jacobson_annihilator <| Set.singleton_subset_iff.mpr h) (singleton_set_smul ⊤ r) /-- **Nakayama's Lemma** - Statement (2) in [Stacks 00DV](https://stacks.math.columbia.edu/tag/00DV). See also `eq_smul_of_le_smul_of_le_jacobson` for a generalisation to the `jacobson` of any ideal -/ theorem eq_bot_of_le_smul_of_le_jacobson_bot (I : Ideal R) (N : Submodule R M) (hN : N.FG) (hIN : N ≤ I • N) (hIjac : I ≤ jacobson ⊥) : N = ⊥ := by rw [eq_smul_of_le_smul_of_le_jacobson hN hIN hIjac, Submodule.bot_smul] theorem sup_eq_sup_smul_of_le_smul_of_le_jacobson {I J : Ideal R} {N N' : Submodule R M} (hN' : N'.FG) (hIJ : I ≤ jacobson J) (hNN : N' ≤ N ⊔ I • N') : N ⊔ N' = N ⊔ J • N' := by have hNN' : N ⊔ N' = N ⊔ I • N' := le_antisymm (sup_le le_sup_left hNN) (sup_le_sup_left (Submodule.smul_le.2 fun _ _ _ => Submodule.smul_mem _ _) _) have h_comap := Submodule.comap_injective_of_surjective (LinearMap.range_eq_top.1 N.range_mkQ) have : (I • N').map N.mkQ = N'.map N.mkQ := by simpa only [← h_comap.eq_iff, comap_map_mkQ, sup_comm, eq_comm] using hNN' have := @Submodule.eq_smul_of_le_smul_of_le_jacobson _ _ _ _ _ I J (N'.map N.mkQ) (hN'.map _) (by rw [← map_smul'', this]) hIJ rwa [← map_smul'', ← h_comap.eq_iff, comap_map_eq, comap_map_eq, Submodule.ker_mkQ, sup_comm, sup_comm (b := N)] at this /-- **Nakayama's Lemma** - A slightly more general version of (4) in [Stacks 00DV](https://stacks.math.columbia.edu/tag/00DV). See also `smul_le_of_le_smul_of_le_jacobson_bot` for the special case when `J = ⊥`. -/ theorem sup_smul_eq_sup_smul_of_le_smul_of_le_jacobson {I J : Ideal R} {N N' : Submodule R M} (hN' : N'.FG) (hIJ : I ≤ jacobson J) (hNN : N' ≤ N ⊔ I • N') : N ⊔ I • N' = N ⊔ J • N' := ((sup_le_sup_left smul_le_right _).antisymm (sup_le le_sup_left hNN)).trans (sup_eq_sup_smul_of_le_smul_of_le_jacobson hN' hIJ hNN) theorem le_of_le_smul_of_le_jacobson_bot {R M} [CommRing R] [AddCommGroup M] [Module R M] {I : Ideal R} {N N' : Submodule R M} (hN' : N'.FG) (hIJ : I ≤ jacobson ⊥) (hNN : N' ≤ N ⊔ I • N') : N' ≤ N := by rw [← sup_eq_left, sup_eq_sup_smul_of_le_smul_of_le_jacobson hN' hIJ hNN, bot_smul, sup_bot_eq] /-- **Nakayama's Lemma** - Statement (4) in [Stacks 00DV](https://stacks.math.columbia.edu/tag/00DV). See also `sup_smul_eq_sup_smul_of_le_smul_of_le_jacobson` for a generalisation to the `jacobson` of any ideal -/ theorem smul_le_of_le_smul_of_le_jacobson_bot {I : Ideal R} {N N' : Submodule R M} (hN' : N'.FG) (hIJ : I ≤ jacobson ⊥) (hNN : N' ≤ N ⊔ I • N') : I • N' ≤ N := smul_le_right.trans (le_of_le_smul_of_le_jacobson_bot hN' hIJ hNN) end Submodule
RingTheory\Noetherian.lean
/- Copyright (c) 2018 Mario Carneiro, Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Kevin Buzzard -/ import Mathlib.Order.Filter.EventuallyConst import Mathlib.Order.PartialSups import Mathlib.Algebra.Module.Submodule.IterateMapComap import Mathlib.RingTheory.OrzechProperty import Mathlib.RingTheory.Nilpotent.Lemmas import Mathlib.Algebra.Order.Archimedean.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_wellFounded` 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] * [samuel1967] ## Tags Noetherian, noetherian, Noetherian ring, Noetherian module, noetherian ring, noetherian module -/ open Set Filter 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. -/ -- Porting note: 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) variable (M) 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 _⟩ variable {M} instance isNoetherian_quotient {R} [Ring R] {M} [AddCommGroup M] [Module R M] (N : Submodule R M) [IsNoetherian R M] : IsNoetherian R (M ⧸ N) := isNoetherian_of_surjective _ _ (LinearMap.range_eq_top.mpr N.mkQ_surjective) @[deprecated (since := "2024-04-27"), nolint defLemma] alias Submodule.Quotient.isNoetherian := isNoetherian_quotient theorem isNoetherian_of_linearEquiv (f : M ≃ₗ[R] P) [IsNoetherian R M] : IsNoetherian R P := isNoetherian_of_surjective _ f.toLinearMap f.range theorem isNoetherian_top_iff : IsNoetherian R (⊤ : Submodule R M) ↔ IsNoetherian R M := by constructor <;> intro h · exact isNoetherian_of_linearEquiv (LinearEquiv.ofTop (⊤ : Submodule R M) rfl) · exact isNoetherian_of_linearEquiv (LinearEquiv.ofTop (⊤ : Submodule R M) rfl).symm 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 := 100) IsNoetherian.finite [IsNoetherian R M] : Finite R M := ⟨IsNoetherian.noetherian ⊤⟩ instance {R₁ S : Type*} [CommSemiring R₁] [Semiring S] [Algebra R₁ S] [IsNoetherian R₁ S] (I : Ideal S) : 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) : Finite R M := ⟨fg_of_injective f hf⟩ end Module section variable {R : Type*} {M : Type*} {P : Type*} variable [Ring R] [AddCommGroup M] [AddCommGroup P] variable [Module R M] [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 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_pi {R ι : Type*} {M : ι → Type*} [Ring R] [∀ i, AddCommGroup (M i)] [∀ i, Module R (M i)] [Finite ι] [∀ i, IsNoetherian R (M i)] : IsNoetherian R (∀ i, M i) := by cases nonempty_fintype ι haveI := Classical.decEq ι suffices on_finset : ∀ s : Finset ι, IsNoetherian R (∀ i : s, M i) by let coe_e := Equiv.subtypeUnivEquiv <| @Finset.mem_univ ι _ letI : IsNoetherian R (∀ i : Finset.univ, M (coe_e i)) := on_finset Finset.univ exact isNoetherian_of_linearEquiv (LinearEquiv.piCongrLeft R M coe_e) intro s induction' s using Finset.induction with a s has ih · exact ⟨fun s => by have : s = ⊥ := by simp only [eq_iff_true_of_subsingleton] rw [this] apply Submodule.fg_bot⟩ refine @isNoetherian_of_linearEquiv R (M a × ((i : s) → M i)) _ _ _ _ _ _ ?_ <| @isNoetherian_prod R (M a) _ _ _ _ _ _ _ ih refine { toFun := fun f i => (Finset.mem_insert.1 i.2).by_cases (fun h : i.1 = a => show M i.1 from Eq.recOn h.symm f.1) (fun h : i.1 ∈ s => show M i.1 from f.2 ⟨i.1, h⟩), invFun := fun f => (f ⟨a, Finset.mem_insert_self _ _⟩, fun i => f ⟨i.1, Finset.mem_insert_of_mem i.2⟩), map_add' := ?_, map_smul' := ?_ left_inv := ?_, right_inv := ?_ } · intro f g ext i unfold Or.by_cases cases' i with i hi rcases Finset.mem_insert.1 hi with (rfl | h) · change _ = _ + _ simp only [dif_pos] rfl · change _ = _ + _ have : ¬i = a := by rintro rfl exact has h simp only [dif_neg this, dif_pos h] rfl · intro c f ext i unfold Or.by_cases cases' i with i hi rcases Finset.mem_insert.1 hi with (rfl | h) · dsimp simp only [dif_pos] · dsimp have : ¬i = a := by rintro rfl exact has h simp only [dif_neg this, dif_pos h] · intro f apply Prod.ext · simp only [Or.by_cases, dif_pos] · ext ⟨i, his⟩ have : ¬i = a := by rintro rfl exact has his simp only [Or.by_cases, this, not_false_iff, dif_neg] · intro f ext ⟨i, hi⟩ rcases Finset.mem_insert.1 hi with (rfl | h) · simp only [Or.by_cases, dif_pos] · have : ¬i = a := by rintro rfl exact has h simp only [Or.by_cases, dif_neg this, dif_pos h] /-- 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' {R ι M : Type*} [Ring R] [AddCommGroup M] [Module R M] [Finite ι] [IsNoetherian R M] : IsNoetherian R (ι → M) := isNoetherian_pi 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 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_wellFounded : IsNoetherian R M ↔ WellFounded ((· > ·) : Submodule R M → Submodule R M → Prop) := by have := (CompleteLattice.wellFounded_characterisations <| Submodule R M).out 0 3 -- Porting note: inlining this makes rw complain about it being a metavariable rw [this] 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_fg_wellFounded : IsNoetherian R M ↔ WellFounded ((· > ·) : { N : Submodule R M // N.FG } → { N : Submodule R M // N.FG } → Prop) := by let α := { N : Submodule R M // N.FG } constructor · intro H let f : α ↪o Submodule R M := OrderEmbedding.subtype _ exact OrderEmbedding.wellFounded f.dual (isNoetherian_iff_wellFounded.mp H) · intro H constructor intro N obtain ⟨⟨N₀, h₁⟩, e : N₀ ≤ N, h₂⟩ := WellFounded.has_min H { 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 _) variable (R M) theorem wellFounded_submodule_gt (R M) [Semiring R] [AddCommMonoid M] [Module R M] : ∀ [IsNoetherian R M], WellFounded ((· > ·) : Submodule R M → Submodule R M → Prop) := isNoetherian_iff_wellFounded.mp ‹_› variable {R M} /-- 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.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_wellFounded, WellFounded.monotone_chain_condition] 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 /-- 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 := WellFounded.recursion (wellFounded_submodule_gt R M) I hgt end 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] lemma Submodule.finite_ne_bot_of_independent {ι : Type*} {N : ι → Submodule R M} (h : CompleteLattice.Independent N) : Set.Finite {i | N i ≠ ⊥} := CompleteLattice.WellFounded.finite_ne_bot_of_independent (isNoetherian_iff_wellFounded.mp inferInstance) 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 have hwf := isNoetherian_iff_wellFounded.mp (by infer_instance : IsNoetherian R M) refine CompleteLattice.WellFounded.finite_of_independent hwf hv.independent_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 @[deprecated (since := "2023-12-30")] alias finite_of_linearIndependent := LinearIndependent.set_finite_of_isNoetherian /-- 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 P] (f : M →ₗ[R] N) (g : N →ₗ[R] P) (h : LinearMap.range f = LinearMap.ker g) : IsNoetherian R N := isNoetherian_iff_wellFounded.2 <| wellFounded_gt_exact_sequence (wellFounded_submodule_gt R _) (wellFounded_submodule_gt R _) (LinearMap.range f) (Submodule.map (f.ker.liftQ f <| le_rfl)) (Submodule.comap (f.ker.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_refl _)) (Submodule.giMapComap g.surjective_rangeRestrict) (by simp [Submodule.map_comap_eq, inf_comm, Submodule.range_liftQ]) (by simp [Submodule.comap_map_eq, h]) /-- For an endomorphism of a Noetherian module, any sufficiently large iterate has disjoint kernel and range. -/ theorem LinearMap.eventually_disjoint_ker_pow_range_pow (f : M →ₗ[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 LinearMap.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_lt m l with h | h · rw [← hn _ (hm.trans h), hn _ hm] · exact f.iterateKer.monotone h.le /-- **Orzech's theorem** for Noetherian module: 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 module: 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⟩ /-- 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) exact ⟨n, fun m p => (h m).eq_bot_of_ge <| sup_eq_left.1 <| (w (m + 1) <| le_add_right p).symm.trans <| w m p⟩ /-- 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 /-- 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 -- see Note [lower instance priority] instance (priority := 80) isNoetherian_of_finite (R M) [Finite M] [Semiring R] [AddCommMonoid M] [Module R 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] /-- 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 := by rw [isNoetherian_iff_wellFounded] at h ⊢ exact OrderEmbedding.wellFounded (Submodule.MapSubtype.orderEmbedding N).dual h /-- 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 := by rw [isNoetherian_iff_wellFounded] at h ⊢ exact (Submodule.restrictScalarsEmbedding R S M).dual.wellFounded 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 let ⟨s, hs⟩ := hN haveI := Classical.decEq M haveI := Classical.decEq R have : ∀ x ∈ s, x ∈ N := fun x hx => hs ▸ Submodule.subset_span hx refine @isNoetherian_of_surjective R ((↑s : Set M) → R) N _ _ _ (Pi.module _ _ _) _ ?_ ?_ isNoetherian_pi · fapply LinearMap.mk · fapply AddHom.mk · exact fun f => ⟨∑ i ∈ s.attach, f i • i.1, N.sum_mem fun c _ => N.smul_mem _ <| this _ c.2⟩ · intro f g apply Subtype.eq change (∑ i ∈ s.attach, (f i + g i) • _) = _ simp only [add_smul, Finset.sum_add_distrib] rfl · intro c f apply Subtype.eq change (∑ i ∈ s.attach, (c • f i) • _) = _ simp only [smul_eq_mul, mul_smul] exact Finset.smul_sum.symm · rw [LinearMap.range_eq_top] rintro ⟨n, hn⟩ change n ∈ N at hn rw [← hs, ← Set.image_id (s : Set M), Finsupp.mem_span_image_iff_total] at hn rcases hn with ⟨l, hl1, hl2⟩ refine ⟨fun x => l x, Subtype.ext ?_⟩ change (∑ i ∈ s.attach, l i • (i : M)) = n rw [s.sum_attach fun i ↦ l i • i, ← hl2, Finsupp.total_apply, Finsupp.sum, eq_comm] refine Finset.sum_subset hl1 fun x _ hx => ?_ rw [Finsupp.not_mem_support_iff.1 hx, zero_smul] 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 : IsNoetherian R (⊤ : Submodule R M) := isNoetherian_of_fg_of_noetherian _ <| Module.finite_def.mp inferInstance isNoetherian_of_linearEquiv (LinearEquiv.ofTop (⊤ : Submodule R M) rfl) /-- 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_surjective (R) [Ring R] (S) [Ring S] (f : R →+* S) (hf : Function.Surjective f) [H : IsNoetherianRing R] : IsNoetherianRing S := by rw [isNoetherianRing_iff, isNoetherian_iff_wellFounded] at H ⊢ exact OrderEmbedding.wellFounded (Ideal.orderEmbeddingOfSurjective f hf).dual H instance isNoetherianRing_range {R} [Ring R] {S} [Ring S] (f : R →+* S) [IsNoetherianRing R] : IsNoetherianRing f.range := isNoetherianRing_of_surjective R f.range f.rangeRestrict f.rangeRestrict_surjective theorem isNoetherianRing_of_ringEquiv (R) [Ring R] {S} [Ring S] (f : R ≃+* S) [IsNoetherianRing R] : IsNoetherianRing S := isNoetherianRing_of_surjective R S f.toRingHom f.toEquiv.surjective theorem IsNoetherianRing.isNilpotent_nilradical (R : Type*) [CommRing 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⟩ /-- 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
RingTheory\NormTrace.lean
/- Copyright (c) 2023 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.RingTheory.Norm.Defs import Mathlib.RingTheory.Trace.Defs /-! # Relation between Norms and Traces -/ lemma Algebra.norm_one_add_smul {A B} [CommRing A] [CommRing B] [Algebra A B] [Module.Free A B] [Module.Finite A B] (a : A) (x : B) : ∃ r : A, Algebra.norm A (1 + a • x) = 1 + Algebra.trace A B x * a + r * a ^ 2 := by classical let ι := Module.Free.ChooseBasisIndex A B let b : Basis ι A B := Module.Free.chooseBasis _ _ haveI : Fintype ι := inferInstance clear_value ι b simp_rw [Algebra.norm_eq_matrix_det b, Algebra.trace_eq_matrix_trace b] simp only [map_add, map_one, map_smul, Matrix.det_one_add_smul a] exact ⟨_, rfl⟩
RingTheory\Nullstellensatz.lean
/- Copyright (c) 2021 Devon Tuma. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Devon Tuma -/ import Mathlib.RingTheory.Jacobson import Mathlib.FieldTheory.IsAlgClosed.Basic import Mathlib.FieldTheory.MvPolynomial import Mathlib.RingTheory.PrimeSpectrum /-! # Nullstellensatz This file establishes a version of Hilbert's classical Nullstellensatz for `MvPolynomial`s. The main statement of the theorem is `MvPolynomial.vanishingIdeal_zeroLocus_eq_radical`. The statement is in terms of new definitions `vanishingIdeal` and `zeroLocus`. Mathlib already has versions of these in terms of the prime spectrum of a ring, but those are not well-suited for expressing this result. Suggestions for better ways to state this theorem or organize things are welcome. The machinery around `vanishingIdeal` and `zeroLocus` is also minimal, I only added lemmas directly needed in this proof, since I'm not sure if they are the right approach. -/ open Ideal noncomputable section namespace MvPolynomial open MvPolynomial variable {k : Type*} [Field k] variable {σ : Type*} /-- Set of points that are zeroes of all polynomials in an ideal -/ def zeroLocus (I : Ideal (MvPolynomial σ k)) : Set (σ → k) := {x : σ → k | ∀ p ∈ I, eval x p = 0} @[simp] theorem mem_zeroLocus_iff {I : Ideal (MvPolynomial σ k)} {x : σ → k} : x ∈ zeroLocus I ↔ ∀ p ∈ I, eval x p = 0 := Iff.rfl theorem zeroLocus_anti_mono {I J : Ideal (MvPolynomial σ k)} (h : I ≤ J) : zeroLocus J ≤ zeroLocus I := fun _ hx p hp => hx p <| h hp @[simp] theorem zeroLocus_bot : zeroLocus (⊥ : Ideal (MvPolynomial σ k)) = ⊤ := eq_top_iff.2 fun x _ _ hp => Trans.trans (congr_arg (eval x) (mem_bot.1 hp)) (eval x).map_zero @[simp] theorem zeroLocus_top : zeroLocus (⊤ : Ideal (MvPolynomial σ k)) = ⊥ := eq_bot_iff.2 fun x hx => one_ne_zero ((eval x).map_one ▸ hx 1 Submodule.mem_top : (1 : k) = 0) /-- Ideal of polynomials with common zeroes at all elements of a set -/ def vanishingIdeal (V : Set (σ → k)) : Ideal (MvPolynomial σ k) where carrier := {p | ∀ x ∈ V, eval x p = 0} zero_mem' x _ := RingHom.map_zero _ add_mem' {p q} hp hq x hx := by simp only [hq x hx, hp x hx, add_zero, RingHom.map_add] smul_mem' p q hq x hx := by simp only [hq x hx, Algebra.id.smul_eq_mul, mul_zero, RingHom.map_mul] @[simp] theorem mem_vanishingIdeal_iff {V : Set (σ → k)} {p : MvPolynomial σ k} : p ∈ vanishingIdeal V ↔ ∀ x ∈ V, eval x p = 0 := Iff.rfl theorem vanishingIdeal_anti_mono {A B : Set (σ → k)} (h : A ≤ B) : vanishingIdeal B ≤ vanishingIdeal A := fun _ hp x hx => hp x <| h hx theorem vanishingIdeal_empty : vanishingIdeal (∅ : Set (σ → k)) = ⊤ := le_antisymm le_top fun _ _ x hx => absurd hx (Set.not_mem_empty x) theorem le_vanishingIdeal_zeroLocus (I : Ideal (MvPolynomial σ k)) : I ≤ vanishingIdeal (zeroLocus I) := fun p hp _ hx => hx p hp theorem zeroLocus_vanishingIdeal_le (V : Set (σ → k)) : V ≤ zeroLocus (vanishingIdeal V) := fun V hV _ hp => hp V hV theorem zeroLocus_vanishingIdeal_galoisConnection : @GaloisConnection (Ideal (MvPolynomial σ k)) (Set (σ → k))ᵒᵈ _ _ zeroLocus vanishingIdeal := GaloisConnection.monotone_intro (fun _ _ ↦ vanishingIdeal_anti_mono) (fun _ _ ↦ zeroLocus_anti_mono) le_vanishingIdeal_zeroLocus zeroLocus_vanishingIdeal_le theorem le_zeroLocus_iff_le_vanishingIdeal {V : Set (σ → k)} {I : Ideal (MvPolynomial σ k)} : V ≤ zeroLocus I ↔ I ≤ vanishingIdeal V := zeroLocus_vanishingIdeal_galoisConnection.le_iff_le theorem zeroLocus_span (S : Set (MvPolynomial σ k)) : zeroLocus (Ideal.span S) = { x | ∀ p ∈ S, eval x p = 0 } := eq_of_forall_le_iff fun _ => le_zeroLocus_iff_le_vanishingIdeal.trans <| Ideal.span_le.trans forall₂_swap theorem mem_vanishingIdeal_singleton_iff (x : σ → k) (p : MvPolynomial σ k) : p ∈ (vanishingIdeal {x} : Ideal (MvPolynomial σ k)) ↔ eval x p = 0 := ⟨fun h => h x rfl, fun hpx _ hy => hy.symm ▸ hpx⟩ instance vanishingIdeal_singleton_isMaximal {x : σ → k} : (vanishingIdeal {x} : Ideal (MvPolynomial σ k)).IsMaximal := by have : MvPolynomial σ k ⧸ vanishingIdeal {x} ≃+* k := RingEquiv.ofBijective (Ideal.Quotient.lift _ (eval x) fun p h => (mem_vanishingIdeal_singleton_iff x p).mp h) (by refine ⟨(injective_iff_map_eq_zero _).mpr fun p hp => ?_, fun z => ⟨(Ideal.Quotient.mk (vanishingIdeal {x} : Ideal (MvPolynomial σ k))) (C z), by simp⟩⟩ obtain ⟨q, rfl⟩ := Quotient.mk_surjective p rwa [Ideal.Quotient.lift_mk, ← mem_vanishingIdeal_singleton_iff, ← Quotient.eq_zero_iff_mem] at hp) rw [← bot_quotient_isMaximal_iff, RingEquiv.bot_maximal_iff this] exact bot_isMaximal theorem radical_le_vanishingIdeal_zeroLocus (I : Ideal (MvPolynomial σ k)) : I.radical ≤ vanishingIdeal (zeroLocus I) := by intro p hp x hx rw [← mem_vanishingIdeal_singleton_iff] rw [radical_eq_sInf] at hp refine (mem_sInf.mp hp) ⟨le_trans (le_vanishingIdeal_zeroLocus I) (vanishingIdeal_anti_mono fun y hy => hy.symm ▸ hx), IsMaximal.isPrime' _⟩ /-- The point in the prime spectrum associated to a given point -/ def pointToPoint (x : σ → k) : PrimeSpectrum (MvPolynomial σ k) := ⟨(vanishingIdeal {x} : Ideal (MvPolynomial σ k)), by infer_instance⟩ @[simp] theorem vanishingIdeal_pointToPoint (V : Set (σ → k)) : PrimeSpectrum.vanishingIdeal (pointToPoint '' V) = MvPolynomial.vanishingIdeal V := le_antisymm (fun p hp x hx => (((PrimeSpectrum.mem_vanishingIdeal _ _).1 hp) ⟨vanishingIdeal {x}, by infer_instance⟩ <| by exact ⟨x, ⟨hx, rfl⟩⟩) -- Porting note: tactic mode code compiles but term mode does not x rfl) fun p hp => (PrimeSpectrum.mem_vanishingIdeal _ _).2 fun I hI => let ⟨x, hx⟩ := hI hx.2 ▸ fun x' hx' => (Set.mem_singleton_iff.1 hx').symm ▸ hp x hx.1 theorem pointToPoint_zeroLocus_le (I : Ideal (MvPolynomial σ k)) : pointToPoint '' MvPolynomial.zeroLocus I ≤ PrimeSpectrum.zeroLocus ↑I := fun J hJ => let ⟨_, hx⟩ := hJ (le_trans (le_vanishingIdeal_zeroLocus I) (hx.2 ▸ vanishingIdeal_anti_mono (Set.singleton_subset_iff.2 hx.1)) : I ≤ J.asIdeal) variable [IsAlgClosed k] [Finite σ] theorem isMaximal_iff_eq_vanishingIdeal_singleton (I : Ideal (MvPolynomial σ k)) : I.IsMaximal ↔ ∃ x : σ → k, I = vanishingIdeal {x} := by cases nonempty_fintype σ refine ⟨fun hI => ?_, fun h => let ⟨x, hx⟩ := h hx.symm ▸ MvPolynomial.vanishingIdeal_singleton_isMaximal⟩ letI : I.IsMaximal := hI letI : Field (MvPolynomial σ k ⧸ I) := Quotient.field I let ϕ : k →+* MvPolynomial σ k ⧸ I := (Ideal.Quotient.mk I).comp C have hϕ : Function.Bijective ϕ := ⟨quotient_mk_comp_C_injective _ _ I hI.ne_top, IsAlgClosed.algebraMap_surjective_of_isIntegral' ϕ (MvPolynomial.comp_C_integral_of_surjective_of_jacobson _ Quotient.mk_surjective)⟩ obtain ⟨φ, hφ⟩ := Function.Surjective.hasRightInverse hϕ.2 let x : σ → k := fun s => φ ((Ideal.Quotient.mk I) (X s)) have hx : ∀ s : σ, ϕ (x s) = (Ideal.Quotient.mk I) (X s) := fun s => hφ ((Ideal.Quotient.mk I) (X s)) refine ⟨x, (IsMaximal.eq_of_le (by infer_instance) hI.ne_top ?_).symm⟩ intro p hp rw [← Quotient.eq_zero_iff_mem, map_mvPolynomial_eq_eval₂ (Ideal.Quotient.mk I) p, eval₂_eq'] rw [mem_vanishingIdeal_singleton_iff, eval_eq'] at hp simpa only [map_sum ϕ, ϕ.map_mul, map_prod ϕ, ϕ.map_pow, ϕ.map_zero, hx] using congr_arg ϕ hp /-- Main statement of the Nullstellensatz -/ @[simp] theorem vanishingIdeal_zeroLocus_eq_radical (I : Ideal (MvPolynomial σ k)) : vanishingIdeal (zeroLocus I) = I.radical := by rw [I.radical_eq_jacobson] refine le_antisymm (le_sInf ?_) fun p hp x hx => ?_ · rintro J ⟨hJI, hJ⟩ obtain ⟨x, hx⟩ := (isMaximal_iff_eq_vanishingIdeal_singleton J).1 hJ refine hx.symm ▸ vanishingIdeal_anti_mono fun y hy p hp => ?_ rw [← mem_vanishingIdeal_singleton_iff, Set.mem_singleton_iff.1 hy, ← hx] exact hJI hp · rw [← mem_vanishingIdeal_singleton_iff x p] refine (mem_sInf.mp hp) ⟨le_trans (le_vanishingIdeal_zeroLocus I) (vanishingIdeal_anti_mono fun y hy => hy.symm ▸ hx), MvPolynomial.vanishingIdeal_singleton_isMaximal⟩ -- Porting note: marked this as high priority to short cut simplifier @[simp (high)] theorem IsPrime.vanishingIdeal_zeroLocus (P : Ideal (MvPolynomial σ k)) [h : P.IsPrime] : vanishingIdeal (zeroLocus P) = P := Trans.trans (vanishingIdeal_zeroLocus_eq_radical P) h.radical end MvPolynomial
RingTheory\OrzechProperty.lean
/- Copyright (c) 2024 Jz Pan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jz Pan -/ import Mathlib.RingTheory.Finiteness import Mathlib.Logic.Equiv.TransferInstance /-! # Orzech property of rings In this file we define the following property of rings: - `OrzechProperty R` is a type class stating that `R` satisfies the following property: for any finitely generated `R`-module `M`, any surjective homomorphism `f : N → M` from a submodule `N` of `M` to `M` is injective. It was introduced in papers by Orzech [orzech1971], Djoković [djokovic1973] and Ribenboim [ribenboim1971], under the names `Π`-ring or `Π₁`-ring. It implies the strong rank condition (that is, the existence of an injective linear map `(Fin n → R) →ₗ[R] (Fin m → R)` implies `n ≤ m`) if the ring is nontrivial (see `Mathlib/LinearAlgebra/InvariantBasisNumber.lean`). It's proved in the above papers that - a left Noetherian ring (not necessarily commutative) satisfies the `OrzechProperty`, which in particular includes the division ring case (see `Mathlib/RingTheory/Noetherian.lean`); - a commutative ring satisfies the `OrzechProperty` (see `Mathlib/RingTheory/FiniteType.lean`). ## References * [Orzech, Morris. *Onto endomorphisms are isomorphisms*][orzech1971] * [Djoković, D. Ž. *Epimorphisms of modules which must be isomorphisms*][djokovic1973] * [Ribenboim, Paulo. *Épimorphismes de modules qui sont nécessairement des isomorphismes*][ribenboim1971] ## Tags free module, rank, Orzech property, (strong) rank condition, invariant basis number, IBN -/ universe u v w open Function variable (R : Type u) [Semiring R] /-- A ring `R` satisfies the Orzech property, if for any finitely generated `R`-module `M`, any surjective homomorphism `f : N → M` from a submodule `N` of `M` to `M` is injective. NOTE: In the definition we need to assume that `M` has the same universe level as `R`, but it in fact implies the universe polymorphic versions `OrzechProperty.injective_of_surjective_of_injective` and `OrzechProperty.injective_of_surjective_of_submodule`. -/ @[mk_iff] class OrzechProperty : Prop where injective_of_surjective_of_submodule' : ∀ {M : Type u} [AddCommMonoid M] [Module R M] [Module.Finite R M] {N : Submodule R M} (f : N →ₗ[R] M), Surjective f → Injective f namespace OrzechProperty variable {R} variable [OrzechProperty R] {M : Type v} [AddCommMonoid M] [Module R M] [Module.Finite R M] theorem injective_of_surjective_of_injective {N : Type w} [AddCommMonoid N] [Module R N] (i f : N →ₗ[R] M) (hi : Injective i) (hf : Surjective f) : Injective f := by obtain ⟨n, g, hg⟩ := Module.Finite.exists_fin' R M haveI := small_of_surjective hg letI := Equiv.addCommMonoid (equivShrink M).symm letI := Equiv.module R (equivShrink M).symm let j : Shrink.{u} M ≃ₗ[R] M := Equiv.linearEquiv R (equivShrink M).symm haveI := Module.Finite.equiv j.symm let i' := j.symm.toLinearMap ∘ₗ i replace hi : Injective i' := by simpa [i'] using hi let f' := j.symm.toLinearMap ∘ₗ f ∘ₗ (LinearEquiv.ofInjective i' hi).symm.toLinearMap replace hf : Surjective f' := by simpa [f'] using hf simpa [f'] using injective_of_surjective_of_submodule' f' hf theorem injective_of_surjective_of_submodule {N : Submodule R M} (f : N →ₗ[R] M) (hf : Surjective f) : Injective f := injective_of_surjective_of_injective N.subtype f N.injective_subtype hf theorem injective_of_surjective_endomorphism (f : M →ₗ[R] M) (hf : Surjective f) : Injective f := injective_of_surjective_of_injective _ f (LinearEquiv.refl _ _).injective hf theorem bijective_of_surjective_endomorphism (f : M →ₗ[R] M) (hf : Surjective f) : Bijective f := ⟨injective_of_surjective_endomorphism f hf, hf⟩ end OrzechProperty
RingTheory\Perfection.lean
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.CharP.Pi import Mathlib.Algebra.CharP.Quotient import Mathlib.Algebra.CharP.Subring import Mathlib.Algebra.Ring.Pi import Mathlib.Analysis.SpecialFunctions.Pow.NNReal import Mathlib.FieldTheory.Perfect import Mathlib.RingTheory.Localization.FractionRing import Mathlib.Algebra.Ring.Subring.Basic import Mathlib.RingTheory.Valuation.Integers /-! # Ring Perfection and Tilt In this file we define the perfection of a ring of characteristic p, and the tilt of a field given a valuation to `ℝ≥0`. ## TODO Define the valuation on the tilt, and define a characteristic predicate for the tilt. -/ universe u₁ u₂ u₃ u₄ open scoped NNReal /-- The perfection of a monoid `M`, defined to be the projective limit of `M` using the `p`-th power maps `M → M` indexed by the natural numbers, implemented as `{ f : ℕ → M | ∀ n, f (n + 1) ^ p = f n }`. -/ def Monoid.perfection (M : Type u₁) [CommMonoid M] (p : ℕ) : Submonoid (ℕ → M) where carrier := { f | ∀ n, f (n + 1) ^ p = f n } one_mem' _ := one_pow _ mul_mem' hf hg n := (mul_pow _ _ _).trans <| congr_arg₂ _ (hf n) (hg n) /-- The perfection of a ring `R` with characteristic `p`, as a subsemiring, defined to be the projective limit of `R` using the Frobenius maps `R → R` indexed by the natural numbers, implemented as `{ f : ℕ → R | ∀ n, f (n + 1) ^ p = f n }`. -/ def Ring.perfectionSubsemiring (R : Type u₁) [CommSemiring R] (p : ℕ) [hp : Fact p.Prime] [CharP R p] : Subsemiring (ℕ → R) := { Monoid.perfection R p with zero_mem' := fun _ ↦ zero_pow hp.1.ne_zero add_mem' := fun hf hg n => (frobenius_add R p _ _).trans <| congr_arg₂ _ (hf n) (hg n) } /-- The perfection of a ring `R` with characteristic `p`, as a subring, defined to be the projective limit of `R` using the Frobenius maps `R → R` indexed by the natural numbers, implemented as `{ f : ℕ → R | ∀ n, f (n + 1) ^ p = f n }`. -/ def Ring.perfectionSubring (R : Type u₁) [CommRing R] (p : ℕ) [hp : Fact p.Prime] [CharP R p] : Subring (ℕ → R) := (Ring.perfectionSubsemiring R p).toSubring fun n => by simp_rw [← frobenius_def, Pi.neg_apply, Pi.one_apply, RingHom.map_neg, RingHom.map_one] /-- The perfection of a ring `R` with characteristic `p`, defined to be the projective limit of `R` using the Frobenius maps `R → R` indexed by the natural numbers, implemented as `{f : ℕ → R // ∀ n, f (n + 1) ^ p = f n}`. -/ def Ring.Perfection (R : Type u₁) [CommSemiring R] (p : ℕ) : Type u₁ := { f // ∀ n : ℕ, (f : ℕ → R) (n + 1) ^ p = f n } namespace Perfection variable (R : Type u₁) [CommSemiring R] (p : ℕ) [hp : Fact p.Prime] [CharP R p] instance commSemiring : CommSemiring (Ring.Perfection R p) := (Ring.perfectionSubsemiring R p).toCommSemiring instance charP : CharP (Ring.Perfection R p) p := CharP.subsemiring (ℕ → R) p (Ring.perfectionSubsemiring R p) instance ring (R : Type u₁) [CommRing R] [CharP R p] : Ring (Ring.Perfection R p) := (Ring.perfectionSubring R p).toRing instance commRing (R : Type u₁) [CommRing R] [CharP R p] : CommRing (Ring.Perfection R p) := (Ring.perfectionSubring R p).toCommRing instance : Inhabited (Ring.Perfection R p) := ⟨0⟩ /-- The `n`-th coefficient of an element of the perfection. -/ def coeff (n : ℕ) : Ring.Perfection R p →+* R where toFun f := f.1 n map_one' := rfl map_mul' _ _ := rfl map_zero' := rfl map_add' _ _ := rfl variable {R p} @[ext] theorem ext {f g : Ring.Perfection R p} (h : ∀ n, coeff R p n f = coeff R p n g) : f = g := Subtype.eq <| funext h variable (R p) /-- The `p`-th root of an element of the perfection. -/ def pthRoot : Ring.Perfection R p →+* Ring.Perfection R p where toFun f := ⟨fun n => coeff R p (n + 1) f, fun _ => f.2 _⟩ map_one' := rfl map_mul' _ _ := rfl map_zero' := rfl map_add' _ _ := rfl variable {R p} @[simp] theorem coeff_mk (f : ℕ → R) (hf) (n : ℕ) : coeff R p n ⟨f, hf⟩ = f n := rfl theorem coeff_pthRoot (f : Ring.Perfection R p) (n : ℕ) : coeff R p n (pthRoot R p f) = coeff R p (n + 1) f := rfl theorem coeff_pow_p (f : Ring.Perfection R p) (n : ℕ) : coeff R p (n + 1) (f ^ p) = coeff R p n f := by rw [RingHom.map_pow]; exact f.2 n theorem coeff_pow_p' (f : Ring.Perfection R p) (n : ℕ) : coeff R p (n + 1) f ^ p = coeff R p n f := f.2 n theorem coeff_frobenius (f : Ring.Perfection R p) (n : ℕ) : coeff R p (n + 1) (frobenius _ p f) = coeff R p n f := by apply coeff_pow_p f n -- `coeff_pow_p f n` also works but is slow! theorem coeff_iterate_frobenius (f : Ring.Perfection R p) (n m : ℕ) : coeff R p (n + m) ((frobenius _ p)^[m] f) = coeff R p n f := Nat.recOn m rfl fun m ih => by erw [Function.iterate_succ_apply', coeff_frobenius, ih] theorem coeff_iterate_frobenius' (f : Ring.Perfection R p) (n m : ℕ) (hmn : m ≤ n) : coeff R p n ((frobenius _ p)^[m] f) = coeff R p (n - m) f := Eq.symm <| (coeff_iterate_frobenius _ _ m).symm.trans <| (tsub_add_cancel_of_le hmn).symm ▸ rfl theorem pthRoot_frobenius : (pthRoot R p).comp (frobenius _ p) = RingHom.id _ := RingHom.ext fun x => ext fun n => by rw [RingHom.comp_apply, RingHom.id_apply, coeff_pthRoot, coeff_frobenius] theorem frobenius_pthRoot : (frobenius _ p).comp (pthRoot R p) = RingHom.id _ := RingHom.ext fun x => ext fun n => by rw [RingHom.comp_apply, RingHom.id_apply, RingHom.map_frobenius, coeff_pthRoot, ← @RingHom.map_frobenius (Ring.Perfection R p) _ R, coeff_frobenius] theorem coeff_add_ne_zero {f : Ring.Perfection R p} {n : ℕ} (hfn : coeff R p n f ≠ 0) (k : ℕ) : coeff R p (n + k) f ≠ 0 := Nat.recOn k hfn fun k ih h => ih <| by erw [← coeff_pow_p, RingHom.map_pow, h, zero_pow hp.1.ne_zero] theorem coeff_ne_zero_of_le {f : Ring.Perfection R p} {m n : ℕ} (hfm : coeff R p m f ≠ 0) (hmn : m ≤ n) : coeff R p n f ≠ 0 := let ⟨k, hk⟩ := Nat.exists_eq_add_of_le hmn hk.symm ▸ coeff_add_ne_zero hfm k variable (R p) instance perfectRing : PerfectRing (Ring.Perfection R p) p where bijective_frobenius := Function.bijective_iff_has_inverse.mpr ⟨pthRoot R p, DFunLike.congr_fun <| @frobenius_pthRoot R _ p _ _, DFunLike.congr_fun <| @pthRoot_frobenius R _ p _ _⟩ /-- Given rings `R` and `S` of characteristic `p`, with `R` being perfect, any homomorphism `R →+* S` can be lifted to a homomorphism `R →+* Perfection S p`. -/ @[simps] noncomputable def lift (R : Type u₁) [CommSemiring R] [CharP R p] [PerfectRing R p] (S : Type u₂) [CommSemiring S] [CharP S p] : (R →+* S) ≃ (R →+* Ring.Perfection S p) where toFun f := { toFun := fun r => ⟨fun n => f (((frobeniusEquiv R p).symm : R →+* R)^[n] r), fun n => by erw [← f.map_pow, Function.iterate_succ_apply', frobeniusEquiv_symm_pow_p]⟩ map_one' := ext fun n => (congr_arg f <| iterate_map_one _ _).trans f.map_one map_mul' := fun x y => ext fun n => (congr_arg f <| iterate_map_mul _ _ _ _).trans <| f.map_mul _ _ map_zero' := ext fun n => (congr_arg f <| iterate_map_zero _ _).trans f.map_zero map_add' := fun x y => ext fun n => (congr_arg f <| iterate_map_add _ _ _ _).trans <| f.map_add _ _ } invFun := RingHom.comp <| coeff S p 0 left_inv f := RingHom.ext fun r => rfl right_inv f := RingHom.ext fun r => ext fun n => show coeff S p 0 (f (((frobeniusEquiv R p).symm)^[n] r)) = coeff S p n (f r) by rw [← coeff_iterate_frobenius _ 0 n, zero_add, ← RingHom.map_iterate_frobenius, Function.RightInverse.iterate (frobenius_apply_frobeniusEquiv_symm R p) n] theorem hom_ext {R : Type u₁} [CommSemiring R] [CharP R p] [PerfectRing R p] {S : Type u₂} [CommSemiring S] [CharP S p] {f g : R →+* Ring.Perfection S p} (hfg : ∀ x, coeff S p 0 (f x) = coeff S p 0 (g x)) : f = g := (lift p R S).symm.injective <| RingHom.ext hfg variable {R} {S : Type u₂} [CommSemiring S] [CharP S p] /-- A ring homomorphism `R →+* S` induces `Perfection R p →+* Perfection S p`. -/ @[simps] def map (φ : R →+* S) : Ring.Perfection R p →+* Ring.Perfection S p where toFun f := ⟨fun n => φ (coeff R p n f), fun n => by rw [← φ.map_pow, coeff_pow_p']⟩ map_one' := Subtype.eq <| funext fun _ => φ.map_one map_mul' f g := Subtype.eq <| funext fun n => φ.map_mul _ _ map_zero' := Subtype.eq <| funext fun _ => φ.map_zero map_add' f g := Subtype.eq <| funext fun n => φ.map_add _ _ theorem coeff_map (φ : R →+* S) (f : Ring.Perfection R p) (n : ℕ) : coeff S p n (map p φ f) = φ (coeff R p n f) := rfl end Perfection /-- A perfection map to a ring of characteristic `p` is a map that is isomorphic to its perfection. -/ -- @[nolint has_nonempty_instance] -- Porting note(#5171): This linter does not exist yet. structure PerfectionMap (p : ℕ) [Fact p.Prime] {R : Type u₁} [CommSemiring R] [CharP R p] {P : Type u₂} [CommSemiring P] [CharP P p] [PerfectRing P p] (π : P →+* R) : Prop where injective : ∀ ⦃x y : P⦄, (∀ n, π (((frobeniusEquiv P p).symm)^[n] x) = π (((frobeniusEquiv P p).symm)^[n] y)) → x = y surjective : ∀ f : ℕ → R, (∀ n, f (n + 1) ^ p = f n) → ∃ x : P, ∀ n, π (((frobeniusEquiv P p).symm)^[n] x) = f n namespace PerfectionMap variable {p : ℕ} [Fact p.Prime] variable {R : Type u₁} [CommSemiring R] [CharP R p] variable {P : Type u₃} [CommSemiring P] [CharP P p] [PerfectRing P p] /-- Create a `PerfectionMap` from an isomorphism to the perfection. -/ @[simps] theorem mk' {f : P →+* R} (g : P ≃+* Ring.Perfection R p) (hfg : Perfection.lift p P R f = g) : PerfectionMap p f := { injective := fun x y hxy => g.injective <| (RingHom.ext_iff.1 hfg x).symm.trans <| Eq.symm <| (RingHom.ext_iff.1 hfg y).symm.trans <| Perfection.ext fun n => (hxy n).symm surjective := fun y hy => let ⟨x, hx⟩ := g.surjective ⟨y, hy⟩ ⟨x, fun n => show Perfection.coeff R p n (Perfection.lift p P R f x) = Perfection.coeff R p n ⟨y, hy⟩ by simp [hfg, hx]⟩ } variable (p R P) /-- The canonical perfection map from the perfection of a ring. -/ theorem of : PerfectionMap p (Perfection.coeff R p 0) := mk' (RingEquiv.refl _) <| (Equiv.apply_eq_iff_eq_symm_apply _).2 rfl /-- For a perfect ring, it itself is the perfection. -/ theorem id [PerfectRing R p] : PerfectionMap p (RingHom.id R) := { injective := fun x y hxy => hxy 0 surjective := fun f hf => ⟨f 0, fun n => show ((frobeniusEquiv R p).symm)^[n] (f 0) = f n from Nat.recOn n rfl fun n ih => injective_pow_p R p <| by rw [Function.iterate_succ_apply', frobeniusEquiv_symm_pow_p, ih, hf]⟩ } variable {p R P} /-- A perfection map induces an isomorphism to the perfection. -/ noncomputable def equiv {π : P →+* R} (m : PerfectionMap p π) : P ≃+* Ring.Perfection R p := RingEquiv.ofBijective (Perfection.lift p P R π) ⟨fun _ _ hxy => m.injective fun n => (congr_arg (Perfection.coeff R p n) hxy : _), fun f => let ⟨x, hx⟩ := m.surjective f.1 f.2 ⟨x, Perfection.ext <| hx⟩⟩ theorem equiv_apply {π : P →+* R} (m : PerfectionMap p π) (x : P) : m.equiv x = Perfection.lift p P R π x := rfl theorem comp_equiv {π : P →+* R} (m : PerfectionMap p π) (x : P) : Perfection.coeff R p 0 (m.equiv x) = π x := rfl theorem comp_equiv' {π : P →+* R} (m : PerfectionMap p π) : (Perfection.coeff R p 0).comp ↑m.equiv = π := RingHom.ext fun _ => rfl theorem comp_symm_equiv {π : P →+* R} (m : PerfectionMap p π) (f : Ring.Perfection R p) : π (m.equiv.symm f) = Perfection.coeff R p 0 f := (m.comp_equiv _).symm.trans <| congr_arg _ <| m.equiv.apply_symm_apply f theorem comp_symm_equiv' {π : P →+* R} (m : PerfectionMap p π) : π.comp ↑m.equiv.symm = Perfection.coeff R p 0 := RingHom.ext m.comp_symm_equiv variable (p R P) /-- Given rings `R` and `S` of characteristic `p`, with `R` being perfect, any homomorphism `R →+* S` can be lifted to a homomorphism `R →+* P`, where `P` is any perfection of `S`. -/ @[simps] noncomputable def lift [PerfectRing R p] (S : Type u₂) [CommSemiring S] [CharP S p] (P : Type u₃) [CommSemiring P] [CharP P p] [PerfectRing P p] (π : P →+* S) (m : PerfectionMap p π) : (R →+* S) ≃ (R →+* P) where toFun f := RingHom.comp ↑m.equiv.symm <| Perfection.lift p R S f invFun f := π.comp f left_inv f := by simp_rw [← RingHom.comp_assoc, comp_symm_equiv'] exact (Perfection.lift p R S).symm_apply_apply f right_inv f := by exact RingHom.ext fun x => m.equiv.injective <| (m.equiv.apply_symm_apply _).trans <| show Perfection.lift p R S (π.comp f) x = RingHom.comp (↑m.equiv) f x from RingHom.ext_iff.1 (by rw [Equiv.apply_eq_iff_eq_symm_apply]; rfl) _ variable {R p} theorem hom_ext [PerfectRing R p] {S : Type u₂} [CommSemiring S] [CharP S p] {P : Type u₃} [CommSemiring P] [CharP P p] [PerfectRing P p] (π : P →+* S) (m : PerfectionMap p π) {f g : R →+* P} (hfg : ∀ x, π (f x) = π (g x)) : f = g := (lift p R S P π m).symm.injective <| RingHom.ext hfg variable {P} (p) variable {S : Type u₂} [CommSemiring S] [CharP S p] variable {Q : Type u₄} [CommSemiring Q] [CharP Q p] [PerfectRing Q p] /-- A ring homomorphism `R →+* S` induces `P →+* Q`, a map of the respective perfections. -/ @[nolint unusedArguments] noncomputable def map {π : P →+* R} (_ : PerfectionMap p π) {σ : Q →+* S} (n : PerfectionMap p σ) (φ : R →+* S) : P →+* Q := lift p P S Q σ n <| φ.comp π theorem comp_map {π : P →+* R} (m : PerfectionMap p π) {σ : Q →+* S} (n : PerfectionMap p σ) (φ : R →+* S) : σ.comp (map p m n φ) = φ.comp π := (lift p P S Q σ n).symm_apply_apply _ theorem map_map {π : P →+* R} (m : PerfectionMap p π) {σ : Q →+* S} (n : PerfectionMap p σ) (φ : R →+* S) (x : P) : σ (map p m n φ x) = φ (π x) := RingHom.ext_iff.1 (comp_map p m n φ) x theorem map_eq_map (φ : R →+* S) : map p (of p R) (of p S) φ = Perfection.map p φ := hom_ext _ (of p S) fun f => by rw [map_map, Perfection.coeff_map] end PerfectionMap section Perfectoid variable (K : Type u₁) [Field K] (v : Valuation K ℝ≥0) variable (O : Type u₂) [CommRing O] [Algebra O K] (hv : v.Integers O) variable (p : ℕ) -- Porting note: Specified all arguments explicitly /-- `O/(p)` for `O`, ring of integers of `K`. -/ @[nolint unusedArguments] -- Porting note(#5171): removed `nolint has_nonempty_instance` def ModP (K : Type u₁) [Field K] (v : Valuation K ℝ≥0) (O : Type u₂) [CommRing O] [Algebra O K] (_ : v.Integers O) (p : ℕ) := O ⧸ (Ideal.span {(p : O)} : Ideal O) variable [hp : Fact p.Prime] [hvp : Fact (v p ≠ 1)] namespace ModP instance commRing : CommRing (ModP K v O hv p) := Ideal.Quotient.commRing (Ideal.span {(p : O)} : Ideal O) instance charP : CharP (ModP K v O hv p) p := CharP.quotient O p <| mt hv.one_of_isUnit <| (map_natCast (algebraMap O K) p).symm ▸ hvp.1 instance : Nontrivial (ModP K v O hv p) := CharP.nontrivial_of_char_ne_one hp.1.ne_one section Classical attribute [local instance] Classical.dec /-- For a field `K` with valuation `v : K → ℝ≥0` and ring of integers `O`, a function `O/(p) → ℝ≥0` that sends `0` to `0` and `x + (p)` to `v(x)` as long as `x ∉ (p)`. -/ noncomputable def preVal (x : ModP K v O hv p) : ℝ≥0 := if x = 0 then 0 else v (algebraMap O K x.out') variable {K v O hv p} theorem preVal_mk {x : O} (hx : (Ideal.Quotient.mk _ x : ModP K v O hv p) ≠ 0) : preVal K v O hv p (Ideal.Quotient.mk _ x) = v (algebraMap O K x) := by obtain ⟨r, hr⟩ : ∃ (a : O), a * (p : O) = (Quotient.mk'' x).out' - x := Ideal.mem_span_singleton'.1 <| Ideal.Quotient.eq.1 <| Quotient.sound' <| Quotient.mk_out' _ refine (if_neg hx).trans (v.map_eq_of_sub_lt <| lt_of_not_le ?_) erw [← RingHom.map_sub, ← hr, hv.le_iff_dvd] exact fun hprx => hx (Ideal.Quotient.eq_zero_iff_mem.2 <| Ideal.mem_span_singleton.2 <| dvd_of_mul_left_dvd hprx) theorem preVal_zero : preVal K v O hv p 0 = 0 := if_pos rfl theorem preVal_mul {x y : ModP K v O hv p} (hxy0 : x * y ≠ 0) : preVal K v O hv p (x * y) = preVal K v O hv p x * preVal K v O hv p y := by have hx0 : x ≠ 0 := mt (by rintro rfl; rw [zero_mul]) hxy0 have hy0 : y ≠ 0 := mt (by rintro rfl; rw [mul_zero]) hxy0 obtain ⟨r, rfl⟩ := Ideal.Quotient.mk_surjective x obtain ⟨s, rfl⟩ := Ideal.Quotient.mk_surjective y rw [← map_mul (Ideal.Quotient.mk (Ideal.span {↑p})) r s] at hxy0 ⊢ rw [preVal_mk hx0, preVal_mk hy0, preVal_mk hxy0, RingHom.map_mul, v.map_mul] theorem preVal_add (x y : ModP K v O hv p) : preVal K v O hv p (x + y) ≤ max (preVal K v O hv p x) (preVal K v O hv p y) := by by_cases hx0 : x = 0 · rw [hx0, zero_add]; exact le_max_right _ _ by_cases hy0 : y = 0 · rw [hy0, add_zero]; exact le_max_left _ _ by_cases hxy0 : x + y = 0 · rw [hxy0, preVal_zero]; exact zero_le _ obtain ⟨r, rfl⟩ := Ideal.Quotient.mk_surjective x obtain ⟨s, rfl⟩ := Ideal.Quotient.mk_surjective y rw [← map_add (Ideal.Quotient.mk (Ideal.span {↑p})) r s] at hxy0 ⊢ rw [preVal_mk hx0, preVal_mk hy0, preVal_mk hxy0, RingHom.map_add]; exact v.map_add _ _ theorem v_p_lt_preVal {x : ModP K v O hv p} : v p < preVal K v O hv p x ↔ x ≠ 0 := by refine ⟨fun h hx => by rw [hx, preVal_zero] at h; exact not_lt_zero' h, fun h => lt_of_not_le fun hp => h ?_⟩ obtain ⟨r, rfl⟩ := Ideal.Quotient.mk_surjective x rw [preVal_mk h, ← map_natCast (algebraMap O K) p, hv.le_iff_dvd] at hp rw [Ideal.Quotient.eq_zero_iff_mem, Ideal.mem_span_singleton]; exact hp theorem preVal_eq_zero {x : ModP K v O hv p} : preVal K v O hv p x = 0 ↔ x = 0 := ⟨fun hvx => by_contradiction fun hx0 : x ≠ 0 => by rw [← v_p_lt_preVal, hvx] at hx0 exact not_lt_zero' hx0, fun hx => hx.symm ▸ preVal_zero⟩ variable (hv) -- Porting note: Originally `(hv hvp)`. Removed `(hvp)` because it caused an error. theorem v_p_lt_val {x : O} : v p < v (algebraMap O K x) ↔ (Ideal.Quotient.mk _ x : ModP K v O hv p) ≠ 0 := by rw [lt_iff_not_le, not_iff_not, ← map_natCast (algebraMap O K) p, hv.le_iff_dvd, Ideal.Quotient.eq_zero_iff_mem, Ideal.mem_span_singleton] open NNReal variable {hv} -- Porting note: Originally `{hv} (hvp)`. Removed `(hvp)` because it caused an error. theorem mul_ne_zero_of_pow_p_ne_zero {x y : ModP K v O hv p} (hx : x ^ p ≠ 0) (hy : y ^ p ≠ 0) : x * y ≠ 0 := by obtain ⟨r, rfl⟩ := Ideal.Quotient.mk_surjective x obtain ⟨s, rfl⟩ := Ideal.Quotient.mk_surjective y have h1p : (0 : ℝ) < 1 / p := one_div_pos.2 (Nat.cast_pos.2 hp.1.pos) rw [← (Ideal.Quotient.mk (Ideal.span {(p : O)})).map_mul] rw [← (Ideal.Quotient.mk (Ideal.span {(p : O)})).map_pow] at hx hy rw [← v_p_lt_val hv] at hx hy ⊢ rw [RingHom.map_pow, v.map_pow, ← rpow_lt_rpow_iff h1p, ← rpow_natCast, ← rpow_mul, mul_one_div_cancel (Nat.cast_ne_zero.2 hp.1.ne_zero : (p : ℝ) ≠ 0), rpow_one] at hx hy rw [RingHom.map_mul, v.map_mul]; refine lt_of_le_of_lt ?_ (mul_lt_mul₀ hx hy) by_cases hvp : v p = 0 · rw [hvp]; exact zero_le _ replace hvp := zero_lt_iff.2 hvp conv_lhs => rw [← rpow_one (v p)] rw [← rpow_add (ne_of_gt hvp)] refine rpow_le_rpow_of_exponent_ge hvp (map_natCast (algebraMap O K) p ▸ hv.2 _) ?_ rw [← add_div, div_le_one (Nat.cast_pos.2 hp.1.pos : 0 < (p : ℝ))]; exact mod_cast hp.1.two_le end Classical end ModP /-- Perfection of `O/(p)` where `O` is the ring of integers of `K`. -/ -- @[nolint has_nonempty_instance] -- Porting note(#5171): This linter does not exist yet. def PreTilt := Ring.Perfection (ModP K v O hv p) p namespace PreTilt instance : CommRing (PreTilt K v O hv p) := Perfection.commRing p _ instance : CharP (PreTilt K v O hv p) p := Perfection.charP (ModP K v O hv p) p section Classical open scoped Classical open Perfection /-- The valuation `Perfection(O/(p)) → ℝ≥0` as a function. Given `f ∈ Perfection(O/(p))`, if `f = 0` then output `0`; otherwise output `preVal(f(n))^(p^n)` for any `n` such that `f(n) ≠ 0`. -/ noncomputable def valAux (f : PreTilt K v O hv p) : ℝ≥0 := if h : ∃ n, coeff _ _ n f ≠ 0 then ModP.preVal K v O hv p (coeff _ _ (Nat.find h) f) ^ p ^ Nat.find h else 0 variable {K v O hv p} theorem coeff_nat_find_add_ne_zero {f : PreTilt K v O hv p} {h : ∃ n, coeff _ _ n f ≠ 0} (k : ℕ) : coeff _ _ (Nat.find h + k) f ≠ 0 := coeff_add_ne_zero (Nat.find_spec h) k theorem valAux_eq {f : PreTilt K v O hv p} {n : ℕ} (hfn : coeff _ _ n f ≠ 0) : valAux K v O hv p f = ModP.preVal K v O hv p (coeff _ _ n f) ^ p ^ n := by have h : ∃ n, coeff _ _ n f ≠ 0 := ⟨n, hfn⟩ rw [valAux, dif_pos h] obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le (Nat.find_min' h hfn) induction' k with k ih · rfl obtain ⟨x, hx⟩ := Ideal.Quotient.mk_surjective (coeff (ModP K v O hv p) p (Nat.find h + k + 1) f) have h1 : (Ideal.Quotient.mk _ x : ModP K v O hv p) ≠ 0 := hx.symm ▸ hfn have h2 : (Ideal.Quotient.mk _ (x ^ p) : ModP K v O hv p) ≠ 0 := by erw [RingHom.map_pow, hx, ← RingHom.map_pow, coeff_pow_p] exact coeff_nat_find_add_ne_zero k erw [ih (coeff_nat_find_add_ne_zero k), ← hx, ← coeff_pow_p, RingHom.map_pow, ← hx, ← RingHom.map_pow, ModP.preVal_mk h1, ModP.preVal_mk h2, RingHom.map_pow, v.map_pow, ← pow_mul, pow_succ'] rfl theorem valAux_zero : valAux K v O hv p 0 = 0 := dif_neg fun ⟨_, hn⟩ => hn rfl theorem valAux_one : valAux K v O hv p 1 = 1 := (valAux_eq <| show coeff (ModP K v O hv p) p 0 1 ≠ 0 from one_ne_zero).trans <| by rw [pow_zero, pow_one, RingHom.map_one, ← (Ideal.Quotient.mk _).map_one, ModP.preVal_mk, RingHom.map_one, v.map_one] change (1 : ModP K v O hv p) ≠ 0 exact one_ne_zero theorem valAux_mul (f g : PreTilt K v O hv p) : valAux K v O hv p (f * g) = valAux K v O hv p f * valAux K v O hv p g := by by_cases hf : f = 0 · rw [hf, zero_mul, valAux_zero, zero_mul] by_cases hg : g = 0 · rw [hg, mul_zero, valAux_zero, mul_zero] obtain ⟨m, hm⟩ : ∃ n, coeff _ _ n f ≠ 0 := not_forall.1 fun h => hf <| Perfection.ext h obtain ⟨n, hn⟩ : ∃ n, coeff _ _ n g ≠ 0 := not_forall.1 fun h => hg <| Perfection.ext h replace hm := coeff_ne_zero_of_le hm (le_max_left m n) replace hn := coeff_ne_zero_of_le hn (le_max_right m n) have hfg : coeff _ _ (max m n + 1) (f * g) ≠ 0 := by rw [RingHom.map_mul] refine ModP.mul_ne_zero_of_pow_p_ne_zero ?_ ?_ · rw [← RingHom.map_pow, coeff_pow_p f]; assumption · rw [← RingHom.map_pow, coeff_pow_p g]; assumption rw [valAux_eq (coeff_add_ne_zero hm 1), valAux_eq (coeff_add_ne_zero hn 1), valAux_eq hfg] rw [RingHom.map_mul] at hfg ⊢; rw [ModP.preVal_mul hfg, mul_pow] theorem valAux_add (f g : PreTilt K v O hv p) : valAux K v O hv p (f + g) ≤ max (valAux K v O hv p f) (valAux K v O hv p g) := by by_cases hf : f = 0 · rw [hf, zero_add, valAux_zero, max_eq_right]; exact zero_le _ by_cases hg : g = 0 · rw [hg, add_zero, valAux_zero, max_eq_left]; exact zero_le _ by_cases hfg : f + g = 0 · rw [hfg, valAux_zero]; exact zero_le _ replace hf : ∃ n, coeff _ _ n f ≠ 0 := not_forall.1 fun h => hf <| Perfection.ext h replace hg : ∃ n, coeff _ _ n g ≠ 0 := not_forall.1 fun h => hg <| Perfection.ext h replace hfg : ∃ n, coeff _ _ n (f + g) ≠ 0 := not_forall.1 fun h => hfg <| Perfection.ext h obtain ⟨m, hm⟩ := hf; obtain ⟨n, hn⟩ := hg; obtain ⟨k, hk⟩ := hfg replace hm := coeff_ne_zero_of_le hm (le_trans (le_max_left m n) (le_max_left _ k)) replace hn := coeff_ne_zero_of_le hn (le_trans (le_max_right m n) (le_max_left _ k)) replace hk := coeff_ne_zero_of_le hk (le_max_right (max m n) k) rw [valAux_eq hm, valAux_eq hn, valAux_eq hk, RingHom.map_add] cases' le_max_iff.1 (ModP.preVal_add (coeff _ _ (max (max m n) k) f) (coeff _ _ (max (max m n) k) g)) with h h · exact le_max_of_le_left (pow_le_pow_left' h _) · exact le_max_of_le_right (pow_le_pow_left' h _) variable (K v O hv p) /-- The valuation `Perfection(O/(p)) → ℝ≥0`. Given `f ∈ Perfection(O/(p))`, if `f = 0` then output `0`; otherwise output `preVal(f(n))^(p^n)` for any `n` such that `f(n) ≠ 0`. -/ noncomputable def val : Valuation (PreTilt K v O hv p) ℝ≥0 where toFun := valAux K v O hv p map_one' := valAux_one map_mul' := valAux_mul map_zero' := valAux_zero map_add_le_max' := valAux_add variable {K v O hv p} theorem map_eq_zero {f : PreTilt K v O hv p} : val K v O hv p f = 0 ↔ f = 0 := by by_cases hf0 : f = 0 · rw [hf0]; exact iff_of_true (Valuation.map_zero _) rfl obtain ⟨n, hn⟩ : ∃ n, coeff _ _ n f ≠ 0 := not_forall.1 fun h => hf0 <| Perfection.ext h show valAux K v O hv p f = 0 ↔ f = 0; refine iff_of_false (fun hvf => hn ?_) hf0 rw [valAux_eq hn] at hvf; replace hvf := pow_eq_zero hvf; rwa [ModP.preVal_eq_zero] at hvf end Classical instance : IsDomain (PreTilt K v O hv p) := by haveI : Nontrivial (PreTilt K v O hv p) := ⟨(CharP.nontrivial_of_char_ne_one hp.1.ne_one).1⟩ haveI : NoZeroDivisors (PreTilt K v O hv p) := ⟨fun hfg => by simp_rw [← map_eq_zero] at hfg ⊢; contrapose! hfg; rw [Valuation.map_mul] exact mul_ne_zero hfg.1 hfg.2⟩ exact NoZeroDivisors.to_isDomain _ end PreTilt /-- The tilt of a field, as defined in Perfectoid Spaces by Peter Scholze, as in [scholze2011perfectoid]. Given a field `K` with valuation `K → ℝ≥0` and ring of integers `O`, this is implemented as the fraction field of the perfection of `O/(p)`. -/ -- @[nolint has_nonempty_instance] -- Porting note(#5171): This linter does not exist yet. def Tilt := FractionRing (PreTilt K v O hv p) namespace Tilt noncomputable instance : Field (Tilt K v O hv p) := FractionRing.field _ end Tilt end Perfectoid
RingTheory\PiTensorProduct.lean
/- Copyright (c) 2024 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jujian Zhang -/ import Mathlib.LinearAlgebra.PiTensorProduct import Mathlib.Algebra.Algebra.Bilinear import Mathlib.Algebra.Algebra.Equiv import Mathlib.Data.Finset.NoncommProd /-! # Tensor product of `R`-algebras and rings If `(Aᵢ)` is a family of `R`-algebras then the `R`-tensor product `⨂ᵢ Aᵢ` is an `R`-algebra as well with structure map defined by `r ↦ r • 1`. In particular if we take `R` to be `ℤ`, then this collapses into the tensor product of rings. -/ open TensorProduct Function variable {ι R' R : Type*} {A : ι → Type*} namespace PiTensorProduct noncomputable section AddCommMonoidWithOne variable [CommSemiring R] [∀ i, AddCommMonoidWithOne (A i)] [∀ i, Module R (A i)] instance instOne : One (⨂[R] i, A i) where one := tprod R 1 lemma one_def : 1 = tprod R (1 : Π i, A i) := rfl instance instAddCommMonoidWithOne : AddCommMonoidWithOne (⨂[R] i, A i) where __ := inferInstanceAs (AddCommMonoid (⨂[R] i, A i)) __ := instOne end AddCommMonoidWithOne noncomputable section NonUnitalNonAssocSemiring variable [CommSemiring R] [∀ i, NonUnitalNonAssocSemiring (A i)] variable [∀ i, Module R (A i)] [∀ i, SMulCommClass R (A i) (A i)] [∀ i, IsScalarTower R (A i) (A i)] attribute [aesop safe] mul_add mul_smul_comm smul_mul_assoc add_mul in /-- The multiplication in tensor product of rings is induced by `(xᵢ) * (yᵢ) = (xᵢ * yᵢ)` -/ def mul : (⨂[R] i, A i) →ₗ[R] (⨂[R] i, A i) →ₗ[R] (⨂[R] i, A i) := PiTensorProduct.piTensorHomMap₂ <| tprod R fun _ ↦ LinearMap.mul _ _ @[simp] lemma mul_tprod_tprod (x y : (i : ι) → A i) : mul (tprod R x) (tprod R y) = tprod R (x * y) := by simp only [mul, piTensorHomMap₂_tprod_tprod_tprod, LinearMap.mul_apply', Pi.mul_def] instance instMul : Mul (⨂[R] i, A i) where mul x y := mul x y lemma mul_def (x y : ⨂[R] i, A i) : x * y = mul x y := rfl @[simp] lemma tprod_mul_tprod (x y : (i : ι) → A i) : tprod R x * tprod R y = tprod R (x * y) := mul_tprod_tprod x y theorem _root_.SemiconjBy.tprod {a₁ a₂ a₃ : Π i, A i} (ha : SemiconjBy a₁ a₂ a₃) : SemiconjBy (tprod R a₁) (tprod R a₂) (tprod R a₃) := by rw [SemiconjBy, tprod_mul_tprod, tprod_mul_tprod, ha] nonrec theorem _root_.Commute.tprod {a₁ a₂ : Π i, A i} (ha : Commute a₁ a₂) : Commute (tprod R a₁) (tprod R a₂) := ha.tprod lemma smul_tprod_mul_smul_tprod (r s : R) (x y : Π i, A i) : (r • tprod R x) * (s • tprod R y) = (r * s) • tprod R (x * y) := by simp only [mul_def, map_smul, LinearMap.smul_apply, mul_tprod_tprod, mul_comm r s, mul_smul] instance instNonUnitalNonAssocSemiring : NonUnitalNonAssocSemiring (⨂[R] i, A i) where __ := instMul __ := inferInstanceAs (AddCommMonoid (⨂[R] i, A i)) left_distrib _ _ _ := (mul _).map_add _ _ right_distrib _ _ _ := mul.map_add₂ _ _ _ zero_mul _ := mul.map_zero₂ _ mul_zero _ := map_zero (mul _) end NonUnitalNonAssocSemiring noncomputable section NonAssocSemiring variable [CommSemiring R] [∀ i, NonAssocSemiring (A i)] variable [∀ i, Module R (A i)] [∀ i, SMulCommClass R (A i) (A i)] [∀ i, IsScalarTower R (A i) (A i)] protected lemma one_mul (x : ⨂[R] i, A i) : mul (tprod R 1) x = x := by induction x using PiTensorProduct.induction_on with | smul_tprod => simp | add _ _ h1 h2 => simp [map_add, h1, h2] protected lemma mul_one (x : ⨂[R] i, A i) : mul x (tprod R 1) = x := by induction x using PiTensorProduct.induction_on with | smul_tprod => simp | add _ _ h1 h2 => simp [h1, h2] instance instNonAssocSemiring : NonAssocSemiring (⨂[R] i, A i) where __ := instNonUnitalNonAssocSemiring one_mul := PiTensorProduct.one_mul mul_one := PiTensorProduct.mul_one variable (R) in /-- `PiTensorProduct.tprod` as a `MonoidHom`. -/ @[simps] def tprodMonoidHom : (Π i, A i) →* ⨂[R] i, A i where toFun := tprod R map_one' := rfl map_mul' x y := (tprod_mul_tprod x y).symm end NonAssocSemiring noncomputable section NonUnitalSemiring variable [CommSemiring R] [∀ i, NonUnitalSemiring (A i)] variable [∀ i, Module R (A i)] [∀ i, SMulCommClass R (A i) (A i)] [∀ i, IsScalarTower R (A i) (A i)] protected lemma mul_assoc (x y z : ⨂[R] i, A i) : 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 <| LinearMap.llcomp R _ _ _ mul.flip ∘ₗ mul).flip by exact DFunLike.congr_fun (DFunLike.congr_fun (DFunLike.congr_fun this x) y) z ext x y z dsimp [← mul_def] simpa only [tprod_mul_tprod] using congr_arg (tprod R) (mul_assoc x y z) instance instNonUnitalSemiring : NonUnitalSemiring (⨂[R] i, A i) where __ := instNonUnitalNonAssocSemiring mul_assoc := PiTensorProduct.mul_assoc end NonUnitalSemiring noncomputable section Semiring variable [CommSemiring R'] [CommSemiring R] [∀ i, Semiring (A i)] variable [Algebra R' R] [∀ i, Algebra R (A i)] [∀ i, Algebra R' (A i)] variable [∀ i, IsScalarTower R' R (A i)] instance instSemiring : Semiring (⨂[R] i, A i) where __ := instNonUnitalSemiring __ := instNonAssocSemiring instance instAlgebra : Algebra R' (⨂[R] i, A i) where __ := hasSMul' toFun := (· • 1) map_one' := by simp map_mul' r s := show (r * s) • 1 = mul (r • 1) (s • 1) by rw [LinearMap.map_smul_of_tower, LinearMap.map_smul_of_tower, LinearMap.smul_apply, mul_comm, mul_smul] congr show (1 : ⨂[R] i, A i) = 1 * 1 rw [mul_one] map_zero' := by simp map_add' := by simp [add_smul] commutes' r x := by simp only [RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk] change mul _ _ = mul _ _ rw [LinearMap.map_smul_of_tower, LinearMap.map_smul_of_tower, LinearMap.smul_apply] change r • (1 * x) = r • (x * 1) rw [mul_one, one_mul] smul_def' r x := by simp only [RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk] change _ = mul _ _ rw [LinearMap.map_smul_of_tower, LinearMap.smul_apply] change _ = r • (1 * x) rw [one_mul] lemma algebraMap_apply (r : R') (i : ι) [DecidableEq ι] : algebraMap R' (⨂[R] i, A i) r = tprod R (Pi.mulSingle i (algebraMap R' (A i) r)) := by change r • tprod R 1 = _ have : Pi.mulSingle i (algebraMap R' (A i) r) = update (fun i ↦ 1) i (r • 1) := by rw [Algebra.algebraMap_eq_smul_one]; rfl rw [this, ← smul_one_smul R r (1 : A i), MultilinearMap.map_smul, update_eq_self, smul_one_smul, Pi.one_def] /-- The map `Aᵢ ⟶ ⨂ᵢ Aᵢ` given by `a ↦ 1 ⊗ ... ⊗ a ⊗ 1 ⊗ ...` -/ @[simps] def singleAlgHom [DecidableEq ι] (i : ι) : A i →ₐ[R] ⨂[R] i, A i where toFun a := tprod R (MonoidHom.mulSingle _ i a) map_one' := by simp only [_root_.map_one]; rfl map_mul' a a' := by simp map_zero' := MultilinearMap.map_update_zero _ _ _ map_add' _ _ := MultilinearMap.map_add _ _ _ _ _ commutes' r := show tprodCoeff R _ _ = r • tprodCoeff R _ _ by rw [Algebra.algebraMap_eq_smul_one] erw [smul_tprodCoeff] rfl /-- Lifting a multilinear map to an algebra homomorphism from tensor product -/ @[simps!] def liftAlgHom {S : Type*} [Semiring S] [Algebra R S] (f : MultilinearMap R A S) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) : (⨂[R] i, A i) →ₐ[R] S := AlgHom.ofLinearMap (lift f) (show lift f (tprod R 1) = 1 by simp [one]) <| LinearMap.map_mul_iff _ |>.mpr <| by aesop @[simp] lemma tprod_noncommProd {κ : Type*} (s : Finset κ) (x : κ → Π i, A i) (hx) : tprod R (s.noncommProd x hx) = s.noncommProd (fun k => tprod R (x k)) (hx.imp fun _ _ => Commute.tprod) := Finset.map_noncommProd s x _ (tprodMonoidHom R) /-- To show two algebra morphisms from finite tensor products are equal, it suffices to show that they agree on elements of the form $1 ⊗ ⋯ ⊗ a ⊗ 1 ⊗ ⋯$. -/ @[ext high] theorem algHom_ext {S : Type*} [Finite ι] [DecidableEq ι] [Semiring S] [Algebra R S] ⦃f g : (⨂[R] i, A i) →ₐ[R] S⦄ (h : ∀ i, f.comp (singleAlgHom i) = g.comp (singleAlgHom i)) : f = g := AlgHom.toLinearMap_injective <| PiTensorProduct.ext <| MultilinearMap.ext fun x => suffices f.toMonoidHom.comp (tprodMonoidHom R) = g.toMonoidHom.comp (tprodMonoidHom R) from DFunLike.congr_fun this x MonoidHom.pi_ext fun i xi => DFunLike.congr_fun (h i) xi end Semiring noncomputable section Ring variable [CommRing R] [∀ i, Ring (A i)] [∀ i, Algebra R (A i)] instance instRing : Ring (⨂[R] i, A i) where __ := instSemiring __ := inferInstanceAs <| AddCommGroup (⨂[R] i, A i) end Ring noncomputable section CommSemiring variable [CommSemiring R] [∀ i, CommSemiring (A i)] [∀ i, Algebra R (A i)] protected lemma mul_comm (x y : ⨂[R] i, A i) : mul x y = mul y x := by suffices mul (R := R) (A := A) = mul.flip from DFunLike.congr_fun (DFunLike.congr_fun this x) y ext x y dsimp simp only [mul_tprod_tprod, mul_tprod_tprod, mul_comm x y] instance instCommSemiring : CommSemiring (⨂[R] i, A i) where __ := instSemiring __ := inferInstanceAs <| AddCommMonoid (⨂[R] i, A i) mul_comm := PiTensorProduct.mul_comm @[simp] lemma tprod_prod {κ : Type*} (s : Finset κ) (x : κ → Π i, A i) : tprod R (∏ k ∈ s, x k) = ∏ k ∈ s, tprod R (x k) := map_prod (tprodMonoidHom R) x s section open Function variable [Fintype ι] variable (R ι) /-- The algebra equivalence from the tensor product of the constant family with value `R` to `R`, given by multiplication of the entries. -/ noncomputable def constantBaseRingEquiv : (⨂[R] _ : ι, R) ≃ₐ[R] R := letI toFun := lift (MultilinearMap.mkPiAlgebra R ι R) AlgEquiv.ofAlgHom (AlgHom.ofLinearMap toFun ((lift.tprod _).trans Finset.prod_const_one) (by rw [LinearMap.map_mul_iff] ext x y show toFun (tprod R x * tprod R y) = toFun (tprod R x) * toFun (tprod R y) simp_rw [tprod_mul_tprod, toFun, lift.tprod, MultilinearMap.mkPiAlgebra_apply, Pi.mul_apply, Finset.prod_mul_distrib])) (Algebra.ofId _ _) (by ext) (by classical ext) variable {R ι} @[simp] theorem constantBaseRingEquiv_tprod (x : ι → R) : constantBaseRingEquiv ι R (tprod R x) = ∏ i, x i := by simp [constantBaseRingEquiv] @[simp] theorem constantBaseRingEquiv_symm (r : R) : (constantBaseRingEquiv ι R).symm r = algebraMap _ _ r := rfl end end CommSemiring noncomputable section CommRing variable [CommRing R] [∀ i, CommRing (A i)] [∀ i, Algebra R (A i)] instance instCommRing : CommRing (⨂[R] i, A i) where __ := instCommSemiring __ := inferInstanceAs <| AddCommGroup (⨂[R] i, A i) end CommRing end PiTensorProduct
RingTheory\PolynomialAlgebra.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Data.Matrix.Basis import Mathlib.Data.Matrix.DMatrix import Mathlib.RingTheory.MatrixAlgebra /-! # Algebra isomorphism between matrices of polynomials and polynomials of matrices Given `[CommRing R] [Ring A] [Algebra R A]` we show `A[X] ≃ₐ[R] (A ⊗[R] R[X])`. Combining this with the isomorphism `Matrix n n A ≃ₐ[R] (A ⊗[R] Matrix n n R)` proved earlier in `RingTheory.MatrixAlgebra`, we obtain the algebra isomorphism ``` def matPolyEquiv : Matrix n n R[X] ≃ₐ[R] (Matrix n n R)[X] ``` which is characterized by ``` coeff (matPolyEquiv m) k i j = coeff (m i j) k ``` We will use this algebra isomorphism to prove the Cayley-Hamilton theorem. -/ universe u v w open Polynomial TensorProduct open Algebra.TensorProduct (algHomOfLinearMapTensorProduct includeLeft) noncomputable section variable (R A : Type*) variable [CommSemiring R] variable [Semiring A] [Algebra R A] namespace PolyEquivTensor /-- (Implementation detail). The function underlying `A ⊗[R] R[X] →ₐ[R] A[X]`, as a bilinear function of two arguments. -/ -- Porting note: was `@[simps apply_apply]` @[simps! apply_apply] def toFunBilinear : A →ₗ[A] R[X] →ₗ[R] A[X] := LinearMap.toSpanSingleton A _ (aeval (Polynomial.X : A[X])).toLinearMap theorem toFunBilinear_apply_eq_sum (a : A) (p : R[X]) : toFunBilinear R A a p = p.sum fun n r => monomial n (a * algebraMap R A r) := by simp only [toFunBilinear_apply_apply, aeval_def, eval₂_eq_sum, Polynomial.sum, Finset.smul_sum] congr with i : 1 rw [← Algebra.smul_def, ← C_mul', mul_smul_comm, C_mul_X_pow_eq_monomial, ← Algebra.commutes, ← Algebra.smul_def, smul_monomial] /-- (Implementation detail). The function underlying `A ⊗[R] R[X] →ₐ[R] A[X]`, as a linear map. -/ def toFunLinear : A ⊗[R] R[X] →ₗ[R] A[X] := TensorProduct.lift (toFunBilinear R A) @[simp] theorem toFunLinear_tmul_apply (a : A) (p : R[X]) : toFunLinear R A (a ⊗ₜ[R] p) = toFunBilinear R A a p := rfl -- We apparently need to provide the decidable instance here -- in order to successfully rewrite by this lemma. theorem toFunLinear_mul_tmul_mul_aux_1 (p : R[X]) (k : ℕ) (h : Decidable ¬p.coeff k = 0) (a : A) : ite (¬coeff p k = 0) (a * (algebraMap R A) (coeff p k)) 0 = a * (algebraMap R A) (coeff p k) := by classical split_ifs <;> simp [*] theorem toFunLinear_mul_tmul_mul_aux_2 (k : ℕ) (a₁ a₂ : A) (p₁ p₂ : R[X]) : a₁ * a₂ * (algebraMap R A) ((p₁ * p₂).coeff k) = (Finset.antidiagonal k).sum fun x => a₁ * (algebraMap R A) (coeff p₁ x.1) * (a₂ * (algebraMap R A) (coeff p₂ x.2)) := by simp_rw [mul_assoc, Algebra.commutes, ← Finset.mul_sum, mul_assoc, ← Finset.mul_sum] congr simp_rw [Algebra.commutes (coeff p₂ _), coeff_mul, map_sum, RingHom.map_mul] theorem toFunLinear_mul_tmul_mul (a₁ a₂ : A) (p₁ p₂ : R[X]) : (toFunLinear R A) ((a₁ * a₂) ⊗ₜ[R] (p₁ * p₂)) = (toFunLinear R A) (a₁ ⊗ₜ[R] p₁) * (toFunLinear R A) (a₂ ⊗ₜ[R] p₂) := by classical simp only [toFunLinear_tmul_apply, toFunBilinear_apply_eq_sum] ext k simp_rw [coeff_sum, coeff_monomial, sum_def, Finset.sum_ite_eq', mem_support_iff, Ne] conv_rhs => rw [coeff_mul] simp_rw [finset_sum_coeff, coeff_monomial, Finset.sum_ite_eq', mem_support_iff, Ne, mul_ite, mul_zero, ite_mul, zero_mul] simp_rw [← ite_zero_mul (¬coeff p₁ _ = 0) (a₁ * (algebraMap R A) (coeff p₁ _))] simp_rw [← mul_ite_zero (¬coeff p₂ _ = 0) _ (_ * _)] simp_rw [toFunLinear_mul_tmul_mul_aux_1, toFunLinear_mul_tmul_mul_aux_2] theorem toFunLinear_one_tmul_one : toFunLinear R A (1 ⊗ₜ[R] 1) = 1 := by rw [toFunLinear_tmul_apply, toFunBilinear_apply_apply, Polynomial.aeval_one, one_smul] /-- (Implementation detail). The algebra homomorphism `A ⊗[R] R[X] →ₐ[R] A[X]`. -/ def toFunAlgHom : A ⊗[R] R[X] →ₐ[R] A[X] := algHomOfLinearMapTensorProduct (toFunLinear R A) (toFunLinear_mul_tmul_mul R A) (toFunLinear_one_tmul_one R A) @[simp] theorem toFunAlgHom_apply_tmul (a : A) (p : R[X]) : toFunAlgHom R A (a ⊗ₜ[R] p) = p.sum fun n r => monomial n (a * (algebraMap R A) r) := toFunBilinear_apply_eq_sum R A _ _ /-- (Implementation detail.) The bare function `A[X] → A ⊗[R] R[X]`. (We don't need to show that it's an algebra map, thankfully --- just that it's an inverse.) -/ def invFun (p : A[X]) : A ⊗[R] R[X] := p.eval₂ (includeLeft : A →ₐ[R] A ⊗[R] R[X]) ((1 : A) ⊗ₜ[R] (X : R[X])) @[simp] theorem invFun_add {p q} : invFun R A (p + q) = invFun R A p + invFun R A q := by simp only [invFun, eval₂_add] theorem invFun_monomial (n : ℕ) (a : A) : invFun R A (monomial n a) = (a ⊗ₜ[R] 1) * 1 ⊗ₜ[R] X ^ n := eval₂_monomial _ _ theorem left_inv (x : A ⊗ R[X]) : invFun R A ((toFunAlgHom R A) x) = x := by refine TensorProduct.induction_on x ?_ ?_ ?_ · simp [invFun] · intro a p dsimp only [invFun] rw [toFunAlgHom_apply_tmul, eval₂_sum] simp_rw [eval₂_monomial, AlgHom.coe_toRingHom, Algebra.TensorProduct.tmul_pow, one_pow, Algebra.TensorProduct.includeLeft_apply, Algebra.TensorProduct.tmul_mul_tmul, mul_one, one_mul, ← Algebra.commutes, ← Algebra.smul_def, smul_tmul, sum_def, ← tmul_sum] conv_rhs => rw [← sum_C_mul_X_pow_eq p] simp only [Algebra.smul_def] rfl · intro p q hp hq simp only [map_add, invFun_add, hp, hq] theorem right_inv (x : A[X]) : (toFunAlgHom R A) (invFun R A x) = x := by refine Polynomial.induction_on' x ?_ ?_ · intro p q hp hq simp only [invFun_add, map_add, hp, hq] · intro n a rw [invFun_monomial, Algebra.TensorProduct.tmul_pow, one_pow, Algebra.TensorProduct.tmul_mul_tmul, mul_one, one_mul, toFunAlgHom_apply_tmul, X_pow_eq_monomial, sum_monomial_index] <;> simp /-- (Implementation detail) The equivalence, ignoring the algebra structure, `(A ⊗[R] R[X]) ≃ A[X]`. -/ def equiv : A ⊗[R] R[X] ≃ A[X] where toFun := toFunAlgHom R A invFun := invFun R A left_inv := left_inv R A right_inv := right_inv R A end PolyEquivTensor open PolyEquivTensor /-- The `R`-algebra isomorphism `A[X] ≃ₐ[R] (A ⊗[R] R[X])`. -/ def polyEquivTensor : A[X] ≃ₐ[R] A ⊗[R] R[X] := AlgEquiv.symm { PolyEquivTensor.toFunAlgHom R A, PolyEquivTensor.equiv R A with } @[simp] theorem polyEquivTensor_apply (p : A[X]) : polyEquivTensor R A p = p.eval₂ (includeLeft : A →ₐ[R] A ⊗[R] R[X]) ((1 : A) ⊗ₜ[R] (X : R[X])) := rfl @[simp] theorem polyEquivTensor_symm_apply_tmul (a : A) (p : R[X]) : (polyEquivTensor R A).symm (a ⊗ₜ p) = p.sum fun n r => monomial n (a * algebraMap R A r) := toFunAlgHom_apply_tmul _ _ _ _ open DMatrix Matrix variable {R} variable {n : Type w} [DecidableEq n] [Fintype n] /-- The algebra isomorphism stating "matrices of polynomials are the same as polynomials of matrices". (You probably shouldn't attempt to use this underlying definition --- it's an algebra equivalence, and characterised extensionally by the lemma `matPolyEquiv_coeff_apply` below.) -/ noncomputable def matPolyEquiv : Matrix n n R[X] ≃ₐ[R] (Matrix n n R)[X] := ((matrixEquivTensor R R[X] n).trans (Algebra.TensorProduct.comm R _ _)).trans (polyEquivTensor R (Matrix n n R)).symm @[simp] theorem matPolyEquiv_symm_C (M : Matrix n n R) : matPolyEquiv.symm (C M) = M.map C := by simp [matPolyEquiv, ← C_eq_algebraMap] @[simp] theorem matPolyEquiv_map_C (M : Matrix n n R) : matPolyEquiv (M.map C) = C M := by rw [← matPolyEquiv_symm_C, AlgEquiv.apply_symm_apply] @[simp] theorem matPolyEquiv_symm_X : matPolyEquiv.symm X = diagonal fun _ : n => (X : R[X]) := by suffices (Matrix.map 1 fun x ↦ X * algebraMap R R[X] x) = diagonal fun _ : n => (X : R[X]) by simpa [matPolyEquiv] rw [← Matrix.diagonal_one] simp [-Matrix.diagonal_one] @[simp] theorem matPolyEquiv_diagonal_X : matPolyEquiv (diagonal fun _ : n => (X : R[X])) = X := by rw [← matPolyEquiv_symm_X, AlgEquiv.apply_symm_apply] open Finset unseal Algebra.TensorProduct.mul in theorem matPolyEquiv_coeff_apply_aux_1 (i j : n) (k : ℕ) (x : R) : matPolyEquiv (stdBasisMatrix i j <| monomial k x) = monomial k (stdBasisMatrix i j x) := by simp only [matPolyEquiv, AlgEquiv.trans_apply, matrixEquivTensor_apply_std_basis] apply (polyEquivTensor R (Matrix n n R)).injective simp only [AlgEquiv.apply_symm_apply,Algebra.TensorProduct.comm_tmul, polyEquivTensor_apply, eval₂_monomial] simp only [Algebra.TensorProduct.tmul_mul_tmul, one_pow, one_mul, Matrix.mul_one, Algebra.TensorProduct.tmul_pow, Algebra.TensorProduct.includeLeft_apply] rw [← smul_X_eq_monomial, ← TensorProduct.smul_tmul] congr with i' <;> simp [stdBasisMatrix] theorem matPolyEquiv_coeff_apply_aux_2 (i j : n) (p : R[X]) (k : ℕ) : coeff (matPolyEquiv (stdBasisMatrix i j p)) k = stdBasisMatrix i j (coeff p k) := by refine Polynomial.induction_on' p ?_ ?_ · intro p q hp hq ext simp [hp, hq, coeff_add, DMatrix.add_apply, stdBasisMatrix_add] · intro k x simp only [matPolyEquiv_coeff_apply_aux_1, coeff_monomial] split_ifs <;> · funext simp @[simp] theorem matPolyEquiv_coeff_apply (m : Matrix n n R[X]) (k : ℕ) (i j : n) : coeff (matPolyEquiv m) k i j = coeff (m i j) k := by refine Matrix.induction_on' m ?_ ?_ ?_ · simp · intro p q hp hq simp [hp, hq] · intro i' j' x erw [matPolyEquiv_coeff_apply_aux_2] dsimp [stdBasisMatrix] split_ifs <;> rename_i h · rcases h with ⟨rfl, rfl⟩ simp [stdBasisMatrix] · simp [stdBasisMatrix, h] @[simp] theorem matPolyEquiv_symm_apply_coeff (p : (Matrix n n R)[X]) (i j : n) (k : ℕ) : coeff (matPolyEquiv.symm p i j) k = coeff p k i j := by have t : p = matPolyEquiv (matPolyEquiv.symm p) := by simp conv_rhs => rw [t] simp only [matPolyEquiv_coeff_apply] theorem matPolyEquiv_smul_one (p : R[X]) : matPolyEquiv (p • (1 : Matrix n n R[X])) = p.map (algebraMap R (Matrix n n R)) := by ext m i j simp only [matPolyEquiv_coeff_apply, smul_apply, one_apply, smul_eq_mul, mul_ite, mul_one, mul_zero, coeff_map, algebraMap_matrix_apply, Algebra.id.map_eq_id, RingHom.id_apply] split_ifs <;> simp @[simp] lemma matPolyEquiv_map_smul (p : R[X]) (M : Matrix n n R[X]) : matPolyEquiv (p • M) = p.map (algebraMap _ _) * matPolyEquiv M := by rw [← one_mul M, ← smul_mul_assoc, _root_.map_mul, matPolyEquiv_smul_one, one_mul] theorem support_subset_support_matPolyEquiv (m : Matrix n n R[X]) (i j : n) : support (m i j) ⊆ support (matPolyEquiv m) := by intro k contrapose simp only [not_mem_support_iff] intro hk rw [← matPolyEquiv_coeff_apply, hk] rfl
RingTheory\PowerBasis.lean
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.FieldTheory.Minpoly.Field import Mathlib.LinearAlgebra.SModEq /-! # Power basis This file defines a structure `PowerBasis R S`, giving a basis of the `R`-algebra `S` as a finite list of powers `1, x, ..., x^n`. For example, if `x` is algebraic over a ring/field, adjoining `x` gives a `PowerBasis` structure generated by `x`. ## Definitions * `PowerBasis R A`: a structure containing an `x` and an `n` such that `1, x, ..., x^n` is a basis for the `R`-algebra `A` (viewed as an `R`-module). * `finrank (hf : f ≠ 0) : FiniteDimensional.finrank K (AdjoinRoot f) = f.natDegree`, the dimension of `AdjoinRoot f` equals the degree of `f` * `PowerBasis.lift (pb : PowerBasis R S)`: if `y : S'` satisfies the same equations as `pb.gen`, this is the map `S →ₐ[R] S'` sending `pb.gen` to `y` * `PowerBasis.equiv`: if two power bases satisfy the same equations, they are equivalent as algebras ## Implementation notes Throughout this file, `R`, `S`, `A`, `B` ... are `CommRing`s, and `K`, `L`, ... are `Field`s. `S` is an `R`-algebra, `B` is an `A`-algebra, `L` is a `K`-algebra. ## Tags power basis, powerbasis -/ open Polynomial open Polynomial variable {R S T : Type*} [CommRing R] [Ring S] [Algebra R S] variable {A B : Type*} [CommRing A] [CommRing B] [IsDomain B] [Algebra A B] variable {K : Type*} [Field K] /-- `pb : PowerBasis R S` states that `1, pb.gen, ..., pb.gen ^ (pb.dim - 1)` is a basis for the `R`-algebra `S` (viewed as `R`-module). This is a structure, not a class, since the same algebra can have many power bases. For the common case where `S` is defined by adjoining an integral element to `R`, the canonical power basis is given by `{Algebra,IntermediateField}.adjoin.powerBasis`. -/ -- Porting note(#5171): this linter isn't ported yet. -- @[nolint has_nonempty_instance] structure PowerBasis (R S : Type*) [CommRing R] [Ring S] [Algebra R S] where gen : S dim : ℕ basis : Basis (Fin dim) R S basis_eq_pow : ∀ (i), basis i = gen ^ (i : ℕ) -- this is usually not needed because of `basis_eq_pow` but can be needed in some cases; -- in such circumstances, add it manually using `@[simps dim gen basis]`. initialize_simps_projections PowerBasis (-basis) namespace PowerBasis @[simp] theorem coe_basis (pb : PowerBasis R S) : ⇑pb.basis = fun i : Fin pb.dim => pb.gen ^ (i : ℕ) := funext pb.basis_eq_pow /-- Cannot be an instance because `PowerBasis` cannot be a class. -/ theorem finite (pb : PowerBasis R S) : Module.Finite R S := .of_basis pb.basis @[deprecated (since := "2024-03-05")] alias finiteDimensional := PowerBasis.finite theorem finrank [StrongRankCondition R] (pb : PowerBasis R S) : FiniteDimensional.finrank R S = pb.dim := by rw [FiniteDimensional.finrank_eq_card_basis pb.basis, Fintype.card_fin] theorem mem_span_pow' {x y : S} {d : ℕ} : y ∈ Submodule.span R (Set.range fun i : Fin d => x ^ (i : ℕ)) ↔ ∃ f : R[X], f.degree < d ∧ y = aeval x f := by have : (Set.range fun i : Fin d => x ^ (i : ℕ)) = (fun i : ℕ => x ^ i) '' ↑(Finset.range d) := by ext n simp_rw [Set.mem_range, Set.mem_image, Finset.mem_coe, Finset.mem_range] exact ⟨fun ⟨⟨i, hi⟩, hy⟩ => ⟨i, hi, hy⟩, fun ⟨i, hi, hy⟩ => ⟨⟨i, hi⟩, hy⟩⟩ simp only [this, Finsupp.mem_span_image_iff_total, degree_lt_iff_coeff_zero, support, exists_iff_exists_finsupp, coeff, aeval_def, eval₂RingHom', eval₂_eq_sum, Polynomial.sum, Finsupp.mem_supported', Finsupp.total, Finsupp.sum, Algebra.smul_def, eval₂_zero, exists_prop, LinearMap.id_coe, eval₂_one, id, not_lt, Finsupp.coe_lsum, LinearMap.coe_smulRight, Finset.mem_range, AlgHom.coe_mks, Finset.mem_coe] simp_rw [@eq_comm _ y] exact Iff.rfl theorem mem_span_pow {x y : S} {d : ℕ} (hd : d ≠ 0) : y ∈ Submodule.span R (Set.range fun i : Fin d => x ^ (i : ℕ)) ↔ ∃ f : R[X], f.natDegree < d ∧ y = aeval x f := by rw [mem_span_pow'] constructor <;> · rintro ⟨f, h, hy⟩ refine ⟨f, ?_, hy⟩ by_cases hf : f = 0 · simp only [hf, natDegree_zero, degree_zero] at h ⊢ first | exact lt_of_le_of_ne (Nat.zero_le d) hd.symm | exact WithBot.bot_lt_coe d simp_all only [degree_eq_natDegree hf] · first | exact WithBot.coe_lt_coe.1 h | exact WithBot.coe_lt_coe.2 h theorem dim_ne_zero [Nontrivial S] (pb : PowerBasis R S) : pb.dim ≠ 0 := fun h => not_nonempty_iff.mpr (h.symm ▸ Fin.isEmpty : IsEmpty (Fin pb.dim)) pb.basis.index_nonempty theorem dim_pos [Nontrivial S] (pb : PowerBasis R S) : 0 < pb.dim := Nat.pos_of_ne_zero pb.dim_ne_zero theorem exists_eq_aeval [Nontrivial S] (pb : PowerBasis R S) (y : S) : ∃ f : R[X], f.natDegree < pb.dim ∧ y = aeval pb.gen f := (mem_span_pow pb.dim_ne_zero).mp (by simpa using pb.basis.mem_span y) theorem exists_eq_aeval' (pb : PowerBasis R S) (y : S) : ∃ f : R[X], y = aeval pb.gen f := by nontriviality S obtain ⟨f, _, hf⟩ := exists_eq_aeval pb y exact ⟨f, hf⟩ theorem algHom_ext {S' : Type*} [Semiring S'] [Algebra R S'] (pb : PowerBasis R S) ⦃f g : S →ₐ[R] S'⦄ (h : f pb.gen = g pb.gen) : f = g := by ext x obtain ⟨f, rfl⟩ := pb.exists_eq_aeval' x rw [← Polynomial.aeval_algHom_apply, ← Polynomial.aeval_algHom_apply, h] open Ideal Finset Submodule in theorem exists_smodEq (pb : PowerBasis A B) (b : B) : ∃ a, SModEq (Ideal.span ({pb.gen})) b (algebraMap A B a) := by rcases subsingleton_or_nontrivial B · exact ⟨0, by rw [SModEq, Subsingleton.eq_zero b, _root_.map_zero]⟩ refine ⟨pb.basis.repr b ⟨0, pb.dim_pos⟩, ?_⟩ have H := pb.basis.sum_repr b rw [← insert_erase (mem_univ ⟨0, pb.dim_pos⟩), sum_insert (not_mem_erase _ _)] at H rw [SModEq, ← add_zero (algebraMap _ _ _), Quotient.mk_add] nth_rewrite 1 [← H] rw [Quotient.mk_add] congr 1 · simp [Algebra.algebraMap_eq_smul_one ((pb.basis.repr b) _)] · rw [Quotient.mk_zero, Quotient.mk_eq_zero, coe_basis] refine sum_mem _ (fun i hi ↦ ?_) rw [Algebra.smul_def'] refine Ideal.mul_mem_left _ _ <| Ideal.pow_mem_of_mem _ (Ideal.subset_span (by simp)) _ <| Nat.pos_of_ne_zero <| fun h ↦ not_mem_erase i univ <| Fin.eq_mk_iff_val_eq.2 h ▸ hi open Submodule.Quotient in theorem exists_gen_dvd_sub (pb : PowerBasis A B) (b : B) : ∃ a, pb.gen ∣ b - algebraMap A B a := by simpa [← Ideal.mem_span_singleton, ← mk_eq_zero, mk_sub, sub_eq_zero] using pb.exists_smodEq b section minpoly variable [Algebra A S] /-- `pb.minpolyGen` is the minimal polynomial for `pb.gen`. -/ noncomputable def minpolyGen (pb : PowerBasis A S) : A[X] := X ^ pb.dim - ∑ i : Fin pb.dim, C (pb.basis.repr (pb.gen ^ pb.dim) i) * X ^ (i : ℕ) theorem aeval_minpolyGen (pb : PowerBasis A S) : aeval pb.gen (minpolyGen pb) = 0 := by simp_rw [minpolyGen, map_sub, map_sum, map_mul, map_pow, aeval_C, ← Algebra.smul_def, aeval_X] refine sub_eq_zero.mpr ((pb.basis.total_repr (pb.gen ^ pb.dim)).symm.trans ?_) rw [Finsupp.total_apply, Finsupp.sum_fintype] <;> simp only [pb.coe_basis, zero_smul, eq_self_iff_true, imp_true_iff] theorem minpolyGen_monic (pb : PowerBasis A S) : Monic (minpolyGen pb) := by nontriviality A apply (monic_X_pow _).sub_of_left _ rw [degree_X_pow] exact degree_sum_fin_lt _ theorem dim_le_natDegree_of_root (pb : PowerBasis A S) {p : A[X]} (ne_zero : p ≠ 0) (root : aeval pb.gen p = 0) : pb.dim ≤ p.natDegree := by refine le_of_not_lt fun hlt => ne_zero ?_ rw [p.as_sum_range' _ hlt, Finset.sum_range] refine Fintype.sum_eq_zero _ fun i => ?_ simp_rw [aeval_eq_sum_range' hlt, Finset.sum_range, ← pb.basis_eq_pow] at root have := Fintype.linearIndependent_iff.1 pb.basis.linearIndependent _ root rw [this, monomial_zero_right] theorem dim_le_degree_of_root (h : PowerBasis A S) {p : A[X]} (ne_zero : p ≠ 0) (root : aeval h.gen p = 0) : ↑h.dim ≤ p.degree := by rw [degree_eq_natDegree ne_zero] exact WithBot.coe_le_coe.2 (h.dim_le_natDegree_of_root ne_zero root) theorem degree_minpolyGen [Nontrivial A] (pb : PowerBasis A S) : degree (minpolyGen pb) = pb.dim := by unfold minpolyGen rw [degree_sub_eq_left_of_degree_lt] <;> rw [degree_X_pow] apply degree_sum_fin_lt theorem natDegree_minpolyGen [Nontrivial A] (pb : PowerBasis A S) : natDegree (minpolyGen pb) = pb.dim := natDegree_eq_of_degree_eq_some pb.degree_minpolyGen @[simp] theorem minpolyGen_eq (pb : PowerBasis A S) : pb.minpolyGen = minpoly A pb.gen := by nontriviality A refine minpoly.unique' A _ pb.minpolyGen_monic pb.aeval_minpolyGen fun q hq => or_iff_not_imp_left.2 fun hn0 h0 => ?_ exact (pb.dim_le_degree_of_root hn0 h0).not_lt (pb.degree_minpolyGen ▸ hq) theorem isIntegral_gen (pb : PowerBasis A S) : IsIntegral A pb.gen := ⟨minpolyGen pb, minpolyGen_monic pb, aeval_minpolyGen pb⟩ @[simp] theorem degree_minpoly [Nontrivial A] (pb : PowerBasis A S) : degree (minpoly A pb.gen) = pb.dim := by rw [← minpolyGen_eq, degree_minpolyGen] @[simp] theorem natDegree_minpoly [Nontrivial A] (pb : PowerBasis A S) : (minpoly A pb.gen).natDegree = pb.dim := by rw [← minpolyGen_eq, natDegree_minpolyGen] protected theorem leftMulMatrix (pb : PowerBasis A S) : Algebra.leftMulMatrix pb.basis pb.gen = @Matrix.of (Fin pb.dim) (Fin pb.dim) _ fun i j => if ↑j + 1 = pb.dim then -pb.minpolyGen.coeff ↑i else if (i : ℕ) = j + 1 then 1 else 0 := by cases subsingleton_or_nontrivial A; · subsingleton rw [Algebra.leftMulMatrix_apply, ← LinearEquiv.eq_symm_apply, LinearMap.toMatrix_symm] refine pb.basis.ext fun k => ?_ simp_rw [Matrix.toLin_self, Matrix.of_apply, pb.basis_eq_pow] apply (pow_succ' _ _).symm.trans split_ifs with h · simp_rw [h, neg_smul, Finset.sum_neg_distrib, eq_neg_iff_add_eq_zero] convert pb.aeval_minpolyGen rw [add_comm, aeval_eq_sum_range, Finset.sum_range_succ, ← leadingCoeff, pb.minpolyGen_monic.leadingCoeff, one_smul, natDegree_minpolyGen, Finset.sum_range] · rw [Fintype.sum_eq_single (⟨(k : ℕ) + 1, lt_of_le_of_ne k.2 h⟩ : Fin pb.dim), if_pos, one_smul] · rfl intro x hx rw [if_neg, zero_smul] apply mt Fin.ext hx end minpoly section Equiv variable [Algebra A S] {S' : Type*} [Ring S'] [Algebra A S'] theorem constr_pow_aeval (pb : PowerBasis A S) {y : S'} (hy : aeval y (minpoly A pb.gen) = 0) (f : A[X]) : pb.basis.constr A (fun i => y ^ (i : ℕ)) (aeval pb.gen f) = aeval y f := by cases subsingleton_or_nontrivial A · rw [(Subsingleton.elim _ _ : f = 0), aeval_zero, map_zero, aeval_zero] rw [← aeval_modByMonic_eq_self_of_root (minpoly.monic pb.isIntegral_gen) (minpoly.aeval _ _), ← @aeval_modByMonic_eq_self_of_root _ _ _ _ _ f _ (minpoly.monic pb.isIntegral_gen) y hy] by_cases hf : f %ₘ minpoly A pb.gen = 0 · simp only [hf, map_zero] have : (f %ₘ minpoly A pb.gen).natDegree < pb.dim := by rw [← pb.natDegree_minpoly] apply natDegree_lt_natDegree hf exact degree_modByMonic_lt _ (minpoly.monic pb.isIntegral_gen) rw [aeval_eq_sum_range' this, aeval_eq_sum_range' this, map_sum] refine Finset.sum_congr rfl fun i (hi : i ∈ Finset.range pb.dim) => ?_ rw [Finset.mem_range] at hi rw [LinearMap.map_smul] congr rw [← Fin.val_mk hi, ← pb.basis_eq_pow ⟨i, hi⟩, Basis.constr_basis] theorem constr_pow_gen (pb : PowerBasis A S) {y : S'} (hy : aeval y (minpoly A pb.gen) = 0) : pb.basis.constr A (fun i => y ^ (i : ℕ)) pb.gen = y := by convert pb.constr_pow_aeval hy X <;> rw [aeval_X] theorem constr_pow_algebraMap (pb : PowerBasis A S) {y : S'} (hy : aeval y (minpoly A pb.gen) = 0) (x : A) : pb.basis.constr A (fun i => y ^ (i : ℕ)) (algebraMap A S x) = algebraMap A S' x := by convert pb.constr_pow_aeval hy (C x) <;> rw [aeval_C] theorem constr_pow_mul (pb : PowerBasis A S) {y : S'} (hy : aeval y (minpoly A pb.gen) = 0) (x x' : S) : pb.basis.constr A (fun i => y ^ (i : ℕ)) (x * x') = pb.basis.constr A (fun i => y ^ (i : ℕ)) x * pb.basis.constr A (fun i => y ^ (i : ℕ)) x' := by obtain ⟨f, rfl⟩ := pb.exists_eq_aeval' x obtain ⟨g, rfl⟩ := pb.exists_eq_aeval' x' simp only [← aeval_mul, pb.constr_pow_aeval hy] /-- `pb.lift y hy` is the algebra map sending `pb.gen` to `y`, where `hy` states the higher powers of `y` are the same as the higher powers of `pb.gen`. See `PowerBasis.liftEquiv` for a bundled equiv sending `⟨y, hy⟩` to the algebra map. -/ noncomputable def lift (pb : PowerBasis A S) (y : S') (hy : aeval y (minpoly A pb.gen) = 0) : S →ₐ[A] S' := { pb.basis.constr A fun i => y ^ (i : ℕ) with map_one' := by convert pb.constr_pow_algebraMap hy 1 using 2 <;> rw [RingHom.map_one] map_zero' := by convert pb.constr_pow_algebraMap hy 0 using 2 <;> rw [RingHom.map_zero] map_mul' := pb.constr_pow_mul hy commutes' := pb.constr_pow_algebraMap hy } @[simp] theorem lift_gen (pb : PowerBasis A S) (y : S') (hy : aeval y (minpoly A pb.gen) = 0) : pb.lift y hy pb.gen = y := pb.constr_pow_gen hy @[simp] theorem lift_aeval (pb : PowerBasis A S) (y : S') (hy : aeval y (minpoly A pb.gen) = 0) (f : A[X]) : pb.lift y hy (aeval pb.gen f) = aeval y f := pb.constr_pow_aeval hy f /-- `pb.liftEquiv` states that roots of the minimal polynomial of `pb.gen` correspond to maps sending `pb.gen` to that root. This is the bundled equiv version of `PowerBasis.lift`. If the codomain of the `AlgHom`s is an integral domain, then the roots form a multiset, see `liftEquiv'` for the corresponding statement. -/ @[simps] noncomputable def liftEquiv (pb : PowerBasis A S) : (S →ₐ[A] S') ≃ { y : S' // aeval y (minpoly A pb.gen) = 0 } where toFun f := ⟨f pb.gen, by rw [aeval_algHom_apply, minpoly.aeval, map_zero]⟩ invFun y := pb.lift y y.2 left_inv f := pb.algHom_ext <| lift_gen _ _ _ right_inv y := Subtype.ext <| lift_gen _ _ y.prop /-- `pb.liftEquiv'` states that elements of the root set of the minimal polynomial of `pb.gen` correspond to maps sending `pb.gen` to that root. -/ @[simps! (config := .asFn)] noncomputable def liftEquiv' (pb : PowerBasis A S) : (S →ₐ[A] B) ≃ { y : B // y ∈ (minpoly A pb.gen).aroots B } := pb.liftEquiv.trans ((Equiv.refl _).subtypeEquiv fun x => by rw [Equiv.refl_apply, mem_roots_iff_aeval_eq_zero] · simp · exact map_monic_ne_zero (minpoly.monic pb.isIntegral_gen)) /-- There are finitely many algebra homomorphisms `S →ₐ[A] B` if `S` is of the form `A[x]` and `B` is an integral domain. -/ noncomputable def AlgHom.fintype (pb : PowerBasis A S) : Fintype (S →ₐ[A] B) := letI := Classical.decEq B Fintype.ofEquiv _ pb.liftEquiv'.symm /-- `pb.equivOfRoot pb' h₁ h₂` is an equivalence of algebras with the same power basis, where "the same" means that `pb` is a root of `pb'`s minimal polynomial and vice versa. See also `PowerBasis.equivOfMinpoly` which takes the hypothesis that the minimal polynomials are identical. -/ @[simps! (config := .lemmasOnly) apply] noncomputable def equivOfRoot (pb : PowerBasis A S) (pb' : PowerBasis A S') (h₁ : aeval pb.gen (minpoly A pb'.gen) = 0) (h₂ : aeval pb'.gen (minpoly A pb.gen) = 0) : S ≃ₐ[A] S' := AlgEquiv.ofAlgHom (pb.lift pb'.gen h₂) (pb'.lift pb.gen h₁) (by ext x obtain ⟨f, hf, rfl⟩ := pb'.exists_eq_aeval' x simp) (by ext x obtain ⟨f, hf, rfl⟩ := pb.exists_eq_aeval' x simp) @[simp] theorem equivOfRoot_aeval (pb : PowerBasis A S) (pb' : PowerBasis A S') (h₁ : aeval pb.gen (minpoly A pb'.gen) = 0) (h₂ : aeval pb'.gen (minpoly A pb.gen) = 0) (f : A[X]) : pb.equivOfRoot pb' h₁ h₂ (aeval pb.gen f) = aeval pb'.gen f := pb.lift_aeval _ h₂ _ @[simp] theorem equivOfRoot_gen (pb : PowerBasis A S) (pb' : PowerBasis A S') (h₁ : aeval pb.gen (minpoly A pb'.gen) = 0) (h₂ : aeval pb'.gen (minpoly A pb.gen) = 0) : pb.equivOfRoot pb' h₁ h₂ pb.gen = pb'.gen := pb.lift_gen _ h₂ @[simp] theorem equivOfRoot_symm (pb : PowerBasis A S) (pb' : PowerBasis A S') (h₁ : aeval pb.gen (minpoly A pb'.gen) = 0) (h₂ : aeval pb'.gen (minpoly A pb.gen) = 0) : (pb.equivOfRoot pb' h₁ h₂).symm = pb'.equivOfRoot pb h₂ h₁ := rfl /-- `pb.equivOfMinpoly pb' h` is an equivalence of algebras with the same power basis, where "the same" means that they have identical minimal polynomials. See also `PowerBasis.equivOfRoot` which takes the hypothesis that each generator is a root of the other basis' minimal polynomial; `PowerBasis.equivOfRoot` is more general if `A` is not a field. -/ @[simps! (config := .lemmasOnly) apply] noncomputable def equivOfMinpoly (pb : PowerBasis A S) (pb' : PowerBasis A S') (h : minpoly A pb.gen = minpoly A pb'.gen) : S ≃ₐ[A] S' := pb.equivOfRoot pb' (h ▸ minpoly.aeval _ _) (h.symm ▸ minpoly.aeval _ _) @[simp] theorem equivOfMinpoly_aeval (pb : PowerBasis A S) (pb' : PowerBasis A S') (h : minpoly A pb.gen = minpoly A pb'.gen) (f : A[X]) : pb.equivOfMinpoly pb' h (aeval pb.gen f) = aeval pb'.gen f := pb.equivOfRoot_aeval pb' _ _ _ @[simp] theorem equivOfMinpoly_gen (pb : PowerBasis A S) (pb' : PowerBasis A S') (h : minpoly A pb.gen = minpoly A pb'.gen) : pb.equivOfMinpoly pb' h pb.gen = pb'.gen := pb.equivOfRoot_gen pb' _ _ @[simp] theorem equivOfMinpoly_symm (pb : PowerBasis A S) (pb' : PowerBasis A S') (h : minpoly A pb.gen = minpoly A pb'.gen) : (pb.equivOfMinpoly pb' h).symm = pb'.equivOfMinpoly pb h.symm := rfl end Equiv end PowerBasis open PowerBasis /-- Useful lemma to show `x` generates a power basis: the powers of `x` less than the degree of `x`'s minimal polynomial are linearly independent. -/ theorem linearIndependent_pow [Algebra K S] (x : S) : LinearIndependent K fun i : Fin (minpoly K x).natDegree => x ^ (i : ℕ) := by by_cases h : IsIntegral K x; swap · rw [minpoly.eq_zero h, natDegree_zero] exact linearIndependent_empty_type refine Fintype.linearIndependent_iff.2 fun g hg i => ?_ simp only at hg simp_rw [Algebra.smul_def, ← aeval_monomial, ← map_sum] at hg apply (fun hn0 => (minpoly.degree_le_of_ne_zero K x (mt (fun h0 => ?_) hn0) hg).not_lt).mtr · simp_rw [← C_mul_X_pow_eq_monomial] exact (degree_eq_natDegree <| minpoly.ne_zero h).symm ▸ degree_sum_fin_lt _ · apply_fun lcoeff K i at h0 simp_rw [map_sum, lcoeff_apply, coeff_monomial, Fin.val_eq_val, Finset.sum_ite_eq'] at h0 exact (if_pos <| Finset.mem_univ _).symm.trans h0 theorem IsIntegral.mem_span_pow [Nontrivial R] {x y : S} (hx : IsIntegral R x) (hy : ∃ f : R[X], y = aeval x f) : y ∈ Submodule.span R (Set.range fun i : Fin (minpoly R x).natDegree => x ^ (i : ℕ)) := by obtain ⟨f, rfl⟩ := hy apply mem_span_pow'.mpr _ have := minpoly.monic hx refine ⟨f %ₘ minpoly R x, (degree_modByMonic_lt _ this).trans_le degree_le_natDegree, ?_⟩ conv_lhs => rw [← modByMonic_add_div f this] simp only [add_zero, zero_mul, minpoly.aeval, aeval_add, map_mul] namespace PowerBasis section Map variable {S' : Type*} [CommRing S'] [Algebra R S'] /-- `PowerBasis.map pb (e : S ≃ₐ[R] S')` is the power basis for `S'` generated by `e pb.gen`. -/ @[simps dim gen basis] noncomputable def map (pb : PowerBasis R S) (e : S ≃ₐ[R] S') : PowerBasis R S' where dim := pb.dim basis := pb.basis.map e.toLinearEquiv gen := e pb.gen basis_eq_pow i := by rw [Basis.map_apply, pb.basis_eq_pow, e.toLinearEquiv_apply, map_pow] variable [Algebra A S] [Algebra A S'] -- @[simp] -- Porting note (#10618): simp can prove this theorem minpolyGen_map (pb : PowerBasis A S) (e : S ≃ₐ[A] S') : (pb.map e).minpolyGen = pb.minpolyGen := by dsimp only [minpolyGen, map_dim] -- Turn `Fin (pb.map e).dim` into `Fin pb.dim` simp only [LinearEquiv.trans_apply, map_basis, Basis.map_repr, map_gen, AlgEquiv.toLinearEquiv_apply, e.toLinearEquiv_symm, map_pow, AlgEquiv.symm_apply_apply, sub_right_inj] @[simp] theorem equivOfRoot_map (pb : PowerBasis A S) (e : S ≃ₐ[A] S') (h₁ h₂) : pb.equivOfRoot (pb.map e) h₁ h₂ = e := by ext x obtain ⟨f, rfl⟩ := pb.exists_eq_aeval' x simp [aeval_algEquiv] @[simp] theorem equivOfMinpoly_map (pb : PowerBasis A S) (e : S ≃ₐ[A] S') (h : minpoly A pb.gen = minpoly A (pb.map e).gen) : pb.equivOfMinpoly (pb.map e) h = e := pb.equivOfRoot_map _ _ _ end Map section Adjoin open Algebra theorem adjoin_gen_eq_top (B : PowerBasis R S) : adjoin R ({B.gen} : Set S) = ⊤ := by rw [← toSubmodule_eq_top, _root_.eq_top_iff, ← B.basis.span_eq, Submodule.span_le] rintro x ⟨i, rfl⟩ rw [B.basis_eq_pow i] exact Subalgebra.pow_mem _ (subset_adjoin (Set.mem_singleton _)) _ theorem adjoin_eq_top_of_gen_mem_adjoin {B : PowerBasis R S} {x : S} (hx : B.gen ∈ adjoin R ({x} : Set S)) : adjoin R ({x} : Set S) = ⊤ := by rw [_root_.eq_top_iff, ← B.adjoin_gen_eq_top] refine adjoin_le ?_ simp [hx] end Adjoin end PowerBasis
RingTheory\Presentation.lean
/- Copyright (c) 2024 Christian Merten. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jung Tao Cheng, Christian Merten, Andrew Yang -/ import Mathlib.LinearAlgebra.TensorProduct.RightExactness import Mathlib.RingTheory.FinitePresentation import Mathlib.RingTheory.Generators import Mathlib.RingTheory.MvPolynomial.Localization import Mathlib.RingTheory.TensorProduct.MvPolynomial /-! # Presentations of algebras A presentation of an `R`-algebra `S` is a distinguished family of generators and relations. ## Main definition - `Algebra.Presentation`: A presentation of an `R`-algebra `S` is a family of generators with 1. `rels`: The type of relations. 2. `relation : relations → MvPolynomial vars R`: The assignment of each relation to a polynomial in the generators. - `Algebra.Presentation.IsFinite`: A presentation is called finite, if both variables and relations are finite. - `Algebra.Presentation.dimension`: The dimension of a presentation is the number of generators minus the number of relations. We also give constructors for localization and base change. ## TODO - Define composition of presentations. - Define `Hom`s of presentations. ## Notes This contribution was created as part of the AIM workshop "Formalizing algebraic geometry" in June 2024. -/ universe t w u v open TensorProduct MvPolynomial variable (R : Type u) (S : Type v) [CommRing R] [CommRing S] [Algebra R S] /-- A presentation of an `R`-algebra `S` is a family of generators with 1. `rels`: The type of relations. 2. `relation : relations → MvPolynomial vars R`: The assignment of each relation to a polynomial in the generators. -/ @[nolint checkUnivs] structure Algebra.Presentation extends Algebra.Generators.{w} R S where /-- The type of relations. -/ rels : Type t /-- The assignment of each relation to a polynomial in the generators. -/ relation : rels → toGenerators.Ring /-- The relations span the kernel of the canonical map. -/ span_range_relation_eq_ker : Ideal.span (Set.range relation) = toGenerators.ker namespace Algebra.Presentation variable {R S} variable (P : Presentation.{t, w} R S) @[simp] lemma aeval_val_relation (i) : aeval P.val (P.relation i) = 0 := by rw [← RingHom.mem_ker, ← P.ker_eq_ker_aeval_val, ← P.span_range_relation_eq_ker] exact Ideal.subset_span ⟨i, rfl⟩ /-- The polynomial algebra wrt a family of generators modulo a family of relations. -/ protected abbrev Quotient : Type (max w u) := P.Ring ⧸ P.ker /-- `P.Quotient` is `P.Ring`-isomorphic to `S` and in particular `R`-isomorphic to `S`. -/ def quotientEquiv : P.Quotient ≃ₐ[P.Ring] S := Ideal.quotientKerAlgEquivOfRightInverse (f := Algebra.ofId P.Ring S) P.aeval_val_σ @[simp] lemma quotientEquiv_mk (p : P.Ring) : P.quotientEquiv p = algebraMap P.Ring S p := rfl @[simp] lemma quotientEquiv_symm (x : S) : P.quotientEquiv.symm x = P.σ x := rfl /-- Dimension of a presentation defined as the cardinality of the generators minus the cardinality of the relations. Note: this definition is completely non-sensical for non-finite presentations and even then for this to make sense, you should assume that the presentation is a complete intersection. -/ noncomputable def dimension : ℕ := Nat.card P.vars - Nat.card P.rels /-- A presentation is finite if there are only finitely-many relations and finitely-many relations. -/ class IsFinite (P : Presentation.{t, w} R S) : Prop where finite_vars : Finite P.vars finite_rels : Finite P.rels attribute [instance] IsFinite.finite_vars IsFinite.finite_rels lemma ideal_fg_of_isFinite [P.IsFinite] : P.ker.FG := by use (Set.finite_range P.relation).toFinset simp [span_range_relation_eq_ker] /-- If a presentation is finite, the corresponding quotient is of finite presentation. -/ instance [P.IsFinite] : FinitePresentation R P.Quotient := FinitePresentation.quotient P.ideal_fg_of_isFinite lemma finitePresentation_of_isFinite [P.IsFinite] : FinitePresentation R S := FinitePresentation.equiv (P.quotientEquiv.restrictScalars R) section Construction section Localization variable (r : R) [IsLocalization.Away r S] open IsLocalization.Away private lemma span_range_relation_eq_ker_localizationAway : Ideal.span { C r * X () - 1 } = RingHom.ker (aeval (S₁ := S) (Generators.localizationAway r).val) := by have : aeval (S₁ := S) (Generators.localizationAway r).val = (mvPolynomialQuotientEquiv S r).toAlgHom.comp (Ideal.Quotient.mkₐ R (Ideal.span {C r * X () - 1})) := by ext x simp only [Generators.localizationAway_vars, aeval_X, Generators.localizationAway_val, AlgEquiv.toAlgHom_eq_coe, AlgHom.coe_comp, AlgHom.coe_coe, Ideal.Quotient.mkₐ_eq_mk, Function.comp_apply] rw [IsLocalization.Away.mvPolynomialQuotientEquiv_apply, aeval_X] rw [this] erw [← RingHom.comap_ker] simp only [Generators.localizationAway_vars, AlgEquiv.toAlgHom_eq_coe, AlgHom.toRingHom_eq_coe, AlgEquiv.toAlgHom_toRingHom] show Ideal.span {C r * X () - 1} = Ideal.comap _ (RingHom.ker (mvPolynomialQuotientEquiv S r)) simp [RingHom.ker_equiv, ← RingHom.ker_eq_comap_bot] /-- If `S` is the localization of `R` away from `r`, we can construct a natural presentation of `S` as `R`-algebra with a single generator `X` and the relation `r * X - 1 = 0`. -/ @[simps relation, simps (config := .lemmasOnly) rels] noncomputable def localizationAway : Presentation R S where toGenerators := Generators.localizationAway r rels := Unit relation _ := C r * X () - 1 span_range_relation_eq_ker := by simp only [Generators.localizationAway_vars, Set.range_const] apply span_range_relation_eq_ker_localizationAway r instance localizationAway_isFinite : (localizationAway r (S := S)).IsFinite where finite_vars := inferInstanceAs <| Finite Unit finite_rels := inferInstanceAs <| Finite Unit @[simp] lemma localizationAway_dimension_zero : (localizationAway r (S := S)).dimension = 0 := by simp [Presentation.dimension, localizationAway, Generators.localizationAway_vars] end Localization variable {T} [CommRing T] [Algebra R T] (P : Presentation R S) private lemma span_range_relation_eq_ker_baseChange : Ideal.span (Set.range fun i ↦ (MvPolynomial.map (algebraMap R T)) (P.relation i)) = RingHom.ker (aeval (R := T) (S₁ := T ⊗[R] S) P.baseChange.val) := by apply le_antisymm · rw [Ideal.span_le] intro x ⟨y, hy⟩ have Z := aeval_val_relation P y apply_fun TensorProduct.includeRight (R := R) (A := T) at Z rw [map_zero] at Z simp only [SetLike.mem_coe, RingHom.mem_ker, ← Z, ← hy, algebraMap_apply, TensorProduct.includeRight_apply] erw [aeval_map_algebraMap] show _ = TensorProduct.includeRight _ erw [map_aeval, TensorProduct.includeRight.comp_algebraMap] rfl · intro x hx rw [RingHom.mem_ker] at hx have H := Algebra.TensorProduct.lTensor_ker (A := T) (IsScalarTower.toAlgHom R P.Ring S) P.algebraMap_surjective let e := MvPolynomial.algebraTensorAlgEquiv (R := R) (σ := P.vars) (A := T) have H' : e.symm x ∈ RingHom.ker (TensorProduct.map (AlgHom.id R T) (IsScalarTower.toAlgHom R P.Ring S)) := by rw [RingHom.mem_ker, ← hx] clear hx induction x using MvPolynomial.induction_on with | h_C a => simp only [Generators.algebraMap_apply, algHom_C, TensorProduct.algebraMap_apply, id.map_eq_id, RingHom.id_apply, e] erw [← MvPolynomial.algebraMap_eq, AlgEquiv.commutes] simp only [TensorProduct.algebraMap_apply, id.map_eq_id, RingHom.id_apply, TensorProduct.map_tmul, AlgHom.coe_id, id_eq, _root_.map_one, algebraMap_eq] erw [aeval_C] simp | h_add p q hp hq => simp only [map_add, hp, hq] | h_X p i hp => simp only [_root_.map_mul, algebraTensorAlgEquiv_symm_X, hp, TensorProduct.map_tmul, _root_.map_one, IsScalarTower.coe_toAlgHom', Generators.algebraMap_apply, aeval_X, e] congr erw [aeval_X] rw [Generators.baseChange_val] erw [H] at H' replace H' : e.symm x ∈ Ideal.map TensorProduct.includeRight P.ker := H' erw [← P.span_range_relation_eq_ker, ← Ideal.mem_comap, Ideal.comap_symm, Ideal.map_map, Ideal.map_span, ← Set.range_comp] at H' convert H' simp only [AlgHom.toRingHom_eq_coe, RingHom.coe_comp, RingHom.coe_coe, Function.comp_apply, TensorProduct.includeRight_apply, TensorProduct.lift_tmul, _root_.map_one, mapAlgHom_apply, one_mul] rfl /-- If `P` is a presentation of `S` over `R` and `T` is an `R`-algebra, we obtain a natural presentation of `T ⊗[R] S` over `T`. -/ @[simps relation, simps (config := .lemmasOnly) rels] noncomputable def baseChange : Presentation T (T ⊗[R] S) where __ := Generators.baseChange P.toGenerators rels := P.rels relation i := MvPolynomial.map (algebraMap R T) (P.relation i) span_range_relation_eq_ker := P.span_range_relation_eq_ker_baseChange end Construction end Presentation end Algebra
RingTheory\Prime.lean
/- Copyright (c) 2020 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.Associated.Basic import Mathlib.Algebra.BigOperators.Group.Finset import Mathlib.Algebra.Ring.Divisibility.Basic import Mathlib.Algebra.Order.Group.Unbundled.Abs /-! # Prime elements in rings This file contains lemmas about prime elements of commutative rings. -/ section CancelCommMonoidWithZero variable {R : Type*} [CancelCommMonoidWithZero R] open Finset /-- If `x * y = a * ∏ i ∈ s, p i` where `p i` is always prime, then `x` and `y` can both be written as a divisor of `a` multiplied by a product over a subset of `s` -/ theorem mul_eq_mul_prime_prod {α : Type*} [DecidableEq α] {x y a : R} {s : Finset α} {p : α → R} (hp : ∀ i ∈ s, Prime (p i)) (hx : x * y = a * ∏ i ∈ s, p i) : ∃ (t u : Finset α) (b c : R), t ∪ u = s ∧ Disjoint t u ∧ a = b * c ∧ (x = b * ∏ i ∈ t, p i) ∧ y = c * ∏ i ∈ u, p i := by induction' s using Finset.induction with i s his ih generalizing x y a · exact ⟨∅, ∅, x, y, by simp [hx]⟩ · rw [prod_insert his, ← mul_assoc] at hx have hpi : Prime (p i) := hp i (mem_insert_self _ _) rcases ih (fun i hi ↦ hp i (mem_insert_of_mem hi)) hx with ⟨t, u, b, c, htus, htu, hbc, rfl, rfl⟩ have hit : i ∉ t := fun hit ↦ his (htus ▸ mem_union_left _ hit) have hiu : i ∉ u := fun hiu ↦ his (htus ▸ mem_union_right _ hiu) obtain ⟨d, rfl⟩ | ⟨d, rfl⟩ : p i ∣ b ∨ p i ∣ c := hpi.dvd_or_dvd ⟨a, by rw [← hbc, mul_comm]⟩ · rw [mul_assoc, mul_comm a, mul_right_inj' hpi.ne_zero] at hbc exact ⟨insert i t, u, d, c, by rw [insert_union, htus], disjoint_insert_left.2 ⟨hiu, htu⟩, by simp [hbc, prod_insert hit, mul_assoc, mul_comm, mul_left_comm]⟩ · rw [← mul_assoc, mul_right_comm b, mul_left_inj' hpi.ne_zero] at hbc exact ⟨t, insert i u, b, d, by rw [union_insert, htus], disjoint_insert_right.2 ⟨hit, htu⟩, by simp [← hbc, prod_insert hiu, mul_assoc, mul_comm, mul_left_comm]⟩ /-- If `x * y = a * p ^ n` where `p` is prime, then `x` and `y` can both be written as the product of a power of `p` and a divisor of `a`. -/ theorem mul_eq_mul_prime_pow {x y a p : R} {n : ℕ} (hp : Prime p) (hx : x * y = a * p ^ n) : ∃ (i j : ℕ) (b c : R), i + j = n ∧ a = b * c ∧ x = b * p ^ i ∧ y = c * p ^ j := by rcases mul_eq_mul_prime_prod (fun _ _ ↦ hp) (show x * y = a * (range n).prod fun _ ↦ p by simpa) with ⟨t, u, b, c, htus, htu, rfl, rfl, rfl⟩ exact ⟨t.card, u.card, b, c, by rw [← card_union_of_disjoint htu, htus, card_range], by simp⟩ end CancelCommMonoidWithZero section CommRing variable {α : Type*} [CommRing α] theorem Prime.neg {p : α} (hp : Prime p) : Prime (-p) := by obtain ⟨h1, h2, h3⟩ := hp exact ⟨neg_ne_zero.mpr h1, by rwa [IsUnit.neg_iff], by simpa [neg_dvd] using h3⟩ theorem Prime.abs [LinearOrder α] {p : α} (hp : Prime p) : Prime (abs p) := by obtain h | h := abs_choice p <;> rw [h] · exact hp · exact hp.neg end CommRing
RingTheory\PrimeSpectrum.lean
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Filippo A. E. Nuccio, Andrew Yang -/ import Mathlib.LinearAlgebra.Finsupp import Mathlib.RingTheory.Ideal.Prod import Mathlib.RingTheory.Nilpotent.Lemmas import Mathlib.RingTheory.Noetherian /-! # Prime spectrum of a commutative (semi)ring as a type The prime spectrum of a commutative (semi)ring is the type of all prime ideals. For the Zariski topology, see `AlgebraicGeometry.PrimeSpectrum.Basic`. (It is also naturally endowed with a sheaf of rings, which is constructed in `AlgebraicGeometry.StructureSheaf`.) ## Main definitions * `PrimeSpectrum R`: The prime spectrum of a commutative (semi)ring `R`, i.e., the set of all prime ideals of `R`. * `zeroLocus s`: The zero locus of a subset `s` of `R` is the subset of `PrimeSpectrum R` consisting of all prime ideals that contain `s`. * `vanishingIdeal t`: The vanishing ideal of a subset `t` of `PrimeSpectrum R` is the intersection of points in `t` (viewed as prime ideals). ## Conventions We denote subsets of (semi)rings with `s`, `s'`, etc... whereas we denote subsets of prime spectra with `t`, `t'`, etc... ## Inspiration/contributors The contents of this file draw inspiration from <https://github.com/ramonfmir/lean-scheme> which has contributions from Ramon Fernandez Mir, Kevin Buzzard, Kenny Lau, and Chris Hughes (on an earlier repository). -/ -- A dividing line between this file and `AlgebraicGeometry.PrimeSpectrum.Basic` is -- that we should not depened on the Zariski topology here assert_not_exists TopologicalSpace noncomputable section open scoped Classical universe u v variable (R : Type u) (S : Type v) /-- The prime spectrum of a commutative (semi)ring `R` is the type of all prime ideals of `R`. It is naturally endowed with a topology (the Zariski topology), and a sheaf of commutative rings (see `AlgebraicGeometry.StructureSheaf`). It is a fundamental building block in algebraic geometry. -/ @[ext] structure PrimeSpectrum [CommSemiring R] where asIdeal : Ideal R isPrime : asIdeal.IsPrime @[deprecated (since := "2024-06-22")] alias PrimeSpectrum.IsPrime := PrimeSpectrum.isPrime attribute [instance] PrimeSpectrum.isPrime namespace PrimeSpectrum section CommSemiRing variable [CommSemiring R] [CommSemiring S] variable {R S} instance [Nontrivial R] : Nonempty <| PrimeSpectrum R := let ⟨I, hI⟩ := Ideal.exists_maximal R ⟨⟨I, hI.isPrime⟩⟩ /-- The prime spectrum of the zero ring is empty. -/ instance [Subsingleton R] : IsEmpty (PrimeSpectrum R) := ⟨fun x ↦ x.isPrime.ne_top <| SetLike.ext' <| Subsingleton.eq_univ_of_nonempty x.asIdeal.nonempty⟩ variable (R S) /-- The map from the direct sum of prime spectra to the prime spectrum of a direct product. -/ @[simp] def primeSpectrumProdOfSum : PrimeSpectrum R ⊕ PrimeSpectrum S → PrimeSpectrum (R × S) | Sum.inl ⟨I, _⟩ => ⟨Ideal.prod I ⊤, Ideal.isPrime_ideal_prod_top⟩ | Sum.inr ⟨J, _⟩ => ⟨Ideal.prod ⊤ J, Ideal.isPrime_ideal_prod_top'⟩ /-- The prime spectrum of `R × S` is in bijection with the disjoint unions of the prime spectrum of `R` and the prime spectrum of `S`. -/ noncomputable def primeSpectrumProd : PrimeSpectrum (R × S) ≃ PrimeSpectrum R ⊕ PrimeSpectrum S := Equiv.symm <| Equiv.ofBijective (primeSpectrumProdOfSum R S) (by constructor · rintro (⟨I, hI⟩ | ⟨J, hJ⟩) (⟨I', hI'⟩ | ⟨J', hJ'⟩) h <;> simp only [mk.injEq, Ideal.prod.ext_iff, primeSpectrumProdOfSum] at h · simp only [h] · exact False.elim (hI.ne_top h.left) · exact False.elim (hJ.ne_top h.right) · simp only [h] · rintro ⟨I, hI⟩ rcases (Ideal.ideal_prod_prime I).mp hI with (⟨p, ⟨hp, rfl⟩⟩ | ⟨p, ⟨hp, rfl⟩⟩) · exact ⟨Sum.inl ⟨p, hp⟩, rfl⟩ · exact ⟨Sum.inr ⟨p, hp⟩, rfl⟩) variable {R S} @[simp] theorem primeSpectrumProd_symm_inl_asIdeal (x : PrimeSpectrum R) : ((primeSpectrumProd R S).symm <| Sum.inl x).asIdeal = Ideal.prod x.asIdeal ⊤ := by cases x rfl @[simp] theorem primeSpectrumProd_symm_inr_asIdeal (x : PrimeSpectrum S) : ((primeSpectrumProd R S).symm <| Sum.inr x).asIdeal = Ideal.prod ⊤ x.asIdeal := by cases x rfl /-- The zero locus of a set `s` of elements of a commutative (semi)ring `R` is the set of all prime ideals of the ring that contain the set `s`. An element `f` of `R` can be thought of as a dependent function on the prime spectrum of `R`. At a point `x` (a prime ideal) the function (i.e., element) `f` takes values in the quotient ring `R` modulo the prime ideal `x`. In this manner, `zeroLocus s` is exactly the subset of `PrimeSpectrum R` where all "functions" in `s` vanish simultaneously. -/ def zeroLocus (s : Set R) : Set (PrimeSpectrum R) := { x | s ⊆ x.asIdeal } @[simp] theorem mem_zeroLocus (x : PrimeSpectrum R) (s : Set R) : x ∈ zeroLocus s ↔ s ⊆ x.asIdeal := Iff.rfl @[simp] theorem zeroLocus_span (s : Set R) : zeroLocus (Ideal.span s : Set R) = zeroLocus s := by ext x exact (Submodule.gi R R).gc s x.asIdeal /-- The vanishing ideal of a set `t` of points of the prime spectrum of a commutative ring `R` is the intersection of all the prime ideals in the set `t`. An element `f` of `R` can be thought of as a dependent function on the prime spectrum of `R`. At a point `x` (a prime ideal) the function (i.e., element) `f` takes values in the quotient ring `R` modulo the prime ideal `x`. In this manner, `vanishingIdeal t` is exactly the ideal of `R` consisting of all "functions" that vanish on all of `t`. -/ def vanishingIdeal (t : Set (PrimeSpectrum R)) : Ideal R := ⨅ x ∈ t, x.asIdeal theorem coe_vanishingIdeal (t : Set (PrimeSpectrum R)) : (vanishingIdeal t : Set R) = { f : R | ∀ x ∈ t, f ∈ x.asIdeal } := by ext f rw [vanishingIdeal, SetLike.mem_coe, Submodule.mem_iInf] apply forall_congr'; intro x rw [Submodule.mem_iInf] theorem mem_vanishingIdeal (t : Set (PrimeSpectrum R)) (f : R) : f ∈ vanishingIdeal t ↔ ∀ x ∈ t, f ∈ x.asIdeal := by rw [← SetLike.mem_coe, coe_vanishingIdeal, Set.mem_setOf_eq] @[simp] theorem vanishingIdeal_singleton (x : PrimeSpectrum R) : vanishingIdeal ({x} : Set (PrimeSpectrum R)) = x.asIdeal := by simp [vanishingIdeal] theorem subset_zeroLocus_iff_le_vanishingIdeal (t : Set (PrimeSpectrum R)) (I : Ideal R) : t ⊆ zeroLocus I ↔ I ≤ vanishingIdeal t := ⟨fun h _ k => (mem_vanishingIdeal _ _).mpr fun _ j => (mem_zeroLocus _ _).mpr (h j) k, fun h => fun x j => (mem_zeroLocus _ _).mpr (le_trans h fun _ h => ((mem_vanishingIdeal _ _).mp h) x j)⟩ section Gc variable (R) /-- `zeroLocus` and `vanishingIdeal` form a galois connection. -/ theorem gc : @GaloisConnection (Ideal R) (Set (PrimeSpectrum R))ᵒᵈ _ _ (fun I => zeroLocus I) fun t => vanishingIdeal t := fun I t => subset_zeroLocus_iff_le_vanishingIdeal t I /-- `zeroLocus` and `vanishingIdeal` form a galois connection. -/ theorem gc_set : @GaloisConnection (Set R) (Set (PrimeSpectrum R))ᵒᵈ _ _ (fun s => zeroLocus s) fun t => vanishingIdeal t := by have ideal_gc : GaloisConnection Ideal.span _ := (Submodule.gi R R).gc simpa [zeroLocus_span, Function.comp] using ideal_gc.compose (gc R) theorem subset_zeroLocus_iff_subset_vanishingIdeal (t : Set (PrimeSpectrum R)) (s : Set R) : t ⊆ zeroLocus s ↔ s ⊆ vanishingIdeal t := (gc_set R) s t end Gc theorem subset_vanishingIdeal_zeroLocus (s : Set R) : s ⊆ vanishingIdeal (zeroLocus s) := (gc_set R).le_u_l s theorem le_vanishingIdeal_zeroLocus (I : Ideal R) : I ≤ vanishingIdeal (zeroLocus I) := (gc R).le_u_l I @[simp] theorem vanishingIdeal_zeroLocus_eq_radical (I : Ideal R) : vanishingIdeal (zeroLocus (I : Set R)) = I.radical := Ideal.ext fun f => by rw [mem_vanishingIdeal, Ideal.radical_eq_sInf, Submodule.mem_sInf] exact ⟨fun h x hx => h ⟨x, hx.2⟩ hx.1, fun h x hx => h x.1 ⟨hx, x.2⟩⟩ @[simp] theorem zeroLocus_radical (I : Ideal R) : zeroLocus (I.radical : Set R) = zeroLocus I := vanishingIdeal_zeroLocus_eq_radical I ▸ (gc R).l_u_l_eq_l I theorem subset_zeroLocus_vanishingIdeal (t : Set (PrimeSpectrum R)) : t ⊆ zeroLocus (vanishingIdeal t) := (gc R).l_u_le t theorem zeroLocus_anti_mono {s t : Set R} (h : s ⊆ t) : zeroLocus t ⊆ zeroLocus s := (gc_set R).monotone_l h theorem zeroLocus_anti_mono_ideal {s t : Ideal R} (h : s ≤ t) : zeroLocus (t : Set R) ⊆ zeroLocus (s : Set R) := (gc R).monotone_l h theorem vanishingIdeal_anti_mono {s t : Set (PrimeSpectrum R)} (h : s ⊆ t) : vanishingIdeal t ≤ vanishingIdeal s := (gc R).monotone_u h theorem zeroLocus_subset_zeroLocus_iff (I J : Ideal R) : zeroLocus (I : Set R) ⊆ zeroLocus (J : Set R) ↔ J ≤ I.radical := by rw [subset_zeroLocus_iff_le_vanishingIdeal, vanishingIdeal_zeroLocus_eq_radical] theorem zeroLocus_subset_zeroLocus_singleton_iff (f g : R) : zeroLocus ({f} : Set R) ⊆ zeroLocus {g} ↔ g ∈ (Ideal.span ({f} : Set R)).radical := by rw [← zeroLocus_span {f}, ← zeroLocus_span {g}, zeroLocus_subset_zeroLocus_iff, Ideal.span_le, Set.singleton_subset_iff, SetLike.mem_coe] theorem zeroLocus_bot : zeroLocus ((⊥ : Ideal R) : Set R) = Set.univ := (gc R).l_bot @[simp] theorem zeroLocus_singleton_zero : zeroLocus ({0} : Set R) = Set.univ := zeroLocus_bot @[simp] theorem zeroLocus_empty : zeroLocus (∅ : Set R) = Set.univ := (gc_set R).l_bot @[simp] theorem vanishingIdeal_empty : vanishingIdeal (∅ : Set (PrimeSpectrum R)) = ⊤ := by simpa using (gc R).u_top theorem zeroLocus_empty_of_one_mem {s : Set R} (h : (1 : R) ∈ s) : zeroLocus s = ∅ := by rw [Set.eq_empty_iff_forall_not_mem] intro x hx rw [mem_zeroLocus] at hx have x_prime : x.asIdeal.IsPrime := by infer_instance have eq_top : x.asIdeal = ⊤ := by rw [Ideal.eq_top_iff_one] exact hx h apply x_prime.ne_top eq_top @[simp] theorem zeroLocus_singleton_one : zeroLocus ({1} : Set R) = ∅ := zeroLocus_empty_of_one_mem (Set.mem_singleton (1 : R)) theorem zeroLocus_empty_iff_eq_top {I : Ideal R} : zeroLocus (I : Set R) = ∅ ↔ I = ⊤ := by constructor · contrapose! intro h rcases Ideal.exists_le_maximal I h with ⟨M, hM, hIM⟩ exact ⟨⟨M, hM.isPrime⟩, hIM⟩ · rintro rfl apply zeroLocus_empty_of_one_mem trivial @[simp] theorem zeroLocus_univ : zeroLocus (Set.univ : Set R) = ∅ := zeroLocus_empty_of_one_mem (Set.mem_univ 1) theorem vanishingIdeal_eq_top_iff {s : Set (PrimeSpectrum R)} : vanishingIdeal s = ⊤ ↔ s = ∅ := by rw [← top_le_iff, ← subset_zeroLocus_iff_le_vanishingIdeal, Submodule.top_coe, zeroLocus_univ, Set.subset_empty_iff] theorem zeroLocus_eq_top_iff (s : Set R) : zeroLocus s = ⊤ ↔ s ⊆ nilradical R := by constructor · intro h x hx refine nilpotent_iff_mem_prime.mpr (fun J hJ ↦ ?_) have hJz : ⟨J, hJ⟩ ∈ zeroLocus s := by rw [h] trivial exact (mem_zeroLocus _ _).mpr hJz hx · rw [eq_top_iff] intro h p _ apply Set.Subset.trans h (nilradical_le_prime p.asIdeal) theorem zeroLocus_sup (I J : Ideal R) : zeroLocus ((I ⊔ J : Ideal R) : Set R) = zeroLocus I ∩ zeroLocus J := (gc R).l_sup theorem zeroLocus_union (s s' : Set R) : zeroLocus (s ∪ s') = zeroLocus s ∩ zeroLocus s' := (gc_set R).l_sup theorem vanishingIdeal_union (t t' : Set (PrimeSpectrum R)) : vanishingIdeal (t ∪ t') = vanishingIdeal t ⊓ vanishingIdeal t' := (gc R).u_inf theorem zeroLocus_iSup {ι : Sort*} (I : ι → Ideal R) : zeroLocus ((⨆ i, I i : Ideal R) : Set R) = ⋂ i, zeroLocus (I i) := (gc R).l_iSup theorem zeroLocus_iUnion {ι : Sort*} (s : ι → Set R) : zeroLocus (⋃ i, s i) = ⋂ i, zeroLocus (s i) := (gc_set R).l_iSup theorem zeroLocus_iUnion₂ {ι : Sort*} {κ : (i : ι) → Sort*} (s : ∀ i, κ i → Set R) : zeroLocus (⋃ (i) (j), s i j) = ⋂ (i) (j), zeroLocus (s i j) := (gc_set R).l_iSup₂ theorem zeroLocus_bUnion (s : Set (Set R)) : zeroLocus (⋃ s' ∈ s, s' : Set R) = ⋂ s' ∈ s, zeroLocus s' := by simp only [zeroLocus_iUnion] theorem vanishingIdeal_iUnion {ι : Sort*} (t : ι → Set (PrimeSpectrum R)) : vanishingIdeal (⋃ i, t i) = ⨅ i, vanishingIdeal (t i) := (gc R).u_iInf theorem zeroLocus_inf (I J : Ideal R) : zeroLocus ((I ⊓ J : Ideal R) : Set R) = zeroLocus I ∪ zeroLocus J := Set.ext fun x => x.2.inf_le theorem union_zeroLocus (s s' : Set R) : zeroLocus s ∪ zeroLocus s' = zeroLocus (Ideal.span s ⊓ Ideal.span s' : Ideal R) := by rw [zeroLocus_inf] simp theorem zeroLocus_mul (I J : Ideal R) : zeroLocus ((I * J : Ideal R) : Set R) = zeroLocus I ∪ zeroLocus J := Set.ext fun x => x.2.mul_le theorem zeroLocus_singleton_mul (f g : R) : zeroLocus ({f * g} : Set R) = zeroLocus {f} ∪ zeroLocus {g} := Set.ext fun x => by simpa using x.2.mul_mem_iff_mem_or_mem @[simp] theorem zeroLocus_pow (I : Ideal R) {n : ℕ} (hn : n ≠ 0) : zeroLocus ((I ^ n : Ideal R) : Set R) = zeroLocus I := zeroLocus_radical (I ^ n) ▸ (I.radical_pow hn).symm ▸ zeroLocus_radical I @[simp] theorem zeroLocus_singleton_pow (f : R) (n : ℕ) (hn : 0 < n) : zeroLocus ({f ^ n} : Set R) = zeroLocus {f} := Set.ext fun x => by simpa using x.2.pow_mem_iff_mem n hn theorem sup_vanishingIdeal_le (t t' : Set (PrimeSpectrum R)) : vanishingIdeal t ⊔ vanishingIdeal t' ≤ vanishingIdeal (t ∩ t') := by intro r rw [Submodule.mem_sup, mem_vanishingIdeal] rintro ⟨f, hf, g, hg, rfl⟩ x ⟨hxt, hxt'⟩ rw [mem_vanishingIdeal] at hf hg apply Submodule.add_mem <;> solve_by_elim theorem mem_compl_zeroLocus_iff_not_mem {f : R} {I : PrimeSpectrum R} : I ∈ (zeroLocus {f} : Set (PrimeSpectrum R))ᶜ ↔ f ∉ I.asIdeal := by rw [Set.mem_compl_iff, mem_zeroLocus, Set.singleton_subset_iff]; rfl section Order /-! ## The specialization order We endow `PrimeSpectrum R` with a partial order induced from the ideal lattice. This is exactly the specialization order. See the corresponding section at `Mathlib.AlgebraicGeometry.PrimeSpectrum.Basic`. -/ instance : PartialOrder (PrimeSpectrum R) := PartialOrder.lift asIdeal (@PrimeSpectrum.ext _ _) @[simp] theorem asIdeal_le_asIdeal (x y : PrimeSpectrum R) : x.asIdeal ≤ y.asIdeal ↔ x ≤ y := Iff.rfl @[simp] theorem asIdeal_lt_asIdeal (x y : PrimeSpectrum R) : x.asIdeal < y.asIdeal ↔ x < y := Iff.rfl instance [IsDomain R] : OrderBot (PrimeSpectrum R) where bot := ⟨⊥, Ideal.bot_prime⟩ bot_le I := @bot_le _ _ _ I.asIdeal instance {R : Type*} [Field R] : Unique (PrimeSpectrum R) where default := ⊥ uniq x := PrimeSpectrum.ext ((IsSimpleOrder.eq_bot_or_eq_top _).resolve_right x.2.ne_top) end Order section Noetherian open Submodule variable (R : Type u) [CommRing R] [IsNoetherianRing R] variable {A : Type u} [CommRing A] [IsDomain A] [IsNoetherianRing A] /-- In a noetherian ring, every ideal contains a product of prime ideals ([samuel, § 3.3, Lemma 3])-/ theorem exists_primeSpectrum_prod_le (I : Ideal R) : ∃ Z : Multiset (PrimeSpectrum R), Multiset.prod (Z.map asIdeal) ≤ I := by -- Porting note: Need to specify `P` explicitly refine IsNoetherian.induction (P := fun I => ∃ Z : Multiset (PrimeSpectrum R), Multiset.prod (Z.map asIdeal) ≤ I) (fun (M : Ideal R) hgt => ?_) I by_cases h_prM : M.IsPrime · use {⟨M, h_prM⟩} rw [Multiset.map_singleton, Multiset.prod_singleton] by_cases htop : M = ⊤ · rw [htop] exact ⟨0, le_top⟩ have lt_add : ∀ z ∉ M, M < M + span R {z} := by intro z hz refine lt_of_le_of_ne le_sup_left fun m_eq => hz ?_ rw [m_eq] exact Ideal.mem_sup_right (mem_span_singleton_self z) obtain ⟨x, hx, y, hy, hxy⟩ := (Ideal.not_isPrime_iff.mp h_prM).resolve_left htop obtain ⟨Wx, h_Wx⟩ := hgt (M + span R {x}) (lt_add _ hx) obtain ⟨Wy, h_Wy⟩ := hgt (M + span R {y}) (lt_add _ hy) use Wx + Wy rw [Multiset.map_add, Multiset.prod_add] apply le_trans (Submodule.mul_le_mul h_Wx h_Wy) rw [add_mul] apply sup_le (show M * (M + span R {y}) ≤ M from Ideal.mul_le_right) rw [mul_add] apply sup_le (show span R {x} * M ≤ M from Ideal.mul_le_left) rwa [span_mul_span, Set.singleton_mul_singleton, span_singleton_le_iff_mem] /-- In a noetherian integral domain which is not a field, every non-zero ideal contains a non-zero product of prime ideals; in a field, the whole ring is a non-zero ideal containing only 0 as product or prime ideals ([samuel, § 3.3, Lemma 3]) -/ theorem exists_primeSpectrum_prod_le_and_ne_bot_of_domain (h_fA : ¬IsField A) {I : Ideal A} (h_nzI : I ≠ ⊥) : ∃ Z : Multiset (PrimeSpectrum A), Multiset.prod (Z.map asIdeal) ≤ I ∧ Multiset.prod (Z.map asIdeal) ≠ ⊥ := by revert h_nzI -- Porting note: Need to specify `P` explicitly refine IsNoetherian.induction (P := fun I => I ≠ ⊥ → ∃ Z : Multiset (PrimeSpectrum A), Multiset.prod (Z.map asIdeal) ≤ I ∧ Multiset.prod (Z.map asIdeal) ≠ ⊥) (fun (M : Ideal A) hgt => ?_) I intro h_nzM have hA_nont : Nontrivial A := IsDomain.toNontrivial by_cases h_topM : M = ⊤ · rcases h_topM with rfl obtain ⟨p_id, h_nzp, h_pp⟩ : ∃ p : Ideal A, p ≠ ⊥ ∧ p.IsPrime := by apply Ring.not_isField_iff_exists_prime.mp h_fA use ({⟨p_id, h_pp⟩} : Multiset (PrimeSpectrum A)), le_top rwa [Multiset.map_singleton, Multiset.prod_singleton] by_cases h_prM : M.IsPrime · use ({⟨M, h_prM⟩} : Multiset (PrimeSpectrum A)) rw [Multiset.map_singleton, Multiset.prod_singleton] exact ⟨le_rfl, h_nzM⟩ obtain ⟨x, hx, y, hy, h_xy⟩ := (Ideal.not_isPrime_iff.mp h_prM).resolve_left h_topM have lt_add : ∀ z ∉ M, M < M + span A {z} := by intro z hz refine lt_of_le_of_ne le_sup_left fun m_eq => hz ?_ rw [m_eq] exact mem_sup_right (mem_span_singleton_self z) obtain ⟨Wx, h_Wx_le, h_Wx_ne⟩ := hgt (M + span A {x}) (lt_add _ hx) (ne_bot_of_gt (lt_add _ hx)) obtain ⟨Wy, h_Wy_le, h_Wx_ne⟩ := hgt (M + span A {y}) (lt_add _ hy) (ne_bot_of_gt (lt_add _ hy)) use Wx + Wy rw [Multiset.map_add, Multiset.prod_add] refine ⟨le_trans (Submodule.mul_le_mul h_Wx_le h_Wy_le) ?_, mt Ideal.mul_eq_bot.mp ?_⟩ · rw [add_mul] apply sup_le (show M * (M + span A {y}) ≤ M from Ideal.mul_le_right) rw [mul_add] apply sup_le (show span A {x} * M ≤ M from Ideal.mul_le_left) rwa [span_mul_span, Set.singleton_mul_singleton, span_singleton_le_iff_mem] · rintro (hx | hy) <;> contradiction end Noetherian end CommSemiRing end PrimeSpectrum
RingTheory\PrincipalIdealDomain.lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Morenikeji Neri -/ import Mathlib.Algebra.EuclideanDomain.Field import Mathlib.RingTheory.Ideal.Colon import Mathlib.RingTheory.UniqueFactorizationDomain /-! # Principal ideal rings, principal ideal domains, and Bézout rings A principal ideal ring (PIR) is a ring in which all left ideals are principal. A principal ideal domain (PID) is an integral domain which is a principal ideal ring. # Main definitions Note that for principal ideal domains, one should use `[IsDomain R] [IsPrincipalIdealRing R]`. There is no explicit definition of a PID. Theorems about PID's are in the `principal_ideal_ring` namespace. - `IsPrincipalIdealRing`: a predicate on rings, saying that every left ideal is principal. - `IsBezout`: the predicate saying that every finitely generated left ideal is principal. - `generator`: a generator of a principal ideal (or more generally submodule) - `to_unique_factorization_monoid`: a PID is a unique factorization domain # Main results - `to_maximal_ideal`: a non-zero prime ideal in a PID is maximal. - `EuclideanDomain.to_principal_ideal_domain` : a Euclidean domain is a PID. - `IsBezout.nonemptyGCDMonoid`: Every Bézout domain is a GCD domain. -/ universe u v variable {R : Type u} {M : Type v} open Set Function open Submodule section variable [Ring R] [AddCommGroup M] [Module R M] instance bot_isPrincipal : (⊥ : Submodule R M).IsPrincipal := ⟨⟨0, by simp⟩⟩ instance top_isPrincipal : (⊤ : Submodule R R).IsPrincipal := ⟨⟨1, Ideal.span_singleton_one.symm⟩⟩ variable (R) /-- A Bézout ring is a ring whose finitely generated ideals are principal. -/ class IsBezout : Prop where /-- Any finitely generated ideal is principal. -/ isPrincipal_of_FG : ∀ I : Ideal R, I.FG → I.IsPrincipal instance (priority := 100) IsBezout.of_isPrincipalIdealRing [IsPrincipalIdealRing R] : IsBezout R := ⟨fun I _ => IsPrincipalIdealRing.principal I⟩ instance (priority := 100) DivisionRing.isPrincipalIdealRing (K : Type u) [DivisionRing K] : IsPrincipalIdealRing K where principal S := by rcases Ideal.eq_bot_or_top S with (rfl | rfl) · apply bot_isPrincipal · apply top_isPrincipal end namespace Submodule.IsPrincipal variable [AddCommGroup M] section Ring variable [Ring R] [Module R M] /-- `generator I`, if `I` is a principal submodule, is an `x ∈ M` such that `span R {x} = I` -/ noncomputable def generator (S : Submodule R M) [S.IsPrincipal] : M := Classical.choose (principal S) theorem span_singleton_generator (S : Submodule R M) [S.IsPrincipal] : span R {generator S} = S := Eq.symm (Classical.choose_spec (principal S)) @[simp] theorem _root_.Ideal.span_singleton_generator (I : Ideal R) [I.IsPrincipal] : Ideal.span ({generator I} : Set R) = I := Eq.symm (Classical.choose_spec (principal I)) @[simp] theorem generator_mem (S : Submodule R M) [S.IsPrincipal] : generator S ∈ S := by conv_rhs => rw [← span_singleton_generator S] exact subset_span (mem_singleton _) theorem mem_iff_eq_smul_generator (S : Submodule R M) [S.IsPrincipal] {x : M} : x ∈ S ↔ ∃ s : R, x = s • generator S := by simp_rw [@eq_comm _ x, ← mem_span_singleton, span_singleton_generator] theorem eq_bot_iff_generator_eq_zero (S : Submodule R M) [S.IsPrincipal] : S = ⊥ ↔ generator S = 0 := by rw [← @span_singleton_eq_bot R M, span_singleton_generator] end Ring section CommRing variable [CommRing R] [Module R M] theorem associated_generator_span_self [IsPrincipalIdealRing R] [IsDomain R] (r : R) : Associated (generator <| Ideal.span {r}) r := by rw [← Ideal.span_singleton_eq_span_singleton] exact Ideal.span_singleton_generator _ theorem mem_iff_generator_dvd (S : Ideal R) [S.IsPrincipal] {x : R} : x ∈ S ↔ generator S ∣ x := (mem_iff_eq_smul_generator S).trans (exists_congr fun a => by simp only [mul_comm, smul_eq_mul]) theorem prime_generator_of_isPrime (S : Ideal R) [S.IsPrincipal] [is_prime : S.IsPrime] (ne_bot : S ≠ ⊥) : Prime (generator S) := ⟨fun h => ne_bot ((eq_bot_iff_generator_eq_zero S).2 h), fun h => is_prime.ne_top (S.eq_top_of_isUnit_mem (generator_mem S) h), fun _ _ => by simpa only [← mem_iff_generator_dvd S] using is_prime.2⟩ -- Note that the converse may not hold if `ϕ` is not injective. theorem generator_map_dvd_of_mem {N : Submodule R M} (ϕ : M →ₗ[R] R) [(N.map ϕ).IsPrincipal] {x : M} (hx : x ∈ N) : generator (N.map ϕ) ∣ ϕ x := by rw [← mem_iff_generator_dvd, Submodule.mem_map] exact ⟨x, hx, rfl⟩ -- Note that the converse may not hold if `ϕ` is not injective. theorem generator_submoduleImage_dvd_of_mem {N O : Submodule R M} (hNO : N ≤ O) (ϕ : O →ₗ[R] R) [(ϕ.submoduleImage N).IsPrincipal] {x : M} (hx : x ∈ N) : generator (ϕ.submoduleImage N) ∣ ϕ ⟨x, hNO hx⟩ := by rw [← mem_iff_generator_dvd, LinearMap.mem_submoduleImage_of_le hNO] exact ⟨x, hx, rfl⟩ end CommRing end Submodule.IsPrincipal namespace IsBezout section variable [Ring R] instance span_pair_isPrincipal [IsBezout R] (x y : R) : (Ideal.span {x, y}).IsPrincipal := by classical exact isPrincipal_of_FG (Ideal.span {x, y}) ⟨{x, y}, by simp⟩ variable (x y : R) [(Ideal.span {x, y}).IsPrincipal] /-- A choice of gcd of two elements in a Bézout domain. Note that the choice is usually not unique. -/ noncomputable def gcd : R := Submodule.IsPrincipal.generator (Ideal.span {x, y}) theorem span_gcd : Ideal.span {gcd x y} = Ideal.span {x, y} := Ideal.span_singleton_generator _ end variable [CommRing R] (x y z : R) [(Ideal.span {x, y}).IsPrincipal] theorem gcd_dvd_left : gcd x y ∣ x := (Submodule.IsPrincipal.mem_iff_generator_dvd _).mp (Ideal.subset_span (by simp)) theorem gcd_dvd_right : gcd x y ∣ y := (Submodule.IsPrincipal.mem_iff_generator_dvd _).mp (Ideal.subset_span (by simp)) variable {x y z} in theorem dvd_gcd (hx : z ∣ x) (hy : z ∣ y) : z ∣ gcd x y := by rw [← Ideal.span_singleton_le_span_singleton] at hx hy ⊢ rw [span_gcd, Ideal.span_insert, sup_le_iff] exact ⟨hx, hy⟩ theorem gcd_eq_sum : ∃ a b : R, a * x + b * y = gcd x y := Ideal.mem_span_pair.mp (by rw [← span_gcd]; apply Ideal.subset_span; simp) variable {x y} theorem _root_.IsRelPrime.isCoprime (h : IsRelPrime x y) : IsCoprime x y := by rw [← Ideal.isCoprime_span_singleton_iff, Ideal.isCoprime_iff_sup_eq, ← Ideal.span_union, Set.singleton_union, ← span_gcd, Ideal.span_singleton_eq_top] exact h (gcd_dvd_left x y) (gcd_dvd_right x y) theorem _root_.isRelPrime_iff_isCoprime : IsRelPrime x y ↔ IsCoprime x y := ⟨IsRelPrime.isCoprime, IsCoprime.isRelPrime⟩ variable (R) /-- Any Bézout domain is a GCD domain. This is not an instance since `GCDMonoid` contains data, and this might not be how we would like to construct it. -/ noncomputable def toGCDDomain [IsBezout R] [IsDomain R] [DecidableEq R] : GCDMonoid R := gcdMonoidOfGCD (gcd · ·) (gcd_dvd_left · ·) (gcd_dvd_right · ·) dvd_gcd instance nonemptyGCDMonoid [IsBezout R] [IsDomain R] : Nonempty (GCDMonoid R) := by classical exact ⟨toGCDDomain R⟩ theorem associated_gcd_gcd [IsDomain R] [GCDMonoid R] : Associated (IsBezout.gcd x y) (GCDMonoid.gcd x y) := gcd_greatest_associated (gcd_dvd_left _ _ ) (gcd_dvd_right _ _) (fun _ => dvd_gcd) end IsBezout namespace IsPrime open Submodule.IsPrincipal Ideal -- TODO -- for a non-ID one could perhaps prove that if p < q are prime then q maximal; -- 0 isn't prime in a non-ID PIR but the Krull dimension is still <= 1. -- The below result follows from this, but we could also use the below result to -- prove this (quotient out by p). theorem to_maximal_ideal [CommRing R] [IsDomain R] [IsPrincipalIdealRing R] {S : Ideal R} [hpi : IsPrime S] (hS : S ≠ ⊥) : IsMaximal S := isMaximal_iff.2 ⟨(ne_top_iff_one S).1 hpi.1, by intro T x hST hxS hxT cases' (mem_iff_generator_dvd _).1 (hST <| generator_mem S) with z hz cases hpi.mem_or_mem (show generator T * z ∈ S from hz ▸ generator_mem S) with | inl h => have hTS : T ≤ S := by rwa [← T.span_singleton_generator, Ideal.span_le, singleton_subset_iff] exact (hxS <| hTS hxT).elim | inr h => cases' (mem_iff_generator_dvd _).1 h with y hy have : generator S ≠ 0 := mt (eq_bot_iff_generator_eq_zero _).2 hS rw [← mul_one (generator S), hy, mul_left_comm, mul_right_inj' this] at hz exact hz.symm ▸ T.mul_mem_right _ (generator_mem T)⟩ end IsPrime section open EuclideanDomain variable [EuclideanDomain R] theorem mod_mem_iff {S : Ideal R} {x y : R} (hy : y ∈ S) : x % y ∈ S ↔ x ∈ S := ⟨fun hxy => div_add_mod x y ▸ S.add_mem (S.mul_mem_right _ hy) hxy, fun hx => (mod_eq_sub_mul_div x y).symm ▸ S.sub_mem hx (S.mul_mem_right _ hy)⟩ -- see Note [lower instance priority] instance (priority := 100) EuclideanDomain.to_principal_ideal_domain : IsPrincipalIdealRing R where principal S := by classical exact ⟨if h : { x : R | x ∈ S ∧ x ≠ 0 }.Nonempty then have wf : WellFounded (EuclideanDomain.r : R → R → Prop) := EuclideanDomain.r_wellFounded have hmin : WellFounded.min wf { x : R | x ∈ S ∧ x ≠ 0 } h ∈ S ∧ WellFounded.min wf { x : R | x ∈ S ∧ x ≠ 0 } h ≠ 0 := WellFounded.min_mem wf { x : R | x ∈ S ∧ x ≠ 0 } h ⟨WellFounded.min wf { x : R | x ∈ S ∧ x ≠ 0 } h, Submodule.ext fun x => ⟨fun hx => div_add_mod x (WellFounded.min wf { x : R | x ∈ S ∧ x ≠ 0 } h) ▸ (Ideal.mem_span_singleton.2 <| dvd_add (dvd_mul_right _ _) <| by have : x % WellFounded.min wf { x : R | x ∈ S ∧ x ≠ 0 } h ∉ { x : R | x ∈ S ∧ x ≠ 0 } := fun h₁ => WellFounded.not_lt_min wf _ h h₁ (mod_lt x hmin.2) have : x % WellFounded.min wf { x : R | x ∈ S ∧ x ≠ 0 } h = 0 := by simp only [not_and_or, Set.mem_setOf_eq, not_ne_iff] at this exact this.neg_resolve_left <| (mod_mem_iff hmin.1).2 hx simp [*]), fun hx => let ⟨y, hy⟩ := Ideal.mem_span_singleton.1 hx hy.symm ▸ S.mul_mem_right _ hmin.1⟩⟩ else ⟨0, Submodule.ext fun a => by rw [← @Submodule.bot_coe R R _ _ _, span_eq, Submodule.mem_bot] exact ⟨fun haS => by_contra fun ha0 => h ⟨a, ⟨haS, ha0⟩⟩, fun h₁ => h₁.symm ▸ S.zero_mem⟩⟩⟩ end theorem IsField.isPrincipalIdealRing {R : Type*} [CommRing R] (h : IsField R) : IsPrincipalIdealRing R := @EuclideanDomain.to_principal_ideal_domain R (@Field.toEuclideanDomain R h.toField) namespace PrincipalIdealRing open IsPrincipalIdealRing -- see Note [lower instance priority] instance (priority := 100) isNoetherianRing [Ring R] [IsPrincipalIdealRing R] : IsNoetherianRing R := isNoetherianRing_iff.2 ⟨fun s : Ideal R => by rcases (IsPrincipalIdealRing.principal s).principal with ⟨a, rfl⟩ rw [← Finset.coe_singleton] exact ⟨{a}, SetLike.coe_injective rfl⟩⟩ theorem isMaximal_of_irreducible [CommRing R] [IsPrincipalIdealRing R] {p : R} (hp : Irreducible p) : Ideal.IsMaximal (span R ({p} : Set R)) := ⟨⟨mt Ideal.span_singleton_eq_top.1 hp.1, fun I hI => by rcases principal I with ⟨a, rfl⟩ erw [Ideal.span_singleton_eq_top] rcases Ideal.span_singleton_le_span_singleton.1 (le_of_lt hI) with ⟨b, rfl⟩ refine (of_irreducible_mul hp).resolve_right (mt (fun hb => ?_) (not_le_of_lt hI)) erw [Ideal.span_singleton_le_span_singleton, IsUnit.mul_right_dvd hb]⟩⟩ @[deprecated (since := "2024-02-12")] protected alias irreducible_iff_prime := irreducible_iff_prime @[deprecated (since := "2024-02-12")] protected alias associates_irreducible_iff_prime := associates_irreducible_iff_prime variable [CommRing R] [IsDomain R] [IsPrincipalIdealRing R] section open scoped Classical /-- `factors a` is a multiset of irreducible elements whose product is `a`, up to units -/ noncomputable def factors (a : R) : Multiset R := if h : a = 0 then ∅ else Classical.choose (WfDvdMonoid.exists_factors a h) theorem factors_spec (a : R) (h : a ≠ 0) : (∀ b ∈ factors a, Irreducible b) ∧ Associated (factors a).prod a := by unfold factors; rw [dif_neg h] exact Classical.choose_spec (WfDvdMonoid.exists_factors a h) theorem ne_zero_of_mem_factors {R : Type v} [CommRing R] [IsDomain R] [IsPrincipalIdealRing R] {a b : R} (ha : a ≠ 0) (hb : b ∈ factors a) : b ≠ 0 := Irreducible.ne_zero ((factors_spec a ha).1 b hb) theorem mem_submonoid_of_factors_subset_of_units_subset (s : Submonoid R) {a : R} (ha : a ≠ 0) (hfac : ∀ b ∈ factors a, b ∈ s) (hunit : ∀ c : Rˣ, (c : R) ∈ s) : a ∈ s := by rcases (factors_spec a ha).2 with ⟨c, hc⟩ rw [← hc] exact mul_mem (multiset_prod_mem _ hfac) (hunit _) /-- If a `RingHom` maps all units and all factors of an element `a` into a submonoid `s`, then it also maps `a` into that submonoid. -/ theorem ringHom_mem_submonoid_of_factors_subset_of_units_subset {R S : Type*} [CommRing R] [IsDomain R] [IsPrincipalIdealRing R] [Semiring S] (f : R →+* S) (s : Submonoid S) (a : R) (ha : a ≠ 0) (h : ∀ b ∈ factors a, f b ∈ s) (hf : ∀ c : Rˣ, f c ∈ s) : f a ∈ s := mem_submonoid_of_factors_subset_of_units_subset (s.comap f.toMonoidHom) ha h hf -- see Note [lower instance priority] /-- A principal ideal domain has unique factorization -/ instance (priority := 100) to_uniqueFactorizationMonoid : UniqueFactorizationMonoid R := { (IsNoetherianRing.wfDvdMonoid : WfDvdMonoid R) with irreducible_iff_prime := irreducible_iff_prime } end end PrincipalIdealRing section Surjective open Submodule variable {S N : Type*} [Ring R] [AddCommGroup M] [AddCommGroup N] [Ring S] variable [Module R M] [Module R N] theorem Submodule.IsPrincipal.of_comap (f : M →ₗ[R] N) (hf : Function.Surjective f) (S : Submodule R N) [hI : IsPrincipal (S.comap f)] : IsPrincipal S := ⟨⟨f (IsPrincipal.generator (S.comap f)), by rw [← Set.image_singleton, ← Submodule.map_span, IsPrincipal.span_singleton_generator, Submodule.map_comap_eq_of_surjective hf]⟩⟩ theorem Ideal.IsPrincipal.of_comap (f : R →+* S) (hf : Function.Surjective f) (I : Ideal S) [hI : IsPrincipal (I.comap f)] : IsPrincipal I := ⟨⟨f (IsPrincipal.generator (I.comap f)), by rw [Ideal.submodule_span_eq, ← Set.image_singleton, ← Ideal.map_span, Ideal.span_singleton_generator, Ideal.map_comap_of_surjective f hf]⟩⟩ /-- The surjective image of a principal ideal ring is again a principal ideal ring. -/ theorem IsPrincipalIdealRing.of_surjective [IsPrincipalIdealRing R] (f : R →+* S) (hf : Function.Surjective f) : IsPrincipalIdealRing S := ⟨fun I => Ideal.IsPrincipal.of_comap f hf I⟩ end Surjective section open Ideal variable [CommRing R] section Bezout variable [IsBezout R] theorem isCoprime_of_dvd (x y : R) (nonzero : ¬(x = 0 ∧ y = 0)) (H : ∀ z ∈ nonunits R, z ≠ 0 → z ∣ x → ¬z ∣ y) : IsCoprime x y := (isRelPrime_of_no_nonunits_factors nonzero H).isCoprime theorem dvd_or_coprime (x y : R) (h : Irreducible x) : x ∣ y ∨ IsCoprime x y := h.dvd_or_isRelPrime.imp_right IsRelPrime.isCoprime /-- See also `Irreducible.isRelPrime_iff_not_dvd`. -/ theorem Irreducible.coprime_iff_not_dvd {p n : R} (hp : Irreducible p) : IsCoprime p n ↔ ¬p ∣ n := by rw [← isRelPrime_iff_isCoprime, hp.isRelPrime_iff_not_dvd] /-- See also `Irreducible.coprime_iff_not_dvd'`. -/ theorem Irreducible.dvd_iff_not_coprime {p n : R} (hp : Irreducible p) : p ∣ n ↔ ¬IsCoprime p n := iff_not_comm.2 hp.coprime_iff_not_dvd theorem Irreducible.coprime_pow_of_not_dvd {p a : R} (m : ℕ) (hp : Irreducible p) (h : ¬p ∣ a) : IsCoprime a (p ^ m) := (hp.coprime_iff_not_dvd.2 h).symm.pow_right theorem Irreducible.coprime_or_dvd {p : R} (hp : Irreducible p) (i : R) : IsCoprime p i ∨ p ∣ i := (_root_.em _).imp_right hp.dvd_iff_not_coprime.2 variable [IsDomain R] section GCD variable [GCDMonoid R] theorem IsBezout.span_gcd_eq_span_gcd (x y : R) : span {GCDMonoid.gcd x y} = span {IsBezout.gcd x y} := by rw [Ideal.span_singleton_eq_span_singleton] exact associated_of_dvd_dvd (IsBezout.dvd_gcd (GCDMonoid.gcd_dvd_left _ _) <| GCDMonoid.gcd_dvd_right _ _) (GCDMonoid.dvd_gcd (IsBezout.gcd_dvd_left _ _) <| IsBezout.gcd_dvd_right _ _) theorem span_gcd (x y : R) : span {gcd x y} = span {x, y} := by rw [← IsBezout.span_gcd, IsBezout.span_gcd_eq_span_gcd] theorem gcd_dvd_iff_exists (a b : R) {z} : gcd a b ∣ z ↔ ∃ x y, z = a * x + b * y := by simp_rw [mul_comm a, mul_comm b, @eq_comm _ z, ← Ideal.mem_span_pair, ← span_gcd, Ideal.mem_span_singleton] /-- **Bézout's lemma** -/ theorem exists_gcd_eq_mul_add_mul (a b : R) : ∃ x y, gcd a b = a * x + b * y := by rw [← gcd_dvd_iff_exists] theorem gcd_isUnit_iff (x y : R) : IsUnit (gcd x y) ↔ IsCoprime x y := by rw [IsCoprime, ← Ideal.mem_span_pair, ← span_gcd, ← span_singleton_eq_top, eq_top_iff_one] end GCD theorem Prime.coprime_iff_not_dvd {p n : R} (hp : Prime p) : IsCoprime p n ↔ ¬p ∣ n := hp.irreducible.coprime_iff_not_dvd theorem exists_associated_pow_of_mul_eq_pow' {a b c : R} (hab : IsCoprime a b) {k : ℕ} (h : a * b = c ^ k) : ∃ d : R, Associated (d ^ k) a := by classical letI := IsBezout.toGCDDomain R exact exists_associated_pow_of_mul_eq_pow ((gcd_isUnit_iff _ _).mpr hab) h theorem exists_associated_pow_of_associated_pow_mul {a b c : R} (hab : IsCoprime a b) {k : ℕ} (h : Associated (c ^ k) (a * b)) : ∃ d : R, Associated (d ^ k) a := by obtain ⟨u, hu⟩ := h.symm exact exists_associated_pow_of_mul_eq_pow' ((isCoprime_mul_unit_right_right u.isUnit a b).mpr hab) <| mul_assoc a _ _ ▸ hu end Bezout variable [IsDomain R] [IsPrincipalIdealRing R] theorem isCoprime_of_irreducible_dvd {x y : R} (nonzero : ¬(x = 0 ∧ y = 0)) (H : ∀ z : R, Irreducible z → z ∣ x → ¬z ∣ y) : IsCoprime x y := (WfDvdMonoid.isRelPrime_of_no_irreducible_factors nonzero H).isCoprime theorem isCoprime_of_prime_dvd {x y : R} (nonzero : ¬(x = 0 ∧ y = 0)) (H : ∀ z : R, Prime z → z ∣ x → ¬z ∣ y) : IsCoprime x y := isCoprime_of_irreducible_dvd nonzero fun z zi ↦ H z zi.prime end section PrincipalOfPrime open Set Ideal variable (R) [CommRing R] /-- `nonPrincipals R` is the set of all ideals of `R` that are not principal ideals. -/ def nonPrincipals := { I : Ideal R | ¬I.IsPrincipal } theorem nonPrincipals_def {I : Ideal R} : I ∈ nonPrincipals R ↔ ¬I.IsPrincipal := Iff.rfl variable {R} theorem nonPrincipals_eq_empty_iff : nonPrincipals R = ∅ ↔ IsPrincipalIdealRing R := by simp [Set.eq_empty_iff_forall_not_mem, isPrincipalIdealRing_iff, nonPrincipals_def] /-- Any chain in the set of non-principal ideals has an upper bound which is non-principal. (Namely, the union of the chain is such an upper bound.) -/ theorem nonPrincipals_zorn (c : Set (Ideal R)) (hs : c ⊆ nonPrincipals R) (hchain : IsChain (· ≤ ·) c) {K : Ideal R} (hKmem : K ∈ c) : ∃ I ∈ nonPrincipals R, ∀ J ∈ c, J ≤ I := by refine ⟨sSup c, ?_, fun J hJ => le_sSup hJ⟩ rintro ⟨x, hx⟩ have hxmem : x ∈ sSup c := hx.symm ▸ Submodule.mem_span_singleton_self x obtain ⟨J, hJc, hxJ⟩ := (Submodule.mem_sSup_of_directed ⟨K, hKmem⟩ hchain.directedOn).1 hxmem have hsSupJ : sSup c = J := le_antisymm (by simp [hx, Ideal.span_le, hxJ]) (le_sSup hJc) specialize hs hJc rw [← hsSupJ, hx, nonPrincipals_def] at hs exact hs ⟨⟨x, rfl⟩⟩ /-- If all prime ideals in a commutative ring are principal, so are all other ideals. -/ theorem IsPrincipalIdealRing.of_prime (H : ∀ P : Ideal R, P.IsPrime → P.IsPrincipal) : IsPrincipalIdealRing R := by -- Suppose the set of `nonPrincipals` is not empty. rw [← nonPrincipals_eq_empty_iff, Set.eq_empty_iff_forall_not_mem] intro J hJ -- We will show a maximal element `I ∈ nonPrincipals R` (which exists by Zorn) is prime. obtain ⟨I, Ibad, -, Imax⟩ := zorn_nonempty_partialOrder₀ (nonPrincipals R) nonPrincipals_zorn _ hJ have Imax' : ∀ {J}, I < J → J.IsPrincipal := by intro J hJ by_contra He exact hJ.ne (Imax _ ((nonPrincipals_def R).2 He) hJ.le).symm by_cases hI1 : I = ⊤ · subst hI1 exact Ibad top_isPrincipal -- Let `x y : R` with `x * y ∈ I` and suppose WLOG `y ∉ I`. refine Ibad (H I ⟨hI1, fun {x y} hxy => or_iff_not_imp_right.mpr fun hy => ?_⟩) obtain ⟨a, ha⟩ : (I ⊔ span {y}).IsPrincipal := Imax' (left_lt_sup.mpr (mt I.span_singleton_le_iff_mem.mp hy)) -- Then `x ∈ I.colon (span {y})`, which is equal to `I` if it's not principal. suffices He : ¬(I.colon (span {y})).IsPrincipal by rw [← Imax _ ((nonPrincipals_def R).2 He) fun a ha => Ideal.mem_colon_singleton.2 (mul_mem_right _ _ ha)] exact Ideal.mem_colon_singleton.2 hxy -- So suppose for the sake of contradiction that both `I ⊔ span {y}` and `I.colon (span {y})` -- are principal. rintro ⟨b, hb⟩ -- We will show `I` is generated by `a * b`. refine (nonPrincipals_def _).1 Ibad ⟨a * b, ?_⟩ refine le_antisymm (α := Ideal R) (fun i hi => ?_) <| (span_singleton_mul_span_singleton a b).ge.trans ?_ · have hisup : i ∈ I ⊔ span {y} := Ideal.mem_sup_left hi have : y ∈ I ⊔ span {y} := Ideal.mem_sup_right (Ideal.mem_span_singleton_self y) erw [ha, mem_span_singleton'] at hisup this obtain ⟨v, rfl⟩ := this obtain ⟨u, rfl⟩ := hisup have hucolon : u ∈ I.colon (span {v * a}) := by rw [Ideal.mem_colon_singleton, mul_comm v, ← mul_assoc] exact mul_mem_right _ _ hi erw [hb, mem_span_singleton'] at hucolon obtain ⟨z, rfl⟩ := hucolon exact mem_span_singleton'.2 ⟨z, by ring⟩ · rw [← Ideal.submodule_span_eq, ← ha, Ideal.sup_mul, sup_le_iff, span_singleton_mul_span_singleton, mul_comm y, Ideal.span_singleton_le_iff_mem] exact ⟨mul_le_right, Ideal.mem_colon_singleton.1 <| hb.symm ▸ Ideal.mem_span_singleton_self b⟩ end PrincipalOfPrime
RingTheory\QuotientNilpotent.lean
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.RingTheory.Nilpotent.Lemmas import Mathlib.RingTheory.Ideal.QuotientOperations /-! # 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 (@Ideal.Quotient.mk_surjective R _ I) variable {R S : Type*} [CommSemiring R] [CommRing S] [Algebra R 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 with n H generalizing S by_cases hI' : I = ⊥ · subst hI' apply h₁ rw [← Ideal.zero_eq_bot, zero_pow two_ne_zero] cases' 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 cases' 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 omega) · 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 (R := R) (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, _root_.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 isUnit_of_mul_eq_one _ _ this
RingTheory\QuotientNoetherian.lean
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.RingTheory.Noetherian import Mathlib.RingTheory.Ideal.QuotientOperations /-! # 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
RingTheory\QuotSMulTop.lean
/- Copyright (c) 2024 Brendan Murphy. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Brendan Murphy -/ import Mathlib.LinearAlgebra.TensorProduct.RightExactness /-! # Reducing a module modulo an element of the ring Given a commutative ring `R` and an element `r : R`, the association `M ↦ M ⧸ rM` extends to a functor on the category of `R`-modules. This functor is isomorphic to the functor of tensoring by `R ⧸ (r)` on either side, but can be more convenient to work with since we can work with quotient types instead of fiddling with simple tensors. ## Tags module, commutative algebra -/ open scoped Pointwise variable {R} [CommRing R] (r : R) (M : Type*) {M' M''} [AddCommGroup M] [Module R M] [AddCommGroup M'] [Module R M'] [AddCommGroup M''] [Module R M''] /-- An abbreviation for `M⧸rM` that keeps us from having to write `(⊤ : Submodule R M)` over and over to satisfy the typechecker. -/ abbrev QuotSMulTop := M ⧸ r • (⊤ : Submodule R M) namespace QuotSMulTop open Submodule Function TensorProduct /-- Reducing a module modulo `r` is the same as left tensoring with `R/(r)`. -/ noncomputable def equivQuotTensor : QuotSMulTop r M ≃ₗ[R] (R ⧸ Ideal.span {r}) ⊗[R] M := quotEquivOfEq _ _ (ideal_span_singleton_smul _ _).symm ≪≫ₗ (quotTensorEquivQuotSMul M _).symm /-- Reducing a module modulo `r` is the same as right tensoring with `R/(r)`. -/ noncomputable def equivTensorQuot : QuotSMulTop r M ≃ₗ[R] M ⊗[R] (R ⧸ Ideal.span {r}) := quotEquivOfEq _ _ (ideal_span_singleton_smul _ _).symm ≪≫ₗ (tensorQuotEquivQuotSMul M _).symm variable {M} /-- The action of the functor `QuotSMulTop r` on morphisms. -/ def map : (M →ₗ[R] M') →ₗ[R] QuotSMulTop r M →ₗ[R] QuotSMulTop r M' := Submodule.mapQLinear _ _ ∘ₗ LinearMap.id.codRestrict _ fun _ => map_le_iff_le_comap.mp <| le_of_eq_of_le (map_pointwise_smul _ _ _) <| smul_mono_right r le_top @[simp] lemma map_apply_mk (f : M →ₗ[R] M') (x : M) : map r f (Submodule.Quotient.mk x) = (Submodule.Quotient.mk (f x) : QuotSMulTop r M') := rfl -- weirdly expensive to typecheck the type here? lemma map_comp_mkQ (f : M →ₗ[R] M') : map r f ∘ₗ mkQ (r • ⊤) = mkQ (r • ⊤) ∘ₗ f := by ext; rfl variable (M) @[simp] lemma map_id : map r (LinearMap.id : M →ₗ[R] M) = .id := DFunLike.ext _ _ <| (mkQ_surjective _).forall.mpr fun _ => rfl variable {M} @[simp] lemma map_comp (g : M' →ₗ[R] M'') (f : M →ₗ[R] M') : map r (g ∘ₗ f) = map r g ∘ₗ map r f := DFunLike.ext _ _ <| (mkQ_surjective _).forall.mpr fun _ => rfl lemma equivQuotTensor_naturality_mk (f : M →ₗ[R] M') (x : M) : equivQuotTensor r M' (map r f (Submodule.Quotient.mk x)) = f.lTensor (R ⧸ Ideal.span {r}) (equivQuotTensor r M (Submodule.Quotient.mk x)) := (LinearMap.lTensor_tmul (R ⧸ Ideal.span {r}) f 1 x).symm lemma equivQuotTensor_naturality (f : M →ₗ[R] M') : equivQuotTensor r M' ∘ₗ map r f = f.lTensor (R ⧸ Ideal.span {r}) ∘ₗ equivQuotTensor r M := quot_hom_ext _ _ _ (equivQuotTensor_naturality_mk r f) lemma equivTensorQuot_naturality_mk (f : M →ₗ[R] M') (x : M) : equivTensorQuot r M' (map r f (Submodule.Quotient.mk x)) = f.rTensor (R ⧸ Ideal.span {r}) (equivTensorQuot r M (Submodule.Quotient.mk x)) := (LinearMap.rTensor_tmul (R ⧸ Ideal.span {r}) f 1 x).symm lemma equivTensorQuot_naturality (f : M →ₗ[R] M') : equivTensorQuot r M' ∘ₗ map r f = f.rTensor (R ⧸ Ideal.span {r}) ∘ₗ equivTensorQuot r M := quot_hom_ext _ _ _ (equivTensorQuot_naturality_mk r f) lemma map_surjective {f : M →ₗ[R] M'} (hf : Surjective f) : Surjective (map r f) := have H₁ := (mkQ_surjective (r • ⊤ : Submodule R M')).comp hf @Surjective.of_comp _ _ _ _ (mkQ (r • ⊤ : Submodule R M)) <| by rwa [← LinearMap.coe_comp, map_comp_mkQ, LinearMap.coe_comp] lemma map_exact {f : M →ₗ[R] M'} {g : M' →ₗ[R] M''} (hfg : Exact f g) (hg : Surjective g) : Exact (map r f) (map r g) := (Exact.iff_of_ladder_linearEquiv (equivQuotTensor_naturality r f).symm (equivQuotTensor_naturality r g).symm).mp (lTensor_exact (R ⧸ Ideal.span {r}) hfg hg) variable (M M') /-- Tensoring on the left and applying `QuotSMulTop · r` commute. -/ noncomputable def tensorQuotSMulTopEquivQuotSMulTop : M ⊗[R] QuotSMulTop r M' ≃ₗ[R] QuotSMulTop r (M ⊗[R] M') := (equivTensorQuot r M').lTensor M ≪≫ₗ (TensorProduct.assoc R M M' (R ⧸ Ideal.span {r})).symm ≪≫ₗ (equivTensorQuot r (M ⊗[R] M')).symm /-- Tensoring on the right and applying `QuotSMulTop · r` commute. -/ noncomputable def quotSMulTopTensorEquivQuotSMulTop : QuotSMulTop r M' ⊗[R] M ≃ₗ[R] QuotSMulTop r (M' ⊗[R] M) := (equivQuotTensor r M').rTensor M ≪≫ₗ TensorProduct.assoc R (R ⧸ Ideal.span {r}) M' M ≪≫ₗ (equivQuotTensor r (M' ⊗[R] M)).symm end QuotSMulTop
RingTheory\ReesAlgebra.lean
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.RingTheory.FiniteType /-! # Rees algebra The Rees algebra of an ideal `I` is the subalgebra `R[It]` of `R[t]` defined as `R[It] = ⨁ₙ Iⁿ tⁿ`. This is used to prove the Artin-Rees lemma, and will potentially enable us to calculate some blowup in the future. ## Main definition - `reesAlgebra` : The Rees algebra of an ideal `I`, defined as a subalgebra of `R[X]`. - `adjoin_monomial_eq_reesAlgebra` : The Rees algebra is generated by the degree one elements. - `reesAlgebra.fg` : The Rees algebra of a f.g. ideal is of finite type. In particular, this implies that the rees algebra over a noetherian ring is still noetherian. -/ universe u v variable {R M : Type u} [CommRing R] [AddCommGroup M] [Module R M] (I : Ideal R) open Polynomial open Polynomial /-- The Rees algebra of an ideal `I`, defined as the subalgebra of `R[X]` whose `i`-th coefficient falls in `I ^ i`. -/ def reesAlgebra : Subalgebra R R[X] where carrier := { f | ∀ i, f.coeff i ∈ I ^ i } mul_mem' hf hg i := by rw [coeff_mul] apply Ideal.sum_mem rintro ⟨j, k⟩ e rw [← Finset.mem_antidiagonal.mp e, pow_add] exact Ideal.mul_mem_mul (hf j) (hg k) one_mem' i := by rw [coeff_one] split_ifs with h · subst h simp · simp add_mem' hf hg i := by rw [coeff_add] exact Ideal.add_mem _ (hf i) (hg i) zero_mem' i := Ideal.zero_mem _ algebraMap_mem' r i := by rw [algebraMap_apply, coeff_C] split_ifs with h · subst h simp · simp theorem mem_reesAlgebra_iff (f : R[X]) : f ∈ reesAlgebra I ↔ ∀ i, f.coeff i ∈ I ^ i := Iff.rfl theorem mem_reesAlgebra_iff_support (f : R[X]) : f ∈ reesAlgebra I ↔ ∀ i ∈ f.support, f.coeff i ∈ I ^ i := by apply forall_congr' intro a rw [mem_support_iff, Iff.comm, Classical.imp_iff_right_iff, Ne, ← imp_iff_not_or] exact fun e => e.symm ▸ (I ^ a).zero_mem theorem reesAlgebra.monomial_mem {I : Ideal R} {i : ℕ} {r : R} : monomial i r ∈ reesAlgebra I ↔ r ∈ I ^ i := by simp (config := { contextual := true }) [mem_reesAlgebra_iff_support, coeff_monomial, ← imp_iff_not_or] theorem monomial_mem_adjoin_monomial {I : Ideal R} {n : ℕ} {r : R} (hr : r ∈ I ^ n) : monomial n r ∈ Algebra.adjoin R (Submodule.map (monomial 1 : R →ₗ[R] R[X]) I : Set R[X]) := by induction' n with n hn generalizing r · exact Subalgebra.algebraMap_mem _ _ · rw [pow_succ'] at hr apply Submodule.smul_induction_on -- Porting note: did not need help with motive previously (p := fun r => (monomial (Nat.succ n)) r ∈ Algebra.adjoin R (Submodule.map (monomial 1) I)) hr · intro r hr s hs rw [Nat.succ_eq_one_add, smul_eq_mul, ← monomial_mul_monomial] exact Subalgebra.mul_mem _ (Algebra.subset_adjoin (Set.mem_image_of_mem _ hr)) (hn hs) · intro x y hx hy rw [monomial_add] exact Subalgebra.add_mem _ hx hy theorem adjoin_monomial_eq_reesAlgebra : Algebra.adjoin R (Submodule.map (monomial 1 : R →ₗ[R] R[X]) I : Set R[X]) = reesAlgebra I := by apply le_antisymm · apply Algebra.adjoin_le _ rintro _ ⟨r, hr, rfl⟩ exact reesAlgebra.monomial_mem.mpr (by rwa [pow_one]) · intro p hp rw [p.as_sum_support] apply Subalgebra.sum_mem _ _ rintro i - exact monomial_mem_adjoin_monomial (hp i) variable {I} theorem reesAlgebra.fg (hI : I.FG) : (reesAlgebra I).FG := by classical obtain ⟨s, hs⟩ := hI rw [← adjoin_monomial_eq_reesAlgebra, ← hs] use s.image (monomial 1) rw [Finset.coe_image] change _ = Algebra.adjoin R (Submodule.map (monomial 1 : R →ₗ[R] R[X]) (Submodule.span R ↑s) : Set R[X]) rw [Submodule.map_span, Algebra.adjoin_span] instance [IsNoetherianRing R] : Algebra.FiniteType R (reesAlgebra I) := ⟨(reesAlgebra I).fg_top.mpr (reesAlgebra.fg <| IsNoetherian.noetherian I)⟩ instance [IsNoetherianRing R] : IsNoetherianRing (reesAlgebra I) := Algebra.FiniteType.isNoetherianRing R _
RingTheory\RingHomProperties.lean
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.Algebra.Category.Ring.Constructions import Mathlib.Algebra.Category.Ring.Colimits import Mathlib.CategoryTheory.Iso import Mathlib.RingTheory.Localization.Away.Basic import Mathlib.RingTheory.IsTensorProduct /-! # Properties of ring homomorphisms We provide the basic framework for talking about properties of ring homomorphisms. The following meta-properties of predicates on ring homomorphisms are defined * `RingHom.RespectsIso`: `P` respects isomorphisms if `P f → P (e ≫ f)` and `P f → P (f ≫ e)`, where `e` is an isomorphism. * `RingHom.StableUnderComposition`: `P` is stable under composition if `P f → P g → P (f ≫ g)`. * `RingHom.StableUnderBaseChange`: `P` is stable under base change if `P (S ⟶ Y)` implies `P (X ⟶ X ⊗[S] Y)`. -/ universe u open CategoryTheory Opposite CategoryTheory.Limits namespace RingHom -- Porting Note: Deleted variable `f` here, since it wasn't used explicitly variable (P : ∀ {R S : Type u} [CommRing R] [CommRing S] (_ : R →+* S), Prop) section RespectsIso /-- A property `RespectsIso` if it still holds when composed with an isomorphism -/ def RespectsIso : Prop := (∀ {R S T : Type u} [CommRing R] [CommRing S] [CommRing T], ∀ (f : R →+* S) (e : S ≃+* T) (_ : P f), P (e.toRingHom.comp f)) ∧ ∀ {R S T : Type u} [CommRing R] [CommRing S] [CommRing T], ∀ (f : S →+* T) (e : R ≃+* S) (_ : P f), P (f.comp e.toRingHom) variable {P} theorem RespectsIso.cancel_left_isIso (hP : RespectsIso @P) {R S T : CommRingCat} (f : R ⟶ S) (g : S ⟶ T) [IsIso f] : P (f ≫ g) ↔ P g := ⟨fun H => by convert hP.2 (f ≫ g) (asIso f).symm.commRingCatIsoToRingEquiv H exact (IsIso.inv_hom_id_assoc _ _).symm, hP.2 g (asIso f).commRingCatIsoToRingEquiv⟩ theorem RespectsIso.cancel_right_isIso (hP : RespectsIso @P) {R S T : CommRingCat} (f : R ⟶ S) (g : S ⟶ T) [IsIso g] : P (f ≫ g) ↔ P f := ⟨fun H => by convert hP.1 (f ≫ g) (asIso g).symm.commRingCatIsoToRingEquiv H change f = f ≫ g ≫ inv g simp, hP.1 f (asIso g).commRingCatIsoToRingEquiv⟩ theorem RespectsIso.is_localization_away_iff (hP : RingHom.RespectsIso @P) {R S : Type u} (R' S' : Type u) [CommRing R] [CommRing S] [CommRing R'] [CommRing S'] [Algebra R R'] [Algebra S S'] (f : R →+* S) (r : R) [IsLocalization.Away r R'] [IsLocalization.Away (f r) S'] : P (Localization.awayMap f r) ↔ P (IsLocalization.Away.map R' S' f r) := by let e₁ : R' ≃+* Localization.Away r := (IsLocalization.algEquiv (Submonoid.powers r) _ _).toRingEquiv let e₂ : Localization.Away (f r) ≃+* S' := (IsLocalization.algEquiv (Submonoid.powers (f r)) _ _).toRingEquiv refine (hP.cancel_left_isIso e₁.toCommRingCatIso.hom (CommRingCat.ofHom _)).symm.trans ?_ refine (hP.cancel_right_isIso (CommRingCat.ofHom _) e₂.toCommRingCatIso.hom).symm.trans ?_ rw [← eq_iff_iff] congr 1 -- Porting note: Here, the proof used to have a huge `simp` involving `[anonymous]`, which didn't -- work out anymore. The issue seemed to be that it couldn't handle a term in which Ring -- homomorphisms were repeatedly casted to the bundled category and back. Here we resolve the -- problem by converting the goal to a more straightforward form. let e := (e₂ : Localization.Away (f r) →+* S').comp (((IsLocalization.map (Localization.Away (f r)) f (by rintro x ⟨n, rfl⟩; use n; simp : Submonoid.powers r ≤ Submonoid.comap f (Submonoid.powers (f r)))) : Localization.Away r →+* Localization.Away (f r)).comp (e₁ : R' →+* Localization.Away r)) suffices e = IsLocalization.Away.map R' S' f r by convert this apply IsLocalization.ringHom_ext (Submonoid.powers r) _ ext1 x dsimp [e, e₁, e₂, IsLocalization.Away.map] simp only [IsLocalization.map_eq, id_apply, RingHomCompTriple.comp_apply] end RespectsIso section StableUnderComposition /-- A property is `StableUnderComposition` if the composition of two such morphisms still falls in the class. -/ def StableUnderComposition : Prop := ∀ ⦃R S T⦄ [CommRing R] [CommRing S] [CommRing T], ∀ (f : R →+* S) (g : S →+* T) (_ : P f) (_ : P g), P (g.comp f) variable {P} theorem StableUnderComposition.respectsIso (hP : RingHom.StableUnderComposition @P) (hP' : ∀ {R S : Type u} [CommRing R] [CommRing S] (e : R ≃+* S), P e.toRingHom) : RingHom.RespectsIso @P := by constructor · introv H apply hP exacts [H, hP' e] · introv H apply hP exacts [hP' e, H] end StableUnderComposition section StableUnderBaseChange /-- A morphism property `P` is `StableUnderBaseChange` if `P(S →+* A)` implies `P(B →+* A ⊗[S] B)`. -/ def StableUnderBaseChange : Prop := ∀ (R S R' S') [CommRing R] [CommRing S] [CommRing R'] [CommRing S'], ∀ [Algebra R S] [Algebra R R'] [Algebra R S'] [Algebra S S'] [Algebra R' S'], ∀ [IsScalarTower R S S'] [IsScalarTower R R' S'], ∀ [Algebra.IsPushout R S R' S'], P (algebraMap R S) → P (algebraMap R' S') theorem StableUnderBaseChange.mk (h₁ : RespectsIso @P) (h₂ : ∀ ⦃R S T⦄ [CommRing R] [CommRing S] [CommRing T], ∀ [Algebra R S] [Algebra R T], P (algebraMap R T) → P (Algebra.TensorProduct.includeLeftRingHom : S →+* TensorProduct R S T)) : StableUnderBaseChange @P := by introv R h H let e := h.symm.1.equiv let f' := Algebra.TensorProduct.productMap (IsScalarTower.toAlgHom R R' S') (IsScalarTower.toAlgHom R S S') have : ∀ x, e x = f' x := by intro x change e.toLinearMap.restrictScalars R x = f'.toLinearMap x congr 1 apply TensorProduct.ext' intro x y simp [e, f', IsBaseChange.equiv_tmul, Algebra.smul_def] -- Porting Note: This had a lot of implicit inferences which didn't resolve anymore. -- Added those in convert h₁.1 (_ : R' →+* TensorProduct R R' S) (_ : TensorProduct R R' S ≃+* S') (h₂ H : P (_ : R' →+* TensorProduct R R' S)) swap · refine { e with map_mul' := fun x y => ?_ } change e (x * y) = e x * e y simp_rw [this] exact map_mul f' _ _ · ext x change _ = e (x ⊗ₜ[R] 1) -- Porting note: Had `dsimp only [e]` here, which didn't work anymore rw [h.symm.1.equiv_tmul, Algebra.smul_def, AlgHom.toLinearMap_apply, map_one, mul_one] attribute [local instance] Algebra.TensorProduct.rightAlgebra theorem StableUnderBaseChange.pushout_inl (hP : RingHom.StableUnderBaseChange @P) (hP' : RingHom.RespectsIso @P) {R S T : CommRingCat} (f : R ⟶ S) (g : R ⟶ T) (H : P g) : P (pushout.inl _ _ : S ⟶ pushout f g) := by letI := f.toAlgebra letI := g.toAlgebra rw [← show _ = pushout.inl f g from colimit.isoColimitCocone_ι_inv ⟨_, CommRingCat.pushoutCoconeIsColimit R S T⟩ WalkingSpan.left, hP'.cancel_right_isIso] dsimp only [CommRingCat.pushoutCocone_inl, PushoutCocone.ι_app_left] apply hP R T S (TensorProduct R S T) exact H end StableUnderBaseChange section ToMorphismProperty /-- The categorical `MorphismProperty` associated to a property of ring homs expressed non-categorical terms. -/ def toMorphismProperty : MorphismProperty CommRingCat := fun _ _ f ↦ P f variable {P} lemma toMorphismProperty_respectsIso_iff : RespectsIso P ↔ (toMorphismProperty P).RespectsIso := by refine ⟨fun h ↦ ⟨?_, ?_⟩, fun h ↦ ⟨?_, ?_⟩⟩ · intro X Y Z e f hf exact h.right f e.commRingCatIsoToRingEquiv hf · intro X Y Z e f hf exact h.left f e.commRingCatIsoToRingEquiv hf · intro X Y Z _ _ _ f e exact h.postcomp e.toCommRingCatIso (CommRingCat.ofHom f) · intro X Y Z _ _ _ f e exact h.precomp e.toCommRingCatIso (CommRingCat.ofHom f) end ToMorphismProperty end RingHom
RingTheory\RingInvo.lean
/- Copyright (c) 2018 Andreas Swerdlow. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andreas Swerdlow, Kenny Lau -/ import Mathlib.Algebra.Ring.Equiv import Mathlib.Algebra.Ring.Opposite /-! # Ring involutions This file defines a ring involution as a structure extending `R ≃+* Rᵐᵒᵖ`, with the additional fact `f.involution : (f (f x).unop).unop = x`. ## Notations We provide a coercion to a function `R → Rᵐᵒᵖ`. ## References * <https://en.wikipedia.org/wiki/Involution_(mathematics)#Ring_theory> ## Tags Ring involution -/ variable {F : Type*} (R : Type*) /-- A ring involution -/ structure RingInvo [Semiring R] extends R ≃+* Rᵐᵒᵖ where /-- The requirement that the ring homomorphism is its own inverse -/ involution' : ∀ x, (toFun (toFun x).unop).unop = x /-- The equivalence of rings underlying a ring involution. -/ add_decl_doc RingInvo.toRingEquiv /-- `RingInvoClass F R` states that `F` is a type of ring involutions. You should extend this class when you extend `RingInvo`. -/ class RingInvoClass (F R : Type*) [Semiring R] [EquivLike F R Rᵐᵒᵖ] extends RingEquivClass F R Rᵐᵒᵖ : Prop where /-- Every ring involution must be its own inverse -/ involution : ∀ (f : F) (x), (f (f x).unop).unop = x /-- Turn an element of a type `F` satisfying `RingInvoClass F R` into an actual `RingInvo`. This is declared as the default coercion from `F` to `RingInvo R`. -/ @[coe] def RingInvoClass.toRingInvo {R} [Semiring R] [EquivLike F R Rᵐᵒᵖ] [RingInvoClass F R] (f : F) : RingInvo R := { (f : R ≃+* Rᵐᵒᵖ) with involution' := RingInvoClass.involution f } namespace RingInvo variable {R} [Semiring R] [EquivLike F R Rᵐᵒᵖ] /-- Any type satisfying `RingInvoClass` can be cast into `RingInvo` via `RingInvoClass.toRingInvo`. -/ instance [RingInvoClass F R] : CoeTC F (RingInvo R) := ⟨RingInvoClass.toRingInvo⟩ instance : EquivLike (RingInvo R) R Rᵐᵒᵖ where coe f := f.toFun inv f := f.invFun coe_injective' e f h₁ h₂ := by rcases e with ⟨⟨tE, _⟩, _⟩; rcases f with ⟨⟨tF, _⟩, _⟩ cases tE cases tF congr left_inv f := f.left_inv right_inv f := f.right_inv instance : RingInvoClass (RingInvo R) R where map_add f := f.map_add' map_mul f := f.map_mul' involution f := f.involution' /-- Construct a ring involution from a ring homomorphism. -/ def mk' (f : R →+* Rᵐᵒᵖ) (involution : ∀ r, (f (f r).unop).unop = r) : RingInvo R := { f with invFun := fun r => (f r.unop).unop left_inv := fun r => involution r right_inv := fun _ => MulOpposite.unop_injective <| involution _ involution' := involution } -- Porting note: removed CoeFun instance, undesired in lean4 -- instance : CoeFun (RingInvo R) fun _ => R → Rᵐᵒᵖ := -- ⟨fun f => f.toRingEquiv.toFun⟩ @[simp] theorem involution (f : RingInvo R) (x : R) : (f (f x).unop).unop = x := f.involution' x -- Porting note: remove Coe instance, not needed -- instance hasCoeToRingEquiv : Coe (RingInvo R) (R ≃+* Rᵐᵒᵖ) := -- ⟨RingInvo.toRingEquiv⟩ @[norm_cast] theorem coe_ringEquiv (f : RingInvo R) (a : R) : (f : R ≃+* Rᵐᵒᵖ) a = f a := rfl -- porting note (#10618): simp can prove this -- @[simp] theorem map_eq_zero_iff (f : RingInvo R) {x : R} : f x = 0 ↔ x = 0 := f.toRingEquiv.map_eq_zero_iff end RingInvo open RingInvo section CommRing variable [CommRing R] /-- The identity function of a `CommRing` is a ring involution. -/ protected def RingInvo.id : RingInvo R := { RingEquiv.toOpposite R with involution' := fun _ => rfl } instance : Inhabited (RingInvo R) := ⟨RingInvo.id _⟩ end CommRing
RingTheory\SimpleModule.lean
/- Copyright (c) 2020 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.LinearAlgebra.Isomorphisms import Mathlib.LinearAlgebra.Projection import Mathlib.Order.JordanHolder import Mathlib.Order.CompactlyGenerated.Intervals import Mathlib.LinearAlgebra.FiniteDimensional /-! # 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 * 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 `⊤`. -/ abbrev IsSimpleModule := 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. -/ abbrev IsSemisimpleModule := ComplementedLattice (Submodule R M) /-- A ring is semisimple if it is semisimple as a module over itself. -/ abbrev IsSemisimpleRing := IsSemisimpleModule R R theorem RingEquiv.isSemisimpleRing (e : R ≃+* S) [IsSemisimpleRing R] : IsSemisimpleRing S := (Submodule.orderIsoMapComap e.toSemilinearEquiv).complementedLattice -- Making this an instance causes the linter to complain of "dangerous instances" 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 := (Submodule.orderIsoMapComapOfBijective l hl).isSimpleOrder_iff variable [Module R N] theorem IsSimpleModule.congr (l : M ≃ₗ[R] N) [IsSimpleModule R N] : IsSimpleModule R M := (Submodule.orderIsoMapComap l).isSimpleOrder theorem isSimpleModule_iff_isAtom : IsSimpleModule R m ↔ IsAtom m := by rw [← Set.isSimpleOrder_Iic_iff_isAtom] exact m.mapIic.isSimpleOrder_iff theorem isSimpleModule_iff_isCoatom : IsSimpleModule R (M ⧸ m) ↔ IsCoatom m := by rw [← Set.isSimpleOrder_Ici_iff_isCoatom] apply OrderIso.isSimpleOrder_iff exact Submodule.comapMkQRelIso m 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) 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) := ⟨fun h ↦ ⟨h.nontrivial, fun _ ↦ h.toSpanSingleton_surjective⟩, fun ⟨_, h⟩ ↦ ⟨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 isSimpleModule_iff_finrank_eq_one {R} [DivisionRing R] [Module R M] : IsSimpleModule R M ↔ FiniteDimensional.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), is_simple_module_of_finrank_eq_one⟩ theorem IsSemisimpleModule.of_sSup_simples_eq_top (h : sSup { m : Submodule R M | IsSimpleModule R m } = ⊤) : IsSemisimpleModule R M := complementedLattice_of_sSup_atoms_eq_top (by simp_rw [← h, isSimpleModule_iff_isAtom]) @[deprecated (since := "2024-03-05")] alias is_semisimple_of_sSup_simples_eq_top := IsSemisimpleModule.of_sSup_simples_eq_top namespace IsSemisimpleModule variable [IsSemisimpleModule R M] theorem eq_bot_or_exists_simple_le (N : Submodule R M) : N = ⊥ ∨ ∃ m ≤ N, IsSimpleModule R m := by simpa only [isSimpleModule_iff_isAtom, and_comm] using eq_bot_or_exists_atom_le _ 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 /-- 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 := m.mapIic.complementedLattice_iff.2 IsModularLattice.complementedLattice_Iic variable {R M} open LinearMap theorem congr (e : N ≃ₗ[R] M) : IsSemisimpleModule R N := (Submodule.orderIsoMapComap e.symm).complementedLattice instance quotient : IsSemisimpleModule R (M ⧸ m) := have ⟨P, compl⟩ := exists_isCompl m .congr (m.quotientEquivOfIsCompl P compl) -- does not work as an instance, not sure why protected theorem range (f : M →ₗ[R] N) : IsSemisimpleModule R (range f) := .congr (quotKerEquivRange _).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' := (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 /-- 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 _ _⟩ @[deprecated (since := "2024-03-05")] alias is_semisimple_iff_top_eq_sSup_simples := sSup_simples_eq_top_iff_isSemisimpleModule /-- 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 refine complementedLattice_of_complementedLattice_Iic (fun i hi ↦ ?_) hp' simpa only [← (p i).mapIic.complementedLattice_iff] using hp i hi 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 let q := ⨆ i ∈ s, p i let p' : ι → Submodule R q := fun i ↦ (p i).comap q.subtype have hp₀ : ∀ i ∈ s, p i ≤ LinearMap.range q.subtype := fun i hi ↦ by simpa only [Submodule.range_subtype] using le_biSup _ hi have hp₁ : ∀ i ∈ s, IsSemisimpleModule R (p' i) := fun i hi ↦ by let e : p' i ≃ₗ[R] p i := (p i).comap_equiv_self_of_inj_of_le q.injective_subtype (hp₀ i hi) exact (Submodule.orderIsoMapComap e).complementedLattice_iff.mpr <| hp i hi have hp₂ : ⨆ i ∈ s, p' i = ⊤ := by apply Submodule.map_injective_of_injective q.injective_subtype simp_rw [Submodule.map_top, Submodule.range_subtype, Submodule.map_iSup] exact biSup_congr fun i hi ↦ Submodule.map_comap_eq_of_le (hp₀ i hi) exact isSemisimpleModule_of_isSemisimpleModule_submodule hp₁ hp₂ 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) 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) 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.total_id_surjective R M).symm instance IsSemisimpleRing.isCoatomic_submodule [IsSemisimpleRing R] : 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 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]) /-- 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 erw [LinearMap.range_eq_map, ← Ideal.span_one, LinearMap.map_span, Set.image_singleton]; rfl⟩ instance [IsSemisimpleRing R] : IsPrincipalIdealRing R where principal I := have ⟨e, _, he⟩ := IsSemisimpleRing.ideal_eq_span_idempotent I; ⟨e, he⟩ variable (ι R) proof_wanted IsSemisimpleRing.mulOpposite [IsSemisimpleRing R] : IsSemisimpleRing Rᵐᵒᵖ proof_wanted IsSemisimpleRing.module_end [IsSemisimpleRing R] [Module.Finite R M] : IsSemisimpleRing (Module.End R M) proof_wanted IsSemisimpleRing.matrix [Fintype ι] [DecidableEq ι] [IsSemisimpleRing R] : IsSemisimpleRing (Matrix ι ι R) universe u in /-- The existence part of the Artin–Wedderburn theorem. -/ proof_wanted isSemisimpleRing_iff_pi_matrix_divisionRing {R : Type u} [Ring R] : IsSemisimpleRing R ↔ ∃ (n : ℕ) (S : Fin n → Type u) (d : Fin n → ℕ) (_ : ∀ i, DivisionRing (S i)), Nonempty (R ≃+* ∀ i, Matrix (Fin (d i)) (Fin (d i)) (S i)) variable {ι R} 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) /-- Schur's Lemma makes the endomorphism ring of a simple module a division ring. -/ noncomputable instance _root_.Module.End.divisionRing [DecidableEq (Module.End R M)] [IsSimpleModule R M] : DivisionRing (Module.End R M) where __ := Module.End.ring 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 := _ qsmul := _ end LinearMap -- Porting note: adding a namespace with all the new statements; existing result is not used in ML3 namespace JordanHolderModule -- Porting note: jordanHolderModule was timing out so outlining the fields /-- An isomorphism `X₂ / X₁ ∩ X₂ ≅ Y₂ / Y₁ ∩ Y₂` of modules for pairs `(X₁,X₂) (Y₁,Y₂) : Submodule R M` -/ def Iso (X Y : Submodule R M × Submodule R M) : Prop := Nonempty <| (X.2 ⧸ X.1.comap X.2.subtype) ≃ₗ[R] Y.2 ⧸ Y.1.comap Y.2.subtype theorem iso_symm {X Y : Submodule R M × Submodule R M} : Iso X Y → Iso Y X := fun ⟨f⟩ => ⟨f.symm⟩ theorem iso_trans {X Y Z : Submodule R M × Submodule R M} : Iso X Y → Iso Y Z → Iso X Z := fun ⟨f⟩ ⟨g⟩ => ⟨f.trans g⟩ @[nolint unusedArguments] theorem second_iso {X Y : Submodule R M} (_ : X ⋖ X ⊔ Y) : Iso (X,X ⊔ Y) (X ⊓ Y,Y) := by constructor rw [sup_comm, inf_comm] dsimp exact (LinearMap.quotientInfEquivSupQuotient Y X).symm 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 := Iso iso_symm := iso_symm iso_trans := iso_trans second_iso := second_iso end JordanHolderModule
RingTheory\Support.lean
/- Copyright (c) 2024 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.RingTheory.PrimeSpectrum import Mathlib.Algebra.Module.LocalizedModule import Mathlib.RingTheory.Localization.AtPrime /-! # Support of a module ## Main results - `Module.support`: The support of an `R`-module as a subset of `Spec R`. - `Module.mem_support_iff_exists_annihilator`: `p ∈ Supp M ↔ ∃ m, Ann(m) ≤ p`. - `Module.support_eq_empty_iff`: `Supp M = ∅ ↔ M = 0` - `Module.support_of_exact`: `Supp N = Supp M ∪ Supp P` for an exact sequence `0 → M → N → P → 0`. - `Module.support_eq_zeroLocus`: If `M` is `R`-finite, then `Supp M = Z(Ann(M))`. - `LocalizedModule.exists_subsingleton_away`: If `M` is `R`-finite and `Mₚ = 0`, then `M[1/f] = 0` for some `p ∈ D(f)`. Also see `AlgebraicGeometry/PrimeSpectrum/Module` for other results depending on the zariski topology. ## TODO - Connect to associated primes once we have them in mathlib. - Given an `R`-algebra `f : R → A` and a finite `R`-module `M`, `Supp_A (A ⊗ M) = f♯ ⁻¹ Supp M` where `f♯ : Spec A → Spec R`. (stacks#0BUR) -/ -- Basic files in `RingTheory` should avoid depending on the Zariski topology -- See `AlgebraicGeometry/PrimeSpectrum/Module` assert_not_exists TopologicalSpace variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] {p : PrimeSpectrum R} variable (R M) in /-- The support of a module, defined as the set of primes `p` such that `Mₚ ≠ 0`. -/ def Module.support : Set (PrimeSpectrum R) := { p | Nontrivial (LocalizedModule p.asIdeal.primeCompl M) } lemma Module.mem_support_iff : p ∈ Module.support R M ↔ Nontrivial (LocalizedModule p.asIdeal.primeCompl M) := Iff.rfl lemma Module.not_mem_support_iff : p ∉ Module.support R M ↔ Subsingleton (LocalizedModule p.asIdeal.primeCompl M) := not_nontrivial_iff_subsingleton lemma Module.not_mem_support_iff' : p ∉ Module.support R M ↔ ∀ m : M, ∃ r ∉ p.asIdeal, r • m = 0 := by rw [not_mem_support_iff, LocalizedModule.subsingleton_iff] rfl lemma Module.mem_support_iff' : p ∈ Module.support R M ↔ ∃ m : M, ∀ r ∉ p.asIdeal, r • m ≠ 0 := by rw [← @not_not (_ ∈ _), not_mem_support_iff'] push_neg rfl lemma Module.mem_support_iff_exists_annihilator : p ∈ Module.support R M ↔ ∃ m : M, (R ∙ m).annihilator ≤ p.asIdeal := by rw [Module.mem_support_iff'] simp_rw [not_imp_not, SetLike.le_def, Submodule.mem_annihilator_span_singleton] lemma Module.mem_support_iff_of_span_eq_top {s : Set M} (hs : Submodule.span R s = ⊤) : p ∈ Module.support R M ↔ ∃ m ∈ s, (R ∙ m).annihilator ≤ p.asIdeal := by constructor · contrapose rw [not_mem_support_iff, LocalizedModule.subsingleton_iff_ker_eq_top, ← top_le_iff, ← hs, Submodule.span_le, Set.subset_def] simp_rw [SetLike.le_def, Submodule.mem_annihilator_span_singleton, SetLike.mem_coe, LocalizedModule.mem_ker_mkLinearMap_iff] push_neg simp_rw [and_comm] exact id · intro ⟨m, _, hm⟩ exact mem_support_iff_exists_annihilator.mpr ⟨m, hm⟩ lemma Module.annihilator_le_of_mem_support (hp : p ∈ Module.support R M) : Module.annihilator R M ≤ p.asIdeal := by obtain ⟨m, hm⟩ := mem_support_iff_exists_annihilator.mp hp exact le_trans ((Submodule.subtype _).annihilator_le_of_injective Subtype.val_injective) hm lemma LocalizedModule.subsingleton_iff_support_subset {f : R} : Subsingleton (LocalizedModule (.powers f) M) ↔ Module.support R M ⊆ PrimeSpectrum.zeroLocus {f} := by rw [LocalizedModule.subsingleton_iff] constructor · rintro H x hx' f rfl obtain ⟨m, hm⟩ := Module.mem_support_iff_exists_annihilator.mp hx' obtain ⟨_, ⟨n, rfl⟩, e⟩ := H m exact Ideal.IsPrime.mem_of_pow_mem inferInstance n (hm ((Submodule.mem_annihilator_span_singleton _ _).mpr e)) · intro H m by_cases h : (Submodule.span R {m}).annihilator = ⊤ · rw [Submodule.annihilator_eq_top_iff, Submodule.span_singleton_eq_bot] at h exact ⟨1, one_mem _, by simpa using h⟩ obtain ⟨n, hn⟩ : f ∈ (Submodule.span R {m}).annihilator.radical := by rw [Ideal.radical_eq_sInf, Ideal.mem_sInf] rintro p ⟨hp, hp'⟩ simpa using H (Module.mem_support_iff_exists_annihilator (p := ⟨p, hp'⟩).mpr ⟨_, hp⟩) exact ⟨_, ⟨n, rfl⟩, (Submodule.mem_annihilator_span_singleton _ _).mp hn⟩ lemma Module.support_eq_empty_iff : Module.support R M = ∅ ↔ Subsingleton M := by rw [← Set.subset_empty_iff, ← PrimeSpectrum.zeroLocus_singleton_one, ← LocalizedModule.subsingleton_iff_support_subset, LocalizedModule.subsingleton_iff, subsingleton_iff_forall_eq 0] simp only [Submonoid.powers_one, Submonoid.mem_bot, exists_eq_left, one_smul] lemma Module.support_eq_empty [Subsingleton M] : Module.support R M = ∅ := Module.support_eq_empty_iff.mpr ‹_› lemma Module.support_of_algebra {A : Type*} [Ring A] [Algebra R A] : Module.support R A = PrimeSpectrum.zeroLocus (RingHom.ker (algebraMap R A)) := by ext p simp only [mem_support_iff', ne_eq, PrimeSpectrum.mem_zeroLocus, SetLike.coe_subset_coe] refine ⟨fun ⟨m, hm⟩ x hx ↦ not_not.mp fun hx' ↦ ?_, fun H ↦ ⟨1, fun r hr e ↦ ?_⟩⟩ · simpa [Algebra.smul_def, (show _ = _ from hx)] using hm _ hx' · exact hr (H ((Algebra.algebraMap_eq_smul_one _).trans e)) lemma Module.support_of_noZeroSMulDivisors [NoZeroSMulDivisors R M] [Nontrivial M] : Module.support R M = Set.univ := by simp only [Set.eq_univ_iff_forall, mem_support_iff', ne_eq, smul_eq_zero, not_or] obtain ⟨x, hx⟩ := exists_ne (0 : M) exact fun p ↦ ⟨x, fun r hr ↦ ⟨fun e ↦ hr (e ▸ p.asIdeal.zero_mem), hx⟩⟩ lemma Module.mem_support_iff_of_finite [Module.Finite R M] : p ∈ Module.support R M ↔ Module.annihilator R M ≤ p.asIdeal := by classical obtain ⟨s, hs⟩ := ‹Module.Finite R M› refine ⟨annihilator_le_of_mem_support, fun H ↦ (mem_support_iff_of_span_eq_top hs).mpr ?_⟩ simp only [SetLike.le_def, Submodule.mem_annihilator_span_singleton] at H ⊢ contrapose! H choose x hx hx' using Subtype.forall'.mp H refine ⟨s.attach.prod x, ?_, ?_⟩ · rw [← Submodule.annihilator_top, ← hs, Submodule.mem_annihilator_span] intro m obtain ⟨k, hk⟩ := Finset.dvd_prod_of_mem x (Finset.mem_attach _ m) rw [hk, mul_comm, mul_smul, hx, smul_zero] · exact p.asIdeal.primeCompl.prod_mem (fun x _ ↦ hx' x) variable {N P : Type*} [AddCommGroup N] [Module R N] [AddCommGroup P] [Module R P] variable (f : M →ₗ[R] N) (g : N →ₗ[R] P) lemma Module.support_subset_of_injective (hf : Function.Injective f) : Module.support R M ⊆ Module.support R N := by simp_rw [Set.subset_def, mem_support_iff'] rintro x ⟨m, hm⟩ exact ⟨f m, fun r hr ↦ by simpa using hf.ne (hm r hr)⟩ lemma Module.support_subset_of_surjective (hf : Function.Surjective f) : Module.support R N ⊆ Module.support R M := by simp_rw [Set.subset_def, mem_support_iff'] rintro x ⟨m, hm⟩ obtain ⟨m, rfl⟩ := hf m exact ⟨m, fun r hr e ↦ hm r hr (by simpa using congr(f $e))⟩ variable {f g} in /-- Given an exact sequence `0 → M → N → P → 0` of `R`-modules, `Supp N = Supp M ∪ Supp P`. -/ lemma Module.support_of_exact (h : Function.Exact f g) (hf : Function.Injective f) (hg : Function.Surjective g) : Module.support R N = Module.support R M ∪ Module.support R P := by refine subset_antisymm ?_ (Set.union_subset (Module.support_subset_of_injective f hf) (Module.support_subset_of_surjective g hg)) intro x contrapose simp only [Set.mem_union, not_or, and_imp, not_mem_support_iff'] intro H₁ H₂ m obtain ⟨r, hr, e₁⟩ := H₂ (g m) rw [← map_smul, h] at e₁ obtain ⟨m', hm'⟩ := e₁ obtain ⟨s, hs, e₁⟩ := H₁ m' exact ⟨_, x.asIdeal.primeCompl.mul_mem hs hr, by rw [mul_smul, ← hm', ← map_smul, e₁, map_zero]⟩ lemma LinearEquiv.support_eq (e : M ≃ₗ[R] N) : Module.support R M = Module.support R N := (Module.support_subset_of_injective e.toLinearMap e.injective).antisymm (Module.support_subset_of_surjective e.toLinearMap e.surjective) section Finite /-- If `M` is `R`-finite, then `Supp M = Z(Ann(M))`. -/ lemma Module.support_eq_zeroLocus [Module.Finite R M] : Module.support R M = PrimeSpectrum.zeroLocus (Module.annihilator R M) := Set.ext fun _ ↦ mem_support_iff_of_finite /-- If `M` is a finite module such that `Mₚ = 0` for some `p`, then `M[1/f] = 0` for some `p ∈ D(f)`. -/ lemma LocalizedModule.exists_subsingleton_away [Module.Finite R M] (p : Ideal R) [p.IsPrime] [Subsingleton (LocalizedModule p.primeCompl M)] : ∃ f ∉ p, Subsingleton (LocalizedModule (.powers f) M) := by have : ⟨p, inferInstance⟩ ∈ (Module.support R M)ᶜ := by simpa [Module.not_mem_support_iff] rw [Module.support_eq_zeroLocus, ← Set.biUnion_of_singleton (Module.annihilator R M : Set R), PrimeSpectrum.zeroLocus_iUnion₂, Set.compl_iInter₂, Set.mem_iUnion₂] at this obtain ⟨f, hf, hf'⟩ := this exact ⟨f, by simpa using hf', subsingleton_iff.mpr fun m ↦ ⟨f, Submonoid.mem_powers f, Module.mem_annihilator.mp hf _⟩⟩ end Finite
RingTheory\SurjectiveOnStalks.lean
/- Copyright (c) 2024 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.RingTheory.Localization.AtPrime import Mathlib.RingTheory.LocalRing.RingHom.Basic import Mathlib.RingTheory.TensorProduct.Basic /-! # Ring Homomorphisms surjective on stalks In this file, we prove some results on ring homomorphisms surjective on stalks, to be used in the development of immersions in algebraic geometry. A ring homomorphism `R →+* S` is surjective on stalks if `R_p →+* S_q` is surjective for all pairs of primes `p = f⁻¹(q)`. We show that this property is stable under composition and base change, and that surjections and localizations satisfy this. -/ variable {R : Type*} [CommRing R] (M : Submonoid R) {S : Type*} [CommRing S] [Algebra R S] variable {T : Type*} [CommRing T] [Algebra R T] [Algebra S T] [IsScalarTower R S T] variable {g : S →+* T} {f : R →+* S} namespace RingHom /-- A ring homomorphism `R →+* S` is surjective on stalks if `R_p →+* S_q` is surjective for all pairs of primes `p = f⁻¹(q)`. -/ def SurjectiveOnStalks (f : R →+* S) : Prop := ∀ (P : Ideal S) (_ : P.IsPrime), Function.Surjective (Localization.localRingHom _ P f rfl) /-- `R_p →+* S_q` is surjective if and only if every `x : S` is of the form `f x / f r` for some `f r ∉ q`. This is useful when proving `SurjectiveOnStalks`. -/ lemma surjective_localRingHom_iff (P : Ideal S) [P.IsPrime] : Function.Surjective (Localization.localRingHom _ P f rfl) ↔ ∀ s : S, ∃ x r : R, ∃ c ∉ P, f r ∉ P ∧ c * f r * s = c * f x := by constructor · intro H y obtain ⟨a, ha⟩ := H (IsLocalization.mk' _ y (1 : P.primeCompl)) obtain ⟨a, t, rfl⟩ := IsLocalization.mk'_surjective (P.comap f).primeCompl a rw [Localization.localRingHom_mk', IsLocalization.mk'_eq_iff_eq, Submonoid.coe_one, one_mul, IsLocalization.eq_iff_exists P.primeCompl] at ha obtain ⟨c, hc⟩ := ha simp only [← mul_assoc] at hc exact ⟨_, _, _, c.2, t.2, hc.symm⟩ · refine fun H y ↦ Localization.ind (fun ⟨y, t, h⟩ ↦ ?_) y simp only obtain ⟨yx, ys, yc, hyc, hy, ey⟩ := H y obtain ⟨tx, ts, yt, hyt, ht, et⟩ := H t refine ⟨Localization.mk (yx * ts) ⟨ys * tx, Submonoid.mul_mem _ hy ?_⟩, ?_⟩ · exact fun H ↦ mul_mem (P.primeCompl.mul_mem hyt ht) h (et ▸ Ideal.mul_mem_left _ yt H) · simp only [Localization.mk_eq_mk', Localization.localRingHom_mk', map_mul f, IsLocalization.mk'_eq_iff_eq, IsLocalization.eq_iff_exists P.primeCompl] refine ⟨⟨yc, hyc⟩ * ⟨yt, hyt⟩, ?_⟩ simp only [Submonoid.coe_mul] convert congr($(ey.symm) * $(et)) using 1 <;> ring lemma surjectiveOnStalks_iff_forall_ideal : f.SurjectiveOnStalks ↔ ∀ I : Ideal S, I ≠ ⊤ → ∀ s : S, ∃ x r : R, ∃ c ∉ I, f r ∉ I ∧ c * f r * s = c * f x := by simp_rw [SurjectiveOnStalks, surjective_localRingHom_iff] refine ⟨fun H I hI s ↦ ?_, fun H I hI ↦ H I hI.ne_top⟩ obtain ⟨M, hM, hIM⟩ := I.exists_le_maximal hI obtain ⟨x, r, c, hc, hr, e⟩ := H M hM.isPrime s exact ⟨x, r, c, fun h ↦ hc (hIM h), fun h ↦ hr (hIM h), e⟩ lemma surjectiveOnStalks_iff_forall_maximal : f.SurjectiveOnStalks ↔ ∀ (I : Ideal S) (_ : I.IsMaximal), Function.Surjective (Localization.localRingHom _ I f rfl) := by refine ⟨fun H I hI ↦ H I hI.isPrime, fun H I hI ↦ ?_⟩ simp_rw [surjective_localRingHom_iff] at H ⊢ intro s obtain ⟨M, hM, hIM⟩ := I.exists_le_maximal hI.ne_top obtain ⟨x, r, c, hc, hr, e⟩ := H M hM s exact ⟨x, r, c, fun h ↦ hc (hIM h), fun h ↦ hr (hIM h), e⟩ lemma surjectiveOnStalks_iff_forall_maximal' : f.SurjectiveOnStalks ↔ ∀ I : Ideal S, I.IsMaximal → ∀ s : S, ∃ x r : R, ∃ c ∉ I, f r ∉ I ∧ c * f r * s = c * f x := by simp only [surjectiveOnStalks_iff_forall_maximal, surjective_localRingHom_iff] lemma surjectiveOnStalks_of_exists_div (h : ∀ x : S, ∃ r s : R, IsUnit (f s) ∧ f s * x = f r) : SurjectiveOnStalks f := surjectiveOnStalks_iff_forall_ideal.mpr fun I hI x ↦ let ⟨r, s, hr, hr'⟩ := h x ⟨r, s, 1, by simpa [← Ideal.eq_top_iff_one], fun h ↦ hI (I.eq_top_of_isUnit_mem h hr), by simpa⟩ lemma surjectiveOnStalks_of_surjective (h : Function.Surjective f) : SurjectiveOnStalks f := surjectiveOnStalks_iff_forall_ideal.mpr fun _ _ s ↦ let ⟨r, hr⟩ := h s ⟨r, 1, 1, by simpa [← Ideal.eq_top_iff_one], by simpa [← Ideal.eq_top_iff_one], by simp [hr]⟩ variable (S) in lemma surjectiveOnStalks_of_isLocalization [IsLocalization M S] : SurjectiveOnStalks (algebraMap R S) := by refine surjectiveOnStalks_of_exists_div fun s ↦ ?_ obtain ⟨x, s, rfl⟩ := IsLocalization.mk'_surjective M s exact ⟨x, s, IsLocalization.map_units S s, IsLocalization.mk'_spec' S x s⟩ lemma SurjectiveOnStalks.comp (hg : SurjectiveOnStalks g) (hf : SurjectiveOnStalks f) : SurjectiveOnStalks (g.comp f) := by intros I hI have := (hg I hI).comp (hf _ (hI.comap g)) rwa [← RingHom.coe_comp, ← Localization.localRingHom_comp] at this lemma SurjectiveOnStalks.of_comp (hg : SurjectiveOnStalks (g.comp f)) : SurjectiveOnStalks g := by intros I hI have := hg I hI rw [Localization.localRingHom_comp (I.comap (g.comp f)) (I.comap g) _ _ rfl _ rfl, RingHom.coe_comp] at this exact this.of_comp open TensorProduct /-- If `R → T` is surjective on stalks, and `J` is some prime of `T`, then every element `x` in `S ⊗[R] T` satisfies `(1 ⊗ r • t) * x = a ⊗ t` for some `r : R`, `a : S`, and `t : T` such that `r • t ∉ J`. -/ lemma SurjectiveOnStalks.exists_mul_eq_tmul (hf₂ : (algebraMap R T).SurjectiveOnStalks) (x : S ⊗[R] T) (J : Ideal T) (hJ : J.IsPrime) : ∃ (t : T) (r : R) (a : S), (r • t ∉ J) ∧ (1 : S) ⊗ₜ[R] (r • t) * x = a ⊗ₜ[R] t := by induction x with | zero => exact ⟨1, 1, 0, by rw [one_smul]; exact J.primeCompl.one_mem, by rw [mul_zero, TensorProduct.zero_tmul]⟩ | tmul x₁ x₂ => obtain ⟨y, s, c, hs, hc, e⟩ := (surjective_localRingHom_iff _).mp (hf₂ J hJ) x₂ simp_rw [Algebra.smul_def] refine ⟨c, s, y • x₁, J.primeCompl.mul_mem hc hs, ?_⟩ rw [Algebra.TensorProduct.tmul_mul_tmul, one_mul, mul_comm _ c, e, TensorProduct.smul_tmul, Algebra.smul_def, mul_comm] | add x₁ x₂ hx₁ hx₂ => obtain ⟨t₁, r₁, a₁, hr₁, e₁⟩ := hx₁ obtain ⟨t₂, r₂, a₂, hr₂, e₂⟩ := hx₂ have : (r₁ * r₂) • (t₁ * t₂) = (r₁ • t₁) * (r₂ • t₂) := by simp_rw [← smul_eq_mul]; rw [smul_smul_smul_comm] refine ⟨t₁ * t₂, r₁ * r₂, r₂ • a₁ + r₁ • a₂, this.symm ▸ J.primeCompl.mul_mem hr₁ hr₂, ?_⟩ rw [this, ← one_mul (1 : S), ← Algebra.TensorProduct.tmul_mul_tmul, mul_add, mul_comm (_ ⊗ₜ _), mul_assoc, e₁, Algebra.TensorProduct.tmul_mul_tmul, one_mul, smul_mul_assoc, ← TensorProduct.smul_tmul, mul_comm (_ ⊗ₜ _), mul_assoc, e₂, Algebra.TensorProduct.tmul_mul_tmul, one_mul, smul_mul_assoc, ← TensorProduct.smul_tmul, TensorProduct.add_tmul, mul_comm t₁ t₂] lemma SurjectiveOnStalks.baseChange (hf : (algebraMap R T).SurjectiveOnStalks) : (algebraMap S (S ⊗[R] T)).SurjectiveOnStalks := by let g : T →+* S ⊗[R] T := Algebra.TensorProduct.includeRight.toRingHom intros J hJ rw [surjective_localRingHom_iff] intro x obtain ⟨t, r, a, ht, e⟩ := hf.exists_mul_eq_tmul x (J.comap g) inferInstance refine ⟨a, algebraMap _ _ r, 1 ⊗ₜ (r • t), ht, ?_, ?_⟩ · intro H simp only [Algebra.algebraMap_eq_smul_one (A := S), Algebra.TensorProduct.algebraMap_apply, Algebra.id.map_eq_id, id_apply, smul_tmul, ← Algebra.algebraMap_eq_smul_one (A := T)] at H rw [Ideal.mem_comap, Algebra.smul_def, g.map_mul] at ht exact ht (J.mul_mem_right _ H) · simp only [tmul_smul, Algebra.TensorProduct.algebraMap_apply, Algebra.id.map_eq_id, RingHomCompTriple.comp_apply, Algebra.smul_mul_assoc, Algebra.TensorProduct.tmul_mul_tmul, one_mul, mul_one, id_apply, ← e] rw [Algebra.algebraMap_eq_smul_one, ← smul_tmul', smul_mul_assoc] lemma surjectiveOnStalks_iff_of_isLocalRingHom [LocalRing S] [IsLocalRingHom f] : f.SurjectiveOnStalks ↔ Function.Surjective f := by refine ⟨fun H x ↦ ?_, fun h ↦ surjectiveOnStalks_of_surjective h⟩ obtain ⟨y, r, c, hc, hr, e⟩ := (surjective_localRingHom_iff _).mp (H (LocalRing.maximalIdeal _) inferInstance) x simp only [LocalRing.mem_maximalIdeal, mem_nonunits_iff, not_not] at hc hr refine ⟨(isUnit_of_map_unit f r hr).unit⁻¹ * y, ?_⟩ apply hr.mul_right_injective apply hc.mul_right_injective simp only [← _root_.map_mul, ← mul_assoc, IsUnit.mul_val_inv, one_mul, e] end RingHom
RingTheory\UniqueFactorizationDomain.lean
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Jens Wagemaker, Aaron Anderson -/ import Mathlib.Algebra.BigOperators.Associated import Mathlib.Algebra.GCDMonoid.Basic import Mathlib.Data.Finsupp.Multiset import Mathlib.Data.Nat.Factors import Mathlib.RingTheory.Noetherian import Mathlib.RingTheory.Multiplicity /-! # Unique factorization ## Main Definitions * `WfDvdMonoid` holds for `Monoid`s for which a strict divisibility relation is well-founded. * `UniqueFactorizationMonoid` holds for `WfDvdMonoid`s where `Irreducible` is equivalent to `Prime` ## TODO * set up the complete lattice structure on `FactorSet`. -/ variable {α : Type*} local infixl:50 " ~ᵤ " => Associated /-- Well-foundedness of the strict version of |, which is equivalent to the descending chain condition on divisibility and to the ascending chain condition on principal ideals in an integral domain. -/ class WfDvdMonoid (α : Type*) [CommMonoidWithZero α] : Prop where wellFounded_dvdNotUnit : WellFounded (@DvdNotUnit α _) export WfDvdMonoid (wellFounded_dvdNotUnit) -- see Note [lower instance priority] instance (priority := 100) IsNoetherianRing.wfDvdMonoid [CommRing α] [IsDomain α] [IsNoetherianRing α] : WfDvdMonoid α := ⟨by convert InvImage.wf (fun a => Ideal.span ({a} : Set α)) (wellFounded_submodule_gt _ _) ext exact Ideal.span_singleton_lt_span_singleton.symm⟩ namespace WfDvdMonoid variable [CommMonoidWithZero α] open Associates Nat theorem of_wfDvdMonoid_associates (_ : WfDvdMonoid (Associates α)) : WfDvdMonoid α := ⟨(mk_surjective.wellFounded_iff mk_dvdNotUnit_mk_iff.symm).2 wellFounded_dvdNotUnit⟩ variable [WfDvdMonoid α] instance wfDvdMonoid_associates : WfDvdMonoid (Associates α) := ⟨(mk_surjective.wellFounded_iff mk_dvdNotUnit_mk_iff.symm).1 wellFounded_dvdNotUnit⟩ theorem wellFounded_associates : WellFounded ((· < ·) : Associates α → Associates α → Prop) := Subrelation.wf dvdNotUnit_of_lt wellFounded_dvdNotUnit -- Porting note: elab_as_elim can only be global and cannot be changed on an imported decl -- attribute [local elab_as_elim] WellFounded.fix theorem exists_irreducible_factor {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : ∃ i, Irreducible i ∧ i ∣ a := let ⟨b, hs, hr⟩ := wellFounded_dvdNotUnit.has_min { b | b ∣ a ∧ ¬IsUnit b } ⟨a, dvd_rfl, ha⟩ ⟨b, ⟨hs.2, fun c d he => let h := dvd_trans ⟨d, he⟩ hs.1 or_iff_not_imp_left.2 fun hc => of_not_not fun hd => hr c ⟨h, hc⟩ ⟨ne_zero_of_dvd_ne_zero ha0 h, d, hd, he⟩⟩, hs.1⟩ @[elab_as_elim] theorem induction_on_irreducible {P : α → Prop} (a : α) (h0 : P 0) (hu : ∀ u : α, IsUnit u → P u) (hi : ∀ a i : α, a ≠ 0 → Irreducible i → P a → P (i * a)) : P a := haveI := Classical.dec wellFounded_dvdNotUnit.fix (fun a ih => if ha0 : a = 0 then ha0.substr h0 else if hau : IsUnit a then hu a hau else let ⟨i, hii, b, hb⟩ := exists_irreducible_factor hau ha0 let hb0 : b ≠ 0 := ne_zero_of_dvd_ne_zero ha0 ⟨i, mul_comm i b ▸ hb⟩ hb.symm ▸ hi b i hb0 hii <| ih b ⟨hb0, i, hii.1, mul_comm i b ▸ hb⟩) a theorem exists_factors (a : α) : a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Irreducible b) ∧ Associated f.prod a := induction_on_irreducible a (fun h => (h rfl).elim) (fun u hu _ => ⟨0, fun _ h => False.elim (Multiset.not_mem_zero _ h), hu.unit, one_mul _⟩) fun a i ha0 hi ih _ => let ⟨s, hs⟩ := ih ha0 ⟨i ::ₘ s, fun b H => (Multiset.mem_cons.1 H).elim (fun h => h.symm ▸ hi) (hs.1 b), by rw [s.prod_cons i] exact hs.2.mul_left i⟩ theorem not_unit_iff_exists_factors_eq (a : α) (hn0 : a ≠ 0) : ¬IsUnit a ↔ ∃ f : Multiset α, (∀ b ∈ f, Irreducible b) ∧ f.prod = a ∧ f ≠ ∅ := ⟨fun hnu => by obtain ⟨f, hi, u, rfl⟩ := exists_factors a hn0 obtain ⟨b, h⟩ := Multiset.exists_mem_of_ne_zero fun h : f = 0 => hnu <| by simp [h] classical refine ⟨(f.erase b).cons (b * u), fun a ha => ?_, ?_, Multiset.cons_ne_zero⟩ · obtain rfl | ha := Multiset.mem_cons.1 ha exacts [Associated.irreducible ⟨u, rfl⟩ (hi b h), hi a (Multiset.mem_of_mem_erase ha)] · rw [Multiset.prod_cons, mul_comm b, mul_assoc, Multiset.prod_erase h, mul_comm], fun ⟨f, hi, he, hne⟩ => let ⟨b, h⟩ := Multiset.exists_mem_of_ne_zero hne not_isUnit_of_not_isUnit_dvd (hi b h).not_unit <| he ▸ Multiset.dvd_prod h⟩ theorem isRelPrime_of_no_irreducible_factors {x y : α} (nonzero : ¬(x = 0 ∧ y = 0)) (H : ∀ z : α, Irreducible z → z ∣ x → ¬z ∣ y) : IsRelPrime x y := isRelPrime_of_no_nonunits_factors nonzero fun _z znu znz zx zy ↦ have ⟨i, h1, h2⟩ := exists_irreducible_factor znu znz H i h1 (h2.trans zx) (h2.trans zy) end WfDvdMonoid theorem WfDvdMonoid.of_wellFounded_associates [CancelCommMonoidWithZero α] (h : WellFounded ((· < ·) : Associates α → Associates α → Prop)) : WfDvdMonoid α := WfDvdMonoid.of_wfDvdMonoid_associates ⟨by convert h ext exact Associates.dvdNotUnit_iff_lt⟩ theorem WfDvdMonoid.iff_wellFounded_associates [CancelCommMonoidWithZero α] : WfDvdMonoid α ↔ WellFounded ((· < ·) : Associates α → Associates α → Prop) := ⟨by apply WfDvdMonoid.wellFounded_associates, WfDvdMonoid.of_wellFounded_associates⟩ theorem WfDvdMonoid.max_power_factor' [CommMonoidWithZero α] [WfDvdMonoid α] {a₀ x : α} (h : a₀ ≠ 0) (hx : ¬IsUnit x) : ∃ (n : ℕ) (a : α), ¬x ∣ a ∧ a₀ = x ^ n * a := by obtain ⟨a, ⟨n, rfl⟩, hm⟩ := wellFounded_dvdNotUnit.has_min {a | ∃ n, x ^ n * a = a₀} ⟨a₀, 0, by rw [pow_zero, one_mul]⟩ refine ⟨n, a, ?_, rfl⟩; rintro ⟨d, rfl⟩ exact hm d ⟨n + 1, by rw [pow_succ, mul_assoc]⟩ ⟨(right_ne_zero_of_mul <| right_ne_zero_of_mul h), x, hx, mul_comm _ _⟩ theorem WfDvdMonoid.max_power_factor [CommMonoidWithZero α] [WfDvdMonoid α] {a₀ x : α} (h : a₀ ≠ 0) (hx : Irreducible x) : ∃ (n : ℕ) (a : α), ¬x ∣ a ∧ a₀ = x ^ n * a := max_power_factor' h hx.not_unit theorem multiplicity.finite_of_not_isUnit [CancelCommMonoidWithZero α] [WfDvdMonoid α] {a b : α} (ha : ¬IsUnit a) (hb : b ≠ 0) : multiplicity.Finite a b := by obtain ⟨n, c, ndvd, rfl⟩ := WfDvdMonoid.max_power_factor' hb ha exact ⟨n, by rwa [pow_succ, mul_dvd_mul_iff_left (left_ne_zero_of_mul hb)]⟩ section Prio -- set_option default_priority 100 -- see Note [default priority] /-- unique factorization monoids. These are defined as `CancelCommMonoidWithZero`s with well-founded strict divisibility relations, but this is equivalent to more familiar definitions: Each element (except zero) is uniquely represented as a multiset of irreducible factors. Uniqueness is only up to associated elements. Each element (except zero) is non-uniquely represented as a multiset of prime factors. To define a UFD using the definition in terms of multisets of irreducible factors, use the definition `of_exists_unique_irreducible_factors` To define a UFD using the definition in terms of multisets of prime factors, use the definition `of_exists_prime_factors` -/ class UniqueFactorizationMonoid (α : Type*) [CancelCommMonoidWithZero α] extends WfDvdMonoid α : Prop where protected irreducible_iff_prime : ∀ {a : α}, Irreducible a ↔ Prime a /-- Can't be an instance because it would cause a loop `ufm → WfDvdMonoid → ufm → ...`. -/ instance (priority := 100) ufm_of_decomposition_of_wfDvdMonoid [CancelCommMonoidWithZero α] [WfDvdMonoid α] [DecompositionMonoid α] : UniqueFactorizationMonoid α := { ‹WfDvdMonoid α› with irreducible_iff_prime := irreducible_iff_prime } @[deprecated ufm_of_decomposition_of_wfDvdMonoid (since := "2024-02-12")] theorem ufm_of_gcd_of_wfDvdMonoid [CancelCommMonoidWithZero α] [WfDvdMonoid α] [DecompositionMonoid α] : UniqueFactorizationMonoid α := ufm_of_decomposition_of_wfDvdMonoid instance Associates.ufm [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] : UniqueFactorizationMonoid (Associates α) := { (WfDvdMonoid.wfDvdMonoid_associates : WfDvdMonoid (Associates α)) with irreducible_iff_prime := by rw [← Associates.irreducible_iff_prime_iff] apply UniqueFactorizationMonoid.irreducible_iff_prime } end Prio namespace UniqueFactorizationMonoid variable [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] theorem exists_prime_factors (a : α) : a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Prime b) ∧ f.prod ~ᵤ a := by simp_rw [← UniqueFactorizationMonoid.irreducible_iff_prime] apply WfDvdMonoid.exists_factors a instance : DecompositionMonoid α where primal a := by obtain rfl | ha := eq_or_ne a 0; · exact isPrimal_zero obtain ⟨f, hf, u, rfl⟩ := exists_prime_factors a ha exact ((Submonoid.isPrimal α).multiset_prod_mem f (hf · ·|>.isPrimal)).mul u.isUnit.isPrimal lemma exists_prime_iff : (∃ (p : α), Prime p) ↔ ∃ (x : α), x ≠ 0 ∧ ¬ IsUnit x := by refine ⟨fun ⟨p, hp⟩ ↦ ⟨p, hp.ne_zero, hp.not_unit⟩, fun ⟨x, hx₀, hxu⟩ ↦ ?_⟩ obtain ⟨f, hf, -⟩ := WfDvdMonoid.exists_irreducible_factor hxu hx₀ exact ⟨f, UniqueFactorizationMonoid.irreducible_iff_prime.mp hf⟩ @[elab_as_elim] theorem induction_on_prime {P : α → Prop} (a : α) (h₁ : P 0) (h₂ : ∀ x : α, IsUnit x → P x) (h₃ : ∀ a p : α, a ≠ 0 → Prime p → P a → P (p * a)) : P a := by simp_rw [← UniqueFactorizationMonoid.irreducible_iff_prime] at h₃ exact WfDvdMonoid.induction_on_irreducible a h₁ h₂ h₃ end UniqueFactorizationMonoid theorem prime_factors_unique [CancelCommMonoidWithZero α] : ∀ {f g : Multiset α}, (∀ x ∈ f, Prime x) → (∀ x ∈ g, Prime x) → f.prod ~ᵤ g.prod → Multiset.Rel Associated f g := by classical intro f induction' f using Multiset.induction_on with p f ih · intros g _ hg h exact Multiset.rel_zero_left.2 <| Multiset.eq_zero_of_forall_not_mem fun x hx => have : IsUnit g.prod := by simpa [associated_one_iff_isUnit] using h.symm (hg x hx).not_unit <| isUnit_iff_dvd_one.2 <| (Multiset.dvd_prod hx).trans (isUnit_iff_dvd_one.1 this) · intros g hf hg hfg let ⟨b, hbg, hb⟩ := (exists_associated_mem_of_dvd_prod (hf p (by simp)) fun q hq => hg _ hq) <| hfg.dvd_iff_dvd_right.1 (show p ∣ (p ::ₘ f).prod by simp) haveI := Classical.decEq α rw [← Multiset.cons_erase hbg] exact Multiset.Rel.cons hb (ih (fun q hq => hf _ (by simp [hq])) (fun {q} (hq : q ∈ g.erase b) => hg q (Multiset.mem_of_mem_erase hq)) (Associated.of_mul_left (by rwa [← Multiset.prod_cons, ← Multiset.prod_cons, Multiset.cons_erase hbg]) hb (hf p (by simp)).ne_zero)) namespace UniqueFactorizationMonoid variable [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] theorem factors_unique {f g : Multiset α} (hf : ∀ x ∈ f, Irreducible x) (hg : ∀ x ∈ g, Irreducible x) (h : f.prod ~ᵤ g.prod) : Multiset.Rel Associated f g := prime_factors_unique (fun x hx => UniqueFactorizationMonoid.irreducible_iff_prime.mp (hf x hx)) (fun x hx => UniqueFactorizationMonoid.irreducible_iff_prime.mp (hg x hx)) h end UniqueFactorizationMonoid /-- If an irreducible has a prime factorization, then it is an associate of one of its prime factors. -/ theorem prime_factors_irreducible [CancelCommMonoidWithZero α] {a : α} {f : Multiset α} (ha : Irreducible a) (pfa : (∀ b ∈ f, Prime b) ∧ f.prod ~ᵤ a) : ∃ p, a ~ᵤ p ∧ f = {p} := by haveI := Classical.decEq α refine @Multiset.induction_on _ (fun g => (g.prod ~ᵤ a) → (∀ b ∈ g, Prime b) → ∃ p, a ~ᵤ p ∧ g = {p}) f ?_ ?_ pfa.2 pfa.1 · intro h; exact (ha.not_unit (associated_one_iff_isUnit.1 (Associated.symm h))).elim · rintro p s _ ⟨u, hu⟩ hs use p have hs0 : s = 0 := by by_contra hs0 obtain ⟨q, hq⟩ := Multiset.exists_mem_of_ne_zero hs0 apply (hs q (by simp [hq])).2.1 refine (ha.isUnit_or_isUnit (?_ : _ = p * ↑u * (s.erase q).prod * _)).resolve_left ?_ · rw [mul_right_comm _ _ q, mul_assoc, ← Multiset.prod_cons, Multiset.cons_erase hq, ← hu, mul_comm, mul_comm p _, mul_assoc] simp apply mt isUnit_of_mul_isUnit_left (mt isUnit_of_mul_isUnit_left _) apply (hs p (Multiset.mem_cons_self _ _)).2.1 simp only [mul_one, Multiset.prod_cons, Multiset.prod_zero, hs0] at * exact ⟨Associated.symm ⟨u, hu⟩, rfl⟩ section ExistsPrimeFactors variable [CancelCommMonoidWithZero α] variable (pf : ∀ a : α, a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Prime b) ∧ f.prod ~ᵤ a) theorem WfDvdMonoid.of_exists_prime_factors : WfDvdMonoid α := ⟨by classical refine RelHomClass.wellFounded (RelHom.mk ?_ ?_ : (DvdNotUnit : α → α → Prop) →r ((· < ·) : ℕ∞ → ℕ∞ → Prop)) wellFounded_lt · intro a by_cases h : a = 0 · exact ⊤ exact ↑(Multiset.card (Classical.choose (pf a h))) rintro a b ⟨ane0, ⟨c, hc, b_eq⟩⟩ rw [dif_neg ane0] by_cases h : b = 0 · simp [h, lt_top_iff_ne_top] · rw [dif_neg h] erw [WithTop.coe_lt_coe] have cne0 : c ≠ 0 := by refine mt (fun con => ?_) h rw [b_eq, con, mul_zero] calc Multiset.card (Classical.choose (pf a ane0)) < _ + Multiset.card (Classical.choose (pf c cne0)) := lt_add_of_pos_right _ (Multiset.card_pos.mpr fun con => hc (associated_one_iff_isUnit.mp ?_)) _ = Multiset.card (Classical.choose (pf a ane0) + Classical.choose (pf c cne0)) := (Multiset.card_add _ _).symm _ = Multiset.card (Classical.choose (pf b h)) := Multiset.card_eq_card_of_rel (prime_factors_unique ?_ (Classical.choose_spec (pf _ h)).1 ?_) · convert (Classical.choose_spec (pf c cne0)).2.symm rw [con, Multiset.prod_zero] · intro x hadd rw [Multiset.mem_add] at hadd cases' hadd with h h <;> apply (Classical.choose_spec (pf _ _)).1 _ h <;> assumption · rw [Multiset.prod_add] trans a * c · apply Associated.mul_mul <;> apply (Classical.choose_spec (pf _ _)).2 <;> assumption · rw [← b_eq] apply (Classical.choose_spec (pf _ _)).2.symm; assumption⟩ theorem irreducible_iff_prime_of_exists_prime_factors {p : α} : Irreducible p ↔ Prime p := by by_cases hp0 : p = 0 · simp [hp0] refine ⟨fun h => ?_, Prime.irreducible⟩ obtain ⟨f, hf⟩ := pf p hp0 obtain ⟨q, hq, rfl⟩ := prime_factors_irreducible h hf rw [hq.prime_iff] exact hf.1 q (Multiset.mem_singleton_self _) theorem UniqueFactorizationMonoid.of_exists_prime_factors : UniqueFactorizationMonoid α := { WfDvdMonoid.of_exists_prime_factors pf with irreducible_iff_prime := irreducible_iff_prime_of_exists_prime_factors pf } end ExistsPrimeFactors theorem UniqueFactorizationMonoid.iff_exists_prime_factors [CancelCommMonoidWithZero α] : UniqueFactorizationMonoid α ↔ ∀ a : α, a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Prime b) ∧ f.prod ~ᵤ a := ⟨fun h => @UniqueFactorizationMonoid.exists_prime_factors _ _ h, UniqueFactorizationMonoid.of_exists_prime_factors⟩ section variable {β : Type*} [CancelCommMonoidWithZero α] [CancelCommMonoidWithZero β] theorem MulEquiv.uniqueFactorizationMonoid (e : α ≃* β) (hα : UniqueFactorizationMonoid α) : UniqueFactorizationMonoid β := by rw [UniqueFactorizationMonoid.iff_exists_prime_factors] at hα ⊢ intro a ha obtain ⟨w, hp, u, h⟩ := hα (e.symm a) fun h => ha <| by convert← map_zero e simp [← h] exact ⟨w.map e, fun b hb => let ⟨c, hc, he⟩ := Multiset.mem_map.1 hb he ▸ e.prime_iff.1 (hp c hc), Units.map e.toMonoidHom u, by erw [Multiset.prod_hom, ← e.map_mul, h] simp⟩ theorem MulEquiv.uniqueFactorizationMonoid_iff (e : α ≃* β) : UniqueFactorizationMonoid α ↔ UniqueFactorizationMonoid β := ⟨e.uniqueFactorizationMonoid, e.symm.uniqueFactorizationMonoid⟩ end theorem irreducible_iff_prime_of_exists_unique_irreducible_factors [CancelCommMonoidWithZero α] (eif : ∀ a : α, a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Irreducible b) ∧ f.prod ~ᵤ a) (uif : ∀ f g : Multiset α, (∀ x ∈ f, Irreducible x) → (∀ x ∈ g, Irreducible x) → f.prod ~ᵤ g.prod → Multiset.Rel Associated f g) (p : α) : Irreducible p ↔ Prime p := letI := Classical.decEq α ⟨ fun hpi => ⟨hpi.ne_zero, hpi.1, fun a b ⟨x, hx⟩ => if hab0 : a * b = 0 then (eq_zero_or_eq_zero_of_mul_eq_zero hab0).elim (fun ha0 => by simp [ha0]) fun hb0 => by simp [hb0] else by have hx0 : x ≠ 0 := fun hx0 => by simp_all have ha0 : a ≠ 0 := left_ne_zero_of_mul hab0 have hb0 : b ≠ 0 := right_ne_zero_of_mul hab0 cases' eif x hx0 with fx hfx cases' eif a ha0 with fa hfa cases' eif b hb0 with fb hfb have h : Multiset.Rel Associated (p ::ₘ fx) (fa + fb) := by apply uif · exact fun i hi => (Multiset.mem_cons.1 hi).elim (fun hip => hip.symm ▸ hpi) (hfx.1 _) · exact fun i hi => (Multiset.mem_add.1 hi).elim (hfa.1 _) (hfb.1 _) calc Multiset.prod (p ::ₘ fx) ~ᵤ a * b := by rw [hx, Multiset.prod_cons]; exact hfx.2.mul_left _ _ ~ᵤ fa.prod * fb.prod := hfa.2.symm.mul_mul hfb.2.symm _ = _ := by rw [Multiset.prod_add] exact let ⟨q, hqf, hq⟩ := Multiset.exists_mem_of_rel_of_mem h (Multiset.mem_cons_self p _) (Multiset.mem_add.1 hqf).elim (fun hqa => Or.inl <| hq.dvd_iff_dvd_left.2 <| hfa.2.dvd_iff_dvd_right.1 (Multiset.dvd_prod hqa)) fun hqb => Or.inr <| hq.dvd_iff_dvd_left.2 <| hfb.2.dvd_iff_dvd_right.1 (Multiset.dvd_prod hqb)⟩, Prime.irreducible⟩ theorem UniqueFactorizationMonoid.of_exists_unique_irreducible_factors [CancelCommMonoidWithZero α] (eif : ∀ a : α, a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Irreducible b) ∧ f.prod ~ᵤ a) (uif : ∀ f g : Multiset α, (∀ x ∈ f, Irreducible x) → (∀ x ∈ g, Irreducible x) → f.prod ~ᵤ g.prod → Multiset.Rel Associated f g) : UniqueFactorizationMonoid α := UniqueFactorizationMonoid.of_exists_prime_factors (by convert eif using 7 simp_rw [irreducible_iff_prime_of_exists_unique_irreducible_factors eif uif]) namespace UniqueFactorizationMonoid variable [CancelCommMonoidWithZero α] variable [UniqueFactorizationMonoid α] open Classical in /-- Noncomputably determines the multiset of prime factors. -/ noncomputable def factors (a : α) : Multiset α := if h : a = 0 then 0 else Classical.choose (UniqueFactorizationMonoid.exists_prime_factors a h) theorem factors_prod {a : α} (ane0 : a ≠ 0) : Associated (factors a).prod a := by rw [factors, dif_neg ane0] exact (Classical.choose_spec (exists_prime_factors a ane0)).2 @[simp] theorem factors_zero : factors (0 : α) = 0 := by simp [factors] theorem ne_zero_of_mem_factors {p a : α} (h : p ∈ factors a) : a ≠ 0 := by rintro rfl simp at h theorem dvd_of_mem_factors {p a : α} (h : p ∈ factors a) : p ∣ a := dvd_trans (Multiset.dvd_prod h) (Associated.dvd (factors_prod (ne_zero_of_mem_factors h))) theorem prime_of_factor {a : α} (x : α) (hx : x ∈ factors a) : Prime x := by have ane0 := ne_zero_of_mem_factors hx rw [factors, dif_neg ane0] at hx exact (Classical.choose_spec (UniqueFactorizationMonoid.exists_prime_factors a ane0)).1 x hx theorem irreducible_of_factor {a : α} : ∀ x : α, x ∈ factors a → Irreducible x := fun x h => (prime_of_factor x h).irreducible @[simp] theorem factors_one : factors (1 : α) = 0 := by nontriviality α using factors rw [← Multiset.rel_zero_right] refine factors_unique irreducible_of_factor (fun x hx => (Multiset.not_mem_zero x hx).elim) ?_ rw [Multiset.prod_zero] exact factors_prod one_ne_zero theorem exists_mem_factors_of_dvd {a p : α} (ha0 : a ≠ 0) (hp : Irreducible p) : p ∣ a → ∃ q ∈ factors a, p ~ᵤ q := fun ⟨b, hb⟩ => have hb0 : b ≠ 0 := fun hb0 => by simp_all have : Multiset.Rel Associated (p ::ₘ factors b) (factors a) := factors_unique (fun x hx => (Multiset.mem_cons.1 hx).elim (fun h => h.symm ▸ hp) (irreducible_of_factor _)) irreducible_of_factor (Associated.symm <| calc Multiset.prod (factors a) ~ᵤ a := factors_prod ha0 _ = p * b := hb _ ~ᵤ Multiset.prod (p ::ₘ factors b) := by rw [Multiset.prod_cons]; exact (factors_prod hb0).symm.mul_left _ ) Multiset.exists_mem_of_rel_of_mem this (by simp) theorem exists_mem_factors {x : α} (hx : x ≠ 0) (h : ¬IsUnit x) : ∃ p, p ∈ factors x := by obtain ⟨p', hp', hp'x⟩ := WfDvdMonoid.exists_irreducible_factor h hx obtain ⟨p, hp, _⟩ := exists_mem_factors_of_dvd hx hp' hp'x exact ⟨p, hp⟩ open Classical in theorem factors_mul {x y : α} (hx : x ≠ 0) (hy : y ≠ 0) : Multiset.Rel Associated (factors (x * y)) (factors x + factors y) := by refine factors_unique irreducible_of_factor (fun a ha => (Multiset.mem_add.mp ha).by_cases (irreducible_of_factor _) (irreducible_of_factor _)) ((factors_prod (mul_ne_zero hx hy)).trans ?_) rw [Multiset.prod_add] exact (Associated.mul_mul (factors_prod hx) (factors_prod hy)).symm theorem factors_pow {x : α} (n : ℕ) : Multiset.Rel Associated (factors (x ^ n)) (n • factors x) := by match n with | 0 => rw [zero_smul, pow_zero, factors_one, Multiset.rel_zero_right] | n+1 => by_cases h0 : x = 0 · simp [h0, zero_pow n.succ_ne_zero, smul_zero] · rw [pow_succ', succ_nsmul'] refine Multiset.Rel.trans _ (factors_mul h0 (pow_ne_zero n h0)) ?_ refine Multiset.Rel.add ?_ <| factors_pow n exact Multiset.rel_refl_of_refl_on fun y _ => Associated.refl _ @[simp] theorem factors_pos (x : α) (hx : x ≠ 0) : 0 < factors x ↔ ¬IsUnit x := by constructor · intro h hx obtain ⟨p, hp⟩ := Multiset.exists_mem_of_ne_zero h.ne' exact (prime_of_factor _ hp).not_unit (isUnit_of_dvd_unit (dvd_of_mem_factors hp) hx) · intro h obtain ⟨p, hp⟩ := exists_mem_factors hx h exact bot_lt_iff_ne_bot.mpr (mt Multiset.eq_zero_iff_forall_not_mem.mp (not_forall.mpr ⟨p, not_not.mpr hp⟩)) open Multiset in theorem factors_pow_count_prod [DecidableEq α] {x : α} (hx : x ≠ 0) : (∏ p ∈ (factors x).toFinset, p ^ (factors x).count p) ~ᵤ x := calc _ = prod (∑ a ∈ toFinset (factors x), count a (factors x) • {a}) := by simp only [prod_sum, prod_nsmul, prod_singleton] _ = prod (factors x) := by rw [toFinset_sum_count_nsmul_eq (factors x)] _ ~ᵤ x := factors_prod hx end UniqueFactorizationMonoid namespace UniqueFactorizationMonoid variable [CancelCommMonoidWithZero α] [NormalizationMonoid α] variable [UniqueFactorizationMonoid α] /-- Noncomputably determines the multiset of prime factors. -/ noncomputable def normalizedFactors (a : α) : Multiset α := Multiset.map normalize <| factors a /-- An arbitrary choice of factors of `x : M` is exactly the (unique) normalized set of factors, if `M` has a trivial group of units. -/ @[simp] theorem factors_eq_normalizedFactors {M : Type*} [CancelCommMonoidWithZero M] [UniqueFactorizationMonoid M] [Unique Mˣ] (x : M) : factors x = normalizedFactors x := by unfold normalizedFactors convert (Multiset.map_id (factors x)).symm ext p exact normalize_eq p theorem normalizedFactors_prod {a : α} (ane0 : a ≠ 0) : Associated (normalizedFactors a).prod a := by rw [normalizedFactors, factors, dif_neg ane0] refine Associated.trans ?_ (Classical.choose_spec (exists_prime_factors a ane0)).2 rw [← Associates.mk_eq_mk_iff_associated, ← Associates.prod_mk, ← Associates.prod_mk, Multiset.map_map] congr 2 ext rw [Function.comp_apply, Associates.mk_normalize] theorem prime_of_normalized_factor {a : α} : ∀ x : α, x ∈ normalizedFactors a → Prime x := by rw [normalizedFactors, factors] split_ifs with ane0; · simp intro x hx; rcases Multiset.mem_map.1 hx with ⟨y, ⟨hy, rfl⟩⟩ rw [(normalize_associated _).prime_iff] exact (Classical.choose_spec (UniqueFactorizationMonoid.exists_prime_factors a ane0)).1 y hy theorem irreducible_of_normalized_factor {a : α} : ∀ x : α, x ∈ normalizedFactors a → Irreducible x := fun x h => (prime_of_normalized_factor x h).irreducible theorem normalize_normalized_factor {a : α} : ∀ x : α, x ∈ normalizedFactors a → normalize x = x := by rw [normalizedFactors, factors] split_ifs with h; · simp intro x hx obtain ⟨y, _, rfl⟩ := Multiset.mem_map.1 hx apply normalize_idem theorem normalizedFactors_irreducible {a : α} (ha : Irreducible a) : normalizedFactors a = {normalize a} := by obtain ⟨p, a_assoc, hp⟩ := prime_factors_irreducible ha ⟨prime_of_normalized_factor, normalizedFactors_prod ha.ne_zero⟩ have p_mem : p ∈ normalizedFactors a := by rw [hp] exact Multiset.mem_singleton_self _ convert hp rwa [← normalize_normalized_factor p p_mem, normalize_eq_normalize_iff, dvd_dvd_iff_associated] theorem normalizedFactors_eq_of_dvd (a : α) : ∀ᵉ (p ∈ normalizedFactors a) (q ∈ normalizedFactors a), p ∣ q → p = q := by intro p hp q hq hdvd convert normalize_eq_normalize hdvd ((prime_of_normalized_factor _ hp).irreducible.dvd_symm (prime_of_normalized_factor _ hq).irreducible hdvd) <;> apply (normalize_normalized_factor _ ‹_›).symm theorem exists_mem_normalizedFactors_of_dvd {a p : α} (ha0 : a ≠ 0) (hp : Irreducible p) : p ∣ a → ∃ q ∈ normalizedFactors a, p ~ᵤ q := fun ⟨b, hb⟩ => have hb0 : b ≠ 0 := fun hb0 => by simp_all have : Multiset.Rel Associated (p ::ₘ normalizedFactors b) (normalizedFactors a) := factors_unique (fun x hx => (Multiset.mem_cons.1 hx).elim (fun h => h.symm ▸ hp) (irreducible_of_normalized_factor _)) irreducible_of_normalized_factor (Associated.symm <| calc Multiset.prod (normalizedFactors a) ~ᵤ a := normalizedFactors_prod ha0 _ = p * b := hb _ ~ᵤ Multiset.prod (p ::ₘ normalizedFactors b) := by rw [Multiset.prod_cons] exact (normalizedFactors_prod hb0).symm.mul_left _ ) Multiset.exists_mem_of_rel_of_mem this (by simp) theorem exists_mem_normalizedFactors {x : α} (hx : x ≠ 0) (h : ¬IsUnit x) : ∃ p, p ∈ normalizedFactors x := by obtain ⟨p', hp', hp'x⟩ := WfDvdMonoid.exists_irreducible_factor h hx obtain ⟨p, hp, _⟩ := exists_mem_normalizedFactors_of_dvd hx hp' hp'x exact ⟨p, hp⟩ @[simp] theorem normalizedFactors_zero : normalizedFactors (0 : α) = 0 := by simp [normalizedFactors, factors] @[simp] theorem normalizedFactors_one : normalizedFactors (1 : α) = 0 := by cases' subsingleton_or_nontrivial α with h h · dsimp [normalizedFactors, factors] simp [Subsingleton.elim (1 : α) 0] · rw [← Multiset.rel_zero_right] apply factors_unique irreducible_of_normalized_factor · intro x hx exfalso apply Multiset.not_mem_zero x hx · apply normalizedFactors_prod one_ne_zero @[simp] theorem normalizedFactors_mul {x y : α} (hx : x ≠ 0) (hy : y ≠ 0) : normalizedFactors (x * y) = normalizedFactors x + normalizedFactors y := by have h : (normalize : α → α) = Associates.out ∘ Associates.mk := by ext rw [Function.comp_apply, Associates.out_mk] rw [← Multiset.map_id' (normalizedFactors (x * y)), ← Multiset.map_id' (normalizedFactors x), ← Multiset.map_id' (normalizedFactors y), ← Multiset.map_congr rfl normalize_normalized_factor, ← Multiset.map_congr rfl normalize_normalized_factor, ← Multiset.map_congr rfl normalize_normalized_factor, ← Multiset.map_add, h, ← Multiset.map_map Associates.out, eq_comm, ← Multiset.map_map Associates.out] refine congr rfl ?_ apply Multiset.map_mk_eq_map_mk_of_rel apply factors_unique · intro x hx rcases Multiset.mem_add.1 hx with (hx | hx) <;> exact irreducible_of_normalized_factor x hx · exact irreducible_of_normalized_factor · rw [Multiset.prod_add] exact ((normalizedFactors_prod hx).mul_mul (normalizedFactors_prod hy)).trans (normalizedFactors_prod (mul_ne_zero hx hy)).symm @[simp] theorem normalizedFactors_pow {x : α} (n : ℕ) : normalizedFactors (x ^ n) = n • normalizedFactors x := by induction' n with n ih · simp by_cases h0 : x = 0 · simp [h0, zero_pow n.succ_ne_zero, smul_zero] rw [pow_succ', succ_nsmul', normalizedFactors_mul h0 (pow_ne_zero _ h0), ih] theorem _root_.Irreducible.normalizedFactors_pow {p : α} (hp : Irreducible p) (k : ℕ) : normalizedFactors (p ^ k) = Multiset.replicate k (normalize p) := by rw [UniqueFactorizationMonoid.normalizedFactors_pow, normalizedFactors_irreducible hp, Multiset.nsmul_singleton] theorem normalizedFactors_prod_eq (s : Multiset α) (hs : ∀ a ∈ s, Irreducible a) : normalizedFactors s.prod = s.map normalize := by induction' s using Multiset.induction with a s ih · rw [Multiset.prod_zero, normalizedFactors_one, Multiset.map_zero] · have ia := hs a (Multiset.mem_cons_self a _) have ib := fun b h => hs b (Multiset.mem_cons_of_mem h) obtain rfl | ⟨b, hb⟩ := s.empty_or_exists_mem · rw [Multiset.cons_zero, Multiset.prod_singleton, Multiset.map_singleton, normalizedFactors_irreducible ia] haveI := nontrivial_of_ne b 0 (ib b hb).ne_zero rw [Multiset.prod_cons, Multiset.map_cons, normalizedFactors_mul ia.ne_zero (Multiset.prod_ne_zero fun h => (ib 0 h).ne_zero rfl), normalizedFactors_irreducible ia, ih ib, Multiset.singleton_add] theorem dvd_iff_normalizedFactors_le_normalizedFactors {x y : α} (hx : x ≠ 0) (hy : y ≠ 0) : x ∣ y ↔ normalizedFactors x ≤ normalizedFactors y := by constructor · rintro ⟨c, rfl⟩ simp [hx, right_ne_zero_of_mul hy] · rw [← (normalizedFactors_prod hx).dvd_iff_dvd_left, ← (normalizedFactors_prod hy).dvd_iff_dvd_right] apply Multiset.prod_dvd_prod_of_le theorem associated_iff_normalizedFactors_eq_normalizedFactors {x y : α} (hx : x ≠ 0) (hy : y ≠ 0) : x ~ᵤ y ↔ normalizedFactors x = normalizedFactors y := by refine ⟨fun h => ?_, fun h => (normalizedFactors_prod hx).symm.trans (_root_.trans (by rw [h]) (normalizedFactors_prod hy))⟩ apply le_antisymm <;> rw [← dvd_iff_normalizedFactors_le_normalizedFactors] all_goals simp [*, h.dvd, h.symm.dvd] theorem normalizedFactors_of_irreducible_pow {p : α} (hp : Irreducible p) (k : ℕ) : normalizedFactors (p ^ k) = Multiset.replicate k (normalize p) := by rw [normalizedFactors_pow, normalizedFactors_irreducible hp, Multiset.nsmul_singleton] theorem zero_not_mem_normalizedFactors (x : α) : (0 : α) ∉ normalizedFactors x := fun h => Prime.ne_zero (prime_of_normalized_factor _ h) rfl theorem dvd_of_mem_normalizedFactors {a p : α} (H : p ∈ normalizedFactors a) : p ∣ a := by by_cases hcases : a = 0 · rw [hcases] exact dvd_zero p · exact dvd_trans (Multiset.dvd_prod H) (Associated.dvd (normalizedFactors_prod hcases)) theorem mem_normalizedFactors_iff [Unique αˣ] {p x : α} (hx : x ≠ 0) : p ∈ normalizedFactors x ↔ Prime p ∧ p ∣ x := by constructor · intro h exact ⟨prime_of_normalized_factor p h, dvd_of_mem_normalizedFactors h⟩ · rintro ⟨hprime, hdvd⟩ obtain ⟨q, hqmem, hqeq⟩ := exists_mem_normalizedFactors_of_dvd hx hprime.irreducible hdvd rw [associated_iff_eq] at hqeq exact hqeq ▸ hqmem theorem exists_associated_prime_pow_of_unique_normalized_factor {p r : α} (h : ∀ {m}, m ∈ normalizedFactors r → m = p) (hr : r ≠ 0) : ∃ i : ℕ, Associated (p ^ i) r := by use Multiset.card.toFun (normalizedFactors r) have := UniqueFactorizationMonoid.normalizedFactors_prod hr rwa [Multiset.eq_replicate_of_mem fun b => h, Multiset.prod_replicate] at this theorem normalizedFactors_prod_of_prime [Nontrivial α] [Unique αˣ] {m : Multiset α} (h : ∀ p ∈ m, Prime p) : normalizedFactors m.prod = m := by simpa only [← Multiset.rel_eq, ← associated_eq_eq] using prime_factors_unique prime_of_normalized_factor h (normalizedFactors_prod (m.prod_ne_zero_of_prime h)) theorem mem_normalizedFactors_eq_of_associated {a b c : α} (ha : a ∈ normalizedFactors c) (hb : b ∈ normalizedFactors c) (h : Associated a b) : a = b := by rw [← normalize_normalized_factor a ha, ← normalize_normalized_factor b hb, normalize_eq_normalize_iff] exact Associated.dvd_dvd h @[simp] theorem normalizedFactors_pos (x : α) (hx : x ≠ 0) : 0 < normalizedFactors x ↔ ¬IsUnit x := by constructor · intro h hx obtain ⟨p, hp⟩ := Multiset.exists_mem_of_ne_zero h.ne' exact (prime_of_normalized_factor _ hp).not_unit (isUnit_of_dvd_unit (dvd_of_mem_normalizedFactors hp) hx) · intro h obtain ⟨p, hp⟩ := exists_mem_normalizedFactors hx h exact bot_lt_iff_ne_bot.mpr (mt Multiset.eq_zero_iff_forall_not_mem.mp (not_forall.mpr ⟨p, not_not.mpr hp⟩)) theorem dvdNotUnit_iff_normalizedFactors_lt_normalizedFactors {x y : α} (hx : x ≠ 0) (hy : y ≠ 0) : DvdNotUnit x y ↔ normalizedFactors x < normalizedFactors y := by constructor · rintro ⟨_, c, hc, rfl⟩ simp only [hx, right_ne_zero_of_mul hy, normalizedFactors_mul, Ne, not_false_iff, lt_add_iff_pos_right, normalizedFactors_pos, hc] · intro h exact dvdNotUnit_of_dvd_of_not_dvd ((dvd_iff_normalizedFactors_le_normalizedFactors hx hy).mpr h.le) (mt (dvd_iff_normalizedFactors_le_normalizedFactors hy hx).mp h.not_le) theorem normalizedFactors_multiset_prod (s : Multiset α) (hs : 0 ∉ s) : normalizedFactors (s.prod) = (s.map normalizedFactors).sum := by cases subsingleton_or_nontrivial α · obtain rfl : s = 0 := by apply Multiset.eq_zero_of_forall_not_mem intro _ convert hs simp induction s using Multiset.induction with | empty => simp | cons _ _ IH => rw [Multiset.prod_cons, Multiset.map_cons, Multiset.sum_cons, normalizedFactors_mul, IH] · exact fun h ↦ hs (Multiset.mem_cons_of_mem h) · exact fun h ↦ hs (h ▸ Multiset.mem_cons_self _ _) · apply Multiset.prod_ne_zero exact fun h ↦ hs (Multiset.mem_cons_of_mem h) end UniqueFactorizationMonoid namespace UniqueFactorizationMonoid open scoped Classical open Multiset Associates variable [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] /-- Noncomputably defines a `normalizationMonoid` structure on a `UniqueFactorizationMonoid`. -/ protected noncomputable def normalizationMonoid : NormalizationMonoid α := normalizationMonoidOfMonoidHomRightInverse { toFun := fun a : Associates α => if a = 0 then 0 else ((normalizedFactors a).map (Classical.choose mk_surjective.hasRightInverse : Associates α → α)).prod map_one' := by nontriviality α; simp map_mul' := fun x y => by by_cases hx : x = 0 · simp [hx] by_cases hy : y = 0 · simp [hy] simp [hx, hy] } (by intro x dsimp by_cases hx : x = 0 · simp [hx] have h : Associates.mkMonoidHom ∘ Classical.choose mk_surjective.hasRightInverse = (id : Associates α → Associates α) := by ext x rw [Function.comp_apply, mkMonoidHom_apply, Classical.choose_spec mk_surjective.hasRightInverse x] rfl rw [if_neg hx, ← mkMonoidHom_apply, MonoidHom.map_multiset_prod, map_map, h, map_id, ← associated_iff_eq] apply normalizedFactors_prod hx) end UniqueFactorizationMonoid namespace UniqueFactorizationMonoid variable {R : Type*} [CancelCommMonoidWithZero R] [UniqueFactorizationMonoid R] theorem isRelPrime_iff_no_prime_factors {a b : R} (ha : a ≠ 0) : IsRelPrime a b ↔ ∀ ⦃d⦄, d ∣ a → d ∣ b → ¬Prime d := ⟨fun h _ ha hb ↦ (·.not_unit <| h ha hb), fun h ↦ WfDvdMonoid.isRelPrime_of_no_irreducible_factors (ha ·.1) fun _ irr ha hb ↦ h ha hb (UniqueFactorizationMonoid.irreducible_iff_prime.mp irr)⟩ /-- Euclid's lemma: if `a ∣ b * c` and `a` and `c` have no common prime factors, `a ∣ b`. Compare `IsCoprime.dvd_of_dvd_mul_left`. -/ theorem dvd_of_dvd_mul_left_of_no_prime_factors {a b c : R} (ha : a ≠ 0) (h : ∀ ⦃d⦄, d ∣ a → d ∣ c → ¬Prime d) : a ∣ b * c → a ∣ b := ((isRelPrime_iff_no_prime_factors ha).mpr h).dvd_of_dvd_mul_right /-- Euclid's lemma: if `a ∣ b * c` and `a` and `b` have no common prime factors, `a ∣ c`. Compare `IsCoprime.dvd_of_dvd_mul_right`. -/ theorem dvd_of_dvd_mul_right_of_no_prime_factors {a b c : R} (ha : a ≠ 0) (no_factors : ∀ {d}, d ∣ a → d ∣ b → ¬Prime d) : a ∣ b * c → a ∣ c := by simpa [mul_comm b c] using dvd_of_dvd_mul_left_of_no_prime_factors ha @no_factors /-- If `a ≠ 0, b` are elements of a unique factorization domain, then dividing out their common factor `c'` gives `a'` and `b'` with no factors in common. -/ theorem exists_reduced_factors : ∀ a ≠ (0 : R), ∀ b, ∃ a' b' c', IsRelPrime a' b' ∧ c' * a' = a ∧ c' * b' = b := by intro a refine induction_on_prime a ?_ ?_ ?_ · intros contradiction · intro a a_unit _ b use a, b, 1 constructor · intro p p_dvd_a _ exact isUnit_of_dvd_unit p_dvd_a a_unit · simp · intro a p a_ne_zero p_prime ih_a pa_ne_zero b by_cases h : p ∣ b · rcases h with ⟨b, rfl⟩ obtain ⟨a', b', c', no_factor, ha', hb'⟩ := ih_a a_ne_zero b refine ⟨a', b', p * c', @no_factor, ?_, ?_⟩ · rw [mul_assoc, ha'] · rw [mul_assoc, hb'] · obtain ⟨a', b', c', coprime, rfl, rfl⟩ := ih_a a_ne_zero b refine ⟨p * a', b', c', ?_, mul_left_comm _ _ _, rfl⟩ intro q q_dvd_pa' q_dvd_b' cases' p_prime.left_dvd_or_dvd_right_of_dvd_mul q_dvd_pa' with p_dvd_q q_dvd_a' · have : p ∣ c' * b' := dvd_mul_of_dvd_right (p_dvd_q.trans q_dvd_b') _ contradiction exact coprime q_dvd_a' q_dvd_b' theorem exists_reduced_factors' (a b : R) (hb : b ≠ 0) : ∃ a' b' c', IsRelPrime a' b' ∧ c' * a' = a ∧ c' * b' = b := let ⟨b', a', c', no_factor, hb, ha⟩ := exists_reduced_factors b hb a ⟨a', b', c', fun _ hpb hpa => no_factor hpa hpb, ha, hb⟩ theorem pow_right_injective {a : R} (ha0 : a ≠ 0) (ha1 : ¬IsUnit a) : Function.Injective (a ^ · : ℕ → R) := by letI := Classical.decEq R intro i j hij letI : Nontrivial R := ⟨⟨a, 0, ha0⟩⟩ letI : NormalizationMonoid R := UniqueFactorizationMonoid.normalizationMonoid obtain ⟨p', hp', dvd'⟩ := WfDvdMonoid.exists_irreducible_factor ha1 ha0 obtain ⟨p, mem, _⟩ := exists_mem_normalizedFactors_of_dvd ha0 hp' dvd' have := congr_arg (fun x => Multiset.count p (normalizedFactors x)) hij simp only [normalizedFactors_pow, Multiset.count_nsmul] at this exact mul_right_cancel₀ (Multiset.count_ne_zero.mpr mem) this theorem pow_eq_pow_iff {a : R} (ha0 : a ≠ 0) (ha1 : ¬IsUnit a) {i j : ℕ} : a ^ i = a ^ j ↔ i = j := (pow_right_injective ha0 ha1).eq_iff section multiplicity variable [NormalizationMonoid R] variable [DecidableRel (Dvd.dvd : R → R → Prop)] open multiplicity Multiset theorem le_multiplicity_iff_replicate_le_normalizedFactors {a b : R} {n : ℕ} (ha : Irreducible a) (hb : b ≠ 0) : ↑n ≤ multiplicity a b ↔ replicate n (normalize a) ≤ normalizedFactors b := by rw [← pow_dvd_iff_le_multiplicity] revert b induction' n with n ih; · simp intro b hb constructor · rintro ⟨c, rfl⟩ rw [Ne, pow_succ', mul_assoc, mul_eq_zero, not_or] at hb rw [pow_succ', mul_assoc, normalizedFactors_mul hb.1 hb.2, replicate_succ, normalizedFactors_irreducible ha, singleton_add, cons_le_cons_iff, ← ih hb.2] apply Dvd.intro _ rfl · rw [Multiset.le_iff_exists_add] rintro ⟨u, hu⟩ rw [← (normalizedFactors_prod hb).dvd_iff_dvd_right, hu, prod_add, prod_replicate] exact (Associated.pow_pow <| associated_normalize a).dvd.trans (Dvd.intro u.prod rfl) /-- The multiplicity of an irreducible factor of a nonzero element is exactly the number of times the normalized factor occurs in the `normalizedFactors`. See also `count_normalizedFactors_eq` which expands the definition of `multiplicity` to produce a specification for `count (normalizedFactors _) _`.. -/ theorem multiplicity_eq_count_normalizedFactors [DecidableEq R] {a b : R} (ha : Irreducible a) (hb : b ≠ 0) : multiplicity a b = (normalizedFactors b).count (normalize a) := by apply le_antisymm · apply PartENat.le_of_lt_add_one rw [← Nat.cast_one, ← Nat.cast_add, lt_iff_not_ge, ge_iff_le, le_multiplicity_iff_replicate_le_normalizedFactors ha hb, ← le_count_iff_replicate_le] simp rw [le_multiplicity_iff_replicate_le_normalizedFactors ha hb, ← le_count_iff_replicate_le] /-- The number of times an irreducible factor `p` appears in `normalizedFactors x` is defined by the number of times it divides `x`. See also `multiplicity_eq_count_normalizedFactors` if `n` is given by `multiplicity p x`. -/ theorem count_normalizedFactors_eq [DecidableEq R] {p x : R} (hp : Irreducible p) (hnorm : normalize p = p) {n : ℕ} (hle : p ^ n ∣ x) (hlt : ¬p ^ (n + 1) ∣ x) : (normalizedFactors x).count p = n := by letI : DecidableRel ((· ∣ ·) : R → R → Prop) := fun _ _ => Classical.propDecidable _ by_cases hx0 : x = 0 · simp [hx0] at hlt rw [← PartENat.natCast_inj] convert (multiplicity_eq_count_normalizedFactors hp hx0).symm · exact hnorm.symm exact (multiplicity.eq_coe_iff.mpr ⟨hle, hlt⟩).symm /-- The number of times an irreducible factor `p` appears in `normalizedFactors x` is defined by the number of times it divides `x`. This is a slightly more general version of `UniqueFactorizationMonoid.count_normalizedFactors_eq` that allows `p = 0`. See also `multiplicity_eq_count_normalizedFactors` if `n` is given by `multiplicity p x`. -/ theorem count_normalizedFactors_eq' [DecidableEq R] {p x : R} (hp : p = 0 ∨ Irreducible p) (hnorm : normalize p = p) {n : ℕ} (hle : p ^ n ∣ x) (hlt : ¬p ^ (n + 1) ∣ x) : (normalizedFactors x).count p = n := by rcases hp with (rfl | hp) · cases n · exact count_eq_zero.2 (zero_not_mem_normalizedFactors _) · rw [zero_pow (Nat.succ_ne_zero _)] at hle hlt exact absurd hle hlt · exact count_normalizedFactors_eq hp hnorm hle hlt /-- Deprecated. Use `WfDvdMonoid.max_power_factor` instead. -/ @[deprecated WfDvdMonoid.max_power_factor (since := "2024-03-01")] theorem max_power_factor {a₀ x : R} (h : a₀ ≠ 0) (hx : Irreducible x) : ∃ n : ℕ, ∃ a : R, ¬x ∣ a ∧ a₀ = x ^ n * a := WfDvdMonoid.max_power_factor h hx end multiplicity section Multiplicative variable [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] variable {β : Type*} [CancelCommMonoidWithZero β] theorem prime_pow_coprime_prod_of_coprime_insert [DecidableEq α] {s : Finset α} (i : α → ℕ) (p : α) (hps : p ∉ s) (is_prime : ∀ q ∈ insert p s, Prime q) (is_coprime : ∀ᵉ (q ∈ insert p s) (q' ∈ insert p s), q ∣ q' → q = q') : IsRelPrime (p ^ i p) (∏ p' ∈ s, p' ^ i p') := by have hp := is_prime _ (Finset.mem_insert_self _ _) refine (isRelPrime_iff_no_prime_factors <| pow_ne_zero _ hp.ne_zero).mpr ?_ intro d hdp hdprod hd apply hps replace hdp := hd.dvd_of_dvd_pow hdp obtain ⟨q, q_mem', hdq⟩ := hd.exists_mem_multiset_dvd hdprod obtain ⟨q, q_mem, rfl⟩ := Multiset.mem_map.mp q_mem' replace hdq := hd.dvd_of_dvd_pow hdq have : p ∣ q := dvd_trans (hd.irreducible.dvd_symm hp.irreducible hdp) hdq convert q_mem rw [Finset.mem_val, is_coprime _ (Finset.mem_insert_self p s) _ (Finset.mem_insert_of_mem q_mem) this] /-- If `P` holds for units and powers of primes, and `P x ∧ P y` for coprime `x, y` implies `P (x * y)`, then `P` holds on a product of powers of distinct primes. -/ -- @[elab_as_elim] Porting note: commented out theorem induction_on_prime_power {P : α → Prop} (s : Finset α) (i : α → ℕ) (is_prime : ∀ p ∈ s, Prime p) (is_coprime : ∀ᵉ (p ∈ s) (q ∈ s), p ∣ q → p = q) (h1 : ∀ {x}, IsUnit x → P x) (hpr : ∀ {p} (i : ℕ), Prime p → P (p ^ i)) (hcp : ∀ {x y}, IsRelPrime x y → P x → P y → P (x * y)) : P (∏ p ∈ s, p ^ i p) := by letI := Classical.decEq α induction' s using Finset.induction_on with p f' hpf' ih · simpa using h1 isUnit_one rw [Finset.prod_insert hpf'] exact hcp (prime_pow_coprime_prod_of_coprime_insert i p hpf' is_prime is_coprime) (hpr (i p) (is_prime _ (Finset.mem_insert_self _ _))) (ih (fun q hq => is_prime _ (Finset.mem_insert_of_mem hq)) fun q hq q' hq' => is_coprime _ (Finset.mem_insert_of_mem hq) _ (Finset.mem_insert_of_mem hq')) /-- If `P` holds for `0`, units and powers of primes, and `P x ∧ P y` for coprime `x, y` implies `P (x * y)`, then `P` holds on all `a : α`. -/ @[elab_as_elim] theorem induction_on_coprime {P : α → Prop} (a : α) (h0 : P 0) (h1 : ∀ {x}, IsUnit x → P x) (hpr : ∀ {p} (i : ℕ), Prime p → P (p ^ i)) (hcp : ∀ {x y}, IsRelPrime x y → P x → P y → P (x * y)) : P a := by letI := Classical.decEq α have P_of_associated : ∀ {x y}, Associated x y → P x → P y := by rintro x y ⟨u, rfl⟩ hx exact hcp (fun p _ hpx => isUnit_of_dvd_unit hpx u.isUnit) hx (h1 u.isUnit) by_cases ha0 : a = 0 · rwa [ha0] haveI : Nontrivial α := ⟨⟨_, _, ha0⟩⟩ letI : NormalizationMonoid α := UniqueFactorizationMonoid.normalizationMonoid refine P_of_associated (normalizedFactors_prod ha0) ?_ rw [← (normalizedFactors a).map_id, Finset.prod_multiset_map_count] refine induction_on_prime_power _ _ ?_ ?_ @h1 @hpr @hcp <;> simp only [Multiset.mem_toFinset] · apply prime_of_normalized_factor · apply normalizedFactors_eq_of_dvd /-- If `f` maps `p ^ i` to `(f p) ^ i` for primes `p`, and `f` is multiplicative on coprime elements, then `f` is multiplicative on all products of primes. -/ -- @[elab_as_elim] Porting note: commented out theorem multiplicative_prime_power {f : α → β} (s : Finset α) (i j : α → ℕ) (is_prime : ∀ p ∈ s, Prime p) (is_coprime : ∀ᵉ (p ∈ s) (q ∈ s), p ∣ q → p = q) (h1 : ∀ {x y}, IsUnit y → f (x * y) = f x * f y) (hpr : ∀ {p} (i : ℕ), Prime p → f (p ^ i) = f p ^ i) (hcp : ∀ {x y}, IsRelPrime x y → f (x * y) = f x * f y) : f (∏ p ∈ s, p ^ (i p + j p)) = f (∏ p ∈ s, p ^ i p) * f (∏ p ∈ s, p ^ j p) := by letI := Classical.decEq α induction' s using Finset.induction_on with p s hps ih · simpa using h1 isUnit_one have hpr_p := is_prime _ (Finset.mem_insert_self _ _) have hpr_s : ∀ p ∈ s, Prime p := fun p hp => is_prime _ (Finset.mem_insert_of_mem hp) have hcp_p := fun i => prime_pow_coprime_prod_of_coprime_insert i p hps is_prime is_coprime have hcp_s : ∀ᵉ (p ∈ s) (q ∈ s), p ∣ q → p = q := fun p hp q hq => is_coprime p (Finset.mem_insert_of_mem hp) q (Finset.mem_insert_of_mem hq) rw [Finset.prod_insert hps, Finset.prod_insert hps, Finset.prod_insert hps, hcp (hcp_p _), hpr _ hpr_p, hcp (hcp_p _), hpr _ hpr_p, hcp (hcp_p (fun p => i p + j p)), hpr _ hpr_p, ih hpr_s hcp_s, pow_add, mul_assoc, mul_left_comm (f p ^ j p), mul_assoc] /-- If `f` maps `p ^ i` to `(f p) ^ i` for primes `p`, and `f` is multiplicative on coprime elements, then `f` is multiplicative everywhere. -/ theorem multiplicative_of_coprime (f : α → β) (a b : α) (h0 : f 0 = 0) (h1 : ∀ {x y}, IsUnit y → f (x * y) = f x * f y) (hpr : ∀ {p} (i : ℕ), Prime p → f (p ^ i) = f p ^ i) (hcp : ∀ {x y}, IsRelPrime x y → f (x * y) = f x * f y) : f (a * b) = f a * f b := by letI := Classical.decEq α by_cases ha0 : a = 0 · rw [ha0, zero_mul, h0, zero_mul] by_cases hb0 : b = 0 · rw [hb0, mul_zero, h0, mul_zero] by_cases hf1 : f 1 = 0 · calc f (a * b) = f (a * b * 1) := by rw [mul_one] _ = 0 := by simp only [h1 isUnit_one, hf1, mul_zero] _ = f a * f (b * 1) := by simp only [h1 isUnit_one, hf1, mul_zero] _ = f a * f b := by rw [mul_one] haveI : Nontrivial α := ⟨⟨_, _, ha0⟩⟩ letI : NormalizationMonoid α := UniqueFactorizationMonoid.normalizationMonoid suffices f (∏ p ∈ (normalizedFactors a).toFinset ∪ (normalizedFactors b).toFinset, p ^ ((normalizedFactors a).count p + (normalizedFactors b).count p)) = f (∏ p ∈ (normalizedFactors a).toFinset ∪ (normalizedFactors b).toFinset, p ^ (normalizedFactors a).count p) * f (∏ p ∈ (normalizedFactors a).toFinset ∪ (normalizedFactors b).toFinset, p ^ (normalizedFactors b).count p) by obtain ⟨ua, a_eq⟩ := normalizedFactors_prod ha0 obtain ⟨ub, b_eq⟩ := normalizedFactors_prod hb0 rw [← a_eq, ← b_eq, mul_right_comm (Multiset.prod (normalizedFactors a)) ua (Multiset.prod (normalizedFactors b) * ub), h1 ua.isUnit, h1 ub.isUnit, h1 ua.isUnit, ← mul_assoc, h1 ub.isUnit, mul_right_comm _ (f ua), ← mul_assoc] congr rw [← (normalizedFactors a).map_id, ← (normalizedFactors b).map_id, Finset.prod_multiset_map_count, Finset.prod_multiset_map_count, Finset.prod_subset (Finset.subset_union_left (s₂ := (normalizedFactors b).toFinset)), Finset.prod_subset (Finset.subset_union_right (s₂ := (normalizedFactors b).toFinset)), ← Finset.prod_mul_distrib] · simp_rw [id, ← pow_add, this] all_goals simp only [Multiset.mem_toFinset] · intro p _ hpb simp [hpb] · intro p _ hpa simp [hpa] refine multiplicative_prime_power _ _ _ ?_ ?_ @h1 @hpr @hcp all_goals simp only [Multiset.mem_toFinset, Finset.mem_union] · rintro p (hpa | hpb) <;> apply prime_of_normalized_factor <;> assumption · rintro p (hp | hp) q (hq | hq) hdvd <;> rw [← normalize_normalized_factor _ hp, ← normalize_normalized_factor _ hq] <;> exact normalize_eq_normalize hdvd ((prime_of_normalized_factor _ hp).irreducible.dvd_symm (prime_of_normalized_factor _ hq).irreducible hdvd) end Multiplicative end UniqueFactorizationMonoid namespace Associates open UniqueFactorizationMonoid Associated Multiset variable [CancelCommMonoidWithZero α] /-- `FactorSet α` representation elements of unique factorization domain as multisets. `Multiset α` produced by `normalizedFactors` are only unique up to associated elements, while the multisets in `FactorSet α` are unique by equality and restricted to irreducible elements. This gives us a representation of each element as a unique multisets (or the added ⊤ for 0), which has a complete lattice structure. Infimum is the greatest common divisor and supremum is the least common multiple. -/ abbrev FactorSet.{u} (α : Type u) [CancelCommMonoidWithZero α] : Type u := WithTop (Multiset { a : Associates α // Irreducible a }) attribute [local instance] Associated.setoid theorem FactorSet.coe_add {a b : Multiset { a : Associates α // Irreducible a }} : (↑(a + b) : FactorSet α) = a + b := by norm_cast theorem FactorSet.sup_add_inf_eq_add [DecidableEq (Associates α)] : ∀ a b : FactorSet α, a ⊔ b + a ⊓ b = a + b | ⊤, b => show ⊤ ⊔ b + ⊤ ⊓ b = ⊤ + b by simp | a, ⊤ => show a ⊔ ⊤ + a ⊓ ⊤ = a + ⊤ by simp | WithTop.some a, WithTop.some b => show (a : FactorSet α) ⊔ b + (a : FactorSet α) ⊓ b = a + b by rw [← WithTop.coe_sup, ← WithTop.coe_inf, ← WithTop.coe_add, ← WithTop.coe_add, WithTop.coe_eq_coe] exact Multiset.union_add_inter _ _ /-- Evaluates the product of a `FactorSet` to be the product of the corresponding multiset, or `0` if there is none. -/ def FactorSet.prod : FactorSet α → Associates α | ⊤ => 0 | WithTop.some s => (s.map (↑)).prod @[simp] theorem prod_top : (⊤ : FactorSet α).prod = 0 := rfl @[simp] theorem prod_coe {s : Multiset { a : Associates α // Irreducible a }} : FactorSet.prod (s : FactorSet α) = (s.map (↑)).prod := rfl @[simp] theorem prod_add : ∀ a b : FactorSet α, (a + b).prod = a.prod * b.prod | ⊤, b => show (⊤ + b).prod = (⊤ : FactorSet α).prod * b.prod by simp | a, ⊤ => show (a + ⊤).prod = a.prod * (⊤ : FactorSet α).prod by simp | WithTop.some a, WithTop.some b => by rw [← FactorSet.coe_add, prod_coe, prod_coe, prod_coe, Multiset.map_add, Multiset.prod_add] @[gcongr] theorem prod_mono : ∀ {a b : FactorSet α}, a ≤ b → a.prod ≤ b.prod | ⊤, b, h => by have : b = ⊤ := top_unique h rw [this, prod_top] | a, ⊤, _ => show a.prod ≤ (⊤ : FactorSet α).prod by simp | WithTop.some a, WithTop.some b, h => prod_le_prod <| Multiset.map_le_map <| WithTop.coe_le_coe.1 <| h theorem FactorSet.prod_eq_zero_iff [Nontrivial α] (p : FactorSet α) : p.prod = 0 ↔ p = ⊤ := by unfold FactorSet at p induction p -- TODO: `induction_eliminator` doesn't work with `abbrev` · simp only [iff_self_iff, eq_self_iff_true, Associates.prod_top] · rw [prod_coe, Multiset.prod_eq_zero_iff, Multiset.mem_map, eq_false WithTop.coe_ne_top, iff_false_iff, not_exists] exact fun a => not_and_of_not_right _ a.prop.ne_zero section count variable [DecidableEq (Associates α)] /-- `bcount p s` is the multiplicity of `p` in the FactorSet `s` (with bundled `p`)-/ def bcount (p : { a : Associates α // Irreducible a }) : FactorSet α → ℕ | ⊤ => 0 | WithTop.some s => s.count p variable [∀ p : Associates α, Decidable (Irreducible p)] {p : Associates α} /-- `count p s` is the multiplicity of the irreducible `p` in the FactorSet `s`. If `p` is not irreducible, `count p s` is defined to be `0`. -/ def count (p : Associates α) : FactorSet α → ℕ := if hp : Irreducible p then bcount ⟨p, hp⟩ else 0 @[simp] theorem count_some (hp : Irreducible p) (s : Multiset _) : count p (WithTop.some s) = s.count ⟨p, hp⟩ := by simp only [count, dif_pos hp, bcount] @[simp] theorem count_zero (hp : Irreducible p) : count p (0 : FactorSet α) = 0 := by simp only [count, dif_pos hp, bcount, Multiset.count_zero] theorem count_reducible (hp : ¬Irreducible p) : count p = 0 := dif_neg hp end count section Mem /-- membership in a FactorSet (bundled version) -/ def BfactorSetMem : { a : Associates α // Irreducible a } → FactorSet α → Prop | _, ⊤ => True | p, some l => p ∈ l /-- `FactorSetMem p s` is the predicate that the irreducible `p` is a member of `s : FactorSet α`. If `p` is not irreducible, `p` is not a member of any `FactorSet`. -/ def FactorSetMem (p : Associates α) (s : FactorSet α) : Prop := letI : Decidable (Irreducible p) := Classical.dec _ if hp : Irreducible p then BfactorSetMem ⟨p, hp⟩ s else False instance : Membership (Associates α) (FactorSet α) := ⟨FactorSetMem⟩ @[simp] theorem factorSetMem_eq_mem (p : Associates α) (s : FactorSet α) : FactorSetMem p s = (p ∈ s) := rfl theorem mem_factorSet_top {p : Associates α} {hp : Irreducible p} : p ∈ (⊤ : FactorSet α) := by dsimp only [Membership.mem]; dsimp only [FactorSetMem]; split_ifs; exact trivial theorem mem_factorSet_some {p : Associates α} {hp : Irreducible p} {l : Multiset { a : Associates α // Irreducible a }} : p ∈ (l : FactorSet α) ↔ Subtype.mk p hp ∈ l := by dsimp only [Membership.mem]; dsimp only [FactorSetMem]; split_ifs; rfl theorem reducible_not_mem_factorSet {p : Associates α} (hp : ¬Irreducible p) (s : FactorSet α) : ¬p ∈ s := fun h ↦ by rwa [← factorSetMem_eq_mem, FactorSetMem, dif_neg hp] at h theorem irreducible_of_mem_factorSet {p : Associates α} {s : FactorSet α} (h : p ∈ s) : Irreducible p := by_contra fun hp ↦ reducible_not_mem_factorSet hp s h end Mem variable [UniqueFactorizationMonoid α] theorem unique' {p q : Multiset (Associates α)} : (∀ a ∈ p, Irreducible a) → (∀ a ∈ q, Irreducible a) → p.prod = q.prod → p = q := by apply Multiset.induction_on_multiset_quot p apply Multiset.induction_on_multiset_quot q intro s t hs ht eq refine Multiset.map_mk_eq_map_mk_of_rel (UniqueFactorizationMonoid.factors_unique ?_ ?_ ?_) · exact fun a ha => irreducible_mk.1 <| hs _ <| Multiset.mem_map_of_mem _ ha · exact fun a ha => irreducible_mk.1 <| ht _ <| Multiset.mem_map_of_mem _ ha have eq' : (Quot.mk Setoid.r : α → Associates α) = Associates.mk := funext quot_mk_eq_mk rwa [eq', prod_mk, prod_mk, mk_eq_mk_iff_associated] at eq theorem FactorSet.unique [Nontrivial α] {p q : FactorSet α} (h : p.prod = q.prod) : p = q := by -- TODO: `induction_eliminator` doesn't work with `abbrev` unfold FactorSet at p q induction p <;> induction q · rfl · rw [eq_comm, ← FactorSet.prod_eq_zero_iff, ← h, Associates.prod_top] · rw [← FactorSet.prod_eq_zero_iff, h, Associates.prod_top] · congr 1 rw [← Multiset.map_eq_map Subtype.coe_injective] apply unique' _ _ h <;> · intro a ha obtain ⟨⟨a', irred⟩, -, rfl⟩ := Multiset.mem_map.mp ha rwa [Subtype.coe_mk] theorem prod_le_prod_iff_le [Nontrivial α] {p q : Multiset (Associates α)} (hp : ∀ a ∈ p, Irreducible a) (hq : ∀ a ∈ q, Irreducible a) : p.prod ≤ q.prod ↔ p ≤ q := by refine ⟨?_, prod_le_prod⟩ rintro ⟨c, eqc⟩ refine Multiset.le_iff_exists_add.2 ⟨factors c, unique' hq (fun x hx ↦ ?_) ?_⟩ · obtain h | h := Multiset.mem_add.1 hx · exact hp x h · exact irreducible_of_factor _ h · rw [eqc, Multiset.prod_add] congr refine associated_iff_eq.mp (factors_prod fun hc => ?_).symm refine not_irreducible_zero (hq _ ?_) rw [← prod_eq_zero_iff, eqc, hc, mul_zero] /-- This returns the multiset of irreducible factors as a `FactorSet`, a multiset of irreducible associates `WithTop`. -/ noncomputable def factors' (a : α) : Multiset { a : Associates α // Irreducible a } := (factors a).pmap (fun a ha => ⟨Associates.mk a, irreducible_mk.2 ha⟩) irreducible_of_factor @[simp] theorem map_subtype_coe_factors' {a : α} : (factors' a).map (↑) = (factors a).map Associates.mk := by simp [factors', Multiset.map_pmap, Multiset.pmap_eq_map] theorem factors'_cong {a b : α} (h : a ~ᵤ b) : factors' a = factors' b := by obtain rfl | hb := eq_or_ne b 0 · rw [associated_zero_iff_eq_zero] at h rw [h] have ha : a ≠ 0 := by contrapose! hb with ha rw [← associated_zero_iff_eq_zero, ← ha] exact h.symm rw [← Multiset.map_eq_map Subtype.coe_injective, map_subtype_coe_factors', map_subtype_coe_factors', ← rel_associated_iff_map_eq_map] exact factors_unique irreducible_of_factor irreducible_of_factor ((factors_prod ha).trans <| h.trans <| (factors_prod hb).symm) /-- This returns the multiset of irreducible factors of an associate as a `FactorSet`, a multiset of irreducible associates `WithTop`. -/ noncomputable def factors (a : Associates α) : FactorSet α := by classical refine if h : a = 0 then ⊤ else Quotient.hrecOn a (fun x _ => factors' x) ?_ h intro a b hab apply Function.hfunext · have : a ~ᵤ 0 ↔ b ~ᵤ 0 := Iff.intro (fun ha0 => hab.symm.trans ha0) fun hb0 => hab.trans hb0 simp only [associated_zero_iff_eq_zero] at this simp only [quotient_mk_eq_mk, this, mk_eq_zero] exact fun ha hb _ => heq_of_eq <| congr_arg some <| factors'_cong hab @[simp] theorem factors_zero : (0 : Associates α).factors = ⊤ := dif_pos rfl @[deprecated (since := "2024-03-16")] alias factors_0 := factors_zero @[simp] theorem factors_mk (a : α) (h : a ≠ 0) : (Associates.mk a).factors = factors' a := by classical apply dif_neg apply mt mk_eq_zero.1 h @[simp] theorem factors_prod (a : Associates α) : a.factors.prod = a := by rcases Associates.mk_surjective a with ⟨a, rfl⟩ rcases eq_or_ne a 0 with rfl | ha · simp · simp [ha, prod_mk, mk_eq_mk_iff_associated, UniqueFactorizationMonoid.factors_prod, -Quotient.eq] @[simp] theorem prod_factors [Nontrivial α] (s : FactorSet α) : s.prod.factors = s := FactorSet.unique <| factors_prod _ @[nontriviality] theorem factors_subsingleton [Subsingleton α] {a : Associates α} : a.factors = ⊤ := by have : Subsingleton (Associates α) := inferInstance convert factors_zero theorem factors_eq_top_iff_zero {a : Associates α} : a.factors = ⊤ ↔ a = 0 := by nontriviality α exact ⟨fun h ↦ by rwa [← factors_prod a, FactorSet.prod_eq_zero_iff], fun h ↦ h ▸ factors_zero⟩ @[deprecated (since := "2024-04-16")] alias factors_eq_none_iff_zero := factors_eq_top_iff_zero theorem factors_eq_some_iff_ne_zero {a : Associates α} : (∃ s : Multiset { p : Associates α // Irreducible p }, a.factors = s) ↔ a ≠ 0 := by simp_rw [@eq_comm _ a.factors, ← WithTop.ne_top_iff_exists] exact factors_eq_top_iff_zero.not theorem eq_of_factors_eq_factors {a b : Associates α} (h : a.factors = b.factors) : a = b := by have : a.factors.prod = b.factors.prod := by rw [h] rwa [factors_prod, factors_prod] at this theorem eq_of_prod_eq_prod [Nontrivial α] {a b : FactorSet α} (h : a.prod = b.prod) : a = b := by have : a.prod.factors = b.prod.factors := by rw [h] rwa [prod_factors, prod_factors] at this @[simp] theorem factors_mul (a b : Associates α) : (a * b).factors = a.factors + b.factors := by nontriviality α refine eq_of_prod_eq_prod <| eq_of_factors_eq_factors ?_ rw [prod_add, factors_prod, factors_prod, factors_prod] @[gcongr] theorem factors_mono : ∀ {a b : Associates α}, a ≤ b → a.factors ≤ b.factors | s, t, ⟨d, eq⟩ => by rw [eq, factors_mul]; exact le_add_of_nonneg_right bot_le @[simp] theorem factors_le {a b : Associates α} : a.factors ≤ b.factors ↔ a ≤ b := by refine ⟨fun h ↦ ?_, factors_mono⟩ have : a.factors.prod ≤ b.factors.prod := prod_mono h rwa [factors_prod, factors_prod] at this section count variable [DecidableEq (Associates α)] [∀ p : Associates α, Decidable (Irreducible p)] theorem eq_factors_of_eq_counts {a b : Associates α} (ha : a ≠ 0) (hb : b ≠ 0) (h : ∀ p : Associates α, Irreducible p → p.count a.factors = p.count b.factors) : a.factors = b.factors := by obtain ⟨sa, h_sa⟩ := factors_eq_some_iff_ne_zero.mpr ha obtain ⟨sb, h_sb⟩ := factors_eq_some_iff_ne_zero.mpr hb rw [h_sa, h_sb] at h ⊢ rw [WithTop.coe_eq_coe] have h_count : ∀ (p : Associates α) (hp : Irreducible p), sa.count ⟨p, hp⟩ = sb.count ⟨p, hp⟩ := by intro p hp rw [← count_some, ← count_some, h p hp] apply Multiset.toFinsupp.injective ext ⟨p, hp⟩ rw [Multiset.toFinsupp_apply, Multiset.toFinsupp_apply, h_count p hp] theorem eq_of_eq_counts {a b : Associates α} (ha : a ≠ 0) (hb : b ≠ 0) (h : ∀ p : Associates α, Irreducible p → p.count a.factors = p.count b.factors) : a = b := eq_of_factors_eq_factors (eq_factors_of_eq_counts ha hb h) theorem count_le_count_of_factors_le {a b p : Associates α} (hb : b ≠ 0) (hp : Irreducible p) (h : a.factors ≤ b.factors) : p.count a.factors ≤ p.count b.factors := by by_cases ha : a = 0 · simp_all obtain ⟨sa, h_sa⟩ := factors_eq_some_iff_ne_zero.mpr ha obtain ⟨sb, h_sb⟩ := factors_eq_some_iff_ne_zero.mpr hb rw [h_sa, h_sb] at h ⊢ rw [count_some hp, count_some hp]; rw [WithTop.coe_le_coe] at h exact Multiset.count_le_of_le _ h theorem count_le_count_of_le {a b p : Associates α} (hb : b ≠ 0) (hp : Irreducible p) (h : a ≤ b) : p.count a.factors ≤ p.count b.factors := count_le_count_of_factors_le hb hp <| factors_mono h end count theorem prod_le [Nontrivial α] {a b : FactorSet α} : a.prod ≤ b.prod ↔ a ≤ b := by refine ⟨fun h ↦ ?_, prod_mono⟩ have : a.prod.factors ≤ b.prod.factors := factors_mono h rwa [prod_factors, prod_factors] at this open Classical in noncomputable instance : Sup (Associates α) := ⟨fun a b => (a.factors ⊔ b.factors).prod⟩ open Classical in noncomputable instance : Inf (Associates α) := ⟨fun a b => (a.factors ⊓ b.factors).prod⟩ open Classical in noncomputable instance : Lattice (Associates α) := { Associates.instPartialOrder with sup := (· ⊔ ·) inf := (· ⊓ ·) sup_le := fun _ _ c hac hbc => factors_prod c ▸ prod_mono (sup_le (factors_mono hac) (factors_mono hbc)) le_sup_left := fun a _ => le_trans (le_of_eq (factors_prod a).symm) <| prod_mono <| le_sup_left le_sup_right := fun _ b => le_trans (le_of_eq (factors_prod b).symm) <| prod_mono <| le_sup_right le_inf := fun a _ _ hac hbc => factors_prod a ▸ prod_mono (le_inf (factors_mono hac) (factors_mono hbc)) inf_le_left := fun a _ => le_trans (prod_mono inf_le_left) (le_of_eq (factors_prod a)) inf_le_right := fun _ b => le_trans (prod_mono inf_le_right) (le_of_eq (factors_prod b)) } open Classical in theorem sup_mul_inf (a b : Associates α) : (a ⊔ b) * (a ⊓ b) = a * b := show (a.factors ⊔ b.factors).prod * (a.factors ⊓ b.factors).prod = a * b by nontriviality α refine eq_of_factors_eq_factors ?_ rw [← prod_add, prod_factors, factors_mul, FactorSet.sup_add_inf_eq_add] theorem dvd_of_mem_factors {a p : Associates α} (hm : p ∈ factors a) : p ∣ a := by rcases eq_or_ne a 0 with rfl | ha0 · exact dvd_zero p obtain ⟨a0, nza, ha'⟩ := exists_non_zero_rep ha0 rw [← Associates.factors_prod a] rw [← ha', factors_mk a0 nza] at hm ⊢ rw [prod_coe] apply Multiset.dvd_prod; apply Multiset.mem_map.mpr exact ⟨⟨p, irreducible_of_mem_factorSet hm⟩, mem_factorSet_some.mp hm, rfl⟩ theorem dvd_of_mem_factors' {a : α} {p : Associates α} {hp : Irreducible p} {hz : a ≠ 0} (h_mem : Subtype.mk p hp ∈ factors' a) : p ∣ Associates.mk a := by haveI := Classical.decEq (Associates α) apply dvd_of_mem_factors rw [factors_mk _ hz] apply mem_factorSet_some.2 h_mem theorem mem_factors'_of_dvd {a p : α} (ha0 : a ≠ 0) (hp : Irreducible p) (hd : p ∣ a) : Subtype.mk (Associates.mk p) (irreducible_mk.2 hp) ∈ factors' a := by obtain ⟨q, hq, hpq⟩ := exists_mem_factors_of_dvd ha0 hp hd apply Multiset.mem_pmap.mpr; use q; use hq exact Subtype.eq (Eq.symm (mk_eq_mk_iff_associated.mpr hpq)) theorem mem_factors'_iff_dvd {a p : α} (ha0 : a ≠ 0) (hp : Irreducible p) : Subtype.mk (Associates.mk p) (irreducible_mk.2 hp) ∈ factors' a ↔ p ∣ a := by constructor · rw [← mk_dvd_mk] apply dvd_of_mem_factors' apply ha0 · apply mem_factors'_of_dvd ha0 hp theorem mem_factors_of_dvd {a p : α} (ha0 : a ≠ 0) (hp : Irreducible p) (hd : p ∣ a) : Associates.mk p ∈ factors (Associates.mk a) := by rw [factors_mk _ ha0] exact mem_factorSet_some.mpr (mem_factors'_of_dvd ha0 hp hd) theorem mem_factors_iff_dvd {a p : α} (ha0 : a ≠ 0) (hp : Irreducible p) : Associates.mk p ∈ factors (Associates.mk a) ↔ p ∣ a := by constructor · rw [← mk_dvd_mk] apply dvd_of_mem_factors · apply mem_factors_of_dvd ha0 hp open Classical in theorem exists_prime_dvd_of_not_inf_one {a b : α} (ha : a ≠ 0) (hb : b ≠ 0) (h : Associates.mk a ⊓ Associates.mk b ≠ 1) : ∃ p : α, Prime p ∧ p ∣ a ∧ p ∣ b := by have hz : factors (Associates.mk a) ⊓ factors (Associates.mk b) ≠ 0 := by contrapose! h with hf change (factors (Associates.mk a) ⊓ factors (Associates.mk b)).prod = 1 rw [hf] exact Multiset.prod_zero rw [factors_mk a ha, factors_mk b hb, ← WithTop.coe_inf] at hz obtain ⟨⟨p0, p0_irr⟩, p0_mem⟩ := Multiset.exists_mem_of_ne_zero ((mt WithTop.coe_eq_coe.mpr) hz) rw [Multiset.inf_eq_inter] at p0_mem obtain ⟨p, rfl⟩ : ∃ p, Associates.mk p = p0 := Quot.exists_rep p0 refine ⟨p, ?_, ?_, ?_⟩ · rw [← UniqueFactorizationMonoid.irreducible_iff_prime, ← irreducible_mk] exact p0_irr · apply dvd_of_mk_le_mk apply dvd_of_mem_factors' (Multiset.mem_inter.mp p0_mem).left apply ha · apply dvd_of_mk_le_mk apply dvd_of_mem_factors' (Multiset.mem_inter.mp p0_mem).right apply hb theorem coprime_iff_inf_one {a b : α} (ha0 : a ≠ 0) (hb0 : b ≠ 0) : Associates.mk a ⊓ Associates.mk b = 1 ↔ ∀ {d : α}, d ∣ a → d ∣ b → ¬Prime d := by constructor · intro hg p ha hb hp refine (Associates.prime_mk.mpr hp).not_unit (isUnit_of_dvd_one ?_) rw [← hg] exact le_inf (mk_le_mk_of_dvd ha) (mk_le_mk_of_dvd hb) · contrapose intro hg hc obtain ⟨p, hp, hpa, hpb⟩ := exists_prime_dvd_of_not_inf_one ha0 hb0 hg exact hc hpa hpb hp theorem factors_self [Nontrivial α] {p : Associates α} (hp : Irreducible p) : p.factors = WithTop.some {⟨p, hp⟩} := eq_of_prod_eq_prod (by rw [factors_prod, FactorSet.prod]; dsimp; rw [prod_singleton]) theorem factors_prime_pow [Nontrivial α] {p : Associates α} (hp : Irreducible p) (k : ℕ) : factors (p ^ k) = WithTop.some (Multiset.replicate k ⟨p, hp⟩) := eq_of_prod_eq_prod (by rw [Associates.factors_prod, FactorSet.prod] dsimp; rw [Multiset.map_replicate, Multiset.prod_replicate, Subtype.coe_mk]) theorem prime_pow_le_iff_le_bcount [DecidableEq (Associates α)] {m p : Associates α} (h₁ : m ≠ 0) (h₂ : Irreducible p) {k : ℕ} : p ^ k ≤ m ↔ k ≤ bcount ⟨p, h₂⟩ m.factors := by rcases Associates.exists_non_zero_rep h₁ with ⟨m, hm, rfl⟩ have := nontrivial_of_ne _ _ hm rw [bcount, factors_mk, Multiset.le_count_iff_replicate_le, ← factors_le, factors_prime_pow, factors_mk, WithTop.coe_le_coe] <;> assumption @[simp] theorem factors_one [Nontrivial α] : factors (1 : Associates α) = 0 := by apply eq_of_prod_eq_prod rw [Associates.factors_prod] exact Multiset.prod_zero @[simp] theorem pow_factors [Nontrivial α] {a : Associates α} {k : ℕ} : (a ^ k).factors = k • a.factors := by induction' k with n h · rw [zero_nsmul, pow_zero] exact factors_one · rw [pow_succ, succ_nsmul, factors_mul, h] section count variable [DecidableEq (Associates α)] [∀ p : Associates α, Decidable (Irreducible p)] theorem prime_pow_dvd_iff_le {m p : Associates α} (h₁ : m ≠ 0) (h₂ : Irreducible p) {k : ℕ} : p ^ k ≤ m ↔ k ≤ count p m.factors := by rw [count, dif_pos h₂, prime_pow_le_iff_le_bcount h₁] theorem le_of_count_ne_zero {m p : Associates α} (h0 : m ≠ 0) (hp : Irreducible p) : count p m.factors ≠ 0 → p ≤ m := by nontriviality α rw [← pos_iff_ne_zero] intro h rw [← pow_one p] apply (prime_pow_dvd_iff_le h0 hp).2 simpa only theorem count_ne_zero_iff_dvd {a p : α} (ha0 : a ≠ 0) (hp : Irreducible p) : (Associates.mk p).count (Associates.mk a).factors ≠ 0 ↔ p ∣ a := by nontriviality α rw [← Associates.mk_le_mk_iff_dvd] refine ⟨fun h => Associates.le_of_count_ne_zero (Associates.mk_ne_zero.mpr ha0) (Associates.irreducible_mk.mpr hp) h, fun h => ?_⟩ rw [← pow_one (Associates.mk p), Associates.prime_pow_dvd_iff_le (Associates.mk_ne_zero.mpr ha0) (Associates.irreducible_mk.mpr hp)] at h exact (zero_lt_one.trans_le h).ne' theorem count_self [Nontrivial α] {p : Associates α} (hp : Irreducible p) : p.count p.factors = 1 := by simp [factors_self hp, Associates.count_some hp] theorem count_eq_zero_of_ne {p q : Associates α} (hp : Irreducible p) (hq : Irreducible q) (h : p ≠ q) : p.count q.factors = 0 := not_ne_iff.mp fun h' ↦ h <| associated_iff_eq.mp <| hp.associated_of_dvd hq <| le_of_count_ne_zero hq.ne_zero hp h' theorem count_mul {a : Associates α} (ha : a ≠ 0) {b : Associates α} (hb : b ≠ 0) {p : Associates α} (hp : Irreducible p) : count p (factors (a * b)) = count p a.factors + count p b.factors := by obtain ⟨a0, nza, rfl⟩ := exists_non_zero_rep ha obtain ⟨b0, nzb, rfl⟩ := exists_non_zero_rep hb rw [factors_mul, factors_mk a0 nza, factors_mk b0 nzb, ← FactorSet.coe_add, count_some hp, Multiset.count_add, count_some hp, count_some hp] theorem count_of_coprime {a : Associates α} (ha : a ≠ 0) {b : Associates α} (hb : b ≠ 0) (hab : ∀ d, d ∣ a → d ∣ b → ¬Prime d) {p : Associates α} (hp : Irreducible p) : count p a.factors = 0 ∨ count p b.factors = 0 := by rw [or_iff_not_imp_left, ← Ne] intro hca contrapose! hab with hcb exact ⟨p, le_of_count_ne_zero ha hp hca, le_of_count_ne_zero hb hp hcb, UniqueFactorizationMonoid.irreducible_iff_prime.mp hp⟩ theorem count_mul_of_coprime {a : Associates α} {b : Associates α} (hb : b ≠ 0) {p : Associates α} (hp : Irreducible p) (hab : ∀ d, d ∣ a → d ∣ b → ¬Prime d) : count p a.factors = 0 ∨ count p a.factors = count p (a * b).factors := by by_cases ha : a = 0 · simp [ha] cases' count_of_coprime ha hb hab hp with hz hb0; · tauto apply Or.intro_right rw [count_mul ha hb hp, hb0, add_zero] theorem count_mul_of_coprime' {a b : Associates α} {p : Associates α} (hp : Irreducible p) (hab : ∀ d, d ∣ a → d ∣ b → ¬Prime d) : count p (a * b).factors = count p a.factors ∨ count p (a * b).factors = count p b.factors := by by_cases ha : a = 0 · simp [ha] by_cases hb : b = 0 · simp [hb] rw [count_mul ha hb hp] cases' count_of_coprime ha hb hab hp with ha0 hb0 · apply Or.intro_right rw [ha0, zero_add] · apply Or.intro_left rw [hb0, add_zero] theorem dvd_count_of_dvd_count_mul {a b : Associates α} (hb : b ≠ 0) {p : Associates α} (hp : Irreducible p) (hab : ∀ d, d ∣ a → d ∣ b → ¬Prime d) {k : ℕ} (habk : k ∣ count p (a * b).factors) : k ∣ count p a.factors := by by_cases ha : a = 0 · simpa [*] using habk cases' count_of_coprime ha hb hab hp with hz h · rw [hz] exact dvd_zero k · rw [count_mul ha hb hp, h] at habk exact habk theorem count_pow [Nontrivial α] {a : Associates α} (ha : a ≠ 0) {p : Associates α} (hp : Irreducible p) (k : ℕ) : count p (a ^ k).factors = k * count p a.factors := by induction' k with n h · rw [pow_zero, factors_one, zero_mul, count_zero hp] · rw [pow_succ', count_mul ha (pow_ne_zero _ ha) hp, h] ring theorem dvd_count_pow [Nontrivial α] {a : Associates α} (ha : a ≠ 0) {p : Associates α} (hp : Irreducible p) (k : ℕ) : k ∣ count p (a ^ k).factors := by rw [count_pow ha hp] apply dvd_mul_right theorem is_pow_of_dvd_count {a : Associates α} (ha : a ≠ 0) {k : ℕ} (hk : ∀ p : Associates α, Irreducible p → k ∣ count p a.factors) : ∃ b : Associates α, a = b ^ k := by nontriviality α obtain ⟨a0, hz, rfl⟩ := exists_non_zero_rep ha rw [factors_mk a0 hz] at hk have hk' : ∀ p, p ∈ factors' a0 → k ∣ (factors' a0).count p := by rintro p - have pp : p = ⟨p.val, p.2⟩ := by simp only [Subtype.coe_eta] rw [pp, ← count_some p.2] exact hk p.val p.2 obtain ⟨u, hu⟩ := Multiset.exists_smul_of_dvd_count _ hk' use FactorSet.prod (u : FactorSet α) apply eq_of_factors_eq_factors rw [pow_factors, prod_factors, factors_mk a0 hz, hu] exact WithBot.coe_nsmul u k /-- The only divisors of prime powers are prime powers. See `eq_pow_find_of_dvd_irreducible_pow` for an explicit expression as a p-power (without using `count`). -/ theorem eq_pow_count_factors_of_dvd_pow {p a : Associates α} (hp : Irreducible p) {n : ℕ} (h : a ∣ p ^ n) : a = p ^ p.count a.factors := by nontriviality α have hph := pow_ne_zero n hp.ne_zero have ha := ne_zero_of_dvd_ne_zero hph h apply eq_of_eq_counts ha (pow_ne_zero _ hp.ne_zero) have eq_zero_of_ne : ∀ q : Associates α, Irreducible q → q ≠ p → _ = 0 := fun q hq h' => Nat.eq_zero_of_le_zero <| by convert count_le_count_of_le hph hq h symm rw [count_pow hp.ne_zero hq, count_eq_zero_of_ne hq hp h', mul_zero] intro q hq rw [count_pow hp.ne_zero hq] by_cases h : q = p · rw [h, count_self hp, mul_one] · rw [count_eq_zero_of_ne hq hp h, mul_zero, eq_zero_of_ne q hq h] theorem count_factors_eq_find_of_dvd_pow {a p : Associates α} (hp : Irreducible p) [∀ n : ℕ, Decidable (a ∣ p ^ n)] {n : ℕ} (h : a ∣ p ^ n) : @Nat.find (fun n => a ∣ p ^ n) _ ⟨n, h⟩ = p.count a.factors := by apply le_antisymm · refine Nat.find_le ⟨1, ?_⟩ rw [mul_one] symm exact eq_pow_count_factors_of_dvd_pow hp h · have hph := pow_ne_zero (@Nat.find (fun n => a ∣ p ^ n) _ ⟨n, h⟩) hp.ne_zero cases' subsingleton_or_nontrivial α with hα hα · simp [eq_iff_true_of_subsingleton] at hph convert count_le_count_of_le hph hp (@Nat.find_spec (fun n => a ∣ p ^ n) _ ⟨n, h⟩) rw [count_pow hp.ne_zero hp, count_self hp, mul_one] end count theorem eq_pow_of_mul_eq_pow {a b c : Associates α} (ha : a ≠ 0) (hb : b ≠ 0) (hab : ∀ d, d ∣ a → d ∣ b → ¬Prime d) {k : ℕ} (h : a * b = c ^ k) : ∃ d : Associates α, a = d ^ k := by classical nontriviality α by_cases hk0 : k = 0 · use 1 rw [hk0, pow_zero] at h ⊢ apply (mul_eq_one_iff.1 h).1 · refine is_pow_of_dvd_count ha fun p hp ↦ ?_ apply dvd_count_of_dvd_count_mul hb hp hab rw [h] apply dvd_count_pow _ hp rintro rfl rw [zero_pow hk0] at h cases mul_eq_zero.mp h <;> contradiction /-- The only divisors of prime powers are prime powers. -/ theorem eq_pow_find_of_dvd_irreducible_pow {a p : Associates α} (hp : Irreducible p) [∀ n : ℕ, Decidable (a ∣ p ^ n)] {n : ℕ} (h : a ∣ p ^ n) : a = p ^ @Nat.find (fun n => a ∣ p ^ n) _ ⟨n, h⟩ := by classical rw [count_factors_eq_find_of_dvd_pow hp, ← eq_pow_count_factors_of_dvd_pow hp h] exact h end Associates section open Associates UniqueFactorizationMonoid /-- `toGCDMonoid` constructs a GCD monoid out of a unique factorization domain. -/ noncomputable def UniqueFactorizationMonoid.toGCDMonoid (α : Type*) [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] : GCDMonoid α where gcd a b := Quot.out (Associates.mk a ⊓ Associates.mk b : Associates α) lcm a b := Quot.out (Associates.mk a ⊔ Associates.mk b : Associates α) gcd_dvd_left a b := by rw [← mk_dvd_mk, Associates.quot_out, congr_fun₂ dvd_eq_le] exact inf_le_left gcd_dvd_right a b := by rw [← mk_dvd_mk, Associates.quot_out, congr_fun₂ dvd_eq_le] exact inf_le_right dvd_gcd {a b c} hac hab := by rw [← mk_dvd_mk, Associates.quot_out, congr_fun₂ dvd_eq_le, le_inf_iff, mk_le_mk_iff_dvd, mk_le_mk_iff_dvd] exact ⟨hac, hab⟩ lcm_zero_left a := by simp lcm_zero_right a := by simp gcd_mul_lcm a b := by rw [← mk_eq_mk_iff_associated, ← Associates.mk_mul_mk, ← associated_iff_eq, Associates.quot_out, Associates.quot_out, mul_comm, sup_mul_inf, Associates.mk_mul_mk] /-- `toNormalizedGCDMonoid` constructs a GCD monoid out of a normalization on a unique factorization domain. -/ noncomputable def UniqueFactorizationMonoid.toNormalizedGCDMonoid (α : Type*) [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] [NormalizationMonoid α] : NormalizedGCDMonoid α := { ‹NormalizationMonoid α› with gcd := fun a b => (Associates.mk a ⊓ Associates.mk b).out lcm := fun a b => (Associates.mk a ⊔ Associates.mk b).out gcd_dvd_left := fun a b => (out_dvd_iff a (Associates.mk a ⊓ Associates.mk b)).2 <| inf_le_left gcd_dvd_right := fun a b => (out_dvd_iff b (Associates.mk a ⊓ Associates.mk b)).2 <| inf_le_right dvd_gcd := fun {a} {b} {c} hac hab => show a ∣ (Associates.mk c ⊓ Associates.mk b).out by rw [dvd_out_iff, le_inf_iff, mk_le_mk_iff_dvd, mk_le_mk_iff_dvd] exact ⟨hac, hab⟩ lcm_zero_left := fun a => show (⊤ ⊔ Associates.mk a).out = 0 by simp lcm_zero_right := fun a => show (Associates.mk a ⊔ ⊤).out = 0 by simp gcd_mul_lcm := fun a b => by rw [← out_mul, mul_comm, sup_mul_inf, mk_mul_mk, out_mk] exact normalize_associated (a * b) normalize_gcd := fun a b => by apply normalize_out _ normalize_lcm := fun a b => by apply normalize_out _ } instance (α) [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] : Nonempty (NormalizedGCDMonoid α) := by letI := UniqueFactorizationMonoid.normalizationMonoid (α := α) classical exact ⟨UniqueFactorizationMonoid.toNormalizedGCDMonoid α⟩ end namespace UniqueFactorizationMonoid /-- If `y` is a nonzero element of a unique factorization monoid with finitely many units (e.g. `ℤ`, `Ideal (ring_of_integers K)`), it has finitely many divisors. -/ noncomputable def fintypeSubtypeDvd {M : Type*} [CancelCommMonoidWithZero M] [UniqueFactorizationMonoid M] [Fintype Mˣ] (y : M) (hy : y ≠ 0) : Fintype { x // x ∣ y } := by haveI : Nontrivial M := ⟨⟨y, 0, hy⟩⟩ haveI : NormalizationMonoid M := UniqueFactorizationMonoid.normalizationMonoid haveI := Classical.decEq M haveI := Classical.decEq (Associates M) -- We'll show `λ (u : Mˣ) (f ⊆ factors y) → u * Π f` is injective -- and has image exactly the divisors of `y`. refine Fintype.ofFinset (((normalizedFactors y).powerset.toFinset ×ˢ (Finset.univ : Finset Mˣ)).image fun s => (s.snd : M) * s.fst.prod) fun x => ?_ simp only [exists_prop, Finset.mem_image, Finset.mem_product, Finset.mem_univ, and_true_iff, Multiset.mem_toFinset, Multiset.mem_powerset, exists_eq_right, Multiset.mem_map] constructor · rintro ⟨s, hs, rfl⟩ show (s.snd : M) * s.fst.prod ∣ y rw [(unit_associated_one.mul_right s.fst.prod).dvd_iff_dvd_left, one_mul, ← (normalizedFactors_prod hy).dvd_iff_dvd_right] exact Multiset.prod_dvd_prod_of_le hs · rintro (h : x ∣ y) have hx : x ≠ 0 := by refine mt (fun hx => ?_) hy rwa [hx, zero_dvd_iff] at h obtain ⟨u, hu⟩ := normalizedFactors_prod hx refine ⟨⟨normalizedFactors x, u⟩, ?_, (mul_comm _ _).trans hu⟩ exact (dvd_iff_normalizedFactors_le_normalizedFactors hx hy).mp h end UniqueFactorizationMonoid section Finsupp variable [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] variable [NormalizationMonoid α] [DecidableEq α] open UniqueFactorizationMonoid /-- This returns the multiset of irreducible factors as a `Finsupp`. -/ noncomputable def factorization (n : α) : α →₀ ℕ := Multiset.toFinsupp (normalizedFactors n) theorem factorization_eq_count {n p : α} : factorization n p = Multiset.count p (normalizedFactors n) := by simp [factorization] @[simp] theorem factorization_zero : factorization (0 : α) = 0 := by simp [factorization] @[simp] theorem factorization_one : factorization (1 : α) = 0 := by simp [factorization] /-- The support of `factorization n` is exactly the Finset of normalized factors -/ @[simp] theorem support_factorization {n : α} : (factorization n).support = (normalizedFactors n).toFinset := by simp [factorization, Multiset.toFinsupp_support] /-- For nonzero `a` and `b`, the power of `p` in `a * b` is the sum of the powers in `a` and `b` -/ @[simp] theorem factorization_mul {a b : α} (ha : a ≠ 0) (hb : b ≠ 0) : factorization (a * b) = factorization a + factorization b := by simp [factorization, normalizedFactors_mul ha hb] /-- For any `p`, the power of `p` in `x^n` is `n` times the power in `x` -/ theorem factorization_pow {x : α} {n : ℕ} : factorization (x ^ n) = n • factorization x := by ext simp [factorization] theorem associated_of_factorization_eq (a b : α) (ha : a ≠ 0) (hb : b ≠ 0) (h : factorization a = factorization b) : Associated a b := by simp_rw [factorization, AddEquiv.apply_eq_iff_eq] at h rwa [associated_iff_normalizedFactors_eq_normalizedFactors ha hb] end Finsupp open UniqueFactorizationMonoid in /-- Every non-zero prime ideal in a unique factorization domain contains a prime element. -/ theorem Ideal.IsPrime.exists_mem_prime_of_ne_bot {R : Type*} [CommSemiring R] [IsDomain R] [UniqueFactorizationMonoid R] {I : Ideal R} (hI₂ : I.IsPrime) (hI : I ≠ ⊥) : ∃ x ∈ I, Prime x := by classical obtain ⟨a : R, ha₁ : a ∈ I, ha₂ : a ≠ 0⟩ := Submodule.exists_mem_ne_zero_of_ne_bot hI replace ha₁ : (factors a).prod ∈ I := by obtain ⟨u : Rˣ, hu : (factors a).prod * u = a⟩ := factors_prod ha₂ rwa [← hu, mul_unit_mem_iff_mem _ u.isUnit] at ha₁ obtain ⟨p : R, hp₁ : p ∈ factors a, hp₂ : p ∈ I⟩ := (hI₂.multiset_prod_mem_iff_exists_mem <| factors a).1 ha₁ exact ⟨p, hp₂, prime_of_factor p hp₁⟩ namespace Nat instance instWfDvdMonoid : WfDvdMonoid ℕ where wellFounded_dvdNotUnit := by refine RelHomClass.wellFounded (⟨fun x : ℕ => if x = 0 then (⊤ : ℕ∞) else x, ?_⟩ : DvdNotUnit →r (· < ·)) wellFounded_lt intro a b h cases' a with a · exfalso revert h simp [DvdNotUnit] cases b · simpa [succ_ne_zero] using WithTop.coe_lt_top (a + 1) cases' dvd_and_not_dvd_iff.2 h with h1 h2 simp only [succ_ne_zero, cast_lt, if_false] refine lt_of_le_of_ne (Nat.le_of_dvd (Nat.succ_pos _) h1) fun con => h2 ?_ rw [con] instance instUniqueFactorizationMonoid : UniqueFactorizationMonoid ℕ where irreducible_iff_prime := Nat.irreducible_iff_prime open UniqueFactorizationMonoid lemma factors_eq : ∀ n : ℕ, normalizedFactors n = n.primeFactorsList | 0 => by simp | n + 1 => by rw [← Multiset.rel_eq, ← associated_eq_eq] apply UniqueFactorizationMonoid.factors_unique irreducible_of_normalized_factor _ · rw [Multiset.prod_coe, Nat.prod_primeFactorsList n.succ_ne_zero] exact normalizedFactors_prod n.succ_ne_zero · intro x hx rw [Nat.irreducible_iff_prime, ← Nat.prime_iff] exact Nat.prime_of_mem_primeFactorsList hx lemma factors_multiset_prod_of_irreducible {s : Multiset ℕ} (h : ∀ x : ℕ, x ∈ s → Irreducible x) : normalizedFactors s.prod = s := by rw [← Multiset.rel_eq, ← associated_eq_eq] apply UniqueFactorizationMonoid.factors_unique irreducible_of_normalized_factor h (normalizedFactors_prod _) rw [Ne, Multiset.prod_eq_zero_iff] exact fun con ↦ not_irreducible_zero (h 0 con) end Nat
RingTheory\ZMod.lean
/- Copyright (c) 2022 Alex J. Best. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alex J. Best -/ import Mathlib.Algebra.Squarefree.Basic import Mathlib.Algebra.EuclideanDomain.Int import Mathlib.Data.ZMod.Basic import Mathlib.RingTheory.PrincipalIdealDomain /-! # Ring theoretic facts about `ZMod n` We collect a few facts about `ZMod n` that need some ring theory to be proved/stated. ## Main statements * `ZMod.ker_intCastRingHom`: the ring homomorphism `ℤ → ZMod n` has kernel generated by `n`. * `ZMod.ringHom_eq_of_ker_eq`: two ring homomorphisms into `ZMod n` with equal kernels are equal. * `isReduced_zmod`: `ZMod n` is reduced for all squarefree `n`. -/ /-- The ring homomorphism `ℤ → ZMod n` has kernel generated by `n`. -/ theorem ZMod.ker_intCastRingHom (n : ℕ) : RingHom.ker (Int.castRingHom (ZMod n)) = Ideal.span ({(n : ℤ)} : Set ℤ) := by ext rw [Ideal.mem_span_singleton, RingHom.mem_ker, Int.coe_castRingHom, ZMod.intCast_zmod_eq_zero_iff_dvd] /-- Two ring homomorphisms into `ZMod n` with equal kernels are equal. -/ theorem ZMod.ringHom_eq_of_ker_eq {n : ℕ} {R : Type*} [CommRing R] (f g : R →+* ZMod n) (h : RingHom.ker f = RingHom.ker g) : f = g := by have := f.liftOfRightInverse_comp _ (ZMod.ringHom_rightInverse f) ⟨g, le_of_eq h⟩ rw [Subtype.coe_mk] at this rw [← this, RingHom.ext_zmod (f.liftOfRightInverse _ _ ⟨g, _⟩) _, RingHom.id_comp] /-- `ZMod n` is reduced iff `n` is square-free (or `n=0`). -/ @[simp] theorem isReduced_zmod {n : ℕ} : IsReduced (ZMod n) ↔ Squarefree n ∨ n = 0 := by rw [← RingHom.ker_isRadical_iff_reduced_of_surjective (ZMod.ringHom_surjective <| Int.castRingHom <| ZMod n), ZMod.ker_intCastRingHom, ← isRadical_iff_span_singleton, isRadical_iff_squarefree_or_zero, Int.squarefree_natCast, Nat.cast_eq_zero] instance {n : ℕ} [Fact <| Squarefree n] : IsReduced (ZMod n) := isReduced_zmod.2 <| Or.inl <| Fact.out
RingTheory\AdicCompletion\Algebra.lean
/- Copyright (c) 2024 Judith Ludwig, Christian Merten. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Judith Ludwig, Christian Merten -/ import Mathlib.RingTheory.AdicCompletion.Basic import Mathlib.Algebra.Module.Torsion /-! # Algebra instance on adic completion In this file we provide an algebra instance on the adic completion of a ring. Then the adic completion of any module is a module over the adic completion of the ring. ## Implementation details We do not make a separate adic completion type in algebra case, to not duplicate all module theoretic results on adic completions. This choice does cause some trouble though, since `I ^ n • ⊤` is not defeq to `I ^ n`. We try to work around most of the trouble by providing as much API as possible. -/ suppress_compilation open Submodule variable {R : Type*} [CommRing R] (I : Ideal R) variable {M : Type*} [AddCommGroup M] [Module R M] namespace AdicCompletion attribute [-simp] smul_eq_mul Algebra.id.smul_eq_mul @[local simp] theorem transitionMap_ideal_mk {m n : ℕ} (hmn : m ≤ n) (x : R) : transitionMap I R hmn (Ideal.Quotient.mk (I ^ n • ⊤ : Ideal R) x) = Ideal.Quotient.mk (I ^ m • ⊤ : Ideal R) x := rfl @[local simp] theorem transitionMap_map_one {m n : ℕ} (hmn : m ≤ n) : transitionMap I R hmn 1 = 1 := rfl @[local simp] theorem transitionMap_map_mul {m n : ℕ} (hmn : m ≤ n) (x y : R ⧸ (I ^ n • ⊤ : Ideal R)) : transitionMap I R hmn (x * y) = transitionMap I R hmn x * transitionMap I R hmn y := Quotient.inductionOn₂' x y (fun _ _ ↦ rfl) @[local simp] theorem transitionMap_map_pow {m n a : ℕ} (hmn : m ≤ n) (x : R ⧸ (I ^ n • ⊤ : Ideal R)) : transitionMap I R hmn (x ^ a) = transitionMap I R hmn x ^ a := Quotient.inductionOn' x (fun _ ↦ rfl) /-- `AdicCompletion.transitionMap` as an algebra homomorphism. -/ def transitionMapₐ {m n : ℕ} (hmn : m ≤ n) : R ⧸ (I ^ n • ⊤ : Ideal R) →ₐ[R] R ⧸ (I ^ m • ⊤ : Ideal R) := AlgHom.ofLinearMap (transitionMap I R hmn) rfl (transitionMap_map_mul I hmn) /-- `AdicCompletion I R` is an `R`-subalgebra of `∀ n, R ⧸ (I ^ n • ⊤ : Ideal R)`. -/ def subalgebra : Subalgebra R (∀ n, R ⧸ (I ^ n • ⊤ : Ideal R)) := Submodule.toSubalgebra (submodule I R) (fun _ ↦ by simp) (fun x y hx hy m n hmn ↦ by simp [hx hmn, hy hmn]) /-- `AdicCompletion I R` is a subring of `∀ n, R ⧸ (I ^ n • ⊤ : Ideal R)`. -/ def subring : Subring (∀ n, R ⧸ (I ^ n • ⊤ : Ideal R)) := Subalgebra.toSubring (subalgebra I) instance : Mul (AdicCompletion I R) where mul x y := ⟨x.val * y.val, by simp [x.property, y.property]⟩ instance : One (AdicCompletion I R) where one := ⟨1, by simp⟩ instance : NatCast (AdicCompletion I R) where natCast n := ⟨n, fun _ ↦ rfl⟩ instance : IntCast (AdicCompletion I R) where intCast n := ⟨n, fun _ ↦ rfl⟩ instance : Pow (AdicCompletion I R) ℕ where pow x n := ⟨x.val ^ n, fun _ ↦ by simp [x.property]⟩ instance : CommRing (AdicCompletion I R) := let f : AdicCompletion I R → ∀ n, R ⧸ (I ^ n • ⊤ : Ideal R) := Subtype.val Subtype.val_injective.commRing f rfl rfl (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ ↦ rfl) instance : Algebra R (AdicCompletion I R) where toFun r := ⟨algebraMap R (∀ n, R ⧸ (I ^ n • ⊤ : Ideal R)) r, by simp⟩ map_one' := Subtype.ext <| map_one _ map_mul' x y := Subtype.ext <| map_mul _ x y map_zero' := Subtype.ext <| map_zero _ map_add' x y := Subtype.ext <| map_add _ x y commutes' r x := Subtype.ext <| Algebra.commutes' r x.val smul_def' r x := Subtype.ext <| Algebra.smul_def' r x.val @[simp] theorem val_one (n : ℕ) : (1 : AdicCompletion I R).val n = 1 := rfl @[simp] theorem val_mul (n : ℕ) (x y : AdicCompletion I R) : (x * y).val n = x.val n * y.val n := rfl /-- The canonical algebra map from the adic completion to `R ⧸ I ^ n`. This is `AdicCompletion.eval` postcomposed with the algebra isomorphism `R ⧸ (I ^ n • ⊤) ≃ₐ[R] R ⧸ I ^ n`. -/ def evalₐ (n : ℕ) : AdicCompletion I R →ₐ[R] R ⧸ I ^ n := have h : (I ^ n • ⊤ : Ideal R) = I ^ n := by ext x; simp AlgHom.comp (Ideal.quotientEquivAlgOfEq R h) (AlgHom.ofLinearMap (eval I R n) rfl (fun _ _ ↦ rfl)) @[simp] theorem evalₐ_mk (n : ℕ) (x : AdicCauchySequence I R) : evalₐ I n (mk I R x) = Ideal.Quotient.mk (I ^ n) (x.val n) := by simp [evalₐ] /-- `AdicCauchySequence I R` is an `R`-subalgebra of `ℕ → R`. -/ def AdicCauchySequence.subalgebra : Subalgebra R (ℕ → R) := Submodule.toSubalgebra (AdicCauchySequence.submodule I R) (fun {m n} _ ↦ by simp; rfl) (fun x y hx hy {m n} hmn ↦ by simp only [Pi.mul_apply] exact SModEq.mul (hx hmn) (hy hmn)) /-- `AdicCauchySequence I R` is a subring of `ℕ → R`. -/ def AdicCauchySequence.subring : Subring (ℕ → R) := Subalgebra.toSubring (AdicCauchySequence.subalgebra I) instance : Mul (AdicCauchySequence I R) where mul x y := ⟨x.val * y.val, fun hmn ↦ SModEq.mul (x.property hmn) (y.property hmn)⟩ instance : One (AdicCauchySequence I R) where one := ⟨1, fun _ ↦ rfl⟩ instance : NatCast (AdicCauchySequence I R) where natCast n := ⟨n, fun _ ↦ rfl⟩ instance : IntCast (AdicCauchySequence I R) where intCast n := ⟨n, fun _ ↦ rfl⟩ instance : Pow (AdicCauchySequence I R) ℕ where pow x n := ⟨x.val ^ n, fun hmn ↦ SModEq.pow n (x.property hmn)⟩ instance : CommRing (AdicCauchySequence I R) := let f : AdicCauchySequence I R → (ℕ → R) := Subtype.val Subtype.val_injective.commRing f rfl rfl (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ ↦ rfl) instance : Algebra R (AdicCauchySequence I R) where toFun r := ⟨algebraMap R (∀ _, R) r, fun _ ↦ rfl⟩ map_one' := Subtype.ext <| map_one _ map_mul' x y := Subtype.ext <| map_mul _ x y map_zero' := Subtype.ext <| map_zero _ map_add' x y := Subtype.ext <| map_add _ x y commutes' r x := Subtype.ext <| Algebra.commutes' r x.val smul_def' r x := Subtype.ext <| Algebra.smul_def' r x.val @[simp] theorem one_apply (n : ℕ) : (1 : AdicCauchySequence I R) n = 1 := rfl @[simp] theorem mul_apply (n : ℕ) (f g : AdicCauchySequence I R) : (f * g) n = f n * g n := rfl /-- The canonical algebra map from adic cauchy sequences to the adic completion. -/ @[simps!] def mkₐ : AdicCauchySequence I R →ₐ[R] AdicCompletion I R := AlgHom.ofLinearMap (mk I R) rfl (fun _ _ ↦ rfl) @[simp] theorem evalₐ_mkₐ (n : ℕ) (x : AdicCauchySequence I R) : evalₐ I n (mkₐ I x) = Ideal.Quotient.mk (I ^ n) (x.val n) := by simp [mkₐ] theorem Ideal.mk_eq_mk {m n : ℕ} (hmn : m ≤ n) (r : AdicCauchySequence I R) : Ideal.Quotient.mk (I ^ m) (r.val n) = Ideal.Quotient.mk (I ^ m) (r.val m) := by have h : I ^ m = I ^ m • ⊤ := by simp rw [h, ← Ideal.Quotient.mk_eq_mk, ← Ideal.Quotient.mk_eq_mk] exact (r.property hmn).symm theorem smul_mk {m n : ℕ} (hmn : m ≤ n) (r : AdicCauchySequence I R) (x : AdicCauchySequence I M) : r.val n • Submodule.Quotient.mk (p := (I ^ m • ⊤ : Submodule R M)) (x.val n) = r.val m • Submodule.Quotient.mk (p := (I ^ m • ⊤ : Submodule R M)) (x.val m) := by rw [← Submodule.Quotient.mk_smul, ← Module.Quotient.mk_smul_mk, AdicCauchySequence.mk_eq_mk hmn, Ideal.mk_eq_mk I hmn, Module.Quotient.mk_smul_mk, Submodule.Quotient.mk_smul] /-- Scalar multiplication of `R ⧸ (I • ⊤)` on `M ⧸ (I • ⊤)`. This is used in order to have good definitional behaviour for the module instance on adic completions -/ instance : SMul (R ⧸ (I • ⊤ : Ideal R)) (M ⧸ (I • ⊤ : Submodule R M)) where smul r x := Quotient.liftOn r (· • x) fun b₁ b₂ (h : Setoid.Rel _ b₁ b₂) ↦ by refine Quotient.inductionOn' x (fun x ↦ ?_) have h : b₁ - b₂ ∈ (I : Submodule R R) := by rwa [show I = I • ⊤ by simp, ← Submodule.quotientRel_r_def] rw [← sub_eq_zero, ← sub_smul, Submodule.Quotient.mk''_eq_mk, ← Submodule.Quotient.mk_smul, Submodule.Quotient.mk_eq_zero] exact Submodule.smul_mem_smul h mem_top @[local simp] theorem mk_smul_mk (r : R) (x : M) : Ideal.Quotient.mk (I • ⊤) r • Submodule.Quotient.mk (p := (I • ⊤ : Submodule R M)) x = r • Submodule.Quotient.mk (p := (I • ⊤ : Submodule R M)) x := rfl theorem val_smul_eq_evalₐ_smul (n : ℕ) (r : AdicCompletion I R) (x : M ⧸ (I ^ n • ⊤ : Submodule R M)) : r.val n • x = evalₐ I n r • x := by apply induction_on I R r (fun r ↦ ?_) exact Quotient.inductionOn' x (fun x ↦ rfl) instance : Module (R ⧸ (I • ⊤ : Ideal R)) (M ⧸ (I • ⊤ : Submodule R M)) := Function.Surjective.moduleLeft (Ideal.Quotient.mk (I • ⊤ : Ideal R)) Ideal.Quotient.mk_surjective (fun _ _ ↦ rfl) instance : IsScalarTower R (R ⧸ (I • ⊤ : Ideal R)) (M ⧸ (I • ⊤ : Submodule R M)) where smul_assoc r s x := by refine Quotient.inductionOn' s (fun s ↦ ?_) refine Quotient.inductionOn' x (fun x ↦ ?_) simp only [Submodule.Quotient.mk''_eq_mk] rw [← Submodule.Quotient.mk_smul, Ideal.Quotient.mk_eq_mk, mk_smul_mk, smul_assoc] rfl instance smul : SMul (AdicCompletion I R) (AdicCompletion I M) where smul r x := { val := fun n ↦ eval I R n r • eval I M n x property := fun {m n} hmn ↦ by apply induction_on I R r (fun r ↦ ?_) apply induction_on I M x (fun x ↦ ?_) simp only [coe_eval, mk_apply_coe, mkQ_apply, Ideal.Quotient.mk_eq_mk, mk_smul_mk, LinearMapClass.map_smul, transitionMap_mk] rw [smul_mk I hmn] } @[simp] theorem smul_eval (n : ℕ) (r : AdicCompletion I R) (x : AdicCompletion I M) : (r • x).val n = r.val n • x.val n := rfl /-- `AdicCompletion I M` is naturally an `AdicCompletion I R` module. -/ instance module : Module (AdicCompletion I R) (AdicCompletion I M) where one_smul b := by ext n simp only [smul_eval, val_one, one_smul] mul_smul r s x := by ext n simp only [smul_eval, val_mul, mul_smul] smul_zero r := by ext n rw [smul_eval, val_zero, smul_zero] smul_add r x y := by ext n simp only [smul_eval, val_add, smul_add] add_smul r s x := by ext n simp only [coe_eval, smul_eval, map_add, add_smul, val_add] zero_smul x := by ext n simp only [smul_eval, _root_.map_zero, zero_smul, val_zero] instance : IsScalarTower R (AdicCompletion I R) (AdicCompletion I M) where smul_assoc r s x := by ext n rw [smul_eval, val_smul, val_smul, smul_eval, smul_assoc] /-- A priori `AdicCompletion I R` has two `AdicCompletion I R`-module instances. Both agree definitionally. -/ example : module I = @Algebra.toModule (AdicCompletion I R) (AdicCompletion I R) _ _ (Algebra.id _) := by with_reducible_and_instances rfl end AdicCompletion
RingTheory\AdicCompletion\AsTensorProduct.lean
/- Copyright (c) 2024 Judith Ludwig, Christian Merten. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Judith Ludwig, Christian Merten -/ import Mathlib.Algebra.Homology.ShortComplex.ModuleCat import Mathlib.CategoryTheory.Abelian.DiagramLemmas.Four import Mathlib.LinearAlgebra.TensorProduct.Pi import Mathlib.LinearAlgebra.TensorProduct.RightExactness import Mathlib.RingTheory.AdicCompletion.Exactness import Mathlib.RingTheory.Flat.Algebra /-! # Adic completion as tensor product In this file we examine properties of the natural map `AdicCompletion I R ⊗[R] M →ₗ[AdicCompletion I R] AdicCompletion I M`. We show (in the `AdicCompletion` namespace): - `ofTensorProduct_bijective_of_pi_of_fintype`: it is an isomorphism if `M = R^n`. - `ofTensorProduct_surjective_of_finite`: it is surjective, if `M` is a finite `R`-module. - `ofTensorProduct_bijective_of_finite_of_isNoetherian`: it is an isomorphism if `R` is Noetherian and `M` is a finite `R`-module. As a corollary we obtain - `flat_of_isNoetherian`: the adic completion of a Noetherian ring `R` is `R`-flat. ## TODO - Show that `ofTensorProduct` is an isomorphism for any finite free `R`-module over an arbitrary ring. This is mostly composing with the isomorphism to `R^n` and checking that a diagram commutes. -/ suppress_compilation universe u v variable {R : Type*} [CommRing R] (I : Ideal R) variable (M : Type*) [AddCommGroup M] [Module R M] variable {N : Type*} [AddCommGroup N] [Module R N] open TensorProduct namespace AdicCompletion private def ofTensorProductBil : AdicCompletion I R →ₗ[AdicCompletion I R] M →ₗ[R] AdicCompletion I M where toFun r := LinearMap.lsmul (AdicCompletion I R) (AdicCompletion I M) r ∘ₗ of I M map_add' x y := by apply LinearMap.ext simp map_smul' r x := by apply LinearMap.ext intro y ext n simp [mul_smul (r.val n)] @[simp] private lemma ofTensorProductBil_apply_apply (r : AdicCompletion I R) (x : M) : ((AdicCompletion.ofTensorProductBil I M) r) x = r • (of I M) x := rfl /-- The natural `AdicCompletion I R`-linear map from `AdicCompletion I R ⊗[R] M` to the adic completion of `M`. -/ def ofTensorProduct : AdicCompletion I R ⊗[R] M →ₗ[AdicCompletion I R] AdicCompletion I M := TensorProduct.AlgebraTensorModule.lift (ofTensorProductBil I M) @[simp] lemma ofTensorProduct_tmul (r : AdicCompletion I R) (x : M) : ofTensorProduct I M (r ⊗ₜ x) = r • of I M x := by simp [ofTensorProduct] variable {M} in /-- `ofTensorProduct` is functorial in `M`. -/ lemma ofTensorProduct_naturality (f : M →ₗ[R] N) : map I f ∘ₗ ofTensorProduct I M = ofTensorProduct I N ∘ₗ AlgebraTensorModule.map LinearMap.id f := by ext simp section PiFintype /- In this section we show that `ofTensorProduct` is an isomorphism if `M = R^n`. -/ variable (ι : Type*) section DecidableEq variable [Fintype ι] [DecidableEq ι] private lemma piEquivOfFintype_comp_ofTensorProduct_eq : piEquivOfFintype I (fun _ : ι ↦ R) ∘ₗ ofTensorProduct I (ι → R) = (TensorProduct.piScalarRight R (AdicCompletion I R) (AdicCompletion I R) ι).toLinearMap := by ext i j k suffices h : (if j = i then 1 else 0) = (if j = i then 1 else 0 : AdicCompletion I R).val k by simpa [Pi.single_apply, -smul_eq_mul, -Algebra.id.smul_eq_mul] split <;> simp only [smul_eq_mul, val_zero, val_one] private lemma ofTensorProduct_eq : ofTensorProduct I (ι → R) = (piEquivOfFintype I (ι := ι) (fun _ : ι ↦ R)).symm.toLinearMap ∘ₗ (TensorProduct.piScalarRight R (AdicCompletion I R) (AdicCompletion I R) ι).toLinearMap := by rw [← piEquivOfFintype_comp_ofTensorProduct_eq I ι, ← LinearMap.comp_assoc] simp /- If `M = R^ι` and `ι` is finite, we may construct an inverse to `ofTensorProduct I (ι → R)`. -/ private def ofTensorProductInvOfPiFintype : AdicCompletion I (ι → R) ≃ₗ[AdicCompletion I R] AdicCompletion I R ⊗[R] (ι → R) := letI f := piEquivOfFintype I (fun _ : ι ↦ R) letI g := (TensorProduct.piScalarRight R (AdicCompletion I R) (AdicCompletion I R) ι).symm f.trans g private lemma ofTensorProductInvOfPiFintype_comp_ofTensorProduct : ofTensorProductInvOfPiFintype I ι ∘ₗ ofTensorProduct I (ι → R) = LinearMap.id := by dsimp only [ofTensorProductInvOfPiFintype] rw [LinearEquiv.coe_trans, LinearMap.comp_assoc, piEquivOfFintype_comp_ofTensorProduct_eq] simp private lemma ofTensorProduct_comp_ofTensorProductInvOfPiFintype : ofTensorProduct I (ι → R) ∘ₗ ofTensorProductInvOfPiFintype I ι = LinearMap.id := by dsimp only [ofTensorProductInvOfPiFintype] rw [LinearEquiv.coe_trans, ofTensorProduct_eq, LinearMap.comp_assoc] nth_rw 2 [← LinearMap.comp_assoc] simp /-- `ofTensorProduct` as an equiv in the case of `M = R^ι` where `ι` is finite. -/ def ofTensorProductEquivOfPiFintype : AdicCompletion I R ⊗[R] (ι → R) ≃ₗ[AdicCompletion I R] AdicCompletion I (ι → R) := LinearEquiv.ofLinear (ofTensorProduct I (ι → R)) (ofTensorProductInvOfPiFintype I ι) (ofTensorProduct_comp_ofTensorProductInvOfPiFintype I ι) (ofTensorProductInvOfPiFintype_comp_ofTensorProduct I ι) end DecidableEq /-- If `M = R^ι`, `ofTensorProduct` is bijective. -/ lemma ofTensorProduct_bijective_of_pi_of_fintype [Finite ι] : Function.Bijective (ofTensorProduct I (ι → R)) := by classical cases nonempty_fintype ι exact EquivLike.bijective (ofTensorProductEquivOfPiFintype I ι) end PiFintype /-- If `M` is a finite `R`-module, then the canonical map `AdicCompletion I R ⊗[R] M →ₗ AdicCompletion I M` is surjective. -/ lemma ofTensorProduct_surjective_of_finite [Module.Finite R M] : Function.Surjective (ofTensorProduct I M) := by obtain ⟨n, p, hp⟩ := Module.Finite.exists_fin' R M let f := ofTensorProduct I M ∘ₗ p.baseChange (AdicCompletion I R) let g := map I p ∘ₗ ofTensorProduct I (Fin n → R) have hfg : f = g := by ext simp [f, g] have hf : Function.Surjective f := by simp only [hfg, LinearMap.coe_comp, g] apply Function.Surjective.comp · exact AdicCompletion.map_surjective I hp · exact (ofTensorProduct_bijective_of_pi_of_fintype I (Fin n)).surjective exact Function.Surjective.of_comp hf section Noetherian variable {R : Type u} [CommRing R] (I : Ideal R) variable (M : Type u) [AddCommGroup M] [Module R M] variable [IsNoetherianRing R] /-! ### Noetherian case Suppose `R` is Noetherian. Then we show that the canonical map `AdicCompletion I R ⊗[R] M →ₗ[AdicCompletion I R] AdicCompletion I M` is an isomorphism for every finite `R`-module `M`. The strategy is the following: Choose a surjection `f : (ι → R) →ₗ[R] M` and consider the following commutative diagram: ``` AdicCompletion I R ⊗[R] ker f -→ AdicCompletion I R ⊗[R] (ι → R) -→ AdicCompletion I R ⊗[R] M -→ 0 | | | | ↓ ↓ ↓ ↓ AdicCompletion I (ker f) ------→ AdicCompletion I (ι → R) -------→ AdicCompletion I M ------→ 0 ``` The vertical maps are given by `ofTensorProduct`. By the previous section we know that the second vertical map is an isomorphism. Since `R` is Noetherian, `ker f` is finitely-generated, so again by the previous section the first vertical map is surjective. Moreover, both rows are exact by right-exactness of the tensor product and exactness of adic completions over Noetherian rings. Hence we conclude by the 5-lemma. -/ open CategoryTheory section variable {ι : Type} [Fintype ι] [DecidableEq ι] (f : (ι → R) →ₗ[R] M) (hf : Function.Surjective f) /- The first horizontal arrow in the top row. -/ private def lTensorKerIncl : AdicCompletion I R ⊗[R] LinearMap.ker f →ₗ[AdicCompletion I R] AdicCompletion I R ⊗[R] (ι → R) := AlgebraTensorModule.map LinearMap.id (LinearMap.ker f).subtype /- The second horizontal arrow in the top row. -/ private def lTensorf : AdicCompletion I R ⊗[R] (ι → R) →ₗ[AdicCompletion I R] AdicCompletion I R ⊗[R] M := AlgebraTensorModule.map LinearMap.id f private lemma if_exact : Function.Exact (LinearMap.ker f).subtype f := fun x ↦ ⟨fun hx ↦ ⟨⟨x, hx⟩, rfl⟩, by rintro ⟨x, rfl⟩; exact x.property⟩ private lemma tens_exact : Function.Exact (lTensorKerIncl I M f) (lTensorf I M f) := lTensor_exact (AdicCompletion I R) (if_exact M f) hf private lemma tens_surj : Function.Surjective (lTensorf I M f) := LinearMap.lTensor_surjective (AdicCompletion I R) hf private lemma adic_exact : Function.Exact (map I (LinearMap.ker f).subtype) (map I f) := map_exact (Submodule.injective_subtype _) (if_exact M f) hf private lemma adic_surj : Function.Surjective (map I f) := map_surjective I hf /- Instance to speed up instance inference. -/ private instance : AddCommGroup (AdicCompletion I R ⊗[R] (LinearMap.ker f)) := inferInstance private def firstRow : ComposableArrows (ModuleCat (AdicCompletion I R)) 4 := ComposableArrows.mk₄ (ModuleCat.ofHom <| lTensorKerIncl I M f) (ModuleCat.ofHom <| lTensorf I M f) (ModuleCat.ofHom (0 : AdicCompletion I R ⊗[R] M →ₗ[AdicCompletion I R] PUnit)) (ModuleCat.ofHom (0 : _ →ₗ[AdicCompletion I R] PUnit)) private def secondRow : ComposableArrows (ModuleCat (AdicCompletion I R)) 4 := ComposableArrows.mk₄ (ModuleCat.ofHom (map I <| (LinearMap.ker f).subtype)) (ModuleCat.ofHom (map I f)) (ModuleCat.ofHom (0 : _ →ₗ[AdicCompletion I R] PUnit)) (ModuleCat.ofHom (0 : _ →ₗ[AdicCompletion I R] PUnit)) private lemma firstRow_exact : (firstRow I M f).Exact where zero k _ := match k with | 0 => (tens_exact I M f hf).linearMap_comp_eq_zero | 1 => LinearMap.zero_comp _ | 2 => LinearMap.zero_comp 0 exact k _ := by rw [ShortComplex.moduleCat_exact_iff] match k with | 0 => intro x hx; exact (tens_exact I M f hf x).mp hx | 1 => intro x _; exact (tens_surj I M f hf) x | 2 => intro _ _; exact ⟨0, rfl⟩ private lemma secondRow_exact : (secondRow I M f).Exact where zero k _ := match k with | 0 => (adic_exact I M f hf).linearMap_comp_eq_zero | 1 => LinearMap.zero_comp (map I f) | 2 => LinearMap.zero_comp 0 exact k _ := by rw [ShortComplex.moduleCat_exact_iff] match k with | 0 => intro x hx; exact (adic_exact I M f hf x).mp hx | 1 => intro x _; exact (adic_surj I M f hf) x | 2 => intro _ _; exact ⟨0, rfl⟩ /- The compatible vertical maps between the first and the second row. -/ private def firstRowToSecondRow : firstRow I M f ⟶ secondRow I M f := ComposableArrows.homMk₄ (ModuleCat.ofHom (ofTensorProduct I (LinearMap.ker f))) (ModuleCat.ofHom (ofTensorProduct I (ι → R))) (ModuleCat.ofHom (ofTensorProduct I M)) (ModuleCat.ofHom 0) (ModuleCat.ofHom 0) (ofTensorProduct_naturality I <| (LinearMap.ker f).subtype).symm (ofTensorProduct_naturality I f).symm rfl rfl private lemma ofTensorProduct_iso : IsIso (ModuleCat.ofHom (ofTensorProduct I M)) := by refine Abelian.isIso_of_epi_of_isIso_of_isIso_of_mono (firstRow_exact I M f hf) (secondRow_exact I M f hf) (firstRowToSecondRow I M f) ?_ ?_ ?_ ?_ · apply ConcreteCategory.epi_of_surjective exact ofTensorProduct_surjective_of_finite I (LinearMap.ker f) · apply (ConcreteCategory.isIso_iff_bijective _).mpr exact ofTensorProduct_bijective_of_pi_of_fintype I ι · show IsIso (ModuleCat.ofHom 0) apply Limits.isIso_of_isTerminal <;> exact Limits.IsZero.isTerminal (ModuleCat.isZero_of_subsingleton _) · apply ConcreteCategory.mono_of_injective intro x y _ rfl private lemma ofTensorProduct_bijective_of_map_from_fin : Function.Bijective (ofTensorProduct I M) := by have : IsIso (ModuleCat.ofHom (ofTensorProduct I M)) := ofTensorProduct_iso I M f hf exact ConcreteCategory.bijective_of_isIso (ModuleCat.ofHom (ofTensorProduct I M)) end /-- If `R` is a Noetherian ring and `M` is a finite `R`-module, then the natural map given by `AdicCompletion.ofTensorProduct` is an isomorphism. -/ theorem ofTensorProduct_bijective_of_finite_of_isNoetherian [Module.Finite R M] : Function.Bijective (ofTensorProduct I M) := by obtain ⟨n, f, hf⟩ := Module.Finite.exists_fin' R M exact ofTensorProduct_bijective_of_map_from_fin I M f hf /-- `ofTensorProduct` packaged as linear equiv if `M` is a finite `R`-module and `R` is Noetherian. -/ def ofTensorProductEquivOfFiniteNoetherian [Module.Finite R M] : AdicCompletion I R ⊗[R] M ≃ₗ[AdicCompletion I R] AdicCompletion I M := LinearEquiv.ofBijective (ofTensorProduct I M) (ofTensorProduct_bijective_of_finite_of_isNoetherian I M) @[simp] lemma ofTensorProductEquivOfFiniteNoetherian_apply [Module.Finite R M] (x : AdicCompletion I R ⊗[R] M) : ofTensorProductEquivOfFiniteNoetherian I M x = ofTensorProduct I M x := rfl @[simp] lemma ofTensorProductEquivOfFiniteNoetherian_symm_of [Module.Finite R M] (x : M) : (ofTensorProductEquivOfFiniteNoetherian I M).symm ((of I M) x) = 1 ⊗ₜ x := by have h : (of I M) x = ofTensorProductEquivOfFiniteNoetherian I M (1 ⊗ₜ x) := by simp rw [h, LinearEquiv.symm_apply_apply] section variable {M : Type u} [AddCommGroup M] [Module R M] variable {N : Type u} [AddCommGroup N] [Module R N] (f : M →ₗ[R] N) variable [Module.Finite R M] [Module.Finite R N] lemma tensor_map_id_left_eq_map : (AlgebraTensorModule.map LinearMap.id f) = (ofTensorProductEquivOfFiniteNoetherian I N).symm.toLinearMap ∘ₗ map I f ∘ₗ (ofTensorProductEquivOfFiniteNoetherian I M).toLinearMap := by erw [ofTensorProduct_naturality I f] ext x simp variable {f} lemma tensor_map_id_left_injective_of_injective (hf : Function.Injective f) : Function.Injective (AlgebraTensorModule.map LinearMap.id f : AdicCompletion I R ⊗[R] M →ₗ[AdicCompletion I R] AdicCompletion I R ⊗[R] N) := by rw [tensor_map_id_left_eq_map I f] simp only [LinearMap.coe_comp, LinearEquiv.coe_coe, EmbeddingLike.comp_injective, EquivLike.injective_comp] exact map_injective I hf end /-- Adic completion of a Noetherian ring `R` is flat over `R`. -/ instance flat_of_isNoetherian [IsNoetherianRing R] : Algebra.Flat R (AdicCompletion I R) where out := (Module.Flat.iff_lTensor_injective' R (AdicCompletion I R)).mpr <| fun J ↦ tensor_map_id_left_injective_of_injective I (Submodule.injective_subtype J) end Noetherian end AdicCompletion
RingTheory\AdicCompletion\Basic.lean
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Judith Ludwig, Christian Merten -/ import Mathlib.Algebra.GeomSum import Mathlib.LinearAlgebra.SModEq import Mathlib.RingTheory.JacobsonIdeal /-! # Completion of a module with respect to an ideal. In this file we define the notions of Hausdorff, precomplete, and complete for an `R`-module `M` with respect to an ideal `I`: ## Main definitions - `IsHausdorff I M`: this says that the intersection of `I^n M` is `0`. - `IsPrecomplete I M`: this says that every Cauchy sequence converges. - `IsAdicComplete I M`: this says that `M` is Hausdorff and precomplete. - `Hausdorffification I M`: this is the universal Hausdorff module with a map from `M`. - `AdicCompletion I M`: if `I` is finitely generated, then this is the universal complete module (TODO) with a map from `M`. This map is injective iff `M` is Hausdorff and surjective iff `M` is precomplete. -/ suppress_compilation open Submodule variable {R : Type*} [CommRing R] (I : Ideal R) variable (M : Type*) [AddCommGroup M] [Module R M] variable {N : Type*} [AddCommGroup N] [Module R N] /-- A module `M` is Hausdorff with respect to an ideal `I` if `⋂ I^n M = 0`. -/ class IsHausdorff : Prop where haus' : ∀ x : M, (∀ n : ℕ, x ≡ 0 [SMOD (I ^ n • ⊤ : Submodule R M)]) → x = 0 /-- A module `M` is precomplete with respect to an ideal `I` if every Cauchy sequence converges. -/ class IsPrecomplete : Prop where prec' : ∀ f : ℕ → M, (∀ {m n}, m ≤ n → f m ≡ f n [SMOD (I ^ m • ⊤ : Submodule R M)]) → ∃ L : M, ∀ n, f n ≡ L [SMOD (I ^ n • ⊤ : Submodule R M)] /-- A module `M` is `I`-adically complete if it is Hausdorff and precomplete. -/ class IsAdicComplete extends IsHausdorff I M, IsPrecomplete I M : Prop variable {I M} theorem IsHausdorff.haus (_ : IsHausdorff I M) : ∀ x : M, (∀ n : ℕ, x ≡ 0 [SMOD (I ^ n • ⊤ : Submodule R M)]) → x = 0 := IsHausdorff.haus' theorem isHausdorff_iff : IsHausdorff I M ↔ ∀ x : M, (∀ n : ℕ, x ≡ 0 [SMOD (I ^ n • ⊤ : Submodule R M)]) → x = 0 := ⟨IsHausdorff.haus, fun h => ⟨h⟩⟩ theorem IsPrecomplete.prec (_ : IsPrecomplete I M) {f : ℕ → M} : (∀ {m n}, m ≤ n → f m ≡ f n [SMOD (I ^ m • ⊤ : Submodule R M)]) → ∃ L : M, ∀ n, f n ≡ L [SMOD (I ^ n • ⊤ : Submodule R M)] := IsPrecomplete.prec' _ theorem isPrecomplete_iff : IsPrecomplete I M ↔ ∀ f : ℕ → M, (∀ {m n}, m ≤ n → f m ≡ f n [SMOD (I ^ m • ⊤ : Submodule R M)]) → ∃ L : M, ∀ n, f n ≡ L [SMOD (I ^ n • ⊤ : Submodule R M)] := ⟨fun h => h.1, fun h => ⟨h⟩⟩ variable (I M) /-- The Hausdorffification of a module with respect to an ideal. -/ abbrev Hausdorffification : Type _ := M ⧸ (⨅ n : ℕ, I ^ n • ⊤ : Submodule R M) /-- The canonical linear map `M ⧸ (I ^ n • ⊤) →ₗ[R] M ⧸ (I ^ m • ⊤)` for `m ≤ n` used to define `AdicCompletion`. -/ def AdicCompletion.transitionMap {m n : ℕ} (hmn : m ≤ n) : M ⧸ (I ^ n • ⊤ : Submodule R M) →ₗ[R] M ⧸ (I ^ m • ⊤ : Submodule R M) := liftQ (I ^ n • ⊤ : Submodule R M) (mkQ (I ^ m • ⊤ : Submodule R M)) (by rw [ker_mkQ] exact smul_mono (Ideal.pow_le_pow_right hmn) le_rfl) /-- The completion of a module with respect to an ideal. This is not necessarily Hausdorff. In fact, this is only complete if the ideal is finitely generated. -/ def AdicCompletion : Type _ := { f : ∀ n : ℕ, M ⧸ (I ^ n • ⊤ : Submodule R M) // ∀ {m n} (hmn : m ≤ n), AdicCompletion.transitionMap I M hmn (f n) = f m } namespace IsHausdorff instance bot : IsHausdorff (⊥ : Ideal R) M := ⟨fun x hx => by simpa only [pow_one ⊥, bot_smul, SModEq.bot] using hx 1⟩ variable {M} protected theorem subsingleton (h : IsHausdorff (⊤ : Ideal R) M) : Subsingleton M := ⟨fun x y => eq_of_sub_eq_zero <| h.haus (x - y) fun n => by rw [Ideal.top_pow, top_smul] exact SModEq.top⟩ variable (M) instance (priority := 100) of_subsingleton [Subsingleton M] : IsHausdorff I M := ⟨fun _ _ => Subsingleton.elim _ _⟩ variable {I M} theorem iInf_pow_smul (h : IsHausdorff I M) : (⨅ n : ℕ, I ^ n • ⊤ : Submodule R M) = ⊥ := eq_bot_iff.2 fun x hx => (mem_bot _).2 <| h.haus x fun n => SModEq.zero.2 <| (mem_iInf fun n : ℕ => I ^ n • ⊤).1 hx n end IsHausdorff namespace Hausdorffification /-- The canonical linear map to the Hausdorffification. -/ def of : M →ₗ[R] Hausdorffification I M := mkQ _ variable {I M} @[elab_as_elim] theorem induction_on {C : Hausdorffification I M → Prop} (x : Hausdorffification I M) (ih : ∀ x, C (of I M x)) : C x := Quotient.inductionOn' x ih variable (I M) instance : IsHausdorff I (Hausdorffification I M) := ⟨fun x => Quotient.inductionOn' x fun x hx => (Quotient.mk_eq_zero _).2 <| (mem_iInf _).2 fun n => by have := comap_map_mkQ (⨅ n : ℕ, I ^ n • ⊤ : Submodule R M) (I ^ n • ⊤) simp only [sup_of_le_right (iInf_le (fun n => (I ^ n • ⊤ : Submodule R M)) n)] at this rw [← this, map_smul'', mem_comap, Submodule.map_top, range_mkQ, ← SModEq.zero] exact hx n⟩ variable {M} [h : IsHausdorff I N] /-- Universal property of Hausdorffification: any linear map to a Hausdorff module extends to a unique map from the Hausdorffification. -/ def lift (f : M →ₗ[R] N) : Hausdorffification I M →ₗ[R] N := liftQ _ f <| map_le_iff_le_comap.1 <| h.iInf_pow_smul ▸ le_iInf fun n => le_trans (map_mono <| iInf_le _ n) <| by rw [map_smul''] exact smul_mono le_rfl le_top theorem lift_of (f : M →ₗ[R] N) (x : M) : lift I f (of I M x) = f x := rfl theorem lift_comp_of (f : M →ₗ[R] N) : (lift I f).comp (of I M) = f := LinearMap.ext fun _ => rfl /-- Uniqueness of lift. -/ theorem lift_eq (f : M →ₗ[R] N) (g : Hausdorffification I M →ₗ[R] N) (hg : g.comp (of I M) = f) : g = lift I f := LinearMap.ext fun x => induction_on x fun x => by rw [lift_of, ← hg, LinearMap.comp_apply] end Hausdorffification namespace IsPrecomplete instance bot : IsPrecomplete (⊥ : Ideal R) M := by refine ⟨fun f hf => ⟨f 1, fun n => ?_⟩⟩ cases' n with n · rw [pow_zero, Ideal.one_eq_top, top_smul] exact SModEq.top specialize hf (Nat.le_add_left 1 n) rw [pow_one, bot_smul, SModEq.bot] at hf; rw [hf] instance top : IsPrecomplete (⊤ : Ideal R) M := ⟨fun f _ => ⟨0, fun n => by rw [Ideal.top_pow, top_smul] exact SModEq.top⟩⟩ instance (priority := 100) of_subsingleton [Subsingleton M] : IsPrecomplete I M := ⟨fun f _ => ⟨0, fun n => by rw [Subsingleton.elim (f n) 0]⟩⟩ end IsPrecomplete namespace AdicCompletion /-- `AdicCompletion` is the submodule of compatible families in `∀ n : ℕ, M ⧸ (I ^ n • ⊤)`. -/ def submodule : Submodule R (∀ n : ℕ, M ⧸ (I ^ n • ⊤ : Submodule R M)) where carrier := { f | ∀ {m n} (hmn : m ≤ n), AdicCompletion.transitionMap I M hmn (f n) = f m } zero_mem' hmn := by rw [Pi.zero_apply, Pi.zero_apply, LinearMap.map_zero] add_mem' hf hg m n hmn := by rw [Pi.add_apply, Pi.add_apply, LinearMap.map_add, hf hmn, hg hmn] smul_mem' c f hf m n hmn := by rw [Pi.smul_apply, Pi.smul_apply, LinearMap.map_smul, hf hmn] instance : Zero (AdicCompletion I M) where zero := ⟨0, by simp⟩ instance : Add (AdicCompletion I M) where add x y := ⟨x.val + y.val, by simp [x.property, y.property]⟩ instance : Neg (AdicCompletion I M) where neg x := ⟨- x.val, by simp [x.property]⟩ instance : Sub (AdicCompletion I M) where sub x y := ⟨x.val - y.val, by simp [x.property, y.property]⟩ instance : SMul ℕ (AdicCompletion I M) where smul n x := ⟨n • x.val, by simp [x.property]⟩ instance : SMul ℤ (AdicCompletion I M) where smul n x := ⟨n • x.val, by simp [x.property]⟩ instance : AddCommGroup (AdicCompletion I M) := let f : AdicCompletion I M → ∀ n, M ⧸ (I ^ n • ⊤ : Submodule R M) := Subtype.val Subtype.val_injective.addCommGroup f rfl (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) instance : SMul R (AdicCompletion I M) where smul r x := ⟨r • x.val, by simp [x.property]⟩ instance : Module R (AdicCompletion I M) := let f : AdicCompletion I M →+ ∀ n, M ⧸ (I ^ n • ⊤ : Submodule R M) := { toFun := Subtype.val, map_zero' := rfl, map_add' := fun _ _ ↦ rfl } Subtype.val_injective.module R f (fun _ _ ↦ rfl) /-- The canonical inclusion from the completion to the product. -/ @[simps] def incl : AdicCompletion I M →ₗ[R] (∀ n, M ⧸ (I ^ n • ⊤ : Submodule R M)) where toFun x := x.val map_add' _ _ := rfl map_smul' _ _ := rfl /-- The canonical linear map to the completion. -/ def of : M →ₗ[R] AdicCompletion I M where toFun x := ⟨fun n => mkQ (I ^ n • ⊤ : Submodule R M) x, fun _ => rfl⟩ map_add' _ _ := rfl map_smul' _ _ := rfl @[simp] theorem of_apply (x : M) (n : ℕ) : (of I M x).1 n = mkQ (I ^ n • ⊤ : Submodule R M) x := rfl /-- Linearly evaluating a sequence in the completion at a given input. -/ def eval (n : ℕ) : AdicCompletion I M →ₗ[R] M ⧸ (I ^ n • ⊤ : Submodule R M) where toFun f := f.1 n map_add' _ _ := rfl map_smul' _ _ := rfl @[simp] theorem coe_eval (n : ℕ) : (eval I M n : AdicCompletion I M → M ⧸ (I ^ n • ⊤ : Submodule R M)) = fun f => f.1 n := rfl theorem eval_apply (n : ℕ) (f : AdicCompletion I M) : eval I M n f = f.1 n := rfl theorem eval_of (n : ℕ) (x : M) : eval I M n (of I M x) = mkQ (I ^ n • ⊤ : Submodule R M) x := rfl @[simp] theorem eval_comp_of (n : ℕ) : (eval I M n).comp (of I M) = mkQ _ := rfl theorem eval_surjective (n : ℕ) : Function.Surjective (eval I M n) := fun x ↦ Quotient.inductionOn' x fun x ↦ ⟨of I M x, rfl⟩ @[simp] theorem range_eval (n : ℕ) : LinearMap.range (eval I M n) = ⊤ := LinearMap.range_eq_top.2 (eval_surjective I M n) @[simp] theorem val_zero (n : ℕ) : (0 : AdicCompletion I M).val n = 0 := rfl variable {I M} @[simp] theorem val_add (n : ℕ) (f g : AdicCompletion I M) : (f + g).val n = f.val n + g.val n := rfl @[simp] theorem val_sub (n : ℕ) (f g : AdicCompletion I M) : (f - g).val n = f.val n - g.val n := rfl @[simp] theorem val_sum {α : Type*} (s : Finset α) (f : α → AdicCompletion I M) (n : ℕ) : (Finset.sum s f).val n = Finset.sum s (fun a ↦ (f a).val n) := by simp_rw [← incl_apply, map_sum, Finset.sum_apply] /- No `simp` attribute, since it causes `simp` unification timeouts when considering the `AdicCompletion I R` module instance on `AdicCompletion I M` (see `AdicCompletion/Algebra`). -/ theorem val_smul (n : ℕ) (r : R) (f : AdicCompletion I M) : (r • f).val n = r • f.val n := rfl @[ext] theorem ext {x y : AdicCompletion I M} (h : ∀ n, x.val n = y.val n) : x = y := Subtype.eq <| funext h variable (I M) instance : IsHausdorff I (AdicCompletion I M) where haus' x h := ext fun n ↦ by refine smul_induction_on (SModEq.zero.1 <| h n) (fun r hr x _ ↦ ?_) (fun x y hx hy ↦ ?_) · simp only [val_smul, val_zero] exact Quotient.inductionOn' (x.val n) (fun a ↦ SModEq.zero.2 <| smul_mem_smul hr mem_top) · simp only [val_add, hx, val_zero, hy, add_zero] @[simp] theorem transitionMap_mk {m n : ℕ} (hmn : m ≤ n) (x : M) : transitionMap I M hmn (Submodule.Quotient.mk (p := (I ^ n • ⊤ : Submodule R M)) x) = Submodule.Quotient.mk (p := (I ^ m • ⊤ : Submodule R M)) x := by rfl @[simp] theorem transitionMap_eq (n : ℕ) : transitionMap I M (Nat.le_refl n) = LinearMap.id := by ext simp @[simp] theorem transitionMap_comp {m n k : ℕ} (hmn : m ≤ n) (hnk : n ≤ k) : transitionMap I M hmn ∘ₗ transitionMap I M hnk = transitionMap I M (hmn.trans hnk) := by ext simp @[simp] theorem transitionMap_comp_apply {m n k : ℕ} (hmn : m ≤ n) (hnk : n ≤ k) (x : M ⧸ (I ^ k • ⊤ : Submodule R M)) : transitionMap I M hmn (transitionMap I M hnk x) = transitionMap I M (hmn.trans hnk) x := by change (transitionMap I M hmn ∘ₗ transitionMap I M hnk) x = transitionMap I M (hmn.trans hnk) x simp @[simp] theorem transitionMap_comp_eval_apply {m n : ℕ} (hmn : m ≤ n) (x : AdicCompletion I M) : transitionMap I M hmn (x.val n) = x.val m := x.property hmn @[simp] theorem transitionMap_comp_eval {m n : ℕ} (hmn : m ≤ n) : transitionMap I M hmn ∘ₗ eval I M n = eval I M m := by ext x simp /-- A sequence `ℕ → M` is an `I`-adic Cauchy sequence if for every `m ≤ n`, `f m ≡ f n` modulo `I ^ m • ⊤`. -/ def IsAdicCauchy (f : ℕ → M) : Prop := ∀ {m n}, m ≤ n → f m ≡ f n [SMOD (I ^ m • ⊤ : Submodule R M)] /-- The type of `I`-adic Cauchy sequences. -/ def AdicCauchySequence : Type _ := { f : ℕ → M // IsAdicCauchy I M f } namespace AdicCauchySequence /-- The type of `I`-adic cauchy sequences is a submodule of the product `ℕ → M`. -/ def submodule : Submodule R (ℕ → M) where carrier := { f | IsAdicCauchy I M f } add_mem' := by intro f g hf hg m n hmn exact SModEq.add (hf hmn) (hg hmn) zero_mem' := by intro _ _ _ rfl smul_mem' := by intro r f hf m n hmn exact SModEq.smul (hf hmn) r instance : Zero (AdicCauchySequence I M) where zero := ⟨0, fun _ ↦ rfl⟩ instance : Add (AdicCauchySequence I M) where add x y := ⟨x.val + y.val, fun hmn ↦ SModEq.add (x.property hmn) (y.property hmn)⟩ instance : Neg (AdicCauchySequence I M) where neg x := ⟨- x.val, fun hmn ↦ SModEq.neg (x.property hmn)⟩ instance : Sub (AdicCauchySequence I M) where sub x y := ⟨x.val - y.val, fun hmn ↦ SModEq.sub (x.property hmn) (y.property hmn)⟩ instance : SMul ℕ (AdicCauchySequence I M) where smul n x := ⟨n • x.val, fun hmn ↦ SModEq.nsmul (x.property hmn) n⟩ instance : SMul ℤ (AdicCauchySequence I M) where smul n x := ⟨n • x.val, fun hmn ↦ SModEq.zsmul (x.property hmn) n⟩ instance : AddCommGroup (AdicCauchySequence I M) := by let f : AdicCauchySequence I M → (ℕ → M) := Subtype.val apply Subtype.val_injective.addCommGroup f rfl (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) instance : SMul R (AdicCauchySequence I M) where smul r x := ⟨r • x.val, fun hmn ↦ SModEq.smul (x.property hmn) r⟩ instance : Module R (AdicCauchySequence I M) := let f : AdicCauchySequence I M →+ (ℕ → M) := { toFun := Subtype.val, map_zero' := rfl, map_add' := fun _ _ ↦ rfl } Subtype.val_injective.module R f (fun _ _ ↦ rfl) instance : CoeFun (AdicCauchySequence I M) (fun _ ↦ ℕ → M) where coe f := f.val @[simp] theorem zero_apply (n : ℕ) : (0 : AdicCauchySequence I M) n = 0 := rfl variable {I M} @[simp] theorem add_apply (n : ℕ) (f g : AdicCauchySequence I M) : (f + g) n = f n + g n := rfl @[simp] theorem sub_apply (n : ℕ) (f g : AdicCauchySequence I M) : (f - g) n = f n - g n := rfl @[simp] theorem smul_apply (n : ℕ) (r : R) (f : AdicCauchySequence I M) : (r • f) n = r • f n := rfl @[ext] theorem ext {x y : AdicCauchySequence I M} (h : ∀ n, x n = y n) : x = y := Subtype.eq <| funext h /-- The defining property of an adic cauchy sequence unwrapped. -/ theorem mk_eq_mk {m n : ℕ} (hmn : m ≤ n) (f : AdicCauchySequence I M) : Submodule.Quotient.mk (p := (I ^ m • ⊤ : Submodule R M)) (f n) = Submodule.Quotient.mk (p := (I ^ m • ⊤ : Submodule R M)) (f m) := (f.property hmn).symm end AdicCauchySequence /-- The `I`-adic cauchy condition can be checked on successive `n`.-/ theorem isAdicCauchy_iff (f : ℕ → M) : IsAdicCauchy I M f ↔ ∀ n, f n ≡ f (n + 1) [SMOD (I ^ n • ⊤ : Submodule R M)] := by constructor · intro h n exact h (Nat.le_succ n) · intro h m n hmn induction n, hmn using Nat.le_induction with | base => rfl | succ n hmn ih => trans · exact ih · refine SModEq.mono (smul_mono (Ideal.pow_le_pow_right hmn) (by rfl)) (h n) /-- Construct `I`-adic cauchy sequence from sequence satisfying the successive cauchy condition. -/ @[simps] def AdicCauchySequence.mk (f : ℕ → M) (h : ∀ n, f n ≡ f (n + 1) [SMOD (I ^ n • ⊤ : Submodule R M)]) : AdicCauchySequence I M where val := f property := by rwa [isAdicCauchy_iff] /-- The canonical linear map from cauchy sequences to the completion. -/ @[simps] def mk : AdicCauchySequence I M →ₗ[R] AdicCompletion I M where toFun f := ⟨fun n ↦ Submodule.mkQ (I ^ n • ⊤ : Submodule R M) (f n), by intro m n hmn simp only [mkQ_apply, transitionMap_mk] exact (f.property hmn).symm⟩ map_add' _ _ := rfl map_smul' _ _ := rfl /-- Criterion for checking that an adic cauchy sequence is mapped to zero in the adic completion. -/ theorem mk_zero_of (f : AdicCauchySequence I M) (h : ∃ k : ℕ, ∀ n ≥ k, ∃ m ≥ n, ∃ l ≥ n, f m ∈ (I ^ l • ⊤ : Submodule R M)) : AdicCompletion.mk I M f = 0 := by obtain ⟨k, h⟩ := h ext n obtain ⟨m, hnm, l, hnl, hl⟩ := h (n + k) (by omega) rw [mk_apply_coe, Submodule.mkQ_apply, val_zero, ← AdicCauchySequence.mk_eq_mk (show n ≤ m by omega)] simpa using (Submodule.smul_mono_left (Ideal.pow_le_pow_right (by omega))) hl /-- Every element in the adic completion is represented by a Cauchy sequence. -/ theorem mk_surjective : Function.Surjective (mk I M) := by intro x choose a ha using fun n ↦ Submodule.Quotient.mk_surjective _ (x.val n) refine ⟨⟨a, ?_⟩, ?_⟩ · intro m n hmn rw [SModEq.def, ha m, ← transitionMap_mk I M hmn, ha n, x.property hmn] · ext n simp [ha n] /-- To show a statement about an element of `adicCompletion I M`, it suffices to check it on Cauchy sequences. -/ theorem induction_on {p : AdicCompletion I M → Prop} (x : AdicCompletion I M) (h : ∀ (f : AdicCauchySequence I M), p (mk I M f)) : p x := by obtain ⟨f, rfl⟩ := mk_surjective I M x exact h f variable {M} /-- Lift a compatible family of linear maps `M →ₗ[R] N ⧸ (I ^ n • ⊤ : Submodule R N)` to the `I`-adic completion of `M`. -/ def lift (f : ∀ (n : ℕ), M →ₗ[R] N ⧸ (I ^ n • ⊤ : Submodule R N)) (h : ∀ {m n : ℕ} (hle : m ≤ n), transitionMap I N hle ∘ₗ f n = f m) : M →ₗ[R] AdicCompletion I N where toFun := fun x ↦ ⟨fun n ↦ f n x, fun hkl ↦ LinearMap.congr_fun (h hkl) x⟩ map_add' x y := by simp only [map_add] rfl map_smul' r x := by simp only [LinearMapClass.map_smul, RingHom.id_apply] rfl @[simp] lemma eval_lift (f : ∀ (n : ℕ), M →ₗ[R] N ⧸ (I ^ n • ⊤ : Submodule R N)) (h : ∀ {m n : ℕ} (hle : m ≤ n), transitionMap I N hle ∘ₗ f n = f m) (n : ℕ) : eval I N n ∘ₗ lift I f h = f n := rfl @[simp] lemma eval_lift_apply (f : ∀ (n : ℕ), M →ₗ[R] N ⧸ (I ^ n • ⊤ : Submodule R N)) (h : ∀ {m n : ℕ} (hle : m ≤ n), transitionMap I N hle ∘ₗ f n = f m) (n : ℕ) (x : M) : (lift I f h x).val n = f n x := rfl end AdicCompletion namespace IsAdicComplete instance bot : IsAdicComplete (⊥ : Ideal R) M where protected theorem subsingleton (h : IsAdicComplete (⊤ : Ideal R) M) : Subsingleton M := h.1.subsingleton instance (priority := 100) of_subsingleton [Subsingleton M] : IsAdicComplete I M where open Finset theorem le_jacobson_bot [IsAdicComplete I R] : I ≤ (⊥ : Ideal R).jacobson := by intro x hx rw [← Ideal.neg_mem_iff, Ideal.mem_jacobson_bot] intro y rw [add_comm] let f : ℕ → R := fun n => ∑ i ∈ range n, (x * y) ^ i have hf : ∀ m n, m ≤ n → f m ≡ f n [SMOD I ^ m • (⊤ : Submodule R R)] := by intro m n h simp only [f, Algebra.id.smul_eq_mul, Ideal.mul_top, SModEq.sub_mem] rw [← add_tsub_cancel_of_le h, Finset.sum_range_add, ← sub_sub, sub_self, zero_sub, @neg_mem_iff] apply Submodule.sum_mem intro n _ rw [mul_pow, pow_add, mul_assoc] exact Ideal.mul_mem_right _ (I ^ m) (Ideal.pow_mem_pow hx m) obtain ⟨L, hL⟩ := IsPrecomplete.prec toIsPrecomplete @hf rw [isUnit_iff_exists_inv] use L rw [← sub_eq_zero, neg_mul] apply IsHausdorff.haus (toIsHausdorff : IsHausdorff I R) intro n specialize hL n rw [SModEq.sub_mem, Algebra.id.smul_eq_mul, Ideal.mul_top] at hL ⊢ rw [sub_zero] suffices (1 - x * y) * f n - 1 ∈ I ^ n by convert Ideal.sub_mem _ this (Ideal.mul_mem_left _ (1 + -(x * y)) hL) using 1 ring cases n · simp only [Ideal.one_eq_top, pow_zero, Nat.zero_eq, mem_top] · rw [← neg_sub _ (1 : R), neg_mul, mul_geom_sum, neg_sub, sub_sub, add_comm, ← sub_sub, sub_self, zero_sub, @neg_mem_iff, mul_pow] exact Ideal.mul_mem_right _ (I ^ _) (Ideal.pow_mem_pow hx _) end IsAdicComplete
RingTheory\AdicCompletion\Exactness.lean
/- Copyright (c) 2024 Judith Ludwig, Christian Merten. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Judith Ludwig, Christian Merten -/ import Mathlib.Algebra.Exact import Mathlib.RingTheory.AdicCompletion.Functoriality import Mathlib.RingTheory.Filtration /-! # Exactness of adic completion In this file we establish exactness properties of adic completions. In particular we show: ## Main results - `AdicCompletion.map_surjective`: Adic completion preserves surjectivity. - `AdicCompletion.map_injective`: Adic completion preserves injectivity of maps between finite modules over a Noetherian ring. - `AdicCompletion.map_exact`: Over a noetherian ring adic completion is exact on finite modules. ## Implementation details All results are proven directly without using Mittag-Leffler systems. -/ universe u v w t open LinearMap namespace AdicCompletion variable {R : Type u} [CommRing R] {I : Ideal R} section Surjectivity variable {M : Type v} [AddCommGroup M] [Module R M] variable {N : Type w} [AddCommGroup N] [Module R N] variable {f : M →ₗ[R] N} (hf : Function.Surjective f) /- In each step, a preimage is constructed from the preimage of the previous step by subtracting this delta. -/ private noncomputable def mapPreimageDelta (x : AdicCauchySequence I N) {n : ℕ} {y yₙ : M} (hy : f y = x (n + 1)) (hyₙ : f yₙ = x n) : { d : (I ^ n • ⊤ : Submodule R M) | f d = f (yₙ - y) } := have h : f (yₙ - y) ∈ Submodule.map f (I ^ n • ⊤ : Submodule R M) := by rw [Submodule.map_smul'', Submodule.map_top, LinearMap.range_eq_top.mpr hf, map_sub, hyₙ, hy, ← Submodule.neg_mem_iff, neg_sub, ← SModEq.sub_mem] exact AdicCauchySequence.mk_eq_mk (Nat.le_succ n) x ⟨⟨h.choose, h.choose_spec.1⟩, h.choose_spec.2⟩ /- Inductively construct preimage of cauchy sequence. -/ private noncomputable def mapPreimage (x : AdicCauchySequence I N) : (n : ℕ) → f ⁻¹' {x n} | .zero => ⟨(hf (x 0)).choose, (hf (x 0)).choose_spec⟩ | .succ n => let y := (hf (x (n + 1))).choose have hy := (hf (x (n + 1))).choose_spec let ⟨yₙ, (hyₙ : f yₙ = x n)⟩ := mapPreimage x n let ⟨⟨d, _⟩, (p : f d = f (yₙ - y))⟩ := mapPreimageDelta hf x hy hyₙ ⟨yₙ - d, by simpa [p]⟩ variable (I) /-- Adic completion preserves surjectivity -/ theorem map_surjective : Function.Surjective (map I f) := fun y ↦ by apply AdicCompletion.induction_on I N y (fun b ↦ ?_) let a := mapPreimage hf b refine ⟨AdicCompletion.mk I M (AdicCauchySequence.mk I M (fun n ↦ (a n : M)) ?_), ?_⟩ · refine fun n ↦ SModEq.symm ?_ simp only [SModEq.symm, SModEq, mapPreimage, Submodule.Quotient.mk_sub, sub_eq_self, Submodule.Quotient.mk_eq_zero, SetLike.coe_mem, a] · exact _root_.AdicCompletion.ext fun n ↦ congrArg _ ((a n).property) end Surjectivity variable {M : Type u} [AddCommGroup M] [Module R M] variable {N : Type u} [AddCommGroup N] [Module R N] variable {P : Type u} [AddCommGroup P] [Module R P] section Injectivity variable [IsNoetherianRing R] [Module.Finite R N] (I) open LinearMap /-- Adic completion preserves injectivity of finite modules over a Noetherian ring. -/ theorem map_injective {f : M →ₗ[R] N} (hf : Function.Injective f) : Function.Injective (map I f) := by obtain ⟨k, hk⟩ := Ideal.exists_pow_inf_eq_pow_smul I (range f) rw [← LinearMap.ker_eq_bot, LinearMap.ker_eq_bot'] intro x apply AdicCompletion.induction_on I M x (fun a ↦ ?_) intro hx refine AdicCompletion.mk_zero_of _ _ _ ⟨42, fun n _ ↦ ⟨n + k, by omega, n, by omega, ?_⟩⟩ rw [← Submodule.comap_map_eq_of_injective hf (I ^ n • ⊤ : Submodule R M), Submodule.map_smul'', Submodule.map_top] apply (smul_mono_right _ inf_le_right : I ^ n • (I ^ k • ⊤ ⊓ (range f)) ≤ _) nth_rw 2 [show n = n + k - k by omega] rw [← hk (n + k) (show n + k ≥ k by omega)] exact ⟨by simpa using congrArg (fun x ↦ x.val (n + k)) hx, ⟨a (n + k), rfl⟩⟩ end Injectivity section variable [IsNoetherianRing R] [Module.Finite R N] variable {f : M →ₗ[R] N} {g : N →ₗ[R] P} (hf : Function.Injective f) (hfg : Function.Exact f g) (hg : Function.Surjective g) section variable {k : ℕ} (hkn : ∀ n ≥ k, I ^ n • ⊤ ⊓ LinearMap.range f = I ^ (n - k) • (I ^ k • ⊤ ⊓ LinearMap.range f)) (x : AdicCauchySequence I N) (hker : ∀ (n : ℕ), g (x n) ∈ (I ^ n • ⊤ : Submodule R P)) /- In each step, a preimage is constructed from the preimage of the previous step by adding this delta. -/ private noncomputable def mapExactAuxDelta {n : ℕ} {d : N} (hdmem : d ∈ (I ^ (k + n + 1) • ⊤ : Submodule R N)) {y yₙ : M} (hd : f y = x (k + n + 1) - d) (hyₙ : f yₙ - x (k + n) ∈ (I ^ (k + n) • ⊤ : Submodule R N)) : { d : (I ^ n • ⊤ : Submodule R M) | f (yₙ + d) - x (k + n + 1) ∈ (I ^ (k + n + 1) • ⊤ : Submodule R N) } := have h : f (y - yₙ) ∈ (I ^ (k + n) • ⊤ : Submodule R N) := by simp only [map_sub, hd] convert_to x (k + n + 1) - x (k + n) - d - (f yₙ - x (k + n)) ∈ I ^ (k + n) • ⊤ · abel · refine Submodule.sub_mem _ (Submodule.sub_mem _ ?_ ?_) hyₙ · rw [← Submodule.Quotient.eq] exact AdicCauchySequence.mk_eq_mk (by omega) _ · exact (Submodule.smul_mono_left (Ideal.pow_le_pow_right (by omega))) hdmem have hincl : I ^ (k + n - k) • (I ^ k • ⊤ ⊓ range f) ≤ I ^ (k + n - k) • (range f) := smul_mono_right _ inf_le_right have hyyₙ : y - yₙ ∈ (I ^ n • ⊤ : Submodule R M) := by convert_to y - yₙ ∈ (I ^ (k + n - k) • ⊤ : Submodule R M) · simp · rw [← Submodule.comap_map_eq_of_injective hf (I ^ (k + n - k) • ⊤ : Submodule R M), Submodule.map_smul'', Submodule.map_top] apply hincl rw [← hkn (k + n) (by omega)] exact ⟨h, ⟨y - yₙ, rfl⟩⟩ ⟨⟨y - yₙ, hyyₙ⟩, by simpa [hd, Nat.succ_eq_add_one, Nat.add_assoc]⟩ open Submodule /- Inductively construct preimage of cauchy sequence in kernel of `g.adicCompletion I`. -/ private noncomputable def mapExactAux : (n : ℕ) → { a : M | f a - x (k + n) ∈ (I ^ (k + n) • ⊤ : Submodule R N) } | .zero => let d := (h2 0).choose let y := (h2 0).choose_spec.choose have hdy : f y = x (k + 0) - d := (h2 0).choose_spec.choose_spec.right have hdmem := (h2 0).choose_spec.choose_spec.left ⟨y, by simpa [hdy]⟩ | .succ n => let d := (h2 <| n + 1).choose let y := (h2 <| n + 1).choose_spec.choose have hdy : f y = x (k + (n + 1)) - d := (h2 <| n + 1).choose_spec.choose_spec.right have hdmem := (h2 <| n + 1).choose_spec.choose_spec.left let ⟨yₙ, (hyₙ : f yₙ - x (k + n) ∈ (I ^ (k + n) • ⊤ : Submodule R N))⟩ := mapExactAux n let ⟨d, hd⟩ := mapExactAuxDelta hf hkn x hdmem hdy hyₙ ⟨yₙ + d, hd⟩ where h1 (n : ℕ) : g (x (k + n)) ∈ Submodule.map g (I ^ (k + n) • ⊤ : Submodule R N) := by rw [map_smul'', Submodule.map_top, range_eq_top.mpr hg] exact hker (k + n) h2 (n : ℕ) : ∃ (d : N) (y : M), d ∈ (I ^ (k + n) • ⊤ : Submodule R N) ∧ f y = x (k + n) - d := by obtain ⟨d, hdmem, hd⟩ := h1 n obtain ⟨y, hdy⟩ := (hfg (x (k + n) - d)).mp (by simp [hd]) exact ⟨d, y, hdmem, hdy⟩ end /-- `AdicCompletion` over a Noetherian ring is exact on finitely generated modules. -/ theorem map_exact : Function.Exact (map I f) (map I g) := by refine LinearMap.exact_of_comp_eq_zero_of_ker_le_range ?_ (fun y ↦ ?_) · rw [map_comp, hfg.linearMap_comp_eq_zero, AdicCompletion.map_zero] · apply AdicCompletion.induction_on I N y (fun b ↦ ?_) intro hz obtain ⟨k, hk⟩ := Ideal.exists_pow_inf_eq_pow_smul I (LinearMap.range f) have hb (n : ℕ) : g (b n) ∈ (I ^ n • ⊤ : Submodule R P) := by simpa using congrArg (fun x ↦ x.val n) hz let a := mapExactAux hf hfg hg hk b hb refine ⟨AdicCompletion.mk I M (AdicCauchySequence.mk I M (fun n ↦ (a n : M)) ?_), ?_⟩ · refine fun n ↦ SModEq.symm ?_ simp [a, mapExactAux, SModEq] · ext n suffices h : Submodule.Quotient.mk (p := (I ^ n • ⊤ : Submodule R N)) (f (a n)) = Submodule.Quotient.mk (p := (I ^ n • ⊤ : Submodule R N)) (b (k + n)) by simp [h, AdicCauchySequence.mk_eq_mk (show n ≤ k + n by omega)] rw [Submodule.Quotient.eq] have hle : (I ^ (k + n) • ⊤ : Submodule R N) ≤ (I ^ n • ⊤ : Submodule R N) := Submodule.smul_mono_left (Ideal.pow_le_pow_right (by omega)) exact hle (a n).property end end AdicCompletion
RingTheory\AdicCompletion\Functoriality.lean
/- Copyright (c) 2024 Judith Ludwig, Christian Merten. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Judith Ludwig, Christian Merten -/ import Mathlib.RingTheory.AdicCompletion.Basic import Mathlib.RingTheory.AdicCompletion.Algebra import Mathlib.Algebra.DirectSum.Basic /-! # Functoriality of adic completions In this file we establish functorial properties of the adic completion. ## Main definitions - `AdicCauchySequence.map I f`: the linear map on `I`-adic cauchy sequences induced by `f` - `AdicCompletion.map I f`: the linear map on `I`-adic completions induced by `f` ## Main results - `sumEquivOfFintype`: adic completion commutes with finite sums - `piEquivOfFintype`: adic completion commutes with finite products -/ suppress_compilation variable {R : Type*} [CommRing R] (I : Ideal R) variable {M : Type*} [AddCommGroup M] [Module R M] variable {N : Type*} [AddCommGroup N] [Module R N] variable {P : Type*} [AddCommGroup P] [Module R P] variable {T : Type*} [AddCommGroup T] [Module (AdicCompletion I R) T] namespace LinearMap /-- `R`-linear version of `reduceModIdeal`. -/ private def reduceModIdealAux (f : M →ₗ[R] N) : M ⧸ (I • ⊤ : Submodule R M) →ₗ[R] N ⧸ (I • ⊤ : Submodule R N) := Submodule.mapQ (I • ⊤ : Submodule R M) (I • ⊤ : Submodule R N) f (fun x hx ↦ by refine Submodule.smul_induction_on hx (fun r hr x _ ↦ ?_) (fun x y hx hy ↦ ?_) · simp [Submodule.smul_mem_smul hr Submodule.mem_top] · simp [Submodule.add_mem _ hx hy]) @[local simp] private theorem reduceModIdealAux_apply (f : M →ₗ[R] N) (x : M) : (f.reduceModIdealAux I) (Submodule.Quotient.mk (p := (I • ⊤ : Submodule R M)) x) = Submodule.Quotient.mk (p := (I • ⊤ : Submodule R N)) (f x) := rfl /-- The induced linear map on the quotients mod `I • ⊤`. -/ def reduceModIdeal (f : M →ₗ[R] N) : M ⧸ (I • ⊤ : Submodule R M) →ₗ[R ⧸ I] N ⧸ (I • ⊤ : Submodule R N) where toFun := f.reduceModIdealAux I map_add' := by simp map_smul' r x := by refine Quotient.inductionOn' r (fun r ↦ ?_) refine Quotient.inductionOn' x (fun x ↦ ?_) simp only [Submodule.Quotient.mk''_eq_mk, Ideal.Quotient.mk_eq_mk, Module.Quotient.mk_smul_mk, Submodule.Quotient.mk_smul, LinearMapClass.map_smul, reduceModIdealAux_apply, RingHomCompTriple.comp_apply] @[simp] theorem reduceModIdeal_apply (f : M →ₗ[R] N) (x : M) : (f.reduceModIdeal I) (Submodule.Quotient.mk (p := (I • ⊤ : Submodule R M)) x) = Submodule.Quotient.mk (p := (I • ⊤ : Submodule R N)) (f x) := rfl end LinearMap namespace AdicCompletion open LinearMap theorem transitionMap_comp_reduceModIdeal (f : M →ₗ[R] N) {m n : ℕ} (hmn : m ≤ n) : transitionMap I N hmn ∘ₗ f.reduceModIdeal (I ^ n) = (f.reduceModIdeal (I ^ m) : _ →ₗ[R] _) ∘ₗ transitionMap I M hmn := by ext x simp namespace AdicCauchySequence /-- A linear map induces a linear map on adic cauchy sequences. -/ @[simps] def map (f : M →ₗ[R] N) : AdicCauchySequence I M →ₗ[R] AdicCauchySequence I N where toFun a := ⟨fun n ↦ f (a n), fun {m n} hmn ↦ by have hm : Submodule.map f (I ^ m • ⊤ : Submodule R M) ≤ (I ^ m • ⊤ : Submodule R N) := by rw [Submodule.map_smul''] exact smul_mono_right _ le_top apply SModEq.mono hm apply SModEq.map (a.property hmn) f⟩ map_add' a b := by ext n; simp map_smul' r a := by ext n; simp variable (M) in @[simp] theorem map_id : map I (LinearMap.id (M := M)) = LinearMap.id := rfl theorem map_comp (f : M →ₗ[R] N) (g : N →ₗ[R] P) : map I g ∘ₗ map I f = map I (g ∘ₗ f) := rfl theorem map_comp_apply (f : M →ₗ[R] N) (g : N →ₗ[R] P) (a : AdicCauchySequence I M) : map I g (map I f a) = map I (g ∘ₗ f) a := rfl @[simp] theorem map_zero : map I (0 : M →ₗ[R] N) = 0 := rfl end AdicCauchySequence /-- `R`-linear version of `adicCompletion`. -/ private def adicCompletionAux (f : M →ₗ[R] N) : AdicCompletion I M →ₗ[R] AdicCompletion I N := AdicCompletion.lift I (fun n ↦ reduceModIdeal (I ^ n) f ∘ₗ AdicCompletion.eval I M n) (fun {m n} hmn ↦ by rw [← comp_assoc, AdicCompletion.transitionMap_comp_reduceModIdeal, comp_assoc, transitionMap_comp_eval]) @[local simp] private theorem adicCompletionAux_val_apply (f : M →ₗ[R] N) {n : ℕ} (x : AdicCompletion I M) : (adicCompletionAux I f x).val n = f.reduceModIdeal (I ^ n) (x.val n) := rfl /-- A linear map induces a map on adic completions. -/ def map (f : M →ₗ[R] N) : AdicCompletion I M →ₗ[AdicCompletion I R] AdicCompletion I N where toFun := adicCompletionAux I f map_add' := by aesop map_smul' r x := by ext n simp only [adicCompletionAux_val_apply, smul_eval, smul_eq_mul, RingHom.id_apply] rw [val_smul_eq_evalₐ_smul, val_smul_eq_evalₐ_smul, map_smul] @[simp] theorem map_val_apply (f : M →ₗ[R] N) {n : ℕ} (x : AdicCompletion I M) : (map I f x).val n = f.reduceModIdeal (I ^ n) (x.val n) := rfl /-- Equality of maps out of an adic completion can be checked on Cauchy sequences. -/ theorem map_ext {N} {f g : AdicCompletion I M → N} (h : ∀ (a : AdicCauchySequence I M), f (AdicCompletion.mk I M a) = g (AdicCompletion.mk I M a)) : f = g := by ext x apply induction_on I M x (fun a ↦ h a) /-- Equality of linear maps out of an adic completion can be checked on Cauchy sequences. -/ @[ext] theorem map_ext' {f g : AdicCompletion I M →ₗ[AdicCompletion I R] T} (h : ∀ (a : AdicCauchySequence I M), f (AdicCompletion.mk I M a) = g (AdicCompletion.mk I M a)) : f = g := by ext x apply induction_on I M x (fun a ↦ h a) /-- Equality of linear maps out of an adic completion can be checked on Cauchy sequences. -/ @[ext] theorem map_ext'' {f g : AdicCompletion I M →ₗ[R] N} (h : f.comp (AdicCompletion.mk I M) = g.comp (AdicCompletion.mk I M)) : f = g := by ext x apply induction_on I M x (fun a ↦ LinearMap.ext_iff.mp h a) variable (M) in @[simp] theorem map_id : map I (LinearMap.id (M := M)) = LinearMap.id (R := AdicCompletion I R) (M := AdicCompletion I M) := by ext a n simp theorem map_comp (f : M →ₗ[R] N) (g : N →ₗ[R] P) : map I g ∘ₗ map I f = map I (g ∘ₗ f) := by ext simp theorem map_comp_apply (f : M →ₗ[R] N) (g : N →ₗ[R] P) (x : AdicCompletion I M) : map I g (map I f x) = map I (g ∘ₗ f) x := by show (map I g ∘ₗ map I f) x = map I (g ∘ₗ f) x rw [map_comp] @[simp] theorem map_mk (f : M →ₗ[R] N) (a : AdicCauchySequence I M) : map I f (AdicCompletion.mk I M a) = AdicCompletion.mk I N (AdicCauchySequence.map I f a) := rfl @[simp] theorem map_zero : map I (0 : M →ₗ[R] N) = 0 := by ext simp /-- A linear equiv induces a linear equiv on adic completions. -/ def congr (f : M ≃ₗ[R] N) : AdicCompletion I M ≃ₗ[AdicCompletion I R] AdicCompletion I N := LinearEquiv.ofLinear (map I f) (map I f.symm) (by simp [map_comp]) (by simp [map_comp]) @[simp] theorem congr_apply (f : M ≃ₗ[R] N) (x : AdicCompletion I M) : congr I f x = map I f x := rfl @[simp] theorem congr_symm_apply (f : M ≃ₗ[R] N) (x : AdicCompletion I N) : (congr I f).symm x = map I f.symm x := rfl section Families /-! ### Adic completion in families In this section we consider a family `M : ι → Type*` of `R`-modules. Purely from the formal properties of adic completions we obtain two canonical maps - `AdicCompleiton I (∀ j, M j) →ₗ[R] ∀ j, AdicCompletion I (M j)` - `(⨁ j, (AdicCompletion I (M j))) →ₗ[R] AdicCompletion I (⨁ j, M j)` If `ι` is finite, both are isomorphisms and, modulo the equivalence `⨁ j, (AdicCompletion I (M j)` and `∀ j, AdicCompletion I (M j)`, inverse to each other. -/ variable {ι : Type*} [DecidableEq ι] (M : ι → Type*) [∀ i, AddCommGroup (M i)] [∀ i, Module R (M i)] section Pi /-- The canonical map from the adic completion of the product to the product of the adic completions. -/ @[simps!] def pi : AdicCompletion I (∀ j, M j) →ₗ[AdicCompletion I R] ∀ j, AdicCompletion I (M j) := LinearMap.pi (fun j ↦ map I (LinearMap.proj j)) end Pi section Sum open DirectSum /-- The canonical map from the sum of the adic completions to the adic completion of the sum. -/ def sum : (⨁ j, (AdicCompletion I (M j))) →ₗ[AdicCompletion I R] AdicCompletion I (⨁ j, M j) := toModule (AdicCompletion I R) ι (AdicCompletion I (⨁ j, M j)) (fun j ↦ map I (lof R ι M j)) @[simp] theorem sum_lof (j : ι) (x : AdicCompletion I (M j)) : sum I M ((DirectSum.lof (AdicCompletion I R) ι (fun i ↦ AdicCompletion I (M i)) j) x) = map I (lof R ι M j) x := by simp [sum] @[simp] theorem sum_of (j : ι) (x : AdicCompletion I (M j)) : sum I M ((DirectSum.of (fun i ↦ AdicCompletion I (M i)) j) x) = map I (lof R ι M j) x := by rw [← lof_eq_of R] apply sum_lof variable [Fintype ι] /-- If `ι` is finite, we use the equivalence of sum and product to obtain an inverse for `AdicCompletion.sum` from `AdicCompletion.pi`. -/ def sumInv : AdicCompletion I (⨁ j, M j) →ₗ[AdicCompletion I R] (⨁ j, (AdicCompletion I (M j))) := letI f := map I (linearEquivFunOnFintype R ι M) letI g := linearEquivFunOnFintype (AdicCompletion I R) ι (fun j ↦ AdicCompletion I (M j)) g.symm.toLinearMap ∘ₗ pi I M ∘ₗ f @[simp] theorem component_sumInv (x : AdicCompletion I (⨁ j, M j)) (j : ι) : component (AdicCompletion I R) ι _ j (sumInv I M x) = map I (component R ι _ j) x := by apply induction_on I _ x (fun x ↦ ?_) rfl @[simp] theorem sumInv_apply (x : AdicCompletion I (⨁ j, M j)) (j : ι) : (sumInv I M x) j = map I (component R ι _ j) x := by apply induction_on I _ x (fun x ↦ ?_) rfl theorem sumInv_comp_sum : sumInv I M ∘ₗ sum I M = LinearMap.id := by ext j x apply DirectSum.ext (AdicCompletion I R) (fun i ↦ ?_) ext n simp only [LinearMap.coe_comp, Function.comp_apply, sum_lof, map_mk, component_sumInv, mk_apply_coe, AdicCauchySequence.map_apply_coe, Submodule.mkQ_apply, LinearMap.id_comp] rw [DirectSum.component.of, DirectSum.component.of] split · next h => subst h; simp · simp theorem sum_comp_sumInv : sum I M ∘ₗ sumInv I M = LinearMap.id := by ext f n simp only [LinearMap.coe_comp, Function.comp_apply, LinearMap.id_coe, id_eq, mk_apply_coe, Submodule.mkQ_apply] rw [← DirectSum.sum_univ_of (((sumInv I M) ((AdicCompletion.mk I (⨁ (j : ι), M j)) f)))] simp only [sumInv_apply, map_mk, map_sum, sum_of, val_sum, mk_apply_coe, AdicCauchySequence.map_apply_coe, Submodule.mkQ_apply] simp only [← Submodule.mkQ_apply, ← map_sum] erw [DirectSum.sum_univ_of] /-- If `ι` is finite, `sum` has `sumInv` as inverse. -/ def sumEquivOfFintype : (⨁ j, (AdicCompletion I (M j))) ≃ₗ[AdicCompletion I R] AdicCompletion I (⨁ j, M j) := LinearEquiv.ofLinear (sum I M) (sumInv I M) (sum_comp_sumInv I M) (sumInv_comp_sum I M) @[simp] theorem sumEquivOfFintype_apply (x : ⨁ j, (AdicCompletion I (M j))) : sumEquivOfFintype I M x = sum I M x := rfl @[simp] theorem sumEquivOfFintype_symm_apply (x : AdicCompletion I (⨁ j, M j)) : (sumEquivOfFintype I M).symm x = sumInv I M x := rfl end Sum section Pi open DirectSum variable [Fintype ι] /-- If `ι` is finite, `pi` is a linear equiv. -/ def piEquivOfFintype : AdicCompletion I (∀ j, M j) ≃ₗ[AdicCompletion I R] ∀ j, AdicCompletion I (M j) := letI f := (congr I (linearEquivFunOnFintype R ι M)).symm letI g := (linearEquivFunOnFintype (AdicCompletion I R) ι (fun j ↦ AdicCompletion I (M j))) f.trans ((sumEquivOfFintype I M).symm.trans g) @[simp] theorem piEquivOfFintype_apply (x : AdicCompletion I (∀ j, M j)) : piEquivOfFintype I M x = pi I M x := by simp [piEquivOfFintype, sumInv, map_comp_apply] /-- Adic completion of `R^n` is `(AdicCompletion I R)^n`. -/ def piEquivFin (n : ℕ) : AdicCompletion I (Fin n → R) ≃ₗ[AdicCompletion I R] Fin n → AdicCompletion I R := piEquivOfFintype I (ι := Fin n) (fun _ : Fin n ↦ R) @[simp] theorem piEquivFin_apply (n : ℕ) (x : AdicCompletion I (Fin n → R)) : piEquivFin I n x = pi I (fun _ : Fin n ↦ R) x := by simp only [piEquivFin, piEquivOfFintype_apply] end Pi end Families end AdicCompletion
RingTheory\Adjoin\Basic.lean
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.Algebra.Operations import Mathlib.Algebra.Algebra.Subalgebra.Prod import Mathlib.Algebra.Algebra.Subalgebra.Tower import Mathlib.LinearAlgebra.Basis import Mathlib.LinearAlgebra.Prod import Mathlib.LinearAlgebra.Finsupp import Mathlib.LinearAlgebra.Prod import Mathlib.Algebra.Module.Submodule.EqLocus /-! # Adjoining elements to form subalgebras This file develops the basic theory of subalgebras of an R-algebra generated by a set of elements. A basic interface for `adjoin` is set up. ## Tags adjoin, algebra -/ universe uR uS uA uB open Pointwise open Submodule Subsemiring 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} @[aesop safe 20 apply (rule_sets := [SetLike])] theorem subset_adjoin : s ⊆ adjoin R s := Algebra.gc.le_u_l s theorem adjoin_le {S : Subalgebra R A} (H : s ⊆ S) : adjoin R s ≤ S := Algebra.gc.l_le H theorem adjoin_eq_sInf : adjoin R s = sInf { p : Subalgebra R A | s ⊆ p } := le_antisymm (le_sInf fun _ h => adjoin_le h) (sInf_le subset_adjoin) theorem adjoin_le_iff {S : Subalgebra R A} : adjoin R s ≤ S ↔ s ⊆ S := Algebra.gc _ _ theorem adjoin_mono (H : s ⊆ t) : adjoin R s ≤ adjoin R t := Algebra.gc.monotone_l H theorem adjoin_eq_of_le (S : Subalgebra R A) (h₁ : s ⊆ S) (h₂ : S ≤ adjoin R s) : adjoin R s = S := le_antisymm (adjoin_le h₁) h₂ theorem adjoin_eq (S : Subalgebra R A) : adjoin R ↑S = S := adjoin_eq_of_le _ (Set.Subset.refl _) subset_adjoin theorem adjoin_iUnion {α : Type*} (s : α → Set A) : adjoin R (Set.iUnion s) = ⨆ i : α, adjoin R (s i) := (@Algebra.gc R A _ _ _).l_iSup theorem adjoin_attach_biUnion [DecidableEq A] {α : Type*} {s : Finset α} (f : s → Finset A) : adjoin R (s.attach.biUnion f : Set A) = ⨆ x, adjoin R (f x) := by simp [adjoin_iUnion] @[elab_as_elim] theorem adjoin_induction {p : A → Prop} {x : A} (h : x ∈ adjoin R s) (mem : ∀ x ∈ s, p x) (algebraMap : ∀ r, p (algebraMap R A r)) (add : ∀ x y, p x → p y → p (x + y)) (mul : ∀ x y, p x → p y → p (x * y)) : p x := let S : Subalgebra R A := { carrier := p mul_mem' := mul _ _ add_mem' := add _ _ algebraMap_mem' := algebraMap } adjoin_le (show s ≤ S from mem) h /-- Induction principle for the algebra generated by a set `s`: show that `p x y` holds for any `x y ∈ adjoin R s` given that it holds for `x y ∈ s` and that it satisfies a number of natural properties. -/ @[elab_as_elim] theorem adjoin_induction₂ {p : A → A → Prop} {a b : A} (ha : a ∈ adjoin R s) (hb : b ∈ adjoin R s) (Hs : ∀ x ∈ s, ∀ y ∈ s, p x y) (Halg : ∀ r₁ r₂, p (algebraMap R A r₁) (algebraMap R A r₂)) (Halg_left : ∀ (r), ∀ x ∈ s, p (algebraMap R A r) x) (Halg_right : ∀ (r), ∀ x ∈ s, p x (algebraMap R A r)) (Hadd_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ + x₂) y) (Hadd_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ + y₂)) (Hmul_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ * x₂) y) (Hmul_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ * y₂)) : p a b := by refine adjoin_induction hb ?_ (fun r => ?_) (Hadd_right a) (Hmul_right a) · exact adjoin_induction ha Hs Halg_left (fun x y Hx Hy z hz => Hadd_left x y z (Hx z hz) (Hy z hz)) fun x y Hx Hy z hz => Hmul_left x y z (Hx z hz) (Hy z hz) · exact adjoin_induction ha (Halg_right r) (fun r' => Halg r' r) (fun x y => Hadd_left x y ((algebraMap R A) r)) fun x y => Hmul_left x y ((algebraMap R A) r) /-- The difference with `Algebra.adjoin_induction` is that this acts on the subtype. -/ @[elab_as_elim] theorem adjoin_induction' {p : adjoin R s → Prop} (mem : ∀ (x) (h : x ∈ s), p ⟨x, subset_adjoin h⟩) (algebraMap : ∀ r, p (algebraMap R _ r)) (add : ∀ x y, p x → p y → p (x + y)) (mul : ∀ x y, p x → p y → p (x * y)) (x : adjoin R s) : p x := Subtype.recOn x fun x hx => by refine Exists.elim ?_ fun (hx : x ∈ adjoin R s) (hc : p ⟨x, hx⟩) => hc exact adjoin_induction hx (fun x hx => ⟨subset_adjoin hx, mem x hx⟩) (fun r => ⟨Subalgebra.algebraMap_mem _ r, algebraMap r⟩) (fun x y hx hy => Exists.elim hx fun hx' hx => Exists.elim hy fun hy' hy => ⟨Subalgebra.add_mem _ hx' hy', add _ _ hx hy⟩) fun x y hx hy => Exists.elim hx fun hx' hx => Exists.elim hy fun hy' hy => ⟨Subalgebra.mul_mem _ hx' hy', mul _ _ hx hy⟩ @[elab_as_elim] theorem adjoin_induction'' {x : A} (hx : x ∈ adjoin R s) {p : (x : A) → x ∈ adjoin R s → Prop} (mem : ∀ x (h : x ∈ s), p x (subset_adjoin h)) (algebraMap : ∀ (r : R), p (algebraMap R A r) (algebraMap_mem _ r)) (add : ∀ x hx y hy, p x hx → p y hy → p (x + y) (add_mem hx hy)) (mul : ∀ x hx y hy, p x hx → p y hy → p (x * y) (mul_mem hx hy)) : p x hx := by refine adjoin_induction' mem algebraMap ?_ ?_ ⟨x, hx⟩ (p := fun x : adjoin R s ↦ p x.1 x.2) exacts [fun x y ↦ add x.1 x.2 y.1 y.2, fun x y ↦ mul x.1 x.2 y.1 y.2] @[simp] theorem adjoin_adjoin_coe_preimage {s : Set A} : adjoin R (((↑) : adjoin R s → A) ⁻¹' s) = ⊤ := by refine eq_top_iff.2 fun x ↦ adjoin_induction' (fun a ha ↦ ?_) (fun r ↦ ?_) (fun _ _ ↦ ?_) (fun _ _ ↦ ?_) x · exact subset_adjoin ha · exact Subalgebra.algebraMap_mem _ r · exact Subalgebra.add_mem _ · exact Subalgebra.mul_mem _ theorem adjoin_union (s t : Set A) : adjoin R (s ∪ t) = adjoin R s ⊔ adjoin R t := (Algebra.gc : GaloisConnection _ ((↑) : Subalgebra R A → Set A)).l_sup variable (R A) @[simp] theorem adjoin_empty : adjoin R (∅ : Set A) = ⊥ := show adjoin R ⊥ = ⊥ by apply GaloisConnection.l_bot exact Algebra.gc @[simp] theorem adjoin_univ : adjoin R (Set.univ : Set A) = ⊤ := eq_top_iff.2 fun _x => subset_adjoin <| Set.mem_univ _ variable {A} (s) theorem adjoin_eq_span : Subalgebra.toSubmodule (adjoin R s) = span R (Submonoid.closure s) := by apply le_antisymm · intro r hr rcases Subsemiring.mem_closure_iff_exists_list.1 hr with ⟨L, HL, rfl⟩ clear hr induction' L with hd tl ih · exact zero_mem _ rw [List.forall_mem_cons] at HL rw [List.map_cons, List.sum_cons] refine Submodule.add_mem _ ?_ (ih HL.2) replace HL := HL.1 clear ih tl suffices ∃ (z r : _) (_hr : r ∈ Submonoid.closure s), z • r = List.prod hd by rcases this with ⟨z, r, hr, hzr⟩ rw [← hzr] exact smul_mem _ _ (subset_span hr) induction' hd with hd tl ih · exact ⟨1, 1, (Submonoid.closure s).one_mem', one_smul _ _⟩ rw [List.forall_mem_cons] at HL rcases ih HL.2 with ⟨z, r, hr, hzr⟩ rw [List.prod_cons, ← hzr] rcases HL.1 with (⟨hd, rfl⟩ | hs) · refine ⟨hd * z, r, hr, ?_⟩ rw [Algebra.smul_def, Algebra.smul_def, (algebraMap _ _).map_mul, _root_.mul_assoc] · exact ⟨z, hd * r, Submonoid.mul_mem _ (Submonoid.subset_closure hs) hr, (mul_smul_comm _ _ _).symm⟩ refine span_le.2 ?_ change Submonoid.closure s ≤ (adjoin R s).toSubsemiring.toSubmonoid exact Submonoid.closure_le.2 subset_adjoin theorem span_le_adjoin (s : Set A) : span R s ≤ Subalgebra.toSubmodule (adjoin R s) := span_le.mpr subset_adjoin theorem adjoin_toSubmodule_le {s : Set A} {t : Submodule R A} : Subalgebra.toSubmodule (adjoin R s) ≤ t ↔ ↑(Submonoid.closure s) ⊆ (t : Set A) := by rw [adjoin_eq_span, span_le] theorem adjoin_eq_span_of_subset {s : Set A} (hs : ↑(Submonoid.closure s) ⊆ (span R s : Set A)) : Subalgebra.toSubmodule (adjoin R s) = span R s := le_antisymm ((adjoin_toSubmodule_le R).mpr hs) (span_le_adjoin R s) @[simp] theorem adjoin_span {s : Set A} : adjoin R (Submodule.span R s : Set A) = adjoin R s := le_antisymm (adjoin_le (span_le_adjoin _ _)) (adjoin_mono Submodule.subset_span) theorem adjoin_image (f : A →ₐ[R] B) (s : Set A) : adjoin R (f '' s) = (adjoin R s).map f := le_antisymm (adjoin_le <| Set.image_subset _ subset_adjoin) <| Subalgebra.map_le.2 <| adjoin_le <| Set.image_subset_iff.1 <| by -- Porting note: I don't understand how this worked in Lean 3 with just `subset_adjoin` simp only [Set.image_id', coe_carrier_toSubmonoid, Subalgebra.coe_toSubsemiring, Subalgebra.coe_comap] exact fun x hx => subset_adjoin ⟨x, hx, rfl⟩ @[simp] theorem adjoin_insert_adjoin (x : A) : adjoin R (insert x ↑(adjoin R s)) = adjoin R (insert x s) := le_antisymm (adjoin_le (Set.insert_subset_iff.mpr ⟨subset_adjoin (Set.mem_insert _ _), adjoin_mono (Set.subset_insert _ _)⟩)) (Algebra.adjoin_mono (Set.insert_subset_insert Algebra.subset_adjoin)) 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 mem_adjoin_of_map_mul {s} {x : A} {f : A →ₗ[R] B} (hf : ∀ a₁ a₂, f (a₁ * a₂) = f a₁ * f a₂) (h : x ∈ adjoin R s) : f x ∈ adjoin R (f '' (s ∪ {1})) := by refine @adjoin_induction R A _ _ _ _ (fun a => f a ∈ adjoin R (f '' (s ∪ {1}))) x h (fun a ha => subset_adjoin ⟨a, ⟨Set.subset_union_left ha, rfl⟩⟩) (fun r => ?_) (fun y z hy hz => by simpa [hy, hz] using Subalgebra.add_mem _ hy hz) fun y z hy hz => by simpa [hy, hz, hf y z] using Subalgebra.mul_mem _ hy hz have : f 1 ∈ adjoin R (f '' (s ∪ {1})) := subset_adjoin ⟨1, ⟨Set.subset_union_right <| Set.mem_singleton 1, rfl⟩⟩ convert Subalgebra.smul_mem (adjoin R (f '' (s ∪ {1}))) this r rw [algebraMap_eq_smul_one] exact f.map_smul _ _ 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 /-- If all elements of `s : Set A` commute pairwise, then `adjoin R s` is a commutative semiring. -/ def adjoinCommSemiringOfComm {s : Set A} (hcomm : ∀ a ∈ s, ∀ b ∈ s, a * b = b * a) : CommSemiring (adjoin R s) := { (adjoin R s).toSemiring with mul_comm := fun x y => by ext simp only [Subalgebra.coe_mul] exact adjoin_induction₂ x.prop y.prop hcomm (fun _ _ => by rw [commutes]) (fun r x _hx => commutes r x) (fun r x _hx => (commutes r x).symm) (fun _ _ _ h₁ h₂ => by simp only [add_mul, mul_add, h₁, h₂]) (fun _ _ _ h₁ h₂ => by simp only [add_mul, mul_add, h₁, h₂]) (fun x₁ x₂ y₁ h₁ h₂ => by rw [mul_assoc, h₂, ← mul_assoc y₁, ← h₁, mul_assoc x₁]) fun x₁ x₂ y₁ h₁ h₂ => by rw [mul_assoc x₂, ← h₂, ← mul_assoc x₂, ← h₁, ← mul_assoc] } variable {R} lemma commute_of_mem_adjoin_of_forall_mem_commute {a b : A} {s : Set A} (hb : b ∈ adjoin R s) (h : ∀ b ∈ s, Commute a b) : Commute a b := adjoin_induction hb h (fun r ↦ commute_algebraMap_right r a) (fun _ _ ↦ Commute.add_right) (fun _ _ ↦ Commute.mul_right) lemma commute_of_mem_adjoin_singleton_of_commute {a b c : A} (hc : c ∈ adjoin R {b}) (h : Commute a b) : Commute a c := commute_of_mem_adjoin_of_forall_mem_commute hc <| by simpa lemma commute_of_mem_adjoin_self {a b : A} (hb : b ∈ adjoin R {a}) : Commute a b := commute_of_mem_adjoin_singleton_of_commute hb rfl variable (R) theorem adjoin_singleton_one : adjoin R ({1} : Set A) = ⊥ := eq_bot_iff.2 <| adjoin_le <| Set.singleton_subset_iff.2 <| SetLike.mem_coe.2 <| one_mem _ theorem self_mem_adjoin_singleton (x : A) : x ∈ adjoin R ({x} : Set A) := Algebra.subset_adjoin (Set.mem_singleton_iff.mpr rfl) 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 · change adjoin R s ≤ (adjoin S s).restrictScalars R refine adjoin_le ?_ -- Porting note: unclear why this was broken have : (Subalgebra.restrictScalars R (adjoin S s) : Set A) = adjoin S s := rfl rw [this] exact subset_adjoin @[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 theorem adjoin_union_coe_submodule : Subalgebra.toSubmodule (adjoin R (s ∪ t)) = Subalgebra.toSubmodule (adjoin R s) * Subalgebra.toSubmodule (adjoin R t) := by rw [adjoin_eq_span, adjoin_eq_span, adjoin_eq_span, span_mul_span] congr 1 with z; simp [Submonoid.closure_union, Submonoid.mem_sup, Set.mem_mul] 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_total] 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 _ _) end CommSemiring section Ring variable [CommRing R] [Ring A] variable [Algebra R A] {s t : Set A} theorem mem_adjoin_iff {s : Set A} {x : A} : x ∈ adjoin R s ↔ x ∈ Subring.closure (Set.range (algebraMap R A) ∪ s) := ⟨fun hx => Subsemiring.closure_induction hx Subring.subset_closure (Subring.zero_mem _) (Subring.one_mem _) (fun _ _ => Subring.add_mem _) fun _ _ => Subring.mul_mem _, suffices Subring.closure (Set.range (algebraMap R A) ∪ s) ≤ (adjoin R s).toSubring from (show (_ : Set A) ⊆ _ from this) (a := x) -- Porting note: Lean doesn't seem to recognize the defeq between the order on subobjects and -- subsets of their coercions to sets as easily as in Lean 3 Subring.closure_le.2 Subsemiring.subset_closure⟩ theorem adjoin_eq_ring_closure (s : Set A) : (adjoin R s).toSubring = Subring.closure (Set.range (algebraMap R A) ∪ s) := Subring.ext fun _x => mem_adjoin_iff variable (R) /-- If all elements of `s : Set A` commute pairwise, then `adjoin R s` is a commutative ring. -/ def adjoinCommRingOfComm {s : Set A} (hcomm : ∀ a ∈ s, ∀ b ∈ s, a * b = b * a) : CommRing (adjoin R s) := { (adjoin R s).toRing, adjoinCommSemiringOfComm R hcomm with } end Ring end Algebra open Algebra Subalgebra namespace AlgHom variable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] theorem map_adjoin (φ : A →ₐ[R] B) (s : Set A) : (adjoin R s).map φ = adjoin R (φ '' s) := (adjoin_image _ _ _).symm @[simp] theorem map_adjoin_singleton (e : A →ₐ[R] B) (x : A) : (adjoin R {x}).map e = adjoin R {e x} := by rw [map_adjoin, Set.image_singleton] theorem adjoin_le_equalizer (φ₁ φ₂ : A →ₐ[R] B) {s : Set A} (h : s.EqOn φ₁ φ₂) : adjoin R s ≤ equalizer φ₁ φ₂ := adjoin_le h theorem ext_of_adjoin_eq_top {s : Set A} (h : adjoin R s = ⊤) ⦃φ₁ φ₂ : A →ₐ[R] B⦄ (hs : s.EqOn φ₁ φ₂) : φ₁ = φ₂ := ext fun _x => adjoin_le_equalizer φ₁ φ₂ hs <| h.symm ▸ trivial /-- Two algebra morphisms are equal on `Algebra.span s`iff they are equal on s -/ theorem eqOn_adjoin_iff {φ ψ : A →ₐ[R] B} {s : Set A} : Set.EqOn φ ψ (adjoin R s) ↔ Set.EqOn φ ψ s := by have (S : Set A) : S ≤ equalizer φ ψ ↔ Set.EqOn φ ψ S := Iff.rfl simp only [← this, Set.le_eq_subset, SetLike.coe_subset_coe, adjoin_le_iff] end AlgHom section NatInt theorem Algebra.adjoin_nat {R : Type*} [Semiring R] (s : Set R) : adjoin ℕ s = subalgebraOfSubsemiring (Subsemiring.closure s) := le_antisymm (adjoin_le Subsemiring.subset_closure) (Subsemiring.closure_le.2 subset_adjoin : Subsemiring.closure s ≤ (adjoin ℕ s).toSubsemiring) theorem Algebra.adjoin_int {R : Type*} [Ring R] (s : Set R) : adjoin ℤ s = subalgebraOfSubring (Subring.closure s) := le_antisymm (adjoin_le Subring.subset_closure) (Subring.closure_le.2 subset_adjoin : Subring.closure s ≤ (adjoin ℤ s).toSubring) /-- The `ℕ`-algebra equivalence between `Subsemiring.closure s` and `Algebra.adjoin ℕ s` given by the identity map. -/ def Subsemiring.closureEquivAdjoinNat {R : Type*} [Semiring R] (s : Set R) : Subsemiring.closure s ≃ₐ[ℕ] Algebra.adjoin ℕ s := Subalgebra.equivOfEq (subalgebraOfSubsemiring <| Subsemiring.closure s) _ (adjoin_nat s).symm /-- The `ℤ`-algebra equivalence between `Subring.closure s` and `Algebra.adjoin ℤ s` given by the identity map. -/ def Subring.closureEquivAdjoinInt {R : Type*} [Ring R] (s : Set R) : Subring.closure s ≃ₐ[ℤ] Algebra.adjoin ℤ s := Subalgebra.equivOfEq (subalgebraOfSubring <| Subring.closure s) _ (adjoin_int s).symm end NatInt section variable (F E : Type*) {K : Type*} [CommSemiring E] [Semiring K] [SMul F E] [Algebra E K] /-- If `K / E / F` is a ring extension tower, `L` is a submonoid of `K / F` which is generated by `S` as an `F`-module, then `E[L]` is generated by `S` as an `E`-module. -/ theorem Submonoid.adjoin_eq_span_of_eq_span [Semiring F] [Module F K] [IsScalarTower F E K] (L : Submonoid K) {S : Set K} (h : (L : Set K) = span F S) : toSubmodule (adjoin E (L : Set K)) = span E S := by rw [adjoin_eq_span, L.closure_eq, h] exact (span_le.mpr <| span_subset_span _ _ _).antisymm (span_mono subset_span) 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` which is generated by `S` as an `F`-module, then `E[L]` is generated by `S` as an `E`-module. -/ theorem Subalgebra.adjoin_eq_span_of_eq_span {S : Set K} (h : toSubmodule L = span F S) : toSubmodule (adjoin E (L : Set K)) = span E S := L.toSubmonoid.adjoin_eq_span_of_eq_span F E (congr_arg ((↑) : _ → Set K) h) /-- 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 _ erw [hi, Set.range_comp, i.toEquiv.range_eq_univ, Set.image_univ] end namespace Subalgebra variable [CommSemiring R] [Ring A] [Algebra R A] [Ring B] [Algebra R B] theorem comap_map_eq (f : A →ₐ[R] B) (S : Subalgebra R A) : (S.map f).comap f = S ⊔ Algebra.adjoin R (f ⁻¹' {0}) := by apply le_antisymm · intro x hx rw [mem_comap, mem_map] at hx obtain ⟨y, hy, hxy⟩ := hx replace hxy : x - y ∈ f ⁻¹' {0} := by simp [hxy] rw [← Algebra.adjoin_eq S, ← Algebra.adjoin_union, ← add_sub_cancel y x] exact Subalgebra.add_mem _ (Algebra.subset_adjoin <| Or.inl hy) (Algebra.subset_adjoin <| Or.inr hxy) · rw [← map_le, Algebra.map_sup, f.map_adjoin] apply le_of_eq rw [sup_eq_left, Algebra.adjoin_le_iff] exact (Set.image_preimage_subset f {0}).trans (Set.singleton_subset_iff.2 (S.map f).zero_mem) theorem comap_map_eq_self {f : A →ₐ[R] B} {S : Subalgebra R A} (h : f ⁻¹' {0} ⊆ S) : (S.map f).comap f = S := by convert comap_map_eq f S rwa [left_eq_sup, Algebra.adjoin_le_iff] end Subalgebra
RingTheory\Adjoin\FG.lean
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.EuclideanDomain.Int import Mathlib.Algebra.MvPolynomial.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_total (adjoin R s)] at hr rcases hr with ⟨l, hlq, rfl⟩ have := @Finsupp.total_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_total R] at this rcases this with ⟨l2, hlp, hl⟩ have := @Finsupp.total_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 x 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 open scoped Classical theorem FG.map {S : Subalgebra R A} (f : A →ₐ[R] B) (hs : S.FG) : (S.map f).FG := let ⟨s, hs⟩ := hs ⟨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 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
RingTheory\Adjoin\Field.lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.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 ?_) rwa [Minpoly.toAdjoin_apply', liftHom_mk, ← Subalgebra.coe_eq_zero, aeval_subalgebra_coe] at hP₁ /-- 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.liftHom _ 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⟩ cases' ih H3 with f 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 L] [Algebra R M] {x : L} (int : IsIntegral R x) (h : Splits (algebraMap R K) (minpoly R x)) theorem IsIntegral.mem_range_algHom_of_minpoly_splits (f : K →ₐ[R] L) : x ∈ f.range := show x ∈ Set.range f from Set.image_subset_range _ _ <| 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] : x ∈ (algebraMap K L).range := int.mem_range_algHom_of_minpoly_splits h (IsScalarTower.toAlgHom R K L) variable [Algebra K M] [IsScalarTower R K M] {x : M} (int : IsIntegral R x) theorem IsIntegral.minpoly_splits_tower_top' {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] [IsScalarTower R K L] (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*} [CommRing F] [StrongRankCondition F] [CommRing E] [StrongRankCondition E] [Ring 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
RingTheory\Adjoin\PowerBasis.lean
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.RingTheory.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`. -/ variable {K S : Type*} [Field K] [CommRing S] [Algebra K S] namespace Algebra open Polynomial open PowerBasis /-- 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 (Fin (minpoly K x).natDegree) _ (adjoin K {x}) fun i => ⟨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] end Algebra open Algebra /-- The power basis given by `x` if `B.gen ∈ adjoin K {x}`. See `PowerBasis.ofGenMemAdjoin'` for a version over a more general base ring. -/ @[simps!] noncomputable def PowerBasis.ofGenMemAdjoin {x : S} (B : PowerBasis K S) (hint : IsIntegral K x) (hx : B.gen ∈ adjoin K ({x} : Set S)) : PowerBasis K S := (Algebra.adjoin.powerBasis hint).map <| (Subalgebra.equivOfEq _ _ <| PowerBasis.adjoin_eq_top_of_gen_mem_adjoin hx).trans Subalgebra.topEquiv section IsIntegral namespace PowerBasis open Polynomial 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} (hB : IsIntegral R B.gen) /-- 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 [IsDomain S] (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 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 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, LinearEquiv.map_smulₛₗ, RingHom.id_apply, 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, eq_self_iff_true, 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 [IsDomain S] {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 [IsDomain S] {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
RingTheory\Adjoin\Tower.lean
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ 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 open scoped Classical 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 := let ⟨s, hs⟩ := hRS let ⟨t, ht⟩ := hSA ⟨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 open scoped Classical 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 cases' hAC with x hx cases' hBC with y hy have := hy simp_rw [eq_top_iff', mem_span_finset] at this choose f hf using this 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 hr (fun c hc => hxy c hc) (subset_span <| mem_insert_self _ _) fun p q hp hq => hyy <| Submodule.mul_mem_mul hp hq 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; Stacks 00IS; Altman--Kleiman 16.17. -/ 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
RingTheory\Bialgebra\Basic.lean
/- Copyright (c) 2024 Ali Ramsey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ali Ramsey, Kevin Buzzard -/ import Mathlib.RingTheory.Coalgebra.Basic import Mathlib.RingTheory.TensorProduct.Basic /-! # Bialgebras In this file we define `Bialgebra`s. ## Main definitions * `Bialgebra R A`: the structure of a bialgebra on the `R`-algebra `A`; * `CommSemiring.toBialgebra`: a commutative semiring is a bialgebra over itself. ## Implementation notes Rather than the "obvious" axiom `∀ a b, counit (a * b) = counit a * counit b`, the far more convoluted `mul_compr₂_counit` is used as a structure field; this says that the corresponding two maps `A →ₗ[R] A →ₗ[R] R` are equal; a similar trick is used for comultiplication as well. An alternative constructor `Bialgebra.mk'` is provided with the more easily-readable axioms. The argument for using the more convoluted axioms is that in practice there is evidence that they will be easier to prove (especially when dealing with things like tensor products of bialgebras). This does make the definition more surprising to mathematicians, however mathlib is no stranger to definitions which are surprising to mathematicians -- see for example its definition of a group. Note that this design decision is also compatible with that of `Coalgebra`. The lengthy docstring for these convoluted fields attempts to explain what is going on. ## References * <https://en.wikipedia.org/wiki/Bialgebra> ## Tags bialgebra -/ suppress_compilation universe u v open scoped TensorProduct /-- A bialgebra over a commutative (semi)ring `R` is both an algebra and a coalgebra over `R`, such that the counit and comultiplication are algebra morphisms. -/ class Bialgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends Algebra R A, Coalgebra R A where -- The counit is an algebra morphism /-- The counit on a bialgebra preserves 1. -/ counit_one : counit 1 = 1 /-- The counit on a bialgebra preserves multiplication. Note that this is written in a rather obscure way: it says that two bilinear maps `A →ₗ[R] A →ₗ[R]` are equal. The two corresponding equal linear maps `A ⊗[R] A →ₗ[R]` are the following: the first factors through `A` and is multiplication on `A` followed by `counit`. The second factors through `R ⊗[R] R`, and is `counit ⊗ counit` followed by multiplication on `R`. See `Bialgebra.mk'` for a constructor for bialgebras which uses the more familiar but mathematically equivalent `counit (a * b) = counit a * counit b`. -/ mul_compr₂_counit : (LinearMap.mul R A).compr₂ counit = (LinearMap.mul R R).compl₁₂ counit counit -- The comultiplication is an algebra morphism /-- The comultiplication on a bialgebra preserves `1`. -/ comul_one : comul 1 = 1 /-- The comultiplication on a bialgebra preserves multiplication. This is written in a rather obscure way: it says that two bilinear maps `A →ₗ[R] A →ₗ[R] (A ⊗[R] A)` are equal. The corresponding equal linear maps `A ⊗[R] A →ₗ[R] A ⊗[R] A` are firstly multiplcation followed by `comul`, and secondly `comul ⊗ comul` followed by multiplication on `A ⊗[R] A`. See `Bialgebra.mk'` for a constructor for bialgebras which uses the more familiar but mathematically equivalent `comul (a * b) = comul a * comul b`. -/ mul_compr₂_comul : (LinearMap.mul R A).compr₂ comul = (LinearMap.mul R (A ⊗[R] A)).compl₁₂ comul comul namespace Bialgebra open Coalgebra variable {R : Type u} {A : Type v} variable [CommSemiring R] [Semiring A] [Bialgebra R A] lemma counit_mul (a b : A) : counit (R := R) (a * b) = counit a * counit b := DFunLike.congr_fun (DFunLike.congr_fun mul_compr₂_counit a) b lemma comul_mul (a b : A) : comul (R := R) (a * b) = comul a * comul b := DFunLike.congr_fun (DFunLike.congr_fun mul_compr₂_comul a) b attribute [simp] counit_one comul_one counit_mul comul_mul /-- If `R` is a field (or even a commutative semiring) and `A` is an `R`-algebra with a coalgebra structure, then `Bialgebra.mk'` consumes proofs that the counit and comultiplication preserve the identity and multiplication, and produces a bialgebra structure on `A`. -/ def mk' (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] [C : Coalgebra R A] (counit_one : C.counit 1 = 1) (counit_mul : ∀ {a b}, C.counit (a * b) = C.counit a * C.counit b) (comul_one : C.comul 1 = 1) (comul_mul : ∀ {a b}, C.comul (a * b) = C.comul a * C.comul b) : Bialgebra R A where counit_one := counit_one mul_compr₂_counit := by ext; exact counit_mul comul_one := comul_one mul_compr₂_comul := by ext; exact comul_mul variable (R A) /-- `counitAlgHom R A` is the counit of the `R`-bialgebra `A`, as an `R`-algebra map. -/ @[simps!] def counitAlgHom : A →ₐ[R] R := .ofLinearMap counit counit_one counit_mul /-- `comulAlgHom R A` is the comultiplication of the `R`-bialgebra `A`, as an `R`-algebra map. -/ @[simps!] def comulAlgHom : A →ₐ[R] A ⊗[R] A := .ofLinearMap comul comul_one comul_mul variable {R A} @[simp] lemma counit_algebraMap (r : R) : counit (R := R) (algebraMap R A r) = r := (counitAlgHom R A).commutes r @[simp] lemma comul_algebraMap (r : R) : comul (R := R) (algebraMap R A r) = algebraMap R (A ⊗[R] A) r := (comulAlgHom R A).commutes r @[simp] lemma counit_natCast (n : ℕ) : counit (R := R) (n : A) = n := map_natCast (counitAlgHom R A) _ @[simp] lemma comul_natCast (n : ℕ) : comul (R := R) (n : A) = n := map_natCast (comulAlgHom R A) _ @[simp] lemma counit_pow (a : A) (n : ℕ) : counit (R := R) (a ^ n) = counit a ^ n := map_pow (counitAlgHom R A) a n @[simp] lemma comul_pow (a : A) (n : ℕ) : comul (R := R) (a ^ n) = comul a ^ n := map_pow (comulAlgHom R A) a n end Bialgebra namespace CommSemiring variable (R : Type u) [CommSemiring R] open Bialgebra /-- Every commutative (semi)ring is a bialgebra over itself -/ noncomputable instance toBialgebra : Bialgebra R R where mul_compr₂_counit := by ext; simp counit_one := rfl mul_compr₂_comul := by ext; simp comul_one := rfl end CommSemiring
RingTheory\Bialgebra\Equiv.lean
/- Copyright (c) 2024 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston -/ import Mathlib.RingTheory.Coalgebra.Equiv import Mathlib.RingTheory.Bialgebra.Hom /-! # Isomorphisms of `R`-bialgebras This file defines bundled isomorphisms of `R`-bialgebras. We simply mimic the early parts of `Mathlib/Algebra/Algebra/Equiv.lean`. ## Main definitions * `BialgEquiv R A B`: the type of `R`-bialgebra isomorphisms between `A` and `B`. ## Notations * `A ≃ₐc[R] B` : `R`-bialgebra equivalence from `A` to `B`. -/ universe u v w u₁ v₁ variable {R : Type u} {A : Type v} {B : Type w} {C : Type u₁} open Bialgebra /-- An equivalence of bialgebras is an invertible bialgebra homomorphism. -/ structure BialgEquiv (R : Type u) [CommSemiring R] (A : Type v) (B : Type w) [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] [CoalgebraStruct R A] [CoalgebraStruct R B] extends A ≃ₗc[R] B, A ≃* B where attribute [nolint docBlame] BialgEquiv.toMulEquiv attribute [nolint docBlame] BialgEquiv.toCoalgEquiv @[inherit_doc BialgEquiv] notation:50 A " ≃ₐc[" R "] " B => BialgEquiv R A B /-- `BialgEquivClass F R A B` asserts `F` is a type of bundled bialgebra equivalences from `A` to `B`. -/ class BialgEquivClass (F : Type*) (R A B : outParam Type*) [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] [CoalgebraStruct R A] [CoalgebraStruct R B] [EquivLike F A B] extends CoalgEquivClass F R A B, MulEquivClass F A B : Prop namespace BialgEquivClass variable {F R A B : Type*} [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] [CoalgebraStruct R A] [CoalgebraStruct R B] [EquivLike F A B] [BialgEquivClass F R A B] instance (priority := 100) toBialgHomClass : BialgHomClass F R A B where map_add := map_add map_smulₛₗ := map_smul counit_comp := CoalgHomClass.counit_comp map_comp_comul := CoalgHomClass.map_comp_comul map_mul := map_mul map_one := map_one /-- Reinterpret an element of a type of bialgebra equivalences as a bialgebra equivalence. -/ @[coe] def toBialgEquiv (f : F) : A ≃ₐc[R] B := { (f : A ≃ₗc[R] B), (f : A →ₐc[R] B) with } /-- Reinterpret an element of a type of bialgebra equivalences as a bialgebra equivalence. -/ instance instCoeToBialgEquiv : CoeHead F (A ≃ₐc[R] B) where coe f := toBialgEquiv f instance (priority := 100) toAlgEquivClass : AlgEquivClass F R A B where map_mul := map_mul map_add := map_add commutes := AlgHomClass.commutes end BialgEquivClass namespace BialgEquiv variable [CommSemiring R] section variable [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] [CoalgebraStruct R A] [CoalgebraStruct R B] /-- The bialgebra morphism underlying a bialgebra equivalence. -/ def toBialgHom (f : A ≃ₐc[R] B) : A →ₐc[R] B := { f.toCoalgEquiv with map_one' := map_one f.toMulEquiv map_mul' := map_mul f.toMulEquiv } /-- The algebra equivalence underlying a bialgebra equivalence. -/ def toAlgEquiv (f : A ≃ₐc[R] B) : A ≃ₐ[R] B := { f.toCoalgEquiv with map_mul' := map_mul f.toMulEquiv map_add' := map_add f.toCoalgEquiv commutes' := AlgHomClass.commutes f.toBialgHom } /-- The equivalence of types underlying a bialgebra equivalence. -/ def toEquiv : (A ≃ₐc[R] B) → A ≃ B := fun f => f.toCoalgEquiv.toEquiv theorem toEquiv_injective : Function.Injective (toEquiv : (A ≃ₐc[R] B) → A ≃ B) := fun ⟨_, _⟩ ⟨_, _⟩ h => (BialgEquiv.mk.injEq _ _ _ _).mpr (CoalgEquiv.toEquiv_injective h) @[simp] theorem toEquiv_inj {e₁ e₂ : A ≃ₐc[R] B} : e₁.toEquiv = e₂.toEquiv ↔ e₁ = e₂ := toEquiv_injective.eq_iff theorem toBialgHom_injective : Function.Injective (toBialgHom : (A ≃ₐc[R] B) → A →ₐc[R] B) := fun _ _ H => toEquiv_injective <| Equiv.ext <| BialgHom.congr_fun H instance : EquivLike (A ≃ₐc[R] B) A B where inv := fun f => f.invFun coe_injective' _ _ h _ := toBialgHom_injective (DFunLike.coe_injective h) left_inv := fun f => f.left_inv right_inv := fun f => f.right_inv instance : FunLike (A ≃ₐc[R] B) A B where coe := DFunLike.coe coe_injective' := DFunLike.coe_injective instance : BialgEquivClass (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) map_mul := (·.map_mul') @[simp, norm_cast] theorem toBialgHom_inj {e₁ e₂ : A ≃ₐc[R] B} : (↑e₁ : A →ₐc[R] B) = e₂ ↔ e₁ = e₂ := toBialgHom_injective.eq_iff @[simp] theorem coe_mk {f h h₀ h₁ h₂ h₃ h₄ h₅ h₆} : (⟨⟨⟨⟨⟨f, h⟩, h₀⟩, h₁, h₂⟩, h₃, h₄, h₅⟩, h₆⟩ : A ≃ₐc[R] B) = f := rfl end section variable [Semiring A] [Semiring B] [Semiring C] [Algebra R A] [Algebra R B] [Algebra R C] [CoalgebraStruct R A] [CoalgebraStruct R B] [CoalgebraStruct R C] variable (e e' : A ≃ₐc[R] B) /-- See Note [custom simps projection] -/ def Simps.apply {R : Type u} [CommSemiring R] {α : Type v} {β : Type w} [Semiring α] [Semiring β] [Algebra R α] [Algebra R β] [CoalgebraStruct R α] [CoalgebraStruct R β] (f : α ≃ₐc[R] β) : α → β := f initialize_simps_projections BialgEquiv (toFun → apply) @[simp, norm_cast] theorem coe_coe : ⇑(e : A →ₐc[R] B) = e := rfl @[simp] theorem toCoalgEquiv_eq_coe (f : A ≃ₐc[R] B) : f.toCoalgEquiv = f := rfl @[simp] theorem toBialgHom_eq_coe (f : A ≃ₐc[R] B) : f.toBialgHom = f := rfl @[simp] theorem toAlgEquiv_eq_coe (f : A ≃ₐc[R] B) : f.toAlgEquiv = f := rfl @[simp] theorem coe_toCoalgEquiv : ⇑(e : A ≃ₐ[R] B) = e := rfl @[simp] theorem coe_toBialgHom : ⇑(e : A →ₐc[R] B) = e := rfl @[simp] theorem coe_toAlgEquiv : ⇑(e : A ≃ₐ[R] B) = e := rfl theorem toCoalgEquiv_toCoalgHom : ((e : A ≃ₐc[R] B) : A →ₗc[R] B) = (e : A →ₐc[R] B) := rfl theorem toBialgHom_toAlgHom : ((e : A →ₐc[R] B) : A →ₐ[R] B) = e := 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 section variable (A R) /-- The identity map is a bialgebra equivalence. -/ @[refl, simps!] def refl : A ≃ₐc[R] A := { CoalgEquiv.refl R A, BialgHom.id R A with } end @[simp] theorem refl_toCoalgEquiv : refl R A = CoalgEquiv.refl R A := rfl @[simp] theorem refl_toBialgHom : refl R A = BialgHom.id R A := rfl /-- Bialgebra equivalences are symmetric. -/ @[symm] def symm (e : A ≃ₐc[R] B) : B ≃ₐc[R] A := { (e : A ≃ₗc[R] B).symm, (e : A ≃* B).symm with } @[simp] theorem symm_toCoalgEquiv (e : A ≃ₐc[R] B) : e.symm = (e : A ≃ₗc[R] B).symm := rfl /-- See Note [custom simps projection] -/ def Simps.symm_apply {R : Type*} [CommSemiring R] {A : Type*} {B : Type*} [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] [CoalgebraStruct R A] [CoalgebraStruct R B] (e : A ≃ₐc[R] B) : B → A := e.symm initialize_simps_projections BialgEquiv (invFun → symm_apply) theorem invFun_eq_symm : e.invFun = e.symm := rfl @[simp] theorem coe_toEquiv_symm : e.toEquiv.symm = e.symm := rfl variable {e₁₂ : A ≃ₐc[R] B} {e₂₃ : B ≃ₐc[R] C} /-- Bialgebra equivalences are transitive. -/ @[trans, simps!] def trans (e₁₂ : A ≃ₐc[R] B) (e₂₃ : B ≃ₐc[R] C) : A ≃ₐc[R] C := { (e₁₂ : A ≃ₗc[R] B).trans (e₂₃ : B ≃ₗc[R] C), (e₁₂ : A ≃* B).trans (e₂₃ : B ≃* C) with } @[simp] theorem trans_toCoalgEquiv : (e₁₂.trans e₂₃ : A ≃ₗc[R] C) = (e₁₂ : A ≃ₗc[R] B).trans (e₂₃ : B ≃ₗc[R] C) := rfl @[simp] theorem trans_toBialgHom : (e₁₂.trans e₂₃ : A →ₐc[R] C) = (e₂₃ : B →ₐc[R] C).comp e₁₂ := rfl @[simp] theorem coe_toEquiv_trans : (e₁₂ : A ≃ B).trans e₂₃ = (e₁₂.trans e₂₃ : A ≃ C) := rfl end end BialgEquiv
RingTheory\Bialgebra\Hom.lean
/- Copyright (c) 2024 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Yury Kudryashov, Amelia Livingston -/ import Mathlib.RingTheory.Coalgebra.Hom import Mathlib.RingTheory.Bialgebra.Basic /-! # Homomorphisms of `R`-bialgebras This file defines bundled homomorphisms of `R`-bialgebras. We simply mimic `Mathlib/Algebra/Algebra/Hom.lean`. ## Main definitions * `BialgHom R A B`: the type of `R`-bialgebra morphisms from `A` to `B`. * `Bialgebra.counitBialgHom R A : A →ₐc[R] R`: the counit of a bialgebra as a bialgebra homomorphism. ## Notations * `A →ₐc[R] B` : `R`-bialgebra homomorphism from `A` to `B`. -/ open TensorProduct Bialgebra universe u v w /-- Given `R`-algebras `A, B` with comultiplication maps `Δ_A, Δ_B` and counit maps `ε_A, ε_B`, an `R`-bialgebra homomorphism `A →ₐc[R] B` is an `R`-algebra map `f` such that `ε_B ∘ f = ε_A` and `(f ⊗ f) ∘ Δ_A = Δ_B ∘ f`. -/ structure BialgHom (R A B : Type*) [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [CoalgebraStruct R A] [CoalgebraStruct R B] extends A →ₗc[R] B, A →* B /-- Reinterpret a `BialgHom` as a `MonoidHom` -/ add_decl_doc BialgHom.toMonoidHom @[inherit_doc BialgHom] infixr:25 " →ₐc " => BialgHom _ @[inherit_doc] notation:25 A " →ₐc[" R "] " B => BialgHom R A B /-- `BialgHomClass F R A B` asserts `F` is a type of bundled bialgebra homomorphisms from `A` to `B`. -/ class BialgHomClass (F : Type*) (R A B : outParam Type*) [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [CoalgebraStruct R A] [CoalgebraStruct R B] [FunLike F A B] extends CoalgHomClass F R A B, MonoidHomClass F A B : Prop namespace BialgHomClass variable {R A B F : Type*} section variable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [CoalgebraStruct R A] [CoalgebraStruct R B] [FunLike F A B] [BialgHomClass F R A B] instance (priority := 100) toAlgHomClass : AlgHomClass F R A B where map_mul := map_mul map_one := map_one map_add := map_add map_zero := map_zero commutes := fun c r => by simp only [Algebra.algebraMap_eq_smul_one, map_smul, _root_.map_one] /-- Turn an element of a type `F` satisfying `BialgHomClass F R A B` into an actual `BialgHom`. This is declared as the default coercion from `F` to `A →ₐc[R] B`. -/ @[coe] def toBialgHom (f : F) : A →ₐc[R] B := { CoalgHomClass.toCoalgHom f, AlgHomClass.toAlgHom f with toFun := f } instance instCoeToBialgHom : CoeHead F (A →ₐc[R] B) := ⟨BialgHomClass.toBialgHom⟩ end section variable [CommSemiring R] [Semiring A] [Bialgebra R A] [Semiring B] [Bialgebra R B] [FunLike F A B] [BialgHomClass F R A B] @[simp] theorem counitAlgHom_comp (f : F) : (counitAlgHom R B).comp (f : A →ₐ[R] B) = counitAlgHom R A := AlgHom.toLinearMap_injective (CoalgHomClass.counit_comp f) @[simp] theorem map_comp_comulAlgHom (f : F) : (Algebra.TensorProduct.map f f).comp (comulAlgHom R A) = (comulAlgHom R B).comp f := AlgHom.toLinearMap_injective (CoalgHomClass.map_comp_comul f) end end BialgHomClass namespace BialgHom variable {R A B C D : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C] [Semiring D] [Algebra 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 ⟨_, _⟩ simp_all instance bialgHomClass : BialgHomClass (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 map_mul := fun f => f.map_mul' map_one := fun f => f.map_one' /-- See Note [custom simps projection] -/ def Simps.apply {R α β : Type*} [CommSemiring R] [Semiring α] [Algebra R α] [Semiring β] [Algebra R β] [CoalgebraStruct R α] [CoalgebraStruct R β] (f : α →ₐc[R] β) : α → β := f initialize_simps_projections BialgHom (toFun → apply) @[simp] protected theorem coe_coe {F : Type*} [FunLike F A B] [BialgHomClass F R A B] (f : F) : ⇑(f : A →ₐc[R] B) = f := rfl @[simp] theorem coe_mk {f : A →ₗc[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₃ h₄ h₅) : ⇑(⟨⟨⟨⟨f, h₀⟩, h₁⟩, h₂, h₃⟩, h₄, h₅⟩ : A →ₐc[R] B) = f := rfl @[simp, norm_cast] theorem coe_coalgHom_mk {f : A →ₗc[R] B} (h h₁) : ((⟨f, h, h₁⟩ : A →ₐc[R] B) : A →ₗc[R] B) = f := by rfl @[norm_cast] theorem coe_toCoalgHom (f : A →ₐc[R] B) : ⇑(f : A →ₗc[R] B) = f := rfl @[simp, norm_cast] theorem coe_toLinearMap (f : A →ₐc[R] B) : ⇑(f : A →ₗ[R] B) = f := rfl @[norm_cast] theorem coe_toAlgHom (f : A →ₐc[R] B) : ⇑(f : A →ₐ[R] B) = f := rfl theorem toAlgHom_toLinearMap (f : A →ₐc[R] B) : ((f : A →ₐ[R] B) : A →ₗ[R] B) = f := by rfl variable (φ : A →ₐc[R] B) 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_coalgHom_injective : Function.Injective ((↑) : (A →ₐc[R] B) → A →ₗc[R] B) := fun φ₁ φ₂ H => coe_fn_injective <| show ((φ₁ : A →ₗc[R] B) : A → B) = ((φ₂ : A →ₗc[R] B) : A → B) from congr_arg _ H theorem coe_algHom_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_linearMap_injective : Function.Injective ((↑) : (A →ₐc[R] B) → A →ₗ[R] B) := CoalgHom.coe_linearMap_injective.comp coe_coalgHom_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₃ h₄ h₅) : (⟨⟨⟨⟨f, h₀⟩, h₁⟩, h₂, h₃⟩, h₄, h₅⟩ : A →ₐc[R] B) = f := rfl /-- Copy of a `BialgHom` 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 := { toCoalgHom := (f : A →ₗc[R] B).copy f' h map_one' := by simp_all map_mul' := by intros; simp_all } @[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 section variable (R A) /-- Identity map as a `BialgHom`. -/ @[simps!] protected def id : A →ₐc[R] A := { CoalgHom.id R A, AlgHom.id R A with } variable {R A} @[simp] theorem coe_id : ⇑(BialgHom.id R A) = id := rfl @[simp] theorem id_toCoalgHom : BialgHom.id R A = CoalgHom.id R A := rfl @[simp] theorem id_toAlgHom : BialgHom.id R A = AlgHom.id R A := rfl end /-- Composition of bialgebra homomorphisms. -/ @[simps!] def comp (φ₁ : B →ₐc[R] C) (φ₂ : A →ₐc[R] B) : A →ₐc[R] C := { (φ₁ : B →ₗc[R] C).comp (φ₂ : A →ₗc[R] B), (φ₁ : B →ₐ[R] C).comp (φ₂ : A →ₐ[R] B) with } @[simp] theorem coe_comp (φ₁ : B →ₐc[R] C) (φ₂ : A →ₐc[R] B) : ⇑(φ₁.comp φ₂) = φ₁ ∘ φ₂ := rfl @[simp] theorem comp_toCoalgHom (φ₁ : B →ₐc[R] C) (φ₂ : A →ₐc[R] B) : φ₁.comp φ₂ = (φ₁ : B →ₗc[R] C).comp (φ₂ : A →ₗc[R] B) := rfl @[simp] theorem comp_toAlgHom (φ₁ : B →ₐc[R] C) (φ₂ : A →ₐc[R] B) : φ₁.comp φ₂ = (φ₁ : B →ₐ[R] C).comp (φ₂ : A →ₐ[R] B) := rfl @[simp] theorem comp_id : φ.comp (BialgHom.id R A) = φ := ext fun _x => rfl @[simp] theorem id_comp : (BialgHom.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 (config := .lemmasOnly) toSemigroup_toMul_mul toOne_one] instance End : Monoid (A →ₐc[R] A) where mul := comp mul_assoc ϕ ψ χ := rfl one := BialgHom.id R A one_mul ϕ := ext fun x => rfl mul_one ϕ := ext fun x => 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 BialgHom namespace Bialgebra variable (R : Type u) (A : Type v) variable [CommSemiring R] [Semiring A] [Bialgebra R A] /-- The counit of a bialgebra as a `BialgHom`. -/ def counitBialgHom : A →ₐc[R] R := { Coalgebra.counitCoalgHom R A, counitAlgHom R A with } @[simp] theorem counitBialgHom_apply (x : A) : counitBialgHom R A x = Coalgebra.counit x := rfl @[simp] theorem counitBialgHom_toCoalgHom : counitBialgHom R A = Coalgebra.counitCoalgHom R A := rfl variable {R} instance subsingleton_to_ring : Subsingleton (A →ₐc[R] R) := ⟨fun _ _ => BialgHom.coe_coalgHom_injective (Subsingleton.elim _ _)⟩ @[ext high] theorem ext_to_ring (f g : A →ₐc[R] R) : f = g := Subsingleton.elim _ _ end Bialgebra
RingTheory\Coalgebra\Basic.lean
/- Copyright (c) 2023 Ali Ramsey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ali Ramsey, Eric Wieser -/ import Mathlib.Algebra.Algebra.Bilinear import Mathlib.LinearAlgebra.Finsupp import Mathlib.LinearAlgebra.Prod import Mathlib.LinearAlgebra.TensorProduct.Finiteness /-! # Coalgebras In this file we define `Coalgebra`, and provide instances for: * Commutative semirings: `CommSemiring.toCoalgebra` * Binary products: `Prod.instCoalgebra` * Finitely supported functions: `Finsupp.instCoalgebra` ## References * <https://en.wikipedia.org/wiki/Coalgebra> -/ suppress_compilation 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 /-- 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. -/ 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 index := TensorProduct.exists_finset (R := R) (CoalgebraStruct.comul a) |>.choose eq := TensorProduct.exists_finset (R := R) (CoalgebraStruct.comul a) |>.choose_spec.symm 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] @[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) end Coalgebra section CommSemiring 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 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] end Prod namespace Finsupp variable (R : Type u) (ι : Type v) (A : Type w) variable [CommSemiring R] [AddCommMonoid A] [Module R A] [Coalgebra R A] open LinearMap 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. -/ 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] end Finsupp end CommSemiring namespace TensorProduct open Coalgebra variable {R A B : Type*} [CommSemiring R] [AddCommMonoid A] [AddCommMonoid B] [Module R A] [Module R B] [CoalgebraStruct R A] [CoalgebraStruct R B] /-- The coalgebra instance will be defined in #11975, in `Mathlib.RingTheory.Coalgebra.TensorProduct`. -/ @[simps] instance instCoalgebraStruct : CoalgebraStruct R (A ⊗[R] B) where comul := TensorProduct.tensorTensorTensorComm R A A B B ∘ₗ TensorProduct.map comul comul counit := LinearMap.mul' R R ∘ₗ TensorProduct.map counit counit end TensorProduct
RingTheory\Coalgebra\Equiv.lean
/- Copyright (c) 2024 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston -/ 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`. ## Notations * `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] extends CoalgHomClass F R A B, SemilinearEquivClass F (RingHom.id R) A B : Prop 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 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) /-- 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 initialize_simps_projections CoalgEquiv (toFun → apply) @[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 section variable (A R) /-- The identity map is a coalgebra equivalence. -/ @[refl, simps!] def refl : A ≃ₗc[R] A := { CoalgHom.id R A, LinearEquiv.refl R A with } end @[simp] theorem refl_toLinearEquiv : refl R A = LinearEquiv.refl R A := rfl @[simp] theorem refl_toCoalgHom : refl R A = CoalgHom.id R A := rfl /-- 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 show (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] } @[simp] theorem symm_toLinearEquiv (e : A ≃ₗc[R] B) : e.symm = (e : A ≃ₗ[R] B).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 /-- 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 (invFun → symm_apply) @[simp] theorem invFun_eq_symm : e.invFun = e.symm := rfl @[simp] theorem coe_toEquiv_symm : 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 end end CoalgEquiv
RingTheory\Coalgebra\Hom.lean
/- Copyright (c) 2024 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Yury Kudryashov, Amelia Livingston -/ 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. ## Notations * `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] extends SemilinearMapClass F (RingHom.id R) A B : Prop 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 (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] 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 (config := .lemmasOnly) 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 x => rfl mul_one ϕ := ext fun x => 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`. -/ 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 [CoalgHom.toLinearMap_eq_coe, LinearMap.coe_comp, CoalgHom.coe_toLinearMap, Function.comp_apply, 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 @[simp] lemma sum_tmul_counit_apply_eq {F : Type*} [FunLike F A B] [CoalgHomClass F R A B] (φ : F) {a : A} (repr : Repr R a) : ∑ i ∈ repr.index, counit (R := R) (repr.left i) ⊗ₜ φ (repr.right i) = 1 ⊗ₜ[R] φ a := by simp [← sum_counit_tmul_eq (repr.induced φ)] @[simp] lemma sum_tmul_apply_counit_eq {F : Type*} [FunLike F A B] [CoalgHomClass F R A B] (φ : F) {a : A} (repr : Repr R a) : ∑ i ∈ repr.index, φ (repr.left i) ⊗ₜ counit (R := R) (repr.right i) = φ a ⊗ₜ[R] 1 := by simp [← sum_tmul_counit_eq (repr.induced φ)] end Coalgebra
RingTheory\Congruence\Basic.lean
/- Copyright (c) 2022 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.Ring.Action.Basic import Mathlib.Algebra.Ring.Hom.Defs import Mathlib.Algebra.Ring.InjSurj import Mathlib.GroupTheory.Congruence.Basic /-! # Congruence relations on rings This file defines congruence relations on rings, which extend `Con` and `AddCon` on monoids and additive monoids. Most of the time you likely want to use the `Ideal.Quotient` API that is built on top of this. ## Main Definitions * `RingCon R`: the type of congruence relations respecting `+` and `*`. * `RingConGen r`: the inductively defined smallest ring congruence relation containing a given binary relation. ## TODO * Use this for `RingQuot` too. * Copy across more API from `Con` and `AddCon` in `GroupTheory/Congruence.lean`. -/ /-- A congruence relation on a type with an addition and multiplication is an equivalence relation which preserves both. -/ structure RingCon (R : Type*) [Add R] [Mul R] extends Con R, AddCon R where /-- The induced multiplicative congruence from a `RingCon`. -/ add_decl_doc RingCon.toCon /-- The induced additive congruence from a `RingCon`. -/ add_decl_doc RingCon.toAddCon variable {α R : Type*} /-- The inductively defined smallest ring congruence relation containing a given binary relation. -/ inductive RingConGen.Rel [Add R] [Mul R] (r : R → R → Prop) : R → R → Prop | of : ∀ x y, r x y → RingConGen.Rel r x y | refl : ∀ x, RingConGen.Rel r x x | symm : ∀ {x y}, RingConGen.Rel r x y → RingConGen.Rel r y x | trans : ∀ {x y z}, RingConGen.Rel r x y → RingConGen.Rel r y z → RingConGen.Rel r x z | add : ∀ {w x y z}, RingConGen.Rel r w x → RingConGen.Rel r y z → RingConGen.Rel r (w + y) (x + z) | mul : ∀ {w x y z}, RingConGen.Rel r w x → RingConGen.Rel r y z → RingConGen.Rel r (w * y) (x * z) /-- The inductively defined smallest ring congruence relation containing a given binary relation. -/ def ringConGen [Add R] [Mul R] (r : R → R → Prop) : RingCon R where r := RingConGen.Rel r iseqv := ⟨RingConGen.Rel.refl, @RingConGen.Rel.symm _ _ _ _, @RingConGen.Rel.trans _ _ _ _⟩ add' := RingConGen.Rel.add mul' := RingConGen.Rel.mul namespace RingCon section Basic variable [Add R] [Mul R] (c : RingCon R) -- Porting note: upgrade to `FunLike` /-- A coercion from a congruence relation to its underlying binary relation. -/ instance : FunLike (RingCon R) R (R → Prop) := { coe := fun c => c.r, coe_injective' := fun x y h => by rcases x with ⟨⟨x, _⟩, _⟩ rcases y with ⟨⟨y, _⟩, _⟩ congr! rw [Setoid.ext_iff,(show x.Rel = y.Rel from h)] simp} theorem rel_eq_coe : c.r = c := rfl @[simp] theorem toCon_coe_eq_coe : (c.toCon : R → R → Prop) = c := rfl protected theorem refl (x) : c x x := c.refl' x protected theorem symm {x y} : c x y → c y x := c.symm' protected theorem trans {x y z} : c x y → c y z → c x z := c.trans' protected theorem add {w x y z} : c w x → c y z → c (w + y) (x + z) := c.add' protected theorem mul {w x y z} : c w x → c y z → c (w * y) (x * z) := c.mul' protected theorem sub {S : Type*} [AddGroup S] [Mul S] (t : RingCon S) {a b c d : S} (h : t a b) (h' : t c d) : t (a - c) (b - d) := t.toAddCon.sub h h' protected theorem neg {S : Type*} [AddGroup S] [Mul S] (t : RingCon S) {a b} (h : t a b) : t (-a) (-b) := t.toAddCon.neg h protected theorem nsmul {S : Type*} [AddGroup S] [Mul S] (t : RingCon S) (m : ℕ) {x y : S} (hx : t x y) : t (m • x) (m • y) := t.toAddCon.nsmul m hx protected theorem zsmul {S : Type*} [AddGroup S] [Mul S] (t : RingCon S) (z : ℤ) {x y : S} (hx : t x y) : t (z • x) (z • y) := t.toAddCon.zsmul z hx instance : Inhabited (RingCon R) := ⟨ringConGen EmptyRelation⟩ @[simp] theorem rel_mk {s : Con R} {h a b} : RingCon.mk s h a b ↔ s a b := Iff.rfl /-- The map sending a congruence relation to its underlying binary relation is injective. -/ theorem ext' {c d : RingCon R} (H : ⇑c = ⇑d) : c = d := DFunLike.coe_injective H /-- Extensionality rule for congruence relations. -/ theorem ext {c d : RingCon R} (H : ∀ x y, c x y ↔ d x y) : c = d := ext' <| by ext; apply H end Basic section Quotient section Basic variable [Add R] [Mul R] (c : RingCon R) /-- Defining the quotient by a congruence relation of a type with addition and multiplication. -/ protected def Quotient := Quotient c.toSetoid variable {c} /-- The morphism into the quotient by a congruence relation -/ @[coe] def toQuotient (r : R) : c.Quotient := @Quotient.mk'' _ c.toSetoid r variable (c) /-- Coercion from a type with addition and multiplication to its quotient by a congruence relation. See Note [use has_coe_t]. -/ instance : CoeTC R c.Quotient := ⟨toQuotient⟩ -- Lower the priority since it unifies with any quotient type. /-- The quotient by a decidable congruence relation has decidable equality. -/ instance (priority := 500) [_d : ∀ a b, Decidable (c a b)] : DecidableEq c.Quotient := inferInstanceAs (DecidableEq (Quotient c.toSetoid)) @[simp] theorem quot_mk_eq_coe (x : R) : Quot.mk c x = (x : c.Quotient) := rfl /-- Two elements are related by a congruence relation `c` iff they are represented by the same element of the quotient by `c`. -/ @[simp] protected theorem eq {a b : R} : (a : c.Quotient) = (b : c.Quotient) ↔ c a b := Quotient.eq'' end Basic /-! ### Basic notation The basic algebraic notation, `0`, `1`, `+`, `*`, `-`, `^`, descend naturally under the quotient -/ section Data section add_mul variable [Add R] [Mul R] (c : RingCon R) instance : Add c.Quotient := inferInstanceAs (Add c.toAddCon.Quotient) @[simp, norm_cast] theorem coe_add (x y : R) : (↑(x + y) : c.Quotient) = ↑x + ↑y := rfl instance : Mul c.Quotient := inferInstanceAs (Mul c.toCon.Quotient) @[simp, norm_cast] theorem coe_mul (x y : R) : (↑(x * y) : c.Quotient) = ↑x * ↑y := rfl end add_mul section Zero variable [AddZeroClass R] [Mul R] (c : RingCon R) instance : Zero c.Quotient := inferInstanceAs (Zero c.toAddCon.Quotient) @[simp, norm_cast] theorem coe_zero : (↑(0 : R) : c.Quotient) = 0 := rfl end Zero section One variable [Add R] [MulOneClass R] (c : RingCon R) instance : One c.Quotient := inferInstanceAs (One c.toCon.Quotient) @[simp, norm_cast] theorem coe_one : (↑(1 : R) : c.Quotient) = 1 := rfl end One section SMul variable [Add R] [MulOneClass R] [SMul α R] [IsScalarTower α R R] (c : RingCon R) instance : SMul α c.Quotient := inferInstanceAs (SMul α c.toCon.Quotient) @[simp, norm_cast] theorem coe_smul (a : α) (x : R) : (↑(a • x) : c.Quotient) = a • (x : c.Quotient) := rfl end SMul section NegSubZSMul variable [AddGroup R] [Mul R] (c : RingCon R) instance : Neg c.Quotient := inferInstanceAs (Neg c.toAddCon.Quotient) @[simp, norm_cast] theorem coe_neg (x : R) : (↑(-x) : c.Quotient) = -x := rfl instance : Sub c.Quotient := inferInstanceAs (Sub c.toAddCon.Quotient) @[simp, norm_cast] theorem coe_sub (x y : R) : (↑(x - y) : c.Quotient) = x - y := rfl instance hasZSMul : SMul ℤ c.Quotient := inferInstanceAs (SMul ℤ c.toAddCon.Quotient) @[simp, norm_cast] theorem coe_zsmul (z : ℤ) (x : R) : (↑(z • x) : c.Quotient) = z • (x : c.Quotient) := rfl end NegSubZSMul section NSMul variable [AddMonoid R] [Mul R] (c : RingCon R) instance hasNSMul : SMul ℕ c.Quotient := inferInstanceAs (SMul ℕ c.toAddCon.Quotient) @[simp, norm_cast] theorem coe_nsmul (n : ℕ) (x : R) : (↑(n • x) : c.Quotient) = n • (x : c.Quotient) := rfl end NSMul section Pow variable [Add R] [Monoid R] (c : RingCon R) instance : Pow c.Quotient ℕ := inferInstanceAs (Pow c.toCon.Quotient ℕ) @[simp, norm_cast] theorem coe_pow (x : R) (n : ℕ) : (↑(x ^ n) : c.Quotient) = (x : c.Quotient) ^ n := rfl end Pow section NatCast variable [AddMonoidWithOne R] [Mul R] (c : RingCon R) instance : NatCast c.Quotient := ⟨fun n => ↑(n : R)⟩ @[simp, norm_cast] theorem coe_natCast (n : ℕ) : (↑(n : R) : c.Quotient) = n := rfl @[deprecated (since := "2024-04-17")] alias coe_nat_cast := coe_natCast end NatCast section IntCast variable [AddGroupWithOne R] [Mul R] (c : RingCon R) instance : IntCast c.Quotient := ⟨fun z => ↑(z : R)⟩ @[simp, norm_cast] theorem coe_intCast (n : ℕ) : (↑(n : R) : c.Quotient) = n := rfl @[deprecated (since := "2024-04-17")] alias coe_int_cast := coe_intCast end IntCast instance [Inhabited R] [Add R] [Mul R] (c : RingCon R) : Inhabited c.Quotient := ⟨↑(default : R)⟩ end Data /-! ### Algebraic structure The operations above on the quotient by `c : RingCon R` preserve the algebraic structure of `R`. -/ section Algebraic instance [NonUnitalNonAssocSemiring R] (c : RingCon R) : NonUnitalNonAssocSemiring c.Quotient := Function.Surjective.nonUnitalNonAssocSemiring _ Quotient.surjective_Quotient_mk'' rfl (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl instance [NonAssocSemiring R] (c : RingCon R) : NonAssocSemiring c.Quotient := Function.Surjective.nonAssocSemiring _ Quotient.surjective_Quotient_mk'' rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl instance [NonUnitalSemiring R] (c : RingCon R) : NonUnitalSemiring c.Quotient := Function.Surjective.nonUnitalSemiring _ Quotient.surjective_Quotient_mk'' rfl (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl instance [Semiring R] (c : RingCon R) : Semiring c.Quotient := Function.Surjective.semiring _ Quotient.surjective_Quotient_mk'' rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl instance [CommSemiring R] (c : RingCon R) : CommSemiring c.Quotient := Function.Surjective.commSemiring _ Quotient.surjective_Quotient_mk'' rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl instance [NonUnitalNonAssocRing R] (c : RingCon R) : NonUnitalNonAssocRing c.Quotient := Function.Surjective.nonUnitalNonAssocRing _ Quotient.surjective_Quotient_mk'' rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl instance [NonAssocRing R] (c : RingCon R) : NonAssocRing c.Quotient := Function.Surjective.nonAssocRing _ Quotient.surjective_Quotient_mk'' rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) fun _ => rfl instance [NonUnitalRing R] (c : RingCon R) : NonUnitalRing c.Quotient := Function.Surjective.nonUnitalRing _ Quotient.surjective_Quotient_mk'' rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl instance [Ring R] (c : RingCon R) : Ring c.Quotient := Function.Surjective.ring _ Quotient.surjective_Quotient_mk'' rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) fun _ => rfl instance [CommRing R] (c : RingCon R) : CommRing c.Quotient := Function.Surjective.commRing _ Quotient.surjective_Quotient_mk'' rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) fun _ => rfl instance isScalarTower_right [Add R] [MulOneClass R] [SMul α R] [IsScalarTower α R R] (c : RingCon R) : IsScalarTower α c.Quotient c.Quotient where smul_assoc _ := Quotient.ind₂' fun _ _ => congr_arg Quotient.mk'' <| smul_mul_assoc _ _ _ instance smulCommClass [Add R] [MulOneClass R] [SMul α R] [IsScalarTower α R R] [SMulCommClass α R R] (c : RingCon R) : SMulCommClass α c.Quotient c.Quotient where smul_comm _ := Quotient.ind₂' fun _ _ => congr_arg Quotient.mk'' <| (mul_smul_comm _ _ _).symm instance smulCommClass' [Add R] [MulOneClass R] [SMul α R] [IsScalarTower α R R] [SMulCommClass R α R] (c : RingCon R) : SMulCommClass c.Quotient α c.Quotient := haveI := SMulCommClass.symm R α R SMulCommClass.symm _ _ _ instance [Monoid α] [NonAssocSemiring R] [DistribMulAction α R] [IsScalarTower α R R] (c : RingCon R) : DistribMulAction α c.Quotient := { c.toCon.mulAction with smul_zero := fun _ => congr_arg toQuotient <| smul_zero _ smul_add := fun _ => Quotient.ind₂' fun _ _ => congr_arg toQuotient <| smul_add _ _ _ } instance [Monoid α] [Semiring R] [MulSemiringAction α R] [IsScalarTower α R R] (c : RingCon R) : MulSemiringAction α c.Quotient := { smul_one := fun _ => congr_arg toQuotient <| smul_one _ smul_mul := fun _ => Quotient.ind₂' fun _ _ => congr_arg toQuotient <| MulSemiringAction.smul_mul _ _ _ } end Algebraic /-- The natural homomorphism from a ring to its quotient by a congruence relation. -/ def mk' [NonAssocSemiring R] (c : RingCon R) : R →+* c.Quotient where toFun := toQuotient map_zero' := rfl map_one' := rfl map_add' _ _ := rfl map_mul' _ _ := rfl end Quotient /-! ### Lattice structure The API in this section is copied from `Mathlib/GroupTheory/Congruence.lean` -/ section Lattice variable [Add R] [Mul R] /-- For congruence relations `c, d` on a type `M` with multiplication and addition, `c ≤ d` iff `∀ x y ∈ M`, `x` is related to `y` by `d` if `x` is related to `y` by `c`. -/ instance : LE (RingCon R) where le c d := ∀ ⦃x y⦄, c x y → d x y /-- Definition of `≤` for congruence relations. -/ theorem le_def {c d : RingCon R} : c ≤ d ↔ ∀ {x y}, c x y → d x y := Iff.rfl /-- The infimum of a set of congruence relations on a given type with multiplication and addition. -/ instance : InfSet (RingCon R) where sInf S := { r := fun x y => ∀ c : RingCon R, c ∈ S → c x y iseqv := ⟨fun x c _hc => c.refl x, fun h c hc => c.symm <| h c hc, fun h1 h2 c hc => c.trans (h1 c hc) <| h2 c hc⟩ add' := fun h1 h2 c hc => c.add (h1 c hc) <| h2 c hc mul' := fun h1 h2 c hc => c.mul (h1 c hc) <| h2 c hc } /-- The infimum of a set of congruence relations is the same as the infimum of the set's image under the map to the underlying equivalence relation. -/ theorem sInf_toSetoid (S : Set (RingCon R)) : (sInf S).toSetoid = sInf ((·.toSetoid) '' S) := Setoid.ext' fun x y => ⟨fun h r ⟨c, hS, hr⟩ => by rw [← hr]; exact h c hS, fun h c hS => h c.toSetoid ⟨c, hS, rfl⟩⟩ /-- The infimum of a set of congruence relations is the same as the infimum of the set's image under the map to the underlying binary relation. -/ @[simp, norm_cast] theorem coe_sInf (S : Set (RingCon R)) : ⇑(sInf S) = sInf ((⇑) '' S) := by ext; simp only [sInf_image, iInf_apply, iInf_Prop_eq]; rfl @[simp, norm_cast] theorem coe_iInf {ι : Sort*} (f : ι → RingCon R) : ⇑(iInf f) = ⨅ i, ⇑(f i) := by rw [iInf, coe_sInf, ← Set.range_comp, sInf_range, Function.comp] instance : PartialOrder (RingCon R) where le_refl _c _ _ := id le_trans _c1 _c2 _c3 h1 h2 _x _y h := h2 <| h1 h le_antisymm _c _d hc hd := ext fun _x _y => ⟨fun h => hc h, fun h => hd h⟩ /-- The complete lattice of congruence relations on a given type with multiplication and addition. -/ instance : CompleteLattice (RingCon R) where __ := completeLatticeOfInf (RingCon R) fun s => ⟨fun r hr x y h => (h : ∀ r ∈ s, (r : RingCon R) x y) r hr, fun _r hr _x _y h _r' hr' => hr hr' h⟩ inf c d := { toSetoid := c.toSetoid ⊓ d.toSetoid mul' := fun h1 h2 => ⟨c.mul h1.1 h2.1, d.mul h1.2 h2.2⟩ add' := fun h1 h2 => ⟨c.add h1.1 h2.1, d.add h1.2 h2.2⟩ } inf_le_left _ _ := fun _ _ h => h.1 inf_le_right _ _ := fun _ _ h => h.2 le_inf _ _ _ hb hc := fun _ _ h => ⟨hb h, hc h⟩ top := { (⊤ : Setoid R) with mul' := fun _ _ => trivial add' := fun _ _ => trivial } le_top _ := fun _ _ _h => trivial bot := { (⊥ : Setoid R) with mul' := congr_arg₂ _ add' := congr_arg₂ _ } bot_le c := fun x _y h => h ▸ c.refl x @[simp, norm_cast] theorem coe_top : ⇑(⊤ : RingCon R) = ⊤ := rfl @[simp, norm_cast] theorem coe_bot : ⇑(⊥ : RingCon R) = Eq := rfl /-- The infimum of two congruence relations equals the infimum of the underlying binary operations. -/ @[simp, norm_cast] theorem coe_inf {c d : RingCon R} : ⇑(c ⊓ d) = ⇑c ⊓ ⇑d := rfl /-- Definition of the infimum of two congruence relations. -/ theorem inf_iff_and {c d : RingCon R} {x y} : (c ⊓ d) x y ↔ c x y ∧ d x y := Iff.rfl instance [Nontrivial R] : Nontrivial (RingCon R) where exists_pair_ne := let ⟨x, y, ne⟩ := exists_pair_ne R ⟨⊥, ⊤, ne_of_apply_ne (· x y) <| by simp [ne]⟩ /-- The inductively defined smallest congruence relation containing a binary relation `r` equals the infimum of the set of congruence relations containing `r`. -/ theorem ringConGen_eq (r : R → R → Prop) : ringConGen r = sInf {s : RingCon R | ∀ x y, r x y → s x y} := le_antisymm (fun _x _y H => RingConGen.Rel.recOn H (fun _ _ h _ hs => hs _ _ h) (RingCon.refl _) (fun _ => RingCon.symm _) (fun _ _ => RingCon.trans _) (fun _ _ h1 h2 c hc => c.add (h1 c hc) <| h2 c hc) (fun _ _ h1 h2 c hc => c.mul (h1 c hc) <| h2 c hc)) (sInf_le fun _ _ => RingConGen.Rel.of _ _) /-- The smallest congruence relation containing a binary relation `r` is contained in any congruence relation containing `r`. -/ theorem ringConGen_le {r : R → R → Prop} {c : RingCon R} (h : ∀ x y, r x y → c x y) : ringConGen r ≤ c := by rw [ringConGen_eq]; exact sInf_le h /-- Given binary relations `r, s` with `r` contained in `s`, the smallest congruence relation containing `s` contains the smallest congruence relation containing `r`. -/ theorem ringConGen_mono {r s : R → R → Prop} (h : ∀ x y, r x y → s x y) : ringConGen r ≤ ringConGen s := ringConGen_le fun x y hr => RingConGen.Rel.of _ _ <| h x y hr /-- Congruence relations equal the smallest congruence relation in which they are contained. -/ theorem ringConGen_of_ringCon (c : RingCon R) : ringConGen c = c := le_antisymm (by rw [ringConGen_eq]; exact sInf_le fun _ _ => id) RingConGen.Rel.of /-- The map sending a binary relation to the smallest congruence relation in which it is contained is idempotent. -/ theorem ringConGen_idem (r : R → R → Prop) : ringConGen (ringConGen r) = ringConGen r := ringConGen_of_ringCon _ /-- The supremum of congruence relations `c, d` equals the smallest congruence relation containing the binary relation '`x` is related to `y` by `c` or `d`'. -/ theorem sup_eq_ringConGen (c d : RingCon R) : c ⊔ d = ringConGen fun x y => c x y ∨ d x y := by rw [ringConGen_eq] apply congr_arg sInf simp only [le_def, or_imp, ← forall_and] /-- The supremum of two congruence relations equals the smallest congruence relation containing the supremum of the underlying binary operations. -/ theorem sup_def {c d : RingCon R} : c ⊔ d = ringConGen (⇑c ⊔ ⇑d) := by rw [sup_eq_ringConGen]; rfl /-- The supremum of a set of congruence relations `S` equals the smallest congruence relation containing the binary relation 'there exists `c ∈ S` such that `x` is related to `y` by `c`'. -/ theorem sSup_eq_ringConGen (S : Set (RingCon R)) : sSup S = ringConGen fun x y => ∃ c : RingCon R, c ∈ S ∧ c x y := by rw [ringConGen_eq] apply congr_arg sInf ext exact ⟨fun h _ _ ⟨r, hr⟩ => h hr.1 hr.2, fun h r hS _ _ hr => h _ _ ⟨r, hS, hr⟩⟩ /-- The supremum of a set of congruence relations is the same as the smallest congruence relation containing the supremum of the set's image under the map to the underlying binary relation. -/ theorem sSup_def {S : Set (RingCon R)} : sSup S = ringConGen (sSup (@Set.image (RingCon R) (R → R → Prop) (⇑) S)) := by rw [sSup_eq_ringConGen, sSup_image] congr with (x y) simp only [sSup_image, iSup_apply, iSup_Prop_eq, exists_prop, rel_eq_coe] variable (R) /-- There is a Galois insertion of congruence relations on a type with multiplication and addition `R` into binary relations on `R`. -/ protected def gi : @GaloisInsertion (R → R → Prop) (RingCon R) _ _ ringConGen (⇑) where choice r _h := ringConGen r gc _r c := ⟨fun H _ _ h => H <| RingConGen.Rel.of _ _ h, fun H => ringConGen_of_ringCon c ▸ ringConGen_mono H⟩ le_l_u x := (ringConGen_of_ringCon x).symm ▸ le_refl x choice_eq _ _ := rfl end Lattice end RingCon
RingTheory\Congruence\BigOperators.lean
/- Copyright (c) 2022 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.GroupTheory.Congruence.BigOperators import Mathlib.RingTheory.Congruence.Basic /-! # Interactions between `∑, ∏` and `RingCon` -/ namespace RingCon /-- Congruence relation of a ring preserves finite sum indexed by a list. -/ protected lemma listSum {ι S : Type*} [AddMonoid S] [Mul S] (t : RingCon S) (l : List ι) {f g : ι → S} (h : ∀ i ∈ l, t (f i) (g i)) : t (l.map f).sum (l.map g).sum := t.toAddCon.list_sum h /-- Congruence relation of a ring preserves finite sum indexed by a multiset. -/ protected lemma multisetSum {ι S : Type*} [AddCommMonoid S] [Mul S] (t : RingCon S) (s : Multiset ι) {f g : ι → S} (h : ∀ i ∈ s, t (f i) (g i)) : t (s.map f).sum (s.map g).sum := t.toAddCon.multiset_sum h /-- Congruence relation of a ring preserves finite sum. -/ protected lemma finsetSum {ι S : Type*} [AddCommMonoid S] [Mul S] (t : RingCon S) (s : Finset ι) {f g : ι → S} (h : ∀ i ∈ s, t (f i) (g i)) : t (s.sum f) (s.sum g) := t.toAddCon.finset_sum s h end RingCon
RingTheory\Congruence\Opposite.lean
/- Copyright (c) 2022 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ 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 left_inv _ := rfl right_inv _ := rfl map_rel_iff' {c d} := by rw [le_def, le_def]; constructor <;> intro h _ _ h' <;> exact h h' end RingCon
RingTheory\Coprime\Basic.lean
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Ken Lee, Chris Hughes -/ import Mathlib.Algebra.GroupWithZero.Action.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 : 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} @[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⟩ => isUnit_of_mul_eq_one x (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⟩ => isUnit_of_mul_eq_one x 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 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, inv_mul_self, 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 : 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_left (hu : IsUnit x) (y z : R) : IsCoprime (x * y) (x * z) ↔ IsCoprime y z := (isCoprime_mul_unit_left_left hu y (x * z)).trans (isCoprime_mul_unit_left_right hu 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_unit_right (hu : IsUnit x) (y z : R) : IsCoprime (y * x) (z * x) ↔ IsCoprime y z := (isCoprime_mul_unit_right_left hu y (z * x)).trans (isCoprime_mul_unit_right_right hu y z) 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 _ _) end CommRing theorem sq_add_sq_ne_zero {R : Type*} [LinearOrderedCommRing R] {a b : R} (h : IsCoprime a b) : a ^ 2 + b ^ 2 ≠ 0 := by intro h' obtain ⟨ha, hb⟩ := (add_eq_zero_iff' (sq_nonneg _) (sq_nonneg _)).mp h' obtain rfl := pow_eq_zero ha obtain rfl := pow_eq_zero hb exact not_isCoprime_zero_zero h end IsCoprime 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
RingTheory\Coprime\Ideal.lean
/- Copyright (c) 2022 Pierre-Alexandre Bazin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Pierre-Alexandre Bazin -/ import Mathlib.LinearAlgebra.DFinsupp 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_iff] refine fun a => ⟨fun i => if h : i = a then ⟨1, ?_⟩ else 0, ?_⟩ · simp [h] · simp only [dif_pos, dif_ctx_congr, Submodule.coe_mk, eq_self_iff_true] 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μ -- Porting note: `refine` yields goals in a different order than in lean3. 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
RingTheory\Coprime\Lemmas.lean
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Ken Lee, Chris Hughes -/ import Mathlib.Algebra.BigOperators.Ring 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 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⟩ have : 1 = m * a + n * b := by rwa [mul_comm m, mul_comm n, eq_comm] exact Nat.dvd_one.mp (Int.gcd_dvd_iff.mpr ⟨a, b, this⟩) · rw [← Int.ofNat_inj, IsCoprime, Int.gcd_eq_gcd_ab, mul_comm m, mul_comm n, Nat.cast_one] intro h exact ⟨_, _, h⟩ 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.nat_coprime, Nat.Coprime.isCoprime⟩ := Nat.isCoprime_iff_coprime theorem Nat.Coprime.cast {R : Type*} [CommRing R] {a b : ℕ} (h : Nat.Coprime a b) : IsCoprime (a : R) (b : R) := by rw [← isCoprime_iff_coprime] at h rw [← Int.cast_natCast a, ← Int.cast_natCast b] exact IsCoprime.intCast h 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 : (∀ i ∈ t, IsCoprime (s i) x) → IsCoprime (∏ i ∈ t, s i) x := by classical refine Finset.induction_on t (fun _ ↦ isCoprime_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 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 -- Porting note: removed names of things due to linter, but they seem helpful theorem Finset.prod_dvd_of_coprime : (t : Set I).Pairwise (IsCoprime 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 (IsCoprime.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_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 dsimp -- Porting note: terms were showing as sort of `HAdd.hadd` instead of `+` -- this whole proof pretty much breaks and has to be rewritten from scratch rw [add_mul] congr 1 · 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] · rw [mul_assoc] congr rw [prod_eq_prod_diff_singleton_mul (mem x hx) _, mul_comm] congr 2 rw [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, if_pos rfl, ← 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 [Function.onFun, pairwise_subtype_iff_pairwise_finset', coe_univ, Set.pairwise_univ] -- Porting note: a lot of the capitalization wasn't working 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 refine ⟨fun hp i hi ↦ IsCoprime.prod_right_iff.mpr fun j hj ↦ ?_, fun hp ↦ ?_⟩ · rw [Finset.mem_sdiff, Finset.mem_singleton] at hj obtain ⟨hj, ji⟩ := hj refine @hp ⟨i, hi⟩ ⟨j, hj⟩ fun h ↦ ji (congrArg Subtype.val h).symm -- Porting note: is there a better way compared to the old `congr_arg coe h`? · rintro ⟨i, hi⟩ ⟨j, hj⟩ h apply IsCoprime.prod_right_iff.mp (hp i hi) exact Finset.mem_sdiff.mpr ⟨hj, fun f ↦ h <| Subtype.ext (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) exact Finset.mem_sdiff.mpr ⟨hj, fun f ↦ h <| Subtype.ext (Finset.mem_singleton.mp f).symm⟩ 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
RingTheory\DedekindDomain\AdicValuation.lean
/- Copyright (c) 2022 María Inés de Frutos-Fernández. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: María Inés de Frutos-Fernández -/ import Mathlib.RingTheory.DedekindDomain.Ideal import Mathlib.RingTheory.Valuation.ExtendToLocalization import Mathlib.RingTheory.Valuation.ValuationSubring import Mathlib.Topology.Algebra.Valued.ValuedField import Mathlib.Algebra.Order.Group.TypeTags /-! # Adic valuations on Dedekind domains Given a Dedekind domain `R` of Krull dimension 1 and a maximal ideal `v` of `R`, we define the `v`-adic valuation on `R` and its extension to the field of fractions `K` of `R`. We prove several properties of this valuation, including the existence of uniformizers. We define the completion of `K` with respect to the `v`-adic valuation, denoted `v.adicCompletion`, and its ring of integers, denoted `v.adicCompletionIntegers`. ## Main definitions - `IsDedekindDomain.HeightOneSpectrum.intValuation v` is the `v`-adic valuation on `R`. - `IsDedekindDomain.HeightOneSpectrum.valuation v` is the `v`-adic valuation on `K`. - `IsDedekindDomain.HeightOneSpectrum.adicCompletion v` is the completion of `K` with respect to its `v`-adic valuation. - `IsDedekindDomain.HeightOneSpectrum.adicCompletionIntegers v` is the ring of integers of `v.adicCompletion`. ## Main results - `IsDedekindDomain.HeightOneSpectrum.intValuation_le_one` : The `v`-adic valuation on `R` is bounded above by 1. - `IsDedekindDomain.HeightOneSpectrum.intValuation_lt_one_iff_dvd` : The `v`-adic valuation of `r ∈ R` is less than 1 if and only if `v` divides the ideal `(r)`. - `IsDedekindDomain.HeightOneSpectrum.intValuation_le_pow_iff_dvd` : The `v`-adic valuation of `r ∈ R` is less than or equal to `Multiplicative.ofAdd (-n)` if and only if `vⁿ` divides the ideal `(r)`. - `IsDedekindDomain.HeightOneSpectrum.intValuation_exists_uniformizer` : There exists `π ∈ R` with `v`-adic valuation `Multiplicative.ofAdd (-1)`. - `IsDedekindDomain.HeightOneSpectrum.valuation_of_mk'` : The `v`-adic valuation of `r/s ∈ K` is the valuation of `r` divided by the valuation of `s`. - `IsDedekindDomain.HeightOneSpectrum.valuation_of_algebraMap` : The `v`-adic valuation on `K` extends the `v`-adic valuation on `R`. - `IsDedekindDomain.HeightOneSpectrum.valuation_exists_uniformizer` : There exists `π ∈ K` with `v`-adic valuation `Multiplicative.ofAdd (-1)`. ## Implementation notes We are only interested in Dedekind domains with Krull dimension 1. ## References * [G. J. Janusz, *Algebraic Number Fields*][janusz1996] * [J.W.S. Cassels, A. Frölich, *Algebraic Number Theory*][cassels1967algebraic] * [J. Neukirch, *Algebraic Number Theory*][Neukirch1992] ## Tags dedekind domain, dedekind ring, adic valuation -/ noncomputable section open scoped Classical DiscreteValuation open Multiplicative IsDedekindDomain variable {R : Type*} [CommRing R] [IsDedekindDomain R] {K : Type*} [Field K] [Algebra R K] [IsFractionRing R K] (v : HeightOneSpectrum R) namespace IsDedekindDomain.HeightOneSpectrum /-! ### Adic valuations on the Dedekind domain R -/ /-- The additive `v`-adic valuation of `r ∈ R` is the exponent of `v` in the factorization of the ideal `(r)`, if `r` is nonzero, or infinity, if `r = 0`. `intValuationDef` is the corresponding multiplicative valuation. -/ def intValuationDef (r : R) : ℤₘ₀ := if r = 0 then 0 else ↑(Multiplicative.ofAdd (-(Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {r} : Ideal R)).factors : ℤ)) theorem intValuationDef_if_pos {r : R} (hr : r = 0) : v.intValuationDef r = 0 := if_pos hr @[simp] theorem intValuationDef_zero : v.intValuationDef 0 = 0 := if_pos rfl theorem intValuationDef_if_neg {r : R} (hr : r ≠ 0) : v.intValuationDef r = Multiplicative.ofAdd (-(Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {r} : Ideal R)).factors : ℤ) := if_neg hr /-- Nonzero elements have nonzero adic valuation. -/ theorem intValuation_ne_zero (x : R) (hx : x ≠ 0) : v.intValuationDef x ≠ 0 := by rw [intValuationDef, if_neg hx] exact WithZero.coe_ne_zero @[deprecated (since := "2024-07-09")] alias int_valuation_ne_zero := intValuation_ne_zero /-- Nonzero divisors have nonzero valuation. -/ theorem intValuation_ne_zero' (x : nonZeroDivisors R) : v.intValuationDef x ≠ 0 := v.intValuation_ne_zero x (nonZeroDivisors.coe_ne_zero x) @[deprecated (since := "2024-07-09")] alias int_valuation_ne_zero' := intValuation_ne_zero' /-- Nonzero divisors have valuation greater than zero. -/ theorem intValuation_zero_le (x : nonZeroDivisors R) : 0 < v.intValuationDef x := by rw [v.intValuationDef_if_neg (nonZeroDivisors.coe_ne_zero x)] exact WithZero.zero_lt_coe _ @[deprecated (since := "2024-07-09")] alias int_valuation_zero_le := intValuation_zero_le /-- The `v`-adic valuation on `R` is bounded above by 1. -/ theorem intValuation_le_one (x : R) : v.intValuationDef x ≤ 1 := by rw [intValuationDef] by_cases hx : x = 0 · rw [if_pos hx]; exact WithZero.zero_le 1 · rw [if_neg hx, ← WithZero.coe_one, ← ofAdd_zero, WithZero.coe_le_coe, ofAdd_le, Right.neg_nonpos_iff] exact Int.natCast_nonneg _ @[deprecated (since := "2024-07-09")] alias int_valuation_le_one := intValuation_le_one /-- The `v`-adic valuation of `r ∈ R` is less than 1 if and only if `v` divides the ideal `(r)`. -/ theorem intValuation_lt_one_iff_dvd (r : R) : v.intValuationDef r < 1 ↔ v.asIdeal ∣ Ideal.span {r} := by rw [intValuationDef] split_ifs with hr · simp [hr] · rw [← WithZero.coe_one, ← ofAdd_zero, WithZero.coe_lt_coe, ofAdd_lt, neg_lt_zero, ← Int.ofNat_zero, Int.ofNat_lt, zero_lt_iff] have h : (Ideal.span {r} : Ideal R) ≠ 0 := by rw [Ne, Ideal.zero_eq_bot, Ideal.span_singleton_eq_bot] exact hr apply Associates.count_ne_zero_iff_dvd h (by apply v.irreducible) @[deprecated (since := "2024-07-09")] alias int_valuation_lt_one_iff_dvd := intValuation_lt_one_iff_dvd /-- The `v`-adic valuation of `r ∈ R` is less than `Multiplicative.ofAdd (-n)` if and only if `vⁿ` divides the ideal `(r)`. -/ theorem intValuation_le_pow_iff_dvd (r : R) (n : ℕ) : v.intValuationDef r ≤ Multiplicative.ofAdd (-(n : ℤ)) ↔ v.asIdeal ^ n ∣ Ideal.span {r} := by rw [intValuationDef] split_ifs with hr · simp_rw [hr, Ideal.dvd_span_singleton, zero_le', Submodule.zero_mem] · rw [WithZero.coe_le_coe, ofAdd_le, neg_le_neg_iff, Int.ofNat_le, Ideal.dvd_span_singleton, ← Associates.le_singleton_iff, Associates.prime_pow_dvd_iff_le (Associates.mk_ne_zero'.mpr hr) (by apply v.associates_irreducible)] @[deprecated (since := "2024-07-09")] alias int_valuation_le_pow_iff_dvd := intValuation_le_pow_iff_dvd /-- The `v`-adic valuation of `0 : R` equals 0. -/ theorem intValuation.map_zero' : v.intValuationDef 0 = 0 := v.intValuationDef_if_pos (Eq.refl 0) @[deprecated (since := "2024-07-09")] alias IntValuation.map_zero' := intValuation.map_zero' /-- The `v`-adic valuation of `1 : R` equals 1. -/ theorem intValuation.map_one' : v.intValuationDef 1 = 1 := by rw [v.intValuationDef_if_neg (zero_ne_one.symm : (1 : R) ≠ 0), Ideal.span_singleton_one, ← Ideal.one_eq_top, Associates.mk_one, Associates.factors_one, Associates.count_zero (by apply v.associates_irreducible), Int.ofNat_zero, neg_zero, ofAdd_zero, WithZero.coe_one] @[deprecated (since := "2024-07-09")] alias IntValuation.map_one' := intValuation.map_one' /-- The `v`-adic valuation of a product equals the product of the valuations. -/ theorem intValuation.map_mul' (x y : R) : v.intValuationDef (x * y) = v.intValuationDef x * v.intValuationDef y := by simp only [intValuationDef] by_cases hx : x = 0 · rw [hx, zero_mul, if_pos (Eq.refl _), zero_mul] · by_cases hy : y = 0 · rw [hy, mul_zero, if_pos (Eq.refl _), mul_zero] · rw [if_neg hx, if_neg hy, if_neg (mul_ne_zero hx hy), ← WithZero.coe_mul, WithZero.coe_inj, ← ofAdd_add, ← Ideal.span_singleton_mul_span_singleton, ← Associates.mk_mul_mk, ← neg_add, Associates.count_mul (by apply Associates.mk_ne_zero'.mpr hx) (by apply Associates.mk_ne_zero'.mpr hy) (by apply v.associates_irreducible)] rfl @[deprecated (since := "2024-07-09")] alias IntValuation.map_mul' := intValuation.map_mul' theorem intValuation.le_max_iff_min_le {a b c : ℕ} : Multiplicative.ofAdd (-c : ℤ) ≤ max (Multiplicative.ofAdd (-a : ℤ)) (Multiplicative.ofAdd (-b : ℤ)) ↔ min a b ≤ c := by rw [le_max_iff, ofAdd_le, ofAdd_le, neg_le_neg_iff, neg_le_neg_iff, Int.ofNat_le, Int.ofNat_le, ← min_le_iff] @[deprecated (since := "2024-07-09")] alias IntValuation.le_max_iff_min_le := intValuation.le_max_iff_min_le /-- The `v`-adic valuation of a sum is bounded above by the maximum of the valuations. -/ theorem intValuation.map_add_le_max' (x y : R) : v.intValuationDef (x + y) ≤ max (v.intValuationDef x) (v.intValuationDef y) := by by_cases hx : x = 0 · rw [hx, zero_add] conv_rhs => rw [intValuationDef, if_pos (Eq.refl _)] rw [max_eq_right (WithZero.zero_le (v.intValuationDef y))] · by_cases hy : y = 0 · rw [hy, add_zero] conv_rhs => rw [max_comm, intValuationDef, if_pos (Eq.refl _)] rw [max_eq_right (WithZero.zero_le (v.intValuationDef x))] · by_cases hxy : x + y = 0 · rw [intValuationDef, if_pos hxy]; exact zero_le' · rw [v.intValuationDef_if_neg hxy, v.intValuationDef_if_neg hx, v.intValuationDef_if_neg hy, WithZero.le_max_iff, intValuation.le_max_iff_min_le] set nmin := min ((Associates.mk v.asIdeal).count (Associates.mk (Ideal.span { x })).factors) ((Associates.mk v.asIdeal).count (Associates.mk (Ideal.span { y })).factors) have h_dvd_x : x ∈ v.asIdeal ^ nmin := by rw [← Associates.le_singleton_iff x nmin _, Associates.prime_pow_dvd_iff_le (Associates.mk_ne_zero'.mpr hx) _] · exact min_le_left _ _ apply v.associates_irreducible have h_dvd_y : y ∈ v.asIdeal ^ nmin := by rw [← Associates.le_singleton_iff y nmin _, Associates.prime_pow_dvd_iff_le (Associates.mk_ne_zero'.mpr hy) _] · exact min_le_right _ _ apply v.associates_irreducible have h_dvd_xy : Associates.mk v.asIdeal ^ nmin ≤ Associates.mk (Ideal.span {x + y}) := by rw [Associates.le_singleton_iff] exact Ideal.add_mem (v.asIdeal ^ nmin) h_dvd_x h_dvd_y rw [Associates.prime_pow_dvd_iff_le (Associates.mk_ne_zero'.mpr hxy) _] at h_dvd_xy · exact h_dvd_xy apply v.associates_irreducible @[deprecated (since := "2024-07-09")] alias IntValuation.map_add_le_max' := intValuation.map_add_le_max' /-- The `v`-adic valuation on `R`. -/ @[simps] def intValuation : Valuation R ℤₘ₀ where toFun := v.intValuationDef map_zero' := intValuation.map_zero' v map_one' := intValuation.map_one' v map_mul' := intValuation.map_mul' v map_add_le_max' := intValuation.map_add_le_max' v theorem intValuation_apply {r : R} (v : IsDedekindDomain.HeightOneSpectrum R) : intValuation v r = intValuationDef v r := rfl /-- There exists `π ∈ R` with `v`-adic valuation `Multiplicative.ofAdd (-1)`. -/ theorem intValuation_exists_uniformizer : ∃ π : R, v.intValuationDef π = Multiplicative.ofAdd (-1 : ℤ) := by have hv : _root_.Irreducible (Associates.mk v.asIdeal) := v.associates_irreducible have hlt : v.asIdeal ^ 2 < v.asIdeal := by rw [← Ideal.dvdNotUnit_iff_lt] exact ⟨v.ne_bot, v.asIdeal, (not_congr Ideal.isUnit_iff).mpr (Ideal.IsPrime.ne_top v.isPrime), sq v.asIdeal⟩ obtain ⟨π, mem, nmem⟩ := SetLike.exists_of_lt hlt have hπ : Associates.mk (Ideal.span {π}) ≠ 0 := by rw [Associates.mk_ne_zero'] intro h rw [h] at nmem exact nmem (Submodule.zero_mem (v.asIdeal ^ 2)) use π rw [intValuationDef, if_neg (Associates.mk_ne_zero'.mp hπ), WithZero.coe_inj] apply congr_arg rw [neg_inj, ← Int.ofNat_one, Int.natCast_inj] rw [← Ideal.dvd_span_singleton, ← Associates.mk_le_mk_iff_dvd] at mem nmem rw [← pow_one (Associates.mk v.asIdeal), Associates.prime_pow_dvd_iff_le hπ hv] at mem rw [Associates.mk_pow, Associates.prime_pow_dvd_iff_le hπ hv, not_le] at nmem exact Nat.eq_of_le_of_lt_succ mem nmem @[deprecated (since := "2024-07-09")] alias int_valuation_exists_uniformizer := intValuation_exists_uniformizer /-- The `I`-adic valuation of a generator of `I` equals `(-1 : ℤₘ₀)` -/ theorem intValuation_singleton {r : R} (hr : r ≠ 0) (hv : v.asIdeal = Ideal.span {r}) : v.intValuation r = Multiplicative.ofAdd (-1 : ℤ) := by rw [intValuation_apply, v.intValuationDef_if_neg hr, ← hv, Associates.count_self, Int.ofNat_one, ofAdd_neg, WithZero.coe_inv] apply v.associates_irreducible /-! ### Adic valuations on the field of fractions `K` -/ /-- The `v`-adic valuation of `x ∈ K` is the valuation of `r` divided by the valuation of `s`, where `r` and `s` are chosen so that `x = r/s`. -/ def valuation (v : HeightOneSpectrum R) : Valuation K ℤₘ₀ := v.intValuation.extendToLocalization (fun r hr => Set.mem_compl <| v.intValuation_ne_zero' ⟨r, hr⟩) K theorem valuation_def (x : K) : v.valuation x = v.intValuation.extendToLocalization (fun r hr => Set.mem_compl (v.intValuation_ne_zero' ⟨r, hr⟩)) K x := rfl /-- The `v`-adic valuation of `r/s ∈ K` is the valuation of `r` divided by the valuation of `s`. -/ theorem valuation_of_mk' {r : R} {s : nonZeroDivisors R} : v.valuation (IsLocalization.mk' K r s) = v.intValuation r / v.intValuation s := by erw [valuation_def, (IsLocalization.toLocalizationMap (nonZeroDivisors R) K).lift_mk', div_eq_mul_inv, mul_eq_mul_left_iff] left rw [Units.val_inv_eq_inv_val, inv_inj] rfl /-- The `v`-adic valuation on `K` extends the `v`-adic valuation on `R`. -/ theorem valuation_of_algebraMap (r : R) : v.valuation (algebraMap R K r) = v.intValuation r := by rw [valuation_def, Valuation.extendToLocalization_apply_map_apply] open scoped algebraMap in lemma valuation_eq_intValuationDef (r : R) : v.valuation (r : K) = v.intValuationDef r := Valuation.extendToLocalization_apply_map_apply .. /-- The `v`-adic valuation on `R` is bounded above by 1. -/ theorem valuation_le_one (r : R) : v.valuation (algebraMap R K r) ≤ 1 := by rw [valuation_of_algebraMap]; exact v.intValuation_le_one r /-- The `v`-adic valuation of `r ∈ R` is less than 1 if and only if `v` divides the ideal `(r)`. -/ theorem valuation_lt_one_iff_dvd (r : R) : v.valuation (algebraMap R K r) < 1 ↔ v.asIdeal ∣ Ideal.span {r} := by rw [valuation_of_algebraMap]; exact v.intValuation_lt_one_iff_dvd r variable (K) /-- There exists `π ∈ K` with `v`-adic valuation `Multiplicative.ofAdd (-1)`. -/ theorem valuation_exists_uniformizer : ∃ π : K, v.valuation π = Multiplicative.ofAdd (-1 : ℤ) := by obtain ⟨r, hr⟩ := v.intValuation_exists_uniformizer use algebraMap R K r rw [valuation_def, Valuation.extendToLocalization_apply_map_apply] exact hr /-- Uniformizers are nonzero. -/ theorem valuation_uniformizer_ne_zero : Classical.choose (v.valuation_exists_uniformizer K) ≠ 0 := haveI hu := Classical.choose_spec (v.valuation_exists_uniformizer K) (Valuation.ne_zero_iff _).mp (ne_of_eq_of_ne hu WithZero.coe_ne_zero) /-! ### Completions with respect to adic valuations Given a Dedekind domain `R` with field of fractions `K` and a maximal ideal `v` of `R`, we define the completion of `K` with respect to its `v`-adic valuation, denoted `v.adicCompletion`, and its ring of integers, denoted `v.adicCompletionIntegers`. -/ variable {K} /-- `K` as a valued field with the `v`-adic valuation. -/ def adicValued : Valued K ℤₘ₀ := Valued.mk' v.valuation theorem adicValued_apply {x : K} : (v.adicValued.v : _) x = v.valuation x := rfl variable (K) /-- The completion of `K` with respect to its `v`-adic valuation. -/ abbrev adicCompletion := @UniformSpace.Completion K v.adicValued.toUniformSpace instance : Field (v.adicCompletion K) := @UniformSpace.Completion.instField K _ v.adicValued.toUniformSpace _ _ v.adicValued.toUniformAddGroup instance : Inhabited (v.adicCompletion K) := ⟨0⟩ instance valuedAdicCompletion : Valued (v.adicCompletion K) ℤₘ₀ := @Valued.valuedCompletion _ _ _ _ v.adicValued theorem valuedAdicCompletion_def {x : v.adicCompletion K} : Valued.v x = @Valued.extension K _ _ _ (adicValued v) x := rfl instance adicCompletion_completeSpace : CompleteSpace (v.adicCompletion K) := @UniformSpace.Completion.completeSpace K v.adicValued.toUniformSpace -- Porting note: replaced by `Coe` -- instance AdicCompletion.hasLiftT : HasLiftT K (v.adicCompletion K) := -- (inferInstance : HasLiftT K (@UniformSpace.Completion K v.adicValued.toUniformSpace)) instance adicCompletion.instCoe : Coe K (v.adicCompletion K) := (inferInstance : Coe K (@UniformSpace.Completion K v.adicValued.toUniformSpace)) /-- The ring of integers of `adicCompletion`. -/ def adicCompletionIntegers : ValuationSubring (v.adicCompletion K) := Valued.v.valuationSubring instance : Inhabited (adicCompletionIntegers K v) := ⟨0⟩ variable (R) theorem mem_adicCompletionIntegers {x : v.adicCompletion K} : x ∈ v.adicCompletionIntegers K ↔ (Valued.v x : ℤₘ₀) ≤ 1 := Iff.rfl theorem not_mem_adicCompletionIntegers {x : v.adicCompletion K} : x ∉ v.adicCompletionIntegers K ↔ 1 < (Valued.v x : ℤₘ₀) := by rw [not_congr <| mem_adicCompletionIntegers R K v] exact not_le section AlgebraInstances instance (priority := 100) adicValued.has_uniform_continuous_const_smul' : @UniformContinuousConstSMul R K v.adicValued.toUniformSpace _ := @uniformContinuousConstSMul_of_continuousConstSMul R K _ _ _ v.adicValued.toUniformSpace _ _ instance adicValued.uniformContinuousConstSMul : @UniformContinuousConstSMul K K v.adicValued.toUniformSpace _ := @Ring.uniformContinuousConstSMul K _ v.adicValued.toUniformSpace _ _ instance adicCompletion.algebra' : Algebra R (v.adicCompletion K) := @UniformSpace.Completion.algebra K _ v.adicValued.toUniformSpace _ _ R _ _ (adicValued.has_uniform_continuous_const_smul' R K v) theorem coe_smul_adicCompletion (r : R) (x : K) : (↑(r • x) : v.adicCompletion K) = r • (↑x : v.adicCompletion K) := @UniformSpace.Completion.coe_smul R K v.adicValued.toUniformSpace _ _ r x instance : Algebra K (v.adicCompletion K) := @UniformSpace.Completion.algebra' K _ v.adicValued.toUniformSpace _ _ theorem algebraMap_adicCompletion' : ⇑(algebraMap R <| v.adicCompletion K) = (↑) ∘ algebraMap R K := rfl theorem algebraMap_adicCompletion : ⇑(algebraMap K <| v.adicCompletion K) = ((↑) : K → adicCompletion K v) := rfl instance : IsScalarTower R K (v.adicCompletion K) := @UniformSpace.Completion.instIsScalarTower R K K v.adicValued.toUniformSpace _ _ _ (adicValued.has_uniform_continuous_const_smul' R K v) _ _ instance : Algebra R (v.adicCompletionIntegers K) where smul r x := ⟨r • (x : v.adicCompletion K), by have h : (algebraMap R (adicCompletion K v)) r = (algebraMap R K r : adicCompletion K v) := rfl rw [Algebra.smul_def] refine ValuationSubring.mul_mem _ _ _ ?_ x.2 --porting note (#10754): added instance letI : Valued K ℤₘ₀ := adicValued v rw [mem_adicCompletionIntegers, h, Valued.valuedCompletion_apply] exact v.valuation_le_one _⟩ toFun r := ⟨(algebraMap R K r : adicCompletion K v), by simpa only [mem_adicCompletionIntegers, Valued.valuedCompletion_apply] using v.valuation_le_one _⟩ map_one' := by simp only [map_one]; rfl map_mul' x y := by ext simp_rw [RingHom.map_mul, Subring.coe_mul, UniformSpace.Completion.coe_mul] map_zero' := by simp only [map_zero]; rfl map_add' x y := by ext simp_rw [RingHom.map_add, Subring.coe_add, UniformSpace.Completion.coe_add] commutes' r x := by rw [mul_comm] smul_def' r x := by ext simp only [Subring.coe_mul, Algebra.smul_def] rfl variable {R K} in open scoped algebraMap in -- to make the coercions from `R` fire /-- The valuation on the completion agrees with the global valuation on elements of the integer ring. -/ theorem valuedAdicCompletion_eq_valuation (r : R) : Valued.v (r : v.adicCompletion K) = v.valuation (r : K) := by convert Valued.valuedCompletion_apply (r : K) variable {R K} in /-- The valuation on the completion agrees with the global valuation on elements of the field. -/ theorem valuedAdicCompletion_eq_valuation' (k : K) : Valued.v (k : v.adicCompletion K) = v.valuation k := by convert Valued.valuedCompletion_apply k variable {R K} in open scoped algebraMap in -- to make the coercion from `R` fire /-- A global integer is in the local integers. -/ lemma coe_mem_adicCompletionIntegers (r : R) : (r : adicCompletion K v) ∈ adicCompletionIntegers K v := by rw [mem_adicCompletionIntegers, valuedAdicCompletion_eq_valuation, valuation_eq_intValuationDef] exact intValuation_le_one v r @[simp] theorem coe_smul_adicCompletionIntegers (r : R) (x : v.adicCompletionIntegers K) : (↑(r • x) : v.adicCompletion K) = r • (x : v.adicCompletion K) := rfl instance : NoZeroSMulDivisors R (v.adicCompletionIntegers K) where eq_zero_or_eq_zero_of_smul_eq_zero {c x} hcx := by rw [Algebra.smul_def, mul_eq_zero] at hcx refine hcx.imp_left fun hc => ?_ letI : UniformSpace K := v.adicValued.toUniformSpace rw [← map_zero (algebraMap R (v.adicCompletionIntegers K))] at hc exact IsFractionRing.injective R K (UniformSpace.Completion.coe_injective K (Subtype.ext_iff.mp hc)) instance adicCompletion.instIsScalarTower' : IsScalarTower R (v.adicCompletionIntegers K) (v.adicCompletion K) where smul_assoc x y z := by simp only [Algebra.smul_def]; apply mul_assoc end AlgebraInstances open nonZeroDivisors algebraMap in variable {R K} in lemma adicCompletion.mul_nonZeroDivisor_mem_adicCompletionIntegers (v : HeightOneSpectrum R) (a : v.adicCompletion K) : ∃ b ∈ R⁰, a * b ∈ v.adicCompletionIntegers K := by by_cases ha : a ∈ v.adicCompletionIntegers K · use 1 simp [ha, Submonoid.one_mem] · rw [not_mem_adicCompletionIntegers] at ha -- Let the additive valuation of a be -d with d>0 obtain ⟨d, hd⟩ : ∃ d : ℤ, Valued.v a = ofAdd d := Option.ne_none_iff_exists'.mp <| (lt_trans zero_lt_one ha).ne' rw [hd, WithZero.one_lt_coe, ← ofAdd_zero, ofAdd_lt] at ha -- let ϖ be a uniformiser obtain ⟨ϖ, hϖ⟩ := intValuation_exists_uniformizer v have hϖ0 : ϖ ≠ 0 := by rintro rfl; simp at hϖ -- use ϖ^d refine ⟨ϖ^d.natAbs, pow_mem (mem_nonZeroDivisors_of_ne_zero hϖ0) _, ?_⟩ -- now manually translate the goal (an inequality in ℤₘ₀) to an inequality in ℤ rw [mem_adicCompletionIntegers, algebraMap.coe_pow, map_mul, hd, map_pow, valuedAdicCompletion_eq_valuation, valuation_eq_intValuationDef, hϖ, ← WithZero.coe_pow, ← WithZero.coe_mul, WithZero.coe_le_one, ← toAdd_le, toAdd_mul, toAdd_ofAdd, toAdd_pow, toAdd_ofAdd, toAdd_one, show d.natAbs • (-1) = (d.natAbs : ℤ) • (-1) by simp only [nsmul_eq_mul, Int.natCast_natAbs, smul_eq_mul], ← Int.eq_natAbs_of_zero_le ha.le, smul_eq_mul] -- and now it's easy linarith end IsDedekindDomain.HeightOneSpectrum
RingTheory\DedekindDomain\Basic.lean
/- Copyright (c) 2020 Kenji Nakagawa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenji Nakagawa, Anne Baanen, Filippo A. E. Nuccio -/ import Mathlib.RingTheory.Ideal.Over import Mathlib.RingTheory.Polynomial.RationalRoot /-! # Dedekind rings and domains This file defines the notion of a Dedekind ring (domain), as a Noetherian integrally closed commutative ring (domain) of Krull dimension at most one. ## Main definitions - `IsDedekindRing` defines a Dedekind ring as a commutative ring that is Noetherian, integrally closed in its field of fractions and has Krull dimension at most one. `isDedekindRing_iff` shows that this does not depend on the choice of field of fractions. - `IsDedekindDomain` defines a Dedekind domain as a Dedekind ring that is a domain. ## Implementation notes The definitions that involve a field of fractions choose a canonical field of fractions, but are independent of that choice. The `..._iff` lemmas express this independence. `IsDedekindRing` and `IsDedekindDomain` form a cycle in the typeclass hierarchy: `IsDedekindRing R + IsDomain R` imply `IsDedekindDomain R`, which implies `IsDedekindRing R`. This should be safe since the start and end point is the literal same expression, which the tabled typeclass synthesis algorithm can deal with. Often, definitions assume that Dedekind rings are not fields. We found it more practical to add a `(h : ¬ IsField A)` assumption whenever this is explicitly needed. ## References * [D. Marcus, *Number Fields*][marcus1977number] * [J.W.S. Cassels, A. Frölich, *Algebraic Number Theory*][cassels1967algebraic] * [J. Neukirch, *Algebraic Number Theory*][Neukirch1992] ## Tags dedekind domain, dedekind ring -/ variable (R A K : Type*) [CommRing R] [CommRing A] [Field K] open scoped nonZeroDivisors Polynomial /-- A ring `R` has Krull dimension at most one if all nonzero prime ideals are maximal. -/ class Ring.DimensionLEOne : Prop := (maximalOfPrime : ∀ {p : Ideal R}, p ≠ ⊥ → p.IsPrime → p.IsMaximal) open Ideal Ring theorem Ideal.IsPrime.isMaximal {R : Type*} [CommRing R] [DimensionLEOne R] {p : Ideal R} (h : p.IsPrime) (hp : p ≠ ⊥) : p.IsMaximal := DimensionLEOne.maximalOfPrime hp h namespace Ring instance DimensionLEOne.principal_ideal_ring [IsDomain A] [IsPrincipalIdealRing A] : DimensionLEOne A where maximalOfPrime := fun nonzero _ => IsPrime.to_maximal_ideal nonzero theorem DimensionLEOne.isIntegralClosure (B : Type*) [CommRing B] [IsDomain B] [Nontrivial R] [Algebra R A] [Algebra R B] [Algebra B A] [IsScalarTower R B A] [IsIntegralClosure B R A] [DimensionLEOne R] : DimensionLEOne B where maximalOfPrime := fun {p} ne_bot _ => IsIntegralClosure.isMaximal_of_isMaximal_comap (R := R) A p (Ideal.IsPrime.isMaximal inferInstance (IsIntegralClosure.comap_ne_bot A ne_bot)) nonrec instance DimensionLEOne.integralClosure [Nontrivial R] [IsDomain A] [Algebra R A] [DimensionLEOne R] : DimensionLEOne (integralClosure R A) := DimensionLEOne.isIntegralClosure R A (integralClosure R A) variable {R} theorem DimensionLEOne.not_lt_lt [Ring.DimensionLEOne R] (p₀ p₁ p₂ : Ideal R) [hp₁ : p₁.IsPrime] [hp₂ : p₂.IsPrime] : ¬(p₀ < p₁ ∧ p₁ < p₂) | ⟨h01, h12⟩ => h12.ne ((hp₁.isMaximal (bot_le.trans_lt h01).ne').eq_of_le hp₂.ne_top h12.le) theorem DimensionLEOne.eq_bot_of_lt [Ring.DimensionLEOne R] (p P : Ideal R) [p.IsPrime] [P.IsPrime] (hpP : p < P) : p = ⊥ := by_contra fun hp0 => not_lt_lt ⊥ p P ⟨Ne.bot_lt hp0, hpP⟩ end Ring /-- A Dedekind ring is a commutative ring that is Noetherian, integrally closed, and has Krull dimension at most one. This is exactly `IsDedekindDomain` minus the `IsDomain` hypothesis. The integral closure condition is independent of the choice of field of fractions: use `isDedekindRing_iff` to prove `IsDedekindRing` for a given `fraction_map`. -/ class IsDedekindRing extends IsNoetherian A A, DimensionLEOne A, IsIntegralClosure A A (FractionRing A) : Prop /-- An integral domain is a Dedekind domain if and only if it is Noetherian, has dimension ≤ 1, and is integrally closed in a given fraction field. In particular, this definition does not depend on the choice of this fraction field. -/ theorem isDedekindRing_iff (K : Type*) [CommRing K] [Algebra A K] [IsFractionRing A K] : IsDedekindRing A ↔ IsNoetherianRing A ∧ DimensionLEOne A ∧ ∀ {x : K}, IsIntegral A x → ∃ y, algebraMap A K y = x := ⟨fun _ => ⟨inferInstance, inferInstance, fun {_} => (isIntegrallyClosed_iff K).mp inferInstance⟩, fun ⟨hr, hd, hi⟩ => { hr, hd, (isIntegrallyClosed_iff K).mpr @hi with }⟩ /-- A Dedekind domain is an integral domain that is Noetherian, integrally closed, and has Krull dimension at most one. This is definition 3.2 of [Neukirch1992]. This is exactly `IsDedekindRing` plus the `IsDomain` hypothesis. The integral closure condition is independent of the choice of field of fractions: use `isDedekindDomain_iff` to prove `IsDedekindDomain` for a given `fraction_map`. This is the default implementation, but there are equivalent definitions, `IsDedekindDomainDvr` and `IsDedekindDomainInv`. TODO: Prove that these are actually equivalent definitions. -/ class IsDedekindDomain extends IsDomain A, IsDedekindRing A : Prop attribute [instance 90] IsDedekindDomain.toIsDomain /-- Make a Dedekind domain from a Dedekind ring given that it is a domain. `IsDedekindRing` and `IsDedekindDomain` form a cycle in the typeclass hierarchy: `IsDedekindRing R + IsDomain R` imply `IsDedekindDomain R`, which implies `IsDedekindRing R`. This should be safe since the start and end point is the literal same expression, which the tabled typeclass synthesis algorithm can deal with. -/ instance [IsDomain A] [IsDedekindRing A] : IsDedekindDomain A where /-- An integral domain is a Dedekind domain iff and only if it is Noetherian, has dimension ≤ 1, and is integrally closed in a given fraction field. In particular, this definition does not depend on the choice of this fraction field. -/ theorem isDedekindDomain_iff (K : Type*) [Field K] [Algebra A K] [IsFractionRing A K] : IsDedekindDomain A ↔ IsDomain A ∧ IsNoetherianRing A ∧ DimensionLEOne A ∧ ∀ {x : K}, IsIntegral A x → ∃ y, algebraMap A K y = x := ⟨fun _ => ⟨inferInstance, inferInstance, inferInstance, fun {_} => (isIntegrallyClosed_iff K).mp inferInstance⟩, fun ⟨hid, hr, hd, hi⟩ => { hid, hr, hd, (isIntegrallyClosed_iff K).mpr @hi with }⟩ -- See library note [lower instance priority] instance (priority := 100) IsPrincipalIdealRing.isDedekindDomain [IsDomain A] [IsPrincipalIdealRing A] : IsDedekindDomain A := { PrincipalIdealRing.isNoetherianRing, Ring.DimensionLEOne.principal_ideal_ring A, UniqueFactorizationMonoid.instIsIntegrallyClosed with }
RingTheory\DedekindDomain\Different.lean
/- Copyright (c) 2023 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.RingTheory.DedekindDomain.Ideal import Mathlib.RingTheory.Discriminant import Mathlib.RingTheory.DedekindDomain.IntegralClosure import Mathlib.NumberTheory.KummerDedekind /-! # The different ideal ## Main definition - `Submodule.traceDual`: The dual `L`-sub `B`-module under the trace form. - `FractionalIdeal.dual`: The dual fractional ideal under the trace form. - `differentIdeal`: The different ideal of an extension of integral domains. ## Main results - `conductor_mul_differentIdeal`: If `L = K[x]`, with `x` integral over `A`, then `𝔣 * 𝔇 = (f'(x))` with `f` being the minimal polynomial of `x`. - `aeval_derivative_mem_differentIdeal`: If `L = K[x]`, with `x` integral over `A`, then `f'(x) ∈ 𝔇` with `f` being the minimal polynomial of `x`. ## TODO - Show properties of the different ideal -/ universe u attribute [local instance] FractionRing.liftAlgebra FractionRing.isScalarTower_liftAlgebra variable (A K : Type*) {L : Type u} {B} [CommRing A] [Field K] [CommRing B] [Field L] variable [Algebra A K] [Algebra B L] [Algebra A B] [Algebra K L] [Algebra A L] variable [IsScalarTower A K L] [IsScalarTower A B L] open nonZeroDivisors IsLocalization Matrix Algebra section BIsDomain /-- Under the AKLB setting, `Iᵛ := traceDual A K (I : Submodule B L)` is the `Submodule B L` such that `x ∈ Iᵛ ↔ ∀ y ∈ I, Tr(x, y) ∈ A` -/ noncomputable def Submodule.traceDual (I : Submodule B L) : Submodule B L where __ := (traceForm K L).dualSubmodule (I.restrictScalars A) smul_mem' c x hx a ha := by rw [traceForm_apply, smul_mul_assoc, mul_comm, ← smul_mul_assoc, mul_comm] exact hx _ (Submodule.smul_mem _ c ha) variable {A K} local notation:max I:max "ᵛ" => Submodule.traceDual A K I namespace Submodule lemma mem_traceDual {I : Submodule B L} {x} : x ∈ Iᵛ ↔ ∀ a ∈ I, traceForm K L x a ∈ (algebraMap A K).range := Iff.rfl lemma le_traceDual_iff_map_le_one {I J : Submodule B L} : I ≤ Jᵛ ↔ ((I * J : Submodule B L).restrictScalars A).map ((trace K L).restrictScalars A) ≤ 1 := by rw [Submodule.map_le_iff_le_comap, Submodule.restrictScalars_mul, Submodule.mul_le] simp [SetLike.le_def, mem_traceDual] lemma le_traceDual_mul_iff {I J J' : Submodule B L} : I ≤ (J * J')ᵛ ↔ I * J ≤ J'ᵛ := by simp_rw [le_traceDual_iff_map_le_one, mul_assoc] lemma le_traceDual {I J : Submodule B L} : I ≤ Jᵛ ↔ I * J ≤ 1ᵛ := by rw [← le_traceDual_mul_iff, mul_one] lemma le_traceDual_comm {I J : Submodule B L} : I ≤ Jᵛ ↔ J ≤ Iᵛ := by rw [le_traceDual, mul_comm, ← le_traceDual] lemma le_traceDual_traceDual {I : Submodule B L} : I ≤ Iᵛᵛ := le_traceDual_comm.mpr le_rfl @[simp] lemma traceDual_bot : (⊥ : Submodule B L)ᵛ = ⊤ := by ext; simpa [mem_traceDual, -RingHom.mem_range] using zero_mem _ open scoped Classical in lemma traceDual_top' : (⊤ : Submodule B L)ᵛ = if ((LinearMap.range (Algebra.trace K L)).restrictScalars A ≤ 1) then ⊤ else ⊥ := by classical split_ifs with h · rw [_root_.eq_top_iff] exact fun _ _ _ _ ↦ h ⟨_, rfl⟩ · simp only [SetLike.le_def, restrictScalars_mem, LinearMap.mem_range, mem_one, forall_exists_index, forall_apply_eq_imp_iff, not_forall, not_exists] at h obtain ⟨b, hb⟩ := h simp_rw [eq_bot_iff, SetLike.le_def, mem_bot, mem_traceDual, mem_top, true_implies, traceForm_apply, RingHom.mem_range] contrapose! hb with hx' obtain ⟨c, hc, hc0⟩ := hx' simpa [hc0] using hc (c⁻¹ * b) variable [IsDomain A] [IsFractionRing A K] [FiniteDimensional K L] [Algebra.IsSeparable K L] lemma traceDual_top [Decidable (IsField A)] : (⊤ : Submodule B L)ᵛ = if IsField A then ⊤ else ⊥ := by convert traceDual_top' rw [← IsFractionRing.surjective_iff_isField (R := A) (K := K), LinearMap.range_eq_top.mpr (Algebra.trace_surjective K L), ← RingHom.range_top_iff_surjective, _root_.eq_top_iff] simp [SetLike.le_def] end Submodule open Submodule variable [IsFractionRing A K] variable (A K) in lemma map_equiv_traceDual [IsDomain A] [IsFractionRing B L] [IsDomain B] [NoZeroSMulDivisors A B] (I : Submodule B (FractionRing B)) : (traceDual A (FractionRing A) I).map (FractionRing.algEquiv B L) = traceDual A K (I.map (FractionRing.algEquiv B L)) := by show Submodule.map (FractionRing.algEquiv B L).toLinearEquiv.toLinearMap _ = traceDual A K (I.map (FractionRing.algEquiv B L).toLinearEquiv.toLinearMap) rw [Submodule.map_equiv_eq_comap_symm, Submodule.map_equiv_eq_comap_symm] ext x simp only [AlgEquiv.toLinearEquiv_symm, AlgEquiv.toLinearEquiv_toLinearMap, traceDual, traceForm_apply, Submodule.mem_comap, AlgEquiv.toLinearMap_apply, Submodule.mem_mk, AddSubmonoid.mem_mk, AddSubsemigroup.mem_mk, Set.mem_setOf_eq] apply (FractionRing.algEquiv B L).forall_congr simp only [restrictScalars_mem, traceForm_apply, AlgEquiv.toEquiv_eq_coe, EquivLike.coe_coe, mem_comap, AlgEquiv.toLinearMap_apply, AlgEquiv.symm_apply_apply] refine fun {y} ↦ (forall_congr' fun hy ↦ ?_) rw [Algebra.trace_eq_of_equiv_equiv (FractionRing.algEquiv A K).toRingEquiv (FractionRing.algEquiv B L).toRingEquiv] swap · apply IsLocalization.ringHom_ext (M := A⁰); ext simp only [AlgEquiv.toRingEquiv_eq_coe, AlgEquiv.toRingEquiv_toRingHom, RingHom.coe_comp, RingHom.coe_coe, Function.comp_apply, AlgEquiv.commutes, ← IsScalarTower.algebraMap_apply] rw [IsScalarTower.algebraMap_apply A B (FractionRing B), AlgEquiv.commutes, ← IsScalarTower.algebraMap_apply] simp only [AlgEquiv.toRingEquiv_eq_coe, _root_.map_mul, AlgEquiv.coe_ringEquiv, AlgEquiv.apply_symm_apply, ← AlgEquiv.symm_toRingEquiv, mem_one, AlgEquiv.algebraMap_eq_apply] variable [IsIntegrallyClosed A] lemma Submodule.mem_traceDual_iff_isIntegral {I : Submodule B L} {x} : x ∈ Iᵛ ↔ ∀ a ∈ I, IsIntegral A (traceForm K L x a) := forall₂_congr (fun _ _ ↦ IsIntegrallyClosed.isIntegral_iff.symm) variable [FiniteDimensional K L] [IsIntegralClosure B A L] lemma Submodule.one_le_traceDual_one : (1 : Submodule B L) ≤ 1ᵛ := by rw [le_traceDual_iff_map_le_one, mul_one] rintro _ ⟨x, ⟨x, rfl⟩, rfl⟩ apply IsIntegrallyClosed.isIntegral_iff.mp apply isIntegral_trace rw [IsIntegralClosure.isIntegral_iff (A := B)] exact ⟨_, rfl⟩ variable [Algebra.IsSeparable K L] /-- If `b` is an `A`-integral basis of `L` with discriminant `b`, then `d • a * x` is integral over `A` for all `a ∈ I` and `x ∈ Iᵛ`. -/ lemma isIntegral_discr_mul_of_mem_traceDual (I : Submodule B L) {ι} [DecidableEq ι] [Fintype ι] {b : Basis ι K L} (hb : ∀ i, IsIntegral A (b i)) {a x : L} (ha : a ∈ I) (hx : x ∈ Iᵛ) : IsIntegral A ((discr K b) • a * x) := by have hinv : IsUnit (traceMatrix K b).det := by simpa [← discr_def] using discr_isUnit_of_basis _ b have H := mulVec_cramer (traceMatrix K b) fun i => trace K L (x * a * b i) have : Function.Injective (traceMatrix K b).mulVec := by rwa [mulVec_injective_iff_isUnit, isUnit_iff_isUnit_det] rw [← traceMatrix_of_basis_mulVec, ← mulVec_smul, this.eq_iff, traceMatrix_of_basis_mulVec] at H rw [← b.equivFun.symm_apply_apply (_ * _), b.equivFun_symm_apply] apply IsIntegral.sum intro i _ rw [smul_mul_assoc, b.equivFun.map_smul, discr_def, mul_comm, ← H, Algebra.smul_def] refine RingHom.IsIntegralElem.mul _ ?_ (hb _) apply IsIntegral.algebraMap rw [cramer_apply] apply IsIntegral.det intros j k rw [updateColumn_apply] split · rw [mul_assoc] rw [mem_traceDual_iff_isIntegral] at hx apply hx have ⟨y, hy⟩ := (IsIntegralClosure.isIntegral_iff (A := B)).mp (hb j) rw [mul_comm, ← hy, ← Algebra.smul_def] exact I.smul_mem _ (ha) · exact isIntegral_trace (RingHom.IsIntegralElem.mul _ (hb j) (hb k)) variable (A K) open scoped Classical variable [IsDomain A] [IsFractionRing B L] [Nontrivial B] [NoZeroDivisors B] namespace FractionalIdeal /-- The dual of a non-zero fractional ideal is the dual of the submodule under the traceform. -/ noncomputable def dual (I : FractionalIdeal B⁰ L) : FractionalIdeal B⁰ L := if hI : I = 0 then 0 else ⟨Iᵛ, by classical have ⟨s, b, hb⟩ := FiniteDimensional.exists_is_basis_integral A K L obtain ⟨x, hx, hx'⟩ := exists_ne_zero_mem_isInteger hI have ⟨y, hy⟩ := (IsIntegralClosure.isIntegral_iff (A := B)).mp (IsIntegral.algebraMap (B := L) (discr_isIntegral K hb)) refine ⟨y * x, mem_nonZeroDivisors_iff_ne_zero.mpr (mul_ne_zero ?_ hx), fun z hz ↦ ?_⟩ · rw [← (IsIntegralClosure.algebraMap_injective B A L).ne_iff, hy, RingHom.map_zero, ← (algebraMap K L).map_zero, (algebraMap K L).injective.ne_iff] exact discr_not_zero_of_basis K b · convert isIntegral_discr_mul_of_mem_traceDual I hb hx' hz using 1 · ext w; exact (IsIntegralClosure.isIntegral_iff (A := B)).symm · rw [Algebra.smul_def, RingHom.map_mul, hy, ← Algebra.smul_def]⟩ end FractionalIdeal end BIsDomain variable [IsDomain A] [IsFractionRing A K] [FiniteDimensional K L] [Algebra.IsSeparable K L] [IsIntegralClosure B A L] namespace FractionalIdeal variable [IsFractionRing B L] [IsIntegrallyClosed A] open Submodule open scoped Classical local notation:max I:max "ᵛ" => Submodule.traceDual A K I variable [IsDedekindDomain B] {I J : FractionalIdeal B⁰ L} lemma coe_dual (hI : I ≠ 0) : (dual A K I : Submodule B L) = Iᵛ := by rw [dual, dif_neg hI, coe_mk] variable (B L) @[simp] lemma coe_dual_one : (dual A K (1 : FractionalIdeal B⁰ L) : Submodule B L) = 1ᵛ := by rw [← coe_one, coe_dual] exact one_ne_zero @[simp] lemma dual_zero : dual A K (0 : FractionalIdeal B⁰ L) = 0 := by rw [dual, dif_pos rfl] variable {A K L B} lemma mem_dual (hI : I ≠ 0) {x} : x ∈ dual A K I ↔ ∀ a ∈ I, traceForm K L x a ∈ (algebraMap A K).range := by rw [dual, dif_neg hI]; rfl variable (A K) lemma dual_ne_zero (hI : I ≠ 0) : dual A K I ≠ 0 := by obtain ⟨b, hb, hb'⟩ := I.prop suffices algebraMap B L b ∈ dual A K I by intro e rw [e, mem_zero_iff, ← (algebraMap B L).map_zero, (IsIntegralClosure.algebraMap_injective B A L).eq_iff] at this exact mem_nonZeroDivisors_iff_ne_zero.mp hb this rw [mem_dual hI] intro a ha apply IsIntegrallyClosed.isIntegral_iff.mp apply isIntegral_trace dsimp convert hb' a ha using 1 · ext w exact IsIntegralClosure.isIntegral_iff (A := B) · exact (Algebra.smul_def _ _).symm variable {A K} @[simp] lemma dual_eq_zero_iff : dual A K I = 0 ↔ I = 0 := ⟨not_imp_not.mp (dual_ne_zero A K), fun e ↦ e.symm ▸ dual_zero A K L B⟩ lemma dual_ne_zero_iff : dual A K I ≠ 0 ↔ I ≠ 0 := dual_eq_zero_iff.not variable (A K) lemma le_dual_inv_aux (hI : I ≠ 0) (hIJ : I * J ≤ 1) : J ≤ dual A K I := by rw [dual, dif_neg hI] intro x hx y hy apply IsIntegrallyClosed.isIntegral_iff.mp apply isIntegral_trace rw [IsIntegralClosure.isIntegral_iff (A := B)] have ⟨z, _, hz⟩ := hIJ (FractionalIdeal.mul_mem_mul hy hx) rw [mul_comm] at hz exact ⟨z, hz⟩ lemma one_le_dual_one : 1 ≤ dual A K (1 : FractionalIdeal B⁰ L) := le_dual_inv_aux A K one_ne_zero (by rw [one_mul]) lemma le_dual_iff (hJ : J ≠ 0) : I ≤ dual A K J ↔ I * J ≤ dual A K 1 := by by_cases hI : I = 0 · simp [hI, zero_le] rw [← coe_le_coe, ← coe_le_coe, coe_mul, coe_dual A K hJ, coe_dual_one, le_traceDual] variable (I) lemma inv_le_dual : I⁻¹ ≤ dual A K I := if hI : I = 0 then by simp [hI] else le_dual_inv_aux A K hI (le_of_eq (mul_inv_cancel hI)) lemma dual_inv_le : (dual A K I)⁻¹ ≤ I := by by_cases hI : I = 0; · simp [hI] convert mul_right_mono ((dual A K I)⁻¹) (mul_left_mono I (inv_le_dual A K I)) using 1 · simp only [mul_inv_cancel hI, one_mul] · simp only [mul_inv_cancel (dual_ne_zero A K (hI := hI)), mul_assoc, mul_one] lemma dual_eq_mul_inv : dual A K I = dual A K 1 * I⁻¹ := by by_cases hI : I = 0; · simp [hI] apply le_antisymm · suffices dual A K I * I ≤ dual A K 1 by convert mul_right_mono I⁻¹ this using 1; simp only [mul_inv_cancel hI, mul_one, mul_assoc] rw [← le_dual_iff A K hI] rw [le_dual_iff A K hI, mul_assoc, inv_mul_cancel hI, mul_one] variable {I} lemma dual_div_dual : dual A K J / dual A K I = I / J := by rw [dual_eq_mul_inv A K J, dual_eq_mul_inv A K I, mul_div_mul_comm, div_self, one_mul] · exact inv_div_inv J I · simp only [ne_eq, dual_eq_zero_iff, one_ne_zero, not_false_eq_true] lemma dual_mul_self (hI : I ≠ 0) : dual A K I * I = dual A K 1 := by rw [dual_eq_mul_inv, mul_assoc, inv_mul_cancel hI, mul_one] lemma self_mul_dual (hI : I ≠ 0) : I * dual A K I = dual A K 1 := by rw [mul_comm, dual_mul_self A K hI] lemma dual_inv : dual A K I⁻¹ = dual A K 1 * I := by rw [dual_eq_mul_inv, inv_inv] variable (I) @[simp] lemma dual_dual : dual A K (dual A K I) = I := by rw [dual_eq_mul_inv, dual_eq_mul_inv A K (I := I), mul_inv, inv_inv, ← mul_assoc, mul_inv_cancel, one_mul] rw [dual_ne_zero_iff] exact one_ne_zero variable {I} @[simp] lemma dual_le_dual (hI : I ≠ 0) (hJ : J ≠ 0) : dual A K I ≤ dual A K J ↔ J ≤ I := by nth_rewrite 2 [← dual_dual A K I] rw [le_dual_iff A K hJ, le_dual_iff A K (I := J) (by rwa [dual_ne_zero_iff]), mul_comm] variable {A K} lemma dual_involutive : Function.Involutive (dual A K : FractionalIdeal B⁰ L → FractionalIdeal B⁰ L) := dual_dual A K lemma dual_injective : Function.Injective (dual A K : FractionalIdeal B⁰ L → FractionalIdeal B⁰ L) := dual_involutive.injective end FractionalIdeal variable (B) variable [IsIntegrallyClosed A] [IsDedekindDomain B] /-- The different ideal of an extension of integral domains `B/A` is the inverse of the dual of `A` as an ideal of `B`. See `coeIdeal_differentIdeal` and `coeSubmodule_differentIdeal`. -/ def differentIdeal [NoZeroSMulDivisors A B] : Ideal B := (1 / Submodule.traceDual A (FractionRing A) 1 : Submodule B (FractionRing B)).comap (Algebra.linearMap B (FractionRing B)) lemma coeSubmodule_differentIdeal_fractionRing [NoZeroSMulDivisors A B] [Algebra.IsIntegral A B] [Algebra.IsSeparable (FractionRing A) (FractionRing B)] [FiniteDimensional (FractionRing A) (FractionRing B)] : coeSubmodule (FractionRing B) (differentIdeal A B) = 1 / Submodule.traceDual A (FractionRing A) 1 := by have : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ rw [coeSubmodule, differentIdeal, Submodule.map_comap_eq, inf_eq_right] have := FractionalIdeal.dual_inv_le (A := A) (K := FractionRing A) (1 : FractionalIdeal B⁰ (FractionRing B)) have : _ ≤ ((1 : FractionalIdeal B⁰ (FractionRing B)) : Submodule B (FractionRing B)) := this simp only [← one_div, FractionalIdeal.val_eq_coe] at this rw [FractionalIdeal.coe_div (FractionalIdeal.dual_ne_zero _ _ _), FractionalIdeal.coe_dual] at this · simpa only [FractionalIdeal.coe_one] using this · exact one_ne_zero · exact one_ne_zero section variable [IsFractionRing B L] lemma coeSubmodule_differentIdeal [NoZeroSMulDivisors A B] : coeSubmodule L (differentIdeal A B) = 1 / Submodule.traceDual A K 1 := by have : (FractionRing.algEquiv B L).toLinearEquiv.comp (Algebra.linearMap B (FractionRing B)) = Algebra.linearMap B L := by ext; simp rw [coeSubmodule, ← this] have H : RingHom.comp (algebraMap (FractionRing A) (FractionRing B)) ↑(FractionRing.algEquiv A K).symm.toRingEquiv = RingHom.comp ↑(FractionRing.algEquiv B L).symm.toRingEquiv (algebraMap K L) := by apply IsLocalization.ringHom_ext A⁰ ext simp only [AlgEquiv.toRingEquiv_eq_coe, RingHom.coe_comp, RingHom.coe_coe, AlgEquiv.coe_ringEquiv, Function.comp_apply, AlgEquiv.commutes, ← IsScalarTower.algebraMap_apply] rw [IsScalarTower.algebraMap_apply A B L, AlgEquiv.commutes, ← IsScalarTower.algebraMap_apply] have : Algebra.IsSeparable (FractionRing A) (FractionRing B) := Algebra.IsSeparable.of_equiv_equiv _ _ H have : FiniteDimensional (FractionRing A) (FractionRing B) := Module.Finite.of_equiv_equiv _ _ H have : Algebra.IsIntegral A B := IsIntegralClosure.isIntegral_algebra _ L simp only [AlgEquiv.toLinearEquiv_toLinearMap, Submodule.map_comp] rw [← coeSubmodule, coeSubmodule_differentIdeal_fractionRing _ _, Submodule.map_div, ← AlgEquiv.toAlgHom_toLinearMap, Submodule.map_one] congr 1 refine (map_equiv_traceDual A K _).trans ?_ congr 1 ext simp variable (L) lemma coeIdeal_differentIdeal [NoZeroSMulDivisors A B] : ↑(differentIdeal A B) = (FractionalIdeal.dual A K (1 : FractionalIdeal B⁰ L))⁻¹ := by apply FractionalIdeal.coeToSubmodule_injective simp only [FractionalIdeal.coe_div (FractionalIdeal.dual_ne_zero _ _ (@one_ne_zero (FractionalIdeal B⁰ L) _ _ _)), FractionalIdeal.coe_coeIdeal, coeSubmodule_differentIdeal A K, inv_eq_one_div, FractionalIdeal.coe_dual_one, FractionalIdeal.coe_one] variable {A K B L} open Submodule lemma differentialIdeal_le_fractionalIdeal_iff {I : FractionalIdeal B⁰ L} (hI : I ≠ 0) [NoZeroSMulDivisors A B] : differentIdeal A B ≤ I ↔ (((I⁻¹ : _) : Submodule B L).restrictScalars A).map ((Algebra.trace K L).restrictScalars A) ≤ 1 := by rw [coeIdeal_differentIdeal A K L B, FractionalIdeal.inv_le_comm (by simp) hI, ← FractionalIdeal.coe_le_coe, FractionalIdeal.coe_dual_one] refine le_traceDual_iff_map_le_one.trans ?_ simp lemma differentialIdeal_le_iff {I : Ideal B} (hI : I ≠ ⊥) [NoZeroSMulDivisors A B] : differentIdeal A B ≤ I ↔ (((I⁻¹ : FractionalIdeal B⁰ L) : Submodule B L).restrictScalars A).map ((Algebra.trace K L).restrictScalars A) ≤ 1 := (FractionalIdeal.coeIdeal_le_coeIdeal _).symm.trans (differentialIdeal_le_fractionalIdeal_iff (I := (I : FractionalIdeal B⁰ L)) (by simpa)) variable (A K) open Pointwise Polynomial in lemma traceForm_dualSubmodule_adjoin {x : L} (hx : Algebra.adjoin K {x} = ⊤) (hAx : IsIntegral A x) : (traceForm K L).dualSubmodule (Subalgebra.toSubmodule (Algebra.adjoin A {x})) = (aeval x (derivative <| minpoly K x) : L)⁻¹ • (Subalgebra.toSubmodule (Algebra.adjoin A {x})) := by classical have hKx : IsIntegral K x := Algebra.IsIntegral.isIntegral x let pb := (Algebra.adjoin.powerBasis' hKx).map ((Subalgebra.equivOfEq _ _ hx).trans (Subalgebra.topEquiv)) have pbgen : pb.gen = x := by simp [pb] have hpb : ⇑(LinearMap.BilinForm.dualBasis (traceForm K L) _ pb.basis) = _ := _root_.funext (traceForm_dualBasis_powerBasis_eq pb) have : (Subalgebra.toSubmodule (Algebra.adjoin A {x})) = Submodule.span A (Set.range pb.basis) := by rw [← span_range_natDegree_eq_adjoin (minpoly.monic hAx) (minpoly.aeval _ _)] congr; ext y have : natDegree (minpoly A x) = natDegree (minpoly K x) := by rw [minpoly.isIntegrallyClosed_eq_field_fractions' K hAx, (minpoly.monic hAx).natDegree_map] simp only [Finset.coe_image, Finset.coe_range, Set.mem_image, Set.mem_Iio, Set.mem_range, pb.basis_eq_pow, pbgen] simp only [PowerBasis.map_dim, adjoin.powerBasis'_dim, this] exact ⟨fun ⟨a, b, c⟩ ↦ ⟨⟨a, b⟩, c⟩, fun ⟨⟨a, b⟩, c⟩ ↦ ⟨a, b, c⟩⟩ clear_value pb conv_lhs => rw [this] rw [← span_coeff_minpolyDiv hAx, LinearMap.BilinForm.dualSubmodule_span_of_basis, Submodule.smul_span, hpb] show _ = Submodule.span A (_ '' _) simp only [← Set.range_comp, smul_eq_mul, div_eq_inv_mul, pbgen, minpolyDiv_eq_of_isIntegrallyClosed K hAx] apply le_antisymm <;> rw [Submodule.span_le] · rintro _ ⟨i, rfl⟩; exact Submodule.subset_span ⟨i, rfl⟩ · rintro _ ⟨i, rfl⟩ by_cases hi : i < pb.dim · exact Submodule.subset_span ⟨⟨i, hi⟩, rfl⟩ · rw [Function.comp_apply, coeff_eq_zero_of_natDegree_lt, mul_zero] · exact zero_mem _ rw [← pb.natDegree_minpoly, pbgen, ← natDegree_minpolyDiv_succ hKx, ← Nat.succ_eq_add_one] at hi exact le_of_not_lt hi end variable (L) {B} open Polynomial Pointwise in lemma conductor_mul_differentIdeal [NoZeroSMulDivisors A B] (x : B) (hx : Algebra.adjoin K {algebraMap B L x} = ⊤) : (conductor A x) * differentIdeal A B = Ideal.span {aeval x (derivative (minpoly A x))} := by classical have hAx : IsIntegral A x := IsIntegralClosure.isIntegral A L x haveI := IsIntegralClosure.isFractionRing_of_finite_extension A K L B apply FractionalIdeal.coeIdeal_injective (K := L) simp only [FractionalIdeal.coeIdeal_mul, FractionalIdeal.coeIdeal_span_singleton] rw [coeIdeal_differentIdeal A K L B, mul_inv_eq_iff_eq_mul₀] swap · exact FractionalIdeal.dual_ne_zero A K one_ne_zero apply FractionalIdeal.coeToSubmodule_injective simp only [FractionalIdeal.coe_coeIdeal, FractionalIdeal.coe_mul, FractionalIdeal.coe_spanSingleton, Submodule.span_singleton_mul] ext y have hne₁ : aeval (algebraMap B L x) (derivative (minpoly K (algebraMap B L x))) ≠ 0 := (Algebra.IsSeparable.isSeparable _ _).aeval_derivative_ne_zero (minpoly.aeval _ _) have : algebraMap B L (aeval x (derivative (minpoly A x))) ≠ 0 := by rwa [minpoly.isIntegrallyClosed_eq_field_fractions K L hAx, derivative_map, aeval_map_algebraMap, aeval_algebraMap_apply] at hne₁ rw [Submodule.mem_smul_iff_inv_mul_mem this, FractionalIdeal.mem_coe, FractionalIdeal.mem_dual, mem_coeSubmodule_conductor] swap · exact one_ne_zero have hne₂ : (aeval (algebraMap B L x) (derivative (minpoly K (algebraMap B L x))))⁻¹ ≠ 0 := by rwa [ne_eq, inv_eq_zero] have : IsIntegral A (algebraMap B L x) := IsIntegral.map (IsScalarTower.toAlgHom A B L) hAx simp_rw [← Subalgebra.mem_toSubmodule, ← Submodule.mul_mem_smul_iff (y := y * _) (mem_nonZeroDivisors_of_ne_zero hne₂)] rw [← traceForm_dualSubmodule_adjoin A K hx this] simp only [LinearMap.BilinForm.mem_dualSubmodule, traceForm_apply, Subalgebra.mem_toSubmodule, minpoly.isIntegrallyClosed_eq_field_fractions K L hAx, derivative_map, aeval_map_algebraMap, aeval_algebraMap_apply, mul_assoc, FractionalIdeal.mem_one_iff, forall_exists_index, forall_apply_eq_imp_iff] simp_rw [← IsScalarTower.toAlgHom_apply A B L x, ← AlgHom.map_adjoin_singleton] simp only [Subalgebra.mem_map, IsScalarTower.coe_toAlgHom', forall_exists_index, and_imp, forall_apply_eq_imp_iff₂, ← _root_.map_mul] exact ⟨fun H b ↦ (mul_one b) ▸ H b 1 (one_mem _), fun H _ _ _ ↦ H _⟩ open Polynomial Pointwise in lemma aeval_derivative_mem_differentIdeal [NoZeroSMulDivisors A B] (x : B) (hx : Algebra.adjoin K {algebraMap B L x} = ⊤) : aeval x (derivative (minpoly A x)) ∈ differentIdeal A B := by refine SetLike.le_def.mp ?_ (Ideal.mem_span_singleton_self _) rw [← conductor_mul_differentIdeal A K L x hx] exact Ideal.mul_le_left
RingTheory\DedekindDomain\Dvr.lean
/- Copyright (c) 2020 Kenji Nakagawa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenji Nakagawa, Anne Baanen, Filippo A. E. Nuccio -/ import Mathlib.RingTheory.Localization.LocalizationLocalization import Mathlib.RingTheory.Localization.Submodule import Mathlib.RingTheory.DiscreteValuationRing.TFAE /-! # Dedekind domains This file defines an equivalent notion of a Dedekind domain (or Dedekind ring), namely a Noetherian integral domain where the localization at all nonzero prime ideals is a DVR (TODO: and shows that implies the main definition). ## Main definitions - `IsDedekindDomainDvr` alternatively defines a Dedekind domain as an integral domain that is Noetherian, and the localization at every nonzero prime ideal is a DVR. ## Main results - `IsLocalization.AtPrime.discreteValuationRing_of_dedekind_domain` shows that `IsDedekindDomain` implies the localization at each nonzero prime ideal is a DVR. - `IsDedekindDomain.isDedekindDomainDvr` is one direction of the equivalence of definitions of a Dedekind domain ## Implementation notes The definitions that involve a field of fractions choose a canonical field of fractions, but are independent of that choice. The `..._iff` lemmas express this independence. Often, definitions assume that Dedekind domains are not fields. We found it more practical to add a `(h : ¬ IsField A)` assumption whenever this is explicitly needed. ## References * [D. Marcus, *Number Fields*][marcus1977number] * [J.W.S. Cassels, A. Frölich, *Algebraic Number Theory*][cassels1967algebraic] * [J. Neukirch, *Algebraic Number Theory*][Neukirch1992] ## Tags dedekind domain, dedekind ring -/ variable (R A K : Type*) [CommRing R] [CommRing A] [IsDomain A] [Field K] open scoped nonZeroDivisors Polynomial /-- A Dedekind domain is an integral domain that is Noetherian, and the localization at every nonzero prime is a discrete valuation ring. This is equivalent to `IsDedekindDomain`. TODO: prove the equivalence. -/ structure IsDedekindDomainDvr : Prop where isNoetherianRing : IsNoetherianRing A is_dvr_at_nonzero_prime : ∀ P ≠ (⊥ : Ideal A), ∀ _ : P.IsPrime, DiscreteValuationRing (Localization.AtPrime P) /-- Localizing a domain of Krull dimension `≤ 1` gives another ring of Krull dimension `≤ 1`. Note that the same proof can/should be generalized to preserving any Krull dimension, once we have a suitable definition. -/ theorem Ring.DimensionLEOne.localization {R : Type*} (Rₘ : Type*) [CommRing R] [IsDomain R] [CommRing Rₘ] [Algebra R Rₘ] {M : Submonoid R} [IsLocalization M Rₘ] (hM : M ≤ R⁰) [h : Ring.DimensionLEOne R] : Ring.DimensionLEOne Rₘ := ⟨by intro p hp0 hpp refine Ideal.isMaximal_def.mpr ⟨hpp.ne_top, Ideal.maximal_of_no_maximal fun P hpP hPm => ?_⟩ have hpP' : (⟨p, hpp⟩ : { p : Ideal Rₘ // p.IsPrime }) < ⟨P, hPm.isPrime⟩ := hpP rw [← (IsLocalization.orderIsoOfPrime M Rₘ).lt_iff_lt] at hpP' haveI : Ideal.IsPrime (Ideal.comap (algebraMap R Rₘ) p) := ((IsLocalization.orderIsoOfPrime M Rₘ) ⟨p, hpp⟩).2.1 haveI : Ideal.IsPrime (Ideal.comap (algebraMap R Rₘ) P) := ((IsLocalization.orderIsoOfPrime M Rₘ) ⟨P, hPm.isPrime⟩).2.1 have hlt : Ideal.comap (algebraMap R Rₘ) p < Ideal.comap (algebraMap R Rₘ) P := hpP' refine h.not_lt_lt ⊥ (Ideal.comap _ _) (Ideal.comap _ _) ⟨?_, hlt⟩ exact IsLocalization.bot_lt_comap_prime _ _ hM _ hp0⟩ /-- The localization of a Dedekind domain is a Dedekind domain. -/ theorem IsLocalization.isDedekindDomain [IsDedekindDomain A] {M : Submonoid A} (hM : M ≤ A⁰) (Aₘ : Type*) [CommRing Aₘ] [IsDomain Aₘ] [Algebra A Aₘ] [IsLocalization M Aₘ] : IsDedekindDomain Aₘ := by have h : ∀ y : M, IsUnit (algebraMap A (FractionRing A) y) := by rintro ⟨y, hy⟩ exact IsUnit.mk0 _ (mt IsFractionRing.to_map_eq_zero_iff.mp (nonZeroDivisors.ne_zero (hM hy))) letI : Algebra Aₘ (FractionRing A) := RingHom.toAlgebra (IsLocalization.lift h) haveI : IsScalarTower A Aₘ (FractionRing A) := IsScalarTower.of_algebraMap_eq fun x => (IsLocalization.lift_eq h x).symm haveI : IsFractionRing Aₘ (FractionRing A) := IsFractionRing.isFractionRing_of_isDomain_of_isLocalization M _ _ refine (isDedekindDomain_iff _ (FractionRing A)).mpr ⟨?_, ?_, ?_, ?_⟩ · infer_instance · exact IsLocalization.isNoetherianRing M _ (by infer_instance) · exact Ring.DimensionLEOne.localization Aₘ hM · intro x hx obtain ⟨⟨y, y_mem⟩, hy⟩ := hx.exists_multiple_integral_of_isLocalization M _ obtain ⟨z, hz⟩ := (isIntegrallyClosed_iff _).mp IsDedekindRing.toIsIntegralClosure hy refine ⟨IsLocalization.mk' Aₘ z ⟨y, y_mem⟩, (IsLocalization.lift_mk'_spec _ _ _ _).mpr ?_⟩ rw [hz, ← Algebra.smul_def] rfl /-- The localization of a Dedekind domain at every nonzero prime ideal is a Dedekind domain. -/ theorem IsLocalization.AtPrime.isDedekindDomain [IsDedekindDomain A] (P : Ideal A) [P.IsPrime] (Aₘ : Type*) [CommRing Aₘ] [IsDomain Aₘ] [Algebra A Aₘ] [IsLocalization.AtPrime Aₘ P] : IsDedekindDomain Aₘ := IsLocalization.isDedekindDomain A P.primeCompl_le_nonZeroDivisors Aₘ theorem IsLocalization.AtPrime.not_isField {P : Ideal A} (hP : P ≠ ⊥) [pP : P.IsPrime] (Aₘ : Type*) [CommRing Aₘ] [Algebra A Aₘ] [IsLocalization.AtPrime Aₘ P] : ¬IsField Aₘ := by intro h letI := h.toField obtain ⟨x, x_mem, x_ne⟩ := P.ne_bot_iff.mp hP exact (LocalRing.maximalIdeal.isMaximal _).ne_top (Ideal.eq_top_of_isUnit_mem _ ((IsLocalization.AtPrime.to_map_mem_maximal_iff Aₘ P _).mpr x_mem) (isUnit_iff_ne_zero.mpr ((map_ne_zero_iff (algebraMap A Aₘ) (IsLocalization.injective Aₘ P.primeCompl_le_nonZeroDivisors)).mpr x_ne))) /-- In a Dedekind domain, the localization at every nonzero prime ideal is a DVR. -/ theorem IsLocalization.AtPrime.discreteValuationRing_of_dedekind_domain [IsDedekindDomain A] {P : Ideal A} (hP : P ≠ ⊥) [pP : P.IsPrime] (Aₘ : Type*) [CommRing Aₘ] [IsDomain Aₘ] [Algebra A Aₘ] [IsLocalization.AtPrime Aₘ P] : DiscreteValuationRing Aₘ := by classical letI : IsNoetherianRing Aₘ := IsLocalization.isNoetherianRing P.primeCompl _ IsDedekindRing.toIsNoetherian letI : LocalRing Aₘ := IsLocalization.AtPrime.localRing Aₘ P have hnf := IsLocalization.AtPrime.not_isField A hP Aₘ exact ((DiscreteValuationRing.TFAE Aₘ hnf).out 0 2).mpr (IsLocalization.AtPrime.isDedekindDomain A P _) /-- Dedekind domains, in the sense of Noetherian integrally closed domains of Krull dimension ≤ 1, are also Dedekind domains in the sense of Noetherian domains where the localization at every nonzero prime ideal is a DVR. -/ theorem IsDedekindDomain.isDedekindDomainDvr [IsDedekindDomain A] : IsDedekindDomainDvr A := { isNoetherianRing := IsDedekindRing.toIsNoetherian is_dvr_at_nonzero_prime := fun _ hP _ => IsLocalization.AtPrime.discreteValuationRing_of_dedekind_domain A hP _ }
RingTheory\DedekindDomain\Factorization.lean
/- Copyright (c) 2022 María Inés de Frutos-Fernández. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: María Inés de Frutos-Fernández -/ import Mathlib.RingTheory.DedekindDomain.Ideal /-! # Factorization of ideals and fractional ideals of Dedekind domains Every nonzero ideal `I` of a Dedekind domain `R` can be factored as a product `∏_v v^{n_v}` over the maximal ideals of `R`, where the exponents `n_v` are natural numbers. Similarly, every nonzero fractional ideal `I` of a Dedekind domain `R` can be factored as a product `∏_v v^{n_v}` over the maximal ideals of `R`, where the exponents `n_v` are integers. We define `FractionalIdeal.count K v I` (abbreviated as `val_v(I)` in the documentation) to be `n_v`, and we prove some of its properties. If `I = 0`, we define `val_v(I) = 0`. ## Main definitions - `FractionalIdeal.count` : If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of `R` such that `I = a⁻¹J`, then we define `val_v(I)` as `(val_v(J) - val_v(a))`. If `I = 0`, we set `val_v(I) = 0`. ## Main results - `Ideal.finite_factors` : Only finitely many maximal ideals of `R` divide a given nonzero ideal. - `Ideal.finprod_heightOneSpectrum_factorization` : The ideal `I` equals the finprod `∏_v v^(val_v(I))`, where `val_v(I)` denotes the multiplicity of `v` in the factorization of `I` and `v` runs over the maximal ideals of `R`. - `FractionalIdeal.finprod_heightOneSpectrum_factorization` : If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of `R` such that `I = a⁻¹J`, then `I` is equal to the product `∏_v v^(val_v(J) - val_v(a))`. - `FractionalIdeal.finprod_heightOneSpectrum_factorization'` : If `I` is a nonzero fractional ideal, then `I` is equal to the product `∏_v v^(val_v(I))`. - `FractionalIdeal.finprod_heightOneSpectrum_factorization_principal` : For a nonzero `k = r/s ∈ K`, the fractional ideal `(k)` is equal to the product `∏_v v^(val_v(r) - val_v(s))`. - `FractionalIdeal.finite_factors` : If `I ≠ 0`, then `val_v(I) = 0` for all but finitely many maximal ideals of `R`. ## Implementation notes Since we are only interested in the factorization of nonzero fractional ideals, we define `val_v(0) = 0` so that every `val_v` is in `ℤ` and we can avoid having to use `WithTop ℤ`. ## Tags dedekind domain, fractional ideal, ideal, factorization -/ noncomputable section open scoped Classical nonZeroDivisors open Set Function UniqueFactorizationMonoid IsDedekindDomain IsDedekindDomain.HeightOneSpectrum Classical variable {R : Type*} [CommRing R] {K : Type*} [Field K] [Algebra R K] [IsFractionRing R K] /-! ### Factorization of ideals of Dedekind domains -/ variable [IsDedekindDomain R] (v : HeightOneSpectrum R) /-- Given a maximal ideal `v` and an ideal `I` of `R`, `maxPowDividing` returns the maximal power of `v` dividing `I`. -/ def IsDedekindDomain.HeightOneSpectrum.maxPowDividing (I : Ideal R) : Ideal R := v.asIdeal ^ (Associates.mk v.asIdeal).count (Associates.mk I).factors /-- Only finitely many maximal ideals of `R` divide a given nonzero ideal. -/ theorem Ideal.finite_factors {I : Ideal R} (hI : I ≠ 0) : {v : HeightOneSpectrum R | v.asIdeal ∣ I}.Finite := by rw [← Set.finite_coe_iff, Set.coe_setOf] haveI h_fin := fintypeSubtypeDvd I hI refine Finite.of_injective (fun v => (⟨(v : HeightOneSpectrum R).asIdeal, v.2⟩ : { x // x ∣ I })) ?_ intro v w hvw simp? at hvw says simp only [Subtype.mk.injEq] at hvw exact Subtype.coe_injective (HeightOneSpectrum.ext hvw) /-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that the multiplicity of `v` in the factorization of `I`, denoted `val_v(I)`, is nonzero. -/ theorem Associates.finite_factors {I : Ideal R} (hI : I ≠ 0) : ∀ᶠ v : HeightOneSpectrum R in Filter.cofinite, ((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ) = 0 := by have h_supp : {v : HeightOneSpectrum R | ¬((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ) = 0} = {v : HeightOneSpectrum R | v.asIdeal ∣ I} := by ext v simp_rw [Int.natCast_eq_zero] exact Associates.count_ne_zero_iff_dvd hI v.irreducible rw [Filter.eventually_cofinite, h_supp] exact Ideal.finite_factors hI namespace Ideal /-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that `v^(val_v(I))` is not the unit ideal. -/ theorem finite_mulSupport {I : Ideal R} (hI : I ≠ 0) : (mulSupport fun v : HeightOneSpectrum R => v.maxPowDividing I).Finite := haveI h_subset : {v : HeightOneSpectrum R | v.maxPowDividing I ≠ 1} ⊆ {v : HeightOneSpectrum R | ((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ) ≠ 0} := by intro v hv h_zero have hv' : v.maxPowDividing I = 1 := by rw [IsDedekindDomain.HeightOneSpectrum.maxPowDividing, Int.natCast_eq_zero.mp h_zero, pow_zero _] exact hv hv' Finite.subset (Filter.eventually_cofinite.mp (Associates.finite_factors hI)) h_subset /-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that `v^(val_v(I))`, regarded as a fractional ideal, is not `(1)`. -/ theorem finite_mulSupport_coe {I : Ideal R} (hI : I ≠ 0) : (mulSupport fun v : HeightOneSpectrum R => (v.asIdeal : FractionalIdeal R⁰ K) ^ ((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ)).Finite := by rw [mulSupport] simp_rw [Ne, zpow_natCast, ← FractionalIdeal.coeIdeal_pow, FractionalIdeal.coeIdeal_eq_one] exact finite_mulSupport hI /-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that `v^-(val_v(I))` is not the unit ideal. -/ theorem finite_mulSupport_inv {I : Ideal R} (hI : I ≠ 0) : (mulSupport fun v : HeightOneSpectrum R => (v.asIdeal : FractionalIdeal R⁰ K) ^ (-((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ))).Finite := by rw [mulSupport] simp_rw [zpow_neg, Ne, inv_eq_one] exact finite_mulSupport_coe hI /-- For every nonzero ideal `I` of `v`, `v^(val_v(I) + 1)` does not divide `∏_v v^(val_v(I))`. -/ theorem finprod_not_dvd (I : Ideal R) (hI : I ≠ 0) : ¬v.asIdeal ^ ((Associates.mk v.asIdeal).count (Associates.mk I).factors + 1) ∣ ∏ᶠ v : HeightOneSpectrum R, v.maxPowDividing I := by have hf := finite_mulSupport hI have h_ne_zero : v.maxPowDividing I ≠ 0 := pow_ne_zero _ v.ne_bot rw [← mul_finprod_cond_ne v hf, pow_add, pow_one, finprod_cond_ne _ _ hf] intro h_contr have hv_prime : Prime v.asIdeal := Ideal.prime_of_isPrime v.ne_bot v.isPrime obtain ⟨w, hw, hvw'⟩ := Prime.exists_mem_finset_dvd hv_prime ((mul_dvd_mul_iff_left h_ne_zero).mp h_contr) have hw_prime : Prime w.asIdeal := Ideal.prime_of_isPrime w.ne_bot w.isPrime have hvw := Prime.dvd_of_dvd_pow hv_prime hvw' rw [Prime.dvd_prime_iff_associated hv_prime hw_prime, associated_iff_eq] at hvw exact (Finset.mem_erase.mp hw).1 (HeightOneSpectrum.ext hvw.symm) end Ideal theorem Associates.finprod_ne_zero (I : Ideal R) : Associates.mk (∏ᶠ v : HeightOneSpectrum R, v.maxPowDividing I) ≠ 0 := by rw [Associates.mk_ne_zero, finprod_def] split_ifs · rw [Finset.prod_ne_zero_iff] intro v _ apply pow_ne_zero _ v.ne_bot · exact one_ne_zero namespace Ideal /-- The multiplicity of `v` in `∏_v v^(val_v(I))` equals `val_v(I)`. -/ theorem finprod_count (I : Ideal R) (hI : I ≠ 0) : (Associates.mk v.asIdeal).count (Associates.mk (∏ᶠ v : HeightOneSpectrum R, v.maxPowDividing I)).factors = (Associates.mk v.asIdeal).count (Associates.mk I).factors := by have h_ne_zero := Associates.finprod_ne_zero I have hv : Irreducible (Associates.mk v.asIdeal) := v.associates_irreducible have h_dvd := finprod_mem_dvd v (Ideal.finite_mulSupport hI) have h_not_dvd := Ideal.finprod_not_dvd v I hI simp only [IsDedekindDomain.HeightOneSpectrum.maxPowDividing] at h_dvd h_ne_zero h_not_dvd rw [← Associates.mk_dvd_mk] at h_dvd h_not_dvd simp only [Associates.dvd_eq_le] at h_dvd h_not_dvd rw [Associates.mk_pow, Associates.prime_pow_dvd_iff_le h_ne_zero hv] at h_dvd h_not_dvd rw [not_le] at h_not_dvd apply Nat.eq_of_le_of_lt_succ h_dvd h_not_dvd /-- The ideal `I` equals the finprod `∏_v v^(val_v(I))`. -/ theorem finprod_heightOneSpectrum_factorization {I : Ideal R} (hI : I ≠ 0) : ∏ᶠ v : HeightOneSpectrum R, v.maxPowDividing I = I := by rw [← associated_iff_eq, ← Associates.mk_eq_mk_iff_associated] apply Associates.eq_of_eq_counts · apply Associates.finprod_ne_zero I · apply Associates.mk_ne_zero.mpr hI intro v hv obtain ⟨J, hJv⟩ := Associates.exists_rep v rw [← hJv, Associates.irreducible_mk] at hv rw [← hJv] apply Ideal.finprod_count ⟨J, Ideal.isPrime_of_prime (irreducible_iff_prime.mp hv), Irreducible.ne_zero hv⟩ I hI variable (K) /-- The ideal `I` equals the finprod `∏_v v^(val_v(I))`, when both sides are regarded as fractional ideals of `R`. -/ theorem finprod_heightOneSpectrum_factorization_coe {I : Ideal R} (hI : I ≠ 0) : (∏ᶠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^ ((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ)) = I := by conv_rhs => rw [← Ideal.finprod_heightOneSpectrum_factorization hI] rw [FractionalIdeal.coeIdeal_finprod R⁰ K (le_refl _)] simp_rw [IsDedekindDomain.HeightOneSpectrum.maxPowDividing, FractionalIdeal.coeIdeal_pow, zpow_natCast] end Ideal /-! ### Factorization of fractional ideals of Dedekind domains -/ namespace FractionalIdeal open Int IsLocalization /-- If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of `R` such that `I = a⁻¹J`, then `I` is equal to the product `∏_v v^(val_v(J) - val_v(a))`. -/ theorem finprod_heightOneSpectrum_factorization {I : FractionalIdeal R⁰ K} (hI : I ≠ 0) {a : R} {J : Ideal R} (haJ : I = spanSingleton R⁰ ((algebraMap R K) a)⁻¹ * ↑J) : ∏ᶠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^ ((Associates.mk v.asIdeal).count (Associates.mk J).factors - (Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {a})).factors : ℤ) = I := by have hJ_ne_zero : J ≠ 0 := ideal_factor_ne_zero hI haJ have hJ := Ideal.finprod_heightOneSpectrum_factorization_coe K hJ_ne_zero have ha_ne_zero : Ideal.span {a} ≠ 0 := constant_factor_ne_zero hI haJ have ha := Ideal.finprod_heightOneSpectrum_factorization_coe K ha_ne_zero rw [haJ, ← div_spanSingleton, div_eq_mul_inv, ← coeIdeal_span_singleton, ← hJ, ← ha, ← finprod_inv_distrib] simp_rw [← zpow_neg] rw [← finprod_mul_distrib (Ideal.finite_mulSupport_coe hJ_ne_zero) (Ideal.finite_mulSupport_inv ha_ne_zero)] apply finprod_congr intro v rw [← zpow_add₀ ((@coeIdeal_ne_zero R _ K _ _ _ _).mpr v.ne_bot), sub_eq_add_neg] /-- For a nonzero `k = r/s ∈ K`, the fractional ideal `(k)` is equal to the product `∏_v v^(val_v(r) - val_v(s))`. -/ theorem finprod_heightOneSpectrum_factorization_principal_fraction {n : R} (hn : n ≠ 0) (d : ↥R⁰) : ∏ᶠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^ ((Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {n} : Ideal R)).factors - (Associates.mk v.asIdeal).count (Associates.mk ((Ideal.span {(↑d : R)}) : Ideal R)).factors : ℤ) = spanSingleton R⁰ (mk' K n d) := by have hd_ne_zero : (algebraMap R K) (d : R) ≠ 0 := map_ne_zero_of_mem_nonZeroDivisors _ (IsFractionRing.injective R K) d.property have h0 : spanSingleton R⁰ (mk' K n d) ≠ 0 := by rw [spanSingleton_ne_zero_iff, IsFractionRing.mk'_eq_div, ne_eq, div_eq_zero_iff, not_or] exact ⟨(map_ne_zero_iff (algebraMap R K) (IsFractionRing.injective R K)).mpr hn, hd_ne_zero⟩ have hI : spanSingleton R⁰ (mk' K n d) = spanSingleton R⁰ ((algebraMap R K) d)⁻¹ * ↑(Ideal.span {n} : Ideal R) := by rw [coeIdeal_span_singleton, spanSingleton_mul_spanSingleton] apply congr_arg rw [IsFractionRing.mk'_eq_div, div_eq_mul_inv, mul_comm] exact finprod_heightOneSpectrum_factorization h0 hI /-- For a nonzero `k = r/s ∈ K`, the fractional ideal `(k)` is equal to the product `∏_v v^(val_v(r) - val_v(s))`. -/ theorem finprod_heightOneSpectrum_factorization_principal {I : FractionalIdeal R⁰ K} (hI : I ≠ 0) (k : K) (hk : I = spanSingleton R⁰ k) : ∏ᶠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^ ((Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {choose (mk'_surjective R⁰ k)} : Ideal R)).factors - (Associates.mk v.asIdeal).count (Associates.mk ((Ideal.span {(↑(choose (choose_spec (mk'_surjective R⁰ k)) : ↥R⁰) : R)}) : Ideal R)).factors : ℤ) = I := by set n : R := choose (mk'_surjective R⁰ k) set d : ↥R⁰ := choose (choose_spec (mk'_surjective R⁰ k)) have hnd : mk' K n d = k := choose_spec (choose_spec (mk'_surjective R⁰ k)) have hn0 : n ≠ 0 := by by_contra h rw [← hnd, h, IsFractionRing.mk'_eq_div, _root_.map_zero, zero_div, spanSingleton_zero] at hk exact hI hk rw [finprod_heightOneSpectrum_factorization_principal_fraction hn0 d, hk, hnd] variable (K) /-- If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of `R` such that `I = a⁻¹J`, then we define `val_v(I)` as `(val_v(J) - val_v(a))`. If `I = 0`, we set `val_v(I) = 0`. -/ def count (I : FractionalIdeal R⁰ K) : ℤ := dite (I = 0) (fun _ : I = 0 => 0) fun _ : ¬I = 0 => let a := choose (exists_eq_spanSingleton_mul I) let J := choose (choose_spec (exists_eq_spanSingleton_mul I)) ((Associates.mk v.asIdeal).count (Associates.mk J).factors - (Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {a})).factors : ℤ) /-- val_v(0) = 0. -/ lemma count_zero : count K v (0 : FractionalIdeal R⁰ K) = 0 := by simp only [count, dif_pos] lemma count_ne_zero {I : FractionalIdeal R⁰ K} (hI : I ≠ 0) : count K v I = ((Associates.mk v.asIdeal).count (Associates.mk (choose (choose_spec (exists_eq_spanSingleton_mul I)))).factors - (Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {choose (exists_eq_spanSingleton_mul I)})).factors : ℤ) := by simp only [count, dif_neg hI] /-- `val_v(I)` does not depend on the choice of `a` and `J` used to represent `I`. -/ theorem count_well_defined {I : FractionalIdeal R⁰ K} (hI : I ≠ 0) {a : R} {J : Ideal R} (h_aJ : I = spanSingleton R⁰ ((algebraMap R K) a)⁻¹ * ↑J) : count K v I = ((Associates.mk v.asIdeal).count (Associates.mk J).factors - (Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {a})).factors : ℤ) := by set a₁ := choose (exists_eq_spanSingleton_mul I) set J₁ := choose (choose_spec (exists_eq_spanSingleton_mul I)) have h_a₁J₁ : I = spanSingleton R⁰ ((algebraMap R K) a₁)⁻¹ * ↑J₁ := (choose_spec (choose_spec (exists_eq_spanSingleton_mul I))).2 have h_a₁_ne_zero : a₁ ≠ 0 := (choose_spec (choose_spec (exists_eq_spanSingleton_mul I))).1 have h_J₁_ne_zero : J₁ ≠ 0 := ideal_factor_ne_zero hI h_a₁J₁ have h_a_ne_zero : Ideal.span {a} ≠ 0 := constant_factor_ne_zero hI h_aJ have h_J_ne_zero : J ≠ 0 := ideal_factor_ne_zero hI h_aJ have h_a₁' : spanSingleton R⁰ ((algebraMap R K) a₁) ≠ 0 := by rw [ne_eq, spanSingleton_eq_zero_iff, ← (algebraMap R K).map_zero, Injective.eq_iff (IsLocalization.injective K (le_refl R⁰))] exact h_a₁_ne_zero have h_a' : spanSingleton R⁰ ((algebraMap R K) a) ≠ 0 := by rw [ne_eq, spanSingleton_eq_zero_iff, ← (algebraMap R K).map_zero, Injective.eq_iff (IsLocalization.injective K (le_refl R⁰))] rw [ne_eq, Ideal.zero_eq_bot, Ideal.span_singleton_eq_bot] at h_a_ne_zero exact h_a_ne_zero have hv : Irreducible (Associates.mk v.asIdeal) := by exact Associates.irreducible_mk.mpr v.irreducible rw [h_a₁J₁, ← div_spanSingleton, ← div_spanSingleton, div_eq_div_iff h_a₁' h_a', ← coeIdeal_span_singleton, ← coeIdeal_span_singleton, ← coeIdeal_mul, ← coeIdeal_mul] at h_aJ rw [count, dif_neg hI, sub_eq_sub_iff_add_eq_add, ← ofNat_add, ← ofNat_add, natCast_inj, ← Associates.count_mul _ _ hv, ← Associates.count_mul _ _ hv, Associates.mk_mul_mk, Associates.mk_mul_mk, coeIdeal_injective h_aJ] · rw [ne_eq, Associates.mk_eq_zero]; exact h_J_ne_zero · rw [ne_eq, Associates.mk_eq_zero, Ideal.zero_eq_bot, Ideal.span_singleton_eq_bot] exact h_a₁_ne_zero · rw [ne_eq, Associates.mk_eq_zero]; exact h_J₁_ne_zero · rw [ne_eq, Associates.mk_eq_zero]; exact h_a_ne_zero /-- For nonzero `I, I'`, `val_v(I*I') = val_v(I) + val_v(I')`. -/ theorem count_mul {I I' : FractionalIdeal R⁰ K} (hI : I ≠ 0) (hI' : I' ≠ 0) : count K v (I * I') = count K v I + count K v I' := by have hv : Irreducible (Associates.mk v.asIdeal) := by apply v.associates_irreducible obtain ⟨a, J, ha, haJ⟩ := exists_eq_spanSingleton_mul I have ha_ne_zero : Associates.mk (Ideal.span {a} : Ideal R) ≠ 0 := by rw [ne_eq, Associates.mk_eq_zero, Ideal.zero_eq_bot, Ideal.span_singleton_eq_bot]; exact ha have hJ_ne_zero : Associates.mk J ≠ 0 := Associates.mk_ne_zero.mpr (ideal_factor_ne_zero hI haJ) obtain ⟨a', J', ha', haJ'⟩ := exists_eq_spanSingleton_mul I' have ha'_ne_zero : Associates.mk (Ideal.span {a'} : Ideal R) ≠ 0 := by rw [ne_eq, Associates.mk_eq_zero, Ideal.zero_eq_bot, Ideal.span_singleton_eq_bot]; exact ha' have hJ'_ne_zero : Associates.mk J' ≠ 0 := Associates.mk_ne_zero.mpr (ideal_factor_ne_zero hI' haJ') have h_prod : I * I' = spanSingleton R⁰ ((algebraMap R K) (a * a'))⁻¹ * ↑(J * J') := by rw [haJ, haJ', mul_assoc, mul_comm (J : FractionalIdeal R⁰ K), mul_assoc, ← mul_assoc, spanSingleton_mul_spanSingleton, coeIdeal_mul, RingHom.map_mul, mul_inv, mul_comm (J : FractionalIdeal R⁰ K)] rw [count_well_defined K v hI haJ, count_well_defined K v hI' haJ', count_well_defined K v (mul_ne_zero hI hI') h_prod, ← Associates.mk_mul_mk, Associates.count_mul hJ_ne_zero hJ'_ne_zero hv, ← Ideal.span_singleton_mul_span_singleton, ← Associates.mk_mul_mk, Associates.count_mul ha_ne_zero ha'_ne_zero hv] push_cast ring /-- For nonzero `I, I'`, `val_v(I*I') = val_v(I) + val_v(I')`. If `I` or `I'` is zero, then `val_v(I*I') = 0`. -/ theorem count_mul' (I I' : FractionalIdeal R⁰ K) : count K v (I * I') = if I ≠ 0 ∧ I' ≠ 0 then count K v I + count K v I' else 0 := by split_ifs with h · exact count_mul K v h.1 h.2 · push_neg at h by_cases hI : I = 0 · rw [hI, MulZeroClass.zero_mul, count, dif_pos (Eq.refl _)] · rw [h hI, MulZeroClass.mul_zero, count, dif_pos (Eq.refl _)] /-- val_v(1) = 0. -/ theorem count_one : count K v (1 : FractionalIdeal R⁰ K) = 0 := by have h1 : (1 : FractionalIdeal R⁰ K) = spanSingleton R⁰ ((algebraMap R K) 1)⁻¹ * ↑(1 : Ideal R) := by rw [(algebraMap R K).map_one, Ideal.one_eq_top, coeIdeal_top, mul_one, inv_one, spanSingleton_one] rw [count_well_defined K v one_ne_zero h1, Ideal.span_singleton_one, Ideal.one_eq_top, sub_self] theorem count_prod {ι} (s : Finset ι) (I : ι → FractionalIdeal R⁰ K) (hS : ∀ i ∈ s, I i ≠ 0) : count K v (∏ i ∈ s, I i) = ∑ i ∈ s, count K v (I i) := by induction' s using Finset.induction with i s hi hrec · rw [Finset.prod_empty, Finset.sum_empty, count_one] · have hS' : ∀ i ∈ s, I i ≠ 0 := fun j hj => hS j (Finset.mem_insert_of_mem hj) have hS0 : ∏ i ∈ s, I i ≠ 0 := Finset.prod_ne_zero_iff.mpr hS' have hi0 : I i ≠ 0 := hS i (Finset.mem_insert_self i s) rw [Finset.prod_insert hi, Finset.sum_insert hi, count_mul K v hi0 hS0, hrec hS'] /-- For every `n ∈ ℕ` and every ideal `I`, `val_v(I^n) = n*val_v(I)`. -/ theorem count_pow (n : ℕ) (I : FractionalIdeal R⁰ K) : count K v (I ^ n) = n * count K v I := by induction' n with n h · rw [pow_zero, ofNat_zero, MulZeroClass.zero_mul, count_one] · rw [pow_succ, count_mul'] by_cases hI : I = 0 · have h_neg : ¬(I ^ n ≠ 0 ∧ I ≠ 0) := by rw [not_and', not_not, ne_eq] intro h exact absurd hI h rw [if_neg h_neg, hI, count_zero, MulZeroClass.mul_zero] · rw [if_pos (And.intro (pow_ne_zero n hI) hI), h, Nat.cast_add, Nat.cast_one] ring /-- `val_v(v) = 1`, when `v` is regarded as a fractional ideal. -/ theorem count_self : count K v (v.asIdeal : FractionalIdeal R⁰ K) = 1 := by have hv : (v.asIdeal : FractionalIdeal R⁰ K) ≠ 0 := coeIdeal_ne_zero.mpr v.ne_bot have h_self : (v.asIdeal : FractionalIdeal R⁰ K) = spanSingleton R⁰ ((algebraMap R K) 1)⁻¹ * ↑v.asIdeal := by rw [(algebraMap R K).map_one, inv_one, spanSingleton_one, one_mul] have hv_irred : Irreducible (Associates.mk v.asIdeal) := by apply v.associates_irreducible rw [count_well_defined K v hv h_self, Associates.count_self hv_irred, Ideal.span_singleton_one, ← Ideal.one_eq_top, Associates.mk_one, Associates.factors_one, Associates.count_zero hv_irred, ofNat_zero, sub_zero, ofNat_one] /-- `val_v(v^n) = n` for every `n ∈ ℕ`. -/ theorem count_pow_self (n : ℕ) : count K v ((v.asIdeal : FractionalIdeal R⁰ K) ^ n) = n := by rw [count_pow, count_self, mul_one] /-- `val_v(I⁻ⁿ) = -val_v(Iⁿ)` for every `n ∈ ℤ`. -/ theorem count_neg_zpow (n : ℤ) (I : FractionalIdeal R⁰ K) : count K v (I ^ (-n)) = - count K v (I ^ n) := by by_cases hI : I = 0 · by_cases hn : n = 0 · rw [hn, neg_zero, zpow_zero, count_one, neg_zero] · rw [hI, zero_zpow n hn, zero_zpow (-n) (neg_ne_zero.mpr hn), count_zero, neg_zero] · rw [eq_neg_iff_add_eq_zero, ← count_mul K v (zpow_ne_zero _ hI) (zpow_ne_zero _ hI), ← zpow_add₀ hI, neg_add_self, zpow_zero] exact count_one K v theorem count_inv (I : FractionalIdeal R⁰ K) : count K v (I⁻¹) = - count K v I := by rw [← zpow_neg_one, count_neg_zpow K v (1 : ℤ) I, zpow_one] /-- `val_v(Iⁿ) = n*val_v(I)` for every `n ∈ ℤ`. -/ theorem count_zpow (n : ℤ) (I : FractionalIdeal R⁰ K) : count K v (I ^ n) = n * count K v I := by cases' n with n · rw [ofNat_eq_coe, zpow_natCast] exact count_pow K v n I · rw [negSucc_coe, count_neg_zpow, zpow_natCast, count_pow] ring /-- `val_v(v^n) = n` for every `n ∈ ℤ`. -/ theorem count_zpow_self (n : ℤ) : count K v ((v.asIdeal : FractionalIdeal R⁰ K) ^ n) = n := by rw [count_zpow, count_self, mul_one] /-- If `v ≠ w` are two maximal ideals of `R`, then `val_v(w) = 0`. -/ theorem count_maximal_coprime {w : HeightOneSpectrum R} (hw : w ≠ v) : count K v (w.asIdeal : FractionalIdeal R⁰ K) = 0 := by have hw_fact : (w.asIdeal : FractionalIdeal R⁰ K) = spanSingleton R⁰ ((algebraMap R K) 1)⁻¹ * ↑w.asIdeal := by rw [(algebraMap R K).map_one, inv_one, spanSingleton_one, one_mul] have hw_ne_zero : (w.asIdeal : FractionalIdeal R⁰ K) ≠ 0 := coeIdeal_ne_zero.mpr w.ne_bot have hv : Irreducible (Associates.mk v.asIdeal) := by apply v.associates_irreducible have hw' : Irreducible (Associates.mk w.asIdeal) := by apply w.associates_irreducible rw [count_well_defined K v hw_ne_zero hw_fact, Ideal.span_singleton_one, ← Ideal.one_eq_top, Associates.mk_one, Associates.factors_one, Associates.count_zero hv, ofNat_zero, sub_zero, natCast_eq_zero, ← pow_one (Associates.mk w.asIdeal), Associates.factors_prime_pow hw', Associates.count_some hv, Multiset.replicate_one, Multiset.count_eq_zero, Multiset.mem_singleton] simp only [Subtype.mk.injEq] rw [Associates.mk_eq_mk_iff_associated, associated_iff_eq, ← HeightOneSpectrum.ext_iff] exact Ne.symm hw theorem count_maximal (w : HeightOneSpectrum R) : count K v (w.asIdeal : FractionalIdeal R⁰ K) = if w = v then 1 else 0 := by split_ifs with h · rw [h, count_self] · exact count_maximal_coprime K v h /-- `val_v(∏_{w ≠ v} w^{exps w}) = 0`. -/ theorem count_finprod_coprime (exps : HeightOneSpectrum R → ℤ) : count K v (∏ᶠ (w : HeightOneSpectrum R) (_ : w ≠ v), (w.asIdeal : (FractionalIdeal R⁰ K)) ^ exps w) = 0 := by apply finprod_mem_induction fun I => count K v I = 0 · exact count_one K v · intro I I' hI hI' by_cases h : I ≠ 0 ∧ I' ≠ 0 · rw [count_mul' K v, if_pos h, hI, hI', add_zero] · rw [count_mul' K v, if_neg h] · intro w hw rw [count_zpow, count_maximal_coprime K v hw, MulZeroClass.mul_zero] theorem count_finsupp_prod (exps : HeightOneSpectrum R →₀ ℤ) : count K v (exps.prod (HeightOneSpectrum.asIdeal · ^ ·)) = exps v := by rw [Finsupp.prod, count_prod] · simp only [count_zpow, count_maximal, mul_ite, mul_one, mul_zero, Finset.sum_ite_eq', exps.mem_support_iff, ne_eq, ite_not, ite_eq_right_iff, @eq_comm ℤ 0, imp_self] · exact fun v hv ↦ zpow_ne_zero _ (coeIdeal_ne_zero.mpr v.ne_bot) /-- If `exps` is finitely supported, then `val_v(∏_w w^{exps w}) = exps v`. -/ theorem count_finprod (exps : HeightOneSpectrum R → ℤ) (h_exps : ∀ᶠ v : HeightOneSpectrum R in Filter.cofinite, exps v = 0) : count K v (∏ᶠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^ exps v) = exps v := by convert count_finsupp_prod K v (Finsupp.mk h_exps.toFinset exps (fun _ ↦ h_exps.mem_toFinset)) rw [finprod_eq_finset_prod_of_mulSupport_subset (s := h_exps.toFinset), Finsupp.prod] · rfl · rw [Finite.coe_toFinset] intro v hv h rw [mem_mulSupport, h, zpow_zero] at hv exact hv (Eq.refl 1) theorem count_coe {J : Ideal R} (hJ : J ≠ 0) : count K v J = (Associates.mk v.asIdeal).count (Associates.mk J).factors := by rw [count_well_defined K (J := J) (a := 1), Ideal.span_singleton_one, sub_eq_self, Nat.cast_eq_zero, ← Ideal.one_eq_top, Associates.mk_one, Associates.factors_one, Associates.count_zero v.associates_irreducible] · simpa only [ne_eq, coeIdeal_eq_zero] · simp only [_root_.map_one, inv_one, spanSingleton_one, one_mul] theorem count_coe_nonneg (J : Ideal R) : 0 ≤ count K v J := by by_cases hJ : J = 0 · simp only [hJ, Submodule.zero_eq_bot, coeIdeal_bot, count_zero, le_refl] · simp only [count_coe K v hJ, Nat.cast_nonneg] theorem count_mono {I J} (hI : I ≠ 0) (h : I ≤ J) : count K v J ≤ count K v I := by by_cases hJ : J = 0 · exact (hI (FractionalIdeal.le_zero_iff.mp (h.trans hJ.le))).elim have := FractionalIdeal.mul_le_mul_left h J⁻¹ rw [inv_mul_cancel hJ, FractionalIdeal.le_one_iff_exists_coeIdeal] at this obtain ⟨J', hJ'⟩ := this rw [← mul_inv_cancel_left₀ hJ I, ← hJ', count_mul K v hJ, le_add_iff_nonneg_right] · exact count_coe_nonneg K v J' · exact hJ' ▸ mul_ne_zero (inv_ne_zero hJ) hI /-- If `I` is a nonzero fractional ideal, then `I` is equal to the product `∏_v v^(count K v I)`. -/ theorem finprod_heightOneSpectrum_factorization' {I : FractionalIdeal R⁰ K} (hI : I ≠ 0) : ∏ᶠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^ (count K v I) = I := by have h := (choose_spec (choose_spec (exists_eq_spanSingleton_mul I))).2 conv_rhs => rw [← finprod_heightOneSpectrum_factorization hI h] apply finprod_congr intro w apply congr_arg rw [count_ne_zero K w hI] variable {K} /-- If `I ≠ 0`, then `val_v(I) = 0` for all but finitely many maximal ideals of `R`. -/ theorem finite_factors' {I : FractionalIdeal R⁰ K} (hI : I ≠ 0) {a : R} {J : Ideal R} (haJ : I = spanSingleton R⁰ ((algebraMap R K) a)⁻¹ * ↑J) : ∀ᶠ v : HeightOneSpectrum R in Filter.cofinite, ((Associates.mk v.asIdeal).count (Associates.mk J).factors : ℤ) - (Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {a})).factors = 0 := by have ha_ne_zero : Ideal.span {a} ≠ 0 := constant_factor_ne_zero hI haJ have hJ_ne_zero : J ≠ 0 := ideal_factor_ne_zero hI haJ have h_subset : {v : HeightOneSpectrum R | ¬((Associates.mk v.asIdeal).count (Associates.mk J).factors : ℤ) - ↑((Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {a})).factors) = 0} ⊆ {v : HeightOneSpectrum R | v.asIdeal ∣ J} ∪ {v : HeightOneSpectrum R | v.asIdeal ∣ Ideal.span {a}} := by intro v hv have hv_irred : Irreducible v.asIdeal := v.irreducible by_contra h_nmem rw [mem_union, mem_setOf_eq, mem_setOf_eq] at h_nmem push_neg at h_nmem rw [← Associates.count_ne_zero_iff_dvd ha_ne_zero hv_irred, not_not, ← Associates.count_ne_zero_iff_dvd hJ_ne_zero hv_irred, not_not] at h_nmem rw [mem_setOf_eq, h_nmem.1, h_nmem.2, sub_self] at hv exact hv (Eq.refl 0) exact Finite.subset (Finite.union (Ideal.finite_factors (ideal_factor_ne_zero hI haJ)) (Ideal.finite_factors (constant_factor_ne_zero hI haJ))) h_subset /-- `val_v(I) = 0` for all but finitely many maximal ideals of `R`. -/ theorem finite_factors (I : FractionalIdeal R⁰ K) : ∀ᶠ v : HeightOneSpectrum R in Filter.cofinite, count K v I = 0 := by by_cases hI : I = 0 · simp only [hI, count_zero, Filter.eventually_cofinite, not_true_eq_false, setOf_false, finite_empty] · convert finite_factors' hI (choose_spec (choose_spec (exists_eq_spanSingleton_mul I))).2 rw [count_ne_zero K _ hI] end FractionalIdeal
RingTheory\DedekindDomain\FiniteAdeleRing.lean
/- Copyright (c) 2023 María Inés de Frutos-Fernández. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: María Inés de Frutos-Fernández -/ import Mathlib.RingTheory.DedekindDomain.AdicValuation import Mathlib.RingTheory.DedekindDomain.Factorization import Mathlib.Algebra.Order.GroupWithZero.WithZero /-! # The finite adèle ring of a Dedekind domain We define the ring of finite adèles of a Dedekind domain `R`. ## Main definitions - `DedekindDomain.FiniteIntegralAdeles` : product of `adicCompletionIntegers`, where `v` runs over all maximal ideals of `R`. - `DedekindDomain.ProdAdicCompletions` : the product of `adicCompletion`, where `v` runs over all maximal ideals of `R`. - `DedekindDomain.finiteAdeleRing` : The finite adèle ring of `R`, defined as the restricted product `Π'_v K_v`. We give this ring a `K`-algebra structure. ## Implementation notes We are only interested on Dedekind domains of Krull dimension 1 (i.e., not fields). If `R` is a field, its finite adèle ring is just defined to be the trivial ring. ## References * [J.W.S. Cassels, A. Frölich, *Algebraic Number Theory*][cassels1967algebraic] ## Tags finite adèle ring, dedekind domain -/ noncomputable section open Function Set IsDedekindDomain IsDedekindDomain.HeightOneSpectrum namespace DedekindDomain variable (R K : Type*) [CommRing R] [IsDedekindDomain R] [Field K] [Algebra R K] [IsFractionRing R K] (v : HeightOneSpectrum R) /-- The product of all `adicCompletionIntegers`, where `v` runs over the maximal ideals of `R`. -/ def FiniteIntegralAdeles : Type _ := ∀ v : HeightOneSpectrum R, v.adicCompletionIntegers K -- deriving CommRing, TopologicalSpace, Inhabited -- Porting note(https://github.com/leanprover-community/mathlib4/issues/5020): added section DerivedInstances instance : CommRing (FiniteIntegralAdeles R K) := inferInstanceAs (CommRing (∀ v : HeightOneSpectrum R, v.adicCompletionIntegers K)) instance : TopologicalSpace (FiniteIntegralAdeles R K) := inferInstanceAs (TopologicalSpace (∀ v : HeightOneSpectrum R, v.adicCompletionIntegers K)) instance : TopologicalRing (FiniteIntegralAdeles R K) := inferInstanceAs (TopologicalRing (∀ v : HeightOneSpectrum R, v.adicCompletionIntegers K)) instance : Inhabited (FiniteIntegralAdeles R K) := inferInstanceAs (Inhabited (∀ v : HeightOneSpectrum R, v.adicCompletionIntegers K)) end DerivedInstances local notation "R_hat" => FiniteIntegralAdeles /-- The product of all `adicCompletion`, where `v` runs over the maximal ideals of `R`. -/ def ProdAdicCompletions := ∀ v : HeightOneSpectrum R, v.adicCompletion K -- deriving NonUnitalNonAssocRing, TopologicalSpace, TopologicalRing, CommRing, Inhabited section DerivedInstances instance : NonUnitalNonAssocRing (ProdAdicCompletions R K) := inferInstanceAs (NonUnitalNonAssocRing (∀ v : HeightOneSpectrum R, v.adicCompletion K)) instance : TopologicalSpace (ProdAdicCompletions R K) := inferInstanceAs (TopologicalSpace (∀ v : HeightOneSpectrum R, v.adicCompletion K)) instance : TopologicalRing (ProdAdicCompletions R K) := inferInstanceAs (TopologicalRing (∀ v : HeightOneSpectrum R, v.adicCompletion K)) instance : CommRing (ProdAdicCompletions R K) := inferInstanceAs (CommRing (∀ v : HeightOneSpectrum R, v.adicCompletion K)) instance : Inhabited (ProdAdicCompletions R K) := inferInstanceAs (Inhabited (∀ v : HeightOneSpectrum R, v.adicCompletion K)) end DerivedInstances local notation "K_hat" => ProdAdicCompletions namespace FiniteIntegralAdeles noncomputable instance : Coe (R_hat R K) (K_hat R K) where coe x v := x v theorem coe_apply (x : R_hat R K) (v : HeightOneSpectrum R) : (x : K_hat R K) v = ↑(x v) := rfl /-- The inclusion of `R_hat` in `K_hat` as a homomorphism of additive monoids. -/ @[simps] def Coe.addMonoidHom : AddMonoidHom (R_hat R K) (K_hat R K) where toFun := (↑) map_zero' := rfl map_add' x y := by -- Porting note: was `ext v` refine funext fun v => ?_ simp only [coe_apply, Pi.add_apply, Subring.coe_add] -- Porting note: added erw [Pi.add_apply, Pi.add_apply, Subring.coe_add] /-- The inclusion of `R_hat` in `K_hat` as a ring homomorphism. -/ @[simps] def Coe.ringHom : RingHom (R_hat R K) (K_hat R K) := { Coe.addMonoidHom R K with toFun := (↑) map_one' := rfl map_mul' := fun x y => by -- Porting note: was `ext p` refine funext fun p => ?_ simp only [Pi.mul_apply, Subring.coe_mul] -- Porting note: added erw [Pi.mul_apply, Pi.mul_apply, Subring.coe_mul] } end FiniteIntegralAdeles section AlgebraInstances instance : Algebra K (K_hat R K) := (by infer_instance : Algebra K <| ∀ v : HeightOneSpectrum R, v.adicCompletion K) @[simp] lemma ProdAdicCompletions.algebraMap_apply' (k : K) : algebraMap K (K_hat R K) k v = (k : v.adicCompletion K) := rfl instance ProdAdicCompletions.algebra' : Algebra R (K_hat R K) := (by infer_instance : Algebra R <| ∀ v : HeightOneSpectrum R, v.adicCompletion K) @[simp] lemma ProdAdicCompletions.algebraMap_apply (r : R) : algebraMap R (K_hat R K) r v = (algebraMap R K r : v.adicCompletion K) := rfl instance : IsScalarTower R K (K_hat R K) := (by infer_instance : IsScalarTower R K <| ∀ v : HeightOneSpectrum R, v.adicCompletion K) instance : Algebra R (R_hat R K) := (by infer_instance : Algebra R <| ∀ v : HeightOneSpectrum R, v.adicCompletionIntegers K) instance ProdAdicCompletions.algebraCompletions : Algebra (R_hat R K) (K_hat R K) := (FiniteIntegralAdeles.Coe.ringHom R K).toAlgebra instance ProdAdicCompletions.isScalarTower_completions : IsScalarTower R (R_hat R K) (K_hat R K) := (by infer_instance : IsScalarTower R (∀ v : HeightOneSpectrum R, v.adicCompletionIntegers K) <| ∀ v : HeightOneSpectrum R, v.adicCompletion K) end AlgebraInstances namespace FiniteIntegralAdeles /-- The inclusion of `R_hat` in `K_hat` as an algebra homomorphism. -/ def Coe.algHom : AlgHom R (R_hat R K) (K_hat R K) := { Coe.ringHom R K with toFun := (↑) commutes' := fun _ => rfl } theorem Coe.algHom_apply (x : R_hat R K) (v : HeightOneSpectrum R) : (Coe.algHom R K) x v = x v := rfl end FiniteIntegralAdeles /-! ### The finite adèle ring of a Dedekind domain We define the finite adèle ring of `R` as the restricted product over all maximal ideals `v` of `R` of `adicCompletion` with respect to `adicCompletionIntegers`. We prove that it is a commutative ring. TODO: show that it is a topological ring with the restricted product topology. -/ namespace ProdAdicCompletions variable {R K} /-- An element `x : K_hat R K` is a finite adèle if for all but finitely many height one ideals `v`, the component `x v` is a `v`-adic integer. -/ def IsFiniteAdele (x : K_hat R K) := ∀ᶠ v : HeightOneSpectrum R in Filter.cofinite, x v ∈ v.adicCompletionIntegers K @[simp] lemma isFiniteAdele_iff (x : K_hat R K) : x.IsFiniteAdele ↔ {v | x v ∉ adicCompletionIntegers K v}.Finite := Iff.rfl namespace IsFiniteAdele /-- The sum of two finite adèles is a finite adèle. -/ theorem add {x y : K_hat R K} (hx : x.IsFiniteAdele) (hy : y.IsFiniteAdele) : (x + y).IsFiniteAdele := by rw [IsFiniteAdele, Filter.eventually_cofinite] at hx hy ⊢ have h_subset : {v : HeightOneSpectrum R | ¬(x + y) v ∈ v.adicCompletionIntegers K} ⊆ {v : HeightOneSpectrum R | ¬x v ∈ v.adicCompletionIntegers K} ∪ {v : HeightOneSpectrum R | ¬y v ∈ v.adicCompletionIntegers K} := by intro v hv rw [mem_union, mem_setOf, mem_setOf] rw [mem_setOf] at hv contrapose! hv rw [mem_adicCompletionIntegers, mem_adicCompletionIntegers, ← max_le_iff] at hv rw [mem_adicCompletionIntegers, Pi.add_apply] exact le_trans (Valued.v.map_add_le_max' (x v) (y v)) hv exact (hx.union hy).subset h_subset /-- The tuple `(0)_v` is a finite adèle. -/ theorem zero : (0 : K_hat R K).IsFiniteAdele := by rw [IsFiniteAdele, Filter.eventually_cofinite] have h_empty : {v : HeightOneSpectrum R | ¬(0 : v.adicCompletion K) ∈ v.adicCompletionIntegers K} = ∅ := by ext v; rw [mem_empty_iff_false, iff_false_iff]; intro hv rw [mem_setOf] at hv; apply hv; rw [mem_adicCompletionIntegers] have h_zero : (Valued.v (0 : v.adicCompletion K) : WithZero (Multiplicative ℤ)) = 0 := Valued.v.map_zero' rw [h_zero]; exact zero_le_one' _ -- Porting note: was `exact`, but `OfNat` got in the way. convert finite_empty /-- The negative of a finite adèle is a finite adèle. -/ theorem neg {x : K_hat R K} (hx : x.IsFiniteAdele) : (-x).IsFiniteAdele := by rw [IsFiniteAdele] at hx ⊢ have h : ∀ v : HeightOneSpectrum R, -x v ∈ v.adicCompletionIntegers K ↔ x v ∈ v.adicCompletionIntegers K := by intro v rw [mem_adicCompletionIntegers, mem_adicCompletionIntegers, Valuation.map_neg] -- Porting note: was `simpa only [Pi.neg_apply, h] using hx` but `Pi.neg_apply` no longer works convert hx using 2 with v convert h v /-- The product of two finite adèles is a finite adèle. -/ theorem mul {x y : K_hat R K} (hx : x.IsFiniteAdele) (hy : y.IsFiniteAdele) : (x * y).IsFiniteAdele := by rw [IsFiniteAdele, Filter.eventually_cofinite] at hx hy ⊢ have h_subset : {v : HeightOneSpectrum R | ¬(x * y) v ∈ v.adicCompletionIntegers K} ⊆ {v : HeightOneSpectrum R | ¬x v ∈ v.adicCompletionIntegers K} ∪ {v : HeightOneSpectrum R | ¬y v ∈ v.adicCompletionIntegers K} := by intro v hv rw [mem_union, mem_setOf, mem_setOf] rw [mem_setOf] at hv contrapose! hv rw [mem_adicCompletionIntegers, mem_adicCompletionIntegers] at hv have h_mul : Valued.v (x v * y v) = Valued.v (x v) * Valued.v (y v) := Valued.v.map_mul' (x v) (y v) rw [mem_adicCompletionIntegers, Pi.mul_apply, h_mul] exact mul_le_one' hv.left hv.right exact (hx.union hy).subset h_subset /-- The tuple `(1)_v` is a finite adèle. -/ theorem one : (1 : K_hat R K).IsFiniteAdele := by rw [IsFiniteAdele, Filter.eventually_cofinite] have h_empty : {v : HeightOneSpectrum R | ¬(1 : v.adicCompletion K) ∈ v.adicCompletionIntegers K} = ∅ := by ext v; rw [mem_empty_iff_false, iff_false_iff]; intro hv rw [mem_setOf] at hv; apply hv; rw [mem_adicCompletionIntegers] exact le_of_eq Valued.v.map_one' -- Porting note: was `exact`, but `OfNat` got in the way. convert finite_empty open scoped DiscreteValuation theorem algebraMap' (k : K) : (_root_.algebraMap K (K_hat R K) k).IsFiniteAdele := by rw [IsFiniteAdele, Filter.eventually_cofinite] simp_rw [mem_adicCompletionIntegers, ProdAdicCompletions.algebraMap_apply', Valued.valuedCompletion_apply, not_le] change {v : HeightOneSpectrum R | 1 < v.valuation k}.Finite -- The goal currently: if k ∈ K = field of fractions of a Dedekind domain R, -- then v(k)>1 for only finitely many v. -- We now write k=n/d and go via R to solve this goal. Do we need to do this? obtain ⟨⟨n, ⟨d, hd⟩⟩, hk⟩ := IsLocalization.surj (nonZeroDivisors R) k have hd' : d ≠ 0 := nonZeroDivisors.ne_zero hd suffices {v : HeightOneSpectrum R | v.valuation (_root_.algebraMap R K d : K) < 1}.Finite by apply Finite.subset this intro v hv apply_fun v.valuation at hk simp only [Valuation.map_mul, valuation_of_algebraMap] at hk rw [mem_setOf_eq, valuation_of_algebraMap] have := intValuation_le_one v n contrapose! this change 1 < v.intValuation n rw [← hk, mul_comm] exact lt_mul_of_le_of_one_lt' this hv (by simp) (by simp) simp_rw [valuation_of_algebraMap] change {v : HeightOneSpectrum R | v.intValuationDef d < 1}.Finite simp_rw [intValuation_lt_one_iff_dvd] apply Ideal.finite_factors simpa only [Submodule.zero_eq_bot, ne_eq, Ideal.span_singleton_eq_bot] end IsFiniteAdele end ProdAdicCompletions open ProdAdicCompletions.IsFiniteAdele /-- The finite adèle ring of `R` is the restricted product over all maximal ideals `v` of `R` of `adicCompletion`, with respect to `adicCompletionIntegers`. Note that we make this a `Type` rather than a `Subtype` (e.g., a `Subalgebra`) since we wish to endow it with a finer topology than that of the subspace topology. -/ def FiniteAdeleRing : Type _ := {x : K_hat R K // x.IsFiniteAdele} namespace FiniteAdeleRing /-- The finite adèle ring of `R`, regarded as a `K`-subalgebra of the product of the local completions of `K`. Note that this definition exists to streamline the proof that the finite adèles are an algebra over `K`, rather than to express their relationship to `K_hat R K` which is essentially a detail of their construction. -/ def subalgebra : Subalgebra K (K_hat R K) where carrier := {x : K_hat R K | x.IsFiniteAdele} mul_mem' := mul one_mem' := one add_mem' := add zero_mem' := zero algebraMap_mem' := algebraMap' instance : CommRing (FiniteAdeleRing R K) := Subalgebra.toCommRing (subalgebra R K) instance : Algebra K (FiniteAdeleRing R K) := Subalgebra.algebra (subalgebra R K) instance : Algebra R (FiniteAdeleRing R K) := ((algebraMap K (FiniteAdeleRing R K)).comp (algebraMap R K)).toAlgebra instance : IsScalarTower R K (FiniteAdeleRing R K) := IsScalarTower.of_algebraMap_eq' rfl instance : Coe (FiniteAdeleRing R K) (K_hat R K) where coe := fun x ↦ x.1 @[ext] lemma ext {a₁ a₂ : FiniteAdeleRing R K} (h : (a₁ : K_hat R K) = a₂) : a₁ = a₂ := Subtype.ext h /-- The finite adele ring is an algebra over the finite integral adeles. -/ instance : Algebra (R_hat R K) (FiniteAdeleRing R K) where smul rhat fadele := ⟨fun v ↦ rhat v * fadele.1 v, Finite.subset fadele.2 <| fun v hv ↦ by simp only [mem_adicCompletionIntegers, mem_compl_iff, mem_setOf_eq, map_mul] at hv ⊢ exact mt (mul_le_one₀ (rhat v).2) hv ⟩ toFun r := ⟨r, by simp_all⟩ map_one' := by ext; rfl map_mul' _ _ := by ext; rfl map_zero' := by ext; rfl map_add' _ _ := by ext; rfl commutes' _ _ := mul_comm _ _ smul_def' r x := rfl instance : CoeFun (FiniteAdeleRing R K) (fun _ ↦ ∀ (v : HeightOneSpectrum R), adicCompletion K v) where coe a v := a.1 v open scoped algebraMap -- coercion from R to `FiniteAdeleRing R K` variable {R K} in lemma exists_finiteIntegralAdele_iff (a : FiniteAdeleRing R K) : (∃ c : R_hat R K, a = c) ↔ ∀ (v : HeightOneSpectrum R), a v ∈ adicCompletionIntegers K v := ⟨by rintro ⟨c, rfl⟩ v; exact (c v).2, fun h ↦ ⟨fun v ↦ ⟨a v, h v⟩, rfl⟩⟩ section Topology open nonZeroDivisors open scoped DiscreteValuation variable {R K} in lemma mul_nonZeroDivisor_mem_finiteIntegralAdeles (a : FiniteAdeleRing R K) : ∃ (b : R⁰) (c : R_hat R K), a * ((b : R) : FiniteAdeleRing R K) = c := by let S := {v | a v ∉ adicCompletionIntegers K v} choose b hb h using adicCompletion.mul_nonZeroDivisor_mem_adicCompletionIntegers (R := R) (K := K) let p := ∏ᶠ v ∈ S, b v (a v) have hp : p ∈ R⁰ := finprod_mem_induction (· ∈ R⁰) (one_mem _) (fun _ _ => mul_mem) <| fun _ _ ↦ hb _ _ use ⟨p, hp⟩ rw [exists_finiteIntegralAdele_iff] intro v by_cases hv : a v ∈ adicCompletionIntegers K v · exact mul_mem hv <| coe_mem_adicCompletionIntegers _ _ · dsimp only have pprod : p = b v (a v) * ∏ᶠ w ∈ S \ {v}, b w (a w) := by rw [← finprod_mem_singleton (a := v) (f := fun v ↦ b v (a v)), finprod_mem_mul_diff (singleton_subset_iff.2 ‹v ∈ S›) a.2] rw [pprod] push_cast rw [← mul_assoc] exact mul_mem (h v (a v)) <| coe_mem_adicCompletionIntegers _ _ theorem submodulesRingBasis : SubmodulesRingBasis (fun (r : R⁰) ↦ Submodule.span (R_hat R K) {((r : R) : FiniteAdeleRing R K)}) where inter i j := ⟨i * j, by push_cast simp only [le_inf_iff, Submodule.span_singleton_le_iff_mem, Submodule.mem_span_singleton] exact ⟨⟨((j : R) : R_hat R K), by rw [mul_comm]; rfl⟩, ⟨((i : R) : R_hat R K), rfl⟩⟩⟩ leftMul a r := by rcases mul_nonZeroDivisor_mem_finiteIntegralAdeles a with ⟨b, c, h⟩ use r * b rintro x ⟨m, hm, rfl⟩ simp only [Submonoid.coe_mul, SetLike.mem_coe] at hm rw [Submodule.mem_span_singleton] at hm ⊢ rcases hm with ⟨n, rfl⟩ simp only [LinearMapClass.map_smul, DistribMulAction.toLinearMap_apply, smul_eq_mul] use n * c push_cast rw [mul_left_comm, h, mul_comm _ (c : FiniteAdeleRing R K), Algebra.smul_def', Algebra.smul_def', ← mul_assoc] rfl mul r := ⟨r, by intro x hx rw [mem_mul] at hx rcases hx with ⟨a, ha, b, hb, rfl⟩ simp only [SetLike.mem_coe, Submodule.mem_span_singleton] at ha hb ⊢ rcases ha with ⟨m, rfl⟩ rcases hb with ⟨n, rfl⟩ use m * n * (r : R) simp only [Algebra.smul_def', map_mul] rw [mul_mul_mul_comm, mul_assoc] rfl⟩ instance : TopologicalSpace (FiniteAdeleRing R K) := SubmodulesRingBasis.topology (submodulesRingBasis R K) -- the point of the above: this now works example : TopologicalRing (FiniteAdeleRing R K) := inferInstance end Topology end FiniteAdeleRing end DedekindDomain
RingTheory\DedekindDomain\Ideal.lean
/- Copyright (c) 2020 Kenji Nakagawa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenji Nakagawa, Anne Baanen, Filippo A. E. Nuccio -/ import Mathlib.Algebra.Algebra.Subalgebra.Pointwise import Mathlib.RingTheory.MaximalSpectrum import Mathlib.RingTheory.ChainOfDivisors import Mathlib.RingTheory.DedekindDomain.Basic import Mathlib.RingTheory.FractionalIdeal.Operations /-! # Dedekind domains and ideals In this file, we show a ring is a Dedekind domain iff all fractional ideals are invertible. Then we prove some results on the unique factorization monoid structure of the ideals. ## Main definitions - `IsDedekindDomainInv` alternatively defines a Dedekind domain as an integral domain where every nonzero fractional ideal is invertible. - `isDedekindDomainInv_iff` shows that this does note depend on the choice of field of fractions. - `IsDedekindDomain.HeightOneSpectrum` defines the type of nonzero prime ideals of `R`. ## Main results: - `isDedekindDomain_iff_isDedekindDomainInv` - `Ideal.uniqueFactorizationMonoid` ## Implementation notes The definitions that involve a field of fractions choose a canonical field of fractions, but are independent of that choice. The `..._iff` lemmas express this independence. Often, definitions assume that Dedekind domains are not fields. We found it more practical to add a `(h : ¬ IsField A)` assumption whenever this is explicitly needed. ## References * [D. Marcus, *Number Fields*][marcus1977number] * [J.W.S. Cassels, A. Frölich, *Algebraic Number Theory*][cassels1967algebraic] * [J. Neukirch, *Algebraic Number Theory*][Neukirch1992] ## Tags dedekind domain, dedekind ring -/ variable (R A K : Type*) [CommRing R] [CommRing A] [Field K] open scoped nonZeroDivisors Polynomial section Inverse 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_nonzero {J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) : J⁻¹ = ⟨(1 : FractionalIdeal R₁⁰ K) / J, fractional_div_of_nonzero h⟩ := div_nonzero h theorem coe_inv_of_nonzero {J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) : (↑J⁻¹ : Submodule R₁ K) = IsLocalization.coeSubmodule K ⊤ / (J : Submodule R₁ K) := by simp_rw [inv_nonzero _ h, coe_one, coe_mk, IsLocalization.coeSubmodule_top] 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_nonzero 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⁻¹ := 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_nonzero hI).mp hy x hx rw [← h] apply mul_left_mono I apply (le_div_iff_of_nonzero hI).mpr _ intro y hy x hx rw [mul_comm] exact mul_mem_mul hx hy 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] theorem map_inv (I : FractionalIdeal R₁⁰ K) (h : K ≃ₐ[R₁] K') : I⁻¹.map (h : K →ₐ[R₁] K') = (I.map h)⁻¹ := by rw [inv_eq, map_div, map_one, inv_eq] open Submodule Submodule.IsPrincipal @[simp] theorem spanSingleton_inv (x : K) : (spanSingleton R₁⁰ x)⁻¹ = spanSingleton _ x⁻¹ := one_div_spanSingleton x -- @[simp] -- Porting note: not in simpNF form 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 _ <| NoZeroSMulDivisors.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 _ <| NoZeroSMulDivisors.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, bot_eq_zero]) 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 <| NoZeroSMulDivisors.algebraMap_injective R₁ K, zero_mul, zero_eq_bot, coeIdeal_bot] · rw [mul_comm, ← den_mul_self_eq_num'] exact mul_right_mono I <| 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 section IsDedekindDomainInv variable [IsDomain A] /-- A Dedekind domain is an integral domain such that every fractional ideal has an inverse. This is equivalent to `IsDedekindDomain`. In particular we provide a `fractional_ideal.comm_group_with_zero` instance, assuming `IsDedekindDomain A`, which implies `IsDedekindDomainInv`. For **integral** ideals, `IsDedekindDomain`(`_inv`) implies only `Ideal.cancelCommMonoidWithZero`. -/ def IsDedekindDomainInv : Prop := ∀ I ≠ (⊥ : FractionalIdeal A⁰ (FractionRing A)), I * I⁻¹ = 1 open FractionalIdeal variable {R A K} theorem isDedekindDomainInv_iff [Algebra A K] [IsFractionRing A K] : IsDedekindDomainInv A ↔ ∀ I ≠ (⊥ : FractionalIdeal A⁰ K), I * I⁻¹ = 1 := by let h : FractionalIdeal A⁰ (FractionRing A) ≃+* FractionalIdeal A⁰ K := FractionalIdeal.mapEquiv (FractionRing.algEquiv A K) refine h.toEquiv.forall_congr (fun {x} => ?_) rw [← h.toEquiv.apply_eq_iff_eq] simp [h, IsDedekindDomainInv] theorem FractionalIdeal.adjoinIntegral_eq_one_of_isUnit [Algebra A K] [IsFractionRing A K] (x : K) (hx : IsIntegral A x) (hI : IsUnit (adjoinIntegral A⁰ x hx)) : adjoinIntegral A⁰ x hx = 1 := by set I := adjoinIntegral A⁰ x hx have mul_self : I * I = I := by apply coeToSubmodule_injective; simp [I] convert congr_arg (· * I⁻¹) mul_self <;> simp only [(mul_inv_cancel_iff_isUnit K).mpr hI, mul_assoc, mul_one] namespace IsDedekindDomainInv variable [Algebra A K] [IsFractionRing A K] (h : IsDedekindDomainInv A) theorem mul_inv_eq_one {I : FractionalIdeal A⁰ K} (hI : I ≠ 0) : I * I⁻¹ = 1 := isDedekindDomainInv_iff.mp h I hI theorem inv_mul_eq_one {I : FractionalIdeal A⁰ K} (hI : I ≠ 0) : I⁻¹ * I = 1 := (mul_comm _ _).trans (h.mul_inv_eq_one hI) protected theorem isUnit {I : FractionalIdeal A⁰ K} (hI : I ≠ 0) : IsUnit I := isUnit_of_mul_eq_one _ _ (h.mul_inv_eq_one hI) theorem isNoetherianRing : IsNoetherianRing A := by refine isNoetherianRing_iff.mpr ⟨fun I : Ideal A => ?_⟩ by_cases hI : I = ⊥ · rw [hI]; apply Submodule.fg_bot have hI : (I : FractionalIdeal A⁰ (FractionRing A)) ≠ 0 := coeIdeal_ne_zero.mpr hI exact I.fg_of_isUnit (IsFractionRing.injective A (FractionRing A)) (h.isUnit hI) theorem integrallyClosed : IsIntegrallyClosed A := by -- It suffices to show that for integral `x`, -- `A[x]` (which is a fractional ideal) is in fact equal to `A`. refine (isIntegrallyClosed_iff (FractionRing A)).mpr (fun {x hx} => ?_) rw [← Set.mem_range, ← Algebra.mem_bot, ← Subalgebra.mem_toSubmodule, Algebra.toSubmodule_bot, Submodule.one_eq_span, ← coe_spanSingleton A⁰ (1 : FractionRing A), spanSingleton_one, ← FractionalIdeal.adjoinIntegral_eq_one_of_isUnit x hx (h.isUnit _)] · exact mem_adjoinIntegral_self A⁰ x hx · exact fun h => one_ne_zero (eq_zero_iff.mp h 1 (Algebra.adjoin A {x}).one_mem) open Ring theorem dimensionLEOne : DimensionLEOne A := ⟨by -- We're going to show that `P` is maximal because any (maximal) ideal `M` -- that is strictly larger would be `⊤`. rintro P P_ne hP refine Ideal.isMaximal_def.mpr ⟨hP.ne_top, fun M hM => ?_⟩ -- We may assume `P` and `M` (as fractional ideals) are nonzero. have P'_ne : (P : FractionalIdeal A⁰ (FractionRing A)) ≠ 0 := coeIdeal_ne_zero.mpr P_ne have M'_ne : (M : FractionalIdeal A⁰ (FractionRing A)) ≠ 0 := coeIdeal_ne_zero.mpr hM.ne_bot -- In particular, we'll show `M⁻¹ * P ≤ P` suffices (M⁻¹ : FractionalIdeal A⁰ (FractionRing A)) * P ≤ P by rw [eq_top_iff, ← coeIdeal_le_coeIdeal (FractionRing A), coeIdeal_top] calc (1 : FractionalIdeal A⁰ (FractionRing A)) = _ * _ * _ := ?_ _ ≤ _ * _ := mul_right_mono ((P : FractionalIdeal A⁰ (FractionRing A))⁻¹ * M : FractionalIdeal A⁰ (FractionRing A)) this _ = M := ?_ · rw [mul_assoc, ← mul_assoc (P : FractionalIdeal A⁰ (FractionRing A)), h.mul_inv_eq_one P'_ne, one_mul, h.inv_mul_eq_one M'_ne] · rw [← mul_assoc (P : FractionalIdeal A⁰ (FractionRing A)), h.mul_inv_eq_one P'_ne, one_mul] -- Suppose we have `x ∈ M⁻¹ * P`, then in fact `x = algebraMap _ _ y` for some `y`. intro x hx have le_one : (M⁻¹ : FractionalIdeal A⁰ (FractionRing A)) * P ≤ 1 := by rw [← h.inv_mul_eq_one M'_ne] exact mul_left_mono _ ((coeIdeal_le_coeIdeal (FractionRing A)).mpr hM.le) obtain ⟨y, _hy, rfl⟩ := (mem_coeIdeal _).mp (le_one hx) -- Since `M` is strictly greater than `P`, let `z ∈ M \ P`. obtain ⟨z, hzM, hzp⟩ := SetLike.exists_of_lt hM -- We have `z * y ∈ M * (M⁻¹ * P) = P`. have zy_mem := mul_mem_mul (mem_coeIdeal_of_mem A⁰ hzM) hx rw [← RingHom.map_mul, ← mul_assoc, h.mul_inv_eq_one M'_ne, one_mul] at zy_mem obtain ⟨zy, hzy, zy_eq⟩ := (mem_coeIdeal A⁰).mp zy_mem rw [IsFractionRing.injective A (FractionRing A) zy_eq] at hzy -- But `P` is a prime ideal, so `z ∉ P` implies `y ∈ P`, as desired. exact mem_coeIdeal_of_mem A⁰ (Or.resolve_left (hP.mem_or_mem hzy) hzp)⟩ /-- Showing one side of the equivalence between the definitions `IsDedekindDomainInv` and `IsDedekindDomain` of Dedekind domains. -/ theorem isDedekindDomain : IsDedekindDomain A := { h.isNoetherianRing, h.dimensionLEOne, h.integrallyClosed with } end IsDedekindDomainInv end IsDedekindDomainInv variable [Algebra A K] [IsFractionRing A K] variable {A K} theorem one_mem_inv_coe_ideal [IsDomain A] {I : Ideal A} (hI : I ≠ ⊥) : (1 : K) ∈ (I : FractionalIdeal A⁰ K)⁻¹ := by rw [FractionalIdeal.mem_inv_iff (FractionalIdeal.coeIdeal_ne_zero.mpr hI)] intro y hy rw [one_mul] exact FractionalIdeal.coeIdeal_le_one hy /-- Specialization of `exists_primeSpectrum_prod_le_and_ne_bot_of_domain` to Dedekind domains: Let `I : Ideal A` be a nonzero ideal, where `A` is a Dedekind domain that is not a field. Then `exists_primeSpectrum_prod_le_and_ne_bot_of_domain` states we can find a product of prime ideals that is contained within `I`. This lemma extends that result by making the product minimal: let `M` be a maximal ideal that contains `I`, then the product including `M` is contained within `I` and the product excluding `M` is not contained within `I`. -/ theorem exists_multiset_prod_cons_le_and_prod_not_le [IsDedekindDomain A] (hNF : ¬IsField A) {I M : Ideal A} (hI0 : I ≠ ⊥) (hIM : I ≤ M) [hM : M.IsMaximal] : ∃ Z : Multiset (PrimeSpectrum A), (M ::ₘ Z.map PrimeSpectrum.asIdeal).prod ≤ I ∧ ¬Multiset.prod (Z.map PrimeSpectrum.asIdeal) ≤ I := by -- Let `Z` be a minimal set of prime ideals such that their product is contained in `J`. obtain ⟨Z₀, hZ₀⟩ := PrimeSpectrum.exists_primeSpectrum_prod_le_and_ne_bot_of_domain hNF hI0 obtain ⟨Z, ⟨hZI, hprodZ⟩, h_eraseZ⟩ := wellFounded_lt.has_min {Z | (Z.map PrimeSpectrum.asIdeal).prod ≤ I ∧ (Z.map PrimeSpectrum.asIdeal).prod ≠ ⊥} ⟨Z₀, hZ₀.1, hZ₀.2⟩ obtain ⟨_, hPZ', hPM⟩ := hM.isPrime.multiset_prod_le.mp (hZI.trans hIM) -- Then in fact there is a `P ∈ Z` with `P ≤ M`. obtain ⟨P, hPZ, rfl⟩ := Multiset.mem_map.mp hPZ' classical have := Multiset.map_erase PrimeSpectrum.asIdeal (fun _ _ => PrimeSpectrum.ext) P Z obtain ⟨hP0, hZP0⟩ : P.asIdeal ≠ ⊥ ∧ ((Z.erase P).map PrimeSpectrum.asIdeal).prod ≠ ⊥ := by rwa [Ne, ← Multiset.cons_erase hPZ', Multiset.prod_cons, Ideal.mul_eq_bot, not_or, ← this] at hprodZ -- By maximality of `P` and `M`, we have that `P ≤ M` implies `P = M`. have hPM' := (P.isPrime.isMaximal hP0).eq_of_le hM.ne_top hPM subst hPM' -- By minimality of `Z`, erasing `P` from `Z` is exactly what we need. refine ⟨Z.erase P, ?_, ?_⟩ · convert hZI rw [this, Multiset.cons_erase hPZ'] · refine fun h => h_eraseZ (Z.erase P) ⟨h, ?_⟩ (Multiset.erase_lt.mpr hPZ) exact hZP0 namespace FractionalIdeal open Ideal lemma not_inv_le_one_of_ne_bot [IsDedekindDomain A] {I : Ideal A} (hI0 : I ≠ ⊥) (hI1 : I ≠ ⊤) : ¬(I⁻¹ : FractionalIdeal A⁰ K) ≤ 1 := by have hNF : ¬IsField A := fun h ↦ letI := h.toField; (eq_bot_or_eq_top I).elim hI0 hI1 wlog hM : I.IsMaximal generalizing I · rcases I.exists_le_maximal hI1 with ⟨M, hmax, hIM⟩ have hMbot : M ≠ ⊥ := (M.bot_lt_of_maximal hNF).ne' refine mt (le_trans <| inv_anti_mono ?_ ?_ ?_) (this hMbot hmax.ne_top hmax) <;> simpa only [coeIdeal_ne_zero, coeIdeal_le_coeIdeal] have hI0 : ⊥ < I := I.bot_lt_of_maximal hNF obtain ⟨⟨a, haI⟩, ha0⟩ := Submodule.nonzero_mem_of_bot_lt hI0 replace ha0 : a ≠ 0 := Subtype.coe_injective.ne ha0 let J : Ideal A := Ideal.span {a} have hJ0 : J ≠ ⊥ := mt Ideal.span_singleton_eq_bot.mp ha0 have hJI : J ≤ I := I.span_singleton_le_iff_mem.2 haI -- Then we can find a product of prime (hence maximal) ideals contained in `J`, -- such that removing element `M` from the product is not contained in `J`. obtain ⟨Z, hle, hnle⟩ := exists_multiset_prod_cons_le_and_prod_not_le hNF hJ0 hJI -- Choose an element `b` of the product that is not in `J`. obtain ⟨b, hbZ, hbJ⟩ := SetLike.not_le_iff_exists.mp hnle have hnz_fa : algebraMap A K a ≠ 0 := mt ((injective_iff_map_eq_zero _).mp (IsFractionRing.injective A K) a) ha0 -- Then `b a⁻¹ : K` is in `M⁻¹` but not in `1`. refine Set.not_subset.2 ⟨algebraMap A K b * (algebraMap A K a)⁻¹, (mem_inv_iff ?_).mpr ?_, ?_⟩ · exact coeIdeal_ne_zero.mpr hI0.ne' · rintro y₀ hy₀ obtain ⟨y, h_Iy, rfl⟩ := (mem_coeIdeal _).mp hy₀ rw [mul_comm, ← mul_assoc, ← RingHom.map_mul] have h_yb : y * b ∈ J := by apply hle rw [Multiset.prod_cons] exact Submodule.smul_mem_smul h_Iy hbZ rw [Ideal.mem_span_singleton'] at h_yb rcases h_yb with ⟨c, hc⟩ rw [← hc, RingHom.map_mul, mul_assoc, mul_inv_cancel hnz_fa, mul_one] apply coe_mem_one · refine mt (mem_one_iff _).mp ?_ rintro ⟨x', h₂_abs⟩ rw [← div_eq_mul_inv, eq_div_iff_mul_eq hnz_fa, ← RingHom.map_mul] at h₂_abs have := Ideal.mem_span_singleton'.mpr ⟨x', IsFractionRing.injective A K h₂_abs⟩ contradiction theorem exists_not_mem_one_of_ne_bot [IsDedekindDomain A] {I : Ideal A} (hI0 : I ≠ ⊥) (hI1 : I ≠ ⊤) : ∃ x ∈ (I⁻¹ : FractionalIdeal A⁰ K), x ∉ (1 : FractionalIdeal A⁰ K) := Set.not_subset.1 <| not_inv_le_one_of_ne_bot hI0 hI1 theorem mul_inv_cancel_of_le_one [h : IsDedekindDomain A] {I : Ideal A} (hI0 : I ≠ ⊥) (hI : (I * (I : FractionalIdeal A⁰ K)⁻¹)⁻¹ ≤ 1) : I * (I : FractionalIdeal A⁰ K)⁻¹ = 1 := by -- We'll show a contradiction with `exists_not_mem_one_of_ne_bot`: -- `J⁻¹ = (I * I⁻¹)⁻¹` cannot have an element `x ∉ 1`, so it must equal `1`. obtain ⟨J, hJ⟩ : ∃ J : Ideal A, (J : FractionalIdeal A⁰ K) = I * (I : FractionalIdeal A⁰ K)⁻¹ := le_one_iff_exists_coeIdeal.mp mul_one_div_le_one by_cases hJ0 : J = ⊥ · subst hJ0 refine absurd ?_ hI0 rw [eq_bot_iff, ← coeIdeal_le_coeIdeal K, hJ] exact coe_ideal_le_self_mul_inv K I by_cases hJ1 : J = ⊤ · rw [← hJ, hJ1, coeIdeal_top] exact (not_inv_le_one_of_ne_bot (K := K) hJ0 hJ1 (hJ ▸ hI)).elim /-- Nonzero integral ideals in a Dedekind domain are invertible. We will use this to show that nonzero fractional ideals are invertible, and finally conclude that fractional ideals in a Dedekind domain form a group with zero. -/ theorem coe_ideal_mul_inv [h : IsDedekindDomain A] (I : Ideal A) (hI0 : I ≠ ⊥) : I * (I : FractionalIdeal A⁰ K)⁻¹ = 1 := by -- We'll show `1 ≤ J⁻¹ = (I * I⁻¹)⁻¹ ≤ 1`. apply mul_inv_cancel_of_le_one hI0 by_cases hJ0 : I * (I : FractionalIdeal A⁰ K)⁻¹ = 0 · rw [hJ0, inv_zero']; exact zero_le _ intro x hx -- In particular, we'll show all `x ∈ J⁻¹` are integral. suffices x ∈ integralClosure A K by rwa [IsIntegrallyClosed.integralClosure_eq_bot, Algebra.mem_bot, Set.mem_range, ← mem_one_iff] at this -- For that, we'll find a subalgebra that is f.g. as a module and contains `x`. -- `A` is a noetherian ring, so we just need to find a subalgebra between `{x}` and `I⁻¹`. rw [mem_integralClosure_iff_mem_fg] have x_mul_mem : ∀ b ∈ (I⁻¹ : FractionalIdeal A⁰ K), x * b ∈ (I⁻¹ : FractionalIdeal A⁰ K) := by intro b hb rw [mem_inv_iff (coeIdeal_ne_zero.mpr hI0)] dsimp only at hx rw [val_eq_coe, mem_coe, mem_inv_iff hJ0] at hx simp only [mul_assoc, mul_comm b] at hx ⊢ intro y hy exact hx _ (mul_mem_mul hy hb) -- It turns out the subalgebra consisting of all `p(x)` for `p : A[X]` works. refine ⟨AlgHom.range (Polynomial.aeval x : A[X] →ₐ[A] K), isNoetherian_submodule.mp (isNoetherian (I : FractionalIdeal A⁰ K)⁻¹) _ fun y hy => ?_, ⟨Polynomial.X, Polynomial.aeval_X x⟩⟩ obtain ⟨p, rfl⟩ := (AlgHom.mem_range _).mp hy rw [Polynomial.aeval_eq_sum_range] refine Submodule.sum_mem _ fun i hi => Submodule.smul_mem _ _ ?_ clear hi induction' i with i ih · rw [pow_zero]; exact one_mem_inv_coe_ideal hI0 · show x ^ i.succ ∈ (I⁻¹ : FractionalIdeal A⁰ K) rw [pow_succ']; exact x_mul_mem _ ih /-- Nonzero fractional ideals in a Dedekind domain are units. This is also available as `_root_.mul_inv_cancel`, using the `Semifield` instance defined below. -/ protected theorem mul_inv_cancel [IsDedekindDomain A] {I : FractionalIdeal A⁰ K} (hne : I ≠ 0) : I * I⁻¹ = 1 := by obtain ⟨a, J, ha, hJ⟩ : ∃ (a : A) (aI : Ideal A), a ≠ 0 ∧ I = spanSingleton A⁰ (algebraMap A K a)⁻¹ * aI := exists_eq_spanSingleton_mul I suffices h₂ : I * (spanSingleton A⁰ (algebraMap _ _ a) * (J : FractionalIdeal A⁰ K)⁻¹) = 1 by rw [mul_inv_cancel_iff] exact ⟨spanSingleton A⁰ (algebraMap _ _ a) * (J : FractionalIdeal A⁰ K)⁻¹, h₂⟩ subst hJ rw [mul_assoc, mul_left_comm (J : FractionalIdeal A⁰ K), coe_ideal_mul_inv, mul_one, spanSingleton_mul_spanSingleton, inv_mul_cancel, spanSingleton_one] · exact mt ((injective_iff_map_eq_zero (algebraMap A K)).mp (IsFractionRing.injective A K) _) ha · exact coeIdeal_ne_zero.mp (right_ne_zero_of_mul hne) theorem mul_right_le_iff [IsDedekindDomain A] {J : FractionalIdeal A⁰ K} (hJ : J ≠ 0) : ∀ {I I'}, I * J ≤ I' * J ↔ I ≤ I' := by intro I I' constructor · intro h convert mul_right_mono J⁻¹ h <;> dsimp only <;> rw [mul_assoc, FractionalIdeal.mul_inv_cancel hJ, mul_one] · exact fun h => mul_right_mono J h theorem mul_left_le_iff [IsDedekindDomain A] {J : FractionalIdeal A⁰ K} (hJ : J ≠ 0) {I I'} : J * I ≤ J * I' ↔ I ≤ I' := by convert mul_right_le_iff hJ using 1; simp only [mul_comm] theorem mul_right_strictMono [IsDedekindDomain A] {I : FractionalIdeal A⁰ K} (hI : I ≠ 0) : StrictMono (· * I) := strictMono_of_le_iff_le fun _ _ => (mul_right_le_iff hI).symm theorem mul_left_strictMono [IsDedekindDomain A] {I : FractionalIdeal A⁰ K} (hI : I ≠ 0) : StrictMono (I * ·) := strictMono_of_le_iff_le fun _ _ => (mul_left_le_iff hI).symm /-- This is also available as `_root_.div_eq_mul_inv`, using the `Semifield` instance defined below. -/ protected theorem div_eq_mul_inv [IsDedekindDomain A] (I J : FractionalIdeal A⁰ K) : I / J = I * J⁻¹ := by by_cases hJ : J = 0 · rw [hJ, div_zero, inv_zero', mul_zero] refine le_antisymm ((mul_right_le_iff hJ).mp ?_) ((le_div_iff_mul_le hJ).mpr ?_) · rw [mul_assoc, mul_comm J⁻¹, FractionalIdeal.mul_inv_cancel hJ, mul_one, mul_le] intro x hx y hy rw [mem_div_iff_of_nonzero hJ] at hx exact hx y hy rw [mul_assoc, mul_comm J⁻¹, FractionalIdeal.mul_inv_cancel hJ, mul_one] end FractionalIdeal /-- `IsDedekindDomain` and `IsDedekindDomainInv` are equivalent ways to express that an integral domain is a Dedekind domain. -/ theorem isDedekindDomain_iff_isDedekindDomainInv [IsDomain A] : IsDedekindDomain A ↔ IsDedekindDomainInv A := ⟨fun _h _I hI => FractionalIdeal.mul_inv_cancel hI, fun h => h.isDedekindDomain⟩ end Inverse section IsDedekindDomain variable {R A} variable [IsDedekindDomain A] [Algebra A K] [IsFractionRing A K] open FractionalIdeal open Ideal noncomputable instance FractionalIdeal.semifield : Semifield (FractionalIdeal A⁰ K) where __ := coeIdeal_injective.nontrivial inv_zero := inv_zero' _ div_eq_mul_inv := FractionalIdeal.div_eq_mul_inv mul_inv_cancel _ := FractionalIdeal.mul_inv_cancel nnqsmul := _ /-- Fractional ideals have cancellative multiplication in a Dedekind domain. Although this instance is a direct consequence of the instance `FractionalIdeal.semifield`, we define this instance to provide a computable alternative. -/ instance FractionalIdeal.cancelCommMonoidWithZero : CancelCommMonoidWithZero (FractionalIdeal A⁰ K) where __ : CommSemiring (FractionalIdeal A⁰ K) := inferInstance instance Ideal.cancelCommMonoidWithZero : CancelCommMonoidWithZero (Ideal A) := { Function.Injective.cancelCommMonoidWithZero (coeIdealHom A⁰ (FractionRing A)) coeIdeal_injective (RingHom.map_zero _) (RingHom.map_one _) (RingHom.map_mul _) (RingHom.map_pow _) with } -- Porting note: Lean can infer all it needs by itself instance Ideal.isDomain : IsDomain (Ideal A) := { } /-- For ideals in a Dedekind domain, to divide is to contain. -/ theorem Ideal.dvd_iff_le {I J : Ideal A} : I ∣ J ↔ J ≤ I := ⟨Ideal.le_of_dvd, fun h => by by_cases hI : I = ⊥ · have hJ : J = ⊥ := by rwa [hI, ← eq_bot_iff] at h rw [hI, hJ] have hI' : (I : FractionalIdeal A⁰ (FractionRing A)) ≠ 0 := coeIdeal_ne_zero.mpr hI have : (I : FractionalIdeal A⁰ (FractionRing A))⁻¹ * J ≤ 1 := le_trans (mul_left_mono (↑I)⁻¹ ((coeIdeal_le_coeIdeal _).mpr h)) (le_of_eq (inv_mul_cancel hI')) obtain ⟨H, hH⟩ := le_one_iff_exists_coeIdeal.mp this use H refine coeIdeal_injective (show (J : FractionalIdeal A⁰ (FractionRing A)) = ↑(I * H) from ?_) rw [coeIdeal_mul, hH, ← mul_assoc, mul_inv_cancel hI', one_mul]⟩ theorem Ideal.dvdNotUnit_iff_lt {I J : Ideal A} : DvdNotUnit I J ↔ J < I := ⟨fun ⟨hI, H, hunit, hmul⟩ => lt_of_le_of_ne (Ideal.dvd_iff_le.mp ⟨H, hmul⟩) (mt (fun h => have : H = 1 := mul_left_cancel₀ hI (by rw [← hmul, h, mul_one]) show IsUnit H from this.symm ▸ isUnit_one) hunit), fun h => dvdNotUnit_of_dvd_of_not_dvd (Ideal.dvd_iff_le.mpr (le_of_lt h)) (mt Ideal.dvd_iff_le.mp (not_le_of_lt h))⟩ instance : WfDvdMonoid (Ideal A) where wellFounded_dvdNotUnit := by have : WellFounded ((· > ·) : Ideal A → Ideal A → Prop) := isNoetherian_iff_wellFounded.mp (isNoetherianRing_iff.mp IsDedekindRing.toIsNoetherian) convert this ext rw [Ideal.dvdNotUnit_iff_lt] instance Ideal.uniqueFactorizationMonoid : UniqueFactorizationMonoid (Ideal A) := { irreducible_iff_prime := by intro P exact ⟨fun hirr => ⟨hirr.ne_zero, hirr.not_unit, fun I J => by have : P.IsMaximal := by refine ⟨⟨mt Ideal.isUnit_iff.mpr hirr.not_unit, ?_⟩⟩ intro J hJ obtain ⟨_J_ne, H, hunit, P_eq⟩ := Ideal.dvdNotUnit_iff_lt.mpr hJ exact Ideal.isUnit_iff.mp ((hirr.isUnit_or_isUnit P_eq).resolve_right hunit) rw [Ideal.dvd_iff_le, Ideal.dvd_iff_le, Ideal.dvd_iff_le, SetLike.le_def, SetLike.le_def, SetLike.le_def] contrapose! rintro ⟨⟨x, x_mem, x_not_mem⟩, ⟨y, y_mem, y_not_mem⟩⟩ exact ⟨x * y, Ideal.mul_mem_mul x_mem y_mem, mt this.isPrime.mem_or_mem (not_or_of_not x_not_mem y_not_mem)⟩⟩, Prime.irreducible⟩ } instance Ideal.normalizationMonoid : NormalizationMonoid (Ideal A) := normalizationMonoidOfUniqueUnits @[simp] theorem Ideal.dvd_span_singleton {I : Ideal A} {x : A} : I ∣ Ideal.span {x} ↔ x ∈ I := Ideal.dvd_iff_le.trans (Ideal.span_le.trans Set.singleton_subset_iff) theorem Ideal.isPrime_of_prime {P : Ideal A} (h : Prime P) : IsPrime P := by refine ⟨?_, fun hxy => ?_⟩ · rintro rfl rw [← Ideal.one_eq_top] at h exact h.not_unit isUnit_one · simp only [← Ideal.dvd_span_singleton, ← Ideal.span_singleton_mul_span_singleton] at hxy ⊢ exact h.dvd_or_dvd hxy theorem Ideal.prime_of_isPrime {P : Ideal A} (hP : P ≠ ⊥) (h : IsPrime P) : Prime P := by refine ⟨hP, mt Ideal.isUnit_iff.mp h.ne_top, fun I J hIJ => ?_⟩ simpa only [Ideal.dvd_iff_le] using h.mul_le.mp (Ideal.le_of_dvd hIJ) /-- In a Dedekind domain, the (nonzero) prime elements of the monoid with zero `Ideal A` are exactly the prime ideals. -/ theorem Ideal.prime_iff_isPrime {P : Ideal A} (hP : P ≠ ⊥) : Prime P ↔ IsPrime P := ⟨Ideal.isPrime_of_prime, Ideal.prime_of_isPrime hP⟩ /-- In a Dedekind domain, the prime ideals are the zero ideal together with the prime elements of the monoid with zero `Ideal A`. -/ theorem Ideal.isPrime_iff_bot_or_prime {P : Ideal A} : IsPrime P ↔ P = ⊥ ∨ Prime P := ⟨fun hp => (eq_or_ne P ⊥).imp_right fun hp0 => Ideal.prime_of_isPrime hp0 hp, fun hp => hp.elim (fun h => h.symm ▸ Ideal.bot_prime) Ideal.isPrime_of_prime⟩ @[simp] theorem Ideal.prime_span_singleton_iff {a : A} : Prime (Ideal.span {a}) ↔ Prime a := by rcases eq_or_ne a 0 with rfl | ha · rw [Set.singleton_zero, span_zero, ← Ideal.zero_eq_bot, ← not_iff_not] simp only [not_prime_zero, not_false_eq_true] · have ha' : span {a} ≠ ⊥ := by simpa only [ne_eq, span_singleton_eq_bot] using ha rw [Ideal.prime_iff_isPrime ha', Ideal.span_singleton_prime ha] open Submodule.IsPrincipal in theorem Ideal.prime_generator_of_prime {P : Ideal A} (h : Prime P) [P.IsPrincipal] : Prime (generator P) := have : Ideal.IsPrime P := Ideal.isPrime_of_prime h prime_generator_of_isPrime _ h.ne_zero open UniqueFactorizationMonoid in nonrec theorem Ideal.mem_normalizedFactors_iff {p I : Ideal A} (hI : I ≠ ⊥) : p ∈ normalizedFactors I ↔ p.IsPrime ∧ I ≤ p := by rw [← Ideal.dvd_iff_le] by_cases hp : p = 0 · rw [← zero_eq_bot] at hI simp only [hp, zero_not_mem_normalizedFactors, zero_dvd_iff, hI, false_iff, not_and, not_false_eq_true, implies_true] · rwa [mem_normalizedFactors_iff hI, prime_iff_isPrime] theorem Ideal.pow_right_strictAnti (I : Ideal A) (hI0 : I ≠ ⊥) (hI1 : I ≠ ⊤) : StrictAnti (I ^ · : ℕ → Ideal A) := strictAnti_nat_of_succ_lt fun e => Ideal.dvdNotUnit_iff_lt.mp ⟨pow_ne_zero _ hI0, I, mt isUnit_iff.mp hI1, pow_succ I e⟩ theorem Ideal.pow_lt_self (I : Ideal A) (hI0 : I ≠ ⊥) (hI1 : I ≠ ⊤) (e : ℕ) (he : 2 ≤ e) : I ^ e < I := by convert I.pow_right_strictAnti hI0 hI1 he dsimp only rw [pow_one] theorem Ideal.exists_mem_pow_not_mem_pow_succ (I : Ideal A) (hI0 : I ≠ ⊥) (hI1 : I ≠ ⊤) (e : ℕ) : ∃ x ∈ I ^ e, x ∉ I ^ (e + 1) := SetLike.exists_of_lt (I.pow_right_strictAnti hI0 hI1 e.lt_succ_self) open UniqueFactorizationMonoid theorem Ideal.eq_prime_pow_of_succ_lt_of_le {P I : Ideal A} [P_prime : P.IsPrime] (hP : P ≠ ⊥) {i : ℕ} (hlt : P ^ (i + 1) < I) (hle : I ≤ P ^ i) : I = P ^ i := by refine le_antisymm hle ?_ have P_prime' := Ideal.prime_of_isPrime hP P_prime have h1 : I ≠ ⊥ := (lt_of_le_of_lt bot_le hlt).ne' have := pow_ne_zero i hP have h3 := pow_ne_zero (i + 1) hP rw [← Ideal.dvdNotUnit_iff_lt, dvdNotUnit_iff_normalizedFactors_lt_normalizedFactors h1 h3, normalizedFactors_pow, normalizedFactors_irreducible P_prime'.irreducible, Multiset.nsmul_singleton, Multiset.lt_replicate_succ] at hlt rw [← Ideal.dvd_iff_le, dvd_iff_normalizedFactors_le_normalizedFactors, normalizedFactors_pow, normalizedFactors_irreducible P_prime'.irreducible, Multiset.nsmul_singleton] all_goals assumption theorem Ideal.pow_succ_lt_pow {P : Ideal A} [P_prime : P.IsPrime] (hP : P ≠ ⊥) (i : ℕ) : P ^ (i + 1) < P ^ i := lt_of_le_of_ne (Ideal.pow_le_pow_right (Nat.le_succ _)) (mt (pow_eq_pow_iff hP (mt Ideal.isUnit_iff.mp P_prime.ne_top)).mp i.succ_ne_self) theorem Associates.le_singleton_iff (x : A) (n : ℕ) (I : Ideal A) : Associates.mk I ^ n ≤ Associates.mk (Ideal.span {x}) ↔ x ∈ I ^ n := by simp_rw [← Associates.dvd_eq_le, ← Associates.mk_pow, Associates.mk_dvd_mk, Ideal.dvd_span_singleton] variable {K} lemma FractionalIdeal.le_inv_comm {I J : FractionalIdeal A⁰ K} (hI : I ≠ 0) (hJ : J ≠ 0) : I ≤ J⁻¹ ↔ J ≤ I⁻¹ := by rw [inv_eq, inv_eq, le_div_iff_mul_le hI, le_div_iff_mul_le hJ, mul_comm] lemma FractionalIdeal.inv_le_comm {I J : FractionalIdeal A⁰ K} (hI : I ≠ 0) (hJ : J ≠ 0) : I⁻¹ ≤ J ↔ J⁻¹ ≤ I := by simpa using le_inv_comm (A := A) (K := K) (inv_ne_zero hI) (inv_ne_zero hJ) open FractionalIdeal /-- Strengthening of `IsLocalization.exist_integer_multiples`: Let `J ≠ ⊤` be an ideal in a Dedekind domain `A`, and `f ≠ 0` a finite collection of elements of `K = Frac(A)`, then we can multiply the elements of `f` by some `a : K` to find a collection of elements of `A` that is not completely contained in `J`. -/ theorem Ideal.exist_integer_multiples_not_mem {J : Ideal A} (hJ : J ≠ ⊤) {ι : Type*} (s : Finset ι) (f : ι → K) {j} (hjs : j ∈ s) (hjf : f j ≠ 0) : ∃ a : K, (∀ i ∈ s, IsLocalization.IsInteger A (a * f i)) ∧ ∃ i ∈ s, a * f i ∉ (J : FractionalIdeal A⁰ K) := by -- Consider the fractional ideal `I` spanned by the `f`s. let I : FractionalIdeal A⁰ K := spanFinset A s f have hI0 : I ≠ 0 := spanFinset_ne_zero.mpr ⟨j, hjs, hjf⟩ -- We claim the multiplier `a` we're looking for is in `I⁻¹ \ (J / I)`. suffices ↑J / I < I⁻¹ by obtain ⟨_, a, hI, hpI⟩ := SetLike.lt_iff_le_and_exists.mp this rw [mem_inv_iff hI0] at hI refine ⟨a, fun i hi => ?_, ?_⟩ -- By definition, `a ∈ I⁻¹` multiplies elements of `I` into elements of `1`, -- in other words, `a * f i` is an integer. · exact (mem_one_iff _).mp (hI (f i) (Submodule.subset_span (Set.mem_image_of_mem f hi))) · contrapose! hpI -- And if all `a`-multiples of `I` are an element of `J`, -- then `a` is actually an element of `J / I`, contradiction. refine (mem_div_iff_of_nonzero hI0).mpr fun y hy => Submodule.span_induction hy ?_ ?_ ?_ ?_ · rintro _ ⟨i, hi, rfl⟩; exact hpI i hi · rw [mul_zero]; exact Submodule.zero_mem _ · intro x y hx hy; rw [mul_add]; exact Submodule.add_mem _ hx hy · intro b x hx; rw [mul_smul_comm]; exact Submodule.smul_mem _ b hx -- To show the inclusion of `J / I` into `I⁻¹ = 1 / I`, note that `J < I`. calc ↑J / I = ↑J * I⁻¹ := div_eq_mul_inv (↑J) I _ < 1 * I⁻¹ := mul_right_strictMono (inv_ne_zero hI0) ?_ _ = I⁻¹ := one_mul _ rw [← coeIdeal_top] -- And multiplying by `I⁻¹` is indeed strictly monotone. exact strictMono_of_le_iff_le (fun _ _ => (coeIdeal_le_coeIdeal K).symm) (lt_top_iff_ne_top.mpr hJ) section Gcd namespace Ideal /-! ### GCD and LCM of ideals in a Dedekind domain We show that the gcd of two ideals in a Dedekind domain is just their supremum, and the lcm is their infimum, and use this to instantiate `NormalizedGCDMonoid (Ideal A)`. -/ @[simp] theorem sup_mul_inf (I J : Ideal A) : (I ⊔ J) * (I ⊓ J) = I * J := by letI := UniqueFactorizationMonoid.toNormalizedGCDMonoid (Ideal A) have hgcd : gcd I J = I ⊔ J := by rw [gcd_eq_normalize _ _, normalize_eq] · rw [dvd_iff_le, sup_le_iff, ← dvd_iff_le, ← dvd_iff_le] exact ⟨gcd_dvd_left _ _, gcd_dvd_right _ _⟩ · rw [dvd_gcd_iff, dvd_iff_le, dvd_iff_le] simp have hlcm : lcm I J = I ⊓ J := by rw [lcm_eq_normalize _ _, normalize_eq] · rw [lcm_dvd_iff, dvd_iff_le, dvd_iff_le] simp · rw [dvd_iff_le, le_inf_iff, ← dvd_iff_le, ← dvd_iff_le] exact ⟨dvd_lcm_left _ _, dvd_lcm_right _ _⟩ rw [← hgcd, ← hlcm, associated_iff_eq.mp (gcd_mul_lcm _ _)] /-- Ideals in a Dedekind domain have gcd and lcm operators that (trivially) are compatible with the normalization operator. -/ instance : NormalizedGCDMonoid (Ideal A) := { Ideal.normalizationMonoid with gcd := (· ⊔ ·) gcd_dvd_left := fun _ _ => by simpa only [dvd_iff_le] using le_sup_left gcd_dvd_right := fun _ _ => by simpa only [dvd_iff_le] using le_sup_right dvd_gcd := by simp only [dvd_iff_le] exact fun h1 h2 => @sup_le (Ideal A) _ _ _ _ h1 h2 lcm := (· ⊓ ·) lcm_zero_left := fun _ => by simp only [zero_eq_bot, bot_inf_eq] lcm_zero_right := fun _ => by simp only [zero_eq_bot, inf_bot_eq] gcd_mul_lcm := fun _ _ => by rw [associated_iff_eq, sup_mul_inf] normalize_gcd := fun _ _ => normalize_eq _ normalize_lcm := fun _ _ => normalize_eq _ } -- In fact, any lawful gcd and lcm would equal sup and inf respectively. @[simp] theorem gcd_eq_sup (I J : Ideal A) : gcd I J = I ⊔ J := rfl @[simp] theorem lcm_eq_inf (I J : Ideal A) : lcm I J = I ⊓ J := rfl theorem isCoprime_iff_gcd {I J : Ideal A} : IsCoprime I J ↔ gcd I J = 1 := by rw [Ideal.isCoprime_iff_codisjoint, codisjoint_iff, one_eq_top, gcd_eq_sup] theorem factors_span_eq {p : K[X]} : factors (span {p}) = (factors p).map (fun q ↦ span {q}) := by rcases eq_or_ne p 0 with rfl | hp; · simpa [Set.singleton_zero] using normalizedFactors_zero have : ∀ q ∈ (factors p).map (fun q ↦ span {q}), Prime q := fun q hq ↦ by obtain ⟨r, hr, rfl⟩ := Multiset.mem_map.mp hq exact prime_span_singleton_iff.mpr <| prime_of_factor r hr rw [← span_singleton_eq_span_singleton.mpr (factors_prod hp), ← multiset_prod_span_singleton, factors_eq_normalizedFactors, normalizedFactors_prod_of_prime this] end Ideal end Gcd end IsDedekindDomain section IsDedekindDomain variable {T : Type*} [CommRing T] [IsDedekindDomain T] {I J : Ideal T} open Multiset UniqueFactorizationMonoid Ideal theorem prod_normalizedFactors_eq_self (hI : I ≠ ⊥) : (normalizedFactors I).prod = I := associated_iff_eq.1 (normalizedFactors_prod hI) theorem count_le_of_ideal_ge [DecidableEq (Ideal T)] {I J : Ideal T} (h : I ≤ J) (hI : I ≠ ⊥) (K : Ideal T) : count K (normalizedFactors J) ≤ count K (normalizedFactors I) := le_iff_count.1 ((dvd_iff_normalizedFactors_le_normalizedFactors (ne_bot_of_le_ne_bot hI h) hI).1 (dvd_iff_le.2 h)) _ theorem sup_eq_prod_inf_factors [DecidableEq (Ideal T)] (hI : I ≠ ⊥) (hJ : J ≠ ⊥) : I ⊔ J = (normalizedFactors I ∩ normalizedFactors J).prod := by have H : normalizedFactors (normalizedFactors I ∩ normalizedFactors J).prod = normalizedFactors I ∩ normalizedFactors J := by apply normalizedFactors_prod_of_prime intro p hp rw [mem_inter] at hp exact prime_of_normalized_factor p hp.left have := Multiset.prod_ne_zero_of_prime (normalizedFactors I ∩ normalizedFactors J) fun _ h => prime_of_normalized_factor _ (Multiset.mem_inter.1 h).1 apply le_antisymm · rw [sup_le_iff, ← dvd_iff_le, ← dvd_iff_le] constructor · rw [dvd_iff_normalizedFactors_le_normalizedFactors this hI, H] exact inf_le_left · rw [dvd_iff_normalizedFactors_le_normalizedFactors this hJ, H] exact inf_le_right · rw [← dvd_iff_le, dvd_iff_normalizedFactors_le_normalizedFactors, normalizedFactors_prod_of_prime, le_iff_count] · intro a rw [Multiset.count_inter] exact le_min (count_le_of_ideal_ge le_sup_left hI a) (count_le_of_ideal_ge le_sup_right hJ a) · intro p hp rw [mem_inter] at hp exact prime_of_normalized_factor p hp.left · exact ne_bot_of_le_ne_bot hI le_sup_left · exact this theorem irreducible_pow_sup [DecidableEq (Ideal T)](hI : I ≠ ⊥) (hJ : Irreducible J) (n : ℕ) : J ^ n ⊔ I = J ^ min ((normalizedFactors I).count J) n := by rw [sup_eq_prod_inf_factors (pow_ne_zero n hJ.ne_zero) hI, min_comm, normalizedFactors_of_irreducible_pow hJ, normalize_eq J, replicate_inter, prod_replicate] theorem irreducible_pow_sup_of_le [DecidableRel fun (x : Ideal T) x_1 ↦ x ∣ x_1] (hJ : Irreducible J) (n : ℕ) (hn : ↑n ≤ multiplicity J I) : J ^ n ⊔ I = J ^ n := by classical by_cases hI : I = ⊥ · simp_all rw [irreducible_pow_sup hI hJ, min_eq_right] rwa [multiplicity_eq_count_normalizedFactors hJ hI, PartENat.coe_le_coe, normalize_eq J] at hn theorem irreducible_pow_sup_of_ge [DecidableRel fun (x : Ideal T) x_1 ↦ x ∣ x_1] (hI : I ≠ ⊥) (hJ : Irreducible J) (n : ℕ) (hn : multiplicity J I ≤ n) : J ^ n ⊔ I = J ^ (multiplicity J I).get (PartENat.dom_of_le_natCast hn) := by classical rw [irreducible_pow_sup hI hJ, min_eq_left] · congr rw [← PartENat.natCast_inj, PartENat.natCast_get, multiplicity_eq_count_normalizedFactors hJ hI, normalize_eq J] · rwa [multiplicity_eq_count_normalizedFactors hJ hI, PartENat.coe_le_coe, normalize_eq J] at hn end IsDedekindDomain /-! ### Height one spectrum of a Dedekind domain If `R` is a Dedekind domain of Krull dimension 1, the maximal ideals of `R` are exactly its nonzero prime ideals. We define `HeightOneSpectrum` and provide lemmas to recover the facts that prime ideals of height one are prime and irreducible. -/ namespace IsDedekindDomain variable [IsDedekindDomain R] /-- The height one prime spectrum of a Dedekind domain `R` is the type of nonzero prime ideals of `R`. Note that this equals the maximal spectrum if `R` has Krull dimension 1. -/ -- Porting note(#5171): removed `has_nonempty_instance`, linter doesn't exist yet @[ext, nolint unusedArguments] structure HeightOneSpectrum where asIdeal : Ideal R isPrime : asIdeal.IsPrime ne_bot : asIdeal ≠ ⊥ attribute [instance] HeightOneSpectrum.isPrime variable (v : HeightOneSpectrum R) {R} namespace HeightOneSpectrum instance isMaximal : v.asIdeal.IsMaximal := v.isPrime.isMaximal v.ne_bot theorem prime : Prime v.asIdeal := Ideal.prime_of_isPrime v.ne_bot v.isPrime theorem irreducible : Irreducible v.asIdeal := UniqueFactorizationMonoid.irreducible_iff_prime.mpr v.prime theorem associates_irreducible : Irreducible <| Associates.mk v.asIdeal := Associates.irreducible_mk.mpr v.irreducible /-- An equivalence between the height one and maximal spectra for rings of Krull dimension 1. -/ def equivMaximalSpectrum (hR : ¬IsField R) : HeightOneSpectrum R ≃ MaximalSpectrum R where toFun v := ⟨v.asIdeal, v.isPrime.isMaximal v.ne_bot⟩ invFun v := ⟨v.asIdeal, v.IsMaximal.isPrime, Ring.ne_bot_of_isMaximal_of_not_isField v.IsMaximal hR⟩ left_inv := fun ⟨_, _, _⟩ => rfl right_inv := fun ⟨_, _⟩ => rfl variable (R) /-- A Dedekind domain is equal to the intersection of its localizations at all its height one non-zero prime ideals viewed as subalgebras of its field of fractions. -/ theorem iInf_localization_eq_bot [Algebra R K] [hK : IsFractionRing R K] : (⨅ v : HeightOneSpectrum R, Localization.subalgebra.ofField K _ v.asIdeal.primeCompl_le_nonZeroDivisors) = ⊥ := by ext x rw [Algebra.mem_iInf] constructor on_goal 1 => by_cases hR : IsField R · rcases Function.bijective_iff_has_inverse.mp (IsField.localization_map_bijective (Rₘ := K) (flip nonZeroDivisors.ne_zero rfl : 0 ∉ R⁰) hR) with ⟨algebra_map_inv, _, algebra_map_right_inv⟩ exact fun _ => Algebra.mem_bot.mpr ⟨algebra_map_inv x, algebra_map_right_inv x⟩ all_goals rw [← MaximalSpectrum.iInf_localization_eq_bot, Algebra.mem_iInf] · exact fun hx ⟨v, hv⟩ => hx ((equivMaximalSpectrum hR).symm ⟨v, hv⟩) · exact fun hx ⟨v, hv, hbot⟩ => hx ⟨v, hv.isMaximal hbot⟩ end HeightOneSpectrum end IsDedekindDomain section open Ideal variable {R A} variable [IsDedekindDomain A] {I : Ideal R} {J : Ideal A} /-- The map from ideals of `R` dividing `I` to the ideals of `A` dividing `J` induced by a homomorphism `f : R/I →+* A/J` -/ @[simps] -- Porting note: use `Subtype` instead of `Set` to make linter happy def idealFactorsFunOfQuotHom {f : R ⧸ I →+* A ⧸ J} (hf : Function.Surjective f) : {p : Ideal R // p ∣ I} →o {p : Ideal A // p ∣ J} where toFun X := ⟨comap (Ideal.Quotient.mk J) (map f (map (Ideal.Quotient.mk I) X)), by have : RingHom.ker (Ideal.Quotient.mk J) ≤ comap (Ideal.Quotient.mk J) (map f (map (Ideal.Quotient.mk I) X)) := ker_le_comap (Ideal.Quotient.mk J) rw [mk_ker] at this exact dvd_iff_le.mpr this⟩ monotone' := by rintro ⟨X, hX⟩ ⟨Y, hY⟩ h rw [← Subtype.coe_le_coe, Subtype.coe_mk, Subtype.coe_mk] at h ⊢ rw [Subtype.coe_mk, comap_le_comap_iff_of_surjective (Ideal.Quotient.mk J) Quotient.mk_surjective, map_le_iff_le_comap, Subtype.coe_mk, comap_map_of_surjective _ hf (map (Ideal.Quotient.mk I) Y)] suffices map (Ideal.Quotient.mk I) X ≤ map (Ideal.Quotient.mk I) Y by exact le_sup_of_le_left this rwa [map_le_iff_le_comap, comap_map_of_surjective (Ideal.Quotient.mk I) Quotient.mk_surjective, ← RingHom.ker_eq_comap_bot, mk_ker, sup_eq_left.mpr <| le_of_dvd hY] @[simp] theorem idealFactorsFunOfQuotHom_id : idealFactorsFunOfQuotHom (RingHom.id (A ⧸ J)).surjective = OrderHom.id := OrderHom.ext _ _ (funext fun X => by simp only [idealFactorsFunOfQuotHom, map_id, OrderHom.coe_mk, OrderHom.id_coe, id, comap_map_of_surjective (Ideal.Quotient.mk J) Quotient.mk_surjective, ← RingHom.ker_eq_comap_bot (Ideal.Quotient.mk J), mk_ker, sup_eq_left.mpr (dvd_iff_le.mp X.prop), Subtype.coe_eta]) variable {B : Type*} [CommRing B] [IsDedekindDomain B] {L : Ideal B} theorem idealFactorsFunOfQuotHom_comp {f : R ⧸ I →+* A ⧸ J} {g : A ⧸ J →+* B ⧸ L} (hf : Function.Surjective f) (hg : Function.Surjective g) : (idealFactorsFunOfQuotHom hg).comp (idealFactorsFunOfQuotHom hf) = idealFactorsFunOfQuotHom (show Function.Surjective (g.comp f) from hg.comp hf) := by refine OrderHom.ext _ _ (funext fun x => ?_) rw [idealFactorsFunOfQuotHom, idealFactorsFunOfQuotHom, OrderHom.comp_coe, OrderHom.coe_mk, OrderHom.coe_mk, Function.comp_apply, idealFactorsFunOfQuotHom, OrderHom.coe_mk, Subtype.mk_eq_mk, Subtype.coe_mk, map_comap_of_surjective (Ideal.Quotient.mk J) Quotient.mk_surjective, map_map] variable [IsDedekindDomain R] (f : R ⧸ I ≃+* A ⧸ J) /-- The bijection between ideals of `R` dividing `I` and the ideals of `A` dividing `J` induced by an isomorphism `f : R/I ≅ A/J`. -/ -- @[simps] -- Porting note: simpNF complains about the lemmas generated by simps def idealFactorsEquivOfQuotEquiv : { p : Ideal R | p ∣ I } ≃o { p : Ideal A | p ∣ J } := by have f_surj : Function.Surjective (f : R ⧸ I →+* A ⧸ J) := f.surjective have fsym_surj : Function.Surjective (f.symm : A ⧸ J →+* R ⧸ I) := f.symm.surjective refine OrderIso.ofHomInv (idealFactorsFunOfQuotHom f_surj) (idealFactorsFunOfQuotHom fsym_surj) ?_ ?_ · have := idealFactorsFunOfQuotHom_comp fsym_surj f_surj simp only [RingEquiv.comp_symm, idealFactorsFunOfQuotHom_id] at this rw [← this, OrderHom.coe_eq, OrderHom.coe_eq] · have := idealFactorsFunOfQuotHom_comp f_surj fsym_surj simp only [RingEquiv.symm_comp, idealFactorsFunOfQuotHom_id] at this rw [← this, OrderHom.coe_eq, OrderHom.coe_eq] theorem idealFactorsEquivOfQuotEquiv_symm : (idealFactorsEquivOfQuotEquiv f).symm = idealFactorsEquivOfQuotEquiv f.symm := rfl theorem idealFactorsEquivOfQuotEquiv_is_dvd_iso {L M : Ideal R} (hL : L ∣ I) (hM : M ∣ I) : (idealFactorsEquivOfQuotEquiv f ⟨L, hL⟩ : Ideal A) ∣ idealFactorsEquivOfQuotEquiv f ⟨M, hM⟩ ↔ L ∣ M := by suffices idealFactorsEquivOfQuotEquiv f ⟨M, hM⟩ ≤ idealFactorsEquivOfQuotEquiv f ⟨L, hL⟩ ↔ (⟨M, hM⟩ : { p : Ideal R | p ∣ I }) ≤ ⟨L, hL⟩ by rw [dvd_iff_le, dvd_iff_le, Subtype.coe_le_coe, this, Subtype.mk_le_mk] exact (idealFactorsEquivOfQuotEquiv f).le_iff_le open UniqueFactorizationMonoid variable [DecidableEq (Ideal R)] [DecidableEq (Ideal A)] theorem idealFactorsEquivOfQuotEquiv_mem_normalizedFactors_of_mem_normalizedFactors (hJ : J ≠ ⊥) {L : Ideal R} (hL : L ∈ normalizedFactors I) : ↑(idealFactorsEquivOfQuotEquiv f ⟨L, dvd_of_mem_normalizedFactors hL⟩) ∈ normalizedFactors J := by have hI : I ≠ ⊥ := by intro hI rw [hI, bot_eq_zero, normalizedFactors_zero, ← Multiset.empty_eq_zero] at hL exact Finset.not_mem_empty _ hL refine mem_normalizedFactors_factor_dvd_iso_of_mem_normalizedFactors hI hJ hL (d := (idealFactorsEquivOfQuotEquiv f).toEquiv) ?_ rintro ⟨l, hl⟩ ⟨l', hl'⟩ rw [Subtype.coe_mk, Subtype.coe_mk] apply idealFactorsEquivOfQuotEquiv_is_dvd_iso f /-- The bijection between the sets of normalized factors of I and J induced by a ring isomorphism `f : R/I ≅ A/J`. -/ -- @[simps apply] -- Porting note: simpNF complains about the lemmas generated by simps def normalizedFactorsEquivOfQuotEquiv (hI : I ≠ ⊥) (hJ : J ≠ ⊥) : { L : Ideal R | L ∈ normalizedFactors I } ≃ { M : Ideal A | M ∈ normalizedFactors J } where toFun j := ⟨idealFactorsEquivOfQuotEquiv f ⟨↑j, dvd_of_mem_normalizedFactors j.prop⟩, idealFactorsEquivOfQuotEquiv_mem_normalizedFactors_of_mem_normalizedFactors f hJ j.prop⟩ invFun j := ⟨(idealFactorsEquivOfQuotEquiv f).symm ⟨↑j, dvd_of_mem_normalizedFactors j.prop⟩, by rw [idealFactorsEquivOfQuotEquiv_symm] exact idealFactorsEquivOfQuotEquiv_mem_normalizedFactors_of_mem_normalizedFactors f.symm hI j.prop⟩ left_inv := fun ⟨j, hj⟩ => by simp right_inv := fun ⟨j, hj⟩ => by simp -- This used to be the end of the proof before leanprover/lean4#2644 erw [OrderIso.apply_symm_apply] @[simp] theorem normalizedFactorsEquivOfQuotEquiv_symm (hI : I ≠ ⊥) (hJ : J ≠ ⊥) : (normalizedFactorsEquivOfQuotEquiv f hI hJ).symm = normalizedFactorsEquivOfQuotEquiv f.symm hJ hI := rfl variable [DecidableRel ((· ∣ ·) : Ideal R → Ideal R → Prop)] variable [DecidableRel ((· ∣ ·) : Ideal A → Ideal A → Prop)] /-- The map `normalizedFactorsEquivOfQuotEquiv` preserves multiplicities. -/ theorem normalizedFactorsEquivOfQuotEquiv_multiplicity_eq_multiplicity (hI : I ≠ ⊥) (hJ : J ≠ ⊥) (L : Ideal R) (hL : L ∈ normalizedFactors I) : multiplicity (↑(normalizedFactorsEquivOfQuotEquiv f hI hJ ⟨L, hL⟩)) J = multiplicity L I := by rw [normalizedFactorsEquivOfQuotEquiv, Equiv.coe_fn_mk, Subtype.coe_mk] refine multiplicity_factor_dvd_iso_eq_multiplicity_of_mem_normalizedFactors hI hJ hL (d := (idealFactorsEquivOfQuotEquiv f).toEquiv) ?_ exact fun ⟨l, hl⟩ ⟨l', hl'⟩ => idealFactorsEquivOfQuotEquiv_is_dvd_iso f hl hl' end section ChineseRemainder open Ideal UniqueFactorizationMonoid variable {R} theorem Ring.DimensionLeOne.prime_le_prime_iff_eq [Ring.DimensionLEOne R] {P Q : Ideal R} [hP : P.IsPrime] [hQ : Q.IsPrime] (hP0 : P ≠ ⊥) : P ≤ Q ↔ P = Q := ⟨(hP.isMaximal hP0).eq_of_le hQ.ne_top, Eq.le⟩ theorem Ideal.coprime_of_no_prime_ge {I J : Ideal R} (h : ∀ P, I ≤ P → J ≤ P → ¬IsPrime P) : IsCoprime I J := by rw [isCoprime_iff_sup_eq] by_contra hIJ obtain ⟨P, hP, hIJ⟩ := Ideal.exists_le_maximal _ hIJ exact h P (le_trans le_sup_left hIJ) (le_trans le_sup_right hIJ) hP.isPrime section DedekindDomain variable [IsDedekindDomain R] theorem Ideal.IsPrime.mul_mem_pow (I : Ideal R) [hI : I.IsPrime] {a b : R} {n : ℕ} (h : a * b ∈ I ^ n) : a ∈ I ∨ b ∈ I ^ n := by cases n; · simp by_cases hI0 : I = ⊥; · simpa [pow_succ, hI0] using h simp only [← Submodule.span_singleton_le_iff_mem, Ideal.submodule_span_eq, ← Ideal.dvd_iff_le, ← Ideal.span_singleton_mul_span_singleton] at h ⊢ by_cases ha : I ∣ span {a} · exact Or.inl ha rw [mul_comm] at h exact Or.inr (Prime.pow_dvd_of_dvd_mul_right ((Ideal.prime_iff_isPrime hI0).mpr hI) _ ha h) theorem Ideal.IsPrime.mem_pow_mul (I : Ideal R) [hI : I.IsPrime] {a b : R} {n : ℕ} (h : a * b ∈ I ^ n) : a ∈ I ^ n ∨ b ∈ I := by rw [mul_comm] at h rw [or_comm] exact Ideal.IsPrime.mul_mem_pow _ h section theorem Ideal.count_normalizedFactors_eq {p x : Ideal R} [hp : p.IsPrime] {n : ℕ} (hle : x ≤ p ^ n) [DecidableEq (Ideal R)] (hlt : ¬x ≤ p ^ (n + 1)) : (normalizedFactors x).count p = n := count_normalizedFactors_eq' ((Ideal.isPrime_iff_bot_or_prime.mp hp).imp_right Prime.irreducible) (normalize_eq _) (Ideal.dvd_iff_le.mpr hle) (mt Ideal.le_of_dvd hlt) end theorem Ideal.le_mul_of_no_prime_factors {I J K : Ideal R} (coprime : ∀ P, J ≤ P → K ≤ P → ¬IsPrime P) (hJ : I ≤ J) (hK : I ≤ K) : I ≤ J * K := by simp only [← Ideal.dvd_iff_le] at coprime hJ hK ⊢ by_cases hJ0 : J = 0 · simpa only [hJ0, zero_mul] using hJ obtain ⟨I', rfl⟩ := hK rw [mul_comm] refine mul_dvd_mul_left K (UniqueFactorizationMonoid.dvd_of_dvd_mul_right_of_no_prime_factors (b := K) hJ0 ?_ hJ) exact fun hPJ hPK => mt Ideal.isPrime_of_prime (coprime _ hPJ hPK) theorem Ideal.le_of_pow_le_prime {I P : Ideal R} [hP : P.IsPrime] {n : ℕ} (h : I ^ n ≤ P) : I ≤ P := by by_cases hP0 : P = ⊥ · simp only [hP0, le_bot_iff] at h ⊢ exact pow_eq_zero h rw [← Ideal.dvd_iff_le] at h ⊢ exact ((Ideal.prime_iff_isPrime hP0).mpr hP).dvd_of_dvd_pow h theorem Ideal.pow_le_prime_iff {I P : Ideal R} [_hP : P.IsPrime] {n : ℕ} (hn : n ≠ 0) : I ^ n ≤ P ↔ I ≤ P := ⟨Ideal.le_of_pow_le_prime, fun h => _root_.trans (Ideal.pow_le_self hn) h⟩ theorem Ideal.prod_le_prime {ι : Type*} {s : Finset ι} {f : ι → Ideal R} {P : Ideal R} [hP : P.IsPrime] : ∏ i ∈ s, f i ≤ P ↔ ∃ i ∈ s, f i ≤ P := by by_cases hP0 : P = ⊥ · simp only [hP0, le_bot_iff] rw [← Ideal.zero_eq_bot, Finset.prod_eq_zero_iff] simp only [← Ideal.dvd_iff_le] exact ((Ideal.prime_iff_isPrime hP0).mpr hP).dvd_finset_prod_iff _ /-- The intersection of distinct prime powers in a Dedekind domain is the product of these prime powers. -/ theorem IsDedekindDomain.inf_prime_pow_eq_prod {ι : Type*} (s : Finset ι) (f : ι → Ideal R) (e : ι → ℕ) (prime : ∀ i ∈ s, Prime (f i)) (coprime : ∀ᵉ (i ∈ s) (j ∈ s), i ≠ j → f i ≠ f j) : (s.inf fun i => f i ^ e i) = ∏ i ∈ s, f i ^ e i := by letI := Classical.decEq ι revert prime coprime refine s.induction ?_ ?_ · simp intro a s ha ih prime coprime specialize ih (fun i hi => prime i (Finset.mem_insert_of_mem hi)) fun i hi j hj => coprime i (Finset.mem_insert_of_mem hi) j (Finset.mem_insert_of_mem hj) rw [Finset.inf_insert, Finset.prod_insert ha, ih] refine le_antisymm (Ideal.le_mul_of_no_prime_factors ?_ inf_le_left inf_le_right) Ideal.mul_le_inf intro P hPa hPs hPp obtain ⟨b, hb, hPb⟩ := Ideal.prod_le_prime.mp hPs haveI := Ideal.isPrime_of_prime (prime a (Finset.mem_insert_self a s)) haveI := Ideal.isPrime_of_prime (prime b (Finset.mem_insert_of_mem hb)) refine coprime a (Finset.mem_insert_self a s) b (Finset.mem_insert_of_mem hb) ?_ ?_ · exact (ne_of_mem_of_not_mem hb ha).symm · refine ((Ring.DimensionLeOne.prime_le_prime_iff_eq ?_).mp (Ideal.le_of_pow_le_prime hPa)).trans ((Ring.DimensionLeOne.prime_le_prime_iff_eq ?_).mp (Ideal.le_of_pow_le_prime hPb)).symm · exact (prime a (Finset.mem_insert_self a s)).ne_zero · exact (prime b (Finset.mem_insert_of_mem hb)).ne_zero /-- **Chinese remainder theorem** for a Dedekind domain: if the ideal `I` factors as `∏ i, P i ^ e i`, then `R ⧸ I` factors as `Π i, R ⧸ (P i ^ e i)`. -/ noncomputable def IsDedekindDomain.quotientEquivPiOfProdEq {ι : Type*} [Fintype ι] (I : Ideal R) (P : ι → Ideal R) (e : ι → ℕ) (prime : ∀ i, Prime (P i)) (coprime : Pairwise fun i j => P i ≠ P j) (prod_eq : ∏ i, P i ^ e i = I) : R ⧸ I ≃+* ∀ i, R ⧸ P i ^ e i := (Ideal.quotEquivOfEq (by simp only [← prod_eq, Finset.inf_eq_iInf, Finset.mem_univ, ciInf_pos, ← IsDedekindDomain.inf_prime_pow_eq_prod _ _ _ (fun i _ => prime i) (coprime.set_pairwise _)])).trans <| Ideal.quotientInfRingEquivPiQuotient _ fun i j hij => Ideal.coprime_of_no_prime_ge (by intro P hPi hPj hPp haveI := Ideal.isPrime_of_prime (prime i) haveI := Ideal.isPrime_of_prime (prime j) refine coprime hij ?_ refine ((Ring.DimensionLeOne.prime_le_prime_iff_eq ?_).mp (Ideal.le_of_pow_le_prime hPi)).trans ((Ring.DimensionLeOne.prime_le_prime_iff_eq ?_).mp (Ideal.le_of_pow_le_prime hPj)).symm · exact (prime i).ne_zero · exact (prime j).ne_zero) open scoped Classical /-- **Chinese remainder theorem** for a Dedekind domain: `R ⧸ I` factors as `Π i, R ⧸ (P i ^ e i)`, where `P i` ranges over the prime factors of `I` and `e i` over the multiplicities. -/ noncomputable def IsDedekindDomain.quotientEquivPiFactors {I : Ideal R} (hI : I ≠ ⊥) : R ⧸ I ≃+* ∀ P : (factors I).toFinset, R ⧸ (P : Ideal R) ^ (Multiset.count ↑P (factors I)) := IsDedekindDomain.quotientEquivPiOfProdEq _ _ _ (fun P : (factors I).toFinset => prime_of_factor _ (Multiset.mem_toFinset.mp P.prop)) (fun i j hij => Subtype.coe_injective.ne hij) (calc (∏ P : (factors I).toFinset, (P : Ideal R) ^ (factors I).count (P : Ideal R)) = ∏ P ∈ (factors I).toFinset, P ^ (factors I).count P := (factors I).toFinset.prod_coe_sort fun P => P ^ (factors I).count P _ = ((factors I).map fun P => P).prod := (Finset.prod_multiset_map_count (factors I) id).symm _ = (factors I).prod := by rw [Multiset.map_id'] _ = I := (@associated_iff_eq (Ideal R) _ Ideal.uniqueUnits _ _).mp (factors_prod hI) ) @[simp] theorem IsDedekindDomain.quotientEquivPiFactors_mk {I : Ideal R} (hI : I ≠ ⊥) (x : R) : IsDedekindDomain.quotientEquivPiFactors hI (Ideal.Quotient.mk I x) = fun _P => Ideal.Quotient.mk _ x := rfl /-- **Chinese remainder theorem** for a Dedekind domain: if the ideal `I` factors as `∏ i ∈ s, P i ^ e i`, then `R ⧸ I` factors as `Π (i : s), R ⧸ (P i ^ e i)`. This is a version of `IsDedekindDomain.quotientEquivPiOfProdEq` where we restrict the product to a finite subset `s` of a potentially infinite indexing type `ι`. -/ noncomputable def IsDedekindDomain.quotientEquivPiOfFinsetProdEq {ι : Type*} {s : Finset ι} (I : Ideal R) (P : ι → Ideal R) (e : ι → ℕ) (prime : ∀ i ∈ s, Prime (P i)) (coprime : ∀ᵉ (i ∈ s) (j ∈ s), i ≠ j → P i ≠ P j) (prod_eq : ∏ i ∈ s, P i ^ e i = I) : R ⧸ I ≃+* ∀ i : s, R ⧸ P i ^ e i := IsDedekindDomain.quotientEquivPiOfProdEq I (fun i : s => P i) (fun i : s => e i) (fun i => prime i i.2) (fun i j h => coprime i i.2 j j.2 (Subtype.coe_injective.ne h)) (_root_.trans (Finset.prod_coe_sort s fun i => P i ^ e i) prod_eq) /-- Corollary of the Chinese remainder theorem: given elements `x i : R / P i ^ e i`, we can choose a representative `y : R` such that `y ≡ x i (mod P i ^ e i)`. -/ theorem IsDedekindDomain.exists_representative_mod_finset {ι : Type*} {s : Finset ι} (P : ι → Ideal R) (e : ι → ℕ) (prime : ∀ i ∈ s, Prime (P i)) (coprime : ∀ᵉ (i ∈ s) (j ∈ s), i ≠ j → P i ≠ P j) (x : ∀ i : s, R ⧸ P i ^ e i) : ∃ y, ∀ (i) (hi : i ∈ s), Ideal.Quotient.mk (P i ^ e i) y = x ⟨i, hi⟩ := by let f := IsDedekindDomain.quotientEquivPiOfFinsetProdEq _ P e prime coprime rfl obtain ⟨y, rfl⟩ := f.surjective x obtain ⟨z, rfl⟩ := Ideal.Quotient.mk_surjective y exact ⟨z, fun i _hi => rfl⟩ /-- Corollary of the Chinese remainder theorem: given elements `x i : R`, we can choose a representative `y : R` such that `y - x i ∈ P i ^ e i`. -/ theorem IsDedekindDomain.exists_forall_sub_mem_ideal {ι : Type*} {s : Finset ι} (P : ι → Ideal R) (e : ι → ℕ) (prime : ∀ i ∈ s, Prime (P i)) (coprime : ∀ᵉ (i ∈ s) (j ∈ s), i ≠ j → P i ≠ P j) (x : s → R) : ∃ y, ∀ (i) (hi : i ∈ s), y - x ⟨i, hi⟩ ∈ P i ^ e i := by obtain ⟨y, hy⟩ := IsDedekindDomain.exists_representative_mod_finset P e prime coprime fun i => Ideal.Quotient.mk _ (x i) exact ⟨y, fun i hi => Ideal.Quotient.eq.mp (hy i hi)⟩ end DedekindDomain end ChineseRemainder section PID open multiplicity UniqueFactorizationMonoid Ideal variable {R} variable [IsDomain R] [IsPrincipalIdealRing R] theorem span_singleton_dvd_span_singleton_iff_dvd {a b : R} : Ideal.span {a} ∣ Ideal.span ({b} : Set R) ↔ a ∣ b := ⟨fun h => mem_span_singleton.mp (dvd_iff_le.mp h (mem_span_singleton.mpr (dvd_refl b))), fun h => dvd_iff_le.mpr fun _d hd => mem_span_singleton.mpr (dvd_trans h (mem_span_singleton.mp hd))⟩ @[simp] theorem Ideal.squarefree_span_singleton {a : R} : Squarefree (span {a}) ↔ Squarefree a := by refine ⟨fun h x hx ↦ ?_, fun h I hI ↦ ?_⟩ · rw [← span_singleton_dvd_span_singleton_iff_dvd, ← span_singleton_mul_span_singleton] at hx simpa using h _ hx · rw [← span_singleton_generator I, span_singleton_mul_span_singleton, span_singleton_dvd_span_singleton_iff_dvd] at hI exact isUnit_iff.mpr <| eq_top_of_isUnit_mem _ (Submodule.IsPrincipal.generator_mem I) (h _ hI) theorem singleton_span_mem_normalizedFactors_of_mem_normalizedFactors [NormalizationMonoid R] {a b : R} (ha : a ∈ normalizedFactors b) : Ideal.span ({a} : Set R) ∈ normalizedFactors (Ideal.span ({b} : Set R)) := by by_cases hb : b = 0 · rw [Ideal.span_singleton_eq_bot.mpr hb, bot_eq_zero, normalizedFactors_zero] rw [hb, normalizedFactors_zero] at ha exact absurd ha (Multiset.not_mem_zero a) · suffices Prime (Ideal.span ({a} : Set R)) by obtain ⟨c, hc, hc'⟩ := exists_mem_normalizedFactors_of_dvd ?_ this.irreducible (dvd_iff_le.mpr (span_singleton_le_span_singleton.mpr (dvd_of_mem_normalizedFactors ha))) rwa [associated_iff_eq.mp hc'] · by_contra h exact hb (span_singleton_eq_bot.mp h) rw [prime_iff_isPrime] · exact (span_singleton_prime (prime_of_normalized_factor a ha).ne_zero).mpr (prime_of_normalized_factor a ha) · by_contra h exact (prime_of_normalized_factor a ha).ne_zero (span_singleton_eq_bot.mp h) theorem multiplicity_eq_multiplicity_span [DecidableRel ((· ∣ ·) : R → R → Prop)] [DecidableRel ((· ∣ ·) : Ideal R → Ideal R → Prop)] {a b : R} : multiplicity (Ideal.span {a}) (Ideal.span ({b} : Set R)) = multiplicity a b := by by_cases h : Finite a b · rw [← PartENat.natCast_get (finite_iff_dom.mp h)] refine (multiplicity.unique (show Ideal.span {a} ^ (multiplicity a b).get h ∣ Ideal.span {b} from ?_) ?_).symm <;> rw [Ideal.span_singleton_pow, span_singleton_dvd_span_singleton_iff_dvd] · exact pow_multiplicity_dvd h · exact multiplicity.is_greatest ((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _))) · suffices ¬Finite (Ideal.span ({a} : Set R)) (Ideal.span ({b} : Set R)) by rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this rw [h, this] exact not_finite_iff_forall.mpr fun n => by rw [Ideal.span_singleton_pow, span_singleton_dvd_span_singleton_iff_dvd] exact not_finite_iff_forall.mp h n variable [DecidableEq R] [DecidableEq (Ideal R)] [NormalizationMonoid R] /-- The bijection between the (normalized) prime factors of `r` and the (normalized) prime factors of `span {r}` -/ -- @[simps] -- Porting note: simpNF complains about the lemmas generated by simps noncomputable def normalizedFactorsEquivSpanNormalizedFactors {r : R} (hr : r ≠ 0) : { d : R | d ∈ normalizedFactors r } ≃ { I : Ideal R | I ∈ normalizedFactors (Ideal.span ({r} : Set R)) } := by refine Equiv.ofBijective ?_ ?_ · exact fun d => ⟨Ideal.span {↑d}, singleton_span_mem_normalizedFactors_of_mem_normalizedFactors d.prop⟩ · refine ⟨?_, ?_⟩ · rintro ⟨a, ha⟩ ⟨b, hb⟩ h rw [Subtype.mk_eq_mk, Ideal.span_singleton_eq_span_singleton, Subtype.coe_mk, Subtype.coe_mk] at h exact Subtype.mk_eq_mk.mpr (mem_normalizedFactors_eq_of_associated ha hb h) · rintro ⟨i, hi⟩ have : i.IsPrime := isPrime_of_prime (prime_of_normalized_factor i hi) have := exists_mem_normalizedFactors_of_dvd hr (Submodule.IsPrincipal.prime_generator_of_isPrime i (prime_of_normalized_factor i hi).ne_zero).irreducible ?_ · obtain ⟨a, ha, ha'⟩ := this use ⟨a, ha⟩ simp only [Subtype.coe_mk, Subtype.mk_eq_mk, ← span_singleton_eq_span_singleton.mpr ha', Ideal.span_singleton_generator] · exact (Submodule.IsPrincipal.mem_iff_generator_dvd i).mp ((show Ideal.span {r} ≤ i from dvd_iff_le.mp (dvd_of_mem_normalizedFactors hi)) (mem_span_singleton.mpr (dvd_refl r))) variable [DecidableRel ((· ∣ ·) : R → R → Prop)] [DecidableRel ((· ∣ ·) : Ideal R → Ideal R → Prop)] /-- The bijection `normalizedFactorsEquivSpanNormalizedFactors` between the set of prime factors of `r` and the set of prime factors of the ideal `⟨r⟩` preserves multiplicities. See `count_normalizedFactorsSpan_eq_count` for the version stated in terms of multisets `count`.-/ theorem multiplicity_normalizedFactorsEquivSpanNormalizedFactors_eq_multiplicity {r d : R} (hr : r ≠ 0) (hd : d ∈ normalizedFactors r) : multiplicity d r = multiplicity (normalizedFactorsEquivSpanNormalizedFactors hr ⟨d, hd⟩ : Ideal R) (Ideal.span {r}) := by simp only [normalizedFactorsEquivSpanNormalizedFactors, multiplicity_eq_multiplicity_span, Subtype.coe_mk, Equiv.ofBijective_apply] /-- The bijection `normalized_factors_equiv_span_normalized_factors.symm` between the set of prime factors of the ideal `⟨r⟩` and the set of prime factors of `r` preserves multiplicities. -/ theorem multiplicity_normalizedFactorsEquivSpanNormalizedFactors_symm_eq_multiplicity {r : R} (hr : r ≠ 0) (I : { I : Ideal R | I ∈ normalizedFactors (Ideal.span ({r} : Set R)) }) : multiplicity ((normalizedFactorsEquivSpanNormalizedFactors hr).symm I : R) r = multiplicity (I : Ideal R) (Ideal.span {r}) := by obtain ⟨x, hx⟩ := (normalizedFactorsEquivSpanNormalizedFactors hr).surjective I obtain ⟨a, ha⟩ := x rw [hx.symm, Equiv.symm_apply_apply, Subtype.coe_mk, multiplicity_normalizedFactorsEquivSpanNormalizedFactors_eq_multiplicity hr ha] /-- The bijection between the set of prime factors of the ideal `⟨r⟩` and the set of prime factors of `r` preserves `count` of the corresponding multisets. See `multiplicity_normalizedFactorsEquivSpanNormalizedFactors_eq_multiplicity` for the version stated in terms of multiplicity. -/ theorem count_span_normalizedFactors_eq {r X : R} (hr : r ≠ 0) (hX : Prime X) : Multiset.count (Ideal.span {X} : Ideal R) (normalizedFactors (Ideal.span {r})) = Multiset.count (normalize X) (normalizedFactors r) := by have := multiplicity_eq_multiplicity_span (R := R) (a := X) (b := r) rw [multiplicity_eq_count_normalizedFactors (Prime.irreducible hX) hr, multiplicity_eq_count_normalizedFactors (Prime.irreducible ?_), normalize_apply, normUnit_eq_one, Units.val_one, one_eq_top, mul_top, Nat.cast_inj] at this · simp only [normalize_apply, this] · simp only [Submodule.zero_eq_bot, ne_eq, span_singleton_eq_bot, hr, not_false_eq_true] · simpa only [prime_span_singleton_iff] theorem count_span_normalizedFactors_eq_of_normUnit {r X : R} (hr : r ≠ 0) (hX₁ : normUnit X = 1) (hX : Prime X) : Multiset.count (Ideal.span {X} : Ideal R) (normalizedFactors (Ideal.span {r})) = Multiset.count X (normalizedFactors r) := by simpa [hX₁] using count_span_normalizedFactors_eq hr hX /-- The number of times an ideal `I` occurs as normalized factor of another ideal `J` is stable when regarding at these ideals as associated elements of the monoid of ideals.-/ theorem count_associates_factors_eq [DecidableEq <| Associates (Ideal R)] [∀ (p : Associates <| Ideal R), Decidable (Irreducible p)] (I J : Ideal R) (hI : I ≠ 0) (hJ : J.IsPrime) (hJ₀ : J ≠ ⊥) : (Associates.mk J).count (Associates.mk I).factors = Multiset.count J (normalizedFactors I) := by replace hI : Associates.mk I ≠ 0 := Associates.mk_ne_zero.mpr hI have hJ' : Irreducible (Associates.mk J) := by simpa only [Associates.irreducible_mk] using (Ideal.prime_of_isPrime hJ₀ hJ).irreducible apply (Ideal.count_normalizedFactors_eq (p := J) (x := I) _ _).symm all_goals rw [← Ideal.dvd_iff_le, ← Associates.mk_dvd_mk, Associates.mk_pow] simp only [Associates.dvd_eq_le] rw [Associates.prime_pow_dvd_iff_le hI hJ'] linarith end PID
RingTheory\DedekindDomain\IntegralClosure.lean
/- Copyright (c) 2020 Kenji Nakagawa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenji Nakagawa, Anne Baanen, Filippo A. E. Nuccio -/ import Mathlib.LinearAlgebra.FreeModule.PID import Mathlib.LinearAlgebra.FreeModule.Finite.Basic import Mathlib.LinearAlgebra.BilinearForm.DualLattice import Mathlib.RingTheory.DedekindDomain.Basic import Mathlib.RingTheory.Localization.Module import Mathlib.RingTheory.Trace.Basic /-! # Integral closure of Dedekind domains This file shows the integral closure of a Dedekind domain (in particular, the ring of integers of a number field) is a Dedekind domain. ## Implementation notes The definitions that involve a field of fractions choose a canonical field of fractions, but are independent of that choice. The `..._iff` lemmas express this independence. Often, definitions assume that Dedekind domains are not fields. We found it more practical to add a `(h : ¬IsField A)` assumption whenever this is explicitly needed. ## References * [D. Marcus, *Number Fields*][marcus1977number] * [J.W.S. Cassels, A. Frölich, *Algebraic Number Theory*][cassels1967algebraic] * [J. Neukirch, *Algebraic Number Theory*][Neukirch1992] ## Tags dedekind domain, dedekind ring -/ variable (R A K : Type*) [CommRing R] [CommRing A] [Field K] open scoped nonZeroDivisors Polynomial variable [IsDomain A] section IsIntegralClosure /-! ### `IsIntegralClosure` section We show that an integral closure of a Dedekind domain in a finite separable field extension is again a Dedekind domain. This implies the ring of integers of a number field is a Dedekind domain. -/ open Algebra variable [Algebra A K] [IsFractionRing A K] variable (L : Type*) [Field L] (C : Type*) [CommRing C] variable [Algebra K L] [Algebra A L] [IsScalarTower A K L] variable [Algebra C L] [IsIntegralClosure C A L] [Algebra A C] [IsScalarTower A C L] /-- If `L` is an algebraic extension of `K = Frac(A)` and `L` has no zero smul divisors by `A`, then `L` is the localization of the integral closure `C` of `A` in `L` at `A⁰`. -/ theorem IsIntegralClosure.isLocalization [Algebra.IsAlgebraic K L] : IsLocalization (Algebra.algebraMapSubmonoid C A⁰) L := by haveI : IsDomain C := (IsIntegralClosure.equiv A C L (integralClosure A L)).toMulEquiv.isDomain (integralClosure A L) haveI : NoZeroSMulDivisors A L := NoZeroSMulDivisors.trans A K L haveI : NoZeroSMulDivisors A C := IsIntegralClosure.noZeroSMulDivisors A L refine ⟨?_, fun z => ?_, fun {x y} h => ⟨1, ?_⟩⟩ · rintro ⟨_, x, hx, rfl⟩ rw [isUnit_iff_ne_zero, map_ne_zero_iff _ (IsIntegralClosure.algebraMap_injective C A L), Subtype.coe_mk, map_ne_zero_iff _ (NoZeroSMulDivisors.algebraMap_injective A C)] exact mem_nonZeroDivisors_iff_ne_zero.mp hx · obtain ⟨m, hm⟩ := IsIntegral.exists_multiple_integral_of_isLocalization A⁰ z (Algebra.IsIntegral.isIntegral (R := K) z) obtain ⟨x, hx⟩ : ∃ x, algebraMap C L x = m • z := IsIntegralClosure.isIntegral_iff.mp hm refine ⟨⟨x, algebraMap A C m, m, SetLike.coe_mem m, rfl⟩, ?_⟩ rw [Subtype.coe_mk, ← IsScalarTower.algebraMap_apply, hx, mul_comm, Submonoid.smul_def, smul_def] · simp only [IsIntegralClosure.algebraMap_injective C A L h] theorem IsIntegralClosure.isLocalization_of_isSeparable [Algebra.IsSeparable K L] : IsLocalization (Algebra.algebraMapSubmonoid C A⁰) L := IsIntegralClosure.isLocalization A K L C variable [FiniteDimensional K L] variable {A K L} theorem IsIntegralClosure.range_le_span_dualBasis [Algebra.IsSeparable K L] {ι : Type*} [Fintype ι] [DecidableEq ι] (b : Basis ι K L) (hb_int : ∀ i, IsIntegral A (b i)) [IsIntegrallyClosed A] : LinearMap.range ((Algebra.linearMap C L).restrictScalars A) ≤ Submodule.span A (Set.range <| (traceForm K L).dualBasis (traceForm_nondegenerate K L) b) := by rw [← LinearMap.BilinForm.dualSubmodule_span_of_basis, ← LinearMap.BilinForm.le_flip_dualSubmodule, Submodule.span_le] rintro _ ⟨i, rfl⟩ _ ⟨y, rfl⟩ simp only [LinearMap.coe_restrictScalars, linearMap_apply, LinearMap.BilinForm.flip_apply, traceForm_apply] refine IsIntegrallyClosed.isIntegral_iff.mp ?_ exact isIntegral_trace ((IsIntegralClosure.isIntegral A L y).algebraMap.mul (hb_int i)) theorem integralClosure_le_span_dualBasis [Algebra.IsSeparable K L] {ι : Type*} [Fintype ι] [DecidableEq ι] (b : Basis ι K L) (hb_int : ∀ i, IsIntegral A (b i)) [IsIntegrallyClosed A] : Subalgebra.toSubmodule (integralClosure A L) ≤ Submodule.span A (Set.range <| (traceForm K L).dualBasis (traceForm_nondegenerate K L) b) := by refine le_trans ?_ (IsIntegralClosure.range_le_span_dualBasis (integralClosure A L) b hb_int) intro x hx exact ⟨⟨x, hx⟩, rfl⟩ variable (A K) /-- Send a set of `x`s in a finite extension `L` of the fraction field of `R` to `(y : R) • x ∈ integralClosure R L`. -/ theorem exists_integral_multiples (s : Finset L) : ∃ y ≠ (0 : A), ∀ x ∈ s, IsIntegral A (y • x) := by haveI := Classical.decEq L refine s.induction ?_ ?_ · use 1, one_ne_zero rintro x ⟨⟩ · rintro x s hx ⟨y, hy, hs⟩ have := exists_integral_multiple ((IsFractionRing.isAlgebraic_iff A K L).mpr (.of_finite _ x)) ((injective_iff_map_eq_zero (algebraMap A L)).mp ?_) · rcases this with ⟨x', y', hy', hx'⟩ refine ⟨y * y', mul_ne_zero hy hy', fun x'' hx'' => ?_⟩ rcases Finset.mem_insert.mp hx'' with (rfl | hx'') · rw [mul_smul, Algebra.smul_def, Algebra.smul_def, mul_comm _ x'', hx'] exact isIntegral_algebraMap.mul x'.2 · rw [mul_comm, mul_smul, Algebra.smul_def] exact isIntegral_algebraMap.mul (hs _ hx'') · rw [IsScalarTower.algebraMap_eq A K L] apply (algebraMap K L).injective.comp exact IsFractionRing.injective _ _ variable (L) /-- If `L` is a finite extension of `K = Frac(A)`, then `L` has a basis over `A` consisting of integral elements. -/ theorem FiniteDimensional.exists_is_basis_integral : ∃ (s : Finset L) (b : Basis s K L), ∀ x, IsIntegral A (b x) := by letI := Classical.decEq L letI : IsNoetherian K L := IsNoetherian.iff_fg.2 inferInstance let s' := IsNoetherian.finsetBasisIndex K L let bs' := IsNoetherian.finsetBasis K L obtain ⟨y, hy, his'⟩ := exists_integral_multiples A K (Finset.univ.image bs') have hy' : algebraMap A L y ≠ 0 := by refine mt ((injective_iff_map_eq_zero (algebraMap A L)).mp ?_ _) hy rw [IsScalarTower.algebraMap_eq A K L] exact (algebraMap K L).injective.comp (IsFractionRing.injective A K) refine ⟨s', bs'.map {Algebra.lmul _ _ (algebraMap A L y) with toFun := fun x => algebraMap A L y * x invFun := fun x => (algebraMap A L y)⁻¹ * x left_inv := ?_ right_inv := ?_}, ?_⟩ · intro x; simp only [inv_mul_cancel_left₀ hy'] · intro x; simp only [mul_inv_cancel_left₀ hy'] · rintro ⟨x', hx'⟩ simp only [Algebra.smul_def, Finset.mem_image, exists_prop, Finset.mem_univ, true_and_iff] at his' simp only [Basis.map_apply, LinearEquiv.coe_mk] exact his' _ ⟨_, rfl⟩ variable [Algebra.IsSeparable K L] /-- If `L` is a finite separable extension of `K = Frac(A)`, where `A` is integrally closed and Noetherian, the integral closure `C` of `A` in `L` is Noetherian over `A`. -/ theorem IsIntegralClosure.isNoetherian [IsIntegrallyClosed A] [IsNoetherianRing A] : IsNoetherian A C := by haveI := Classical.decEq L obtain ⟨s, b, hb_int⟩ := FiniteDimensional.exists_is_basis_integral A K L let b' := (traceForm K L).dualBasis (traceForm_nondegenerate K L) b letI := isNoetherian_span_of_finite A (Set.finite_range b') let f : C →ₗ[A] Submodule.span A (Set.range b') := (Submodule.inclusion (IsIntegralClosure.range_le_span_dualBasis C b hb_int)).comp ((Algebra.linearMap C L).restrictScalars A).rangeRestrict refine isNoetherian_of_ker_bot f ?_ rw [LinearMap.ker_comp, Submodule.ker_inclusion, Submodule.comap_bot, LinearMap.ker_codRestrict] exact LinearMap.ker_eq_bot_of_injective (IsIntegralClosure.algebraMap_injective C A L) /-- If `L` is a finite separable extension of `K = Frac(A)`, where `A` is integrally closed and Noetherian, the integral closure `C` of `A` in `L` is Noetherian. -/ theorem IsIntegralClosure.isNoetherianRing [IsIntegrallyClosed A] [IsNoetherianRing A] : IsNoetherianRing C := isNoetherianRing_iff.mpr <| isNoetherian_of_tower A (IsIntegralClosure.isNoetherian A K L C) /-- If `L` is a finite separable extension of `K = Frac(A)`, where `A` is a principal ring and `L` has no zero smul divisors by `A`, the integral closure `C` of `A` in `L` is a free `A`-module. -/ theorem IsIntegralClosure.module_free [NoZeroSMulDivisors A L] [IsPrincipalIdealRing A] : Module.Free A C := haveI : NoZeroSMulDivisors A C := IsIntegralClosure.noZeroSMulDivisors A L haveI : IsNoetherian A C := IsIntegralClosure.isNoetherian A K L _ inferInstance /-- If `L` is a finite separable extension of `K = Frac(A)`, where `A` is a principal ring and `L` has no zero smul divisors by `A`, the `A`-rank of the integral closure `C` of `A` in `L` is equal to the `K`-rank of `L`. -/ theorem IsIntegralClosure.rank [IsPrincipalIdealRing A] [NoZeroSMulDivisors A L] : FiniteDimensional.finrank A C = FiniteDimensional.finrank K L := by haveI : Module.Free A C := IsIntegralClosure.module_free A K L C haveI : IsNoetherian A C := IsIntegralClosure.isNoetherian A K L C haveI : IsLocalization (Algebra.algebraMapSubmonoid C A⁰) L := IsIntegralClosure.isLocalization A K L C let b := Basis.localizationLocalization K A⁰ L (Module.Free.chooseBasis A C) rw [FiniteDimensional.finrank_eq_card_chooseBasisIndex, FiniteDimensional.finrank_eq_card_basis b] variable {A K} /-- If `L` is a finite separable extension of `K = Frac(A)`, where `A` is integrally closed and Noetherian, the integral closure of `A` in `L` is Noetherian. -/ theorem integralClosure.isNoetherianRing [IsIntegrallyClosed A] [IsNoetherianRing A] : IsNoetherianRing (integralClosure A L) := IsIntegralClosure.isNoetherianRing A K L (integralClosure A L) variable (A K) [IsDomain C] /-- If `L` is a finite separable extension of `K = Frac(A)`, where `A` is a Dedekind domain, the integral closure `C` of `A` in `L` is a Dedekind domain. This cannot be an instance since `A`, `K` or `L` can't be inferred. See also the instance `integralClosure.isDedekindDomain_fractionRing` where `K := FractionRing A` and `C := integralClosure A L`. -/ theorem IsIntegralClosure.isDedekindDomain [IsDedekindDomain A] : IsDedekindDomain C := have : IsFractionRing C L := IsIntegralClosure.isFractionRing_of_finite_extension A K L C have : Algebra.IsIntegral A C := IsIntegralClosure.isIntegral_algebra A L { IsIntegralClosure.isNoetherianRing A K L C, Ring.DimensionLEOne.isIntegralClosure A L C, (isIntegrallyClosed_iff L).mpr fun {x} hx => ⟨IsIntegralClosure.mk' C x (isIntegral_trans (R := A) _ hx), IsIntegralClosure.algebraMap_mk' _ _ _⟩ with : IsDedekindDomain C } /-- If `L` is a finite separable extension of `K = Frac(A)`, where `A` is a Dedekind domain, the integral closure of `A` in `L` is a Dedekind domain. This cannot be an instance since `K` can't be inferred. See also the instance `integralClosure.isDedekindDomain_fractionRing` where `K := FractionRing A`. -/ theorem integralClosure.isDedekindDomain [IsDedekindDomain A] : IsDedekindDomain (integralClosure A L) := IsIntegralClosure.isDedekindDomain A K L (integralClosure A L) variable [Algebra (FractionRing A) L] [IsScalarTower A (FractionRing A) L] variable [FiniteDimensional (FractionRing A) L] [Algebra.IsSeparable (FractionRing A) L] /-- If `L` is a finite separable extension of `Frac(A)`, where `A` is a Dedekind domain, the integral closure of `A` in `L` is a Dedekind domain. See also the lemma `integralClosure.isDedekindDomain` where you can choose the field of fractions yourself. -/ instance integralClosure.isDedekindDomain_fractionRing [IsDedekindDomain A] : IsDedekindDomain (integralClosure A L) := integralClosure.isDedekindDomain A (FractionRing A) L end IsIntegralClosure
RingTheory\DedekindDomain\PID.lean
/- Copyright (c) 2023 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.RingTheory.DedekindDomain.Dvr import Mathlib.RingTheory.DedekindDomain.Ideal /-! # Criteria under which a Dedekind domain is a PID This file contains some results that we can use to test wether all ideals in a Dedekind domain are principal. ## Main results * `Ideal.IsPrincipal.of_finite_maximals_of_isUnit`: an invertible ideal in a commutative ring with finitely many maximal ideals, is a principal ideal. * `IsPrincipalIdealRing.of_finite_primes`: if a Dedekind domain has finitely many prime ideals, it is a principal ideal domain. -/ variable {R : Type*} [CommRing R] open Ideal open UniqueFactorizationMonoid open scoped nonZeroDivisors open UniqueFactorizationMonoid /-- Let `P` be a prime ideal, `x ∈ P \ P²` and `x ∉ Q` for all prime ideals `Q ≠ P`. Then `P` is generated by `x`. -/ theorem Ideal.eq_span_singleton_of_mem_of_not_mem_sq_of_not_mem_prime_ne {P : Ideal R} (hP : P.IsPrime) [IsDedekindDomain R] {x : R} (x_mem : x ∈ P) (hxP2 : x ∉ P ^ 2) (hxQ : ∀ Q : Ideal R, IsPrime Q → Q ≠ P → x ∉ Q) : P = Ideal.span {x} := by letI := Classical.decEq (Ideal R) have hx0 : x ≠ 0 := by rintro rfl exact hxP2 (zero_mem _) by_cases hP0 : P = ⊥ · subst hP0 -- Porting note: was `simpa using hxP2` but that hypothesis didn't even seem relevant in Lean 3 rwa [eq_comm, span_singleton_eq_bot, ← mem_bot] have hspan0 : span ({x} : Set R) ≠ ⊥ := mt Ideal.span_singleton_eq_bot.mp hx0 have span_le := (Ideal.span_singleton_le_iff_mem _).mpr x_mem refine associated_iff_eq.mp ((associated_iff_normalizedFactors_eq_normalizedFactors hP0 hspan0).mpr (le_antisymm ((dvd_iff_normalizedFactors_le_normalizedFactors hP0 hspan0).mp ?_) ?_)) · rwa [Ideal.dvd_iff_le, Ideal.span_singleton_le_iff_mem] simp only [normalizedFactors_irreducible (Ideal.prime_of_isPrime hP0 hP).irreducible, normalize_eq, Multiset.le_iff_count, Multiset.count_singleton] intro Q split_ifs with hQ · subst hQ refine (Ideal.count_normalizedFactors_eq ?_ ?_).le <;> simp only [Ideal.span_singleton_le_iff_mem, pow_one] <;> assumption by_cases hQp : IsPrime Q · refine (Ideal.count_normalizedFactors_eq ?_ ?_).le <;> -- Porting note: included `zero_add` in the simp arguments simp only [Ideal.span_singleton_le_iff_mem, zero_add, pow_one, pow_zero, one_eq_top, Submodule.mem_top] exact hxQ _ hQp hQ · exact (Multiset.count_eq_zero.mpr fun hQi => hQp (isPrime_of_prime (irreducible_iff_prime.mp (irreducible_of_normalized_factor _ hQi)))).le -- Porting note: replaced three implicit coercions of `I` with explicit `(I : Submodule R A)` theorem FractionalIdeal.isPrincipal_of_unit_of_comap_mul_span_singleton_eq_top {R A : Type*} [CommRing R] [CommRing A] [Algebra R A] {S : Submonoid R} [IsLocalization S A] (I : (FractionalIdeal S A)ˣ) {v : A} (hv : v ∈ (↑I⁻¹ : FractionalIdeal S A)) (h : Submodule.comap (Algebra.linearMap R A) ((I : Submodule R A) * Submodule.span R {v}) = ⊤) : Submodule.IsPrincipal (I : Submodule R A) := by have hinv := I.mul_inv set J := Submodule.comap (Algebra.linearMap R A) ((I : Submodule R A) * Submodule.span R {v}) have hJ : IsLocalization.coeSubmodule A J = ↑I * Submodule.span R {v} := by -- Porting note: had to insert `val_eq_coe` into this rewrite. -- Arguably this is because `Subtype.ext_iff` is breaking the `FractionalIdeal` API. rw [Subtype.ext_iff, val_eq_coe, coe_mul, val_eq_coe, coe_one] at hinv apply Submodule.map_comap_eq_self rw [← Submodule.one_eq_range, ← hinv] exact Submodule.mul_le_mul_right ((Submodule.span_singleton_le_iff_mem _ _).2 hv) have : (1 : A) ∈ ↑I * Submodule.span R {v} := by rw [← hJ, h, IsLocalization.coeSubmodule_top, Submodule.mem_one] exact ⟨1, (algebraMap R _).map_one⟩ obtain ⟨w, hw, hvw⟩ := Submodule.mem_mul_span_singleton.1 this refine ⟨⟨w, ?_⟩⟩ rw [← FractionalIdeal.coe_spanSingleton S, ← inv_inv I, eq_comm] refine congr_arg coeToSubmodule (Units.eq_inv_of_mul_eq_one_left (le_antisymm ?_ ?_)) · conv_rhs => rw [← hinv, mul_comm] apply FractionalIdeal.mul_le_mul_left (FractionalIdeal.spanSingleton_le_iff_mem.mpr hw) · rw [FractionalIdeal.one_le, ← hvw, mul_comm] exact FractionalIdeal.mul_mem_mul hv (FractionalIdeal.mem_spanSingleton_self _ _) /-- An invertible fractional ideal of a commutative ring with finitely many maximal ideals is principal. https://math.stackexchange.com/a/95857 -/ theorem FractionalIdeal.isPrincipal.of_finite_maximals_of_inv {A : Type*} [CommRing A] [Algebra R A] {S : Submonoid R} [IsLocalization S A] (hS : S ≤ R⁰) (hf : {I : Ideal R | I.IsMaximal}.Finite) (I I' : FractionalIdeal S A) (hinv : I * I' = 1) : Submodule.IsPrincipal (I : Submodule R A) := by have hinv' := hinv rw [Subtype.ext_iff, val_eq_coe, coe_mul] at hinv let s := hf.toFinset haveI := Classical.decEq (Ideal R) have coprime : ∀ M ∈ s, ∀ M' ∈ s.erase M, M ⊔ M' = ⊤ := by simp_rw [Finset.mem_erase, hf.mem_toFinset] rintro M hM M' ⟨hne, hM'⟩ exact Ideal.IsMaximal.coprime_of_ne hM hM' hne.symm have nle : ∀ M ∈ s, ¬⨅ M' ∈ s.erase M, M' ≤ M := fun M hM => left_lt_sup.1 ((hf.mem_toFinset.1 hM).ne_top.lt_top.trans_eq (Ideal.sup_iInf_eq_top <| coprime M hM).symm) have : ∀ M ∈ s, ∃ a ∈ I, ∃ b ∈ I', a * b ∉ IsLocalization.coeSubmodule A M := by intro M hM; by_contra! h obtain ⟨x, hx, hxM⟩ := SetLike.exists_of_lt ((IsLocalization.coeSubmodule_strictMono hS (hf.mem_toFinset.1 hM).ne_top.lt_top).trans_eq hinv.symm) exact hxM (Submodule.map₂_le.2 h hx) choose! a ha b hb hm using this choose! u hu hum using fun M hM => SetLike.not_le_iff_exists.1 (nle M hM) let v := ∑ M ∈ s, u M • b M have hv : v ∈ I' := Submodule.sum_mem _ fun M hM => Submodule.smul_mem _ _ <| hb M hM refine FractionalIdeal.isPrincipal_of_unit_of_comap_mul_span_singleton_eq_top (Units.mkOfMulEqOne I I' hinv') hv (of_not_not fun h => ?_) obtain ⟨M, hM, hJM⟩ := Ideal.exists_le_maximal _ h replace hM := hf.mem_toFinset.2 hM have : ∀ a ∈ I, ∀ b ∈ I', ∃ c, algebraMap R _ c = a * b := by intro a ha b hb; have hi := hinv.le obtain ⟨c, -, hc⟩ := hi (Submodule.mul_mem_mul ha hb) exact ⟨c, hc⟩ have hmem : a M * v ∈ IsLocalization.coeSubmodule A M := by obtain ⟨c, hc⟩ := this _ (ha M hM) v hv refine IsLocalization.coeSubmodule_mono _ hJM ⟨c, ?_, hc⟩ have := Submodule.mul_mem_mul (ha M hM) (Submodule.mem_span_singleton_self v) rwa [← hc] at this simp_rw [v, Finset.mul_sum, mul_smul_comm] at hmem rw [← s.add_sum_erase _ hM, Submodule.add_mem_iff_left] at hmem · refine hm M hM ?_ obtain ⟨c, hc : algebraMap R A c = a M * b M⟩ := this _ (ha M hM) _ (hb M hM) rw [← hc] at hmem ⊢ rw [Algebra.smul_def, ← _root_.map_mul] at hmem obtain ⟨d, hdM, he⟩ := hmem rw [IsLocalization.injective _ hS he] at hdM -- Note: #8386 had to specify the value of `f` exact Submodule.mem_map_of_mem (f := Algebra.linearMap _ _) (((hf.mem_toFinset.1 hM).isPrime.mem_or_mem hdM).resolve_left <| hum M hM) · refine Submodule.sum_mem _ fun M' hM' => ?_ rw [Finset.mem_erase] at hM' obtain ⟨c, hc⟩ := this _ (ha M hM) _ (hb M' hM'.2) rw [← hc, Algebra.smul_def, ← _root_.map_mul] specialize hu M' hM'.2 simp_rw [Ideal.mem_iInf, Finset.mem_erase] at hu -- Note: #8386 had to specify the value of `f` exact Submodule.mem_map_of_mem (f := Algebra.linearMap _ _) (M.mul_mem_right _ <| hu M ⟨hM'.1.symm, hM⟩) /-- An invertible ideal in a commutative ring with finitely many maximal ideals is principal. https://math.stackexchange.com/a/95857 -/ theorem Ideal.IsPrincipal.of_finite_maximals_of_isUnit (hf : {I : Ideal R | I.IsMaximal}.Finite) {I : Ideal R} (hI : IsUnit (I : FractionalIdeal R⁰ (FractionRing R))) : I.IsPrincipal := (IsLocalization.coeSubmodule_isPrincipal _ le_rfl).mp (FractionalIdeal.isPrincipal.of_finite_maximals_of_inv le_rfl hf I (↑hI.unit⁻¹ : FractionalIdeal R⁰ (FractionRing R)) hI.unit.mul_inv) /-- A Dedekind domain is a PID if its set of primes is finite. -/ theorem IsPrincipalIdealRing.of_finite_primes [IsDedekindDomain R] (h : {I : Ideal R | I.IsPrime}.Finite) : IsPrincipalIdealRing R := ⟨fun I => by obtain rfl | hI := eq_or_ne I ⊥ · exact bot_isPrincipal apply Ideal.IsPrincipal.of_finite_maximals_of_isUnit · apply h.subset; exact @Ideal.IsMaximal.isPrime _ _ · exact isUnit_of_mul_eq_one _ _ (FractionalIdeal.coe_ideal_mul_inv I hI)⟩ variable [IsDedekindDomain R] variable (S : Type*) [CommRing S] variable [Algebra R S] [Module.Free R S] [Module.Finite R S] variable (p : Ideal R) (hp0 : p ≠ ⊥) [IsPrime p] variable {Sₚ : Type*} [CommRing Sₚ] [Algebra S Sₚ] variable [IsLocalization (Algebra.algebraMapSubmonoid S p.primeCompl) Sₚ] variable [Algebra R Sₚ] [IsScalarTower R S Sₚ] /- The first hypothesis below follows from properties of the localization but is needed for the second, so we leave it to the user to provide (automatically). -/ variable [IsDedekindDomain Sₚ] /-- If `p` is a prime in the Dedekind domain `R`, `S` an extension of `R` and `Sₚ` the localization of `S` at `p`, then all primes in `Sₚ` are factors of the image of `p` in `Sₚ`. -/ theorem IsLocalization.OverPrime.mem_normalizedFactors_of_isPrime [IsDomain S] {P : Ideal Sₚ} (hP : IsPrime P) (hP0 : P ≠ ⊥) : P ∈ normalizedFactors (Ideal.map (algebraMap R Sₚ) p) := by have non_zero_div : Algebra.algebraMapSubmonoid S p.primeCompl ≤ S⁰ := map_le_nonZeroDivisors_of_injective _ (NoZeroSMulDivisors.algebraMap_injective _ _) p.primeCompl_le_nonZeroDivisors letI : Algebra (Localization.AtPrime p) Sₚ := localizationAlgebra p.primeCompl S haveI : IsScalarTower R (Localization.AtPrime p) Sₚ := IsScalarTower.of_algebraMap_eq fun x => by -- Porting note: replaced `erw` with a `rw` followed by `exact` to help infer implicits rw [IsScalarTower.algebraMap_apply R S] exact (IsLocalization.map_eq (T := Algebra.algebraMapSubmonoid S (primeCompl p)) (Submonoid.le_comap_map _) x).symm obtain ⟨pid, p', ⟨hp'0, hp'p⟩, hpu⟩ := (DiscreteValuationRing.iff_pid_with_one_nonzero_prime (Localization.AtPrime p)).mp (IsLocalization.AtPrime.discreteValuationRing_of_dedekind_domain R hp0 _) have : LocalRing.maximalIdeal (Localization.AtPrime p) ≠ ⊥ := by rw [Submodule.ne_bot_iff] at hp0 ⊢ obtain ⟨x, x_mem, x_ne⟩ := hp0 exact ⟨algebraMap _ _ x, (IsLocalization.AtPrime.to_map_mem_maximal_iff _ _ _).mpr x_mem, IsLocalization.to_map_ne_zero_of_mem_nonZeroDivisors _ p.primeCompl_le_nonZeroDivisors (mem_nonZeroDivisors_of_ne_zero x_ne)⟩ rw [← Multiset.singleton_le, ← normalize_eq P, ← normalizedFactors_irreducible (Ideal.prime_of_isPrime hP0 hP).irreducible, ← dvd_iff_normalizedFactors_le_normalizedFactors hP0, dvd_iff_le, IsScalarTower.algebraMap_eq R (Localization.AtPrime p) Sₚ, ← Ideal.map_map, Localization.AtPrime.map_eq_maximalIdeal, Ideal.map_le_iff_le_comap, hpu (LocalRing.maximalIdeal _) ⟨this, _⟩, hpu (comap _ _) ⟨_, _⟩] · have : Algebra.IsIntegral (Localization.AtPrime p) Sₚ := ⟨isIntegral_localization⟩ exact mt (Ideal.eq_bot_of_comap_eq_bot ) hP0 · exact Ideal.comap_isPrime (algebraMap (Localization.AtPrime p) Sₚ) P · exact (LocalRing.maximalIdeal.isMaximal _).isPrime · rw [Ne, zero_eq_bot, Ideal.map_eq_bot_iff_of_injective] · assumption rw [IsScalarTower.algebraMap_eq R S Sₚ] exact (IsLocalization.injective Sₚ non_zero_div).comp (NoZeroSMulDivisors.algebraMap_injective _ _) /-- Let `p` be a prime in the Dedekind domain `R` and `S` be an integral extension of `R`, then the localization `Sₚ` of `S` at `p` is a PID. -/ theorem IsDedekindDomain.isPrincipalIdealRing_localization_over_prime [IsDomain S] : IsPrincipalIdealRing Sₚ := by letI := Classical.decEq (Ideal Sₚ) letI := Classical.decPred fun P : Ideal Sₚ => P.IsPrime refine IsPrincipalIdealRing.of_finite_primes (Set.Finite.ofFinset (Finset.filter (fun P => P.IsPrime) ({⊥} ∪ (normalizedFactors (Ideal.map (algebraMap R Sₚ) p)).toFinset)) fun P => ?_) rw [Finset.mem_filter, Finset.mem_union, Finset.mem_singleton, Set.mem_setOf, Multiset.mem_toFinset] exact and_iff_right_of_imp fun hP => or_iff_not_imp_left.mpr (IsLocalization.OverPrime.mem_normalizedFactors_of_isPrime S p hp0 hP)
RingTheory\DedekindDomain\SelmerGroup.lean
/- Copyright (c) 2022 David Kurniadi Angdinata. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Kurniadi Angdinata -/ import Mathlib.Algebra.Group.Equiv.TypeTags import Mathlib.Data.ZMod.Quotient import Mathlib.RingTheory.DedekindDomain.AdicValuation /-! # Selmer groups of fraction fields of Dedekind domains Let $K$ be the field of fractions of a Dedekind domain $R$. For any set $S$ of prime ideals in the height one spectrum of $R$, and for any natural number $n$, the Selmer group $K(S, n)$ is defined to be the subgroup of the unit group $K^\times$ modulo $n$-th powers where each element has $v$-adic valuation divisible by $n$ for all prime ideals $v$ away from $S$. In other words, this is precisely $$ K(S, n) := \{x(K^\times)^n \in K^\times / (K^\times)^n \ \mid \ \forall v \notin S, \ \mathrm{ord}_v(x) \equiv 0 \pmod n\}. $$ There is a fundamental short exact sequence $$ 1 \to R_S^\times / (R_S^\times)^n \to K(S, n) \to \mathrm{Cl}_S(R)[n] \to 0, $$ where $R_S^\times$ is the $S$-unit group of $R$ and $\mathrm{Cl}_S(R)$ is the $S$-class group of $R$. If the flanking groups are both finite, then $K(S, n)$ is finite by the first isomorphism theorem. Such is the case when $R$ is the ring of integers of a number field $K$, $S$ is finite, and $n$ is positive, in which case $R_S^\times$ is finitely generated by Dirichlet's unit theorem and $\mathrm{Cl}_S(R)$ is finite by the class number theorem. This file defines the Selmer group $K(S, n)$ and some basic facts. ## Main definitions * `IsDedekindDomain.selmerGroup`: the Selmer group. * TODO: maps in the sequence. ## Main statements * TODO: proofs of exactness of the sequence. * TODO: proofs of finiteness for global fields. ## Notations * `K⟮S, n⟯`: the Selmer group with parameters `K`, `S`, and `n`. ## Implementation notes The Selmer group is typically defined as a subgroup of the Galois cohomology group $H^1(K, \mu_n)$ with certain local conditions defined by $v$-adic valuations, where $\mu_n$ is the group of $n$-th roots of unity over a separable closure of $K$. Here $H^1(K, \mu_n)$ is identified with $K^\times / (K^\times)^n$ by the long exact sequence from Kummer theory and Hilbert's theorem 90, and the fundamental short exact sequence becomes an easy consequence of the snake lemma. This file will define all the maps explicitly for computational purposes, but isomorphisms to the Galois cohomological definition will be provided when possible. ## References https://doc.sagemath.org/html/en/reference/number_fields/sage/rings/number_field/selmer_group.html ## Tags class group, selmer group, unit group -/ set_option quotPrecheck false local notation K "/" n => Kˣ ⧸ (powMonoidHom n : Kˣ →* Kˣ).range namespace IsDedekindDomain noncomputable section open scoped DiscreteValuation nonZeroDivisors universe u v variable {R : Type u} [CommRing R] [IsDedekindDomain R] {K : Type v} [Field K] [Algebra R K] [IsFractionRing R K] (v : HeightOneSpectrum R) /-! ### Valuations of non-zero elements -/ namespace HeightOneSpectrum open Classical in /-- The multiplicative `v`-adic valuation on `Kˣ`. -/ def valuationOfNeZeroToFun (x : Kˣ) : Multiplicative ℤ := let hx := IsLocalization.sec R⁰ (x : K) Multiplicative.ofAdd <| (-(Associates.mk v.asIdeal).count (Associates.mk <| Ideal.span {hx.fst}).factors : ℤ) - (-(Associates.mk v.asIdeal).count (Associates.mk <| Ideal.span {(hx.snd : R)}).factors : ℤ) @[simp] theorem valuationOfNeZeroToFun_eq (x : Kˣ) : (v.valuationOfNeZeroToFun x : ℤₘ₀) = v.valuation (x : K) := by classical rw [show v.valuation (x : K) = _ * _ by rfl] rw [Units.val_inv_eq_inv_val] change _ = ite _ _ _ * (ite _ _ _)⁻¹ simp_rw [IsLocalization.toLocalizationMap_sec, SubmonoidClass.coe_subtype, if_neg <| IsLocalization.sec_fst_ne_zero le_rfl x.ne_zero, if_neg (nonZeroDivisors.coe_ne_zero _), valuationOfNeZeroToFun, ofAdd_sub, ofAdd_neg, div_inv_eq_mul, WithZero.coe_mul, WithZero.coe_inv, inv_inv] /-- The multiplicative `v`-adic valuation on `Kˣ`. -/ def valuationOfNeZero : Kˣ →* Multiplicative ℤ where toFun := v.valuationOfNeZeroToFun map_one' := by rw [← WithZero.coe_inj, valuationOfNeZeroToFun_eq]; exact map_one _ map_mul' _ _ := by rw [← WithZero.coe_inj, WithZero.coe_mul] simp only [valuationOfNeZeroToFun_eq]; exact map_mul _ _ _ @[simp] theorem valuationOfNeZero_eq (x : Kˣ) : (v.valuationOfNeZero x : ℤₘ₀) = v.valuation (x : K) := valuationOfNeZeroToFun_eq v x @[simp] theorem valuation_of_unit_eq (x : Rˣ) : v.valuationOfNeZero (Units.map (algebraMap R K : R →* K) x) = 1 := by rw [← WithZero.coe_inj, valuationOfNeZero_eq, Units.coe_map, eq_iff_le_not_lt] constructor · exact v.valuation_le_one x · cases' x with x _ hx _ change ¬v.valuation (algebraMap R K x) < 1 apply_fun v.intValuation at hx rw [map_one, map_mul] at hx rw [not_lt, ← hx, ← mul_one <| v.valuation _, valuation_of_algebraMap, mul_le_mul_left₀ <| left_ne_zero_of_mul_eq_one hx] exact v.intValuation_le_one _ -- Porting note: invalid attribute 'semireducible', declaration is in an imported module -- attribute [local semireducible] MulOpposite /-- The multiplicative `v`-adic valuation on `Kˣ` modulo `n`-th powers. -/ def valuationOfNeZeroMod (n : ℕ) : (K/n) →* Multiplicative (ZMod n) := (Int.quotientZMultiplesNatEquivZMod n).toMultiplicative.toMonoidHom.comp <| QuotientGroup.map (powMonoidHom n : Kˣ →* Kˣ).range (AddSubgroup.toSubgroup (AddSubgroup.zmultiples (n : ℤ))) v.valuationOfNeZero (by rintro _ ⟨x, rfl⟩ exact ⟨v.valuationOfNeZero x, by simp only [powMonoidHom_apply, map_pow, Int.toAdd_pow]; rfl⟩) @[simp] theorem valuation_of_unit_mod_eq (n : ℕ) (x : Rˣ) : v.valuationOfNeZeroMod n (Units.map (algebraMap R K : R →* K) x : K/n) = 1 := by -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [valuationOfNeZeroMod, MonoidHom.comp_apply, ← QuotientGroup.coe_mk', QuotientGroup.map_mk' (G := Kˣ) (N := MonoidHom.range (powMonoidHom n)), valuation_of_unit_eq, QuotientGroup.mk_one, map_one] end HeightOneSpectrum /-! ### Selmer groups -/ variable {S S' : Set <| HeightOneSpectrum R} {n : ℕ} /-- The Selmer group `K⟮S, n⟯`. -/ def selmerGroup : Subgroup <| K/n where carrier := {x : K/n | ∀ (v) (_ : v ∉ S), (v : HeightOneSpectrum R).valuationOfNeZeroMod n x = 1} one_mem' _ _ := by rw [map_one] mul_mem' hx hy v hv := by rw [map_mul, hx v hv, hy v hv, one_mul] inv_mem' hx v hv := by rw [map_inv, hx v hv, inv_one] -- Porting note: was `scoped[SelmerGroup]` but that does not work even using `open SelmerGroup` local notation K "⟮" S "," n "⟯" => @selmerGroup _ _ _ K _ _ _ S n namespace selmerGroup theorem monotone (hS : S ≤ S') : K⟮S,n⟯ ≤ K⟮S',n⟯ := fun _ hx v => hx v ∘ mt (@hS v) /-- The multiplicative `v`-adic valuations on `K⟮S, n⟯` for all `v ∈ S`. -/ def valuation : K⟮S,n⟯ →* S → Multiplicative (ZMod n) where toFun x v := (v : HeightOneSpectrum R).valuationOfNeZeroMod n (x : K/n) map_one' := funext fun v => map_one _ map_mul' x y := by simp only [Submonoid.coe_mul, Subgroup.coe_toSubmonoid, map_mul]; rfl theorem valuation_ker_eq : valuation.ker = K⟮(∅ : Set <| HeightOneSpectrum R),n⟯.subgroupOf (K⟮S,n⟯) := by ext ⟨_, hx⟩ constructor · intro hx' v _ by_cases hv : v ∈ S · exact congr_fun hx' ⟨v, hv⟩ · exact hx v hv · exact fun hx' => funext fun v => hx' v <| Set.not_mem_empty v /-- The natural homomorphism from `Rˣ` to `K⟮∅, n⟯`. -/ def fromUnit {n : ℕ} : Rˣ →* K⟮(∅ : Set <| HeightOneSpectrum R),n⟯ where toFun x := ⟨QuotientGroup.mk <| Units.map (algebraMap R K).toMonoidHom x, fun v _ => v.valuation_of_unit_mod_eq n x⟩ map_one' := by simp only [map_one, QuotientGroup.mk_one, Subgroup.mk_eq_one] map_mul' _ _ := by simp only [RingHom.toMonoidHom_eq_coe, map_mul, MonoidHom.mem_range, powMonoidHom_apply, QuotientGroup.mk_mul, Submonoid.mk_mul_mk] theorem fromUnit_ker [hn : Fact <| 0 < n] : (@fromUnit R _ _ K _ _ _ n).ker = (powMonoidHom n : Rˣ →* Rˣ).range := by ext ⟨_, _, _, _⟩ constructor · intro hx rcases (QuotientGroup.eq_one_iff _).mp (Subtype.mk.inj hx) with ⟨⟨v, i, vi, iv⟩, hx⟩ have hv : ↑(_ ^ n : Kˣ) = algebraMap R K _ := congr_arg Units.val hx have hi : ↑(_ ^ n : Kˣ)⁻¹ = algebraMap R K _ := congr_arg Units.inv hx rw [Units.val_pow_eq_pow_val] at hv rw [← inv_pow, Units.inv_mk, Units.val_pow_eq_pow_val] at hi rcases IsIntegrallyClosed.exists_algebraMap_eq_of_isIntegral_pow (R := R) (x := v) hn.out (hv.symm ▸ isIntegral_algebraMap) with ⟨v', rfl⟩ rcases IsIntegrallyClosed.exists_algebraMap_eq_of_isIntegral_pow (R := R) (x := i) hn.out (hi.symm ▸ isIntegral_algebraMap) with ⟨i', rfl⟩ rw [← map_mul, map_eq_one_iff _ <| NoZeroSMulDivisors.algebraMap_injective R K] at vi rw [← map_mul, map_eq_one_iff _ <| NoZeroSMulDivisors.algebraMap_injective R K] at iv rw [Units.val_mk, ← map_pow] at hv exact ⟨⟨v', i', vi, iv⟩, by simpa only [Units.ext_iff, powMonoidHom_apply, Units.val_pow_eq_pow_val] using NoZeroSMulDivisors.algebraMap_injective R K hv⟩ · rintro ⟨x, hx⟩ rw [← hx] exact Subtype.mk_eq_mk.mpr <| (QuotientGroup.eq_one_iff _).mpr ⟨Units.map (algebraMap R K) x, by simp only [powMonoidHom_apply, RingHom.toMonoidHom_eq_coe, map_pow]⟩ /-- The injection induced by the natural homomorphism from `Rˣ` to `K⟮∅, n⟯`. -/ def fromUnitLift [Fact <| 0 < n] : (R/n) →* K⟮(∅ : Set <| HeightOneSpectrum R),n⟯ := (QuotientGroup.kerLift _).comp (QuotientGroup.quotientMulEquivOfEq (fromUnit_ker (R := R))).symm.toMonoidHom theorem fromUnitLift_injective [Fact <| 0 < n] : Function.Injective <| @fromUnitLift R _ _ K _ _ _ n _ := by dsimp only [fromUnitLift, MonoidHom.coe_comp, MulEquiv.coe_toMonoidHom] exact Function.Injective.comp (QuotientGroup.kerLift_injective _) (MulEquiv.injective _) end selmerGroup end end IsDedekindDomain
RingTheory\DedekindDomain\SInteger.lean
/- Copyright (c) 2022 David Kurniadi Angdinata. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Kurniadi Angdinata -/ import Mathlib.RingTheory.DedekindDomain.AdicValuation /-! # `S`-integers and `S`-units of fraction fields of Dedekind domains Let `K` be the field of fractions of a Dedekind domain `R`, and let `S` be a set of prime ideals in the height one spectrum of `R`. An `S`-integer of `K` is defined to have `v`-adic valuation at most one for all primes ideals `v` away from `S`, whereas an `S`-unit of `Kˣ` is defined to have `v`-adic valuation exactly one for all prime ideals `v` away from `S`. This file defines the subalgebra of `S`-integers of `K` and the subgroup of `S`-units of `Kˣ`, where `K` can be specialised to the case of a number field or a function field separately. ## Main definitions * `Set.integer`: `S`-integers. * `Set.unit`: `S`-units. * TODO: localised notation for `S`-integers. ## Main statements * `Set.unitEquivUnitsInteger`: `S`-units are units of `S`-integers. * TODO: proof that `S`-units is the kernel of a map to a product. * TODO: proof that `∅`-integers is the usual ring of integers. * TODO: finite generation of `S`-units and Dirichlet's `S`-unit theorem. ## References * [D Marcus, *Number Fields*][marcus1977number] * [J W S Cassels, A Frölich, *Algebraic Number Theory*][cassels1967algebraic] * [J Neukirch, *Algebraic Number Theory*][Neukirch1992] ## Tags S integer, S-integer, S unit, S-unit -/ namespace Set noncomputable section open IsDedekindDomain open scoped nonZeroDivisors universe u v variable {R : Type u} [CommRing R] [IsDedekindDomain R] (S : Set <| HeightOneSpectrum R) (K : Type v) [Field K] [Algebra R K] [IsFractionRing R K] /-! ## `S`-integers -/ /-- The `R`-subalgebra of `S`-integers of `K`. -/ @[simps!] def integer : Subalgebra R K := { (⨅ (v) (_ : v ∉ S), (v : HeightOneSpectrum R).valuation.valuationSubring.toSubring).copy {x : K | ∀ (v) (_ : v ∉ S), (v : HeightOneSpectrum R).valuation x ≤ 1} <| Set.ext fun _ => by simp [SetLike.mem_coe, Subring.mem_iInf] with algebraMap_mem' := fun x v _ => v.valuation_le_one x } theorem integer_eq : (S.integer K).toSubring = ⨅ (v) (_ : v ∉ S), (v : HeightOneSpectrum R).valuation.valuationSubring.toSubring := SetLike.ext' <| by -- Porting note: was `simpa only [integer, Subring.copy_eq]` ext; simp theorem integer_valuation_le_one (x : S.integer K) {v : HeightOneSpectrum R} (hv : v ∉ S) : v.valuation (x : K) ≤ 1 := x.property v hv /-! ## `S`-units -/ /-- The subgroup of `S`-units of `Kˣ`. -/ @[simps!] def unit : Subgroup Kˣ := (⨅ (v) (_ : v ∉ S), (v : HeightOneSpectrum R).valuation.valuationSubring.unitGroup).copy {x : Kˣ | ∀ (v) (_ : v ∉ S), (v : HeightOneSpectrum R).valuation (x : K) = 1} <| Set.ext fun _ => by -- Porting note: was -- simpa only [SetLike.mem_coe, Subgroup.mem_iInf, Valuation.mem_unitGroup_iff] simp only [mem_setOf, SetLike.mem_coe, Subgroup.mem_iInf, Valuation.mem_unitGroup_iff] theorem unit_eq : S.unit K = ⨅ (v) (_ : v ∉ S), (v : HeightOneSpectrum R).valuation.valuationSubring.unitGroup := Subgroup.copy_eq _ _ _ theorem unit_valuation_eq_one (x : S.unit K) {v : HeightOneSpectrum R} (hv : v ∉ S) : v.valuation ((x : Kˣ) : K) = 1 := x.property v hv -- Porting note: `apply_inv_coe` fails the simpNF linter /-- The group of `S`-units is the group of units of the ring of `S`-integers. -/ @[simps apply_val_coe symm_apply_coe] def unitEquivUnitsInteger : S.unit K ≃* (S.integer K)ˣ where toFun x := ⟨⟨((x : Kˣ) : K), fun v hv => (x.property v hv).le⟩, ⟨((x⁻¹ : Kˣ) : K), fun v hv => (x⁻¹.property v hv).le⟩, Subtype.ext x.val.val_inv, Subtype.ext x.val.inv_val⟩ invFun x := ⟨Units.mk0 x fun hx => x.ne_zero (ZeroMemClass.coe_eq_zero.mp hx), fun v hv => eq_one_of_one_le_mul_left (x.val.property v hv) (x.inv.property v hv) <| Eq.ge <| by -- Porting note: was -- rw [← map_mul]; convert v.valuation.map_one; exact subtype.mk_eq_mk.mp x.val_inv⟩ rw [Units.val_mk0, ← map_mul, Subtype.mk_eq_mk.mp x.val_inv, v.valuation.map_one]⟩ left_inv _ := by ext; rfl right_inv _ := by ext; rfl map_mul' _ _ := by ext; rfl end end Set
RingTheory\Derivation\Basic.lean
/- Copyright (c) 2020 Nicolò Cavalleri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nicolò Cavalleri, Andrew Yang -/ import Mathlib.RingTheory.Adjoin.Basic import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.Derivative /-! # Derivations This file defines derivation. A derivation `D` from the `R`-algebra `A` to the `A`-module `M` is an `R`-linear map that satisfy the Leibniz rule `D (a * b) = a * D b + D a * b`. ## Main results - `Derivation`: The type of `R`-derivations from `A` to `M`. This has an `A`-module structure. - `Derivation.llcomp`: We may compose linear maps and derivations to obtain a derivation, and the composition is bilinear. See `RingTheory.Derivation.Lie` for - `derivation.lie_algebra`: The `R`-derivations from `A` to `A` form a lie algebra over `R`. and `RingTheory.Derivation.ToSquareZero` for - `derivationToSquareZeroEquivLift`: The `R`-derivations from `A` into a square-zero ideal `I` of `B` corresponds to the lifts `A →ₐ[R] B` of the map `A →ₐ[R] B ⧸ I`. ## Future project - Generalize derivations into bimodules. -/ open Algebra /-- `D : Derivation R A M` is an `R`-linear map from `A` to `M` that satisfies the `leibniz` equality. We also require that `D 1 = 0`. See `Derivation.mk'` for a constructor that deduces this assumption from the Leibniz rule when `M` is cancellative. TODO: update this when bimodules are defined. -/ structure Derivation (R : Type*) (A : Type*) (M : Type*) [CommSemiring R] [CommSemiring A] [AddCommMonoid M] [Algebra R A] [Module A M] [Module R M] extends A →ₗ[R] M where protected map_one_eq_zero' : toLinearMap 1 = 0 protected leibniz' (a b : A) : toLinearMap (a * b) = a • toLinearMap b + b • toLinearMap a /-- The `LinearMap` underlying a `Derivation`. -/ add_decl_doc Derivation.toLinearMap namespace Derivation section variable {R : Type*} {A : Type*} {B : Type*} {M : Type*} variable [CommSemiring R] [CommSemiring A] [CommSemiring B] [AddCommMonoid M] variable [Algebra R A] [Algebra R B] variable [Module A M] [Module B M] [Module R M] variable (D : Derivation R A M) {D1 D2 : Derivation R A M} (r : R) (a b : A) instance : FunLike (Derivation R A M) A M where coe D := D.toFun coe_injective' D1 D2 h := by cases D1; cases D2; congr; exact DFunLike.coe_injective h instance : AddMonoidHomClass (Derivation R A M) A M where map_add D := D.toLinearMap.map_add' map_zero D := D.toLinearMap.map_zero -- Not a simp lemma because it can be proved via `coeFn_coe` + `toLinearMap_eq_coe` theorem toFun_eq_coe : D.toFun = ⇑D := rfl /-- See Note [custom simps projection] -/ def Simps.apply (D : Derivation R A M) : A → M := D initialize_simps_projections Derivation (toFun → apply) attribute [coe] toLinearMap instance hasCoeToLinearMap : Coe (Derivation R A M) (A →ₗ[R] M) := ⟨fun D => D.toLinearMap⟩ @[simp] theorem mk_coe (f : A →ₗ[R] M) (h₁ h₂) : ((⟨f, h₁, h₂⟩ : Derivation R A M) : A → M) = f := rfl @[simp, norm_cast] theorem coeFn_coe (f : Derivation R A M) : ⇑(f : A →ₗ[R] M) = f := rfl theorem coe_injective : @Function.Injective (Derivation R A M) (A → M) DFunLike.coe := DFunLike.coe_injective @[ext] theorem ext (H : ∀ a, D1 a = D2 a) : D1 = D2 := DFunLike.ext _ _ H theorem congr_fun (h : D1 = D2) (a : A) : D1 a = D2 a := DFunLike.congr_fun h a protected theorem map_add : D (a + b) = D a + D b := map_add D a b protected theorem map_zero : D 0 = 0 := map_zero D @[simp] theorem map_smul : D (r • a) = r • D a := D.toLinearMap.map_smul r a @[simp] theorem leibniz : D (a * b) = a • D b + b • D a := D.leibniz' _ _ @[simp] theorem map_smul_of_tower {S : Type*} [SMul S A] [SMul S M] [LinearMap.CompatibleSMul A M S R] (D : Derivation R A M) (r : S) (a : A) : D (r • a) = r • D a := D.toLinearMap.map_smul_of_tower r a @[simp] theorem map_one_eq_zero : D 1 = 0 := D.map_one_eq_zero' @[simp] theorem map_algebraMap : D (algebraMap R A r) = 0 := by rw [← mul_one r, RingHom.map_mul, RingHom.map_one, ← smul_def, map_smul, map_one_eq_zero, smul_zero] @[simp] theorem map_natCast (n : ℕ) : D (n : A) = 0 := by rw [← nsmul_one, D.map_smul_of_tower n, map_one_eq_zero, smul_zero] @[simp] theorem leibniz_pow (n : ℕ) : D (a ^ n) = n • a ^ (n - 1) • D a := by induction' n with n ihn · rw [pow_zero, map_one_eq_zero, zero_smul] · rcases (zero_le n).eq_or_lt with (rfl | hpos) · erw [pow_one, one_smul, pow_zero, one_smul] · have : a * a ^ (n - 1) = a ^ n := by rw [← pow_succ', Nat.sub_add_cancel hpos] simp only [pow_succ', leibniz, ihn, smul_comm a n (_ : M), smul_smul a, add_smul, this, Nat.succ_eq_add_one, Nat.add_succ_sub_one, add_zero, one_nsmul] open Polynomial in @[simp] theorem map_aeval (P : R[X]) (x : A) : D (aeval x P) = aeval x (derivative P) • D x := by induction P using Polynomial.induction_on · simp · simp [add_smul, *] · simp [mul_smul, ← Nat.cast_smul_eq_nsmul A] theorem eqOn_adjoin {s : Set A} (h : Set.EqOn D1 D2 s) : Set.EqOn D1 D2 (adjoin R s) := fun x hx => Algebra.adjoin_induction hx h (fun r => (D1.map_algebraMap r).trans (D2.map_algebraMap r).symm) (fun x y hx hy => by simp only [map_add, *]) fun x y hx hy => by simp only [leibniz, *] /-- If adjoin of a set is the whole algebra, then any two derivations equal on this set are equal on the whole algebra. -/ theorem ext_of_adjoin_eq_top (s : Set A) (hs : adjoin R s = ⊤) (h : Set.EqOn D1 D2 s) : D1 = D2 := ext fun _ => eqOn_adjoin h <| hs.symm ▸ trivial -- Data typeclasses instance : Zero (Derivation R A M) := ⟨{ toLinearMap := 0 map_one_eq_zero' := rfl leibniz' := fun a b => by simp only [add_zero, LinearMap.zero_apply, smul_zero] }⟩ @[simp] theorem coe_zero : ⇑(0 : Derivation R A M) = 0 := rfl @[simp] theorem coe_zero_linearMap : ↑(0 : Derivation R A M) = (0 : A →ₗ[R] M) := rfl theorem zero_apply (a : A) : (0 : Derivation R A M) a = 0 := rfl instance : Add (Derivation R A M) := ⟨fun D1 D2 => { toLinearMap := D1 + D2 map_one_eq_zero' := by simp leibniz' := fun a b => by simp only [leibniz, LinearMap.add_apply, coeFn_coe, smul_add, add_add_add_comm] }⟩ @[simp] theorem coe_add (D1 D2 : Derivation R A M) : ⇑(D1 + D2) = D1 + D2 := rfl @[simp] theorem coe_add_linearMap (D1 D2 : Derivation R A M) : ↑(D1 + D2) = (D1 + D2 : A →ₗ[R] M) := rfl theorem add_apply : (D1 + D2) a = D1 a + D2 a := rfl instance : Inhabited (Derivation R A M) := ⟨0⟩ section Scalar variable {S T : Type*} variable [Monoid S] [DistribMulAction S M] [SMulCommClass R S M] [SMulCommClass S A M] variable [Monoid T] [DistribMulAction T M] [SMulCommClass R T M] [SMulCommClass T A M] instance : SMul S (Derivation R A M) := ⟨fun r D => { toLinearMap := r • D.1 map_one_eq_zero' := by rw [LinearMap.smul_apply, coeFn_coe, D.map_one_eq_zero, smul_zero] leibniz' := fun a b => by simp only [LinearMap.smul_apply, coeFn_coe, leibniz, smul_add, smul_comm r (_ : A) (_ : M)] }⟩ @[simp] theorem coe_smul (r : S) (D : Derivation R A M) : ⇑(r • D) = r • ⇑D := rfl @[simp] theorem coe_smul_linearMap (r : S) (D : Derivation R A M) : ↑(r • D) = r • (D : A →ₗ[R] M) := rfl theorem smul_apply (r : S) (D : Derivation R A M) : (r • D) a = r • D a := rfl instance : AddCommMonoid (Derivation R A M) := coe_injective.addCommMonoid _ coe_zero coe_add fun _ _ => rfl /-- `coe_fn` as an `AddMonoidHom`. -/ def coeFnAddMonoidHom : Derivation R A M →+ A → M where toFun := (↑) map_zero' := coe_zero map_add' := coe_add instance : DistribMulAction S (Derivation R A M) := Function.Injective.distribMulAction coeFnAddMonoidHom coe_injective coe_smul instance [DistribMulAction Sᵐᵒᵖ M] [IsCentralScalar S M] : IsCentralScalar S (Derivation R A M) where op_smul_eq_smul _ _ := ext fun _ => op_smul_eq_smul _ _ instance [SMul S T] [IsScalarTower S T M] : IsScalarTower S T (Derivation R A M) := ⟨fun _ _ _ => ext fun _ => smul_assoc _ _ _⟩ instance [SMulCommClass S T M] : SMulCommClass S T (Derivation R A M) := ⟨fun _ _ _ => ext fun _ => smul_comm _ _ _⟩ end Scalar instance instModule {S : Type*} [Semiring S] [Module S M] [SMulCommClass R S M] [SMulCommClass S A M] : Module S (Derivation R A M) := Function.Injective.module S coeFnAddMonoidHom coe_injective coe_smul section PushForward variable {N : Type*} [AddCommMonoid N] [Module A N] [Module R N] [IsScalarTower R A M] [IsScalarTower R A N] variable (f : M →ₗ[A] N) (e : M ≃ₗ[A] N) /-- We can push forward derivations using linear maps, i.e., the composition of a derivation with a linear map is a derivation. Furthermore, this operation is linear on the spaces of derivations. -/ def _root_.LinearMap.compDer : Derivation R A M →ₗ[R] Derivation R A N where toFun D := { toLinearMap := (f : M →ₗ[R] N).comp (D : A →ₗ[R] M) map_one_eq_zero' := by simp only [LinearMap.comp_apply, coeFn_coe, map_one_eq_zero, map_zero] leibniz' := fun a b => by simp only [coeFn_coe, LinearMap.comp_apply, LinearMap.map_add, leibniz, LinearMap.coe_restrictScalars, LinearMap.map_smul] } map_add' D₁ D₂ := by ext; exact LinearMap.map_add _ _ _ map_smul' r D := by dsimp; ext; exact LinearMap.map_smul (f : M →ₗ[R] N) _ _ @[simp] theorem coe_to_linearMap_comp : (f.compDer D : A →ₗ[R] N) = (f : M →ₗ[R] N).comp (D : A →ₗ[R] M) := rfl @[simp] theorem coe_comp : (f.compDer D : A → N) = (f : M →ₗ[R] N).comp (D : A →ₗ[R] M) := rfl /-- The composition of a derivation with a linear map as a bilinear map -/ @[simps] def llcomp : (M →ₗ[A] N) →ₗ[A] Derivation R A M →ₗ[R] Derivation R A N where toFun f := f.compDer map_add' f₁ f₂ := by ext; rfl map_smul' r D := by ext; rfl /-- Pushing a derivation forward through a linear equivalence is an equivalence. -/ def _root_.LinearEquiv.compDer : Derivation R A M ≃ₗ[R] Derivation R A N := { e.toLinearMap.compDer with invFun := e.symm.toLinearMap.compDer left_inv := fun D => by ext a; exact e.symm_apply_apply (D a) right_inv := fun D => by ext a; exact e.apply_symm_apply (D a) } @[simp] theorem linearEquiv_coe_to_linearMap_comp : (e.compDer D : A →ₗ[R] N) = (e.toLinearMap : M →ₗ[R] N).comp (D : A →ₗ[R] M) := rfl @[simp] theorem linearEquiv_coe_comp : (e.compDer D : A → N) = (e.toLinearMap : M →ₗ[R] N).comp (D : A →ₗ[R] M) := rfl end PushForward variable (A) in /-- For a tower `R → A → B` and an `R`-derivation `B → M`, we may compose with `A → B` to obtain an `R`-derivation `A → M`. -/ @[simps!] def compAlgebraMap [Algebra A B] [IsScalarTower R A B] [IsScalarTower A B M] (d : Derivation R B M) : Derivation R A M where map_one_eq_zero' := by simp leibniz' a b := by simp toLinearMap := d.toLinearMap.comp (IsScalarTower.toAlgHom R A B).toLinearMap section RestrictScalars variable {S : Type*} [CommSemiring S] variable [Algebra S A] [Module S M] [LinearMap.CompatibleSMul A M R S] variable (R) /-- If `A` is both an `R`-algebra and an `S`-algebra; `M` is both an `R`-module and an `S`-module, then an `S`-derivation `A → M` is also an `R`-derivation if it is also `R`-linear. -/ protected def restrictScalars (d : Derivation S A M) : Derivation R A M where map_one_eq_zero' := d.map_one_eq_zero leibniz' := d.leibniz toLinearMap := d.toLinearMap.restrictScalars R lemma coe_restrictScalars (d : Derivation S A M) : ⇑(d.restrictScalars R) = ⇑d := rfl @[simp] lemma restrictScalars_apply (d : Derivation S A M) (x : A) : d.restrictScalars R x = d x := rfl end RestrictScalars end section Cancel variable {R : Type*} [CommSemiring R] {A : Type*} [CommSemiring A] [Algebra R A] {M : Type*} [AddCancelCommMonoid M] [Module R M] [Module A M] /-- Define `Derivation R A M` from a linear map when `M` is cancellative by verifying the Leibniz rule. -/ def mk' (D : A →ₗ[R] M) (h : ∀ a b, D (a * b) = a • D b + b • D a) : Derivation R A M where toLinearMap := D map_one_eq_zero' := add_right_eq_self.1 <| by simpa only [one_smul, one_mul] using (h 1 1).symm leibniz' := h @[simp] theorem coe_mk' (D : A →ₗ[R] M) (h) : ⇑(mk' D h) = D := rfl @[simp] theorem coe_mk'_linearMap (D : A →ₗ[R] M) (h) : (mk' D h : A →ₗ[R] M) = D := rfl end Cancel section variable {R : Type*} [CommRing R] variable {A : Type*} [CommRing A] [Algebra R A] section variable {M : Type*} [AddCommGroup M] [Module A M] [Module R M] variable (D : Derivation R A M) {D1 D2 : Derivation R A M} (r : R) (a b : A) protected theorem map_neg : D (-a) = -D a := map_neg D a protected theorem map_sub : D (a - b) = D a - D b := map_sub D a b @[simp] theorem map_intCast (n : ℤ) : D (n : A) = 0 := by rw [← zsmul_one, D.map_smul_of_tower n, map_one_eq_zero, smul_zero] @[deprecated (since := "2024-04-05")] alias map_coe_nat := map_natCast @[deprecated (since := "2024-04-05")] alias map_coe_int := map_intCast theorem leibniz_of_mul_eq_one {a b : A} (h : a * b = 1) : D a = -a ^ 2 • D b := by rw [neg_smul] refine eq_neg_of_add_eq_zero_left ?_ calc D a + a ^ 2 • D b = a • b • D a + a • a • D b := by simp only [smul_smul, h, one_smul, sq] _ = a • D (a * b) := by rw [leibniz, smul_add, add_comm] _ = 0 := by rw [h, map_one_eq_zero, smul_zero] theorem leibniz_invOf [Invertible a] : D (⅟ a) = -⅟ a ^ 2 • D a := D.leibniz_of_mul_eq_one <| invOf_mul_self a section Field variable {K : Type*} [Field K] [Module K M] [Algebra R K] (D : Derivation R K M) theorem leibniz_inv (a : K) : D a⁻¹ = -a⁻¹ ^ 2 • D a := by rcases eq_or_ne a 0 with (rfl | ha) · simp · exact D.leibniz_of_mul_eq_one (inv_mul_cancel ha) theorem leibniz_div (a b : K) : D (a / b) = b⁻¹ ^ 2 • (b • D a - a • D b) := by simp only [div_eq_mul_inv, leibniz, leibniz_inv, inv_pow, neg_smul, smul_neg, smul_smul, add_comm, sub_eq_add_neg, smul_add] rw [← inv_mul_mul_self b⁻¹, inv_inv] ring_nf theorem leibniz_div_const (a b : K) (h : D b = 0) : D (a / b) = b⁻¹ • D a := by simp only [leibniz_div, inv_pow, h, smul_zero, sub_zero, smul_smul] rw [← mul_self_mul_inv b⁻¹, inv_inv] ring_nf lemma leibniz_zpow (a : K) (n : ℤ) : D (a ^ n) = n • a ^ (n - 1) • D a := by by_cases hn : n = 0 · simp [hn] by_cases ha : a = 0 · simp [ha, zero_zpow n hn] rcases Int.natAbs_eq n with h | h · rw [h] simp only [zpow_natCast, leibniz_pow, natCast_zsmul] rw [← zpow_natCast] congr omega · rw [h, zpow_neg, zpow_natCast, leibniz_inv, leibniz_pow, inv_pow, ← pow_mul, ← zpow_natCast, ← zpow_natCast, ← Nat.cast_smul_eq_nsmul K, ← Int.cast_smul_eq_zsmul K, smul_smul, smul_smul, smul_smul] trans (-n.natAbs * (a ^ ((n.natAbs - 1 : ℕ) : ℤ) / (a ^ ((n.natAbs * 2 : ℕ) : ℤ)))) • D a · ring_nf rw [← zpow_sub₀ ha] congr 3 · norm_cast omega end Field instance : Neg (Derivation R A M) := ⟨fun D => mk' (-D) fun a b => by simp only [LinearMap.neg_apply, smul_neg, neg_add_rev, leibniz, coeFn_coe, add_comm]⟩ @[simp] theorem coe_neg (D : Derivation R A M) : ⇑(-D) = -D := rfl @[simp] theorem coe_neg_linearMap (D : Derivation R A M) : ↑(-D) = (-D : A →ₗ[R] M) := rfl theorem neg_apply : (-D) a = -D a := rfl instance : Sub (Derivation R A M) := ⟨fun D1 D2 => mk' (D1 - D2 : A →ₗ[R] M) fun a b => by simp only [LinearMap.sub_apply, leibniz, coeFn_coe, smul_sub, add_sub_add_comm]⟩ @[simp] theorem coe_sub (D1 D2 : Derivation R A M) : ⇑(D1 - D2) = D1 - D2 := rfl @[simp] theorem coe_sub_linearMap (D1 D2 : Derivation R A M) : ↑(D1 - D2) = (D1 - D2 : A →ₗ[R] M) := rfl theorem sub_apply : (D1 - D2) a = D1 a - D2 a := rfl instance : AddCommGroup (Derivation R A M) := coe_injective.addCommGroup _ coe_zero coe_add coe_neg coe_sub (fun _ _ => rfl) fun _ _ => rfl end end end Derivation
RingTheory\Derivation\Lie.lean
/- Copyright (c) 2020 Nicolò Cavalleri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nicolò Cavalleri, Andrew Yang -/ import Mathlib.Algebra.Lie.OfAssociative import Mathlib.RingTheory.Derivation.Basic /-! # Results - `Derivation.instLieAlgebra`: The `R`-derivations from `A` to `A` form a Lie algebra over `R`. -/ namespace Derivation variable {R : Type*} [CommRing R] variable {A : Type*} [CommRing A] [Algebra R A] variable (D : Derivation R A A) {D1 D2 : Derivation R A A} (a : A) section LieStructures /-! # Lie structures -/ /-- The commutator of derivations is again a derivation. -/ instance : Bracket (Derivation R A A) (Derivation R A A) := ⟨fun D1 D2 => mk' ⁅(D1 : Module.End R A), (D2 : Module.End R A)⁆ fun a b => by simp only [Ring.lie_def, map_add, Algebra.id.smul_eq_mul, LinearMap.mul_apply, leibniz, coeFn_coe, LinearMap.sub_apply] ring⟩ @[simp] theorem commutator_coe_linear_map : ↑⁅D1, D2⁆ = ⁅(D1 : Module.End R A), (D2 : Module.End R A)⁆ := rfl theorem commutator_apply : ⁅D1, D2⁆ a = D1 (D2 a) - D2 (D1 a) := rfl instance : LieRing (Derivation R A A) where add_lie d e f := by ext a; simp only [commutator_apply, add_apply, map_add]; ring lie_add d e f := by ext a; simp only [commutator_apply, add_apply, map_add]; ring lie_self d := by ext a; simp only [commutator_apply, add_apply, map_add]; ring_nf; simp leibniz_lie d e f := by ext a; simp only [commutator_apply, add_apply, sub_apply, map_sub]; ring instance instLieAlgebra : LieAlgebra R (Derivation R A A) := { Derivation.instModule with lie_smul := fun r d e => by ext a; simp only [commutator_apply, map_smul, smul_sub, smul_apply] } end LieStructures end Derivation
RingTheory\Derivation\ToSquareZero.lean
/- Copyright (c) 2020 Nicolò Cavalleri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nicolò Cavalleri, Andrew Yang -/ import Mathlib.RingTheory.Derivation.Basic import Mathlib.RingTheory.Ideal.QuotientOperations /-! # Results - `derivationToSquareZeroOfLift`: The `R`-derivations from `A` into a square-zero ideal `I` of `B` corresponds to the lifts `A →ₐ[R] B` of the map `A →ₐ[R] B ⧸ I`. -/ section ToSquareZero universe u v w variable {R : Type u} {A : Type v} {B : Type w} [CommSemiring R] [CommSemiring A] [CommRing B] variable [Algebra R A] [Algebra R B] (I : Ideal B) (hI : I ^ 2 = ⊥) /-- If `f₁ f₂ : A →ₐ[R] B` are two lifts of the same `A →ₐ[R] B ⧸ I`, we may define a map `f₁ - f₂ : A →ₗ[R] I`. -/ def diffToIdealOfQuotientCompEq (f₁ f₂ : A →ₐ[R] B) (e : (Ideal.Quotient.mkₐ R I).comp f₁ = (Ideal.Quotient.mkₐ R I).comp f₂) : A →ₗ[R] I := LinearMap.codRestrict (I.restrictScalars _) (f₁.toLinearMap - f₂.toLinearMap) (by intro x change f₁ x - f₂ x ∈ I rw [← Ideal.Quotient.eq, ← Ideal.Quotient.mkₐ_eq_mk R, ← AlgHom.comp_apply, e] rfl) @[simp] theorem diffToIdealOfQuotientCompEq_apply (f₁ f₂ : A →ₐ[R] B) (e : (Ideal.Quotient.mkₐ R I).comp f₁ = (Ideal.Quotient.mkₐ R I).comp f₂) (x : A) : ((diffToIdealOfQuotientCompEq I f₁ f₂ e) x : B) = f₁ x - f₂ x := rfl variable [Algebra A B] /-- Given a tower of algebras `R → A → B`, and a square-zero `I : Ideal B`, each lift `A →ₐ[R] B` of the canonical map `A →ₐ[R] B ⧸ I` corresponds to an `R`-derivation from `A` to `I`. -/ def derivationToSquareZeroOfLift [IsScalarTower R A B] (f : A →ₐ[R] B) (e : (Ideal.Quotient.mkₐ R I).comp f = IsScalarTower.toAlgHom R A (B ⧸ I)) : Derivation R A I := by refine { diffToIdealOfQuotientCompEq I f (IsScalarTower.toAlgHom R A B) ?_ with map_one_eq_zero' := ?_ leibniz' := ?_ } · rw [e]; ext; rfl · ext; change f 1 - algebraMap A B 1 = 0; rw [map_one, map_one, sub_self] · intro x y let F := diffToIdealOfQuotientCompEq I f (IsScalarTower.toAlgHom R A B) (by rw [e]; ext; rfl) have : (f x - algebraMap A B x) * (f y - algebraMap A B y) = 0 := by rw [← Ideal.mem_bot, ← hI, pow_two] convert Ideal.mul_mem_mul (F x).2 (F y).2 using 1 ext dsimp only [Submodule.coe_add, Submodule.coe_mk, LinearMap.coe_mk, diffToIdealOfQuotientCompEq_apply, Submodule.coe_smul_of_tower, IsScalarTower.coe_toAlgHom', LinearMap.toFun_eq_coe] simp only [map_mul, sub_mul, mul_sub, Algebra.smul_def] at this ⊢ rw [sub_eq_iff_eq_add, sub_eq_iff_eq_add] at this simp only [LinearMap.coe_toAddHom, diffToIdealOfQuotientCompEq_apply, map_mul, this, IsScalarTower.coe_toAlgHom'] ring theorem derivationToSquareZeroOfLift_apply [IsScalarTower R A B] (f : A →ₐ[R] B) (e : (Ideal.Quotient.mkₐ R I).comp f = IsScalarTower.toAlgHom R A (B ⧸ I)) (x : A) : (derivationToSquareZeroOfLift I hI f e x : B) = f x - algebraMap A B x := rfl /-- Given a tower of algebras `R → A → B`, and a square-zero `I : Ideal B`, each `R`-derivation from `A` to `I` corresponds to a lift `A →ₐ[R] B` of the canonical map `A →ₐ[R] B ⧸ I`. -/ @[simps (config := .lemmasOnly)] def liftOfDerivationToSquareZero [IsScalarTower R A B] (f : Derivation R A I) : A →ₐ[R] B := { ((I.restrictScalars R).subtype.comp f.toLinearMap + (IsScalarTower.toAlgHom R A B).toLinearMap : A →ₗ[R] B) with toFun := fun x => f x + algebraMap A B x map_one' := by dsimp -- Note: added the `(algebraMap _ _)` hint because otherwise it would match `f 1` rw [map_one (algebraMap _ _), f.map_one_eq_zero, Submodule.coe_zero, zero_add] map_mul' := fun x y => by have : (f x : B) * f y = 0 := by rw [← Ideal.mem_bot, ← hI, pow_two] convert Ideal.mul_mem_mul (f x).2 (f y).2 using 1 simp only [map_mul, f.leibniz, add_mul, mul_add, Submodule.coe_add, Submodule.coe_smul_of_tower, Algebra.smul_def, this] ring commutes' := fun r => by simp only [Derivation.map_algebraMap, eq_self_iff_true, zero_add, Submodule.coe_zero, ← IsScalarTower.algebraMap_apply R A B r] map_zero' := ((I.restrictScalars R).subtype.comp f.toLinearMap + (IsScalarTower.toAlgHom R A B).toLinearMap).map_zero } -- @[simp] -- Porting note: simp normal form is `liftOfDerivationToSquareZero_mk_apply'` theorem liftOfDerivationToSquareZero_mk_apply [IsScalarTower R A B] (d : Derivation R A I) (x : A) : Ideal.Quotient.mk I (liftOfDerivationToSquareZero I hI d x) = algebraMap A (B ⧸ I) x := by rw [liftOfDerivationToSquareZero_apply, map_add, Ideal.Quotient.eq_zero_iff_mem.mpr (d x).prop, zero_add] rfl @[simp] theorem liftOfDerivationToSquareZero_mk_apply' (d : Derivation R A I) (x : A) : (Ideal.Quotient.mk I) (d x) + (algebraMap A (B ⧸ I)) x = algebraMap A (B ⧸ I) x := by simp only [Ideal.Quotient.eq_zero_iff_mem.mpr (d x).prop, zero_add] /-- Given a tower of algebras `R → A → B`, and a square-zero `I : Ideal B`, there is a 1-1 correspondence between `R`-derivations from `A` to `I` and lifts `A →ₐ[R] B` of the canonical map `A →ₐ[R] B ⧸ I`. -/ @[simps!] def derivationToSquareZeroEquivLift [IsScalarTower R A B] : Derivation R A I ≃ { f : A →ₐ[R] B // (Ideal.Quotient.mkₐ R I).comp f = IsScalarTower.toAlgHom R A (B ⧸ I) } := by refine ⟨fun d => ⟨liftOfDerivationToSquareZero I hI d, ?_⟩, fun f => (derivationToSquareZeroOfLift I hI f.1 f.2 : _), ?_, ?_⟩ · ext x; exact liftOfDerivationToSquareZero_mk_apply I hI d x · intro d; ext x; exact add_sub_cancel_right (d x : B) (algebraMap A B x) · rintro ⟨f, hf⟩; ext x; exact sub_add_cancel (f x) (algebraMap A B x) end ToSquareZero
RingTheory\DiscreteValuationRing\Basic.lean
/- Copyright (c) 2020 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard -/ import Mathlib.RingTheory.PrincipalIdealDomain import Mathlib.RingTheory.Valuation.PrimeMultiplicity import Mathlib.RingTheory.AdicCompletion.Basic import Mathlib.RingTheory.LocalRing.MaximalIdeal.Basic /-! # 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. * `DiscreteValuationRing R` : a predicate expressing that R is a DVR. ### Definitions * `addVal R : AddValuation R PartENat` : the additive valuation on a DVR. ## 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 LocalRing /-- An integral domain is a *discrete valuation ring* (DVR) if it's a local PID which is not a field. -/ class DiscreteValuationRing (R : Type u) [CommRing R] [IsDomain R] extends IsPrincipalIdealRing R, LocalRing R : Prop where not_a_field' : maximalIdeal R ≠ ⊥ namespace DiscreteValuationRing variable (R : Type u) [CommRing R] [IsDomain R] [DiscreteValuationRing R] theorem not_a_field : maximalIdeal R ≠ ⊥ := not_a_field' /-- A discrete valuation ring `R` is not a field. -/ theorem not_isField : ¬IsField R := LocalRing.isField_iff_maximalIdeal_eq.not.mpr (not_a_field R) variable {R} open PrincipalIdealRing theorem irreducible_of_span_eq_maximalIdeal {R : Type*} [CommRing R] [LocalRing 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] : DiscreteValuationRing R ↔ IsPrincipalIdealRing R ∧ ∃! P : Ideal R, P ≠ ⊥ ∧ IsPrime P := by constructor · intro RDVR rcases id RDVR with ⟨Rlocal⟩ constructor · assumption use LocalRing.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 erw [span_singleton_prime hq] at hQ2 replace hQ2 := hQ2.irreducible rw [irreducible_iff_uniformizer] at hQ2 exact hQ2.symm · rintro ⟨RPID, Punique⟩ haveI : LocalRing R := LocalRing.of_unique_nonzero_prime Punique refine { not_a_field' := ?_ } rcases Punique with ⟨P, ⟨hP1, hP2⟩, _⟩ have hPM : P ≤ maximalIdeal R := le_maximalIdeal hP2.1 intro h rw [h, le_bot_iff] at hPM exact hP1 hPM 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] end DiscreteValuationRing namespace DiscreteValuationRing 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_unit H0).elim · rw [add_comm, pow_succ'] at H0 exact (hϖ.not_unit (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 `DiscreteValuationRing.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_unit, ?_⟩ intro a b h by_cases ha : a = 0 · rw [ha] simp only [true_or_iff, 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 cases' WfDvdMonoid.exists_factors x hx with fx hfx 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_iff, and_imp, Multiset.card_map, eq_self_iff_true, 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 show 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 · erw [Submodule.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) : DiscreteValuationRing 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 erw [Ne, 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) : DiscreteValuationRing R := by letI : UniqueFactorizationMonoid R := hR.toUniqueFactorizationMonoid apply of_ufd_of_unique_irreducible _ hR.unique_irreducible obtain ⟨p, hp, H⟩ := hR exact ⟨p, hp⟩ section variable [CommRing R] [IsDomain R] [DiscreteValuationRing 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 cases' WfDvdMonoid.exists_factors x hx with fx hfx 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_iff, and_imp, Multiset.card_map, eq_self_iff_true, 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 cases' h with h h · rw [sub_eq_zero] at h exact mod_cast h · apply (hirr.ne_zero (pow_eq_zero h)).elim /-! ## The additive valuation on a DVR -/ open multiplicity open Classical in /-- The `PartENat`-valued additive valuation on a DVR. -/ noncomputable def addVal (R : Type u) [CommRing R] [IsDomain R] [DiscreteValuationRing R] : AddValuation R PartENat := 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, addValuation_apply, hr, eq_of_associated_left (associated_of_irreducible R hϖ (Classical.choose_spec (exists_prime R)).irreducible), eq_of_associated_right (Associated.symm ⟨u, mul_comm _ _⟩), multiplicity_pow_self_of_prime (irreducible_iff_prime.1 hϖ)] theorem addVal_def' (u : Rˣ) {ϖ : R} (hϖ : Irreducible ϖ) (n : ℕ) : addVal R ((u : R) * ϖ ^ n) = n := addVal_def _ u hϖ n rfl --@[simp] Porting note (#10618): simp can prove it theorem addVal_zero : addVal R 0 = ⊤ := (addVal R).map_zero --@[simp] Porting note (#10618): simp can prove it 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 --@[simp] Porting note (#10618): simp can prove it 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] exact PartENat.natCast_ne_top _ · 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, addValuation_apply, addValuation_apply, multiplicity_le_multiplicity_iff] at h exact ha.dvd.trans (h n ha.symm.dvd) · rw [addVal, addValuation_apply, addValuation_apply] exact multiplicity_le_multiplicity_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 _ _ end instance (R : Type*) [CommRing R] [IsDomain R] [DiscreteValuationRing 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, PartENat.eq_top_iff_forall_le] end DiscreteValuationRing
RingTheory\DiscreteValuationRing\TFAE.lean
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.RingTheory.Ideal.Cotangent import Mathlib.RingTheory.DedekindDomain.Basic import Mathlib.RingTheory.Valuation.ValuationRing import Mathlib.RingTheory.Nakayama /-! # Equivalent conditions for DVR In `DiscreteValuationRing.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_localRing_of_isDomain` for a version without `¬ IsField R`. -/ variable (R : Type*) [CommRing R] (K : Type*) [Field K] [Algebra R K] [IsFractionRing R K] open scoped DiscreteValuation open LocalRing FiniteDimensional theorem exists_maximalIdeal_pow_eq_of_principal [IsNoetherianRing R] [LocalRing R] [IsDomain R] (h' : (maximalIdeal R).IsPrincipal) (I : Ideal R) (hI : I ≠ ⊥) : ∃ n : ℕ, I = maximalIdeal R ^ n := by by_cases h : IsField R · exact ⟨0, by simp [letI := h.toField; (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' := DiscreteValuationRing.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 fa fs fh · exact (hf₂ rfl).elim 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 [LocalRing 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 _ cases' 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 by_contra h; apply hx 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 `DiscreteValuationRing.TFAE` for a version assuming `¬ IsField R`. -/ theorem tfae_of_isNoetherianRing_of_localRing_of_isDomain [IsNoetherianRing R] [LocalRing 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) (_ : I ≠ ⊥), ∃ n : ℕ, I = maximalIdeal R ^ n] := by tfae_have 1 → 2 · exact fun _ ↦ inferInstance tfae_have 2 → 1 · exact fun _ ↦ ((IsBezout.TFAE (R := R)).out 0 1).mp ‹_› tfae_have 1 → 4 · intro H exact ⟨inferInstance, fun P hP hP' ↦ eq_maximalIdeal (hP'.isMaximal hP)⟩ tfae_have 4 → 3 · exact fun ⟨h₁, h₂⟩ ↦ { h₁ with maximalOfPrime := (h₂ _ · · ▸ maximalIdeal.isMaximal R) } tfae_have 3 → 5 · exact fun h ↦ maximalIdeal_isPrincipal_of_isDedekindDomain R tfae_have 6 ↔ 5 · exact finrank_cotangentSpace_le_one_iff tfae_have 5 → 7 · exact exists_maximalIdeal_pow_eq_of_principal R tfae_have 7 → 2 · rw [ValuationRing.iff_ideal_total] intro H constructor intro I J -- `by_cases` should invoke `classical` by itself if it can't find a `Decidable` instance, -- however the `tfae` hypotheses trigger a looping instance search. -- See also: -- https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/.60by_cases.60.20trying.20to.20find.20a.20weird.20instance -- As a workaround, add the desired instance ourselves. let _ := Classical.decEq (Ideal R) by_cases hI : I = ⊥; · subst hI; left; exact bot_le by_cases hJ : J = ⊥; · subst hJ; right; exact bot_le 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_localRing_of_isDomain` for a version without `¬ IsField R`. -/ theorem DiscreteValuationRing.TFAE [IsNoetherianRing R] [LocalRing R] [IsDomain R] (h : ¬IsField R) : List.TFAE [DiscreteValuationRing 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_localRing_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 LocalRing.finrank_CotangentSpace_eq_one_iff [IsNoetherianRing R] [LocalRing R] [IsDomain R] : finrank (ResidueField R) (CotangentSpace R) = 1 ↔ DiscreteValuationRing 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 (DiscreteValuationRing.TFAE R hR).out 5 0 variable (R) lemma LocalRing.finrank_CotangentSpace_eq_one [IsDomain R] [DiscreteValuationRing R] : finrank (ResidueField R) (CotangentSpace R) = 1 := finrank_CotangentSpace_eq_one_iff.mpr ‹_› instance (priority := 100) IsDedekindDomain.isPrincipalIdealRing [LocalRing R] [IsDedekindDomain R] : IsPrincipalIdealRing R := ((tfae_of_isNoetherianRing_of_localRing_of_isDomain R).out 2 0).mp ‹_›
RingTheory\Etale\Basic.lean
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.RingTheory.QuotientNilpotent import Mathlib.RingTheory.Smooth.Basic import Mathlib.RingTheory.Unramified.Basic /-! # Etale morphisms An `R`-algebra `A` is formally étale if for every `R`-algebra, every square-zero ideal `I : Ideal B` and `f : A →ₐ[R] B ⧸ I`, there exists exactly one lift `A →ₐ[R] B`. It is étale if it is formally étale and of finite presentation. We show that the property extends onto nilpotent ideals, and that these properties are stable under `R`-algebra homomorphisms and compositions. We show that étale is stable under algebra isomorphisms, composition and localization at an element. -/ -- Porting note: added to make the syntax work below. open scoped TensorProduct universe u namespace Algebra section variable (R : Type u) [CommSemiring R] variable (A : Type u) [Semiring A] [Algebra R A] /-- An `R` algebra `A` is formally étale if for every `R`-algebra, every square-zero ideal `I : Ideal B` and `f : A →ₐ[R] B ⧸ I`, there exists exactly one lift `A →ₐ[R] B`. See <https://stacks.math.columbia.edu/tag/00UQ> -/ @[mk_iff] class FormallyEtale : Prop where comp_bijective : ∀ ⦃B : Type u⦄ [CommRing B], ∀ [Algebra R B] (I : Ideal B) (_ : I ^ 2 = ⊥), Function.Bijective ((Ideal.Quotient.mkₐ R I).comp : (A →ₐ[R] B) → A →ₐ[R] B ⧸ I) end namespace FormallyEtale section variable {R : Type u} [CommSemiring R] variable {A : Type u} [Semiring A] [Algebra R A] variable {B : Type u} [CommRing B] [Algebra R B] (I : Ideal B) theorem iff_unramified_and_smooth : FormallyEtale R A ↔ FormallyUnramified R A ∧ FormallySmooth R A := by rw [formallyUnramified_iff, formallySmooth_iff, formallyEtale_iff] simp_rw [← forall_and, Function.Bijective] instance (priority := 100) to_unramified [h : FormallyEtale R A] : FormallyUnramified R A := (FormallyEtale.iff_unramified_and_smooth.mp h).1 instance (priority := 100) to_smooth [h : FormallyEtale R A] : FormallySmooth R A := (FormallyEtale.iff_unramified_and_smooth.mp h).2 theorem of_unramified_and_smooth [h₁ : FormallyUnramified R A] [h₂ : FormallySmooth R A] : FormallyEtale R A := FormallyEtale.iff_unramified_and_smooth.mpr ⟨h₁, h₂⟩ end section OfEquiv variable {R : Type u} [CommSemiring R] variable {A B : Type u} [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] theorem of_equiv [FormallyEtale R A] (e : A ≃ₐ[R] B) : FormallyEtale R B := FormallyEtale.iff_unramified_and_smooth.mpr ⟨FormallyUnramified.of_equiv e, FormallySmooth.of_equiv e⟩ end OfEquiv section Comp variable (R : Type u) [CommSemiring R] variable (A : Type u) [CommSemiring A] [Algebra R A] variable (B : Type u) [Semiring B] [Algebra R B] [Algebra A B] [IsScalarTower R A B] theorem comp [FormallyEtale R A] [FormallyEtale A B] : FormallyEtale R B := FormallyEtale.iff_unramified_and_smooth.mpr ⟨FormallyUnramified.comp R A B, FormallySmooth.comp R A B⟩ end Comp section BaseChange open scoped TensorProduct variable {R : Type u} [CommSemiring R] variable {A : Type u} [Semiring A] [Algebra R A] variable (B : Type u) [CommSemiring B] [Algebra R B] instance base_change [FormallyEtale R A] : FormallyEtale B (B ⊗[R] A) := FormallyEtale.iff_unramified_and_smooth.mpr ⟨inferInstance, inferInstance⟩ end BaseChange section Localization /-! We now consider a commutative square of commutative rings ``` R -----> S | | | | v v Rₘ ----> Sₘ ``` where `Rₘ` and `Sₘ` are the localisations of `R` and `S` at a multiplicatively closed subset `M` of `R`. -/ /-! Let R, S, Rₘ, Sₘ be commutative rings -/ variable {R S Rₘ Sₘ : Type u} [CommRing R] [CommRing S] [CommRing Rₘ] [CommRing Sₘ] /-! Let M be a multiplicatively closed subset of `R` -/ variable (M : Submonoid R) /-! Assume that the rings are in a commutative diagram as above. -/ variable [Algebra R S] [Algebra R Sₘ] [Algebra S Sₘ] [Algebra R Rₘ] [Algebra Rₘ Sₘ] variable [IsScalarTower R Rₘ Sₘ] [IsScalarTower R S Sₘ] /-! and that Rₘ and Sₘ are localizations of R and S at M. -/ variable [IsLocalization M Rₘ] [IsLocalization (M.map (algebraMap R S)) Sₘ] -- Porting note: no longer supported -- attribute [local elab_as_elim] Ideal.IsNilpotent.induction_on theorem of_isLocalization : FormallyEtale R Rₘ := FormallyEtale.iff_unramified_and_smooth.mpr ⟨FormallyUnramified.of_isLocalization M, FormallySmooth.of_isLocalization M⟩ theorem localization_base [FormallyEtale R Sₘ] : FormallyEtale Rₘ Sₘ := FormallyEtale.iff_unramified_and_smooth.mpr ⟨FormallyUnramified.localization_base M, FormallySmooth.localization_base M⟩ /-- The localization of a formally étale map is formally étale. -/ theorem localization_map [FormallyEtale R S] : FormallyEtale Rₘ Sₘ := by haveI : FormallyEtale S Sₘ := FormallyEtale.of_isLocalization (M.map (algebraMap R S)) haveI : FormallyEtale R Sₘ := FormallyEtale.comp R S Sₘ exact FormallyEtale.localization_base M end Localization end FormallyEtale section variable (R : Type u) [CommSemiring R] variable (A : Type u) [Semiring A] [Algebra R A] /-- An `R`-algebra `A` is étale if it is formally étale and of finite presentation. Note that the definition <https://stacks.math.columbia.edu/tag/00U1> in the stacks project is different, but <https://stacks.math.columbia.edu/tag/00UR> shows that it is equivalent to the definition here. -/ class Etale : Prop where formallyEtale : FormallyEtale R A := by infer_instance finitePresentation : FinitePresentation R A := by infer_instance end namespace Etale attribute [instance] formallyEtale finitePresentation variable {R : Type u} [CommRing R] variable {A B : Type u} [CommRing A] [Algebra R A] [CommRing B] [Algebra R B] /-- Being étale is transported via algebra isomorphisms. -/ theorem of_equiv [Etale R A] (e : A ≃ₐ[R] B) : Etale R B where formallyEtale := FormallyEtale.of_equiv e finitePresentation := FinitePresentation.equiv e section Comp variable (R A B) /-- Etale is stable under composition. -/ theorem comp [Algebra A B] [IsScalarTower R A B] [Etale R A] [Etale A B] : Etale R B where formallyEtale := FormallyEtale.comp R A B finitePresentation := FinitePresentation.trans R A B /-- Etale is stable under base change. -/ instance baseChange [Etale R A] : Etale B (B ⊗[R] A) where end Comp /-- Localization at an element is étale. -/ theorem of_isLocalization_Away (r : R) [IsLocalization.Away r A] : Etale R A where formallyEtale := Algebra.FormallyEtale.of_isLocalization (Submonoid.powers r) finitePresentation := IsLocalization.Away.finitePresentation r end Etale end Algebra
RingTheory\Flat\Algebra.lean
/- Copyright (c) 2024 Christian Merten. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christian Merten -/ import Mathlib.RingTheory.Flat.Stability import Mathlib.LinearAlgebra.TensorProduct.Tower /-! # Flat algebras and flat ring homomorphisms We define flat algebras and flat ring homomorphisms. ## Main definitions * `Algebra.Flat`: an `R`-algebra `S` is flat if it is flat as `R`-module * `RingHom.Flat`: a ring homomorphism `f : R → S` is flat, if it makes `S` into a flat `R`-algebra -/ universe u v w t open Function (Injective Surjective) open LinearMap (lsmul rTensor lTensor) open TensorProduct /-- An `R`-algebra `S` is flat if it is flat as `R`-module. -/ class Algebra.Flat (R : Type u) (S : Type v) [CommRing R] [CommRing S] [Algebra R S] : Prop where out : Module.Flat R S namespace Algebra.Flat attribute [instance] out instance self (R : Type u) [CommRing R] : Algebra.Flat R R where out := Module.Flat.self R variable (R : Type u) (S : Type v) [CommRing R] [CommRing S] /-- If `T` is a flat `S`-algebra and `S` is a flat `R`-algebra, then `T` is a flat `R`-algebra. -/ theorem comp (T : Type w) [CommRing T] [Algebra R S] [Algebra R T] [Algebra S T] [IsScalarTower R S T] [Algebra.Flat R S] [Algebra.Flat S T] : Algebra.Flat R T where out := Module.Flat.comp R S T /-- If `S` is a flat `R`-algebra and `T` is any `R`-algebra, then `T ⊗[R] S` is a flat `T`-algebra. -/ instance baseChange (T : Type w) [CommRing T] [Algebra R S] [Algebra R T] [Algebra.Flat R S] : Algebra.Flat T (T ⊗[R] S) where out := Module.Flat.baseChange R T S /-- A base change of a flat algebra is flat. -/ theorem isBaseChange [Algebra R S] (R' : Type w) (S' : Type t) [CommRing R'] [CommRing S'] [Algebra R R'] [Algebra S S'] [Algebra R' S'] [Algebra R S'] [IsScalarTower R R' S'] [IsScalarTower R S S'] [h : IsPushout R S R' S'] [Algebra.Flat R R'] : Algebra.Flat S S' where out := Module.Flat.isBaseChange R S R' S' h.out end Algebra.Flat /-- A ring homomorphism `f : R →+* S` is flat if `S` is flat as an `R` algebra. -/ class RingHom.Flat {R : Type u} {S : Type v} [CommRing R] [CommRing S] (f : R →+* S) : Prop where out : f.toAlgebra.Flat := by infer_instance namespace RingHom.Flat attribute [instance] out /-- The identity of a ring is flat. -/ instance identity (R : Type u) [CommRing R] : RingHom.Flat (1 : R →+* R) where variable {R : Type u} {S : Type v} {T : Type w} [CommRing R] [CommRing S] [CommRing T] (f : R →+* S) (g : S →+* T) /-- Composition of flat ring homomorphisms is flat. -/ instance comp [RingHom.Flat f] [RingHom.Flat g] : RingHom.Flat (g.comp f) where out := letI : Algebra R S := f.toAlgebra letI : Algebra S T := g.toAlgebra letI : Algebra R T := (g.comp f).toAlgebra letI : IsScalarTower R S T := IsScalarTower.of_algebraMap_eq (congrFun rfl) Algebra.Flat.comp R S T end RingHom.Flat
RingTheory\Flat\Basic.lean
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Jujian Zhang -/ import Mathlib.RingTheory.Noetherian import Mathlib.Algebra.DirectSum.Module import Mathlib.Algebra.DirectSum.Finsupp import Mathlib.Algebra.Module.Projective import Mathlib.Algebra.Module.Injective import Mathlib.Algebra.Module.CharacterModule import Mathlib.LinearAlgebra.DirectSum.TensorProduct import Mathlib.LinearAlgebra.FreeModule.Basic import Mathlib.Algebra.Module.Projective import Mathlib.LinearAlgebra.TensorProduct.RightExactness import Mathlib.Algebra.Exact /-! # Flat modules A module `M` over a commutative ring `R` is *flat* if for all finitely generated ideals `I` of `R`, the canonical map `I ⊗ M →ₗ M` is injective. This is equivalent to the claim that for all injective `R`-linear maps `f : M₁ → M₂` the induced map `M₁ ⊗ M → M₂ ⊗ M` is injective. See <https://stacks.math.columbia.edu/tag/00HD>. ## Main declaration * `Module.Flat`: the predicate asserting that an `R`-module `M` is flat. ## Main theorems * `Module.Flat.of_retract`: retracts of flat modules are flat * `Module.Flat.of_linearEquiv`: modules linearly equivalent to a flat modules are flat * `Module.Flat.directSum`: arbitrary direct sums of flat modules are flat * `Module.Flat.of_free`: free modules are flat * `Module.Flat.of_projective`: projective modules are flat * `Module.Flat.preserves_injective_linearMap`: If `M` is a flat module then tensoring with `M` preserves injectivity of linear maps. This lemma is fully universally polymorphic in all arguments, i.e. `R`, `M` and linear maps `N → N'` can all have different universe levels. * `Module.Flat.iff_rTensor_preserves_injective_linearMap`: a module is flat iff tensoring preserves injectivity in the ring's universe (or higher). ## Implementation notes In `Module.Flat.iff_rTensor_preserves_injective_linearMap`, we require that the universe level of the ring is lower than or equal to that of the module. This requirement is to make sure ideals of the ring can be lifted to the universe of the module. It is unclear if this lemma also holds when the module lives in a lower universe. ## TODO * Generalize flatness to noncommutative rings. -/ universe u v w namespace Module open Function (Surjective) open LinearMap Submodule TensorProduct DirectSum variable (R : Type u) (M : Type v) [CommRing R] [AddCommGroup M] [Module R M] /-- An `R`-module `M` is flat if for all finitely generated ideals `I` of `R`, the canonical map `I ⊗ M →ₗ M` is injective. -/ @[mk_iff] class Flat : Prop where out : ∀ ⦃I : Ideal R⦄ (_ : I.FG), Function.Injective (TensorProduct.lift ((lsmul R M).comp I.subtype)) namespace Flat instance self (R : Type u) [CommRing R] : Flat R R := ⟨by intro I _ rw [← Equiv.injective_comp (TensorProduct.rid R I).symm.toEquiv] convert Subtype.coe_injective using 1 ext x simp only [Function.comp_apply, LinearEquiv.coe_toEquiv, rid_symm_apply, comp_apply, mul_one, lift.tmul, Submodule.subtype_apply, Algebra.id.smul_eq_mul, lsmul_apply]⟩ /-- An `R`-module `M` is flat iff for all finitely generated ideals `I` of `R`, the tensor product of the inclusion `I → R` and the identity `M → M` is injective. See `iff_rTensor_injective'` to extend to all ideals `I`. --/ lemma iff_rTensor_injective : Flat R M ↔ ∀ ⦃I : Ideal R⦄ (_ : I.FG), Function.Injective (rTensor M I.subtype) := by simp [flat_iff, ← lid_comp_rTensor] /-- An `R`-module `M` is flat iff for all ideals `I` of `R`, the tensor product of the inclusion `I → R` and the identity `M → M` is injective. See `iff_rTensor_injective` to restrict to finitely generated ideals `I`. --/ theorem iff_rTensor_injective' : Flat R M ↔ ∀ I : Ideal R, Function.Injective (rTensor M I.subtype) := by rewrite [Flat.iff_rTensor_injective] refine ⟨fun h I => ?_, fun h I _ => h I⟩ rewrite [injective_iff_map_eq_zero] intro x hx₀ obtain ⟨J, hfg, hle, y, rfl⟩ := Submodule.exists_fg_le_eq_rTensor_inclusion x rewrite [← rTensor_comp_apply] at hx₀ rw [(injective_iff_map_eq_zero _).mp (h hfg) y hx₀, LinearMap.map_zero] @[deprecated (since := "2024-03-29")] alias lTensor_inj_iff_rTensor_inj := LinearMap.lTensor_inj_iff_rTensor_inj /-- The `lTensor`-variant of `iff_rTensor_injective`. . -/ theorem iff_lTensor_injective : Module.Flat R M ↔ ∀ ⦃I : Ideal R⦄ (_ : I.FG), Function.Injective (lTensor M I.subtype) := by simpa [← comm_comp_rTensor_comp_comm_eq] using Module.Flat.iff_rTensor_injective R M /-- The `lTensor`-variant of `iff_rTensor_injective'`. . -/ theorem iff_lTensor_injective' : Module.Flat R M ↔ ∀ (I : Ideal R), Function.Injective (lTensor M I.subtype) := by simpa [← comm_comp_rTensor_comp_comm_eq] using Module.Flat.iff_rTensor_injective' R M variable (N : Type w) [AddCommGroup N] [Module R N] /-- A retract of a flat `R`-module is flat. -/ lemma of_retract [f : Flat R M] (i : N →ₗ[R] M) (r : M →ₗ[R] N) (h : r.comp i = LinearMap.id) : Flat R N := by rw [iff_rTensor_injective] at * intro I hI have h₁ : Function.Injective (lTensor R i) := by apply Function.RightInverse.injective (g := (lTensor R r)) intro x rw [← LinearMap.comp_apply, ← lTensor_comp, h] simp rw [← Function.Injective.of_comp_iff h₁ (rTensor N I.subtype), ← LinearMap.coe_comp] rw [LinearMap.lTensor_comp_rTensor, ← LinearMap.rTensor_comp_lTensor] rw [LinearMap.coe_comp, Function.Injective.of_comp_iff (f hI)] apply Function.RightInverse.injective (g := lTensor _ r) intro x rw [← LinearMap.comp_apply, ← lTensor_comp, h] simp /-- A `R`-module linearly equivalent to a flat `R`-module is flat. -/ lemma of_linearEquiv [f : Flat R M] (e : N ≃ₗ[R] M) : Flat R N := by have h : e.symm.toLinearMap.comp e.toLinearMap = LinearMap.id := by simp exact of_retract _ _ _ e.toLinearMap e.symm.toLinearMap h /-- A direct sum of flat `R`-modules is flat. -/ instance directSum (ι : Type v) (M : ι → Type w) [(i : ι) → AddCommGroup (M i)] [(i : ι) → Module R (M i)] [F : (i : ι) → (Flat R (M i))] : Flat R (⨁ i, M i) := by haveI := Classical.decEq ι rw [iff_rTensor_injective] intro I hI -- This instance was added during PR #10828, -- see https://leanprover.zulipchat.com/#narrow/stream/144837-PR-reviews/topic/.2310828.20-.20generalizing.20CommRing.20to.20CommSemiring.20etc.2E/near/422684923 letI : ∀ i, AddCommGroup (I ⊗[R] M i) := inferInstance rw [← Equiv.comp_injective _ (TensorProduct.lid R (⨁ i, M i)).toEquiv] set η₁ := TensorProduct.lid R (⨁ i, M i) set η := fun i ↦ TensorProduct.lid R (M i) set φ := fun i ↦ rTensor (M i) I.subtype set π := fun i ↦ component R ι (fun j ↦ M j) i set ψ := (TensorProduct.directSumRight R {x // x ∈ I} (fun i ↦ M i)).symm.toLinearMap with psi_def set ρ := rTensor (⨁ i, M i) I.subtype set τ := (fun i ↦ component R ι (fun j ↦ ({x // x ∈ I} ⊗[R] (M j))) i) rw [← Equiv.injective_comp (TensorProduct.directSumRight _ _ _).symm.toEquiv] rw [LinearEquiv.coe_toEquiv, ← LinearEquiv.coe_coe, ← LinearMap.coe_comp] rw [LinearEquiv.coe_toEquiv, ← LinearEquiv.coe_coe, ← LinearMap.coe_comp] rw [← psi_def, injective_iff_map_eq_zero ((η₁.comp ρ).comp ψ)] have h₁ : ∀ (i : ι), (π i).comp ((η₁.comp ρ).comp ψ) = (η i).comp ((φ i).comp (τ i)) := by intro i apply DirectSum.linearMap_ext intro j apply TensorProduct.ext' intro a m simp only [ρ, ψ, φ, η, η₁, coe_comp, LinearEquiv.coe_coe, Function.comp_apply, directSumRight_symm_lof_tmul, rTensor_tmul, Submodule.coeSubtype, lid_tmul, map_smul] rw [DirectSum.component.of, DirectSum.component.of] by_cases h₂ : j = i · subst j; simp · simp [h₂] intro a ha; rw [DirectSum.ext_iff R]; intro i have f := LinearMap.congr_arg (f := (π i)) ha erw [LinearMap.congr_fun (h₁ i) a] at f rw [(map_zero (π i) : (π i) 0 = (0 : M i))] at f have h₂ := F i rw [iff_rTensor_injective] at h₂ have h₃ := h₂ hI simp only [coe_comp, LinearEquiv.coe_coe, Function.comp_apply, AddEquivClass.map_eq_zero_iff, h₃, LinearMap.map_eq_zero_iff] at f simp [f] open scoped Classical in /-- Free `R`-modules over discrete types are flat. -/ instance finsupp (ι : Type v) : Flat R (ι →₀ R) := of_linearEquiv R _ _ (finsuppLEquivDirectSum R R ι) instance of_free [Free R M] : Flat R M := of_linearEquiv R _ _ (Free.repr R M) /-- A projective module with a discrete type of generator is flat -/ lemma of_projective_surjective (ι : Type w) [Projective R M] (p : (ι →₀ R) →ₗ[R] M) (hp : Surjective p) : Flat R M := by have h := Module.projective_lifting_property p (LinearMap.id) hp cases h with | _ e he => exact of_retract R _ _ _ _ he instance of_projective [h : Projective R M] : Flat R M := by rw [Module.projective_def'] at h cases h with | _ e he => exact of_retract R _ _ _ _ he /-- Define the character module of `M` to be `M →+ ℚ ⧸ ℤ`. The character module of `M` is an injective module if and only if `L ⊗ 𝟙 M` is injective for any linear map `L` in the same universe as `M`. -/ lemma injective_characterModule_iff_rTensor_preserves_injective_linearMap : Module.Injective R (CharacterModule M) ↔ ∀ ⦃N N' : Type v⦄ [AddCommGroup N] [AddCommGroup N'] [Module R N] [Module R N'] (L : N →ₗ[R] N'), Function.Injective L → Function.Injective (L.rTensor M) := by simp_rw [injective_iff, rTensor_injective_iff_lcomp_surjective, Surjective, DFunLike.ext_iff]; rfl variable {R M N} /-- `CharacterModule M` is Baer iff `M` is flat. -/ theorem iff_characterModule_baer : Flat R M ↔ Module.Baer R (CharacterModule M) := by simp_rw [iff_rTensor_injective', Baer, rTensor_injective_iff_lcomp_surjective, Surjective, DFunLike.ext_iff, Subtype.forall]; rfl /-- `CharacterModule M` is an injective module iff `M` is flat. -/ theorem iff_characterModule_injective [Small.{v} R] : Flat R M ↔ Module.Injective R (CharacterModule M) := iff_characterModule_baer.trans Module.Baer.iff_injective /-- If `M` is a flat module, then `f ⊗ 𝟙 M` is injective for all injective linear maps `f`. -/ theorem rTensor_preserves_injective_linearMap {N' : Type*} [AddCommGroup N'] [Module R N'] [h : Flat R M] (L : N →ₗ[R] N') (hL : Function.Injective L) : Function.Injective (L.rTensor M) := rTensor_injective_iff_lcomp_surjective.2 ((iff_characterModule_baer.1 h).extension_property _ hL) @[deprecated (since := "2024-03-29")] alias preserves_injective_linearMap := rTensor_preserves_injective_linearMap /-- If `M` is a flat module, then `𝟙 M ⊗ f` is injective for all injective linear maps `f`. -/ theorem lTensor_preserves_injective_linearMap {N' : Type*} [AddCommGroup N'] [Module R N'] [Flat R M] (L : N →ₗ[R] N') (hL : Function.Injective L) : Function.Injective (L.lTensor M) := (L.lTensor_inj_iff_rTensor_inj M).2 (rTensor_preserves_injective_linearMap L hL) variable (R M) in /-- M is flat if and only if `f ⊗ 𝟙 M` is injective whenever `f` is an injective linear map. -/ lemma iff_rTensor_preserves_injective_linearMap [Small.{v} R] : Flat R M ↔ ∀ ⦃N N' : Type v⦄ [AddCommGroup N] [AddCommGroup N'] [Module R N] [Module R N'] (L : N →ₗ[R] N'), Function.Injective L → Function.Injective (L.rTensor M) := by rw [iff_characterModule_injective, injective_characterModule_iff_rTensor_preserves_injective_linearMap] variable (R M) in /-- M is flat if and only if `𝟙 M ⊗ f` is injective whenever `f` is an injective linear map. -/ lemma iff_lTensor_preserves_injective_linearMap [Small.{v} R] : Flat R M ↔ ∀ ⦃N N' : Type v⦄ [AddCommGroup N] [AddCommGroup N'] [Module R N] [Module R N'] (L : N →ₗ[R] N'), Function.Injective L → Function.Injective (L.lTensor M) := by simp_rw [iff_rTensor_preserves_injective_linearMap, LinearMap.lTensor_inj_iff_rTensor_inj] variable (M) in lemma lTensor_exact [Small.{v} R] [flat : Flat R M] ⦃N N' N'' : Type v⦄ [AddCommGroup N] [AddCommGroup N'] [AddCommGroup N''] [Module R N] [Module R N'] [Module R N''] ⦃f : N →ₗ[R] N'⦄ ⦃g : N' →ₗ[R] N''⦄ (exact : Function.Exact f g) : Function.Exact (f.lTensor M) (g.lTensor M) := by let π : N' →ₗ[R] N' ⧸ LinearMap.range f := Submodule.mkQ _ let ι : N' ⧸ LinearMap.range f →ₗ[R] N'' := Submodule.subtype _ ∘ₗ (LinearMap.quotKerEquivRange g).toLinearMap ∘ₗ Submodule.quotEquivOfEq (LinearMap.range f) (LinearMap.ker g) (LinearMap.exact_iff.mp exact).symm suffices exact1 : Function.Exact (f.lTensor M) (π.lTensor M) by rw [show g = ι.comp π by aesop, lTensor_comp] exact exact1.comp_injective (inj := iff_lTensor_preserves_injective_linearMap R M |>.mp flat _ $ by simpa [ι] using Subtype.val_injective) (h0 := map_zero _) exact _root_.lTensor_exact _ (fun x => by simp [π]) Quotient.surjective_Quotient_mk'' variable (M) in lemma rTensor_exact [Small.{v} R] [flat : Flat R M] ⦃N N' N'' : Type v⦄ [AddCommGroup N] [AddCommGroup N'] [AddCommGroup N''] [Module R N] [Module R N'] [Module R N''] ⦃f : N →ₗ[R] N'⦄ ⦃g : N' →ₗ[R] N''⦄ (exact : Function.Exact f g) : Function.Exact (f.rTensor M) (g.rTensor M) := by let π : N' →ₗ[R] N' ⧸ LinearMap.range f := Submodule.mkQ _ let ι : N' ⧸ LinearMap.range f →ₗ[R] N'' := Submodule.subtype _ ∘ₗ (LinearMap.quotKerEquivRange g).toLinearMap ∘ₗ Submodule.quotEquivOfEq (LinearMap.range f) (LinearMap.ker g) (LinearMap.exact_iff.mp exact).symm suffices exact1 : Function.Exact (f.rTensor M) (π.rTensor M) by rw [show g = ι.comp π by aesop, rTensor_comp] exact exact1.comp_injective (inj := iff_rTensor_preserves_injective_linearMap R M |>.mp flat _ $ by simpa [ι] using Subtype.val_injective) (h0 := map_zero _) exact _root_.rTensor_exact _ (fun x => by simp [π]) Quotient.surjective_Quotient_mk'' /-- M is flat if and only if `M ⊗ -` is a left exact functor. -/ lemma iff_lTensor_exact [Small.{v} R] : Flat R M ↔ ∀ ⦃N N' N'' : Type v⦄ [AddCommGroup N] [AddCommGroup N'] [AddCommGroup N''] [Module R N] [Module R N'] [Module R N''] ⦃f : N →ₗ[R] N'⦄ ⦃g : N' →ₗ[R] N''⦄, Function.Exact f g → Function.Exact (f.lTensor M) (g.lTensor M) := by refine ⟨fun _ => lTensor_exact M, fun H => iff_lTensor_preserves_injective_linearMap R M |>.mpr fun N' N'' _ _ _ _ L hL => LinearMap.ker_eq_bot |>.mp <| eq_bot_iff |>.mpr fun x (hx : _ = 0) => ?_⟩ simpa [Eq.comm] using @H PUnit N' N'' _ _ _ _ _ _ 0 L (fun x => by aesop) x |>.mp hx /-- M is flat if and only if `- ⊗ M` is a left exact functor. -/ lemma iff_rTensor_exact [Small.{v} R] : Flat R M ↔ ∀ ⦃N N' N'' : Type v⦄ [AddCommGroup N] [AddCommGroup N'] [AddCommGroup N''] [Module R N] [Module R N'] [Module R N''] ⦃f : N →ₗ[R] N'⦄ ⦃g : N' →ₗ[R] N''⦄, Function.Exact f g → Function.Exact (f.rTensor M) (g.rTensor M) := by refine ⟨fun _ => rTensor_exact M, fun H => iff_rTensor_preserves_injective_linearMap R M |>.mpr fun N' N'' _ _ _ _ L hL => LinearMap.ker_eq_bot |>.mp <| eq_bot_iff |>.mpr fun x (hx : _ = 0) => ?_⟩ simpa [Eq.comm] using @H PUnit N' N'' _ _ _ _ _ _ 0 L (fun x => by aesop) x |>.mp hx end Flat end Module
RingTheory\Flat\CategoryTheory.lean
/- Copyright (c) 2024 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jujian Zhang -/ import Mathlib.RingTheory.Flat.Basic import Mathlib.Algebra.Homology.ShortComplex.ModuleCat import Mathlib.Algebra.Category.ModuleCat.Monoidal.Basic /-! # Tensoring with a flat module is an exact functor In this file we prove that tensoring with a flat module is an exact functor. ## Main results - `Module.Flat.iff_lTensor_preserves_shortComplex_exact`: an `R`-module `M` is flat if and only if for every exact sequence `A ⟶ B ⟶ C`, `M ⊗ A ⟶ M ⊗ B ⟶ M ⊗ C` is also exact. - `Module.Flat.iff_rTensor_preserves_shortComplex_exact`: an `R`-module `M` is flat if and only if for every short exact sequence `A ⟶ B ⟶ C`, `A ⊗ M ⟶ B ⊗ M ⟶ C ⊗ M` is also exact. ## TODO - Prove that tensoring with a flat module is an exact functor in the sense that it preserves both finite limits and colimits. - Relate flatness with `Tor` -/ universe u open CategoryTheory MonoidalCategory ShortComplex.ShortExact namespace Module.Flat variable {R : Type u} [CommRing R] (M : ModuleCat.{u} R) lemma lTensor_shortComplex_exact [Flat R M] (C : ShortComplex $ ModuleCat R) (hC : C.Exact) : C.map (tensorLeft M) |>.Exact := by rw [moduleCat_exact_iff_function_exact] at hC ⊢ exact lTensor_exact M hC lemma rTensor_shortComplex_exact [Flat R M] (C : ShortComplex $ ModuleCat R) (hC : C.Exact) : C.map (tensorRight M) |>.Exact := by rw [moduleCat_exact_iff_function_exact] at hC ⊢ exact rTensor_exact M hC lemma iff_lTensor_preserves_shortComplex_exact : Flat R M ↔ ∀ (C : ShortComplex $ ModuleCat R) (_ : C.Exact), (C.map (tensorLeft M) |>.Exact) := ⟨fun _ _ ↦ lTensor_shortComplex_exact _ _, fun H ↦ iff_lTensor_exact.2 $ fun _ _ _ _ _ _ _ _ _ f g h ↦ moduleCat_exact_iff_function_exact _ |>.1 $ H (.mk (ModuleCat.ofHom f) (ModuleCat.ofHom g) (DFunLike.ext _ _ h.apply_apply_eq_zero)) (moduleCat_exact_iff_function_exact _ |>.2 h)⟩ lemma iff_rTensor_preserves_shortComplex_exact : Flat R M ↔ ∀ (C : ShortComplex $ ModuleCat R) (_ : C.Exact), (C.map (tensorRight M) |>.Exact) := ⟨fun _ _ ↦ rTensor_shortComplex_exact _ _, fun H ↦ iff_rTensor_exact.2 $ fun _ _ _ _ _ _ _ _ _ f g h ↦ moduleCat_exact_iff_function_exact _ |>.1 $ H (.mk (ModuleCat.ofHom f) (ModuleCat.ofHom g) (DFunLike.ext _ _ h.apply_apply_eq_zero)) (moduleCat_exact_iff_function_exact _ |>.2 h)⟩ end Module.Flat
RingTheory\Flat\EquationalCriterion.lean
/- Copyright (c) 2024 Mitchell Lee. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mitchell Lee -/ import Mathlib.RingTheory.Flat.Basic import Mathlib.LinearAlgebra.TensorProduct.Vanishing import Mathlib.Algebra.Module.FinitePresentation /-! # The equational criterion for flatness Let $M$ be a module over a commutative ring $R$. Let us say that a relation $\sum_{i \in \iota} f_i x_i = 0$ in $M$ is *trivial* (`Module.IsTrivialRelation`) if there exist a finite index type $\kappa$, elements $(y_j)_{j \in \kappa}$ of $M$, and elements $(a_{ij})_{i \in \iota, j \in \kappa}$ of $R$ such that for all $i$, $$x_i = \sum_j a_{ij} y_j$$ and for all $j$, $$\sum_{i} f_i a_{ij} = 0.$$ The *equational criterion for flatness* [Stacks 00HK](https://stacks.math.columbia.edu/tag/00HK) (`Module.Flat.iff_forall_isTrivialRelation`) states that $M$ is flat if and only if every relation in $M$ is trivial. The equational criterion for flatness can be stated in the following form (`Module.Flat.iff_forall_exists_factorization`). Let $M$ be an $R$-module. Then the following two conditions are equivalent: * $M$ is flat. * For all finite index types $\iota$, all elements $f \in R^{\iota}$, and all homomorphisms $x \colon R^{\iota} \to M$ such that $x(f) = 0$, there exist a finite index type $\kappa$ and module homomorphisms $a \colon R^{\iota} \to R^{\kappa}$ and $y \colon R^{\kappa} \to M$ such that $x = y \circ a$ and $a(f) = 0$. Of course, the module $R^\iota$ in this statement can be replaced by an arbitrary free module (`Module.Flat.exists_factorization_of_apply_eq_zero_of_free`). We also have the following strengthening of the equational criterion for flatness (`Module.Flat.exists_factorization_of_comp_eq_zero_of_free`): Let $M$ be a flat module. Let $K$ and $N$ be finite $R$-modules with $N$ free, and let $f \colon K \to N$ and $x \colon N \to M$ be homomorphisms such that $x \circ f = 0$. Then there exist a finite index type $\kappa$ and module homomorphisms $a \colon N \to R^{\kappa}$ and $y \colon R^{\kappa} \to M$ such that $x = y \circ a$ and $a \circ f = 0$. We recover the usual equational criterion for flatness if $K = R$ and $N = R^\iota$. This is used in the proof of Lazard's theorem. We conclude that every homomorphism from a finitely presented module to a flat module factors through a finite free module (`Module.Flat.exists_factorization_of_isFinitelyPresented`). ## References * [Stacks: Flat modules and flat ring maps](https://stacks.math.columbia.edu/tag/00H9) * [Stacks: Characterizing flatness](https://stacks.math.columbia.edu/tag/058C) -/ universe u variable {R M : Type u} [CommRing R] [AddCommGroup M] [Module R M] open LinearMap TensorProduct Finsupp namespace Module variable {ι : Type u} [Fintype ι] (f : ι → R) (x : ι → M) /-- The proposition that the relation $\sum_i f_i x_i = 0$ in $M$ is trivial. That is, there exist a finite index type $\kappa$, elements $(y_j)_{j \in \kappa}$ of $M$, and elements $(a_{ij})_{i \in \iota, j \in \kappa}$ of $R$ such that for all $i$, $$x_i = \sum_j a_{ij} y_j$$ and for all $j$, $$\sum_{i} f_i a_{ij} = 0.$$ By `Module.sum_smul_eq_zero_of_isTrivialRelation`, this condition implies $\sum_i f_i x_i = 0$. -/ abbrev IsTrivialRelation : Prop := ∃ (κ : Type u) (_ : Fintype κ) (a : ι → κ → R) (y : κ → M), (∀ i, x i = ∑ j, a i j • y j) ∧ ∀ j, ∑ i, f i * a i j = 0 variable {f x} /-- `Module.IsTrivialRelation` is equivalent to the predicate `TensorProduct.VanishesTrivially` defined in `Mathlib/LinearAlgebra/TensorProduct/Vanishing.lean`. -/ theorem isTrivialRelation_iff_vanishesTrivially : IsTrivialRelation f x ↔ VanishesTrivially R f x := by simp only [IsTrivialRelation, VanishesTrivially, smul_eq_mul, mul_comm] /-- If the relation given by $(f_i)_{i \in \iota}$ and $(x_i)_{i \in \iota}$ is trivial, then $\sum_{i} f_i x_i$ is actually equal to $0$. -/ theorem sum_smul_eq_zero_of_isTrivialRelation (h : IsTrivialRelation f x) : ∑ i, f i • x i = 0 := by simpa using congr_arg (TensorProduct.lid R M) <| sum_tmul_eq_zero_of_vanishesTrivially R (isTrivialRelation_iff_vanishesTrivially.mp h) end Module namespace Module.Flat variable (R M) in /-- **Equational criterion for flatness** [Stacks 00HK](https://stacks.math.columbia.edu/tag/00HK), combined form. Let $M$ be a module over a commutative ring $R$. The following are equivalent: * $M$ is flat. * For all ideals $I \subseteq R$, the map $I \otimes M \to M$ is injective. * Every $\sum_i f_i \otimes x_i$ that vanishes in $R \otimes M$ vanishes trivially. * Every relation $\sum_i f_i x_i = 0$ in $M$ is trivial. * For all finite index types $\iota$, all elements $f \in R^{\iota}$, and all homomorphisms $x \colon R^{\iota} \to M$ such that $x(f) = 0$, there exist a finite index type $\kappa$ and module homomorphisms $a \colon R^{\iota} \to R^{\kappa}$ and $y \colon R^{\kappa} \to M$ such that $x = y \circ a$ and $a(f) = 0$. * For all finite free modules $N$, all elements $f \in N$, and all homomorphisms $x \colon N \to M$ such that $x(f) = 0$, there exist a finite index type $\kappa$ and module homomorphisms $a \colon N \to R^{\kappa}$ and $y \colon R^{\kappa} \to M$ such that $x = y \circ a$ and $a(f) = 0$. -/ theorem tfae_equational_criterion : List.TFAE [ Flat R M, ∀ (I : Ideal R), Function.Injective ⇑(rTensor M (Submodule.subtype I)), ∀ {ι : Type u} [Fintype ι] {f : ι → R} {x : ι → M}, ∑ i, f i ⊗ₜ x i = (0 : R ⊗[R] M) → VanishesTrivially R f x, ∀ {ι : Type u} [Fintype ι] {f : ι → R} {x : ι → M}, ∑ i, f i • x i = 0 → IsTrivialRelation f x, ∀ {ι : Type u} [Fintype ι] {f : ι →₀ R} {x : (ι →₀ R) →ₗ[R] M}, x f = 0 → ∃ (κ : Type u) (_ : Fintype κ) (a : (ι →₀ R) →ₗ[R] (κ →₀ R)) (y : (κ →₀ R) →ₗ[R] M), x = y ∘ₗ a ∧ a f = 0, ∀ {N : Type u} [AddCommGroup N] [Module R N] [Free R N] [Finite R N] {f : N} {x : N →ₗ[R] M}, x f = 0 → ∃ (κ : Type u) (_ : Fintype κ) (a : N →ₗ[R] (κ →₀ R)) (y : (κ →₀ R) →ₗ[R] M), x = y ∘ₗ a ∧ a f = 0] := by classical tfae_have 1 ↔ 2 · exact iff_rTensor_injective' R M tfae_have 3 ↔ 2 · exact forall_vanishesTrivially_iff_forall_rTensor_injective R tfae_have 3 ↔ 4 · simp [(TensorProduct.lid R M).injective.eq_iff.symm, isTrivialRelation_iff_vanishesTrivially] tfae_have 4 → 5 · intro h₄ ι hι f x hfx let f' : ι → R := f let x' : ι → M := fun i ↦ x (single i 1) have := calc ∑ i, f' i • x' i _ = ∑ i, f i • x (single i 1) := rfl _ = x (∑ i, f i • Finsupp.single i 1) := by simp_rw [map_sum, map_smul] _ = x f := by simp_rw [smul_single, smul_eq_mul, mul_one, univ_sum_single] _ = 0 := hfx obtain ⟨κ, hκ, a', y', ⟨ha'y', ha'⟩⟩ := h₄ this use κ, hκ use Finsupp.total ι (κ →₀ R) R (fun i ↦ equivFunOnFinite.symm (a' i)) use Finsupp.total κ M R y' constructor · apply Finsupp.basisSingleOne.ext intro i simpa [total_apply, sum_fintype, single_apply] using ha'y' i · ext j simp only [total_apply, zero_smul, implies_true, sum_fintype, finset_sum_apply] exact ha' j tfae_have 5 → 4 · intro h₅ ι hi f x hfx let f' : ι →₀ R := equivFunOnFinite.symm f let x' : (ι →₀ R) →ₗ[R] M := Finsupp.total ι M R x have : x' f' = 0 := by simpa [x', f', total_apply, sum_fintype] using hfx obtain ⟨κ, hκ, a', y', ha'y', ha'⟩ := h₅ this refine ⟨κ, hκ, fun i ↦ a' (single i 1), fun j ↦ y' (single j 1), fun i ↦ ?_, fun j ↦ ?_⟩ · simpa [x', ← map_smul, ← map_sum, smul_single] using LinearMap.congr_fun ha'y' (Finsupp.single i 1) · simp_rw [← smul_eq_mul, ← Finsupp.smul_apply, ← map_smul, ← finset_sum_apply, ← map_sum, smul_single, smul_eq_mul, mul_one, ← (fun _ ↦ equivFunOnFinite_symm_apply_toFun _ _ : ∀ x, f' x = f x), univ_sum_single] simpa using DFunLike.congr_fun ha' j tfae_have 5 → 6 · intro h₅ N _ _ _ _ f x hfx have ϕ := Module.Free.repr R N have : (x ∘ₗ ϕ.symm) (ϕ f) = 0 := by simpa obtain ⟨κ, hκ, a', y, ha'y, ha'⟩ := h₅ this refine ⟨κ, hκ, a' ∘ₗ ϕ, y, ?_, ?_⟩ · simpa [LinearMap.comp_assoc] using congrArg (fun g ↦ (g ∘ₗ ϕ : N →ₗ[R] M)) ha'y · simpa using ha' tfae_have 6 → 5 · intro h₆ _ _ _ _ hfx exact h₆ hfx tfae_finish /-- **Equational criterion for flatness** [Stacks 00HK](https://stacks.math.columbia.edu/tag/00HK). A module $M$ is flat if and only if every relation $\sum_i f_i x_i = 0$ in $M$ is trivial. -/ theorem iff_forall_isTrivialRelation : Flat R M ↔ ∀ {ι : Type u} [Fintype ι] {f : ι → R} {x : ι → M}, ∑ i, f i • x i = 0 → IsTrivialRelation f x := (tfae_equational_criterion R M).out 0 3 /-- **Equational criterion for flatness** [Stacks 00HK](https://stacks.math.columbia.edu/tag/00HK), forward direction. If $M$ is flat, then every relation $\sum_i f_i x_i = 0$ in $M$ is trivial. -/ theorem isTrivialRelation_of_sum_smul_eq_zero [Flat R M] {ι : Type u} [Fintype ι] {f : ι → R} {x : ι → M} (h : ∑ i, f i • x i = 0) : IsTrivialRelation f x := iff_forall_isTrivialRelation.mp ‹Flat R M› h /-- **Equational criterion for flatness** [Stacks 00HK](https://stacks.math.columbia.edu/tag/00HK), backward direction. If every relation $\sum_i f_i x_i = 0$ in $M$ is trivial, then $M$ is flat. -/ theorem of_forall_isTrivialRelation (hfx : ∀ {ι : Type u} [Fintype ι] {f : ι → R} {x : ι → M}, ∑ i, f i • x i = 0 → IsTrivialRelation f x) : Flat R M := iff_forall_isTrivialRelation.mpr hfx /-- **Equational criterion for flatness** [Stacks 00HK](https://stacks.math.columbia.edu/tag/00HK), alternate form. A module $M$ is flat if and only if for all finite free modules $R^\iota$, all $f \in R^{\iota}$, and all homomorphisms $x \colon R^{\iota} \to M$ such that $x(f) = 0$, there exist a finite free module $R^\kappa$ and homomorphisms $a \colon R^{\iota} \to R^{\kappa}$ and $y \colon R^{\kappa} \to M$ such that $x = y \circ a$ and $a(f) = 0$. -/ theorem iff_forall_exists_factorization : Flat R M ↔ ∀ {ι : Type u} [Fintype ι] {f : ι →₀ R} {x : (ι →₀ R) →ₗ[R] M}, x f = 0 → ∃ (κ : Type u) (_ : Fintype κ) (a : (ι →₀ R) →ₗ[R] (κ →₀ R)) (y : (κ →₀ R) →ₗ[R] M), x = y ∘ₗ a ∧ a f = 0 := (tfae_equational_criterion R M).out 0 4 /-- **Equational criterion for flatness** [Stacks 00HK](https://stacks.math.columbia.edu/tag/00HK), forward direction, alternate form. Let $M$ be a flat module. Let $R^\iota$ be a finite free module, let $f \in R^{\iota}$ be an element, and let $x \colon R^{\iota} \to M$ be a homomorphism such that $x(f) = 0$. Then there exist a finite free module $R^\kappa$ and homomorphisms $a \colon R^{\iota} \to R^{\kappa}$ and $y \colon R^{\kappa} \to M$ such that $x = y \circ a$ and $a(f) = 0$. -/ theorem exists_factorization_of_apply_eq_zero [Flat R M] {ι : Type u} [_root_.Finite ι] {f : ι →₀ R} {x : (ι →₀ R) →ₗ[R] M} (h : x f = 0) : ∃ (κ : Type u) (_ : Fintype κ) (a : (ι →₀ R) →ₗ[R] (κ →₀ R)) (y : (κ →₀ R) →ₗ[R] M), x = y ∘ₗ a ∧ a f = 0 := let ⟨_⟩ := nonempty_fintype ι; iff_forall_exists_factorization.mp ‹Flat R M› h /-- **Equational criterion for flatness** [Stacks 00HK](https://stacks.math.columbia.edu/tag/00HK), backward direction, alternate form. Let $M$ be a module over a commutative ring $R$. Suppose that for all finite free modules $R^\iota$, all $f \in R^{\iota}$, and all homomorphisms $x \colon R^{\iota} \to M$ such that $x(f) = 0$, there exist a finite free module $R^\kappa$ and homomorphisms $a \colon R^{\iota} \to R^{\kappa}$ and $y \colon R^{\kappa} \to M$ such that $x = y \circ a$ and $a(f) = 0$. Then $M$ is flat. -/ theorem of_forall_exists_factorization (h : ∀ {ι : Type u} [Fintype ι] {f : ι →₀ R} {x : (ι →₀ R) →ₗ[R] M}, x f = 0 → ∃ (κ : Type u) (_ : Fintype κ) (a : (ι →₀ R) →ₗ[R] (κ →₀ R)) (y : (κ →₀ R) →ₗ[R] M), x = y ∘ₗ a ∧ a f = 0) : Flat R M := iff_forall_exists_factorization.mpr h /-- **Equational criterion for flatness** [Stacks 00HK](https://stacks.math.columbia.edu/tag/00HK), forward direction, second alternate form. Let $M$ be a flat module over a commutative ring $R$. Let $N$ be a finite free module over $R$, let $f \in N$, and let $x \colon N \to M$ be a homomorphism such that $x(f) = 0$. Then there exist a finite index type $\kappa$ and module homomorphisms $a \colon N \to R^{\kappa}$ and $y \colon R^{\kappa} \to M$ such that $x = y \circ a$ and $a(f) = 0$. -/ theorem exists_factorization_of_apply_eq_zero_of_free [Flat R M] {N : Type u} [AddCommGroup N] [Module R N] [Free R N] [Finite R N] {f : N} {x : N →ₗ[R] M} (h : x f = 0) : ∃ (κ : Type u) (_ : Fintype κ) (a : N →ₗ[R] (κ →₀ R)) (y : (κ →₀ R) →ₗ[R] M), x = y ∘ₗ a ∧ a f = 0 := by exact ((tfae_equational_criterion R M).out 0 5 rfl rfl).mp ‹Flat R M› h /-- Let $M$ be a flat module. Let $K$ and $N$ be finite $R$-modules with $N$ free, and let $f \colon K \to N$ and $x \colon N \to M$ be homomorphisms such that $x \circ f = 0$. Then there exist a finite index type $\kappa$ and module homomorphisms $a \colon N \to R^{\kappa}$ and $y \colon R^{\kappa} \to M$ such that $x = y \circ a$ and $a \circ f = 0$. -/ theorem exists_factorization_of_comp_eq_zero_of_free [Flat R M] {K N : Type u} [AddCommGroup K] [Module R K] [Finite R K] [AddCommGroup N] [Module R N] [Free R N] [Finite R N] {f : K →ₗ[R] N} {x : N →ₗ[R] M} (h : x ∘ₗ f = 0) : ∃ (κ : Type u) (_ : Fintype κ) (a : N →ₗ[R] (κ →₀ R)) (y : (κ →₀ R) →ₗ[R] M), x = y ∘ₗ a ∧ a ∘ₗ f = 0 := by have (K' : Submodule R K) (hK' : K'.FG) : ∃ (κ : Type u) (_ : Fintype κ) (a : N →ₗ[R] (κ →₀ R)) (y : (κ →₀ R) →ₗ[R] M), x = y ∘ₗ a ∧ K' ≤ LinearMap.ker (a ∘ₗ f) := by revert N apply Submodule.fg_induction (N := K') (hN := hK') · intro k N _ _ _ _ f x hfx have : x (f k) = 0 := by simpa using LinearMap.congr_fun hfx k simpa using exists_factorization_of_apply_eq_zero_of_free this · intro K₁ K₂ ih₁ ih₂ N _ _ _ _ f x hfx obtain ⟨κ₁, _, a₁, y₁, rfl, ha₁⟩ := ih₁ hfx have : y₁ ∘ₗ (a₁ ∘ₗ f) = 0 := by rw [← comp_assoc, hfx] obtain ⟨κ₂, hκ₂, a₂, y₂, rfl, ha₂⟩ := ih₂ this use κ₂, hκ₂, a₂ ∘ₗ a₁, y₂ simp_rw [comp_assoc] exact ⟨trivial, sup_le (ha₁.trans (ker_le_ker_comp _ _)) ha₂⟩ convert this ⊤ Finite.out simp only [top_le_iff, ker_eq_top] /-- Every homomorphism from a finitely presented module to a flat module factors through a finite free module. -/ theorem exists_factorization_of_isFinitelyPresented [Flat R M] {P : Type u} [AddCommGroup P] [Module R P] [FinitePresentation R P] (h₁ : P →ₗ[R] M) : ∃ (κ : Type u) (_ : Fintype κ) (h₂ : P →ₗ[R] (κ →₀ R)) (h₃ : (κ →₀ R) →ₗ[R] M), h₁ = h₃ ∘ₗ h₂ := by obtain ⟨L, _, _, K, ϕ, _, _, hK⟩ := FinitePresentation.equiv_quotient R P haveI : Finite R ↥K := Module.Finite.iff_fg.mpr hK have : (h₁ ∘ₗ ϕ.symm ∘ₗ K.mkQ) ∘ₗ K.subtype = 0 := by simp_rw [comp_assoc, (LinearMap.exact_subtype_mkQ K).linearMap_comp_eq_zero, comp_zero] obtain ⟨κ, hκ, a, y, hay, ha⟩ := exists_factorization_of_comp_eq_zero_of_free this use κ, hκ, (K.liftQ a (by rwa [← range_le_ker_iff, Submodule.range_subtype] at ha)) ∘ₗ ϕ, y apply (cancel_right ϕ.symm.surjective).mp apply (cancel_right K.mkQ_surjective).mp simpa [comp_assoc] end Module.Flat
RingTheory\Flat\Stability.lean
/- Copyright (c) 2024 Christian Merten. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christian Merten -/ import Mathlib.RingTheory.Flat.Basic import Mathlib.RingTheory.IsTensorProduct import Mathlib.LinearAlgebra.TensorProduct.Tower import Mathlib.RingTheory.Localization.BaseChange import Mathlib.Algebra.Module.LocalizedModule /-! # Flatness is stable under composition and base change We show that flatness is stable under composition and base change. ## Main theorems * `Module.Flat.comp`: if `S` is a flat `R`-algebra and `M` is a flat `S`-module, then `M` is a flat `R`-module * `Module.Flat.baseChange`: if `M` is a flat `R`-module and `S` is any `R`-algebra, then `S ⊗[R] M` is `S`-flat. * `Module.Flat.of_isLocalizedModule`: if `M` is a flat `R`-module and `S` is a submonoid of `R` then the localization of `M` at `S` is flat as a module for the localzation of `R` at `S`. -/ universe u v w t open Function (Injective Surjective) open LinearMap (lsmul rTensor lTensor) open TensorProduct namespace Module.Flat section Composition /-! ### Composition Let `R` be a ring, `S` a flat `R`-algebra and `M` a flat `S`-module. To show that `M` is flat as an `R`-module, we show that the inclusion of an `R`-ideal `I` into `R` tensored on the left with `M` is injective. For this consider the composition of natural maps `M ⊗[R] I ≃ M ⊗[S] (S ⊗[R] I) ≃ M ⊗[S] J → M ⊗[S] S ≃ M ≃ M ⊗[R] R` where `J` is the image of `S ⊗[R] I` under the (by flatness of `S`) injective map `S ⊗[R] I → S`. One checks that this composition is precisely `I → R` tensored on the left with `M` and it is injective as a composition of injective maps (note that `M ⊗[S] J → M ⊗[S] S` is injective because `M` is `S`-flat). -/ variable (R : Type u) (S : Type v) (M : Type w) [CommRing R] [CommRing S] [Algebra R S] [AddCommGroup M] [Module R M] [Module S M] [IsScalarTower R S M] private noncomputable abbrev auxRightMul (I : Ideal R) : M ⊗[R] I →ₗ[S] M := by letI i : M ⊗[R] I →ₗ[S] M ⊗[R] R := AlgebraTensorModule.map LinearMap.id I.subtype letI e' : M ⊗[R] R →ₗ[S] M := AlgebraTensorModule.rid R S M exact AlgebraTensorModule.rid R S M ∘ₗ i private noncomputable abbrev J (I : Ideal R) : Ideal S := LinearMap.range (auxRightMul R S S I) private noncomputable abbrev auxIso [Module.Flat R S] {I : Ideal R} : S ⊗[R] I ≃ₗ[S] J R S I := by apply LinearEquiv.ofInjective (auxRightMul R S S I) simp only [LinearMap.coe_comp, LinearEquiv.coe_coe, EquivLike.comp_injective] exact (Module.Flat.iff_lTensor_injective' R S).mp inferInstance I private noncomputable abbrev auxLTensor [Module.Flat R S] (I : Ideal R) : M ⊗[R] I →ₗ[S] M := by letI e1 : M ⊗[R] I ≃ₗ[S] M ⊗[S] (S ⊗[R] I) := (AlgebraTensorModule.cancelBaseChange R S S M I).symm letI e2 : M ⊗[S] (S ⊗[R] I) ≃ₗ[S] M ⊗[S] (J R S I) := TensorProduct.congr (LinearEquiv.refl S M) (auxIso R S) letI e3 : M ⊗[S] (J R S I) →ₗ[S] M ⊗[S] S := lTensor M (J R S I).subtype letI e4 : M ⊗[S] S →ₗ[S] M := TensorProduct.rid S M exact e4 ∘ₗ e3 ∘ₗ (e1 ≪≫ₗ e2) private lemma auxLTensor_eq [Module.Flat R S] {I : Ideal R} : (auxLTensor R S M I : M ⊗[R] I →ₗ[R] M) = TensorProduct.rid R M ∘ₗ lTensor M (I.subtype) := by apply TensorProduct.ext' intro m x erw [TensorProduct.rid_tmul] simp /-- If `S` is a flat `R`-algebra, then any flat `S`-Module is also `R`-flat. -/ theorem comp [Module.Flat R S] [Module.Flat S M] : Module.Flat R M := by rw [Module.Flat.iff_lTensor_injective'] intro I rw [← EquivLike.comp_injective _ (TensorProduct.rid R M)] haveI h : TensorProduct.rid R M ∘ lTensor M (Submodule.subtype I) = TensorProduct.rid R M ∘ₗ lTensor M I.subtype := rfl simp only [h, ← auxLTensor_eq R S M, LinearMap.coe_restrictScalars, LinearMap.coe_comp, LinearEquiv.coe_coe, EquivLike.comp_injective, EquivLike.injective_comp] exact (Module.Flat.iff_lTensor_injective' S M).mp inferInstance _ end Composition section BaseChange /-! ### Base change Let `R` be a ring, `M` a flat `R`-module and `S` an `R`-algebra. To show that `S ⊗[R] M` is `S`-flat, we consider for an ideal `I` in `S` the composition of natural maps `I ⊗[S] (S ⊗[R] M) ≃ I ⊗[R] M → S ⊗[R] M ≃ S ⊗[S] (S ⊗[R] M)`. One checks that this composition is precisely the inclusion `I → S` tensored on the right with `S ⊗[R] M` and that the former is injective (note that `I ⊗[R] M → S ⊗[R] M` is injective, since `M` is `R`-flat). -/ variable (R : Type u) (S : Type v) (M : Type w) [CommRing R] [CommRing S] [Algebra R S] [AddCommGroup M] [Module R M] private noncomputable abbrev auxRTensorBaseChange (I : Ideal S) : I ⊗[S] (S ⊗[R] M) →ₗ[S] S ⊗[S] (S ⊗[R] M) := letI e1 : I ⊗[S] (S ⊗[R] M) ≃ₗ[S] I ⊗[R] M := AlgebraTensorModule.cancelBaseChange R S S I M letI e2 : S ⊗[S] (S ⊗[R] M) ≃ₗ[S] S ⊗[R] M := AlgebraTensorModule.cancelBaseChange R S S S M letI f : I ⊗[R] M →ₗ[S] S ⊗[R] M := AlgebraTensorModule.map (Submodule.subtype I) LinearMap.id e2.symm.toLinearMap ∘ₗ f ∘ₗ e1.toLinearMap private lemma auxRTensorBaseChange_eq (I : Ideal S) : auxRTensorBaseChange R S M I = rTensor (S ⊗[R] M) (Submodule.subtype I) := by ext simp /-- If `M` is a flat `R`-module and `S` is any `R`-algebra, `S ⊗[R] M` is `S`-flat. -/ instance baseChange [Module.Flat R M] : Module.Flat S (S ⊗[R] M) := by rw [Module.Flat.iff_rTensor_injective'] intro I simp only [← auxRTensorBaseChange_eq, auxRTensorBaseChange, LinearMap.coe_comp, LinearEquiv.coe_coe, EmbeddingLike.comp_injective, EquivLike.injective_comp] exact rTensor_preserves_injective_linearMap (I.subtype : I →ₗ[R] S) Subtype.val_injective /-- A base change of a flat module is flat. -/ theorem isBaseChange [Module.Flat R M] (N : Type t) [AddCommGroup N] [Module R N] [Module S N] [IsScalarTower R S N] {f : M →ₗ[R] N} (h : IsBaseChange S f) : Module.Flat S N := of_linearEquiv S (S ⊗[R] M) N (IsBaseChange.equiv h).symm end BaseChange section Localization variable {R : Type u} {M Mp : Type*} (Rp : Type v) [CommRing R] [AddCommGroup M] [Module R M] [CommRing Rp] [Algebra R Rp] [AddCommGroup Mp] [Module R Mp] [Module Rp Mp] [IsScalarTower R Rp Mp] (f : M →ₗ[R] Mp) instance localizedModule [Module.Flat R M] (S : Submonoid R) : Module.Flat (Localization S) (LocalizedModule S M) := by apply Module.Flat.isBaseChange (R := R) (S := Localization S) (f := LocalizedModule.mkLinearMap S M) rw [← isLocalizedModule_iff_isBaseChange S] exact localizedModuleIsLocalizedModule S theorem of_isLocalizedModule [Module.Flat R M] (S : Submonoid R) [IsLocalization S Rp] (f : M →ₗ[R] Mp) [h : IsLocalizedModule S f] : Module.Flat Rp Mp := by fapply Module.Flat.isBaseChange (R := R) (M := M) (S := Rp) (N := Mp) exact (isLocalizedModule_iff_isBaseChange S Rp f).mp h end Localization end Module.Flat
RingTheory\FractionalIdeal\Basic.lean
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Filippo A. E. Nuccio -/ 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 * `mul_left_mono` and `mul_right_mono` 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 re-use 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) (NoZeroSMulDivisors.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 @[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 -- Porting note: this seems to be needed a lot more than in Lean 3 @[simp] theorem val_eq_coe (I : FractionalIdeal S P) : I.val = I := rfl -- Porting note: had to rephrase this to make it clear to `simp` what was going on. @[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⟩ := 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 _ _ 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 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 @[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 -- Porting note: doesn't need to be @[simp] because it can be proved by coeIdeal_eq_zero 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 -- Porting note: changed the proof from convert; simp into rw; exact rw [(mem_zero_iff _).mp hx] exact zero_mem I instance orderBot : OrderBot (FractionalIdeal S P) where bot := 0 bot_le := zero_le @[simp] theorem bot_eq_zero : (⊥ : FractionalIdeal S P) = 0 := rfl @[simp] 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 : Inf (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 : Sup (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 @[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] @[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 _ _ _) theorem mul_left_mono (I : FractionalIdeal S P) : Monotone (I * ·) := by intro J J' h simp only [mul_def] exact mul_le.mpr fun x hx y hy => mul_mem_mul hx (h hy) theorem mul_right_mono (I : FractionalIdeal S P) : Monotone fun J => J * I := by intro J J' h simp only [mul_def] exact mul_le.mpr fun x hx y hy => mul_mem_mul (h hx) hy 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] @[deprecated (since := "2024-04-17")] alias coe_nat_cast := coe_natCast 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 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 theorem add_le_add_left {I J : FractionalIdeal S P} (hIJ : I ≤ J) (J' : FractionalIdeal S P) : J' + I ≤ J' + J := sup_le_sup_left hIJ J' theorem mul_le_mul_left {I J : FractionalIdeal S P} (hIJ : I ≤ J) (J' : FractionalIdeal S P) : J' * I ≤ J' * J := mul_le.mpr fun _ hk _ hj => mul_mem_mul hk (hIJ hj) theorem le_self_mul_self {I : FractionalIdeal S P} (hI : 1 ≤ I) : I ≤ I * I := by convert mul_left_mono I hI exact (mul_one I).symm theorem mul_self_le_self {I : FractionalIdeal S P} (hI : I ≤ 1) : I * I ≤ I := by convert mul_left_mono I hI exact (mul_one I).symm 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
RingTheory\FractionalIdeal\Norm.lean
/- Copyright (c) 2024 Xavier Roblot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Xavier Roblot -/ import Mathlib.RingTheory.FractionalIdeal.Basic import Mathlib.RingTheory.Ideal.Norm /-! # 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 -/ namespace FractionalIdeal open scoped Pointwise nonZeroDivisors 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 [← Int.cast_natAbs, ← Nat.cast_mul, ← Ideal.absNorm_span_singleton] rw [← _root_.map_mul, ← _root_.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 dsimp only rw [num_zero_eq, Submodule.zero_eq_bot, Ideal.absNorm_bot, Nat.cast_zero, zero_div] exact IsFractionRing.injective R K map_one' := by dsimp only rw [absNorm_div_norm_eq_absNorm_div_norm 1 ⊤ (by simp [Submodule.one_eq_range]), Ideal.absNorm_top, Nat.cast_one, OneMemClass.coe_one, _root_.map_one, abs_one, Int.cast_one, one_div_one] map_mul' I J := by dsimp only 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, _root_.map_mul, _root_.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_not_mem_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, _root_.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, Int.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 [Int.cast_natAbs, Int.cast_abs, show ((Algebra.norm ℤ _) : ℚ) = algebraMap ℤ ℚ (Algebra.norm ℤ _) by rfl, ← Algebra.norm_localization ℤ ℤ⁰ (Sₘ := K) _] rw [hr, Algebra.smul_def, _root_.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 [← SetLike.mem_coe, Submodule.coe_pointwise_smul, Set.mem_smul_set, SetLike.mem_coe, mem_coe, mem_spanSingleton, Submodule.mem_map, Algebra.linearMap_apply, Submonoid.smul_def, Ideal.mem_span_singleton', exists_exists_eq_and, _root_.map_mul, hr, ← Algebra.smul_def, smul_comm (d : R)] end IsLocalization end FractionalIdeal
RingTheory\FractionalIdeal\Operations.lean
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Filippo A. E. Nuccio -/ import Mathlib.RingTheory.FractionalIdeal.Basic import Mathlib.RingTheory.IntegralClosure.IsIntegral.Basic /-! # 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, _root_.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 only [mem_coeIdeal] constructor · rintro ⟨_, ⟨y, hy, rfl⟩, rfl⟩ exact ⟨y, hy, (g.commutes y).symm⟩ · rintro ⟨y, hy, rfl⟩ exact ⟨_, ⟨y, hy, rfl⟩, g.commutes y⟩ @[simp] theorem map_one : (1 : FractionalIdeal S P).map g = 1 := map_coeIdeal g ⊤ @[simp] theorem map_zero : (0 : FractionalIdeal S P).map g = 0 := map_coeIdeal g 0 @[simp] theorem map_add : (I + J).map g = I.map g + J.map g := coeToSubmodule_injective (Submodule.map_sup _ _ _) @[simp] 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 := map_add I J _ map_mul' I J := 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 b hb => span_induction 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) 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 _ variable {S} 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 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 r => 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]; erw [RingEquiv.apply_symm_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 only [IsLocalization.map_map, RingHomInvPair.comp_eq₂, mem_canonicalEquiv_apply, exists_prop, exists_exists_and_eq_and] 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_not_mem⟩ := 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_not_mem 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 ▸ 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 := ⟨fun h ↦ zero_of_num_eq_bot zero_not_mem_nonZeroDivisors h, fun 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, not_mem_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 not_mem_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 fractional_div_of_nonzero {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 open Classical in noncomputable instance : Div (FractionalIdeal R₁⁰ K) := ⟨fun I J => if h : J = 0 then 0 else ⟨I / J, fractional_div_of_nonzero h⟩⟩ variable {I J : FractionalIdeal R₁⁰ K} @[simp] theorem div_zero {I : FractionalIdeal R₁⁰ K} : I / 0 = 0 := dif_pos rfl theorem div_nonzero {I J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) : I / J = ⟨I / J, fractional_div_of_nonzero h⟩ := dif_neg h @[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_nonzero {I J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) {x} : x ∈ I / J ↔ ∀ y ∈ J, x * y ∈ I := by rw [div_nonzero h] exact Submodule.mem_div_iff_forall_mul_mem 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_nonzero {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_nonzero hJ').mp (h hx), fun h x hx => (mem_div_iff_of_nonzero hJ').mpr (h x hx)⟩ theorem le_div_iff_mul_le {I J J' : FractionalIdeal R₁⁰ K} (hJ' : J' ≠ 0) : I ≤ J / J' ↔ I * J' ≤ J := by rw [div_nonzero hJ'] -- Porting note: this used to be { convert; rw }, flipped the order. rw [← 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_nonzero (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⟩ -- Porting note: this used to be { convert; rw }, flipped the order. rw [mul_comm, Algebra.linearMap_apply, ← Algebra.smul_def] exact Submodule.smul_mem _ y' h 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_nonzero hI).mp hy x hx rw [← h] apply mul_left_mono I apply (le_div_iff_of_nonzero hI).mpr _ intro y hy x hx rw [mul_comm] exact mul_mem_mul hx hy 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] 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, map_zero, div_zero] · -- Porting note: `simp` wouldn't apply these lemmas so do them manually using `rw` rw [← coeToSubmodule_inj, div_nonzero H, div_nonzero (map_ne_zero _ H)] simp [Submodule.map_div] -- Porting note: doesn't need to be @[simp] because this follows from `map_one` and `map_div` 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 [map_div, 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.mk'_surjective 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 erw [Set.mem_smul_set, Set.mem_smul_set] simp [Algebra.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 h => ⟨@generator _ _ _ _ _ (↑I) h, @eq_spanSingleton_of_principal _ _ _ _ _ _ _ I h⟩, 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 [Submodule.mem_span_singleton, 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 n hn · rw [pow_zero, pow_zero, spanSingleton_one] · 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) 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] variable {K} 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_simp 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, MulZeroClass.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, MulZeroClass.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} (hzI : 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_singleton_mul, 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] attribute [local instance] Classical.propDecidable 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 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
RingTheory\GradedAlgebra\Basic.lean
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser, Kevin Buzzard, Jujian Zhang, Fangming Li -/ import Mathlib.Algebra.DirectSum.Algebra import Mathlib.Algebra.DirectSum.Decomposition import Mathlib.Algebra.DirectSum.Internal import Mathlib.Algebra.DirectSum.Ring /-! # Internally-graded rings and algebras This file defines the typeclass `GradedAlgebra 𝒜`, for working with an algebra `A` that is internally graded by a collection of submodules `𝒜 : ι → Submodule R A`. See the docstring of that typeclass for more information. ## Main definitions * `GradedRing 𝒜`: the typeclass, which is a combination of `SetLike.GradedMonoid`, and `DirectSum.Decomposition 𝒜`. * `GradedAlgebra 𝒜`: A convenience alias for `GradedRing` when `𝒜` is a family of submodules. * `DirectSum.decomposeRingEquiv 𝒜 : A ≃ₐ[R] ⨁ i, 𝒜 i`, a more bundled version of `DirectSum.decompose 𝒜`. * `DirectSum.decomposeAlgEquiv 𝒜 : A ≃ₐ[R] ⨁ i, 𝒜 i`, a more bundled version of `DirectSum.decompose 𝒜`. * `GradedAlgebra.proj 𝒜 i` is the linear map from `A` to its degree `i : ι` component, such that `proj 𝒜 i x = decompose 𝒜 x i`. ## Implementation notes For now, we do not have internally-graded semirings and internally-graded rings; these can be represented with `𝒜 : ι → Submodule ℕ A` and `𝒜 : ι → Submodule ℤ A` respectively, since all `Semiring`s are ℕ-algebras via `Semiring.toNatAlgebra`, and all `Ring`s are `ℤ`-algebras via `Ring.toIntAlgebra`. ## Tags graded algebra, graded ring, graded semiring, decomposition -/ open DirectSum variable {ι R A σ : Type*} section GradedRing variable [DecidableEq ι] [AddMonoid ι] [CommSemiring R] [Semiring A] [Algebra R A] variable [SetLike σ A] [AddSubmonoidClass σ A] (𝒜 : ι → σ) open DirectSum /-- An internally-graded `R`-algebra `A` is one that can be decomposed into a collection of `Submodule R A`s indexed by `ι` such that the canonical map `A → ⨁ i, 𝒜 i` is bijective and respects multiplication, i.e. the product of an element of degree `i` and an element of degree `j` is an element of degree `i + j`. Note that the fact that `A` is internally-graded, `GradedAlgebra 𝒜`, implies an externally-graded algebra structure `DirectSum.GAlgebra R (fun i ↦ ↥(𝒜 i))`, which in turn makes available an `Algebra R (⨁ i, 𝒜 i)` instance. -/ class GradedRing (𝒜 : ι → σ) extends SetLike.GradedMonoid 𝒜, DirectSum.Decomposition 𝒜 variable [GradedRing 𝒜] namespace DirectSum /-- If `A` is graded by `ι` with degree `i` component `𝒜 i`, then it is isomorphic as a ring to a direct sum of components. -/ def decomposeRingEquiv : A ≃+* ⨁ i, 𝒜 i := RingEquiv.symm { (decomposeAddEquiv 𝒜).symm with map_mul' := (coeRingHom 𝒜).map_mul } @[simp] theorem decompose_one : decompose 𝒜 (1 : A) = 1 := map_one (decomposeRingEquiv 𝒜) @[simp] theorem decompose_symm_one : (decompose 𝒜).symm 1 = (1 : A) := map_one (decomposeRingEquiv 𝒜).symm @[simp] theorem decompose_mul (x y : A) : decompose 𝒜 (x * y) = decompose 𝒜 x * decompose 𝒜 y := map_mul (decomposeRingEquiv 𝒜) x y @[simp] theorem decompose_symm_mul (x y : ⨁ i, 𝒜 i) : (decompose 𝒜).symm (x * y) = (decompose 𝒜).symm x * (decompose 𝒜).symm y := map_mul (decomposeRingEquiv 𝒜).symm x y end DirectSum /-- The projection maps of a graded ring -/ def GradedRing.proj (i : ι) : A →+ A := (AddSubmonoidClass.subtype (𝒜 i)).comp <| (DFinsupp.evalAddMonoidHom i).comp <| RingHom.toAddMonoidHom <| RingEquiv.toRingHom <| DirectSum.decomposeRingEquiv 𝒜 @[simp] theorem GradedRing.proj_apply (i : ι) (r : A) : GradedRing.proj 𝒜 i r = (decompose 𝒜 r : ⨁ i, 𝒜 i) i := rfl theorem GradedRing.proj_recompose (a : ⨁ i, 𝒜 i) (i : ι) : GradedRing.proj 𝒜 i ((decompose 𝒜).symm a) = (decompose 𝒜).symm (DirectSum.of _ i (a i)) := by rw [GradedRing.proj_apply, decompose_symm_of, Equiv.apply_symm_apply] theorem GradedRing.mem_support_iff [∀ (i) (x : 𝒜 i), Decidable (x ≠ 0)] (r : A) (i : ι) : i ∈ (decompose 𝒜 r).support ↔ GradedRing.proj 𝒜 i r ≠ 0 := DFinsupp.mem_support_iff.trans ZeroMemClass.coe_eq_zero.not.symm end GradedRing section AddCancelMonoid open DirectSum variable [DecidableEq ι] [Semiring A] [SetLike σ A] [AddSubmonoidClass σ A] (𝒜 : ι → σ) variable {i j : ι} namespace DirectSum theorem coe_decompose_mul_add_of_left_mem [AddLeftCancelMonoid ι] [GradedRing 𝒜] {a b : A} (a_mem : a ∈ 𝒜 i) : (decompose 𝒜 (a * b) (i + j) : A) = a * decompose 𝒜 b j := by lift a to 𝒜 i using a_mem rw [decompose_mul, decompose_coe, coe_of_mul_apply_add] theorem coe_decompose_mul_add_of_right_mem [AddRightCancelMonoid ι] [GradedRing 𝒜] {a b : A} (b_mem : b ∈ 𝒜 j) : (decompose 𝒜 (a * b) (i + j) : A) = decompose 𝒜 a i * b := by lift b to 𝒜 j using b_mem rw [decompose_mul, decompose_coe, coe_mul_of_apply_add] theorem decompose_mul_add_left [AddLeftCancelMonoid ι] [GradedRing 𝒜] (a : 𝒜 i) {b : A} : decompose 𝒜 (↑a * b) (i + j) = @GradedMonoid.GMul.mul ι (fun i => 𝒜 i) _ _ _ _ a (decompose 𝒜 b j) := Subtype.ext <| coe_decompose_mul_add_of_left_mem 𝒜 a.2 theorem decompose_mul_add_right [AddRightCancelMonoid ι] [GradedRing 𝒜] {a : A} (b : 𝒜 j) : decompose 𝒜 (a * ↑b) (i + j) = @GradedMonoid.GMul.mul ι (fun i => 𝒜 i) _ _ _ _ (decompose 𝒜 a i) b := Subtype.ext <| coe_decompose_mul_add_of_right_mem 𝒜 b.2 end DirectSum end AddCancelMonoid section GradedAlgebra variable [DecidableEq ι] [AddMonoid ι] [CommSemiring R] [Semiring A] [Algebra R A] variable (𝒜 : ι → Submodule R A) /-- A special case of `GradedRing` with `σ = Submodule R A`. This is useful both because it can avoid typeclass search, and because it provides a more concise name. -/ abbrev GradedAlgebra := GradedRing 𝒜 /-- A helper to construct a `GradedAlgebra` when the `SetLike.GradedMonoid` structure is already available. This makes the `left_inv` condition easier to prove, and phrases the `right_inv` condition in a way that allows custom `@[ext]` lemmas to apply. See note [reducible non-instances]. -/ abbrev GradedAlgebra.ofAlgHom [SetLike.GradedMonoid 𝒜] (decompose : A →ₐ[R] ⨁ i, 𝒜 i) (right_inv : (DirectSum.coeAlgHom 𝒜).comp decompose = AlgHom.id R A) (left_inv : ∀ i (x : 𝒜 i), decompose (x : A) = DirectSum.of (fun i => ↥(𝒜 i)) i x) : GradedAlgebra 𝒜 where decompose' := decompose left_inv := AlgHom.congr_fun right_inv right_inv := by suffices decompose.comp (DirectSum.coeAlgHom 𝒜) = AlgHom.id _ _ from AlgHom.congr_fun this ext i x : 2 exact (decompose.congr_arg <| DirectSum.coeAlgHom_of _ _ _).trans (left_inv i x) variable [GradedAlgebra 𝒜] namespace DirectSum /-- If `A` is graded by `ι` with degree `i` component `𝒜 i`, then it is isomorphic as an algebra to a direct sum of components. -/ -- Porting note: deleted [simps] and added the corresponding lemmas by hand def decomposeAlgEquiv : A ≃ₐ[R] ⨁ i, 𝒜 i := AlgEquiv.symm { (decomposeAddEquiv 𝒜).symm with map_mul' := map_mul (coeAlgHom 𝒜) commutes' := (coeAlgHom 𝒜).commutes } @[simp] lemma decomposeAlgEquiv_apply (a : A) : decomposeAlgEquiv 𝒜 a = decompose 𝒜 a := rfl @[simp] lemma decomposeAlgEquiv_symm_apply (a : ⨁ i, 𝒜 i) : (decomposeAlgEquiv 𝒜).symm a = (decompose 𝒜).symm a := rfl @[simp] lemma decompose_algebraMap (r : R) : decompose 𝒜 (algebraMap R A r) = algebraMap R (⨁ i, 𝒜 i) r := (decomposeAlgEquiv 𝒜).commutes r @[simp] lemma decompose_symm_algebraMap (r : R) : (decompose 𝒜).symm (algebraMap R (⨁ i, 𝒜 i) r) = algebraMap R A r := (decomposeAlgEquiv 𝒜).symm.commutes r end DirectSum open DirectSum /-- The projection maps of graded algebra-/ def GradedAlgebra.proj (𝒜 : ι → Submodule R A) [GradedAlgebra 𝒜] (i : ι) : A →ₗ[R] A := (𝒜 i).subtype.comp <| (DFinsupp.lapply i).comp <| (decomposeAlgEquiv 𝒜).toAlgHom.toLinearMap @[simp] theorem GradedAlgebra.proj_apply (i : ι) (r : A) : GradedAlgebra.proj 𝒜 i r = (decompose 𝒜 r : ⨁ i, 𝒜 i) i := rfl theorem GradedAlgebra.proj_recompose (a : ⨁ i, 𝒜 i) (i : ι) : GradedAlgebra.proj 𝒜 i ((decompose 𝒜).symm a) = (decompose 𝒜).symm (of _ i (a i)) := by rw [GradedAlgebra.proj_apply, decompose_symm_of, Equiv.apply_symm_apply] theorem GradedAlgebra.mem_support_iff [DecidableEq A] (r : A) (i : ι) : i ∈ (decompose 𝒜 r).support ↔ GradedAlgebra.proj 𝒜 i r ≠ 0 := DFinsupp.mem_support_iff.trans Submodule.coe_eq_zero.not.symm end GradedAlgebra section CanonicalOrder open SetLike.GradedMonoid DirectSum variable [Semiring A] [DecidableEq ι] variable [CanonicallyOrderedAddCommMonoid ι] variable [SetLike σ A] [AddSubmonoidClass σ A] (𝒜 : ι → σ) [GradedRing 𝒜] /-- If `A` is graded by a canonically ordered add monoid, then the projection map `x ↦ x₀` is a ring homomorphism. -/ @[simps] def GradedRing.projZeroRingHom : A →+* A where toFun a := decompose 𝒜 a 0 map_one' := -- Porting note: qualified `one_mem` decompose_of_mem_same 𝒜 SetLike.GradedOne.one_mem map_zero' := by simp only -- Porting note: added rw [decompose_zero] rfl map_add' _ _ := by simp only -- Porting note: added rw [decompose_add] rfl map_mul' := by refine DirectSum.Decomposition.inductionOn 𝒜 (fun x => ?_) ?_ ?_ · simp only [zero_mul, decompose_zero, zero_apply, ZeroMemClass.coe_zero] · rintro i ⟨c, hc⟩ refine DirectSum.Decomposition.inductionOn 𝒜 ?_ ?_ ?_ · simp only [mul_zero, decompose_zero, zero_apply, ZeroMemClass.coe_zero] · rintro j ⟨c', hc'⟩ simp only [Subtype.coe_mk] by_cases h : i + j = 0 · rw [decompose_of_mem_same 𝒜 (show c * c' ∈ 𝒜 0 from h ▸ SetLike.GradedMul.mul_mem hc hc'), decompose_of_mem_same 𝒜 (show c ∈ 𝒜 0 from (add_eq_zero_iff.mp h).1 ▸ hc), decompose_of_mem_same 𝒜 (show c' ∈ 𝒜 0 from (add_eq_zero_iff.mp h).2 ▸ hc')] · rw [decompose_of_mem_ne 𝒜 (SetLike.GradedMul.mul_mem hc hc') h] cases' show i ≠ 0 ∨ j ≠ 0 by rwa [add_eq_zero_iff, not_and_or] at h with h' h' · simp only [decompose_of_mem_ne 𝒜 hc h', zero_mul] · simp only [decompose_of_mem_ne 𝒜 hc' h', mul_zero] · intro _ _ hd he simp only at hd he -- Porting note: added simp only [mul_add, decompose_add, add_apply, AddMemClass.coe_add, hd, he] · rintro _ _ ha hb _ simp only at ha hb -- Porting note: added simp only [add_mul, decompose_add, add_apply, AddMemClass.coe_add, ha, hb] section GradeZero /-- The ring homomorphism from `A` to `𝒜 0` sending every `a : A` to `a₀`. -/ def GradedRing.projZeroRingHom' : A →+* 𝒜 0 := ((GradedRing.projZeroRingHom 𝒜).codRestrict _ fun _x => SetLike.coe_mem _ : A →+* SetLike.GradeZero.subsemiring 𝒜) @[simp] lemma GradedRing.coe_projZeroRingHom'_apply (a : A) : (GradedRing.projZeroRingHom' 𝒜 a : A) = GradedRing.projZeroRingHom 𝒜 a := rfl @[simp] lemma GradedRing.projZeroRingHom'_apply_coe (a : 𝒜 0) : GradedRing.projZeroRingHom' 𝒜 a = a := by ext; simp only [coe_projZeroRingHom'_apply, projZeroRingHom_apply, decompose_coe, of_eq_same] /-- The ring homomorphism `GradedRing.projZeroRingHom' 𝒜` is surjective. -/ lemma GradedRing.projZeroRingHom'_surjective : Function.Surjective (GradedRing.projZeroRingHom' 𝒜) := Function.RightInverse.surjective (GradedRing.projZeroRingHom'_apply_coe 𝒜) end GradeZero variable {a b : A} {n i : ι} namespace DirectSum theorem coe_decompose_mul_of_left_mem_of_not_le (a_mem : a ∈ 𝒜 i) (h : ¬i ≤ n) : (decompose 𝒜 (a * b) n : A) = 0 := by lift a to 𝒜 i using a_mem rwa [decompose_mul, decompose_coe, coe_of_mul_apply_of_not_le] theorem coe_decompose_mul_of_right_mem_of_not_le (b_mem : b ∈ 𝒜 i) (h : ¬i ≤ n) : (decompose 𝒜 (a * b) n : A) = 0 := by lift b to 𝒜 i using b_mem rwa [decompose_mul, decompose_coe, coe_mul_of_apply_of_not_le] variable [Sub ι] [OrderedSub ι] [ContravariantClass ι ι (· + ·) (· ≤ ·)] theorem coe_decompose_mul_of_left_mem_of_le (a_mem : a ∈ 𝒜 i) (h : i ≤ n) : (decompose 𝒜 (a * b) n : A) = a * decompose 𝒜 b (n - i) := by lift a to 𝒜 i using a_mem rwa [decompose_mul, decompose_coe, coe_of_mul_apply_of_le] theorem coe_decompose_mul_of_right_mem_of_le (b_mem : b ∈ 𝒜 i) (h : i ≤ n) : (decompose 𝒜 (a * b) n : A) = decompose 𝒜 a (n - i) * b := by lift b to 𝒜 i using b_mem rwa [decompose_mul, decompose_coe, coe_mul_of_apply_of_le] theorem coe_decompose_mul_of_left_mem (n) [Decidable (i ≤ n)] (a_mem : a ∈ 𝒜 i) : (decompose 𝒜 (a * b) n : A) = if i ≤ n then a * decompose 𝒜 b (n - i) else 0 := by lift a to 𝒜 i using a_mem rw [decompose_mul, decompose_coe, coe_of_mul_apply] theorem coe_decompose_mul_of_right_mem (n) [Decidable (i ≤ n)] (b_mem : b ∈ 𝒜 i) : (decompose 𝒜 (a * b) n : A) = if i ≤ n then decompose 𝒜 a (n - i) * b else 0 := by lift b to 𝒜 i using b_mem rw [decompose_mul, decompose_coe, coe_mul_of_apply] end DirectSum end CanonicalOrder namespace DirectSum.IsInternal variable {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] [Algebra R A] variable {ι : Type*} [DecidableEq ι] [AddMonoid ι] variable {M : ι → Submodule R A} [SetLike.GradedMonoid M] -- The following lines were given on Zulip by Adam Topaz /-- The canonical isomorphism of an internal direct sum with the ambient algebra -/ noncomputable def coeAlgEquiv (hM : DirectSum.IsInternal M) : (DirectSum ι fun i => ↥(M i)) ≃ₐ[R] A := { RingEquiv.ofBijective (DirectSum.coeAlgHom M) hM with commutes' := fun r => by simp } /-- Given an `R`-algebra `A` and a family `ι → Submodule R A` of submodules parameterized by an additive monoid `ι` and statisfying `SetLike.GradedMonoid M` (essentially, is multiplicative) such that `DirectSum.IsInternal M` (`A` is the direct sum of the `M i`), we endow `A` with the structure of a graded algebra. The submodules are the *homogeneous* parts. -/ noncomputable def gradedAlgebra (hM : DirectSum.IsInternal M) : GradedAlgebra M := { (inferInstance : SetLike.GradedMonoid M) with decompose' := hM.coeAlgEquiv.symm left_inv := hM.coeAlgEquiv.symm.left_inv right_inv := hM.coeAlgEquiv.left_inv } end DirectSum.IsInternal
RingTheory\GradedAlgebra\HomogeneousIdeal.lean
/- Copyright (c) 2021 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jujian Zhang, Eric Wieser -/ import Mathlib.RingTheory.Ideal.Basic import Mathlib.RingTheory.Ideal.Maps import Mathlib.LinearAlgebra.Finsupp import Mathlib.RingTheory.GradedAlgebra.Basic /-! # Homogeneous ideals of a graded algebra This file defines homogeneous ideals of `GradedRing 𝒜` where `𝒜 : ι → Submodule R A` and operations on them. ## Main definitions For any `I : Ideal A`: * `Ideal.IsHomogeneous 𝒜 I`: The property that an ideal is closed under `GradedRing.proj`. * `HomogeneousIdeal 𝒜`: The structure extending ideals which satisfy `Ideal.IsHomogeneous`. * `Ideal.homogeneousCore I 𝒜`: The largest homogeneous ideal smaller than `I`. * `Ideal.homogeneousHull I 𝒜`: The smallest homogeneous ideal larger than `I`. ## Main statements * `HomogeneousIdeal.completeLattice`: `Ideal.IsHomogeneous` is preserved by `⊥`, `⊤`, `⊔`, `⊓`, `⨆`, `⨅`, and so the subtype of homogeneous ideals inherits a complete lattice structure. * `Ideal.homogeneousCore.gi`: `Ideal.homogeneousCore` forms a galois insertion with coercion. * `Ideal.homogeneousHull.gi`: `Ideal.homogeneousHull` forms a galois insertion with coercion. ## Implementation notes We introduce `Ideal.homogeneousCore'` earlier than might be expected so that we can get access to `Ideal.IsHomogeneous.iff_exists` as quickly as possible. ## Tags graded algebra, homogeneous -/ open SetLike DirectSum Set open Pointwise DirectSum variable {ι σ R A : Type*} section HomogeneousDef variable [Semiring A] variable [SetLike σ A] [AddSubmonoidClass σ A] (𝒜 : ι → σ) variable [DecidableEq ι] [AddMonoid ι] [GradedRing 𝒜] variable (I : Ideal A) /-- An `I : Ideal A` is homogeneous if for every `r ∈ I`, all homogeneous components of `r` are in `I`. -/ def Ideal.IsHomogeneous : Prop := ∀ (i : ι) ⦃r : A⦄, r ∈ I → (DirectSum.decompose 𝒜 r i : A) ∈ I theorem Ideal.IsHomogeneous.mem_iff {I} (hI : Ideal.IsHomogeneous 𝒜 I) {x} : x ∈ I ↔ ∀ i, (decompose 𝒜 x i : A) ∈ I := by classical refine ⟨fun hx i ↦ hI i hx, fun hx ↦ ?_⟩ rw [← DirectSum.sum_support_decompose 𝒜 x] exact Ideal.sum_mem _ (fun i _ ↦ hx i) /-- For any `Semiring A`, we collect the homogeneous ideals of `A` into a type. -/ structure HomogeneousIdeal extends Submodule A A where is_homogeneous' : Ideal.IsHomogeneous 𝒜 toSubmodule variable {𝒜} /-- Converting a homogeneous ideal to an ideal. -/ def HomogeneousIdeal.toIdeal (I : HomogeneousIdeal 𝒜) : Ideal A := I.toSubmodule theorem HomogeneousIdeal.isHomogeneous (I : HomogeneousIdeal 𝒜) : I.toIdeal.IsHomogeneous 𝒜 := I.is_homogeneous' theorem HomogeneousIdeal.toIdeal_injective : Function.Injective (HomogeneousIdeal.toIdeal : HomogeneousIdeal 𝒜 → Ideal A) := fun ⟨x, hx⟩ ⟨y, hy⟩ => fun (h : x = y) => by simp [h] instance HomogeneousIdeal.setLike : SetLike (HomogeneousIdeal 𝒜) A where coe I := I.toIdeal coe_injective' _ _ h := HomogeneousIdeal.toIdeal_injective <| SetLike.coe_injective h @[ext] theorem HomogeneousIdeal.ext {I J : HomogeneousIdeal 𝒜} (h : I.toIdeal = J.toIdeal) : I = J := HomogeneousIdeal.toIdeal_injective h theorem HomogeneousIdeal.ext' {I J : HomogeneousIdeal 𝒜} (h : ∀ i, ∀ x ∈ 𝒜 i, x ∈ I ↔ x ∈ J) : I = J := by ext rw [I.isHomogeneous.mem_iff, J.isHomogeneous.mem_iff] apply forall_congr' exact fun i ↦ h i _ (decompose 𝒜 _ i).2 @[simp] theorem HomogeneousIdeal.mem_iff {I : HomogeneousIdeal 𝒜} {x : A} : x ∈ I.toIdeal ↔ x ∈ I := Iff.rfl end HomogeneousDef section HomogeneousCore variable [Semiring A] variable [SetLike σ A] (𝒜 : ι → σ) variable (I : Ideal A) /-- For any `I : Ideal A`, not necessarily homogeneous, `I.homogeneousCore' 𝒜` is the largest homogeneous ideal of `A` contained in `I`, as an ideal. -/ def Ideal.homogeneousCore' (I : Ideal A) : Ideal A := Ideal.span ((↑) '' (((↑) : Subtype (Homogeneous 𝒜) → A) ⁻¹' I)) theorem Ideal.homogeneousCore'_mono : Monotone (Ideal.homogeneousCore' 𝒜) := fun _ _ I_le_J => Ideal.span_mono <| Set.image_subset _ fun _ => @I_le_J _ theorem Ideal.homogeneousCore'_le : I.homogeneousCore' 𝒜 ≤ I := Ideal.span_le.2 <| image_preimage_subset _ _ end HomogeneousCore section IsHomogeneousIdealDefs variable [Semiring A] variable [SetLike σ A] [AddSubmonoidClass σ A] (𝒜 : ι → σ) variable [DecidableEq ι] [AddMonoid ι] [GradedRing 𝒜] variable (I : Ideal A) theorem Ideal.isHomogeneous_iff_forall_subset : I.IsHomogeneous 𝒜 ↔ ∀ i, (I : Set A) ⊆ GradedRing.proj 𝒜 i ⁻¹' I := Iff.rfl theorem Ideal.isHomogeneous_iff_subset_iInter : I.IsHomogeneous 𝒜 ↔ (I : Set A) ⊆ ⋂ i, GradedRing.proj 𝒜 i ⁻¹' ↑I := subset_iInter_iff.symm theorem Ideal.mul_homogeneous_element_mem_of_mem {I : Ideal A} (r x : A) (hx₁ : Homogeneous 𝒜 x) (hx₂ : x ∈ I) (j : ι) : GradedRing.proj 𝒜 j (r * x) ∈ I := by classical rw [← DirectSum.sum_support_decompose 𝒜 r, Finset.sum_mul, map_sum] apply Ideal.sum_mem intro k _ obtain ⟨i, hi⟩ := hx₁ have mem₁ : (DirectSum.decompose 𝒜 r k : A) * x ∈ 𝒜 (k + i) := GradedMul.mul_mem (SetLike.coe_mem _) hi erw [GradedRing.proj_apply, DirectSum.decompose_of_mem 𝒜 mem₁, coe_of_apply] split_ifs · exact I.mul_mem_left _ hx₂ · exact I.zero_mem theorem Ideal.homogeneous_span (s : Set A) (h : ∀ x ∈ s, Homogeneous 𝒜 x) : (Ideal.span s).IsHomogeneous 𝒜 := by rintro i r hr rw [Ideal.span, Finsupp.span_eq_range_total] at hr rw [LinearMap.mem_range] at hr obtain ⟨s, rfl⟩ := hr rw [Finsupp.total_apply, Finsupp.sum, decompose_sum, DFinsupp.finset_sum_apply, AddSubmonoidClass.coe_finset_sum] refine Ideal.sum_mem _ ?_ rintro z hz1 rw [smul_eq_mul] refine Ideal.mul_homogeneous_element_mem_of_mem 𝒜 (s z) z ?_ ?_ i · rcases z with ⟨z, hz2⟩ apply h _ hz2 · exact Ideal.subset_span z.2 /-- For any `I : Ideal A`, not necessarily homogeneous, `I.homogeneousCore' 𝒜` is the largest homogeneous ideal of `A` contained in `I`. -/ def Ideal.homogeneousCore : HomogeneousIdeal 𝒜 := ⟨Ideal.homogeneousCore' 𝒜 I, Ideal.homogeneous_span _ _ fun _ h => by have := Subtype.image_preimage_coe (setOf (Homogeneous 𝒜)) (I : Set A) exact (cast congr(_ ∈ $this) h).1⟩ theorem Ideal.homogeneousCore_mono : Monotone (Ideal.homogeneousCore 𝒜) := Ideal.homogeneousCore'_mono 𝒜 theorem Ideal.toIdeal_homogeneousCore_le : (I.homogeneousCore 𝒜).toIdeal ≤ I := Ideal.homogeneousCore'_le 𝒜 I variable {𝒜 I} theorem Ideal.mem_homogeneousCore_of_homogeneous_of_mem {x : A} (h : SetLike.Homogeneous 𝒜 x) (hmem : x ∈ I) : x ∈ I.homogeneousCore 𝒜 := Ideal.subset_span ⟨⟨x, h⟩, hmem, rfl⟩ theorem Ideal.IsHomogeneous.toIdeal_homogeneousCore_eq_self (h : I.IsHomogeneous 𝒜) : (I.homogeneousCore 𝒜).toIdeal = I := by apply le_antisymm (I.homogeneousCore'_le 𝒜) _ intro x hx classical rw [← DirectSum.sum_support_decompose 𝒜 x] exact Ideal.sum_mem _ fun j _ => Ideal.subset_span ⟨⟨_, homogeneous_coe _⟩, h _ hx, rfl⟩ @[simp] theorem HomogeneousIdeal.toIdeal_homogeneousCore_eq_self (I : HomogeneousIdeal 𝒜) : I.toIdeal.homogeneousCore 𝒜 = I := by ext1 convert Ideal.IsHomogeneous.toIdeal_homogeneousCore_eq_self I.isHomogeneous variable (𝒜 I) theorem Ideal.IsHomogeneous.iff_eq : I.IsHomogeneous 𝒜 ↔ (I.homogeneousCore 𝒜).toIdeal = I := ⟨fun hI => hI.toIdeal_homogeneousCore_eq_self, fun hI => hI ▸ (Ideal.homogeneousCore 𝒜 I).2⟩ theorem Ideal.IsHomogeneous.iff_exists : I.IsHomogeneous 𝒜 ↔ ∃ S : Set (homogeneousSubmonoid 𝒜), I = Ideal.span ((↑) '' S) := by rw [Ideal.IsHomogeneous.iff_eq, eq_comm] exact ((Set.image_preimage.compose (Submodule.gi _ _).gc).exists_eq_l _).symm end IsHomogeneousIdealDefs /-! ### Operations In this section, we show that `Ideal.IsHomogeneous` is preserved by various notations, then use these results to provide these notation typeclasses for `HomogeneousIdeal`. -/ section Operations section Semiring variable [Semiring A] [DecidableEq ι] [AddMonoid ι] variable [SetLike σ A] [AddSubmonoidClass σ A] (𝒜 : ι → σ) [GradedRing 𝒜] namespace Ideal.IsHomogeneous theorem bot : Ideal.IsHomogeneous 𝒜 ⊥ := fun i r hr => by simp only [Ideal.mem_bot] at hr rw [hr, decompose_zero, zero_apply] apply Ideal.zero_mem theorem top : Ideal.IsHomogeneous 𝒜 ⊤ := fun i r _ => by simp only [Submodule.mem_top] variable {𝒜} theorem inf {I J : Ideal A} (HI : I.IsHomogeneous 𝒜) (HJ : J.IsHomogeneous 𝒜) : (I ⊓ J).IsHomogeneous 𝒜 := fun _ _ hr => ⟨HI _ hr.1, HJ _ hr.2⟩ theorem sup {I J : Ideal A} (HI : I.IsHomogeneous 𝒜) (HJ : J.IsHomogeneous 𝒜) : (I ⊔ J).IsHomogeneous 𝒜 := by rw [iff_exists] at HI HJ ⊢ obtain ⟨⟨s₁, rfl⟩, ⟨s₂, rfl⟩⟩ := HI, HJ refine ⟨s₁ ∪ s₂, ?_⟩ rw [Set.image_union] exact (Submodule.span_union _ _).symm protected theorem iSup {κ : Sort*} {f : κ → Ideal A} (h : ∀ i, (f i).IsHomogeneous 𝒜) : (⨆ i, f i).IsHomogeneous 𝒜 := by simp_rw [iff_exists] at h ⊢ choose s hs using h refine ⟨⋃ i, s i, ?_⟩ simp_rw [Set.image_iUnion, Ideal.span_iUnion] congr exact funext hs protected theorem iInf {κ : Sort*} {f : κ → Ideal A} (h : ∀ i, (f i).IsHomogeneous 𝒜) : (⨅ i, f i).IsHomogeneous 𝒜 := by intro i x hx simp only [Ideal.mem_iInf] at hx ⊢ exact fun j => h _ _ (hx j) theorem iSup₂ {κ : Sort*} {κ' : κ → Sort*} {f : ∀ i, κ' i → Ideal A} (h : ∀ i j, (f i j).IsHomogeneous 𝒜) : (⨆ (i) (j), f i j).IsHomogeneous 𝒜 := IsHomogeneous.iSup fun i => IsHomogeneous.iSup <| h i theorem iInf₂ {κ : Sort*} {κ' : κ → Sort*} {f : ∀ i, κ' i → Ideal A} (h : ∀ i j, (f i j).IsHomogeneous 𝒜) : (⨅ (i) (j), f i j).IsHomogeneous 𝒜 := IsHomogeneous.iInf fun i => IsHomogeneous.iInf <| h i theorem sSup {ℐ : Set (Ideal A)} (h : ∀ I ∈ ℐ, Ideal.IsHomogeneous 𝒜 I) : (sSup ℐ).IsHomogeneous 𝒜 := by rw [sSup_eq_iSup] exact iSup₂ h theorem sInf {ℐ : Set (Ideal A)} (h : ∀ I ∈ ℐ, Ideal.IsHomogeneous 𝒜 I) : (sInf ℐ).IsHomogeneous 𝒜 := by rw [sInf_eq_iInf] exact iInf₂ h end Ideal.IsHomogeneous variable {𝒜} namespace HomogeneousIdeal instance : PartialOrder (HomogeneousIdeal 𝒜) := SetLike.instPartialOrder instance : Top (HomogeneousIdeal 𝒜) := ⟨⟨⊤, Ideal.IsHomogeneous.top 𝒜⟩⟩ instance : Bot (HomogeneousIdeal 𝒜) := ⟨⟨⊥, Ideal.IsHomogeneous.bot 𝒜⟩⟩ instance : Sup (HomogeneousIdeal 𝒜) := ⟨fun I J => ⟨_, I.isHomogeneous.sup J.isHomogeneous⟩⟩ instance : Inf (HomogeneousIdeal 𝒜) := ⟨fun I J => ⟨_, I.isHomogeneous.inf J.isHomogeneous⟩⟩ instance : SupSet (HomogeneousIdeal 𝒜) := ⟨fun S => ⟨⨆ s ∈ S, toIdeal s, Ideal.IsHomogeneous.iSup₂ fun s _ => s.isHomogeneous⟩⟩ instance : InfSet (HomogeneousIdeal 𝒜) := ⟨fun S => ⟨⨅ s ∈ S, toIdeal s, Ideal.IsHomogeneous.iInf₂ fun s _ => s.isHomogeneous⟩⟩ @[simp] theorem coe_top : ((⊤ : HomogeneousIdeal 𝒜) : Set A) = univ := rfl @[simp] theorem coe_bot : ((⊥ : HomogeneousIdeal 𝒜) : Set A) = 0 := rfl @[simp] theorem coe_sup (I J : HomogeneousIdeal 𝒜) : ↑(I ⊔ J) = (I + J : Set A) := Submodule.coe_sup _ _ @[simp] theorem coe_inf (I J : HomogeneousIdeal 𝒜) : (↑(I ⊓ J) : Set A) = ↑I ∩ ↑J := rfl @[simp] theorem toIdeal_top : (⊤ : HomogeneousIdeal 𝒜).toIdeal = (⊤ : Ideal A) := rfl @[simp] theorem toIdeal_bot : (⊥ : HomogeneousIdeal 𝒜).toIdeal = (⊥ : Ideal A) := rfl @[simp] theorem toIdeal_sup (I J : HomogeneousIdeal 𝒜) : (I ⊔ J).toIdeal = I.toIdeal ⊔ J.toIdeal := rfl @[simp] theorem toIdeal_inf (I J : HomogeneousIdeal 𝒜) : (I ⊓ J).toIdeal = I.toIdeal ⊓ J.toIdeal := rfl @[simp] theorem toIdeal_sSup (ℐ : Set (HomogeneousIdeal 𝒜)) : (sSup ℐ).toIdeal = ⨆ s ∈ ℐ, toIdeal s := rfl @[simp] theorem toIdeal_sInf (ℐ : Set (HomogeneousIdeal 𝒜)) : (sInf ℐ).toIdeal = ⨅ s ∈ ℐ, toIdeal s := rfl @[simp] theorem toIdeal_iSup {κ : Sort*} (s : κ → HomogeneousIdeal 𝒜) : (⨆ i, s i).toIdeal = ⨆ i, (s i).toIdeal := by rw [iSup, toIdeal_sSup, iSup_range] @[simp] theorem toIdeal_iInf {κ : Sort*} (s : κ → HomogeneousIdeal 𝒜) : (⨅ i, s i).toIdeal = ⨅ i, (s i).toIdeal := by rw [iInf, toIdeal_sInf, iInf_range] -- @[simp] -- Porting note (#10618): simp can prove this theorem toIdeal_iSup₂ {κ : Sort*} {κ' : κ → Sort*} (s : ∀ i, κ' i → HomogeneousIdeal 𝒜) : (⨆ (i) (j), s i j).toIdeal = ⨆ (i) (j), (s i j).toIdeal := by simp_rw [toIdeal_iSup] -- @[simp] -- Porting note (#10618): simp can prove this theorem toIdeal_iInf₂ {κ : Sort*} {κ' : κ → Sort*} (s : ∀ i, κ' i → HomogeneousIdeal 𝒜) : (⨅ (i) (j), s i j).toIdeal = ⨅ (i) (j), (s i j).toIdeal := by simp_rw [toIdeal_iInf] @[simp] theorem eq_top_iff (I : HomogeneousIdeal 𝒜) : I = ⊤ ↔ I.toIdeal = ⊤ := toIdeal_injective.eq_iff.symm @[simp] theorem eq_bot_iff (I : HomogeneousIdeal 𝒜) : I = ⊥ ↔ I.toIdeal = ⊥ := toIdeal_injective.eq_iff.symm instance completeLattice : CompleteLattice (HomogeneousIdeal 𝒜) := toIdeal_injective.completeLattice _ toIdeal_sup toIdeal_inf toIdeal_sSup toIdeal_sInf toIdeal_top toIdeal_bot instance : Add (HomogeneousIdeal 𝒜) := ⟨(· ⊔ ·)⟩ @[simp] theorem toIdeal_add (I J : HomogeneousIdeal 𝒜) : (I + J).toIdeal = I.toIdeal + J.toIdeal := rfl instance : Inhabited (HomogeneousIdeal 𝒜) where default := ⊥ end HomogeneousIdeal end Semiring section CommSemiring variable [CommSemiring A] variable [DecidableEq ι] [AddMonoid ι] variable [SetLike σ A] [AddSubmonoidClass σ A] {𝒜 : ι → σ} [GradedRing 𝒜] variable (I : Ideal A) theorem Ideal.IsHomogeneous.mul {I J : Ideal A} (HI : I.IsHomogeneous 𝒜) (HJ : J.IsHomogeneous 𝒜) : (I * J).IsHomogeneous 𝒜 := by rw [Ideal.IsHomogeneous.iff_exists] at HI HJ ⊢ obtain ⟨⟨s₁, rfl⟩, ⟨s₂, rfl⟩⟩ := HI, HJ rw [Ideal.span_mul_span'] exact ⟨s₁ * s₂, congr_arg _ <| (Set.image_mul (homogeneousSubmonoid 𝒜).subtype).symm⟩ instance : Mul (HomogeneousIdeal 𝒜) where mul I J := ⟨I.toIdeal * J.toIdeal, I.isHomogeneous.mul J.isHomogeneous⟩ @[simp] theorem HomogeneousIdeal.toIdeal_mul (I J : HomogeneousIdeal 𝒜) : (I * J).toIdeal = I.toIdeal * J.toIdeal := rfl end CommSemiring end Operations /-! ### Homogeneous core Note that many results about the homogeneous core came earlier in this file, as they are helpful for building the lattice structure. -/ section homogeneousCore open HomogeneousIdeal variable [Semiring A] [DecidableEq ι] [AddMonoid ι] variable [SetLike σ A] [AddSubmonoidClass σ A] (𝒜 : ι → σ) [GradedRing 𝒜] variable (I : Ideal A) theorem Ideal.homogeneousCore.gc : GaloisConnection toIdeal (Ideal.homogeneousCore 𝒜) := fun I _ => ⟨fun H => I.toIdeal_homogeneousCore_eq_self ▸ Ideal.homogeneousCore_mono 𝒜 H, fun H => le_trans H (Ideal.homogeneousCore'_le _ _)⟩ /-- `toIdeal : HomogeneousIdeal 𝒜 → Ideal A` and `Ideal.homogeneousCore 𝒜` forms a galois coinsertion. -/ def Ideal.homogeneousCore.gi : GaloisCoinsertion toIdeal (Ideal.homogeneousCore 𝒜) where choice I HI := ⟨I, le_antisymm (I.toIdeal_homogeneousCore_le 𝒜) HI ▸ HomogeneousIdeal.isHomogeneous _⟩ gc := Ideal.homogeneousCore.gc 𝒜 u_l_le _ := Ideal.homogeneousCore'_le _ _ choice_eq I H := le_antisymm H (I.toIdeal_homogeneousCore_le _) theorem Ideal.homogeneousCore_eq_sSup : I.homogeneousCore 𝒜 = sSup { J : HomogeneousIdeal 𝒜 | J.toIdeal ≤ I } := Eq.symm <| IsLUB.sSup_eq <| (Ideal.homogeneousCore.gc 𝒜).isGreatest_u.isLUB theorem Ideal.homogeneousCore'_eq_sSup : I.homogeneousCore' 𝒜 = sSup { J : Ideal A | J.IsHomogeneous 𝒜 ∧ J ≤ I } := by refine (IsLUB.sSup_eq ?_).symm apply IsGreatest.isLUB have coe_mono : Monotone (toIdeal : HomogeneousIdeal 𝒜 → Ideal A) := fun x y => id convert coe_mono.map_isGreatest (Ideal.homogeneousCore.gc 𝒜).isGreatest_u using 1 ext x rw [mem_image, mem_setOf_eq] refine ⟨fun hI => ⟨⟨x, hI.1⟩, ⟨hI.2, rfl⟩⟩, ?_⟩ rintro ⟨x, ⟨hx, rfl⟩⟩ exact ⟨x.isHomogeneous, hx⟩ end homogeneousCore /-! ### Homogeneous hulls -/ section HomogeneousHull open HomogeneousIdeal variable [Semiring A] [DecidableEq ι] [AddMonoid ι] variable [SetLike σ A] [AddSubmonoidClass σ A] (𝒜 : ι → σ) [GradedRing 𝒜] variable (I : Ideal A) /-- For any `I : Ideal A`, not necessarily homogeneous, `I.homogeneousHull 𝒜` is the smallest homogeneous ideal containing `I`. -/ def Ideal.homogeneousHull : HomogeneousIdeal 𝒜 := ⟨Ideal.span { r : A | ∃ (i : ι) (x : I), (DirectSum.decompose 𝒜 (x : A) i : A) = r }, by refine Ideal.homogeneous_span _ _ fun x hx => ?_ obtain ⟨i, x, rfl⟩ := hx apply SetLike.homogeneous_coe⟩ theorem Ideal.le_toIdeal_homogeneousHull : I ≤ (Ideal.homogeneousHull 𝒜 I).toIdeal := by intro r hr classical rw [← DirectSum.sum_support_decompose 𝒜 r] refine Ideal.sum_mem _ ?_ intro j _ apply Ideal.subset_span use j use ⟨r, hr⟩ theorem Ideal.homogeneousHull_mono : Monotone (Ideal.homogeneousHull 𝒜) := fun I J I_le_J => by apply Ideal.span_mono rintro r ⟨hr1, ⟨x, hx⟩, rfl⟩ exact ⟨hr1, ⟨⟨x, I_le_J hx⟩, rfl⟩⟩ variable {I 𝒜} theorem Ideal.IsHomogeneous.toIdeal_homogeneousHull_eq_self (h : I.IsHomogeneous 𝒜) : (Ideal.homogeneousHull 𝒜 I).toIdeal = I := by apply le_antisymm _ (Ideal.le_toIdeal_homogeneousHull _ _) apply Ideal.span_le.2 rintro _ ⟨i, x, rfl⟩ exact h _ x.prop @[simp] theorem HomogeneousIdeal.homogeneousHull_toIdeal_eq_self (I : HomogeneousIdeal 𝒜) : I.toIdeal.homogeneousHull 𝒜 = I := HomogeneousIdeal.toIdeal_injective <| I.isHomogeneous.toIdeal_homogeneousHull_eq_self variable (I 𝒜) theorem Ideal.toIdeal_homogeneousHull_eq_iSup : (I.homogeneousHull 𝒜).toIdeal = ⨆ i, Ideal.span (GradedRing.proj 𝒜 i '' I) := by rw [← Ideal.span_iUnion] apply congr_arg Ideal.span _ ext1 simp only [Set.mem_iUnion, Set.mem_image, mem_setOf_eq, GradedRing.proj_apply, SetLike.exists, exists_prop, Subtype.coe_mk, SetLike.mem_coe] theorem Ideal.homogeneousHull_eq_iSup : I.homogeneousHull 𝒜 = ⨆ i, ⟨Ideal.span (GradedRing.proj 𝒜 i '' I), Ideal.homogeneous_span 𝒜 _ (by rintro _ ⟨x, -, rfl⟩ apply SetLike.homogeneous_coe)⟩ := by ext1 rw [Ideal.toIdeal_homogeneousHull_eq_iSup, toIdeal_iSup] rfl end HomogeneousHull section GaloisConnection open HomogeneousIdeal variable [Semiring A] [DecidableEq ι] [AddMonoid ι] variable [SetLike σ A] [AddSubmonoidClass σ A] (𝒜 : ι → σ) [GradedRing 𝒜] theorem Ideal.homogeneousHull.gc : GaloisConnection (Ideal.homogeneousHull 𝒜) toIdeal := fun _ J => ⟨le_trans (Ideal.le_toIdeal_homogeneousHull _ _), fun H => J.homogeneousHull_toIdeal_eq_self ▸ Ideal.homogeneousHull_mono 𝒜 H⟩ /-- `Ideal.homogeneousHull 𝒜` and `toIdeal : HomogeneousIdeal 𝒜 → Ideal A` form a galois insertion. -/ def Ideal.homogeneousHull.gi : GaloisInsertion (Ideal.homogeneousHull 𝒜) toIdeal where choice I H := ⟨I, le_antisymm H (I.le_toIdeal_homogeneousHull 𝒜) ▸ isHomogeneous _⟩ gc := Ideal.homogeneousHull.gc 𝒜 le_l_u _ := Ideal.le_toIdeal_homogeneousHull _ _ choice_eq I H := le_antisymm (I.le_toIdeal_homogeneousHull 𝒜) H theorem Ideal.homogeneousHull_eq_sInf (I : Ideal A) : Ideal.homogeneousHull 𝒜 I = sInf { J : HomogeneousIdeal 𝒜 | I ≤ J.toIdeal } := Eq.symm <| IsGLB.sInf_eq <| (Ideal.homogeneousHull.gc 𝒜).isLeast_l.isGLB end GaloisConnection section IrrelevantIdeal variable [Semiring A] variable [DecidableEq ι] variable [CanonicallyOrderedAddCommMonoid ι] variable [SetLike σ A] [AddSubmonoidClass σ A] (𝒜 : ι → σ) [GradedRing 𝒜] open GradedRing SetLike.GradedMonoid DirectSum /-- For a graded ring `⨁ᵢ 𝒜ᵢ` graded by a `CanonicallyOrderedAddCommMonoid ι`, the irrelevant ideal refers to `⨁_{i>0} 𝒜ᵢ`, or equivalently `{a | a₀ = 0}`. This definition is used in `Proj` construction where `ι` is always `ℕ` so the irrelevant ideal is simply elements with `0` as 0-th coordinate. # Future work Here in the definition, `ι` is assumed to be `CanonicallyOrderedAddCommMonoid`. However, the notion of irrelevant ideal makes sense in a more general setting by defining it as the ideal of elements with `0` as i-th coordinate for all `i ≤ 0`, i.e. `{a | ∀ (i : ι), i ≤ 0 → aᵢ = 0}`. -/ def HomogeneousIdeal.irrelevant : HomogeneousIdeal 𝒜 := ⟨RingHom.ker (GradedRing.projZeroRingHom 𝒜), fun i r (hr : (decompose 𝒜 r 0 : A) = 0) => by change (decompose 𝒜 (decompose 𝒜 r _ : A) 0 : A) = 0 by_cases h : i = 0 · rw [h, hr, decompose_zero, zero_apply, ZeroMemClass.coe_zero] · rw [decompose_of_mem_ne 𝒜 (SetLike.coe_mem _) h]⟩ @[simp] theorem HomogeneousIdeal.mem_irrelevant_iff (a : A) : a ∈ HomogeneousIdeal.irrelevant 𝒜 ↔ proj 𝒜 0 a = 0 := Iff.rfl @[simp] theorem HomogeneousIdeal.toIdeal_irrelevant : (HomogeneousIdeal.irrelevant 𝒜).toIdeal = RingHom.ker (GradedRing.projZeroRingHom 𝒜) := rfl end IrrelevantIdeal
RingTheory\GradedAlgebra\HomogeneousLocalization.lean
/- Copyright (c) 2022 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jujian Zhang, Eric Wieser -/ import Mathlib.RingTheory.Localization.AtPrime import Mathlib.RingTheory.GradedAlgebra.Basic /-! # Homogeneous Localization ## Notation - `ι` is a commutative monoid; - `R` is a commutative semiring; - `A` is a commutative ring and an `R`-algebra; - `𝒜 : ι → Submodule R A` is the grading of `A`; - `x : Submonoid A` is a submonoid ## Main definitions and results This file constructs the subring of `Aₓ` where the numerator and denominator have the same grading, i.e. `{a/b ∈ Aₓ | ∃ (i : ι), a ∈ 𝒜ᵢ ∧ b ∈ 𝒜ᵢ}`. * `HomogeneousLocalization.NumDenSameDeg`: a structure with a numerator and denominator field where they are required to have the same grading. However `NumDenSameDeg 𝒜 x` cannot have a ring structure for many reasons, for example if `c` is a `NumDenSameDeg`, then generally, `c + (-c)` is not necessarily `0` for degree reasons --- `0` is considered to have grade zero (see `deg_zero`) but `c + (-c)` has the same degree as `c`. To circumvent this, we quotient `NumDenSameDeg 𝒜 x` by the kernel of `c ↦ c.num / c.den`. * `HomogeneousLocalization.NumDenSameDeg.embedding`: for `x : Submonoid A` and any `c : NumDenSameDeg 𝒜 x`, or equivalent a numerator and a denominator of the same degree, we get an element `c.num / c.den` of `Aₓ`. * `HomogeneousLocalization`: `NumDenSameDeg 𝒜 x` quotiented by kernel of `embedding 𝒜 x`. * `HomogeneousLocalization.val`: if `f : HomogeneousLocalization 𝒜 x`, then `f.val` is an element of `Aₓ`. In another word, one can view `HomogeneousLocalization 𝒜 x` as a subring of `Aₓ` through `HomogeneousLocalization.val`. * `HomogeneousLocalization.num`: if `f : HomogeneousLocalization 𝒜 x`, then `f.num : A` is the numerator of `f`. * `HomogeneousLocalization.den`: if `f : HomogeneousLocalization 𝒜 x`, then `f.den : A` is the denominator of `f`. * `HomogeneousLocalization.deg`: if `f : HomogeneousLocalization 𝒜 x`, then `f.deg : ι` is the degree of `f` such that `f.num ∈ 𝒜 f.deg` and `f.den ∈ 𝒜 f.deg` (see `HomogeneousLocalization.num_mem_deg` and `HomogeneousLocalization.den_mem_deg`). * `HomogeneousLocalization.num_mem_deg`: if `f : HomogeneousLocalization 𝒜 x`, then `f.num_mem_deg` is a proof that `f.num ∈ 𝒜 f.deg`. * `HomogeneousLocalization.den_mem_deg`: if `f : HomogeneousLocalization 𝒜 x`, then `f.den_mem_deg` is a proof that `f.den ∈ 𝒜 f.deg`. * `HomogeneousLocalization.eq_num_div_den`: if `f : HomogeneousLocalization 𝒜 x`, then `f.val : Aₓ` is equal to `f.num / f.den`. * `HomogeneousLocalization.localRing`: `HomogeneousLocalization 𝒜 x` is a local ring when `x` is the complement of some prime ideals. * `HomogeneousLocalization.map`: Let `A` and `B` be two graded rings and `g : A → B` a grading preserving ring map. If `P ≤ A` and `Q ≤ B` are submonoids such that `P ≤ g⁻¹(Q)`, then `g` induces a ring map between the homogeneous localization of `A` at `P` and the homogeneous localization of `B` at `Q`. ## References * [Robin Hartshorne, *Algebraic Geometry*][Har77] -/ noncomputable section open DirectSum Pointwise open DirectSum SetLike variable {ι R A : Type*} variable [CommRing R] [CommRing A] [Algebra R A] variable (𝒜 : ι → Submodule R A) variable (x : Submonoid A) local notation "at " x => Localization x namespace HomogeneousLocalization section /-- Let `x` be a submonoid of `A`, then `NumDenSameDeg 𝒜 x` is a structure with a numerator and a denominator with same grading such that the denominator is contained in `x`. -/ -- Porting note(#5171): this linter isn't ported yet. -- @[nolint has_nonempty_instance] structure NumDenSameDeg where deg : ι (num den : 𝒜 deg) den_mem : (den : A) ∈ x end namespace NumDenSameDeg open SetLike.GradedMonoid Submodule variable {𝒜} @[ext] theorem ext {c1 c2 : NumDenSameDeg 𝒜 x} (hdeg : c1.deg = c2.deg) (hnum : (c1.num : A) = c2.num) (hden : (c1.den : A) = c2.den) : c1 = c2 := by rcases c1 with ⟨i1, ⟨n1, hn1⟩, ⟨d1, hd1⟩, h1⟩ rcases c2 with ⟨i2, ⟨n2, hn2⟩, ⟨d2, hd2⟩, h2⟩ dsimp only [Subtype.coe_mk] at * subst hdeg hnum hden congr instance : Neg (NumDenSameDeg 𝒜 x) where neg c := ⟨c.deg, ⟨-c.num, neg_mem c.num.2⟩, c.den, c.den_mem⟩ @[simp] theorem deg_neg (c : NumDenSameDeg 𝒜 x) : (-c).deg = c.deg := rfl @[simp] theorem num_neg (c : NumDenSameDeg 𝒜 x) : ((-c).num : A) = -c.num := rfl @[simp] theorem den_neg (c : NumDenSameDeg 𝒜 x) : ((-c).den : A) = c.den := rfl section SMul variable {α : Type*} [SMul α R] [SMul α A] [IsScalarTower α R A] instance : SMul α (NumDenSameDeg 𝒜 x) where smul m c := ⟨c.deg, m • c.num, c.den, c.den_mem⟩ @[simp] theorem deg_smul (c : NumDenSameDeg 𝒜 x) (m : α) : (m • c).deg = c.deg := rfl @[simp] theorem num_smul (c : NumDenSameDeg 𝒜 x) (m : α) : ((m • c).num : A) = m • c.num := rfl @[simp] theorem den_smul (c : NumDenSameDeg 𝒜 x) (m : α) : ((m • c).den : A) = c.den := rfl end SMul variable [AddCommMonoid ι] [DecidableEq ι] [GradedAlgebra 𝒜] instance : One (NumDenSameDeg 𝒜 x) where one := { deg := 0 -- Porting note: Changed `one_mem` to `GradedOne.one_mem` num := ⟨1, GradedOne.one_mem⟩ den := ⟨1, GradedOne.one_mem⟩ den_mem := Submonoid.one_mem _ } @[simp] theorem deg_one : (1 : NumDenSameDeg 𝒜 x).deg = 0 := rfl @[simp] theorem num_one : ((1 : NumDenSameDeg 𝒜 x).num : A) = 1 := rfl @[simp] theorem den_one : ((1 : NumDenSameDeg 𝒜 x).den : A) = 1 := rfl instance : Zero (NumDenSameDeg 𝒜 x) where zero := ⟨0, 0, ⟨1, GradedOne.one_mem⟩, Submonoid.one_mem _⟩ @[simp] theorem deg_zero : (0 : NumDenSameDeg 𝒜 x).deg = 0 := rfl @[simp] theorem num_zero : (0 : NumDenSameDeg 𝒜 x).num = 0 := rfl @[simp] theorem den_zero : ((0 : NumDenSameDeg 𝒜 x).den : A) = 1 := rfl instance : Mul (NumDenSameDeg 𝒜 x) where mul p q := { deg := p.deg + q.deg -- Porting note: Changed `mul_mem` to `GradedMul.mul_mem` num := ⟨p.num * q.num, GradedMul.mul_mem p.num.prop q.num.prop⟩ den := ⟨p.den * q.den, GradedMul.mul_mem p.den.prop q.den.prop⟩ den_mem := Submonoid.mul_mem _ p.den_mem q.den_mem } @[simp] theorem deg_mul (c1 c2 : NumDenSameDeg 𝒜 x) : (c1 * c2).deg = c1.deg + c2.deg := rfl @[simp] theorem num_mul (c1 c2 : NumDenSameDeg 𝒜 x) : ((c1 * c2).num : A) = c1.num * c2.num := rfl @[simp] theorem den_mul (c1 c2 : NumDenSameDeg 𝒜 x) : ((c1 * c2).den : A) = c1.den * c2.den := rfl instance : Add (NumDenSameDeg 𝒜 x) where add c1 c2 := { deg := c1.deg + c2.deg num := ⟨c1.den * c2.num + c2.den * c1.num, add_mem (GradedMul.mul_mem c1.den.2 c2.num.2) (add_comm c2.deg c1.deg ▸ GradedMul.mul_mem c2.den.2 c1.num.2)⟩ den := ⟨c1.den * c2.den, GradedMul.mul_mem c1.den.2 c2.den.2⟩ den_mem := Submonoid.mul_mem _ c1.den_mem c2.den_mem } @[simp] theorem deg_add (c1 c2 : NumDenSameDeg 𝒜 x) : (c1 + c2).deg = c1.deg + c2.deg := rfl @[simp] theorem num_add (c1 c2 : NumDenSameDeg 𝒜 x) : ((c1 + c2).num : A) = c1.den * c2.num + c2.den * c1.num := rfl @[simp] theorem den_add (c1 c2 : NumDenSameDeg 𝒜 x) : ((c1 + c2).den : A) = c1.den * c2.den := rfl instance : CommMonoid (NumDenSameDeg 𝒜 x) where one := 1 mul := (· * ·) mul_assoc c1 c2 c3 := ext _ (add_assoc _ _ _) (mul_assoc _ _ _) (mul_assoc _ _ _) one_mul c := ext _ (zero_add _) (one_mul _) (one_mul _) mul_one c := ext _ (add_zero _) (mul_one _) (mul_one _) mul_comm c1 c2 := ext _ (add_comm _ _) (mul_comm _ _) (mul_comm _ _) instance : Pow (NumDenSameDeg 𝒜 x) ℕ where pow c n := ⟨n • c.deg, @GradedMonoid.GMonoid.gnpow _ (fun i => ↥(𝒜 i)) _ _ n _ c.num, @GradedMonoid.GMonoid.gnpow _ (fun i => ↥(𝒜 i)) _ _ n _ c.den, by induction' n with n ih · simpa only [Nat.zero_eq, coe_gnpow, pow_zero] using Submonoid.one_mem _ · simpa only [pow_succ, coe_gnpow] using x.mul_mem ih c.den_mem⟩ @[simp] theorem deg_pow (c : NumDenSameDeg 𝒜 x) (n : ℕ) : (c ^ n).deg = n • c.deg := rfl @[simp] theorem num_pow (c : NumDenSameDeg 𝒜 x) (n : ℕ) : ((c ^ n).num : A) = (c.num : A) ^ n := rfl @[simp] theorem den_pow (c : NumDenSameDeg 𝒜 x) (n : ℕ) : ((c ^ n).den : A) = (c.den : A) ^ n := rfl variable (𝒜) /-- For `x : prime ideal of A` and any `p : NumDenSameDeg 𝒜 x`, or equivalent a numerator and a denominator of the same degree, we get an element `p.num / p.den` of `Aₓ`. -/ def embedding (p : NumDenSameDeg 𝒜 x) : at x := Localization.mk p.num ⟨p.den, p.den_mem⟩ end NumDenSameDeg end HomogeneousLocalization /-- For `x : prime ideal of A`, `HomogeneousLocalization 𝒜 x` is `NumDenSameDeg 𝒜 x` modulo the kernel of `embedding 𝒜 x`. This is essentially the subring of `Aₓ` where the numerator and denominator share the same grading. -/ -- Porting note(#5171): this linter isn't ported yet. -- @[nolint has_nonempty_instance] def HomogeneousLocalization : Type _ := Quotient (Setoid.ker <| HomogeneousLocalization.NumDenSameDeg.embedding 𝒜 x) namespace HomogeneousLocalization open HomogeneousLocalization HomogeneousLocalization.NumDenSameDeg variable {𝒜} {x} /-- Construct an element of `HomogeneousLocalization 𝒜 x` from a homogeneous fraction. -/ abbrev mk (y : HomogeneousLocalization.NumDenSameDeg 𝒜 x) : HomogeneousLocalization 𝒜 x := Quotient.mk'' y lemma mk_surjective : Function.Surjective (mk (𝒜 := 𝒜) (x := x)) := Quotient.surjective_Quotient_mk'' /-- View an element of `HomogeneousLocalization 𝒜 x` as an element of `Aₓ` by forgetting that the numerator and denominator are of the same grading. -/ def val (y : HomogeneousLocalization 𝒜 x) : at x := Quotient.liftOn' y (NumDenSameDeg.embedding 𝒜 x) fun _ _ => id @[simp] theorem val_mk (i : NumDenSameDeg 𝒜 x) : val (mk i) = Localization.mk (i.num : A) ⟨i.den, i.den_mem⟩ := rfl variable (x) @[ext] theorem val_injective : Function.Injective (HomogeneousLocalization.val (𝒜 := 𝒜) (x := x)) := fun a b => Quotient.recOnSubsingleton₂' a b fun _ _ h => Quotient.sound' h variable (𝒜) {x} in lemma subsingleton (hx : 0 ∈ x) : Subsingleton (HomogeneousLocalization 𝒜 x) := have := IsLocalization.subsingleton (S := at x) hx (HomogeneousLocalization.val_injective (𝒜 := 𝒜) (x := x)).subsingleton section SMul variable {α : Type*} [SMul α R] [SMul α A] [IsScalarTower α R A] variable [IsScalarTower α A A] instance : SMul α (HomogeneousLocalization 𝒜 x) where smul m := Quotient.map' (m • ·) fun c1 c2 (h : Localization.mk _ _ = Localization.mk _ _) => by change Localization.mk _ _ = Localization.mk _ _ simp only [num_smul, den_smul] convert congr_arg (fun z : at x => m • z) h <;> rw [Localization.smul_mk] @[simp] lemma mk_smul (i : NumDenSameDeg 𝒜 x) (m : α) : mk (m • i) = m • mk i := rfl @[simp] theorem val_smul (n : α) : ∀ y : HomogeneousLocalization 𝒜 x, (n • y).val = n • y.val := Quotient.ind' fun _ ↦ by rw [← mk_smul, val_mk, val_mk, Localization.smul_mk]; rfl theorem val_nsmul (n : ℕ) (y : HomogeneousLocalization 𝒜 x) : (n • y).val = n • y.val := by rw [val_smul, OreLocalization.nsmul_eq_nsmul] theorem val_zsmul (n : ℤ) (y : HomogeneousLocalization 𝒜 x) : (n • y).val = n • y.val := by rw [val_smul, OreLocalization.zsmul_eq_zsmul] end SMul instance : Neg (HomogeneousLocalization 𝒜 x) where neg := Quotient.map' Neg.neg fun c1 c2 (h : Localization.mk _ _ = Localization.mk _ _) => by change Localization.mk _ _ = Localization.mk _ _ simp only [num_neg, den_neg, ← Localization.neg_mk] exact congr_arg Neg.neg h @[simp] lemma mk_neg (i : NumDenSameDeg 𝒜 x) : mk (-i) = -mk i := rfl @[simp] theorem val_neg {x} : ∀ y : HomogeneousLocalization 𝒜 x, (-y).val = -y.val := Quotient.ind' fun y ↦ by rw [← mk_neg, val_mk, val_mk, Localization.neg_mk]; rfl variable [AddCommMonoid ι] [DecidableEq ι] [GradedAlgebra 𝒜] instance hasPow : Pow (HomogeneousLocalization 𝒜 x) ℕ where pow z n := (Quotient.map' (· ^ n) fun c1 c2 (h : Localization.mk _ _ = Localization.mk _ _) => by change Localization.mk _ _ = Localization.mk _ _ simp only [num_pow, den_pow] convert congr_arg (fun z : at x => z ^ n) h <;> erw [Localization.mk_pow] <;> rfl : HomogeneousLocalization 𝒜 x → HomogeneousLocalization 𝒜 x) z @[simp] lemma mk_pow (i : NumDenSameDeg 𝒜 x) (n : ℕ) : mk (i ^ n) = mk i ^ n := rfl instance : Add (HomogeneousLocalization 𝒜 x) where add := Quotient.map₂' (· + ·) fun c1 c2 (h : Localization.mk _ _ = Localization.mk _ _) c3 c4 (h' : Localization.mk _ _ = Localization.mk _ _) => by change Localization.mk _ _ = Localization.mk _ _ simp only [num_add, den_add, ← Localization.add_mk] convert congr_arg₂ (· + ·) h h' <;> erw [Localization.add_mk] <;> rfl @[simp] lemma mk_add (i j : NumDenSameDeg 𝒜 x) : mk (i + j) = mk i + mk j := rfl instance : Sub (HomogeneousLocalization 𝒜 x) where sub z1 z2 := z1 + -z2 instance : Mul (HomogeneousLocalization 𝒜 x) where mul := Quotient.map₂' (· * ·) fun c1 c2 (h : Localization.mk _ _ = Localization.mk _ _) c3 c4 (h' : Localization.mk _ _ = Localization.mk _ _) => by change Localization.mk _ _ = Localization.mk _ _ simp only [num_mul, den_mul] convert congr_arg₂ (· * ·) h h' <;> erw [Localization.mk_mul] <;> rfl @[simp] lemma mk_mul (i j : NumDenSameDeg 𝒜 x) : mk (i * j) = mk i * mk j := rfl instance : One (HomogeneousLocalization 𝒜 x) where one := Quotient.mk'' 1 @[simp] lemma mk_one : mk (1 : NumDenSameDeg 𝒜 x) = 1 := rfl instance : Zero (HomogeneousLocalization 𝒜 x) where zero := Quotient.mk'' 0 @[simp] lemma mk_zero : mk (0 : NumDenSameDeg 𝒜 x) = 0 := rfl theorem zero_eq : (0 : HomogeneousLocalization 𝒜 x) = Quotient.mk'' 0 := rfl theorem one_eq : (1 : HomogeneousLocalization 𝒜 x) = Quotient.mk'' 1 := rfl variable {x} @[simp] theorem val_zero : (0 : HomogeneousLocalization 𝒜 x).val = 0 := Localization.mk_zero _ @[simp] theorem val_one : (1 : HomogeneousLocalization 𝒜 x).val = 1 := Localization.mk_one @[simp] theorem val_add : ∀ y1 y2 : HomogeneousLocalization 𝒜 x, (y1 + y2).val = y1.val + y2.val := Quotient.ind₂' fun y1 y2 ↦ by rw [← mk_add, val_mk, val_mk, val_mk, Localization.add_mk]; rfl @[simp] theorem val_mul : ∀ y1 y2 : HomogeneousLocalization 𝒜 x, (y1 * y2).val = y1.val * y2.val := Quotient.ind₂' fun y1 y2 ↦ by rw [← mk_mul, val_mk, val_mk, val_mk, Localization.mk_mul]; rfl @[simp] theorem val_sub (y1 y2 : HomogeneousLocalization 𝒜 x) : (y1 - y2).val = y1.val - y2.val := by rw [sub_eq_add_neg, ← val_neg, ← val_add]; rfl @[simp] theorem val_pow : ∀ (y : HomogeneousLocalization 𝒜 x) (n : ℕ), (y ^ n).val = y.val ^ n := Quotient.ind' fun y n ↦ by rw [← mk_pow, val_mk, val_mk, Localization.mk_pow]; rfl instance : NatCast (HomogeneousLocalization 𝒜 x) := ⟨Nat.unaryCast⟩ instance : IntCast (HomogeneousLocalization 𝒜 x) := ⟨Int.castDef⟩ @[simp] theorem val_natCast (n : ℕ) : (n : HomogeneousLocalization 𝒜 x).val = n := show val (Nat.unaryCast n) = _ by induction n <;> simp [Nat.unaryCast, *] @[simp] theorem val_intCast (n : ℤ) : (n : HomogeneousLocalization 𝒜 x).val = n := show val (Int.castDef n) = _ by cases n <;> simp [Int.castDef, *] instance homogenousLocalizationCommRing : CommRing (HomogeneousLocalization 𝒜 x) := (HomogeneousLocalization.val_injective x).commRing _ val_zero val_one val_add val_mul val_neg val_sub (val_nsmul x · ·) (val_zsmul x · ·) val_pow val_natCast val_intCast instance homogeneousLocalizationAlgebra : Algebra (HomogeneousLocalization 𝒜 x) (Localization x) where smul p q := p.val * q toFun := val map_one' := val_one map_mul' := val_mul map_zero' := val_zero map_add' := val_add commutes' _ _ := mul_comm _ _ smul_def' _ _ := rfl @[simp] lemma algebraMap_apply (y) : algebraMap (HomogeneousLocalization 𝒜 x) (Localization x) y = y.val := rfl lemma mk_eq_zero_of_num (f : NumDenSameDeg 𝒜 x) (h : f.num = 0) : mk f = 0 := by apply val_injective simp only [val_mk, val_zero, h, ZeroMemClass.coe_zero, Localization.mk_zero] lemma mk_eq_zero_of_den (f : NumDenSameDeg 𝒜 x) (h : f.den = 0) : mk f = 0 := by have := subsingleton 𝒜 (h ▸ f.den_mem) exact Subsingleton.elim _ _ end HomogeneousLocalization namespace HomogeneousLocalization open HomogeneousLocalization HomogeneousLocalization.NumDenSameDeg variable {𝒜} {x} /-- Numerator of an element in `HomogeneousLocalization x`. -/ def num (f : HomogeneousLocalization 𝒜 x) : A := (Quotient.out' f).num /-- Denominator of an element in `HomogeneousLocalization x`. -/ def den (f : HomogeneousLocalization 𝒜 x) : A := (Quotient.out' f).den /-- For an element in `HomogeneousLocalization x`, degree is the natural number `i` such that `𝒜 i` contains both numerator and denominator. -/ def deg (f : HomogeneousLocalization 𝒜 x) : ι := (Quotient.out' f).deg theorem den_mem (f : HomogeneousLocalization 𝒜 x) : f.den ∈ x := (Quotient.out' f).den_mem theorem num_mem_deg (f : HomogeneousLocalization 𝒜 x) : f.num ∈ 𝒜 f.deg := (Quotient.out' f).num.2 theorem den_mem_deg (f : HomogeneousLocalization 𝒜 x) : f.den ∈ 𝒜 f.deg := (Quotient.out' f).den.2 theorem eq_num_div_den (f : HomogeneousLocalization 𝒜 x) : f.val = Localization.mk f.num ⟨f.den, f.den_mem⟩ := congr_arg HomogeneousLocalization.val (Quotient.out_eq' f).symm theorem den_smul_val (f : HomogeneousLocalization 𝒜 x) : f.den • f.val = algebraMap _ _ f.num := by rw [eq_num_div_den, Localization.mk_eq_mk', IsLocalization.smul_mk'] exact IsLocalization.mk'_mul_cancel_left _ ⟨_, _⟩ theorem ext_iff_val (f g : HomogeneousLocalization 𝒜 x) : f = g ↔ f.val = g.val := ⟨congr_arg val, fun e ↦ val_injective x e⟩ section variable [AddCommMonoid ι] [DecidableEq ι] [GradedAlgebra 𝒜] variable (𝒜) (𝔭 : Ideal A) [Ideal.IsPrime 𝔭] /-- Localizing a ring homogeneously at a prime ideal. -/ abbrev AtPrime := HomogeneousLocalization 𝒜 𝔭.primeCompl theorem isUnit_iff_isUnit_val (f : HomogeneousLocalization.AtPrime 𝒜 𝔭) : IsUnit f.val ↔ IsUnit f := by refine ⟨fun h1 ↦ ?_, IsUnit.map (algebraMap _ _)⟩ rcases h1 with ⟨⟨a, b, eq0, eq1⟩, rfl : a = f.val⟩ obtain ⟨f, rfl⟩ := mk_surjective f obtain ⟨b, s, rfl⟩ := IsLocalization.mk'_surjective 𝔭.primeCompl b rw [val_mk, Localization.mk_eq_mk', ← IsLocalization.mk'_mul, IsLocalization.mk'_eq_iff_eq_mul, one_mul, IsLocalization.eq_iff_exists (M := 𝔭.primeCompl)] at eq0 obtain ⟨c, hc : _ = c.1 * (f.den.1 * s.1)⟩ := eq0 have : f.num.1 ∉ 𝔭 := by exact fun h ↦ mul_mem c.2 (mul_mem f.den_mem s.2) (hc ▸ Ideal.mul_mem_left _ c.1 (Ideal.mul_mem_right b _ h)) refine isUnit_of_mul_eq_one _ (Quotient.mk'' ⟨f.1, f.3, f.2, this⟩) ?_ rw [← mk_mul, ext_iff_val, val_mk] simp [mul_comm f.den.1] instance : Nontrivial (HomogeneousLocalization.AtPrime 𝒜 𝔭) := ⟨⟨0, 1, fun r => by simp [ext_iff_val, val_zero, val_one, zero_ne_one] at r⟩⟩ instance localRing : LocalRing (HomogeneousLocalization.AtPrime 𝒜 𝔭) := LocalRing.of_isUnit_or_isUnit_one_sub_self fun a => by simpa only [← isUnit_iff_isUnit_val, val_sub, val_one] using LocalRing.isUnit_or_isUnit_one_sub_self _ end section variable (𝒜) (f : A) /-- Localizing away from powers of `f` homogeneously. -/ abbrev Away := HomogeneousLocalization 𝒜 (Submonoid.powers f) variable [AddCommMonoid ι] [DecidableEq ι] [GradedAlgebra 𝒜] variable {𝒜} {f} theorem Away.eventually_smul_mem {m} (hf : f ∈ 𝒜 m) (z : Away 𝒜 f) : ∀ᶠ n in Filter.atTop, f ^ n • z.val ∈ algebraMap _ _ '' (𝒜 (n • m) : Set A) := by obtain ⟨k, hk : f ^ k = _⟩ := z.den_mem apply Filter.mem_of_superset (Filter.Ici_mem_atTop k) rintro k' (hk' : k ≤ k') simp only [Set.mem_image, SetLike.mem_coe, Set.mem_setOf_eq] by_cases hfk : f ^ k = 0 · refine ⟨0, zero_mem _, ?_⟩ rw [← tsub_add_cancel_of_le hk', map_zero, pow_add, hfk, mul_zero, zero_smul] rw [← tsub_add_cancel_of_le hk', pow_add, mul_smul, hk, den_smul_val, Algebra.smul_def, ← _root_.map_mul] rw [← smul_eq_mul, add_smul, DirectSum.degree_eq_of_mem_mem 𝒜 (SetLike.pow_mem_graded _ hf) (hk.symm ▸ z.den_mem_deg) hfk] exact ⟨_, SetLike.mul_mem_graded (SetLike.pow_mem_graded _ hf) z.num_mem_deg, rfl⟩ end section variable [AddCommMonoid ι] [DecidableEq ι] [GradedAlgebra 𝒜] variable (𝒜) variable {B : Type*} [CommRing B] [Algebra R B] variable (ℬ : ι → Submodule R B) [GradedAlgebra ℬ] variable {P : Submonoid A} {Q : Submonoid B} /-- Let `A, B` be two graded algebras with the same indexing set and `g : A → B` be a graded algebra homomorphism (i.e. `g(Aₘ) ⊆ Bₘ`). Let `P ≤ A` be a submonoid and `Q ≤ B` be a submonoid such that `P ≤ g⁻¹ Q`, then `g` induce a map from the homogeneous localizations `A⁰_P` to the homogeneous localizations `B⁰_Q`. -/ def map (g : A →+* B) (comap_le : P ≤ Q.comap g) (hg : ∀ i, ∀ a ∈ 𝒜 i, g a ∈ ℬ i) : HomogeneousLocalization 𝒜 P →+* HomogeneousLocalization ℬ Q where toFun := Quotient.map' (fun x ↦ ⟨x.1, ⟨_, hg _ _ x.2.2⟩, ⟨_, hg _ _ x.3.2⟩, comap_le x.4⟩) fun x y (e : x.embedding = y.embedding) ↦ by apply_fun IsLocalization.map (Localization Q) g comap_le at e simp_rw [HomogeneousLocalization.NumDenSameDeg.embedding, Localization.mk_eq_mk', IsLocalization.map_mk', ← Localization.mk_eq_mk'] at e exact e map_add' := Quotient.ind₂' fun x y ↦ by simp only [← mk_add, Quotient.map'_mk'', num_add, map_add, map_mul, den_add]; rfl map_mul' := Quotient.ind₂' fun x y ↦ by simp only [← mk_mul, Quotient.map'_mk'', num_mul, map_mul, den_mul]; rfl map_zero' := by simp only [← mk_zero (𝒜 := 𝒜), Quotient.map'_mk'', deg_zero, num_zero, ZeroMemClass.coe_zero, map_zero, den_zero, map_one]; rfl map_one' := by simp only [← mk_one (𝒜 := 𝒜), Quotient.map'_mk'', deg_zero, num_one, ZeroMemClass.coe_zero, map_zero, den_one, map_one]; rfl /-- Let `A` be a graded algebra and `P ≤ Q` be two submonoids, then the homogeneous localization of `A` at `P` embedds into the homogeneous localization of `A` at `Q`. -/ abbrev mapId {P Q : Submonoid A} (h : P ≤ Q) : HomogeneousLocalization 𝒜 P →+* HomogeneousLocalization 𝒜 Q := map 𝒜 𝒜 (RingHom.id _) h (fun _ _ ↦ id) lemma map_mk (g : A →+* B) (comap_le : P ≤ Q.comap g) (hg : ∀ i, ∀ a ∈ 𝒜 i, g a ∈ ℬ i) (x) : map 𝒜 ℬ g comap_le hg (mk x) = mk ⟨x.1, ⟨_, hg _ _ x.2.2⟩, ⟨_, hg _ _ x.3.2⟩, comap_le x.4⟩ := rfl end end HomogeneousLocalization
RingTheory\GradedAlgebra\Noetherian.lean
/- Copyright (c) 2023 Fangming Li. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Fangming Li -/ import Mathlib.RingTheory.Noetherian import Mathlib.RingTheory.GradedAlgebra.Basic /-! # The properties of a graded Noetherian ring. This file proves that the 0-th grade of a Noetherian ring is also a Noetherian ring. -/ variable {ι A σ : Type*} variable [Ring A] [IsNoetherianRing A] variable [DecidableEq ι] [CanonicallyOrderedAddCommMonoid ι] variable [SetLike σ A] [AddSubgroupClass σ A] variable (𝒜 : ι → σ) [GradedRing 𝒜] namespace GradedRing /-- If the internally graded ring `A` is Noetherian, then `𝒜 0` is a Noetherian ring. -/ instance GradeZero.isNoetherianRing : IsNoetherianRing (𝒜 0) := isNoetherianRing_of_surjective A (𝒜 0) (GradedRing.projZeroRingHom' 𝒜) (GradedRing.projZeroRingHom'_surjective 𝒜) end GradedRing
RingTheory\GradedAlgebra\Radical.lean
/- Copyright (c) 2022 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jujian Zhang, Eric Wieser -/ import Mathlib.RingTheory.GradedAlgebra.HomogeneousIdeal /-! This file contains a proof that the radical of any homogeneous ideal is a homogeneous ideal ## Main statements * `Ideal.IsHomogeneous.isPrime_iff`: for any `I : Ideal A`, if `I` is homogeneous, then `I` is prime if and only if `I` is homogeneously prime, i.e. `I ≠ ⊤` and if `x, y` are homogeneous elements such that `x * y ∈ I`, then at least one of `x,y` is in `I`. * `Ideal.IsPrime.homogeneousCore`: for any `I : Ideal A`, if `I` is prime, then `I.homogeneous_core 𝒜` (i.e. the largest homogeneous ideal contained in `I`) is also prime. * `Ideal.IsHomogeneous.radical`: for any `I : Ideal A`, if `I` is homogeneous, then the radical of `I` is homogeneous as well. * `HomogeneousIdeal.radical`: for any `I : HomogeneousIdeal 𝒜`, `I.radical` is the radical of `I` as a `HomogeneousIdeal 𝒜`. ## Implementation details Throughout this file, the indexing type `ι` of grading is assumed to be a `LinearOrderedCancelAddCommMonoid`. This might be stronger than necessary but cancelling property is strictly necessary; for a counterexample of how `Ideal.IsHomogeneous.isPrime_iff` fails for a non-cancellative set see `Counterexamples/HomogeneousPrimeNotPrime.lean`. ## Tags homogeneous, radical -/ open GradedRing DirectSum SetLike Finset variable {ι σ A : Type*} variable [CommRing A] variable [LinearOrderedCancelAddCommMonoid ι] variable [SetLike σ A] [AddSubmonoidClass σ A] {𝒜 : ι → σ} [GradedRing 𝒜] -- Porting note: This proof needs a long time to elaborate theorem Ideal.IsHomogeneous.isPrime_of_homogeneous_mem_or_mem {I : Ideal A} (hI : I.IsHomogeneous 𝒜) (I_ne_top : I ≠ ⊤) (homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I) : Ideal.IsPrime I := ⟨I_ne_top, by intro x y hxy by_contra! rid obtain ⟨rid₁, rid₂⟩ := rid classical /- The idea of the proof is the following : since `x * y ∈ I` and `I` homogeneous, then `proj i (x * y) ∈ I` for any `i : ι`. Then consider two sets `{i ∈ x.support | xᵢ ∉ I}` and `{j ∈ y.support | yⱼ ∉ J}`; let `max₁, max₂` be the maximum of the two sets, then `proj (max₁ + max₂) (x * y) ∈ I`. Then, `proj max₁ x ∉ I` and `proj max₂ j ∉ I` but `proj i x ∈ I` for all `max₁ < i` and `proj j y ∈ I` for all `max₂ < j`. ` proj (max₁ + max₂) (x * y)` `= ∑ {(i, j) ∈ supports | i + j = max₁ + max₂}, xᵢ * yⱼ` `= proj max₁ x * proj max₂ y` ` + ∑ {(i, j) ∈ supports \ {(max₁, max₂)} | i + j = max₁ + max₂}, xᵢ * yⱼ`. This is a contradiction, because both `proj (max₁ + max₂) (x * y) ∈ I` and the sum on the right hand side is in `I` however `proj max₁ x * proj max₂ y` is not in `I`. -/ set set₁ := (decompose 𝒜 x).support.filter (fun i => proj 𝒜 i x ∉ I) with set₁_eq set set₂ := (decompose 𝒜 y).support.filter (fun i => proj 𝒜 i y ∉ I) with set₂_eq have nonempty : ∀ x : A, x ∉ I → ((decompose 𝒜 x).support.filter (fun i => proj 𝒜 i x ∉ I)).Nonempty := by intro x hx rw [filter_nonempty_iff] contrapose! hx simp_rw [proj_apply] at hx rw [← sum_support_decompose 𝒜 x] exact Ideal.sum_mem _ hx set max₁ := set₁.max' (nonempty x rid₁) set max₂ := set₂.max' (nonempty y rid₂) have mem_max₁ : max₁ ∈ set₁ := max'_mem set₁ (nonempty x rid₁) have mem_max₂ : max₂ ∈ set₂ := max'_mem set₂ (nonempty y rid₂) replace hxy : proj 𝒜 (max₁ + max₂) (x * y) ∈ I := hI _ hxy have mem_I : proj 𝒜 max₁ x * proj 𝒜 max₂ y ∈ I := by set antidiag := ((decompose 𝒜 x).support ×ˢ (decompose 𝒜 y).support).filter (fun z : ι × ι => z.1 + z.2 = max₁ + max₂) with ha have mem_antidiag : (max₁, max₂) ∈ antidiag := by simp only [antidiag, add_sum_erase, mem_filter, mem_product] exact ⟨⟨mem_of_mem_filter _ mem_max₁, mem_of_mem_filter _ mem_max₂⟩, trivial⟩ have eq_add_sum := calc proj 𝒜 (max₁ + max₂) (x * y) = ∑ ij ∈ antidiag, proj 𝒜 ij.1 x * proj 𝒜 ij.2 y := by simp_rw [ha, proj_apply, DirectSum.decompose_mul, DirectSum.coe_mul_apply 𝒜] _ = proj 𝒜 max₁ x * proj 𝒜 max₂ y + ∑ ij ∈ antidiag.erase (max₁, max₂), proj 𝒜 ij.1 x * proj 𝒜 ij.2 y := (add_sum_erase _ _ mem_antidiag).symm rw [eq_sub_of_add_eq eq_add_sum.symm] refine Ideal.sub_mem _ hxy (Ideal.sum_mem _ fun z H => ?_) rcases z with ⟨i, j⟩ simp only [antidiag, mem_erase, Prod.mk.inj_iff, Ne, mem_filter, mem_product] at H rcases H with ⟨H₁, ⟨H₂, H₃⟩, H₄⟩ have max_lt : max₁ < i ∨ max₂ < j := by rcases lt_trichotomy max₁ i with (h | rfl | h) · exact Or.inl h · refine False.elim (H₁ ⟨rfl, add_left_cancel H₄⟩) · apply Or.inr have := add_lt_add_right h j rw [H₄] at this exact lt_of_add_lt_add_left this cases' max_lt with max_lt max_lt · -- in this case `max₁ < i`, then `xᵢ ∈ I`; for otherwise `i ∈ set₁` then `i ≤ max₁`. have not_mem : i ∉ set₁ := fun h => lt_irrefl _ ((max'_lt_iff set₁ (nonempty x rid₁)).mp max_lt i h) rw [set₁_eq] at not_mem simp only [not_and, Classical.not_not, Ne, mem_filter] at not_mem exact Ideal.mul_mem_right _ I (not_mem H₂) · -- in this case `max₂ < j`, then `yⱼ ∈ I`; for otherwise `j ∈ set₂`, then `j ≤ max₂`. have not_mem : j ∉ set₂ := fun h => lt_irrefl _ ((max'_lt_iff set₂ (nonempty y rid₂)).mp max_lt j h) rw [set₂_eq] at not_mem simp only [not_and, Classical.not_not, Ne, mem_filter] at not_mem exact Ideal.mul_mem_left I _ (not_mem H₃) have not_mem_I : proj 𝒜 max₁ x * proj 𝒜 max₂ y ∉ I := by have neither_mem : proj 𝒜 max₁ x ∉ I ∧ proj 𝒜 max₂ y ∉ I := by rw [mem_filter] at mem_max₁ mem_max₂ exact ⟨mem_max₁.2, mem_max₂.2⟩ intro _rid cases' homogeneous_mem_or_mem ⟨max₁, SetLike.coe_mem _⟩ ⟨max₂, SetLike.coe_mem _⟩ mem_I with h h · apply neither_mem.1 h · apply neither_mem.2 h exact not_mem_I mem_I⟩ theorem Ideal.IsHomogeneous.isPrime_iff {I : Ideal A} (h : I.IsHomogeneous 𝒜) : I.IsPrime ↔ I ≠ ⊤ ∧ ∀ {x y : A}, SetLike.Homogeneous 𝒜 x → SetLike.Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I := ⟨fun HI => ⟨HI.ne_top, fun _ _ hxy => Ideal.IsPrime.mem_or_mem HI hxy⟩, fun ⟨I_ne_top, homogeneous_mem_or_mem⟩ => h.isPrime_of_homogeneous_mem_or_mem I_ne_top @homogeneous_mem_or_mem⟩ theorem Ideal.IsPrime.homogeneousCore {I : Ideal A} (h : I.IsPrime) : (I.homogeneousCore 𝒜).toIdeal.IsPrime := by apply (Ideal.homogeneousCore 𝒜 I).is_homogeneous'.isPrime_of_homogeneous_mem_or_mem · exact ne_top_of_le_ne_top h.ne_top (Ideal.toIdeal_homogeneousCore_le 𝒜 I) rintro x y hx hy hxy have H := h.mem_or_mem (Ideal.toIdeal_homogeneousCore_le 𝒜 I hxy) refine H.imp ?_ ?_ · exact Ideal.mem_homogeneousCore_of_homogeneous_of_mem hx · exact Ideal.mem_homogeneousCore_of_homogeneous_of_mem hy theorem Ideal.IsHomogeneous.radical_eq {I : Ideal A} (hI : I.IsHomogeneous 𝒜) : I.radical = InfSet.sInf { J | Ideal.IsHomogeneous 𝒜 J ∧ I ≤ J ∧ J.IsPrime } := by rw [Ideal.radical_eq_sInf] apply le_antisymm · exact sInf_le_sInf fun J => And.right · refine sInf_le_sInf_of_forall_exists_le ?_ rintro J ⟨HJ₁, HJ₂⟩ refine ⟨(J.homogeneousCore 𝒜).toIdeal, ?_, J.toIdeal_homogeneousCore_le _⟩ refine ⟨HomogeneousIdeal.isHomogeneous _, ?_, HJ₂.homogeneousCore⟩ exact hI.toIdeal_homogeneousCore_eq_self.symm.trans_le (Ideal.homogeneousCore_mono _ HJ₁) theorem Ideal.IsHomogeneous.radical {I : Ideal A} (h : I.IsHomogeneous 𝒜) : I.radical.IsHomogeneous 𝒜 := by rw [h.radical_eq] exact Ideal.IsHomogeneous.sInf fun _ => And.left /-- The radical of a homogenous ideal, as another homogenous ideal. -/ def HomogeneousIdeal.radical (I : HomogeneousIdeal 𝒜) : HomogeneousIdeal 𝒜 := ⟨I.toIdeal.radical, I.isHomogeneous.radical⟩ @[simp] theorem HomogeneousIdeal.coe_radical (I : HomogeneousIdeal 𝒜) : I.radical.toIdeal = I.toIdeal.radical := rfl
RingTheory\HahnSeries\Addition.lean
/- Copyright (c) 2021 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.RingTheory.HahnSeries.Basic import Mathlib.Algebra.Module.Basic import Mathlib.Algebra.Module.LinearMap.Defs /-! # Additive properties of Hahn series If `Γ` is ordered and `R` has zero, then `HahnSeries Γ R` consists of formal series over `Γ` with coefficients in `R`, whose supports are partially well-ordered. With further structure on `R` and `Γ`, we can add further structure on `HahnSeries Γ R`. When `R` has an addition operation, `HahnSeries Γ R` also has addition by adding coefficients. ## Main Definitions * If `R` is a (commutative) additive monoid or group, then so is `HahnSeries Γ R`. ## References - [J. van der Hoeven, *Operators on Generalized Power Series*][van_der_hoeven] -/ open Finset Function open scoped Classical noncomputable section variable {Γ R : Type*} namespace HahnSeries section Addition variable [PartialOrder Γ] section AddMonoid variable [AddMonoid R] instance : Add (HahnSeries Γ R) where add x y := { coeff := x.coeff + y.coeff isPWO_support' := (x.isPWO_support.union y.isPWO_support).mono (Function.support_add _ _) } instance : AddMonoid (HahnSeries Γ R) where zero := 0 add := (· + ·) nsmul := nsmulRec add_assoc x y z := by ext apply add_assoc zero_add x := by ext apply zero_add add_zero x := by ext apply add_zero @[simp] theorem add_coeff' {x y : HahnSeries Γ R} : (x + y).coeff = x.coeff + y.coeff := rfl theorem add_coeff {x y : HahnSeries Γ R} {a : Γ} : (x + y).coeff a = x.coeff a + y.coeff a := rfl /-- `addOppositeEquiv` is an additive monoid isomorphism between Hahn series over `Γ` with coefficients in the opposite additive monoid `Rᵃᵒᵖ` and the additive opposite of Hahn series over `Γ` with coefficients `R`. -/ @[simps (config := .lemmasOnly)] def addOppositeEquiv : HahnSeries Γ (Rᵃᵒᵖ) ≃+ (HahnSeries Γ R)ᵃᵒᵖ where toFun x := .op ⟨fun a ↦ (x.coeff a).unop, by convert x.isPWO_support; ext; simp⟩ invFun x := ⟨fun a ↦ .op (x.unop.coeff a), by convert x.unop.isPWO_support; ext; simp⟩ left_inv x := by ext; simp right_inv x := by apply AddOpposite.unop_injective ext simp map_add' x y := by apply AddOpposite.unop_injective ext simp @[simp] lemma addOppositeEquiv_support (x : HahnSeries Γ (Rᵃᵒᵖ)) : (addOppositeEquiv x).unop.support = x.support := by ext simp [addOppositeEquiv_apply] @[simp] lemma addOppositeEquiv_symm_support (x : (HahnSeries Γ R)ᵃᵒᵖ) : (addOppositeEquiv.symm x).support = x.unop.support := by rw [← addOppositeEquiv_support, AddEquiv.apply_symm_apply] @[simp] lemma addOppositeEquiv_orderTop (x : HahnSeries Γ (Rᵃᵒᵖ)) : (addOppositeEquiv x).unop.orderTop = x.orderTop := by simp only [orderTop, AddOpposite.unop_op, mk_eq_zero, AddEquivClass.map_eq_zero_iff, addOppositeEquiv_support, ne_eq] simp only [addOppositeEquiv_apply, AddOpposite.unop_op, mk_eq_zero, zero_coeff] simp_rw [HahnSeries.ext_iff, Function.funext_iff] simp only [Pi.zero_apply, AddOpposite.unop_eq_zero_iff, zero_coeff] @[simp] lemma addOppositeEquiv_symm_orderTop (x : (HahnSeries Γ R)ᵃᵒᵖ) : (addOppositeEquiv.symm x).orderTop = x.unop.orderTop := by rw [← addOppositeEquiv_orderTop, AddEquiv.apply_symm_apply] @[simp] lemma addOppositeEquiv_leadingCoeff (x : HahnSeries Γ (Rᵃᵒᵖ)) : (addOppositeEquiv x).unop.leadingCoeff = x.leadingCoeff.unop := by simp only [leadingCoeff, AddOpposite.unop_op, mk_eq_zero, AddEquivClass.map_eq_zero_iff, addOppositeEquiv_support, ne_eq] simp only [addOppositeEquiv_apply, AddOpposite.unop_op, mk_eq_zero, zero_coeff] simp_rw [HahnSeries.ext_iff, Function.funext_iff] simp only [Pi.zero_apply, AddOpposite.unop_eq_zero_iff, zero_coeff] split <;> rfl @[simp] lemma addOppositeEquiv_symm_leadingCoeff (x : (HahnSeries Γ R)ᵃᵒᵖ) : (addOppositeEquiv.symm x).leadingCoeff = .op x.unop.leadingCoeff := by apply AddOpposite.unop_injective rw [← addOppositeEquiv_leadingCoeff, AddEquiv.apply_symm_apply, AddOpposite.unop_op] theorem support_add_subset {x y : HahnSeries Γ R} : support (x + y) ⊆ support x ∪ support y := fun a ha => by rw [mem_support, add_coeff] at ha rw [Set.mem_union, mem_support, mem_support] contrapose! ha rw [ha.1, ha.2, add_zero] protected theorem min_le_min_add {Γ} [LinearOrder Γ] {x y : HahnSeries Γ R} (hx : x ≠ 0) (hy : y ≠ 0) (hxy : x + y ≠ 0) : min (Set.IsWF.min x.isWF_support (support_nonempty_iff.2 hx)) (Set.IsWF.min y.isWF_support (support_nonempty_iff.2 hy)) ≤ Set.IsWF.min (x + y).isWF_support (support_nonempty_iff.2 hxy) := by rw [← Set.IsWF.min_union] exact Set.IsWF.min_le_min_of_subset (support_add_subset (x := x) (y := y)) theorem min_orderTop_le_orderTop_add {Γ} [LinearOrder Γ] {x y : HahnSeries Γ R} : min x.orderTop y.orderTop ≤ (x + y).orderTop := by by_cases hx : x = 0; · simp [hx] by_cases hy : y = 0; · simp [hy] by_cases hxy : x + y = 0; · simp [hxy] rw [orderTop_of_ne hx, orderTop_of_ne hy, orderTop_of_ne hxy, ← WithTop.coe_min, WithTop.coe_le_coe] exact HahnSeries.min_le_min_add hx hy hxy theorem min_order_le_order_add {Γ} [Zero Γ] [LinearOrder Γ] {x y : HahnSeries Γ R} (hxy : x + y ≠ 0) : min x.order y.order ≤ (x + y).order := by by_cases hx : x = 0; · simp [hx] by_cases hy : y = 0; · simp [hy] rw [order_of_ne hx, order_of_ne hy, order_of_ne hxy] exact HahnSeries.min_le_min_add hx hy hxy theorem orderTop_add_eq_left {Γ} [LinearOrder Γ] {x y : HahnSeries Γ R} (hxy : x.orderTop < y.orderTop) : (x + y).orderTop = x.orderTop := by have hx : x ≠ 0 := ne_zero_iff_orderTop.mpr hxy.ne_top let g : Γ := Set.IsWF.min x.isWF_support (support_nonempty_iff.2 hx) have hcxyne : (x + y).coeff g ≠ 0 := by rw [add_coeff, coeff_eq_zero_of_lt_orderTop (lt_of_eq_of_lt (orderTop_of_ne hx).symm hxy), add_zero] exact coeff_orderTop_ne (orderTop_of_ne hx) have hxyx : (x + y).orderTop ≤ x.orderTop := by rw [orderTop_of_ne hx] exact orderTop_le_of_coeff_ne_zero hcxyne exact le_antisymm hxyx (le_of_eq_of_le (min_eq_left_of_lt hxy).symm min_orderTop_le_orderTop_add) theorem orderTop_add_eq_right {Γ} [LinearOrder Γ] {x y : HahnSeries Γ R} (hxy : y.orderTop < x.orderTop) : (x + y).orderTop = y.orderTop := by simpa [← map_add, ← AddOpposite.op_add, hxy] using orderTop_add_eq_left (x := addOppositeEquiv.symm (.op y)) (y := addOppositeEquiv.symm (.op x)) theorem leadingCoeff_add_eq_left {Γ} [LinearOrder Γ] {x y : HahnSeries Γ R} (hxy : x.orderTop < y.orderTop) : (x + y).leadingCoeff = x.leadingCoeff := by have hx : x ≠ 0 := ne_zero_iff_orderTop.mpr hxy.ne_top have ho : (x + y).orderTop = x.orderTop := orderTop_add_eq_left hxy by_cases h : x + y = 0 · rw [h, orderTop_zero] at ho rw [h, orderTop_eq_top_iff.mp ho.symm] · rw [orderTop_of_ne h, orderTop_of_ne hx, WithTop.coe_eq_coe] at ho rw [leadingCoeff_of_ne h, leadingCoeff_of_ne hx, ho, add_coeff, coeff_eq_zero_of_lt_orderTop (lt_of_eq_of_lt (orderTop_of_ne hx).symm hxy), add_zero] theorem leadingCoeff_add_eq_right {Γ} [LinearOrder Γ] {x y : HahnSeries Γ R} (hxy : y.orderTop < x.orderTop) : (x + y).leadingCoeff = y.leadingCoeff := by simpa [← map_add, ← AddOpposite.op_add, hxy] using leadingCoeff_add_eq_left (x := addOppositeEquiv.symm (.op y)) (y := addOppositeEquiv.symm (.op x)) /-- `single` as an additive monoid/group homomorphism -/ @[simps!] def single.addMonoidHom (a : Γ) : R →+ HahnSeries Γ R := { single a with map_add' := fun x y => by ext b by_cases h : b = a <;> simp [h] } /-- `coeff g` as an additive monoid/group homomorphism -/ @[simps] def coeff.addMonoidHom (g : Γ) : HahnSeries Γ R →+ R where toFun f := f.coeff g map_zero' := zero_coeff map_add' _ _ := add_coeff section Domain variable {Γ' : Type*} [PartialOrder Γ'] theorem embDomain_add (f : Γ ↪o Γ') (x y : HahnSeries Γ R) : embDomain f (x + y) = embDomain f x + embDomain f y := by ext g by_cases hg : g ∈ Set.range f · obtain ⟨a, rfl⟩ := hg simp · simp [embDomain_notin_range hg] end Domain end AddMonoid instance [AddCommMonoid R] : AddCommMonoid (HahnSeries Γ R) := { inferInstanceAs (AddMonoid (HahnSeries Γ R)) with add_comm := fun x y => by ext apply add_comm } section AddGroup variable [AddGroup R] instance : Neg (HahnSeries Γ R) where neg x := { coeff := fun a => -x.coeff a isPWO_support' := by rw [Function.support_neg] exact x.isPWO_support } instance : AddGroup (HahnSeries Γ R) := { inferInstanceAs (AddMonoid (HahnSeries Γ R)) with zsmul := zsmulRec add_left_neg := fun x => by ext apply add_left_neg } @[simp] theorem neg_coeff' {x : HahnSeries Γ R} : (-x).coeff = -x.coeff := rfl theorem neg_coeff {x : HahnSeries Γ R} {a : Γ} : (-x).coeff a = -x.coeff a := rfl @[simp] theorem support_neg {x : HahnSeries Γ R} : (-x).support = x.support := by ext simp @[simp] theorem sub_coeff' {x y : HahnSeries Γ R} : (x - y).coeff = x.coeff - y.coeff := by ext simp [sub_eq_add_neg] theorem sub_coeff {x y : HahnSeries Γ R} {a : Γ} : (x - y).coeff a = x.coeff a - y.coeff a := by simp theorem orderTop_neg {x : HahnSeries Γ R} : (-x).orderTop = x.orderTop := by simp only [orderTop, support_neg, neg_eq_zero] @[simp] theorem order_neg [Zero Γ] {f : HahnSeries Γ R} : (-f).order = f.order := by by_cases hf : f = 0 · simp only [hf, neg_zero] simp only [order, support_neg, neg_eq_zero] theorem min_orderTop_le_orderTop_sub {Γ} [LinearOrder Γ] {x y : HahnSeries Γ R} : min x.orderTop y.orderTop ≤ (x - y).orderTop := by rw [sub_eq_add_neg, ← orderTop_neg (x := y)] exact min_orderTop_le_orderTop_add theorem orderTop_sub {Γ} [LinearOrder Γ] {x y : HahnSeries Γ R} (hxy : x.orderTop < y.orderTop) : (x - y).orderTop = x.orderTop := by rw [sub_eq_add_neg] rw [← orderTop_neg (x := y)] at hxy exact orderTop_add_eq_left hxy theorem leadingCoeff_sub {Γ} [LinearOrder Γ] {x y : HahnSeries Γ R} (hxy : x.orderTop < y.orderTop) : (x - y).leadingCoeff = x.leadingCoeff := by rw [sub_eq_add_neg] rw [← orderTop_neg (x := y)] at hxy exact leadingCoeff_add_eq_left hxy end AddGroup instance [AddCommGroup R] : AddCommGroup (HahnSeries Γ R) := { inferInstanceAs (AddCommMonoid (HahnSeries Γ R)), inferInstanceAs (AddGroup (HahnSeries Γ R)) with } end Addition section SMulZeroClass variable [PartialOrder Γ] {V : Type*} [Zero V] [SMulZeroClass R V] instance : SMul R (HahnSeries Γ V) := ⟨fun r x => { coeff := r • x.coeff isPWO_support' := x.isPWO_support.mono (Function.support_const_smul_subset r x.coeff) }⟩ @[simp] theorem smul_coeff {r : R} {x : HahnSeries Γ V} {a : Γ} : (r • x).coeff a = r • x.coeff a := rfl instance : SMulZeroClass R (HahnSeries Γ V) := { inferInstanceAs (SMul R (HahnSeries Γ V)) with smul_zero := by intro ext simp only [smul_coeff, zero_coeff, smul_zero]} theorem orderTop_smul_not_lt (r : R) (x : HahnSeries Γ V) : ¬ (r • x).orderTop < x.orderTop := by by_cases hrx : r • x = 0 · rw [hrx, orderTop_zero] exact not_top_lt · simp only [orderTop_of_ne hrx, orderTop_of_ne <| right_ne_zero_of_smul hrx, WithTop.coe_lt_coe] exact Set.IsWF.min_of_subset_not_lt_min (Function.support_smul_subset_right (fun _ => r) x.coeff) theorem order_smul_not_lt [Zero Γ] (r : R) (x : HahnSeries Γ V) (h : r • x ≠ 0) : ¬ (r • x).order < x.order := by have hx : x ≠ 0 := right_ne_zero_of_smul h simp_all only [order, dite_false] exact Set.IsWF.min_of_subset_not_lt_min (Function.support_smul_subset_right (fun _ => r) x.coeff) theorem le_order_smul {Γ} [Zero Γ] [LinearOrder Γ] (r : R) (x : HahnSeries Γ V) (h : r • x ≠ 0) : x.order ≤ (r • x).order := le_of_not_lt (order_smul_not_lt r x h) end SMulZeroClass section DistribMulAction variable [PartialOrder Γ] {V : Type*} [Monoid R] [AddMonoid V] [DistribMulAction R V] instance : DistribMulAction R (HahnSeries Γ V) where smul := (· • ·) one_smul _ := by ext simp smul_zero _ := by ext simp smul_add _ _ _ := by ext simp [smul_add] mul_smul _ _ _ := by ext simp [mul_smul] variable {S : Type*} [Monoid S] [DistribMulAction S V] instance [SMul R S] [IsScalarTower R S V] : IsScalarTower R S (HahnSeries Γ V) := ⟨fun r s a => by ext simp⟩ instance [SMulCommClass R S V] : SMulCommClass R S (HahnSeries Γ V) := ⟨fun r s a => by ext simp [smul_comm]⟩ end DistribMulAction section Module variable [PartialOrder Γ] [Semiring R] {V : Type*} [AddCommMonoid V] [Module R V] instance : Module R (HahnSeries Γ V) := { inferInstanceAs (DistribMulAction R (HahnSeries Γ V)) with zero_smul := fun _ => by ext simp add_smul := fun _ _ _ => by ext simp [add_smul] } /-- `single` as a linear map -/ @[simps] def single.linearMap (a : Γ) : V →ₗ[R] HahnSeries Γ V := { single.addMonoidHom a with map_smul' := fun r s => by ext b by_cases h : b = a <;> simp [h] } /-- `coeff g` as a linear map -/ @[simps] def coeff.linearMap (g : Γ) : HahnSeries Γ V →ₗ[R] V := { coeff.addMonoidHom g with map_smul' := fun _ _ => rfl } section Domain variable {Γ' : Type*} [PartialOrder Γ'] theorem embDomain_smul (f : Γ ↪o Γ') (r : R) (x : HahnSeries Γ R) : embDomain f (r • x) = r • embDomain f x := by ext g by_cases hg : g ∈ Set.range f · obtain ⟨a, rfl⟩ := hg simp · simp [embDomain_notin_range hg] /-- Extending the domain of Hahn series is a linear map. -/ @[simps] def embDomainLinearMap (f : Γ ↪o Γ') : HahnSeries Γ R →ₗ[R] HahnSeries Γ' R where toFun := embDomain f map_add' := embDomain_add f map_smul' := embDomain_smul f end Domain end Module end HahnSeries
RingTheory\HahnSeries\Basic.lean
/- Copyright (c) 2021 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.Algebra.Group.Support import Mathlib.Order.WellFoundedSet /-! # Hahn Series If `Γ` is ordered and `R` has zero, then `HahnSeries Γ R` consists of formal series over `Γ` with coefficients in `R`, whose supports are partially well-ordered. With further structure on `R` and `Γ`, we can add further structure on `HahnSeries Γ R`, with the most studied case being when `Γ` is a linearly ordered abelian group and `R` is a field, in which case `HahnSeries Γ R` is a valued field, with value group `Γ`. These generalize Laurent series (with value group `ℤ`), and Laurent series are implemented that way in the file `RingTheory/LaurentSeries`. ## Main Definitions * If `Γ` is ordered and `R` has zero, then `HahnSeries Γ R` consists of formal series over `Γ` with coefficients in `R`, whose supports are partially well-ordered. * `support x` is the subset of `Γ` whose coefficients are nonzero. * `single a r` is the Hahn series which has coefficient `r` at `a` and zero otherwise. * `orderTop x` is a minimal element of `WithTop Γ` where `x` has a nonzero coefficient if `x ≠ 0`, and is `⊤` when `x = 0`. * `order x` is a minimal element of `Γ` where `x` has a nonzero coefficient if `x ≠ 0`, and is zero when `x = 0`. ## References - [J. van der Hoeven, *Operators on Generalized Power Series*][van_der_hoeven] -/ open Finset Function noncomputable section /-- If `Γ` is linearly ordered and `R` has zero, then `HahnSeries Γ R` consists of formal series over `Γ` with coefficients in `R`, whose supports are well-founded. -/ @[ext] structure HahnSeries (Γ : Type*) (R : Type*) [PartialOrder Γ] [Zero R] where /-- The coefficient function of a Hahn Series. -/ coeff : Γ → R isPWO_support' : (Function.support coeff).IsPWO variable {Γ : Type*} {R : Type*} namespace HahnSeries section Zero variable [PartialOrder Γ] [Zero R] theorem coeff_injective : Injective (coeff : HahnSeries Γ R → Γ → R) := fun _ _ => HahnSeries.ext @[simp] theorem coeff_inj {x y : HahnSeries Γ R} : x.coeff = y.coeff ↔ x = y := coeff_injective.eq_iff /-- The support of a Hahn series is just the set of indices whose coefficients are nonzero. Notably, it is well-founded. -/ nonrec def support (x : HahnSeries Γ R) : Set Γ := support x.coeff @[simp] theorem isPWO_support (x : HahnSeries Γ R) : x.support.IsPWO := x.isPWO_support' @[simp] theorem isWF_support (x : HahnSeries Γ R) : x.support.IsWF := x.isPWO_support.isWF @[simp] theorem mem_support (x : HahnSeries Γ R) (a : Γ) : a ∈ x.support ↔ x.coeff a ≠ 0 := Iff.refl _ instance : Zero (HahnSeries Γ R) := ⟨{ coeff := 0 isPWO_support' := by simp }⟩ instance : Inhabited (HahnSeries Γ R) := ⟨0⟩ instance [Subsingleton R] : Subsingleton (HahnSeries Γ R) := ⟨fun _ _ => HahnSeries.ext (by subsingleton)⟩ @[simp] theorem zero_coeff {a : Γ} : (0 : HahnSeries Γ R).coeff a = 0 := rfl @[simp] theorem coeff_fun_eq_zero_iff {x : HahnSeries Γ R} : x.coeff = 0 ↔ x = 0 := coeff_injective.eq_iff' rfl theorem ne_zero_of_coeff_ne_zero {x : HahnSeries Γ R} {g : Γ} (h : x.coeff g ≠ 0) : x ≠ 0 := mt (fun x0 => (x0.symm ▸ zero_coeff : x.coeff g = 0)) h @[simp] theorem support_zero : support (0 : HahnSeries Γ R) = ∅ := Function.support_zero @[simp] nonrec theorem support_nonempty_iff {x : HahnSeries Γ R} : x.support.Nonempty ↔ x ≠ 0 := by rw [support, support_nonempty_iff, Ne, coeff_fun_eq_zero_iff] @[simp] theorem support_eq_empty_iff {x : HahnSeries Γ R} : x.support = ∅ ↔ x = 0 := Function.support_eq_empty_iff.trans coeff_fun_eq_zero_iff /-- Change a HahnSeries with coefficients in HahnSeries to a HahnSeries on the Lex product. -/ def ofIterate {Γ' : Type*} [PartialOrder Γ'] (x : HahnSeries Γ (HahnSeries Γ' R)) : HahnSeries (Γ ×ₗ Γ') R where coeff := fun g => coeff (coeff x g.1) g.2 isPWO_support' := by refine Set.PartiallyWellOrderedOn.subsetProdLex ?_ ?_ · refine Set.IsPWO.mono x.isPWO_support' ?_ simp_rw [Set.image_subset_iff, support_subset_iff, Set.mem_preimage, Function.mem_support] exact fun _ ↦ ne_zero_of_coeff_ne_zero · exact fun a => by simpa [Function.mem_support, ne_eq] using (x.coeff a).isPWO_support' @[simp] lemma mk_eq_zero (f : Γ → R) (h) : HahnSeries.mk f h = 0 ↔ f = 0 := by rw [HahnSeries.ext_iff] rfl /-- Change a Hahn series on a lex product to a Hahn series with coefficients in a Hahn series. -/ def toIterate {Γ' : Type*} [PartialOrder Γ'] (x : HahnSeries (Γ ×ₗ Γ') R) : HahnSeries Γ (HahnSeries Γ' R) where coeff := fun g => { coeff := fun g' => coeff x (g, g') isPWO_support' := Set.PartiallyWellOrderedOn.fiberProdLex x.isPWO_support' g } isPWO_support' := by have h₁ : (Function.support fun g => HahnSeries.mk (fun g' => x.coeff (g, g')) (Set.PartiallyWellOrderedOn.fiberProdLex x.isPWO_support' g)) = Function.support fun g => fun g' => x.coeff (g, g') := by simp only [Function.support, ne_eq, mk_eq_zero] rw [h₁, Function.support_curry' x.coeff] exact Set.PartiallyWellOrderedOn.imageProdLex x.isPWO_support' /-- The equivalence between iterated Hahn series and Hahn series on the lex product. -/ @[simps] def iterateEquiv {Γ' : Type*} [PartialOrder Γ'] : HahnSeries Γ (HahnSeries Γ' R) ≃ HahnSeries (Γ ×ₗ Γ') R where toFun := ofIterate invFun := toIterate left_inv := congrFun rfl right_inv := congrFun rfl open Classical in /-- `single a r` is the Hahn series which has coefficient `r` at `a` and zero otherwise. -/ def single (a : Γ) : ZeroHom R (HahnSeries Γ R) where toFun r := { coeff := Pi.single a r isPWO_support' := (Set.isPWO_singleton a).mono Pi.support_single_subset } map_zero' := HahnSeries.ext (Pi.single_zero _) variable {a b : Γ} {r : R} @[simp] theorem single_coeff_same (a : Γ) (r : R) : (single a r).coeff a = r := by classical exact Pi.single_eq_same (f := fun _ => R) a r @[simp] theorem single_coeff_of_ne (h : b ≠ a) : (single a r).coeff b = 0 := by classical exact Pi.single_eq_of_ne (f := fun _ => R) h r open Classical in theorem single_coeff : (single a r).coeff b = if b = a then r else 0 := by split_ifs with h <;> simp [h] @[simp] theorem support_single_of_ne (h : r ≠ 0) : support (single a r) = {a} := by classical exact Pi.support_single_of_ne h theorem support_single_subset : support (single a r) ⊆ {a} := by classical exact Pi.support_single_subset theorem eq_of_mem_support_single {b : Γ} (h : b ∈ support (single a r)) : b = a := support_single_subset h --@[simp] Porting note (#10618): simp can prove it theorem single_eq_zero : single a (0 : R) = 0 := (single a).map_zero theorem single_injective (a : Γ) : Function.Injective (single a : R → HahnSeries Γ R) := fun r s rs => by rw [← single_coeff_same a r, ← single_coeff_same a s, rs] theorem single_ne_zero (h : r ≠ 0) : single a r ≠ 0 := fun con => h (single_injective a (con.trans single_eq_zero.symm)) @[simp] theorem single_eq_zero_iff {a : Γ} {r : R} : single a r = 0 ↔ r = 0 := map_eq_zero_iff _ <| single_injective a instance [Nonempty Γ] [Nontrivial R] : Nontrivial (HahnSeries Γ R) := ⟨by obtain ⟨r, s, rs⟩ := exists_pair_ne R inhabit Γ refine ⟨single default r, single default s, fun con => rs ?_⟩ rw [← single_coeff_same (default : Γ) r, con, single_coeff_same]⟩ section Order open Classical in /-- The orderTop of a Hahn series `x` is a minimal element of `WithTop Γ` where `x` has a nonzero coefficient if `x ≠ 0`, and is `⊤` when `x = 0`. -/ def orderTop (x : HahnSeries Γ R) : WithTop Γ := if h : x = 0 then ⊤ else x.isWF_support.min (support_nonempty_iff.2 h) @[simp] theorem orderTop_zero : orderTop (0 : HahnSeries Γ R) = ⊤ := dif_pos rfl theorem orderTop_of_ne {x : HahnSeries Γ R} (hx : x ≠ 0) : orderTop x = x.isWF_support.min (support_nonempty_iff.2 hx) := dif_neg hx @[simp] theorem ne_zero_iff_orderTop {x : HahnSeries Γ R} : x ≠ 0 ↔ orderTop x ≠ ⊤ := by constructor · exact fun hx => Eq.mpr (congrArg (fun h ↦ h ≠ ⊤) (orderTop_of_ne hx)) WithTop.coe_ne_top · contrapose! simp_all only [orderTop_zero, implies_true] theorem orderTop_eq_top_iff {x : HahnSeries Γ R} : orderTop x = ⊤ ↔ x = 0 := by constructor · contrapose! exact ne_zero_iff_orderTop.mp · simp_all only [orderTop_zero, implies_true] theorem untop_orderTop_of_ne_zero {x : HahnSeries Γ R} (hx : x ≠ 0) : WithTop.untop x.orderTop (ne_zero_iff_orderTop.mp hx) = x.isWF_support.min (support_nonempty_iff.2 hx) := WithTop.coe_inj.mp ((WithTop.coe_untop (orderTop x) (ne_zero_iff_orderTop.mp hx)).trans (orderTop_of_ne hx)) theorem coeff_orderTop_ne {x : HahnSeries Γ R} {g : Γ} (hg : x.orderTop = g) : x.coeff g ≠ 0 := by have h : orderTop x ≠ ⊤ := by simp_all only [ne_eq, WithTop.coe_ne_top, not_false_eq_true] have hx : x ≠ 0 := ne_zero_iff_orderTop.mpr h rw [orderTop_of_ne hx, WithTop.coe_eq_coe] at hg rw [← hg] exact x.isWF_support.min_mem (support_nonempty_iff.2 hx) theorem orderTop_le_of_coeff_ne_zero {Γ} [LinearOrder Γ] {x : HahnSeries Γ R} {g : Γ} (h : x.coeff g ≠ 0) : x.orderTop ≤ g := by rw [orderTop_of_ne (ne_zero_of_coeff_ne_zero h), WithTop.coe_le_coe] exact Set.IsWF.min_le _ _ ((mem_support _ _).2 h) @[simp] theorem orderTop_single (h : r ≠ 0) : (single a r).orderTop = a := (orderTop_of_ne (single_ne_zero h)).trans (WithTop.coe_inj.mpr (support_single_subset ((single a r).isWF_support.min_mem (support_nonempty_iff.2 (single_ne_zero h))))) theorem orderTop_single_le : a ≤ (single a r).orderTop := by by_cases hr : r = 0 · simp only [hr, map_zero, orderTop_zero, le_top] · rw [orderTop_single hr] theorem lt_orderTop_single {g g' : Γ} (hgg' : g < g') : g < (single g' r).orderTop := lt_of_lt_of_le (WithTop.coe_lt_coe.mpr hgg') orderTop_single_le theorem coeff_eq_zero_of_lt_orderTop {x : HahnSeries Γ R} {i : Γ} (hi : i < x.orderTop) : x.coeff i = 0 := by rcases eq_or_ne x 0 with (rfl | hx) · exact zero_coeff contrapose! hi rw [← mem_support] at hi rw [orderTop_of_ne hx, WithTop.coe_lt_coe] exact Set.IsWF.not_lt_min _ _ hi open Classical in /-- A leading coefficient of a Hahn series is the coefficient of a lowest-order nonzero term, or zero if the series vanishes. -/ def leadingCoeff (x : HahnSeries Γ R) : R := if h : x = 0 then 0 else x.coeff (x.isWF_support.min (support_nonempty_iff.2 h)) @[simp] theorem leadingCoeff_zero : leadingCoeff (0 : HahnSeries Γ R) = 0 := dif_pos rfl theorem leadingCoeff_of_ne {x : HahnSeries Γ R} (hx : x ≠ 0) : x.leadingCoeff = x.coeff (x.isWF_support.min (support_nonempty_iff.2 hx)) := dif_neg hx theorem leadingCoeff_eq_iff {x : HahnSeries Γ R} : x.leadingCoeff = 0 ↔ x = 0 := by refine { mp := ?_, mpr := fun hx => hx ▸ leadingCoeff_zero } contrapose! exact fun hx => (leadingCoeff_of_ne hx) ▸ coeff_orderTop_ne (orderTop_of_ne hx) theorem leadingCoeff_ne_iff {x : HahnSeries Γ R} : x.leadingCoeff ≠ 0 ↔ x ≠ 0 := leadingCoeff_eq_iff.not theorem leadingCoeff_of_single {a : Γ} {r : R} : leadingCoeff (single a r) = r := by simp only [leadingCoeff, single_eq_zero_iff] by_cases h : r = 0 <;> simp [h] variable [Zero Γ] open Classical in /-- The order of a nonzero Hahn series `x` is a minimal element of `Γ` where `x` has a nonzero coefficient, the order of 0 is 0. -/ def order (x : HahnSeries Γ R) : Γ := if h : x = 0 then 0 else x.isWF_support.min (support_nonempty_iff.2 h) @[simp] theorem order_zero : order (0 : HahnSeries Γ R) = 0 := dif_pos rfl theorem order_of_ne {x : HahnSeries Γ R} (hx : x ≠ 0) : order x = x.isWF_support.min (support_nonempty_iff.2 hx) := dif_neg hx theorem order_eq_orderTop_of_ne {x : HahnSeries Γ R} (hx : x ≠ 0) : order x = orderTop x := by rw [order_of_ne hx, orderTop_of_ne hx] theorem coeff_order_ne_zero {x : HahnSeries Γ R} (hx : x ≠ 0) : x.coeff x.order ≠ 0 := by rw [order_of_ne hx] exact x.isWF_support.min_mem (support_nonempty_iff.2 hx) theorem order_le_of_coeff_ne_zero {Γ} [LinearOrderedCancelAddCommMonoid Γ] {x : HahnSeries Γ R} {g : Γ} (h : x.coeff g ≠ 0) : x.order ≤ g := le_trans (le_of_eq (order_of_ne (ne_zero_of_coeff_ne_zero h))) (Set.IsWF.min_le _ _ ((mem_support _ _).2 h)) @[simp] theorem order_single (h : r ≠ 0) : (single a r).order = a := (order_of_ne (single_ne_zero h)).trans (support_single_subset ((single a r).isWF_support.min_mem (support_nonempty_iff.2 (single_ne_zero h)))) theorem coeff_eq_zero_of_lt_order {x : HahnSeries Γ R} {i : Γ} (hi : i < x.order) : x.coeff i = 0 := by rcases eq_or_ne x 0 with (rfl | hx) · simp contrapose! hi rw [← mem_support] at hi rw [order_of_ne hx] exact Set.IsWF.not_lt_min _ _ hi theorem zero_lt_orderTop_iff {x : HahnSeries Γ R} (hx : x ≠ 0) : 0 < x.orderTop ↔ 0 < x.order := by simp_all [orderTop_of_ne hx, order_of_ne hx] theorem zero_lt_orderTop_of_order {x : HahnSeries Γ R} (hx : 0 < x.order) : 0 < x.orderTop := by by_cases h : x = 0 · simp_all only [order_zero, lt_self_iff_false] · exact (zero_lt_orderTop_iff h).mpr hx theorem zero_le_orderTop_iff {x : HahnSeries Γ R} : 0 ≤ x.orderTop ↔ 0 ≤ x.order := by by_cases h : x = 0 · simp_all · simp_all [order_of_ne h, orderTop_of_ne h, zero_lt_orderTop_iff] theorem leadingCoeff_eq {x : HahnSeries Γ R} : x.leadingCoeff = x.coeff x.order := by by_cases h : x = 0 · rw [h, leadingCoeff_zero, zero_coeff] · rw [leadingCoeff_of_ne h, order_of_ne h] end Order section Domain variable {Γ' : Type*} [PartialOrder Γ'] open Classical in /-- Extends the domain of a `HahnSeries` by an `OrderEmbedding`. -/ def embDomain (f : Γ ↪o Γ') : HahnSeries Γ R → HahnSeries Γ' R := fun x => { coeff := fun b : Γ' => if h : b ∈ f '' x.support then x.coeff (Classical.choose h) else 0 isPWO_support' := (x.isPWO_support.image_of_monotone f.monotone).mono fun b hb => by contrapose! hb rw [Function.mem_support, dif_neg hb, Classical.not_not] } @[simp] theorem embDomain_coeff {f : Γ ↪o Γ'} {x : HahnSeries Γ R} {a : Γ} : (embDomain f x).coeff (f a) = x.coeff a := by rw [embDomain] dsimp only by_cases ha : a ∈ x.support · rw [dif_pos (Set.mem_image_of_mem f ha)] exact congr rfl (f.injective (Classical.choose_spec (Set.mem_image_of_mem f ha)).2) · rw [dif_neg, Classical.not_not.1 fun c => ha ((mem_support _ _).2 c)] contrapose! ha obtain ⟨b, hb1, hb2⟩ := (Set.mem_image _ _ _).1 ha rwa [f.injective hb2] at hb1 @[simp] theorem embDomain_mk_coeff {f : Γ → Γ'} (hfi : Function.Injective f) (hf : ∀ g g' : Γ, f g ≤ f g' ↔ g ≤ g') {x : HahnSeries Γ R} {a : Γ} : (embDomain ⟨⟨f, hfi⟩, hf _ _⟩ x).coeff (f a) = x.coeff a := embDomain_coeff theorem embDomain_notin_image_support {f : Γ ↪o Γ'} {x : HahnSeries Γ R} {b : Γ'} (hb : b ∉ f '' x.support) : (embDomain f x).coeff b = 0 := dif_neg hb theorem support_embDomain_subset {f : Γ ↪o Γ'} {x : HahnSeries Γ R} : support (embDomain f x) ⊆ f '' x.support := by intro g hg contrapose! hg rw [mem_support, embDomain_notin_image_support hg, Classical.not_not] theorem embDomain_notin_range {f : Γ ↪o Γ'} {x : HahnSeries Γ R} {b : Γ'} (hb : b ∉ Set.range f) : (embDomain f x).coeff b = 0 := embDomain_notin_image_support fun con => hb (Set.image_subset_range _ _ con) @[simp] theorem embDomain_zero {f : Γ ↪o Γ'} : embDomain f (0 : HahnSeries Γ R) = 0 := by ext simp [embDomain_notin_image_support] @[simp] theorem embDomain_single {f : Γ ↪o Γ'} {g : Γ} {r : R} : embDomain f (single g r) = single (f g) r := by ext g' by_cases h : g' = f g · simp [h] rw [embDomain_notin_image_support, single_coeff_of_ne h] by_cases hr : r = 0 · simp [hr] rwa [support_single_of_ne hr, Set.image_singleton, Set.mem_singleton_iff] theorem embDomain_injective {f : Γ ↪o Γ'} : Function.Injective (embDomain f : HahnSeries Γ R → HahnSeries Γ' R) := fun x y xy => by ext g rw [HahnSeries.ext_iff, Function.funext_iff] at xy have xyg := xy (f g) rwa [embDomain_coeff, embDomain_coeff] at xyg end Domain end Zero section LocallyFiniteLinearOrder variable [Zero R] [LinearOrder Γ] theorem forallLTEqZero_supp_BddBelow (f : Γ → R) (n : Γ) (hn : ∀(m : Γ), m < n → f m = 0) : BddBelow (Function.support f) := by simp only [BddBelow, Set.Nonempty, lowerBounds] use n intro m hm rw [Function.mem_support, ne_eq] at hm exact not_lt.mp (mt (hn m) hm) theorem BddBelow_zero [Nonempty Γ] : BddBelow (Function.support (0 : Γ → R)) := by simp only [support_zero', bddBelow_empty] variable [LocallyFiniteOrder Γ] theorem suppBddBelow_supp_PWO (f : Γ → R) (hf : BddBelow (Function.support f)) : (Function.support f).IsPWO := Set.isWF_iff_isPWO.mp hf.wellFoundedOn_lt /-- Construct a Hahn series from any function whose support is bounded below. -/ @[simps] def ofSuppBddBelow (f : Γ → R) (hf : BddBelow (Function.support f)) : HahnSeries Γ R where coeff := f isPWO_support' := suppBddBelow_supp_PWO f hf @[simp] theorem zero_ofSuppBddBelow [Nonempty Γ] : ofSuppBddBelow 0 BddBelow_zero = (0 : HahnSeries Γ R) := rfl theorem order_ofForallLtEqZero [Zero Γ] (f : Γ → R) (hf : f ≠ 0) (n : Γ) (hn : ∀(m : Γ), m < n → f m = 0) : n ≤ order (ofSuppBddBelow f (forallLTEqZero_supp_BddBelow f n hn)) := by dsimp only [order] by_cases h : ofSuppBddBelow f (forallLTEqZero_supp_BddBelow f n hn) = 0 cases h · exact (hf rfl).elim simp_all only [dite_false] rw [Set.IsWF.le_min_iff] intro m hm rw [HahnSeries.support, Function.mem_support, ne_eq] at hm exact not_lt.mp (mt (hn m) hm) end LocallyFiniteLinearOrder end HahnSeries
RingTheory\HahnSeries\Multiplication.lean
/- Copyright (c) 2021 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Scott Carnahan -/ import Mathlib.Algebra.Algebra.Subalgebra.Basic import Mathlib.Data.Finset.MulAntidiagonal import Mathlib.Data.Finset.SMulAntidiagonal import Mathlib.RingTheory.HahnSeries.Addition /-! # Multiplicative properties of Hahn series If `Γ` is ordered and `R` has zero, then `HahnSeries Γ R` consists of formal series over `Γ` with coefficients in `R`, whose supports are partially well-ordered. With further structure on `R` and `Γ`, we can add further structure on `HahnSeries Γ R`. We prove some facts about multiplying Hahn series. ## Main Definitions * `HahnModule` is a type alias for `HahnSeries`, which we use for defining scalar multiplication of `HahnSeries Γ R` on `HahnModule Γ' R V` for an `R`-module `V`, where `Γ'` admits an ordered cancellative vector addition operation from `Γ`. ## Main results * If `R` is a (commutative) (semi-)ring, then so is `HahnSeries Γ R`. * If `V` is an `R`-module, then `HahnModule Γ' R V` is a `HahnSeries Γ R`-module. ## TODO * Scalar tower instances ## References - [J. van der Hoeven, *Operators on Generalized Power Series*][van_der_hoeven] -/ open Finset Function Pointwise noncomputable section variable {Γ Γ' R V : Type*} namespace HahnSeries variable [Zero Γ] [PartialOrder Γ] instance [Zero R] [One R] : One (HahnSeries Γ R) := ⟨single 0 1⟩ open Classical in @[simp] theorem one_coeff [Zero R] [One R] {a : Γ} : (1 : HahnSeries Γ R).coeff a = if a = 0 then 1 else 0 := single_coeff @[simp] theorem single_zero_one [Zero R] [One R] : single (0 : Γ) (1 : R) = 1 := rfl @[simp] theorem support_one [MulZeroOneClass R] [Nontrivial R] : support (1 : HahnSeries Γ R) = {0} := support_single_of_ne one_ne_zero @[simp] theorem orderTop_one [MulZeroOneClass R] [Nontrivial R] : orderTop (1 : HahnSeries Γ R) = 0 := by rw [← single_zero_one, orderTop_single one_ne_zero, WithTop.coe_eq_zero] @[simp] theorem order_one [MulZeroOneClass R] : order (1 : HahnSeries Γ R) = 0 := by cases subsingleton_or_nontrivial R · rw [Subsingleton.elim (1 : HahnSeries Γ R) 0, order_zero] · exact order_single one_ne_zero @[simp] theorem leadingCoeff_one [MulZeroOneClass R] : (1 : HahnSeries Γ R).leadingCoeff = 1 := by simp [leadingCoeff_eq] end HahnSeries /-- We introduce a type alias for `HahnSeries` in order to work with scalar multiplication by series. If we wrote a `SMul (HahnSeries Γ R) (HahnSeries Γ V)` instance, then when `V = HahnSeries Γ R`, we would have two different actions of `HahnSeries Γ R` on `HahnSeries Γ V`. See `Mathlib.Algebra.Polynomial.Module` for more discussion on this problem. -/ @[nolint unusedArguments] def HahnModule (Γ R V : Type*) [PartialOrder Γ] [Zero V] [SMul R V] := HahnSeries Γ V namespace HahnModule section variable [PartialOrder Γ] [Zero V] [SMul R V] /-- The casting function to the type synonym. -/ def of (R : Type*) [SMul R V] : HahnSeries Γ V ≃ HahnModule Γ R V := Equiv.refl _ /-- Recursion principle to reduce a result about the synonym to the original type. -/ @[elab_as_elim] def rec {motive : HahnModule Γ R V → Sort*} (h : ∀ x : HahnSeries Γ V, motive (of R x)) : ∀ x, motive x := fun x => h <| (of R).symm x @[ext] theorem ext (x y : HahnModule Γ R V) (h : ((of R).symm x).coeff = ((of R).symm y).coeff) : x = y := (of R).symm.injective <| HahnSeries.coeff_inj.1 h end section SMul variable [PartialOrder Γ] [AddCommMonoid V] [SMul R V] instance instAddCommMonoid : AddCommMonoid (HahnModule Γ R V) := inferInstanceAs <| AddCommMonoid (HahnSeries Γ V) instance instBaseSMul {V} [Monoid R] [AddMonoid V] [DistribMulAction R V] : SMul R (HahnModule Γ R V) := inferInstanceAs <| SMul R (HahnSeries Γ V) @[simp] theorem of_zero : of R (0 : HahnSeries Γ V) = 0 := rfl @[simp] theorem of_add (x y : HahnSeries Γ V) : of R (x + y) = of R x + of R y := rfl @[simp] theorem of_symm_zero : (of R).symm (0 : HahnModule Γ R V) = 0 := rfl @[simp] theorem of_symm_add (x y : HahnModule Γ R V) : (of R).symm (x + y) = (of R).symm x + (of R).symm y := rfl variable [PartialOrder Γ'] [VAdd Γ Γ'] [IsOrderedCancelVAdd Γ Γ'] instance instSMul [Zero R] : SMul (HahnSeries Γ R) (HahnModule Γ' R V) where smul x y := (of R) { coeff := fun a => ∑ ij ∈ VAddAntidiagonal x.isPWO_support ((of R).symm y).isPWO_support a, x.coeff ij.fst • ((of R).symm y).coeff ij.snd isPWO_support' := haveI h : { a : Γ' | (∑ ij ∈ VAddAntidiagonal x.isPWO_support ((of R).symm y).isPWO_support a, x.coeff ij.fst • ((of R).symm y).coeff ij.snd) ≠ 0 } ⊆ { a : Γ' | (VAddAntidiagonal x.isPWO_support ((of R).symm y).isPWO_support a).Nonempty } := by intro a ha contrapose! ha simp [not_nonempty_iff_eq_empty.1 ha] isPWO_support_vaddAntidiagonal.mono h } theorem smul_coeff [Zero R] (x : HahnSeries Γ R) (y : HahnModule Γ' R V) (a : Γ') : ((of R).symm <| x • y).coeff a = ∑ ij ∈ VAddAntidiagonal x.isPWO_support ((of R).symm y).isPWO_support a, x.coeff ij.fst • ((of R).symm y).coeff ij.snd := rfl end SMul section SMulZeroClass variable [PartialOrder Γ] [PartialOrder Γ'] [VAdd Γ Γ'] [IsOrderedCancelVAdd Γ Γ'] [AddCommMonoid V] instance instBaseSMulZeroClass [SMulZeroClass R V] : SMulZeroClass R (HahnModule Γ R V) := inferInstanceAs <| SMulZeroClass R (HahnSeries Γ V) @[simp] theorem of_smul [SMulZeroClass R V] (r : R) (x : HahnSeries Γ V) : (of R) (r • x) = r • (of R) x := rfl @[simp] theorem of_symm_smul [SMulZeroClass R V] (r : R) (x : HahnModule Γ R V) : (of R).symm (r • x) = r • (of R).symm x := rfl variable [Zero R] instance instSMulZeroClass [SMulZeroClass R V] : SMulZeroClass (HahnSeries Γ R) (HahnModule Γ' R V) where smul_zero x := by ext simp [smul_coeff] theorem smul_coeff_right [SMulZeroClass R V] {x : HahnSeries Γ R} {y : HahnModule Γ' R V} {a : Γ'} {s : Set Γ'} (hs : s.IsPWO) (hys : ((of R).symm y).support ⊆ s) : ((of R).symm <| x • y).coeff a = ∑ ij ∈ VAddAntidiagonal x.isPWO_support hs a, x.coeff ij.fst • ((of R).symm y).coeff ij.snd := by classical rw [smul_coeff] apply sum_subset_zero_on_sdiff (vaddAntidiagonal_mono_right hys) _ fun _ _ => rfl intro b hb simp only [not_and, mem_sdiff, mem_vaddAntidiagonal, HahnSeries.mem_support, not_imp_not] at hb rw [hb.2 hb.1.1 hb.1.2.2, smul_zero] theorem smul_coeff_left [SMulWithZero R V] {x : HahnSeries Γ R} {y : HahnModule Γ' R V} {a : Γ'} {s : Set Γ} (hs : s.IsPWO) (hxs : x.support ⊆ s) : ((of R).symm <| x • y).coeff a = ∑ ij ∈ VAddAntidiagonal hs ((of R).symm y).isPWO_support a, x.coeff ij.fst • ((of R).symm y).coeff ij.snd := by classical rw [smul_coeff] apply sum_subset_zero_on_sdiff (vaddAntidiagonal_mono_left hxs) _ fun _ _ => rfl intro b hb simp only [not_and', mem_sdiff, mem_vaddAntidiagonal, HahnSeries.mem_support, not_ne_iff] at hb rw [hb.2 ⟨hb.1.2.1, hb.1.2.2⟩, zero_smul] end SMulZeroClass section DistribSMul variable [PartialOrder Γ] [PartialOrder Γ'] [VAdd Γ Γ'] [IsOrderedCancelVAdd Γ Γ'] [AddCommMonoid V] theorem smul_add [Zero R] [DistribSMul R V] (x : HahnSeries Γ R) (y z : HahnModule Γ' R V) : x • (y + z) = x • y + x • z := by ext k have hwf := ((of R).symm y).isPWO_support.union ((of R).symm z).isPWO_support rw [smul_coeff_right hwf, of_symm_add] · simp_all only [HahnSeries.add_coeff', Pi.add_apply, smul_add, of_symm_add] rw [smul_coeff_right hwf Set.subset_union_right, smul_coeff_right hwf Set.subset_union_left] simp_all [sum_add_distrib] · intro b simp_all only [Set.isPWO_union, HahnSeries.isPWO_support, and_self, of_symm_add, HahnSeries.add_coeff', Pi.add_apply, ne_eq, Set.mem_union, HahnSeries.mem_support] contrapose! intro h rw [h.1, h.2, add_zero] instance instDistribSMul [MonoidWithZero R] [DistribSMul R V] : DistribSMul (HahnSeries Γ R) (HahnModule Γ' R V) where smul_add := smul_add theorem add_smul [AddCommMonoid R] [SMulWithZero R V] {x y : HahnSeries Γ R} {z : HahnModule Γ' R V} (h : ∀ (r s : R) (u : V), (r + s) • u = r • u + s • u) : (x + y) • z = x • z + y • z := by ext a have hwf := x.isPWO_support.union y.isPWO_support rw [smul_coeff_left hwf, HahnSeries.add_coeff', of_symm_add] simp_all only [Pi.add_apply, HahnSeries.add_coeff'] rw [smul_coeff_left hwf Set.subset_union_right, smul_coeff_left hwf Set.subset_union_left] · simp only [HahnSeries.add_coeff, h, sum_add_distrib] · intro b simp_all only [Set.isPWO_union, HahnSeries.isPWO_support, and_self, HahnSeries.mem_support, HahnSeries.add_coeff, ne_eq, Set.mem_union, Set.mem_setOf_eq, mem_support] contrapose! intro h rw [h.1, h.2, add_zero] theorem single_smul_coeff_add [MulZeroClass R] [SMulWithZero R V] {r : R} {x : HahnModule Γ' R V} {a : Γ'} {b : Γ} : ((of R).symm (HahnSeries.single b r • x)).coeff (b +ᵥ a) = r • ((of R).symm x).coeff a := by by_cases hr : r = 0 · simp_all only [map_zero, zero_smul, smul_coeff, HahnSeries.support_zero, HahnSeries.zero_coeff, sum_const_zero] simp only [hr, smul_coeff, smul_coeff, HahnSeries.support_single_of_ne, ne_eq, not_false_iff, smul_eq_mul] by_cases hx : ((of R).symm x).coeff a = 0 · simp only [hx, smul_zero] rw [sum_congr _ fun _ _ => rfl, sum_empty] ext ⟨a1, a2⟩ simp only [not_mem_empty, not_and, Set.mem_singleton_iff, Classical.not_not, mem_vaddAntidiagonal, Set.mem_setOf_eq, iff_false_iff] rintro rfl h2 h1 rw [IsCancelVAdd.left_cancel a1 a2 a h1] at h2 exact h2 hx trans ∑ ij ∈ {(b, a)}, (HahnSeries.single b r).coeff ij.fst • ((of R).symm x).coeff ij.snd · apply sum_congr _ fun _ _ => rfl ext ⟨a1, a2⟩ simp only [Set.mem_singleton_iff, Prod.mk.inj_iff, mem_vaddAntidiagonal, mem_singleton, Set.mem_setOf_eq] constructor · rintro ⟨rfl, _, h1⟩ exact ⟨rfl, IsCancelVAdd.left_cancel a1 a2 a h1⟩ · rintro ⟨rfl, rfl⟩ exact ⟨rfl, by exact hx, rfl⟩ · simp theorem single_zero_smul_coeff {Γ} [OrderedAddCommMonoid Γ] [AddAction Γ Γ'] [IsOrderedCancelVAdd Γ Γ'] [MulZeroClass R] [SMulWithZero R V] {r : R} {x : HahnModule Γ' R V} {a : Γ'} : ((of R).symm ((HahnSeries.single 0 r : HahnSeries Γ R) • x)).coeff a = r • ((of R).symm x).coeff a := by nth_rw 1 [← zero_vadd Γ a] exact single_smul_coeff_add @[simp] theorem single_zero_smul_eq_smul (Γ) [OrderedAddCommMonoid Γ] [AddAction Γ Γ'] [IsOrderedCancelVAdd Γ Γ'] [MulZeroClass R] [SMulWithZero R V] {r : R} {x : HahnModule Γ' R V} : (HahnSeries.single (0 : Γ) r) • x = r • x := by ext exact single_zero_smul_coeff @[simp] theorem zero_smul' [Zero R] [SMulWithZero R V] {x : HahnModule Γ' R V} : (0 : HahnSeries Γ R) • x = 0 := by ext simp [smul_coeff] @[simp] theorem one_smul' {Γ} [OrderedAddCommMonoid Γ] [AddAction Γ Γ'] [IsOrderedCancelVAdd Γ Γ'] [MonoidWithZero R] [MulActionWithZero R V] {x : HahnModule Γ' R V} : (1 : HahnSeries Γ R) • x = x := by ext g exact single_zero_smul_coeff.trans (one_smul R (x.coeff g)) theorem support_smul_subset_vadd_support' [MulZeroClass R] [SMulWithZero R V] {x : HahnSeries Γ R} {y : HahnModule Γ' R V} : ((of R).symm (x • y)).support ⊆ x.support +ᵥ ((of R).symm y).support := by apply Set.Subset.trans (fun x hx => _) support_vaddAntidiagonal_subset_vadd · exact x.isPWO_support · exact y.isPWO_support intro x hx contrapose! hx simp only [Set.mem_setOf_eq, not_nonempty_iff_eq_empty] at hx simp [hx, smul_coeff] theorem support_smul_subset_vadd_support [MulZeroClass R] [SMulWithZero R V] {x : HahnSeries Γ R} {y : HahnModule Γ' R V} : ((of R).symm (x • y)).support ⊆ x.support +ᵥ ((of R).symm y).support := by have h : x.support +ᵥ ((of R).symm y).support = x.support +ᵥ ((of R).symm y).support := by exact rfl rw [h] exact support_smul_subset_vadd_support' theorem smul_coeff_order_add_order {Γ} [LinearOrderedCancelAddCommMonoid Γ] [Zero R] [SMulWithZero R V] (x : HahnSeries Γ R) (y : HahnModule Γ R V) : ((of R).symm (x • y)).coeff (x.order + ((of R).symm y).order) = x.leadingCoeff • ((of R).symm y).leadingCoeff := by by_cases hx : x = (0 : HahnSeries Γ R); · simp [HahnSeries.zero_coeff, hx] by_cases hy : (of R).symm y = 0; · simp [hy, smul_coeff] rw [HahnSeries.order_of_ne hx, HahnSeries.order_of_ne hy, smul_coeff, HahnSeries.leadingCoeff_of_ne hx, HahnSeries.leadingCoeff_of_ne hy] erw [Finset.vaddAntidiagonal_min_vadd_min, Finset.sum_singleton] end DistribSMul end HahnModule variable [OrderedCancelAddCommMonoid Γ] namespace HahnSeries instance [NonUnitalNonAssocSemiring R] : Mul (HahnSeries Γ R) where mul x y := (HahnModule.of R).symm (x • HahnModule.of R y) theorem of_symm_smul_of_eq_mul [NonUnitalNonAssocSemiring R] {x y : HahnSeries Γ R} : (HahnModule.of R).symm (x • HahnModule.of R y) = x * y := rfl theorem mul_coeff [NonUnitalNonAssocSemiring R] {x y : HahnSeries Γ R} {a : Γ} : (x * y).coeff a = ∑ ij ∈ addAntidiagonal x.isPWO_support y.isPWO_support a, x.coeff ij.fst * y.coeff ij.snd := rfl theorem mul_coeff_left' [NonUnitalNonAssocSemiring R] {x y : HahnSeries Γ R} {a : Γ} {s : Set Γ} (hs : s.IsPWO) (hxs : x.support ⊆ s) : (x * y).coeff a = ∑ ij ∈ addAntidiagonal hs y.isPWO_support a, x.coeff ij.fst * y.coeff ij.snd := HahnModule.smul_coeff_left hs hxs theorem mul_coeff_right' [NonUnitalNonAssocSemiring R] {x y : HahnSeries Γ R} {a : Γ} {s : Set Γ} (hs : s.IsPWO) (hys : y.support ⊆ s) : (x * y).coeff a = ∑ ij ∈ addAntidiagonal x.isPWO_support hs a, x.coeff ij.fst * y.coeff ij.snd := HahnModule.smul_coeff_right hs hys instance [NonUnitalNonAssocSemiring R] : Distrib (HahnSeries Γ R) := { inferInstanceAs (Mul (HahnSeries Γ R)), inferInstanceAs (Add (HahnSeries Γ R)) with left_distrib := fun x y z => by simp only [← of_symm_smul_of_eq_mul] exact HahnModule.smul_add x y z right_distrib := fun x y z => by simp only [← of_symm_smul_of_eq_mul] refine HahnModule.add_smul ?_ simp only [smul_eq_mul] exact add_mul } theorem single_mul_coeff_add [NonUnitalNonAssocSemiring R] {r : R} {x : HahnSeries Γ R} {a : Γ} {b : Γ} : (single b r * x).coeff (a + b) = r * x.coeff a := by rw [← of_symm_smul_of_eq_mul, add_comm, ← vadd_eq_add] exact HahnModule.single_smul_coeff_add theorem mul_single_coeff_add [NonUnitalNonAssocSemiring R] {r : R} {x : HahnSeries Γ R} {a : Γ} {b : Γ} : (x * single b r).coeff (a + b) = x.coeff a * r := by by_cases hr : r = 0 · simp [hr, mul_coeff] simp only [hr, smul_coeff, mul_coeff, support_single_of_ne, Ne, not_false_iff, smul_eq_mul] by_cases hx : x.coeff a = 0 · simp only [hx, zero_mul] rw [sum_congr _ fun _ _ => rfl, sum_empty] ext ⟨a1, a2⟩ simp only [not_mem_empty, not_and, Set.mem_singleton_iff, Classical.not_not, mem_addAntidiagonal, Set.mem_setOf_eq, iff_false_iff] rintro h2 rfl h1 rw [← add_right_cancel h1] at hx exact h2 hx trans ∑ ij ∈ {(a, b)}, x.coeff ij.fst * (single b r).coeff ij.snd · apply sum_congr _ fun _ _ => rfl ext ⟨a1, a2⟩ simp only [Set.mem_singleton_iff, Prod.mk.inj_iff, mem_addAntidiagonal, mem_singleton, Set.mem_setOf_eq] constructor · rintro ⟨_, rfl, h1⟩ exact ⟨add_right_cancel h1, rfl⟩ · rintro ⟨rfl, rfl⟩ simp [hx] · simp @[simp] theorem mul_single_zero_coeff [NonUnitalNonAssocSemiring R] {r : R} {x : HahnSeries Γ R} {a : Γ} : (x * single 0 r).coeff a = x.coeff a * r := by rw [← add_zero a, mul_single_coeff_add, add_zero] theorem single_zero_mul_coeff [NonUnitalNonAssocSemiring R] {r : R} {x : HahnSeries Γ R} {a : Γ} : ((single 0 r : HahnSeries Γ R) * x).coeff a = r * x.coeff a := by rw [← add_zero a, single_mul_coeff_add, add_zero] @[simp] theorem single_zero_mul_eq_smul [Semiring R] {r : R} {x : HahnSeries Γ R} : single 0 r * x = r • x := by ext exact single_zero_mul_coeff theorem support_mul_subset_add_support [NonUnitalNonAssocSemiring R] {x y : HahnSeries Γ R} : support (x * y) ⊆ support x + support y := by rw [← of_symm_smul_of_eq_mul, ← vadd_eq_add] exact HahnModule.support_smul_subset_vadd_support theorem mul_coeff_order_add_order {Γ} [LinearOrderedCancelAddCommMonoid Γ] [NonUnitalNonAssocSemiring R] (x y : HahnSeries Γ R) : (x * y).coeff (x.order + y.order) = x.leadingCoeff * y.leadingCoeff := by simp only [← of_symm_smul_of_eq_mul] exact HahnModule.smul_coeff_order_add_order x y private theorem mul_assoc' [NonUnitalSemiring R] (x y z : HahnSeries Γ R) : x * y * z = x * (y * z) := by ext b rw [mul_coeff_left' (x.isPWO_support.add y.isPWO_support) support_mul_subset_add_support, mul_coeff_right' (y.isPWO_support.add z.isPWO_support) support_mul_subset_add_support] simp only [mul_coeff, add_coeff, sum_mul, mul_sum, sum_sigma'] apply Finset.sum_nbij' (fun ⟨⟨_i, j⟩, ⟨k, l⟩⟩ ↦ ⟨(k, l + j), (l, j)⟩) (fun ⟨⟨i, _j⟩, ⟨k, l⟩⟩ ↦ ⟨(i + k, l), (i, k)⟩) <;> aesop (add safe Set.add_mem_add) (add simp [add_assoc, mul_assoc]) instance [NonUnitalNonAssocSemiring R] : NonUnitalNonAssocSemiring (HahnSeries Γ R) := { inferInstanceAs (AddCommMonoid (HahnSeries Γ R)), inferInstanceAs (Distrib (HahnSeries Γ R)) with zero_mul := fun _ => by ext simp [mul_coeff] mul_zero := fun _ => by ext simp [mul_coeff] } instance [NonUnitalSemiring R] : NonUnitalSemiring (HahnSeries Γ R) := { inferInstanceAs (NonUnitalNonAssocSemiring (HahnSeries Γ R)) with mul_assoc := mul_assoc' } instance [NonAssocSemiring R] : NonAssocSemiring (HahnSeries Γ R) := { AddMonoidWithOne.unary, inferInstanceAs (NonUnitalNonAssocSemiring (HahnSeries Γ R)) with one_mul := fun x => by ext exact single_zero_mul_coeff.trans (one_mul _) mul_one := fun x => by ext exact mul_single_zero_coeff.trans (mul_one _) } instance [Semiring R] : Semiring (HahnSeries Γ R) := { inferInstanceAs (NonAssocSemiring (HahnSeries Γ R)), inferInstanceAs (NonUnitalSemiring (HahnSeries Γ R)) with } instance [NonUnitalCommSemiring R] : NonUnitalCommSemiring (HahnSeries Γ R) where __ : NonUnitalSemiring (HahnSeries Γ R) := inferInstance mul_comm x y := by ext simp_rw [mul_coeff, mul_comm] exact Finset.sum_equiv (Equiv.prodComm _ _) (fun _ ↦ swap_mem_addAntidiagonal.symm) <| by simp instance [CommSemiring R] : CommSemiring (HahnSeries Γ R) := { inferInstanceAs (NonUnitalCommSemiring (HahnSeries Γ R)), inferInstanceAs (Semiring (HahnSeries Γ R)) with } instance [NonUnitalNonAssocRing R] : NonUnitalNonAssocRing (HahnSeries Γ R) := { inferInstanceAs (NonUnitalNonAssocSemiring (HahnSeries Γ R)), inferInstanceAs (AddGroup (HahnSeries Γ R)) with } instance [NonUnitalRing R] : NonUnitalRing (HahnSeries Γ R) := { inferInstanceAs (NonUnitalNonAssocRing (HahnSeries Γ R)), inferInstanceAs (NonUnitalSemiring (HahnSeries Γ R)) with } instance [NonAssocRing R] : NonAssocRing (HahnSeries Γ R) := { inferInstanceAs (NonUnitalNonAssocRing (HahnSeries Γ R)), inferInstanceAs (NonAssocSemiring (HahnSeries Γ R)) with } instance [Ring R] : Ring (HahnSeries Γ R) := { inferInstanceAs (Semiring (HahnSeries Γ R)), inferInstanceAs (AddCommGroup (HahnSeries Γ R)) with } instance [NonUnitalCommRing R] : NonUnitalCommRing (HahnSeries Γ R) := { inferInstanceAs (NonUnitalCommSemiring (HahnSeries Γ R)), inferInstanceAs (NonUnitalRing (HahnSeries Γ R)) with } instance [CommRing R] : CommRing (HahnSeries Γ R) := { inferInstanceAs (CommSemiring (HahnSeries Γ R)), inferInstanceAs (Ring (HahnSeries Γ R)) with } end HahnSeries namespace HahnModule variable [PartialOrder Γ'] [AddAction Γ Γ'] [IsOrderedCancelVAdd Γ Γ'] [AddCommMonoid V] private theorem mul_smul' [Semiring R] [Module R V] (x y : HahnSeries Γ R) (z : HahnModule Γ' R V) : (x * y) • z = x • (y • z) := by ext b rw [smul_coeff_left (x.isPWO_support.add y.isPWO_support) HahnSeries.support_mul_subset_add_support, smul_coeff_right (y.isPWO_support.vadd ((of R).symm z).isPWO_support) support_smul_subset_vadd_support] simp only [HahnSeries.mul_coeff, smul_coeff, HahnSeries.add_coeff, sum_smul, smul_sum, sum_sigma'] apply Finset.sum_nbij' (fun ⟨⟨_i, j⟩, ⟨k, l⟩⟩ ↦ ⟨(k, l +ᵥ j), (l, j)⟩) (fun ⟨⟨i, _j⟩, ⟨k, l⟩⟩ ↦ ⟨(i + k, l), (i, k)⟩) <;> aesop (add safe [Set.vadd_mem_vadd, Set.add_mem_add]) (add simp [add_vadd, mul_smul]) instance instBaseModule [Semiring R] [Module R V] : Module R (HahnModule Γ' R V) := inferInstanceAs <| Module R (HahnSeries Γ' V) instance instModule [Semiring R] [Module R V] : Module (HahnSeries Γ R) (HahnModule Γ' R V) := { inferInstanceAs (DistribSMul (HahnSeries Γ R) (HahnModule Γ' R V)) with mul_smul := mul_smul' one_smul := fun _ => one_smul' add_smul := fun _ _ _ => add_smul Module.add_smul zero_smul := fun _ => zero_smul' } instance instNoZeroSMulDivisors {Γ} [LinearOrderedCancelAddCommMonoid Γ] [Zero R] [SMulWithZero R V] [NoZeroSMulDivisors R V] : NoZeroSMulDivisors (HahnSeries Γ R) (HahnModule Γ R V) where eq_zero_or_eq_zero_of_smul_eq_zero {x y} hxy := by contrapose! hxy simp only [ne_eq] rw [HahnModule.ext_iff, Function.funext_iff, not_forall] refine ⟨x.order + ((of R).symm y).order, ?_⟩ rw [smul_coeff_order_add_order x y, of_symm_zero, HahnSeries.zero_coeff, smul_eq_zero, not_or] constructor · exact HahnSeries.leadingCoeff_ne_iff.mpr hxy.1 · exact HahnSeries.leadingCoeff_ne_iff.mpr hxy.2 end HahnModule namespace HahnSeries instance {Γ} [LinearOrderedCancelAddCommMonoid Γ] [NonUnitalNonAssocSemiring R] [NoZeroDivisors R] : NoZeroDivisors (HahnSeries Γ R) where eq_zero_or_eq_zero_of_mul_eq_zero {x y} xy := by haveI : NoZeroSMulDivisors (HahnSeries Γ R) (HahnSeries Γ R) := HahnModule.instNoZeroSMulDivisors exact eq_zero_or_eq_zero_of_smul_eq_zero xy instance {Γ} [LinearOrderedCancelAddCommMonoid Γ] [Ring R] [IsDomain R] : IsDomain (HahnSeries Γ R) := NoZeroDivisors.to_isDomain _ theorem orderTop_add_orderTop_le_orderTop_mul {Γ} [LinearOrderedCancelAddCommMonoid Γ] [NonUnitalNonAssocSemiring R] {x y : HahnSeries Γ R} : x.orderTop + y.orderTop ≤ (x * y).orderTop := by by_cases hx : x = 0; · simp [hx] by_cases hy : y = 0; · simp [hy] by_cases hxy : x * y = 0 · simp [hxy] rw [orderTop_of_ne hx, orderTop_of_ne hy, orderTop_of_ne hxy, ← WithTop.coe_add, WithTop.coe_le_coe, ← Set.IsWF.min_add] exact Set.IsWF.min_le_min_of_subset support_mul_subset_add_support @[simp] theorem order_mul {Γ} [LinearOrderedCancelAddCommMonoid Γ] [NonUnitalNonAssocSemiring R] [NoZeroDivisors R] {x y : HahnSeries Γ R} (hx : x ≠ 0) (hy : y ≠ 0) : (x * y).order = x.order + y.order := by apply le_antisymm · apply order_le_of_coeff_ne_zero rw [mul_coeff_order_add_order x y] exact mul_ne_zero (leadingCoeff_ne_iff.mpr hx) (leadingCoeff_ne_iff.mpr hy) · rw [order_of_ne hx, order_of_ne hy, order_of_ne (mul_ne_zero hx hy), ← Set.IsWF.min_add] exact Set.IsWF.min_le_min_of_subset support_mul_subset_add_support @[simp] theorem order_pow {Γ} [LinearOrderedCancelAddCommMonoid Γ] [Semiring R] [NoZeroDivisors R] (x : HahnSeries Γ R) (n : ℕ) : (x ^ n).order = n • x.order := by induction' n with h IH · simp rcases eq_or_ne x 0 with (rfl | hx) · simp rw [pow_succ, order_mul (pow_ne_zero _ hx) hx, succ_nsmul, IH] section NonUnitalNonAssocSemiring variable [NonUnitalNonAssocSemiring R] @[simp] theorem single_mul_single {a b : Γ} {r s : R} : single a r * single b s = single (a + b) (r * s) := by ext x by_cases h : x = a + b · rw [h, mul_single_coeff_add] simp · rw [single_coeff_of_ne h, mul_coeff, sum_eq_zero] simp_rw [mem_addAntidiagonal] rintro ⟨y, z⟩ ⟨hy, hz, rfl⟩ rw [eq_of_mem_support_single hy, eq_of_mem_support_single hz] at h exact (h rfl).elim end NonUnitalNonAssocSemiring section Semiring variable [Semiring R] @[simp] theorem single_pow (a : Γ) (n : ℕ) (r : R) : single a r ^ n = single (n • a) (r ^ n) := by induction' n with n IH · ext; simp only [pow_zero, one_coeff, zero_smul, single_coeff] · rw [pow_succ, pow_succ, IH, single_mul_single, succ_nsmul] end Semiring section NonAssocSemiring variable [NonAssocSemiring R] /-- `C a` is the constant Hahn Series `a`. `C` is provided as a ring homomorphism. -/ @[simps] def C : R →+* HahnSeries Γ R where toFun := single 0 map_zero' := single_eq_zero map_one' := rfl map_add' x y := by ext a by_cases h : a = 0 <;> simp [h] map_mul' x y := by rw [single_mul_single, zero_add] --@[simp] Porting note (#10618): simp can prove it theorem C_zero : C (0 : R) = (0 : HahnSeries Γ R) := C.map_zero --@[simp] Porting note (#10618): simp can prove it theorem C_one : C (1 : R) = (1 : HahnSeries Γ R) := C.map_one theorem C_injective : Function.Injective (C : R → HahnSeries Γ R) := by intro r s rs rw [HahnSeries.ext_iff, Function.funext_iff] at rs have h := rs 0 rwa [C_apply, single_coeff_same, C_apply, single_coeff_same] at h theorem C_ne_zero {r : R} (h : r ≠ 0) : (C r : HahnSeries Γ R) ≠ 0 := by contrapose! h rw [← C_zero] at h exact C_injective h theorem order_C {r : R} : order (C r : HahnSeries Γ R) = 0 := by by_cases h : r = 0 · rw [h, C_zero, order_zero] · exact order_single h end NonAssocSemiring section Semiring variable [Semiring R] theorem C_mul_eq_smul {r : R} {x : HahnSeries Γ R} : C r * x = r • x := single_zero_mul_eq_smul end Semiring section Domain variable {Γ' : Type*} [OrderedCancelAddCommMonoid Γ'] theorem embDomain_mul [NonUnitalNonAssocSemiring R] (f : Γ ↪o Γ') (hf : ∀ x y, f (x + y) = f x + f y) (x y : HahnSeries Γ R) : embDomain f (x * y) = embDomain f x * embDomain f y := by ext g by_cases hg : g ∈ Set.range f · obtain ⟨g, rfl⟩ := hg simp only [mul_coeff, embDomain_coeff] trans ∑ ij in (addAntidiagonal x.isPWO_support y.isPWO_support g).map (Function.Embedding.prodMap f.toEmbedding f.toEmbedding), (embDomain f x).coeff ij.1 * (embDomain f y).coeff ij.2 · simp apply sum_subset · rintro ⟨i, j⟩ hij simp only [exists_prop, mem_map, Prod.mk.inj_iff, mem_addAntidiagonal, Function.Embedding.coe_prodMap, mem_support, Prod.exists] at hij obtain ⟨i, j, ⟨hx, hy, rfl⟩, rfl, rfl⟩ := hij simp [hx, hy, hf] · rintro ⟨_, _⟩ h1 h2 contrapose! h2 obtain ⟨i, _, rfl⟩ := support_embDomain_subset (ne_zero_and_ne_zero_of_mul h2).1 obtain ⟨j, _, rfl⟩ := support_embDomain_subset (ne_zero_and_ne_zero_of_mul h2).2 simp only [exists_prop, mem_map, Prod.mk.inj_iff, mem_addAntidiagonal, Function.Embedding.coe_prodMap, mem_support, Prod.exists] simp only [mem_addAntidiagonal, embDomain_coeff, mem_support, ← hf, OrderEmbedding.eq_iff_eq] at h1 exact ⟨i, j, h1, rfl⟩ · rw [embDomain_notin_range hg, eq_comm] contrapose! hg obtain ⟨_, hi, _, hj, rfl⟩ := support_mul_subset_add_support ((mem_support _ _).2 hg) obtain ⟨i, _, rfl⟩ := support_embDomain_subset hi obtain ⟨j, _, rfl⟩ := support_embDomain_subset hj exact ⟨i + j, hf i j⟩ theorem embDomain_one [NonAssocSemiring R] (f : Γ ↪o Γ') (hf : f 0 = 0) : embDomain f (1 : HahnSeries Γ R) = (1 : HahnSeries Γ' R) := embDomain_single.trans <| hf.symm ▸ rfl /-- Extending the domain of Hahn series is a ring homomorphism. -/ @[simps] def embDomainRingHom [NonAssocSemiring R] (f : Γ →+ Γ') (hfi : Function.Injective f) (hf : ∀ g g' : Γ, f g ≤ f g' ↔ g ≤ g') : HahnSeries Γ R →+* HahnSeries Γ' R where toFun := embDomain ⟨⟨f, hfi⟩, hf _ _⟩ map_one' := embDomain_one _ f.map_zero map_mul' := embDomain_mul _ f.map_add map_zero' := embDomain_zero map_add' := embDomain_add _ theorem embDomainRingHom_C [NonAssocSemiring R] {f : Γ →+ Γ'} {hfi : Function.Injective f} {hf : ∀ g g' : Γ, f g ≤ f g' ↔ g ≤ g'} {r : R} : embDomainRingHom f hfi hf (C r) = C r := embDomain_single.trans (by simp) end Domain section Algebra variable [CommSemiring R] {A : Type*} [Semiring A] [Algebra R A] instance : Algebra R (HahnSeries Γ A) where toRingHom := C.comp (algebraMap R A) smul_def' r x := by ext simp commutes' r x := by ext simp only [smul_coeff, single_zero_mul_eq_smul, RingHom.coe_comp, RingHom.toFun_eq_coe, C_apply, Function.comp_apply, algebraMap_smul, mul_single_zero_coeff] rw [← Algebra.commutes, Algebra.smul_def] theorem C_eq_algebraMap : C = algebraMap R (HahnSeries Γ R) := rfl theorem algebraMap_apply {r : R} : algebraMap R (HahnSeries Γ A) r = C (algebraMap R A r) := rfl instance [Nontrivial Γ] [Nontrivial R] : Nontrivial (Subalgebra R (HahnSeries Γ R)) := ⟨⟨⊥, ⊤, by rw [Ne, SetLike.ext_iff, not_forall] obtain ⟨a, ha⟩ := exists_ne (0 : Γ) refine ⟨single a 1, ?_⟩ simp only [Algebra.mem_bot, not_exists, Set.mem_range, iff_true_iff, Algebra.mem_top] intro x rw [HahnSeries.ext_iff, Function.funext_iff, not_forall] refine ⟨a, ?_⟩ rw [single_coeff_same, algebraMap_apply, C_apply, single_coeff_of_ne ha] exact zero_ne_one⟩⟩ section Domain variable {Γ' : Type*} [OrderedCancelAddCommMonoid Γ'] /-- Extending the domain of Hahn series is an algebra homomorphism. -/ @[simps!] def embDomainAlgHom (f : Γ →+ Γ') (hfi : Function.Injective f) (hf : ∀ g g' : Γ, f g ≤ f g' ↔ g ≤ g') : HahnSeries Γ A →ₐ[R] HahnSeries Γ' A := { embDomainRingHom f hfi hf with commutes' := fun _ => embDomainRingHom_C (hf := hf) } end Domain end Algebra end HahnSeries
RingTheory\HahnSeries\PowerSeries.lean
/- Copyright (c) 2021 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.RingTheory.HahnSeries.Multiplication import Mathlib.RingTheory.PowerSeries.Basic import Mathlib.Data.Finsupp.PWO /-! # Comparison between Hahn series and power series If `Γ` is ordered and `R` has zero, then `HahnSeries Γ R` consists of formal series over `Γ` with coefficients in `R`, whose supports are partially well-ordered. With further structure on `R` and `Γ`, we can add further structure on `HahnSeries Γ R`. When `R` is a semiring and `Γ = ℕ`, then we get the more familiar semiring of formal power series with coefficients in `R`. ## Main Definitions * `toPowerSeries` the isomorphism from `HahnSeries ℕ R` to `PowerSeries R`. * `ofPowerSeries` the inverse, casting a `PowerSeries R` to a `HahnSeries ℕ R`. ## TODO * Build an API for the variable `X` (defined to be `single 1 1 : HahnSeries Γ R`) in analogy to `X : R[X]` and `X : PowerSeries R` ## References - [J. van der Hoeven, *Operators on Generalized Power Series*][van_der_hoeven] -/ open Finset Function Pointwise Polynomial noncomputable section variable {Γ : Type*} {R : Type*} namespace HahnSeries section Semiring variable [Semiring R] /-- The ring `HahnSeries ℕ R` is isomorphic to `PowerSeries R`. -/ @[simps] def toPowerSeries : HahnSeries ℕ R ≃+* PowerSeries R where toFun f := PowerSeries.mk f.coeff invFun f := ⟨fun n => PowerSeries.coeff R n f, (Nat.lt_wfRel.wf.isWF _).isPWO⟩ left_inv f := by ext simp right_inv f := by ext simp map_add' f g := by ext simp map_mul' f g := by ext n simp only [PowerSeries.coeff_mul, PowerSeries.coeff_mk, mul_coeff, isPWO_support] classical refine (sum_filter_ne_zero _).symm.trans <| (sum_congr ?_ fun _ _ ↦ rfl).trans <| sum_filter_ne_zero _ ext m simp only [mem_antidiagonal, mem_addAntidiagonal, and_congr_left_iff, mem_filter, mem_support] rintro h rw [and_iff_right (left_ne_zero_of_mul h), and_iff_right (right_ne_zero_of_mul h)] theorem coeff_toPowerSeries {f : HahnSeries ℕ R} {n : ℕ} : PowerSeries.coeff R n (toPowerSeries f) = f.coeff n := PowerSeries.coeff_mk _ _ theorem coeff_toPowerSeries_symm {f : PowerSeries R} {n : ℕ} : (HahnSeries.toPowerSeries.symm f).coeff n = PowerSeries.coeff R n f := rfl variable (Γ R) [StrictOrderedSemiring Γ] /-- Casts a power series as a Hahn series with coefficients from a `StrictOrderedSemiring`. -/ def ofPowerSeries : PowerSeries R →+* HahnSeries Γ R := (HahnSeries.embDomainRingHom (Nat.castAddMonoidHom Γ) Nat.strictMono_cast.injective fun _ _ => Nat.cast_le).comp (RingEquiv.toRingHom toPowerSeries.symm) variable {Γ} {R} theorem ofPowerSeries_injective : Function.Injective (ofPowerSeries Γ R) := embDomain_injective.comp toPowerSeries.symm.injective /-@[simp] Porting note: removing simp. RHS is more complicated and it makes linter failures elsewhere-/ theorem ofPowerSeries_apply (x : PowerSeries R) : ofPowerSeries Γ R x = HahnSeries.embDomain ⟨⟨((↑) : ℕ → Γ), Nat.strictMono_cast.injective⟩, by simp only [Function.Embedding.coeFn_mk] exact Nat.cast_le⟩ (toPowerSeries.symm x) := rfl theorem ofPowerSeries_apply_coeff (x : PowerSeries R) (n : ℕ) : (ofPowerSeries Γ R x).coeff n = PowerSeries.coeff R n x := by simp [ofPowerSeries_apply] @[simp] theorem ofPowerSeries_C (r : R) : ofPowerSeries Γ R (PowerSeries.C R r) = HahnSeries.C r := by ext n simp only [ofPowerSeries_apply, C, RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk, ne_eq, single_coeff] split_ifs with hn · subst hn convert @embDomain_coeff ℕ R _ _ Γ _ _ _ 0 <;> simp · rw [embDomain_notin_image_support] simp only [not_exists, Set.mem_image, toPowerSeries_symm_apply_coeff, mem_support, PowerSeries.coeff_C] intro simp (config := { contextual := true }) [Ne.symm hn] @[simp] theorem ofPowerSeries_X : ofPowerSeries Γ R PowerSeries.X = single 1 1 := by ext n simp only [single_coeff, ofPowerSeries_apply, RingHom.coe_mk] split_ifs with hn · rw [hn] convert @embDomain_coeff ℕ R _ _ Γ _ _ _ 1 <;> simp · rw [embDomain_notin_image_support] simp only [not_exists, Set.mem_image, toPowerSeries_symm_apply_coeff, mem_support, PowerSeries.coeff_X] intro simp (config := { contextual := true }) [Ne.symm hn] theorem ofPowerSeries_X_pow {R} [Semiring R] (n : ℕ) : ofPowerSeries Γ R (PowerSeries.X ^ n) = single (n : Γ) 1 := by simp -- Lemmas about converting hahn_series over fintype to and from mv_power_series /-- The ring `HahnSeries (σ →₀ ℕ) R` is isomorphic to `MvPowerSeries σ R` for a `Finite` `σ`. We take the index set of the hahn series to be `Finsupp` rather than `pi`, even though we assume `Finite σ` as this is more natural for alignment with `MvPowerSeries`. After importing `Algebra.Order.Pi` the ring `HahnSeries (σ → ℕ) R` could be constructed instead. -/ @[simps] def toMvPowerSeries {σ : Type*} [Finite σ] : HahnSeries (σ →₀ ℕ) R ≃+* MvPowerSeries σ R where toFun f := f.coeff invFun f := ⟨(f : (σ →₀ ℕ) → R), Finsupp.isPWO _⟩ left_inv f := by ext simp right_inv f := by ext simp map_add' f g := by ext simp map_mul' f g := by ext n simp only [MvPowerSeries.coeff_mul] classical change (f * g).coeff n = _ simp_rw [mul_coeff] refine (sum_filter_ne_zero _).symm.trans <| (sum_congr ?_ fun _ _ ↦ rfl).trans <| sum_filter_ne_zero _ ext m simp only [and_congr_left_iff, mem_addAntidiagonal, mem_filter, mem_support, Finset.mem_antidiagonal] rintro h rw [and_iff_right (left_ne_zero_of_mul h), and_iff_right (right_ne_zero_of_mul h)] variable {σ : Type*} [Finite σ] theorem coeff_toMvPowerSeries {f : HahnSeries (σ →₀ ℕ) R} {n : σ →₀ ℕ} : MvPowerSeries.coeff R n (toMvPowerSeries f) = f.coeff n := rfl theorem coeff_toMvPowerSeries_symm {f : MvPowerSeries σ R} {n : σ →₀ ℕ} : (HahnSeries.toMvPowerSeries.symm f).coeff n = MvPowerSeries.coeff R n f := rfl end Semiring section Algebra variable (R) [CommSemiring R] {A : Type*} [Semiring A] [Algebra R A] /-- The `R`-algebra `HahnSeries ℕ A` is isomorphic to `PowerSeries A`. -/ @[simps!] def toPowerSeriesAlg : HahnSeries ℕ A ≃ₐ[R] PowerSeries A := { toPowerSeries with commutes' := fun r => by ext n cases n <;> simp [algebraMap_apply, PowerSeries.algebraMap_apply] } variable (Γ) [StrictOrderedSemiring Γ] /-- Casting a power series as a Hahn series with coefficients from a `StrictOrderedSemiring` is an algebra homomorphism. -/ @[simps!] def ofPowerSeriesAlg : PowerSeries A →ₐ[R] HahnSeries Γ A := (HahnSeries.embDomainAlgHom (Nat.castAddMonoidHom Γ) Nat.strictMono_cast.injective fun _ _ => Nat.cast_le).comp (AlgEquiv.toAlgHom (toPowerSeriesAlg R).symm) instance powerSeriesAlgebra {S : Type*} [CommSemiring S] [Algebra S (PowerSeries R)] : Algebra S (HahnSeries Γ R) := RingHom.toAlgebra <| (ofPowerSeries Γ R).comp (algebraMap S (PowerSeries R)) variable {R} variable {S : Type*} [CommSemiring S] [Algebra S (PowerSeries R)] theorem algebraMap_apply' (x : S) : algebraMap S (HahnSeries Γ R) x = ofPowerSeries Γ R (algebraMap S (PowerSeries R) x) := rfl @[simp] theorem _root_.Polynomial.algebraMap_hahnSeries_apply (f : R[X]) : algebraMap R[X] (HahnSeries Γ R) f = ofPowerSeries Γ R f := rfl theorem _root_.Polynomial.algebraMap_hahnSeries_injective : Function.Injective (algebraMap R[X] (HahnSeries Γ R)) := ofPowerSeries_injective.comp (Polynomial.coe_injective R) end Algebra end HahnSeries
RingTheory\HahnSeries\Summable.lean
/- Copyright (c) 2021 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.Algebra.BigOperators.Finprod import Mathlib.RingTheory.HahnSeries.Multiplication /-! # Summable families of Hahn Series We introduce a notion of formal summability for families of Hahn series, and define a formal sum function. This theory is applied to characterize invertible Hahn series whose coefficients are in a commutative domain. ## Main Definitions * A `HahnSeries.SummableFamily` is a family of Hahn series such that the union of the supports is partially well-ordered and only finitely many are nonzero at any given coefficient. Note that this is different from `Summable` in the valuation topology, because there are topologically summable families that do not satisfy the axioms of `HahnSeries.SummableFamily`, and formally summable families whose sums do not converge topologically. * The formal sum, `HahnSeries.SummableFamily.hsum` can be bundled as a `LinearMap` via `HahnSeries.SummableFamily.lsum`. ## Main results * If `R` is a commutative domain, and `Γ` is a linearly ordered additive commutative group, then a Hahn series is a unit if and only if its leading term is a unit in `R`. ## TODO * Remove unnecessary domain hypotheses. * More general summable families, e.g., define the evaluation homomorphism from a power series ring taking `X` to a positive order element. * Generalize `SMul` to Hahn modules. ## References - [J. van der Hoeven, *Operators on Generalized Power Series*][van_der_hoeven] -/ open Finset Function open Pointwise noncomputable section variable {Γ : Type*} {R : Type*} namespace HahnSeries theorem isPWO_iUnion_support_powers [LinearOrderedCancelAddCommMonoid Γ] [Ring R] [IsDomain R] {x : HahnSeries Γ R} (hx : 0 < x.orderTop) : (⋃ n : ℕ, (x ^ n).support).IsPWO := by apply (x.isWF_support.isPWO.addSubmonoid_closure _).mono _ · exact fun g hg => WithTop.coe_le_coe.1 (le_trans (le_of_lt hx) (orderTop_le_of_coeff_ne_zero hg)) refine Set.iUnion_subset fun n => ?_ induction' n with n ih <;> intro g hn · simp only [Nat.zero_eq, pow_zero, support_one, Set.mem_singleton_iff] at hn rw [hn, SetLike.mem_coe] exact AddSubmonoid.zero_mem _ · obtain ⟨i, hi, j, hj, rfl⟩ := support_mul_subset_add_support hn exact SetLike.mem_coe.2 (AddSubmonoid.add_mem _ (ih hi) (AddSubmonoid.subset_closure hj)) section variable (Γ) (R) [PartialOrder Γ] [AddCommMonoid R] /-- A family of Hahn series whose formal coefficient-wise sum is a Hahn series. For each coefficient of the sum to be well-defined, we require that only finitely many series are nonzero at any given coefficient. For the formal sum to be a Hahn series, we require that the union of the supports of the constituent series is partially well-ordered. -/ structure SummableFamily (α : Type*) where /-- A parametrized family of Hahn series. -/ toFun : α → HahnSeries Γ R isPWO_iUnion_support' : Set.IsPWO (⋃ a : α, (toFun a).support) finite_co_support' : ∀ g : Γ, { a | (toFun a).coeff g ≠ 0 }.Finite end namespace SummableFamily section AddCommMonoid variable [PartialOrder Γ] [AddCommMonoid R] {α : Type*} instance : FunLike (SummableFamily Γ R α) α (HahnSeries Γ R) where coe := toFun coe_injective' | ⟨_, _, _⟩, ⟨_, _, _⟩, rfl => rfl theorem isPWO_iUnion_support (s : SummableFamily Γ R α) : Set.IsPWO (⋃ a : α, (s a).support) := s.isPWO_iUnion_support' theorem finite_co_support (s : SummableFamily Γ R α) (g : Γ) : (Function.support fun a => (s a).coeff g).Finite := s.finite_co_support' g theorem coe_injective : @Function.Injective (SummableFamily Γ R α) (α → HahnSeries Γ R) (⇑) := DFunLike.coe_injective @[ext] theorem ext {s t : SummableFamily Γ R α} (h : ∀ a : α, s a = t a) : s = t := DFunLike.ext s t h instance : Add (SummableFamily Γ R α) := ⟨fun x y => { toFun := x + y isPWO_iUnion_support' := (x.isPWO_iUnion_support.union y.isPWO_iUnion_support).mono (by rw [← Set.iUnion_union_distrib] exact Set.iUnion_mono fun a => support_add_subset) finite_co_support' := fun g => ((x.finite_co_support g).union (y.finite_co_support g)).subset (by intro a ha change (x a).coeff g + (y a).coeff g ≠ 0 at ha rw [Set.mem_union, Function.mem_support, Function.mem_support] contrapose! ha rw [ha.1, ha.2, add_zero]) }⟩ instance : Zero (SummableFamily Γ R α) := ⟨⟨0, by simp, by simp⟩⟩ instance : Inhabited (SummableFamily Γ R α) := ⟨0⟩ @[simp] theorem coe_add {s t : SummableFamily Γ R α} : ⇑(s + t) = s + t := rfl theorem add_apply {s t : SummableFamily Γ R α} {a : α} : (s + t) a = s a + t a := rfl @[simp] theorem coe_zero : ((0 : SummableFamily Γ R α) : α → HahnSeries Γ R) = 0 := rfl theorem zero_apply {a : α} : (0 : SummableFamily Γ R α) a = 0 := rfl instance : AddCommMonoid (SummableFamily Γ R α) where zero := 0 nsmul := nsmulRec zero_add s := by ext apply zero_add add_zero s := by ext apply add_zero add_comm s t := by ext apply add_comm add_assoc r s t := by ext apply add_assoc /-- The infinite sum of a `SummableFamily` of Hahn series. -/ def hsum (s : SummableFamily Γ R α) : HahnSeries Γ R where coeff g := ∑ᶠ i, (s i).coeff g isPWO_support' := s.isPWO_iUnion_support.mono fun g => by contrapose rw [Set.mem_iUnion, not_exists, Function.mem_support, Classical.not_not] simp_rw [mem_support, Classical.not_not] intro h rw [finsum_congr h, finsum_zero] @[simp] theorem hsum_coeff {s : SummableFamily Γ R α} {g : Γ} : s.hsum.coeff g = ∑ᶠ i, (s i).coeff g := rfl theorem support_hsum_subset {s : SummableFamily Γ R α} : s.hsum.support ⊆ ⋃ a : α, (s a).support := fun g hg => by rw [mem_support, hsum_coeff, finsum_eq_sum _ (s.finite_co_support _)] at hg obtain ⟨a, _, h2⟩ := exists_ne_zero_of_sum_ne_zero hg rw [Set.mem_iUnion] exact ⟨a, h2⟩ @[simp] theorem hsum_add {s t : SummableFamily Γ R α} : (s + t).hsum = s.hsum + t.hsum := by ext g simp only [hsum_coeff, add_coeff, add_apply] exact finsum_add_distrib (s.finite_co_support _) (t.finite_co_support _) end AddCommMonoid section AddCommGroup variable [PartialOrder Γ] [AddCommGroup R] {α : Type*} {s t : SummableFamily Γ R α} {a : α} instance : Neg (SummableFamily Γ R α) := ⟨fun s => { toFun := fun a => -s a isPWO_iUnion_support' := by simp_rw [support_neg] exact s.isPWO_iUnion_support finite_co_support' := fun g => by simp only [neg_coeff', Pi.neg_apply, Ne, neg_eq_zero] exact s.finite_co_support g }⟩ instance : AddCommGroup (SummableFamily Γ R α) := { inferInstanceAs (AddCommMonoid (SummableFamily Γ R α)) with zsmul := zsmulRec add_left_neg := fun a => by ext apply add_left_neg } @[simp] theorem coe_neg : ⇑(-s) = -s := rfl theorem neg_apply : (-s) a = -s a := rfl @[simp] theorem coe_sub : ⇑(s - t) = s - t := rfl theorem sub_apply : (s - t) a = s a - t a := rfl end AddCommGroup section Semiring variable [OrderedCancelAddCommMonoid Γ] [Semiring R] {α : Type*} instance : SMul (HahnSeries Γ R) (SummableFamily Γ R α) where smul x s := { toFun := fun a => x * s a isPWO_iUnion_support' := by apply (x.isPWO_support.add s.isPWO_iUnion_support).mono refine Set.Subset.trans (Set.iUnion_mono fun a => support_mul_subset_add_support) ?_ intro g simp only [Set.mem_iUnion, exists_imp] exact fun a ha => (Set.add_subset_add (Set.Subset.refl _) (Set.subset_iUnion _ a)) ha finite_co_support' := fun g => by apply ((addAntidiagonal x.isPWO_support s.isPWO_iUnion_support g).finite_toSet.biUnion' fun ij _ => ?_).subset fun a ha => ?_ · exact fun ij _ => Function.support fun a => (s a).coeff ij.2 · apply s.finite_co_support · obtain ⟨i, hi, j, hj, rfl⟩ := support_mul_subset_add_support ha simp only [exists_prop, Set.mem_iUnion, mem_addAntidiagonal, mul_coeff, mem_support, isPWO_support, Prod.exists] exact ⟨i, j, mem_coe.2 (mem_addAntidiagonal.2 ⟨hi, Set.mem_iUnion.2 ⟨a, hj⟩, rfl⟩), hj⟩ } @[simp] theorem smul_apply {x : HahnSeries Γ R} {s : SummableFamily Γ R α} {a : α} : (x • s) a = x * s a := rfl instance : Module (HahnSeries Γ R) (SummableFamily Γ R α) where smul := (· • ·) smul_zero _ := ext fun _ => mul_zero _ zero_smul _ := ext fun _ => zero_mul _ one_smul _ := ext fun _ => one_mul _ add_smul _ _ _ := ext fun _ => add_mul _ _ _ smul_add _ _ _ := ext fun _ => mul_add _ _ _ mul_smul _ _ _ := ext fun _ => mul_assoc _ _ _ @[simp] theorem hsum_smul {x : HahnSeries Γ R} {s : SummableFamily Γ R α} : (x • s).hsum = x * s.hsum := by ext g simp only [mul_coeff, hsum_coeff, smul_apply] refine (Eq.trans (finsum_congr fun a => ?_) (finsum_sum_comm (addAntidiagonal x.isPWO_support s.isPWO_iUnion_support g) (fun i ij => x.coeff (Prod.fst ij) * (s i).coeff ij.snd) ?_)).trans ?_ · refine sum_subset (addAntidiagonal_mono_right (Set.subset_iUnion (fun j => support (toFun s j)) a)) ?_ rintro ⟨i, j⟩ hU ha rw [mem_addAntidiagonal] at * rw [Classical.not_not.1 fun con => ha ⟨hU.1, con, hU.2.2⟩, mul_zero] · rintro ⟨i, j⟩ _ refine (s.finite_co_support j).subset ?_ simp_rw [Function.support_subset_iff', Function.mem_support, Classical.not_not] intro a ha rw [ha, mul_zero] · refine (sum_congr rfl ?_).trans (sum_subset (addAntidiagonal_mono_right ?_) ?_).symm · rintro ⟨i, j⟩ _ rw [mul_finsum] apply s.finite_co_support · intro x hx simp only [Set.mem_iUnion, Ne, mem_support] contrapose! hx simp [hx] · rintro ⟨i, j⟩ hU ha rw [mem_addAntidiagonal] at * rw [← hsum_coeff, Classical.not_not.1 fun con => ha ⟨hU.1, con, hU.2.2⟩, mul_zero] /-- The summation of a `summable_family` as a `LinearMap`. -/ @[simps] def lsum : SummableFamily Γ R α →ₗ[HahnSeries Γ R] HahnSeries Γ R where toFun := hsum map_add' _ _ := hsum_add map_smul' _ _ := hsum_smul @[simp] theorem hsum_sub {R : Type*} [Ring R] {s t : SummableFamily Γ R α} : (s - t).hsum = s.hsum - t.hsum := by rw [← lsum_apply, LinearMap.map_sub, lsum_apply, lsum_apply] end Semiring section OfFinsupp variable [PartialOrder Γ] [AddCommMonoid R] {α : Type*} /-- A family with only finitely many nonzero elements is summable. -/ def ofFinsupp (f : α →₀ HahnSeries Γ R) : SummableFamily Γ R α where toFun := f isPWO_iUnion_support' := by apply (f.support.isPWO_bUnion.2 fun a _ => (f a).isPWO_support).mono refine Set.iUnion_subset_iff.2 fun a g hg => ?_ have haf : a ∈ f.support := by rw [Finsupp.mem_support_iff, ← support_nonempty_iff] exact ⟨g, hg⟩ exact Set.mem_biUnion haf hg finite_co_support' g := by refine f.support.finite_toSet.subset fun a ha => ?_ simp only [coeff.addMonoidHom_apply, mem_coe, Finsupp.mem_support_iff, Ne, Function.mem_support] contrapose! ha simp [ha] @[simp] theorem coe_ofFinsupp {f : α →₀ HahnSeries Γ R} : ⇑(SummableFamily.ofFinsupp f) = f := rfl @[simp] theorem hsum_ofFinsupp {f : α →₀ HahnSeries Γ R} : (ofFinsupp f).hsum = f.sum fun _ => id := by ext g simp only [hsum_coeff, coe_ofFinsupp, Finsupp.sum, Ne] simp_rw [← coeff.addMonoidHom_apply, id] rw [map_sum, finsum_eq_sum_of_support_subset] intro x h simp only [coeff.addMonoidHom_apply, mem_coe, Finsupp.mem_support_iff, Ne] contrapose! h simp [h] end OfFinsupp section EmbDomain variable [PartialOrder Γ] [AddCommMonoid R] {α β : Type*} open Classical in /-- A summable family can be reindexed by an embedding without changing its sum. -/ def embDomain (s : SummableFamily Γ R α) (f : α ↪ β) : SummableFamily Γ R β where toFun b := if h : b ∈ Set.range f then s (Classical.choose h) else 0 isPWO_iUnion_support' := by refine s.isPWO_iUnion_support.mono (Set.iUnion_subset fun b g h => ?_) by_cases hb : b ∈ Set.range f · dsimp only at h rw [dif_pos hb] at h exact Set.mem_iUnion.2 ⟨Classical.choose hb, h⟩ · simp [-Set.mem_range, dif_neg hb] at h finite_co_support' g := ((s.finite_co_support g).image f).subset (by intro b h by_cases hb : b ∈ Set.range f · simp only [Ne, Set.mem_setOf_eq, dif_pos hb] at h exact ⟨Classical.choose hb, h, Classical.choose_spec hb⟩ · simp only [Ne, Set.mem_setOf_eq, dif_neg hb, zero_coeff, not_true_eq_false] at h) variable (s : SummableFamily Γ R α) (f : α ↪ β) {a : α} {b : β} open Classical in theorem embDomain_apply : s.embDomain f b = if h : b ∈ Set.range f then s (Classical.choose h) else 0 := rfl @[simp] theorem embDomain_image : s.embDomain f (f a) = s a := by rw [embDomain_apply, dif_pos (Set.mem_range_self a)] exact congr rfl (f.injective (Classical.choose_spec (Set.mem_range_self a))) @[simp] theorem embDomain_notin_range (h : b ∉ Set.range f) : s.embDomain f b = 0 := by rw [embDomain_apply, dif_neg h] @[simp] theorem hsum_embDomain : (s.embDomain f).hsum = s.hsum := by classical ext g simp only [hsum_coeff, embDomain_apply, apply_dite HahnSeries.coeff, dite_apply, zero_coeff] exact finsum_emb_domain f fun a => (s a).coeff g end EmbDomain section powers variable [LinearOrderedCancelAddCommMonoid Γ] [CommRing R] [IsDomain R] /-- The powers of an element of positive valuation form a summable family. -/ def powers (x : HahnSeries Γ R) (hx : 0 < x.orderTop) : SummableFamily Γ R ℕ where toFun n := x ^ n isPWO_iUnion_support' := isPWO_iUnion_support_powers hx finite_co_support' g := by have hpwo := isPWO_iUnion_support_powers hx by_cases hg : g ∈ ⋃ n : ℕ, { g | (x ^ n).coeff g ≠ 0 } swap; · exact Set.finite_empty.subset fun n hn => hg (Set.mem_iUnion.2 ⟨n, hn⟩) apply hpwo.isWF.induction hg intro y ys hy refine ((((addAntidiagonal x.isPWO_support hpwo y).finite_toSet.biUnion fun ij hij => hy ij.snd ?_ ?_).image Nat.succ).union (Set.finite_singleton 0)).subset ?_ · exact (mem_addAntidiagonal.1 (mem_coe.1 hij)).2.1 · obtain ⟨hi, _, rfl⟩ := mem_addAntidiagonal.1 (mem_coe.1 hij) rw [← zero_add ij.snd, ← add_assoc, add_zero] exact add_lt_add_right (WithTop.coe_lt_coe.1 (hx.trans_le (orderTop_le_of_coeff_ne_zero hi))) _ · rintro (_ | n) hn · exact Set.mem_union_right _ (Set.mem_singleton 0) · obtain ⟨i, hi, j, hj, rfl⟩ := support_mul_subset_add_support hn refine Set.mem_union_left _ ⟨n, Set.mem_iUnion.2 ⟨⟨j, i⟩, Set.mem_iUnion.2 ⟨?_, hi⟩⟩, rfl⟩ simp only [and_true_iff, Set.mem_iUnion, mem_addAntidiagonal, mem_coe, eq_self_iff_true, Ne, mem_support, Set.mem_setOf_eq] exact ⟨hj, ⟨n, hi⟩, add_comm j i⟩ variable {x : HahnSeries Γ R} (hx : 0 < x.orderTop) @[simp] theorem coe_powers : ⇑(powers x hx) = HPow.hPow x := rfl theorem embDomain_succ_smul_powers : (x • powers x hx).embDomain ⟨Nat.succ, Nat.succ_injective⟩ = powers x hx - ofFinsupp (Finsupp.single 0 1) := by apply SummableFamily.ext rintro (_ | n) · rw [embDomain_notin_range, sub_apply, coe_powers, pow_zero, coe_ofFinsupp, Finsupp.single_eq_same, sub_self] rw [Set.mem_range, not_exists] exact Nat.succ_ne_zero · refine Eq.trans (embDomain_image _ ⟨Nat.succ, Nat.succ_injective⟩) ?_ simp only [pow_succ', coe_powers, coe_sub, smul_apply, coe_ofFinsupp, Pi.sub_apply] rw [Finsupp.single_eq_of_ne n.succ_ne_zero.symm, sub_zero] theorem one_sub_self_mul_hsum_powers : (1 - x) * (powers x hx).hsum = 1 := by rw [← hsum_smul, sub_smul 1 x (powers x hx), one_smul, hsum_sub, ← hsum_embDomain (x • powers x hx) ⟨Nat.succ, Nat.succ_injective⟩, embDomain_succ_smul_powers] simp end powers end SummableFamily section Inversion variable [LinearOrderedAddCommGroup Γ] section IsDomain variable [CommRing R] [IsDomain R] theorem unit_aux (x : HahnSeries Γ R) {r : R} (hr : r * x.leadingCoeff = 1) : 0 < (1 - single (-x.order) r * x).orderTop := by by_cases hx : x = 0; · simp_all [hx] have hrz : r ≠ 0 := by intro h rw [h, zero_mul] at hr exact (zero_ne_one' R) hr refine lt_of_le_of_ne (le_trans ?_ min_orderTop_le_orderTop_sub) fun h => ?_ · refine le_min (by rw [orderTop_one]) ?_ refine le_trans ?_ orderTop_add_orderTop_le_orderTop_mul by_cases h : x = 0; · simp [h] rw [← order_eq_orderTop_of_ne h, orderTop_single (fun _ => by simp_all only [zero_mul, zero_ne_one]), ← @WithTop.coe_add, WithTop.coe_nonneg, add_left_neg] · apply coeff_orderTop_ne h.symm simp only [C_apply, single_mul_single, zero_add, mul_one, sub_coeff', Pi.sub_apply, one_coeff, ↓reduceIte] have hrc := mul_coeff_order_add_order ((single (-x.order)) r) x rw [order_single hrz, leadingCoeff_of_single, neg_add_self, hr] at hrc rw [hrc, sub_self] theorem isUnit_iff {x : HahnSeries Γ R} : IsUnit x ↔ IsUnit (x.leadingCoeff) := by constructor · rintro ⟨⟨u, i, ui, iu⟩, rfl⟩ refine isUnit_of_mul_eq_one (u.leadingCoeff) (i.leadingCoeff) ((mul_coeff_order_add_order u i).symm.trans ?_) rw [ui, one_coeff, if_pos] rw [← order_mul (left_ne_zero_of_mul_eq_one ui) (right_ne_zero_of_mul_eq_one ui), ui, order_one] · rintro ⟨⟨u, i, ui, iu⟩, h⟩ rw [Units.val_mk] at h rw [h] at iu have h := SummableFamily.one_sub_self_mul_hsum_powers (unit_aux x iu) rw [sub_sub_cancel] at h exact isUnit_of_mul_isUnit_right (isUnit_of_mul_eq_one _ _ h) end IsDomain open Classical in instance instField [Field R] : Field (HahnSeries Γ R) where __ : IsDomain (HahnSeries Γ R) := inferInstance inv x := if x0 : x = 0 then 0 else (single (-x.order)) (x.leadingCoeff)⁻¹ * (SummableFamily.powers _ (unit_aux x (inv_mul_cancel (leadingCoeff_ne_iff.mpr x0)))).hsum inv_zero := dif_pos rfl mul_inv_cancel x x0 := (congr rfl (dif_neg x0)).trans $ by have h := SummableFamily.one_sub_self_mul_hsum_powers (unit_aux x (inv_mul_cancel (leadingCoeff_ne_iff.mpr x0))) rw [sub_sub_cancel] at h rw [← mul_assoc, mul_comm x, h] nnqsmul := _ nnqsmul_def := fun q a => rfl qsmul := _ qsmul_def := fun q a => rfl end Inversion end HahnSeries
RingTheory\HahnSeries\Valuation.lean
/- Copyright (c) 2021 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.RingTheory.HahnSeries.Multiplication import Mathlib.RingTheory.Valuation.Basic /-! # Valuations on Hahn Series rings If `Γ` is a `LinearOrderedCancelAddCommMonoid` and `R` is a domain, then the domain `HahnSeries Γ R` admits an additive valuation given by `orderTop`. ## Main Definitions * `HahnSeries.addVal Γ R` defines an `AddValuation` on `HahnSeries Γ R` when `Γ` is linearly ordered. ## TODO * Multiplicative valuations * Add any API for Laurent series valuations that do not depend on `Γ = ℤ`. ## References - [J. van der Hoeven, *Operators on Generalized Power Series*][van_der_hoeven] -/ noncomputable section variable {Γ R : Type*} namespace HahnSeries section Valuation variable (Γ R) [LinearOrderedCancelAddCommMonoid Γ] [Ring R] [IsDomain R] /-- The additive valuation on `HahnSeries Γ R`, returning the smallest index at which a Hahn Series has a nonzero coefficient, or `⊤` for the 0 series. -/ def addVal : AddValuation (HahnSeries Γ R) (WithTop Γ) := AddValuation.of orderTop orderTop_zero (orderTop_one) (fun x y => min_orderTop_le_orderTop_add) fun x y => by by_cases hx : x = 0; · simp [hx] by_cases hy : y = 0; · simp [hy] rw [← order_eq_orderTop_of_ne hx, ← order_eq_orderTop_of_ne hy, ← order_eq_orderTop_of_ne (mul_ne_zero hx hy), ← WithTop.coe_add, WithTop.coe_eq_coe, order_mul hx hy] variable {Γ} {R} theorem addVal_apply {x : HahnSeries Γ R} : addVal Γ R x = x.orderTop := AddValuation.of_apply _ @[simp] theorem addVal_apply_of_ne {x : HahnSeries Γ R} (hx : x ≠ 0) : addVal Γ R x = x.order := addVal_apply.trans (order_eq_orderTop_of_ne hx).symm theorem addVal_le_of_coeff_ne_zero {x : HahnSeries Γ R} {g : Γ} (h : x.coeff g ≠ 0) : addVal Γ R x ≤ g := orderTop_le_of_coeff_ne_zero h end Valuation end HahnSeries
RingTheory\Ideal\AssociatedPrime.lean
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.LinearAlgebra.Span import Mathlib.RingTheory.Ideal.IsPrimary import Mathlib.RingTheory.Ideal.QuotientOperations import Mathlib.RingTheory.Noetherian /-! # 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] /-- `IsAssociatedPrime I M` if the prime ideal `I` is the annihilator of some `x : M`. -/ def IsAssociatedPrime : Prop := I.IsPrime ∧ ∃ x : M, I = (R ∙ x).annihilator 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 rw [Submodule.mem_annihilator_span_singleton, Submodule.mem_annihilator_span_singleton, ← 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 rwa [Subsingleton.elim x 0, Submodule.span_singleton_eq_bot.mpr rfl, Submodule.annihilator_bot] at hx variable (R) theorem exists_le_isAssociatedPrime_of_isNoetherianRing [H : IsNoetherianRing R] (x : M) (hx : x ≠ 0) : ∃ P : Ideal R, IsAssociatedPrime P M ∧ (R ∙ x).annihilator ≤ P := by have : (R ∙ x).annihilator ≠ ⊤ := by rwa [Ne, Ideal.eq_top_iff_one, Submodule.mem_annihilator_span_singleton, one_smul] obtain ⟨P, ⟨l, h₁, y, rfl⟩, h₃⟩ := set_has_maximal_iff_noetherian.mpr H { P | (R ∙ x).annihilator ≤ P ∧ P ≠ ⊤ ∧ ∃ y : M, P = (R ∙ y).annihilator } ⟨(R ∙ x).annihilator, rfl.le, this, x, rfl⟩ refine ⟨_, ⟨⟨h₁, ?_⟩, y, rfl⟩, l⟩ intro a b hab rw [or_iff_not_imp_left] intro ha rw [Submodule.mem_annihilator_span_singleton] at ha hab have H₁ : (R ∙ y).annihilator ≤ (R ∙ a • y).annihilator := by intro c hc rw [Submodule.mem_annihilator_span_singleton] at hc ⊢ rw [smul_comm, hc, smul_zero] have H₂ : (Submodule.span R {a • y}).annihilator ≠ ⊤ := by rwa [Ne, Submodule.annihilator_eq_top_iff, Submodule.span_singleton_eq_bot] rwa [H₁.eq_of_not_lt (h₃ (R ∙ a • y).annihilator ⟨l.trans H₁, H₂, _, rfl⟩), Submodule.mem_annihilator_span_singleton, smul_comm, smul_smul] variable {R} theorem associatedPrimes.subset_of_injective (hf : Function.Injective f) : associatedPrimes R M ⊆ associatedPrimes R M' := fun _I h => h.map_of_injective f hf theorem LinearEquiv.AssociatedPrimes.eq (l : M ≃ₗ[R] M') : associatedPrimes R M = associatedPrimes R M' := le_antisymm (associatedPrimes.subset_of_injective l l.injective) (associatedPrimes.subset_of_injective l.symm 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_iff] 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 simp_rw [← Submodule.mem_annihilator_span_singleton] refine subset_antisymm (Set.iUnion₂_subset ?_) ?_ · rintro _ ⟨h, x, ⟨⟩⟩ r h' refine ⟨x, ne_of_eq_of_ne (one_smul R x).symm ?_, h'⟩ refine mt (Submodule.mem_annihilator_span_singleton _ _).mpr ?_ 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') variable {R M} theorem IsAssociatedPrime.annihilator_le (h : IsAssociatedPrime I M) : (⊤ : Submodule R M).annihilator ≤ I := by obtain ⟨hI, x, rfl⟩ := h 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 [Submodule.span_singleton_eq_bot.mpr rfl, Submodule.annihilator_bot] at e obtain ⟨x, rfl⟩ := Ideal.Quotient.mkₐ_surjective R _ x replace e : ∀ {y}, y ∈ J ↔ x * y ∈ I := by intro y rw [e, Submodule.mem_annihilator_span_singleton, ← 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 (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
RingTheory\Ideal\Basic.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Chris Hughes, Mario Carneiro -/ import Mathlib.Tactic.FinCases import Mathlib.Data.Nat.Choose.Sum import Mathlib.LinearAlgebra.Finsupp import Mathlib.Algebra.Field.IsField import Mathlib.Tactic.Abel /-! # Ideals over a ring This file defines `Ideal R`, the type of (left) ideals over a ring `R`. Note that over commutative rings, left ideals and two-sided ideals are equivalent. ## Implementation notes `Ideal R` is implemented using `Submodule R R`, where `•` is interpreted as `*`. ## TODO Support right ideals, and two-sided ideals over non-commutative rings. -/ universe u v w variable {α : Type u} {β : Type v} open Set Function open Pointwise /-- A (left) ideal in a semiring `R` is an additive submonoid `s` such that `a * b ∈ s` whenever `b ∈ s`. If `R` is a ring, then `s` is an additive subgroup. -/ abbrev Ideal (R : Type u) [Semiring R] := Submodule R R /-- A ring is a principal ideal ring if all (left) ideals are principal. -/ @[mk_iff] class IsPrincipalIdealRing (R : Type u) [Semiring R] : Prop where principal : ∀ S : Ideal R, S.IsPrincipal attribute [instance] IsPrincipalIdealRing.principal section Semiring namespace Ideal variable [Semiring α] (I : Ideal α) {a b : α} protected theorem zero_mem : (0 : α) ∈ I := Submodule.zero_mem I protected theorem add_mem : a ∈ I → b ∈ I → a + b ∈ I := Submodule.add_mem I variable (a) theorem mul_mem_left : b ∈ I → a * b ∈ I := Submodule.smul_mem I a variable {a} @[ext] theorem ext {I J : Ideal α} (h : ∀ x, x ∈ I ↔ x ∈ J) : I = J := Submodule.ext h theorem sum_mem (I : Ideal α) {ι : Type*} {t : Finset ι} {f : ι → α} : (∀ c ∈ t, f c ∈ I) → (∑ i ∈ t, f i) ∈ I := Submodule.sum_mem I theorem eq_top_of_unit_mem (x y : α) (hx : x ∈ I) (h : y * x = 1) : I = ⊤ := eq_top_iff.2 fun z _ => calc z = z * (y * x) := by simp [h] _ = z * y * x := Eq.symm <| mul_assoc z y x _ ∈ I := I.mul_mem_left _ hx theorem eq_top_of_isUnit_mem {x} (hx : x ∈ I) (h : IsUnit x) : I = ⊤ := let ⟨y, hy⟩ := h.exists_left_inv eq_top_of_unit_mem I x y hx hy theorem eq_top_iff_one : I = ⊤ ↔ (1 : α) ∈ I := ⟨by rintro rfl; trivial, fun h => eq_top_of_unit_mem _ _ 1 h (by simp)⟩ theorem ne_top_iff_one : I ≠ ⊤ ↔ (1 : α) ∉ I := not_congr I.eq_top_iff_one @[simp] theorem unit_mul_mem_iff_mem {x y : α} (hy : IsUnit y) : y * x ∈ I ↔ x ∈ I := by refine ⟨fun h => ?_, fun h => I.mul_mem_left y h⟩ obtain ⟨y', hy'⟩ := hy.exists_left_inv have := I.mul_mem_left y' h rwa [← mul_assoc, hy', one_mul] at this /-- The ideal generated by a subset of a ring -/ def span (s : Set α) : Ideal α := Submodule.span α s @[simp] theorem submodule_span_eq {s : Set α} : Submodule.span α s = Ideal.span s := rfl @[simp] theorem span_empty : span (∅ : Set α) = ⊥ := Submodule.span_empty @[simp] theorem span_univ : span (Set.univ : Set α) = ⊤ := Submodule.span_univ theorem span_union (s t : Set α) : span (s ∪ t) = span s ⊔ span t := Submodule.span_union _ _ theorem span_iUnion {ι} (s : ι → Set α) : span (⋃ i, s i) = ⨆ i, span (s i) := Submodule.span_iUnion _ theorem mem_span {s : Set α} (x) : x ∈ span s ↔ ∀ p : Ideal α, s ⊆ p → x ∈ p := mem_iInter₂ theorem subset_span {s : Set α} : s ⊆ span s := Submodule.subset_span theorem span_le {s : Set α} {I} : span s ≤ I ↔ s ⊆ I := Submodule.span_le theorem span_mono {s t : Set α} : s ⊆ t → span s ≤ span t := Submodule.span_mono @[simp] theorem span_eq : span (I : Set α) = I := Submodule.span_eq _ @[simp] theorem span_singleton_one : span ({1} : Set α) = ⊤ := (eq_top_iff_one _).2 <| subset_span <| mem_singleton _ theorem isCompactElement_top : CompleteLattice.IsCompactElement (⊤ : Ideal α) := by simpa only [← span_singleton_one] using Submodule.singleton_span_isCompactElement 1 theorem mem_span_insert {s : Set α} {x y} : x ∈ span (insert y s) ↔ ∃ a, ∃ z ∈ span s, x = a * y + z := Submodule.mem_span_insert theorem mem_span_singleton' {x y : α} : x ∈ span ({y} : Set α) ↔ ∃ a, a * y = x := Submodule.mem_span_singleton theorem span_singleton_le_iff_mem {x : α} : span {x} ≤ I ↔ x ∈ I := Submodule.span_singleton_le_iff_mem _ _ theorem span_singleton_mul_left_unit {a : α} (h2 : IsUnit a) (x : α) : span ({a * x} : Set α) = span {x} := by apply le_antisymm <;> rw [span_singleton_le_iff_mem, mem_span_singleton'] exacts [⟨a, rfl⟩, ⟨_, h2.unit.inv_mul_cancel_left x⟩] theorem span_insert (x) (s : Set α) : span (insert x s) = span ({x} : Set α) ⊔ span s := Submodule.span_insert x s theorem span_eq_bot {s : Set α} : span s = ⊥ ↔ ∀ x ∈ s, (x : α) = 0 := Submodule.span_eq_bot @[simp] theorem span_singleton_eq_bot {x} : span ({x} : Set α) = ⊥ ↔ x = 0 := Submodule.span_singleton_eq_bot theorem span_singleton_ne_top {α : Type*} [CommSemiring α] {x : α} (hx : ¬IsUnit x) : Ideal.span ({x} : Set α) ≠ ⊤ := (Ideal.ne_top_iff_one _).mpr fun h1 => let ⟨y, hy⟩ := Ideal.mem_span_singleton'.mp h1 hx ⟨⟨x, y, mul_comm y x ▸ hy, hy⟩, rfl⟩ @[simp] theorem span_zero : span (0 : Set α) = ⊥ := by rw [← Set.singleton_zero, span_singleton_eq_bot] @[simp] theorem span_one : span (1 : Set α) = ⊤ := by rw [← Set.singleton_one, span_singleton_one] theorem span_eq_top_iff_finite (s : Set α) : span s = ⊤ ↔ ∃ s' : Finset α, ↑s' ⊆ s ∧ span (s' : Set α) = ⊤ := by simp_rw [eq_top_iff_one] exact ⟨Submodule.mem_span_finite_of_mem_span, fun ⟨s', h₁, h₂⟩ => span_mono h₁ h₂⟩ theorem mem_span_singleton_sup {S : Type*} [CommSemiring S] {x y : S} {I : Ideal S} : x ∈ Ideal.span {y} ⊔ I ↔ ∃ a : S, ∃ b ∈ I, a * y + b = x := by rw [Submodule.mem_sup] constructor · rintro ⟨ya, hya, b, hb, rfl⟩ obtain ⟨a, rfl⟩ := mem_span_singleton'.mp hya exact ⟨a, b, hb, rfl⟩ · rintro ⟨a, b, hb, rfl⟩ exact ⟨a * y, Ideal.mem_span_singleton'.mpr ⟨a, rfl⟩, b, hb, rfl⟩ /-- The ideal generated by an arbitrary binary relation. -/ def ofRel (r : α → α → Prop) : Ideal α := Submodule.span α { x | ∃ a b, r a b ∧ x + b = a } /-- An ideal `P` of a ring `R` is prime if `P ≠ R` and `xy ∈ P → x ∈ P ∨ y ∈ P` -/ class IsPrime (I : Ideal α) : Prop where /-- The prime ideal is not the entire ring. -/ ne_top' : I ≠ ⊤ /-- If a product lies in the prime ideal, then at least one element lies in the prime ideal. -/ mem_or_mem' : ∀ {x y : α}, x * y ∈ I → x ∈ I ∨ y ∈ I theorem isPrime_iff {I : Ideal α} : IsPrime I ↔ I ≠ ⊤ ∧ ∀ {x y : α}, x * y ∈ I → x ∈ I ∨ y ∈ I := ⟨fun h => ⟨h.1, h.2⟩, fun h => ⟨h.1, h.2⟩⟩ theorem IsPrime.ne_top {I : Ideal α} (hI : I.IsPrime) : I ≠ ⊤ := hI.1 theorem IsPrime.mem_or_mem {I : Ideal α} (hI : I.IsPrime) {x y : α} : x * y ∈ I → x ∈ I ∨ y ∈ I := hI.2 theorem IsPrime.mem_or_mem_of_mul_eq_zero {I : Ideal α} (hI : I.IsPrime) {x y : α} (h : x * y = 0) : x ∈ I ∨ y ∈ I := hI.mem_or_mem (h.symm ▸ I.zero_mem) theorem IsPrime.mem_of_pow_mem {I : Ideal α} (hI : I.IsPrime) {r : α} (n : ℕ) (H : r ^ n ∈ I) : r ∈ I := by induction' n with n ih · rw [pow_zero] at H exact (mt (eq_top_iff_one _).2 hI.1).elim H · rw [pow_succ] at H exact Or.casesOn (hI.mem_or_mem H) ih id theorem not_isPrime_iff {I : Ideal α} : ¬I.IsPrime ↔ I = ⊤ ∨ ∃ (x : α) (_hx : x ∉ I) (y : α) (_hy : y ∉ I), x * y ∈ I := by simp_rw [Ideal.isPrime_iff, not_and_or, Ne, Classical.not_not, not_forall, not_or] exact or_congr Iff.rfl ⟨fun ⟨x, y, hxy, hx, hy⟩ => ⟨x, hx, y, hy, hxy⟩, fun ⟨x, hx, y, hy, hxy⟩ => ⟨x, y, hxy, hx, hy⟩⟩ theorem zero_ne_one_of_proper {I : Ideal α} (h : I ≠ ⊤) : (0 : α) ≠ 1 := fun hz => I.ne_top_iff_one.1 h <| hz ▸ I.zero_mem theorem bot_prime [IsDomain α] : (⊥ : Ideal α).IsPrime := ⟨fun h => one_ne_zero (α := α) (by rwa [Ideal.eq_top_iff_one, Submodule.mem_bot] at h), fun h => mul_eq_zero.mp (by simpa only [Submodule.mem_bot] using h)⟩ /-- An ideal is maximal if it is maximal in the collection of proper ideals. -/ class IsMaximal (I : Ideal α) : Prop where /-- The maximal ideal is a coatom in the ordering on ideals; that is, it is not the entire ring, and there are no other proper ideals strictly containing it. -/ out : IsCoatom I theorem isMaximal_def {I : Ideal α} : I.IsMaximal ↔ IsCoatom I := ⟨fun h => h.1, fun h => ⟨h⟩⟩ theorem IsMaximal.ne_top {I : Ideal α} (h : I.IsMaximal) : I ≠ ⊤ := (isMaximal_def.1 h).1 theorem isMaximal_iff {I : Ideal α} : I.IsMaximal ↔ (1 : α) ∉ I ∧ ∀ (J : Ideal α) (x), I ≤ J → x ∉ I → x ∈ J → (1 : α) ∈ J := isMaximal_def.trans <| and_congr I.ne_top_iff_one <| forall_congr' fun J => by rw [lt_iff_le_not_le] exact ⟨fun H x h hx₁ hx₂ => J.eq_top_iff_one.1 <| H ⟨h, not_subset.2 ⟨_, hx₂, hx₁⟩⟩, fun H ⟨h₁, h₂⟩ => let ⟨x, xJ, xI⟩ := not_subset.1 h₂ J.eq_top_iff_one.2 <| H x h₁ xI xJ⟩ theorem IsMaximal.eq_of_le {I J : Ideal α} (hI : I.IsMaximal) (hJ : J ≠ ⊤) (IJ : I ≤ J) : I = J := eq_iff_le_not_lt.2 ⟨IJ, fun h => hJ (hI.1.2 _ h)⟩ instance : IsCoatomic (Ideal α) := by apply CompleteLattice.coatomic_of_top_compact rw [← span_singleton_one] exact Submodule.singleton_span_isCompactElement 1 theorem IsMaximal.coprime_of_ne {M M' : Ideal α} (hM : M.IsMaximal) (hM' : M'.IsMaximal) (hne : M ≠ M') : M ⊔ M' = ⊤ := by contrapose! hne with h exact hM.eq_of_le hM'.ne_top (le_sup_left.trans_eq (hM'.eq_of_le h le_sup_right).symm) /-- **Krull's theorem**: if `I` is an ideal that is not the whole ring, then it is included in some maximal ideal. -/ theorem exists_le_maximal (I : Ideal α) (hI : I ≠ ⊤) : ∃ M : Ideal α, M.IsMaximal ∧ I ≤ M := let ⟨m, hm⟩ := (eq_top_or_exists_le_coatom I).resolve_left hI ⟨m, ⟨⟨hm.1⟩, hm.2⟩⟩ variable (α) /-- Krull's theorem: a nontrivial ring has a maximal ideal. -/ theorem exists_maximal [Nontrivial α] : ∃ M : Ideal α, M.IsMaximal := let ⟨I, ⟨hI, _⟩⟩ := exists_le_maximal (⊥ : Ideal α) bot_ne_top ⟨I, hI⟩ variable {α} instance [Nontrivial α] : Nontrivial (Ideal α) := by rcases@exists_maximal α _ _ with ⟨M, hM, _⟩ exact nontrivial_of_ne M ⊤ hM /-- If P is not properly contained in any maximal ideal then it is not properly contained in any proper ideal -/ theorem maximal_of_no_maximal {P : Ideal α} (hmax : ∀ m : Ideal α, P < m → ¬IsMaximal m) (J : Ideal α) (hPJ : P < J) : J = ⊤ := by by_contra hnonmax rcases exists_le_maximal J hnonmax with ⟨M, hM1, hM2⟩ exact hmax M (lt_of_lt_of_le hPJ hM2) hM1 theorem span_pair_comm {x y : α} : (span {x, y} : Ideal α) = span {y, x} := by simp only [span_insert, sup_comm] theorem mem_span_pair {x y z : α} : z ∈ span ({x, y} : Set α) ↔ ∃ a b, a * x + b * y = z := Submodule.mem_span_pair @[simp] theorem span_pair_add_mul_left {R : Type u} [CommRing R] {x y : R} (z : R) : (span {x + y * z, y} : Ideal R) = span {x, y} := by ext rw [mem_span_pair, mem_span_pair] exact ⟨fun ⟨a, b, h⟩ => ⟨a, b + a * z, by rw [← h] ring1⟩, fun ⟨a, b, h⟩ => ⟨a, b - a * z, by rw [← h] ring1⟩⟩ @[simp] theorem span_pair_add_mul_right {R : Type u} [CommRing R] {x y : R} (z : R) : (span {x, y + x * z} : Ideal R) = span {x, y} := by rw [span_pair_comm, span_pair_add_mul_left, span_pair_comm] theorem IsMaximal.exists_inv {I : Ideal α} (hI : I.IsMaximal) {x} (hx : x ∉ I) : ∃ y, ∃ i ∈ I, y * x + i = 1 := by cases' isMaximal_iff.1 hI with H₁ H₂ rcases mem_span_insert.1 (H₂ (span (insert x I)) x (Set.Subset.trans (subset_insert _ _) subset_span) hx (subset_span (mem_insert _ _))) with ⟨y, z, hz, hy⟩ refine ⟨y, z, ?_, hy.symm⟩ rwa [← span_eq I] section Lattice variable {R : Type u} [Semiring R] -- Porting note: is this the right approach? or is there a better way to prove? (next 4 decls) theorem mem_sup_left {S T : Ideal R} : ∀ {x : R}, x ∈ S → x ∈ S ⊔ T := @le_sup_left _ _ S T theorem mem_sup_right {S T : Ideal R} : ∀ {x : R}, x ∈ T → x ∈ S ⊔ T := @le_sup_right _ _ S T theorem mem_iSup_of_mem {ι : Sort*} {S : ι → Ideal R} (i : ι) : ∀ {x : R}, x ∈ S i → x ∈ iSup S := @le_iSup _ _ _ S _ theorem mem_sSup_of_mem {S : Set (Ideal R)} {s : Ideal R} (hs : s ∈ S) : ∀ {x : R}, x ∈ s → x ∈ sSup S := @le_sSup _ _ _ _ hs theorem mem_sInf {s : Set (Ideal R)} {x : R} : x ∈ sInf s ↔ ∀ ⦃I⦄, I ∈ s → x ∈ I := ⟨fun hx I his => hx I ⟨I, iInf_pos his⟩, fun H _I ⟨_J, hij⟩ => hij ▸ fun _S ⟨hj, hS⟩ => hS ▸ H hj⟩ @[simp 1001] -- Porting note: increased priority to appease `simpNF` theorem mem_inf {I J : Ideal R} {x : R} : x ∈ I ⊓ J ↔ x ∈ I ∧ x ∈ J := Iff.rfl @[simp 1001] -- Porting note: increased priority to appease `simpNF` theorem mem_iInf {ι : Sort*} {I : ι → Ideal R} {x : R} : x ∈ iInf I ↔ ∀ i, x ∈ I i := Submodule.mem_iInf _ @[simp 1001] -- Porting note: increased priority to appease `simpNF` theorem mem_bot {x : R} : x ∈ (⊥ : Ideal R) ↔ x = 0 := Submodule.mem_bot _ end Lattice section Pi variable (ι : Type v) /-- `I^n` as an ideal of `R^n`. -/ def pi : Ideal (ι → α) where carrier := { x | ∀ i, x i ∈ I } zero_mem' _i := I.zero_mem add_mem' ha hb i := I.add_mem (ha i) (hb i) smul_mem' a _b hb i := I.mul_mem_left (a i) (hb i) theorem mem_pi (x : ι → α) : x ∈ I.pi ι ↔ ∀ i, x i ∈ I := Iff.rfl end Pi theorem sInf_isPrime_of_isChain {s : Set (Ideal α)} (hs : s.Nonempty) (hs' : IsChain (· ≤ ·) s) (H : ∀ p ∈ s, Ideal.IsPrime p) : (sInf s).IsPrime := ⟨fun e => let ⟨x, hx⟩ := hs (H x hx).ne_top (eq_top_iff.mpr (e.symm.trans_le (sInf_le hx))), fun e => or_iff_not_imp_left.mpr fun hx => by rw [Ideal.mem_sInf] at hx e ⊢ push_neg at hx obtain ⟨I, hI, hI'⟩ := hx intro J hJ cases' hs'.total hI hJ with h h · exact h (((H I hI).mem_or_mem (e hI)).resolve_left hI') · exact ((H J hJ).mem_or_mem (e hJ)).resolve_left fun x => hI' <| h x⟩ end Ideal end Semiring section CommSemiring variable {a b : α} -- A separate namespace definition is needed because the variables were historically in a different -- order. namespace Ideal variable [CommSemiring α] (I : Ideal α) @[simp] theorem mul_unit_mem_iff_mem {x y : α} (hy : IsUnit y) : x * y ∈ I ↔ x ∈ I := mul_comm y x ▸ unit_mul_mem_iff_mem I hy theorem mem_span_singleton {x y : α} : x ∈ span ({y} : Set α) ↔ y ∣ x := mem_span_singleton'.trans <| exists_congr fun _ => by rw [eq_comm, mul_comm] theorem mem_span_singleton_self (x : α) : x ∈ span ({x} : Set α) := mem_span_singleton.mpr dvd_rfl theorem span_singleton_le_span_singleton {x y : α} : span ({x} : Set α) ≤ span ({y} : Set α) ↔ y ∣ x := span_le.trans <| singleton_subset_iff.trans mem_span_singleton theorem span_singleton_eq_span_singleton {α : Type u} [CommRing α] [IsDomain α] {x y : α} : span ({x} : Set α) = span ({y} : Set α) ↔ Associated x y := by rw [← dvd_dvd_iff_associated, le_antisymm_iff, and_comm] apply and_congr <;> rw [span_singleton_le_span_singleton] theorem span_singleton_mul_right_unit {a : α} (h2 : IsUnit a) (x : α) : span ({x * a} : Set α) = span {x} := by rw [mul_comm, span_singleton_mul_left_unit h2] @[simp] theorem span_singleton_eq_top {x} : span ({x} : Set α) = ⊤ ↔ IsUnit x := by rw [isUnit_iff_dvd_one, ← span_singleton_le_span_singleton, span_singleton_one, eq_top_iff] theorem span_singleton_prime {p : α} (hp : p ≠ 0) : IsPrime (span ({p} : Set α)) ↔ Prime p := by simp [isPrime_iff, Prime, span_singleton_eq_top, hp, mem_span_singleton] theorem IsMaximal.isPrime {I : Ideal α} (H : I.IsMaximal) : I.IsPrime := ⟨H.1.1, @fun x y hxy => or_iff_not_imp_left.2 fun hx => by let J : Ideal α := Submodule.span α (insert x ↑I) have IJ : I ≤ J := Set.Subset.trans (subset_insert _ _) subset_span have xJ : x ∈ J := Ideal.subset_span (Set.mem_insert x I) cases' isMaximal_iff.1 H with _ oJ specialize oJ J x IJ hx xJ rcases Submodule.mem_span_insert.mp oJ with ⟨a, b, h, oe⟩ obtain F : y * 1 = y * (a • x + b) := congr_arg (fun g : α => y * g) oe rw [← mul_one y, F, mul_add, mul_comm, smul_eq_mul, mul_assoc] refine Submodule.add_mem I (I.mul_mem_left a hxy) (Submodule.smul_mem I y ?_) rwa [Submodule.span_eq] at h⟩ -- see Note [lower instance priority] instance (priority := 100) IsMaximal.isPrime' (I : Ideal α) : ∀ [_H : I.IsMaximal], I.IsPrime := @IsMaximal.isPrime _ _ _ theorem span_singleton_lt_span_singleton [IsDomain α] {x y : α} : span ({x} : Set α) < span ({y} : Set α) ↔ DvdNotUnit y x := by rw [lt_iff_le_not_le, span_singleton_le_span_singleton, span_singleton_le_span_singleton, dvd_and_not_dvd_iff] theorem factors_decreasing [IsDomain α] (b₁ b₂ : α) (h₁ : b₁ ≠ 0) (h₂ : ¬IsUnit b₂) : span ({b₁ * b₂} : Set α) < span {b₁} := lt_of_le_not_le (Ideal.span_le.2 <| singleton_subset_iff.2 <| Ideal.mem_span_singleton.2 ⟨b₂, rfl⟩) fun h => h₂ <| isUnit_of_dvd_one <| (mul_dvd_mul_iff_left h₁).1 <| by rwa [mul_one, ← Ideal.span_singleton_le_span_singleton] variable (b) theorem mul_mem_right (h : a ∈ I) : a * b ∈ I := mul_comm b a ▸ I.mul_mem_left b h variable {b} theorem pow_mem_of_mem (ha : a ∈ I) (n : ℕ) (hn : 0 < n) : a ^ n ∈ I := Nat.casesOn n (Not.elim (by decide)) (fun m _hm => (pow_succ a m).symm ▸ I.mul_mem_left (a ^ m) ha) hn theorem pow_mem_of_pow_mem {m n : ℕ} (ha : a ^ m ∈ I) (h : m ≤ n) : a ^ n ∈ I := by rw [← Nat.add_sub_of_le h, pow_add] exact I.mul_mem_right _ ha theorem add_pow_mem_of_pow_mem_of_le {m n k : ℕ} (ha : a ^ m ∈ I) (hb : b ^ n ∈ I) (hk : m + n ≤ k + 1) : (a + b) ^ k ∈ I := by rw [add_pow] apply I.sum_mem intro c _ apply mul_mem_right by_cases h : m ≤ c · exact I.mul_mem_right _ (I.pow_mem_of_pow_mem ha h) · refine I.mul_mem_left _ (I.pow_mem_of_pow_mem hb ?_) simp only [not_le, Nat.lt_iff_add_one_le] at h have hck : c ≤ k := by rw [← add_le_add_iff_right 1] exact le_trans h (le_trans (Nat.le_add_right _ _) hk) rw [Nat.le_sub_iff_add_le hck, ← add_le_add_iff_right 1] exact le_trans (by rwa [add_comm _ n, add_assoc, add_le_add_iff_left]) hk theorem add_pow_add_pred_mem_of_pow_mem {m n : ℕ} (ha : a ^ m ∈ I) (hb : b ^ n ∈ I) : (a + b) ^ (m + n - 1) ∈ I := I.add_pow_mem_of_pow_mem_of_le ha hb <| by rw [← Nat.sub_le_iff_le_add] theorem IsPrime.mul_mem_iff_mem_or_mem {I : Ideal α} (hI : I.IsPrime) : ∀ {x y : α}, x * y ∈ I ↔ x ∈ I ∨ y ∈ I := @fun x y => ⟨hI.mem_or_mem, by rintro (h | h) exacts [I.mul_mem_right y h, I.mul_mem_left x h]⟩ theorem IsPrime.pow_mem_iff_mem {I : Ideal α} (hI : I.IsPrime) {r : α} (n : ℕ) (hn : 0 < n) : r ^ n ∈ I ↔ r ∈ I := ⟨hI.mem_of_pow_mem n, fun hr => I.pow_mem_of_mem hr n hn⟩ theorem pow_multiset_sum_mem_span_pow [DecidableEq α] (s : Multiset α) (n : ℕ) : s.sum ^ (Multiset.card s * n + 1) ∈ span ((s.map fun (x : α) ↦ x ^ (n + 1)).toFinset : Set α) := by induction' s using Multiset.induction_on with a s hs · simp simp only [Finset.coe_insert, Multiset.map_cons, Multiset.toFinset_cons, Multiset.sum_cons, Multiset.card_cons, add_pow] refine Submodule.sum_mem _ ?_ intro c _hc rw [mem_span_insert] by_cases h : n + 1 ≤ c · refine ⟨a ^ (c - (n + 1)) * s.sum ^ ((Multiset.card s + 1) * n + 1 - c) * ((Multiset.card s + 1) * n + 1).choose c, 0, Submodule.zero_mem _, ?_⟩ rw [mul_comm _ (a ^ (n + 1))] simp_rw [← mul_assoc] rw [← pow_add, add_zero, add_tsub_cancel_of_le h] · use 0 simp_rw [zero_mul, zero_add] refine ⟨_, ?_, rfl⟩ replace h : c ≤ n := Nat.lt_succ_iff.mp (not_le.mp h) have : (Multiset.card s + 1) * n + 1 - c = Multiset.card s * n + 1 + (n - c) := by rw [add_mul, one_mul, add_assoc, add_comm n 1, ← add_assoc, add_tsub_assoc_of_le h] rw [this, pow_add] simp_rw [mul_assoc, mul_comm (s.sum ^ (Multiset.card s * n + 1)), ← mul_assoc] exact mul_mem_left _ _ hs theorem sum_pow_mem_span_pow {ι} (s : Finset ι) (f : ι → α) (n : ℕ) : (∑ i ∈ s, f i) ^ (s.card * n + 1) ∈ span ((fun i => f i ^ (n + 1)) '' s) := by classical simpa only [Multiset.card_map, Multiset.map_map, comp_apply, Multiset.toFinset_map, Finset.coe_image, Finset.val_toFinset] using pow_multiset_sum_mem_span_pow (s.1.map f) n theorem span_pow_eq_top (s : Set α) (hs : span s = ⊤) (n : ℕ) : span ((fun (x : α) => x ^ n) '' s) = ⊤ := by rw [eq_top_iff_one] cases' n with n · obtain rfl | ⟨x, hx⟩ := eq_empty_or_nonempty s · rw [Set.image_empty, hs] trivial · exact subset_span ⟨_, hx, pow_zero _⟩ rw [eq_top_iff_one, span, Finsupp.mem_span_iff_total] at hs rcases hs with ⟨f, hf⟩ have hf : (f.support.sum fun a => f a * a) = 1 := hf -- Porting note: was `change ... at hf` have := sum_pow_mem_span_pow f.support (fun a => f a * a) n rw [hf, one_pow] at this refine span_le.mpr ?_ this rintro _ hx simp_rw [Set.mem_image] at hx rcases hx with ⟨x, _, rfl⟩ have : span ({(x : α) ^ (n + 1)} : Set α) ≤ span ((fun x : α => x ^ (n + 1)) '' s) := by rw [span_le, Set.singleton_subset_iff] exact subset_span ⟨x, x.prop, rfl⟩ refine this ?_ rw [mul_pow, mem_span_singleton] exact ⟨f x ^ (n + 1), mul_comm _ _⟩ lemma isPrime_of_maximally_disjoint (I : Ideal α) (S : Submonoid α) (disjoint : Disjoint (I : Set α) S) (maximally_disjoint : ∀ (J : Ideal α), I < J → ¬ Disjoint (J : Set α) S) : I.IsPrime where ne_top' := by rintro rfl have : 1 ∈ (S : Set α) := S.one_mem aesop mem_or_mem' {x y} hxy := by by_contra! rid have hx := maximally_disjoint (I ⊔ span {x}) (Submodule.lt_sup_iff_not_mem.mpr rid.1) have hy := maximally_disjoint (I ⊔ span {y}) (Submodule.lt_sup_iff_not_mem.mpr rid.2) simp only [Set.not_disjoint_iff, mem_inter_iff, SetLike.mem_coe, Submodule.mem_sup, mem_span_singleton] at hx hy obtain ⟨s₁, ⟨i₁, hi₁, ⟨_, ⟨r₁, rfl⟩, hr₁⟩⟩, hs₁⟩ := hx obtain ⟨s₂, ⟨i₂, hi₂, ⟨_, ⟨r₂, rfl⟩, hr₂⟩⟩, hs₂⟩ := hy refine disjoint.ne_of_mem (I.add_mem (I.mul_mem_left (i₁ + x * r₁) hi₂) <| I.add_mem (I.mul_mem_right (y * r₂) hi₁) <| I.mul_mem_right (r₁ * r₂) hxy) (S.mul_mem hs₁ hs₂) ?_ rw [← hr₁, ← hr₂] ring end Ideal end CommSemiring section Ring namespace Ideal variable [Ring α] (I : Ideal α) {a b : α} protected theorem neg_mem_iff : -a ∈ I ↔ a ∈ I := Submodule.neg_mem_iff I protected theorem add_mem_iff_left : b ∈ I → (a + b ∈ I ↔ a ∈ I) := Submodule.add_mem_iff_left I protected theorem add_mem_iff_right : a ∈ I → (a + b ∈ I ↔ b ∈ I) := Submodule.add_mem_iff_right I protected theorem sub_mem : a ∈ I → b ∈ I → a - b ∈ I := Submodule.sub_mem I theorem mem_span_insert' {s : Set α} {x y} : x ∈ span (insert y s) ↔ ∃ a, x + a * y ∈ span s := Submodule.mem_span_insert' @[simp] theorem span_singleton_neg (x : α) : (span {-x} : Ideal α) = span {x} := by ext simp only [mem_span_singleton'] exact ⟨fun ⟨y, h⟩ => ⟨-y, h ▸ neg_mul_comm y x⟩, fun ⟨y, h⟩ => ⟨-y, h ▸ neg_mul_neg y x⟩⟩ end Ideal end Ring section DivisionSemiring variable {K : Type u} [DivisionSemiring K] (I : Ideal K) namespace Ideal /-- All ideals in a division (semi)ring are trivial. -/ theorem eq_bot_or_top : I = ⊥ ∨ I = ⊤ := by rw [or_iff_not_imp_right] change _ ≠ _ → _ rw [Ideal.ne_top_iff_one] intro h1 rw [eq_bot_iff] intro r hr by_cases H : r = 0; · simpa simpa [H, h1] using I.mul_mem_left r⁻¹ hr variable (K) in /-- A bijection between (left) ideals of a division ring and `{0, 1}`, sending `⊥` to `0` and `⊤` to `1`. -/ def equivFinTwo [DecidableEq (Ideal K)] : Ideal K ≃ Fin 2 where toFun := fun I ↦ if I = ⊥ then 0 else 1 invFun := ![⊥, ⊤] left_inv := fun I ↦ by rcases eq_bot_or_top I with rfl | rfl <;> simp right_inv := fun i ↦ by fin_cases i <;> simp instance : Finite (Ideal K) := let _i := Classical.decEq (Ideal K); ⟨equivFinTwo K⟩ /-- Ideals of a `DivisionSemiring` are a simple order. Thanks to the way abbreviations work, this automatically gives an `IsSimpleModule K` instance. -/ instance isSimpleOrder : IsSimpleOrder (Ideal K) := ⟨eq_bot_or_top⟩ theorem eq_bot_of_prime [h : I.IsPrime] : I = ⊥ := or_iff_not_imp_right.mp I.eq_bot_or_top h.1 theorem bot_isMaximal : IsMaximal (⊥ : Ideal K) := ⟨⟨fun h => absurd ((eq_top_iff_one (⊤ : Ideal K)).mp rfl) (by rw [← h]; simp), fun I hI => or_iff_not_imp_left.mp (eq_bot_or_top I) (ne_of_gt hI)⟩⟩ end Ideal end DivisionSemiring section CommRing namespace Ideal theorem mul_sub_mul_mem {R : Type*} [CommRing R] (I : Ideal R) {a b c d : R} (h1 : a - b ∈ I) (h2 : c - d ∈ I) : a * c - b * d ∈ I := by rw [show a * c - b * d = (a - b) * c + b * (c - d) by rw [sub_mul, mul_sub]; abel] exact I.add_mem (I.mul_mem_right _ h1) (I.mul_mem_left _ h2) end Ideal end CommRing -- TODO: consider moving the lemmas below out of the `Ring` namespace since they are -- about `CommSemiring`s. namespace Ring variable {R : Type*} [CommSemiring R] theorem exists_not_isUnit_of_not_isField [Nontrivial R] (hf : ¬IsField R) : ∃ (x : R) (_hx : x ≠ (0 : R)), ¬IsUnit x := by have : ¬_ := fun h => hf ⟨exists_pair_ne R, mul_comm, h⟩ simp_rw [isUnit_iff_exists_inv] push_neg at this ⊢ obtain ⟨x, hx, not_unit⟩ := this exact ⟨x, hx, not_unit⟩ theorem not_isField_iff_exists_ideal_bot_lt_and_lt_top [Nontrivial R] : ¬IsField R ↔ ∃ I : Ideal R, ⊥ < I ∧ I < ⊤ := by constructor · intro h obtain ⟨x, nz, nu⟩ := exists_not_isUnit_of_not_isField h use Ideal.span {x} rw [bot_lt_iff_ne_bot, lt_top_iff_ne_top] exact ⟨mt Ideal.span_singleton_eq_bot.mp nz, mt Ideal.span_singleton_eq_top.mp nu⟩ · rintro ⟨I, bot_lt, lt_top⟩ hf obtain ⟨x, mem, ne_zero⟩ := SetLike.exists_of_lt bot_lt rw [Submodule.mem_bot] at ne_zero obtain ⟨y, hy⟩ := hf.mul_inv_cancel ne_zero rw [lt_top_iff_ne_top, Ne, Ideal.eq_top_iff_one, ← hy] at lt_top exact lt_top (I.mul_mem_right _ mem) theorem not_isField_iff_exists_prime [Nontrivial R] : ¬IsField R ↔ ∃ p : Ideal R, p ≠ ⊥ ∧ p.IsPrime := not_isField_iff_exists_ideal_bot_lt_and_lt_top.trans ⟨fun ⟨I, bot_lt, lt_top⟩ => let ⟨p, hp, le_p⟩ := I.exists_le_maximal (lt_top_iff_ne_top.mp lt_top) ⟨p, bot_lt_iff_ne_bot.mp (lt_of_lt_of_le bot_lt le_p), hp.isPrime⟩, fun ⟨p, ne_bot, Prime⟩ => ⟨p, bot_lt_iff_ne_bot.mpr ne_bot, lt_top_iff_ne_top.mpr Prime.1⟩⟩ /-- Also see `Ideal.isSimpleOrder` for the forward direction as an instance when `R` is a division (semi)ring. This result actually holds for all division semirings, but we lack the predicate to state it. -/ theorem isField_iff_isSimpleOrder_ideal : IsField R ↔ IsSimpleOrder (Ideal R) := by cases subsingleton_or_nontrivial R · exact ⟨fun h => (not_isField_of_subsingleton _ h).elim, fun h => (false_of_nontrivial_of_subsingleton <| Ideal R).elim⟩ rw [← not_iff_not, Ring.not_isField_iff_exists_ideal_bot_lt_and_lt_top, ← not_iff_not] push_neg simp_rw [lt_top_iff_ne_top, bot_lt_iff_ne_bot, ← or_iff_not_imp_left, not_ne_iff] exact ⟨fun h => ⟨h⟩, fun h => h.2⟩ /-- When a ring is not a field, the maximal ideals are nontrivial. -/ theorem ne_bot_of_isMaximal_of_not_isField [Nontrivial R] {M : Ideal R} (max : M.IsMaximal) (not_field : ¬IsField R) : M ≠ ⊥ := by rintro h rw [h] at max rcases max with ⟨⟨_h1, h2⟩⟩ obtain ⟨I, hIbot, hItop⟩ := not_isField_iff_exists_ideal_bot_lt_and_lt_top.mp not_field exact ne_of_lt hItop (h2 I hIbot) end Ring namespace Ideal variable {R : Type u} [CommSemiring R] [Nontrivial R] theorem bot_lt_of_maximal (M : Ideal R) [hm : M.IsMaximal] (non_field : ¬IsField R) : ⊥ < M := by rcases Ring.not_isField_iff_exists_ideal_bot_lt_and_lt_top.1 non_field with ⟨I, Ibot, Itop⟩ constructor; · simp intro mle apply lt_irrefl (⊤ : Ideal R) have : M = ⊥ := eq_bot_iff.mpr mle rw [← this] at Ibot rwa [hm.1.2 I Ibot] at Itop end Ideal variable {a b : α} /-- The set of non-invertible elements of a monoid. -/ def nonunits (α : Type u) [Monoid α] : Set α := { a | ¬IsUnit a } @[simp] theorem mem_nonunits_iff [Monoid α] : a ∈ nonunits α ↔ ¬IsUnit a := Iff.rfl theorem mul_mem_nonunits_right [CommMonoid α] : b ∈ nonunits α → a * b ∈ nonunits α := mt isUnit_of_mul_isUnit_right theorem mul_mem_nonunits_left [CommMonoid α] : a ∈ nonunits α → a * b ∈ nonunits α := mt isUnit_of_mul_isUnit_left theorem zero_mem_nonunits [Semiring α] : 0 ∈ nonunits α ↔ (0 : α) ≠ 1 := not_congr isUnit_zero_iff @[simp 1001] -- increased priority to appease `simpNF` theorem one_not_mem_nonunits [Monoid α] : (1 : α) ∉ nonunits α := not_not_intro isUnit_one theorem coe_subset_nonunits [Semiring α] {I : Ideal α} (h : I ≠ ⊤) : (I : Set α) ⊆ nonunits α := fun _x hx hu => h <| I.eq_top_of_isUnit_mem hx hu theorem exists_max_ideal_of_mem_nonunits [CommSemiring α] (h : a ∈ nonunits α) : ∃ I : Ideal α, I.IsMaximal ∧ a ∈ I := by have : Ideal.span ({a} : Set α) ≠ ⊤ := by intro H rw [Ideal.span_singleton_eq_top] at H contradiction rcases Ideal.exists_le_maximal _ this with ⟨I, Imax, H⟩ use I, Imax apply H apply Ideal.subset_span exact Set.mem_singleton a